]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- started updated to 3.14.1
[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                 if (err == 0)
462                         return; /* STFU */
463  
464 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
465 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
466 +               printk(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  #ifdef PRINT_USER_FAULTS
470                 /* XXX for debugging only */
471                 show_regs(regs);
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/parisc/mm/fault.c linux-3.13.10-vs2.3.6.11/arch/parisc/mm/fault.c
484 --- linux-3.13.10/arch/parisc/mm/fault.c        2014-01-22 20:38:18.000000000 +0000
485 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/mm/fault.c     2014-01-31 20:38:03.000000000 +0000
486 @@ -272,8 +272,9 @@ bad_area:
487  
488  #ifdef PRINT_USER_FAULTS
489                 printk(KERN_DEBUG "\n");
490 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
491 -                   task_pid_nr(tsk), tsk->comm, code, address);
492 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
493 +                   "command='%s' type=%lu address=0x%08lx\n",
494 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
495                 if (vma) {
496                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
497                                         vma->vm_start, vma->vm_end);
498 diff -NurpP --minimal linux-3.13.10/arch/powerpc/Kconfig linux-3.13.10-vs2.3.6.11/arch/powerpc/Kconfig
499 --- linux-3.13.10/arch/powerpc/Kconfig  2014-01-22 20:38:18.000000000 +0000
500 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/Kconfig       2014-01-31 20:38:03.000000000 +0000
501 @@ -1028,6 +1028,8 @@ source "lib/Kconfig"
502  
503  source "arch/powerpc/Kconfig.debug"
504  
505 +source "kernel/vserver/Kconfig"
506 +
507  source "security/Kconfig"
508  
509  config KEYS_COMPAT
510 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
511 --- linux-3.13.10/arch/powerpc/include/uapi/asm/unistd.h        2013-05-31 13:44:44.000000000 +0000
512 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/include/uapi/asm/unistd.h     2014-01-31 20:38:03.000000000 +0000
513 @@ -275,7 +275,7 @@
514  #endif
515  #define __NR_rtas              255
516  #define __NR_sys_debug_setcontext 256
517 -/* Number 257 is reserved for vserver */
518 +#define __NR_vserver           257
519  #define __NR_migrate_pages     258
520  #define __NR_mbind             259
521  #define __NR_get_mempolicy     260
522 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
523 --- linux-3.13.10/arch/powerpc/kernel/traps.c   2014-01-22 20:38:23.000000000 +0000
524 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/kernel/traps.c        2014-01-31 20:38:03.000000000 +0000
525 @@ -1272,8 +1272,9 @@ void nonrecoverable_exception(struct pt_
526  
527  void trace_syscall(struct pt_regs *regs)
528  {
529 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
530 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
531 +       printk("Task: %p(%d:#%u), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
532 +              current, task_pid_nr(current), current->xid,
533 +              regs->nip, regs->link, regs->gpr[0],
534                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
535  }
536  
537 diff -NurpP --minimal linux-3.13.10/arch/s390/Kconfig linux-3.13.10-vs2.3.6.11/arch/s390/Kconfig
538 --- linux-3.13.10/arch/s390/Kconfig     2014-04-17 01:12:08.000000000 +0000
539 +++ linux-3.13.10-vs2.3.6.11/arch/s390/Kconfig  2014-04-17 01:17:10.000000000 +0000
540 @@ -650,6 +650,8 @@ source "fs/Kconfig"
541  
542  source "arch/s390/Kconfig.debug"
543  
544 +source "kernel/vserver/Kconfig"
545 +
546  source "security/Kconfig"
547  
548  source "crypto/Kconfig"
549 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
550 --- linux-3.13.10/arch/s390/include/asm/tlb.h   2013-11-25 15:46:29.000000000 +0000
551 +++ linux-3.13.10-vs2.3.6.11/arch/s390/include/asm/tlb.h        2014-01-31 20:38:03.000000000 +0000
552 @@ -24,6 +24,7 @@
553  #include <linux/mm.h>
554  #include <linux/pagemap.h>
555  #include <linux/swap.h>
556 +
557  #include <asm/processor.h>
558  #include <asm/pgalloc.h>
559  #include <asm/tlbflush.h>
560 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
561 --- linux-3.13.10/arch/s390/include/uapi/asm/unistd.h   2013-02-19 13:57:16.000000000 +0000
562 +++ linux-3.13.10-vs2.3.6.11/arch/s390/include/uapi/asm/unistd.h        2014-01-31 20:38:03.000000000 +0000
563 @@ -200,7 +200,7 @@
564  #define __NR_clock_gettime     (__NR_timer_create+6)
565  #define __NR_clock_getres      (__NR_timer_create+7)
566  #define __NR_clock_nanosleep   (__NR_timer_create+8)
567 -/* Number 263 is reserved for vserver */
568 +#define __NR_vserver           263
569  #define __NR_statfs64          265
570  #define __NR_fstatfs64         266
571  #define __NR_remap_file_pages  267
572 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
573 --- linux-3.13.10/arch/s390/kernel/ptrace.c     2014-01-22 20:38:24.000000000 +0000
574 +++ linux-3.13.10-vs2.3.6.11/arch/s390/kernel/ptrace.c  2014-01-31 20:38:03.000000000 +0000
575 @@ -21,6 +21,7 @@
576  #include <linux/tracehook.h>
577  #include <linux/seccomp.h>
578  #include <linux/compat.h>
579 +#include <linux/vs_base.h>
580  #include <trace/syscall.h>
581  #include <asm/segment.h>
582  #include <asm/page.h>
583 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
584 --- linux-3.13.10/arch/s390/kernel/syscalls.S   2013-07-14 17:00:34.000000000 +0000
585 +++ linux-3.13.10-vs2.3.6.11/arch/s390/kernel/syscalls.S        2014-01-31 20:38:03.000000000 +0000
586 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
587  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
588  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
589  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
590 -NI_SYSCALL                                                     /* reserved for vserver */
591 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
592  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
593  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
594  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
595 diff -NurpP --minimal linux-3.13.10/arch/sh/Kconfig linux-3.13.10-vs2.3.6.11/arch/sh/Kconfig
596 --- linux-3.13.10/arch/sh/Kconfig       2014-01-22 20:38:24.000000000 +0000
597 +++ linux-3.13.10-vs2.3.6.11/arch/sh/Kconfig    2014-01-31 20:38:03.000000000 +0000
598 @@ -927,6 +927,8 @@ source "fs/Kconfig"
599  
600  source "arch/sh/Kconfig.debug"
601  
602 +source "kernel/vserver/Kconfig"
603 +
604  source "security/Kconfig"
605  
606  source "crypto/Kconfig"
607 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
608 --- linux-3.13.10/arch/sh/kernel/irq.c  2014-01-22 20:38:24.000000000 +0000
609 +++ linux-3.13.10-vs2.3.6.11/arch/sh/kernel/irq.c       2014-01-31 20:38:03.000000000 +0000
610 @@ -14,6 +14,7 @@
611  #include <linux/ftrace.h>
612  #include <linux/delay.h>
613  #include <linux/ratelimit.h>
614 +// #include <linux/vs_context.h>
615  #include <asm/processor.h>
616  #include <asm/machvec.h>
617  #include <asm/uaccess.h>
618 diff -NurpP --minimal linux-3.13.10/arch/sparc/Kconfig linux-3.13.10-vs2.3.6.11/arch/sparc/Kconfig
619 --- linux-3.13.10/arch/sparc/Kconfig    2014-01-22 20:38:24.000000000 +0000
620 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/Kconfig 2014-01-31 20:38:03.000000000 +0000
621 @@ -553,6 +553,8 @@ source "fs/Kconfig"
622  
623  source "arch/sparc/Kconfig.debug"
624  
625 +source "kernel/vserver/Kconfig"
626 +
627  source "security/Kconfig"
628  
629  source "crypto/Kconfig"
630 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
631 --- linux-3.13.10/arch/sparc/include/uapi/asm/unistd.h  2013-02-19 13:57:17.000000000 +0000
632 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/include/uapi/asm/unistd.h       2014-01-31 20:38:03.000000000 +0000
633 @@ -332,7 +332,7 @@
634  #define __NR_timer_getoverrun  264
635  #define __NR_timer_delete      265
636  #define __NR_timer_create      266
637 -/* #define __NR_vserver                267 Reserved for VSERVER */
638 +#define __NR_vserver           267
639  #define __NR_io_setup          268
640  #define __NR_io_destroy                269
641  #define __NR_io_submit         270
642 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
643 --- linux-3.13.10/arch/sparc/kernel/systbls_32.S        2013-05-31 13:44:48.000000000 +0000
644 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_32.S     2014-01-31 20:38:03.000000000 +0000
645 @@ -70,7 +70,7 @@ sys_call_table:
646  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
647  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
648  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
649 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
650 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
651  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
652  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
653  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
654 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
655 --- linux-3.13.10/arch/sparc/kernel/systbls_64.S        2013-07-14 17:00:35.000000000 +0000
656 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_64.S     2014-01-31 20:38:03.000000000 +0000
657 @@ -71,7 +71,7 @@ sys_call_table32:
658  /*250*/        .word sys_mremap, compat_sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
659         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
660  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
661 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
662 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
663  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
664         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
665  /*280*/        .word sys_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
666 @@ -149,7 +149,7 @@ sys_call_table:
667  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
668         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
669  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
670 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
671 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
672  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
673         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
674  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
675 diff -NurpP --minimal linux-3.13.10/arch/um/Kconfig.rest linux-3.13.10-vs2.3.6.11/arch/um/Kconfig.rest
676 --- linux-3.13.10/arch/um/Kconfig.rest  2012-12-11 03:30:57.000000000 +0000
677 +++ linux-3.13.10-vs2.3.6.11/arch/um/Kconfig.rest       2014-01-31 20:38:03.000000000 +0000
678 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
679  
680  source "fs/Kconfig"
681  
682 +source "kernel/vserver/Kconfig"
683 +
684  source "security/Kconfig"
685  
686  source "crypto/Kconfig"
687 diff -NurpP --minimal linux-3.13.10/arch/x86/Kconfig linux-3.13.10-vs2.3.6.11/arch/x86/Kconfig
688 --- linux-3.13.10/arch/x86/Kconfig      2014-01-22 20:38:25.000000000 +0000
689 +++ linux-3.13.10-vs2.3.6.11/arch/x86/Kconfig   2014-01-31 20:38:03.000000000 +0000
690 @@ -2403,6 +2403,8 @@ source "fs/Kconfig"
691  
692  source "arch/x86/Kconfig.debug"
693  
694 +source "kernel/vserver/Kconfig"
695 +
696  source "security/Kconfig"
697  
698  source "crypto/Kconfig"
699 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
700 --- linux-3.13.10/arch/x86/syscalls/syscall_32.tbl      2013-07-14 17:00:37.000000000 +0000
701 +++ linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_32.tbl   2014-01-31 20:38:03.000000000 +0000
702 @@ -279,7 +279,7 @@
703  270    i386    tgkill                  sys_tgkill
704  271    i386    utimes                  sys_utimes                      compat_sys_utimes
705  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
706 -273    i386    vserver
707 +273    i386    vserver                 sys_vserver                     sys32_vserver
708  274    i386    mbind                   sys_mbind
709  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
710  276    i386    set_mempolicy           sys_set_mempolicy
711 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
712 --- linux-3.13.10/arch/x86/syscalls/syscall_64.tbl      2013-05-31 13:44:50.000000000 +0000
713 +++ linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_64.tbl   2014-01-31 20:38:03.000000000 +0000
714 @@ -242,7 +242,7 @@
715  233    common  epoll_ctl               sys_epoll_ctl
716  234    common  tgkill                  sys_tgkill
717  235    common  utimes                  sys_utimes
718 -236    64      vserver
719 +236    64      vserver                 sys_vserver
720  237    common  mbind                   sys_mbind
721  238    common  set_mempolicy           sys_set_mempolicy
722  239    common  get_mempolicy           sys_get_mempolicy
723 diff -NurpP --minimal linux-3.13.10/drivers/block/Kconfig linux-3.13.10-vs2.3.6.11/drivers/block/Kconfig
724 --- linux-3.13.10/drivers/block/Kconfig 2014-01-22 20:38:27.000000000 +0000
725 +++ linux-3.13.10-vs2.3.6.11/drivers/block/Kconfig      2014-01-31 20:38:03.000000000 +0000
726 @@ -281,6 +281,13 @@ config BLK_DEV_CRYPTOLOOP
727  
728  source "drivers/block/drbd/Kconfig"
729  
730 +config BLK_DEV_VROOT
731 +       tristate "Virtual Root device support"
732 +       depends on QUOTACTL
733 +       ---help---
734 +         Saying Y here will allow you to use quota/fs ioctls on a shared
735 +         partition within a virtual server without compromising security.
736 +
737  config BLK_DEV_NBD
738         tristate "Network block device support"
739         depends on NET
740 diff -NurpP --minimal linux-3.13.10/drivers/block/Makefile linux-3.13.10-vs2.3.6.11/drivers/block/Makefile
741 --- linux-3.13.10/drivers/block/Makefile        2014-01-22 20:38:27.000000000 +0000
742 +++ linux-3.13.10-vs2.3.6.11/drivers/block/Makefile     2014-01-31 20:38:03.000000000 +0000
743 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIRTIO_BLK)      += virtio_blk.o
744  obj-$(CONFIG_VIODASD)          += viodasd.o
745  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
746  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
747 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
748  
749  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
750  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
751 diff -NurpP --minimal linux-3.13.10/drivers/block/loop.c linux-3.13.10-vs2.3.6.11/drivers/block/loop.c
752 --- linux-3.13.10/drivers/block/loop.c  2014-01-22 20:38:27.000000000 +0000
753 +++ linux-3.13.10-vs2.3.6.11/drivers/block/loop.c       2014-01-31 20:55:14.000000000 +0000
754 @@ -75,6 +75,7 @@
755  #include <linux/sysfs.h>
756  #include <linux/miscdevice.h>
757  #include <linux/falloc.h>
758 +#include <linux/vs_context.h>
759  #include "loop.h"
760  
761  #include <asm/uaccess.h>
762 @@ -884,6 +885,7 @@ static int loop_set_fd(struct loop_devic
763         lo->lo_blocksize = lo_blocksize;
764         lo->lo_device = bdev;
765         lo->lo_flags = lo_flags;
766 +       lo->lo_xid = vx_current_xid();
767         lo->lo_backing_file = file;
768         lo->transfer = transfer_none;
769         lo->ioctl = NULL;
770 @@ -1028,6 +1030,7 @@ static int loop_clr_fd(struct loop_devic
771         lo->lo_sizelimit = 0;
772         lo->lo_encrypt_key_size = 0;
773         lo->lo_thread = NULL;
774 +       lo->lo_xid = 0;
775         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
776         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
777         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
778 @@ -1071,7 +1074,7 @@ loop_set_status(struct loop_device *lo,
779  
780         if (lo->lo_encrypt_key_size &&
781             !uid_eq(lo->lo_key_owner, uid) &&
782 -           !capable(CAP_SYS_ADMIN))
783 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
784                 return -EPERM;
785         if (lo->lo_state != Lo_bound)
786                 return -ENXIO;
787 @@ -1161,7 +1164,8 @@ loop_get_status(struct loop_device *lo,
788         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
789         info->lo_encrypt_type =
790                 lo->lo_encryption ? lo->lo_encryption->number : 0;
791 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
792 +       if (lo->lo_encrypt_key_size &&
793 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
794                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
795                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
796                        lo->lo_encrypt_key_size);
797 @@ -1503,6 +1507,11 @@ static int lo_open(struct block_device *
798                 goto out;
799         }
800  
801 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
802 +               err = -EACCES;
803 +               goto out;
804 +       }
805 +
806         mutex_lock(&lo->lo_ctl_mutex);
807         lo->lo_refcnt++;
808         mutex_unlock(&lo->lo_ctl_mutex);
809 diff -NurpP --minimal linux-3.13.10/drivers/block/loop.h linux-3.13.10-vs2.3.6.11/drivers/block/loop.h
810 --- linux-3.13.10/drivers/block/loop.h  2013-11-25 15:44:28.000000000 +0000
811 +++ linux-3.13.10-vs2.3.6.11/drivers/block/loop.h       2014-02-01 01:57:49.000000000 +0000
812 @@ -41,6 +41,7 @@ struct loop_device {
813         struct loop_func_table *lo_encryption;
814         __u32           lo_init[2];
815         kuid_t          lo_key_owner;   /* Who set the key */
816 +       vxid_t          lo_xid;
817         int             (*ioctl)(struct loop_device *, int cmd, 
818                                  unsigned long arg); 
819  
820 diff -NurpP --minimal linux-3.13.10/drivers/block/vroot.c linux-3.13.10-vs2.3.6.11/drivers/block/vroot.c
821 --- linux-3.13.10/drivers/block/vroot.c 1970-01-01 00:00:00.000000000 +0000
822 +++ linux-3.13.10-vs2.3.6.11/drivers/block/vroot.c      2014-01-31 20:38:03.000000000 +0000
823 @@ -0,0 +1,290 @@
824 +/*
825 + *  linux/drivers/block/vroot.c
826 + *
827 + *  written by Herbert Pötzl, 9/11/2002
828 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
829 + *
830 + *  based on the loop.c code by Theodore Ts'o.
831 + *
832 + * Copyright (C) 2002-2007 by Herbert Pötzl.
833 + * Redistribution of this file is permitted under the
834 + * GNU General Public License.
835 + *
836 + */
837 +
838 +#include <linux/module.h>
839 +#include <linux/moduleparam.h>
840 +#include <linux/file.h>
841 +#include <linux/major.h>
842 +#include <linux/blkdev.h>
843 +#include <linux/slab.h>
844 +
845 +#include <linux/vroot.h>
846 +#include <linux/vs_context.h>
847 +
848 +
849 +static int max_vroot = 8;
850 +
851 +static struct vroot_device *vroot_dev;
852 +static struct gendisk **disks;
853 +
854 +
855 +static int vroot_set_dev(
856 +       struct vroot_device *vr,
857 +       struct block_device *bdev,
858 +       unsigned int arg)
859 +{
860 +       struct block_device *real_bdev;
861 +       struct file *file;
862 +       struct inode *inode;
863 +       int error;
864 +
865 +       error = -EBUSY;
866 +       if (vr->vr_state != Vr_unbound)
867 +               goto out;
868 +
869 +       error = -EBADF;
870 +       file = fget(arg);
871 +       if (!file)
872 +               goto out;
873 +
874 +       error = -EINVAL;
875 +       inode = file->f_dentry->d_inode;
876 +
877 +
878 +       if (S_ISBLK(inode->i_mode)) {
879 +               real_bdev = inode->i_bdev;
880 +               vr->vr_device = real_bdev;
881 +               __iget(real_bdev->bd_inode);
882 +       } else
883 +               goto out_fput;
884 +
885 +       vxdprintk(VXD_CBIT(misc, 0),
886 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
887 +               vr->vr_number, VXD_DEV(real_bdev));
888 +
889 +       vr->vr_state = Vr_bound;
890 +       error = 0;
891 +
892 + out_fput:
893 +       fput(file);
894 + out:
895 +       return error;
896 +}
897 +
898 +static int vroot_clr_dev(
899 +       struct vroot_device *vr,
900 +       struct block_device *bdev)
901 +{
902 +       struct block_device *real_bdev;
903 +
904 +       if (vr->vr_state != Vr_bound)
905 +               return -ENXIO;
906 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
907 +               return -EBUSY;
908 +
909 +       real_bdev = vr->vr_device;
910 +
911 +       vxdprintk(VXD_CBIT(misc, 0),
912 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
913 +               vr->vr_number, VXD_DEV(real_bdev));
914 +
915 +       bdput(real_bdev);
916 +       vr->vr_state = Vr_unbound;
917 +       vr->vr_device = NULL;
918 +       return 0;
919 +}
920 +
921 +
922 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
923 +       unsigned int cmd, unsigned long arg)
924 +{
925 +       struct vroot_device *vr = bdev->bd_disk->private_data;
926 +       int err;
927 +
928 +       down(&vr->vr_ctl_mutex);
929 +       switch (cmd) {
930 +       case VROOT_SET_DEV:
931 +               err = vroot_set_dev(vr, bdev, arg);
932 +               break;
933 +       case VROOT_CLR_DEV:
934 +               err = vroot_clr_dev(vr, bdev);
935 +               break;
936 +       default:
937 +               err = -EINVAL;
938 +               break;
939 +       }
940 +       up(&vr->vr_ctl_mutex);
941 +       return err;
942 +}
943 +
944 +static int vr_open(struct block_device *bdev, fmode_t mode)
945 +{
946 +       struct vroot_device *vr = bdev->bd_disk->private_data;
947 +
948 +       down(&vr->vr_ctl_mutex);
949 +       vr->vr_refcnt++;
950 +       up(&vr->vr_ctl_mutex);
951 +       return 0;
952 +}
953 +
954 +static void vr_release(struct gendisk *disk, fmode_t mode)
955 +{
956 +       struct vroot_device *vr = disk->private_data;
957 +
958 +       down(&vr->vr_ctl_mutex);
959 +       --vr->vr_refcnt;
960 +       up(&vr->vr_ctl_mutex);
961 +}
962 +
963 +static struct block_device_operations vr_fops = {
964 +       .owner =        THIS_MODULE,
965 +       .open =         vr_open,
966 +       .release =      vr_release,
967 +       .ioctl =        vr_ioctl,
968 +};
969 +
970 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
971 +{
972 +       printk("vroot_make_request %p, %p\n", q, bio);
973 +       bio_io_error(bio);
974 +}
975 +
976 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
977 +{
978 +       struct inode *inode = bdev->bd_inode;
979 +       struct vroot_device *vr;
980 +       struct block_device *real_bdev;
981 +       int minor = iminor(inode);
982 +
983 +       vr = &vroot_dev[minor];
984 +       real_bdev = vr->vr_device;
985 +
986 +       vxdprintk(VXD_CBIT(misc, 0),
987 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
988 +               vr->vr_number, VXD_DEV(real_bdev));
989 +
990 +       if (vr->vr_state != Vr_bound)
991 +               return ERR_PTR(-ENXIO);
992 +
993 +       __iget(real_bdev->bd_inode);
994 +       return real_bdev;
995 +}
996 +
997 +
998 +
999 +/*
1000 + * And now the modules code and kernel interface.
1001 + */
1002 +
1003 +module_param(max_vroot, int, 0);
1004 +
1005 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1006 +MODULE_LICENSE("GPL");
1007 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1008 +
1009 +MODULE_AUTHOR ("Herbert Pötzl");
1010 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1011 +
1012 +
1013 +int __init vroot_init(void)
1014 +{
1015 +       int err, i;
1016 +
1017 +       if (max_vroot < 1 || max_vroot > 256) {
1018 +               max_vroot = MAX_VROOT_DEFAULT;
1019 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1020 +                       "(must be between 1 and 256), "
1021 +                       "using default (%d)\n", max_vroot);
1022 +       }
1023 +
1024 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1025 +               return -EIO;
1026 +
1027 +       err = -ENOMEM;
1028 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1029 +       if (!vroot_dev)
1030 +               goto out_mem1;
1031 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1032 +
1033 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1034 +       if (!disks)
1035 +               goto out_mem2;
1036 +
1037 +       for (i = 0; i < max_vroot; i++) {
1038 +               disks[i] = alloc_disk(1);
1039 +               if (!disks[i])
1040 +                       goto out_mem3;
1041 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1042 +               if (!disks[i]->queue)
1043 +                       goto out_mem3;
1044 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1045 +       }
1046 +
1047 +       for (i = 0; i < max_vroot; i++) {
1048 +               struct vroot_device *vr = &vroot_dev[i];
1049 +               struct gendisk *disk = disks[i];
1050 +
1051 +               memset(vr, 0, sizeof(*vr));
1052 +               sema_init(&vr->vr_ctl_mutex, 1);
1053 +               vr->vr_number = i;
1054 +               disk->major = VROOT_MAJOR;
1055 +               disk->first_minor = i;
1056 +               disk->fops = &vr_fops;
1057 +               sprintf(disk->disk_name, "vroot%d", i);
1058 +               disk->private_data = vr;
1059 +       }
1060 +
1061 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1062 +       if (err)
1063 +               goto out_mem3;
1064 +
1065 +       for (i = 0; i < max_vroot; i++)
1066 +               add_disk(disks[i]);
1067 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1068 +       return 0;
1069 +
1070 +out_mem3:
1071 +       while (i--)
1072 +               put_disk(disks[i]);
1073 +       kfree(disks);
1074 +out_mem2:
1075 +       kfree(vroot_dev);
1076 +out_mem1:
1077 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1078 +       printk(KERN_ERR "vroot: ran out of memory\n");
1079 +       return err;
1080 +}
1081 +
1082 +void vroot_exit(void)
1083 +{
1084 +       int i;
1085 +
1086 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1087 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1088 +
1089 +       for (i = 0; i < max_vroot; i++) {
1090 +               del_gendisk(disks[i]);
1091 +               put_disk(disks[i]);
1092 +       }
1093 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1094 +
1095 +       kfree(disks);
1096 +       kfree(vroot_dev);
1097 +}
1098 +
1099 +module_init(vroot_init);
1100 +module_exit(vroot_exit);
1101 +
1102 +#ifndef MODULE
1103 +
1104 +static int __init max_vroot_setup(char *str)
1105 +{
1106 +       max_vroot = simple_strtol(str, NULL, 0);
1107 +       return 1;
1108 +}
1109 +
1110 +__setup("max_vroot=", max_vroot_setup);
1111 +
1112 +#endif
1113 +
1114 diff -NurpP --minimal linux-3.13.10/drivers/infiniband/Kconfig linux-3.13.10-vs2.3.6.11/drivers/infiniband/Kconfig
1115 --- linux-3.13.10/drivers/infiniband/Kconfig    2014-01-22 20:38:35.000000000 +0000
1116 +++ linux-3.13.10-vs2.3.6.11/drivers/infiniband/Kconfig 2014-01-31 20:38:03.000000000 +0000
1117 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1118  config INFINIBAND_ADDR_TRANS
1119         bool
1120         depends on INET
1121 -       depends on !(INFINIBAND = y && IPV6 = m)
1122 +       depends on !(INFINIBAND = y && IPV6 = y)
1123         default y
1124  
1125  source "drivers/infiniband/hw/mthca/Kconfig"
1126 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
1127 --- linux-3.13.10/drivers/infiniband/core/addr.c        2013-11-25 15:44:35.000000000 +0000
1128 +++ linux-3.13.10-vs2.3.6.11/drivers/infiniband/core/addr.c     2014-01-31 20:38:03.000000000 +0000
1129 @@ -277,7 +277,7 @@ static int addr6_resolve(struct sockaddr
1130  
1131         if (ipv6_addr_any(&fl6.saddr)) {
1132                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1133 -                                        &fl6.daddr, 0, &fl6.saddr);
1134 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1135                 if (ret)
1136                         goto put;
1137  
1138 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
1139 --- linux-3.13.10/drivers/md/dm-ioctl.c 2014-01-22 20:38:36.000000000 +0000
1140 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm-ioctl.c      2014-01-31 21:01:49.000000000 +0000
1141 @@ -16,6 +16,7 @@
1142  #include <linux/dm-ioctl.h>
1143  #include <linux/hdreg.h>
1144  #include <linux/compat.h>
1145 +#include <linux/vs_context.h>
1146  
1147  #include <asm/uaccess.h>
1148  
1149 @@ -114,7 +115,8 @@ static struct hash_cell *__get_name_cell
1150         unsigned int h = hash_str(str);
1151  
1152         list_for_each_entry (hc, _name_buckets + h, name_list)
1153 -               if (!strcmp(hc->name, str)) {
1154 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1155 +                       !strcmp(hc->name, str)) {
1156                         dm_get(hc->md);
1157                         return hc;
1158                 }
1159 @@ -128,7 +130,8 @@ static struct hash_cell *__get_uuid_cell
1160         unsigned int h = hash_str(str);
1161  
1162         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1163 -               if (!strcmp(hc->uuid, str)) {
1164 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1165 +                       !strcmp(hc->uuid, str)) {
1166                         dm_get(hc->md);
1167                         return hc;
1168                 }
1169 @@ -139,13 +142,15 @@ static struct hash_cell *__get_uuid_cell
1170  static struct hash_cell *__get_dev_cell(uint64_t dev)
1171  {
1172         struct mapped_device *md;
1173 -       struct hash_cell *hc;
1174 +       struct hash_cell *hc = NULL;
1175  
1176         md = dm_get_md(huge_decode_dev(dev));
1177         if (!md)
1178                 return NULL;
1179  
1180 -       hc = dm_get_mdptr(md);
1181 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1182 +               hc = dm_get_mdptr(md);
1183 +
1184         if (!hc) {
1185                 dm_put(md);
1186                 return NULL;
1187 @@ -467,6 +472,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1188  
1189  static int remove_all(struct dm_ioctl *param, size_t param_size)
1190  {
1191 +       if (!vx_check(0, VS_ADMIN))
1192 +               return -EPERM;
1193 +
1194         dm_hash_remove_all(true, !!(param->flags & DM_DEFERRED_REMOVE), false);
1195         param->data_size = 0;
1196         return 0;
1197 @@ -514,6 +522,8 @@ static int list_devices(struct dm_ioctl
1198          */
1199         for (i = 0; i < NUM_BUCKETS; i++) {
1200                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1201 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1202 +                               continue;
1203                         needed += sizeof(struct dm_name_list);
1204                         needed += strlen(hc->name) + 1;
1205                         needed += ALIGN_MASK;
1206 @@ -537,6 +547,8 @@ static int list_devices(struct dm_ioctl
1207          */
1208         for (i = 0; i < NUM_BUCKETS; i++) {
1209                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1210 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1211 +                               continue;
1212                         if (old_nl)
1213                                 old_nl->next = (uint32_t) ((void *) nl -
1214                                                            (void *) old_nl);
1215 @@ -1797,8 +1809,8 @@ static int ctl_ioctl(uint command, struc
1216         size_t input_param_size;
1217         struct dm_ioctl param_kernel;
1218  
1219 -       /* only root can play with this */
1220 -       if (!capable(CAP_SYS_ADMIN))
1221 +       /* only root and certain contexts can play with this */
1222 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1223                 return -EACCES;
1224  
1225         if (_IOC_TYPE(command) != DM_IOCTL)
1226 diff -NurpP --minimal linux-3.13.10/drivers/md/dm.c linux-3.13.10-vs2.3.6.11/drivers/md/dm.c
1227 --- linux-3.13.10/drivers/md/dm.c       2014-04-17 01:12:19.000000000 +0000
1228 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm.c    2014-02-25 11:26:09.000000000 +0000
1229 @@ -19,6 +19,7 @@
1230  #include <linux/idr.h>
1231  #include <linux/hdreg.h>
1232  #include <linux/delay.h>
1233 +#include <linux/vs_base.h>
1234  
1235  #include <trace/events/block.h>
1236  
1237 @@ -139,6 +140,7 @@ struct mapped_device {
1238         struct mutex suspend_lock;
1239         atomic_t holders;
1240         atomic_t open_count;
1241 +       vxid_t xid;
1242  
1243         /*
1244          * The current mapping.
1245 @@ -384,6 +386,7 @@ int dm_deleting_md(struct mapped_device
1246  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1247  {
1248         struct mapped_device *md;
1249 +       int ret = -ENXIO;
1250  
1251         spin_lock(&_minor_lock);
1252  
1253 @@ -392,18 +395,19 @@ static int dm_blk_open(struct block_devi
1254                 goto out;
1255  
1256         if (test_bit(DMF_FREEING, &md->flags) ||
1257 -           dm_deleting_md(md)) {
1258 -               md = NULL;
1259 +           dm_deleting_md(md))
1260 +               goto out;
1261 +
1262 +       ret = -EACCES;
1263 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1264                 goto out;
1265 -       }
1266  
1267         dm_get(md);
1268         atomic_inc(&md->open_count);
1269 -
1270 +       ret = 0;
1271  out:
1272         spin_unlock(&_minor_lock);
1273 -
1274 -       return md ? 0 : -ENXIO;
1275 +       return ret;
1276  }
1277  
1278  static void dm_blk_close(struct gendisk *disk, fmode_t mode)
1279 @@ -687,6 +691,14 @@ int dm_set_geometry(struct mapped_device
1280         return 0;
1281  }
1282  
1283 +/*
1284 + * Get the xid associated with a dm device
1285 + */
1286 +vxid_t dm_get_xid(struct mapped_device *md)
1287 +{
1288 +       return md->xid;
1289 +}
1290 +
1291  /*-----------------------------------------------------------------
1292   * CRUD START:
1293   *   A more elegant soln is in the works that uses the queue
1294 @@ -2026,6 +2038,7 @@ static struct mapped_device *alloc_dev(i
1295         INIT_LIST_HEAD(&md->uevent_list);
1296         spin_lock_init(&md->uevent_lock);
1297  
1298 +       md->xid = vx_current_xid();
1299         md->queue = blk_alloc_queue(GFP_KERNEL);
1300         if (!md->queue)
1301                 goto bad_queue;
1302 diff -NurpP --minimal linux-3.13.10/drivers/md/dm.h linux-3.13.10-vs2.3.6.11/drivers/md/dm.h
1303 --- linux-3.13.10/drivers/md/dm.h       2014-04-17 01:12:19.000000000 +0000
1304 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm.h    2014-02-25 11:26:09.000000000 +0000
1305 @@ -50,6 +50,8 @@ struct dm_dev_internal {
1306  struct dm_table;
1307  struct dm_md_mempools;
1308  
1309 +vxid_t dm_get_xid(struct mapped_device *md);
1310 +
1311  /*-----------------------------------------------------------------
1312   * Internal table functions.
1313   *---------------------------------------------------------------*/
1314 diff -NurpP --minimal linux-3.13.10/drivers/net/tun.c linux-3.13.10-vs2.3.6.11/drivers/net/tun.c
1315 --- linux-3.13.10/drivers/net/tun.c     2014-04-17 01:12:21.000000000 +0000
1316 +++ linux-3.13.10-vs2.3.6.11/drivers/net/tun.c  2014-04-17 01:17:10.000000000 +0000
1317 @@ -65,6 +65,7 @@
1318  #include <linux/nsproxy.h>
1319  #include <linux/virtio_net.h>
1320  #include <linux/rcupdate.h>
1321 +#include <linux/vs_network.h>
1322  #include <net/net_namespace.h>
1323  #include <net/netns/generic.h>
1324  #include <net/rtnetlink.h>
1325 @@ -168,6 +169,7 @@ struct tun_struct {
1326         unsigned int            flags;
1327         kuid_t                  owner;
1328         kgid_t                  group;
1329 +       vnid_t                  nid;
1330  
1331         struct net_device       *dev;
1332         netdev_features_t       set_features;
1333 @@ -385,6 +387,7 @@ static inline bool tun_not_capable(struc
1334         return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1335                   (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1336                 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1337 +               /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1338  }
1339  
1340  static void tun_set_real_num_queues(struct tun_struct *tun)
1341 @@ -1382,6 +1385,7 @@ static void tun_setup(struct net_device
1342  
1343         tun->owner = INVALID_UID;
1344         tun->group = INVALID_GID;
1345 +       tun->nid = nx_current_nid();
1346  
1347         dev->ethtool_ops = &tun_ethtool_ops;
1348         dev->destructor = tun_free_netdev;
1349 @@ -1598,7 +1602,7 @@ static int tun_set_iff(struct net *net,
1350                 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1351                              MAX_TAP_QUEUES : 1;
1352  
1353 -               if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1354 +               if (!nx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1355                         return -EPERM;
1356                 err = security_tun_dev_create();
1357                 if (err < 0)
1358 @@ -1969,6 +1973,16 @@ static long __tun_chr_ioctl(struct file
1359                           from_kgid(&init_user_ns, tun->group));
1360                 break;
1361  
1362 +       case TUNSETNID:
1363 +               if (!capable(CAP_CONTEXT))
1364 +                       return -EPERM;
1365 +
1366 +               /* Set nid owner of the device */
1367 +               tun->nid = (vnid_t) arg;
1368 +
1369 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1370 +               break;
1371 +
1372         case TUNSETLINK:
1373                 /* Only allow setting the type when the interface is down */
1374                 if (tun->dev->flags & IFF_UP) {
1375 diff -NurpP --minimal linux-3.13.10/drivers/tty/sysrq.c linux-3.13.10-vs2.3.6.11/drivers/tty/sysrq.c
1376 --- linux-3.13.10/drivers/tty/sysrq.c   2014-01-22 20:39:02.000000000 +0000
1377 +++ linux-3.13.10-vs2.3.6.11/drivers/tty/sysrq.c        2014-01-31 20:55:49.000000000 +0000
1378 @@ -46,6 +46,7 @@
1379  #include <linux/jiffies.h>
1380  #include <linux/syscalls.h>
1381  #include <linux/of.h>
1382 +#include <linux/vserver/debug.h>
1383  
1384  #include <asm/ptrace.h>
1385  #include <asm/irq_regs.h>
1386 @@ -407,6 +408,21 @@ static struct sysrq_key_op sysrq_unrt_op
1387         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1388  };
1389  
1390 +
1391 +#ifdef CONFIG_VSERVER_DEBUG
1392 +static void sysrq_handle_vxinfo(int key)
1393 +{
1394 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1395 +}
1396 +
1397 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1398 +       .handler        = sysrq_handle_vxinfo,
1399 +       .help_msg       = "conteXt",
1400 +       .action_msg     = "Show Context Info",
1401 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1402 +};
1403 +#endif
1404 +
1405  /* Key Operations table and lock */
1406  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1407  
1408 @@ -462,7 +478,11 @@ static struct sysrq_key_op *sysrq_key_ta
1409         &sysrq_showstate_blocked_op,    /* w */
1410         /* x: May be registered on ppc/powerpc for xmon */
1411         /* x: May be registered on sparc64 for global PMU dump */
1412 +#ifdef CONFIG_VSERVER_DEBUG
1413 +       &sysrq_showvxinfo_op,           /* x */
1414 +#else
1415         NULL,                           /* x */
1416 +#endif
1417         /* y: May be registered on sparc64 for global register dump */
1418         NULL,                           /* y */
1419         &sysrq_ftrace_dump_op,          /* z */
1420 @@ -477,6 +497,8 @@ static int sysrq_key_table_key2index(int
1421                 retval = key - '0';
1422         else if ((key >= 'a') && (key <= 'z'))
1423                 retval = key + 10 - 'a';
1424 +       else if ((key >= 'A') && (key <= 'Z'))
1425 +               retval = key + 10 - 'A';
1426         else
1427                 retval = -1;
1428         return retval;
1429 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
1430 --- linux-3.13.10/drivers/tty/tty_io.c  2014-01-22 20:39:02.000000000 +0000
1431 +++ linux-3.13.10-vs2.3.6.11/drivers/tty/tty_io.c       2014-01-31 20:38:03.000000000 +0000
1432 @@ -104,6 +104,7 @@
1433  
1434  #include <linux/kmod.h>
1435  #include <linux/nsproxy.h>
1436 +#include <linux/vs_pid.h>
1437  
1438  #undef TTY_DEBUG_HANGUP
1439  
1440 @@ -2218,7 +2219,8 @@ static int tiocsti(struct tty_struct *tt
1441         char ch, mbz = 0;
1442         struct tty_ldisc *ld;
1443  
1444 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1445 +       if (((current->signal->tty != tty) &&
1446 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1447                 return -EPERM;
1448         if (get_user(ch, p))
1449                 return -EFAULT;
1450 @@ -2506,6 +2508,7 @@ static int tiocspgrp(struct tty_struct *
1451                 return -ENOTTY;
1452         if (get_user(pgrp_nr, p))
1453                 return -EFAULT;
1454 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1455         if (pgrp_nr < 0)
1456                 return -EINVAL;
1457         rcu_read_lock();
1458 diff -NurpP --minimal linux-3.13.10/fs/attr.c linux-3.13.10-vs2.3.6.11/fs/attr.c
1459 --- linux-3.13.10/fs/attr.c     2014-04-17 01:12:31.000000000 +0000
1460 +++ linux-3.13.10-vs2.3.6.11/fs/attr.c  2014-03-12 15:51:07.000000000 +0000
1461 @@ -15,6 +15,9 @@
1462  #include <linux/security.h>
1463  #include <linux/evm.h>
1464  #include <linux/ima.h>
1465 +#include <linux/proc_fs.h>
1466 +#include <linux/devpts_fs.h>
1467 +#include <linux/vs_tag.h>
1468  
1469  /**
1470   * inode_change_ok - check if attribute changes to an inode are allowed
1471 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1472                         return -EPERM;
1473         }
1474  
1475 +       /* check for inode tag permission */
1476 +       if (dx_permission(inode, MAY_WRITE))
1477 +               return -EACCES;
1478 +
1479         return 0;
1480  }
1481  EXPORT_SYMBOL(inode_change_ok);
1482 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1483                 inode->i_uid = attr->ia_uid;
1484         if (ia_valid & ATTR_GID)
1485                 inode->i_gid = attr->ia_gid;
1486 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1487 +               inode->i_tag = attr->ia_tag;
1488         if (ia_valid & ATTR_ATIME)
1489                 inode->i_atime = timespec_trunc(attr->ia_atime,
1490                                                 inode->i_sb->s_time_gran);
1491 @@ -197,7 +206,8 @@ int notify_change(struct dentry * dentry
1492  
1493         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1494  
1495 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1496 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1497 +               ATTR_TAG | ATTR_TIMES_SET)) {
1498                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1499                         return -EPERM;
1500         }
1501 diff -NurpP --minimal linux-3.13.10/fs/block_dev.c linux-3.13.10-vs2.3.6.11/fs/block_dev.c
1502 --- linux-3.13.10/fs/block_dev.c        2013-11-25 15:46:58.000000000 +0000
1503 +++ linux-3.13.10-vs2.3.6.11/fs/block_dev.c     2014-01-31 20:38:03.000000000 +0000
1504 @@ -28,6 +28,7 @@
1505  #include <linux/log2.h>
1506  #include <linux/cleancache.h>
1507  #include <linux/aio.h>
1508 +#include <linux/vs_device.h>
1509  #include <asm/uaccess.h>
1510  #include "internal.h"
1511  
1512 @@ -515,6 +516,7 @@ struct block_device *bdget(dev_t dev)
1513                 bdev->bd_invalidated = 0;
1514                 inode->i_mode = S_IFBLK;
1515                 inode->i_rdev = dev;
1516 +               inode->i_mdev = dev;
1517                 inode->i_bdev = bdev;
1518                 inode->i_data.a_ops = &def_blk_aops;
1519                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1520 @@ -562,6 +564,11 @@ EXPORT_SYMBOL(bdput);
1521  static struct block_device *bd_acquire(struct inode *inode)
1522  {
1523         struct block_device *bdev;
1524 +       dev_t mdev;
1525 +
1526 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1527 +               return NULL;
1528 +       inode->i_mdev = mdev;
1529  
1530         spin_lock(&bdev_lock);
1531         bdev = inode->i_bdev;
1532 @@ -572,7 +579,7 @@ static struct block_device *bd_acquire(s
1533         }
1534         spin_unlock(&bdev_lock);
1535  
1536 -       bdev = bdget(inode->i_rdev);
1537 +       bdev = bdget(mdev);
1538         if (bdev) {
1539                 spin_lock(&bdev_lock);
1540                 if (!inode->i_bdev) {
1541 diff -NurpP --minimal linux-3.13.10/fs/btrfs/ctree.h linux-3.13.10-vs2.3.6.11/fs/btrfs/ctree.h
1542 --- linux-3.13.10/fs/btrfs/ctree.h      2014-01-22 20:39:05.000000000 +0000
1543 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/ctree.h   2014-01-31 23:58:35.000000000 +0000
1544 @@ -718,11 +718,14 @@ struct btrfs_inode_item {
1545         /* modification sequence number for NFS */
1546         __le64 sequence;
1547  
1548 +       __le16 tag;
1549         /*
1550          * a little future expansion, for more than this we can
1551          * just grow the inode item and version it
1552          */
1553 -       __le64 reserved[4];
1554 +       __le16 reserved16;
1555 +       __le32 reserved32;
1556 +       __le64 reserved[3];
1557         struct btrfs_timespec atime;
1558         struct btrfs_timespec ctime;
1559         struct btrfs_timespec mtime;
1560 @@ -2000,6 +2003,8 @@ struct btrfs_ioctl_defrag_range_args {
1561  
1562  #define BTRFS_DEFAULT_COMMIT_INTERVAL  (30)
1563  
1564 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1565 +
1566  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1567  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1568  #define btrfs_raw_test_opt(o, opt)     ((o) & BTRFS_MOUNT_##opt)
1569 @@ -2269,6 +2274,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1570  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1571  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1572  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1573 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1574  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1575  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1576  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1577 @@ -2341,6 +2347,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1578  
1579  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1580  
1581 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1582 +#define BTRFS_INODE_BARRIER            (1 << 25)
1583 +#define BTRFS_INODE_COW                        (1 << 26)
1584 +
1585  
1586  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1587  
1588 @@ -3722,6 +3732,7 @@ long btrfs_ioctl(struct file *file, unsi
1589  void btrfs_update_iflags(struct inode *inode);
1590  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1591  int btrfs_is_empty_uuid(u8 *uuid);
1592 +int btrfs_sync_flags(struct inode *inode, int, int);
1593  int btrfs_defrag_file(struct inode *inode, struct file *file,
1594                       struct btrfs_ioctl_defrag_range_args *range,
1595                       u64 newer_than, unsigned long max_pages);
1596 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
1597 --- linux-3.13.10/fs/btrfs/disk-io.c    2014-01-22 20:39:05.000000000 +0000
1598 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/disk-io.c 2014-01-31 20:38:03.000000000 +0000
1599 @@ -2388,6 +2388,9 @@ int open_ctree(struct super_block *sb,
1600                 goto fail_alloc;
1601         }
1602  
1603 +       if (btrfs_test_opt(tree_root, TAGGED))
1604 +               sb->s_flags |= MS_TAGGED;
1605 +
1606         features = btrfs_super_incompat_flags(disk_super) &
1607                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1608         if (features) {
1609 diff -NurpP --minimal linux-3.13.10/fs/btrfs/inode.c linux-3.13.10-vs2.3.6.11/fs/btrfs/inode.c
1610 --- linux-3.13.10/fs/btrfs/inode.c      2014-04-17 01:12:31.000000000 +0000
1611 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/inode.c   2014-03-12 15:51:07.000000000 +0000
1612 @@ -43,6 +43,7 @@
1613  #include <linux/btrfs.h>
1614  #include <linux/blkdev.h>
1615  #include <linux/posix_acl_xattr.h>
1616 +#include <linux/vs_tag.h>
1617  #include "ctree.h"
1618  #include "disk-io.h"
1619  #include "transaction.h"
1620 @@ -3317,6 +3318,9 @@ static void btrfs_read_locked_inode(stru
1621         struct btrfs_key location;
1622         int maybe_acls;
1623         u32 rdev;
1624 +       kuid_t kuid;
1625 +       kgid_t kgid;
1626 +       ktag_t ktag;
1627         int ret;
1628         bool filled = false;
1629  
1630 @@ -3344,8 +3348,14 @@ static void btrfs_read_locked_inode(stru
1631                                     struct btrfs_inode_item);
1632         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1633         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1634 -       i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1635 -       i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1636 +
1637 +       kuid = make_kuid(&init_user_ns, btrfs_inode_uid(leaf, inode_item));
1638 +       kgid = make_kgid(&init_user_ns, btrfs_inode_gid(leaf, inode_item));
1639 +       ktag = make_ktag(&init_user_ns, btrfs_inode_tag(leaf, inode_item));
1640 +
1641 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
1642 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
1643 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
1644         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1645  
1646         tspec = btrfs_inode_atime(inode_item);
1647 @@ -3436,11 +3446,18 @@ static void fill_inode_item(struct btrfs
1648                             struct inode *inode)
1649  {
1650         struct btrfs_map_token token;
1651 +       uid_t uid = from_kuid(&init_user_ns,
1652 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
1653 +       gid_t gid = from_kgid(&init_user_ns,
1654 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
1655  
1656         btrfs_init_map_token(&token);
1657  
1658 -       btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1659 -       btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1660 +       btrfs_set_token_inode_uid(leaf, item, uid, &token);
1661 +       btrfs_set_token_inode_gid(leaf, item, gid, &token);
1662 +#ifdef CONFIG_TAGGING_INTERN
1663 +       btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1664 +#endif
1665         btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1666                                    &token);
1667         btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1668 @@ -8652,12 +8669,15 @@ static const struct inode_operations btr
1669         .listxattr      = btrfs_listxattr,
1670         .removexattr    = btrfs_removexattr,
1671         .permission     = btrfs_permission,
1672 +       .sync_flags     = btrfs_sync_flags,
1673         .get_acl        = btrfs_get_acl,
1674         .update_time    = btrfs_update_time,
1675  };
1676 +
1677  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1678         .lookup         = btrfs_lookup,
1679         .permission     = btrfs_permission,
1680 +       .sync_flags     = btrfs_sync_flags,
1681         .get_acl        = btrfs_get_acl,
1682         .update_time    = btrfs_update_time,
1683  };
1684 @@ -8727,6 +8747,7 @@ static const struct inode_operations btr
1685         .removexattr    = btrfs_removexattr,
1686         .permission     = btrfs_permission,
1687         .fiemap         = btrfs_fiemap,
1688 +       .sync_flags     = btrfs_sync_flags,
1689         .get_acl        = btrfs_get_acl,
1690         .update_time    = btrfs_update_time,
1691  };
1692 diff -NurpP --minimal linux-3.13.10/fs/btrfs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/btrfs/ioctl.c
1693 --- linux-3.13.10/fs/btrfs/ioctl.c      2014-04-17 01:12:31.000000000 +0000
1694 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/ioctl.c   2014-02-25 11:26:09.000000000 +0000
1695 @@ -78,10 +78,13 @@ static unsigned int btrfs_flags_to_ioctl
1696  {
1697         unsigned int iflags = 0;
1698  
1699 -       if (flags & BTRFS_INODE_SYNC)
1700 -               iflags |= FS_SYNC_FL;
1701         if (flags & BTRFS_INODE_IMMUTABLE)
1702                 iflags |= FS_IMMUTABLE_FL;
1703 +       if (flags & BTRFS_INODE_IXUNLINK)
1704 +               iflags |= FS_IXUNLINK_FL;
1705 +
1706 +       if (flags & BTRFS_INODE_SYNC)
1707 +               iflags |= FS_SYNC_FL;
1708         if (flags & BTRFS_INODE_APPEND)
1709                 iflags |= FS_APPEND_FL;
1710         if (flags & BTRFS_INODE_NODUMP)
1711 @@ -98,28 +101,78 @@ static unsigned int btrfs_flags_to_ioctl
1712         else if (flags & BTRFS_INODE_NOCOMPRESS)
1713                 iflags |= FS_NOCOMP_FL;
1714  
1715 +       if (flags & BTRFS_INODE_BARRIER)
1716 +               iflags |= FS_BARRIER_FL;
1717 +       if (flags & BTRFS_INODE_COW)
1718 +               iflags |= FS_COW_FL;
1719         return iflags;
1720  }
1721  
1722  /*
1723 - * Update inode->i_flags based on the btrfs internal flags.
1724 + * Update inode->i_(v)flags based on the btrfs internal flags.
1725   */
1726  void btrfs_update_iflags(struct inode *inode)
1727  {
1728         struct btrfs_inode *ip = BTRFS_I(inode);
1729  
1730 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1731 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1732 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1733  
1734 -       if (ip->flags & BTRFS_INODE_SYNC)
1735 -               inode->i_flags |= S_SYNC;
1736         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1737                 inode->i_flags |= S_IMMUTABLE;
1738 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1739 +               inode->i_flags |= S_IXUNLINK;
1740 +
1741 +       if (ip->flags & BTRFS_INODE_SYNC)
1742 +               inode->i_flags |= S_SYNC;
1743         if (ip->flags & BTRFS_INODE_APPEND)
1744                 inode->i_flags |= S_APPEND;
1745         if (ip->flags & BTRFS_INODE_NOATIME)
1746                 inode->i_flags |= S_NOATIME;
1747         if (ip->flags & BTRFS_INODE_DIRSYNC)
1748                 inode->i_flags |= S_DIRSYNC;
1749 +
1750 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1751 +
1752 +       if (ip->flags & BTRFS_INODE_BARRIER)
1753 +               inode->i_vflags |= V_BARRIER;
1754 +       if (ip->flags & BTRFS_INODE_COW)
1755 +               inode->i_vflags |= V_COW;
1756 +}
1757 +
1758 +/*
1759 + * Update btrfs internal flags from inode->i_(v)flags.
1760 + */
1761 +void btrfs_update_flags(struct inode *inode)
1762 +{
1763 +       struct btrfs_inode *ip = BTRFS_I(inode);
1764 +
1765 +       unsigned int flags = inode->i_flags;
1766 +       unsigned int vflags = inode->i_vflags;
1767 +
1768 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1769 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1770 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1771 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1772 +
1773 +       if (flags & S_IMMUTABLE)
1774 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1775 +       if (flags & S_IXUNLINK)
1776 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1777 +
1778 +       if (flags & S_SYNC)
1779 +               ip->flags |= BTRFS_INODE_SYNC;
1780 +       if (flags & S_APPEND)
1781 +               ip->flags |= BTRFS_INODE_APPEND;
1782 +       if (flags & S_NOATIME)
1783 +               ip->flags |= BTRFS_INODE_NOATIME;
1784 +       if (flags & S_DIRSYNC)
1785 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1786 +
1787 +       if (vflags & V_BARRIER)
1788 +               ip->flags |= BTRFS_INODE_BARRIER;
1789 +       if (vflags & V_COW)
1790 +               ip->flags |= BTRFS_INODE_COW;
1791  }
1792  
1793  /*
1794 @@ -135,6 +188,7 @@ void btrfs_inherit_iflags(struct inode *
1795                 return;
1796  
1797         flags = BTRFS_I(dir)->flags;
1798 +       flags &= ~BTRFS_INODE_BARRIER;
1799  
1800         if (flags & BTRFS_INODE_NOCOMPRESS) {
1801                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1802 @@ -153,6 +207,30 @@ void btrfs_inherit_iflags(struct inode *
1803         btrfs_update_iflags(inode);
1804  }
1805  
1806 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1807 +{
1808 +       struct btrfs_inode *ip = BTRFS_I(inode);
1809 +       struct btrfs_root *root = ip->root;
1810 +       struct btrfs_trans_handle *trans;
1811 +       int ret;
1812 +
1813 +       trans = btrfs_join_transaction(root);
1814 +       BUG_ON(!trans);
1815 +
1816 +       inode->i_flags = flags;
1817 +       inode->i_vflags = vflags;
1818 +       btrfs_update_flags(inode);
1819 +
1820 +       ret = btrfs_update_inode(trans, root, inode);
1821 +       BUG_ON(ret);
1822 +
1823 +       btrfs_update_iflags(inode);
1824 +       inode->i_ctime = CURRENT_TIME;
1825 +       btrfs_end_transaction(trans, root);
1826 +
1827 +       return 0;
1828 +}
1829 +
1830  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1831  {
1832         struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1833 @@ -215,21 +293,27 @@ static int btrfs_ioctl_setflags(struct f
1834  
1835         flags = btrfs_mask_flags(inode->i_mode, flags);
1836         oldflags = btrfs_flags_to_ioctl(ip->flags);
1837 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1838 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1839 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1840                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1841                         ret = -EPERM;
1842                         goto out_unlock;
1843                 }
1844         }
1845  
1846 -       if (flags & FS_SYNC_FL)
1847 -               ip->flags |= BTRFS_INODE_SYNC;
1848 -       else
1849 -               ip->flags &= ~BTRFS_INODE_SYNC;
1850         if (flags & FS_IMMUTABLE_FL)
1851                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1852         else
1853                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1854 +       if (flags & FS_IXUNLINK_FL)
1855 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1856 +       else
1857 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1858 +
1859 +       if (flags & FS_SYNC_FL)
1860 +               ip->flags |= BTRFS_INODE_SYNC;
1861 +       else
1862 +               ip->flags &= ~BTRFS_INODE_SYNC;
1863         if (flags & FS_APPEND_FL)
1864                 ip->flags |= BTRFS_INODE_APPEND;
1865         else
1866 diff -NurpP --minimal linux-3.13.10/fs/btrfs/super.c linux-3.13.10-vs2.3.6.11/fs/btrfs/super.c
1867 --- linux-3.13.10/fs/btrfs/super.c      2014-01-22 20:39:05.000000000 +0000
1868 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/super.c   2014-01-31 23:58:08.000000000 +0000
1869 @@ -323,7 +323,7 @@ enum {
1870         Opt_check_integrity, Opt_check_integrity_including_extent_data,
1871         Opt_check_integrity_print_mask, Opt_fatal_errors, Opt_rescan_uuid_tree,
1872         Opt_commit_interval,
1873 -       Opt_err,
1874 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1875  };
1876  
1877  static match_table_t tokens = {
1878 @@ -365,6 +365,9 @@ static match_table_t tokens = {
1879         {Opt_rescan_uuid_tree, "rescan_uuid_tree"},
1880         {Opt_fatal_errors, "fatal_errors=%s"},
1881         {Opt_commit_interval, "commit=%d"},
1882 +       {Opt_tag, "tag"},
1883 +       {Opt_notag, "notag"},
1884 +       {Opt_tagid, "tagid=%u"},
1885         {Opt_err, NULL},
1886  };
1887  
1888 @@ -674,6 +677,22 @@ int btrfs_parse_options(struct btrfs_roo
1889                                 info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
1890                         }
1891                         break;
1892 +#ifndef CONFIG_TAGGING_NONE
1893 +               case Opt_tag:
1894 +                       printk(KERN_INFO "btrfs: use tagging\n");
1895 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1896 +                       break;
1897 +               case Opt_notag:
1898 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
1899 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
1900 +                       break;
1901 +#endif
1902 +#ifdef CONFIG_PROPAGATE
1903 +               case Opt_tagid:
1904 +                       /* use args[0] */
1905 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1906 +                       break;
1907 +#endif
1908                 case Opt_err:
1909                         printk(KERN_INFO "btrfs: unrecognized mount option "
1910                                "'%s'\n", p);
1911 @@ -1320,6 +1339,12 @@ static int btrfs_remount(struct super_bl
1912         btrfs_resize_thread_pool(fs_info,
1913                 fs_info->thread_pool_size, old_thread_pool_size);
1914  
1915 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1916 +               printk("btrfs: %s: tagging not permitted on remount.\n",
1917 +                       sb->s_id);
1918 +               return -EINVAL;
1919 +       }
1920 +
1921         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1922                 goto out;
1923  
1924 diff -NurpP --minimal linux-3.13.10/fs/char_dev.c linux-3.13.10-vs2.3.6.11/fs/char_dev.c
1925 --- linux-3.13.10/fs/char_dev.c 2014-01-22 20:39:05.000000000 +0000
1926 +++ linux-3.13.10-vs2.3.6.11/fs/char_dev.c      2014-01-31 20:38:03.000000000 +0000
1927 @@ -21,6 +21,8 @@
1928  #include <linux/mutex.h>
1929  #include <linux/backing-dev.h>
1930  #include <linux/tty.h>
1931 +#include <linux/vs_context.h>
1932 +#include <linux/vs_device.h>
1933  
1934  #include "internal.h"
1935  
1936 @@ -372,14 +374,21 @@ static int chrdev_open(struct inode *ino
1937         struct cdev *p;
1938         struct cdev *new = NULL;
1939         int ret = 0;
1940 +       dev_t mdev;
1941 +
1942 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
1943 +               return -EPERM;
1944 +       inode->i_mdev = mdev;
1945  
1946         spin_lock(&cdev_lock);
1947         p = inode->i_cdev;
1948         if (!p) {
1949                 struct kobject *kobj;
1950                 int idx;
1951 +
1952                 spin_unlock(&cdev_lock);
1953 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
1954 +
1955 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
1956                 if (!kobj)
1957                         return -ENXIO;
1958                 new = container_of(kobj, struct cdev, kobj);
1959 diff -NurpP --minimal linux-3.13.10/fs/dcache.c linux-3.13.10-vs2.3.6.11/fs/dcache.c
1960 --- linux-3.13.10/fs/dcache.c   2014-04-17 01:12:32.000000000 +0000
1961 +++ linux-3.13.10-vs2.3.6.11/fs/dcache.c        2014-04-17 01:17:10.000000000 +0000
1962 @@ -38,6 +38,7 @@
1963  #include <linux/prefetch.h>
1964  #include <linux/ratelimit.h>
1965  #include <linux/list_lru.h>
1966 +#include <linux/vs_limit.h>
1967  #include "internal.h"
1968  #include "mount.h"
1969  
1970 @@ -640,6 +641,8 @@ int d_invalidate(struct dentry * dentry)
1971                 spin_lock(&dentry->d_lock);
1972         }
1973  
1974 +       vx_dentry_dec(dentry);
1975 +
1976         /*
1977          * Somebody else still using it?
1978          *
1979 @@ -669,6 +672,7 @@ EXPORT_SYMBOL(d_invalidate);
1980  static inline void __dget_dlock(struct dentry *dentry)
1981  {
1982         dentry->d_lockref.count++;
1983 +       vx_dentry_inc(dentry);
1984  }
1985  
1986  static inline void __dget(struct dentry *dentry)
1987 @@ -1483,6 +1487,9 @@ struct dentry *__d_alloc(struct super_bl
1988         struct dentry *dentry;
1989         char *dname;
1990  
1991 +       if (!vx_dentry_avail(1))
1992 +               return NULL;
1993 +
1994         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
1995         if (!dentry)
1996                 return NULL;
1997 @@ -1515,6 +1522,7 @@ struct dentry *__d_alloc(struct super_bl
1998  
1999         dentry->d_lockref.count = 1;
2000         dentry->d_flags = 0;
2001 +       vx_dentry_inc(dentry);
2002         spin_lock_init(&dentry->d_lock);
2003         seqcount_init(&dentry->d_seq);
2004         dentry->d_inode = NULL;
2005 @@ -2278,6 +2286,7 @@ struct dentry *__d_lookup(const struct d
2006                 }
2007  
2008                 dentry->d_lockref.count++;
2009 +               vx_dentry_inc(dentry);
2010                 found = dentry;
2011                 spin_unlock(&dentry->d_lock);
2012                 break;
2013 diff -NurpP --minimal linux-3.13.10/fs/devpts/inode.c linux-3.13.10-vs2.3.6.11/fs/devpts/inode.c
2014 --- linux-3.13.10/fs/devpts/inode.c     2014-01-22 20:39:06.000000000 +0000
2015 +++ linux-3.13.10-vs2.3.6.11/fs/devpts/inode.c  2014-02-01 01:40:53.000000000 +0000
2016 @@ -25,6 +25,7 @@
2017  #include <linux/parser.h>
2018  #include <linux/fsnotify.h>
2019  #include <linux/seq_file.h>
2020 +#include <linux/vs_base.h>
2021  
2022  #define DEVPTS_DEFAULT_MODE 0600
2023  /*
2024 @@ -36,6 +37,21 @@
2025  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2026  #define PTMX_MINOR     2
2027  
2028 +static int devpts_permission(struct inode *inode, int mask)
2029 +{
2030 +       int ret = -EACCES;
2031 +
2032 +       /* devpts is xid tagged */
2033 +       if (vx_check((vxid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2034 +               ret = generic_permission(inode, mask);
2035 +       return ret;
2036 +}
2037 +
2038 +static struct inode_operations devpts_file_inode_operations = {
2039 +       .permission     = devpts_permission,
2040 +};
2041 +
2042 +
2043  /*
2044   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2045   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2046 @@ -345,6 +361,34 @@ static int devpts_show_options(struct se
2047         return 0;
2048  }
2049  
2050 +static int devpts_filter(struct dentry *de)
2051 +{
2052 +       vxid_t xid = 0;
2053 +
2054 +       /* devpts is xid tagged */
2055 +       if (de && de->d_inode)
2056 +               xid = (vxid_t)i_tag_read(de->d_inode);
2057 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2058 +       else
2059 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2060 +                       de->d_name.len, de->d_name.name);
2061 +#endif
2062 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2063 +}
2064 +
2065 +static int devpts_readdir(struct file * filp, struct dir_context *ctx)
2066 +{
2067 +       return dcache_readdir_filter(filp, ctx, devpts_filter);
2068 +}
2069 +
2070 +static struct file_operations devpts_dir_operations = {
2071 +       .open           = dcache_dir_open,
2072 +       .release        = dcache_dir_close,
2073 +       .llseek         = dcache_dir_lseek,
2074 +       .read           = generic_read_dir,
2075 +       .iterate        = devpts_readdir,
2076 +};
2077 +
2078  static const struct super_operations devpts_sops = {
2079         .statfs         = simple_statfs,
2080         .remount_fs     = devpts_remount,
2081 @@ -388,8 +432,10 @@ devpts_fill_super(struct super_block *s,
2082         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2083         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2084         inode->i_op = &simple_dir_inode_operations;
2085 -       inode->i_fop = &simple_dir_operations;
2086 +       inode->i_fop = &devpts_dir_operations;
2087         set_nlink(inode, 2);
2088 +       /* devpts is xid tagged */
2089 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2090  
2091         s->s_root = d_make_root(inode);
2092         if (s->s_root)
2093 @@ -593,6 +639,9 @@ struct inode *devpts_pty_new(struct inod
2094         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2095         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2096         init_special_inode(inode, S_IFCHR|opts->mode, device);
2097 +       /* devpts is xid tagged */
2098 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2099 +       inode->i_op = &devpts_file_inode_operations;
2100         inode->i_private = priv;
2101  
2102         sprintf(s, "%d", index);
2103 diff -NurpP --minimal linux-3.13.10/fs/ext2/balloc.c linux-3.13.10-vs2.3.6.11/fs/ext2/balloc.c
2104 --- linux-3.13.10/fs/ext2/balloc.c      2013-05-31 13:45:23.000000000 +0000
2105 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/balloc.c   2014-01-31 20:38:03.000000000 +0000
2106 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2107                         start = 0;
2108                 end = EXT2_BLOCKS_PER_GROUP(sb);
2109         }
2110 -
2111         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2112  
2113  repeat:
2114 diff -NurpP --minimal linux-3.13.10/fs/ext2/ext2.h linux-3.13.10-vs2.3.6.11/fs/ext2/ext2.h
2115 --- linux-3.13.10/fs/ext2/ext2.h        2012-12-11 03:30:57.000000000 +0000
2116 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ext2.h     2014-01-31 20:38:03.000000000 +0000
2117 @@ -244,8 +244,12 @@ struct ext2_group_desc
2118  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2119  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2120  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2121 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2122  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2123  
2124 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2125 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2126 +
2127  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2128  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2129  
2130 @@ -329,7 +333,8 @@ struct ext2_inode {
2131                         __u16   i_pad1;
2132                         __le16  l_i_uid_high;   /* these 2 fields    */
2133                         __le16  l_i_gid_high;   /* were reserved2[0] */
2134 -                       __u32   l_i_reserved2;
2135 +                       __le16  l_i_tag;        /* Context Tag */
2136 +                       __u16   l_i_reserved2;
2137                 } linux2;
2138                 struct {
2139                         __u8    h_i_frag;       /* Fragment number */
2140 @@ -357,6 +362,7 @@ struct ext2_inode {
2141  #define i_gid_low      i_gid
2142  #define i_uid_high     osd2.linux2.l_i_uid_high
2143  #define i_gid_high     osd2.linux2.l_i_gid_high
2144 +#define i_raw_tag      osd2.linux2.l_i_tag
2145  #define i_reserved2    osd2.linux2.l_i_reserved2
2146  
2147  /*
2148 @@ -384,6 +390,7 @@ struct ext2_inode {
2149  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2150  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2151  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2152 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2153  
2154  
2155  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2156 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2157  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2158  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2159                        u64 start, u64 len);
2160 +extern int ext2_sync_flags(struct inode *, int, int);
2161  
2162  /* ioctl.c */
2163  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2164 diff -NurpP --minimal linux-3.13.10/fs/ext2/file.c linux-3.13.10-vs2.3.6.11/fs/ext2/file.c
2165 --- linux-3.13.10/fs/ext2/file.c        2012-12-11 03:30:57.000000000 +0000
2166 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/file.c     2014-01-31 20:38:03.000000000 +0000
2167 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2168         .setattr        = ext2_setattr,
2169         .get_acl        = ext2_get_acl,
2170         .fiemap         = ext2_fiemap,
2171 +       .sync_flags     = ext2_sync_flags,
2172  };
2173 diff -NurpP --minimal linux-3.13.10/fs/ext2/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext2/ialloc.c
2174 --- linux-3.13.10/fs/ext2/ialloc.c      2013-05-31 13:45:23.000000000 +0000
2175 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ialloc.c   2014-01-31 20:38:03.000000000 +0000
2176 @@ -17,6 +17,7 @@
2177  #include <linux/backing-dev.h>
2178  #include <linux/buffer_head.h>
2179  #include <linux/random.h>
2180 +#include <linux/vs_tag.h>
2181  #include "ext2.h"
2182  #include "xattr.h"
2183  #include "acl.h"
2184 @@ -546,6 +547,7 @@ got:
2185                 inode->i_mode = mode;
2186                 inode->i_uid = current_fsuid();
2187                 inode->i_gid = dir->i_gid;
2188 +               i_tag_write(inode, dx_current_fstag(sb));
2189         } else
2190                 inode_init_owner(inode, dir, mode);
2191  
2192 diff -NurpP --minimal linux-3.13.10/fs/ext2/inode.c linux-3.13.10-vs2.3.6.11/fs/ext2/inode.c
2193 --- linux-3.13.10/fs/ext2/inode.c       2014-01-22 20:39:06.000000000 +0000
2194 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/inode.c    2014-01-31 20:38:03.000000000 +0000
2195 @@ -32,6 +32,7 @@
2196  #include <linux/fiemap.h>
2197  #include <linux/namei.h>
2198  #include <linux/aio.h>
2199 +#include <linux/vs_tag.h>
2200  #include "ext2.h"
2201  #include "acl.h"
2202  #include "xip.h"
2203 @@ -1182,7 +1183,7 @@ static void ext2_truncate_blocks(struct
2204                 return;
2205         if (ext2_inode_is_fast_symlink(inode))
2206                 return;
2207 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2208 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2209                 return;
2210         __ext2_truncate_blocks(inode, offset);
2211  }
2212 @@ -1273,36 +1274,61 @@ void ext2_set_inode_flags(struct inode *
2213  {
2214         unsigned int flags = EXT2_I(inode)->i_flags;
2215  
2216 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2217 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2218 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2219 +
2220 +
2221 +       if (flags & EXT2_IMMUTABLE_FL)
2222 +               inode->i_flags |= S_IMMUTABLE;
2223 +       if (flags & EXT2_IXUNLINK_FL)
2224 +               inode->i_flags |= S_IXUNLINK;
2225 +
2226         if (flags & EXT2_SYNC_FL)
2227                 inode->i_flags |= S_SYNC;
2228         if (flags & EXT2_APPEND_FL)
2229                 inode->i_flags |= S_APPEND;
2230 -       if (flags & EXT2_IMMUTABLE_FL)
2231 -               inode->i_flags |= S_IMMUTABLE;
2232         if (flags & EXT2_NOATIME_FL)
2233                 inode->i_flags |= S_NOATIME;
2234         if (flags & EXT2_DIRSYNC_FL)
2235                 inode->i_flags |= S_DIRSYNC;
2236 +
2237 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2238 +
2239 +       if (flags & EXT2_BARRIER_FL)
2240 +               inode->i_vflags |= V_BARRIER;
2241 +       if (flags & EXT2_COW_FL)
2242 +               inode->i_vflags |= V_COW;
2243  }
2244  
2245  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2246  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2247  {
2248         unsigned int flags = ei->vfs_inode.i_flags;
2249 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2250 +
2251 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2252 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2253 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2254 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2255 +
2256 +       if (flags & S_IMMUTABLE)
2257 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2258 +       if (flags & S_IXUNLINK)
2259 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2260  
2261 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2262 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2263         if (flags & S_SYNC)
2264                 ei->i_flags |= EXT2_SYNC_FL;
2265         if (flags & S_APPEND)
2266                 ei->i_flags |= EXT2_APPEND_FL;
2267 -       if (flags & S_IMMUTABLE)
2268 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2269         if (flags & S_NOATIME)
2270                 ei->i_flags |= EXT2_NOATIME_FL;
2271         if (flags & S_DIRSYNC)
2272                 ei->i_flags |= EXT2_DIRSYNC_FL;
2273 +
2274 +       if (vflags & V_BARRIER)
2275 +               ei->i_flags |= EXT2_BARRIER_FL;
2276 +       if (vflags & V_COW)
2277 +               ei->i_flags |= EXT2_COW_FL;
2278  }
2279  
2280  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2281 @@ -1338,8 +1364,10 @@ struct inode *ext2_iget (struct super_bl
2282                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2283                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2284         }
2285 -       i_uid_write(inode, i_uid);
2286 -       i_gid_write(inode, i_gid);
2287 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2288 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2289 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2290 +               le16_to_cpu(raw_inode->i_raw_tag)));
2291         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2292         inode->i_size = le32_to_cpu(raw_inode->i_size);
2293         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2294 @@ -1437,8 +1465,10 @@ static int __ext2_write_inode(struct ino
2295         struct ext2_inode_info *ei = EXT2_I(inode);
2296         struct super_block *sb = inode->i_sb;
2297         ino_t ino = inode->i_ino;
2298 -       uid_t uid = i_uid_read(inode);
2299 -       gid_t gid = i_gid_read(inode);
2300 +       uid_t uid = from_kuid(&init_user_ns,
2301 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2302 +       gid_t gid = from_kgid(&init_user_ns,
2303 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2304         struct buffer_head * bh;
2305         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2306         int n;
2307 @@ -1474,6 +1504,9 @@ static int __ext2_write_inode(struct ino
2308                 raw_inode->i_uid_high = 0;
2309                 raw_inode->i_gid_high = 0;
2310         }
2311 +#ifdef CONFIG_TAGGING_INTERN
2312 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2313 +#endif
2314         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2315         raw_inode->i_size = cpu_to_le32(inode->i_size);
2316         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2317 @@ -1554,7 +1587,8 @@ int ext2_setattr(struct dentry *dentry,
2318         if (is_quota_modification(inode, iattr))
2319                 dquot_initialize(inode);
2320         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2321 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2322 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2323 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2324                 error = dquot_transfer(inode, iattr);
2325                 if (error)
2326                         return error;
2327 diff -NurpP --minimal linux-3.13.10/fs/ext2/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext2/ioctl.c
2328 --- linux-3.13.10/fs/ext2/ioctl.c       2013-05-31 13:45:23.000000000 +0000
2329 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ioctl.c    2014-01-31 20:38:03.000000000 +0000
2330 @@ -17,6 +17,16 @@
2331  #include <asm/uaccess.h>
2332  
2333  
2334 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2335 +{
2336 +       inode->i_flags = flags;
2337 +       inode->i_vflags = vflags;
2338 +       ext2_get_inode_flags(EXT2_I(inode));
2339 +       inode->i_ctime = CURRENT_TIME_SEC;
2340 +       mark_inode_dirty(inode);
2341 +       return 0;
2342 +}
2343 +
2344  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2345  {
2346         struct inode *inode = file_inode(filp);
2347 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2348  
2349                 flags = ext2_mask_flags(inode->i_mode, flags);
2350  
2351 +               if (IS_BARRIER(inode)) {
2352 +                       vxwprintk_task(1, "messing with the barrier.");
2353 +                       return -EACCES;
2354 +               }
2355 +
2356                 mutex_lock(&inode->i_mutex);
2357                 /* Is it quota file? Do not allow user to mess with it */
2358                 if (IS_NOQUOTA(inode)) {
2359 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2360                  *
2361                  * This test looks nicer. Thanks to Pauline Middelink
2362                  */
2363 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2364 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2365 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2366 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2367                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2368                                 mutex_unlock(&inode->i_mutex);
2369                                 ret = -EPERM;
2370 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2371                         }
2372                 }
2373  
2374 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2375 +               flags &= EXT2_FL_USER_MODIFIABLE;
2376                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2377                 ei->i_flags = flags;
2378  
2379 diff -NurpP --minimal linux-3.13.10/fs/ext2/namei.c linux-3.13.10-vs2.3.6.11/fs/ext2/namei.c
2380 --- linux-3.13.10/fs/ext2/namei.c       2013-11-25 15:45:01.000000000 +0000
2381 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/namei.c    2014-01-31 20:38:03.000000000 +0000
2382 @@ -32,6 +32,7 @@
2383  
2384  #include <linux/pagemap.h>
2385  #include <linux/quotaops.h>
2386 +#include <linux/vs_tag.h>
2387  #include "ext2.h"
2388  #include "xattr.h"
2389  #include "acl.h"
2390 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2391                                         (unsigned long) ino);
2392                         return ERR_PTR(-EIO);
2393                 }
2394 +               dx_propagate_tag(nd, inode);
2395         }
2396         return d_splice_alias(inode, dentry);
2397  }
2398 @@ -432,5 +434,6 @@ const struct inode_operations ext2_speci
2399         .removexattr    = generic_removexattr,
2400  #endif
2401         .setattr        = ext2_setattr,
2402 +       .sync_flags     = ext2_sync_flags,
2403         .get_acl        = ext2_get_acl,
2404  };
2405 diff -NurpP --minimal linux-3.13.10/fs/ext2/super.c linux-3.13.10-vs2.3.6.11/fs/ext2/super.c
2406 --- linux-3.13.10/fs/ext2/super.c       2014-01-22 20:39:06.000000000 +0000
2407 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/super.c    2014-01-31 20:38:03.000000000 +0000
2408 @@ -395,7 +395,8 @@ enum {
2409         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2410         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2411         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2412 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2413 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2414 +       Opt_tag, Opt_notag, Opt_tagid
2415  };
2416  
2417  static const match_table_t tokens = {
2418 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2419         {Opt_acl, "acl"},
2420         {Opt_noacl, "noacl"},
2421         {Opt_xip, "xip"},
2422 +       {Opt_tag, "tag"},
2423 +       {Opt_notag, "notag"},
2424 +       {Opt_tagid, "tagid=%u"},
2425         {Opt_grpquota, "grpquota"},
2426         {Opt_ignore, "noquota"},
2427         {Opt_quota, "quota"},
2428 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2429                 case Opt_nouid32:
2430                         set_opt (sbi->s_mount_opt, NO_UID32);
2431                         break;
2432 +#ifndef CONFIG_TAGGING_NONE
2433 +               case Opt_tag:
2434 +                       set_opt (sbi->s_mount_opt, TAGGED);
2435 +                       break;
2436 +               case Opt_notag:
2437 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2438 +                       break;
2439 +#endif
2440 +#ifdef CONFIG_PROPAGATE
2441 +               case Opt_tagid:
2442 +                       /* use args[0] */
2443 +                       set_opt (sbi->s_mount_opt, TAGGED);
2444 +                       break;
2445 +#endif
2446                 case Opt_nocheck:
2447                         clear_opt (sbi->s_mount_opt, CHECK);
2448                         break;
2449 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2450         if (!parse_options((char *) data, sb))
2451                 goto failed_mount;
2452  
2453 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2454 +               sb->s_flags |= MS_TAGGED;
2455         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2456                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2457                  MS_POSIXACL : 0);
2458 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2459                 err = -EINVAL;
2460                 goto restore_opts;
2461         }
2462 +
2463 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2464 +               !(sb->s_flags & MS_TAGGED)) {
2465 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2466 +                      sb->s_id);
2467 +               err = -EINVAL;
2468 +               goto restore_opts;
2469 +       }
2470  
2471         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2472                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2473 diff -NurpP --minimal linux-3.13.10/fs/ext3/ext3.h linux-3.13.10-vs2.3.6.11/fs/ext3/ext3.h
2474 --- linux-3.13.10/fs/ext3/ext3.h        2012-12-11 03:30:57.000000000 +0000
2475 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ext3.h     2014-01-31 20:38:03.000000000 +0000
2476 @@ -151,10 +151,14 @@ struct ext3_group_desc
2477  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2478  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2479  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2480 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2481  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2482  
2483 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2484 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2485 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2486 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2487 +
2488 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2489 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2490  
2491  /* Flags that should be inherited by new inodes from their parent. */
2492  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2493 @@ -290,7 +294,8 @@ struct ext3_inode {
2494                         __u16   i_pad1;
2495                         __le16  l_i_uid_high;   /* these 2 fields    */
2496                         __le16  l_i_gid_high;   /* were reserved2[0] */
2497 -                       __u32   l_i_reserved2;
2498 +                       __le16  l_i_tag;        /* Context Tag */
2499 +                       __u16   l_i_reserved2;
2500                 } linux2;
2501                 struct {
2502                         __u8    h_i_frag;       /* Fragment number */
2503 @@ -320,6 +325,7 @@ struct ext3_inode {
2504  #define i_gid_low      i_gid
2505  #define i_uid_high     osd2.linux2.l_i_uid_high
2506  #define i_gid_high     osd2.linux2.l_i_gid_high
2507 +#define i_raw_tag      osd2.linux2.l_i_tag
2508  #define i_reserved2    osd2.linux2.l_i_reserved2
2509  
2510  /*
2511 @@ -364,6 +370,7 @@ struct ext3_inode {
2512  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2513  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2514                                                   * error in ordered mode */
2515 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2516  
2517  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2518  #ifndef _LINUX_EXT2_FS_H
2519 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2520  extern void ext3_set_aops(struct inode *inode);
2521  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2522                        u64 start, u64 len);
2523 +extern int ext3_sync_flags(struct inode *, int, int);
2524  
2525  /* ioctl.c */
2526  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2527 diff -NurpP --minimal linux-3.13.10/fs/ext3/file.c linux-3.13.10-vs2.3.6.11/fs/ext3/file.c
2528 --- linux-3.13.10/fs/ext3/file.c        2012-12-11 03:30:57.000000000 +0000
2529 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/file.c     2014-01-31 20:38:03.000000000 +0000
2530 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2531  #endif
2532         .get_acl        = ext3_get_acl,
2533         .fiemap         = ext3_fiemap,
2534 +       .sync_flags     = ext3_sync_flags,
2535  };
2536  
2537 diff -NurpP --minimal linux-3.13.10/fs/ext3/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext3/ialloc.c
2538 --- linux-3.13.10/fs/ext3/ialloc.c      2012-12-11 03:30:57.000000000 +0000
2539 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ialloc.c   2014-01-31 20:38:03.000000000 +0000
2540 @@ -14,6 +14,7 @@
2541  
2542  #include <linux/quotaops.h>
2543  #include <linux/random.h>
2544 +#include <linux/vs_tag.h>
2545  
2546  #include "ext3.h"
2547  #include "xattr.h"
2548 @@ -469,6 +470,7 @@ got:
2549                 inode->i_mode = mode;
2550                 inode->i_uid = current_fsuid();
2551                 inode->i_gid = dir->i_gid;
2552 +               i_tag_write(inode, dx_current_fstag(sb));
2553         } else
2554                 inode_init_owner(inode, dir, mode);
2555  
2556 diff -NurpP --minimal linux-3.13.10/fs/ext3/inode.c linux-3.13.10-vs2.3.6.11/fs/ext3/inode.c
2557 --- linux-3.13.10/fs/ext3/inode.c       2013-11-25 15:45:01.000000000 +0000
2558 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/inode.c    2014-01-31 20:38:03.000000000 +0000
2559 @@ -28,6 +28,8 @@
2560  #include <linux/mpage.h>
2561  #include <linux/namei.h>
2562  #include <linux/aio.h>
2563 +#include <linux/vs_tag.h>
2564 +
2565  #include "ext3.h"
2566  #include "xattr.h"
2567  #include "acl.h"
2568 @@ -2855,36 +2857,60 @@ void ext3_set_inode_flags(struct inode *
2569  {
2570         unsigned int flags = EXT3_I(inode)->i_flags;
2571  
2572 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2573 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2574 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2575 +
2576 +       if (flags & EXT3_IMMUTABLE_FL)
2577 +               inode->i_flags |= S_IMMUTABLE;
2578 +       if (flags & EXT3_IXUNLINK_FL)
2579 +               inode->i_flags |= S_IXUNLINK;
2580 +
2581         if (flags & EXT3_SYNC_FL)
2582                 inode->i_flags |= S_SYNC;
2583         if (flags & EXT3_APPEND_FL)
2584                 inode->i_flags |= S_APPEND;
2585 -       if (flags & EXT3_IMMUTABLE_FL)
2586 -               inode->i_flags |= S_IMMUTABLE;
2587         if (flags & EXT3_NOATIME_FL)
2588                 inode->i_flags |= S_NOATIME;
2589         if (flags & EXT3_DIRSYNC_FL)
2590                 inode->i_flags |= S_DIRSYNC;
2591 +
2592 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2593 +
2594 +       if (flags & EXT3_BARRIER_FL)
2595 +               inode->i_vflags |= V_BARRIER;
2596 +       if (flags & EXT3_COW_FL)
2597 +               inode->i_vflags |= V_COW;
2598  }
2599  
2600  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2601  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2602  {
2603         unsigned int flags = ei->vfs_inode.i_flags;
2604 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2605 +
2606 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2607 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2608 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2609 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2610 +
2611 +       if (flags & S_IMMUTABLE)
2612 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2613 +       if (flags & S_IXUNLINK)
2614 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2615  
2616 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2617 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2618         if (flags & S_SYNC)
2619                 ei->i_flags |= EXT3_SYNC_FL;
2620         if (flags & S_APPEND)
2621                 ei->i_flags |= EXT3_APPEND_FL;
2622 -       if (flags & S_IMMUTABLE)
2623 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2624         if (flags & S_NOATIME)
2625                 ei->i_flags |= EXT3_NOATIME_FL;
2626         if (flags & S_DIRSYNC)
2627                 ei->i_flags |= EXT3_DIRSYNC_FL;
2628 +
2629 +       if (vflags & V_BARRIER)
2630 +               ei->i_flags |= EXT3_BARRIER_FL;
2631 +       if (vflags & V_COW)
2632 +               ei->i_flags |= EXT3_COW_FL;
2633  }
2634  
2635  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2636 @@ -2922,8 +2948,10 @@ struct inode *ext3_iget(struct super_blo
2637                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2638                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2639         }
2640 -       i_uid_write(inode, i_uid);
2641 -       i_gid_write(inode, i_gid);
2642 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2643 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2644 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2645 +               le16_to_cpu(raw_inode->i_raw_tag)));
2646         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2647         inode->i_size = le32_to_cpu(raw_inode->i_size);
2648         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2649 @@ -3095,8 +3123,10 @@ again:
2650  
2651         ext3_get_inode_flags(ei);
2652         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2653 -       i_uid = i_uid_read(inode);
2654 -       i_gid = i_gid_read(inode);
2655 +       i_uid = from_kuid(&init_user_ns,
2656 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2657 +       i_gid = from_kgid(&init_user_ns,
2658 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2659         if(!(test_opt(inode->i_sb, NO_UID32))) {
2660                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2661                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2662 @@ -3121,6 +3151,9 @@ again:
2663                 raw_inode->i_uid_high = 0;
2664                 raw_inode->i_gid_high = 0;
2665         }
2666 +#ifdef CONFIG_TAGGING_INTERN
2667 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2668 +#endif
2669         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2670         disksize = cpu_to_le32(ei->i_disksize);
2671         if (disksize != raw_inode->i_size) {
2672 @@ -3289,7 +3322,8 @@ int ext3_setattr(struct dentry *dentry,
2673         if (is_quota_modification(inode, attr))
2674                 dquot_initialize(inode);
2675         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2676 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2677 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2678 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2679                 handle_t *handle;
2680  
2681                 /* (user+group)*(old+new) structure, inode write (sb,
2682 @@ -3311,6 +3345,8 @@ int ext3_setattr(struct dentry *dentry,
2683                         inode->i_uid = attr->ia_uid;
2684                 if (attr->ia_valid & ATTR_GID)
2685                         inode->i_gid = attr->ia_gid;
2686 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2687 +                       inode->i_tag = attr->ia_tag;
2688                 error = ext3_mark_inode_dirty(handle, inode);
2689                 ext3_journal_stop(handle);
2690         }
2691 diff -NurpP --minimal linux-3.13.10/fs/ext3/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext3/ioctl.c
2692 --- linux-3.13.10/fs/ext3/ioctl.c       2013-05-31 13:45:23.000000000 +0000
2693 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ioctl.c    2014-01-31 20:38:03.000000000 +0000
2694 @@ -12,6 +12,34 @@
2695  #include <asm/uaccess.h>
2696  #include "ext3.h"
2697  
2698 +
2699 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2700 +{
2701 +       handle_t *handle = NULL;
2702 +       struct ext3_iloc iloc;
2703 +       int err;
2704 +
2705 +       handle = ext3_journal_start(inode, 1);
2706 +       if (IS_ERR(handle))
2707 +               return PTR_ERR(handle);
2708 +
2709 +       if (IS_SYNC(inode))
2710 +               handle->h_sync = 1;
2711 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2712 +       if (err)
2713 +               goto flags_err;
2714 +
2715 +       inode->i_flags = flags;
2716 +       inode->i_vflags = vflags;
2717 +       ext3_get_inode_flags(EXT3_I(inode));
2718 +       inode->i_ctime = CURRENT_TIME_SEC;
2719 +
2720 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2721 +flags_err:
2722 +       ext3_journal_stop(handle);
2723 +       return err;
2724 +}
2725 +
2726  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2727  {
2728         struct inode *inode = file_inode(filp);
2729 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2730  
2731                 flags = ext3_mask_flags(inode->i_mode, flags);
2732  
2733 +               if (IS_BARRIER(inode)) {
2734 +                       vxwprintk_task(1, "messing with the barrier.");
2735 +                       return -EACCES;
2736 +               }
2737 +
2738                 mutex_lock(&inode->i_mutex);
2739  
2740                 /* Is it quota file? Do not allow user to mess with it */
2741 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2742                  *
2743                  * This test looks nicer. Thanks to Pauline Middelink
2744                  */
2745 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2746 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2747 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2748 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2749                         if (!capable(CAP_LINUX_IMMUTABLE))
2750                                 goto flags_out;
2751                 }
2752 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2753                 if (err)
2754                         goto flags_err;
2755  
2756 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2757 +               flags &= EXT3_FL_USER_MODIFIABLE;
2758                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2759                 ei->i_flags = flags;
2760  
2761 diff -NurpP --minimal linux-3.13.10/fs/ext3/namei.c linux-3.13.10-vs2.3.6.11/fs/ext3/namei.c
2762 --- linux-3.13.10/fs/ext3/namei.c       2013-11-25 15:46:59.000000000 +0000
2763 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/namei.c    2014-01-31 20:38:03.000000000 +0000
2764 @@ -25,6 +25,8 @@
2765   */
2766  
2767  #include <linux/quotaops.h>
2768 +#include <linux/vs_tag.h>
2769 +
2770  #include "ext3.h"
2771  #include "namei.h"
2772  #include "xattr.h"
2773 @@ -915,6 +917,7 @@ restart:
2774                                         submit_bh(READ | REQ_META | REQ_PRIO,
2775                                                   bh);
2776                                 }
2777 +               dx_propagate_tag(nd, inode);
2778                         }
2779                 }
2780                 if ((bh = bh_use[ra_ptr++]) == NULL)
2781 @@ -2568,6 +2571,7 @@ const struct inode_operations ext3_dir_i
2782         .listxattr      = ext3_listxattr,
2783         .removexattr    = generic_removexattr,
2784  #endif
2785 +       .sync_flags     = ext3_sync_flags,
2786         .get_acl        = ext3_get_acl,
2787  };
2788  
2789 diff -NurpP --minimal linux-3.13.10/fs/ext3/super.c linux-3.13.10-vs2.3.6.11/fs/ext3/super.c
2790 --- linux-3.13.10/fs/ext3/super.c       2014-01-22 20:39:06.000000000 +0000
2791 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/super.c    2014-01-31 20:38:03.000000000 +0000
2792 @@ -826,7 +826,8 @@ enum {
2793         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2794         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2795         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2796 -       Opt_resize, Opt_usrquota, Opt_grpquota
2797 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2798 +       Opt_tag, Opt_notag, Opt_tagid
2799  };
2800  
2801  static const match_table_t tokens = {
2802 @@ -884,6 +885,9 @@ static const match_table_t tokens = {
2803         {Opt_barrier, "barrier"},
2804         {Opt_nobarrier, "nobarrier"},
2805         {Opt_resize, "resize"},
2806 +       {Opt_tag, "tag"},
2807 +       {Opt_notag, "notag"},
2808 +       {Opt_tagid, "tagid=%u"},
2809         {Opt_err, NULL},
2810  };
2811  
2812 @@ -1056,6 +1060,20 @@ static int parse_options (char *options,
2813                 case Opt_nouid32:
2814                         set_opt (sbi->s_mount_opt, NO_UID32);
2815                         break;
2816 +#ifndef CONFIG_TAGGING_NONE
2817 +               case Opt_tag:
2818 +                       set_opt (sbi->s_mount_opt, TAGGED);
2819 +                       break;
2820 +               case Opt_notag:
2821 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2822 +                       break;
2823 +#endif
2824 +#ifdef CONFIG_PROPAGATE
2825 +               case Opt_tagid:
2826 +                       /* use args[0] */
2827 +                       set_opt (sbi->s_mount_opt, TAGGED);
2828 +                       break;
2829 +#endif
2830                 case Opt_nocheck:
2831                         clear_opt (sbi->s_mount_opt, CHECK);
2832                         break;
2833 @@ -1788,6 +1806,9 @@ static int ext3_fill_super (struct super
2834                             NULL, 0))
2835                 goto failed_mount;
2836  
2837 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2838 +               sb->s_flags |= MS_TAGGED;
2839 +
2840         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2841                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2842  
2843 @@ -2683,6 +2704,14 @@ static int ext3_remount (struct super_bl
2844         if (test_opt(sb, ABORT))
2845                 ext3_abort(sb, __func__, "Abort forced by user");
2846  
2847 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2848 +               !(sb->s_flags & MS_TAGGED)) {
2849 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2850 +                       sb->s_id);
2851 +               err = -EINVAL;
2852 +               goto restore_opts;
2853 +       }
2854 +
2855         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2856                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2857  
2858 diff -NurpP --minimal linux-3.13.10/fs/ext4/ext4.h linux-3.13.10-vs2.3.6.11/fs/ext4/ext4.h
2859 --- linux-3.13.10/fs/ext4/ext4.h        2014-04-17 01:12:32.000000000 +0000
2860 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ext4.h     2014-03-12 15:51:07.000000000 +0000
2861 @@ -385,7 +385,10 @@ struct flex_groups {
2862  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2863  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2864  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2865 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2866 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2867  #define EXT4_INLINE_DATA_FL            0x10000000 /* Inode has inline data. */
2868 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
2869  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2870  
2871  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2872 @@ -670,7 +673,7 @@ struct ext4_inode {
2873                         __le16  l_i_uid_high;   /* these 2 fields */
2874                         __le16  l_i_gid_high;   /* were reserved2[0] */
2875                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2876 -                       __le16  l_i_reserved;
2877 +                       __le16  l_i_tag;        /* Context Tag */
2878                 } linux2;
2879                 struct {
2880                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
2881 @@ -790,6 +793,7 @@ do {                                                                               \
2882  #define i_gid_low      i_gid
2883  #define i_uid_high     osd2.linux2.l_i_uid_high
2884  #define i_gid_high     osd2.linux2.l_i_gid_high
2885 +#define i_raw_tag      osd2.linux2.l_i_tag
2886  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
2887  
2888  #elif defined(__GNU__)
2889 @@ -976,6 +980,7 @@ struct ext4_inode_info {
2890  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
2891  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
2892  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
2893 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
2894  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
2895  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
2896  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2897 @@ -2653,6 +2658,7 @@ extern struct buffer_head *ext4_get_firs
2898  extern int ext4_inline_data_fiemap(struct inode *inode,
2899                                    struct fiemap_extent_info *fieinfo,
2900                                    int *has_inline);
2901 +extern int ext4_sync_flags(struct inode *, int, int);
2902  extern int ext4_try_to_evict_inline_data(handle_t *handle,
2903                                          struct inode *inode,
2904                                          int needed);
2905 diff -NurpP --minimal linux-3.13.10/fs/ext4/file.c linux-3.13.10-vs2.3.6.11/fs/ext4/file.c
2906 --- linux-3.13.10/fs/ext4/file.c        2013-11-25 15:46:59.000000000 +0000
2907 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/file.c     2014-01-31 20:38:03.000000000 +0000
2908 @@ -618,5 +618,6 @@ const struct inode_operations ext4_file_
2909         .removexattr    = generic_removexattr,
2910         .get_acl        = ext4_get_acl,
2911         .fiemap         = ext4_fiemap,
2912 +       .sync_flags     = ext4_sync_flags,
2913  };
2914  
2915 diff -NurpP --minimal linux-3.13.10/fs/ext4/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext4/ialloc.c
2916 --- linux-3.13.10/fs/ext4/ialloc.c      2014-01-22 20:39:06.000000000 +0000
2917 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ialloc.c   2014-01-31 20:38:03.000000000 +0000
2918 @@ -22,6 +22,7 @@
2919  #include <linux/random.h>
2920  #include <linux/bitops.h>
2921  #include <linux/blkdev.h>
2922 +#include <linux/vs_tag.h>
2923  #include <asm/byteorder.h>
2924  
2925  #include "ext4.h"
2926 @@ -731,6 +732,7 @@ struct inode *__ext4_new_inode(handle_t
2927                 inode->i_mode = mode;
2928                 inode->i_uid = current_fsuid();
2929                 inode->i_gid = dir->i_gid;
2930 +               i_tag_write(inode, dx_current_fstag(sb));
2931         } else
2932                 inode_init_owner(inode, dir, mode);
2933         dquot_initialize(inode);
2934 diff -NurpP --minimal linux-3.13.10/fs/ext4/inode.c linux-3.13.10-vs2.3.6.11/fs/ext4/inode.c
2935 --- linux-3.13.10/fs/ext4/inode.c       2014-04-17 01:12:32.000000000 +0000
2936 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/inode.c    2014-04-17 01:28:13.000000000 +0000
2937 @@ -39,6 +39,7 @@
2938  #include <linux/ratelimit.h>
2939  #include <linux/aio.h>
2940  #include <linux/bitops.h>
2941 +#include <linux/vs_tag.h>
2942  
2943  #include "ext4_jbd2.h"
2944  #include "xattr.h"
2945 @@ -3929,42 +3930,67 @@ void ext4_set_inode_flags(struct inode *
2946         unsigned int flags = EXT4_I(inode)->i_flags;
2947         unsigned int new_fl = 0;
2948  
2949 +       if (flags & EXT4_IMMUTABLE_FL)
2950 +               new_fl |= S_IMMUTABLE;
2951 +       if (flags & EXT4_IXUNLINK_FL)
2952 +               new_fl |= S_IXUNLINK;
2953 +
2954         if (flags & EXT4_SYNC_FL)
2955                 new_fl |= S_SYNC;
2956         if (flags & EXT4_APPEND_FL)
2957                 new_fl |= S_APPEND;
2958 -       if (flags & EXT4_IMMUTABLE_FL)
2959 -               new_fl |= S_IMMUTABLE;
2960         if (flags & EXT4_NOATIME_FL)
2961                 new_fl |= S_NOATIME;
2962         if (flags & EXT4_DIRSYNC_FL)
2963                 new_fl |= S_DIRSYNC;
2964 +
2965         set_mask_bits(&inode->i_flags,
2966 -                     S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC, new_fl);
2967 +               S_IXUNLINK | S_IMMUTABLE |
2968 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC, new_fl);
2969 +
2970 +       new_fl = 0;
2971 +       if (flags & EXT4_BARRIER_FL)
2972 +               new_fl |= V_BARRIER;
2973 +       if (flags & EXT4_COW_FL)
2974 +               new_fl |= V_COW;
2975 +
2976 +       set_mask_bits(&inode->i_vflags,
2977 +               V_BARRIER | V_COW, new_fl);
2978  }
2979  
2980  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2981  void ext4_get_inode_flags(struct ext4_inode_info *ei)
2982  {
2983 -       unsigned int vfs_fl;
2984 +       unsigned int vfs_fl, vfs_vf;
2985         unsigned long old_fl, new_fl;
2986  
2987         do {
2988                 vfs_fl = ei->vfs_inode.i_flags;
2989 +               vfs_vf = ei->vfs_inode.i_vflags;
2990                 old_fl = ei->i_flags;
2991                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2992                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
2993 -                               EXT4_DIRSYNC_FL);
2994 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
2995 +                               EXT4_COW_FL);
2996 +
2997 +               if (vfs_fl & S_IMMUTABLE)
2998 +                       new_fl |= EXT4_IMMUTABLE_FL;
2999 +               if (vfs_fl & S_IXUNLINK)
3000 +                       new_fl |= EXT4_IXUNLINK_FL;
3001 +
3002                 if (vfs_fl & S_SYNC)
3003                         new_fl |= EXT4_SYNC_FL;
3004                 if (vfs_fl & S_APPEND)
3005                         new_fl |= EXT4_APPEND_FL;
3006 -               if (vfs_fl & S_IMMUTABLE)
3007 -                       new_fl |= EXT4_IMMUTABLE_FL;
3008                 if (vfs_fl & S_NOATIME)
3009                         new_fl |= EXT4_NOATIME_FL;
3010                 if (vfs_fl & S_DIRSYNC)
3011                         new_fl |= EXT4_DIRSYNC_FL;
3012 +
3013 +               if (vfs_vf & V_BARRIER)
3014 +                       new_fl |= EXT4_BARRIER_FL;
3015 +               if (vfs_vf & V_COW)
3016 +                       new_fl |= EXT4_COW_FL;
3017         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3018  }
3019  
3020 @@ -4069,8 +4095,10 @@ struct inode *ext4_iget(struct super_blo
3021                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3022                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3023         }
3024 -       i_uid_write(inode, i_uid);
3025 -       i_gid_write(inode, i_gid);
3026 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3027 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3028 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3029 +               le16_to_cpu(raw_inode->i_raw_tag)));
3030         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3031  
3032         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3033 @@ -4298,8 +4326,10 @@ static int ext4_do_update_inode(handle_t
3034  
3035         ext4_get_inode_flags(ei);
3036         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3037 -       i_uid = i_uid_read(inode);
3038 -       i_gid = i_gid_read(inode);
3039 +       i_uid = from_kuid(&init_user_ns,
3040 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
3041 +       i_gid = from_kgid(&init_user_ns,
3042 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
3043         if (!(test_opt(inode->i_sb, NO_UID32))) {
3044                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3045                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3046 @@ -4322,6 +4352,9 @@ static int ext4_do_update_inode(handle_t
3047                 raw_inode->i_uid_high = 0;
3048                 raw_inode->i_gid_high = 0;
3049         }
3050 +#ifdef CONFIG_TAGGING_INTERN
3051 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3052 +#endif
3053         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3054  
3055         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3056 @@ -4553,7 +4586,8 @@ int ext4_setattr(struct dentry *dentry,
3057         if (is_quota_modification(inode, attr))
3058                 dquot_initialize(inode);
3059         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3060 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3061 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3062 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3063                 handle_t *handle;
3064  
3065                 /* (user+group)*(old+new) structure, inode write (sb,
3066 @@ -4576,6 +4610,8 @@ int ext4_setattr(struct dentry *dentry,
3067                         inode->i_uid = attr->ia_uid;
3068                 if (attr->ia_valid & ATTR_GID)
3069                         inode->i_gid = attr->ia_gid;
3070 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3071 +                       inode->i_tag = attr->ia_tag;
3072                 error = ext4_mark_inode_dirty(handle, inode);
3073                 ext4_journal_stop(handle);
3074         }
3075 diff -NurpP --minimal linux-3.13.10/fs/ext4/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext4/ioctl.c
3076 --- linux-3.13.10/fs/ext4/ioctl.c       2014-04-17 01:12:32.000000000 +0000
3077 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ioctl.c    2014-03-12 15:51:07.000000000 +0000
3078 @@ -14,6 +14,7 @@
3079  #include <linux/compat.h>
3080  #include <linux/mount.h>
3081  #include <linux/file.h>
3082 +#include <linux/vs_tag.h>
3083  #include <asm/uaccess.h>
3084  #include "ext4_jbd2.h"
3085  #include "ext4.h"
3086 @@ -214,6 +215,33 @@ swap_boot_out:
3087         return err;
3088  }
3089  
3090 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3091 +{
3092 +       handle_t *handle = NULL;
3093 +       struct ext4_iloc iloc;
3094 +       int err;
3095 +
3096 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3097 +       if (IS_ERR(handle))
3098 +               return PTR_ERR(handle);
3099 +
3100 +       if (IS_SYNC(inode))
3101 +               ext4_handle_sync(handle);
3102 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3103 +       if (err)
3104 +               goto flags_err;
3105 +
3106 +       inode->i_flags = flags;
3107 +       inode->i_vflags = vflags;
3108 +       ext4_get_inode_flags(EXT4_I(inode));
3109 +       inode->i_ctime = ext4_current_time(inode);
3110 +
3111 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3112 +flags_err:
3113 +       ext4_journal_stop(handle);
3114 +       return err;
3115 +}
3116 +
3117  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3118  {
3119         struct inode *inode = file_inode(filp);
3120 @@ -247,6 +275,11 @@ long ext4_ioctl(struct file *filp, unsig
3121  
3122                 flags = ext4_mask_flags(inode->i_mode, flags);
3123  
3124 +               if (IS_BARRIER(inode)) {
3125 +                       vxwprintk_task(1, "messing with the barrier.");
3126 +                       return -EACCES;
3127 +               }
3128 +
3129                 err = -EPERM;
3130                 mutex_lock(&inode->i_mutex);
3131                 /* Is it quota file? Do not allow user to mess with it */
3132 @@ -264,7 +297,9 @@ long ext4_ioctl(struct file *filp, unsig
3133                  *
3134                  * This test looks nicer. Thanks to Pauline Middelink
3135                  */
3136 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3137 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3138 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3139 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3140                         if (!capable(CAP_LINUX_IMMUTABLE))
3141                                 goto flags_out;
3142                 }
3143 diff -NurpP --minimal linux-3.13.10/fs/ext4/namei.c linux-3.13.10-vs2.3.6.11/fs/ext4/namei.c
3144 --- linux-3.13.10/fs/ext4/namei.c       2013-11-25 15:46:59.000000000 +0000
3145 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/namei.c    2014-01-31 20:38:03.000000000 +0000
3146 @@ -34,6 +34,7 @@
3147  #include <linux/quotaops.h>
3148  #include <linux/buffer_head.h>
3149  #include <linux/bio.h>
3150 +#include <linux/vs_tag.h>
3151  #include "ext4.h"
3152  #include "ext4_jbd2.h"
3153  
3154 @@ -1299,6 +1300,7 @@ restart:
3155                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3156                                                     1, &bh);
3157                         }
3158 +               dx_propagate_tag(nd, inode);
3159                 }
3160                 if ((bh = bh_use[ra_ptr++]) == NULL)
3161                         goto next;
3162 @@ -3226,6 +3228,7 @@ const struct inode_operations ext4_dir_i
3163         .removexattr    = generic_removexattr,
3164         .get_acl        = ext4_get_acl,
3165         .fiemap         = ext4_fiemap,
3166 +       .sync_flags     = ext4_sync_flags,
3167  };
3168  
3169  const struct inode_operations ext4_special_inode_operations = {
3170 diff -NurpP --minimal linux-3.13.10/fs/ext4/super.c linux-3.13.10-vs2.3.6.11/fs/ext4/super.c
3171 --- linux-3.13.10/fs/ext4/super.c       2014-04-17 01:12:32.000000000 +0000
3172 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/super.c    2014-03-12 15:51:07.000000000 +0000
3173 @@ -1162,7 +1162,7 @@ enum {
3174         Opt_inode_readahead_blks, Opt_journal_ioprio,
3175         Opt_dioread_nolock, Opt_dioread_lock,
3176         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3177 -       Opt_max_dir_size_kb,
3178 +       Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3179  };
3180  
3181  static const match_table_t tokens = {
3182 @@ -1243,6 +1243,9 @@ static const match_table_t tokens = {
3183         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3184         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3185         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3186 +       {Opt_tag, "tag"},
3187 +       {Opt_notag, "notag"},
3188 +       {Opt_tagid, "tagid=%u"},
3189         {Opt_err, NULL},
3190  };
3191  
3192 @@ -1475,6 +1478,20 @@ static int handle_mount_opt(struct super
3193         case Opt_i_version:
3194                 sb->s_flags |= MS_I_VERSION;
3195                 return 1;
3196 +#ifndef CONFIG_TAGGING_NONE
3197 +       case Opt_tag:
3198 +               set_opt(sb, TAGGED);
3199 +               return 1;
3200 +       case Opt_notag:
3201 +               clear_opt(sb, TAGGED);
3202 +               return 1;
3203 +#endif
3204 +#ifdef CONFIG_PROPAGATE
3205 +       case Opt_tagid:
3206 +               /* use args[0] */
3207 +               set_opt(sb, TAGGED);
3208 +               return 1;
3209 +#endif
3210         }
3211  
3212         for (m = ext4_mount_opts; m->token != Opt_err; m++)
3213 @@ -3564,6 +3581,9 @@ static int ext4_fill_super(struct super_
3214                         clear_opt(sb, DELALLOC);
3215         }
3216  
3217 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3218 +               sb->s_flags |= MS_TAGGED;
3219 +
3220         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3221                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3222  
3223 @@ -4818,6 +4838,14 @@ static int ext4_remount(struct super_blo
3224         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3225                 ext4_abort(sb, "Abort forced by user");
3226  
3227 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3228 +               !(sb->s_flags & MS_TAGGED)) {
3229 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3230 +                       sb->s_id);
3231 +               err = -EINVAL;
3232 +               goto restore_opts;
3233 +       }
3234 +
3235         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3236                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3237  
3238 diff -NurpP --minimal linux-3.13.10/fs/fcntl.c linux-3.13.10-vs2.3.6.11/fs/fcntl.c
3239 --- linux-3.13.10/fs/fcntl.c    2014-01-22 20:39:06.000000000 +0000
3240 +++ linux-3.13.10-vs2.3.6.11/fs/fcntl.c 2014-01-31 20:38:03.000000000 +0000
3241 @@ -21,6 +21,7 @@
3242  #include <linux/rcupdate.h>
3243  #include <linux/pid_namespace.h>
3244  #include <linux/user_namespace.h>
3245 +#include <linux/vs_limit.h>
3246  
3247  #include <asm/poll.h>
3248  #include <asm/siginfo.h>
3249 @@ -377,6 +378,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3250  
3251         if (!f.file)
3252                 goto out;
3253 +       if (!vx_files_avail(1))
3254 +               goto out;
3255  
3256         if (unlikely(f.file->f_mode & FMODE_PATH)) {
3257                 if (!check_fcntl_cmd(cmd))
3258 diff -NurpP --minimal linux-3.13.10/fs/file.c linux-3.13.10-vs2.3.6.11/fs/file.c
3259 --- linux-3.13.10/fs/file.c     2014-04-17 01:12:32.000000000 +0000
3260 +++ linux-3.13.10-vs2.3.6.11/fs/file.c  2014-02-25 11:26:09.000000000 +0000
3261 @@ -22,6 +22,7 @@
3262  #include <linux/spinlock.h>
3263  #include <linux/rcupdate.h>
3264  #include <linux/workqueue.h>
3265 +#include <linux/vs_limit.h>
3266  
3267  int sysctl_nr_open __read_mostly = 1024*1024;
3268  int sysctl_nr_open_min = BITS_PER_LONG;
3269 @@ -311,6 +312,8 @@ struct files_struct *dup_fd(struct files
3270                 struct file *f = *old_fds++;
3271                 if (f) {
3272                         get_file(f);
3273 +                       /* TODO: sum it first for check and performance */
3274 +                       vx_openfd_inc(open_files - i);
3275                 } else {
3276                         /*
3277                          * The fd may be claimed in the fd bitmap but not yet
3278 @@ -376,9 +379,11 @@ static void close_files(struct files_str
3279                                         filp_close(file, files);
3280                                         cond_resched();
3281                                 }
3282 +                               vx_openfd_dec(i);
3283                         }
3284                         i++;
3285                         set >>= 1;
3286 +                       cond_resched();
3287                 }
3288         }
3289  }
3290 @@ -503,6 +508,7 @@ repeat:
3291         else
3292                 __clear_close_on_exec(fd, fdt);
3293         error = fd;
3294 +       vx_openfd_inc(fd);
3295  #if 1
3296         /* Sanity check */
3297         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3298 @@ -533,6 +539,7 @@ static void __put_unused_fd(struct files
3299         __clear_open_fd(fd, fdt);
3300         if (fd < files->next_fd)
3301                 files->next_fd = fd;
3302 +       vx_openfd_dec(fd);
3303  }
3304  
3305  void put_unused_fd(unsigned int fd)
3306 @@ -812,6 +819,8 @@ static int do_dup2(struct files_struct *
3307  
3308         if (tofree)
3309                 filp_close(tofree, files);
3310 +       else
3311 +               vx_openfd_inc(fd);      /* fd was unused */
3312  
3313         return fd;
3314  
3315 diff -NurpP --minimal linux-3.13.10/fs/file_table.c linux-3.13.10-vs2.3.6.11/fs/file_table.c
3316 --- linux-3.13.10/fs/file_table.c       2014-01-22 20:39:06.000000000 +0000
3317 +++ linux-3.13.10-vs2.3.6.11/fs/file_table.c    2014-02-01 00:00:01.000000000 +0000
3318 @@ -26,6 +26,8 @@
3319  #include <linux/hardirq.h>
3320  #include <linux/task_work.h>
3321  #include <linux/ima.h>
3322 +#include <linux/vs_limit.h>
3323 +#include <linux/vs_context.h>
3324  
3325  #include <linux/atomic.h>
3326  
3327 @@ -137,6 +139,8 @@ struct file *get_empty_filp(void)
3328         spin_lock_init(&f->f_lock);
3329         eventpoll_init_file(f);
3330         /* f->f_version: 0 */
3331 +       f->f_xid = vx_current_xid();
3332 +       vx_files_inc(f);
3333         return f;
3334  
3335  over:
3336 @@ -254,6 +258,8 @@ static void __fput(struct file *file)
3337                 i_readcount_dec(inode);
3338         if (file->f_mode & FMODE_WRITE)
3339                 drop_file_write_access(file);
3340 +       vx_files_dec(file);
3341 +       file->f_xid = 0;
3342         file->f_path.dentry = NULL;
3343         file->f_path.mnt = NULL;
3344         file->f_inode = NULL;
3345 @@ -340,6 +346,8 @@ void put_filp(struct file *file)
3346  {
3347         if (atomic_long_dec_and_test(&file->f_count)) {
3348                 security_file_free(file);
3349 +               vx_files_dec(file);
3350 +               file->f_xid = 0;
3351                 file_free(file);
3352         }
3353  }
3354 diff -NurpP --minimal linux-3.13.10/fs/fs_struct.c linux-3.13.10-vs2.3.6.11/fs/fs_struct.c
3355 --- linux-3.13.10/fs/fs_struct.c        2014-01-22 20:39:06.000000000 +0000
3356 +++ linux-3.13.10-vs2.3.6.11/fs/fs_struct.c     2014-01-31 20:38:03.000000000 +0000
3357 @@ -4,6 +4,7 @@
3358  #include <linux/path.h>
3359  #include <linux/slab.h>
3360  #include <linux/fs_struct.h>
3361 +#include <linux/vserver/global.h>
3362  #include "internal.h"
3363  
3364  /*
3365 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3366  {
3367         path_put(&fs->root);
3368         path_put(&fs->pwd);
3369 +       atomic_dec(&vs_global_fs);
3370         kmem_cache_free(fs_cachep, fs);
3371  }
3372  
3373 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3374                 fs->pwd = old->pwd;
3375                 path_get(&fs->pwd);
3376                 spin_unlock(&old->lock);
3377 +               atomic_inc(&vs_global_fs);
3378         }
3379         return fs;
3380  }
3381 diff -NurpP --minimal linux-3.13.10/fs/gfs2/file.c linux-3.13.10-vs2.3.6.11/fs/gfs2/file.c
3382 --- linux-3.13.10/fs/gfs2/file.c        2014-01-22 20:39:06.000000000 +0000
3383 +++ linux-3.13.10-vs2.3.6.11/fs/gfs2/file.c     2014-01-31 20:38:03.000000000 +0000
3384 @@ -137,6 +137,9 @@ static const u32 fsflags_to_gfs2[32] = {
3385         [12] = GFS2_DIF_EXHASH,
3386         [14] = GFS2_DIF_INHERIT_JDATA,
3387         [17] = GFS2_DIF_TOPDIR,
3388 +       [27] = GFS2_DIF_IXUNLINK,
3389 +       [26] = GFS2_DIF_BARRIER,
3390 +       [29] = GFS2_DIF_COW,
3391  };
3392  
3393  static const u32 gfs2_to_fsflags[32] = {
3394 @@ -147,6 +150,9 @@ static const u32 gfs2_to_fsflags[32] = {
3395         [gfs2fl_ExHash] = FS_INDEX_FL,
3396         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3397         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3398 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3399 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3400 +       [gfs2fl_Cow] = FS_COW_FL,
3401  };
3402  
3403  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3404 @@ -177,12 +183,18 @@ void gfs2_set_inode_flags(struct inode *
3405  {
3406         struct gfs2_inode *ip = GFS2_I(inode);
3407         unsigned int flags = inode->i_flags;
3408 +       unsigned int vflags = inode->i_vflags;
3409 +
3410 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3411 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3412  
3413 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3414         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3415                 inode->i_flags |= S_NOSEC;
3416         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3417                 flags |= S_IMMUTABLE;
3418 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3419 +               flags |= S_IXUNLINK;
3420 +
3421         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3422                 flags |= S_APPEND;
3423         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3424 @@ -190,6 +202,43 @@ void gfs2_set_inode_flags(struct inode *
3425         if (ip->i_diskflags & GFS2_DIF_SYNC)
3426                 flags |= S_SYNC;
3427         inode->i_flags = flags;
3428 +
3429 +       vflags &= ~(V_BARRIER | V_COW);
3430 +
3431 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3432 +               vflags |= V_BARRIER;
3433 +       if (ip->i_diskflags & GFS2_DIF_COW)
3434 +               vflags |= V_COW;
3435 +       inode->i_vflags = vflags;
3436 +}
3437 +
3438 +void gfs2_get_inode_flags(struct inode *inode)
3439 +{
3440 +       struct gfs2_inode *ip = GFS2_I(inode);
3441 +       unsigned int flags = inode->i_flags;
3442 +       unsigned int vflags = inode->i_vflags;
3443 +
3444 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3445 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3446 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3447 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3448 +
3449 +       if (flags & S_IMMUTABLE)
3450 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3451 +       if (flags & S_IXUNLINK)
3452 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3453 +
3454 +       if (flags & S_APPEND)
3455 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3456 +       if (flags & S_NOATIME)
3457 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3458 +       if (flags & S_SYNC)
3459 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3460 +
3461 +       if (vflags & V_BARRIER)
3462 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3463 +       if (vflags & V_COW)
3464 +               ip->i_diskflags |= GFS2_DIF_COW;
3465  }
3466  
3467  /* Flags that can be set by user space */
3468 @@ -303,6 +352,37 @@ static int gfs2_set_flags(struct file *f
3469         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3470  }
3471  
3472 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3473 +{
3474 +       struct gfs2_inode *ip = GFS2_I(inode);
3475 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3476 +       struct buffer_head *bh;
3477 +       struct gfs2_holder gh;
3478 +       int error;
3479 +
3480 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3481 +       if (error)
3482 +               return error;
3483 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3484 +       if (error)
3485 +               goto out;
3486 +       error = gfs2_meta_inode_buffer(ip, &bh);
3487 +       if (error)
3488 +               goto out_trans_end;
3489 +       gfs2_trans_add_meta(ip->i_gl, bh);
3490 +       inode->i_flags = flags;
3491 +       inode->i_vflags = vflags;
3492 +       gfs2_get_inode_flags(inode);
3493 +       gfs2_dinode_out(ip, bh->b_data);
3494 +       brelse(bh);
3495 +       gfs2_set_aops(inode);
3496 +out_trans_end:
3497 +       gfs2_trans_end(sdp);
3498 +out:
3499 +       gfs2_glock_dq_uninit(&gh);
3500 +       return error;
3501 +}
3502 +
3503  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3504  {
3505         switch(cmd) {
3506 diff -NurpP --minimal linux-3.13.10/fs/gfs2/inode.h linux-3.13.10-vs2.3.6.11/fs/gfs2/inode.h
3507 --- linux-3.13.10/fs/gfs2/inode.h       2013-11-25 15:45:01.000000000 +0000
3508 +++ linux-3.13.10-vs2.3.6.11/fs/gfs2/inode.h    2014-01-31 20:38:03.000000000 +0000
3509 @@ -118,6 +118,7 @@ extern const struct file_operations gfs2
3510  extern const struct file_operations gfs2_dir_fops_nolock;
3511  
3512  extern void gfs2_set_inode_flags(struct inode *inode);
3513 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3514   
3515  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3516  extern const struct file_operations gfs2_file_fops;
3517 diff -NurpP --minimal linux-3.13.10/fs/hostfs/hostfs.h linux-3.13.10-vs2.3.6.11/fs/hostfs/hostfs.h
3518 --- linux-3.13.10/fs/hostfs/hostfs.h    2012-12-11 03:30:57.000000000 +0000
3519 +++ linux-3.13.10-vs2.3.6.11/fs/hostfs/hostfs.h 2014-01-31 20:38:03.000000000 +0000
3520 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3521         unsigned short  ia_mode;
3522         uid_t           ia_uid;
3523         gid_t           ia_gid;
3524 +       vtag_t          ia_tag;
3525         loff_t          ia_size;
3526         struct timespec ia_atime;
3527         struct timespec ia_mtime;
3528 diff -NurpP --minimal linux-3.13.10/fs/inode.c linux-3.13.10-vs2.3.6.11/fs/inode.c
3529 --- linux-3.13.10/fs/inode.c    2014-01-22 20:39:06.000000000 +0000
3530 +++ linux-3.13.10-vs2.3.6.11/fs/inode.c 2014-01-31 23:33:47.000000000 +0000
3531 @@ -18,6 +18,7 @@
3532  #include <linux/buffer_head.h> /* for inode_has_buffers */
3533  #include <linux/ratelimit.h>
3534  #include <linux/list_lru.h>
3535 +#include <linux/vs_tag.h>
3536  #include "internal.h"
3537  
3538  /*
3539 @@ -129,6 +130,8 @@ int inode_init_always(struct super_block
3540         struct address_space *const mapping = &inode->i_data;
3541  
3542         inode->i_sb = sb;
3543 +
3544 +       /* essential because of inode slab reuse */
3545         inode->i_blkbits = sb->s_blocksize_bits;
3546         inode->i_flags = 0;
3547         atomic_set(&inode->i_count, 1);
3548 @@ -138,6 +141,7 @@ int inode_init_always(struct super_block
3549         inode->i_opflags = 0;
3550         i_uid_write(inode, 0);
3551         i_gid_write(inode, 0);
3552 +       i_tag_write(inode, 0);
3553         atomic_set(&inode->i_writecount, 0);
3554         inode->i_size = 0;
3555         inode->i_blocks = 0;
3556 @@ -150,6 +154,7 @@ int inode_init_always(struct super_block
3557         inode->i_bdev = NULL;
3558         inode->i_cdev = NULL;
3559         inode->i_rdev = 0;
3560 +       inode->i_mdev = 0;
3561         inode->dirtied_when = 0;
3562  
3563         if (security_inode_alloc(inode))
3564 @@ -477,6 +482,8 @@ void __insert_inode_hash(struct inode *i
3565  }
3566  EXPORT_SYMBOL(__insert_inode_hash);
3567  
3568 +EXPORT_SYMBOL_GPL(__iget);
3569 +
3570  /**
3571   *     __remove_inode_hash - remove an inode from the hash
3572   *     @inode: inode to unhash
3573 @@ -1802,9 +1809,11 @@ void init_special_inode(struct inode *in
3574         if (S_ISCHR(mode)) {
3575                 inode->i_fop = &def_chr_fops;
3576                 inode->i_rdev = rdev;
3577 +               inode->i_mdev = rdev;
3578         } else if (S_ISBLK(mode)) {
3579                 inode->i_fop = &def_blk_fops;
3580                 inode->i_rdev = rdev;
3581 +               inode->i_mdev = rdev;
3582         } else if (S_ISFIFO(mode))
3583                 inode->i_fop = &pipefifo_fops;
3584         else if (S_ISSOCK(mode))
3585 @@ -1833,6 +1842,7 @@ void inode_init_owner(struct inode *inod
3586         } else
3587                 inode->i_gid = current_fsgid();
3588         inode->i_mode = mode;
3589 +       i_tag_write(inode, dx_current_fstag(inode->i_sb));
3590  }
3591  EXPORT_SYMBOL(inode_init_owner);
3592  
3593 diff -NurpP --minimal linux-3.13.10/fs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ioctl.c
3594 --- linux-3.13.10/fs/ioctl.c    2014-01-22 20:39:06.000000000 +0000
3595 +++ linux-3.13.10-vs2.3.6.11/fs/ioctl.c 2014-01-31 20:38:03.000000000 +0000
3596 @@ -15,6 +15,9 @@
3597  #include <linux/writeback.h>
3598  #include <linux/buffer_head.h>
3599  #include <linux/falloc.h>
3600 +#include <linux/proc_fs.h>
3601 +#include <linux/vserver/inode.h>
3602 +#include <linux/vs_tag.h>
3603  
3604  #include <asm/ioctls.h>
3605  
3606 diff -NurpP --minimal linux-3.13.10/fs/ioprio.c linux-3.13.10-vs2.3.6.11/fs/ioprio.c
3607 --- linux-3.13.10/fs/ioprio.c   2012-12-11 03:30:57.000000000 +0000
3608 +++ linux-3.13.10-vs2.3.6.11/fs/ioprio.c        2014-01-31 20:38:03.000000000 +0000
3609 @@ -28,6 +28,7 @@
3610  #include <linux/syscalls.h>
3611  #include <linux/security.h>
3612  #include <linux/pid_namespace.h>
3613 +#include <linux/vs_base.h>
3614  
3615  int set_task_ioprio(struct task_struct *task, int ioprio)
3616  {
3617 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3618                         else
3619                                 pgrp = find_vpid(who);
3620                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3621 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3622 +                                       continue;
3623                                 ret = set_task_ioprio(p, ioprio);
3624                                 if (ret)
3625                                         break;
3626 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3627                         else
3628                                 pgrp = find_vpid(who);
3629                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3630 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3631 +                                       continue;
3632                                 tmpio = get_task_ioprio(p);
3633                                 if (tmpio < 0)
3634                                         continue;
3635 diff -NurpP --minimal linux-3.13.10/fs/jfs/file.c linux-3.13.10-vs2.3.6.11/fs/jfs/file.c
3636 --- linux-3.13.10/fs/jfs/file.c 2013-02-19 13:58:48.000000000 +0000
3637 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/file.c      2014-01-31 20:38:03.000000000 +0000
3638 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3639         if (is_quota_modification(inode, iattr))
3640                 dquot_initialize(inode);
3641         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3642 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3643 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3644 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3645                 rc = dquot_transfer(inode, iattr);
3646                 if (rc)
3647                         return rc;
3648 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3649  #ifdef CONFIG_JFS_POSIX_ACL
3650         .get_acl        = jfs_get_acl,
3651  #endif
3652 +       .sync_flags     = jfs_sync_flags,
3653  };
3654  
3655  const struct file_operations jfs_file_operations = {
3656 diff -NurpP --minimal linux-3.13.10/fs/jfs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/jfs/ioctl.c
3657 --- linux-3.13.10/fs/jfs/ioctl.c        2013-05-31 13:45:24.000000000 +0000
3658 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/ioctl.c     2014-01-31 20:38:03.000000000 +0000
3659 @@ -12,6 +12,7 @@
3660  #include <linux/time.h>
3661  #include <linux/sched.h>
3662  #include <linux/blkdev.h>
3663 +#include <linux/mount.h>
3664  #include <asm/current.h>
3665  #include <asm/uaccess.h>
3666  
3667 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3668  }
3669  
3670  
3671 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3672 +{
3673 +       inode->i_flags = flags;
3674 +       inode->i_vflags = vflags;
3675 +       jfs_get_inode_flags(JFS_IP(inode));
3676 +       inode->i_ctime = CURRENT_TIME_SEC;
3677 +       mark_inode_dirty(inode);
3678 +       return 0;
3679 +}
3680 +
3681  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3682  {
3683         struct inode *inode = file_inode(filp);
3684 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3685                 if (!S_ISDIR(inode->i_mode))
3686                         flags &= ~JFS_DIRSYNC_FL;
3687  
3688 +               if (IS_BARRIER(inode)) {
3689 +                       vxwprintk_task(1, "messing with the barrier.");
3690 +                       return -EACCES;
3691 +               }
3692 +
3693                 /* Is it quota file? Do not allow user to mess with it */
3694                 if (IS_NOQUOTA(inode)) {
3695                         err = -EPERM;
3696 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3697                  * the relevant capability.
3698                  */
3699                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3700 -                       ((flags ^ oldflags) &
3701 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3702 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3703 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3704                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3705                                 mutex_unlock(&inode->i_mutex);
3706                                 err = -EPERM;
3707 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3708                         }
3709                 }
3710  
3711 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3712 +               flags &= JFS_FL_USER_MODIFIABLE;
3713                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3714                 jfs_inode->mode2 = flags;
3715  
3716 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
3717 --- linux-3.13.10/fs/jfs/jfs_dinode.h   2012-12-11 03:30:57.000000000 +0000
3718 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_dinode.h        2014-01-31 20:38:03.000000000 +0000
3719 @@ -161,9 +161,13 @@ struct dinode {
3720  
3721  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3722  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3723 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3724  
3725 -#define JFS_FL_USER_VISIBLE    0x03F80000
3726 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3727 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3728 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3729 +
3730 +#define JFS_FL_USER_VISIBLE    0x07F80000
3731 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3732  #define JFS_FL_INHERIT         0x03C80000
3733  
3734  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3735 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
3736 --- linux-3.13.10/fs/jfs/jfs_filsys.h   2012-12-11 03:30:57.000000000 +0000
3737 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_filsys.h        2014-01-31 20:38:03.000000000 +0000
3738 @@ -266,6 +266,7 @@
3739  #define JFS_NAME_MAX   255
3740  #define JFS_PATH_MAX   BPSIZE
3741  
3742 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3743  
3744  /*
3745   *     file system state (superblock state)
3746 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
3747 --- linux-3.13.10/fs/jfs/jfs_imap.c     2013-11-25 15:45:01.000000000 +0000
3748 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_imap.c  2014-01-31 20:38:03.000000000 +0000
3749 @@ -46,6 +46,7 @@
3750  #include <linux/pagemap.h>
3751  #include <linux/quotaops.h>
3752  #include <linux/slab.h>
3753 +#include <linux/vs_tag.h>
3754  
3755  #include "jfs_incore.h"
3756  #include "jfs_inode.h"
3757 @@ -3047,6 +3048,8 @@ static int copy_from_dinode(struct dinod
3758  {
3759         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3760         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3761 +       kuid_t kuid;
3762 +       kgid_t kgid;
3763  
3764         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3765         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3766 @@ -3067,14 +3070,18 @@ static int copy_from_dinode(struct dinod
3767         }
3768         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3769  
3770 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3771 +       kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3772 +       kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3773 +       ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3774 +
3775 +       jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3776         if (!uid_valid(sbi->uid))
3777                 ip->i_uid = jfs_ip->saved_uid;
3778         else {
3779                 ip->i_uid = sbi->uid;
3780         }
3781  
3782 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3783 +       jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3784         if (!gid_valid(sbi->gid))
3785                 ip->i_gid = jfs_ip->saved_gid;
3786         else {
3787 @@ -3139,16 +3146,14 @@ static void copy_to_dinode(struct dinode
3788         dip->di_size = cpu_to_le64(ip->i_size);
3789         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3790         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3791 -       if (!uid_valid(sbi->uid))
3792 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3793 -       else
3794 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3795 -                                                  jfs_ip->saved_uid));
3796 -       if (!gid_valid(sbi->gid))
3797 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3798 -       else
3799 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3800 -                                                   jfs_ip->saved_gid));
3801 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3802 +               TAGINO_KUID(DX_TAG(ip),
3803 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3804 +               ip->i_tag)));
3805 +       dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3806 +               TAGINO_KGID(DX_TAG(ip),
3807 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3808 +               ip->i_tag)));
3809         jfs_get_inode_flags(jfs_ip);
3810         /*
3811          * mode2 is only needed for storing the higher order bits.
3812 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
3813 --- linux-3.13.10/fs/jfs/jfs_inode.c    2013-11-25 15:46:59.000000000 +0000
3814 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.c 2014-01-31 20:38:03.000000000 +0000
3815 @@ -18,6 +18,7 @@
3816  
3817  #include <linux/fs.h>
3818  #include <linux/quotaops.h>
3819 +#include <linux/vs_tag.h>
3820  #include "jfs_incore.h"
3821  #include "jfs_inode.h"
3822  #include "jfs_filsys.h"
3823 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3824  {
3825         unsigned int flags = JFS_IP(inode)->mode2;
3826  
3827 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3828 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3829 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3830 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3831  
3832         if (flags & JFS_IMMUTABLE_FL)
3833                 inode->i_flags |= S_IMMUTABLE;
3834 +       if (flags & JFS_IXUNLINK_FL)
3835 +               inode->i_flags |= S_IXUNLINK;
3836 +
3837 +       if (flags & JFS_SYNC_FL)
3838 +               inode->i_flags |= S_SYNC;
3839         if (flags & JFS_APPEND_FL)
3840                 inode->i_flags |= S_APPEND;
3841         if (flags & JFS_NOATIME_FL)
3842                 inode->i_flags |= S_NOATIME;
3843         if (flags & JFS_DIRSYNC_FL)
3844                 inode->i_flags |= S_DIRSYNC;
3845 -       if (flags & JFS_SYNC_FL)
3846 -               inode->i_flags |= S_SYNC;
3847 +
3848 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3849 +
3850 +       if (flags & JFS_BARRIER_FL)
3851 +               inode->i_vflags |= V_BARRIER;
3852 +       if (flags & JFS_COW_FL)
3853 +               inode->i_vflags |= V_COW;
3854  }
3855  
3856  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3857  {
3858         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3859 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3860 +
3861 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3862 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3863 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3864 +                          JFS_BARRIER_FL | JFS_COW_FL);
3865  
3866 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3867 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3868         if (flags & S_IMMUTABLE)
3869                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3870 +       if (flags & S_IXUNLINK)
3871 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3872 +
3873         if (flags & S_APPEND)
3874                 jfs_ip->mode2 |= JFS_APPEND_FL;
3875         if (flags & S_NOATIME)
3876 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3877                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3878         if (flags & S_SYNC)
3879                 jfs_ip->mode2 |= JFS_SYNC_FL;
3880 +
3881 +       if (vflags & V_BARRIER)
3882 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3883 +       if (vflags & V_COW)
3884 +               jfs_ip->mode2 |= JFS_COW_FL;
3885  }
3886  
3887  /*
3888 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
3889 --- linux-3.13.10/fs/jfs/jfs_inode.h    2012-12-11 03:30:57.000000000 +0000
3890 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.h 2014-01-31 20:38:03.000000000 +0000
3891 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3892  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3893         int fh_len, int fh_type);
3894  extern void jfs_set_inode_flags(struct inode *);
3895 +extern int jfs_sync_flags(struct inode *, int, int);
3896  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3897  extern int jfs_setattr(struct dentry *, struct iattr *);
3898  
3899 diff -NurpP --minimal linux-3.13.10/fs/jfs/namei.c linux-3.13.10-vs2.3.6.11/fs/jfs/namei.c
3900 --- linux-3.13.10/fs/jfs/namei.c        2013-11-25 15:45:01.000000000 +0000
3901 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/namei.c     2014-01-31 20:38:03.000000000 +0000
3902 @@ -22,6 +22,7 @@
3903  #include <linux/ctype.h>
3904  #include <linux/quotaops.h>
3905  #include <linux/exportfs.h>
3906 +#include <linux/vs_tag.h>
3907  #include "jfs_incore.h"
3908  #include "jfs_superblock.h"
3909  #include "jfs_inode.h"
3910 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3911                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3912         }
3913  
3914 +       dx_propagate_tag(nd, ip);
3915         return d_splice_alias(ip, dentry);
3916  }
3917  
3918 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
3919  #ifdef CONFIG_JFS_POSIX_ACL
3920         .get_acl        = jfs_get_acl,
3921  #endif
3922 +       .sync_flags     = jfs_sync_flags,
3923  };
3924  
3925  const struct file_operations jfs_dir_operations = {
3926 diff -NurpP --minimal linux-3.13.10/fs/jfs/super.c linux-3.13.10-vs2.3.6.11/fs/jfs/super.c
3927 --- linux-3.13.10/fs/jfs/super.c        2013-11-25 15:45:01.000000000 +0000
3928 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/super.c     2014-01-31 20:38:03.000000000 +0000
3929 @@ -203,7 +203,8 @@ enum {
3930         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
3931         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
3932         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
3933 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
3934 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
3935 +       Opt_tag, Opt_notag, Opt_tagid
3936  };
3937  
3938  static const match_table_t tokens = {
3939 @@ -213,6 +214,10 @@ static const match_table_t tokens = {
3940         {Opt_resize, "resize=%u"},
3941         {Opt_resize_nosize, "resize"},
3942         {Opt_errors, "errors=%s"},
3943 +       {Opt_tag, "tag"},
3944 +       {Opt_notag, "notag"},
3945 +       {Opt_tagid, "tagid=%u"},
3946 +       {Opt_tag, "tagxid"},
3947         {Opt_ignore, "noquota"},
3948         {Opt_ignore, "quota"},
3949         {Opt_usrquota, "usrquota"},
3950 @@ -389,7 +394,20 @@ static int parse_options(char *options,
3951                         }
3952                         break;
3953                 }
3954 -
3955 +#ifndef CONFIG_TAGGING_NONE
3956 +               case Opt_tag:
3957 +                       *flag |= JFS_TAGGED;
3958 +                       break;
3959 +               case Opt_notag:
3960 +                       *flag &= JFS_TAGGED;
3961 +                       break;
3962 +#endif
3963 +#ifdef CONFIG_PROPAGATE
3964 +               case Opt_tagid:
3965 +                       /* use args[0] */
3966 +                       *flag |= JFS_TAGGED;
3967 +                       break;
3968 +#endif
3969                 default:
3970                         printk("jfs: Unrecognized mount option \"%s\" "
3971                                         " or missing value\n", p);
3972 @@ -421,6 +439,12 @@ static int jfs_remount(struct super_bloc
3973                 return -EINVAL;
3974         }
3975  
3976 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
3977 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
3978 +                       sb->s_id);
3979 +               return -EINVAL;
3980 +       }
3981 +
3982         if (newLVSize) {
3983                 if (sb->s_flags & MS_RDONLY) {
3984                         pr_err("JFS: resize requires volume" \
3985 @@ -506,6 +530,9 @@ static int jfs_fill_super(struct super_b
3986  #ifdef CONFIG_JFS_POSIX_ACL
3987         sb->s_flags |= MS_POSIXACL;
3988  #endif
3989 +       /* map mount option tagxid */
3990 +       if (sbi->flag & JFS_TAGGED)
3991 +               sb->s_flags |= MS_TAGGED;
3992  
3993         if (newLVSize) {
3994                 pr_err("resize option for remount only\n");
3995 diff -NurpP --minimal linux-3.13.10/fs/libfs.c linux-3.13.10-vs2.3.6.11/fs/libfs.c
3996 --- linux-3.13.10/fs/libfs.c    2014-01-22 20:39:06.000000000 +0000
3997 +++ linux-3.13.10-vs2.3.6.11/fs/libfs.c 2014-02-01 01:35:46.000000000 +0000
3998 @@ -145,13 +145,14 @@ static inline unsigned char dt_type(stru
3999   * both impossible due to the lock on directory.
4000   */
4001  
4002 -int dcache_readdir(struct file *file, struct dir_context *ctx)
4003 +static inline int do_dcache_readdir_filter(struct file *filp,
4004 +       struct dir_context *ctx, int (*filter)(struct dentry *dentry))
4005  {
4006 -       struct dentry *dentry = file->f_path.dentry;
4007 -       struct dentry *cursor = file->private_data;
4008 +       struct dentry *dentry = filp->f_path.dentry;
4009 +       struct dentry *cursor = filp->private_data;
4010         struct list_head *p, *q = &cursor->d_u.d_child;
4011  
4012 -       if (!dir_emit_dots(file, ctx))
4013 +       if (!dir_emit_dots(filp, ctx))
4014                 return 0;
4015         spin_lock(&dentry->d_lock);
4016         if (ctx->pos == 2)
4017 @@ -159,6 +160,8 @@ int dcache_readdir(struct file *file, st
4018  
4019         for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
4020                 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
4021 +               if (filter && !filter(next))
4022 +                       continue;
4023                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4024                 if (!simple_positive(next)) {
4025                         spin_unlock(&next->d_lock);
4026 @@ -181,8 +184,22 @@ int dcache_readdir(struct file *file, st
4027         spin_unlock(&dentry->d_lock);
4028         return 0;
4029  }
4030 +
4031  EXPORT_SYMBOL(dcache_readdir);
4032  
4033 +int dcache_readdir(struct file *filp, struct dir_context *ctx)
4034 +{
4035 +       return do_dcache_readdir_filter(filp, ctx, NULL);
4036 +}
4037 +
4038 +EXPORT_SYMBOL(dcache_readdir_filter);
4039 +
4040 +int dcache_readdir_filter(struct file *filp, struct dir_context *ctx,
4041 +       int (*filter)(struct dentry *))
4042 +{
4043 +       return do_dcache_readdir_filter(filp, ctx, filter);
4044 +}
4045 +
4046  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4047  {
4048         return -EISDIR;
4049 diff -NurpP --minimal linux-3.13.10/fs/locks.c linux-3.13.10-vs2.3.6.11/fs/locks.c
4050 --- linux-3.13.10/fs/locks.c    2014-01-22 20:39:06.000000000 +0000
4051 +++ linux-3.13.10-vs2.3.6.11/fs/locks.c 2014-01-31 23:51:55.000000000 +0000
4052 @@ -129,6 +129,8 @@
4053  #include <linux/hashtable.h>
4054  #include <linux/percpu.h>
4055  #include <linux/lglock.h>
4056 +#include <linux/vs_base.h>
4057 +#include <linux/vs_limit.h>
4058  
4059  #include <asm/uaccess.h>
4060  
4061 @@ -210,11 +212,17 @@ static void locks_init_lock_heads(struct
4062  /* Allocate an empty lock structure. */
4063  struct file_lock *locks_alloc_lock(void)
4064  {
4065 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4066 +       struct file_lock *fl;
4067  
4068 -       if (fl)
4069 -               locks_init_lock_heads(fl);
4070 +       if (!vx_locks_avail(1))
4071 +               return NULL;
4072  
4073 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4074 +
4075 +       if (fl) {
4076 +               locks_init_lock_heads(fl);
4077 +               fl->fl_xid = -1;
4078 +       }
4079         return fl;
4080  }
4081  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4082 @@ -238,6 +246,7 @@ void locks_free_lock(struct file_lock *f
4083         BUG_ON(!list_empty(&fl->fl_block));
4084         BUG_ON(!hlist_unhashed(&fl->fl_link));
4085  
4086 +       vx_locks_dec(fl);
4087         locks_release_private(fl);
4088         kmem_cache_free(filelock_cache, fl);
4089  }
4090 @@ -247,6 +256,7 @@ void locks_init_lock(struct file_lock *f
4091  {
4092         memset(fl, 0, sizeof(struct file_lock));
4093         locks_init_lock_heads(fl);
4094 +       fl->fl_xid = -1;
4095  }
4096  
4097  EXPORT_SYMBOL(locks_init_lock);
4098 @@ -287,6 +297,7 @@ void locks_copy_lock(struct file_lock *n
4099         new->fl_file = fl->fl_file;
4100         new->fl_ops = fl->fl_ops;
4101         new->fl_lmops = fl->fl_lmops;
4102 +       new->fl_xid = fl->fl_xid;
4103  
4104         locks_copy_private(new, fl);
4105  }
4106 @@ -325,6 +336,11 @@ static int flock_make_lock(struct file *
4107         fl->fl_flags = FL_FLOCK;
4108         fl->fl_type = type;
4109         fl->fl_end = OFFSET_MAX;
4110 +
4111 +       vxd_assert(filp->f_xid == vx_current_xid(),
4112 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4113 +       fl->fl_xid = filp->f_xid;
4114 +       vx_locks_inc(fl);
4115         
4116         *lock = fl;
4117         return 0;
4118 @@ -464,6 +480,7 @@ static int lease_init(struct file *filp,
4119  
4120         fl->fl_owner = current->files;
4121         fl->fl_pid = current->tgid;
4122 +       fl->fl_xid = vx_current_xid();
4123  
4124         fl->fl_file = filp;
4125         fl->fl_flags = FL_LEASE;
4126 @@ -483,6 +500,11 @@ static struct file_lock *lease_alloc(str
4127         if (fl == NULL)
4128                 return ERR_PTR(error);
4129  
4130 +       fl->fl_xid = vx_current_xid();
4131 +       if (filp)
4132 +               vxd_assert(filp->f_xid == fl->fl_xid,
4133 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4134 +       vx_locks_inc(fl);
4135         error = lease_init(filp, type, fl);
4136         if (error) {
4137                 locks_free_lock(fl);
4138 @@ -858,6 +880,7 @@ static int flock_lock_file(struct file *
4139                 spin_lock(&inode->i_lock);
4140         }
4141  
4142 +       new_fl->fl_xid = -1;
4143  find_conflict:
4144         for_each_lock(inode, before) {
4145                 struct file_lock *fl = *before;
4146 @@ -878,6 +901,7 @@ find_conflict:
4147                 goto out;
4148         locks_copy_lock(new_fl, request);
4149         locks_insert_lock(before, new_fl);
4150 +       vx_locks_inc(new_fl);
4151         new_fl = NULL;
4152         error = 0;
4153  
4154 @@ -888,7 +912,8 @@ out:
4155         return error;
4156  }
4157  
4158 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4159 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4160 +       struct file_lock *conflock, vxid_t xid)
4161  {
4162         struct file_lock *fl;
4163         struct file_lock *new_fl = NULL;
4164 @@ -899,6 +924,8 @@ static int __posix_lock_file(struct inod
4165         int error;
4166         bool added = false;
4167  
4168 +       vxd_assert(xid == vx_current_xid(),
4169 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4170         /*
4171          * We may need two file_lock structures for this operation,
4172          * so we get them in advance to avoid races.
4173 @@ -909,7 +936,11 @@ static int __posix_lock_file(struct inod
4174             (request->fl_type != F_UNLCK ||
4175              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4176                 new_fl = locks_alloc_lock();
4177 +               new_fl->fl_xid = xid;
4178 +               vx_locks_inc(new_fl);
4179                 new_fl2 = locks_alloc_lock();
4180 +               new_fl2->fl_xid = xid;
4181 +               vx_locks_inc(new_fl2);
4182         }
4183  
4184         spin_lock(&inode->i_lock);
4185 @@ -1118,7 +1149,8 @@ static int __posix_lock_file(struct inod
4186  int posix_lock_file(struct file *filp, struct file_lock *fl,
4187                         struct file_lock *conflock)
4188  {
4189 -       return __posix_lock_file(file_inode(filp), fl, conflock);
4190 +       return __posix_lock_file(file_inode(filp),
4191 +               fl, conflock, filp->f_xid);
4192  }
4193  EXPORT_SYMBOL(posix_lock_file);
4194  
4195 @@ -1208,7 +1240,7 @@ int locks_mandatory_area(int read_write,
4196         fl.fl_end = offset + count - 1;
4197  
4198         for (;;) {
4199 -               error = __posix_lock_file(inode, &fl, NULL);
4200 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4201                 if (error != FILE_LOCK_DEFERRED)
4202                         break;
4203                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4204 @@ -1549,6 +1581,7 @@ static int generic_add_lease(struct file
4205                 goto out;
4206  
4207         locks_insert_lock(before, lease);
4208 +       vx_locks_inc(lease);
4209         error = 0;
4210  out:
4211         if (is_deleg)
4212 @@ -1991,6 +2024,11 @@ int fcntl_setlk(unsigned int fd, struct
4213         if (file_lock == NULL)
4214                 return -ENOLCK;
4215  
4216 +       vxd_assert(filp->f_xid == vx_current_xid(),
4217 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4218 +       file_lock->fl_xid = filp->f_xid;
4219 +       vx_locks_inc(file_lock);
4220 +
4221         /*
4222          * This might block, so we do it before checking the inode.
4223          */
4224 @@ -2109,6 +2147,11 @@ int fcntl_setlk64(unsigned int fd, struc
4225         if (file_lock == NULL)
4226                 return -ENOLCK;
4227  
4228 +       vxd_assert(filp->f_xid == vx_current_xid(),
4229 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4230 +       file_lock->fl_xid = filp->f_xid;
4231 +       vx_locks_inc(file_lock);
4232 +
4233         /*
4234          * This might block, so we do it before checking the inode.
4235          */
4236 @@ -2378,8 +2421,11 @@ static int locks_show(struct seq_file *f
4237  
4238         lock_get_status(f, fl, iter->li_pos, "");
4239  
4240 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4241 -               lock_get_status(f, bfl, iter->li_pos, " ->");
4242 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4243 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4244 +                       continue;
4245 +               lock_get_status(f, bfl, iter->li_pos, " ->");
4246 +       }
4247  
4248         return 0;
4249  }
4250 diff -NurpP --minimal linux-3.13.10/fs/mount.h linux-3.13.10-vs2.3.6.11/fs/mount.h
4251 --- linux-3.13.10/fs/mount.h    2014-04-17 01:12:32.000000000 +0000
4252 +++ linux-3.13.10-vs2.3.6.11/fs/mount.h 2014-04-17 01:17:10.000000000 +0000
4253 @@ -57,6 +57,7 @@ struct mount {
4254         int mnt_expiry_mark;            /* true if marked for expiry */
4255         int mnt_pinned;
4256         struct path mnt_ex_mountpoint;
4257 +       vtag_t mnt_tag;                 /* tagging used for vfsmount */
4258  };
4259  
4260  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4261 diff -NurpP --minimal linux-3.13.10/fs/namei.c linux-3.13.10-vs2.3.6.11/fs/namei.c
4262 --- linux-3.13.10/fs/namei.c    2014-04-17 01:12:32.000000000 +0000
4263 +++ linux-3.13.10-vs2.3.6.11/fs/namei.c 2014-04-17 01:17:10.000000000 +0000
4264 @@ -34,9 +34,19 @@
4265  #include <linux/device_cgroup.h>
4266  #include <linux/fs_struct.h>
4267  #include <linux/posix_acl.h>
4268 +#include <linux/proc_fs.h>
4269 +#include <linux/magic.h>
4270 +#include <linux/vserver/inode.h>
4271 +#include <linux/vs_base.h>
4272 +#include <linux/vs_tag.h>
4273 +#include <linux/vs_cowbl.h>
4274 +#include <linux/vs_device.h>
4275 +#include <linux/vs_context.h>
4276 +#include <linux/pid_namespace.h>
4277  #include <asm/uaccess.h>
4278  
4279  #include "internal.h"
4280 +#include "proc/internal.h"
4281  #include "mount.h"
4282  
4283  /* [Feb-1997 T. Schoebel-Theuer]
4284 @@ -266,6 +276,89 @@ static int check_acl(struct inode *inode
4285         return -EAGAIN;
4286  }
4287  
4288 +static inline int dx_barrier(const struct inode *inode)
4289 +{
4290 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4291 +               vxwprintk_task(1, "did hit the barrier.");
4292 +               return 1;
4293 +       }
4294 +       return 0;
4295 +}
4296 +
4297 +static int __dx_permission(const struct inode *inode, int mask)
4298 +{
4299 +       if (dx_barrier(inode))
4300 +               return -EACCES;
4301 +
4302 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4303 +               /* devpts is xid tagged */
4304 +               if (S_ISDIR(inode->i_mode) ||
4305 +                   vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4306 +                       return 0;
4307 +
4308 +               /* just pretend we didn't find anything */
4309 +               return -ENOENT;
4310 +       }
4311 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4312 +               struct proc_dir_entry *de = PDE(inode);
4313 +
4314 +               if (de && !vx_hide_check(0, de->vx_flags))
4315 +                       goto out;
4316 +
4317 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4318 +                       struct pid *pid;
4319 +                       struct task_struct *tsk;
4320 +
4321 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4322 +                           vx_flags(VXF_STATE_SETUP, 0))
4323 +                               return 0;
4324 +
4325 +                       pid = PROC_I(inode)->pid;
4326 +                       if (!pid)
4327 +                               goto out;
4328 +
4329 +                       rcu_read_lock();
4330 +                       tsk = pid_task(pid, PIDTYPE_PID);
4331 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4332 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4333 +                       if (tsk &&
4334 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4335 +                               rcu_read_unlock();
4336 +                               return 0;
4337 +                       }
4338 +                       rcu_read_unlock();
4339 +               }
4340 +               else {
4341 +                       /* FIXME: Should we block some entries here? */
4342 +                       return 0;
4343 +               }
4344 +       }
4345 +       else {
4346 +               if (dx_notagcheck(inode->i_sb) ||
4347 +                   dx_check((vxid_t)i_tag_read(inode),
4348 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4349 +                       return 0;
4350 +       }
4351 +
4352 +out:
4353 +       return -EACCES;
4354 +}
4355 +
4356 +int dx_permission(const struct inode *inode, int mask)
4357 +{
4358 +       int ret = __dx_permission(inode, mask);
4359 +       if (unlikely(ret)) {
4360 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4361 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4362 +#endif
4363 +                   vxwprintk_task(1,
4364 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4365 +                       mask, inode->i_sb->s_id, inode,
4366 +                       i_tag_read(inode), inode->i_ino);
4367 +       }
4368 +       return ret;
4369 +}
4370 +
4371  /*
4372   * This does the basic permission checking
4373   */
4374 @@ -388,10 +481,14 @@ int __inode_permission(struct inode *ino
4375                 /*
4376                  * Nobody gets write access to an immutable file.
4377                  */
4378 -               if (IS_IMMUTABLE(inode))
4379 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4380                         return -EACCES;
4381         }
4382  
4383 +       retval = dx_permission(inode, mask);
4384 +       if (retval)
4385 +               return retval;
4386 +
4387         retval = do_inode_permission(inode, mask);
4388         if (retval)
4389                 return retval;
4390 @@ -1238,7 +1335,8 @@ static void follow_dotdot(struct nameida
4391  
4392                 if (nd->path.dentry == nd->root.dentry &&
4393                     nd->path.mnt == nd->root.mnt) {
4394 -                       break;
4395 +                       /* for sane '/' avoid follow_mount() */
4396 +                       return;
4397                 }
4398                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4399                         /* rare case of legitimate dget_parent()... */
4400 @@ -1383,6 +1481,9 @@ static int lookup_fast(struct nameidata
4401                                 goto unlazy;
4402                         }
4403                 }
4404 +
4405 +               /* FIXME: check dx permission */
4406 +
4407                 path->mnt = mnt;
4408                 path->dentry = dentry;
4409                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4410 @@ -1413,6 +1514,8 @@ unlazy:
4411                 }
4412         }
4413  
4414 +       /* FIXME: check dx permission */
4415 +
4416         path->mnt = mnt;
4417         path->dentry = dentry;
4418         err = follow_managed(path, nd->flags);
4419 @@ -2400,7 +2503,7 @@ static int may_delete(struct inode *dir,
4420                 return -EPERM;
4421  
4422         if (check_sticky(dir, inode) || IS_APPEND(inode) ||
4423 -           IS_IMMUTABLE(inode) || IS_SWAPFILE(inode))
4424 +               IS_IXORUNLINK(inode) || IS_SWAPFILE(inode))
4425                 return -EPERM;
4426         if (isdir) {
4427                 if (!d_is_directory(victim) && !d_is_autodir(victim))
4428 @@ -2480,19 +2583,25 @@ int vfs_create(struct inode *dir, struct
4429                 bool want_excl)
4430  {
4431         int error = may_create(dir, dentry);
4432 -       if (error)
4433 +       if (error) {
4434 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4435                 return error;
4436 +       }
4437  
4438         if (!dir->i_op->create)
4439                 return -EACCES; /* shouldn't it be ENOSYS? */
4440         mode &= S_IALLUGO;
4441         mode |= S_IFREG;
4442         error = security_inode_create(dir, dentry, mode);
4443 -       if (error)
4444 +       if (error) {
4445 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4446                 return error;
4447 +       }
4448         error = dir->i_op->create(dir, dentry, mode, want_excl);
4449         if (!error)
4450                 fsnotify_create(dir, dentry);
4451 +       else
4452 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4453         return error;
4454  }
4455  
4456 @@ -2527,6 +2636,15 @@ static int may_open(struct path *path, i
4457                 break;
4458         }
4459  
4460 +#ifdef CONFIG_VSERVER_COWBL
4461 +       if (IS_COW(inode) &&
4462 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4463 +               if (IS_COW_LINK(inode))
4464 +                       return -EMLINK;
4465 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4466 +               mark_inode_dirty(inode);
4467 +       }
4468 +#endif
4469         error = inode_permission(inode, acc_mode);
4470         if (error)
4471                 return error;
4472 @@ -3022,6 +3140,16 @@ finish_open:
4473         }
4474  finish_open_created:
4475         error = may_open(&nd->path, acc_mode, open_flag);
4476 +#ifdef CONFIG_VSERVER_COWBL
4477 +       if (error == -EMLINK) {
4478 +               struct dentry *dentry;
4479 +               dentry = cow_break_link(name->name);
4480 +               if (IS_ERR(dentry))
4481 +                       error = PTR_ERR(dentry);
4482 +               else
4483 +                       dput(dentry);
4484 +       }
4485 +#endif
4486         if (error)
4487                 goto out;
4488         file->f_path.mnt = nd->path.mnt;
4489 @@ -3147,6 +3275,7 @@ static struct file *path_openat(int dfd,
4490         int opened = 0;
4491         int error;
4492  
4493 +restart:
4494         file = get_empty_filp();
4495         if (IS_ERR(file))
4496                 return file;
4497 @@ -3188,6 +3317,16 @@ static struct file *path_openat(int dfd,
4498                 error = do_last(nd, &path, file, op, &opened, pathname);
4499                 put_link(nd, &link, cookie);
4500         }
4501 +
4502 +#ifdef CONFIG_VSERVER_COWBL
4503 +       if (error == -EMLINK) {
4504 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4505 +                       path_put(&nd->root);
4506 +               if (base)
4507 +                       fput(base);
4508 +               goto restart;
4509 +       }
4510 +#endif
4511  out:
4512         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4513                 path_put(&nd->root);
4514 @@ -3303,6 +3442,11 @@ struct dentry *kern_path_create(int dfd,
4515                 goto fail;
4516         }
4517         *path = nd.path;
4518 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4519 +               path->dentry, path->dentry->d_name.len,
4520 +               path->dentry->d_name.name, dentry,
4521 +               dentry->d_name.len, dentry->d_name.name,
4522 +               path->dentry->d_inode);
4523         return dentry;
4524  fail:
4525         dput(dentry);
4526 @@ -3850,7 +3994,7 @@ int vfs_link(struct dentry *old_dentry,
4527         /*
4528          * A link to an append-only or immutable file cannot be created.
4529          */
4530 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4531 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4532                 return -EPERM;
4533         if (!dir->i_op->link)
4534                 return -EPERM;
4535 @@ -4305,6 +4449,287 @@ int generic_readlink(struct dentry *dent
4536         return res;
4537  }
4538  
4539 +
4540 +#ifdef CONFIG_VSERVER_COWBL
4541 +
4542 +static inline
4543 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4544 +{
4545 +       loff_t ppos = 0;
4546 +       loff_t opos = 0;
4547 +
4548 +       return do_splice_direct(in, &ppos, out, &opos, len, 0);
4549 +}
4550 +
4551 +struct dentry *cow_break_link(const char *pathname)
4552 +{
4553 +       int ret, mode, pathlen, redo = 0, drop = 1;
4554 +       struct nameidata old_nd, dir_nd;
4555 +       struct path dir_path, *old_path, *new_path;
4556 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4557 +       struct file *old_file;
4558 +       struct file *new_file;
4559 +       char *to, *path, pad='\251';
4560 +       loff_t size;
4561 +
4562 +       vxdprintk(VXD_CBIT(misc, 1),
4563 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4564 +
4565 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4566 +       ret = -ENOMEM;
4567 +       if (!path)
4568 +               goto out;
4569 +
4570 +       /* old_nd.path will have refs to dentry and mnt */
4571 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4572 +       vxdprintk(VXD_CBIT(misc, 2),
4573 +               "do_path_lookup(old): %d", ret);
4574 +       if (ret < 0)
4575 +               goto out_free_path;
4576 +
4577 +       /* dentry/mnt refs handed over to old_path */
4578 +       old_path = &old_nd.path;
4579 +       /* no explicit reference for old_dentry here */
4580 +       old_dentry = old_path->dentry;
4581 +
4582 +       mode = old_dentry->d_inode->i_mode;
4583 +       to = d_path(old_path, path, PATH_MAX-2);
4584 +       pathlen = strlen(to);
4585 +       vxdprintk(VXD_CBIT(misc, 2),
4586 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4587 +               old_dentry,
4588 +               old_dentry->d_name.len, old_dentry->d_name.name,
4589 +               old_dentry->d_name.len);
4590 +
4591 +       to[pathlen + 1] = 0;
4592 +retry:
4593 +       new_dentry = NULL;
4594 +       to[pathlen] = pad--;
4595 +       ret = -ELOOP;
4596 +       if (pad <= '\240')
4597 +               goto out_rel_old;
4598 +
4599 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4600 +
4601 +       /* dir_nd.path will have refs to dentry and mnt */
4602 +       ret = do_path_lookup(AT_FDCWD, to,
4603 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4604 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4605 +       if (ret < 0)
4606 +               goto retry;
4607 +
4608 +       /* this puppy downs the dir inode mutex if successful.
4609 +          dir_path will hold refs to dentry and mnt and
4610 +          we'll have write access to the mnt */
4611 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4612 +       if (!new_dentry || IS_ERR(new_dentry)) {
4613 +               path_put(&dir_nd.path);
4614 +               vxdprintk(VXD_CBIT(misc, 2),
4615 +                       "kern_path_create(new) failed with %ld",
4616 +                       PTR_ERR(new_dentry));
4617 +               goto retry;
4618 +       }
4619 +       vxdprintk(VXD_CBIT(misc, 2),
4620 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4621 +               new_dentry,
4622 +               new_dentry->d_name.len, new_dentry->d_name.name,
4623 +               new_dentry->d_name.len);
4624 +
4625 +       /* take a reference on new_dentry */
4626 +       dget(new_dentry);
4627 +
4628 +       /* dentry/mnt refs handed over to new_path */
4629 +       new_path = &dir_path;
4630 +
4631 +       /* dentry for old/new dir */
4632 +       dir = dir_nd.path.dentry;
4633 +
4634 +       /* give up reference on dir */
4635 +       dput(new_path->dentry);
4636 +
4637 +       /* new_dentry already has a reference */
4638 +       new_path->dentry = new_dentry;
4639 +
4640 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4641 +       vxdprintk(VXD_CBIT(misc, 2),
4642 +               "vfs_create(new): %d", ret);
4643 +       if (ret == -EEXIST) {
4644 +               path_put(&dir_nd.path);
4645 +               mutex_unlock(&dir->d_inode->i_mutex);
4646 +               mnt_drop_write(new_path->mnt);
4647 +               path_put(new_path);
4648 +               new_dentry = NULL;
4649 +               goto retry;
4650 +       }
4651 +       else if (ret < 0)
4652 +               goto out_unlock_new;
4653 +
4654 +       /* drop out early, ret passes ENOENT */
4655 +       ret = -ENOENT;
4656 +       if ((redo = d_unhashed(old_dentry)))
4657 +               goto out_unlock_new;
4658 +
4659 +       /* doesn't change refs for old_path */
4660 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4661 +       vxdprintk(VXD_CBIT(misc, 2),
4662 +               "dentry_open(old): %p", old_file);
4663 +       if (IS_ERR(old_file)) {
4664 +               ret = PTR_ERR(old_file);
4665 +               goto out_unlock_new;
4666 +       }
4667 +
4668 +       /* doesn't change refs for new_path */
4669 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4670 +       vxdprintk(VXD_CBIT(misc, 2),
4671 +               "dentry_open(new): %p", new_file);
4672 +       if (IS_ERR(new_file)) {
4673 +               ret = PTR_ERR(new_file);
4674 +               goto out_fput_old;
4675 +       }
4676 +
4677 +       /* unlock the inode mutex from kern_path_create() */
4678 +       mutex_unlock(&dir->d_inode->i_mutex);
4679 +
4680 +       /* drop write access to mnt */
4681 +       mnt_drop_write(new_path->mnt);
4682 +
4683 +       drop = 0;
4684 +
4685 +       size = i_size_read(old_file->f_dentry->d_inode);
4686 +       ret = do_cow_splice(old_file, new_file, size);
4687 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4688 +       if (ret < 0) {
4689 +               goto out_fput_both;
4690 +       } else if (ret < size) {
4691 +               ret = -ENOSPC;
4692 +               goto out_fput_both;
4693 +       } else {
4694 +               struct inode *old_inode = old_dentry->d_inode;
4695 +               struct inode *new_inode = new_dentry->d_inode;
4696 +               struct iattr attr = {
4697 +                       .ia_uid = old_inode->i_uid,
4698 +                       .ia_gid = old_inode->i_gid,
4699 +                       .ia_valid = ATTR_UID | ATTR_GID
4700 +                       };
4701 +
4702 +               setattr_copy(new_inode, &attr);
4703 +               mark_inode_dirty(new_inode);
4704 +       }
4705 +
4706 +       /* lock rename mutex */
4707 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4708 +
4709 +       /* drop out late */
4710 +       ret = -ENOENT;
4711 +       if ((redo = d_unhashed(old_dentry)))
4712 +               goto out_unlock;
4713 +
4714 +       vxdprintk(VXD_CBIT(misc, 2),
4715 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4716 +               new_dentry->d_name.len, new_dentry->d_name.name,
4717 +               new_dentry->d_name.len,
4718 +               old_dentry->d_name.len, old_dentry->d_name.name,
4719 +               old_dentry->d_name.len);
4720 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4721 +               old_dentry->d_parent->d_inode, old_dentry, NULL);
4722 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4723 +
4724 +out_unlock:
4725 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4726 +
4727 +out_fput_both:
4728 +       vxdprintk(VXD_CBIT(misc, 3),
4729 +               "fput(new_file=%p[#%ld])", new_file,
4730 +               atomic_long_read(&new_file->f_count));
4731 +       fput(new_file);
4732 +
4733 +out_fput_old:
4734 +       vxdprintk(VXD_CBIT(misc, 3),
4735 +               "fput(old_file=%p[#%ld])", old_file,
4736 +               atomic_long_read(&old_file->f_count));
4737 +       fput(old_file);
4738 +
4739 +out_unlock_new:
4740 +       /* drop references from dir_nd.path */
4741 +       path_put(&dir_nd.path);
4742 +
4743 +       if (drop) {
4744 +               /* unlock the inode mutex from kern_path_create() */
4745 +               mutex_unlock(&dir->d_inode->i_mutex);
4746 +
4747 +               /* drop write access to mnt */
4748 +               mnt_drop_write(new_path->mnt);
4749 +       }
4750 +
4751 +       if (!ret)
4752 +               goto out_redo;
4753 +
4754 +       /* error path cleanup */
4755 +       vfs_unlink(dir->d_inode, new_dentry, NULL);
4756 +
4757 +out_redo:
4758 +       if (!redo)
4759 +               goto out_rel_both;
4760 +
4761 +       /* lookup dentry once again
4762 +          old_nd.path will be freed as old_path in out_rel_old */
4763 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4764 +       if (ret)
4765 +               goto out_rel_both;
4766 +
4767 +       /* drop reference on new_dentry */
4768 +       dput(new_dentry);
4769 +       new_dentry = old_path->dentry;
4770 +       dget(new_dentry);
4771 +       vxdprintk(VXD_CBIT(misc, 2),
4772 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4773 +               new_dentry,
4774 +               new_dentry->d_name.len, new_dentry->d_name.name,
4775 +               new_dentry->d_name.len);
4776 +
4777 +out_rel_both:
4778 +       if (new_path)
4779 +               path_put(new_path);
4780 +out_rel_old:
4781 +       path_put(old_path);
4782 +out_free_path:
4783 +       kfree(path);
4784 +out:
4785 +       if (ret) {
4786 +               dput(new_dentry);
4787 +               new_dentry = ERR_PTR(ret);
4788 +       }
4789 +       vxdprintk(VXD_CBIT(misc, 3),
4790 +               "cow_break_link returning with %p", new_dentry);
4791 +       return new_dentry;
4792 +}
4793 +
4794 +#endif
4795 +
4796 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4797 +{
4798 +       struct path path;
4799 +       struct vfsmount *vmnt;
4800 +       char *pstr, *root;
4801 +       int length = 0;
4802 +
4803 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4804 +       if (!pstr)
4805 +               return 0;
4806 +
4807 +       vmnt = &ns->root->mnt;
4808 +       path.mnt = vmnt;
4809 +       path.dentry = vmnt->mnt_root;
4810 +       root = d_path(&path, pstr, PATH_MAX - 2);
4811 +       length = sprintf(buffer + length,
4812 +               "Namespace:\t%p [#%u]\n"
4813 +               "RootPath:\t%s\n",
4814 +               ns, atomic_read(&ns->count),
4815 +               root);
4816 +       kfree(pstr);
4817 +       return length;
4818 +}
4819 +
4820  /* get the link contents into pagecache */
4821  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4822  {
4823 @@ -4427,3 +4852,4 @@ EXPORT_SYMBOL(vfs_symlink);
4824  EXPORT_SYMBOL(vfs_unlink);
4825  EXPORT_SYMBOL(dentry_unhash);
4826  EXPORT_SYMBOL(generic_readlink);
4827 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4828 diff -NurpP --minimal linux-3.13.10/fs/namespace.c linux-3.13.10-vs2.3.6.11/fs/namespace.c
4829 --- linux-3.13.10/fs/namespace.c        2014-04-17 01:12:32.000000000 +0000
4830 +++ linux-3.13.10-vs2.3.6.11/fs/namespace.c     2014-04-17 01:18:37.000000000 +0000
4831 @@ -24,6 +24,11 @@
4832  #include <linux/proc_ns.h>
4833  #include <linux/magic.h>
4834  #include <linux/bootmem.h>
4835 +#include <linux/vs_base.h>
4836 +#include <linux/vs_context.h>
4837 +#include <linux/vs_tag.h>
4838 +#include <linux/vserver/space.h>
4839 +#include <linux/vserver/global.h>
4840  #include "pnode.h"
4841  #include "internal.h"
4842  
4843 @@ -839,6 +844,10 @@ vfs_kern_mount(struct file_system_type *
4844         if (!type)
4845                 return ERR_PTR(-ENODEV);
4846  
4847 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4848 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4849 +               return ERR_PTR(-EPERM);
4850 +
4851         mnt = alloc_vfsmnt(name);
4852         if (!mnt)
4853                 return ERR_PTR(-ENOMEM);
4854 @@ -899,6 +908,7 @@ static struct mount *clone_mnt(struct mo
4855         mnt->mnt.mnt_root = dget(root);
4856         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4857         mnt->mnt_parent = mnt;
4858 +       mnt->mnt_tag = old->mnt_tag;
4859         lock_mount_hash();
4860         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4861         unlock_mount_hash();
4862 @@ -1369,7 +1379,8 @@ static int do_umount(struct mount *mnt,
4863   */
4864  static inline bool may_mount(void)
4865  {
4866 -       return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4867 +       return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4868 +               CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4869  }
4870  
4871  /*
4872 @@ -1785,6 +1796,7 @@ static int do_change_type(struct path *p
4873                 if (err)
4874                         goto out_unlock;
4875         }
4876 +       // mnt->mnt_flags = mnt_flags;
4877  
4878         lock_mount_hash();
4879         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4880 @@ -1813,12 +1825,14 @@ static bool has_locked_children(struct m
4881   * do loopback mount.
4882   */
4883  static int do_loopback(struct path *path, const char *old_name,
4884 -                               int recurse)
4885 +       vtag_t tag, unsigned long flags, int mnt_flags)
4886  {
4887         struct path old_path;
4888         struct mount *mnt = NULL, *old, *parent;
4889         struct mountpoint *mp;
4890 +       int recurse = flags & MS_REC;
4891         int err;
4892 +
4893         if (!old_name || !*old_name)
4894                 return -EINVAL;
4895         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4896 @@ -1898,7 +1912,7 @@ static int change_mount_flags(struct vfs
4897   * on it - tough luck.
4898   */
4899  static int do_remount(struct path *path, int flags, int mnt_flags,
4900 -                     void *data)
4901 +       void *data, vxid_t xid)
4902  {
4903         int err;
4904         struct super_block *sb = path->mnt->mnt_sb;
4905 @@ -2377,6 +2391,7 @@ long do_mount(const char *dev_name, cons
4906         struct path path;
4907         int retval = 0;
4908         int mnt_flags = 0;
4909 +       vtag_t tag = 0;
4910  
4911         /* Discard magic */
4912         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4913 @@ -2406,6 +2421,12 @@ long do_mount(const char *dev_name, cons
4914         if (!(flags & MS_NOATIME))
4915                 mnt_flags |= MNT_RELATIME;
4916  
4917 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4918 +               /* FIXME: bind and re-mounts get the tag flag? */
4919 +               if (flags & (MS_BIND|MS_REMOUNT))
4920 +                       flags |= MS_TAGID;
4921 +       }
4922 +
4923         /* Separate the per-mountpoint flags */
4924         if (flags & MS_NOSUID)
4925                 mnt_flags |= MNT_NOSUID;
4926 @@ -2422,15 +2443,17 @@ long do_mount(const char *dev_name, cons
4927         if (flags & MS_RDONLY)
4928                 mnt_flags |= MNT_READONLY;
4929  
4930 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4931 +               mnt_flags |= MNT_NODEV;
4932         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4933                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4934                    MS_STRICTATIME);
4935  
4936         if (flags & MS_REMOUNT)
4937                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4938 -                                   data_page);
4939 +                                   data_page, tag);
4940         else if (flags & MS_BIND)
4941 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
4942 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4943         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4944                 retval = do_change_type(&path, flags);
4945         else if (flags & MS_MOVE)
4946 @@ -2546,6 +2569,7 @@ struct mnt_namespace *copy_mnt_ns(unsign
4947                         p = next_mnt(p, old);
4948         }
4949         namespace_unlock();
4950 +       atomic_inc(&vs_global_mnt_ns);
4951  
4952         if (rootmnt)
4953                 mntput(rootmnt);
4954 @@ -2727,9 +2751,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4955         new_mnt = real_mount(new.mnt);
4956         root_mnt = real_mount(root.mnt);
4957         old_mnt = real_mount(old.mnt);
4958 -       if (IS_MNT_SHARED(old_mnt) ||
4959 +       if ((IS_MNT_SHARED(old_mnt) ||
4960                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4961 -               IS_MNT_SHARED(root_mnt->mnt_parent))
4962 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4963 +               !vx_flags(VXF_STATE_SETUP, 0))
4964                 goto out4;
4965         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4966                 goto out4;
4967 @@ -2859,6 +2884,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4968         if (!atomic_dec_and_test(&ns->count))
4969                 return;
4970         drop_collected_mounts(&ns->root->mnt);
4971 +       atomic_dec(&vs_global_mnt_ns);
4972         free_mnt_ns(ns);
4973  }
4974  
4975 diff -NurpP --minimal linux-3.13.10/fs/nfs/client.c linux-3.13.10-vs2.3.6.11/fs/nfs/client.c
4976 --- linux-3.13.10/fs/nfs/client.c       2014-01-22 20:39:06.000000000 +0000
4977 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/client.c    2014-01-31 20:38:03.000000000 +0000
4978 @@ -685,6 +685,9 @@ int nfs_init_server_rpcclient(struct nfs
4979         if (server->flags & NFS_MOUNT_SOFT)
4980                 server->client->cl_softrtry = 1;
4981  
4982 +       server->client->cl_tag = 0;
4983 +       if (server->flags & NFS_MOUNT_TAGGED)
4984 +               server->client->cl_tag = 1;
4985         return 0;
4986  }
4987  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4988 @@ -863,6 +866,10 @@ static void nfs_server_set_fsinfo(struct
4989                 server->acdirmin = server->acdirmax = 0;
4990         }
4991  
4992 +       /* FIXME: needs fsinfo
4993 +       if (server->flags & NFS_MOUNT_TAGGED)
4994 +               sb->s_flags |= MS_TAGGED;       */
4995 +
4996         server->maxfilesize = fsinfo->maxfilesize;
4997  
4998         server->time_delta = fsinfo->time_delta;
4999 diff -NurpP --minimal linux-3.13.10/fs/nfs/dir.c linux-3.13.10-vs2.3.6.11/fs/nfs/dir.c
5000 --- linux-3.13.10/fs/nfs/dir.c  2014-04-17 01:12:32.000000000 +0000
5001 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/dir.c       2014-02-25 11:26:10.000000000 +0000
5002 @@ -37,6 +37,7 @@
5003  #include <linux/sched.h>
5004  #include <linux/kmemleak.h>
5005  #include <linux/xattr.h>
5006 +#include <linux/vs_tag.h>
5007  
5008  #include "delegation.h"
5009  #include "iostat.h"
5010 @@ -1319,6 +1320,7 @@ struct dentry *nfs_lookup(struct inode *
5011         /* Success: notify readdir to use READDIRPLUS */
5012         nfs_advise_use_readdirplus(dir);
5013  
5014 +       dx_propagate_tag(nd, inode);
5015  no_entry:
5016         res = d_materialise_unique(dentry, inode);
5017         if (res != NULL) {
5018 diff -NurpP --minimal linux-3.13.10/fs/nfs/inode.c linux-3.13.10-vs2.3.6.11/fs/nfs/inode.c
5019 --- linux-3.13.10/fs/nfs/inode.c        2014-04-17 01:12:32.000000000 +0000
5020 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/inode.c     2014-03-12 15:51:07.000000000 +0000
5021 @@ -38,6 +38,7 @@
5022  #include <linux/slab.h>
5023  #include <linux/compat.h>
5024  #include <linux/freezer.h>
5025 +#include <linux/vs_tag.h>
5026  
5027  #include <asm/uaccess.h>
5028  
5029 @@ -359,6 +360,8 @@ nfs_fhget(struct super_block *sb, struct
5030         if (inode->i_state & I_NEW) {
5031                 struct nfs_inode *nfsi = NFS_I(inode);
5032                 unsigned long now = jiffies;
5033 +               kuid_t kuid;
5034 +               kgid_t kgid;
5035  
5036                 /* We set i_ino for the few things that still rely on it,
5037                  * such as stat(2) */
5038 @@ -403,8 +406,8 @@ nfs_fhget(struct super_block *sb, struct
5039                 inode->i_version = 0;
5040                 inode->i_size = 0;
5041                 clear_nlink(inode);
5042 -               inode->i_uid = make_kuid(&init_user_ns, -2);
5043 -               inode->i_gid = make_kgid(&init_user_ns, -2);
5044 +               kuid = make_kuid(&init_user_ns, -2);
5045 +               kgid = make_kgid(&init_user_ns, -2);
5046                 inode->i_blocks = 0;
5047                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5048                 nfsi->write_io = 0;
5049 @@ -438,11 +441,11 @@ nfs_fhget(struct super_block *sb, struct
5050                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5051                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5052                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5053 -                       inode->i_uid = fattr->uid;
5054 +                       kuid = fattr->uid;
5055                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5056                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5057                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5058 -                       inode->i_gid = fattr->gid;
5059 +                       kgid = fattr->gid;
5060                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5061                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5062                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5063 @@ -453,6 +456,10 @@ nfs_fhget(struct super_block *sb, struct
5064                          */
5065                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5066                 }
5067 +               inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5068 +               inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5069 +               inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
5070 +                               /* maybe fattr->xid someday */
5071  
5072                 nfs_setsecurity(inode, fattr, label);
5073  
5074 @@ -578,6 +585,8 @@ void nfs_setattr_update_inode(struct ino
5075                         inode->i_uid = attr->ia_uid;
5076                 if ((attr->ia_valid & ATTR_GID) != 0)
5077                         inode->i_gid = attr->ia_gid;
5078 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5079 +                       inode->i_tag = attr->ia_tag;
5080                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5081                 spin_unlock(&inode->i_lock);
5082         }
5083 @@ -1092,7 +1101,9 @@ static int nfs_check_inode_attributes(st
5084         struct nfs_inode *nfsi = NFS_I(inode);
5085         loff_t cur_size, new_isize;
5086         unsigned long invalid = 0;
5087 -
5088 +       kuid_t kuid;
5089 +       kgid_t kgid;
5090 +       ktag_t ktag;
5091  
5092         if (nfs_have_delegated_attributes(inode))
5093                 return 0;
5094 @@ -1117,13 +1128,18 @@ static int nfs_check_inode_attributes(st
5095                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5096         }
5097  
5098 +       kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
5099 +       kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
5100 +       ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
5101 +
5102         /* Have any file permissions changed? */
5103         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5104                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5105 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5106 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5107                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5108 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5109 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5110                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5111 +               /* maybe check for tag too? */
5112  
5113         /* Has the link count changed? */
5114         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5115 @@ -1440,6 +1456,9 @@ static int nfs_update_inode(struct inode
5116         unsigned long invalid = 0;
5117         unsigned long now = jiffies;
5118         unsigned long save_cache_validity;
5119 +       kuid_t kuid;
5120 +       kgid_t kgid;
5121 +       ktag_t ktag;
5122  
5123         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5124                         __func__, inode->i_sb->s_id, inode->i_ino,
5125 @@ -1541,6 +1560,9 @@ static int nfs_update_inode(struct inode
5126                                 | NFS_INO_REVAL_PAGECACHE
5127                                 | NFS_INO_REVAL_FORCED);
5128  
5129 +       kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5130 +       kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5131 +       ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
5132  
5133         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5134                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5135 @@ -1583,6 +1605,10 @@ static int nfs_update_inode(struct inode
5136                                 | NFS_INO_INVALID_ACL
5137                                 | NFS_INO_REVAL_FORCED);
5138  
5139 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5140 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5141 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
5142 +
5143         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5144                 if (inode->i_nlink != fattr->nlink) {
5145                         invalid |= NFS_INO_INVALID_ATTR;
5146 diff -NurpP --minimal linux-3.13.10/fs/nfs/nfs3xdr.c linux-3.13.10-vs2.3.6.11/fs/nfs/nfs3xdr.c
5147 --- linux-3.13.10/fs/nfs/nfs3xdr.c      2013-05-31 13:45:24.000000000 +0000
5148 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/nfs3xdr.c   2014-01-31 20:38:03.000000000 +0000
5149 @@ -20,6 +20,7 @@
5150  #include <linux/nfs3.h>
5151  #include <linux/nfs_fs.h>
5152  #include <linux/nfsacl.h>
5153 +#include <linux/vs_tag.h>
5154  #include "internal.h"
5155  
5156  #define NFSDBG_FACILITY                NFSDBG_XDR
5157 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5158   *             set_mtime       mtime;
5159   *     };
5160   */
5161 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5162 +static void encode_sattr3(struct xdr_stream *xdr,
5163 +       const struct iattr *attr, int tag)
5164  {
5165         u32 nbytes;
5166         __be32 *p;
5167 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5168         } else
5169                 *p++ = xdr_zero;
5170  
5171 -       if (attr->ia_valid & ATTR_UID) {
5172 +       if (attr->ia_valid & ATTR_UID ||
5173 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5174                 *p++ = xdr_one;
5175 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5176 +               *p++ = cpu_to_be32(from_kuid(&init_user_ns,
5177 +                       TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
5178         } else
5179                 *p++ = xdr_zero;
5180  
5181 -       if (attr->ia_valid & ATTR_GID) {
5182 +       if (attr->ia_valid & ATTR_GID ||
5183 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5184                 *p++ = xdr_one;
5185 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5186 +               *p++ = cpu_to_be32(from_kgid(&init_user_ns,
5187 +                       TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
5188         } else
5189                 *p++ = xdr_zero;
5190  
5191 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5192                                       const struct nfs3_sattrargs *args)
5193  {
5194         encode_nfs_fh3(xdr, args->fh);
5195 -       encode_sattr3(xdr, args->sattr);
5196 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5197         encode_sattrguard3(xdr, args);
5198  }
5199  
5200 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5201   *     };
5202   */
5203  static void encode_createhow3(struct xdr_stream *xdr,
5204 -                             const struct nfs3_createargs *args)
5205 +       const struct nfs3_createargs *args, int tag)
5206  {
5207         encode_uint32(xdr, args->createmode);
5208         switch (args->createmode) {
5209         case NFS3_CREATE_UNCHECKED:
5210         case NFS3_CREATE_GUARDED:
5211 -               encode_sattr3(xdr, args->sattr);
5212 +               encode_sattr3(xdr, args->sattr, tag);
5213                 break;
5214         case NFS3_CREATE_EXCLUSIVE:
5215                 encode_createverf3(xdr, args->verifier);
5216 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5217                                      const struct nfs3_createargs *args)
5218  {
5219         encode_diropargs3(xdr, args->fh, args->name, args->len);
5220 -       encode_createhow3(xdr, args);
5221 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5222  }
5223  
5224  /*
5225 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5226                                     const struct nfs3_mkdirargs *args)
5227  {
5228         encode_diropargs3(xdr, args->fh, args->name, args->len);
5229 -       encode_sattr3(xdr, args->sattr);
5230 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5231  }
5232  
5233  /*
5234 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5235   *     };
5236   */
5237  static void encode_symlinkdata3(struct xdr_stream *xdr,
5238 -                               const struct nfs3_symlinkargs *args)
5239 +       const struct nfs3_symlinkargs *args, int tag)
5240  {
5241 -       encode_sattr3(xdr, args->sattr);
5242 +       encode_sattr3(xdr, args->sattr, tag);
5243         encode_nfspath3(xdr, args->pages, args->pathlen);
5244  }
5245  
5246 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5247                                       const struct nfs3_symlinkargs *args)
5248  {
5249         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5250 -       encode_symlinkdata3(xdr, args);
5251 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5252  }
5253  
5254  /*
5255 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5256   *     };
5257   */
5258  static void encode_devicedata3(struct xdr_stream *xdr,
5259 -                              const struct nfs3_mknodargs *args)
5260 +       const struct nfs3_mknodargs *args, int tag)
5261  {
5262 -       encode_sattr3(xdr, args->sattr);
5263 +       encode_sattr3(xdr, args->sattr, tag);
5264         encode_specdata3(xdr, args->rdev);
5265  }
5266  
5267  static void encode_mknoddata3(struct xdr_stream *xdr,
5268 -                             const struct nfs3_mknodargs *args)
5269 +       const struct nfs3_mknodargs *args, int tag)
5270  {
5271         encode_ftype3(xdr, args->type);
5272         switch (args->type) {
5273         case NF3CHR:
5274         case NF3BLK:
5275 -               encode_devicedata3(xdr, args);
5276 +               encode_devicedata3(xdr, args, tag);
5277                 break;
5278         case NF3SOCK:
5279         case NF3FIFO:
5280 -               encode_sattr3(xdr, args->sattr);
5281 +               encode_sattr3(xdr, args->sattr, tag);
5282                 break;
5283         case NF3REG:
5284         case NF3DIR:
5285 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5286                                     const struct nfs3_mknodargs *args)
5287  {
5288         encode_diropargs3(xdr, args->fh, args->name, args->len);
5289 -       encode_mknoddata3(xdr, args);
5290 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5291  }
5292  
5293  /*
5294 diff -NurpP --minimal linux-3.13.10/fs/nfs/super.c linux-3.13.10-vs2.3.6.11/fs/nfs/super.c
5295 --- linux-3.13.10/fs/nfs/super.c        2014-01-22 20:39:06.000000000 +0000
5296 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/super.c     2014-01-31 20:38:03.000000000 +0000
5297 @@ -55,6 +55,7 @@
5298  #include <linux/parser.h>
5299  #include <linux/nsproxy.h>
5300  #include <linux/rcupdate.h>
5301 +#include <linux/vs_tag.h>
5302  
5303  #include <asm/uaccess.h>
5304  
5305 @@ -103,6 +104,7 @@ enum {
5306         Opt_mountport,
5307         Opt_mountvers,
5308         Opt_minorversion,
5309 +       Opt_tagid,
5310  
5311         /* Mount options that take string arguments */
5312         Opt_nfsvers,
5313 @@ -115,6 +117,9 @@ enum {
5314         /* Special mount options */
5315         Opt_userspace, Opt_deprecated, Opt_sloppy,
5316  
5317 +       /* Linux-VServer tagging options */
5318 +       Opt_tag, Opt_notag,
5319 +
5320         Opt_err
5321  };
5322  
5323 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5324         { Opt_fscache_uniq, "fsc=%s" },
5325         { Opt_local_lock, "local_lock=%s" },
5326  
5327 +       { Opt_tag, "tag" },
5328 +       { Opt_notag, "notag" },
5329 +       { Opt_tagid, "tagid=%u" },
5330 +
5331         /* The following needs to be listed after all other options */
5332         { Opt_nfsvers, "v%s" },
5333  
5334 @@ -638,6 +647,7 @@ static void nfs_show_mount_options(struc
5335                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5336                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5337                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5338 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5339                 { 0, NULL, NULL }
5340         };
5341         const struct proc_nfs_info *nfs_infop;
5342 @@ -1321,6 +1331,14 @@ static int nfs_parse_mount_options(char
5343                 case Opt_nomigration:
5344                         mnt->options &= NFS_OPTION_MIGRATION;
5345                         break;
5346 +#ifndef CONFIG_TAGGING_NONE
5347 +               case Opt_tag:
5348 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5349 +                       break;
5350 +               case Opt_notag:
5351 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5352 +                       break;
5353 +#endif
5354  
5355                 /*
5356                  * options that take numeric values
5357 @@ -1407,6 +1425,12 @@ static int nfs_parse_mount_options(char
5358                                 goto out_invalid_value;
5359                         mnt->minorversion = option;
5360                         break;
5361 +#ifdef CONFIG_PROPAGATE
5362 +               case Opt_tagid:
5363 +                       /* use args[0] */
5364 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5365 +                       break;
5366 +#endif
5367  
5368                 /*
5369                  * options that take text values
5370 diff -NurpP --minimal linux-3.13.10/fs/nfsd/auth.c linux-3.13.10-vs2.3.6.11/fs/nfsd/auth.c
5371 --- linux-3.13.10/fs/nfsd/auth.c        2013-05-31 13:45:24.000000000 +0000
5372 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/auth.c     2014-01-31 20:38:03.000000000 +0000
5373 @@ -2,6 +2,7 @@
5374  
5375  #include <linux/sched.h>
5376  #include <linux/user_namespace.h>
5377 +#include <linux/vs_tag.h>
5378  #include "nfsd.h"
5379  #include "auth.h"
5380  
5381 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5382  
5383         new->fsuid = rqstp->rq_cred.cr_uid;
5384         new->fsgid = rqstp->rq_cred.cr_gid;
5385 +       /* FIXME: this desperately needs a tag :)
5386 +       new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5387 +                       */
5388  
5389         rqgi = rqstp->rq_cred.cr_group_info;
5390  
5391 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfs3xdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs3xdr.c
5392 --- linux-3.13.10/fs/nfsd/nfs3xdr.c     2013-05-31 13:45:24.000000000 +0000
5393 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs3xdr.c  2014-01-31 20:38:03.000000000 +0000
5394 @@ -8,6 +8,7 @@
5395  
5396  #include <linux/namei.h>
5397  #include <linux/sunrpc/svc_xprt.h>
5398 +#include <linux/vs_tag.h>
5399  #include "xdr3.h"
5400  #include "auth.h"
5401  #include "netns.h"
5402 @@ -98,6 +99,8 @@ static __be32 *
5403  decode_sattr3(__be32 *p, struct iattr *iap)
5404  {
5405         u32     tmp;
5406 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5407 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5408  
5409         iap->ia_valid = 0;
5410  
5411 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5412                 iap->ia_mode = ntohl(*p++);
5413         }
5414         if (*p++) {
5415 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5416 +               kuid = make_kuid(&init_user_ns, ntohl(*p++));
5417                 if (uid_valid(iap->ia_uid))
5418                         iap->ia_valid |= ATTR_UID;
5419         }
5420         if (*p++) {
5421 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5422 +               kgid = make_kgid(&init_user_ns, ntohl(*p++));
5423                 if (gid_valid(iap->ia_gid))
5424                         iap->ia_valid |= ATTR_GID;
5425         }
5426 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5427 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5428 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5429         if (*p++) {
5430                 u64     newsize;
5431  
5432 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5433         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5434         *p++ = htonl((u32) stat->mode);
5435         *p++ = htonl((u32) stat->nlink);
5436 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5437 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5438 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5439 +               TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5440 +               stat->uid, stat->tag)));
5441 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5442 +               TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5443 +               stat->gid, stat->tag)));
5444         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5445                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5446         } else {
5447 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfs4xdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs4xdr.c
5448 --- linux-3.13.10/fs/nfsd/nfs4xdr.c     2014-01-22 20:39:06.000000000 +0000
5449 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs4xdr.c  2014-01-31 20:38:03.000000000 +0000
5450 @@ -46,6 +46,7 @@
5451  #include <linux/utsname.h>
5452  #include <linux/pagemap.h>
5453  #include <linux/sunrpc/svcauth_gss.h>
5454 +#include <linux/vs_tag.h>
5455  
5456  #include "idmap.h"
5457  #include "acl.h"
5458 @@ -2430,14 +2431,18 @@ out_acl:
5459                 WRITE32(stat.nlink);
5460         }
5461         if (bmval1 & FATTR4_WORD1_OWNER) {
5462 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5463 +               status = nfsd4_encode_user(rqstp,
5464 +                       TAGINO_KUID(DX_TAG(dentry->d_inode),
5465 +                       stat.uid, stat.tag), &p, &buflen);
5466                 if (status == nfserr_resource)
5467                         goto out_resource;
5468                 if (status)
5469                         goto out;
5470         }
5471         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5472 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5473 +               status = nfsd4_encode_group(rqstp,
5474 +                       TAGINO_KGID(DX_TAG(dentry->d_inode),
5475 +                       stat.gid, stat.tag), &p, &buflen);
5476                 if (status == nfserr_resource)
5477                         goto out_resource;
5478                 if (status)
5479 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfsxdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfsxdr.c
5480 --- linux-3.13.10/fs/nfsd/nfsxdr.c      2013-05-31 13:45:24.000000000 +0000
5481 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfsxdr.c   2014-01-31 20:38:03.000000000 +0000
5482 @@ -7,6 +7,7 @@
5483  #include "vfs.h"
5484  #include "xdr.h"
5485  #include "auth.h"
5486 +#include <linux/vs_tag.h>
5487  
5488  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5489  
5490 @@ -89,6 +90,8 @@ static __be32 *
5491  decode_sattr(__be32 *p, struct iattr *iap)
5492  {
5493         u32     tmp, tmp1;
5494 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5495 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5496  
5497         iap->ia_valid = 0;
5498  
5499 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5500                 iap->ia_mode = tmp;
5501         }
5502         if ((tmp = ntohl(*p++)) != (u32)-1) {
5503 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5504 +               kuid = make_kuid(&init_user_ns, tmp);
5505                 if (uid_valid(iap->ia_uid))
5506                         iap->ia_valid |= ATTR_UID;
5507         }
5508         if ((tmp = ntohl(*p++)) != (u32)-1) {
5509 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5510 +               kgid = make_kgid(&init_user_ns, tmp);
5511                 if (gid_valid(iap->ia_gid))
5512                         iap->ia_valid |= ATTR_GID;
5513         }
5514 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5515 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5516 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5517         if ((tmp = ntohl(*p++)) != (u32)-1) {
5518                 iap->ia_valid |= ATTR_SIZE;
5519                 iap->ia_size = tmp;
5520 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5521         *p++ = htonl(nfs_ftypes[type >> 12]);
5522         *p++ = htonl((u32) stat->mode);
5523         *p++ = htonl((u32) stat->nlink);
5524 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5525 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5526 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5527 +               TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5528 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5529 +               TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5530  
5531         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5532                 *p++ = htonl(NFS_MAXPATHLEN);
5533 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/dlmglue.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.c
5534 --- linux-3.13.10/fs/ocfs2/dlmglue.c    2014-01-22 20:39:07.000000000 +0000
5535 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.c 2014-01-31 20:38:03.000000000 +0000
5536 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5537         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5538         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5539         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5540 +       lvb->lvb_itag      = cpu_to_be16(i_tag_read(inode));
5541         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5542         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5543         lvb->lvb_iatime_packed  =
5544 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5545  
5546         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5547         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5548 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5549         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5550         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5551         ocfs2_unpack_timespec(&inode->i_atime,
5552 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/dlmglue.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.h
5553 --- linux-3.13.10/fs/ocfs2/dlmglue.h    2012-12-11 03:30:57.000000000 +0000
5554 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.h 2014-01-31 20:38:03.000000000 +0000
5555 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5556         __be16       lvb_inlink;
5557         __be32       lvb_iattr;
5558         __be32       lvb_igeneration;
5559 -       __be32       lvb_reserved2;
5560 +       __be16       lvb_itag;
5561 +       __be16       lvb_reserved2;
5562  };
5563  
5564  #define OCFS2_QINFO_LVB_VERSION 1
5565 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/file.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/file.c
5566 --- linux-3.13.10/fs/ocfs2/file.c       2014-04-17 01:12:32.000000000 +0000
5567 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/file.c    2014-04-17 01:17:10.000000000 +0000
5568 @@ -1119,7 +1119,7 @@ int ocfs2_setattr(struct dentry *dentry,
5569                 attr->ia_valid &= ~ATTR_SIZE;
5570  
5571  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5572 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5573 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5574         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5575                 return 0;
5576  
5577 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/inode.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.c
5578 --- linux-3.13.10/fs/ocfs2/inode.c      2014-01-22 20:39:07.000000000 +0000
5579 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.c   2014-01-31 20:38:03.000000000 +0000
5580 @@ -28,6 +28,7 @@
5581  #include <linux/highmem.h>
5582  #include <linux/pagemap.h>
5583  #include <linux/quotaops.h>
5584 +#include <linux/vs_tag.h>
5585  
5586  #include <asm/byteorder.h>
5587  
5588 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5589  {
5590         unsigned int flags = OCFS2_I(inode)->ip_attr;
5591  
5592 -       inode->i_flags &= ~(S_IMMUTABLE |
5593 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5594                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5595  
5596         if (flags & OCFS2_IMMUTABLE_FL)
5597                 inode->i_flags |= S_IMMUTABLE;
5598 +       if (flags & OCFS2_IXUNLINK_FL)
5599 +               inode->i_flags |= S_IXUNLINK;
5600  
5601         if (flags & OCFS2_SYNC_FL)
5602                 inode->i_flags |= S_SYNC;
5603 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5604                 inode->i_flags |= S_NOATIME;
5605         if (flags & OCFS2_DIRSYNC_FL)
5606                 inode->i_flags |= S_DIRSYNC;
5607 +
5608 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5609 +
5610 +       if (flags & OCFS2_BARRIER_FL)
5611 +               inode->i_vflags |= V_BARRIER;
5612 +       if (flags & OCFS2_COW_FL)
5613 +               inode->i_vflags |= V_COW;
5614  }
5615  
5616  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5617  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5618  {
5619         unsigned int flags = oi->vfs_inode.i_flags;
5620 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5621 +
5622 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5623 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5624 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5625 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5626 +
5627 +       if (flags & S_IMMUTABLE)
5628 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5629 +       if (flags & S_IXUNLINK)
5630 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5631  
5632 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5633 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5634         if (flags & S_SYNC)
5635                 oi->ip_attr |= OCFS2_SYNC_FL;
5636         if (flags & S_APPEND)
5637                 oi->ip_attr |= OCFS2_APPEND_FL;
5638 -       if (flags & S_IMMUTABLE)
5639 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5640         if (flags & S_NOATIME)
5641                 oi->ip_attr |= OCFS2_NOATIME_FL;
5642         if (flags & S_DIRSYNC)
5643                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5644 +
5645 +       if (vflags & V_BARRIER)
5646 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5647 +       if (vflags & V_COW)
5648 +               oi->ip_attr |= OCFS2_COW_FL;
5649  }
5650  
5651  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5652 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5653         struct super_block *sb;
5654         struct ocfs2_super *osb;
5655         int use_plocks = 1;
5656 +       uid_t uid;
5657 +       gid_t gid;
5658  
5659         sb = inode->i_sb;
5660         osb = OCFS2_SB(sb);
5661 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5662         inode->i_generation = le32_to_cpu(fe->i_generation);
5663         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5664         inode->i_mode = le16_to_cpu(fe->i_mode);
5665 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5666 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5667 +       uid = le32_to_cpu(fe->i_uid);
5668 +       gid = le32_to_cpu(fe->i_gid);
5669 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5670 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5671 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5672 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5673  
5674         /* Fast symlinks will have i_size but no allocated clusters. */
5675         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5676 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/inode.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.h
5677 --- linux-3.13.10/fs/ocfs2/inode.h      2013-07-14 17:01:29.000000000 +0000
5678 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.h   2014-01-31 20:38:03.000000000 +0000
5679 @@ -152,6 +152,7 @@ struct buffer_head *ocfs2_bread(struct i
5680  
5681  void ocfs2_set_inode_flags(struct inode *inode);
5682  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5683 +int ocfs2_sync_flags(struct inode *inode, int, int);
5684  
5685  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5686  {
5687 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/ioctl.c
5688 --- linux-3.13.10/fs/ocfs2/ioctl.c      2013-11-25 15:47:00.000000000 +0000
5689 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ioctl.c   2014-01-31 20:38:03.000000000 +0000
5690 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5691         return status;
5692  }
5693  
5694 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5695 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5696 +{
5697 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5698 +       struct buffer_head *bh = NULL;
5699 +       handle_t *handle = NULL;
5700 +       int status;
5701 +
5702 +       status = ocfs2_inode_lock(inode, &bh, 1);
5703 +       if (status < 0) {
5704 +               mlog_errno(status);
5705 +               return status;
5706 +       }
5707 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5708 +       if (IS_ERR(handle)) {
5709 +               status = PTR_ERR(handle);
5710 +               mlog_errno(status);
5711 +               goto bail_unlock;
5712 +       }
5713 +
5714 +       inode->i_flags = flags;
5715 +       inode->i_vflags = vflags;
5716 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5717 +
5718 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5719 +       if (status < 0)
5720 +               mlog_errno(status);
5721 +
5722 +       ocfs2_commit_trans(osb, handle);
5723 +bail_unlock:
5724 +       ocfs2_inode_unlock(inode, 1);
5725 +       brelse(bh);
5726 +       return status;
5727 +}
5728 +
5729 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5730                                 unsigned mask)
5731  {
5732         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5733 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5734                         goto bail_unlock;
5735         }
5736  
5737 +       if (IS_BARRIER(inode)) {
5738 +               vxwprintk_task(1, "messing with the barrier.");
5739 +               goto bail_unlock;
5740 +       }
5741 +
5742         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5743         if (IS_ERR(handle)) {
5744                 status = PTR_ERR(handle);
5745 @@ -881,6 +920,7 @@ bail:
5746         return status;
5747  }
5748  
5749 +
5750  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5751  {
5752         struct inode *inode = file_inode(filp);
5753 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/namei.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/namei.c
5754 --- linux-3.13.10/fs/ocfs2/namei.c      2014-01-22 20:39:07.000000000 +0000
5755 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/namei.c   2014-01-31 20:38:03.000000000 +0000
5756 @@ -41,6 +41,7 @@
5757  #include <linux/slab.h>
5758  #include <linux/highmem.h>
5759  #include <linux/quotaops.h>
5760 +#include <linux/vs_tag.h>
5761  
5762  #include <cluster/masklog.h>
5763  
5764 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5765         struct ocfs2_dinode *fe = NULL;
5766         struct ocfs2_extent_list *fel;
5767         u16 feat;
5768 +       ktag_t ktag;
5769  
5770         *new_fe_bh = NULL;
5771  
5772 @@ -512,8 +514,13 @@ static int __ocfs2_mknod_locked(struct i
5773         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5774         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5775         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5776 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5777 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5778 +
5779 +       ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5780 +       fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5781 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5782 +       fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5783 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5784 +       inode->i_tag = ktag; /* is this correct? */
5785         fe->i_mode = cpu_to_le16(inode->i_mode);
5786         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5787                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5788 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ocfs2.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2.h
5789 --- linux-3.13.10/fs/ocfs2/ocfs2.h      2013-11-25 15:45:04.000000000 +0000
5790 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2.h   2014-01-31 20:38:03.000000000 +0000
5791 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5792                                                      writes */
5793         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5794         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5795 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5796  };
5797  
5798  #define OCFS2_OSB_SOFT_RO                      0x0001
5799 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
5800 --- linux-3.13.10/fs/ocfs2/ocfs2_fs.h   2012-12-11 03:30:57.000000000 +0000
5801 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2_fs.h        2014-01-31 20:38:03.000000000 +0000
5802 @@ -266,6 +266,11 @@
5803  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5804  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5805  
5806 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5807 +
5808 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5809 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5810 +
5811  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5812  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5813  
5814 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/super.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/super.c
5815 --- linux-3.13.10/fs/ocfs2/super.c      2014-01-22 20:39:07.000000000 +0000
5816 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/super.c   2014-01-31 20:38:03.000000000 +0000
5817 @@ -185,6 +185,7 @@ enum {
5818         Opt_coherency_full,
5819         Opt_resv_level,
5820         Opt_dir_resv_level,
5821 +       Opt_tag, Opt_notag, Opt_tagid,
5822         Opt_err,
5823  };
5824  
5825 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5826         {Opt_coherency_full, "coherency=full"},
5827         {Opt_resv_level, "resv_level=%u"},
5828         {Opt_dir_resv_level, "dir_resv_level=%u"},
5829 +       {Opt_tag, "tag"},
5830 +       {Opt_notag, "notag"},
5831 +       {Opt_tagid, "tagid=%u"},
5832         {Opt_err, NULL}
5833  };
5834  
5835 @@ -661,6 +665,13 @@ static int ocfs2_remount(struct super_bl
5836                 goto out;
5837         }
5838  
5839 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5840 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5841 +               ret = -EINVAL;
5842 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5843 +               goto out;
5844 +       }
5845 +
5846         /* We're going to/from readonly mode. */
5847         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5848                 /* Disable quota accounting before remounting RO */
5849 @@ -1176,6 +1187,9 @@ static int ocfs2_fill_super(struct super
5850  
5851         ocfs2_complete_mount_recovery(osb);
5852  
5853 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5854 +               sb->s_flags |= MS_TAGGED;
5855 +
5856         if (ocfs2_mount_local(osb))
5857                 snprintf(nodestr, sizeof(nodestr), "local");
5858         else
5859 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
5860                             option < OCFS2_MAX_RESV_LEVEL)
5861                                 mopt->dir_resv_level = option;
5862                         break;
5863 +#ifndef CONFIG_TAGGING_NONE
5864 +               case Opt_tag:
5865 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5866 +                       break;
5867 +               case Opt_notag:
5868 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5869 +                       break;
5870 +#endif
5871 +#ifdef CONFIG_PROPAGATE
5872 +               case Opt_tagid:
5873 +                       /* use args[0] */
5874 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5875 +                       break;
5876 +#endif
5877                 default:
5878                         mlog(ML_ERROR,
5879                              "Unrecognized mount option \"%s\" "
5880 diff -NurpP --minimal linux-3.13.10/fs/open.c linux-3.13.10-vs2.3.6.11/fs/open.c
5881 --- linux-3.13.10/fs/open.c     2014-01-22 20:39:07.000000000 +0000
5882 +++ linux-3.13.10-vs2.3.6.11/fs/open.c  2014-01-31 20:38:03.000000000 +0000
5883 @@ -31,6 +31,11 @@
5884  #include <linux/ima.h>
5885  #include <linux/dnotify.h>
5886  #include <linux/compat.h>
5887 +#include <linux/vs_base.h>
5888 +#include <linux/vs_limit.h>
5889 +#include <linux/vs_tag.h>
5890 +#include <linux/vs_cowbl.h>
5891 +#include <linux/vserver/dlimit.h>
5892  
5893  #include "internal.h"
5894  
5895 @@ -68,6 +73,11 @@ long vfs_truncate(struct path *path, lof
5896         struct inode *inode;
5897         long error;
5898  
5899 +#ifdef CONFIG_VSERVER_COWBL
5900 +       error = cow_check_and_break(path);
5901 +       if (error)
5902 +               goto out;
5903 +#endif
5904         inode = path->dentry->d_inode;
5905  
5906         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5907 @@ -511,6 +521,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5908         unsigned int lookup_flags = LOOKUP_FOLLOW;
5909  retry:
5910         error = user_path_at(dfd, filename, lookup_flags, &path);
5911 +#ifdef CONFIG_VSERVER_COWBL
5912 +       if (!error) {
5913 +               error = cow_check_and_break(&path);
5914 +               if (error)
5915 +                       path_put(&path);
5916 +       }
5917 +#endif
5918         if (!error) {
5919                 error = chmod_common(&path, mode);
5920                 path_put(&path);
5921 @@ -544,13 +561,15 @@ static int chown_common(struct path *pat
5922                 if (!uid_valid(uid))
5923                         return -EINVAL;
5924                 newattrs.ia_valid |= ATTR_UID;
5925 -               newattrs.ia_uid = uid;
5926 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5927 +                       dx_map_uid(user));
5928         }
5929         if (group != (gid_t) -1) {
5930                 if (!gid_valid(gid))
5931                         return -EINVAL;
5932                 newattrs.ia_valid |= ATTR_GID;
5933 -               newattrs.ia_gid = gid;
5934 +               newattrs.ia_gid = make_kgid(&init_user_ns,
5935 +                       dx_map_gid(group));
5936         }
5937         if (!S_ISDIR(inode->i_mode))
5938                 newattrs.ia_valid |=
5939 @@ -589,6 +608,18 @@ retry:
5940         error = mnt_want_write(path.mnt);
5941         if (error)
5942                 goto out_release;
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 +#ifdef CONFIG_VSERVER_COWBL
5952 +       error = cow_check_and_break(&path);
5953 +       if (!error)
5954 +#endif
5955         error = chown_common(&path, user, group);
5956         mnt_drop_write(path.mnt);
5957  out_release:
5958 diff -NurpP --minimal linux-3.13.10/fs/proc/array.c linux-3.13.10-vs2.3.6.11/fs/proc/array.c
5959 --- linux-3.13.10/fs/proc/array.c       2014-01-22 20:39:07.000000000 +0000
5960 +++ linux-3.13.10-vs2.3.6.11/fs/proc/array.c    2014-02-01 01:44:54.000000000 +0000
5961 @@ -82,6 +82,8 @@
5962  #include <linux/ptrace.h>
5963  #include <linux/tracehook.h>
5964  #include <linux/user_namespace.h>
5965 +#include <linux/vs_context.h>
5966 +#include <linux/vs_network.h>
5967  
5968  #include <asm/pgtable.h>
5969  #include <asm/processor.h>
5970 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
5971         rcu_read_lock();
5972         ppid = pid_alive(p) ?
5973                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5974 +       if (unlikely(vx_current_initpid(p->pid)))
5975 +               ppid = 0;
5976 +
5977         tpid = 0;
5978         if (pid_alive(p)) {
5979                 struct task_struct *tracer = ptrace_parent(p);
5980 @@ -299,7 +304,7 @@ static inline void task_sig(struct seq_f
5981  }
5982  
5983  static void render_cap_t(struct seq_file *m, const char *header,
5984 -                       kernel_cap_t *a)
5985 +                       struct vx_info *vxi, kernel_cap_t *a)
5986  {
5987         unsigned __capi;
5988  
5989 @@ -333,10 +338,11 @@ static inline void task_cap(struct seq_f
5990         NORM_CAPS(cap_effective);
5991         NORM_CAPS(cap_bset);
5992  
5993 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
5994 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
5995 -       render_cap_t(m, "CapEff:\t", &cap_effective);
5996 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
5997 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5998 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5999 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6000 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6001 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6002  }
6003  
6004  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
6005 @@ -365,6 +371,43 @@ static void task_cpus_allowed(struct seq
6006         seq_putc(m, '\n');
6007  }
6008  
6009 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6010 +                       struct pid *pid, struct task_struct *task)
6011 +{
6012 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6013 +                       "Count:\t%u\n"
6014 +                       "uts:\t%p(%c)\n"
6015 +                       "ipc:\t%p(%c)\n"
6016 +                       "mnt:\t%p(%c)\n"
6017 +                       "pid:\t%p(%c)\n"
6018 +                       "net:\t%p(%c)\n",
6019 +                       task->nsproxy,
6020 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6021 +                       atomic_read(&task->nsproxy->count),
6022 +                       task->nsproxy->uts_ns,
6023 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6024 +                       task->nsproxy->ipc_ns,
6025 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6026 +                       task->nsproxy->mnt_ns,
6027 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6028 +                       task->nsproxy->pid_ns_for_children,
6029 +                       (task->nsproxy->pid_ns_for_children ==
6030 +                               init_task.nsproxy->pid_ns_for_children ? 'I' : '-'),
6031 +                       task->nsproxy->net_ns,
6032 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6033 +       return 0;
6034 +}
6035 +
6036 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6037 +{
6038 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6039 +               return;
6040 +
6041 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6042 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6043 +}
6044 +
6045 +
6046  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6047                         struct pid *pid, struct task_struct *task)
6048  {
6049 @@ -382,6 +425,7 @@ int proc_pid_status(struct seq_file *m,
6050         task_seccomp(m, task);
6051         task_cpus_allowed(m, task);
6052         cpuset_task_status_allowed(m, task);
6053 +       task_vs_id(m, task);
6054         task_context_switch_counts(m, task);
6055         return 0;
6056  }
6057 @@ -491,6 +535,17 @@ static int do_task_stat(struct seq_file
6058         /* convert nsec -> ticks */
6059         start_time = nsec_to_clock_t(start_time);
6060  
6061 +       /* fixup start time for virt uptime */
6062 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6063 +               unsigned long long bias =
6064 +                       current->vx_info->cvirt.bias_clock;
6065 +
6066 +               if (start_time > bias)
6067 +                       start_time -= bias;
6068 +               else
6069 +                       start_time = 0;
6070 +       }
6071 +
6072         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6073         seq_put_decimal_ll(m, ' ', ppid);
6074         seq_put_decimal_ll(m, ' ', pgid);
6075 diff -NurpP --minimal linux-3.13.10/fs/proc/base.c linux-3.13.10-vs2.3.6.11/fs/proc/base.c
6076 --- linux-3.13.10/fs/proc/base.c        2014-04-17 01:12:32.000000000 +0000
6077 +++ linux-3.13.10-vs2.3.6.11/fs/proc/base.c     2014-04-17 01:17:10.000000000 +0000
6078 @@ -87,6 +87,8 @@
6079  #include <linux/slab.h>
6080  #include <linux/flex_array.h>
6081  #include <linux/posix-timers.h>
6082 +#include <linux/vs_context.h>
6083 +#include <linux/vs_network.h>
6084  #ifdef CONFIG_HARDWALL
6085  #include <asm/hardwall.h>
6086  #endif
6087 @@ -976,11 +978,15 @@ static ssize_t oom_adj_write(struct file
6088                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6089  
6090         if (oom_adj < task->signal->oom_score_adj &&
6091 -           !capable(CAP_SYS_RESOURCE)) {
6092 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6093                 err = -EACCES;
6094                 goto err_sighand;
6095         }
6096  
6097 +       /* prevent guest processes from circumventing the oom killer */
6098 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6099 +               oom_adj = OOM_ADJUST_MIN;
6100 +
6101         /*
6102          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6103          * /proc/pid/oom_score_adj instead.
6104 @@ -1565,6 +1571,8 @@ struct inode *proc_pid_make_inode(struct
6105                 inode->i_gid = cred->egid;
6106                 rcu_read_unlock();
6107         }
6108 +       /* procfs is xid tagged */
6109 +       i_tag_write(inode, (vtag_t)vx_task_xid(task));
6110         security_task_to_inode(task, inode);
6111  
6112  out:
6113 @@ -1610,6 +1618,8 @@ int pid_getattr(struct vfsmount *mnt, st
6114  
6115  /* dentry stuff */
6116  
6117 +static unsigned name_to_int(struct dentry *dentry);
6118 +
6119  /*
6120   *     Exceptional case: normally we are not allowed to unhash a busy
6121   * directory. In this case, however, we can do it - no aliasing problems
6122 @@ -1638,6 +1648,12 @@ int pid_revalidate(struct dentry *dentry
6123         task = get_proc_task(inode);
6124  
6125         if (task) {
6126 +               unsigned pid = name_to_int(dentry);
6127 +
6128 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6129 +                       put_task_struct(task);
6130 +                       goto drop;
6131 +               }
6132                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6133                     task_dumpable(task)) {
6134                         rcu_read_lock();
6135 @@ -1654,6 +1670,7 @@ int pid_revalidate(struct dentry *dentry
6136                 put_task_struct(task);
6137                 return 1;
6138         }
6139 +drop:
6140         d_drop(dentry);
6141         return 0;
6142  }
6143 @@ -2173,6 +2190,13 @@ static struct dentry *proc_pident_lookup
6144         if (!task)
6145                 goto out_no_task;
6146  
6147 +       /* TODO: maybe we can come up with a generic approach? */
6148 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6149 +               (dentry->d_name.len == 5) &&
6150 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6151 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6152 +               goto out;
6153 +
6154         /*
6155          * Yes, it does not scale. And it should not. Don't add
6156          * new entries into /proc/<tgid>/ without very good reasons.
6157 @@ -2569,6 +2593,9 @@ static int proc_pid_personality(struct s
6158  static const struct file_operations proc_task_operations;
6159  static const struct inode_operations proc_task_inode_operations;
6160  
6161 +extern int proc_pid_vx_info(struct task_struct *, char *);
6162 +extern int proc_pid_nx_info(struct task_struct *, char *);
6163 +
6164  static const struct pid_entry tgid_base_stuff[] = {
6165         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6166         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6167 @@ -2635,6 +2662,8 @@ static const struct pid_entry tgid_base_
6168  #ifdef CONFIG_CGROUPS
6169         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6170  #endif
6171 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6172 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6173         INF("oom_score",  S_IRUGO, proc_oom_score),
6174         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6175         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6176 @@ -2847,7 +2876,7 @@ retry:
6177         iter.task = NULL;
6178         pid = find_ge_pid(iter.tgid, ns);
6179         if (pid) {
6180 -               iter.tgid = pid_nr_ns(pid, ns);
6181 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6182                 iter.task = pid_task(pid, PIDTYPE_PID);
6183                 /* What we to know is if the pid we have find is the
6184                  * pid of a thread_group_leader.  Testing for task
6185 @@ -2900,8 +2929,10 @@ int proc_pid_readdir(struct file *file,
6186                 if (!has_pid_permissions(ns, iter.task, 2))
6187                         continue;
6188  
6189 -               len = snprintf(name, sizeof(name), "%d", iter.tgid);
6190 +               len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6191                 ctx->pos = iter.tgid + TGID_OFFSET;
6192 +               if (!vx_proc_task_visible(iter.task))
6193 +                       continue;
6194                 if (!proc_fill_cache(file, ctx, name, len,
6195                                      proc_pid_instantiate, iter.task, NULL)) {
6196                         put_task_struct(iter.task);
6197 @@ -2994,6 +3025,7 @@ static const struct pid_entry tid_base_s
6198         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6199         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6200  #endif
6201 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6202  };
6203  
6204  static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
6205 @@ -3060,6 +3092,8 @@ static struct dentry *proc_task_lookup(s
6206         tid = name_to_int(dentry);
6207         if (tid == ~0U)
6208                 goto out;
6209 +       if (vx_current_initpid(tid))
6210 +               goto out;
6211  
6212         ns = dentry->d_sb->s_fs_info;
6213         rcu_read_lock();
6214 diff -NurpP --minimal linux-3.13.10/fs/proc/generic.c linux-3.13.10-vs2.3.6.11/fs/proc/generic.c
6215 --- linux-3.13.10/fs/proc/generic.c     2014-01-22 20:39:07.000000000 +0000
6216 +++ linux-3.13.10-vs2.3.6.11/fs/proc/generic.c  2014-02-01 00:07:40.000000000 +0000
6217 @@ -23,6 +23,7 @@
6218  #include <linux/bitops.h>
6219  #include <linux/spinlock.h>
6220  #include <linux/completion.h>
6221 +#include <linux/vserver/inode.h>
6222  #include <asm/uaccess.h>
6223  
6224  #include "internal.h"
6225 @@ -187,6 +188,8 @@ struct dentry *proc_lookup_de(struct pro
6226         for (de = de->subdir; de ; de = de->next) {
6227                 if (de->namelen != dentry->d_name.len)
6228                         continue;
6229 +               if (!vx_hide_check(0, de->vx_flags))
6230 +                       continue;
6231                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6232                         pde_get(de);
6233                         spin_unlock(&proc_subdir_lock);
6234 @@ -195,6 +198,8 @@ struct dentry *proc_lookup_de(struct pro
6235                                 return ERR_PTR(-ENOMEM);
6236                         d_set_d_op(dentry, &simple_dentry_operations);
6237                         d_add(dentry, inode);
6238 +                       /* generic proc entries belong to the host */
6239 +                       i_tag_write(inode, 0);
6240                         return NULL;
6241                 }
6242         }
6243 @@ -242,6 +247,9 @@ int proc_readdir_de(struct proc_dir_entr
6244         do {
6245                 struct proc_dir_entry *next;
6246                 pde_get(de);
6247 +
6248 +               if (!vx_hide_check(0, de->vx_flags))
6249 +                       goto skip;
6250                 spin_unlock(&proc_subdir_lock);
6251                 if (!dir_emit(ctx, de->name, de->namelen,
6252                             de->low_ino, de->mode >> 12)) {
6253 @@ -249,6 +257,7 @@ int proc_readdir_de(struct proc_dir_entr
6254                         return 0;
6255                 }
6256                 spin_lock(&proc_subdir_lock);
6257 +       skip:
6258                 ctx->pos++;
6259                 next = de->next;
6260                 pde_put(de);
6261 @@ -355,6 +364,7 @@ static struct proc_dir_entry *__proc_cre
6262         ent->namelen = len;
6263         ent->mode = mode;
6264         ent->nlink = nlink;
6265 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6266         atomic_set(&ent->count, 1);
6267         spin_lock_init(&ent->pde_unload_lock);
6268         INIT_LIST_HEAD(&ent->pde_openers);
6269 @@ -378,7 +388,8 @@ struct proc_dir_entry *proc_symlink(cons
6270                                 kfree(ent->data);
6271                                 kfree(ent);
6272                                 ent = NULL;
6273 -                       }
6274 +                       } else
6275 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6276                 } else {
6277                         kfree(ent);
6278                         ent = NULL;
6279 diff -NurpP --minimal linux-3.13.10/fs/proc/inode.c linux-3.13.10-vs2.3.6.11/fs/proc/inode.c
6280 --- linux-3.13.10/fs/proc/inode.c       2014-01-22 20:39:07.000000000 +0000
6281 +++ linux-3.13.10-vs2.3.6.11/fs/proc/inode.c    2014-01-31 20:38:03.000000000 +0000
6282 @@ -415,6 +415,8 @@ struct inode *proc_get_inode(struct supe
6283                         inode->i_uid = de->uid;
6284                         inode->i_gid = de->gid;
6285                 }
6286 +               if (de->vx_flags)
6287 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6288                 if (de->size)
6289                         inode->i_size = de->size;
6290                 if (de->nlink)
6291 diff -NurpP --minimal linux-3.13.10/fs/proc/internal.h linux-3.13.10-vs2.3.6.11/fs/proc/internal.h
6292 --- linux-3.13.10/fs/proc/internal.h    2013-11-25 15:45:04.000000000 +0000
6293 +++ linux-3.13.10-vs2.3.6.11/fs/proc/internal.h 2014-01-31 20:38:03.000000000 +0000
6294 @@ -14,6 +14,7 @@
6295  #include <linux/spinlock.h>
6296  #include <linux/atomic.h>
6297  #include <linux/binfmts.h>
6298 +#include <linux/vs_pid.h>
6299  
6300  struct ctl_table_header;
6301  struct mempolicy;
6302 @@ -35,6 +36,7 @@ struct proc_dir_entry {
6303         nlink_t nlink;
6304         kuid_t uid;
6305         kgid_t gid;
6306 +       int vx_flags;
6307         loff_t size;
6308         const struct inode_operations *proc_iops;
6309         const struct file_operations *proc_fops;
6310 @@ -50,16 +52,23 @@ struct proc_dir_entry {
6311         char name[];
6312  };
6313  
6314 +struct vx_info;
6315 +struct nx_info;
6316 +
6317  union proc_op {
6318         int (*proc_get_link)(struct dentry *, struct path *);
6319         int (*proc_read)(struct task_struct *task, char *page);
6320         int (*proc_show)(struct seq_file *m,
6321                 struct pid_namespace *ns, struct pid *pid,
6322                 struct task_struct *task);
6323 +       int (*proc_vs_read)(char *page);
6324 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
6325 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
6326  };
6327  
6328  struct proc_inode {
6329         struct pid *pid;
6330 +       int vx_flags;
6331         int fd;
6332         union proc_op op;
6333         struct proc_dir_entry *pde;
6334 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
6335         return PROC_I(inode)->pid;
6336  }
6337  
6338 -static inline struct task_struct *get_proc_task(struct inode *inode)
6339 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6340  {
6341         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6342  }
6343  
6344 +static inline struct task_struct *get_proc_task(struct inode *inode)
6345 +{
6346 +       return vx_get_proc_task(inode, proc_pid(inode));
6347 +}
6348 +
6349  static inline int task_dumpable(struct task_struct *task)
6350  {
6351         int dumpable = 0;
6352 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6353                            struct pid *, struct task_struct *);
6354  extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6355                           struct pid *, struct task_struct *);
6356 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6357 +                           struct pid *pid, struct task_struct *task);
6358  
6359  /*
6360   * base.c
6361 diff -NurpP --minimal linux-3.13.10/fs/proc/loadavg.c linux-3.13.10-vs2.3.6.11/fs/proc/loadavg.c
6362 --- linux-3.13.10/fs/proc/loadavg.c     2012-12-11 03:30:57.000000000 +0000
6363 +++ linux-3.13.10-vs2.3.6.11/fs/proc/loadavg.c  2014-01-31 20:38:03.000000000 +0000
6364 @@ -12,15 +12,27 @@
6365  
6366  static int loadavg_proc_show(struct seq_file *m, void *v)
6367  {
6368 +       unsigned long running;
6369 +       unsigned int threads;
6370         unsigned long avnrun[3];
6371  
6372         get_avenrun(avnrun, FIXED_1/200, 0);
6373  
6374 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6375 +               struct vx_info *vxi = current_vx_info();
6376 +
6377 +               running = atomic_read(&vxi->cvirt.nr_running);
6378 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6379 +       } else {
6380 +               running = nr_running();
6381 +               threads = nr_threads;
6382 +       }
6383 +
6384         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6385                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6386                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6387                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6388 -               nr_running(), nr_threads,
6389 +               running, threads,
6390                 task_active_pid_ns(current)->last_pid);
6391         return 0;
6392  }
6393 diff -NurpP --minimal linux-3.13.10/fs/proc/meminfo.c linux-3.13.10-vs2.3.6.11/fs/proc/meminfo.c
6394 --- linux-3.13.10/fs/proc/meminfo.c     2014-01-22 20:39:07.000000000 +0000
6395 +++ linux-3.13.10-vs2.3.6.11/fs/proc/meminfo.c  2014-01-31 20:38:03.000000000 +0000
6396 @@ -37,7 +37,8 @@ static int meminfo_proc_show(struct seq_
6397         si_swapinfo(&i);
6398         committed = percpu_counter_read_positive(&vm_committed_as);
6399  
6400 -       cached = global_page_state(NR_FILE_PAGES) -
6401 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6402 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6403                         total_swapcache_pages() - i.bufferram;
6404         if (cached < 0)
6405                 cached = 0;
6406 diff -NurpP --minimal linux-3.13.10/fs/proc/root.c linux-3.13.10-vs2.3.6.11/fs/proc/root.c
6407 --- linux-3.13.10/fs/proc/root.c        2013-11-25 15:47:00.000000000 +0000
6408 +++ linux-3.13.10-vs2.3.6.11/fs/proc/root.c     2014-02-01 00:02:11.000000000 +0000
6409 @@ -20,9 +20,14 @@
6410  #include <linux/mount.h>
6411  #include <linux/pid_namespace.h>
6412  #include <linux/parser.h>
6413 +#include <linux/vserver/inode.h>
6414  
6415  #include "internal.h"
6416  
6417 +struct proc_dir_entry *proc_virtual;
6418 +
6419 +extern void proc_vx_init(void);
6420 +
6421  static int proc_test_super(struct super_block *sb, void *data)
6422  {
6423         return sb->s_fs_info == data;
6424 @@ -114,7 +119,8 @@ static struct dentry *proc_mount(struct
6425                         return ERR_PTR(-EPERM);
6426  
6427                 /* Does the mounter have privilege over the pid namespace? */
6428 -               if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
6429 +               if (!vx_ns_capable(ns->user_ns,
6430 +                       CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6431                         return ERR_PTR(-EPERM);
6432         }
6433  
6434 @@ -188,6 +194,7 @@ void __init proc_root_init(void)
6435  #endif
6436         proc_mkdir("bus", NULL);
6437         proc_sys_init();
6438 +       proc_vx_init();
6439  }
6440  
6441  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6442 @@ -249,6 +256,7 @@ struct proc_dir_entry proc_root = {
6443         .proc_iops      = &proc_root_inode_operations, 
6444         .proc_fops      = &proc_root_operations,
6445         .parent         = &proc_root,
6446 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6447         .name           = "/proc",
6448  };
6449  
6450 diff -NurpP --minimal linux-3.13.10/fs/proc/self.c linux-3.13.10-vs2.3.6.11/fs/proc/self.c
6451 --- linux-3.13.10/fs/proc/self.c        2014-01-22 20:39:07.000000000 +0000
6452 +++ linux-3.13.10-vs2.3.6.11/fs/proc/self.c     2014-01-31 20:38:03.000000000 +0000
6453 @@ -2,6 +2,7 @@
6454  #include <linux/namei.h>
6455  #include <linux/slab.h>
6456  #include <linux/pid_namespace.h>
6457 +#include <linux/vserver/inode.h>
6458  #include "internal.h"
6459  
6460  /*
6461 @@ -54,6 +55,8 @@ int proc_setup_self(struct super_block *
6462         self = d_alloc_name(s->s_root, "self");
6463         if (self) {
6464                 struct inode *inode = new_inode_pseudo(s);
6465 +
6466 +               // self->vx_flags = IATTR_PROC_SYMLINK;
6467                 if (inode) {
6468                         inode->i_ino = self_inum;
6469                         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6470 diff -NurpP --minimal linux-3.13.10/fs/proc/stat.c linux-3.13.10-vs2.3.6.11/fs/proc/stat.c
6471 --- linux-3.13.10/fs/proc/stat.c        2013-07-14 17:01:29.000000000 +0000
6472 +++ linux-3.13.10-vs2.3.6.11/fs/proc/stat.c     2014-01-31 20:38:03.000000000 +0000
6473 @@ -9,8 +9,10 @@
6474  #include <linux/slab.h>
6475  #include <linux/time.h>
6476  #include <linux/irqnr.h>
6477 +#include <linux/vserver/cvirt.h>
6478  #include <asm/cputime.h>
6479  #include <linux/tick.h>
6480 +#include <linux/cpuset.h>
6481  
6482  #ifndef arch_irq_stat_cpu
6483  #define arch_irq_stat_cpu(cpu) 0
6484 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6485         u64 sum_softirq = 0;
6486         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6487         struct timespec boottime;
6488 +       cpumask_var_t cpus_allowed;
6489 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6490  
6491         user = nice = system = idle = iowait =
6492                 irq = softirq = steal = 0;
6493         guest = guest_nice = 0;
6494         getboottime(&boottime);
6495 +
6496 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6497 +               vx_vsi_boottime(&boottime);
6498 +
6499 +       if (virt_cpu)
6500 +               cpuset_cpus_allowed(current, cpus_allowed);
6501 +
6502         jif = boottime.tv_sec;
6503  
6504         for_each_possible_cpu(i) {
6505 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6506 +                       continue;
6507 +
6508                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6509                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6510                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6511 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6512         seq_putc(p, '\n');
6513  
6514         for_each_online_cpu(i) {
6515 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6516 +                       continue;
6517 +
6518                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6519                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6520                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6521 diff -NurpP --minimal linux-3.13.10/fs/proc/uptime.c linux-3.13.10-vs2.3.6.11/fs/proc/uptime.c
6522 --- linux-3.13.10/fs/proc/uptime.c      2013-11-25 15:45:04.000000000 +0000
6523 +++ linux-3.13.10-vs2.3.6.11/fs/proc/uptime.c   2014-01-31 20:38:03.000000000 +0000
6524 @@ -5,6 +5,7 @@
6525  #include <linux/seq_file.h>
6526  #include <linux/time.h>
6527  #include <linux/kernel_stat.h>
6528 +#include <linux/vserver/cvirt.h>
6529  #include <asm/cputime.h>
6530  
6531  static int uptime_proc_show(struct seq_file *m, void *v)
6532 @@ -24,6 +25,10 @@ static int uptime_proc_show(struct seq_f
6533         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6534         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6535         idle.tv_nsec = rem;
6536 +
6537 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6538 +               vx_vsi_uptime(&uptime, &idle);
6539 +
6540         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6541                         (unsigned long) uptime.tv_sec,
6542                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6543 diff -NurpP --minimal linux-3.13.10/fs/proc_namespace.c linux-3.13.10-vs2.3.6.11/fs/proc_namespace.c
6544 --- linux-3.13.10/fs/proc_namespace.c   2014-01-22 20:39:07.000000000 +0000
6545 +++ linux-3.13.10-vs2.3.6.11/fs/proc_namespace.c        2014-02-25 12:43:16.000000000 +0000
6546 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6547                 { MS_SYNCHRONOUS, ",sync" },
6548                 { MS_DIRSYNC, ",dirsync" },
6549                 { MS_MANDLOCK, ",mand" },
6550 +               { MS_TAGGED, ",tag" },
6551 +               { MS_NOTAGCHECK, ",notagcheck" },
6552                 { 0, NULL }
6553         };
6554         const struct proc_fs_info *fs_infop;
6555 @@ -80,6 +82,38 @@ static inline void mangle(struct seq_fil
6556         seq_escape(m, s, " \t\n\\");
6557  }
6558  
6559 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6560 +
6561 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6562 +{
6563 +       struct path root;
6564 +       struct dentry *point;
6565 +       struct mount *mnt = real_mount(vfsmnt);
6566 +       struct mount *root_mnt;
6567 +       int ret;
6568 +
6569 +       if (mnt == mnt->mnt_ns->root)
6570 +               return 1;
6571 +
6572 +       rcu_read_lock();
6573 +       root = current->fs->root;
6574 +       root_mnt = real_mount(root.mnt);
6575 +       point = root.dentry;
6576 +
6577 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6578 +               point = mnt->mnt_mountpoint;
6579 +               mnt = mnt->mnt_parent;
6580 +       }
6581 +       rcu_read_unlock();
6582 +
6583 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6584 +       return ret;
6585 +}
6586 +
6587 +#else
6588 +#define        mnt_is_reachable(v)     (1)
6589 +#endif
6590 +
6591  static void show_type(struct seq_file *m, struct super_block *sb)
6592  {
6593         mangle(m, sb->s_type->name);
6594 @@ -96,6 +130,17 @@ static int show_vfsmnt(struct seq_file *
6595         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6596         struct super_block *sb = mnt_path.dentry->d_sb;
6597  
6598 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6599 +               return SEQ_SKIP;
6600 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6601 +               return SEQ_SKIP;
6602 +
6603 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6604 +               mnt == current->fs->root.mnt) {
6605 +               seq_puts(m, "/dev/root / ");
6606 +               goto type;
6607 +       }
6608 +
6609         if (sb->s_op->show_devname) {
6610                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6611                 if (err)
6612 @@ -106,6 +151,7 @@ static int show_vfsmnt(struct seq_file *
6613         seq_putc(m, ' ');
6614         seq_path(m, &mnt_path, " \t\n\\");
6615         seq_putc(m, ' ');
6616 +type:
6617         show_type(m, sb);
6618         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6619         err = show_sb_opts(m, sb);
6620 @@ -128,6 +174,11 @@ static int show_mountinfo(struct seq_fil
6621         struct path root = p->root;
6622         int err = 0;
6623  
6624 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6625 +               return SEQ_SKIP;
6626 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6627 +               return SEQ_SKIP;
6628 +
6629         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6630                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6631         if (sb->s_op->show_path)
6632 @@ -187,6 +238,17 @@ static int show_vfsstat(struct seq_file
6633         struct super_block *sb = mnt_path.dentry->d_sb;
6634         int err = 0;
6635  
6636 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6637 +               return SEQ_SKIP;
6638 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6639 +               return SEQ_SKIP;
6640 +
6641 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6642 +               mnt == current->fs->root.mnt) {
6643 +               seq_puts(m, "device /dev/root mounted on / ");
6644 +               goto type;
6645 +       }
6646 +
6647         /* device */
6648         if (sb->s_op->show_devname) {
6649                 seq_puts(m, "device ");
6650 @@ -203,7 +265,7 @@ static int show_vfsstat(struct seq_file
6651         seq_puts(m, " mounted on ");
6652         seq_path(m, &mnt_path, " \t\n\\");
6653         seq_putc(m, ' ');
6654 -
6655 +type:
6656         /* file system type */
6657         seq_puts(m, "with fstype ");
6658         show_type(m, sb);
6659 diff -NurpP --minimal linux-3.13.10/fs/quota/dquot.c linux-3.13.10-vs2.3.6.11/fs/quota/dquot.c
6660 --- linux-3.13.10/fs/quota/dquot.c      2014-04-17 01:12:34.000000000 +0000
6661 +++ linux-3.13.10-vs2.3.6.11/fs/quota/dquot.c   2014-03-12 15:51:07.000000000 +0000
6662 @@ -1602,6 +1602,9 @@ int __dquot_alloc_space(struct inode *in
6663         struct dquot **dquots = inode->i_dquot;
6664         int reserve = flags & DQUOT_SPACE_RESERVE;
6665  
6666 +       if ((ret = dl_alloc_space(inode, number)))
6667 +               return ret;
6668 +
6669         /*
6670          * First test before acquiring mutex - solves deadlocks when we
6671          * re-enter the quota code and are already holding the mutex
6672 @@ -1657,6 +1660,9 @@ int dquot_alloc_inode(const struct inode
6673         struct dquot_warn warn[MAXQUOTAS];
6674         struct dquot * const *dquots = inode->i_dquot;
6675  
6676 +       if ((ret = dl_alloc_inode(inode)))
6677 +               return ret;
6678 +
6679         /* First test before acquiring mutex - solves deadlocks when we
6680           * re-enter the quota code and are already holding the mutex */
6681         if (!dquot_active(inode))
6682 @@ -1757,6 +1763,8 @@ void __dquot_free_space(struct inode *in
6683         struct dquot **dquots = inode->i_dquot;
6684         int reserve = flags & DQUOT_SPACE_RESERVE;
6685  
6686 +       dl_free_space(inode, number);
6687 +
6688         /* First test before acquiring mutex - solves deadlocks when we
6689           * re-enter the quota code and are already holding the mutex */
6690         if (!dquot_active(inode)) {
6691 @@ -1801,6 +1809,8 @@ void dquot_free_inode(const struct inode
6692         struct dquot_warn warn[MAXQUOTAS];
6693         struct dquot * const *dquots = inode->i_dquot;
6694  
6695 +       dl_free_inode(inode);
6696 +
6697         /* First test before acquiring mutex - solves deadlocks when we
6698           * re-enter the quota code and are already holding the mutex */
6699         if (!dquot_active(inode))
6700 diff -NurpP --minimal linux-3.13.10/fs/quota/quota.c linux-3.13.10-vs2.3.6.11/fs/quota/quota.c
6701 --- linux-3.13.10/fs/quota/quota.c      2014-01-22 20:39:07.000000000 +0000
6702 +++ linux-3.13.10-vs2.3.6.11/fs/quota/quota.c   2014-01-31 20:38:03.000000000 +0000
6703 @@ -8,6 +8,7 @@
6704  #include <linux/fs.h>
6705  #include <linux/namei.h>
6706  #include <linux/slab.h>
6707 +#include <linux/vs_context.h>
6708  #include <asm/current.h>
6709  #include <linux/uaccess.h>
6710  #include <linux/kernel.h>
6711 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6712                         break;
6713                 /*FALLTHROUGH*/
6714         default:
6715 -               if (!capable(CAP_SYS_ADMIN))
6716 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6717                         return -EPERM;
6718         }
6719  
6720 @@ -338,6 +339,46 @@ static int do_quotactl(struct super_bloc
6721  
6722  #ifdef CONFIG_BLOCK
6723  
6724 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6725 +
6726 +#include <linux/vroot.h>
6727 +#include <linux/major.h>
6728 +#include <linux/module.h>
6729 +#include <linux/kallsyms.h>
6730 +#include <linux/vserver/debug.h>
6731 +
6732 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6733 +
6734 +static DEFINE_SPINLOCK(vroot_grb_lock);
6735 +
6736 +int register_vroot_grb(vroot_grb_func *func) {
6737 +       int ret = -EBUSY;
6738 +
6739 +       spin_lock(&vroot_grb_lock);
6740 +       if (!vroot_get_real_bdev) {
6741 +               vroot_get_real_bdev = func;
6742 +               ret = 0;
6743 +       }
6744 +       spin_unlock(&vroot_grb_lock);
6745 +       return ret;
6746 +}
6747 +EXPORT_SYMBOL(register_vroot_grb);
6748 +
6749 +int unregister_vroot_grb(vroot_grb_func *func) {
6750 +       int ret = -EINVAL;
6751 +
6752 +       spin_lock(&vroot_grb_lock);
6753 +       if (vroot_get_real_bdev) {
6754 +               vroot_get_real_bdev = NULL;
6755 +               ret = 0;
6756 +       }
6757 +       spin_unlock(&vroot_grb_lock);
6758 +       return ret;
6759 +}
6760 +EXPORT_SYMBOL(unregister_vroot_grb);
6761 +
6762 +#endif
6763 +
6764  /* Return 1 if 'cmd' will block on frozen filesystem */
6765  static int quotactl_cmd_write(int cmd)
6766  {
6767 @@ -373,6 +414,22 @@ static struct super_block *quotactl_bloc
6768         putname(tmp);
6769         if (IS_ERR(bdev))
6770                 return ERR_CAST(bdev);
6771 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6772 +       if (bdev && bdev->bd_inode &&
6773 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6774 +               struct block_device *bdnew = (void *)-EINVAL;
6775 +
6776 +               if (vroot_get_real_bdev)
6777 +                       bdnew = vroot_get_real_bdev(bdev);
6778 +               else
6779 +                       vxdprintk(VXD_CBIT(misc, 0),
6780 +                                       "vroot_get_real_bdev not set");
6781 +               bdput(bdev);
6782 +               if (IS_ERR(bdnew))
6783 +                       return ERR_PTR(PTR_ERR(bdnew));
6784 +               bdev = bdnew;
6785 +       }
6786 +#endif
6787         if (quotactl_cmd_write(cmd))
6788                 sb = get_super_thawed(bdev);
6789         else
6790 diff -NurpP --minimal linux-3.13.10/fs/stat.c linux-3.13.10-vs2.3.6.11/fs/stat.c
6791 --- linux-3.13.10/fs/stat.c     2014-01-22 20:39:07.000000000 +0000
6792 +++ linux-3.13.10-vs2.3.6.11/fs/stat.c  2014-01-31 20:38:03.000000000 +0000
6793 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6794         stat->nlink = inode->i_nlink;
6795         stat->uid = inode->i_uid;
6796         stat->gid = inode->i_gid;
6797 +       stat->tag = inode->i_tag;
6798         stat->rdev = inode->i_rdev;
6799         stat->size = i_size_read(inode);
6800         stat->atime = inode->i_atime;
6801 diff -NurpP --minimal linux-3.13.10/fs/statfs.c linux-3.13.10-vs2.3.6.11/fs/statfs.c
6802 --- linux-3.13.10/fs/statfs.c   2013-11-25 15:47:00.000000000 +0000
6803 +++ linux-3.13.10-vs2.3.6.11/fs/statfs.c        2014-01-31 20:38:03.000000000 +0000
6804 @@ -7,6 +7,8 @@
6805  #include <linux/statfs.h>
6806  #include <linux/security.h>
6807  #include <linux/uaccess.h>
6808 +#include <linux/vs_base.h>
6809 +#include <linux/vs_dlimit.h>
6810  #include "internal.h"
6811  
6812  static int flags_by_mnt(int mnt_flags)
6813 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6814         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6815         if (retval == 0 && buf->f_frsize == 0)
6816                 buf->f_frsize = buf->f_bsize;
6817 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6818 +               vx_vsi_statfs(dentry->d_sb, buf);
6819         return retval;
6820  }
6821  
6822 diff -NurpP --minimal linux-3.13.10/fs/super.c linux-3.13.10-vs2.3.6.11/fs/super.c
6823 --- linux-3.13.10/fs/super.c    2014-01-22 20:39:07.000000000 +0000
6824 +++ linux-3.13.10-vs2.3.6.11/fs/super.c 2014-01-31 20:38:03.000000000 +0000
6825 @@ -34,6 +34,8 @@
6826  #include <linux/cleancache.h>
6827  #include <linux/fsnotify.h>
6828  #include <linux/lockdep.h>
6829 +#include <linux/magic.h>
6830 +#include <linux/vs_context.h>
6831  #include "internal.h"
6832  
6833  
6834 @@ -1098,6 +1100,13 @@ mount_fs(struct file_system_type *type,
6835         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6836         sb->s_flags |= MS_BORN;
6837  
6838 +       error = -EPERM;
6839 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6840 +               !sb->s_bdev &&
6841 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6842 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6843 +               goto out_sb;
6844 +
6845         error = security_sb_kern_mount(sb, flags, secdata);
6846         if (error)
6847                 goto out_sb;
6848 diff -NurpP --minimal linux-3.13.10/fs/sysfs/mount.c linux-3.13.10-vs2.3.6.11/fs/sysfs/mount.c
6849 --- linux-3.13.10/fs/sysfs/mount.c      2013-11-25 15:47:00.000000000 +0000
6850 +++ linux-3.13.10-vs2.3.6.11/fs/sysfs/mount.c   2014-01-31 20:38:03.000000000 +0000
6851 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6852  
6853         sb->s_blocksize = PAGE_CACHE_SIZE;
6854         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6855 -       sb->s_magic = SYSFS_MAGIC;
6856 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6857         sb->s_op = &sysfs_ops;
6858         sb->s_time_gran = 1;
6859  
6860 diff -NurpP --minimal linux-3.13.10/fs/utimes.c linux-3.13.10-vs2.3.6.11/fs/utimes.c
6861 --- linux-3.13.10/fs/utimes.c   2014-01-22 20:39:07.000000000 +0000
6862 +++ linux-3.13.10-vs2.3.6.11/fs/utimes.c        2014-01-31 23:49:14.000000000 +0000
6863 @@ -8,6 +8,8 @@
6864  #include <linux/stat.h>
6865  #include <linux/utime.h>
6866  #include <linux/syscalls.h>
6867 +#include <linux/mount.h>
6868 +#include <linux/vs_cowbl.h>
6869  #include <asm/uaccess.h>
6870  #include <asm/unistd.h>
6871  
6872 @@ -52,13 +54,19 @@ static int utimes_common(struct path *pa
6873  {
6874         int error;
6875         struct iattr newattrs;
6876 -       struct inode *inode = path->dentry->d_inode;
6877         struct inode *delegated_inode = NULL;
6878 +       struct inode *inode;
6879 +
6880 +       error = cow_check_and_break(path);
6881 +       if (error)
6882 +               goto out;
6883  
6884         error = mnt_want_write(path->mnt);
6885         if (error)
6886                 goto out;
6887  
6888 +       inode = path->dentry->d_inode;
6889 +
6890         if (times && times[0].tv_nsec == UTIME_NOW &&
6891                      times[1].tv_nsec == UTIME_NOW)
6892                 times = NULL;
6893 diff -NurpP --minimal linux-3.13.10/fs/xattr.c linux-3.13.10-vs2.3.6.11/fs/xattr.c
6894 --- linux-3.13.10/fs/xattr.c    2013-02-19 13:58:49.000000000 +0000
6895 +++ linux-3.13.10-vs2.3.6.11/fs/xattr.c 2014-01-31 20:38:03.000000000 +0000
6896 @@ -21,6 +21,7 @@
6897  #include <linux/audit.h>
6898  #include <linux/vmalloc.h>
6899  #include <linux/posix_acl_xattr.h>
6900 +#include <linux/mount.h>
6901  
6902  #include <asm/uaccess.h>
6903  
6904 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6905          * The trusted.* namespace can only be accessed by privileged users.
6906          */
6907         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6908 -               if (!capable(CAP_SYS_ADMIN))
6909 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6910                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6911                 return 0;
6912         }
6913 diff -NurpP --minimal linux-3.13.10/include/linux/cred.h linux-3.13.10-vs2.3.6.11/include/linux/cred.h
6914 --- linux-3.13.10/include/linux/cred.h  2013-02-19 13:58:50.000000000 +0000
6915 +++ linux-3.13.10-vs2.3.6.11/include/linux/cred.h       2014-01-31 20:38:03.000000000 +0000
6916 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
6917  extern int copy_creds(struct task_struct *, unsigned long);
6918  extern const struct cred *get_task_cred(struct task_struct *);
6919  extern struct cred *cred_alloc_blank(void);
6920 +extern struct cred *__prepare_creds(const struct cred *);
6921  extern struct cred *prepare_creds(void);
6922  extern struct cred *prepare_exec_creds(void);
6923  extern int commit_creds(struct cred *);
6924 @@ -196,6 +197,31 @@ static inline void validate_process_cred
6925  }
6926  #endif
6927  
6928 +static inline void set_cred_subscribers(struct cred *cred, int n)
6929 +{
6930 +#ifdef CONFIG_DEBUG_CREDENTIALS
6931 +       atomic_set(&cred->subscribers, n);
6932 +#endif
6933 +}
6934 +
6935 +static inline int read_cred_subscribers(const struct cred *cred)
6936 +{
6937 +#ifdef CONFIG_DEBUG_CREDENTIALS
6938 +       return atomic_read(&cred->subscribers);
6939 +#else
6940 +       return 0;
6941 +#endif
6942 +}
6943 +
6944 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
6945 +{
6946 +#ifdef CONFIG_DEBUG_CREDENTIALS
6947 +       struct cred *cred = (struct cred *) _cred;
6948 +
6949 +       atomic_add(n, &cred->subscribers);
6950 +#endif
6951 +}
6952 +
6953  /**
6954   * get_new_cred - Get a reference on a new set of credentials
6955   * @cred: The new credentials to reference
6956 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
6957 --- linux-3.13.10/include/linux/devpts_fs.h     2013-02-19 13:58:50.000000000 +0000
6958 +++ linux-3.13.10-vs2.3.6.11/include/linux/devpts_fs.h  2014-01-31 20:38:03.000000000 +0000
6959 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
6960  
6961  #endif
6962  
6963 -
6964  #endif /* _LINUX_DEVPTS_FS_H */
6965 diff -NurpP --minimal linux-3.13.10/include/linux/fs.h linux-3.13.10-vs2.3.6.11/include/linux/fs.h
6966 --- linux-3.13.10/include/linux/fs.h    2014-01-22 20:39:10.000000000 +0000
6967 +++ linux-3.13.10-vs2.3.6.11/include/linux/fs.h 2014-01-31 23:33:22.000000000 +0000
6968 @@ -213,6 +213,7 @@ typedef void (dio_iodone_t)(struct kiocb
6969  #define ATTR_KILL_PRIV (1 << 14)
6970  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
6971  #define ATTR_TIMES_SET (1 << 16)
6972 +#define ATTR_TAG       (1 << 17)
6973  
6974  /*
6975   * This is the Inode Attributes structure, used for notify_change().  It
6976 @@ -228,6 +229,7 @@ struct iattr {
6977         umode_t         ia_mode;
6978         kuid_t          ia_uid;
6979         kgid_t          ia_gid;
6980 +       ktag_t          ia_tag;
6981         loff_t          ia_size;
6982         struct timespec ia_atime;
6983         struct timespec ia_mtime;
6984 @@ -526,7 +528,9 @@ struct inode {
6985         unsigned short          i_opflags;
6986         kuid_t                  i_uid;
6987         kgid_t                  i_gid;
6988 -       unsigned int            i_flags;
6989 +       ktag_t                  i_tag;
6990 +       unsigned short          i_flags;
6991 +       unsigned short          i_vflags;
6992  
6993  #ifdef CONFIG_FS_POSIX_ACL
6994         struct posix_acl        *i_acl;
6995 @@ -555,6 +559,7 @@ struct inode {
6996                 unsigned int __i_nlink;
6997         };
6998         dev_t                   i_rdev;
6999 +       dev_t                   i_mdev;
7000         loff_t                  i_size;
7001         struct timespec         i_atime;
7002         struct timespec         i_mtime;
7003 @@ -713,6 +718,11 @@ static inline gid_t i_gid_read(const str
7004         return from_kgid(&init_user_ns, inode->i_gid);
7005  }
7006  
7007 +static inline vtag_t i_tag_read(const struct inode *inode)
7008 +{
7009 +       return from_ktag(&init_user_ns, inode->i_tag);
7010 +}
7011 +
7012  static inline void i_uid_write(struct inode *inode, uid_t uid)
7013  {
7014         inode->i_uid = make_kuid(&init_user_ns, uid);
7015 @@ -723,14 +733,19 @@ static inline void i_gid_write(struct in
7016         inode->i_gid = make_kgid(&init_user_ns, gid);
7017  }
7018  
7019 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
7020 +{
7021 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7022 +}
7023 +
7024  static inline unsigned iminor(const struct inode *inode)
7025  {
7026 -       return MINOR(inode->i_rdev);
7027 +       return MINOR(inode->i_mdev);
7028  }
7029  
7030  static inline unsigned imajor(const struct inode *inode)
7031  {
7032 -       return MAJOR(inode->i_rdev);
7033 +       return MAJOR(inode->i_mdev);
7034  }
7035  
7036  extern struct block_device *I_BDEV(struct inode *inode);
7037 @@ -790,6 +805,7 @@ struct file {
7038         loff_t                  f_pos;
7039         struct fown_struct      f_owner;
7040         const struct cred       *f_cred;
7041 +       vxid_t                  f_xid;
7042         struct file_ra_state    f_ra;
7043  
7044         u64                     f_version;
7045 @@ -962,6 +978,7 @@ struct file_lock {
7046         struct file *fl_file;
7047         loff_t fl_start;
7048         loff_t fl_end;
7049 +       vxid_t fl_xid;
7050  
7051         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7052         /* for lease breaks: */
7053 @@ -1573,6 +1590,7 @@ struct inode_operations {
7054         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7055         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7056         int (*removexattr) (struct dentry *, const char *);
7057 +       int (*sync_flags) (struct inode *, int, int);
7058         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7059                       u64 len);
7060         int (*update_time)(struct inode *, struct timespec *, int);
7061 @@ -1586,6 +1604,7 @@ ssize_t rw_copy_check_uvector(int type,
7062                               unsigned long nr_segs, unsigned long fast_segs,
7063                               struct iovec *fast_pointer,
7064                               struct iovec **ret_pointer);
7065 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7066  
7067  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7068  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7069 @@ -1639,6 +1658,14 @@ struct super_operations {
7070  #define S_IMA          1024    /* Inode has an associated IMA struct */
7071  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7072  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7073 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7074 +
7075 +/* Linux-VServer related Inode flags */
7076 +
7077 +#define V_VALID                1
7078 +#define V_XATTR                2
7079 +#define V_BARRIER      4       /* Barrier for chroot() */
7080 +#define V_COW          8       /* Copy on Write */
7081  
7082  /*
7083   * Note that nosuid etc flags are inode-specific: setting some file-system
7084 @@ -1663,10 +1690,13 @@ struct super_operations {
7085  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7086  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7087  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7088 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7089  
7090  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7091  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7092  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7093 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7094 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7095  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7096  
7097  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7098 @@ -1677,6 +1707,16 @@ struct super_operations {
7099  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7100  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7101  
7102 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7103 +
7104 +#ifdef CONFIG_VSERVER_COWBL
7105 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7106 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7107 +#else
7108 +#  define IS_COW(inode)                (0)
7109 +#  define IS_COW_LINK(inode)   (0)
7110 +#endif
7111 +
7112  /*
7113   * Inode state bits.  Protected by inode->i_lock
7114   *
7115 @@ -1920,6 +1960,9 @@ extern struct kobject *fs_kobj;
7116  extern int locks_mandatory_locked(struct inode *);
7117  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7118  
7119 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7120 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7121 +
7122  /*
7123   * Candidates for mandatory locking have the setgid bit set
7124   * but no group execute bit -  an otherwise meaningless combination.
7125 @@ -2605,6 +2648,7 @@ extern int dcache_dir_open(struct inode
7126  extern int dcache_dir_close(struct inode *, struct file *);
7127  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7128  extern int dcache_readdir(struct file *, struct dir_context *);
7129 +extern int dcache_readdir_filter(struct file *, struct dir_context *, int (*)(struct dentry *));
7130  extern int simple_setattr(struct dentry *, struct iattr *);
7131  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7132  extern int simple_statfs(struct dentry *, struct kstatfs *);
7133 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
7134 --- linux-3.13.10/include/linux/init_task.h     2014-01-22 20:39:11.000000000 +0000
7135 +++ linux-3.13.10-vs2.3.6.11/include/linux/init_task.h  2014-01-31 20:38:03.000000000 +0000
7136 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7137         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7138         INIT_CPUSET_SEQ(tsk)                                            \
7139         INIT_VTIME(tsk)                                                 \
7140 +       .xid            = 0,                                            \
7141 +       .vx_info        = NULL,                                         \
7142 +       .nid            = 0,                                            \
7143 +       .nx_info        = NULL,                                         \
7144  }
7145  
7146  
7147 diff -NurpP --minimal linux-3.13.10/include/linux/ipc.h linux-3.13.10-vs2.3.6.11/include/linux/ipc.h
7148 --- linux-3.13.10/include/linux/ipc.h   2012-12-11 03:30:57.000000000 +0000
7149 +++ linux-3.13.10-vs2.3.6.11/include/linux/ipc.h        2014-01-31 20:38:03.000000000 +0000
7150 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7151         key_t           key;
7152         kuid_t          uid;
7153         kgid_t          gid;
7154 +       vxid_t          xid;
7155         kuid_t          cuid;
7156         kgid_t          cgid;
7157         umode_t         mode; 
7158 diff -NurpP --minimal linux-3.13.10/include/linux/memcontrol.h linux-3.13.10-vs2.3.6.11/include/linux/memcontrol.h
7159 --- linux-3.13.10/include/linux/memcontrol.h    2013-11-25 15:47:01.000000000 +0000
7160 +++ linux-3.13.10-vs2.3.6.11/include/linux/memcontrol.h 2014-01-31 20:38:03.000000000 +0000
7161 @@ -99,6 +99,13 @@ extern struct mem_cgroup *try_get_mem_cg
7162  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7163  extern struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css);
7164  
7165 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7166 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7167 +
7168 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7169 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7170 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7171 +
7172  static inline
7173  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7174  {
7175 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
7176 --- linux-3.13.10/include/linux/mm_types.h      2014-01-22 20:39:11.000000000 +0000
7177 +++ linux-3.13.10-vs2.3.6.11/include/linux/mm_types.h   2014-01-31 20:38:03.000000000 +0000
7178 @@ -397,6 +397,7 @@ struct mm_struct {
7179  
7180         /* Architecture-specific MM context */
7181         mm_context_t context;
7182 +       struct vx_info *mm_vx_info;
7183  
7184         unsigned long flags; /* Must use atomic bitops to access the bits */
7185  
7186 diff -NurpP --minimal linux-3.13.10/include/linux/mount.h linux-3.13.10-vs2.3.6.11/include/linux/mount.h
7187 --- linux-3.13.10/include/linux/mount.h 2014-01-22 20:39:11.000000000 +0000
7188 +++ linux-3.13.10-vs2.3.6.11/include/linux/mount.h      2014-01-31 20:38:03.000000000 +0000
7189 @@ -52,6 +52,9 @@ struct mnt_namespace;
7190  #define MNT_DOOMED             0x1000000
7191  #define MNT_SYNC_UMOUNT                0x2000000
7192  
7193 +#define MNT_TAGID      0x10000
7194 +#define MNT_NOTAG      0x20000
7195 +
7196  struct vfsmount {
7197         struct dentry *mnt_root;        /* root of the mounted tree */
7198         struct super_block *mnt_sb;     /* pointer to superblock */
7199 diff -NurpP --minimal linux-3.13.10/include/linux/net.h linux-3.13.10-vs2.3.6.11/include/linux/net.h
7200 --- linux-3.13.10/include/linux/net.h   2014-01-22 20:39:11.000000000 +0000
7201 +++ linux-3.13.10-vs2.3.6.11/include/linux/net.h        2014-01-31 20:38:03.000000000 +0000
7202 @@ -39,6 +39,7 @@ struct net;
7203  #define SOCK_PASSCRED          3
7204  #define SOCK_PASSSEC           4
7205  #define SOCK_EXTERNALLY_ALLOCATED 5
7206 +#define SOCK_USER_SOCKET       6
7207  
7208  #ifndef ARCH_HAS_SOCKET_TYPES
7209  /**
7210 diff -NurpP --minimal linux-3.13.10/include/linux/netdevice.h linux-3.13.10-vs2.3.6.11/include/linux/netdevice.h
7211 --- linux-3.13.10/include/linux/netdevice.h     2014-04-17 01:12:37.000000000 +0000
7212 +++ linux-3.13.10-vs2.3.6.11/include/linux/netdevice.h  2014-03-12 15:51:07.000000000 +0000
7213 @@ -1839,6 +1839,7 @@ int init_dummy_netdev(struct net_device
7214  
7215  struct net_device *dev_get_by_index(struct net *net, int ifindex);
7216  struct net_device *__dev_get_by_index(struct net *net, int ifindex);
7217 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7218  struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
7219  int netdev_get_name(struct net *net, char *name, int ifindex);
7220  int dev_restart(struct net_device *dev);
7221 diff -NurpP --minimal linux-3.13.10/include/linux/nsproxy.h linux-3.13.10-vs2.3.6.11/include/linux/nsproxy.h
7222 --- linux-3.13.10/include/linux/nsproxy.h       2013-11-25 15:45:06.000000000 +0000
7223 +++ linux-3.13.10-vs2.3.6.11/include/linux/nsproxy.h    2014-01-31 20:38:03.000000000 +0000
7224 @@ -3,6 +3,7 @@
7225  
7226  #include <linux/spinlock.h>
7227  #include <linux/sched.h>
7228 +#include <linux/vserver/debug.h>
7229  
7230  struct mnt_namespace;
7231  struct uts_namespace;
7232 @@ -67,6 +68,7 @@ static inline struct nsproxy *task_nspro
7233  }
7234  
7235  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7236 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7237  void exit_task_namespaces(struct task_struct *tsk);
7238  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7239  void free_nsproxy(struct nsproxy *ns);
7240 @@ -74,16 +76,26 @@ int unshare_nsproxy_namespaces(unsigned
7241         struct cred *, struct fs_struct *);
7242  int __init nsproxy_cache_init(void);
7243  
7244 -static inline void put_nsproxy(struct nsproxy *ns)
7245 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
7246 +
7247 +static inline void __get_nsproxy(struct nsproxy *ns,
7248 +       const char *_file, int _line)
7249  {
7250 -       if (atomic_dec_and_test(&ns->count)) {
7251 -               free_nsproxy(ns);
7252 -       }
7253 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7254 +               ns, atomic_read(&ns->count), _file, _line);
7255 +       atomic_inc(&ns->count);
7256  }
7257  
7258 -static inline void get_nsproxy(struct nsproxy *ns)
7259 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
7260 +
7261 +static inline void __put_nsproxy(struct nsproxy *ns,
7262 +       const char *_file, int _line)
7263  {
7264 -       atomic_inc(&ns->count);
7265 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7266 +               ns, atomic_read(&ns->count), _file, _line);
7267 +       if (atomic_dec_and_test(&ns->count)) {
7268 +               free_nsproxy(ns);
7269 +       }
7270  }
7271  
7272  #endif
7273 diff -NurpP --minimal linux-3.13.10/include/linux/pid.h linux-3.13.10-vs2.3.6.11/include/linux/pid.h
7274 --- linux-3.13.10/include/linux/pid.h   2013-11-25 15:45:06.000000000 +0000
7275 +++ linux-3.13.10-vs2.3.6.11/include/linux/pid.h        2014-01-31 20:38:03.000000000 +0000
7276 @@ -8,7 +8,8 @@ enum pid_type
7277         PIDTYPE_PID,
7278         PIDTYPE_PGID,
7279         PIDTYPE_SID,
7280 -       PIDTYPE_MAX
7281 +       PIDTYPE_MAX,
7282 +       PIDTYPE_REALPID
7283  };
7284  
7285  /*
7286 @@ -170,6 +171,7 @@ static inline pid_t pid_nr(struct pid *p
7287  }
7288  
7289  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7290 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7291  pid_t pid_vnr(struct pid *pid);
7292  
7293  #define do_each_pid_task(pid, type, task)                              \
7294 diff -NurpP --minimal linux-3.13.10/include/linux/quotaops.h linux-3.13.10-vs2.3.6.11/include/linux/quotaops.h
7295 --- linux-3.13.10/include/linux/quotaops.h      2013-11-25 15:47:02.000000000 +0000
7296 +++ linux-3.13.10-vs2.3.6.11/include/linux/quotaops.h   2014-01-31 20:38:03.000000000 +0000
7297 @@ -8,6 +8,7 @@
7298  #define _LINUX_QUOTAOPS_
7299  
7300  #include <linux/fs.h>
7301 +#include <linux/vs_dlimit.h>
7302  
7303  #define DQUOT_SPACE_WARN       0x1
7304  #define DQUOT_SPACE_RESERVE    0x2
7305 @@ -207,11 +208,12 @@ static inline void dquot_drop(struct ino
7306  
7307  static inline int dquot_alloc_inode(const struct inode *inode)
7308  {
7309 -       return 0;
7310 +       return dl_alloc_inode(inode);
7311  }
7312  
7313  static inline void dquot_free_inode(const struct inode *inode)
7314  {
7315 +       dl_free_inode(inode);
7316  }
7317  
7318  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
7319 @@ -222,6 +224,10 @@ static inline int dquot_transfer(struct
7320  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
7321                 int flags)
7322  {
7323 +       int ret = 0;
7324 +
7325 +       if ((ret = dl_alloc_space(inode, number)))
7326 +               return ret;
7327         if (!(flags & DQUOT_SPACE_RESERVE))
7328                 inode_add_bytes(inode, number);
7329         return 0;
7330 @@ -232,6 +238,7 @@ static inline void __dquot_free_space(st
7331  {
7332         if (!(flags & DQUOT_SPACE_RESERVE))
7333                 inode_sub_bytes(inode, number);
7334 +       dl_free_space(inode, number);
7335  }
7336  
7337  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
7338 diff -NurpP --minimal linux-3.13.10/include/linux/sched.h linux-3.13.10-vs2.3.6.11/include/linux/sched.h
7339 --- linux-3.13.10/include/linux/sched.h 2014-01-22 20:39:11.000000000 +0000
7340 +++ linux-3.13.10-vs2.3.6.11/include/linux/sched.h      2014-01-31 20:38:03.000000000 +0000
7341 @@ -1237,6 +1237,14 @@ struct task_struct {
7342  #endif
7343         struct seccomp seccomp;
7344  
7345 +/* vserver context data */
7346 +       struct vx_info *vx_info;
7347 +       struct nx_info *nx_info;
7348 +
7349 +       vxid_t xid;
7350 +       vnid_t nid;
7351 +       vtag_t tag;
7352 +
7353  /* Thread group tracking */
7354         u32 parent_exec_id;
7355         u32 self_exec_id;
7356 @@ -1531,6 +1539,11 @@ struct pid_namespace;
7357  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
7358                         struct pid_namespace *ns);
7359  
7360 +#include <linux/vserver/base.h>
7361 +#include <linux/vserver/context.h>
7362 +#include <linux/vserver/debug.h>
7363 +#include <linux/vserver/pid.h>
7364 +
7365  static inline pid_t task_pid_nr(struct task_struct *tsk)
7366  {
7367         return tsk->pid;
7368 @@ -1544,7 +1557,8 @@ static inline pid_t task_pid_nr_ns(struc
7369  
7370  static inline pid_t task_pid_vnr(struct task_struct *tsk)
7371  {
7372 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7373 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7374 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
7375  }
7376  
7377  
7378 @@ -1557,7 +1571,7 @@ pid_t task_tgid_nr_ns(struct task_struct
7379  
7380  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
7381  {
7382 -       return pid_vnr(task_tgid(tsk));
7383 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
7384  }
7385  
7386  
7387 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
7388 --- linux-3.13.10/include/linux/shmem_fs.h      2014-01-22 20:39:11.000000000 +0000
7389 +++ linux-3.13.10-vs2.3.6.11/include/linux/shmem_fs.h   2014-01-31 20:38:03.000000000 +0000
7390 @@ -9,6 +9,9 @@
7391  
7392  /* inode in-kernel data */
7393  
7394 +#define TMPFS_SUPER_MAGIC      0x01021994
7395 +
7396 +
7397  struct shmem_inode_info {
7398         spinlock_t              lock;
7399         unsigned long           flags;
7400 diff -NurpP --minimal linux-3.13.10/include/linux/stat.h linux-3.13.10-vs2.3.6.11/include/linux/stat.h
7401 --- linux-3.13.10/include/linux/stat.h  2012-12-11 03:30:57.000000000 +0000
7402 +++ linux-3.13.10-vs2.3.6.11/include/linux/stat.h       2014-01-31 20:38:03.000000000 +0000
7403 @@ -25,6 +25,7 @@ struct kstat {
7404         unsigned int    nlink;
7405         kuid_t          uid;
7406         kgid_t          gid;
7407 +       ktag_t          tag;
7408         dev_t           rdev;
7409         loff_t          size;
7410         struct timespec  atime;
7411 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
7412 --- linux-3.13.10/include/linux/sunrpc/auth.h   2013-11-25 15:47:02.000000000 +0000
7413 +++ linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/auth.h        2014-01-31 20:38:03.000000000 +0000
7414 @@ -36,6 +36,7 @@ enum {
7415  struct auth_cred {
7416         kuid_t  uid;
7417         kgid_t  gid;
7418 +       ktag_t  tag;
7419         struct group_info *group_info;
7420         const char *principal;
7421         unsigned long ac_flags;
7422 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
7423 --- linux-3.13.10/include/linux/sunrpc/clnt.h   2014-01-22 20:39:11.000000000 +0000
7424 +++ linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/clnt.h        2014-01-31 20:38:03.000000000 +0000
7425 @@ -51,7 +51,8 @@ struct rpc_clnt {
7426                                 cl_discrtry : 1,/* disconnect before retry */
7427                                 cl_noretranstimeo: 1,/* No retransmit timeouts */
7428                                 cl_autobind : 1,/* use getport() */
7429 -                               cl_chatty   : 1;/* be verbose */
7430 +                               cl_chatty   : 1,/* be verbose */
7431 +                               cl_tag      : 1;/* context tagging */
7432  
7433         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
7434         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
7435 diff -NurpP --minimal linux-3.13.10/include/linux/sysfs.h linux-3.13.10-vs2.3.6.11/include/linux/sysfs.h
7436 --- linux-3.13.10/include/linux/sysfs.h 2014-01-22 20:39:11.000000000 +0000
7437 +++ linux-3.13.10-vs2.3.6.11/include/linux/sysfs.h      2014-01-31 20:38:03.000000000 +0000
7438 @@ -20,6 +20,8 @@
7439  #include <linux/stat.h>
7440  #include <linux/atomic.h>
7441  
7442 +#define SYSFS_SUPER_MAGIC      0x62656572
7443 +
7444  struct kobject;
7445  struct module;
7446  struct bin_attribute;
7447 diff -NurpP --minimal linux-3.13.10/include/linux/types.h linux-3.13.10-vs2.3.6.11/include/linux/types.h
7448 --- linux-3.13.10/include/linux/types.h 2013-02-19 13:58:52.000000000 +0000
7449 +++ linux-3.13.10-vs2.3.6.11/include/linux/types.h      2014-01-31 20:38:03.000000000 +0000
7450 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
7451  typedef __kernel_gid32_t       gid_t;
7452  typedef __kernel_uid16_t        uid16_t;
7453  typedef __kernel_gid16_t        gid16_t;
7454 +typedef unsigned int           vxid_t;
7455 +typedef unsigned int           vnid_t;
7456 +typedef unsigned int           vtag_t;
7457  
7458  typedef unsigned long          uintptr_t;
7459  
7460 diff -NurpP --minimal linux-3.13.10/include/linux/uidgid.h linux-3.13.10-vs2.3.6.11/include/linux/uidgid.h
7461 --- linux-3.13.10/include/linux/uidgid.h        2012-12-11 03:30:57.000000000 +0000
7462 +++ linux-3.13.10-vs2.3.6.11/include/linux/uidgid.h     2014-01-31 20:38:03.000000000 +0000
7463 @@ -23,13 +23,17 @@ typedef struct {
7464         uid_t val;
7465  } kuid_t;
7466  
7467 -
7468  typedef struct {
7469         gid_t val;
7470  } kgid_t;
7471  
7472 +typedef struct {
7473 +       vtag_t val;
7474 +} ktag_t;
7475 +
7476  #define KUIDT_INIT(value) (kuid_t){ value }
7477  #define KGIDT_INIT(value) (kgid_t){ value }
7478 +#define KTAGT_INIT(value) (ktag_t){ value }
7479  
7480  static inline uid_t __kuid_val(kuid_t uid)
7481  {
7482 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
7483         return gid.val;
7484  }
7485  
7486 +static inline vtag_t __ktag_val(ktag_t tag)
7487 +{
7488 +       return tag.val;
7489 +}
7490 +
7491  #else
7492  
7493  typedef uid_t kuid_t;
7494  typedef gid_t kgid_t;
7495 +typedef vtag_t ktag_t;
7496  
7497  static inline uid_t __kuid_val(kuid_t uid)
7498  {
7499 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
7500         return gid;
7501  }
7502  
7503 +static inline vtag_t __ktag_val(ktag_t tag)
7504 +{
7505 +       return tag;
7506 +}
7507 +
7508  #define KUIDT_INIT(value) ((kuid_t) value )
7509  #define KGIDT_INIT(value) ((kgid_t) value )
7510 +#define KTAGT_INIT(value) ((ktag_t) value )
7511  
7512  #endif
7513  
7514  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
7515  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
7516 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
7517  
7518  #define INVALID_UID KUIDT_INIT(-1)
7519  #define INVALID_GID KGIDT_INIT(-1)
7520 +#define INVALID_TAG KTAGT_INIT(-1)
7521  
7522  static inline bool uid_eq(kuid_t left, kuid_t right)
7523  {
7524 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
7525         return __kgid_val(left) == __kgid_val(right);
7526  }
7527  
7528 +static inline bool tag_eq(ktag_t left, ktag_t right)
7529 +{
7530 +       return __ktag_val(left) == __ktag_val(right);
7531 +}
7532 +
7533  static inline bool uid_gt(kuid_t left, kuid_t right)
7534  {
7535         return __kuid_val(left) > __kuid_val(right);
7536 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
7537         return !gid_eq(gid, INVALID_GID);
7538  }
7539  
7540 +static inline bool tag_valid(ktag_t tag)
7541 +{
7542 +       return !tag_eq(tag, INVALID_TAG);
7543 +}
7544 +
7545  #ifdef CONFIG_USER_NS
7546  
7547  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
7548  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
7549 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
7550  
7551  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
7552  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
7553 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
7554 +
7555  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
7556  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
7557  
7558 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
7559         return KGIDT_INIT(gid);
7560  }
7561  
7562 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
7563 +{
7564 +       return KTAGT_INIT(tag);
7565 +}
7566 +
7567  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
7568  {
7569         return __kuid_val(kuid);
7570 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
7571         return __kgid_val(kgid);
7572  }
7573  
7574 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
7575 +{
7576 +       return __ktag_val(ktag);
7577 +}
7578 +
7579  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
7580  {
7581         uid_t uid = from_kuid(to, kuid);
7582 diff -NurpP --minimal linux-3.13.10/include/linux/vroot.h linux-3.13.10-vs2.3.6.11/include/linux/vroot.h
7583 --- linux-3.13.10/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
7584 +++ linux-3.13.10-vs2.3.6.11/include/linux/vroot.h      2014-01-31 20:38:03.000000000 +0000
7585 @@ -0,0 +1,51 @@
7586 +
7587 +/*
7588 + * include/linux/vroot.h
7589 + *
7590 + * written by Herbert Pötzl, 9/11/2002
7591 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
7592 + *
7593 + * Copyright (C) 2002-2007 by Herbert Pötzl.
7594 + * Redistribution of this file is permitted under the
7595 + * GNU General Public License.
7596 + */
7597 +
7598 +#ifndef _LINUX_VROOT_H
7599 +#define _LINUX_VROOT_H
7600 +
7601 +
7602 +#ifdef __KERNEL__
7603 +
7604 +/* Possible states of device */
7605 +enum {
7606 +       Vr_unbound,
7607 +       Vr_bound,
7608 +};
7609 +
7610 +struct vroot_device {
7611 +       int             vr_number;
7612 +       int             vr_refcnt;
7613 +
7614 +       struct semaphore        vr_ctl_mutex;
7615 +       struct block_device    *vr_device;
7616 +       int                     vr_state;
7617 +};
7618 +
7619 +
7620 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
7621 +
7622 +extern int register_vroot_grb(vroot_grb_func *);
7623 +extern int unregister_vroot_grb(vroot_grb_func *);
7624 +
7625 +#endif /* __KERNEL__ */
7626 +
7627 +#define MAX_VROOT_DEFAULT      8
7628 +
7629 +/*
7630 + * IOCTL commands --- we will commandeer 0x56 ('V')
7631 + */
7632 +
7633 +#define VROOT_SET_DEV          0x5600
7634 +#define VROOT_CLR_DEV          0x5601
7635 +
7636 +#endif /* _LINUX_VROOT_H */
7637 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
7638 --- linux-3.13.10/include/linux/vs_base.h       1970-01-01 00:00:00.000000000 +0000
7639 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_base.h    2014-01-31 20:38:03.000000000 +0000
7640 @@ -0,0 +1,10 @@
7641 +#ifndef _VS_BASE_H
7642 +#define _VS_BASE_H
7643 +
7644 +#include "vserver/base.h"
7645 +#include "vserver/check.h"
7646 +#include "vserver/debug.h"
7647 +
7648 +#else
7649 +#warning duplicate inclusion
7650 +#endif
7651 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
7652 --- linux-3.13.10/include/linux/vs_context.h    1970-01-01 00:00:00.000000000 +0000
7653 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_context.h 2014-01-31 20:38:03.000000000 +0000
7654 @@ -0,0 +1,242 @@
7655 +#ifndef _VS_CONTEXT_H
7656 +#define _VS_CONTEXT_H
7657 +
7658 +#include "vserver/base.h"
7659 +#include "vserver/check.h"
7660 +#include "vserver/context.h"
7661 +#include "vserver/history.h"
7662 +#include "vserver/debug.h"
7663 +
7664 +#include <linux/sched.h>
7665 +
7666 +
7667 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
7668 +
7669 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
7670 +       const char *_file, int _line, void *_here)
7671 +{
7672 +       if (!vxi)
7673 +               return NULL;
7674 +
7675 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
7676 +               vxi, vxi ? vxi->vx_id : 0,
7677 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7678 +               _file, _line);
7679 +       __vxh_get_vx_info(vxi, _here);
7680 +
7681 +       atomic_inc(&vxi->vx_usecnt);
7682 +       return vxi;
7683 +}
7684 +
7685 +
7686 +extern void free_vx_info(struct vx_info *);
7687 +
7688 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
7689 +
7690 +static inline void __put_vx_info(struct vx_info *vxi,
7691 +       const char *_file, int _line, void *_here)
7692 +{
7693 +       if (!vxi)
7694 +               return;
7695 +
7696 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
7697 +               vxi, vxi ? vxi->vx_id : 0,
7698 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7699 +               _file, _line);
7700 +       __vxh_put_vx_info(vxi, _here);
7701 +
7702 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
7703 +               free_vx_info(vxi);
7704 +}
7705 +
7706 +
7707 +#define init_vx_info(p, i) \
7708 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7709 +
7710 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7711 +       const char *_file, int _line, void *_here)
7712 +{
7713 +       if (vxi) {
7714 +               vxlprintk(VXD_CBIT(xid, 3),
7715 +                       "init_vx_info(%p[#%d.%d])",
7716 +                       vxi, vxi ? vxi->vx_id : 0,
7717 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7718 +                       _file, _line);
7719 +               __vxh_init_vx_info(vxi, vxp, _here);
7720 +
7721 +               atomic_inc(&vxi->vx_usecnt);
7722 +       }
7723 +       *vxp = vxi;
7724 +}
7725 +
7726 +
7727 +#define set_vx_info(p, i) \
7728 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7729 +
7730 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7731 +       const char *_file, int _line, void *_here)
7732 +{
7733 +       struct vx_info *vxo;
7734 +
7735 +       if (!vxi)
7736 +               return;
7737 +
7738 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
7739 +               vxi, vxi ? vxi->vx_id : 0,
7740 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7741 +               _file, _line);
7742 +       __vxh_set_vx_info(vxi, vxp, _here);
7743 +
7744 +       atomic_inc(&vxi->vx_usecnt);
7745 +       vxo = xchg(vxp, vxi);
7746 +       BUG_ON(vxo);
7747 +}
7748 +
7749 +
7750 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
7751 +
7752 +static inline void __clr_vx_info(struct vx_info **vxp,
7753 +       const char *_file, int _line, void *_here)
7754 +{
7755 +       struct vx_info *vxo;
7756 +
7757 +       vxo = xchg(vxp, NULL);
7758 +       if (!vxo)
7759 +               return;
7760 +
7761 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
7762 +               vxo, vxo ? vxo->vx_id : 0,
7763 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
7764 +               _file, _line);
7765 +       __vxh_clr_vx_info(vxo, vxp, _here);
7766 +
7767 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
7768 +               free_vx_info(vxo);
7769 +}
7770 +
7771 +
7772 +#define claim_vx_info(v, p) \
7773 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7774 +
7775 +static inline void __claim_vx_info(struct vx_info *vxi,
7776 +       struct task_struct *task,
7777 +       const char *_file, int _line, void *_here)
7778 +{
7779 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
7780 +               vxi, vxi ? vxi->vx_id : 0,
7781 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7782 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7783 +               task, _file, _line);
7784 +       __vxh_claim_vx_info(vxi, task, _here);
7785 +
7786 +       atomic_inc(&vxi->vx_tasks);
7787 +}
7788 +
7789 +
7790 +extern void unhash_vx_info(struct vx_info *);
7791 +
7792 +#define release_vx_info(v, p) \
7793 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7794 +
7795 +static inline void __release_vx_info(struct vx_info *vxi,
7796 +       struct task_struct *task,
7797 +       const char *_file, int _line, void *_here)
7798 +{
7799 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
7800 +               vxi, vxi ? vxi->vx_id : 0,
7801 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7802 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7803 +               task, _file, _line);
7804 +       __vxh_release_vx_info(vxi, task, _here);
7805 +
7806 +       might_sleep();
7807 +
7808 +       if (atomic_dec_and_test(&vxi->vx_tasks))
7809 +               unhash_vx_info(vxi);
7810 +}
7811 +
7812 +
7813 +#define task_get_vx_info(p) \
7814 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
7815 +
7816 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
7817 +       const char *_file, int _line, void *_here)
7818 +{
7819 +       struct vx_info *vxi;
7820 +
7821 +       task_lock(p);
7822 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
7823 +               p, _file, _line);
7824 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
7825 +       task_unlock(p);
7826 +       return vxi;
7827 +}
7828 +
7829 +
7830 +static inline void __wakeup_vx_info(struct vx_info *vxi)
7831 +{
7832 +       if (waitqueue_active(&vxi->vx_wait))
7833 +               wake_up_interruptible(&vxi->vx_wait);
7834 +}
7835 +
7836 +
7837 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
7838 +
7839 +static inline void __enter_vx_info(struct vx_info *vxi,
7840 +       struct vx_info_save *vxis, const char *_file, int _line)
7841 +{
7842 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
7843 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
7844 +               current->xid, current->vx_info, _file, _line);
7845 +       vxis->vxi = xchg(&current->vx_info, vxi);
7846 +       vxis->xid = current->xid;
7847 +       current->xid = vxi ? vxi->vx_id : 0;
7848 +}
7849 +
7850 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
7851 +
7852 +static inline void __leave_vx_info(struct vx_info_save *vxis,
7853 +       const char *_file, int _line)
7854 +{
7855 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
7856 +               vxis, vxis->xid, vxis->vxi, current,
7857 +               current->xid, current->vx_info, _file, _line);
7858 +       (void)xchg(&current->vx_info, vxis->vxi);
7859 +       current->xid = vxis->xid;
7860 +}
7861 +
7862 +
7863 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
7864 +{
7865 +       vxis->vxi = xchg(&current->vx_info, NULL);
7866 +       vxis->xid = xchg(&current->xid, (vxid_t)0);
7867 +}
7868 +
7869 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
7870 +{
7871 +       (void)xchg(&current->xid, vxis->xid);
7872 +       (void)xchg(&current->vx_info, vxis->vxi);
7873 +}
7874 +
7875 +#define task_is_init(p) \
7876 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
7877 +
7878 +static inline int __task_is_init(struct task_struct *p,
7879 +       const char *_file, int _line, void *_here)
7880 +{
7881 +       int is_init = is_global_init(p);
7882 +
7883 +       task_lock(p);
7884 +       if (p->vx_info)
7885 +               is_init = p->vx_info->vx_initpid == p->pid;
7886 +       task_unlock(p);
7887 +       return is_init;
7888 +}
7889 +
7890 +extern void exit_vx_info(struct task_struct *, int);
7891 +extern void exit_vx_info_early(struct task_struct *, int);
7892 +
7893 +
7894 +#else
7895 +#warning duplicate inclusion
7896 +#endif
7897 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
7898 --- linux-3.13.10/include/linux/vs_cowbl.h      1970-01-01 00:00:00.000000000 +0000
7899 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_cowbl.h   2014-01-31 20:38:03.000000000 +0000
7900 @@ -0,0 +1,48 @@
7901 +#ifndef _VS_COWBL_H
7902 +#define _VS_COWBL_H
7903 +
7904 +#include <linux/fs.h>
7905 +#include <linux/dcache.h>
7906 +#include <linux/namei.h>
7907 +#include <linux/slab.h>
7908 +
7909 +extern struct dentry *cow_break_link(const char *pathname);
7910 +
7911 +static inline int cow_check_and_break(struct path *path)
7912 +{
7913 +       struct inode *inode = path->dentry->d_inode;
7914 +       int error = 0;
7915 +
7916 +       /* do we need this check? */
7917 +       if (IS_RDONLY(inode))
7918 +               return -EROFS;
7919 +
7920 +       if (IS_COW(inode)) {
7921 +               if (IS_COW_LINK(inode)) {
7922 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
7923 +                       char *pp, *buf;
7924 +
7925 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
7926 +                       if (!buf) {
7927 +                               return -ENOMEM;
7928 +                       }
7929 +                       pp = d_path(path, buf, PATH_MAX);
7930 +                       new_dentry = cow_break_link(pp);
7931 +                       kfree(buf);
7932 +                       if (!IS_ERR(new_dentry)) {
7933 +                               path->dentry = new_dentry;
7934 +                               dput(old_dentry);
7935 +                       } else
7936 +                               error = PTR_ERR(new_dentry);
7937 +               } else {
7938 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
7939 +                       inode->i_ctime = CURRENT_TIME;
7940 +                       mark_inode_dirty(inode);
7941 +               }
7942 +       }
7943 +       return error;
7944 +}
7945 +
7946 +#else
7947 +#warning duplicate inclusion
7948 +#endif
7949 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
7950 --- linux-3.13.10/include/linux/vs_cvirt.h      1970-01-01 00:00:00.000000000 +0000
7951 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_cvirt.h   2014-01-31 20:38:03.000000000 +0000
7952 @@ -0,0 +1,50 @@
7953 +#ifndef _VS_CVIRT_H
7954 +#define _VS_CVIRT_H
7955 +
7956 +#include "vserver/cvirt.h"
7957 +#include "vserver/context.h"
7958 +#include "vserver/base.h"
7959 +#include "vserver/check.h"
7960 +#include "vserver/debug.h"
7961 +
7962 +
7963 +static inline void vx_activate_task(struct task_struct *p)
7964 +{
7965 +       struct vx_info *vxi;
7966 +
7967 +       if ((vxi = p->vx_info)) {
7968 +               vx_update_load(vxi);
7969 +               atomic_inc(&vxi->cvirt.nr_running);
7970 +       }
7971 +}
7972 +
7973 +static inline void vx_deactivate_task(struct task_struct *p)
7974 +{
7975 +       struct vx_info *vxi;
7976 +
7977 +       if ((vxi = p->vx_info)) {
7978 +               vx_update_load(vxi);
7979 +               atomic_dec(&vxi->cvirt.nr_running);
7980 +       }
7981 +}
7982 +
7983 +static inline void vx_uninterruptible_inc(struct task_struct *p)
7984 +{
7985 +       struct vx_info *vxi;
7986 +
7987 +       if ((vxi = p->vx_info))
7988 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
7989 +}
7990 +
7991 +static inline void vx_uninterruptible_dec(struct task_struct *p)
7992 +{
7993 +       struct vx_info *vxi;
7994 +
7995 +       if ((vxi = p->vx_info))
7996 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
7997 +}
7998 +
7999 +
8000 +#else
8001 +#warning duplicate inclusion
8002 +#endif
8003 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
8004 --- linux-3.13.10/include/linux/vs_device.h     1970-01-01 00:00:00.000000000 +0000
8005 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_device.h  2014-01-31 20:38:03.000000000 +0000
8006 @@ -0,0 +1,45 @@
8007 +#ifndef _VS_DEVICE_H
8008 +#define _VS_DEVICE_H
8009 +
8010 +#include "vserver/base.h"
8011 +#include "vserver/device.h"
8012 +#include "vserver/debug.h"
8013 +
8014 +
8015 +#ifdef CONFIG_VSERVER_DEVICE
8016 +
8017 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8018 +
8019 +#define vs_device_perm(v, d, m, p) \
8020 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8021 +
8022 +#else
8023 +
8024 +static inline
8025 +int vs_map_device(struct vx_info *vxi,
8026 +       dev_t device, dev_t *target, umode_t mode)
8027 +{
8028 +       if (target)
8029 +               *target = device;
8030 +       return ~0;
8031 +}
8032 +
8033 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8034 +
8035 +#endif
8036 +
8037 +
8038 +#define vs_map_chrdev(d, t, p) \
8039 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8040 +#define vs_map_blkdev(d, t, p) \
8041 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8042 +
8043 +#define vs_chrdev_perm(d, p) \
8044 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8045 +#define vs_blkdev_perm(d, p) \
8046 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8047 +
8048 +
8049 +#else
8050 +#warning duplicate inclusion
8051 +#endif
8052 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
8053 --- linux-3.13.10/include/linux/vs_dlimit.h     1970-01-01 00:00:00.000000000 +0000
8054 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_dlimit.h  2014-01-31 20:38:03.000000000 +0000
8055 @@ -0,0 +1,215 @@
8056 +#ifndef _VS_DLIMIT_H
8057 +#define _VS_DLIMIT_H
8058 +
8059 +#include <linux/fs.h>
8060 +
8061 +#include "vserver/dlimit.h"
8062 +#include "vserver/base.h"
8063 +#include "vserver/debug.h"
8064 +
8065 +
8066 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8067 +
8068 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8069 +       const char *_file, int _line)
8070 +{
8071 +       if (!dli)
8072 +               return NULL;
8073 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8074 +               dli, dli ? dli->dl_tag : 0,
8075 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8076 +               _file, _line);
8077 +       atomic_inc(&dli->dl_usecnt);
8078 +       return dli;
8079 +}
8080 +
8081 +
8082 +#define free_dl_info(i) \
8083 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8084 +
8085 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8086 +
8087 +static inline void __put_dl_info(struct dl_info *dli,
8088 +       const char *_file, int _line)
8089 +{
8090 +       if (!dli)
8091 +               return;
8092 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8093 +               dli, dli ? dli->dl_tag : 0,
8094 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8095 +               _file, _line);
8096 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8097 +               free_dl_info(dli);
8098 +}
8099 +
8100 +
8101 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8102 +
8103 +static inline int __dl_alloc_space(struct super_block *sb,
8104 +       vtag_t tag, dlsize_t nr, const char *file, int line)
8105 +{
8106 +       struct dl_info *dli = NULL;
8107 +       int ret = 0;
8108 +
8109 +       if (nr == 0)
8110 +               goto out;
8111 +       dli = locate_dl_info(sb, tag);
8112 +       if (!dli)
8113 +               goto out;
8114 +
8115 +       spin_lock(&dli->dl_lock);
8116 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
8117 +       if (!ret)
8118 +               dli->dl_space_used += nr;
8119 +       spin_unlock(&dli->dl_lock);
8120 +       put_dl_info(dli);
8121 +out:
8122 +       vxlprintk(VXD_CBIT(dlim, 1),
8123 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
8124 +               sb, tag, __dlimit_char(dli), (long long)nr,
8125 +               ret, file, line);
8126 +       return ret ? -ENOSPC : 0;
8127 +}
8128 +
8129 +static inline void __dl_free_space(struct super_block *sb,
8130 +       vtag_t tag, dlsize_t nr, const char *_file, int _line)
8131 +{
8132 +       struct dl_info *dli = NULL;
8133 +
8134 +       if (nr == 0)
8135 +               goto out;
8136 +       dli = locate_dl_info(sb, tag);
8137 +       if (!dli)
8138 +               goto out;
8139 +
8140 +       spin_lock(&dli->dl_lock);
8141 +       if (dli->dl_space_used > nr)
8142 +               dli->dl_space_used -= nr;
8143 +       else
8144 +               dli->dl_space_used = 0;
8145 +       spin_unlock(&dli->dl_lock);
8146 +       put_dl_info(dli);
8147 +out:
8148 +       vxlprintk(VXD_CBIT(dlim, 1),
8149 +               "FREE  (%p,#%d)%c %lld bytes",
8150 +               sb, tag, __dlimit_char(dli), (long long)nr,
8151 +               _file, _line);
8152 +}
8153 +
8154 +static inline int __dl_alloc_inode(struct super_block *sb,
8155 +       vtag_t tag, const char *_file, int _line)
8156 +{
8157 +       struct dl_info *dli;
8158 +       int ret = 0;
8159 +
8160 +       dli = locate_dl_info(sb, tag);
8161 +       if (!dli)
8162 +               goto out;
8163 +
8164 +       spin_lock(&dli->dl_lock);
8165 +       dli->dl_inodes_used++;
8166 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8167 +       spin_unlock(&dli->dl_lock);
8168 +       put_dl_info(dli);
8169 +out:
8170 +       vxlprintk(VXD_CBIT(dlim, 0),
8171 +               "ALLOC (%p,#%d)%c inode (%d)",
8172 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
8173 +       return ret ? -ENOSPC : 0;
8174 +}
8175 +
8176 +static inline void __dl_free_inode(struct super_block *sb,
8177 +       vtag_t tag, const char *_file, int _line)
8178 +{
8179 +       struct dl_info *dli;
8180 +
8181 +       dli = locate_dl_info(sb, tag);
8182 +       if (!dli)
8183 +               goto out;
8184 +
8185 +       spin_lock(&dli->dl_lock);
8186 +       if (dli->dl_inodes_used > 1)
8187 +               dli->dl_inodes_used--;
8188 +       else
8189 +               dli->dl_inodes_used = 0;
8190 +       spin_unlock(&dli->dl_lock);
8191 +       put_dl_info(dli);
8192 +out:
8193 +       vxlprintk(VXD_CBIT(dlim, 0),
8194 +               "FREE  (%p,#%d)%c inode",
8195 +               sb, tag, __dlimit_char(dli), _file, _line);
8196 +}
8197 +
8198 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
8199 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
8200 +       const char *_file, int _line)
8201 +{
8202 +       struct dl_info *dli;
8203 +       uint64_t broot, bfree;
8204 +
8205 +       dli = locate_dl_info(sb, tag);
8206 +       if (!dli)
8207 +               return;
8208 +
8209 +       spin_lock(&dli->dl_lock);
8210 +       broot = (dli->dl_space_total -
8211 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8212 +               >> sb->s_blocksize_bits;
8213 +       bfree = (dli->dl_space_total - dli->dl_space_used)
8214 +                       >> sb->s_blocksize_bits;
8215 +       spin_unlock(&dli->dl_lock);
8216 +
8217 +       vxlprintk(VXD_CBIT(dlim, 2),
8218 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8219 +               (long long)bfree, (long long)broot,
8220 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
8221 +               _file, _line);
8222 +       if (free_blocks) {
8223 +               if (*free_blocks > bfree)
8224 +                       *free_blocks = bfree;
8225 +       }
8226 +       if (root_blocks) {
8227 +               if (*root_blocks > broot)
8228 +                       *root_blocks = broot;
8229 +       }
8230 +       put_dl_info(dli);
8231 +}
8232 +
8233 +#define dl_prealloc_space(in, bytes) \
8234 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8235 +               __FILE__, __LINE__ )
8236 +
8237 +#define dl_alloc_space(in, bytes) \
8238 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8239 +               __FILE__, __LINE__ )
8240 +
8241 +#define dl_reserve_space(in, bytes) \
8242 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8243 +               __FILE__, __LINE__ )
8244 +
8245 +#define dl_claim_space(in, bytes) (0)
8246 +
8247 +#define dl_release_space(in, bytes) \
8248 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8249 +               __FILE__, __LINE__ )
8250 +
8251 +#define dl_free_space(in, bytes) \
8252 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8253 +               __FILE__, __LINE__ )
8254 +
8255 +
8256 +
8257 +#define dl_alloc_inode(in) \
8258 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8259 +
8260 +#define dl_free_inode(in) \
8261 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8262 +
8263 +
8264 +#define dl_adjust_block(sb, tag, fb, rb) \
8265 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8266 +
8267 +
8268 +#else
8269 +#warning duplicate inclusion
8270 +#endif
8271 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
8272 --- linux-3.13.10/include/linux/vs_inet.h       1970-01-01 00:00:00.000000000 +0000
8273 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_inet.h    2014-02-01 00:32:45.000000000 +0000
8274 @@ -0,0 +1,364 @@
8275 +#ifndef _VS_INET_H
8276 +#define _VS_INET_H
8277 +
8278 +#include "vserver/base.h"
8279 +#include "vserver/network.h"
8280 +#include "vserver/debug.h"
8281 +
8282 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
8283 +
8284 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
8285 +                       NIPQUAD((a)->mask), (a)->type
8286 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
8287 +
8288 +#define NIPQUAD(addr) \
8289 +       ((unsigned char *)&addr)[0], \
8290 +       ((unsigned char *)&addr)[1], \
8291 +       ((unsigned char *)&addr)[2], \
8292 +       ((unsigned char *)&addr)[3]
8293 +
8294 +#define NIPQUAD_FMT "%u.%u.%u.%u"
8295 +
8296 +
8297 +static inline
8298 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
8299 +{
8300 +       __be32 ip = nxa->ip[0].s_addr;
8301 +       __be32 mask = nxa->mask.s_addr;
8302 +       __be32 bcast = ip | ~mask;
8303 +       int ret = 0;
8304 +
8305 +       switch (nxa->type & tmask) {
8306 +       case NXA_TYPE_MASK:
8307 +               ret = (ip == (addr & mask));
8308 +               break;
8309 +       case NXA_TYPE_ADDR:
8310 +               ret = 3;
8311 +               if (addr == ip)
8312 +                       break;
8313 +               /* fall through to broadcast */
8314 +       case NXA_MOD_BCAST:
8315 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
8316 +               break;
8317 +       case NXA_TYPE_RANGE:
8318 +               ret = ((nxa->ip[0].s_addr <= addr) &&
8319 +                       (nxa->ip[1].s_addr > addr));
8320 +               break;
8321 +       case NXA_TYPE_ANY:
8322 +               ret = 2;
8323 +               break;
8324 +       }
8325 +
8326 +       vxdprintk(VXD_CBIT(net, 0),
8327 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
8328 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
8329 +       return ret;
8330 +}
8331 +
8332 +static inline
8333 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
8334 +{
8335 +       struct nx_addr_v4 *nxa;
8336 +       unsigned long irqflags;
8337 +       int ret = 1;
8338 +
8339 +       if (!nxi)
8340 +               goto out;
8341 +
8342 +       ret = 2;
8343 +       /* allow 127.0.0.1 when remapping lback */
8344 +       if ((tmask & NXA_LOOPBACK) &&
8345 +               (addr == IPI_LOOPBACK) &&
8346 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8347 +               goto out;
8348 +       ret = 3;
8349 +       /* check for lback address */
8350 +       if ((tmask & NXA_MOD_LBACK) &&
8351 +               (nxi->v4_lback.s_addr == addr))
8352 +               goto out;
8353 +       ret = 4;
8354 +       /* check for broadcast address */
8355 +       if ((tmask & NXA_MOD_BCAST) &&
8356 +               (nxi->v4_bcast.s_addr == addr))
8357 +               goto out;
8358 +       ret = 5;
8359 +
8360 +       /* check for v4 addresses */
8361 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8362 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
8363 +               if (v4_addr_match(nxa, addr, tmask))
8364 +                       goto out_unlock;
8365 +       ret = 0;
8366 +out_unlock:
8367 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8368 +out:
8369 +       vxdprintk(VXD_CBIT(net, 0),
8370 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
8371 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
8372 +       return ret;
8373 +}
8374 +
8375 +static inline
8376 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
8377 +{
8378 +       /* FIXME: needs full range checks */
8379 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
8380 +}
8381 +
8382 +static inline
8383 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
8384 +{
8385 +       struct nx_addr_v4 *ptr;
8386 +       unsigned long irqflags;
8387 +       int ret = 1;
8388 +
8389 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8390 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
8391 +               if (v4_nx_addr_match(ptr, nxa, mask))
8392 +                       goto out_unlock;
8393 +       ret = 0;
8394 +out_unlock:
8395 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8396 +       return ret;
8397 +}
8398 +
8399 +#include <net/inet_sock.h>
8400 +
8401 +/*
8402 + *     Check if a given address matches for a socket
8403 + *
8404 + *     nxi:            the socket's nx_info if any
8405 + *     addr:           to be verified address
8406 + */
8407 +static inline
8408 +int v4_sock_addr_match (
8409 +       struct nx_info *nxi,
8410 +       struct inet_sock *inet,
8411 +       __be32 addr)
8412 +{
8413 +       __be32 saddr = inet->inet_rcv_saddr;
8414 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
8415 +
8416 +       if (addr && (saddr == addr || bcast == addr))
8417 +               return 1;
8418 +       if (!saddr)
8419 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
8420 +       return 0;
8421 +}
8422 +
8423 +
8424 +/* inet related checks and helpers */
8425 +
8426 +
8427 +struct in_ifaddr;
8428 +struct net_device;
8429 +struct sock;
8430 +
8431 +#ifdef CONFIG_INET
8432 +
8433 +#include <linux/netdevice.h>
8434 +#include <linux/inetdevice.h>
8435 +#include <net/inet_sock.h>
8436 +#include <net/inet_timewait_sock.h>
8437 +
8438 +
8439 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8440 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
8441 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
8442 +
8443 +
8444 +/*
8445 + *     check if address is covered by socket
8446 + *
8447 + *     sk:     the socket to check against
8448 + *     addr:   the address in question (must be != 0)
8449 + */
8450 +
8451 +static inline
8452 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
8453 +{
8454 +       struct nx_info *nxi = sk->sk_nx_info;
8455 +       __be32 saddr = sk->sk_rcv_saddr;
8456 +
8457 +       vxdprintk(VXD_CBIT(net, 5),
8458 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
8459 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
8460 +               (sk->sk_socket?sk->sk_socket->flags:0));
8461 +
8462 +       if (saddr) {            /* direct address match */
8463 +               return v4_addr_match(nxa, saddr, -1);
8464 +       } else if (nxi) {       /* match against nx_info */
8465 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
8466 +       } else {                /* unrestricted any socket */
8467 +               return 1;
8468 +       }
8469 +}
8470 +
8471 +
8472 +
8473 +static inline
8474 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
8475 +{
8476 +       vxdprintk(VXD_CBIT(net, 1),
8477 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
8478 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
8479 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
8480 +
8481 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8482 +               return 1;
8483 +       if (dev_in_nx_info(dev, nxi))
8484 +               return 1;
8485 +       return 0;
8486 +}
8487 +
8488 +
8489 +static inline
8490 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
8491 +{
8492 +       if (!nxi)
8493 +               return 1;
8494 +       if (!ifa)
8495 +               return 0;
8496 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
8497 +}
8498 +
8499 +static inline
8500 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
8501 +{
8502 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
8503 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8504 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
8505 +
8506 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8507 +               return 1;
8508 +       if (v4_ifa_in_nx_info(ifa, nxi))
8509 +               return 1;
8510 +       return 0;
8511 +}
8512 +
8513 +
8514 +struct nx_v4_sock_addr {
8515 +       __be32 saddr;   /* Address used for validation */
8516 +       __be32 baddr;   /* Address used for socket bind */
8517 +};
8518 +
8519 +static inline
8520 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
8521 +       struct nx_v4_sock_addr *nsa)
8522 +{
8523 +       struct sock *sk = &inet->sk;
8524 +       struct nx_info *nxi = sk->sk_nx_info;
8525 +       __be32 saddr = addr->sin_addr.s_addr;
8526 +       __be32 baddr = saddr;
8527 +
8528 +       vxdprintk(VXD_CBIT(net, 3),
8529 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
8530 +               sk, sk->sk_nx_info, sk->sk_socket,
8531 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
8532 +               NIPQUAD(saddr));
8533 +
8534 +       if (nxi) {
8535 +               if (saddr == INADDR_ANY) {
8536 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
8537 +                               baddr = nxi->v4.ip[0].s_addr;
8538 +               } else if (saddr == IPI_LOOPBACK) {
8539 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8540 +                               baddr = nxi->v4_lback.s_addr;
8541 +               } else if (!ipv4_is_multicast(saddr) ||
8542 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
8543 +                       /* normal address bind */
8544 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
8545 +                               return -EADDRNOTAVAIL;
8546 +               }
8547 +       }
8548 +
8549 +       vxdprintk(VXD_CBIT(net, 3),
8550 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
8551 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
8552 +
8553 +       nsa->saddr = saddr;
8554 +       nsa->baddr = baddr;
8555 +       return 0;
8556 +}
8557 +
8558 +static inline
8559 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
8560 +{
8561 +       inet->inet_saddr = nsa->baddr;
8562 +       inet->inet_rcv_saddr = nsa->baddr;
8563 +}
8564 +
8565 +
8566 +/*
8567 + *      helper to simplify inet_lookup_listener
8568 + *
8569 + *      nxi:   the socket's nx_info if any
8570 + *      addr:  to be verified address
8571 + *      saddr: socket address
8572 + */
8573 +static inline int v4_inet_addr_match (
8574 +       struct nx_info *nxi,
8575 +       __be32 addr,
8576 +       __be32 saddr)
8577 +{
8578 +       if (addr && (saddr == addr))
8579 +               return 1;
8580 +       if (!saddr)
8581 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
8582 +       return 0;
8583 +}
8584 +
8585 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
8586 +{
8587 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
8588 +               (addr == nxi->v4_lback.s_addr))
8589 +               return IPI_LOOPBACK;
8590 +       return addr;
8591 +}
8592 +
8593 +static inline
8594 +int nx_info_has_v4(struct nx_info *nxi)
8595 +{
8596 +       if (!nxi)
8597 +               return 1;
8598 +       if (NX_IPV4(nxi))
8599 +               return 1;
8600 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8601 +               return 1;
8602 +       return 0;
8603 +}
8604 +
8605 +#else /* CONFIG_INET */
8606 +
8607 +static inline
8608 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
8609 +{
8610 +       return 1;
8611 +}
8612 +
8613 +static inline
8614 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8615 +{
8616 +       return 1;
8617 +}
8618 +
8619 +static inline
8620 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8621 +{
8622 +       return 1;
8623 +}
8624 +
8625 +static inline
8626 +int nx_info_has_v4(struct nx_info *nxi)
8627 +{
8628 +       return 0;
8629 +}
8630 +
8631 +#endif /* CONFIG_INET */
8632 +
8633 +#define current_nx_info_has_v4() \
8634 +       nx_info_has_v4(current_nx_info())
8635 +
8636 +#else
8637 +// #warning duplicate inclusion
8638 +#endif
8639 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
8640 --- linux-3.13.10/include/linux/vs_inet6.h      1970-01-01 00:00:00.000000000 +0000
8641 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_inet6.h   2014-02-01 00:35:02.000000000 +0000
8642 @@ -0,0 +1,257 @@
8643 +#ifndef _VS_INET6_H
8644 +#define _VS_INET6_H
8645 +
8646 +#include "vserver/base.h"
8647 +#include "vserver/network.h"
8648 +#include "vserver/debug.h"
8649 +
8650 +#include <net/ipv6.h>
8651 +
8652 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
8653 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
8654 +
8655 +
8656 +#ifdef CONFIG_IPV6
8657 +
8658 +static inline
8659 +int v6_addr_match(struct nx_addr_v6 *nxa,
8660 +       const struct in6_addr *addr, uint16_t mask)
8661 +{
8662 +       int ret = 0;
8663 +
8664 +       switch (nxa->type & mask) {
8665 +       case NXA_TYPE_MASK:
8666 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
8667 +               break;
8668 +       case NXA_TYPE_ADDR:
8669 +               ret = ipv6_addr_equal(&nxa->ip, addr);
8670 +               break;
8671 +       case NXA_TYPE_ANY:
8672 +               ret = 1;
8673 +               break;
8674 +       }
8675 +       vxdprintk(VXD_CBIT(net, 0),
8676 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
8677 +               nxa, NXAV6(nxa), addr, mask, ret);
8678 +       return ret;
8679 +}
8680 +
8681 +static inline
8682 +int v6_addr_in_nx_info(struct nx_info *nxi,
8683 +       const struct in6_addr *addr, uint16_t mask)
8684 +{
8685 +       struct nx_addr_v6 *nxa;
8686 +       unsigned long irqflags;
8687 +       int ret = 1;
8688 +
8689 +       if (!nxi)
8690 +               goto out;
8691 +
8692 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8693 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
8694 +               if (v6_addr_match(nxa, addr, mask))
8695 +                       goto out_unlock;
8696 +       ret = 0;
8697 +out_unlock:
8698 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8699 +out:
8700 +       vxdprintk(VXD_CBIT(net, 0),
8701 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
8702 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
8703 +       return ret;
8704 +}
8705 +
8706 +static inline
8707 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
8708 +{
8709 +       /* FIXME: needs full range checks */
8710 +       return v6_addr_match(nxa, &addr->ip, mask);
8711 +}
8712 +
8713 +static inline
8714 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
8715 +{
8716 +       struct nx_addr_v6 *ptr;
8717 +       unsigned long irqflags;
8718 +       int ret = 1;
8719 +
8720 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8721 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
8722 +               if (v6_nx_addr_match(ptr, nxa, mask))
8723 +                       goto out_unlock;
8724 +       ret = 0;
8725 +out_unlock:
8726 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8727 +       return ret;
8728 +}
8729 +
8730 +
8731 +/*
8732 + *     Check if a given address matches for a socket
8733 + *
8734 + *     nxi:            the socket's nx_info if any
8735 + *     addr:           to be verified address
8736 + */
8737 +static inline
8738 +int v6_sock_addr_match (
8739 +       struct nx_info *nxi,
8740 +       struct inet_sock *inet,
8741 +       struct in6_addr *addr)
8742 +{
8743 +       struct sock *sk = &inet->sk;
8744 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8745 +
8746 +       if (!ipv6_addr_any(addr) &&
8747 +               ipv6_addr_equal(saddr, addr))
8748 +               return 1;
8749 +       if (ipv6_addr_any(saddr))
8750 +               return v6_addr_in_nx_info(nxi, addr, -1);
8751 +       return 0;
8752 +}
8753 +
8754 +/*
8755 + *     check if address is covered by socket
8756 + *
8757 + *     sk:     the socket to check against
8758 + *     addr:   the address in question (must be != 0)
8759 + */
8760 +
8761 +static inline
8762 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
8763 +{
8764 +       struct nx_info *nxi = sk->sk_nx_info;
8765 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8766 +
8767 +       vxdprintk(VXD_CBIT(net, 5),
8768 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
8769 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
8770 +               (sk->sk_socket?sk->sk_socket->flags:0));
8771 +
8772 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
8773 +               return v6_addr_match(nxa, saddr, -1);
8774 +       } else if (nxi) {               /* match against nx_info */
8775 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
8776 +       } else {                        /* unrestricted any socket */
8777 +               return 1;
8778 +       }
8779 +}
8780 +
8781 +
8782 +/* inet related checks and helpers */
8783 +
8784 +
8785 +struct in_ifaddr;
8786 +struct net_device;
8787 +struct sock;
8788 +
8789 +
8790 +#include <linux/netdevice.h>
8791 +#include <linux/inetdevice.h>
8792 +#include <net/inet_timewait_sock.h>
8793 +
8794 +
8795 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8796 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
8797 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
8798 +
8799 +
8800 +
8801 +static inline
8802 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
8803 +{
8804 +       if (!nxi)
8805 +               return 1;
8806 +       if (!ifa)
8807 +               return 0;
8808 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
8809 +}
8810 +
8811 +static inline
8812 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
8813 +{
8814 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
8815 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8816 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
8817 +
8818 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8819 +               return 1;
8820 +       if (v6_ifa_in_nx_info(ifa, nxi))
8821 +               return 1;
8822 +       return 0;
8823 +}
8824 +
8825 +
8826 +struct nx_v6_sock_addr {
8827 +       struct in6_addr saddr;  /* Address used for validation */
8828 +       struct in6_addr baddr;  /* Address used for socket bind */
8829 +};
8830 +
8831 +static inline
8832 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
8833 +       struct nx_v6_sock_addr *nsa)
8834 +{
8835 +       // struct sock *sk = &inet->sk;
8836 +       // struct nx_info *nxi = sk->sk_nx_info;
8837 +       struct in6_addr saddr = addr->sin6_addr;
8838 +       struct in6_addr baddr = saddr;
8839 +
8840 +       nsa->saddr = saddr;
8841 +       nsa->baddr = baddr;
8842 +       return 0;
8843 +}
8844 +
8845 +static inline
8846 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
8847 +{
8848 +       // struct sock *sk = &inet->sk;
8849 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
8850 +
8851 +       // *saddr = nsa->baddr;
8852 +       // inet->inet_saddr = nsa->baddr;
8853 +}
8854 +
8855 +static inline
8856 +int nx_info_has_v6(struct nx_info *nxi)
8857 +{
8858 +       if (!nxi)
8859 +               return 1;
8860 +       if (NX_IPV6(nxi))
8861 +               return 1;
8862 +       return 0;
8863 +}
8864 +
8865 +#else /* CONFIG_IPV6 */
8866 +
8867 +static inline
8868 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
8869 +{
8870 +       return 1;
8871 +}
8872 +
8873 +
8874 +static inline
8875 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8876 +{
8877 +       return 1;
8878 +}
8879 +
8880 +static inline
8881 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8882 +{
8883 +       return 1;
8884 +}
8885 +
8886 +static inline
8887 +int nx_info_has_v6(struct nx_info *nxi)
8888 +{
8889 +       return 0;
8890 +}
8891 +
8892 +#endif /* CONFIG_IPV6 */
8893 +
8894 +#define current_nx_info_has_v6() \
8895 +       nx_info_has_v6(current_nx_info())
8896 +
8897 +#else
8898 +#warning duplicate inclusion
8899 +#endif
8900 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
8901 --- linux-3.13.10/include/linux/vs_limit.h      1970-01-01 00:00:00.000000000 +0000
8902 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_limit.h   2014-02-01 01:29:43.000000000 +0000
8903 @@ -0,0 +1,140 @@
8904 +#ifndef _VS_LIMIT_H
8905 +#define _VS_LIMIT_H
8906 +
8907 +#include "vserver/limit.h"
8908 +#include "vserver/base.h"
8909 +#include "vserver/context.h"
8910 +#include "vserver/debug.h"
8911 +#include "vserver/context.h"
8912 +#include "vserver/limit_int.h"
8913 +
8914 +
8915 +#define vx_acc_cres(v, d, p, r) \
8916 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
8917 +
8918 +#define vx_acc_cres_cond(x, d, p, r) \
8919 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8920 +       r, d, p, __FILE__, __LINE__)
8921 +
8922 +
8923 +#define vx_add_cres(v, a, p, r) \
8924 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
8925 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
8926 +
8927 +#define vx_add_cres_cond(x, a, p, r) \
8928 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8929 +       r, a, p, __FILE__, __LINE__)
8930 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
8931 +
8932 +
8933 +/* process and file limits */
8934 +
8935 +#define vx_nproc_inc(p) \
8936 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
8937 +
8938 +#define vx_nproc_dec(p) \
8939 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
8940 +
8941 +#define vx_files_inc(f) \
8942 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
8943 +
8944 +#define vx_files_dec(f) \
8945 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
8946 +
8947 +#define vx_locks_inc(l) \
8948 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
8949 +
8950 +#define vx_locks_dec(l) \
8951 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
8952 +
8953 +#define vx_openfd_inc(f) \
8954 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
8955 +
8956 +#define vx_openfd_dec(f) \
8957 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
8958 +
8959 +
8960 +#define vx_cres_avail(v, n, r) \
8961 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
8962 +
8963 +
8964 +#define vx_nproc_avail(n) \
8965 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
8966 +
8967 +#define vx_files_avail(n) \
8968 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
8969 +
8970 +#define vx_locks_avail(n) \
8971 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
8972 +
8973 +#define vx_openfd_avail(n) \
8974 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
8975 +
8976 +
8977 +/* dentry limits */
8978 +
8979 +#define vx_dentry_inc(d) do {                                          \
8980 +       if (d_count(d) == 1)                                            \
8981 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
8982 +       } while (0)
8983 +
8984 +#define vx_dentry_dec(d) do {                                          \
8985 +       if (d_count(d) == 0)                                            \
8986 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
8987 +       } while (0)
8988 +
8989 +#define vx_dentry_avail(n) \
8990 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
8991 +
8992 +
8993 +/* socket limits */
8994 +
8995 +#define vx_sock_inc(s) \
8996 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
8997 +
8998 +#define vx_sock_dec(s) \
8999 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9000 +
9001 +#define vx_sock_avail(n) \
9002 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9003 +
9004 +
9005 +/* ipc resource limits */
9006 +
9007 +#define vx_ipcmsg_add(v, u, a) \
9008 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9009 +
9010 +#define vx_ipcmsg_sub(v, u, a) \
9011 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9012 +
9013 +#define vx_ipcmsg_avail(v, a) \
9014 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9015 +
9016 +
9017 +#define vx_ipcshm_add(v, k, a) \
9018 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9019 +
9020 +#define vx_ipcshm_sub(v, k, a) \
9021 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9022 +
9023 +#define vx_ipcshm_avail(v, a) \
9024 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
9025 +
9026 +
9027 +#define vx_semary_inc(a) \
9028 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9029 +
9030 +#define vx_semary_dec(a) \
9031 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9032 +
9033 +
9034 +#define vx_nsems_add(a,n) \
9035 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9036 +
9037 +#define vx_nsems_sub(a,n) \
9038 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9039 +
9040 +
9041 +#else
9042 +#warning duplicate inclusion
9043 +#endif
9044 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
9045 --- linux-3.13.10/include/linux/vs_network.h    1970-01-01 00:00:00.000000000 +0000
9046 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_network.h 2014-01-31 20:38:03.000000000 +0000
9047 @@ -0,0 +1,169 @@
9048 +#ifndef _NX_VS_NETWORK_H
9049 +#define _NX_VS_NETWORK_H
9050 +
9051 +#include "vserver/context.h"
9052 +#include "vserver/network.h"
9053 +#include "vserver/base.h"
9054 +#include "vserver/check.h"
9055 +#include "vserver/debug.h"
9056 +
9057 +#include <linux/sched.h>
9058 +
9059 +
9060 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9061 +
9062 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9063 +       const char *_file, int _line)
9064 +{
9065 +       if (!nxi)
9066 +               return NULL;
9067 +
9068 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9069 +               nxi, nxi ? nxi->nx_id : 0,
9070 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9071 +               _file, _line);
9072 +
9073 +       atomic_inc(&nxi->nx_usecnt);
9074 +       return nxi;
9075 +}
9076 +
9077 +
9078 +extern void free_nx_info(struct nx_info *);
9079 +
9080 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9081 +
9082 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9083 +{
9084 +       if (!nxi)
9085 +               return;
9086 +
9087 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9088 +               nxi, nxi ? nxi->nx_id : 0,
9089 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9090 +               _file, _line);
9091 +
9092 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9093 +               free_nx_info(nxi);
9094 +}
9095 +
9096 +
9097 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9098 +
9099 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9100 +               const char *_file, int _line)
9101 +{
9102 +       if (nxi) {
9103 +               vxlprintk(VXD_CBIT(nid, 3),
9104 +                       "init_nx_info(%p[#%d.%d])",
9105 +                       nxi, nxi ? nxi->nx_id : 0,
9106 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9107 +                       _file, _line);
9108 +
9109 +               atomic_inc(&nxi->nx_usecnt);
9110 +       }
9111 +       *nxp = nxi;
9112 +}
9113 +
9114 +
9115 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9116 +
9117 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9118 +       const char *_file, int _line)
9119 +{
9120 +       struct nx_info *nxo;
9121 +
9122 +       if (!nxi)
9123 +               return;
9124 +
9125 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9126 +               nxi, nxi ? nxi->nx_id : 0,
9127 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9128 +               _file, _line);
9129 +
9130 +       atomic_inc(&nxi->nx_usecnt);
9131 +       nxo = xchg(nxp, nxi);
9132 +       BUG_ON(nxo);
9133 +}
9134 +
9135 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9136 +
9137 +static inline void __clr_nx_info(struct nx_info **nxp,
9138 +       const char *_file, int _line)
9139 +{
9140 +       struct nx_info *nxo;
9141 +
9142 +       nxo = xchg(nxp, NULL);
9143 +       if (!nxo)
9144 +               return;
9145 +
9146 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9147 +               nxo, nxo ? nxo->nx_id : 0,
9148 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9149 +               _file, _line);
9150 +
9151 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
9152 +               free_nx_info(nxo);
9153 +}
9154 +
9155 +
9156 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9157 +
9158 +static inline void __claim_nx_info(struct nx_info *nxi,
9159 +       struct task_struct *task, const char *_file, int _line)
9160 +{
9161 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9162 +               nxi, nxi ? nxi->nx_id : 0,
9163 +               nxi?atomic_read(&nxi->nx_usecnt):0,
9164 +               nxi?atomic_read(&nxi->nx_tasks):0,
9165 +               task, _file, _line);
9166 +
9167 +       atomic_inc(&nxi->nx_tasks);
9168 +}
9169 +
9170 +
9171 +extern void unhash_nx_info(struct nx_info *);
9172 +
9173 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9174 +
9175 +static inline void __release_nx_info(struct nx_info *nxi,
9176 +       struct task_struct *task, const char *_file, int _line)
9177 +{
9178 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9179 +               nxi, nxi ? nxi->nx_id : 0,
9180 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9181 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
9182 +               task, _file, _line);
9183 +
9184 +       might_sleep();
9185 +
9186 +       if (atomic_dec_and_test(&nxi->nx_tasks))
9187 +               unhash_nx_info(nxi);
9188 +}
9189 +
9190 +
9191 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
9192 +
9193 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9194 +       const char *_file, int _line)
9195 +{
9196 +       struct nx_info *nxi;
9197 +
9198 +       task_lock(p);
9199 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9200 +               p, _file, _line);
9201 +       nxi = __get_nx_info(p->nx_info, _file, _line);
9202 +       task_unlock(p);
9203 +       return nxi;
9204 +}
9205 +
9206 +
9207 +static inline void exit_nx_info(struct task_struct *p)
9208 +{
9209 +       if (p->nx_info)
9210 +               release_nx_info(p->nx_info, p);
9211 +}
9212 +
9213 +
9214 +#else
9215 +#warning duplicate inclusion
9216 +#endif
9217 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
9218 --- linux-3.13.10/include/linux/vs_pid.h        1970-01-01 00:00:00.000000000 +0000
9219 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_pid.h     2014-01-31 20:38:03.000000000 +0000
9220 @@ -0,0 +1,50 @@
9221 +#ifndef _VS_PID_H
9222 +#define _VS_PID_H
9223 +
9224 +#include "vserver/base.h"
9225 +#include "vserver/check.h"
9226 +#include "vserver/context.h"
9227 +#include "vserver/debug.h"
9228 +#include "vserver/pid.h"
9229 +#include <linux/pid_namespace.h>
9230 +
9231 +
9232 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
9233 +
9234 +static inline
9235 +int vx_proc_task_visible(struct task_struct *task)
9236 +{
9237 +       if ((task->pid == 1) &&
9238 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9239 +               /* show a blend through init */
9240 +               goto visible;
9241 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9242 +               goto visible;
9243 +       return 0;
9244 +visible:
9245 +       return 1;
9246 +}
9247 +
9248 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9249 +
9250 +
9251 +static inline
9252 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9253 +{
9254 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9255 +
9256 +       if (task && !vx_proc_task_visible(task)) {
9257 +               vxdprintk(VXD_CBIT(misc, 6),
9258 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9259 +                       task, task->xid, task->pid,
9260 +                       current, current->xid, current->pid);
9261 +               put_task_struct(task);
9262 +               task = NULL;
9263 +       }
9264 +       return task;
9265 +}
9266 +
9267 +
9268 +#else
9269 +#warning duplicate inclusion
9270 +#endif
9271 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
9272 --- linux-3.13.10/include/linux/vs_sched.h      1970-01-01 00:00:00.000000000 +0000
9273 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_sched.h   2014-01-31 20:38:03.000000000 +0000
9274 @@ -0,0 +1,40 @@
9275 +#ifndef _VS_SCHED_H
9276 +#define _VS_SCHED_H
9277 +
9278 +#include "vserver/base.h"
9279 +#include "vserver/context.h"
9280 +#include "vserver/sched.h"
9281 +
9282 +
9283 +#define MAX_PRIO_BIAS           20
9284 +#define MIN_PRIO_BIAS          -20
9285 +
9286 +static inline
9287 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
9288 +{
9289 +       struct vx_info *vxi = p->vx_info;
9290 +
9291 +       if (vxi)
9292 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
9293 +       return prio;
9294 +}
9295 +
9296 +static inline void vx_account_user(struct vx_info *vxi,
9297 +       cputime_t cputime, int nice)
9298 +{
9299 +       if (!vxi)
9300 +               return;
9301 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
9302 +}
9303 +
9304 +static inline void vx_account_system(struct vx_info *vxi,
9305 +       cputime_t cputime, int idle)
9306 +{
9307 +       if (!vxi)
9308 +               return;
9309 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
9310 +}
9311 +
9312 +#else
9313 +#warning duplicate inclusion
9314 +#endif
9315 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
9316 --- linux-3.13.10/include/linux/vs_socket.h     1970-01-01 00:00:00.000000000 +0000
9317 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_socket.h  2014-01-31 20:38:03.000000000 +0000
9318 @@ -0,0 +1,67 @@
9319 +#ifndef _VS_SOCKET_H
9320 +#define _VS_SOCKET_H
9321 +
9322 +#include "vserver/debug.h"
9323 +#include "vserver/base.h"
9324 +#include "vserver/cacct.h"
9325 +#include "vserver/context.h"
9326 +#include "vserver/tag.h"
9327 +
9328 +
9329 +/* socket accounting */
9330 +
9331 +#include <linux/socket.h>
9332 +
9333 +static inline int vx_sock_type(int family)
9334 +{
9335 +       switch (family) {
9336 +       case PF_UNSPEC:
9337 +               return VXA_SOCK_UNSPEC;
9338 +       case PF_UNIX:
9339 +               return VXA_SOCK_UNIX;
9340 +       case PF_INET:
9341 +               return VXA_SOCK_INET;
9342 +       case PF_INET6:
9343 +               return VXA_SOCK_INET6;
9344 +       case PF_PACKET:
9345 +               return VXA_SOCK_PACKET;
9346 +       default:
9347 +               return VXA_SOCK_OTHER;
9348 +       }
9349 +}
9350 +
9351 +#define vx_acc_sock(v, f, p, s) \
9352 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
9353 +
9354 +static inline void __vx_acc_sock(struct vx_info *vxi,
9355 +       int family, int pos, int size, char *file, int line)
9356 +{
9357 +       if (vxi) {
9358 +               int type = vx_sock_type(family);
9359 +
9360 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
9361 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
9362 +       }
9363 +}
9364 +
9365 +#define vx_sock_recv(sk, s) \
9366 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
9367 +#define vx_sock_send(sk, s) \
9368 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
9369 +#define vx_sock_fail(sk, s) \
9370 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
9371 +
9372 +
9373 +#define sock_vx_init(s) do {           \
9374 +       (s)->sk_xid = 0;                \
9375 +       (s)->sk_vx_info = NULL;         \
9376 +       } while (0)
9377 +
9378 +#define sock_nx_init(s) do {           \
9379 +       (s)->sk_nid = 0;                \
9380 +       (s)->sk_nx_info = NULL;         \
9381 +       } while (0)
9382 +
9383 +#else
9384 +#warning duplicate inclusion
9385 +#endif
9386 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
9387 --- linux-3.13.10/include/linux/vs_tag.h        1970-01-01 00:00:00.000000000 +0000
9388 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_tag.h     2014-01-31 20:38:03.000000000 +0000
9389 @@ -0,0 +1,47 @@
9390 +#ifndef _VS_TAG_H
9391 +#define _VS_TAG_H
9392 +
9393 +#include <linux/vserver/tag.h>
9394 +
9395 +/* check conditions */
9396 +
9397 +#define DX_ADMIN       0x0001
9398 +#define DX_WATCH       0x0002
9399 +#define DX_HOSTID      0x0008
9400 +
9401 +#define DX_IDENT       0x0010
9402 +
9403 +#define DX_ARG_MASK    0x0010
9404 +
9405 +
9406 +#define dx_task_tag(t) ((t)->tag)
9407 +
9408 +#define dx_current_tag() dx_task_tag(current)
9409 +
9410 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
9411 +
9412 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
9413 +
9414 +
9415 +/*
9416 + * check current context for ADMIN/WATCH and
9417 + * optionally against supplied argument
9418 + */
9419 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
9420 +{
9421 +       if (mode & DX_ARG_MASK) {
9422 +               if ((mode & DX_IDENT) && (id == cid))
9423 +                       return 1;
9424 +       }
9425 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
9426 +               ((mode & DX_WATCH) && (cid == 1)) ||
9427 +               ((mode & DX_HOSTID) && (id == 0)));
9428 +}
9429 +
9430 +struct inode;
9431 +int dx_permission(const struct inode *inode, int mask);
9432 +
9433 +
9434 +#else
9435 +#warning duplicate inclusion
9436 +#endif
9437 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
9438 --- linux-3.13.10/include/linux/vs_time.h       1970-01-01 00:00:00.000000000 +0000
9439 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_time.h    2014-01-31 20:38:03.000000000 +0000
9440 @@ -0,0 +1,19 @@
9441 +#ifndef _VS_TIME_H
9442 +#define _VS_TIME_H
9443 +
9444 +
9445 +/* time faking stuff */
9446 +
9447 +#ifdef CONFIG_VSERVER_VTIME
9448 +
9449 +extern void vx_adjust_timespec(struct timespec *ts);
9450 +extern int vx_settimeofday(const struct timespec *ts);
9451 +
9452 +#else
9453 +#define        vx_adjust_timespec(t)   do { } while (0)
9454 +#define        vx_settimeofday(t)      do_settimeofday(t)
9455 +#endif
9456 +
9457 +#else
9458 +#warning duplicate inclusion
9459 +#endif
9460 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
9461 --- linux-3.13.10/include/linux/vserver/base.h  1970-01-01 00:00:00.000000000 +0000
9462 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/base.h       2014-01-31 20:38:03.000000000 +0000
9463 @@ -0,0 +1,184 @@
9464 +#ifndef _VSERVER_BASE_H
9465 +#define _VSERVER_BASE_H
9466 +
9467 +
9468 +/* context state changes */
9469 +
9470 +enum {
9471 +       VSC_STARTUP = 1,
9472 +       VSC_SHUTDOWN,
9473 +
9474 +       VSC_NETUP,
9475 +       VSC_NETDOWN,
9476 +};
9477 +
9478 +
9479 +
9480 +#define vx_task_xid(t) ((t)->xid)
9481 +
9482 +#define vx_current_xid() vx_task_xid(current)
9483 +
9484 +#define current_vx_info() (current->vx_info)
9485 +
9486 +
9487 +#define nx_task_nid(t) ((t)->nid)
9488 +
9489 +#define nx_current_nid() nx_task_nid(current)
9490 +
9491 +#define current_nx_info() (current->nx_info)
9492 +
9493 +
9494 +/* generic flag merging */
9495 +
9496 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
9497 +
9498 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
9499 +
9500 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
9501 +
9502 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
9503 +
9504 +
9505 +/* context flags */
9506 +
9507 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
9508 +
9509 +#define vx_current_flags()     __vx_flags(current_vx_info())
9510 +
9511 +#define vx_info_flags(v, m, f) \
9512 +       vs_check_flags(__vx_flags(v), m, f)
9513 +
9514 +#define task_vx_flags(t, m, f) \
9515 +       ((t) && vx_info_flags((t)->vx_info, m, f))
9516 +
9517 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
9518 +
9519 +
9520 +/* context caps */
9521 +
9522 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
9523 +
9524 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
9525 +
9526 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
9527 +
9528 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
9529 +
9530 +
9531 +
9532 +/* network flags */
9533 +
9534 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
9535 +
9536 +#define nx_current_flags()     __nx_flags(current_nx_info())
9537 +
9538 +#define nx_info_flags(n, m, f) \
9539 +       vs_check_flags(__nx_flags(n), m, f)
9540 +
9541 +#define task_nx_flags(t, m, f) \
9542 +       ((t) && nx_info_flags((t)->nx_info, m, f))
9543 +
9544 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
9545 +
9546 +
9547 +/* network caps */
9548 +
9549 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
9550 +
9551 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
9552 +
9553 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
9554 +
9555 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
9556 +
9557 +
9558 +/* context mask capabilities */
9559 +
9560 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
9561 +
9562 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
9563 +
9564 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
9565 +
9566 +
9567 +/* context bcap mask */
9568 +
9569 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
9570 +
9571 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
9572 +
9573 +
9574 +/* mask given bcaps */
9575 +
9576 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
9577 +
9578 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
9579 +
9580 +
9581 +/* masked cap_bset */
9582 +
9583 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
9584 +
9585 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
9586 +
9587 +#if 0
9588 +#define vx_info_mbcap(v, b) \
9589 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
9590 +       vx_info_bcaps(v, b) : (b))
9591 +
9592 +#define task_vx_mbcap(t, b) \
9593 +       vx_info_mbcap((t)->vx_info, (t)->b)
9594 +
9595 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
9596 +#endif
9597 +
9598 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
9599 +
9600 +#define vx_capable(b, c) (capable(b) || \
9601 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9602 +
9603 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
9604 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9605 +
9606 +#define nx_capable(b, c) (capable(b) || \
9607 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9608 +
9609 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
9610 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9611 +
9612 +#define vx_task_initpid(t, n) \
9613 +       ((t)->vx_info && \
9614 +       ((t)->vx_info->vx_initpid == (n)))
9615 +
9616 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
9617 +
9618 +
9619 +/* context unshare mask */
9620 +
9621 +#define __vx_umask(v)          ((v)->vx_umask)
9622 +
9623 +#define vx_current_umask()     __vx_umask(current_vx_info())
9624 +
9625 +#define vx_can_unshare(b, f) (capable(b) || \
9626 +       (cap_raised(current_cap(), b) && \
9627 +       !((f) & ~vx_current_umask())))
9628 +
9629 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
9630 +       (cap_raised(current_cap(), b) && \
9631 +       !((f) & ~vx_current_umask())))
9632 +
9633 +#define __vx_wmask(v)          ((v)->vx_wmask)
9634 +
9635 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
9636 +
9637 +
9638 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
9639 +
9640 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
9641 +
9642 +
9643 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
9644 +
9645 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
9646 +
9647 +#endif
9648 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
9649 --- linux-3.13.10/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
9650 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct.h      2014-01-31 20:38:03.000000000 +0000
9651 @@ -0,0 +1,15 @@
9652 +#ifndef _VSERVER_CACCT_H
9653 +#define _VSERVER_CACCT_H
9654 +
9655 +
9656 +enum sock_acc_field {
9657 +       VXA_SOCK_UNSPEC = 0,
9658 +       VXA_SOCK_UNIX,
9659 +       VXA_SOCK_INET,
9660 +       VXA_SOCK_INET6,
9661 +       VXA_SOCK_PACKET,
9662 +       VXA_SOCK_OTHER,
9663 +       VXA_SOCK_SIZE   /* array size */
9664 +};
9665 +
9666 +#endif /* _VSERVER_CACCT_H */
9667 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
9668 --- linux-3.13.10/include/linux/vserver/cacct_cmd.h     1970-01-01 00:00:00.000000000 +0000
9669 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_cmd.h  2014-01-31 20:38:03.000000000 +0000
9670 @@ -0,0 +1,10 @@
9671 +#ifndef _VSERVER_CACCT_CMD_H
9672 +#define _VSERVER_CACCT_CMD_H
9673 +
9674 +
9675 +#include <linux/compiler.h>
9676 +#include <uapi/vserver/cacct_cmd.h>
9677 +
9678 +extern int vc_sock_stat(struct vx_info *, void __user *);
9679 +
9680 +#endif /* _VSERVER_CACCT_CMD_H */
9681 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
9682 --- linux-3.13.10/include/linux/vserver/cacct_def.h     1970-01-01 00:00:00.000000000 +0000
9683 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_def.h  2014-01-31 20:38:03.000000000 +0000
9684 @@ -0,0 +1,43 @@
9685 +#ifndef _VSERVER_CACCT_DEF_H
9686 +#define _VSERVER_CACCT_DEF_H
9687 +
9688 +#include <asm/atomic.h>
9689 +#include <linux/vserver/cacct.h>
9690 +
9691 +
9692 +struct _vx_sock_acc {
9693 +       atomic_long_t count;
9694 +       atomic_long_t total;
9695 +};
9696 +
9697 +/* context sub struct */
9698 +
9699 +struct _vx_cacct {
9700 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
9701 +       atomic_t slab[8];
9702 +       atomic_t page[6][8];
9703 +};
9704 +
9705 +#ifdef CONFIG_VSERVER_DEBUG
9706 +
9707 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
9708 +{
9709 +       int i, j;
9710 +
9711 +       printk("\t_vx_cacct:");
9712 +       for (i = 0; i < 6; i++) {
9713 +               struct _vx_sock_acc *ptr = cacct->sock[i];
9714 +
9715 +               printk("\t [%d] =", i);
9716 +               for (j = 0; j < 3; j++) {
9717 +                       printk(" [%d] = %8lu, %8lu", j,
9718 +                               atomic_long_read(&ptr[j].count),
9719 +                               atomic_long_read(&ptr[j].total));
9720 +               }
9721 +               printk("\n");
9722 +       }
9723 +}
9724 +
9725 +#endif
9726 +
9727 +#endif /* _VSERVER_CACCT_DEF_H */
9728 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
9729 --- linux-3.13.10/include/linux/vserver/cacct_int.h     1970-01-01 00:00:00.000000000 +0000
9730 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_int.h  2014-01-31 20:38:03.000000000 +0000
9731 @@ -0,0 +1,17 @@
9732 +#ifndef _VSERVER_CACCT_INT_H
9733 +#define _VSERVER_CACCT_INT_H
9734 +
9735 +static inline
9736 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
9737 +{
9738 +       return atomic_long_read(&cacct->sock[type][pos].count);
9739 +}
9740 +
9741 +
9742 +static inline
9743 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
9744 +{
9745 +       return atomic_long_read(&cacct->sock[type][pos].total);
9746 +}
9747 +
9748 +#endif /* _VSERVER_CACCT_INT_H */
9749 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
9750 --- linux-3.13.10/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
9751 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/check.h      2014-01-31 20:38:03.000000000 +0000
9752 @@ -0,0 +1,89 @@
9753 +#ifndef _VSERVER_CHECK_H
9754 +#define _VSERVER_CHECK_H
9755 +
9756 +
9757 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
9758 +
9759 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
9760 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
9761 +#else
9762 +#define MIN_D_CONTEXT  65536
9763 +#endif
9764 +
9765 +/* check conditions */
9766 +
9767 +#define VS_ADMIN       0x0001
9768 +#define VS_WATCH       0x0002
9769 +#define VS_HIDE                0x0004
9770 +#define VS_HOSTID      0x0008
9771 +
9772 +#define VS_IDENT       0x0010
9773 +#define VS_EQUIV       0x0020
9774 +#define VS_PARENT      0x0040
9775 +#define VS_CHILD       0x0080
9776 +
9777 +#define VS_ARG_MASK    0x00F0
9778 +
9779 +#define VS_DYNAMIC     0x0100
9780 +#define VS_STATIC      0x0200
9781 +
9782 +#define VS_ATR_MASK    0x0F00
9783 +
9784 +#ifdef CONFIG_VSERVER_PRIVACY
9785 +#define VS_ADMIN_P     (0)
9786 +#define VS_WATCH_P     (0)
9787 +#else
9788 +#define VS_ADMIN_P     VS_ADMIN
9789 +#define VS_WATCH_P     VS_WATCH
9790 +#endif
9791 +
9792 +#define VS_HARDIRQ     0x1000
9793 +#define VS_SOFTIRQ     0x2000
9794 +#define VS_IRQ         0x4000
9795 +
9796 +#define VS_IRQ_MASK    0xF000
9797 +
9798 +#include <linux/hardirq.h>
9799 +
9800 +/*
9801 + * check current context for ADMIN/WATCH and
9802 + * optionally against supplied argument
9803 + */
9804 +static inline int __vs_check(int cid, int id, unsigned int mode)
9805 +{
9806 +       if (mode & VS_ARG_MASK) {
9807 +               if ((mode & VS_IDENT) && (id == cid))
9808 +                       return 1;
9809 +       }
9810 +       if (mode & VS_ATR_MASK) {
9811 +               if ((mode & VS_DYNAMIC) &&
9812 +                       (id >= MIN_D_CONTEXT) &&
9813 +                       (id <= MAX_S_CONTEXT))
9814 +                       return 1;
9815 +               if ((mode & VS_STATIC) &&
9816 +                       (id > 1) && (id < MIN_D_CONTEXT))
9817 +                       return 1;
9818 +       }
9819 +       if (mode & VS_IRQ_MASK) {
9820 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
9821 +                       return 1;
9822 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
9823 +                       return 1;
9824 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
9825 +                       return 1;
9826 +       }
9827 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
9828 +               ((mode & VS_WATCH) && (cid == 1)) ||
9829 +               ((mode & VS_HOSTID) && (id == 0)));
9830 +}
9831 +
9832 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
9833 +
9834 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
9835 +
9836 +
9837 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
9838 +
9839 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
9840 +
9841 +#endif
9842 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
9843 --- linux-3.13.10/include/linux/vserver/context.h       1970-01-01 00:00:00.000000000 +0000
9844 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/context.h    2014-01-31 20:38:03.000000000 +0000
9845 @@ -0,0 +1,110 @@
9846 +#ifndef _VSERVER_CONTEXT_H
9847 +#define _VSERVER_CONTEXT_H
9848 +
9849 +
9850 +#include <linux/list.h>
9851 +#include <linux/spinlock.h>
9852 +#include <linux/rcupdate.h>
9853 +#include <uapi/vserver/context.h>
9854 +
9855 +#include "limit_def.h"
9856 +#include "sched_def.h"
9857 +#include "cvirt_def.h"
9858 +#include "cacct_def.h"
9859 +#include "device_def.h"
9860 +
9861 +#define VX_SPACES      2
9862 +
9863 +struct _vx_info_pc {
9864 +       struct _vx_sched_pc sched_pc;
9865 +       struct _vx_cvirt_pc cvirt_pc;
9866 +};
9867 +
9868 +struct _vx_space {
9869 +       unsigned long vx_nsmask;                /* assignment mask */
9870 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
9871 +       struct fs_struct *vx_fs;                /* private namespace fs */
9872 +       const struct cred *vx_cred;             /* task credentials */
9873 +};
9874 +
9875 +struct vx_info {
9876 +       struct hlist_node vx_hlist;             /* linked list of contexts */
9877 +       vxid_t vx_id;                           /* context id */
9878 +       atomic_t vx_usecnt;                     /* usage count */
9879 +       atomic_t vx_tasks;                      /* tasks count */
9880 +       struct vx_info *vx_parent;              /* parent context */
9881 +       int vx_state;                           /* context state */
9882 +
9883 +       struct _vx_space space[VX_SPACES];      /* namespace store */
9884 +
9885 +       uint64_t vx_flags;                      /* context flags */
9886 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
9887 +       uint64_t vx_umask;                      /* unshare mask (guest) */
9888 +       uint64_t vx_wmask;                      /* warn mask (guest) */
9889 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
9890 +
9891 +       struct task_struct *vx_reaper;          /* guest reaper process */
9892 +       pid_t vx_initpid;                       /* PID of guest init */
9893 +       int64_t vx_badness_bias;                /* OOM points bias */
9894 +
9895 +       struct _vx_limit limit;                 /* vserver limits */
9896 +       struct _vx_sched sched;                 /* vserver scheduler */
9897 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
9898 +       struct _vx_cacct cacct;                 /* context accounting */
9899 +
9900 +       struct _vx_device dmap;                 /* default device map targets */
9901 +
9902 +#ifndef CONFIG_SMP
9903 +       struct _vx_info_pc info_pc;             /* per cpu data */
9904 +#else
9905 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
9906 +#endif
9907 +
9908 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
9909 +       int reboot_cmd;                         /* last sys_reboot() cmd */
9910 +       int exit_code;                          /* last process exit code */
9911 +
9912 +       char vx_name[65];                       /* vserver name */
9913 +};
9914 +
9915 +#ifndef CONFIG_SMP
9916 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
9917 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
9918 +#else
9919 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
9920 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
9921 +#endif
9922 +
9923 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
9924 +
9925 +
9926 +struct vx_info_save {
9927 +       struct vx_info *vxi;
9928 +       vxid_t xid;
9929 +};
9930 +
9931 +
9932 +/* status flags */
9933 +
9934 +#define VXS_HASHED     0x0001
9935 +#define VXS_PAUSED     0x0010
9936 +#define VXS_SHUTDOWN   0x0100
9937 +#define VXS_HELPER     0x1000
9938 +#define VXS_RELEASED   0x8000
9939 +
9940 +
9941 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
9942 +extern void release_vx_info(struct vx_info *, struct task_struct *);
9943 +
9944 +extern struct vx_info *lookup_vx_info(int);
9945 +extern struct vx_info *lookup_or_create_vx_info(int);
9946 +
9947 +extern int get_xid_list(int, unsigned int *, int);
9948 +extern int xid_is_hashed(vxid_t);
9949 +
9950 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
9951 +
9952 +extern long vs_state_change(struct vx_info *, unsigned int);
9953 +
9954 +
9955 +#endif /* _VSERVER_CONTEXT_H */
9956 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
9957 --- linux-3.13.10/include/linux/vserver/context_cmd.h   1970-01-01 00:00:00.000000000 +0000
9958 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/context_cmd.h        2014-01-31 20:38:03.000000000 +0000
9959 @@ -0,0 +1,33 @@
9960 +#ifndef _VSERVER_CONTEXT_CMD_H
9961 +#define _VSERVER_CONTEXT_CMD_H
9962 +
9963 +#include <uapi/vserver/context_cmd.h>
9964 +
9965 +extern int vc_task_xid(uint32_t);
9966 +
9967 +extern int vc_vx_info(struct vx_info *, void __user *);
9968 +
9969 +extern int vc_ctx_stat(struct vx_info *, void __user *);
9970 +
9971 +extern int vc_ctx_create(uint32_t, void __user *);
9972 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
9973 +
9974 +extern int vc_get_cflags(struct vx_info *, void __user *);
9975 +extern int vc_set_cflags(struct vx_info *, void __user *);
9976 +
9977 +extern int vc_get_ccaps(struct vx_info *, void __user *);
9978 +extern int vc_set_ccaps(struct vx_info *, void __user *);
9979 +
9980 +extern int vc_get_bcaps(struct vx_info *, void __user *);
9981 +extern int vc_set_bcaps(struct vx_info *, void __user *);
9982 +
9983 +extern int vc_get_umask(struct vx_info *, void __user *);
9984 +extern int vc_set_umask(struct vx_info *, void __user *);
9985 +
9986 +extern int vc_get_wmask(struct vx_info *, void __user *);
9987 +extern int vc_set_wmask(struct vx_info *, void __user *);
9988 +
9989 +extern int vc_get_badness(struct vx_info *, void __user *);
9990 +extern int vc_set_badness(struct vx_info *, void __user *);
9991 +
9992 +#endif /* _VSERVER_CONTEXT_CMD_H */
9993 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
9994 --- linux-3.13.10/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
9995 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt.h      2014-01-31 20:38:03.000000000 +0000
9996 @@ -0,0 +1,18 @@
9997 +#ifndef _VSERVER_CVIRT_H
9998 +#define _VSERVER_CVIRT_H
9999 +
10000 +struct timespec;
10001 +
10002 +void vx_vsi_boottime(struct timespec *);
10003 +
10004 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10005 +
10006 +
10007 +struct vx_info;
10008 +
10009 +void vx_update_load(struct vx_info *);
10010 +
10011 +
10012 +int vx_do_syslog(int, char __user *, int);
10013 +
10014 +#endif /* _VSERVER_CVIRT_H */
10015 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
10016 --- linux-3.13.10/include/linux/vserver/cvirt_cmd.h     1970-01-01 00:00:00.000000000 +0000
10017 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_cmd.h  2014-01-31 20:38:03.000000000 +0000
10018 @@ -0,0 +1,13 @@
10019 +#ifndef _VSERVER_CVIRT_CMD_H
10020 +#define _VSERVER_CVIRT_CMD_H
10021 +
10022 +
10023 +#include <linux/compiler.h>
10024 +#include <uapi/vserver/cvirt_cmd.h>
10025 +
10026 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10027 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10028 +
10029 +extern int vc_virt_stat(struct vx_info *, void __user *);
10030 +
10031 +#endif /* _VSERVER_CVIRT_CMD_H */
10032 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
10033 --- linux-3.13.10/include/linux/vserver/cvirt_def.h     1970-01-01 00:00:00.000000000 +0000
10034 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_def.h  2014-01-31 20:38:03.000000000 +0000
10035 @@ -0,0 +1,80 @@
10036 +#ifndef _VSERVER_CVIRT_DEF_H
10037 +#define _VSERVER_CVIRT_DEF_H
10038 +
10039 +#include <linux/jiffies.h>
10040 +#include <linux/spinlock.h>
10041 +#include <linux/wait.h>
10042 +#include <linux/time.h>
10043 +#include <asm/atomic.h>
10044 +
10045 +
10046 +struct _vx_usage_stat {
10047 +       uint64_t user;
10048 +       uint64_t nice;
10049 +       uint64_t system;
10050 +       uint64_t softirq;
10051 +       uint64_t irq;
10052 +       uint64_t idle;
10053 +       uint64_t iowait;
10054 +};
10055 +
10056 +struct _vx_syslog {
10057 +       wait_queue_head_t log_wait;
10058 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10059 +
10060 +       unsigned long log_start;        /* next char to be read by syslog() */
10061 +       unsigned long con_start;        /* next char to be sent to consoles */
10062 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10063 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10064 +
10065 +       char log_buf[1024];
10066 +};
10067 +
10068 +
10069 +/* context sub struct */
10070 +
10071 +struct _vx_cvirt {
10072 +       atomic_t nr_threads;            /* number of current threads */
10073 +       atomic_t nr_running;            /* number of running threads */
10074 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10075 +
10076 +       atomic_t nr_onhold;             /* processes on hold */
10077 +       uint32_t onhold_last;           /* jiffies when put on hold */
10078 +
10079 +       struct timespec bias_ts;        /* time offset to the host */
10080 +       struct timespec bias_idle;
10081 +       struct timespec bias_uptime;    /* context creation point */
10082 +       uint64_t bias_clock;            /* offset in clock_t */
10083 +
10084 +       spinlock_t load_lock;           /* lock for the load averages */
10085 +       atomic_t load_updates;          /* nr of load updates done so far */
10086 +       uint32_t load_last;             /* last time load was calculated */
10087 +       uint32_t load[3];               /* load averages 1,5,15 */
10088 +
10089 +       atomic_t total_forks;           /* number of forks so far */
10090 +
10091 +       struct _vx_syslog syslog;
10092 +};
10093 +
10094 +struct _vx_cvirt_pc {
10095 +       struct _vx_usage_stat cpustat;
10096 +};
10097 +
10098 +
10099 +#ifdef CONFIG_VSERVER_DEBUG
10100 +
10101 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10102 +{
10103 +       printk("\t_vx_cvirt:\n");
10104 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10105 +               atomic_read(&cvirt->nr_threads),
10106 +               atomic_read(&cvirt->nr_running),
10107 +               atomic_read(&cvirt->nr_uninterruptible),
10108 +               atomic_read(&cvirt->nr_onhold));
10109 +       /* add rest here */
10110 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10111 +}
10112 +
10113 +#endif
10114 +
10115 +#endif /* _VSERVER_CVIRT_DEF_H */
10116 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
10117 --- linux-3.13.10/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
10118 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug.h      2014-01-31 20:38:03.000000000 +0000
10119 @@ -0,0 +1,146 @@
10120 +#ifndef _VSERVER_DEBUG_H
10121 +#define _VSERVER_DEBUG_H
10122 +
10123 +
10124 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10125 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10126 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10127 +
10128 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10129 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10130 +#define VXF_DEV                "%p[%lu,%d:%d]"
10131 +
10132 +#if    defined(CONFIG_QUOTES_UTF8)
10133 +#define        VS_Q_LQM        "\xc2\xbb"
10134 +#define        VS_Q_RQM        "\xc2\xab"
10135 +#elif  defined(CONFIG_QUOTES_ASCII)
10136 +#define        VS_Q_LQM        "\x27"
10137 +#define        VS_Q_RQM        "\x27"
10138 +#else
10139 +#define        VS_Q_LQM        "\xbb"
10140 +#define        VS_Q_RQM        "\xab"
10141 +#endif
10142 +
10143 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
10144 +
10145 +
10146 +#define vxd_path(p)                                            \
10147 +       ({ static char _buffer[PATH_MAX];                       \
10148 +          d_path(p, _buffer, sizeof(_buffer)); })
10149 +
10150 +#define vxd_cond_path(n)                                       \
10151 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10152 +
10153 +
10154 +#ifdef CONFIG_VSERVER_DEBUG
10155 +
10156 +extern unsigned int vs_debug_switch;
10157 +extern unsigned int vs_debug_xid;
10158 +extern unsigned int vs_debug_nid;
10159 +extern unsigned int vs_debug_tag;
10160 +extern unsigned int vs_debug_net;
10161 +extern unsigned int vs_debug_limit;
10162 +extern unsigned int vs_debug_cres;
10163 +extern unsigned int vs_debug_dlim;
10164 +extern unsigned int vs_debug_quota;
10165 +extern unsigned int vs_debug_cvirt;
10166 +extern unsigned int vs_debug_space;
10167 +extern unsigned int vs_debug_perm;
10168 +extern unsigned int vs_debug_misc;
10169 +
10170 +
10171 +#define VX_LOGLEVEL    "vxD: "
10172 +#define VX_PROC_FMT    "%p: "
10173 +#define VX_PROCESS     current
10174 +
10175 +#define vxdprintk(c, f, x...)                                  \
10176 +       do {                                                    \
10177 +               if (c)                                          \
10178 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10179 +                               VX_PROCESS , ##x);              \
10180 +       } while (0)
10181 +
10182 +#define vxlprintk(c, f, x...)                                  \
10183 +       do {                                                    \
10184 +               if (c)                                          \
10185 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10186 +       } while (0)
10187 +
10188 +#define vxfprintk(c, f, x...)                                  \
10189 +       do {                                                    \
10190 +               if (c)                                          \
10191 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10192 +       } while (0)
10193 +
10194 +
10195 +struct vx_info;
10196 +
10197 +void dump_vx_info(struct vx_info *, int);
10198 +void dump_vx_info_inactive(int);
10199 +
10200 +#else  /* CONFIG_VSERVER_DEBUG */
10201 +
10202 +#define vs_debug_switch        0
10203 +#define vs_debug_xid   0
10204 +#define vs_debug_nid   0
10205 +#define vs_debug_tag   0
10206 +#define vs_debug_net   0
10207 +#define vs_debug_limit 0
10208 +#define vs_debug_cres  0
10209 +#define vs_debug_dlim  0
10210 +#define vs_debug_quota 0
10211 +#define vs_debug_cvirt 0
10212 +#define vs_debug_space 0
10213 +#define vs_debug_perm  0
10214 +#define vs_debug_misc  0
10215 +
10216 +#define vxdprintk(x...) do { } while (0)
10217 +#define vxlprintk(x...) do { } while (0)
10218 +#define vxfprintk(x...) do { } while (0)
10219 +
10220 +#endif /* CONFIG_VSERVER_DEBUG */
10221 +
10222 +
10223 +#ifdef CONFIG_VSERVER_WARN
10224 +
10225 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
10226 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10227 +#define VX_WARN_XID    "[xid #%u] "
10228 +#define VX_WARN_NID    "[nid #%u] "
10229 +#define VX_WARN_TAG    "[tag #%u] "
10230 +
10231 +#define vxwprintk(c, f, x...)                                  \
10232 +       do {                                                    \
10233 +               if (c)                                          \
10234 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
10235 +       } while (0)
10236 +
10237 +#else  /* CONFIG_VSERVER_WARN */
10238 +
10239 +#define vxwprintk(x...) do { } while (0)
10240 +
10241 +#endif /* CONFIG_VSERVER_WARN */
10242 +
10243 +#define vxwprintk_task(c, f, x...)                             \
10244 +       vxwprintk(c, VX_WARN_TASK f,                            \
10245 +               current->comm, current->pid,                    \
10246 +               current->xid, current->nid,                     \
10247 +               current->tag, ##x)
10248 +#define vxwprintk_xid(c, f, x...)                              \
10249 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
10250 +#define vxwprintk_nid(c, f, x...)                              \
10251 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
10252 +#define vxwprintk_tag(c, f, x...)                              \
10253 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10254 +
10255 +#ifdef CONFIG_VSERVER_DEBUG
10256 +#define vxd_assert_lock(l)     assert_spin_locked(l)
10257 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10258 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10259 +#else
10260 +#define vxd_assert_lock(l)     do { } while (0)
10261 +#define vxd_assert(c, f, x...) do { } while (0)
10262 +#endif
10263 +
10264 +
10265 +#endif /* _VSERVER_DEBUG_H */
10266 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
10267 --- linux-3.13.10/include/linux/vserver/debug_cmd.h     1970-01-01 00:00:00.000000000 +0000
10268 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug_cmd.h  2014-01-31 20:38:03.000000000 +0000
10269 @@ -0,0 +1,37 @@
10270 +#ifndef _VSERVER_DEBUG_CMD_H
10271 +#define _VSERVER_DEBUG_CMD_H
10272 +
10273 +#include <uapi/vserver/debug_cmd.h>
10274 +
10275 +
10276 +#ifdef CONFIG_COMPAT
10277 +
10278 +#include <asm/compat.h>
10279 +
10280 +struct vcmd_read_history_v0_x32 {
10281 +       uint32_t index;
10282 +       uint32_t count;
10283 +       compat_uptr_t data_ptr;
10284 +};
10285 +
10286 +struct vcmd_read_monitor_v0_x32 {
10287 +       uint32_t index;
10288 +       uint32_t count;
10289 +       compat_uptr_t data_ptr;
10290 +};
10291 +
10292 +#endif  /* CONFIG_COMPAT */
10293 +
10294 +extern int vc_dump_history(uint32_t);
10295 +
10296 +extern int vc_read_history(uint32_t, void __user *);
10297 +extern int vc_read_monitor(uint32_t, void __user *);
10298 +
10299 +#ifdef CONFIG_COMPAT
10300 +
10301 +extern int vc_read_history_x32(uint32_t, void __user *);
10302 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10303 +
10304 +#endif  /* CONFIG_COMPAT */
10305 +
10306 +#endif /* _VSERVER_DEBUG_CMD_H */
10307 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
10308 --- linux-3.13.10/include/linux/vserver/device.h        1970-01-01 00:00:00.000000000 +0000
10309 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device.h     2014-01-31 20:38:03.000000000 +0000
10310 @@ -0,0 +1,9 @@
10311 +#ifndef _VSERVER_DEVICE_H
10312 +#define _VSERVER_DEVICE_H
10313 +
10314 +
10315 +#include <uapi/vserver/device.h>
10316 +
10317 +#else  /* _VSERVER_DEVICE_H */
10318 +#warning duplicate inclusion
10319 +#endif /* _VSERVER_DEVICE_H */
10320 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
10321 --- linux-3.13.10/include/linux/vserver/device_cmd.h    1970-01-01 00:00:00.000000000 +0000
10322 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_cmd.h 2014-01-31 20:38:03.000000000 +0000
10323 @@ -0,0 +1,31 @@
10324 +#ifndef _VSERVER_DEVICE_CMD_H
10325 +#define _VSERVER_DEVICE_CMD_H
10326 +
10327 +#include <uapi/vserver/device_cmd.h>
10328 +
10329 +
10330 +#ifdef CONFIG_COMPAT
10331 +
10332 +#include <asm/compat.h>
10333 +
10334 +struct vcmd_set_mapping_v0_x32 {
10335 +       compat_uptr_t device_ptr;
10336 +       compat_uptr_t target_ptr;
10337 +       uint32_t flags;
10338 +};
10339 +
10340 +#endif /* CONFIG_COMPAT */
10341 +
10342 +#include <linux/compiler.h>
10343 +
10344 +extern int vc_set_mapping(struct vx_info *, void __user *);
10345 +extern int vc_unset_mapping(struct vx_info *, void __user *);
10346 +
10347 +#ifdef CONFIG_COMPAT
10348 +
10349 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
10350 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
10351 +
10352 +#endif /* CONFIG_COMPAT */
10353 +
10354 +#endif /* _VSERVER_DEVICE_CMD_H */
10355 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
10356 --- linux-3.13.10/include/linux/vserver/device_def.h    1970-01-01 00:00:00.000000000 +0000
10357 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_def.h 2014-01-31 20:38:03.000000000 +0000
10358 @@ -0,0 +1,17 @@
10359 +#ifndef _VSERVER_DEVICE_DEF_H
10360 +#define _VSERVER_DEVICE_DEF_H
10361 +
10362 +#include <linux/types.h>
10363 +
10364 +struct vx_dmap_target {
10365 +       dev_t target;
10366 +       uint32_t flags;
10367 +};
10368 +
10369 +struct _vx_device {
10370 +#ifdef CONFIG_VSERVER_DEVICE
10371 +       struct vx_dmap_target targets[2];
10372 +#endif
10373 +};
10374 +
10375 +#endif /* _VSERVER_DEVICE_DEF_H */
10376 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
10377 --- linux-3.13.10/include/linux/vserver/dlimit.h        1970-01-01 00:00:00.000000000 +0000
10378 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit.h     2014-01-31 20:38:03.000000000 +0000
10379 @@ -0,0 +1,54 @@
10380 +#ifndef _VSERVER_DLIMIT_H
10381 +#define _VSERVER_DLIMIT_H
10382 +
10383 +#include "switch.h"
10384 +
10385 +
10386 +#ifdef __KERNEL__
10387 +
10388 +/*      keep in sync with CDLIM_INFINITY       */
10389 +
10390 +#define DLIM_INFINITY          (~0ULL)
10391 +
10392 +#include <linux/spinlock.h>
10393 +#include <linux/rcupdate.h>
10394 +
10395 +struct super_block;
10396 +
10397 +struct dl_info {
10398 +       struct hlist_node dl_hlist;             /* linked list of contexts */
10399 +       struct rcu_head dl_rcu;                 /* the rcu head */
10400 +       vtag_t dl_tag;                          /* context tag */
10401 +       atomic_t dl_usecnt;                     /* usage count */
10402 +       atomic_t dl_refcnt;                     /* reference count */
10403 +
10404 +       struct super_block *dl_sb;              /* associated superblock */
10405 +
10406 +       spinlock_t dl_lock;                     /* protect the values */
10407 +
10408 +       unsigned long long dl_space_used;       /* used space in bytes */
10409 +       unsigned long long dl_space_total;      /* maximum space in bytes */
10410 +       unsigned long dl_inodes_used;           /* used inodes */
10411 +       unsigned long dl_inodes_total;          /* maximum inodes */
10412 +
10413 +       unsigned int dl_nrlmult;                /* non root limit mult */
10414 +};
10415 +
10416 +struct rcu_head;
10417 +
10418 +extern void rcu_free_dl_info(struct rcu_head *);
10419 +extern void unhash_dl_info(struct dl_info *);
10420 +
10421 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
10422 +
10423 +
10424 +struct kstatfs;
10425 +
10426 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
10427 +
10428 +typedef uint64_t dlsize_t;
10429 +
10430 +#endif /* __KERNEL__ */
10431 +#else  /* _VSERVER_DLIMIT_H */
10432 +#warning duplicate inclusion
10433 +#endif /* _VSERVER_DLIMIT_H */
10434 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
10435 --- linux-3.13.10/include/linux/vserver/dlimit_cmd.h    1970-01-01 00:00:00.000000000 +0000
10436 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit_cmd.h 2014-01-31 20:38:03.000000000 +0000
10437 @@ -0,0 +1,46 @@
10438 +#ifndef _VSERVER_DLIMIT_CMD_H
10439 +#define _VSERVER_DLIMIT_CMD_H
10440 +
10441 +#include <uapi/vserver/dlimit_cmd.h>
10442 +
10443 +
10444 +#ifdef CONFIG_COMPAT
10445 +
10446 +#include <asm/compat.h>
10447 +
10448 +struct vcmd_ctx_dlimit_base_v0_x32 {
10449 +       compat_uptr_t name_ptr;
10450 +       uint32_t flags;
10451 +};
10452 +
10453 +struct vcmd_ctx_dlimit_v0_x32 {
10454 +       compat_uptr_t name_ptr;
10455 +       uint32_t space_used;                    /* used space in kbytes */
10456 +       uint32_t space_total;                   /* maximum space in kbytes */
10457 +       uint32_t inodes_used;                   /* used inodes */
10458 +       uint32_t inodes_total;                  /* maximum inodes */
10459 +       uint32_t reserved;                      /* reserved for root in % */
10460 +       uint32_t flags;
10461 +};
10462 +
10463 +#endif /* CONFIG_COMPAT */
10464 +
10465 +#include <linux/compiler.h>
10466 +
10467 +extern int vc_add_dlimit(uint32_t, void __user *);
10468 +extern int vc_rem_dlimit(uint32_t, void __user *);
10469 +
10470 +extern int vc_set_dlimit(uint32_t, void __user *);
10471 +extern int vc_get_dlimit(uint32_t, void __user *);
10472 +
10473 +#ifdef CONFIG_COMPAT
10474 +
10475 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
10476 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
10477 +
10478 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
10479 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
10480 +
10481 +#endif /* CONFIG_COMPAT */
10482 +
10483 +#endif /* _VSERVER_DLIMIT_CMD_H */
10484 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
10485 --- linux-3.13.10/include/linux/vserver/global.h        1970-01-01 00:00:00.000000000 +0000
10486 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/global.h     2014-01-31 20:38:03.000000000 +0000
10487 @@ -0,0 +1,19 @@
10488 +#ifndef _VSERVER_GLOBAL_H
10489 +#define _VSERVER_GLOBAL_H
10490 +
10491 +
10492 +extern atomic_t vx_global_ctotal;
10493 +extern atomic_t vx_global_cactive;
10494 +
10495 +extern atomic_t nx_global_ctotal;
10496 +extern atomic_t nx_global_cactive;
10497 +
10498 +extern atomic_t vs_global_nsproxy;
10499 +extern atomic_t vs_global_fs;
10500 +extern atomic_t vs_global_mnt_ns;
10501 +extern atomic_t vs_global_uts_ns;
10502 +extern atomic_t vs_global_user_ns;
10503 +extern atomic_t vs_global_pid_ns;
10504 +
10505 +
10506 +#endif /* _VSERVER_GLOBAL_H */
10507 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
10508 --- linux-3.13.10/include/linux/vserver/history.h       1970-01-01 00:00:00.000000000 +0000
10509 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/history.h    2014-01-31 20:38:03.000000000 +0000
10510 @@ -0,0 +1,197 @@
10511 +#ifndef _VSERVER_HISTORY_H
10512 +#define _VSERVER_HISTORY_H
10513 +
10514 +
10515 +enum {
10516 +       VXH_UNUSED = 0,
10517 +       VXH_THROW_OOPS = 1,
10518 +
10519 +       VXH_GET_VX_INFO,
10520 +       VXH_PUT_VX_INFO,
10521 +       VXH_INIT_VX_INFO,
10522 +       VXH_SET_VX_INFO,
10523 +       VXH_CLR_VX_INFO,
10524 +       VXH_CLAIM_VX_INFO,
10525 +       VXH_RELEASE_VX_INFO,
10526 +       VXH_ALLOC_VX_INFO,
10527 +       VXH_DEALLOC_VX_INFO,
10528 +       VXH_HASH_VX_INFO,
10529 +       VXH_UNHASH_VX_INFO,
10530 +       VXH_LOC_VX_INFO,
10531 +       VXH_LOOKUP_VX_INFO,
10532 +       VXH_CREATE_VX_INFO,
10533 +};
10534 +
10535 +struct _vxhe_vxi {
10536 +       struct vx_info *ptr;
10537 +       unsigned xid;
10538 +       unsigned usecnt;
10539 +       unsigned tasks;
10540 +};
10541 +
10542 +struct _vxhe_set_clr {
10543 +       void *data;
10544 +};
10545 +
10546 +struct _vxhe_loc_lookup {
10547 +       unsigned arg;
10548 +};
10549 +
10550 +struct _vx_hist_entry {
10551 +       void *loc;
10552 +       unsigned short seq;
10553 +       unsigned short type;
10554 +       struct _vxhe_vxi vxi;
10555 +       union {
10556 +               struct _vxhe_set_clr sc;
10557 +               struct _vxhe_loc_lookup ll;
10558 +       };
10559 +};
10560 +
10561 +#ifdef CONFIG_VSERVER_HISTORY
10562 +
10563 +extern unsigned volatile int vxh_active;
10564 +
10565 +struct _vx_hist_entry *vxh_advance(void *loc);
10566 +
10567 +
10568 +static inline
10569 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
10570 +{
10571 +       entry->vxi.ptr = vxi;
10572 +       if (vxi) {
10573 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
10574 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
10575 +               entry->vxi.xid = vxi->vx_id;
10576 +       }
10577 +}
10578 +
10579 +
10580 +#define        __HERE__ current_text_addr()
10581 +
10582 +#define __VXH_BODY(__type, __data, __here)     \
10583 +       struct _vx_hist_entry *entry;           \
10584 +                                               \
10585 +       preempt_disable();                      \
10586 +       entry = vxh_advance(__here);            \
10587 +       __data;                                 \
10588 +       entry->type = __type;                   \
10589 +       preempt_enable();
10590 +
10591 +
10592 +       /* pass vxi only */
10593 +
10594 +#define __VXH_SMPL                             \
10595 +       __vxh_copy_vxi(entry, vxi)
10596 +
10597 +static inline
10598 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
10599 +{
10600 +       __VXH_BODY(__type, __VXH_SMPL, __here)
10601 +}
10602 +
10603 +       /* pass vxi and data (void *) */
10604 +
10605 +#define __VXH_DATA                             \
10606 +       __vxh_copy_vxi(entry, vxi);             \
10607 +       entry->sc.data = data
10608 +
10609 +static inline
10610 +void   __vxh_data(struct vx_info *vxi, void *data,
10611 +                       int __type, void *__here)
10612 +{
10613 +       __VXH_BODY(__type, __VXH_DATA, __here)
10614 +}
10615 +
10616 +       /* pass vxi and arg (long) */
10617 +
10618 +#define __VXH_LONG                             \
10619 +       __vxh_copy_vxi(entry, vxi);             \
10620 +       entry->ll.arg = arg
10621 +
10622 +static inline
10623 +void   __vxh_long(struct vx_info *vxi, long arg,
10624 +                       int __type, void *__here)
10625 +{
10626 +       __VXH_BODY(__type, __VXH_LONG, __here)
10627 +}
10628 +
10629 +
10630 +static inline
10631 +void   __vxh_throw_oops(void *__here)
10632 +{
10633 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
10634 +       /* prevent further acquisition */
10635 +       vxh_active = 0;
10636 +}
10637 +
10638 +
10639 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
10640 +
10641 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
10642 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
10643 +
10644 +#define __vxh_init_vx_info(v, d, h) \
10645 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
10646 +#define __vxh_set_vx_info(v, d, h) \
10647 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
10648 +#define __vxh_clr_vx_info(v, d, h) \
10649 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
10650 +
10651 +#define __vxh_claim_vx_info(v, d, h) \
10652 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
10653 +#define __vxh_release_vx_info(v, d, h) \
10654 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
10655 +
10656 +#define vxh_alloc_vx_info(v) \
10657 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
10658 +#define vxh_dealloc_vx_info(v) \
10659 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
10660 +
10661 +#define vxh_hash_vx_info(v) \
10662 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
10663 +#define vxh_unhash_vx_info(v) \
10664 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
10665 +
10666 +#define vxh_loc_vx_info(v, l) \
10667 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
10668 +#define vxh_lookup_vx_info(v, l) \
10669 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
10670 +#define vxh_create_vx_info(v, l) \
10671 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
10672 +
10673 +extern void vxh_dump_history(void);
10674 +
10675 +
10676 +#else  /* CONFIG_VSERVER_HISTORY */
10677 +
10678 +#define        __HERE__        0
10679 +
10680 +#define vxh_throw_oops()               do { } while (0)
10681 +
10682 +#define __vxh_get_vx_info(v, h)                do { } while (0)
10683 +#define __vxh_put_vx_info(v, h)                do { } while (0)
10684 +
10685 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
10686 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
10687 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
10688 +
10689 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
10690 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
10691 +
10692 +#define vxh_alloc_vx_info(v)           do { } while (0)
10693 +#define vxh_dealloc_vx_info(v)         do { } while (0)
10694 +
10695 +#define vxh_hash_vx_info(v)            do { } while (0)
10696 +#define vxh_unhash_vx_info(v)          do { } while (0)
10697 +
10698 +#define vxh_loc_vx_info(v, l)          do { } while (0)
10699 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
10700 +#define vxh_create_vx_info(v, l)       do { } while (0)
10701 +
10702 +#define vxh_dump_history()             do { } while (0)
10703 +
10704 +
10705 +#endif /* CONFIG_VSERVER_HISTORY */
10706 +
10707 +#endif /* _VSERVER_HISTORY_H */
10708 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
10709 --- linux-3.13.10/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
10710 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode.h      2014-01-31 20:38:03.000000000 +0000
10711 @@ -0,0 +1,19 @@
10712 +#ifndef _VSERVER_INODE_H
10713 +#define _VSERVER_INODE_H
10714 +
10715 +#include <uapi/vserver/inode.h>
10716 +
10717 +
10718 +#ifdef CONFIG_VSERVER_PROC_SECURE
10719 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
10720 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10721 +#else
10722 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
10723 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10724 +#endif
10725 +
10726 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
10727 +
10728 +#else  /* _VSERVER_INODE_H */
10729 +#warning duplicate inclusion
10730 +#endif /* _VSERVER_INODE_H */
10731 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
10732 --- linux-3.13.10/include/linux/vserver/inode_cmd.h     1970-01-01 00:00:00.000000000 +0000
10733 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode_cmd.h  2014-01-31 20:38:03.000000000 +0000
10734 @@ -0,0 +1,36 @@
10735 +#ifndef _VSERVER_INODE_CMD_H
10736 +#define _VSERVER_INODE_CMD_H
10737 +
10738 +#include <uapi/vserver/inode_cmd.h>
10739 +
10740 +
10741 +
10742 +#ifdef CONFIG_COMPAT
10743 +
10744 +#include <asm/compat.h>
10745 +
10746 +struct vcmd_ctx_iattr_v1_x32 {
10747 +       compat_uptr_t name_ptr;
10748 +       uint32_t tag;
10749 +       uint32_t flags;
10750 +       uint32_t mask;
10751 +};
10752 +
10753 +#endif /* CONFIG_COMPAT */
10754 +
10755 +#include <linux/compiler.h>
10756 +
10757 +extern int vc_get_iattr(void __user *);
10758 +extern int vc_set_iattr(void __user *);
10759 +
10760 +extern int vc_fget_iattr(uint32_t, void __user *);
10761 +extern int vc_fset_iattr(uint32_t, void __user *);
10762 +
10763 +#ifdef CONFIG_COMPAT
10764 +
10765 +extern int vc_get_iattr_x32(void __user *);
10766 +extern int vc_set_iattr_x32(void __user *);
10767 +
10768 +#endif /* CONFIG_COMPAT */
10769 +
10770 +#endif /* _VSERVER_INODE_CMD_H */
10771 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
10772 --- linux-3.13.10/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
10773 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit.h      2014-01-31 20:38:03.000000000 +0000
10774 @@ -0,0 +1,61 @@
10775 +#ifndef _VSERVER_LIMIT_H
10776 +#define _VSERVER_LIMIT_H
10777 +
10778 +#include <uapi/vserver/limit.h>
10779 +
10780 +
10781 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
10782 +
10783 +/*     keep in sync with CRLIM_INFINITY */
10784 +
10785 +#define        VLIM_INFINITY   (~0ULL)
10786 +
10787 +#include <asm/atomic.h>
10788 +#include <asm/resource.h>
10789 +
10790 +#ifndef RLIM_INFINITY
10791 +#warning RLIM_INFINITY is undefined
10792 +#endif
10793 +
10794 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
10795 +
10796 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
10797 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
10798 +
10799 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
10800 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
10801 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
10802 +
10803 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
10804 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
10805 +
10806 +typedef atomic_long_t rlim_atomic_t;
10807 +typedef unsigned long rlim_t;
10808 +
10809 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
10810 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
10811 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
10812 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
10813 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
10814 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
10815 +
10816 +
10817 +#if    (RLIM_INFINITY == VLIM_INFINITY)
10818 +#define        VX_VLIM(r) ((long long)(long)(r))
10819 +#define        VX_RLIM(v) ((rlim_t)(v))
10820 +#else
10821 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
10822 +               ? VLIM_INFINITY : (long long)(r))
10823 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
10824 +               ? RLIM_INFINITY : (rlim_t)(v))
10825 +#endif
10826 +
10827 +struct sysinfo;
10828 +
10829 +void vx_vsi_meminfo(struct sysinfo *);
10830 +void vx_vsi_swapinfo(struct sysinfo *);
10831 +long vx_vsi_cached(struct sysinfo *);
10832 +
10833 +#define NUM_LIMITS     24
10834 +
10835 +#endif /* _VSERVER_LIMIT_H */
10836 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
10837 --- linux-3.13.10/include/linux/vserver/limit_cmd.h     1970-01-01 00:00:00.000000000 +0000
10838 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_cmd.h  2014-01-31 20:38:03.000000000 +0000
10839 @@ -0,0 +1,35 @@
10840 +#ifndef _VSERVER_LIMIT_CMD_H
10841 +#define _VSERVER_LIMIT_CMD_H
10842 +
10843 +#include <uapi/vserver/limit_cmd.h>
10844 +
10845 +
10846 +#ifdef CONFIG_IA32_EMULATION
10847 +
10848 +struct vcmd_ctx_rlimit_v0_x32 {
10849 +       uint32_t id;
10850 +       uint64_t minimum;
10851 +       uint64_t softlimit;
10852 +       uint64_t maximum;
10853 +} __attribute__ ((packed));
10854 +
10855 +#endif /* CONFIG_IA32_EMULATION */
10856 +
10857 +#include <linux/compiler.h>
10858 +
10859 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
10860 +extern int vc_get_rlimit(struct vx_info *, void __user *);
10861 +extern int vc_set_rlimit(struct vx_info *, void __user *);
10862 +extern int vc_reset_hits(struct vx_info *, void __user *);
10863 +extern int vc_reset_minmax(struct vx_info *, void __user *);
10864 +
10865 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
10866 +
10867 +#ifdef CONFIG_IA32_EMULATION
10868 +
10869 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
10870 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
10871 +
10872 +#endif /* CONFIG_IA32_EMULATION */
10873 +
10874 +#endif /* _VSERVER_LIMIT_CMD_H */
10875 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
10876 --- linux-3.13.10/include/linux/vserver/limit_def.h     1970-01-01 00:00:00.000000000 +0000
10877 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_def.h  2014-01-31 20:38:03.000000000 +0000
10878 @@ -0,0 +1,47 @@
10879 +#ifndef _VSERVER_LIMIT_DEF_H
10880 +#define _VSERVER_LIMIT_DEF_H
10881 +
10882 +#include <asm/atomic.h>
10883 +#include <asm/resource.h>
10884 +
10885 +#include "limit.h"
10886 +
10887 +
10888 +struct _vx_res_limit {
10889 +       rlim_t soft;            /* Context soft limit */
10890 +       rlim_t hard;            /* Context hard limit */
10891 +
10892 +       rlim_atomic_t rcur;     /* Current value */
10893 +       rlim_t rmin;            /* Context minimum */
10894 +       rlim_t rmax;            /* Context maximum */
10895 +
10896 +       atomic_t lhit;          /* Limit hits */
10897 +};
10898 +
10899 +/* context sub struct */
10900 +
10901 +struct _vx_limit {
10902 +       struct _vx_res_limit res[NUM_LIMITS];
10903 +};
10904 +
10905 +#ifdef CONFIG_VSERVER_DEBUG
10906 +
10907 +static inline void __dump_vx_limit(struct _vx_limit *limit)
10908 +{
10909 +       int i;
10910 +
10911 +       printk("\t_vx_limit:");
10912 +       for (i = 0; i < NUM_LIMITS; i++) {
10913 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
10914 +                       i, (unsigned long)__rlim_get(limit, i),
10915 +                       (unsigned long)__rlim_rmin(limit, i),
10916 +                       (unsigned long)__rlim_rmax(limit, i),
10917 +                       (long)__rlim_soft(limit, i),
10918 +                       (long)__rlim_hard(limit, i),
10919 +                       atomic_read(&__rlim_lhit(limit, i)));
10920 +       }
10921 +}
10922 +
10923 +#endif
10924 +
10925 +#endif /* _VSERVER_LIMIT_DEF_H */
10926 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
10927 --- linux-3.13.10/include/linux/vserver/limit_int.h     1970-01-01 00:00:00.000000000 +0000
10928 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_int.h  2014-01-31 20:38:03.000000000 +0000
10929 @@ -0,0 +1,193 @@
10930 +#ifndef _VSERVER_LIMIT_INT_H
10931 +#define _VSERVER_LIMIT_INT_H
10932 +
10933 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
10934 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
10935 +
10936 +extern const char *vlimit_name[NUM_LIMITS];
10937 +
10938 +static inline void __vx_acc_cres(struct vx_info *vxi,
10939 +       int res, int dir, void *_data, char *_file, int _line)
10940 +{
10941 +       if (VXD_RCRES_COND(res))
10942 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
10943 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10944 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10945 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
10946 +       if (!vxi)
10947 +               return;
10948 +
10949 +       if (dir > 0)
10950 +               __rlim_inc(&vxi->limit, res);
10951 +       else
10952 +               __rlim_dec(&vxi->limit, res);
10953 +}
10954 +
10955 +static inline void __vx_add_cres(struct vx_info *vxi,
10956 +       int res, int amount, void *_data, char *_file, int _line)
10957 +{
10958 +       if (VXD_RCRES_COND(res))
10959 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
10960 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10961 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10962 +                       amount, _data, _file, _line);
10963 +       if (amount == 0)
10964 +               return;
10965 +       if (!vxi)
10966 +               return;
10967 +       __rlim_add(&vxi->limit, res, amount);
10968 +}
10969 +
10970 +static inline
10971 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
10972 +{
10973 +       int cond = (value > __rlim_rmax(limit, res));
10974 +
10975 +       if (cond)
10976 +               __rlim_rmax(limit, res) = value;
10977 +       return cond;
10978 +}
10979 +
10980 +static inline
10981 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
10982 +{
10983 +       int cond = (value < __rlim_rmin(limit, res));
10984 +
10985 +       if (cond)
10986 +               __rlim_rmin(limit, res) = value;
10987 +       return cond;
10988 +}
10989 +
10990 +static inline
10991 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
10992 +{
10993 +       if (!__vx_cres_adjust_max(limit, res, value))
10994 +               __vx_cres_adjust_min(limit, res, value);
10995 +}
10996 +
10997 +
10998 +/*     return values:
10999 +        +1 ... no limit hit
11000 +        -1 ... over soft limit
11001 +         0 ... over hard limit         */
11002 +
11003 +static inline int __vx_cres_avail(struct vx_info *vxi,
11004 +       int res, int num, char *_file, int _line)
11005 +{
11006 +       struct _vx_limit *limit;
11007 +       rlim_t value;
11008 +
11009 +       if (VXD_RLIMIT_COND(res))
11010 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11011 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11012 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11013 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11014 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11015 +                       num, _file, _line);
11016 +       if (!vxi)
11017 +               return 1;
11018 +
11019 +       limit = &vxi->limit;
11020 +       value = __rlim_get(limit, res);
11021 +
11022 +       if (!__vx_cres_adjust_max(limit, res, value))
11023 +               __vx_cres_adjust_min(limit, res, value);
11024 +
11025 +       if (num == 0)
11026 +               return 1;
11027 +
11028 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
11029 +               return -1;
11030 +       if (value + num <= __rlim_soft(limit, res))
11031 +               return -1;
11032 +
11033 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
11034 +               return 1;
11035 +       if (value + num <= __rlim_hard(limit, res))
11036 +               return 1;
11037 +
11038 +       __rlim_hit(limit, res);
11039 +       return 0;
11040 +}
11041 +
11042 +
11043 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11044 +
11045 +static inline
11046 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11047 +{
11048 +       rlim_t value, sum = 0;
11049 +       int res;
11050 +
11051 +       while ((res = *array++)) {
11052 +               value = __rlim_get(limit, res);
11053 +               __vx_cres_fixup(limit, res, value);
11054 +               sum += value;
11055 +       }
11056 +       return sum;
11057 +}
11058 +
11059 +static inline
11060 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11061 +{
11062 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11063 +       int res = *array;
11064 +
11065 +       if (value == __rlim_get(limit, res))
11066 +               return value;
11067 +
11068 +       __rlim_set(limit, res, value);
11069 +       /* now adjust min/max */
11070 +       if (!__vx_cres_adjust_max(limit, res, value))
11071 +               __vx_cres_adjust_min(limit, res, value);
11072 +
11073 +       return value;
11074 +}
11075 +
11076 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11077 +       const int *array, int num, char *_file, int _line)
11078 +{
11079 +       struct _vx_limit *limit;
11080 +       rlim_t value = 0;
11081 +       int res;
11082 +
11083 +       if (num == 0)
11084 +               return 1;
11085 +       if (!vxi)
11086 +               return 1;
11087 +
11088 +       limit = &vxi->limit;
11089 +       res = *array;
11090 +       value = __vx_cres_array_sum(limit, array + 1);
11091 +
11092 +       __rlim_set(limit, res, value);
11093 +       __vx_cres_fixup(limit, res, value);
11094 +
11095 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11096 +}
11097 +
11098 +
11099 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11100 +{
11101 +       rlim_t value;
11102 +       int res;
11103 +
11104 +       /* complex resources first */
11105 +       if ((id < 0) || (id == RLIMIT_RSS))
11106 +               __vx_cres_array_fixup(limit, VLA_RSS);
11107 +
11108 +       for (res = 0; res < NUM_LIMITS; res++) {
11109 +               if ((id > 0) && (res != id))
11110 +                       continue;
11111 +
11112 +               value = __rlim_get(limit, res);
11113 +               __vx_cres_fixup(limit, res, value);
11114 +
11115 +               /* not supposed to happen, maybe warn? */
11116 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11117 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11118 +       }
11119 +}
11120 +
11121 +
11122 +#endif /* _VSERVER_LIMIT_INT_H */
11123 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
11124 --- linux-3.13.10/include/linux/vserver/monitor.h       1970-01-01 00:00:00.000000000 +0000
11125 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/monitor.h    2014-01-31 20:38:03.000000000 +0000
11126 @@ -0,0 +1,6 @@
11127 +#ifndef _VSERVER_MONITOR_H
11128 +#define _VSERVER_MONITOR_H
11129 +
11130 +#include <uapi/vserver/monitor.h>
11131 +
11132 +#endif /* _VSERVER_MONITOR_H */
11133 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
11134 --- linux-3.13.10/include/linux/vserver/network.h       1970-01-01 00:00:00.000000000 +0000
11135 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/network.h    2014-01-31 20:38:03.000000000 +0000
11136 @@ -0,0 +1,76 @@
11137 +#ifndef _VSERVER_NETWORK_H
11138 +#define _VSERVER_NETWORK_H
11139 +
11140 +
11141 +#include <linux/list.h>
11142 +#include <linux/spinlock.h>
11143 +#include <linux/rcupdate.h>
11144 +#include <linux/in.h>
11145 +#include <linux/in6.h>
11146 +#include <asm/atomic.h>
11147 +#include <uapi/vserver/network.h>
11148 +
11149 +struct nx_addr_v4 {
11150 +       struct nx_addr_v4 *next;
11151 +       struct in_addr ip[2];
11152 +       struct in_addr mask;
11153 +       uint16_t type;
11154 +       uint16_t flags;
11155 +};
11156 +
11157 +struct nx_addr_v6 {
11158 +       struct nx_addr_v6 *next;
11159 +       struct in6_addr ip;
11160 +       struct in6_addr mask;
11161 +       uint32_t prefix;
11162 +       uint16_t type;
11163 +       uint16_t flags;
11164 +};
11165 +
11166 +struct nx_info {
11167 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
11168 +       vnid_t nx_id;                   /* vnet id */
11169 +       atomic_t nx_usecnt;             /* usage count */
11170 +       atomic_t nx_tasks;              /* tasks count */
11171 +       int nx_state;                   /* context state */
11172 +
11173 +       uint64_t nx_flags;              /* network flag word */
11174 +       uint64_t nx_ncaps;              /* network capabilities */
11175 +
11176 +       spinlock_t addr_lock;           /* protect address changes */
11177 +       struct in_addr v4_lback;        /* Loopback address */
11178 +       struct in_addr v4_bcast;        /* Broadcast address */
11179 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
11180 +#ifdef CONFIG_IPV6
11181 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
11182 +#endif
11183 +       char nx_name[65];               /* network context name */
11184 +};
11185 +
11186 +
11187 +/* status flags */
11188 +
11189 +#define NXS_HASHED      0x0001
11190 +#define NXS_SHUTDOWN    0x0100
11191 +#define NXS_RELEASED    0x8000
11192 +
11193 +extern struct nx_info *lookup_nx_info(int);
11194 +
11195 +extern int get_nid_list(int, unsigned int *, int);
11196 +extern int nid_is_hashed(vnid_t);
11197 +
11198 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11199 +
11200 +extern long vs_net_change(struct nx_info *, unsigned int);
11201 +
11202 +struct sock;
11203 +
11204 +
11205 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
11206 +#ifdef  CONFIG_IPV6
11207 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
11208 +#else
11209 +#define NX_IPV6(n)     (0)
11210 +#endif
11211 +
11212 +#endif /* _VSERVER_NETWORK_H */
11213 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
11214 --- linux-3.13.10/include/linux/vserver/network_cmd.h   1970-01-01 00:00:00.000000000 +0000
11215 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/network_cmd.h        2014-01-31 20:38:03.000000000 +0000
11216 @@ -0,0 +1,37 @@
11217 +#ifndef _VSERVER_NETWORK_CMD_H
11218 +#define _VSERVER_NETWORK_CMD_H
11219 +
11220 +#include <uapi/vserver/network_cmd.h>
11221 +
11222 +extern int vc_task_nid(uint32_t);
11223 +
11224 +extern int vc_nx_info(struct nx_info *, void __user *);
11225 +
11226 +extern int vc_net_create(uint32_t, void __user *);
11227 +extern int vc_net_migrate(struct nx_info *, void __user *);
11228 +
11229 +extern int vc_net_add(struct nx_info *, void __user *);
11230 +extern int vc_net_remove(struct nx_info *, void __user *);
11231 +
11232 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11233 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11234 +
11235 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11236 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11237 +
11238 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11239 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11240 +
11241 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11242 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11243 +
11244 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11245 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11246 +
11247 +extern int vc_get_nflags(struct nx_info *, void __user *);
11248 +extern int vc_set_nflags(struct nx_info *, void __user *);
11249 +
11250 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11251 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11252 +
11253 +#endif /* _VSERVER_CONTEXT_CMD_H */
11254 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
11255 --- linux-3.13.10/include/linux/vserver/percpu.h        1970-01-01 00:00:00.000000000 +0000
11256 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/percpu.h     2014-01-31 20:38:03.000000000 +0000
11257 @@ -0,0 +1,14 @@
11258 +#ifndef _VSERVER_PERCPU_H
11259 +#define _VSERVER_PERCPU_H
11260 +
11261 +#include "cvirt_def.h"
11262 +#include "sched_def.h"
11263 +
11264 +struct _vx_percpu {
11265 +       struct _vx_cvirt_pc cvirt;
11266 +       struct _vx_sched_pc sched;
11267 +};
11268 +
11269 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
11270 +
11271 +#endif /* _VSERVER_PERCPU_H */
11272 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
11273 --- linux-3.13.10/include/linux/vserver/pid.h   1970-01-01 00:00:00.000000000 +0000
11274 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/pid.h        2014-01-31 20:38:03.000000000 +0000
11275 @@ -0,0 +1,51 @@
11276 +#ifndef _VSERVER_PID_H
11277 +#define _VSERVER_PID_H
11278 +
11279 +/* pid faking stuff */
11280 +
11281 +#define vx_info_map_pid(v, p) \
11282 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
11283 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
11284 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
11285 +#define vx_map_tgid(p) vx_map_pid(p)
11286 +
11287 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
11288 +       const char *func, const char *file, int line)
11289 +{
11290 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11291 +               vxfprintk(VXD_CBIT(cvirt, 2),
11292 +                       "vx_map_tgid: %p/%llx: %d -> %d",
11293 +                       vxi, (long long)vxi->vx_flags, pid,
11294 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
11295 +                       func, file, line);
11296 +               if (pid == 0)
11297 +                       return 0;
11298 +               if (pid == vxi->vx_initpid)
11299 +                       return 1;
11300 +       }
11301 +       return pid;
11302 +}
11303 +
11304 +#define vx_info_rmap_pid(v, p) \
11305 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
11306 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
11307 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
11308 +
11309 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
11310 +       const char *func, const char *file, int line)
11311 +{
11312 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11313 +               vxfprintk(VXD_CBIT(cvirt, 2),
11314 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
11315 +                       vxi, (long long)vxi->vx_flags, pid,
11316 +                       (pid == 1) ? vxi->vx_initpid : pid,
11317 +                       func, file, line);
11318 +               if ((pid == 1) && vxi->vx_initpid)
11319 +                       return vxi->vx_initpid;
11320 +               if (pid == vxi->vx_initpid)
11321 +                       return ~0U;
11322 +       }
11323 +       return pid;
11324 +}
11325 +
11326 +#endif
11327 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
11328 --- linux-3.13.10/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
11329 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched.h      2014-01-31 20:38:03.000000000 +0000
11330 @@ -0,0 +1,23 @@
11331 +#ifndef _VSERVER_SCHED_H
11332 +#define _VSERVER_SCHED_H
11333 +
11334 +
11335 +#ifdef __KERNEL__
11336 +
11337 +struct timespec;
11338 +
11339 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11340 +
11341 +
11342 +struct vx_info;
11343 +
11344 +void vx_update_load(struct vx_info *);
11345 +
11346 +
11347 +void vx_update_sched_param(struct _vx_sched *sched,
11348 +       struct _vx_sched_pc *sched_pc);
11349 +
11350 +#endif /* __KERNEL__ */
11351 +#else  /* _VSERVER_SCHED_H */
11352 +#warning duplicate inclusion
11353 +#endif /* _VSERVER_SCHED_H */
11354 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
11355 --- linux-3.13.10/include/linux/vserver/sched_cmd.h     1970-01-01 00:00:00.000000000 +0000
11356 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_cmd.h  2014-01-31 20:38:03.000000000 +0000
11357 @@ -0,0 +1,11 @@
11358 +#ifndef _VSERVER_SCHED_CMD_H
11359 +#define _VSERVER_SCHED_CMD_H
11360 +
11361 +
11362 +#include <linux/compiler.h>
11363 +#include <uapi/vserver/sched_cmd.h>
11364 +
11365 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
11366 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
11367 +
11368 +#endif /* _VSERVER_SCHED_CMD_H */
11369 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
11370 --- linux-3.13.10/include/linux/vserver/sched_def.h     1970-01-01 00:00:00.000000000 +0000
11371 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_def.h  2014-01-31 20:38:03.000000000 +0000
11372 @@ -0,0 +1,38 @@
11373 +#ifndef _VSERVER_SCHED_DEF_H
11374 +#define _VSERVER_SCHED_DEF_H
11375 +
11376 +#include <linux/spinlock.h>
11377 +#include <linux/jiffies.h>
11378 +#include <linux/cpumask.h>
11379 +#include <asm/atomic.h>
11380 +#include <asm/param.h>
11381 +
11382 +
11383 +/* context sub struct */
11384 +
11385 +struct _vx_sched {
11386 +       int prio_bias;                  /* bias offset for priority */
11387 +
11388 +       cpumask_t update;               /* CPUs which should update */
11389 +};
11390 +
11391 +struct _vx_sched_pc {
11392 +       int prio_bias;                  /* bias offset for priority */
11393 +
11394 +       uint64_t user_ticks;            /* token tick events */
11395 +       uint64_t sys_ticks;             /* token tick events */
11396 +       uint64_t hold_ticks;            /* token ticks paused */
11397 +};
11398 +
11399 +
11400 +#ifdef CONFIG_VSERVER_DEBUG
11401 +
11402 +static inline void __dump_vx_sched(struct _vx_sched *sched)
11403 +{
11404 +       printk("\t_vx_sched:\n");
11405 +       printk("\t priority = %4d\n", sched->prio_bias);
11406 +}
11407 +
11408 +#endif
11409 +
11410 +#endif /* _VSERVER_SCHED_DEF_H */
11411 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
11412 --- linux-3.13.10/include/linux/vserver/signal.h        1970-01-01 00:00:00.000000000 +0000
11413 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal.h     2014-01-31 20:38:03.000000000 +0000
11414 @@ -0,0 +1,14 @@
11415 +#ifndef _VSERVER_SIGNAL_H
11416 +#define _VSERVER_SIGNAL_H
11417 +
11418 +
11419 +#ifdef __KERNEL__
11420 +
11421 +struct vx_info;
11422 +
11423 +int vx_info_kill(struct vx_info *, int, int);
11424 +
11425 +#endif /* __KERNEL__ */
11426 +#else  /* _VSERVER_SIGNAL_H */
11427 +#warning duplicate inclusion
11428 +#endif /* _VSERVER_SIGNAL_H */
11429 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
11430 --- linux-3.13.10/include/linux/vserver/signal_cmd.h    1970-01-01 00:00:00.000000000 +0000
11431 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal_cmd.h 2014-01-31 20:38:03.000000000 +0000
11432 @@ -0,0 +1,14 @@
11433 +#ifndef _VSERVER_SIGNAL_CMD_H
11434 +#define _VSERVER_SIGNAL_CMD_H
11435 +
11436 +#include <uapi/vserver/signal_cmd.h>
11437 +
11438 +
11439 +extern int vc_ctx_kill(struct vx_info *, void __user *);
11440 +extern int vc_wait_exit(struct vx_info *, void __user *);
11441 +
11442 +
11443 +extern int vc_get_pflags(uint32_t pid, void __user *);
11444 +extern int vc_set_pflags(uint32_t pid, void __user *);
11445 +
11446 +#endif /* _VSERVER_SIGNAL_CMD_H */
11447 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
11448 --- linux-3.13.10/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
11449 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/space.h      2014-01-31 20:38:03.000000000 +0000
11450 @@ -0,0 +1,12 @@
11451 +#ifndef _VSERVER_SPACE_H
11452 +#define _VSERVER_SPACE_H
11453 +
11454 +#include <linux/types.h>
11455 +
11456 +struct vx_info;
11457 +
11458 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
11459 +
11460 +#else  /* _VSERVER_SPACE_H */
11461 +#warning duplicate inclusion
11462 +#endif /* _VSERVER_SPACE_H */
11463 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
11464 --- linux-3.13.10/include/linux/vserver/space_cmd.h     1970-01-01 00:00:00.000000000 +0000
11465 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/space_cmd.h  2014-01-31 20:38:03.000000000 +0000
11466 @@ -0,0 +1,13 @@
11467 +#ifndef _VSERVER_SPACE_CMD_H
11468 +#define _VSERVER_SPACE_CMD_H
11469 +
11470 +#include <uapi/vserver/space_cmd.h>
11471 +
11472 +
11473 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
11474 +extern int vc_set_space_v1(struct vx_info *, void __user *);
11475 +extern int vc_enter_space(struct vx_info *, void __user *);
11476 +extern int vc_set_space(struct vx_info *, void __user *);
11477 +extern int vc_get_space_mask(void __user *, int);
11478 +
11479 +#endif /* _VSERVER_SPACE_CMD_H */
11480 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
11481 --- linux-3.13.10/include/linux/vserver/switch.h        1970-01-01 00:00:00.000000000 +0000
11482 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/switch.h     2014-01-31 20:38:03.000000000 +0000
11483 @@ -0,0 +1,8 @@
11484 +#ifndef _VSERVER_SWITCH_H
11485 +#define _VSERVER_SWITCH_H
11486 +
11487 +
11488 +#include <linux/errno.h>
11489 +#include <uapi/vserver/switch.h>
11490 +
11491 +#endif /* _VSERVER_SWITCH_H */
11492 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
11493 --- linux-3.13.10/include/linux/vserver/tag.h   1970-01-01 00:00:00.000000000 +0000
11494 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag.h        2014-01-31 20:38:03.000000000 +0000
11495 @@ -0,0 +1,160 @@
11496 +#ifndef _DX_TAG_H
11497 +#define _DX_TAG_H
11498 +
11499 +#include <linux/types.h>
11500 +#include <linux/uidgid.h>
11501 +
11502 +
11503 +#define DX_TAG(in)     (IS_TAGGED(in))
11504 +
11505 +
11506 +#ifdef CONFIG_TAG_NFSD
11507 +#define DX_TAG_NFSD    1
11508 +#else
11509 +#define DX_TAG_NFSD    0
11510 +#endif
11511 +
11512 +
11513 +#ifdef CONFIG_TAGGING_NONE
11514 +
11515 +#define MAX_UID                0xFFFFFFFF
11516 +#define MAX_GID                0xFFFFFFFF
11517 +
11518 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
11519 +
11520 +#define TAGINO_UID(cond, uid, tag)     (uid)
11521 +#define TAGINO_GID(cond, gid, tag)     (gid)
11522 +
11523 +#endif
11524 +
11525 +
11526 +#ifdef CONFIG_TAGGING_GID16
11527 +
11528 +#define MAX_UID                0xFFFFFFFF
11529 +#define MAX_GID                0x0000FFFF
11530 +
11531 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11532 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
11533 +
11534 +#define TAGINO_UID(cond, uid, tag)     (uid)
11535 +#define TAGINO_GID(cond, gid, tag)     \
11536 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
11537 +
11538 +#endif
11539 +
11540 +
11541 +#ifdef CONFIG_TAGGING_ID24
11542 +
11543 +#define MAX_UID                0x00FFFFFF
11544 +#define MAX_GID                0x00FFFFFF
11545 +
11546 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11547 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
11548 +
11549 +#define TAGINO_UID(cond, uid, tag)     \
11550 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
11551 +#define TAGINO_GID(cond, gid, tag)     \
11552 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
11553 +
11554 +#endif
11555 +
11556 +
11557 +#ifdef CONFIG_TAGGING_UID16
11558 +
11559 +#define MAX_UID                0x0000FFFF
11560 +#define MAX_GID                0xFFFFFFFF
11561 +
11562 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11563 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
11564 +
11565 +#define TAGINO_UID(cond, uid, tag)     \
11566 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
11567 +#define TAGINO_GID(cond, gid, tag)     (gid)
11568 +
11569 +#endif
11570 +
11571 +
11572 +#ifdef CONFIG_TAGGING_INTERN
11573 +
11574 +#define MAX_UID                0xFFFFFFFF
11575 +#define MAX_GID                0xFFFFFFFF
11576 +
11577 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11578 +       ((cond) ? (tag) : 0)
11579 +
11580 +#define TAGINO_UID(cond, uid, tag)     (uid)
11581 +#define TAGINO_GID(cond, gid, tag)     (gid)
11582 +
11583 +#endif
11584 +
11585 +
11586 +#ifndef CONFIG_TAGGING_NONE
11587 +#define dx_current_fstag(sb)   \
11588 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
11589 +#else
11590 +#define dx_current_fstag(sb)   (0)
11591 +#endif
11592 +
11593 +#ifndef CONFIG_TAGGING_INTERN
11594 +#define TAGINO_TAG(cond, tag)  (0)
11595 +#else
11596 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
11597 +#endif
11598 +
11599 +#define TAGINO_KUID(cond, kuid, ktag)  \
11600 +       KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
11601 +#define TAGINO_KGID(cond, kgid, ktag)  \
11602 +       KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
11603 +#define TAGINO_KTAG(cond, ktag)                \
11604 +       KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
11605 +
11606 +
11607 +#define INOTAG_UID(cond, uid, gid)     \
11608 +       ((cond) ? ((uid) & MAX_UID) : (uid))
11609 +#define INOTAG_GID(cond, uid, gid)     \
11610 +       ((cond) ? ((gid) & MAX_GID) : (gid))
11611 +
11612 +#define INOTAG_KUID(cond, kuid, kgid)  \
11613 +       KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11614 +#define INOTAG_KGID(cond, kuid, kgid)  \
11615 +       KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11616 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
11617 +       KTAGT_INIT(INOTAG_TAG(cond, \
11618 +               __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
11619 +
11620 +
11621 +static inline uid_t dx_map_uid(uid_t uid)
11622 +{
11623 +       if ((uid > MAX_UID) && (uid != -1))
11624 +               uid = -2;
11625 +       return (uid & MAX_UID);
11626 +}
11627 +
11628 +static inline gid_t dx_map_gid(gid_t gid)
11629 +{
11630 +       if ((gid > MAX_GID) && (gid != -1))
11631 +               gid = -2;
11632 +       return (gid & MAX_GID);
11633 +}
11634 +
11635 +struct peer_tag {
11636 +       int32_t xid;
11637 +       int32_t nid;
11638 +};
11639 +
11640 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
11641 +
11642 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
11643 +                unsigned long *flags);
11644 +
11645 +#ifdef CONFIG_PROPAGATE
11646 +
11647 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
11648 +
11649 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
11650 +
11651 +#else
11652 +#define dx_propagate_tag(n, i) do { } while (0)
11653 +#endif
11654 +
11655 +#endif /* _DX_TAG_H */
11656 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
11657 --- linux-3.13.10/include/linux/vserver/tag_cmd.h       1970-01-01 00:00:00.000000000 +0000
11658 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag_cmd.h    2014-01-31 20:38:03.000000000 +0000
11659 @@ -0,0 +1,10 @@
11660 +#ifndef _VSERVER_TAG_CMD_H
11661 +#define _VSERVER_TAG_CMD_H
11662 +
11663 +#include <uapi/vserver/tag_cmd.h>
11664 +
11665 +extern int vc_task_tag(uint32_t);
11666 +
11667 +extern int vc_tag_migrate(uint32_t);
11668 +
11669 +#endif /* _VSERVER_TAG_CMD_H */
11670 diff -NurpP --minimal linux-3.13.10/include/net/addrconf.h linux-3.13.10-vs2.3.6.11/include/net/addrconf.h
11671 --- linux-3.13.10/include/net/addrconf.h        2013-11-25 15:47:02.000000000 +0000
11672 +++ linux-3.13.10-vs2.3.6.11/include/net/addrconf.h     2014-01-31 20:39:35.000000000 +0000
11673 @@ -79,7 +79,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
11674  
11675  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dev,
11676                        const struct in6_addr *daddr, unsigned int srcprefs,
11677 -                      struct in6_addr *saddr);
11678 +                      struct in6_addr *saddr, struct nx_info *nxi);
11679  int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
11680                       unsigned char banned_flags);
11681  int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
11682 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
11683 --- linux-3.13.10/include/net/af_unix.h 2013-11-25 15:47:02.000000000 +0000
11684 +++ linux-3.13.10-vs2.3.6.11/include/net/af_unix.h      2014-01-31 20:38:03.000000000 +0000
11685 @@ -4,6 +4,7 @@
11686  #include <linux/socket.h>
11687  #include <linux/un.h>
11688  #include <linux/mutex.h>
11689 +#include <linux/vs_base.h>
11690  #include <net/sock.h>
11691  
11692  void unix_inflight(struct file *fp);
11693 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
11694 --- linux-3.13.10/include/net/inet_timewait_sock.h      2014-01-22 20:39:11.000000000 +0000
11695 +++ linux-3.13.10-vs2.3.6.11/include/net/inet_timewait_sock.h   2014-01-31 20:40:30.000000000 +0000
11696 @@ -121,6 +121,10 @@ struct inet_timewait_sock {
11697  #define tw_v6_rcv_saddr        __tw_common.skc_v6_rcv_saddr
11698  #define tw_dport               __tw_common.skc_dport
11699  #define tw_num                 __tw_common.skc_num
11700 +#define tw_xid                 __tw_common.skc_xid
11701 +#define tw_vx_info             __tw_common.skc_vx_info
11702 +#define tw_nid                 __tw_common.skc_nid
11703 +#define tw_nx_info             __tw_common.skc_nx_info
11704  
11705         int                     tw_timeout;
11706         volatile unsigned char  tw_substate;
11707 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
11708 --- linux-3.13.10/include/net/ip6_route.h       2014-01-22 20:39:11.000000000 +0000
11709 +++ linux-3.13.10-vs2.3.6.11/include/net/ip6_route.h    2014-01-31 20:41:10.000000000 +0000
11710 @@ -90,7 +90,7 @@ int ip6_del_rt(struct rt6_info *);
11711  
11712  int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
11713                         const struct in6_addr *daddr, unsigned int prefs,
11714 -                       struct in6_addr *saddr);
11715 +                       struct in6_addr *saddr, struct nx_info *nxi);
11716  
11717  struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
11718                             const struct in6_addr *saddr, int oif, int flags);
11719 diff -NurpP --minimal linux-3.13.10/include/net/route.h linux-3.13.10-vs2.3.6.11/include/net/route.h
11720 --- linux-3.13.10/include/net/route.h   2014-01-22 20:39:12.000000000 +0000
11721 +++ linux-3.13.10-vs2.3.6.11/include/net/route.h        2014-02-01 12:30:58.000000000 +0000
11722 @@ -203,6 +203,9 @@ static inline void ip_rt_put(struct rtab
11723         dst_release(&rt->dst);
11724  }
11725  
11726 +#include <linux/vs_base.h>
11727 +#include <linux/vs_inet.h>
11728 +
11729  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
11730  
11731  extern const __u8 ip_tos2prio[16];
11732 @@ -252,6 +255,9 @@ static inline void ip_route_connect_init
11733                            protocol, flow_flags, dst, src, dport, sport);
11734  }
11735  
11736 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
11737 +       struct flowi4 *);
11738 +
11739  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
11740                                               __be32 dst, __be32 src, u32 tos,
11741                                               int oif, u8 protocol,
11742 @@ -260,11 +266,25 @@ static inline struct rtable *ip_route_co
11743  {
11744         struct net *net = sock_net(sk);
11745         struct rtable *rt;
11746 +       struct nx_info *nx_info = current_nx_info();
11747  
11748         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
11749                               sport, dport, sk, can_sleep);
11750  
11751 -       if (!dst || !src) {
11752 +       if (sk)
11753 +               nx_info = sk->sk_nx_info;
11754 +
11755 +       vxdprintk(VXD_CBIT(net, 4),
11756 +               "ip_route_connect(%p) %p,%p;%lx",
11757 +               sk, nx_info, sk->sk_socket,
11758 +               (sk->sk_socket?sk->sk_socket->flags:0));
11759 +
11760 +       rt = ip_v4_find_src(net, nx_info, fl4);
11761 +       if (IS_ERR(rt))
11762 +               return rt;
11763 +       ip_rt_put(rt);
11764 +
11765 +       if (!fl4->daddr || !fl4->saddr) {
11766                 rt = __ip_route_output_key(net, fl4);
11767                 if (IS_ERR(rt))
11768                         return rt;
11769 diff -NurpP --minimal linux-3.13.10/include/net/sock.h linux-3.13.10-vs2.3.6.11/include/net/sock.h
11770 --- linux-3.13.10/include/net/sock.h    2014-04-17 01:12:39.000000000 +0000
11771 +++ linux-3.13.10-vs2.3.6.11/include/net/sock.h 2014-04-17 01:17:10.000000000 +0000
11772 @@ -191,6 +191,10 @@ struct sock_common {
11773  #ifdef CONFIG_NET_NS
11774         struct net              *skc_net;
11775  #endif
11776 +       vxid_t                  skc_xid;
11777 +       struct vx_info          *skc_vx_info;
11778 +       vnid_t                  skc_nid;
11779 +       struct nx_info          *skc_nx_info;
11780  
11781  #if IS_ENABLED(CONFIG_IPV6)
11782         struct in6_addr         skc_v6_daddr;
11783 @@ -321,7 +325,11 @@ struct sock {
11784  #define sk_prot                        __sk_common.skc_prot
11785  #define sk_net                 __sk_common.skc_net
11786  #define sk_v6_daddr            __sk_common.skc_v6_daddr
11787 -#define sk_v6_rcv_saddr        __sk_common.skc_v6_rcv_saddr
11788 +#define sk_v6_rcv_saddr                __sk_common.skc_v6_rcv_saddr
11789 +#define sk_xid                 __sk_common.skc_xid
11790 +#define sk_vx_info             __sk_common.skc_vx_info
11791 +#define sk_nid                 __sk_common.skc_nid
11792 +#define sk_nx_info             __sk_common.skc_nx_info
11793  
11794         socket_lock_t           sk_lock;
11795         struct sk_buff_head     sk_receive_queue;
11796 diff -NurpP --minimal linux-3.13.10/include/uapi/Kbuild linux-3.13.10-vs2.3.6.11/include/uapi/Kbuild
11797 --- linux-3.13.10/include/uapi/Kbuild   2012-12-11 03:30:57.000000000 +0000
11798 +++ linux-3.13.10-vs2.3.6.11/include/uapi/Kbuild        2014-01-31 20:38:03.000000000 +0000
11799 @@ -12,3 +12,4 @@ header-y += video/
11800  header-y += drm/
11801  header-y += xen/
11802  header-y += scsi/
11803 +header-y += vserver/
11804 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
11805 --- linux-3.13.10/include/uapi/linux/capability.h       2012-12-11 03:30:57.000000000 +0000
11806 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/capability.h    2014-01-31 20:38:03.000000000 +0000
11807 @@ -259,6 +259,7 @@ struct vfs_cap_data {
11808     arbitrary SCSI commands */
11809  /* Allow setting encryption key on loopback filesystem */
11810  /* Allow setting zone reclaim policy */
11811 +/* Allow the selection of a security context */
11812  
11813  #define CAP_SYS_ADMIN        21
11814  
11815 @@ -345,7 +346,12 @@ struct vfs_cap_data {
11816  
11817  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
11818  
11819 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
11820 +/* Allow context manipulations */
11821 +/* Allow changing context info on files */
11822 +
11823 +#define CAP_CONTEXT         63
11824 +
11825 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
11826  
11827  /*
11828   * Bit location of each capability (used by user-space library and kernel)
11829 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
11830 --- linux-3.13.10/include/uapi/linux/fs.h       2013-11-25 15:47:02.000000000 +0000
11831 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/fs.h    2014-01-31 20:38:03.000000000 +0000
11832 @@ -86,6 +86,9 @@ struct inodes_stat_t {
11833  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
11834  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
11835  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
11836 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
11837 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
11838 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
11839  
11840  /* These sb flags are internal to the kernel */
11841  #define MS_NOSEC       (1<<28)
11842 @@ -191,11 +194,14 @@ struct inodes_stat_t {
11843  #define FS_EXTENT_FL                   0x00080000 /* Extents */
11844  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
11845  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
11846 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
11847  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
11848  
11849 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
11850 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
11851 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
11852 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
11853  
11854 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
11855 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
11856  
11857  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
11858  #define SYNC_FILE_RANGE_WRITE          2
11859 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
11860 --- linux-3.13.10/include/uapi/linux/gfs2_ondisk.h      2012-12-11 03:30:57.000000000 +0000
11861 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/gfs2_ondisk.h   2014-01-31 20:38:03.000000000 +0000
11862 @@ -225,6 +225,9 @@ enum {
11863         gfs2fl_Sync             = 8,
11864         gfs2fl_System           = 9,
11865         gfs2fl_TopLevel         = 10,
11866 +       gfs2fl_IXUnlink         = 16,
11867 +       gfs2fl_Barrier          = 17,
11868 +       gfs2fl_Cow              = 18,
11869         gfs2fl_TruncInProg      = 29,
11870         gfs2fl_InheritDirectio  = 30,
11871         gfs2fl_InheritJdata     = 31,
11872 @@ -242,6 +245,9 @@ enum {
11873  #define GFS2_DIF_SYNC                  0x00000100
11874  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
11875  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
11876 +#define GFS2_DIF_IXUNLINK               0x00010000
11877 +#define GFS2_DIF_BARRIER                0x00020000
11878 +#define GFS2_DIF_COW                    0x00040000
11879  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
11880  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
11881  #define GFS2_DIF_INHERIT_JDATA         0x80000000
11882 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
11883 --- linux-3.13.10/include/uapi/linux/if_tun.h   2013-11-25 15:47:02.000000000 +0000
11884 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/if_tun.h        2014-01-31 20:45:49.000000000 +0000
11885 @@ -58,6 +58,7 @@
11886  #define TUNSETQUEUE  _IOW('T', 217, int)
11887  #define TUNSETIFINDEX  _IOW('T', 218, unsigned int)
11888  #define TUNGETFILTER _IOR('T', 219, struct sock_fprog)
11889 +#define TUNSETNID     _IOW('T', 220, int)
11890  
11891  /* TUNSETIFF ifr flags */
11892  #define IFF_TUN                0x0001
11893 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
11894 --- linux-3.13.10/include/uapi/linux/major.h    2014-01-22 20:39:12.000000000 +0000
11895 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/major.h 2014-01-31 20:38:03.000000000 +0000
11896 @@ -15,6 +15,7 @@
11897  #define HD_MAJOR               IDE0_MAJOR
11898  #define PTY_SLAVE_MAJOR                3
11899  #define TTY_MAJOR              4
11900 +#define VROOT_MAJOR            4
11901  #define TTYAUX_MAJOR           5
11902  #define LP_MAJOR               6
11903  #define VCS_MAJOR              7
11904 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
11905 --- linux-3.13.10/include/uapi/linux/nfs_mount.h        2014-01-22 20:39:12.000000000 +0000
11906 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/nfs_mount.h     2014-01-31 20:38:03.000000000 +0000
11907 @@ -63,7 +63,8 @@ struct nfs_mount_data {
11908  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 non-text parsed mount data only */
11909  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
11910  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
11911 -#define NFS_MOUNT_FLAGMASK     0xFFFF
11912 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
11913 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
11914  
11915  /* The following are for internal use only */
11916  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
11917 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
11918 --- linux-3.13.10/include/uapi/linux/reboot.h   2012-12-11 03:30:57.000000000 +0000
11919 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/reboot.h        2014-01-31 20:38:03.000000000 +0000
11920 @@ -33,7 +33,7 @@
11921  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
11922  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
11923  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
11924 -
11925 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
11926  
11927  
11928  #endif /* _UAPI_LINUX_REBOOT_H */
11929 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
11930 --- linux-3.13.10/include/uapi/linux/sysctl.h   2012-12-11 03:30:57.000000000 +0000
11931 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/sysctl.h        2014-01-31 20:38:03.000000000 +0000
11932 @@ -60,6 +60,7 @@ enum
11933         CTL_ABI=9,              /* Binary emulation */
11934         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
11935         CTL_ARLAN=254,          /* arlan wireless driver */
11936 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
11937         CTL_S390DBF=5677,       /* s390 debug */
11938         CTL_SUNRPC=7249,        /* sunrpc debug */
11939         CTL_PM=9899,            /* frv power management */
11940 @@ -94,6 +95,7 @@ enum
11941  
11942         KERN_PANIC=15,          /* int: panic timeout */
11943         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
11944 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
11945  
11946         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
11947         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
11948 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/Kbuild linux-3.13.10-vs2.3.6.11/include/uapi/vserver/Kbuild
11949 --- linux-3.13.10/include/uapi/vserver/Kbuild   1970-01-01 00:00:00.000000000 +0000
11950 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/Kbuild        2014-01-31 20:38:03.000000000 +0000
11951 @@ -0,0 +1,9 @@
11952 +
11953 +header-y += context_cmd.h network_cmd.h space_cmd.h \
11954 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11955 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11956 +       debug_cmd.h device_cmd.h
11957 +
11958 +header-y += switch.h context.h network.h monitor.h \
11959 +       limit.h inode.h device.h
11960 +
11961 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
11962 --- linux-3.13.10/include/uapi/vserver/cacct_cmd.h      1970-01-01 00:00:00.000000000 +0000
11963 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cacct_cmd.h   2014-01-31 20:38:03.000000000 +0000
11964 @@ -0,0 +1,15 @@
11965 +#ifndef _UAPI_VS_CACCT_CMD_H
11966 +#define _UAPI_VS_CACCT_CMD_H
11967 +
11968 +
11969 +/* virtual host info name commands */
11970 +
11971 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11972 +
11973 +struct vcmd_sock_stat_v0 {
11974 +       uint32_t field;
11975 +       uint32_t count[3];
11976 +       uint64_t total[3];
11977 +};
11978 +
11979 +#endif /* _UAPI_VS_CACCT_CMD_H */
11980 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
11981 --- linux-3.13.10/include/uapi/vserver/context.h        1970-01-01 00:00:00.000000000 +0000
11982 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context.h     2014-01-31 20:38:03.000000000 +0000
11983 @@ -0,0 +1,81 @@
11984 +#ifndef _UAPI_VS_CONTEXT_H
11985 +#define _UAPI_VS_CONTEXT_H
11986 +
11987 +#include <linux/types.h>
11988 +#include <linux/capability.h>
11989 +
11990 +
11991 +/* context flags */
11992 +
11993 +#define VXF_INFO_SCHED         0x00000002
11994 +#define VXF_INFO_NPROC         0x00000004
11995 +#define VXF_INFO_PRIVATE       0x00000008
11996 +
11997 +#define VXF_INFO_INIT          0x00000010
11998 +#define VXF_INFO_HIDE          0x00000020
11999 +#define VXF_INFO_ULIMIT                0x00000040
12000 +#define VXF_INFO_NSPACE                0x00000080
12001 +
12002 +#define VXF_SCHED_HARD         0x00000100
12003 +#define VXF_SCHED_PRIO         0x00000200
12004 +#define VXF_SCHED_PAUSE                0x00000400
12005 +
12006 +#define VXF_VIRT_MEM           0x00010000
12007 +#define VXF_VIRT_UPTIME                0x00020000
12008 +#define VXF_VIRT_CPU           0x00040000
12009 +#define VXF_VIRT_LOAD          0x00080000
12010 +#define VXF_VIRT_TIME          0x00100000
12011 +
12012 +#define VXF_HIDE_MOUNT         0x01000000
12013 +/* was VXF_HIDE_NETIF          0x02000000 */
12014 +#define VXF_HIDE_VINFO         0x04000000
12015 +
12016 +#define VXF_STATE_SETUP                (1ULL << 32)
12017 +#define VXF_STATE_INIT         (1ULL << 33)
12018 +#define VXF_STATE_ADMIN                (1ULL << 34)
12019 +
12020 +#define VXF_SC_HELPER          (1ULL << 36)
12021 +#define VXF_REBOOT_KILL                (1ULL << 37)
12022 +#define VXF_PERSISTENT         (1ULL << 38)
12023 +
12024 +#define VXF_FORK_RSS           (1ULL << 48)
12025 +#define VXF_PROLIFIC           (1ULL << 49)
12026 +
12027 +#define VXF_IGNEG_NICE         (1ULL << 52)
12028 +
12029 +#define VXF_ONE_TIME           (0x0007ULL << 32)
12030 +
12031 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12032 +
12033 +
12034 +/* context migration */
12035 +
12036 +#define VXM_SET_INIT           0x00000001
12037 +#define VXM_SET_REAPER         0x00000002
12038 +
12039 +/* context caps */
12040 +
12041 +#define VXC_SET_UTSNAME                0x00000001
12042 +#define VXC_SET_RLIMIT         0x00000002
12043 +#define VXC_FS_SECURITY                0x00000004
12044 +#define VXC_FS_TRUSTED         0x00000008
12045 +#define VXC_TIOCSTI            0x00000010
12046 +
12047 +/* was VXC_RAW_ICMP            0x00000100 */
12048 +#define VXC_SYSLOG             0x00001000
12049 +#define VXC_OOM_ADJUST         0x00002000
12050 +#define VXC_AUDIT_CONTROL      0x00004000
12051 +
12052 +#define VXC_SECURE_MOUNT       0x00010000
12053 +/* #define VXC_SECURE_REMOUNT  0x00020000 */
12054 +#define VXC_BINARY_MOUNT       0x00040000
12055 +#define VXC_DEV_MOUNT          0x00080000
12056 +
12057 +#define VXC_QUOTA_CTL          0x00100000
12058 +#define VXC_ADMIN_MAPPER       0x00200000
12059 +#define VXC_ADMIN_CLOOP                0x00400000
12060 +
12061 +#define VXC_KTHREAD            0x01000000
12062 +#define VXC_NAMESPACE          0x02000000
12063 +
12064 +#endif /* _UAPI_VS_CONTEXT_H */
12065 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
12066 --- linux-3.13.10/include/uapi/vserver/context_cmd.h    1970-01-01 00:00:00.000000000 +0000
12067 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context_cmd.h 2014-01-31 20:38:03.000000000 +0000
12068 @@ -0,0 +1,115 @@
12069 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12070 +#define _UAPI_VS_CONTEXT_CMD_H
12071 +
12072 +
12073 +/* vinfo commands */
12074 +
12075 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12076 +
12077 +
12078 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12079 +
12080 +struct vcmd_vx_info_v0 {
12081 +       uint32_t xid;
12082 +       uint32_t initpid;
12083 +       /* more to come */
12084 +};
12085 +
12086 +
12087 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12088 +
12089 +struct vcmd_ctx_stat_v0 {
12090 +       uint32_t usecnt;
12091 +       uint32_t tasks;
12092 +       /* more to come */
12093 +};
12094 +
12095 +
12096 +/* context commands */
12097 +
12098 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12099 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12100 +
12101 +struct vcmd_ctx_create {
12102 +       uint64_t flagword;
12103 +};
12104 +
12105 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12106 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12107 +
12108 +struct vcmd_ctx_migrate {
12109 +       uint64_t flagword;
12110 +};
12111 +
12112 +
12113 +
12114 +/* flag commands */
12115 +
12116 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12117 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12118 +
12119 +struct vcmd_ctx_flags_v0 {
12120 +       uint64_t flagword;
12121 +       uint64_t mask;
12122 +};
12123 +
12124 +
12125 +
12126 +/* context caps commands */
12127 +
12128 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12129 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12130 +
12131 +struct vcmd_ctx_caps_v1 {
12132 +       uint64_t ccaps;
12133 +       uint64_t cmask;
12134 +};
12135 +
12136 +
12137 +
12138 +/* bcaps commands */
12139 +
12140 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12141 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12142 +
12143 +struct vcmd_bcaps {
12144 +       uint64_t bcaps;
12145 +       uint64_t bmask;
12146 +};
12147 +
12148 +
12149 +
12150 +/* umask commands */
12151 +
12152 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12153 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12154 +
12155 +struct vcmd_umask {
12156 +       uint64_t umask;
12157 +       uint64_t mask;
12158 +};
12159 +
12160 +
12161 +
12162 +/* wmask commands */
12163 +
12164 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
12165 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
12166 +
12167 +struct vcmd_wmask {
12168 +       uint64_t wmask;
12169 +       uint64_t mask;
12170 +};
12171 +
12172 +
12173 +
12174 +/* OOM badness */
12175 +
12176 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12177 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12178 +
12179 +struct vcmd_badness_v0 {
12180 +       int64_t bias;
12181 +};
12182 +
12183 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12184 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
12185 --- linux-3.13.10/include/uapi/vserver/cvirt_cmd.h      1970-01-01 00:00:00.000000000 +0000
12186 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cvirt_cmd.h   2014-01-31 20:38:03.000000000 +0000
12187 @@ -0,0 +1,41 @@
12188 +#ifndef _UAPI_VS_CVIRT_CMD_H
12189 +#define _UAPI_VS_CVIRT_CMD_H
12190 +
12191 +
12192 +/* virtual host info name commands */
12193 +
12194 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12195 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12196 +
12197 +struct vcmd_vhi_name_v0 {
12198 +       uint32_t field;
12199 +       char name[65];
12200 +};
12201 +
12202 +
12203 +enum vhi_name_field {
12204 +       VHIN_CONTEXT = 0,
12205 +       VHIN_SYSNAME,
12206 +       VHIN_NODENAME,
12207 +       VHIN_RELEASE,
12208 +       VHIN_VERSION,
12209 +       VHIN_MACHINE,
12210 +       VHIN_DOMAINNAME,
12211 +};
12212 +
12213 +
12214 +
12215 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12216 +
12217 +struct vcmd_virt_stat_v0 {
12218 +       uint64_t offset;
12219 +       uint64_t uptime;
12220 +       uint32_t nr_threads;
12221 +       uint32_t nr_running;
12222 +       uint32_t nr_uninterruptible;
12223 +       uint32_t nr_onhold;
12224 +       uint32_t nr_forks;
12225 +       uint32_t load[3];
12226 +};
12227 +
12228 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12229 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
12230 --- linux-3.13.10/include/uapi/vserver/debug_cmd.h      1970-01-01 00:00:00.000000000 +0000
12231 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/debug_cmd.h   2014-01-31 20:38:03.000000000 +0000
12232 @@ -0,0 +1,24 @@
12233 +#ifndef _UAPI_VS_DEBUG_CMD_H
12234 +#define _UAPI_VS_DEBUG_CMD_H
12235 +
12236 +
12237 +/* debug commands */
12238 +
12239 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12240 +
12241 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12242 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12243 +
12244 +struct  vcmd_read_history_v0 {
12245 +       uint32_t index;
12246 +       uint32_t count;
12247 +       char __user *data;
12248 +};
12249 +
12250 +struct  vcmd_read_monitor_v0 {
12251 +       uint32_t index;
12252 +       uint32_t count;
12253 +       char __user *data;
12254 +};
12255 +
12256 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12257 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
12258 --- linux-3.13.10/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
12259 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device.h      2014-01-31 20:38:03.000000000 +0000
12260 @@ -0,0 +1,12 @@
12261 +#ifndef _UAPI_VS_DEVICE_H
12262 +#define _UAPI_VS_DEVICE_H
12263 +
12264 +
12265 +#define DATTR_CREATE   0x00000001
12266 +#define DATTR_OPEN     0x00000002
12267 +
12268 +#define DATTR_REMAP    0x00000010
12269 +
12270 +#define DATTR_MASK     0x00000013
12271 +
12272 +#endif /* _UAPI_VS_DEVICE_H */
12273 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
12274 --- linux-3.13.10/include/uapi/vserver/device_cmd.h     1970-01-01 00:00:00.000000000 +0000
12275 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device_cmd.h  2014-01-31 20:38:03.000000000 +0000
12276 @@ -0,0 +1,16 @@
12277 +#ifndef _UAPI_VS_DEVICE_CMD_H
12278 +#define _UAPI_VS_DEVICE_CMD_H
12279 +
12280 +
12281 +/*  device vserver commands */
12282 +
12283 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12284 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12285 +
12286 +struct vcmd_set_mapping_v0 {
12287 +       const char __user *device;
12288 +       const char __user *target;
12289 +       uint32_t flags;
12290 +};
12291 +
12292 +#endif /* _UAPI_VS_DEVICE_CMD_H */
12293 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
12294 --- linux-3.13.10/include/uapi/vserver/dlimit_cmd.h     1970-01-01 00:00:00.000000000 +0000
12295 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/dlimit_cmd.h  2014-01-31 20:38:03.000000000 +0000
12296 @@ -0,0 +1,67 @@
12297 +#ifndef _UAPI_VS_DLIMIT_CMD_H
12298 +#define _UAPI_VS_DLIMIT_CMD_H
12299 +
12300 +
12301 +/*  dlimit vserver commands */
12302 +
12303 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12304 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12305 +
12306 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12307 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12308 +
12309 +struct vcmd_ctx_dlimit_base_v0 {
12310 +       const char __user *name;
12311 +       uint32_t flags;
12312 +};
12313 +
12314 +struct vcmd_ctx_dlimit_v0 {
12315 +       const char __user *name;
12316 +       uint32_t space_used;                    /* used space in kbytes */
12317 +       uint32_t space_total;                   /* maximum space in kbytes */
12318 +       uint32_t inodes_used;                   /* used inodes */
12319 +       uint32_t inodes_total;                  /* maximum inodes */
12320 +       uint32_t reserved;                      /* reserved for root in % */
12321 +       uint32_t flags;
12322 +};
12323 +
12324 +#define CDLIM_UNSET            ((uint32_t)0UL)
12325 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12326 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12327 +
12328 +#define DLIME_UNIT     0
12329 +#define DLIME_KILO     1
12330 +#define DLIME_MEGA     2
12331 +#define DLIME_GIGA     3
12332 +
12333 +#define DLIMF_SHIFT    0x10
12334 +
12335 +#define DLIMS_USED     0
12336 +#define DLIMS_TOTAL    2
12337 +
12338 +static inline
12339 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12340 +{
12341 +       int exp = (flags & DLIMF_SHIFT) ?
12342 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12343 +       return ((uint64_t)val) << (10 * exp);
12344 +}
12345 +
12346 +static inline
12347 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12348 +{
12349 +       int exp = 0;
12350 +
12351 +       if (*flags & DLIMF_SHIFT) {
12352 +               while (val > (1LL << 32) && (exp < 3)) {
12353 +                       val >>= 10;
12354 +                       exp++;
12355 +               }
12356 +               *flags &= ~(DLIME_GIGA << shift);
12357 +               *flags |= exp << shift;
12358 +       } else
12359 +               val >>= 10;
12360 +       return val;
12361 +}
12362 +
12363 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
12364 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
12365 --- linux-3.13.10/include/uapi/vserver/inode.h  1970-01-01 00:00:00.000000000 +0000
12366 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode.h       2014-01-31 20:38:03.000000000 +0000
12367 @@ -0,0 +1,23 @@
12368 +#ifndef _UAPI_VS_INODE_H
12369 +#define _UAPI_VS_INODE_H
12370 +
12371 +
12372 +#define IATTR_TAG      0x01000000
12373 +
12374 +#define IATTR_ADMIN    0x00000001
12375 +#define IATTR_WATCH    0x00000002
12376 +#define IATTR_HIDE     0x00000004
12377 +#define IATTR_FLAGS    0x00000007
12378 +
12379 +#define IATTR_BARRIER  0x00010000
12380 +#define IATTR_IXUNLINK 0x00020000
12381 +#define IATTR_IMMUTABLE 0x00040000
12382 +#define IATTR_COW      0x00080000
12383 +
12384 +
12385 +/* inode ioctls */
12386 +
12387 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12388 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12389 +
12390 +#endif /* _UAPI_VS_INODE_H */
12391 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
12392 --- linux-3.13.10/include/uapi/vserver/inode_cmd.h      1970-01-01 00:00:00.000000000 +0000
12393 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode_cmd.h   2014-01-31 20:38:03.000000000 +0000
12394 @@ -0,0 +1,26 @@
12395 +#ifndef _UAPI_VS_INODE_CMD_H
12396 +#define _UAPI_VS_INODE_CMD_H
12397 +
12398 +
12399 +/*  inode vserver commands */
12400 +
12401 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12402 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12403 +
12404 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12405 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12406 +
12407 +struct vcmd_ctx_iattr_v1 {
12408 +       const char __user *name;
12409 +       uint32_t tag;
12410 +       uint32_t flags;
12411 +       uint32_t mask;
12412 +};
12413 +
12414 +struct vcmd_ctx_fiattr_v0 {
12415 +       uint32_t tag;
12416 +       uint32_t flags;
12417 +       uint32_t mask;
12418 +};
12419 +
12420 +#endif /* _UAPI_VS_INODE_CMD_H */
12421 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
12422 --- linux-3.13.10/include/uapi/vserver/limit.h  1970-01-01 00:00:00.000000000 +0000
12423 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit.h       2014-01-31 20:38:03.000000000 +0000
12424 @@ -0,0 +1,14 @@
12425 +#ifndef _UAPI_VS_LIMIT_H
12426 +#define _UAPI_VS_LIMIT_H
12427 +
12428 +
12429 +#define VLIMIT_NSOCK   16
12430 +#define VLIMIT_OPENFD  17
12431 +#define VLIMIT_ANON    18
12432 +#define VLIMIT_SHMEM   19
12433 +#define VLIMIT_SEMARY  20
12434 +#define VLIMIT_NSEMS   21
12435 +#define VLIMIT_DENTRY  22
12436 +#define VLIMIT_MAPPED  23
12437 +
12438 +#endif /* _UAPI_VS_LIMIT_H */
12439 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
12440 --- linux-3.13.10/include/uapi/vserver/limit_cmd.h      1970-01-01 00:00:00.000000000 +0000
12441 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit_cmd.h   2014-01-31 20:38:03.000000000 +0000
12442 @@ -0,0 +1,40 @@
12443 +#ifndef _UAPI_VS_LIMIT_CMD_H
12444 +#define _UAPI_VS_LIMIT_CMD_H
12445 +
12446 +
12447 +/*  rlimit vserver commands */
12448 +
12449 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12450 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12451 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12452 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12453 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12454 +
12455 +struct vcmd_ctx_rlimit_v0 {
12456 +       uint32_t id;
12457 +       uint64_t minimum;
12458 +       uint64_t softlimit;
12459 +       uint64_t maximum;
12460 +};
12461 +
12462 +struct vcmd_ctx_rlimit_mask_v0 {
12463 +       uint32_t minimum;
12464 +       uint32_t softlimit;
12465 +       uint32_t maximum;
12466 +};
12467 +
12468 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12469 +
12470 +struct vcmd_rlimit_stat_v0 {
12471 +       uint32_t id;
12472 +       uint32_t hits;
12473 +       uint64_t value;
12474 +       uint64_t minimum;
12475 +       uint64_t maximum;
12476 +};
12477 +
12478 +#define CRLIM_UNSET            (0ULL)
12479 +#define CRLIM_INFINITY         (~0ULL)
12480 +#define CRLIM_KEEP             (~1ULL)
12481 +
12482 +#endif /* _UAPI_VS_LIMIT_CMD_H */
12483 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
12484 --- linux-3.13.10/include/uapi/vserver/monitor.h        1970-01-01 00:00:00.000000000 +0000
12485 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/monitor.h     2014-01-31 20:38:03.000000000 +0000
12486 @@ -0,0 +1,96 @@
12487 +#ifndef _UAPI_VS_MONITOR_H
12488 +#define _UAPI_VS_MONITOR_H
12489 +
12490 +#include <linux/types.h>
12491 +
12492 +
12493 +enum {
12494 +       VXM_UNUSED = 0,
12495 +
12496 +       VXM_SYNC = 0x10,
12497 +
12498 +       VXM_UPDATE = 0x20,
12499 +       VXM_UPDATE_1,
12500 +       VXM_UPDATE_2,
12501 +
12502 +       VXM_RQINFO_1 = 0x24,
12503 +       VXM_RQINFO_2,
12504 +
12505 +       VXM_ACTIVATE = 0x40,
12506 +       VXM_DEACTIVATE,
12507 +       VXM_IDLE,
12508 +
12509 +       VXM_HOLD = 0x44,
12510 +       VXM_UNHOLD,
12511 +
12512 +       VXM_MIGRATE = 0x48,
12513 +       VXM_RESCHED,
12514 +
12515 +       /* all other bits are flags */
12516 +       VXM_SCHED = 0x80,
12517 +};
12518 +
12519 +struct _vxm_update_1 {
12520 +       uint32_t tokens_max;
12521 +       uint32_t fill_rate;
12522 +       uint32_t interval;
12523 +};
12524 +
12525 +struct _vxm_update_2 {
12526 +       uint32_t tokens_min;
12527 +       uint32_t fill_rate;
12528 +       uint32_t interval;
12529 +};
12530 +
12531 +struct _vxm_rqinfo_1 {
12532 +       uint16_t running;
12533 +       uint16_t onhold;
12534 +       uint16_t iowait;
12535 +       uint16_t uintr;
12536 +       uint32_t idle_tokens;
12537 +};
12538 +
12539 +struct _vxm_rqinfo_2 {
12540 +       uint32_t norm_time;
12541 +       uint32_t idle_time;
12542 +       uint32_t idle_skip;
12543 +};
12544 +
12545 +struct _vxm_sched {
12546 +       uint32_t tokens;
12547 +       uint32_t norm_time;
12548 +       uint32_t idle_time;
12549 +};
12550 +
12551 +struct _vxm_task {
12552 +       uint16_t pid;
12553 +       uint16_t state;
12554 +};
12555 +
12556 +struct _vxm_event {
12557 +       uint32_t jif;
12558 +       union {
12559 +               uint32_t seq;
12560 +               uint32_t sec;
12561 +       };
12562 +       union {
12563 +               uint32_t tokens;
12564 +               uint32_t nsec;
12565 +               struct _vxm_task tsk;
12566 +       };
12567 +};
12568 +
12569 +struct _vx_mon_entry {
12570 +       uint16_t type;
12571 +       uint16_t xid;
12572 +       union {
12573 +               struct _vxm_event ev;
12574 +               struct _vxm_sched sd;
12575 +               struct _vxm_update_1 u1;
12576 +               struct _vxm_update_2 u2;
12577 +               struct _vxm_rqinfo_1 q1;
12578 +               struct _vxm_rqinfo_2 q2;
12579 +       };
12580 +};
12581 +
12582 +#endif /* _UAPI_VS_MONITOR_H */
12583 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
12584 --- linux-3.13.10/include/uapi/vserver/network.h        1970-01-01 00:00:00.000000000 +0000
12585 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network.h     2014-01-31 20:38:03.000000000 +0000
12586 @@ -0,0 +1,76 @@
12587 +#ifndef _UAPI_VS_NETWORK_H
12588 +#define _UAPI_VS_NETWORK_H
12589 +
12590 +#include <linux/types.h>
12591 +
12592 +
12593 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12594 +
12595 +
12596 +/* network flags */
12597 +
12598 +#define NXF_INFO_PRIVATE       0x00000008
12599 +
12600 +#define NXF_SINGLE_IP          0x00000100
12601 +#define NXF_LBACK_REMAP                0x00000200
12602 +#define NXF_LBACK_ALLOW                0x00000400
12603 +
12604 +#define NXF_HIDE_NETIF         0x02000000
12605 +#define NXF_HIDE_LBACK         0x04000000
12606 +
12607 +#define NXF_STATE_SETUP                (1ULL << 32)
12608 +#define NXF_STATE_ADMIN                (1ULL << 34)
12609 +
12610 +#define NXF_SC_HELPER          (1ULL << 36)
12611 +#define NXF_PERSISTENT         (1ULL << 38)
12612 +
12613 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12614 +
12615 +
12616 +#define        NXF_INIT_SET            (__nxf_init_set())
12617 +
12618 +static inline uint64_t __nxf_init_set(void) {
12619 +       return    NXF_STATE_ADMIN
12620 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12621 +               | NXF_LBACK_REMAP
12622 +               | NXF_HIDE_LBACK
12623 +#endif
12624 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12625 +               | NXF_SINGLE_IP
12626 +#endif
12627 +               | NXF_HIDE_NETIF;
12628 +}
12629 +
12630 +
12631 +/* network caps */
12632 +
12633 +#define NXC_TUN_CREATE         0x00000001
12634 +
12635 +#define NXC_RAW_ICMP           0x00000100
12636 +
12637 +#define NXC_MULTICAST          0x00001000
12638 +
12639 +
12640 +/* address types */
12641 +
12642 +#define NXA_TYPE_IPV4          0x0001
12643 +#define NXA_TYPE_IPV6          0x0002
12644 +
12645 +#define NXA_TYPE_NONE          0x0000
12646 +#define NXA_TYPE_ANY           0x00FF
12647 +
12648 +#define NXA_TYPE_ADDR          0x0010
12649 +#define NXA_TYPE_MASK          0x0020
12650 +#define NXA_TYPE_RANGE         0x0040
12651 +
12652 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12653 +
12654 +#define NXA_MOD_BCAST          0x0100
12655 +#define NXA_MOD_LBACK          0x0200
12656 +
12657 +#define NXA_LOOPBACK           0x1000
12658 +
12659 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12660 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12661 +
12662 +#endif /* _UAPI_VS_NETWORK_H */
12663 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
12664 --- linux-3.13.10/include/uapi/vserver/network_cmd.h    1970-01-01 00:00:00.000000000 +0000
12665 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network_cmd.h 2014-01-31 20:38:03.000000000 +0000
12666 @@ -0,0 +1,123 @@
12667 +#ifndef _UAPI_VS_NETWORK_CMD_H
12668 +#define _UAPI_VS_NETWORK_CMD_H
12669 +
12670 +
12671 +/* vinfo commands */
12672 +
12673 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12674 +
12675 +
12676 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12677 +
12678 +struct vcmd_nx_info_v0 {
12679 +       uint32_t nid;
12680 +       /* more to come */
12681 +};
12682 +
12683 +
12684 +#include <linux/in.h>
12685 +#include <linux/in6.h>
12686 +
12687 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12688 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12689 +
12690 +struct  vcmd_net_create {
12691 +       uint64_t flagword;
12692 +};
12693 +
12694 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12695 +
12696 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12697 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12698 +
12699 +struct vcmd_net_addr_v0 {
12700 +       uint16_t type;
12701 +       uint16_t count;
12702 +       struct in_addr ip[4];
12703 +       struct in_addr mask[4];
12704 +};
12705 +
12706 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
12707 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
12708 +
12709 +struct vcmd_net_addr_ipv4_v1 {
12710 +       uint16_t type;
12711 +       uint16_t flags;
12712 +       struct in_addr ip;
12713 +       struct in_addr mask;
12714 +};
12715 +
12716 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
12717 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
12718 +
12719 +struct vcmd_net_addr_ipv4_v2 {
12720 +       uint16_t type;
12721 +       uint16_t flags;
12722 +       struct in_addr ip;
12723 +       struct in_addr ip2;
12724 +       struct in_addr mask;
12725 +};
12726 +
12727 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12728 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12729 +
12730 +struct vcmd_net_addr_ipv6_v1 {
12731 +       uint16_t type;
12732 +       uint16_t flags;
12733 +       uint32_t prefix;
12734 +       struct in6_addr ip;
12735 +       struct in6_addr mask;
12736 +};
12737 +
12738 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12739 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12740 +
12741 +struct vcmd_match_ipv4_v0 {
12742 +       uint16_t type;
12743 +       uint16_t flags;
12744 +       uint16_t parent;
12745 +       uint16_t prefix;
12746 +       struct in_addr ip;
12747 +       struct in_addr ip2;
12748 +       struct in_addr mask;
12749 +};
12750 +
12751 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12752 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12753 +
12754 +struct vcmd_match_ipv6_v0 {
12755 +       uint16_t type;
12756 +       uint16_t flags;
12757 +       uint16_t parent;
12758 +       uint16_t prefix;
12759 +       struct in6_addr ip;
12760 +       struct in6_addr ip2;
12761 +       struct in6_addr mask;
12762 +};
12763 +
12764 +
12765 +
12766 +
12767 +/* flag commands */
12768 +
12769 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12770 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12771 +
12772 +struct vcmd_net_flags_v0 {
12773 +       uint64_t flagword;
12774 +       uint64_t mask;
12775 +};
12776 +
12777 +
12778 +
12779 +/* network caps commands */
12780 +
12781 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12782 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12783 +
12784 +struct vcmd_net_caps_v0 {
12785 +       uint64_t ncaps;
12786 +       uint64_t cmask;
12787 +};
12788 +
12789 +#endif /* _UAPI_VS_NETWORK_CMD_H */
12790 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
12791 --- linux-3.13.10/include/uapi/vserver/sched_cmd.h      1970-01-01 00:00:00.000000000 +0000
12792 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/sched_cmd.h   2014-01-31 20:38:03.000000000 +0000
12793 @@ -0,0 +1,13 @@
12794 +#ifndef _UAPI_VS_SCHED_CMD_H
12795 +#define _UAPI_VS_SCHED_CMD_H
12796 +
12797 +
12798 +struct vcmd_prio_bias {
12799 +       int32_t cpu_id;
12800 +       int32_t prio_bias;
12801 +};
12802 +
12803 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
12804 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
12805 +
12806 +#endif /* _UAPI_VS_SCHED_CMD_H */
12807 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
12808 --- linux-3.13.10/include/uapi/vserver/signal_cmd.h     1970-01-01 00:00:00.000000000 +0000
12809 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/signal_cmd.h  2014-01-31 20:38:03.000000000 +0000
12810 @@ -0,0 +1,31 @@
12811 +#ifndef _UAPI_VS_SIGNAL_CMD_H
12812 +#define _UAPI_VS_SIGNAL_CMD_H
12813 +
12814 +
12815 +/*  signalling vserver commands */
12816 +
12817 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12818 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12819 +
12820 +struct vcmd_ctx_kill_v0 {
12821 +       int32_t pid;
12822 +       int32_t sig;
12823 +};
12824 +
12825 +struct vcmd_wait_exit_v0 {
12826 +       int32_t reboot_cmd;
12827 +       int32_t exit_code;
12828 +};
12829 +
12830 +
12831 +/*  process alteration commands */
12832 +
12833 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12834 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12835 +
12836 +struct vcmd_pflags_v0 {
12837 +       uint32_t flagword;
12838 +       uint32_t mask;
12839 +};
12840 +
12841 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
12842 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
12843 --- linux-3.13.10/include/uapi/vserver/space_cmd.h      1970-01-01 00:00:00.000000000 +0000
12844 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/space_cmd.h   2014-01-31 20:38:03.000000000 +0000
12845 @@ -0,0 +1,28 @@
12846 +#ifndef _UAPI_VS_SPACE_CMD_H
12847 +#define _UAPI_VS_SPACE_CMD_H
12848 +
12849 +
12850 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12851 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12852 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12853 +
12854 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12855 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12856 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12857 +
12858 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12859 +
12860 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12861 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12862 +
12863 +
12864 +struct vcmd_space_mask_v1 {
12865 +       uint64_t mask;
12866 +};
12867 +
12868 +struct vcmd_space_mask_v2 {
12869 +       uint64_t mask;
12870 +       uint32_t index;
12871 +};
12872 +
12873 +#endif /* _UAPI_VS_SPACE_CMD_H */
12874 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
12875 --- linux-3.13.10/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12876 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/switch.h      2014-01-31 20:38:03.000000000 +0000
12877 @@ -0,0 +1,90 @@
12878 +#ifndef _UAPI_VS_SWITCH_H
12879 +#define _UAPI_VS_SWITCH_H
12880 +
12881 +#include <linux/types.h>
12882 +
12883 +
12884 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12885 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12886 +#define VC_VERSION(c)          ((c) & 0xFFF)
12887 +
12888 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12889 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12890 +
12891 +/*
12892 +
12893 +  Syscall Matrix V2.8
12894 +
12895 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12896 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12897 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12898 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12899 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
12900 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
12901 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12902 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
12903 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
12904 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12905 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
12906 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
12907 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12908 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
12909 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
12910 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12911 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
12912 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
12913 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12914 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
12915 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
12916 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12917 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
12918 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
12919 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12920 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
12921 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
12922 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12923 +
12924 +*/
12925 +
12926 +#define VC_CAT_VERSION         0
12927 +
12928 +#define VC_CAT_VSETUP          1
12929 +#define VC_CAT_VHOST           2
12930 +
12931 +#define VC_CAT_DEVICE          6
12932 +
12933 +#define VC_CAT_VPROC           9
12934 +#define VC_CAT_PROCALT         10
12935 +#define VC_CAT_PROCMIG         11
12936 +#define VC_CAT_PROCTRL         12
12937 +
12938 +#define VC_CAT_SCHED           14
12939 +#define VC_CAT_MEMCTRL         20
12940 +
12941 +#define VC_CAT_VNET            25
12942 +#define VC_CAT_NETALT          26
12943 +#define VC_CAT_NETMIG          27
12944 +#define VC_CAT_NETCTRL         28
12945 +
12946 +#define VC_CAT_TAGMIG          35
12947 +#define VC_CAT_DLIMIT          36
12948 +#define VC_CAT_INODE           38
12949 +
12950 +#define VC_CAT_VSTAT           40
12951 +#define VC_CAT_VINFO           46
12952 +#define VC_CAT_EVENT           48
12953 +
12954 +#define VC_CAT_FLAGS           52
12955 +#define VC_CAT_VSPACE          54
12956 +#define VC_CAT_DEBUG           56
12957 +#define VC_CAT_RLIMIT          60
12958 +
12959 +#define VC_CAT_SYSTEST         61
12960 +#define VC_CAT_COMPAT          63
12961 +
12962 +/*  query version */
12963 +
12964 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
12965 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
12966 +
12967 +#endif /* _UAPI_VS_SWITCH_H */
12968 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
12969 --- linux-3.13.10/include/uapi/vserver/tag_cmd.h        1970-01-01 00:00:00.000000000 +0000
12970 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/tag_cmd.h     2014-01-31 20:38:03.000000000 +0000
12971 @@ -0,0 +1,14 @@
12972 +#ifndef _UAPI_VS_TAG_CMD_H
12973 +#define _UAPI_VS_TAG_CMD_H
12974 +
12975 +
12976 +/* vinfo commands */
12977 +
12978 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
12979 +
12980 +
12981 +/* context commands */
12982 +
12983 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
12984 +
12985 +#endif /* _UAPI_VS_TAG_CMD_H */
12986 diff -NurpP --minimal linux-3.13.10/init/Kconfig linux-3.13.10-vs2.3.6.11/init/Kconfig
12987 --- linux-3.13.10/init/Kconfig  2014-04-17 01:12:39.000000000 +0000
12988 +++ linux-3.13.10-vs2.3.6.11/init/Kconfig       2014-04-17 01:17:11.000000000 +0000
12989 @@ -855,6 +855,7 @@ config NUMA_BALANCING
12990  menuconfig CGROUPS
12991         boolean "Control Group support"
12992         depends on EVENTFD
12993 +       default y
12994         help
12995           This option adds support for grouping sets of processes together, for
12996           use with process control subsystems such as Cpusets, CFS, memory
12997 @@ -1117,6 +1118,7 @@ config IPC_NS
12998  config USER_NS
12999         bool "User namespace"
13000         select UIDGID_STRICT_TYPE_CHECKS
13001 +       depends on VSERVER_DISABLED
13002  
13003         default n
13004         help
13005 diff -NurpP --minimal linux-3.13.10/init/main.c linux-3.13.10-vs2.3.6.11/init/main.c
13006 --- linux-3.13.10/init/main.c   2014-01-22 20:39:12.000000000 +0000
13007 +++ linux-3.13.10-vs2.3.6.11/init/main.c        2014-01-31 20:38:03.000000000 +0000
13008 @@ -77,6 +77,7 @@
13009  #include <linux/sched_clock.h>
13010  #include <linux/context_tracking.h>
13011  #include <linux/random.h>
13012 +#include <linux/vserver/percpu.h>
13013  
13014  #include <asm/io.h>
13015  #include <asm/bugs.h>
13016 diff -NurpP --minimal linux-3.13.10/ipc/mqueue.c linux-3.13.10-vs2.3.6.11/ipc/mqueue.c
13017 --- linux-3.13.10/ipc/mqueue.c  2014-04-17 01:12:39.000000000 +0000
13018 +++ linux-3.13.10-vs2.3.6.11/ipc/mqueue.c       2014-03-12 15:51:08.000000000 +0000
13019 @@ -35,6 +35,8 @@
13020  #include <linux/ipc_namespace.h>
13021  #include <linux/user_namespace.h>
13022  #include <linux/slab.h>
13023 +#include <linux/vs_context.h>
13024 +#include <linux/vs_limit.h>
13025  
13026  #include <net/sock.h>
13027  #include "util.h"
13028 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13029         struct pid* notify_owner;
13030         struct user_namespace *notify_user_ns;
13031         struct user_struct *user;       /* user who created, for accounting */
13032 +       struct vx_info *vxi;
13033         struct sock *notify_sock;
13034         struct sk_buff *notify_cookie;
13035  
13036 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13037         if (S_ISREG(mode)) {
13038                 struct mqueue_inode_info *info;
13039                 unsigned long mq_bytes, mq_treesize;
13040 +               struct vx_info *vxi = current_vx_info();
13041  
13042                 inode->i_fop = &mqueue_file_operations;
13043                 inode->i_size = FILENT_SIZE;
13044 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13045                 info->notify_user_ns = NULL;
13046                 info->qsize = 0;
13047                 info->user = NULL;      /* set when all is ok */
13048 +               info->vxi = NULL;
13049                 info->msg_tree = RB_ROOT;
13050                 info->node_cache = NULL;
13051                 memset(&info->attr, 0, sizeof(info->attr));
13052 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13053  
13054                 spin_lock(&mq_lock);
13055                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13056 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13057 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13058 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13059                         spin_unlock(&mq_lock);
13060                         /* mqueue_evict_inode() releases info->messages */
13061                         ret = -EMFILE;
13062                         goto out_inode;
13063                 }
13064                 u->mq_bytes += mq_bytes;
13065 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13066                 spin_unlock(&mq_lock);
13067  
13068                 /* all is ok */
13069                 info->user = get_uid(u);
13070 +               info->vxi = get_vx_info(vxi);
13071         } else if (S_ISDIR(mode)) {
13072                 inc_nlink(inode);
13073                 /* Some things misbehave if size == 0 on a directory */
13074 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13075  
13076         user = info->user;
13077         if (user) {
13078 +               struct vx_info *vxi = info->vxi;
13079 +
13080                 spin_lock(&mq_lock);
13081                 user->mq_bytes -= mq_bytes;
13082 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13083                 /*
13084                  * get_ns_from_inode() ensures that the
13085                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13086 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13087                 if (ipc_ns)
13088                         ipc_ns->mq_queues_count--;
13089                 spin_unlock(&mq_lock);
13090 +               put_vx_info(vxi);
13091                 free_uid(user);
13092         }
13093         if (ipc_ns)
13094 diff -NurpP --minimal linux-3.13.10/ipc/msg.c linux-3.13.10-vs2.3.6.11/ipc/msg.c
13095 --- linux-3.13.10/ipc/msg.c     2014-04-17 01:12:39.000000000 +0000
13096 +++ linux-3.13.10-vs2.3.6.11/ipc/msg.c  2014-04-17 01:17:11.000000000 +0000
13097 @@ -37,6 +37,7 @@
13098  #include <linux/rwsem.h>
13099  #include <linux/nsproxy.h>
13100  #include <linux/ipc_namespace.h>
13101 +#include <linux/vs_base.h>
13102  
13103  #include <asm/current.h>
13104  #include <asm/uaccess.h>
13105 @@ -194,6 +195,7 @@ static int newque(struct ipc_namespace *
13106  
13107         msq->q_perm.mode = msgflg & S_IRWXUGO;
13108         msq->q_perm.key = key;
13109 +       msq->q_perm.xid = vx_current_xid();
13110  
13111         msq->q_perm.security = NULL;
13112         retval = security_msg_queue_alloc(msq);
13113 diff -NurpP --minimal linux-3.13.10/ipc/sem.c linux-3.13.10-vs2.3.6.11/ipc/sem.c
13114 --- linux-3.13.10/ipc/sem.c     2013-11-25 15:47:03.000000000 +0000
13115 +++ linux-3.13.10-vs2.3.6.11/ipc/sem.c  2014-01-31 20:38:03.000000000 +0000
13116 @@ -86,6 +86,8 @@
13117  #include <linux/rwsem.h>
13118  #include <linux/nsproxy.h>
13119  #include <linux/ipc_namespace.h>
13120 +#include <linux/vs_base.h>
13121 +#include <linux/vs_limit.h>
13122  
13123  #include <asm/uaccess.h>
13124  #include "util.h"
13125 @@ -500,6 +502,7 @@ static int newary(struct ipc_namespace *
13126  
13127         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13128         sma->sem_perm.key = key;
13129 +       sma->sem_perm.xid = vx_current_xid();
13130  
13131         sma->sem_perm.security = NULL;
13132         retval = security_sem_alloc(sma);
13133 @@ -514,6 +517,9 @@ static int newary(struct ipc_namespace *
13134                 return id;
13135         }
13136         ns->used_sems += nsems;
13137 +       /* FIXME: obsoleted? */
13138 +       vx_semary_inc(sma);
13139 +       vx_nsems_add(sma, nsems);
13140  
13141         sma->sem_base = (struct sem *) &sma[1];
13142  
13143 @@ -1103,6 +1109,9 @@ static void freeary(struct ipc_namespace
13144  
13145         wake_up_sem_queue_do(&tasks);
13146         ns->used_sems -= sma->sem_nsems;
13147 +       /* FIXME: obsoleted? */
13148 +       vx_nsems_sub(sma, sma->sem_nsems);
13149 +       vx_semary_dec(sma);
13150         ipc_rcu_putref(sma, sem_rcu_free);
13151  }
13152  
13153 diff -NurpP --minimal linux-3.13.10/ipc/shm.c linux-3.13.10-vs2.3.6.11/ipc/shm.c
13154 --- linux-3.13.10/ipc/shm.c     2014-01-22 20:39:12.000000000 +0000
13155 +++ linux-3.13.10-vs2.3.6.11/ipc/shm.c  2014-01-31 20:38:03.000000000 +0000
13156 @@ -42,6 +42,8 @@
13157  #include <linux/nsproxy.h>
13158  #include <linux/mount.h>
13159  #include <linux/ipc_namespace.h>
13160 +#include <linux/vs_context.h>
13161 +#include <linux/vs_limit.h>
13162  
13163  #include <asm/uaccess.h>
13164  
13165 @@ -209,10 +211,14 @@ static void shm_open(struct vm_area_stru
13166  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13167  {
13168         struct file *shm_file;
13169 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13170 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13171  
13172         shm_file = shp->shm_file;
13173         shp->shm_file = NULL;
13174 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13175 +       vx_ipcshm_sub(vxi, shp, numpages);
13176 +       ns->shm_tot -= numpages;
13177 +
13178         shm_rmid(ns, shp);
13179         shm_unlock(shp);
13180         if (!is_file_hugepages(shm_file))
13181 @@ -220,6 +226,7 @@ static void shm_destroy(struct ipc_names
13182         else if (shp->mlock_user)
13183                 user_shm_unlock(file_inode(shm_file)->i_size, shp->mlock_user);
13184         fput(shm_file);
13185 +       put_vx_info(vxi);
13186         ipc_rcu_putref(shp, shm_rcu_free);
13187  }
13188  
13189 @@ -497,11 +504,15 @@ static int newseg(struct ipc_namespace *
13190         if (ns->shm_tot + numpages > ns->shm_ctlall)
13191                 return -ENOSPC;
13192  
13193 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13194 +               return -ENOSPC;
13195 +
13196         shp = ipc_rcu_alloc(sizeof(*shp));
13197         if (!shp)
13198                 return -ENOMEM;
13199  
13200         shp->shm_perm.key = key;
13201 +       shp->shm_perm.xid = vx_current_xid();
13202         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13203         shp->mlock_user = NULL;
13204  
13205 @@ -570,6 +581,7 @@ static int newseg(struct ipc_namespace *
13206  
13207         ipc_unlock_object(&shp->shm_perm);
13208         rcu_read_unlock();
13209 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13210         return error;
13211  
13212  no_id:
13213 diff -NurpP --minimal linux-3.13.10/kernel/Makefile linux-3.13.10-vs2.3.6.11/kernel/Makefile
13214 --- linux-3.13.10/kernel/Makefile       2014-01-22 20:39:12.000000000 +0000
13215 +++ linux-3.13.10-vs2.3.6.11/kernel/Makefile    2014-01-31 21:36:22.000000000 +0000
13216 @@ -25,6 +25,7 @@ obj-y += printk/
13217  obj-y += cpu/
13218  obj-y += irq/
13219  obj-y += rcu/
13220 +obj-y += vserver/
13221  
13222  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13223  obj-$(CONFIG_FREEZER) += freezer.o
13224 diff -NurpP --minimal linux-3.13.10/kernel/auditsc.c linux-3.13.10-vs2.3.6.11/kernel/auditsc.c
13225 --- linux-3.13.10/kernel/auditsc.c      2014-04-17 01:12:39.000000000 +0000
13226 +++ linux-3.13.10-vs2.3.6.11/kernel/auditsc.c   2014-04-17 01:17:11.000000000 +0000
13227 @@ -1956,7 +1956,7 @@ static int audit_set_loginuid_perm(kuid_
13228         if (is_audit_feature_set(AUDIT_FEATURE_LOGINUID_IMMUTABLE))
13229                 return -EPERM;
13230         /* it is set, you need permission */
13231 -       if (!capable(CAP_AUDIT_CONTROL))
13232 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13233                 return -EPERM;
13234         /* reject if this is not an unset and we don't allow that */
13235         if (is_audit_feature_set(AUDIT_FEATURE_ONLY_UNSET_LOGINUID) && uid_valid(loginuid))
13236 diff -NurpP --minimal linux-3.13.10/kernel/capability.c linux-3.13.10-vs2.3.6.11/kernel/capability.c
13237 --- linux-3.13.10/kernel/capability.c   2013-11-25 15:47:03.000000000 +0000
13238 +++ linux-3.13.10-vs2.3.6.11/kernel/capability.c        2014-01-31 20:38:03.000000000 +0000
13239 @@ -15,6 +15,7 @@
13240  #include <linux/syscalls.h>
13241  #include <linux/pid_namespace.h>
13242  #include <linux/user_namespace.h>
13243 +#include <linux/vs_context.h>
13244  #include <asm/uaccess.h>
13245  
13246  /*
13247 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13248         return 0;
13249  }
13250  
13251 +
13252  /*
13253   * The only thing that can change the capabilities of the current
13254   * process is the current process. As such, we can't be in this code
13255 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13256         return (ret == 0);
13257  }
13258  
13259 +#include <linux/vserver/base.h>
13260 +
13261  /**
13262   * has_capability_noaudit - Does a task have a capability (unaudited) in the
13263   * initial user ns
13264 diff -NurpP --minimal linux-3.13.10/kernel/compat.c linux-3.13.10-vs2.3.6.11/kernel/compat.c
13265 --- linux-3.13.10/kernel/compat.c       2013-07-14 17:01:34.000000000 +0000
13266 +++ linux-3.13.10-vs2.3.6.11/kernel/compat.c    2014-01-31 20:38:03.000000000 +0000
13267 @@ -27,6 +27,7 @@
13268  #include <linux/times.h>
13269  #include <linux/ptrace.h>
13270  #include <linux/gfp.h>
13271 +#include <linux/vs_time.h>
13272  
13273  #include <asm/uaccess.h>
13274  
13275 @@ -1040,7 +1041,7 @@ asmlinkage long compat_sys_stime(compat_
13276         if (err)
13277                 return err;
13278  
13279 -       do_settimeofday(&tv);
13280 +       vx_settimeofday(&tv);
13281         return 0;
13282  }
13283  
13284 diff -NurpP --minimal linux-3.13.10/kernel/cred.c linux-3.13.10-vs2.3.6.11/kernel/cred.c
13285 --- linux-3.13.10/kernel/cred.c 2013-02-19 13:58:56.000000000 +0000
13286 +++ linux-3.13.10-vs2.3.6.11/kernel/cred.c      2014-01-31 20:38:03.000000000 +0000
13287 @@ -56,31 +56,6 @@ struct cred init_cred = {
13288         .group_info             = &init_groups,
13289  };
13290  
13291 -static inline void set_cred_subscribers(struct cred *cred, int n)
13292 -{
13293 -#ifdef CONFIG_DEBUG_CREDENTIALS
13294 -       atomic_set(&cred->subscribers, n);
13295 -#endif
13296 -}
13297 -
13298 -static inline int read_cred_subscribers(const struct cred *cred)
13299 -{
13300 -#ifdef CONFIG_DEBUG_CREDENTIALS
13301 -       return atomic_read(&cred->subscribers);
13302 -#else
13303 -       return 0;
13304 -#endif
13305 -}
13306 -
13307 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
13308 -{
13309 -#ifdef CONFIG_DEBUG_CREDENTIALS
13310 -       struct cred *cred = (struct cred *) _cred;
13311 -
13312 -       atomic_add(n, &cred->subscribers);
13313 -#endif
13314 -}
13315 -
13316  /*
13317   * The RCU callback to actually dispose of a set of credentials
13318   */
13319 @@ -232,21 +207,16 @@ error:
13320   *
13321   * Call commit_creds() or abort_creds() to clean up.
13322   */
13323 -struct cred *prepare_creds(void)
13324 +struct cred *__prepare_creds(const struct cred *old)
13325  {
13326 -       struct task_struct *task = current;
13327 -       const struct cred *old;
13328         struct cred *new;
13329  
13330 -       validate_process_creds();
13331 -
13332         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13333         if (!new)
13334                 return NULL;
13335  
13336         kdebug("prepare_creds() alloc %p", new);
13337  
13338 -       old = task->cred;
13339         memcpy(new, old, sizeof(struct cred));
13340  
13341         atomic_set(&new->usage, 1);
13342 @@ -275,6 +245,13 @@ error:
13343         abort_creds(new);
13344         return NULL;
13345  }
13346 +
13347 +struct cred *prepare_creds(void)
13348 +{
13349 +       validate_process_creds();
13350 +
13351 +       return __prepare_creds(current->cred);
13352 +}
13353  EXPORT_SYMBOL(prepare_creds);
13354  
13355  /*
13356 diff -NurpP --minimal linux-3.13.10/kernel/exit.c linux-3.13.10-vs2.3.6.11/kernel/exit.c
13357 --- linux-3.13.10/kernel/exit.c 2013-11-25 15:45:07.000000000 +0000
13358 +++ linux-3.13.10-vs2.3.6.11/kernel/exit.c      2014-01-31 20:38:03.000000000 +0000
13359 @@ -48,6 +48,10 @@
13360  #include <linux/fs_struct.h>
13361  #include <linux/init_task.h>
13362  #include <linux/perf_event.h>
13363 +#include <linux/vs_limit.h>
13364 +#include <linux/vs_context.h>
13365 +#include <linux/vs_network.h>
13366 +#include <linux/vs_pid.h>
13367  #include <trace/events/sched.h>
13368  #include <linux/hw_breakpoint.h>
13369  #include <linux/oom.h>
13370 @@ -503,15 +507,25 @@ static struct task_struct *find_new_reap
13371         __acquires(&tasklist_lock)
13372  {
13373         struct pid_namespace *pid_ns = task_active_pid_ns(father);
13374 -       struct task_struct *thread;
13375 +       struct vx_info *vxi = task_get_vx_info(father);
13376 +       struct task_struct *thread = father;
13377 +       struct task_struct *reaper;
13378  
13379 -       thread = father;
13380         while_each_thread(father, thread) {
13381                 if (thread->flags & PF_EXITING)
13382                         continue;
13383                 if (unlikely(pid_ns->child_reaper == father))
13384                         pid_ns->child_reaper = thread;
13385 -               return thread;
13386 +               reaper = thread;
13387 +               goto out_put;
13388 +       }
13389 +
13390 +       reaper = pid_ns->child_reaper;
13391 +       if (vxi) {
13392 +               BUG_ON(!vxi->vx_reaper);
13393 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
13394 +                   vxi->vx_reaper != father)
13395 +                       reaper = vxi->vx_reaper;
13396         }
13397  
13398         if (unlikely(pid_ns->child_reaper == father)) {
13399 @@ -549,7 +563,9 @@ static struct task_struct *find_new_reap
13400                 }
13401         }
13402  
13403 -       return pid_ns->child_reaper;
13404 +out_put:
13405 +       put_vx_info(vxi);
13406 +       return reaper;
13407  }
13408  
13409  /*
13410 @@ -600,10 +616,15 @@ static void forget_original_parent(struc
13411         list_for_each_entry_safe(p, n, &father->children, sibling) {
13412                 struct task_struct *t = p;
13413                 do {
13414 -                       t->real_parent = reaper;
13415 +                       struct task_struct *new_parent = reaper;
13416 +
13417 +                       if (unlikely(p == reaper))
13418 +                               new_parent = task_active_pid_ns(p)->child_reaper;
13419 +
13420 +                       t->real_parent = new_parent;
13421                         if (t->parent == father) {
13422                                 BUG_ON(t->ptrace);
13423 -                               t->parent = t->real_parent;
13424 +                               t->parent = new_parent;
13425                         }
13426                         if (t->pdeath_signal)
13427                                 group_send_sig_info(t->pdeath_signal,
13428 @@ -810,6 +831,9 @@ void do_exit(long code)
13429          */
13430         flush_ptrace_hw_breakpoint(tsk);
13431  
13432 +       /* needs to stay before exit_notify() */
13433 +       exit_vx_info_early(tsk, code);
13434 +
13435         exit_notify(tsk, group_dead);
13436  #ifdef CONFIG_NUMA
13437         task_lock(tsk);
13438 @@ -863,10 +887,15 @@ void do_exit(long code)
13439         smp_mb();
13440         raw_spin_unlock_wait(&tsk->pi_lock);
13441  
13442 +       /* needs to stay after exit_notify() */
13443 +       exit_vx_info(tsk, code);
13444 +       exit_nx_info(tsk);
13445 +
13446         /* causes final put_task_struct in finish_task_switch(). */
13447         tsk->state = TASK_DEAD;
13448         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
13449         schedule();
13450 +       printk("bad task: %p [%lx]\n", current, current->state);
13451         BUG();
13452         /* Avoid "noreturn function does return".  */
13453         for (;;)
13454 diff -NurpP --minimal linux-3.13.10/kernel/fork.c linux-3.13.10-vs2.3.6.11/kernel/fork.c
13455 --- linux-3.13.10/kernel/fork.c 2014-01-22 20:39:13.000000000 +0000
13456 +++ linux-3.13.10-vs2.3.6.11/kernel/fork.c      2014-01-31 20:38:03.000000000 +0000
13457 @@ -71,6 +71,9 @@
13458  #include <linux/signalfd.h>
13459  #include <linux/uprobes.h>
13460  #include <linux/aio.h>
13461 +#include <linux/vs_context.h>
13462 +#include <linux/vs_network.h>
13463 +#include <linux/vs_limit.h>
13464  
13465  #include <asm/pgtable.h>
13466  #include <asm/pgalloc.h>
13467 @@ -211,6 +214,8 @@ void free_task(struct task_struct *tsk)
13468         arch_release_thread_info(tsk->stack);
13469         free_thread_info(tsk->stack);
13470         rt_mutex_debug_task_free(tsk);
13471 +       clr_vx_info(&tsk->vx_info);
13472 +       clr_nx_info(&tsk->nx_info);
13473         ftrace_graph_exit_task(tsk);
13474         put_seccomp_filter(tsk);
13475         arch_release_task_struct(tsk);
13476 @@ -542,6 +547,7 @@ static struct mm_struct *mm_init(struct
13477         if (likely(!mm_alloc_pgd(mm))) {
13478                 mm->def_flags = 0;
13479                 mmu_notifier_mm_init(mm);
13480 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
13481                 return mm;
13482         }
13483  
13484 @@ -594,6 +600,7 @@ void __mmdrop(struct mm_struct *mm)
13485         destroy_context(mm);
13486         mmu_notifier_mm_destroy(mm);
13487         check_mm(mm);
13488 +       clr_vx_info(&mm->mm_vx_info);
13489         free_mm(mm);
13490  }
13491  EXPORT_SYMBOL_GPL(__mmdrop);
13492 @@ -813,6 +820,7 @@ struct mm_struct *dup_mm(struct task_str
13493                 goto fail_nomem;
13494  
13495         memcpy(mm, oldmm, sizeof(*mm));
13496 +       mm->mm_vx_info = NULL;
13497         mm_init_cpumask(mm);
13498  
13499  #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
13500 @@ -851,6 +859,7 @@ fail_nocontext:
13501          * If init_new_context() failed, we cannot use mmput() to free the mm
13502          * because it calls destroy_context()
13503          */
13504 +       clr_vx_info(&mm->mm_vx_info);
13505         mm_free_pgd(mm);
13506         free_mm(mm);
13507         return NULL;
13508 @@ -1135,6 +1144,8 @@ static struct task_struct *copy_process(
13509  {
13510         int retval;
13511         struct task_struct *p;
13512 +       struct vx_info *vxi;
13513 +       struct nx_info *nxi;
13514  
13515         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
13516                 return ERR_PTR(-EINVAL);
13517 @@ -1197,7 +1208,12 @@ static struct task_struct *copy_process(
13518         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
13519         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
13520  #endif
13521 +       init_vx_info(&p->vx_info, current_vx_info());
13522 +       init_nx_info(&p->nx_info, current_nx_info());
13523 +
13524         retval = -EAGAIN;
13525 +       if (!vx_nproc_avail(1))
13526 +               goto bad_fork_free;
13527         if (atomic_read(&p->real_cred->user->processes) >=
13528                         task_rlimit(p, RLIMIT_NPROC)) {
13529                 if (p->real_cred->user != INIT_USER &&
13530 @@ -1479,6 +1495,18 @@ static struct task_struct *copy_process(
13531  
13532         total_forks++;
13533         spin_unlock(&current->sighand->siglock);
13534 +
13535 +       /* p is copy of current */
13536 +       vxi = p->vx_info;
13537 +       if (vxi) {
13538 +               claim_vx_info(vxi, p);
13539 +               atomic_inc(&vxi->cvirt.nr_threads);
13540 +               atomic_inc(&vxi->cvirt.total_forks);
13541 +               vx_nproc_inc(p);
13542 +       }
13543 +       nxi = p->nx_info;
13544 +       if (nxi)
13545 +               claim_nx_info(nxi, p);
13546         write_unlock_irq(&tasklist_lock);
13547         proc_fork_connector(p);
13548         cgroup_post_fork(p);
13549 diff -NurpP --minimal linux-3.13.10/kernel/kthread.c linux-3.13.10-vs2.3.6.11/kernel/kthread.c
13550 --- linux-3.13.10/kernel/kthread.c      2014-01-22 20:39:13.000000000 +0000
13551 +++ linux-3.13.10-vs2.3.6.11/kernel/kthread.c   2014-01-31 20:38:03.000000000 +0000
13552 @@ -18,6 +18,7 @@
13553  #include <linux/freezer.h>
13554  #include <linux/ptrace.h>
13555  #include <linux/uaccess.h>
13556 +#include <linux/vs_pid.h>
13557  #include <trace/events/sched.h>
13558  
13559  static DEFINE_SPINLOCK(kthread_create_lock);
13560 diff -NurpP --minimal linux-3.13.10/kernel/nsproxy.c linux-3.13.10-vs2.3.6.11/kernel/nsproxy.c
13561 --- linux-3.13.10/kernel/nsproxy.c      2013-11-25 15:47:03.000000000 +0000
13562 +++ linux-3.13.10-vs2.3.6.11/kernel/nsproxy.c   2014-02-01 00:17:43.000000000 +0000
13563 @@ -20,11 +20,14 @@
13564  #include <linux/mnt_namespace.h>
13565  #include <linux/utsname.h>
13566  #include <linux/pid_namespace.h>
13567 +#include <linux/vserver/global.h>
13568 +#include <linux/vserver/debug.h>
13569  #include <net/net_namespace.h>
13570  #include <linux/ipc_namespace.h>
13571  #include <linux/proc_ns.h>
13572  #include <linux/file.h>
13573  #include <linux/syscalls.h>
13574 +#include "../fs/mount.h"
13575  
13576  static struct kmem_cache *nsproxy_cachep;
13577  
13578 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
13579         struct nsproxy *nsproxy;
13580  
13581         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
13582 -       if (nsproxy)
13583 +       if (nsproxy) {
13584                 atomic_set(&nsproxy->count, 1);
13585 +               atomic_inc(&vs_global_nsproxy);
13586 +       }
13587 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
13588         return nsproxy;
13589  }
13590  
13591 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
13592   * Return the newly created nsproxy.  Do not attach this to the task,
13593   * leave it to the caller to do proper locking and attach it to task.
13594   */
13595 -static struct nsproxy *create_new_namespaces(unsigned long flags,
13596 -       struct task_struct *tsk, struct user_namespace *user_ns,
13597 -       struct fs_struct *new_fs)
13598 +static struct nsproxy *unshare_namespaces(
13599 +       unsigned long flags,
13600 +       struct nsproxy *orig,
13601 +       struct fs_struct *new_fs,
13602 +       struct user_namespace *new_user,
13603 +       struct pid_namespace *new_pid)
13604  {
13605         struct nsproxy *new_nsp;
13606         int err;
13607 @@ -67,32 +76,31 @@ static struct nsproxy *create_new_namesp
13608         if (!new_nsp)
13609                 return ERR_PTR(-ENOMEM);
13610  
13611 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
13612 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
13613         if (IS_ERR(new_nsp->mnt_ns)) {
13614                 err = PTR_ERR(new_nsp->mnt_ns);
13615                 goto out_ns;
13616         }
13617  
13618 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
13619 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
13620         if (IS_ERR(new_nsp->uts_ns)) {
13621                 err = PTR_ERR(new_nsp->uts_ns);
13622                 goto out_uts;
13623         }
13624  
13625 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
13626 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
13627         if (IS_ERR(new_nsp->ipc_ns)) {
13628                 err = PTR_ERR(new_nsp->ipc_ns);
13629                 goto out_ipc;
13630         }
13631  
13632 -       new_nsp->pid_ns_for_children =
13633 -               copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children);
13634 +       new_nsp->pid_ns_for_children = copy_pid_ns(flags, new_user, new_pid);
13635         if (IS_ERR(new_nsp->pid_ns_for_children)) {
13636                 err = PTR_ERR(new_nsp->pid_ns_for_children);
13637                 goto out_pid;
13638         }
13639  
13640 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
13641 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
13642         if (IS_ERR(new_nsp->net_ns)) {
13643                 err = PTR_ERR(new_nsp->net_ns);
13644                 goto out_net;
13645 @@ -117,6 +125,41 @@ out_ns:
13646         return ERR_PTR(err);
13647  }
13648  
13649 +static struct nsproxy *create_new_namespaces(unsigned long flags,
13650 +       struct task_struct *tsk, struct user_namespace *user_ns,
13651 +       struct fs_struct *new_fs)
13652 +
13653 +{
13654 +       return unshare_namespaces(flags, tsk->nsproxy,
13655 +               new_fs, user_ns, task_active_pid_ns(tsk));
13656 +}
13657 +
13658 +/*
13659 + * copies the nsproxy, setting refcount to 1, and grabbing a
13660 + * reference to all contained namespaces.
13661 + */
13662 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
13663 +{
13664 +       struct nsproxy *ns = create_nsproxy();
13665 +
13666 +       if (ns) {
13667 +               memcpy(ns, orig, sizeof(struct nsproxy));
13668 +               atomic_set(&ns->count, 1);
13669 +
13670 +               if (ns->mnt_ns)
13671 +                       get_mnt_ns(ns->mnt_ns);
13672 +               if (ns->uts_ns)
13673 +                       get_uts_ns(ns->uts_ns);
13674 +               if (ns->ipc_ns)
13675 +                       get_ipc_ns(ns->ipc_ns);
13676 +               if (ns->pid_ns_for_children)
13677 +                       get_pid_ns(ns->pid_ns_for_children);
13678 +               if (ns->net_ns)
13679 +                       get_net(ns->net_ns);
13680 +       }
13681 +       return ns;
13682 +}
13683 +
13684  /*
13685   * called from clone.  This now handles copy for nsproxy and all
13686   * namespaces therein.
13687 @@ -125,7 +168,10 @@ int copy_namespaces(unsigned long flags,
13688  {
13689         struct nsproxy *old_ns = tsk->nsproxy;
13690         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
13691 -       struct nsproxy *new_ns;
13692 +       struct nsproxy *new_ns = NULL;
13693 +
13694 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
13695 +               flags, tsk, old_ns);
13696  
13697         if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13698                               CLONE_NEWPID | CLONE_NEWNET)))) {
13699 @@ -133,7 +179,7 @@ int copy_namespaces(unsigned long flags,
13700                 return 0;
13701         }
13702  
13703 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13704 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags))
13705                 return -EPERM;
13706  
13707         /*
13708 @@ -152,6 +198,9 @@ int copy_namespaces(unsigned long flags,
13709                 return  PTR_ERR(new_ns);
13710  
13711         tsk->nsproxy = new_ns;
13712 +       vxdprintk(VXD_CBIT(space, 3),
13713 +               "copy_namespaces(0x%08lx,%p[%p]) = [%p]",
13714 +               flags, tsk, old_ns, new_ns);
13715         return 0;
13716  }
13717  
13718 @@ -165,7 +214,9 @@ void free_nsproxy(struct nsproxy *ns)
13719                 put_ipc_ns(ns->ipc_ns);
13720         if (ns->pid_ns_for_children)
13721                 put_pid_ns(ns->pid_ns_for_children);
13722 -       put_net(ns->net_ns);
13723 +       if (ns->net_ns)
13724 +               put_net(ns->net_ns);
13725 +       atomic_dec(&vs_global_nsproxy);
13726         kmem_cache_free(nsproxy_cachep, ns);
13727  }
13728  
13729 @@ -179,12 +230,16 @@ int unshare_nsproxy_namespaces(unsigned
13730         struct user_namespace *user_ns;
13731         int err = 0;
13732  
13733 +       vxdprintk(VXD_CBIT(space, 4),
13734 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
13735 +               unshare_flags, current->nsproxy);
13736 +
13737         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13738                                CLONE_NEWNET | CLONE_NEWPID)))
13739                 return 0;
13740  
13741         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
13742 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13743 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
13744                 return -EPERM;
13745  
13746         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
13747 diff -NurpP --minimal linux-3.13.10/kernel/pid.c linux-3.13.10-vs2.3.6.11/kernel/pid.c
13748 --- linux-3.13.10/kernel/pid.c  2013-11-25 15:47:03.000000000 +0000
13749 +++ linux-3.13.10-vs2.3.6.11/kernel/pid.c       2014-01-31 20:38:03.000000000 +0000
13750 @@ -38,6 +38,7 @@
13751  #include <linux/syscalls.h>
13752  #include <linux/proc_ns.h>
13753  #include <linux/proc_fs.h>
13754 +#include <linux/vs_pid.h>
13755  
13756  #define pid_hashfn(nr, ns)     \
13757         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
13758 @@ -373,7 +374,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
13759  
13760  struct pid *find_vpid(int nr)
13761  {
13762 -       return find_pid_ns(nr, task_active_pid_ns(current));
13763 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
13764  }
13765  EXPORT_SYMBOL_GPL(find_vpid);
13766  
13767 @@ -429,6 +430,9 @@ void transfer_pid(struct task_struct *ol
13768  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
13769  {
13770         struct task_struct *result = NULL;
13771 +
13772 +       if (type == PIDTYPE_REALPID)
13773 +               type = PIDTYPE_PID;
13774         if (pid) {
13775                 struct hlist_node *first;
13776                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
13777 @@ -448,7 +452,7 @@ struct task_struct *find_task_by_pid_ns(
13778         rcu_lockdep_assert(rcu_read_lock_held(),
13779                            "find_task_by_pid_ns() needs rcu_read_lock()"
13780                            " protection");
13781 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
13782 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
13783  }
13784  
13785  struct task_struct *find_task_by_vpid(pid_t vnr)
13786 @@ -492,7 +496,7 @@ struct pid *find_get_pid(pid_t nr)
13787  }
13788  EXPORT_SYMBOL_GPL(find_get_pid);
13789  
13790 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13791 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
13792  {
13793         struct upid *upid;
13794         pid_t nr = 0;
13795 @@ -506,6 +510,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
13796  }
13797  EXPORT_SYMBOL_GPL(pid_nr_ns);
13798  
13799 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13800 +{
13801 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
13802 +}
13803 +
13804  pid_t pid_vnr(struct pid *pid)
13805  {
13806         return pid_nr_ns(pid, task_active_pid_ns(current));
13807 diff -NurpP --minimal linux-3.13.10/kernel/pid_namespace.c linux-3.13.10-vs2.3.6.11/kernel/pid_namespace.c
13808 --- linux-3.13.10/kernel/pid_namespace.c        2014-01-22 20:39:13.000000000 +0000
13809 +++ linux-3.13.10-vs2.3.6.11/kernel/pid_namespace.c     2014-02-01 12:23:11.000000000 +0000
13810 @@ -18,6 +18,7 @@
13811  #include <linux/proc_ns.h>
13812  #include <linux/reboot.h>
13813  #include <linux/export.h>
13814 +#include <linux/vserver/global.h>
13815  
13816  struct pid_cache {
13817         int nr_ids;
13818 @@ -110,6 +111,7 @@ static struct pid_namespace *create_pid_
13819                 goto out_free_map;
13820  
13821         kref_init(&ns->kref);
13822 +       atomic_inc(&vs_global_pid_ns);
13823         ns->level = level;
13824         ns->parent = get_pid_ns(parent_pid_ns);
13825         ns->user_ns = get_user_ns(user_ns);
13826 @@ -127,6 +129,7 @@ static struct pid_namespace *create_pid_
13827  out_free_map:
13828         kfree(ns->pidmap[0].page);
13829  out_free:
13830 +       atomic_dec(&vs_global_pid_ns);
13831         kmem_cache_free(pid_ns_cachep, ns);
13832  out:
13833         return ERR_PTR(err);
13834 diff -NurpP --minimal linux-3.13.10/kernel/posix-timers.c linux-3.13.10-vs2.3.6.11/kernel/posix-timers.c
13835 --- linux-3.13.10/kernel/posix-timers.c 2013-07-14 17:01:35.000000000 +0000
13836 +++ linux-3.13.10-vs2.3.6.11/kernel/posix-timers.c      2014-01-31 20:38:03.000000000 +0000
13837 @@ -48,6 +48,7 @@
13838  #include <linux/workqueue.h>
13839  #include <linux/export.h>
13840  #include <linux/hashtable.h>
13841 +#include <linux/vs_context.h>
13842  
13843  /*
13844   * Management arrays for POSIX timers. Timers are now kept in static hash table
13845 @@ -398,6 +399,7 @@ int posix_timer_event(struct k_itimer *t
13846  {
13847         struct task_struct *task;
13848         int shared, ret = -1;
13849 +
13850         /*
13851          * FIXME: if ->sigq is queued we can race with
13852          * dequeue_signal()->do_schedule_next_timer().
13853 @@ -414,10 +416,18 @@ int posix_timer_event(struct k_itimer *t
13854         rcu_read_lock();
13855         task = pid_task(timr->it_pid, PIDTYPE_PID);
13856         if (task) {
13857 +               struct vx_info_save vxis;
13858 +               struct vx_info *vxi;
13859 +
13860 +               vxi = get_vx_info(task->vx_info);
13861 +               enter_vx_info(vxi, &vxis);
13862                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
13863                 ret = send_sigqueue(timr->sigq, task, shared);
13864 +               leave_vx_info(&vxis);
13865 +               put_vx_info(vxi);
13866         }
13867         rcu_read_unlock();
13868 +
13869         /* If we failed to send the signal the timer stops. */
13870         return ret > 0;
13871  }
13872 diff -NurpP --minimal linux-3.13.10/kernel/printk/printk.c linux-3.13.10-vs2.3.6.11/kernel/printk/printk.c
13873 --- linux-3.13.10/kernel/printk/printk.c        2014-04-17 01:12:39.000000000 +0000
13874 +++ linux-3.13.10-vs2.3.6.11/kernel/printk/printk.c     2014-04-17 01:17:11.000000000 +0000
13875 @@ -45,6 +45,7 @@
13876  #include <linux/poll.h>
13877  #include <linux/irq_work.h>
13878  #include <linux/utsname.h>
13879 +#include <linux/vs_cvirt.h>
13880  
13881  #include <asm/uaccess.h>
13882  
13883 @@ -386,7 +387,7 @@ static int check_syslog_permissions(int
13884                 return 0;
13885  
13886         if (syslog_action_restricted(type)) {
13887 -               if (capable(CAP_SYSLOG))
13888 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
13889                         return 0;
13890                 /*
13891                  * For historical reasons, accept CAP_SYS_ADMIN too, with
13892 @@ -1134,12 +1135,9 @@ int do_syslog(int type, char __user *buf
13893         if (error)
13894                 return error;
13895  
13896 -       switch (type) {
13897 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
13898 -               break;
13899 -       case SYSLOG_ACTION_OPEN:        /* Open log */
13900 -               break;
13901 -       case SYSLOG_ACTION_READ:        /* Read from log */
13902 +       if ((type == SYSLOG_ACTION_READ) ||
13903 +           (type == SYSLOG_ACTION_READ_ALL) ||
13904 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
13905                 error = -EINVAL;
13906                 if (!buf || len < 0)
13907                         goto out;
13908 @@ -1150,6 +1148,16 @@ int do_syslog(int type, char __user *buf
13909                         error = -EFAULT;
13910                         goto out;
13911                 }
13912 +       }
13913 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13914 +               return vx_do_syslog(type, buf, len);
13915 +
13916 +       switch (type) {
13917 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
13918 +               break;
13919 +       case SYSLOG_ACTION_OPEN:        /* Open log */
13920 +               break;
13921 +       case SYSLOG_ACTION_READ:        /* Read from log */
13922                 error = wait_event_interruptible(log_wait,
13923                                                  syslog_seq != log_next_seq);
13924                 if (error)
13925 @@ -1162,16 +1170,6 @@ int do_syslog(int type, char __user *buf
13926                 /* FALL THRU */
13927         /* Read last kernel messages */
13928         case SYSLOG_ACTION_READ_ALL:
13929 -               error = -EINVAL;
13930 -               if (!buf || len < 0)
13931 -                       goto out;
13932 -               error = 0;
13933 -               if (!len)
13934 -                       goto out;
13935 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
13936 -                       error = -EFAULT;
13937 -                       goto out;
13938 -               }
13939                 error = syslog_print_all(buf, len, clear);
13940                 break;
13941         /* Clear ring buffer */
13942 diff -NurpP --minimal linux-3.13.10/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/kernel/ptrace.c
13943 --- linux-3.13.10/kernel/ptrace.c       2014-01-22 20:39:13.000000000 +0000
13944 +++ linux-3.13.10-vs2.3.6.11/kernel/ptrace.c    2014-01-31 20:38:03.000000000 +0000
13945 @@ -23,6 +23,7 @@
13946  #include <linux/syscalls.h>
13947  #include <linux/uaccess.h>
13948  #include <linux/regset.h>
13949 +#include <linux/vs_context.h>
13950  #include <linux/hw_breakpoint.h>
13951  #include <linux/cn_proc.h>
13952  #include <linux/compat.h>
13953 @@ -264,6 +265,11 @@ ok:
13954         }
13955         rcu_read_unlock();
13956  
13957 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
13958 +               return -EPERM;
13959 +       if (!vx_check(task->xid, VS_IDENT) &&
13960 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
13961 +               return -EACCES;
13962         return security_ptrace_access_check(task, mode);
13963  }
13964  
13965 diff -NurpP --minimal linux-3.13.10/kernel/reboot.c linux-3.13.10-vs2.3.6.11/kernel/reboot.c
13966 --- linux-3.13.10/kernel/reboot.c       2014-01-22 20:39:13.000000000 +0000
13967 +++ linux-3.13.10-vs2.3.6.11/kernel/reboot.c    2014-02-01 00:19:40.000000000 +0000
13968 @@ -16,6 +16,7 @@
13969  #include <linux/syscalls.h>
13970  #include <linux/syscore_ops.h>
13971  #include <linux/uaccess.h>
13972 +#include <linux/vs_pid.h>
13973  
13974  /*
13975   * this indicates whether you can reboot with ctrl-alt-del: the default is yes
13976 @@ -188,6 +189,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
13977  
13978  static DEFINE_MUTEX(reboot_mutex);
13979  
13980 +long vs_reboot(unsigned int, void __user *);
13981 +
13982  /*
13983   * Reboot system call: for obvious reasons only root may call it,
13984   * and even root needs to set up some magic numbers in the registers
13985 @@ -230,6 +233,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
13986         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
13987                 cmd = LINUX_REBOOT_CMD_HALT;
13988  
13989 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13990 +               return vs_reboot(cmd, arg);
13991 +
13992         mutex_lock(&reboot_mutex);
13993         switch (cmd) {
13994         case LINUX_REBOOT_CMD_RESTART:
13995 diff -NurpP --minimal linux-3.13.10/kernel/sched/core.c linux-3.13.10-vs2.3.6.11/kernel/sched/core.c
13996 --- linux-3.13.10/kernel/sched/core.c   2014-04-17 01:12:39.000000000 +0000
13997 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/core.c        2014-02-25 11:26:10.000000000 +0000
13998 @@ -73,6 +73,8 @@
13999  #include <linux/init_task.h>
14000  #include <linux/binfmts.h>
14001  #include <linux/context_tracking.h>
14002 +#include <linux/vs_sched.h>
14003 +#include <linux/vs_cvirt.h>
14004  
14005  #include <asm/switch_to.h>
14006  #include <asm/tlb.h>
14007 @@ -2927,7 +2929,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14008                 nice = 19;
14009  
14010         if (increment < 0 && !can_nice(current, nice))
14011 -               return -EPERM;
14012 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14013  
14014         retval = security_task_setnice(current, nice);
14015         if (retval)
14016 diff -NurpP --minimal linux-3.13.10/kernel/sched/cputime.c linux-3.13.10-vs2.3.6.11/kernel/sched/cputime.c
14017 --- linux-3.13.10/kernel/sched/cputime.c        2013-11-25 15:47:03.000000000 +0000
14018 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/cputime.c     2014-01-31 20:38:03.000000000 +0000
14019 @@ -4,6 +4,7 @@
14020  #include <linux/kernel_stat.h>
14021  #include <linux/static_key.h>
14022  #include <linux/context_tracking.h>
14023 +#include <linux/vs_sched.h>
14024  #include "sched.h"
14025  
14026  
14027 @@ -135,14 +136,17 @@ static inline void task_group_account_fi
14028  void account_user_time(struct task_struct *p, cputime_t cputime,
14029                        cputime_t cputime_scaled)
14030  {
14031 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14032 +       int nice = (TASK_NICE(p) > 0);
14033         int index;
14034  
14035         /* Add user time to process. */
14036         p->utime += cputime;
14037         p->utimescaled += cputime_scaled;
14038 +       vx_account_user(vxi, cputime, nice);
14039         account_group_user_time(p, cputime);
14040  
14041 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14042 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14043  
14044         /* Add user time to cpustat. */
14045         task_group_account_field(p, index, (__force u64) cputime);
14046 @@ -189,9 +193,12 @@ static inline
14047  void __account_system_time(struct task_struct *p, cputime_t cputime,
14048                         cputime_t cputime_scaled, int index)
14049  {
14050 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14051 +
14052         /* Add system time to process. */
14053         p->stime += cputime;
14054         p->stimescaled += cputime_scaled;
14055 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14056         account_group_system_time(p, cputime);
14057  
14058         /* Add system time to cpustat. */
14059 diff -NurpP --minimal linux-3.13.10/kernel/sched/fair.c linux-3.13.10-vs2.3.6.11/kernel/sched/fair.c
14060 --- linux-3.13.10/kernel/sched/fair.c   2014-04-17 01:12:40.000000000 +0000
14061 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/fair.c        2014-04-17 01:17:11.000000000 +0000
14062 @@ -29,6 +29,7 @@
14063  #include <linux/mempolicy.h>
14064  #include <linux/migrate.h>
14065  #include <linux/task_work.h>
14066 +#include <linux/vs_cvirt.h>
14067  
14068  #include <trace/events/sched.h>
14069  
14070 @@ -2577,6 +2578,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14071                 __enqueue_entity(cfs_rq, se);
14072         se->on_rq = 1;
14073  
14074 +       if (entity_is_task(se))
14075 +               vx_activate_task(task_of(se));
14076         if (cfs_rq->nr_running == 1) {
14077                 list_add_leaf_cfs_rq(cfs_rq);
14078                 check_enqueue_throttle(cfs_rq);
14079 @@ -2658,6 +2661,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14080         if (se != cfs_rq->curr)
14081                 __dequeue_entity(cfs_rq, se);
14082         se->on_rq = 0;
14083 +       if (entity_is_task(se))
14084 +               vx_deactivate_task(task_of(se));
14085         account_entity_dequeue(cfs_rq, se);
14086  
14087         /*
14088 diff -NurpP --minimal linux-3.13.10/kernel/sched/proc.c linux-3.13.10-vs2.3.6.11/kernel/sched/proc.c
14089 --- linux-3.13.10/kernel/sched/proc.c   2013-11-25 15:45:08.000000000 +0000
14090 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/proc.c        2014-01-31 21:22:36.000000000 +0000
14091 @@ -78,9 +78,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14092   */
14093  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14094  {
14095 -       loads[0] = (avenrun[0] + offset) << shift;
14096 -       loads[1] = (avenrun[1] + offset) << shift;
14097 -       loads[2] = (avenrun[2] + offset) << shift;
14098 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14099 +               struct vx_info *vxi = current_vx_info();
14100 +
14101 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14102 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14103 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14104 +       } else {
14105 +               loads[0] = (avenrun[0] + offset) << shift;
14106 +               loads[1] = (avenrun[1] + offset) << shift;
14107 +               loads[2] = (avenrun[2] + offset) << shift;
14108 +       }
14109  }
14110  
14111  long calc_load_fold_active(struct rq *this_rq)
14112 diff -NurpP --minimal linux-3.13.10/kernel/signal.c linux-3.13.10-vs2.3.6.11/kernel/signal.c
14113 --- linux-3.13.10/kernel/signal.c       2014-01-22 20:39:13.000000000 +0000
14114 +++ linux-3.13.10-vs2.3.6.11/kernel/signal.c    2014-01-31 20:38:03.000000000 +0000
14115 @@ -33,6 +33,8 @@
14116  #include <linux/uprobes.h>
14117  #include <linux/compat.h>
14118  #include <linux/cn_proc.h>
14119 +#include <linux/vs_context.h>
14120 +#include <linux/vs_pid.h>
14121  #define CREATE_TRACE_POINTS
14122  #include <trace/events/signal.h>
14123  
14124 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14125         struct pid *sid;
14126         int error;
14127  
14128 +       vxdprintk(VXD_CBIT(misc, 7),
14129 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14130 +               sig, info, t, vx_task_xid(t), t->pid);
14131 +
14132         if (!valid_signal(sig))
14133                 return -EINVAL;
14134  
14135 +/*     FIXME: needed? if so, why?
14136 +       if ((info != SEND_SIG_NOINFO) &&
14137 +               (is_si_special(info) || !si_fromuser(info)))
14138 +               goto skip;      */
14139 +
14140         if (!si_fromuser(info))
14141                 return 0;
14142  
14143 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14144                 }
14145         }
14146  
14147 +       error = -EPERM;
14148 +       if (t->pid == 1 && current->xid)
14149 +               return error;
14150 +
14151 +       error = -ESRCH;
14152 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14153 +                 loops, maybe ENOENT or EACCES? */
14154 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14155 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14156 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14157 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14158 +               return error;
14159 +       }
14160 +/* skip: */
14161         return security_task_kill(t, info, sig, 0);
14162  }
14163  
14164 @@ -1353,7 +1378,7 @@ int kill_pid_info(int sig, struct siginf
14165         rcu_read_lock();
14166  retry:
14167         p = pid_task(pid, PIDTYPE_PID);
14168 -       if (p) {
14169 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14170                 error = group_send_sig_info(sig, info, p);
14171                 if (unlikely(error == -ESRCH))
14172                         /*
14173 @@ -1401,7 +1426,7 @@ int kill_pid_info_as_cred(int sig, struc
14174  
14175         rcu_read_lock();
14176         p = pid_task(pid, PIDTYPE_PID);
14177 -       if (!p) {
14178 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14179                 ret = -ESRCH;
14180                 goto out_unlock;
14181         }
14182 @@ -1453,8 +1478,10 @@ static int kill_something_info(int sig,
14183                 struct task_struct * p;
14184  
14185                 for_each_process(p) {
14186 -                       if (task_pid_vnr(p) > 1 &&
14187 -                                       !same_thread_group(p, current)) {
14188 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14189 +                               task_pid_vnr(p) > 1 &&
14190 +                               !same_thread_group(p, current) &&
14191 +                               !vx_current_initpid(p->pid)) {
14192                                 int err = group_send_sig_info(sig, info, p);
14193                                 ++count;
14194                                 if (err != -EPERM)
14195 @@ -2308,6 +2335,11 @@ relock:
14196                                 !sig_kernel_only(signr))
14197                         continue;
14198  
14199 +               /* virtual init is protected against user signals */
14200 +               if ((info->si_code == SI_USER) &&
14201 +                       vx_current_initpid(current->pid))
14202 +                       continue;
14203 +
14204                 if (sig_kernel_stop(signr)) {
14205                         /*
14206                          * The default action is to stop all threads in
14207 diff -NurpP --minimal linux-3.13.10/kernel/softirq.c linux-3.13.10-vs2.3.6.11/kernel/softirq.c
14208 --- linux-3.13.10/kernel/softirq.c      2014-01-22 20:39:13.000000000 +0000
14209 +++ linux-3.13.10-vs2.3.6.11/kernel/softirq.c   2014-01-31 20:38:03.000000000 +0000
14210 @@ -23,6 +23,7 @@
14211  #include <linux/smp.h>
14212  #include <linux/smpboot.h>
14213  #include <linux/tick.h>
14214 +#include <linux/vs_context.h>
14215  
14216  #define CREATE_TRACE_POINTS
14217  #include <trace/events/irq.h>
14218 diff -NurpP --minimal linux-3.13.10/kernel/sys.c linux-3.13.10-vs2.3.6.11/kernel/sys.c
14219 --- linux-3.13.10/kernel/sys.c  2014-01-22 20:39:13.000000000 +0000
14220 +++ linux-3.13.10-vs2.3.6.11/kernel/sys.c       2014-02-01 00:19:29.000000000 +0000
14221 @@ -54,6 +54,7 @@
14222  #include <linux/cred.h>
14223  
14224  #include <linux/kmsg_dump.h>
14225 +#include <linux/vs_pid.h>
14226  /* Move somewhere else to avoid recompiling? */
14227  #include <generated/utsrelease.h>
14228  
14229 @@ -145,7 +146,10 @@ static int set_one_prio(struct task_stru
14230                 goto out;
14231         }
14232         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14233 -               error = -EACCES;
14234 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14235 +                       error = 0;
14236 +               else
14237 +                       error = -EACCES;
14238                 goto out;
14239         }
14240         no_nice = security_task_setnice(p, niceval);
14241 @@ -196,6 +200,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14242                         else
14243                                 pgrp = task_pgrp(current);
14244                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14245 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14246 +                                       continue;
14247                                 error = set_one_prio(p, niceval, error);
14248                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14249                         break;
14250 @@ -261,6 +267,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14251                         else
14252                                 pgrp = task_pgrp(current);
14253                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14254 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14255 +                                       continue;
14256                                 niceval = 20 - task_nice(p);
14257                                 if (niceval > retval)
14258                                         retval = niceval;
14259 @@ -1198,7 +1206,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14260         int errno;
14261         char tmp[__NEW_UTS_LEN];
14262  
14263 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14264 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14265 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14266                 return -EPERM;
14267  
14268         if (len < 0 || len > __NEW_UTS_LEN)
14269 @@ -1249,7 +1258,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14270         int errno;
14271         char tmp[__NEW_UTS_LEN];
14272  
14273 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14274 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14275 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14276                 return -EPERM;
14277         if (len < 0 || len > __NEW_UTS_LEN)
14278                 return -EINVAL;
14279 @@ -1368,7 +1378,7 @@ int do_prlimit(struct task_struct *tsk,
14280                 /* Keep the capable check against init_user_ns until
14281                    cgroups can contain all limits */
14282                 if (new_rlim->rlim_max > rlim->rlim_max &&
14283 -                               !capable(CAP_SYS_RESOURCE))
14284 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14285                         retval = -EPERM;
14286                 if (!retval)
14287                         retval = security_task_setrlimit(tsk->group_leader,
14288 @@ -1421,7 +1431,8 @@ static int check_prlimit_permission(stru
14289             gid_eq(cred->gid, tcred->sgid) &&
14290             gid_eq(cred->gid, tcred->gid))
14291                 return 0;
14292 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14293 +       if (vx_ns_capable(tcred->user_ns,
14294 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14295                 return 0;
14296  
14297         return -EPERM;
14298 diff -NurpP --minimal linux-3.13.10/kernel/sysctl.c linux-3.13.10-vs2.3.6.11/kernel/sysctl.c
14299 --- linux-3.13.10/kernel/sysctl.c       2014-04-17 01:12:40.000000000 +0000
14300 +++ linux-3.13.10-vs2.3.6.11/kernel/sysctl.c    2014-02-25 11:26:10.000000000 +0000
14301 @@ -83,6 +83,7 @@
14302  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14303  #include <linux/lockdep.h>
14304  #endif
14305 +extern char vshelper_path[];
14306  #ifdef CONFIG_CHR_DEV_SG
14307  #include <scsi/sg.h>
14308  #endif
14309 @@ -650,6 +651,13 @@ static struct ctl_table kern_table[] = {
14310                 .mode           = 0644,
14311                 .proc_handler   = proc_dostring,
14312         },
14313 +       {
14314 +               .procname       = "vshelper",
14315 +               .data           = &vshelper_path,
14316 +               .maxlen         = 256,
14317 +               .mode           = 0644,
14318 +               .proc_handler   = &proc_dostring,
14319 +       },
14320  
14321  #ifdef CONFIG_CHR_DEV_SG
14322         {
14323 diff -NurpP --minimal linux-3.13.10/kernel/sysctl_binary.c linux-3.13.10-vs2.3.6.11/kernel/sysctl_binary.c
14324 --- linux-3.13.10/kernel/sysctl_binary.c        2014-01-22 20:39:13.000000000 +0000
14325 +++ linux-3.13.10-vs2.3.6.11/kernel/sysctl_binary.c     2014-01-31 20:38:03.000000000 +0000
14326 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
14327  
14328         { CTL_INT,      KERN_PANIC,                     "panic" },
14329         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
14330 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
14331  
14332         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
14333         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
14334 diff -NurpP --minimal linux-3.13.10/kernel/time/timekeeping.c linux-3.13.10-vs2.3.6.11/kernel/time/timekeeping.c
14335 --- linux-3.13.10/kernel/time/timekeeping.c     2014-04-17 01:12:40.000000000 +0000
14336 +++ linux-3.13.10-vs2.3.6.11/kernel/time/timekeeping.c  2014-02-25 11:26:10.000000000 +0000
14337 @@ -22,6 +22,7 @@
14338  #include <linux/tick.h>
14339  #include <linux/stop_machine.h>
14340  #include <linux/pvclock_gtod.h>
14341 +#include <linux/vs_time.h>
14342  
14343  #include "tick-internal.h"
14344  #include "ntp_internal.h"
14345 @@ -709,6 +710,7 @@ void getrawmonotonic(struct timespec *ts
14346         } while (read_seqcount_retry(&timekeeper_seq, seq));
14347  
14348         timespec_add_ns(ts, nsecs);
14349 +       vx_adjust_timespec(ts);
14350  }
14351  EXPORT_SYMBOL(getrawmonotonic);
14352  
14353 diff -NurpP --minimal linux-3.13.10/kernel/time.c linux-3.13.10-vs2.3.6.11/kernel/time.c
14354 --- linux-3.13.10/kernel/time.c 2013-11-25 15:45:08.000000000 +0000
14355 +++ linux-3.13.10-vs2.3.6.11/kernel/time.c      2014-01-31 20:38:03.000000000 +0000
14356 @@ -37,6 +37,7 @@
14357  #include <linux/fs.h>
14358  #include <linux/math64.h>
14359  #include <linux/ptrace.h>
14360 +#include <linux/vs_time.h>
14361  
14362  #include <asm/uaccess.h>
14363  #include <asm/unistd.h>
14364 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
14365         if (err)
14366                 return err;
14367  
14368 -       do_settimeofday(&tv);
14369 +       vx_settimeofday(&tv);
14370         return 0;
14371  }
14372  
14373 @@ -181,7 +182,7 @@ int do_sys_settimeofday(const struct tim
14374                 }
14375         }
14376         if (tv)
14377 -               return do_settimeofday(tv);
14378 +               return vx_settimeofday(tv);
14379         return 0;
14380  }
14381  
14382 diff -NurpP --minimal linux-3.13.10/kernel/timer.c linux-3.13.10-vs2.3.6.11/kernel/timer.c
14383 --- linux-3.13.10/kernel/timer.c        2014-01-22 20:39:13.000000000 +0000
14384 +++ linux-3.13.10-vs2.3.6.11/kernel/timer.c     2014-01-31 20:38:03.000000000 +0000
14385 @@ -42,6 +42,10 @@
14386  #include <linux/sched/sysctl.h>
14387  #include <linux/slab.h>
14388  #include <linux/compat.h>
14389 +#include <linux/vs_base.h>
14390 +#include <linux/vs_cvirt.h>
14391 +#include <linux/vs_pid.h>
14392 +#include <linux/vserver/sched.h>
14393  
14394  #include <asm/uaccess.h>
14395  #include <asm/unistd.h>
14396 diff -NurpP --minimal linux-3.13.10/kernel/user_namespace.c linux-3.13.10-vs2.3.6.11/kernel/user_namespace.c
14397 --- linux-3.13.10/kernel/user_namespace.c       2014-01-22 20:39:13.000000000 +0000
14398 +++ linux-3.13.10-vs2.3.6.11/kernel/user_namespace.c    2014-01-31 20:38:03.000000000 +0000
14399 @@ -22,6 +22,7 @@
14400  #include <linux/ctype.h>
14401  #include <linux/projid.h>
14402  #include <linux/fs_struct.h>
14403 +#include <linux/vserver/global.h>
14404  
14405  static struct kmem_cache *user_ns_cachep __read_mostly;
14406  
14407 @@ -94,6 +95,7 @@ int create_user_ns(struct cred *new)
14408  
14409         atomic_set(&ns->count, 1);
14410         /* Leave the new->user_ns reference with the new user namespace. */
14411 +       atomic_inc(&vs_global_user_ns);
14412         ns->parent = parent_ns;
14413         ns->level = parent_ns->level + 1;
14414         ns->owner = owner;
14415 @@ -848,6 +850,8 @@ static void *userns_get(struct task_stru
14416  
14417  static void userns_put(void *ns)
14418  {
14419 +       /* FIXME: maybe move into destroyer? */
14420 +       atomic_dec(&vs_global_user_ns);
14421         put_user_ns(ns);
14422  }
14423  
14424 diff -NurpP --minimal linux-3.13.10/kernel/utsname.c linux-3.13.10-vs2.3.6.11/kernel/utsname.c
14425 --- linux-3.13.10/kernel/utsname.c      2013-11-25 15:47:03.000000000 +0000
14426 +++ linux-3.13.10-vs2.3.6.11/kernel/utsname.c   2014-01-31 20:38:03.000000000 +0000
14427 @@ -16,14 +16,17 @@
14428  #include <linux/slab.h>
14429  #include <linux/user_namespace.h>
14430  #include <linux/proc_ns.h>
14431 +#include <linux/vserver/global.h>
14432  
14433  static struct uts_namespace *create_uts_ns(void)
14434  {
14435         struct uts_namespace *uts_ns;
14436  
14437         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
14438 -       if (uts_ns)
14439 +       if (uts_ns) {
14440                 kref_init(&uts_ns->kref);
14441 +               atomic_inc(&vs_global_uts_ns);
14442 +       }
14443         return uts_ns;
14444  }
14445  
14446 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
14447         ns = container_of(kref, struct uts_namespace, kref);
14448         put_user_ns(ns->user_ns);
14449         proc_free_inum(ns->proc_inum);
14450 +       atomic_dec(&vs_global_uts_ns);
14451         kfree(ns);
14452  }
14453  
14454 diff -NurpP --minimal linux-3.13.10/kernel/vserver/Kconfig linux-3.13.10-vs2.3.6.11/kernel/vserver/Kconfig
14455 --- linux-3.13.10/kernel/vserver/Kconfig        1970-01-01 00:00:00.000000000 +0000
14456 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/Kconfig     2014-01-31 20:38:03.000000000 +0000
14457 @@ -0,0 +1,230 @@
14458 +#
14459 +# Linux VServer configuration
14460 +#
14461 +
14462 +menu "Linux VServer"
14463 +
14464 +config VSERVER_AUTO_LBACK
14465 +       bool    "Automatically Assign Loopback IP"
14466 +       default y
14467 +       help
14468 +         Automatically assign a guest specific loopback
14469 +         IP and add it to the kernel network stack on
14470 +         startup.
14471 +
14472 +config VSERVER_AUTO_SINGLE
14473 +       bool    "Automatic Single IP Special Casing"
14474 +       default n
14475 +       help
14476 +         This allows network contexts with a single IP to
14477 +         automatically remap 0.0.0.0 bindings to that IP,
14478 +         avoiding further network checks and improving
14479 +         performance.
14480 +
14481 +         (note: such guests do not allow to change the ip
14482 +          on the fly and do not show loopback addresses)
14483 +
14484 +config VSERVER_COWBL
14485 +       bool    "Enable COW Immutable Link Breaking"
14486 +       default y
14487 +       help
14488 +         This enables the COW (Copy-On-Write) link break code.
14489 +         It allows you to treat unified files like normal files
14490 +         when writing to them (which will implicitely break the
14491 +         link and create a copy of the unified file)
14492 +
14493 +config VSERVER_VTIME
14494 +       bool    "Enable Virtualized Guest Time (EXPERIMENTAL)"
14495 +       default n
14496 +       help
14497 +         This enables per guest time offsets to allow for
14498 +         adjusting the system clock individually per guest.
14499 +         this adds some overhead to the time functions and
14500 +         therefore should not be enabled without good reason.
14501 +
14502 +config VSERVER_DEVICE
14503 +       bool    "Enable Guest Device Mapping (EXPERIMENTAL)"
14504 +       default n
14505 +       help
14506 +         This enables generic device remapping.
14507 +
14508 +config VSERVER_PROC_SECURE
14509 +       bool    "Enable Proc Security"
14510 +       depends on PROC_FS
14511 +       default y
14512 +       help
14513 +         This configures ProcFS security to initially hide
14514 +         non-process entries for all contexts except the main and
14515 +         spectator context (i.e. for all guests), which is a secure
14516 +         default.
14517 +
14518 +         (note: on 1.2x the entries were visible by default)
14519 +
14520 +choice
14521 +       prompt  "Persistent Inode Tagging"
14522 +       default TAGGING_ID24
14523 +       help
14524 +         This adds persistent context information to filesystems
14525 +         mounted with the tagxid option. Tagging is a requirement
14526 +         for per-context disk limits and per-context quota.
14527 +
14528 +
14529 +config TAGGING_NONE
14530 +       bool    "Disabled"
14531 +       help
14532 +         do not store per-context information in inodes.
14533 +
14534 +config TAGGING_UID16
14535 +       bool    "UID16/GID32"
14536 +       help
14537 +         reduces UID to 16 bit, but leaves GID at 32 bit.
14538 +
14539 +config TAGGING_GID16
14540 +       bool    "UID32/GID16"
14541 +       help
14542 +         reduces GID to 16 bit, but leaves UID at 32 bit.
14543 +
14544 +config TAGGING_ID24
14545 +       bool    "UID24/GID24"
14546 +       help
14547 +         uses the upper 8bit from UID and GID for XID tagging
14548 +         which leaves 24bit for UID/GID each, which should be
14549 +         more than sufficient for normal use.
14550 +
14551 +config TAGGING_INTERN
14552 +       bool    "UID32/GID32"
14553 +       help
14554 +         this uses otherwise reserved inode fields in the on
14555 +         disk representation, which limits the use to a few
14556 +         filesystems (currently ext2 and ext3)
14557 +
14558 +endchoice
14559 +
14560 +config TAG_NFSD
14561 +       bool    "Tag NFSD User Auth and Files"
14562 +       default n
14563 +       help
14564 +         Enable this if you do want the in-kernel NFS
14565 +         Server to use the tagging specified above.
14566 +         (will require patched clients too)
14567 +
14568 +config VSERVER_PRIVACY
14569 +       bool    "Honor Privacy Aspects of Guests"
14570 +       default n
14571 +       help
14572 +         When enabled, most context checks will disallow
14573 +         access to structures assigned to a specific context,
14574 +         like ptys or loop devices.
14575 +
14576 +config VSERVER_CONTEXTS
14577 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
14578 +       range 1 65533
14579 +       default "768"   if 64BIT
14580 +       default "256"
14581 +       help
14582 +         This setting will optimize certain data structures
14583 +         and memory allocations according to the expected
14584 +         maximum.
14585 +
14586 +         note: this is not a strict upper limit.
14587 +
14588 +config VSERVER_WARN
14589 +       bool    "VServer Warnings"
14590 +       default y
14591 +       help
14592 +         This enables various runtime warnings, which will
14593 +         notify about potential manipulation attempts or
14594 +         resource shortage. It is generally considered to
14595 +         be a good idea to have that enabled.
14596 +
14597 +config VSERVER_WARN_DEVPTS
14598 +       bool    "VServer DevPTS Warnings"
14599 +       depends on VSERVER_WARN
14600 +       default y
14601 +       help
14602 +         This enables DevPTS related warnings, issued when a
14603 +         process inside a context tries to lookup or access
14604 +         a dynamic pts from the host or a different context.
14605 +
14606 +config VSERVER_DEBUG
14607 +       bool    "VServer Debugging Code"
14608 +       default n
14609 +       help
14610 +         Set this to yes if you want to be able to activate
14611 +         debugging output at runtime. It adds a very small
14612 +         overhead to all vserver related functions and
14613 +         increases the kernel size by about 20k.
14614 +
14615 +config VSERVER_HISTORY
14616 +       bool    "VServer History Tracing"
14617 +       depends on VSERVER_DEBUG
14618 +       default n
14619 +       help
14620 +         Set this to yes if you want to record the history of
14621 +         linux-vserver activities, so they can be replayed in
14622 +         the event of a kernel panic or oops.
14623 +
14624 +config VSERVER_HISTORY_SIZE
14625 +       int     "Per-CPU History Size (32-65536)"
14626 +       depends on VSERVER_HISTORY
14627 +       range 32 65536
14628 +       default 64
14629 +       help
14630 +         This allows you to specify the number of entries in
14631 +         the per-CPU history buffer.
14632 +
14633 +config VSERVER_EXTRA_MNT_CHECK
14634 +       bool    "Extra Checks for Reachability"
14635 +       default n
14636 +       help
14637 +         Set this to yes if you want to do extra checks for
14638 +         vfsmount reachability in the proc filesystem code.
14639 +         This shouldn't be required on any setup utilizing
14640 +         mnt namespaces.
14641 +
14642 +choice
14643 +       prompt  "Quotes used in debug and warn messages"
14644 +       default QUOTES_ISO8859
14645 +
14646 +config QUOTES_ISO8859
14647 +       bool    "Extended ASCII (ISO 8859) angle quotes"
14648 +       help
14649 +         This uses the extended ASCII characters \xbb
14650 +         and \xab for quoting file and process names.
14651 +
14652 +config QUOTES_UTF8
14653 +       bool    "UTF-8 angle quotes"
14654 +       help
14655 +         This uses the the UTF-8 sequences for angle
14656 +         quotes to quote file and process names.
14657 +
14658 +config QUOTES_ASCII
14659 +       bool    "ASCII single quotes"
14660 +       help
14661 +         This uses the ASCII single quote character
14662 +         (\x27) to quote file and process names.
14663 +
14664 +endchoice
14665 +
14666 +endmenu
14667 +
14668 +
14669 +config VSERVER
14670 +       bool
14671 +       default y
14672 +       select NAMESPACES
14673 +       select UTS_NS
14674 +       select IPC_NS
14675 +#      select USER_NS
14676 +       select SYSVIPC
14677 +
14678 +config VSERVER_SECURITY
14679 +       bool
14680 +       depends on SECURITY
14681 +       default y
14682 +       select SECURITY_CAPABILITIES
14683 +
14684 +config VSERVER_DISABLED
14685 +       bool
14686 +       default n
14687 +
14688 diff -NurpP --minimal linux-3.13.10/kernel/vserver/Makefile linux-3.13.10-vs2.3.6.11/kernel/vserver/Makefile
14689 --- linux-3.13.10/kernel/vserver/Makefile       1970-01-01 00:00:00.000000000 +0000
14690 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/Makefile    2014-01-31 20:38:03.000000000 +0000
14691 @@ -0,0 +1,18 @@
14692 +#
14693 +# Makefile for the Linux vserver routines.
14694 +#
14695 +
14696 +
14697 +obj-y          += vserver.o
14698 +
14699 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
14700 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
14701 +                  dlimit.o tag.o
14702 +
14703 +vserver-$(CONFIG_INET) += inet.o
14704 +vserver-$(CONFIG_PROC_FS) += proc.o
14705 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
14706 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
14707 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
14708 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
14709 +
14710 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cacct.c linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct.c
14711 --- linux-3.13.10/kernel/vserver/cacct.c        1970-01-01 00:00:00.000000000 +0000
14712 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct.c     2014-01-31 20:38:03.000000000 +0000
14713 @@ -0,0 +1,42 @@
14714 +/*
14715 + *  linux/kernel/vserver/cacct.c
14716 + *
14717 + *  Virtual Server: Context Accounting
14718 + *
14719 + *  Copyright (C) 2006-2007 Herbert Pötzl
14720 + *
14721 + *  V0.01  added accounting stats
14722 + *
14723 + */
14724 +
14725 +#include <linux/types.h>
14726 +#include <linux/vs_context.h>
14727 +#include <linux/vserver/cacct_cmd.h>
14728 +#include <linux/vserver/cacct_int.h>
14729 +
14730 +#include <asm/errno.h>
14731 +#include <asm/uaccess.h>
14732 +
14733 +
14734 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
14735 +{
14736 +       struct vcmd_sock_stat_v0 vc_data;
14737 +       int j, field;
14738 +
14739 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
14740 +               return -EFAULT;
14741 +
14742 +       field = vc_data.field;
14743 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
14744 +               return -EINVAL;
14745 +
14746 +       for (j = 0; j < 3; j++) {
14747 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
14748 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
14749 +       }
14750 +
14751 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
14752 +               return -EFAULT;
14753 +       return 0;
14754 +}
14755 +
14756 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
14757 --- linux-3.13.10/kernel/vserver/cacct_init.h   1970-01-01 00:00:00.000000000 +0000
14758 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_init.h        2014-01-31 20:38:03.000000000 +0000
14759 @@ -0,0 +1,25 @@
14760 +
14761 +
14762 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
14763 +{
14764 +       int i, j;
14765 +
14766 +
14767 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14768 +               for (j = 0; j < 3; j++) {
14769 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
14770 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
14771 +               }
14772 +       }
14773 +       for (i = 0; i < 8; i++)
14774 +               atomic_set(&cacct->slab[i], 0);
14775 +       for (i = 0; i < 5; i++)
14776 +               for (j = 0; j < 4; j++)
14777 +                       atomic_set(&cacct->page[i][j], 0);
14778 +}
14779 +
14780 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
14781 +{
14782 +       return;
14783 +}
14784 +
14785 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
14786 --- linux-3.13.10/kernel/vserver/cacct_proc.h   1970-01-01 00:00:00.000000000 +0000
14787 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_proc.h        2014-01-31 20:38:03.000000000 +0000
14788 @@ -0,0 +1,53 @@
14789 +#ifndef _VX_CACCT_PROC_H
14790 +#define _VX_CACCT_PROC_H
14791 +
14792 +#include <linux/vserver/cacct_int.h>
14793 +
14794 +
14795 +#define VX_SOCKA_TOP   \
14796 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
14797 +
14798 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
14799 +{
14800 +       int i, j, length = 0;
14801 +       static char *type[VXA_SOCK_SIZE] = {
14802 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
14803 +       };
14804 +
14805 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
14806 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14807 +               length += sprintf(buffer + length, "%s:", type[i]);
14808 +               for (j = 0; j < 3; j++) {
14809 +                       length += sprintf(buffer + length,
14810 +                               "\t%10lu/%-10lu",
14811 +                               vx_sock_count(cacct, i, j),
14812 +                               vx_sock_total(cacct, i, j));
14813 +               }
14814 +               buffer[length++] = '\n';
14815 +       }
14816 +
14817 +       length += sprintf(buffer + length, "\n");
14818 +       length += sprintf(buffer + length,
14819 +               "slab:\t %8u %8u %8u %8u\n",
14820 +               atomic_read(&cacct->slab[1]),
14821 +               atomic_read(&cacct->slab[4]),
14822 +               atomic_read(&cacct->slab[0]),
14823 +               atomic_read(&cacct->slab[2]));
14824 +
14825 +       length += sprintf(buffer + length, "\n");
14826 +       for (i = 0; i < 5; i++) {
14827 +               length += sprintf(buffer + length,
14828 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
14829 +                       atomic_read(&cacct->page[i][0]),
14830 +                       atomic_read(&cacct->page[i][1]),
14831 +                       atomic_read(&cacct->page[i][2]),
14832 +                       atomic_read(&cacct->page[i][3]),
14833 +                       atomic_read(&cacct->page[i][4]),
14834 +                       atomic_read(&cacct->page[i][5]),
14835 +                       atomic_read(&cacct->page[i][6]),
14836 +                       atomic_read(&cacct->page[i][7]));
14837 +       }
14838 +       return length;
14839 +}
14840 +
14841 +#endif /* _VX_CACCT_PROC_H */
14842 diff -NurpP --minimal linux-3.13.10/kernel/vserver/context.c linux-3.13.10-vs2.3.6.11/kernel/vserver/context.c
14843 --- linux-3.13.10/kernel/vserver/context.c      1970-01-01 00:00:00.000000000 +0000
14844 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/context.c   2014-01-31 20:38:03.000000000 +0000
14845 @@ -0,0 +1,1119 @@
14846 +/*
14847 + *  linux/kernel/vserver/context.c
14848 + *
14849 + *  Virtual Server: Context Support
14850 + *
14851 + *  Copyright (C) 2003-2011  Herbert Pötzl
14852 + *
14853 + *  V0.01  context helper
14854 + *  V0.02  vx_ctx_kill syscall command
14855 + *  V0.03  replaced context_info calls
14856 + *  V0.04  redesign of struct (de)alloc
14857 + *  V0.05  rlimit basic implementation
14858 + *  V0.06  task_xid and info commands
14859 + *  V0.07  context flags and caps
14860 + *  V0.08  switch to RCU based hash
14861 + *  V0.09  revert to non RCU for now
14862 + *  V0.10  and back to working RCU hash
14863 + *  V0.11  and back to locking again
14864 + *  V0.12  referenced context store
14865 + *  V0.13  separate per cpu data
14866 + *  V0.14  changed vcmds to vxi arg
14867 + *  V0.15  added context stat
14868 + *  V0.16  have __create claim() the vxi
14869 + *  V0.17  removed older and legacy stuff
14870 + *  V0.18  added user credentials
14871 + *  V0.19  added warn mask
14872 + *
14873 + */
14874 +
14875 +#include <linux/slab.h>
14876 +#include <linux/types.h>
14877 +#include <linux/security.h>
14878 +#include <linux/pid_namespace.h>
14879 +#include <linux/capability.h>
14880 +
14881 +#include <linux/vserver/context.h>
14882 +#include <linux/vserver/network.h>
14883 +#include <linux/vserver/debug.h>
14884 +#include <linux/vserver/limit.h>
14885 +#include <linux/vserver/limit_int.h>
14886 +#include <linux/vserver/space.h>
14887 +#include <linux/init_task.h>
14888 +#include <linux/fs_struct.h>
14889 +#include <linux/cred.h>
14890 +
14891 +#include <linux/vs_context.h>
14892 +#include <linux/vs_limit.h>
14893 +#include <linux/vs_pid.h>
14894 +#include <linux/vserver/context_cmd.h>
14895 +
14896 +#include "cvirt_init.h"
14897 +#include "cacct_init.h"
14898 +#include "limit_init.h"
14899 +#include "sched_init.h"
14900 +
14901 +
14902 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
14903 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
14904 +
14905 +
14906 +/*     now inactive context structures */
14907 +
14908 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
14909 +
14910 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
14911 +
14912 +
14913 +/*     __alloc_vx_info()
14914 +
14915 +       * allocate an initialized vx_info struct
14916 +       * doesn't make it visible (hash)                        */
14917 +
14918 +static struct vx_info *__alloc_vx_info(vxid_t xid)
14919 +{
14920 +       struct vx_info *new = NULL;
14921 +       int cpu, index;
14922 +
14923 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
14924 +
14925 +       /* would this benefit from a slab cache? */
14926 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
14927 +       if (!new)
14928 +               return 0;
14929 +
14930 +       memset(new, 0, sizeof(struct vx_info));
14931 +#ifdef CONFIG_SMP
14932 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
14933 +       if (!new->ptr_pc)
14934 +               goto error;
14935 +#endif
14936 +       new->vx_id = xid;
14937 +       INIT_HLIST_NODE(&new->vx_hlist);
14938 +       atomic_set(&new->vx_usecnt, 0);
14939 +       atomic_set(&new->vx_tasks, 0);
14940 +       new->vx_parent = NULL;
14941 +       new->vx_state = 0;
14942 +       init_waitqueue_head(&new->vx_wait);
14943 +
14944 +       /* prepare reaper */
14945 +       get_task_struct(init_pid_ns.child_reaper);
14946 +       new->vx_reaper = init_pid_ns.child_reaper;
14947 +       new->vx_badness_bias = 0;
14948 +
14949 +       /* rest of init goes here */
14950 +       vx_info_init_limit(&new->limit);
14951 +       vx_info_init_sched(&new->sched);
14952 +       vx_info_init_cvirt(&new->cvirt);
14953 +       vx_info_init_cacct(&new->cacct);
14954 +
14955 +       /* per cpu data structures */
14956 +       for_each_possible_cpu(cpu) {
14957 +               vx_info_init_sched_pc(
14958 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
14959 +               vx_info_init_cvirt_pc(
14960 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
14961 +       }
14962 +
14963 +       new->vx_flags = VXF_INIT_SET;
14964 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
14965 +       new->vx_ccaps = 0;
14966 +       new->vx_umask = 0;
14967 +       new->vx_wmask = 0;
14968 +
14969 +       new->reboot_cmd = 0;
14970 +       new->exit_code = 0;
14971 +
14972 +       // preconfig spaces
14973 +       for (index = 0; index < VX_SPACES; index++) {
14974 +               struct _vx_space *space = &new->space[index];
14975 +
14976 +               // filesystem
14977 +               spin_lock(&init_fs.lock);
14978 +               init_fs.users++;
14979 +               spin_unlock(&init_fs.lock);
14980 +               space->vx_fs = &init_fs;
14981 +
14982 +               /* FIXME: do we want defaults? */
14983 +               // space->vx_real_cred = 0;
14984 +               // space->vx_cred = 0;
14985 +       }
14986 +
14987 +
14988 +       vxdprintk(VXD_CBIT(xid, 0),
14989 +               "alloc_vx_info(%d) = %p", xid, new);
14990 +       vxh_alloc_vx_info(new);
14991 +       atomic_inc(&vx_global_ctotal);
14992 +       return new;
14993 +#ifdef CONFIG_SMP
14994 +error:
14995 +       kfree(new);
14996 +       return 0;
14997 +#endif
14998 +}
14999 +
15000 +/*     __dealloc_vx_info()
15001 +
15002 +       * final disposal of vx_info                             */
15003 +
15004 +static void __dealloc_vx_info(struct vx_info *vxi)
15005 +{
15006 +#ifdef CONFIG_VSERVER_WARN
15007 +       struct vx_info_save vxis;
15008 +       int cpu;
15009 +#endif
15010 +       vxdprintk(VXD_CBIT(xid, 0),
15011 +               "dealloc_vx_info(%p)", vxi);
15012 +       vxh_dealloc_vx_info(vxi);
15013 +
15014 +#ifdef CONFIG_VSERVER_WARN
15015 +       enter_vx_info(vxi, &vxis);
15016 +       vx_info_exit_limit(&vxi->limit);
15017 +       vx_info_exit_sched(&vxi->sched);
15018 +       vx_info_exit_cvirt(&vxi->cvirt);
15019 +       vx_info_exit_cacct(&vxi->cacct);
15020 +
15021 +       for_each_possible_cpu(cpu) {
15022 +               vx_info_exit_sched_pc(
15023 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15024 +               vx_info_exit_cvirt_pc(
15025 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15026 +       }
15027 +       leave_vx_info(&vxis);
15028 +#endif
15029 +
15030 +       vxi->vx_id = -1;
15031 +       vxi->vx_state |= VXS_RELEASED;
15032 +
15033 +#ifdef CONFIG_SMP
15034 +       free_percpu(vxi->ptr_pc);
15035 +#endif
15036 +       kfree(vxi);
15037 +       atomic_dec(&vx_global_ctotal);
15038 +}
15039 +
15040 +static void __shutdown_vx_info(struct vx_info *vxi)
15041 +{
15042 +       struct nsproxy *nsproxy;
15043 +       struct fs_struct *fs;
15044 +       struct cred *cred;
15045 +       int index, kill;
15046 +
15047 +       might_sleep();
15048 +
15049 +       vxi->vx_state |= VXS_SHUTDOWN;
15050 +       vs_state_change(vxi, VSC_SHUTDOWN);
15051 +
15052 +       for (index = 0; index < VX_SPACES; index++) {
15053 +               struct _vx_space *space = &vxi->space[index];
15054 +
15055 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15056 +               if (nsproxy)
15057 +                       put_nsproxy(nsproxy);
15058 +
15059 +               fs = xchg(&space->vx_fs, NULL);
15060 +               spin_lock(&fs->lock);
15061 +               kill = !--fs->users;
15062 +               spin_unlock(&fs->lock);
15063 +               if (kill)
15064 +                       free_fs_struct(fs);
15065 +
15066 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15067 +               if (cred)
15068 +                       abort_creds(cred);
15069 +       }
15070 +}
15071 +
15072 +/* exported stuff */
15073 +
15074 +void free_vx_info(struct vx_info *vxi)
15075 +{
15076 +       unsigned long flags;
15077 +       unsigned index;
15078 +
15079 +       /* check for reference counts first */
15080 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15081 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15082 +
15083 +       /* context must not be hashed */
15084 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15085 +
15086 +       /* context shutdown is mandatory */
15087 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15088 +
15089 +       /* spaces check */
15090 +       for (index = 0; index < VX_SPACES; index++) {
15091 +               struct _vx_space *space = &vxi->space[index];
15092 +
15093 +               BUG_ON(space->vx_nsproxy);
15094 +               BUG_ON(space->vx_fs);
15095 +               // BUG_ON(space->vx_real_cred);
15096 +               // BUG_ON(space->vx_cred);
15097 +       }
15098 +
15099 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15100 +       hlist_del(&vxi->vx_hlist);
15101 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15102 +
15103 +       __dealloc_vx_info(vxi);
15104 +}
15105 +
15106 +
15107 +/*     hash table for vx_info hash */
15108 +
15109 +#define VX_HASH_SIZE   13
15110 +
15111 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15112 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15113 +
15114 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15115 +
15116 +
15117 +static inline unsigned int __hashval(vxid_t xid)
15118 +{
15119 +       return (xid % VX_HASH_SIZE);
15120 +}
15121 +
15122 +
15123 +
15124 +/*     __hash_vx_info()
15125 +
15126 +       * add the vxi to the global hash table
15127 +       * requires the hash_lock to be held                     */
15128 +
15129 +static inline void __hash_vx_info(struct vx_info *vxi)
15130 +{
15131 +       struct hlist_head *head;
15132 +
15133 +       vxd_assert_lock(&vx_info_hash_lock);
15134 +       vxdprintk(VXD_CBIT(xid, 4),
15135 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15136 +       vxh_hash_vx_info(vxi);
15137 +
15138 +       /* context must not be hashed */
15139 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15140 +
15141 +       vxi->vx_state |= VXS_HASHED;
15142 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15143 +       hlist_add_head(&vxi->vx_hlist, head);
15144 +       atomic_inc(&vx_global_cactive);
15145 +}
15146 +
15147 +/*     __unhash_vx_info()
15148 +
15149 +       * remove the vxi from the global hash table
15150 +       * requires the hash_lock to be held                     */
15151 +
15152 +static inline void __unhash_vx_info(struct vx_info *vxi)
15153 +{
15154 +       unsigned long flags;
15155 +
15156 +       vxd_assert_lock(&vx_info_hash_lock);
15157 +       vxdprintk(VXD_CBIT(xid, 4),
15158 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15159 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15160 +       vxh_unhash_vx_info(vxi);
15161 +
15162 +       /* context must be hashed */
15163 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15164 +       /* but without tasks */
15165 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15166 +
15167 +       vxi->vx_state &= ~VXS_HASHED;
15168 +       hlist_del_init(&vxi->vx_hlist);
15169 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15170 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15171 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15172 +       atomic_dec(&vx_global_cactive);
15173 +}
15174 +
15175 +
15176 +/*     __lookup_vx_info()
15177 +
15178 +       * requires the hash_lock to be held
15179 +       * doesn't increment the vx_refcnt                       */
15180 +
15181 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
15182 +{
15183 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15184 +       struct hlist_node *pos;
15185 +       struct vx_info *vxi;
15186 +
15187 +       vxd_assert_lock(&vx_info_hash_lock);
15188 +       hlist_for_each(pos, head) {
15189 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15190 +
15191 +               if (vxi->vx_id == xid)
15192 +                       goto found;
15193 +       }
15194 +       vxi = NULL;
15195 +found:
15196 +       vxdprintk(VXD_CBIT(xid, 0),
15197 +               "__lookup_vx_info(#%u): %p[#%u]",
15198 +               xid, vxi, vxi ? vxi->vx_id : 0);
15199 +       vxh_lookup_vx_info(vxi, xid);
15200 +       return vxi;
15201 +}
15202 +
15203 +
15204 +/*     __create_vx_info()
15205 +
15206 +       * create the requested context
15207 +       * get(), claim() and hash it                            */
15208 +
15209 +static struct vx_info *__create_vx_info(int id)
15210 +{
15211 +       struct vx_info *new, *vxi = NULL;
15212 +
15213 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15214 +
15215 +       if (!(new = __alloc_vx_info(id)))
15216 +               return ERR_PTR(-ENOMEM);
15217 +
15218 +       /* required to make dynamic xids unique */
15219 +       spin_lock(&vx_info_hash_lock);
15220 +
15221 +       /* static context requested */
15222 +       if ((vxi = __lookup_vx_info(id))) {
15223 +               vxdprintk(VXD_CBIT(xid, 0),
15224 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15225 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15226 +                       vxi = ERR_PTR(-EBUSY);
15227 +               else
15228 +                       vxi = ERR_PTR(-EEXIST);
15229 +               goto out_unlock;
15230 +       }
15231 +       /* new context */
15232 +       vxdprintk(VXD_CBIT(xid, 0),
15233 +               "create_vx_info(%d) = %p (new)", id, new);
15234 +       claim_vx_info(new, NULL);
15235 +       __hash_vx_info(get_vx_info(new));
15236 +       vxi = new, new = NULL;
15237 +
15238 +out_unlock:
15239 +       spin_unlock(&vx_info_hash_lock);
15240 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15241 +       if (new)
15242 +               __dealloc_vx_info(new);
15243 +       return vxi;
15244 +}
15245 +
15246 +
15247 +/*     exported stuff                                          */
15248 +
15249 +
15250 +void unhash_vx_info(struct vx_info *vxi)
15251 +{
15252 +       spin_lock(&vx_info_hash_lock);
15253 +       __unhash_vx_info(vxi);
15254 +       spin_unlock(&vx_info_hash_lock);
15255 +       __shutdown_vx_info(vxi);
15256 +       __wakeup_vx_info(vxi);
15257 +}
15258 +
15259 +
15260 +/*     lookup_vx_info()
15261 +
15262 +       * search for a vx_info and get() it
15263 +       * negative id means current                             */
15264 +
15265 +struct vx_info *lookup_vx_info(int id)
15266 +{
15267 +       struct vx_info *vxi = NULL;
15268 +
15269 +       if (id < 0) {
15270 +               vxi = get_vx_info(current_vx_info());
15271 +       } else if (id > 1) {
15272 +               spin_lock(&vx_info_hash_lock);
15273 +               vxi = get_vx_info(__lookup_vx_info(id));
15274 +               spin_unlock(&vx_info_hash_lock);
15275 +       }
15276 +       return vxi;
15277 +}
15278 +
15279 +/*     xid_is_hashed()
15280 +
15281 +       * verify that xid is still hashed                       */
15282 +
15283 +int xid_is_hashed(vxid_t xid)
15284 +{
15285 +       int hashed;
15286 +
15287 +       spin_lock(&vx_info_hash_lock);
15288 +       hashed = (__lookup_vx_info(xid) != NULL);
15289 +       spin_unlock(&vx_info_hash_lock);
15290 +       return hashed;
15291 +}
15292 +
15293 +#ifdef CONFIG_PROC_FS
15294 +
15295 +/*     get_xid_list()
15296 +
15297 +       * get a subset of hashed xids for proc
15298 +       * assumes size is at least one                          */
15299 +
15300 +int get_xid_list(int index, unsigned int *xids, int size)
15301 +{
15302 +       int hindex, nr_xids = 0;
15303 +
15304 +       /* only show current and children */
15305 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15306 +               if (index > 0)
15307 +                       return 0;
15308 +               xids[nr_xids] = vx_current_xid();
15309 +               return 1;
15310 +       }
15311 +
15312 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15313 +               struct hlist_head *head = &vx_info_hash[hindex];
15314 +               struct hlist_node *pos;
15315 +
15316 +               spin_lock(&vx_info_hash_lock);
15317 +               hlist_for_each(pos, head) {
15318 +                       struct vx_info *vxi;
15319 +
15320 +                       if (--index > 0)
15321 +                               continue;
15322 +
15323 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15324 +                       xids[nr_xids] = vxi->vx_id;
15325 +                       if (++nr_xids >= size) {
15326 +                               spin_unlock(&vx_info_hash_lock);
15327 +                               goto out;
15328 +                       }
15329 +               }
15330 +               /* keep the lock time short */
15331 +               spin_unlock(&vx_info_hash_lock);
15332 +       }
15333 +out:
15334 +       return nr_xids;
15335 +}
15336 +#endif
15337 +
15338 +#ifdef CONFIG_VSERVER_DEBUG
15339 +
15340 +void   dump_vx_info_inactive(int level)
15341 +{
15342 +       struct hlist_node *entry, *next;
15343 +
15344 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
15345 +               struct vx_info *vxi =
15346 +                       list_entry(entry, struct vx_info, vx_hlist);
15347 +
15348 +               dump_vx_info(vxi, level);
15349 +       }
15350 +}
15351 +
15352 +#endif
15353 +
15354 +#if 0
15355 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
15356 +{
15357 +       struct user_struct *new_user, *old_user;
15358 +
15359 +       if (!p || !vxi)
15360 +               BUG();
15361 +
15362 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
15363 +               return -EACCES;
15364 +
15365 +       new_user = alloc_uid(vxi->vx_id, p->uid);
15366 +       if (!new_user)
15367 +               return -ENOMEM;
15368 +
15369 +       old_user = p->user;
15370 +       if (new_user != old_user) {
15371 +               atomic_inc(&new_user->processes);
15372 +               atomic_dec(&old_user->processes);
15373 +               p->user = new_user;
15374 +       }
15375 +       free_uid(old_user);
15376 +       return 0;
15377 +}
15378 +#endif
15379 +
15380 +#if 0
15381 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
15382 +{
15383 +       // p->cap_effective &= vxi->vx_cap_bset;
15384 +       p->cap_effective =
15385 +               cap_intersect(p->cap_effective, vxi->cap_bset);
15386 +       // p->cap_inheritable &= vxi->vx_cap_bset;
15387 +       p->cap_inheritable =
15388 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
15389 +       // p->cap_permitted &= vxi->vx_cap_bset;
15390 +       p->cap_permitted =
15391 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
15392 +}
15393 +#endif
15394 +
15395 +
15396 +#include <linux/file.h>
15397 +#include <linux/fdtable.h>
15398 +
15399 +static int vx_openfd_task(struct task_struct *tsk)
15400 +{
15401 +       struct files_struct *files = tsk->files;
15402 +       struct fdtable *fdt;
15403 +       const unsigned long *bptr;
15404 +       int count, total;
15405 +
15406 +       /* no rcu_read_lock() because of spin_lock() */
15407 +       spin_lock(&files->file_lock);
15408 +       fdt = files_fdtable(files);
15409 +       bptr = fdt->open_fds;
15410 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
15411 +       for (total = 0; count > 0; count--) {
15412 +               if (*bptr)
15413 +                       total += hweight_long(*bptr);
15414 +               bptr++;
15415 +       }
15416 +       spin_unlock(&files->file_lock);
15417 +       return total;
15418 +}
15419 +
15420 +
15421 +/*     for *space compatibility */
15422 +
15423 +asmlinkage long sys_unshare(unsigned long);
15424 +
15425 +/*
15426 + *     migrate task to new context
15427 + *     gets vxi, puts old_vxi on change
15428 + *     optionally unshares namespaces (hack)
15429 + */
15430 +
15431 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
15432 +{
15433 +       struct vx_info *old_vxi;
15434 +       int ret = 0;
15435 +
15436 +       if (!p || !vxi)
15437 +               BUG();
15438 +
15439 +       vxdprintk(VXD_CBIT(xid, 5),
15440 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
15441 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
15442 +
15443 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
15444 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15445 +               return -EACCES;
15446 +
15447 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
15448 +               return -EFAULT;
15449 +
15450 +       old_vxi = task_get_vx_info(p);
15451 +       if (old_vxi == vxi)
15452 +               goto out;
15453 +
15454 +//     if (!(ret = vx_migrate_user(p, vxi))) {
15455 +       {
15456 +               int openfd;
15457 +
15458 +               task_lock(p);
15459 +               openfd = vx_openfd_task(p);
15460 +
15461 +               if (old_vxi) {
15462 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
15463 +                       atomic_dec(&old_vxi->cvirt.nr_running);
15464 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
15465 +                       /* FIXME: what about the struct files here? */
15466 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
15467 +                       /* account for the executable */
15468 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
15469 +               }
15470 +               atomic_inc(&vxi->cvirt.nr_threads);
15471 +               atomic_inc(&vxi->cvirt.nr_running);
15472 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
15473 +               /* FIXME: what about the struct files here? */
15474 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
15475 +               /* account for the executable */
15476 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
15477 +
15478 +               if (old_vxi) {
15479 +                       release_vx_info(old_vxi, p);
15480 +                       clr_vx_info(&p->vx_info);
15481 +               }
15482 +               claim_vx_info(vxi, p);
15483 +               set_vx_info(&p->vx_info, vxi);
15484 +               p->xid = vxi->vx_id;
15485 +
15486 +               vxdprintk(VXD_CBIT(xid, 5),
15487 +                       "moved task %p into vxi:%p[#%d]",
15488 +                       p, vxi, vxi->vx_id);
15489 +
15490 +               // vx_mask_cap_bset(vxi, p);
15491 +               task_unlock(p);
15492 +
15493 +               /* hack for *spaces to provide compatibility */
15494 +               if (unshare) {
15495 +                       struct nsproxy *old_nsp, *new_nsp;
15496 +
15497 +                       ret = unshare_nsproxy_namespaces(
15498 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
15499 +                               &new_nsp, NULL, NULL);
15500 +                       if (ret)
15501 +                               goto out;
15502 +
15503 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
15504 +                       vx_set_space(vxi,
15505 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
15506 +                       put_nsproxy(old_nsp);
15507 +               }
15508 +       }
15509 +out:
15510 +       put_vx_info(old_vxi);
15511 +       return ret;
15512 +}
15513 +
15514 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
15515 +{
15516 +       struct task_struct *old_reaper;
15517 +       struct vx_info *reaper_vxi;
15518 +
15519 +       if (!vxi)
15520 +               return -EINVAL;
15521 +
15522 +       vxdprintk(VXD_CBIT(xid, 6),
15523 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
15524 +               vxi, vxi->vx_id, p, p->xid, p->pid);
15525 +
15526 +       old_reaper = vxi->vx_reaper;
15527 +       if (old_reaper == p)
15528 +               return 0;
15529 +
15530 +       reaper_vxi = task_get_vx_info(p);
15531 +       if (reaper_vxi && reaper_vxi != vxi) {
15532 +               vxwprintk(1,
15533 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
15534 +                       "for [xid #%u]",
15535 +                       p->comm, p->pid, p->xid, vx_current_xid());
15536 +               goto out;
15537 +       }
15538 +
15539 +       /* set new child reaper */
15540 +       get_task_struct(p);
15541 +       vxi->vx_reaper = p;
15542 +       put_task_struct(old_reaper);
15543 +out:
15544 +       put_vx_info(reaper_vxi);
15545 +       return 0;
15546 +}
15547 +
15548 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
15549 +{
15550 +       if (!vxi)
15551 +               return -EINVAL;
15552 +
15553 +       vxdprintk(VXD_CBIT(xid, 6),
15554 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
15555 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15556 +
15557 +       vxi->vx_flags &= ~VXF_STATE_INIT;
15558 +       // vxi->vx_initpid = p->tgid;
15559 +       vxi->vx_initpid = p->pid;
15560 +       return 0;
15561 +}
15562 +
15563 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
15564 +{
15565 +       vxdprintk(VXD_CBIT(xid, 6),
15566 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
15567 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15568 +
15569 +       vxi->exit_code = code;
15570 +       vxi->vx_initpid = 0;
15571 +}
15572 +
15573 +
15574 +void vx_set_persistent(struct vx_info *vxi)
15575 +{
15576 +       vxdprintk(VXD_CBIT(xid, 6),
15577 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
15578 +
15579 +       get_vx_info(vxi);
15580 +       claim_vx_info(vxi, NULL);
15581 +}
15582 +
15583 +void vx_clear_persistent(struct vx_info *vxi)
15584 +{
15585 +       vxdprintk(VXD_CBIT(xid, 6),
15586 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
15587 +
15588 +       release_vx_info(vxi, NULL);
15589 +       put_vx_info(vxi);
15590 +}
15591 +
15592 +void vx_update_persistent(struct vx_info *vxi)
15593 +{
15594 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
15595 +               vx_set_persistent(vxi);
15596 +       else
15597 +               vx_clear_persistent(vxi);
15598 +}
15599 +
15600 +
15601 +/*     task must be current or locked          */
15602 +
15603 +void   exit_vx_info(struct task_struct *p, int code)
15604 +{
15605 +       struct vx_info *vxi = p->vx_info;
15606 +
15607 +       if (vxi) {
15608 +               atomic_dec(&vxi->cvirt.nr_threads);
15609 +               vx_nproc_dec(p);
15610 +
15611 +               vxi->exit_code = code;
15612 +               release_vx_info(vxi, p);
15613 +       }
15614 +}
15615 +
15616 +void   exit_vx_info_early(struct task_struct *p, int code)
15617 +{
15618 +       struct vx_info *vxi = p->vx_info;
15619 +
15620 +       if (vxi) {
15621 +               if (vxi->vx_initpid == p->pid)
15622 +                       vx_exit_init(vxi, p, code);
15623 +               if (vxi->vx_reaper == p)
15624 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
15625 +       }
15626 +}
15627 +
15628 +
15629 +/* vserver syscall commands below here */
15630 +
15631 +/* taks xid and vx_info functions */
15632 +
15633 +#include <asm/uaccess.h>
15634 +
15635 +
15636 +int vc_task_xid(uint32_t id)
15637 +{
15638 +       vxid_t xid;
15639 +
15640 +       if (id) {
15641 +               struct task_struct *tsk;
15642 +
15643 +               rcu_read_lock();
15644 +               tsk = find_task_by_real_pid(id);
15645 +               xid = (tsk) ? tsk->xid : -ESRCH;
15646 +               rcu_read_unlock();
15647 +       } else
15648 +               xid = vx_current_xid();
15649 +       return xid;
15650 +}
15651 +
15652 +
15653 +int vc_vx_info(struct vx_info *vxi, void __user *data)
15654 +{
15655 +       struct vcmd_vx_info_v0 vc_data;
15656 +
15657 +       vc_data.xid = vxi->vx_id;
15658 +       vc_data.initpid = vxi->vx_initpid;
15659 +
15660 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15661 +               return -EFAULT;
15662 +       return 0;
15663 +}
15664 +
15665 +
15666 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
15667 +{
15668 +       struct vcmd_ctx_stat_v0 vc_data;
15669 +
15670 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
15671 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
15672 +
15673 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15674 +               return -EFAULT;
15675 +       return 0;
15676 +}
15677 +
15678 +
15679 +/* context functions */
15680 +
15681 +int vc_ctx_create(uint32_t xid, void __user *data)
15682 +{
15683 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
15684 +       struct vx_info *new_vxi;
15685 +       int ret;
15686 +
15687 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15688 +               return -EFAULT;
15689 +
15690 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
15691 +               return -EINVAL;
15692 +
15693 +       new_vxi = __create_vx_info(xid);
15694 +       if (IS_ERR(new_vxi))
15695 +               return PTR_ERR(new_vxi);
15696 +
15697 +       /* initial flags */
15698 +       new_vxi->vx_flags = vc_data.flagword;
15699 +
15700 +       ret = -ENOEXEC;
15701 +       if (vs_state_change(new_vxi, VSC_STARTUP))
15702 +               goto out;
15703 +
15704 +       ret = vx_migrate_task(current, new_vxi, (!data));
15705 +       if (ret)
15706 +               goto out;
15707 +
15708 +       /* return context id on success */
15709 +       ret = new_vxi->vx_id;
15710 +
15711 +       /* get a reference for persistent contexts */
15712 +       if ((vc_data.flagword & VXF_PERSISTENT))
15713 +               vx_set_persistent(new_vxi);
15714 +out:
15715 +       release_vx_info(new_vxi, NULL);
15716 +       put_vx_info(new_vxi);
15717 +       return ret;
15718 +}
15719 +
15720 +
15721 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
15722 +{
15723 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
15724 +       int ret;
15725 +
15726 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15727 +               return -EFAULT;
15728 +
15729 +       ret = vx_migrate_task(current, vxi, 0);
15730 +       if (ret)
15731 +               return ret;
15732 +       if (vc_data.flagword & VXM_SET_INIT)
15733 +               ret = vx_set_init(vxi, current);
15734 +       if (ret)
15735 +               return ret;
15736 +       if (vc_data.flagword & VXM_SET_REAPER)
15737 +               ret = vx_set_reaper(vxi, current);
15738 +       return ret;
15739 +}
15740 +
15741 +
15742 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
15743 +{
15744 +       struct vcmd_ctx_flags_v0 vc_data;
15745 +
15746 +       vc_data.flagword = vxi->vx_flags;
15747 +
15748 +       /* special STATE flag handling */
15749 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
15750 +
15751 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15752 +               return -EFAULT;
15753 +       return 0;
15754 +}
15755 +
15756 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
15757 +{
15758 +       struct vcmd_ctx_flags_v0 vc_data;
15759 +       uint64_t mask, trigger;
15760 +
15761 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15762 +               return -EFAULT;
15763 +
15764 +       /* special STATE flag handling */
15765 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
15766 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
15767 +
15768 +       if (vxi == current_vx_info()) {
15769 +               /* if (trigger & VXF_STATE_SETUP)
15770 +                       vx_mask_cap_bset(vxi, current); */
15771 +               if (trigger & VXF_STATE_INIT) {
15772 +                       int ret;
15773 +
15774 +                       ret = vx_set_init(vxi, current);
15775 +                       if (ret)
15776 +                               return ret;
15777 +                       ret = vx_set_reaper(vxi, current);
15778 +                       if (ret)
15779 +                               return ret;
15780 +               }
15781 +       }
15782 +
15783 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
15784 +               vc_data.flagword, mask);
15785 +       if (trigger & VXF_PERSISTENT)
15786 +               vx_update_persistent(vxi);
15787 +
15788 +       return 0;
15789 +}
15790 +
15791 +
15792 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
15793 +{
15794 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
15795 +
15796 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
15797 +       return v;
15798 +}
15799 +
15800 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
15801 +{
15802 +       kernel_cap_t c = __cap_empty_set;
15803 +
15804 +       c.cap[0] = v & 0xFFFFFFFF;
15805 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
15806 +
15807 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
15808 +       return c;
15809 +}
15810 +
15811 +
15812 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
15813 +{
15814 +       if (bcaps)
15815 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
15816 +       if (ccaps)
15817 +               *ccaps = vxi->vx_ccaps;
15818 +
15819 +       return 0;
15820 +}
15821 +
15822 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
15823 +{
15824 +       struct vcmd_ctx_caps_v1 vc_data;
15825 +       int ret;
15826 +
15827 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
15828 +       if (ret)
15829 +               return ret;
15830 +       vc_data.cmask = ~0ULL;
15831 +
15832 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15833 +               return -EFAULT;
15834 +       return 0;
15835 +}
15836 +
15837 +static int do_set_caps(struct vx_info *vxi,
15838 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
15839 +{
15840 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
15841 +
15842 +#if 0
15843 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
15844 +               bcaps, bmask, ccaps, cmask);
15845 +#endif
15846 +       vxi->vx_bcaps = cap_t_from_caps(
15847 +               vs_mask_flags(bcold, bcaps, bmask));
15848 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
15849 +
15850 +       return 0;
15851 +}
15852 +
15853 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
15854 +{
15855 +       struct vcmd_ctx_caps_v1 vc_data;
15856 +
15857 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15858 +               return -EFAULT;
15859 +
15860 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
15861 +}
15862 +
15863 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
15864 +{
15865 +       struct vcmd_bcaps vc_data;
15866 +       int ret;
15867 +
15868 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
15869 +       if (ret)
15870 +               return ret;
15871 +       vc_data.bmask = ~0ULL;
15872 +
15873 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15874 +               return -EFAULT;
15875 +       return 0;
15876 +}
15877 +
15878 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
15879 +{
15880 +       struct vcmd_bcaps vc_data;
15881 +
15882 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15883 +               return -EFAULT;
15884 +
15885 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
15886 +}
15887 +
15888 +
15889 +int vc_get_umask(struct vx_info *vxi, void __user *data)
15890 +{
15891 +       struct vcmd_umask vc_data;
15892 +
15893 +       vc_data.umask = vxi->vx_umask;
15894 +       vc_data.mask = ~0ULL;
15895 +
15896 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15897 +               return -EFAULT;
15898 +       return 0;
15899 +}
15900 +
15901 +int vc_set_umask(struct vx_info *vxi, void __user *data)
15902 +{
15903 +       struct vcmd_umask vc_data;
15904 +
15905 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15906 +               return -EFAULT;
15907 +
15908 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
15909 +               vc_data.umask, vc_data.mask);
15910 +       return 0;
15911 +}
15912 +
15913 +
15914 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
15915 +{
15916 +       struct vcmd_wmask vc_data;
15917 +
15918 +       vc_data.wmask = vxi->vx_wmask;
15919 +       vc_data.mask = ~0ULL;
15920 +
15921 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15922 +               return -EFAULT;
15923 +       return 0;
15924 +}
15925 +
15926 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
15927 +{
15928 +       struct vcmd_wmask vc_data;
15929 +
15930 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15931 +               return -EFAULT;
15932 +
15933 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
15934 +               vc_data.wmask, vc_data.mask);
15935 +       return 0;
15936 +}
15937 +
15938 +
15939 +int vc_get_badness(struct vx_info *vxi, void __user *data)
15940 +{
15941 +       struct vcmd_badness_v0 vc_data;
15942 +
15943 +       vc_data.bias = vxi->vx_badness_bias;
15944 +
15945 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15946 +               return -EFAULT;
15947 +       return 0;
15948 +}
15949 +
15950 +int vc_set_badness(struct vx_info *vxi, void __user *data)
15951 +{
15952 +       struct vcmd_badness_v0 vc_data;
15953 +
15954 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15955 +               return -EFAULT;
15956 +
15957 +       vxi->vx_badness_bias = vc_data.bias;
15958 +       return 0;
15959 +}
15960 +
15961 +#include <linux/module.h>
15962 +
15963 +EXPORT_SYMBOL_GPL(free_vx_info);
15964 +
15965 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cvirt.c linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt.c
15966 --- linux-3.13.10/kernel/vserver/cvirt.c        1970-01-01 00:00:00.000000000 +0000
15967 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt.c     2014-01-31 20:38:04.000000000 +0000
15968 @@ -0,0 +1,313 @@
15969 +/*
15970 + *  linux/kernel/vserver/cvirt.c
15971 + *
15972 + *  Virtual Server: Context Virtualization
15973 + *
15974 + *  Copyright (C) 2004-2007  Herbert Pötzl
15975 + *
15976 + *  V0.01  broken out from limit.c
15977 + *  V0.02  added utsname stuff
15978 + *  V0.03  changed vcmds to vxi arg
15979 + *
15980 + */
15981 +
15982 +#include <linux/types.h>
15983 +#include <linux/utsname.h>
15984 +#include <linux/vs_cvirt.h>
15985 +#include <linux/vserver/switch.h>
15986 +#include <linux/vserver/cvirt_cmd.h>
15987 +
15988 +#include <asm/uaccess.h>
15989 +
15990 +
15991 +void vx_vsi_boottime(struct timespec *boottime)
15992 +{
15993 +       struct vx_info *vxi = current_vx_info();
15994 +
15995 +       set_normalized_timespec(boottime,
15996 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
15997 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
15998 +       return;
15999 +}
16000 +
16001 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16002 +{
16003 +       struct vx_info *vxi = current_vx_info();
16004 +
16005 +       set_normalized_timespec(uptime,
16006 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16007 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16008 +       if (!idle)
16009 +               return;
16010 +       set_normalized_timespec(idle,
16011 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16012 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16013 +       return;
16014 +}
16015 +
16016 +uint64_t vx_idle_jiffies(void)
16017 +{
16018 +       return init_task.utime + init_task.stime;
16019 +}
16020 +
16021 +
16022 +
16023 +static inline uint32_t __update_loadavg(uint32_t load,
16024 +       int wsize, int delta, int n)
16025 +{
16026 +       unsigned long long calc, prev;
16027 +
16028 +       /* just set it to n */
16029 +       if (unlikely(delta >= wsize))
16030 +               return (n << FSHIFT);
16031 +
16032 +       calc = delta * n;
16033 +       calc <<= FSHIFT;
16034 +       prev = (wsize - delta);
16035 +       prev *= load;
16036 +       calc += prev;
16037 +       do_div(calc, wsize);
16038 +       return calc;
16039 +}
16040 +
16041 +
16042 +void vx_update_load(struct vx_info *vxi)
16043 +{
16044 +       uint32_t now, last, delta;
16045 +       unsigned int nr_running, nr_uninterruptible;
16046 +       unsigned int total;
16047 +       unsigned long flags;
16048 +
16049 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16050 +
16051 +       now = jiffies;
16052 +       last = vxi->cvirt.load_last;
16053 +       delta = now - last;
16054 +
16055 +       if (delta < 5*HZ)
16056 +               goto out;
16057 +
16058 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16059 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16060 +       total = nr_running + nr_uninterruptible;
16061 +
16062 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16063 +               60*HZ, delta, total);
16064 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16065 +               5*60*HZ, delta, total);
16066 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16067 +               15*60*HZ, delta, total);
16068 +
16069 +       vxi->cvirt.load_last = now;
16070 +out:
16071 +       atomic_inc(&vxi->cvirt.load_updates);
16072 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16073 +}
16074 +
16075 +
16076 +/*
16077 + * Commands to do_syslog:
16078 + *
16079 + *      0 -- Close the log.  Currently a NOP.
16080 + *      1 -- Open the log. Currently a NOP.
16081 + *      2 -- Read from the log.
16082 + *      3 -- Read all messages remaining in the ring buffer.
16083 + *      4 -- Read and clear all messages remaining in the ring buffer
16084 + *      5 -- Clear ring buffer.
16085 + *      6 -- Disable printk's to console
16086 + *      7 -- Enable printk's to console
16087 + *      8 -- Set level of messages printed to console
16088 + *      9 -- Return number of unread characters in the log buffer
16089 + *     10 -- Return size of the log buffer
16090 + */
16091 +int vx_do_syslog(int type, char __user *buf, int len)
16092 +{
16093 +       int error = 0;
16094 +       int do_clear = 0;
16095 +       struct vx_info *vxi = current_vx_info();
16096 +       struct _vx_syslog *log;
16097 +
16098 +       if (!vxi)
16099 +               return -EINVAL;
16100 +       log = &vxi->cvirt.syslog;
16101 +
16102 +       switch (type) {
16103 +       case 0:         /* Close log */
16104 +       case 1:         /* Open log */
16105 +               break;
16106 +       case 2:         /* Read from log */
16107 +               error = wait_event_interruptible(log->log_wait,
16108 +                       (log->log_start - log->log_end));
16109 +               if (error)
16110 +                       break;
16111 +               spin_lock_irq(&log->logbuf_lock);
16112 +               spin_unlock_irq(&log->logbuf_lock);
16113 +               break;
16114 +       case 4:         /* Read/clear last kernel messages */
16115 +               do_clear = 1;
16116 +               /* fall through */
16117 +       case 3:         /* Read last kernel messages */
16118 +               return 0;
16119 +
16120 +       case 5:         /* Clear ring buffer */
16121 +               return 0;
16122 +
16123 +       case 6:         /* Disable logging to console */
16124 +       case 7:         /* Enable logging to console */
16125 +       case 8:         /* Set level of messages printed to console */
16126 +               break;
16127 +
16128 +       case 9:         /* Number of chars in the log buffer */
16129 +               return 0;
16130 +       case 10:        /* Size of the log buffer */
16131 +               return 0;
16132 +       default:
16133 +               error = -EINVAL;
16134 +               break;
16135 +       }
16136 +       return error;
16137 +}
16138 +
16139 +
16140 +/* virtual host info names */
16141 +
16142 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16143 +{
16144 +       struct nsproxy *nsproxy;
16145 +       struct uts_namespace *uts;
16146 +
16147 +       if (id == VHIN_CONTEXT)
16148 +               return vxi->vx_name;
16149 +
16150 +       nsproxy = vxi->space[0].vx_nsproxy;
16151 +       if (!nsproxy)
16152 +               return NULL;
16153 +
16154 +       uts = nsproxy->uts_ns;
16155 +       if (!uts)
16156 +               return NULL;
16157 +
16158 +       switch (id) {
16159 +       case VHIN_SYSNAME:
16160 +               return uts->name.sysname;
16161 +       case VHIN_NODENAME:
16162 +               return uts->name.nodename;
16163 +       case VHIN_RELEASE:
16164 +               return uts->name.release;
16165 +       case VHIN_VERSION:
16166 +               return uts->name.version;
16167 +       case VHIN_MACHINE:
16168 +               return uts->name.machine;
16169 +       case VHIN_DOMAINNAME:
16170 +               return uts->name.domainname;
16171 +       default:
16172 +               return NULL;
16173 +       }
16174 +       return NULL;
16175 +}
16176 +
16177 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16178 +{
16179 +       struct vcmd_vhi_name_v0 vc_data;
16180 +       char *name;
16181 +
16182 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16183 +               return -EFAULT;
16184 +
16185 +       name = vx_vhi_name(vxi, vc_data.field);
16186 +       if (!name)
16187 +               return -EINVAL;
16188 +
16189 +       memcpy(name, vc_data.name, 65);
16190 +       return 0;
16191 +}
16192 +
16193 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16194 +{
16195 +       struct vcmd_vhi_name_v0 vc_data;
16196 +       char *name;
16197 +
16198 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16199 +               return -EFAULT;
16200 +
16201 +       name = vx_vhi_name(vxi, vc_data.field);
16202 +       if (!name)
16203 +               return -EINVAL;
16204 +
16205 +       memcpy(vc_data.name, name, 65);
16206 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16207 +               return -EFAULT;
16208 +       return 0;
16209 +}
16210 +
16211 +
16212 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16213 +{
16214 +       struct vcmd_virt_stat_v0 vc_data;
16215 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16216 +       struct timespec uptime;
16217 +
16218 +       do_posix_clock_monotonic_gettime(&uptime);
16219 +       set_normalized_timespec(&uptime,
16220 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16221 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16222 +
16223 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16224 +       vc_data.uptime = timespec_to_ns(&uptime);
16225 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16226 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16227 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16228 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16229 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16230 +       vc_data.load[0] = cvirt->load[0];
16231 +       vc_data.load[1] = cvirt->load[1];
16232 +       vc_data.load[2] = cvirt->load[2];
16233 +
16234 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16235 +               return -EFAULT;
16236 +       return 0;
16237 +}
16238 +
16239 +
16240 +#ifdef CONFIG_VSERVER_VTIME
16241 +
16242 +/* virtualized time base */
16243 +
16244 +void vx_adjust_timespec(struct timespec *ts)
16245 +{
16246 +       struct vx_info *vxi;
16247 +
16248 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16249 +               return;
16250 +
16251 +       vxi = current_vx_info();
16252 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16253 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16254 +
16255 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
16256 +               ts->tv_sec++;
16257 +               ts->tv_nsec -= NSEC_PER_SEC;
16258 +       } else if (ts->tv_nsec < 0) {
16259 +               ts->tv_sec--;
16260 +               ts->tv_nsec += NSEC_PER_SEC;
16261 +       }
16262 +}
16263 +
16264 +int vx_settimeofday(const struct timespec *ts)
16265 +{
16266 +       struct timespec ats, delta;
16267 +       struct vx_info *vxi;
16268 +
16269 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16270 +               return do_settimeofday(ts);
16271 +
16272 +       getnstimeofday(&ats);
16273 +       delta = timespec_sub(*ts, ats);
16274 +
16275 +       vxi = current_vx_info();
16276 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16277 +       return 0;
16278 +}
16279 +
16280 +#endif
16281 +
16282 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
16283 --- linux-3.13.10/kernel/vserver/cvirt_init.h   1970-01-01 00:00:00.000000000 +0000
16284 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_init.h        2014-01-31 20:38:04.000000000 +0000
16285 @@ -0,0 +1,70 @@
16286 +
16287 +
16288 +extern uint64_t vx_idle_jiffies(void);
16289 +
16290 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16291 +{
16292 +       uint64_t idle_jiffies = vx_idle_jiffies();
16293 +       uint64_t nsuptime;
16294 +
16295 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16296 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16297 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16298 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16299 +       cvirt->bias_ts.tv_sec = 0;
16300 +       cvirt->bias_ts.tv_nsec = 0;
16301 +
16302 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16303 +       atomic_set(&cvirt->nr_threads, 0);
16304 +       atomic_set(&cvirt->nr_running, 0);
16305 +       atomic_set(&cvirt->nr_uninterruptible, 0);
16306 +       atomic_set(&cvirt->nr_onhold, 0);
16307 +
16308 +       spin_lock_init(&cvirt->load_lock);
16309 +       cvirt->load_last = jiffies;
16310 +       atomic_set(&cvirt->load_updates, 0);
16311 +       cvirt->load[0] = 0;
16312 +       cvirt->load[1] = 0;
16313 +       cvirt->load[2] = 0;
16314 +       atomic_set(&cvirt->total_forks, 0);
16315 +
16316 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
16317 +       init_waitqueue_head(&cvirt->syslog.log_wait);
16318 +       cvirt->syslog.log_start = 0;
16319 +       cvirt->syslog.log_end = 0;
16320 +       cvirt->syslog.con_start = 0;
16321 +       cvirt->syslog.logged_chars = 0;
16322 +}
16323 +
16324 +static inline
16325 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16326 +{
16327 +       // cvirt_pc->cpustat = { 0 };
16328 +}
16329 +
16330 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16331 +{
16332 +#ifdef CONFIG_VSERVER_WARN
16333 +       int value;
16334 +#endif
16335 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16336 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
16337 +               cvirt, value);
16338 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16339 +               "!!! cvirt: %p[nr_running] = %d on exit.",
16340 +               cvirt, value);
16341 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16342 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16343 +               cvirt, value);
16344 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16345 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
16346 +               cvirt, value);
16347 +       return;
16348 +}
16349 +
16350 +static inline
16351 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16352 +{
16353 +       return;
16354 +}
16355 +
16356 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
16357 --- linux-3.13.10/kernel/vserver/cvirt_proc.h   1970-01-01 00:00:00.000000000 +0000
16358 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_proc.h        2014-01-31 20:38:04.000000000 +0000
16359 @@ -0,0 +1,123 @@
16360 +#ifndef _VX_CVIRT_PROC_H
16361 +#define _VX_CVIRT_PROC_H
16362 +
16363 +#include <linux/nsproxy.h>
16364 +#include <linux/mnt_namespace.h>
16365 +#include <linux/ipc_namespace.h>
16366 +#include <linux/utsname.h>
16367 +#include <linux/ipc.h>
16368 +
16369 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
16370 +
16371 +static inline
16372 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
16373 +{
16374 +       struct mnt_namespace *ns;
16375 +       struct uts_namespace *uts;
16376 +       struct ipc_namespace *ipc;
16377 +       int length = 0;
16378 +
16379 +       if (!nsproxy)
16380 +               goto out;
16381 +
16382 +       length += sprintf(buffer + length,
16383 +               "NSProxy:\t%p [%p,%p,%p]\n",
16384 +               nsproxy, nsproxy->mnt_ns,
16385 +               nsproxy->uts_ns, nsproxy->ipc_ns);
16386 +
16387 +       ns = nsproxy->mnt_ns;
16388 +       if (!ns)
16389 +               goto skip_ns;
16390 +
16391 +       length += vx_info_mnt_namespace(ns, buffer + length);
16392 +
16393 +skip_ns:
16394 +
16395 +       uts = nsproxy->uts_ns;
16396 +       if (!uts)
16397 +               goto skip_uts;
16398 +
16399 +       length += sprintf(buffer + length,
16400 +               "SysName:\t%.*s\n"
16401 +               "NodeName:\t%.*s\n"
16402 +               "Release:\t%.*s\n"
16403 +               "Version:\t%.*s\n"
16404 +               "Machine:\t%.*s\n"
16405 +               "DomainName:\t%.*s\n",
16406 +               __NEW_UTS_LEN, uts->name.sysname,
16407 +               __NEW_UTS_LEN, uts->name.nodename,
16408 +               __NEW_UTS_LEN, uts->name.release,
16409 +               __NEW_UTS_LEN, uts->name.version,
16410 +               __NEW_UTS_LEN, uts->name.machine,
16411 +               __NEW_UTS_LEN, uts->name.domainname);
16412 +skip_uts:
16413 +
16414 +       ipc = nsproxy->ipc_ns;
16415 +       if (!ipc)
16416 +               goto skip_ipc;
16417 +
16418 +       length += sprintf(buffer + length,
16419 +               "SEMS:\t\t%d %d %d %d  %d\n"
16420 +               "MSG:\t\t%d %d %d\n"
16421 +               "SHM:\t\t%lu %lu  %d %ld\n",
16422 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
16423 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
16424 +               ipc->used_sems,
16425 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
16426 +               (unsigned long)ipc->shm_ctlmax,
16427 +               (unsigned long)ipc->shm_ctlall,
16428 +               ipc->shm_ctlmni, ipc->shm_tot);
16429 +skip_ipc:
16430 +out:
16431 +       return length;
16432 +}
16433 +
16434 +
16435 +#include <linux/sched.h>
16436 +
16437 +#define LOAD_INT(x) ((x) >> FSHIFT)
16438 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
16439 +
16440 +static inline
16441 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
16442 +{
16443 +       int length = 0;
16444 +       int a, b, c;
16445 +
16446 +       length += sprintf(buffer + length,
16447 +               "BiasUptime:\t%lu.%02lu\n",
16448 +               (unsigned long)cvirt->bias_uptime.tv_sec,
16449 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
16450 +
16451 +       a = cvirt->load[0] + (FIXED_1 / 200);
16452 +       b = cvirt->load[1] + (FIXED_1 / 200);
16453 +       c = cvirt->load[2] + (FIXED_1 / 200);
16454 +       length += sprintf(buffer + length,
16455 +               "nr_threads:\t%d\n"
16456 +               "nr_running:\t%d\n"
16457 +               "nr_unintr:\t%d\n"
16458 +               "nr_onhold:\t%d\n"
16459 +               "load_updates:\t%d\n"
16460 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
16461 +               "total_forks:\t%d\n",
16462 +               atomic_read(&cvirt->nr_threads),
16463 +               atomic_read(&cvirt->nr_running),
16464 +               atomic_read(&cvirt->nr_uninterruptible),
16465 +               atomic_read(&cvirt->nr_onhold),
16466 +               atomic_read(&cvirt->load_updates),
16467 +               LOAD_INT(a), LOAD_FRAC(a),
16468 +               LOAD_INT(b), LOAD_FRAC(b),
16469 +               LOAD_INT(c), LOAD_FRAC(c),
16470 +               atomic_read(&cvirt->total_forks));
16471 +       return length;
16472 +}
16473 +
16474 +static inline
16475 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
16476 +       char *buffer, int cpu)
16477 +{
16478 +       int length = 0;
16479 +       return length;
16480 +}
16481 +
16482 +#endif /* _VX_CVIRT_PROC_H */
16483 diff -NurpP --minimal linux-3.13.10/kernel/vserver/debug.c linux-3.13.10-vs2.3.6.11/kernel/vserver/debug.c
16484 --- linux-3.13.10/kernel/vserver/debug.c        1970-01-01 00:00:00.000000000 +0000
16485 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/debug.c     2014-01-31 20:38:04.000000000 +0000
16486 @@ -0,0 +1,32 @@
16487 +/*
16488 + *  kernel/vserver/debug.c
16489 + *
16490 + *  Copyright (C) 2005-2007 Herbert Pötzl
16491 + *
16492 + *  V0.01  vx_info dump support
16493 + *
16494 + */
16495 +
16496 +#include <linux/module.h>
16497 +
16498 +#include <linux/vserver/context.h>
16499 +
16500 +
16501 +void   dump_vx_info(struct vx_info *vxi, int level)
16502 +{
16503 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
16504 +               atomic_read(&vxi->vx_usecnt),
16505 +               atomic_read(&vxi->vx_tasks),
16506 +               vxi->vx_state);
16507 +       if (level > 0) {
16508 +               __dump_vx_limit(&vxi->limit);
16509 +               __dump_vx_sched(&vxi->sched);
16510 +               __dump_vx_cvirt(&vxi->cvirt);
16511 +               __dump_vx_cacct(&vxi->cacct);
16512 +       }
16513 +       printk("---\n");
16514 +}
16515 +
16516 +
16517 +EXPORT_SYMBOL_GPL(dump_vx_info);
16518 +
16519 diff -NurpP --minimal linux-3.13.10/kernel/vserver/device.c linux-3.13.10-vs2.3.6.11/kernel/vserver/device.c
16520 --- linux-3.13.10/kernel/vserver/device.c       1970-01-01 00:00:00.000000000 +0000
16521 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/device.c    2014-01-31 20:38:04.000000000 +0000
16522 @@ -0,0 +1,443 @@
16523 +/*
16524 + *  linux/kernel/vserver/device.c
16525 + *
16526 + *  Linux-VServer: Device Support
16527 + *
16528 + *  Copyright (C) 2006  Herbert Pötzl
16529 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
16530 + *
16531 + *  V0.01  device mapping basics
16532 + *  V0.02  added defaults
16533 + *
16534 + */
16535 +
16536 +#include <linux/slab.h>
16537 +#include <linux/rcupdate.h>
16538 +#include <linux/fs.h>
16539 +#include <linux/namei.h>
16540 +#include <linux/hash.h>
16541 +
16542 +#include <asm/errno.h>
16543 +#include <asm/uaccess.h>
16544 +#include <linux/vserver/base.h>
16545 +#include <linux/vserver/debug.h>
16546 +#include <linux/vserver/context.h>
16547 +#include <linux/vserver/device.h>
16548 +#include <linux/vserver/device_cmd.h>
16549 +
16550 +
16551 +#define DMAP_HASH_BITS 4
16552 +
16553 +
16554 +struct vs_mapping {
16555 +       union {
16556 +               struct hlist_node hlist;
16557 +               struct list_head list;
16558 +       } u;
16559 +#define dm_hlist       u.hlist
16560 +#define dm_list                u.list
16561 +       vxid_t xid;
16562 +       dev_t device;
16563 +       struct vx_dmap_target target;
16564 +};
16565 +
16566 +
16567 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
16568 +
16569 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
16570 +
16571 +static struct vx_dmap_target dmap_defaults[2] = {
16572 +       { .flags = DATTR_OPEN },
16573 +       { .flags = DATTR_OPEN },
16574 +};
16575 +
16576 +
16577 +struct kmem_cache *dmap_cachep __read_mostly;
16578 +
16579 +int __init dmap_cache_init(void)
16580 +{
16581 +       dmap_cachep = kmem_cache_create("dmap_cache",
16582 +               sizeof(struct vs_mapping), 0,
16583 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
16584 +       return 0;
16585 +}
16586 +
16587 +__initcall(dmap_cache_init);
16588 +
16589 +
16590 +static inline unsigned int __hashval(dev_t dev, int bits)
16591 +{
16592 +       return hash_long((unsigned long)dev, bits);
16593 +}
16594 +
16595 +
16596 +/*     __hash_mapping()
16597 + *     add the mapping to the hash table
16598 + */
16599 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
16600 +{
16601 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16602 +       struct hlist_head *head, *hash = dmap_main_hash;
16603 +       int device = vdm->device;
16604 +
16605 +       spin_lock(hash_lock);
16606 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
16607 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
16608 +
16609 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
16610 +       hlist_add_head(&vdm->dm_hlist, head);
16611 +       spin_unlock(hash_lock);
16612 +}
16613 +
16614 +
16615 +static inline int __mode_to_default(umode_t mode)
16616 +{
16617 +       switch (mode) {
16618 +       case S_IFBLK:
16619 +               return 0;
16620 +       case S_IFCHR:
16621 +               return 1;
16622 +       default:
16623 +               BUG();
16624 +       }
16625 +}
16626 +
16627 +
16628 +/*     __set_default()
16629 + *     set a default
16630 + */
16631 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
16632 +       struct vx_dmap_target *vdmt)
16633 +{
16634 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16635 +       spin_lock(hash_lock);
16636 +
16637 +       if (vxi)
16638 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
16639 +       else
16640 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
16641 +
16642 +
16643 +       spin_unlock(hash_lock);
16644 +
16645 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
16646 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
16647 +}
16648 +
16649 +
16650 +/*     __remove_default()
16651 + *     remove a default
16652 + */
16653 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
16654 +{
16655 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16656 +       spin_lock(hash_lock);
16657 +
16658 +       if (vxi)
16659 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
16660 +       else    /* remove == reset */
16661 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
16662 +
16663 +       spin_unlock(hash_lock);
16664 +       return 0;
16665 +}
16666 +
16667 +
16668 +/*     __find_mapping()
16669 + *     find a mapping in the hash table
16670 + *
16671 + *     caller must hold hash_lock
16672 + */
16673 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
16674 +       struct vs_mapping **local, struct vs_mapping **global)
16675 +{
16676 +       struct hlist_head *hash = dmap_main_hash;
16677 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
16678 +       struct hlist_node *pos;
16679 +       struct vs_mapping *vdm;
16680 +
16681 +       *local = NULL;
16682 +       if (global)
16683 +               *global = NULL;
16684 +
16685 +       hlist_for_each(pos, head) {
16686 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
16687 +
16688 +               if ((vdm->device == device) &&
16689 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
16690 +                       if (vdm->xid == xid) {
16691 +                               *local = vdm;
16692 +                               return 1;
16693 +                       } else if (global && vdm->xid == 0)
16694 +                               *global = vdm;
16695 +               }
16696 +       }
16697 +
16698 +       if (global && *global)
16699 +               return 0;
16700 +       else
16701 +               return -ENOENT;
16702 +}
16703 +
16704 +
16705 +/*     __lookup_mapping()
16706 + *     find a mapping and store the result in target and flags
16707 + */
16708 +static inline int __lookup_mapping(struct vx_info *vxi,
16709 +       dev_t device, dev_t *target, int *flags, umode_t mode)
16710 +{
16711 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16712 +       struct vs_mapping *vdm, *global;
16713 +       struct vx_dmap_target *vdmt;
16714 +       int ret = 0;
16715 +       vxid_t xid = vxi->vx_id;
16716 +       int index;
16717 +
16718 +       spin_lock(hash_lock);
16719 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
16720 +               ret = 1;
16721 +               vdmt = &vdm->target;
16722 +               goto found;
16723 +       }
16724 +
16725 +       index = __mode_to_default(mode);
16726 +       if (vxi && vxi->dmap.targets[index].flags) {
16727 +               ret = 2;
16728 +               vdmt = &vxi->dmap.targets[index];
16729 +       } else if (global) {
16730 +               ret = 3;
16731 +               vdmt = &global->target;
16732 +               goto found;
16733 +       } else {
16734 +               ret = 4;
16735 +               vdmt = &dmap_defaults[index];
16736 +       }
16737 +
16738 +found:
16739 +       if (target && (vdmt->flags & DATTR_REMAP))
16740 +               *target = vdmt->target;
16741 +       else if (target)
16742 +               *target = device;
16743 +       if (flags)
16744 +               *flags = vdmt->flags;
16745 +
16746 +       spin_unlock(hash_lock);
16747 +
16748 +       return ret;
16749 +}
16750 +
16751 +
16752 +/*     __remove_mapping()
16753 + *     remove a mapping from the hash table
16754 + */
16755 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
16756 +       umode_t mode)
16757 +{
16758 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16759 +       struct vs_mapping *vdm = NULL;
16760 +       int ret = 0;
16761 +
16762 +       spin_lock(hash_lock);
16763 +
16764 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
16765 +               NULL);
16766 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
16767 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
16768 +       if (ret < 0)
16769 +               goto out;
16770 +       hlist_del(&vdm->dm_hlist);
16771 +
16772 +out:
16773 +       spin_unlock(hash_lock);
16774 +       if (vdm)
16775 +               kmem_cache_free(dmap_cachep, vdm);
16776 +       return ret;
16777 +}
16778 +
16779 +
16780 +
16781 +int vs_map_device(struct vx_info *vxi,
16782 +       dev_t device, dev_t *target, umode_t mode)
16783 +{
16784 +       int ret, flags = DATTR_MASK;
16785 +
16786 +       if (!vxi) {
16787 +               if (target)
16788 +                       *target = device;
16789 +               goto out;
16790 +       }
16791 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
16792 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
16793 +               device, target ? *target : 0, flags, mode, ret);
16794 +out:
16795 +       return (flags & DATTR_MASK);
16796 +}
16797 +
16798 +
16799 +
16800 +static int do_set_mapping(struct vx_info *vxi,
16801 +       dev_t device, dev_t target, int flags, umode_t mode)
16802 +{
16803 +       if (device) {
16804 +               struct vs_mapping *new;
16805 +
16806 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
16807 +               if (!new)
16808 +                       return -ENOMEM;
16809 +
16810 +               INIT_HLIST_NODE(&new->dm_hlist);
16811 +               new->device = device;
16812 +               new->target.target = target;
16813 +               new->target.flags = flags | mode;
16814 +               new->xid = (vxi ? vxi->vx_id : 0);
16815 +
16816 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
16817 +               __hash_mapping(vxi, new);
16818 +       } else {
16819 +               struct vx_dmap_target new = {
16820 +                       .target = target,
16821 +                       .flags = flags | mode,
16822 +               };
16823 +               __set_default(vxi, mode, &new);
16824 +       }
16825 +       return 0;
16826 +}
16827 +
16828 +
16829 +static int do_unset_mapping(struct vx_info *vxi,
16830 +       dev_t device, dev_t target, int flags, umode_t mode)
16831 +{
16832 +       int ret = -EINVAL;
16833 +
16834 +       if (device) {
16835 +               ret = __remove_mapping(vxi, device, mode);
16836 +               if (ret < 0)
16837 +                       goto out;
16838 +       } else {
16839 +               ret = __remove_default(vxi, mode);
16840 +               if (ret < 0)
16841 +                       goto out;
16842 +       }
16843 +
16844 +out:
16845 +       return ret;
16846 +}
16847 +
16848 +
16849 +static inline int __user_device(const char __user *name, dev_t *dev,
16850 +       umode_t *mode)
16851 +{
16852 +       struct nameidata nd;
16853 +       int ret;
16854 +
16855 +       if (!name) {
16856 +               *dev = 0;
16857 +               return 0;
16858 +       }
16859 +       ret = user_lpath(name, &nd.path);
16860 +       if (ret)
16861 +               return ret;
16862 +       if (nd.path.dentry->d_inode) {
16863 +               *dev = nd.path.dentry->d_inode->i_rdev;
16864 +               *mode = nd.path.dentry->d_inode->i_mode;
16865 +       }
16866 +       path_put(&nd.path);
16867 +       return 0;
16868 +}
16869 +
16870 +static inline int __mapping_mode(dev_t device, dev_t target,
16871 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
16872 +{
16873 +       if (device)
16874 +               *mode = device_mode & S_IFMT;
16875 +       else if (target)
16876 +               *mode = target_mode & S_IFMT;
16877 +       else
16878 +               return -EINVAL;
16879 +
16880 +       /* if both given, device and target mode have to match */
16881 +       if (device && target &&
16882 +               ((device_mode ^ target_mode) & S_IFMT))
16883 +               return -EINVAL;
16884 +       return 0;
16885 +}
16886 +
16887 +
16888 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
16889 +       const char __user *target_path, int flags, int set)
16890 +{
16891 +       dev_t device = ~0, target = ~0;
16892 +       umode_t device_mode = 0, target_mode = 0, mode;
16893 +       int ret;
16894 +
16895 +       ret = __user_device(device_path, &device, &device_mode);
16896 +       if (ret)
16897 +               return ret;
16898 +       ret = __user_device(target_path, &target, &target_mode);
16899 +       if (ret)
16900 +               return ret;
16901 +
16902 +       ret = __mapping_mode(device, target,
16903 +               device_mode, target_mode, &mode);
16904 +       if (ret)
16905 +               return ret;
16906 +
16907 +       if (set)
16908 +               return do_set_mapping(vxi, device, target,
16909 +                       flags, mode);
16910 +       else
16911 +               return do_unset_mapping(vxi, device, target,
16912 +                       flags, mode);
16913 +}
16914 +
16915 +
16916 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
16917 +{
16918 +       struct vcmd_set_mapping_v0 vc_data;
16919 +
16920 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16921 +               return -EFAULT;
16922 +
16923 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16924 +               vc_data.flags, 1);
16925 +}
16926 +
16927 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
16928 +{
16929 +       struct vcmd_set_mapping_v0 vc_data;
16930 +
16931 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16932 +               return -EFAULT;
16933 +
16934 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16935 +               vc_data.flags, 0);
16936 +}
16937 +
16938 +
16939 +#ifdef CONFIG_COMPAT
16940 +
16941 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
16942 +{
16943 +       struct vcmd_set_mapping_v0_x32 vc_data;
16944 +
16945 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16946 +               return -EFAULT;
16947 +
16948 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16949 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
16950 +}
16951 +
16952 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
16953 +{
16954 +       struct vcmd_set_mapping_v0_x32 vc_data;
16955 +
16956 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16957 +               return -EFAULT;
16958 +
16959 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16960 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
16961 +}
16962 +
16963 +#endif /* CONFIG_COMPAT */
16964 +
16965 +
16966 diff -NurpP --minimal linux-3.13.10/kernel/vserver/dlimit.c linux-3.13.10-vs2.3.6.11/kernel/vserver/dlimit.c
16967 --- linux-3.13.10/kernel/vserver/dlimit.c       1970-01-01 00:00:00.000000000 +0000
16968 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/dlimit.c    2014-01-31 20:38:04.000000000 +0000
16969 @@ -0,0 +1,528 @@
16970 +/*
16971 + *  linux/kernel/vserver/dlimit.c
16972 + *
16973 + *  Virtual Server: Context Disk Limits
16974 + *
16975 + *  Copyright (C) 2004-2009  Herbert Pötzl
16976 + *
16977 + *  V0.01  initial version
16978 + *  V0.02  compat32 splitup
16979 + *  V0.03  extended interface
16980 + *
16981 + */
16982 +
16983 +#include <linux/statfs.h>
16984 +#include <linux/sched.h>
16985 +#include <linux/namei.h>
16986 +#include <linux/vs_tag.h>
16987 +#include <linux/vs_dlimit.h>
16988 +#include <linux/vserver/dlimit_cmd.h>
16989 +#include <linux/slab.h>
16990 +// #include <linux/gfp.h>
16991 +
16992 +#include <asm/uaccess.h>
16993 +
16994 +/*     __alloc_dl_info()
16995 +
16996 +       * allocate an initialized dl_info struct
16997 +       * doesn't make it visible (hash)                        */
16998 +
16999 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
17000 +{
17001 +       struct dl_info *new = NULL;
17002 +
17003 +       vxdprintk(VXD_CBIT(dlim, 5),
17004 +               "alloc_dl_info(%p,%d)*", sb, tag);
17005 +
17006 +       /* would this benefit from a slab cache? */
17007 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17008 +       if (!new)
17009 +               return 0;
17010 +
17011 +       memset(new, 0, sizeof(struct dl_info));
17012 +       new->dl_tag = tag;
17013 +       new->dl_sb = sb;
17014 +       // INIT_RCU_HEAD(&new->dl_rcu);
17015 +       INIT_HLIST_NODE(&new->dl_hlist);
17016 +       spin_lock_init(&new->dl_lock);
17017 +       atomic_set(&new->dl_refcnt, 0);
17018 +       atomic_set(&new->dl_usecnt, 0);
17019 +
17020 +       /* rest of init goes here */
17021 +
17022 +       vxdprintk(VXD_CBIT(dlim, 4),
17023 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17024 +       return new;
17025 +}
17026 +
17027 +/*     __dealloc_dl_info()
17028 +
17029 +       * final disposal of dl_info                             */
17030 +
17031 +static void __dealloc_dl_info(struct dl_info *dli)
17032 +{
17033 +       vxdprintk(VXD_CBIT(dlim, 4),
17034 +               "dealloc_dl_info(%p)", dli);
17035 +
17036 +       dli->dl_hlist.next = LIST_POISON1;
17037 +       dli->dl_tag = -1;
17038 +       dli->dl_sb = 0;
17039 +
17040 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17041 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17042 +
17043 +       kfree(dli);
17044 +}
17045 +
17046 +
17047 +/*     hash table for dl_info hash */
17048 +
17049 +#define DL_HASH_SIZE   13
17050 +
17051 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17052 +
17053 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17054 +
17055 +
17056 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
17057 +{
17058 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17059 +}
17060 +
17061 +
17062 +
17063 +/*     __hash_dl_info()
17064 +
17065 +       * add the dli to the global hash table
17066 +       * requires the hash_lock to be held                     */
17067 +
17068 +static inline void __hash_dl_info(struct dl_info *dli)
17069 +{
17070 +       struct hlist_head *head;
17071 +
17072 +       vxdprintk(VXD_CBIT(dlim, 6),
17073 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17074 +       get_dl_info(dli);
17075 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17076 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17077 +}
17078 +
17079 +/*     __unhash_dl_info()
17080 +
17081 +       * remove the dli from the global hash table
17082 +       * requires the hash_lock to be held                     */
17083 +
17084 +static inline void __unhash_dl_info(struct dl_info *dli)
17085 +{
17086 +       vxdprintk(VXD_CBIT(dlim, 6),
17087 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17088 +       hlist_del_rcu(&dli->dl_hlist);
17089 +       put_dl_info(dli);
17090 +}
17091 +
17092 +
17093 +/*     __lookup_dl_info()
17094 +
17095 +       * requires the rcu_read_lock()
17096 +       * doesn't increment the dl_refcnt                       */
17097 +
17098 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
17099 +{
17100 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17101 +       struct dl_info *dli;
17102 +
17103 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17104 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
17105 +                       return dli;
17106 +       }
17107 +       return NULL;
17108 +}
17109 +
17110 +
17111 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
17112 +{
17113 +       struct dl_info *dli;
17114 +
17115 +       rcu_read_lock();
17116 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17117 +       vxdprintk(VXD_CBIT(dlim, 7),
17118 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17119 +       rcu_read_unlock();
17120 +       return dli;
17121 +}
17122 +
17123 +void rcu_free_dl_info(struct rcu_head *head)
17124 +{
17125 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17126 +       int usecnt, refcnt;
17127 +
17128 +       BUG_ON(!dli || !head);
17129 +
17130 +       usecnt = atomic_read(&dli->dl_usecnt);
17131 +       BUG_ON(usecnt < 0);
17132 +
17133 +       refcnt = atomic_read(&dli->dl_refcnt);
17134 +       BUG_ON(refcnt < 0);
17135 +
17136 +       vxdprintk(VXD_CBIT(dlim, 3),
17137 +               "rcu_free_dl_info(%p)", dli);
17138 +       if (!usecnt)
17139 +               __dealloc_dl_info(dli);
17140 +       else
17141 +               printk("!!! rcu didn't free\n");
17142 +}
17143 +
17144 +
17145 +
17146 +
17147 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17148 +       uint32_t flags, int add)
17149 +{
17150 +       struct path path;
17151 +       int ret;
17152 +
17153 +       ret = user_lpath(name, &path);
17154 +       if (!ret) {
17155 +               struct super_block *sb;
17156 +               struct dl_info *dli;
17157 +
17158 +               ret = -EINVAL;
17159 +               if (!path.dentry->d_inode)
17160 +                       goto out_release;
17161 +               if (!(sb = path.dentry->d_inode->i_sb))
17162 +                       goto out_release;
17163 +
17164 +               if (add) {
17165 +                       dli = __alloc_dl_info(sb, id);
17166 +                       spin_lock(&dl_info_hash_lock);
17167 +
17168 +                       ret = -EEXIST;
17169 +                       if (__lookup_dl_info(sb, id))
17170 +                               goto out_unlock;
17171 +                       __hash_dl_info(dli);
17172 +                       dli = NULL;
17173 +               } else {
17174 +                       spin_lock(&dl_info_hash_lock);
17175 +                       dli = __lookup_dl_info(sb, id);
17176 +
17177 +                       ret = -ESRCH;
17178 +                       if (!dli)
17179 +                               goto out_unlock;
17180 +                       __unhash_dl_info(dli);
17181 +               }
17182 +               ret = 0;
17183 +       out_unlock:
17184 +               spin_unlock(&dl_info_hash_lock);
17185 +               if (add && dli)
17186 +                       __dealloc_dl_info(dli);
17187 +       out_release:
17188 +               path_put(&path);
17189 +       }
17190 +       return ret;
17191 +}
17192 +
17193 +int vc_add_dlimit(uint32_t id, void __user *data)
17194 +{
17195 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17196 +
17197 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17198 +               return -EFAULT;
17199 +
17200 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17201 +}
17202 +
17203 +int vc_rem_dlimit(uint32_t id, void __user *data)
17204 +{
17205 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17206 +
17207 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17208 +               return -EFAULT;
17209 +
17210 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17211 +}
17212 +
17213 +#ifdef CONFIG_COMPAT
17214 +
17215 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17216 +{
17217 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17218 +
17219 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17220 +               return -EFAULT;
17221 +
17222 +       return do_addrem_dlimit(id,
17223 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17224 +}
17225 +
17226 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17227 +{
17228 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17229 +
17230 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17231 +               return -EFAULT;
17232 +
17233 +       return do_addrem_dlimit(id,
17234 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17235 +}
17236 +
17237 +#endif /* CONFIG_COMPAT */
17238 +
17239 +
17240 +static inline
17241 +int do_set_dlimit(uint32_t id, const char __user *name,
17242 +       uint32_t space_used, uint32_t space_total,
17243 +       uint32_t inodes_used, uint32_t inodes_total,
17244 +       uint32_t reserved, uint32_t flags)
17245 +{
17246 +       struct path path;
17247 +       int ret;
17248 +
17249 +       ret = user_lpath(name, &path);
17250 +       if (!ret) {
17251 +               struct super_block *sb;
17252 +               struct dl_info *dli;
17253 +
17254 +               ret = -EINVAL;
17255 +               if (!path.dentry->d_inode)
17256 +                       goto out_release;
17257 +               if (!(sb = path.dentry->d_inode->i_sb))
17258 +                       goto out_release;
17259 +
17260 +               /* sanity checks */
17261 +               if ((reserved != CDLIM_KEEP &&
17262 +                       reserved > 100) ||
17263 +                       (inodes_used != CDLIM_KEEP &&
17264 +                       inodes_used > inodes_total) ||
17265 +                       (space_used != CDLIM_KEEP &&
17266 +                       space_used > space_total))
17267 +                       goto out_release;
17268 +
17269 +               ret = -ESRCH;
17270 +               dli = locate_dl_info(sb, id);
17271 +               if (!dli)
17272 +                       goto out_release;
17273 +
17274 +               spin_lock(&dli->dl_lock);
17275 +
17276 +               if (inodes_used != CDLIM_KEEP)
17277 +                       dli->dl_inodes_used = inodes_used;
17278 +               if (inodes_total != CDLIM_KEEP)
17279 +                       dli->dl_inodes_total = inodes_total;
17280 +               if (space_used != CDLIM_KEEP)
17281 +                       dli->dl_space_used = dlimit_space_32to64(
17282 +                               space_used, flags, DLIMS_USED);
17283 +
17284 +               if (space_total == CDLIM_INFINITY)
17285 +                       dli->dl_space_total = DLIM_INFINITY;
17286 +               else if (space_total != CDLIM_KEEP)
17287 +                       dli->dl_space_total = dlimit_space_32to64(
17288 +                               space_total, flags, DLIMS_TOTAL);
17289 +
17290 +               if (reserved != CDLIM_KEEP)
17291 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17292 +
17293 +               spin_unlock(&dli->dl_lock);
17294 +
17295 +               put_dl_info(dli);
17296 +               ret = 0;
17297 +
17298 +       out_release:
17299 +               path_put(&path);
17300 +       }
17301 +       return ret;
17302 +}
17303 +
17304 +int vc_set_dlimit(uint32_t id, void __user *data)
17305 +{
17306 +       struct vcmd_ctx_dlimit_v0 vc_data;
17307 +
17308 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17309 +               return -EFAULT;
17310 +
17311 +       return do_set_dlimit(id, vc_data.name,
17312 +               vc_data.space_used, vc_data.space_total,
17313 +               vc_data.inodes_used, vc_data.inodes_total,
17314 +               vc_data.reserved, vc_data.flags);
17315 +}
17316 +
17317 +#ifdef CONFIG_COMPAT
17318 +
17319 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17320 +{
17321 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17322 +
17323 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17324 +               return -EFAULT;
17325 +
17326 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17327 +               vc_data.space_used, vc_data.space_total,
17328 +               vc_data.inodes_used, vc_data.inodes_total,
17329 +               vc_data.reserved, vc_data.flags);
17330 +}
17331 +
17332 +#endif /* CONFIG_COMPAT */
17333 +
17334 +
17335 +static inline
17336 +int do_get_dlimit(uint32_t id, const char __user *name,
17337 +       uint32_t *space_used, uint32_t *space_total,
17338 +       uint32_t *inodes_used, uint32_t *inodes_total,
17339 +       uint32_t *reserved, uint32_t *flags)
17340 +{
17341 +       struct path path;
17342 +       int ret;
17343 +
17344 +       ret = user_lpath(name, &path);
17345 +       if (!ret) {
17346 +               struct super_block *sb;
17347 +               struct dl_info *dli;
17348 +
17349 +               ret = -EINVAL;
17350 +               if (!path.dentry->d_inode)
17351 +                       goto out_release;
17352 +               if (!(sb = path.dentry->d_inode->i_sb))
17353 +                       goto out_release;
17354 +
17355 +               ret = -ESRCH;
17356 +               dli = locate_dl_info(sb, id);
17357 +               if (!dli)
17358 +                       goto out_release;
17359 +
17360 +               spin_lock(&dli->dl_lock);
17361 +               *inodes_used = dli->dl_inodes_used;
17362 +               *inodes_total = dli->dl_inodes_total;
17363 +
17364 +               *space_used = dlimit_space_64to32(
17365 +                       dli->dl_space_used, flags, DLIMS_USED);
17366 +
17367 +               if (dli->dl_space_total == DLIM_INFINITY)
17368 +                       *space_total = CDLIM_INFINITY;
17369 +               else
17370 +                       *space_total = dlimit_space_64to32(
17371 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
17372 +
17373 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
17374 +               spin_unlock(&dli->dl_lock);
17375 +
17376 +               put_dl_info(dli);
17377 +               ret = -EFAULT;
17378 +
17379 +               ret = 0;
17380 +       out_release:
17381 +               path_put(&path);
17382 +       }
17383 +       return ret;
17384 +}
17385 +
17386 +
17387 +int vc_get_dlimit(uint32_t id, void __user *data)
17388 +{
17389 +       struct vcmd_ctx_dlimit_v0 vc_data;
17390 +       int ret;
17391 +
17392 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17393 +               return -EFAULT;
17394 +
17395 +       ret = do_get_dlimit(id, vc_data.name,
17396 +               &vc_data.space_used, &vc_data.space_total,
17397 +               &vc_data.inodes_used, &vc_data.inodes_total,
17398 +               &vc_data.reserved, &vc_data.flags);
17399 +       if (ret)
17400 +               return ret;
17401 +
17402 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17403 +               return -EFAULT;
17404 +       return 0;
17405 +}
17406 +
17407 +#ifdef CONFIG_COMPAT
17408 +
17409 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
17410 +{
17411 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17412 +       int ret;
17413 +
17414 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17415 +               return -EFAULT;
17416 +
17417 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
17418 +               &vc_data.space_used, &vc_data.space_total,
17419 +               &vc_data.inodes_used, &vc_data.inodes_total,
17420 +               &vc_data.reserved, &vc_data.flags);
17421 +       if (ret)
17422 +               return ret;
17423 +
17424 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17425 +               return -EFAULT;
17426 +       return 0;
17427 +}
17428 +
17429 +#endif /* CONFIG_COMPAT */
17430 +
17431 +
17432 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
17433 +{
17434 +       struct dl_info *dli;
17435 +       __u64 blimit, bfree, bavail;
17436 +       __u32 ifree;
17437 +
17438 +       dli = locate_dl_info(sb, dx_current_tag());
17439 +       if (!dli)
17440 +               return;
17441 +
17442 +       spin_lock(&dli->dl_lock);
17443 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
17444 +               goto no_ilim;
17445 +
17446 +       /* reduce max inodes available to limit */
17447 +       if (buf->f_files > dli->dl_inodes_total)
17448 +               buf->f_files = dli->dl_inodes_total;
17449 +
17450 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
17451 +       /* reduce free inodes to min */
17452 +       if (ifree < buf->f_ffree)
17453 +               buf->f_ffree = ifree;
17454 +
17455 +no_ilim:
17456 +       if (dli->dl_space_total == DLIM_INFINITY)
17457 +               goto no_blim;
17458 +
17459 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
17460 +
17461 +       if (dli->dl_space_total < dli->dl_space_used)
17462 +               bfree = 0;
17463 +       else
17464 +               bfree = (dli->dl_space_total - dli->dl_space_used)
17465 +                       >> sb->s_blocksize_bits;
17466 +
17467 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
17468 +       if (bavail < dli->dl_space_used)
17469 +               bavail = 0;
17470 +       else
17471 +               bavail = (bavail - dli->dl_space_used)
17472 +                       >> sb->s_blocksize_bits;
17473 +
17474 +       /* reduce max space available to limit */
17475 +       if (buf->f_blocks > blimit)
17476 +               buf->f_blocks = blimit;
17477 +
17478 +       /* reduce free space to min */
17479 +       if (bfree < buf->f_bfree)
17480 +               buf->f_bfree = bfree;
17481 +
17482 +       /* reduce avail space to min */
17483 +       if (bavail < buf->f_bavail)
17484 +               buf->f_bavail = bavail;
17485 +
17486 +no_blim:
17487 +       spin_unlock(&dli->dl_lock);
17488 +       put_dl_info(dli);
17489 +
17490 +       return;
17491 +}
17492 +
17493 +#include <linux/module.h>
17494 +
17495 +EXPORT_SYMBOL_GPL(locate_dl_info);
17496 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
17497 +
17498 diff -NurpP --minimal linux-3.13.10/kernel/vserver/helper.c linux-3.13.10-vs2.3.6.11/kernel/vserver/helper.c
17499 --- linux-3.13.10/kernel/vserver/helper.c       1970-01-01 00:00:00.000000000 +0000
17500 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/helper.c    2014-01-31 20:38:04.000000000 +0000
17501 @@ -0,0 +1,242 @@
17502 +/*
17503 + *  linux/kernel/vserver/helper.c
17504 + *
17505 + *  Virtual Context Support
17506 + *
17507 + *  Copyright (C) 2004-2007  Herbert Pötzl
17508 + *
17509 + *  V0.01  basic helper
17510 + *
17511 + */
17512 +
17513 +#include <linux/kmod.h>
17514 +#include <linux/reboot.h>
17515 +#include <linux/vs_context.h>
17516 +#include <linux/vs_network.h>
17517 +#include <linux/vserver/signal.h>
17518 +
17519 +
17520 +char vshelper_path[255] = "/sbin/vshelper";
17521 +
17522 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
17523 +{
17524 +       current->flags &= ~PF_NO_SETAFFINITY;
17525 +       return 0;
17526 +}
17527 +
17528 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
17529 +{
17530 +       struct subprocess_info *info;
17531 +       gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
17532 +
17533 +       info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
17534 +                                        vshelper_init, NULL, NULL);
17535 +       if (info == NULL)
17536 +               return -ENOMEM;
17537 +
17538 +       return call_usermodehelper_exec(info, wait);
17539 +}
17540 +
17541 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
17542 +{
17543 +       int ret;
17544 +
17545 +       if ((ret = vs_call_usermodehelper(name, argv, envp,
17546 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
17547 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
17548 +                       name, argv[1], argv[2],
17549 +                       sync ? "sync" : "async", ret);
17550 +       }
17551 +       vxdprintk(VXD_CBIT(switch, 4),
17552 +               "%s: (%s %s) returned %s with %d",
17553 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
17554 +       return ret;
17555 +}
17556 +
17557 +/*
17558 + *      vshelper path is set via /proc/sys
17559 + *      invoked by vserver sys_reboot(), with
17560 + *      the following arguments
17561 + *
17562 + *      argv [0] = vshelper_path;
17563 + *      argv [1] = action: "restart", "halt", "poweroff", ...
17564 + *      argv [2] = context identifier
17565 + *
17566 + *      envp [*] = type-specific parameters
17567 + */
17568 +
17569 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
17570 +{
17571 +       char id_buf[8], cmd_buf[16];
17572 +       char uid_buf[16], pid_buf[16];
17573 +       int ret;
17574 +
17575 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17576 +       char *envp[] = {"HOME=/", "TERM=linux",
17577 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
17578 +                       uid_buf, pid_buf, cmd_buf, 0};
17579 +
17580 +       if (vx_info_state(vxi, VXS_HELPER))
17581 +               return -EAGAIN;
17582 +       vxi->vx_state |= VXS_HELPER;
17583 +
17584 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17585 +
17586 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17587 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
17588 +               from_kuid(&init_user_ns, current_uid()));
17589 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
17590 +
17591 +       switch (cmd) {
17592 +       case LINUX_REBOOT_CMD_RESTART:
17593 +               argv[1] = "restart";
17594 +               break;
17595 +
17596 +       case LINUX_REBOOT_CMD_HALT:
17597 +               argv[1] = "halt";
17598 +               break;
17599 +
17600 +       case LINUX_REBOOT_CMD_POWER_OFF:
17601 +               argv[1] = "poweroff";
17602 +               break;
17603 +
17604 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
17605 +               argv[1] = "swsusp";
17606 +               break;
17607 +
17608 +       case LINUX_REBOOT_CMD_OOM:
17609 +               argv[1] = "oom";
17610 +               break;
17611 +
17612 +       default:
17613 +               vxi->vx_state &= ~VXS_HELPER;
17614 +               return 0;
17615 +       }
17616 +
17617 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
17618 +       vxi->vx_state &= ~VXS_HELPER;
17619 +       __wakeup_vx_info(vxi);
17620 +       return (ret) ? -EPERM : 0;
17621 +}
17622 +
17623 +
17624 +long vs_reboot(unsigned int cmd, void __user *arg)
17625 +{
17626 +       struct vx_info *vxi = current_vx_info();
17627 +       long ret = 0;
17628 +
17629 +       vxdprintk(VXD_CBIT(misc, 5),
17630 +               "vs_reboot(%p[#%d],%u)",
17631 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17632 +
17633 +       ret = vs_reboot_helper(vxi, cmd, arg);
17634 +       if (ret)
17635 +               return ret;
17636 +
17637 +       vxi->reboot_cmd = cmd;
17638 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17639 +               switch (cmd) {
17640 +               case LINUX_REBOOT_CMD_RESTART:
17641 +               case LINUX_REBOOT_CMD_HALT:
17642 +               case LINUX_REBOOT_CMD_POWER_OFF:
17643 +                       vx_info_kill(vxi, 0, SIGKILL);
17644 +                       vx_info_kill(vxi, 1, SIGKILL);
17645 +               default:
17646 +                       break;
17647 +               }
17648 +       }
17649 +       return 0;
17650 +}
17651 +
17652 +long vs_oom_action(unsigned int cmd)
17653 +{
17654 +       struct vx_info *vxi = current_vx_info();
17655 +       long ret = 0;
17656 +
17657 +       vxdprintk(VXD_CBIT(misc, 5),
17658 +               "vs_oom_action(%p[#%d],%u)",
17659 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17660 +
17661 +       ret = vs_reboot_helper(vxi, cmd, NULL);
17662 +       if (ret)
17663 +               return ret;
17664 +
17665 +       vxi->reboot_cmd = cmd;
17666 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17667 +               vx_info_kill(vxi, 0, SIGKILL);
17668 +               vx_info_kill(vxi, 1, SIGKILL);
17669 +       }
17670 +       return 0;
17671 +}
17672 +
17673 +/*
17674 + *      argv [0] = vshelper_path;
17675 + *      argv [1] = action: "startup", "shutdown"
17676 + *      argv [2] = context identifier
17677 + *
17678 + *      envp [*] = type-specific parameters
17679 + */
17680 +
17681 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
17682 +{
17683 +       char id_buf[8], cmd_buf[16];
17684 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17685 +       char *envp[] = {"HOME=/", "TERM=linux",
17686 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17687 +
17688 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
17689 +               return 0;
17690 +
17691 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17692 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17693 +
17694 +       switch (cmd) {
17695 +       case VSC_STARTUP:
17696 +               argv[1] = "startup";
17697 +               break;
17698 +       case VSC_SHUTDOWN:
17699 +               argv[1] = "shutdown";
17700 +               break;
17701 +       default:
17702 +               return 0;
17703 +       }
17704 +
17705 +       return do_vshelper(vshelper_path, argv, envp, 1);
17706 +}
17707 +
17708 +
17709 +/*
17710 + *      argv [0] = vshelper_path;
17711 + *      argv [1] = action: "netup", "netdown"
17712 + *      argv [2] = context identifier
17713 + *
17714 + *      envp [*] = type-specific parameters
17715 + */
17716 +
17717 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
17718 +{
17719 +       char id_buf[8], cmd_buf[16];
17720 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17721 +       char *envp[] = {"HOME=/", "TERM=linux",
17722 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17723 +
17724 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
17725 +               return 0;
17726 +
17727 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
17728 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17729 +
17730 +       switch (cmd) {
17731 +       case VSC_NETUP:
17732 +               argv[1] = "netup";
17733 +               break;
17734 +       case VSC_NETDOWN:
17735 +               argv[1] = "netdown";
17736 +               break;
17737 +       default:
17738 +               return 0;
17739 +       }
17740 +
17741 +       return do_vshelper(vshelper_path, argv, envp, 1);
17742 +}
17743 +
17744 diff -NurpP --minimal linux-3.13.10/kernel/vserver/history.c linux-3.13.10-vs2.3.6.11/kernel/vserver/history.c
17745 --- linux-3.13.10/kernel/vserver/history.c      1970-01-01 00:00:00.000000000 +0000
17746 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/history.c   2014-01-31 20:38:04.000000000 +0000
17747 @@ -0,0 +1,258 @@
17748 +/*
17749 + *  kernel/vserver/history.c
17750 + *
17751 + *  Virtual Context History Backtrace
17752 + *
17753 + *  Copyright (C) 2004-2007  Herbert Pötzl
17754 + *
17755 + *  V0.01  basic structure
17756 + *  V0.02  hash/unhash and trace
17757 + *  V0.03  preemption fixes
17758 + *
17759 + */
17760 +
17761 +#include <linux/module.h>
17762 +#include <asm/uaccess.h>
17763 +
17764 +#include <linux/vserver/context.h>
17765 +#include <linux/vserver/debug.h>
17766 +#include <linux/vserver/debug_cmd.h>
17767 +#include <linux/vserver/history.h>
17768 +
17769 +
17770 +#ifdef CONFIG_VSERVER_HISTORY
17771 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
17772 +#else
17773 +#define VXH_SIZE       64
17774 +#endif
17775 +
17776 +struct _vx_history {
17777 +       unsigned int counter;
17778 +
17779 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
17780 +};
17781 +
17782 +
17783 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
17784 +
17785 +unsigned volatile int vxh_active = 1;
17786 +
17787 +static atomic_t sequence = ATOMIC_INIT(0);
17788 +
17789 +
17790 +/*     vxh_advance()
17791 +
17792 +       * requires disabled preemption                          */
17793 +
17794 +struct _vx_hist_entry *vxh_advance(void *loc)
17795 +{
17796 +       unsigned int cpu = smp_processor_id();
17797 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17798 +       struct _vx_hist_entry *entry;
17799 +       unsigned int index;
17800 +
17801 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
17802 +       entry = &hist->entry[index];
17803 +
17804 +       entry->seq = atomic_inc_return(&sequence);
17805 +       entry->loc = loc;
17806 +       return entry;
17807 +}
17808 +
17809 +EXPORT_SYMBOL_GPL(vxh_advance);
17810 +
17811 +
17812 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
17813 +
17814 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
17815 +
17816 +
17817 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
17818 +
17819 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
17820 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
17821 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
17822 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
17823 +
17824 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
17825 +{
17826 +       switch (e->type) {
17827 +       case VXH_THROW_OOPS:
17828 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
17829 +               break;
17830 +
17831 +       case VXH_GET_VX_INFO:
17832 +       case VXH_PUT_VX_INFO:
17833 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17834 +                       VXH_LOC_ARGS(e),
17835 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
17836 +                       VXH_VXI_ARGS(e));
17837 +               break;
17838 +
17839 +       case VXH_INIT_VX_INFO:
17840 +       case VXH_SET_VX_INFO:
17841 +       case VXH_CLR_VX_INFO:
17842 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17843 +                       VXH_LOC_ARGS(e),
17844 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
17845 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
17846 +                       VXH_VXI_ARGS(e), e->sc.data);
17847 +               break;
17848 +
17849 +       case VXH_CLAIM_VX_INFO:
17850 +       case VXH_RELEASE_VX_INFO:
17851 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17852 +                       VXH_LOC_ARGS(e),
17853 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
17854 +                       VXH_VXI_ARGS(e), e->sc.data);
17855 +               break;
17856 +
17857 +       case VXH_ALLOC_VX_INFO:
17858 +       case VXH_DEALLOC_VX_INFO:
17859 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17860 +                       VXH_LOC_ARGS(e),
17861 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
17862 +                       VXH_VXI_ARGS(e));
17863 +               break;
17864 +
17865 +       case VXH_HASH_VX_INFO:
17866 +       case VXH_UNHASH_VX_INFO:
17867 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
17868 +                       VXH_LOC_ARGS(e),
17869 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
17870 +                       VXH_VXI_ARGS(e));
17871 +               break;
17872 +
17873 +       case VXH_LOC_VX_INFO:
17874 +       case VXH_LOOKUP_VX_INFO:
17875 +       case VXH_CREATE_VX_INFO:
17876 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
17877 +                       VXH_LOC_ARGS(e),
17878 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
17879 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
17880 +                       e->ll.arg, VXH_VXI_ARGS(e));
17881 +               break;
17882 +       }
17883 +}
17884 +
17885 +static void __vxh_dump_history(void)
17886 +{
17887 +       unsigned int i, cpu;
17888 +
17889 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
17890 +               atomic_read(&sequence), NR_CPUS);
17891 +
17892 +       for (i = 0; i < VXH_SIZE; i++) {
17893 +               for_each_online_cpu(cpu) {
17894 +                       struct _vx_history *hist =
17895 +                               &per_cpu(vx_history_buffer, cpu);
17896 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
17897 +                       struct _vx_hist_entry *entry = &hist->entry[index];
17898 +
17899 +                       vxh_dump_entry(entry, cpu);
17900 +               }
17901 +       }
17902 +}
17903 +
17904 +void   vxh_dump_history(void)
17905 +{
17906 +       vxh_active = 0;
17907 +#ifdef CONFIG_SMP
17908 +       local_irq_enable();
17909 +       smp_send_stop();
17910 +       local_irq_disable();
17911 +#endif
17912 +       __vxh_dump_history();
17913 +}
17914 +
17915 +
17916 +/* vserver syscall commands below here */
17917 +
17918 +
17919 +int vc_dump_history(uint32_t id)
17920 +{
17921 +       vxh_active = 0;
17922 +       __vxh_dump_history();
17923 +       vxh_active = 1;
17924 +
17925 +       return 0;
17926 +}
17927 +
17928 +
17929 +int do_read_history(struct __user _vx_hist_entry *data,
17930 +       int cpu, uint32_t *index, uint32_t *count)
17931 +{
17932 +       int pos, ret = 0;
17933 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17934 +       int end = hist->counter;
17935 +       int start = end - VXH_SIZE + 2;
17936 +       int idx = *index;
17937 +
17938 +       /* special case: get current pos */
17939 +       if (!*count) {
17940 +               *index = end;
17941 +               return 0;
17942 +       }
17943 +
17944 +       /* have we lost some data? */
17945 +       if (idx < start)
17946 +               idx = start;
17947 +
17948 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
17949 +               struct _vx_hist_entry *entry =
17950 +                       &hist->entry[idx % VXH_SIZE];
17951 +
17952 +               /* send entry to userspace */
17953 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
17954 +               if (ret)
17955 +                       break;
17956 +       }
17957 +       /* save new index and count */
17958 +       *index = idx;
17959 +       *count = pos;
17960 +       return ret ? ret : (*index < end);
17961 +}
17962 +
17963 +int vc_read_history(uint32_t id, void __user *data)
17964 +{
17965 +       struct vcmd_read_history_v0 vc_data;
17966 +       int ret;
17967 +
17968 +       if (id >= NR_CPUS)
17969 +               return -EINVAL;
17970 +
17971 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17972 +               return -EFAULT;
17973 +
17974 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
17975 +               id, &vc_data.index, &vc_data.count);
17976 +
17977 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17978 +               return -EFAULT;
17979 +       return ret;
17980 +}
17981 +
17982 +#ifdef CONFIG_COMPAT
17983 +
17984 +int vc_read_history_x32(uint32_t id, void __user *data)
17985 +{
17986 +       struct vcmd_read_history_v0_x32 vc_data;
17987 +       int ret;
17988 +
17989 +       if (id >= NR_CPUS)
17990 +               return -EINVAL;
17991 +
17992 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17993 +               return -EFAULT;
17994 +
17995 +       ret = do_read_history((struct __user _vx_hist_entry *)
17996 +               compat_ptr(vc_data.data_ptr),
17997 +               id, &vc_data.index, &vc_data.count);
17998 +
17999 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18000 +               return -EFAULT;
18001 +       return ret;
18002 +}
18003 +
18004 +#endif /* CONFIG_COMPAT */
18005 +
18006 diff -NurpP --minimal linux-3.13.10/kernel/vserver/inet.c linux-3.13.10-vs2.3.6.11/kernel/vserver/inet.c
18007 --- linux-3.13.10/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
18008 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/inet.c      2014-02-01 00:26:40.000000000 +0000
18009 @@ -0,0 +1,236 @@
18010 +
18011 +#include <linux/in.h>
18012 +#include <linux/inetdevice.h>
18013 +#include <linux/export.h>
18014 +#include <linux/vs_inet.h>
18015 +#include <linux/vs_inet6.h>
18016 +#include <linux/vserver/debug.h>
18017 +#include <net/route.h>
18018 +#include <net/addrconf.h>
18019 +
18020 +
18021 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18022 +{
18023 +       int ret = 0;
18024 +
18025 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18026 +               ret = 1;
18027 +       else {
18028 +               struct nx_addr_v4 *ptr;
18029 +               unsigned long irqflags;
18030 +
18031 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18032 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18033 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18034 +                               ret = 1;
18035 +                               break;
18036 +                       }
18037 +               }
18038 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18039 +       }
18040 +
18041 +       vxdprintk(VXD_CBIT(net, 2),
18042 +               "nx_v4_addr_conflict(%p,%p): %d",
18043 +               nxi1, nxi2, ret);
18044 +
18045 +       return ret;
18046 +}
18047 +
18048 +
18049 +#ifdef CONFIG_IPV6
18050 +
18051 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18052 +{
18053 +       int ret = 0;
18054 +
18055 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18056 +               ret = 1;
18057 +       else {
18058 +               struct nx_addr_v6 *ptr;
18059 +               unsigned long irqflags;
18060 +
18061 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18062 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18063 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18064 +                               ret = 1;
18065 +                               break;
18066 +                       }
18067 +               }
18068 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18069 +       }
18070 +
18071 +       vxdprintk(VXD_CBIT(net, 2),
18072 +               "nx_v6_addr_conflict(%p,%p): %d",
18073 +               nxi1, nxi2, ret);
18074 +
18075 +       return ret;
18076 +}
18077 +
18078 +#endif
18079 +
18080 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18081 +{
18082 +       struct in_device *in_dev;
18083 +       struct in_ifaddr **ifap;
18084 +       struct in_ifaddr *ifa;
18085 +       int ret = 0;
18086 +
18087 +       if (!dev)
18088 +               goto out;
18089 +       in_dev = in_dev_get(dev);
18090 +       if (!in_dev)
18091 +               goto out;
18092 +
18093 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18094 +               ifap = &ifa->ifa_next) {
18095 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18096 +                       ret = 1;
18097 +                       break;
18098 +               }
18099 +       }
18100 +       in_dev_put(in_dev);
18101 +out:
18102 +       return ret;
18103 +}
18104 +
18105 +
18106 +#ifdef CONFIG_IPV6
18107 +
18108 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18109 +{
18110 +       struct inet6_dev *in_dev;
18111 +       struct inet6_ifaddr *ifa;
18112 +       int ret = 0;
18113 +
18114 +       if (!dev)
18115 +               goto out;
18116 +       in_dev = in6_dev_get(dev);
18117 +       if (!in_dev)
18118 +               goto out;
18119 +
18120 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18121 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18122 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18123 +                       ret = 1;
18124 +                       break;
18125 +               }
18126 +       }
18127 +       in6_dev_put(in_dev);
18128 +out:
18129 +       return ret;
18130 +}
18131 +
18132 +#endif
18133 +
18134 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18135 +{
18136 +       int ret = 1;
18137 +
18138 +       if (!nxi)
18139 +               goto out;
18140 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18141 +               goto out;
18142 +#ifdef CONFIG_IPV6
18143 +       ret = 2;
18144 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18145 +               goto out;
18146 +#endif
18147 +       ret = 0;
18148 +out:
18149 +       vxdprintk(VXD_CBIT(net, 3),
18150 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18151 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18152 +       return ret;
18153 +}
18154 +
18155 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18156 +       struct flowi4 *fl4)
18157 +{
18158 +       struct rtable *rt;
18159 +
18160 +       if (!nxi)
18161 +               return NULL;
18162 +
18163 +       /* FIXME: handle lback only case */
18164 +       if (!NX_IPV4(nxi))
18165 +               return ERR_PTR(-EPERM);
18166 +
18167 +       vxdprintk(VXD_CBIT(net, 4),
18168 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18169 +               nxi, nxi ? nxi->nx_id : 0,
18170 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18171 +
18172 +       /* single IP is unconditional */
18173 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18174 +               (fl4->saddr == INADDR_ANY))
18175 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18176 +
18177 +       if (fl4->saddr == INADDR_ANY) {
18178 +               struct nx_addr_v4 *ptr;
18179 +               __be32 found = 0;
18180 +
18181 +               rt = __ip_route_output_key(net, fl4);
18182 +               if (!IS_ERR(rt)) {
18183 +                       found = fl4->saddr;
18184 +                       ip_rt_put(rt);
18185 +                       vxdprintk(VXD_CBIT(net, 4),
18186 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18187 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18188 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18189 +                               goto found;
18190 +               }
18191 +
18192 +               WARN_ON_ONCE(in_irq());
18193 +               spin_lock_bh(&nxi->addr_lock);
18194 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18195 +                       __be32 primary = ptr->ip[0].s_addr;
18196 +                       __be32 mask = ptr->mask.s_addr;
18197 +                       __be32 neta = primary & mask;
18198 +
18199 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18200 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18201 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18202 +                               NIPQUAD(mask), NIPQUAD(neta));
18203 +                       if ((found & mask) != neta)
18204 +                               continue;
18205 +
18206 +                       fl4->saddr = primary;
18207 +                       rt = __ip_route_output_key(net, fl4);
18208 +                       vxdprintk(VXD_CBIT(net, 4),
18209 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18210 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18211 +                       if (!IS_ERR(rt)) {
18212 +                               found = fl4->saddr;
18213 +                               ip_rt_put(rt);
18214 +                               if (found == primary)
18215 +                                       goto found_unlock;
18216 +                       }
18217 +               }
18218 +               /* still no source ip? */
18219 +               found = ipv4_is_loopback(fl4->daddr)
18220 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18221 +       found_unlock:
18222 +               spin_unlock_bh(&nxi->addr_lock);
18223 +       found:
18224 +               /* assign src ip to flow */
18225 +               fl4->saddr = found;
18226 +
18227 +       } else {
18228 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18229 +                       return ERR_PTR(-EPERM);
18230 +       }
18231 +
18232 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18233 +               if (ipv4_is_loopback(fl4->daddr))
18234 +                       fl4->daddr = nxi->v4_lback.s_addr;
18235 +               if (ipv4_is_loopback(fl4->saddr))
18236 +                       fl4->saddr = nxi->v4_lback.s_addr;
18237 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18238 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18239 +               return ERR_PTR(-EPERM);
18240 +
18241 +       return NULL;
18242 +}
18243 +
18244 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18245 +
18246 diff -NurpP --minimal linux-3.13.10/kernel/vserver/init.c linux-3.13.10-vs2.3.6.11/kernel/vserver/init.c
18247 --- linux-3.13.10/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
18248 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/init.c      2014-01-31 20:38:04.000000000 +0000
18249 @@ -0,0 +1,45 @@
18250 +/*
18251 + *  linux/kernel/init.c
18252 + *
18253 + *  Virtual Server Init
18254 + *
18255 + *  Copyright (C) 2004-2007  Herbert Pötzl
18256 + *
18257 + *  V0.01  basic structure
18258 + *
18259 + */
18260 +
18261 +#include <linux/init.h>
18262 +
18263 +int    vserver_register_sysctl(void);
18264 +void   vserver_unregister_sysctl(void);
18265 +
18266 +
18267 +static int __init init_vserver(void)
18268 +{
18269 +       int ret = 0;
18270 +
18271 +#ifdef CONFIG_VSERVER_DEBUG
18272 +       vserver_register_sysctl();
18273 +#endif
18274 +       return ret;
18275 +}
18276 +
18277 +
18278 +static void __exit exit_vserver(void)
18279 +{
18280 +
18281 +#ifdef CONFIG_VSERVER_DEBUG
18282 +       vserver_unregister_sysctl();
18283 +#endif
18284 +       return;
18285 +}
18286 +
18287 +/* FIXME: GFP_ZONETYPES gone
18288 +long vx_slab[GFP_ZONETYPES]; */
18289 +long vx_area;
18290 +
18291 +
18292 +module_init(init_vserver);
18293 +module_exit(exit_vserver);
18294 +
18295 diff -NurpP --minimal linux-3.13.10/kernel/vserver/inode.c linux-3.13.10-vs2.3.6.11/kernel/vserver/inode.c
18296 --- linux-3.13.10/kernel/vserver/inode.c        1970-01-01 00:00:00.000000000 +0000
18297 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/inode.c     2014-01-31 20:38:04.000000000 +0000
18298 @@ -0,0 +1,440 @@
18299 +/*
18300 + *  linux/kernel/vserver/inode.c
18301 + *
18302 + *  Virtual Server: File System Support
18303 + *
18304 + *  Copyright (C) 2004-2007  Herbert Pötzl
18305 + *
18306 + *  V0.01  separated from vcontext V0.05
18307 + *  V0.02  moved to tag (instead of xid)
18308 + *
18309 + */
18310 +
18311 +#include <linux/tty.h>
18312 +#include <linux/proc_fs.h>
18313 +#include <linux/devpts_fs.h>
18314 +#include <linux/fs.h>
18315 +#include <linux/file.h>
18316 +#include <linux/mount.h>
18317 +#include <linux/parser.h>
18318 +#include <linux/namei.h>
18319 +#include <linux/magic.h>
18320 +#include <linux/slab.h>
18321 +#include <linux/vserver/inode.h>
18322 +#include <linux/vserver/inode_cmd.h>
18323 +#include <linux/vs_base.h>
18324 +#include <linux/vs_tag.h>
18325 +
18326 +#include <asm/uaccess.h>
18327 +#include <../../fs/proc/internal.h>
18328 +
18329 +
18330 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18331 +{
18332 +       struct proc_dir_entry *entry;
18333 +
18334 +       if (!in || !in->i_sb)
18335 +               return -ESRCH;
18336 +
18337 +       *flags = IATTR_TAG
18338 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18339 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18340 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18341 +               | (IS_COW(in) ? IATTR_COW : 0);
18342 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18343 +
18344 +       if (S_ISDIR(in->i_mode))
18345 +               *mask |= IATTR_BARRIER;
18346 +
18347 +       if (IS_TAGGED(in)) {
18348 +               *tag = i_tag_read(in);
18349 +               *mask |= IATTR_TAG;
18350 +       }
18351 +
18352 +       switch (in->i_sb->s_magic) {
18353 +       case PROC_SUPER_MAGIC:
18354 +               entry = PROC_I(in)->pde;
18355 +
18356 +               /* check for specific inodes? */
18357 +               if (entry)
18358 +                       *mask |= IATTR_FLAGS;
18359 +               if (entry)
18360 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
18361 +               else
18362 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
18363 +               break;
18364 +
18365 +       case DEVPTS_SUPER_MAGIC:
18366 +               *tag = i_tag_read(in);
18367 +               *mask |= IATTR_TAG;
18368 +               break;
18369 +
18370 +       default:
18371 +               break;
18372 +       }
18373 +       return 0;
18374 +}
18375 +
18376 +int vc_get_iattr(void __user *data)
18377 +{
18378 +       struct path path;
18379 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
18380 +       int ret;
18381 +
18382 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18383 +               return -EFAULT;
18384 +
18385 +       ret = user_lpath(vc_data.name, &path);
18386 +       if (!ret) {
18387 +               ret = __vc_get_iattr(path.dentry->d_inode,
18388 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18389 +               path_put(&path);
18390 +       }
18391 +       if (ret)
18392 +               return ret;
18393 +
18394 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18395 +               ret = -EFAULT;
18396 +       return ret;
18397 +}
18398 +
18399 +#ifdef CONFIG_COMPAT
18400 +
18401 +int vc_get_iattr_x32(void __user *data)
18402 +{
18403 +       struct path path;
18404 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
18405 +       int ret;
18406 +
18407 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18408 +               return -EFAULT;
18409 +
18410 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18411 +       if (!ret) {
18412 +               ret = __vc_get_iattr(path.dentry->d_inode,
18413 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18414 +               path_put(&path);
18415 +       }
18416 +       if (ret)
18417 +               return ret;
18418 +
18419 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18420 +               ret = -EFAULT;
18421 +       return ret;
18422 +}
18423 +
18424 +#endif /* CONFIG_COMPAT */
18425 +
18426 +
18427 +int vc_fget_iattr(uint32_t fd, void __user *data)
18428 +{
18429 +       struct file *filp;
18430 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
18431 +       int ret;
18432 +
18433 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18434 +               return -EFAULT;
18435 +
18436 +       filp = fget(fd);
18437 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18438 +               return -EBADF;
18439 +
18440 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
18441 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
18442 +
18443 +       fput(filp);
18444 +
18445 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18446 +               ret = -EFAULT;
18447 +       return ret;
18448 +}
18449 +
18450 +
18451 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18452 +{
18453 +       struct inode *in = de->d_inode;
18454 +       int error = 0, is_proc = 0, has_tag = 0;
18455 +       struct iattr attr = { 0 };
18456 +
18457 +       if (!in || !in->i_sb)
18458 +               return -ESRCH;
18459 +
18460 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
18461 +       if ((*mask & IATTR_FLAGS) && !is_proc)
18462 +               return -EINVAL;
18463 +
18464 +       has_tag = IS_TAGGED(in) ||
18465 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
18466 +       if ((*mask & IATTR_TAG) && !has_tag)
18467 +               return -EINVAL;
18468 +
18469 +       mutex_lock(&in->i_mutex);
18470 +       if (*mask & IATTR_TAG) {
18471 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
18472 +               attr.ia_valid |= ATTR_TAG;
18473 +       }
18474 +
18475 +       if (*mask & IATTR_FLAGS) {
18476 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
18477 +               unsigned int iflags = PROC_I(in)->vx_flags;
18478 +
18479 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
18480 +                       | (*flags & IATTR_FLAGS);
18481 +               PROC_I(in)->vx_flags = iflags;
18482 +               if (entry)
18483 +                       entry->vx_flags = iflags;
18484 +       }
18485 +
18486 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
18487 +               IATTR_BARRIER | IATTR_COW)) {
18488 +               int iflags = in->i_flags;
18489 +               int vflags = in->i_vflags;
18490 +
18491 +               if (*mask & IATTR_IMMUTABLE) {
18492 +                       if (*flags & IATTR_IMMUTABLE)
18493 +                               iflags |= S_IMMUTABLE;
18494 +                       else
18495 +                               iflags &= ~S_IMMUTABLE;
18496 +               }
18497 +               if (*mask & IATTR_IXUNLINK) {
18498 +                       if (*flags & IATTR_IXUNLINK)
18499 +                               iflags |= S_IXUNLINK;
18500 +                       else
18501 +                               iflags &= ~S_IXUNLINK;
18502 +               }
18503 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
18504 +                       if (*flags & IATTR_BARRIER)
18505 +                               vflags |= V_BARRIER;
18506 +                       else
18507 +                               vflags &= ~V_BARRIER;
18508 +               }
18509 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
18510 +                       if (*flags & IATTR_COW)
18511 +                               vflags |= V_COW;
18512 +                       else
18513 +                               vflags &= ~V_COW;
18514 +               }
18515 +               if (in->i_op && in->i_op->sync_flags) {
18516 +                       error = in->i_op->sync_flags(in, iflags, vflags);
18517 +                       if (error)
18518 +                               goto out;
18519 +               }
18520 +       }
18521 +
18522 +       if (attr.ia_valid) {
18523 +               if (in->i_op && in->i_op->setattr)
18524 +                       error = in->i_op->setattr(de, &attr);
18525 +               else {
18526 +                       error = inode_change_ok(in, &attr);
18527 +                       if (!error) {
18528 +                               setattr_copy(in, &attr);
18529 +                               mark_inode_dirty(in);
18530 +                       }
18531 +               }
18532 +       }
18533 +
18534 +out:
18535 +       mutex_unlock(&in->i_mutex);
18536 +       return error;
18537 +}
18538 +
18539 +int vc_set_iattr(void __user *data)
18540 +{
18541 +       struct path path;
18542 +       struct vcmd_ctx_iattr_v1 vc_data;
18543 +       int ret;
18544 +
18545 +       if (!capable(CAP_LINUX_IMMUTABLE))
18546 +               return -EPERM;
18547 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18548 +               return -EFAULT;
18549 +
18550 +       ret = user_lpath(vc_data.name, &path);
18551 +       if (!ret) {
18552 +               ret = __vc_set_iattr(path.dentry,
18553 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18554 +               path_put(&path);
18555 +       }
18556 +
18557 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18558 +               ret = -EFAULT;
18559 +       return ret;
18560 +}
18561 +
18562 +#ifdef CONFIG_COMPAT
18563 +
18564 +int vc_set_iattr_x32(void __user *data)
18565 +{
18566 +       struct path path;
18567 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
18568 +       int ret;
18569 +
18570 +       if (!capable(CAP_LINUX_IMMUTABLE))
18571 +               return -EPERM;
18572 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18573 +               return -EFAULT;
18574 +
18575 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18576 +       if (!ret) {
18577 +               ret = __vc_set_iattr(path.dentry,
18578 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18579 +               path_put(&path);
18580 +       }
18581 +
18582 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18583 +               ret = -EFAULT;
18584 +       return ret;
18585 +}
18586 +
18587 +#endif /* CONFIG_COMPAT */
18588 +
18589 +int vc_fset_iattr(uint32_t fd, void __user *data)
18590 +{
18591 +       struct file *filp;
18592 +       struct vcmd_ctx_fiattr_v0 vc_data;
18593 +       int ret;
18594 +
18595 +       if (!capable(CAP_LINUX_IMMUTABLE))
18596 +               return -EPERM;
18597 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18598 +               return -EFAULT;
18599 +
18600 +       filp = fget(fd);
18601 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18602 +               return -EBADF;
18603 +
18604 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
18605 +               &vc_data.flags, &vc_data.mask);
18606 +
18607 +       fput(filp);
18608 +
18609 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18610 +               return -EFAULT;
18611 +       return ret;
18612 +}
18613 +
18614 +
18615 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
18616 +
18617 +static match_table_t tokens = {
18618 +       {Opt_notagcheck, "notagcheck"},
18619 +#ifdef CONFIG_PROPAGATE
18620 +       {Opt_notag, "notag"},
18621 +       {Opt_tag, "tag"},
18622 +       {Opt_tagid, "tagid=%u"},
18623 +#endif
18624 +       {Opt_err, NULL}
18625 +};
18626 +
18627 +
18628 +static void __dx_parse_remove(char *string, char *opt)
18629 +{
18630 +       char *p = strstr(string, opt);
18631 +       char *q = p;
18632 +
18633 +       if (p) {
18634 +               while (*q != '\0' && *q != ',')
18635 +                       q++;
18636 +               while (*q)
18637 +                       *p++ = *q++;
18638 +               while (*p)
18639 +                       *p++ = '\0';
18640 +       }
18641 +}
18642 +
18643 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
18644 +                unsigned long *flags)
18645 +{
18646 +       int set = 0;
18647 +       substring_t args[MAX_OPT_ARGS];
18648 +       int token;
18649 +       char *s, *p, *opts;
18650 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
18651 +       int option = 0;
18652 +#endif
18653 +
18654 +       if (!string)
18655 +               return 0;
18656 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
18657 +       if (!s)
18658 +               return 0;
18659 +
18660 +       opts = s;
18661 +       while ((p = strsep(&opts, ",")) != NULL) {
18662 +               token = match_token(p, tokens, args);
18663 +
18664 +               switch (token) {
18665 +#ifdef CONFIG_PROPAGATE
18666 +               case Opt_tag:
18667 +                       if (tag)
18668 +                               *tag = 0;
18669 +                       if (remove)
18670 +                               __dx_parse_remove(s, "tag");
18671 +                       *mnt_flags |= MNT_TAGID;
18672 +                       set |= MNT_TAGID;
18673 +                       break;
18674 +               case Opt_notag:
18675 +                       if (remove)
18676 +                               __dx_parse_remove(s, "notag");
18677 +                       *mnt_flags |= MNT_NOTAG;
18678 +                       set |= MNT_NOTAG;
18679 +                       break;
18680 +               case Opt_tagid:
18681 +                       if (tag && !match_int(args, &option))
18682 +                               *tag = option;
18683 +                       if (remove)
18684 +                               __dx_parse_remove(s, "tagid");
18685 +                       *mnt_flags |= MNT_TAGID;
18686 +                       set |= MNT_TAGID;
18687 +                       break;
18688 +#endif /* CONFIG_PROPAGATE */
18689 +               case Opt_notagcheck:
18690 +                       if (remove)
18691 +                               __dx_parse_remove(s, "notagcheck");
18692 +                       *flags |= MS_NOTAGCHECK;
18693 +                       set |= MS_NOTAGCHECK;
18694 +                       break;
18695 +               }
18696 +               vxdprintk(VXD_CBIT(tag, 7),
18697 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
18698 +                       p, token, option);
18699 +       }
18700 +       if (set)
18701 +               strcpy(string, s);
18702 +       kfree(s);
18703 +       return set;
18704 +}
18705 +
18706 +#ifdef CONFIG_PROPAGATE
18707 +
18708 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
18709 +{
18710 +       vtag_t new_tag = 0;
18711 +       struct vfsmount *mnt;
18712 +       int propagate;
18713 +
18714 +       if (!nd)
18715 +               return;
18716 +       mnt = nd->path.mnt;
18717 +       if (!mnt)
18718 +               return;
18719 +
18720 +       propagate = (mnt->mnt_flags & MNT_TAGID);
18721 +       if (propagate)
18722 +               new_tag = mnt->mnt_tag;
18723 +
18724 +       vxdprintk(VXD_CBIT(tag, 7),
18725 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
18726 +               inode, inode->i_ino, inode->i_tag,
18727 +               new_tag, (propagate) ? 1 : 0);
18728 +
18729 +       if (propagate)
18730 +               i_tag_write(inode, new_tag);
18731 +}
18732 +
18733 +#include <linux/module.h>
18734 +
18735 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
18736 +
18737 +#endif /* CONFIG_PROPAGATE */
18738 +
18739 diff -NurpP --minimal linux-3.13.10/kernel/vserver/limit.c linux-3.13.10-vs2.3.6.11/kernel/vserver/limit.c
18740 --- linux-3.13.10/kernel/vserver/limit.c        1970-01-01 00:00:00.000000000 +0000
18741 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit.c     2014-02-01 00:22:08.000000000 +0000
18742 @@ -0,0 +1,345 @@
18743 +/*
18744 + *  linux/kernel/vserver/limit.c
18745 + *
18746 + *  Virtual Server: Context Limits
18747 + *
18748 + *  Copyright (C) 2004-2010  Herbert Pötzl
18749 + *
18750 + *  V0.01  broken out from vcontext V0.05
18751 + *  V0.02  changed vcmds to vxi arg
18752 + *  V0.03  added memory cgroup support
18753 + *
18754 + */
18755 +
18756 +#include <linux/sched.h>
18757 +#include <linux/module.h>
18758 +#include <linux/memcontrol.h>
18759 +#include <linux/res_counter.h>
18760 +#include <linux/vs_limit.h>
18761 +#include <linux/vserver/limit.h>
18762 +#include <linux/vserver/limit_cmd.h>
18763 +
18764 +#include <asm/uaccess.h>
18765 +
18766 +
18767 +const char *vlimit_name[NUM_LIMITS] = {
18768 +       [RLIMIT_CPU]            = "CPU",
18769 +       [RLIMIT_NPROC]          = "NPROC",
18770 +       [RLIMIT_NOFILE]         = "NOFILE",
18771 +       [RLIMIT_LOCKS]          = "LOCKS",
18772 +       [RLIMIT_SIGPENDING]     = "SIGP",
18773 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
18774 +
18775 +       [VLIMIT_NSOCK]          = "NSOCK",
18776 +       [VLIMIT_OPENFD]         = "OPENFD",
18777 +       [VLIMIT_SHMEM]          = "SHMEM",
18778 +       [VLIMIT_DENTRY]         = "DENTRY",
18779 +};
18780 +
18781 +EXPORT_SYMBOL_GPL(vlimit_name);
18782 +
18783 +#define MASK_ENTRY(x)  (1 << (x))
18784 +
18785 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
18786 +               /* minimum */
18787 +       0
18788 +       ,       /* softlimit */
18789 +       0
18790 +       ,       /* maximum */
18791 +       MASK_ENTRY( RLIMIT_NPROC        ) |
18792 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
18793 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
18794 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
18795 +
18796 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
18797 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
18798 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
18799 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
18800 +       0
18801 +};
18802 +               /* accounting only */
18803 +uint32_t account_mask =
18804 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
18805 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
18806 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
18807 +       0;
18808 +
18809 +
18810 +static int is_valid_vlimit(int id)
18811 +{
18812 +       uint32_t mask = vlimit_mask.minimum |
18813 +               vlimit_mask.softlimit | vlimit_mask.maximum;
18814 +       return mask & (1 << id);
18815 +}
18816 +
18817 +static int is_accounted_vlimit(int id)
18818 +{
18819 +       if (is_valid_vlimit(id))
18820 +               return 1;
18821 +       return account_mask & (1 << id);
18822 +}
18823 +
18824 +
18825 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
18826 +{
18827 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
18828 +       return VX_VLIM(limit);
18829 +}
18830 +
18831 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
18832 +{
18833 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
18834 +       return VX_VLIM(limit);
18835 +}
18836 +
18837 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
18838 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
18839 +{
18840 +       if (!is_valid_vlimit(id))
18841 +               return -EINVAL;
18842 +
18843 +       if (minimum)
18844 +               *minimum = CRLIM_UNSET;
18845 +       if (softlimit)
18846 +               *softlimit = vc_get_soft(vxi, id);
18847 +       if (maximum)
18848 +               *maximum = vc_get_hard(vxi, id);
18849 +       return 0;
18850 +}
18851 +
18852 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
18853 +{
18854 +       struct vcmd_ctx_rlimit_v0 vc_data;
18855 +       int ret;
18856 +
18857 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18858 +               return -EFAULT;
18859 +
18860 +       ret = do_get_rlimit(vxi, vc_data.id,
18861 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18862 +       if (ret)
18863 +               return ret;
18864 +
18865 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18866 +               return -EFAULT;
18867 +       return 0;
18868 +}
18869 +
18870 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
18871 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
18872 +{
18873 +       if (!is_valid_vlimit(id))
18874 +               return -EINVAL;
18875 +
18876 +       if (maximum != CRLIM_KEEP)
18877 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
18878 +       if (softlimit != CRLIM_KEEP)
18879 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
18880 +
18881 +       /* clamp soft limit */
18882 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
18883 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
18884 +
18885 +       return 0;
18886 +}
18887 +
18888 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
18889 +{
18890 +       struct vcmd_ctx_rlimit_v0 vc_data;
18891 +
18892 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18893 +               return -EFAULT;
18894 +
18895 +       return do_set_rlimit(vxi, vc_data.id,
18896 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18897 +}
18898 +
18899 +#ifdef CONFIG_IA32_EMULATION
18900 +
18901 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
18902 +{
18903 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18904 +
18905 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18906 +               return -EFAULT;
18907 +
18908 +       return do_set_rlimit(vxi, vc_data.id,
18909 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18910 +}
18911 +
18912 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
18913 +{
18914 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18915 +       int ret;
18916 +
18917 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18918 +               return -EFAULT;
18919 +
18920 +       ret = do_get_rlimit(vxi, vc_data.id,
18921 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18922 +       if (ret)
18923 +               return ret;
18924 +
18925 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18926 +               return -EFAULT;
18927 +       return 0;
18928 +}
18929 +
18930 +#endif /* CONFIG_IA32_EMULATION */
18931 +
18932 +
18933 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
18934 +{
18935 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
18936 +               return -EFAULT;
18937 +       return 0;
18938 +}
18939 +
18940 +
18941 +static inline void vx_reset_hits(struct _vx_limit *limit)
18942 +{
18943 +       int lim;
18944 +
18945 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18946 +               atomic_set(&__rlim_lhit(limit, lim), 0);
18947 +       }
18948 +}
18949 +
18950 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
18951 +{
18952 +       vx_reset_hits(&vxi->limit);
18953 +       return 0;
18954 +}
18955 +
18956 +static inline void vx_reset_minmax(struct _vx_limit *limit)
18957 +{
18958 +       rlim_t value;
18959 +       int lim;
18960 +
18961 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18962 +               value = __rlim_get(limit, lim);
18963 +               __rlim_rmax(limit, lim) = value;
18964 +               __rlim_rmin(limit, lim) = value;
18965 +       }
18966 +}
18967 +
18968 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
18969 +{
18970 +       vx_reset_minmax(&vxi->limit);
18971 +       return 0;
18972 +}
18973 +
18974 +
18975 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
18976 +{
18977 +       struct vcmd_rlimit_stat_v0 vc_data;
18978 +       struct _vx_limit *limit = &vxi->limit;
18979 +       int id;
18980 +
18981 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18982 +               return -EFAULT;
18983 +
18984 +       id = vc_data.id;
18985 +       if (!is_accounted_vlimit(id))
18986 +               return -EINVAL;
18987 +
18988 +       vx_limit_fixup(limit, id);
18989 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
18990 +       vc_data.value = __rlim_get(limit, id);
18991 +       vc_data.minimum = __rlim_rmin(limit, id);
18992 +       vc_data.maximum = __rlim_rmax(limit, id);
18993 +
18994 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18995 +               return -EFAULT;
18996 +       return 0;
18997 +}
18998 +
18999 +
19000 +void vx_vsi_meminfo(struct sysinfo *val)
19001 +{
19002 +#ifdef CONFIG_MEMCG
19003 +       struct mem_cgroup *mcg;
19004 +       u64 res_limit, res_usage;
19005 +
19006 +       rcu_read_lock();
19007 +       mcg = mem_cgroup_from_task(current);
19008 +       rcu_read_unlock();
19009 +       if (!mcg)
19010 +               goto out;
19011 +
19012 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19013 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19014 +
19015 +       if (res_limit != RES_COUNTER_MAX)
19016 +               val->totalram = (res_limit >> PAGE_SHIFT);
19017 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19018 +       val->bufferram = 0;
19019 +       val->totalhigh = 0;
19020 +       val->freehigh = 0;
19021 +out:
19022 +#endif /* CONFIG_MEMCG */
19023 +       return;
19024 +}
19025 +
19026 +void vx_vsi_swapinfo(struct sysinfo *val)
19027 +{
19028 +#ifdef CONFIG_MEMCG
19029 +#ifdef CONFIG_MEMCG_SWAP
19030 +       struct mem_cgroup *mcg;
19031 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19032 +       s64 swap_limit, swap_usage;
19033 +
19034 +       rcu_read_lock();
19035 +       mcg = mem_cgroup_from_task(current);
19036 +       rcu_read_unlock();
19037 +       if (!mcg)
19038 +               goto out;
19039 +
19040 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19041 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19042 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19043 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19044 +
19045 +       /* memory unlimited */
19046 +       if (res_limit == RES_COUNTER_MAX)
19047 +               goto out;
19048 +
19049 +       swap_limit = memsw_limit - res_limit;
19050 +       /* we have a swap limit? */
19051 +       if (memsw_limit != RES_COUNTER_MAX)
19052 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19053 +
19054 +       /* calculate swap part */
19055 +       swap_usage = (memsw_usage > res_usage) ?
19056 +               memsw_usage - res_usage : 0;
19057 +
19058 +       /* total shown minus usage gives free swap */
19059 +       val->freeswap = (swap_usage < swap_limit) ?
19060 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19061 +out:
19062 +#else  /* !CONFIG_MEMCG_SWAP */
19063 +       val->totalswap = 0;
19064 +       val->freeswap = 0;
19065 +#endif /* !CONFIG_MEMCG_SWAP */
19066 +#endif /* CONFIG_MEMCG */
19067 +       return;
19068 +}
19069 +
19070 +long vx_vsi_cached(struct sysinfo *val)
19071 +{
19072 +       long cache = 0;
19073 +#ifdef CONFIG_MEMCG
19074 +       struct mem_cgroup *mcg;
19075 +
19076 +       rcu_read_lock();
19077 +       mcg = mem_cgroup_from_task(current);
19078 +       rcu_read_unlock();
19079 +       if (!mcg)
19080 +               goto out;
19081 +
19082 +       cache = mem_cgroup_stat_read_cache(mcg);
19083 +out:
19084 +#endif
19085 +       return cache;
19086 +}
19087 +
19088 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
19089 --- linux-3.13.10/kernel/vserver/limit_init.h   1970-01-01 00:00:00.000000000 +0000
19090 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_init.h        2014-01-31 20:38:04.000000000 +0000
19091 @@ -0,0 +1,31 @@
19092 +
19093 +
19094 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19095 +{
19096 +       int lim;
19097 +
19098 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19099 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19100 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19101 +               __rlim_set(limit, lim, 0);
19102 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19103 +               __rlim_rmin(limit, lim) = 0;
19104 +               __rlim_rmax(limit, lim) = 0;
19105 +       }
19106 +}
19107 +
19108 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19109 +{
19110 +       rlim_t value;
19111 +       int lim;
19112 +
19113 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19114 +               if ((1 << lim) & VLIM_NOCHECK)
19115 +                       continue;
19116 +               value = __rlim_get(limit, lim);
19117 +               vxwprintk_xid(value,
19118 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19119 +                       limit, vlimit_name[lim], lim, (long)value);
19120 +       }
19121 +}
19122 +
19123 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
19124 --- linux-3.13.10/kernel/vserver/limit_proc.h   1970-01-01 00:00:00.000000000 +0000
19125 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_proc.h        2014-01-31 20:38:04.000000000 +0000
19126 @@ -0,0 +1,57 @@
19127 +#ifndef _VX_LIMIT_PROC_H
19128 +#define _VX_LIMIT_PROC_H
19129 +
19130 +#include <linux/vserver/limit_int.h>
19131 +
19132 +
19133 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19134 +#define VX_LIMIT_TOP   \
19135 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19136 +
19137 +#define VX_LIMIT_ARG(r)                                \
19138 +       (unsigned long)__rlim_get(limit, r),    \
19139 +       (unsigned long)__rlim_rmin(limit, r),   \
19140 +       (unsigned long)__rlim_rmax(limit, r),   \
19141 +       VX_VLIM(__rlim_soft(limit, r)),         \
19142 +       VX_VLIM(__rlim_hard(limit, r)),         \
19143 +       atomic_read(&__rlim_lhit(limit, r))
19144 +
19145 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19146 +{
19147 +       vx_limit_fixup(limit, -1);
19148 +       return sprintf(buffer, VX_LIMIT_TOP
19149 +               "PROC"  VX_LIMIT_FMT
19150 +               "VM"    VX_LIMIT_FMT
19151 +               "VML"   VX_LIMIT_FMT
19152 +               "RSS"   VX_LIMIT_FMT
19153 +               "ANON"  VX_LIMIT_FMT
19154 +               "RMAP"  VX_LIMIT_FMT
19155 +               "FILES" VX_LIMIT_FMT
19156 +               "OFD"   VX_LIMIT_FMT
19157 +               "LOCKS" VX_LIMIT_FMT
19158 +               "SOCK"  VX_LIMIT_FMT
19159 +               "MSGQ"  VX_LIMIT_FMT
19160 +               "SHM"   VX_LIMIT_FMT
19161 +               "SEMA"  VX_LIMIT_FMT
19162 +               "SEMS"  VX_LIMIT_FMT
19163 +               "DENT"  VX_LIMIT_FMT,
19164 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19165 +               VX_LIMIT_ARG(RLIMIT_AS),
19166 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19167 +               VX_LIMIT_ARG(RLIMIT_RSS),
19168 +               VX_LIMIT_ARG(VLIMIT_ANON),
19169 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19170 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19171 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19172 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19173 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19174 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19175 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19176 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19177 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19178 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19179 +}
19180 +
19181 +#endif /* _VX_LIMIT_PROC_H */
19182 +
19183 +
19184 diff -NurpP --minimal linux-3.13.10/kernel/vserver/network.c linux-3.13.10-vs2.3.6.11/kernel/vserver/network.c
19185 --- linux-3.13.10/kernel/vserver/network.c      1970-01-01 00:00:00.000000000 +0000
19186 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/network.c   2014-01-31 20:38:04.000000000 +0000
19187 @@ -0,0 +1,1053 @@
19188 +/*
19189 + *  linux/kernel/vserver/network.c
19190 + *
19191 + *  Virtual Server: Network Support
19192 + *
19193 + *  Copyright (C) 2003-2007  Herbert Pötzl
19194 + *
19195 + *  V0.01  broken out from vcontext V0.05
19196 + *  V0.02  cleaned up implementation
19197 + *  V0.03  added equiv nx commands
19198 + *  V0.04  switch to RCU based hash
19199 + *  V0.05  and back to locking again
19200 + *  V0.06  changed vcmds to nxi arg
19201 + *  V0.07  have __create claim() the nxi
19202 + *
19203 + */
19204 +
19205 +#include <linux/err.h>
19206 +#include <linux/slab.h>
19207 +#include <linux/rcupdate.h>
19208 +#include <net/ipv6.h>
19209 +
19210 +#include <linux/vs_network.h>
19211 +#include <linux/vs_pid.h>
19212 +#include <linux/vserver/network_cmd.h>
19213 +
19214 +
19215 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19216 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19217 +
19218 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19219 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19220 +
19221 +
19222 +static int __init init_network(void)
19223 +{
19224 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19225 +               sizeof(struct nx_addr_v4), 0,
19226 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19227 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19228 +               sizeof(struct nx_addr_v6), 0,
19229 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19230 +       return 0;
19231 +}
19232 +
19233 +
19234 +/*     __alloc_nx_addr_v4()                                    */
19235 +
19236 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19237 +{
19238 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19239 +               nx_addr_v4_cachep, GFP_KERNEL);
19240 +
19241 +       if (!IS_ERR(nxa))
19242 +               memset(nxa, 0, sizeof(*nxa));
19243 +       return nxa;
19244 +}
19245 +
19246 +/*     __dealloc_nx_addr_v4()                                  */
19247 +
19248 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19249 +{
19250 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19251 +}
19252 +
19253 +/*     __dealloc_nx_addr_v4_all()                              */
19254 +
19255 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19256 +{
19257 +       while (nxa) {
19258 +               struct nx_addr_v4 *next = nxa->next;
19259 +
19260 +               __dealloc_nx_addr_v4(nxa);
19261 +               nxa = next;
19262 +       }
19263 +}
19264 +
19265 +
19266 +#ifdef CONFIG_IPV6
19267 +
19268 +/*     __alloc_nx_addr_v6()                                    */
19269 +
19270 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19271 +{
19272 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19273 +               nx_addr_v6_cachep, GFP_KERNEL);
19274 +
19275 +       if (!IS_ERR(nxa))
19276 +               memset(nxa, 0, sizeof(*nxa));
19277 +       return nxa;
19278 +}
19279 +
19280 +/*     __dealloc_nx_addr_v6()                                  */
19281 +
19282 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19283 +{
19284 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19285 +}
19286 +
19287 +/*     __dealloc_nx_addr_v6_all()                              */
19288 +
19289 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19290 +{
19291 +       while (nxa) {
19292 +               struct nx_addr_v6 *next = nxa->next;
19293 +
19294 +               __dealloc_nx_addr_v6(nxa);
19295 +               nxa = next;
19296 +       }
19297 +}
19298 +
19299 +#endif /* CONFIG_IPV6 */
19300 +
19301 +/*     __alloc_nx_info()
19302 +
19303 +       * allocate an initialized nx_info struct
19304 +       * doesn't make it visible (hash)                        */
19305 +
19306 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19307 +{
19308 +       struct nx_info *new = NULL;
19309 +
19310 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19311 +
19312 +       /* would this benefit from a slab cache? */
19313 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19314 +       if (!new)
19315 +               return 0;
19316 +
19317 +       memset(new, 0, sizeof(struct nx_info));
19318 +       new->nx_id = nid;
19319 +       INIT_HLIST_NODE(&new->nx_hlist);
19320 +       atomic_set(&new->nx_usecnt, 0);
19321 +       atomic_set(&new->nx_tasks, 0);
19322 +       spin_lock_init(&new->addr_lock);
19323 +       new->nx_state = 0;
19324 +
19325 +       new->nx_flags = NXF_INIT_SET;
19326 +
19327 +       /* rest of init goes here */
19328 +
19329 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19330 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19331 +
19332 +       vxdprintk(VXD_CBIT(nid, 0),
19333 +               "alloc_nx_info(%d) = %p", nid, new);
19334 +       atomic_inc(&nx_global_ctotal);
19335 +       return new;
19336 +}
19337 +
19338 +/*     __dealloc_nx_info()
19339 +
19340 +       * final disposal of nx_info                             */
19341 +
19342 +static void __dealloc_nx_info(struct nx_info *nxi)
19343 +{
19344 +       vxdprintk(VXD_CBIT(nid, 0),
19345 +               "dealloc_nx_info(%p)", nxi);
19346 +
19347 +       nxi->nx_hlist.next = LIST_POISON1;
19348 +       nxi->nx_id = -1;
19349 +
19350 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19351 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19352 +
19353 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
19354 +#ifdef CONFIG_IPV6
19355 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
19356 +#endif
19357 +
19358 +       nxi->nx_state |= NXS_RELEASED;
19359 +       kfree(nxi);
19360 +       atomic_dec(&nx_global_ctotal);
19361 +}
19362 +
19363 +static void __shutdown_nx_info(struct nx_info *nxi)
19364 +{
19365 +       nxi->nx_state |= NXS_SHUTDOWN;
19366 +       vs_net_change(nxi, VSC_NETDOWN);
19367 +}
19368 +
19369 +/*     exported stuff                                          */
19370 +
19371 +void free_nx_info(struct nx_info *nxi)
19372 +{
19373 +       /* context shutdown is mandatory */
19374 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
19375 +
19376 +       /* context must not be hashed */
19377 +       BUG_ON(nxi->nx_state & NXS_HASHED);
19378 +
19379 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19380 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19381 +
19382 +       __dealloc_nx_info(nxi);
19383 +}
19384 +
19385 +
19386 +void __nx_set_lback(struct nx_info *nxi)
19387 +{
19388 +       int nid = nxi->nx_id;
19389 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
19390 +
19391 +       nxi->v4_lback.s_addr = lback;
19392 +}
19393 +
19394 +extern int __nx_inet_add_lback(__be32 addr);
19395 +extern int __nx_inet_del_lback(__be32 addr);
19396 +
19397 +
19398 +/*     hash table for nx_info hash */
19399 +
19400 +#define NX_HASH_SIZE   13
19401 +
19402 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
19403 +
19404 +static DEFINE_SPINLOCK(nx_info_hash_lock);
19405 +
19406 +
19407 +static inline unsigned int __hashval(vnid_t nid)
19408 +{
19409 +       return (nid % NX_HASH_SIZE);
19410 +}
19411 +
19412 +
19413 +
19414 +/*     __hash_nx_info()
19415 +
19416 +       * add the nxi to the global hash table
19417 +       * requires the hash_lock to be held                     */
19418 +
19419 +static inline void __hash_nx_info(struct nx_info *nxi)
19420 +{
19421 +       struct hlist_head *head;
19422 +
19423 +       vxd_assert_lock(&nx_info_hash_lock);
19424 +       vxdprintk(VXD_CBIT(nid, 4),
19425 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
19426 +
19427 +       /* context must not be hashed */
19428 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
19429 +
19430 +       nxi->nx_state |= NXS_HASHED;
19431 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
19432 +       hlist_add_head(&nxi->nx_hlist, head);
19433 +       atomic_inc(&nx_global_cactive);
19434 +}
19435 +
19436 +/*     __unhash_nx_info()
19437 +
19438 +       * remove the nxi from the global hash table
19439 +       * requires the hash_lock to be held                     */
19440 +
19441 +static inline void __unhash_nx_info(struct nx_info *nxi)
19442 +{
19443 +       vxd_assert_lock(&nx_info_hash_lock);
19444 +       vxdprintk(VXD_CBIT(nid, 4),
19445 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
19446 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
19447 +
19448 +       /* context must be hashed */
19449 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
19450 +       /* but without tasks */
19451 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19452 +
19453 +       nxi->nx_state &= ~NXS_HASHED;
19454 +       hlist_del(&nxi->nx_hlist);
19455 +       atomic_dec(&nx_global_cactive);
19456 +}
19457 +
19458 +
19459 +/*     __lookup_nx_info()
19460 +
19461 +       * requires the hash_lock to be held
19462 +       * doesn't increment the nx_refcnt                       */
19463 +
19464 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
19465 +{
19466 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
19467 +       struct hlist_node *pos;
19468 +       struct nx_info *nxi;
19469 +
19470 +       vxd_assert_lock(&nx_info_hash_lock);
19471 +       hlist_for_each(pos, head) {
19472 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19473 +
19474 +               if (nxi->nx_id == nid)
19475 +                       goto found;
19476 +       }
19477 +       nxi = NULL;
19478 +found:
19479 +       vxdprintk(VXD_CBIT(nid, 0),
19480 +               "__lookup_nx_info(#%u): %p[#%u]",
19481 +               nid, nxi, nxi ? nxi->nx_id : 0);
19482 +       return nxi;
19483 +}
19484 +
19485 +
19486 +/*     __create_nx_info()
19487 +
19488 +       * create the requested context
19489 +       * get(), claim() and hash it                            */
19490 +
19491 +static struct nx_info *__create_nx_info(int id)
19492 +{
19493 +       struct nx_info *new, *nxi = NULL;
19494 +
19495 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
19496 +
19497 +       if (!(new = __alloc_nx_info(id)))
19498 +               return ERR_PTR(-ENOMEM);
19499 +
19500 +       /* required to make dynamic xids unique */
19501 +       spin_lock(&nx_info_hash_lock);
19502 +
19503 +       /* static context requested */
19504 +       if ((nxi = __lookup_nx_info(id))) {
19505 +               vxdprintk(VXD_CBIT(nid, 0),
19506 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
19507 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19508 +                       nxi = ERR_PTR(-EBUSY);
19509 +               else
19510 +                       nxi = ERR_PTR(-EEXIST);
19511 +               goto out_unlock;
19512 +       }
19513 +       /* new context */
19514 +       vxdprintk(VXD_CBIT(nid, 0),
19515 +               "create_nx_info(%d) = %p (new)", id, new);
19516 +       claim_nx_info(new, NULL);
19517 +       __nx_set_lback(new);
19518 +       __hash_nx_info(get_nx_info(new));
19519 +       nxi = new, new = NULL;
19520 +
19521 +out_unlock:
19522 +       spin_unlock(&nx_info_hash_lock);
19523 +       if (new)
19524 +               __dealloc_nx_info(new);
19525 +       return nxi;
19526 +}
19527 +
19528 +
19529 +
19530 +/*     exported stuff                                          */
19531 +
19532 +
19533 +void unhash_nx_info(struct nx_info *nxi)
19534 +{
19535 +       __shutdown_nx_info(nxi);
19536 +       spin_lock(&nx_info_hash_lock);
19537 +       __unhash_nx_info(nxi);
19538 +       spin_unlock(&nx_info_hash_lock);
19539 +}
19540 +
19541 +/*     lookup_nx_info()
19542 +
19543 +       * search for a nx_info and get() it
19544 +       * negative id means current                             */
19545 +
19546 +struct nx_info *lookup_nx_info(int id)
19547 +{
19548 +       struct nx_info *nxi = NULL;
19549 +
19550 +       if (id < 0) {
19551 +               nxi = get_nx_info(current_nx_info());
19552 +       } else if (id > 1) {
19553 +               spin_lock(&nx_info_hash_lock);
19554 +               nxi = get_nx_info(__lookup_nx_info(id));
19555 +               spin_unlock(&nx_info_hash_lock);
19556 +       }
19557 +       return nxi;
19558 +}
19559 +
19560 +/*     nid_is_hashed()
19561 +
19562 +       * verify that nid is still hashed                       */
19563 +
19564 +int nid_is_hashed(vnid_t nid)
19565 +{
19566 +       int hashed;
19567 +
19568 +       spin_lock(&nx_info_hash_lock);
19569 +       hashed = (__lookup_nx_info(nid) != NULL);
19570 +       spin_unlock(&nx_info_hash_lock);
19571 +       return hashed;
19572 +}
19573 +
19574 +
19575 +#ifdef CONFIG_PROC_FS
19576 +
19577 +/*     get_nid_list()
19578 +
19579 +       * get a subset of hashed nids for proc
19580 +       * assumes size is at least one                          */
19581 +
19582 +int get_nid_list(int index, unsigned int *nids, int size)
19583 +{
19584 +       int hindex, nr_nids = 0;
19585 +
19586 +       /* only show current and children */
19587 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
19588 +               if (index > 0)
19589 +                       return 0;
19590 +               nids[nr_nids] = nx_current_nid();
19591 +               return 1;
19592 +       }
19593 +
19594 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
19595 +               struct hlist_head *head = &nx_info_hash[hindex];
19596 +               struct hlist_node *pos;
19597 +
19598 +               spin_lock(&nx_info_hash_lock);
19599 +               hlist_for_each(pos, head) {
19600 +                       struct nx_info *nxi;
19601 +
19602 +                       if (--index > 0)
19603 +                               continue;
19604 +
19605 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19606 +                       nids[nr_nids] = nxi->nx_id;
19607 +                       if (++nr_nids >= size) {
19608 +                               spin_unlock(&nx_info_hash_lock);
19609 +                               goto out;
19610 +                       }
19611 +               }
19612 +               /* keep the lock time short */
19613 +               spin_unlock(&nx_info_hash_lock);
19614 +       }
19615 +out:
19616 +       return nr_nids;
19617 +}
19618 +#endif
19619 +
19620 +
19621 +/*
19622 + *     migrate task to new network
19623 + *     gets nxi, puts old_nxi on change
19624 + */
19625 +
19626 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
19627 +{
19628 +       struct nx_info *old_nxi;
19629 +       int ret = 0;
19630 +
19631 +       if (!p || !nxi)
19632 +               BUG();
19633 +
19634 +       vxdprintk(VXD_CBIT(nid, 5),
19635 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
19636 +               p, nxi, nxi->nx_id,
19637 +               atomic_read(&nxi->nx_usecnt),
19638 +               atomic_read(&nxi->nx_tasks));
19639 +
19640 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
19641 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19642 +               return -EACCES;
19643 +
19644 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
19645 +               return -EFAULT;
19646 +
19647 +       /* maybe disallow this completely? */
19648 +       old_nxi = task_get_nx_info(p);
19649 +       if (old_nxi == nxi)
19650 +               goto out;
19651 +
19652 +       task_lock(p);
19653 +       if (old_nxi)
19654 +               clr_nx_info(&p->nx_info);
19655 +       claim_nx_info(nxi, p);
19656 +       set_nx_info(&p->nx_info, nxi);
19657 +       p->nid = nxi->nx_id;
19658 +       task_unlock(p);
19659 +
19660 +       vxdprintk(VXD_CBIT(nid, 5),
19661 +               "moved task %p into nxi:%p[#%d]",
19662 +               p, nxi, nxi->nx_id);
19663 +
19664 +       if (old_nxi)
19665 +               release_nx_info(old_nxi, p);
19666 +       ret = 0;
19667 +out:
19668 +       put_nx_info(old_nxi);
19669 +       return ret;
19670 +}
19671 +
19672 +
19673 +void nx_set_persistent(struct nx_info *nxi)
19674 +{
19675 +       vxdprintk(VXD_CBIT(nid, 6),
19676 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
19677 +
19678 +       get_nx_info(nxi);
19679 +       claim_nx_info(nxi, NULL);
19680 +}
19681 +
19682 +void nx_clear_persistent(struct nx_info *nxi)
19683 +{
19684 +       vxdprintk(VXD_CBIT(nid, 6),
19685 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
19686 +
19687 +       release_nx_info(nxi, NULL);
19688 +       put_nx_info(nxi);
19689 +}
19690 +
19691 +void nx_update_persistent(struct nx_info *nxi)
19692 +{
19693 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
19694 +               nx_set_persistent(nxi);
19695 +       else
19696 +               nx_clear_persistent(nxi);
19697 +}
19698 +
19699 +/* vserver syscall commands below here */
19700 +
19701 +/* taks nid and nx_info functions */
19702 +
19703 +#include <asm/uaccess.h>
19704 +
19705 +
19706 +int vc_task_nid(uint32_t id)
19707 +{
19708 +       vnid_t nid;
19709 +
19710 +       if (id) {
19711 +               struct task_struct *tsk;
19712 +
19713 +               rcu_read_lock();
19714 +               tsk = find_task_by_real_pid(id);
19715 +               nid = (tsk) ? tsk->nid : -ESRCH;
19716 +               rcu_read_unlock();
19717 +       } else
19718 +               nid = nx_current_nid();
19719 +       return nid;
19720 +}
19721 +
19722 +
19723 +int vc_nx_info(struct nx_info *nxi, void __user *data)
19724 +{
19725 +       struct vcmd_nx_info_v0 vc_data;
19726 +
19727 +       vc_data.nid = nxi->nx_id;
19728 +
19729 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19730 +               return -EFAULT;
19731 +       return 0;
19732 +}
19733 +
19734 +
19735 +/* network functions */
19736 +
19737 +int vc_net_create(uint32_t nid, void __user *data)
19738 +{
19739 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
19740 +       struct nx_info *new_nxi;
19741 +       int ret;
19742 +
19743 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19744 +               return -EFAULT;
19745 +
19746 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
19747 +               return -EINVAL;
19748 +
19749 +       new_nxi = __create_nx_info(nid);
19750 +       if (IS_ERR(new_nxi))
19751 +               return PTR_ERR(new_nxi);
19752 +
19753 +       /* initial flags */
19754 +       new_nxi->nx_flags = vc_data.flagword;
19755 +
19756 +       ret = -ENOEXEC;
19757 +       if (vs_net_change(new_nxi, VSC_NETUP))
19758 +               goto out;
19759 +
19760 +       ret = nx_migrate_task(current, new_nxi);
19761 +       if (ret)
19762 +               goto out;
19763 +
19764 +       /* return context id on success */
19765 +       ret = new_nxi->nx_id;
19766 +
19767 +       /* get a reference for persistent contexts */
19768 +       if ((vc_data.flagword & NXF_PERSISTENT))
19769 +               nx_set_persistent(new_nxi);
19770 +out:
19771 +       release_nx_info(new_nxi, NULL);
19772 +       put_nx_info(new_nxi);
19773 +       return ret;
19774 +}
19775 +
19776 +
19777 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
19778 +{
19779 +       return nx_migrate_task(current, nxi);
19780 +}
19781 +
19782 +
19783 +static inline
19784 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
19785 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
19786 +       struct nx_addr_v4 **prev)
19787 +{
19788 +       struct nx_addr_v4 *nxa = &nxi->v4;
19789 +
19790 +       for (; nxa; nxa = nxa->next) {
19791 +               if ((nxa->ip[0].s_addr == ip) &&
19792 +                   (nxa->ip[1].s_addr == ip2) &&
19793 +                   (nxa->mask.s_addr == mask) &&
19794 +                   (nxa->type == type) &&
19795 +                   (nxa->flags == flags))
19796 +                   return nxa;
19797 +
19798 +               /* save previous entry */
19799 +               if (prev)
19800 +                       *prev = nxa;
19801 +       }
19802 +       return NULL;
19803 +}
19804 +
19805 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19806 +       uint16_t type, uint16_t flags)
19807 +{
19808 +       struct nx_addr_v4 *nxa = NULL;
19809 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
19810 +       unsigned long irqflags;
19811 +       int ret = -EEXIST;
19812 +
19813 +       if (IS_ERR(new))
19814 +               return PTR_ERR(new);
19815 +
19816 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19817 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
19818 +               goto out_unlock;
19819 +
19820 +       if (NX_IPV4(nxi)) {
19821 +               nxa->next = new;
19822 +               nxa = new;
19823 +               new = NULL;
19824 +
19825 +               /* remove single ip for ip list */
19826 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
19827 +       }
19828 +
19829 +       nxa->ip[0].s_addr = ip;
19830 +       nxa->ip[1].s_addr = ip2;
19831 +       nxa->mask.s_addr = mask;
19832 +       nxa->type = type;
19833 +       nxa->flags = flags;
19834 +       ret = 0;
19835 +out_unlock:
19836 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19837 +       if (new)
19838 +               __dealloc_nx_addr_v4(new);
19839 +       return ret;
19840 +}
19841 +
19842 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19843 +       uint16_t type, uint16_t flags)
19844 +{
19845 +       struct nx_addr_v4 *nxa = NULL;
19846 +       struct nx_addr_v4 *old = NULL;
19847 +       unsigned long irqflags;
19848 +       int ret = 0;
19849 +
19850 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19851 +       switch (type) {
19852 +       case NXA_TYPE_ADDR:
19853 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
19854 +               if (old) {
19855 +                       if (nxa) {
19856 +                               nxa->next = old->next;
19857 +                               old->next = NULL;
19858 +                       } else {
19859 +                               if (old->next) {
19860 +                                       nxa = old;
19861 +                                       old = old->next;
19862 +                                       *nxa = *old;
19863 +                                       old->next = NULL;
19864 +                               } else {
19865 +                                       memset(old, 0, sizeof(*old));
19866 +                                       old = NULL;
19867 +                               }
19868 +                       }
19869 +               } else
19870 +                       ret = -ESRCH;
19871 +               break;
19872 +
19873 +       case NXA_TYPE_ANY:
19874 +               nxa = &nxi->v4;
19875 +               old = nxa->next;
19876 +               memset(nxa, 0, sizeof(*nxa));
19877 +               break;
19878 +
19879 +       default:
19880 +               ret = -EINVAL;
19881 +       }
19882 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19883 +       __dealloc_nx_addr_v4_all(old);
19884 +       return ret;
19885 +}
19886 +
19887 +
19888 +int vc_net_add(struct nx_info *nxi, void __user *data)
19889 +{
19890 +       struct vcmd_net_addr_v0 vc_data;
19891 +       int index, ret = 0;
19892 +
19893 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19894 +               return -EFAULT;
19895 +
19896 +       switch (vc_data.type) {
19897 +       case NXA_TYPE_IPV4:
19898 +               if ((vc_data.count < 1) || (vc_data.count > 4))
19899 +                       return -EINVAL;
19900 +
19901 +               index = 0;
19902 +               while (index < vc_data.count) {
19903 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
19904 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
19905 +                       if (ret)
19906 +                               return ret;
19907 +                       index++;
19908 +               }
19909 +               ret = index;
19910 +               break;
19911 +
19912 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
19913 +               nxi->v4_bcast = vc_data.ip[0];
19914 +               ret = 1;
19915 +               break;
19916 +
19917 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
19918 +               nxi->v4_lback = vc_data.ip[0];
19919 +               ret = 1;
19920 +               break;
19921 +
19922 +       default:
19923 +               ret = -EINVAL;
19924 +               break;
19925 +       }
19926 +       return ret;
19927 +}
19928 +
19929 +int vc_net_remove(struct nx_info *nxi, void __user *data)
19930 +{
19931 +       struct vcmd_net_addr_v0 vc_data;
19932 +
19933 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19934 +               return -EFAULT;
19935 +
19936 +       switch (vc_data.type) {
19937 +       case NXA_TYPE_ANY:
19938 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
19939 +       default:
19940 +               return -EINVAL;
19941 +       }
19942 +       return 0;
19943 +}
19944 +
19945 +
19946 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
19947 +{
19948 +       struct vcmd_net_addr_ipv4_v1 vc_data;
19949 +
19950 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19951 +               return -EFAULT;
19952 +
19953 +       switch (vc_data.type) {
19954 +       case NXA_TYPE_ADDR:
19955 +       case NXA_TYPE_MASK:
19956 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
19957 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19958 +
19959 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19960 +               nxi->v4_bcast = vc_data.ip;
19961 +               break;
19962 +
19963 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19964 +               nxi->v4_lback = vc_data.ip;
19965 +               break;
19966 +
19967 +       default:
19968 +               return -EINVAL;
19969 +       }
19970 +       return 0;
19971 +}
19972 +
19973 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
19974 +{
19975 +       struct vcmd_net_addr_ipv4_v2 vc_data;
19976 +
19977 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19978 +               return -EFAULT;
19979 +
19980 +       switch (vc_data.type) {
19981 +       case NXA_TYPE_ADDR:
19982 +       case NXA_TYPE_MASK:
19983 +       case NXA_TYPE_RANGE:
19984 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19985 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19986 +
19987 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19988 +               nxi->v4_bcast = vc_data.ip;
19989 +               break;
19990 +
19991 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19992 +               nxi->v4_lback = vc_data.ip;
19993 +               break;
19994 +
19995 +       default:
19996 +               return -EINVAL;
19997 +       }
19998 +       return 0;
19999 +}
20000 +
20001 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20002 +{
20003 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20004 +
20005 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20006 +               return -EFAULT;
20007 +
20008 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20009 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20010 +}
20011 +
20012 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20013 +{
20014 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20015 +
20016 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20017 +               return -EFAULT;
20018 +
20019 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20020 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20021 +}
20022 +
20023 +#ifdef CONFIG_IPV6
20024 +
20025 +static inline
20026 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20027 +       struct in6_addr *ip, struct in6_addr *mask,
20028 +       uint32_t prefix, uint16_t type, uint16_t flags,
20029 +       struct nx_addr_v6 **prev)
20030 +{
20031 +       struct nx_addr_v6 *nxa = &nxi->v6;
20032 +
20033 +       for (; nxa; nxa = nxa->next) {
20034 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
20035 +                   ipv6_addr_equal(&nxa->mask, mask) &&
20036 +                   (nxa->prefix == prefix) &&
20037 +                   (nxa->type == type) &&
20038 +                   (nxa->flags == flags))
20039 +                   return nxa;
20040 +
20041 +               /* save previous entry */
20042 +               if (prev)
20043 +                       *prev = nxa;
20044 +       }
20045 +       return NULL;
20046 +}
20047 +
20048 +
20049 +int do_add_v6_addr(struct nx_info *nxi,
20050 +       struct in6_addr *ip, struct in6_addr *mask,
20051 +       uint32_t prefix, uint16_t type, uint16_t flags)
20052 +{
20053 +       struct nx_addr_v6 *nxa = NULL;
20054 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20055 +       unsigned long irqflags;
20056 +       int ret = -EEXIST;
20057 +
20058 +       if (IS_ERR(new))
20059 +               return PTR_ERR(new);
20060 +
20061 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20062 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20063 +               goto out_unlock;
20064 +
20065 +       if (NX_IPV6(nxi)) {
20066 +               nxa->next = new;
20067 +               nxa = new;
20068 +               new = NULL;
20069 +       }
20070 +
20071 +       nxa->ip = *ip;
20072 +       nxa->mask = *mask;
20073 +       nxa->prefix = prefix;
20074 +       nxa->type = type;
20075 +       nxa->flags = flags;
20076 +       ret = 0;
20077 +out_unlock:
20078 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20079 +       if (new)
20080 +               __dealloc_nx_addr_v6(new);
20081 +       return ret;
20082 +}
20083 +
20084 +int do_remove_v6_addr(struct nx_info *nxi,
20085 +       struct in6_addr *ip, struct in6_addr *mask,
20086 +       uint32_t prefix, uint16_t type, uint16_t flags)
20087 +{
20088 +       struct nx_addr_v6 *nxa = NULL;
20089 +       struct nx_addr_v6 *old = NULL;
20090 +       unsigned long irqflags;
20091 +       int ret = 0;
20092 +
20093 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20094 +       switch (type) {
20095 +       case NXA_TYPE_ADDR:
20096 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20097 +               if (old) {
20098 +                       if (nxa) {
20099 +                               nxa->next = old->next;
20100 +                               old->next = NULL;
20101 +                       } else {
20102 +                               if (old->next) {
20103 +                                       nxa = old;
20104 +                                       old = old->next;
20105 +                                       *nxa = *old;
20106 +                                       old->next = NULL;
20107 +                               } else {
20108 +                                       memset(old, 0, sizeof(*old));
20109 +                                       old = NULL;
20110 +                               }
20111 +                       }
20112 +               } else
20113 +                       ret = -ESRCH;
20114 +               break;
20115 +
20116 +       case NXA_TYPE_ANY:
20117 +               nxa = &nxi->v6;
20118 +               old = nxa->next;
20119 +               memset(nxa, 0, sizeof(*nxa));
20120 +               break;
20121 +
20122 +       default:
20123 +               ret = -EINVAL;
20124 +       }
20125 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20126 +       __dealloc_nx_addr_v6_all(old);
20127 +       return ret;
20128 +}
20129 +
20130 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20131 +{
20132 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20133 +
20134 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20135 +               return -EFAULT;
20136 +
20137 +       switch (vc_data.type) {
20138 +       case NXA_TYPE_ADDR:
20139 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20140 +               /* fallthrough */
20141 +       case NXA_TYPE_MASK:
20142 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20143 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20144 +       default:
20145 +               return -EINVAL;
20146 +       }
20147 +       return 0;
20148 +}
20149 +
20150 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20151 +{
20152 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20153 +
20154 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20155 +               return -EFAULT;
20156 +
20157 +       switch (vc_data.type) {
20158 +       case NXA_TYPE_ADDR:
20159 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20160 +               /* fallthrough */
20161 +       case NXA_TYPE_MASK:
20162 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20163 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20164 +       case NXA_TYPE_ANY:
20165 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20166 +       default:
20167 +               return -EINVAL;
20168 +       }
20169 +       return 0;
20170 +}
20171 +
20172 +#endif /* CONFIG_IPV6 */
20173 +
20174 +
20175 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20176 +{
20177 +       struct vcmd_net_flags_v0 vc_data;
20178 +
20179 +       vc_data.flagword = nxi->nx_flags;
20180 +
20181 +       /* special STATE flag handling */
20182 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20183 +
20184 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20185 +               return -EFAULT;
20186 +       return 0;
20187 +}
20188 +
20189 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20190 +{
20191 +       struct vcmd_net_flags_v0 vc_data;
20192 +       uint64_t mask, trigger;
20193 +
20194 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20195 +               return -EFAULT;
20196 +
20197 +       /* special STATE flag handling */
20198 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20199 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20200 +
20201 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20202 +               vc_data.flagword, mask);
20203 +       if (trigger & NXF_PERSISTENT)
20204 +               nx_update_persistent(nxi);
20205 +
20206 +       return 0;
20207 +}
20208 +
20209 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20210 +{
20211 +       struct vcmd_net_caps_v0 vc_data;
20212 +
20213 +       vc_data.ncaps = nxi->nx_ncaps;
20214 +       vc_data.cmask = ~0ULL;
20215 +
20216 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20217 +               return -EFAULT;
20218 +       return 0;
20219 +}
20220 +
20221 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20222 +{
20223 +       struct vcmd_net_caps_v0 vc_data;
20224 +
20225 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20226 +               return -EFAULT;
20227 +
20228 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20229 +               vc_data.ncaps, vc_data.cmask);
20230 +       return 0;
20231 +}
20232 +
20233 +
20234 +#include <linux/module.h>
20235 +
20236 +module_init(init_network);
20237 +
20238 +EXPORT_SYMBOL_GPL(free_nx_info);
20239 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20240 +
20241 diff -NurpP --minimal linux-3.13.10/kernel/vserver/proc.c linux-3.13.10-vs2.3.6.11/kernel/vserver/proc.c
20242 --- linux-3.13.10/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
20243 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/proc.c      2014-02-01 01:21:49.000000000 +0000
20244 @@ -0,0 +1,1097 @@
20245 +/*
20246 + *  linux/kernel/vserver/proc.c
20247 + *
20248 + *  Virtual Context Support
20249 + *
20250 + *  Copyright (C) 2003-2011  Herbert Pötzl
20251 + *
20252 + *  V0.01  basic structure
20253 + *  V0.02  adaptation vs1.3.0
20254 + *  V0.03  proc permissions
20255 + *  V0.04  locking/generic
20256 + *  V0.05  next generation procfs
20257 + *  V0.06  inode validation
20258 + *  V0.07  generic rewrite vid
20259 + *  V0.08  remove inode type
20260 + *  V0.09  added u/wmask info
20261 + *
20262 + */
20263 +
20264 +#include <linux/proc_fs.h>
20265 +#include <linux/fs_struct.h>
20266 +#include <linux/mount.h>
20267 +#include <linux/namei.h>
20268 +#include <asm/unistd.h>
20269 +
20270 +#include <linux/vs_context.h>
20271 +#include <linux/vs_network.h>
20272 +#include <linux/vs_cvirt.h>
20273 +
20274 +#include <linux/in.h>
20275 +#include <linux/inetdevice.h>
20276 +#include <linux/vs_inet.h>
20277 +#include <linux/vs_inet6.h>
20278 +
20279 +#include <linux/vserver/global.h>
20280 +
20281 +#include "cvirt_proc.h"
20282 +#include "cacct_proc.h"
20283 +#include "limit_proc.h"
20284 +#include "sched_proc.h"
20285 +#include "vci_config.h"
20286 +
20287 +#include <../../fs/proc/internal.h>
20288 +
20289 +
20290 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20291 +{
20292 +       unsigned __capi;
20293 +
20294 +       CAP_FOR_EACH_U32(__capi) {
20295 +               buffer += sprintf(buffer, "%08x",
20296 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20297 +       }
20298 +       return buffer;
20299 +}
20300 +
20301 +
20302 +static struct proc_dir_entry *proc_virtual;
20303 +
20304 +static struct proc_dir_entry *proc_virtnet;
20305 +
20306 +
20307 +/* first the actual feeds */
20308 +
20309 +
20310 +static int proc_vci(char *buffer)
20311 +{
20312 +       return sprintf(buffer,
20313 +               "VCIVersion:\t%04x:%04x\n"
20314 +               "VCISyscall:\t%d\n"
20315 +               "VCIKernel:\t%08x\n",
20316 +               VCI_VERSION >> 16,
20317 +               VCI_VERSION & 0xFFFF,
20318 +               __NR_vserver,
20319 +               vci_kernel_config());
20320 +}
20321 +
20322 +static int proc_virtual_info(char *buffer)
20323 +{
20324 +       return proc_vci(buffer);
20325 +}
20326 +
20327 +static int proc_virtual_status(char *buffer)
20328 +{
20329 +       return sprintf(buffer,
20330 +               "#CTotal:\t%d\n"
20331 +               "#CActive:\t%d\n"
20332 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20333 +               "#InitTask:\t%d\t%d %d\n",
20334 +               atomic_read(&vx_global_ctotal),
20335 +               atomic_read(&vx_global_cactive),
20336 +               atomic_read(&vs_global_nsproxy),
20337 +               atomic_read(&vs_global_fs),
20338 +               atomic_read(&vs_global_mnt_ns),
20339 +               atomic_read(&vs_global_uts_ns),
20340 +               atomic_read(&nr_ipc_ns),
20341 +               atomic_read(&vs_global_user_ns),
20342 +               atomic_read(&vs_global_pid_ns),
20343 +               atomic_read(&init_task.usage),
20344 +               atomic_read(&init_task.nsproxy->count),
20345 +               init_task.fs->users);
20346 +}
20347 +
20348 +
20349 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20350 +{
20351 +       int length;
20352 +
20353 +       length = sprintf(buffer,
20354 +               "ID:\t%d\n"
20355 +               "Info:\t%p\n"
20356 +               "Init:\t%d\n"
20357 +               "OOM:\t%lld\n",
20358 +               vxi->vx_id,
20359 +               vxi,
20360 +               vxi->vx_initpid,
20361 +               vxi->vx_badness_bias);
20362 +       return length;
20363 +}
20364 +
20365 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
20366 +{
20367 +       char *orig = buffer;
20368 +
20369 +       buffer += sprintf(buffer,
20370 +               "UseCnt:\t%d\n"
20371 +               "Tasks:\t%d\n"
20372 +               "Flags:\t%016llx\n",
20373 +               atomic_read(&vxi->vx_usecnt),
20374 +               atomic_read(&vxi->vx_tasks),
20375 +               (unsigned long long)vxi->vx_flags);
20376 +
20377 +       buffer += sprintf(buffer, "BCaps:\t");
20378 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
20379 +       buffer += sprintf(buffer, "\n");
20380 +
20381 +       buffer += sprintf(buffer,
20382 +               "CCaps:\t%016llx\n"
20383 +               "Umask:\t%16llx\n"
20384 +               "Wmask:\t%16llx\n"
20385 +               "Spaces:\t%08lx %08lx\n",
20386 +               (unsigned long long)vxi->vx_ccaps,
20387 +               (unsigned long long)vxi->vx_umask,
20388 +               (unsigned long long)vxi->vx_wmask,
20389 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
20390 +       return buffer - orig;
20391 +}
20392 +
20393 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
20394 +{
20395 +       return vx_info_proc_limit(&vxi->limit, buffer);
20396 +}
20397 +
20398 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
20399 +{
20400 +       int cpu, length;
20401 +
20402 +       length = vx_info_proc_sched(&vxi->sched, buffer);
20403 +       for_each_online_cpu(cpu) {
20404 +               length += vx_info_proc_sched_pc(
20405 +                       &vx_per_cpu(vxi, sched_pc, cpu),
20406 +                       buffer + length, cpu);
20407 +       }
20408 +       return length;
20409 +}
20410 +
20411 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
20412 +{
20413 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
20414 +}
20415 +
20416 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
20417 +{
20418 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
20419 +}
20420 +
20421 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
20422 +{
20423 +       int cpu, length;
20424 +
20425 +       vx_update_load(vxi);
20426 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
20427 +       for_each_online_cpu(cpu) {
20428 +               length += vx_info_proc_cvirt_pc(
20429 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
20430 +                       buffer + length, cpu);
20431 +       }
20432 +       return length;
20433 +}
20434 +
20435 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
20436 +{
20437 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
20438 +}
20439 +
20440 +
20441 +static int proc_virtnet_info(char *buffer)
20442 +{
20443 +       return proc_vci(buffer);
20444 +}
20445 +
20446 +static int proc_virtnet_status(char *buffer)
20447 +{
20448 +       return sprintf(buffer,
20449 +               "#CTotal:\t%d\n"
20450 +               "#CActive:\t%d\n",
20451 +               atomic_read(&nx_global_ctotal),
20452 +               atomic_read(&nx_global_cactive));
20453 +}
20454 +
20455 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
20456 +{
20457 +       struct nx_addr_v4 *v4a;
20458 +#ifdef CONFIG_IPV6
20459 +       struct nx_addr_v6 *v6a;
20460 +#endif
20461 +       int length, i;
20462 +
20463 +       length = sprintf(buffer,
20464 +               "ID:\t%d\n"
20465 +               "Info:\t%p\n"
20466 +               "Bcast:\t" NIPQUAD_FMT "\n"
20467 +               "Lback:\t" NIPQUAD_FMT "\n",
20468 +               nxi->nx_id,
20469 +               nxi,
20470 +               NIPQUAD(nxi->v4_bcast.s_addr),
20471 +               NIPQUAD(nxi->v4_lback.s_addr));
20472 +
20473 +       if (!NX_IPV4(nxi))
20474 +               goto skip_v4;
20475 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20476 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
20477 +                       i, NXAV4(v4a));
20478 +skip_v4:
20479 +#ifdef CONFIG_IPV6
20480 +       if (!NX_IPV6(nxi))
20481 +               goto skip_v6;
20482 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20483 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
20484 +                       i, NXAV6(v6a));
20485 +skip_v6:
20486 +#endif
20487 +       return length;
20488 +}
20489 +
20490 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
20491 +{
20492 +       int length;
20493 +
20494 +       length = sprintf(buffer,
20495 +               "UseCnt:\t%d\n"
20496 +               "Tasks:\t%d\n"
20497 +               "Flags:\t%016llx\n"
20498 +               "NCaps:\t%016llx\n",
20499 +               atomic_read(&nxi->nx_usecnt),
20500 +               atomic_read(&nxi->nx_tasks),
20501 +               (unsigned long long)nxi->nx_flags,
20502 +               (unsigned long long)nxi->nx_ncaps);
20503 +       return length;
20504 +}
20505 +
20506 +
20507 +
20508 +/* here the inode helpers */
20509 +
20510 +struct vs_entry {
20511 +       int len;
20512 +       char *name;
20513 +       mode_t mode;
20514 +       struct inode_operations *iop;
20515 +       struct file_operations *fop;
20516 +       union proc_op op;
20517 +};
20518 +
20519 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
20520 +{
20521 +       struct inode *inode = new_inode(sb);
20522 +
20523 +       if (!inode)
20524 +               goto out;
20525 +
20526 +       inode->i_mode = p->mode;
20527 +       if (p->iop)
20528 +               inode->i_op = p->iop;
20529 +       if (p->fop)
20530 +               inode->i_fop = p->fop;
20531 +
20532 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
20533 +       inode->i_flags |= S_IMMUTABLE;
20534 +
20535 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
20536 +
20537 +       i_uid_write(inode, 0);
20538 +       i_gid_write(inode, 0);
20539 +       i_tag_write(inode, 0);
20540 +out:
20541 +       return inode;
20542 +}
20543 +
20544 +static struct dentry *vs_proc_instantiate(struct inode *dir,
20545 +       struct dentry *dentry, int id, void *ptr)
20546 +{
20547 +       struct vs_entry *p = ptr;
20548 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
20549 +       struct dentry *error = ERR_PTR(-EINVAL);
20550 +
20551 +       if (!inode)
20552 +               goto out;
20553 +
20554 +       PROC_I(inode)->op = p->op;
20555 +       PROC_I(inode)->fd = id;
20556 +       d_add(dentry, inode);
20557 +       error = NULL;
20558 +out:
20559 +       return error;
20560 +}
20561 +
20562 +/* Lookups */
20563 +
20564 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
20565 +
20566 +
20567 +/*
20568 + * Fill a directory entry.
20569 + *
20570 + * If possible create the dcache entry and derive our inode number and
20571 + * file type from dcache entry.
20572 + *
20573 + * Since all of the proc inode numbers are dynamically generated, the inode
20574 + * numbers do not exist until the inode is cache.  This means creating the
20575 + * the dcache entry in iterate is necessary to keep the inode numbers
20576 + * reported by iterate in sync with the inode numbers reported
20577 + * by stat.
20578 + */
20579 +static int vx_proc_fill_cache(struct file *filp, struct dir_context *ctx,
20580 +       char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
20581 +{
20582 +       struct dentry *child, *dir = filp->f_dentry;
20583 +       struct inode *inode;
20584 +       struct qstr qname;
20585 +       ino_t ino = 0;
20586 +       unsigned type = DT_UNKNOWN;
20587 +
20588 +       qname.name = name;
20589 +       qname.len  = len;
20590 +       qname.hash = full_name_hash(name, len);
20591 +
20592 +       child = d_lookup(dir, &qname);
20593 +       if (!child) {
20594 +               struct dentry *new;
20595 +               new = d_alloc(dir, &qname);
20596 +               if (new) {
20597 +                       child = instantiate(dir->d_inode, new, id, ptr);
20598 +                       if (child)
20599 +                               dput(new);
20600 +                       else
20601 +                               child = new;
20602 +               }
20603 +       }
20604 +       if (!child || IS_ERR(child) || !child->d_inode)
20605 +               goto end_instantiate;
20606 +       inode = child->d_inode;
20607 +       if (inode) {
20608 +               ino = inode->i_ino;
20609 +               type = inode->i_mode >> 12;
20610 +       }
20611 +       dput(child);
20612 +end_instantiate:
20613 +       if (!ino)
20614 +               ino = 1;
20615 +       return !dir_emit(ctx, name, len, ino, type);
20616 +}
20617 +
20618 +
20619 +
20620 +/* get and revalidate vx_info/xid */
20621 +
20622 +static inline
20623 +struct vx_info *get_proc_vx_info(struct inode *inode)
20624 +{
20625 +       return lookup_vx_info(PROC_I(inode)->fd);
20626 +}
20627 +
20628 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
20629 +{
20630 +       struct inode *inode = dentry->d_inode;
20631 +       vxid_t xid = PROC_I(inode)->fd;
20632 +
20633 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20634 +               return -ECHILD;
20635 +
20636 +       if (!xid || xid_is_hashed(xid))
20637 +               return 1;
20638 +       d_drop(dentry);
20639 +       return 0;
20640 +}
20641 +
20642 +
20643 +/* get and revalidate nx_info/nid */
20644 +
20645 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
20646 +{
20647 +       struct inode *inode = dentry->d_inode;
20648 +       vnid_t nid = PROC_I(inode)->fd;
20649 +
20650 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20651 +               return -ECHILD;
20652 +
20653 +       if (!nid || nid_is_hashed(nid))
20654 +               return 1;
20655 +       d_drop(dentry);
20656 +       return 0;
20657 +}
20658 +
20659 +
20660 +
20661 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
20662 +
20663 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
20664 +                         size_t count, loff_t *ppos)
20665 +{
20666 +       struct inode *inode = file->f_dentry->d_inode;
20667 +       unsigned long page;
20668 +       ssize_t length = 0;
20669 +
20670 +       if (count > PROC_BLOCK_SIZE)
20671 +               count = PROC_BLOCK_SIZE;
20672 +
20673 +       /* fade that out as soon as stable */
20674 +       WARN_ON(PROC_I(inode)->fd);
20675 +
20676 +       if (!(page = __get_free_page(GFP_KERNEL)))
20677 +               return -ENOMEM;
20678 +
20679 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
20680 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
20681 +
20682 +       if (length >= 0)
20683 +               length = simple_read_from_buffer(buf, count, ppos,
20684 +                       (char *)page, length);
20685 +
20686 +       free_page(page);
20687 +       return length;
20688 +}
20689 +
20690 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
20691 +                         size_t count, loff_t *ppos)
20692 +{
20693 +       struct inode *inode = file->f_dentry->d_inode;
20694 +       struct vx_info *vxi = NULL;
20695 +       vxid_t xid = PROC_I(inode)->fd;
20696 +       unsigned long page;
20697 +       ssize_t length = 0;
20698 +
20699 +       if (count > PROC_BLOCK_SIZE)
20700 +               count = PROC_BLOCK_SIZE;
20701 +
20702 +       /* fade that out as soon as stable */
20703 +       WARN_ON(!xid);
20704 +       vxi = lookup_vx_info(xid);
20705 +       if (!vxi)
20706 +               goto out;
20707 +
20708 +       length = -ENOMEM;
20709 +       if (!(page = __get_free_page(GFP_KERNEL)))
20710 +               goto out_put;
20711 +
20712 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
20713 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
20714 +
20715 +       if (length >= 0)
20716 +               length = simple_read_from_buffer(buf, count, ppos,
20717 +                       (char *)page, length);
20718 +
20719 +       free_page(page);
20720 +out_put:
20721 +       put_vx_info(vxi);
20722 +out:
20723 +       return length;
20724 +}
20725 +
20726 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
20727 +                         size_t count, loff_t *ppos)
20728 +{
20729 +       struct inode *inode = file->f_dentry->d_inode;
20730 +       struct nx_info *nxi = NULL;
20731 +       vnid_t nid = PROC_I(inode)->fd;
20732 +       unsigned long page;
20733 +       ssize_t length = 0;
20734 +
20735 +       if (count > PROC_BLOCK_SIZE)
20736 +               count = PROC_BLOCK_SIZE;
20737 +
20738 +       /* fade that out as soon as stable */
20739 +       WARN_ON(!nid);
20740 +       nxi = lookup_nx_info(nid);
20741 +       if (!nxi)
20742 +               goto out;
20743 +
20744 +       length = -ENOMEM;
20745 +       if (!(page = __get_free_page(GFP_KERNEL)))
20746 +               goto out_put;
20747 +
20748 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
20749 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
20750 +
20751 +       if (length >= 0)
20752 +               length = simple_read_from_buffer(buf, count, ppos,
20753 +                       (char *)page, length);
20754 +
20755 +       free_page(page);
20756 +out_put:
20757 +       put_nx_info(nxi);
20758 +out:
20759 +       return length;
20760 +}
20761 +
20762 +
20763 +
20764 +/* here comes the lower level */
20765 +
20766 +
20767 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
20768 +       .len  = sizeof(NAME) - 1,       \
20769 +       .name = (NAME),                 \
20770 +       .mode = MODE,                   \
20771 +       .iop  = IOP,                    \
20772 +       .fop  = FOP,                    \
20773 +       .op   = OP,                     \
20774 +}
20775 +
20776 +
20777 +#define DIR(NAME, MODE, OTYPE)                         \
20778 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
20779 +               &proc_ ## OTYPE ## _inode_operations,   \
20780 +               &proc_ ## OTYPE ## _file_operations, { } )
20781 +
20782 +#define INF(NAME, MODE, OTYPE)                         \
20783 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20784 +               &proc_vs_info_file_operations,          \
20785 +               { .proc_vs_read = &proc_##OTYPE } )
20786 +
20787 +#define VINF(NAME, MODE, OTYPE)                                \
20788 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20789 +               &proc_vx_info_file_operations,          \
20790 +               { .proc_vxi_read = &proc_##OTYPE } )
20791 +
20792 +#define NINF(NAME, MODE, OTYPE)                                \
20793 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20794 +               &proc_nx_info_file_operations,          \
20795 +               { .proc_nxi_read = &proc_##OTYPE } )
20796 +
20797 +
20798 +static struct file_operations proc_vs_info_file_operations = {
20799 +       .read =         proc_vs_info_read,
20800 +};
20801 +
20802 +static struct file_operations proc_vx_info_file_operations = {
20803 +       .read =         proc_vx_info_read,
20804 +};
20805 +
20806 +static struct dentry_operations proc_xid_dentry_operations = {
20807 +       .d_revalidate = proc_xid_revalidate,
20808 +};
20809 +
20810 +static struct vs_entry vx_base_stuff[] = {
20811 +       VINF("info",    S_IRUGO, vxi_info),
20812 +       VINF("status",  S_IRUGO, vxi_status),
20813 +       VINF("limit",   S_IRUGO, vxi_limit),
20814 +       VINF("sched",   S_IRUGO, vxi_sched),
20815 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
20816 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
20817 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
20818 +       VINF("cacct",   S_IRUGO, vxi_cacct),
20819 +       {}
20820 +};
20821 +
20822 +
20823 +
20824 +
20825 +static struct dentry *proc_xid_instantiate(struct inode *dir,
20826 +       struct dentry *dentry, int id, void *ptr)
20827 +{
20828 +       dentry->d_op = &proc_xid_dentry_operations;
20829 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20830 +}
20831 +
20832 +static struct dentry *proc_xid_lookup(struct inode *dir,
20833 +       struct dentry *dentry, unsigned int flags)
20834 +{
20835 +       struct vs_entry *p = vx_base_stuff;
20836 +       struct dentry *error = ERR_PTR(-ENOENT);
20837 +
20838 +       for (; p->name; p++) {
20839 +               if (p->len != dentry->d_name.len)
20840 +                       continue;
20841 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20842 +                       break;
20843 +       }
20844 +       if (!p->name)
20845 +               goto out;
20846 +
20847 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20848 +out:
20849 +       return error;
20850 +}
20851 +
20852 +static int proc_xid_iterate(struct file *filp, struct dir_context *ctx)
20853 +{
20854 +       struct dentry *dentry = filp->f_dentry;
20855 +       struct inode *inode = dentry->d_inode;
20856 +       struct vs_entry *p = vx_base_stuff;
20857 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
20858 +       int index;
20859 +       u64 ino;
20860 +
20861 +       switch (ctx->pos) {
20862 +       case 0:
20863 +               ino = inode->i_ino;
20864 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20865 +                       goto out;
20866 +               ctx->pos++;
20867 +               /* fall through */
20868 +       case 1:
20869 +               ino = parent_ino(dentry);
20870 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20871 +                       goto out;
20872 +               ctx->pos++;
20873 +               /* fall through */
20874 +       default:
20875 +               index = ctx->pos - 2;
20876 +               if (index >= size)
20877 +                       goto out;
20878 +               for (p += index; p->name; p++) {
20879 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20880 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20881 +                               goto out;
20882 +                       ctx->pos++;
20883 +               }
20884 +       }
20885 +out:
20886 +       return 1;
20887 +}
20888 +
20889 +
20890 +
20891 +static struct file_operations proc_nx_info_file_operations = {
20892 +       .read =         proc_nx_info_read,
20893 +};
20894 +
20895 +static struct dentry_operations proc_nid_dentry_operations = {
20896 +       .d_revalidate = proc_nid_revalidate,
20897 +};
20898 +
20899 +static struct vs_entry nx_base_stuff[] = {
20900 +       NINF("info",    S_IRUGO, nxi_info),
20901 +       NINF("status",  S_IRUGO, nxi_status),
20902 +       {}
20903 +};
20904 +
20905 +
20906 +static struct dentry *proc_nid_instantiate(struct inode *dir,
20907 +       struct dentry *dentry, int id, void *ptr)
20908 +{
20909 +       dentry->d_op = &proc_nid_dentry_operations;
20910 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20911 +}
20912 +
20913 +static struct dentry *proc_nid_lookup(struct inode *dir,
20914 +       struct dentry *dentry, unsigned int flags)
20915 +{
20916 +       struct vs_entry *p = nx_base_stuff;
20917 +       struct dentry *error = ERR_PTR(-ENOENT);
20918 +
20919 +       for (; p->name; p++) {
20920 +               if (p->len != dentry->d_name.len)
20921 +                       continue;
20922 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20923 +                       break;
20924 +       }
20925 +       if (!p->name)
20926 +               goto out;
20927 +
20928 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20929 +out:
20930 +       return error;
20931 +}
20932 +
20933 +static int proc_nid_iterate(struct file *filp, struct dir_context *ctx)
20934 +{
20935 +       struct dentry *dentry = filp->f_dentry;
20936 +       struct inode *inode = dentry->d_inode;
20937 +       struct vs_entry *p = nx_base_stuff;
20938 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
20939 +       int index;
20940 +       u64 ino;
20941 +
20942 +       switch (ctx->pos) {
20943 +       case 0:
20944 +               ino = inode->i_ino;
20945 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20946 +                       goto out;
20947 +               ctx->pos++;
20948 +               /* fall through */
20949 +       case 1:
20950 +               ino = parent_ino(dentry);
20951 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20952 +                       goto out;
20953 +               ctx->pos++;
20954 +               /* fall through */
20955 +       default:
20956 +               index = ctx->pos - 2;
20957 +               if (index >= size)
20958 +                       goto out;
20959 +               for (p += index; p->name; p++) {
20960 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20961 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20962 +                               goto out;
20963 +                       ctx->pos++;
20964 +               }
20965 +       }
20966 +out:
20967 +       return 1;
20968 +}
20969 +
20970 +
20971 +#define MAX_MULBY10    ((~0U - 9) / 10)
20972 +
20973 +static inline int atovid(const char *str, int len)
20974 +{
20975 +       int vid, c;
20976 +
20977 +       vid = 0;
20978 +       while (len-- > 0) {
20979 +               c = *str - '0';
20980 +               str++;
20981 +               if (c > 9)
20982 +                       return -1;
20983 +               if (vid >= MAX_MULBY10)
20984 +                       return -1;
20985 +               vid *= 10;
20986 +               vid += c;
20987 +               if (!vid)
20988 +                       return -1;
20989 +       }
20990 +       return vid;
20991 +}
20992 +
20993 +/* now the upper level (virtual) */
20994 +
20995 +
20996 +static struct file_operations proc_xid_file_operations = {
20997 +       .read =         generic_read_dir,
20998 +       .iterate =      proc_xid_iterate,
20999 +};
21000 +
21001 +static struct inode_operations proc_xid_inode_operations = {
21002 +       .lookup =       proc_xid_lookup,
21003 +};
21004 +
21005 +static struct vs_entry vx_virtual_stuff[] = {
21006 +       INF("info",     S_IRUGO, virtual_info),
21007 +       INF("status",   S_IRUGO, virtual_status),
21008 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21009 +};
21010 +
21011 +
21012 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21013 +       struct dentry *dentry, unsigned int flags)
21014 +{
21015 +       struct vs_entry *p = vx_virtual_stuff;
21016 +       struct dentry *error = ERR_PTR(-ENOENT);
21017 +       int id = 0;
21018 +
21019 +       for (; p->name; p++) {
21020 +               if (p->len != dentry->d_name.len)
21021 +                       continue;
21022 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21023 +                       break;
21024 +       }
21025 +       if (p->name)
21026 +               goto instantiate;
21027 +
21028 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21029 +       if ((id < 0) || !xid_is_hashed(id))
21030 +               goto out;
21031 +
21032 +instantiate:
21033 +       error = proc_xid_instantiate(dir, dentry, id, p);
21034 +out:
21035 +       return error;
21036 +}
21037 +
21038 +static struct file_operations proc_nid_file_operations = {
21039 +       .read =         generic_read_dir,
21040 +       .iterate =      proc_nid_iterate,
21041 +};
21042 +
21043 +static struct inode_operations proc_nid_inode_operations = {
21044 +       .lookup =       proc_nid_lookup,
21045 +};
21046 +
21047 +static struct vs_entry nx_virtnet_stuff[] = {
21048 +       INF("info",     S_IRUGO, virtnet_info),
21049 +       INF("status",   S_IRUGO, virtnet_status),
21050 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21051 +};
21052 +
21053 +
21054 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21055 +       struct dentry *dentry, unsigned int flags)
21056 +{
21057 +       struct vs_entry *p = nx_virtnet_stuff;
21058 +       struct dentry *error = ERR_PTR(-ENOENT);
21059 +       int id = 0;
21060 +
21061 +       for (; p->name; p++) {
21062 +               if (p->len != dentry->d_name.len)
21063 +                       continue;
21064 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21065 +                       break;
21066 +       }
21067 +       if (p->name)
21068 +               goto instantiate;
21069 +
21070 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21071 +       if ((id < 0) || !nid_is_hashed(id))
21072 +               goto out;
21073 +
21074 +instantiate:
21075 +       error = proc_nid_instantiate(dir, dentry, id, p);
21076 +out:
21077 +       return error;
21078 +}
21079 +
21080 +
21081 +#define PROC_MAXVIDS 32
21082 +
21083 +int proc_virtual_iterate(struct file *filp, struct dir_context *ctx)
21084 +{
21085 +       struct dentry *dentry = filp->f_dentry;
21086 +       struct inode *inode = dentry->d_inode;
21087 +       struct vs_entry *p = vx_virtual_stuff;
21088 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21089 +       int index;
21090 +       unsigned int xid_array[PROC_MAXVIDS];
21091 +       char buf[PROC_NUMBUF];
21092 +       unsigned int nr_xids, i;
21093 +       u64 ino;
21094 +
21095 +       switch (ctx->pos) {
21096 +       case 0:
21097 +               ino = inode->i_ino;
21098 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21099 +                       goto out;
21100 +               ctx->pos++;
21101 +               /* fall through */
21102 +       case 1:
21103 +               ino = parent_ino(dentry);
21104 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21105 +                       goto out;
21106 +               ctx->pos++;
21107 +               /* fall through */
21108 +       default:
21109 +               index = ctx->pos - 2;
21110 +               if (index >= size)
21111 +                       goto entries;
21112 +               for (p += index; p->name; p++) {
21113 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21114 +                               vs_proc_instantiate, 0, p))
21115 +                               goto out;
21116 +                       ctx->pos++;
21117 +               }
21118 +       entries:
21119 +               index = ctx->pos - size;
21120 +               p = &vx_virtual_stuff[size - 1];
21121 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21122 +               for (i = 0; i < nr_xids; i++) {
21123 +                       int n, xid = xid_array[i];
21124 +                       unsigned int j = PROC_NUMBUF;
21125 +
21126 +                       n = xid;
21127 +                       do
21128 +                               buf[--j] = '0' + (n % 10);
21129 +                       while (n /= 10);
21130 +
21131 +                       if (vx_proc_fill_cache(filp, ctx,
21132 +                               buf + j, PROC_NUMBUF - j,
21133 +                               vs_proc_instantiate, xid, p))
21134 +                               goto out;
21135 +                       ctx->pos++;
21136 +               }
21137 +       }
21138 +out:
21139 +       return 0;
21140 +}
21141 +
21142 +static int proc_virtual_getattr(struct vfsmount *mnt,
21143 +       struct dentry *dentry, struct kstat *stat)
21144 +{
21145 +       struct inode *inode = dentry->d_inode;
21146 +
21147 +       generic_fillattr(inode, stat);
21148 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21149 +       return 0;
21150 +}
21151 +
21152 +static struct file_operations proc_virtual_dir_operations = {
21153 +       .read =         generic_read_dir,
21154 +       .iterate =      proc_virtual_iterate,
21155 +};
21156 +
21157 +static struct inode_operations proc_virtual_dir_inode_operations = {
21158 +       .getattr =      proc_virtual_getattr,
21159 +       .lookup =       proc_virtual_lookup,
21160 +};
21161 +
21162 +
21163 +
21164 +int proc_virtnet_iterate(struct file *filp, struct dir_context *ctx)
21165 +{
21166 +       struct dentry *dentry = filp->f_dentry;
21167 +       struct inode *inode = dentry->d_inode;
21168 +       struct vs_entry *p = nx_virtnet_stuff;
21169 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21170 +       int index;
21171 +       unsigned int nid_array[PROC_MAXVIDS];
21172 +       char buf[PROC_NUMBUF];
21173 +       unsigned int nr_nids, i;
21174 +       u64 ino;
21175 +
21176 +       switch (ctx->pos) {
21177 +       case 0:
21178 +               ino = inode->i_ino;
21179 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21180 +                       goto out;
21181 +               ctx->pos++;
21182 +               /* fall through */
21183 +       case 1:
21184 +               ino = parent_ino(dentry);
21185 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21186 +                       goto out;
21187 +               ctx->pos++;
21188 +               /* fall through */
21189 +       default:
21190 +               index = ctx->pos - 2;
21191 +               if (index >= size)
21192 +                       goto entries;
21193 +               for (p += index; p->name; p++) {
21194 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21195 +                               vs_proc_instantiate, 0, p))
21196 +                               goto out;
21197 +                       ctx->pos++;
21198 +               }
21199 +       entries:
21200 +               index = ctx->pos - size;
21201 +               p = &nx_virtnet_stuff[size - 1];
21202 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21203 +               for (i = 0; i < nr_nids; i++) {
21204 +                       int n, nid = nid_array[i];
21205 +                       unsigned int j = PROC_NUMBUF;
21206 +
21207 +                       n = nid;
21208 +                       do
21209 +                               buf[--j] = '0' + (n % 10);
21210 +                       while (n /= 10);
21211 +
21212 +                       if (vx_proc_fill_cache(filp, ctx,
21213 +                               buf + j, PROC_NUMBUF - j,
21214 +                               vs_proc_instantiate, nid, p))
21215 +                               goto out;
21216 +                       ctx->pos++;
21217 +               }
21218 +       }
21219 +out:
21220 +       return 0;
21221 +}
21222 +
21223 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21224 +       struct dentry *dentry, struct kstat *stat)
21225 +{
21226 +       struct inode *inode = dentry->d_inode;
21227 +
21228 +       generic_fillattr(inode, stat);
21229 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21230 +       return 0;
21231 +}
21232 +
21233 +static struct file_operations proc_virtnet_dir_operations = {
21234 +       .read =         generic_read_dir,
21235 +       .iterate =      proc_virtnet_iterate,
21236 +};
21237 +
21238 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21239 +       .getattr =      proc_virtnet_getattr,
21240 +       .lookup =       proc_virtnet_lookup,
21241 +};
21242 +
21243 +
21244 +
21245 +void proc_vx_init(void)
21246 +{
21247 +       struct proc_dir_entry *ent;
21248 +
21249 +       ent = proc_mkdir("virtual", 0);
21250 +       if (ent) {
21251 +               ent->proc_fops = &proc_virtual_dir_operations;
21252 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21253 +       }
21254 +       proc_virtual = ent;
21255 +
21256 +       ent = proc_mkdir("virtnet", 0);
21257 +       if (ent) {
21258 +               ent->proc_fops = &proc_virtnet_dir_operations;
21259 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21260 +       }
21261 +       proc_virtnet = ent;
21262 +}
21263 +
21264 +
21265 +
21266 +
21267 +/* per pid info */
21268 +
21269 +
21270 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21271 +{
21272 +       struct vx_info *vxi;
21273 +       char *orig = buffer;
21274 +
21275 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21276 +
21277 +       vxi = task_get_vx_info(p);
21278 +       if (!vxi)
21279 +               goto out;
21280 +
21281 +       buffer += sprintf(buffer, "BCaps:\t");
21282 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21283 +       buffer += sprintf(buffer, "\n");
21284 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21285 +               (unsigned long long)vxi->vx_ccaps);
21286 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21287 +               (unsigned long long)vxi->vx_flags);
21288 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21289 +
21290 +       put_vx_info(vxi);
21291 +out:
21292 +       return buffer - orig;
21293 +}
21294 +
21295 +
21296 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21297 +{
21298 +       struct nx_info *nxi;
21299 +       struct nx_addr_v4 *v4a;
21300 +#ifdef CONFIG_IPV6
21301 +       struct nx_addr_v6 *v6a;
21302 +#endif
21303 +       char *orig = buffer;
21304 +       int i;
21305 +
21306 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21307 +
21308 +       nxi = task_get_nx_info(p);
21309 +       if (!nxi)
21310 +               goto out;
21311 +
21312 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21313 +               (unsigned long long)nxi->nx_ncaps);
21314 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21315 +               (unsigned long long)nxi->nx_flags);
21316 +
21317 +       buffer += sprintf(buffer,
21318 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21319 +               NIPQUAD(nxi->v4_bcast.s_addr));
21320 +       buffer += sprintf (buffer,
21321 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21322 +               NIPQUAD(nxi->v4_lback.s_addr));
21323 +       if (!NX_IPV4(nxi))
21324 +               goto skip_v4;
21325 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21326 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21327 +                       i, NXAV4(v4a));
21328 +skip_v4:
21329 +#ifdef CONFIG_IPV6
21330 +       if (!NX_IPV6(nxi))
21331 +               goto skip_v6;
21332 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21333 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
21334 +                       i, NXAV6(v6a));
21335 +skip_v6:
21336 +#endif
21337 +       put_nx_info(nxi);
21338 +out:
21339 +       return buffer - orig;
21340 +}
21341 +
21342 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sched.c linux-3.13.10-vs2.3.6.11/kernel/vserver/sched.c
21343 --- linux-3.13.10/kernel/vserver/sched.c        1970-01-01 00:00:00.000000000 +0000
21344 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched.c     2014-01-31 20:38:04.000000000 +0000
21345 @@ -0,0 +1,83 @@
21346 +/*
21347 + *  linux/kernel/vserver/sched.c
21348 + *
21349 + *  Virtual Server: Scheduler Support
21350 + *
21351 + *  Copyright (C) 2004-2010  Herbert Pötzl
21352 + *
21353 + *  V0.01  adapted Sam Vilains version to 2.6.3
21354 + *  V0.02  removed legacy interface
21355 + *  V0.03  changed vcmds to vxi arg
21356 + *  V0.04  removed older and legacy interfaces
21357 + *  V0.05  removed scheduler code/commands
21358 + *
21359 + */
21360 +
21361 +#include <linux/vs_context.h>
21362 +#include <linux/vs_sched.h>
21363 +#include <linux/cpumask.h>
21364 +#include <linux/vserver/sched_cmd.h>
21365 +
21366 +#include <asm/uaccess.h>
21367 +
21368 +
21369 +void vx_update_sched_param(struct _vx_sched *sched,
21370 +       struct _vx_sched_pc *sched_pc)
21371 +{
21372 +       sched_pc->prio_bias = sched->prio_bias;
21373 +}
21374 +
21375 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
21376 +{
21377 +       int cpu;
21378 +
21379 +       if (data->prio_bias > MAX_PRIO_BIAS)
21380 +               data->prio_bias = MAX_PRIO_BIAS;
21381 +       if (data->prio_bias < MIN_PRIO_BIAS)
21382 +               data->prio_bias = MIN_PRIO_BIAS;
21383 +
21384 +       if (data->cpu_id != ~0) {
21385 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
21386 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
21387 +                       cpu_online_mask);
21388 +       } else
21389 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
21390 +
21391 +       for_each_cpu_mask(cpu, vxi->sched.update)
21392 +               vx_update_sched_param(&vxi->sched,
21393 +                       &vx_per_cpu(vxi, sched_pc, cpu));
21394 +       return 0;
21395 +}
21396 +
21397 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
21398 +{
21399 +       struct vcmd_prio_bias vc_data;
21400 +
21401 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21402 +               return -EFAULT;
21403 +
21404 +       return do_set_prio_bias(vxi, &vc_data);
21405 +}
21406 +
21407 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
21408 +{
21409 +       struct vcmd_prio_bias vc_data;
21410 +       struct _vx_sched_pc *pcd;
21411 +       int cpu;
21412 +
21413 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21414 +               return -EFAULT;
21415 +
21416 +       cpu = vc_data.cpu_id;
21417 +
21418 +       if (!cpu_possible(cpu))
21419 +               return -EINVAL;
21420 +
21421 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
21422 +       vc_data.prio_bias = pcd->prio_bias;
21423 +
21424 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21425 +               return -EFAULT;
21426 +       return 0;
21427 +}
21428 +
21429 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
21430 --- linux-3.13.10/kernel/vserver/sched_init.h   1970-01-01 00:00:00.000000000 +0000
21431 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_init.h        2014-01-31 20:38:04.000000000 +0000
21432 @@ -0,0 +1,27 @@
21433 +
21434 +static inline void vx_info_init_sched(struct _vx_sched *sched)
21435 +{
21436 +       /* scheduling; hard code starting values as constants */
21437 +       sched->prio_bias = 0;
21438 +}
21439 +
21440 +static inline
21441 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21442 +{
21443 +       sched_pc->prio_bias = 0;
21444 +
21445 +       sched_pc->user_ticks = 0;
21446 +       sched_pc->sys_ticks = 0;
21447 +       sched_pc->hold_ticks = 0;
21448 +}
21449 +
21450 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
21451 +{
21452 +       return;
21453 +}
21454 +
21455 +static inline
21456 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21457 +{
21458 +       return;
21459 +}
21460 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
21461 --- linux-3.13.10/kernel/vserver/sched_proc.h   1970-01-01 00:00:00.000000000 +0000
21462 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_proc.h        2014-01-31 20:38:04.000000000 +0000
21463 @@ -0,0 +1,32 @@
21464 +#ifndef _VX_SCHED_PROC_H
21465 +#define _VX_SCHED_PROC_H
21466 +
21467 +
21468 +static inline
21469 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
21470 +{
21471 +       int length = 0;
21472 +
21473 +       length += sprintf(buffer,
21474 +               "PrioBias:\t%8d\n",
21475 +               sched->prio_bias);
21476 +       return length;
21477 +}
21478 +
21479 +static inline
21480 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
21481 +       char *buffer, int cpu)
21482 +{
21483 +       int length = 0;
21484 +
21485 +       length += sprintf(buffer + length,
21486 +               "cpu %d: %lld %lld %lld", cpu,
21487 +               (unsigned long long)sched_pc->user_ticks,
21488 +               (unsigned long long)sched_pc->sys_ticks,
21489 +               (unsigned long long)sched_pc->hold_ticks);
21490 +       length += sprintf(buffer + length,
21491 +               " %d\n", sched_pc->prio_bias);
21492 +       return length;
21493 +}
21494 +
21495 +#endif /* _VX_SCHED_PROC_H */
21496 diff -NurpP --minimal linux-3.13.10/kernel/vserver/signal.c linux-3.13.10-vs2.3.6.11/kernel/vserver/signal.c
21497 --- linux-3.13.10/kernel/vserver/signal.c       1970-01-01 00:00:00.000000000 +0000
21498 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/signal.c    2014-01-31 20:38:04.000000000 +0000
21499 @@ -0,0 +1,134 @@
21500 +/*
21501 + *  linux/kernel/vserver/signal.c
21502 + *
21503 + *  Virtual Server: Signal Support
21504 + *
21505 + *  Copyright (C) 2003-2007  Herbert Pötzl
21506 + *
21507 + *  V0.01  broken out from vcontext V0.05
21508 + *  V0.02  changed vcmds to vxi arg
21509 + *  V0.03  adjusted siginfo for kill
21510 + *
21511 + */
21512 +
21513 +#include <asm/uaccess.h>
21514 +
21515 +#include <linux/vs_context.h>
21516 +#include <linux/vs_pid.h>
21517 +#include <linux/vserver/signal_cmd.h>
21518 +
21519 +
21520 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
21521 +{
21522 +       int retval, count = 0;
21523 +       struct task_struct *p;
21524 +       struct siginfo *sip = SEND_SIG_PRIV;
21525 +
21526 +       retval = -ESRCH;
21527 +       vxdprintk(VXD_CBIT(misc, 4),
21528 +               "vx_info_kill(%p[#%d],%d,%d)*",
21529 +               vxi, vxi->vx_id, pid, sig);
21530 +       read_lock(&tasklist_lock);
21531 +       switch (pid) {
21532 +       case  0:
21533 +       case -1:
21534 +               for_each_process(p) {
21535 +                       int err = 0;
21536 +
21537 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
21538 +                               (pid && vxi->vx_initpid == p->pid))
21539 +                               continue;
21540 +
21541 +                       err = group_send_sig_info(sig, sip, p);
21542 +                       ++count;
21543 +                       if (err != -EPERM)
21544 +                               retval = err;
21545 +               }
21546 +               break;
21547 +
21548 +       case 1:
21549 +               if (vxi->vx_initpid) {
21550 +                       pid = vxi->vx_initpid;
21551 +                       /* for now, only SIGINT to private init ... */
21552 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21553 +                               /* ... as long as there are tasks left */
21554 +                               (atomic_read(&vxi->vx_tasks) > 1))
21555 +                               sig = SIGINT;
21556 +               }
21557 +               /* fallthrough */
21558 +       default:
21559 +               rcu_read_lock();
21560 +               p = find_task_by_real_pid(pid);
21561 +               rcu_read_unlock();
21562 +               if (p) {
21563 +                       if (vx_task_xid(p) == vxi->vx_id)
21564 +                               retval = group_send_sig_info(sig, sip, p);
21565 +               }
21566 +               break;
21567 +       }
21568 +       read_unlock(&tasklist_lock);
21569 +       vxdprintk(VXD_CBIT(misc, 4),
21570 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
21571 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
21572 +       return retval;
21573 +}
21574 +
21575 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
21576 +{
21577 +       struct vcmd_ctx_kill_v0 vc_data;
21578 +
21579 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21580 +               return -EFAULT;
21581 +
21582 +       /* special check to allow guest shutdown */
21583 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21584 +               /* forbid killall pid=0 when init is present */
21585 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
21586 +               (vc_data.pid > 1)))
21587 +               return -EACCES;
21588 +
21589 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
21590 +}
21591 +
21592 +
21593 +static int __wait_exit(struct vx_info *vxi)
21594 +{
21595 +       DECLARE_WAITQUEUE(wait, current);
21596 +       int ret = 0;
21597 +
21598 +       add_wait_queue(&vxi->vx_wait, &wait);
21599 +       set_current_state(TASK_INTERRUPTIBLE);
21600 +
21601 +wait:
21602 +       if (vx_info_state(vxi,
21603 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
21604 +               goto out;
21605 +       if (signal_pending(current)) {
21606 +               ret = -ERESTARTSYS;
21607 +               goto out;
21608 +       }
21609 +       schedule();
21610 +       goto wait;
21611 +
21612 +out:
21613 +       set_current_state(TASK_RUNNING);
21614 +       remove_wait_queue(&vxi->vx_wait, &wait);
21615 +       return ret;
21616 +}
21617 +
21618 +
21619 +
21620 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
21621 +{
21622 +       struct vcmd_wait_exit_v0 vc_data;
21623 +       int ret;
21624 +
21625 +       ret = __wait_exit(vxi);
21626 +       vc_data.reboot_cmd = vxi->reboot_cmd;
21627 +       vc_data.exit_code = vxi->exit_code;
21628 +
21629 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21630 +               ret = -EFAULT;
21631 +       return ret;
21632 +}
21633 +
21634 diff -NurpP --minimal linux-3.13.10/kernel/vserver/space.c linux-3.13.10-vs2.3.6.11/kernel/vserver/space.c
21635 --- linux-3.13.10/kernel/vserver/space.c        1970-01-01 00:00:00.000000000 +0000
21636 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/space.c     2014-02-01 12:21:24.000000000 +0000
21637 @@ -0,0 +1,436 @@
21638 +/*
21639 + *  linux/kernel/vserver/space.c
21640 + *
21641 + *  Virtual Server: Context Space Support
21642 + *
21643 + *  Copyright (C) 2003-2010  Herbert Pötzl
21644 + *
21645 + *  V0.01  broken out from context.c 0.07
21646 + *  V0.02  added task locking for namespace
21647 + *  V0.03  broken out vx_enter_namespace
21648 + *  V0.04  added *space support and commands
21649 + *  V0.05  added credential support
21650 + *
21651 + */
21652 +
21653 +#include <linux/utsname.h>
21654 +#include <linux/nsproxy.h>
21655 +#include <linux/err.h>
21656 +#include <linux/fs_struct.h>
21657 +#include <linux/cred.h>
21658 +#include <asm/uaccess.h>
21659 +
21660 +#include <linux/vs_context.h>
21661 +#include <linux/vserver/space.h>
21662 +#include <linux/vserver/space_cmd.h>
21663 +
21664 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
21665 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
21666 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
21667 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
21668 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
21669 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
21670 +
21671 +
21672 +/* namespace functions */
21673 +
21674 +#include <linux/mnt_namespace.h>
21675 +#include <linux/user_namespace.h>
21676 +#include <linux/pid_namespace.h>
21677 +#include <linux/ipc_namespace.h>
21678 +#include <net/net_namespace.h>
21679 +#include "../fs/mount.h"
21680 +
21681 +
21682 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
21683 +       .mask = CLONE_FS |
21684 +               CLONE_NEWNS |
21685 +#ifdef CONFIG_UTS_NS
21686 +               CLONE_NEWUTS |
21687 +#endif
21688 +#ifdef CONFIG_IPC_NS
21689 +               CLONE_NEWIPC |
21690 +#endif
21691 +#ifdef CONFIG_USER_NS
21692 +               CLONE_NEWUSER |
21693 +#endif
21694 +               0
21695 +};
21696 +
21697 +static const struct vcmd_space_mask_v1 space_mask = {
21698 +       .mask = CLONE_FS |
21699 +               CLONE_NEWNS |
21700 +#ifdef CONFIG_UTS_NS
21701 +               CLONE_NEWUTS |
21702 +#endif
21703 +#ifdef CONFIG_IPC_NS
21704 +               CLONE_NEWIPC |
21705 +#endif
21706 +#ifdef CONFIG_USER_NS
21707 +               CLONE_NEWUSER |
21708 +#endif
21709 +#ifdef CONFIG_PID_NS
21710 +               CLONE_NEWPID |
21711 +#endif
21712 +#ifdef CONFIG_NET_NS
21713 +               CLONE_NEWNET |
21714 +#endif
21715 +               0
21716 +};
21717 +
21718 +static const struct vcmd_space_mask_v1 default_space_mask = {
21719 +       .mask = CLONE_FS |
21720 +               CLONE_NEWNS |
21721 +#ifdef CONFIG_UTS_NS
21722 +               CLONE_NEWUTS |
21723 +#endif
21724 +#ifdef CONFIG_IPC_NS
21725 +               CLONE_NEWIPC |
21726 +#endif
21727 +#ifdef CONFIG_USER_NS
21728 +               CLONE_NEWUSER |
21729 +#endif
21730 +#ifdef CONFIG_PID_NS
21731 +//             CLONE_NEWPID |
21732 +#endif
21733 +               0
21734 +};
21735 +
21736 +/*
21737 + *     build a new nsproxy mix
21738 + *      assumes that both proxies are 'const'
21739 + *     does not touch nsproxy refcounts
21740 + *     will hold a reference on the result.
21741 + */
21742 +
21743 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
21744 +       struct nsproxy *new_nsproxy, unsigned long mask)
21745 +{
21746 +       struct mnt_namespace *old_ns;
21747 +       struct uts_namespace *old_uts;
21748 +       struct ipc_namespace *old_ipc;
21749 +#ifdef CONFIG_PID_NS
21750 +       struct pid_namespace *old_pid;
21751 +#endif
21752 +#ifdef CONFIG_NET_NS
21753 +       struct net *old_net;
21754 +#endif
21755 +       struct nsproxy *nsproxy;
21756 +
21757 +       nsproxy = copy_nsproxy(old_nsproxy);
21758 +       if (!nsproxy)
21759 +               goto out;
21760 +
21761 +       if (mask & CLONE_NEWNS) {
21762 +               old_ns = nsproxy->mnt_ns;
21763 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
21764 +               if (nsproxy->mnt_ns)
21765 +                       get_mnt_ns(nsproxy->mnt_ns);
21766 +       } else
21767 +               old_ns = NULL;
21768 +
21769 +       if (mask & CLONE_NEWUTS) {
21770 +               old_uts = nsproxy->uts_ns;
21771 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
21772 +               if (nsproxy->uts_ns)
21773 +                       get_uts_ns(nsproxy->uts_ns);
21774 +       } else
21775 +               old_uts = NULL;
21776 +
21777 +       if (mask & CLONE_NEWIPC) {
21778 +               old_ipc = nsproxy->ipc_ns;
21779 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
21780 +               if (nsproxy->ipc_ns)
21781 +                       get_ipc_ns(nsproxy->ipc_ns);
21782 +       } else
21783 +               old_ipc = NULL;
21784 +
21785 +#ifdef CONFIG_PID_NS
21786 +       if (mask & CLONE_NEWPID) {
21787 +               old_pid = nsproxy->pid_ns_for_children;
21788 +               nsproxy->pid_ns_for_children = new_nsproxy->pid_ns_for_children;
21789 +               if (nsproxy->pid_ns_for_children)
21790 +                       get_pid_ns(nsproxy->pid_ns_for_children);
21791 +       } else
21792 +               old_pid = NULL;
21793 +#endif
21794 +#ifdef CONFIG_NET_NS
21795 +       if (mask & CLONE_NEWNET) {
21796 +               old_net = nsproxy->net_ns;
21797 +               nsproxy->net_ns = new_nsproxy->net_ns;
21798 +               if (nsproxy->net_ns)
21799 +                       get_net(nsproxy->net_ns);
21800 +       } else
21801 +               old_net = NULL;
21802 +#endif
21803 +       if (old_ns)
21804 +               put_mnt_ns(old_ns);
21805 +       if (old_uts)
21806 +               put_uts_ns(old_uts);
21807 +       if (old_ipc)
21808 +               put_ipc_ns(old_ipc);
21809 +#ifdef CONFIG_PID_NS
21810 +       if (old_pid)
21811 +               put_pid_ns(old_pid);
21812 +#endif
21813 +#ifdef CONFIG_NET_NS
21814 +       if (old_net)
21815 +               put_net(old_net);
21816 +#endif
21817 +out:
21818 +       return nsproxy;
21819 +}
21820 +
21821 +
21822 +/*
21823 + *     merge two nsproxy structs into a new one.
21824 + *     will hold a reference on the result.
21825 + */
21826 +
21827 +static inline
21828 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
21829 +       struct nsproxy *proxy, unsigned long mask)
21830 +{
21831 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
21832 +
21833 +       if (!proxy)
21834 +               return NULL;
21835 +
21836 +       if (mask) {
21837 +               /* vs_mix_nsproxy returns with reference */
21838 +               return vs_mix_nsproxy(old ? old : &null_proxy,
21839 +                       proxy, mask);
21840 +       }
21841 +       get_nsproxy(proxy);
21842 +       return proxy;
21843 +}
21844 +
21845 +
21846 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21847 +{
21848 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
21849 +       struct fs_struct *fs_cur, *fs = NULL;
21850 +       struct _vx_space *space;
21851 +       int ret, kill = 0;
21852 +
21853 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
21854 +               vxi, vxi->vx_id, mask, index);
21855 +
21856 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
21857 +               return -EACCES;
21858 +
21859 +       if (index >= VX_SPACES)
21860 +               return -EINVAL;
21861 +
21862 +       space = &vxi->space[index];
21863 +
21864 +       if (!mask)
21865 +               mask = space->vx_nsmask;
21866 +
21867 +       if ((mask & space->vx_nsmask) != mask)
21868 +               return -EINVAL;
21869 +
21870 +       if (mask & CLONE_FS) {
21871 +               fs = copy_fs_struct(space->vx_fs);
21872 +               if (!fs)
21873 +                       return -ENOMEM;
21874 +       }
21875 +       proxy = space->vx_nsproxy;
21876 +
21877 +       vxdprintk(VXD_CBIT(space, 9),
21878 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
21879 +               vxi, vxi->vx_id, mask, index, proxy, fs);
21880 +
21881 +       task_lock(current);
21882 +       fs_cur = current->fs;
21883 +
21884 +       if (mask & CLONE_FS) {
21885 +               spin_lock(&fs_cur->lock);
21886 +               current->fs = fs;
21887 +               kill = !--fs_cur->users;
21888 +               spin_unlock(&fs_cur->lock);
21889 +       }
21890 +
21891 +       proxy_cur = current->nsproxy;
21892 +       get_nsproxy(proxy_cur);
21893 +       task_unlock(current);
21894 +
21895 +       if (kill)
21896 +               free_fs_struct(fs_cur);
21897 +
21898 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
21899 +       if (IS_ERR(proxy_new)) {
21900 +               ret = PTR_ERR(proxy_new);
21901 +               goto out_put;
21902 +       }
21903 +
21904 +       proxy_new = xchg(&current->nsproxy, proxy_new);
21905 +
21906 +       if (mask & CLONE_NEWUSER) {
21907 +               struct cred *cred;
21908 +
21909 +               vxdprintk(VXD_CBIT(space, 10),
21910 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
21911 +                       vxi, vxi->vx_id, space->vx_cred,
21912 +                       current->real_cred, current->cred);
21913 +
21914 +               if (space->vx_cred) {
21915 +                       cred = __prepare_creds(space->vx_cred);
21916 +                       if (cred)
21917 +                               commit_creds(cred);
21918 +               }
21919 +       }
21920 +
21921 +       ret = 0;
21922 +
21923 +       if (proxy_new)
21924 +               put_nsproxy(proxy_new);
21925 +out_put:
21926 +       if (proxy_cur)
21927 +               put_nsproxy(proxy_cur);
21928 +       return ret;
21929 +}
21930 +
21931 +
21932 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21933 +{
21934 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
21935 +       struct fs_struct *fs_vxi, *fs = NULL;
21936 +       struct _vx_space *space;
21937 +       int ret, kill = 0;
21938 +
21939 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
21940 +               vxi, vxi->vx_id, mask, index);
21941 +
21942 +       if ((mask & space_mask.mask) != mask)
21943 +               return -EINVAL;
21944 +
21945 +       if (index >= VX_SPACES)
21946 +               return -EINVAL;
21947 +
21948 +       space = &vxi->space[index];
21949 +
21950 +       proxy_vxi = space->vx_nsproxy;
21951 +       fs_vxi = space->vx_fs;
21952 +
21953 +       if (mask & CLONE_FS) {
21954 +               fs = copy_fs_struct(current->fs);
21955 +               if (!fs)
21956 +                       return -ENOMEM;
21957 +       }
21958 +
21959 +       task_lock(current);
21960 +
21961 +       if (mask & CLONE_FS) {
21962 +               spin_lock(&fs_vxi->lock);
21963 +               space->vx_fs = fs;
21964 +               kill = !--fs_vxi->users;
21965 +               spin_unlock(&fs_vxi->lock);
21966 +       }
21967 +
21968 +       proxy_cur = current->nsproxy;
21969 +       get_nsproxy(proxy_cur);
21970 +       task_unlock(current);
21971 +
21972 +       if (kill)
21973 +               free_fs_struct(fs_vxi);
21974 +
21975 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
21976 +       if (IS_ERR(proxy_new)) {
21977 +               ret = PTR_ERR(proxy_new);
21978 +               goto out_put;
21979 +       }
21980 +
21981 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
21982 +       space->vx_nsmask |= mask;
21983 +
21984 +       if (mask & CLONE_NEWUSER) {
21985 +               struct cred *cred;
21986 +
21987 +               vxdprintk(VXD_CBIT(space, 10),
21988 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
21989 +                       vxi, vxi->vx_id, space->vx_cred,
21990 +                       current->real_cred, current->cred);
21991 +
21992 +               cred = prepare_creds();
21993 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
21994 +               if (cred)
21995 +                       abort_creds(cred);
21996 +       }
21997 +
21998 +       ret = 0;
21999 +
22000 +       if (proxy_new)
22001 +               put_nsproxy(proxy_new);
22002 +out_put:
22003 +       if (proxy_cur)
22004 +               put_nsproxy(proxy_cur);
22005 +       return ret;
22006 +}
22007 +
22008 +
22009 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22010 +{
22011 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22012 +
22013 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22014 +               return -EFAULT;
22015 +
22016 +       return vx_enter_space(vxi, vc_data.mask, 0);
22017 +}
22018 +
22019 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22020 +{
22021 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22022 +
22023 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22024 +               return -EFAULT;
22025 +
22026 +       if (vc_data.index >= VX_SPACES)
22027 +               return -EINVAL;
22028 +
22029 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22030 +}
22031 +
22032 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22033 +{
22034 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22035 +
22036 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22037 +               return -EFAULT;
22038 +
22039 +       return vx_set_space(vxi, vc_data.mask, 0);
22040 +}
22041 +
22042 +int vc_set_space(struct vx_info *vxi, void __user *data)
22043 +{
22044 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22045 +
22046 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22047 +               return -EFAULT;
22048 +
22049 +       if (vc_data.index >= VX_SPACES)
22050 +               return -EINVAL;
22051 +
22052 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22053 +}
22054 +
22055 +int vc_get_space_mask(void __user *data, int type)
22056 +{
22057 +       const struct vcmd_space_mask_v1 *mask;
22058 +
22059 +       if (type == 0)
22060 +               mask = &space_mask_v0;
22061 +       else if (type == 1)
22062 +               mask = &space_mask;
22063 +       else
22064 +               mask = &default_space_mask;
22065 +
22066 +       vxdprintk(VXD_CBIT(space, 10),
22067 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22068 +
22069 +       if (copy_to_user(data, mask, sizeof(*mask)))
22070 +               return -EFAULT;
22071 +       return 0;
22072 +}
22073 +
22074 diff -NurpP --minimal linux-3.13.10/kernel/vserver/switch.c linux-3.13.10-vs2.3.6.11/kernel/vserver/switch.c
22075 --- linux-3.13.10/kernel/vserver/switch.c       1970-01-01 00:00:00.000000000 +0000
22076 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/switch.c    2014-01-31 20:38:04.000000000 +0000
22077 @@ -0,0 +1,556 @@
22078 +/*
22079 + *  linux/kernel/vserver/switch.c
22080 + *
22081 + *  Virtual Server: Syscall Switch
22082 + *
22083 + *  Copyright (C) 2003-2011  Herbert Pötzl
22084 + *
22085 + *  V0.01  syscall switch
22086 + *  V0.02  added signal to context
22087 + *  V0.03  added rlimit functions
22088 + *  V0.04  added iattr, task/xid functions
22089 + *  V0.05  added debug/history stuff
22090 + *  V0.06  added compat32 layer
22091 + *  V0.07  vcmd args and perms
22092 + *  V0.08  added status commands
22093 + *  V0.09  added tag commands
22094 + *  V0.10  added oom bias
22095 + *  V0.11  added device commands
22096 + *  V0.12  added warn mask
22097 + *
22098 + */
22099 +
22100 +#include <linux/vs_context.h>
22101 +#include <linux/vs_network.h>
22102 +#include <linux/vserver/switch.h>
22103 +
22104 +#include "vci_config.h"
22105 +
22106 +
22107 +static inline
22108 +int vc_get_version(uint32_t id)
22109 +{
22110 +       return VCI_VERSION;
22111 +}
22112 +
22113 +static inline
22114 +int vc_get_vci(uint32_t id)
22115 +{
22116 +       return vci_kernel_config();
22117 +}
22118 +
22119 +#include <linux/vserver/context_cmd.h>
22120 +#include <linux/vserver/cvirt_cmd.h>
22121 +#include <linux/vserver/cacct_cmd.h>
22122 +#include <linux/vserver/limit_cmd.h>
22123 +#include <linux/vserver/network_cmd.h>
22124 +#include <linux/vserver/sched_cmd.h>
22125 +#include <linux/vserver/debug_cmd.h>
22126 +#include <linux/vserver/inode_cmd.h>
22127 +#include <linux/vserver/dlimit_cmd.h>
22128 +#include <linux/vserver/signal_cmd.h>
22129 +#include <linux/vserver/space_cmd.h>
22130 +#include <linux/vserver/tag_cmd.h>
22131 +#include <linux/vserver/device_cmd.h>
22132 +
22133 +#include <linux/vserver/inode.h>
22134 +#include <linux/vserver/dlimit.h>
22135 +
22136 +
22137 +#ifdef CONFIG_COMPAT
22138 +#define __COMPAT(name, id, data, compat)       \
22139 +       (compat) ? name ## _x32(id, data) : name(id, data)
22140 +#define __COMPAT_NO_ID(name, data, compat)     \
22141 +       (compat) ? name ## _x32(data) : name(data)
22142 +#else
22143 +#define __COMPAT(name, id, data, compat)       \
22144 +       name(id, data)
22145 +#define __COMPAT_NO_ID(name, data, compat)     \
22146 +       name(data)
22147 +#endif
22148 +
22149 +
22150 +static inline
22151 +long do_vcmd(uint32_t cmd, uint32_t id,
22152 +       struct vx_info *vxi, struct nx_info *nxi,
22153 +       void __user *data, int compat)
22154 +{
22155 +       switch (cmd) {
22156 +
22157 +       case VCMD_get_version:
22158 +               return vc_get_version(id);
22159 +       case VCMD_get_vci:
22160 +               return vc_get_vci(id);
22161 +
22162 +       case VCMD_task_xid:
22163 +               return vc_task_xid(id);
22164 +       case VCMD_vx_info:
22165 +               return vc_vx_info(vxi, data);
22166 +
22167 +       case VCMD_task_nid:
22168 +               return vc_task_nid(id);
22169 +       case VCMD_nx_info:
22170 +               return vc_nx_info(nxi, data);
22171 +
22172 +       case VCMD_task_tag:
22173 +               return vc_task_tag(id);
22174 +
22175 +       case VCMD_set_space_v1:
22176 +               return vc_set_space_v1(vxi, data);
22177 +       /* this is version 2 */
22178 +       case VCMD_set_space:
22179 +               return vc_set_space(vxi, data);
22180 +
22181 +       case VCMD_get_space_mask_v0:
22182 +               return vc_get_space_mask(data, 0);
22183 +       /* this is version 1 */
22184 +       case VCMD_get_space_mask:
22185 +               return vc_get_space_mask(data, 1);
22186 +
22187 +       case VCMD_get_space_default:
22188 +               return vc_get_space_mask(data, -1);
22189 +
22190 +       case VCMD_set_umask:
22191 +               return vc_set_umask(vxi, data);
22192 +
22193 +       case VCMD_get_umask:
22194 +               return vc_get_umask(vxi, data);
22195 +
22196 +       case VCMD_set_wmask:
22197 +               return vc_set_wmask(vxi, data);
22198 +
22199 +       case VCMD_get_wmask:
22200 +               return vc_get_wmask(vxi, data);
22201 +#ifdef CONFIG_IA32_EMULATION
22202 +       case VCMD_get_rlimit:
22203 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22204 +       case VCMD_set_rlimit:
22205 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22206 +#else
22207 +       case VCMD_get_rlimit:
22208 +               return vc_get_rlimit(vxi, data);
22209 +       case VCMD_set_rlimit:
22210 +               return vc_set_rlimit(vxi, data);
22211 +#endif
22212 +       case VCMD_get_rlimit_mask:
22213 +               return vc_get_rlimit_mask(id, data);
22214 +       case VCMD_reset_hits:
22215 +               return vc_reset_hits(vxi, data);
22216 +       case VCMD_reset_minmax:
22217 +               return vc_reset_minmax(vxi, data);
22218 +
22219 +       case VCMD_get_vhi_name:
22220 +               return vc_get_vhi_name(vxi, data);
22221 +       case VCMD_set_vhi_name:
22222 +               return vc_set_vhi_name(vxi, data);
22223 +
22224 +       case VCMD_ctx_stat:
22225 +               return vc_ctx_stat(vxi, data);
22226 +       case VCMD_virt_stat:
22227 +               return vc_virt_stat(vxi, data);
22228 +       case VCMD_sock_stat:
22229 +               return vc_sock_stat(vxi, data);
22230 +       case VCMD_rlimit_stat:
22231 +               return vc_rlimit_stat(vxi, data);
22232 +
22233 +       case VCMD_set_cflags:
22234 +               return vc_set_cflags(vxi, data);
22235 +       case VCMD_get_cflags:
22236 +               return vc_get_cflags(vxi, data);
22237 +
22238 +       /* this is version 1 */
22239 +       case VCMD_set_ccaps:
22240 +               return vc_set_ccaps(vxi, data);
22241 +       /* this is version 1 */
22242 +       case VCMD_get_ccaps:
22243 +               return vc_get_ccaps(vxi, data);
22244 +       case VCMD_set_bcaps:
22245 +               return vc_set_bcaps(vxi, data);
22246 +       case VCMD_get_bcaps:
22247 +               return vc_get_bcaps(vxi, data);
22248 +
22249 +       case VCMD_set_badness:
22250 +               return vc_set_badness(vxi, data);
22251 +       case VCMD_get_badness:
22252 +               return vc_get_badness(vxi, data);
22253 +
22254 +       case VCMD_set_nflags:
22255 +               return vc_set_nflags(nxi, data);
22256 +       case VCMD_get_nflags:
22257 +               return vc_get_nflags(nxi, data);
22258 +
22259 +       case VCMD_set_ncaps:
22260 +               return vc_set_ncaps(nxi, data);
22261 +       case VCMD_get_ncaps:
22262 +               return vc_get_ncaps(nxi, data);
22263 +
22264 +       case VCMD_set_prio_bias:
22265 +               return vc_set_prio_bias(vxi, data);
22266 +       case VCMD_get_prio_bias:
22267 +               return vc_get_prio_bias(vxi, data);
22268 +       case VCMD_add_dlimit:
22269 +               return __COMPAT(vc_add_dlimit, id, data, compat);
22270 +       case VCMD_rem_dlimit:
22271 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
22272 +       case VCMD_set_dlimit:
22273 +               return __COMPAT(vc_set_dlimit, id, data, compat);
22274 +       case VCMD_get_dlimit:
22275 +               return __COMPAT(vc_get_dlimit, id, data, compat);
22276 +
22277 +       case VCMD_ctx_kill:
22278 +               return vc_ctx_kill(vxi, data);
22279 +
22280 +       case VCMD_wait_exit:
22281 +               return vc_wait_exit(vxi, data);
22282 +
22283 +       case VCMD_get_iattr:
22284 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22285 +       case VCMD_set_iattr:
22286 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22287 +
22288 +       case VCMD_fget_iattr:
22289 +               return vc_fget_iattr(id, data);
22290 +       case VCMD_fset_iattr:
22291 +               return vc_fset_iattr(id, data);
22292 +
22293 +       case VCMD_enter_space_v0:
22294 +               return vc_enter_space_v1(vxi, NULL);
22295 +       case VCMD_enter_space_v1:
22296 +               return vc_enter_space_v1(vxi, data);
22297 +       /* this is version 2 */
22298 +       case VCMD_enter_space:
22299 +               return vc_enter_space(vxi, data);
22300 +
22301 +       case VCMD_ctx_create_v0:
22302 +               return vc_ctx_create(id, NULL);
22303 +       case VCMD_ctx_create:
22304 +               return vc_ctx_create(id, data);
22305 +       case VCMD_ctx_migrate_v0:
22306 +               return vc_ctx_migrate(vxi, NULL);
22307 +       case VCMD_ctx_migrate:
22308 +               return vc_ctx_migrate(vxi, data);
22309 +
22310 +       case VCMD_net_create_v0:
22311 +               return vc_net_create(id, NULL);
22312 +       case VCMD_net_create:
22313 +               return vc_net_create(id, data);
22314 +       case VCMD_net_migrate:
22315 +               return vc_net_migrate(nxi, data);
22316 +
22317 +       case VCMD_tag_migrate:
22318 +               return vc_tag_migrate(id);
22319 +
22320 +       case VCMD_net_add:
22321 +               return vc_net_add(nxi, data);
22322 +       case VCMD_net_remove:
22323 +               return vc_net_remove(nxi, data);
22324 +
22325 +       case VCMD_net_add_ipv4_v1:
22326 +               return vc_net_add_ipv4_v1(nxi, data);
22327 +       /* this is version 2 */
22328 +       case VCMD_net_add_ipv4:
22329 +               return vc_net_add_ipv4(nxi, data);
22330 +
22331 +       case VCMD_net_rem_ipv4_v1:
22332 +               return vc_net_rem_ipv4_v1(nxi, data);
22333 +       /* this is version 2 */
22334 +       case VCMD_net_rem_ipv4:
22335 +               return vc_net_rem_ipv4(nxi, data);
22336 +#ifdef CONFIG_IPV6
22337 +       case VCMD_net_add_ipv6:
22338 +               return vc_net_add_ipv6(nxi, data);
22339 +       case VCMD_net_remove_ipv6:
22340 +               return vc_net_remove_ipv6(nxi, data);
22341 +#endif
22342 +/*     case VCMD_add_match_ipv4:
22343 +               return vc_add_match_ipv4(nxi, data);
22344 +       case VCMD_get_match_ipv4:
22345 +               return vc_get_match_ipv4(nxi, data);
22346 +#ifdef CONFIG_IPV6
22347 +       case VCMD_add_match_ipv6:
22348 +               return vc_add_match_ipv6(nxi, data);
22349 +       case VCMD_get_match_ipv6:
22350 +               return vc_get_match_ipv6(nxi, data);
22351 +#endif */
22352 +
22353 +#ifdef CONFIG_VSERVER_DEVICE
22354 +       case VCMD_set_mapping:
22355 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
22356 +       case VCMD_unset_mapping:
22357 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
22358 +#endif
22359 +#ifdef CONFIG_VSERVER_HISTORY
22360 +       case VCMD_dump_history:
22361 +               return vc_dump_history(id);
22362 +       case VCMD_read_history:
22363 +               return __COMPAT(vc_read_history, id, data, compat);
22364 +#endif
22365 +       default:
22366 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
22367 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
22368 +       }
22369 +       return -ENOSYS;
22370 +}
22371 +
22372 +
22373 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
22374 +       case VCMD_ ## vcmd: perm = _perm;               \
22375 +               args = _args; flags = _flags; break
22376 +
22377 +
22378 +#define VCA_NONE       0x00
22379 +#define VCA_VXI                0x01
22380 +#define VCA_NXI                0x02
22381 +
22382 +#define VCF_NONE       0x00
22383 +#define VCF_INFO       0x01
22384 +#define VCF_ADMIN      0x02
22385 +#define VCF_ARES       0x06    /* includes admin */
22386 +#define VCF_SETUP      0x08
22387 +
22388 +#define VCF_ZIDOK      0x10    /* zero id okay */
22389 +
22390 +
22391 +static inline
22392 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
22393 +{
22394 +       long ret;
22395 +       int permit = -1, state = 0;
22396 +       int perm = -1, args = 0, flags = 0;
22397 +       struct vx_info *vxi = NULL;
22398 +       struct nx_info *nxi = NULL;
22399 +
22400 +       switch (cmd) {
22401 +       /* unpriviledged commands */
22402 +       __VCMD(get_version,      0, VCA_NONE,   0);
22403 +       __VCMD(get_vci,          0, VCA_NONE,   0);
22404 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
22405 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
22406 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
22407 +       __VCMD(get_space_default,0, VCA_NONE,   0);
22408 +
22409 +       /* info commands */
22410 +       __VCMD(task_xid,         2, VCA_NONE,   0);
22411 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
22412 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
22413 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
22414 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
22415 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
22416 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
22417 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
22418 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
22419 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
22420 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
22421 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
22422 +
22423 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
22424 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
22425 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
22426 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
22427 +
22428 +       __VCMD(task_nid,         2, VCA_NONE,   0);
22429 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
22430 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
22431 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
22432 +
22433 +       __VCMD(task_tag,         2, VCA_NONE,   0);
22434 +
22435 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
22436 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
22437 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
22438 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
22439 +
22440 +       /* lower admin commands */
22441 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
22442 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
22443 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
22444 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
22445 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
22446 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
22447 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
22448 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
22449 +
22450 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
22451 +       __VCMD(net_create,       5, VCA_NONE,   0);
22452 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
22453 +
22454 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
22455 +
22456 +       /* higher admin commands */
22457 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
22458 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22459 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22460 +
22461 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22462 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22463 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22464 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22465 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22466 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22467 +
22468 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22469 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22470 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22471 +
22472 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22473 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22474 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22475 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22476 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22477 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22478 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22479 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22480 +#ifdef CONFIG_IPV6
22481 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22482 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22483 +#endif
22484 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
22485 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
22486 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
22487 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
22488 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
22489 +
22490 +#ifdef CONFIG_VSERVER_DEVICE
22491 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22492 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22493 +#endif
22494 +       /* debug level admin commands */
22495 +#ifdef CONFIG_VSERVER_HISTORY
22496 +       __VCMD(dump_history,     9, VCA_NONE,   0);
22497 +       __VCMD(read_history,     9, VCA_NONE,   0);
22498 +#endif
22499 +
22500 +       default:
22501 +               perm = -1;
22502 +       }
22503 +
22504 +       vxdprintk(VXD_CBIT(switch, 0),
22505 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
22506 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22507 +               VC_VERSION(cmd), id, data, compat,
22508 +               perm, args, flags);
22509 +
22510 +       ret = -ENOSYS;
22511 +       if (perm < 0)
22512 +               goto out;
22513 +
22514 +       state = 1;
22515 +       if (!capable(CAP_CONTEXT))
22516 +               goto out;
22517 +
22518 +       state = 2;
22519 +       /* moved here from the individual commands */
22520 +       ret = -EPERM;
22521 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
22522 +               goto out;
22523 +
22524 +       state = 3;
22525 +       /* vcmd involves resource management  */
22526 +       ret = -EPERM;
22527 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
22528 +               goto out;
22529 +
22530 +       state = 4;
22531 +       /* various legacy exceptions */
22532 +       switch (cmd) {
22533 +       /* will go away when spectator is a cap */
22534 +       case VCMD_ctx_migrate_v0:
22535 +       case VCMD_ctx_migrate:
22536 +               if (id == 1) {
22537 +                       current->xid = 1;
22538 +                       ret = 1;
22539 +                       goto out;
22540 +               }
22541 +               break;
22542 +
22543 +       /* will go away when spectator is a cap */
22544 +       case VCMD_net_migrate:
22545 +               if (id == 1) {
22546 +                       current->nid = 1;
22547 +                       ret = 1;
22548 +                       goto out;
22549 +               }
22550 +               break;
22551 +       }
22552 +
22553 +       /* vcmds are fine by default */
22554 +       permit = 1;
22555 +
22556 +       /* admin type vcmds require admin ... */
22557 +       if (flags & VCF_ADMIN)
22558 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
22559 +
22560 +       /* ... but setup type vcmds override that */
22561 +       if (!permit && (flags & VCF_SETUP))
22562 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
22563 +
22564 +       state = 5;
22565 +       ret = -EPERM;
22566 +       if (!permit)
22567 +               goto out;
22568 +
22569 +       state = 6;
22570 +       if (!id && (flags & VCF_ZIDOK))
22571 +               goto skip_id;
22572 +
22573 +       ret = -ESRCH;
22574 +       if (args & VCA_VXI) {
22575 +               vxi = lookup_vx_info(id);
22576 +               if (!vxi)
22577 +                       goto out;
22578 +
22579 +               if ((flags & VCF_ADMIN) &&
22580 +                       /* special case kill for shutdown */
22581 +                       (cmd != VCMD_ctx_kill) &&
22582 +                       /* can context be administrated? */
22583 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
22584 +                       ret = -EACCES;
22585 +                       goto out_vxi;
22586 +               }
22587 +       }
22588 +       state = 7;
22589 +       if (args & VCA_NXI) {
22590 +               nxi = lookup_nx_info(id);
22591 +               if (!nxi)
22592 +                       goto out_vxi;
22593 +
22594 +               if ((flags & VCF_ADMIN) &&
22595 +                       /* can context be administrated? */
22596 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
22597 +                       ret = -EACCES;
22598 +                       goto out_nxi;
22599 +               }
22600 +       }
22601 +skip_id:
22602 +       state = 8;
22603 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
22604 +
22605 +out_nxi:
22606 +       if ((args & VCA_NXI) && nxi)
22607 +               put_nx_info(nxi);
22608 +out_vxi:
22609 +       if ((args & VCA_VXI) && vxi)
22610 +               put_vx_info(vxi);
22611 +out:
22612 +       vxdprintk(VXD_CBIT(switch, 1),
22613 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
22614 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22615 +               VC_VERSION(cmd), ret, ret, state, permit);
22616 +       return ret;
22617 +}
22618 +
22619 +asmlinkage long
22620 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
22621 +{
22622 +       return do_vserver(cmd, id, data, 0);
22623 +}
22624 +
22625 +#ifdef CONFIG_COMPAT
22626 +
22627 +asmlinkage long
22628 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
22629 +{
22630 +       return do_vserver(cmd, id, data, 1);
22631 +}
22632 +
22633 +#endif /* CONFIG_COMPAT */
22634 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sysctl.c linux-3.13.10-vs2.3.6.11/kernel/vserver/sysctl.c
22635 --- linux-3.13.10/kernel/vserver/sysctl.c       1970-01-01 00:00:00.000000000 +0000
22636 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sysctl.c    2014-01-31 20:38:04.000000000 +0000
22637 @@ -0,0 +1,247 @@
22638 +/*
22639 + *  kernel/vserver/sysctl.c
22640 + *
22641 + *  Virtual Context Support
22642 + *
22643 + *  Copyright (C) 2004-2007  Herbert Pötzl
22644 + *
22645 + *  V0.01  basic structure
22646 + *
22647 + */
22648 +
22649 +#include <linux/module.h>
22650 +#include <linux/ctype.h>
22651 +#include <linux/sysctl.h>
22652 +#include <linux/parser.h>
22653 +#include <asm/uaccess.h>
22654 +
22655 +enum {
22656 +       CTL_DEBUG_ERROR         = 0,
22657 +       CTL_DEBUG_SWITCH        = 1,
22658 +       CTL_DEBUG_XID,
22659 +       CTL_DEBUG_NID,
22660 +       CTL_DEBUG_TAG,
22661 +       CTL_DEBUG_NET,
22662 +       CTL_DEBUG_LIMIT,
22663 +       CTL_DEBUG_CRES,
22664 +       CTL_DEBUG_DLIM,
22665 +       CTL_DEBUG_QUOTA,
22666 +       CTL_DEBUG_CVIRT,
22667 +       CTL_DEBUG_SPACE,
22668 +       CTL_DEBUG_PERM,
22669 +       CTL_DEBUG_MISC,
22670 +};
22671 +
22672 +
22673 +unsigned int vs_debug_switch   = 0;
22674 +unsigned int vs_debug_xid      = 0;
22675 +unsigned int vs_debug_nid      = 0;
22676 +unsigned int vs_debug_tag      = 0;
22677 +unsigned int vs_debug_net      = 0;
22678 +unsigned int vs_debug_limit    = 0;
22679 +unsigned int vs_debug_cres     = 0;
22680 +unsigned int vs_debug_dlim     = 0;
22681 +unsigned int vs_debug_quota    = 0;
22682 +unsigned int vs_debug_cvirt    = 0;
22683 +unsigned int vs_debug_space    = 0;
22684 +unsigned int vs_debug_perm     = 0;
22685 +unsigned int vs_debug_misc     = 0;
22686 +
22687 +
22688 +static struct ctl_table_header *vserver_table_header;
22689 +static ctl_table vserver_root_table[];
22690 +
22691 +
22692 +void vserver_register_sysctl(void)
22693 +{
22694 +       if (!vserver_table_header) {
22695 +               vserver_table_header = register_sysctl_table(vserver_root_table);
22696 +       }
22697 +
22698 +}
22699 +
22700 +void vserver_unregister_sysctl(void)
22701 +{
22702 +       if (vserver_table_header) {
22703 +               unregister_sysctl_table(vserver_table_header);
22704 +               vserver_table_header = NULL;
22705 +       }
22706 +}
22707 +
22708 +
22709 +static int proc_dodebug(ctl_table *table, int write,
22710 +       void __user *buffer, size_t *lenp, loff_t *ppos)
22711 +{
22712 +       char            tmpbuf[20], *p, c;
22713 +       unsigned int    value;
22714 +       size_t          left, len;
22715 +
22716 +       if ((*ppos && !write) || !*lenp) {
22717 +               *lenp = 0;
22718 +               return 0;
22719 +       }
22720 +
22721 +       left = *lenp;
22722 +
22723 +       if (write) {
22724 +               if (!access_ok(VERIFY_READ, buffer, left))
22725 +                       return -EFAULT;
22726 +               p = (char *)buffer;
22727 +               while (left && __get_user(c, p) >= 0 && isspace(c))
22728 +                       left--, p++;
22729 +               if (!left)
22730 +                       goto done;
22731 +
22732 +               if (left > sizeof(tmpbuf) - 1)
22733 +                       return -EINVAL;
22734 +               if (copy_from_user(tmpbuf, p, left))
22735 +                       return -EFAULT;
22736 +               tmpbuf[left] = '\0';
22737 +
22738 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
22739 +                       value = 10 * value + (*p - '0');
22740 +               if (*p && !isspace(*p))
22741 +                       return -EINVAL;
22742 +               while (left && isspace(*p))
22743 +                       left--, p++;
22744 +               *(unsigned int *)table->data = value;
22745 +       } else {
22746 +               if (!access_ok(VERIFY_WRITE, buffer, left))
22747 +                       return -EFAULT;
22748 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
22749 +               if (len > left)
22750 +                       len = left;
22751 +               if (__copy_to_user(buffer, tmpbuf, len))
22752 +                       return -EFAULT;
22753 +               if ((left -= len) > 0) {
22754 +                       if (put_user('\n', (char *)buffer + len))
22755 +                               return -EFAULT;
22756 +                       left--;
22757 +               }
22758 +       }
22759 +
22760 +done:
22761 +       *lenp -= left;
22762 +       *ppos += *lenp;
22763 +       return 0;
22764 +}
22765 +
22766 +static int zero;
22767 +
22768 +#define        CTL_ENTRY(ctl, name)                            \
22769 +       {                                               \
22770 +               .procname       = #name,                \
22771 +               .data           = &vs_ ## name,         \
22772 +               .maxlen         = sizeof(int),          \
22773 +               .mode           = 0644,                 \
22774 +               .proc_handler   = &proc_dodebug,        \
22775 +               .extra1         = &zero,                \
22776 +               .extra2         = &zero,                \
22777 +       }
22778 +
22779 +static ctl_table vserver_debug_table[] = {
22780 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
22781 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
22782 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
22783 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
22784 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
22785 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
22786 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
22787 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
22788 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
22789 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
22790 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
22791 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
22792 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
22793 +       { 0 }
22794 +};
22795 +
22796 +static ctl_table vserver_root_table[] = {
22797 +       {
22798 +               .procname       = "vserver",
22799 +               .mode           = 0555,
22800 +               .child          = vserver_debug_table
22801 +       },
22802 +       { 0 }
22803 +};
22804 +
22805 +
22806 +static match_table_t tokens = {
22807 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
22808 +       { CTL_DEBUG_XID,        "xid=%x"        },
22809 +       { CTL_DEBUG_NID,        "nid=%x"        },
22810 +       { CTL_DEBUG_TAG,        "tag=%x"        },
22811 +       { CTL_DEBUG_NET,        "net=%x"        },
22812 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
22813 +       { CTL_DEBUG_CRES,       "cres=%x"       },
22814 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
22815 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
22816 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
22817 +       { CTL_DEBUG_SPACE,      "space=%x"      },
22818 +       { CTL_DEBUG_PERM,       "perm=%x"       },
22819 +       { CTL_DEBUG_MISC,       "misc=%x"       },
22820 +       { CTL_DEBUG_ERROR,      NULL            }
22821 +};
22822 +
22823 +#define        HANDLE_CASE(id, name, val)                              \
22824 +       case CTL_DEBUG_ ## id:                                  \
22825 +               vs_debug_ ## name = val;                        \
22826 +               printk("vs_debug_" #name "=0x%x\n", val);       \
22827 +               break
22828 +
22829 +
22830 +static int __init vs_debug_setup(char *str)
22831 +{
22832 +       char *p;
22833 +       int token;
22834 +
22835 +       printk("vs_debug_setup(%s)\n", str);
22836 +       while ((p = strsep(&str, ",")) != NULL) {
22837 +               substring_t args[MAX_OPT_ARGS];
22838 +               unsigned int value;
22839 +
22840 +               if (!*p)
22841 +                       continue;
22842 +
22843 +               token = match_token(p, tokens, args);
22844 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
22845 +
22846 +               switch (token) {
22847 +               HANDLE_CASE(SWITCH, switch, value);
22848 +               HANDLE_CASE(XID,    xid,    value);
22849 +               HANDLE_CASE(NID,    nid,    value);
22850 +               HANDLE_CASE(TAG,    tag,    value);
22851 +               HANDLE_CASE(NET,    net,    value);
22852 +               HANDLE_CASE(LIMIT,  limit,  value);
22853 +               HANDLE_CASE(CRES,   cres,   value);
22854 +               HANDLE_CASE(DLIM,   dlim,   value);
22855 +               HANDLE_CASE(QUOTA,  quota,  value);
22856 +               HANDLE_CASE(CVIRT,  cvirt,  value);
22857 +               HANDLE_CASE(SPACE,  space,  value);
22858 +               HANDLE_CASE(PERM,   perm,   value);
22859 +               HANDLE_CASE(MISC,   misc,   value);
22860 +               default:
22861 +                       return -EINVAL;
22862 +                       break;
22863 +               }
22864 +       }
22865 +       return 1;
22866 +}
22867 +
22868 +__setup("vsdebug=", vs_debug_setup);
22869 +
22870 +
22871 +
22872 +EXPORT_SYMBOL_GPL(vs_debug_switch);
22873 +EXPORT_SYMBOL_GPL(vs_debug_xid);
22874 +EXPORT_SYMBOL_GPL(vs_debug_nid);
22875 +EXPORT_SYMBOL_GPL(vs_debug_net);
22876 +EXPORT_SYMBOL_GPL(vs_debug_limit);
22877 +EXPORT_SYMBOL_GPL(vs_debug_cres);
22878 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
22879 +EXPORT_SYMBOL_GPL(vs_debug_quota);
22880 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
22881 +EXPORT_SYMBOL_GPL(vs_debug_space);
22882 +EXPORT_SYMBOL_GPL(vs_debug_perm);
22883 +EXPORT_SYMBOL_GPL(vs_debug_misc);
22884 +
22885 diff -NurpP --minimal linux-3.13.10/kernel/vserver/tag.c linux-3.13.10-vs2.3.6.11/kernel/vserver/tag.c
22886 --- linux-3.13.10/kernel/vserver/tag.c  1970-01-01 00:00:00.000000000 +0000
22887 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/tag.c       2014-01-31 20:38:04.000000000 +0000
22888 @@ -0,0 +1,63 @@
22889 +/*
22890 + *  linux/kernel/vserver/tag.c
22891 + *
22892 + *  Virtual Server: Shallow Tag Space
22893 + *
22894 + *  Copyright (C) 2007  Herbert Pötzl
22895 + *
22896 + *  V0.01  basic implementation
22897 + *
22898 + */
22899 +
22900 +#include <linux/sched.h>
22901 +#include <linux/vserver/debug.h>
22902 +#include <linux/vs_pid.h>
22903 +#include <linux/vs_tag.h>
22904 +
22905 +#include <linux/vserver/tag_cmd.h>
22906 +
22907 +
22908 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
22909 +{
22910 +       if (!p)
22911 +               BUG();
22912 +
22913 +       vxdprintk(VXD_CBIT(tag, 5),
22914 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
22915 +
22916 +       task_lock(p);
22917 +       p->tag = tag;
22918 +       task_unlock(p);
22919 +
22920 +       vxdprintk(VXD_CBIT(tag, 5),
22921 +               "moved task %p into [#%d]", p, tag);
22922 +       return 0;
22923 +}
22924 +
22925 +/* vserver syscall commands below here */
22926 +
22927 +/* taks xid and vx_info functions */
22928 +
22929 +
22930 +int vc_task_tag(uint32_t id)
22931 +{
22932 +       vtag_t tag;
22933 +
22934 +       if (id) {
22935 +               struct task_struct *tsk;
22936 +               rcu_read_lock();
22937 +               tsk = find_task_by_real_pid(id);
22938 +               tag = (tsk) ? tsk->tag : -ESRCH;
22939 +               rcu_read_unlock();
22940 +       } else
22941 +               tag = dx_current_tag();
22942 +       return tag;
22943 +}
22944 +
22945 +
22946 +int vc_tag_migrate(uint32_t tag)
22947 +{
22948 +       return dx_migrate_task(current, tag & 0xFFFF);
22949 +}
22950 +
22951 +
22952 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
22953 --- linux-3.13.10/kernel/vserver/vci_config.h   1970-01-01 00:00:00.000000000 +0000
22954 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/vci_config.h        2014-01-31 20:38:04.000000000 +0000
22955 @@ -0,0 +1,80 @@
22956 +
22957 +/*  interface version */
22958 +
22959 +#define VCI_VERSION            0x00020308
22960 +
22961 +
22962 +enum {
22963 +       VCI_KCBIT_NO_DYNAMIC = 0,
22964 +
22965 +       VCI_KCBIT_PROC_SECURE = 4,
22966 +       /* VCI_KCBIT_HARDCPU = 5, */
22967 +       /* VCI_KCBIT_IDLELIMIT = 6, */
22968 +       /* VCI_KCBIT_IDLETIME = 7, */
22969 +
22970 +       VCI_KCBIT_COWBL = 8,
22971 +       VCI_KCBIT_FULLCOWBL = 9,
22972 +       VCI_KCBIT_SPACES = 10,
22973 +       VCI_KCBIT_NETV2 = 11,
22974 +       VCI_KCBIT_MEMCG = 12,
22975 +       VCI_KCBIT_MEMCG_SWAP = 13,
22976 +
22977 +       VCI_KCBIT_DEBUG = 16,
22978 +       VCI_KCBIT_HISTORY = 20,
22979 +       VCI_KCBIT_TAGGED = 24,
22980 +       VCI_KCBIT_PPTAG = 28,
22981 +
22982 +       VCI_KCBIT_MORE = 31,
22983 +};
22984 +
22985 +
22986 +static inline uint32_t vci_kernel_config(void)
22987 +{
22988 +       return
22989 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
22990 +
22991 +       /* configured features */
22992 +#ifdef CONFIG_VSERVER_PROC_SECURE
22993 +       (1 << VCI_KCBIT_PROC_SECURE) |
22994 +#endif
22995 +#ifdef CONFIG_VSERVER_COWBL
22996 +       (1 << VCI_KCBIT_COWBL) |
22997 +       (1 << VCI_KCBIT_FULLCOWBL) |
22998 +#endif
22999 +       (1 << VCI_KCBIT_SPACES) |
23000 +       (1 << VCI_KCBIT_NETV2) |
23001 +#ifdef CONFIG_MEMCG
23002 +       (1 << VCI_KCBIT_MEMCG) |
23003 +#endif
23004 +#ifdef CONFIG_MEMCG_SWAP
23005 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
23006 +#endif
23007 +
23008 +       /* debug options */
23009 +#ifdef CONFIG_VSERVER_DEBUG
23010 +       (1 << VCI_KCBIT_DEBUG) |
23011 +#endif
23012 +#ifdef CONFIG_VSERVER_HISTORY
23013 +       (1 << VCI_KCBIT_HISTORY) |
23014 +#endif
23015 +
23016 +       /* inode context tagging */
23017 +#if    defined(CONFIG_TAGGING_NONE)
23018 +       (0 << VCI_KCBIT_TAGGED) |
23019 +#elif  defined(CONFIG_TAGGING_UID16)
23020 +       (1 << VCI_KCBIT_TAGGED) |
23021 +#elif  defined(CONFIG_TAGGING_GID16)
23022 +       (2 << VCI_KCBIT_TAGGED) |
23023 +#elif  defined(CONFIG_TAGGING_ID24)
23024 +       (3 << VCI_KCBIT_TAGGED) |
23025 +#elif  defined(CONFIG_TAGGING_INTERN)
23026 +       (4 << VCI_KCBIT_TAGGED) |
23027 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23028 +       (5 << VCI_KCBIT_TAGGED) |
23029 +#else
23030 +       (7 << VCI_KCBIT_TAGGED) |
23031 +#endif
23032 +       (1 << VCI_KCBIT_PPTAG) |
23033 +       0;
23034 +}
23035 +
23036 diff -NurpP --minimal linux-3.13.10/mm/memcontrol.c linux-3.13.10-vs2.3.6.11/mm/memcontrol.c
23037 --- linux-3.13.10/mm/memcontrol.c       2014-04-17 01:12:40.000000000 +0000
23038 +++ linux-3.13.10-vs2.3.6.11/mm/memcontrol.c    2014-04-17 01:17:11.000000000 +0000
23039 @@ -1056,6 +1056,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23040         return mem_cgroup_from_css(task_css(p, mem_cgroup_subsys_id));
23041  }
23042  
23043 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23044 +{
23045 +       return res_counter_read_u64(&mem->res, member);
23046 +}
23047 +
23048 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23049 +{
23050 +       return res_counter_read_u64(&mem->memsw, member);
23051 +}
23052 +
23053 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23054 +{
23055 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23056 +}
23057 +
23058 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23059 +{
23060 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23061 +}
23062 +
23063 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23064 +{
23065 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23066 +}
23067 +
23068  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23069  {
23070         struct mem_cgroup *memcg = NULL;
23071 diff -NurpP --minimal linux-3.13.10/mm/oom_kill.c linux-3.13.10-vs2.3.6.11/mm/oom_kill.c
23072 --- linux-3.13.10/mm/oom_kill.c 2014-04-17 01:12:40.000000000 +0000
23073 +++ linux-3.13.10-vs2.3.6.11/mm/oom_kill.c      2014-02-25 11:26:10.000000000 +0000
23074 @@ -35,6 +35,8 @@
23075  #include <linux/freezer.h>
23076  #include <linux/ftrace.h>
23077  #include <linux/ratelimit.h>
23078 +#include <linux/reboot.h>
23079 +#include <linux/vs_context.h>
23080  
23081  #define CREATE_TRACE_POINTS
23082  #include <trace/events/oom.h>
23083 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23084  static bool oom_unkillable_task(struct task_struct *p,
23085                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23086  {
23087 -       if (is_global_init(p))
23088 +       unsigned xid = vx_current_xid();
23089 +
23090 +       /* skip the init task, global and per guest */
23091 +       if (task_is_init(p))
23092                 return true;
23093         if (p->flags & PF_KTHREAD)
23094                 return true;
23095  
23096 +       /* skip other guest and host processes if oom in guest */
23097 +       if (xid && vx_task_xid(p) != xid)
23098 +               return true;
23099 +
23100         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23101         if (memcg && !task_in_mem_cgroup(p, memcg))
23102                 return true;
23103 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23104                 dump_header(p, gfp_mask, order, memcg, nodemask);
23105  
23106         task_lock(p);
23107 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23108 -               message, task_pid_nr(p), p->comm, points);
23109 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23110 +               message, task_pid_nr(p), p->xid, p->comm, points);
23111         task_unlock(p);
23112  
23113         /*
23114 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23115  
23116         /* mm cannot safely be dereferenced after task_unlock(victim) */
23117         mm = victim->mm;
23118 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23119 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23120 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23121 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23122                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23123                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23124         task_unlock(victim);
23125 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23126  }
23127  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23128  
23129 +long vs_oom_action(unsigned int);
23130 +
23131  /*
23132   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23133   * if a parallel OOM killing is already taking place that includes a zone in
23134 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23135         /* Found nothing?!?! Either we hang forever, or we panic. */
23136         if (!p) {
23137                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23138 -               panic("Out of memory and no killable processes...\n");
23139 +
23140 +               /* avoid panic for guest OOM */
23141 +               if (vx_current_xid())
23142 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23143 +               else
23144 +                       panic("Out of memory and no killable processes...\n");
23145         }
23146         if (p != (void *)-1UL) {
23147                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23148 diff -NurpP --minimal linux-3.13.10/mm/page_alloc.c linux-3.13.10-vs2.3.6.11/mm/page_alloc.c
23149 --- linux-3.13.10/mm/page_alloc.c       2014-04-17 01:12:40.000000000 +0000
23150 +++ linux-3.13.10-vs2.3.6.11/mm/page_alloc.c    2014-04-17 01:17:11.000000000 +0000
23151 @@ -61,6 +61,8 @@
23152  #include <linux/page-debug-flags.h>
23153  #include <linux/hugetlb.h>
23154  #include <linux/sched/rt.h>
23155 +#include <linux/vs_base.h>
23156 +#include <linux/vs_limit.h>
23157  
23158  #include <asm/sections.h>
23159  #include <asm/tlbflush.h>
23160 @@ -2983,6 +2985,9 @@ void si_meminfo(struct sysinfo *val)
23161         val->totalhigh = totalhigh_pages;
23162         val->freehigh = nr_free_highpages();
23163         val->mem_unit = PAGE_SIZE;
23164 +
23165 +       if (vx_flags(VXF_VIRT_MEM, 0))
23166 +               vx_vsi_meminfo(val);
23167  }
23168  
23169  EXPORT_SYMBOL(si_meminfo);
23170 @@ -3007,6 +3012,9 @@ void si_meminfo_node(struct sysinfo *val
23171         val->freehigh = 0;
23172  #endif
23173         val->mem_unit = PAGE_SIZE;
23174 +
23175 +       if (vx_flags(VXF_VIRT_MEM, 0))
23176 +               vx_vsi_meminfo(val);
23177  }
23178  #endif
23179  
23180 diff -NurpP --minimal linux-3.13.10/mm/pgtable-generic.c linux-3.13.10-vs2.3.6.11/mm/pgtable-generic.c
23181 --- linux-3.13.10/mm/pgtable-generic.c  2014-01-22 20:39:14.000000000 +0000
23182 +++ linux-3.13.10-vs2.3.6.11/mm/pgtable-generic.c       2014-01-31 20:38:04.000000000 +0000
23183 @@ -6,6 +6,8 @@
23184   *  Copyright (C) 2010  Linus Torvalds
23185   */
23186  
23187 +#include <linux/mm.h>
23188 +
23189  #include <linux/pagemap.h>
23190  #include <asm/tlb.h>
23191  #include <asm-generic/pgtable.h>
23192 diff -NurpP --minimal linux-3.13.10/mm/shmem.c linux-3.13.10-vs2.3.6.11/mm/shmem.c
23193 --- linux-3.13.10/mm/shmem.c    2014-01-22 20:39:14.000000000 +0000
23194 +++ linux-3.13.10-vs2.3.6.11/mm/shmem.c 2014-01-31 20:38:04.000000000 +0000
23195 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23196  {
23197         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23198  
23199 -       buf->f_type = TMPFS_MAGIC;
23200 +       buf->f_type = TMPFS_SUPER_MAGIC;
23201         buf->f_bsize = PAGE_CACHE_SIZE;
23202         buf->f_namelen = NAME_MAX;
23203         if (sbinfo->max_blocks) {
23204 @@ -2639,7 +2639,7 @@ int shmem_fill_super(struct super_block
23205         sb->s_maxbytes = MAX_LFS_FILESIZE;
23206         sb->s_blocksize = PAGE_CACHE_SIZE;
23207         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23208 -       sb->s_magic = TMPFS_MAGIC;
23209 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23210         sb->s_op = &shmem_ops;
23211         sb->s_time_gran = 1;
23212  #ifdef CONFIG_TMPFS_XATTR
23213 diff -NurpP --minimal linux-3.13.10/mm/slab.c linux-3.13.10-vs2.3.6.11/mm/slab.c
23214 --- linux-3.13.10/mm/slab.c     2014-01-22 20:39:14.000000000 +0000
23215 +++ linux-3.13.10-vs2.3.6.11/mm/slab.c  2014-01-31 20:38:04.000000000 +0000
23216 @@ -322,6 +322,8 @@ static void kmem_cache_node_init(struct
23217  #define STATS_INC_FREEMISS(x)  do { } while (0)
23218  #endif
23219  
23220 +#include "slab_vs.h"
23221 +
23222  #if DEBUG
23223  
23224  /*
23225 @@ -3240,6 +3242,7 @@ slab_alloc_node(struct kmem_cache *cache
23226         /* ___cache_alloc_node can fall back to other nodes */
23227         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23228    out:
23229 +       vx_slab_alloc(cachep, flags);
23230         local_irq_restore(save_flags);
23231         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23232         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23233 @@ -3430,6 +3433,7 @@ static inline void __cache_free(struct k
23234         check_irq_off();
23235         kmemleak_free_recursive(objp, cachep->flags);
23236         objp = cache_free_debugcheck(cachep, objp, caller);
23237 +       vx_slab_free(cachep);
23238  
23239         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23240  
23241 diff -NurpP --minimal linux-3.13.10/mm/slab_vs.h linux-3.13.10-vs2.3.6.11/mm/slab_vs.h
23242 --- linux-3.13.10/mm/slab_vs.h  1970-01-01 00:00:00.000000000 +0000
23243 +++ linux-3.13.10-vs2.3.6.11/mm/slab_vs.h       2014-01-31 20:38:04.000000000 +0000
23244 @@ -0,0 +1,29 @@
23245 +
23246 +#include <linux/vserver/context.h>
23247 +
23248 +#include <linux/vs_context.h>
23249 +
23250 +static inline
23251 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23252 +{
23253 +       int what = gfp_zone(cachep->allocflags);
23254 +       struct vx_info *vxi = current_vx_info();
23255 +
23256 +       if (!vxi)
23257 +               return;
23258 +
23259 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
23260 +}
23261 +
23262 +static inline
23263 +void vx_slab_free(struct kmem_cache *cachep)
23264 +{
23265 +       int what = gfp_zone(cachep->allocflags);
23266 +       struct vx_info *vxi = current_vx_info();
23267 +
23268 +       if (!vxi)
23269 +               return;
23270 +
23271 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23272 +}
23273 +
23274 diff -NurpP --minimal linux-3.13.10/mm/swapfile.c linux-3.13.10-vs2.3.6.11/mm/swapfile.c
23275 --- linux-3.13.10/mm/swapfile.c 2014-04-17 01:12:40.000000000 +0000
23276 +++ linux-3.13.10-vs2.3.6.11/mm/swapfile.c      2014-02-25 11:26:10.000000000 +0000
23277 @@ -39,6 +39,7 @@
23278  #include <asm/tlbflush.h>
23279  #include <linux/swapops.h>
23280  #include <linux/page_cgroup.h>
23281 +#include <linux/vs_base.h>
23282  
23283  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23284                                  unsigned char);
23285 @@ -2042,6 +2043,16 @@ static int swap_show(struct seq_file *sw
23286  
23287         if (si == SEQ_START_TOKEN) {
23288                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23289 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
23290 +                       struct sysinfo si;
23291 +
23292 +                       vx_vsi_swapinfo(&si);
23293 +                       if (si.totalswap < (1 << 10))
23294 +                               return 0;
23295 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23296 +                               "hdv0", "partition", si.totalswap >> 10,
23297 +                               (si.totalswap - si.freeswap) >> 10, -1);
23298 +               }
23299                 return 0;
23300         }
23301  
23302 @@ -2589,6 +2600,8 @@ void si_swapinfo(struct sysinfo *val)
23303         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
23304         val->totalswap = total_swap_pages + nr_to_be_unused;
23305         spin_unlock(&swap_lock);
23306 +       if (vx_flags(VXF_VIRT_MEM, 0))
23307 +               vx_vsi_swapinfo(val);
23308  }
23309  
23310  /*
23311 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
23312 --- linux-3.13.10/net/bridge/br_multicast.c     2014-04-17 01:12:40.000000000 +0000
23313 +++ linux-3.13.10-vs2.3.6.11/net/bridge/br_multicast.c  2014-04-17 01:17:11.000000000 +0000
23314 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
23315         ip6h->hop_limit = 1;
23316         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23317         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23318 -                              &ip6h->saddr)) {
23319 +                              &ip6h->saddr, NULL)) {
23320                 kfree_skb(skb);
23321                 return NULL;
23322         }
23323 diff -NurpP --minimal linux-3.13.10/net/core/dev.c linux-3.13.10-vs2.3.6.11/net/core/dev.c
23324 --- linux-3.13.10/net/core/dev.c        2014-04-17 01:12:41.000000000 +0000
23325 +++ linux-3.13.10-vs2.3.6.11/net/core/dev.c     2014-03-12 15:51:08.000000000 +0000
23326 @@ -122,6 +122,7 @@
23327  #include <linux/in.h>
23328  #include <linux/jhash.h>
23329  #include <linux/random.h>
23330 +#include <linux/vs_inet.h>
23331  #include <trace/events/napi.h>
23332  #include <trace/events/net.h>
23333  #include <trace/events/skb.h>
23334 @@ -669,7 +670,8 @@ struct net_device *__dev_get_by_name(str
23335         struct hlist_head *head = dev_name_hash(net, name);
23336  
23337         hlist_for_each_entry(dev, head, name_hlist)
23338 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23339 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23340 +                   nx_dev_visible(current_nx_info(), dev))
23341                         return dev;
23342  
23343         return NULL;
23344 @@ -694,7 +696,8 @@ struct net_device *dev_get_by_name_rcu(s
23345         struct hlist_head *head = dev_name_hash(net, name);
23346  
23347         hlist_for_each_entry_rcu(dev, head, name_hlist)
23348 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23349 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23350 +                   nx_dev_visible(current_nx_info(), dev))
23351                         return dev;
23352  
23353         return NULL;
23354 @@ -744,7 +747,8 @@ struct net_device *__dev_get_by_index(st
23355         struct hlist_head *head = dev_index_hash(net, ifindex);
23356  
23357         hlist_for_each_entry(dev, head, index_hlist)
23358 -               if (dev->ifindex == ifindex)
23359 +               if ((dev->ifindex == ifindex) &&
23360 +                   nx_dev_visible(current_nx_info(), dev))
23361                         return dev;
23362  
23363         return NULL;
23364 @@ -762,7 +766,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
23365   *     about locking. The caller must hold RCU lock.
23366   */
23367  
23368 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23369 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
23370  {
23371         struct net_device *dev;
23372         struct hlist_head *head = dev_index_hash(net, ifindex);
23373 @@ -773,6 +777,16 @@ struct net_device *dev_get_by_index_rcu(
23374  
23375         return NULL;
23376  }
23377 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
23378 +
23379 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23380 +{
23381 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
23382 +
23383 +       if (nx_dev_visible(current_nx_info(), dev))
23384 +               return dev;
23385 +       return NULL;
23386 +}
23387  EXPORT_SYMBOL(dev_get_by_index_rcu);
23388  
23389  
23390 @@ -855,7 +869,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
23391  
23392         for_each_netdev_rcu(net, dev)
23393                 if (dev->type == type &&
23394 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
23395 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
23396 +                   nx_dev_visible(current_nx_info(), dev))
23397                         return dev;
23398  
23399         return NULL;
23400 @@ -867,9 +882,11 @@ struct net_device *__dev_getfirstbyhwtyp
23401         struct net_device *dev;
23402  
23403         ASSERT_RTNL();
23404 -       for_each_netdev(net, dev)
23405 -               if (dev->type == type)
23406 +       for_each_netdev(net, dev) {
23407 +               if ((dev->type == type) &&
23408 +                   nx_dev_visible(current_nx_info(), dev))
23409                         return dev;
23410 +       }
23411  
23412         return NULL;
23413  }
23414 @@ -881,7 +898,8 @@ struct net_device *dev_getfirstbyhwtype(
23415  
23416         rcu_read_lock();
23417         for_each_netdev_rcu(net, dev)
23418 -               if (dev->type == type) {
23419 +               if ((dev->type == type) &&
23420 +                   nx_dev_visible(current_nx_info(), dev)) {
23421                         dev_hold(dev);
23422                         ret = dev;
23423                         break;
23424 @@ -909,7 +927,8 @@ struct net_device *dev_get_by_flags_rcu(
23425  
23426         ret = NULL;
23427         for_each_netdev_rcu(net, dev) {
23428 -               if (((dev->flags ^ if_flags) & mask) == 0) {
23429 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
23430 +                       nx_dev_visible(current_nx_info(), dev)) {
23431                         ret = dev;
23432                         break;
23433                 }
23434 @@ -987,6 +1006,8 @@ static int __dev_alloc_name(struct net *
23435                                 continue;
23436                         if (i < 0 || i >= max_netdevices)
23437                                 continue;
23438 +                       if (!nx_dev_visible(current_nx_info(), d))
23439 +                               continue;
23440  
23441                         /*  avoid cases where sscanf is not exact inverse of printf */
23442                         snprintf(buf, IFNAMSIZ, name, i);
23443 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
23444 --- linux-3.13.10/net/core/net-procfs.c 2013-11-25 15:45:09.000000000 +0000
23445 +++ linux-3.13.10-vs2.3.6.11/net/core/net-procfs.c      2014-01-31 20:38:04.000000000 +0000
23446 @@ -1,6 +1,7 @@
23447  #include <linux/netdevice.h>
23448  #include <linux/proc_fs.h>
23449  #include <linux/seq_file.h>
23450 +#include <linux/vs_inet.h>
23451  #include <net/wext.h>
23452  
23453  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
23454 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
23455  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
23456  {
23457         struct rtnl_link_stats64 temp;
23458 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
23459 +       const struct rtnl_link_stats64 *stats;
23460 +
23461 +       /* device visible inside network context? */
23462 +       if (!nx_dev_visible(current_nx_info(), dev))
23463 +               return;
23464  
23465 +       stats = dev_get_stats(dev, &temp);
23466         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
23467                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
23468                    dev->name, stats->rx_bytes, stats->rx_packets,
23469 diff -NurpP --minimal linux-3.13.10/net/core/rtnetlink.c linux-3.13.10-vs2.3.6.11/net/core/rtnetlink.c
23470 --- linux-3.13.10/net/core/rtnetlink.c  2014-04-17 01:12:41.000000000 +0000
23471 +++ linux-3.13.10-vs2.3.6.11/net/core/rtnetlink.c       2014-04-17 01:17:11.000000000 +0000
23472 @@ -1090,6 +1090,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
23473                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
23474                         if (idx < s_idx)
23475                                 goto cont;
23476 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
23477 +                               continue;
23478                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
23479                                              NETLINK_CB(cb->skb).portid,
23480                                              cb->nlh->nlmsg_seq, 0,
23481 @@ -1992,6 +1994,9 @@ void rtmsg_ifinfo(int type, struct net_d
23482         int err = -ENOBUFS;
23483         size_t if_info_size;
23484  
23485 +       if (!nx_dev_visible(current_nx_info(), dev))
23486 +               return;
23487 +
23488         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), flags);
23489         if (skb == NULL)
23490                 goto errout;
23491 diff -NurpP --minimal linux-3.13.10/net/core/sock.c linux-3.13.10-vs2.3.6.11/net/core/sock.c
23492 --- linux-3.13.10/net/core/sock.c       2014-04-17 01:12:41.000000000 +0000
23493 +++ linux-3.13.10-vs2.3.6.11/net/core/sock.c    2014-04-17 01:17:11.000000000 +0000
23494 @@ -133,6 +133,10 @@
23495  #include <net/netprio_cgroup.h>
23496  
23497  #include <linux/filter.h>
23498 +#include <linux/vs_socket.h>
23499 +#include <linux/vs_limit.h>
23500 +#include <linux/vs_context.h>
23501 +#include <linux/vs_network.h>
23502  
23503  #include <trace/events/sock.h>
23504  
23505 @@ -1279,6 +1283,8 @@ static struct sock *sk_prot_alloc(struct
23506                         goto out_free_sec;
23507                 sk_tx_queue_clear(sk);
23508         }
23509 +               sock_vx_init(sk);
23510 +               sock_nx_init(sk);
23511  
23512         return sk;
23513  
23514 @@ -1387,6 +1393,11 @@ static void __sk_free(struct sock *sk)
23515                 put_cred(sk->sk_peer_cred);
23516         put_pid(sk->sk_peer_pid);
23517         put_net(sock_net(sk));
23518 +       vx_sock_dec(sk);
23519 +       clr_vx_info(&sk->sk_vx_info);
23520 +       sk->sk_xid = -1;
23521 +       clr_nx_info(&sk->sk_nx_info);
23522 +       sk->sk_nid = -1;
23523         sk_prot_free(sk->sk_prot_creator, sk);
23524  }
23525  
23526 @@ -1447,6 +1458,8 @@ struct sock *sk_clone_lock(const struct
23527  
23528                 /* SANITY */
23529                 get_net(sock_net(newsk));
23530 +               sock_vx_init(newsk);
23531 +               sock_nx_init(newsk);
23532                 sk_node_init(&newsk->sk_node);
23533                 sock_lock_init(newsk);
23534                 bh_lock_sock(newsk);
23535 @@ -1503,6 +1516,12 @@ struct sock *sk_clone_lock(const struct
23536                 smp_wmb();
23537                 atomic_set(&newsk->sk_refcnt, 2);
23538  
23539 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
23540 +               newsk->sk_xid = sk->sk_xid;
23541 +               vx_sock_inc(newsk);
23542 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
23543 +               newsk->sk_nid = sk->sk_nid;
23544 +
23545                 /*
23546                  * Increment the counter in the same struct proto as the master
23547                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
23548 @@ -2340,6 +2359,12 @@ void sock_init_data(struct socket *sock,
23549  
23550         sk->sk_stamp = ktime_set(-1L, 0);
23551  
23552 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
23553 +       sk->sk_xid = vx_current_xid();
23554 +       vx_sock_inc(sk);
23555 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
23556 +       sk->sk_nid = nx_current_nid();
23557 +
23558  #ifdef CONFIG_NET_RX_BUSY_POLL
23559         sk->sk_napi_id          =       0;
23560         sk->sk_ll_usec          =       sysctl_net_busy_read;
23561 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
23562 --- linux-3.13.10/net/ipv4/af_inet.c    2014-04-17 01:12:41.000000000 +0000
23563 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/af_inet.c 2014-04-17 01:17:11.000000000 +0000
23564 @@ -118,6 +118,7 @@
23565  #ifdef CONFIG_IP_MROUTE
23566  #include <linux/mroute.h>
23567  #endif
23568 +#include <linux/vs_limit.h>
23569  
23570  
23571  /* The inetsw table contains everything that inet_create needs to
23572 @@ -309,10 +310,13 @@ lookup_protocol:
23573         }
23574  
23575         err = -EPERM;
23576 +       if ((protocol == IPPROTO_ICMP) &&
23577 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
23578 +               goto override;
23579         if (sock->type == SOCK_RAW && !kern &&
23580             !ns_capable(net->user_ns, CAP_NET_RAW))
23581                 goto out_rcu_unlock;
23582 -
23583 +override:
23584         sock->ops = answer->ops;
23585         answer_prot = answer->prot;
23586         answer_no_check = answer->no_check;
23587 @@ -433,6 +437,7 @@ int inet_bind(struct socket *sock, struc
23588         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
23589         struct sock *sk = sock->sk;
23590         struct inet_sock *inet = inet_sk(sk);
23591 +       struct nx_v4_sock_addr nsa;
23592         struct net *net = sock_net(sk);
23593         unsigned short snum;
23594         int chk_addr_ret;
23595 @@ -457,7 +462,11 @@ int inet_bind(struct socket *sock, struc
23596                         goto out;
23597         }
23598  
23599 -       chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
23600 +       err = v4_map_sock_addr(inet, addr, &nsa);
23601 +       if (err)
23602 +               goto out;
23603 +
23604 +       chk_addr_ret = inet_addr_type(net, nsa.saddr);
23605  
23606         /* Not specified by any standard per-se, however it breaks too
23607          * many applications when removed.  It is unfortunate since
23608 @@ -469,7 +478,7 @@ int inet_bind(struct socket *sock, struc
23609         err = -EADDRNOTAVAIL;
23610         if (!sysctl_ip_nonlocal_bind &&
23611             !(inet->freebind || inet->transparent) &&
23612 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
23613 +           nsa.saddr != htonl(INADDR_ANY) &&
23614             chk_addr_ret != RTN_LOCAL &&
23615             chk_addr_ret != RTN_MULTICAST &&
23616             chk_addr_ret != RTN_BROADCAST)
23617 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
23618         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
23619                 goto out_release_sock;
23620  
23621 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23622 +       v4_set_sock_addr(inet, &nsa);
23623         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23624                 inet->inet_saddr = 0;  /* Use device */
23625  
23626 @@ -714,11 +723,13 @@ int inet_getname(struct socket *sock, st
23627                      peer == 1))
23628                         return -ENOTCONN;
23629                 sin->sin_port = inet->inet_dport;
23630 -               sin->sin_addr.s_addr = inet->inet_daddr;
23631 +               sin->sin_addr.s_addr =
23632 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
23633         } else {
23634                 __be32 addr = inet->inet_rcv_saddr;
23635                 if (!addr)
23636                         addr = inet->inet_saddr;
23637 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
23638                 sin->sin_port = inet->inet_sport;
23639                 sin->sin_addr.s_addr = addr;
23640         }
23641 diff -NurpP --minimal linux-3.13.10/net/ipv4/arp.c linux-3.13.10-vs2.3.6.11/net/ipv4/arp.c
23642 --- linux-3.13.10/net/ipv4/arp.c        2013-11-25 15:47:06.000000000 +0000
23643 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/arp.c     2014-01-31 20:38:04.000000000 +0000
23644 @@ -1336,6 +1336,7 @@ static void arp_format_neigh_entry(struc
23645         struct net_device *dev = n->dev;
23646         int hatype = dev->type;
23647  
23648 +       /* FIXME: check for network context */
23649         read_lock(&n->lock);
23650         /* Convert hardware address to XX:XX:XX:XX ... form. */
23651  #if IS_ENABLED(CONFIG_AX25)
23652 @@ -1367,6 +1368,7 @@ static void arp_format_pneigh_entry(stru
23653         int hatype = dev ? dev->type : 0;
23654         char tbuf[16];
23655  
23656 +       /* FIXME: check for network context */
23657         sprintf(tbuf, "%pI4", n->key);
23658         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
23659                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
23660 diff -NurpP --minimal linux-3.13.10/net/ipv4/devinet.c linux-3.13.10-vs2.3.6.11/net/ipv4/devinet.c
23661 --- linux-3.13.10/net/ipv4/devinet.c    2014-04-17 01:12:41.000000000 +0000
23662 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/devinet.c 2014-03-12 15:51:08.000000000 +0000
23663 @@ -527,6 +527,7 @@ struct in_device *inetdev_by_index(struc
23664  }
23665  EXPORT_SYMBOL(inetdev_by_index);
23666  
23667 +
23668  /* Called only from RTNL semaphored context. No locks. */
23669  
23670  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
23671 @@ -947,6 +948,8 @@ int devinet_ioctl(struct net *net, unsig
23672  
23673         in_dev = __in_dev_get_rtnl(dev);
23674         if (in_dev) {
23675 +               struct nx_info *nxi = current_nx_info();
23676 +
23677                 if (tryaddrmatch) {
23678                         /* Matthias Andree */
23679                         /* compare label and address (4.4BSD style) */
23680 @@ -955,6 +958,8 @@ int devinet_ioctl(struct net *net, unsig
23681                            This is checked above. */
23682                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23683                              ifap = &ifa->ifa_next) {
23684 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23685 +                                       continue;
23686                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
23687                                     sin_orig.sin_addr.s_addr ==
23688                                                         ifa->ifa_local) {
23689 @@ -967,9 +972,12 @@ int devinet_ioctl(struct net *net, unsig
23690                    comparing just the label */
23691                 if (!ifa) {
23692                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23693 -                            ifap = &ifa->ifa_next)
23694 +                            ifap = &ifa->ifa_next) {
23695 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23696 +                                       continue;
23697                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
23698                                         break;
23699 +                       }
23700                 }
23701         }
23702  
23703 @@ -1123,6 +1131,8 @@ static int inet_gifconf(struct net_devic
23704                 goto out;
23705  
23706         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
23707 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
23708 +                       continue;
23709                 if (!buf) {
23710                         done += sizeof(ifr);
23711                         continue;
23712 @@ -1524,6 +1534,7 @@ static int inet_dump_ifaddr(struct sk_bu
23713         struct net_device *dev;
23714         struct in_device *in_dev;
23715         struct in_ifaddr *ifa;
23716 +       struct sock *sk = skb->sk;
23717         struct hlist_head *head;
23718  
23719         s_h = cb->args[0];
23720 @@ -1547,6 +1558,8 @@ static int inet_dump_ifaddr(struct sk_bu
23721  
23722                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
23723                              ifa = ifa->ifa_next, ip_idx++) {
23724 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
23725 +                               continue;
23726                                 if (ip_idx < s_ip_idx)
23727                                         continue;
23728                                 if (inet_fill_ifaddr(skb, ifa,
23729 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
23730 --- linux-3.13.10/net/ipv4/fib_trie.c   2014-01-22 20:39:15.000000000 +0000
23731 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/fib_trie.c        2014-01-31 20:38:04.000000000 +0000
23732 @@ -2530,6 +2530,7 @@ static int fib_route_seq_show(struct seq
23733  
23734                         seq_setwidth(seq, 127);
23735  
23736 +                       /* FIXME: check for network context? */
23737                         if (fi)
23738                                 seq_printf(seq,
23739                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
23740 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
23741 --- linux-3.13.10/net/ipv4/inet_connection_sock.c       2014-01-22 20:39:15.000000000 +0000
23742 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_connection_sock.c    2014-02-01 00:33:11.000000000 +0000
23743 @@ -45,6 +45,37 @@ void inet_get_local_port_range(struct ne
23744  }
23745  EXPORT_SYMBOL(inet_get_local_port_range);
23746  
23747 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
23748 +{
23749 +       __be32  sk1_rcv_saddr = sk1->sk_rcv_saddr,
23750 +               sk2_rcv_saddr = sk2->sk_rcv_saddr;
23751 +
23752 +       if (inet_v6_ipv6only(sk2))
23753 +               return 0;
23754 +
23755 +       if (sk1_rcv_saddr &&
23756 +           sk2_rcv_saddr &&
23757 +           sk1_rcv_saddr == sk2_rcv_saddr)
23758 +               return 1;
23759 +
23760 +       if (sk1_rcv_saddr &&
23761 +           !sk2_rcv_saddr &&
23762 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
23763 +               return 1;
23764 +
23765 +       if (sk2_rcv_saddr &&
23766 +           !sk1_rcv_saddr &&
23767 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
23768 +               return 1;
23769 +
23770 +       if (!sk1_rcv_saddr &&
23771 +           !sk2_rcv_saddr &&
23772 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
23773 +               return 1;
23774 +
23775 +       return 0;
23776 +}
23777 +
23778  int inet_csk_bind_conflict(const struct sock *sk,
23779                            const struct inet_bind_bucket *tb, bool relax)
23780  {
23781 @@ -72,15 +103,13 @@ int inet_csk_bind_conflict(const struct
23782                             (sk2->sk_state != TCP_TIME_WAIT &&
23783                              !uid_eq(uid, sock_i_uid(sk2))))) {
23784  
23785 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23786 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23787 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23788                                         break;
23789                         }
23790                         if (!relax && reuse && sk2->sk_reuse &&
23791                             sk2->sk_state != TCP_LISTEN) {
23792  
23793 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23794 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23795 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23796                                         break;
23797                         }
23798                 }
23799 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
23800 --- linux-3.13.10/net/ipv4/inet_diag.c  2014-02-01 02:17:51.000000000 +0000
23801 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_diag.c       2014-02-01 02:32:22.000000000 +0000
23802 @@ -31,6 +31,8 @@
23803  
23804  #include <linux/inet.h>
23805  #include <linux/stddef.h>
23806 +#include <linux/vs_network.h>
23807 +#include <linux/vs_inet.h>
23808  
23809  #include <linux/inet_diag.h>
23810  #include <linux/sock_diag.h>
23811 @@ -110,8 +112,10 @@ int inet_sk_diag_fill(struct sock *sk, s
23812         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23813         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23814  
23815 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
23816 -       r->id.idiag_dst[0] = inet->inet_daddr;
23817 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
23818 +               inet->inet_rcv_saddr);
23819 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
23820 +               inet->inet_daddr);
23821  
23822         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
23823                 goto errout;
23824 @@ -254,8 +258,8 @@ static int inet_twsk_diag_fill(struct in
23825         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23826         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23827  
23828 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
23829 -       r->id.idiag_dst[0]    = tw->tw_daddr;
23830 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
23831 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
23832  
23833         r->idiag_state        = tw->tw_substate;
23834         r->idiag_timer        = 3;
23835 @@ -298,12 +302,14 @@ int inet_diag_dump_one_icsk(struct inet_
23836  
23837         err = -EINVAL;
23838         if (req->sdiag_family == AF_INET) {
23839 +               /* TODO: lback */
23840                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
23841                                  req->id.idiag_dport, req->id.idiag_src[0],
23842                                  req->id.idiag_sport, req->id.idiag_if);
23843         }
23844  #if IS_ENABLED(CONFIG_IPV6)
23845         else if (req->sdiag_family == AF_INET6) {
23846 +               /* TODO: lback */
23847                 sk = inet6_lookup(net, hashinfo,
23848                                   (struct in6_addr *)req->id.idiag_dst,
23849                                   req->id.idiag_dport,
23850 @@ -501,6 +507,7 @@ int inet_diag_bc_sk(const struct nlattr
23851         } else
23852  #endif
23853         {
23854 +                       /* TODO: lback */
23855                 entry.saddr = &inet->inet_rcv_saddr;
23856                 entry.daddr = &inet->inet_daddr;
23857         }
23858 @@ -659,6 +666,7 @@ static int inet_twsk_diag_dump(struct so
23859                 } else
23860  #endif
23861                 {
23862 +                       /* TODO: lback */
23863                         entry.saddr = &tw->tw_rcv_saddr;
23864                         entry.daddr = &tw->tw_daddr;
23865                 }
23866 @@ -741,8 +749,8 @@ static int inet_diag_fill_req(struct sk_
23867         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23868         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23869  
23870 -       r->id.idiag_src[0] = ireq->ir_loc_addr;
23871 -       r->id.idiag_dst[0] = ireq->ir_rmt_addr;
23872 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_loc_addr);
23873 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_rmt_addr);
23874  
23875         r->idiag_expires = jiffies_to_msecs(tmo);
23876         r->idiag_rqueue = 0;
23877 @@ -806,6 +814,7 @@ static int inet_diag_dump_reqs(struct sk
23878                             r->id.idiag_dport)
23879                                 continue;
23880  
23881 +                       /* TODO: lback */
23882                         if (bc) {
23883                                 inet_diag_req_addrs(sk, req, &entry);
23884                                 entry.dport = ntohs(ireq->ir_rmt_port);
23885 @@ -862,6 +871,8 @@ void inet_diag_dump_icsk(struct inet_has
23886                                 if (!net_eq(sock_net(sk), net))
23887                                         continue;
23888  
23889 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23890 +                                       continue;
23891                                 if (num < s_num) {
23892                                         num++;
23893                                         continue;
23894 @@ -934,6 +945,8 @@ skip_listen_ht:
23895  
23896                         if (!net_eq(sock_net(sk), net))
23897                                 continue;
23898 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23899 +                               continue;
23900                         if (num < s_num)
23901                                 goto next_normal;
23902                         state = (sk->sk_state == TCP_TIME_WAIT) ?
23903 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
23904 --- linux-3.13.10/net/ipv4/inet_hashtables.c    2014-01-22 20:39:15.000000000 +0000
23905 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_hashtables.c 2014-01-31 20:38:04.000000000 +0000
23906 @@ -22,6 +22,7 @@
23907  #include <net/inet_connection_sock.h>
23908  #include <net/inet_hashtables.h>
23909  #include <net/secure_seq.h>
23910 +#include <net/route.h>
23911  #include <net/ip.h>
23912  
23913  static unsigned int inet_ehashfn(struct net *net, const __be32 laddr,
23914 @@ -181,6 +182,11 @@ static inline int compute_score(struct s
23915                         if (rcv_saddr != daddr)
23916                                 return -1;
23917                         score += 4;
23918 +               } else {
23919 +                       /* block non nx_info ips */
23920 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
23921 +                               daddr, NXA_MASK_BIND))
23922 +                               return -1;
23923                 }
23924                 if (sk->sk_bound_dev_if) {
23925                         if (sk->sk_bound_dev_if != dif)
23926 @@ -198,7 +204,6 @@ static inline int compute_score(struct s
23927   * wildcarded during the search since they can never be otherwise.
23928   */
23929  
23930 -
23931  struct sock *__inet_lookup_listener(struct net *net,
23932                                     struct inet_hashinfo *hashinfo,
23933                                     const __be32 saddr, __be16 sport,
23934 @@ -234,6 +239,7 @@ begin:
23935                         phash = next_pseudo_random32(phash);
23936                 }
23937         }
23938 +
23939         /*
23940          * if the nulls value we got at the end of this lookup is
23941          * not the expected one, we must restart lookup.
23942 diff -NurpP --minimal linux-3.13.10/net/ipv4/netfilter.c linux-3.13.10-vs2.3.6.11/net/ipv4/netfilter.c
23943 --- linux-3.13.10/net/ipv4/netfilter.c  2013-07-14 17:01:37.000000000 +0000
23944 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/netfilter.c       2014-01-31 20:38:04.000000000 +0000
23945 @@ -11,7 +11,7 @@
23946  #include <linux/skbuff.h>
23947  #include <linux/gfp.h>
23948  #include <linux/export.h>
23949 -#include <net/route.h>
23950 +// #include <net/route.h>
23951  #include <net/xfrm.h>
23952  #include <net/ip.h>
23953  #include <net/netfilter/nf_queue.h>
23954 diff -NurpP --minimal linux-3.13.10/net/ipv4/raw.c linux-3.13.10-vs2.3.6.11/net/ipv4/raw.c
23955 --- linux-3.13.10/net/ipv4/raw.c        2014-01-22 20:39:15.000000000 +0000
23956 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/raw.c     2014-01-31 20:38:04.000000000 +0000
23957 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
23958  
23959                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
23960                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
23961 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
23962 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
23963                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23964                         goto found; /* gotcha */
23965         }
23966 @@ -397,6 +397,12 @@ static int raw_send_hdrinc(struct sock *
23967                 icmp_out_count(net, ((struct icmphdr *)
23968                         skb_transport_header(skb))->type);
23969  
23970 +       err = -EPERM;
23971 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
23972 +               sk->sk_nx_info &&
23973 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
23974 +               goto error_free;
23975 +
23976         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
23977                       rt->dst.dev, dst_output);
23978         if (err > 0)
23979 @@ -585,6 +591,16 @@ static int raw_sendmsg(struct kiocb *ioc
23980                         goto done;
23981         }
23982  
23983 +       if (sk->sk_nx_info) {
23984 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
23985 +               if (IS_ERR(rt)) {
23986 +                       err = PTR_ERR(rt);
23987 +                       rt = NULL;
23988 +                       goto done;
23989 +               }
23990 +               ip_rt_put(rt);
23991 +       }
23992 +
23993         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
23994         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
23995         if (IS_ERR(rt)) {
23996 @@ -661,17 +677,19 @@ static int raw_bind(struct sock *sk, str
23997  {
23998         struct inet_sock *inet = inet_sk(sk);
23999         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24000 +       struct nx_v4_sock_addr nsa = { 0 };
24001         int ret = -EINVAL;
24002         int chk_addr_ret;
24003  
24004         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24005                 goto out;
24006 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24007 +       v4_map_sock_addr(inet, addr, &nsa);
24008 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24009         ret = -EADDRNOTAVAIL;
24010 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24011 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24012             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24013                 goto out;
24014 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24015 +       v4_set_sock_addr(inet, &nsa);
24016         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24017                 inet->inet_saddr = 0;  /* Use device */
24018         sk_dst_reset(sk);
24019 @@ -720,7 +738,8 @@ static int raw_recvmsg(struct kiocb *ioc
24020         /* Copy the address. */
24021         if (sin) {
24022                 sin->sin_family = AF_INET;
24023 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24024 +               sin->sin_addr.s_addr =
24025 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24026                 sin->sin_port = 0;
24027                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24028                 *addr_len = sizeof(*sin);
24029 @@ -916,7 +935,8 @@ static struct sock *raw_get_first(struct
24030         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24031                         ++state->bucket) {
24032                 sk_for_each(sk, &state->h->ht[state->bucket])
24033 -                       if (sock_net(sk) == seq_file_net(seq))
24034 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24035 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24036                                 goto found;
24037         }
24038         sk = NULL;
24039 @@ -932,7 +952,8 @@ static struct sock *raw_get_next(struct
24040                 sk = sk_next(sk);
24041  try_again:
24042                 ;
24043 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24044 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24045 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24046  
24047         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24048                 sk = sk_head(&state->h->ht[state->bucket]);
24049 diff -NurpP --minimal linux-3.13.10/net/ipv4/route.c linux-3.13.10-vs2.3.6.11/net/ipv4/route.c
24050 --- linux-3.13.10/net/ipv4/route.c      2014-04-17 01:12:41.000000000 +0000
24051 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/route.c   2014-03-12 15:51:08.000000000 +0000
24052 @@ -2063,7 +2063,7 @@ struct rtable *__ip_route_output_key(str
24053  
24054  
24055         if (fl4->flowi4_oif) {
24056 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24057 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24058                 rth = ERR_PTR(-ENODEV);
24059                 if (dev_out == NULL)
24060                         goto out;
24061 diff -NurpP --minimal linux-3.13.10/net/ipv4/tcp.c linux-3.13.10-vs2.3.6.11/net/ipv4/tcp.c
24062 --- linux-3.13.10/net/ipv4/tcp.c        2014-04-17 01:12:41.000000000 +0000
24063 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp.c     2014-04-17 01:17:11.000000000 +0000
24064 @@ -268,6 +268,7 @@
24065  #include <linux/crypto.h>
24066  #include <linux/time.h>
24067  #include <linux/slab.h>
24068 +#include <linux/in.h>
24069  
24070  #include <net/icmp.h>
24071  #include <net/inet_common.h>
24072 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
24073 --- linux-3.13.10/net/ipv4/tcp_ipv4.c   2014-04-17 01:12:41.000000000 +0000
24074 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_ipv4.c        2014-04-17 01:17:11.000000000 +0000
24075 @@ -2227,6 +2227,12 @@ static void *listening_get_next(struct s
24076                 req = req->dl_next;
24077                 while (1) {
24078                         while (req) {
24079 +                               vxdprintk(VXD_CBIT(net, 6),
24080 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24081 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24082 +                               if (req->sk &&
24083 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24084 +                                       continue;
24085                                 if (req->rsk_ops->family == st->family) {
24086                                         cur = req;
24087                                         goto out;
24088 @@ -2251,6 +2257,10 @@ get_req:
24089         }
24090  get_sk:
24091         sk_nulls_for_each_from(sk, node) {
24092 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24093 +                       sk, sk->sk_nid, nx_current_nid());
24094 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24095 +                       continue;
24096                 if (!net_eq(sock_net(sk), net))
24097                         continue;
24098                 if (sk->sk_family == st->family) {
24099 @@ -2325,6 +2335,11 @@ static void *established_get_first(struc
24100  
24101                 spin_lock_bh(lock);
24102                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24103 +                       vxdprintk(VXD_CBIT(net, 6),
24104 +                               "sk,egf: %p [#%d] (from %d)",
24105 +                               sk, sk->sk_nid, nx_current_nid());
24106 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24107 +                               continue;
24108                         if (sk->sk_family != st->family ||
24109                             !net_eq(sock_net(sk), net)) {
24110                                 continue;
24111 @@ -2351,6 +2366,11 @@ static void *established_get_next(struct
24112         sk = sk_nulls_next(sk);
24113  
24114         sk_nulls_for_each_from(sk, node) {
24115 +               vxdprintk(VXD_CBIT(net, 6),
24116 +                       "sk,egn: %p [#%d] (from %d)",
24117 +                       sk, sk->sk_nid, nx_current_nid());
24118 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24119 +                       continue;
24120                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24121                         return sk;
24122         }
24123 @@ -2549,9 +2569,9 @@ static void get_openreq4(const struct so
24124         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24125                 " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d %pK",
24126                 i,
24127 -               ireq->ir_loc_addr,
24128 +               nx_map_sock_lback(current_nx_info(), ireq->ir_loc_addr),
24129                 ntohs(inet_sk(sk)->inet_sport),
24130 -               ireq->ir_rmt_addr,
24131 +               nx_map_sock_lback(current_nx_info(), ireq->ir_rmt_addr),
24132                 ntohs(ireq->ir_rmt_port),
24133                 TCP_SYN_RECV,
24134                 0, 0, /* could print option size, but that is af dependent. */
24135 @@ -2573,8 +2593,8 @@ static void get_tcp4_sock(struct sock *s
24136         const struct inet_connection_sock *icsk = inet_csk(sk);
24137         const struct inet_sock *inet = inet_sk(sk);
24138         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24139 -       __be32 dest = inet->inet_daddr;
24140 -       __be32 src = inet->inet_rcv_saddr;
24141 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24142 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24143         __u16 destp = ntohs(inet->inet_dport);
24144         __u16 srcp = ntohs(inet->inet_sport);
24145         int rx_queue;
24146 @@ -2631,8 +2651,8 @@ static void get_timewait4_sock(const str
24147         __u16 destp, srcp;
24148         s32 delta = tw->tw_ttd - inet_tw_time_stamp();
24149  
24150 -       dest  = tw->tw_daddr;
24151 -       src   = tw->tw_rcv_saddr;
24152 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24153 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24154         destp = ntohs(tw->tw_dport);
24155         srcp  = ntohs(tw->tw_sport);
24156  
24157 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
24158 --- linux-3.13.10/net/ipv4/tcp_minisocks.c      2014-01-22 20:39:15.000000000 +0000
24159 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_minisocks.c   2014-01-31 20:38:04.000000000 +0000
24160 @@ -23,6 +23,9 @@
24161  #include <linux/slab.h>
24162  #include <linux/sysctl.h>
24163  #include <linux/workqueue.h>
24164 +#include <linux/vs_limit.h>
24165 +#include <linux/vs_socket.h>
24166 +#include <linux/vs_context.h>
24167  #include <net/tcp.h>
24168  #include <net/inet_common.h>
24169  #include <net/xfrm.h>
24170 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int
24171                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24172                 tcptw->tw_ts_offset     = tp->tsoffset;
24173  
24174 +               tw->tw_xid              = sk->sk_xid;
24175 +               tw->tw_vx_info          = NULL;
24176 +               tw->tw_nid              = sk->sk_nid;
24177 +               tw->tw_nx_info          = NULL;
24178 +
24179  #if IS_ENABLED(CONFIG_IPV6)
24180                 if (tw->tw_family == PF_INET6) {
24181                         struct ipv6_pinfo *np = inet6_sk(sk);
24182 diff -NurpP --minimal linux-3.13.10/net/ipv4/udp.c linux-3.13.10-vs2.3.6.11/net/ipv4/udp.c
24183 --- linux-3.13.10/net/ipv4/udp.c        2014-01-22 20:39:15.000000000 +0000
24184 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/udp.c     2014-01-31 22:20:27.000000000 +0000
24185 @@ -308,14 +308,7 @@ fail:
24186  }
24187  EXPORT_SYMBOL(udp_lib_get_port);
24188  
24189 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24190 -{
24191 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24192 -
24193 -       return  (!ipv6_only_sock(sk2)  &&
24194 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24195 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24196 -}
24197 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24198  
24199  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24200                                        unsigned int port)
24201 @@ -350,6 +343,11 @@ static inline int compute_score(struct s
24202                         if (inet->inet_rcv_saddr != daddr)
24203                                 return -1;
24204                         score += 4;
24205 +               } else {
24206 +                       /* block non nx_info ips */
24207 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24208 +                               daddr, NXA_MASK_BIND))
24209 +                               return -1;
24210                 }
24211                 if (inet->inet_daddr) {
24212                         if (inet->inet_daddr != saddr)
24213 @@ -472,6 +470,7 @@ begin:
24214         return result;
24215  }
24216  
24217 +
24218  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24219   * harder than this. -DaveM
24220   */
24221 @@ -518,6 +517,11 @@ begin:
24222         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24223                 score = compute_score(sk, net, saddr, hnum, sport,
24224                                       daddr, dport, dif);
24225 +               /* FIXME: disabled?
24226 +               if (score == 9) {
24227 +                       result = sk;
24228 +                       break;
24229 +               } else */
24230                 if (score > badness) {
24231                         result = sk;
24232                         badness = score;
24233 @@ -542,6 +546,7 @@ begin:
24234         if (get_nulls_value(node) != slot)
24235                 goto begin;
24236  
24237 +
24238         if (result) {
24239                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24240                         result = NULL;
24241 @@ -551,6 +556,7 @@ begin:
24242                         goto begin;
24243                 }
24244         }
24245 +
24246         rcu_read_unlock();
24247         return result;
24248  }
24249 @@ -585,7 +591,7 @@ static inline bool __udp_is_mcast_sock(s
24250             udp_sk(sk)->udp_port_hash != hnum ||
24251             (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24252             (inet->inet_dport != rmt_port && inet->inet_dport) ||
24253 -           (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||
24254 +           !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24255             ipv6_only_sock(sk) ||
24256             (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24257                 return false;
24258 @@ -989,6 +995,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24259                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24260                                    faddr, saddr, dport, inet->inet_sport);
24261  
24262 +               if (sk->sk_nx_info) {
24263 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24264 +                       if (IS_ERR(rt)) {
24265 +                               err = PTR_ERR(rt);
24266 +                               rt = NULL;
24267 +                               goto out;
24268 +                       }
24269 +                       ip_rt_put(rt);
24270 +               }
24271 +
24272                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24273                 rt = ip_route_output_flow(net, fl4, sk);
24274                 if (IS_ERR(rt)) {
24275 @@ -1293,7 +1309,8 @@ try_again:
24276         if (sin) {
24277                 sin->sin_family = AF_INET;
24278                 sin->sin_port = udp_hdr(skb)->source;
24279 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24280 +               sin->sin_addr.s_addr = nx_map_sock_lback(
24281 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24282                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24283                 *addr_len = sizeof(*sin);
24284         }
24285 @@ -2223,6 +2240,8 @@ static struct sock *udp_get_first(struct
24286                 sk_nulls_for_each(sk, node, &hslot->head) {
24287                         if (!net_eq(sock_net(sk), net))
24288                                 continue;
24289 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24290 +                               continue;
24291                         if (sk->sk_family == state->family)
24292                                 goto found;
24293                 }
24294 @@ -2240,7 +2259,9 @@ static struct sock *udp_get_next(struct
24295  
24296         do {
24297                 sk = sk_nulls_next(sk);
24298 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
24299 +       } while (sk && (!net_eq(sock_net(sk), net) ||
24300 +               sk->sk_family != state->family ||
24301 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24302  
24303         if (!sk) {
24304                 if (state->bucket <= state->udp_table->mask)
24305 @@ -2336,8 +2357,8 @@ static void udp4_format_sock(struct sock
24306                 int bucket)
24307  {
24308         struct inet_sock *inet = inet_sk(sp);
24309 -       __be32 dest = inet->inet_daddr;
24310 -       __be32 src  = inet->inet_rcv_saddr;
24311 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24312 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24313         __u16 destp       = ntohs(inet->inet_dport);
24314         __u16 srcp        = ntohs(inet->inet_sport);
24315  
24316 diff -NurpP --minimal linux-3.13.10/net/ipv6/Kconfig linux-3.13.10-vs2.3.6.11/net/ipv6/Kconfig
24317 --- linux-3.13.10/net/ipv6/Kconfig      2014-01-22 20:39:15.000000000 +0000
24318 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/Kconfig   2014-01-31 20:38:04.000000000 +0000
24319 @@ -4,8 +4,8 @@
24320  
24321  #   IPv6 as module will cause a CRASH if you try to unload it
24322  menuconfig IPV6
24323 -       tristate "The IPv6 protocol"
24324 -       default m
24325 +       bool "The IPv6 protocol"
24326 +       default n
24327         ---help---
24328           This is complemental support for the IP version 6.
24329           You will still be able to do traditional IPv4 networking as well.
24330 diff -NurpP --minimal linux-3.13.10/net/ipv6/addrconf.c linux-3.13.10-vs2.3.6.11/net/ipv6/addrconf.c
24331 --- linux-3.13.10/net/ipv6/addrconf.c   2014-04-17 01:12:41.000000000 +0000
24332 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/addrconf.c        2014-04-17 01:17:11.000000000 +0000
24333 @@ -90,6 +90,8 @@
24334  #include <linux/proc_fs.h>
24335  #include <linux/seq_file.h>
24336  #include <linux/export.h>
24337 +#include <linux/vs_network.h>
24338 +#include <linux/vs_inet6.h>
24339  
24340  /* Set to 3 to get tracing... */
24341  #define ACONF_DEBUG 2
24342 @@ -1284,7 +1286,7 @@ out:
24343  
24344  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
24345                        const struct in6_addr *daddr, unsigned int prefs,
24346 -                      struct in6_addr *saddr)
24347 +                      struct in6_addr *saddr, struct nx_info *nxi)
24348  {
24349         struct ipv6_saddr_score scores[2],
24350                                 *score = &scores[0], *hiscore = &scores[1];
24351 @@ -1356,6 +1358,8 @@ int ipv6_dev_get_saddr(struct net *net,
24352                                                dev->name);
24353                                 continue;
24354                         }
24355 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
24356 +                               continue;
24357  
24358                         score->rule = -1;
24359                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
24360 @@ -3371,7 +3375,10 @@ static void if6_seq_stop(struct seq_file
24361  static int if6_seq_show(struct seq_file *seq, void *v)
24362  {
24363         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
24364 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24365 +
24366 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
24367 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
24368 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24369                    &ifp->addr,
24370                    ifp->idev->dev->ifindex,
24371                    ifp->prefix_len,
24372 @@ -3892,6 +3899,11 @@ static int in6_dump_addrs(struct inet6_d
24373         struct ifacaddr6 *ifaca;
24374         int err = 1;
24375         int ip_idx = *p_ip_idx;
24376 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24377 +
24378 +       /* disable ipv6 on non v6 guests */
24379 +       if (nxi && !nx_info_has_v6(nxi))
24380 +               return skb->len;
24381  
24382         read_lock_bh(&idev->lock);
24383         switch (type) {
24384 @@ -3902,6 +3914,8 @@ static int in6_dump_addrs(struct inet6_d
24385                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
24386                         if (++ip_idx < s_ip_idx)
24387                                 continue;
24388 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
24389 +                                       continue;
24390                         err = inet6_fill_ifaddr(skb, ifa,
24391                                                 NETLINK_CB(cb->skb).portid,
24392                                                 cb->nlh->nlmsg_seq,
24393 @@ -3919,6 +3933,8 @@ static int in6_dump_addrs(struct inet6_d
24394                      ifmca = ifmca->next, ip_idx++) {
24395                         if (ip_idx < s_ip_idx)
24396                                 continue;
24397 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
24398 +                                       continue;
24399                         err = inet6_fill_ifmcaddr(skb, ifmca,
24400                                                   NETLINK_CB(cb->skb).portid,
24401                                                   cb->nlh->nlmsg_seq,
24402 @@ -3934,6 +3950,8 @@ static int in6_dump_addrs(struct inet6_d
24403                      ifaca = ifaca->aca_next, ip_idx++) {
24404                         if (ip_idx < s_ip_idx)
24405                                 continue;
24406 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
24407 +                                       continue;
24408                         err = inet6_fill_ifacaddr(skb, ifaca,
24409                                                   NETLINK_CB(cb->skb).portid,
24410                                                   cb->nlh->nlmsg_seq,
24411 @@ -3962,6 +3980,10 @@ static int inet6_dump_addr(struct sk_buf
24412         struct inet6_dev *idev;
24413         struct hlist_head *head;
24414  
24415 +       /* FIXME: maybe disable ipv6 on non v6 guests?
24416 +       if (skb->sk && skb->sk->sk_vx_info)
24417 +               return skb->len; */
24418 +
24419         s_h = cb->args[0];
24420         s_idx = idx = cb->args[1];
24421         s_ip_idx = ip_idx = cb->args[2];
24422 @@ -4404,6 +4426,7 @@ static int inet6_dump_ifinfo(struct sk_b
24423         struct net_device *dev;
24424         struct inet6_dev *idev;
24425         struct hlist_head *head;
24426 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24427  
24428         s_h = cb->args[0];
24429         s_idx = cb->args[1];
24430 @@ -4415,6 +4438,8 @@ static int inet6_dump_ifinfo(struct sk_b
24431                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24432                         if (idx < s_idx)
24433                                 goto cont;
24434 +                       if (!v6_dev_in_nx_info(dev, nxi))
24435 +                               goto cont;
24436                         idev = __in6_dev_get(dev);
24437                         if (!idev)
24438                                 goto cont;
24439 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
24440 --- linux-3.13.10/net/ipv6/af_inet6.c   2014-01-22 20:39:15.000000000 +0000
24441 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/af_inet6.c        2014-01-31 21:39:03.000000000 +0000
24442 @@ -43,6 +43,8 @@
24443  #include <linux/netdevice.h>
24444  #include <linux/icmpv6.h>
24445  #include <linux/netfilter_ipv6.h>
24446 +#include <linux/vs_inet.h>
24447 +#include <linux/vs_inet6.h>
24448  
24449  #include <net/ip.h>
24450  #include <net/ipv6.h>
24451 @@ -156,10 +158,13 @@ lookup_protocol:
24452         }
24453  
24454         err = -EPERM;
24455 +       if ((protocol == IPPROTO_ICMPV6) &&
24456 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24457 +               goto override;
24458         if (sock->type == SOCK_RAW && !kern &&
24459             !ns_capable(net->user_ns, CAP_NET_RAW))
24460                 goto out_rcu_unlock;
24461 -
24462 +override:
24463         sock->ops = answer->ops;
24464         answer_prot = answer->prot;
24465         answer_no_check = answer->no_check;
24466 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
24467         struct inet_sock *inet = inet_sk(sk);
24468         struct ipv6_pinfo *np = inet6_sk(sk);
24469         struct net *net = sock_net(sk);
24470 +       struct nx_v6_sock_addr nsa;
24471         __be32 v4addr = 0;
24472         unsigned short snum;
24473         int addr_type = 0;
24474 @@ -274,6 +280,10 @@ int inet6_bind(struct socket *sock, stru
24475         if (addr->sin6_family != AF_INET6)
24476                 return -EAFNOSUPPORT;
24477  
24478 +       err = v6_map_sock_addr(inet, addr, &nsa);
24479 +       if (err)
24480 +               return err;
24481 +
24482         addr_type = ipv6_addr_type(&addr->sin6_addr);
24483         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
24484                 return -EINVAL;
24485 @@ -305,6 +315,7 @@ int inet6_bind(struct socket *sock, stru
24486                 /* Reproduce AF_INET checks to make the bindings consistent */
24487                 v4addr = addr->sin6_addr.s6_addr32[3];
24488                 chk_addr_ret = inet_addr_type(net, v4addr);
24489 +
24490                 if (!sysctl_ip_nonlocal_bind &&
24491                     !(inet->freebind || inet->transparent) &&
24492                     v4addr != htonl(INADDR_ANY) &&
24493 @@ -314,6 +325,10 @@ int inet6_bind(struct socket *sock, stru
24494                         err = -EADDRNOTAVAIL;
24495                         goto out;
24496                 }
24497 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
24498 +                       err = -EADDRNOTAVAIL;
24499 +                       goto out;
24500 +               }
24501         } else {
24502                 if (addr_type != IPV6_ADDR_ANY) {
24503                         struct net_device *dev = NULL;
24504 @@ -340,6 +355,11 @@ int inet6_bind(struct socket *sock, stru
24505                                 }
24506                         }
24507  
24508 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24509 +                               err = -EADDRNOTAVAIL;
24510 +                               goto out_unlock;
24511 +                       }
24512 +
24513                         /* ipv4 addr of the socket is invalid.  Only the
24514                          * unspecified and mapped address have a v4 equivalent.
24515                          */
24516 @@ -356,6 +376,9 @@ int inet6_bind(struct socket *sock, stru
24517                 }
24518         }
24519  
24520 +       /* what's that for? */
24521 +       v6_set_sock_addr(inet, &nsa);
24522 +
24523         inet->inet_rcv_saddr = v4addr;
24524         inet->inet_saddr = v4addr;
24525  
24526 @@ -457,9 +480,11 @@ int inet6_getname(struct socket *sock, s
24527                         return -ENOTCONN;
24528                 sin->sin6_port = inet->inet_dport;
24529                 sin->sin6_addr = sk->sk_v6_daddr;
24530 +               /* FIXME: remap lback? */
24531                 if (np->sndflow)
24532                         sin->sin6_flowinfo = np->flow_label;
24533         } else {
24534 +               /* FIXME: remap lback? */
24535                 if (ipv6_addr_any(&sk->sk_v6_rcv_saddr))
24536                         sin->sin6_addr = np->saddr;
24537                 else
24538 diff -NurpP --minimal linux-3.13.10/net/ipv6/datagram.c linux-3.13.10-vs2.3.6.11/net/ipv6/datagram.c
24539 --- linux-3.13.10/net/ipv6/datagram.c   2014-01-22 20:39:15.000000000 +0000
24540 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/datagram.c        2014-01-31 20:38:04.000000000 +0000
24541 @@ -655,7 +655,7 @@ int ip6_datagram_send_ctl(struct net *ne
24542  
24543                         rcu_read_lock();
24544                         if (fl6->flowi6_oif) {
24545 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
24546 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
24547                                 if (!dev) {
24548                                         rcu_read_unlock();
24549                                         return -ENODEV;
24550 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
24551 --- linux-3.13.10/net/ipv6/fib6_rules.c 2014-01-22 20:39:15.000000000 +0000
24552 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/fib6_rules.c      2014-01-31 20:38:04.000000000 +0000
24553 @@ -97,7 +97,7 @@ static int fib6_rule_action(struct fib_r
24554                                                ip6_dst_idev(&rt->dst)->dev,
24555                                                &flp6->daddr,
24556                                                rt6_flags2srcprefs(flags),
24557 -                                              &saddr))
24558 +                                              &saddr, NULL))
24559                                 goto again;
24560                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
24561                                                r->src.plen))
24562 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
24563 --- linux-3.13.10/net/ipv6/inet6_hashtables.c   2014-01-22 20:39:15.000000000 +0000
24564 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/inet6_hashtables.c        2014-01-31 20:38:04.000000000 +0000
24565 @@ -16,6 +16,7 @@
24566  
24567  #include <linux/module.h>
24568  #include <linux/random.h>
24569 +#include <linux/vs_inet6.h>
24570  
24571  #include <net/inet_connection_sock.h>
24572  #include <net/inet_hashtables.h>
24573 @@ -116,7 +117,6 @@ struct sock *__inet6_lookup_established(
24574         unsigned int slot = hash & hashinfo->ehash_mask;
24575         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
24576  
24577 -
24578         rcu_read_lock();
24579  begin:
24580         sk_nulls_for_each_rcu(sk, node, &head->chain) {
24581 @@ -158,6 +158,9 @@ static inline int compute_score(struct s
24582                         if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24583                                 return -1;
24584                         score++;
24585 +               } else {
24586 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24587 +                               return -1;
24588                 }
24589                 if (sk->sk_bound_dev_if) {
24590                         if (sk->sk_bound_dev_if != dif)
24591 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
24592 --- linux-3.13.10/net/ipv6/ip6_fib.c    2014-01-22 20:39:15.000000000 +0000
24593 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_fib.c 2014-01-31 21:48:35.000000000 +0000
24594 @@ -1779,6 +1779,7 @@ static int ipv6_route_seq_show(struct se
24595         struct rt6_info *rt = v;
24596         struct ipv6_route_iter *iter = seq->private;
24597  
24598 +       /* FIXME: check for network context? */
24599         seq_printf(seq, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
24600  
24601  #ifdef CONFIG_IPV6_SUBTREES
24602 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
24603 --- linux-3.13.10/net/ipv6/ip6_output.c 2014-04-17 01:12:41.000000000 +0000
24604 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_output.c      2014-04-17 01:17:11.000000000 +0000
24605 @@ -872,7 +872,8 @@ static int ip6_dst_lookup_tail(struct so
24606                 struct rt6_info *rt = (struct rt6_info *) *dst;
24607                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
24608                                           sk ? inet6_sk(sk)->srcprefs : 0,
24609 -                                         &fl6->saddr);
24610 +                                         &fl6->saddr,
24611 +                                         sk ? sk->sk_nx_info : NULL);
24612                 if (err)
24613                         goto out_err_release;
24614         }
24615 diff -NurpP --minimal linux-3.13.10/net/ipv6/ndisc.c linux-3.13.10-vs2.3.6.11/net/ipv6/ndisc.c
24616 --- linux-3.13.10/net/ipv6/ndisc.c      2014-01-22 20:39:15.000000000 +0000
24617 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ndisc.c   2014-01-31 20:38:04.000000000 +0000
24618 @@ -486,7 +486,7 @@ void ndisc_send_na(struct net_device *de
24619         } else {
24620                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
24621                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
24622 -                                      &tmpaddr))
24623 +                                      &tmpaddr, NULL))
24624                         return;
24625                 src_addr = &tmpaddr;
24626         }
24627 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
24628 --- linux-3.13.10/net/ipv6/netfilter/ip6t_MASQUERADE.c  2013-11-25 15:47:07.000000000 +0000
24629 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/netfilter/ip6t_MASQUERADE.c       2014-01-31 20:38:04.000000000 +0000
24630 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
24631                             ctinfo == IP_CT_RELATED_REPLY));
24632  
24633         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
24634 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
24635 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
24636                 return NF_DROP;
24637  
24638         nfct_nat(ct)->masq_index = par->out->ifindex;
24639 diff -NurpP --minimal linux-3.13.10/net/ipv6/raw.c linux-3.13.10-vs2.3.6.11/net/ipv6/raw.c
24640 --- linux-3.13.10/net/ipv6/raw.c        2014-01-22 20:39:15.000000000 +0000
24641 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/raw.c     2014-01-31 20:38:04.000000000 +0000
24642 @@ -30,6 +30,7 @@
24643  #include <linux/icmpv6.h>
24644  #include <linux/netfilter.h>
24645  #include <linux/netfilter_ipv6.h>
24646 +#include <linux/vs_inet6.h>
24647  #include <linux/skbuff.h>
24648  #include <linux/compat.h>
24649  #include <asm/uaccess.h>
24650 @@ -287,6 +288,13 @@ static int rawv6_bind(struct sock *sk, s
24651                                 goto out_unlock;
24652                 }
24653  
24654 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24655 +                       err = -EADDRNOTAVAIL;
24656 +                       if (dev)
24657 +                               dev_put(dev);
24658 +                       goto out;
24659 +               }
24660 +
24661                 /* ipv4 addr of the socket is invalid.  Only the
24662                  * unspecified and mapped address have a v4 equivalent.
24663                  */
24664 diff -NurpP --minimal linux-3.13.10/net/ipv6/route.c linux-3.13.10-vs2.3.6.11/net/ipv6/route.c
24665 --- linux-3.13.10/net/ipv6/route.c      2014-04-17 01:12:41.000000000 +0000
24666 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/route.c   2014-04-17 01:17:11.000000000 +0000
24667 @@ -58,6 +58,7 @@
24668  #include <net/netevent.h>
24669  #include <net/netlink.h>
24670  #include <net/nexthop.h>
24671 +#include <linux/vs_inet6.h>
24672  
24673  #include <asm/uaccess.h>
24674  
24675 @@ -2196,15 +2197,17 @@ int ip6_route_get_saddr(struct net *net,
24676                         struct rt6_info *rt,
24677                         const struct in6_addr *daddr,
24678                         unsigned int prefs,
24679 -                       struct in6_addr *saddr)
24680 +                       struct in6_addr *saddr,
24681 +                       struct nx_info *nxi)
24682  {
24683         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
24684         int err = 0;
24685 -       if (rt->rt6i_prefsrc.plen)
24686 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
24687 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
24688                 *saddr = rt->rt6i_prefsrc.addr;
24689         else
24690                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
24691 -                                        daddr, prefs, saddr);
24692 +                                        daddr, prefs, saddr, nxi);
24693         return err;
24694  }
24695  
24696 @@ -2624,7 +2627,8 @@ static int rt6_fill_node(struct net *net
24697                                 goto nla_put_failure;
24698         } else if (dst) {
24699                 struct in6_addr saddr_buf;
24700 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
24701 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
24702 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
24703                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
24704                         goto nla_put_failure;
24705         }
24706 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
24707 --- linux-3.13.10/net/ipv6/tcp_ipv6.c   2014-01-22 20:39:15.000000000 +0000
24708 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/tcp_ipv6.c        2014-01-31 20:38:04.000000000 +0000
24709 @@ -72,6 +72,7 @@
24710  
24711  #include <linux/crypto.h>
24712  #include <linux/scatterlist.h>
24713 +#include <linux/vs_inet6.h>
24714  
24715  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
24716  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
24717 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
24718          *      connect() to INADDR_ANY means loopback (BSD'ism).
24719          */
24720  
24721 -       if(ipv6_addr_any(&usin->sin6_addr))
24722 -               usin->sin6_addr.s6_addr[15] = 0x1;
24723 +       if(ipv6_addr_any(&usin->sin6_addr)) {
24724 +               struct nx_info *nxi =  sk->sk_nx_info;
24725 +
24726 +               if (nxi && nx_info_has_v6(nxi))
24727 +                       /* FIXME: remap lback? */
24728 +                       usin->sin6_addr = nxi->v6.ip;
24729 +               else
24730 +                       usin->sin6_addr.s6_addr[15] = 0x1;
24731 +       }
24732  
24733         addr_type = ipv6_addr_type(&usin->sin6_addr);
24734  
24735 diff -NurpP --minimal linux-3.13.10/net/ipv6/udp.c linux-3.13.10-vs2.3.6.11/net/ipv6/udp.c
24736 --- linux-3.13.10/net/ipv6/udp.c        2014-01-22 20:39:15.000000000 +0000
24737 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/udp.c     2014-02-01 02:33:38.000000000 +0000
24738 @@ -47,6 +47,7 @@
24739  #include <net/xfrm.h>
24740  #include <net/inet6_hashtables.h>
24741  #include <net/busy_poll.h>
24742 +#include <linux/vs_inet6.h>
24743  
24744  #include <linux/proc_fs.h>
24745  #include <linux/seq_file.h>
24746 @@ -76,33 +77,61 @@ static unsigned int udp6_ehashfn(struct
24747                                udp_ipv6_hash_secret + net_hash_mix(net));
24748  }
24749  
24750 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
24751 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24752  {
24753 +       const struct in6_addr *sk1_rcv_saddr6 = inet6_rcv_saddr(sk1);
24754         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
24755 -       int sk_ipv6only = ipv6_only_sock(sk);
24756 +       __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr;
24757 +       __be32 sk2_rcv_saddr = sk2->sk_rcv_saddr;
24758 +       int sk1_ipv6only = ipv6_only_sock(sk1);
24759         int sk2_ipv6only = inet_v6_ipv6only(sk2);
24760 -       int addr_type = ipv6_addr_type(&sk->sk_v6_rcv_saddr);
24761 +       int addr_type1 = ipv6_addr_type(sk1_rcv_saddr6);
24762         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
24763  
24764         /* if both are mapped, treat as IPv4 */
24765 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
24766 -               return (!sk2_ipv6only &&
24767 -                       (!sk->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24768 -                         sk->sk_rcv_saddr == sk2->sk_rcv_saddr));
24769 +       if (addr_type1 == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
24770 +               if (!sk2_ipv6only &&
24771 +                       (!sk1->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24772 +                         sk1->sk_rcv_saddr == sk2->sk_rcv_saddr))
24773 +                       goto vs_v4;
24774 +               else
24775 +                       return 0;
24776 +       }
24777  
24778         if (addr_type2 == IPV6_ADDR_ANY &&
24779 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
24780 -               return 1;
24781 +           !(sk2_ipv6only && addr_type1 == IPV6_ADDR_MAPPED))
24782 +               goto vs;
24783  
24784 -       if (addr_type == IPV6_ADDR_ANY &&
24785 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24786 -               return 1;
24787 +       if (addr_type1 == IPV6_ADDR_ANY &&
24788 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24789 +               goto vs;
24790  
24791         if (sk2_rcv_saddr6 &&
24792 -           ipv6_addr_equal(&sk->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24793 -               return 1;
24794 +           ipv6_addr_equal(&sk1->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24795 +               goto vs;
24796  
24797         return 0;
24798 +
24799 +vs_v4:
24800 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
24801 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24802 +       if (!sk2_rcv_saddr)
24803 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
24804 +       if (!sk1_rcv_saddr)
24805 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
24806 +       return 1;
24807 +vs:
24808 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type1 == IPV6_ADDR_ANY)
24809 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24810 +       else if (addr_type2 == IPV6_ADDR_ANY)
24811 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
24812 +       else if (addr_type1 == IPV6_ADDR_ANY) {
24813 +               if (addr_type2 == IPV6_ADDR_MAPPED)
24814 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24815 +               else
24816 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
24817 +       }
24818 +       return 1;
24819  }
24820  
24821  static unsigned int udp6_portaddr_hash(struct net *net,
24822 @@ -160,6 +189,10 @@ static inline int compute_score(struct s
24823                         if (inet->inet_dport != sport)
24824                                 return -1;
24825                         score++;
24826 +               } else {
24827 +                       /* block non nx_info ips */
24828 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24829 +                               return -1;
24830                 }
24831                 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
24832                         if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24833 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
24834 --- linux-3.13.10/net/ipv6/xfrm6_policy.c       2014-01-22 20:39:15.000000000 +0000
24835 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/xfrm6_policy.c    2014-01-31 20:38:04.000000000 +0000
24836 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
24837         dev = ip6_dst_idev(dst)->dev;
24838         ipv6_dev_get_saddr(dev_net(dev), dev,
24839                            (struct in6_addr *)&daddr->a6, 0,
24840 -                          (struct in6_addr *)&saddr->a6);
24841 +                          (struct in6_addr *)&saddr->a6, NULL);
24842         dst_release(dst);
24843         return 0;
24844  }
24845 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
24846 --- linux-3.13.10/net/netfilter/ipvs/ip_vs_xmit.c       2013-11-25 15:47:07.000000000 +0000
24847 +++ linux-3.13.10-vs2.3.6.11/net/netfilter/ipvs/ip_vs_xmit.c    2014-01-31 20:38:04.000000000 +0000
24848 @@ -316,7 +316,7 @@ __ip_vs_route_output_v6(struct net *net,
24849                 return dst;
24850         if (ipv6_addr_any(&fl6.saddr) &&
24851             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
24852 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
24853 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
24854                 goto out_err;
24855         if (do_xfrm) {
24856                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
24857 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
24858 --- linux-3.13.10/net/netlink/af_netlink.c      2014-01-22 20:39:16.000000000 +0000
24859 +++ linux-3.13.10-vs2.3.6.11/net/netlink/af_netlink.c   2014-02-25 11:47:07.000000000 +0000
24860 @@ -58,6 +58,9 @@
24861  #include <linux/mutex.h>
24862  #include <linux/vmalloc.h>
24863  #include <linux/if_arp.h>
24864 +#include <linux/vs_context.h>
24865 +#include <linux/vs_network.h>
24866 +#include <linux/vs_limit.h>
24867  #include <asm/cacheflush.h>
24868  
24869  #include <net/net_namespace.h>
24870 @@ -2850,6 +2853,8 @@ static struct sock *netlink_seq_socket_i
24871                         sk_for_each(s, &hash->table[j]) {
24872                                 if (sock_net(s) != seq_file_net(seq))
24873                                         continue;
24874 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
24875 +                                       continue;
24876                                 if (off == pos) {
24877                                         iter->link = i;
24878                                         iter->hash_idx = j;
24879 @@ -2886,7 +2891,8 @@ static void *netlink_seq_next(struct seq
24880         s = v;
24881         do {
24882                 s = sk_next(s);
24883 -       } while (s && !nl_table[s->sk_protocol].compare(net, s));
24884 +       } while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24885 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
24886         if (s)
24887                 return s;
24888  
24889 @@ -2899,7 +2905,8 @@ static void *netlink_seq_next(struct seq
24890                 for (; j <= hash->mask; j++) {
24891                         s = sk_head(&hash->table[j]);
24892  
24893 -                       while (s && !nl_table[s->sk_protocol].compare(net, s))
24894 +                       while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24895 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
24896                                 s = sk_next(s);
24897                         if (s) {
24898                                 iter->link = i;
24899 diff -NurpP --minimal linux-3.13.10/net/socket.c linux-3.13.10-vs2.3.6.11/net/socket.c
24900 --- linux-3.13.10/net/socket.c  2014-04-17 01:12:42.000000000 +0000
24901 +++ linux-3.13.10-vs2.3.6.11/net/socket.c       2014-04-17 01:17:11.000000000 +0000
24902 @@ -98,6 +98,9 @@
24903  
24904  #include <net/sock.h>
24905  #include <linux/netfilter.h>
24906 +#include <linux/vs_socket.h>
24907 +#include <linux/vs_inet.h>
24908 +#include <linux/vs_inet6.h>
24909  
24910  #include <linux/if_tun.h>
24911  #include <linux/ipv6_route.h>
24912 @@ -623,13 +626,29 @@ static inline int __sock_sendmsg_nosec(s
24913                                        struct msghdr *msg, size_t size)
24914  {
24915         struct sock_iocb *si = kiocb_to_siocb(iocb);
24916 +       size_t len;
24917  
24918         si->sock = sock;
24919         si->scm = NULL;
24920         si->msg = msg;
24921         si->size = size;
24922  
24923 -       return sock->ops->sendmsg(iocb, sock, msg, size);
24924 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
24925 +       if (sock->sk) {
24926 +               if (len == size)
24927 +                       vx_sock_send(sock->sk, size);
24928 +               else
24929 +                       vx_sock_fail(sock->sk, size);
24930 +       }
24931 +       vxdprintk(VXD_CBIT(net, 7),
24932 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
24933 +               sock, sock->sk,
24934 +               (sock->sk)?sock->sk->sk_nx_info:0,
24935 +               (sock->sk)?sock->sk->sk_vx_info:0,
24936 +               (sock->sk)?sock->sk->sk_xid:0,
24937 +               (sock->sk)?sock->sk->sk_nid:0,
24938 +               (unsigned int)size, len);
24939 +       return len;
24940  }
24941  
24942  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
24943 @@ -773,6 +792,7 @@ static inline int __sock_recvmsg_nosec(s
24944                                        struct msghdr *msg, size_t size, int flags)
24945  {
24946         struct sock_iocb *si = kiocb_to_siocb(iocb);
24947 +       int len;
24948  
24949         si->sock = sock;
24950         si->scm = NULL;
24951 @@ -780,7 +800,18 @@ static inline int __sock_recvmsg_nosec(s
24952         si->size = size;
24953         si->flags = flags;
24954  
24955 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
24956 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
24957 +       if ((len >= 0) && sock->sk)
24958 +               vx_sock_recv(sock->sk, len);
24959 +       vxdprintk(VXD_CBIT(net, 7),
24960 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
24961 +               sock, sock->sk,
24962 +               (sock->sk)?sock->sk->sk_nx_info:0,
24963 +               (sock->sk)?sock->sk->sk_vx_info:0,
24964 +               (sock->sk)?sock->sk->sk_xid:0,
24965 +               (sock->sk)?sock->sk->sk_nid:0,
24966 +               (unsigned int)size, len);
24967 +       return len;
24968  }
24969  
24970  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
24971 @@ -1256,6 +1287,13 @@ int __sock_create(struct net *net, int f
24972         if (type < 0 || type >= SOCK_MAX)
24973                 return -EINVAL;
24974  
24975 +       if (!nx_check(0, VS_ADMIN)) {
24976 +               if (family == PF_INET && !current_nx_info_has_v4())
24977 +                       return -EAFNOSUPPORT;
24978 +               if (family == PF_INET6 && !current_nx_info_has_v6())
24979 +                       return -EAFNOSUPPORT;
24980 +       }
24981 +
24982         /* Compatibility.
24983  
24984            This uglymoron is moved from INET layer to here to avoid
24985 @@ -1390,6 +1428,7 @@ SYSCALL_DEFINE3(socket, int, family, int
24986         if (retval < 0)
24987                 goto out;
24988  
24989 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
24990         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
24991         if (retval < 0)
24992                 goto out_release;
24993 @@ -1431,10 +1470,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
24994         err = sock_create(family, type, protocol, &sock1);
24995         if (err < 0)
24996                 goto out;
24997 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
24998  
24999         err = sock_create(family, type, protocol, &sock2);
25000         if (err < 0)
25001                 goto out_release_1;
25002 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25003  
25004         err = sock1->ops->socketpair(sock1, sock2);
25005         if (err < 0)
25006 diff -NurpP --minimal linux-3.13.10/net/sunrpc/auth.c linux-3.13.10-vs2.3.6.11/net/sunrpc/auth.c
25007 --- linux-3.13.10/net/sunrpc/auth.c     2013-11-25 15:47:08.000000000 +0000
25008 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/auth.c  2014-01-31 20:38:04.000000000 +0000
25009 @@ -15,6 +15,7 @@
25010  #include <linux/sunrpc/clnt.h>
25011  #include <linux/sunrpc/gss_api.h>
25012  #include <linux/spinlock.h>
25013 +#include <linux/vs_tag.h>
25014  
25015  #ifdef RPC_DEBUG
25016  # define RPCDBG_FACILITY       RPCDBG_AUTH
25017 @@ -586,6 +587,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25018         memset(&acred, 0, sizeof(acred));
25019         acred.uid = cred->fsuid;
25020         acred.gid = cred->fsgid;
25021 +       acred.tag = make_ktag(&init_user_ns, dx_current_tag());
25022         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25023  
25024         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25025 @@ -626,6 +628,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25026         struct auth_cred acred = {
25027                 .uid = GLOBAL_ROOT_UID,
25028                 .gid = GLOBAL_ROOT_GID,
25029 +               .tag = KTAGT_INIT(dx_current_tag()),
25030         };
25031  
25032         dprintk("RPC: %5u looking up %s cred\n",
25033 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
25034 --- linux-3.13.10/net/sunrpc/auth_unix.c        2013-11-25 15:47:08.000000000 +0000
25035 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/auth_unix.c     2014-01-31 20:38:04.000000000 +0000
25036 @@ -13,11 +13,13 @@
25037  #include <linux/sunrpc/clnt.h>
25038  #include <linux/sunrpc/auth.h>
25039  #include <linux/user_namespace.h>
25040 +#include <linux/vs_tag.h>
25041  
25042  #define NFS_NGROUPS    16
25043  
25044  struct unx_cred {
25045         struct rpc_cred         uc_base;
25046 +       ktag_t                  uc_tag;
25047         kgid_t                  uc_gid;
25048         kgid_t                  uc_gids[NFS_NGROUPS];
25049  };
25050 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25051                 groups = NFS_NGROUPS;
25052  
25053         cred->uc_gid = acred->gid;
25054 +       cred->uc_tag = acred->tag;
25055         for (i = 0; i < groups; i++)
25056                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25057         if (i < NFS_NGROUPS)
25058 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25059         unsigned int i;
25060  
25061  
25062 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25063 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
25064 +           !gid_eq(cred->uc_gid, acred->gid) ||
25065 +           !tag_eq(cred->uc_tag, acred->tag))
25066                 return 0;
25067  
25068         if (acred->group_info != NULL)
25069 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25070         struct rpc_clnt *clnt = task->tk_client;
25071         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25072         __be32          *base, *hold;
25073 -       int             i;
25074 +       int             i, tag;
25075  
25076         *p++ = htonl(RPC_AUTH_UNIX);
25077         base = p++;
25078 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
25079          */
25080         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25081  
25082 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25083 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25084 +       tag = task->tk_client->cl_tag;
25085 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
25086 +               TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
25087 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
25088 +               TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
25089         hold = p++;
25090         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25091                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25092 diff -NurpP --minimal linux-3.13.10/net/sunrpc/clnt.c linux-3.13.10-vs2.3.6.11/net/sunrpc/clnt.c
25093 --- linux-3.13.10/net/sunrpc/clnt.c     2014-04-17 01:12:42.000000000 +0000
25094 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/clnt.c  2014-02-25 11:26:10.000000000 +0000
25095 @@ -31,6 +31,7 @@
25096  #include <linux/in.h>
25097  #include <linux/in6.h>
25098  #include <linux/un.h>
25099 +#include <linux/vs_cvirt.h>
25100  
25101  #include <linux/sunrpc/clnt.h>
25102  #include <linux/sunrpc/addr.h>
25103 @@ -538,6 +539,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25104         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25105                 clnt->cl_chatty = 1;
25106  
25107 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25108 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25109 +               clnt->cl_tag = 1; */
25110         return clnt;
25111  }
25112  EXPORT_SYMBOL_GPL(rpc_create);
25113 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
25114 --- linux-3.13.10/net/unix/af_unix.c    2014-04-17 01:12:42.000000000 +0000
25115 +++ linux-3.13.10-vs2.3.6.11/net/unix/af_unix.c 2014-04-17 01:17:11.000000000 +0000
25116 @@ -115,6 +115,8 @@
25117  #include <net/checksum.h>
25118  #include <linux/security.h>
25119  #include <linux/freezer.h>
25120 +#include <linux/vs_context.h>
25121 +#include <linux/vs_limit.h>
25122  
25123  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25124  EXPORT_SYMBOL_GPL(unix_socket_table);
25125 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25126                 if (!net_eq(sock_net(s), net))
25127                         continue;
25128  
25129 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25130 +                       continue;
25131                 if (u->addr->len == len &&
25132                     !memcmp(u->addr->name, sunname, len))
25133                         goto found;
25134 @@ -2275,6 +2279,8 @@ static struct sock *unix_from_bucket(str
25135         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25136                 if (sock_net(sk) != seq_file_net(seq))
25137                         continue;
25138 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25139 +                       continue;
25140                 if (++count == offset)
25141                         break;
25142         }
25143 @@ -2292,6 +2298,8 @@ static struct sock *unix_next_socket(str
25144                 sk = sk_next(sk);
25145                 if (!sk)
25146                         goto next_bucket;
25147 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25148 +                       continue;
25149                 if (sock_net(sk) == seq_file_net(seq))
25150                         return sk;
25151         }
25152 diff -NurpP --minimal linux-3.13.10/scripts/checksyscalls.sh linux-3.13.10-vs2.3.6.11/scripts/checksyscalls.sh
25153 --- linux-3.13.10/scripts/checksyscalls.sh      2012-12-11 03:30:57.000000000 +0000
25154 +++ linux-3.13.10-vs2.3.6.11/scripts/checksyscalls.sh   2014-01-31 20:38:04.000000000 +0000
25155 @@ -193,7 +193,6 @@ cat << EOF
25156  #define __IGNORE_afs_syscall
25157  #define __IGNORE_getpmsg
25158  #define __IGNORE_putpmsg
25159 -#define __IGNORE_vserver
25160  EOF
25161  }
25162  
25163 diff -NurpP --minimal linux-3.13.10/security/commoncap.c linux-3.13.10-vs2.3.6.11/security/commoncap.c
25164 --- linux-3.13.10/security/commoncap.c  2013-11-25 15:47:08.000000000 +0000
25165 +++ linux-3.13.10-vs2.3.6.11/security/commoncap.c       2014-01-31 20:38:04.000000000 +0000
25166 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25167  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25168                 int cap, int audit)
25169  {
25170 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25171         struct user_namespace *ns = targ_ns;
25172  
25173         /* See if cred has the capability in the target user namespace
25174 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25175          */
25176         for (;;) {
25177                 /* Do we have the necessary capabilities? */
25178 -               if (ns == cred->user_ns)
25179 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25180 +               if (ns == cred->user_ns) {
25181 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25182 +                           cap_raised(cred->cap_effective, cap))
25183 +                               return 0;
25184 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25185 +               }
25186  
25187                 /* Have we tried all of the parent namespaces? */
25188                 if (ns == &init_user_ns)
25189 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25190  
25191         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25192                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25193 -           !capable(CAP_SYS_ADMIN))
25194 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25195                 return -EPERM;
25196         return 0;
25197  }
25198 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25199  
25200         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25201                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25202 -           !capable(CAP_SYS_ADMIN))
25203 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25204                 return -EPERM;
25205         return 0;
25206  }
25207 diff -NurpP --minimal linux-3.13.10/security/selinux/hooks.c linux-3.13.10-vs2.3.6.11/security/selinux/hooks.c
25208 --- linux-3.13.10/security/selinux/hooks.c      2014-04-17 01:12:42.000000000 +0000
25209 +++ linux-3.13.10-vs2.3.6.11/security/selinux/hooks.c   2014-04-17 01:17:11.000000000 +0000
25210 @@ -68,7 +68,6 @@
25211  #include <linux/dccp.h>
25212  #include <linux/quota.h>
25213  #include <linux/un.h>          /* for Unix socket types */
25214 -#include <net/af_unix.h>       /* for Unix socket types */
25215  #include <linux/parser.h>
25216  #include <linux/nfs_mount.h>
25217  #include <net/ipv6.h>
This page took 2.430359 seconds and 3 git commands to generate.