]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- fix NULL pointer dereference in netlink_seq_next
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.13.1/Documentation/vserver/debug.txt linux-3.13.1-vs2.3.6.10/Documentation/vserver/debug.txt
2 --- linux-3.13.1/Documentation/vserver/debug.txt        1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/alpha/Kconfig linux-3.13.1-vs2.3.6.10/arch/alpha/Kconfig
160 --- linux-3.13.1/arch/alpha/Kconfig     2014-01-22 20:38:09.000000000 +0000
161 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/alpha/kernel/systbls.S linux-3.13.1-vs2.3.6.10/arch/alpha/kernel/systbls.S
172 --- linux-3.13.1/arch/alpha/kernel/systbls.S    2013-11-25 15:44:11.000000000 +0000
173 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/alpha/kernel/traps.c linux-3.13.1-vs2.3.6.10/arch/alpha/kernel/traps.c
184 --- linux-3.13.1/arch/alpha/kernel/traps.c      2014-01-22 20:38:10.000000000 +0000
185 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/arm/Kconfig linux-3.13.1-vs2.3.6.10/arch/arm/Kconfig
197 --- linux-3.13.1/arch/arm/Kconfig       2014-01-22 20:38:10.000000000 +0000
198 +++ linux-3.13.1-vs2.3.6.10/arch/arm/Kconfig    2014-01-31 20:38:03.000000000 +0000
199 @@ -2265,6 +2265,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.1/arch/arm/kernel/calls.S linux-3.13.1-vs2.3.6.10/arch/arm/kernel/calls.S
209 --- linux-3.13.1/arch/arm/kernel/calls.S        2013-05-31 13:44:29.000000000 +0000
210 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/arm/kernel/traps.c linux-3.13.1-vs2.3.6.10/arch/arm/kernel/traps.c
221 --- linux-3.13.1/arch/arm/kernel/traps.c        2014-01-22 20:38:11.000000000 +0000
222 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/cris/Kconfig linux-3.13.1-vs2.3.6.10/arch/cris/Kconfig
235 --- linux-3.13.1/arch/cris/Kconfig      2014-01-22 20:38:15.000000000 +0000
236 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/ia64/Kconfig linux-3.13.1-vs2.3.6.10/arch/ia64/Kconfig
247 --- linux-3.13.1/arch/ia64/Kconfig      2014-01-22 20:38:16.000000000 +0000
248 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/ia64/kernel/entry.S linux-3.13.1-vs2.3.6.10/arch/ia64/kernel/entry.S
259 --- linux-3.13.1/arch/ia64/kernel/entry.S       2014-01-22 20:38:16.000000000 +0000
260 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/ia64/kernel/ptrace.c linux-3.13.1-vs2.3.6.10/arch/ia64/kernel/ptrace.c
271 --- linux-3.13.1/arch/ia64/kernel/ptrace.c      2013-02-19 13:56:51.000000000 +0000
272 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/ia64/kernel/traps.c linux-3.13.1-vs2.3.6.10/arch/ia64/kernel/traps.c
282 --- linux-3.13.1/arch/ia64/kernel/traps.c       2013-11-25 15:44:20.000000000 +0000
283 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/m32r/kernel/traps.c linux-3.13.1-vs2.3.6.10/arch/m32r/kernel/traps.c
309 --- linux-3.13.1/arch/m32r/kernel/traps.c       2013-07-14 17:00:26.000000000 +0000
310 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/m68k/Kconfig linux-3.13.1-vs2.3.6.10/arch/m68k/Kconfig
324 --- linux-3.13.1/arch/m68k/Kconfig      2014-01-22 20:38:16.000000000 +0000
325 +++ linux-3.13.1-vs2.3.6.10/arch/m68k/Kconfig   2014-01-31 20:38:03.000000000 +0000
326 @@ -134,6 +134,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.1/arch/mips/Kconfig linux-3.13.1-vs2.3.6.10/arch/mips/Kconfig
336 --- linux-3.13.1/arch/mips/Kconfig      2014-01-22 20:38:16.000000000 +0000
337 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/mips/kernel/ptrace.c linux-3.13.1-vs2.3.6.10/arch/mips/kernel/ptrace.c
348 --- linux-3.13.1/arch/mips/kernel/ptrace.c      2014-01-22 20:38:17.000000000 +0000
349 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/mips/kernel/scall32-o32.S linux-3.13.1-vs2.3.6.10/arch/mips/kernel/scall32-o32.S
369 --- linux-3.13.1/arch/mips/kernel/scall32-o32.S 2014-01-22 20:38:17.000000000 +0000
370 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/mips/kernel/scall64-64.S linux-3.13.1-vs2.3.6.10/arch/mips/kernel/scall64-64.S
381 --- linux-3.13.1/arch/mips/kernel/scall64-64.S  2014-01-22 20:38:17.000000000 +0000
382 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/mips/kernel/scall64-n32.S linux-3.13.1-vs2.3.6.10/arch/mips/kernel/scall64-n32.S
393 --- linux-3.13.1/arch/mips/kernel/scall64-n32.S 2014-01-22 20:38:17.000000000 +0000
394 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/mips/kernel/scall64-o32.S linux-3.13.1-vs2.3.6.10/arch/mips/kernel/scall64-o32.S
405 --- linux-3.13.1/arch/mips/kernel/scall64-o32.S 2014-01-22 20:38:17.000000000 +0000
406 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/mips/kernel/traps.c linux-3.13.1-vs2.3.6.10/arch/mips/kernel/traps.c
417 --- linux-3.13.1/arch/mips/kernel/traps.c       2014-01-22 20:38:17.000000000 +0000
418 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/parisc/Kconfig linux-3.13.1-vs2.3.6.10/arch/parisc/Kconfig
434 --- linux-3.13.1/arch/parisc/Kconfig    2014-01-22 20:38:18.000000000 +0000
435 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/parisc/kernel/syscall_table.S linux-3.13.1-vs2.3.6.10/arch/parisc/kernel/syscall_table.S
446 --- linux-3.13.1/arch/parisc/kernel/syscall_table.S     2013-07-14 17:00:31.000000000 +0000
447 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/parisc/kernel/traps.c linux-3.13.1-vs2.3.6.10/arch/parisc/kernel/traps.c
458 --- linux-3.13.1/arch/parisc/kernel/traps.c     2013-11-25 15:46:28.000000000 +0000
459 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/parisc/mm/fault.c linux-3.13.1-vs2.3.6.10/arch/parisc/mm/fault.c
484 --- linux-3.13.1/arch/parisc/mm/fault.c 2014-01-22 20:38:18.000000000 +0000
485 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/powerpc/Kconfig linux-3.13.1-vs2.3.6.10/arch/powerpc/Kconfig
499 --- linux-3.13.1/arch/powerpc/Kconfig   2014-01-22 20:38:18.000000000 +0000
500 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/powerpc/include/uapi/asm/unistd.h linux-3.13.1-vs2.3.6.10/arch/powerpc/include/uapi/asm/unistd.h
511 --- linux-3.13.1/arch/powerpc/include/uapi/asm/unistd.h 2013-05-31 13:44:44.000000000 +0000
512 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/powerpc/kernel/traps.c linux-3.13.1-vs2.3.6.10/arch/powerpc/kernel/traps.c
523 --- linux-3.13.1/arch/powerpc/kernel/traps.c    2014-01-22 20:38:23.000000000 +0000
524 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/s390/Kconfig linux-3.13.1-vs2.3.6.10/arch/s390/Kconfig
538 --- linux-3.13.1/arch/s390/Kconfig      2014-01-22 20:38:24.000000000 +0000
539 +++ linux-3.13.1-vs2.3.6.10/arch/s390/Kconfig   2014-01-31 20:38:03.000000000 +0000
540 @@ -649,6 +649,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.1/arch/s390/include/asm/tlb.h linux-3.13.1-vs2.3.6.10/arch/s390/include/asm/tlb.h
550 --- linux-3.13.1/arch/s390/include/asm/tlb.h    2013-11-25 15:46:29.000000000 +0000
551 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/s390/include/uapi/asm/unistd.h linux-3.13.1-vs2.3.6.10/arch/s390/include/uapi/asm/unistd.h
561 --- linux-3.13.1/arch/s390/include/uapi/asm/unistd.h    2013-02-19 13:57:16.000000000 +0000
562 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/s390/kernel/ptrace.c linux-3.13.1-vs2.3.6.10/arch/s390/kernel/ptrace.c
573 --- linux-3.13.1/arch/s390/kernel/ptrace.c      2014-01-22 20:38:24.000000000 +0000
574 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/s390/kernel/syscalls.S linux-3.13.1-vs2.3.6.10/arch/s390/kernel/syscalls.S
584 --- linux-3.13.1/arch/s390/kernel/syscalls.S    2013-07-14 17:00:34.000000000 +0000
585 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/sh/Kconfig linux-3.13.1-vs2.3.6.10/arch/sh/Kconfig
596 --- linux-3.13.1/arch/sh/Kconfig        2014-01-22 20:38:24.000000000 +0000
597 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/sh/kernel/irq.c linux-3.13.1-vs2.3.6.10/arch/sh/kernel/irq.c
608 --- linux-3.13.1/arch/sh/kernel/irq.c   2014-01-22 20:38:24.000000000 +0000
609 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/sparc/Kconfig linux-3.13.1-vs2.3.6.10/arch/sparc/Kconfig
619 --- linux-3.13.1/arch/sparc/Kconfig     2014-01-22 20:38:24.000000000 +0000
620 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/sparc/include/uapi/asm/unistd.h linux-3.13.1-vs2.3.6.10/arch/sparc/include/uapi/asm/unistd.h
631 --- linux-3.13.1/arch/sparc/include/uapi/asm/unistd.h   2013-02-19 13:57:17.000000000 +0000
632 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/sparc/kernel/systbls_32.S linux-3.13.1-vs2.3.6.10/arch/sparc/kernel/systbls_32.S
643 --- linux-3.13.1/arch/sparc/kernel/systbls_32.S 2013-05-31 13:44:48.000000000 +0000
644 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/sparc/kernel/systbls_64.S linux-3.13.1-vs2.3.6.10/arch/sparc/kernel/systbls_64.S
655 --- linux-3.13.1/arch/sparc/kernel/systbls_64.S 2013-07-14 17:00:35.000000000 +0000
656 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/um/Kconfig.rest linux-3.13.1-vs2.3.6.10/arch/um/Kconfig.rest
676 --- linux-3.13.1/arch/um/Kconfig.rest   2012-12-11 03:30:57.000000000 +0000
677 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/x86/Kconfig linux-3.13.1-vs2.3.6.10/arch/x86/Kconfig
688 --- linux-3.13.1/arch/x86/Kconfig       2014-01-22 20:38:25.000000000 +0000
689 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/x86/syscalls/syscall_32.tbl linux-3.13.1-vs2.3.6.10/arch/x86/syscalls/syscall_32.tbl
700 --- linux-3.13.1/arch/x86/syscalls/syscall_32.tbl       2013-07-14 17:00:37.000000000 +0000
701 +++ linux-3.13.1-vs2.3.6.10/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.1/arch/x86/syscalls/syscall_64.tbl linux-3.13.1-vs2.3.6.10/arch/x86/syscalls/syscall_64.tbl
712 --- linux-3.13.1/arch/x86/syscalls/syscall_64.tbl       2013-05-31 13:44:50.000000000 +0000
713 +++ linux-3.13.1-vs2.3.6.10/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.1/drivers/block/Kconfig linux-3.13.1-vs2.3.6.10/drivers/block/Kconfig
724 --- linux-3.13.1/drivers/block/Kconfig  2014-01-22 20:38:27.000000000 +0000
725 +++ linux-3.13.1-vs2.3.6.10/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.1/drivers/block/Makefile linux-3.13.1-vs2.3.6.10/drivers/block/Makefile
741 --- linux-3.13.1/drivers/block/Makefile 2014-01-22 20:38:27.000000000 +0000
742 +++ linux-3.13.1-vs2.3.6.10/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.1/drivers/block/loop.c linux-3.13.1-vs2.3.6.10/drivers/block/loop.c
752 --- linux-3.13.1/drivers/block/loop.c   2014-01-22 20:38:27.000000000 +0000
753 +++ linux-3.13.1-vs2.3.6.10/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.1/drivers/block/loop.h linux-3.13.1-vs2.3.6.10/drivers/block/loop.h
810 --- linux-3.13.1/drivers/block/loop.h   2013-11-25 15:44:28.000000000 +0000
811 +++ linux-3.13.1-vs2.3.6.10/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.1/drivers/block/vroot.c linux-3.13.1-vs2.3.6.10/drivers/block/vroot.c
821 --- linux-3.13.1/drivers/block/vroot.c  1970-01-01 00:00:00.000000000 +0000
822 +++ linux-3.13.1-vs2.3.6.10/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.1/drivers/infiniband/Kconfig linux-3.13.1-vs2.3.6.10/drivers/infiniband/Kconfig
1115 --- linux-3.13.1/drivers/infiniband/Kconfig     2014-01-22 20:38:35.000000000 +0000
1116 +++ linux-3.13.1-vs2.3.6.10/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.1/drivers/infiniband/core/addr.c linux-3.13.1-vs2.3.6.10/drivers/infiniband/core/addr.c
1127 --- linux-3.13.1/drivers/infiniband/core/addr.c 2013-11-25 15:44:35.000000000 +0000
1128 +++ linux-3.13.1-vs2.3.6.10/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.1/drivers/md/dm-ioctl.c linux-3.13.1-vs2.3.6.10/drivers/md/dm-ioctl.c
1139 --- linux-3.13.1/drivers/md/dm-ioctl.c  2014-01-22 20:38:36.000000000 +0000
1140 +++ linux-3.13.1-vs2.3.6.10/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.1/drivers/md/dm.c linux-3.13.1-vs2.3.6.10/drivers/md/dm.c
1227 --- linux-3.13.1/drivers/md/dm.c        2014-01-22 20:38:36.000000000 +0000
1228 +++ linux-3.13.1-vs2.3.6.10/drivers/md/dm.c     2014-01-31 20:38:03.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.1/drivers/md/dm.h linux-3.13.1-vs2.3.6.10/drivers/md/dm.h
1303 --- linux-3.13.1/drivers/md/dm.h        2014-01-22 20:38:36.000000000 +0000
1304 +++ linux-3.13.1-vs2.3.6.10/drivers/md/dm.h     2014-01-31 20:38:03.000000000 +0000
1305 @@ -48,6 +48,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.1/drivers/net/tun.c linux-3.13.1-vs2.3.6.10/drivers/net/tun.c
1315 --- linux-3.13.1/drivers/net/tun.c      2014-01-22 20:38:45.000000000 +0000
1316 +++ linux-3.13.1-vs2.3.6.10/drivers/net/tun.c   2014-01-31 20:38:03.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 @@ -1967,6 +1971,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.1/drivers/tty/sysrq.c linux-3.13.1-vs2.3.6.10/drivers/tty/sysrq.c
1376 --- linux-3.13.1/drivers/tty/sysrq.c    2014-01-22 20:39:02.000000000 +0000
1377 +++ linux-3.13.1-vs2.3.6.10/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.1/drivers/tty/tty_io.c linux-3.13.1-vs2.3.6.10/drivers/tty/tty_io.c
1430 --- linux-3.13.1/drivers/tty/tty_io.c   2014-01-22 20:39:02.000000000 +0000
1431 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/attr.c linux-3.13.1-vs2.3.6.10/fs/attr.c
1459 --- linux-3.13.1/fs/attr.c      2014-01-22 20:39:05.000000000 +0000
1460 +++ linux-3.13.1-vs2.3.6.10/fs/attr.c   2014-01-31 20:38:03.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.1/fs/block_dev.c linux-3.13.1-vs2.3.6.10/fs/block_dev.c
1502 --- linux-3.13.1/fs/block_dev.c 2013-11-25 15:46:58.000000000 +0000
1503 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/btrfs/ctree.h linux-3.13.1-vs2.3.6.10/fs/btrfs/ctree.h
1542 --- linux-3.13.1/fs/btrfs/ctree.h       2014-01-22 20:39:05.000000000 +0000
1543 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/btrfs/disk-io.c linux-3.13.1-vs2.3.6.10/fs/btrfs/disk-io.c
1597 --- linux-3.13.1/fs/btrfs/disk-io.c     2014-01-22 20:39:05.000000000 +0000
1598 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/btrfs/inode.c linux-3.13.1-vs2.3.6.10/fs/btrfs/inode.c
1610 --- linux-3.13.1/fs/btrfs/inode.c       2014-01-22 20:39:05.000000000 +0000
1611 +++ linux-3.13.1-vs2.3.6.10/fs/btrfs/inode.c    2014-01-31 23:56:42.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 @@ -8648,12 +8665,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 @@ -8723,6 +8743,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.1/fs/btrfs/ioctl.c linux-3.13.1-vs2.3.6.10/fs/btrfs/ioctl.c
1693 --- linux-3.13.1/fs/btrfs/ioctl.c       2014-01-22 20:39:05.000000000 +0000
1694 +++ linux-3.13.1-vs2.3.6.10/fs/btrfs/ioctl.c    2014-01-31 20:38:03.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.1/fs/btrfs/super.c linux-3.13.1-vs2.3.6.10/fs/btrfs/super.c
1867 --- linux-3.13.1/fs/btrfs/super.c       2014-01-22 20:39:05.000000000 +0000
1868 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/char_dev.c linux-3.13.1-vs2.3.6.10/fs/char_dev.c
1925 --- linux-3.13.1/fs/char_dev.c  2014-01-22 20:39:05.000000000 +0000
1926 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/dcache.c linux-3.13.1-vs2.3.6.10/fs/dcache.c
1960 --- linux-3.13.1/fs/dcache.c    2014-01-22 20:39:06.000000000 +0000
1961 +++ linux-3.13.1-vs2.3.6.10/fs/dcache.c 2014-01-31 23:38:38.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.1/fs/devpts/inode.c linux-3.13.1-vs2.3.6.10/fs/devpts/inode.c
2014 --- linux-3.13.1/fs/devpts/inode.c      2014-01-22 20:39:06.000000000 +0000
2015 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext2/balloc.c linux-3.13.1-vs2.3.6.10/fs/ext2/balloc.c
2104 --- linux-3.13.1/fs/ext2/balloc.c       2013-05-31 13:45:23.000000000 +0000
2105 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext2/ext2.h linux-3.13.1-vs2.3.6.10/fs/ext2/ext2.h
2115 --- linux-3.13.1/fs/ext2/ext2.h 2012-12-11 03:30:57.000000000 +0000
2116 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext2/file.c linux-3.13.1-vs2.3.6.10/fs/ext2/file.c
2165 --- linux-3.13.1/fs/ext2/file.c 2012-12-11 03:30:57.000000000 +0000
2166 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext2/ialloc.c linux-3.13.1-vs2.3.6.10/fs/ext2/ialloc.c
2174 --- linux-3.13.1/fs/ext2/ialloc.c       2013-05-31 13:45:23.000000000 +0000
2175 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext2/inode.c linux-3.13.1-vs2.3.6.10/fs/ext2/inode.c
2193 --- linux-3.13.1/fs/ext2/inode.c        2014-01-22 20:39:06.000000000 +0000
2194 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext2/ioctl.c linux-3.13.1-vs2.3.6.10/fs/ext2/ioctl.c
2328 --- linux-3.13.1/fs/ext2/ioctl.c        2013-05-31 13:45:23.000000000 +0000
2329 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext2/namei.c linux-3.13.1-vs2.3.6.10/fs/ext2/namei.c
2380 --- linux-3.13.1/fs/ext2/namei.c        2013-11-25 15:45:01.000000000 +0000
2381 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext2/super.c linux-3.13.1-vs2.3.6.10/fs/ext2/super.c
2406 --- linux-3.13.1/fs/ext2/super.c        2014-01-22 20:39:06.000000000 +0000
2407 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext3/ext3.h linux-3.13.1-vs2.3.6.10/fs/ext3/ext3.h
2474 --- linux-3.13.1/fs/ext3/ext3.h 2012-12-11 03:30:57.000000000 +0000
2475 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext3/file.c linux-3.13.1-vs2.3.6.10/fs/ext3/file.c
2528 --- linux-3.13.1/fs/ext3/file.c 2012-12-11 03:30:57.000000000 +0000
2529 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext3/ialloc.c linux-3.13.1-vs2.3.6.10/fs/ext3/ialloc.c
2538 --- linux-3.13.1/fs/ext3/ialloc.c       2012-12-11 03:30:57.000000000 +0000
2539 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext3/inode.c linux-3.13.1-vs2.3.6.10/fs/ext3/inode.c
2557 --- linux-3.13.1/fs/ext3/inode.c        2013-11-25 15:45:01.000000000 +0000
2558 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext3/ioctl.c linux-3.13.1-vs2.3.6.10/fs/ext3/ioctl.c
2692 --- linux-3.13.1/fs/ext3/ioctl.c        2013-05-31 13:45:23.000000000 +0000
2693 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext3/namei.c linux-3.13.1-vs2.3.6.10/fs/ext3/namei.c
2762 --- linux-3.13.1/fs/ext3/namei.c        2013-11-25 15:46:59.000000000 +0000
2763 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext3/super.c linux-3.13.1-vs2.3.6.10/fs/ext3/super.c
2790 --- linux-3.13.1/fs/ext3/super.c        2014-01-22 20:39:06.000000000 +0000
2791 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext4/ext4.h linux-3.13.1-vs2.3.6.10/fs/ext4/ext4.h
2859 --- linux-3.13.1/fs/ext4/ext4.h 2014-01-22 20:39:06.000000000 +0000
2860 +++ linux-3.13.1-vs2.3.6.10/fs/ext4/ext4.h      2014-01-31 20:38:03.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 @@ -788,6 +791,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 @@ -974,6 +978,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 @@ -2651,6 +2656,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.1/fs/ext4/file.c linux-3.13.1-vs2.3.6.10/fs/ext4/file.c
2906 --- linux-3.13.1/fs/ext4/file.c 2013-11-25 15:46:59.000000000 +0000
2907 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext4/ialloc.c linux-3.13.1-vs2.3.6.10/fs/ext4/ialloc.c
2916 --- linux-3.13.1/fs/ext4/ialloc.c       2014-01-22 20:39:06.000000000 +0000
2917 +++ linux-3.13.1-vs2.3.6.10/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.1/fs/ext4/inode.c linux-3.13.1-vs2.3.6.10/fs/ext4/inode.c
2935 --- linux-3.13.1/fs/ext4/inode.c        2014-01-22 20:39:06.000000000 +0000
2936 +++ linux-3.13.1-vs2.3.6.10/fs/ext4/inode.c     2014-01-31 20:38:03.000000000 +0000
2937 @@ -38,6 +38,7 @@
2938  #include <linux/slab.h>
2939  #include <linux/ratelimit.h>
2940  #include <linux/aio.h>
2941 +#include <linux/vs_tag.h>
2942  
2943  #include "ext4_jbd2.h"
2944  #include "xattr.h"
2945 @@ -3927,41 +3928,64 @@ void ext4_set_inode_flags(struct inode *
2946  {
2947         unsigned int flags = EXT4_I(inode)->i_flags;
2948  
2949 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2950 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2951 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2952 +
2953 +       if (flags & EXT4_IMMUTABLE_FL)
2954 +               inode->i_flags |= S_IMMUTABLE;
2955 +       if (flags & EXT4_IXUNLINK_FL)
2956 +               inode->i_flags |= S_IXUNLINK;
2957 +
2958         if (flags & EXT4_SYNC_FL)
2959                 inode->i_flags |= S_SYNC;
2960         if (flags & EXT4_APPEND_FL)
2961                 inode->i_flags |= S_APPEND;
2962 -       if (flags & EXT4_IMMUTABLE_FL)
2963 -               inode->i_flags |= S_IMMUTABLE;
2964         if (flags & EXT4_NOATIME_FL)
2965                 inode->i_flags |= S_NOATIME;
2966         if (flags & EXT4_DIRSYNC_FL)
2967                 inode->i_flags |= S_DIRSYNC;
2968 +
2969 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2970 +
2971 +       if (flags & EXT4_BARRIER_FL)
2972 +               inode->i_vflags |= V_BARRIER;
2973 +       if (flags & EXT4_COW_FL)
2974 +               inode->i_vflags |= V_COW;
2975  }
2976  
2977  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2978  void ext4_get_inode_flags(struct ext4_inode_info *ei)
2979  {
2980 -       unsigned int vfs_fl;
2981 +       unsigned int vfs_fl, vfs_vf;
2982         unsigned long old_fl, new_fl;
2983  
2984         do {
2985                 vfs_fl = ei->vfs_inode.i_flags;
2986 +               vfs_vf = ei->vfs_inode.i_vflags;
2987                 old_fl = ei->i_flags;
2988                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2989                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
2990 -                               EXT4_DIRSYNC_FL);
2991 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
2992 +                               EXT4_COW_FL);
2993 +
2994 +               if (vfs_fl & S_IMMUTABLE)
2995 +                       new_fl |= EXT4_IMMUTABLE_FL;
2996 +               if (vfs_fl & S_IXUNLINK)
2997 +                       new_fl |= EXT4_IXUNLINK_FL;
2998 +
2999                 if (vfs_fl & S_SYNC)
3000                         new_fl |= EXT4_SYNC_FL;
3001                 if (vfs_fl & S_APPEND)
3002                         new_fl |= EXT4_APPEND_FL;
3003 -               if (vfs_fl & S_IMMUTABLE)
3004 -                       new_fl |= EXT4_IMMUTABLE_FL;
3005                 if (vfs_fl & S_NOATIME)
3006                         new_fl |= EXT4_NOATIME_FL;
3007                 if (vfs_fl & S_DIRSYNC)
3008                         new_fl |= EXT4_DIRSYNC_FL;
3009 +
3010 +               if (vfs_vf & V_BARRIER)
3011 +                       new_fl |= EXT4_BARRIER_FL;
3012 +               if (vfs_vf & V_COW)
3013 +                       new_fl |= EXT4_COW_FL;
3014         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3015  }
3016  
3017 @@ -4066,8 +4090,10 @@ struct inode *ext4_iget(struct super_blo
3018                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3019                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3020         }
3021 -       i_uid_write(inode, i_uid);
3022 -       i_gid_write(inode, i_gid);
3023 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3024 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3025 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3026 +               le16_to_cpu(raw_inode->i_raw_tag)));
3027         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3028  
3029         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3030 @@ -4295,8 +4321,10 @@ static int ext4_do_update_inode(handle_t
3031  
3032         ext4_get_inode_flags(ei);
3033         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3034 -       i_uid = i_uid_read(inode);
3035 -       i_gid = i_gid_read(inode);
3036 +       i_uid = from_kuid(&init_user_ns,
3037 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
3038 +       i_gid = from_kgid(&init_user_ns,
3039 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
3040         if (!(test_opt(inode->i_sb, NO_UID32))) {
3041                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3042                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3043 @@ -4319,6 +4347,9 @@ static int ext4_do_update_inode(handle_t
3044                 raw_inode->i_uid_high = 0;
3045                 raw_inode->i_gid_high = 0;
3046         }
3047 +#ifdef CONFIG_TAGGING_INTERN
3048 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3049 +#endif
3050         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3051  
3052         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3053 @@ -4550,7 +4581,8 @@ int ext4_setattr(struct dentry *dentry,
3054         if (is_quota_modification(inode, attr))
3055                 dquot_initialize(inode);
3056         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3057 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3058 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3059 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3060                 handle_t *handle;
3061  
3062                 /* (user+group)*(old+new) structure, inode write (sb,
3063 @@ -4573,6 +4605,8 @@ int ext4_setattr(struct dentry *dentry,
3064                         inode->i_uid = attr->ia_uid;
3065                 if (attr->ia_valid & ATTR_GID)
3066                         inode->i_gid = attr->ia_gid;
3067 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3068 +                       inode->i_tag = attr->ia_tag;
3069                 error = ext4_mark_inode_dirty(handle, inode);
3070                 ext4_journal_stop(handle);
3071         }
3072 diff -NurpP --minimal linux-3.13.1/fs/ext4/ioctl.c linux-3.13.1-vs2.3.6.10/fs/ext4/ioctl.c
3073 --- linux-3.13.1/fs/ext4/ioctl.c        2014-01-22 20:39:06.000000000 +0000
3074 +++ linux-3.13.1-vs2.3.6.10/fs/ext4/ioctl.c     2014-01-31 20:38:03.000000000 +0000
3075 @@ -14,6 +14,7 @@
3076  #include <linux/compat.h>
3077  #include <linux/mount.h>
3078  #include <linux/file.h>
3079 +#include <linux/vs_tag.h>
3080  #include <asm/uaccess.h>
3081  #include "ext4_jbd2.h"
3082  #include "ext4.h"
3083 @@ -213,6 +214,33 @@ swap_boot_out:
3084         return err;
3085  }
3086  
3087 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3088 +{
3089 +       handle_t *handle = NULL;
3090 +       struct ext4_iloc iloc;
3091 +       int err;
3092 +
3093 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3094 +       if (IS_ERR(handle))
3095 +               return PTR_ERR(handle);
3096 +
3097 +       if (IS_SYNC(inode))
3098 +               ext4_handle_sync(handle);
3099 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3100 +       if (err)
3101 +               goto flags_err;
3102 +
3103 +       inode->i_flags = flags;
3104 +       inode->i_vflags = vflags;
3105 +       ext4_get_inode_flags(EXT4_I(inode));
3106 +       inode->i_ctime = ext4_current_time(inode);
3107 +
3108 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3109 +flags_err:
3110 +       ext4_journal_stop(handle);
3111 +       return err;
3112 +}
3113 +
3114  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3115  {
3116         struct inode *inode = file_inode(filp);
3117 @@ -246,6 +274,11 @@ long ext4_ioctl(struct file *filp, unsig
3118  
3119                 flags = ext4_mask_flags(inode->i_mode, flags);
3120  
3121 +               if (IS_BARRIER(inode)) {
3122 +                       vxwprintk_task(1, "messing with the barrier.");
3123 +                       return -EACCES;
3124 +               }
3125 +
3126                 err = -EPERM;
3127                 mutex_lock(&inode->i_mutex);
3128                 /* Is it quota file? Do not allow user to mess with it */
3129 @@ -263,7 +296,9 @@ long ext4_ioctl(struct file *filp, unsig
3130                  *
3131                  * This test looks nicer. Thanks to Pauline Middelink
3132                  */
3133 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3134 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3135 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3136 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3137                         if (!capable(CAP_LINUX_IMMUTABLE))
3138                                 goto flags_out;
3139                 }
3140 diff -NurpP --minimal linux-3.13.1/fs/ext4/namei.c linux-3.13.1-vs2.3.6.10/fs/ext4/namei.c
3141 --- linux-3.13.1/fs/ext4/namei.c        2013-11-25 15:46:59.000000000 +0000
3142 +++ linux-3.13.1-vs2.3.6.10/fs/ext4/namei.c     2014-01-31 20:38:03.000000000 +0000
3143 @@ -34,6 +34,7 @@
3144  #include <linux/quotaops.h>
3145  #include <linux/buffer_head.h>
3146  #include <linux/bio.h>
3147 +#include <linux/vs_tag.h>
3148  #include "ext4.h"
3149  #include "ext4_jbd2.h"
3150  
3151 @@ -1299,6 +1300,7 @@ restart:
3152                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3153                                                     1, &bh);
3154                         }
3155 +               dx_propagate_tag(nd, inode);
3156                 }
3157                 if ((bh = bh_use[ra_ptr++]) == NULL)
3158                         goto next;
3159 @@ -3226,6 +3228,7 @@ const struct inode_operations ext4_dir_i
3160         .removexattr    = generic_removexattr,
3161         .get_acl        = ext4_get_acl,
3162         .fiemap         = ext4_fiemap,
3163 +       .sync_flags     = ext4_sync_flags,
3164  };
3165  
3166  const struct inode_operations ext4_special_inode_operations = {
3167 diff -NurpP --minimal linux-3.13.1/fs/ext4/super.c linux-3.13.1-vs2.3.6.10/fs/ext4/super.c
3168 --- linux-3.13.1/fs/ext4/super.c        2014-01-22 20:39:06.000000000 +0000
3169 +++ linux-3.13.1-vs2.3.6.10/fs/ext4/super.c     2014-01-31 20:38:03.000000000 +0000
3170 @@ -1162,7 +1162,7 @@ enum {
3171         Opt_inode_readahead_blks, Opt_journal_ioprio,
3172         Opt_dioread_nolock, Opt_dioread_lock,
3173         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3174 -       Opt_max_dir_size_kb,
3175 +       Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3176  };
3177  
3178  static const match_table_t tokens = {
3179 @@ -1243,6 +1243,9 @@ static const match_table_t tokens = {
3180         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3181         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3182         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3183 +       {Opt_tag, "tag"},
3184 +       {Opt_notag, "notag"},
3185 +       {Opt_tagid, "tagid=%u"},
3186         {Opt_err, NULL},
3187  };
3188  
3189 @@ -1475,6 +1478,20 @@ static int handle_mount_opt(struct super
3190         case Opt_i_version:
3191                 sb->s_flags |= MS_I_VERSION;
3192                 return 1;
3193 +#ifndef CONFIG_TAGGING_NONE
3194 +       case Opt_tag:
3195 +               set_opt(sb, TAGGED);
3196 +               return 1;
3197 +       case Opt_notag:
3198 +               clear_opt(sb, TAGGED);
3199 +               return 1;
3200 +#endif
3201 +#ifdef CONFIG_PROPAGATE
3202 +       case Opt_tagid:
3203 +               /* use args[0] */
3204 +               set_opt(sb, TAGGED);
3205 +               return 1;
3206 +#endif
3207         }
3208  
3209         for (m = ext4_mount_opts; m->token != Opt_err; m++)
3210 @@ -3564,6 +3581,9 @@ static int ext4_fill_super(struct super_
3211                         clear_opt(sb, DELALLOC);
3212         }
3213  
3214 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3215 +               sb->s_flags |= MS_TAGGED;
3216 +
3217         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3218                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3219  
3220 @@ -4812,6 +4832,14 @@ static int ext4_remount(struct super_blo
3221         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3222                 ext4_abort(sb, "Abort forced by user");
3223  
3224 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3225 +               !(sb->s_flags & MS_TAGGED)) {
3226 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3227 +                       sb->s_id);
3228 +               err = -EINVAL;
3229 +               goto restore_opts;
3230 +       }
3231 +
3232         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3233                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3234  
3235 diff -NurpP --minimal linux-3.13.1/fs/fcntl.c linux-3.13.1-vs2.3.6.10/fs/fcntl.c
3236 --- linux-3.13.1/fs/fcntl.c     2014-01-22 20:39:06.000000000 +0000
3237 +++ linux-3.13.1-vs2.3.6.10/fs/fcntl.c  2014-01-31 20:38:03.000000000 +0000
3238 @@ -21,6 +21,7 @@
3239  #include <linux/rcupdate.h>
3240  #include <linux/pid_namespace.h>
3241  #include <linux/user_namespace.h>
3242 +#include <linux/vs_limit.h>
3243  
3244  #include <asm/poll.h>
3245  #include <asm/siginfo.h>
3246 @@ -377,6 +378,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3247  
3248         if (!f.file)
3249                 goto out;
3250 +       if (!vx_files_avail(1))
3251 +               goto out;
3252  
3253         if (unlikely(f.file->f_mode & FMODE_PATH)) {
3254                 if (!check_fcntl_cmd(cmd))
3255 diff -NurpP --minimal linux-3.13.1/fs/file.c linux-3.13.1-vs2.3.6.10/fs/file.c
3256 --- linux-3.13.1/fs/file.c      2013-07-14 17:01:28.000000000 +0000
3257 +++ linux-3.13.1-vs2.3.6.10/fs/file.c   2014-01-31 20:38:03.000000000 +0000
3258 @@ -22,6 +22,7 @@
3259  #include <linux/spinlock.h>
3260  #include <linux/rcupdate.h>
3261  #include <linux/workqueue.h>
3262 +#include <linux/vs_limit.h>
3263  
3264  int sysctl_nr_open __read_mostly = 1024*1024;
3265  int sysctl_nr_open_min = BITS_PER_LONG;
3266 @@ -311,6 +312,8 @@ struct files_struct *dup_fd(struct files
3267                 struct file *f = *old_fds++;
3268                 if (f) {
3269                         get_file(f);
3270 +                       /* TODO: sum it first for check and performance */
3271 +                       vx_openfd_inc(open_files - i);
3272                 } else {
3273                         /*
3274                          * The fd may be claimed in the fd bitmap but not yet
3275 @@ -376,9 +379,11 @@ static void close_files(struct files_str
3276                                         filp_close(file, files);
3277                                         cond_resched();
3278                                 }
3279 +                               vx_openfd_dec(i);
3280                         }
3281                         i++;
3282                         set >>= 1;
3283 +                       cond_resched();
3284                 }
3285         }
3286  }
3287 @@ -503,6 +508,7 @@ repeat:
3288         else
3289                 __clear_close_on_exec(fd, fdt);
3290         error = fd;
3291 +       vx_openfd_inc(fd);
3292  #if 1
3293         /* Sanity check */
3294         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3295 @@ -533,6 +539,7 @@ static void __put_unused_fd(struct files
3296         __clear_open_fd(fd, fdt);
3297         if (fd < files->next_fd)
3298                 files->next_fd = fd;
3299 +       vx_openfd_dec(fd);
3300  }
3301  
3302  void put_unused_fd(unsigned int fd)
3303 @@ -812,6 +819,8 @@ static int do_dup2(struct files_struct *
3304  
3305         if (tofree)
3306                 filp_close(tofree, files);
3307 +       else
3308 +               vx_openfd_inc(fd);      /* fd was unused */
3309  
3310         return fd;
3311  
3312 diff -NurpP --minimal linux-3.13.1/fs/file_table.c linux-3.13.1-vs2.3.6.10/fs/file_table.c
3313 --- linux-3.13.1/fs/file_table.c        2014-01-22 20:39:06.000000000 +0000
3314 +++ linux-3.13.1-vs2.3.6.10/fs/file_table.c     2014-02-01 00:00:01.000000000 +0000
3315 @@ -26,6 +26,8 @@
3316  #include <linux/hardirq.h>
3317  #include <linux/task_work.h>
3318  #include <linux/ima.h>
3319 +#include <linux/vs_limit.h>
3320 +#include <linux/vs_context.h>
3321  
3322  #include <linux/atomic.h>
3323  
3324 @@ -137,6 +139,8 @@ struct file *get_empty_filp(void)
3325         spin_lock_init(&f->f_lock);
3326         eventpoll_init_file(f);
3327         /* f->f_version: 0 */
3328 +       f->f_xid = vx_current_xid();
3329 +       vx_files_inc(f);
3330         return f;
3331  
3332  over:
3333 @@ -254,6 +258,8 @@ static void __fput(struct file *file)
3334                 i_readcount_dec(inode);
3335         if (file->f_mode & FMODE_WRITE)
3336                 drop_file_write_access(file);
3337 +       vx_files_dec(file);
3338 +       file->f_xid = 0;
3339         file->f_path.dentry = NULL;
3340         file->f_path.mnt = NULL;
3341         file->f_inode = NULL;
3342 @@ -340,6 +346,8 @@ void put_filp(struct file *file)
3343  {
3344         if (atomic_long_dec_and_test(&file->f_count)) {
3345                 security_file_free(file);
3346 +               vx_files_dec(file);
3347 +               file->f_xid = 0;
3348                 file_free(file);
3349         }
3350  }
3351 diff -NurpP --minimal linux-3.13.1/fs/fs_struct.c linux-3.13.1-vs2.3.6.10/fs/fs_struct.c
3352 --- linux-3.13.1/fs/fs_struct.c 2014-01-22 20:39:06.000000000 +0000
3353 +++ linux-3.13.1-vs2.3.6.10/fs/fs_struct.c      2014-01-31 20:38:03.000000000 +0000
3354 @@ -4,6 +4,7 @@
3355  #include <linux/path.h>
3356  #include <linux/slab.h>
3357  #include <linux/fs_struct.h>
3358 +#include <linux/vserver/global.h>
3359  #include "internal.h"
3360  
3361  /*
3362 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3363  {
3364         path_put(&fs->root);
3365         path_put(&fs->pwd);
3366 +       atomic_dec(&vs_global_fs);
3367         kmem_cache_free(fs_cachep, fs);
3368  }
3369  
3370 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3371                 fs->pwd = old->pwd;
3372                 path_get(&fs->pwd);
3373                 spin_unlock(&old->lock);
3374 +               atomic_inc(&vs_global_fs);
3375         }
3376         return fs;
3377  }
3378 diff -NurpP --minimal linux-3.13.1/fs/gfs2/file.c linux-3.13.1-vs2.3.6.10/fs/gfs2/file.c
3379 --- linux-3.13.1/fs/gfs2/file.c 2014-01-22 20:39:06.000000000 +0000
3380 +++ linux-3.13.1-vs2.3.6.10/fs/gfs2/file.c      2014-01-31 20:38:03.000000000 +0000
3381 @@ -137,6 +137,9 @@ static const u32 fsflags_to_gfs2[32] = {
3382         [12] = GFS2_DIF_EXHASH,
3383         [14] = GFS2_DIF_INHERIT_JDATA,
3384         [17] = GFS2_DIF_TOPDIR,
3385 +       [27] = GFS2_DIF_IXUNLINK,
3386 +       [26] = GFS2_DIF_BARRIER,
3387 +       [29] = GFS2_DIF_COW,
3388  };
3389  
3390  static const u32 gfs2_to_fsflags[32] = {
3391 @@ -147,6 +150,9 @@ static const u32 gfs2_to_fsflags[32] = {
3392         [gfs2fl_ExHash] = FS_INDEX_FL,
3393         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3394         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3395 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3396 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3397 +       [gfs2fl_Cow] = FS_COW_FL,
3398  };
3399  
3400  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3401 @@ -177,12 +183,18 @@ void gfs2_set_inode_flags(struct inode *
3402  {
3403         struct gfs2_inode *ip = GFS2_I(inode);
3404         unsigned int flags = inode->i_flags;
3405 +       unsigned int vflags = inode->i_vflags;
3406 +
3407 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3408 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3409  
3410 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3411         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3412                 inode->i_flags |= S_NOSEC;
3413         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3414                 flags |= S_IMMUTABLE;
3415 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3416 +               flags |= S_IXUNLINK;
3417 +
3418         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3419                 flags |= S_APPEND;
3420         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3421 @@ -190,6 +202,43 @@ void gfs2_set_inode_flags(struct inode *
3422         if (ip->i_diskflags & GFS2_DIF_SYNC)
3423                 flags |= S_SYNC;
3424         inode->i_flags = flags;
3425 +
3426 +       vflags &= ~(V_BARRIER | V_COW);
3427 +
3428 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3429 +               vflags |= V_BARRIER;
3430 +       if (ip->i_diskflags & GFS2_DIF_COW)
3431 +               vflags |= V_COW;
3432 +       inode->i_vflags = vflags;
3433 +}
3434 +
3435 +void gfs2_get_inode_flags(struct inode *inode)
3436 +{
3437 +       struct gfs2_inode *ip = GFS2_I(inode);
3438 +       unsigned int flags = inode->i_flags;
3439 +       unsigned int vflags = inode->i_vflags;
3440 +
3441 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3442 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3443 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3444 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3445 +
3446 +       if (flags & S_IMMUTABLE)
3447 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3448 +       if (flags & S_IXUNLINK)
3449 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3450 +
3451 +       if (flags & S_APPEND)
3452 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3453 +       if (flags & S_NOATIME)
3454 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3455 +       if (flags & S_SYNC)
3456 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3457 +
3458 +       if (vflags & V_BARRIER)
3459 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3460 +       if (vflags & V_COW)
3461 +               ip->i_diskflags |= GFS2_DIF_COW;
3462  }
3463  
3464  /* Flags that can be set by user space */
3465 @@ -303,6 +352,37 @@ static int gfs2_set_flags(struct file *f
3466         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3467  }
3468  
3469 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3470 +{
3471 +       struct gfs2_inode *ip = GFS2_I(inode);
3472 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3473 +       struct buffer_head *bh;
3474 +       struct gfs2_holder gh;
3475 +       int error;
3476 +
3477 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3478 +       if (error)
3479 +               return error;
3480 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3481 +       if (error)
3482 +               goto out;
3483 +       error = gfs2_meta_inode_buffer(ip, &bh);
3484 +       if (error)
3485 +               goto out_trans_end;
3486 +       gfs2_trans_add_meta(ip->i_gl, bh);
3487 +       inode->i_flags = flags;
3488 +       inode->i_vflags = vflags;
3489 +       gfs2_get_inode_flags(inode);
3490 +       gfs2_dinode_out(ip, bh->b_data);
3491 +       brelse(bh);
3492 +       gfs2_set_aops(inode);
3493 +out_trans_end:
3494 +       gfs2_trans_end(sdp);
3495 +out:
3496 +       gfs2_glock_dq_uninit(&gh);
3497 +       return error;
3498 +}
3499 +
3500  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3501  {
3502         switch(cmd) {
3503 diff -NurpP --minimal linux-3.13.1/fs/gfs2/inode.h linux-3.13.1-vs2.3.6.10/fs/gfs2/inode.h
3504 --- linux-3.13.1/fs/gfs2/inode.h        2013-11-25 15:45:01.000000000 +0000
3505 +++ linux-3.13.1-vs2.3.6.10/fs/gfs2/inode.h     2014-01-31 20:38:03.000000000 +0000
3506 @@ -118,6 +118,7 @@ extern const struct file_operations gfs2
3507  extern const struct file_operations gfs2_dir_fops_nolock;
3508  
3509  extern void gfs2_set_inode_flags(struct inode *inode);
3510 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3511   
3512  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3513  extern const struct file_operations gfs2_file_fops;
3514 diff -NurpP --minimal linux-3.13.1/fs/hostfs/hostfs.h linux-3.13.1-vs2.3.6.10/fs/hostfs/hostfs.h
3515 --- linux-3.13.1/fs/hostfs/hostfs.h     2012-12-11 03:30:57.000000000 +0000
3516 +++ linux-3.13.1-vs2.3.6.10/fs/hostfs/hostfs.h  2014-01-31 20:38:03.000000000 +0000
3517 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3518         unsigned short  ia_mode;
3519         uid_t           ia_uid;
3520         gid_t           ia_gid;
3521 +       vtag_t          ia_tag;
3522         loff_t          ia_size;
3523         struct timespec ia_atime;
3524         struct timespec ia_mtime;
3525 diff -NurpP --minimal linux-3.13.1/fs/inode.c linux-3.13.1-vs2.3.6.10/fs/inode.c
3526 --- linux-3.13.1/fs/inode.c     2014-01-22 20:39:06.000000000 +0000
3527 +++ linux-3.13.1-vs2.3.6.10/fs/inode.c  2014-01-31 23:33:47.000000000 +0000
3528 @@ -18,6 +18,7 @@
3529  #include <linux/buffer_head.h> /* for inode_has_buffers */
3530  #include <linux/ratelimit.h>
3531  #include <linux/list_lru.h>
3532 +#include <linux/vs_tag.h>
3533  #include "internal.h"
3534  
3535  /*
3536 @@ -129,6 +130,8 @@ int inode_init_always(struct super_block
3537         struct address_space *const mapping = &inode->i_data;
3538  
3539         inode->i_sb = sb;
3540 +
3541 +       /* essential because of inode slab reuse */
3542         inode->i_blkbits = sb->s_blocksize_bits;
3543         inode->i_flags = 0;
3544         atomic_set(&inode->i_count, 1);
3545 @@ -138,6 +141,7 @@ int inode_init_always(struct super_block
3546         inode->i_opflags = 0;
3547         i_uid_write(inode, 0);
3548         i_gid_write(inode, 0);
3549 +       i_tag_write(inode, 0);
3550         atomic_set(&inode->i_writecount, 0);
3551         inode->i_size = 0;
3552         inode->i_blocks = 0;
3553 @@ -150,6 +154,7 @@ int inode_init_always(struct super_block
3554         inode->i_bdev = NULL;
3555         inode->i_cdev = NULL;
3556         inode->i_rdev = 0;
3557 +       inode->i_mdev = 0;
3558         inode->dirtied_when = 0;
3559  
3560         if (security_inode_alloc(inode))
3561 @@ -477,6 +482,8 @@ void __insert_inode_hash(struct inode *i
3562  }
3563  EXPORT_SYMBOL(__insert_inode_hash);
3564  
3565 +EXPORT_SYMBOL_GPL(__iget);
3566 +
3567  /**
3568   *     __remove_inode_hash - remove an inode from the hash
3569   *     @inode: inode to unhash
3570 @@ -1802,9 +1809,11 @@ void init_special_inode(struct inode *in
3571         if (S_ISCHR(mode)) {
3572                 inode->i_fop = &def_chr_fops;
3573                 inode->i_rdev = rdev;
3574 +               inode->i_mdev = rdev;
3575         } else if (S_ISBLK(mode)) {
3576                 inode->i_fop = &def_blk_fops;
3577                 inode->i_rdev = rdev;
3578 +               inode->i_mdev = rdev;
3579         } else if (S_ISFIFO(mode))
3580                 inode->i_fop = &pipefifo_fops;
3581         else if (S_ISSOCK(mode))
3582 @@ -1833,6 +1842,7 @@ void inode_init_owner(struct inode *inod
3583         } else
3584                 inode->i_gid = current_fsgid();
3585         inode->i_mode = mode;
3586 +       i_tag_write(inode, dx_current_fstag(inode->i_sb));
3587  }
3588  EXPORT_SYMBOL(inode_init_owner);
3589  
3590 diff -NurpP --minimal linux-3.13.1/fs/ioctl.c linux-3.13.1-vs2.3.6.10/fs/ioctl.c
3591 --- linux-3.13.1/fs/ioctl.c     2014-01-22 20:39:06.000000000 +0000
3592 +++ linux-3.13.1-vs2.3.6.10/fs/ioctl.c  2014-01-31 20:38:03.000000000 +0000
3593 @@ -15,6 +15,9 @@
3594  #include <linux/writeback.h>
3595  #include <linux/buffer_head.h>
3596  #include <linux/falloc.h>
3597 +#include <linux/proc_fs.h>
3598 +#include <linux/vserver/inode.h>
3599 +#include <linux/vs_tag.h>
3600  
3601  #include <asm/ioctls.h>
3602  
3603 diff -NurpP --minimal linux-3.13.1/fs/ioprio.c linux-3.13.1-vs2.3.6.10/fs/ioprio.c
3604 --- linux-3.13.1/fs/ioprio.c    2012-12-11 03:30:57.000000000 +0000
3605 +++ linux-3.13.1-vs2.3.6.10/fs/ioprio.c 2014-01-31 20:38:03.000000000 +0000
3606 @@ -28,6 +28,7 @@
3607  #include <linux/syscalls.h>
3608  #include <linux/security.h>
3609  #include <linux/pid_namespace.h>
3610 +#include <linux/vs_base.h>
3611  
3612  int set_task_ioprio(struct task_struct *task, int ioprio)
3613  {
3614 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3615                         else
3616                                 pgrp = find_vpid(who);
3617                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3618 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3619 +                                       continue;
3620                                 ret = set_task_ioprio(p, ioprio);
3621                                 if (ret)
3622                                         break;
3623 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3624                         else
3625                                 pgrp = find_vpid(who);
3626                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3627 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3628 +                                       continue;
3629                                 tmpio = get_task_ioprio(p);
3630                                 if (tmpio < 0)
3631                                         continue;
3632 diff -NurpP --minimal linux-3.13.1/fs/jfs/file.c linux-3.13.1-vs2.3.6.10/fs/jfs/file.c
3633 --- linux-3.13.1/fs/jfs/file.c  2013-02-19 13:58:48.000000000 +0000
3634 +++ linux-3.13.1-vs2.3.6.10/fs/jfs/file.c       2014-01-31 20:38:03.000000000 +0000
3635 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3636         if (is_quota_modification(inode, iattr))
3637                 dquot_initialize(inode);
3638         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3639 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3640 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3641 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3642                 rc = dquot_transfer(inode, iattr);
3643                 if (rc)
3644                         return rc;
3645 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3646  #ifdef CONFIG_JFS_POSIX_ACL
3647         .get_acl        = jfs_get_acl,
3648  #endif
3649 +       .sync_flags     = jfs_sync_flags,
3650  };
3651  
3652  const struct file_operations jfs_file_operations = {
3653 diff -NurpP --minimal linux-3.13.1/fs/jfs/ioctl.c linux-3.13.1-vs2.3.6.10/fs/jfs/ioctl.c
3654 --- linux-3.13.1/fs/jfs/ioctl.c 2013-05-31 13:45:24.000000000 +0000
3655 +++ linux-3.13.1-vs2.3.6.10/fs/jfs/ioctl.c      2014-01-31 20:38:03.000000000 +0000
3656 @@ -12,6 +12,7 @@
3657  #include <linux/time.h>
3658  #include <linux/sched.h>
3659  #include <linux/blkdev.h>
3660 +#include <linux/mount.h>
3661  #include <asm/current.h>
3662  #include <asm/uaccess.h>
3663  
3664 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3665  }
3666  
3667  
3668 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3669 +{
3670 +       inode->i_flags = flags;
3671 +       inode->i_vflags = vflags;
3672 +       jfs_get_inode_flags(JFS_IP(inode));
3673 +       inode->i_ctime = CURRENT_TIME_SEC;
3674 +       mark_inode_dirty(inode);
3675 +       return 0;
3676 +}
3677 +
3678  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3679  {
3680         struct inode *inode = file_inode(filp);
3681 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3682                 if (!S_ISDIR(inode->i_mode))
3683                         flags &= ~JFS_DIRSYNC_FL;
3684  
3685 +               if (IS_BARRIER(inode)) {
3686 +                       vxwprintk_task(1, "messing with the barrier.");
3687 +                       return -EACCES;
3688 +               }
3689 +
3690                 /* Is it quota file? Do not allow user to mess with it */
3691                 if (IS_NOQUOTA(inode)) {
3692                         err = -EPERM;
3693 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3694                  * the relevant capability.
3695                  */
3696                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3697 -                       ((flags ^ oldflags) &
3698 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3699 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3700 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3701                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3702                                 mutex_unlock(&inode->i_mutex);
3703                                 err = -EPERM;
3704 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3705                         }
3706                 }
3707  
3708 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3709 +               flags &= JFS_FL_USER_MODIFIABLE;
3710                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3711                 jfs_inode->mode2 = flags;
3712  
3713 diff -NurpP --minimal linux-3.13.1/fs/jfs/jfs_dinode.h linux-3.13.1-vs2.3.6.10/fs/jfs/jfs_dinode.h
3714 --- linux-3.13.1/fs/jfs/jfs_dinode.h    2012-12-11 03:30:57.000000000 +0000
3715 +++ linux-3.13.1-vs2.3.6.10/fs/jfs/jfs_dinode.h 2014-01-31 20:38:03.000000000 +0000
3716 @@ -161,9 +161,13 @@ struct dinode {
3717  
3718  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3719  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3720 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3721  
3722 -#define JFS_FL_USER_VISIBLE    0x03F80000
3723 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3724 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3725 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3726 +
3727 +#define JFS_FL_USER_VISIBLE    0x07F80000
3728 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3729  #define JFS_FL_INHERIT         0x03C80000
3730  
3731  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3732 diff -NurpP --minimal linux-3.13.1/fs/jfs/jfs_filsys.h linux-3.13.1-vs2.3.6.10/fs/jfs/jfs_filsys.h
3733 --- linux-3.13.1/fs/jfs/jfs_filsys.h    2012-12-11 03:30:57.000000000 +0000
3734 +++ linux-3.13.1-vs2.3.6.10/fs/jfs/jfs_filsys.h 2014-01-31 20:38:03.000000000 +0000
3735 @@ -266,6 +266,7 @@
3736  #define JFS_NAME_MAX   255
3737  #define JFS_PATH_MAX   BPSIZE
3738  
3739 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3740  
3741  /*
3742   *     file system state (superblock state)
3743 diff -NurpP --minimal linux-3.13.1/fs/jfs/jfs_imap.c linux-3.13.1-vs2.3.6.10/fs/jfs/jfs_imap.c
3744 --- linux-3.13.1/fs/jfs/jfs_imap.c      2013-11-25 15:45:01.000000000 +0000
3745 +++ linux-3.13.1-vs2.3.6.10/fs/jfs/jfs_imap.c   2014-01-31 20:38:03.000000000 +0000
3746 @@ -46,6 +46,7 @@
3747  #include <linux/pagemap.h>
3748  #include <linux/quotaops.h>
3749  #include <linux/slab.h>
3750 +#include <linux/vs_tag.h>
3751  
3752  #include "jfs_incore.h"
3753  #include "jfs_inode.h"
3754 @@ -3047,6 +3048,8 @@ static int copy_from_dinode(struct dinod
3755  {
3756         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3757         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3758 +       kuid_t kuid;
3759 +       kgid_t kgid;
3760  
3761         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3762         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3763 @@ -3067,14 +3070,18 @@ static int copy_from_dinode(struct dinod
3764         }
3765         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3766  
3767 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3768 +       kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3769 +       kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3770 +       ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3771 +
3772 +       jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3773         if (!uid_valid(sbi->uid))
3774                 ip->i_uid = jfs_ip->saved_uid;
3775         else {
3776                 ip->i_uid = sbi->uid;
3777         }
3778  
3779 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3780 +       jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3781         if (!gid_valid(sbi->gid))
3782                 ip->i_gid = jfs_ip->saved_gid;
3783         else {
3784 @@ -3139,16 +3146,14 @@ static void copy_to_dinode(struct dinode
3785         dip->di_size = cpu_to_le64(ip->i_size);
3786         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3787         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3788 -       if (!uid_valid(sbi->uid))
3789 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3790 -       else
3791 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3792 -                                                  jfs_ip->saved_uid));
3793 -       if (!gid_valid(sbi->gid))
3794 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3795 -       else
3796 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3797 -                                                   jfs_ip->saved_gid));
3798 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3799 +               TAGINO_KUID(DX_TAG(ip),
3800 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3801 +               ip->i_tag)));
3802 +       dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3803 +               TAGINO_KGID(DX_TAG(ip),
3804 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3805 +               ip->i_tag)));
3806         jfs_get_inode_flags(jfs_ip);
3807         /*
3808          * mode2 is only needed for storing the higher order bits.
3809 diff -NurpP --minimal linux-3.13.1/fs/jfs/jfs_inode.c linux-3.13.1-vs2.3.6.10/fs/jfs/jfs_inode.c
3810 --- linux-3.13.1/fs/jfs/jfs_inode.c     2013-11-25 15:46:59.000000000 +0000
3811 +++ linux-3.13.1-vs2.3.6.10/fs/jfs/jfs_inode.c  2014-01-31 20:38:03.000000000 +0000
3812 @@ -18,6 +18,7 @@
3813  
3814  #include <linux/fs.h>
3815  #include <linux/quotaops.h>
3816 +#include <linux/vs_tag.h>
3817  #include "jfs_incore.h"
3818  #include "jfs_inode.h"
3819  #include "jfs_filsys.h"
3820 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3821  {
3822         unsigned int flags = JFS_IP(inode)->mode2;
3823  
3824 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3825 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3826 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3827 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3828  
3829         if (flags & JFS_IMMUTABLE_FL)
3830                 inode->i_flags |= S_IMMUTABLE;
3831 +       if (flags & JFS_IXUNLINK_FL)
3832 +               inode->i_flags |= S_IXUNLINK;
3833 +
3834 +       if (flags & JFS_SYNC_FL)
3835 +               inode->i_flags |= S_SYNC;
3836         if (flags & JFS_APPEND_FL)
3837                 inode->i_flags |= S_APPEND;
3838         if (flags & JFS_NOATIME_FL)
3839                 inode->i_flags |= S_NOATIME;
3840         if (flags & JFS_DIRSYNC_FL)
3841                 inode->i_flags |= S_DIRSYNC;
3842 -       if (flags & JFS_SYNC_FL)
3843 -               inode->i_flags |= S_SYNC;
3844 +
3845 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3846 +
3847 +       if (flags & JFS_BARRIER_FL)
3848 +               inode->i_vflags |= V_BARRIER;
3849 +       if (flags & JFS_COW_FL)
3850 +               inode->i_vflags |= V_COW;
3851  }
3852  
3853  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3854  {
3855         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3856 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3857 +
3858 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3859 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3860 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3861 +                          JFS_BARRIER_FL | JFS_COW_FL);
3862  
3863 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3864 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3865         if (flags & S_IMMUTABLE)
3866                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3867 +       if (flags & S_IXUNLINK)
3868 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3869 +
3870         if (flags & S_APPEND)
3871                 jfs_ip->mode2 |= JFS_APPEND_FL;
3872         if (flags & S_NOATIME)
3873 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3874                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3875         if (flags & S_SYNC)
3876                 jfs_ip->mode2 |= JFS_SYNC_FL;
3877 +
3878 +       if (vflags & V_BARRIER)
3879 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3880 +       if (vflags & V_COW)
3881 +               jfs_ip->mode2 |= JFS_COW_FL;
3882  }
3883  
3884  /*
3885 diff -NurpP --minimal linux-3.13.1/fs/jfs/jfs_inode.h linux-3.13.1-vs2.3.6.10/fs/jfs/jfs_inode.h
3886 --- linux-3.13.1/fs/jfs/jfs_inode.h     2012-12-11 03:30:57.000000000 +0000
3887 +++ linux-3.13.1-vs2.3.6.10/fs/jfs/jfs_inode.h  2014-01-31 20:38:03.000000000 +0000
3888 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3889  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3890         int fh_len, int fh_type);
3891  extern void jfs_set_inode_flags(struct inode *);
3892 +extern int jfs_sync_flags(struct inode *, int, int);
3893  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3894  extern int jfs_setattr(struct dentry *, struct iattr *);
3895  
3896 diff -NurpP --minimal linux-3.13.1/fs/jfs/namei.c linux-3.13.1-vs2.3.6.10/fs/jfs/namei.c
3897 --- linux-3.13.1/fs/jfs/namei.c 2013-11-25 15:45:01.000000000 +0000
3898 +++ linux-3.13.1-vs2.3.6.10/fs/jfs/namei.c      2014-01-31 20:38:03.000000000 +0000
3899 @@ -22,6 +22,7 @@
3900  #include <linux/ctype.h>
3901  #include <linux/quotaops.h>
3902  #include <linux/exportfs.h>
3903 +#include <linux/vs_tag.h>
3904  #include "jfs_incore.h"
3905  #include "jfs_superblock.h"
3906  #include "jfs_inode.h"
3907 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3908                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3909         }
3910  
3911 +       dx_propagate_tag(nd, ip);
3912         return d_splice_alias(ip, dentry);
3913  }
3914  
3915 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
3916  #ifdef CONFIG_JFS_POSIX_ACL
3917         .get_acl        = jfs_get_acl,
3918  #endif
3919 +       .sync_flags     = jfs_sync_flags,
3920  };
3921  
3922  const struct file_operations jfs_dir_operations = {
3923 diff -NurpP --minimal linux-3.13.1/fs/jfs/super.c linux-3.13.1-vs2.3.6.10/fs/jfs/super.c
3924 --- linux-3.13.1/fs/jfs/super.c 2013-11-25 15:45:01.000000000 +0000
3925 +++ linux-3.13.1-vs2.3.6.10/fs/jfs/super.c      2014-01-31 20:38:03.000000000 +0000
3926 @@ -203,7 +203,8 @@ enum {
3927         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
3928         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
3929         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
3930 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
3931 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
3932 +       Opt_tag, Opt_notag, Opt_tagid
3933  };
3934  
3935  static const match_table_t tokens = {
3936 @@ -213,6 +214,10 @@ static const match_table_t tokens = {
3937         {Opt_resize, "resize=%u"},
3938         {Opt_resize_nosize, "resize"},
3939         {Opt_errors, "errors=%s"},
3940 +       {Opt_tag, "tag"},
3941 +       {Opt_notag, "notag"},
3942 +       {Opt_tagid, "tagid=%u"},
3943 +       {Opt_tag, "tagxid"},
3944         {Opt_ignore, "noquota"},
3945         {Opt_ignore, "quota"},
3946         {Opt_usrquota, "usrquota"},
3947 @@ -389,7 +394,20 @@ static int parse_options(char *options,
3948                         }
3949                         break;
3950                 }
3951 -
3952 +#ifndef CONFIG_TAGGING_NONE
3953 +               case Opt_tag:
3954 +                       *flag |= JFS_TAGGED;
3955 +                       break;
3956 +               case Opt_notag:
3957 +                       *flag &= JFS_TAGGED;
3958 +                       break;
3959 +#endif
3960 +#ifdef CONFIG_PROPAGATE
3961 +               case Opt_tagid:
3962 +                       /* use args[0] */
3963 +                       *flag |= JFS_TAGGED;
3964 +                       break;
3965 +#endif
3966                 default:
3967                         printk("jfs: Unrecognized mount option \"%s\" "
3968                                         " or missing value\n", p);
3969 @@ -421,6 +439,12 @@ static int jfs_remount(struct super_bloc
3970                 return -EINVAL;
3971         }
3972  
3973 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
3974 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
3975 +                       sb->s_id);
3976 +               return -EINVAL;
3977 +       }
3978 +
3979         if (newLVSize) {
3980                 if (sb->s_flags & MS_RDONLY) {
3981                         pr_err("JFS: resize requires volume" \
3982 @@ -506,6 +530,9 @@ static int jfs_fill_super(struct super_b
3983  #ifdef CONFIG_JFS_POSIX_ACL
3984         sb->s_flags |= MS_POSIXACL;
3985  #endif
3986 +       /* map mount option tagxid */
3987 +       if (sbi->flag & JFS_TAGGED)
3988 +               sb->s_flags |= MS_TAGGED;
3989  
3990         if (newLVSize) {
3991                 pr_err("resize option for remount only\n");
3992 diff -NurpP --minimal linux-3.13.1/fs/libfs.c linux-3.13.1-vs2.3.6.10/fs/libfs.c
3993 --- linux-3.13.1/fs/libfs.c     2014-01-22 20:39:06.000000000 +0000
3994 +++ linux-3.13.1-vs2.3.6.10/fs/libfs.c  2014-02-01 01:35:46.000000000 +0000
3995 @@ -145,13 +145,14 @@ static inline unsigned char dt_type(stru
3996   * both impossible due to the lock on directory.
3997   */
3998  
3999 -int dcache_readdir(struct file *file, struct dir_context *ctx)
4000 +static inline int do_dcache_readdir_filter(struct file *filp,
4001 +       struct dir_context *ctx, int (*filter)(struct dentry *dentry))
4002  {
4003 -       struct dentry *dentry = file->f_path.dentry;
4004 -       struct dentry *cursor = file->private_data;
4005 +       struct dentry *dentry = filp->f_path.dentry;
4006 +       struct dentry *cursor = filp->private_data;
4007         struct list_head *p, *q = &cursor->d_u.d_child;
4008  
4009 -       if (!dir_emit_dots(file, ctx))
4010 +       if (!dir_emit_dots(filp, ctx))
4011                 return 0;
4012         spin_lock(&dentry->d_lock);
4013         if (ctx->pos == 2)
4014 @@ -159,6 +160,8 @@ int dcache_readdir(struct file *file, st
4015  
4016         for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
4017                 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
4018 +               if (filter && !filter(next))
4019 +                       continue;
4020                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4021                 if (!simple_positive(next)) {
4022                         spin_unlock(&next->d_lock);
4023 @@ -181,8 +184,22 @@ int dcache_readdir(struct file *file, st
4024         spin_unlock(&dentry->d_lock);
4025         return 0;
4026  }
4027 +
4028  EXPORT_SYMBOL(dcache_readdir);
4029  
4030 +int dcache_readdir(struct file *filp, struct dir_context *ctx)
4031 +{
4032 +       return do_dcache_readdir_filter(filp, ctx, NULL);
4033 +}
4034 +
4035 +EXPORT_SYMBOL(dcache_readdir_filter);
4036 +
4037 +int dcache_readdir_filter(struct file *filp, struct dir_context *ctx,
4038 +       int (*filter)(struct dentry *))
4039 +{
4040 +       return do_dcache_readdir_filter(filp, ctx, filter);
4041 +}
4042 +
4043  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4044  {
4045         return -EISDIR;
4046 diff -NurpP --minimal linux-3.13.1/fs/locks.c linux-3.13.1-vs2.3.6.10/fs/locks.c
4047 --- linux-3.13.1/fs/locks.c     2014-01-22 20:39:06.000000000 +0000
4048 +++ linux-3.13.1-vs2.3.6.10/fs/locks.c  2014-01-31 23:51:55.000000000 +0000
4049 @@ -129,6 +129,8 @@
4050  #include <linux/hashtable.h>
4051  #include <linux/percpu.h>
4052  #include <linux/lglock.h>
4053 +#include <linux/vs_base.h>
4054 +#include <linux/vs_limit.h>
4055  
4056  #include <asm/uaccess.h>
4057  
4058 @@ -210,11 +212,17 @@ static void locks_init_lock_heads(struct
4059  /* Allocate an empty lock structure. */
4060  struct file_lock *locks_alloc_lock(void)
4061  {
4062 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4063 +       struct file_lock *fl;
4064  
4065 -       if (fl)
4066 -               locks_init_lock_heads(fl);
4067 +       if (!vx_locks_avail(1))
4068 +               return NULL;
4069  
4070 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4071 +
4072 +       if (fl) {
4073 +               locks_init_lock_heads(fl);
4074 +               fl->fl_xid = -1;
4075 +       }
4076         return fl;
4077  }
4078  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4079 @@ -238,6 +246,7 @@ void locks_free_lock(struct file_lock *f
4080         BUG_ON(!list_empty(&fl->fl_block));
4081         BUG_ON(!hlist_unhashed(&fl->fl_link));
4082  
4083 +       vx_locks_dec(fl);
4084         locks_release_private(fl);
4085         kmem_cache_free(filelock_cache, fl);
4086  }
4087 @@ -247,6 +256,7 @@ void locks_init_lock(struct file_lock *f
4088  {
4089         memset(fl, 0, sizeof(struct file_lock));
4090         locks_init_lock_heads(fl);
4091 +       fl->fl_xid = -1;
4092  }
4093  
4094  EXPORT_SYMBOL(locks_init_lock);
4095 @@ -287,6 +297,7 @@ void locks_copy_lock(struct file_lock *n
4096         new->fl_file = fl->fl_file;
4097         new->fl_ops = fl->fl_ops;
4098         new->fl_lmops = fl->fl_lmops;
4099 +       new->fl_xid = fl->fl_xid;
4100  
4101         locks_copy_private(new, fl);
4102  }
4103 @@ -325,6 +336,11 @@ static int flock_make_lock(struct file *
4104         fl->fl_flags = FL_FLOCK;
4105         fl->fl_type = type;
4106         fl->fl_end = OFFSET_MAX;
4107 +
4108 +       vxd_assert(filp->f_xid == vx_current_xid(),
4109 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4110 +       fl->fl_xid = filp->f_xid;
4111 +       vx_locks_inc(fl);
4112         
4113         *lock = fl;
4114         return 0;
4115 @@ -464,6 +480,7 @@ static int lease_init(struct file *filp,
4116  
4117         fl->fl_owner = current->files;
4118         fl->fl_pid = current->tgid;
4119 +       fl->fl_xid = vx_current_xid();
4120  
4121         fl->fl_file = filp;
4122         fl->fl_flags = FL_LEASE;
4123 @@ -483,6 +500,11 @@ static struct file_lock *lease_alloc(str
4124         if (fl == NULL)
4125                 return ERR_PTR(error);
4126  
4127 +       fl->fl_xid = vx_current_xid();
4128 +       if (filp)
4129 +               vxd_assert(filp->f_xid == fl->fl_xid,
4130 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4131 +       vx_locks_inc(fl);
4132         error = lease_init(filp, type, fl);
4133         if (error) {
4134                 locks_free_lock(fl);
4135 @@ -858,6 +880,7 @@ static int flock_lock_file(struct file *
4136                 spin_lock(&inode->i_lock);
4137         }
4138  
4139 +       new_fl->fl_xid = -1;
4140  find_conflict:
4141         for_each_lock(inode, before) {
4142                 struct file_lock *fl = *before;
4143 @@ -878,6 +901,7 @@ find_conflict:
4144                 goto out;
4145         locks_copy_lock(new_fl, request);
4146         locks_insert_lock(before, new_fl);
4147 +       vx_locks_inc(new_fl);
4148         new_fl = NULL;
4149         error = 0;
4150  
4151 @@ -888,7 +912,8 @@ out:
4152         return error;
4153  }
4154  
4155 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4156 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4157 +       struct file_lock *conflock, vxid_t xid)
4158  {
4159         struct file_lock *fl;
4160         struct file_lock *new_fl = NULL;
4161 @@ -899,6 +924,8 @@ static int __posix_lock_file(struct inod
4162         int error;
4163         bool added = false;
4164  
4165 +       vxd_assert(xid == vx_current_xid(),
4166 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4167         /*
4168          * We may need two file_lock structures for this operation,
4169          * so we get them in advance to avoid races.
4170 @@ -909,7 +936,11 @@ static int __posix_lock_file(struct inod
4171             (request->fl_type != F_UNLCK ||
4172              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4173                 new_fl = locks_alloc_lock();
4174 +               new_fl->fl_xid = xid;
4175 +               vx_locks_inc(new_fl);
4176                 new_fl2 = locks_alloc_lock();
4177 +               new_fl2->fl_xid = xid;
4178 +               vx_locks_inc(new_fl2);
4179         }
4180  
4181         spin_lock(&inode->i_lock);
4182 @@ -1118,7 +1149,8 @@ static int __posix_lock_file(struct inod
4183  int posix_lock_file(struct file *filp, struct file_lock *fl,
4184                         struct file_lock *conflock)
4185  {
4186 -       return __posix_lock_file(file_inode(filp), fl, conflock);
4187 +       return __posix_lock_file(file_inode(filp),
4188 +               fl, conflock, filp->f_xid);
4189  }
4190  EXPORT_SYMBOL(posix_lock_file);
4191  
4192 @@ -1208,7 +1240,7 @@ int locks_mandatory_area(int read_write,
4193         fl.fl_end = offset + count - 1;
4194  
4195         for (;;) {
4196 -               error = __posix_lock_file(inode, &fl, NULL);
4197 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4198                 if (error != FILE_LOCK_DEFERRED)
4199                         break;
4200                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4201 @@ -1549,6 +1581,7 @@ static int generic_add_lease(struct file
4202                 goto out;
4203  
4204         locks_insert_lock(before, lease);
4205 +       vx_locks_inc(lease);
4206         error = 0;
4207  out:
4208         if (is_deleg)
4209 @@ -1991,6 +2024,11 @@ int fcntl_setlk(unsigned int fd, struct
4210         if (file_lock == NULL)
4211                 return -ENOLCK;
4212  
4213 +       vxd_assert(filp->f_xid == vx_current_xid(),
4214 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4215 +       file_lock->fl_xid = filp->f_xid;
4216 +       vx_locks_inc(file_lock);
4217 +
4218         /*
4219          * This might block, so we do it before checking the inode.
4220          */
4221 @@ -2109,6 +2147,11 @@ int fcntl_setlk64(unsigned int fd, struc
4222         if (file_lock == NULL)
4223                 return -ENOLCK;
4224  
4225 +       vxd_assert(filp->f_xid == vx_current_xid(),
4226 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4227 +       file_lock->fl_xid = filp->f_xid;
4228 +       vx_locks_inc(file_lock);
4229 +
4230         /*
4231          * This might block, so we do it before checking the inode.
4232          */
4233 @@ -2378,8 +2421,11 @@ static int locks_show(struct seq_file *f
4234  
4235         lock_get_status(f, fl, iter->li_pos, "");
4236  
4237 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4238 -               lock_get_status(f, bfl, iter->li_pos, " ->");
4239 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4240 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4241 +                       continue;
4242 +               lock_get_status(f, bfl, iter->li_pos, " ->");
4243 +       }
4244  
4245         return 0;
4246  }
4247 diff -NurpP --minimal linux-3.13.1/fs/mount.h linux-3.13.1-vs2.3.6.10/fs/mount.h
4248 --- linux-3.13.1/fs/mount.h     2014-01-22 20:39:06.000000000 +0000
4249 +++ linux-3.13.1-vs2.3.6.10/fs/mount.h  2014-01-31 23:34:30.000000000 +0000
4250 @@ -57,6 +57,7 @@ struct mount {
4251         int mnt_expiry_mark;            /* true if marked for expiry */
4252         int mnt_pinned;
4253         struct path mnt_ex_mountpoint;
4254 +       vtag_t mnt_tag;                 /* tagging used for vfsmount */
4255  };
4256  
4257  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4258 diff -NurpP --minimal linux-3.13.1/fs/namei.c linux-3.13.1-vs2.3.6.10/fs/namei.c
4259 --- linux-3.13.1/fs/namei.c     2014-01-22 20:39:06.000000000 +0000
4260 +++ linux-3.13.1-vs2.3.6.10/fs/namei.c  2014-02-01 01:26:19.000000000 +0000
4261 @@ -34,9 +34,19 @@
4262  #include <linux/device_cgroup.h>
4263  #include <linux/fs_struct.h>
4264  #include <linux/posix_acl.h>
4265 +#include <linux/proc_fs.h>
4266 +#include <linux/magic.h>
4267 +#include <linux/vserver/inode.h>
4268 +#include <linux/vs_base.h>
4269 +#include <linux/vs_tag.h>
4270 +#include <linux/vs_cowbl.h>
4271 +#include <linux/vs_device.h>
4272 +#include <linux/vs_context.h>
4273 +#include <linux/pid_namespace.h>
4274  #include <asm/uaccess.h>
4275  
4276  #include "internal.h"
4277 +#include "proc/internal.h"
4278  #include "mount.h"
4279  
4280  /* [Feb-1997 T. Schoebel-Theuer]
4281 @@ -266,6 +276,89 @@ static int check_acl(struct inode *inode
4282         return -EAGAIN;
4283  }
4284  
4285 +static inline int dx_barrier(const struct inode *inode)
4286 +{
4287 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4288 +               vxwprintk_task(1, "did hit the barrier.");
4289 +               return 1;
4290 +       }
4291 +       return 0;
4292 +}
4293 +
4294 +static int __dx_permission(const struct inode *inode, int mask)
4295 +{
4296 +       if (dx_barrier(inode))
4297 +               return -EACCES;
4298 +
4299 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4300 +               /* devpts is xid tagged */
4301 +               if (S_ISDIR(inode->i_mode) ||
4302 +                   vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4303 +                       return 0;
4304 +
4305 +               /* just pretend we didn't find anything */
4306 +               return -ENOENT;
4307 +       }
4308 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4309 +               struct proc_dir_entry *de = PDE(inode);
4310 +
4311 +               if (de && !vx_hide_check(0, de->vx_flags))
4312 +                       goto out;
4313 +
4314 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4315 +                       struct pid *pid;
4316 +                       struct task_struct *tsk;
4317 +
4318 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4319 +                           vx_flags(VXF_STATE_SETUP, 0))
4320 +                               return 0;
4321 +
4322 +                       pid = PROC_I(inode)->pid;
4323 +                       if (!pid)
4324 +                               goto out;
4325 +
4326 +                       rcu_read_lock();
4327 +                       tsk = pid_task(pid, PIDTYPE_PID);
4328 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4329 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4330 +                       if (tsk &&
4331 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4332 +                               rcu_read_unlock();
4333 +                               return 0;
4334 +                       }
4335 +                       rcu_read_unlock();
4336 +               }
4337 +               else {
4338 +                       /* FIXME: Should we block some entries here? */
4339 +                       return 0;
4340 +               }
4341 +       }
4342 +       else {
4343 +               if (dx_notagcheck(inode->i_sb) ||
4344 +                   dx_check((vxid_t)i_tag_read(inode),
4345 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4346 +                       return 0;
4347 +       }
4348 +
4349 +out:
4350 +       return -EACCES;
4351 +}
4352 +
4353 +int dx_permission(const struct inode *inode, int mask)
4354 +{
4355 +       int ret = __dx_permission(inode, mask);
4356 +       if (unlikely(ret)) {
4357 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4358 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4359 +#endif
4360 +                   vxwprintk_task(1,
4361 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4362 +                       mask, inode->i_sb->s_id, inode,
4363 +                       i_tag_read(inode), inode->i_ino);
4364 +       }
4365 +       return ret;
4366 +}
4367 +
4368  /*
4369   * This does the basic permission checking
4370   */
4371 @@ -388,10 +481,14 @@ int __inode_permission(struct inode *ino
4372                 /*
4373                  * Nobody gets write access to an immutable file.
4374                  */
4375 -               if (IS_IMMUTABLE(inode))
4376 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4377                         return -EACCES;
4378         }
4379  
4380 +       retval = dx_permission(inode, mask);
4381 +       if (retval)
4382 +               return retval;
4383 +
4384         retval = do_inode_permission(inode, mask);
4385         if (retval)
4386                 return retval;
4387 @@ -1241,7 +1338,8 @@ static void follow_dotdot(struct nameida
4388  
4389                 if (nd->path.dentry == nd->root.dentry &&
4390                     nd->path.mnt == nd->root.mnt) {
4391 -                       break;
4392 +                       /* for sane '/' avoid follow_mount() */
4393 +                       return;
4394                 }
4395                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4396                         /* rare case of legitimate dget_parent()... */
4397 @@ -1386,6 +1484,9 @@ static int lookup_fast(struct nameidata
4398                                 goto unlazy;
4399                         }
4400                 }
4401 +
4402 +               /* FIXME: check dx permission */
4403 +
4404                 path->mnt = mnt;
4405                 path->dentry = dentry;
4406                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4407 @@ -1416,6 +1517,8 @@ unlazy:
4408                 }
4409         }
4410  
4411 +       /* FIXME: check dx permission */
4412 +
4413         path->mnt = mnt;
4414         path->dentry = dentry;
4415         err = follow_managed(path, nd->flags);
4416 @@ -2403,7 +2506,7 @@ static int may_delete(struct inode *dir,
4417                 return -EPERM;
4418  
4419         if (check_sticky(dir, inode) || IS_APPEND(inode) ||
4420 -           IS_IMMUTABLE(inode) || IS_SWAPFILE(inode))
4421 +               IS_IXORUNLINK(inode) || IS_SWAPFILE(inode))
4422                 return -EPERM;
4423         if (isdir) {
4424                 if (!d_is_directory(victim) && !d_is_autodir(victim))
4425 @@ -2483,19 +2586,25 @@ int vfs_create(struct inode *dir, struct
4426                 bool want_excl)
4427  {
4428         int error = may_create(dir, dentry);
4429 -       if (error)
4430 +       if (error) {
4431 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4432                 return error;
4433 +       }
4434  
4435         if (!dir->i_op->create)
4436                 return -EACCES; /* shouldn't it be ENOSYS? */
4437         mode &= S_IALLUGO;
4438         mode |= S_IFREG;
4439         error = security_inode_create(dir, dentry, mode);
4440 -       if (error)
4441 +       if (error) {
4442 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4443                 return error;
4444 +       }
4445         error = dir->i_op->create(dir, dentry, mode, want_excl);
4446         if (!error)
4447                 fsnotify_create(dir, dentry);
4448 +       else
4449 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4450         return error;
4451  }
4452  
4453 @@ -2530,6 +2639,15 @@ static int may_open(struct path *path, i
4454                 break;
4455         }
4456  
4457 +#ifdef CONFIG_VSERVER_COWBL
4458 +       if (IS_COW(inode) &&
4459 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4460 +               if (IS_COW_LINK(inode))
4461 +                       return -EMLINK;
4462 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4463 +               mark_inode_dirty(inode);
4464 +       }
4465 +#endif
4466         error = inode_permission(inode, acc_mode);
4467         if (error)
4468                 return error;
4469 @@ -3025,6 +3143,16 @@ finish_open:
4470         }
4471  finish_open_created:
4472         error = may_open(&nd->path, acc_mode, open_flag);
4473 +#ifdef CONFIG_VSERVER_COWBL
4474 +       if (error == -EMLINK) {
4475 +               struct dentry *dentry;
4476 +               dentry = cow_break_link(name->name);
4477 +               if (IS_ERR(dentry))
4478 +                       error = PTR_ERR(dentry);
4479 +               else
4480 +                       dput(dentry);
4481 +       }
4482 +#endif
4483         if (error)
4484                 goto out;
4485         file->f_path.mnt = nd->path.mnt;
4486 @@ -3150,6 +3278,7 @@ static struct file *path_openat(int dfd,
4487         int opened = 0;
4488         int error;
4489  
4490 +restart:
4491         file = get_empty_filp();
4492         if (IS_ERR(file))
4493                 return file;
4494 @@ -3191,6 +3320,16 @@ static struct file *path_openat(int dfd,
4495                 error = do_last(nd, &path, file, op, &opened, pathname);
4496                 put_link(nd, &link, cookie);
4497         }
4498 +
4499 +#ifdef CONFIG_VSERVER_COWBL
4500 +       if (error == -EMLINK) {
4501 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4502 +                       path_put(&nd->root);
4503 +               if (base)
4504 +                       fput(base);
4505 +               goto restart;
4506 +       }
4507 +#endif
4508  out:
4509         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4510                 path_put(&nd->root);
4511 @@ -3306,6 +3445,11 @@ struct dentry *kern_path_create(int dfd,
4512                 goto fail;
4513         }
4514         *path = nd.path;
4515 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4516 +               path->dentry, path->dentry->d_name.len,
4517 +               path->dentry->d_name.name, dentry,
4518 +               dentry->d_name.len, dentry->d_name.name,
4519 +               path->dentry->d_inode);
4520         return dentry;
4521  fail:
4522         dput(dentry);
4523 @@ -3853,7 +3997,7 @@ int vfs_link(struct dentry *old_dentry,
4524         /*
4525          * A link to an append-only or immutable file cannot be created.
4526          */
4527 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4528 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4529                 return -EPERM;
4530         if (!dir->i_op->link)
4531                 return -EPERM;
4532 @@ -4305,6 +4449,287 @@ int generic_readlink(struct dentry *dent
4533         return res;
4534  }
4535  
4536 +
4537 +#ifdef CONFIG_VSERVER_COWBL
4538 +
4539 +static inline
4540 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4541 +{
4542 +       loff_t ppos = 0;
4543 +       loff_t opos = 0;
4544 +
4545 +       return do_splice_direct(in, &ppos, out, &opos, len, 0);
4546 +}
4547 +
4548 +struct dentry *cow_break_link(const char *pathname)
4549 +{
4550 +       int ret, mode, pathlen, redo = 0, drop = 1;
4551 +       struct nameidata old_nd, dir_nd;
4552 +       struct path dir_path, *old_path, *new_path;
4553 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4554 +       struct file *old_file;
4555 +       struct file *new_file;
4556 +       char *to, *path, pad='\251';
4557 +       loff_t size;
4558 +
4559 +       vxdprintk(VXD_CBIT(misc, 1),
4560 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4561 +
4562 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4563 +       ret = -ENOMEM;
4564 +       if (!path)
4565 +               goto out;
4566 +
4567 +       /* old_nd.path will have refs to dentry and mnt */
4568 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4569 +       vxdprintk(VXD_CBIT(misc, 2),
4570 +               "do_path_lookup(old): %d", ret);
4571 +       if (ret < 0)
4572 +               goto out_free_path;
4573 +
4574 +       /* dentry/mnt refs handed over to old_path */
4575 +       old_path = &old_nd.path;
4576 +       /* no explicit reference for old_dentry here */
4577 +       old_dentry = old_path->dentry;
4578 +
4579 +       mode = old_dentry->d_inode->i_mode;
4580 +       to = d_path(old_path, path, PATH_MAX-2);
4581 +       pathlen = strlen(to);
4582 +       vxdprintk(VXD_CBIT(misc, 2),
4583 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4584 +               old_dentry,
4585 +               old_dentry->d_name.len, old_dentry->d_name.name,
4586 +               old_dentry->d_name.len);
4587 +
4588 +       to[pathlen + 1] = 0;
4589 +retry:
4590 +       new_dentry = NULL;
4591 +       to[pathlen] = pad--;
4592 +       ret = -ELOOP;
4593 +       if (pad <= '\240')
4594 +               goto out_rel_old;
4595 +
4596 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4597 +
4598 +       /* dir_nd.path will have refs to dentry and mnt */
4599 +       ret = do_path_lookup(AT_FDCWD, to,
4600 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4601 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4602 +       if (ret < 0)
4603 +               goto retry;
4604 +
4605 +       /* this puppy downs the dir inode mutex if successful.
4606 +          dir_path will hold refs to dentry and mnt and
4607 +          we'll have write access to the mnt */
4608 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4609 +       if (!new_dentry || IS_ERR(new_dentry)) {
4610 +               path_put(&dir_nd.path);
4611 +               vxdprintk(VXD_CBIT(misc, 2),
4612 +                       "kern_path_create(new) failed with %ld",
4613 +                       PTR_ERR(new_dentry));
4614 +               goto retry;
4615 +       }
4616 +       vxdprintk(VXD_CBIT(misc, 2),
4617 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4618 +               new_dentry,
4619 +               new_dentry->d_name.len, new_dentry->d_name.name,
4620 +               new_dentry->d_name.len);
4621 +
4622 +       /* take a reference on new_dentry */
4623 +       dget(new_dentry);
4624 +
4625 +       /* dentry/mnt refs handed over to new_path */
4626 +       new_path = &dir_path;
4627 +
4628 +       /* dentry for old/new dir */
4629 +       dir = dir_nd.path.dentry;
4630 +
4631 +       /* give up reference on dir */
4632 +       dput(new_path->dentry);
4633 +
4634 +       /* new_dentry already has a reference */
4635 +       new_path->dentry = new_dentry;
4636 +
4637 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4638 +       vxdprintk(VXD_CBIT(misc, 2),
4639 +               "vfs_create(new): %d", ret);
4640 +       if (ret == -EEXIST) {
4641 +               path_put(&dir_nd.path);
4642 +               mutex_unlock(&dir->d_inode->i_mutex);
4643 +               mnt_drop_write(new_path->mnt);
4644 +               path_put(new_path);
4645 +               new_dentry = NULL;
4646 +               goto retry;
4647 +       }
4648 +       else if (ret < 0)
4649 +               goto out_unlock_new;
4650 +
4651 +       /* drop out early, ret passes ENOENT */
4652 +       ret = -ENOENT;
4653 +       if ((redo = d_unhashed(old_dentry)))
4654 +               goto out_unlock_new;
4655 +
4656 +       /* doesn't change refs for old_path */
4657 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4658 +       vxdprintk(VXD_CBIT(misc, 2),
4659 +               "dentry_open(old): %p", old_file);
4660 +       if (IS_ERR(old_file)) {
4661 +               ret = PTR_ERR(old_file);
4662 +               goto out_unlock_new;
4663 +       }
4664 +
4665 +       /* doesn't change refs for new_path */
4666 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4667 +       vxdprintk(VXD_CBIT(misc, 2),
4668 +               "dentry_open(new): %p", new_file);
4669 +       if (IS_ERR(new_file)) {
4670 +               ret = PTR_ERR(new_file);
4671 +               goto out_fput_old;
4672 +       }
4673 +
4674 +       /* unlock the inode mutex from kern_path_create() */
4675 +       mutex_unlock(&dir->d_inode->i_mutex);
4676 +
4677 +       /* drop write access to mnt */
4678 +       mnt_drop_write(new_path->mnt);
4679 +
4680 +       drop = 0;
4681 +
4682 +       size = i_size_read(old_file->f_dentry->d_inode);
4683 +       ret = do_cow_splice(old_file, new_file, size);
4684 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4685 +       if (ret < 0) {
4686 +               goto out_fput_both;
4687 +       } else if (ret < size) {
4688 +               ret = -ENOSPC;
4689 +               goto out_fput_both;
4690 +       } else {
4691 +               struct inode *old_inode = old_dentry->d_inode;
4692 +               struct inode *new_inode = new_dentry->d_inode;
4693 +               struct iattr attr = {
4694 +                       .ia_uid = old_inode->i_uid,
4695 +                       .ia_gid = old_inode->i_gid,
4696 +                       .ia_valid = ATTR_UID | ATTR_GID
4697 +                       };
4698 +
4699 +               setattr_copy(new_inode, &attr);
4700 +               mark_inode_dirty(new_inode);
4701 +       }
4702 +
4703 +       /* lock rename mutex */
4704 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4705 +
4706 +       /* drop out late */
4707 +       ret = -ENOENT;
4708 +       if ((redo = d_unhashed(old_dentry)))
4709 +               goto out_unlock;
4710 +
4711 +       vxdprintk(VXD_CBIT(misc, 2),
4712 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4713 +               new_dentry->d_name.len, new_dentry->d_name.name,
4714 +               new_dentry->d_name.len,
4715 +               old_dentry->d_name.len, old_dentry->d_name.name,
4716 +               old_dentry->d_name.len);
4717 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4718 +               old_dentry->d_parent->d_inode, old_dentry, NULL);
4719 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4720 +
4721 +out_unlock:
4722 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4723 +
4724 +out_fput_both:
4725 +       vxdprintk(VXD_CBIT(misc, 3),
4726 +               "fput(new_file=%p[#%ld])", new_file,
4727 +               atomic_long_read(&new_file->f_count));
4728 +       fput(new_file);
4729 +
4730 +out_fput_old:
4731 +       vxdprintk(VXD_CBIT(misc, 3),
4732 +               "fput(old_file=%p[#%ld])", old_file,
4733 +               atomic_long_read(&old_file->f_count));
4734 +       fput(old_file);
4735 +
4736 +out_unlock_new:
4737 +       /* drop references from dir_nd.path */
4738 +       path_put(&dir_nd.path);
4739 +
4740 +       if (drop) {
4741 +               /* unlock the inode mutex from kern_path_create() */
4742 +               mutex_unlock(&dir->d_inode->i_mutex);
4743 +
4744 +               /* drop write access to mnt */
4745 +               mnt_drop_write(new_path->mnt);
4746 +       }
4747 +
4748 +       if (!ret)
4749 +               goto out_redo;
4750 +
4751 +       /* error path cleanup */
4752 +       vfs_unlink(dir->d_inode, new_dentry, NULL);
4753 +
4754 +out_redo:
4755 +       if (!redo)
4756 +               goto out_rel_both;
4757 +
4758 +       /* lookup dentry once again
4759 +          old_nd.path will be freed as old_path in out_rel_old */
4760 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4761 +       if (ret)
4762 +               goto out_rel_both;
4763 +
4764 +       /* drop reference on new_dentry */
4765 +       dput(new_dentry);
4766 +       new_dentry = old_path->dentry;
4767 +       dget(new_dentry);
4768 +       vxdprintk(VXD_CBIT(misc, 2),
4769 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4770 +               new_dentry,
4771 +               new_dentry->d_name.len, new_dentry->d_name.name,
4772 +               new_dentry->d_name.len);
4773 +
4774 +out_rel_both:
4775 +       if (new_path)
4776 +               path_put(new_path);
4777 +out_rel_old:
4778 +       path_put(old_path);
4779 +out_free_path:
4780 +       kfree(path);
4781 +out:
4782 +       if (ret) {
4783 +               dput(new_dentry);
4784 +               new_dentry = ERR_PTR(ret);
4785 +       }
4786 +       vxdprintk(VXD_CBIT(misc, 3),
4787 +               "cow_break_link returning with %p", new_dentry);
4788 +       return new_dentry;
4789 +}
4790 +
4791 +#endif
4792 +
4793 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4794 +{
4795 +       struct path path;
4796 +       struct vfsmount *vmnt;
4797 +       char *pstr, *root;
4798 +       int length = 0;
4799 +
4800 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4801 +       if (!pstr)
4802 +               return 0;
4803 +
4804 +       vmnt = &ns->root->mnt;
4805 +       path.mnt = vmnt;
4806 +       path.dentry = vmnt->mnt_root;
4807 +       root = d_path(&path, pstr, PATH_MAX - 2);
4808 +       length = sprintf(buffer + length,
4809 +               "Namespace:\t%p [#%u]\n"
4810 +               "RootPath:\t%s\n",
4811 +               ns, atomic_read(&ns->count),
4812 +               root);
4813 +       kfree(pstr);
4814 +       return length;
4815 +}
4816 +
4817  /* get the link contents into pagecache */
4818  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4819  {
4820 @@ -4427,3 +4852,4 @@ EXPORT_SYMBOL(vfs_symlink);
4821  EXPORT_SYMBOL(vfs_unlink);
4822  EXPORT_SYMBOL(dentry_unhash);
4823  EXPORT_SYMBOL(generic_readlink);
4824 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4825 diff -NurpP --minimal linux-3.13.1/fs/namespace.c linux-3.13.1-vs2.3.6.10/fs/namespace.c
4826 --- linux-3.13.1/fs/namespace.c 2014-01-22 20:39:06.000000000 +0000
4827 +++ linux-3.13.1-vs2.3.6.10/fs/namespace.c      2014-01-31 23:44:28.000000000 +0000
4828 @@ -23,6 +23,11 @@
4829  #include <linux/uaccess.h>
4830  #include <linux/proc_ns.h>
4831  #include <linux/magic.h>
4832 +#include <linux/vs_base.h>
4833 +#include <linux/vs_context.h>
4834 +#include <linux/vs_tag.h>
4835 +#include <linux/vserver/space.h>
4836 +#include <linux/vserver/global.h>
4837  #include "pnode.h"
4838  #include "internal.h"
4839  
4840 @@ -803,6 +808,10 @@ vfs_kern_mount(struct file_system_type *
4841         if (!type)
4842                 return ERR_PTR(-ENODEV);
4843  
4844 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4845 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4846 +               return ERR_PTR(-EPERM);
4847 +
4848         mnt = alloc_vfsmnt(name);
4849         if (!mnt)
4850                 return ERR_PTR(-ENOMEM);
4851 @@ -863,6 +872,7 @@ static struct mount *clone_mnt(struct mo
4852         mnt->mnt.mnt_root = dget(root);
4853         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4854         mnt->mnt_parent = mnt;
4855 +       mnt->mnt_tag = old->mnt_tag;
4856         lock_mount_hash();
4857         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4858         unlock_mount_hash();
4859 @@ -1323,7 +1333,8 @@ static int do_umount(struct mount *mnt,
4860   */
4861  static inline bool may_mount(void)
4862  {
4863 -       return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4864 +       return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4865 +               CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4866  }
4867  
4868  /*
4869 @@ -1738,6 +1749,7 @@ static int do_change_type(struct path *p
4870                 if (err)
4871                         goto out_unlock;
4872         }
4873 +       // mnt->mnt_flags = mnt_flags;
4874  
4875         lock_mount_hash();
4876         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4877 @@ -1766,12 +1778,14 @@ static bool has_locked_children(struct m
4878   * do loopback mount.
4879   */
4880  static int do_loopback(struct path *path, const char *old_name,
4881 -                               int recurse)
4882 +       vtag_t tag, unsigned long flags, int mnt_flags)
4883  {
4884         struct path old_path;
4885         struct mount *mnt = NULL, *old, *parent;
4886         struct mountpoint *mp;
4887 +       int recurse = flags & MS_REC;
4888         int err;
4889 +
4890         if (!old_name || !*old_name)
4891                 return -EINVAL;
4892         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4893 @@ -1851,7 +1865,7 @@ static int change_mount_flags(struct vfs
4894   * on it - tough luck.
4895   */
4896  static int do_remount(struct path *path, int flags, int mnt_flags,
4897 -                     void *data)
4898 +       void *data, vxid_t xid)
4899  {
4900         int err;
4901         struct super_block *sb = path->mnt->mnt_sb;
4902 @@ -2330,6 +2344,7 @@ long do_mount(const char *dev_name, cons
4903         struct path path;
4904         int retval = 0;
4905         int mnt_flags = 0;
4906 +       vtag_t tag = 0;
4907  
4908         /* Discard magic */
4909         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4910 @@ -2359,6 +2374,12 @@ long do_mount(const char *dev_name, cons
4911         if (!(flags & MS_NOATIME))
4912                 mnt_flags |= MNT_RELATIME;
4913  
4914 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4915 +               /* FIXME: bind and re-mounts get the tag flag? */
4916 +               if (flags & (MS_BIND|MS_REMOUNT))
4917 +                       flags |= MS_TAGID;
4918 +       }
4919 +
4920         /* Separate the per-mountpoint flags */
4921         if (flags & MS_NOSUID)
4922                 mnt_flags |= MNT_NOSUID;
4923 @@ -2375,15 +2396,17 @@ long do_mount(const char *dev_name, cons
4924         if (flags & MS_RDONLY)
4925                 mnt_flags |= MNT_READONLY;
4926  
4927 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4928 +               mnt_flags |= MNT_NODEV;
4929         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4930                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4931                    MS_STRICTATIME);
4932  
4933         if (flags & MS_REMOUNT)
4934                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4935 -                                   data_page);
4936 +                                   data_page, tag);
4937         else if (flags & MS_BIND)
4938 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
4939 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4940         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4941                 retval = do_change_type(&path, flags);
4942         else if (flags & MS_MOVE)
4943 @@ -2499,6 +2522,7 @@ struct mnt_namespace *copy_mnt_ns(unsign
4944                         p = next_mnt(p, old);
4945         }
4946         namespace_unlock();
4947 +       atomic_inc(&vs_global_mnt_ns);
4948  
4949         if (rootmnt)
4950                 mntput(rootmnt);
4951 @@ -2680,9 +2704,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4952         new_mnt = real_mount(new.mnt);
4953         root_mnt = real_mount(root.mnt);
4954         old_mnt = real_mount(old.mnt);
4955 -       if (IS_MNT_SHARED(old_mnt) ||
4956 +       if ((IS_MNT_SHARED(old_mnt) ||
4957                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4958 -               IS_MNT_SHARED(root_mnt->mnt_parent))
4959 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4960 +               !vx_flags(VXF_STATE_SETUP, 0))
4961                 goto out4;
4962         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4963                 goto out4;
4964 @@ -2806,6 +2831,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4965         if (!atomic_dec_and_test(&ns->count))
4966                 return;
4967         drop_collected_mounts(&ns->root->mnt);
4968 +       atomic_dec(&vs_global_mnt_ns);
4969         free_mnt_ns(ns);
4970  }
4971  
4972 diff -NurpP --minimal linux-3.13.1/fs/nfs/client.c linux-3.13.1-vs2.3.6.10/fs/nfs/client.c
4973 --- linux-3.13.1/fs/nfs/client.c        2014-01-22 20:39:06.000000000 +0000
4974 +++ linux-3.13.1-vs2.3.6.10/fs/nfs/client.c     2014-01-31 20:38:03.000000000 +0000
4975 @@ -685,6 +685,9 @@ int nfs_init_server_rpcclient(struct nfs
4976         if (server->flags & NFS_MOUNT_SOFT)
4977                 server->client->cl_softrtry = 1;
4978  
4979 +       server->client->cl_tag = 0;
4980 +       if (server->flags & NFS_MOUNT_TAGGED)
4981 +               server->client->cl_tag = 1;
4982         return 0;
4983  }
4984  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4985 @@ -863,6 +866,10 @@ static void nfs_server_set_fsinfo(struct
4986                 server->acdirmin = server->acdirmax = 0;
4987         }
4988  
4989 +       /* FIXME: needs fsinfo
4990 +       if (server->flags & NFS_MOUNT_TAGGED)
4991 +               sb->s_flags |= MS_TAGGED;       */
4992 +
4993         server->maxfilesize = fsinfo->maxfilesize;
4994  
4995         server->time_delta = fsinfo->time_delta;
4996 diff -NurpP --minimal linux-3.13.1/fs/nfs/dir.c linux-3.13.1-vs2.3.6.10/fs/nfs/dir.c
4997 --- linux-3.13.1/fs/nfs/dir.c   2014-01-22 20:39:06.000000000 +0000
4998 +++ linux-3.13.1-vs2.3.6.10/fs/nfs/dir.c        2014-01-31 20:38:03.000000000 +0000
4999 @@ -37,6 +37,7 @@
5000  #include <linux/sched.h>
5001  #include <linux/kmemleak.h>
5002  #include <linux/xattr.h>
5003 +#include <linux/vs_tag.h>
5004  
5005  #include "delegation.h"
5006  #include "iostat.h"
5007 @@ -1319,6 +1320,7 @@ struct dentry *nfs_lookup(struct inode *
5008         /* Success: notify readdir to use READDIRPLUS */
5009         nfs_advise_use_readdirplus(dir);
5010  
5011 +       dx_propagate_tag(nd, inode);
5012  no_entry:
5013         res = d_materialise_unique(dentry, inode);
5014         if (res != NULL) {
5015 diff -NurpP --minimal linux-3.13.1/fs/nfs/inode.c linux-3.13.1-vs2.3.6.10/fs/nfs/inode.c
5016 --- linux-3.13.1/fs/nfs/inode.c 2014-01-22 20:39:06.000000000 +0000
5017 +++ linux-3.13.1-vs2.3.6.10/fs/nfs/inode.c      2014-01-31 22:44:31.000000000 +0000
5018 @@ -38,6 +38,7 @@
5019  #include <linux/slab.h>
5020  #include <linux/compat.h>
5021  #include <linux/freezer.h>
5022 +#include <linux/vs_tag.h>
5023  
5024  #include <asm/uaccess.h>
5025  
5026 @@ -352,6 +353,8 @@ nfs_fhget(struct super_block *sb, struct
5027         if (inode->i_state & I_NEW) {
5028                 struct nfs_inode *nfsi = NFS_I(inode);
5029                 unsigned long now = jiffies;
5030 +               kuid_t kuid;
5031 +               kgid_t kgid;
5032  
5033                 /* We set i_ino for the few things that still rely on it,
5034                  * such as stat(2) */
5035 @@ -396,8 +399,8 @@ nfs_fhget(struct super_block *sb, struct
5036                 inode->i_version = 0;
5037                 inode->i_size = 0;
5038                 clear_nlink(inode);
5039 -               inode->i_uid = make_kuid(&init_user_ns, -2);
5040 -               inode->i_gid = make_kgid(&init_user_ns, -2);
5041 +               kuid = make_kuid(&init_user_ns, -2);
5042 +               kgid = make_kgid(&init_user_ns, -2);
5043                 inode->i_blocks = 0;
5044                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5045                 nfsi->write_io = 0;
5046 @@ -431,11 +434,11 @@ nfs_fhget(struct super_block *sb, struct
5047                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5048                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5049                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5050 -                       inode->i_uid = fattr->uid;
5051 +                       kuid = fattr->uid;
5052                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5053                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5054                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5055 -                       inode->i_gid = fattr->gid;
5056 +                       kgid = fattr->gid;
5057                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5058                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5059                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5060 @@ -446,6 +449,10 @@ nfs_fhget(struct super_block *sb, struct
5061                          */
5062                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5063                 }
5064 +               inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5065 +               inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5066 +               inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
5067 +                               /* maybe fattr->xid someday */
5068  
5069                 nfs_setsecurity(inode, fattr, label);
5070  
5071 @@ -571,6 +578,8 @@ void nfs_setattr_update_inode(struct ino
5072                         inode->i_uid = attr->ia_uid;
5073                 if ((attr->ia_valid & ATTR_GID) != 0)
5074                         inode->i_gid = attr->ia_gid;
5075 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5076 +                       inode->i_tag = attr->ia_tag;
5077                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5078                 spin_unlock(&inode->i_lock);
5079         }
5080 @@ -1085,7 +1094,9 @@ static int nfs_check_inode_attributes(st
5081         struct nfs_inode *nfsi = NFS_I(inode);
5082         loff_t cur_size, new_isize;
5083         unsigned long invalid = 0;
5084 -
5085 +       kuid_t kuid;
5086 +       kgid_t kgid;
5087 +       ktag_t ktag;
5088  
5089         if (nfs_have_delegated_attributes(inode))
5090                 return 0;
5091 @@ -1110,13 +1121,18 @@ static int nfs_check_inode_attributes(st
5092                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5093         }
5094  
5095 +       kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
5096 +       kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
5097 +       ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
5098 +
5099         /* Have any file permissions changed? */
5100         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5101                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5102 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5103 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5104                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5105 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5106 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5107                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5108 +               /* maybe check for tag too? */
5109  
5110         /* Has the link count changed? */
5111         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5112 @@ -1433,6 +1449,9 @@ static int nfs_update_inode(struct inode
5113         unsigned long invalid = 0;
5114         unsigned long now = jiffies;
5115         unsigned long save_cache_validity;
5116 +       kuid_t kuid;
5117 +       kgid_t kgid;
5118 +       ktag_t ktag;
5119  
5120         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5121                         __func__, inode->i_sb->s_id, inode->i_ino,
5122 @@ -1534,6 +1553,9 @@ static int nfs_update_inode(struct inode
5123                                 | NFS_INO_REVAL_PAGECACHE
5124                                 | NFS_INO_REVAL_FORCED);
5125  
5126 +       kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5127 +       kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5128 +       ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
5129  
5130         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5131                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5132 @@ -1576,6 +1598,10 @@ static int nfs_update_inode(struct inode
5133                                 | NFS_INO_INVALID_ACL
5134                                 | NFS_INO_REVAL_FORCED);
5135  
5136 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5137 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5138 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
5139 +
5140         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5141                 if (inode->i_nlink != fattr->nlink) {
5142                         invalid |= NFS_INO_INVALID_ATTR;
5143 diff -NurpP --minimal linux-3.13.1/fs/nfs/nfs3xdr.c linux-3.13.1-vs2.3.6.10/fs/nfs/nfs3xdr.c
5144 --- linux-3.13.1/fs/nfs/nfs3xdr.c       2013-05-31 13:45:24.000000000 +0000
5145 +++ linux-3.13.1-vs2.3.6.10/fs/nfs/nfs3xdr.c    2014-01-31 20:38:03.000000000 +0000
5146 @@ -20,6 +20,7 @@
5147  #include <linux/nfs3.h>
5148  #include <linux/nfs_fs.h>
5149  #include <linux/nfsacl.h>
5150 +#include <linux/vs_tag.h>
5151  #include "internal.h"
5152  
5153  #define NFSDBG_FACILITY                NFSDBG_XDR
5154 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5155   *             set_mtime       mtime;
5156   *     };
5157   */
5158 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5159 +static void encode_sattr3(struct xdr_stream *xdr,
5160 +       const struct iattr *attr, int tag)
5161  {
5162         u32 nbytes;
5163         __be32 *p;
5164 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5165         } else
5166                 *p++ = xdr_zero;
5167  
5168 -       if (attr->ia_valid & ATTR_UID) {
5169 +       if (attr->ia_valid & ATTR_UID ||
5170 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5171                 *p++ = xdr_one;
5172 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5173 +               *p++ = cpu_to_be32(from_kuid(&init_user_ns,
5174 +                       TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
5175         } else
5176                 *p++ = xdr_zero;
5177  
5178 -       if (attr->ia_valid & ATTR_GID) {
5179 +       if (attr->ia_valid & ATTR_GID ||
5180 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5181                 *p++ = xdr_one;
5182 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5183 +               *p++ = cpu_to_be32(from_kgid(&init_user_ns,
5184 +                       TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
5185         } else
5186                 *p++ = xdr_zero;
5187  
5188 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5189                                       const struct nfs3_sattrargs *args)
5190  {
5191         encode_nfs_fh3(xdr, args->fh);
5192 -       encode_sattr3(xdr, args->sattr);
5193 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5194         encode_sattrguard3(xdr, args);
5195  }
5196  
5197 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5198   *     };
5199   */
5200  static void encode_createhow3(struct xdr_stream *xdr,
5201 -                             const struct nfs3_createargs *args)
5202 +       const struct nfs3_createargs *args, int tag)
5203  {
5204         encode_uint32(xdr, args->createmode);
5205         switch (args->createmode) {
5206         case NFS3_CREATE_UNCHECKED:
5207         case NFS3_CREATE_GUARDED:
5208 -               encode_sattr3(xdr, args->sattr);
5209 +               encode_sattr3(xdr, args->sattr, tag);
5210                 break;
5211         case NFS3_CREATE_EXCLUSIVE:
5212                 encode_createverf3(xdr, args->verifier);
5213 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5214                                      const struct nfs3_createargs *args)
5215  {
5216         encode_diropargs3(xdr, args->fh, args->name, args->len);
5217 -       encode_createhow3(xdr, args);
5218 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5219  }
5220  
5221  /*
5222 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5223                                     const struct nfs3_mkdirargs *args)
5224  {
5225         encode_diropargs3(xdr, args->fh, args->name, args->len);
5226 -       encode_sattr3(xdr, args->sattr);
5227 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5228  }
5229  
5230  /*
5231 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5232   *     };
5233   */
5234  static void encode_symlinkdata3(struct xdr_stream *xdr,
5235 -                               const struct nfs3_symlinkargs *args)
5236 +       const struct nfs3_symlinkargs *args, int tag)
5237  {
5238 -       encode_sattr3(xdr, args->sattr);
5239 +       encode_sattr3(xdr, args->sattr, tag);
5240         encode_nfspath3(xdr, args->pages, args->pathlen);
5241  }
5242  
5243 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5244                                       const struct nfs3_symlinkargs *args)
5245  {
5246         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5247 -       encode_symlinkdata3(xdr, args);
5248 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5249  }
5250  
5251  /*
5252 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5253   *     };
5254   */
5255  static void encode_devicedata3(struct xdr_stream *xdr,
5256 -                              const struct nfs3_mknodargs *args)
5257 +       const struct nfs3_mknodargs *args, int tag)
5258  {
5259 -       encode_sattr3(xdr, args->sattr);
5260 +       encode_sattr3(xdr, args->sattr, tag);
5261         encode_specdata3(xdr, args->rdev);
5262  }
5263  
5264  static void encode_mknoddata3(struct xdr_stream *xdr,
5265 -                             const struct nfs3_mknodargs *args)
5266 +       const struct nfs3_mknodargs *args, int tag)
5267  {
5268         encode_ftype3(xdr, args->type);
5269         switch (args->type) {
5270         case NF3CHR:
5271         case NF3BLK:
5272 -               encode_devicedata3(xdr, args);
5273 +               encode_devicedata3(xdr, args, tag);
5274                 break;
5275         case NF3SOCK:
5276         case NF3FIFO:
5277 -               encode_sattr3(xdr, args->sattr);
5278 +               encode_sattr3(xdr, args->sattr, tag);
5279                 break;
5280         case NF3REG:
5281         case NF3DIR:
5282 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5283                                     const struct nfs3_mknodargs *args)
5284  {
5285         encode_diropargs3(xdr, args->fh, args->name, args->len);
5286 -       encode_mknoddata3(xdr, args);
5287 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5288  }
5289  
5290  /*
5291 diff -NurpP --minimal linux-3.13.1/fs/nfs/super.c linux-3.13.1-vs2.3.6.10/fs/nfs/super.c
5292 --- linux-3.13.1/fs/nfs/super.c 2014-01-22 20:39:06.000000000 +0000
5293 +++ linux-3.13.1-vs2.3.6.10/fs/nfs/super.c      2014-01-31 20:38:03.000000000 +0000
5294 @@ -55,6 +55,7 @@
5295  #include <linux/parser.h>
5296  #include <linux/nsproxy.h>
5297  #include <linux/rcupdate.h>
5298 +#include <linux/vs_tag.h>
5299  
5300  #include <asm/uaccess.h>
5301  
5302 @@ -103,6 +104,7 @@ enum {
5303         Opt_mountport,
5304         Opt_mountvers,
5305         Opt_minorversion,
5306 +       Opt_tagid,
5307  
5308         /* Mount options that take string arguments */
5309         Opt_nfsvers,
5310 @@ -115,6 +117,9 @@ enum {
5311         /* Special mount options */
5312         Opt_userspace, Opt_deprecated, Opt_sloppy,
5313  
5314 +       /* Linux-VServer tagging options */
5315 +       Opt_tag, Opt_notag,
5316 +
5317         Opt_err
5318  };
5319  
5320 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5321         { Opt_fscache_uniq, "fsc=%s" },
5322         { Opt_local_lock, "local_lock=%s" },
5323  
5324 +       { Opt_tag, "tag" },
5325 +       { Opt_notag, "notag" },
5326 +       { Opt_tagid, "tagid=%u" },
5327 +
5328         /* The following needs to be listed after all other options */
5329         { Opt_nfsvers, "v%s" },
5330  
5331 @@ -638,6 +647,7 @@ static void nfs_show_mount_options(struc
5332                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5333                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5334                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5335 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5336                 { 0, NULL, NULL }
5337         };
5338         const struct proc_nfs_info *nfs_infop;
5339 @@ -1321,6 +1331,14 @@ static int nfs_parse_mount_options(char
5340                 case Opt_nomigration:
5341                         mnt->options &= NFS_OPTION_MIGRATION;
5342                         break;
5343 +#ifndef CONFIG_TAGGING_NONE
5344 +               case Opt_tag:
5345 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5346 +                       break;
5347 +               case Opt_notag:
5348 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5349 +                       break;
5350 +#endif
5351  
5352                 /*
5353                  * options that take numeric values
5354 @@ -1407,6 +1425,12 @@ static int nfs_parse_mount_options(char
5355                                 goto out_invalid_value;
5356                         mnt->minorversion = option;
5357                         break;
5358 +#ifdef CONFIG_PROPAGATE
5359 +               case Opt_tagid:
5360 +                       /* use args[0] */
5361 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5362 +                       break;
5363 +#endif
5364  
5365                 /*
5366                  * options that take text values
5367 diff -NurpP --minimal linux-3.13.1/fs/nfsd/auth.c linux-3.13.1-vs2.3.6.10/fs/nfsd/auth.c
5368 --- linux-3.13.1/fs/nfsd/auth.c 2013-05-31 13:45:24.000000000 +0000
5369 +++ linux-3.13.1-vs2.3.6.10/fs/nfsd/auth.c      2014-01-31 20:38:03.000000000 +0000
5370 @@ -2,6 +2,7 @@
5371  
5372  #include <linux/sched.h>
5373  #include <linux/user_namespace.h>
5374 +#include <linux/vs_tag.h>
5375  #include "nfsd.h"
5376  #include "auth.h"
5377  
5378 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5379  
5380         new->fsuid = rqstp->rq_cred.cr_uid;
5381         new->fsgid = rqstp->rq_cred.cr_gid;
5382 +       /* FIXME: this desperately needs a tag :)
5383 +       new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5384 +                       */
5385  
5386         rqgi = rqstp->rq_cred.cr_group_info;
5387  
5388 diff -NurpP --minimal linux-3.13.1/fs/nfsd/nfs3xdr.c linux-3.13.1-vs2.3.6.10/fs/nfsd/nfs3xdr.c
5389 --- linux-3.13.1/fs/nfsd/nfs3xdr.c      2013-05-31 13:45:24.000000000 +0000
5390 +++ linux-3.13.1-vs2.3.6.10/fs/nfsd/nfs3xdr.c   2014-01-31 20:38:03.000000000 +0000
5391 @@ -8,6 +8,7 @@
5392  
5393  #include <linux/namei.h>
5394  #include <linux/sunrpc/svc_xprt.h>
5395 +#include <linux/vs_tag.h>
5396  #include "xdr3.h"
5397  #include "auth.h"
5398  #include "netns.h"
5399 @@ -98,6 +99,8 @@ static __be32 *
5400  decode_sattr3(__be32 *p, struct iattr *iap)
5401  {
5402         u32     tmp;
5403 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5404 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5405  
5406         iap->ia_valid = 0;
5407  
5408 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5409                 iap->ia_mode = ntohl(*p++);
5410         }
5411         if (*p++) {
5412 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5413 +               kuid = make_kuid(&init_user_ns, ntohl(*p++));
5414                 if (uid_valid(iap->ia_uid))
5415                         iap->ia_valid |= ATTR_UID;
5416         }
5417         if (*p++) {
5418 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5419 +               kgid = make_kgid(&init_user_ns, ntohl(*p++));
5420                 if (gid_valid(iap->ia_gid))
5421                         iap->ia_valid |= ATTR_GID;
5422         }
5423 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5424 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5425 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5426         if (*p++) {
5427                 u64     newsize;
5428  
5429 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5430         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5431         *p++ = htonl((u32) stat->mode);
5432         *p++ = htonl((u32) stat->nlink);
5433 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5434 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5435 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5436 +               TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5437 +               stat->uid, stat->tag)));
5438 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5439 +               TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5440 +               stat->gid, stat->tag)));
5441         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5442                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5443         } else {
5444 diff -NurpP --minimal linux-3.13.1/fs/nfsd/nfs4xdr.c linux-3.13.1-vs2.3.6.10/fs/nfsd/nfs4xdr.c
5445 --- linux-3.13.1/fs/nfsd/nfs4xdr.c      2014-01-22 20:39:06.000000000 +0000
5446 +++ linux-3.13.1-vs2.3.6.10/fs/nfsd/nfs4xdr.c   2014-01-31 20:38:03.000000000 +0000
5447 @@ -46,6 +46,7 @@
5448  #include <linux/utsname.h>
5449  #include <linux/pagemap.h>
5450  #include <linux/sunrpc/svcauth_gss.h>
5451 +#include <linux/vs_tag.h>
5452  
5453  #include "idmap.h"
5454  #include "acl.h"
5455 @@ -2430,14 +2431,18 @@ out_acl:
5456                 WRITE32(stat.nlink);
5457         }
5458         if (bmval1 & FATTR4_WORD1_OWNER) {
5459 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5460 +               status = nfsd4_encode_user(rqstp,
5461 +                       TAGINO_KUID(DX_TAG(dentry->d_inode),
5462 +                       stat.uid, stat.tag), &p, &buflen);
5463                 if (status == nfserr_resource)
5464                         goto out_resource;
5465                 if (status)
5466                         goto out;
5467         }
5468         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5469 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5470 +               status = nfsd4_encode_group(rqstp,
5471 +                       TAGINO_KGID(DX_TAG(dentry->d_inode),
5472 +                       stat.gid, stat.tag), &p, &buflen);
5473                 if (status == nfserr_resource)
5474                         goto out_resource;
5475                 if (status)
5476 diff -NurpP --minimal linux-3.13.1/fs/nfsd/nfsxdr.c linux-3.13.1-vs2.3.6.10/fs/nfsd/nfsxdr.c
5477 --- linux-3.13.1/fs/nfsd/nfsxdr.c       2013-05-31 13:45:24.000000000 +0000
5478 +++ linux-3.13.1-vs2.3.6.10/fs/nfsd/nfsxdr.c    2014-01-31 20:38:03.000000000 +0000
5479 @@ -7,6 +7,7 @@
5480  #include "vfs.h"
5481  #include "xdr.h"
5482  #include "auth.h"
5483 +#include <linux/vs_tag.h>
5484  
5485  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5486  
5487 @@ -89,6 +90,8 @@ static __be32 *
5488  decode_sattr(__be32 *p, struct iattr *iap)
5489  {
5490         u32     tmp, tmp1;
5491 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5492 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5493  
5494         iap->ia_valid = 0;
5495  
5496 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5497                 iap->ia_mode = tmp;
5498         }
5499         if ((tmp = ntohl(*p++)) != (u32)-1) {
5500 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5501 +               kuid = make_kuid(&init_user_ns, tmp);
5502                 if (uid_valid(iap->ia_uid))
5503                         iap->ia_valid |= ATTR_UID;
5504         }
5505         if ((tmp = ntohl(*p++)) != (u32)-1) {
5506 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5507 +               kgid = make_kgid(&init_user_ns, tmp);
5508                 if (gid_valid(iap->ia_gid))
5509                         iap->ia_valid |= ATTR_GID;
5510         }
5511 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5512 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5513 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5514         if ((tmp = ntohl(*p++)) != (u32)-1) {
5515                 iap->ia_valid |= ATTR_SIZE;
5516                 iap->ia_size = tmp;
5517 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5518         *p++ = htonl(nfs_ftypes[type >> 12]);
5519         *p++ = htonl((u32) stat->mode);
5520         *p++ = htonl((u32) stat->nlink);
5521 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5522 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5523 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5524 +               TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5525 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5526 +               TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5527  
5528         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5529                 *p++ = htonl(NFS_MAXPATHLEN);
5530 diff -NurpP --minimal linux-3.13.1/fs/ocfs2/dlmglue.c linux-3.13.1-vs2.3.6.10/fs/ocfs2/dlmglue.c
5531 --- linux-3.13.1/fs/ocfs2/dlmglue.c     2014-01-22 20:39:07.000000000 +0000
5532 +++ linux-3.13.1-vs2.3.6.10/fs/ocfs2/dlmglue.c  2014-01-31 20:38:03.000000000 +0000
5533 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5534         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5535         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5536         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5537 +       lvb->lvb_itag      = cpu_to_be16(i_tag_read(inode));
5538         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5539         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5540         lvb->lvb_iatime_packed  =
5541 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5542  
5543         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5544         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5545 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5546         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5547         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5548         ocfs2_unpack_timespec(&inode->i_atime,
5549 diff -NurpP --minimal linux-3.13.1/fs/ocfs2/dlmglue.h linux-3.13.1-vs2.3.6.10/fs/ocfs2/dlmglue.h
5550 --- linux-3.13.1/fs/ocfs2/dlmglue.h     2012-12-11 03:30:57.000000000 +0000
5551 +++ linux-3.13.1-vs2.3.6.10/fs/ocfs2/dlmglue.h  2014-01-31 20:38:03.000000000 +0000
5552 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5553         __be16       lvb_inlink;
5554         __be32       lvb_iattr;
5555         __be32       lvb_igeneration;
5556 -       __be32       lvb_reserved2;
5557 +       __be16       lvb_itag;
5558 +       __be16       lvb_reserved2;
5559  };
5560  
5561  #define OCFS2_QINFO_LVB_VERSION 1
5562 diff -NurpP --minimal linux-3.13.1/fs/ocfs2/file.c linux-3.13.1-vs2.3.6.10/fs/ocfs2/file.c
5563 --- linux-3.13.1/fs/ocfs2/file.c        2014-01-22 20:39:07.000000000 +0000
5564 +++ linux-3.13.1-vs2.3.6.10/fs/ocfs2/file.c     2014-01-31 20:38:03.000000000 +0000
5565 @@ -1119,7 +1119,7 @@ int ocfs2_setattr(struct dentry *dentry,
5566                 attr->ia_valid &= ~ATTR_SIZE;
5567  
5568  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5569 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5570 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5571         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5572                 return 0;
5573  
5574 diff -NurpP --minimal linux-3.13.1/fs/ocfs2/inode.c linux-3.13.1-vs2.3.6.10/fs/ocfs2/inode.c
5575 --- linux-3.13.1/fs/ocfs2/inode.c       2014-01-22 20:39:07.000000000 +0000
5576 +++ linux-3.13.1-vs2.3.6.10/fs/ocfs2/inode.c    2014-01-31 20:38:03.000000000 +0000
5577 @@ -28,6 +28,7 @@
5578  #include <linux/highmem.h>
5579  #include <linux/pagemap.h>
5580  #include <linux/quotaops.h>
5581 +#include <linux/vs_tag.h>
5582  
5583  #include <asm/byteorder.h>
5584  
5585 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5586  {
5587         unsigned int flags = OCFS2_I(inode)->ip_attr;
5588  
5589 -       inode->i_flags &= ~(S_IMMUTABLE |
5590 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5591                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5592  
5593         if (flags & OCFS2_IMMUTABLE_FL)
5594                 inode->i_flags |= S_IMMUTABLE;
5595 +       if (flags & OCFS2_IXUNLINK_FL)
5596 +               inode->i_flags |= S_IXUNLINK;
5597  
5598         if (flags & OCFS2_SYNC_FL)
5599                 inode->i_flags |= S_SYNC;
5600 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5601                 inode->i_flags |= S_NOATIME;
5602         if (flags & OCFS2_DIRSYNC_FL)
5603                 inode->i_flags |= S_DIRSYNC;
5604 +
5605 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5606 +
5607 +       if (flags & OCFS2_BARRIER_FL)
5608 +               inode->i_vflags |= V_BARRIER;
5609 +       if (flags & OCFS2_COW_FL)
5610 +               inode->i_vflags |= V_COW;
5611  }
5612  
5613  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5614  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5615  {
5616         unsigned int flags = oi->vfs_inode.i_flags;
5617 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5618 +
5619 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5620 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5621 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5622 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5623 +
5624 +       if (flags & S_IMMUTABLE)
5625 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5626 +       if (flags & S_IXUNLINK)
5627 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5628  
5629 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5630 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5631         if (flags & S_SYNC)
5632                 oi->ip_attr |= OCFS2_SYNC_FL;
5633         if (flags & S_APPEND)
5634                 oi->ip_attr |= OCFS2_APPEND_FL;
5635 -       if (flags & S_IMMUTABLE)
5636 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5637         if (flags & S_NOATIME)
5638                 oi->ip_attr |= OCFS2_NOATIME_FL;
5639         if (flags & S_DIRSYNC)
5640                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5641 +
5642 +       if (vflags & V_BARRIER)
5643 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5644 +       if (vflags & V_COW)
5645 +               oi->ip_attr |= OCFS2_COW_FL;
5646  }
5647  
5648  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5649 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5650         struct super_block *sb;
5651         struct ocfs2_super *osb;
5652         int use_plocks = 1;
5653 +       uid_t uid;
5654 +       gid_t gid;
5655  
5656         sb = inode->i_sb;
5657         osb = OCFS2_SB(sb);
5658 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5659         inode->i_generation = le32_to_cpu(fe->i_generation);
5660         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5661         inode->i_mode = le16_to_cpu(fe->i_mode);
5662 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5663 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5664 +       uid = le32_to_cpu(fe->i_uid);
5665 +       gid = le32_to_cpu(fe->i_gid);
5666 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5667 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5668 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5669 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5670  
5671         /* Fast symlinks will have i_size but no allocated clusters. */
5672         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5673 diff -NurpP --minimal linux-3.13.1/fs/ocfs2/inode.h linux-3.13.1-vs2.3.6.10/fs/ocfs2/inode.h
5674 --- linux-3.13.1/fs/ocfs2/inode.h       2013-07-14 17:01:29.000000000 +0000
5675 +++ linux-3.13.1-vs2.3.6.10/fs/ocfs2/inode.h    2014-01-31 20:38:03.000000000 +0000
5676 @@ -152,6 +152,7 @@ struct buffer_head *ocfs2_bread(struct i
5677  
5678  void ocfs2_set_inode_flags(struct inode *inode);
5679  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5680 +int ocfs2_sync_flags(struct inode *inode, int, int);
5681  
5682  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5683  {
5684 diff -NurpP --minimal linux-3.13.1/fs/ocfs2/ioctl.c linux-3.13.1-vs2.3.6.10/fs/ocfs2/ioctl.c
5685 --- linux-3.13.1/fs/ocfs2/ioctl.c       2013-11-25 15:47:00.000000000 +0000
5686 +++ linux-3.13.1-vs2.3.6.10/fs/ocfs2/ioctl.c    2014-01-31 20:38:03.000000000 +0000
5687 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5688         return status;
5689  }
5690  
5691 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5692 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5693 +{
5694 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5695 +       struct buffer_head *bh = NULL;
5696 +       handle_t *handle = NULL;
5697 +       int status;
5698 +
5699 +       status = ocfs2_inode_lock(inode, &bh, 1);
5700 +       if (status < 0) {
5701 +               mlog_errno(status);
5702 +               return status;
5703 +       }
5704 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5705 +       if (IS_ERR(handle)) {
5706 +               status = PTR_ERR(handle);
5707 +               mlog_errno(status);
5708 +               goto bail_unlock;
5709 +       }
5710 +
5711 +       inode->i_flags = flags;
5712 +       inode->i_vflags = vflags;
5713 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5714 +
5715 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5716 +       if (status < 0)
5717 +               mlog_errno(status);
5718 +
5719 +       ocfs2_commit_trans(osb, handle);
5720 +bail_unlock:
5721 +       ocfs2_inode_unlock(inode, 1);
5722 +       brelse(bh);
5723 +       return status;
5724 +}
5725 +
5726 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5727                                 unsigned mask)
5728  {
5729         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5730 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5731                         goto bail_unlock;
5732         }
5733  
5734 +       if (IS_BARRIER(inode)) {
5735 +               vxwprintk_task(1, "messing with the barrier.");
5736 +               goto bail_unlock;
5737 +       }
5738 +
5739         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5740         if (IS_ERR(handle)) {
5741                 status = PTR_ERR(handle);
5742 @@ -881,6 +920,7 @@ bail:
5743         return status;
5744  }
5745  
5746 +
5747  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5748  {
5749         struct inode *inode = file_inode(filp);
5750 diff -NurpP --minimal linux-3.13.1/fs/ocfs2/namei.c linux-3.13.1-vs2.3.6.10/fs/ocfs2/namei.c
5751 --- linux-3.13.1/fs/ocfs2/namei.c       2014-01-22 20:39:07.000000000 +0000
5752 +++ linux-3.13.1-vs2.3.6.10/fs/ocfs2/namei.c    2014-01-31 20:38:03.000000000 +0000
5753 @@ -41,6 +41,7 @@
5754  #include <linux/slab.h>
5755  #include <linux/highmem.h>
5756  #include <linux/quotaops.h>
5757 +#include <linux/vs_tag.h>
5758  
5759  #include <cluster/masklog.h>
5760  
5761 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5762         struct ocfs2_dinode *fe = NULL;
5763         struct ocfs2_extent_list *fel;
5764         u16 feat;
5765 +       ktag_t ktag;
5766  
5767         *new_fe_bh = NULL;
5768  
5769 @@ -512,8 +514,13 @@ static int __ocfs2_mknod_locked(struct i
5770         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5771         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5772         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5773 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5774 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5775 +
5776 +       ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5777 +       fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5778 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5779 +       fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5780 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5781 +       inode->i_tag = ktag; /* is this correct? */
5782         fe->i_mode = cpu_to_le16(inode->i_mode);
5783         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5784                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5785 diff -NurpP --minimal linux-3.13.1/fs/ocfs2/ocfs2.h linux-3.13.1-vs2.3.6.10/fs/ocfs2/ocfs2.h
5786 --- linux-3.13.1/fs/ocfs2/ocfs2.h       2013-11-25 15:45:04.000000000 +0000
5787 +++ linux-3.13.1-vs2.3.6.10/fs/ocfs2/ocfs2.h    2014-01-31 20:38:03.000000000 +0000
5788 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5789                                                      writes */
5790         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5791         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5792 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5793  };
5794  
5795  #define OCFS2_OSB_SOFT_RO                      0x0001
5796 diff -NurpP --minimal linux-3.13.1/fs/ocfs2/ocfs2_fs.h linux-3.13.1-vs2.3.6.10/fs/ocfs2/ocfs2_fs.h
5797 --- linux-3.13.1/fs/ocfs2/ocfs2_fs.h    2012-12-11 03:30:57.000000000 +0000
5798 +++ linux-3.13.1-vs2.3.6.10/fs/ocfs2/ocfs2_fs.h 2014-01-31 20:38:03.000000000 +0000
5799 @@ -266,6 +266,11 @@
5800  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5801  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5802  
5803 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5804 +
5805 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5806 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5807 +
5808  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5809  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5810  
5811 diff -NurpP --minimal linux-3.13.1/fs/ocfs2/super.c linux-3.13.1-vs2.3.6.10/fs/ocfs2/super.c
5812 --- linux-3.13.1/fs/ocfs2/super.c       2014-01-22 20:39:07.000000000 +0000
5813 +++ linux-3.13.1-vs2.3.6.10/fs/ocfs2/super.c    2014-01-31 20:38:03.000000000 +0000
5814 @@ -185,6 +185,7 @@ enum {
5815         Opt_coherency_full,
5816         Opt_resv_level,
5817         Opt_dir_resv_level,
5818 +       Opt_tag, Opt_notag, Opt_tagid,
5819         Opt_err,
5820  };
5821  
5822 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5823         {Opt_coherency_full, "coherency=full"},
5824         {Opt_resv_level, "resv_level=%u"},
5825         {Opt_dir_resv_level, "dir_resv_level=%u"},
5826 +       {Opt_tag, "tag"},
5827 +       {Opt_notag, "notag"},
5828 +       {Opt_tagid, "tagid=%u"},
5829         {Opt_err, NULL}
5830  };
5831  
5832 @@ -661,6 +665,13 @@ static int ocfs2_remount(struct super_bl
5833                 goto out;
5834         }
5835  
5836 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5837 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5838 +               ret = -EINVAL;
5839 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5840 +               goto out;
5841 +       }
5842 +
5843         /* We're going to/from readonly mode. */
5844         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5845                 /* Disable quota accounting before remounting RO */
5846 @@ -1176,6 +1187,9 @@ static int ocfs2_fill_super(struct super
5847  
5848         ocfs2_complete_mount_recovery(osb);
5849  
5850 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5851 +               sb->s_flags |= MS_TAGGED;
5852 +
5853         if (ocfs2_mount_local(osb))
5854                 snprintf(nodestr, sizeof(nodestr), "local");
5855         else
5856 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
5857                             option < OCFS2_MAX_RESV_LEVEL)
5858                                 mopt->dir_resv_level = option;
5859                         break;
5860 +#ifndef CONFIG_TAGGING_NONE
5861 +               case Opt_tag:
5862 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5863 +                       break;
5864 +               case Opt_notag:
5865 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5866 +                       break;
5867 +#endif
5868 +#ifdef CONFIG_PROPAGATE
5869 +               case Opt_tagid:
5870 +                       /* use args[0] */
5871 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5872 +                       break;
5873 +#endif
5874                 default:
5875                         mlog(ML_ERROR,
5876                              "Unrecognized mount option \"%s\" "
5877 diff -NurpP --minimal linux-3.13.1/fs/open.c linux-3.13.1-vs2.3.6.10/fs/open.c
5878 --- linux-3.13.1/fs/open.c      2014-01-22 20:39:07.000000000 +0000
5879 +++ linux-3.13.1-vs2.3.6.10/fs/open.c   2014-01-31 20:38:03.000000000 +0000
5880 @@ -31,6 +31,11 @@
5881  #include <linux/ima.h>
5882  #include <linux/dnotify.h>
5883  #include <linux/compat.h>
5884 +#include <linux/vs_base.h>
5885 +#include <linux/vs_limit.h>
5886 +#include <linux/vs_tag.h>
5887 +#include <linux/vs_cowbl.h>
5888 +#include <linux/vserver/dlimit.h>
5889  
5890  #include "internal.h"
5891  
5892 @@ -68,6 +73,11 @@ long vfs_truncate(struct path *path, lof
5893         struct inode *inode;
5894         long error;
5895  
5896 +#ifdef CONFIG_VSERVER_COWBL
5897 +       error = cow_check_and_break(path);
5898 +       if (error)
5899 +               goto out;
5900 +#endif
5901         inode = path->dentry->d_inode;
5902  
5903         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5904 @@ -511,6 +521,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5905         unsigned int lookup_flags = LOOKUP_FOLLOW;
5906  retry:
5907         error = user_path_at(dfd, filename, lookup_flags, &path);
5908 +#ifdef CONFIG_VSERVER_COWBL
5909 +       if (!error) {
5910 +               error = cow_check_and_break(&path);
5911 +               if (error)
5912 +                       path_put(&path);
5913 +       }
5914 +#endif
5915         if (!error) {
5916                 error = chmod_common(&path, mode);
5917                 path_put(&path);
5918 @@ -544,13 +561,15 @@ static int chown_common(struct path *pat
5919                 if (!uid_valid(uid))
5920                         return -EINVAL;
5921                 newattrs.ia_valid |= ATTR_UID;
5922 -               newattrs.ia_uid = uid;
5923 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5924 +                       dx_map_uid(user));
5925         }
5926         if (group != (gid_t) -1) {
5927                 if (!gid_valid(gid))
5928                         return -EINVAL;
5929                 newattrs.ia_valid |= ATTR_GID;
5930 -               newattrs.ia_gid = gid;
5931 +               newattrs.ia_gid = make_kgid(&init_user_ns,
5932 +                       dx_map_gid(group));
5933         }
5934         if (!S_ISDIR(inode->i_mode))
5935                 newattrs.ia_valid |=
5936 @@ -589,6 +608,18 @@ retry:
5937         error = mnt_want_write(path.mnt);
5938         if (error)
5939                 goto out_release;
5940 +#ifdef CONFIG_VSERVER_COWBL
5941 +       error = cow_check_and_break(&path);
5942 +       if (!error)
5943 +#endif
5944 +#ifdef CONFIG_VSERVER_COWBL
5945 +       error = cow_check_and_break(&path);
5946 +       if (!error)
5947 +#endif
5948 +#ifdef CONFIG_VSERVER_COWBL
5949 +       error = cow_check_and_break(&path);
5950 +       if (!error)
5951 +#endif
5952         error = chown_common(&path, user, group);
5953         mnt_drop_write(path.mnt);
5954  out_release:
5955 diff -NurpP --minimal linux-3.13.1/fs/proc/array.c linux-3.13.1-vs2.3.6.10/fs/proc/array.c
5956 --- linux-3.13.1/fs/proc/array.c        2014-01-22 20:39:07.000000000 +0000
5957 +++ linux-3.13.1-vs2.3.6.10/fs/proc/array.c     2014-02-01 01:44:54.000000000 +0000
5958 @@ -82,6 +82,8 @@
5959  #include <linux/ptrace.h>
5960  #include <linux/tracehook.h>
5961  #include <linux/user_namespace.h>
5962 +#include <linux/vs_context.h>
5963 +#include <linux/vs_network.h>
5964  
5965  #include <asm/pgtable.h>
5966  #include <asm/processor.h>
5967 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
5968         rcu_read_lock();
5969         ppid = pid_alive(p) ?
5970                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5971 +       if (unlikely(vx_current_initpid(p->pid)))
5972 +               ppid = 0;
5973 +
5974         tpid = 0;
5975         if (pid_alive(p)) {
5976                 struct task_struct *tracer = ptrace_parent(p);
5977 @@ -299,7 +304,7 @@ static inline void task_sig(struct seq_f
5978  }
5979  
5980  static void render_cap_t(struct seq_file *m, const char *header,
5981 -                       kernel_cap_t *a)
5982 +                       struct vx_info *vxi, kernel_cap_t *a)
5983  {
5984         unsigned __capi;
5985  
5986 @@ -333,10 +338,11 @@ static inline void task_cap(struct seq_f
5987         NORM_CAPS(cap_effective);
5988         NORM_CAPS(cap_bset);
5989  
5990 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
5991 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
5992 -       render_cap_t(m, "CapEff:\t", &cap_effective);
5993 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
5994 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5995 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5996 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5997 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5998 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
5999  }
6000  
6001  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
6002 @@ -365,6 +371,43 @@ static void task_cpus_allowed(struct seq
6003         seq_putc(m, '\n');
6004  }
6005  
6006 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6007 +                       struct pid *pid, struct task_struct *task)
6008 +{
6009 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6010 +                       "Count:\t%u\n"
6011 +                       "uts:\t%p(%c)\n"
6012 +                       "ipc:\t%p(%c)\n"
6013 +                       "mnt:\t%p(%c)\n"
6014 +                       "pid:\t%p(%c)\n"
6015 +                       "net:\t%p(%c)\n",
6016 +                       task->nsproxy,
6017 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6018 +                       atomic_read(&task->nsproxy->count),
6019 +                       task->nsproxy->uts_ns,
6020 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6021 +                       task->nsproxy->ipc_ns,
6022 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6023 +                       task->nsproxy->mnt_ns,
6024 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6025 +                       task->nsproxy->pid_ns_for_children,
6026 +                       (task->nsproxy->pid_ns_for_children ==
6027 +                               init_task.nsproxy->pid_ns_for_children ? 'I' : '-'),
6028 +                       task->nsproxy->net_ns,
6029 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6030 +       return 0;
6031 +}
6032 +
6033 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6034 +{
6035 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6036 +               return;
6037 +
6038 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6039 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6040 +}
6041 +
6042 +
6043  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6044                         struct pid *pid, struct task_struct *task)
6045  {
6046 @@ -382,6 +425,7 @@ int proc_pid_status(struct seq_file *m,
6047         task_seccomp(m, task);
6048         task_cpus_allowed(m, task);
6049         cpuset_task_status_allowed(m, task);
6050 +       task_vs_id(m, task);
6051         task_context_switch_counts(m, task);
6052         return 0;
6053  }
6054 @@ -491,6 +535,17 @@ static int do_task_stat(struct seq_file
6055         /* convert nsec -> ticks */
6056         start_time = nsec_to_clock_t(start_time);
6057  
6058 +       /* fixup start time for virt uptime */
6059 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6060 +               unsigned long long bias =
6061 +                       current->vx_info->cvirt.bias_clock;
6062 +
6063 +               if (start_time > bias)
6064 +                       start_time -= bias;
6065 +               else
6066 +                       start_time = 0;
6067 +       }
6068 +
6069         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6070         seq_put_decimal_ll(m, ' ', ppid);
6071         seq_put_decimal_ll(m, ' ', pgid);
6072 diff -NurpP --minimal linux-3.13.1/fs/proc/base.c linux-3.13.1-vs2.3.6.10/fs/proc/base.c
6073 --- linux-3.13.1/fs/proc/base.c 2014-01-22 20:39:07.000000000 +0000
6074 +++ linux-3.13.1-vs2.3.6.10/fs/proc/base.c      2014-02-01 00:05:10.000000000 +0000
6075 @@ -87,6 +87,8 @@
6076  #include <linux/slab.h>
6077  #include <linux/flex_array.h>
6078  #include <linux/posix-timers.h>
6079 +#include <linux/vs_context.h>
6080 +#include <linux/vs_network.h>
6081  #ifdef CONFIG_HARDWALL
6082  #include <asm/hardwall.h>
6083  #endif
6084 @@ -976,11 +978,15 @@ static ssize_t oom_adj_write(struct file
6085                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6086  
6087         if (oom_adj < task->signal->oom_score_adj &&
6088 -           !capable(CAP_SYS_RESOURCE)) {
6089 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6090                 err = -EACCES;
6091                 goto err_sighand;
6092         }
6093  
6094 +       /* prevent guest processes from circumventing the oom killer */
6095 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6096 +               oom_adj = OOM_ADJUST_MIN;
6097 +
6098         /*
6099          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6100          * /proc/pid/oom_score_adj instead.
6101 @@ -1565,6 +1571,8 @@ struct inode *proc_pid_make_inode(struct
6102                 inode->i_gid = cred->egid;
6103                 rcu_read_unlock();
6104         }
6105 +       /* procfs is xid tagged */
6106 +       i_tag_write(inode, (vtag_t)vx_task_xid(task));
6107         security_task_to_inode(task, inode);
6108  
6109  out:
6110 @@ -1610,6 +1618,8 @@ int pid_getattr(struct vfsmount *mnt, st
6111  
6112  /* dentry stuff */
6113  
6114 +static unsigned name_to_int(struct dentry *dentry);
6115 +
6116  /*
6117   *     Exceptional case: normally we are not allowed to unhash a busy
6118   * directory. In this case, however, we can do it - no aliasing problems
6119 @@ -1638,6 +1648,12 @@ int pid_revalidate(struct dentry *dentry
6120         task = get_proc_task(inode);
6121  
6122         if (task) {
6123 +               unsigned pid = name_to_int(dentry);
6124 +
6125 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6126 +                       put_task_struct(task);
6127 +                       goto drop;
6128 +               }
6129                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6130                     task_dumpable(task)) {
6131                         rcu_read_lock();
6132 @@ -1654,6 +1670,7 @@ int pid_revalidate(struct dentry *dentry
6133                 put_task_struct(task);
6134                 return 1;
6135         }
6136 +drop:
6137         d_drop(dentry);
6138         return 0;
6139  }
6140 @@ -2172,6 +2189,13 @@ static struct dentry *proc_pident_lookup
6141         if (!task)
6142                 goto out_no_task;
6143  
6144 +       /* TODO: maybe we can come up with a generic approach? */
6145 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6146 +               (dentry->d_name.len == 5) &&
6147 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6148 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6149 +               goto out;
6150 +
6151         /*
6152          * Yes, it does not scale. And it should not. Don't add
6153          * new entries into /proc/<tgid>/ without very good reasons.
6154 @@ -2568,6 +2592,9 @@ static int proc_pid_personality(struct s
6155  static const struct file_operations proc_task_operations;
6156  static const struct inode_operations proc_task_inode_operations;
6157  
6158 +extern int proc_pid_vx_info(struct task_struct *, char *);
6159 +extern int proc_pid_nx_info(struct task_struct *, char *);
6160 +
6161  static const struct pid_entry tgid_base_stuff[] = {
6162         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6163         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6164 @@ -2634,6 +2661,8 @@ static const struct pid_entry tgid_base_
6165  #ifdef CONFIG_CGROUPS
6166         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6167  #endif
6168 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6169 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6170         INF("oom_score",  S_IRUGO, proc_oom_score),
6171         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6172         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6173 @@ -2846,7 +2875,7 @@ retry:
6174         iter.task = NULL;
6175         pid = find_ge_pid(iter.tgid, ns);
6176         if (pid) {
6177 -               iter.tgid = pid_nr_ns(pid, ns);
6178 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6179                 iter.task = pid_task(pid, PIDTYPE_PID);
6180                 /* What we to know is if the pid we have find is the
6181                  * pid of a thread_group_leader.  Testing for task
6182 @@ -2899,8 +2928,10 @@ int proc_pid_readdir(struct file *file,
6183                 if (!has_pid_permissions(ns, iter.task, 2))
6184                         continue;
6185  
6186 -               len = snprintf(name, sizeof(name), "%d", iter.tgid);
6187 +               len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6188                 ctx->pos = iter.tgid + TGID_OFFSET;
6189 +               if (!vx_proc_task_visible(iter.task))
6190 +                       continue;
6191                 if (!proc_fill_cache(file, ctx, name, len,
6192                                      proc_pid_instantiate, iter.task, NULL)) {
6193                         put_task_struct(iter.task);
6194 @@ -2993,6 +3024,7 @@ static const struct pid_entry tid_base_s
6195         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6196         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6197  #endif
6198 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6199  };
6200  
6201  static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
6202 @@ -3059,6 +3091,8 @@ static struct dentry *proc_task_lookup(s
6203         tid = name_to_int(dentry);
6204         if (tid == ~0U)
6205                 goto out;
6206 +       if (vx_current_initpid(tid))
6207 +               goto out;
6208  
6209         ns = dentry->d_sb->s_fs_info;
6210         rcu_read_lock();
6211 diff -NurpP --minimal linux-3.13.1/fs/proc/generic.c linux-3.13.1-vs2.3.6.10/fs/proc/generic.c
6212 --- linux-3.13.1/fs/proc/generic.c      2014-01-22 20:39:07.000000000 +0000
6213 +++ linux-3.13.1-vs2.3.6.10/fs/proc/generic.c   2014-02-01 00:07:40.000000000 +0000
6214 @@ -23,6 +23,7 @@
6215  #include <linux/bitops.h>
6216  #include <linux/spinlock.h>
6217  #include <linux/completion.h>
6218 +#include <linux/vserver/inode.h>
6219  #include <asm/uaccess.h>
6220  
6221  #include "internal.h"
6222 @@ -187,6 +188,8 @@ struct dentry *proc_lookup_de(struct pro
6223         for (de = de->subdir; de ; de = de->next) {
6224                 if (de->namelen != dentry->d_name.len)
6225                         continue;
6226 +               if (!vx_hide_check(0, de->vx_flags))
6227 +                       continue;
6228                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6229                         pde_get(de);
6230                         spin_unlock(&proc_subdir_lock);
6231 @@ -195,6 +198,8 @@ struct dentry *proc_lookup_de(struct pro
6232                                 return ERR_PTR(-ENOMEM);
6233                         d_set_d_op(dentry, &simple_dentry_operations);
6234                         d_add(dentry, inode);
6235 +                       /* generic proc entries belong to the host */
6236 +                       i_tag_write(inode, 0);
6237                         return NULL;
6238                 }
6239         }
6240 @@ -242,6 +247,9 @@ int proc_readdir_de(struct proc_dir_entr
6241         do {
6242                 struct proc_dir_entry *next;
6243                 pde_get(de);
6244 +
6245 +               if (!vx_hide_check(0, de->vx_flags))
6246 +                       goto skip;
6247                 spin_unlock(&proc_subdir_lock);
6248                 if (!dir_emit(ctx, de->name, de->namelen,
6249                             de->low_ino, de->mode >> 12)) {
6250 @@ -249,6 +257,7 @@ int proc_readdir_de(struct proc_dir_entr
6251                         return 0;
6252                 }
6253                 spin_lock(&proc_subdir_lock);
6254 +       skip:
6255                 ctx->pos++;
6256                 next = de->next;
6257                 pde_put(de);
6258 @@ -355,6 +364,7 @@ static struct proc_dir_entry *__proc_cre
6259         ent->namelen = len;
6260         ent->mode = mode;
6261         ent->nlink = nlink;
6262 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6263         atomic_set(&ent->count, 1);
6264         spin_lock_init(&ent->pde_unload_lock);
6265         INIT_LIST_HEAD(&ent->pde_openers);
6266 @@ -378,7 +388,8 @@ struct proc_dir_entry *proc_symlink(cons
6267                                 kfree(ent->data);
6268                                 kfree(ent);
6269                                 ent = NULL;
6270 -                       }
6271 +                       } else
6272 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6273                 } else {
6274                         kfree(ent);
6275                         ent = NULL;
6276 diff -NurpP --minimal linux-3.13.1/fs/proc/inode.c linux-3.13.1-vs2.3.6.10/fs/proc/inode.c
6277 --- linux-3.13.1/fs/proc/inode.c        2014-01-22 20:39:07.000000000 +0000
6278 +++ linux-3.13.1-vs2.3.6.10/fs/proc/inode.c     2014-01-31 20:38:03.000000000 +0000
6279 @@ -415,6 +415,8 @@ struct inode *proc_get_inode(struct supe
6280                         inode->i_uid = de->uid;
6281                         inode->i_gid = de->gid;
6282                 }
6283 +               if (de->vx_flags)
6284 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6285                 if (de->size)
6286                         inode->i_size = de->size;
6287                 if (de->nlink)
6288 diff -NurpP --minimal linux-3.13.1/fs/proc/internal.h linux-3.13.1-vs2.3.6.10/fs/proc/internal.h
6289 --- linux-3.13.1/fs/proc/internal.h     2013-11-25 15:45:04.000000000 +0000
6290 +++ linux-3.13.1-vs2.3.6.10/fs/proc/internal.h  2014-01-31 20:38:03.000000000 +0000
6291 @@ -14,6 +14,7 @@
6292  #include <linux/spinlock.h>
6293  #include <linux/atomic.h>
6294  #include <linux/binfmts.h>
6295 +#include <linux/vs_pid.h>
6296  
6297  struct ctl_table_header;
6298  struct mempolicy;
6299 @@ -35,6 +36,7 @@ struct proc_dir_entry {
6300         nlink_t nlink;
6301         kuid_t uid;
6302         kgid_t gid;
6303 +       int vx_flags;
6304         loff_t size;
6305         const struct inode_operations *proc_iops;
6306         const struct file_operations *proc_fops;
6307 @@ -50,16 +52,23 @@ struct proc_dir_entry {
6308         char name[];
6309  };
6310  
6311 +struct vx_info;
6312 +struct nx_info;
6313 +
6314  union proc_op {
6315         int (*proc_get_link)(struct dentry *, struct path *);
6316         int (*proc_read)(struct task_struct *task, char *page);
6317         int (*proc_show)(struct seq_file *m,
6318                 struct pid_namespace *ns, struct pid *pid,
6319                 struct task_struct *task);
6320 +       int (*proc_vs_read)(char *page);
6321 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
6322 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
6323  };
6324  
6325  struct proc_inode {
6326         struct pid *pid;
6327 +       int vx_flags;
6328         int fd;
6329         union proc_op op;
6330         struct proc_dir_entry *pde;
6331 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
6332         return PROC_I(inode)->pid;
6333  }
6334  
6335 -static inline struct task_struct *get_proc_task(struct inode *inode)
6336 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6337  {
6338         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6339  }
6340  
6341 +static inline struct task_struct *get_proc_task(struct inode *inode)
6342 +{
6343 +       return vx_get_proc_task(inode, proc_pid(inode));
6344 +}
6345 +
6346  static inline int task_dumpable(struct task_struct *task)
6347  {
6348         int dumpable = 0;
6349 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6350                            struct pid *, struct task_struct *);
6351  extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6352                           struct pid *, struct task_struct *);
6353 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6354 +                           struct pid *pid, struct task_struct *task);
6355  
6356  /*
6357   * base.c
6358 diff -NurpP --minimal linux-3.13.1/fs/proc/loadavg.c linux-3.13.1-vs2.3.6.10/fs/proc/loadavg.c
6359 --- linux-3.13.1/fs/proc/loadavg.c      2012-12-11 03:30:57.000000000 +0000
6360 +++ linux-3.13.1-vs2.3.6.10/fs/proc/loadavg.c   2014-01-31 20:38:03.000000000 +0000
6361 @@ -12,15 +12,27 @@
6362  
6363  static int loadavg_proc_show(struct seq_file *m, void *v)
6364  {
6365 +       unsigned long running;
6366 +       unsigned int threads;
6367         unsigned long avnrun[3];
6368  
6369         get_avenrun(avnrun, FIXED_1/200, 0);
6370  
6371 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6372 +               struct vx_info *vxi = current_vx_info();
6373 +
6374 +               running = atomic_read(&vxi->cvirt.nr_running);
6375 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6376 +       } else {
6377 +               running = nr_running();
6378 +               threads = nr_threads;
6379 +       }
6380 +
6381         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6382                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6383                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6384                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6385 -               nr_running(), nr_threads,
6386 +               running, threads,
6387                 task_active_pid_ns(current)->last_pid);
6388         return 0;
6389  }
6390 diff -NurpP --minimal linux-3.13.1/fs/proc/meminfo.c linux-3.13.1-vs2.3.6.10/fs/proc/meminfo.c
6391 --- linux-3.13.1/fs/proc/meminfo.c      2014-01-22 20:39:07.000000000 +0000
6392 +++ linux-3.13.1-vs2.3.6.10/fs/proc/meminfo.c   2014-01-31 20:38:03.000000000 +0000
6393 @@ -37,7 +37,8 @@ static int meminfo_proc_show(struct seq_
6394         si_swapinfo(&i);
6395         committed = percpu_counter_read_positive(&vm_committed_as);
6396  
6397 -       cached = global_page_state(NR_FILE_PAGES) -
6398 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6399 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6400                         total_swapcache_pages() - i.bufferram;
6401         if (cached < 0)
6402                 cached = 0;
6403 diff -NurpP --minimal linux-3.13.1/fs/proc/root.c linux-3.13.1-vs2.3.6.10/fs/proc/root.c
6404 --- linux-3.13.1/fs/proc/root.c 2013-11-25 15:47:00.000000000 +0000
6405 +++ linux-3.13.1-vs2.3.6.10/fs/proc/root.c      2014-02-01 00:02:11.000000000 +0000
6406 @@ -20,9 +20,14 @@
6407  #include <linux/mount.h>
6408  #include <linux/pid_namespace.h>
6409  #include <linux/parser.h>
6410 +#include <linux/vserver/inode.h>
6411  
6412  #include "internal.h"
6413  
6414 +struct proc_dir_entry *proc_virtual;
6415 +
6416 +extern void proc_vx_init(void);
6417 +
6418  static int proc_test_super(struct super_block *sb, void *data)
6419  {
6420         return sb->s_fs_info == data;
6421 @@ -114,7 +119,8 @@ static struct dentry *proc_mount(struct
6422                         return ERR_PTR(-EPERM);
6423  
6424                 /* Does the mounter have privilege over the pid namespace? */
6425 -               if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
6426 +               if (!vx_ns_capable(ns->user_ns,
6427 +                       CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6428                         return ERR_PTR(-EPERM);
6429         }
6430  
6431 @@ -188,6 +194,7 @@ void __init proc_root_init(void)
6432  #endif
6433         proc_mkdir("bus", NULL);
6434         proc_sys_init();
6435 +       proc_vx_init();
6436  }
6437  
6438  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6439 @@ -249,6 +256,7 @@ struct proc_dir_entry proc_root = {
6440         .proc_iops      = &proc_root_inode_operations, 
6441         .proc_fops      = &proc_root_operations,
6442         .parent         = &proc_root,
6443 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6444         .name           = "/proc",
6445  };
6446  
6447 diff -NurpP --minimal linux-3.13.1/fs/proc/self.c linux-3.13.1-vs2.3.6.10/fs/proc/self.c
6448 --- linux-3.13.1/fs/proc/self.c 2014-01-22 20:39:07.000000000 +0000
6449 +++ linux-3.13.1-vs2.3.6.10/fs/proc/self.c      2014-01-31 20:38:03.000000000 +0000
6450 @@ -2,6 +2,7 @@
6451  #include <linux/namei.h>
6452  #include <linux/slab.h>
6453  #include <linux/pid_namespace.h>
6454 +#include <linux/vserver/inode.h>
6455  #include "internal.h"
6456  
6457  /*
6458 @@ -54,6 +55,8 @@ int proc_setup_self(struct super_block *
6459         self = d_alloc_name(s->s_root, "self");
6460         if (self) {
6461                 struct inode *inode = new_inode_pseudo(s);
6462 +
6463 +               // self->vx_flags = IATTR_PROC_SYMLINK;
6464                 if (inode) {
6465                         inode->i_ino = self_inum;
6466                         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6467 diff -NurpP --minimal linux-3.13.1/fs/proc/stat.c linux-3.13.1-vs2.3.6.10/fs/proc/stat.c
6468 --- linux-3.13.1/fs/proc/stat.c 2013-07-14 17:01:29.000000000 +0000
6469 +++ linux-3.13.1-vs2.3.6.10/fs/proc/stat.c      2014-01-31 20:38:03.000000000 +0000
6470 @@ -9,8 +9,10 @@
6471  #include <linux/slab.h>
6472  #include <linux/time.h>
6473  #include <linux/irqnr.h>
6474 +#include <linux/vserver/cvirt.h>
6475  #include <asm/cputime.h>
6476  #include <linux/tick.h>
6477 +#include <linux/cpuset.h>
6478  
6479  #ifndef arch_irq_stat_cpu
6480  #define arch_irq_stat_cpu(cpu) 0
6481 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6482         u64 sum_softirq = 0;
6483         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6484         struct timespec boottime;
6485 +       cpumask_var_t cpus_allowed;
6486 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6487  
6488         user = nice = system = idle = iowait =
6489                 irq = softirq = steal = 0;
6490         guest = guest_nice = 0;
6491         getboottime(&boottime);
6492 +
6493 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6494 +               vx_vsi_boottime(&boottime);
6495 +
6496 +       if (virt_cpu)
6497 +               cpuset_cpus_allowed(current, cpus_allowed);
6498 +
6499         jif = boottime.tv_sec;
6500  
6501         for_each_possible_cpu(i) {
6502 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6503 +                       continue;
6504 +
6505                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6506                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6507                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6508 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6509         seq_putc(p, '\n');
6510  
6511         for_each_online_cpu(i) {
6512 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6513 +                       continue;
6514 +
6515                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6516                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6517                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6518 diff -NurpP --minimal linux-3.13.1/fs/proc/uptime.c linux-3.13.1-vs2.3.6.10/fs/proc/uptime.c
6519 --- linux-3.13.1/fs/proc/uptime.c       2013-11-25 15:45:04.000000000 +0000
6520 +++ linux-3.13.1-vs2.3.6.10/fs/proc/uptime.c    2014-01-31 20:38:03.000000000 +0000
6521 @@ -5,6 +5,7 @@
6522  #include <linux/seq_file.h>
6523  #include <linux/time.h>
6524  #include <linux/kernel_stat.h>
6525 +#include <linux/vserver/cvirt.h>
6526  #include <asm/cputime.h>
6527  
6528  static int uptime_proc_show(struct seq_file *m, void *v)
6529 @@ -24,6 +25,10 @@ static int uptime_proc_show(struct seq_f
6530         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6531         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6532         idle.tv_nsec = rem;
6533 +
6534 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6535 +               vx_vsi_uptime(&uptime, &idle);
6536 +
6537         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6538                         (unsigned long) uptime.tv_sec,
6539                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6540 diff -NurpP --minimal linux-3.13.1/fs/proc_namespace.c linux-3.13.1-vs2.3.6.10/fs/proc_namespace.c
6541 --- linux-3.13.1/fs/proc_namespace.c    2014-01-22 20:39:07.000000000 +0000
6542 +++ linux-3.13.1-vs2.3.6.10/fs/proc_namespace.c 2014-01-31 20:38:03.000000000 +0000
6543 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6544                 { MS_SYNCHRONOUS, ",sync" },
6545                 { MS_DIRSYNC, ",dirsync" },
6546                 { MS_MANDLOCK, ",mand" },
6547 +               { MS_TAGGED, ",tag" },
6548 +               { MS_NOTAGCHECK, ",notagcheck" },
6549                 { 0, NULL }
6550         };
6551         const struct proc_fs_info *fs_infop;
6552 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6553         seq_escape(m, s, " \t\n\\");
6554  }
6555  
6556 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6557 +
6558 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6559 +{
6560 +       struct path root;
6561 +       struct dentry *point;
6562 +       struct mount *mnt = real_mount(vfsmnt);
6563 +       struct mount *root_mnt;
6564 +       int ret;
6565 +
6566 +       if (mnt == mnt->mnt_ns->root)
6567 +               return 1;
6568 +
6569 +       br_read_lock(&vfsmount_lock);
6570 +       root = current->fs->root;
6571 +       root_mnt = real_mount(root.mnt);
6572 +       point = root.dentry;
6573 +
6574 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6575 +               point = mnt->mnt_mountpoint;
6576 +               mnt = mnt->mnt_parent;
6577 +       }
6578 +
6579 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6580 +
6581 +       br_read_unlock(&vfsmount_lock);
6582 +
6583 +       return ret;
6584 +}
6585 +
6586 +#else
6587 +#define        mnt_is_reachable(v)     (1)
6588 +#endif
6589 +
6590  static void show_type(struct seq_file *m, struct super_block *sb)
6591  {
6592         mangle(m, sb->s_type->name);
6593 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6594         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6595         struct super_block *sb = mnt_path.dentry->d_sb;
6596  
6597 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6598 +               return SEQ_SKIP;
6599 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6600 +               return SEQ_SKIP;
6601 +
6602 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6603 +               mnt == current->fs->root.mnt) {
6604 +               seq_puts(m, "/dev/root / ");
6605 +               goto type;
6606 +       }
6607 +
6608         if (sb->s_op->show_devname) {
6609                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6610                 if (err)
6611 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6612         seq_putc(m, ' ');
6613         seq_path(m, &mnt_path, " \t\n\\");
6614         seq_putc(m, ' ');
6615 +type:
6616         show_type(m, sb);
6617         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6618         err = show_sb_opts(m, sb);
6619 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6620         struct path root = p->root;
6621         int err = 0;
6622  
6623 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6624 +               return SEQ_SKIP;
6625 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6626 +               return SEQ_SKIP;
6627 +
6628         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6629                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6630         if (sb->s_op->show_path)
6631 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6632         struct super_block *sb = mnt_path.dentry->d_sb;
6633         int err = 0;
6634  
6635 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6636 +               return SEQ_SKIP;
6637 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6638 +               return SEQ_SKIP;
6639 +
6640 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6641 +               mnt == current->fs->root.mnt) {
6642 +               seq_puts(m, "device /dev/root mounted on / ");
6643 +               goto type;
6644 +       }
6645 +
6646         /* device */
6647         if (sb->s_op->show_devname) {
6648                 seq_puts(m, "device ");
6649 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6650         seq_puts(m, " mounted on ");
6651         seq_path(m, &mnt_path, " \t\n\\");
6652         seq_putc(m, ' ');
6653 -
6654 +type:
6655         /* file system type */
6656         seq_puts(m, "with fstype ");
6657         show_type(m, sb);
6658 diff -NurpP --minimal linux-3.13.1/fs/quota/dquot.c linux-3.13.1-vs2.3.6.10/fs/quota/dquot.c
6659 --- linux-3.13.1/fs/quota/dquot.c       2013-11-25 15:47:00.000000000 +0000
6660 +++ linux-3.13.1-vs2.3.6.10/fs/quota/dquot.c    2014-01-31 20:38:03.000000000 +0000
6661 @@ -1594,6 +1594,9 @@ int __dquot_alloc_space(struct inode *in
6662         struct dquot **dquots = inode->i_dquot;
6663         int reserve = flags & DQUOT_SPACE_RESERVE;
6664  
6665 +       if ((ret = dl_alloc_space(inode, number)))
6666 +               return ret;
6667 +
6668         /*
6669          * First test before acquiring mutex - solves deadlocks when we
6670          * re-enter the quota code and are already holding the mutex
6671 @@ -1649,6 +1652,9 @@ int dquot_alloc_inode(const struct inode
6672         struct dquot_warn warn[MAXQUOTAS];
6673         struct dquot * const *dquots = inode->i_dquot;
6674  
6675 +       if ((ret = dl_alloc_inode(inode)))
6676 +               return ret;
6677 +
6678         /* First test before acquiring mutex - solves deadlocks when we
6679           * re-enter the quota code and are already holding the mutex */
6680         if (!dquot_active(inode))
6681 @@ -1749,6 +1755,8 @@ void __dquot_free_space(struct inode *in
6682         struct dquot **dquots = inode->i_dquot;
6683         int reserve = flags & DQUOT_SPACE_RESERVE;
6684  
6685 +       dl_free_space(inode, number);
6686 +
6687         /* First test before acquiring mutex - solves deadlocks when we
6688           * re-enter the quota code and are already holding the mutex */
6689         if (!dquot_active(inode)) {
6690 @@ -1793,6 +1801,8 @@ void dquot_free_inode(const struct inode
6691         struct dquot_warn warn[MAXQUOTAS];
6692         struct dquot * const *dquots = inode->i_dquot;
6693  
6694 +       dl_free_inode(inode);
6695 +
6696         /* First test before acquiring mutex - solves deadlocks when we
6697           * re-enter the quota code and are already holding the mutex */
6698         if (!dquot_active(inode))
6699 diff -NurpP --minimal linux-3.13.1/fs/quota/quota.c linux-3.13.1-vs2.3.6.10/fs/quota/quota.c
6700 --- linux-3.13.1/fs/quota/quota.c       2014-01-22 20:39:07.000000000 +0000
6701 +++ linux-3.13.1-vs2.3.6.10/fs/quota/quota.c    2014-01-31 20:38:03.000000000 +0000
6702 @@ -8,6 +8,7 @@
6703  #include <linux/fs.h>
6704  #include <linux/namei.h>
6705  #include <linux/slab.h>
6706 +#include <linux/vs_context.h>
6707  #include <asm/current.h>
6708  #include <linux/uaccess.h>
6709  #include <linux/kernel.h>
6710 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6711                         break;
6712                 /*FALLTHROUGH*/
6713         default:
6714 -               if (!capable(CAP_SYS_ADMIN))
6715 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6716                         return -EPERM;
6717         }
6718  
6719 @@ -338,6 +339,46 @@ static int do_quotactl(struct super_bloc
6720  
6721  #ifdef CONFIG_BLOCK
6722  
6723 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6724 +
6725 +#include <linux/vroot.h>
6726 +#include <linux/major.h>
6727 +#include <linux/module.h>
6728 +#include <linux/kallsyms.h>
6729 +#include <linux/vserver/debug.h>
6730 +
6731 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6732 +
6733 +static DEFINE_SPINLOCK(vroot_grb_lock);
6734 +
6735 +int register_vroot_grb(vroot_grb_func *func) {
6736 +       int ret = -EBUSY;
6737 +
6738 +       spin_lock(&vroot_grb_lock);
6739 +       if (!vroot_get_real_bdev) {
6740 +               vroot_get_real_bdev = func;
6741 +               ret = 0;
6742 +       }
6743 +       spin_unlock(&vroot_grb_lock);
6744 +       return ret;
6745 +}
6746 +EXPORT_SYMBOL(register_vroot_grb);
6747 +
6748 +int unregister_vroot_grb(vroot_grb_func *func) {
6749 +       int ret = -EINVAL;
6750 +
6751 +       spin_lock(&vroot_grb_lock);
6752 +       if (vroot_get_real_bdev) {
6753 +               vroot_get_real_bdev = NULL;
6754 +               ret = 0;
6755 +       }
6756 +       spin_unlock(&vroot_grb_lock);
6757 +       return ret;
6758 +}
6759 +EXPORT_SYMBOL(unregister_vroot_grb);
6760 +
6761 +#endif
6762 +
6763  /* Return 1 if 'cmd' will block on frozen filesystem */
6764  static int quotactl_cmd_write(int cmd)
6765  {
6766 @@ -373,6 +414,22 @@ static struct super_block *quotactl_bloc
6767         putname(tmp);
6768         if (IS_ERR(bdev))
6769                 return ERR_CAST(bdev);
6770 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6771 +       if (bdev && bdev->bd_inode &&
6772 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6773 +               struct block_device *bdnew = (void *)-EINVAL;
6774 +
6775 +               if (vroot_get_real_bdev)
6776 +                       bdnew = vroot_get_real_bdev(bdev);
6777 +               else
6778 +                       vxdprintk(VXD_CBIT(misc, 0),
6779 +                                       "vroot_get_real_bdev not set");
6780 +               bdput(bdev);
6781 +               if (IS_ERR(bdnew))
6782 +                       return ERR_PTR(PTR_ERR(bdnew));
6783 +               bdev = bdnew;
6784 +       }
6785 +#endif
6786         if (quotactl_cmd_write(cmd))
6787                 sb = get_super_thawed(bdev);
6788         else
6789 diff -NurpP --minimal linux-3.13.1/fs/stat.c linux-3.13.1-vs2.3.6.10/fs/stat.c
6790 --- linux-3.13.1/fs/stat.c      2014-01-22 20:39:07.000000000 +0000
6791 +++ linux-3.13.1-vs2.3.6.10/fs/stat.c   2014-01-31 20:38:03.000000000 +0000
6792 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6793         stat->nlink = inode->i_nlink;
6794         stat->uid = inode->i_uid;
6795         stat->gid = inode->i_gid;
6796 +       stat->tag = inode->i_tag;
6797         stat->rdev = inode->i_rdev;
6798         stat->size = i_size_read(inode);
6799         stat->atime = inode->i_atime;
6800 diff -NurpP --minimal linux-3.13.1/fs/statfs.c linux-3.13.1-vs2.3.6.10/fs/statfs.c
6801 --- linux-3.13.1/fs/statfs.c    2013-11-25 15:47:00.000000000 +0000
6802 +++ linux-3.13.1-vs2.3.6.10/fs/statfs.c 2014-01-31 20:38:03.000000000 +0000
6803 @@ -7,6 +7,8 @@
6804  #include <linux/statfs.h>
6805  #include <linux/security.h>
6806  #include <linux/uaccess.h>
6807 +#include <linux/vs_base.h>
6808 +#include <linux/vs_dlimit.h>
6809  #include "internal.h"
6810  
6811  static int flags_by_mnt(int mnt_flags)
6812 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6813         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6814         if (retval == 0 && buf->f_frsize == 0)
6815                 buf->f_frsize = buf->f_bsize;
6816 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6817 +               vx_vsi_statfs(dentry->d_sb, buf);
6818         return retval;
6819  }
6820  
6821 diff -NurpP --minimal linux-3.13.1/fs/super.c linux-3.13.1-vs2.3.6.10/fs/super.c
6822 --- linux-3.13.1/fs/super.c     2014-01-22 20:39:07.000000000 +0000
6823 +++ linux-3.13.1-vs2.3.6.10/fs/super.c  2014-01-31 20:38:03.000000000 +0000
6824 @@ -34,6 +34,8 @@
6825  #include <linux/cleancache.h>
6826  #include <linux/fsnotify.h>
6827  #include <linux/lockdep.h>
6828 +#include <linux/magic.h>
6829 +#include <linux/vs_context.h>
6830  #include "internal.h"
6831  
6832  
6833 @@ -1098,6 +1100,13 @@ mount_fs(struct file_system_type *type,
6834         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6835         sb->s_flags |= MS_BORN;
6836  
6837 +       error = -EPERM;
6838 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6839 +               !sb->s_bdev &&
6840 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6841 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6842 +               goto out_sb;
6843 +
6844         error = security_sb_kern_mount(sb, flags, secdata);
6845         if (error)
6846                 goto out_sb;
6847 diff -NurpP --minimal linux-3.13.1/fs/sysfs/mount.c linux-3.13.1-vs2.3.6.10/fs/sysfs/mount.c
6848 --- linux-3.13.1/fs/sysfs/mount.c       2013-11-25 15:47:00.000000000 +0000
6849 +++ linux-3.13.1-vs2.3.6.10/fs/sysfs/mount.c    2014-01-31 20:38:03.000000000 +0000
6850 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6851  
6852         sb->s_blocksize = PAGE_CACHE_SIZE;
6853         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6854 -       sb->s_magic = SYSFS_MAGIC;
6855 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6856         sb->s_op = &sysfs_ops;
6857         sb->s_time_gran = 1;
6858  
6859 diff -NurpP --minimal linux-3.13.1/fs/utimes.c linux-3.13.1-vs2.3.6.10/fs/utimes.c
6860 --- linux-3.13.1/fs/utimes.c    2014-01-22 20:39:07.000000000 +0000
6861 +++ linux-3.13.1-vs2.3.6.10/fs/utimes.c 2014-01-31 23:49:14.000000000 +0000
6862 @@ -8,6 +8,8 @@
6863  #include <linux/stat.h>
6864  #include <linux/utime.h>
6865  #include <linux/syscalls.h>
6866 +#include <linux/mount.h>
6867 +#include <linux/vs_cowbl.h>
6868  #include <asm/uaccess.h>
6869  #include <asm/unistd.h>
6870  
6871 @@ -52,13 +54,19 @@ static int utimes_common(struct path *pa
6872  {
6873         int error;
6874         struct iattr newattrs;
6875 -       struct inode *inode = path->dentry->d_inode;
6876         struct inode *delegated_inode = NULL;
6877 +       struct inode *inode;
6878 +
6879 +       error = cow_check_and_break(path);
6880 +       if (error)
6881 +               goto out;
6882  
6883         error = mnt_want_write(path->mnt);
6884         if (error)
6885                 goto out;
6886  
6887 +       inode = path->dentry->d_inode;
6888 +
6889         if (times && times[0].tv_nsec == UTIME_NOW &&
6890                      times[1].tv_nsec == UTIME_NOW)
6891                 times = NULL;
6892 diff -NurpP --minimal linux-3.13.1/fs/xattr.c linux-3.13.1-vs2.3.6.10/fs/xattr.c
6893 --- linux-3.13.1/fs/xattr.c     2013-02-19 13:58:49.000000000 +0000
6894 +++ linux-3.13.1-vs2.3.6.10/fs/xattr.c  2014-01-31 20:38:03.000000000 +0000
6895 @@ -21,6 +21,7 @@
6896  #include <linux/audit.h>
6897  #include <linux/vmalloc.h>
6898  #include <linux/posix_acl_xattr.h>
6899 +#include <linux/mount.h>
6900  
6901  #include <asm/uaccess.h>
6902  
6903 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6904          * The trusted.* namespace can only be accessed by privileged users.
6905          */
6906         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6907 -               if (!capable(CAP_SYS_ADMIN))
6908 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6909                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6910                 return 0;
6911         }
6912 diff -NurpP --minimal linux-3.13.1/include/linux/cred.h linux-3.13.1-vs2.3.6.10/include/linux/cred.h
6913 --- linux-3.13.1/include/linux/cred.h   2013-02-19 13:58:50.000000000 +0000
6914 +++ linux-3.13.1-vs2.3.6.10/include/linux/cred.h        2014-01-31 20:38:03.000000000 +0000
6915 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
6916  extern int copy_creds(struct task_struct *, unsigned long);
6917  extern const struct cred *get_task_cred(struct task_struct *);
6918  extern struct cred *cred_alloc_blank(void);
6919 +extern struct cred *__prepare_creds(const struct cred *);
6920  extern struct cred *prepare_creds(void);
6921  extern struct cred *prepare_exec_creds(void);
6922  extern int commit_creds(struct cred *);
6923 @@ -196,6 +197,31 @@ static inline void validate_process_cred
6924  }
6925  #endif
6926  
6927 +static inline void set_cred_subscribers(struct cred *cred, int n)
6928 +{
6929 +#ifdef CONFIG_DEBUG_CREDENTIALS
6930 +       atomic_set(&cred->subscribers, n);
6931 +#endif
6932 +}
6933 +
6934 +static inline int read_cred_subscribers(const struct cred *cred)
6935 +{
6936 +#ifdef CONFIG_DEBUG_CREDENTIALS
6937 +       return atomic_read(&cred->subscribers);
6938 +#else
6939 +       return 0;
6940 +#endif
6941 +}
6942 +
6943 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
6944 +{
6945 +#ifdef CONFIG_DEBUG_CREDENTIALS
6946 +       struct cred *cred = (struct cred *) _cred;
6947 +
6948 +       atomic_add(n, &cred->subscribers);
6949 +#endif
6950 +}
6951 +
6952  /**
6953   * get_new_cred - Get a reference on a new set of credentials
6954   * @cred: The new credentials to reference
6955 diff -NurpP --minimal linux-3.13.1/include/linux/devpts_fs.h linux-3.13.1-vs2.3.6.10/include/linux/devpts_fs.h
6956 --- linux-3.13.1/include/linux/devpts_fs.h      2013-02-19 13:58:50.000000000 +0000
6957 +++ linux-3.13.1-vs2.3.6.10/include/linux/devpts_fs.h   2014-01-31 20:38:03.000000000 +0000
6958 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
6959  
6960  #endif
6961  
6962 -
6963  #endif /* _LINUX_DEVPTS_FS_H */
6964 diff -NurpP --minimal linux-3.13.1/include/linux/fs.h linux-3.13.1-vs2.3.6.10/include/linux/fs.h
6965 --- linux-3.13.1/include/linux/fs.h     2014-01-22 20:39:10.000000000 +0000
6966 +++ linux-3.13.1-vs2.3.6.10/include/linux/fs.h  2014-01-31 23:33:22.000000000 +0000
6967 @@ -213,6 +213,7 @@ typedef void (dio_iodone_t)(struct kiocb
6968  #define ATTR_KILL_PRIV (1 << 14)
6969  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
6970  #define ATTR_TIMES_SET (1 << 16)
6971 +#define ATTR_TAG       (1 << 17)
6972  
6973  /*
6974   * This is the Inode Attributes structure, used for notify_change().  It
6975 @@ -228,6 +229,7 @@ struct iattr {
6976         umode_t         ia_mode;
6977         kuid_t          ia_uid;
6978         kgid_t          ia_gid;
6979 +       ktag_t          ia_tag;
6980         loff_t          ia_size;
6981         struct timespec ia_atime;
6982         struct timespec ia_mtime;
6983 @@ -526,7 +528,9 @@ struct inode {
6984         unsigned short          i_opflags;
6985         kuid_t                  i_uid;
6986         kgid_t                  i_gid;
6987 -       unsigned int            i_flags;
6988 +       ktag_t                  i_tag;
6989 +       unsigned short          i_flags;
6990 +       unsigned short          i_vflags;
6991  
6992  #ifdef CONFIG_FS_POSIX_ACL
6993         struct posix_acl        *i_acl;
6994 @@ -555,6 +559,7 @@ struct inode {
6995                 unsigned int __i_nlink;
6996         };
6997         dev_t                   i_rdev;
6998 +       dev_t                   i_mdev;
6999         loff_t                  i_size;
7000         struct timespec         i_atime;
7001         struct timespec         i_mtime;
7002 @@ -713,6 +718,11 @@ static inline gid_t i_gid_read(const str
7003         return from_kgid(&init_user_ns, inode->i_gid);
7004  }
7005  
7006 +static inline vtag_t i_tag_read(const struct inode *inode)
7007 +{
7008 +       return from_ktag(&init_user_ns, inode->i_tag);
7009 +}
7010 +
7011  static inline void i_uid_write(struct inode *inode, uid_t uid)
7012  {
7013         inode->i_uid = make_kuid(&init_user_ns, uid);
7014 @@ -723,14 +733,19 @@ static inline void i_gid_write(struct in
7015         inode->i_gid = make_kgid(&init_user_ns, gid);
7016  }
7017  
7018 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
7019 +{
7020 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7021 +}
7022 +
7023  static inline unsigned iminor(const struct inode *inode)
7024  {
7025 -       return MINOR(inode->i_rdev);
7026 +       return MINOR(inode->i_mdev);
7027  }
7028  
7029  static inline unsigned imajor(const struct inode *inode)
7030  {
7031 -       return MAJOR(inode->i_rdev);
7032 +       return MAJOR(inode->i_mdev);
7033  }
7034  
7035  extern struct block_device *I_BDEV(struct inode *inode);
7036 @@ -790,6 +805,7 @@ struct file {
7037         loff_t                  f_pos;
7038         struct fown_struct      f_owner;
7039         const struct cred       *f_cred;
7040 +       vxid_t                  f_xid;
7041         struct file_ra_state    f_ra;
7042  
7043         u64                     f_version;
7044 @@ -962,6 +978,7 @@ struct file_lock {
7045         struct file *fl_file;
7046         loff_t fl_start;
7047         loff_t fl_end;
7048 +       vxid_t fl_xid;
7049  
7050         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7051         /* for lease breaks: */
7052 @@ -1573,6 +1590,7 @@ struct inode_operations {
7053         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7054         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7055         int (*removexattr) (struct dentry *, const char *);
7056 +       int (*sync_flags) (struct inode *, int, int);
7057         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7058                       u64 len);
7059         int (*update_time)(struct inode *, struct timespec *, int);
7060 @@ -1586,6 +1604,7 @@ ssize_t rw_copy_check_uvector(int type,
7061                               unsigned long nr_segs, unsigned long fast_segs,
7062                               struct iovec *fast_pointer,
7063                               struct iovec **ret_pointer);
7064 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7065  
7066  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7067  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7068 @@ -1639,6 +1658,14 @@ struct super_operations {
7069  #define S_IMA          1024    /* Inode has an associated IMA struct */
7070  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7071  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7072 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7073 +
7074 +/* Linux-VServer related Inode flags */
7075 +
7076 +#define V_VALID                1
7077 +#define V_XATTR                2
7078 +#define V_BARRIER      4       /* Barrier for chroot() */
7079 +#define V_COW          8       /* Copy on Write */
7080  
7081  /*
7082   * Note that nosuid etc flags are inode-specific: setting some file-system
7083 @@ -1663,10 +1690,13 @@ struct super_operations {
7084  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7085  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7086  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7087 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7088  
7089  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7090  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7091  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7092 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7093 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7094  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7095  
7096  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7097 @@ -1677,6 +1707,16 @@ struct super_operations {
7098  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7099  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7100  
7101 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7102 +
7103 +#ifdef CONFIG_VSERVER_COWBL
7104 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7105 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7106 +#else
7107 +#  define IS_COW(inode)                (0)
7108 +#  define IS_COW_LINK(inode)   (0)
7109 +#endif
7110 +
7111  /*
7112   * Inode state bits.  Protected by inode->i_lock
7113   *
7114 @@ -1920,6 +1960,9 @@ extern struct kobject *fs_kobj;
7115  extern int locks_mandatory_locked(struct inode *);
7116  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7117  
7118 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7119 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7120 +
7121  /*
7122   * Candidates for mandatory locking have the setgid bit set
7123   * but no group execute bit -  an otherwise meaningless combination.
7124 @@ -2605,6 +2648,7 @@ extern int dcache_dir_open(struct inode
7125  extern int dcache_dir_close(struct inode *, struct file *);
7126  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7127  extern int dcache_readdir(struct file *, struct dir_context *);
7128 +extern int dcache_readdir_filter(struct file *, struct dir_context *, int (*)(struct dentry *));
7129  extern int simple_setattr(struct dentry *, struct iattr *);
7130  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7131  extern int simple_statfs(struct dentry *, struct kstatfs *);
7132 diff -NurpP --minimal linux-3.13.1/include/linux/init_task.h linux-3.13.1-vs2.3.6.10/include/linux/init_task.h
7133 --- linux-3.13.1/include/linux/init_task.h      2014-01-22 20:39:11.000000000 +0000
7134 +++ linux-3.13.1-vs2.3.6.10/include/linux/init_task.h   2014-01-31 20:38:03.000000000 +0000
7135 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7136         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7137         INIT_CPUSET_SEQ(tsk)                                            \
7138         INIT_VTIME(tsk)                                                 \
7139 +       .xid            = 0,                                            \
7140 +       .vx_info        = NULL,                                         \
7141 +       .nid            = 0,                                            \
7142 +       .nx_info        = NULL,                                         \
7143  }
7144  
7145  
7146 diff -NurpP --minimal linux-3.13.1/include/linux/ipc.h linux-3.13.1-vs2.3.6.10/include/linux/ipc.h
7147 --- linux-3.13.1/include/linux/ipc.h    2012-12-11 03:30:57.000000000 +0000
7148 +++ linux-3.13.1-vs2.3.6.10/include/linux/ipc.h 2014-01-31 20:38:03.000000000 +0000
7149 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7150         key_t           key;
7151         kuid_t          uid;
7152         kgid_t          gid;
7153 +       vxid_t          xid;
7154         kuid_t          cuid;
7155         kgid_t          cgid;
7156         umode_t         mode; 
7157 diff -NurpP --minimal linux-3.13.1/include/linux/memcontrol.h linux-3.13.1-vs2.3.6.10/include/linux/memcontrol.h
7158 --- linux-3.13.1/include/linux/memcontrol.h     2013-11-25 15:47:01.000000000 +0000
7159 +++ linux-3.13.1-vs2.3.6.10/include/linux/memcontrol.h  2014-01-31 20:38:03.000000000 +0000
7160 @@ -99,6 +99,13 @@ extern struct mem_cgroup *try_get_mem_cg
7161  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7162  extern struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css);
7163  
7164 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7165 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7166 +
7167 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7168 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7169 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7170 +
7171  static inline
7172  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7173  {
7174 diff -NurpP --minimal linux-3.13.1/include/linux/mm_types.h linux-3.13.1-vs2.3.6.10/include/linux/mm_types.h
7175 --- linux-3.13.1/include/linux/mm_types.h       2014-01-22 20:39:11.000000000 +0000
7176 +++ linux-3.13.1-vs2.3.6.10/include/linux/mm_types.h    2014-01-31 20:38:03.000000000 +0000
7177 @@ -397,6 +397,7 @@ struct mm_struct {
7178  
7179         /* Architecture-specific MM context */
7180         mm_context_t context;
7181 +       struct vx_info *mm_vx_info;
7182  
7183         unsigned long flags; /* Must use atomic bitops to access the bits */
7184  
7185 diff -NurpP --minimal linux-3.13.1/include/linux/mount.h linux-3.13.1-vs2.3.6.10/include/linux/mount.h
7186 --- linux-3.13.1/include/linux/mount.h  2014-01-22 20:39:11.000000000 +0000
7187 +++ linux-3.13.1-vs2.3.6.10/include/linux/mount.h       2014-01-31 20:38:03.000000000 +0000
7188 @@ -52,6 +52,9 @@ struct mnt_namespace;
7189  #define MNT_DOOMED             0x1000000
7190  #define MNT_SYNC_UMOUNT                0x2000000
7191  
7192 +#define MNT_TAGID      0x10000
7193 +#define MNT_NOTAG      0x20000
7194 +
7195  struct vfsmount {
7196         struct dentry *mnt_root;        /* root of the mounted tree */
7197         struct super_block *mnt_sb;     /* pointer to superblock */
7198 diff -NurpP --minimal linux-3.13.1/include/linux/net.h linux-3.13.1-vs2.3.6.10/include/linux/net.h
7199 --- linux-3.13.1/include/linux/net.h    2014-01-22 20:39:11.000000000 +0000
7200 +++ linux-3.13.1-vs2.3.6.10/include/linux/net.h 2014-01-31 20:38:03.000000000 +0000
7201 @@ -39,6 +39,7 @@ struct net;
7202  #define SOCK_PASSCRED          3
7203  #define SOCK_PASSSEC           4
7204  #define SOCK_EXTERNALLY_ALLOCATED 5
7205 +#define SOCK_USER_SOCKET       6
7206  
7207  #ifndef ARCH_HAS_SOCKET_TYPES
7208  /**
7209 diff -NurpP --minimal linux-3.13.1/include/linux/netdevice.h linux-3.13.1-vs2.3.6.10/include/linux/netdevice.h
7210 --- linux-3.13.1/include/linux/netdevice.h      2014-01-22 20:39:11.000000000 +0000
7211 +++ linux-3.13.1-vs2.3.6.10/include/linux/netdevice.h   2014-01-31 20:44:02.000000000 +0000
7212 @@ -1839,6 +1839,7 @@ int init_dummy_netdev(struct net_device
7213  
7214  struct net_device *dev_get_by_index(struct net *net, int ifindex);
7215  struct net_device *__dev_get_by_index(struct net *net, int ifindex);
7216 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7217  struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
7218  int netdev_get_name(struct net *net, char *name, int ifindex);
7219  int dev_restart(struct net_device *dev);
7220 diff -NurpP --minimal linux-3.13.1/include/linux/nsproxy.h linux-3.13.1-vs2.3.6.10/include/linux/nsproxy.h
7221 --- linux-3.13.1/include/linux/nsproxy.h        2013-11-25 15:45:06.000000000 +0000
7222 +++ linux-3.13.1-vs2.3.6.10/include/linux/nsproxy.h     2014-01-31 20:38:03.000000000 +0000
7223 @@ -3,6 +3,7 @@
7224  
7225  #include <linux/spinlock.h>
7226  #include <linux/sched.h>
7227 +#include <linux/vserver/debug.h>
7228  
7229  struct mnt_namespace;
7230  struct uts_namespace;
7231 @@ -67,6 +68,7 @@ static inline struct nsproxy *task_nspro
7232  }
7233  
7234  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7235 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7236  void exit_task_namespaces(struct task_struct *tsk);
7237  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7238  void free_nsproxy(struct nsproxy *ns);
7239 @@ -74,16 +76,26 @@ int unshare_nsproxy_namespaces(unsigned
7240         struct cred *, struct fs_struct *);
7241  int __init nsproxy_cache_init(void);
7242  
7243 -static inline void put_nsproxy(struct nsproxy *ns)
7244 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
7245 +
7246 +static inline void __get_nsproxy(struct nsproxy *ns,
7247 +       const char *_file, int _line)
7248  {
7249 -       if (atomic_dec_and_test(&ns->count)) {
7250 -               free_nsproxy(ns);
7251 -       }
7252 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7253 +               ns, atomic_read(&ns->count), _file, _line);
7254 +       atomic_inc(&ns->count);
7255  }
7256  
7257 -static inline void get_nsproxy(struct nsproxy *ns)
7258 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
7259 +
7260 +static inline void __put_nsproxy(struct nsproxy *ns,
7261 +       const char *_file, int _line)
7262  {
7263 -       atomic_inc(&ns->count);
7264 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7265 +               ns, atomic_read(&ns->count), _file, _line);
7266 +       if (atomic_dec_and_test(&ns->count)) {
7267 +               free_nsproxy(ns);
7268 +       }
7269  }
7270  
7271  #endif
7272 diff -NurpP --minimal linux-3.13.1/include/linux/pid.h linux-3.13.1-vs2.3.6.10/include/linux/pid.h
7273 --- linux-3.13.1/include/linux/pid.h    2013-11-25 15:45:06.000000000 +0000
7274 +++ linux-3.13.1-vs2.3.6.10/include/linux/pid.h 2014-01-31 20:38:03.000000000 +0000
7275 @@ -8,7 +8,8 @@ enum pid_type
7276         PIDTYPE_PID,
7277         PIDTYPE_PGID,
7278         PIDTYPE_SID,
7279 -       PIDTYPE_MAX
7280 +       PIDTYPE_MAX,
7281 +       PIDTYPE_REALPID
7282  };
7283  
7284  /*
7285 @@ -170,6 +171,7 @@ static inline pid_t pid_nr(struct pid *p
7286  }
7287  
7288  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7289 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7290  pid_t pid_vnr(struct pid *pid);
7291  
7292  #define do_each_pid_task(pid, type, task)                              \
7293 diff -NurpP --minimal linux-3.13.1/include/linux/quotaops.h linux-3.13.1-vs2.3.6.10/include/linux/quotaops.h
7294 --- linux-3.13.1/include/linux/quotaops.h       2013-11-25 15:47:02.000000000 +0000
7295 +++ linux-3.13.1-vs2.3.6.10/include/linux/quotaops.h    2014-01-31 20:38:03.000000000 +0000
7296 @@ -8,6 +8,7 @@
7297  #define _LINUX_QUOTAOPS_
7298  
7299  #include <linux/fs.h>
7300 +#include <linux/vs_dlimit.h>
7301  
7302  #define DQUOT_SPACE_WARN       0x1
7303  #define DQUOT_SPACE_RESERVE    0x2
7304 @@ -207,11 +208,12 @@ static inline void dquot_drop(struct ino
7305  
7306  static inline int dquot_alloc_inode(const struct inode *inode)
7307  {
7308 -       return 0;
7309 +       return dl_alloc_inode(inode);
7310  }
7311  
7312  static inline void dquot_free_inode(const struct inode *inode)
7313  {
7314 +       dl_free_inode(inode);
7315  }
7316  
7317  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
7318 @@ -222,6 +224,10 @@ static inline int dquot_transfer(struct
7319  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
7320                 int flags)
7321  {
7322 +       int ret = 0;
7323 +
7324 +       if ((ret = dl_alloc_space(inode, number)))
7325 +               return ret;
7326         if (!(flags & DQUOT_SPACE_RESERVE))
7327                 inode_add_bytes(inode, number);
7328         return 0;
7329 @@ -232,6 +238,7 @@ static inline void __dquot_free_space(st
7330  {
7331         if (!(flags & DQUOT_SPACE_RESERVE))
7332                 inode_sub_bytes(inode, number);
7333 +       dl_free_space(inode, number);
7334  }
7335  
7336  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
7337 diff -NurpP --minimal linux-3.13.1/include/linux/sched.h linux-3.13.1-vs2.3.6.10/include/linux/sched.h
7338 --- linux-3.13.1/include/linux/sched.h  2014-01-22 20:39:11.000000000 +0000
7339 +++ linux-3.13.1-vs2.3.6.10/include/linux/sched.h       2014-01-31 20:38:03.000000000 +0000
7340 @@ -1237,6 +1237,14 @@ struct task_struct {
7341  #endif
7342         struct seccomp seccomp;
7343  
7344 +/* vserver context data */
7345 +       struct vx_info *vx_info;
7346 +       struct nx_info *nx_info;
7347 +
7348 +       vxid_t xid;
7349 +       vnid_t nid;
7350 +       vtag_t tag;
7351 +
7352  /* Thread group tracking */
7353         u32 parent_exec_id;
7354         u32 self_exec_id;
7355 @@ -1531,6 +1539,11 @@ struct pid_namespace;
7356  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
7357                         struct pid_namespace *ns);
7358  
7359 +#include <linux/vserver/base.h>
7360 +#include <linux/vserver/context.h>
7361 +#include <linux/vserver/debug.h>
7362 +#include <linux/vserver/pid.h>
7363 +
7364  static inline pid_t task_pid_nr(struct task_struct *tsk)
7365  {
7366         return tsk->pid;
7367 @@ -1544,7 +1557,8 @@ static inline pid_t task_pid_nr_ns(struc
7368  
7369  static inline pid_t task_pid_vnr(struct task_struct *tsk)
7370  {
7371 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7372 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7373 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
7374  }
7375  
7376  
7377 @@ -1557,7 +1571,7 @@ pid_t task_tgid_nr_ns(struct task_struct
7378  
7379  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
7380  {
7381 -       return pid_vnr(task_tgid(tsk));
7382 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
7383  }
7384  
7385  
7386 diff -NurpP --minimal linux-3.13.1/include/linux/shmem_fs.h linux-3.13.1-vs2.3.6.10/include/linux/shmem_fs.h
7387 --- linux-3.13.1/include/linux/shmem_fs.h       2014-01-22 20:39:11.000000000 +0000
7388 +++ linux-3.13.1-vs2.3.6.10/include/linux/shmem_fs.h    2014-01-31 20:38:03.000000000 +0000
7389 @@ -9,6 +9,9 @@
7390  
7391  /* inode in-kernel data */
7392  
7393 +#define TMPFS_SUPER_MAGIC      0x01021994
7394 +
7395 +
7396  struct shmem_inode_info {
7397         spinlock_t              lock;
7398         unsigned long           flags;
7399 diff -NurpP --minimal linux-3.13.1/include/linux/stat.h linux-3.13.1-vs2.3.6.10/include/linux/stat.h
7400 --- linux-3.13.1/include/linux/stat.h   2012-12-11 03:30:57.000000000 +0000
7401 +++ linux-3.13.1-vs2.3.6.10/include/linux/stat.h        2014-01-31 20:38:03.000000000 +0000
7402 @@ -25,6 +25,7 @@ struct kstat {
7403         unsigned int    nlink;
7404         kuid_t          uid;
7405         kgid_t          gid;
7406 +       ktag_t          tag;
7407         dev_t           rdev;
7408         loff_t          size;
7409         struct timespec  atime;
7410 diff -NurpP --minimal linux-3.13.1/include/linux/sunrpc/auth.h linux-3.13.1-vs2.3.6.10/include/linux/sunrpc/auth.h
7411 --- linux-3.13.1/include/linux/sunrpc/auth.h    2013-11-25 15:47:02.000000000 +0000
7412 +++ linux-3.13.1-vs2.3.6.10/include/linux/sunrpc/auth.h 2014-01-31 20:38:03.000000000 +0000
7413 @@ -36,6 +36,7 @@ enum {
7414  struct auth_cred {
7415         kuid_t  uid;
7416         kgid_t  gid;
7417 +       ktag_t  tag;
7418         struct group_info *group_info;
7419         const char *principal;
7420         unsigned long ac_flags;
7421 diff -NurpP --minimal linux-3.13.1/include/linux/sunrpc/clnt.h linux-3.13.1-vs2.3.6.10/include/linux/sunrpc/clnt.h
7422 --- linux-3.13.1/include/linux/sunrpc/clnt.h    2014-01-22 20:39:11.000000000 +0000
7423 +++ linux-3.13.1-vs2.3.6.10/include/linux/sunrpc/clnt.h 2014-01-31 20:38:03.000000000 +0000
7424 @@ -51,7 +51,8 @@ struct rpc_clnt {
7425                                 cl_discrtry : 1,/* disconnect before retry */
7426                                 cl_noretranstimeo: 1,/* No retransmit timeouts */
7427                                 cl_autobind : 1,/* use getport() */
7428 -                               cl_chatty   : 1;/* be verbose */
7429 +                               cl_chatty   : 1,/* be verbose */
7430 +                               cl_tag      : 1;/* context tagging */
7431  
7432         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
7433         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
7434 diff -NurpP --minimal linux-3.13.1/include/linux/sysfs.h linux-3.13.1-vs2.3.6.10/include/linux/sysfs.h
7435 --- linux-3.13.1/include/linux/sysfs.h  2014-01-22 20:39:11.000000000 +0000
7436 +++ linux-3.13.1-vs2.3.6.10/include/linux/sysfs.h       2014-01-31 20:38:03.000000000 +0000
7437 @@ -20,6 +20,8 @@
7438  #include <linux/stat.h>
7439  #include <linux/atomic.h>
7440  
7441 +#define SYSFS_SUPER_MAGIC      0x62656572
7442 +
7443  struct kobject;
7444  struct module;
7445  struct bin_attribute;
7446 diff -NurpP --minimal linux-3.13.1/include/linux/types.h linux-3.13.1-vs2.3.6.10/include/linux/types.h
7447 --- linux-3.13.1/include/linux/types.h  2013-02-19 13:58:52.000000000 +0000
7448 +++ linux-3.13.1-vs2.3.6.10/include/linux/types.h       2014-01-31 20:38:03.000000000 +0000
7449 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
7450  typedef __kernel_gid32_t       gid_t;
7451  typedef __kernel_uid16_t        uid16_t;
7452  typedef __kernel_gid16_t        gid16_t;
7453 +typedef unsigned int           vxid_t;
7454 +typedef unsigned int           vnid_t;
7455 +typedef unsigned int           vtag_t;
7456  
7457  typedef unsigned long          uintptr_t;
7458  
7459 diff -NurpP --minimal linux-3.13.1/include/linux/uidgid.h linux-3.13.1-vs2.3.6.10/include/linux/uidgid.h
7460 --- linux-3.13.1/include/linux/uidgid.h 2012-12-11 03:30:57.000000000 +0000
7461 +++ linux-3.13.1-vs2.3.6.10/include/linux/uidgid.h      2014-01-31 20:38:03.000000000 +0000
7462 @@ -23,13 +23,17 @@ typedef struct {
7463         uid_t val;
7464  } kuid_t;
7465  
7466 -
7467  typedef struct {
7468         gid_t val;
7469  } kgid_t;
7470  
7471 +typedef struct {
7472 +       vtag_t val;
7473 +} ktag_t;
7474 +
7475  #define KUIDT_INIT(value) (kuid_t){ value }
7476  #define KGIDT_INIT(value) (kgid_t){ value }
7477 +#define KTAGT_INIT(value) (ktag_t){ value }
7478  
7479  static inline uid_t __kuid_val(kuid_t uid)
7480  {
7481 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
7482         return gid.val;
7483  }
7484  
7485 +static inline vtag_t __ktag_val(ktag_t tag)
7486 +{
7487 +       return tag.val;
7488 +}
7489 +
7490  #else
7491  
7492  typedef uid_t kuid_t;
7493  typedef gid_t kgid_t;
7494 +typedef vtag_t ktag_t;
7495  
7496  static inline uid_t __kuid_val(kuid_t uid)
7497  {
7498 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
7499         return gid;
7500  }
7501  
7502 +static inline vtag_t __ktag_val(ktag_t tag)
7503 +{
7504 +       return tag;
7505 +}
7506 +
7507  #define KUIDT_INIT(value) ((kuid_t) value )
7508  #define KGIDT_INIT(value) ((kgid_t) value )
7509 +#define KTAGT_INIT(value) ((ktag_t) value )
7510  
7511  #endif
7512  
7513  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
7514  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
7515 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
7516  
7517  #define INVALID_UID KUIDT_INIT(-1)
7518  #define INVALID_GID KGIDT_INIT(-1)
7519 +#define INVALID_TAG KTAGT_INIT(-1)
7520  
7521  static inline bool uid_eq(kuid_t left, kuid_t right)
7522  {
7523 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
7524         return __kgid_val(left) == __kgid_val(right);
7525  }
7526  
7527 +static inline bool tag_eq(ktag_t left, ktag_t right)
7528 +{
7529 +       return __ktag_val(left) == __ktag_val(right);
7530 +}
7531 +
7532  static inline bool uid_gt(kuid_t left, kuid_t right)
7533  {
7534         return __kuid_val(left) > __kuid_val(right);
7535 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
7536         return !gid_eq(gid, INVALID_GID);
7537  }
7538  
7539 +static inline bool tag_valid(ktag_t tag)
7540 +{
7541 +       return !tag_eq(tag, INVALID_TAG);
7542 +}
7543 +
7544  #ifdef CONFIG_USER_NS
7545  
7546  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
7547  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
7548 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
7549  
7550  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
7551  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
7552 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
7553 +
7554  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
7555  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
7556  
7557 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
7558         return KGIDT_INIT(gid);
7559  }
7560  
7561 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
7562 +{
7563 +       return KTAGT_INIT(tag);
7564 +}
7565 +
7566  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
7567  {
7568         return __kuid_val(kuid);
7569 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
7570         return __kgid_val(kgid);
7571  }
7572  
7573 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
7574 +{
7575 +       return __ktag_val(ktag);
7576 +}
7577 +
7578  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
7579  {
7580         uid_t uid = from_kuid(to, kuid);
7581 diff -NurpP --minimal linux-3.13.1/include/linux/vroot.h linux-3.13.1-vs2.3.6.10/include/linux/vroot.h
7582 --- linux-3.13.1/include/linux/vroot.h  1970-01-01 00:00:00.000000000 +0000
7583 +++ linux-3.13.1-vs2.3.6.10/include/linux/vroot.h       2014-01-31 20:38:03.000000000 +0000
7584 @@ -0,0 +1,51 @@
7585 +
7586 +/*
7587 + * include/linux/vroot.h
7588 + *
7589 + * written by Herbert Pötzl, 9/11/2002
7590 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
7591 + *
7592 + * Copyright (C) 2002-2007 by Herbert Pötzl.
7593 + * Redistribution of this file is permitted under the
7594 + * GNU General Public License.
7595 + */
7596 +
7597 +#ifndef _LINUX_VROOT_H
7598 +#define _LINUX_VROOT_H
7599 +
7600 +
7601 +#ifdef __KERNEL__
7602 +
7603 +/* Possible states of device */
7604 +enum {
7605 +       Vr_unbound,
7606 +       Vr_bound,
7607 +};
7608 +
7609 +struct vroot_device {
7610 +       int             vr_number;
7611 +       int             vr_refcnt;
7612 +
7613 +       struct semaphore        vr_ctl_mutex;
7614 +       struct block_device    *vr_device;
7615 +       int                     vr_state;
7616 +};
7617 +
7618 +
7619 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
7620 +
7621 +extern int register_vroot_grb(vroot_grb_func *);
7622 +extern int unregister_vroot_grb(vroot_grb_func *);
7623 +
7624 +#endif /* __KERNEL__ */
7625 +
7626 +#define MAX_VROOT_DEFAULT      8
7627 +
7628 +/*
7629 + * IOCTL commands --- we will commandeer 0x56 ('V')
7630 + */
7631 +
7632 +#define VROOT_SET_DEV          0x5600
7633 +#define VROOT_CLR_DEV          0x5601
7634 +
7635 +#endif /* _LINUX_VROOT_H */
7636 diff -NurpP --minimal linux-3.13.1/include/linux/vs_base.h linux-3.13.1-vs2.3.6.10/include/linux/vs_base.h
7637 --- linux-3.13.1/include/linux/vs_base.h        1970-01-01 00:00:00.000000000 +0000
7638 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_base.h     2014-01-31 20:38:03.000000000 +0000
7639 @@ -0,0 +1,10 @@
7640 +#ifndef _VS_BASE_H
7641 +#define _VS_BASE_H
7642 +
7643 +#include "vserver/base.h"
7644 +#include "vserver/check.h"
7645 +#include "vserver/debug.h"
7646 +
7647 +#else
7648 +#warning duplicate inclusion
7649 +#endif
7650 diff -NurpP --minimal linux-3.13.1/include/linux/vs_context.h linux-3.13.1-vs2.3.6.10/include/linux/vs_context.h
7651 --- linux-3.13.1/include/linux/vs_context.h     1970-01-01 00:00:00.000000000 +0000
7652 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_context.h  2014-01-31 20:38:03.000000000 +0000
7653 @@ -0,0 +1,242 @@
7654 +#ifndef _VS_CONTEXT_H
7655 +#define _VS_CONTEXT_H
7656 +
7657 +#include "vserver/base.h"
7658 +#include "vserver/check.h"
7659 +#include "vserver/context.h"
7660 +#include "vserver/history.h"
7661 +#include "vserver/debug.h"
7662 +
7663 +#include <linux/sched.h>
7664 +
7665 +
7666 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
7667 +
7668 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
7669 +       const char *_file, int _line, void *_here)
7670 +{
7671 +       if (!vxi)
7672 +               return NULL;
7673 +
7674 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
7675 +               vxi, vxi ? vxi->vx_id : 0,
7676 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7677 +               _file, _line);
7678 +       __vxh_get_vx_info(vxi, _here);
7679 +
7680 +       atomic_inc(&vxi->vx_usecnt);
7681 +       return vxi;
7682 +}
7683 +
7684 +
7685 +extern void free_vx_info(struct vx_info *);
7686 +
7687 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
7688 +
7689 +static inline void __put_vx_info(struct vx_info *vxi,
7690 +       const char *_file, int _line, void *_here)
7691 +{
7692 +       if (!vxi)
7693 +               return;
7694 +
7695 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
7696 +               vxi, vxi ? vxi->vx_id : 0,
7697 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7698 +               _file, _line);
7699 +       __vxh_put_vx_info(vxi, _here);
7700 +
7701 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
7702 +               free_vx_info(vxi);
7703 +}
7704 +
7705 +
7706 +#define init_vx_info(p, i) \
7707 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7708 +
7709 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7710 +       const char *_file, int _line, void *_here)
7711 +{
7712 +       if (vxi) {
7713 +               vxlprintk(VXD_CBIT(xid, 3),
7714 +                       "init_vx_info(%p[#%d.%d])",
7715 +                       vxi, vxi ? vxi->vx_id : 0,
7716 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7717 +                       _file, _line);
7718 +               __vxh_init_vx_info(vxi, vxp, _here);
7719 +
7720 +               atomic_inc(&vxi->vx_usecnt);
7721 +       }
7722 +       *vxp = vxi;
7723 +}
7724 +
7725 +
7726 +#define set_vx_info(p, i) \
7727 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7728 +
7729 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7730 +       const char *_file, int _line, void *_here)
7731 +{
7732 +       struct vx_info *vxo;
7733 +
7734 +       if (!vxi)
7735 +               return;
7736 +
7737 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
7738 +               vxi, vxi ? vxi->vx_id : 0,
7739 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7740 +               _file, _line);
7741 +       __vxh_set_vx_info(vxi, vxp, _here);
7742 +
7743 +       atomic_inc(&vxi->vx_usecnt);
7744 +       vxo = xchg(vxp, vxi);
7745 +       BUG_ON(vxo);
7746 +}
7747 +
7748 +
7749 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
7750 +
7751 +static inline void __clr_vx_info(struct vx_info **vxp,
7752 +       const char *_file, int _line, void *_here)
7753 +{
7754 +       struct vx_info *vxo;
7755 +
7756 +       vxo = xchg(vxp, NULL);
7757 +       if (!vxo)
7758 +               return;
7759 +
7760 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
7761 +               vxo, vxo ? vxo->vx_id : 0,
7762 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
7763 +               _file, _line);
7764 +       __vxh_clr_vx_info(vxo, vxp, _here);
7765 +
7766 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
7767 +               free_vx_info(vxo);
7768 +}
7769 +
7770 +
7771 +#define claim_vx_info(v, p) \
7772 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7773 +
7774 +static inline void __claim_vx_info(struct vx_info *vxi,
7775 +       struct task_struct *task,
7776 +       const char *_file, int _line, void *_here)
7777 +{
7778 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
7779 +               vxi, vxi ? vxi->vx_id : 0,
7780 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7781 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7782 +               task, _file, _line);
7783 +       __vxh_claim_vx_info(vxi, task, _here);
7784 +
7785 +       atomic_inc(&vxi->vx_tasks);
7786 +}
7787 +
7788 +
7789 +extern void unhash_vx_info(struct vx_info *);
7790 +
7791 +#define release_vx_info(v, p) \
7792 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7793 +
7794 +static inline void __release_vx_info(struct vx_info *vxi,
7795 +       struct task_struct *task,
7796 +       const char *_file, int _line, void *_here)
7797 +{
7798 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
7799 +               vxi, vxi ? vxi->vx_id : 0,
7800 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7801 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7802 +               task, _file, _line);
7803 +       __vxh_release_vx_info(vxi, task, _here);
7804 +
7805 +       might_sleep();
7806 +
7807 +       if (atomic_dec_and_test(&vxi->vx_tasks))
7808 +               unhash_vx_info(vxi);
7809 +}
7810 +
7811 +
7812 +#define task_get_vx_info(p) \
7813 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
7814 +
7815 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
7816 +       const char *_file, int _line, void *_here)
7817 +{
7818 +       struct vx_info *vxi;
7819 +
7820 +       task_lock(p);
7821 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
7822 +               p, _file, _line);
7823 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
7824 +       task_unlock(p);
7825 +       return vxi;
7826 +}
7827 +
7828 +
7829 +static inline void __wakeup_vx_info(struct vx_info *vxi)
7830 +{
7831 +       if (waitqueue_active(&vxi->vx_wait))
7832 +               wake_up_interruptible(&vxi->vx_wait);
7833 +}
7834 +
7835 +
7836 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
7837 +
7838 +static inline void __enter_vx_info(struct vx_info *vxi,
7839 +       struct vx_info_save *vxis, const char *_file, int _line)
7840 +{
7841 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
7842 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
7843 +               current->xid, current->vx_info, _file, _line);
7844 +       vxis->vxi = xchg(&current->vx_info, vxi);
7845 +       vxis->xid = current->xid;
7846 +       current->xid = vxi ? vxi->vx_id : 0;
7847 +}
7848 +
7849 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
7850 +
7851 +static inline void __leave_vx_info(struct vx_info_save *vxis,
7852 +       const char *_file, int _line)
7853 +{
7854 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
7855 +               vxis, vxis->xid, vxis->vxi, current,
7856 +               current->xid, current->vx_info, _file, _line);
7857 +       (void)xchg(&current->vx_info, vxis->vxi);
7858 +       current->xid = vxis->xid;
7859 +}
7860 +
7861 +
7862 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
7863 +{
7864 +       vxis->vxi = xchg(&current->vx_info, NULL);
7865 +       vxis->xid = xchg(&current->xid, (vxid_t)0);
7866 +}
7867 +
7868 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
7869 +{
7870 +       (void)xchg(&current->xid, vxis->xid);
7871 +       (void)xchg(&current->vx_info, vxis->vxi);
7872 +}
7873 +
7874 +#define task_is_init(p) \
7875 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
7876 +
7877 +static inline int __task_is_init(struct task_struct *p,
7878 +       const char *_file, int _line, void *_here)
7879 +{
7880 +       int is_init = is_global_init(p);
7881 +
7882 +       task_lock(p);
7883 +       if (p->vx_info)
7884 +               is_init = p->vx_info->vx_initpid == p->pid;
7885 +       task_unlock(p);
7886 +       return is_init;
7887 +}
7888 +
7889 +extern void exit_vx_info(struct task_struct *, int);
7890 +extern void exit_vx_info_early(struct task_struct *, int);
7891 +
7892 +
7893 +#else
7894 +#warning duplicate inclusion
7895 +#endif
7896 diff -NurpP --minimal linux-3.13.1/include/linux/vs_cowbl.h linux-3.13.1-vs2.3.6.10/include/linux/vs_cowbl.h
7897 --- linux-3.13.1/include/linux/vs_cowbl.h       1970-01-01 00:00:00.000000000 +0000
7898 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_cowbl.h    2014-01-31 20:38:03.000000000 +0000
7899 @@ -0,0 +1,48 @@
7900 +#ifndef _VS_COWBL_H
7901 +#define _VS_COWBL_H
7902 +
7903 +#include <linux/fs.h>
7904 +#include <linux/dcache.h>
7905 +#include <linux/namei.h>
7906 +#include <linux/slab.h>
7907 +
7908 +extern struct dentry *cow_break_link(const char *pathname);
7909 +
7910 +static inline int cow_check_and_break(struct path *path)
7911 +{
7912 +       struct inode *inode = path->dentry->d_inode;
7913 +       int error = 0;
7914 +
7915 +       /* do we need this check? */
7916 +       if (IS_RDONLY(inode))
7917 +               return -EROFS;
7918 +
7919 +       if (IS_COW(inode)) {
7920 +               if (IS_COW_LINK(inode)) {
7921 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
7922 +                       char *pp, *buf;
7923 +
7924 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
7925 +                       if (!buf) {
7926 +                               return -ENOMEM;
7927 +                       }
7928 +                       pp = d_path(path, buf, PATH_MAX);
7929 +                       new_dentry = cow_break_link(pp);
7930 +                       kfree(buf);
7931 +                       if (!IS_ERR(new_dentry)) {
7932 +                               path->dentry = new_dentry;
7933 +                               dput(old_dentry);
7934 +                       } else
7935 +                               error = PTR_ERR(new_dentry);
7936 +               } else {
7937 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
7938 +                       inode->i_ctime = CURRENT_TIME;
7939 +                       mark_inode_dirty(inode);
7940 +               }
7941 +       }
7942 +       return error;
7943 +}
7944 +
7945 +#else
7946 +#warning duplicate inclusion
7947 +#endif
7948 diff -NurpP --minimal linux-3.13.1/include/linux/vs_cvirt.h linux-3.13.1-vs2.3.6.10/include/linux/vs_cvirt.h
7949 --- linux-3.13.1/include/linux/vs_cvirt.h       1970-01-01 00:00:00.000000000 +0000
7950 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_cvirt.h    2014-01-31 20:38:03.000000000 +0000
7951 @@ -0,0 +1,50 @@
7952 +#ifndef _VS_CVIRT_H
7953 +#define _VS_CVIRT_H
7954 +
7955 +#include "vserver/cvirt.h"
7956 +#include "vserver/context.h"
7957 +#include "vserver/base.h"
7958 +#include "vserver/check.h"
7959 +#include "vserver/debug.h"
7960 +
7961 +
7962 +static inline void vx_activate_task(struct task_struct *p)
7963 +{
7964 +       struct vx_info *vxi;
7965 +
7966 +       if ((vxi = p->vx_info)) {
7967 +               vx_update_load(vxi);
7968 +               atomic_inc(&vxi->cvirt.nr_running);
7969 +       }
7970 +}
7971 +
7972 +static inline void vx_deactivate_task(struct task_struct *p)
7973 +{
7974 +       struct vx_info *vxi;
7975 +
7976 +       if ((vxi = p->vx_info)) {
7977 +               vx_update_load(vxi);
7978 +               atomic_dec(&vxi->cvirt.nr_running);
7979 +       }
7980 +}
7981 +
7982 +static inline void vx_uninterruptible_inc(struct task_struct *p)
7983 +{
7984 +       struct vx_info *vxi;
7985 +
7986 +       if ((vxi = p->vx_info))
7987 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
7988 +}
7989 +
7990 +static inline void vx_uninterruptible_dec(struct task_struct *p)
7991 +{
7992 +       struct vx_info *vxi;
7993 +
7994 +       if ((vxi = p->vx_info))
7995 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
7996 +}
7997 +
7998 +
7999 +#else
8000 +#warning duplicate inclusion
8001 +#endif
8002 diff -NurpP --minimal linux-3.13.1/include/linux/vs_device.h linux-3.13.1-vs2.3.6.10/include/linux/vs_device.h
8003 --- linux-3.13.1/include/linux/vs_device.h      1970-01-01 00:00:00.000000000 +0000
8004 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_device.h   2014-01-31 20:38:03.000000000 +0000
8005 @@ -0,0 +1,45 @@
8006 +#ifndef _VS_DEVICE_H
8007 +#define _VS_DEVICE_H
8008 +
8009 +#include "vserver/base.h"
8010 +#include "vserver/device.h"
8011 +#include "vserver/debug.h"
8012 +
8013 +
8014 +#ifdef CONFIG_VSERVER_DEVICE
8015 +
8016 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8017 +
8018 +#define vs_device_perm(v, d, m, p) \
8019 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8020 +
8021 +#else
8022 +
8023 +static inline
8024 +int vs_map_device(struct vx_info *vxi,
8025 +       dev_t device, dev_t *target, umode_t mode)
8026 +{
8027 +       if (target)
8028 +               *target = device;
8029 +       return ~0;
8030 +}
8031 +
8032 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8033 +
8034 +#endif
8035 +
8036 +
8037 +#define vs_map_chrdev(d, t, p) \
8038 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8039 +#define vs_map_blkdev(d, t, p) \
8040 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8041 +
8042 +#define vs_chrdev_perm(d, p) \
8043 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8044 +#define vs_blkdev_perm(d, p) \
8045 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8046 +
8047 +
8048 +#else
8049 +#warning duplicate inclusion
8050 +#endif
8051 diff -NurpP --minimal linux-3.13.1/include/linux/vs_dlimit.h linux-3.13.1-vs2.3.6.10/include/linux/vs_dlimit.h
8052 --- linux-3.13.1/include/linux/vs_dlimit.h      1970-01-01 00:00:00.000000000 +0000
8053 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_dlimit.h   2014-01-31 20:38:03.000000000 +0000
8054 @@ -0,0 +1,215 @@
8055 +#ifndef _VS_DLIMIT_H
8056 +#define _VS_DLIMIT_H
8057 +
8058 +#include <linux/fs.h>
8059 +
8060 +#include "vserver/dlimit.h"
8061 +#include "vserver/base.h"
8062 +#include "vserver/debug.h"
8063 +
8064 +
8065 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8066 +
8067 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8068 +       const char *_file, int _line)
8069 +{
8070 +       if (!dli)
8071 +               return NULL;
8072 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8073 +               dli, dli ? dli->dl_tag : 0,
8074 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8075 +               _file, _line);
8076 +       atomic_inc(&dli->dl_usecnt);
8077 +       return dli;
8078 +}
8079 +
8080 +
8081 +#define free_dl_info(i) \
8082 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8083 +
8084 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8085 +
8086 +static inline void __put_dl_info(struct dl_info *dli,
8087 +       const char *_file, int _line)
8088 +{
8089 +       if (!dli)
8090 +               return;
8091 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8092 +               dli, dli ? dli->dl_tag : 0,
8093 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8094 +               _file, _line);
8095 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8096 +               free_dl_info(dli);
8097 +}
8098 +
8099 +
8100 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8101 +
8102 +static inline int __dl_alloc_space(struct super_block *sb,
8103 +       vtag_t tag, dlsize_t nr, const char *file, int line)
8104 +{
8105 +       struct dl_info *dli = NULL;
8106 +       int ret = 0;
8107 +
8108 +       if (nr == 0)
8109 +               goto out;
8110 +       dli = locate_dl_info(sb, tag);
8111 +       if (!dli)
8112 +               goto out;
8113 +
8114 +       spin_lock(&dli->dl_lock);
8115 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
8116 +       if (!ret)
8117 +               dli->dl_space_used += nr;
8118 +       spin_unlock(&dli->dl_lock);
8119 +       put_dl_info(dli);
8120 +out:
8121 +       vxlprintk(VXD_CBIT(dlim, 1),
8122 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
8123 +               sb, tag, __dlimit_char(dli), (long long)nr,
8124 +               ret, file, line);
8125 +       return ret ? -ENOSPC : 0;
8126 +}
8127 +
8128 +static inline void __dl_free_space(struct super_block *sb,
8129 +       vtag_t tag, dlsize_t nr, const char *_file, int _line)
8130 +{
8131 +       struct dl_info *dli = NULL;
8132 +
8133 +       if (nr == 0)
8134 +               goto out;
8135 +       dli = locate_dl_info(sb, tag);
8136 +       if (!dli)
8137 +               goto out;
8138 +
8139 +       spin_lock(&dli->dl_lock);
8140 +       if (dli->dl_space_used > nr)
8141 +               dli->dl_space_used -= nr;
8142 +       else
8143 +               dli->dl_space_used = 0;
8144 +       spin_unlock(&dli->dl_lock);
8145 +       put_dl_info(dli);
8146 +out:
8147 +       vxlprintk(VXD_CBIT(dlim, 1),
8148 +               "FREE  (%p,#%d)%c %lld bytes",
8149 +               sb, tag, __dlimit_char(dli), (long long)nr,
8150 +               _file, _line);
8151 +}
8152 +
8153 +static inline int __dl_alloc_inode(struct super_block *sb,
8154 +       vtag_t tag, const char *_file, int _line)
8155 +{
8156 +       struct dl_info *dli;
8157 +       int ret = 0;
8158 +
8159 +       dli = locate_dl_info(sb, tag);
8160 +       if (!dli)
8161 +               goto out;
8162 +
8163 +       spin_lock(&dli->dl_lock);
8164 +       dli->dl_inodes_used++;
8165 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8166 +       spin_unlock(&dli->dl_lock);
8167 +       put_dl_info(dli);
8168 +out:
8169 +       vxlprintk(VXD_CBIT(dlim, 0),
8170 +               "ALLOC (%p,#%d)%c inode (%d)",
8171 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
8172 +       return ret ? -ENOSPC : 0;
8173 +}
8174 +
8175 +static inline void __dl_free_inode(struct super_block *sb,
8176 +       vtag_t tag, const char *_file, int _line)
8177 +{
8178 +       struct dl_info *dli;
8179 +
8180 +       dli = locate_dl_info(sb, tag);
8181 +       if (!dli)
8182 +               goto out;
8183 +
8184 +       spin_lock(&dli->dl_lock);
8185 +       if (dli->dl_inodes_used > 1)
8186 +               dli->dl_inodes_used--;
8187 +       else
8188 +               dli->dl_inodes_used = 0;
8189 +       spin_unlock(&dli->dl_lock);
8190 +       put_dl_info(dli);
8191 +out:
8192 +       vxlprintk(VXD_CBIT(dlim, 0),
8193 +               "FREE  (%p,#%d)%c inode",
8194 +               sb, tag, __dlimit_char(dli), _file, _line);
8195 +}
8196 +
8197 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
8198 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
8199 +       const char *_file, int _line)
8200 +{
8201 +       struct dl_info *dli;
8202 +       uint64_t broot, bfree;
8203 +
8204 +       dli = locate_dl_info(sb, tag);
8205 +       if (!dli)
8206 +               return;
8207 +
8208 +       spin_lock(&dli->dl_lock);
8209 +       broot = (dli->dl_space_total -
8210 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8211 +               >> sb->s_blocksize_bits;
8212 +       bfree = (dli->dl_space_total - dli->dl_space_used)
8213 +                       >> sb->s_blocksize_bits;
8214 +       spin_unlock(&dli->dl_lock);
8215 +
8216 +       vxlprintk(VXD_CBIT(dlim, 2),
8217 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8218 +               (long long)bfree, (long long)broot,
8219 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
8220 +               _file, _line);
8221 +       if (free_blocks) {
8222 +               if (*free_blocks > bfree)
8223 +                       *free_blocks = bfree;
8224 +       }
8225 +       if (root_blocks) {
8226 +               if (*root_blocks > broot)
8227 +                       *root_blocks = broot;
8228 +       }
8229 +       put_dl_info(dli);
8230 +}
8231 +
8232 +#define dl_prealloc_space(in, bytes) \
8233 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8234 +               __FILE__, __LINE__ )
8235 +
8236 +#define dl_alloc_space(in, bytes) \
8237 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8238 +               __FILE__, __LINE__ )
8239 +
8240 +#define dl_reserve_space(in, bytes) \
8241 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8242 +               __FILE__, __LINE__ )
8243 +
8244 +#define dl_claim_space(in, bytes) (0)
8245 +
8246 +#define dl_release_space(in, bytes) \
8247 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8248 +               __FILE__, __LINE__ )
8249 +
8250 +#define dl_free_space(in, bytes) \
8251 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8252 +               __FILE__, __LINE__ )
8253 +
8254 +
8255 +
8256 +#define dl_alloc_inode(in) \
8257 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8258 +
8259 +#define dl_free_inode(in) \
8260 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8261 +
8262 +
8263 +#define dl_adjust_block(sb, tag, fb, rb) \
8264 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8265 +
8266 +
8267 +#else
8268 +#warning duplicate inclusion
8269 +#endif
8270 diff -NurpP --minimal linux-3.13.1/include/linux/vs_inet.h linux-3.13.1-vs2.3.6.10/include/linux/vs_inet.h
8271 --- linux-3.13.1/include/linux/vs_inet.h        1970-01-01 00:00:00.000000000 +0000
8272 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_inet.h     2014-02-01 00:32:45.000000000 +0000
8273 @@ -0,0 +1,364 @@
8274 +#ifndef _VS_INET_H
8275 +#define _VS_INET_H
8276 +
8277 +#include "vserver/base.h"
8278 +#include "vserver/network.h"
8279 +#include "vserver/debug.h"
8280 +
8281 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
8282 +
8283 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
8284 +                       NIPQUAD((a)->mask), (a)->type
8285 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
8286 +
8287 +#define NIPQUAD(addr) \
8288 +       ((unsigned char *)&addr)[0], \
8289 +       ((unsigned char *)&addr)[1], \
8290 +       ((unsigned char *)&addr)[2], \
8291 +       ((unsigned char *)&addr)[3]
8292 +
8293 +#define NIPQUAD_FMT "%u.%u.%u.%u"
8294 +
8295 +
8296 +static inline
8297 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
8298 +{
8299 +       __be32 ip = nxa->ip[0].s_addr;
8300 +       __be32 mask = nxa->mask.s_addr;
8301 +       __be32 bcast = ip | ~mask;
8302 +       int ret = 0;
8303 +
8304 +       switch (nxa->type & tmask) {
8305 +       case NXA_TYPE_MASK:
8306 +               ret = (ip == (addr & mask));
8307 +               break;
8308 +       case NXA_TYPE_ADDR:
8309 +               ret = 3;
8310 +               if (addr == ip)
8311 +                       break;
8312 +               /* fall through to broadcast */
8313 +       case NXA_MOD_BCAST:
8314 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
8315 +               break;
8316 +       case NXA_TYPE_RANGE:
8317 +               ret = ((nxa->ip[0].s_addr <= addr) &&
8318 +                       (nxa->ip[1].s_addr > addr));
8319 +               break;
8320 +       case NXA_TYPE_ANY:
8321 +               ret = 2;
8322 +               break;
8323 +       }
8324 +
8325 +       vxdprintk(VXD_CBIT(net, 0),
8326 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
8327 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
8328 +       return ret;
8329 +}
8330 +
8331 +static inline
8332 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
8333 +{
8334 +       struct nx_addr_v4 *nxa;
8335 +       unsigned long irqflags;
8336 +       int ret = 1;
8337 +
8338 +       if (!nxi)
8339 +               goto out;
8340 +
8341 +       ret = 2;
8342 +       /* allow 127.0.0.1 when remapping lback */
8343 +       if ((tmask & NXA_LOOPBACK) &&
8344 +               (addr == IPI_LOOPBACK) &&
8345 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8346 +               goto out;
8347 +       ret = 3;
8348 +       /* check for lback address */
8349 +       if ((tmask & NXA_MOD_LBACK) &&
8350 +               (nxi->v4_lback.s_addr == addr))
8351 +               goto out;
8352 +       ret = 4;
8353 +       /* check for broadcast address */
8354 +       if ((tmask & NXA_MOD_BCAST) &&
8355 +               (nxi->v4_bcast.s_addr == addr))
8356 +               goto out;
8357 +       ret = 5;
8358 +
8359 +       /* check for v4 addresses */
8360 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8361 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
8362 +               if (v4_addr_match(nxa, addr, tmask))
8363 +                       goto out_unlock;
8364 +       ret = 0;
8365 +out_unlock:
8366 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8367 +out:
8368 +       vxdprintk(VXD_CBIT(net, 0),
8369 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
8370 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
8371 +       return ret;
8372 +}
8373 +
8374 +static inline
8375 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
8376 +{
8377 +       /* FIXME: needs full range checks */
8378 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
8379 +}
8380 +
8381 +static inline
8382 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
8383 +{
8384 +       struct nx_addr_v4 *ptr;
8385 +       unsigned long irqflags;
8386 +       int ret = 1;
8387 +
8388 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8389 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
8390 +               if (v4_nx_addr_match(ptr, nxa, mask))
8391 +                       goto out_unlock;
8392 +       ret = 0;
8393 +out_unlock:
8394 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8395 +       return ret;
8396 +}
8397 +
8398 +#include <net/inet_sock.h>
8399 +
8400 +/*
8401 + *     Check if a given address matches for a socket
8402 + *
8403 + *     nxi:            the socket's nx_info if any
8404 + *     addr:           to be verified address
8405 + */
8406 +static inline
8407 +int v4_sock_addr_match (
8408 +       struct nx_info *nxi,
8409 +       struct inet_sock *inet,
8410 +       __be32 addr)
8411 +{
8412 +       __be32 saddr = inet->inet_rcv_saddr;
8413 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
8414 +
8415 +       if (addr && (saddr == addr || bcast == addr))
8416 +               return 1;
8417 +       if (!saddr)
8418 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
8419 +       return 0;
8420 +}
8421 +
8422 +
8423 +/* inet related checks and helpers */
8424 +
8425 +
8426 +struct in_ifaddr;
8427 +struct net_device;
8428 +struct sock;
8429 +
8430 +#ifdef CONFIG_INET
8431 +
8432 +#include <linux/netdevice.h>
8433 +#include <linux/inetdevice.h>
8434 +#include <net/inet_sock.h>
8435 +#include <net/inet_timewait_sock.h>
8436 +
8437 +
8438 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8439 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
8440 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
8441 +
8442 +
8443 +/*
8444 + *     check if address is covered by socket
8445 + *
8446 + *     sk:     the socket to check against
8447 + *     addr:   the address in question (must be != 0)
8448 + */
8449 +
8450 +static inline
8451 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
8452 +{
8453 +       struct nx_info *nxi = sk->sk_nx_info;
8454 +       __be32 saddr = sk->sk_rcv_saddr;
8455 +
8456 +       vxdprintk(VXD_CBIT(net, 5),
8457 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
8458 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
8459 +               (sk->sk_socket?sk->sk_socket->flags:0));
8460 +
8461 +       if (saddr) {            /* direct address match */
8462 +               return v4_addr_match(nxa, saddr, -1);
8463 +       } else if (nxi) {       /* match against nx_info */
8464 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
8465 +       } else {                /* unrestricted any socket */
8466 +               return 1;
8467 +       }
8468 +}
8469 +
8470 +
8471 +
8472 +static inline
8473 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
8474 +{
8475 +       vxdprintk(VXD_CBIT(net, 1),
8476 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
8477 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
8478 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
8479 +
8480 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8481 +               return 1;
8482 +       if (dev_in_nx_info(dev, nxi))
8483 +               return 1;
8484 +       return 0;
8485 +}
8486 +
8487 +
8488 +static inline
8489 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
8490 +{
8491 +       if (!nxi)
8492 +               return 1;
8493 +       if (!ifa)
8494 +               return 0;
8495 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
8496 +}
8497 +
8498 +static inline
8499 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
8500 +{
8501 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
8502 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8503 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
8504 +
8505 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8506 +               return 1;
8507 +       if (v4_ifa_in_nx_info(ifa, nxi))
8508 +               return 1;
8509 +       return 0;
8510 +}
8511 +
8512 +
8513 +struct nx_v4_sock_addr {
8514 +       __be32 saddr;   /* Address used for validation */
8515 +       __be32 baddr;   /* Address used for socket bind */
8516 +};
8517 +
8518 +static inline
8519 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
8520 +       struct nx_v4_sock_addr *nsa)
8521 +{
8522 +       struct sock *sk = &inet->sk;
8523 +       struct nx_info *nxi = sk->sk_nx_info;
8524 +       __be32 saddr = addr->sin_addr.s_addr;
8525 +       __be32 baddr = saddr;
8526 +
8527 +       vxdprintk(VXD_CBIT(net, 3),
8528 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
8529 +               sk, sk->sk_nx_info, sk->sk_socket,
8530 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
8531 +               NIPQUAD(saddr));
8532 +
8533 +       if (nxi) {
8534 +               if (saddr == INADDR_ANY) {
8535 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
8536 +                               baddr = nxi->v4.ip[0].s_addr;
8537 +               } else if (saddr == IPI_LOOPBACK) {
8538 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8539 +                               baddr = nxi->v4_lback.s_addr;
8540 +               } else if (!ipv4_is_multicast(saddr) ||
8541 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
8542 +                       /* normal address bind */
8543 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
8544 +                               return -EADDRNOTAVAIL;
8545 +               }
8546 +       }
8547 +
8548 +       vxdprintk(VXD_CBIT(net, 3),
8549 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
8550 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
8551 +
8552 +       nsa->saddr = saddr;
8553 +       nsa->baddr = baddr;
8554 +       return 0;
8555 +}
8556 +
8557 +static inline
8558 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
8559 +{
8560 +       inet->inet_saddr = nsa->baddr;
8561 +       inet->inet_rcv_saddr = nsa->baddr;
8562 +}
8563 +
8564 +
8565 +/*
8566 + *      helper to simplify inet_lookup_listener
8567 + *
8568 + *      nxi:   the socket's nx_info if any
8569 + *      addr:  to be verified address
8570 + *      saddr: socket address
8571 + */
8572 +static inline int v4_inet_addr_match (
8573 +       struct nx_info *nxi,
8574 +       __be32 addr,
8575 +       __be32 saddr)
8576 +{
8577 +       if (addr && (saddr == addr))
8578 +               return 1;
8579 +       if (!saddr)
8580 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
8581 +       return 0;
8582 +}
8583 +
8584 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
8585 +{
8586 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
8587 +               (addr == nxi->v4_lback.s_addr))
8588 +               return IPI_LOOPBACK;
8589 +       return addr;
8590 +}
8591 +
8592 +static inline
8593 +int nx_info_has_v4(struct nx_info *nxi)
8594 +{
8595 +       if (!nxi)
8596 +               return 1;
8597 +       if (NX_IPV4(nxi))
8598 +               return 1;
8599 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8600 +               return 1;
8601 +       return 0;
8602 +}
8603 +
8604 +#else /* CONFIG_INET */
8605 +
8606 +static inline
8607 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
8608 +{
8609 +       return 1;
8610 +}
8611 +
8612 +static inline
8613 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8614 +{
8615 +       return 1;
8616 +}
8617 +
8618 +static inline
8619 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8620 +{
8621 +       return 1;
8622 +}
8623 +
8624 +static inline
8625 +int nx_info_has_v4(struct nx_info *nxi)
8626 +{
8627 +       return 0;
8628 +}
8629 +
8630 +#endif /* CONFIG_INET */
8631 +
8632 +#define current_nx_info_has_v4() \
8633 +       nx_info_has_v4(current_nx_info())
8634 +
8635 +#else
8636 +// #warning duplicate inclusion
8637 +#endif
8638 diff -NurpP --minimal linux-3.13.1/include/linux/vs_inet6.h linux-3.13.1-vs2.3.6.10/include/linux/vs_inet6.h
8639 --- linux-3.13.1/include/linux/vs_inet6.h       1970-01-01 00:00:00.000000000 +0000
8640 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_inet6.h    2014-02-01 00:35:02.000000000 +0000
8641 @@ -0,0 +1,257 @@
8642 +#ifndef _VS_INET6_H
8643 +#define _VS_INET6_H
8644 +
8645 +#include "vserver/base.h"
8646 +#include "vserver/network.h"
8647 +#include "vserver/debug.h"
8648 +
8649 +#include <net/ipv6.h>
8650 +
8651 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
8652 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
8653 +
8654 +
8655 +#ifdef CONFIG_IPV6
8656 +
8657 +static inline
8658 +int v6_addr_match(struct nx_addr_v6 *nxa,
8659 +       const struct in6_addr *addr, uint16_t mask)
8660 +{
8661 +       int ret = 0;
8662 +
8663 +       switch (nxa->type & mask) {
8664 +       case NXA_TYPE_MASK:
8665 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
8666 +               break;
8667 +       case NXA_TYPE_ADDR:
8668 +               ret = ipv6_addr_equal(&nxa->ip, addr);
8669 +               break;
8670 +       case NXA_TYPE_ANY:
8671 +               ret = 1;
8672 +               break;
8673 +       }
8674 +       vxdprintk(VXD_CBIT(net, 0),
8675 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
8676 +               nxa, NXAV6(nxa), addr, mask, ret);
8677 +       return ret;
8678 +}
8679 +
8680 +static inline
8681 +int v6_addr_in_nx_info(struct nx_info *nxi,
8682 +       const struct in6_addr *addr, uint16_t mask)
8683 +{
8684 +       struct nx_addr_v6 *nxa;
8685 +       unsigned long irqflags;
8686 +       int ret = 1;
8687 +
8688 +       if (!nxi)
8689 +               goto out;
8690 +
8691 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8692 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
8693 +               if (v6_addr_match(nxa, addr, mask))
8694 +                       goto out_unlock;
8695 +       ret = 0;
8696 +out_unlock:
8697 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8698 +out:
8699 +       vxdprintk(VXD_CBIT(net, 0),
8700 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
8701 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
8702 +       return ret;
8703 +}
8704 +
8705 +static inline
8706 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
8707 +{
8708 +       /* FIXME: needs full range checks */
8709 +       return v6_addr_match(nxa, &addr->ip, mask);
8710 +}
8711 +
8712 +static inline
8713 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
8714 +{
8715 +       struct nx_addr_v6 *ptr;
8716 +       unsigned long irqflags;
8717 +       int ret = 1;
8718 +
8719 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8720 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
8721 +               if (v6_nx_addr_match(ptr, nxa, mask))
8722 +                       goto out_unlock;
8723 +       ret = 0;
8724 +out_unlock:
8725 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8726 +       return ret;
8727 +}
8728 +
8729 +
8730 +/*
8731 + *     Check if a given address matches for a socket
8732 + *
8733 + *     nxi:            the socket's nx_info if any
8734 + *     addr:           to be verified address
8735 + */
8736 +static inline
8737 +int v6_sock_addr_match (
8738 +       struct nx_info *nxi,
8739 +       struct inet_sock *inet,
8740 +       struct in6_addr *addr)
8741 +{
8742 +       struct sock *sk = &inet->sk;
8743 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8744 +
8745 +       if (!ipv6_addr_any(addr) &&
8746 +               ipv6_addr_equal(saddr, addr))
8747 +               return 1;
8748 +       if (ipv6_addr_any(saddr))
8749 +               return v6_addr_in_nx_info(nxi, addr, -1);
8750 +       return 0;
8751 +}
8752 +
8753 +/*
8754 + *     check if address is covered by socket
8755 + *
8756 + *     sk:     the socket to check against
8757 + *     addr:   the address in question (must be != 0)
8758 + */
8759 +
8760 +static inline
8761 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
8762 +{
8763 +       struct nx_info *nxi = sk->sk_nx_info;
8764 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8765 +
8766 +       vxdprintk(VXD_CBIT(net, 5),
8767 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
8768 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
8769 +               (sk->sk_socket?sk->sk_socket->flags:0));
8770 +
8771 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
8772 +               return v6_addr_match(nxa, saddr, -1);
8773 +       } else if (nxi) {               /* match against nx_info */
8774 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
8775 +       } else {                        /* unrestricted any socket */
8776 +               return 1;
8777 +       }
8778 +}
8779 +
8780 +
8781 +/* inet related checks and helpers */
8782 +
8783 +
8784 +struct in_ifaddr;
8785 +struct net_device;
8786 +struct sock;
8787 +
8788 +
8789 +#include <linux/netdevice.h>
8790 +#include <linux/inetdevice.h>
8791 +#include <net/inet_timewait_sock.h>
8792 +
8793 +
8794 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8795 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
8796 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
8797 +
8798 +
8799 +
8800 +static inline
8801 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
8802 +{
8803 +       if (!nxi)
8804 +               return 1;
8805 +       if (!ifa)
8806 +               return 0;
8807 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
8808 +}
8809 +
8810 +static inline
8811 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
8812 +{
8813 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
8814 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8815 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
8816 +
8817 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8818 +               return 1;
8819 +       if (v6_ifa_in_nx_info(ifa, nxi))
8820 +               return 1;
8821 +       return 0;
8822 +}
8823 +
8824 +
8825 +struct nx_v6_sock_addr {
8826 +       struct in6_addr saddr;  /* Address used for validation */
8827 +       struct in6_addr baddr;  /* Address used for socket bind */
8828 +};
8829 +
8830 +static inline
8831 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
8832 +       struct nx_v6_sock_addr *nsa)
8833 +{
8834 +       // struct sock *sk = &inet->sk;
8835 +       // struct nx_info *nxi = sk->sk_nx_info;
8836 +       struct in6_addr saddr = addr->sin6_addr;
8837 +       struct in6_addr baddr = saddr;
8838 +
8839 +       nsa->saddr = saddr;
8840 +       nsa->baddr = baddr;
8841 +       return 0;
8842 +}
8843 +
8844 +static inline
8845 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
8846 +{
8847 +       // struct sock *sk = &inet->sk;
8848 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
8849 +
8850 +       // *saddr = nsa->baddr;
8851 +       // inet->inet_saddr = nsa->baddr;
8852 +}
8853 +
8854 +static inline
8855 +int nx_info_has_v6(struct nx_info *nxi)
8856 +{
8857 +       if (!nxi)
8858 +               return 1;
8859 +       if (NX_IPV6(nxi))
8860 +               return 1;
8861 +       return 0;
8862 +}
8863 +
8864 +#else /* CONFIG_IPV6 */
8865 +
8866 +static inline
8867 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
8868 +{
8869 +       return 1;
8870 +}
8871 +
8872 +
8873 +static inline
8874 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8875 +{
8876 +       return 1;
8877 +}
8878 +
8879 +static inline
8880 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8881 +{
8882 +       return 1;
8883 +}
8884 +
8885 +static inline
8886 +int nx_info_has_v6(struct nx_info *nxi)
8887 +{
8888 +       return 0;
8889 +}
8890 +
8891 +#endif /* CONFIG_IPV6 */
8892 +
8893 +#define current_nx_info_has_v6() \
8894 +       nx_info_has_v6(current_nx_info())
8895 +
8896 +#else
8897 +#warning duplicate inclusion
8898 +#endif
8899 diff -NurpP --minimal linux-3.13.1/include/linux/vs_limit.h linux-3.13.1-vs2.3.6.10/include/linux/vs_limit.h
8900 --- linux-3.13.1/include/linux/vs_limit.h       1970-01-01 00:00:00.000000000 +0000
8901 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_limit.h    2014-02-01 01:29:43.000000000 +0000
8902 @@ -0,0 +1,140 @@
8903 +#ifndef _VS_LIMIT_H
8904 +#define _VS_LIMIT_H
8905 +
8906 +#include "vserver/limit.h"
8907 +#include "vserver/base.h"
8908 +#include "vserver/context.h"
8909 +#include "vserver/debug.h"
8910 +#include "vserver/context.h"
8911 +#include "vserver/limit_int.h"
8912 +
8913 +
8914 +#define vx_acc_cres(v, d, p, r) \
8915 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
8916 +
8917 +#define vx_acc_cres_cond(x, d, p, r) \
8918 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8919 +       r, d, p, __FILE__, __LINE__)
8920 +
8921 +
8922 +#define vx_add_cres(v, a, p, r) \
8923 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
8924 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
8925 +
8926 +#define vx_add_cres_cond(x, a, p, r) \
8927 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8928 +       r, a, p, __FILE__, __LINE__)
8929 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
8930 +
8931 +
8932 +/* process and file limits */
8933 +
8934 +#define vx_nproc_inc(p) \
8935 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
8936 +
8937 +#define vx_nproc_dec(p) \
8938 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
8939 +
8940 +#define vx_files_inc(f) \
8941 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
8942 +
8943 +#define vx_files_dec(f) \
8944 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
8945 +
8946 +#define vx_locks_inc(l) \
8947 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
8948 +
8949 +#define vx_locks_dec(l) \
8950 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
8951 +
8952 +#define vx_openfd_inc(f) \
8953 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
8954 +
8955 +#define vx_openfd_dec(f) \
8956 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
8957 +
8958 +
8959 +#define vx_cres_avail(v, n, r) \
8960 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
8961 +
8962 +
8963 +#define vx_nproc_avail(n) \
8964 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
8965 +
8966 +#define vx_files_avail(n) \
8967 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
8968 +
8969 +#define vx_locks_avail(n) \
8970 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
8971 +
8972 +#define vx_openfd_avail(n) \
8973 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
8974 +
8975 +
8976 +/* dentry limits */
8977 +
8978 +#define vx_dentry_inc(d) do {                                          \
8979 +       if (d_count(d) == 1)                                            \
8980 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
8981 +       } while (0)
8982 +
8983 +#define vx_dentry_dec(d) do {                                          \
8984 +       if (d_count(d) == 0)                                            \
8985 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
8986 +       } while (0)
8987 +
8988 +#define vx_dentry_avail(n) \
8989 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
8990 +
8991 +
8992 +/* socket limits */
8993 +
8994 +#define vx_sock_inc(s) \
8995 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
8996 +
8997 +#define vx_sock_dec(s) \
8998 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
8999 +
9000 +#define vx_sock_avail(n) \
9001 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9002 +
9003 +
9004 +/* ipc resource limits */
9005 +
9006 +#define vx_ipcmsg_add(v, u, a) \
9007 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9008 +
9009 +#define vx_ipcmsg_sub(v, u, a) \
9010 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9011 +
9012 +#define vx_ipcmsg_avail(v, a) \
9013 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9014 +
9015 +
9016 +#define vx_ipcshm_add(v, k, a) \
9017 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9018 +
9019 +#define vx_ipcshm_sub(v, k, a) \
9020 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9021 +
9022 +#define vx_ipcshm_avail(v, a) \
9023 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
9024 +
9025 +
9026 +#define vx_semary_inc(a) \
9027 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9028 +
9029 +#define vx_semary_dec(a) \
9030 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9031 +
9032 +
9033 +#define vx_nsems_add(a,n) \
9034 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9035 +
9036 +#define vx_nsems_sub(a,n) \
9037 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9038 +
9039 +
9040 +#else
9041 +#warning duplicate inclusion
9042 +#endif
9043 diff -NurpP --minimal linux-3.13.1/include/linux/vs_network.h linux-3.13.1-vs2.3.6.10/include/linux/vs_network.h
9044 --- linux-3.13.1/include/linux/vs_network.h     1970-01-01 00:00:00.000000000 +0000
9045 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_network.h  2014-01-31 20:38:03.000000000 +0000
9046 @@ -0,0 +1,169 @@
9047 +#ifndef _NX_VS_NETWORK_H
9048 +#define _NX_VS_NETWORK_H
9049 +
9050 +#include "vserver/context.h"
9051 +#include "vserver/network.h"
9052 +#include "vserver/base.h"
9053 +#include "vserver/check.h"
9054 +#include "vserver/debug.h"
9055 +
9056 +#include <linux/sched.h>
9057 +
9058 +
9059 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9060 +
9061 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9062 +       const char *_file, int _line)
9063 +{
9064 +       if (!nxi)
9065 +               return NULL;
9066 +
9067 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9068 +               nxi, nxi ? nxi->nx_id : 0,
9069 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9070 +               _file, _line);
9071 +
9072 +       atomic_inc(&nxi->nx_usecnt);
9073 +       return nxi;
9074 +}
9075 +
9076 +
9077 +extern void free_nx_info(struct nx_info *);
9078 +
9079 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9080 +
9081 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9082 +{
9083 +       if (!nxi)
9084 +               return;
9085 +
9086 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9087 +               nxi, nxi ? nxi->nx_id : 0,
9088 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9089 +               _file, _line);
9090 +
9091 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9092 +               free_nx_info(nxi);
9093 +}
9094 +
9095 +
9096 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9097 +
9098 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9099 +               const char *_file, int _line)
9100 +{
9101 +       if (nxi) {
9102 +               vxlprintk(VXD_CBIT(nid, 3),
9103 +                       "init_nx_info(%p[#%d.%d])",
9104 +                       nxi, nxi ? nxi->nx_id : 0,
9105 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9106 +                       _file, _line);
9107 +
9108 +               atomic_inc(&nxi->nx_usecnt);
9109 +       }
9110 +       *nxp = nxi;
9111 +}
9112 +
9113 +
9114 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9115 +
9116 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9117 +       const char *_file, int _line)
9118 +{
9119 +       struct nx_info *nxo;
9120 +
9121 +       if (!nxi)
9122 +               return;
9123 +
9124 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9125 +               nxi, nxi ? nxi->nx_id : 0,
9126 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9127 +               _file, _line);
9128 +
9129 +       atomic_inc(&nxi->nx_usecnt);
9130 +       nxo = xchg(nxp, nxi);
9131 +       BUG_ON(nxo);
9132 +}
9133 +
9134 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9135 +
9136 +static inline void __clr_nx_info(struct nx_info **nxp,
9137 +       const char *_file, int _line)
9138 +{
9139 +       struct nx_info *nxo;
9140 +
9141 +       nxo = xchg(nxp, NULL);
9142 +       if (!nxo)
9143 +               return;
9144 +
9145 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9146 +               nxo, nxo ? nxo->nx_id : 0,
9147 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9148 +               _file, _line);
9149 +
9150 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
9151 +               free_nx_info(nxo);
9152 +}
9153 +
9154 +
9155 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9156 +
9157 +static inline void __claim_nx_info(struct nx_info *nxi,
9158 +       struct task_struct *task, const char *_file, int _line)
9159 +{
9160 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9161 +               nxi, nxi ? nxi->nx_id : 0,
9162 +               nxi?atomic_read(&nxi->nx_usecnt):0,
9163 +               nxi?atomic_read(&nxi->nx_tasks):0,
9164 +               task, _file, _line);
9165 +
9166 +       atomic_inc(&nxi->nx_tasks);
9167 +}
9168 +
9169 +
9170 +extern void unhash_nx_info(struct nx_info *);
9171 +
9172 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9173 +
9174 +static inline void __release_nx_info(struct nx_info *nxi,
9175 +       struct task_struct *task, const char *_file, int _line)
9176 +{
9177 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9178 +               nxi, nxi ? nxi->nx_id : 0,
9179 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9180 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
9181 +               task, _file, _line);
9182 +
9183 +       might_sleep();
9184 +
9185 +       if (atomic_dec_and_test(&nxi->nx_tasks))
9186 +               unhash_nx_info(nxi);
9187 +}
9188 +
9189 +
9190 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
9191 +
9192 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9193 +       const char *_file, int _line)
9194 +{
9195 +       struct nx_info *nxi;
9196 +
9197 +       task_lock(p);
9198 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9199 +               p, _file, _line);
9200 +       nxi = __get_nx_info(p->nx_info, _file, _line);
9201 +       task_unlock(p);
9202 +       return nxi;
9203 +}
9204 +
9205 +
9206 +static inline void exit_nx_info(struct task_struct *p)
9207 +{
9208 +       if (p->nx_info)
9209 +               release_nx_info(p->nx_info, p);
9210 +}
9211 +
9212 +
9213 +#else
9214 +#warning duplicate inclusion
9215 +#endif
9216 diff -NurpP --minimal linux-3.13.1/include/linux/vs_pid.h linux-3.13.1-vs2.3.6.10/include/linux/vs_pid.h
9217 --- linux-3.13.1/include/linux/vs_pid.h 1970-01-01 00:00:00.000000000 +0000
9218 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_pid.h      2014-01-31 20:38:03.000000000 +0000
9219 @@ -0,0 +1,50 @@
9220 +#ifndef _VS_PID_H
9221 +#define _VS_PID_H
9222 +
9223 +#include "vserver/base.h"
9224 +#include "vserver/check.h"
9225 +#include "vserver/context.h"
9226 +#include "vserver/debug.h"
9227 +#include "vserver/pid.h"
9228 +#include <linux/pid_namespace.h>
9229 +
9230 +
9231 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
9232 +
9233 +static inline
9234 +int vx_proc_task_visible(struct task_struct *task)
9235 +{
9236 +       if ((task->pid == 1) &&
9237 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9238 +               /* show a blend through init */
9239 +               goto visible;
9240 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9241 +               goto visible;
9242 +       return 0;
9243 +visible:
9244 +       return 1;
9245 +}
9246 +
9247 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9248 +
9249 +
9250 +static inline
9251 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9252 +{
9253 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9254 +
9255 +       if (task && !vx_proc_task_visible(task)) {
9256 +               vxdprintk(VXD_CBIT(misc, 6),
9257 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9258 +                       task, task->xid, task->pid,
9259 +                       current, current->xid, current->pid);
9260 +               put_task_struct(task);
9261 +               task = NULL;
9262 +       }
9263 +       return task;
9264 +}
9265 +
9266 +
9267 +#else
9268 +#warning duplicate inclusion
9269 +#endif
9270 diff -NurpP --minimal linux-3.13.1/include/linux/vs_sched.h linux-3.13.1-vs2.3.6.10/include/linux/vs_sched.h
9271 --- linux-3.13.1/include/linux/vs_sched.h       1970-01-01 00:00:00.000000000 +0000
9272 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_sched.h    2014-01-31 20:38:03.000000000 +0000
9273 @@ -0,0 +1,40 @@
9274 +#ifndef _VS_SCHED_H
9275 +#define _VS_SCHED_H
9276 +
9277 +#include "vserver/base.h"
9278 +#include "vserver/context.h"
9279 +#include "vserver/sched.h"
9280 +
9281 +
9282 +#define MAX_PRIO_BIAS           20
9283 +#define MIN_PRIO_BIAS          -20
9284 +
9285 +static inline
9286 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
9287 +{
9288 +       struct vx_info *vxi = p->vx_info;
9289 +
9290 +       if (vxi)
9291 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
9292 +       return prio;
9293 +}
9294 +
9295 +static inline void vx_account_user(struct vx_info *vxi,
9296 +       cputime_t cputime, int nice)
9297 +{
9298 +       if (!vxi)
9299 +               return;
9300 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
9301 +}
9302 +
9303 +static inline void vx_account_system(struct vx_info *vxi,
9304 +       cputime_t cputime, int idle)
9305 +{
9306 +       if (!vxi)
9307 +               return;
9308 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
9309 +}
9310 +
9311 +#else
9312 +#warning duplicate inclusion
9313 +#endif
9314 diff -NurpP --minimal linux-3.13.1/include/linux/vs_socket.h linux-3.13.1-vs2.3.6.10/include/linux/vs_socket.h
9315 --- linux-3.13.1/include/linux/vs_socket.h      1970-01-01 00:00:00.000000000 +0000
9316 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_socket.h   2014-01-31 20:38:03.000000000 +0000
9317 @@ -0,0 +1,67 @@
9318 +#ifndef _VS_SOCKET_H
9319 +#define _VS_SOCKET_H
9320 +
9321 +#include "vserver/debug.h"
9322 +#include "vserver/base.h"
9323 +#include "vserver/cacct.h"
9324 +#include "vserver/context.h"
9325 +#include "vserver/tag.h"
9326 +
9327 +
9328 +/* socket accounting */
9329 +
9330 +#include <linux/socket.h>
9331 +
9332 +static inline int vx_sock_type(int family)
9333 +{
9334 +       switch (family) {
9335 +       case PF_UNSPEC:
9336 +               return VXA_SOCK_UNSPEC;
9337 +       case PF_UNIX:
9338 +               return VXA_SOCK_UNIX;
9339 +       case PF_INET:
9340 +               return VXA_SOCK_INET;
9341 +       case PF_INET6:
9342 +               return VXA_SOCK_INET6;
9343 +       case PF_PACKET:
9344 +               return VXA_SOCK_PACKET;
9345 +       default:
9346 +               return VXA_SOCK_OTHER;
9347 +       }
9348 +}
9349 +
9350 +#define vx_acc_sock(v, f, p, s) \
9351 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
9352 +
9353 +static inline void __vx_acc_sock(struct vx_info *vxi,
9354 +       int family, int pos, int size, char *file, int line)
9355 +{
9356 +       if (vxi) {
9357 +               int type = vx_sock_type(family);
9358 +
9359 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
9360 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
9361 +       }
9362 +}
9363 +
9364 +#define vx_sock_recv(sk, s) \
9365 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
9366 +#define vx_sock_send(sk, s) \
9367 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
9368 +#define vx_sock_fail(sk, s) \
9369 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
9370 +
9371 +
9372 +#define sock_vx_init(s) do {           \
9373 +       (s)->sk_xid = 0;                \
9374 +       (s)->sk_vx_info = NULL;         \
9375 +       } while (0)
9376 +
9377 +#define sock_nx_init(s) do {           \
9378 +       (s)->sk_nid = 0;                \
9379 +       (s)->sk_nx_info = NULL;         \
9380 +       } while (0)
9381 +
9382 +#else
9383 +#warning duplicate inclusion
9384 +#endif
9385 diff -NurpP --minimal linux-3.13.1/include/linux/vs_tag.h linux-3.13.1-vs2.3.6.10/include/linux/vs_tag.h
9386 --- linux-3.13.1/include/linux/vs_tag.h 1970-01-01 00:00:00.000000000 +0000
9387 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_tag.h      2014-01-31 20:38:03.000000000 +0000
9388 @@ -0,0 +1,47 @@
9389 +#ifndef _VS_TAG_H
9390 +#define _VS_TAG_H
9391 +
9392 +#include <linux/vserver/tag.h>
9393 +
9394 +/* check conditions */
9395 +
9396 +#define DX_ADMIN       0x0001
9397 +#define DX_WATCH       0x0002
9398 +#define DX_HOSTID      0x0008
9399 +
9400 +#define DX_IDENT       0x0010
9401 +
9402 +#define DX_ARG_MASK    0x0010
9403 +
9404 +
9405 +#define dx_task_tag(t) ((t)->tag)
9406 +
9407 +#define dx_current_tag() dx_task_tag(current)
9408 +
9409 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
9410 +
9411 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
9412 +
9413 +
9414 +/*
9415 + * check current context for ADMIN/WATCH and
9416 + * optionally against supplied argument
9417 + */
9418 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
9419 +{
9420 +       if (mode & DX_ARG_MASK) {
9421 +               if ((mode & DX_IDENT) && (id == cid))
9422 +                       return 1;
9423 +       }
9424 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
9425 +               ((mode & DX_WATCH) && (cid == 1)) ||
9426 +               ((mode & DX_HOSTID) && (id == 0)));
9427 +}
9428 +
9429 +struct inode;
9430 +int dx_permission(const struct inode *inode, int mask);
9431 +
9432 +
9433 +#else
9434 +#warning duplicate inclusion
9435 +#endif
9436 diff -NurpP --minimal linux-3.13.1/include/linux/vs_time.h linux-3.13.1-vs2.3.6.10/include/linux/vs_time.h
9437 --- linux-3.13.1/include/linux/vs_time.h        1970-01-01 00:00:00.000000000 +0000
9438 +++ linux-3.13.1-vs2.3.6.10/include/linux/vs_time.h     2014-01-31 20:38:03.000000000 +0000
9439 @@ -0,0 +1,19 @@
9440 +#ifndef _VS_TIME_H
9441 +#define _VS_TIME_H
9442 +
9443 +
9444 +/* time faking stuff */
9445 +
9446 +#ifdef CONFIG_VSERVER_VTIME
9447 +
9448 +extern void vx_adjust_timespec(struct timespec *ts);
9449 +extern int vx_settimeofday(const struct timespec *ts);
9450 +
9451 +#else
9452 +#define        vx_adjust_timespec(t)   do { } while (0)
9453 +#define        vx_settimeofday(t)      do_settimeofday(t)
9454 +#endif
9455 +
9456 +#else
9457 +#warning duplicate inclusion
9458 +#endif
9459 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/base.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/base.h
9460 --- linux-3.13.1/include/linux/vserver/base.h   1970-01-01 00:00:00.000000000 +0000
9461 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/base.h        2014-01-31 20:38:03.000000000 +0000
9462 @@ -0,0 +1,184 @@
9463 +#ifndef _VSERVER_BASE_H
9464 +#define _VSERVER_BASE_H
9465 +
9466 +
9467 +/* context state changes */
9468 +
9469 +enum {
9470 +       VSC_STARTUP = 1,
9471 +       VSC_SHUTDOWN,
9472 +
9473 +       VSC_NETUP,
9474 +       VSC_NETDOWN,
9475 +};
9476 +
9477 +
9478 +
9479 +#define vx_task_xid(t) ((t)->xid)
9480 +
9481 +#define vx_current_xid() vx_task_xid(current)
9482 +
9483 +#define current_vx_info() (current->vx_info)
9484 +
9485 +
9486 +#define nx_task_nid(t) ((t)->nid)
9487 +
9488 +#define nx_current_nid() nx_task_nid(current)
9489 +
9490 +#define current_nx_info() (current->nx_info)
9491 +
9492 +
9493 +/* generic flag merging */
9494 +
9495 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
9496 +
9497 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
9498 +
9499 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
9500 +
9501 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
9502 +
9503 +
9504 +/* context flags */
9505 +
9506 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
9507 +
9508 +#define vx_current_flags()     __vx_flags(current_vx_info())
9509 +
9510 +#define vx_info_flags(v, m, f) \
9511 +       vs_check_flags(__vx_flags(v), m, f)
9512 +
9513 +#define task_vx_flags(t, m, f) \
9514 +       ((t) && vx_info_flags((t)->vx_info, m, f))
9515 +
9516 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
9517 +
9518 +
9519 +/* context caps */
9520 +
9521 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
9522 +
9523 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
9524 +
9525 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
9526 +
9527 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
9528 +
9529 +
9530 +
9531 +/* network flags */
9532 +
9533 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
9534 +
9535 +#define nx_current_flags()     __nx_flags(current_nx_info())
9536 +
9537 +#define nx_info_flags(n, m, f) \
9538 +       vs_check_flags(__nx_flags(n), m, f)
9539 +
9540 +#define task_nx_flags(t, m, f) \
9541 +       ((t) && nx_info_flags((t)->nx_info, m, f))
9542 +
9543 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
9544 +
9545 +
9546 +/* network caps */
9547 +
9548 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
9549 +
9550 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
9551 +
9552 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
9553 +
9554 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
9555 +
9556 +
9557 +/* context mask capabilities */
9558 +
9559 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
9560 +
9561 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
9562 +
9563 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
9564 +
9565 +
9566 +/* context bcap mask */
9567 +
9568 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
9569 +
9570 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
9571 +
9572 +
9573 +/* mask given bcaps */
9574 +
9575 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
9576 +
9577 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
9578 +
9579 +
9580 +/* masked cap_bset */
9581 +
9582 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
9583 +
9584 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
9585 +
9586 +#if 0
9587 +#define vx_info_mbcap(v, b) \
9588 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
9589 +       vx_info_bcaps(v, b) : (b))
9590 +
9591 +#define task_vx_mbcap(t, b) \
9592 +       vx_info_mbcap((t)->vx_info, (t)->b)
9593 +
9594 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
9595 +#endif
9596 +
9597 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
9598 +
9599 +#define vx_capable(b, c) (capable(b) || \
9600 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9601 +
9602 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
9603 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9604 +
9605 +#define nx_capable(b, c) (capable(b) || \
9606 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9607 +
9608 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
9609 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9610 +
9611 +#define vx_task_initpid(t, n) \
9612 +       ((t)->vx_info && \
9613 +       ((t)->vx_info->vx_initpid == (n)))
9614 +
9615 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
9616 +
9617 +
9618 +/* context unshare mask */
9619 +
9620 +#define __vx_umask(v)          ((v)->vx_umask)
9621 +
9622 +#define vx_current_umask()     __vx_umask(current_vx_info())
9623 +
9624 +#define vx_can_unshare(b, f) (capable(b) || \
9625 +       (cap_raised(current_cap(), b) && \
9626 +       !((f) & ~vx_current_umask())))
9627 +
9628 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
9629 +       (cap_raised(current_cap(), b) && \
9630 +       !((f) & ~vx_current_umask())))
9631 +
9632 +#define __vx_wmask(v)          ((v)->vx_wmask)
9633 +
9634 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
9635 +
9636 +
9637 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
9638 +
9639 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
9640 +
9641 +
9642 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
9643 +
9644 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
9645 +
9646 +#endif
9647 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/cacct.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/cacct.h
9648 --- linux-3.13.1/include/linux/vserver/cacct.h  1970-01-01 00:00:00.000000000 +0000
9649 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/cacct.h       2014-01-31 20:38:03.000000000 +0000
9650 @@ -0,0 +1,15 @@
9651 +#ifndef _VSERVER_CACCT_H
9652 +#define _VSERVER_CACCT_H
9653 +
9654 +
9655 +enum sock_acc_field {
9656 +       VXA_SOCK_UNSPEC = 0,
9657 +       VXA_SOCK_UNIX,
9658 +       VXA_SOCK_INET,
9659 +       VXA_SOCK_INET6,
9660 +       VXA_SOCK_PACKET,
9661 +       VXA_SOCK_OTHER,
9662 +       VXA_SOCK_SIZE   /* array size */
9663 +};
9664 +
9665 +#endif /* _VSERVER_CACCT_H */
9666 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/cacct_cmd.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/cacct_cmd.h
9667 --- linux-3.13.1/include/linux/vserver/cacct_cmd.h      1970-01-01 00:00:00.000000000 +0000
9668 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/cacct_cmd.h   2014-01-31 20:38:03.000000000 +0000
9669 @@ -0,0 +1,10 @@
9670 +#ifndef _VSERVER_CACCT_CMD_H
9671 +#define _VSERVER_CACCT_CMD_H
9672 +
9673 +
9674 +#include <linux/compiler.h>
9675 +#include <uapi/vserver/cacct_cmd.h>
9676 +
9677 +extern int vc_sock_stat(struct vx_info *, void __user *);
9678 +
9679 +#endif /* _VSERVER_CACCT_CMD_H */
9680 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/cacct_def.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/cacct_def.h
9681 --- linux-3.13.1/include/linux/vserver/cacct_def.h      1970-01-01 00:00:00.000000000 +0000
9682 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/cacct_def.h   2014-01-31 20:38:03.000000000 +0000
9683 @@ -0,0 +1,43 @@
9684 +#ifndef _VSERVER_CACCT_DEF_H
9685 +#define _VSERVER_CACCT_DEF_H
9686 +
9687 +#include <asm/atomic.h>
9688 +#include <linux/vserver/cacct.h>
9689 +
9690 +
9691 +struct _vx_sock_acc {
9692 +       atomic_long_t count;
9693 +       atomic_long_t total;
9694 +};
9695 +
9696 +/* context sub struct */
9697 +
9698 +struct _vx_cacct {
9699 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
9700 +       atomic_t slab[8];
9701 +       atomic_t page[6][8];
9702 +};
9703 +
9704 +#ifdef CONFIG_VSERVER_DEBUG
9705 +
9706 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
9707 +{
9708 +       int i, j;
9709 +
9710 +       printk("\t_vx_cacct:");
9711 +       for (i = 0; i < 6; i++) {
9712 +               struct _vx_sock_acc *ptr = cacct->sock[i];
9713 +
9714 +               printk("\t [%d] =", i);
9715 +               for (j = 0; j < 3; j++) {
9716 +                       printk(" [%d] = %8lu, %8lu", j,
9717 +                               atomic_long_read(&ptr[j].count),
9718 +                               atomic_long_read(&ptr[j].total));
9719 +               }
9720 +               printk("\n");
9721 +       }
9722 +}
9723 +
9724 +#endif
9725 +
9726 +#endif /* _VSERVER_CACCT_DEF_H */
9727 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/cacct_int.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/cacct_int.h
9728 --- linux-3.13.1/include/linux/vserver/cacct_int.h      1970-01-01 00:00:00.000000000 +0000
9729 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/cacct_int.h   2014-01-31 20:38:03.000000000 +0000
9730 @@ -0,0 +1,17 @@
9731 +#ifndef _VSERVER_CACCT_INT_H
9732 +#define _VSERVER_CACCT_INT_H
9733 +
9734 +static inline
9735 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
9736 +{
9737 +       return atomic_long_read(&cacct->sock[type][pos].count);
9738 +}
9739 +
9740 +
9741 +static inline
9742 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
9743 +{
9744 +       return atomic_long_read(&cacct->sock[type][pos].total);
9745 +}
9746 +
9747 +#endif /* _VSERVER_CACCT_INT_H */
9748 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/check.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/check.h
9749 --- linux-3.13.1/include/linux/vserver/check.h  1970-01-01 00:00:00.000000000 +0000
9750 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/check.h       2014-01-31 20:38:03.000000000 +0000
9751 @@ -0,0 +1,89 @@
9752 +#ifndef _VSERVER_CHECK_H
9753 +#define _VSERVER_CHECK_H
9754 +
9755 +
9756 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
9757 +
9758 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
9759 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
9760 +#else
9761 +#define MIN_D_CONTEXT  65536
9762 +#endif
9763 +
9764 +/* check conditions */
9765 +
9766 +#define VS_ADMIN       0x0001
9767 +#define VS_WATCH       0x0002
9768 +#define VS_HIDE                0x0004
9769 +#define VS_HOSTID      0x0008
9770 +
9771 +#define VS_IDENT       0x0010
9772 +#define VS_EQUIV       0x0020
9773 +#define VS_PARENT      0x0040
9774 +#define VS_CHILD       0x0080
9775 +
9776 +#define VS_ARG_MASK    0x00F0
9777 +
9778 +#define VS_DYNAMIC     0x0100
9779 +#define VS_STATIC      0x0200
9780 +
9781 +#define VS_ATR_MASK    0x0F00
9782 +
9783 +#ifdef CONFIG_VSERVER_PRIVACY
9784 +#define VS_ADMIN_P     (0)
9785 +#define VS_WATCH_P     (0)
9786 +#else
9787 +#define VS_ADMIN_P     VS_ADMIN
9788 +#define VS_WATCH_P     VS_WATCH
9789 +#endif
9790 +
9791 +#define VS_HARDIRQ     0x1000
9792 +#define VS_SOFTIRQ     0x2000
9793 +#define VS_IRQ         0x4000
9794 +
9795 +#define VS_IRQ_MASK    0xF000
9796 +
9797 +#include <linux/hardirq.h>
9798 +
9799 +/*
9800 + * check current context for ADMIN/WATCH and
9801 + * optionally against supplied argument
9802 + */
9803 +static inline int __vs_check(int cid, int id, unsigned int mode)
9804 +{
9805 +       if (mode & VS_ARG_MASK) {
9806 +               if ((mode & VS_IDENT) && (id == cid))
9807 +                       return 1;
9808 +       }
9809 +       if (mode & VS_ATR_MASK) {
9810 +               if ((mode & VS_DYNAMIC) &&
9811 +                       (id >= MIN_D_CONTEXT) &&
9812 +                       (id <= MAX_S_CONTEXT))
9813 +                       return 1;
9814 +               if ((mode & VS_STATIC) &&
9815 +                       (id > 1) && (id < MIN_D_CONTEXT))
9816 +                       return 1;
9817 +       }
9818 +       if (mode & VS_IRQ_MASK) {
9819 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
9820 +                       return 1;
9821 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
9822 +                       return 1;
9823 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
9824 +                       return 1;
9825 +       }
9826 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
9827 +               ((mode & VS_WATCH) && (cid == 1)) ||
9828 +               ((mode & VS_HOSTID) && (id == 0)));
9829 +}
9830 +
9831 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
9832 +
9833 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
9834 +
9835 +
9836 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
9837 +
9838 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
9839 +
9840 +#endif
9841 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/context.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/context.h
9842 --- linux-3.13.1/include/linux/vserver/context.h        1970-01-01 00:00:00.000000000 +0000
9843 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/context.h     2014-01-31 20:38:03.000000000 +0000
9844 @@ -0,0 +1,110 @@
9845 +#ifndef _VSERVER_CONTEXT_H
9846 +#define _VSERVER_CONTEXT_H
9847 +
9848 +
9849 +#include <linux/list.h>
9850 +#include <linux/spinlock.h>
9851 +#include <linux/rcupdate.h>
9852 +#include <uapi/vserver/context.h>
9853 +
9854 +#include "limit_def.h"
9855 +#include "sched_def.h"
9856 +#include "cvirt_def.h"
9857 +#include "cacct_def.h"
9858 +#include "device_def.h"
9859 +
9860 +#define VX_SPACES      2
9861 +
9862 +struct _vx_info_pc {
9863 +       struct _vx_sched_pc sched_pc;
9864 +       struct _vx_cvirt_pc cvirt_pc;
9865 +};
9866 +
9867 +struct _vx_space {
9868 +       unsigned long vx_nsmask;                /* assignment mask */
9869 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
9870 +       struct fs_struct *vx_fs;                /* private namespace fs */
9871 +       const struct cred *vx_cred;             /* task credentials */
9872 +};
9873 +
9874 +struct vx_info {
9875 +       struct hlist_node vx_hlist;             /* linked list of contexts */
9876 +       vxid_t vx_id;                           /* context id */
9877 +       atomic_t vx_usecnt;                     /* usage count */
9878 +       atomic_t vx_tasks;                      /* tasks count */
9879 +       struct vx_info *vx_parent;              /* parent context */
9880 +       int vx_state;                           /* context state */
9881 +
9882 +       struct _vx_space space[VX_SPACES];      /* namespace store */
9883 +
9884 +       uint64_t vx_flags;                      /* context flags */
9885 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
9886 +       uint64_t vx_umask;                      /* unshare mask (guest) */
9887 +       uint64_t vx_wmask;                      /* warn mask (guest) */
9888 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
9889 +
9890 +       struct task_struct *vx_reaper;          /* guest reaper process */
9891 +       pid_t vx_initpid;                       /* PID of guest init */
9892 +       int64_t vx_badness_bias;                /* OOM points bias */
9893 +
9894 +       struct _vx_limit limit;                 /* vserver limits */
9895 +       struct _vx_sched sched;                 /* vserver scheduler */
9896 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
9897 +       struct _vx_cacct cacct;                 /* context accounting */
9898 +
9899 +       struct _vx_device dmap;                 /* default device map targets */
9900 +
9901 +#ifndef CONFIG_SMP
9902 +       struct _vx_info_pc info_pc;             /* per cpu data */
9903 +#else
9904 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
9905 +#endif
9906 +
9907 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
9908 +       int reboot_cmd;                         /* last sys_reboot() cmd */
9909 +       int exit_code;                          /* last process exit code */
9910 +
9911 +       char vx_name[65];                       /* vserver name */
9912 +};
9913 +
9914 +#ifndef CONFIG_SMP
9915 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
9916 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
9917 +#else
9918 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
9919 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
9920 +#endif
9921 +
9922 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
9923 +
9924 +
9925 +struct vx_info_save {
9926 +       struct vx_info *vxi;
9927 +       vxid_t xid;
9928 +};
9929 +
9930 +
9931 +/* status flags */
9932 +
9933 +#define VXS_HASHED     0x0001
9934 +#define VXS_PAUSED     0x0010
9935 +#define VXS_SHUTDOWN   0x0100
9936 +#define VXS_HELPER     0x1000
9937 +#define VXS_RELEASED   0x8000
9938 +
9939 +
9940 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
9941 +extern void release_vx_info(struct vx_info *, struct task_struct *);
9942 +
9943 +extern struct vx_info *lookup_vx_info(int);
9944 +extern struct vx_info *lookup_or_create_vx_info(int);
9945 +
9946 +extern int get_xid_list(int, unsigned int *, int);
9947 +extern int xid_is_hashed(vxid_t);
9948 +
9949 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
9950 +
9951 +extern long vs_state_change(struct vx_info *, unsigned int);
9952 +
9953 +
9954 +#endif /* _VSERVER_CONTEXT_H */
9955 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/context_cmd.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/context_cmd.h
9956 --- linux-3.13.1/include/linux/vserver/context_cmd.h    1970-01-01 00:00:00.000000000 +0000
9957 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/context_cmd.h 2014-01-31 20:38:03.000000000 +0000
9958 @@ -0,0 +1,33 @@
9959 +#ifndef _VSERVER_CONTEXT_CMD_H
9960 +#define _VSERVER_CONTEXT_CMD_H
9961 +
9962 +#include <uapi/vserver/context_cmd.h>
9963 +
9964 +extern int vc_task_xid(uint32_t);
9965 +
9966 +extern int vc_vx_info(struct vx_info *, void __user *);
9967 +
9968 +extern int vc_ctx_stat(struct vx_info *, void __user *);
9969 +
9970 +extern int vc_ctx_create(uint32_t, void __user *);
9971 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
9972 +
9973 +extern int vc_get_cflags(struct vx_info *, void __user *);
9974 +extern int vc_set_cflags(struct vx_info *, void __user *);
9975 +
9976 +extern int vc_get_ccaps(struct vx_info *, void __user *);
9977 +extern int vc_set_ccaps(struct vx_info *, void __user *);
9978 +
9979 +extern int vc_get_bcaps(struct vx_info *, void __user *);
9980 +extern int vc_set_bcaps(struct vx_info *, void __user *);
9981 +
9982 +extern int vc_get_umask(struct vx_info *, void __user *);
9983 +extern int vc_set_umask(struct vx_info *, void __user *);
9984 +
9985 +extern int vc_get_wmask(struct vx_info *, void __user *);
9986 +extern int vc_set_wmask(struct vx_info *, void __user *);
9987 +
9988 +extern int vc_get_badness(struct vx_info *, void __user *);
9989 +extern int vc_set_badness(struct vx_info *, void __user *);
9990 +
9991 +#endif /* _VSERVER_CONTEXT_CMD_H */
9992 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/cvirt.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/cvirt.h
9993 --- linux-3.13.1/include/linux/vserver/cvirt.h  1970-01-01 00:00:00.000000000 +0000
9994 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/cvirt.h       2014-01-31 20:38:03.000000000 +0000
9995 @@ -0,0 +1,18 @@
9996 +#ifndef _VSERVER_CVIRT_H
9997 +#define _VSERVER_CVIRT_H
9998 +
9999 +struct timespec;
10000 +
10001 +void vx_vsi_boottime(struct timespec *);
10002 +
10003 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10004 +
10005 +
10006 +struct vx_info;
10007 +
10008 +void vx_update_load(struct vx_info *);
10009 +
10010 +
10011 +int vx_do_syslog(int, char __user *, int);
10012 +
10013 +#endif /* _VSERVER_CVIRT_H */
10014 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/cvirt_cmd.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/cvirt_cmd.h
10015 --- linux-3.13.1/include/linux/vserver/cvirt_cmd.h      1970-01-01 00:00:00.000000000 +0000
10016 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/cvirt_cmd.h   2014-01-31 20:38:03.000000000 +0000
10017 @@ -0,0 +1,13 @@
10018 +#ifndef _VSERVER_CVIRT_CMD_H
10019 +#define _VSERVER_CVIRT_CMD_H
10020 +
10021 +
10022 +#include <linux/compiler.h>
10023 +#include <uapi/vserver/cvirt_cmd.h>
10024 +
10025 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10026 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10027 +
10028 +extern int vc_virt_stat(struct vx_info *, void __user *);
10029 +
10030 +#endif /* _VSERVER_CVIRT_CMD_H */
10031 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/cvirt_def.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/cvirt_def.h
10032 --- linux-3.13.1/include/linux/vserver/cvirt_def.h      1970-01-01 00:00:00.000000000 +0000
10033 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/cvirt_def.h   2014-01-31 20:38:03.000000000 +0000
10034 @@ -0,0 +1,80 @@
10035 +#ifndef _VSERVER_CVIRT_DEF_H
10036 +#define _VSERVER_CVIRT_DEF_H
10037 +
10038 +#include <linux/jiffies.h>
10039 +#include <linux/spinlock.h>
10040 +#include <linux/wait.h>
10041 +#include <linux/time.h>
10042 +#include <asm/atomic.h>
10043 +
10044 +
10045 +struct _vx_usage_stat {
10046 +       uint64_t user;
10047 +       uint64_t nice;
10048 +       uint64_t system;
10049 +       uint64_t softirq;
10050 +       uint64_t irq;
10051 +       uint64_t idle;
10052 +       uint64_t iowait;
10053 +};
10054 +
10055 +struct _vx_syslog {
10056 +       wait_queue_head_t log_wait;
10057 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10058 +
10059 +       unsigned long log_start;        /* next char to be read by syslog() */
10060 +       unsigned long con_start;        /* next char to be sent to consoles */
10061 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10062 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10063 +
10064 +       char log_buf[1024];
10065 +};
10066 +
10067 +
10068 +/* context sub struct */
10069 +
10070 +struct _vx_cvirt {
10071 +       atomic_t nr_threads;            /* number of current threads */
10072 +       atomic_t nr_running;            /* number of running threads */
10073 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10074 +
10075 +       atomic_t nr_onhold;             /* processes on hold */
10076 +       uint32_t onhold_last;           /* jiffies when put on hold */
10077 +
10078 +       struct timespec bias_ts;        /* time offset to the host */
10079 +       struct timespec bias_idle;
10080 +       struct timespec bias_uptime;    /* context creation point */
10081 +       uint64_t bias_clock;            /* offset in clock_t */
10082 +
10083 +       spinlock_t load_lock;           /* lock for the load averages */
10084 +       atomic_t load_updates;          /* nr of load updates done so far */
10085 +       uint32_t load_last;             /* last time load was calculated */
10086 +       uint32_t load[3];               /* load averages 1,5,15 */
10087 +
10088 +       atomic_t total_forks;           /* number of forks so far */
10089 +
10090 +       struct _vx_syslog syslog;
10091 +};
10092 +
10093 +struct _vx_cvirt_pc {
10094 +       struct _vx_usage_stat cpustat;
10095 +};
10096 +
10097 +
10098 +#ifdef CONFIG_VSERVER_DEBUG
10099 +
10100 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10101 +{
10102 +       printk("\t_vx_cvirt:\n");
10103 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10104 +               atomic_read(&cvirt->nr_threads),
10105 +               atomic_read(&cvirt->nr_running),
10106 +               atomic_read(&cvirt->nr_uninterruptible),
10107 +               atomic_read(&cvirt->nr_onhold));
10108 +       /* add rest here */
10109 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10110 +}
10111 +
10112 +#endif
10113 +
10114 +#endif /* _VSERVER_CVIRT_DEF_H */
10115 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/debug.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/debug.h
10116 --- linux-3.13.1/include/linux/vserver/debug.h  1970-01-01 00:00:00.000000000 +0000
10117 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/debug.h       2014-01-31 20:38:03.000000000 +0000
10118 @@ -0,0 +1,146 @@
10119 +#ifndef _VSERVER_DEBUG_H
10120 +#define _VSERVER_DEBUG_H
10121 +
10122 +
10123 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10124 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10125 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10126 +
10127 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10128 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10129 +#define VXF_DEV                "%p[%lu,%d:%d]"
10130 +
10131 +#if    defined(CONFIG_QUOTES_UTF8)
10132 +#define        VS_Q_LQM        "\xc2\xbb"
10133 +#define        VS_Q_RQM        "\xc2\xab"
10134 +#elif  defined(CONFIG_QUOTES_ASCII)
10135 +#define        VS_Q_LQM        "\x27"
10136 +#define        VS_Q_RQM        "\x27"
10137 +#else
10138 +#define        VS_Q_LQM        "\xbb"
10139 +#define        VS_Q_RQM        "\xab"
10140 +#endif
10141 +
10142 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
10143 +
10144 +
10145 +#define vxd_path(p)                                            \
10146 +       ({ static char _buffer[PATH_MAX];                       \
10147 +          d_path(p, _buffer, sizeof(_buffer)); })
10148 +
10149 +#define vxd_cond_path(n)                                       \
10150 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10151 +
10152 +
10153 +#ifdef CONFIG_VSERVER_DEBUG
10154 +
10155 +extern unsigned int vs_debug_switch;
10156 +extern unsigned int vs_debug_xid;
10157 +extern unsigned int vs_debug_nid;
10158 +extern unsigned int vs_debug_tag;
10159 +extern unsigned int vs_debug_net;
10160 +extern unsigned int vs_debug_limit;
10161 +extern unsigned int vs_debug_cres;
10162 +extern unsigned int vs_debug_dlim;
10163 +extern unsigned int vs_debug_quota;
10164 +extern unsigned int vs_debug_cvirt;
10165 +extern unsigned int vs_debug_space;
10166 +extern unsigned int vs_debug_perm;
10167 +extern unsigned int vs_debug_misc;
10168 +
10169 +
10170 +#define VX_LOGLEVEL    "vxD: "
10171 +#define VX_PROC_FMT    "%p: "
10172 +#define VX_PROCESS     current
10173 +
10174 +#define vxdprintk(c, f, x...)                                  \
10175 +       do {                                                    \
10176 +               if (c)                                          \
10177 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10178 +                               VX_PROCESS , ##x);              \
10179 +       } while (0)
10180 +
10181 +#define vxlprintk(c, f, x...)                                  \
10182 +       do {                                                    \
10183 +               if (c)                                          \
10184 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10185 +       } while (0)
10186 +
10187 +#define vxfprintk(c, f, x...)                                  \
10188 +       do {                                                    \
10189 +               if (c)                                          \
10190 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10191 +       } while (0)
10192 +
10193 +
10194 +struct vx_info;
10195 +
10196 +void dump_vx_info(struct vx_info *, int);
10197 +void dump_vx_info_inactive(int);
10198 +
10199 +#else  /* CONFIG_VSERVER_DEBUG */
10200 +
10201 +#define vs_debug_switch        0
10202 +#define vs_debug_xid   0
10203 +#define vs_debug_nid   0
10204 +#define vs_debug_tag   0
10205 +#define vs_debug_net   0
10206 +#define vs_debug_limit 0
10207 +#define vs_debug_cres  0
10208 +#define vs_debug_dlim  0
10209 +#define vs_debug_quota 0
10210 +#define vs_debug_cvirt 0
10211 +#define vs_debug_space 0
10212 +#define vs_debug_perm  0
10213 +#define vs_debug_misc  0
10214 +
10215 +#define vxdprintk(x...) do { } while (0)
10216 +#define vxlprintk(x...) do { } while (0)
10217 +#define vxfprintk(x...) do { } while (0)
10218 +
10219 +#endif /* CONFIG_VSERVER_DEBUG */
10220 +
10221 +
10222 +#ifdef CONFIG_VSERVER_WARN
10223 +
10224 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
10225 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10226 +#define VX_WARN_XID    "[xid #%u] "
10227 +#define VX_WARN_NID    "[nid #%u] "
10228 +#define VX_WARN_TAG    "[tag #%u] "
10229 +
10230 +#define vxwprintk(c, f, x...)                                  \
10231 +       do {                                                    \
10232 +               if (c)                                          \
10233 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
10234 +       } while (0)
10235 +
10236 +#else  /* CONFIG_VSERVER_WARN */
10237 +
10238 +#define vxwprintk(x...) do { } while (0)
10239 +
10240 +#endif /* CONFIG_VSERVER_WARN */
10241 +
10242 +#define vxwprintk_task(c, f, x...)                             \
10243 +       vxwprintk(c, VX_WARN_TASK f,                            \
10244 +               current->comm, current->pid,                    \
10245 +               current->xid, current->nid,                     \
10246 +               current->tag, ##x)
10247 +#define vxwprintk_xid(c, f, x...)                              \
10248 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
10249 +#define vxwprintk_nid(c, f, x...)                              \
10250 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
10251 +#define vxwprintk_tag(c, f, x...)                              \
10252 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10253 +
10254 +#ifdef CONFIG_VSERVER_DEBUG
10255 +#define vxd_assert_lock(l)     assert_spin_locked(l)
10256 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10257 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10258 +#else
10259 +#define vxd_assert_lock(l)     do { } while (0)
10260 +#define vxd_assert(c, f, x...) do { } while (0)
10261 +#endif
10262 +
10263 +
10264 +#endif /* _VSERVER_DEBUG_H */
10265 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/debug_cmd.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/debug_cmd.h
10266 --- linux-3.13.1/include/linux/vserver/debug_cmd.h      1970-01-01 00:00:00.000000000 +0000
10267 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/debug_cmd.h   2014-01-31 20:38:03.000000000 +0000
10268 @@ -0,0 +1,37 @@
10269 +#ifndef _VSERVER_DEBUG_CMD_H
10270 +#define _VSERVER_DEBUG_CMD_H
10271 +
10272 +#include <uapi/vserver/debug_cmd.h>
10273 +
10274 +
10275 +#ifdef CONFIG_COMPAT
10276 +
10277 +#include <asm/compat.h>
10278 +
10279 +struct vcmd_read_history_v0_x32 {
10280 +       uint32_t index;
10281 +       uint32_t count;
10282 +       compat_uptr_t data_ptr;
10283 +};
10284 +
10285 +struct vcmd_read_monitor_v0_x32 {
10286 +       uint32_t index;
10287 +       uint32_t count;
10288 +       compat_uptr_t data_ptr;
10289 +};
10290 +
10291 +#endif  /* CONFIG_COMPAT */
10292 +
10293 +extern int vc_dump_history(uint32_t);
10294 +
10295 +extern int vc_read_history(uint32_t, void __user *);
10296 +extern int vc_read_monitor(uint32_t, void __user *);
10297 +
10298 +#ifdef CONFIG_COMPAT
10299 +
10300 +extern int vc_read_history_x32(uint32_t, void __user *);
10301 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10302 +
10303 +#endif  /* CONFIG_COMPAT */
10304 +
10305 +#endif /* _VSERVER_DEBUG_CMD_H */
10306 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/device.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/device.h
10307 --- linux-3.13.1/include/linux/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
10308 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/device.h      2014-01-31 20:38:03.000000000 +0000
10309 @@ -0,0 +1,9 @@
10310 +#ifndef _VSERVER_DEVICE_H
10311 +#define _VSERVER_DEVICE_H
10312 +
10313 +
10314 +#include <uapi/vserver/device.h>
10315 +
10316 +#else  /* _VSERVER_DEVICE_H */
10317 +#warning duplicate inclusion
10318 +#endif /* _VSERVER_DEVICE_H */
10319 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/device_cmd.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/device_cmd.h
10320 --- linux-3.13.1/include/linux/vserver/device_cmd.h     1970-01-01 00:00:00.000000000 +0000
10321 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/device_cmd.h  2014-01-31 20:38:03.000000000 +0000
10322 @@ -0,0 +1,31 @@
10323 +#ifndef _VSERVER_DEVICE_CMD_H
10324 +#define _VSERVER_DEVICE_CMD_H
10325 +
10326 +#include <uapi/vserver/device_cmd.h>
10327 +
10328 +
10329 +#ifdef CONFIG_COMPAT
10330 +
10331 +#include <asm/compat.h>
10332 +
10333 +struct vcmd_set_mapping_v0_x32 {
10334 +       compat_uptr_t device_ptr;
10335 +       compat_uptr_t target_ptr;
10336 +       uint32_t flags;
10337 +};
10338 +
10339 +#endif /* CONFIG_COMPAT */
10340 +
10341 +#include <linux/compiler.h>
10342 +
10343 +extern int vc_set_mapping(struct vx_info *, void __user *);
10344 +extern int vc_unset_mapping(struct vx_info *, void __user *);
10345 +
10346 +#ifdef CONFIG_COMPAT
10347 +
10348 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
10349 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
10350 +
10351 +#endif /* CONFIG_COMPAT */
10352 +
10353 +#endif /* _VSERVER_DEVICE_CMD_H */
10354 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/device_def.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/device_def.h
10355 --- linux-3.13.1/include/linux/vserver/device_def.h     1970-01-01 00:00:00.000000000 +0000
10356 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/device_def.h  2014-01-31 20:38:03.000000000 +0000
10357 @@ -0,0 +1,17 @@
10358 +#ifndef _VSERVER_DEVICE_DEF_H
10359 +#define _VSERVER_DEVICE_DEF_H
10360 +
10361 +#include <linux/types.h>
10362 +
10363 +struct vx_dmap_target {
10364 +       dev_t target;
10365 +       uint32_t flags;
10366 +};
10367 +
10368 +struct _vx_device {
10369 +#ifdef CONFIG_VSERVER_DEVICE
10370 +       struct vx_dmap_target targets[2];
10371 +#endif
10372 +};
10373 +
10374 +#endif /* _VSERVER_DEVICE_DEF_H */
10375 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/dlimit.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/dlimit.h
10376 --- linux-3.13.1/include/linux/vserver/dlimit.h 1970-01-01 00:00:00.000000000 +0000
10377 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/dlimit.h      2014-01-31 20:38:03.000000000 +0000
10378 @@ -0,0 +1,54 @@
10379 +#ifndef _VSERVER_DLIMIT_H
10380 +#define _VSERVER_DLIMIT_H
10381 +
10382 +#include "switch.h"
10383 +
10384 +
10385 +#ifdef __KERNEL__
10386 +
10387 +/*      keep in sync with CDLIM_INFINITY       */
10388 +
10389 +#define DLIM_INFINITY          (~0ULL)
10390 +
10391 +#include <linux/spinlock.h>
10392 +#include <linux/rcupdate.h>
10393 +
10394 +struct super_block;
10395 +
10396 +struct dl_info {
10397 +       struct hlist_node dl_hlist;             /* linked list of contexts */
10398 +       struct rcu_head dl_rcu;                 /* the rcu head */
10399 +       vtag_t dl_tag;                          /* context tag */
10400 +       atomic_t dl_usecnt;                     /* usage count */
10401 +       atomic_t dl_refcnt;                     /* reference count */
10402 +
10403 +       struct super_block *dl_sb;              /* associated superblock */
10404 +
10405 +       spinlock_t dl_lock;                     /* protect the values */
10406 +
10407 +       unsigned long long dl_space_used;       /* used space in bytes */
10408 +       unsigned long long dl_space_total;      /* maximum space in bytes */
10409 +       unsigned long dl_inodes_used;           /* used inodes */
10410 +       unsigned long dl_inodes_total;          /* maximum inodes */
10411 +
10412 +       unsigned int dl_nrlmult;                /* non root limit mult */
10413 +};
10414 +
10415 +struct rcu_head;
10416 +
10417 +extern void rcu_free_dl_info(struct rcu_head *);
10418 +extern void unhash_dl_info(struct dl_info *);
10419 +
10420 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
10421 +
10422 +
10423 +struct kstatfs;
10424 +
10425 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
10426 +
10427 +typedef uint64_t dlsize_t;
10428 +
10429 +#endif /* __KERNEL__ */
10430 +#else  /* _VSERVER_DLIMIT_H */
10431 +#warning duplicate inclusion
10432 +#endif /* _VSERVER_DLIMIT_H */
10433 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/dlimit_cmd.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/dlimit_cmd.h
10434 --- linux-3.13.1/include/linux/vserver/dlimit_cmd.h     1970-01-01 00:00:00.000000000 +0000
10435 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/dlimit_cmd.h  2014-01-31 20:38:03.000000000 +0000
10436 @@ -0,0 +1,46 @@
10437 +#ifndef _VSERVER_DLIMIT_CMD_H
10438 +#define _VSERVER_DLIMIT_CMD_H
10439 +
10440 +#include <uapi/vserver/dlimit_cmd.h>
10441 +
10442 +
10443 +#ifdef CONFIG_COMPAT
10444 +
10445 +#include <asm/compat.h>
10446 +
10447 +struct vcmd_ctx_dlimit_base_v0_x32 {
10448 +       compat_uptr_t name_ptr;
10449 +       uint32_t flags;
10450 +};
10451 +
10452 +struct vcmd_ctx_dlimit_v0_x32 {
10453 +       compat_uptr_t name_ptr;
10454 +       uint32_t space_used;                    /* used space in kbytes */
10455 +       uint32_t space_total;                   /* maximum space in kbytes */
10456 +       uint32_t inodes_used;                   /* used inodes */
10457 +       uint32_t inodes_total;                  /* maximum inodes */
10458 +       uint32_t reserved;                      /* reserved for root in % */
10459 +       uint32_t flags;
10460 +};
10461 +
10462 +#endif /* CONFIG_COMPAT */
10463 +
10464 +#include <linux/compiler.h>
10465 +
10466 +extern int vc_add_dlimit(uint32_t, void __user *);
10467 +extern int vc_rem_dlimit(uint32_t, void __user *);
10468 +
10469 +extern int vc_set_dlimit(uint32_t, void __user *);
10470 +extern int vc_get_dlimit(uint32_t, void __user *);
10471 +
10472 +#ifdef CONFIG_COMPAT
10473 +
10474 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
10475 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
10476 +
10477 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
10478 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
10479 +
10480 +#endif /* CONFIG_COMPAT */
10481 +
10482 +#endif /* _VSERVER_DLIMIT_CMD_H */
10483 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/global.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/global.h
10484 --- linux-3.13.1/include/linux/vserver/global.h 1970-01-01 00:00:00.000000000 +0000
10485 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/global.h      2014-01-31 20:38:03.000000000 +0000
10486 @@ -0,0 +1,19 @@
10487 +#ifndef _VSERVER_GLOBAL_H
10488 +#define _VSERVER_GLOBAL_H
10489 +
10490 +
10491 +extern atomic_t vx_global_ctotal;
10492 +extern atomic_t vx_global_cactive;
10493 +
10494 +extern atomic_t nx_global_ctotal;
10495 +extern atomic_t nx_global_cactive;
10496 +
10497 +extern atomic_t vs_global_nsproxy;
10498 +extern atomic_t vs_global_fs;
10499 +extern atomic_t vs_global_mnt_ns;
10500 +extern atomic_t vs_global_uts_ns;
10501 +extern atomic_t vs_global_user_ns;
10502 +extern atomic_t vs_global_pid_ns;
10503 +
10504 +
10505 +#endif /* _VSERVER_GLOBAL_H */
10506 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/history.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/history.h
10507 --- linux-3.13.1/include/linux/vserver/history.h        1970-01-01 00:00:00.000000000 +0000
10508 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/history.h     2014-01-31 20:38:03.000000000 +0000
10509 @@ -0,0 +1,197 @@
10510 +#ifndef _VSERVER_HISTORY_H
10511 +#define _VSERVER_HISTORY_H
10512 +
10513 +
10514 +enum {
10515 +       VXH_UNUSED = 0,
10516 +       VXH_THROW_OOPS = 1,
10517 +
10518 +       VXH_GET_VX_INFO,
10519 +       VXH_PUT_VX_INFO,
10520 +       VXH_INIT_VX_INFO,
10521 +       VXH_SET_VX_INFO,
10522 +       VXH_CLR_VX_INFO,
10523 +       VXH_CLAIM_VX_INFO,
10524 +       VXH_RELEASE_VX_INFO,
10525 +       VXH_ALLOC_VX_INFO,
10526 +       VXH_DEALLOC_VX_INFO,
10527 +       VXH_HASH_VX_INFO,
10528 +       VXH_UNHASH_VX_INFO,
10529 +       VXH_LOC_VX_INFO,
10530 +       VXH_LOOKUP_VX_INFO,
10531 +       VXH_CREATE_VX_INFO,
10532 +};
10533 +
10534 +struct _vxhe_vxi {
10535 +       struct vx_info *ptr;
10536 +       unsigned xid;
10537 +       unsigned usecnt;
10538 +       unsigned tasks;
10539 +};
10540 +
10541 +struct _vxhe_set_clr {
10542 +       void *data;
10543 +};
10544 +
10545 +struct _vxhe_loc_lookup {
10546 +       unsigned arg;
10547 +};
10548 +
10549 +struct _vx_hist_entry {
10550 +       void *loc;
10551 +       unsigned short seq;
10552 +       unsigned short type;
10553 +       struct _vxhe_vxi vxi;
10554 +       union {
10555 +               struct _vxhe_set_clr sc;
10556 +               struct _vxhe_loc_lookup ll;
10557 +       };
10558 +};
10559 +
10560 +#ifdef CONFIG_VSERVER_HISTORY
10561 +
10562 +extern unsigned volatile int vxh_active;
10563 +
10564 +struct _vx_hist_entry *vxh_advance(void *loc);
10565 +
10566 +
10567 +static inline
10568 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
10569 +{
10570 +       entry->vxi.ptr = vxi;
10571 +       if (vxi) {
10572 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
10573 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
10574 +               entry->vxi.xid = vxi->vx_id;
10575 +       }
10576 +}
10577 +
10578 +
10579 +#define        __HERE__ current_text_addr()
10580 +
10581 +#define __VXH_BODY(__type, __data, __here)     \
10582 +       struct _vx_hist_entry *entry;           \
10583 +                                               \
10584 +       preempt_disable();                      \
10585 +       entry = vxh_advance(__here);            \
10586 +       __data;                                 \
10587 +       entry->type = __type;                   \
10588 +       preempt_enable();
10589 +
10590 +
10591 +       /* pass vxi only */
10592 +
10593 +#define __VXH_SMPL                             \
10594 +       __vxh_copy_vxi(entry, vxi)
10595 +
10596 +static inline
10597 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
10598 +{
10599 +       __VXH_BODY(__type, __VXH_SMPL, __here)
10600 +}
10601 +
10602 +       /* pass vxi and data (void *) */
10603 +
10604 +#define __VXH_DATA                             \
10605 +       __vxh_copy_vxi(entry, vxi);             \
10606 +       entry->sc.data = data
10607 +
10608 +static inline
10609 +void   __vxh_data(struct vx_info *vxi, void *data,
10610 +                       int __type, void *__here)
10611 +{
10612 +       __VXH_BODY(__type, __VXH_DATA, __here)
10613 +}
10614 +
10615 +       /* pass vxi and arg (long) */
10616 +
10617 +#define __VXH_LONG                             \
10618 +       __vxh_copy_vxi(entry, vxi);             \
10619 +       entry->ll.arg = arg
10620 +
10621 +static inline
10622 +void   __vxh_long(struct vx_info *vxi, long arg,
10623 +                       int __type, void *__here)
10624 +{
10625 +       __VXH_BODY(__type, __VXH_LONG, __here)
10626 +}
10627 +
10628 +
10629 +static inline
10630 +void   __vxh_throw_oops(void *__here)
10631 +{
10632 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
10633 +       /* prevent further acquisition */
10634 +       vxh_active = 0;
10635 +}
10636 +
10637 +
10638 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
10639 +
10640 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
10641 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
10642 +
10643 +#define __vxh_init_vx_info(v, d, h) \
10644 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
10645 +#define __vxh_set_vx_info(v, d, h) \
10646 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
10647 +#define __vxh_clr_vx_info(v, d, h) \
10648 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
10649 +
10650 +#define __vxh_claim_vx_info(v, d, h) \
10651 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
10652 +#define __vxh_release_vx_info(v, d, h) \
10653 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
10654 +
10655 +#define vxh_alloc_vx_info(v) \
10656 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
10657 +#define vxh_dealloc_vx_info(v) \
10658 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
10659 +
10660 +#define vxh_hash_vx_info(v) \
10661 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
10662 +#define vxh_unhash_vx_info(v) \
10663 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
10664 +
10665 +#define vxh_loc_vx_info(v, l) \
10666 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
10667 +#define vxh_lookup_vx_info(v, l) \
10668 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
10669 +#define vxh_create_vx_info(v, l) \
10670 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
10671 +
10672 +extern void vxh_dump_history(void);
10673 +
10674 +
10675 +#else  /* CONFIG_VSERVER_HISTORY */
10676 +
10677 +#define        __HERE__        0
10678 +
10679 +#define vxh_throw_oops()               do { } while (0)
10680 +
10681 +#define __vxh_get_vx_info(v, h)                do { } while (0)
10682 +#define __vxh_put_vx_info(v, h)                do { } while (0)
10683 +
10684 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
10685 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
10686 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
10687 +
10688 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
10689 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
10690 +
10691 +#define vxh_alloc_vx_info(v)           do { } while (0)
10692 +#define vxh_dealloc_vx_info(v)         do { } while (0)
10693 +
10694 +#define vxh_hash_vx_info(v)            do { } while (0)
10695 +#define vxh_unhash_vx_info(v)          do { } while (0)
10696 +
10697 +#define vxh_loc_vx_info(v, l)          do { } while (0)
10698 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
10699 +#define vxh_create_vx_info(v, l)       do { } while (0)
10700 +
10701 +#define vxh_dump_history()             do { } while (0)
10702 +
10703 +
10704 +#endif /* CONFIG_VSERVER_HISTORY */
10705 +
10706 +#endif /* _VSERVER_HISTORY_H */
10707 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/inode.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/inode.h
10708 --- linux-3.13.1/include/linux/vserver/inode.h  1970-01-01 00:00:00.000000000 +0000
10709 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/inode.h       2014-01-31 20:38:03.000000000 +0000
10710 @@ -0,0 +1,19 @@
10711 +#ifndef _VSERVER_INODE_H
10712 +#define _VSERVER_INODE_H
10713 +
10714 +#include <uapi/vserver/inode.h>
10715 +
10716 +
10717 +#ifdef CONFIG_VSERVER_PROC_SECURE
10718 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
10719 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10720 +#else
10721 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
10722 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10723 +#endif
10724 +
10725 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
10726 +
10727 +#else  /* _VSERVER_INODE_H */
10728 +#warning duplicate inclusion
10729 +#endif /* _VSERVER_INODE_H */
10730 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/inode_cmd.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/inode_cmd.h
10731 --- linux-3.13.1/include/linux/vserver/inode_cmd.h      1970-01-01 00:00:00.000000000 +0000
10732 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/inode_cmd.h   2014-01-31 20:38:03.000000000 +0000
10733 @@ -0,0 +1,36 @@
10734 +#ifndef _VSERVER_INODE_CMD_H
10735 +#define _VSERVER_INODE_CMD_H
10736 +
10737 +#include <uapi/vserver/inode_cmd.h>
10738 +
10739 +
10740 +
10741 +#ifdef CONFIG_COMPAT
10742 +
10743 +#include <asm/compat.h>
10744 +
10745 +struct vcmd_ctx_iattr_v1_x32 {
10746 +       compat_uptr_t name_ptr;
10747 +       uint32_t tag;
10748 +       uint32_t flags;
10749 +       uint32_t mask;
10750 +};
10751 +
10752 +#endif /* CONFIG_COMPAT */
10753 +
10754 +#include <linux/compiler.h>
10755 +
10756 +extern int vc_get_iattr(void __user *);
10757 +extern int vc_set_iattr(void __user *);
10758 +
10759 +extern int vc_fget_iattr(uint32_t, void __user *);
10760 +extern int vc_fset_iattr(uint32_t, void __user *);
10761 +
10762 +#ifdef CONFIG_COMPAT
10763 +
10764 +extern int vc_get_iattr_x32(void __user *);
10765 +extern int vc_set_iattr_x32(void __user *);
10766 +
10767 +#endif /* CONFIG_COMPAT */
10768 +
10769 +#endif /* _VSERVER_INODE_CMD_H */
10770 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/limit.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/limit.h
10771 --- linux-3.13.1/include/linux/vserver/limit.h  1970-01-01 00:00:00.000000000 +0000
10772 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/limit.h       2014-01-31 20:38:03.000000000 +0000
10773 @@ -0,0 +1,61 @@
10774 +#ifndef _VSERVER_LIMIT_H
10775 +#define _VSERVER_LIMIT_H
10776 +
10777 +#include <uapi/vserver/limit.h>
10778 +
10779 +
10780 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
10781 +
10782 +/*     keep in sync with CRLIM_INFINITY */
10783 +
10784 +#define        VLIM_INFINITY   (~0ULL)
10785 +
10786 +#include <asm/atomic.h>
10787 +#include <asm/resource.h>
10788 +
10789 +#ifndef RLIM_INFINITY
10790 +#warning RLIM_INFINITY is undefined
10791 +#endif
10792 +
10793 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
10794 +
10795 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
10796 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
10797 +
10798 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
10799 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
10800 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
10801 +
10802 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
10803 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
10804 +
10805 +typedef atomic_long_t rlim_atomic_t;
10806 +typedef unsigned long rlim_t;
10807 +
10808 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
10809 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
10810 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
10811 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
10812 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
10813 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
10814 +
10815 +
10816 +#if    (RLIM_INFINITY == VLIM_INFINITY)
10817 +#define        VX_VLIM(r) ((long long)(long)(r))
10818 +#define        VX_RLIM(v) ((rlim_t)(v))
10819 +#else
10820 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
10821 +               ? VLIM_INFINITY : (long long)(r))
10822 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
10823 +               ? RLIM_INFINITY : (rlim_t)(v))
10824 +#endif
10825 +
10826 +struct sysinfo;
10827 +
10828 +void vx_vsi_meminfo(struct sysinfo *);
10829 +void vx_vsi_swapinfo(struct sysinfo *);
10830 +long vx_vsi_cached(struct sysinfo *);
10831 +
10832 +#define NUM_LIMITS     24
10833 +
10834 +#endif /* _VSERVER_LIMIT_H */
10835 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/limit_cmd.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/limit_cmd.h
10836 --- linux-3.13.1/include/linux/vserver/limit_cmd.h      1970-01-01 00:00:00.000000000 +0000
10837 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/limit_cmd.h   2014-01-31 20:38:03.000000000 +0000
10838 @@ -0,0 +1,35 @@
10839 +#ifndef _VSERVER_LIMIT_CMD_H
10840 +#define _VSERVER_LIMIT_CMD_H
10841 +
10842 +#include <uapi/vserver/limit_cmd.h>
10843 +
10844 +
10845 +#ifdef CONFIG_IA32_EMULATION
10846 +
10847 +struct vcmd_ctx_rlimit_v0_x32 {
10848 +       uint32_t id;
10849 +       uint64_t minimum;
10850 +       uint64_t softlimit;
10851 +       uint64_t maximum;
10852 +} __attribute__ ((packed));
10853 +
10854 +#endif /* CONFIG_IA32_EMULATION */
10855 +
10856 +#include <linux/compiler.h>
10857 +
10858 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
10859 +extern int vc_get_rlimit(struct vx_info *, void __user *);
10860 +extern int vc_set_rlimit(struct vx_info *, void __user *);
10861 +extern int vc_reset_hits(struct vx_info *, void __user *);
10862 +extern int vc_reset_minmax(struct vx_info *, void __user *);
10863 +
10864 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
10865 +
10866 +#ifdef CONFIG_IA32_EMULATION
10867 +
10868 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
10869 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
10870 +
10871 +#endif /* CONFIG_IA32_EMULATION */
10872 +
10873 +#endif /* _VSERVER_LIMIT_CMD_H */
10874 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/limit_def.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/limit_def.h
10875 --- linux-3.13.1/include/linux/vserver/limit_def.h      1970-01-01 00:00:00.000000000 +0000
10876 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/limit_def.h   2014-01-31 20:38:03.000000000 +0000
10877 @@ -0,0 +1,47 @@
10878 +#ifndef _VSERVER_LIMIT_DEF_H
10879 +#define _VSERVER_LIMIT_DEF_H
10880 +
10881 +#include <asm/atomic.h>
10882 +#include <asm/resource.h>
10883 +
10884 +#include "limit.h"
10885 +
10886 +
10887 +struct _vx_res_limit {
10888 +       rlim_t soft;            /* Context soft limit */
10889 +       rlim_t hard;            /* Context hard limit */
10890 +
10891 +       rlim_atomic_t rcur;     /* Current value */
10892 +       rlim_t rmin;            /* Context minimum */
10893 +       rlim_t rmax;            /* Context maximum */
10894 +
10895 +       atomic_t lhit;          /* Limit hits */
10896 +};
10897 +
10898 +/* context sub struct */
10899 +
10900 +struct _vx_limit {
10901 +       struct _vx_res_limit res[NUM_LIMITS];
10902 +};
10903 +
10904 +#ifdef CONFIG_VSERVER_DEBUG
10905 +
10906 +static inline void __dump_vx_limit(struct _vx_limit *limit)
10907 +{
10908 +       int i;
10909 +
10910 +       printk("\t_vx_limit:");
10911 +       for (i = 0; i < NUM_LIMITS; i++) {
10912 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
10913 +                       i, (unsigned long)__rlim_get(limit, i),
10914 +                       (unsigned long)__rlim_rmin(limit, i),
10915 +                       (unsigned long)__rlim_rmax(limit, i),
10916 +                       (long)__rlim_soft(limit, i),
10917 +                       (long)__rlim_hard(limit, i),
10918 +                       atomic_read(&__rlim_lhit(limit, i)));
10919 +       }
10920 +}
10921 +
10922 +#endif
10923 +
10924 +#endif /* _VSERVER_LIMIT_DEF_H */
10925 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/limit_int.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/limit_int.h
10926 --- linux-3.13.1/include/linux/vserver/limit_int.h      1970-01-01 00:00:00.000000000 +0000
10927 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/limit_int.h   2014-01-31 20:38:03.000000000 +0000
10928 @@ -0,0 +1,193 @@
10929 +#ifndef _VSERVER_LIMIT_INT_H
10930 +#define _VSERVER_LIMIT_INT_H
10931 +
10932 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
10933 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
10934 +
10935 +extern const char *vlimit_name[NUM_LIMITS];
10936 +
10937 +static inline void __vx_acc_cres(struct vx_info *vxi,
10938 +       int res, int dir, void *_data, char *_file, int _line)
10939 +{
10940 +       if (VXD_RCRES_COND(res))
10941 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
10942 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10943 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10944 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
10945 +       if (!vxi)
10946 +               return;
10947 +
10948 +       if (dir > 0)
10949 +               __rlim_inc(&vxi->limit, res);
10950 +       else
10951 +               __rlim_dec(&vxi->limit, res);
10952 +}
10953 +
10954 +static inline void __vx_add_cres(struct vx_info *vxi,
10955 +       int res, int amount, void *_data, char *_file, int _line)
10956 +{
10957 +       if (VXD_RCRES_COND(res))
10958 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
10959 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10960 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10961 +                       amount, _data, _file, _line);
10962 +       if (amount == 0)
10963 +               return;
10964 +       if (!vxi)
10965 +               return;
10966 +       __rlim_add(&vxi->limit, res, amount);
10967 +}
10968 +
10969 +static inline
10970 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
10971 +{
10972 +       int cond = (value > __rlim_rmax(limit, res));
10973 +
10974 +       if (cond)
10975 +               __rlim_rmax(limit, res) = value;
10976 +       return cond;
10977 +}
10978 +
10979 +static inline
10980 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
10981 +{
10982 +       int cond = (value < __rlim_rmin(limit, res));
10983 +
10984 +       if (cond)
10985 +               __rlim_rmin(limit, res) = value;
10986 +       return cond;
10987 +}
10988 +
10989 +static inline
10990 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
10991 +{
10992 +       if (!__vx_cres_adjust_max(limit, res, value))
10993 +               __vx_cres_adjust_min(limit, res, value);
10994 +}
10995 +
10996 +
10997 +/*     return values:
10998 +        +1 ... no limit hit
10999 +        -1 ... over soft limit
11000 +         0 ... over hard limit         */
11001 +
11002 +static inline int __vx_cres_avail(struct vx_info *vxi,
11003 +       int res, int num, char *_file, int _line)
11004 +{
11005 +       struct _vx_limit *limit;
11006 +       rlim_t value;
11007 +
11008 +       if (VXD_RLIMIT_COND(res))
11009 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11010 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11011 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11012 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11013 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11014 +                       num, _file, _line);
11015 +       if (!vxi)
11016 +               return 1;
11017 +
11018 +       limit = &vxi->limit;
11019 +       value = __rlim_get(limit, res);
11020 +
11021 +       if (!__vx_cres_adjust_max(limit, res, value))
11022 +               __vx_cres_adjust_min(limit, res, value);
11023 +
11024 +       if (num == 0)
11025 +               return 1;
11026 +
11027 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
11028 +               return -1;
11029 +       if (value + num <= __rlim_soft(limit, res))
11030 +               return -1;
11031 +
11032 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
11033 +               return 1;
11034 +       if (value + num <= __rlim_hard(limit, res))
11035 +               return 1;
11036 +
11037 +       __rlim_hit(limit, res);
11038 +       return 0;
11039 +}
11040 +
11041 +
11042 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11043 +
11044 +static inline
11045 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11046 +{
11047 +       rlim_t value, sum = 0;
11048 +       int res;
11049 +
11050 +       while ((res = *array++)) {
11051 +               value = __rlim_get(limit, res);
11052 +               __vx_cres_fixup(limit, res, value);
11053 +               sum += value;
11054 +       }
11055 +       return sum;
11056 +}
11057 +
11058 +static inline
11059 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11060 +{
11061 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11062 +       int res = *array;
11063 +
11064 +       if (value == __rlim_get(limit, res))
11065 +               return value;
11066 +
11067 +       __rlim_set(limit, res, value);
11068 +       /* now adjust min/max */
11069 +       if (!__vx_cres_adjust_max(limit, res, value))
11070 +               __vx_cres_adjust_min(limit, res, value);
11071 +
11072 +       return value;
11073 +}
11074 +
11075 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11076 +       const int *array, int num, char *_file, int _line)
11077 +{
11078 +       struct _vx_limit *limit;
11079 +       rlim_t value = 0;
11080 +       int res;
11081 +
11082 +       if (num == 0)
11083 +               return 1;
11084 +       if (!vxi)
11085 +               return 1;
11086 +
11087 +       limit = &vxi->limit;
11088 +       res = *array;
11089 +       value = __vx_cres_array_sum(limit, array + 1);
11090 +
11091 +       __rlim_set(limit, res, value);
11092 +       __vx_cres_fixup(limit, res, value);
11093 +
11094 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11095 +}
11096 +
11097 +
11098 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11099 +{
11100 +       rlim_t value;
11101 +       int res;
11102 +
11103 +       /* complex resources first */
11104 +       if ((id < 0) || (id == RLIMIT_RSS))
11105 +               __vx_cres_array_fixup(limit, VLA_RSS);
11106 +
11107 +       for (res = 0; res < NUM_LIMITS; res++) {
11108 +               if ((id > 0) && (res != id))
11109 +                       continue;
11110 +
11111 +               value = __rlim_get(limit, res);
11112 +               __vx_cres_fixup(limit, res, value);
11113 +
11114 +               /* not supposed to happen, maybe warn? */
11115 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11116 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11117 +       }
11118 +}
11119 +
11120 +
11121 +#endif /* _VSERVER_LIMIT_INT_H */
11122 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/monitor.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/monitor.h
11123 --- linux-3.13.1/include/linux/vserver/monitor.h        1970-01-01 00:00:00.000000000 +0000
11124 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/monitor.h     2014-01-31 20:38:03.000000000 +0000
11125 @@ -0,0 +1,6 @@
11126 +#ifndef _VSERVER_MONITOR_H
11127 +#define _VSERVER_MONITOR_H
11128 +
11129 +#include <uapi/vserver/monitor.h>
11130 +
11131 +#endif /* _VSERVER_MONITOR_H */
11132 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/network.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/network.h
11133 --- linux-3.13.1/include/linux/vserver/network.h        1970-01-01 00:00:00.000000000 +0000
11134 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/network.h     2014-01-31 20:38:03.000000000 +0000
11135 @@ -0,0 +1,76 @@
11136 +#ifndef _VSERVER_NETWORK_H
11137 +#define _VSERVER_NETWORK_H
11138 +
11139 +
11140 +#include <linux/list.h>
11141 +#include <linux/spinlock.h>
11142 +#include <linux/rcupdate.h>
11143 +#include <linux/in.h>
11144 +#include <linux/in6.h>
11145 +#include <asm/atomic.h>
11146 +#include <uapi/vserver/network.h>
11147 +
11148 +struct nx_addr_v4 {
11149 +       struct nx_addr_v4 *next;
11150 +       struct in_addr ip[2];
11151 +       struct in_addr mask;
11152 +       uint16_t type;
11153 +       uint16_t flags;
11154 +};
11155 +
11156 +struct nx_addr_v6 {
11157 +       struct nx_addr_v6 *next;
11158 +       struct in6_addr ip;
11159 +       struct in6_addr mask;
11160 +       uint32_t prefix;
11161 +       uint16_t type;
11162 +       uint16_t flags;
11163 +};
11164 +
11165 +struct nx_info {
11166 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
11167 +       vnid_t nx_id;                   /* vnet id */
11168 +       atomic_t nx_usecnt;             /* usage count */
11169 +       atomic_t nx_tasks;              /* tasks count */
11170 +       int nx_state;                   /* context state */
11171 +
11172 +       uint64_t nx_flags;              /* network flag word */
11173 +       uint64_t nx_ncaps;              /* network capabilities */
11174 +
11175 +       spinlock_t addr_lock;           /* protect address changes */
11176 +       struct in_addr v4_lback;        /* Loopback address */
11177 +       struct in_addr v4_bcast;        /* Broadcast address */
11178 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
11179 +#ifdef CONFIG_IPV6
11180 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
11181 +#endif
11182 +       char nx_name[65];               /* network context name */
11183 +};
11184 +
11185 +
11186 +/* status flags */
11187 +
11188 +#define NXS_HASHED      0x0001
11189 +#define NXS_SHUTDOWN    0x0100
11190 +#define NXS_RELEASED    0x8000
11191 +
11192 +extern struct nx_info *lookup_nx_info(int);
11193 +
11194 +extern int get_nid_list(int, unsigned int *, int);
11195 +extern int nid_is_hashed(vnid_t);
11196 +
11197 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11198 +
11199 +extern long vs_net_change(struct nx_info *, unsigned int);
11200 +
11201 +struct sock;
11202 +
11203 +
11204 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
11205 +#ifdef  CONFIG_IPV6
11206 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
11207 +#else
11208 +#define NX_IPV6(n)     (0)
11209 +#endif
11210 +
11211 +#endif /* _VSERVER_NETWORK_H */
11212 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/network_cmd.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/network_cmd.h
11213 --- linux-3.13.1/include/linux/vserver/network_cmd.h    1970-01-01 00:00:00.000000000 +0000
11214 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/network_cmd.h 2014-01-31 20:38:03.000000000 +0000
11215 @@ -0,0 +1,37 @@
11216 +#ifndef _VSERVER_NETWORK_CMD_H
11217 +#define _VSERVER_NETWORK_CMD_H
11218 +
11219 +#include <uapi/vserver/network_cmd.h>
11220 +
11221 +extern int vc_task_nid(uint32_t);
11222 +
11223 +extern int vc_nx_info(struct nx_info *, void __user *);
11224 +
11225 +extern int vc_net_create(uint32_t, void __user *);
11226 +extern int vc_net_migrate(struct nx_info *, void __user *);
11227 +
11228 +extern int vc_net_add(struct nx_info *, void __user *);
11229 +extern int vc_net_remove(struct nx_info *, void __user *);
11230 +
11231 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11232 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11233 +
11234 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11235 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11236 +
11237 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11238 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11239 +
11240 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11241 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11242 +
11243 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11244 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11245 +
11246 +extern int vc_get_nflags(struct nx_info *, void __user *);
11247 +extern int vc_set_nflags(struct nx_info *, void __user *);
11248 +
11249 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11250 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11251 +
11252 +#endif /* _VSERVER_CONTEXT_CMD_H */
11253 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/percpu.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/percpu.h
11254 --- linux-3.13.1/include/linux/vserver/percpu.h 1970-01-01 00:00:00.000000000 +0000
11255 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/percpu.h      2014-01-31 20:38:03.000000000 +0000
11256 @@ -0,0 +1,14 @@
11257 +#ifndef _VSERVER_PERCPU_H
11258 +#define _VSERVER_PERCPU_H
11259 +
11260 +#include "cvirt_def.h"
11261 +#include "sched_def.h"
11262 +
11263 +struct _vx_percpu {
11264 +       struct _vx_cvirt_pc cvirt;
11265 +       struct _vx_sched_pc sched;
11266 +};
11267 +
11268 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
11269 +
11270 +#endif /* _VSERVER_PERCPU_H */
11271 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/pid.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/pid.h
11272 --- linux-3.13.1/include/linux/vserver/pid.h    1970-01-01 00:00:00.000000000 +0000
11273 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/pid.h 2014-01-31 20:38:03.000000000 +0000
11274 @@ -0,0 +1,51 @@
11275 +#ifndef _VSERVER_PID_H
11276 +#define _VSERVER_PID_H
11277 +
11278 +/* pid faking stuff */
11279 +
11280 +#define vx_info_map_pid(v, p) \
11281 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
11282 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
11283 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
11284 +#define vx_map_tgid(p) vx_map_pid(p)
11285 +
11286 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
11287 +       const char *func, const char *file, int line)
11288 +{
11289 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11290 +               vxfprintk(VXD_CBIT(cvirt, 2),
11291 +                       "vx_map_tgid: %p/%llx: %d -> %d",
11292 +                       vxi, (long long)vxi->vx_flags, pid,
11293 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
11294 +                       func, file, line);
11295 +               if (pid == 0)
11296 +                       return 0;
11297 +               if (pid == vxi->vx_initpid)
11298 +                       return 1;
11299 +       }
11300 +       return pid;
11301 +}
11302 +
11303 +#define vx_info_rmap_pid(v, p) \
11304 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
11305 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
11306 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
11307 +
11308 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
11309 +       const char *func, const char *file, int line)
11310 +{
11311 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11312 +               vxfprintk(VXD_CBIT(cvirt, 2),
11313 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
11314 +                       vxi, (long long)vxi->vx_flags, pid,
11315 +                       (pid == 1) ? vxi->vx_initpid : pid,
11316 +                       func, file, line);
11317 +               if ((pid == 1) && vxi->vx_initpid)
11318 +                       return vxi->vx_initpid;
11319 +               if (pid == vxi->vx_initpid)
11320 +                       return ~0U;
11321 +       }
11322 +       return pid;
11323 +}
11324 +
11325 +#endif
11326 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/sched.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/sched.h
11327 --- linux-3.13.1/include/linux/vserver/sched.h  1970-01-01 00:00:00.000000000 +0000
11328 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/sched.h       2014-01-31 20:38:03.000000000 +0000
11329 @@ -0,0 +1,23 @@
11330 +#ifndef _VSERVER_SCHED_H
11331 +#define _VSERVER_SCHED_H
11332 +
11333 +
11334 +#ifdef __KERNEL__
11335 +
11336 +struct timespec;
11337 +
11338 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11339 +
11340 +
11341 +struct vx_info;
11342 +
11343 +void vx_update_load(struct vx_info *);
11344 +
11345 +
11346 +void vx_update_sched_param(struct _vx_sched *sched,
11347 +       struct _vx_sched_pc *sched_pc);
11348 +
11349 +#endif /* __KERNEL__ */
11350 +#else  /* _VSERVER_SCHED_H */
11351 +#warning duplicate inclusion
11352 +#endif /* _VSERVER_SCHED_H */
11353 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/sched_cmd.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/sched_cmd.h
11354 --- linux-3.13.1/include/linux/vserver/sched_cmd.h      1970-01-01 00:00:00.000000000 +0000
11355 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/sched_cmd.h   2014-01-31 20:38:03.000000000 +0000
11356 @@ -0,0 +1,11 @@
11357 +#ifndef _VSERVER_SCHED_CMD_H
11358 +#define _VSERVER_SCHED_CMD_H
11359 +
11360 +
11361 +#include <linux/compiler.h>
11362 +#include <uapi/vserver/sched_cmd.h>
11363 +
11364 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
11365 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
11366 +
11367 +#endif /* _VSERVER_SCHED_CMD_H */
11368 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/sched_def.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/sched_def.h
11369 --- linux-3.13.1/include/linux/vserver/sched_def.h      1970-01-01 00:00:00.000000000 +0000
11370 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/sched_def.h   2014-01-31 20:38:03.000000000 +0000
11371 @@ -0,0 +1,38 @@
11372 +#ifndef _VSERVER_SCHED_DEF_H
11373 +#define _VSERVER_SCHED_DEF_H
11374 +
11375 +#include <linux/spinlock.h>
11376 +#include <linux/jiffies.h>
11377 +#include <linux/cpumask.h>
11378 +#include <asm/atomic.h>
11379 +#include <asm/param.h>
11380 +
11381 +
11382 +/* context sub struct */
11383 +
11384 +struct _vx_sched {
11385 +       int prio_bias;                  /* bias offset for priority */
11386 +
11387 +       cpumask_t update;               /* CPUs which should update */
11388 +};
11389 +
11390 +struct _vx_sched_pc {
11391 +       int prio_bias;                  /* bias offset for priority */
11392 +
11393 +       uint64_t user_ticks;            /* token tick events */
11394 +       uint64_t sys_ticks;             /* token tick events */
11395 +       uint64_t hold_ticks;            /* token ticks paused */
11396 +};
11397 +
11398 +
11399 +#ifdef CONFIG_VSERVER_DEBUG
11400 +
11401 +static inline void __dump_vx_sched(struct _vx_sched *sched)
11402 +{
11403 +       printk("\t_vx_sched:\n");
11404 +       printk("\t priority = %4d\n", sched->prio_bias);
11405 +}
11406 +
11407 +#endif
11408 +
11409 +#endif /* _VSERVER_SCHED_DEF_H */
11410 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/signal.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/signal.h
11411 --- linux-3.13.1/include/linux/vserver/signal.h 1970-01-01 00:00:00.000000000 +0000
11412 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/signal.h      2014-01-31 20:38:03.000000000 +0000
11413 @@ -0,0 +1,14 @@
11414 +#ifndef _VSERVER_SIGNAL_H
11415 +#define _VSERVER_SIGNAL_H
11416 +
11417 +
11418 +#ifdef __KERNEL__
11419 +
11420 +struct vx_info;
11421 +
11422 +int vx_info_kill(struct vx_info *, int, int);
11423 +
11424 +#endif /* __KERNEL__ */
11425 +#else  /* _VSERVER_SIGNAL_H */
11426 +#warning duplicate inclusion
11427 +#endif /* _VSERVER_SIGNAL_H */
11428 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/signal_cmd.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/signal_cmd.h
11429 --- linux-3.13.1/include/linux/vserver/signal_cmd.h     1970-01-01 00:00:00.000000000 +0000
11430 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/signal_cmd.h  2014-01-31 20:38:03.000000000 +0000
11431 @@ -0,0 +1,14 @@
11432 +#ifndef _VSERVER_SIGNAL_CMD_H
11433 +#define _VSERVER_SIGNAL_CMD_H
11434 +
11435 +#include <uapi/vserver/signal_cmd.h>
11436 +
11437 +
11438 +extern int vc_ctx_kill(struct vx_info *, void __user *);
11439 +extern int vc_wait_exit(struct vx_info *, void __user *);
11440 +
11441 +
11442 +extern int vc_get_pflags(uint32_t pid, void __user *);
11443 +extern int vc_set_pflags(uint32_t pid, void __user *);
11444 +
11445 +#endif /* _VSERVER_SIGNAL_CMD_H */
11446 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/space.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/space.h
11447 --- linux-3.13.1/include/linux/vserver/space.h  1970-01-01 00:00:00.000000000 +0000
11448 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/space.h       2014-01-31 20:38:03.000000000 +0000
11449 @@ -0,0 +1,12 @@
11450 +#ifndef _VSERVER_SPACE_H
11451 +#define _VSERVER_SPACE_H
11452 +
11453 +#include <linux/types.h>
11454 +
11455 +struct vx_info;
11456 +
11457 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
11458 +
11459 +#else  /* _VSERVER_SPACE_H */
11460 +#warning duplicate inclusion
11461 +#endif /* _VSERVER_SPACE_H */
11462 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/space_cmd.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/space_cmd.h
11463 --- linux-3.13.1/include/linux/vserver/space_cmd.h      1970-01-01 00:00:00.000000000 +0000
11464 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/space_cmd.h   2014-01-31 20:38:03.000000000 +0000
11465 @@ -0,0 +1,13 @@
11466 +#ifndef _VSERVER_SPACE_CMD_H
11467 +#define _VSERVER_SPACE_CMD_H
11468 +
11469 +#include <uapi/vserver/space_cmd.h>
11470 +
11471 +
11472 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
11473 +extern int vc_set_space_v1(struct vx_info *, void __user *);
11474 +extern int vc_enter_space(struct vx_info *, void __user *);
11475 +extern int vc_set_space(struct vx_info *, void __user *);
11476 +extern int vc_get_space_mask(void __user *, int);
11477 +
11478 +#endif /* _VSERVER_SPACE_CMD_H */
11479 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/switch.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/switch.h
11480 --- linux-3.13.1/include/linux/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
11481 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/switch.h      2014-01-31 20:38:03.000000000 +0000
11482 @@ -0,0 +1,8 @@
11483 +#ifndef _VSERVER_SWITCH_H
11484 +#define _VSERVER_SWITCH_H
11485 +
11486 +
11487 +#include <linux/errno.h>
11488 +#include <uapi/vserver/switch.h>
11489 +
11490 +#endif /* _VSERVER_SWITCH_H */
11491 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/tag.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/tag.h
11492 --- linux-3.13.1/include/linux/vserver/tag.h    1970-01-01 00:00:00.000000000 +0000
11493 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/tag.h 2014-01-31 20:38:03.000000000 +0000
11494 @@ -0,0 +1,160 @@
11495 +#ifndef _DX_TAG_H
11496 +#define _DX_TAG_H
11497 +
11498 +#include <linux/types.h>
11499 +#include <linux/uidgid.h>
11500 +
11501 +
11502 +#define DX_TAG(in)     (IS_TAGGED(in))
11503 +
11504 +
11505 +#ifdef CONFIG_TAG_NFSD
11506 +#define DX_TAG_NFSD    1
11507 +#else
11508 +#define DX_TAG_NFSD    0
11509 +#endif
11510 +
11511 +
11512 +#ifdef CONFIG_TAGGING_NONE
11513 +
11514 +#define MAX_UID                0xFFFFFFFF
11515 +#define MAX_GID                0xFFFFFFFF
11516 +
11517 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
11518 +
11519 +#define TAGINO_UID(cond, uid, tag)     (uid)
11520 +#define TAGINO_GID(cond, gid, tag)     (gid)
11521 +
11522 +#endif
11523 +
11524 +
11525 +#ifdef CONFIG_TAGGING_GID16
11526 +
11527 +#define MAX_UID                0xFFFFFFFF
11528 +#define MAX_GID                0x0000FFFF
11529 +
11530 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11531 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
11532 +
11533 +#define TAGINO_UID(cond, uid, tag)     (uid)
11534 +#define TAGINO_GID(cond, gid, tag)     \
11535 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
11536 +
11537 +#endif
11538 +
11539 +
11540 +#ifdef CONFIG_TAGGING_ID24
11541 +
11542 +#define MAX_UID                0x00FFFFFF
11543 +#define MAX_GID                0x00FFFFFF
11544 +
11545 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11546 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
11547 +
11548 +#define TAGINO_UID(cond, uid, tag)     \
11549 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
11550 +#define TAGINO_GID(cond, gid, tag)     \
11551 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
11552 +
11553 +#endif
11554 +
11555 +
11556 +#ifdef CONFIG_TAGGING_UID16
11557 +
11558 +#define MAX_UID                0x0000FFFF
11559 +#define MAX_GID                0xFFFFFFFF
11560 +
11561 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11562 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
11563 +
11564 +#define TAGINO_UID(cond, uid, tag)     \
11565 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
11566 +#define TAGINO_GID(cond, gid, tag)     (gid)
11567 +
11568 +#endif
11569 +
11570 +
11571 +#ifdef CONFIG_TAGGING_INTERN
11572 +
11573 +#define MAX_UID                0xFFFFFFFF
11574 +#define MAX_GID                0xFFFFFFFF
11575 +
11576 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11577 +       ((cond) ? (tag) : 0)
11578 +
11579 +#define TAGINO_UID(cond, uid, tag)     (uid)
11580 +#define TAGINO_GID(cond, gid, tag)     (gid)
11581 +
11582 +#endif
11583 +
11584 +
11585 +#ifndef CONFIG_TAGGING_NONE
11586 +#define dx_current_fstag(sb)   \
11587 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
11588 +#else
11589 +#define dx_current_fstag(sb)   (0)
11590 +#endif
11591 +
11592 +#ifndef CONFIG_TAGGING_INTERN
11593 +#define TAGINO_TAG(cond, tag)  (0)
11594 +#else
11595 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
11596 +#endif
11597 +
11598 +#define TAGINO_KUID(cond, kuid, ktag)  \
11599 +       KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
11600 +#define TAGINO_KGID(cond, kgid, ktag)  \
11601 +       KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
11602 +#define TAGINO_KTAG(cond, ktag)                \
11603 +       KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
11604 +
11605 +
11606 +#define INOTAG_UID(cond, uid, gid)     \
11607 +       ((cond) ? ((uid) & MAX_UID) : (uid))
11608 +#define INOTAG_GID(cond, uid, gid)     \
11609 +       ((cond) ? ((gid) & MAX_GID) : (gid))
11610 +
11611 +#define INOTAG_KUID(cond, kuid, kgid)  \
11612 +       KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11613 +#define INOTAG_KGID(cond, kuid, kgid)  \
11614 +       KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11615 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
11616 +       KTAGT_INIT(INOTAG_TAG(cond, \
11617 +               __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
11618 +
11619 +
11620 +static inline uid_t dx_map_uid(uid_t uid)
11621 +{
11622 +       if ((uid > MAX_UID) && (uid != -1))
11623 +               uid = -2;
11624 +       return (uid & MAX_UID);
11625 +}
11626 +
11627 +static inline gid_t dx_map_gid(gid_t gid)
11628 +{
11629 +       if ((gid > MAX_GID) && (gid != -1))
11630 +               gid = -2;
11631 +       return (gid & MAX_GID);
11632 +}
11633 +
11634 +struct peer_tag {
11635 +       int32_t xid;
11636 +       int32_t nid;
11637 +};
11638 +
11639 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
11640 +
11641 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
11642 +                unsigned long *flags);
11643 +
11644 +#ifdef CONFIG_PROPAGATE
11645 +
11646 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
11647 +
11648 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
11649 +
11650 +#else
11651 +#define dx_propagate_tag(n, i) do { } while (0)
11652 +#endif
11653 +
11654 +#endif /* _DX_TAG_H */
11655 diff -NurpP --minimal linux-3.13.1/include/linux/vserver/tag_cmd.h linux-3.13.1-vs2.3.6.10/include/linux/vserver/tag_cmd.h
11656 --- linux-3.13.1/include/linux/vserver/tag_cmd.h        1970-01-01 00:00:00.000000000 +0000
11657 +++ linux-3.13.1-vs2.3.6.10/include/linux/vserver/tag_cmd.h     2014-01-31 20:38:03.000000000 +0000
11658 @@ -0,0 +1,10 @@
11659 +#ifndef _VSERVER_TAG_CMD_H
11660 +#define _VSERVER_TAG_CMD_H
11661 +
11662 +#include <uapi/vserver/tag_cmd.h>
11663 +
11664 +extern int vc_task_tag(uint32_t);
11665 +
11666 +extern int vc_tag_migrate(uint32_t);
11667 +
11668 +#endif /* _VSERVER_TAG_CMD_H */
11669 diff -NurpP --minimal linux-3.13.1/include/net/addrconf.h linux-3.13.1-vs2.3.6.10/include/net/addrconf.h
11670 --- linux-3.13.1/include/net/addrconf.h 2013-11-25 15:47:02.000000000 +0000
11671 +++ linux-3.13.1-vs2.3.6.10/include/net/addrconf.h      2014-01-31 20:39:35.000000000 +0000
11672 @@ -79,7 +79,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
11673  
11674  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dev,
11675                        const struct in6_addr *daddr, unsigned int srcprefs,
11676 -                      struct in6_addr *saddr);
11677 +                      struct in6_addr *saddr, struct nx_info *nxi);
11678  int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
11679                       unsigned char banned_flags);
11680  int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
11681 diff -NurpP --minimal linux-3.13.1/include/net/af_unix.h linux-3.13.1-vs2.3.6.10/include/net/af_unix.h
11682 --- linux-3.13.1/include/net/af_unix.h  2013-11-25 15:47:02.000000000 +0000
11683 +++ linux-3.13.1-vs2.3.6.10/include/net/af_unix.h       2014-01-31 20:38:03.000000000 +0000
11684 @@ -4,6 +4,7 @@
11685  #include <linux/socket.h>
11686  #include <linux/un.h>
11687  #include <linux/mutex.h>
11688 +#include <linux/vs_base.h>
11689  #include <net/sock.h>
11690  
11691  void unix_inflight(struct file *fp);
11692 diff -NurpP --minimal linux-3.13.1/include/net/inet_timewait_sock.h linux-3.13.1-vs2.3.6.10/include/net/inet_timewait_sock.h
11693 --- linux-3.13.1/include/net/inet_timewait_sock.h       2014-01-22 20:39:11.000000000 +0000
11694 +++ linux-3.13.1-vs2.3.6.10/include/net/inet_timewait_sock.h    2014-01-31 20:40:30.000000000 +0000
11695 @@ -121,6 +121,10 @@ struct inet_timewait_sock {
11696  #define tw_v6_rcv_saddr        __tw_common.skc_v6_rcv_saddr
11697  #define tw_dport               __tw_common.skc_dport
11698  #define tw_num                 __tw_common.skc_num
11699 +#define tw_xid                 __tw_common.skc_xid
11700 +#define tw_vx_info             __tw_common.skc_vx_info
11701 +#define tw_nid                 __tw_common.skc_nid
11702 +#define tw_nx_info             __tw_common.skc_nx_info
11703  
11704         int                     tw_timeout;
11705         volatile unsigned char  tw_substate;
11706 diff -NurpP --minimal linux-3.13.1/include/net/ip6_route.h linux-3.13.1-vs2.3.6.10/include/net/ip6_route.h
11707 --- linux-3.13.1/include/net/ip6_route.h        2014-01-22 20:39:11.000000000 +0000
11708 +++ linux-3.13.1-vs2.3.6.10/include/net/ip6_route.h     2014-01-31 20:41:10.000000000 +0000
11709 @@ -90,7 +90,7 @@ int ip6_del_rt(struct rt6_info *);
11710  
11711  int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
11712                         const struct in6_addr *daddr, unsigned int prefs,
11713 -                       struct in6_addr *saddr);
11714 +                       struct in6_addr *saddr, struct nx_info *nxi);
11715  
11716  struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
11717                             const struct in6_addr *saddr, int oif, int flags);
11718 diff -NurpP --minimal linux-3.13.1/include/net/route.h linux-3.13.1-vs2.3.6.10/include/net/route.h
11719 --- linux-3.13.1/include/net/route.h    2014-01-22 20:39:12.000000000 +0000
11720 +++ linux-3.13.1-vs2.3.6.10/include/net/route.h 2014-02-01 12:30:58.000000000 +0000
11721 @@ -203,6 +203,9 @@ static inline void ip_rt_put(struct rtab
11722         dst_release(&rt->dst);
11723  }
11724  
11725 +#include <linux/vs_base.h>
11726 +#include <linux/vs_inet.h>
11727 +
11728  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
11729  
11730  extern const __u8 ip_tos2prio[16];
11731 @@ -252,6 +255,9 @@ static inline void ip_route_connect_init
11732                            protocol, flow_flags, dst, src, dport, sport);
11733  }
11734  
11735 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
11736 +       struct flowi4 *);
11737 +
11738  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
11739                                               __be32 dst, __be32 src, u32 tos,
11740                                               int oif, u8 protocol,
11741 @@ -260,11 +266,25 @@ static inline struct rtable *ip_route_co
11742  {
11743         struct net *net = sock_net(sk);
11744         struct rtable *rt;
11745 +       struct nx_info *nx_info = current_nx_info();
11746  
11747         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
11748                               sport, dport, sk, can_sleep);
11749  
11750 -       if (!dst || !src) {
11751 +       if (sk)
11752 +               nx_info = sk->sk_nx_info;
11753 +
11754 +       vxdprintk(VXD_CBIT(net, 4),
11755 +               "ip_route_connect(%p) %p,%p;%lx",
11756 +               sk, nx_info, sk->sk_socket,
11757 +               (sk->sk_socket?sk->sk_socket->flags:0));
11758 +
11759 +       rt = ip_v4_find_src(net, nx_info, fl4);
11760 +       if (IS_ERR(rt))
11761 +               return rt;
11762 +       ip_rt_put(rt);
11763 +
11764 +       if (!fl4->daddr || !fl4->saddr) {
11765                 rt = __ip_route_output_key(net, fl4);
11766                 if (IS_ERR(rt))
11767                         return rt;
11768 diff -NurpP --minimal linux-3.13.1/include/net/sock.h linux-3.13.1-vs2.3.6.10/include/net/sock.h
11769 --- linux-3.13.1/include/net/sock.h     2014-01-22 20:39:12.000000000 +0000
11770 +++ linux-3.13.1-vs2.3.6.10/include/net/sock.h  2014-01-31 20:42:22.000000000 +0000
11771 @@ -191,6 +191,10 @@ struct sock_common {
11772  #ifdef CONFIG_NET_NS
11773         struct net              *skc_net;
11774  #endif
11775 +       vxid_t                  skc_xid;
11776 +       struct vx_info          *skc_vx_info;
11777 +       vnid_t                  skc_nid;
11778 +       struct nx_info          *skc_nx_info;
11779  
11780  #if IS_ENABLED(CONFIG_IPV6)
11781         struct in6_addr         skc_v6_daddr;
11782 @@ -321,7 +325,11 @@ struct sock {
11783  #define sk_prot                        __sk_common.skc_prot
11784  #define sk_net                 __sk_common.skc_net
11785  #define sk_v6_daddr            __sk_common.skc_v6_daddr
11786 -#define sk_v6_rcv_saddr        __sk_common.skc_v6_rcv_saddr
11787 +#define sk_v6_rcv_saddr                __sk_common.skc_v6_rcv_saddr
11788 +#define sk_xid                 __sk_common.skc_xid
11789 +#define sk_vx_info             __sk_common.skc_vx_info
11790 +#define sk_nid                 __sk_common.skc_nid
11791 +#define sk_nx_info             __sk_common.skc_nx_info
11792  
11793         socket_lock_t           sk_lock;
11794         struct sk_buff_head     sk_receive_queue;
11795 diff -NurpP --minimal linux-3.13.1/include/uapi/Kbuild linux-3.13.1-vs2.3.6.10/include/uapi/Kbuild
11796 --- linux-3.13.1/include/uapi/Kbuild    2012-12-11 03:30:57.000000000 +0000
11797 +++ linux-3.13.1-vs2.3.6.10/include/uapi/Kbuild 2014-01-31 20:38:03.000000000 +0000
11798 @@ -12,3 +12,4 @@ header-y += video/
11799  header-y += drm/
11800  header-y += xen/
11801  header-y += scsi/
11802 +header-y += vserver/
11803 diff -NurpP --minimal linux-3.13.1/include/uapi/linux/capability.h linux-3.13.1-vs2.3.6.10/include/uapi/linux/capability.h
11804 --- linux-3.13.1/include/uapi/linux/capability.h        2012-12-11 03:30:57.000000000 +0000
11805 +++ linux-3.13.1-vs2.3.6.10/include/uapi/linux/capability.h     2014-01-31 20:38:03.000000000 +0000
11806 @@ -259,6 +259,7 @@ struct vfs_cap_data {
11807     arbitrary SCSI commands */
11808  /* Allow setting encryption key on loopback filesystem */
11809  /* Allow setting zone reclaim policy */
11810 +/* Allow the selection of a security context */
11811  
11812  #define CAP_SYS_ADMIN        21
11813  
11814 @@ -345,7 +346,12 @@ struct vfs_cap_data {
11815  
11816  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
11817  
11818 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
11819 +/* Allow context manipulations */
11820 +/* Allow changing context info on files */
11821 +
11822 +#define CAP_CONTEXT         63
11823 +
11824 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
11825  
11826  /*
11827   * Bit location of each capability (used by user-space library and kernel)
11828 diff -NurpP --minimal linux-3.13.1/include/uapi/linux/fs.h linux-3.13.1-vs2.3.6.10/include/uapi/linux/fs.h
11829 --- linux-3.13.1/include/uapi/linux/fs.h        2013-11-25 15:47:02.000000000 +0000
11830 +++ linux-3.13.1-vs2.3.6.10/include/uapi/linux/fs.h     2014-01-31 20:38:03.000000000 +0000
11831 @@ -86,6 +86,9 @@ struct inodes_stat_t {
11832  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
11833  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
11834  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
11835 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
11836 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
11837 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
11838  
11839  /* These sb flags are internal to the kernel */
11840  #define MS_NOSEC       (1<<28)
11841 @@ -191,11 +194,14 @@ struct inodes_stat_t {
11842  #define FS_EXTENT_FL                   0x00080000 /* Extents */
11843  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
11844  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
11845 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
11846  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
11847  
11848 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
11849 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
11850 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
11851 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
11852  
11853 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
11854 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
11855  
11856  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
11857  #define SYNC_FILE_RANGE_WRITE          2
11858 diff -NurpP --minimal linux-3.13.1/include/uapi/linux/gfs2_ondisk.h linux-3.13.1-vs2.3.6.10/include/uapi/linux/gfs2_ondisk.h
11859 --- linux-3.13.1/include/uapi/linux/gfs2_ondisk.h       2012-12-11 03:30:57.000000000 +0000
11860 +++ linux-3.13.1-vs2.3.6.10/include/uapi/linux/gfs2_ondisk.h    2014-01-31 20:38:03.000000000 +0000
11861 @@ -225,6 +225,9 @@ enum {
11862         gfs2fl_Sync             = 8,
11863         gfs2fl_System           = 9,
11864         gfs2fl_TopLevel         = 10,
11865 +       gfs2fl_IXUnlink         = 16,
11866 +       gfs2fl_Barrier          = 17,
11867 +       gfs2fl_Cow              = 18,
11868         gfs2fl_TruncInProg      = 29,
11869         gfs2fl_InheritDirectio  = 30,
11870         gfs2fl_InheritJdata     = 31,
11871 @@ -242,6 +245,9 @@ enum {
11872  #define GFS2_DIF_SYNC                  0x00000100
11873  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
11874  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
11875 +#define GFS2_DIF_IXUNLINK               0x00010000
11876 +#define GFS2_DIF_BARRIER                0x00020000
11877 +#define GFS2_DIF_COW                    0x00040000
11878  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
11879  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
11880  #define GFS2_DIF_INHERIT_JDATA         0x80000000
11881 diff -NurpP --minimal linux-3.13.1/include/uapi/linux/if_tun.h linux-3.13.1-vs2.3.6.10/include/uapi/linux/if_tun.h
11882 --- linux-3.13.1/include/uapi/linux/if_tun.h    2013-11-25 15:47:02.000000000 +0000
11883 +++ linux-3.13.1-vs2.3.6.10/include/uapi/linux/if_tun.h 2014-01-31 20:45:49.000000000 +0000
11884 @@ -58,6 +58,7 @@
11885  #define TUNSETQUEUE  _IOW('T', 217, int)
11886  #define TUNSETIFINDEX  _IOW('T', 218, unsigned int)
11887  #define TUNGETFILTER _IOR('T', 219, struct sock_fprog)
11888 +#define TUNSETNID     _IOW('T', 220, int)
11889  
11890  /* TUNSETIFF ifr flags */
11891  #define IFF_TUN                0x0001
11892 diff -NurpP --minimal linux-3.13.1/include/uapi/linux/major.h linux-3.13.1-vs2.3.6.10/include/uapi/linux/major.h
11893 --- linux-3.13.1/include/uapi/linux/major.h     2014-01-22 20:39:12.000000000 +0000
11894 +++ linux-3.13.1-vs2.3.6.10/include/uapi/linux/major.h  2014-01-31 20:38:03.000000000 +0000
11895 @@ -15,6 +15,7 @@
11896  #define HD_MAJOR               IDE0_MAJOR
11897  #define PTY_SLAVE_MAJOR                3
11898  #define TTY_MAJOR              4
11899 +#define VROOT_MAJOR            4
11900  #define TTYAUX_MAJOR           5
11901  #define LP_MAJOR               6
11902  #define VCS_MAJOR              7
11903 diff -NurpP --minimal linux-3.13.1/include/uapi/linux/nfs_mount.h linux-3.13.1-vs2.3.6.10/include/uapi/linux/nfs_mount.h
11904 --- linux-3.13.1/include/uapi/linux/nfs_mount.h 2014-01-22 20:39:12.000000000 +0000
11905 +++ linux-3.13.1-vs2.3.6.10/include/uapi/linux/nfs_mount.h      2014-01-31 20:38:03.000000000 +0000
11906 @@ -63,7 +63,8 @@ struct nfs_mount_data {
11907  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 non-text parsed mount data only */
11908  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
11909  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
11910 -#define NFS_MOUNT_FLAGMASK     0xFFFF
11911 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
11912 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
11913  
11914  /* The following are for internal use only */
11915  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
11916 diff -NurpP --minimal linux-3.13.1/include/uapi/linux/reboot.h linux-3.13.1-vs2.3.6.10/include/uapi/linux/reboot.h
11917 --- linux-3.13.1/include/uapi/linux/reboot.h    2012-12-11 03:30:57.000000000 +0000
11918 +++ linux-3.13.1-vs2.3.6.10/include/uapi/linux/reboot.h 2014-01-31 20:38:03.000000000 +0000
11919 @@ -33,7 +33,7 @@
11920  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
11921  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
11922  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
11923 -
11924 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
11925  
11926  
11927  #endif /* _UAPI_LINUX_REBOOT_H */
11928 diff -NurpP --minimal linux-3.13.1/include/uapi/linux/sysctl.h linux-3.13.1-vs2.3.6.10/include/uapi/linux/sysctl.h
11929 --- linux-3.13.1/include/uapi/linux/sysctl.h    2012-12-11 03:30:57.000000000 +0000
11930 +++ linux-3.13.1-vs2.3.6.10/include/uapi/linux/sysctl.h 2014-01-31 20:38:03.000000000 +0000
11931 @@ -60,6 +60,7 @@ enum
11932         CTL_ABI=9,              /* Binary emulation */
11933         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
11934         CTL_ARLAN=254,          /* arlan wireless driver */
11935 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
11936         CTL_S390DBF=5677,       /* s390 debug */
11937         CTL_SUNRPC=7249,        /* sunrpc debug */
11938         CTL_PM=9899,            /* frv power management */
11939 @@ -94,6 +95,7 @@ enum
11940  
11941         KERN_PANIC=15,          /* int: panic timeout */
11942         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
11943 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
11944  
11945         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
11946         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
11947 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/Kbuild linux-3.13.1-vs2.3.6.10/include/uapi/vserver/Kbuild
11948 --- linux-3.13.1/include/uapi/vserver/Kbuild    1970-01-01 00:00:00.000000000 +0000
11949 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/Kbuild 2014-01-31 20:38:03.000000000 +0000
11950 @@ -0,0 +1,9 @@
11951 +
11952 +header-y += context_cmd.h network_cmd.h space_cmd.h \
11953 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11954 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11955 +       debug_cmd.h device_cmd.h
11956 +
11957 +header-y += switch.h context.h network.h monitor.h \
11958 +       limit.h inode.h device.h
11959 +
11960 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/cacct_cmd.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/cacct_cmd.h
11961 --- linux-3.13.1/include/uapi/vserver/cacct_cmd.h       1970-01-01 00:00:00.000000000 +0000
11962 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/cacct_cmd.h    2014-01-31 20:38:03.000000000 +0000
11963 @@ -0,0 +1,15 @@
11964 +#ifndef _UAPI_VS_CACCT_CMD_H
11965 +#define _UAPI_VS_CACCT_CMD_H
11966 +
11967 +
11968 +/* virtual host info name commands */
11969 +
11970 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11971 +
11972 +struct vcmd_sock_stat_v0 {
11973 +       uint32_t field;
11974 +       uint32_t count[3];
11975 +       uint64_t total[3];
11976 +};
11977 +
11978 +#endif /* _UAPI_VS_CACCT_CMD_H */
11979 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/context.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/context.h
11980 --- linux-3.13.1/include/uapi/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
11981 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/context.h      2014-01-31 20:38:03.000000000 +0000
11982 @@ -0,0 +1,81 @@
11983 +#ifndef _UAPI_VS_CONTEXT_H
11984 +#define _UAPI_VS_CONTEXT_H
11985 +
11986 +#include <linux/types.h>
11987 +#include <linux/capability.h>
11988 +
11989 +
11990 +/* context flags */
11991 +
11992 +#define VXF_INFO_SCHED         0x00000002
11993 +#define VXF_INFO_NPROC         0x00000004
11994 +#define VXF_INFO_PRIVATE       0x00000008
11995 +
11996 +#define VXF_INFO_INIT          0x00000010
11997 +#define VXF_INFO_HIDE          0x00000020
11998 +#define VXF_INFO_ULIMIT                0x00000040
11999 +#define VXF_INFO_NSPACE                0x00000080
12000 +
12001 +#define VXF_SCHED_HARD         0x00000100
12002 +#define VXF_SCHED_PRIO         0x00000200
12003 +#define VXF_SCHED_PAUSE                0x00000400
12004 +
12005 +#define VXF_VIRT_MEM           0x00010000
12006 +#define VXF_VIRT_UPTIME                0x00020000
12007 +#define VXF_VIRT_CPU           0x00040000
12008 +#define VXF_VIRT_LOAD          0x00080000
12009 +#define VXF_VIRT_TIME          0x00100000
12010 +
12011 +#define VXF_HIDE_MOUNT         0x01000000
12012 +/* was VXF_HIDE_NETIF          0x02000000 */
12013 +#define VXF_HIDE_VINFO         0x04000000
12014 +
12015 +#define VXF_STATE_SETUP                (1ULL << 32)
12016 +#define VXF_STATE_INIT         (1ULL << 33)
12017 +#define VXF_STATE_ADMIN                (1ULL << 34)
12018 +
12019 +#define VXF_SC_HELPER          (1ULL << 36)
12020 +#define VXF_REBOOT_KILL                (1ULL << 37)
12021 +#define VXF_PERSISTENT         (1ULL << 38)
12022 +
12023 +#define VXF_FORK_RSS           (1ULL << 48)
12024 +#define VXF_PROLIFIC           (1ULL << 49)
12025 +
12026 +#define VXF_IGNEG_NICE         (1ULL << 52)
12027 +
12028 +#define VXF_ONE_TIME           (0x0007ULL << 32)
12029 +
12030 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12031 +
12032 +
12033 +/* context migration */
12034 +
12035 +#define VXM_SET_INIT           0x00000001
12036 +#define VXM_SET_REAPER         0x00000002
12037 +
12038 +/* context caps */
12039 +
12040 +#define VXC_SET_UTSNAME                0x00000001
12041 +#define VXC_SET_RLIMIT         0x00000002
12042 +#define VXC_FS_SECURITY                0x00000004
12043 +#define VXC_FS_TRUSTED         0x00000008
12044 +#define VXC_TIOCSTI            0x00000010
12045 +
12046 +/* was VXC_RAW_ICMP            0x00000100 */
12047 +#define VXC_SYSLOG             0x00001000
12048 +#define VXC_OOM_ADJUST         0x00002000
12049 +#define VXC_AUDIT_CONTROL      0x00004000
12050 +
12051 +#define VXC_SECURE_MOUNT       0x00010000
12052 +/* #define VXC_SECURE_REMOUNT  0x00020000 */
12053 +#define VXC_BINARY_MOUNT       0x00040000
12054 +#define VXC_DEV_MOUNT          0x00080000
12055 +
12056 +#define VXC_QUOTA_CTL          0x00100000
12057 +#define VXC_ADMIN_MAPPER       0x00200000
12058 +#define VXC_ADMIN_CLOOP                0x00400000
12059 +
12060 +#define VXC_KTHREAD            0x01000000
12061 +#define VXC_NAMESPACE          0x02000000
12062 +
12063 +#endif /* _UAPI_VS_CONTEXT_H */
12064 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/context_cmd.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/context_cmd.h
12065 --- linux-3.13.1/include/uapi/vserver/context_cmd.h     1970-01-01 00:00:00.000000000 +0000
12066 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/context_cmd.h  2014-01-31 20:38:03.000000000 +0000
12067 @@ -0,0 +1,115 @@
12068 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12069 +#define _UAPI_VS_CONTEXT_CMD_H
12070 +
12071 +
12072 +/* vinfo commands */
12073 +
12074 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12075 +
12076 +
12077 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12078 +
12079 +struct vcmd_vx_info_v0 {
12080 +       uint32_t xid;
12081 +       uint32_t initpid;
12082 +       /* more to come */
12083 +};
12084 +
12085 +
12086 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12087 +
12088 +struct vcmd_ctx_stat_v0 {
12089 +       uint32_t usecnt;
12090 +       uint32_t tasks;
12091 +       /* more to come */
12092 +};
12093 +
12094 +
12095 +/* context commands */
12096 +
12097 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12098 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12099 +
12100 +struct vcmd_ctx_create {
12101 +       uint64_t flagword;
12102 +};
12103 +
12104 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12105 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12106 +
12107 +struct vcmd_ctx_migrate {
12108 +       uint64_t flagword;
12109 +};
12110 +
12111 +
12112 +
12113 +/* flag commands */
12114 +
12115 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12116 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12117 +
12118 +struct vcmd_ctx_flags_v0 {
12119 +       uint64_t flagword;
12120 +       uint64_t mask;
12121 +};
12122 +
12123 +
12124 +
12125 +/* context caps commands */
12126 +
12127 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12128 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12129 +
12130 +struct vcmd_ctx_caps_v1 {
12131 +       uint64_t ccaps;
12132 +       uint64_t cmask;
12133 +};
12134 +
12135 +
12136 +
12137 +/* bcaps commands */
12138 +
12139 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12140 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12141 +
12142 +struct vcmd_bcaps {
12143 +       uint64_t bcaps;
12144 +       uint64_t bmask;
12145 +};
12146 +
12147 +
12148 +
12149 +/* umask commands */
12150 +
12151 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12152 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12153 +
12154 +struct vcmd_umask {
12155 +       uint64_t umask;
12156 +       uint64_t mask;
12157 +};
12158 +
12159 +
12160 +
12161 +/* wmask commands */
12162 +
12163 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
12164 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
12165 +
12166 +struct vcmd_wmask {
12167 +       uint64_t wmask;
12168 +       uint64_t mask;
12169 +};
12170 +
12171 +
12172 +
12173 +/* OOM badness */
12174 +
12175 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12176 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12177 +
12178 +struct vcmd_badness_v0 {
12179 +       int64_t bias;
12180 +};
12181 +
12182 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12183 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/cvirt_cmd.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/cvirt_cmd.h
12184 --- linux-3.13.1/include/uapi/vserver/cvirt_cmd.h       1970-01-01 00:00:00.000000000 +0000
12185 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/cvirt_cmd.h    2014-01-31 20:38:03.000000000 +0000
12186 @@ -0,0 +1,41 @@
12187 +#ifndef _UAPI_VS_CVIRT_CMD_H
12188 +#define _UAPI_VS_CVIRT_CMD_H
12189 +
12190 +
12191 +/* virtual host info name commands */
12192 +
12193 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12194 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12195 +
12196 +struct vcmd_vhi_name_v0 {
12197 +       uint32_t field;
12198 +       char name[65];
12199 +};
12200 +
12201 +
12202 +enum vhi_name_field {
12203 +       VHIN_CONTEXT = 0,
12204 +       VHIN_SYSNAME,
12205 +       VHIN_NODENAME,
12206 +       VHIN_RELEASE,
12207 +       VHIN_VERSION,
12208 +       VHIN_MACHINE,
12209 +       VHIN_DOMAINNAME,
12210 +};
12211 +
12212 +
12213 +
12214 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12215 +
12216 +struct vcmd_virt_stat_v0 {
12217 +       uint64_t offset;
12218 +       uint64_t uptime;
12219 +       uint32_t nr_threads;
12220 +       uint32_t nr_running;
12221 +       uint32_t nr_uninterruptible;
12222 +       uint32_t nr_onhold;
12223 +       uint32_t nr_forks;
12224 +       uint32_t load[3];
12225 +};
12226 +
12227 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12228 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/debug_cmd.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/debug_cmd.h
12229 --- linux-3.13.1/include/uapi/vserver/debug_cmd.h       1970-01-01 00:00:00.000000000 +0000
12230 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/debug_cmd.h    2014-01-31 20:38:03.000000000 +0000
12231 @@ -0,0 +1,24 @@
12232 +#ifndef _UAPI_VS_DEBUG_CMD_H
12233 +#define _UAPI_VS_DEBUG_CMD_H
12234 +
12235 +
12236 +/* debug commands */
12237 +
12238 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12239 +
12240 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12241 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12242 +
12243 +struct  vcmd_read_history_v0 {
12244 +       uint32_t index;
12245 +       uint32_t count;
12246 +       char __user *data;
12247 +};
12248 +
12249 +struct  vcmd_read_monitor_v0 {
12250 +       uint32_t index;
12251 +       uint32_t count;
12252 +       char __user *data;
12253 +};
12254 +
12255 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12256 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/device.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/device.h
12257 --- linux-3.13.1/include/uapi/vserver/device.h  1970-01-01 00:00:00.000000000 +0000
12258 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/device.h       2014-01-31 20:38:03.000000000 +0000
12259 @@ -0,0 +1,12 @@
12260 +#ifndef _UAPI_VS_DEVICE_H
12261 +#define _UAPI_VS_DEVICE_H
12262 +
12263 +
12264 +#define DATTR_CREATE   0x00000001
12265 +#define DATTR_OPEN     0x00000002
12266 +
12267 +#define DATTR_REMAP    0x00000010
12268 +
12269 +#define DATTR_MASK     0x00000013
12270 +
12271 +#endif /* _UAPI_VS_DEVICE_H */
12272 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/device_cmd.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/device_cmd.h
12273 --- linux-3.13.1/include/uapi/vserver/device_cmd.h      1970-01-01 00:00:00.000000000 +0000
12274 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/device_cmd.h   2014-01-31 20:38:03.000000000 +0000
12275 @@ -0,0 +1,16 @@
12276 +#ifndef _UAPI_VS_DEVICE_CMD_H
12277 +#define _UAPI_VS_DEVICE_CMD_H
12278 +
12279 +
12280 +/*  device vserver commands */
12281 +
12282 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12283 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12284 +
12285 +struct vcmd_set_mapping_v0 {
12286 +       const char __user *device;
12287 +       const char __user *target;
12288 +       uint32_t flags;
12289 +};
12290 +
12291 +#endif /* _UAPI_VS_DEVICE_CMD_H */
12292 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/dlimit_cmd.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/dlimit_cmd.h
12293 --- linux-3.13.1/include/uapi/vserver/dlimit_cmd.h      1970-01-01 00:00:00.000000000 +0000
12294 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/dlimit_cmd.h   2014-01-31 20:38:03.000000000 +0000
12295 @@ -0,0 +1,67 @@
12296 +#ifndef _UAPI_VS_DLIMIT_CMD_H
12297 +#define _UAPI_VS_DLIMIT_CMD_H
12298 +
12299 +
12300 +/*  dlimit vserver commands */
12301 +
12302 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12303 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12304 +
12305 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12306 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12307 +
12308 +struct vcmd_ctx_dlimit_base_v0 {
12309 +       const char __user *name;
12310 +       uint32_t flags;
12311 +};
12312 +
12313 +struct vcmd_ctx_dlimit_v0 {
12314 +       const char __user *name;
12315 +       uint32_t space_used;                    /* used space in kbytes */
12316 +       uint32_t space_total;                   /* maximum space in kbytes */
12317 +       uint32_t inodes_used;                   /* used inodes */
12318 +       uint32_t inodes_total;                  /* maximum inodes */
12319 +       uint32_t reserved;                      /* reserved for root in % */
12320 +       uint32_t flags;
12321 +};
12322 +
12323 +#define CDLIM_UNSET            ((uint32_t)0UL)
12324 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12325 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12326 +
12327 +#define DLIME_UNIT     0
12328 +#define DLIME_KILO     1
12329 +#define DLIME_MEGA     2
12330 +#define DLIME_GIGA     3
12331 +
12332 +#define DLIMF_SHIFT    0x10
12333 +
12334 +#define DLIMS_USED     0
12335 +#define DLIMS_TOTAL    2
12336 +
12337 +static inline
12338 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12339 +{
12340 +       int exp = (flags & DLIMF_SHIFT) ?
12341 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12342 +       return ((uint64_t)val) << (10 * exp);
12343 +}
12344 +
12345 +static inline
12346 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12347 +{
12348 +       int exp = 0;
12349 +
12350 +       if (*flags & DLIMF_SHIFT) {
12351 +               while (val > (1LL << 32) && (exp < 3)) {
12352 +                       val >>= 10;
12353 +                       exp++;
12354 +               }
12355 +               *flags &= ~(DLIME_GIGA << shift);
12356 +               *flags |= exp << shift;
12357 +       } else
12358 +               val >>= 10;
12359 +       return val;
12360 +}
12361 +
12362 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
12363 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/inode.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/inode.h
12364 --- linux-3.13.1/include/uapi/vserver/inode.h   1970-01-01 00:00:00.000000000 +0000
12365 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/inode.h        2014-01-31 20:38:03.000000000 +0000
12366 @@ -0,0 +1,23 @@
12367 +#ifndef _UAPI_VS_INODE_H
12368 +#define _UAPI_VS_INODE_H
12369 +
12370 +
12371 +#define IATTR_TAG      0x01000000
12372 +
12373 +#define IATTR_ADMIN    0x00000001
12374 +#define IATTR_WATCH    0x00000002
12375 +#define IATTR_HIDE     0x00000004
12376 +#define IATTR_FLAGS    0x00000007
12377 +
12378 +#define IATTR_BARRIER  0x00010000
12379 +#define IATTR_IXUNLINK 0x00020000
12380 +#define IATTR_IMMUTABLE 0x00040000
12381 +#define IATTR_COW      0x00080000
12382 +
12383 +
12384 +/* inode ioctls */
12385 +
12386 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12387 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12388 +
12389 +#endif /* _UAPI_VS_INODE_H */
12390 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/inode_cmd.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/inode_cmd.h
12391 --- linux-3.13.1/include/uapi/vserver/inode_cmd.h       1970-01-01 00:00:00.000000000 +0000
12392 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/inode_cmd.h    2014-01-31 20:38:03.000000000 +0000
12393 @@ -0,0 +1,26 @@
12394 +#ifndef _UAPI_VS_INODE_CMD_H
12395 +#define _UAPI_VS_INODE_CMD_H
12396 +
12397 +
12398 +/*  inode vserver commands */
12399 +
12400 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12401 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12402 +
12403 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12404 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12405 +
12406 +struct vcmd_ctx_iattr_v1 {
12407 +       const char __user *name;
12408 +       uint32_t tag;
12409 +       uint32_t flags;
12410 +       uint32_t mask;
12411 +};
12412 +
12413 +struct vcmd_ctx_fiattr_v0 {
12414 +       uint32_t tag;
12415 +       uint32_t flags;
12416 +       uint32_t mask;
12417 +};
12418 +
12419 +#endif /* _UAPI_VS_INODE_CMD_H */
12420 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/limit.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/limit.h
12421 --- linux-3.13.1/include/uapi/vserver/limit.h   1970-01-01 00:00:00.000000000 +0000
12422 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/limit.h        2014-01-31 20:38:03.000000000 +0000
12423 @@ -0,0 +1,14 @@
12424 +#ifndef _UAPI_VS_LIMIT_H
12425 +#define _UAPI_VS_LIMIT_H
12426 +
12427 +
12428 +#define VLIMIT_NSOCK   16
12429 +#define VLIMIT_OPENFD  17
12430 +#define VLIMIT_ANON    18
12431 +#define VLIMIT_SHMEM   19
12432 +#define VLIMIT_SEMARY  20
12433 +#define VLIMIT_NSEMS   21
12434 +#define VLIMIT_DENTRY  22
12435 +#define VLIMIT_MAPPED  23
12436 +
12437 +#endif /* _UAPI_VS_LIMIT_H */
12438 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/limit_cmd.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/limit_cmd.h
12439 --- linux-3.13.1/include/uapi/vserver/limit_cmd.h       1970-01-01 00:00:00.000000000 +0000
12440 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/limit_cmd.h    2014-01-31 20:38:03.000000000 +0000
12441 @@ -0,0 +1,40 @@
12442 +#ifndef _UAPI_VS_LIMIT_CMD_H
12443 +#define _UAPI_VS_LIMIT_CMD_H
12444 +
12445 +
12446 +/*  rlimit vserver commands */
12447 +
12448 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12449 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12450 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12451 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12452 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12453 +
12454 +struct vcmd_ctx_rlimit_v0 {
12455 +       uint32_t id;
12456 +       uint64_t minimum;
12457 +       uint64_t softlimit;
12458 +       uint64_t maximum;
12459 +};
12460 +
12461 +struct vcmd_ctx_rlimit_mask_v0 {
12462 +       uint32_t minimum;
12463 +       uint32_t softlimit;
12464 +       uint32_t maximum;
12465 +};
12466 +
12467 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12468 +
12469 +struct vcmd_rlimit_stat_v0 {
12470 +       uint32_t id;
12471 +       uint32_t hits;
12472 +       uint64_t value;
12473 +       uint64_t minimum;
12474 +       uint64_t maximum;
12475 +};
12476 +
12477 +#define CRLIM_UNSET            (0ULL)
12478 +#define CRLIM_INFINITY         (~0ULL)
12479 +#define CRLIM_KEEP             (~1ULL)
12480 +
12481 +#endif /* _UAPI_VS_LIMIT_CMD_H */
12482 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/monitor.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/monitor.h
12483 --- linux-3.13.1/include/uapi/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
12484 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/monitor.h      2014-01-31 20:38:03.000000000 +0000
12485 @@ -0,0 +1,96 @@
12486 +#ifndef _UAPI_VS_MONITOR_H
12487 +#define _UAPI_VS_MONITOR_H
12488 +
12489 +#include <linux/types.h>
12490 +
12491 +
12492 +enum {
12493 +       VXM_UNUSED = 0,
12494 +
12495 +       VXM_SYNC = 0x10,
12496 +
12497 +       VXM_UPDATE = 0x20,
12498 +       VXM_UPDATE_1,
12499 +       VXM_UPDATE_2,
12500 +
12501 +       VXM_RQINFO_1 = 0x24,
12502 +       VXM_RQINFO_2,
12503 +
12504 +       VXM_ACTIVATE = 0x40,
12505 +       VXM_DEACTIVATE,
12506 +       VXM_IDLE,
12507 +
12508 +       VXM_HOLD = 0x44,
12509 +       VXM_UNHOLD,
12510 +
12511 +       VXM_MIGRATE = 0x48,
12512 +       VXM_RESCHED,
12513 +
12514 +       /* all other bits are flags */
12515 +       VXM_SCHED = 0x80,
12516 +};
12517 +
12518 +struct _vxm_update_1 {
12519 +       uint32_t tokens_max;
12520 +       uint32_t fill_rate;
12521 +       uint32_t interval;
12522 +};
12523 +
12524 +struct _vxm_update_2 {
12525 +       uint32_t tokens_min;
12526 +       uint32_t fill_rate;
12527 +       uint32_t interval;
12528 +};
12529 +
12530 +struct _vxm_rqinfo_1 {
12531 +       uint16_t running;
12532 +       uint16_t onhold;
12533 +       uint16_t iowait;
12534 +       uint16_t uintr;
12535 +       uint32_t idle_tokens;
12536 +};
12537 +
12538 +struct _vxm_rqinfo_2 {
12539 +       uint32_t norm_time;
12540 +       uint32_t idle_time;
12541 +       uint32_t idle_skip;
12542 +};
12543 +
12544 +struct _vxm_sched {
12545 +       uint32_t tokens;
12546 +       uint32_t norm_time;
12547 +       uint32_t idle_time;
12548 +};
12549 +
12550 +struct _vxm_task {
12551 +       uint16_t pid;
12552 +       uint16_t state;
12553 +};
12554 +
12555 +struct _vxm_event {
12556 +       uint32_t jif;
12557 +       union {
12558 +               uint32_t seq;
12559 +               uint32_t sec;
12560 +       };
12561 +       union {
12562 +               uint32_t tokens;
12563 +               uint32_t nsec;
12564 +               struct _vxm_task tsk;
12565 +       };
12566 +};
12567 +
12568 +struct _vx_mon_entry {
12569 +       uint16_t type;
12570 +       uint16_t xid;
12571 +       union {
12572 +               struct _vxm_event ev;
12573 +               struct _vxm_sched sd;
12574 +               struct _vxm_update_1 u1;
12575 +               struct _vxm_update_2 u2;
12576 +               struct _vxm_rqinfo_1 q1;
12577 +               struct _vxm_rqinfo_2 q2;
12578 +       };
12579 +};
12580 +
12581 +#endif /* _UAPI_VS_MONITOR_H */
12582 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/network.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/network.h
12583 --- linux-3.13.1/include/uapi/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
12584 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/network.h      2014-01-31 20:38:03.000000000 +0000
12585 @@ -0,0 +1,76 @@
12586 +#ifndef _UAPI_VS_NETWORK_H
12587 +#define _UAPI_VS_NETWORK_H
12588 +
12589 +#include <linux/types.h>
12590 +
12591 +
12592 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12593 +
12594 +
12595 +/* network flags */
12596 +
12597 +#define NXF_INFO_PRIVATE       0x00000008
12598 +
12599 +#define NXF_SINGLE_IP          0x00000100
12600 +#define NXF_LBACK_REMAP                0x00000200
12601 +#define NXF_LBACK_ALLOW                0x00000400
12602 +
12603 +#define NXF_HIDE_NETIF         0x02000000
12604 +#define NXF_HIDE_LBACK         0x04000000
12605 +
12606 +#define NXF_STATE_SETUP                (1ULL << 32)
12607 +#define NXF_STATE_ADMIN                (1ULL << 34)
12608 +
12609 +#define NXF_SC_HELPER          (1ULL << 36)
12610 +#define NXF_PERSISTENT         (1ULL << 38)
12611 +
12612 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12613 +
12614 +
12615 +#define        NXF_INIT_SET            (__nxf_init_set())
12616 +
12617 +static inline uint64_t __nxf_init_set(void) {
12618 +       return    NXF_STATE_ADMIN
12619 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12620 +               | NXF_LBACK_REMAP
12621 +               | NXF_HIDE_LBACK
12622 +#endif
12623 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12624 +               | NXF_SINGLE_IP
12625 +#endif
12626 +               | NXF_HIDE_NETIF;
12627 +}
12628 +
12629 +
12630 +/* network caps */
12631 +
12632 +#define NXC_TUN_CREATE         0x00000001
12633 +
12634 +#define NXC_RAW_ICMP           0x00000100
12635 +
12636 +#define NXC_MULTICAST          0x00001000
12637 +
12638 +
12639 +/* address types */
12640 +
12641 +#define NXA_TYPE_IPV4          0x0001
12642 +#define NXA_TYPE_IPV6          0x0002
12643 +
12644 +#define NXA_TYPE_NONE          0x0000
12645 +#define NXA_TYPE_ANY           0x00FF
12646 +
12647 +#define NXA_TYPE_ADDR          0x0010
12648 +#define NXA_TYPE_MASK          0x0020
12649 +#define NXA_TYPE_RANGE         0x0040
12650 +
12651 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12652 +
12653 +#define NXA_MOD_BCAST          0x0100
12654 +#define NXA_MOD_LBACK          0x0200
12655 +
12656 +#define NXA_LOOPBACK           0x1000
12657 +
12658 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12659 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12660 +
12661 +#endif /* _UAPI_VS_NETWORK_H */
12662 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/network_cmd.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/network_cmd.h
12663 --- linux-3.13.1/include/uapi/vserver/network_cmd.h     1970-01-01 00:00:00.000000000 +0000
12664 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/network_cmd.h  2014-01-31 20:38:03.000000000 +0000
12665 @@ -0,0 +1,123 @@
12666 +#ifndef _UAPI_VS_NETWORK_CMD_H
12667 +#define _UAPI_VS_NETWORK_CMD_H
12668 +
12669 +
12670 +/* vinfo commands */
12671 +
12672 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12673 +
12674 +
12675 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12676 +
12677 +struct vcmd_nx_info_v0 {
12678 +       uint32_t nid;
12679 +       /* more to come */
12680 +};
12681 +
12682 +
12683 +#include <linux/in.h>
12684 +#include <linux/in6.h>
12685 +
12686 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12687 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12688 +
12689 +struct  vcmd_net_create {
12690 +       uint64_t flagword;
12691 +};
12692 +
12693 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12694 +
12695 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12696 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12697 +
12698 +struct vcmd_net_addr_v0 {
12699 +       uint16_t type;
12700 +       uint16_t count;
12701 +       struct in_addr ip[4];
12702 +       struct in_addr mask[4];
12703 +};
12704 +
12705 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
12706 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
12707 +
12708 +struct vcmd_net_addr_ipv4_v1 {
12709 +       uint16_t type;
12710 +       uint16_t flags;
12711 +       struct in_addr ip;
12712 +       struct in_addr mask;
12713 +};
12714 +
12715 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
12716 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
12717 +
12718 +struct vcmd_net_addr_ipv4_v2 {
12719 +       uint16_t type;
12720 +       uint16_t flags;
12721 +       struct in_addr ip;
12722 +       struct in_addr ip2;
12723 +       struct in_addr mask;
12724 +};
12725 +
12726 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12727 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12728 +
12729 +struct vcmd_net_addr_ipv6_v1 {
12730 +       uint16_t type;
12731 +       uint16_t flags;
12732 +       uint32_t prefix;
12733 +       struct in6_addr ip;
12734 +       struct in6_addr mask;
12735 +};
12736 +
12737 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12738 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12739 +
12740 +struct vcmd_match_ipv4_v0 {
12741 +       uint16_t type;
12742 +       uint16_t flags;
12743 +       uint16_t parent;
12744 +       uint16_t prefix;
12745 +       struct in_addr ip;
12746 +       struct in_addr ip2;
12747 +       struct in_addr mask;
12748 +};
12749 +
12750 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12751 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12752 +
12753 +struct vcmd_match_ipv6_v0 {
12754 +       uint16_t type;
12755 +       uint16_t flags;
12756 +       uint16_t parent;
12757 +       uint16_t prefix;
12758 +       struct in6_addr ip;
12759 +       struct in6_addr ip2;
12760 +       struct in6_addr mask;
12761 +};
12762 +
12763 +
12764 +
12765 +
12766 +/* flag commands */
12767 +
12768 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12769 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12770 +
12771 +struct vcmd_net_flags_v0 {
12772 +       uint64_t flagword;
12773 +       uint64_t mask;
12774 +};
12775 +
12776 +
12777 +
12778 +/* network caps commands */
12779 +
12780 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12781 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12782 +
12783 +struct vcmd_net_caps_v0 {
12784 +       uint64_t ncaps;
12785 +       uint64_t cmask;
12786 +};
12787 +
12788 +#endif /* _UAPI_VS_NETWORK_CMD_H */
12789 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/sched_cmd.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/sched_cmd.h
12790 --- linux-3.13.1/include/uapi/vserver/sched_cmd.h       1970-01-01 00:00:00.000000000 +0000
12791 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/sched_cmd.h    2014-01-31 20:38:03.000000000 +0000
12792 @@ -0,0 +1,13 @@
12793 +#ifndef _UAPI_VS_SCHED_CMD_H
12794 +#define _UAPI_VS_SCHED_CMD_H
12795 +
12796 +
12797 +struct vcmd_prio_bias {
12798 +       int32_t cpu_id;
12799 +       int32_t prio_bias;
12800 +};
12801 +
12802 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
12803 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
12804 +
12805 +#endif /* _UAPI_VS_SCHED_CMD_H */
12806 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/signal_cmd.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/signal_cmd.h
12807 --- linux-3.13.1/include/uapi/vserver/signal_cmd.h      1970-01-01 00:00:00.000000000 +0000
12808 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/signal_cmd.h   2014-01-31 20:38:03.000000000 +0000
12809 @@ -0,0 +1,31 @@
12810 +#ifndef _UAPI_VS_SIGNAL_CMD_H
12811 +#define _UAPI_VS_SIGNAL_CMD_H
12812 +
12813 +
12814 +/*  signalling vserver commands */
12815 +
12816 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12817 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12818 +
12819 +struct vcmd_ctx_kill_v0 {
12820 +       int32_t pid;
12821 +       int32_t sig;
12822 +};
12823 +
12824 +struct vcmd_wait_exit_v0 {
12825 +       int32_t reboot_cmd;
12826 +       int32_t exit_code;
12827 +};
12828 +
12829 +
12830 +/*  process alteration commands */
12831 +
12832 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12833 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12834 +
12835 +struct vcmd_pflags_v0 {
12836 +       uint32_t flagword;
12837 +       uint32_t mask;
12838 +};
12839 +
12840 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
12841 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/space_cmd.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/space_cmd.h
12842 --- linux-3.13.1/include/uapi/vserver/space_cmd.h       1970-01-01 00:00:00.000000000 +0000
12843 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/space_cmd.h    2014-01-31 20:38:03.000000000 +0000
12844 @@ -0,0 +1,28 @@
12845 +#ifndef _UAPI_VS_SPACE_CMD_H
12846 +#define _UAPI_VS_SPACE_CMD_H
12847 +
12848 +
12849 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12850 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12851 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12852 +
12853 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12854 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12855 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12856 +
12857 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12858 +
12859 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12860 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12861 +
12862 +
12863 +struct vcmd_space_mask_v1 {
12864 +       uint64_t mask;
12865 +};
12866 +
12867 +struct vcmd_space_mask_v2 {
12868 +       uint64_t mask;
12869 +       uint32_t index;
12870 +};
12871 +
12872 +#endif /* _UAPI_VS_SPACE_CMD_H */
12873 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/switch.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/switch.h
12874 --- linux-3.13.1/include/uapi/vserver/switch.h  1970-01-01 00:00:00.000000000 +0000
12875 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/switch.h       2014-01-31 20:38:03.000000000 +0000
12876 @@ -0,0 +1,90 @@
12877 +#ifndef _UAPI_VS_SWITCH_H
12878 +#define _UAPI_VS_SWITCH_H
12879 +
12880 +#include <linux/types.h>
12881 +
12882 +
12883 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12884 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12885 +#define VC_VERSION(c)          ((c) & 0xFFF)
12886 +
12887 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12888 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12889 +
12890 +/*
12891 +
12892 +  Syscall Matrix V2.8
12893 +
12894 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12895 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12896 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12897 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12898 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
12899 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
12900 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12901 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
12902 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
12903 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12904 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
12905 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
12906 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12907 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
12908 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
12909 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12910 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
12911 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
12912 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12913 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
12914 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
12915 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12916 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
12917 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
12918 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12919 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
12920 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
12921 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12922 +
12923 +*/
12924 +
12925 +#define VC_CAT_VERSION         0
12926 +
12927 +#define VC_CAT_VSETUP          1
12928 +#define VC_CAT_VHOST           2
12929 +
12930 +#define VC_CAT_DEVICE          6
12931 +
12932 +#define VC_CAT_VPROC           9
12933 +#define VC_CAT_PROCALT         10
12934 +#define VC_CAT_PROCMIG         11
12935 +#define VC_CAT_PROCTRL         12
12936 +
12937 +#define VC_CAT_SCHED           14
12938 +#define VC_CAT_MEMCTRL         20
12939 +
12940 +#define VC_CAT_VNET            25
12941 +#define VC_CAT_NETALT          26
12942 +#define VC_CAT_NETMIG          27
12943 +#define VC_CAT_NETCTRL         28
12944 +
12945 +#define VC_CAT_TAGMIG          35
12946 +#define VC_CAT_DLIMIT          36
12947 +#define VC_CAT_INODE           38
12948 +
12949 +#define VC_CAT_VSTAT           40
12950 +#define VC_CAT_VINFO           46
12951 +#define VC_CAT_EVENT           48
12952 +
12953 +#define VC_CAT_FLAGS           52
12954 +#define VC_CAT_VSPACE          54
12955 +#define VC_CAT_DEBUG           56
12956 +#define VC_CAT_RLIMIT          60
12957 +
12958 +#define VC_CAT_SYSTEST         61
12959 +#define VC_CAT_COMPAT          63
12960 +
12961 +/*  query version */
12962 +
12963 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
12964 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
12965 +
12966 +#endif /* _UAPI_VS_SWITCH_H */
12967 diff -NurpP --minimal linux-3.13.1/include/uapi/vserver/tag_cmd.h linux-3.13.1-vs2.3.6.10/include/uapi/vserver/tag_cmd.h
12968 --- linux-3.13.1/include/uapi/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
12969 +++ linux-3.13.1-vs2.3.6.10/include/uapi/vserver/tag_cmd.h      2014-01-31 20:38:03.000000000 +0000
12970 @@ -0,0 +1,14 @@
12971 +#ifndef _UAPI_VS_TAG_CMD_H
12972 +#define _UAPI_VS_TAG_CMD_H
12973 +
12974 +
12975 +/* vinfo commands */
12976 +
12977 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
12978 +
12979 +
12980 +/* context commands */
12981 +
12982 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
12983 +
12984 +#endif /* _UAPI_VS_TAG_CMD_H */
12985 diff -NurpP --minimal linux-3.13.1/init/Kconfig linux-3.13.1-vs2.3.6.10/init/Kconfig
12986 --- linux-3.13.1/init/Kconfig   2014-01-22 20:39:12.000000000 +0000
12987 +++ linux-3.13.1-vs2.3.6.10/init/Kconfig        2014-01-31 21:05:27.000000000 +0000
12988 @@ -855,6 +855,7 @@ config NUMA_BALANCING
12989  menuconfig CGROUPS
12990         boolean "Control Group support"
12991         depends on EVENTFD
12992 +       default y
12993         help
12994           This option adds support for grouping sets of processes together, for
12995           use with process control subsystems such as Cpusets, CFS, memory
12996 @@ -1117,6 +1118,7 @@ config IPC_NS
12997  config USER_NS
12998         bool "User namespace"
12999         select UIDGID_STRICT_TYPE_CHECKS
13000 +       depends on VSERVER_DISABLED
13001  
13002         default n
13003         help
13004 diff -NurpP --minimal linux-3.13.1/init/main.c linux-3.13.1-vs2.3.6.10/init/main.c
13005 --- linux-3.13.1/init/main.c    2014-01-22 20:39:12.000000000 +0000
13006 +++ linux-3.13.1-vs2.3.6.10/init/main.c 2014-01-31 20:38:03.000000000 +0000
13007 @@ -77,6 +77,7 @@
13008  #include <linux/sched_clock.h>
13009  #include <linux/context_tracking.h>
13010  #include <linux/random.h>
13011 +#include <linux/vserver/percpu.h>
13012  
13013  #include <asm/io.h>
13014  #include <asm/bugs.h>
13015 diff -NurpP --minimal linux-3.13.1/ipc/mqueue.c linux-3.13.1-vs2.3.6.10/ipc/mqueue.c
13016 --- linux-3.13.1/ipc/mqueue.c   2014-01-22 20:39:12.000000000 +0000
13017 +++ linux-3.13.1-vs2.3.6.10/ipc/mqueue.c        2014-01-31 20:38:03.000000000 +0000
13018 @@ -35,6 +35,8 @@
13019  #include <linux/ipc_namespace.h>
13020  #include <linux/user_namespace.h>
13021  #include <linux/slab.h>
13022 +#include <linux/vs_context.h>
13023 +#include <linux/vs_limit.h>
13024  
13025  #include <net/sock.h>
13026  #include "util.h"
13027 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13028         struct pid* notify_owner;
13029         struct user_namespace *notify_user_ns;
13030         struct user_struct *user;       /* user who created, for accounting */
13031 +       struct vx_info *vxi;
13032         struct sock *notify_sock;
13033         struct sk_buff *notify_cookie;
13034  
13035 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13036         if (S_ISREG(mode)) {
13037                 struct mqueue_inode_info *info;
13038                 unsigned long mq_bytes, mq_treesize;
13039 +               struct vx_info *vxi = current_vx_info();
13040  
13041                 inode->i_fop = &mqueue_file_operations;
13042                 inode->i_size = FILENT_SIZE;
13043 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13044                 info->notify_user_ns = NULL;
13045                 info->qsize = 0;
13046                 info->user = NULL;      /* set when all is ok */
13047 +               info->vxi = NULL;
13048                 info->msg_tree = RB_ROOT;
13049                 info->node_cache = NULL;
13050                 memset(&info->attr, 0, sizeof(info->attr));
13051 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13052  
13053                 spin_lock(&mq_lock);
13054                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13055 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13056 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13057 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13058                         spin_unlock(&mq_lock);
13059                         /* mqueue_evict_inode() releases info->messages */
13060                         ret = -EMFILE;
13061                         goto out_inode;
13062                 }
13063                 u->mq_bytes += mq_bytes;
13064 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13065                 spin_unlock(&mq_lock);
13066  
13067                 /* all is ok */
13068                 info->user = get_uid(u);
13069 +               info->vxi = get_vx_info(vxi);
13070         } else if (S_ISDIR(mode)) {
13071                 inc_nlink(inode);
13072                 /* Some things misbehave if size == 0 on a directory */
13073 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13074  
13075         user = info->user;
13076         if (user) {
13077 +               struct vx_info *vxi = info->vxi;
13078 +
13079                 spin_lock(&mq_lock);
13080                 user->mq_bytes -= mq_bytes;
13081 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13082                 /*
13083                  * get_ns_from_inode() ensures that the
13084                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13085 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13086                 if (ipc_ns)
13087                         ipc_ns->mq_queues_count--;
13088                 spin_unlock(&mq_lock);
13089 +               put_vx_info(vxi);
13090                 free_uid(user);
13091         }
13092         if (ipc_ns)
13093 diff -NurpP --minimal linux-3.13.1/ipc/msg.c linux-3.13.1-vs2.3.6.10/ipc/msg.c
13094 --- linux-3.13.1/ipc/msg.c      2013-11-25 15:47:03.000000000 +0000
13095 +++ linux-3.13.1-vs2.3.6.10/ipc/msg.c   2014-01-31 20:38:03.000000000 +0000
13096 @@ -37,6 +37,7 @@
13097  #include <linux/rwsem.h>
13098  #include <linux/nsproxy.h>
13099  #include <linux/ipc_namespace.h>
13100 +#include <linux/vs_base.h>
13101  
13102  #include <asm/current.h>
13103  #include <asm/uaccess.h>
13104 @@ -194,6 +195,7 @@ static int newque(struct ipc_namespace *
13105  
13106         msq->q_perm.mode = msgflg & S_IRWXUGO;
13107         msq->q_perm.key = key;
13108 +       msq->q_perm.xid = vx_current_xid();
13109  
13110         msq->q_perm.security = NULL;
13111         retval = security_msg_queue_alloc(msq);
13112 diff -NurpP --minimal linux-3.13.1/ipc/sem.c linux-3.13.1-vs2.3.6.10/ipc/sem.c
13113 --- linux-3.13.1/ipc/sem.c      2013-11-25 15:47:03.000000000 +0000
13114 +++ linux-3.13.1-vs2.3.6.10/ipc/sem.c   2014-01-31 20:38:03.000000000 +0000
13115 @@ -86,6 +86,8 @@
13116  #include <linux/rwsem.h>
13117  #include <linux/nsproxy.h>
13118  #include <linux/ipc_namespace.h>
13119 +#include <linux/vs_base.h>
13120 +#include <linux/vs_limit.h>
13121  
13122  #include <asm/uaccess.h>
13123  #include "util.h"
13124 @@ -500,6 +502,7 @@ static int newary(struct ipc_namespace *
13125  
13126         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13127         sma->sem_perm.key = key;
13128 +       sma->sem_perm.xid = vx_current_xid();
13129  
13130         sma->sem_perm.security = NULL;
13131         retval = security_sem_alloc(sma);
13132 @@ -514,6 +517,9 @@ static int newary(struct ipc_namespace *
13133                 return id;
13134         }
13135         ns->used_sems += nsems;
13136 +       /* FIXME: obsoleted? */
13137 +       vx_semary_inc(sma);
13138 +       vx_nsems_add(sma, nsems);
13139  
13140         sma->sem_base = (struct sem *) &sma[1];
13141  
13142 @@ -1103,6 +1109,9 @@ static void freeary(struct ipc_namespace
13143  
13144         wake_up_sem_queue_do(&tasks);
13145         ns->used_sems -= sma->sem_nsems;
13146 +       /* FIXME: obsoleted? */
13147 +       vx_nsems_sub(sma, sma->sem_nsems);
13148 +       vx_semary_dec(sma);
13149         ipc_rcu_putref(sma, sem_rcu_free);
13150  }
13151  
13152 diff -NurpP --minimal linux-3.13.1/ipc/shm.c linux-3.13.1-vs2.3.6.10/ipc/shm.c
13153 --- linux-3.13.1/ipc/shm.c      2014-01-22 20:39:12.000000000 +0000
13154 +++ linux-3.13.1-vs2.3.6.10/ipc/shm.c   2014-01-31 20:38:03.000000000 +0000
13155 @@ -42,6 +42,8 @@
13156  #include <linux/nsproxy.h>
13157  #include <linux/mount.h>
13158  #include <linux/ipc_namespace.h>
13159 +#include <linux/vs_context.h>
13160 +#include <linux/vs_limit.h>
13161  
13162  #include <asm/uaccess.h>
13163  
13164 @@ -209,10 +211,14 @@ static void shm_open(struct vm_area_stru
13165  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13166  {
13167         struct file *shm_file;
13168 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13169 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13170  
13171         shm_file = shp->shm_file;
13172         shp->shm_file = NULL;
13173 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13174 +       vx_ipcshm_sub(vxi, shp, numpages);
13175 +       ns->shm_tot -= numpages;
13176 +
13177         shm_rmid(ns, shp);
13178         shm_unlock(shp);
13179         if (!is_file_hugepages(shm_file))
13180 @@ -220,6 +226,7 @@ static void shm_destroy(struct ipc_names
13181         else if (shp->mlock_user)
13182                 user_shm_unlock(file_inode(shm_file)->i_size, shp->mlock_user);
13183         fput(shm_file);
13184 +       put_vx_info(vxi);
13185         ipc_rcu_putref(shp, shm_rcu_free);
13186  }
13187  
13188 @@ -497,11 +504,15 @@ static int newseg(struct ipc_namespace *
13189         if (ns->shm_tot + numpages > ns->shm_ctlall)
13190                 return -ENOSPC;
13191  
13192 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13193 +               return -ENOSPC;
13194 +
13195         shp = ipc_rcu_alloc(sizeof(*shp));
13196         if (!shp)
13197                 return -ENOMEM;
13198  
13199         shp->shm_perm.key = key;
13200 +       shp->shm_perm.xid = vx_current_xid();
13201         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13202         shp->mlock_user = NULL;
13203  
13204 @@ -570,6 +581,7 @@ static int newseg(struct ipc_namespace *
13205  
13206         ipc_unlock_object(&shp->shm_perm);
13207         rcu_read_unlock();
13208 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13209         return error;
13210  
13211  no_id:
13212 diff -NurpP --minimal linux-3.13.1/kernel/Makefile linux-3.13.1-vs2.3.6.10/kernel/Makefile
13213 --- linux-3.13.1/kernel/Makefile        2014-01-22 20:39:12.000000000 +0000
13214 +++ linux-3.13.1-vs2.3.6.10/kernel/Makefile     2014-01-31 21:36:22.000000000 +0000
13215 @@ -25,6 +25,7 @@ obj-y += printk/
13216  obj-y += cpu/
13217  obj-y += irq/
13218  obj-y += rcu/
13219 +obj-y += vserver/
13220  
13221  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13222  obj-$(CONFIG_FREEZER) += freezer.o
13223 diff -NurpP --minimal linux-3.13.1/kernel/auditsc.c linux-3.13.1-vs2.3.6.10/kernel/auditsc.c
13224 --- linux-3.13.1/kernel/auditsc.c       2014-01-22 20:39:12.000000000 +0000
13225 +++ linux-3.13.1-vs2.3.6.10/kernel/auditsc.c    2014-01-31 21:07:11.000000000 +0000
13226 @@ -1956,7 +1956,7 @@ static int audit_set_loginuid_perm(kuid_
13227         if (is_audit_feature_set(AUDIT_FEATURE_LOGINUID_IMMUTABLE))
13228                 return -EPERM;
13229         /* it is set, you need permission */
13230 -       if (!capable(CAP_AUDIT_CONTROL))
13231 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13232                 return -EPERM;
13233         /* reject if this is not an unset and we don't allow that */
13234         if (is_audit_feature_set(AUDIT_FEATURE_ONLY_UNSET_LOGINUID) && uid_valid(loginuid))
13235 diff -NurpP --minimal linux-3.13.1/kernel/capability.c linux-3.13.1-vs2.3.6.10/kernel/capability.c
13236 --- linux-3.13.1/kernel/capability.c    2013-11-25 15:47:03.000000000 +0000
13237 +++ linux-3.13.1-vs2.3.6.10/kernel/capability.c 2014-01-31 20:38:03.000000000 +0000
13238 @@ -15,6 +15,7 @@
13239  #include <linux/syscalls.h>
13240  #include <linux/pid_namespace.h>
13241  #include <linux/user_namespace.h>
13242 +#include <linux/vs_context.h>
13243  #include <asm/uaccess.h>
13244  
13245  /*
13246 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13247         return 0;
13248  }
13249  
13250 +
13251  /*
13252   * The only thing that can change the capabilities of the current
13253   * process is the current process. As such, we can't be in this code
13254 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13255         return (ret == 0);
13256  }
13257  
13258 +#include <linux/vserver/base.h>
13259 +
13260  /**
13261   * has_capability_noaudit - Does a task have a capability (unaudited) in the
13262   * initial user ns
13263 diff -NurpP --minimal linux-3.13.1/kernel/compat.c linux-3.13.1-vs2.3.6.10/kernel/compat.c
13264 --- linux-3.13.1/kernel/compat.c        2013-07-14 17:01:34.000000000 +0000
13265 +++ linux-3.13.1-vs2.3.6.10/kernel/compat.c     2014-01-31 20:38:03.000000000 +0000
13266 @@ -27,6 +27,7 @@
13267  #include <linux/times.h>
13268  #include <linux/ptrace.h>
13269  #include <linux/gfp.h>
13270 +#include <linux/vs_time.h>
13271  
13272  #include <asm/uaccess.h>
13273  
13274 @@ -1040,7 +1041,7 @@ asmlinkage long compat_sys_stime(compat_
13275         if (err)
13276                 return err;
13277  
13278 -       do_settimeofday(&tv);
13279 +       vx_settimeofday(&tv);
13280         return 0;
13281  }
13282  
13283 diff -NurpP --minimal linux-3.13.1/kernel/cred.c linux-3.13.1-vs2.3.6.10/kernel/cred.c
13284 --- linux-3.13.1/kernel/cred.c  2013-02-19 13:58:56.000000000 +0000
13285 +++ linux-3.13.1-vs2.3.6.10/kernel/cred.c       2014-01-31 20:38:03.000000000 +0000
13286 @@ -56,31 +56,6 @@ struct cred init_cred = {
13287         .group_info             = &init_groups,
13288  };
13289  
13290 -static inline void set_cred_subscribers(struct cred *cred, int n)
13291 -{
13292 -#ifdef CONFIG_DEBUG_CREDENTIALS
13293 -       atomic_set(&cred->subscribers, n);
13294 -#endif
13295 -}
13296 -
13297 -static inline int read_cred_subscribers(const struct cred *cred)
13298 -{
13299 -#ifdef CONFIG_DEBUG_CREDENTIALS
13300 -       return atomic_read(&cred->subscribers);
13301 -#else
13302 -       return 0;
13303 -#endif
13304 -}
13305 -
13306 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
13307 -{
13308 -#ifdef CONFIG_DEBUG_CREDENTIALS
13309 -       struct cred *cred = (struct cred *) _cred;
13310 -
13311 -       atomic_add(n, &cred->subscribers);
13312 -#endif
13313 -}
13314 -
13315  /*
13316   * The RCU callback to actually dispose of a set of credentials
13317   */
13318 @@ -232,21 +207,16 @@ error:
13319   *
13320   * Call commit_creds() or abort_creds() to clean up.
13321   */
13322 -struct cred *prepare_creds(void)
13323 +struct cred *__prepare_creds(const struct cred *old)
13324  {
13325 -       struct task_struct *task = current;
13326 -       const struct cred *old;
13327         struct cred *new;
13328  
13329 -       validate_process_creds();
13330 -
13331         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13332         if (!new)
13333                 return NULL;
13334  
13335         kdebug("prepare_creds() alloc %p", new);
13336  
13337 -       old = task->cred;
13338         memcpy(new, old, sizeof(struct cred));
13339  
13340         atomic_set(&new->usage, 1);
13341 @@ -275,6 +245,13 @@ error:
13342         abort_creds(new);
13343         return NULL;
13344  }
13345 +
13346 +struct cred *prepare_creds(void)
13347 +{
13348 +       validate_process_creds();
13349 +
13350 +       return __prepare_creds(current->cred);
13351 +}
13352  EXPORT_SYMBOL(prepare_creds);
13353  
13354  /*
13355 diff -NurpP --minimal linux-3.13.1/kernel/exit.c linux-3.13.1-vs2.3.6.10/kernel/exit.c
13356 --- linux-3.13.1/kernel/exit.c  2013-11-25 15:45:07.000000000 +0000
13357 +++ linux-3.13.1-vs2.3.6.10/kernel/exit.c       2014-01-31 20:38:03.000000000 +0000
13358 @@ -48,6 +48,10 @@
13359  #include <linux/fs_struct.h>
13360  #include <linux/init_task.h>
13361  #include <linux/perf_event.h>
13362 +#include <linux/vs_limit.h>
13363 +#include <linux/vs_context.h>
13364 +#include <linux/vs_network.h>
13365 +#include <linux/vs_pid.h>
13366  #include <trace/events/sched.h>
13367  #include <linux/hw_breakpoint.h>
13368  #include <linux/oom.h>
13369 @@ -503,15 +507,25 @@ static struct task_struct *find_new_reap
13370         __acquires(&tasklist_lock)
13371  {
13372         struct pid_namespace *pid_ns = task_active_pid_ns(father);
13373 -       struct task_struct *thread;
13374 +       struct vx_info *vxi = task_get_vx_info(father);
13375 +       struct task_struct *thread = father;
13376 +       struct task_struct *reaper;
13377  
13378 -       thread = father;
13379         while_each_thread(father, thread) {
13380                 if (thread->flags & PF_EXITING)
13381                         continue;
13382                 if (unlikely(pid_ns->child_reaper == father))
13383                         pid_ns->child_reaper = thread;
13384 -               return thread;
13385 +               reaper = thread;
13386 +               goto out_put;
13387 +       }
13388 +
13389 +       reaper = pid_ns->child_reaper;
13390 +       if (vxi) {
13391 +               BUG_ON(!vxi->vx_reaper);
13392 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
13393 +                   vxi->vx_reaper != father)
13394 +                       reaper = vxi->vx_reaper;
13395         }
13396  
13397         if (unlikely(pid_ns->child_reaper == father)) {
13398 @@ -549,7 +563,9 @@ static struct task_struct *find_new_reap
13399                 }
13400         }
13401  
13402 -       return pid_ns->child_reaper;
13403 +out_put:
13404 +       put_vx_info(vxi);
13405 +       return reaper;
13406  }
13407  
13408  /*
13409 @@ -600,10 +616,15 @@ static void forget_original_parent(struc
13410         list_for_each_entry_safe(p, n, &father->children, sibling) {
13411                 struct task_struct *t = p;
13412                 do {
13413 -                       t->real_parent = reaper;
13414 +                       struct task_struct *new_parent = reaper;
13415 +
13416 +                       if (unlikely(p == reaper))
13417 +                               new_parent = task_active_pid_ns(p)->child_reaper;
13418 +
13419 +                       t->real_parent = new_parent;
13420                         if (t->parent == father) {
13421                                 BUG_ON(t->ptrace);
13422 -                               t->parent = t->real_parent;
13423 +                               t->parent = new_parent;
13424                         }
13425                         if (t->pdeath_signal)
13426                                 group_send_sig_info(t->pdeath_signal,
13427 @@ -810,6 +831,9 @@ void do_exit(long code)
13428          */
13429         flush_ptrace_hw_breakpoint(tsk);
13430  
13431 +       /* needs to stay before exit_notify() */
13432 +       exit_vx_info_early(tsk, code);
13433 +
13434         exit_notify(tsk, group_dead);
13435  #ifdef CONFIG_NUMA
13436         task_lock(tsk);
13437 @@ -863,10 +887,15 @@ void do_exit(long code)
13438         smp_mb();
13439         raw_spin_unlock_wait(&tsk->pi_lock);
13440  
13441 +       /* needs to stay after exit_notify() */
13442 +       exit_vx_info(tsk, code);
13443 +       exit_nx_info(tsk);
13444 +
13445         /* causes final put_task_struct in finish_task_switch(). */
13446         tsk->state = TASK_DEAD;
13447         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
13448         schedule();
13449 +       printk("bad task: %p [%lx]\n", current, current->state);
13450         BUG();
13451         /* Avoid "noreturn function does return".  */
13452         for (;;)
13453 diff -NurpP --minimal linux-3.13.1/kernel/fork.c linux-3.13.1-vs2.3.6.10/kernel/fork.c
13454 --- linux-3.13.1/kernel/fork.c  2014-01-22 20:39:13.000000000 +0000
13455 +++ linux-3.13.1-vs2.3.6.10/kernel/fork.c       2014-01-31 20:38:03.000000000 +0000
13456 @@ -71,6 +71,9 @@
13457  #include <linux/signalfd.h>
13458  #include <linux/uprobes.h>
13459  #include <linux/aio.h>
13460 +#include <linux/vs_context.h>
13461 +#include <linux/vs_network.h>
13462 +#include <linux/vs_limit.h>
13463  
13464  #include <asm/pgtable.h>
13465  #include <asm/pgalloc.h>
13466 @@ -211,6 +214,8 @@ void free_task(struct task_struct *tsk)
13467         arch_release_thread_info(tsk->stack);
13468         free_thread_info(tsk->stack);
13469         rt_mutex_debug_task_free(tsk);
13470 +       clr_vx_info(&tsk->vx_info);
13471 +       clr_nx_info(&tsk->nx_info);
13472         ftrace_graph_exit_task(tsk);
13473         put_seccomp_filter(tsk);
13474         arch_release_task_struct(tsk);
13475 @@ -542,6 +547,7 @@ static struct mm_struct *mm_init(struct
13476         if (likely(!mm_alloc_pgd(mm))) {
13477                 mm->def_flags = 0;
13478                 mmu_notifier_mm_init(mm);
13479 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
13480                 return mm;
13481         }
13482  
13483 @@ -594,6 +600,7 @@ void __mmdrop(struct mm_struct *mm)
13484         destroy_context(mm);
13485         mmu_notifier_mm_destroy(mm);
13486         check_mm(mm);
13487 +       clr_vx_info(&mm->mm_vx_info);
13488         free_mm(mm);
13489  }
13490  EXPORT_SYMBOL_GPL(__mmdrop);
13491 @@ -813,6 +820,7 @@ struct mm_struct *dup_mm(struct task_str
13492                 goto fail_nomem;
13493  
13494         memcpy(mm, oldmm, sizeof(*mm));
13495 +       mm->mm_vx_info = NULL;
13496         mm_init_cpumask(mm);
13497  
13498  #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
13499 @@ -851,6 +859,7 @@ fail_nocontext:
13500          * If init_new_context() failed, we cannot use mmput() to free the mm
13501          * because it calls destroy_context()
13502          */
13503 +       clr_vx_info(&mm->mm_vx_info);
13504         mm_free_pgd(mm);
13505         free_mm(mm);
13506         return NULL;
13507 @@ -1135,6 +1144,8 @@ static struct task_struct *copy_process(
13508  {
13509         int retval;
13510         struct task_struct *p;
13511 +       struct vx_info *vxi;
13512 +       struct nx_info *nxi;
13513  
13514         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
13515                 return ERR_PTR(-EINVAL);
13516 @@ -1197,7 +1208,12 @@ static struct task_struct *copy_process(
13517         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
13518         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
13519  #endif
13520 +       init_vx_info(&p->vx_info, current_vx_info());
13521 +       init_nx_info(&p->nx_info, current_nx_info());
13522 +
13523         retval = -EAGAIN;
13524 +       if (!vx_nproc_avail(1))
13525 +               goto bad_fork_free;
13526         if (atomic_read(&p->real_cred->user->processes) >=
13527                         task_rlimit(p, RLIMIT_NPROC)) {
13528                 if (p->real_cred->user != INIT_USER &&
13529 @@ -1479,6 +1495,18 @@ static struct task_struct *copy_process(
13530  
13531         total_forks++;
13532         spin_unlock(&current->sighand->siglock);
13533 +
13534 +       /* p is copy of current */
13535 +       vxi = p->vx_info;
13536 +       if (vxi) {
13537 +               claim_vx_info(vxi, p);
13538 +               atomic_inc(&vxi->cvirt.nr_threads);
13539 +               atomic_inc(&vxi->cvirt.total_forks);
13540 +               vx_nproc_inc(p);
13541 +       }
13542 +       nxi = p->nx_info;
13543 +       if (nxi)
13544 +               claim_nx_info(nxi, p);
13545         write_unlock_irq(&tasklist_lock);
13546         proc_fork_connector(p);
13547         cgroup_post_fork(p);
13548 diff -NurpP --minimal linux-3.13.1/kernel/kthread.c linux-3.13.1-vs2.3.6.10/kernel/kthread.c
13549 --- linux-3.13.1/kernel/kthread.c       2014-01-22 20:39:13.000000000 +0000
13550 +++ linux-3.13.1-vs2.3.6.10/kernel/kthread.c    2014-01-31 20:38:03.000000000 +0000
13551 @@ -18,6 +18,7 @@
13552  #include <linux/freezer.h>
13553  #include <linux/ptrace.h>
13554  #include <linux/uaccess.h>
13555 +#include <linux/vs_pid.h>
13556  #include <trace/events/sched.h>
13557  
13558  static DEFINE_SPINLOCK(kthread_create_lock);
13559 diff -NurpP --minimal linux-3.13.1/kernel/nsproxy.c linux-3.13.1-vs2.3.6.10/kernel/nsproxy.c
13560 --- linux-3.13.1/kernel/nsproxy.c       2013-11-25 15:47:03.000000000 +0000
13561 +++ linux-3.13.1-vs2.3.6.10/kernel/nsproxy.c    2014-02-01 00:17:43.000000000 +0000
13562 @@ -20,11 +20,14 @@
13563  #include <linux/mnt_namespace.h>
13564  #include <linux/utsname.h>
13565  #include <linux/pid_namespace.h>
13566 +#include <linux/vserver/global.h>
13567 +#include <linux/vserver/debug.h>
13568  #include <net/net_namespace.h>
13569  #include <linux/ipc_namespace.h>
13570  #include <linux/proc_ns.h>
13571  #include <linux/file.h>
13572  #include <linux/syscalls.h>
13573 +#include "../fs/mount.h"
13574  
13575  static struct kmem_cache *nsproxy_cachep;
13576  
13577 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
13578         struct nsproxy *nsproxy;
13579  
13580         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
13581 -       if (nsproxy)
13582 +       if (nsproxy) {
13583                 atomic_set(&nsproxy->count, 1);
13584 +               atomic_inc(&vs_global_nsproxy);
13585 +       }
13586 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
13587         return nsproxy;
13588  }
13589  
13590 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
13591   * Return the newly created nsproxy.  Do not attach this to the task,
13592   * leave it to the caller to do proper locking and attach it to task.
13593   */
13594 -static struct nsproxy *create_new_namespaces(unsigned long flags,
13595 -       struct task_struct *tsk, struct user_namespace *user_ns,
13596 -       struct fs_struct *new_fs)
13597 +static struct nsproxy *unshare_namespaces(
13598 +       unsigned long flags,
13599 +       struct nsproxy *orig,
13600 +       struct fs_struct *new_fs,
13601 +       struct user_namespace *new_user,
13602 +       struct pid_namespace *new_pid)
13603  {
13604         struct nsproxy *new_nsp;
13605         int err;
13606 @@ -67,32 +76,31 @@ static struct nsproxy *create_new_namesp
13607         if (!new_nsp)
13608                 return ERR_PTR(-ENOMEM);
13609  
13610 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
13611 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
13612         if (IS_ERR(new_nsp->mnt_ns)) {
13613                 err = PTR_ERR(new_nsp->mnt_ns);
13614                 goto out_ns;
13615         }
13616  
13617 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
13618 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
13619         if (IS_ERR(new_nsp->uts_ns)) {
13620                 err = PTR_ERR(new_nsp->uts_ns);
13621                 goto out_uts;
13622         }
13623  
13624 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
13625 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
13626         if (IS_ERR(new_nsp->ipc_ns)) {
13627                 err = PTR_ERR(new_nsp->ipc_ns);
13628                 goto out_ipc;
13629         }
13630  
13631 -       new_nsp->pid_ns_for_children =
13632 -               copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children);
13633 +       new_nsp->pid_ns_for_children = copy_pid_ns(flags, new_user, new_pid);
13634         if (IS_ERR(new_nsp->pid_ns_for_children)) {
13635                 err = PTR_ERR(new_nsp->pid_ns_for_children);
13636                 goto out_pid;
13637         }
13638  
13639 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
13640 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
13641         if (IS_ERR(new_nsp->net_ns)) {
13642                 err = PTR_ERR(new_nsp->net_ns);
13643                 goto out_net;
13644 @@ -117,6 +125,41 @@ out_ns:
13645         return ERR_PTR(err);
13646  }
13647  
13648 +static struct nsproxy *create_new_namespaces(unsigned long flags,
13649 +       struct task_struct *tsk, struct user_namespace *user_ns,
13650 +       struct fs_struct *new_fs)
13651 +
13652 +{
13653 +       return unshare_namespaces(flags, tsk->nsproxy,
13654 +               new_fs, user_ns, task_active_pid_ns(tsk));
13655 +}
13656 +
13657 +/*
13658 + * copies the nsproxy, setting refcount to 1, and grabbing a
13659 + * reference to all contained namespaces.
13660 + */
13661 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
13662 +{
13663 +       struct nsproxy *ns = create_nsproxy();
13664 +
13665 +       if (ns) {
13666 +               memcpy(ns, orig, sizeof(struct nsproxy));
13667 +               atomic_set(&ns->count, 1);
13668 +
13669 +               if (ns->mnt_ns)
13670 +                       get_mnt_ns(ns->mnt_ns);
13671 +               if (ns->uts_ns)
13672 +                       get_uts_ns(ns->uts_ns);
13673 +               if (ns->ipc_ns)
13674 +                       get_ipc_ns(ns->ipc_ns);
13675 +               if (ns->pid_ns_for_children)
13676 +                       get_pid_ns(ns->pid_ns_for_children);
13677 +               if (ns->net_ns)
13678 +                       get_net(ns->net_ns);
13679 +       }
13680 +       return ns;
13681 +}
13682 +
13683  /*
13684   * called from clone.  This now handles copy for nsproxy and all
13685   * namespaces therein.
13686 @@ -125,7 +168,10 @@ int copy_namespaces(unsigned long flags,
13687  {
13688         struct nsproxy *old_ns = tsk->nsproxy;
13689         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
13690 -       struct nsproxy *new_ns;
13691 +       struct nsproxy *new_ns = NULL;
13692 +
13693 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
13694 +               flags, tsk, old_ns);
13695  
13696         if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13697                               CLONE_NEWPID | CLONE_NEWNET)))) {
13698 @@ -133,7 +179,7 @@ int copy_namespaces(unsigned long flags,
13699                 return 0;
13700         }
13701  
13702 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13703 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags))
13704                 return -EPERM;
13705  
13706         /*
13707 @@ -152,6 +198,9 @@ int copy_namespaces(unsigned long flags,
13708                 return  PTR_ERR(new_ns);
13709  
13710         tsk->nsproxy = new_ns;
13711 +       vxdprintk(VXD_CBIT(space, 3),
13712 +               "copy_namespaces(0x%08lx,%p[%p]) = [%p]",
13713 +               flags, tsk, old_ns, new_ns);
13714         return 0;
13715  }
13716  
13717 @@ -165,7 +214,9 @@ void free_nsproxy(struct nsproxy *ns)
13718                 put_ipc_ns(ns->ipc_ns);
13719         if (ns->pid_ns_for_children)
13720                 put_pid_ns(ns->pid_ns_for_children);
13721 -       put_net(ns->net_ns);
13722 +       if (ns->net_ns)
13723 +               put_net(ns->net_ns);
13724 +       atomic_dec(&vs_global_nsproxy);
13725         kmem_cache_free(nsproxy_cachep, ns);
13726  }
13727  
13728 @@ -179,12 +230,16 @@ int unshare_nsproxy_namespaces(unsigned
13729         struct user_namespace *user_ns;
13730         int err = 0;
13731  
13732 +       vxdprintk(VXD_CBIT(space, 4),
13733 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
13734 +               unshare_flags, current->nsproxy);
13735 +
13736         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13737                                CLONE_NEWNET | CLONE_NEWPID)))
13738                 return 0;
13739  
13740         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
13741 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13742 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
13743                 return -EPERM;
13744  
13745         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
13746 diff -NurpP --minimal linux-3.13.1/kernel/pid.c linux-3.13.1-vs2.3.6.10/kernel/pid.c
13747 --- linux-3.13.1/kernel/pid.c   2013-11-25 15:47:03.000000000 +0000
13748 +++ linux-3.13.1-vs2.3.6.10/kernel/pid.c        2014-01-31 20:38:03.000000000 +0000
13749 @@ -38,6 +38,7 @@
13750  #include <linux/syscalls.h>
13751  #include <linux/proc_ns.h>
13752  #include <linux/proc_fs.h>
13753 +#include <linux/vs_pid.h>
13754  
13755  #define pid_hashfn(nr, ns)     \
13756         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
13757 @@ -373,7 +374,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
13758  
13759  struct pid *find_vpid(int nr)
13760  {
13761 -       return find_pid_ns(nr, task_active_pid_ns(current));
13762 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
13763  }
13764  EXPORT_SYMBOL_GPL(find_vpid);
13765  
13766 @@ -429,6 +430,9 @@ void transfer_pid(struct task_struct *ol
13767  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
13768  {
13769         struct task_struct *result = NULL;
13770 +
13771 +       if (type == PIDTYPE_REALPID)
13772 +               type = PIDTYPE_PID;
13773         if (pid) {
13774                 struct hlist_node *first;
13775                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
13776 @@ -448,7 +452,7 @@ struct task_struct *find_task_by_pid_ns(
13777         rcu_lockdep_assert(rcu_read_lock_held(),
13778                            "find_task_by_pid_ns() needs rcu_read_lock()"
13779                            " protection");
13780 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
13781 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
13782  }
13783  
13784  struct task_struct *find_task_by_vpid(pid_t vnr)
13785 @@ -492,7 +496,7 @@ struct pid *find_get_pid(pid_t nr)
13786  }
13787  EXPORT_SYMBOL_GPL(find_get_pid);
13788  
13789 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13790 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
13791  {
13792         struct upid *upid;
13793         pid_t nr = 0;
13794 @@ -506,6 +510,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
13795  }
13796  EXPORT_SYMBOL_GPL(pid_nr_ns);
13797  
13798 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13799 +{
13800 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
13801 +}
13802 +
13803  pid_t pid_vnr(struct pid *pid)
13804  {
13805         return pid_nr_ns(pid, task_active_pid_ns(current));
13806 diff -NurpP --minimal linux-3.13.1/kernel/pid_namespace.c linux-3.13.1-vs2.3.6.10/kernel/pid_namespace.c
13807 --- linux-3.13.1/kernel/pid_namespace.c 2014-01-22 20:39:13.000000000 +0000
13808 +++ linux-3.13.1-vs2.3.6.10/kernel/pid_namespace.c      2014-02-01 12:23:11.000000000 +0000
13809 @@ -18,6 +18,7 @@
13810  #include <linux/proc_ns.h>
13811  #include <linux/reboot.h>
13812  #include <linux/export.h>
13813 +#include <linux/vserver/global.h>
13814  
13815  struct pid_cache {
13816         int nr_ids;
13817 @@ -110,6 +111,7 @@ static struct pid_namespace *create_pid_
13818                 goto out_free_map;
13819  
13820         kref_init(&ns->kref);
13821 +       atomic_inc(&vs_global_pid_ns);
13822         ns->level = level;
13823         ns->parent = get_pid_ns(parent_pid_ns);
13824         ns->user_ns = get_user_ns(user_ns);
13825 @@ -127,6 +129,7 @@ static struct pid_namespace *create_pid_
13826  out_free_map:
13827         kfree(ns->pidmap[0].page);
13828  out_free:
13829 +       atomic_dec(&vs_global_pid_ns);
13830         kmem_cache_free(pid_ns_cachep, ns);
13831  out:
13832         return ERR_PTR(err);
13833 diff -NurpP --minimal linux-3.13.1/kernel/posix-timers.c linux-3.13.1-vs2.3.6.10/kernel/posix-timers.c
13834 --- linux-3.13.1/kernel/posix-timers.c  2013-07-14 17:01:35.000000000 +0000
13835 +++ linux-3.13.1-vs2.3.6.10/kernel/posix-timers.c       2014-01-31 20:38:03.000000000 +0000
13836 @@ -48,6 +48,7 @@
13837  #include <linux/workqueue.h>
13838  #include <linux/export.h>
13839  #include <linux/hashtable.h>
13840 +#include <linux/vs_context.h>
13841  
13842  /*
13843   * Management arrays for POSIX timers. Timers are now kept in static hash table
13844 @@ -398,6 +399,7 @@ int posix_timer_event(struct k_itimer *t
13845  {
13846         struct task_struct *task;
13847         int shared, ret = -1;
13848 +
13849         /*
13850          * FIXME: if ->sigq is queued we can race with
13851          * dequeue_signal()->do_schedule_next_timer().
13852 @@ -414,10 +416,18 @@ int posix_timer_event(struct k_itimer *t
13853         rcu_read_lock();
13854         task = pid_task(timr->it_pid, PIDTYPE_PID);
13855         if (task) {
13856 +               struct vx_info_save vxis;
13857 +               struct vx_info *vxi;
13858 +
13859 +               vxi = get_vx_info(task->vx_info);
13860 +               enter_vx_info(vxi, &vxis);
13861                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
13862                 ret = send_sigqueue(timr->sigq, task, shared);
13863 +               leave_vx_info(&vxis);
13864 +               put_vx_info(vxi);
13865         }
13866         rcu_read_unlock();
13867 +
13868         /* If we failed to send the signal the timer stops. */
13869         return ret > 0;
13870  }
13871 diff -NurpP --minimal linux-3.13.1/kernel/printk/printk.c linux-3.13.1-vs2.3.6.10/kernel/printk/printk.c
13872 --- linux-3.13.1/kernel/printk/printk.c 2014-01-22 20:39:13.000000000 +0000
13873 +++ linux-3.13.1-vs2.3.6.10/kernel/printk/printk.c      2014-02-01 01:59:45.000000000 +0000
13874 @@ -45,6 +45,7 @@
13875  #include <linux/poll.h>
13876  #include <linux/irq_work.h>
13877  #include <linux/utsname.h>
13878 +#include <linux/vs_cvirt.h>
13879  
13880  #include <asm/uaccess.h>
13881  
13882 @@ -386,7 +387,7 @@ static int check_syslog_permissions(int
13883                 return 0;
13884  
13885         if (syslog_action_restricted(type)) {
13886 -               if (capable(CAP_SYSLOG))
13887 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
13888                         return 0;
13889                 /*
13890                  * For historical reasons, accept CAP_SYS_ADMIN too, with
13891 @@ -1135,12 +1136,9 @@ int do_syslog(int type, char __user *buf
13892         if (error)
13893                 return error;
13894  
13895 -       switch (type) {
13896 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
13897 -               break;
13898 -       case SYSLOG_ACTION_OPEN:        /* Open log */
13899 -               break;
13900 -       case SYSLOG_ACTION_READ:        /* Read from log */
13901 +       if ((type == SYSLOG_ACTION_READ) ||
13902 +           (type == SYSLOG_ACTION_READ_ALL) ||
13903 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
13904                 error = -EINVAL;
13905                 if (!buf || len < 0)
13906                         goto out;
13907 @@ -1151,6 +1149,16 @@ int do_syslog(int type, char __user *buf
13908                         error = -EFAULT;
13909                         goto out;
13910                 }
13911 +       }
13912 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13913 +               return vx_do_syslog(type, buf, len);
13914 +
13915 +       switch (type) {
13916 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
13917 +               break;
13918 +       case SYSLOG_ACTION_OPEN:        /* Open log */
13919 +               break;
13920 +       case SYSLOG_ACTION_READ:        /* Read from log */
13921                 error = wait_event_interruptible(log_wait,
13922                                                  syslog_seq != log_next_seq);
13923                 if (error)
13924 @@ -1163,16 +1171,6 @@ int do_syslog(int type, char __user *buf
13925                 /* FALL THRU */
13926         /* Read last kernel messages */
13927         case SYSLOG_ACTION_READ_ALL:
13928 -               error = -EINVAL;
13929 -               if (!buf || len < 0)
13930 -                       goto out;
13931 -               error = 0;
13932 -               if (!len)
13933 -                       goto out;
13934 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
13935 -                       error = -EFAULT;
13936 -                       goto out;
13937 -               }
13938                 error = syslog_print_all(buf, len, clear);
13939                 break;
13940         /* Clear ring buffer */
13941 diff -NurpP --minimal linux-3.13.1/kernel/ptrace.c linux-3.13.1-vs2.3.6.10/kernel/ptrace.c
13942 --- linux-3.13.1/kernel/ptrace.c        2014-01-22 20:39:13.000000000 +0000
13943 +++ linux-3.13.1-vs2.3.6.10/kernel/ptrace.c     2014-01-31 20:38:03.000000000 +0000
13944 @@ -23,6 +23,7 @@
13945  #include <linux/syscalls.h>
13946  #include <linux/uaccess.h>
13947  #include <linux/regset.h>
13948 +#include <linux/vs_context.h>
13949  #include <linux/hw_breakpoint.h>
13950  #include <linux/cn_proc.h>
13951  #include <linux/compat.h>
13952 @@ -264,6 +265,11 @@ ok:
13953         }
13954         rcu_read_unlock();
13955  
13956 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
13957 +               return -EPERM;
13958 +       if (!vx_check(task->xid, VS_IDENT) &&
13959 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
13960 +               return -EACCES;
13961         return security_ptrace_access_check(task, mode);
13962  }
13963  
13964 diff -NurpP --minimal linux-3.13.1/kernel/reboot.c linux-3.13.1-vs2.3.6.10/kernel/reboot.c
13965 --- linux-3.13.1/kernel/reboot.c        2014-01-22 20:39:13.000000000 +0000
13966 +++ linux-3.13.1-vs2.3.6.10/kernel/reboot.c     2014-02-01 00:19:40.000000000 +0000
13967 @@ -16,6 +16,7 @@
13968  #include <linux/syscalls.h>
13969  #include <linux/syscore_ops.h>
13970  #include <linux/uaccess.h>
13971 +#include <linux/vs_pid.h>
13972  
13973  /*
13974   * this indicates whether you can reboot with ctrl-alt-del: the default is yes
13975 @@ -188,6 +189,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
13976  
13977  static DEFINE_MUTEX(reboot_mutex);
13978  
13979 +long vs_reboot(unsigned int, void __user *);
13980 +
13981  /*
13982   * Reboot system call: for obvious reasons only root may call it,
13983   * and even root needs to set up some magic numbers in the registers
13984 @@ -230,6 +233,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
13985         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
13986                 cmd = LINUX_REBOOT_CMD_HALT;
13987  
13988 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13989 +               return vs_reboot(cmd, arg);
13990 +
13991         mutex_lock(&reboot_mutex);
13992         switch (cmd) {
13993         case LINUX_REBOOT_CMD_RESTART:
13994 diff -NurpP --minimal linux-3.13.1/kernel/sched/core.c linux-3.13.1-vs2.3.6.10/kernel/sched/core.c
13995 --- linux-3.13.1/kernel/sched/core.c    2014-01-22 20:39:13.000000000 +0000
13996 +++ linux-3.13.1-vs2.3.6.10/kernel/sched/core.c 2014-01-31 20:38:03.000000000 +0000
13997 @@ -73,6 +73,8 @@
13998  #include <linux/init_task.h>
13999  #include <linux/binfmts.h>
14000  #include <linux/context_tracking.h>
14001 +#include <linux/vs_sched.h>
14002 +#include <linux/vs_cvirt.h>
14003  
14004  #include <asm/switch_to.h>
14005  #include <asm/tlb.h>
14006 @@ -2905,7 +2907,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14007                 nice = 19;
14008  
14009         if (increment < 0 && !can_nice(current, nice))
14010 -               return -EPERM;
14011 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14012  
14013         retval = security_task_setnice(current, nice);
14014         if (retval)
14015 diff -NurpP --minimal linux-3.13.1/kernel/sched/cputime.c linux-3.13.1-vs2.3.6.10/kernel/sched/cputime.c
14016 --- linux-3.13.1/kernel/sched/cputime.c 2013-11-25 15:47:03.000000000 +0000
14017 +++ linux-3.13.1-vs2.3.6.10/kernel/sched/cputime.c      2014-01-31 20:38:03.000000000 +0000
14018 @@ -4,6 +4,7 @@
14019  #include <linux/kernel_stat.h>
14020  #include <linux/static_key.h>
14021  #include <linux/context_tracking.h>
14022 +#include <linux/vs_sched.h>
14023  #include "sched.h"
14024  
14025  
14026 @@ -135,14 +136,17 @@ static inline void task_group_account_fi
14027  void account_user_time(struct task_struct *p, cputime_t cputime,
14028                        cputime_t cputime_scaled)
14029  {
14030 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14031 +       int nice = (TASK_NICE(p) > 0);
14032         int index;
14033  
14034         /* Add user time to process. */
14035         p->utime += cputime;
14036         p->utimescaled += cputime_scaled;
14037 +       vx_account_user(vxi, cputime, nice);
14038         account_group_user_time(p, cputime);
14039  
14040 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14041 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14042  
14043         /* Add user time to cpustat. */
14044         task_group_account_field(p, index, (__force u64) cputime);
14045 @@ -189,9 +193,12 @@ static inline
14046  void __account_system_time(struct task_struct *p, cputime_t cputime,
14047                         cputime_t cputime_scaled, int index)
14048  {
14049 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14050 +
14051         /* Add system time to process. */
14052         p->stime += cputime;
14053         p->stimescaled += cputime_scaled;
14054 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14055         account_group_system_time(p, cputime);
14056  
14057         /* Add system time to cpustat. */
14058 diff -NurpP --minimal linux-3.13.1/kernel/sched/fair.c linux-3.13.1-vs2.3.6.10/kernel/sched/fair.c
14059 --- linux-3.13.1/kernel/sched/fair.c    2014-01-22 20:39:13.000000000 +0000
14060 +++ linux-3.13.1-vs2.3.6.10/kernel/sched/fair.c 2014-01-31 20:38:03.000000000 +0000
14061 @@ -29,6 +29,7 @@
14062  #include <linux/mempolicy.h>
14063  #include <linux/migrate.h>
14064  #include <linux/task_work.h>
14065 +#include <linux/vs_cvirt.h>
14066  
14067  #include <trace/events/sched.h>
14068  
14069 @@ -2577,6 +2578,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14070                 __enqueue_entity(cfs_rq, se);
14071         se->on_rq = 1;
14072  
14073 +       if (entity_is_task(se))
14074 +               vx_activate_task(task_of(se));
14075         if (cfs_rq->nr_running == 1) {
14076                 list_add_leaf_cfs_rq(cfs_rq);
14077                 check_enqueue_throttle(cfs_rq);
14078 @@ -2658,6 +2661,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14079         if (se != cfs_rq->curr)
14080                 __dequeue_entity(cfs_rq, se);
14081         se->on_rq = 0;
14082 +       if (entity_is_task(se))
14083 +               vx_deactivate_task(task_of(se));
14084         account_entity_dequeue(cfs_rq, se);
14085  
14086         /*
14087 diff -NurpP --minimal linux-3.13.1/kernel/sched/proc.c linux-3.13.1-vs2.3.6.10/kernel/sched/proc.c
14088 --- linux-3.13.1/kernel/sched/proc.c    2013-11-25 15:45:08.000000000 +0000
14089 +++ linux-3.13.1-vs2.3.6.10/kernel/sched/proc.c 2014-01-31 21:22:36.000000000 +0000
14090 @@ -78,9 +78,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14091   */
14092  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14093  {
14094 -       loads[0] = (avenrun[0] + offset) << shift;
14095 -       loads[1] = (avenrun[1] + offset) << shift;
14096 -       loads[2] = (avenrun[2] + offset) << shift;
14097 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14098 +               struct vx_info *vxi = current_vx_info();
14099 +
14100 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14101 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14102 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14103 +       } else {
14104 +               loads[0] = (avenrun[0] + offset) << shift;
14105 +               loads[1] = (avenrun[1] + offset) << shift;
14106 +               loads[2] = (avenrun[2] + offset) << shift;
14107 +       }
14108  }
14109  
14110  long calc_load_fold_active(struct rq *this_rq)
14111 diff -NurpP --minimal linux-3.13.1/kernel/signal.c linux-3.13.1-vs2.3.6.10/kernel/signal.c
14112 --- linux-3.13.1/kernel/signal.c        2014-01-22 20:39:13.000000000 +0000
14113 +++ linux-3.13.1-vs2.3.6.10/kernel/signal.c     2014-01-31 20:38:03.000000000 +0000
14114 @@ -33,6 +33,8 @@
14115  #include <linux/uprobes.h>
14116  #include <linux/compat.h>
14117  #include <linux/cn_proc.h>
14118 +#include <linux/vs_context.h>
14119 +#include <linux/vs_pid.h>
14120  #define CREATE_TRACE_POINTS
14121  #include <trace/events/signal.h>
14122  
14123 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14124         struct pid *sid;
14125         int error;
14126  
14127 +       vxdprintk(VXD_CBIT(misc, 7),
14128 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14129 +               sig, info, t, vx_task_xid(t), t->pid);
14130 +
14131         if (!valid_signal(sig))
14132                 return -EINVAL;
14133  
14134 +/*     FIXME: needed? if so, why?
14135 +       if ((info != SEND_SIG_NOINFO) &&
14136 +               (is_si_special(info) || !si_fromuser(info)))
14137 +               goto skip;      */
14138 +
14139         if (!si_fromuser(info))
14140                 return 0;
14141  
14142 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14143                 }
14144         }
14145  
14146 +       error = -EPERM;
14147 +       if (t->pid == 1 && current->xid)
14148 +               return error;
14149 +
14150 +       error = -ESRCH;
14151 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14152 +                 loops, maybe ENOENT or EACCES? */
14153 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14154 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14155 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14156 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14157 +               return error;
14158 +       }
14159 +/* skip: */
14160         return security_task_kill(t, info, sig, 0);
14161  }
14162  
14163 @@ -1353,7 +1378,7 @@ int kill_pid_info(int sig, struct siginf
14164         rcu_read_lock();
14165  retry:
14166         p = pid_task(pid, PIDTYPE_PID);
14167 -       if (p) {
14168 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14169                 error = group_send_sig_info(sig, info, p);
14170                 if (unlikely(error == -ESRCH))
14171                         /*
14172 @@ -1401,7 +1426,7 @@ int kill_pid_info_as_cred(int sig, struc
14173  
14174         rcu_read_lock();
14175         p = pid_task(pid, PIDTYPE_PID);
14176 -       if (!p) {
14177 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14178                 ret = -ESRCH;
14179                 goto out_unlock;
14180         }
14181 @@ -1453,8 +1478,10 @@ static int kill_something_info(int sig,
14182                 struct task_struct * p;
14183  
14184                 for_each_process(p) {
14185 -                       if (task_pid_vnr(p) > 1 &&
14186 -                                       !same_thread_group(p, current)) {
14187 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14188 +                               task_pid_vnr(p) > 1 &&
14189 +                               !same_thread_group(p, current) &&
14190 +                               !vx_current_initpid(p->pid)) {
14191                                 int err = group_send_sig_info(sig, info, p);
14192                                 ++count;
14193                                 if (err != -EPERM)
14194 @@ -2308,6 +2335,11 @@ relock:
14195                                 !sig_kernel_only(signr))
14196                         continue;
14197  
14198 +               /* virtual init is protected against user signals */
14199 +               if ((info->si_code == SI_USER) &&
14200 +                       vx_current_initpid(current->pid))
14201 +                       continue;
14202 +
14203                 if (sig_kernel_stop(signr)) {
14204                         /*
14205                          * The default action is to stop all threads in
14206 diff -NurpP --minimal linux-3.13.1/kernel/softirq.c linux-3.13.1-vs2.3.6.10/kernel/softirq.c
14207 --- linux-3.13.1/kernel/softirq.c       2014-01-22 20:39:13.000000000 +0000
14208 +++ linux-3.13.1-vs2.3.6.10/kernel/softirq.c    2014-01-31 20:38:03.000000000 +0000
14209 @@ -23,6 +23,7 @@
14210  #include <linux/smp.h>
14211  #include <linux/smpboot.h>
14212  #include <linux/tick.h>
14213 +#include <linux/vs_context.h>
14214  
14215  #define CREATE_TRACE_POINTS
14216  #include <trace/events/irq.h>
14217 diff -NurpP --minimal linux-3.13.1/kernel/sys.c linux-3.13.1-vs2.3.6.10/kernel/sys.c
14218 --- linux-3.13.1/kernel/sys.c   2014-01-22 20:39:13.000000000 +0000
14219 +++ linux-3.13.1-vs2.3.6.10/kernel/sys.c        2014-02-01 00:19:29.000000000 +0000
14220 @@ -54,6 +54,7 @@
14221  #include <linux/cred.h>
14222  
14223  #include <linux/kmsg_dump.h>
14224 +#include <linux/vs_pid.h>
14225  /* Move somewhere else to avoid recompiling? */
14226  #include <generated/utsrelease.h>
14227  
14228 @@ -145,7 +146,10 @@ static int set_one_prio(struct task_stru
14229                 goto out;
14230         }
14231         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14232 -               error = -EACCES;
14233 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14234 +                       error = 0;
14235 +               else
14236 +                       error = -EACCES;
14237                 goto out;
14238         }
14239         no_nice = security_task_setnice(p, niceval);
14240 @@ -196,6 +200,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14241                         else
14242                                 pgrp = task_pgrp(current);
14243                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14244 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14245 +                                       continue;
14246                                 error = set_one_prio(p, niceval, error);
14247                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14248                         break;
14249 @@ -261,6 +267,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14250                         else
14251                                 pgrp = task_pgrp(current);
14252                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14253 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14254 +                                       continue;
14255                                 niceval = 20 - task_nice(p);
14256                                 if (niceval > retval)
14257                                         retval = niceval;
14258 @@ -1198,7 +1206,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14259         int errno;
14260         char tmp[__NEW_UTS_LEN];
14261  
14262 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14263 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14264 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14265                 return -EPERM;
14266  
14267         if (len < 0 || len > __NEW_UTS_LEN)
14268 @@ -1249,7 +1258,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14269         int errno;
14270         char tmp[__NEW_UTS_LEN];
14271  
14272 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14273 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14274 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14275                 return -EPERM;
14276         if (len < 0 || len > __NEW_UTS_LEN)
14277                 return -EINVAL;
14278 @@ -1368,7 +1378,7 @@ int do_prlimit(struct task_struct *tsk,
14279                 /* Keep the capable check against init_user_ns until
14280                    cgroups can contain all limits */
14281                 if (new_rlim->rlim_max > rlim->rlim_max &&
14282 -                               !capable(CAP_SYS_RESOURCE))
14283 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14284                         retval = -EPERM;
14285                 if (!retval)
14286                         retval = security_task_setrlimit(tsk->group_leader,
14287 @@ -1421,7 +1431,8 @@ static int check_prlimit_permission(stru
14288             gid_eq(cred->gid, tcred->sgid) &&
14289             gid_eq(cred->gid, tcred->gid))
14290                 return 0;
14291 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14292 +       if (vx_ns_capable(tcred->user_ns,
14293 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14294                 return 0;
14295  
14296         return -EPERM;
14297 diff -NurpP --minimal linux-3.13.1/kernel/sysctl.c linux-3.13.1-vs2.3.6.10/kernel/sysctl.c
14298 --- linux-3.13.1/kernel/sysctl.c        2014-01-22 20:39:13.000000000 +0000
14299 +++ linux-3.13.1-vs2.3.6.10/kernel/sysctl.c     2014-01-31 20:38:03.000000000 +0000
14300 @@ -83,6 +83,7 @@
14301  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14302  #include <linux/lockdep.h>
14303  #endif
14304 +extern char vshelper_path[];
14305  #ifdef CONFIG_CHR_DEV_SG
14306  #include <scsi/sg.h>
14307  #endif
14308 @@ -641,6 +642,13 @@ static struct ctl_table kern_table[] = {
14309                 .mode           = 0644,
14310                 .proc_handler   = proc_dostring,
14311         },
14312 +       {
14313 +               .procname       = "vshelper",
14314 +               .data           = &vshelper_path,
14315 +               .maxlen         = 256,
14316 +               .mode           = 0644,
14317 +               .proc_handler   = &proc_dostring,
14318 +       },
14319  
14320  #ifdef CONFIG_CHR_DEV_SG
14321         {
14322 diff -NurpP --minimal linux-3.13.1/kernel/sysctl_binary.c linux-3.13.1-vs2.3.6.10/kernel/sysctl_binary.c
14323 --- linux-3.13.1/kernel/sysctl_binary.c 2014-01-22 20:39:13.000000000 +0000
14324 +++ linux-3.13.1-vs2.3.6.10/kernel/sysctl_binary.c      2014-01-31 20:38:03.000000000 +0000
14325 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
14326  
14327         { CTL_INT,      KERN_PANIC,                     "panic" },
14328         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
14329 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
14330  
14331         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
14332         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
14333 diff -NurpP --minimal linux-3.13.1/kernel/time/timekeeping.c linux-3.13.1-vs2.3.6.10/kernel/time/timekeeping.c
14334 --- linux-3.13.1/kernel/time/timekeeping.c      2014-01-22 20:39:13.000000000 +0000
14335 +++ linux-3.13.1-vs2.3.6.10/kernel/time/timekeeping.c   2014-01-31 20:38:03.000000000 +0000
14336 @@ -22,6 +22,7 @@
14337  #include <linux/tick.h>
14338  #include <linux/stop_machine.h>
14339  #include <linux/pvclock_gtod.h>
14340 +#include <linux/vs_time.h>
14341  
14342  #include "tick-internal.h"
14343  #include "ntp_internal.h"
14344 @@ -708,6 +709,7 @@ void getrawmonotonic(struct timespec *ts
14345         } while (read_seqcount_retry(&timekeeper_seq, seq));
14346  
14347         timespec_add_ns(ts, nsecs);
14348 +       vx_adjust_timespec(ts);
14349  }
14350  EXPORT_SYMBOL(getrawmonotonic);
14351  
14352 diff -NurpP --minimal linux-3.13.1/kernel/time.c linux-3.13.1-vs2.3.6.10/kernel/time.c
14353 --- linux-3.13.1/kernel/time.c  2013-11-25 15:45:08.000000000 +0000
14354 +++ linux-3.13.1-vs2.3.6.10/kernel/time.c       2014-01-31 20:38:03.000000000 +0000
14355 @@ -37,6 +37,7 @@
14356  #include <linux/fs.h>
14357  #include <linux/math64.h>
14358  #include <linux/ptrace.h>
14359 +#include <linux/vs_time.h>
14360  
14361  #include <asm/uaccess.h>
14362  #include <asm/unistd.h>
14363 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
14364         if (err)
14365                 return err;
14366  
14367 -       do_settimeofday(&tv);
14368 +       vx_settimeofday(&tv);
14369         return 0;
14370  }
14371  
14372 @@ -181,7 +182,7 @@ int do_sys_settimeofday(const struct tim
14373                 }
14374         }
14375         if (tv)
14376 -               return do_settimeofday(tv);
14377 +               return vx_settimeofday(tv);
14378         return 0;
14379  }
14380  
14381 diff -NurpP --minimal linux-3.13.1/kernel/timer.c linux-3.13.1-vs2.3.6.10/kernel/timer.c
14382 --- linux-3.13.1/kernel/timer.c 2014-01-22 20:39:13.000000000 +0000
14383 +++ linux-3.13.1-vs2.3.6.10/kernel/timer.c      2014-01-31 20:38:03.000000000 +0000
14384 @@ -42,6 +42,10 @@
14385  #include <linux/sched/sysctl.h>
14386  #include <linux/slab.h>
14387  #include <linux/compat.h>
14388 +#include <linux/vs_base.h>
14389 +#include <linux/vs_cvirt.h>
14390 +#include <linux/vs_pid.h>
14391 +#include <linux/vserver/sched.h>
14392  
14393  #include <asm/uaccess.h>
14394  #include <asm/unistd.h>
14395 diff -NurpP --minimal linux-3.13.1/kernel/user_namespace.c linux-3.13.1-vs2.3.6.10/kernel/user_namespace.c
14396 --- linux-3.13.1/kernel/user_namespace.c        2014-01-22 20:39:13.000000000 +0000
14397 +++ linux-3.13.1-vs2.3.6.10/kernel/user_namespace.c     2014-01-31 20:38:03.000000000 +0000
14398 @@ -22,6 +22,7 @@
14399  #include <linux/ctype.h>
14400  #include <linux/projid.h>
14401  #include <linux/fs_struct.h>
14402 +#include <linux/vserver/global.h>
14403  
14404  static struct kmem_cache *user_ns_cachep __read_mostly;
14405  
14406 @@ -94,6 +95,7 @@ int create_user_ns(struct cred *new)
14407  
14408         atomic_set(&ns->count, 1);
14409         /* Leave the new->user_ns reference with the new user namespace. */
14410 +       atomic_inc(&vs_global_user_ns);
14411         ns->parent = parent_ns;
14412         ns->level = parent_ns->level + 1;
14413         ns->owner = owner;
14414 @@ -848,6 +850,8 @@ static void *userns_get(struct task_stru
14415  
14416  static void userns_put(void *ns)
14417  {
14418 +       /* FIXME: maybe move into destroyer? */
14419 +       atomic_dec(&vs_global_user_ns);
14420         put_user_ns(ns);
14421  }
14422  
14423 diff -NurpP --minimal linux-3.13.1/kernel/utsname.c linux-3.13.1-vs2.3.6.10/kernel/utsname.c
14424 --- linux-3.13.1/kernel/utsname.c       2013-11-25 15:47:03.000000000 +0000
14425 +++ linux-3.13.1-vs2.3.6.10/kernel/utsname.c    2014-01-31 20:38:03.000000000 +0000
14426 @@ -16,14 +16,17 @@
14427  #include <linux/slab.h>
14428  #include <linux/user_namespace.h>
14429  #include <linux/proc_ns.h>
14430 +#include <linux/vserver/global.h>
14431  
14432  static struct uts_namespace *create_uts_ns(void)
14433  {
14434         struct uts_namespace *uts_ns;
14435  
14436         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
14437 -       if (uts_ns)
14438 +       if (uts_ns) {
14439                 kref_init(&uts_ns->kref);
14440 +               atomic_inc(&vs_global_uts_ns);
14441 +       }
14442         return uts_ns;
14443  }
14444  
14445 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
14446         ns = container_of(kref, struct uts_namespace, kref);
14447         put_user_ns(ns->user_ns);
14448         proc_free_inum(ns->proc_inum);
14449 +       atomic_dec(&vs_global_uts_ns);
14450         kfree(ns);
14451  }
14452  
14453 diff -NurpP --minimal linux-3.13.1/kernel/vserver/Kconfig linux-3.13.1-vs2.3.6.10/kernel/vserver/Kconfig
14454 --- linux-3.13.1/kernel/vserver/Kconfig 1970-01-01 00:00:00.000000000 +0000
14455 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/Kconfig      2014-01-31 20:38:03.000000000 +0000
14456 @@ -0,0 +1,230 @@
14457 +#
14458 +# Linux VServer configuration
14459 +#
14460 +
14461 +menu "Linux VServer"
14462 +
14463 +config VSERVER_AUTO_LBACK
14464 +       bool    "Automatically Assign Loopback IP"
14465 +       default y
14466 +       help
14467 +         Automatically assign a guest specific loopback
14468 +         IP and add it to the kernel network stack on
14469 +         startup.
14470 +
14471 +config VSERVER_AUTO_SINGLE
14472 +       bool    "Automatic Single IP Special Casing"
14473 +       default n
14474 +       help
14475 +         This allows network contexts with a single IP to
14476 +         automatically remap 0.0.0.0 bindings to that IP,
14477 +         avoiding further network checks and improving
14478 +         performance.
14479 +
14480 +         (note: such guests do not allow to change the ip
14481 +          on the fly and do not show loopback addresses)
14482 +
14483 +config VSERVER_COWBL
14484 +       bool    "Enable COW Immutable Link Breaking"
14485 +       default y
14486 +       help
14487 +         This enables the COW (Copy-On-Write) link break code.
14488 +         It allows you to treat unified files like normal files
14489 +         when writing to them (which will implicitely break the
14490 +         link and create a copy of the unified file)
14491 +
14492 +config VSERVER_VTIME
14493 +       bool    "Enable Virtualized Guest Time (EXPERIMENTAL)"
14494 +       default n
14495 +       help
14496 +         This enables per guest time offsets to allow for
14497 +         adjusting the system clock individually per guest.
14498 +         this adds some overhead to the time functions and
14499 +         therefore should not be enabled without good reason.
14500 +
14501 +config VSERVER_DEVICE
14502 +       bool    "Enable Guest Device Mapping (EXPERIMENTAL)"
14503 +       default n
14504 +       help
14505 +         This enables generic device remapping.
14506 +
14507 +config VSERVER_PROC_SECURE
14508 +       bool    "Enable Proc Security"
14509 +       depends on PROC_FS
14510 +       default y
14511 +       help
14512 +         This configures ProcFS security to initially hide
14513 +         non-process entries for all contexts except the main and
14514 +         spectator context (i.e. for all guests), which is a secure
14515 +         default.
14516 +
14517 +         (note: on 1.2x the entries were visible by default)
14518 +
14519 +choice
14520 +       prompt  "Persistent Inode Tagging"
14521 +       default TAGGING_ID24
14522 +       help
14523 +         This adds persistent context information to filesystems
14524 +         mounted with the tagxid option. Tagging is a requirement
14525 +         for per-context disk limits and per-context quota.
14526 +
14527 +
14528 +config TAGGING_NONE
14529 +       bool    "Disabled"
14530 +       help
14531 +         do not store per-context information in inodes.
14532 +
14533 +config TAGGING_UID16
14534 +       bool    "UID16/GID32"
14535 +       help
14536 +         reduces UID to 16 bit, but leaves GID at 32 bit.
14537 +
14538 +config TAGGING_GID16
14539 +       bool    "UID32/GID16"
14540 +       help
14541 +         reduces GID to 16 bit, but leaves UID at 32 bit.
14542 +
14543 +config TAGGING_ID24
14544 +       bool    "UID24/GID24"
14545 +       help
14546 +         uses the upper 8bit from UID and GID for XID tagging
14547 +         which leaves 24bit for UID/GID each, which should be
14548 +         more than sufficient for normal use.
14549 +
14550 +config TAGGING_INTERN
14551 +       bool    "UID32/GID32"
14552 +       help
14553 +         this uses otherwise reserved inode fields in the on
14554 +         disk representation, which limits the use to a few
14555 +         filesystems (currently ext2 and ext3)
14556 +
14557 +endchoice
14558 +
14559 +config TAG_NFSD
14560 +       bool    "Tag NFSD User Auth and Files"
14561 +       default n
14562 +       help
14563 +         Enable this if you do want the in-kernel NFS
14564 +         Server to use the tagging specified above.
14565 +         (will require patched clients too)
14566 +
14567 +config VSERVER_PRIVACY
14568 +       bool    "Honor Privacy Aspects of Guests"
14569 +       default n
14570 +       help
14571 +         When enabled, most context checks will disallow
14572 +         access to structures assigned to a specific context,
14573 +         like ptys or loop devices.
14574 +
14575 +config VSERVER_CONTEXTS
14576 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
14577 +       range 1 65533
14578 +       default "768"   if 64BIT
14579 +       default "256"
14580 +       help
14581 +         This setting will optimize certain data structures
14582 +         and memory allocations according to the expected
14583 +         maximum.
14584 +
14585 +         note: this is not a strict upper limit.
14586 +
14587 +config VSERVER_WARN
14588 +       bool    "VServer Warnings"
14589 +       default y
14590 +       help
14591 +         This enables various runtime warnings, which will
14592 +         notify about potential manipulation attempts or
14593 +         resource shortage. It is generally considered to
14594 +         be a good idea to have that enabled.
14595 +
14596 +config VSERVER_WARN_DEVPTS
14597 +       bool    "VServer DevPTS Warnings"
14598 +       depends on VSERVER_WARN
14599 +       default y
14600 +       help
14601 +         This enables DevPTS related warnings, issued when a
14602 +         process inside a context tries to lookup or access
14603 +         a dynamic pts from the host or a different context.
14604 +
14605 +config VSERVER_DEBUG
14606 +       bool    "VServer Debugging Code"
14607 +       default n
14608 +       help
14609 +         Set this to yes if you want to be able to activate
14610 +         debugging output at runtime. It adds a very small
14611 +         overhead to all vserver related functions and
14612 +         increases the kernel size by about 20k.
14613 +
14614 +config VSERVER_HISTORY
14615 +       bool    "VServer History Tracing"
14616 +       depends on VSERVER_DEBUG
14617 +       default n
14618 +       help
14619 +         Set this to yes if you want to record the history of
14620 +         linux-vserver activities, so they can be replayed in
14621 +         the event of a kernel panic or oops.
14622 +
14623 +config VSERVER_HISTORY_SIZE
14624 +       int     "Per-CPU History Size (32-65536)"
14625 +       depends on VSERVER_HISTORY
14626 +       range 32 65536
14627 +       default 64
14628 +       help
14629 +         This allows you to specify the number of entries in
14630 +         the per-CPU history buffer.
14631 +
14632 +config VSERVER_EXTRA_MNT_CHECK
14633 +       bool    "Extra Checks for Reachability"
14634 +       default n
14635 +       help
14636 +         Set this to yes if you want to do extra checks for
14637 +         vfsmount reachability in the proc filesystem code.
14638 +         This shouldn't be required on any setup utilizing
14639 +         mnt namespaces.
14640 +
14641 +choice
14642 +       prompt  "Quotes used in debug and warn messages"
14643 +       default QUOTES_ISO8859
14644 +
14645 +config QUOTES_ISO8859
14646 +       bool    "Extended ASCII (ISO 8859) angle quotes"
14647 +       help
14648 +         This uses the extended ASCII characters \xbb
14649 +         and \xab for quoting file and process names.
14650 +
14651 +config QUOTES_UTF8
14652 +       bool    "UTF-8 angle quotes"
14653 +       help
14654 +         This uses the the UTF-8 sequences for angle
14655 +         quotes to quote file and process names.
14656 +
14657 +config QUOTES_ASCII
14658 +       bool    "ASCII single quotes"
14659 +       help
14660 +         This uses the ASCII single quote character
14661 +         (\x27) to quote file and process names.
14662 +
14663 +endchoice
14664 +
14665 +endmenu
14666 +
14667 +
14668 +config VSERVER
14669 +       bool
14670 +       default y
14671 +       select NAMESPACES
14672 +       select UTS_NS
14673 +       select IPC_NS
14674 +#      select USER_NS
14675 +       select SYSVIPC
14676 +
14677 +config VSERVER_SECURITY
14678 +       bool
14679 +       depends on SECURITY
14680 +       default y
14681 +       select SECURITY_CAPABILITIES
14682 +
14683 +config VSERVER_DISABLED
14684 +       bool
14685 +       default n
14686 +
14687 diff -NurpP --minimal linux-3.13.1/kernel/vserver/Makefile linux-3.13.1-vs2.3.6.10/kernel/vserver/Makefile
14688 --- linux-3.13.1/kernel/vserver/Makefile        1970-01-01 00:00:00.000000000 +0000
14689 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/Makefile     2014-01-31 20:38:03.000000000 +0000
14690 @@ -0,0 +1,18 @@
14691 +#
14692 +# Makefile for the Linux vserver routines.
14693 +#
14694 +
14695 +
14696 +obj-y          += vserver.o
14697 +
14698 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
14699 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
14700 +                  dlimit.o tag.o
14701 +
14702 +vserver-$(CONFIG_INET) += inet.o
14703 +vserver-$(CONFIG_PROC_FS) += proc.o
14704 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
14705 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
14706 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
14707 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
14708 +
14709 diff -NurpP --minimal linux-3.13.1/kernel/vserver/cacct.c linux-3.13.1-vs2.3.6.10/kernel/vserver/cacct.c
14710 --- linux-3.13.1/kernel/vserver/cacct.c 1970-01-01 00:00:00.000000000 +0000
14711 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/cacct.c      2014-01-31 20:38:03.000000000 +0000
14712 @@ -0,0 +1,42 @@
14713 +/*
14714 + *  linux/kernel/vserver/cacct.c
14715 + *
14716 + *  Virtual Server: Context Accounting
14717 + *
14718 + *  Copyright (C) 2006-2007 Herbert Pötzl
14719 + *
14720 + *  V0.01  added accounting stats
14721 + *
14722 + */
14723 +
14724 +#include <linux/types.h>
14725 +#include <linux/vs_context.h>
14726 +#include <linux/vserver/cacct_cmd.h>
14727 +#include <linux/vserver/cacct_int.h>
14728 +
14729 +#include <asm/errno.h>
14730 +#include <asm/uaccess.h>
14731 +
14732 +
14733 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
14734 +{
14735 +       struct vcmd_sock_stat_v0 vc_data;
14736 +       int j, field;
14737 +
14738 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
14739 +               return -EFAULT;
14740 +
14741 +       field = vc_data.field;
14742 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
14743 +               return -EINVAL;
14744 +
14745 +       for (j = 0; j < 3; j++) {
14746 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
14747 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
14748 +       }
14749 +
14750 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
14751 +               return -EFAULT;
14752 +       return 0;
14753 +}
14754 +
14755 diff -NurpP --minimal linux-3.13.1/kernel/vserver/cacct_init.h linux-3.13.1-vs2.3.6.10/kernel/vserver/cacct_init.h
14756 --- linux-3.13.1/kernel/vserver/cacct_init.h    1970-01-01 00:00:00.000000000 +0000
14757 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/cacct_init.h 2014-01-31 20:38:03.000000000 +0000
14758 @@ -0,0 +1,25 @@
14759 +
14760 +
14761 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
14762 +{
14763 +       int i, j;
14764 +
14765 +
14766 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14767 +               for (j = 0; j < 3; j++) {
14768 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
14769 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
14770 +               }
14771 +       }
14772 +       for (i = 0; i < 8; i++)
14773 +               atomic_set(&cacct->slab[i], 0);
14774 +       for (i = 0; i < 5; i++)
14775 +               for (j = 0; j < 4; j++)
14776 +                       atomic_set(&cacct->page[i][j], 0);
14777 +}
14778 +
14779 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
14780 +{
14781 +       return;
14782 +}
14783 +
14784 diff -NurpP --minimal linux-3.13.1/kernel/vserver/cacct_proc.h linux-3.13.1-vs2.3.6.10/kernel/vserver/cacct_proc.h
14785 --- linux-3.13.1/kernel/vserver/cacct_proc.h    1970-01-01 00:00:00.000000000 +0000
14786 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/cacct_proc.h 2014-01-31 20:38:03.000000000 +0000
14787 @@ -0,0 +1,53 @@
14788 +#ifndef _VX_CACCT_PROC_H
14789 +#define _VX_CACCT_PROC_H
14790 +
14791 +#include <linux/vserver/cacct_int.h>
14792 +
14793 +
14794 +#define VX_SOCKA_TOP   \
14795 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
14796 +
14797 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
14798 +{
14799 +       int i, j, length = 0;
14800 +       static char *type[VXA_SOCK_SIZE] = {
14801 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
14802 +       };
14803 +
14804 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
14805 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14806 +               length += sprintf(buffer + length, "%s:", type[i]);
14807 +               for (j = 0; j < 3; j++) {
14808 +                       length += sprintf(buffer + length,
14809 +                               "\t%10lu/%-10lu",
14810 +                               vx_sock_count(cacct, i, j),
14811 +                               vx_sock_total(cacct, i, j));
14812 +               }
14813 +               buffer[length++] = '\n';
14814 +       }
14815 +
14816 +       length += sprintf(buffer + length, "\n");
14817 +       length += sprintf(buffer + length,
14818 +               "slab:\t %8u %8u %8u %8u\n",
14819 +               atomic_read(&cacct->slab[1]),
14820 +               atomic_read(&cacct->slab[4]),
14821 +               atomic_read(&cacct->slab[0]),
14822 +               atomic_read(&cacct->slab[2]));
14823 +
14824 +       length += sprintf(buffer + length, "\n");
14825 +       for (i = 0; i < 5; i++) {
14826 +               length += sprintf(buffer + length,
14827 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
14828 +                       atomic_read(&cacct->page[i][0]),
14829 +                       atomic_read(&cacct->page[i][1]),
14830 +                       atomic_read(&cacct->page[i][2]),
14831 +                       atomic_read(&cacct->page[i][3]),
14832 +                       atomic_read(&cacct->page[i][4]),
14833 +                       atomic_read(&cacct->page[i][5]),
14834 +                       atomic_read(&cacct->page[i][6]),
14835 +                       atomic_read(&cacct->page[i][7]));
14836 +       }
14837 +       return length;
14838 +}
14839 +
14840 +#endif /* _VX_CACCT_PROC_H */
14841 diff -NurpP --minimal linux-3.13.1/kernel/vserver/context.c linux-3.13.1-vs2.3.6.10/kernel/vserver/context.c
14842 --- linux-3.13.1/kernel/vserver/context.c       1970-01-01 00:00:00.000000000 +0000
14843 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/context.c    2014-01-31 20:38:03.000000000 +0000
14844 @@ -0,0 +1,1119 @@
14845 +/*
14846 + *  linux/kernel/vserver/context.c
14847 + *
14848 + *  Virtual Server: Context Support
14849 + *
14850 + *  Copyright (C) 2003-2011  Herbert Pötzl
14851 + *
14852 + *  V0.01  context helper
14853 + *  V0.02  vx_ctx_kill syscall command
14854 + *  V0.03  replaced context_info calls
14855 + *  V0.04  redesign of struct (de)alloc
14856 + *  V0.05  rlimit basic implementation
14857 + *  V0.06  task_xid and info commands
14858 + *  V0.07  context flags and caps
14859 + *  V0.08  switch to RCU based hash
14860 + *  V0.09  revert to non RCU for now
14861 + *  V0.10  and back to working RCU hash
14862 + *  V0.11  and back to locking again
14863 + *  V0.12  referenced context store
14864 + *  V0.13  separate per cpu data
14865 + *  V0.14  changed vcmds to vxi arg
14866 + *  V0.15  added context stat
14867 + *  V0.16  have __create claim() the vxi
14868 + *  V0.17  removed older and legacy stuff
14869 + *  V0.18  added user credentials
14870 + *  V0.19  added warn mask
14871 + *
14872 + */
14873 +
14874 +#include <linux/slab.h>
14875 +#include <linux/types.h>
14876 +#include <linux/security.h>
14877 +#include <linux/pid_namespace.h>
14878 +#include <linux/capability.h>
14879 +
14880 +#include <linux/vserver/context.h>
14881 +#include <linux/vserver/network.h>
14882 +#include <linux/vserver/debug.h>
14883 +#include <linux/vserver/limit.h>
14884 +#include <linux/vserver/limit_int.h>
14885 +#include <linux/vserver/space.h>
14886 +#include <linux/init_task.h>
14887 +#include <linux/fs_struct.h>
14888 +#include <linux/cred.h>
14889 +
14890 +#include <linux/vs_context.h>
14891 +#include <linux/vs_limit.h>
14892 +#include <linux/vs_pid.h>
14893 +#include <linux/vserver/context_cmd.h>
14894 +
14895 +#include "cvirt_init.h"
14896 +#include "cacct_init.h"
14897 +#include "limit_init.h"
14898 +#include "sched_init.h"
14899 +
14900 +
14901 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
14902 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
14903 +
14904 +
14905 +/*     now inactive context structures */
14906 +
14907 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
14908 +
14909 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
14910 +
14911 +
14912 +/*     __alloc_vx_info()
14913 +
14914 +       * allocate an initialized vx_info struct
14915 +       * doesn't make it visible (hash)                        */
14916 +
14917 +static struct vx_info *__alloc_vx_info(vxid_t xid)
14918 +{
14919 +       struct vx_info *new = NULL;
14920 +       int cpu, index;
14921 +
14922 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
14923 +
14924 +       /* would this benefit from a slab cache? */
14925 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
14926 +       if (!new)
14927 +               return 0;
14928 +
14929 +       memset(new, 0, sizeof(struct vx_info));
14930 +#ifdef CONFIG_SMP
14931 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
14932 +       if (!new->ptr_pc)
14933 +               goto error;
14934 +#endif
14935 +       new->vx_id = xid;
14936 +       INIT_HLIST_NODE(&new->vx_hlist);
14937 +       atomic_set(&new->vx_usecnt, 0);
14938 +       atomic_set(&new->vx_tasks, 0);
14939 +       new->vx_parent = NULL;
14940 +       new->vx_state = 0;
14941 +       init_waitqueue_head(&new->vx_wait);
14942 +
14943 +       /* prepare reaper */
14944 +       get_task_struct(init_pid_ns.child_reaper);
14945 +       new->vx_reaper = init_pid_ns.child_reaper;
14946 +       new->vx_badness_bias = 0;
14947 +
14948 +       /* rest of init goes here */
14949 +       vx_info_init_limit(&new->limit);
14950 +       vx_info_init_sched(&new->sched);
14951 +       vx_info_init_cvirt(&new->cvirt);
14952 +       vx_info_init_cacct(&new->cacct);
14953 +
14954 +       /* per cpu data structures */
14955 +       for_each_possible_cpu(cpu) {
14956 +               vx_info_init_sched_pc(
14957 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
14958 +               vx_info_init_cvirt_pc(
14959 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
14960 +       }
14961 +
14962 +       new->vx_flags = VXF_INIT_SET;
14963 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
14964 +       new->vx_ccaps = 0;
14965 +       new->vx_umask = 0;
14966 +       new->vx_wmask = 0;
14967 +
14968 +       new->reboot_cmd = 0;
14969 +       new->exit_code = 0;
14970 +
14971 +       // preconfig spaces
14972 +       for (index = 0; index < VX_SPACES; index++) {
14973 +               struct _vx_space *space = &new->space[index];
14974 +
14975 +               // filesystem
14976 +               spin_lock(&init_fs.lock);
14977 +               init_fs.users++;
14978 +               spin_unlock(&init_fs.lock);
14979 +               space->vx_fs = &init_fs;
14980 +
14981 +               /* FIXME: do we want defaults? */
14982 +               // space->vx_real_cred = 0;
14983 +               // space->vx_cred = 0;
14984 +       }
14985 +
14986 +
14987 +       vxdprintk(VXD_CBIT(xid, 0),
14988 +               "alloc_vx_info(%d) = %p", xid, new);
14989 +       vxh_alloc_vx_info(new);
14990 +       atomic_inc(&vx_global_ctotal);
14991 +       return new;
14992 +#ifdef CONFIG_SMP
14993 +error:
14994 +       kfree(new);
14995 +       return 0;
14996 +#endif
14997 +}
14998 +
14999 +/*     __dealloc_vx_info()
15000 +
15001 +       * final disposal of vx_info                             */
15002 +
15003 +static void __dealloc_vx_info(struct vx_info *vxi)
15004 +{
15005 +#ifdef CONFIG_VSERVER_WARN
15006 +       struct vx_info_save vxis;
15007 +       int cpu;
15008 +#endif
15009 +       vxdprintk(VXD_CBIT(xid, 0),
15010 +               "dealloc_vx_info(%p)", vxi);
15011 +       vxh_dealloc_vx_info(vxi);
15012 +
15013 +#ifdef CONFIG_VSERVER_WARN
15014 +       enter_vx_info(vxi, &vxis);
15015 +       vx_info_exit_limit(&vxi->limit);
15016 +       vx_info_exit_sched(&vxi->sched);
15017 +       vx_info_exit_cvirt(&vxi->cvirt);
15018 +       vx_info_exit_cacct(&vxi->cacct);
15019 +
15020 +       for_each_possible_cpu(cpu) {
15021 +               vx_info_exit_sched_pc(
15022 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15023 +               vx_info_exit_cvirt_pc(
15024 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15025 +       }
15026 +       leave_vx_info(&vxis);
15027 +#endif
15028 +
15029 +       vxi->vx_id = -1;
15030 +       vxi->vx_state |= VXS_RELEASED;
15031 +
15032 +#ifdef CONFIG_SMP
15033 +       free_percpu(vxi->ptr_pc);
15034 +#endif
15035 +       kfree(vxi);
15036 +       atomic_dec(&vx_global_ctotal);
15037 +}
15038 +
15039 +static void __shutdown_vx_info(struct vx_info *vxi)
15040 +{
15041 +       struct nsproxy *nsproxy;
15042 +       struct fs_struct *fs;
15043 +       struct cred *cred;
15044 +       int index, kill;
15045 +
15046 +       might_sleep();
15047 +
15048 +       vxi->vx_state |= VXS_SHUTDOWN;
15049 +       vs_state_change(vxi, VSC_SHUTDOWN);
15050 +
15051 +       for (index = 0; index < VX_SPACES; index++) {
15052 +               struct _vx_space *space = &vxi->space[index];
15053 +
15054 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15055 +               if (nsproxy)
15056 +                       put_nsproxy(nsproxy);
15057 +
15058 +               fs = xchg(&space->vx_fs, NULL);
15059 +               spin_lock(&fs->lock);
15060 +               kill = !--fs->users;
15061 +               spin_unlock(&fs->lock);
15062 +               if (kill)
15063 +                       free_fs_struct(fs);
15064 +
15065 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15066 +               if (cred)
15067 +                       abort_creds(cred);
15068 +       }
15069 +}
15070 +
15071 +/* exported stuff */
15072 +
15073 +void free_vx_info(struct vx_info *vxi)
15074 +{
15075 +       unsigned long flags;
15076 +       unsigned index;
15077 +
15078 +       /* check for reference counts first */
15079 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15080 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15081 +
15082 +       /* context must not be hashed */
15083 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15084 +
15085 +       /* context shutdown is mandatory */
15086 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15087 +
15088 +       /* spaces check */
15089 +       for (index = 0; index < VX_SPACES; index++) {
15090 +               struct _vx_space *space = &vxi->space[index];
15091 +
15092 +               BUG_ON(space->vx_nsproxy);
15093 +               BUG_ON(space->vx_fs);
15094 +               // BUG_ON(space->vx_real_cred);
15095 +               // BUG_ON(space->vx_cred);
15096 +       }
15097 +
15098 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15099 +       hlist_del(&vxi->vx_hlist);
15100 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15101 +
15102 +       __dealloc_vx_info(vxi);
15103 +}
15104 +
15105 +
15106 +/*     hash table for vx_info hash */
15107 +
15108 +#define VX_HASH_SIZE   13
15109 +
15110 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15111 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15112 +
15113 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15114 +
15115 +
15116 +static inline unsigned int __hashval(vxid_t xid)
15117 +{
15118 +       return (xid % VX_HASH_SIZE);
15119 +}
15120 +
15121 +
15122 +
15123 +/*     __hash_vx_info()
15124 +
15125 +       * add the vxi to the global hash table
15126 +       * requires the hash_lock to be held                     */
15127 +
15128 +static inline void __hash_vx_info(struct vx_info *vxi)
15129 +{
15130 +       struct hlist_head *head;
15131 +
15132 +       vxd_assert_lock(&vx_info_hash_lock);
15133 +       vxdprintk(VXD_CBIT(xid, 4),
15134 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15135 +       vxh_hash_vx_info(vxi);
15136 +
15137 +       /* context must not be hashed */
15138 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15139 +
15140 +       vxi->vx_state |= VXS_HASHED;
15141 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15142 +       hlist_add_head(&vxi->vx_hlist, head);
15143 +       atomic_inc(&vx_global_cactive);
15144 +}
15145 +
15146 +/*     __unhash_vx_info()
15147 +
15148 +       * remove the vxi from the global hash table
15149 +       * requires the hash_lock to be held                     */
15150 +
15151 +static inline void __unhash_vx_info(struct vx_info *vxi)
15152 +{
15153 +       unsigned long flags;
15154 +
15155 +       vxd_assert_lock(&vx_info_hash_lock);
15156 +       vxdprintk(VXD_CBIT(xid, 4),
15157 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15158 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15159 +       vxh_unhash_vx_info(vxi);
15160 +
15161 +       /* context must be hashed */
15162 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15163 +       /* but without tasks */
15164 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15165 +
15166 +       vxi->vx_state &= ~VXS_HASHED;
15167 +       hlist_del_init(&vxi->vx_hlist);
15168 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15169 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15170 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15171 +       atomic_dec(&vx_global_cactive);
15172 +}
15173 +
15174 +
15175 +/*     __lookup_vx_info()
15176 +
15177 +       * requires the hash_lock to be held
15178 +       * doesn't increment the vx_refcnt                       */
15179 +
15180 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
15181 +{
15182 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15183 +       struct hlist_node *pos;
15184 +       struct vx_info *vxi;
15185 +
15186 +       vxd_assert_lock(&vx_info_hash_lock);
15187 +       hlist_for_each(pos, head) {
15188 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15189 +
15190 +               if (vxi->vx_id == xid)
15191 +                       goto found;
15192 +       }
15193 +       vxi = NULL;
15194 +found:
15195 +       vxdprintk(VXD_CBIT(xid, 0),
15196 +               "__lookup_vx_info(#%u): %p[#%u]",
15197 +               xid, vxi, vxi ? vxi->vx_id : 0);
15198 +       vxh_lookup_vx_info(vxi, xid);
15199 +       return vxi;
15200 +}
15201 +
15202 +
15203 +/*     __create_vx_info()
15204 +
15205 +       * create the requested context
15206 +       * get(), claim() and hash it                            */
15207 +
15208 +static struct vx_info *__create_vx_info(int id)
15209 +{
15210 +       struct vx_info *new, *vxi = NULL;
15211 +
15212 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15213 +
15214 +       if (!(new = __alloc_vx_info(id)))
15215 +               return ERR_PTR(-ENOMEM);
15216 +
15217 +       /* required to make dynamic xids unique */
15218 +       spin_lock(&vx_info_hash_lock);
15219 +
15220 +       /* static context requested */
15221 +       if ((vxi = __lookup_vx_info(id))) {
15222 +               vxdprintk(VXD_CBIT(xid, 0),
15223 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15224 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15225 +                       vxi = ERR_PTR(-EBUSY);
15226 +               else
15227 +                       vxi = ERR_PTR(-EEXIST);
15228 +               goto out_unlock;
15229 +       }
15230 +       /* new context */
15231 +       vxdprintk(VXD_CBIT(xid, 0),
15232 +               "create_vx_info(%d) = %p (new)", id, new);
15233 +       claim_vx_info(new, NULL);
15234 +       __hash_vx_info(get_vx_info(new));
15235 +       vxi = new, new = NULL;
15236 +
15237 +out_unlock:
15238 +       spin_unlock(&vx_info_hash_lock);
15239 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15240 +       if (new)
15241 +               __dealloc_vx_info(new);
15242 +       return vxi;
15243 +}
15244 +
15245 +
15246 +/*     exported stuff                                          */
15247 +
15248 +
15249 +void unhash_vx_info(struct vx_info *vxi)
15250 +{
15251 +       spin_lock(&vx_info_hash_lock);
15252 +       __unhash_vx_info(vxi);
15253 +       spin_unlock(&vx_info_hash_lock);
15254 +       __shutdown_vx_info(vxi);
15255 +       __wakeup_vx_info(vxi);
15256 +}
15257 +
15258 +
15259 +/*     lookup_vx_info()
15260 +
15261 +       * search for a vx_info and get() it
15262 +       * negative id means current                             */
15263 +
15264 +struct vx_info *lookup_vx_info(int id)
15265 +{
15266 +       struct vx_info *vxi = NULL;
15267 +
15268 +       if (id < 0) {
15269 +               vxi = get_vx_info(current_vx_info());
15270 +       } else if (id > 1) {
15271 +               spin_lock(&vx_info_hash_lock);
15272 +               vxi = get_vx_info(__lookup_vx_info(id));
15273 +               spin_unlock(&vx_info_hash_lock);
15274 +       }
15275 +       return vxi;
15276 +}
15277 +
15278 +/*     xid_is_hashed()
15279 +
15280 +       * verify that xid is still hashed                       */
15281 +
15282 +int xid_is_hashed(vxid_t xid)
15283 +{
15284 +       int hashed;
15285 +
15286 +       spin_lock(&vx_info_hash_lock);
15287 +       hashed = (__lookup_vx_info(xid) != NULL);
15288 +       spin_unlock(&vx_info_hash_lock);
15289 +       return hashed;
15290 +}
15291 +
15292 +#ifdef CONFIG_PROC_FS
15293 +
15294 +/*     get_xid_list()
15295 +
15296 +       * get a subset of hashed xids for proc
15297 +       * assumes size is at least one                          */
15298 +
15299 +int get_xid_list(int index, unsigned int *xids, int size)
15300 +{
15301 +       int hindex, nr_xids = 0;
15302 +
15303 +       /* only show current and children */
15304 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15305 +               if (index > 0)
15306 +                       return 0;
15307 +               xids[nr_xids] = vx_current_xid();
15308 +               return 1;
15309 +       }
15310 +
15311 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15312 +               struct hlist_head *head = &vx_info_hash[hindex];
15313 +               struct hlist_node *pos;
15314 +
15315 +               spin_lock(&vx_info_hash_lock);
15316 +               hlist_for_each(pos, head) {
15317 +                       struct vx_info *vxi;
15318 +
15319 +                       if (--index > 0)
15320 +                               continue;
15321 +
15322 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15323 +                       xids[nr_xids] = vxi->vx_id;
15324 +                       if (++nr_xids >= size) {
15325 +                               spin_unlock(&vx_info_hash_lock);
15326 +                               goto out;
15327 +                       }
15328 +               }
15329 +               /* keep the lock time short */
15330 +               spin_unlock(&vx_info_hash_lock);
15331 +       }
15332 +out:
15333 +       return nr_xids;
15334 +}
15335 +#endif
15336 +
15337 +#ifdef CONFIG_VSERVER_DEBUG
15338 +
15339 +void   dump_vx_info_inactive(int level)
15340 +{
15341 +       struct hlist_node *entry, *next;
15342 +
15343 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
15344 +               struct vx_info *vxi =
15345 +                       list_entry(entry, struct vx_info, vx_hlist);
15346 +
15347 +               dump_vx_info(vxi, level);
15348 +       }
15349 +}
15350 +
15351 +#endif
15352 +
15353 +#if 0
15354 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
15355 +{
15356 +       struct user_struct *new_user, *old_user;
15357 +
15358 +       if (!p || !vxi)
15359 +               BUG();
15360 +
15361 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
15362 +               return -EACCES;
15363 +
15364 +       new_user = alloc_uid(vxi->vx_id, p->uid);
15365 +       if (!new_user)
15366 +               return -ENOMEM;
15367 +
15368 +       old_user = p->user;
15369 +       if (new_user != old_user) {
15370 +               atomic_inc(&new_user->processes);
15371 +               atomic_dec(&old_user->processes);
15372 +               p->user = new_user;
15373 +       }
15374 +       free_uid(old_user);
15375 +       return 0;
15376 +}
15377 +#endif
15378 +
15379 +#if 0
15380 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
15381 +{
15382 +       // p->cap_effective &= vxi->vx_cap_bset;
15383 +       p->cap_effective =
15384 +               cap_intersect(p->cap_effective, vxi->cap_bset);
15385 +       // p->cap_inheritable &= vxi->vx_cap_bset;
15386 +       p->cap_inheritable =
15387 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
15388 +       // p->cap_permitted &= vxi->vx_cap_bset;
15389 +       p->cap_permitted =
15390 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
15391 +}
15392 +#endif
15393 +
15394 +
15395 +#include <linux/file.h>
15396 +#include <linux/fdtable.h>
15397 +
15398 +static int vx_openfd_task(struct task_struct *tsk)
15399 +{
15400 +       struct files_struct *files = tsk->files;
15401 +       struct fdtable *fdt;
15402 +       const unsigned long *bptr;
15403 +       int count, total;
15404 +
15405 +       /* no rcu_read_lock() because of spin_lock() */
15406 +       spin_lock(&files->file_lock);
15407 +       fdt = files_fdtable(files);
15408 +       bptr = fdt->open_fds;
15409 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
15410 +       for (total = 0; count > 0; count--) {
15411 +               if (*bptr)
15412 +                       total += hweight_long(*bptr);
15413 +               bptr++;
15414 +       }
15415 +       spin_unlock(&files->file_lock);
15416 +       return total;
15417 +}
15418 +
15419 +
15420 +/*     for *space compatibility */
15421 +
15422 +asmlinkage long sys_unshare(unsigned long);
15423 +
15424 +/*
15425 + *     migrate task to new context
15426 + *     gets vxi, puts old_vxi on change
15427 + *     optionally unshares namespaces (hack)
15428 + */
15429 +
15430 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
15431 +{
15432 +       struct vx_info *old_vxi;
15433 +       int ret = 0;
15434 +
15435 +       if (!p || !vxi)
15436 +               BUG();
15437 +
15438 +       vxdprintk(VXD_CBIT(xid, 5),
15439 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
15440 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
15441 +
15442 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
15443 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15444 +               return -EACCES;
15445 +
15446 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
15447 +               return -EFAULT;
15448 +
15449 +       old_vxi = task_get_vx_info(p);
15450 +       if (old_vxi == vxi)
15451 +               goto out;
15452 +
15453 +//     if (!(ret = vx_migrate_user(p, vxi))) {
15454 +       {
15455 +               int openfd;
15456 +
15457 +               task_lock(p);
15458 +               openfd = vx_openfd_task(p);
15459 +
15460 +               if (old_vxi) {
15461 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
15462 +                       atomic_dec(&old_vxi->cvirt.nr_running);
15463 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
15464 +                       /* FIXME: what about the struct files here? */
15465 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
15466 +                       /* account for the executable */
15467 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
15468 +               }
15469 +               atomic_inc(&vxi->cvirt.nr_threads);
15470 +               atomic_inc(&vxi->cvirt.nr_running);
15471 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
15472 +               /* FIXME: what about the struct files here? */
15473 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
15474 +               /* account for the executable */
15475 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
15476 +
15477 +               if (old_vxi) {
15478 +                       release_vx_info(old_vxi, p);
15479 +                       clr_vx_info(&p->vx_info);
15480 +               }
15481 +               claim_vx_info(vxi, p);
15482 +               set_vx_info(&p->vx_info, vxi);
15483 +               p->xid = vxi->vx_id;
15484 +
15485 +               vxdprintk(VXD_CBIT(xid, 5),
15486 +                       "moved task %p into vxi:%p[#%d]",
15487 +                       p, vxi, vxi->vx_id);
15488 +
15489 +               // vx_mask_cap_bset(vxi, p);
15490 +               task_unlock(p);
15491 +
15492 +               /* hack for *spaces to provide compatibility */
15493 +               if (unshare) {
15494 +                       struct nsproxy *old_nsp, *new_nsp;
15495 +
15496 +                       ret = unshare_nsproxy_namespaces(
15497 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
15498 +                               &new_nsp, NULL, NULL);
15499 +                       if (ret)
15500 +                               goto out;
15501 +
15502 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
15503 +                       vx_set_space(vxi,
15504 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
15505 +                       put_nsproxy(old_nsp);
15506 +               }
15507 +       }
15508 +out:
15509 +       put_vx_info(old_vxi);
15510 +       return ret;
15511 +}
15512 +
15513 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
15514 +{
15515 +       struct task_struct *old_reaper;
15516 +       struct vx_info *reaper_vxi;
15517 +
15518 +       if (!vxi)
15519 +               return -EINVAL;
15520 +
15521 +       vxdprintk(VXD_CBIT(xid, 6),
15522 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
15523 +               vxi, vxi->vx_id, p, p->xid, p->pid);
15524 +
15525 +       old_reaper = vxi->vx_reaper;
15526 +       if (old_reaper == p)
15527 +               return 0;
15528 +
15529 +       reaper_vxi = task_get_vx_info(p);
15530 +       if (reaper_vxi && reaper_vxi != vxi) {
15531 +               vxwprintk(1,
15532 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
15533 +                       "for [xid #%u]",
15534 +                       p->comm, p->pid, p->xid, vx_current_xid());
15535 +               goto out;
15536 +       }
15537 +
15538 +       /* set new child reaper */
15539 +       get_task_struct(p);
15540 +       vxi->vx_reaper = p;
15541 +       put_task_struct(old_reaper);
15542 +out:
15543 +       put_vx_info(reaper_vxi);
15544 +       return 0;
15545 +}
15546 +
15547 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
15548 +{
15549 +       if (!vxi)
15550 +               return -EINVAL;
15551 +
15552 +       vxdprintk(VXD_CBIT(xid, 6),
15553 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
15554 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15555 +
15556 +       vxi->vx_flags &= ~VXF_STATE_INIT;
15557 +       // vxi->vx_initpid = p->tgid;
15558 +       vxi->vx_initpid = p->pid;
15559 +       return 0;
15560 +}
15561 +
15562 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
15563 +{
15564 +       vxdprintk(VXD_CBIT(xid, 6),
15565 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
15566 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15567 +
15568 +       vxi->exit_code = code;
15569 +       vxi->vx_initpid = 0;
15570 +}
15571 +
15572 +
15573 +void vx_set_persistent(struct vx_info *vxi)
15574 +{
15575 +       vxdprintk(VXD_CBIT(xid, 6),
15576 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
15577 +
15578 +       get_vx_info(vxi);
15579 +       claim_vx_info(vxi, NULL);
15580 +}
15581 +
15582 +void vx_clear_persistent(struct vx_info *vxi)
15583 +{
15584 +       vxdprintk(VXD_CBIT(xid, 6),
15585 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
15586 +
15587 +       release_vx_info(vxi, NULL);
15588 +       put_vx_info(vxi);
15589 +}
15590 +
15591 +void vx_update_persistent(struct vx_info *vxi)
15592 +{
15593 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
15594 +               vx_set_persistent(vxi);
15595 +       else
15596 +               vx_clear_persistent(vxi);
15597 +}
15598 +
15599 +
15600 +/*     task must be current or locked          */
15601 +
15602 +void   exit_vx_info(struct task_struct *p, int code)
15603 +{
15604 +       struct vx_info *vxi = p->vx_info;
15605 +
15606 +       if (vxi) {
15607 +               atomic_dec(&vxi->cvirt.nr_threads);
15608 +               vx_nproc_dec(p);
15609 +
15610 +               vxi->exit_code = code;
15611 +               release_vx_info(vxi, p);
15612 +       }
15613 +}
15614 +
15615 +void   exit_vx_info_early(struct task_struct *p, int code)
15616 +{
15617 +       struct vx_info *vxi = p->vx_info;
15618 +
15619 +       if (vxi) {
15620 +               if (vxi->vx_initpid == p->pid)
15621 +                       vx_exit_init(vxi, p, code);
15622 +               if (vxi->vx_reaper == p)
15623 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
15624 +       }
15625 +}
15626 +
15627 +
15628 +/* vserver syscall commands below here */
15629 +
15630 +/* taks xid and vx_info functions */
15631 +
15632 +#include <asm/uaccess.h>
15633 +
15634 +
15635 +int vc_task_xid(uint32_t id)
15636 +{
15637 +       vxid_t xid;
15638 +
15639 +       if (id) {
15640 +               struct task_struct *tsk;
15641 +
15642 +               rcu_read_lock();
15643 +               tsk = find_task_by_real_pid(id);
15644 +               xid = (tsk) ? tsk->xid : -ESRCH;
15645 +               rcu_read_unlock();
15646 +       } else
15647 +               xid = vx_current_xid();
15648 +       return xid;
15649 +}
15650 +
15651 +
15652 +int vc_vx_info(struct vx_info *vxi, void __user *data)
15653 +{
15654 +       struct vcmd_vx_info_v0 vc_data;
15655 +
15656 +       vc_data.xid = vxi->vx_id;
15657 +       vc_data.initpid = vxi->vx_initpid;
15658 +
15659 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15660 +               return -EFAULT;
15661 +       return 0;
15662 +}
15663 +
15664 +
15665 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
15666 +{
15667 +       struct vcmd_ctx_stat_v0 vc_data;
15668 +
15669 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
15670 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
15671 +
15672 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15673 +               return -EFAULT;
15674 +       return 0;
15675 +}
15676 +
15677 +
15678 +/* context functions */
15679 +
15680 +int vc_ctx_create(uint32_t xid, void __user *data)
15681 +{
15682 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
15683 +       struct vx_info *new_vxi;
15684 +       int ret;
15685 +
15686 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15687 +               return -EFAULT;
15688 +
15689 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
15690 +               return -EINVAL;
15691 +
15692 +       new_vxi = __create_vx_info(xid);
15693 +       if (IS_ERR(new_vxi))
15694 +               return PTR_ERR(new_vxi);
15695 +
15696 +       /* initial flags */
15697 +       new_vxi->vx_flags = vc_data.flagword;
15698 +
15699 +       ret = -ENOEXEC;
15700 +       if (vs_state_change(new_vxi, VSC_STARTUP))
15701 +               goto out;
15702 +
15703 +       ret = vx_migrate_task(current, new_vxi, (!data));
15704 +       if (ret)
15705 +               goto out;
15706 +
15707 +       /* return context id on success */
15708 +       ret = new_vxi->vx_id;
15709 +
15710 +       /* get a reference for persistent contexts */
15711 +       if ((vc_data.flagword & VXF_PERSISTENT))
15712 +               vx_set_persistent(new_vxi);
15713 +out:
15714 +       release_vx_info(new_vxi, NULL);
15715 +       put_vx_info(new_vxi);
15716 +       return ret;
15717 +}
15718 +
15719 +
15720 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
15721 +{
15722 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
15723 +       int ret;
15724 +
15725 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15726 +               return -EFAULT;
15727 +
15728 +       ret = vx_migrate_task(current, vxi, 0);
15729 +       if (ret)
15730 +               return ret;
15731 +       if (vc_data.flagword & VXM_SET_INIT)
15732 +               ret = vx_set_init(vxi, current);
15733 +       if (ret)
15734 +               return ret;
15735 +       if (vc_data.flagword & VXM_SET_REAPER)
15736 +               ret = vx_set_reaper(vxi, current);
15737 +       return ret;
15738 +}
15739 +
15740 +
15741 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
15742 +{
15743 +       struct vcmd_ctx_flags_v0 vc_data;
15744 +
15745 +       vc_data.flagword = vxi->vx_flags;
15746 +
15747 +       /* special STATE flag handling */
15748 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
15749 +
15750 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15751 +               return -EFAULT;
15752 +       return 0;
15753 +}
15754 +
15755 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
15756 +{
15757 +       struct vcmd_ctx_flags_v0 vc_data;
15758 +       uint64_t mask, trigger;
15759 +
15760 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15761 +               return -EFAULT;
15762 +
15763 +       /* special STATE flag handling */
15764 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
15765 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
15766 +
15767 +       if (vxi == current_vx_info()) {
15768 +               /* if (trigger & VXF_STATE_SETUP)
15769 +                       vx_mask_cap_bset(vxi, current); */
15770 +               if (trigger & VXF_STATE_INIT) {
15771 +                       int ret;
15772 +
15773 +                       ret = vx_set_init(vxi, current);
15774 +                       if (ret)
15775 +                               return ret;
15776 +                       ret = vx_set_reaper(vxi, current);
15777 +                       if (ret)
15778 +                               return ret;
15779 +               }
15780 +       }
15781 +
15782 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
15783 +               vc_data.flagword, mask);
15784 +       if (trigger & VXF_PERSISTENT)
15785 +               vx_update_persistent(vxi);
15786 +
15787 +       return 0;
15788 +}
15789 +
15790 +
15791 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
15792 +{
15793 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
15794 +
15795 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
15796 +       return v;
15797 +}
15798 +
15799 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
15800 +{
15801 +       kernel_cap_t c = __cap_empty_set;
15802 +
15803 +       c.cap[0] = v & 0xFFFFFFFF;
15804 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
15805 +
15806 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
15807 +       return c;
15808 +}
15809 +
15810 +
15811 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
15812 +{
15813 +       if (bcaps)
15814 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
15815 +       if (ccaps)
15816 +               *ccaps = vxi->vx_ccaps;
15817 +
15818 +       return 0;
15819 +}
15820 +
15821 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
15822 +{
15823 +       struct vcmd_ctx_caps_v1 vc_data;
15824 +       int ret;
15825 +
15826 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
15827 +       if (ret)
15828 +               return ret;
15829 +       vc_data.cmask = ~0ULL;
15830 +
15831 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15832 +               return -EFAULT;
15833 +       return 0;
15834 +}
15835 +
15836 +static int do_set_caps(struct vx_info *vxi,
15837 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
15838 +{
15839 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
15840 +
15841 +#if 0
15842 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
15843 +               bcaps, bmask, ccaps, cmask);
15844 +#endif
15845 +       vxi->vx_bcaps = cap_t_from_caps(
15846 +               vs_mask_flags(bcold, bcaps, bmask));
15847 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
15848 +
15849 +       return 0;
15850 +}
15851 +
15852 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
15853 +{
15854 +       struct vcmd_ctx_caps_v1 vc_data;
15855 +
15856 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15857 +               return -EFAULT;
15858 +
15859 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
15860 +}
15861 +
15862 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
15863 +{
15864 +       struct vcmd_bcaps vc_data;
15865 +       int ret;
15866 +
15867 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
15868 +       if (ret)
15869 +               return ret;
15870 +       vc_data.bmask = ~0ULL;
15871 +
15872 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15873 +               return -EFAULT;
15874 +       return 0;
15875 +}
15876 +
15877 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
15878 +{
15879 +       struct vcmd_bcaps vc_data;
15880 +
15881 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15882 +               return -EFAULT;
15883 +
15884 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
15885 +}
15886 +
15887 +
15888 +int vc_get_umask(struct vx_info *vxi, void __user *data)
15889 +{
15890 +       struct vcmd_umask vc_data;
15891 +
15892 +       vc_data.umask = vxi->vx_umask;
15893 +       vc_data.mask = ~0ULL;
15894 +
15895 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15896 +               return -EFAULT;
15897 +       return 0;
15898 +}
15899 +
15900 +int vc_set_umask(struct vx_info *vxi, void __user *data)
15901 +{
15902 +       struct vcmd_umask vc_data;
15903 +
15904 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15905 +               return -EFAULT;
15906 +
15907 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
15908 +               vc_data.umask, vc_data.mask);
15909 +       return 0;
15910 +}
15911 +
15912 +
15913 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
15914 +{
15915 +       struct vcmd_wmask vc_data;
15916 +
15917 +       vc_data.wmask = vxi->vx_wmask;
15918 +       vc_data.mask = ~0ULL;
15919 +
15920 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15921 +               return -EFAULT;
15922 +       return 0;
15923 +}
15924 +
15925 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
15926 +{
15927 +       struct vcmd_wmask vc_data;
15928 +
15929 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15930 +               return -EFAULT;
15931 +
15932 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
15933 +               vc_data.wmask, vc_data.mask);
15934 +       return 0;
15935 +}
15936 +
15937 +
15938 +int vc_get_badness(struct vx_info *vxi, void __user *data)
15939 +{
15940 +       struct vcmd_badness_v0 vc_data;
15941 +
15942 +       vc_data.bias = vxi->vx_badness_bias;
15943 +
15944 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15945 +               return -EFAULT;
15946 +       return 0;
15947 +}
15948 +
15949 +int vc_set_badness(struct vx_info *vxi, void __user *data)
15950 +{
15951 +       struct vcmd_badness_v0 vc_data;
15952 +
15953 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15954 +               return -EFAULT;
15955 +
15956 +       vxi->vx_badness_bias = vc_data.bias;
15957 +       return 0;
15958 +}
15959 +
15960 +#include <linux/module.h>
15961 +
15962 +EXPORT_SYMBOL_GPL(free_vx_info);
15963 +
15964 diff -NurpP --minimal linux-3.13.1/kernel/vserver/cvirt.c linux-3.13.1-vs2.3.6.10/kernel/vserver/cvirt.c
15965 --- linux-3.13.1/kernel/vserver/cvirt.c 1970-01-01 00:00:00.000000000 +0000
15966 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/cvirt.c      2014-01-31 20:38:04.000000000 +0000
15967 @@ -0,0 +1,313 @@
15968 +/*
15969 + *  linux/kernel/vserver/cvirt.c
15970 + *
15971 + *  Virtual Server: Context Virtualization
15972 + *
15973 + *  Copyright (C) 2004-2007  Herbert Pötzl
15974 + *
15975 + *  V0.01  broken out from limit.c
15976 + *  V0.02  added utsname stuff
15977 + *  V0.03  changed vcmds to vxi arg
15978 + *
15979 + */
15980 +
15981 +#include <linux/types.h>
15982 +#include <linux/utsname.h>
15983 +#include <linux/vs_cvirt.h>
15984 +#include <linux/vserver/switch.h>
15985 +#include <linux/vserver/cvirt_cmd.h>
15986 +
15987 +#include <asm/uaccess.h>
15988 +
15989 +
15990 +void vx_vsi_boottime(struct timespec *boottime)
15991 +{
15992 +       struct vx_info *vxi = current_vx_info();
15993 +
15994 +       set_normalized_timespec(boottime,
15995 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
15996 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
15997 +       return;
15998 +}
15999 +
16000 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16001 +{
16002 +       struct vx_info *vxi = current_vx_info();
16003 +
16004 +       set_normalized_timespec(uptime,
16005 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16006 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16007 +       if (!idle)
16008 +               return;
16009 +       set_normalized_timespec(idle,
16010 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16011 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16012 +       return;
16013 +}
16014 +
16015 +uint64_t vx_idle_jiffies(void)
16016 +{
16017 +       return init_task.utime + init_task.stime;
16018 +}
16019 +
16020 +
16021 +
16022 +static inline uint32_t __update_loadavg(uint32_t load,
16023 +       int wsize, int delta, int n)
16024 +{
16025 +       unsigned long long calc, prev;
16026 +
16027 +       /* just set it to n */
16028 +       if (unlikely(delta >= wsize))
16029 +               return (n << FSHIFT);
16030 +
16031 +       calc = delta * n;
16032 +       calc <<= FSHIFT;
16033 +       prev = (wsize - delta);
16034 +       prev *= load;
16035 +       calc += prev;
16036 +       do_div(calc, wsize);
16037 +       return calc;
16038 +}
16039 +
16040 +
16041 +void vx_update_load(struct vx_info *vxi)
16042 +{
16043 +       uint32_t now, last, delta;
16044 +       unsigned int nr_running, nr_uninterruptible;
16045 +       unsigned int total;
16046 +       unsigned long flags;
16047 +
16048 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16049 +
16050 +       now = jiffies;
16051 +       last = vxi->cvirt.load_last;
16052 +       delta = now - last;
16053 +
16054 +       if (delta < 5*HZ)
16055 +               goto out;
16056 +
16057 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16058 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16059 +       total = nr_running + nr_uninterruptible;
16060 +
16061 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16062 +               60*HZ, delta, total);
16063 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16064 +               5*60*HZ, delta, total);
16065 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16066 +               15*60*HZ, delta, total);
16067 +
16068 +       vxi->cvirt.load_last = now;
16069 +out:
16070 +       atomic_inc(&vxi->cvirt.load_updates);
16071 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16072 +}
16073 +
16074 +
16075 +/*
16076 + * Commands to do_syslog:
16077 + *
16078 + *      0 -- Close the log.  Currently a NOP.
16079 + *      1 -- Open the log. Currently a NOP.
16080 + *      2 -- Read from the log.
16081 + *      3 -- Read all messages remaining in the ring buffer.
16082 + *      4 -- Read and clear all messages remaining in the ring buffer
16083 + *      5 -- Clear ring buffer.
16084 + *      6 -- Disable printk's to console
16085 + *      7 -- Enable printk's to console
16086 + *      8 -- Set level of messages printed to console
16087 + *      9 -- Return number of unread characters in the log buffer
16088 + *     10 -- Return size of the log buffer
16089 + */
16090 +int vx_do_syslog(int type, char __user *buf, int len)
16091 +{
16092 +       int error = 0;
16093 +       int do_clear = 0;
16094 +       struct vx_info *vxi = current_vx_info();
16095 +       struct _vx_syslog *log;
16096 +
16097 +       if (!vxi)
16098 +               return -EINVAL;
16099 +       log = &vxi->cvirt.syslog;
16100 +
16101 +       switch (type) {
16102 +       case 0:         /* Close log */
16103 +       case 1:         /* Open log */
16104 +               break;
16105 +       case 2:         /* Read from log */
16106 +               error = wait_event_interruptible(log->log_wait,
16107 +                       (log->log_start - log->log_end));
16108 +               if (error)
16109 +                       break;
16110 +               spin_lock_irq(&log->logbuf_lock);
16111 +               spin_unlock_irq(&log->logbuf_lock);
16112 +               break;
16113 +       case 4:         /* Read/clear last kernel messages */
16114 +               do_clear = 1;
16115 +               /* fall through */
16116 +       case 3:         /* Read last kernel messages */
16117 +               return 0;
16118 +
16119 +       case 5:         /* Clear ring buffer */
16120 +               return 0;
16121 +
16122 +       case 6:         /* Disable logging to console */
16123 +       case 7:         /* Enable logging to console */
16124 +       case 8:         /* Set level of messages printed to console */
16125 +               break;
16126 +
16127 +       case 9:         /* Number of chars in the log buffer */
16128 +               return 0;
16129 +       case 10:        /* Size of the log buffer */
16130 +               return 0;
16131 +       default:
16132 +               error = -EINVAL;
16133 +               break;
16134 +       }
16135 +       return error;
16136 +}
16137 +
16138 +
16139 +/* virtual host info names */
16140 +
16141 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16142 +{
16143 +       struct nsproxy *nsproxy;
16144 +       struct uts_namespace *uts;
16145 +
16146 +       if (id == VHIN_CONTEXT)
16147 +               return vxi->vx_name;
16148 +
16149 +       nsproxy = vxi->space[0].vx_nsproxy;
16150 +       if (!nsproxy)
16151 +               return NULL;
16152 +
16153 +       uts = nsproxy->uts_ns;
16154 +       if (!uts)
16155 +               return NULL;
16156 +
16157 +       switch (id) {
16158 +       case VHIN_SYSNAME:
16159 +               return uts->name.sysname;
16160 +       case VHIN_NODENAME:
16161 +               return uts->name.nodename;
16162 +       case VHIN_RELEASE:
16163 +               return uts->name.release;
16164 +       case VHIN_VERSION:
16165 +               return uts->name.version;
16166 +       case VHIN_MACHINE:
16167 +               return uts->name.machine;
16168 +       case VHIN_DOMAINNAME:
16169 +               return uts->name.domainname;
16170 +       default:
16171 +               return NULL;
16172 +       }
16173 +       return NULL;
16174 +}
16175 +
16176 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16177 +{
16178 +       struct vcmd_vhi_name_v0 vc_data;
16179 +       char *name;
16180 +
16181 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16182 +               return -EFAULT;
16183 +
16184 +       name = vx_vhi_name(vxi, vc_data.field);
16185 +       if (!name)
16186 +               return -EINVAL;
16187 +
16188 +       memcpy(name, vc_data.name, 65);
16189 +       return 0;
16190 +}
16191 +
16192 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16193 +{
16194 +       struct vcmd_vhi_name_v0 vc_data;
16195 +       char *name;
16196 +
16197 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16198 +               return -EFAULT;
16199 +
16200 +       name = vx_vhi_name(vxi, vc_data.field);
16201 +       if (!name)
16202 +               return -EINVAL;
16203 +
16204 +       memcpy(vc_data.name, name, 65);
16205 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16206 +               return -EFAULT;
16207 +       return 0;
16208 +}
16209 +
16210 +
16211 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16212 +{
16213 +       struct vcmd_virt_stat_v0 vc_data;
16214 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16215 +       struct timespec uptime;
16216 +
16217 +       do_posix_clock_monotonic_gettime(&uptime);
16218 +       set_normalized_timespec(&uptime,
16219 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16220 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16221 +
16222 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16223 +       vc_data.uptime = timespec_to_ns(&uptime);
16224 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16225 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16226 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16227 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16228 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16229 +       vc_data.load[0] = cvirt->load[0];
16230 +       vc_data.load[1] = cvirt->load[1];
16231 +       vc_data.load[2] = cvirt->load[2];
16232 +
16233 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16234 +               return -EFAULT;
16235 +       return 0;
16236 +}
16237 +
16238 +
16239 +#ifdef CONFIG_VSERVER_VTIME
16240 +
16241 +/* virtualized time base */
16242 +
16243 +void vx_adjust_timespec(struct timespec *ts)
16244 +{
16245 +       struct vx_info *vxi;
16246 +
16247 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16248 +               return;
16249 +
16250 +       vxi = current_vx_info();
16251 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16252 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16253 +
16254 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
16255 +               ts->tv_sec++;
16256 +               ts->tv_nsec -= NSEC_PER_SEC;
16257 +       } else if (ts->tv_nsec < 0) {
16258 +               ts->tv_sec--;
16259 +               ts->tv_nsec += NSEC_PER_SEC;
16260 +       }
16261 +}
16262 +
16263 +int vx_settimeofday(const struct timespec *ts)
16264 +{
16265 +       struct timespec ats, delta;
16266 +       struct vx_info *vxi;
16267 +
16268 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16269 +               return do_settimeofday(ts);
16270 +
16271 +       getnstimeofday(&ats);
16272 +       delta = timespec_sub(*ts, ats);
16273 +
16274 +       vxi = current_vx_info();
16275 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16276 +       return 0;
16277 +}
16278 +
16279 +#endif
16280 +
16281 diff -NurpP --minimal linux-3.13.1/kernel/vserver/cvirt_init.h linux-3.13.1-vs2.3.6.10/kernel/vserver/cvirt_init.h
16282 --- linux-3.13.1/kernel/vserver/cvirt_init.h    1970-01-01 00:00:00.000000000 +0000
16283 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/cvirt_init.h 2014-01-31 20:38:04.000000000 +0000
16284 @@ -0,0 +1,70 @@
16285 +
16286 +
16287 +extern uint64_t vx_idle_jiffies(void);
16288 +
16289 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16290 +{
16291 +       uint64_t idle_jiffies = vx_idle_jiffies();
16292 +       uint64_t nsuptime;
16293 +
16294 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16295 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16296 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16297 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16298 +       cvirt->bias_ts.tv_sec = 0;
16299 +       cvirt->bias_ts.tv_nsec = 0;
16300 +
16301 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16302 +       atomic_set(&cvirt->nr_threads, 0);
16303 +       atomic_set(&cvirt->nr_running, 0);
16304 +       atomic_set(&cvirt->nr_uninterruptible, 0);
16305 +       atomic_set(&cvirt->nr_onhold, 0);
16306 +
16307 +       spin_lock_init(&cvirt->load_lock);
16308 +       cvirt->load_last = jiffies;
16309 +       atomic_set(&cvirt->load_updates, 0);
16310 +       cvirt->load[0] = 0;
16311 +       cvirt->load[1] = 0;
16312 +       cvirt->load[2] = 0;
16313 +       atomic_set(&cvirt->total_forks, 0);
16314 +
16315 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
16316 +       init_waitqueue_head(&cvirt->syslog.log_wait);
16317 +       cvirt->syslog.log_start = 0;
16318 +       cvirt->syslog.log_end = 0;
16319 +       cvirt->syslog.con_start = 0;
16320 +       cvirt->syslog.logged_chars = 0;
16321 +}
16322 +
16323 +static inline
16324 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16325 +{
16326 +       // cvirt_pc->cpustat = { 0 };
16327 +}
16328 +
16329 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16330 +{
16331 +#ifdef CONFIG_VSERVER_WARN
16332 +       int value;
16333 +#endif
16334 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16335 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
16336 +               cvirt, value);
16337 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16338 +               "!!! cvirt: %p[nr_running] = %d on exit.",
16339 +               cvirt, value);
16340 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16341 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16342 +               cvirt, value);
16343 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16344 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
16345 +               cvirt, value);
16346 +       return;
16347 +}
16348 +
16349 +static inline
16350 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16351 +{
16352 +       return;
16353 +}
16354 +
16355 diff -NurpP --minimal linux-3.13.1/kernel/vserver/cvirt_proc.h linux-3.13.1-vs2.3.6.10/kernel/vserver/cvirt_proc.h
16356 --- linux-3.13.1/kernel/vserver/cvirt_proc.h    1970-01-01 00:00:00.000000000 +0000
16357 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/cvirt_proc.h 2014-01-31 20:38:04.000000000 +0000
16358 @@ -0,0 +1,123 @@
16359 +#ifndef _VX_CVIRT_PROC_H
16360 +#define _VX_CVIRT_PROC_H
16361 +
16362 +#include <linux/nsproxy.h>
16363 +#include <linux/mnt_namespace.h>
16364 +#include <linux/ipc_namespace.h>
16365 +#include <linux/utsname.h>
16366 +#include <linux/ipc.h>
16367 +
16368 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
16369 +
16370 +static inline
16371 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
16372 +{
16373 +       struct mnt_namespace *ns;
16374 +       struct uts_namespace *uts;
16375 +       struct ipc_namespace *ipc;
16376 +       int length = 0;
16377 +
16378 +       if (!nsproxy)
16379 +               goto out;
16380 +
16381 +       length += sprintf(buffer + length,
16382 +               "NSProxy:\t%p [%p,%p,%p]\n",
16383 +               nsproxy, nsproxy->mnt_ns,
16384 +               nsproxy->uts_ns, nsproxy->ipc_ns);
16385 +
16386 +       ns = nsproxy->mnt_ns;
16387 +       if (!ns)
16388 +               goto skip_ns;
16389 +
16390 +       length += vx_info_mnt_namespace(ns, buffer + length);
16391 +
16392 +skip_ns:
16393 +
16394 +       uts = nsproxy->uts_ns;
16395 +       if (!uts)
16396 +               goto skip_uts;
16397 +
16398 +       length += sprintf(buffer + length,
16399 +               "SysName:\t%.*s\n"
16400 +               "NodeName:\t%.*s\n"
16401 +               "Release:\t%.*s\n"
16402 +               "Version:\t%.*s\n"
16403 +               "Machine:\t%.*s\n"
16404 +               "DomainName:\t%.*s\n",
16405 +               __NEW_UTS_LEN, uts->name.sysname,
16406 +               __NEW_UTS_LEN, uts->name.nodename,
16407 +               __NEW_UTS_LEN, uts->name.release,
16408 +               __NEW_UTS_LEN, uts->name.version,
16409 +               __NEW_UTS_LEN, uts->name.machine,
16410 +               __NEW_UTS_LEN, uts->name.domainname);
16411 +skip_uts:
16412 +
16413 +       ipc = nsproxy->ipc_ns;
16414 +       if (!ipc)
16415 +               goto skip_ipc;
16416 +
16417 +       length += sprintf(buffer + length,
16418 +               "SEMS:\t\t%d %d %d %d  %d\n"
16419 +               "MSG:\t\t%d %d %d\n"
16420 +               "SHM:\t\t%lu %lu  %d %ld\n",
16421 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
16422 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
16423 +               ipc->used_sems,
16424 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
16425 +               (unsigned long)ipc->shm_ctlmax,
16426 +               (unsigned long)ipc->shm_ctlall,
16427 +               ipc->shm_ctlmni, ipc->shm_tot);
16428 +skip_ipc:
16429 +out:
16430 +       return length;
16431 +}
16432 +
16433 +
16434 +#include <linux/sched.h>
16435 +
16436 +#define LOAD_INT(x) ((x) >> FSHIFT)
16437 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
16438 +
16439 +static inline
16440 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
16441 +{
16442 +       int length = 0;
16443 +       int a, b, c;
16444 +
16445 +       length += sprintf(buffer + length,
16446 +               "BiasUptime:\t%lu.%02lu\n",
16447 +               (unsigned long)cvirt->bias_uptime.tv_sec,
16448 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
16449 +
16450 +       a = cvirt->load[0] + (FIXED_1 / 200);
16451 +       b = cvirt->load[1] + (FIXED_1 / 200);
16452 +       c = cvirt->load[2] + (FIXED_1 / 200);
16453 +       length += sprintf(buffer + length,
16454 +               "nr_threads:\t%d\n"
16455 +               "nr_running:\t%d\n"
16456 +               "nr_unintr:\t%d\n"
16457 +               "nr_onhold:\t%d\n"
16458 +               "load_updates:\t%d\n"
16459 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
16460 +               "total_forks:\t%d\n",
16461 +               atomic_read(&cvirt->nr_threads),
16462 +               atomic_read(&cvirt->nr_running),
16463 +               atomic_read(&cvirt->nr_uninterruptible),
16464 +               atomic_read(&cvirt->nr_onhold),
16465 +               atomic_read(&cvirt->load_updates),
16466 +               LOAD_INT(a), LOAD_FRAC(a),
16467 +               LOAD_INT(b), LOAD_FRAC(b),
16468 +               LOAD_INT(c), LOAD_FRAC(c),
16469 +               atomic_read(&cvirt->total_forks));
16470 +       return length;
16471 +}
16472 +
16473 +static inline
16474 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
16475 +       char *buffer, int cpu)
16476 +{
16477 +       int length = 0;
16478 +       return length;
16479 +}
16480 +
16481 +#endif /* _VX_CVIRT_PROC_H */
16482 diff -NurpP --minimal linux-3.13.1/kernel/vserver/debug.c linux-3.13.1-vs2.3.6.10/kernel/vserver/debug.c
16483 --- linux-3.13.1/kernel/vserver/debug.c 1970-01-01 00:00:00.000000000 +0000
16484 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/debug.c      2014-01-31 20:38:04.000000000 +0000
16485 @@ -0,0 +1,32 @@
16486 +/*
16487 + *  kernel/vserver/debug.c
16488 + *
16489 + *  Copyright (C) 2005-2007 Herbert Pötzl
16490 + *
16491 + *  V0.01  vx_info dump support
16492 + *
16493 + */
16494 +
16495 +#include <linux/module.h>
16496 +
16497 +#include <linux/vserver/context.h>
16498 +
16499 +
16500 +void   dump_vx_info(struct vx_info *vxi, int level)
16501 +{
16502 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
16503 +               atomic_read(&vxi->vx_usecnt),
16504 +               atomic_read(&vxi->vx_tasks),
16505 +               vxi->vx_state);
16506 +       if (level > 0) {
16507 +               __dump_vx_limit(&vxi->limit);
16508 +               __dump_vx_sched(&vxi->sched);
16509 +               __dump_vx_cvirt(&vxi->cvirt);
16510 +               __dump_vx_cacct(&vxi->cacct);
16511 +       }
16512 +       printk("---\n");
16513 +}
16514 +
16515 +
16516 +EXPORT_SYMBOL_GPL(dump_vx_info);
16517 +
16518 diff -NurpP --minimal linux-3.13.1/kernel/vserver/device.c linux-3.13.1-vs2.3.6.10/kernel/vserver/device.c
16519 --- linux-3.13.1/kernel/vserver/device.c        1970-01-01 00:00:00.000000000 +0000
16520 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/device.c     2014-01-31 20:38:04.000000000 +0000
16521 @@ -0,0 +1,443 @@
16522 +/*
16523 + *  linux/kernel/vserver/device.c
16524 + *
16525 + *  Linux-VServer: Device Support
16526 + *
16527 + *  Copyright (C) 2006  Herbert Pötzl
16528 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
16529 + *
16530 + *  V0.01  device mapping basics
16531 + *  V0.02  added defaults
16532 + *
16533 + */
16534 +
16535 +#include <linux/slab.h>
16536 +#include <linux/rcupdate.h>
16537 +#include <linux/fs.h>
16538 +#include <linux/namei.h>
16539 +#include <linux/hash.h>
16540 +
16541 +#include <asm/errno.h>
16542 +#include <asm/uaccess.h>
16543 +#include <linux/vserver/base.h>
16544 +#include <linux/vserver/debug.h>
16545 +#include <linux/vserver/context.h>
16546 +#include <linux/vserver/device.h>
16547 +#include <linux/vserver/device_cmd.h>
16548 +
16549 +
16550 +#define DMAP_HASH_BITS 4
16551 +
16552 +
16553 +struct vs_mapping {
16554 +       union {
16555 +               struct hlist_node hlist;
16556 +               struct list_head list;
16557 +       } u;
16558 +#define dm_hlist       u.hlist
16559 +#define dm_list                u.list
16560 +       vxid_t xid;
16561 +       dev_t device;
16562 +       struct vx_dmap_target target;
16563 +};
16564 +
16565 +
16566 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
16567 +
16568 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
16569 +
16570 +static struct vx_dmap_target dmap_defaults[2] = {
16571 +       { .flags = DATTR_OPEN },
16572 +       { .flags = DATTR_OPEN },
16573 +};
16574 +
16575 +
16576 +struct kmem_cache *dmap_cachep __read_mostly;
16577 +
16578 +int __init dmap_cache_init(void)
16579 +{
16580 +       dmap_cachep = kmem_cache_create("dmap_cache",
16581 +               sizeof(struct vs_mapping), 0,
16582 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
16583 +       return 0;
16584 +}
16585 +
16586 +__initcall(dmap_cache_init);
16587 +
16588 +
16589 +static inline unsigned int __hashval(dev_t dev, int bits)
16590 +{
16591 +       return hash_long((unsigned long)dev, bits);
16592 +}
16593 +
16594 +
16595 +/*     __hash_mapping()
16596 + *     add the mapping to the hash table
16597 + */
16598 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
16599 +{
16600 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16601 +       struct hlist_head *head, *hash = dmap_main_hash;
16602 +       int device = vdm->device;
16603 +
16604 +       spin_lock(hash_lock);
16605 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
16606 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
16607 +
16608 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
16609 +       hlist_add_head(&vdm->dm_hlist, head);
16610 +       spin_unlock(hash_lock);
16611 +}
16612 +
16613 +
16614 +static inline int __mode_to_default(umode_t mode)
16615 +{
16616 +       switch (mode) {
16617 +       case S_IFBLK:
16618 +               return 0;
16619 +       case S_IFCHR:
16620 +               return 1;
16621 +       default:
16622 +               BUG();
16623 +       }
16624 +}
16625 +
16626 +
16627 +/*     __set_default()
16628 + *     set a default
16629 + */
16630 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
16631 +       struct vx_dmap_target *vdmt)
16632 +{
16633 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16634 +       spin_lock(hash_lock);
16635 +
16636 +       if (vxi)
16637 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
16638 +       else
16639 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
16640 +
16641 +
16642 +       spin_unlock(hash_lock);
16643 +
16644 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
16645 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
16646 +}
16647 +
16648 +
16649 +/*     __remove_default()
16650 + *     remove a default
16651 + */
16652 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
16653 +{
16654 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16655 +       spin_lock(hash_lock);
16656 +
16657 +       if (vxi)
16658 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
16659 +       else    /* remove == reset */
16660 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
16661 +
16662 +       spin_unlock(hash_lock);
16663 +       return 0;
16664 +}
16665 +
16666 +
16667 +/*     __find_mapping()
16668 + *     find a mapping in the hash table
16669 + *
16670 + *     caller must hold hash_lock
16671 + */
16672 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
16673 +       struct vs_mapping **local, struct vs_mapping **global)
16674 +{
16675 +       struct hlist_head *hash = dmap_main_hash;
16676 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
16677 +       struct hlist_node *pos;
16678 +       struct vs_mapping *vdm;
16679 +
16680 +       *local = NULL;
16681 +       if (global)
16682 +               *global = NULL;
16683 +
16684 +       hlist_for_each(pos, head) {
16685 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
16686 +
16687 +               if ((vdm->device == device) &&
16688 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
16689 +                       if (vdm->xid == xid) {
16690 +                               *local = vdm;
16691 +                               return 1;
16692 +                       } else if (global && vdm->xid == 0)
16693 +                               *global = vdm;
16694 +               }
16695 +       }
16696 +
16697 +       if (global && *global)
16698 +               return 0;
16699 +       else
16700 +               return -ENOENT;
16701 +}
16702 +
16703 +
16704 +/*     __lookup_mapping()
16705 + *     find a mapping and store the result in target and flags
16706 + */
16707 +static inline int __lookup_mapping(struct vx_info *vxi,
16708 +       dev_t device, dev_t *target, int *flags, umode_t mode)
16709 +{
16710 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16711 +       struct vs_mapping *vdm, *global;
16712 +       struct vx_dmap_target *vdmt;
16713 +       int ret = 0;
16714 +       vxid_t xid = vxi->vx_id;
16715 +       int index;
16716 +
16717 +       spin_lock(hash_lock);
16718 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
16719 +               ret = 1;
16720 +               vdmt = &vdm->target;
16721 +               goto found;
16722 +       }
16723 +
16724 +       index = __mode_to_default(mode);
16725 +       if (vxi && vxi->dmap.targets[index].flags) {
16726 +               ret = 2;
16727 +               vdmt = &vxi->dmap.targets[index];
16728 +       } else if (global) {
16729 +               ret = 3;
16730 +               vdmt = &global->target;
16731 +               goto found;
16732 +       } else {
16733 +               ret = 4;
16734 +               vdmt = &dmap_defaults[index];
16735 +       }
16736 +
16737 +found:
16738 +       if (target && (vdmt->flags & DATTR_REMAP))
16739 +               *target = vdmt->target;
16740 +       else if (target)
16741 +               *target = device;
16742 +       if (flags)
16743 +               *flags = vdmt->flags;
16744 +
16745 +       spin_unlock(hash_lock);
16746 +
16747 +       return ret;
16748 +}
16749 +
16750 +
16751 +/*     __remove_mapping()
16752 + *     remove a mapping from the hash table
16753 + */
16754 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
16755 +       umode_t mode)
16756 +{
16757 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16758 +       struct vs_mapping *vdm = NULL;
16759 +       int ret = 0;
16760 +
16761 +       spin_lock(hash_lock);
16762 +
16763 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
16764 +               NULL);
16765 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
16766 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
16767 +       if (ret < 0)
16768 +               goto out;
16769 +       hlist_del(&vdm->dm_hlist);
16770 +
16771 +out:
16772 +       spin_unlock(hash_lock);
16773 +       if (vdm)
16774 +               kmem_cache_free(dmap_cachep, vdm);
16775 +       return ret;
16776 +}
16777 +
16778 +
16779 +
16780 +int vs_map_device(struct vx_info *vxi,
16781 +       dev_t device, dev_t *target, umode_t mode)
16782 +{
16783 +       int ret, flags = DATTR_MASK;
16784 +
16785 +       if (!vxi) {
16786 +               if (target)
16787 +                       *target = device;
16788 +               goto out;
16789 +       }
16790 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
16791 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
16792 +               device, target ? *target : 0, flags, mode, ret);
16793 +out:
16794 +       return (flags & DATTR_MASK);
16795 +}
16796 +
16797 +
16798 +
16799 +static int do_set_mapping(struct vx_info *vxi,
16800 +       dev_t device, dev_t target, int flags, umode_t mode)
16801 +{
16802 +       if (device) {
16803 +               struct vs_mapping *new;
16804 +
16805 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
16806 +               if (!new)
16807 +                       return -ENOMEM;
16808 +
16809 +               INIT_HLIST_NODE(&new->dm_hlist);
16810 +               new->device = device;
16811 +               new->target.target = target;
16812 +               new->target.flags = flags | mode;
16813 +               new->xid = (vxi ? vxi->vx_id : 0);
16814 +
16815 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
16816 +               __hash_mapping(vxi, new);
16817 +       } else {
16818 +               struct vx_dmap_target new = {
16819 +                       .target = target,
16820 +                       .flags = flags | mode,
16821 +               };
16822 +               __set_default(vxi, mode, &new);
16823 +       }
16824 +       return 0;
16825 +}
16826 +
16827 +
16828 +static int do_unset_mapping(struct vx_info *vxi,
16829 +       dev_t device, dev_t target, int flags, umode_t mode)
16830 +{
16831 +       int ret = -EINVAL;
16832 +
16833 +       if (device) {
16834 +               ret = __remove_mapping(vxi, device, mode);
16835 +               if (ret < 0)
16836 +                       goto out;
16837 +       } else {
16838 +               ret = __remove_default(vxi, mode);
16839 +               if (ret < 0)
16840 +                       goto out;
16841 +       }
16842 +
16843 +out:
16844 +       return ret;
16845 +}
16846 +
16847 +
16848 +static inline int __user_device(const char __user *name, dev_t *dev,
16849 +       umode_t *mode)
16850 +{
16851 +       struct nameidata nd;
16852 +       int ret;
16853 +
16854 +       if (!name) {
16855 +               *dev = 0;
16856 +               return 0;
16857 +       }
16858 +       ret = user_lpath(name, &nd.path);
16859 +       if (ret)
16860 +               return ret;
16861 +       if (nd.path.dentry->d_inode) {
16862 +               *dev = nd.path.dentry->d_inode->i_rdev;
16863 +               *mode = nd.path.dentry->d_inode->i_mode;
16864 +       }
16865 +       path_put(&nd.path);
16866 +       return 0;
16867 +}
16868 +
16869 +static inline int __mapping_mode(dev_t device, dev_t target,
16870 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
16871 +{
16872 +       if (device)
16873 +               *mode = device_mode & S_IFMT;
16874 +       else if (target)
16875 +               *mode = target_mode & S_IFMT;
16876 +       else
16877 +               return -EINVAL;
16878 +
16879 +       /* if both given, device and target mode have to match */
16880 +       if (device && target &&
16881 +               ((device_mode ^ target_mode) & S_IFMT))
16882 +               return -EINVAL;
16883 +       return 0;
16884 +}
16885 +
16886 +
16887 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
16888 +       const char __user *target_path, int flags, int set)
16889 +{
16890 +       dev_t device = ~0, target = ~0;
16891 +       umode_t device_mode = 0, target_mode = 0, mode;
16892 +       int ret;
16893 +
16894 +       ret = __user_device(device_path, &device, &device_mode);
16895 +       if (ret)
16896 +               return ret;
16897 +       ret = __user_device(target_path, &target, &target_mode);
16898 +       if (ret)
16899 +               return ret;
16900 +
16901 +       ret = __mapping_mode(device, target,
16902 +               device_mode, target_mode, &mode);
16903 +       if (ret)
16904 +               return ret;
16905 +
16906 +       if (set)
16907 +               return do_set_mapping(vxi, device, target,
16908 +                       flags, mode);
16909 +       else
16910 +               return do_unset_mapping(vxi, device, target,
16911 +                       flags, mode);
16912 +}
16913 +
16914 +
16915 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
16916 +{
16917 +       struct vcmd_set_mapping_v0 vc_data;
16918 +
16919 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16920 +               return -EFAULT;
16921 +
16922 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16923 +               vc_data.flags, 1);
16924 +}
16925 +
16926 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
16927 +{
16928 +       struct vcmd_set_mapping_v0 vc_data;
16929 +
16930 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16931 +               return -EFAULT;
16932 +
16933 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16934 +               vc_data.flags, 0);
16935 +}
16936 +
16937 +
16938 +#ifdef CONFIG_COMPAT
16939 +
16940 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
16941 +{
16942 +       struct vcmd_set_mapping_v0_x32 vc_data;
16943 +
16944 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16945 +               return -EFAULT;
16946 +
16947 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16948 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
16949 +}
16950 +
16951 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
16952 +{
16953 +       struct vcmd_set_mapping_v0_x32 vc_data;
16954 +
16955 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16956 +               return -EFAULT;
16957 +
16958 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16959 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
16960 +}
16961 +
16962 +#endif /* CONFIG_COMPAT */
16963 +
16964 +
16965 diff -NurpP --minimal linux-3.13.1/kernel/vserver/dlimit.c linux-3.13.1-vs2.3.6.10/kernel/vserver/dlimit.c
16966 --- linux-3.13.1/kernel/vserver/dlimit.c        1970-01-01 00:00:00.000000000 +0000
16967 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/dlimit.c     2014-01-31 20:38:04.000000000 +0000
16968 @@ -0,0 +1,528 @@
16969 +/*
16970 + *  linux/kernel/vserver/dlimit.c
16971 + *
16972 + *  Virtual Server: Context Disk Limits
16973 + *
16974 + *  Copyright (C) 2004-2009  Herbert Pötzl
16975 + *
16976 + *  V0.01  initial version
16977 + *  V0.02  compat32 splitup
16978 + *  V0.03  extended interface
16979 + *
16980 + */
16981 +
16982 +#include <linux/statfs.h>
16983 +#include <linux/sched.h>
16984 +#include <linux/namei.h>
16985 +#include <linux/vs_tag.h>
16986 +#include <linux/vs_dlimit.h>
16987 +#include <linux/vserver/dlimit_cmd.h>
16988 +#include <linux/slab.h>
16989 +// #include <linux/gfp.h>
16990 +
16991 +#include <asm/uaccess.h>
16992 +
16993 +/*     __alloc_dl_info()
16994 +
16995 +       * allocate an initialized dl_info struct
16996 +       * doesn't make it visible (hash)                        */
16997 +
16998 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
16999 +{
17000 +       struct dl_info *new = NULL;
17001 +
17002 +       vxdprintk(VXD_CBIT(dlim, 5),
17003 +               "alloc_dl_info(%p,%d)*", sb, tag);
17004 +
17005 +       /* would this benefit from a slab cache? */
17006 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17007 +       if (!new)
17008 +               return 0;
17009 +
17010 +       memset(new, 0, sizeof(struct dl_info));
17011 +       new->dl_tag = tag;
17012 +       new->dl_sb = sb;
17013 +       // INIT_RCU_HEAD(&new->dl_rcu);
17014 +       INIT_HLIST_NODE(&new->dl_hlist);
17015 +       spin_lock_init(&new->dl_lock);
17016 +       atomic_set(&new->dl_refcnt, 0);
17017 +       atomic_set(&new->dl_usecnt, 0);
17018 +
17019 +       /* rest of init goes here */
17020 +
17021 +       vxdprintk(VXD_CBIT(dlim, 4),
17022 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17023 +       return new;
17024 +}
17025 +
17026 +/*     __dealloc_dl_info()
17027 +
17028 +       * final disposal of dl_info                             */
17029 +
17030 +static void __dealloc_dl_info(struct dl_info *dli)
17031 +{
17032 +       vxdprintk(VXD_CBIT(dlim, 4),
17033 +               "dealloc_dl_info(%p)", dli);
17034 +
17035 +       dli->dl_hlist.next = LIST_POISON1;
17036 +       dli->dl_tag = -1;
17037 +       dli->dl_sb = 0;
17038 +
17039 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17040 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17041 +
17042 +       kfree(dli);
17043 +}
17044 +
17045 +
17046 +/*     hash table for dl_info hash */
17047 +
17048 +#define DL_HASH_SIZE   13
17049 +
17050 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17051 +
17052 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17053 +
17054 +
17055 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
17056 +{
17057 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17058 +}
17059 +
17060 +
17061 +
17062 +/*     __hash_dl_info()
17063 +
17064 +       * add the dli to the global hash table
17065 +       * requires the hash_lock to be held                     */
17066 +
17067 +static inline void __hash_dl_info(struct dl_info *dli)
17068 +{
17069 +       struct hlist_head *head;
17070 +
17071 +       vxdprintk(VXD_CBIT(dlim, 6),
17072 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17073 +       get_dl_info(dli);
17074 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17075 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17076 +}
17077 +
17078 +/*     __unhash_dl_info()
17079 +
17080 +       * remove the dli from the global hash table
17081 +       * requires the hash_lock to be held                     */
17082 +
17083 +static inline void __unhash_dl_info(struct dl_info *dli)
17084 +{
17085 +       vxdprintk(VXD_CBIT(dlim, 6),
17086 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17087 +       hlist_del_rcu(&dli->dl_hlist);
17088 +       put_dl_info(dli);
17089 +}
17090 +
17091 +
17092 +/*     __lookup_dl_info()
17093 +
17094 +       * requires the rcu_read_lock()
17095 +       * doesn't increment the dl_refcnt                       */
17096 +
17097 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
17098 +{
17099 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17100 +       struct dl_info *dli;
17101 +
17102 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17103 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
17104 +                       return dli;
17105 +       }
17106 +       return NULL;
17107 +}
17108 +
17109 +
17110 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
17111 +{
17112 +       struct dl_info *dli;
17113 +
17114 +       rcu_read_lock();
17115 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17116 +       vxdprintk(VXD_CBIT(dlim, 7),
17117 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17118 +       rcu_read_unlock();
17119 +       return dli;
17120 +}
17121 +
17122 +void rcu_free_dl_info(struct rcu_head *head)
17123 +{
17124 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17125 +       int usecnt, refcnt;
17126 +
17127 +       BUG_ON(!dli || !head);
17128 +
17129 +       usecnt = atomic_read(&dli->dl_usecnt);
17130 +       BUG_ON(usecnt < 0);
17131 +
17132 +       refcnt = atomic_read(&dli->dl_refcnt);
17133 +       BUG_ON(refcnt < 0);
17134 +
17135 +       vxdprintk(VXD_CBIT(dlim, 3),
17136 +               "rcu_free_dl_info(%p)", dli);
17137 +       if (!usecnt)
17138 +               __dealloc_dl_info(dli);
17139 +       else
17140 +               printk("!!! rcu didn't free\n");
17141 +}
17142 +
17143 +
17144 +
17145 +
17146 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17147 +       uint32_t flags, int add)
17148 +{
17149 +       struct path path;
17150 +       int ret;
17151 +
17152 +       ret = user_lpath(name, &path);
17153 +       if (!ret) {
17154 +               struct super_block *sb;
17155 +               struct dl_info *dli;
17156 +
17157 +               ret = -EINVAL;
17158 +               if (!path.dentry->d_inode)
17159 +                       goto out_release;
17160 +               if (!(sb = path.dentry->d_inode->i_sb))
17161 +                       goto out_release;
17162 +
17163 +               if (add) {
17164 +                       dli = __alloc_dl_info(sb, id);
17165 +                       spin_lock(&dl_info_hash_lock);
17166 +
17167 +                       ret = -EEXIST;
17168 +                       if (__lookup_dl_info(sb, id))
17169 +                               goto out_unlock;
17170 +                       __hash_dl_info(dli);
17171 +                       dli = NULL;
17172 +               } else {
17173 +                       spin_lock(&dl_info_hash_lock);
17174 +                       dli = __lookup_dl_info(sb, id);
17175 +
17176 +                       ret = -ESRCH;
17177 +                       if (!dli)
17178 +                               goto out_unlock;
17179 +                       __unhash_dl_info(dli);
17180 +               }
17181 +               ret = 0;
17182 +       out_unlock:
17183 +               spin_unlock(&dl_info_hash_lock);
17184 +               if (add && dli)
17185 +                       __dealloc_dl_info(dli);
17186 +       out_release:
17187 +               path_put(&path);
17188 +       }
17189 +       return ret;
17190 +}
17191 +
17192 +int vc_add_dlimit(uint32_t id, void __user *data)
17193 +{
17194 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17195 +
17196 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17197 +               return -EFAULT;
17198 +
17199 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17200 +}
17201 +
17202 +int vc_rem_dlimit(uint32_t id, void __user *data)
17203 +{
17204 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17205 +
17206 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17207 +               return -EFAULT;
17208 +
17209 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17210 +}
17211 +
17212 +#ifdef CONFIG_COMPAT
17213 +
17214 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17215 +{
17216 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17217 +
17218 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17219 +               return -EFAULT;
17220 +
17221 +       return do_addrem_dlimit(id,
17222 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17223 +}
17224 +
17225 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17226 +{
17227 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17228 +
17229 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17230 +               return -EFAULT;
17231 +
17232 +       return do_addrem_dlimit(id,
17233 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17234 +}
17235 +
17236 +#endif /* CONFIG_COMPAT */
17237 +
17238 +
17239 +static inline
17240 +int do_set_dlimit(uint32_t id, const char __user *name,
17241 +       uint32_t space_used, uint32_t space_total,
17242 +       uint32_t inodes_used, uint32_t inodes_total,
17243 +       uint32_t reserved, uint32_t flags)
17244 +{
17245 +       struct path path;
17246 +       int ret;
17247 +
17248 +       ret = user_lpath(name, &path);
17249 +       if (!ret) {
17250 +               struct super_block *sb;
17251 +               struct dl_info *dli;
17252 +
17253 +               ret = -EINVAL;
17254 +               if (!path.dentry->d_inode)
17255 +                       goto out_release;
17256 +               if (!(sb = path.dentry->d_inode->i_sb))
17257 +                       goto out_release;
17258 +
17259 +               /* sanity checks */
17260 +               if ((reserved != CDLIM_KEEP &&
17261 +                       reserved > 100) ||
17262 +                       (inodes_used != CDLIM_KEEP &&
17263 +                       inodes_used > inodes_total) ||
17264 +                       (space_used != CDLIM_KEEP &&
17265 +                       space_used > space_total))
17266 +                       goto out_release;
17267 +
17268 +               ret = -ESRCH;
17269 +               dli = locate_dl_info(sb, id);
17270 +               if (!dli)
17271 +                       goto out_release;
17272 +
17273 +               spin_lock(&dli->dl_lock);
17274 +
17275 +               if (inodes_used != CDLIM_KEEP)
17276 +                       dli->dl_inodes_used = inodes_used;
17277 +               if (inodes_total != CDLIM_KEEP)
17278 +                       dli->dl_inodes_total = inodes_total;
17279 +               if (space_used != CDLIM_KEEP)
17280 +                       dli->dl_space_used = dlimit_space_32to64(
17281 +                               space_used, flags, DLIMS_USED);
17282 +
17283 +               if (space_total == CDLIM_INFINITY)
17284 +                       dli->dl_space_total = DLIM_INFINITY;
17285 +               else if (space_total != CDLIM_KEEP)
17286 +                       dli->dl_space_total = dlimit_space_32to64(
17287 +                               space_total, flags, DLIMS_TOTAL);
17288 +
17289 +               if (reserved != CDLIM_KEEP)
17290 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17291 +
17292 +               spin_unlock(&dli->dl_lock);
17293 +
17294 +               put_dl_info(dli);
17295 +               ret = 0;
17296 +
17297 +       out_release:
17298 +               path_put(&path);
17299 +       }
17300 +       return ret;
17301 +}
17302 +
17303 +int vc_set_dlimit(uint32_t id, void __user *data)
17304 +{
17305 +       struct vcmd_ctx_dlimit_v0 vc_data;
17306 +
17307 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17308 +               return -EFAULT;
17309 +
17310 +       return do_set_dlimit(id, vc_data.name,
17311 +               vc_data.space_used, vc_data.space_total,
17312 +               vc_data.inodes_used, vc_data.inodes_total,
17313 +               vc_data.reserved, vc_data.flags);
17314 +}
17315 +
17316 +#ifdef CONFIG_COMPAT
17317 +
17318 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17319 +{
17320 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17321 +
17322 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17323 +               return -EFAULT;
17324 +
17325 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17326 +               vc_data.space_used, vc_data.space_total,
17327 +               vc_data.inodes_used, vc_data.inodes_total,
17328 +               vc_data.reserved, vc_data.flags);
17329 +}
17330 +
17331 +#endif /* CONFIG_COMPAT */
17332 +
17333 +
17334 +static inline
17335 +int do_get_dlimit(uint32_t id, const char __user *name,
17336 +       uint32_t *space_used, uint32_t *space_total,
17337 +       uint32_t *inodes_used, uint32_t *inodes_total,
17338 +       uint32_t *reserved, uint32_t *flags)
17339 +{
17340 +       struct path path;
17341 +       int ret;
17342 +
17343 +       ret = user_lpath(name, &path);
17344 +       if (!ret) {
17345 +               struct super_block *sb;
17346 +               struct dl_info *dli;
17347 +
17348 +               ret = -EINVAL;
17349 +               if (!path.dentry->d_inode)
17350 +                       goto out_release;
17351 +               if (!(sb = path.dentry->d_inode->i_sb))
17352 +                       goto out_release;
17353 +
17354 +               ret = -ESRCH;
17355 +               dli = locate_dl_info(sb, id);
17356 +               if (!dli)
17357 +                       goto out_release;
17358 +
17359 +               spin_lock(&dli->dl_lock);
17360 +               *inodes_used = dli->dl_inodes_used;
17361 +               *inodes_total = dli->dl_inodes_total;
17362 +
17363 +               *space_used = dlimit_space_64to32(
17364 +                       dli->dl_space_used, flags, DLIMS_USED);
17365 +
17366 +               if (dli->dl_space_total == DLIM_INFINITY)
17367 +                       *space_total = CDLIM_INFINITY;
17368 +               else
17369 +                       *space_total = dlimit_space_64to32(
17370 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
17371 +
17372 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
17373 +               spin_unlock(&dli->dl_lock);
17374 +
17375 +               put_dl_info(dli);
17376 +               ret = -EFAULT;
17377 +
17378 +               ret = 0;
17379 +       out_release:
17380 +               path_put(&path);
17381 +       }
17382 +       return ret;
17383 +}
17384 +
17385 +
17386 +int vc_get_dlimit(uint32_t id, void __user *data)
17387 +{
17388 +       struct vcmd_ctx_dlimit_v0 vc_data;
17389 +       int ret;
17390 +
17391 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17392 +               return -EFAULT;
17393 +
17394 +       ret = do_get_dlimit(id, vc_data.name,
17395 +               &vc_data.space_used, &vc_data.space_total,
17396 +               &vc_data.inodes_used, &vc_data.inodes_total,
17397 +               &vc_data.reserved, &vc_data.flags);
17398 +       if (ret)
17399 +               return ret;
17400 +
17401 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17402 +               return -EFAULT;
17403 +       return 0;
17404 +}
17405 +
17406 +#ifdef CONFIG_COMPAT
17407 +
17408 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
17409 +{
17410 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17411 +       int ret;
17412 +
17413 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17414 +               return -EFAULT;
17415 +
17416 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
17417 +               &vc_data.space_used, &vc_data.space_total,
17418 +               &vc_data.inodes_used, &vc_data.inodes_total,
17419 +               &vc_data.reserved, &vc_data.flags);
17420 +       if (ret)
17421 +               return ret;
17422 +
17423 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17424 +               return -EFAULT;
17425 +       return 0;
17426 +}
17427 +
17428 +#endif /* CONFIG_COMPAT */
17429 +
17430 +
17431 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
17432 +{
17433 +       struct dl_info *dli;
17434 +       __u64 blimit, bfree, bavail;
17435 +       __u32 ifree;
17436 +
17437 +       dli = locate_dl_info(sb, dx_current_tag());
17438 +       if (!dli)
17439 +               return;
17440 +
17441 +       spin_lock(&dli->dl_lock);
17442 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
17443 +               goto no_ilim;
17444 +
17445 +       /* reduce max inodes available to limit */
17446 +       if (buf->f_files > dli->dl_inodes_total)
17447 +               buf->f_files = dli->dl_inodes_total;
17448 +
17449 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
17450 +       /* reduce free inodes to min */
17451 +       if (ifree < buf->f_ffree)
17452 +               buf->f_ffree = ifree;
17453 +
17454 +no_ilim:
17455 +       if (dli->dl_space_total == DLIM_INFINITY)
17456 +               goto no_blim;
17457 +
17458 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
17459 +
17460 +       if (dli->dl_space_total < dli->dl_space_used)
17461 +               bfree = 0;
17462 +       else
17463 +               bfree = (dli->dl_space_total - dli->dl_space_used)
17464 +                       >> sb->s_blocksize_bits;
17465 +
17466 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
17467 +       if (bavail < dli->dl_space_used)
17468 +               bavail = 0;
17469 +       else
17470 +               bavail = (bavail - dli->dl_space_used)
17471 +                       >> sb->s_blocksize_bits;
17472 +
17473 +       /* reduce max space available to limit */
17474 +       if (buf->f_blocks > blimit)
17475 +               buf->f_blocks = blimit;
17476 +
17477 +       /* reduce free space to min */
17478 +       if (bfree < buf->f_bfree)
17479 +               buf->f_bfree = bfree;
17480 +
17481 +       /* reduce avail space to min */
17482 +       if (bavail < buf->f_bavail)
17483 +               buf->f_bavail = bavail;
17484 +
17485 +no_blim:
17486 +       spin_unlock(&dli->dl_lock);
17487 +       put_dl_info(dli);
17488 +
17489 +       return;
17490 +}
17491 +
17492 +#include <linux/module.h>
17493 +
17494 +EXPORT_SYMBOL_GPL(locate_dl_info);
17495 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
17496 +
17497 diff -NurpP --minimal linux-3.13.1/kernel/vserver/helper.c linux-3.13.1-vs2.3.6.10/kernel/vserver/helper.c
17498 --- linux-3.13.1/kernel/vserver/helper.c        1970-01-01 00:00:00.000000000 +0000
17499 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/helper.c     2014-01-31 20:38:04.000000000 +0000
17500 @@ -0,0 +1,242 @@
17501 +/*
17502 + *  linux/kernel/vserver/helper.c
17503 + *
17504 + *  Virtual Context Support
17505 + *
17506 + *  Copyright (C) 2004-2007  Herbert Pötzl
17507 + *
17508 + *  V0.01  basic helper
17509 + *
17510 + */
17511 +
17512 +#include <linux/kmod.h>
17513 +#include <linux/reboot.h>
17514 +#include <linux/vs_context.h>
17515 +#include <linux/vs_network.h>
17516 +#include <linux/vserver/signal.h>
17517 +
17518 +
17519 +char vshelper_path[255] = "/sbin/vshelper";
17520 +
17521 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
17522 +{
17523 +       current->flags &= ~PF_NO_SETAFFINITY;
17524 +       return 0;
17525 +}
17526 +
17527 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
17528 +{
17529 +       struct subprocess_info *info;
17530 +       gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
17531 +
17532 +       info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
17533 +                                        vshelper_init, NULL, NULL);
17534 +       if (info == NULL)
17535 +               return -ENOMEM;
17536 +
17537 +       return call_usermodehelper_exec(info, wait);
17538 +}
17539 +
17540 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
17541 +{
17542 +       int ret;
17543 +
17544 +       if ((ret = vs_call_usermodehelper(name, argv, envp,
17545 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
17546 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
17547 +                       name, argv[1], argv[2],
17548 +                       sync ? "sync" : "async", ret);
17549 +       }
17550 +       vxdprintk(VXD_CBIT(switch, 4),
17551 +               "%s: (%s %s) returned %s with %d",
17552 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
17553 +       return ret;
17554 +}
17555 +
17556 +/*
17557 + *      vshelper path is set via /proc/sys
17558 + *      invoked by vserver sys_reboot(), with
17559 + *      the following arguments
17560 + *
17561 + *      argv [0] = vshelper_path;
17562 + *      argv [1] = action: "restart", "halt", "poweroff", ...
17563 + *      argv [2] = context identifier
17564 + *
17565 + *      envp [*] = type-specific parameters
17566 + */
17567 +
17568 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
17569 +{
17570 +       char id_buf[8], cmd_buf[16];
17571 +       char uid_buf[16], pid_buf[16];
17572 +       int ret;
17573 +
17574 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17575 +       char *envp[] = {"HOME=/", "TERM=linux",
17576 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
17577 +                       uid_buf, pid_buf, cmd_buf, 0};
17578 +
17579 +       if (vx_info_state(vxi, VXS_HELPER))
17580 +               return -EAGAIN;
17581 +       vxi->vx_state |= VXS_HELPER;
17582 +
17583 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17584 +
17585 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17586 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
17587 +               from_kuid(&init_user_ns, current_uid()));
17588 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
17589 +
17590 +       switch (cmd) {
17591 +       case LINUX_REBOOT_CMD_RESTART:
17592 +               argv[1] = "restart";
17593 +               break;
17594 +
17595 +       case LINUX_REBOOT_CMD_HALT:
17596 +               argv[1] = "halt";
17597 +               break;
17598 +
17599 +       case LINUX_REBOOT_CMD_POWER_OFF:
17600 +               argv[1] = "poweroff";
17601 +               break;
17602 +
17603 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
17604 +               argv[1] = "swsusp";
17605 +               break;
17606 +
17607 +       case LINUX_REBOOT_CMD_OOM:
17608 +               argv[1] = "oom";
17609 +               break;
17610 +
17611 +       default:
17612 +               vxi->vx_state &= ~VXS_HELPER;
17613 +               return 0;
17614 +       }
17615 +
17616 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
17617 +       vxi->vx_state &= ~VXS_HELPER;
17618 +       __wakeup_vx_info(vxi);
17619 +       return (ret) ? -EPERM : 0;
17620 +}
17621 +
17622 +
17623 +long vs_reboot(unsigned int cmd, void __user *arg)
17624 +{
17625 +       struct vx_info *vxi = current_vx_info();
17626 +       long ret = 0;
17627 +
17628 +       vxdprintk(VXD_CBIT(misc, 5),
17629 +               "vs_reboot(%p[#%d],%u)",
17630 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17631 +
17632 +       ret = vs_reboot_helper(vxi, cmd, arg);
17633 +       if (ret)
17634 +               return ret;
17635 +
17636 +       vxi->reboot_cmd = cmd;
17637 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17638 +               switch (cmd) {
17639 +               case LINUX_REBOOT_CMD_RESTART:
17640 +               case LINUX_REBOOT_CMD_HALT:
17641 +               case LINUX_REBOOT_CMD_POWER_OFF:
17642 +                       vx_info_kill(vxi, 0, SIGKILL);
17643 +                       vx_info_kill(vxi, 1, SIGKILL);
17644 +               default:
17645 +                       break;
17646 +               }
17647 +       }
17648 +       return 0;
17649 +}
17650 +
17651 +long vs_oom_action(unsigned int cmd)
17652 +{
17653 +       struct vx_info *vxi = current_vx_info();
17654 +       long ret = 0;
17655 +
17656 +       vxdprintk(VXD_CBIT(misc, 5),
17657 +               "vs_oom_action(%p[#%d],%u)",
17658 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17659 +
17660 +       ret = vs_reboot_helper(vxi, cmd, NULL);
17661 +       if (ret)
17662 +               return ret;
17663 +
17664 +       vxi->reboot_cmd = cmd;
17665 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17666 +               vx_info_kill(vxi, 0, SIGKILL);
17667 +               vx_info_kill(vxi, 1, SIGKILL);
17668 +       }
17669 +       return 0;
17670 +}
17671 +
17672 +/*
17673 + *      argv [0] = vshelper_path;
17674 + *      argv [1] = action: "startup", "shutdown"
17675 + *      argv [2] = context identifier
17676 + *
17677 + *      envp [*] = type-specific parameters
17678 + */
17679 +
17680 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
17681 +{
17682 +       char id_buf[8], cmd_buf[16];
17683 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17684 +       char *envp[] = {"HOME=/", "TERM=linux",
17685 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17686 +
17687 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
17688 +               return 0;
17689 +
17690 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17691 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17692 +
17693 +       switch (cmd) {
17694 +       case VSC_STARTUP:
17695 +               argv[1] = "startup";
17696 +               break;
17697 +       case VSC_SHUTDOWN:
17698 +               argv[1] = "shutdown";
17699 +               break;
17700 +       default:
17701 +               return 0;
17702 +       }
17703 +
17704 +       return do_vshelper(vshelper_path, argv, envp, 1);
17705 +}
17706 +
17707 +
17708 +/*
17709 + *      argv [0] = vshelper_path;
17710 + *      argv [1] = action: "netup", "netdown"
17711 + *      argv [2] = context identifier
17712 + *
17713 + *      envp [*] = type-specific parameters
17714 + */
17715 +
17716 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
17717 +{
17718 +       char id_buf[8], cmd_buf[16];
17719 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17720 +       char *envp[] = {"HOME=/", "TERM=linux",
17721 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17722 +
17723 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
17724 +               return 0;
17725 +
17726 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
17727 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17728 +
17729 +       switch (cmd) {
17730 +       case VSC_NETUP:
17731 +               argv[1] = "netup";
17732 +               break;
17733 +       case VSC_NETDOWN:
17734 +               argv[1] = "netdown";
17735 +               break;
17736 +       default:
17737 +               return 0;
17738 +       }
17739 +
17740 +       return do_vshelper(vshelper_path, argv, envp, 1);
17741 +}
17742 +
17743 diff -NurpP --minimal linux-3.13.1/kernel/vserver/history.c linux-3.13.1-vs2.3.6.10/kernel/vserver/history.c
17744 --- linux-3.13.1/kernel/vserver/history.c       1970-01-01 00:00:00.000000000 +0000
17745 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/history.c    2014-01-31 20:38:04.000000000 +0000
17746 @@ -0,0 +1,258 @@
17747 +/*
17748 + *  kernel/vserver/history.c
17749 + *
17750 + *  Virtual Context History Backtrace
17751 + *
17752 + *  Copyright (C) 2004-2007  Herbert Pötzl
17753 + *
17754 + *  V0.01  basic structure
17755 + *  V0.02  hash/unhash and trace
17756 + *  V0.03  preemption fixes
17757 + *
17758 + */
17759 +
17760 +#include <linux/module.h>
17761 +#include <asm/uaccess.h>
17762 +
17763 +#include <linux/vserver/context.h>
17764 +#include <linux/vserver/debug.h>
17765 +#include <linux/vserver/debug_cmd.h>
17766 +#include <linux/vserver/history.h>
17767 +
17768 +
17769 +#ifdef CONFIG_VSERVER_HISTORY
17770 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
17771 +#else
17772 +#define VXH_SIZE       64
17773 +#endif
17774 +
17775 +struct _vx_history {
17776 +       unsigned int counter;
17777 +
17778 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
17779 +};
17780 +
17781 +
17782 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
17783 +
17784 +unsigned volatile int vxh_active = 1;
17785 +
17786 +static atomic_t sequence = ATOMIC_INIT(0);
17787 +
17788 +
17789 +/*     vxh_advance()
17790 +
17791 +       * requires disabled preemption                          */
17792 +
17793 +struct _vx_hist_entry *vxh_advance(void *loc)
17794 +{
17795 +       unsigned int cpu = smp_processor_id();
17796 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17797 +       struct _vx_hist_entry *entry;
17798 +       unsigned int index;
17799 +
17800 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
17801 +       entry = &hist->entry[index];
17802 +
17803 +       entry->seq = atomic_inc_return(&sequence);
17804 +       entry->loc = loc;
17805 +       return entry;
17806 +}
17807 +
17808 +EXPORT_SYMBOL_GPL(vxh_advance);
17809 +
17810 +
17811 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
17812 +
17813 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
17814 +
17815 +
17816 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
17817 +
17818 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
17819 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
17820 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
17821 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
17822 +
17823 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
17824 +{
17825 +       switch (e->type) {
17826 +       case VXH_THROW_OOPS:
17827 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
17828 +               break;
17829 +
17830 +       case VXH_GET_VX_INFO:
17831 +       case VXH_PUT_VX_INFO:
17832 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17833 +                       VXH_LOC_ARGS(e),
17834 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
17835 +                       VXH_VXI_ARGS(e));
17836 +               break;
17837 +
17838 +       case VXH_INIT_VX_INFO:
17839 +       case VXH_SET_VX_INFO:
17840 +       case VXH_CLR_VX_INFO:
17841 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17842 +                       VXH_LOC_ARGS(e),
17843 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
17844 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
17845 +                       VXH_VXI_ARGS(e), e->sc.data);
17846 +               break;
17847 +
17848 +       case VXH_CLAIM_VX_INFO:
17849 +       case VXH_RELEASE_VX_INFO:
17850 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17851 +                       VXH_LOC_ARGS(e),
17852 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
17853 +                       VXH_VXI_ARGS(e), e->sc.data);
17854 +               break;
17855 +
17856 +       case VXH_ALLOC_VX_INFO:
17857 +       case VXH_DEALLOC_VX_INFO:
17858 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17859 +                       VXH_LOC_ARGS(e),
17860 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
17861 +                       VXH_VXI_ARGS(e));
17862 +               break;
17863 +
17864 +       case VXH_HASH_VX_INFO:
17865 +       case VXH_UNHASH_VX_INFO:
17866 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
17867 +                       VXH_LOC_ARGS(e),
17868 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
17869 +                       VXH_VXI_ARGS(e));
17870 +               break;
17871 +
17872 +       case VXH_LOC_VX_INFO:
17873 +       case VXH_LOOKUP_VX_INFO:
17874 +       case VXH_CREATE_VX_INFO:
17875 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
17876 +                       VXH_LOC_ARGS(e),
17877 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
17878 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
17879 +                       e->ll.arg, VXH_VXI_ARGS(e));
17880 +               break;
17881 +       }
17882 +}
17883 +
17884 +static void __vxh_dump_history(void)
17885 +{
17886 +       unsigned int i, cpu;
17887 +
17888 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
17889 +               atomic_read(&sequence), NR_CPUS);
17890 +
17891 +       for (i = 0; i < VXH_SIZE; i++) {
17892 +               for_each_online_cpu(cpu) {
17893 +                       struct _vx_history *hist =
17894 +                               &per_cpu(vx_history_buffer, cpu);
17895 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
17896 +                       struct _vx_hist_entry *entry = &hist->entry[index];
17897 +
17898 +                       vxh_dump_entry(entry, cpu);
17899 +               }
17900 +       }
17901 +}
17902 +
17903 +void   vxh_dump_history(void)
17904 +{
17905 +       vxh_active = 0;
17906 +#ifdef CONFIG_SMP
17907 +       local_irq_enable();
17908 +       smp_send_stop();
17909 +       local_irq_disable();
17910 +#endif
17911 +       __vxh_dump_history();
17912 +}
17913 +
17914 +
17915 +/* vserver syscall commands below here */
17916 +
17917 +
17918 +int vc_dump_history(uint32_t id)
17919 +{
17920 +       vxh_active = 0;
17921 +       __vxh_dump_history();
17922 +       vxh_active = 1;
17923 +
17924 +       return 0;
17925 +}
17926 +
17927 +
17928 +int do_read_history(struct __user _vx_hist_entry *data,
17929 +       int cpu, uint32_t *index, uint32_t *count)
17930 +{
17931 +       int pos, ret = 0;
17932 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17933 +       int end = hist->counter;
17934 +       int start = end - VXH_SIZE + 2;
17935 +       int idx = *index;
17936 +
17937 +       /* special case: get current pos */
17938 +       if (!*count) {
17939 +               *index = end;
17940 +               return 0;
17941 +       }
17942 +
17943 +       /* have we lost some data? */
17944 +       if (idx < start)
17945 +               idx = start;
17946 +
17947 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
17948 +               struct _vx_hist_entry *entry =
17949 +                       &hist->entry[idx % VXH_SIZE];
17950 +
17951 +               /* send entry to userspace */
17952 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
17953 +               if (ret)
17954 +                       break;
17955 +       }
17956 +       /* save new index and count */
17957 +       *index = idx;
17958 +       *count = pos;
17959 +       return ret ? ret : (*index < end);
17960 +}
17961 +
17962 +int vc_read_history(uint32_t id, void __user *data)
17963 +{
17964 +       struct vcmd_read_history_v0 vc_data;
17965 +       int ret;
17966 +
17967 +       if (id >= NR_CPUS)
17968 +               return -EINVAL;
17969 +
17970 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17971 +               return -EFAULT;
17972 +
17973 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
17974 +               id, &vc_data.index, &vc_data.count);
17975 +
17976 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17977 +               return -EFAULT;
17978 +       return ret;
17979 +}
17980 +
17981 +#ifdef CONFIG_COMPAT
17982 +
17983 +int vc_read_history_x32(uint32_t id, void __user *data)
17984 +{
17985 +       struct vcmd_read_history_v0_x32 vc_data;
17986 +       int ret;
17987 +
17988 +       if (id >= NR_CPUS)
17989 +               return -EINVAL;
17990 +
17991 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17992 +               return -EFAULT;
17993 +
17994 +       ret = do_read_history((struct __user _vx_hist_entry *)
17995 +               compat_ptr(vc_data.data_ptr),
17996 +               id, &vc_data.index, &vc_data.count);
17997 +
17998 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17999 +               return -EFAULT;
18000 +       return ret;
18001 +}
18002 +
18003 +#endif /* CONFIG_COMPAT */
18004 +
18005 diff -NurpP --minimal linux-3.13.1/kernel/vserver/inet.c linux-3.13.1-vs2.3.6.10/kernel/vserver/inet.c
18006 --- linux-3.13.1/kernel/vserver/inet.c  1970-01-01 00:00:00.000000000 +0000
18007 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/inet.c       2014-02-01 00:26:40.000000000 +0000
18008 @@ -0,0 +1,236 @@
18009 +
18010 +#include <linux/in.h>
18011 +#include <linux/inetdevice.h>
18012 +#include <linux/export.h>
18013 +#include <linux/vs_inet.h>
18014 +#include <linux/vs_inet6.h>
18015 +#include <linux/vserver/debug.h>
18016 +#include <net/route.h>
18017 +#include <net/addrconf.h>
18018 +
18019 +
18020 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18021 +{
18022 +       int ret = 0;
18023 +
18024 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18025 +               ret = 1;
18026 +       else {
18027 +               struct nx_addr_v4 *ptr;
18028 +               unsigned long irqflags;
18029 +
18030 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18031 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18032 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18033 +                               ret = 1;
18034 +                               break;
18035 +                       }
18036 +               }
18037 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18038 +       }
18039 +
18040 +       vxdprintk(VXD_CBIT(net, 2),
18041 +               "nx_v4_addr_conflict(%p,%p): %d",
18042 +               nxi1, nxi2, ret);
18043 +
18044 +       return ret;
18045 +}
18046 +
18047 +
18048 +#ifdef CONFIG_IPV6
18049 +
18050 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18051 +{
18052 +       int ret = 0;
18053 +
18054 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18055 +               ret = 1;
18056 +       else {
18057 +               struct nx_addr_v6 *ptr;
18058 +               unsigned long irqflags;
18059 +
18060 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18061 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18062 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18063 +                               ret = 1;
18064 +                               break;
18065 +                       }
18066 +               }
18067 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18068 +       }
18069 +
18070 +       vxdprintk(VXD_CBIT(net, 2),
18071 +               "nx_v6_addr_conflict(%p,%p): %d",
18072 +               nxi1, nxi2, ret);
18073 +
18074 +       return ret;
18075 +}
18076 +
18077 +#endif
18078 +
18079 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18080 +{
18081 +       struct in_device *in_dev;
18082 +       struct in_ifaddr **ifap;
18083 +       struct in_ifaddr *ifa;
18084 +       int ret = 0;
18085 +
18086 +       if (!dev)
18087 +               goto out;
18088 +       in_dev = in_dev_get(dev);
18089 +       if (!in_dev)
18090 +               goto out;
18091 +
18092 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18093 +               ifap = &ifa->ifa_next) {
18094 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18095 +                       ret = 1;
18096 +                       break;
18097 +               }
18098 +       }
18099 +       in_dev_put(in_dev);
18100 +out:
18101 +       return ret;
18102 +}
18103 +
18104 +
18105 +#ifdef CONFIG_IPV6
18106 +
18107 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18108 +{
18109 +       struct inet6_dev *in_dev;
18110 +       struct inet6_ifaddr *ifa;
18111 +       int ret = 0;
18112 +
18113 +       if (!dev)
18114 +               goto out;
18115 +       in_dev = in6_dev_get(dev);
18116 +       if (!in_dev)
18117 +               goto out;
18118 +
18119 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18120 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18121 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18122 +                       ret = 1;
18123 +                       break;
18124 +               }
18125 +       }
18126 +       in6_dev_put(in_dev);
18127 +out:
18128 +       return ret;
18129 +}
18130 +
18131 +#endif
18132 +
18133 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18134 +{
18135 +       int ret = 1;
18136 +
18137 +       if (!nxi)
18138 +               goto out;
18139 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18140 +               goto out;
18141 +#ifdef CONFIG_IPV6
18142 +       ret = 2;
18143 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18144 +               goto out;
18145 +#endif
18146 +       ret = 0;
18147 +out:
18148 +       vxdprintk(VXD_CBIT(net, 3),
18149 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18150 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18151 +       return ret;
18152 +}
18153 +
18154 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18155 +       struct flowi4 *fl4)
18156 +{
18157 +       struct rtable *rt;
18158 +
18159 +       if (!nxi)
18160 +               return NULL;
18161 +
18162 +       /* FIXME: handle lback only case */
18163 +       if (!NX_IPV4(nxi))
18164 +               return ERR_PTR(-EPERM);
18165 +
18166 +       vxdprintk(VXD_CBIT(net, 4),
18167 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18168 +               nxi, nxi ? nxi->nx_id : 0,
18169 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18170 +
18171 +       /* single IP is unconditional */
18172 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18173 +               (fl4->saddr == INADDR_ANY))
18174 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18175 +
18176 +       if (fl4->saddr == INADDR_ANY) {
18177 +               struct nx_addr_v4 *ptr;
18178 +               __be32 found = 0;
18179 +
18180 +               rt = __ip_route_output_key(net, fl4);
18181 +               if (!IS_ERR(rt)) {
18182 +                       found = fl4->saddr;
18183 +                       ip_rt_put(rt);
18184 +                       vxdprintk(VXD_CBIT(net, 4),
18185 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18186 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18187 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18188 +                               goto found;
18189 +               }
18190 +
18191 +               WARN_ON_ONCE(in_irq());
18192 +               spin_lock_bh(&nxi->addr_lock);
18193 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18194 +                       __be32 primary = ptr->ip[0].s_addr;
18195 +                       __be32 mask = ptr->mask.s_addr;
18196 +                       __be32 neta = primary & mask;
18197 +
18198 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18199 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18200 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18201 +                               NIPQUAD(mask), NIPQUAD(neta));
18202 +                       if ((found & mask) != neta)
18203 +                               continue;
18204 +
18205 +                       fl4->saddr = primary;
18206 +                       rt = __ip_route_output_key(net, fl4);
18207 +                       vxdprintk(VXD_CBIT(net, 4),
18208 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18209 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18210 +                       if (!IS_ERR(rt)) {
18211 +                               found = fl4->saddr;
18212 +                               ip_rt_put(rt);
18213 +                               if (found == primary)
18214 +                                       goto found_unlock;
18215 +                       }
18216 +               }
18217 +               /* still no source ip? */
18218 +               found = ipv4_is_loopback(fl4->daddr)
18219 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18220 +       found_unlock:
18221 +               spin_unlock_bh(&nxi->addr_lock);
18222 +       found:
18223 +               /* assign src ip to flow */
18224 +               fl4->saddr = found;
18225 +
18226 +       } else {
18227 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18228 +                       return ERR_PTR(-EPERM);
18229 +       }
18230 +
18231 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18232 +               if (ipv4_is_loopback(fl4->daddr))
18233 +                       fl4->daddr = nxi->v4_lback.s_addr;
18234 +               if (ipv4_is_loopback(fl4->saddr))
18235 +                       fl4->saddr = nxi->v4_lback.s_addr;
18236 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18237 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18238 +               return ERR_PTR(-EPERM);
18239 +
18240 +       return NULL;
18241 +}
18242 +
18243 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18244 +
18245 diff -NurpP --minimal linux-3.13.1/kernel/vserver/init.c linux-3.13.1-vs2.3.6.10/kernel/vserver/init.c
18246 --- linux-3.13.1/kernel/vserver/init.c  1970-01-01 00:00:00.000000000 +0000
18247 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/init.c       2014-01-31 20:38:04.000000000 +0000
18248 @@ -0,0 +1,45 @@
18249 +/*
18250 + *  linux/kernel/init.c
18251 + *
18252 + *  Virtual Server Init
18253 + *
18254 + *  Copyright (C) 2004-2007  Herbert Pötzl
18255 + *
18256 + *  V0.01  basic structure
18257 + *
18258 + */
18259 +
18260 +#include <linux/init.h>
18261 +
18262 +int    vserver_register_sysctl(void);
18263 +void   vserver_unregister_sysctl(void);
18264 +
18265 +
18266 +static int __init init_vserver(void)
18267 +{
18268 +       int ret = 0;
18269 +
18270 +#ifdef CONFIG_VSERVER_DEBUG
18271 +       vserver_register_sysctl();
18272 +#endif
18273 +       return ret;
18274 +}
18275 +
18276 +
18277 +static void __exit exit_vserver(void)
18278 +{
18279 +
18280 +#ifdef CONFIG_VSERVER_DEBUG
18281 +       vserver_unregister_sysctl();
18282 +#endif
18283 +       return;
18284 +}
18285 +
18286 +/* FIXME: GFP_ZONETYPES gone
18287 +long vx_slab[GFP_ZONETYPES]; */
18288 +long vx_area;
18289 +
18290 +
18291 +module_init(init_vserver);
18292 +module_exit(exit_vserver);
18293 +
18294 diff -NurpP --minimal linux-3.13.1/kernel/vserver/inode.c linux-3.13.1-vs2.3.6.10/kernel/vserver/inode.c
18295 --- linux-3.13.1/kernel/vserver/inode.c 1970-01-01 00:00:00.000000000 +0000
18296 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/inode.c      2014-01-31 20:38:04.000000000 +0000
18297 @@ -0,0 +1,440 @@
18298 +/*
18299 + *  linux/kernel/vserver/inode.c
18300 + *
18301 + *  Virtual Server: File System Support
18302 + *
18303 + *  Copyright (C) 2004-2007  Herbert Pötzl
18304 + *
18305 + *  V0.01  separated from vcontext V0.05
18306 + *  V0.02  moved to tag (instead of xid)
18307 + *
18308 + */
18309 +
18310 +#include <linux/tty.h>
18311 +#include <linux/proc_fs.h>
18312 +#include <linux/devpts_fs.h>
18313 +#include <linux/fs.h>
18314 +#include <linux/file.h>
18315 +#include <linux/mount.h>
18316 +#include <linux/parser.h>
18317 +#include <linux/namei.h>
18318 +#include <linux/magic.h>
18319 +#include <linux/slab.h>
18320 +#include <linux/vserver/inode.h>
18321 +#include <linux/vserver/inode_cmd.h>
18322 +#include <linux/vs_base.h>
18323 +#include <linux/vs_tag.h>
18324 +
18325 +#include <asm/uaccess.h>
18326 +#include <../../fs/proc/internal.h>
18327 +
18328 +
18329 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18330 +{
18331 +       struct proc_dir_entry *entry;
18332 +
18333 +       if (!in || !in->i_sb)
18334 +               return -ESRCH;
18335 +
18336 +       *flags = IATTR_TAG
18337 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18338 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18339 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18340 +               | (IS_COW(in) ? IATTR_COW : 0);
18341 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18342 +
18343 +       if (S_ISDIR(in->i_mode))
18344 +               *mask |= IATTR_BARRIER;
18345 +
18346 +       if (IS_TAGGED(in)) {
18347 +               *tag = i_tag_read(in);
18348 +               *mask |= IATTR_TAG;
18349 +       }
18350 +
18351 +       switch (in->i_sb->s_magic) {
18352 +       case PROC_SUPER_MAGIC:
18353 +               entry = PROC_I(in)->pde;
18354 +
18355 +               /* check for specific inodes? */
18356 +               if (entry)
18357 +                       *mask |= IATTR_FLAGS;
18358 +               if (entry)
18359 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
18360 +               else
18361 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
18362 +               break;
18363 +
18364 +       case DEVPTS_SUPER_MAGIC:
18365 +               *tag = i_tag_read(in);
18366 +               *mask |= IATTR_TAG;
18367 +               break;
18368 +
18369 +       default:
18370 +               break;
18371 +       }
18372 +       return 0;
18373 +}
18374 +
18375 +int vc_get_iattr(void __user *data)
18376 +{
18377 +       struct path path;
18378 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
18379 +       int ret;
18380 +
18381 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18382 +               return -EFAULT;
18383 +
18384 +       ret = user_lpath(vc_data.name, &path);
18385 +       if (!ret) {
18386 +               ret = __vc_get_iattr(path.dentry->d_inode,
18387 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18388 +               path_put(&path);
18389 +       }
18390 +       if (ret)
18391 +               return ret;
18392 +
18393 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18394 +               ret = -EFAULT;
18395 +       return ret;
18396 +}
18397 +
18398 +#ifdef CONFIG_COMPAT
18399 +
18400 +int vc_get_iattr_x32(void __user *data)
18401 +{
18402 +       struct path path;
18403 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
18404 +       int ret;
18405 +
18406 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18407 +               return -EFAULT;
18408 +
18409 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18410 +       if (!ret) {
18411 +               ret = __vc_get_iattr(path.dentry->d_inode,
18412 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18413 +               path_put(&path);
18414 +       }
18415 +       if (ret)
18416 +               return ret;
18417 +
18418 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18419 +               ret = -EFAULT;
18420 +       return ret;
18421 +}
18422 +
18423 +#endif /* CONFIG_COMPAT */
18424 +
18425 +
18426 +int vc_fget_iattr(uint32_t fd, void __user *data)
18427 +{
18428 +       struct file *filp;
18429 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
18430 +       int ret;
18431 +
18432 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18433 +               return -EFAULT;
18434 +
18435 +       filp = fget(fd);
18436 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18437 +               return -EBADF;
18438 +
18439 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
18440 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
18441 +
18442 +       fput(filp);
18443 +
18444 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18445 +               ret = -EFAULT;
18446 +       return ret;
18447 +}
18448 +
18449 +
18450 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18451 +{
18452 +       struct inode *in = de->d_inode;
18453 +       int error = 0, is_proc = 0, has_tag = 0;
18454 +       struct iattr attr = { 0 };
18455 +
18456 +       if (!in || !in->i_sb)
18457 +               return -ESRCH;
18458 +
18459 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
18460 +       if ((*mask & IATTR_FLAGS) && !is_proc)
18461 +               return -EINVAL;
18462 +
18463 +       has_tag = IS_TAGGED(in) ||
18464 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
18465 +       if ((*mask & IATTR_TAG) && !has_tag)
18466 +               return -EINVAL;
18467 +
18468 +       mutex_lock(&in->i_mutex);
18469 +       if (*mask & IATTR_TAG) {
18470 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
18471 +               attr.ia_valid |= ATTR_TAG;
18472 +       }
18473 +
18474 +       if (*mask & IATTR_FLAGS) {
18475 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
18476 +               unsigned int iflags = PROC_I(in)->vx_flags;
18477 +
18478 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
18479 +                       | (*flags & IATTR_FLAGS);
18480 +               PROC_I(in)->vx_flags = iflags;
18481 +               if (entry)
18482 +                       entry->vx_flags = iflags;
18483 +       }
18484 +
18485 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
18486 +               IATTR_BARRIER | IATTR_COW)) {
18487 +               int iflags = in->i_flags;
18488 +               int vflags = in->i_vflags;
18489 +
18490 +               if (*mask & IATTR_IMMUTABLE) {
18491 +                       if (*flags & IATTR_IMMUTABLE)
18492 +                               iflags |= S_IMMUTABLE;
18493 +                       else
18494 +                               iflags &= ~S_IMMUTABLE;
18495 +               }
18496 +               if (*mask & IATTR_IXUNLINK) {
18497 +                       if (*flags & IATTR_IXUNLINK)
18498 +                               iflags |= S_IXUNLINK;
18499 +                       else
18500 +                               iflags &= ~S_IXUNLINK;
18501 +               }
18502 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
18503 +                       if (*flags & IATTR_BARRIER)
18504 +                               vflags |= V_BARRIER;
18505 +                       else
18506 +                               vflags &= ~V_BARRIER;
18507 +               }
18508 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
18509 +                       if (*flags & IATTR_COW)
18510 +                               vflags |= V_COW;
18511 +                       else
18512 +                               vflags &= ~V_COW;
18513 +               }
18514 +               if (in->i_op && in->i_op->sync_flags) {
18515 +                       error = in->i_op->sync_flags(in, iflags, vflags);
18516 +                       if (error)
18517 +                               goto out;
18518 +               }
18519 +       }
18520 +
18521 +       if (attr.ia_valid) {
18522 +               if (in->i_op && in->i_op->setattr)
18523 +                       error = in->i_op->setattr(de, &attr);
18524 +               else {
18525 +                       error = inode_change_ok(in, &attr);
18526 +                       if (!error) {
18527 +                               setattr_copy(in, &attr);
18528 +                               mark_inode_dirty(in);
18529 +                       }
18530 +               }
18531 +       }
18532 +
18533 +out:
18534 +       mutex_unlock(&in->i_mutex);
18535 +       return error;
18536 +}
18537 +
18538 +int vc_set_iattr(void __user *data)
18539 +{
18540 +       struct path path;
18541 +       struct vcmd_ctx_iattr_v1 vc_data;
18542 +       int ret;
18543 +
18544 +       if (!capable(CAP_LINUX_IMMUTABLE))
18545 +               return -EPERM;
18546 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18547 +               return -EFAULT;
18548 +
18549 +       ret = user_lpath(vc_data.name, &path);
18550 +       if (!ret) {
18551 +               ret = __vc_set_iattr(path.dentry,
18552 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18553 +               path_put(&path);
18554 +       }
18555 +
18556 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18557 +               ret = -EFAULT;
18558 +       return ret;
18559 +}
18560 +
18561 +#ifdef CONFIG_COMPAT
18562 +
18563 +int vc_set_iattr_x32(void __user *data)
18564 +{
18565 +       struct path path;
18566 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
18567 +       int ret;
18568 +
18569 +       if (!capable(CAP_LINUX_IMMUTABLE))
18570 +               return -EPERM;
18571 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18572 +               return -EFAULT;
18573 +
18574 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18575 +       if (!ret) {
18576 +               ret = __vc_set_iattr(path.dentry,
18577 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18578 +               path_put(&path);
18579 +       }
18580 +
18581 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18582 +               ret = -EFAULT;
18583 +       return ret;
18584 +}
18585 +
18586 +#endif /* CONFIG_COMPAT */
18587 +
18588 +int vc_fset_iattr(uint32_t fd, void __user *data)
18589 +{
18590 +       struct file *filp;
18591 +       struct vcmd_ctx_fiattr_v0 vc_data;
18592 +       int ret;
18593 +
18594 +       if (!capable(CAP_LINUX_IMMUTABLE))
18595 +               return -EPERM;
18596 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18597 +               return -EFAULT;
18598 +
18599 +       filp = fget(fd);
18600 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18601 +               return -EBADF;
18602 +
18603 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
18604 +               &vc_data.flags, &vc_data.mask);
18605 +
18606 +       fput(filp);
18607 +
18608 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18609 +               return -EFAULT;
18610 +       return ret;
18611 +}
18612 +
18613 +
18614 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
18615 +
18616 +static match_table_t tokens = {
18617 +       {Opt_notagcheck, "notagcheck"},
18618 +#ifdef CONFIG_PROPAGATE
18619 +       {Opt_notag, "notag"},
18620 +       {Opt_tag, "tag"},
18621 +       {Opt_tagid, "tagid=%u"},
18622 +#endif
18623 +       {Opt_err, NULL}
18624 +};
18625 +
18626 +
18627 +static void __dx_parse_remove(char *string, char *opt)
18628 +{
18629 +       char *p = strstr(string, opt);
18630 +       char *q = p;
18631 +
18632 +       if (p) {
18633 +               while (*q != '\0' && *q != ',')
18634 +                       q++;
18635 +               while (*q)
18636 +                       *p++ = *q++;
18637 +               while (*p)
18638 +                       *p++ = '\0';
18639 +       }
18640 +}
18641 +
18642 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
18643 +                unsigned long *flags)
18644 +{
18645 +       int set = 0;
18646 +       substring_t args[MAX_OPT_ARGS];
18647 +       int token;
18648 +       char *s, *p, *opts;
18649 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
18650 +       int option = 0;
18651 +#endif
18652 +
18653 +       if (!string)
18654 +               return 0;
18655 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
18656 +       if (!s)
18657 +               return 0;
18658 +
18659 +       opts = s;
18660 +       while ((p = strsep(&opts, ",")) != NULL) {
18661 +               token = match_token(p, tokens, args);
18662 +
18663 +               switch (token) {
18664 +#ifdef CONFIG_PROPAGATE
18665 +               case Opt_tag:
18666 +                       if (tag)
18667 +                               *tag = 0;
18668 +                       if (remove)
18669 +                               __dx_parse_remove(s, "tag");
18670 +                       *mnt_flags |= MNT_TAGID;
18671 +                       set |= MNT_TAGID;
18672 +                       break;
18673 +               case Opt_notag:
18674 +                       if (remove)
18675 +                               __dx_parse_remove(s, "notag");
18676 +                       *mnt_flags |= MNT_NOTAG;
18677 +                       set |= MNT_NOTAG;
18678 +                       break;
18679 +               case Opt_tagid:
18680 +                       if (tag && !match_int(args, &option))
18681 +                               *tag = option;
18682 +                       if (remove)
18683 +                               __dx_parse_remove(s, "tagid");
18684 +                       *mnt_flags |= MNT_TAGID;
18685 +                       set |= MNT_TAGID;
18686 +                       break;
18687 +#endif /* CONFIG_PROPAGATE */
18688 +               case Opt_notagcheck:
18689 +                       if (remove)
18690 +                               __dx_parse_remove(s, "notagcheck");
18691 +                       *flags |= MS_NOTAGCHECK;
18692 +                       set |= MS_NOTAGCHECK;
18693 +                       break;
18694 +               }
18695 +               vxdprintk(VXD_CBIT(tag, 7),
18696 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
18697 +                       p, token, option);
18698 +       }
18699 +       if (set)
18700 +               strcpy(string, s);
18701 +       kfree(s);
18702 +       return set;
18703 +}
18704 +
18705 +#ifdef CONFIG_PROPAGATE
18706 +
18707 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
18708 +{
18709 +       vtag_t new_tag = 0;
18710 +       struct vfsmount *mnt;
18711 +       int propagate;
18712 +
18713 +       if (!nd)
18714 +               return;
18715 +       mnt = nd->path.mnt;
18716 +       if (!mnt)
18717 +               return;
18718 +
18719 +       propagate = (mnt->mnt_flags & MNT_TAGID);
18720 +       if (propagate)
18721 +               new_tag = mnt->mnt_tag;
18722 +
18723 +       vxdprintk(VXD_CBIT(tag, 7),
18724 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
18725 +               inode, inode->i_ino, inode->i_tag,
18726 +               new_tag, (propagate) ? 1 : 0);
18727 +
18728 +       if (propagate)
18729 +               i_tag_write(inode, new_tag);
18730 +}
18731 +
18732 +#include <linux/module.h>
18733 +
18734 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
18735 +
18736 +#endif /* CONFIG_PROPAGATE */
18737 +
18738 diff -NurpP --minimal linux-3.13.1/kernel/vserver/limit.c linux-3.13.1-vs2.3.6.10/kernel/vserver/limit.c
18739 --- linux-3.13.1/kernel/vserver/limit.c 1970-01-01 00:00:00.000000000 +0000
18740 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/limit.c      2014-02-01 00:22:08.000000000 +0000
18741 @@ -0,0 +1,345 @@
18742 +/*
18743 + *  linux/kernel/vserver/limit.c
18744 + *
18745 + *  Virtual Server: Context Limits
18746 + *
18747 + *  Copyright (C) 2004-2010  Herbert Pötzl
18748 + *
18749 + *  V0.01  broken out from vcontext V0.05
18750 + *  V0.02  changed vcmds to vxi arg
18751 + *  V0.03  added memory cgroup support
18752 + *
18753 + */
18754 +
18755 +#include <linux/sched.h>
18756 +#include <linux/module.h>
18757 +#include <linux/memcontrol.h>
18758 +#include <linux/res_counter.h>
18759 +#include <linux/vs_limit.h>
18760 +#include <linux/vserver/limit.h>
18761 +#include <linux/vserver/limit_cmd.h>
18762 +
18763 +#include <asm/uaccess.h>
18764 +
18765 +
18766 +const char *vlimit_name[NUM_LIMITS] = {
18767 +       [RLIMIT_CPU]            = "CPU",
18768 +       [RLIMIT_NPROC]          = "NPROC",
18769 +       [RLIMIT_NOFILE]         = "NOFILE",
18770 +       [RLIMIT_LOCKS]          = "LOCKS",
18771 +       [RLIMIT_SIGPENDING]     = "SIGP",
18772 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
18773 +
18774 +       [VLIMIT_NSOCK]          = "NSOCK",
18775 +       [VLIMIT_OPENFD]         = "OPENFD",
18776 +       [VLIMIT_SHMEM]          = "SHMEM",
18777 +       [VLIMIT_DENTRY]         = "DENTRY",
18778 +};
18779 +
18780 +EXPORT_SYMBOL_GPL(vlimit_name);
18781 +
18782 +#define MASK_ENTRY(x)  (1 << (x))
18783 +
18784 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
18785 +               /* minimum */
18786 +       0
18787 +       ,       /* softlimit */
18788 +       0
18789 +       ,       /* maximum */
18790 +       MASK_ENTRY( RLIMIT_NPROC        ) |
18791 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
18792 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
18793 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
18794 +
18795 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
18796 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
18797 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
18798 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
18799 +       0
18800 +};
18801 +               /* accounting only */
18802 +uint32_t account_mask =
18803 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
18804 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
18805 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
18806 +       0;
18807 +
18808 +
18809 +static int is_valid_vlimit(int id)
18810 +{
18811 +       uint32_t mask = vlimit_mask.minimum |
18812 +               vlimit_mask.softlimit | vlimit_mask.maximum;
18813 +       return mask & (1 << id);
18814 +}
18815 +
18816 +static int is_accounted_vlimit(int id)
18817 +{
18818 +       if (is_valid_vlimit(id))
18819 +               return 1;
18820 +       return account_mask & (1 << id);
18821 +}
18822 +
18823 +
18824 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
18825 +{
18826 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
18827 +       return VX_VLIM(limit);
18828 +}
18829 +
18830 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
18831 +{
18832 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
18833 +       return VX_VLIM(limit);
18834 +}
18835 +
18836 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
18837 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
18838 +{
18839 +       if (!is_valid_vlimit(id))
18840 +               return -EINVAL;
18841 +
18842 +       if (minimum)
18843 +               *minimum = CRLIM_UNSET;
18844 +       if (softlimit)
18845 +               *softlimit = vc_get_soft(vxi, id);
18846 +       if (maximum)
18847 +               *maximum = vc_get_hard(vxi, id);
18848 +       return 0;
18849 +}
18850 +
18851 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
18852 +{
18853 +       struct vcmd_ctx_rlimit_v0 vc_data;
18854 +       int ret;
18855 +
18856 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18857 +               return -EFAULT;
18858 +
18859 +       ret = do_get_rlimit(vxi, vc_data.id,
18860 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18861 +       if (ret)
18862 +               return ret;
18863 +
18864 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18865 +               return -EFAULT;
18866 +       return 0;
18867 +}
18868 +
18869 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
18870 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
18871 +{
18872 +       if (!is_valid_vlimit(id))
18873 +               return -EINVAL;
18874 +
18875 +       if (maximum != CRLIM_KEEP)
18876 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
18877 +       if (softlimit != CRLIM_KEEP)
18878 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
18879 +
18880 +       /* clamp soft limit */
18881 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
18882 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
18883 +
18884 +       return 0;
18885 +}
18886 +
18887 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
18888 +{
18889 +       struct vcmd_ctx_rlimit_v0 vc_data;
18890 +
18891 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18892 +               return -EFAULT;
18893 +
18894 +       return do_set_rlimit(vxi, vc_data.id,
18895 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18896 +}
18897 +
18898 +#ifdef CONFIG_IA32_EMULATION
18899 +
18900 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
18901 +{
18902 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18903 +
18904 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18905 +               return -EFAULT;
18906 +
18907 +       return do_set_rlimit(vxi, vc_data.id,
18908 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18909 +}
18910 +
18911 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
18912 +{
18913 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18914 +       int ret;
18915 +
18916 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18917 +               return -EFAULT;
18918 +
18919 +       ret = do_get_rlimit(vxi, vc_data.id,
18920 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18921 +       if (ret)
18922 +               return ret;
18923 +
18924 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18925 +               return -EFAULT;
18926 +       return 0;
18927 +}
18928 +
18929 +#endif /* CONFIG_IA32_EMULATION */
18930 +
18931 +
18932 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
18933 +{
18934 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
18935 +               return -EFAULT;
18936 +       return 0;
18937 +}
18938 +
18939 +
18940 +static inline void vx_reset_hits(struct _vx_limit *limit)
18941 +{
18942 +       int lim;
18943 +
18944 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18945 +               atomic_set(&__rlim_lhit(limit, lim), 0);
18946 +       }
18947 +}
18948 +
18949 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
18950 +{
18951 +       vx_reset_hits(&vxi->limit);
18952 +       return 0;
18953 +}
18954 +
18955 +static inline void vx_reset_minmax(struct _vx_limit *limit)
18956 +{
18957 +       rlim_t value;
18958 +       int lim;
18959 +
18960 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18961 +               value = __rlim_get(limit, lim);
18962 +               __rlim_rmax(limit, lim) = value;
18963 +               __rlim_rmin(limit, lim) = value;
18964 +       }
18965 +}
18966 +
18967 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
18968 +{
18969 +       vx_reset_minmax(&vxi->limit);
18970 +       return 0;
18971 +}
18972 +
18973 +
18974 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
18975 +{
18976 +       struct vcmd_rlimit_stat_v0 vc_data;
18977 +       struct _vx_limit *limit = &vxi->limit;
18978 +       int id;
18979 +
18980 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18981 +               return -EFAULT;
18982 +
18983 +       id = vc_data.id;
18984 +       if (!is_accounted_vlimit(id))
18985 +               return -EINVAL;
18986 +
18987 +       vx_limit_fixup(limit, id);
18988 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
18989 +       vc_data.value = __rlim_get(limit, id);
18990 +       vc_data.minimum = __rlim_rmin(limit, id);
18991 +       vc_data.maximum = __rlim_rmax(limit, id);
18992 +
18993 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18994 +               return -EFAULT;
18995 +       return 0;
18996 +}
18997 +
18998 +
18999 +void vx_vsi_meminfo(struct sysinfo *val)
19000 +{
19001 +#ifdef CONFIG_MEMCG
19002 +       struct mem_cgroup *mcg;
19003 +       u64 res_limit, res_usage;
19004 +
19005 +       rcu_read_lock();
19006 +       mcg = mem_cgroup_from_task(current);
19007 +       rcu_read_unlock();
19008 +       if (!mcg)
19009 +               goto out;
19010 +
19011 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19012 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19013 +
19014 +       if (res_limit != RES_COUNTER_MAX)
19015 +               val->totalram = (res_limit >> PAGE_SHIFT);
19016 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19017 +       val->bufferram = 0;
19018 +       val->totalhigh = 0;
19019 +       val->freehigh = 0;
19020 +out:
19021 +#endif /* CONFIG_MEMCG */
19022 +       return;
19023 +}
19024 +
19025 +void vx_vsi_swapinfo(struct sysinfo *val)
19026 +{
19027 +#ifdef CONFIG_MEMCG
19028 +#ifdef CONFIG_MEMCG_SWAP
19029 +       struct mem_cgroup *mcg;
19030 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19031 +       s64 swap_limit, swap_usage;
19032 +
19033 +       rcu_read_lock();
19034 +       mcg = mem_cgroup_from_task(current);
19035 +       rcu_read_unlock();
19036 +       if (!mcg)
19037 +               goto out;
19038 +
19039 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19040 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19041 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19042 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19043 +
19044 +       /* memory unlimited */
19045 +       if (res_limit == RES_COUNTER_MAX)
19046 +               goto out;
19047 +
19048 +       swap_limit = memsw_limit - res_limit;
19049 +       /* we have a swap limit? */
19050 +       if (memsw_limit != RES_COUNTER_MAX)
19051 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19052 +
19053 +       /* calculate swap part */
19054 +       swap_usage = (memsw_usage > res_usage) ?
19055 +               memsw_usage - res_usage : 0;
19056 +
19057 +       /* total shown minus usage gives free swap */
19058 +       val->freeswap = (swap_usage < swap_limit) ?
19059 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19060 +out:
19061 +#else  /* !CONFIG_MEMCG_SWAP */
19062 +       val->totalswap = 0;
19063 +       val->freeswap = 0;
19064 +#endif /* !CONFIG_MEMCG_SWAP */
19065 +#endif /* CONFIG_MEMCG */
19066 +       return;
19067 +}
19068 +
19069 +long vx_vsi_cached(struct sysinfo *val)
19070 +{
19071 +       long cache = 0;
19072 +#ifdef CONFIG_MEMCG
19073 +       struct mem_cgroup *mcg;
19074 +
19075 +       rcu_read_lock();
19076 +       mcg = mem_cgroup_from_task(current);
19077 +       rcu_read_unlock();
19078 +       if (!mcg)
19079 +               goto out;
19080 +
19081 +       cache = mem_cgroup_stat_read_cache(mcg);
19082 +out:
19083 +#endif
19084 +       return cache;
19085 +}
19086 +
19087 diff -NurpP --minimal linux-3.13.1/kernel/vserver/limit_init.h linux-3.13.1-vs2.3.6.10/kernel/vserver/limit_init.h
19088 --- linux-3.13.1/kernel/vserver/limit_init.h    1970-01-01 00:00:00.000000000 +0000
19089 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/limit_init.h 2014-01-31 20:38:04.000000000 +0000
19090 @@ -0,0 +1,31 @@
19091 +
19092 +
19093 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19094 +{
19095 +       int lim;
19096 +
19097 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19098 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19099 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19100 +               __rlim_set(limit, lim, 0);
19101 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19102 +               __rlim_rmin(limit, lim) = 0;
19103 +               __rlim_rmax(limit, lim) = 0;
19104 +       }
19105 +}
19106 +
19107 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19108 +{
19109 +       rlim_t value;
19110 +       int lim;
19111 +
19112 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19113 +               if ((1 << lim) & VLIM_NOCHECK)
19114 +                       continue;
19115 +               value = __rlim_get(limit, lim);
19116 +               vxwprintk_xid(value,
19117 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19118 +                       limit, vlimit_name[lim], lim, (long)value);
19119 +       }
19120 +}
19121 +
19122 diff -NurpP --minimal linux-3.13.1/kernel/vserver/limit_proc.h linux-3.13.1-vs2.3.6.10/kernel/vserver/limit_proc.h
19123 --- linux-3.13.1/kernel/vserver/limit_proc.h    1970-01-01 00:00:00.000000000 +0000
19124 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/limit_proc.h 2014-01-31 20:38:04.000000000 +0000
19125 @@ -0,0 +1,57 @@
19126 +#ifndef _VX_LIMIT_PROC_H
19127 +#define _VX_LIMIT_PROC_H
19128 +
19129 +#include <linux/vserver/limit_int.h>
19130 +
19131 +
19132 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19133 +#define VX_LIMIT_TOP   \
19134 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19135 +
19136 +#define VX_LIMIT_ARG(r)                                \
19137 +       (unsigned long)__rlim_get(limit, r),    \
19138 +       (unsigned long)__rlim_rmin(limit, r),   \
19139 +       (unsigned long)__rlim_rmax(limit, r),   \
19140 +       VX_VLIM(__rlim_soft(limit, r)),         \
19141 +       VX_VLIM(__rlim_hard(limit, r)),         \
19142 +       atomic_read(&__rlim_lhit(limit, r))
19143 +
19144 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19145 +{
19146 +       vx_limit_fixup(limit, -1);
19147 +       return sprintf(buffer, VX_LIMIT_TOP
19148 +               "PROC"  VX_LIMIT_FMT
19149 +               "VM"    VX_LIMIT_FMT
19150 +               "VML"   VX_LIMIT_FMT
19151 +               "RSS"   VX_LIMIT_FMT
19152 +               "ANON"  VX_LIMIT_FMT
19153 +               "RMAP"  VX_LIMIT_FMT
19154 +               "FILES" VX_LIMIT_FMT
19155 +               "OFD"   VX_LIMIT_FMT
19156 +               "LOCKS" VX_LIMIT_FMT
19157 +               "SOCK"  VX_LIMIT_FMT
19158 +               "MSGQ"  VX_LIMIT_FMT
19159 +               "SHM"   VX_LIMIT_FMT
19160 +               "SEMA"  VX_LIMIT_FMT
19161 +               "SEMS"  VX_LIMIT_FMT
19162 +               "DENT"  VX_LIMIT_FMT,
19163 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19164 +               VX_LIMIT_ARG(RLIMIT_AS),
19165 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19166 +               VX_LIMIT_ARG(RLIMIT_RSS),
19167 +               VX_LIMIT_ARG(VLIMIT_ANON),
19168 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19169 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19170 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19171 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19172 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19173 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19174 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19175 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19176 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19177 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19178 +}
19179 +
19180 +#endif /* _VX_LIMIT_PROC_H */
19181 +
19182 +
19183 diff -NurpP --minimal linux-3.13.1/kernel/vserver/network.c linux-3.13.1-vs2.3.6.10/kernel/vserver/network.c
19184 --- linux-3.13.1/kernel/vserver/network.c       1970-01-01 00:00:00.000000000 +0000
19185 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/network.c    2014-01-31 20:38:04.000000000 +0000
19186 @@ -0,0 +1,1053 @@
19187 +/*
19188 + *  linux/kernel/vserver/network.c
19189 + *
19190 + *  Virtual Server: Network Support
19191 + *
19192 + *  Copyright (C) 2003-2007  Herbert Pötzl
19193 + *
19194 + *  V0.01  broken out from vcontext V0.05
19195 + *  V0.02  cleaned up implementation
19196 + *  V0.03  added equiv nx commands
19197 + *  V0.04  switch to RCU based hash
19198 + *  V0.05  and back to locking again
19199 + *  V0.06  changed vcmds to nxi arg
19200 + *  V0.07  have __create claim() the nxi
19201 + *
19202 + */
19203 +
19204 +#include <linux/err.h>
19205 +#include <linux/slab.h>
19206 +#include <linux/rcupdate.h>
19207 +#include <net/ipv6.h>
19208 +
19209 +#include <linux/vs_network.h>
19210 +#include <linux/vs_pid.h>
19211 +#include <linux/vserver/network_cmd.h>
19212 +
19213 +
19214 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19215 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19216 +
19217 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19218 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19219 +
19220 +
19221 +static int __init init_network(void)
19222 +{
19223 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19224 +               sizeof(struct nx_addr_v4), 0,
19225 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19226 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19227 +               sizeof(struct nx_addr_v6), 0,
19228 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19229 +       return 0;
19230 +}
19231 +
19232 +
19233 +/*     __alloc_nx_addr_v4()                                    */
19234 +
19235 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19236 +{
19237 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19238 +               nx_addr_v4_cachep, GFP_KERNEL);
19239 +
19240 +       if (!IS_ERR(nxa))
19241 +               memset(nxa, 0, sizeof(*nxa));
19242 +       return nxa;
19243 +}
19244 +
19245 +/*     __dealloc_nx_addr_v4()                                  */
19246 +
19247 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19248 +{
19249 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19250 +}
19251 +
19252 +/*     __dealloc_nx_addr_v4_all()                              */
19253 +
19254 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19255 +{
19256 +       while (nxa) {
19257 +               struct nx_addr_v4 *next = nxa->next;
19258 +
19259 +               __dealloc_nx_addr_v4(nxa);
19260 +               nxa = next;
19261 +       }
19262 +}
19263 +
19264 +
19265 +#ifdef CONFIG_IPV6
19266 +
19267 +/*     __alloc_nx_addr_v6()                                    */
19268 +
19269 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19270 +{
19271 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19272 +               nx_addr_v6_cachep, GFP_KERNEL);
19273 +
19274 +       if (!IS_ERR(nxa))
19275 +               memset(nxa, 0, sizeof(*nxa));
19276 +       return nxa;
19277 +}
19278 +
19279 +/*     __dealloc_nx_addr_v6()                                  */
19280 +
19281 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19282 +{
19283 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19284 +}
19285 +
19286 +/*     __dealloc_nx_addr_v6_all()                              */
19287 +
19288 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19289 +{
19290 +       while (nxa) {
19291 +               struct nx_addr_v6 *next = nxa->next;
19292 +
19293 +               __dealloc_nx_addr_v6(nxa);
19294 +               nxa = next;
19295 +       }
19296 +}
19297 +
19298 +#endif /* CONFIG_IPV6 */
19299 +
19300 +/*     __alloc_nx_info()
19301 +
19302 +       * allocate an initialized nx_info struct
19303 +       * doesn't make it visible (hash)                        */
19304 +
19305 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19306 +{
19307 +       struct nx_info *new = NULL;
19308 +
19309 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19310 +
19311 +       /* would this benefit from a slab cache? */
19312 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19313 +       if (!new)
19314 +               return 0;
19315 +
19316 +       memset(new, 0, sizeof(struct nx_info));
19317 +       new->nx_id = nid;
19318 +       INIT_HLIST_NODE(&new->nx_hlist);
19319 +       atomic_set(&new->nx_usecnt, 0);
19320 +       atomic_set(&new->nx_tasks, 0);
19321 +       spin_lock_init(&new->addr_lock);
19322 +       new->nx_state = 0;
19323 +
19324 +       new->nx_flags = NXF_INIT_SET;
19325 +
19326 +       /* rest of init goes here */
19327 +
19328 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19329 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19330 +
19331 +       vxdprintk(VXD_CBIT(nid, 0),
19332 +               "alloc_nx_info(%d) = %p", nid, new);
19333 +       atomic_inc(&nx_global_ctotal);
19334 +       return new;
19335 +}
19336 +
19337 +/*     __dealloc_nx_info()
19338 +
19339 +       * final disposal of nx_info                             */
19340 +
19341 +static void __dealloc_nx_info(struct nx_info *nxi)
19342 +{
19343 +       vxdprintk(VXD_CBIT(nid, 0),
19344 +               "dealloc_nx_info(%p)", nxi);
19345 +
19346 +       nxi->nx_hlist.next = LIST_POISON1;
19347 +       nxi->nx_id = -1;
19348 +
19349 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19350 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19351 +
19352 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
19353 +#ifdef CONFIG_IPV6
19354 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
19355 +#endif
19356 +
19357 +       nxi->nx_state |= NXS_RELEASED;
19358 +       kfree(nxi);
19359 +       atomic_dec(&nx_global_ctotal);
19360 +}
19361 +
19362 +static void __shutdown_nx_info(struct nx_info *nxi)
19363 +{
19364 +       nxi->nx_state |= NXS_SHUTDOWN;
19365 +       vs_net_change(nxi, VSC_NETDOWN);
19366 +}
19367 +
19368 +/*     exported stuff                                          */
19369 +
19370 +void free_nx_info(struct nx_info *nxi)
19371 +{
19372 +       /* context shutdown is mandatory */
19373 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
19374 +
19375 +       /* context must not be hashed */
19376 +       BUG_ON(nxi->nx_state & NXS_HASHED);
19377 +
19378 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19379 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19380 +
19381 +       __dealloc_nx_info(nxi);
19382 +}
19383 +
19384 +
19385 +void __nx_set_lback(struct nx_info *nxi)
19386 +{
19387 +       int nid = nxi->nx_id;
19388 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
19389 +
19390 +       nxi->v4_lback.s_addr = lback;
19391 +}
19392 +
19393 +extern int __nx_inet_add_lback(__be32 addr);
19394 +extern int __nx_inet_del_lback(__be32 addr);
19395 +
19396 +
19397 +/*     hash table for nx_info hash */
19398 +
19399 +#define NX_HASH_SIZE   13
19400 +
19401 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
19402 +
19403 +static DEFINE_SPINLOCK(nx_info_hash_lock);
19404 +
19405 +
19406 +static inline unsigned int __hashval(vnid_t nid)
19407 +{
19408 +       return (nid % NX_HASH_SIZE);
19409 +}
19410 +
19411 +
19412 +
19413 +/*     __hash_nx_info()
19414 +
19415 +       * add the nxi to the global hash table
19416 +       * requires the hash_lock to be held                     */
19417 +
19418 +static inline void __hash_nx_info(struct nx_info *nxi)
19419 +{
19420 +       struct hlist_head *head;
19421 +
19422 +       vxd_assert_lock(&nx_info_hash_lock);
19423 +       vxdprintk(VXD_CBIT(nid, 4),
19424 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
19425 +
19426 +       /* context must not be hashed */
19427 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
19428 +
19429 +       nxi->nx_state |= NXS_HASHED;
19430 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
19431 +       hlist_add_head(&nxi->nx_hlist, head);
19432 +       atomic_inc(&nx_global_cactive);
19433 +}
19434 +
19435 +/*     __unhash_nx_info()
19436 +
19437 +       * remove the nxi from the global hash table
19438 +       * requires the hash_lock to be held                     */
19439 +
19440 +static inline void __unhash_nx_info(struct nx_info *nxi)
19441 +{
19442 +       vxd_assert_lock(&nx_info_hash_lock);
19443 +       vxdprintk(VXD_CBIT(nid, 4),
19444 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
19445 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
19446 +
19447 +       /* context must be hashed */
19448 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
19449 +       /* but without tasks */
19450 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19451 +
19452 +       nxi->nx_state &= ~NXS_HASHED;
19453 +       hlist_del(&nxi->nx_hlist);
19454 +       atomic_dec(&nx_global_cactive);
19455 +}
19456 +
19457 +
19458 +/*     __lookup_nx_info()
19459 +
19460 +       * requires the hash_lock to be held
19461 +       * doesn't increment the nx_refcnt                       */
19462 +
19463 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
19464 +{
19465 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
19466 +       struct hlist_node *pos;
19467 +       struct nx_info *nxi;
19468 +
19469 +       vxd_assert_lock(&nx_info_hash_lock);
19470 +       hlist_for_each(pos, head) {
19471 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19472 +
19473 +               if (nxi->nx_id == nid)
19474 +                       goto found;
19475 +       }
19476 +       nxi = NULL;
19477 +found:
19478 +       vxdprintk(VXD_CBIT(nid, 0),
19479 +               "__lookup_nx_info(#%u): %p[#%u]",
19480 +               nid, nxi, nxi ? nxi->nx_id : 0);
19481 +       return nxi;
19482 +}
19483 +
19484 +
19485 +/*     __create_nx_info()
19486 +
19487 +       * create the requested context
19488 +       * get(), claim() and hash it                            */
19489 +
19490 +static struct nx_info *__create_nx_info(int id)
19491 +{
19492 +       struct nx_info *new, *nxi = NULL;
19493 +
19494 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
19495 +
19496 +       if (!(new = __alloc_nx_info(id)))
19497 +               return ERR_PTR(-ENOMEM);
19498 +
19499 +       /* required to make dynamic xids unique */
19500 +       spin_lock(&nx_info_hash_lock);
19501 +
19502 +       /* static context requested */
19503 +       if ((nxi = __lookup_nx_info(id))) {
19504 +               vxdprintk(VXD_CBIT(nid, 0),
19505 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
19506 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19507 +                       nxi = ERR_PTR(-EBUSY);
19508 +               else
19509 +                       nxi = ERR_PTR(-EEXIST);
19510 +               goto out_unlock;
19511 +       }
19512 +       /* new context */
19513 +       vxdprintk(VXD_CBIT(nid, 0),
19514 +               "create_nx_info(%d) = %p (new)", id, new);
19515 +       claim_nx_info(new, NULL);
19516 +       __nx_set_lback(new);
19517 +       __hash_nx_info(get_nx_info(new));
19518 +       nxi = new, new = NULL;
19519 +
19520 +out_unlock:
19521 +       spin_unlock(&nx_info_hash_lock);
19522 +       if (new)
19523 +               __dealloc_nx_info(new);
19524 +       return nxi;
19525 +}
19526 +
19527 +
19528 +
19529 +/*     exported stuff                                          */
19530 +
19531 +
19532 +void unhash_nx_info(struct nx_info *nxi)
19533 +{
19534 +       __shutdown_nx_info(nxi);
19535 +       spin_lock(&nx_info_hash_lock);
19536 +       __unhash_nx_info(nxi);
19537 +       spin_unlock(&nx_info_hash_lock);
19538 +}
19539 +
19540 +/*     lookup_nx_info()
19541 +
19542 +       * search for a nx_info and get() it
19543 +       * negative id means current                             */
19544 +
19545 +struct nx_info *lookup_nx_info(int id)
19546 +{
19547 +       struct nx_info *nxi = NULL;
19548 +
19549 +       if (id < 0) {
19550 +               nxi = get_nx_info(current_nx_info());
19551 +       } else if (id > 1) {
19552 +               spin_lock(&nx_info_hash_lock);
19553 +               nxi = get_nx_info(__lookup_nx_info(id));
19554 +               spin_unlock(&nx_info_hash_lock);
19555 +       }
19556 +       return nxi;
19557 +}
19558 +
19559 +/*     nid_is_hashed()
19560 +
19561 +       * verify that nid is still hashed                       */
19562 +
19563 +int nid_is_hashed(vnid_t nid)
19564 +{
19565 +       int hashed;
19566 +
19567 +       spin_lock(&nx_info_hash_lock);
19568 +       hashed = (__lookup_nx_info(nid) != NULL);
19569 +       spin_unlock(&nx_info_hash_lock);
19570 +       return hashed;
19571 +}
19572 +
19573 +
19574 +#ifdef CONFIG_PROC_FS
19575 +
19576 +/*     get_nid_list()
19577 +
19578 +       * get a subset of hashed nids for proc
19579 +       * assumes size is at least one                          */
19580 +
19581 +int get_nid_list(int index, unsigned int *nids, int size)
19582 +{
19583 +       int hindex, nr_nids = 0;
19584 +
19585 +       /* only show current and children */
19586 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
19587 +               if (index > 0)
19588 +                       return 0;
19589 +               nids[nr_nids] = nx_current_nid();
19590 +               return 1;
19591 +       }
19592 +
19593 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
19594 +               struct hlist_head *head = &nx_info_hash[hindex];
19595 +               struct hlist_node *pos;
19596 +
19597 +               spin_lock(&nx_info_hash_lock);
19598 +               hlist_for_each(pos, head) {
19599 +                       struct nx_info *nxi;
19600 +
19601 +                       if (--index > 0)
19602 +                               continue;
19603 +
19604 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19605 +                       nids[nr_nids] = nxi->nx_id;
19606 +                       if (++nr_nids >= size) {
19607 +                               spin_unlock(&nx_info_hash_lock);
19608 +                               goto out;
19609 +                       }
19610 +               }
19611 +               /* keep the lock time short */
19612 +               spin_unlock(&nx_info_hash_lock);
19613 +       }
19614 +out:
19615 +       return nr_nids;
19616 +}
19617 +#endif
19618 +
19619 +
19620 +/*
19621 + *     migrate task to new network
19622 + *     gets nxi, puts old_nxi on change
19623 + */
19624 +
19625 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
19626 +{
19627 +       struct nx_info *old_nxi;
19628 +       int ret = 0;
19629 +
19630 +       if (!p || !nxi)
19631 +               BUG();
19632 +
19633 +       vxdprintk(VXD_CBIT(nid, 5),
19634 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
19635 +               p, nxi, nxi->nx_id,
19636 +               atomic_read(&nxi->nx_usecnt),
19637 +               atomic_read(&nxi->nx_tasks));
19638 +
19639 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
19640 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19641 +               return -EACCES;
19642 +
19643 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
19644 +               return -EFAULT;
19645 +
19646 +       /* maybe disallow this completely? */
19647 +       old_nxi = task_get_nx_info(p);
19648 +       if (old_nxi == nxi)
19649 +               goto out;
19650 +
19651 +       task_lock(p);
19652 +       if (old_nxi)
19653 +               clr_nx_info(&p->nx_info);
19654 +       claim_nx_info(nxi, p);
19655 +       set_nx_info(&p->nx_info, nxi);
19656 +       p->nid = nxi->nx_id;
19657 +       task_unlock(p);
19658 +
19659 +       vxdprintk(VXD_CBIT(nid, 5),
19660 +               "moved task %p into nxi:%p[#%d]",
19661 +               p, nxi, nxi->nx_id);
19662 +
19663 +       if (old_nxi)
19664 +               release_nx_info(old_nxi, p);
19665 +       ret = 0;
19666 +out:
19667 +       put_nx_info(old_nxi);
19668 +       return ret;
19669 +}
19670 +
19671 +
19672 +void nx_set_persistent(struct nx_info *nxi)
19673 +{
19674 +       vxdprintk(VXD_CBIT(nid, 6),
19675 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
19676 +
19677 +       get_nx_info(nxi);
19678 +       claim_nx_info(nxi, NULL);
19679 +}
19680 +
19681 +void nx_clear_persistent(struct nx_info *nxi)
19682 +{
19683 +       vxdprintk(VXD_CBIT(nid, 6),
19684 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
19685 +
19686 +       release_nx_info(nxi, NULL);
19687 +       put_nx_info(nxi);
19688 +}
19689 +
19690 +void nx_update_persistent(struct nx_info *nxi)
19691 +{
19692 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
19693 +               nx_set_persistent(nxi);
19694 +       else
19695 +               nx_clear_persistent(nxi);
19696 +}
19697 +
19698 +/* vserver syscall commands below here */
19699 +
19700 +/* taks nid and nx_info functions */
19701 +
19702 +#include <asm/uaccess.h>
19703 +
19704 +
19705 +int vc_task_nid(uint32_t id)
19706 +{
19707 +       vnid_t nid;
19708 +
19709 +       if (id) {
19710 +               struct task_struct *tsk;
19711 +
19712 +               rcu_read_lock();
19713 +               tsk = find_task_by_real_pid(id);
19714 +               nid = (tsk) ? tsk->nid : -ESRCH;
19715 +               rcu_read_unlock();
19716 +       } else
19717 +               nid = nx_current_nid();
19718 +       return nid;
19719 +}
19720 +
19721 +
19722 +int vc_nx_info(struct nx_info *nxi, void __user *data)
19723 +{
19724 +       struct vcmd_nx_info_v0 vc_data;
19725 +
19726 +       vc_data.nid = nxi->nx_id;
19727 +
19728 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19729 +               return -EFAULT;
19730 +       return 0;
19731 +}
19732 +
19733 +
19734 +/* network functions */
19735 +
19736 +int vc_net_create(uint32_t nid, void __user *data)
19737 +{
19738 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
19739 +       struct nx_info *new_nxi;
19740 +       int ret;
19741 +
19742 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19743 +               return -EFAULT;
19744 +
19745 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
19746 +               return -EINVAL;
19747 +
19748 +       new_nxi = __create_nx_info(nid);
19749 +       if (IS_ERR(new_nxi))
19750 +               return PTR_ERR(new_nxi);
19751 +
19752 +       /* initial flags */
19753 +       new_nxi->nx_flags = vc_data.flagword;
19754 +
19755 +       ret = -ENOEXEC;
19756 +       if (vs_net_change(new_nxi, VSC_NETUP))
19757 +               goto out;
19758 +
19759 +       ret = nx_migrate_task(current, new_nxi);
19760 +       if (ret)
19761 +               goto out;
19762 +
19763 +       /* return context id on success */
19764 +       ret = new_nxi->nx_id;
19765 +
19766 +       /* get a reference for persistent contexts */
19767 +       if ((vc_data.flagword & NXF_PERSISTENT))
19768 +               nx_set_persistent(new_nxi);
19769 +out:
19770 +       release_nx_info(new_nxi, NULL);
19771 +       put_nx_info(new_nxi);
19772 +       return ret;
19773 +}
19774 +
19775 +
19776 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
19777 +{
19778 +       return nx_migrate_task(current, nxi);
19779 +}
19780 +
19781 +
19782 +static inline
19783 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
19784 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
19785 +       struct nx_addr_v4 **prev)
19786 +{
19787 +       struct nx_addr_v4 *nxa = &nxi->v4;
19788 +
19789 +       for (; nxa; nxa = nxa->next) {
19790 +               if ((nxa->ip[0].s_addr == ip) &&
19791 +                   (nxa->ip[1].s_addr == ip2) &&
19792 +                   (nxa->mask.s_addr == mask) &&
19793 +                   (nxa->type == type) &&
19794 +                   (nxa->flags == flags))
19795 +                   return nxa;
19796 +
19797 +               /* save previous entry */
19798 +               if (prev)
19799 +                       *prev = nxa;
19800 +       }
19801 +       return NULL;
19802 +}
19803 +
19804 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19805 +       uint16_t type, uint16_t flags)
19806 +{
19807 +       struct nx_addr_v4 *nxa = NULL;
19808 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
19809 +       unsigned long irqflags;
19810 +       int ret = -EEXIST;
19811 +
19812 +       if (IS_ERR(new))
19813 +               return PTR_ERR(new);
19814 +
19815 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19816 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
19817 +               goto out_unlock;
19818 +
19819 +       if (NX_IPV4(nxi)) {
19820 +               nxa->next = new;
19821 +               nxa = new;
19822 +               new = NULL;
19823 +
19824 +               /* remove single ip for ip list */
19825 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
19826 +       }
19827 +
19828 +       nxa->ip[0].s_addr = ip;
19829 +       nxa->ip[1].s_addr = ip2;
19830 +       nxa->mask.s_addr = mask;
19831 +       nxa->type = type;
19832 +       nxa->flags = flags;
19833 +       ret = 0;
19834 +out_unlock:
19835 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19836 +       if (new)
19837 +               __dealloc_nx_addr_v4(new);
19838 +       return ret;
19839 +}
19840 +
19841 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19842 +       uint16_t type, uint16_t flags)
19843 +{
19844 +       struct nx_addr_v4 *nxa = NULL;
19845 +       struct nx_addr_v4 *old = NULL;
19846 +       unsigned long irqflags;
19847 +       int ret = 0;
19848 +
19849 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19850 +       switch (type) {
19851 +       case NXA_TYPE_ADDR:
19852 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
19853 +               if (old) {
19854 +                       if (nxa) {
19855 +                               nxa->next = old->next;
19856 +                               old->next = NULL;
19857 +                       } else {
19858 +                               if (old->next) {
19859 +                                       nxa = old;
19860 +                                       old = old->next;
19861 +                                       *nxa = *old;
19862 +                                       old->next = NULL;
19863 +                               } else {
19864 +                                       memset(old, 0, sizeof(*old));
19865 +                                       old = NULL;
19866 +                               }
19867 +                       }
19868 +               } else
19869 +                       ret = -ESRCH;
19870 +               break;
19871 +
19872 +       case NXA_TYPE_ANY:
19873 +               nxa = &nxi->v4;
19874 +               old = nxa->next;
19875 +               memset(nxa, 0, sizeof(*nxa));
19876 +               break;
19877 +
19878 +       default:
19879 +               ret = -EINVAL;
19880 +       }
19881 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19882 +       __dealloc_nx_addr_v4_all(old);
19883 +       return ret;
19884 +}
19885 +
19886 +
19887 +int vc_net_add(struct nx_info *nxi, void __user *data)
19888 +{
19889 +       struct vcmd_net_addr_v0 vc_data;
19890 +       int index, ret = 0;
19891 +
19892 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19893 +               return -EFAULT;
19894 +
19895 +       switch (vc_data.type) {
19896 +       case NXA_TYPE_IPV4:
19897 +               if ((vc_data.count < 1) || (vc_data.count > 4))
19898 +                       return -EINVAL;
19899 +
19900 +               index = 0;
19901 +               while (index < vc_data.count) {
19902 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
19903 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
19904 +                       if (ret)
19905 +                               return ret;
19906 +                       index++;
19907 +               }
19908 +               ret = index;
19909 +               break;
19910 +
19911 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
19912 +               nxi->v4_bcast = vc_data.ip[0];
19913 +               ret = 1;
19914 +               break;
19915 +
19916 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
19917 +               nxi->v4_lback = vc_data.ip[0];
19918 +               ret = 1;
19919 +               break;
19920 +
19921 +       default:
19922 +               ret = -EINVAL;
19923 +               break;
19924 +       }
19925 +       return ret;
19926 +}
19927 +
19928 +int vc_net_remove(struct nx_info *nxi, void __user *data)
19929 +{
19930 +       struct vcmd_net_addr_v0 vc_data;
19931 +
19932 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19933 +               return -EFAULT;
19934 +
19935 +       switch (vc_data.type) {
19936 +       case NXA_TYPE_ANY:
19937 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
19938 +       default:
19939 +               return -EINVAL;
19940 +       }
19941 +       return 0;
19942 +}
19943 +
19944 +
19945 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
19946 +{
19947 +       struct vcmd_net_addr_ipv4_v1 vc_data;
19948 +
19949 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19950 +               return -EFAULT;
19951 +
19952 +       switch (vc_data.type) {
19953 +       case NXA_TYPE_ADDR:
19954 +       case NXA_TYPE_MASK:
19955 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
19956 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19957 +
19958 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19959 +               nxi->v4_bcast = vc_data.ip;
19960 +               break;
19961 +
19962 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19963 +               nxi->v4_lback = vc_data.ip;
19964 +               break;
19965 +
19966 +       default:
19967 +               return -EINVAL;
19968 +       }
19969 +       return 0;
19970 +}
19971 +
19972 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
19973 +{
19974 +       struct vcmd_net_addr_ipv4_v2 vc_data;
19975 +
19976 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19977 +               return -EFAULT;
19978 +
19979 +       switch (vc_data.type) {
19980 +       case NXA_TYPE_ADDR:
19981 +       case NXA_TYPE_MASK:
19982 +       case NXA_TYPE_RANGE:
19983 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19984 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19985 +
19986 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19987 +               nxi->v4_bcast = vc_data.ip;
19988 +               break;
19989 +
19990 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19991 +               nxi->v4_lback = vc_data.ip;
19992 +               break;
19993 +
19994 +       default:
19995 +               return -EINVAL;
19996 +       }
19997 +       return 0;
19998 +}
19999 +
20000 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20001 +{
20002 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20003 +
20004 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20005 +               return -EFAULT;
20006 +
20007 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20008 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20009 +}
20010 +
20011 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20012 +{
20013 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20014 +
20015 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20016 +               return -EFAULT;
20017 +
20018 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20019 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20020 +}
20021 +
20022 +#ifdef CONFIG_IPV6
20023 +
20024 +static inline
20025 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20026 +       struct in6_addr *ip, struct in6_addr *mask,
20027 +       uint32_t prefix, uint16_t type, uint16_t flags,
20028 +       struct nx_addr_v6 **prev)
20029 +{
20030 +       struct nx_addr_v6 *nxa = &nxi->v6;
20031 +
20032 +       for (; nxa; nxa = nxa->next) {
20033 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
20034 +                   ipv6_addr_equal(&nxa->mask, mask) &&
20035 +                   (nxa->prefix == prefix) &&
20036 +                   (nxa->type == type) &&
20037 +                   (nxa->flags == flags))
20038 +                   return nxa;
20039 +
20040 +               /* save previous entry */
20041 +               if (prev)
20042 +                       *prev = nxa;
20043 +       }
20044 +       return NULL;
20045 +}
20046 +
20047 +
20048 +int do_add_v6_addr(struct nx_info *nxi,
20049 +       struct in6_addr *ip, struct in6_addr *mask,
20050 +       uint32_t prefix, uint16_t type, uint16_t flags)
20051 +{
20052 +       struct nx_addr_v6 *nxa = NULL;
20053 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20054 +       unsigned long irqflags;
20055 +       int ret = -EEXIST;
20056 +
20057 +       if (IS_ERR(new))
20058 +               return PTR_ERR(new);
20059 +
20060 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20061 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20062 +               goto out_unlock;
20063 +
20064 +       if (NX_IPV6(nxi)) {
20065 +               nxa->next = new;
20066 +               nxa = new;
20067 +               new = NULL;
20068 +       }
20069 +
20070 +       nxa->ip = *ip;
20071 +       nxa->mask = *mask;
20072 +       nxa->prefix = prefix;
20073 +       nxa->type = type;
20074 +       nxa->flags = flags;
20075 +       ret = 0;
20076 +out_unlock:
20077 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20078 +       if (new)
20079 +               __dealloc_nx_addr_v6(new);
20080 +       return ret;
20081 +}
20082 +
20083 +int do_remove_v6_addr(struct nx_info *nxi,
20084 +       struct in6_addr *ip, struct in6_addr *mask,
20085 +       uint32_t prefix, uint16_t type, uint16_t flags)
20086 +{
20087 +       struct nx_addr_v6 *nxa = NULL;
20088 +       struct nx_addr_v6 *old = NULL;
20089 +       unsigned long irqflags;
20090 +       int ret = 0;
20091 +
20092 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20093 +       switch (type) {
20094 +       case NXA_TYPE_ADDR:
20095 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20096 +               if (old) {
20097 +                       if (nxa) {
20098 +                               nxa->next = old->next;
20099 +                               old->next = NULL;
20100 +                       } else {
20101 +                               if (old->next) {
20102 +                                       nxa = old;
20103 +                                       old = old->next;
20104 +                                       *nxa = *old;
20105 +                                       old->next = NULL;
20106 +                               } else {
20107 +                                       memset(old, 0, sizeof(*old));
20108 +                                       old = NULL;
20109 +                               }
20110 +                       }
20111 +               } else
20112 +                       ret = -ESRCH;
20113 +               break;
20114 +
20115 +       case NXA_TYPE_ANY:
20116 +               nxa = &nxi->v6;
20117 +               old = nxa->next;
20118 +               memset(nxa, 0, sizeof(*nxa));
20119 +               break;
20120 +
20121 +       default:
20122 +               ret = -EINVAL;
20123 +       }
20124 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20125 +       __dealloc_nx_addr_v6_all(old);
20126 +       return ret;
20127 +}
20128 +
20129 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20130 +{
20131 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20132 +
20133 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20134 +               return -EFAULT;
20135 +
20136 +       switch (vc_data.type) {
20137 +       case NXA_TYPE_ADDR:
20138 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20139 +               /* fallthrough */
20140 +       case NXA_TYPE_MASK:
20141 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20142 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20143 +       default:
20144 +               return -EINVAL;
20145 +       }
20146 +       return 0;
20147 +}
20148 +
20149 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20150 +{
20151 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20152 +
20153 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20154 +               return -EFAULT;
20155 +
20156 +       switch (vc_data.type) {
20157 +       case NXA_TYPE_ADDR:
20158 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20159 +               /* fallthrough */
20160 +       case NXA_TYPE_MASK:
20161 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20162 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20163 +       case NXA_TYPE_ANY:
20164 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20165 +       default:
20166 +               return -EINVAL;
20167 +       }
20168 +       return 0;
20169 +}
20170 +
20171 +#endif /* CONFIG_IPV6 */
20172 +
20173 +
20174 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20175 +{
20176 +       struct vcmd_net_flags_v0 vc_data;
20177 +
20178 +       vc_data.flagword = nxi->nx_flags;
20179 +
20180 +       /* special STATE flag handling */
20181 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20182 +
20183 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20184 +               return -EFAULT;
20185 +       return 0;
20186 +}
20187 +
20188 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20189 +{
20190 +       struct vcmd_net_flags_v0 vc_data;
20191 +       uint64_t mask, trigger;
20192 +
20193 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20194 +               return -EFAULT;
20195 +
20196 +       /* special STATE flag handling */
20197 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20198 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20199 +
20200 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20201 +               vc_data.flagword, mask);
20202 +       if (trigger & NXF_PERSISTENT)
20203 +               nx_update_persistent(nxi);
20204 +
20205 +       return 0;
20206 +}
20207 +
20208 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20209 +{
20210 +       struct vcmd_net_caps_v0 vc_data;
20211 +
20212 +       vc_data.ncaps = nxi->nx_ncaps;
20213 +       vc_data.cmask = ~0ULL;
20214 +
20215 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20216 +               return -EFAULT;
20217 +       return 0;
20218 +}
20219 +
20220 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20221 +{
20222 +       struct vcmd_net_caps_v0 vc_data;
20223 +
20224 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20225 +               return -EFAULT;
20226 +
20227 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20228 +               vc_data.ncaps, vc_data.cmask);
20229 +       return 0;
20230 +}
20231 +
20232 +
20233 +#include <linux/module.h>
20234 +
20235 +module_init(init_network);
20236 +
20237 +EXPORT_SYMBOL_GPL(free_nx_info);
20238 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20239 +
20240 diff -NurpP --minimal linux-3.13.1/kernel/vserver/proc.c linux-3.13.1-vs2.3.6.10/kernel/vserver/proc.c
20241 --- linux-3.13.1/kernel/vserver/proc.c  1970-01-01 00:00:00.000000000 +0000
20242 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/proc.c       2014-02-01 01:21:49.000000000 +0000
20243 @@ -0,0 +1,1097 @@
20244 +/*
20245 + *  linux/kernel/vserver/proc.c
20246 + *
20247 + *  Virtual Context Support
20248 + *
20249 + *  Copyright (C) 2003-2011  Herbert Pötzl
20250 + *
20251 + *  V0.01  basic structure
20252 + *  V0.02  adaptation vs1.3.0
20253 + *  V0.03  proc permissions
20254 + *  V0.04  locking/generic
20255 + *  V0.05  next generation procfs
20256 + *  V0.06  inode validation
20257 + *  V0.07  generic rewrite vid
20258 + *  V0.08  remove inode type
20259 + *  V0.09  added u/wmask info
20260 + *
20261 + */
20262 +
20263 +#include <linux/proc_fs.h>
20264 +#include <linux/fs_struct.h>
20265 +#include <linux/mount.h>
20266 +#include <linux/namei.h>
20267 +#include <asm/unistd.h>
20268 +
20269 +#include <linux/vs_context.h>
20270 +#include <linux/vs_network.h>
20271 +#include <linux/vs_cvirt.h>
20272 +
20273 +#include <linux/in.h>
20274 +#include <linux/inetdevice.h>
20275 +#include <linux/vs_inet.h>
20276 +#include <linux/vs_inet6.h>
20277 +
20278 +#include <linux/vserver/global.h>
20279 +
20280 +#include "cvirt_proc.h"
20281 +#include "cacct_proc.h"
20282 +#include "limit_proc.h"
20283 +#include "sched_proc.h"
20284 +#include "vci_config.h"
20285 +
20286 +#include <../../fs/proc/internal.h>
20287 +
20288 +
20289 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20290 +{
20291 +       unsigned __capi;
20292 +
20293 +       CAP_FOR_EACH_U32(__capi) {
20294 +               buffer += sprintf(buffer, "%08x",
20295 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20296 +       }
20297 +       return buffer;
20298 +}
20299 +
20300 +
20301 +static struct proc_dir_entry *proc_virtual;
20302 +
20303 +static struct proc_dir_entry *proc_virtnet;
20304 +
20305 +
20306 +/* first the actual feeds */
20307 +
20308 +
20309 +static int proc_vci(char *buffer)
20310 +{
20311 +       return sprintf(buffer,
20312 +               "VCIVersion:\t%04x:%04x\n"
20313 +               "VCISyscall:\t%d\n"
20314 +               "VCIKernel:\t%08x\n",
20315 +               VCI_VERSION >> 16,
20316 +               VCI_VERSION & 0xFFFF,
20317 +               __NR_vserver,
20318 +               vci_kernel_config());
20319 +}
20320 +
20321 +static int proc_virtual_info(char *buffer)
20322 +{
20323 +       return proc_vci(buffer);
20324 +}
20325 +
20326 +static int proc_virtual_status(char *buffer)
20327 +{
20328 +       return sprintf(buffer,
20329 +               "#CTotal:\t%d\n"
20330 +               "#CActive:\t%d\n"
20331 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20332 +               "#InitTask:\t%d\t%d %d\n",
20333 +               atomic_read(&vx_global_ctotal),
20334 +               atomic_read(&vx_global_cactive),
20335 +               atomic_read(&vs_global_nsproxy),
20336 +               atomic_read(&vs_global_fs),
20337 +               atomic_read(&vs_global_mnt_ns),
20338 +               atomic_read(&vs_global_uts_ns),
20339 +               atomic_read(&nr_ipc_ns),
20340 +               atomic_read(&vs_global_user_ns),
20341 +               atomic_read(&vs_global_pid_ns),
20342 +               atomic_read(&init_task.usage),
20343 +               atomic_read(&init_task.nsproxy->count),
20344 +               init_task.fs->users);
20345 +}
20346 +
20347 +
20348 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20349 +{
20350 +       int length;
20351 +
20352 +       length = sprintf(buffer,
20353 +               "ID:\t%d\n"
20354 +               "Info:\t%p\n"
20355 +               "Init:\t%d\n"
20356 +               "OOM:\t%lld\n",
20357 +               vxi->vx_id,
20358 +               vxi,
20359 +               vxi->vx_initpid,
20360 +               vxi->vx_badness_bias);
20361 +       return length;
20362 +}
20363 +
20364 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
20365 +{
20366 +       char *orig = buffer;
20367 +
20368 +       buffer += sprintf(buffer,
20369 +               "UseCnt:\t%d\n"
20370 +               "Tasks:\t%d\n"
20371 +               "Flags:\t%016llx\n",
20372 +               atomic_read(&vxi->vx_usecnt),
20373 +               atomic_read(&vxi->vx_tasks),
20374 +               (unsigned long long)vxi->vx_flags);
20375 +
20376 +       buffer += sprintf(buffer, "BCaps:\t");
20377 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
20378 +       buffer += sprintf(buffer, "\n");
20379 +
20380 +       buffer += sprintf(buffer,
20381 +               "CCaps:\t%016llx\n"
20382 +               "Umask:\t%16llx\n"
20383 +               "Wmask:\t%16llx\n"
20384 +               "Spaces:\t%08lx %08lx\n",
20385 +               (unsigned long long)vxi->vx_ccaps,
20386 +               (unsigned long long)vxi->vx_umask,
20387 +               (unsigned long long)vxi->vx_wmask,
20388 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
20389 +       return buffer - orig;
20390 +}
20391 +
20392 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
20393 +{
20394 +       return vx_info_proc_limit(&vxi->limit, buffer);
20395 +}
20396 +
20397 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
20398 +{
20399 +       int cpu, length;
20400 +
20401 +       length = vx_info_proc_sched(&vxi->sched, buffer);
20402 +       for_each_online_cpu(cpu) {
20403 +               length += vx_info_proc_sched_pc(
20404 +                       &vx_per_cpu(vxi, sched_pc, cpu),
20405 +                       buffer + length, cpu);
20406 +       }
20407 +       return length;
20408 +}
20409 +
20410 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
20411 +{
20412 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
20413 +}
20414 +
20415 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
20416 +{
20417 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
20418 +}
20419 +
20420 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
20421 +{
20422 +       int cpu, length;
20423 +
20424 +       vx_update_load(vxi);
20425 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
20426 +       for_each_online_cpu(cpu) {
20427 +               length += vx_info_proc_cvirt_pc(
20428 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
20429 +                       buffer + length, cpu);
20430 +       }
20431 +       return length;
20432 +}
20433 +
20434 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
20435 +{
20436 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
20437 +}
20438 +
20439 +
20440 +static int proc_virtnet_info(char *buffer)
20441 +{
20442 +       return proc_vci(buffer);
20443 +}
20444 +
20445 +static int proc_virtnet_status(char *buffer)
20446 +{
20447 +       return sprintf(buffer,
20448 +               "#CTotal:\t%d\n"
20449 +               "#CActive:\t%d\n",
20450 +               atomic_read(&nx_global_ctotal),
20451 +               atomic_read(&nx_global_cactive));
20452 +}
20453 +
20454 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
20455 +{
20456 +       struct nx_addr_v4 *v4a;
20457 +#ifdef CONFIG_IPV6
20458 +       struct nx_addr_v6 *v6a;
20459 +#endif
20460 +       int length, i;
20461 +
20462 +       length = sprintf(buffer,
20463 +               "ID:\t%d\n"
20464 +               "Info:\t%p\n"
20465 +               "Bcast:\t" NIPQUAD_FMT "\n"
20466 +               "Lback:\t" NIPQUAD_FMT "\n",
20467 +               nxi->nx_id,
20468 +               nxi,
20469 +               NIPQUAD(nxi->v4_bcast.s_addr),
20470 +               NIPQUAD(nxi->v4_lback.s_addr));
20471 +
20472 +       if (!NX_IPV4(nxi))
20473 +               goto skip_v4;
20474 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20475 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
20476 +                       i, NXAV4(v4a));
20477 +skip_v4:
20478 +#ifdef CONFIG_IPV6
20479 +       if (!NX_IPV6(nxi))
20480 +               goto skip_v6;
20481 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20482 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
20483 +                       i, NXAV6(v6a));
20484 +skip_v6:
20485 +#endif
20486 +       return length;
20487 +}
20488 +
20489 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
20490 +{
20491 +       int length;
20492 +
20493 +       length = sprintf(buffer,
20494 +               "UseCnt:\t%d\n"
20495 +               "Tasks:\t%d\n"
20496 +               "Flags:\t%016llx\n"
20497 +               "NCaps:\t%016llx\n",
20498 +               atomic_read(&nxi->nx_usecnt),
20499 +               atomic_read(&nxi->nx_tasks),
20500 +               (unsigned long long)nxi->nx_flags,
20501 +               (unsigned long long)nxi->nx_ncaps);
20502 +       return length;
20503 +}
20504 +
20505 +
20506 +
20507 +/* here the inode helpers */
20508 +
20509 +struct vs_entry {
20510 +       int len;
20511 +       char *name;
20512 +       mode_t mode;
20513 +       struct inode_operations *iop;
20514 +       struct file_operations *fop;
20515 +       union proc_op op;
20516 +};
20517 +
20518 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
20519 +{
20520 +       struct inode *inode = new_inode(sb);
20521 +
20522 +       if (!inode)
20523 +               goto out;
20524 +
20525 +       inode->i_mode = p->mode;
20526 +       if (p->iop)
20527 +               inode->i_op = p->iop;
20528 +       if (p->fop)
20529 +               inode->i_fop = p->fop;
20530 +
20531 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
20532 +       inode->i_flags |= S_IMMUTABLE;
20533 +
20534 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
20535 +
20536 +       i_uid_write(inode, 0);
20537 +       i_gid_write(inode, 0);
20538 +       i_tag_write(inode, 0);
20539 +out:
20540 +       return inode;
20541 +}
20542 +
20543 +static struct dentry *vs_proc_instantiate(struct inode *dir,
20544 +       struct dentry *dentry, int id, void *ptr)
20545 +{
20546 +       struct vs_entry *p = ptr;
20547 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
20548 +       struct dentry *error = ERR_PTR(-EINVAL);
20549 +
20550 +       if (!inode)
20551 +               goto out;
20552 +
20553 +       PROC_I(inode)->op = p->op;
20554 +       PROC_I(inode)->fd = id;
20555 +       d_add(dentry, inode);
20556 +       error = NULL;
20557 +out:
20558 +       return error;
20559 +}
20560 +
20561 +/* Lookups */
20562 +
20563 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
20564 +
20565 +
20566 +/*
20567 + * Fill a directory entry.
20568 + *
20569 + * If possible create the dcache entry and derive our inode number and
20570 + * file type from dcache entry.
20571 + *
20572 + * Since all of the proc inode numbers are dynamically generated, the inode
20573 + * numbers do not exist until the inode is cache.  This means creating the
20574 + * the dcache entry in iterate is necessary to keep the inode numbers
20575 + * reported by iterate in sync with the inode numbers reported
20576 + * by stat.
20577 + */
20578 +static int vx_proc_fill_cache(struct file *filp, struct dir_context *ctx,
20579 +       char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
20580 +{
20581 +       struct dentry *child, *dir = filp->f_dentry;
20582 +       struct inode *inode;
20583 +       struct qstr qname;
20584 +       ino_t ino = 0;
20585 +       unsigned type = DT_UNKNOWN;
20586 +
20587 +       qname.name = name;
20588 +       qname.len  = len;
20589 +       qname.hash = full_name_hash(name, len);
20590 +
20591 +       child = d_lookup(dir, &qname);
20592 +       if (!child) {
20593 +               struct dentry *new;
20594 +               new = d_alloc(dir, &qname);
20595 +               if (new) {
20596 +                       child = instantiate(dir->d_inode, new, id, ptr);
20597 +                       if (child)
20598 +                               dput(new);
20599 +                       else
20600 +                               child = new;
20601 +               }
20602 +       }
20603 +       if (!child || IS_ERR(child) || !child->d_inode)
20604 +               goto end_instantiate;
20605 +       inode = child->d_inode;
20606 +       if (inode) {
20607 +               ino = inode->i_ino;
20608 +               type = inode->i_mode >> 12;
20609 +       }
20610 +       dput(child);
20611 +end_instantiate:
20612 +       if (!ino)
20613 +               ino = 1;
20614 +       return !dir_emit(ctx, name, len, ino, type);
20615 +}
20616 +
20617 +
20618 +
20619 +/* get and revalidate vx_info/xid */
20620 +
20621 +static inline
20622 +struct vx_info *get_proc_vx_info(struct inode *inode)
20623 +{
20624 +       return lookup_vx_info(PROC_I(inode)->fd);
20625 +}
20626 +
20627 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
20628 +{
20629 +       struct inode *inode = dentry->d_inode;
20630 +       vxid_t xid = PROC_I(inode)->fd;
20631 +
20632 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20633 +               return -ECHILD;
20634 +
20635 +       if (!xid || xid_is_hashed(xid))
20636 +               return 1;
20637 +       d_drop(dentry);
20638 +       return 0;
20639 +}
20640 +
20641 +
20642 +/* get and revalidate nx_info/nid */
20643 +
20644 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
20645 +{
20646 +       struct inode *inode = dentry->d_inode;
20647 +       vnid_t nid = PROC_I(inode)->fd;
20648 +
20649 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20650 +               return -ECHILD;
20651 +
20652 +       if (!nid || nid_is_hashed(nid))
20653 +               return 1;
20654 +       d_drop(dentry);
20655 +       return 0;
20656 +}
20657 +
20658 +
20659 +
20660 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
20661 +
20662 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
20663 +                         size_t count, loff_t *ppos)
20664 +{
20665 +       struct inode *inode = file->f_dentry->d_inode;
20666 +       unsigned long page;
20667 +       ssize_t length = 0;
20668 +
20669 +       if (count > PROC_BLOCK_SIZE)
20670 +               count = PROC_BLOCK_SIZE;
20671 +
20672 +       /* fade that out as soon as stable */
20673 +       WARN_ON(PROC_I(inode)->fd);
20674 +
20675 +       if (!(page = __get_free_page(GFP_KERNEL)))
20676 +               return -ENOMEM;
20677 +
20678 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
20679 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
20680 +
20681 +       if (length >= 0)
20682 +               length = simple_read_from_buffer(buf, count, ppos,
20683 +                       (char *)page, length);
20684 +
20685 +       free_page(page);
20686 +       return length;
20687 +}
20688 +
20689 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
20690 +                         size_t count, loff_t *ppos)
20691 +{
20692 +       struct inode *inode = file->f_dentry->d_inode;
20693 +       struct vx_info *vxi = NULL;
20694 +       vxid_t xid = PROC_I(inode)->fd;
20695 +       unsigned long page;
20696 +       ssize_t length = 0;
20697 +
20698 +       if (count > PROC_BLOCK_SIZE)
20699 +               count = PROC_BLOCK_SIZE;
20700 +
20701 +       /* fade that out as soon as stable */
20702 +       WARN_ON(!xid);
20703 +       vxi = lookup_vx_info(xid);
20704 +       if (!vxi)
20705 +               goto out;
20706 +
20707 +       length = -ENOMEM;
20708 +       if (!(page = __get_free_page(GFP_KERNEL)))
20709 +               goto out_put;
20710 +
20711 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
20712 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
20713 +
20714 +       if (length >= 0)
20715 +               length = simple_read_from_buffer(buf, count, ppos,
20716 +                       (char *)page, length);
20717 +
20718 +       free_page(page);
20719 +out_put:
20720 +       put_vx_info(vxi);
20721 +out:
20722 +       return length;
20723 +}
20724 +
20725 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
20726 +                         size_t count, loff_t *ppos)
20727 +{
20728 +       struct inode *inode = file->f_dentry->d_inode;
20729 +       struct nx_info *nxi = NULL;
20730 +       vnid_t nid = PROC_I(inode)->fd;
20731 +       unsigned long page;
20732 +       ssize_t length = 0;
20733 +
20734 +       if (count > PROC_BLOCK_SIZE)
20735 +               count = PROC_BLOCK_SIZE;
20736 +
20737 +       /* fade that out as soon as stable */
20738 +       WARN_ON(!nid);
20739 +       nxi = lookup_nx_info(nid);
20740 +       if (!nxi)
20741 +               goto out;
20742 +
20743 +       length = -ENOMEM;
20744 +       if (!(page = __get_free_page(GFP_KERNEL)))
20745 +               goto out_put;
20746 +
20747 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
20748 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
20749 +
20750 +       if (length >= 0)
20751 +               length = simple_read_from_buffer(buf, count, ppos,
20752 +                       (char *)page, length);
20753 +
20754 +       free_page(page);
20755 +out_put:
20756 +       put_nx_info(nxi);
20757 +out:
20758 +       return length;
20759 +}
20760 +
20761 +
20762 +
20763 +/* here comes the lower level */
20764 +
20765 +
20766 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
20767 +       .len  = sizeof(NAME) - 1,       \
20768 +       .name = (NAME),                 \
20769 +       .mode = MODE,                   \
20770 +       .iop  = IOP,                    \
20771 +       .fop  = FOP,                    \
20772 +       .op   = OP,                     \
20773 +}
20774 +
20775 +
20776 +#define DIR(NAME, MODE, OTYPE)                         \
20777 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
20778 +               &proc_ ## OTYPE ## _inode_operations,   \
20779 +               &proc_ ## OTYPE ## _file_operations, { } )
20780 +
20781 +#define INF(NAME, MODE, OTYPE)                         \
20782 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20783 +               &proc_vs_info_file_operations,          \
20784 +               { .proc_vs_read = &proc_##OTYPE } )
20785 +
20786 +#define VINF(NAME, MODE, OTYPE)                                \
20787 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20788 +               &proc_vx_info_file_operations,          \
20789 +               { .proc_vxi_read = &proc_##OTYPE } )
20790 +
20791 +#define NINF(NAME, MODE, OTYPE)                                \
20792 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20793 +               &proc_nx_info_file_operations,          \
20794 +               { .proc_nxi_read = &proc_##OTYPE } )
20795 +
20796 +
20797 +static struct file_operations proc_vs_info_file_operations = {
20798 +       .read =         proc_vs_info_read,
20799 +};
20800 +
20801 +static struct file_operations proc_vx_info_file_operations = {
20802 +       .read =         proc_vx_info_read,
20803 +};
20804 +
20805 +static struct dentry_operations proc_xid_dentry_operations = {
20806 +       .d_revalidate = proc_xid_revalidate,
20807 +};
20808 +
20809 +static struct vs_entry vx_base_stuff[] = {
20810 +       VINF("info",    S_IRUGO, vxi_info),
20811 +       VINF("status",  S_IRUGO, vxi_status),
20812 +       VINF("limit",   S_IRUGO, vxi_limit),
20813 +       VINF("sched",   S_IRUGO, vxi_sched),
20814 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
20815 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
20816 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
20817 +       VINF("cacct",   S_IRUGO, vxi_cacct),
20818 +       {}
20819 +};
20820 +
20821 +
20822 +
20823 +
20824 +static struct dentry *proc_xid_instantiate(struct inode *dir,
20825 +       struct dentry *dentry, int id, void *ptr)
20826 +{
20827 +       dentry->d_op = &proc_xid_dentry_operations;
20828 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20829 +}
20830 +
20831 +static struct dentry *proc_xid_lookup(struct inode *dir,
20832 +       struct dentry *dentry, unsigned int flags)
20833 +{
20834 +       struct vs_entry *p = vx_base_stuff;
20835 +       struct dentry *error = ERR_PTR(-ENOENT);
20836 +
20837 +       for (; p->name; p++) {
20838 +               if (p->len != dentry->d_name.len)
20839 +                       continue;
20840 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20841 +                       break;
20842 +       }
20843 +       if (!p->name)
20844 +               goto out;
20845 +
20846 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20847 +out:
20848 +       return error;
20849 +}
20850 +
20851 +static int proc_xid_iterate(struct file *filp, struct dir_context *ctx)
20852 +{
20853 +       struct dentry *dentry = filp->f_dentry;
20854 +       struct inode *inode = dentry->d_inode;
20855 +       struct vs_entry *p = vx_base_stuff;
20856 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
20857 +       int index;
20858 +       u64 ino;
20859 +
20860 +       switch (ctx->pos) {
20861 +       case 0:
20862 +               ino = inode->i_ino;
20863 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20864 +                       goto out;
20865 +               ctx->pos++;
20866 +               /* fall through */
20867 +       case 1:
20868 +               ino = parent_ino(dentry);
20869 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20870 +                       goto out;
20871 +               ctx->pos++;
20872 +               /* fall through */
20873 +       default:
20874 +               index = ctx->pos - 2;
20875 +               if (index >= size)
20876 +                       goto out;
20877 +               for (p += index; p->name; p++) {
20878 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20879 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20880 +                               goto out;
20881 +                       ctx->pos++;
20882 +               }
20883 +       }
20884 +out:
20885 +       return 1;
20886 +}
20887 +
20888 +
20889 +
20890 +static struct file_operations proc_nx_info_file_operations = {
20891 +       .read =         proc_nx_info_read,
20892 +};
20893 +
20894 +static struct dentry_operations proc_nid_dentry_operations = {
20895 +       .d_revalidate = proc_nid_revalidate,
20896 +};
20897 +
20898 +static struct vs_entry nx_base_stuff[] = {
20899 +       NINF("info",    S_IRUGO, nxi_info),
20900 +       NINF("status",  S_IRUGO, nxi_status),
20901 +       {}
20902 +};
20903 +
20904 +
20905 +static struct dentry *proc_nid_instantiate(struct inode *dir,
20906 +       struct dentry *dentry, int id, void *ptr)
20907 +{
20908 +       dentry->d_op = &proc_nid_dentry_operations;
20909 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20910 +}
20911 +
20912 +static struct dentry *proc_nid_lookup(struct inode *dir,
20913 +       struct dentry *dentry, unsigned int flags)
20914 +{
20915 +       struct vs_entry *p = nx_base_stuff;
20916 +       struct dentry *error = ERR_PTR(-ENOENT);
20917 +
20918 +       for (; p->name; p++) {
20919 +               if (p->len != dentry->d_name.len)
20920 +                       continue;
20921 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20922 +                       break;
20923 +       }
20924 +       if (!p->name)
20925 +               goto out;
20926 +
20927 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20928 +out:
20929 +       return error;
20930 +}
20931 +
20932 +static int proc_nid_iterate(struct file *filp, struct dir_context *ctx)
20933 +{
20934 +       struct dentry *dentry = filp->f_dentry;
20935 +       struct inode *inode = dentry->d_inode;
20936 +       struct vs_entry *p = nx_base_stuff;
20937 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
20938 +       int index;
20939 +       u64 ino;
20940 +
20941 +       switch (ctx->pos) {
20942 +       case 0:
20943 +               ino = inode->i_ino;
20944 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20945 +                       goto out;
20946 +               ctx->pos++;
20947 +               /* fall through */
20948 +       case 1:
20949 +               ino = parent_ino(dentry);
20950 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20951 +                       goto out;
20952 +               ctx->pos++;
20953 +               /* fall through */
20954 +       default:
20955 +               index = ctx->pos - 2;
20956 +               if (index >= size)
20957 +                       goto out;
20958 +               for (p += index; p->name; p++) {
20959 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20960 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20961 +                               goto out;
20962 +                       ctx->pos++;
20963 +               }
20964 +       }
20965 +out:
20966 +       return 1;
20967 +}
20968 +
20969 +
20970 +#define MAX_MULBY10    ((~0U - 9) / 10)
20971 +
20972 +static inline int atovid(const char *str, int len)
20973 +{
20974 +       int vid, c;
20975 +
20976 +       vid = 0;
20977 +       while (len-- > 0) {
20978 +               c = *str - '0';
20979 +               str++;
20980 +               if (c > 9)
20981 +                       return -1;
20982 +               if (vid >= MAX_MULBY10)
20983 +                       return -1;
20984 +               vid *= 10;
20985 +               vid += c;
20986 +               if (!vid)
20987 +                       return -1;
20988 +       }
20989 +       return vid;
20990 +}
20991 +
20992 +/* now the upper level (virtual) */
20993 +
20994 +
20995 +static struct file_operations proc_xid_file_operations = {
20996 +       .read =         generic_read_dir,
20997 +       .iterate =      proc_xid_iterate,
20998 +};
20999 +
21000 +static struct inode_operations proc_xid_inode_operations = {
21001 +       .lookup =       proc_xid_lookup,
21002 +};
21003 +
21004 +static struct vs_entry vx_virtual_stuff[] = {
21005 +       INF("info",     S_IRUGO, virtual_info),
21006 +       INF("status",   S_IRUGO, virtual_status),
21007 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21008 +};
21009 +
21010 +
21011 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21012 +       struct dentry *dentry, unsigned int flags)
21013 +{
21014 +       struct vs_entry *p = vx_virtual_stuff;
21015 +       struct dentry *error = ERR_PTR(-ENOENT);
21016 +       int id = 0;
21017 +
21018 +       for (; p->name; p++) {
21019 +               if (p->len != dentry->d_name.len)
21020 +                       continue;
21021 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21022 +                       break;
21023 +       }
21024 +       if (p->name)
21025 +               goto instantiate;
21026 +
21027 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21028 +       if ((id < 0) || !xid_is_hashed(id))
21029 +               goto out;
21030 +
21031 +instantiate:
21032 +       error = proc_xid_instantiate(dir, dentry, id, p);
21033 +out:
21034 +       return error;
21035 +}
21036 +
21037 +static struct file_operations proc_nid_file_operations = {
21038 +       .read =         generic_read_dir,
21039 +       .iterate =      proc_nid_iterate,
21040 +};
21041 +
21042 +static struct inode_operations proc_nid_inode_operations = {
21043 +       .lookup =       proc_nid_lookup,
21044 +};
21045 +
21046 +static struct vs_entry nx_virtnet_stuff[] = {
21047 +       INF("info",     S_IRUGO, virtnet_info),
21048 +       INF("status",   S_IRUGO, virtnet_status),
21049 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21050 +};
21051 +
21052 +
21053 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21054 +       struct dentry *dentry, unsigned int flags)
21055 +{
21056 +       struct vs_entry *p = nx_virtnet_stuff;
21057 +       struct dentry *error = ERR_PTR(-ENOENT);
21058 +       int id = 0;
21059 +
21060 +       for (; p->name; p++) {
21061 +               if (p->len != dentry->d_name.len)
21062 +                       continue;
21063 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21064 +                       break;
21065 +       }
21066 +       if (p->name)
21067 +               goto instantiate;
21068 +
21069 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21070 +       if ((id < 0) || !nid_is_hashed(id))
21071 +               goto out;
21072 +
21073 +instantiate:
21074 +       error = proc_nid_instantiate(dir, dentry, id, p);
21075 +out:
21076 +       return error;
21077 +}
21078 +
21079 +
21080 +#define PROC_MAXVIDS 32
21081 +
21082 +int proc_virtual_iterate(struct file *filp, struct dir_context *ctx)
21083 +{
21084 +       struct dentry *dentry = filp->f_dentry;
21085 +       struct inode *inode = dentry->d_inode;
21086 +       struct vs_entry *p = vx_virtual_stuff;
21087 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21088 +       int index;
21089 +       unsigned int xid_array[PROC_MAXVIDS];
21090 +       char buf[PROC_NUMBUF];
21091 +       unsigned int nr_xids, i;
21092 +       u64 ino;
21093 +
21094 +       switch (ctx->pos) {
21095 +       case 0:
21096 +               ino = inode->i_ino;
21097 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21098 +                       goto out;
21099 +               ctx->pos++;
21100 +               /* fall through */
21101 +       case 1:
21102 +               ino = parent_ino(dentry);
21103 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21104 +                       goto out;
21105 +               ctx->pos++;
21106 +               /* fall through */
21107 +       default:
21108 +               index = ctx->pos - 2;
21109 +               if (index >= size)
21110 +                       goto entries;
21111 +               for (p += index; p->name; p++) {
21112 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21113 +                               vs_proc_instantiate, 0, p))
21114 +                               goto out;
21115 +                       ctx->pos++;
21116 +               }
21117 +       entries:
21118 +               index = ctx->pos - size;
21119 +               p = &vx_virtual_stuff[size - 1];
21120 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21121 +               for (i = 0; i < nr_xids; i++) {
21122 +                       int n, xid = xid_array[i];
21123 +                       unsigned int j = PROC_NUMBUF;
21124 +
21125 +                       n = xid;
21126 +                       do
21127 +                               buf[--j] = '0' + (n % 10);
21128 +                       while (n /= 10);
21129 +
21130 +                       if (vx_proc_fill_cache(filp, ctx,
21131 +                               buf + j, PROC_NUMBUF - j,
21132 +                               vs_proc_instantiate, xid, p))
21133 +                               goto out;
21134 +                       ctx->pos++;
21135 +               }
21136 +       }
21137 +out:
21138 +       return 0;
21139 +}
21140 +
21141 +static int proc_virtual_getattr(struct vfsmount *mnt,
21142 +       struct dentry *dentry, struct kstat *stat)
21143 +{
21144 +       struct inode *inode = dentry->d_inode;
21145 +
21146 +       generic_fillattr(inode, stat);
21147 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21148 +       return 0;
21149 +}
21150 +
21151 +static struct file_operations proc_virtual_dir_operations = {
21152 +       .read =         generic_read_dir,
21153 +       .iterate =      proc_virtual_iterate,
21154 +};
21155 +
21156 +static struct inode_operations proc_virtual_dir_inode_operations = {
21157 +       .getattr =      proc_virtual_getattr,
21158 +       .lookup =       proc_virtual_lookup,
21159 +};
21160 +
21161 +
21162 +
21163 +int proc_virtnet_iterate(struct file *filp, struct dir_context *ctx)
21164 +{
21165 +       struct dentry *dentry = filp->f_dentry;
21166 +       struct inode *inode = dentry->d_inode;
21167 +       struct vs_entry *p = nx_virtnet_stuff;
21168 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21169 +       int index;
21170 +       unsigned int nid_array[PROC_MAXVIDS];
21171 +       char buf[PROC_NUMBUF];
21172 +       unsigned int nr_nids, i;
21173 +       u64 ino;
21174 +
21175 +       switch (ctx->pos) {
21176 +       case 0:
21177 +               ino = inode->i_ino;
21178 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21179 +                       goto out;
21180 +               ctx->pos++;
21181 +               /* fall through */
21182 +       case 1:
21183 +               ino = parent_ino(dentry);
21184 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21185 +                       goto out;
21186 +               ctx->pos++;
21187 +               /* fall through */
21188 +       default:
21189 +               index = ctx->pos - 2;
21190 +               if (index >= size)
21191 +                       goto entries;
21192 +               for (p += index; p->name; p++) {
21193 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21194 +                               vs_proc_instantiate, 0, p))
21195 +                               goto out;
21196 +                       ctx->pos++;
21197 +               }
21198 +       entries:
21199 +               index = ctx->pos - size;
21200 +               p = &nx_virtnet_stuff[size - 1];
21201 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21202 +               for (i = 0; i < nr_nids; i++) {
21203 +                       int n, nid = nid_array[i];
21204 +                       unsigned int j = PROC_NUMBUF;
21205 +
21206 +                       n = nid;
21207 +                       do
21208 +                               buf[--j] = '0' + (n % 10);
21209 +                       while (n /= 10);
21210 +
21211 +                       if (vx_proc_fill_cache(filp, ctx,
21212 +                               buf + j, PROC_NUMBUF - j,
21213 +                               vs_proc_instantiate, nid, p))
21214 +                               goto out;
21215 +                       ctx->pos++;
21216 +               }
21217 +       }
21218 +out:
21219 +       return 0;
21220 +}
21221 +
21222 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21223 +       struct dentry *dentry, struct kstat *stat)
21224 +{
21225 +       struct inode *inode = dentry->d_inode;
21226 +
21227 +       generic_fillattr(inode, stat);
21228 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21229 +       return 0;
21230 +}
21231 +
21232 +static struct file_operations proc_virtnet_dir_operations = {
21233 +       .read =         generic_read_dir,
21234 +       .iterate =      proc_virtnet_iterate,
21235 +};
21236 +
21237 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21238 +       .getattr =      proc_virtnet_getattr,
21239 +       .lookup =       proc_virtnet_lookup,
21240 +};
21241 +
21242 +
21243 +
21244 +void proc_vx_init(void)
21245 +{
21246 +       struct proc_dir_entry *ent;
21247 +
21248 +       ent = proc_mkdir("virtual", 0);
21249 +       if (ent) {
21250 +               ent->proc_fops = &proc_virtual_dir_operations;
21251 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21252 +       }
21253 +       proc_virtual = ent;
21254 +
21255 +       ent = proc_mkdir("virtnet", 0);
21256 +       if (ent) {
21257 +               ent->proc_fops = &proc_virtnet_dir_operations;
21258 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21259 +       }
21260 +       proc_virtnet = ent;
21261 +}
21262 +
21263 +
21264 +
21265 +
21266 +/* per pid info */
21267 +
21268 +
21269 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21270 +{
21271 +       struct vx_info *vxi;
21272 +       char *orig = buffer;
21273 +
21274 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21275 +
21276 +       vxi = task_get_vx_info(p);
21277 +       if (!vxi)
21278 +               goto out;
21279 +
21280 +       buffer += sprintf(buffer, "BCaps:\t");
21281 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21282 +       buffer += sprintf(buffer, "\n");
21283 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21284 +               (unsigned long long)vxi->vx_ccaps);
21285 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21286 +               (unsigned long long)vxi->vx_flags);
21287 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21288 +
21289 +       put_vx_info(vxi);
21290 +out:
21291 +       return buffer - orig;
21292 +}
21293 +
21294 +
21295 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21296 +{
21297 +       struct nx_info *nxi;
21298 +       struct nx_addr_v4 *v4a;
21299 +#ifdef CONFIG_IPV6
21300 +       struct nx_addr_v6 *v6a;
21301 +#endif
21302 +       char *orig = buffer;
21303 +       int i;
21304 +
21305 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21306 +
21307 +       nxi = task_get_nx_info(p);
21308 +       if (!nxi)
21309 +               goto out;
21310 +
21311 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21312 +               (unsigned long long)nxi->nx_ncaps);
21313 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21314 +               (unsigned long long)nxi->nx_flags);
21315 +
21316 +       buffer += sprintf(buffer,
21317 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21318 +               NIPQUAD(nxi->v4_bcast.s_addr));
21319 +       buffer += sprintf (buffer,
21320 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21321 +               NIPQUAD(nxi->v4_lback.s_addr));
21322 +       if (!NX_IPV4(nxi))
21323 +               goto skip_v4;
21324 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21325 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21326 +                       i, NXAV4(v4a));
21327 +skip_v4:
21328 +#ifdef CONFIG_IPV6
21329 +       if (!NX_IPV6(nxi))
21330 +               goto skip_v6;
21331 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21332 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
21333 +                       i, NXAV6(v6a));
21334 +skip_v6:
21335 +#endif
21336 +       put_nx_info(nxi);
21337 +out:
21338 +       return buffer - orig;
21339 +}
21340 +
21341 diff -NurpP --minimal linux-3.13.1/kernel/vserver/sched.c linux-3.13.1-vs2.3.6.10/kernel/vserver/sched.c
21342 --- linux-3.13.1/kernel/vserver/sched.c 1970-01-01 00:00:00.000000000 +0000
21343 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/sched.c      2014-01-31 20:38:04.000000000 +0000
21344 @@ -0,0 +1,83 @@
21345 +/*
21346 + *  linux/kernel/vserver/sched.c
21347 + *
21348 + *  Virtual Server: Scheduler Support
21349 + *
21350 + *  Copyright (C) 2004-2010  Herbert Pötzl
21351 + *
21352 + *  V0.01  adapted Sam Vilains version to 2.6.3
21353 + *  V0.02  removed legacy interface
21354 + *  V0.03  changed vcmds to vxi arg
21355 + *  V0.04  removed older and legacy interfaces
21356 + *  V0.05  removed scheduler code/commands
21357 + *
21358 + */
21359 +
21360 +#include <linux/vs_context.h>
21361 +#include <linux/vs_sched.h>
21362 +#include <linux/cpumask.h>
21363 +#include <linux/vserver/sched_cmd.h>
21364 +
21365 +#include <asm/uaccess.h>
21366 +
21367 +
21368 +void vx_update_sched_param(struct _vx_sched *sched,
21369 +       struct _vx_sched_pc *sched_pc)
21370 +{
21371 +       sched_pc->prio_bias = sched->prio_bias;
21372 +}
21373 +
21374 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
21375 +{
21376 +       int cpu;
21377 +
21378 +       if (data->prio_bias > MAX_PRIO_BIAS)
21379 +               data->prio_bias = MAX_PRIO_BIAS;
21380 +       if (data->prio_bias < MIN_PRIO_BIAS)
21381 +               data->prio_bias = MIN_PRIO_BIAS;
21382 +
21383 +       if (data->cpu_id != ~0) {
21384 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
21385 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
21386 +                       cpu_online_mask);
21387 +       } else
21388 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
21389 +
21390 +       for_each_cpu_mask(cpu, vxi->sched.update)
21391 +               vx_update_sched_param(&vxi->sched,
21392 +                       &vx_per_cpu(vxi, sched_pc, cpu));
21393 +       return 0;
21394 +}
21395 +
21396 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
21397 +{
21398 +       struct vcmd_prio_bias vc_data;
21399 +
21400 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21401 +               return -EFAULT;
21402 +
21403 +       return do_set_prio_bias(vxi, &vc_data);
21404 +}
21405 +
21406 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
21407 +{
21408 +       struct vcmd_prio_bias vc_data;
21409 +       struct _vx_sched_pc *pcd;
21410 +       int cpu;
21411 +
21412 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21413 +               return -EFAULT;
21414 +
21415 +       cpu = vc_data.cpu_id;
21416 +
21417 +       if (!cpu_possible(cpu))
21418 +               return -EINVAL;
21419 +
21420 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
21421 +       vc_data.prio_bias = pcd->prio_bias;
21422 +
21423 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21424 +               return -EFAULT;
21425 +       return 0;
21426 +}
21427 +
21428 diff -NurpP --minimal linux-3.13.1/kernel/vserver/sched_init.h linux-3.13.1-vs2.3.6.10/kernel/vserver/sched_init.h
21429 --- linux-3.13.1/kernel/vserver/sched_init.h    1970-01-01 00:00:00.000000000 +0000
21430 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/sched_init.h 2014-01-31 20:38:04.000000000 +0000
21431 @@ -0,0 +1,27 @@
21432 +
21433 +static inline void vx_info_init_sched(struct _vx_sched *sched)
21434 +{
21435 +       /* scheduling; hard code starting values as constants */
21436 +       sched->prio_bias = 0;
21437 +}
21438 +
21439 +static inline
21440 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21441 +{
21442 +       sched_pc->prio_bias = 0;
21443 +
21444 +       sched_pc->user_ticks = 0;
21445 +       sched_pc->sys_ticks = 0;
21446 +       sched_pc->hold_ticks = 0;
21447 +}
21448 +
21449 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
21450 +{
21451 +       return;
21452 +}
21453 +
21454 +static inline
21455 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21456 +{
21457 +       return;
21458 +}
21459 diff -NurpP --minimal linux-3.13.1/kernel/vserver/sched_proc.h linux-3.13.1-vs2.3.6.10/kernel/vserver/sched_proc.h
21460 --- linux-3.13.1/kernel/vserver/sched_proc.h    1970-01-01 00:00:00.000000000 +0000
21461 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/sched_proc.h 2014-01-31 20:38:04.000000000 +0000
21462 @@ -0,0 +1,32 @@
21463 +#ifndef _VX_SCHED_PROC_H
21464 +#define _VX_SCHED_PROC_H
21465 +
21466 +
21467 +static inline
21468 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
21469 +{
21470 +       int length = 0;
21471 +
21472 +       length += sprintf(buffer,
21473 +               "PrioBias:\t%8d\n",
21474 +               sched->prio_bias);
21475 +       return length;
21476 +}
21477 +
21478 +static inline
21479 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
21480 +       char *buffer, int cpu)
21481 +{
21482 +       int length = 0;
21483 +
21484 +       length += sprintf(buffer + length,
21485 +               "cpu %d: %lld %lld %lld", cpu,
21486 +               (unsigned long long)sched_pc->user_ticks,
21487 +               (unsigned long long)sched_pc->sys_ticks,
21488 +               (unsigned long long)sched_pc->hold_ticks);
21489 +       length += sprintf(buffer + length,
21490 +               " %d\n", sched_pc->prio_bias);
21491 +       return length;
21492 +}
21493 +
21494 +#endif /* _VX_SCHED_PROC_H */
21495 diff -NurpP --minimal linux-3.13.1/kernel/vserver/signal.c linux-3.13.1-vs2.3.6.10/kernel/vserver/signal.c
21496 --- linux-3.13.1/kernel/vserver/signal.c        1970-01-01 00:00:00.000000000 +0000
21497 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/signal.c     2014-01-31 20:38:04.000000000 +0000
21498 @@ -0,0 +1,134 @@
21499 +/*
21500 + *  linux/kernel/vserver/signal.c
21501 + *
21502 + *  Virtual Server: Signal Support
21503 + *
21504 + *  Copyright (C) 2003-2007  Herbert Pötzl
21505 + *
21506 + *  V0.01  broken out from vcontext V0.05
21507 + *  V0.02  changed vcmds to vxi arg
21508 + *  V0.03  adjusted siginfo for kill
21509 + *
21510 + */
21511 +
21512 +#include <asm/uaccess.h>
21513 +
21514 +#include <linux/vs_context.h>
21515 +#include <linux/vs_pid.h>
21516 +#include <linux/vserver/signal_cmd.h>
21517 +
21518 +
21519 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
21520 +{
21521 +       int retval, count = 0;
21522 +       struct task_struct *p;
21523 +       struct siginfo *sip = SEND_SIG_PRIV;
21524 +
21525 +       retval = -ESRCH;
21526 +       vxdprintk(VXD_CBIT(misc, 4),
21527 +               "vx_info_kill(%p[#%d],%d,%d)*",
21528 +               vxi, vxi->vx_id, pid, sig);
21529 +       read_lock(&tasklist_lock);
21530 +       switch (pid) {
21531 +       case  0:
21532 +       case -1:
21533 +               for_each_process(p) {
21534 +                       int err = 0;
21535 +
21536 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
21537 +                               (pid && vxi->vx_initpid == p->pid))
21538 +                               continue;
21539 +
21540 +                       err = group_send_sig_info(sig, sip, p);
21541 +                       ++count;
21542 +                       if (err != -EPERM)
21543 +                               retval = err;
21544 +               }
21545 +               break;
21546 +
21547 +       case 1:
21548 +               if (vxi->vx_initpid) {
21549 +                       pid = vxi->vx_initpid;
21550 +                       /* for now, only SIGINT to private init ... */
21551 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21552 +                               /* ... as long as there are tasks left */
21553 +                               (atomic_read(&vxi->vx_tasks) > 1))
21554 +                               sig = SIGINT;
21555 +               }
21556 +               /* fallthrough */
21557 +       default:
21558 +               rcu_read_lock();
21559 +               p = find_task_by_real_pid(pid);
21560 +               rcu_read_unlock();
21561 +               if (p) {
21562 +                       if (vx_task_xid(p) == vxi->vx_id)
21563 +                               retval = group_send_sig_info(sig, sip, p);
21564 +               }
21565 +               break;
21566 +       }
21567 +       read_unlock(&tasklist_lock);
21568 +       vxdprintk(VXD_CBIT(misc, 4),
21569 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
21570 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
21571 +       return retval;
21572 +}
21573 +
21574 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
21575 +{
21576 +       struct vcmd_ctx_kill_v0 vc_data;
21577 +
21578 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21579 +               return -EFAULT;
21580 +
21581 +       /* special check to allow guest shutdown */
21582 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21583 +               /* forbid killall pid=0 when init is present */
21584 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
21585 +               (vc_data.pid > 1)))
21586 +               return -EACCES;
21587 +
21588 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
21589 +}
21590 +
21591 +
21592 +static int __wait_exit(struct vx_info *vxi)
21593 +{
21594 +       DECLARE_WAITQUEUE(wait, current);
21595 +       int ret = 0;
21596 +
21597 +       add_wait_queue(&vxi->vx_wait, &wait);
21598 +       set_current_state(TASK_INTERRUPTIBLE);
21599 +
21600 +wait:
21601 +       if (vx_info_state(vxi,
21602 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
21603 +               goto out;
21604 +       if (signal_pending(current)) {
21605 +               ret = -ERESTARTSYS;
21606 +               goto out;
21607 +       }
21608 +       schedule();
21609 +       goto wait;
21610 +
21611 +out:
21612 +       set_current_state(TASK_RUNNING);
21613 +       remove_wait_queue(&vxi->vx_wait, &wait);
21614 +       return ret;
21615 +}
21616 +
21617 +
21618 +
21619 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
21620 +{
21621 +       struct vcmd_wait_exit_v0 vc_data;
21622 +       int ret;
21623 +
21624 +       ret = __wait_exit(vxi);
21625 +       vc_data.reboot_cmd = vxi->reboot_cmd;
21626 +       vc_data.exit_code = vxi->exit_code;
21627 +
21628 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21629 +               ret = -EFAULT;
21630 +       return ret;
21631 +}
21632 +
21633 diff -NurpP --minimal linux-3.13.1/kernel/vserver/space.c linux-3.13.1-vs2.3.6.10/kernel/vserver/space.c
21634 --- linux-3.13.1/kernel/vserver/space.c 1970-01-01 00:00:00.000000000 +0000
21635 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/space.c      2014-02-01 12:21:24.000000000 +0000
21636 @@ -0,0 +1,436 @@
21637 +/*
21638 + *  linux/kernel/vserver/space.c
21639 + *
21640 + *  Virtual Server: Context Space Support
21641 + *
21642 + *  Copyright (C) 2003-2010  Herbert Pötzl
21643 + *
21644 + *  V0.01  broken out from context.c 0.07
21645 + *  V0.02  added task locking for namespace
21646 + *  V0.03  broken out vx_enter_namespace
21647 + *  V0.04  added *space support and commands
21648 + *  V0.05  added credential support
21649 + *
21650 + */
21651 +
21652 +#include <linux/utsname.h>
21653 +#include <linux/nsproxy.h>
21654 +#include <linux/err.h>
21655 +#include <linux/fs_struct.h>
21656 +#include <linux/cred.h>
21657 +#include <asm/uaccess.h>
21658 +
21659 +#include <linux/vs_context.h>
21660 +#include <linux/vserver/space.h>
21661 +#include <linux/vserver/space_cmd.h>
21662 +
21663 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
21664 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
21665 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
21666 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
21667 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
21668 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
21669 +
21670 +
21671 +/* namespace functions */
21672 +
21673 +#include <linux/mnt_namespace.h>
21674 +#include <linux/user_namespace.h>
21675 +#include <linux/pid_namespace.h>
21676 +#include <linux/ipc_namespace.h>
21677 +#include <net/net_namespace.h>
21678 +#include "../fs/mount.h"
21679 +
21680 +
21681 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
21682 +       .mask = CLONE_FS |
21683 +               CLONE_NEWNS |
21684 +#ifdef CONFIG_UTS_NS
21685 +               CLONE_NEWUTS |
21686 +#endif
21687 +#ifdef CONFIG_IPC_NS
21688 +               CLONE_NEWIPC |
21689 +#endif
21690 +#ifdef CONFIG_USER_NS
21691 +               CLONE_NEWUSER |
21692 +#endif
21693 +               0
21694 +};
21695 +
21696 +static const struct vcmd_space_mask_v1 space_mask = {
21697 +       .mask = CLONE_FS |
21698 +               CLONE_NEWNS |
21699 +#ifdef CONFIG_UTS_NS
21700 +               CLONE_NEWUTS |
21701 +#endif
21702 +#ifdef CONFIG_IPC_NS
21703 +               CLONE_NEWIPC |
21704 +#endif
21705 +#ifdef CONFIG_USER_NS
21706 +               CLONE_NEWUSER |
21707 +#endif
21708 +#ifdef CONFIG_PID_NS
21709 +               CLONE_NEWPID |
21710 +#endif
21711 +#ifdef CONFIG_NET_NS
21712 +               CLONE_NEWNET |
21713 +#endif
21714 +               0
21715 +};
21716 +
21717 +static const struct vcmd_space_mask_v1 default_space_mask = {
21718 +       .mask = CLONE_FS |
21719 +               CLONE_NEWNS |
21720 +#ifdef CONFIG_UTS_NS
21721 +               CLONE_NEWUTS |
21722 +#endif
21723 +#ifdef CONFIG_IPC_NS
21724 +               CLONE_NEWIPC |
21725 +#endif
21726 +#ifdef CONFIG_USER_NS
21727 +               CLONE_NEWUSER |
21728 +#endif
21729 +#ifdef CONFIG_PID_NS
21730 +//             CLONE_NEWPID |
21731 +#endif
21732 +               0
21733 +};
21734 +
21735 +/*
21736 + *     build a new nsproxy mix
21737 + *      assumes that both proxies are 'const'
21738 + *     does not touch nsproxy refcounts
21739 + *     will hold a reference on the result.
21740 + */
21741 +
21742 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
21743 +       struct nsproxy *new_nsproxy, unsigned long mask)
21744 +{
21745 +       struct mnt_namespace *old_ns;
21746 +       struct uts_namespace *old_uts;
21747 +       struct ipc_namespace *old_ipc;
21748 +#ifdef CONFIG_PID_NS
21749 +       struct pid_namespace *old_pid;
21750 +#endif
21751 +#ifdef CONFIG_NET_NS
21752 +       struct net *old_net;
21753 +#endif
21754 +       struct nsproxy *nsproxy;
21755 +
21756 +       nsproxy = copy_nsproxy(old_nsproxy);
21757 +       if (!nsproxy)
21758 +               goto out;
21759 +
21760 +       if (mask & CLONE_NEWNS) {
21761 +               old_ns = nsproxy->mnt_ns;
21762 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
21763 +               if (nsproxy->mnt_ns)
21764 +                       get_mnt_ns(nsproxy->mnt_ns);
21765 +       } else
21766 +               old_ns = NULL;
21767 +
21768 +       if (mask & CLONE_NEWUTS) {
21769 +               old_uts = nsproxy->uts_ns;
21770 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
21771 +               if (nsproxy->uts_ns)
21772 +                       get_uts_ns(nsproxy->uts_ns);
21773 +       } else
21774 +               old_uts = NULL;
21775 +
21776 +       if (mask & CLONE_NEWIPC) {
21777 +               old_ipc = nsproxy->ipc_ns;
21778 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
21779 +               if (nsproxy->ipc_ns)
21780 +                       get_ipc_ns(nsproxy->ipc_ns);
21781 +       } else
21782 +               old_ipc = NULL;
21783 +
21784 +#ifdef CONFIG_PID_NS
21785 +       if (mask & CLONE_NEWPID) {
21786 +               old_pid = nsproxy->pid_ns_for_children;
21787 +               nsproxy->pid_ns_for_children = new_nsproxy->pid_ns_for_children;
21788 +               if (nsproxy->pid_ns_for_children)
21789 +                       get_pid_ns(nsproxy->pid_ns_for_children);
21790 +       } else
21791 +               old_pid = NULL;
21792 +#endif
21793 +#ifdef CONFIG_NET_NS
21794 +       if (mask & CLONE_NEWNET) {
21795 +               old_net = nsproxy->net_ns;
21796 +               nsproxy->net_ns = new_nsproxy->net_ns;
21797 +               if (nsproxy->net_ns)
21798 +                       get_net(nsproxy->net_ns);
21799 +       } else
21800 +               old_net = NULL;
21801 +#endif
21802 +       if (old_ns)
21803 +               put_mnt_ns(old_ns);
21804 +       if (old_uts)
21805 +               put_uts_ns(old_uts);
21806 +       if (old_ipc)
21807 +               put_ipc_ns(old_ipc);
21808 +#ifdef CONFIG_PID_NS
21809 +       if (old_pid)
21810 +               put_pid_ns(old_pid);
21811 +#endif
21812 +#ifdef CONFIG_NET_NS
21813 +       if (old_net)
21814 +               put_net(old_net);
21815 +#endif
21816 +out:
21817 +       return nsproxy;
21818 +}
21819 +
21820 +
21821 +/*
21822 + *     merge two nsproxy structs into a new one.
21823 + *     will hold a reference on the result.
21824 + */
21825 +
21826 +static inline
21827 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
21828 +       struct nsproxy *proxy, unsigned long mask)
21829 +{
21830 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
21831 +
21832 +       if (!proxy)
21833 +               return NULL;
21834 +
21835 +       if (mask) {
21836 +               /* vs_mix_nsproxy returns with reference */
21837 +               return vs_mix_nsproxy(old ? old : &null_proxy,
21838 +                       proxy, mask);
21839 +       }
21840 +       get_nsproxy(proxy);
21841 +       return proxy;
21842 +}
21843 +
21844 +
21845 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21846 +{
21847 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
21848 +       struct fs_struct *fs_cur, *fs = NULL;
21849 +       struct _vx_space *space;
21850 +       int ret, kill = 0;
21851 +
21852 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
21853 +               vxi, vxi->vx_id, mask, index);
21854 +
21855 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
21856 +               return -EACCES;
21857 +
21858 +       if (index >= VX_SPACES)
21859 +               return -EINVAL;
21860 +
21861 +       space = &vxi->space[index];
21862 +
21863 +       if (!mask)
21864 +               mask = space->vx_nsmask;
21865 +
21866 +       if ((mask & space->vx_nsmask) != mask)
21867 +               return -EINVAL;
21868 +
21869 +       if (mask & CLONE_FS) {
21870 +               fs = copy_fs_struct(space->vx_fs);
21871 +               if (!fs)
21872 +                       return -ENOMEM;
21873 +       }
21874 +       proxy = space->vx_nsproxy;
21875 +
21876 +       vxdprintk(VXD_CBIT(space, 9),
21877 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
21878 +               vxi, vxi->vx_id, mask, index, proxy, fs);
21879 +
21880 +       task_lock(current);
21881 +       fs_cur = current->fs;
21882 +
21883 +       if (mask & CLONE_FS) {
21884 +               spin_lock(&fs_cur->lock);
21885 +               current->fs = fs;
21886 +               kill = !--fs_cur->users;
21887 +               spin_unlock(&fs_cur->lock);
21888 +       }
21889 +
21890 +       proxy_cur = current->nsproxy;
21891 +       get_nsproxy(proxy_cur);
21892 +       task_unlock(current);
21893 +
21894 +       if (kill)
21895 +               free_fs_struct(fs_cur);
21896 +
21897 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
21898 +       if (IS_ERR(proxy_new)) {
21899 +               ret = PTR_ERR(proxy_new);
21900 +               goto out_put;
21901 +       }
21902 +
21903 +       proxy_new = xchg(&current->nsproxy, proxy_new);
21904 +
21905 +       if (mask & CLONE_NEWUSER) {
21906 +               struct cred *cred;
21907 +
21908 +               vxdprintk(VXD_CBIT(space, 10),
21909 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
21910 +                       vxi, vxi->vx_id, space->vx_cred,
21911 +                       current->real_cred, current->cred);
21912 +
21913 +               if (space->vx_cred) {
21914 +                       cred = __prepare_creds(space->vx_cred);
21915 +                       if (cred)
21916 +                               commit_creds(cred);
21917 +               }
21918 +       }
21919 +
21920 +       ret = 0;
21921 +
21922 +       if (proxy_new)
21923 +               put_nsproxy(proxy_new);
21924 +out_put:
21925 +       if (proxy_cur)
21926 +               put_nsproxy(proxy_cur);
21927 +       return ret;
21928 +}
21929 +
21930 +
21931 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21932 +{
21933 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
21934 +       struct fs_struct *fs_vxi, *fs = NULL;
21935 +       struct _vx_space *space;
21936 +       int ret, kill = 0;
21937 +
21938 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
21939 +               vxi, vxi->vx_id, mask, index);
21940 +
21941 +       if ((mask & space_mask.mask) != mask)
21942 +               return -EINVAL;
21943 +
21944 +       if (index >= VX_SPACES)
21945 +               return -EINVAL;
21946 +
21947 +       space = &vxi->space[index];
21948 +
21949 +       proxy_vxi = space->vx_nsproxy;
21950 +       fs_vxi = space->vx_fs;
21951 +
21952 +       if (mask & CLONE_FS) {
21953 +               fs = copy_fs_struct(current->fs);
21954 +               if (!fs)
21955 +                       return -ENOMEM;
21956 +       }
21957 +
21958 +       task_lock(current);
21959 +
21960 +       if (mask & CLONE_FS) {
21961 +               spin_lock(&fs_vxi->lock);
21962 +               space->vx_fs = fs;
21963 +               kill = !--fs_vxi->users;
21964 +               spin_unlock(&fs_vxi->lock);
21965 +       }
21966 +
21967 +       proxy_cur = current->nsproxy;
21968 +       get_nsproxy(proxy_cur);
21969 +       task_unlock(current);
21970 +
21971 +       if (kill)
21972 +               free_fs_struct(fs_vxi);
21973 +
21974 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
21975 +       if (IS_ERR(proxy_new)) {
21976 +               ret = PTR_ERR(proxy_new);
21977 +               goto out_put;
21978 +       }
21979 +
21980 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
21981 +       space->vx_nsmask |= mask;
21982 +
21983 +       if (mask & CLONE_NEWUSER) {
21984 +               struct cred *cred;
21985 +
21986 +               vxdprintk(VXD_CBIT(space, 10),
21987 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
21988 +                       vxi, vxi->vx_id, space->vx_cred,
21989 +                       current->real_cred, current->cred);
21990 +
21991 +               cred = prepare_creds();
21992 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
21993 +               if (cred)
21994 +                       abort_creds(cred);
21995 +       }
21996 +
21997 +       ret = 0;
21998 +
21999 +       if (proxy_new)
22000 +               put_nsproxy(proxy_new);
22001 +out_put:
22002 +       if (proxy_cur)
22003 +               put_nsproxy(proxy_cur);
22004 +       return ret;
22005 +}
22006 +
22007 +
22008 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22009 +{
22010 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22011 +
22012 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22013 +               return -EFAULT;
22014 +
22015 +       return vx_enter_space(vxi, vc_data.mask, 0);
22016 +}
22017 +
22018 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22019 +{
22020 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22021 +
22022 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22023 +               return -EFAULT;
22024 +
22025 +       if (vc_data.index >= VX_SPACES)
22026 +               return -EINVAL;
22027 +
22028 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22029 +}
22030 +
22031 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22032 +{
22033 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22034 +
22035 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22036 +               return -EFAULT;
22037 +
22038 +       return vx_set_space(vxi, vc_data.mask, 0);
22039 +}
22040 +
22041 +int vc_set_space(struct vx_info *vxi, void __user *data)
22042 +{
22043 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22044 +
22045 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22046 +               return -EFAULT;
22047 +
22048 +       if (vc_data.index >= VX_SPACES)
22049 +               return -EINVAL;
22050 +
22051 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22052 +}
22053 +
22054 +int vc_get_space_mask(void __user *data, int type)
22055 +{
22056 +       const struct vcmd_space_mask_v1 *mask;
22057 +
22058 +       if (type == 0)
22059 +               mask = &space_mask_v0;
22060 +       else if (type == 1)
22061 +               mask = &space_mask;
22062 +       else
22063 +               mask = &default_space_mask;
22064 +
22065 +       vxdprintk(VXD_CBIT(space, 10),
22066 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22067 +
22068 +       if (copy_to_user(data, mask, sizeof(*mask)))
22069 +               return -EFAULT;
22070 +       return 0;
22071 +}
22072 +
22073 diff -NurpP --minimal linux-3.13.1/kernel/vserver/switch.c linux-3.13.1-vs2.3.6.10/kernel/vserver/switch.c
22074 --- linux-3.13.1/kernel/vserver/switch.c        1970-01-01 00:00:00.000000000 +0000
22075 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/switch.c     2014-01-31 20:38:04.000000000 +0000
22076 @@ -0,0 +1,556 @@
22077 +/*
22078 + *  linux/kernel/vserver/switch.c
22079 + *
22080 + *  Virtual Server: Syscall Switch
22081 + *
22082 + *  Copyright (C) 2003-2011  Herbert Pötzl
22083 + *
22084 + *  V0.01  syscall switch
22085 + *  V0.02  added signal to context
22086 + *  V0.03  added rlimit functions
22087 + *  V0.04  added iattr, task/xid functions
22088 + *  V0.05  added debug/history stuff
22089 + *  V0.06  added compat32 layer
22090 + *  V0.07  vcmd args and perms
22091 + *  V0.08  added status commands
22092 + *  V0.09  added tag commands
22093 + *  V0.10  added oom bias
22094 + *  V0.11  added device commands
22095 + *  V0.12  added warn mask
22096 + *
22097 + */
22098 +
22099 +#include <linux/vs_context.h>
22100 +#include <linux/vs_network.h>
22101 +#include <linux/vserver/switch.h>
22102 +
22103 +#include "vci_config.h"
22104 +
22105 +
22106 +static inline
22107 +int vc_get_version(uint32_t id)
22108 +{
22109 +       return VCI_VERSION;
22110 +}
22111 +
22112 +static inline
22113 +int vc_get_vci(uint32_t id)
22114 +{
22115 +       return vci_kernel_config();
22116 +}
22117 +
22118 +#include <linux/vserver/context_cmd.h>
22119 +#include <linux/vserver/cvirt_cmd.h>
22120 +#include <linux/vserver/cacct_cmd.h>
22121 +#include <linux/vserver/limit_cmd.h>
22122 +#include <linux/vserver/network_cmd.h>
22123 +#include <linux/vserver/sched_cmd.h>
22124 +#include <linux/vserver/debug_cmd.h>
22125 +#include <linux/vserver/inode_cmd.h>
22126 +#include <linux/vserver/dlimit_cmd.h>
22127 +#include <linux/vserver/signal_cmd.h>
22128 +#include <linux/vserver/space_cmd.h>
22129 +#include <linux/vserver/tag_cmd.h>
22130 +#include <linux/vserver/device_cmd.h>
22131 +
22132 +#include <linux/vserver/inode.h>
22133 +#include <linux/vserver/dlimit.h>
22134 +
22135 +
22136 +#ifdef CONFIG_COMPAT
22137 +#define __COMPAT(name, id, data, compat)       \
22138 +       (compat) ? name ## _x32(id, data) : name(id, data)
22139 +#define __COMPAT_NO_ID(name, data, compat)     \
22140 +       (compat) ? name ## _x32(data) : name(data)
22141 +#else
22142 +#define __COMPAT(name, id, data, compat)       \
22143 +       name(id, data)
22144 +#define __COMPAT_NO_ID(name, data, compat)     \
22145 +       name(data)
22146 +#endif
22147 +
22148 +
22149 +static inline
22150 +long do_vcmd(uint32_t cmd, uint32_t id,
22151 +       struct vx_info *vxi, struct nx_info *nxi,
22152 +       void __user *data, int compat)
22153 +{
22154 +       switch (cmd) {
22155 +
22156 +       case VCMD_get_version:
22157 +               return vc_get_version(id);
22158 +       case VCMD_get_vci:
22159 +               return vc_get_vci(id);
22160 +
22161 +       case VCMD_task_xid:
22162 +               return vc_task_xid(id);
22163 +       case VCMD_vx_info:
22164 +               return vc_vx_info(vxi, data);
22165 +
22166 +       case VCMD_task_nid:
22167 +               return vc_task_nid(id);
22168 +       case VCMD_nx_info:
22169 +               return vc_nx_info(nxi, data);
22170 +
22171 +       case VCMD_task_tag:
22172 +               return vc_task_tag(id);
22173 +
22174 +       case VCMD_set_space_v1:
22175 +               return vc_set_space_v1(vxi, data);
22176 +       /* this is version 2 */
22177 +       case VCMD_set_space:
22178 +               return vc_set_space(vxi, data);
22179 +
22180 +       case VCMD_get_space_mask_v0:
22181 +               return vc_get_space_mask(data, 0);
22182 +       /* this is version 1 */
22183 +       case VCMD_get_space_mask:
22184 +               return vc_get_space_mask(data, 1);
22185 +
22186 +       case VCMD_get_space_default:
22187 +               return vc_get_space_mask(data, -1);
22188 +
22189 +       case VCMD_set_umask:
22190 +               return vc_set_umask(vxi, data);
22191 +
22192 +       case VCMD_get_umask:
22193 +               return vc_get_umask(vxi, data);
22194 +
22195 +       case VCMD_set_wmask:
22196 +               return vc_set_wmask(vxi, data);
22197 +
22198 +       case VCMD_get_wmask:
22199 +               return vc_get_wmask(vxi, data);
22200 +#ifdef CONFIG_IA32_EMULATION
22201 +       case VCMD_get_rlimit:
22202 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22203 +       case VCMD_set_rlimit:
22204 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22205 +#else
22206 +       case VCMD_get_rlimit:
22207 +               return vc_get_rlimit(vxi, data);
22208 +       case VCMD_set_rlimit:
22209 +               return vc_set_rlimit(vxi, data);
22210 +#endif
22211 +       case VCMD_get_rlimit_mask:
22212 +               return vc_get_rlimit_mask(id, data);
22213 +       case VCMD_reset_hits:
22214 +               return vc_reset_hits(vxi, data);
22215 +       case VCMD_reset_minmax:
22216 +               return vc_reset_minmax(vxi, data);
22217 +
22218 +       case VCMD_get_vhi_name:
22219 +               return vc_get_vhi_name(vxi, data);
22220 +       case VCMD_set_vhi_name:
22221 +               return vc_set_vhi_name(vxi, data);
22222 +
22223 +       case VCMD_ctx_stat:
22224 +               return vc_ctx_stat(vxi, data);
22225 +       case VCMD_virt_stat:
22226 +               return vc_virt_stat(vxi, data);
22227 +       case VCMD_sock_stat:
22228 +               return vc_sock_stat(vxi, data);
22229 +       case VCMD_rlimit_stat:
22230 +               return vc_rlimit_stat(vxi, data);
22231 +
22232 +       case VCMD_set_cflags:
22233 +               return vc_set_cflags(vxi, data);
22234 +       case VCMD_get_cflags:
22235 +               return vc_get_cflags(vxi, data);
22236 +
22237 +       /* this is version 1 */
22238 +       case VCMD_set_ccaps:
22239 +               return vc_set_ccaps(vxi, data);
22240 +       /* this is version 1 */
22241 +       case VCMD_get_ccaps:
22242 +               return vc_get_ccaps(vxi, data);
22243 +       case VCMD_set_bcaps:
22244 +               return vc_set_bcaps(vxi, data);
22245 +       case VCMD_get_bcaps:
22246 +               return vc_get_bcaps(vxi, data);
22247 +
22248 +       case VCMD_set_badness:
22249 +               return vc_set_badness(vxi, data);
22250 +       case VCMD_get_badness:
22251 +               return vc_get_badness(vxi, data);
22252 +
22253 +       case VCMD_set_nflags:
22254 +               return vc_set_nflags(nxi, data);
22255 +       case VCMD_get_nflags:
22256 +               return vc_get_nflags(nxi, data);
22257 +
22258 +       case VCMD_set_ncaps:
22259 +               return vc_set_ncaps(nxi, data);
22260 +       case VCMD_get_ncaps:
22261 +               return vc_get_ncaps(nxi, data);
22262 +
22263 +       case VCMD_set_prio_bias:
22264 +               return vc_set_prio_bias(vxi, data);
22265 +       case VCMD_get_prio_bias:
22266 +               return vc_get_prio_bias(vxi, data);
22267 +       case VCMD_add_dlimit:
22268 +               return __COMPAT(vc_add_dlimit, id, data, compat);
22269 +       case VCMD_rem_dlimit:
22270 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
22271 +       case VCMD_set_dlimit:
22272 +               return __COMPAT(vc_set_dlimit, id, data, compat);
22273 +       case VCMD_get_dlimit:
22274 +               return __COMPAT(vc_get_dlimit, id, data, compat);
22275 +
22276 +       case VCMD_ctx_kill:
22277 +               return vc_ctx_kill(vxi, data);
22278 +
22279 +       case VCMD_wait_exit:
22280 +               return vc_wait_exit(vxi, data);
22281 +
22282 +       case VCMD_get_iattr:
22283 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22284 +       case VCMD_set_iattr:
22285 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22286 +
22287 +       case VCMD_fget_iattr:
22288 +               return vc_fget_iattr(id, data);
22289 +       case VCMD_fset_iattr:
22290 +               return vc_fset_iattr(id, data);
22291 +
22292 +       case VCMD_enter_space_v0:
22293 +               return vc_enter_space_v1(vxi, NULL);
22294 +       case VCMD_enter_space_v1:
22295 +               return vc_enter_space_v1(vxi, data);
22296 +       /* this is version 2 */
22297 +       case VCMD_enter_space:
22298 +               return vc_enter_space(vxi, data);
22299 +
22300 +       case VCMD_ctx_create_v0:
22301 +               return vc_ctx_create(id, NULL);
22302 +       case VCMD_ctx_create:
22303 +               return vc_ctx_create(id, data);
22304 +       case VCMD_ctx_migrate_v0:
22305 +               return vc_ctx_migrate(vxi, NULL);
22306 +       case VCMD_ctx_migrate:
22307 +               return vc_ctx_migrate(vxi, data);
22308 +
22309 +       case VCMD_net_create_v0:
22310 +               return vc_net_create(id, NULL);
22311 +       case VCMD_net_create:
22312 +               return vc_net_create(id, data);
22313 +       case VCMD_net_migrate:
22314 +               return vc_net_migrate(nxi, data);
22315 +
22316 +       case VCMD_tag_migrate:
22317 +               return vc_tag_migrate(id);
22318 +
22319 +       case VCMD_net_add:
22320 +               return vc_net_add(nxi, data);
22321 +       case VCMD_net_remove:
22322 +               return vc_net_remove(nxi, data);
22323 +
22324 +       case VCMD_net_add_ipv4_v1:
22325 +               return vc_net_add_ipv4_v1(nxi, data);
22326 +       /* this is version 2 */
22327 +       case VCMD_net_add_ipv4:
22328 +               return vc_net_add_ipv4(nxi, data);
22329 +
22330 +       case VCMD_net_rem_ipv4_v1:
22331 +               return vc_net_rem_ipv4_v1(nxi, data);
22332 +       /* this is version 2 */
22333 +       case VCMD_net_rem_ipv4:
22334 +               return vc_net_rem_ipv4(nxi, data);
22335 +#ifdef CONFIG_IPV6
22336 +       case VCMD_net_add_ipv6:
22337 +               return vc_net_add_ipv6(nxi, data);
22338 +       case VCMD_net_remove_ipv6:
22339 +               return vc_net_remove_ipv6(nxi, data);
22340 +#endif
22341 +/*     case VCMD_add_match_ipv4:
22342 +               return vc_add_match_ipv4(nxi, data);
22343 +       case VCMD_get_match_ipv4:
22344 +               return vc_get_match_ipv4(nxi, data);
22345 +#ifdef CONFIG_IPV6
22346 +       case VCMD_add_match_ipv6:
22347 +               return vc_add_match_ipv6(nxi, data);
22348 +       case VCMD_get_match_ipv6:
22349 +               return vc_get_match_ipv6(nxi, data);
22350 +#endif */
22351 +
22352 +#ifdef CONFIG_VSERVER_DEVICE
22353 +       case VCMD_set_mapping:
22354 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
22355 +       case VCMD_unset_mapping:
22356 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
22357 +#endif
22358 +#ifdef CONFIG_VSERVER_HISTORY
22359 +       case VCMD_dump_history:
22360 +               return vc_dump_history(id);
22361 +       case VCMD_read_history:
22362 +               return __COMPAT(vc_read_history, id, data, compat);
22363 +#endif
22364 +       default:
22365 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
22366 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
22367 +       }
22368 +       return -ENOSYS;
22369 +}
22370 +
22371 +
22372 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
22373 +       case VCMD_ ## vcmd: perm = _perm;               \
22374 +               args = _args; flags = _flags; break
22375 +
22376 +
22377 +#define VCA_NONE       0x00
22378 +#define VCA_VXI                0x01
22379 +#define VCA_NXI                0x02
22380 +
22381 +#define VCF_NONE       0x00
22382 +#define VCF_INFO       0x01
22383 +#define VCF_ADMIN      0x02
22384 +#define VCF_ARES       0x06    /* includes admin */
22385 +#define VCF_SETUP      0x08
22386 +
22387 +#define VCF_ZIDOK      0x10    /* zero id okay */
22388 +
22389 +
22390 +static inline
22391 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
22392 +{
22393 +       long ret;
22394 +       int permit = -1, state = 0;
22395 +       int perm = -1, args = 0, flags = 0;
22396 +       struct vx_info *vxi = NULL;
22397 +       struct nx_info *nxi = NULL;
22398 +
22399 +       switch (cmd) {
22400 +       /* unpriviledged commands */
22401 +       __VCMD(get_version,      0, VCA_NONE,   0);
22402 +       __VCMD(get_vci,          0, VCA_NONE,   0);
22403 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
22404 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
22405 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
22406 +       __VCMD(get_space_default,0, VCA_NONE,   0);
22407 +
22408 +       /* info commands */
22409 +       __VCMD(task_xid,         2, VCA_NONE,   0);
22410 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
22411 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
22412 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
22413 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
22414 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
22415 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
22416 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
22417 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
22418 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
22419 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
22420 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
22421 +
22422 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
22423 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
22424 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
22425 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
22426 +
22427 +       __VCMD(task_nid,         2, VCA_NONE,   0);
22428 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
22429 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
22430 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
22431 +
22432 +       __VCMD(task_tag,         2, VCA_NONE,   0);
22433 +
22434 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
22435 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
22436 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
22437 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
22438 +
22439 +       /* lower admin commands */
22440 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
22441 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
22442 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
22443 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
22444 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
22445 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
22446 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
22447 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
22448 +
22449 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
22450 +       __VCMD(net_create,       5, VCA_NONE,   0);
22451 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
22452 +
22453 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
22454 +
22455 +       /* higher admin commands */
22456 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
22457 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22458 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22459 +
22460 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22461 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22462 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22463 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22464 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22465 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22466 +
22467 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22468 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22469 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22470 +
22471 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22472 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22473 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22474 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22475 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22476 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22477 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22478 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22479 +#ifdef CONFIG_IPV6
22480 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22481 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22482 +#endif
22483 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
22484 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
22485 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
22486 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
22487 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
22488 +
22489 +#ifdef CONFIG_VSERVER_DEVICE
22490 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22491 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22492 +#endif
22493 +       /* debug level admin commands */
22494 +#ifdef CONFIG_VSERVER_HISTORY
22495 +       __VCMD(dump_history,     9, VCA_NONE,   0);
22496 +       __VCMD(read_history,     9, VCA_NONE,   0);
22497 +#endif
22498 +
22499 +       default:
22500 +               perm = -1;
22501 +       }
22502 +
22503 +       vxdprintk(VXD_CBIT(switch, 0),
22504 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
22505 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22506 +               VC_VERSION(cmd), id, data, compat,
22507 +               perm, args, flags);
22508 +
22509 +       ret = -ENOSYS;
22510 +       if (perm < 0)
22511 +               goto out;
22512 +
22513 +       state = 1;
22514 +       if (!capable(CAP_CONTEXT))
22515 +               goto out;
22516 +
22517 +       state = 2;
22518 +       /* moved here from the individual commands */
22519 +       ret = -EPERM;
22520 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
22521 +               goto out;
22522 +
22523 +       state = 3;
22524 +       /* vcmd involves resource management  */
22525 +       ret = -EPERM;
22526 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
22527 +               goto out;
22528 +
22529 +       state = 4;
22530 +       /* various legacy exceptions */
22531 +       switch (cmd) {
22532 +       /* will go away when spectator is a cap */
22533 +       case VCMD_ctx_migrate_v0:
22534 +       case VCMD_ctx_migrate:
22535 +               if (id == 1) {
22536 +                       current->xid = 1;
22537 +                       ret = 1;
22538 +                       goto out;
22539 +               }
22540 +               break;
22541 +
22542 +       /* will go away when spectator is a cap */
22543 +       case VCMD_net_migrate:
22544 +               if (id == 1) {
22545 +                       current->nid = 1;
22546 +                       ret = 1;
22547 +                       goto out;
22548 +               }
22549 +               break;
22550 +       }
22551 +
22552 +       /* vcmds are fine by default */
22553 +       permit = 1;
22554 +
22555 +       /* admin type vcmds require admin ... */
22556 +       if (flags & VCF_ADMIN)
22557 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
22558 +
22559 +       /* ... but setup type vcmds override that */
22560 +       if (!permit && (flags & VCF_SETUP))
22561 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
22562 +
22563 +       state = 5;
22564 +       ret = -EPERM;
22565 +       if (!permit)
22566 +               goto out;
22567 +
22568 +       state = 6;
22569 +       if (!id && (flags & VCF_ZIDOK))
22570 +               goto skip_id;
22571 +
22572 +       ret = -ESRCH;
22573 +       if (args & VCA_VXI) {
22574 +               vxi = lookup_vx_info(id);
22575 +               if (!vxi)
22576 +                       goto out;
22577 +
22578 +               if ((flags & VCF_ADMIN) &&
22579 +                       /* special case kill for shutdown */
22580 +                       (cmd != VCMD_ctx_kill) &&
22581 +                       /* can context be administrated? */
22582 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
22583 +                       ret = -EACCES;
22584 +                       goto out_vxi;
22585 +               }
22586 +       }
22587 +       state = 7;
22588 +       if (args & VCA_NXI) {
22589 +               nxi = lookup_nx_info(id);
22590 +               if (!nxi)
22591 +                       goto out_vxi;
22592 +
22593 +               if ((flags & VCF_ADMIN) &&
22594 +                       /* can context be administrated? */
22595 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
22596 +                       ret = -EACCES;
22597 +                       goto out_nxi;
22598 +               }
22599 +       }
22600 +skip_id:
22601 +       state = 8;
22602 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
22603 +
22604 +out_nxi:
22605 +       if ((args & VCA_NXI) && nxi)
22606 +               put_nx_info(nxi);
22607 +out_vxi:
22608 +       if ((args & VCA_VXI) && vxi)
22609 +               put_vx_info(vxi);
22610 +out:
22611 +       vxdprintk(VXD_CBIT(switch, 1),
22612 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
22613 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22614 +               VC_VERSION(cmd), ret, ret, state, permit);
22615 +       return ret;
22616 +}
22617 +
22618 +asmlinkage long
22619 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
22620 +{
22621 +       return do_vserver(cmd, id, data, 0);
22622 +}
22623 +
22624 +#ifdef CONFIG_COMPAT
22625 +
22626 +asmlinkage long
22627 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
22628 +{
22629 +       return do_vserver(cmd, id, data, 1);
22630 +}
22631 +
22632 +#endif /* CONFIG_COMPAT */
22633 diff -NurpP --minimal linux-3.13.1/kernel/vserver/sysctl.c linux-3.13.1-vs2.3.6.10/kernel/vserver/sysctl.c
22634 --- linux-3.13.1/kernel/vserver/sysctl.c        1970-01-01 00:00:00.000000000 +0000
22635 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/sysctl.c     2014-01-31 20:38:04.000000000 +0000
22636 @@ -0,0 +1,247 @@
22637 +/*
22638 + *  kernel/vserver/sysctl.c
22639 + *
22640 + *  Virtual Context Support
22641 + *
22642 + *  Copyright (C) 2004-2007  Herbert Pötzl
22643 + *
22644 + *  V0.01  basic structure
22645 + *
22646 + */
22647 +
22648 +#include <linux/module.h>
22649 +#include <linux/ctype.h>
22650 +#include <linux/sysctl.h>
22651 +#include <linux/parser.h>
22652 +#include <asm/uaccess.h>
22653 +
22654 +enum {
22655 +       CTL_DEBUG_ERROR         = 0,
22656 +       CTL_DEBUG_SWITCH        = 1,
22657 +       CTL_DEBUG_XID,
22658 +       CTL_DEBUG_NID,
22659 +       CTL_DEBUG_TAG,
22660 +       CTL_DEBUG_NET,
22661 +       CTL_DEBUG_LIMIT,
22662 +       CTL_DEBUG_CRES,
22663 +       CTL_DEBUG_DLIM,
22664 +       CTL_DEBUG_QUOTA,
22665 +       CTL_DEBUG_CVIRT,
22666 +       CTL_DEBUG_SPACE,
22667 +       CTL_DEBUG_PERM,
22668 +       CTL_DEBUG_MISC,
22669 +};
22670 +
22671 +
22672 +unsigned int vs_debug_switch   = 0;
22673 +unsigned int vs_debug_xid      = 0;
22674 +unsigned int vs_debug_nid      = 0;
22675 +unsigned int vs_debug_tag      = 0;
22676 +unsigned int vs_debug_net      = 0;
22677 +unsigned int vs_debug_limit    = 0;
22678 +unsigned int vs_debug_cres     = 0;
22679 +unsigned int vs_debug_dlim     = 0;
22680 +unsigned int vs_debug_quota    = 0;
22681 +unsigned int vs_debug_cvirt    = 0;
22682 +unsigned int vs_debug_space    = 0;
22683 +unsigned int vs_debug_perm     = 0;
22684 +unsigned int vs_debug_misc     = 0;
22685 +
22686 +
22687 +static struct ctl_table_header *vserver_table_header;
22688 +static ctl_table vserver_root_table[];
22689 +
22690 +
22691 +void vserver_register_sysctl(void)
22692 +{
22693 +       if (!vserver_table_header) {
22694 +               vserver_table_header = register_sysctl_table(vserver_root_table);
22695 +       }
22696 +
22697 +}
22698 +
22699 +void vserver_unregister_sysctl(void)
22700 +{
22701 +       if (vserver_table_header) {
22702 +               unregister_sysctl_table(vserver_table_header);
22703 +               vserver_table_header = NULL;
22704 +       }
22705 +}
22706 +
22707 +
22708 +static int proc_dodebug(ctl_table *table, int write,
22709 +       void __user *buffer, size_t *lenp, loff_t *ppos)
22710 +{
22711 +       char            tmpbuf[20], *p, c;
22712 +       unsigned int    value;
22713 +       size_t          left, len;
22714 +
22715 +       if ((*ppos && !write) || !*lenp) {
22716 +               *lenp = 0;
22717 +               return 0;
22718 +       }
22719 +
22720 +       left = *lenp;
22721 +
22722 +       if (write) {
22723 +               if (!access_ok(VERIFY_READ, buffer, left))
22724 +                       return -EFAULT;
22725 +               p = (char *)buffer;
22726 +               while (left && __get_user(c, p) >= 0 && isspace(c))
22727 +                       left--, p++;
22728 +               if (!left)
22729 +                       goto done;
22730 +
22731 +               if (left > sizeof(tmpbuf) - 1)
22732 +                       return -EINVAL;
22733 +               if (copy_from_user(tmpbuf, p, left))
22734 +                       return -EFAULT;
22735 +               tmpbuf[left] = '\0';
22736 +
22737 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
22738 +                       value = 10 * value + (*p - '0');
22739 +               if (*p && !isspace(*p))
22740 +                       return -EINVAL;
22741 +               while (left && isspace(*p))
22742 +                       left--, p++;
22743 +               *(unsigned int *)table->data = value;
22744 +       } else {
22745 +               if (!access_ok(VERIFY_WRITE, buffer, left))
22746 +                       return -EFAULT;
22747 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
22748 +               if (len > left)
22749 +                       len = left;
22750 +               if (__copy_to_user(buffer, tmpbuf, len))
22751 +                       return -EFAULT;
22752 +               if ((left -= len) > 0) {
22753 +                       if (put_user('\n', (char *)buffer + len))
22754 +                               return -EFAULT;
22755 +                       left--;
22756 +               }
22757 +       }
22758 +
22759 +done:
22760 +       *lenp -= left;
22761 +       *ppos += *lenp;
22762 +       return 0;
22763 +}
22764 +
22765 +static int zero;
22766 +
22767 +#define        CTL_ENTRY(ctl, name)                            \
22768 +       {                                               \
22769 +               .procname       = #name,                \
22770 +               .data           = &vs_ ## name,         \
22771 +               .maxlen         = sizeof(int),          \
22772 +               .mode           = 0644,                 \
22773 +               .proc_handler   = &proc_dodebug,        \
22774 +               .extra1         = &zero,                \
22775 +               .extra2         = &zero,                \
22776 +       }
22777 +
22778 +static ctl_table vserver_debug_table[] = {
22779 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
22780 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
22781 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
22782 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
22783 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
22784 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
22785 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
22786 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
22787 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
22788 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
22789 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
22790 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
22791 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
22792 +       { 0 }
22793 +};
22794 +
22795 +static ctl_table vserver_root_table[] = {
22796 +       {
22797 +               .procname       = "vserver",
22798 +               .mode           = 0555,
22799 +               .child          = vserver_debug_table
22800 +       },
22801 +       { 0 }
22802 +};
22803 +
22804 +
22805 +static match_table_t tokens = {
22806 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
22807 +       { CTL_DEBUG_XID,        "xid=%x"        },
22808 +       { CTL_DEBUG_NID,        "nid=%x"        },
22809 +       { CTL_DEBUG_TAG,        "tag=%x"        },
22810 +       { CTL_DEBUG_NET,        "net=%x"        },
22811 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
22812 +       { CTL_DEBUG_CRES,       "cres=%x"       },
22813 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
22814 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
22815 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
22816 +       { CTL_DEBUG_SPACE,      "space=%x"      },
22817 +       { CTL_DEBUG_PERM,       "perm=%x"       },
22818 +       { CTL_DEBUG_MISC,       "misc=%x"       },
22819 +       { CTL_DEBUG_ERROR,      NULL            }
22820 +};
22821 +
22822 +#define        HANDLE_CASE(id, name, val)                              \
22823 +       case CTL_DEBUG_ ## id:                                  \
22824 +               vs_debug_ ## name = val;                        \
22825 +               printk("vs_debug_" #name "=0x%x\n", val);       \
22826 +               break
22827 +
22828 +
22829 +static int __init vs_debug_setup(char *str)
22830 +{
22831 +       char *p;
22832 +       int token;
22833 +
22834 +       printk("vs_debug_setup(%s)\n", str);
22835 +       while ((p = strsep(&str, ",")) != NULL) {
22836 +               substring_t args[MAX_OPT_ARGS];
22837 +               unsigned int value;
22838 +
22839 +               if (!*p)
22840 +                       continue;
22841 +
22842 +               token = match_token(p, tokens, args);
22843 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
22844 +
22845 +               switch (token) {
22846 +               HANDLE_CASE(SWITCH, switch, value);
22847 +               HANDLE_CASE(XID,    xid,    value);
22848 +               HANDLE_CASE(NID,    nid,    value);
22849 +               HANDLE_CASE(TAG,    tag,    value);
22850 +               HANDLE_CASE(NET,    net,    value);
22851 +               HANDLE_CASE(LIMIT,  limit,  value);
22852 +               HANDLE_CASE(CRES,   cres,   value);
22853 +               HANDLE_CASE(DLIM,   dlim,   value);
22854 +               HANDLE_CASE(QUOTA,  quota,  value);
22855 +               HANDLE_CASE(CVIRT,  cvirt,  value);
22856 +               HANDLE_CASE(SPACE,  space,  value);
22857 +               HANDLE_CASE(PERM,   perm,   value);
22858 +               HANDLE_CASE(MISC,   misc,   value);
22859 +               default:
22860 +                       return -EINVAL;
22861 +                       break;
22862 +               }
22863 +       }
22864 +       return 1;
22865 +}
22866 +
22867 +__setup("vsdebug=", vs_debug_setup);
22868 +
22869 +
22870 +
22871 +EXPORT_SYMBOL_GPL(vs_debug_switch);
22872 +EXPORT_SYMBOL_GPL(vs_debug_xid);
22873 +EXPORT_SYMBOL_GPL(vs_debug_nid);
22874 +EXPORT_SYMBOL_GPL(vs_debug_net);
22875 +EXPORT_SYMBOL_GPL(vs_debug_limit);
22876 +EXPORT_SYMBOL_GPL(vs_debug_cres);
22877 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
22878 +EXPORT_SYMBOL_GPL(vs_debug_quota);
22879 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
22880 +EXPORT_SYMBOL_GPL(vs_debug_space);
22881 +EXPORT_SYMBOL_GPL(vs_debug_perm);
22882 +EXPORT_SYMBOL_GPL(vs_debug_misc);
22883 +
22884 diff -NurpP --minimal linux-3.13.1/kernel/vserver/tag.c linux-3.13.1-vs2.3.6.10/kernel/vserver/tag.c
22885 --- linux-3.13.1/kernel/vserver/tag.c   1970-01-01 00:00:00.000000000 +0000
22886 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/tag.c        2014-01-31 20:38:04.000000000 +0000
22887 @@ -0,0 +1,63 @@
22888 +/*
22889 + *  linux/kernel/vserver/tag.c
22890 + *
22891 + *  Virtual Server: Shallow Tag Space
22892 + *
22893 + *  Copyright (C) 2007  Herbert Pötzl
22894 + *
22895 + *  V0.01  basic implementation
22896 + *
22897 + */
22898 +
22899 +#include <linux/sched.h>
22900 +#include <linux/vserver/debug.h>
22901 +#include <linux/vs_pid.h>
22902 +#include <linux/vs_tag.h>
22903 +
22904 +#include <linux/vserver/tag_cmd.h>
22905 +
22906 +
22907 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
22908 +{
22909 +       if (!p)
22910 +               BUG();
22911 +
22912 +       vxdprintk(VXD_CBIT(tag, 5),
22913 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
22914 +
22915 +       task_lock(p);
22916 +       p->tag = tag;
22917 +       task_unlock(p);
22918 +
22919 +       vxdprintk(VXD_CBIT(tag, 5),
22920 +               "moved task %p into [#%d]", p, tag);
22921 +       return 0;
22922 +}
22923 +
22924 +/* vserver syscall commands below here */
22925 +
22926 +/* taks xid and vx_info functions */
22927 +
22928 +
22929 +int vc_task_tag(uint32_t id)
22930 +{
22931 +       vtag_t tag;
22932 +
22933 +       if (id) {
22934 +               struct task_struct *tsk;
22935 +               rcu_read_lock();
22936 +               tsk = find_task_by_real_pid(id);
22937 +               tag = (tsk) ? tsk->tag : -ESRCH;
22938 +               rcu_read_unlock();
22939 +       } else
22940 +               tag = dx_current_tag();
22941 +       return tag;
22942 +}
22943 +
22944 +
22945 +int vc_tag_migrate(uint32_t tag)
22946 +{
22947 +       return dx_migrate_task(current, tag & 0xFFFF);
22948 +}
22949 +
22950 +
22951 diff -NurpP --minimal linux-3.13.1/kernel/vserver/vci_config.h linux-3.13.1-vs2.3.6.10/kernel/vserver/vci_config.h
22952 --- linux-3.13.1/kernel/vserver/vci_config.h    1970-01-01 00:00:00.000000000 +0000
22953 +++ linux-3.13.1-vs2.3.6.10/kernel/vserver/vci_config.h 2014-01-31 20:38:04.000000000 +0000
22954 @@ -0,0 +1,80 @@
22955 +
22956 +/*  interface version */
22957 +
22958 +#define VCI_VERSION            0x00020308
22959 +
22960 +
22961 +enum {
22962 +       VCI_KCBIT_NO_DYNAMIC = 0,
22963 +
22964 +       VCI_KCBIT_PROC_SECURE = 4,
22965 +       /* VCI_KCBIT_HARDCPU = 5, */
22966 +       /* VCI_KCBIT_IDLELIMIT = 6, */
22967 +       /* VCI_KCBIT_IDLETIME = 7, */
22968 +
22969 +       VCI_KCBIT_COWBL = 8,
22970 +       VCI_KCBIT_FULLCOWBL = 9,
22971 +       VCI_KCBIT_SPACES = 10,
22972 +       VCI_KCBIT_NETV2 = 11,
22973 +       VCI_KCBIT_MEMCG = 12,
22974 +       VCI_KCBIT_MEMCG_SWAP = 13,
22975 +
22976 +       VCI_KCBIT_DEBUG = 16,
22977 +       VCI_KCBIT_HISTORY = 20,
22978 +       VCI_KCBIT_TAGGED = 24,
22979 +       VCI_KCBIT_PPTAG = 28,
22980 +
22981 +       VCI_KCBIT_MORE = 31,
22982 +};
22983 +
22984 +
22985 +static inline uint32_t vci_kernel_config(void)
22986 +{
22987 +       return
22988 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
22989 +
22990 +       /* configured features */
22991 +#ifdef CONFIG_VSERVER_PROC_SECURE
22992 +       (1 << VCI_KCBIT_PROC_SECURE) |
22993 +#endif
22994 +#ifdef CONFIG_VSERVER_COWBL
22995 +       (1 << VCI_KCBIT_COWBL) |
22996 +       (1 << VCI_KCBIT_FULLCOWBL) |
22997 +#endif
22998 +       (1 << VCI_KCBIT_SPACES) |
22999 +       (1 << VCI_KCBIT_NETV2) |
23000 +#ifdef CONFIG_MEMCG
23001 +       (1 << VCI_KCBIT_MEMCG) |
23002 +#endif
23003 +#ifdef CONFIG_MEMCG_SWAP
23004 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
23005 +#endif
23006 +
23007 +       /* debug options */
23008 +#ifdef CONFIG_VSERVER_DEBUG
23009 +       (1 << VCI_KCBIT_DEBUG) |
23010 +#endif
23011 +#ifdef CONFIG_VSERVER_HISTORY
23012 +       (1 << VCI_KCBIT_HISTORY) |
23013 +#endif
23014 +
23015 +       /* inode context tagging */
23016 +#if    defined(CONFIG_TAGGING_NONE)
23017 +       (0 << VCI_KCBIT_TAGGED) |
23018 +#elif  defined(CONFIG_TAGGING_UID16)
23019 +       (1 << VCI_KCBIT_TAGGED) |
23020 +#elif  defined(CONFIG_TAGGING_GID16)
23021 +       (2 << VCI_KCBIT_TAGGED) |
23022 +#elif  defined(CONFIG_TAGGING_ID24)
23023 +       (3 << VCI_KCBIT_TAGGED) |
23024 +#elif  defined(CONFIG_TAGGING_INTERN)
23025 +       (4 << VCI_KCBIT_TAGGED) |
23026 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23027 +       (5 << VCI_KCBIT_TAGGED) |
23028 +#else
23029 +       (7 << VCI_KCBIT_TAGGED) |
23030 +#endif
23031 +       (1 << VCI_KCBIT_PPTAG) |
23032 +       0;
23033 +}
23034 +
23035 diff -NurpP --minimal linux-3.13.1/mm/memcontrol.c linux-3.13.1-vs2.3.6.10/mm/memcontrol.c
23036 --- linux-3.13.1/mm/memcontrol.c        2014-01-22 20:39:14.000000000 +0000
23037 +++ linux-3.13.1-vs2.3.6.10/mm/memcontrol.c     2014-01-31 20:38:04.000000000 +0000
23038 @@ -1056,6 +1056,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23039         return mem_cgroup_from_css(task_css(p, mem_cgroup_subsys_id));
23040  }
23041  
23042 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23043 +{
23044 +       return res_counter_read_u64(&mem->res, member);
23045 +}
23046 +
23047 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23048 +{
23049 +       return res_counter_read_u64(&mem->memsw, member);
23050 +}
23051 +
23052 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23053 +{
23054 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23055 +}
23056 +
23057 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23058 +{
23059 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23060 +}
23061 +
23062 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23063 +{
23064 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23065 +}
23066 +
23067  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23068  {
23069         struct mem_cgroup *memcg = NULL;
23070 diff -NurpP --minimal linux-3.13.1/mm/oom_kill.c linux-3.13.1-vs2.3.6.10/mm/oom_kill.c
23071 --- linux-3.13.1/mm/oom_kill.c  2014-01-22 20:39:14.000000000 +0000
23072 +++ linux-3.13.1-vs2.3.6.10/mm/oom_kill.c       2014-01-31 20:38:04.000000000 +0000
23073 @@ -35,6 +35,8 @@
23074  #include <linux/freezer.h>
23075  #include <linux/ftrace.h>
23076  #include <linux/ratelimit.h>
23077 +#include <linux/reboot.h>
23078 +#include <linux/vs_context.h>
23079  
23080  #define CREATE_TRACE_POINTS
23081  #include <trace/events/oom.h>
23082 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23083  static bool oom_unkillable_task(struct task_struct *p,
23084                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23085  {
23086 -       if (is_global_init(p))
23087 +       unsigned xid = vx_current_xid();
23088 +
23089 +       /* skip the init task, global and per guest */
23090 +       if (task_is_init(p))
23091                 return true;
23092         if (p->flags & PF_KTHREAD)
23093                 return true;
23094  
23095 +       /* skip other guest and host processes if oom in guest */
23096 +       if (xid && vx_task_xid(p) != xid)
23097 +               return true;
23098 +
23099         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23100         if (memcg && !task_in_mem_cgroup(p, memcg))
23101                 return true;
23102 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23103                 dump_header(p, gfp_mask, order, memcg, nodemask);
23104  
23105         task_lock(p);
23106 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23107 -               message, task_pid_nr(p), p->comm, points);
23108 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23109 +               message, task_pid_nr(p), p->xid, p->comm, points);
23110         task_unlock(p);
23111  
23112         /*
23113 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23114  
23115         /* mm cannot safely be dereferenced after task_unlock(victim) */
23116         mm = victim->mm;
23117 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23118 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23119 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23120 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23121                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23122                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23123         task_unlock(victim);
23124 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23125  }
23126  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23127  
23128 +long vs_oom_action(unsigned int);
23129 +
23130  /*
23131   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23132   * if a parallel OOM killing is already taking place that includes a zone in
23133 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23134         /* Found nothing?!?! Either we hang forever, or we panic. */
23135         if (!p) {
23136                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23137 -               panic("Out of memory and no killable processes...\n");
23138 +
23139 +               /* avoid panic for guest OOM */
23140 +               if (vx_current_xid())
23141 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23142 +               else
23143 +                       panic("Out of memory and no killable processes...\n");
23144         }
23145         if (p != (void *)-1UL) {
23146                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23147 diff -NurpP --minimal linux-3.13.1/mm/page_alloc.c linux-3.13.1-vs2.3.6.10/mm/page_alloc.c
23148 --- linux-3.13.1/mm/page_alloc.c        2014-01-22 20:39:14.000000000 +0000
23149 +++ linux-3.13.1-vs2.3.6.10/mm/page_alloc.c     2014-01-31 20:38:04.000000000 +0000
23150 @@ -61,6 +61,8 @@
23151  #include <linux/page-debug-flags.h>
23152  #include <linux/hugetlb.h>
23153  #include <linux/sched/rt.h>
23154 +#include <linux/vs_base.h>
23155 +#include <linux/vs_limit.h>
23156  
23157  #include <asm/sections.h>
23158  #include <asm/tlbflush.h>
23159 @@ -2963,6 +2965,9 @@ void si_meminfo(struct sysinfo *val)
23160         val->totalhigh = totalhigh_pages;
23161         val->freehigh = nr_free_highpages();
23162         val->mem_unit = PAGE_SIZE;
23163 +
23164 +       if (vx_flags(VXF_VIRT_MEM, 0))
23165 +               vx_vsi_meminfo(val);
23166  }
23167  
23168  EXPORT_SYMBOL(si_meminfo);
23169 @@ -2987,6 +2992,9 @@ void si_meminfo_node(struct sysinfo *val
23170         val->freehigh = 0;
23171  #endif
23172         val->mem_unit = PAGE_SIZE;
23173 +
23174 +       if (vx_flags(VXF_VIRT_MEM, 0))
23175 +               vx_vsi_meminfo(val);
23176  }
23177  #endif
23178  
23179 diff -NurpP --minimal linux-3.13.1/mm/pgtable-generic.c linux-3.13.1-vs2.3.6.10/mm/pgtable-generic.c
23180 --- linux-3.13.1/mm/pgtable-generic.c   2014-01-22 20:39:14.000000000 +0000
23181 +++ linux-3.13.1-vs2.3.6.10/mm/pgtable-generic.c        2014-01-31 20:38:04.000000000 +0000
23182 @@ -6,6 +6,8 @@
23183   *  Copyright (C) 2010  Linus Torvalds
23184   */
23185  
23186 +#include <linux/mm.h>
23187 +
23188  #include <linux/pagemap.h>
23189  #include <asm/tlb.h>
23190  #include <asm-generic/pgtable.h>
23191 diff -NurpP --minimal linux-3.13.1/mm/shmem.c linux-3.13.1-vs2.3.6.10/mm/shmem.c
23192 --- linux-3.13.1/mm/shmem.c     2014-01-22 20:39:14.000000000 +0000
23193 +++ linux-3.13.1-vs2.3.6.10/mm/shmem.c  2014-01-31 20:38:04.000000000 +0000
23194 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23195  {
23196         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23197  
23198 -       buf->f_type = TMPFS_MAGIC;
23199 +       buf->f_type = TMPFS_SUPER_MAGIC;
23200         buf->f_bsize = PAGE_CACHE_SIZE;
23201         buf->f_namelen = NAME_MAX;
23202         if (sbinfo->max_blocks) {
23203 @@ -2639,7 +2639,7 @@ int shmem_fill_super(struct super_block
23204         sb->s_maxbytes = MAX_LFS_FILESIZE;
23205         sb->s_blocksize = PAGE_CACHE_SIZE;
23206         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23207 -       sb->s_magic = TMPFS_MAGIC;
23208 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23209         sb->s_op = &shmem_ops;
23210         sb->s_time_gran = 1;
23211  #ifdef CONFIG_TMPFS_XATTR
23212 diff -NurpP --minimal linux-3.13.1/mm/slab.c linux-3.13.1-vs2.3.6.10/mm/slab.c
23213 --- linux-3.13.1/mm/slab.c      2014-01-22 20:39:14.000000000 +0000
23214 +++ linux-3.13.1-vs2.3.6.10/mm/slab.c   2014-01-31 20:38:04.000000000 +0000
23215 @@ -322,6 +322,8 @@ static void kmem_cache_node_init(struct
23216  #define STATS_INC_FREEMISS(x)  do { } while (0)
23217  #endif
23218  
23219 +#include "slab_vs.h"
23220 +
23221  #if DEBUG
23222  
23223  /*
23224 @@ -3240,6 +3242,7 @@ slab_alloc_node(struct kmem_cache *cache
23225         /* ___cache_alloc_node can fall back to other nodes */
23226         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23227    out:
23228 +       vx_slab_alloc(cachep, flags);
23229         local_irq_restore(save_flags);
23230         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23231         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23232 @@ -3430,6 +3433,7 @@ static inline void __cache_free(struct k
23233         check_irq_off();
23234         kmemleak_free_recursive(objp, cachep->flags);
23235         objp = cache_free_debugcheck(cachep, objp, caller);
23236 +       vx_slab_free(cachep);
23237  
23238         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23239  
23240 diff -NurpP --minimal linux-3.13.1/mm/slab_vs.h linux-3.13.1-vs2.3.6.10/mm/slab_vs.h
23241 --- linux-3.13.1/mm/slab_vs.h   1970-01-01 00:00:00.000000000 +0000
23242 +++ linux-3.13.1-vs2.3.6.10/mm/slab_vs.h        2014-01-31 20:38:04.000000000 +0000
23243 @@ -0,0 +1,29 @@
23244 +
23245 +#include <linux/vserver/context.h>
23246 +
23247 +#include <linux/vs_context.h>
23248 +
23249 +static inline
23250 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23251 +{
23252 +       int what = gfp_zone(cachep->allocflags);
23253 +       struct vx_info *vxi = current_vx_info();
23254 +
23255 +       if (!vxi)
23256 +               return;
23257 +
23258 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
23259 +}
23260 +
23261 +static inline
23262 +void vx_slab_free(struct kmem_cache *cachep)
23263 +{
23264 +       int what = gfp_zone(cachep->allocflags);
23265 +       struct vx_info *vxi = current_vx_info();
23266 +
23267 +       if (!vxi)
23268 +               return;
23269 +
23270 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23271 +}
23272 +
23273 diff -NurpP --minimal linux-3.13.1/mm/swapfile.c linux-3.13.1-vs2.3.6.10/mm/swapfile.c
23274 --- linux-3.13.1/mm/swapfile.c  2014-01-22 20:39:14.000000000 +0000
23275 +++ linux-3.13.1-vs2.3.6.10/mm/swapfile.c       2014-01-31 20:38:04.000000000 +0000
23276 @@ -39,6 +39,7 @@
23277  #include <asm/tlbflush.h>
23278  #include <linux/swapops.h>
23279  #include <linux/page_cgroup.h>
23280 +#include <linux/vs_base.h>
23281  
23282  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23283                                  unsigned char);
23284 @@ -2033,6 +2034,16 @@ static int swap_show(struct seq_file *sw
23285  
23286         if (si == SEQ_START_TOKEN) {
23287                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23288 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
23289 +                       struct sysinfo si;
23290 +
23291 +                       vx_vsi_swapinfo(&si);
23292 +                       if (si.totalswap < (1 << 10))
23293 +                               return 0;
23294 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23295 +                               "hdv0", "partition", si.totalswap >> 10,
23296 +                               (si.totalswap - si.freeswap) >> 10, -1);
23297 +               }
23298                 return 0;
23299         }
23300  
23301 @@ -2580,6 +2591,8 @@ void si_swapinfo(struct sysinfo *val)
23302         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
23303         val->totalswap = total_swap_pages + nr_to_be_unused;
23304         spin_unlock(&swap_lock);
23305 +       if (vx_flags(VXF_VIRT_MEM, 0))
23306 +               vx_vsi_swapinfo(val);
23307  }
23308  
23309  /*
23310 diff -NurpP --minimal linux-3.13.1/net/bridge/br_multicast.c linux-3.13.1-vs2.3.6.10/net/bridge/br_multicast.c
23311 --- linux-3.13.1/net/bridge/br_multicast.c      2014-01-22 20:39:14.000000000 +0000
23312 +++ linux-3.13.1-vs2.3.6.10/net/bridge/br_multicast.c   2014-01-31 20:38:04.000000000 +0000
23313 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
23314         ip6h->hop_limit = 1;
23315         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23316         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23317 -                              &ip6h->saddr)) {
23318 +                              &ip6h->saddr, NULL)) {
23319                 kfree_skb(skb);
23320                 return NULL;
23321         }
23322 diff -NurpP --minimal linux-3.13.1/net/core/dev.c linux-3.13.1-vs2.3.6.10/net/core/dev.c
23323 --- linux-3.13.1/net/core/dev.c 2014-01-22 20:39:15.000000000 +0000
23324 +++ linux-3.13.1-vs2.3.6.10/net/core/dev.c      2014-01-31 20:38:04.000000000 +0000
23325 @@ -122,6 +122,7 @@
23326  #include <linux/in.h>
23327  #include <linux/jhash.h>
23328  #include <linux/random.h>
23329 +#include <linux/vs_inet.h>
23330  #include <trace/events/napi.h>
23331  #include <trace/events/net.h>
23332  #include <trace/events/skb.h>
23333 @@ -669,7 +670,8 @@ struct net_device *__dev_get_by_name(str
23334         struct hlist_head *head = dev_name_hash(net, name);
23335  
23336         hlist_for_each_entry(dev, head, name_hlist)
23337 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23338 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23339 +                   nx_dev_visible(current_nx_info(), dev))
23340                         return dev;
23341  
23342         return NULL;
23343 @@ -694,7 +696,8 @@ struct net_device *dev_get_by_name_rcu(s
23344         struct hlist_head *head = dev_name_hash(net, name);
23345  
23346         hlist_for_each_entry_rcu(dev, head, name_hlist)
23347 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23348 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23349 +                   nx_dev_visible(current_nx_info(), dev))
23350                         return dev;
23351  
23352         return NULL;
23353 @@ -744,7 +747,8 @@ struct net_device *__dev_get_by_index(st
23354         struct hlist_head *head = dev_index_hash(net, ifindex);
23355  
23356         hlist_for_each_entry(dev, head, index_hlist)
23357 -               if (dev->ifindex == ifindex)
23358 +               if ((dev->ifindex == ifindex) &&
23359 +                   nx_dev_visible(current_nx_info(), dev))
23360                         return dev;
23361  
23362         return NULL;
23363 @@ -762,7 +766,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
23364   *     about locking. The caller must hold RCU lock.
23365   */
23366  
23367 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23368 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
23369  {
23370         struct net_device *dev;
23371         struct hlist_head *head = dev_index_hash(net, ifindex);
23372 @@ -773,6 +777,16 @@ struct net_device *dev_get_by_index_rcu(
23373  
23374         return NULL;
23375  }
23376 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
23377 +
23378 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23379 +{
23380 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
23381 +
23382 +       if (nx_dev_visible(current_nx_info(), dev))
23383 +               return dev;
23384 +       return NULL;
23385 +}
23386  EXPORT_SYMBOL(dev_get_by_index_rcu);
23387  
23388  
23389 @@ -855,7 +869,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
23390  
23391         for_each_netdev_rcu(net, dev)
23392                 if (dev->type == type &&
23393 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
23394 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
23395 +                   nx_dev_visible(current_nx_info(), dev))
23396                         return dev;
23397  
23398         return NULL;
23399 @@ -867,9 +882,11 @@ struct net_device *__dev_getfirstbyhwtyp
23400         struct net_device *dev;
23401  
23402         ASSERT_RTNL();
23403 -       for_each_netdev(net, dev)
23404 -               if (dev->type == type)
23405 +       for_each_netdev(net, dev) {
23406 +               if ((dev->type == type) &&
23407 +                   nx_dev_visible(current_nx_info(), dev))
23408                         return dev;
23409 +       }
23410  
23411         return NULL;
23412  }
23413 @@ -881,7 +898,8 @@ struct net_device *dev_getfirstbyhwtype(
23414  
23415         rcu_read_lock();
23416         for_each_netdev_rcu(net, dev)
23417 -               if (dev->type == type) {
23418 +               if ((dev->type == type) &&
23419 +                   nx_dev_visible(current_nx_info(), dev)) {
23420                         dev_hold(dev);
23421                         ret = dev;
23422                         break;
23423 @@ -909,7 +927,8 @@ struct net_device *dev_get_by_flags_rcu(
23424  
23425         ret = NULL;
23426         for_each_netdev_rcu(net, dev) {
23427 -               if (((dev->flags ^ if_flags) & mask) == 0) {
23428 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
23429 +                       nx_dev_visible(current_nx_info(), dev)) {
23430                         ret = dev;
23431                         break;
23432                 }
23433 @@ -987,6 +1006,8 @@ static int __dev_alloc_name(struct net *
23434                                 continue;
23435                         if (i < 0 || i >= max_netdevices)
23436                                 continue;
23437 +                       if (!nx_dev_visible(current_nx_info(), d))
23438 +                               continue;
23439  
23440                         /*  avoid cases where sscanf is not exact inverse of printf */
23441                         snprintf(buf, IFNAMSIZ, name, i);
23442 diff -NurpP --minimal linux-3.13.1/net/core/net-procfs.c linux-3.13.1-vs2.3.6.10/net/core/net-procfs.c
23443 --- linux-3.13.1/net/core/net-procfs.c  2013-11-25 15:45:09.000000000 +0000
23444 +++ linux-3.13.1-vs2.3.6.10/net/core/net-procfs.c       2014-01-31 20:38:04.000000000 +0000
23445 @@ -1,6 +1,7 @@
23446  #include <linux/netdevice.h>
23447  #include <linux/proc_fs.h>
23448  #include <linux/seq_file.h>
23449 +#include <linux/vs_inet.h>
23450  #include <net/wext.h>
23451  
23452  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
23453 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
23454  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
23455  {
23456         struct rtnl_link_stats64 temp;
23457 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
23458 +       const struct rtnl_link_stats64 *stats;
23459 +
23460 +       /* device visible inside network context? */
23461 +       if (!nx_dev_visible(current_nx_info(), dev))
23462 +               return;
23463  
23464 +       stats = dev_get_stats(dev, &temp);
23465         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
23466                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
23467                    dev->name, stats->rx_bytes, stats->rx_packets,
23468 diff -NurpP --minimal linux-3.13.1/net/core/rtnetlink.c linux-3.13.1-vs2.3.6.10/net/core/rtnetlink.c
23469 --- linux-3.13.1/net/core/rtnetlink.c   2014-01-22 20:39:15.000000000 +0000
23470 +++ linux-3.13.1-vs2.3.6.10/net/core/rtnetlink.c        2014-01-31 22:32:10.000000000 +0000
23471 @@ -1090,6 +1090,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
23472                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
23473                         if (idx < s_idx)
23474                                 goto cont;
23475 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
23476 +                               continue;
23477                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
23478                                              NETLINK_CB(cb->skb).portid,
23479                                              cb->nlh->nlmsg_seq, 0,
23480 @@ -1992,6 +1994,9 @@ void rtmsg_ifinfo(int type, struct net_d
23481         int err = -ENOBUFS;
23482         size_t if_info_size;
23483  
23484 +       if (!nx_dev_visible(current_nx_info(), dev))
23485 +               return;
23486 +
23487         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), flags);
23488         if (skb == NULL)
23489                 goto errout;
23490 diff -NurpP --minimal linux-3.13.1/net/core/sock.c linux-3.13.1-vs2.3.6.10/net/core/sock.c
23491 --- linux-3.13.1/net/core/sock.c        2014-01-22 20:39:15.000000000 +0000
23492 +++ linux-3.13.1-vs2.3.6.10/net/core/sock.c     2014-01-31 22:33:49.000000000 +0000
23493 @@ -133,6 +133,10 @@
23494  #include <net/netprio_cgroup.h>
23495  
23496  #include <linux/filter.h>
23497 +#include <linux/vs_socket.h>
23498 +#include <linux/vs_limit.h>
23499 +#include <linux/vs_context.h>
23500 +#include <linux/vs_network.h>
23501  
23502  #include <trace/events/sock.h>
23503  
23504 @@ -1279,6 +1283,8 @@ static struct sock *sk_prot_alloc(struct
23505                         goto out_free_sec;
23506                 sk_tx_queue_clear(sk);
23507         }
23508 +               sock_vx_init(sk);
23509 +               sock_nx_init(sk);
23510  
23511         return sk;
23512  
23513 @@ -1387,6 +1393,11 @@ static void __sk_free(struct sock *sk)
23514                 put_cred(sk->sk_peer_cred);
23515         put_pid(sk->sk_peer_pid);
23516         put_net(sock_net(sk));
23517 +       vx_sock_dec(sk);
23518 +       clr_vx_info(&sk->sk_vx_info);
23519 +       sk->sk_xid = -1;
23520 +       clr_nx_info(&sk->sk_nx_info);
23521 +       sk->sk_nid = -1;
23522         sk_prot_free(sk->sk_prot_creator, sk);
23523  }
23524  
23525 @@ -1447,6 +1458,8 @@ struct sock *sk_clone_lock(const struct
23526  
23527                 /* SANITY */
23528                 get_net(sock_net(newsk));
23529 +               sock_vx_init(newsk);
23530 +               sock_nx_init(newsk);
23531                 sk_node_init(&newsk->sk_node);
23532                 sock_lock_init(newsk);
23533                 bh_lock_sock(newsk);
23534 @@ -1503,6 +1516,12 @@ struct sock *sk_clone_lock(const struct
23535                 smp_wmb();
23536                 atomic_set(&newsk->sk_refcnt, 2);
23537  
23538 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
23539 +               newsk->sk_xid = sk->sk_xid;
23540 +               vx_sock_inc(newsk);
23541 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
23542 +               newsk->sk_nid = sk->sk_nid;
23543 +
23544                 /*
23545                  * Increment the counter in the same struct proto as the master
23546                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
23547 @@ -2338,6 +2357,12 @@ void sock_init_data(struct socket *sock,
23548  
23549         sk->sk_stamp = ktime_set(-1L, 0);
23550  
23551 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
23552 +       sk->sk_xid = vx_current_xid();
23553 +       vx_sock_inc(sk);
23554 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
23555 +       sk->sk_nid = nx_current_nid();
23556 +
23557  #ifdef CONFIG_NET_RX_BUSY_POLL
23558         sk->sk_napi_id          =       0;
23559         sk->sk_ll_usec          =       sysctl_net_busy_read;
23560 diff -NurpP --minimal linux-3.13.1/net/ipv4/af_inet.c linux-3.13.1-vs2.3.6.10/net/ipv4/af_inet.c
23561 --- linux-3.13.1/net/ipv4/af_inet.c     2014-01-22 20:39:15.000000000 +0000
23562 +++ linux-3.13.1-vs2.3.6.10/net/ipv4/af_inet.c  2014-01-31 20:38:04.000000000 +0000
23563 @@ -118,6 +118,7 @@
23564  #ifdef CONFIG_IP_MROUTE
23565  #include <linux/mroute.h>
23566  #endif
23567 +#include <linux/vs_limit.h>
23568  
23569  
23570  /* The inetsw table contains everything that inet_create needs to
23571 @@ -309,10 +310,13 @@ lookup_protocol:
23572         }
23573  
23574         err = -EPERM;
23575 +       if ((protocol == IPPROTO_ICMP) &&
23576 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
23577 +               goto override;
23578         if (sock->type == SOCK_RAW && !kern &&
23579             !ns_capable(net->user_ns, CAP_NET_RAW))
23580                 goto out_rcu_unlock;
23581 -
23582 +override:
23583         sock->ops = answer->ops;
23584         answer_prot = answer->prot;
23585         answer_no_check = answer->no_check;
23586 @@ -433,6 +437,7 @@ int inet_bind(struct socket *sock, struc
23587         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
23588         struct sock *sk = sock->sk;
23589         struct inet_sock *inet = inet_sk(sk);
23590 +       struct nx_v4_sock_addr nsa;
23591         struct net *net = sock_net(sk);
23592         unsigned short snum;
23593         int chk_addr_ret;
23594 @@ -457,7 +462,11 @@ int inet_bind(struct socket *sock, struc
23595                         goto out;
23596         }
23597  
23598 -       chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
23599 +       err = v4_map_sock_addr(inet, addr, &nsa);
23600 +       if (err)
23601 +               goto out;
23602 +
23603 +       chk_addr_ret = inet_addr_type(net, nsa.saddr);
23604  
23605         /* Not specified by any standard per-se, however it breaks too
23606          * many applications when removed.  It is unfortunate since
23607 @@ -469,7 +478,7 @@ int inet_bind(struct socket *sock, struc
23608         err = -EADDRNOTAVAIL;
23609         if (!sysctl_ip_nonlocal_bind &&
23610             !(inet->freebind || inet->transparent) &&
23611 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
23612 +           nsa.saddr != htonl(INADDR_ANY) &&
23613             chk_addr_ret != RTN_LOCAL &&
23614             chk_addr_ret != RTN_MULTICAST &&
23615             chk_addr_ret != RTN_BROADCAST)
23616 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
23617         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
23618                 goto out_release_sock;
23619  
23620 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23621 +       v4_set_sock_addr(inet, &nsa);
23622         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23623                 inet->inet_saddr = 0;  /* Use device */
23624  
23625 @@ -714,11 +723,13 @@ int inet_getname(struct socket *sock, st
23626                      peer == 1))
23627                         return -ENOTCONN;
23628                 sin->sin_port = inet->inet_dport;
23629 -               sin->sin_addr.s_addr = inet->inet_daddr;
23630 +               sin->sin_addr.s_addr =
23631 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
23632         } else {
23633                 __be32 addr = inet->inet_rcv_saddr;
23634                 if (!addr)
23635                         addr = inet->inet_saddr;
23636 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
23637                 sin->sin_port = inet->inet_sport;
23638                 sin->sin_addr.s_addr = addr;
23639         }
23640 diff -NurpP --minimal linux-3.13.1/net/ipv4/arp.c linux-3.13.1-vs2.3.6.10/net/ipv4/arp.c
23641 --- linux-3.13.1/net/ipv4/arp.c 2013-11-25 15:47:06.000000000 +0000
23642 +++ linux-3.13.1-vs2.3.6.10/net/ipv4/arp.c      2014-01-31 20:38:04.000000000 +0000
23643 @@ -1336,6 +1336,7 @@ static void arp_format_neigh_entry(struc
23644         struct net_device *dev = n->dev;
23645         int hatype = dev->type;
23646  
23647 +       /* FIXME: check for network context */
23648         read_lock(&n->lock);
23649         /* Convert hardware address to XX:XX:XX:XX ... form. */
23650  #if IS_ENABLED(CONFIG_AX25)
23651 @@ -1367,6 +1368,7 @@ static void arp_format_pneigh_entry(stru
23652         int hatype = dev ? dev->type : 0;
23653         char tbuf[16];
23654  
23655 +       /* FIXME: check for network context */
23656         sprintf(tbuf, "%pI4", n->key);
23657         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
23658                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
23659 diff -NurpP --minimal linux-3.13.1/net/ipv4/devinet.c linux-3.13.1-vs2.3.6.10/net/ipv4/devinet.c
23660 --- linux-3.13.1/net/ipv4/devinet.c     2013-11-25 15:47:06.000000000 +0000
23661 +++ linux-3.13.1-vs2.3.6.10/net/ipv4/devinet.c  2014-01-31 20:38:04.000000000 +0000
23662 @@ -527,6 +527,7 @@ struct in_device *inetdev_by_index(struc
23663  }
23664  EXPORT_SYMBOL(inetdev_by_index);
23665  
23666 +
23667  /* Called only from RTNL semaphored context. No locks. */
23668  
23669  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
23670 @@ -947,6 +948,8 @@ int devinet_ioctl(struct net *net, unsig
23671  
23672         in_dev = __in_dev_get_rtnl(dev);
23673         if (in_dev) {
23674 +               struct nx_info *nxi = current_nx_info();
23675 +
23676                 if (tryaddrmatch) {
23677                         /* Matthias Andree */
23678                         /* compare label and address (4.4BSD style) */
23679 @@ -955,6 +958,8 @@ int devinet_ioctl(struct net *net, unsig
23680                            This is checked above. */
23681                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23682                              ifap = &ifa->ifa_next) {
23683 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23684 +                                       continue;
23685                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
23686                                     sin_orig.sin_addr.s_addr ==
23687                                                         ifa->ifa_local) {
23688 @@ -967,9 +972,12 @@ int devinet_ioctl(struct net *net, unsig
23689                    comparing just the label */
23690                 if (!ifa) {
23691                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23692 -                            ifap = &ifa->ifa_next)
23693 +                            ifap = &ifa->ifa_next) {
23694 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23695 +                                       continue;
23696                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
23697                                         break;
23698 +                       }
23699                 }
23700         }
23701  
23702 @@ -1123,6 +1131,8 @@ static int inet_gifconf(struct net_devic
23703                 goto out;
23704  
23705         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
23706 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
23707 +                       continue;
23708                 if (!buf) {
23709                         done += sizeof(ifr);
23710                         continue;
23711 @@ -1523,6 +1533,7 @@ static int inet_dump_ifaddr(struct sk_bu
23712         struct net_device *dev;
23713         struct in_device *in_dev;
23714         struct in_ifaddr *ifa;
23715 +       struct sock *sk = skb->sk;
23716         struct hlist_head *head;
23717  
23718         s_h = cb->args[0];
23719 @@ -1546,6 +1557,8 @@ static int inet_dump_ifaddr(struct sk_bu
23720  
23721                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
23722                              ifa = ifa->ifa_next, ip_idx++) {
23723 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
23724 +                               continue;
23725                                 if (ip_idx < s_ip_idx)
23726                                         continue;
23727                                 if (inet_fill_ifaddr(skb, ifa,
23728 diff -NurpP --minimal linux-3.13.1/net/ipv4/fib_trie.c linux-3.13.1-vs2.3.6.10/net/ipv4/fib_trie.c
23729 --- linux-3.13.1/net/ipv4/fib_trie.c    2014-01-22 20:39:15.000000000 +0000
23730 +++ linux-3.13.1-vs2.3.6.10/net/ipv4/fib_trie.c 2014-01-31 20:38:04.000000000 +0000
23731 @@ -2530,6 +2530,7 @@ static int fib_route_seq_show(struct seq
23732  
23733                         seq_setwidth(seq, 127);
23734  
23735 +                       /* FIXME: check for network context? */
23736                         if (fi)
23737                                 seq_printf(seq,
23738                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
23739 diff -NurpP --minimal linux-3.13.1/net/ipv4/inet_connection_sock.c linux-3.13.1-vs2.3.6.10/net/ipv4/inet_connection_sock.c
23740 --- linux-3.13.1/net/ipv4/inet_connection_sock.c        2014-01-22 20:39:15.000000000 +0000
23741 +++ linux-3.13.1-vs2.3.6.10/net/ipv4/inet_connection_sock.c     2014-02-01 00:33:11.000000000 +0000
23742 @@ -45,6 +45,37 @@ void inet_get_local_port_range(struct ne
23743  }
23744  EXPORT_SYMBOL(inet_get_local_port_range);
23745  
23746 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
23747 +{
23748 +       __be32  sk1_rcv_saddr = sk1->sk_rcv_saddr,
23749 +               sk2_rcv_saddr = sk2->sk_rcv_saddr;
23750 +
23751 +       if (inet_v6_ipv6only(sk2))
23752 +               return 0;
23753 +
23754 +       if (sk1_rcv_saddr &&
23755 +           sk2_rcv_saddr &&
23756 +           sk1_rcv_saddr == sk2_rcv_saddr)
23757 +               return 1;
23758 +
23759 +       if (sk1_rcv_saddr &&
23760 +           !sk2_rcv_saddr &&
23761 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
23762 +               return 1;
23763 +
23764 +       if (sk2_rcv_saddr &&
23765 +           !sk1_rcv_saddr &&
23766 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
23767 +               return 1;
23768 +
23769 +       if (!sk1_rcv_saddr &&
23770 +           !sk2_rcv_saddr &&
23771 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
23772 +               return 1;
23773 +
23774 +       return 0;
23775 +}
23776 +
23777  int inet_csk_bind_conflict(const struct sock *sk,
23778                            const struct inet_bind_bucket *tb, bool relax)
23779  {
23780 @@ -72,15 +103,13 @@ int inet_csk_bind_conflict(const struct
23781                             (sk2->sk_state != TCP_TIME_WAIT &&
23782                              !uid_eq(uid, sock_i_uid(sk2))))) {
23783  
23784 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23785 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23786 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23787                                         break;
23788                         }
23789                         if (!relax && reuse && sk2->sk_reuse &&
23790                             sk2->sk_state != TCP_LISTEN) {
23791  
23792 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23793 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23794 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23795                                         break;
23796                         }
23797                 }
23798 diff -NurpP --minimal linux-3.13.1/net/ipv4/inet_diag.c linux-3.13.1-vs2.3.6.10/net/ipv4/inet_diag.c
23799 --- linux-3.13.1/net/ipv4/inet_diag.c   2014-02-01 02:17:51.000000000 +0000
23800 +++ linux-3.13.1-vs2.3.6.10/net/ipv4/inet_diag.c        2014-02-01 02:32:22.000000000 +0000
23801 @@ -31,6 +31,8 @@
23802  
23803  #include <linux/inet.h>
23804  #include <linux/stddef.h>
23805 +#include <linux/vs_network.h>
23806 +#include <linux/vs_inet.h>
23807  
23808  #include <linux/inet_diag.h>
23809  #include <linux/sock_diag.h>
23810 @@ -110,8 +112,10 @@ int inet_sk_diag_fill(struct sock *sk, s
23811         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23812         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23813  
23814 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
23815 -       r->id.idiag_dst[0] = inet->inet_daddr;
23816 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
23817 +               inet->inet_rcv_saddr);
23818 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
23819 +               inet->inet_daddr);
23820  
23821         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
23822                 goto errout;
23823 @@ -254,8 +258,8 @@ static int inet_twsk_diag_fill(struct in
23824         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23825         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23826  
23827 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
23828 -       r->id.idiag_dst[0]    = tw->tw_daddr;
23829 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
23830 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
23831  
23832         r->idiag_state        = tw->tw_substate;
23833         r->idiag_timer        = 3;
23834 @@ -298,12 +302,14 @@ int inet_diag_dump_one_icsk(struct inet_
23835  
23836         err = -EINVAL;
23837         if (req->sdiag_family == AF_INET) {
23838 +               /* TODO: lback */
23839                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
23840                                  req->id.idiag_dport, req->id.idiag_src[0],
23841                                  req->id.idiag_sport, req->id.idiag_if);
23842         }
23843  #if IS_ENABLED(CONFIG_IPV6)
23844         else if (req->sdiag_family == AF_INET6) {
23845 +               /* TODO: lback */
23846                 sk = inet6_lookup(net, hashinfo,
23847                                   (struct in6_addr *)req->id.idiag_dst,
23848                                   req->id.idiag_dport,
23849 @@ -501,6 +507,7 @@ int inet_diag_bc_sk(const struct nlattr
23850         } else
23851  #endif
23852         {
23853 +                       /* TODO: lback */
23854                 entry.saddr = &inet->inet_rcv_saddr;
23855                 entry.daddr = &inet->inet_daddr;
23856         }
23857 @@ -659,6 +666,7 @@ static int inet_twsk_diag_dump(struct so
23858                 } else
23859  #endif
23860                 {
23861 +                       /* TODO: lback */
23862                         entry.saddr = &tw->tw_rcv_saddr;
23863                         entry.daddr = &tw->tw_daddr;
23864                 }
23865 @@ -741,8 +749,8 @@ static int inet_diag_fill_req(struct sk_
23866         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23867         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23868  
23869 -       r->id.idiag_src[0] = ireq->ir_loc_addr;
23870 -       r->id.idiag_dst[0] = ireq->ir_rmt_addr;
23871 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_loc_addr);
23872 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_rmt_addr);
23873  
23874         r->idiag_expires = jiffies_to_msecs(tmo);
23875         r->idiag_rqueue = 0;
23876 @@ -806,6 +814,7 @@ static int inet_diag_dump_reqs(struct sk
23877                             r->id.idiag_dport)
23878                                 continue;
23879  
23880 +                       /* TODO: lback */
23881                         if (bc) {
23882                                 inet_diag_req_addrs(sk, req, &entry);
23883                                 entry.dport = ntohs(ireq->ir_rmt_port);
23884 @@ -862,6 +871,8 @@ void inet_diag_dump_icsk(struct inet_has
23885                                 if (!net_eq(sock_net(sk), net))
23886                                         continue;
23887  
23888 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23889 +                                       continue;
23890                                 if (num < s_num) {
23891                                         num++;
23892                                         continue;
23893 @@ -934,6 +945,8 @@ skip_listen_ht:
23894  
23895                         if (!net_eq(sock_net(sk), net))
23896                                 continue;
23897 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23898 +                               continue;
23899                         if (num < s_num)
23900                                 goto next_normal;
23901                         state = (sk->sk_state == TCP_TIME_WAIT) ?
23902 diff -NurpP --minimal linux-3.13.1/net/ipv4/inet_hashtables.c linux-3.13.1-vs2.3.6.10/net/ipv4/inet_hashtables.c
23903 --- linux-3.13.1/net/ipv4/inet_hashtables.c     2014-01-22 20:39:15.000000000 +0000
23904 +++ linux-3.13.1-vs2.3.6.10/net/ipv4/inet_hashtables.c  2014-01-31 20:38:04.000000000 +0000
23905 @@ -22,6 +22,7 @@
23906  #include <net/inet_connection_sock.h>
23907  #include <net/inet_hashtables.h>
23908  #include <net/secure_seq.h>
23909 +#include <net/route.h>
23910  #include <net/ip.h>
23911  
23912  static unsigned int inet_ehashfn(struct net *net, const __be32 laddr,
23913 @@ -181,6 +182,11 @@ static inline int compute_score(struct s
23914                         if (rcv_saddr != daddr)
23915                                 return -1;
23916                         score += 4;
23917 +               } else {
23918 +                       /* block non nx_info ips */
23919 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
23920 +                               daddr, NXA_MASK_BIND))
23921 +                               return -1;
23922                 }
23923                 if (sk->sk_bound_dev_if) {
23924                         if (sk->sk_bound_dev_if != dif)
23925 @@ -198,7 +204,6 @@ static inline int compute_score(struct s
23926   * wildcarded during the search since they can never be otherwise.
23927   */
23928  
23929 -
23930  struct sock *__inet_lookup_listener(struct net *net,
23931                                     struct inet_hashinfo *hashinfo,
23932                                     const __be32 saddr, __be16 sport,
23933 @@ -234,6 +239,7 @@ begin:
23934                         phash = next_pseudo_random32(phash);
23935                 }
23936         }
23937 +
23938         /*
23939          * if the nulls value we got at the end of this lookup is
23940          * not the expected one, we must restart lookup.
23941 diff -NurpP --minimal linux-3.13.1/net/ipv4/netfilter.c linux-3.13.1-vs2.3.6.10/net/ipv4/netfilter.c
23942 --- linux-3.13.1/net/ipv4/netfilter.c   2013-07-14 17:01:37.000000000 +0000
23943 +++ linux-3.13.1-vs2.3.6.10/net/ipv4/netfilter.c        2014-01-31 20:38:04.000000000 +0000
23944 @@ -11,7 +11,7 @@
23945  #include <linux/skbuff.h>
23946  #include <linux/gfp.h>
23947  #include <linux/export.h>
23948 -#include <net/route.h>
23949 +// #include <net/route.h>
23950  #include <net/xfrm.h>
23951  #include <net/ip.h>
23952  #include <net/netfilter/nf_queue.h>
23953 diff -NurpP --minimal linux-3.13.1/net/ipv4/raw.c linux-3.13.1-vs2.3.6.10/net/ipv4/raw.c
23954 --- linux-3.13.1/net/ipv4/raw.c 2014-01-22 20:39:15.000000000 +0000
23955 +++ linux-3.13.1-vs2.3.6.10/net/ipv4/raw.c      2014-01-31 20:38:04.000000000 +0000
23956 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
23957  
23958                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
23959                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
23960 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
23961 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
23962                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23963                         goto found; /* gotcha */
23964         }
23965 @@ -397,6 +397,12 @@ static int raw_send_hdrinc(struct sock *
23966                 icmp_out_count(net, ((struct icmphdr *)
23967                         skb_transport_header(skb))->type);
23968  
23969 +       err = -EPERM;
23970 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
23971 +               sk->sk_nx_info &&
23972 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
23973 +               goto error_free;
23974 +
23975         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
23976                       rt->dst.dev, dst_output);
23977         if (err > 0)
23978 @@ -585,6 +591,16 @@ static int raw_sendmsg(struct kiocb *ioc
23979                         goto done;
23980         }
23981  
23982 +       if (sk->sk_nx_info) {
23983 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
23984 +               if (IS_ERR(rt)) {
23985 +                       err = PTR_ERR(rt);
23986 +                       rt = NULL;
23987 +                       goto done;
23988 +               }
23989 +               ip_rt_put(rt);
23990 +       }
23991 +
23992         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
23993         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
23994         if (IS_ERR(rt)) {
23995 @@ -661,17 +677,19 @@ static int raw_bind(struct sock *sk, str
23996  {
23997         struct inet_sock *inet = inet_sk(sk);
23998         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
23999 +       struct nx_v4_sock_addr nsa = { 0 };
24000         int ret = -EINVAL;
24001         int chk_addr_ret;
24002  
24003         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24004                 goto out;
24005 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24006 +       v4_map_sock_addr(inet, addr, &nsa);
24007 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24008         ret = -EADDRNOTAVAIL;
24009 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24010 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24011             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24012                 goto out;
24013 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24014 +       v4_set_sock_addr(inet, &nsa);
24015         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24016                 inet->inet_saddr = 0;  /* Use device */
24017         sk_dst_reset(sk);
24018 @@ -720,7 +738,8 @@ static int raw_recvmsg(struct kiocb *ioc
24019         /* Copy the address. */
24020         if (sin) {
24021                 sin->sin_family = AF_INET;
24022 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24023 +               sin->sin_addr.s_addr =
24024 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24025                 sin->sin_port = 0;
24026                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24027                 *addr_len = sizeof(*sin);
24028 @@ -916,7 +935,8 @@ static struct sock *raw_get_first(struct
24029         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24030                         ++state->bucket) {
24031                 sk_for_each(sk, &state->h->ht[state->bucket])
24032 -                       if (sock_net(sk) == seq_file_net(seq))
24033 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24034 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24035                                 goto found;
24036         }
24037         sk = NULL;
24038 @@ -932,7 +952,8 @@ static struct sock *raw_get_next(struct
24039                 sk = sk_next(sk);
24040  try_again:
24041                 ;
24042 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24043 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24044 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24045  
24046         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24047                 sk = sk_head(&state->h->ht[state->bucket]);
24048 diff -NurpP --minimal linux-3.13.1/net/ipv4/route.c linux-3.13.1-vs2.3.6.10/net/ipv4/route.c
24049 --- linux-3.13.1/net/ipv4/route.c       2014-01-22 20:39:15.000000000 +0000
24050 +++ linux-3.13.1-vs2.3.6.10/net/ipv4/route.c    2014-01-31 20:38:04.000000000 +0000
24051 @@ -2063,7 +2063,7 @@ struct rtable *__ip_route_output_key(str
24052  
24053  
24054         if (fl4->flowi4_oif) {
24055 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24056 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24057                 rth = ERR_PTR(-ENODEV);
24058                 if (dev_out == NULL)
24059                         goto out;
24060 diff -NurpP --minimal linux-3.13.1/net/ipv4/tcp.c linux-3.13.1-vs2.3.6.10/net/ipv4/tcp.c
24061 --- linux-3.13.1/net/ipv4/tcp.c 2014-01-22 20:39:15.000000000 +0000
24062 +++ linux-3.13.1-vs2.3.6.10/net/ipv4/tcp.c      2014-01-31 20:38:04.000000000 +0000
24063 @@ -268,6 +268,7 @@
24064  #include <linux/crypto.h>
24065  #include <linux/time.h>
24066  #include <linux/slab.h>
24067 +#include <linux/in.h>
24068  
24069  #include <net/icmp.h>
24070  #include <net/inet_common.h>
24071 diff -NurpP --minimal linux-3.13.1/net/ipv4/tcp_ipv4.c linux-3.13.1-vs2.3.6.10/net/ipv4/tcp_ipv4.c
24072 --- linux-3.13.1/net/ipv4/tcp_ipv4.c    2014-01-22 20:39:15.000000000 +0000
24073 +++ linux-3.13.1-vs2.3.6.10/net/ipv4/tcp_ipv4.c 2014-02-01 12:30:30.000000000 +0000
24074 @@ -2227,6 +2227,12 @@ static void *listening_get_next(struct s
24075                 req = req->dl_next;
24076                 while (1) {
24077                         while (req) {
24078 +                               vxdprintk(VXD_CBIT(net, 6),
24079 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24080 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24081 +                               if (req->sk &&
24082 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24083 +                                       continue;
24084                                 if (req->rsk_ops->family == st->family) {
24085                                         cur = req;
24086                                         goto out;
24087 @@ -2251,6 +2257,10 @@ get_req:
24088         }
24089  get_sk:
24090         sk_nulls_for_each_from(sk, node) {
24091 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24092 +                       sk, sk->sk_nid, nx_current_nid());
24093 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24094 +                       continue;
24095                 if (!net_eq(sock_net(sk), net))
24096                         continue;
24097                 if (sk->sk_family == st->family) {
24098 @@ -2325,6 +2335,11 @@ static void *established_get_first(struc
24099  
24100                 spin_lock_bh(lock);
24101                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24102 +                       vxdprintk(VXD_CBIT(net, 6),
24103 +                               "sk,egf: %p [#%d] (from %d)",
24104 +                               sk, sk->sk_nid, nx_current_nid());
24105 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24106 +                               continue;
24107                         if (sk->sk_family != st->family ||
24108                             !net_eq(sock_net(sk), net)) {
24109                                 continue;
24110 @@ -2351,6 +2366,11 @@ static void *established_get_next(struct
24111         sk = sk_nulls_next(sk);
24112  
24113         sk_nulls_for_each_from(sk, node) {
24114 +               vxdprintk(VXD_CBIT(net, 6),
24115 +                       "sk,egn: %p [#%d] (from %d)",
24116 +                       sk, sk->sk_nid, nx_current_nid());
24117 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24118 +                       continue;
24119                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24120                         return sk;
24121         }
24122 @@ -2549,9 +2569,9 @@ static void get_openreq4(const struct so
24123         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24124                 " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d %pK",
24125                 i,
24126 -               ireq->ir_loc_addr,
24127 +               nx_map_sock_lback(current_nx_info(), ireq->ir_loc_addr),
24128                 ntohs(inet_sk(sk)->inet_sport),
24129 -               ireq->ir_rmt_addr,
24130 +               nx_map_sock_lback(current_nx_info(), ireq->ir_rmt_addr),
24131                 ntohs(ireq->ir_rmt_port),
24132                 TCP_SYN_RECV,
24133                 0, 0, /* could print option size, but that is af dependent. */
24134 @@ -2573,8 +2593,8 @@ static void get_tcp4_sock(struct sock *s
24135         const struct inet_connection_sock *icsk = inet_csk(sk);
24136         const struct inet_sock *inet = inet_sk(sk);
24137         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24138 -       __be32 dest = inet->inet_daddr;
24139 -       __be32 src = inet->inet_rcv_saddr;
24140 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24141 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24142         __u16 destp = ntohs(inet->inet_dport);
24143         __u16 srcp = ntohs(inet->inet_sport);
24144         int rx_queue;
24145 @@ -2631,8 +2651,8 @@ static void get_timewait4_sock(const str
24146         __u16 destp, srcp;
24147         long delta = tw->tw_ttd - jiffies;
24148  
24149 -       dest  = tw->tw_daddr;
24150 -       src   = tw->tw_rcv_saddr;
24151 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24152 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24153         destp = ntohs(tw->tw_dport);
24154         srcp  = ntohs(tw->tw_sport);
24155  
24156 diff -NurpP --minimal linux-3.13.1/net/ipv4/tcp_minisocks.c linux-3.13.1-vs2.3.6.10/net/ipv4/tcp_minisocks.c
24157 --- linux-3.13.1/net/ipv4/tcp_minisocks.c       2014-01-22 20:39:15.000000000 +0000
24158 +++ linux-3.13.1-vs2.3.6.10/net/ipv4/tcp_minisocks.c    2014-01-31 20:38:04.000000000 +0000
24159 @@ -23,6 +23,9 @@
24160  #include <linux/slab.h>
24161  #include <linux/sysctl.h>
24162  #include <linux/workqueue.h>
24163 +#include <linux/vs_limit.h>
24164 +#include <linux/vs_socket.h>
24165 +#include <linux/vs_context.h>
24166  #include <net/tcp.h>
24167  #include <net/inet_common.h>
24168  #include <net/xfrm.h>
24169 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int
24170                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24171                 tcptw->tw_ts_offset     = tp->tsoffset;
24172  
24173 +               tw->tw_xid              = sk->sk_xid;
24174 +               tw->tw_vx_info          = NULL;
24175 +               tw->tw_nid              = sk->sk_nid;
24176 +               tw->tw_nx_info          = NULL;
24177 +
24178  #if IS_ENABLED(CONFIG_IPV6)
24179                 if (tw->tw_family == PF_INET6) {
24180                         struct ipv6_pinfo *np = inet6_sk(sk);
24181 diff -NurpP --minimal linux-3.13.1/net/ipv4/udp.c linux-3.13.1-vs2.3.6.10/net/ipv4/udp.c
24182 --- linux-3.13.1/net/ipv4/udp.c 2014-01-22 20:39:15.000000000 +0000
24183 +++ linux-3.13.1-vs2.3.6.10/net/ipv4/udp.c      2014-01-31 22:20:27.000000000 +0000
24184 @@ -308,14 +308,7 @@ fail:
24185  }
24186  EXPORT_SYMBOL(udp_lib_get_port);
24187  
24188 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24189 -{
24190 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24191 -
24192 -       return  (!ipv6_only_sock(sk2)  &&
24193 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24194 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24195 -}
24196 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24197  
24198  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24199                                        unsigned int port)
24200 @@ -350,6 +343,11 @@ static inline int compute_score(struct s
24201                         if (inet->inet_rcv_saddr != daddr)
24202                                 return -1;
24203                         score += 4;
24204 +               } else {
24205 +                       /* block non nx_info ips */
24206 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24207 +                               daddr, NXA_MASK_BIND))
24208 +                               return -1;
24209                 }
24210                 if (inet->inet_daddr) {
24211                         if (inet->inet_daddr != saddr)
24212 @@ -472,6 +470,7 @@ begin:
24213         return result;
24214  }
24215  
24216 +
24217  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24218   * harder than this. -DaveM
24219   */
24220 @@ -518,6 +517,11 @@ begin:
24221         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24222                 score = compute_score(sk, net, saddr, hnum, sport,
24223                                       daddr, dport, dif);
24224 +               /* FIXME: disabled?
24225 +               if (score == 9) {
24226 +                       result = sk;
24227 +                       break;
24228 +               } else */
24229                 if (score > badness) {
24230                         result = sk;
24231                         badness = score;
24232 @@ -542,6 +546,7 @@ begin:
24233         if (get_nulls_value(node) != slot)
24234                 goto begin;
24235  
24236 +
24237         if (result) {
24238                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24239                         result = NULL;
24240 @@ -551,6 +556,7 @@ begin:
24241                         goto begin;
24242                 }
24243         }
24244 +
24245         rcu_read_unlock();
24246         return result;
24247  }
24248 @@ -585,7 +591,7 @@ static inline bool __udp_is_mcast_sock(s
24249             udp_sk(sk)->udp_port_hash != hnum ||
24250             (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24251             (inet->inet_dport != rmt_port && inet->inet_dport) ||
24252 -           (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||
24253 +           !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24254             ipv6_only_sock(sk) ||
24255             (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24256                 return false;
24257 @@ -989,6 +995,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24258                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24259                                    faddr, saddr, dport, inet->inet_sport);
24260  
24261 +               if (sk->sk_nx_info) {
24262 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24263 +                       if (IS_ERR(rt)) {
24264 +                               err = PTR_ERR(rt);
24265 +                               rt = NULL;
24266 +                               goto out;
24267 +                       }
24268 +                       ip_rt_put(rt);
24269 +               }
24270 +
24271                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24272                 rt = ip_route_output_flow(net, fl4, sk);
24273                 if (IS_ERR(rt)) {
24274 @@ -1293,7 +1309,8 @@ try_again:
24275         if (sin) {
24276                 sin->sin_family = AF_INET;
24277                 sin->sin_port = udp_hdr(skb)->source;
24278 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24279 +               sin->sin_addr.s_addr = nx_map_sock_lback(
24280 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24281                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24282                 *addr_len = sizeof(*sin);
24283         }
24284 @@ -2223,6 +2240,8 @@ static struct sock *udp_get_first(struct
24285                 sk_nulls_for_each(sk, node, &hslot->head) {
24286                         if (!net_eq(sock_net(sk), net))
24287                                 continue;
24288 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24289 +                               continue;
24290                         if (sk->sk_family == state->family)
24291                                 goto found;
24292                 }
24293 @@ -2240,7 +2259,9 @@ static struct sock *udp_get_next(struct
24294  
24295         do {
24296                 sk = sk_nulls_next(sk);
24297 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
24298 +       } while (sk && (!net_eq(sock_net(sk), net) ||
24299 +               sk->sk_family != state->family ||
24300 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24301  
24302         if (!sk) {
24303                 if (state->bucket <= state->udp_table->mask)
24304 @@ -2336,8 +2357,8 @@ static void udp4_format_sock(struct sock
24305                 int bucket)
24306  {
24307         struct inet_sock *inet = inet_sk(sp);
24308 -       __be32 dest = inet->inet_daddr;
24309 -       __be32 src  = inet->inet_rcv_saddr;
24310 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24311 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24312         __u16 destp       = ntohs(inet->inet_dport);
24313         __u16 srcp        = ntohs(inet->inet_sport);
24314  
24315 diff -NurpP --minimal linux-3.13.1/net/ipv6/Kconfig linux-3.13.1-vs2.3.6.10/net/ipv6/Kconfig
24316 --- linux-3.13.1/net/ipv6/Kconfig       2014-01-22 20:39:15.000000000 +0000
24317 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/Kconfig    2014-01-31 20:38:04.000000000 +0000
24318 @@ -4,8 +4,8 @@
24319  
24320  #   IPv6 as module will cause a CRASH if you try to unload it
24321  menuconfig IPV6
24322 -       tristate "The IPv6 protocol"
24323 -       default m
24324 +       bool "The IPv6 protocol"
24325 +       default n
24326         ---help---
24327           This is complemental support for the IP version 6.
24328           You will still be able to do traditional IPv4 networking as well.
24329 diff -NurpP --minimal linux-3.13.1/net/ipv6/addrconf.c linux-3.13.1-vs2.3.6.10/net/ipv6/addrconf.c
24330 --- linux-3.13.1/net/ipv6/addrconf.c    2014-01-22 20:39:15.000000000 +0000
24331 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/addrconf.c 2014-01-31 20:38:04.000000000 +0000
24332 @@ -90,6 +90,8 @@
24333  #include <linux/proc_fs.h>
24334  #include <linux/seq_file.h>
24335  #include <linux/export.h>
24336 +#include <linux/vs_network.h>
24337 +#include <linux/vs_inet6.h>
24338  
24339  /* Set to 3 to get tracing... */
24340  #define ACONF_DEBUG 2
24341 @@ -1281,7 +1283,7 @@ out:
24342  
24343  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
24344                        const struct in6_addr *daddr, unsigned int prefs,
24345 -                      struct in6_addr *saddr)
24346 +                      struct in6_addr *saddr, struct nx_info *nxi)
24347  {
24348         struct ipv6_saddr_score scores[2],
24349                                 *score = &scores[0], *hiscore = &scores[1];
24350 @@ -1353,6 +1355,8 @@ int ipv6_dev_get_saddr(struct net *net,
24351                                                dev->name);
24352                                 continue;
24353                         }
24354 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
24355 +                               continue;
24356  
24357                         score->rule = -1;
24358                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
24359 @@ -3366,7 +3370,10 @@ static void if6_seq_stop(struct seq_file
24360  static int if6_seq_show(struct seq_file *seq, void *v)
24361  {
24362         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
24363 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24364 +
24365 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
24366 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
24367 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24368                    &ifp->addr,
24369                    ifp->idev->dev->ifindex,
24370                    ifp->prefix_len,
24371 @@ -3887,6 +3894,11 @@ static int in6_dump_addrs(struct inet6_d
24372         struct ifacaddr6 *ifaca;
24373         int err = 1;
24374         int ip_idx = *p_ip_idx;
24375 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24376 +
24377 +       /* disable ipv6 on non v6 guests */
24378 +       if (nxi && !nx_info_has_v6(nxi))
24379 +               return skb->len;
24380  
24381         read_lock_bh(&idev->lock);
24382         switch (type) {
24383 @@ -3897,6 +3909,8 @@ static int in6_dump_addrs(struct inet6_d
24384                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
24385                         if (++ip_idx < s_ip_idx)
24386                                 continue;
24387 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
24388 +                                       continue;
24389                         err = inet6_fill_ifaddr(skb, ifa,
24390                                                 NETLINK_CB(cb->skb).portid,
24391                                                 cb->nlh->nlmsg_seq,
24392 @@ -3914,6 +3928,8 @@ static int in6_dump_addrs(struct inet6_d
24393                      ifmca = ifmca->next, ip_idx++) {
24394                         if (ip_idx < s_ip_idx)
24395                                 continue;
24396 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
24397 +                                       continue;
24398                         err = inet6_fill_ifmcaddr(skb, ifmca,
24399                                                   NETLINK_CB(cb->skb).portid,
24400                                                   cb->nlh->nlmsg_seq,
24401 @@ -3929,6 +3945,8 @@ static int in6_dump_addrs(struct inet6_d
24402                      ifaca = ifaca->aca_next, ip_idx++) {
24403                         if (ip_idx < s_ip_idx)
24404                                 continue;
24405 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
24406 +                                       continue;
24407                         err = inet6_fill_ifacaddr(skb, ifaca,
24408                                                   NETLINK_CB(cb->skb).portid,
24409                                                   cb->nlh->nlmsg_seq,
24410 @@ -3957,6 +3975,10 @@ static int inet6_dump_addr(struct sk_buf
24411         struct inet6_dev *idev;
24412         struct hlist_head *head;
24413  
24414 +       /* FIXME: maybe disable ipv6 on non v6 guests?
24415 +       if (skb->sk && skb->sk->sk_vx_info)
24416 +               return skb->len; */
24417 +
24418         s_h = cb->args[0];
24419         s_idx = idx = cb->args[1];
24420         s_ip_idx = ip_idx = cb->args[2];
24421 @@ -4399,6 +4421,7 @@ static int inet6_dump_ifinfo(struct sk_b
24422         struct net_device *dev;
24423         struct inet6_dev *idev;
24424         struct hlist_head *head;
24425 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24426  
24427         s_h = cb->args[0];
24428         s_idx = cb->args[1];
24429 @@ -4410,6 +4433,8 @@ static int inet6_dump_ifinfo(struct sk_b
24430                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24431                         if (idx < s_idx)
24432                                 goto cont;
24433 +                       if (!v6_dev_in_nx_info(dev, nxi))
24434 +                               goto cont;
24435                         idev = __in6_dev_get(dev);
24436                         if (!idev)
24437                                 goto cont;
24438 diff -NurpP --minimal linux-3.13.1/net/ipv6/af_inet6.c linux-3.13.1-vs2.3.6.10/net/ipv6/af_inet6.c
24439 --- linux-3.13.1/net/ipv6/af_inet6.c    2014-01-22 20:39:15.000000000 +0000
24440 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/af_inet6.c 2014-01-31 21:39:03.000000000 +0000
24441 @@ -43,6 +43,8 @@
24442  #include <linux/netdevice.h>
24443  #include <linux/icmpv6.h>
24444  #include <linux/netfilter_ipv6.h>
24445 +#include <linux/vs_inet.h>
24446 +#include <linux/vs_inet6.h>
24447  
24448  #include <net/ip.h>
24449  #include <net/ipv6.h>
24450 @@ -156,10 +158,13 @@ lookup_protocol:
24451         }
24452  
24453         err = -EPERM;
24454 +       if ((protocol == IPPROTO_ICMPV6) &&
24455 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24456 +               goto override;
24457         if (sock->type == SOCK_RAW && !kern &&
24458             !ns_capable(net->user_ns, CAP_NET_RAW))
24459                 goto out_rcu_unlock;
24460 -
24461 +override:
24462         sock->ops = answer->ops;
24463         answer_prot = answer->prot;
24464         answer_no_check = answer->no_check;
24465 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
24466         struct inet_sock *inet = inet_sk(sk);
24467         struct ipv6_pinfo *np = inet6_sk(sk);
24468         struct net *net = sock_net(sk);
24469 +       struct nx_v6_sock_addr nsa;
24470         __be32 v4addr = 0;
24471         unsigned short snum;
24472         int addr_type = 0;
24473 @@ -274,6 +280,10 @@ int inet6_bind(struct socket *sock, stru
24474         if (addr->sin6_family != AF_INET6)
24475                 return -EAFNOSUPPORT;
24476  
24477 +       err = v6_map_sock_addr(inet, addr, &nsa);
24478 +       if (err)
24479 +               return err;
24480 +
24481         addr_type = ipv6_addr_type(&addr->sin6_addr);
24482         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
24483                 return -EINVAL;
24484 @@ -305,6 +315,7 @@ int inet6_bind(struct socket *sock, stru
24485                 /* Reproduce AF_INET checks to make the bindings consistent */
24486                 v4addr = addr->sin6_addr.s6_addr32[3];
24487                 chk_addr_ret = inet_addr_type(net, v4addr);
24488 +
24489                 if (!sysctl_ip_nonlocal_bind &&
24490                     !(inet->freebind || inet->transparent) &&
24491                     v4addr != htonl(INADDR_ANY) &&
24492 @@ -314,6 +325,10 @@ int inet6_bind(struct socket *sock, stru
24493                         err = -EADDRNOTAVAIL;
24494                         goto out;
24495                 }
24496 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
24497 +                       err = -EADDRNOTAVAIL;
24498 +                       goto out;
24499 +               }
24500         } else {
24501                 if (addr_type != IPV6_ADDR_ANY) {
24502                         struct net_device *dev = NULL;
24503 @@ -340,6 +355,11 @@ int inet6_bind(struct socket *sock, stru
24504                                 }
24505                         }
24506  
24507 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24508 +                               err = -EADDRNOTAVAIL;
24509 +                               goto out_unlock;
24510 +                       }
24511 +
24512                         /* ipv4 addr of the socket is invalid.  Only the
24513                          * unspecified and mapped address have a v4 equivalent.
24514                          */
24515 @@ -356,6 +376,9 @@ int inet6_bind(struct socket *sock, stru
24516                 }
24517         }
24518  
24519 +       /* what's that for? */
24520 +       v6_set_sock_addr(inet, &nsa);
24521 +
24522         inet->inet_rcv_saddr = v4addr;
24523         inet->inet_saddr = v4addr;
24524  
24525 @@ -457,9 +480,11 @@ int inet6_getname(struct socket *sock, s
24526                         return -ENOTCONN;
24527                 sin->sin6_port = inet->inet_dport;
24528                 sin->sin6_addr = sk->sk_v6_daddr;
24529 +               /* FIXME: remap lback? */
24530                 if (np->sndflow)
24531                         sin->sin6_flowinfo = np->flow_label;
24532         } else {
24533 +               /* FIXME: remap lback? */
24534                 if (ipv6_addr_any(&sk->sk_v6_rcv_saddr))
24535                         sin->sin6_addr = np->saddr;
24536                 else
24537 diff -NurpP --minimal linux-3.13.1/net/ipv6/datagram.c linux-3.13.1-vs2.3.6.10/net/ipv6/datagram.c
24538 --- linux-3.13.1/net/ipv6/datagram.c    2014-01-22 20:39:15.000000000 +0000
24539 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/datagram.c 2014-01-31 20:38:04.000000000 +0000
24540 @@ -655,7 +655,7 @@ int ip6_datagram_send_ctl(struct net *ne
24541  
24542                         rcu_read_lock();
24543                         if (fl6->flowi6_oif) {
24544 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
24545 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
24546                                 if (!dev) {
24547                                         rcu_read_unlock();
24548                                         return -ENODEV;
24549 diff -NurpP --minimal linux-3.13.1/net/ipv6/fib6_rules.c linux-3.13.1-vs2.3.6.10/net/ipv6/fib6_rules.c
24550 --- linux-3.13.1/net/ipv6/fib6_rules.c  2014-01-22 20:39:15.000000000 +0000
24551 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/fib6_rules.c       2014-01-31 20:38:04.000000000 +0000
24552 @@ -97,7 +97,7 @@ static int fib6_rule_action(struct fib_r
24553                                                ip6_dst_idev(&rt->dst)->dev,
24554                                                &flp6->daddr,
24555                                                rt6_flags2srcprefs(flags),
24556 -                                              &saddr))
24557 +                                              &saddr, NULL))
24558                                 goto again;
24559                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
24560                                                r->src.plen))
24561 diff -NurpP --minimal linux-3.13.1/net/ipv6/inet6_hashtables.c linux-3.13.1-vs2.3.6.10/net/ipv6/inet6_hashtables.c
24562 --- linux-3.13.1/net/ipv6/inet6_hashtables.c    2014-01-22 20:39:15.000000000 +0000
24563 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/inet6_hashtables.c 2014-01-31 20:38:04.000000000 +0000
24564 @@ -16,6 +16,7 @@
24565  
24566  #include <linux/module.h>
24567  #include <linux/random.h>
24568 +#include <linux/vs_inet6.h>
24569  
24570  #include <net/inet_connection_sock.h>
24571  #include <net/inet_hashtables.h>
24572 @@ -116,7 +117,6 @@ struct sock *__inet6_lookup_established(
24573         unsigned int slot = hash & hashinfo->ehash_mask;
24574         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
24575  
24576 -
24577         rcu_read_lock();
24578  begin:
24579         sk_nulls_for_each_rcu(sk, node, &head->chain) {
24580 @@ -158,6 +158,9 @@ static inline int compute_score(struct s
24581                         if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24582                                 return -1;
24583                         score++;
24584 +               } else {
24585 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24586 +                               return -1;
24587                 }
24588                 if (sk->sk_bound_dev_if) {
24589                         if (sk->sk_bound_dev_if != dif)
24590 diff -NurpP --minimal linux-3.13.1/net/ipv6/ip6_fib.c linux-3.13.1-vs2.3.6.10/net/ipv6/ip6_fib.c
24591 --- linux-3.13.1/net/ipv6/ip6_fib.c     2014-01-22 20:39:15.000000000 +0000
24592 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/ip6_fib.c  2014-01-31 21:48:35.000000000 +0000
24593 @@ -1779,6 +1779,7 @@ static int ipv6_route_seq_show(struct se
24594         struct rt6_info *rt = v;
24595         struct ipv6_route_iter *iter = seq->private;
24596  
24597 +       /* FIXME: check for network context? */
24598         seq_printf(seq, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
24599  
24600  #ifdef CONFIG_IPV6_SUBTREES
24601 diff -NurpP --minimal linux-3.13.1/net/ipv6/ip6_output.c linux-3.13.1-vs2.3.6.10/net/ipv6/ip6_output.c
24602 --- linux-3.13.1/net/ipv6/ip6_output.c  2014-01-22 20:39:15.000000000 +0000
24603 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/ip6_output.c       2014-01-31 20:38:04.000000000 +0000
24604 @@ -859,7 +859,8 @@ static int ip6_dst_lookup_tail(struct so
24605                 struct rt6_info *rt = (struct rt6_info *) *dst;
24606                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
24607                                           sk ? inet6_sk(sk)->srcprefs : 0,
24608 -                                         &fl6->saddr);
24609 +                                         &fl6->saddr,
24610 +                                         sk ? sk->sk_nx_info : NULL);
24611                 if (err)
24612                         goto out_err_release;
24613         }
24614 diff -NurpP --minimal linux-3.13.1/net/ipv6/ndisc.c linux-3.13.1-vs2.3.6.10/net/ipv6/ndisc.c
24615 --- linux-3.13.1/net/ipv6/ndisc.c       2014-01-22 20:39:15.000000000 +0000
24616 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/ndisc.c    2014-01-31 20:38:04.000000000 +0000
24617 @@ -486,7 +486,7 @@ void ndisc_send_na(struct net_device *de
24618         } else {
24619                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
24620                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
24621 -                                      &tmpaddr))
24622 +                                      &tmpaddr, NULL))
24623                         return;
24624                 src_addr = &tmpaddr;
24625         }
24626 diff -NurpP --minimal linux-3.13.1/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.13.1-vs2.3.6.10/net/ipv6/netfilter/ip6t_MASQUERADE.c
24627 --- linux-3.13.1/net/ipv6/netfilter/ip6t_MASQUERADE.c   2013-11-25 15:47:07.000000000 +0000
24628 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/netfilter/ip6t_MASQUERADE.c        2014-01-31 20:38:04.000000000 +0000
24629 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
24630                             ctinfo == IP_CT_RELATED_REPLY));
24631  
24632         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
24633 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
24634 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
24635                 return NF_DROP;
24636  
24637         nfct_nat(ct)->masq_index = par->out->ifindex;
24638 diff -NurpP --minimal linux-3.13.1/net/ipv6/raw.c linux-3.13.1-vs2.3.6.10/net/ipv6/raw.c
24639 --- linux-3.13.1/net/ipv6/raw.c 2014-01-22 20:39:15.000000000 +0000
24640 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/raw.c      2014-01-31 20:38:04.000000000 +0000
24641 @@ -30,6 +30,7 @@
24642  #include <linux/icmpv6.h>
24643  #include <linux/netfilter.h>
24644  #include <linux/netfilter_ipv6.h>
24645 +#include <linux/vs_inet6.h>
24646  #include <linux/skbuff.h>
24647  #include <linux/compat.h>
24648  #include <asm/uaccess.h>
24649 @@ -287,6 +288,13 @@ static int rawv6_bind(struct sock *sk, s
24650                                 goto out_unlock;
24651                 }
24652  
24653 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24654 +                       err = -EADDRNOTAVAIL;
24655 +                       if (dev)
24656 +                               dev_put(dev);
24657 +                       goto out;
24658 +               }
24659 +
24660                 /* ipv4 addr of the socket is invalid.  Only the
24661                  * unspecified and mapped address have a v4 equivalent.
24662                  */
24663 diff -NurpP --minimal linux-3.13.1/net/ipv6/route.c linux-3.13.1-vs2.3.6.10/net/ipv6/route.c
24664 --- linux-3.13.1/net/ipv6/route.c       2014-01-22 20:39:15.000000000 +0000
24665 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/route.c    2014-01-31 20:38:04.000000000 +0000
24666 @@ -58,6 +58,7 @@
24667  #include <net/netevent.h>
24668  #include <net/netlink.h>
24669  #include <net/nexthop.h>
24670 +#include <linux/vs_inet6.h>
24671  
24672  #include <asm/uaccess.h>
24673  
24674 @@ -2196,15 +2197,17 @@ int ip6_route_get_saddr(struct net *net,
24675                         struct rt6_info *rt,
24676                         const struct in6_addr *daddr,
24677                         unsigned int prefs,
24678 -                       struct in6_addr *saddr)
24679 +                       struct in6_addr *saddr,
24680 +                       struct nx_info *nxi)
24681  {
24682         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
24683         int err = 0;
24684 -       if (rt->rt6i_prefsrc.plen)
24685 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
24686 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
24687                 *saddr = rt->rt6i_prefsrc.addr;
24688         else
24689                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
24690 -                                        daddr, prefs, saddr);
24691 +                                        daddr, prefs, saddr, nxi);
24692         return err;
24693  }
24694  
24695 @@ -2624,7 +2627,8 @@ static int rt6_fill_node(struct net *net
24696                                 goto nla_put_failure;
24697         } else if (dst) {
24698                 struct in6_addr saddr_buf;
24699 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
24700 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
24701 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
24702                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
24703                         goto nla_put_failure;
24704         }
24705 diff -NurpP --minimal linux-3.13.1/net/ipv6/tcp_ipv6.c linux-3.13.1-vs2.3.6.10/net/ipv6/tcp_ipv6.c
24706 --- linux-3.13.1/net/ipv6/tcp_ipv6.c    2014-01-22 20:39:15.000000000 +0000
24707 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/tcp_ipv6.c 2014-01-31 20:38:04.000000000 +0000
24708 @@ -72,6 +72,7 @@
24709  
24710  #include <linux/crypto.h>
24711  #include <linux/scatterlist.h>
24712 +#include <linux/vs_inet6.h>
24713  
24714  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
24715  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
24716 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
24717          *      connect() to INADDR_ANY means loopback (BSD'ism).
24718          */
24719  
24720 -       if(ipv6_addr_any(&usin->sin6_addr))
24721 -               usin->sin6_addr.s6_addr[15] = 0x1;
24722 +       if(ipv6_addr_any(&usin->sin6_addr)) {
24723 +               struct nx_info *nxi =  sk->sk_nx_info;
24724 +
24725 +               if (nxi && nx_info_has_v6(nxi))
24726 +                       /* FIXME: remap lback? */
24727 +                       usin->sin6_addr = nxi->v6.ip;
24728 +               else
24729 +                       usin->sin6_addr.s6_addr[15] = 0x1;
24730 +       }
24731  
24732         addr_type = ipv6_addr_type(&usin->sin6_addr);
24733  
24734 diff -NurpP --minimal linux-3.13.1/net/ipv6/udp.c linux-3.13.1-vs2.3.6.10/net/ipv6/udp.c
24735 --- linux-3.13.1/net/ipv6/udp.c 2014-01-22 20:39:15.000000000 +0000
24736 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/udp.c      2014-02-01 02:33:38.000000000 +0000
24737 @@ -47,6 +47,7 @@
24738  #include <net/xfrm.h>
24739  #include <net/inet6_hashtables.h>
24740  #include <net/busy_poll.h>
24741 +#include <linux/vs_inet6.h>
24742  
24743  #include <linux/proc_fs.h>
24744  #include <linux/seq_file.h>
24745 @@ -76,33 +77,61 @@ static unsigned int udp6_ehashfn(struct
24746                                udp_ipv6_hash_secret + net_hash_mix(net));
24747  }
24748  
24749 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
24750 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24751  {
24752 +       const struct in6_addr *sk1_rcv_saddr6 = inet6_rcv_saddr(sk1);
24753         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
24754 -       int sk_ipv6only = ipv6_only_sock(sk);
24755 +       __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr;
24756 +       __be32 sk2_rcv_saddr = sk2->sk_rcv_saddr;
24757 +       int sk1_ipv6only = ipv6_only_sock(sk1);
24758         int sk2_ipv6only = inet_v6_ipv6only(sk2);
24759 -       int addr_type = ipv6_addr_type(&sk->sk_v6_rcv_saddr);
24760 +       int addr_type1 = ipv6_addr_type(sk1_rcv_saddr6);
24761         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
24762  
24763         /* if both are mapped, treat as IPv4 */
24764 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
24765 -               return (!sk2_ipv6only &&
24766 -                       (!sk->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24767 -                         sk->sk_rcv_saddr == sk2->sk_rcv_saddr));
24768 +       if (addr_type1 == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
24769 +               if (!sk2_ipv6only &&
24770 +                       (!sk1->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24771 +                         sk1->sk_rcv_saddr == sk2->sk_rcv_saddr))
24772 +                       goto vs_v4;
24773 +               else
24774 +                       return 0;
24775 +       }
24776  
24777         if (addr_type2 == IPV6_ADDR_ANY &&
24778 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
24779 -               return 1;
24780 +           !(sk2_ipv6only && addr_type1 == IPV6_ADDR_MAPPED))
24781 +               goto vs;
24782  
24783 -       if (addr_type == IPV6_ADDR_ANY &&
24784 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24785 -               return 1;
24786 +       if (addr_type1 == IPV6_ADDR_ANY &&
24787 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24788 +               goto vs;
24789  
24790         if (sk2_rcv_saddr6 &&
24791 -           ipv6_addr_equal(&sk->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24792 -               return 1;
24793 +           ipv6_addr_equal(&sk1->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24794 +               goto vs;
24795  
24796         return 0;
24797 +
24798 +vs_v4:
24799 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
24800 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24801 +       if (!sk2_rcv_saddr)
24802 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
24803 +       if (!sk1_rcv_saddr)
24804 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
24805 +       return 1;
24806 +vs:
24807 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type1 == IPV6_ADDR_ANY)
24808 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24809 +       else if (addr_type2 == IPV6_ADDR_ANY)
24810 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
24811 +       else if (addr_type1 == IPV6_ADDR_ANY) {
24812 +               if (addr_type2 == IPV6_ADDR_MAPPED)
24813 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24814 +               else
24815 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
24816 +       }
24817 +       return 1;
24818  }
24819  
24820  static unsigned int udp6_portaddr_hash(struct net *net,
24821 @@ -160,6 +189,10 @@ static inline int compute_score(struct s
24822                         if (inet->inet_dport != sport)
24823                                 return -1;
24824                         score++;
24825 +               } else {
24826 +                       /* block non nx_info ips */
24827 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24828 +                               return -1;
24829                 }
24830                 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
24831                         if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24832 diff -NurpP --minimal linux-3.13.1/net/ipv6/xfrm6_policy.c linux-3.13.1-vs2.3.6.10/net/ipv6/xfrm6_policy.c
24833 --- linux-3.13.1/net/ipv6/xfrm6_policy.c        2014-01-22 20:39:15.000000000 +0000
24834 +++ linux-3.13.1-vs2.3.6.10/net/ipv6/xfrm6_policy.c     2014-01-31 20:38:04.000000000 +0000
24835 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
24836         dev = ip6_dst_idev(dst)->dev;
24837         ipv6_dev_get_saddr(dev_net(dev), dev,
24838                            (struct in6_addr *)&daddr->a6, 0,
24839 -                          (struct in6_addr *)&saddr->a6);
24840 +                          (struct in6_addr *)&saddr->a6, NULL);
24841         dst_release(dst);
24842         return 0;
24843  }
24844 diff -NurpP --minimal linux-3.13.1/net/netfilter/ipvs/ip_vs_xmit.c linux-3.13.1-vs2.3.6.10/net/netfilter/ipvs/ip_vs_xmit.c
24845 --- linux-3.13.1/net/netfilter/ipvs/ip_vs_xmit.c        2013-11-25 15:47:07.000000000 +0000
24846 +++ linux-3.13.1-vs2.3.6.10/net/netfilter/ipvs/ip_vs_xmit.c     2014-01-31 20:38:04.000000000 +0000
24847 @@ -316,7 +316,7 @@ __ip_vs_route_output_v6(struct net *net,
24848                 return dst;
24849         if (ipv6_addr_any(&fl6.saddr) &&
24850             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
24851 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
24852 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
24853                 goto out_err;
24854         if (do_xfrm) {
24855                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
24856 diff -NurpP --minimal linux-3.13.1/net/netlink/af_netlink.c linux-3.13.1-vs2.3.6.10/net/netlink/af_netlink.c
24857 --- linux-3.13.1/net/netlink/af_netlink.c       2014-01-22 20:39:16.000000000 +0000
24858 +++ linux-3.13.1-vs2.3.6.10/net/netlink/af_netlink.c    2014-02-01 02:35:17.000000000 +0000
24859 @@ -58,6 +58,9 @@
24860  #include <linux/mutex.h>
24861  #include <linux/vmalloc.h>
24862  #include <linux/if_arp.h>
24863 +#include <linux/vs_context.h>
24864 +#include <linux/vs_network.h>
24865 +#include <linux/vs_limit.h>
24866  #include <asm/cacheflush.h>
24867  
24868  #include <net/net_namespace.h>
24869 @@ -2850,6 +2853,8 @@ static struct sock *netlink_seq_socket_i
24870                         sk_for_each(s, &hash->table[j]) {
24871                                 if (sock_net(s) != seq_file_net(seq))
24872                                         continue;
24873 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
24874 +                                       continue;
24875                                 if (off == pos) {
24876                                         iter->link = i;
24877                                         iter->hash_idx = j;
24878 @@ -2886,7 +2891,8 @@ static void *netlink_seq_next(struct seq
24879         s = v;
24880         do {
24881                 s = sk_next(s);
24882 -       } while (s && !nl_table[s->sk_protocol].compare(net, s));
24883 +       } while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24884 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
24885         if (s)
24886                 return s;
24887  
24888 @@ -2899,7 +2905,8 @@ static void *netlink_seq_next(struct seq
24889                 for (; j <= hash->mask; j++) {
24890                         s = sk_head(&hash->table[j]);
24891  
24892 -                       while (s && !nl_table[s->sk_protocol].compare(net, s))
24893 +                       while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24894 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
24895                                 s = sk_next(s);
24896                         if (s) {
24897                                 iter->link = i;
24898 diff -NurpP --minimal linux-3.13.1/net/socket.c linux-3.13.1-vs2.3.6.10/net/socket.c
24899 --- linux-3.13.1/net/socket.c   2014-01-22 20:39:17.000000000 +0000
24900 +++ linux-3.13.1-vs2.3.6.10/net/socket.c        2014-02-01 12:32:53.000000000 +0000
24901 @@ -98,6 +98,9 @@
24902  
24903  #include <net/sock.h>
24904  #include <linux/netfilter.h>
24905 +#include <linux/vs_socket.h>
24906 +#include <linux/vs_inet.h>
24907 +#include <linux/vs_inet6.h>
24908  
24909  #include <linux/if_tun.h>
24910  #include <linux/ipv6_route.h>
24911 @@ -623,13 +626,29 @@ static inline int __sock_sendmsg_nosec(s
24912                                        struct msghdr *msg, size_t size)
24913  {
24914         struct sock_iocb *si = kiocb_to_siocb(iocb);
24915 +       size_t len;
24916  
24917         si->sock = sock;
24918         si->scm = NULL;
24919         si->msg = msg;
24920         si->size = size;
24921  
24922 -       return sock->ops->sendmsg(iocb, sock, msg, size);
24923 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
24924 +       if (sock->sk) {
24925 +               if (len == size)
24926 +                       vx_sock_send(sock->sk, size);
24927 +               else
24928 +                       vx_sock_fail(sock->sk, size);
24929 +       }
24930 +       vxdprintk(VXD_CBIT(net, 7),
24931 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
24932 +               sock, sock->sk,
24933 +               (sock->sk)?sock->sk->sk_nx_info:0,
24934 +               (sock->sk)?sock->sk->sk_vx_info:0,
24935 +               (sock->sk)?sock->sk->sk_xid:0,
24936 +               (sock->sk)?sock->sk->sk_nid:0,
24937 +               (unsigned int)size, len);
24938 +       return len;
24939  }
24940  
24941  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
24942 @@ -773,6 +792,7 @@ static inline int __sock_recvmsg_nosec(s
24943                                        struct msghdr *msg, size_t size, int flags)
24944  {
24945         struct sock_iocb *si = kiocb_to_siocb(iocb);
24946 +       int len;
24947  
24948         si->sock = sock;
24949         si->scm = NULL;
24950 @@ -780,7 +800,18 @@ static inline int __sock_recvmsg_nosec(s
24951         si->size = size;
24952         si->flags = flags;
24953  
24954 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
24955 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
24956 +       if ((len >= 0) && sock->sk)
24957 +               vx_sock_recv(sock->sk, len);
24958 +       vxdprintk(VXD_CBIT(net, 7),
24959 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
24960 +               sock, sock->sk,
24961 +               (sock->sk)?sock->sk->sk_nx_info:0,
24962 +               (sock->sk)?sock->sk->sk_vx_info:0,
24963 +               (sock->sk)?sock->sk->sk_xid:0,
24964 +               (sock->sk)?sock->sk->sk_nid:0,
24965 +               (unsigned int)size, len);
24966 +       return len;
24967  }
24968  
24969  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
24970 @@ -1256,6 +1287,13 @@ int __sock_create(struct net *net, int f
24971         if (type < 0 || type >= SOCK_MAX)
24972                 return -EINVAL;
24973  
24974 +       if (!nx_check(0, VS_ADMIN)) {
24975 +               if (family == PF_INET && !current_nx_info_has_v4())
24976 +                       return -EAFNOSUPPORT;
24977 +               if (family == PF_INET6 && !current_nx_info_has_v6())
24978 +                       return -EAFNOSUPPORT;
24979 +       }
24980 +
24981         /* Compatibility.
24982  
24983            This uglymoron is moved from INET layer to here to avoid
24984 @@ -1390,6 +1428,7 @@ SYSCALL_DEFINE3(socket, int, family, int
24985         if (retval < 0)
24986                 goto out;
24987  
24988 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
24989         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
24990         if (retval < 0)
24991                 goto out_release;
24992 @@ -1431,10 +1470,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
24993         err = sock_create(family, type, protocol, &sock1);
24994         if (err < 0)
24995                 goto out;
24996 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
24997  
24998         err = sock_create(family, type, protocol, &sock2);
24999         if (err < 0)
25000                 goto out_release_1;
25001 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25002  
25003         err = sock1->ops->socketpair(sock1, sock2);
25004         if (err < 0)
25005 diff -NurpP --minimal linux-3.13.1/net/sunrpc/auth.c linux-3.13.1-vs2.3.6.10/net/sunrpc/auth.c
25006 --- linux-3.13.1/net/sunrpc/auth.c      2013-11-25 15:47:08.000000000 +0000
25007 +++ linux-3.13.1-vs2.3.6.10/net/sunrpc/auth.c   2014-01-31 20:38:04.000000000 +0000
25008 @@ -15,6 +15,7 @@
25009  #include <linux/sunrpc/clnt.h>
25010  #include <linux/sunrpc/gss_api.h>
25011  #include <linux/spinlock.h>
25012 +#include <linux/vs_tag.h>
25013  
25014  #ifdef RPC_DEBUG
25015  # define RPCDBG_FACILITY       RPCDBG_AUTH
25016 @@ -586,6 +587,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25017         memset(&acred, 0, sizeof(acred));
25018         acred.uid = cred->fsuid;
25019         acred.gid = cred->fsgid;
25020 +       acred.tag = make_ktag(&init_user_ns, dx_current_tag());
25021         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25022  
25023         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25024 @@ -626,6 +628,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25025         struct auth_cred acred = {
25026                 .uid = GLOBAL_ROOT_UID,
25027                 .gid = GLOBAL_ROOT_GID,
25028 +               .tag = KTAGT_INIT(dx_current_tag()),
25029         };
25030  
25031         dprintk("RPC: %5u looking up %s cred\n",
25032 diff -NurpP --minimal linux-3.13.1/net/sunrpc/auth_unix.c linux-3.13.1-vs2.3.6.10/net/sunrpc/auth_unix.c
25033 --- linux-3.13.1/net/sunrpc/auth_unix.c 2013-11-25 15:47:08.000000000 +0000
25034 +++ linux-3.13.1-vs2.3.6.10/net/sunrpc/auth_unix.c      2014-01-31 20:38:04.000000000 +0000
25035 @@ -13,11 +13,13 @@
25036  #include <linux/sunrpc/clnt.h>
25037  #include <linux/sunrpc/auth.h>
25038  #include <linux/user_namespace.h>
25039 +#include <linux/vs_tag.h>
25040  
25041  #define NFS_NGROUPS    16
25042  
25043  struct unx_cred {
25044         struct rpc_cred         uc_base;
25045 +       ktag_t                  uc_tag;
25046         kgid_t                  uc_gid;
25047         kgid_t                  uc_gids[NFS_NGROUPS];
25048  };
25049 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25050                 groups = NFS_NGROUPS;
25051  
25052         cred->uc_gid = acred->gid;
25053 +       cred->uc_tag = acred->tag;
25054         for (i = 0; i < groups; i++)
25055                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25056         if (i < NFS_NGROUPS)
25057 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25058         unsigned int i;
25059  
25060  
25061 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25062 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
25063 +           !gid_eq(cred->uc_gid, acred->gid) ||
25064 +           !tag_eq(cred->uc_tag, acred->tag))
25065                 return 0;
25066  
25067         if (acred->group_info != NULL)
25068 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25069         struct rpc_clnt *clnt = task->tk_client;
25070         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25071         __be32          *base, *hold;
25072 -       int             i;
25073 +       int             i, tag;
25074  
25075         *p++ = htonl(RPC_AUTH_UNIX);
25076         base = p++;
25077 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
25078          */
25079         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25080  
25081 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25082 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25083 +       tag = task->tk_client->cl_tag;
25084 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
25085 +               TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
25086 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
25087 +               TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
25088         hold = p++;
25089         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25090                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25091 diff -NurpP --minimal linux-3.13.1/net/sunrpc/clnt.c linux-3.13.1-vs2.3.6.10/net/sunrpc/clnt.c
25092 --- linux-3.13.1/net/sunrpc/clnt.c      2014-01-22 20:39:17.000000000 +0000
25093 +++ linux-3.13.1-vs2.3.6.10/net/sunrpc/clnt.c   2014-01-31 21:38:13.000000000 +0000
25094 @@ -31,6 +31,7 @@
25095  #include <linux/in.h>
25096  #include <linux/in6.h>
25097  #include <linux/un.h>
25098 +#include <linux/vs_cvirt.h>
25099  
25100  #include <linux/sunrpc/clnt.h>
25101  #include <linux/sunrpc/addr.h>
25102 @@ -538,6 +539,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25103         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25104                 clnt->cl_chatty = 1;
25105  
25106 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25107 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25108 +               clnt->cl_tag = 1; */
25109         return clnt;
25110  }
25111  EXPORT_SYMBOL_GPL(rpc_create);
25112 diff -NurpP --minimal linux-3.13.1/net/unix/af_unix.c linux-3.13.1-vs2.3.6.10/net/unix/af_unix.c
25113 --- linux-3.13.1/net/unix/af_unix.c     2014-01-22 20:39:17.000000000 +0000
25114 +++ linux-3.13.1-vs2.3.6.10/net/unix/af_unix.c  2014-01-31 22:42:26.000000000 +0000
25115 @@ -115,6 +115,8 @@
25116  #include <net/checksum.h>
25117  #include <linux/security.h>
25118  #include <linux/freezer.h>
25119 +#include <linux/vs_context.h>
25120 +#include <linux/vs_limit.h>
25121  
25122  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25123  EXPORT_SYMBOL_GPL(unix_socket_table);
25124 @@ -271,6 +273,8 @@ static struct sock *__unix_find_socket_b
25125                 if (!net_eq(sock_net(s), net))
25126                         continue;
25127  
25128 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25129 +                       continue;
25130                 if (u->addr->len == len &&
25131                     !memcmp(u->addr->name, sunname, len))
25132                         goto found;
25133 @@ -2269,6 +2273,8 @@ static struct sock *unix_from_bucket(str
25134         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25135                 if (sock_net(sk) != seq_file_net(seq))
25136                         continue;
25137 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25138 +                       continue;
25139                 if (++count == offset)
25140                         break;
25141         }
25142 @@ -2286,6 +2292,8 @@ static struct sock *unix_next_socket(str
25143                 sk = sk_next(sk);
25144                 if (!sk)
25145                         goto next_bucket;
25146 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25147 +                       continue;
25148                 if (sock_net(sk) == seq_file_net(seq))
25149                         return sk;
25150         }
25151 diff -NurpP --minimal linux-3.13.1/scripts/checksyscalls.sh linux-3.13.1-vs2.3.6.10/scripts/checksyscalls.sh
25152 --- linux-3.13.1/scripts/checksyscalls.sh       2012-12-11 03:30:57.000000000 +0000
25153 +++ linux-3.13.1-vs2.3.6.10/scripts/checksyscalls.sh    2014-01-31 20:38:04.000000000 +0000
25154 @@ -193,7 +193,6 @@ cat << EOF
25155  #define __IGNORE_afs_syscall
25156  #define __IGNORE_getpmsg
25157  #define __IGNORE_putpmsg
25158 -#define __IGNORE_vserver
25159  EOF
25160  }
25161  
25162 diff -NurpP --minimal linux-3.13.1/security/commoncap.c linux-3.13.1-vs2.3.6.10/security/commoncap.c
25163 --- linux-3.13.1/security/commoncap.c   2013-11-25 15:47:08.000000000 +0000
25164 +++ linux-3.13.1-vs2.3.6.10/security/commoncap.c        2014-01-31 20:38:04.000000000 +0000
25165 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25166  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25167                 int cap, int audit)
25168  {
25169 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25170         struct user_namespace *ns = targ_ns;
25171  
25172         /* See if cred has the capability in the target user namespace
25173 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25174          */
25175         for (;;) {
25176                 /* Do we have the necessary capabilities? */
25177 -               if (ns == cred->user_ns)
25178 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25179 +               if (ns == cred->user_ns) {
25180 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25181 +                           cap_raised(cred->cap_effective, cap))
25182 +                               return 0;
25183 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25184 +               }
25185  
25186                 /* Have we tried all of the parent namespaces? */
25187                 if (ns == &init_user_ns)
25188 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25189  
25190         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25191                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25192 -           !capable(CAP_SYS_ADMIN))
25193 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25194                 return -EPERM;
25195         return 0;
25196  }
25197 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25198  
25199         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25200                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25201 -           !capable(CAP_SYS_ADMIN))
25202 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25203                 return -EPERM;
25204         return 0;
25205  }
25206 diff -NurpP --minimal linux-3.13.1/security/selinux/hooks.c linux-3.13.1-vs2.3.6.10/security/selinux/hooks.c
25207 --- linux-3.13.1/security/selinux/hooks.c       2014-01-22 20:39:21.000000000 +0000
25208 +++ linux-3.13.1-vs2.3.6.10/security/selinux/hooks.c    2014-01-31 20:38:04.000000000 +0000
25209 @@ -68,7 +68,6 @@
25210  #include <linux/dccp.h>
25211  #include <linux/quota.h>
25212  #include <linux/un.h>          /* for Unix socket types */
25213 -#include <net/af_unix.h>       /* for Unix socket types */
25214  #include <linux/parser.h>
25215  #include <linux/nfs_mount.h>
25216  #include <net/ipv6.h>
This page took 2.109703 seconds and 4 git commands to generate.