]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- fix vserver patch for 3.14.5
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.13.10/Documentation/vserver/debug.txt linux-3.13.10-vs2.3.6.11/Documentation/vserver/debug.txt
2 --- linux-3.13.10/Documentation/vserver/debug.txt       1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.13.10-vs2.3.6.11/Documentation/vserver/debug.txt    2014-01-31 20:38:03.000000000 +0000
4 @@ -0,0 +1,154 @@
5 +
6 +debug_cvirt:
7 +
8 + 2   4 "vx_map_tgid: %p/%llx: %d -> %d"
9 +       "vx_rmap_tgid: %p/%llx: %d -> %d"
10 +
11 +debug_dlim:
12 +
13 + 0   1 "ALLOC (%p,#%d)%c inode (%d)"
14 +       "FREE  (%p,#%d)%c inode"
15 + 1   2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
16 +       "FREE  (%p,#%d)%c %lld bytes"
17 + 2   4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
18 + 3   8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
19 +       "ext3_has_free_blocks(%p): free=%lu, root=%lu"
20 +       "rcu_free_dl_info(%p)"
21 + 4  10 "alloc_dl_info(%p,%d) = %p"
22 +       "dealloc_dl_info(%p)"
23 +       "get_dl_info(%p[#%d.%d])"
24 +       "put_dl_info(%p[#%d.%d])"
25 + 5  20 "alloc_dl_info(%p,%d)*"
26 + 6  40 "__hash_dl_info: %p[#%d]"
27 +       "__unhash_dl_info: %p[#%d]"
28 + 7  80 "locate_dl_info(%p,#%d) = %p"
29 +
30 +debug_misc:
31 +
32 + 0   1 "destroy_dqhash: %p [#0x%08x] c=%d"
33 +       "new_dqhash: %p [#0x%08x]"
34 +       "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
35 +       "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
36 +       "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
37 +       "vroot_get_real_bdev not set"
38 + 1   2 "cow_break_link(»%s«)"
39 +       "temp copy »%s«"
40 + 2   4 "dentry_open(new): %p"
41 +       "dentry_open(old): %p"
42 +       "lookup_create(new): %p"
43 +       "old path »%s«"
44 +       "path_lookup(old): %d"
45 +       "vfs_create(new): %d"
46 +       "vfs_rename: %d"
47 +       "vfs_sendfile: %d"
48 + 3   8 "fput(new_file=%p[#%d])"
49 +       "fput(old_file=%p[#%d])"
50 + 4  10 "vx_info_kill(%p[#%d],%d,%d) = %d"
51 +       "vx_info_kill(%p[#%d],%d,%d)*"
52 + 5  20 "vs_reboot(%p[#%d],%d)"
53 + 6  40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
54 +
55 +debug_net:
56 +
57 + 2   4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
58 + 3   8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
59 +       "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
60 + 4  10 "ip_route_connect(%p) %p,%p;%lx"
61 + 5  20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
62 + 6  40 "sk,egf: %p [#%d] (from %d)"
63 +       "sk,egn: %p [#%d] (from %d)"
64 +       "sk,req: %p [#%d] (from %d)"
65 +       "sk: %p [#%d] (from %d)"
66 +       "tw: %p [#%d] (from %d)"
67 + 7  80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
68 +       "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
69 +
70 +debug_nid:
71 +
72 + 0   1 "__lookup_nx_info(#%u): %p[#%u]"
73 +       "alloc_nx_info(%d) = %p"
74 +       "create_nx_info(%d) (dynamic rejected)"
75 +       "create_nx_info(%d) = %p (already there)"
76 +       "create_nx_info(%d) = %p (new)"
77 +       "dealloc_nx_info(%p)"
78 + 1   2 "alloc_nx_info(%d)*"
79 +       "create_nx_info(%d)*"
80 + 2   4 "get_nx_info(%p[#%d.%d])"
81 +       "put_nx_info(%p[#%d.%d])"
82 + 3   8 "claim_nx_info(%p[#%d.%d.%d]) %p"
83 +       "clr_nx_info(%p[#%d.%d])"
84 +       "init_nx_info(%p[#%d.%d])"
85 +       "release_nx_info(%p[#%d.%d.%d]) %p"
86 +       "set_nx_info(%p[#%d.%d])"
87 + 4  10 "__hash_nx_info: %p[#%d]"
88 +       "__nx_dynamic_id: [#%d]"
89 +       "__unhash_nx_info: %p[#%d.%d.%d]"
90 + 5  20 "moved task %p into nxi:%p[#%d]"
91 +       "nx_migrate_task(%p,%p[#%d.%d.%d])"
92 +       "task_get_nx_info(%p)"
93 + 6  40 "nx_clear_persistent(%p[#%d])"
94 +
95 +debug_quota:
96 +
97 + 0   1 "quota_sync_dqh(%p,%d) discard inode %p"
98 + 1   2 "quota_sync_dqh(%p,%d)"
99 +       "sync_dquots(%p,%d)"
100 +       "sync_dquots_dqh(%p,%d)"
101 + 3   8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
102 +
103 +debug_switch:
104 +
105 + 0   1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
106 + 1   2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
107 + 4  10 "%s: (%s %s) returned %s with %d"
108 +
109 +debug_tag:
110 +
111 + 7  80 "dx_parse_tag(»%s«): %d:#%d"
112 +       "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
113 +
114 +debug_xid:
115 +
116 + 0   1 "__lookup_vx_info(#%u): %p[#%u]"
117 +       "alloc_vx_info(%d) = %p"
118 +       "alloc_vx_info(%d)*"
119 +       "create_vx_info(%d) (dynamic rejected)"
120 +       "create_vx_info(%d) = %p (already there)"
121 +       "create_vx_info(%d) = %p (new)"
122 +       "dealloc_vx_info(%p)"
123 +       "loc_vx_info(%d) = %p (found)"
124 +       "loc_vx_info(%d) = %p (new)"
125 +       "loc_vx_info(%d) = %p (not available)"
126 + 1   2 "create_vx_info(%d)*"
127 +       "loc_vx_info(%d)*"
128 + 2   4 "get_vx_info(%p[#%d.%d])"
129 +       "put_vx_info(%p[#%d.%d])"
130 + 3   8 "claim_vx_info(%p[#%d.%d.%d]) %p"
131 +       "clr_vx_info(%p[#%d.%d])"
132 +       "init_vx_info(%p[#%d.%d])"
133 +       "release_vx_info(%p[#%d.%d.%d]) %p"
134 +       "set_vx_info(%p[#%d.%d])"
135 + 4  10 "__hash_vx_info: %p[#%d]"
136 +       "__unhash_vx_info: %p[#%d.%d.%d]"
137 +       "__vx_dynamic_id: [#%d]"
138 + 5  20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
139 +       "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
140 +       "moved task %p into vxi:%p[#%d]"
141 +       "task_get_vx_info(%p)"
142 +       "vx_migrate_task(%p,%p[#%d.%d])"
143 + 6  40 "vx_clear_persistent(%p[#%d])"
144 +       "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
145 +       "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
146 +       "vx_set_persistent(%p[#%d])"
147 +       "vx_set_reaper(%p[#%d],%p[#%d,%d])"
148 + 7  80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
149 +
150 +
151 +debug_limit:
152 +
153 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
154 +       "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
155 +
156 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
157 +       "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
158 +       "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
159 diff -NurpP --minimal linux-3.13.10/arch/alpha/Kconfig linux-3.13.10-vs2.3.6.11/arch/alpha/Kconfig
160 --- linux-3.13.10/arch/alpha/Kconfig    2014-01-22 20:38:09.000000000 +0000
161 +++ linux-3.13.10-vs2.3.6.11/arch/alpha/Kconfig 2014-01-31 20:38:03.000000000 +0000
162 @@ -735,6 +735,8 @@ config DUMMY_CONSOLE
163         depends on VGA_HOSE
164         default y
165  
166 +source "kernel/vserver/Kconfig"
167 +
168  source "security/Kconfig"
169  
170  source "crypto/Kconfig"
171 diff -NurpP --minimal linux-3.13.10/arch/alpha/kernel/systbls.S linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/systbls.S
172 --- linux-3.13.10/arch/alpha/kernel/systbls.S   2013-11-25 15:44:11.000000000 +0000
173 +++ linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/systbls.S        2014-01-31 20:38:03.000000000 +0000
174 @@ -446,7 +446,7 @@ sys_call_table:
175         .quad sys_stat64                        /* 425 */
176         .quad sys_lstat64
177         .quad sys_fstat64
178 -       .quad sys_ni_syscall                    /* sys_vserver */
179 +       .quad sys_vserver                       /* sys_vserver */
180         .quad sys_ni_syscall                    /* sys_mbind */
181         .quad sys_ni_syscall                    /* sys_get_mempolicy */
182         .quad sys_ni_syscall                    /* sys_set_mempolicy */
183 diff -NurpP --minimal linux-3.13.10/arch/alpha/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/traps.c
184 --- linux-3.13.10/arch/alpha/kernel/traps.c     2014-01-22 20:38:10.000000000 +0000
185 +++ linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/traps.c  2014-01-31 20:38:03.000000000 +0000
186 @@ -175,7 +175,8 @@ die_if_kernel(char * str, struct pt_regs
187  #ifdef CONFIG_SMP
188         printk("CPU %d ", hard_smp_processor_id());
189  #endif
190 -       printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
191 +       printk("%s(%d:#%u): %s %ld\n", current->comm,
192 +               task_pid_nr(current), current->xid, str, err);
193         dik_show_regs(regs, r9_15);
194         add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
195         dik_show_trace((unsigned long *)(regs+1));
196 diff -NurpP --minimal linux-3.13.10/arch/arm/Kconfig linux-3.13.10-vs2.3.6.11/arch/arm/Kconfig
197 --- linux-3.13.10/arch/arm/Kconfig      2014-04-17 01:12:06.000000000 +0000
198 +++ linux-3.13.10-vs2.3.6.11/arch/arm/Kconfig   2014-04-17 01:17:10.000000000 +0000
199 @@ -2267,6 +2267,8 @@ source "fs/Kconfig"
200  
201  source "arch/arm/Kconfig.debug"
202  
203 +source "kernel/vserver/Kconfig"
204 +
205  source "security/Kconfig"
206  
207  source "crypto/Kconfig"
208 diff -NurpP --minimal linux-3.13.10/arch/arm/kernel/calls.S linux-3.13.10-vs2.3.6.11/arch/arm/kernel/calls.S
209 --- linux-3.13.10/arch/arm/kernel/calls.S       2013-05-31 13:44:29.000000000 +0000
210 +++ linux-3.13.10-vs2.3.6.11/arch/arm/kernel/calls.S    2014-01-31 20:38:03.000000000 +0000
211 @@ -322,7 +322,7 @@
212  /* 310 */      CALL(sys_request_key)
213                 CALL(sys_keyctl)
214                 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
215 -/* vserver */  CALL(sys_ni_syscall)
216 +               CALL(sys_vserver)
217                 CALL(sys_ioprio_set)
218  /* 315 */      CALL(sys_ioprio_get)
219                 CALL(sys_inotify_init)
220 diff -NurpP --minimal linux-3.13.10/arch/arm/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/arm/kernel/traps.c
221 --- linux-3.13.10/arch/arm/kernel/traps.c       2014-01-22 20:38:11.000000000 +0000
222 +++ linux-3.13.10-vs2.3.6.11/arch/arm/kernel/traps.c    2014-01-31 20:38:03.000000000 +0000
223 @@ -247,8 +247,8 @@ static int __die(const char *str, int er
224  
225         print_modules();
226         __show_regs(regs);
227 -       printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
228 -               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), end_of_stack(tsk));
229 +       printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
230 +               TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, end_of_stack(tsk));
231  
232         if (!user_mode(regs) || in_interrupt()) {
233                 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
234 diff -NurpP --minimal linux-3.13.10/arch/cris/Kconfig linux-3.13.10-vs2.3.6.11/arch/cris/Kconfig
235 --- linux-3.13.10/arch/cris/Kconfig     2014-01-22 20:38:15.000000000 +0000
236 +++ linux-3.13.10-vs2.3.6.11/arch/cris/Kconfig  2014-01-31 20:38:03.000000000 +0000
237 @@ -561,6 +561,8 @@ source "fs/Kconfig"
238  
239  source "arch/cris/Kconfig.debug"
240  
241 +source "kernel/vserver/Kconfig"
242 +
243  source "security/Kconfig"
244  
245  source "crypto/Kconfig"
246 diff -NurpP --minimal linux-3.13.10/arch/ia64/Kconfig linux-3.13.10-vs2.3.6.11/arch/ia64/Kconfig
247 --- linux-3.13.10/arch/ia64/Kconfig     2014-01-22 20:38:16.000000000 +0000
248 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/Kconfig  2014-01-31 20:38:03.000000000 +0000
249 @@ -641,6 +641,8 @@ source "fs/Kconfig"
250  
251  source "arch/ia64/Kconfig.debug"
252  
253 +source "kernel/vserver/Kconfig"
254 +
255  source "security/Kconfig"
256  
257  source "crypto/Kconfig"
258 diff -NurpP --minimal linux-3.13.10/arch/ia64/kernel/entry.S linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/entry.S
259 --- linux-3.13.10/arch/ia64/kernel/entry.S      2014-01-22 20:38:16.000000000 +0000
260 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/entry.S   2014-01-31 20:38:03.000000000 +0000
261 @@ -1706,7 +1706,7 @@ sys_call_table:
262         data8 sys_mq_notify
263         data8 sys_mq_getsetattr
264         data8 sys_kexec_load
265 -       data8 sys_ni_syscall                    // reserved for vserver
266 +       data8 sys_vserver
267         data8 sys_waitid                        // 1270
268         data8 sys_add_key
269         data8 sys_request_key
270 diff -NurpP --minimal linux-3.13.10/arch/ia64/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/ptrace.c
271 --- linux-3.13.10/arch/ia64/kernel/ptrace.c     2013-02-19 13:56:51.000000000 +0000
272 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/ptrace.c  2014-01-31 20:38:03.000000000 +0000
273 @@ -21,6 +21,7 @@
274  #include <linux/regset.h>
275  #include <linux/elf.h>
276  #include <linux/tracehook.h>
277 +#include <linux/vs_base.h>
278  
279  #include <asm/pgtable.h>
280  #include <asm/processor.h>
281 diff -NurpP --minimal linux-3.13.10/arch/ia64/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/traps.c
282 --- linux-3.13.10/arch/ia64/kernel/traps.c      2013-11-25 15:44:20.000000000 +0000
283 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/traps.c   2014-01-31 20:38:03.000000000 +0000
284 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
285         put_cpu();
286  
287         if (++die.lock_owner_depth < 3) {
288 -               printk("%s[%d]: %s %ld [%d]\n",
289 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
290 +               printk("%s[%d:#%u]: %s %ld [%d]\n",
291 +                       current->comm, task_pid_nr(current), current->xid,
292 +                       str, err, ++die_counter);
293                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
294                     != NOTIFY_STOP)
295                         show_regs(regs);
296 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
297                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
298                                 last.time = current_jiffies + 5 * HZ;
299                                 printk(KERN_WARNING
300 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
301 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
302 +                                       "%s(%d:#%u): floating-point assist fault at ip %016lx, isr %016lx\n",
303 +                                       current->comm, task_pid_nr(current), current->xid,
304 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
305                         }
306                 }
307         }
308 diff -NurpP --minimal linux-3.13.10/arch/m32r/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/m32r/kernel/traps.c
309 --- linux-3.13.10/arch/m32r/kernel/traps.c      2013-07-14 17:00:26.000000000 +0000
310 +++ linux-3.13.10-vs2.3.6.11/arch/m32r/kernel/traps.c   2014-01-31 20:38:03.000000000 +0000
311 @@ -184,8 +184,9 @@ static void show_registers(struct pt_reg
312         } else {
313                 printk("SPI: %08lx\n", sp);
314         }
315 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
316 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
317 +       printk("Process %s (pid: %d:#%u, process nr: %d, stackpage=%08lx)",
318 +               current->comm, task_pid_nr(current), current->xid,
319 +               0xffff & i, 4096+(unsigned long)current);
320  
321         /*
322          * When in-kernel, we also print out the stack and code at the
323 diff -NurpP --minimal linux-3.13.10/arch/m68k/Kconfig linux-3.13.10-vs2.3.6.11/arch/m68k/Kconfig
324 --- linux-3.13.10/arch/m68k/Kconfig     2014-04-17 01:12:07.000000000 +0000
325 +++ linux-3.13.10-vs2.3.6.11/arch/m68k/Kconfig  2014-04-17 01:17:10.000000000 +0000
326 @@ -135,6 +135,8 @@ source "fs/Kconfig"
327  
328  source "arch/m68k/Kconfig.debug"
329  
330 +source "kernel/vserver/Kconfig"
331 +
332  source "security/Kconfig"
333  
334  source "crypto/Kconfig"
335 diff -NurpP --minimal linux-3.13.10/arch/mips/Kconfig linux-3.13.10-vs2.3.6.11/arch/mips/Kconfig
336 --- linux-3.13.10/arch/mips/Kconfig     2014-01-22 20:38:16.000000000 +0000
337 +++ linux-3.13.10-vs2.3.6.11/arch/mips/Kconfig  2014-01-31 20:38:03.000000000 +0000
338 @@ -2539,6 +2539,8 @@ source "fs/Kconfig"
339  
340  source "arch/mips/Kconfig.debug"
341  
342 +source "kernel/vserver/Kconfig"
343 +
344  source "security/Kconfig"
345  
346  source "crypto/Kconfig"
347 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/arch/mips/kernel/ptrace.c
348 --- linux-3.13.10/arch/mips/kernel/ptrace.c     2014-01-22 20:38:17.000000000 +0000
349 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/ptrace.c  2014-01-31 20:53:13.000000000 +0000
350 @@ -30,6 +30,7 @@
351  #include <linux/audit.h>
352  #include <linux/seccomp.h>
353  #include <linux/ftrace.h>
354 +#include <linux/vs_base.h>
355  
356  #include <asm/byteorder.h>
357  #include <asm/cpu.h>
358 @@ -398,6 +399,9 @@ long arch_ptrace(struct task_struct *chi
359         void __user *datavp = (void __user *) data;
360         unsigned long __user *datalp = (void __user *) data;
361  
362 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
363 +               goto out;
364 +
365         switch (request) {
366         /* when I and D space are separate, these will need to be fixed. */
367         case PTRACE_PEEKTEXT: /* read word at location addr. */
368 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/scall32-o32.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall32-o32.S
369 --- linux-3.13.10/arch/mips/kernel/scall32-o32.S        2014-01-22 20:38:17.000000000 +0000
370 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall32-o32.S     2014-01-31 20:48:18.000000000 +0000
371 @@ -491,7 +491,7 @@ EXPORT(sys_call_table)
372         PTR     sys_mq_timedreceive
373         PTR     sys_mq_notify                   /* 4275 */
374         PTR     sys_mq_getsetattr
375 -       PTR     sys_ni_syscall                  /* sys_vserver */
376 +       PTR     sys_vserver
377         PTR     sys_waitid
378         PTR     sys_ni_syscall                  /* available, was setaltroot */
379         PTR     sys_add_key                     /* 4280 */
380 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/scall64-64.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-64.S
381 --- linux-3.13.10/arch/mips/kernel/scall64-64.S 2014-01-22 20:38:17.000000000 +0000
382 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-64.S      2014-01-31 20:38:03.000000000 +0000
383 @@ -352,7 +352,7 @@ EXPORT(sys_call_table)
384         PTR     sys_mq_timedreceive
385         PTR     sys_mq_notify
386         PTR     sys_mq_getsetattr               /* 5235 */
387 -       PTR     sys_ni_syscall                  /* sys_vserver */
388 +       PTR     sys_vserver
389         PTR     sys_waitid
390         PTR     sys_ni_syscall                  /* available, was setaltroot */
391         PTR     sys_add_key
392 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/scall64-n32.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-n32.S
393 --- linux-3.13.10/arch/mips/kernel/scall64-n32.S        2014-01-22 20:38:17.000000000 +0000
394 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-n32.S     2014-01-31 20:38:03.000000000 +0000
395 @@ -345,7 +345,7 @@ EXPORT(sysn32_call_table)
396         PTR     compat_sys_mq_timedreceive
397         PTR     compat_sys_mq_notify
398         PTR     compat_sys_mq_getsetattr
399 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
400 +       PTR     sys32_vserver                   /* 6240 */
401         PTR     compat_sys_waitid
402         PTR     sys_ni_syscall                  /* available, was setaltroot */
403         PTR     sys_add_key
404 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/scall64-o32.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-o32.S
405 --- linux-3.13.10/arch/mips/kernel/scall64-o32.S        2014-01-22 20:38:17.000000000 +0000
406 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-o32.S     2014-01-31 20:38:03.000000000 +0000
407 @@ -469,7 +469,7 @@ EXPORT(sys32_call_table)
408         PTR     compat_sys_mq_timedreceive
409         PTR     compat_sys_mq_notify            /* 4275 */
410         PTR     compat_sys_mq_getsetattr
411 -       PTR     sys_ni_syscall                  /* sys_vserver */
412 +       PTR     sys32_vserver
413         PTR     compat_sys_waitid
414         PTR     sys_ni_syscall                  /* available, was setaltroot */
415         PTR     sys_add_key                     /* 4280 */
416 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/mips/kernel/traps.c
417 --- linux-3.13.10/arch/mips/kernel/traps.c      2014-01-22 20:38:17.000000000 +0000
418 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/traps.c   2014-01-31 20:38:03.000000000 +0000
419 @@ -334,9 +334,10 @@ void show_registers(struct pt_regs *regs
420  
421         __show_regs(regs);
422         print_modules();
423 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
424 -              current->comm, current->pid, current_thread_info(), current,
425 -             field, current_thread_info()->tp_value);
426 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
427 +               current->comm, task_pid_nr(current), current->xid,
428 +               current_thread_info(), current,
429 +               field, current_thread_info()->tp_value);
430         if (cpu_has_userlocal) {
431                 unsigned long tls;
432  
433 diff -NurpP --minimal linux-3.13.10/arch/parisc/Kconfig linux-3.13.10-vs2.3.6.11/arch/parisc/Kconfig
434 --- linux-3.13.10/arch/parisc/Kconfig   2014-01-22 20:38:18.000000000 +0000
435 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/Kconfig        2014-01-31 20:38:03.000000000 +0000
436 @@ -320,6 +320,8 @@ source "fs/Kconfig"
437  
438  source "arch/parisc/Kconfig.debug"
439  
440 +source "kernel/vserver/Kconfig"
441 +
442  source "security/Kconfig"
443  
444  source "crypto/Kconfig"
445 diff -NurpP --minimal linux-3.13.10/arch/parisc/kernel/syscall_table.S linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/syscall_table.S
446 --- linux-3.13.10/arch/parisc/kernel/syscall_table.S    2013-07-14 17:00:31.000000000 +0000
447 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/syscall_table.S 2014-01-31 20:38:03.000000000 +0000
448 @@ -358,7 +358,7 @@
449         ENTRY_COMP(mbind)               /* 260 */
450         ENTRY_COMP(get_mempolicy)
451         ENTRY_COMP(set_mempolicy)
452 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
453 +       ENTRY_DIFF(vserver)
454         ENTRY_SAME(add_key)
455         ENTRY_SAME(request_key)         /* 265 */
456         ENTRY_SAME(keyctl)
457 diff -NurpP --minimal linux-3.13.10/arch/parisc/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/traps.c
458 --- linux-3.13.10/arch/parisc/kernel/traps.c    2013-11-25 15:46:28.000000000 +0000
459 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
460 @@ -229,8 +229,9 @@ void die_if_kernel(char *str, struct pt_
461                 if (err == 0)
462                         return; /* STFU */
463  
464 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
465 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
466 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
467 +                       current->comm, task_pid_nr(current), current->xid,
468 +                       str, err, regs->iaoq[0]);
469  #ifdef PRINT_USER_FAULTS
470                 /* XXX for debugging only */
471                 show_regs(regs);
472 @@ -263,8 +264,8 @@ void die_if_kernel(char *str, struct pt_
473                 pdc_console_restart();
474         
475         if (err)
476 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
477 -                       current->comm, task_pid_nr(current), str, err);
478 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
479 +                       current->comm, task_pid_nr(current), current->xid, str, err);
480  
481         /* Wot's wrong wif bein' racy? */
482         if (current->thread.flags & PARISC_KERNEL_DEATH) {
483 diff -NurpP --minimal linux-3.13.10/arch/parisc/mm/fault.c linux-3.13.10-vs2.3.6.11/arch/parisc/mm/fault.c
484 --- linux-3.13.10/arch/parisc/mm/fault.c        2014-01-22 20:38:18.000000000 +0000
485 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/mm/fault.c     2014-01-31 20:38:03.000000000 +0000
486 @@ -272,8 +272,9 @@ bad_area:
487  
488  #ifdef PRINT_USER_FAULTS
489                 printk(KERN_DEBUG "\n");
490 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
491 -                   task_pid_nr(tsk), tsk->comm, code, address);
492 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
493 +                   "command='%s' type=%lu address=0x%08lx\n",
494 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
495                 if (vma) {
496                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
497                                         vma->vm_start, vma->vm_end);
498 diff -NurpP --minimal linux-3.13.10/arch/powerpc/Kconfig linux-3.13.10-vs2.3.6.11/arch/powerpc/Kconfig
499 --- linux-3.13.10/arch/powerpc/Kconfig  2014-01-22 20:38:18.000000000 +0000
500 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/Kconfig       2014-01-31 20:38:03.000000000 +0000
501 @@ -1028,6 +1028,8 @@ source "lib/Kconfig"
502  
503  source "arch/powerpc/Kconfig.debug"
504  
505 +source "kernel/vserver/Kconfig"
506 +
507  source "security/Kconfig"
508  
509  config KEYS_COMPAT
510 diff -NurpP --minimal linux-3.13.10/arch/powerpc/include/uapi/asm/unistd.h linux-3.13.10-vs2.3.6.11/arch/powerpc/include/uapi/asm/unistd.h
511 --- linux-3.13.10/arch/powerpc/include/uapi/asm/unistd.h        2013-05-31 13:44:44.000000000 +0000
512 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/include/uapi/asm/unistd.h     2014-01-31 20:38:03.000000000 +0000
513 @@ -275,7 +275,7 @@
514  #endif
515  #define __NR_rtas              255
516  #define __NR_sys_debug_setcontext 256
517 -/* Number 257 is reserved for vserver */
518 +#define __NR_vserver           257
519  #define __NR_migrate_pages     258
520  #define __NR_mbind             259
521  #define __NR_get_mempolicy     260
522 diff -NurpP --minimal linux-3.13.10/arch/powerpc/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/powerpc/kernel/traps.c
523 --- linux-3.13.10/arch/powerpc/kernel/traps.c   2014-01-22 20:38:23.000000000 +0000
524 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/kernel/traps.c        2014-01-31 20:38:03.000000000 +0000
525 @@ -1272,8 +1272,9 @@ void nonrecoverable_exception(struct pt_
526  
527  void trace_syscall(struct pt_regs *regs)
528  {
529 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
530 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
531 +       printk("Task: %p(%d:#%u), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
532 +              current, task_pid_nr(current), current->xid,
533 +              regs->nip, regs->link, regs->gpr[0],
534                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
535  }
536  
537 diff -NurpP --minimal linux-3.13.10/arch/s390/Kconfig linux-3.13.10-vs2.3.6.11/arch/s390/Kconfig
538 --- linux-3.13.10/arch/s390/Kconfig     2014-04-17 01:12:08.000000000 +0000
539 +++ linux-3.13.10-vs2.3.6.11/arch/s390/Kconfig  2014-04-17 01:17:10.000000000 +0000
540 @@ -650,6 +650,8 @@ source "fs/Kconfig"
541  
542  source "arch/s390/Kconfig.debug"
543  
544 +source "kernel/vserver/Kconfig"
545 +
546  source "security/Kconfig"
547  
548  source "crypto/Kconfig"
549 diff -NurpP --minimal linux-3.13.10/arch/s390/include/asm/tlb.h linux-3.13.10-vs2.3.6.11/arch/s390/include/asm/tlb.h
550 --- linux-3.13.10/arch/s390/include/asm/tlb.h   2013-11-25 15:46:29.000000000 +0000
551 +++ linux-3.13.10-vs2.3.6.11/arch/s390/include/asm/tlb.h        2014-01-31 20:38:03.000000000 +0000
552 @@ -24,6 +24,7 @@
553  #include <linux/mm.h>
554  #include <linux/pagemap.h>
555  #include <linux/swap.h>
556 +
557  #include <asm/processor.h>
558  #include <asm/pgalloc.h>
559  #include <asm/tlbflush.h>
560 diff -NurpP --minimal linux-3.13.10/arch/s390/include/uapi/asm/unistd.h linux-3.13.10-vs2.3.6.11/arch/s390/include/uapi/asm/unistd.h
561 --- linux-3.13.10/arch/s390/include/uapi/asm/unistd.h   2013-02-19 13:57:16.000000000 +0000
562 +++ linux-3.13.10-vs2.3.6.11/arch/s390/include/uapi/asm/unistd.h        2014-01-31 20:38:03.000000000 +0000
563 @@ -200,7 +200,7 @@
564  #define __NR_clock_gettime     (__NR_timer_create+6)
565  #define __NR_clock_getres      (__NR_timer_create+7)
566  #define __NR_clock_nanosleep   (__NR_timer_create+8)
567 -/* Number 263 is reserved for vserver */
568 +#define __NR_vserver           263
569  #define __NR_statfs64          265
570  #define __NR_fstatfs64         266
571  #define __NR_remap_file_pages  267
572 diff -NurpP --minimal linux-3.13.10/arch/s390/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/arch/s390/kernel/ptrace.c
573 --- linux-3.13.10/arch/s390/kernel/ptrace.c     2014-01-22 20:38:24.000000000 +0000
574 +++ linux-3.13.10-vs2.3.6.11/arch/s390/kernel/ptrace.c  2014-01-31 20:38:03.000000000 +0000
575 @@ -21,6 +21,7 @@
576  #include <linux/tracehook.h>
577  #include <linux/seccomp.h>
578  #include <linux/compat.h>
579 +#include <linux/vs_base.h>
580  #include <trace/syscall.h>
581  #include <asm/segment.h>
582  #include <asm/page.h>
583 diff -NurpP --minimal linux-3.13.10/arch/s390/kernel/syscalls.S linux-3.13.10-vs2.3.6.11/arch/s390/kernel/syscalls.S
584 --- linux-3.13.10/arch/s390/kernel/syscalls.S   2013-07-14 17:00:34.000000000 +0000
585 +++ linux-3.13.10-vs2.3.6.11/arch/s390/kernel/syscalls.S        2014-01-31 20:38:03.000000000 +0000
586 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
587  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
588  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
589  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
590 -NI_SYSCALL                                                     /* reserved for vserver */
591 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
592  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
593  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
594  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
595 diff -NurpP --minimal linux-3.13.10/arch/sh/Kconfig linux-3.13.10-vs2.3.6.11/arch/sh/Kconfig
596 --- linux-3.13.10/arch/sh/Kconfig       2014-01-22 20:38:24.000000000 +0000
597 +++ linux-3.13.10-vs2.3.6.11/arch/sh/Kconfig    2014-01-31 20:38:03.000000000 +0000
598 @@ -927,6 +927,8 @@ source "fs/Kconfig"
599  
600  source "arch/sh/Kconfig.debug"
601  
602 +source "kernel/vserver/Kconfig"
603 +
604  source "security/Kconfig"
605  
606  source "crypto/Kconfig"
607 diff -NurpP --minimal linux-3.13.10/arch/sh/kernel/irq.c linux-3.13.10-vs2.3.6.11/arch/sh/kernel/irq.c
608 --- linux-3.13.10/arch/sh/kernel/irq.c  2014-01-22 20:38:24.000000000 +0000
609 +++ linux-3.13.10-vs2.3.6.11/arch/sh/kernel/irq.c       2014-01-31 20:38:03.000000000 +0000
610 @@ -14,6 +14,7 @@
611  #include <linux/ftrace.h>
612  #include <linux/delay.h>
613  #include <linux/ratelimit.h>
614 +// #include <linux/vs_context.h>
615  #include <asm/processor.h>
616  #include <asm/machvec.h>
617  #include <asm/uaccess.h>
618 diff -NurpP --minimal linux-3.13.10/arch/sparc/Kconfig linux-3.13.10-vs2.3.6.11/arch/sparc/Kconfig
619 --- linux-3.13.10/arch/sparc/Kconfig    2014-01-22 20:38:24.000000000 +0000
620 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/Kconfig 2014-01-31 20:38:03.000000000 +0000
621 @@ -553,6 +553,8 @@ source "fs/Kconfig"
622  
623  source "arch/sparc/Kconfig.debug"
624  
625 +source "kernel/vserver/Kconfig"
626 +
627  source "security/Kconfig"
628  
629  source "crypto/Kconfig"
630 diff -NurpP --minimal linux-3.13.10/arch/sparc/include/uapi/asm/unistd.h linux-3.13.10-vs2.3.6.11/arch/sparc/include/uapi/asm/unistd.h
631 --- linux-3.13.10/arch/sparc/include/uapi/asm/unistd.h  2013-02-19 13:57:17.000000000 +0000
632 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/include/uapi/asm/unistd.h       2014-01-31 20:38:03.000000000 +0000
633 @@ -332,7 +332,7 @@
634  #define __NR_timer_getoverrun  264
635  #define __NR_timer_delete      265
636  #define __NR_timer_create      266
637 -/* #define __NR_vserver                267 Reserved for VSERVER */
638 +#define __NR_vserver           267
639  #define __NR_io_setup          268
640  #define __NR_io_destroy                269
641  #define __NR_io_submit         270
642 diff -NurpP --minimal linux-3.13.10/arch/sparc/kernel/systbls_32.S linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_32.S
643 --- linux-3.13.10/arch/sparc/kernel/systbls_32.S        2013-05-31 13:44:48.000000000 +0000
644 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_32.S     2014-01-31 20:38:03.000000000 +0000
645 @@ -70,7 +70,7 @@ sys_call_table:
646  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
647  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
648  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
649 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
650 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
651  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
652  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
653  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
654 diff -NurpP --minimal linux-3.13.10/arch/sparc/kernel/systbls_64.S linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_64.S
655 --- linux-3.13.10/arch/sparc/kernel/systbls_64.S        2013-07-14 17:00:35.000000000 +0000
656 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_64.S     2014-01-31 20:38:03.000000000 +0000
657 @@ -71,7 +71,7 @@ sys_call_table32:
658  /*250*/        .word sys_mremap, compat_sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
659         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
660  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
661 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
662 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
663  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
664         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
665  /*280*/        .word sys_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
666 @@ -149,7 +149,7 @@ sys_call_table:
667  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
668         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
669  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
670 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
671 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
672  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
673         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
674  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
675 diff -NurpP --minimal linux-3.13.10/arch/um/Kconfig.rest linux-3.13.10-vs2.3.6.11/arch/um/Kconfig.rest
676 --- linux-3.13.10/arch/um/Kconfig.rest  2012-12-11 03:30:57.000000000 +0000
677 +++ linux-3.13.10-vs2.3.6.11/arch/um/Kconfig.rest       2014-01-31 20:38:03.000000000 +0000
678 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
679  
680  source "fs/Kconfig"
681  
682 +source "kernel/vserver/Kconfig"
683 +
684  source "security/Kconfig"
685  
686  source "crypto/Kconfig"
687 diff -NurpP --minimal linux-3.13.10/arch/x86/Kconfig linux-3.13.10-vs2.3.6.11/arch/x86/Kconfig
688 --- linux-3.13.10/arch/x86/Kconfig      2014-01-22 20:38:25.000000000 +0000
689 +++ linux-3.13.10-vs2.3.6.11/arch/x86/Kconfig   2014-01-31 20:38:03.000000000 +0000
690 @@ -2403,6 +2403,8 @@ source "fs/Kconfig"
691  
692  source "arch/x86/Kconfig.debug"
693  
694 +source "kernel/vserver/Kconfig"
695 +
696  source "security/Kconfig"
697  
698  source "crypto/Kconfig"
699 diff -NurpP --minimal linux-3.13.10/arch/x86/syscalls/syscall_32.tbl linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_32.tbl
700 --- linux-3.13.10/arch/x86/syscalls/syscall_32.tbl      2013-07-14 17:00:37.000000000 +0000
701 +++ linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_32.tbl   2014-01-31 20:38:03.000000000 +0000
702 @@ -279,7 +279,7 @@
703  270    i386    tgkill                  sys_tgkill
704  271    i386    utimes                  sys_utimes                      compat_sys_utimes
705  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
706 -273    i386    vserver
707 +273    i386    vserver                 sys_vserver                     sys32_vserver
708  274    i386    mbind                   sys_mbind
709  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
710  276    i386    set_mempolicy           sys_set_mempolicy
711 diff -NurpP --minimal linux-3.13.10/arch/x86/syscalls/syscall_64.tbl linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_64.tbl
712 --- linux-3.13.10/arch/x86/syscalls/syscall_64.tbl      2013-05-31 13:44:50.000000000 +0000
713 +++ linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_64.tbl   2014-01-31 20:38:03.000000000 +0000
714 @@ -242,7 +242,7 @@
715  233    common  epoll_ctl               sys_epoll_ctl
716  234    common  tgkill                  sys_tgkill
717  235    common  utimes                  sys_utimes
718 -236    64      vserver
719 +236    64      vserver                 sys_vserver
720  237    common  mbind                   sys_mbind
721  238    common  set_mempolicy           sys_set_mempolicy
722  239    common  get_mempolicy           sys_get_mempolicy
723 diff -NurpP --minimal linux-3.13.10/drivers/block/Kconfig linux-3.13.10-vs2.3.6.11/drivers/block/Kconfig
724 --- linux-3.13.10/drivers/block/Kconfig 2014-01-22 20:38:27.000000000 +0000
725 +++ linux-3.13.10-vs2.3.6.11/drivers/block/Kconfig      2014-01-31 20:38:03.000000000 +0000
726 @@ -281,6 +281,13 @@ config BLK_DEV_CRYPTOLOOP
727  
728  source "drivers/block/drbd/Kconfig"
729  
730 +config BLK_DEV_VROOT
731 +       tristate "Virtual Root device support"
732 +       depends on QUOTACTL
733 +       ---help---
734 +         Saying Y here will allow you to use quota/fs ioctls on a shared
735 +         partition within a virtual server without compromising security.
736 +
737  config BLK_DEV_NBD
738         tristate "Network block device support"
739         depends on NET
740 diff -NurpP --minimal linux-3.13.10/drivers/block/Makefile linux-3.13.10-vs2.3.6.11/drivers/block/Makefile
741 --- linux-3.13.10/drivers/block/Makefile        2014-01-22 20:38:27.000000000 +0000
742 +++ linux-3.13.10-vs2.3.6.11/drivers/block/Makefile     2014-01-31 20:38:03.000000000 +0000
743 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIRTIO_BLK)      += virtio_blk.o
744  obj-$(CONFIG_VIODASD)          += viodasd.o
745  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
746  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
747 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
748  
749  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
750  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
751 diff -NurpP --minimal linux-3.13.10/drivers/block/loop.c linux-3.13.10-vs2.3.6.11/drivers/block/loop.c
752 --- linux-3.13.10/drivers/block/loop.c  2014-01-22 20:38:27.000000000 +0000
753 +++ linux-3.13.10-vs2.3.6.11/drivers/block/loop.c       2014-01-31 20:55:14.000000000 +0000
754 @@ -75,6 +75,7 @@
755  #include <linux/sysfs.h>
756  #include <linux/miscdevice.h>
757  #include <linux/falloc.h>
758 +#include <linux/vs_context.h>
759  #include "loop.h"
760  
761  #include <asm/uaccess.h>
762 @@ -884,6 +885,7 @@ static int loop_set_fd(struct loop_devic
763         lo->lo_blocksize = lo_blocksize;
764         lo->lo_device = bdev;
765         lo->lo_flags = lo_flags;
766 +       lo->lo_xid = vx_current_xid();
767         lo->lo_backing_file = file;
768         lo->transfer = transfer_none;
769         lo->ioctl = NULL;
770 @@ -1028,6 +1030,7 @@ static int loop_clr_fd(struct loop_devic
771         lo->lo_sizelimit = 0;
772         lo->lo_encrypt_key_size = 0;
773         lo->lo_thread = NULL;
774 +       lo->lo_xid = 0;
775         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
776         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
777         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
778 @@ -1071,7 +1074,7 @@ loop_set_status(struct loop_device *lo,
779  
780         if (lo->lo_encrypt_key_size &&
781             !uid_eq(lo->lo_key_owner, uid) &&
782 -           !capable(CAP_SYS_ADMIN))
783 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
784                 return -EPERM;
785         if (lo->lo_state != Lo_bound)
786                 return -ENXIO;
787 @@ -1161,7 +1164,8 @@ loop_get_status(struct loop_device *lo,
788         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
789         info->lo_encrypt_type =
790                 lo->lo_encryption ? lo->lo_encryption->number : 0;
791 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
792 +       if (lo->lo_encrypt_key_size &&
793 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
794                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
795                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
796                        lo->lo_encrypt_key_size);
797 @@ -1503,6 +1507,11 @@ static int lo_open(struct block_device *
798                 goto out;
799         }
800  
801 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
802 +               err = -EACCES;
803 +               goto out;
804 +       }
805 +
806         mutex_lock(&lo->lo_ctl_mutex);
807         lo->lo_refcnt++;
808         mutex_unlock(&lo->lo_ctl_mutex);
809 diff -NurpP --minimal linux-3.13.10/drivers/block/loop.h linux-3.13.10-vs2.3.6.11/drivers/block/loop.h
810 --- linux-3.13.10/drivers/block/loop.h  2013-11-25 15:44:28.000000000 +0000
811 +++ linux-3.13.10-vs2.3.6.11/drivers/block/loop.h       2014-02-01 01:57:49.000000000 +0000
812 @@ -41,6 +41,7 @@ struct loop_device {
813         struct loop_func_table *lo_encryption;
814         __u32           lo_init[2];
815         kuid_t          lo_key_owner;   /* Who set the key */
816 +       vxid_t          lo_xid;
817         int             (*ioctl)(struct loop_device *, int cmd, 
818                                  unsigned long arg); 
819  
820 diff -NurpP --minimal linux-3.13.10/drivers/block/vroot.c linux-3.13.10-vs2.3.6.11/drivers/block/vroot.c
821 --- linux-3.13.10/drivers/block/vroot.c 1970-01-01 00:00:00.000000000 +0000
822 +++ linux-3.13.10-vs2.3.6.11/drivers/block/vroot.c      2014-01-31 20:38:03.000000000 +0000
823 @@ -0,0 +1,290 @@
824 +/*
825 + *  linux/drivers/block/vroot.c
826 + *
827 + *  written by Herbert Pötzl, 9/11/2002
828 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
829 + *
830 + *  based on the loop.c code by Theodore Ts'o.
831 + *
832 + * Copyright (C) 2002-2007 by Herbert Pötzl.
833 + * Redistribution of this file is permitted under the
834 + * GNU General Public License.
835 + *
836 + */
837 +
838 +#include <linux/module.h>
839 +#include <linux/moduleparam.h>
840 +#include <linux/file.h>
841 +#include <linux/major.h>
842 +#include <linux/blkdev.h>
843 +#include <linux/slab.h>
844 +
845 +#include <linux/vroot.h>
846 +#include <linux/vs_context.h>
847 +
848 +
849 +static int max_vroot = 8;
850 +
851 +static struct vroot_device *vroot_dev;
852 +static struct gendisk **disks;
853 +
854 +
855 +static int vroot_set_dev(
856 +       struct vroot_device *vr,
857 +       struct block_device *bdev,
858 +       unsigned int arg)
859 +{
860 +       struct block_device *real_bdev;
861 +       struct file *file;
862 +       struct inode *inode;
863 +       int error;
864 +
865 +       error = -EBUSY;
866 +       if (vr->vr_state != Vr_unbound)
867 +               goto out;
868 +
869 +       error = -EBADF;
870 +       file = fget(arg);
871 +       if (!file)
872 +               goto out;
873 +
874 +       error = -EINVAL;
875 +       inode = file->f_dentry->d_inode;
876 +
877 +
878 +       if (S_ISBLK(inode->i_mode)) {
879 +               real_bdev = inode->i_bdev;
880 +               vr->vr_device = real_bdev;
881 +               __iget(real_bdev->bd_inode);
882 +       } else
883 +               goto out_fput;
884 +
885 +       vxdprintk(VXD_CBIT(misc, 0),
886 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
887 +               vr->vr_number, VXD_DEV(real_bdev));
888 +
889 +       vr->vr_state = Vr_bound;
890 +       error = 0;
891 +
892 + out_fput:
893 +       fput(file);
894 + out:
895 +       return error;
896 +}
897 +
898 +static int vroot_clr_dev(
899 +       struct vroot_device *vr,
900 +       struct block_device *bdev)
901 +{
902 +       struct block_device *real_bdev;
903 +
904 +       if (vr->vr_state != Vr_bound)
905 +               return -ENXIO;
906 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
907 +               return -EBUSY;
908 +
909 +       real_bdev = vr->vr_device;
910 +
911 +       vxdprintk(VXD_CBIT(misc, 0),
912 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
913 +               vr->vr_number, VXD_DEV(real_bdev));
914 +
915 +       bdput(real_bdev);
916 +       vr->vr_state = Vr_unbound;
917 +       vr->vr_device = NULL;
918 +       return 0;
919 +}
920 +
921 +
922 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
923 +       unsigned int cmd, unsigned long arg)
924 +{
925 +       struct vroot_device *vr = bdev->bd_disk->private_data;
926 +       int err;
927 +
928 +       down(&vr->vr_ctl_mutex);
929 +       switch (cmd) {
930 +       case VROOT_SET_DEV:
931 +               err = vroot_set_dev(vr, bdev, arg);
932 +               break;
933 +       case VROOT_CLR_DEV:
934 +               err = vroot_clr_dev(vr, bdev);
935 +               break;
936 +       default:
937 +               err = -EINVAL;
938 +               break;
939 +       }
940 +       up(&vr->vr_ctl_mutex);
941 +       return err;
942 +}
943 +
944 +static int vr_open(struct block_device *bdev, fmode_t mode)
945 +{
946 +       struct vroot_device *vr = bdev->bd_disk->private_data;
947 +
948 +       down(&vr->vr_ctl_mutex);
949 +       vr->vr_refcnt++;
950 +       up(&vr->vr_ctl_mutex);
951 +       return 0;
952 +}
953 +
954 +static void vr_release(struct gendisk *disk, fmode_t mode)
955 +{
956 +       struct vroot_device *vr = disk->private_data;
957 +
958 +       down(&vr->vr_ctl_mutex);
959 +       --vr->vr_refcnt;
960 +       up(&vr->vr_ctl_mutex);
961 +}
962 +
963 +static struct block_device_operations vr_fops = {
964 +       .owner =        THIS_MODULE,
965 +       .open =         vr_open,
966 +       .release =      vr_release,
967 +       .ioctl =        vr_ioctl,
968 +};
969 +
970 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
971 +{
972 +       printk("vroot_make_request %p, %p\n", q, bio);
973 +       bio_io_error(bio);
974 +}
975 +
976 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
977 +{
978 +       struct inode *inode = bdev->bd_inode;
979 +       struct vroot_device *vr;
980 +       struct block_device *real_bdev;
981 +       int minor = iminor(inode);
982 +
983 +       vr = &vroot_dev[minor];
984 +       real_bdev = vr->vr_device;
985 +
986 +       vxdprintk(VXD_CBIT(misc, 0),
987 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
988 +               vr->vr_number, VXD_DEV(real_bdev));
989 +
990 +       if (vr->vr_state != Vr_bound)
991 +               return ERR_PTR(-ENXIO);
992 +
993 +       __iget(real_bdev->bd_inode);
994 +       return real_bdev;
995 +}
996 +
997 +
998 +
999 +/*
1000 + * And now the modules code and kernel interface.
1001 + */
1002 +
1003 +module_param(max_vroot, int, 0);
1004 +
1005 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1006 +MODULE_LICENSE("GPL");
1007 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1008 +
1009 +MODULE_AUTHOR ("Herbert Pötzl");
1010 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1011 +
1012 +
1013 +int __init vroot_init(void)
1014 +{
1015 +       int err, i;
1016 +
1017 +       if (max_vroot < 1 || max_vroot > 256) {
1018 +               max_vroot = MAX_VROOT_DEFAULT;
1019 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1020 +                       "(must be between 1 and 256), "
1021 +                       "using default (%d)\n", max_vroot);
1022 +       }
1023 +
1024 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1025 +               return -EIO;
1026 +
1027 +       err = -ENOMEM;
1028 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1029 +       if (!vroot_dev)
1030 +               goto out_mem1;
1031 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1032 +
1033 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1034 +       if (!disks)
1035 +               goto out_mem2;
1036 +
1037 +       for (i = 0; i < max_vroot; i++) {
1038 +               disks[i] = alloc_disk(1);
1039 +               if (!disks[i])
1040 +                       goto out_mem3;
1041 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1042 +               if (!disks[i]->queue)
1043 +                       goto out_mem3;
1044 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1045 +       }
1046 +
1047 +       for (i = 0; i < max_vroot; i++) {
1048 +               struct vroot_device *vr = &vroot_dev[i];
1049 +               struct gendisk *disk = disks[i];
1050 +
1051 +               memset(vr, 0, sizeof(*vr));
1052 +               sema_init(&vr->vr_ctl_mutex, 1);
1053 +               vr->vr_number = i;
1054 +               disk->major = VROOT_MAJOR;
1055 +               disk->first_minor = i;
1056 +               disk->fops = &vr_fops;
1057 +               sprintf(disk->disk_name, "vroot%d", i);
1058 +               disk->private_data = vr;
1059 +       }
1060 +
1061 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1062 +       if (err)
1063 +               goto out_mem3;
1064 +
1065 +       for (i = 0; i < max_vroot; i++)
1066 +               add_disk(disks[i]);
1067 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1068 +       return 0;
1069 +
1070 +out_mem3:
1071 +       while (i--)
1072 +               put_disk(disks[i]);
1073 +       kfree(disks);
1074 +out_mem2:
1075 +       kfree(vroot_dev);
1076 +out_mem1:
1077 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1078 +       printk(KERN_ERR "vroot: ran out of memory\n");
1079 +       return err;
1080 +}
1081 +
1082 +void vroot_exit(void)
1083 +{
1084 +       int i;
1085 +
1086 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1087 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1088 +
1089 +       for (i = 0; i < max_vroot; i++) {
1090 +               del_gendisk(disks[i]);
1091 +               put_disk(disks[i]);
1092 +       }
1093 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1094 +
1095 +       kfree(disks);
1096 +       kfree(vroot_dev);
1097 +}
1098 +
1099 +module_init(vroot_init);
1100 +module_exit(vroot_exit);
1101 +
1102 +#ifndef MODULE
1103 +
1104 +static int __init max_vroot_setup(char *str)
1105 +{
1106 +       max_vroot = simple_strtol(str, NULL, 0);
1107 +       return 1;
1108 +}
1109 +
1110 +__setup("max_vroot=", max_vroot_setup);
1111 +
1112 +#endif
1113 +
1114 diff -NurpP --minimal linux-3.13.10/drivers/infiniband/core/addr.c linux-3.13.10-vs2.3.6.11/drivers/infiniband/core/addr.c
1115 --- linux-3.13.10/drivers/infiniband/core/addr.c        2013-11-25 15:44:35.000000000 +0000
1116 +++ linux-3.13.10-vs2.3.6.11/drivers/infiniband/core/addr.c     2014-01-31 20:38:03.000000000 +0000
1117 @@ -277,7 +277,7 @@ static int addr6_resolve(struct sockaddr
1118  
1119         if (ipv6_addr_any(&fl6.saddr)) {
1120                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1121 -                                        &fl6.daddr, 0, &fl6.saddr);
1122 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1123                 if (ret)
1124                         goto put;
1125  
1126 diff -NurpP --minimal linux-3.13.10/drivers/md/dm-ioctl.c linux-3.13.10-vs2.3.6.11/drivers/md/dm-ioctl.c
1127 --- linux-3.13.10/drivers/md/dm-ioctl.c 2014-01-22 20:38:36.000000000 +0000
1128 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm-ioctl.c      2014-01-31 21:01:49.000000000 +0000
1129 @@ -16,6 +16,7 @@
1130  #include <linux/dm-ioctl.h>
1131  #include <linux/hdreg.h>
1132  #include <linux/compat.h>
1133 +#include <linux/vs_context.h>
1134  
1135  #include <asm/uaccess.h>
1136  
1137 @@ -114,7 +115,8 @@ static struct hash_cell *__get_name_cell
1138         unsigned int h = hash_str(str);
1139  
1140         list_for_each_entry (hc, _name_buckets + h, name_list)
1141 -               if (!strcmp(hc->name, str)) {
1142 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1143 +                       !strcmp(hc->name, str)) {
1144                         dm_get(hc->md);
1145                         return hc;
1146                 }
1147 @@ -128,7 +130,8 @@ static struct hash_cell *__get_uuid_cell
1148         unsigned int h = hash_str(str);
1149  
1150         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1151 -               if (!strcmp(hc->uuid, str)) {
1152 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1153 +                       !strcmp(hc->uuid, str)) {
1154                         dm_get(hc->md);
1155                         return hc;
1156                 }
1157 @@ -139,13 +142,15 @@ static struct hash_cell *__get_uuid_cell
1158  static struct hash_cell *__get_dev_cell(uint64_t dev)
1159  {
1160         struct mapped_device *md;
1161 -       struct hash_cell *hc;
1162 +       struct hash_cell *hc = NULL;
1163  
1164         md = dm_get_md(huge_decode_dev(dev));
1165         if (!md)
1166                 return NULL;
1167  
1168 -       hc = dm_get_mdptr(md);
1169 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1170 +               hc = dm_get_mdptr(md);
1171 +
1172         if (!hc) {
1173                 dm_put(md);
1174                 return NULL;
1175 @@ -467,6 +472,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1176  
1177  static int remove_all(struct dm_ioctl *param, size_t param_size)
1178  {
1179 +       if (!vx_check(0, VS_ADMIN))
1180 +               return -EPERM;
1181 +
1182         dm_hash_remove_all(true, !!(param->flags & DM_DEFERRED_REMOVE), false);
1183         param->data_size = 0;
1184         return 0;
1185 @@ -514,6 +522,8 @@ static int list_devices(struct dm_ioctl
1186          */
1187         for (i = 0; i < NUM_BUCKETS; i++) {
1188                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1189 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1190 +                               continue;
1191                         needed += sizeof(struct dm_name_list);
1192                         needed += strlen(hc->name) + 1;
1193                         needed += ALIGN_MASK;
1194 @@ -537,6 +547,8 @@ static int list_devices(struct dm_ioctl
1195          */
1196         for (i = 0; i < NUM_BUCKETS; i++) {
1197                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1198 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1199 +                               continue;
1200                         if (old_nl)
1201                                 old_nl->next = (uint32_t) ((void *) nl -
1202                                                            (void *) old_nl);
1203 @@ -1797,8 +1809,8 @@ static int ctl_ioctl(uint command, struc
1204         size_t input_param_size;
1205         struct dm_ioctl param_kernel;
1206  
1207 -       /* only root can play with this */
1208 -       if (!capable(CAP_SYS_ADMIN))
1209 +       /* only root and certain contexts can play with this */
1210 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1211                 return -EACCES;
1212  
1213         if (_IOC_TYPE(command) != DM_IOCTL)
1214 diff -NurpP --minimal linux-3.13.10/drivers/md/dm.c linux-3.13.10-vs2.3.6.11/drivers/md/dm.c
1215 --- linux-3.13.10/drivers/md/dm.c       2014-04-17 01:12:19.000000000 +0000
1216 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm.c    2014-02-25 11:26:09.000000000 +0000
1217 @@ -19,6 +19,7 @@
1218  #include <linux/idr.h>
1219  #include <linux/hdreg.h>
1220  #include <linux/delay.h>
1221 +#include <linux/vs_base.h>
1222  
1223  #include <trace/events/block.h>
1224  
1225 @@ -139,6 +140,7 @@ struct mapped_device {
1226         struct mutex suspend_lock;
1227         atomic_t holders;
1228         atomic_t open_count;
1229 +       vxid_t xid;
1230  
1231         /*
1232          * The current mapping.
1233 @@ -384,6 +386,7 @@ int dm_deleting_md(struct mapped_device
1234  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1235  {
1236         struct mapped_device *md;
1237 +       int ret = -ENXIO;
1238  
1239         spin_lock(&_minor_lock);
1240  
1241 @@ -392,18 +395,19 @@ static int dm_blk_open(struct block_devi
1242                 goto out;
1243  
1244         if (test_bit(DMF_FREEING, &md->flags) ||
1245 -           dm_deleting_md(md)) {
1246 -               md = NULL;
1247 +           dm_deleting_md(md))
1248 +               goto out;
1249 +
1250 +       ret = -EACCES;
1251 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1252                 goto out;
1253 -       }
1254  
1255         dm_get(md);
1256         atomic_inc(&md->open_count);
1257 -
1258 +       ret = 0;
1259  out:
1260         spin_unlock(&_minor_lock);
1261 -
1262 -       return md ? 0 : -ENXIO;
1263 +       return ret;
1264  }
1265  
1266  static void dm_blk_close(struct gendisk *disk, fmode_t mode)
1267 @@ -687,6 +691,14 @@ int dm_set_geometry(struct mapped_device
1268         return 0;
1269  }
1270  
1271 +/*
1272 + * Get the xid associated with a dm device
1273 + */
1274 +vxid_t dm_get_xid(struct mapped_device *md)
1275 +{
1276 +       return md->xid;
1277 +}
1278 +
1279  /*-----------------------------------------------------------------
1280   * CRUD START:
1281   *   A more elegant soln is in the works that uses the queue
1282 @@ -2026,6 +2038,7 @@ static struct mapped_device *alloc_dev(i
1283         INIT_LIST_HEAD(&md->uevent_list);
1284         spin_lock_init(&md->uevent_lock);
1285  
1286 +       md->xid = vx_current_xid();
1287         md->queue = blk_alloc_queue(GFP_KERNEL);
1288         if (!md->queue)
1289                 goto bad_queue;
1290 diff -NurpP --minimal linux-3.13.10/drivers/md/dm.h linux-3.13.10-vs2.3.6.11/drivers/md/dm.h
1291 --- linux-3.13.10/drivers/md/dm.h       2014-04-17 01:12:19.000000000 +0000
1292 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm.h    2014-02-25 11:26:09.000000000 +0000
1293 @@ -50,6 +50,8 @@ struct dm_dev_internal {
1294  struct dm_table;
1295  struct dm_md_mempools;
1296  
1297 +vxid_t dm_get_xid(struct mapped_device *md);
1298 +
1299  /*-----------------------------------------------------------------
1300   * Internal table functions.
1301   *---------------------------------------------------------------*/
1302 diff -NurpP --minimal linux-3.13.10/drivers/net/tun.c linux-3.13.10-vs2.3.6.11/drivers/net/tun.c
1303 --- linux-3.13.10/drivers/net/tun.c     2014-04-17 01:12:21.000000000 +0000
1304 +++ linux-3.13.10-vs2.3.6.11/drivers/net/tun.c  2014-04-17 01:17:10.000000000 +0000
1305 @@ -65,6 +65,7 @@
1306  #include <linux/nsproxy.h>
1307  #include <linux/virtio_net.h>
1308  #include <linux/rcupdate.h>
1309 +#include <linux/vs_network.h>
1310  #include <net/net_namespace.h>
1311  #include <net/netns/generic.h>
1312  #include <net/rtnetlink.h>
1313 @@ -168,6 +169,7 @@ struct tun_struct {
1314         unsigned int            flags;
1315         kuid_t                  owner;
1316         kgid_t                  group;
1317 +       vnid_t                  nid;
1318  
1319         struct net_device       *dev;
1320         netdev_features_t       set_features;
1321 @@ -385,6 +387,7 @@ static inline bool tun_not_capable(struc
1322         return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1323                   (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1324                 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1325 +               /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1326  }
1327  
1328  static void tun_set_real_num_queues(struct tun_struct *tun)
1329 @@ -1382,6 +1385,7 @@ static void tun_setup(struct net_device
1330  
1331         tun->owner = INVALID_UID;
1332         tun->group = INVALID_GID;
1333 +       tun->nid = nx_current_nid();
1334  
1335         dev->ethtool_ops = &tun_ethtool_ops;
1336         dev->destructor = tun_free_netdev;
1337 @@ -1598,7 +1602,7 @@ static int tun_set_iff(struct net *net,
1338                 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1339                              MAX_TAP_QUEUES : 1;
1340  
1341 -               if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1342 +               if (!nx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1343                         return -EPERM;
1344                 err = security_tun_dev_create();
1345                 if (err < 0)
1346 @@ -1969,6 +1973,16 @@ static long __tun_chr_ioctl(struct file
1347                           from_kgid(&init_user_ns, tun->group));
1348                 break;
1349  
1350 +       case TUNSETNID:
1351 +               if (!capable(CAP_CONTEXT))
1352 +                       return -EPERM;
1353 +
1354 +               /* Set nid owner of the device */
1355 +               tun->nid = (vnid_t) arg;
1356 +
1357 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1358 +               break;
1359 +
1360         case TUNSETLINK:
1361                 /* Only allow setting the type when the interface is down */
1362                 if (tun->dev->flags & IFF_UP) {
1363 diff -NurpP --minimal linux-3.13.10/drivers/tty/sysrq.c linux-3.13.10-vs2.3.6.11/drivers/tty/sysrq.c
1364 --- linux-3.13.10/drivers/tty/sysrq.c   2014-01-22 20:39:02.000000000 +0000
1365 +++ linux-3.13.10-vs2.3.6.11/drivers/tty/sysrq.c        2014-01-31 20:55:49.000000000 +0000
1366 @@ -46,6 +46,7 @@
1367  #include <linux/jiffies.h>
1368  #include <linux/syscalls.h>
1369  #include <linux/of.h>
1370 +#include <linux/vserver/debug.h>
1371  
1372  #include <asm/ptrace.h>
1373  #include <asm/irq_regs.h>
1374 @@ -407,6 +408,21 @@ static struct sysrq_key_op sysrq_unrt_op
1375         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1376  };
1377  
1378 +
1379 +#ifdef CONFIG_VSERVER_DEBUG
1380 +static void sysrq_handle_vxinfo(int key)
1381 +{
1382 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1383 +}
1384 +
1385 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1386 +       .handler        = sysrq_handle_vxinfo,
1387 +       .help_msg       = "conteXt",
1388 +       .action_msg     = "Show Context Info",
1389 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1390 +};
1391 +#endif
1392 +
1393  /* Key Operations table and lock */
1394  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1395  
1396 @@ -462,7 +478,11 @@ static struct sysrq_key_op *sysrq_key_ta
1397         &sysrq_showstate_blocked_op,    /* w */
1398         /* x: May be registered on ppc/powerpc for xmon */
1399         /* x: May be registered on sparc64 for global PMU dump */
1400 +#ifdef CONFIG_VSERVER_DEBUG
1401 +       &sysrq_showvxinfo_op,           /* x */
1402 +#else
1403         NULL,                           /* x */
1404 +#endif
1405         /* y: May be registered on sparc64 for global register dump */
1406         NULL,                           /* y */
1407         &sysrq_ftrace_dump_op,          /* z */
1408 @@ -477,6 +497,8 @@ static int sysrq_key_table_key2index(int
1409                 retval = key - '0';
1410         else if ((key >= 'a') && (key <= 'z'))
1411                 retval = key + 10 - 'a';
1412 +       else if ((key >= 'A') && (key <= 'Z'))
1413 +               retval = key + 10 - 'A';
1414         else
1415                 retval = -1;
1416         return retval;
1417 diff -NurpP --minimal linux-3.13.10/drivers/tty/tty_io.c linux-3.13.10-vs2.3.6.11/drivers/tty/tty_io.c
1418 --- linux-3.13.10/drivers/tty/tty_io.c  2014-01-22 20:39:02.000000000 +0000
1419 +++ linux-3.13.10-vs2.3.6.11/drivers/tty/tty_io.c       2014-01-31 20:38:03.000000000 +0000
1420 @@ -104,6 +104,7 @@
1421  
1422  #include <linux/kmod.h>
1423  #include <linux/nsproxy.h>
1424 +#include <linux/vs_pid.h>
1425  
1426  #undef TTY_DEBUG_HANGUP
1427  
1428 @@ -2218,7 +2219,8 @@ static int tiocsti(struct tty_struct *tt
1429         char ch, mbz = 0;
1430         struct tty_ldisc *ld;
1431  
1432 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1433 +       if (((current->signal->tty != tty) &&
1434 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1435                 return -EPERM;
1436         if (get_user(ch, p))
1437                 return -EFAULT;
1438 @@ -2506,6 +2508,7 @@ static int tiocspgrp(struct tty_struct *
1439                 return -ENOTTY;
1440         if (get_user(pgrp_nr, p))
1441                 return -EFAULT;
1442 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1443         if (pgrp_nr < 0)
1444                 return -EINVAL;
1445         rcu_read_lock();
1446 diff -NurpP --minimal linux-3.13.10/fs/attr.c linux-3.13.10-vs2.3.6.11/fs/attr.c
1447 --- linux-3.13.10/fs/attr.c     2014-04-17 01:12:31.000000000 +0000
1448 +++ linux-3.13.10-vs2.3.6.11/fs/attr.c  2014-03-12 15:51:07.000000000 +0000
1449 @@ -15,6 +15,9 @@
1450  #include <linux/security.h>
1451  #include <linux/evm.h>
1452  #include <linux/ima.h>
1453 +#include <linux/proc_fs.h>
1454 +#include <linux/devpts_fs.h>
1455 +#include <linux/vs_tag.h>
1456  
1457  /**
1458   * inode_change_ok - check if attribute changes to an inode are allowed
1459 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1460                         return -EPERM;
1461         }
1462  
1463 +       /* check for inode tag permission */
1464 +       if (dx_permission(inode, MAY_WRITE))
1465 +               return -EACCES;
1466 +
1467         return 0;
1468  }
1469  EXPORT_SYMBOL(inode_change_ok);
1470 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1471                 inode->i_uid = attr->ia_uid;
1472         if (ia_valid & ATTR_GID)
1473                 inode->i_gid = attr->ia_gid;
1474 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1475 +               inode->i_tag = attr->ia_tag;
1476         if (ia_valid & ATTR_ATIME)
1477                 inode->i_atime = timespec_trunc(attr->ia_atime,
1478                                                 inode->i_sb->s_time_gran);
1479 @@ -197,7 +206,8 @@ int notify_change(struct dentry * dentry
1480  
1481         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1482  
1483 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1484 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1485 +               ATTR_TAG | ATTR_TIMES_SET)) {
1486                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1487                         return -EPERM;
1488         }
1489 diff -NurpP --minimal linux-3.13.10/fs/block_dev.c linux-3.13.10-vs2.3.6.11/fs/block_dev.c
1490 --- linux-3.13.10/fs/block_dev.c        2013-11-25 15:46:58.000000000 +0000
1491 +++ linux-3.13.10-vs2.3.6.11/fs/block_dev.c     2014-01-31 20:38:03.000000000 +0000
1492 @@ -28,6 +28,7 @@
1493  #include <linux/log2.h>
1494  #include <linux/cleancache.h>
1495  #include <linux/aio.h>
1496 +#include <linux/vs_device.h>
1497  #include <asm/uaccess.h>
1498  #include "internal.h"
1499  
1500 @@ -515,6 +516,7 @@ struct block_device *bdget(dev_t dev)
1501                 bdev->bd_invalidated = 0;
1502                 inode->i_mode = S_IFBLK;
1503                 inode->i_rdev = dev;
1504 +               inode->i_mdev = dev;
1505                 inode->i_bdev = bdev;
1506                 inode->i_data.a_ops = &def_blk_aops;
1507                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1508 @@ -562,6 +564,11 @@ EXPORT_SYMBOL(bdput);
1509  static struct block_device *bd_acquire(struct inode *inode)
1510  {
1511         struct block_device *bdev;
1512 +       dev_t mdev;
1513 +
1514 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1515 +               return NULL;
1516 +       inode->i_mdev = mdev;
1517  
1518         spin_lock(&bdev_lock);
1519         bdev = inode->i_bdev;
1520 @@ -572,7 +579,7 @@ static struct block_device *bd_acquire(s
1521         }
1522         spin_unlock(&bdev_lock);
1523  
1524 -       bdev = bdget(inode->i_rdev);
1525 +       bdev = bdget(mdev);
1526         if (bdev) {
1527                 spin_lock(&bdev_lock);
1528                 if (!inode->i_bdev) {
1529 diff -NurpP --minimal linux-3.13.10/fs/btrfs/ctree.h linux-3.13.10-vs2.3.6.11/fs/btrfs/ctree.h
1530 --- linux-3.13.10/fs/btrfs/ctree.h      2014-01-22 20:39:05.000000000 +0000
1531 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/ctree.h   2014-01-31 23:58:35.000000000 +0000
1532 @@ -718,11 +718,14 @@ struct btrfs_inode_item {
1533         /* modification sequence number for NFS */
1534         __le64 sequence;
1535  
1536 +       __le16 tag;
1537         /*
1538          * a little future expansion, for more than this we can
1539          * just grow the inode item and version it
1540          */
1541 -       __le64 reserved[4];
1542 +       __le16 reserved16;
1543 +       __le32 reserved32;
1544 +       __le64 reserved[3];
1545         struct btrfs_timespec atime;
1546         struct btrfs_timespec ctime;
1547         struct btrfs_timespec mtime;
1548 @@ -2000,6 +2003,8 @@ struct btrfs_ioctl_defrag_range_args {
1549  
1550  #define BTRFS_DEFAULT_COMMIT_INTERVAL  (30)
1551  
1552 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1553 +
1554  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1555  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1556  #define btrfs_raw_test_opt(o, opt)     ((o) & BTRFS_MOUNT_##opt)
1557 @@ -2269,6 +2274,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1558  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1559  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1560  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1561 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1562  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1563  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1564  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1565 @@ -2341,6 +2347,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1566  
1567  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1568  
1569 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1570 +#define BTRFS_INODE_BARRIER            (1 << 25)
1571 +#define BTRFS_INODE_COW                        (1 << 26)
1572 +
1573  
1574  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1575  
1576 @@ -3722,6 +3732,7 @@ long btrfs_ioctl(struct file *file, unsi
1577  void btrfs_update_iflags(struct inode *inode);
1578  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1579  int btrfs_is_empty_uuid(u8 *uuid);
1580 +int btrfs_sync_flags(struct inode *inode, int, int);
1581  int btrfs_defrag_file(struct inode *inode, struct file *file,
1582                       struct btrfs_ioctl_defrag_range_args *range,
1583                       u64 newer_than, unsigned long max_pages);
1584 diff -NurpP --minimal linux-3.13.10/fs/btrfs/disk-io.c linux-3.13.10-vs2.3.6.11/fs/btrfs/disk-io.c
1585 --- linux-3.13.10/fs/btrfs/disk-io.c    2014-01-22 20:39:05.000000000 +0000
1586 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/disk-io.c 2014-01-31 20:38:03.000000000 +0000
1587 @@ -2388,6 +2388,9 @@ int open_ctree(struct super_block *sb,
1588                 goto fail_alloc;
1589         }
1590  
1591 +       if (btrfs_test_opt(tree_root, TAGGED))
1592 +               sb->s_flags |= MS_TAGGED;
1593 +
1594         features = btrfs_super_incompat_flags(disk_super) &
1595                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1596         if (features) {
1597 diff -NurpP --minimal linux-3.13.10/fs/btrfs/inode.c linux-3.13.10-vs2.3.6.11/fs/btrfs/inode.c
1598 --- linux-3.13.10/fs/btrfs/inode.c      2014-04-17 01:12:31.000000000 +0000
1599 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/inode.c   2014-03-12 15:51:07.000000000 +0000
1600 @@ -43,6 +43,7 @@
1601  #include <linux/btrfs.h>
1602  #include <linux/blkdev.h>
1603  #include <linux/posix_acl_xattr.h>
1604 +#include <linux/vs_tag.h>
1605  #include "ctree.h"
1606  #include "disk-io.h"
1607  #include "transaction.h"
1608 @@ -3317,6 +3318,9 @@ static void btrfs_read_locked_inode(stru
1609         struct btrfs_key location;
1610         int maybe_acls;
1611         u32 rdev;
1612 +       kuid_t kuid;
1613 +       kgid_t kgid;
1614 +       ktag_t ktag;
1615         int ret;
1616         bool filled = false;
1617  
1618 @@ -3344,8 +3348,14 @@ static void btrfs_read_locked_inode(stru
1619                                     struct btrfs_inode_item);
1620         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1621         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1622 -       i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1623 -       i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1624 +
1625 +       kuid = make_kuid(&init_user_ns, btrfs_inode_uid(leaf, inode_item));
1626 +       kgid = make_kgid(&init_user_ns, btrfs_inode_gid(leaf, inode_item));
1627 +       ktag = make_ktag(&init_user_ns, btrfs_inode_tag(leaf, inode_item));
1628 +
1629 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
1630 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
1631 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
1632         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1633  
1634         tspec = btrfs_inode_atime(inode_item);
1635 @@ -3436,11 +3446,18 @@ static void fill_inode_item(struct btrfs
1636                             struct inode *inode)
1637  {
1638         struct btrfs_map_token token;
1639 +       uid_t uid = from_kuid(&init_user_ns,
1640 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
1641 +       gid_t gid = from_kgid(&init_user_ns,
1642 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
1643  
1644         btrfs_init_map_token(&token);
1645  
1646 -       btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1647 -       btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1648 +       btrfs_set_token_inode_uid(leaf, item, uid, &token);
1649 +       btrfs_set_token_inode_gid(leaf, item, gid, &token);
1650 +#ifdef CONFIG_TAGGING_INTERN
1651 +       btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1652 +#endif
1653         btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1654                                    &token);
1655         btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1656 @@ -8652,14 +8669,17 @@ static const struct inode_operations btr
1657         .listxattr      = btrfs_listxattr,
1658         .removexattr    = btrfs_removexattr,
1659         .permission     = btrfs_permission,
1660 +       .sync_flags     = btrfs_sync_flags,
1661         .get_acl        = btrfs_get_acl,
1662         .set_acl        = btrfs_set_acl,
1663         .update_time    = btrfs_update_time,
1664  };
1665 +
1666  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1667         .lookup         = btrfs_lookup,
1668         .permission     = btrfs_permission,
1669 +       .sync_flags     = btrfs_sync_flags,
1670         .get_acl        = btrfs_get_acl,
1671         .set_acl        = btrfs_set_acl,
1672         .update_time    = btrfs_update_time,
1673  };
1674 @@ -8727,6 +8747,7 @@ static const struct inode_operations btr
1675         .removexattr    = btrfs_removexattr,
1676         .permission     = btrfs_permission,
1677         .fiemap         = btrfs_fiemap,
1678 +       .sync_flags     = btrfs_sync_flags,
1679         .get_acl        = btrfs_get_acl,
1680         .update_time    = btrfs_update_time,
1681  };
1682 diff -NurpP --minimal linux-3.13.10/fs/btrfs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/btrfs/ioctl.c
1683 --- linux-3.13.10/fs/btrfs/ioctl.c      2014-04-17 01:12:31.000000000 +0000
1684 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/ioctl.c   2014-02-25 11:26:09.000000000 +0000
1685 @@ -78,10 +78,13 @@ static unsigned int btrfs_flags_to_ioctl
1686  {
1687         unsigned int iflags = 0;
1688  
1689 -       if (flags & BTRFS_INODE_SYNC)
1690 -               iflags |= FS_SYNC_FL;
1691         if (flags & BTRFS_INODE_IMMUTABLE)
1692                 iflags |= FS_IMMUTABLE_FL;
1693 +       if (flags & BTRFS_INODE_IXUNLINK)
1694 +               iflags |= FS_IXUNLINK_FL;
1695 +
1696 +       if (flags & BTRFS_INODE_SYNC)
1697 +               iflags |= FS_SYNC_FL;
1698         if (flags & BTRFS_INODE_APPEND)
1699                 iflags |= FS_APPEND_FL;
1700         if (flags & BTRFS_INODE_NODUMP)
1701 @@ -98,28 +101,78 @@ static unsigned int btrfs_flags_to_ioctl
1702         else if (flags & BTRFS_INODE_NOCOMPRESS)
1703                 iflags |= FS_NOCOMP_FL;
1704  
1705 +       if (flags & BTRFS_INODE_BARRIER)
1706 +               iflags |= FS_BARRIER_FL;
1707 +       if (flags & BTRFS_INODE_COW)
1708 +               iflags |= FS_COW_FL;
1709         return iflags;
1710  }
1711  
1712  /*
1713 - * Update inode->i_flags based on the btrfs internal flags.
1714 + * Update inode->i_(v)flags based on the btrfs internal flags.
1715   */
1716  void btrfs_update_iflags(struct inode *inode)
1717  {
1718         struct btrfs_inode *ip = BTRFS_I(inode);
1719  
1720 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1721 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1722 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1723  
1724 -       if (ip->flags & BTRFS_INODE_SYNC)
1725 -               inode->i_flags |= S_SYNC;
1726         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1727                 inode->i_flags |= S_IMMUTABLE;
1728 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1729 +               inode->i_flags |= S_IXUNLINK;
1730 +
1731 +       if (ip->flags & BTRFS_INODE_SYNC)
1732 +               inode->i_flags |= S_SYNC;
1733         if (ip->flags & BTRFS_INODE_APPEND)
1734                 inode->i_flags |= S_APPEND;
1735         if (ip->flags & BTRFS_INODE_NOATIME)
1736                 inode->i_flags |= S_NOATIME;
1737         if (ip->flags & BTRFS_INODE_DIRSYNC)
1738                 inode->i_flags |= S_DIRSYNC;
1739 +
1740 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1741 +
1742 +       if (ip->flags & BTRFS_INODE_BARRIER)
1743 +               inode->i_vflags |= V_BARRIER;
1744 +       if (ip->flags & BTRFS_INODE_COW)
1745 +               inode->i_vflags |= V_COW;
1746 +}
1747 +
1748 +/*
1749 + * Update btrfs internal flags from inode->i_(v)flags.
1750 + */
1751 +void btrfs_update_flags(struct inode *inode)
1752 +{
1753 +       struct btrfs_inode *ip = BTRFS_I(inode);
1754 +
1755 +       unsigned int flags = inode->i_flags;
1756 +       unsigned int vflags = inode->i_vflags;
1757 +
1758 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1759 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1760 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1761 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1762 +
1763 +       if (flags & S_IMMUTABLE)
1764 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1765 +       if (flags & S_IXUNLINK)
1766 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1767 +
1768 +       if (flags & S_SYNC)
1769 +               ip->flags |= BTRFS_INODE_SYNC;
1770 +       if (flags & S_APPEND)
1771 +               ip->flags |= BTRFS_INODE_APPEND;
1772 +       if (flags & S_NOATIME)
1773 +               ip->flags |= BTRFS_INODE_NOATIME;
1774 +       if (flags & S_DIRSYNC)
1775 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1776 +
1777 +       if (vflags & V_BARRIER)
1778 +               ip->flags |= BTRFS_INODE_BARRIER;
1779 +       if (vflags & V_COW)
1780 +               ip->flags |= BTRFS_INODE_COW;
1781  }
1782  
1783  /*
1784 @@ -135,6 +188,7 @@ void btrfs_inherit_iflags(struct inode *
1785                 return;
1786  
1787         flags = BTRFS_I(dir)->flags;
1788 +       flags &= ~BTRFS_INODE_BARRIER;
1789  
1790         if (flags & BTRFS_INODE_NOCOMPRESS) {
1791                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1792 @@ -153,6 +207,30 @@ void btrfs_inherit_iflags(struct inode *
1793         btrfs_update_iflags(inode);
1794  }
1795  
1796 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1797 +{
1798 +       struct btrfs_inode *ip = BTRFS_I(inode);
1799 +       struct btrfs_root *root = ip->root;
1800 +       struct btrfs_trans_handle *trans;
1801 +       int ret;
1802 +
1803 +       trans = btrfs_join_transaction(root);
1804 +       BUG_ON(!trans);
1805 +
1806 +       inode->i_flags = flags;
1807 +       inode->i_vflags = vflags;
1808 +       btrfs_update_flags(inode);
1809 +
1810 +       ret = btrfs_update_inode(trans, root, inode);
1811 +       BUG_ON(ret);
1812 +
1813 +       btrfs_update_iflags(inode);
1814 +       inode->i_ctime = CURRENT_TIME;
1815 +       btrfs_end_transaction(trans, root);
1816 +
1817 +       return 0;
1818 +}
1819 +
1820  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1821  {
1822         struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1823 @@ -215,21 +293,27 @@ static int btrfs_ioctl_setflags(struct f
1824  
1825         flags = btrfs_mask_flags(inode->i_mode, flags);
1826         oldflags = btrfs_flags_to_ioctl(ip->flags);
1827 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1828 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1829 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1830                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1831                         ret = -EPERM;
1832                         goto out_unlock;
1833                 }
1834         }
1835  
1836 -       if (flags & FS_SYNC_FL)
1837 -               ip->flags |= BTRFS_INODE_SYNC;
1838 -       else
1839 -               ip->flags &= ~BTRFS_INODE_SYNC;
1840         if (flags & FS_IMMUTABLE_FL)
1841                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1842         else
1843                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1844 +       if (flags & FS_IXUNLINK_FL)
1845 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1846 +       else
1847 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1848 +
1849 +       if (flags & FS_SYNC_FL)
1850 +               ip->flags |= BTRFS_INODE_SYNC;
1851 +       else
1852 +               ip->flags &= ~BTRFS_INODE_SYNC;
1853         if (flags & FS_APPEND_FL)
1854                 ip->flags |= BTRFS_INODE_APPEND;
1855         else
1856 diff -NurpP --minimal linux-3.13.10/fs/btrfs/super.c linux-3.13.10-vs2.3.6.11/fs/btrfs/super.c
1857 --- linux-3.13.10/fs/btrfs/super.c      2014-01-22 20:39:05.000000000 +0000
1858 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/super.c   2014-01-31 23:58:08.000000000 +0000
1859 @@ -323,7 +323,7 @@ enum {
1860         Opt_commit_interval, Opt_barrier, Opt_nodefrag, Opt_nodiscard,
1861         Opt_noenospc_debug, Opt_noflushoncommit, Opt_acl, Opt_datacow,
1862         Opt_datasum, Opt_treelog, Opt_noinode_cache,
1863 -       Opt_err,
1864 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1865  };
1866  
1867  static match_table_t tokens = {
1868 @@ -365,6 +365,9 @@ static match_table_t tokens = {
1869         {Opt_rescan_uuid_tree, "rescan_uuid_tree"},
1870         {Opt_fatal_errors, "fatal_errors=%s"},
1871         {Opt_commit_interval, "commit=%d"},
1872 +       {Opt_tag, "tag"},
1873 +       {Opt_notag, "notag"},
1874 +       {Opt_tagid, "tagid=%u"},
1875         {Opt_err, NULL},
1876  };
1877  
1878 @@ -674,6 +677,22 @@ int btrfs_parse_options(struct btrfs_roo
1879                                 info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
1880                         }
1881                         break;
1882 +#ifndef CONFIG_TAGGING_NONE
1883 +               case Opt_tag:
1884 +                       printk(KERN_INFO "btrfs: use tagging\n");
1885 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1886 +                       break;
1887 +               case Opt_notag:
1888 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
1889 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
1890 +                       break;
1891 +#endif
1892 +#ifdef CONFIG_PROPAGATE
1893 +               case Opt_tagid:
1894 +                       /* use args[0] */
1895 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1896 +                       break;
1897 +#endif
1898                 case Opt_err:
1899                         printk(KERN_INFO "btrfs: unrecognized mount option "
1900                                "'%s'\n", p);
1901 @@ -1320,6 +1339,12 @@ static int btrfs_remount(struct super_bl
1902         btrfs_resize_thread_pool(fs_info,
1903                 fs_info->thread_pool_size, old_thread_pool_size);
1904  
1905 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1906 +               printk("btrfs: %s: tagging not permitted on remount.\n",
1907 +                       sb->s_id);
1908 +               return -EINVAL;
1909 +       }
1910 +
1911         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1912                 goto out;
1913  
1914 diff -NurpP --minimal linux-3.13.10/fs/char_dev.c linux-3.13.10-vs2.3.6.11/fs/char_dev.c
1915 --- linux-3.13.10/fs/char_dev.c 2014-01-22 20:39:05.000000000 +0000
1916 +++ linux-3.13.10-vs2.3.6.11/fs/char_dev.c      2014-01-31 20:38:03.000000000 +0000
1917 @@ -21,6 +21,8 @@
1918  #include <linux/mutex.h>
1919  #include <linux/backing-dev.h>
1920  #include <linux/tty.h>
1921 +#include <linux/vs_context.h>
1922 +#include <linux/vs_device.h>
1923  
1924  #include "internal.h"
1925  
1926 @@ -372,14 +374,21 @@ static int chrdev_open(struct inode *ino
1927         struct cdev *p;
1928         struct cdev *new = NULL;
1929         int ret = 0;
1930 +       dev_t mdev;
1931 +
1932 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
1933 +               return -EPERM;
1934 +       inode->i_mdev = mdev;
1935  
1936         spin_lock(&cdev_lock);
1937         p = inode->i_cdev;
1938         if (!p) {
1939                 struct kobject *kobj;
1940                 int idx;
1941 +
1942                 spin_unlock(&cdev_lock);
1943 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
1944 +
1945 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
1946                 if (!kobj)
1947                         return -ENXIO;
1948                 new = container_of(kobj, struct cdev, kobj);
1949 diff -NurpP --minimal linux-3.13.10/fs/dcache.c linux-3.13.10-vs2.3.6.11/fs/dcache.c
1950 --- linux-3.13.10/fs/dcache.c   2014-04-17 01:12:32.000000000 +0000
1951 +++ linux-3.13.10-vs2.3.6.11/fs/dcache.c        2014-04-17 01:17:10.000000000 +0000
1952 @@ -38,6 +38,7 @@
1953  #include <linux/prefetch.h>
1954  #include <linux/ratelimit.h>
1955  #include <linux/list_lru.h>
1956 +#include <linux/vs_limit.h>
1957  #include "internal.h"
1958  #include "mount.h"
1959  
1960 @@ -640,6 +641,8 @@ int d_invalidate(struct dentry * dentry)
1961                 spin_lock(&dentry->d_lock);
1962         }
1963  
1964 +       vx_dentry_dec(dentry);
1965 +
1966         /*
1967          * Somebody else still using it?
1968          *
1969 @@ -669,6 +672,7 @@ EXPORT_SYMBOL(d_invalidate);
1970  static inline void __dget_dlock(struct dentry *dentry)
1971  {
1972         dentry->d_lockref.count++;
1973 +       vx_dentry_inc(dentry);
1974  }
1975  
1976  static inline void __dget(struct dentry *dentry)
1977 @@ -1483,6 +1487,9 @@ struct dentry *__d_alloc(struct super_bl
1978         struct dentry *dentry;
1979         char *dname;
1980  
1981 +       if (!vx_dentry_avail(1))
1982 +               return NULL;
1983 +
1984         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
1985         if (!dentry)
1986                 return NULL;
1987 @@ -1515,6 +1522,7 @@ struct dentry *__d_alloc(struct super_bl
1988  
1989         dentry->d_lockref.count = 1;
1990         dentry->d_flags = 0;
1991 +       vx_dentry_inc(dentry);
1992         spin_lock_init(&dentry->d_lock);
1993         seqcount_init(&dentry->d_seq);
1994         dentry->d_inode = NULL;
1995 @@ -2278,6 +2286,7 @@ struct dentry *__d_lookup(const struct d
1996                 }
1997  
1998                 dentry->d_lockref.count++;
1999 +               vx_dentry_inc(dentry);
2000                 found = dentry;
2001                 spin_unlock(&dentry->d_lock);
2002                 break;
2003 diff -NurpP --minimal linux-3.13.10/fs/devpts/inode.c linux-3.13.10-vs2.3.6.11/fs/devpts/inode.c
2004 --- linux-3.13.10/fs/devpts/inode.c     2014-01-22 20:39:06.000000000 +0000
2005 +++ linux-3.13.10-vs2.3.6.11/fs/devpts/inode.c  2014-02-01 01:40:53.000000000 +0000
2006 @@ -25,6 +25,7 @@
2007  #include <linux/parser.h>
2008  #include <linux/fsnotify.h>
2009  #include <linux/seq_file.h>
2010 +#include <linux/vs_base.h>
2011  
2012  #define DEVPTS_DEFAULT_MODE 0600
2013  /*
2014 @@ -36,6 +37,21 @@
2015  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2016  #define PTMX_MINOR     2
2017  
2018 +static int devpts_permission(struct inode *inode, int mask)
2019 +{
2020 +       int ret = -EACCES;
2021 +
2022 +       /* devpts is xid tagged */
2023 +       if (vx_check((vxid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2024 +               ret = generic_permission(inode, mask);
2025 +       return ret;
2026 +}
2027 +
2028 +static struct inode_operations devpts_file_inode_operations = {
2029 +       .permission     = devpts_permission,
2030 +};
2031 +
2032 +
2033  /*
2034   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2035   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2036 @@ -345,6 +361,34 @@ static int devpts_show_options(struct se
2037         return 0;
2038  }
2039  
2040 +static int devpts_filter(struct dentry *de)
2041 +{
2042 +       vxid_t xid = 0;
2043 +
2044 +       /* devpts is xid tagged */
2045 +       if (de && de->d_inode)
2046 +               xid = (vxid_t)i_tag_read(de->d_inode);
2047 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2048 +       else
2049 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2050 +                       de->d_name.len, de->d_name.name);
2051 +#endif
2052 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2053 +}
2054 +
2055 +static int devpts_readdir(struct file * filp, struct dir_context *ctx)
2056 +{
2057 +       return dcache_readdir_filter(filp, ctx, devpts_filter);
2058 +}
2059 +
2060 +static struct file_operations devpts_dir_operations = {
2061 +       .open           = dcache_dir_open,
2062 +       .release        = dcache_dir_close,
2063 +       .llseek         = dcache_dir_lseek,
2064 +       .read           = generic_read_dir,
2065 +       .iterate        = devpts_readdir,
2066 +};
2067 +
2068  static const struct super_operations devpts_sops = {
2069         .statfs         = simple_statfs,
2070         .remount_fs     = devpts_remount,
2071 @@ -388,8 +432,10 @@ devpts_fill_super(struct super_block *s,
2072         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2073         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2074         inode->i_op = &simple_dir_inode_operations;
2075 -       inode->i_fop = &simple_dir_operations;
2076 +       inode->i_fop = &devpts_dir_operations;
2077         set_nlink(inode, 2);
2078 +       /* devpts is xid tagged */
2079 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2080  
2081         s->s_root = d_make_root(inode);
2082         if (s->s_root)
2083 @@ -593,6 +639,9 @@ struct inode *devpts_pty_new(struct inod
2084         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2085         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2086         init_special_inode(inode, S_IFCHR|opts->mode, device);
2087 +       /* devpts is xid tagged */
2088 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2089 +       inode->i_op = &devpts_file_inode_operations;
2090         inode->i_private = priv;
2091  
2092         sprintf(s, "%d", index);
2093 diff -NurpP --minimal linux-3.13.10/fs/ext2/balloc.c linux-3.13.10-vs2.3.6.11/fs/ext2/balloc.c
2094 --- linux-3.13.10/fs/ext2/balloc.c      2013-05-31 13:45:23.000000000 +0000
2095 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/balloc.c   2014-01-31 20:38:03.000000000 +0000
2096 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2097                         start = 0;
2098                 end = EXT2_BLOCKS_PER_GROUP(sb);
2099         }
2100 -
2101         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2102  
2103  repeat:
2104 diff -NurpP --minimal linux-3.13.10/fs/ext2/ext2.h linux-3.13.10-vs2.3.6.11/fs/ext2/ext2.h
2105 --- linux-3.13.10/fs/ext2/ext2.h        2012-12-11 03:30:57.000000000 +0000
2106 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ext2.h     2014-01-31 20:38:03.000000000 +0000
2107 @@ -244,8 +244,12 @@ struct ext2_group_desc
2108  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2109  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2110  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2111 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2112  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2113  
2114 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2115 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2116 +
2117  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2118  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2119  
2120 @@ -329,7 +333,8 @@ struct ext2_inode {
2121                         __u16   i_pad1;
2122                         __le16  l_i_uid_high;   /* these 2 fields    */
2123                         __le16  l_i_gid_high;   /* were reserved2[0] */
2124 -                       __u32   l_i_reserved2;
2125 +                       __le16  l_i_tag;        /* Context Tag */
2126 +                       __u16   l_i_reserved2;
2127                 } linux2;
2128                 struct {
2129                         __u8    h_i_frag;       /* Fragment number */
2130 @@ -357,6 +362,7 @@ struct ext2_inode {
2131  #define i_gid_low      i_gid
2132  #define i_uid_high     osd2.linux2.l_i_uid_high
2133  #define i_gid_high     osd2.linux2.l_i_gid_high
2134 +#define i_raw_tag      osd2.linux2.l_i_tag
2135  #define i_reserved2    osd2.linux2.l_i_reserved2
2136  
2137  /*
2138 @@ -384,6 +390,7 @@ struct ext2_inode {
2139  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2140  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2141  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2142 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2143  
2144  
2145  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2146 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2147  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2148  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2149                        u64 start, u64 len);
2150 +extern int ext2_sync_flags(struct inode *, int, int);
2151  
2152  /* ioctl.c */
2153  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2154 diff -NurpP --minimal linux-3.13.10/fs/ext2/file.c linux-3.13.10-vs2.3.6.11/fs/ext2/file.c
2155 --- linux-3.13.10/fs/ext2/file.c        2012-12-11 03:30:57.000000000 +0000
2156 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/file.c     2014-01-31 20:38:03.000000000 +0000
2157 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2158         .setattr        = ext2_setattr,
2159         .get_acl        = ext2_get_acl,
2160         .fiemap         = ext2_fiemap,
2161 +       .sync_flags     = ext2_sync_flags,
2162  };
2163 diff -NurpP --minimal linux-3.13.10/fs/ext2/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext2/ialloc.c
2164 --- linux-3.13.10/fs/ext2/ialloc.c      2013-05-31 13:45:23.000000000 +0000
2165 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ialloc.c   2014-01-31 20:38:03.000000000 +0000
2166 @@ -17,6 +17,7 @@
2167  #include <linux/backing-dev.h>
2168  #include <linux/buffer_head.h>
2169  #include <linux/random.h>
2170 +#include <linux/vs_tag.h>
2171  #include "ext2.h"
2172  #include "xattr.h"
2173  #include "acl.h"
2174 @@ -546,6 +547,7 @@ got:
2175                 inode->i_mode = mode;
2176                 inode->i_uid = current_fsuid();
2177                 inode->i_gid = dir->i_gid;
2178 +               i_tag_write(inode, dx_current_fstag(sb));
2179         } else
2180                 inode_init_owner(inode, dir, mode);
2181  
2182 diff -NurpP --minimal linux-3.13.10/fs/ext2/inode.c linux-3.13.10-vs2.3.6.11/fs/ext2/inode.c
2183 --- linux-3.13.10/fs/ext2/inode.c       2014-01-22 20:39:06.000000000 +0000
2184 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/inode.c    2014-01-31 20:38:03.000000000 +0000
2185 @@ -32,6 +32,7 @@
2186  #include <linux/fiemap.h>
2187  #include <linux/namei.h>
2188  #include <linux/aio.h>
2189 +#include <linux/vs_tag.h>
2190  #include "ext2.h"
2191  #include "acl.h"
2192  #include "xip.h"
2193 @@ -1182,7 +1183,7 @@ static void ext2_truncate_blocks(struct
2194                 return;
2195         if (ext2_inode_is_fast_symlink(inode))
2196                 return;
2197 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2198 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2199                 return;
2200         __ext2_truncate_blocks(inode, offset);
2201  }
2202 @@ -1273,36 +1274,61 @@ void ext2_set_inode_flags(struct inode *
2203  {
2204         unsigned int flags = EXT2_I(inode)->i_flags;
2205  
2206 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2207 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2208 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2209 +
2210 +
2211 +       if (flags & EXT2_IMMUTABLE_FL)
2212 +               inode->i_flags |= S_IMMUTABLE;
2213 +       if (flags & EXT2_IXUNLINK_FL)
2214 +               inode->i_flags |= S_IXUNLINK;
2215 +
2216         if (flags & EXT2_SYNC_FL)
2217                 inode->i_flags |= S_SYNC;
2218         if (flags & EXT2_APPEND_FL)
2219                 inode->i_flags |= S_APPEND;
2220 -       if (flags & EXT2_IMMUTABLE_FL)
2221 -               inode->i_flags |= S_IMMUTABLE;
2222         if (flags & EXT2_NOATIME_FL)
2223                 inode->i_flags |= S_NOATIME;
2224         if (flags & EXT2_DIRSYNC_FL)
2225                 inode->i_flags |= S_DIRSYNC;
2226 +
2227 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2228 +
2229 +       if (flags & EXT2_BARRIER_FL)
2230 +               inode->i_vflags |= V_BARRIER;
2231 +       if (flags & EXT2_COW_FL)
2232 +               inode->i_vflags |= V_COW;
2233  }
2234  
2235  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2236  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2237  {
2238         unsigned int flags = ei->vfs_inode.i_flags;
2239 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2240 +
2241 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2242 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2243 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2244 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2245 +
2246 +       if (flags & S_IMMUTABLE)
2247 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2248 +       if (flags & S_IXUNLINK)
2249 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2250  
2251 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2252 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2253         if (flags & S_SYNC)
2254                 ei->i_flags |= EXT2_SYNC_FL;
2255         if (flags & S_APPEND)
2256                 ei->i_flags |= EXT2_APPEND_FL;
2257 -       if (flags & S_IMMUTABLE)
2258 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2259         if (flags & S_NOATIME)
2260                 ei->i_flags |= EXT2_NOATIME_FL;
2261         if (flags & S_DIRSYNC)
2262                 ei->i_flags |= EXT2_DIRSYNC_FL;
2263 +
2264 +       if (vflags & V_BARRIER)
2265 +               ei->i_flags |= EXT2_BARRIER_FL;
2266 +       if (vflags & V_COW)
2267 +               ei->i_flags |= EXT2_COW_FL;
2268  }
2269  
2270  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2271 @@ -1338,8 +1364,10 @@ struct inode *ext2_iget (struct super_bl
2272                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2273                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2274         }
2275 -       i_uid_write(inode, i_uid);
2276 -       i_gid_write(inode, i_gid);
2277 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2278 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2279 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2280 +               le16_to_cpu(raw_inode->i_raw_tag)));
2281         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2282         inode->i_size = le32_to_cpu(raw_inode->i_size);
2283         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2284 @@ -1437,8 +1465,10 @@ static int __ext2_write_inode(struct ino
2285         struct ext2_inode_info *ei = EXT2_I(inode);
2286         struct super_block *sb = inode->i_sb;
2287         ino_t ino = inode->i_ino;
2288 -       uid_t uid = i_uid_read(inode);
2289 -       gid_t gid = i_gid_read(inode);
2290 +       uid_t uid = from_kuid(&init_user_ns,
2291 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2292 +       gid_t gid = from_kgid(&init_user_ns,
2293 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2294         struct buffer_head * bh;
2295         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2296         int n;
2297 @@ -1474,6 +1504,9 @@ static int __ext2_write_inode(struct ino
2298                 raw_inode->i_uid_high = 0;
2299                 raw_inode->i_gid_high = 0;
2300         }
2301 +#ifdef CONFIG_TAGGING_INTERN
2302 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2303 +#endif
2304         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2305         raw_inode->i_size = cpu_to_le32(inode->i_size);
2306         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2307 @@ -1554,7 +1587,8 @@ int ext2_setattr(struct dentry *dentry,
2308         if (is_quota_modification(inode, iattr))
2309                 dquot_initialize(inode);
2310         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2311 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2312 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2313 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2314                 error = dquot_transfer(inode, iattr);
2315                 if (error)
2316                         return error;
2317 diff -NurpP --minimal linux-3.13.10/fs/ext2/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext2/ioctl.c
2318 --- linux-3.13.10/fs/ext2/ioctl.c       2013-05-31 13:45:23.000000000 +0000
2319 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ioctl.c    2014-01-31 20:38:03.000000000 +0000
2320 @@ -17,6 +17,16 @@
2321  #include <asm/uaccess.h>
2322  
2323  
2324 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2325 +{
2326 +       inode->i_flags = flags;
2327 +       inode->i_vflags = vflags;
2328 +       ext2_get_inode_flags(EXT2_I(inode));
2329 +       inode->i_ctime = CURRENT_TIME_SEC;
2330 +       mark_inode_dirty(inode);
2331 +       return 0;
2332 +}
2333 +
2334  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2335  {
2336         struct inode *inode = file_inode(filp);
2337 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2338  
2339                 flags = ext2_mask_flags(inode->i_mode, flags);
2340  
2341 +               if (IS_BARRIER(inode)) {
2342 +                       vxwprintk_task(1, "messing with the barrier.");
2343 +                       return -EACCES;
2344 +               }
2345 +
2346                 mutex_lock(&inode->i_mutex);
2347                 /* Is it quota file? Do not allow user to mess with it */
2348                 if (IS_NOQUOTA(inode)) {
2349 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2350                  *
2351                  * This test looks nicer. Thanks to Pauline Middelink
2352                  */
2353 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2354 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2355 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2356 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2357                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2358                                 mutex_unlock(&inode->i_mutex);
2359                                 ret = -EPERM;
2360 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2361                         }
2362                 }
2363  
2364 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2365 +               flags &= EXT2_FL_USER_MODIFIABLE;
2366                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2367                 ei->i_flags = flags;
2368  
2369 diff -NurpP --minimal linux-3.13.10/fs/ext2/namei.c linux-3.13.10-vs2.3.6.11/fs/ext2/namei.c
2370 --- linux-3.13.10/fs/ext2/namei.c       2013-11-25 15:45:01.000000000 +0000
2371 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/namei.c    2014-01-31 20:38:03.000000000 +0000
2372 @@ -32,6 +32,7 @@
2373  
2374  #include <linux/pagemap.h>
2375  #include <linux/quotaops.h>
2376 +#include <linux/vs_tag.h>
2377  #include "ext2.h"
2378  #include "xattr.h"
2379  #include "acl.h"
2380 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2381                                         (unsigned long) ino);
2382                         return ERR_PTR(-EIO);
2383                 }
2384 +               dx_propagate_tag(nd, inode);
2385         }
2386         return d_splice_alias(inode, dentry);
2387  }
2388 @@ -432,5 +434,6 @@ const struct inode_operations ext2_speci
2389         .removexattr    = generic_removexattr,
2390  #endif
2391         .setattr        = ext2_setattr,
2392 +       .sync_flags     = ext2_sync_flags,
2393         .get_acl        = ext2_get_acl,
2394  };
2395 diff -NurpP --minimal linux-3.13.10/fs/ext2/super.c linux-3.13.10-vs2.3.6.11/fs/ext2/super.c
2396 --- linux-3.13.10/fs/ext2/super.c       2014-01-22 20:39:06.000000000 +0000
2397 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/super.c    2014-01-31 20:38:03.000000000 +0000
2398 @@ -395,7 +395,8 @@ enum {
2399         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2400         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2401         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2402 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2403 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2404 +       Opt_tag, Opt_notag, Opt_tagid
2405  };
2406  
2407  static const match_table_t tokens = {
2408 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2409         {Opt_acl, "acl"},
2410         {Opt_noacl, "noacl"},
2411         {Opt_xip, "xip"},
2412 +       {Opt_tag, "tag"},
2413 +       {Opt_notag, "notag"},
2414 +       {Opt_tagid, "tagid=%u"},
2415         {Opt_grpquota, "grpquota"},
2416         {Opt_ignore, "noquota"},
2417         {Opt_quota, "quota"},
2418 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2419                 case Opt_nouid32:
2420                         set_opt (sbi->s_mount_opt, NO_UID32);
2421                         break;
2422 +#ifndef CONFIG_TAGGING_NONE
2423 +               case Opt_tag:
2424 +                       set_opt (sbi->s_mount_opt, TAGGED);
2425 +                       break;
2426 +               case Opt_notag:
2427 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2428 +                       break;
2429 +#endif
2430 +#ifdef CONFIG_PROPAGATE
2431 +               case Opt_tagid:
2432 +                       /* use args[0] */
2433 +                       set_opt (sbi->s_mount_opt, TAGGED);
2434 +                       break;
2435 +#endif
2436                 case Opt_nocheck:
2437                         clear_opt (sbi->s_mount_opt, CHECK);
2438                         break;
2439 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2440         if (!parse_options((char *) data, sb))
2441                 goto failed_mount;
2442  
2443 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2444 +               sb->s_flags |= MS_TAGGED;
2445         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2446                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2447                  MS_POSIXACL : 0);
2448 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2449                 err = -EINVAL;
2450                 goto restore_opts;
2451         }
2452 +
2453 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2454 +               !(sb->s_flags & MS_TAGGED)) {
2455 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2456 +                      sb->s_id);
2457 +               err = -EINVAL;
2458 +               goto restore_opts;
2459 +       }
2460  
2461         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2462                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2463 diff -NurpP --minimal linux-3.13.10/fs/ext3/ext3.h linux-3.13.10-vs2.3.6.11/fs/ext3/ext3.h
2464 --- linux-3.13.10/fs/ext3/ext3.h        2012-12-11 03:30:57.000000000 +0000
2465 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ext3.h     2014-01-31 20:38:03.000000000 +0000
2466 @@ -151,10 +151,14 @@ struct ext3_group_desc
2467  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2468  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2469  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2470 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2471  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2472  
2473 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2474 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2475 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2476 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2477 +
2478 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2479 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2480  
2481  /* Flags that should be inherited by new inodes from their parent. */
2482  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2483 @@ -290,7 +294,8 @@ struct ext3_inode {
2484                         __u16   i_pad1;
2485                         __le16  l_i_uid_high;   /* these 2 fields    */
2486                         __le16  l_i_gid_high;   /* were reserved2[0] */
2487 -                       __u32   l_i_reserved2;
2488 +                       __le16  l_i_tag;        /* Context Tag */
2489 +                       __u16   l_i_reserved2;
2490                 } linux2;
2491                 struct {
2492                         __u8    h_i_frag;       /* Fragment number */
2493 @@ -320,6 +325,7 @@ struct ext3_inode {
2494  #define i_gid_low      i_gid
2495  #define i_uid_high     osd2.linux2.l_i_uid_high
2496  #define i_gid_high     osd2.linux2.l_i_gid_high
2497 +#define i_raw_tag      osd2.linux2.l_i_tag
2498  #define i_reserved2    osd2.linux2.l_i_reserved2
2499  
2500  /*
2501 @@ -364,6 +370,7 @@ struct ext3_inode {
2502  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2503  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2504                                                   * error in ordered mode */
2505 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2506  
2507  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2508  #ifndef _LINUX_EXT2_FS_H
2509 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2510  extern void ext3_set_aops(struct inode *inode);
2511  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2512                        u64 start, u64 len);
2513 +extern int ext3_sync_flags(struct inode *, int, int);
2514  
2515  /* ioctl.c */
2516  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2517 diff -NurpP --minimal linux-3.13.10/fs/ext3/file.c linux-3.13.10-vs2.3.6.11/fs/ext3/file.c
2518 --- linux-3.13.10/fs/ext3/file.c        2012-12-11 03:30:57.000000000 +0000
2519 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/file.c     2014-01-31 20:38:03.000000000 +0000
2520 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2521  #endif
2522         .get_acl        = ext3_get_acl,
2523         .fiemap         = ext3_fiemap,
2524 +       .sync_flags     = ext3_sync_flags,
2525  };
2526  
2527 diff -NurpP --minimal linux-3.13.10/fs/ext3/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext3/ialloc.c
2528 --- linux-3.13.10/fs/ext3/ialloc.c      2012-12-11 03:30:57.000000000 +0000
2529 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ialloc.c   2014-01-31 20:38:03.000000000 +0000
2530 @@ -14,6 +14,7 @@
2531  
2532  #include <linux/quotaops.h>
2533  #include <linux/random.h>
2534 +#include <linux/vs_tag.h>
2535  
2536  #include "ext3.h"
2537  #include "xattr.h"
2538 @@ -469,6 +470,7 @@ got:
2539                 inode->i_mode = mode;
2540                 inode->i_uid = current_fsuid();
2541                 inode->i_gid = dir->i_gid;
2542 +               i_tag_write(inode, dx_current_fstag(sb));
2543         } else
2544                 inode_init_owner(inode, dir, mode);
2545  
2546 diff -NurpP --minimal linux-3.13.10/fs/ext3/inode.c linux-3.13.10-vs2.3.6.11/fs/ext3/inode.c
2547 --- linux-3.13.10/fs/ext3/inode.c       2013-11-25 15:45:01.000000000 +0000
2548 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/inode.c    2014-01-31 20:38:03.000000000 +0000
2549 @@ -28,6 +28,8 @@
2550  #include <linux/mpage.h>
2551  #include <linux/namei.h>
2552  #include <linux/aio.h>
2553 +#include <linux/vs_tag.h>
2554 +
2555  #include "ext3.h"
2556  #include "xattr.h"
2557  #include "acl.h"
2558 @@ -2855,36 +2857,60 @@ void ext3_set_inode_flags(struct inode *
2559  {
2560         unsigned int flags = EXT3_I(inode)->i_flags;
2561  
2562 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2563 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2564 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2565 +
2566 +       if (flags & EXT3_IMMUTABLE_FL)
2567 +               inode->i_flags |= S_IMMUTABLE;
2568 +       if (flags & EXT3_IXUNLINK_FL)
2569 +               inode->i_flags |= S_IXUNLINK;
2570 +
2571         if (flags & EXT3_SYNC_FL)
2572                 inode->i_flags |= S_SYNC;
2573         if (flags & EXT3_APPEND_FL)
2574                 inode->i_flags |= S_APPEND;
2575 -       if (flags & EXT3_IMMUTABLE_FL)
2576 -               inode->i_flags |= S_IMMUTABLE;
2577         if (flags & EXT3_NOATIME_FL)
2578                 inode->i_flags |= S_NOATIME;
2579         if (flags & EXT3_DIRSYNC_FL)
2580                 inode->i_flags |= S_DIRSYNC;
2581 +
2582 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2583 +
2584 +       if (flags & EXT3_BARRIER_FL)
2585 +               inode->i_vflags |= V_BARRIER;
2586 +       if (flags & EXT3_COW_FL)
2587 +               inode->i_vflags |= V_COW;
2588  }
2589  
2590  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2591  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2592  {
2593         unsigned int flags = ei->vfs_inode.i_flags;
2594 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2595 +
2596 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2597 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2598 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2599 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2600 +
2601 +       if (flags & S_IMMUTABLE)
2602 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2603 +       if (flags & S_IXUNLINK)
2604 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2605  
2606 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2607 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2608         if (flags & S_SYNC)
2609                 ei->i_flags |= EXT3_SYNC_FL;
2610         if (flags & S_APPEND)
2611                 ei->i_flags |= EXT3_APPEND_FL;
2612 -       if (flags & S_IMMUTABLE)
2613 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2614         if (flags & S_NOATIME)
2615                 ei->i_flags |= EXT3_NOATIME_FL;
2616         if (flags & S_DIRSYNC)
2617                 ei->i_flags |= EXT3_DIRSYNC_FL;
2618 +
2619 +       if (vflags & V_BARRIER)
2620 +               ei->i_flags |= EXT3_BARRIER_FL;
2621 +       if (vflags & V_COW)
2622 +               ei->i_flags |= EXT3_COW_FL;
2623  }
2624  
2625  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2626 @@ -2922,8 +2948,10 @@ struct inode *ext3_iget(struct super_blo
2627                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2628                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2629         }
2630 -       i_uid_write(inode, i_uid);
2631 -       i_gid_write(inode, i_gid);
2632 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2633 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2634 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2635 +               le16_to_cpu(raw_inode->i_raw_tag)));
2636         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2637         inode->i_size = le32_to_cpu(raw_inode->i_size);
2638         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2639 @@ -3095,8 +3123,10 @@ again:
2640  
2641         ext3_get_inode_flags(ei);
2642         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2643 -       i_uid = i_uid_read(inode);
2644 -       i_gid = i_gid_read(inode);
2645 +       i_uid = from_kuid(&init_user_ns,
2646 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2647 +       i_gid = from_kgid(&init_user_ns,
2648 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2649         if(!(test_opt(inode->i_sb, NO_UID32))) {
2650                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2651                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2652 @@ -3121,6 +3151,9 @@ again:
2653                 raw_inode->i_uid_high = 0;
2654                 raw_inode->i_gid_high = 0;
2655         }
2656 +#ifdef CONFIG_TAGGING_INTERN
2657 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2658 +#endif
2659         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2660         disksize = cpu_to_le32(ei->i_disksize);
2661         if (disksize != raw_inode->i_size) {
2662 @@ -3289,7 +3322,8 @@ int ext3_setattr(struct dentry *dentry,
2663         if (is_quota_modification(inode, attr))
2664                 dquot_initialize(inode);
2665         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2666 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2667 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2668 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2669                 handle_t *handle;
2670  
2671                 /* (user+group)*(old+new) structure, inode write (sb,
2672 @@ -3311,6 +3345,8 @@ int ext3_setattr(struct dentry *dentry,
2673                         inode->i_uid = attr->ia_uid;
2674                 if (attr->ia_valid & ATTR_GID)
2675                         inode->i_gid = attr->ia_gid;
2676 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2677 +                       inode->i_tag = attr->ia_tag;
2678                 error = ext3_mark_inode_dirty(handle, inode);
2679                 ext3_journal_stop(handle);
2680         }
2681 diff -NurpP --minimal linux-3.13.10/fs/ext3/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext3/ioctl.c
2682 --- linux-3.13.10/fs/ext3/ioctl.c       2013-05-31 13:45:23.000000000 +0000
2683 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ioctl.c    2014-01-31 20:38:03.000000000 +0000
2684 @@ -12,6 +12,34 @@
2685  #include <asm/uaccess.h>
2686  #include "ext3.h"
2687  
2688 +
2689 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2690 +{
2691 +       handle_t *handle = NULL;
2692 +       struct ext3_iloc iloc;
2693 +       int err;
2694 +
2695 +       handle = ext3_journal_start(inode, 1);
2696 +       if (IS_ERR(handle))
2697 +               return PTR_ERR(handle);
2698 +
2699 +       if (IS_SYNC(inode))
2700 +               handle->h_sync = 1;
2701 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2702 +       if (err)
2703 +               goto flags_err;
2704 +
2705 +       inode->i_flags = flags;
2706 +       inode->i_vflags = vflags;
2707 +       ext3_get_inode_flags(EXT3_I(inode));
2708 +       inode->i_ctime = CURRENT_TIME_SEC;
2709 +
2710 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2711 +flags_err:
2712 +       ext3_journal_stop(handle);
2713 +       return err;
2714 +}
2715 +
2716  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2717  {
2718         struct inode *inode = file_inode(filp);
2719 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2720  
2721                 flags = ext3_mask_flags(inode->i_mode, flags);
2722  
2723 +               if (IS_BARRIER(inode)) {
2724 +                       vxwprintk_task(1, "messing with the barrier.");
2725 +                       return -EACCES;
2726 +               }
2727 +
2728                 mutex_lock(&inode->i_mutex);
2729  
2730                 /* Is it quota file? Do not allow user to mess with it */
2731 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2732                  *
2733                  * This test looks nicer. Thanks to Pauline Middelink
2734                  */
2735 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2736 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2737 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2738 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2739                         if (!capable(CAP_LINUX_IMMUTABLE))
2740                                 goto flags_out;
2741                 }
2742 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2743                 if (err)
2744                         goto flags_err;
2745  
2746 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2747 +               flags &= EXT3_FL_USER_MODIFIABLE;
2748                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2749                 ei->i_flags = flags;
2750  
2751 diff -NurpP --minimal linux-3.13.10/fs/ext3/namei.c linux-3.13.10-vs2.3.6.11/fs/ext3/namei.c
2752 --- linux-3.13.10/fs/ext3/namei.c       2013-11-25 15:46:59.000000000 +0000
2753 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/namei.c    2014-01-31 20:38:03.000000000 +0000
2754 @@ -25,6 +25,8 @@
2755   */
2756  
2757  #include <linux/quotaops.h>
2758 +#include <linux/vs_tag.h>
2759 +
2760  #include "ext3.h"
2761  #include "namei.h"
2762  #include "xattr.h"
2763 @@ -915,6 +917,7 @@ restart:
2764                                         submit_bh(READ | REQ_META | REQ_PRIO,
2765                                                   bh);
2766                                 }
2767 +               dx_propagate_tag(nd, inode);
2768                         }
2769                 }
2770                 if ((bh = bh_use[ra_ptr++]) == NULL)
2771 @@ -2568,6 +2571,7 @@ const struct inode_operations ext3_dir_i
2772         .listxattr      = ext3_listxattr,
2773         .removexattr    = generic_removexattr,
2774  #endif
2775 +       .sync_flags     = ext3_sync_flags,
2776         .get_acl        = ext3_get_acl,
2777  };
2778  
2779 diff -NurpP --minimal linux-3.13.10/fs/ext3/super.c linux-3.13.10-vs2.3.6.11/fs/ext3/super.c
2780 --- linux-3.13.10/fs/ext3/super.c       2014-01-22 20:39:06.000000000 +0000
2781 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/super.c    2014-01-31 20:38:03.000000000 +0000
2782 @@ -826,7 +826,8 @@ enum {
2783         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2784         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2785         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2786 -       Opt_resize, Opt_usrquota, Opt_grpquota
2787 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2788 +       Opt_tag, Opt_notag, Opt_tagid
2789  };
2790  
2791  static const match_table_t tokens = {
2792 @@ -884,6 +885,9 @@ static const match_table_t tokens = {
2793         {Opt_barrier, "barrier"},
2794         {Opt_nobarrier, "nobarrier"},
2795         {Opt_resize, "resize"},
2796 +       {Opt_tag, "tag"},
2797 +       {Opt_notag, "notag"},
2798 +       {Opt_tagid, "tagid=%u"},
2799         {Opt_err, NULL},
2800  };
2801  
2802 @@ -1056,6 +1060,20 @@ static int parse_options (char *options,
2803                 case Opt_nouid32:
2804                         set_opt (sbi->s_mount_opt, NO_UID32);
2805                         break;
2806 +#ifndef CONFIG_TAGGING_NONE
2807 +               case Opt_tag:
2808 +                       set_opt (sbi->s_mount_opt, TAGGED);
2809 +                       break;
2810 +               case Opt_notag:
2811 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2812 +                       break;
2813 +#endif
2814 +#ifdef CONFIG_PROPAGATE
2815 +               case Opt_tagid:
2816 +                       /* use args[0] */
2817 +                       set_opt (sbi->s_mount_opt, TAGGED);
2818 +                       break;
2819 +#endif
2820                 case Opt_nocheck:
2821                         clear_opt (sbi->s_mount_opt, CHECK);
2822                         break;
2823 @@ -1788,6 +1806,9 @@ static int ext3_fill_super (struct super
2824                             NULL, 0))
2825                 goto failed_mount;
2826  
2827 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2828 +               sb->s_flags |= MS_TAGGED;
2829 +
2830         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2831                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2832  
2833 @@ -2683,6 +2704,14 @@ static int ext3_remount (struct super_bl
2834         if (test_opt(sb, ABORT))
2835                 ext3_abort(sb, __func__, "Abort forced by user");
2836  
2837 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2838 +               !(sb->s_flags & MS_TAGGED)) {
2839 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2840 +                       sb->s_id);
2841 +               err = -EINVAL;
2842 +               goto restore_opts;
2843 +       }
2844 +
2845         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2846                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2847  
2848 diff -NurpP --minimal linux-3.13.10/fs/ext4/ext4.h linux-3.13.10-vs2.3.6.11/fs/ext4/ext4.h
2849 --- linux-3.13.10/fs/ext4/ext4.h        2014-04-17 01:12:32.000000000 +0000
2850 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ext4.h     2014-03-12 15:51:07.000000000 +0000
2851 @@ -385,7 +385,10 @@ struct flex_groups {
2852  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2853  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2854  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2855 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2856 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2857  #define EXT4_INLINE_DATA_FL            0x10000000 /* Inode has inline data. */
2858 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
2859  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2860  
2861  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2862 @@ -670,7 +673,7 @@ struct ext4_inode {
2863                         __le16  l_i_uid_high;   /* these 2 fields */
2864                         __le16  l_i_gid_high;   /* were reserved2[0] */
2865                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2866 -                       __le16  l_i_reserved;
2867 +                       __le16  l_i_tag;        /* Context Tag */
2868                 } linux2;
2869                 struct {
2870                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
2871 @@ -790,6 +793,7 @@ do {                                                                               \
2872  #define i_gid_low      i_gid
2873  #define i_uid_high     osd2.linux2.l_i_uid_high
2874  #define i_gid_high     osd2.linux2.l_i_gid_high
2875 +#define i_raw_tag      osd2.linux2.l_i_tag
2876  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
2877  
2878  #elif defined(__GNU__)
2879 @@ -976,6 +980,7 @@ struct ext4_inode_info {
2880  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
2881  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
2882  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
2883 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
2884  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
2885  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
2886  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2887 @@ -2653,6 +2658,7 @@ extern struct buffer_head *ext4_get_firs
2888  extern int ext4_inline_data_fiemap(struct inode *inode,
2889                                    struct fiemap_extent_info *fieinfo,
2890                                    int *has_inline);
2891 +extern int ext4_sync_flags(struct inode *, int, int);
2892  extern int ext4_try_to_evict_inline_data(handle_t *handle,
2893                                          struct inode *inode,
2894                                          int needed);
2895 diff -NurpP --minimal linux-3.13.10/fs/ext4/file.c linux-3.13.10-vs2.3.6.11/fs/ext4/file.c
2896 --- linux-3.13.10/fs/ext4/file.c        2013-11-25 15:46:59.000000000 +0000
2897 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/file.c     2014-01-31 20:38:03.000000000 +0000
2898 @@ -618,5 +618,6 @@ const struct inode_operations ext4_file_
2899         .removexattr    = generic_removexattr,
2900         .get_acl        = ext4_get_acl,
2901         .fiemap         = ext4_fiemap,
2902 +       .sync_flags     = ext4_sync_flags,
2903  };
2904  
2905 diff -NurpP --minimal linux-3.13.10/fs/ext4/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext4/ialloc.c
2906 --- linux-3.13.10/fs/ext4/ialloc.c      2014-01-22 20:39:06.000000000 +0000
2907 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ialloc.c   2014-01-31 20:38:03.000000000 +0000
2908 @@ -22,6 +22,7 @@
2909  #include <linux/random.h>
2910  #include <linux/bitops.h>
2911  #include <linux/blkdev.h>
2912 +#include <linux/vs_tag.h>
2913  #include <asm/byteorder.h>
2914  
2915  #include "ext4.h"
2916 @@ -731,6 +732,7 @@ struct inode *__ext4_new_inode(handle_t
2917                 inode->i_mode = mode;
2918                 inode->i_uid = current_fsuid();
2919                 inode->i_gid = dir->i_gid;
2920 +               i_tag_write(inode, dx_current_fstag(sb));
2921         } else
2922                 inode_init_owner(inode, dir, mode);
2923         dquot_initialize(inode);
2924 diff -NurpP --minimal linux-3.13.10/fs/ext4/inode.c linux-3.13.10-vs2.3.6.11/fs/ext4/inode.c
2925 --- linux-3.13.10/fs/ext4/inode.c       2014-04-17 01:12:32.000000000 +0000
2926 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/inode.c    2014-04-17 01:28:13.000000000 +0000
2927 @@ -39,6 +39,7 @@
2928  #include <linux/ratelimit.h>
2929  #include <linux/aio.h>
2930  #include <linux/bitops.h>
2931 +#include <linux/vs_tag.h>
2932  
2933  #include "ext4_jbd2.h"
2934  #include "xattr.h"
2935 @@ -3929,42 +3930,67 @@ void ext4_set_inode_flags(struct inode *
2936         unsigned int flags = EXT4_I(inode)->i_flags;
2937         unsigned int new_fl = 0;
2938  
2939 +       if (flags & EXT4_IMMUTABLE_FL)
2940 +               new_fl |= S_IMMUTABLE;
2941 +       if (flags & EXT4_IXUNLINK_FL)
2942 +               new_fl |= S_IXUNLINK;
2943 +
2944         if (flags & EXT4_SYNC_FL)
2945                 new_fl |= S_SYNC;
2946         if (flags & EXT4_APPEND_FL)
2947                 new_fl |= S_APPEND;
2948 -       if (flags & EXT4_IMMUTABLE_FL)
2949 -               new_fl |= S_IMMUTABLE;
2950         if (flags & EXT4_NOATIME_FL)
2951                 new_fl |= S_NOATIME;
2952         if (flags & EXT4_DIRSYNC_FL)
2953                 new_fl |= S_DIRSYNC;
2954 +
2955         set_mask_bits(&inode->i_flags,
2956 -                     S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC, new_fl);
2957 +               S_IXUNLINK | S_IMMUTABLE |
2958 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC, new_fl);
2959 +
2960 +       new_fl = 0;
2961 +       if (flags & EXT4_BARRIER_FL)
2962 +               new_fl |= V_BARRIER;
2963 +       if (flags & EXT4_COW_FL)
2964 +               new_fl |= V_COW;
2965 +
2966 +       set_mask_bits(&inode->i_vflags,
2967 +               V_BARRIER | V_COW, new_fl);
2968  }
2969  
2970  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2971  void ext4_get_inode_flags(struct ext4_inode_info *ei)
2972  {
2973 -       unsigned int vfs_fl;
2974 +       unsigned int vfs_fl, vfs_vf;
2975         unsigned long old_fl, new_fl;
2976  
2977         do {
2978                 vfs_fl = ei->vfs_inode.i_flags;
2979 +               vfs_vf = ei->vfs_inode.i_vflags;
2980                 old_fl = ei->i_flags;
2981                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2982                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
2983 -                               EXT4_DIRSYNC_FL);
2984 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
2985 +                               EXT4_COW_FL);
2986 +
2987 +               if (vfs_fl & S_IMMUTABLE)
2988 +                       new_fl |= EXT4_IMMUTABLE_FL;
2989 +               if (vfs_fl & S_IXUNLINK)
2990 +                       new_fl |= EXT4_IXUNLINK_FL;
2991 +
2992                 if (vfs_fl & S_SYNC)
2993                         new_fl |= EXT4_SYNC_FL;
2994                 if (vfs_fl & S_APPEND)
2995                         new_fl |= EXT4_APPEND_FL;
2996 -               if (vfs_fl & S_IMMUTABLE)
2997 -                       new_fl |= EXT4_IMMUTABLE_FL;
2998                 if (vfs_fl & S_NOATIME)
2999                         new_fl |= EXT4_NOATIME_FL;
3000                 if (vfs_fl & S_DIRSYNC)
3001                         new_fl |= EXT4_DIRSYNC_FL;
3002 +
3003 +               if (vfs_vf & V_BARRIER)
3004 +                       new_fl |= EXT4_BARRIER_FL;
3005 +               if (vfs_vf & V_COW)
3006 +                       new_fl |= EXT4_COW_FL;
3007         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3008  }
3009  
3010 @@ -4069,8 +4095,10 @@ struct inode *ext4_iget(struct super_blo
3011                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3012                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3013         }
3014 -       i_uid_write(inode, i_uid);
3015 -       i_gid_write(inode, i_gid);
3016 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3017 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3018 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3019 +               le16_to_cpu(raw_inode->i_raw_tag)));
3020         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3021  
3022         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3023 @@ -4298,8 +4326,10 @@ static int ext4_do_update_inode(handle_t
3024  
3025         ext4_get_inode_flags(ei);
3026         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3027 -       i_uid = i_uid_read(inode);
3028 -       i_gid = i_gid_read(inode);
3029 +       i_uid = from_kuid(&init_user_ns,
3030 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
3031 +       i_gid = from_kgid(&init_user_ns,
3032 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
3033         if (!(test_opt(inode->i_sb, NO_UID32))) {
3034                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3035                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3036 @@ -4322,6 +4352,9 @@ static int ext4_do_update_inode(handle_t
3037                 raw_inode->i_uid_high = 0;
3038                 raw_inode->i_gid_high = 0;
3039         }
3040 +#ifdef CONFIG_TAGGING_INTERN
3041 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3042 +#endif
3043         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3044  
3045         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3046 @@ -4553,7 +4586,8 @@ int ext4_setattr(struct dentry *dentry,
3047         if (is_quota_modification(inode, attr))
3048                 dquot_initialize(inode);
3049         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3050 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3051 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3052 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3053                 handle_t *handle;
3054  
3055                 /* (user+group)*(old+new) structure, inode write (sb,
3056 @@ -4576,6 +4610,8 @@ int ext4_setattr(struct dentry *dentry,
3057                         inode->i_uid = attr->ia_uid;
3058                 if (attr->ia_valid & ATTR_GID)
3059                         inode->i_gid = attr->ia_gid;
3060 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3061 +                       inode->i_tag = attr->ia_tag;
3062                 error = ext4_mark_inode_dirty(handle, inode);
3063                 ext4_journal_stop(handle);
3064         }
3065 diff -NurpP --minimal linux-3.13.10/fs/ext4/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext4/ioctl.c
3066 --- linux-3.13.10/fs/ext4/ioctl.c       2014-04-17 01:12:32.000000000 +0000
3067 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ioctl.c    2014-03-12 15:51:07.000000000 +0000
3068 @@ -14,6 +14,7 @@
3069  #include <linux/compat.h>
3070  #include <linux/mount.h>
3071  #include <linux/file.h>
3072 +#include <linux/vs_tag.h>
3073  #include <asm/uaccess.h>
3074  #include "ext4_jbd2.h"
3075  #include "ext4.h"
3076 @@ -214,6 +215,33 @@ swap_boot_out:
3077         return err;
3078  }
3079  
3080 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3081 +{
3082 +       handle_t *handle = NULL;
3083 +       struct ext4_iloc iloc;
3084 +       int err;
3085 +
3086 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3087 +       if (IS_ERR(handle))
3088 +               return PTR_ERR(handle);
3089 +
3090 +       if (IS_SYNC(inode))
3091 +               ext4_handle_sync(handle);
3092 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3093 +       if (err)
3094 +               goto flags_err;
3095 +
3096 +       inode->i_flags = flags;
3097 +       inode->i_vflags = vflags;
3098 +       ext4_get_inode_flags(EXT4_I(inode));
3099 +       inode->i_ctime = ext4_current_time(inode);
3100 +
3101 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3102 +flags_err:
3103 +       ext4_journal_stop(handle);
3104 +       return err;
3105 +}
3106 +
3107  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3108  {
3109         struct inode *inode = file_inode(filp);
3110 @@ -247,6 +275,11 @@ long ext4_ioctl(struct file *filp, unsig
3111  
3112                 flags = ext4_mask_flags(inode->i_mode, flags);
3113  
3114 +               if (IS_BARRIER(inode)) {
3115 +                       vxwprintk_task(1, "messing with the barrier.");
3116 +                       return -EACCES;
3117 +               }
3118 +
3119                 err = -EPERM;
3120                 mutex_lock(&inode->i_mutex);
3121                 /* Is it quota file? Do not allow user to mess with it */
3122 @@ -264,7 +297,9 @@ long ext4_ioctl(struct file *filp, unsig
3123                  *
3124                  * This test looks nicer. Thanks to Pauline Middelink
3125                  */
3126 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3127 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3128 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3129 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3130                         if (!capable(CAP_LINUX_IMMUTABLE))
3131                                 goto flags_out;
3132                 }
3133 diff -NurpP --minimal linux-3.13.10/fs/ext4/namei.c linux-3.13.10-vs2.3.6.11/fs/ext4/namei.c
3134 --- linux-3.13.10/fs/ext4/namei.c       2013-11-25 15:46:59.000000000 +0000
3135 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/namei.c    2014-01-31 20:38:03.000000000 +0000
3136 @@ -34,6 +34,7 @@
3137  #include <linux/quotaops.h>
3138  #include <linux/buffer_head.h>
3139  #include <linux/bio.h>
3140 +#include <linux/vs_tag.h>
3141  #include "ext4.h"
3142  #include "ext4_jbd2.h"
3143  
3144 @@ -1299,6 +1300,7 @@ restart:
3145                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3146                                                     1, &bh);
3147                         }
3148 +               dx_propagate_tag(nd, inode);
3149                 }
3150                 if ((bh = bh_use[ra_ptr++]) == NULL)
3151                         goto next;
3152 @@ -3226,6 +3228,7 @@ const struct inode_operations ext4_dir_i
3153         .removexattr    = generic_removexattr,
3154         .get_acl        = ext4_get_acl,
3155         .fiemap         = ext4_fiemap,
3156 +       .sync_flags     = ext4_sync_flags,
3157  };
3158  
3159  const struct inode_operations ext4_special_inode_operations = {
3160 diff -NurpP --minimal linux-3.13.10/fs/ext4/super.c linux-3.13.10-vs2.3.6.11/fs/ext4/super.c
3161 --- linux-3.13.10/fs/ext4/super.c       2014-04-17 01:12:32.000000000 +0000
3162 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/super.c    2014-03-12 15:51:07.000000000 +0000
3163 @@ -1162,7 +1162,7 @@ enum {
3164         Opt_inode_readahead_blks, Opt_journal_ioprio,
3165         Opt_dioread_nolock, Opt_dioread_lock,
3166         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3167 -       Opt_max_dir_size_kb,
3168 +       Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3169  };
3170  
3171  static const match_table_t tokens = {
3172 @@ -1243,6 +1243,9 @@ static const match_table_t tokens = {
3173         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3174         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3175         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3176 +       {Opt_tag, "tag"},
3177 +       {Opt_notag, "notag"},
3178 +       {Opt_tagid, "tagid=%u"},
3179         {Opt_err, NULL},
3180  };
3181  
3182 @@ -1475,6 +1478,20 @@ static int handle_mount_opt(struct super
3183         case Opt_i_version:
3184                 sb->s_flags |= MS_I_VERSION;
3185                 return 1;
3186 +#ifndef CONFIG_TAGGING_NONE
3187 +       case Opt_tag:
3188 +               set_opt(sb, TAGGED);
3189 +               return 1;
3190 +       case Opt_notag:
3191 +               clear_opt(sb, TAGGED);
3192 +               return 1;
3193 +#endif
3194 +#ifdef CONFIG_PROPAGATE
3195 +       case Opt_tagid:
3196 +               /* use args[0] */
3197 +               set_opt(sb, TAGGED);
3198 +               return 1;
3199 +#endif
3200         }
3201  
3202         for (m = ext4_mount_opts; m->token != Opt_err; m++)
3203 @@ -3564,6 +3581,9 @@ static int ext4_fill_super(struct super_
3204                         clear_opt(sb, DELALLOC);
3205         }
3206  
3207 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3208 +               sb->s_flags |= MS_TAGGED;
3209 +
3210         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3211                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3212  
3213 @@ -4818,6 +4838,14 @@ static int ext4_remount(struct super_blo
3214         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3215                 ext4_abort(sb, "Abort forced by user");
3216  
3217 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3218 +               !(sb->s_flags & MS_TAGGED)) {
3219 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3220 +                       sb->s_id);
3221 +               err = -EINVAL;
3222 +               goto restore_opts;
3223 +       }
3224 +
3225         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3226                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3227  
3228 diff -NurpP --minimal linux-3.13.10/fs/fcntl.c linux-3.13.10-vs2.3.6.11/fs/fcntl.c
3229 --- linux-3.13.10/fs/fcntl.c    2014-01-22 20:39:06.000000000 +0000
3230 +++ linux-3.13.10-vs2.3.6.11/fs/fcntl.c 2014-01-31 20:38:03.000000000 +0000
3231 @@ -21,6 +21,7 @@
3232  #include <linux/rcupdate.h>
3233  #include <linux/pid_namespace.h>
3234  #include <linux/user_namespace.h>
3235 +#include <linux/vs_limit.h>
3236  
3237  #include <asm/poll.h>
3238  #include <asm/siginfo.h>
3239 @@ -377,6 +378,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3240  
3241         if (!f.file)
3242                 goto out;
3243 +       if (!vx_files_avail(1))
3244 +               goto out;
3245  
3246         if (unlikely(f.file->f_mode & FMODE_PATH)) {
3247                 if (!check_fcntl_cmd(cmd))
3248 diff -NurpP --minimal linux-3.13.10/fs/file.c linux-3.13.10-vs2.3.6.11/fs/file.c
3249 --- linux-3.13.10/fs/file.c     2014-04-17 01:12:32.000000000 +0000
3250 +++ linux-3.13.10-vs2.3.6.11/fs/file.c  2014-02-25 11:26:09.000000000 +0000
3251 @@ -22,6 +22,7 @@
3252  #include <linux/spinlock.h>
3253  #include <linux/rcupdate.h>
3254  #include <linux/workqueue.h>
3255 +#include <linux/vs_limit.h>
3256  
3257  int sysctl_nr_open __read_mostly = 1024*1024;
3258  int sysctl_nr_open_min = BITS_PER_LONG;
3259 @@ -311,6 +312,8 @@ struct files_struct *dup_fd(struct files
3260                 struct file *f = *old_fds++;
3261                 if (f) {
3262                         get_file(f);
3263 +                       /* TODO: sum it first for check and performance */
3264 +                       vx_openfd_inc(open_files - i);
3265                 } else {
3266                         /*
3267                          * The fd may be claimed in the fd bitmap but not yet
3268 @@ -376,9 +379,11 @@ static void close_files(struct files_str
3269                                         filp_close(file, files);
3270                                         cond_resched();
3271                                 }
3272 +                               vx_openfd_dec(i);
3273                         }
3274                         i++;
3275                         set >>= 1;
3276 +                       cond_resched();
3277                 }
3278         }
3279  }
3280 @@ -503,6 +508,7 @@ repeat:
3281         else
3282                 __clear_close_on_exec(fd, fdt);
3283         error = fd;
3284 +       vx_openfd_inc(fd);
3285  #if 1
3286         /* Sanity check */
3287         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3288 @@ -533,6 +539,7 @@ static void __put_unused_fd(struct files
3289         __clear_open_fd(fd, fdt);
3290         if (fd < files->next_fd)
3291                 files->next_fd = fd;
3292 +       vx_openfd_dec(fd);
3293  }
3294  
3295  void put_unused_fd(unsigned int fd)
3296 @@ -812,6 +819,8 @@ static int do_dup2(struct files_struct *
3297  
3298         if (tofree)
3299                 filp_close(tofree, files);
3300 +       else
3301 +               vx_openfd_inc(fd);      /* fd was unused */
3302  
3303         return fd;
3304  
3305 diff -NurpP --minimal linux-3.13.10/fs/file_table.c linux-3.13.10-vs2.3.6.11/fs/file_table.c
3306 --- linux-3.13.10/fs/file_table.c       2014-01-22 20:39:06.000000000 +0000
3307 +++ linux-3.13.10-vs2.3.6.11/fs/file_table.c    2014-02-01 00:00:01.000000000 +0000
3308 @@ -26,6 +26,8 @@
3309  #include <linux/hardirq.h>
3310  #include <linux/task_work.h>
3311  #include <linux/ima.h>
3312 +#include <linux/vs_limit.h>
3313 +#include <linux/vs_context.h>
3314  
3315  #include <linux/atomic.h>
3316  
3317 @@ -137,6 +139,8 @@ struct file *get_empty_filp(void)
3318         spin_lock_init(&f->f_lock);
3319         eventpoll_init_file(f);
3320         /* f->f_version: 0 */
3321 +       f->f_xid = vx_current_xid();
3322 +       vx_files_inc(f);
3323         return f;
3324  
3325  over:
3326 @@ -254,6 +258,8 @@ static void __fput(struct file *file)
3327                 i_readcount_dec(inode);
3328         if (file->f_mode & FMODE_WRITE)
3329                 drop_file_write_access(file);
3330 +       vx_files_dec(file);
3331 +       file->f_xid = 0;
3332         file->f_path.dentry = NULL;
3333         file->f_path.mnt = NULL;
3334         file->f_inode = NULL;
3335 @@ -340,6 +346,8 @@ void put_filp(struct file *file)
3336  {
3337         if (atomic_long_dec_and_test(&file->f_count)) {
3338                 security_file_free(file);
3339 +               vx_files_dec(file);
3340 +               file->f_xid = 0;
3341                 file_free(file);
3342         }
3343  }
3344 diff -NurpP --minimal linux-3.13.10/fs/fs_struct.c linux-3.13.10-vs2.3.6.11/fs/fs_struct.c
3345 --- linux-3.13.10/fs/fs_struct.c        2014-01-22 20:39:06.000000000 +0000
3346 +++ linux-3.13.10-vs2.3.6.11/fs/fs_struct.c     2014-01-31 20:38:03.000000000 +0000
3347 @@ -4,6 +4,7 @@
3348  #include <linux/path.h>
3349  #include <linux/slab.h>
3350  #include <linux/fs_struct.h>
3351 +#include <linux/vserver/global.h>
3352  #include "internal.h"
3353  
3354  /*
3355 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3356  {
3357         path_put(&fs->root);
3358         path_put(&fs->pwd);
3359 +       atomic_dec(&vs_global_fs);
3360         kmem_cache_free(fs_cachep, fs);
3361  }
3362  
3363 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3364                 fs->pwd = old->pwd;
3365                 path_get(&fs->pwd);
3366                 spin_unlock(&old->lock);
3367 +               atomic_inc(&vs_global_fs);
3368         }
3369         return fs;
3370  }
3371 diff -NurpP --minimal linux-3.13.10/fs/gfs2/file.c linux-3.13.10-vs2.3.6.11/fs/gfs2/file.c
3372 --- linux-3.13.10/fs/gfs2/file.c        2014-01-22 20:39:06.000000000 +0000
3373 +++ linux-3.13.10-vs2.3.6.11/fs/gfs2/file.c     2014-01-31 20:38:03.000000000 +0000
3374 @@ -137,6 +137,9 @@ static const u32 fsflags_to_gfs2[32] = {
3375         [12] = GFS2_DIF_EXHASH,
3376         [14] = GFS2_DIF_INHERIT_JDATA,
3377         [17] = GFS2_DIF_TOPDIR,
3378 +       [27] = GFS2_DIF_IXUNLINK,
3379 +       [26] = GFS2_DIF_BARRIER,
3380 +       [29] = GFS2_DIF_COW,
3381  };
3382  
3383  static const u32 gfs2_to_fsflags[32] = {
3384 @@ -147,6 +150,9 @@ static const u32 gfs2_to_fsflags[32] = {
3385         [gfs2fl_ExHash] = FS_INDEX_FL,
3386         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3387         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3388 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3389 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3390 +       [gfs2fl_Cow] = FS_COW_FL,
3391  };
3392  
3393  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3394 @@ -177,12 +183,18 @@ void gfs2_set_inode_flags(struct inode *
3395  {
3396         struct gfs2_inode *ip = GFS2_I(inode);
3397         unsigned int flags = inode->i_flags;
3398 +       unsigned int vflags = inode->i_vflags;
3399 +
3400 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3401 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3402  
3403 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3404         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3405                 inode->i_flags |= S_NOSEC;
3406         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3407                 flags |= S_IMMUTABLE;
3408 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3409 +               flags |= S_IXUNLINK;
3410 +
3411         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3412                 flags |= S_APPEND;
3413         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3414 @@ -190,6 +202,43 @@ void gfs2_set_inode_flags(struct inode *
3415         if (ip->i_diskflags & GFS2_DIF_SYNC)
3416                 flags |= S_SYNC;
3417         inode->i_flags = flags;
3418 +
3419 +       vflags &= ~(V_BARRIER | V_COW);
3420 +
3421 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3422 +               vflags |= V_BARRIER;
3423 +       if (ip->i_diskflags & GFS2_DIF_COW)
3424 +               vflags |= V_COW;
3425 +       inode->i_vflags = vflags;
3426 +}
3427 +
3428 +void gfs2_get_inode_flags(struct inode *inode)
3429 +{
3430 +       struct gfs2_inode *ip = GFS2_I(inode);
3431 +       unsigned int flags = inode->i_flags;
3432 +       unsigned int vflags = inode->i_vflags;
3433 +
3434 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3435 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3436 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3437 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3438 +
3439 +       if (flags & S_IMMUTABLE)
3440 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3441 +       if (flags & S_IXUNLINK)
3442 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3443 +
3444 +       if (flags & S_APPEND)
3445 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3446 +       if (flags & S_NOATIME)
3447 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3448 +       if (flags & S_SYNC)
3449 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3450 +
3451 +       if (vflags & V_BARRIER)
3452 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3453 +       if (vflags & V_COW)
3454 +               ip->i_diskflags |= GFS2_DIF_COW;
3455  }
3456  
3457  /* Flags that can be set by user space */
3458 @@ -303,6 +352,37 @@ static int gfs2_set_flags(struct file *f
3459         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3460  }
3461  
3462 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3463 +{
3464 +       struct gfs2_inode *ip = GFS2_I(inode);
3465 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3466 +       struct buffer_head *bh;
3467 +       struct gfs2_holder gh;
3468 +       int error;
3469 +
3470 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3471 +       if (error)
3472 +               return error;
3473 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3474 +       if (error)
3475 +               goto out;
3476 +       error = gfs2_meta_inode_buffer(ip, &bh);
3477 +       if (error)
3478 +               goto out_trans_end;
3479 +       gfs2_trans_add_meta(ip->i_gl, bh);
3480 +       inode->i_flags = flags;
3481 +       inode->i_vflags = vflags;
3482 +       gfs2_get_inode_flags(inode);
3483 +       gfs2_dinode_out(ip, bh->b_data);
3484 +       brelse(bh);
3485 +       gfs2_set_aops(inode);
3486 +out_trans_end:
3487 +       gfs2_trans_end(sdp);
3488 +out:
3489 +       gfs2_glock_dq_uninit(&gh);
3490 +       return error;
3491 +}
3492 +
3493  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3494  {
3495         switch(cmd) {
3496 diff -NurpP --minimal linux-3.13.10/fs/gfs2/inode.h linux-3.13.10-vs2.3.6.11/fs/gfs2/inode.h
3497 --- linux-3.13.10/fs/gfs2/inode.h       2013-11-25 15:45:01.000000000 +0000
3498 +++ linux-3.13.10-vs2.3.6.11/fs/gfs2/inode.h    2014-01-31 20:38:03.000000000 +0000
3499 @@ -118,6 +118,7 @@ extern const struct file_operations gfs2
3500  extern const struct file_operations gfs2_dir_fops_nolock;
3501  
3502  extern void gfs2_set_inode_flags(struct inode *inode);
3503 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3504   
3505  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3506  extern const struct file_operations gfs2_file_fops;
3507 diff -NurpP --minimal linux-3.13.10/fs/hostfs/hostfs.h linux-3.13.10-vs2.3.6.11/fs/hostfs/hostfs.h
3508 --- linux-3.13.10/fs/hostfs/hostfs.h    2012-12-11 03:30:57.000000000 +0000
3509 +++ linux-3.13.10-vs2.3.6.11/fs/hostfs/hostfs.h 2014-01-31 20:38:03.000000000 +0000
3510 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3511         unsigned short  ia_mode;
3512         uid_t           ia_uid;
3513         gid_t           ia_gid;
3514 +       vtag_t          ia_tag;
3515         loff_t          ia_size;
3516         struct timespec ia_atime;
3517         struct timespec ia_mtime;
3518 diff -NurpP --minimal linux-3.13.10/fs/inode.c linux-3.13.10-vs2.3.6.11/fs/inode.c
3519 --- linux-3.13.10/fs/inode.c    2014-01-22 20:39:06.000000000 +0000
3520 +++ linux-3.13.10-vs2.3.6.11/fs/inode.c 2014-01-31 23:33:47.000000000 +0000
3521 @@ -18,6 +18,7 @@
3522  #include <linux/buffer_head.h> /* for inode_has_buffers */
3523  #include <linux/ratelimit.h>
3524  #include <linux/list_lru.h>
3525 +#include <linux/vs_tag.h>
3526  #include "internal.h"
3527  
3528  /*
3529 @@ -129,6 +130,8 @@ int inode_init_always(struct super_block
3530         struct address_space *const mapping = &inode->i_data;
3531  
3532         inode->i_sb = sb;
3533 +
3534 +       /* essential because of inode slab reuse */
3535         inode->i_blkbits = sb->s_blocksize_bits;
3536         inode->i_flags = 0;
3537         atomic_set(&inode->i_count, 1);
3538 @@ -138,6 +141,7 @@ int inode_init_always(struct super_block
3539         inode->i_opflags = 0;
3540         i_uid_write(inode, 0);
3541         i_gid_write(inode, 0);
3542 +       i_tag_write(inode, 0);
3543         atomic_set(&inode->i_writecount, 0);
3544         inode->i_size = 0;
3545         inode->i_blocks = 0;
3546 @@ -150,6 +154,7 @@ int inode_init_always(struct super_block
3547         inode->i_bdev = NULL;
3548         inode->i_cdev = NULL;
3549         inode->i_rdev = 0;
3550 +       inode->i_mdev = 0;
3551         inode->dirtied_when = 0;
3552  
3553         if (security_inode_alloc(inode))
3554 @@ -477,6 +482,8 @@ void __insert_inode_hash(struct inode *i
3555  }
3556  EXPORT_SYMBOL(__insert_inode_hash);
3557  
3558 +EXPORT_SYMBOL_GPL(__iget);
3559 +
3560  /**
3561   *     __remove_inode_hash - remove an inode from the hash
3562   *     @inode: inode to unhash
3563 @@ -1802,9 +1809,11 @@ void init_special_inode(struct inode *in
3564         if (S_ISCHR(mode)) {
3565                 inode->i_fop = &def_chr_fops;
3566                 inode->i_rdev = rdev;
3567 +               inode->i_mdev = rdev;
3568         } else if (S_ISBLK(mode)) {
3569                 inode->i_fop = &def_blk_fops;
3570                 inode->i_rdev = rdev;
3571 +               inode->i_mdev = rdev;
3572         } else if (S_ISFIFO(mode))
3573                 inode->i_fop = &pipefifo_fops;
3574         else if (S_ISSOCK(mode))
3575 @@ -1833,6 +1842,7 @@ void inode_init_owner(struct inode *inod
3576         } else
3577                 inode->i_gid = current_fsgid();
3578         inode->i_mode = mode;
3579 +       i_tag_write(inode, dx_current_fstag(inode->i_sb));
3580  }
3581  EXPORT_SYMBOL(inode_init_owner);
3582  
3583 diff -NurpP --minimal linux-3.13.10/fs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ioctl.c
3584 --- linux-3.13.10/fs/ioctl.c    2014-01-22 20:39:06.000000000 +0000
3585 +++ linux-3.13.10-vs2.3.6.11/fs/ioctl.c 2014-01-31 20:38:03.000000000 +0000
3586 @@ -15,6 +15,9 @@
3587  #include <linux/writeback.h>
3588  #include <linux/buffer_head.h>
3589  #include <linux/falloc.h>
3590 +#include <linux/proc_fs.h>
3591 +#include <linux/vserver/inode.h>
3592 +#include <linux/vs_tag.h>
3593  
3594  #include <asm/ioctls.h>
3595  
3596 diff -NurpP --minimal linux-3.13.10/fs/ioprio.c linux-3.13.10-vs2.3.6.11/fs/ioprio.c
3597 --- linux-3.13.10/fs/ioprio.c   2012-12-11 03:30:57.000000000 +0000
3598 +++ linux-3.13.10-vs2.3.6.11/fs/ioprio.c        2014-01-31 20:38:03.000000000 +0000
3599 @@ -28,6 +28,7 @@
3600  #include <linux/syscalls.h>
3601  #include <linux/security.h>
3602  #include <linux/pid_namespace.h>
3603 +#include <linux/vs_base.h>
3604  
3605  int set_task_ioprio(struct task_struct *task, int ioprio)
3606  {
3607 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3608                         else
3609                                 pgrp = find_vpid(who);
3610                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3611 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3612 +                                       continue;
3613                                 ret = set_task_ioprio(p, ioprio);
3614                                 if (ret)
3615                                         break;
3616 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3617                         else
3618                                 pgrp = find_vpid(who);
3619                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3620 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3621 +                                       continue;
3622                                 tmpio = get_task_ioprio(p);
3623                                 if (tmpio < 0)
3624                                         continue;
3625 diff -NurpP --minimal linux-3.13.10/fs/jfs/file.c linux-3.13.10-vs2.3.6.11/fs/jfs/file.c
3626 --- linux-3.13.10/fs/jfs/file.c 2013-02-19 13:58:48.000000000 +0000
3627 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/file.c      2014-01-31 20:38:03.000000000 +0000
3628 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3629         if (is_quota_modification(inode, iattr))
3630                 dquot_initialize(inode);
3631         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3632 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3633 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3634 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3635                 rc = dquot_transfer(inode, iattr);
3636                 if (rc)
3637                         return rc;
3638 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3639  #ifdef CONFIG_JFS_POSIX_ACL
3640         .get_acl        = jfs_get_acl,
3641  #endif
3642 +       .sync_flags     = jfs_sync_flags,
3643  };
3644  
3645  const struct file_operations jfs_file_operations = {
3646 diff -NurpP --minimal linux-3.13.10/fs/jfs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/jfs/ioctl.c
3647 --- linux-3.13.10/fs/jfs/ioctl.c        2013-05-31 13:45:24.000000000 +0000
3648 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/ioctl.c     2014-01-31 20:38:03.000000000 +0000
3649 @@ -12,6 +12,7 @@
3650  #include <linux/time.h>
3651  #include <linux/sched.h>
3652  #include <linux/blkdev.h>
3653 +#include <linux/mount.h>
3654  #include <asm/current.h>
3655  #include <asm/uaccess.h>
3656  
3657 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3658  }
3659  
3660  
3661 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3662 +{
3663 +       inode->i_flags = flags;
3664 +       inode->i_vflags = vflags;
3665 +       jfs_get_inode_flags(JFS_IP(inode));
3666 +       inode->i_ctime = CURRENT_TIME_SEC;
3667 +       mark_inode_dirty(inode);
3668 +       return 0;
3669 +}
3670 +
3671  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3672  {
3673         struct inode *inode = file_inode(filp);
3674 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3675                 if (!S_ISDIR(inode->i_mode))
3676                         flags &= ~JFS_DIRSYNC_FL;
3677  
3678 +               if (IS_BARRIER(inode)) {
3679 +                       vxwprintk_task(1, "messing with the barrier.");
3680 +                       return -EACCES;
3681 +               }
3682 +
3683                 /* Is it quota file? Do not allow user to mess with it */
3684                 if (IS_NOQUOTA(inode)) {
3685                         err = -EPERM;
3686 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3687                  * the relevant capability.
3688                  */
3689                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3690 -                       ((flags ^ oldflags) &
3691 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3692 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3693 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3694                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3695                                 mutex_unlock(&inode->i_mutex);
3696                                 err = -EPERM;
3697 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3698                         }
3699                 }
3700  
3701 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3702 +               flags &= JFS_FL_USER_MODIFIABLE;
3703                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3704                 jfs_inode->mode2 = flags;
3705  
3706 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_dinode.h linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_dinode.h
3707 --- linux-3.13.10/fs/jfs/jfs_dinode.h   2012-12-11 03:30:57.000000000 +0000
3708 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_dinode.h        2014-01-31 20:38:03.000000000 +0000
3709 @@ -161,9 +161,13 @@ struct dinode {
3710  
3711  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3712  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3713 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3714  
3715 -#define JFS_FL_USER_VISIBLE    0x03F80000
3716 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3717 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3718 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3719 +
3720 +#define JFS_FL_USER_VISIBLE    0x07F80000
3721 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3722  #define JFS_FL_INHERIT         0x03C80000
3723  
3724  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3725 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_filsys.h linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_filsys.h
3726 --- linux-3.13.10/fs/jfs/jfs_filsys.h   2012-12-11 03:30:57.000000000 +0000
3727 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_filsys.h        2014-01-31 20:38:03.000000000 +0000
3728 @@ -266,6 +266,7 @@
3729  #define JFS_NAME_MAX   255
3730  #define JFS_PATH_MAX   BPSIZE
3731  
3732 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3733  
3734  /*
3735   *     file system state (superblock state)
3736 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_imap.c linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_imap.c
3737 --- linux-3.13.10/fs/jfs/jfs_imap.c     2013-11-25 15:45:01.000000000 +0000
3738 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_imap.c  2014-01-31 20:38:03.000000000 +0000
3739 @@ -46,6 +46,7 @@
3740  #include <linux/pagemap.h>
3741  #include <linux/quotaops.h>
3742  #include <linux/slab.h>
3743 +#include <linux/vs_tag.h>
3744  
3745  #include "jfs_incore.h"
3746  #include "jfs_inode.h"
3747 @@ -3047,6 +3048,8 @@ static int copy_from_dinode(struct dinod
3748  {
3749         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3750         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3751 +       kuid_t kuid;
3752 +       kgid_t kgid;
3753  
3754         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3755         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3756 @@ -3067,14 +3070,18 @@ static int copy_from_dinode(struct dinod
3757         }
3758         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3759  
3760 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3761 +       kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3762 +       kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3763 +       ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3764 +
3765 +       jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3766         if (!uid_valid(sbi->uid))
3767                 ip->i_uid = jfs_ip->saved_uid;
3768         else {
3769                 ip->i_uid = sbi->uid;
3770         }
3771  
3772 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3773 +       jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3774         if (!gid_valid(sbi->gid))
3775                 ip->i_gid = jfs_ip->saved_gid;
3776         else {
3777 @@ -3139,16 +3146,14 @@ static void copy_to_dinode(struct dinode
3778         dip->di_size = cpu_to_le64(ip->i_size);
3779         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3780         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3781 -       if (!uid_valid(sbi->uid))
3782 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3783 -       else
3784 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3785 -                                                  jfs_ip->saved_uid));
3786 -       if (!gid_valid(sbi->gid))
3787 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3788 -       else
3789 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3790 -                                                   jfs_ip->saved_gid));
3791 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3792 +               TAGINO_KUID(DX_TAG(ip),
3793 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3794 +               ip->i_tag)));
3795 +       dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3796 +               TAGINO_KGID(DX_TAG(ip),
3797 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3798 +               ip->i_tag)));
3799         jfs_get_inode_flags(jfs_ip);
3800         /*
3801          * mode2 is only needed for storing the higher order bits.
3802 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_inode.c linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.c
3803 --- linux-3.13.10/fs/jfs/jfs_inode.c    2013-11-25 15:46:59.000000000 +0000
3804 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.c 2014-01-31 20:38:03.000000000 +0000
3805 @@ -18,6 +18,7 @@
3806  
3807  #include <linux/fs.h>
3808  #include <linux/quotaops.h>
3809 +#include <linux/vs_tag.h>
3810  #include "jfs_incore.h"
3811  #include "jfs_inode.h"
3812  #include "jfs_filsys.h"
3813 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3814  {
3815         unsigned int flags = JFS_IP(inode)->mode2;
3816  
3817 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3818 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3819 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3820 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3821  
3822         if (flags & JFS_IMMUTABLE_FL)
3823                 inode->i_flags |= S_IMMUTABLE;
3824 +       if (flags & JFS_IXUNLINK_FL)
3825 +               inode->i_flags |= S_IXUNLINK;
3826 +
3827 +       if (flags & JFS_SYNC_FL)
3828 +               inode->i_flags |= S_SYNC;
3829         if (flags & JFS_APPEND_FL)
3830                 inode->i_flags |= S_APPEND;
3831         if (flags & JFS_NOATIME_FL)
3832                 inode->i_flags |= S_NOATIME;
3833         if (flags & JFS_DIRSYNC_FL)
3834                 inode->i_flags |= S_DIRSYNC;
3835 -       if (flags & JFS_SYNC_FL)
3836 -               inode->i_flags |= S_SYNC;
3837 +
3838 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3839 +
3840 +       if (flags & JFS_BARRIER_FL)
3841 +               inode->i_vflags |= V_BARRIER;
3842 +       if (flags & JFS_COW_FL)
3843 +               inode->i_vflags |= V_COW;
3844  }
3845  
3846  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3847  {
3848         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3849 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3850 +
3851 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3852 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3853 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3854 +                          JFS_BARRIER_FL | JFS_COW_FL);
3855  
3856 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3857 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3858         if (flags & S_IMMUTABLE)
3859                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3860 +       if (flags & S_IXUNLINK)
3861 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3862 +
3863         if (flags & S_APPEND)
3864                 jfs_ip->mode2 |= JFS_APPEND_FL;
3865         if (flags & S_NOATIME)
3866 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3867                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3868         if (flags & S_SYNC)
3869                 jfs_ip->mode2 |= JFS_SYNC_FL;
3870 +
3871 +       if (vflags & V_BARRIER)
3872 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3873 +       if (vflags & V_COW)
3874 +               jfs_ip->mode2 |= JFS_COW_FL;
3875  }
3876  
3877  /*
3878 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_inode.h linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.h
3879 --- linux-3.13.10/fs/jfs/jfs_inode.h    2012-12-11 03:30:57.000000000 +0000
3880 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.h 2014-01-31 20:38:03.000000000 +0000
3881 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3882  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3883         int fh_len, int fh_type);
3884  extern void jfs_set_inode_flags(struct inode *);
3885 +extern int jfs_sync_flags(struct inode *, int, int);
3886  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3887  extern int jfs_setattr(struct dentry *, struct iattr *);
3888  
3889 diff -NurpP --minimal linux-3.13.10/fs/jfs/namei.c linux-3.13.10-vs2.3.6.11/fs/jfs/namei.c
3890 --- linux-3.13.10/fs/jfs/namei.c        2013-11-25 15:45:01.000000000 +0000
3891 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/namei.c     2014-01-31 20:38:03.000000000 +0000
3892 @@ -22,6 +22,7 @@
3893  #include <linux/ctype.h>
3894  #include <linux/quotaops.h>
3895  #include <linux/exportfs.h>
3896 +#include <linux/vs_tag.h>
3897  #include "jfs_incore.h"
3898  #include "jfs_superblock.h"
3899  #include "jfs_inode.h"
3900 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3901                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3902         }
3903  
3904 +       dx_propagate_tag(nd, ip);
3905         return d_splice_alias(ip, dentry);
3906  }
3907  
3908 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
3909  #ifdef CONFIG_JFS_POSIX_ACL
3910         .get_acl        = jfs_get_acl,
3911  #endif
3912 +       .sync_flags     = jfs_sync_flags,
3913  };
3914  
3915  const struct file_operations jfs_dir_operations = {
3916 diff -NurpP --minimal linux-3.13.10/fs/jfs/super.c linux-3.13.10-vs2.3.6.11/fs/jfs/super.c
3917 --- linux-3.13.10/fs/jfs/super.c        2013-11-25 15:45:01.000000000 +0000
3918 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/super.c     2014-01-31 20:38:03.000000000 +0000
3919 @@ -203,7 +203,8 @@ enum {
3920         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
3921         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
3922         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
3923 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
3924 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
3925 +       Opt_tag, Opt_notag, Opt_tagid
3926  };
3927  
3928  static const match_table_t tokens = {
3929 @@ -213,6 +214,10 @@ static const match_table_t tokens = {
3930         {Opt_resize, "resize=%u"},
3931         {Opt_resize_nosize, "resize"},
3932         {Opt_errors, "errors=%s"},
3933 +       {Opt_tag, "tag"},
3934 +       {Opt_notag, "notag"},
3935 +       {Opt_tagid, "tagid=%u"},
3936 +       {Opt_tag, "tagxid"},
3937         {Opt_ignore, "noquota"},
3938         {Opt_ignore, "quota"},
3939         {Opt_usrquota, "usrquota"},
3940 @@ -389,7 +394,20 @@ static int parse_options(char *options,
3941                         }
3942                         break;
3943                 }
3944 -
3945 +#ifndef CONFIG_TAGGING_NONE
3946 +               case Opt_tag:
3947 +                       *flag |= JFS_TAGGED;
3948 +                       break;
3949 +               case Opt_notag:
3950 +                       *flag &= JFS_TAGGED;
3951 +                       break;
3952 +#endif
3953 +#ifdef CONFIG_PROPAGATE
3954 +               case Opt_tagid:
3955 +                       /* use args[0] */
3956 +                       *flag |= JFS_TAGGED;
3957 +                       break;
3958 +#endif
3959                 default:
3960                         printk("jfs: Unrecognized mount option \"%s\" "
3961                                         " or missing value\n", p);
3962 @@ -421,6 +439,12 @@ static int jfs_remount(struct super_bloc
3963                 return -EINVAL;
3964         }
3965  
3966 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
3967 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
3968 +                       sb->s_id);
3969 +               return -EINVAL;
3970 +       }
3971 +
3972         if (newLVSize) {
3973                 if (sb->s_flags & MS_RDONLY) {
3974                         pr_err("JFS: resize requires volume" \
3975 @@ -506,6 +530,9 @@ static int jfs_fill_super(struct super_b
3976  #ifdef CONFIG_JFS_POSIX_ACL
3977         sb->s_flags |= MS_POSIXACL;
3978  #endif
3979 +       /* map mount option tagxid */
3980 +       if (sbi->flag & JFS_TAGGED)
3981 +               sb->s_flags |= MS_TAGGED;
3982  
3983         if (newLVSize) {
3984                 pr_err("resize option for remount only\n");
3985 diff -NurpP --minimal linux-3.13.10/fs/libfs.c linux-3.13.10-vs2.3.6.11/fs/libfs.c
3986 --- linux-3.13.10/fs/libfs.c    2014-01-22 20:39:06.000000000 +0000
3987 +++ linux-3.13.10-vs2.3.6.11/fs/libfs.c 2014-02-01 01:35:46.000000000 +0000
3988 @@ -145,13 +145,14 @@ static inline unsigned char dt_type(stru
3989   * both impossible due to the lock on directory.
3990   */
3991  
3992 -int dcache_readdir(struct file *file, struct dir_context *ctx)
3993 +static inline int do_dcache_readdir_filter(struct file *filp,
3994 +       struct dir_context *ctx, int (*filter)(struct dentry *dentry))
3995  {
3996 -       struct dentry *dentry = file->f_path.dentry;
3997 -       struct dentry *cursor = file->private_data;
3998 +       struct dentry *dentry = filp->f_path.dentry;
3999 +       struct dentry *cursor = filp->private_data;
4000         struct list_head *p, *q = &cursor->d_u.d_child;
4001  
4002 -       if (!dir_emit_dots(file, ctx))
4003 +       if (!dir_emit_dots(filp, ctx))
4004                 return 0;
4005         spin_lock(&dentry->d_lock);
4006         if (ctx->pos == 2)
4007 @@ -159,6 +160,8 @@ int dcache_readdir(struct file *file, st
4008  
4009         for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
4010                 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
4011 +               if (filter && !filter(next))
4012 +                       continue;
4013                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4014                 if (!simple_positive(next)) {
4015                         spin_unlock(&next->d_lock);
4016 @@ -181,8 +184,22 @@ int dcache_readdir(struct file *file, st
4017         spin_unlock(&dentry->d_lock);
4018         return 0;
4019  }
4020 +
4021  EXPORT_SYMBOL(dcache_readdir);
4022  
4023 +int dcache_readdir(struct file *filp, struct dir_context *ctx)
4024 +{
4025 +       return do_dcache_readdir_filter(filp, ctx, NULL);
4026 +}
4027 +
4028 +EXPORT_SYMBOL(dcache_readdir_filter);
4029 +
4030 +int dcache_readdir_filter(struct file *filp, struct dir_context *ctx,
4031 +       int (*filter)(struct dentry *))
4032 +{
4033 +       return do_dcache_readdir_filter(filp, ctx, filter);
4034 +}
4035 +
4036  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4037  {
4038         return -EISDIR;
4039 diff -NurpP --minimal linux-3.13.10/fs/locks.c linux-3.13.10-vs2.3.6.11/fs/locks.c
4040 --- linux-3.13.10/fs/locks.c    2014-01-22 20:39:06.000000000 +0000
4041 +++ linux-3.13.10-vs2.3.6.11/fs/locks.c 2014-01-31 23:51:55.000000000 +0000
4042 @@ -129,6 +129,8 @@
4043  #include <linux/hashtable.h>
4044  #include <linux/percpu.h>
4045  #include <linux/lglock.h>
4046 +#include <linux/vs_base.h>
4047 +#include <linux/vs_limit.h>
4048  
4049  #include <asm/uaccess.h>
4050  
4051 @@ -210,11 +212,17 @@ static void locks_init_lock_heads(struct
4052  /* Allocate an empty lock structure. */
4053  struct file_lock *locks_alloc_lock(void)
4054  {
4055 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4056 +       struct file_lock *fl;
4057  
4058 -       if (fl)
4059 -               locks_init_lock_heads(fl);
4060 +       if (!vx_locks_avail(1))
4061 +               return NULL;
4062  
4063 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4064 +
4065 +       if (fl) {
4066 +               locks_init_lock_heads(fl);
4067 +               fl->fl_xid = -1;
4068 +       }
4069         return fl;
4070  }
4071  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4072 @@ -238,6 +246,7 @@ void locks_free_lock(struct file_lock *f
4073         BUG_ON(!list_empty(&fl->fl_block));
4074         BUG_ON(!hlist_unhashed(&fl->fl_link));
4075  
4076 +       vx_locks_dec(fl);
4077         locks_release_private(fl);
4078         kmem_cache_free(filelock_cache, fl);
4079  }
4080 @@ -247,6 +256,7 @@ void locks_init_lock(struct file_lock *f
4081  {
4082         memset(fl, 0, sizeof(struct file_lock));
4083         locks_init_lock_heads(fl);
4084 +       fl->fl_xid = -1;
4085  }
4086  
4087  EXPORT_SYMBOL(locks_init_lock);
4088 @@ -287,6 +297,7 @@ void locks_copy_lock(struct file_lock *n
4089         new->fl_file = fl->fl_file;
4090         new->fl_ops = fl->fl_ops;
4091         new->fl_lmops = fl->fl_lmops;
4092 +       new->fl_xid = fl->fl_xid;
4093  
4094         locks_copy_private(new, fl);
4095  }
4096 @@ -325,6 +336,11 @@ static int flock_make_lock(struct file *
4097         fl->fl_flags = FL_FLOCK;
4098         fl->fl_type = type;
4099         fl->fl_end = OFFSET_MAX;
4100 +
4101 +       vxd_assert(filp->f_xid == vx_current_xid(),
4102 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4103 +       fl->fl_xid = filp->f_xid;
4104 +       vx_locks_inc(fl);
4105         
4106         *lock = fl;
4107         return 0;
4108 @@ -464,6 +480,7 @@ static int lease_init(struct file *filp,
4109  
4110         fl->fl_owner = current->files;
4111         fl->fl_pid = current->tgid;
4112 +       fl->fl_xid = vx_current_xid();
4113  
4114         fl->fl_file = filp;
4115         fl->fl_flags = FL_LEASE;
4116 @@ -483,6 +500,11 @@ static struct file_lock *lease_alloc(str
4117         if (fl == NULL)
4118                 return ERR_PTR(error);
4119  
4120 +       fl->fl_xid = vx_current_xid();
4121 +       if (filp)
4122 +               vxd_assert(filp->f_xid == fl->fl_xid,
4123 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4124 +       vx_locks_inc(fl);
4125         error = lease_init(filp, type, fl);
4126         if (error) {
4127                 locks_free_lock(fl);
4128 @@ -858,6 +880,7 @@ static int flock_lock_file(struct file *
4129                 spin_lock(&inode->i_lock);
4130         }
4131  
4132 +       new_fl->fl_xid = -1;
4133  find_conflict:
4134         for_each_lock(inode, before) {
4135                 struct file_lock *fl = *before;
4136 @@ -878,6 +901,7 @@ find_conflict:
4137                 goto out;
4138         locks_copy_lock(new_fl, request);
4139         locks_insert_lock(before, new_fl);
4140 +       vx_locks_inc(new_fl);
4141         new_fl = NULL;
4142         error = 0;
4143  
4144 @@ -888,7 +912,8 @@ out:
4145         return error;
4146  }
4147  
4148 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4149 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4150 +       struct file_lock *conflock, vxid_t xid)
4151  {
4152         struct file_lock *fl;
4153         struct file_lock *new_fl = NULL;
4154 @@ -899,6 +924,8 @@ static int __posix_lock_file(struct inod
4155         int error;
4156         bool added = false;
4157  
4158 +       vxd_assert(xid == vx_current_xid(),
4159 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4160         /*
4161          * We may need two file_lock structures for this operation,
4162          * so we get them in advance to avoid races.
4163 @@ -909,7 +936,11 @@ static int __posix_lock_file(struct inod
4164             (request->fl_type != F_UNLCK ||
4165              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4166                 new_fl = locks_alloc_lock();
4167 +               new_fl->fl_xid = xid;
4168 +               vx_locks_inc(new_fl);
4169                 new_fl2 = locks_alloc_lock();
4170 +               new_fl2->fl_xid = xid;
4171 +               vx_locks_inc(new_fl2);
4172         }
4173  
4174         spin_lock(&inode->i_lock);
4175 @@ -1118,7 +1149,8 @@ static int __posix_lock_file(struct inod
4176  int posix_lock_file(struct file *filp, struct file_lock *fl,
4177                         struct file_lock *conflock)
4178  {
4179 -       return __posix_lock_file(file_inode(filp), fl, conflock);
4180 +       return __posix_lock_file(file_inode(filp),
4181 +               fl, conflock, filp->f_xid);
4182  }
4183  EXPORT_SYMBOL(posix_lock_file);
4184  
4185 @@ -1208,7 +1240,7 @@ int locks_mandatory_area(int read_write,
4186         fl.fl_end = offset + count - 1;
4187  
4188         for (;;) {
4189 -               error = __posix_lock_file(inode, &fl, NULL);
4190 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4191                 if (error != FILE_LOCK_DEFERRED)
4192                         break;
4193                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4194 @@ -1549,6 +1581,7 @@ static int generic_add_lease(struct file
4195                 goto out;
4196  
4197         locks_insert_lock(before, lease);
4198 +       vx_locks_inc(lease);
4199         error = 0;
4200  out:
4201         if (is_deleg)
4202 @@ -1991,6 +2024,11 @@ int fcntl_setlk(unsigned int fd, struct
4203         if (file_lock == NULL)
4204                 return -ENOLCK;
4205  
4206 +       vxd_assert(filp->f_xid == vx_current_xid(),
4207 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4208 +       file_lock->fl_xid = filp->f_xid;
4209 +       vx_locks_inc(file_lock);
4210 +
4211         /*
4212          * This might block, so we do it before checking the inode.
4213          */
4214 @@ -2109,6 +2147,11 @@ int fcntl_setlk64(unsigned int fd, struc
4215         if (file_lock == NULL)
4216                 return -ENOLCK;
4217  
4218 +       vxd_assert(filp->f_xid == vx_current_xid(),
4219 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4220 +       file_lock->fl_xid = filp->f_xid;
4221 +       vx_locks_inc(file_lock);
4222 +
4223         /*
4224          * This might block, so we do it before checking the inode.
4225          */
4226 @@ -2378,8 +2421,11 @@ static int locks_show(struct seq_file *f
4227  
4228         lock_get_status(f, fl, iter->li_pos, "");
4229  
4230 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4231 -               lock_get_status(f, bfl, iter->li_pos, " ->");
4232 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4233 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4234 +                       continue;
4235 +               lock_get_status(f, bfl, iter->li_pos, " ->");
4236 +       }
4237  
4238         return 0;
4239  }
4240 diff -NurpP --minimal linux-3.13.10/fs/mount.h linux-3.13.10-vs2.3.6.11/fs/mount.h
4241 --- linux-3.13.10/fs/mount.h    2014-04-17 01:12:32.000000000 +0000
4242 +++ linux-3.13.10-vs2.3.6.11/fs/mount.h 2014-04-17 01:17:10.000000000 +0000
4243 @@ -57,6 +57,7 @@ struct mount {
4244         int mnt_expiry_mark;            /* true if marked for expiry */
4245         int mnt_pinned;
4246         struct path mnt_ex_mountpoint;
4247 +       vtag_t mnt_tag;                 /* tagging used for vfsmount */
4248  };
4249  
4250  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4251 diff -NurpP --minimal linux-3.13.10/fs/namei.c linux-3.13.10-vs2.3.6.11/fs/namei.c
4252 --- linux-3.13.10/fs/namei.c    2014-04-17 01:12:32.000000000 +0000
4253 +++ linux-3.13.10-vs2.3.6.11/fs/namei.c 2014-04-17 01:17:10.000000000 +0000
4254 @@ -34,9 +34,19 @@
4255  #include <linux/device_cgroup.h>
4256  #include <linux/fs_struct.h>
4257  #include <linux/posix_acl.h>
4258 +#include <linux/proc_fs.h>
4259 +#include <linux/magic.h>
4260 +#include <linux/vserver/inode.h>
4261 +#include <linux/vs_base.h>
4262 +#include <linux/vs_tag.h>
4263 +#include <linux/vs_cowbl.h>
4264 +#include <linux/vs_device.h>
4265 +#include <linux/vs_context.h>
4266 +#include <linux/pid_namespace.h>
4267  #include <asm/uaccess.h>
4268  
4269  #include "internal.h"
4270 +#include "proc/internal.h"
4271  #include "mount.h"
4272  
4273  /* [Feb-1997 T. Schoebel-Theuer]
4274 @@ -266,6 +276,89 @@ static int check_acl(struct inode *inode
4275         return -EAGAIN;
4276  }
4277  
4278 +static inline int dx_barrier(const struct inode *inode)
4279 +{
4280 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4281 +               vxwprintk_task(1, "did hit the barrier.");
4282 +               return 1;
4283 +       }
4284 +       return 0;
4285 +}
4286 +
4287 +static int __dx_permission(const struct inode *inode, int mask)
4288 +{
4289 +       if (dx_barrier(inode))
4290 +               return -EACCES;
4291 +
4292 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4293 +               /* devpts is xid tagged */
4294 +               if (S_ISDIR(inode->i_mode) ||
4295 +                   vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4296 +                       return 0;
4297 +
4298 +               /* just pretend we didn't find anything */
4299 +               return -ENOENT;
4300 +       }
4301 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4302 +               struct proc_dir_entry *de = PDE(inode);
4303 +
4304 +               if (de && !vx_hide_check(0, de->vx_flags))
4305 +                       goto out;
4306 +
4307 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4308 +                       struct pid *pid;
4309 +                       struct task_struct *tsk;
4310 +
4311 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4312 +                           vx_flags(VXF_STATE_SETUP, 0))
4313 +                               return 0;
4314 +
4315 +                       pid = PROC_I(inode)->pid;
4316 +                       if (!pid)
4317 +                               goto out;
4318 +
4319 +                       rcu_read_lock();
4320 +                       tsk = pid_task(pid, PIDTYPE_PID);
4321 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4322 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4323 +                       if (tsk &&
4324 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4325 +                               rcu_read_unlock();
4326 +                               return 0;
4327 +                       }
4328 +                       rcu_read_unlock();
4329 +               }
4330 +               else {
4331 +                       /* FIXME: Should we block some entries here? */
4332 +                       return 0;
4333 +               }
4334 +       }
4335 +       else {
4336 +               if (dx_notagcheck(inode->i_sb) ||
4337 +                   dx_check((vxid_t)i_tag_read(inode),
4338 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4339 +                       return 0;
4340 +       }
4341 +
4342 +out:
4343 +       return -EACCES;
4344 +}
4345 +
4346 +int dx_permission(const struct inode *inode, int mask)
4347 +{
4348 +       int ret = __dx_permission(inode, mask);
4349 +       if (unlikely(ret)) {
4350 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4351 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4352 +#endif
4353 +                   vxwprintk_task(1,
4354 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4355 +                       mask, inode->i_sb->s_id, inode,
4356 +                       i_tag_read(inode), inode->i_ino);
4357 +       }
4358 +       return ret;
4359 +}
4360 +
4361  /*
4362   * This does the basic permission checking
4363   */
4364 @@ -388,10 +481,14 @@ int __inode_permission(struct inode *ino
4365                 /*
4366                  * Nobody gets write access to an immutable file.
4367                  */
4368 -               if (IS_IMMUTABLE(inode))
4369 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4370                         return -EACCES;
4371         }
4372  
4373 +       retval = dx_permission(inode, mask);
4374 +       if (retval)
4375 +               return retval;
4376 +
4377         retval = do_inode_permission(inode, mask);
4378         if (retval)
4379                 return retval;
4380 @@ -1238,7 +1335,8 @@ static void follow_dotdot(struct nameida
4381  
4382                 if (nd->path.dentry == nd->root.dentry &&
4383                     nd->path.mnt == nd->root.mnt) {
4384 -                       break;
4385 +                       /* for sane '/' avoid follow_mount() */
4386 +                       return;
4387                 }
4388                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4389                         /* rare case of legitimate dget_parent()... */
4390 @@ -1383,6 +1481,9 @@ static int lookup_fast(struct nameidata
4391                                 goto unlazy;
4392                         }
4393                 }
4394 +
4395 +               /* FIXME: check dx permission */
4396 +
4397                 path->mnt = mnt;
4398                 path->dentry = dentry;
4399                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4400 @@ -1413,6 +1514,8 @@ unlazy:
4401                 }
4402         }
4403  
4404 +       /* FIXME: check dx permission */
4405 +
4406         path->mnt = mnt;
4407         path->dentry = dentry;
4408         err = follow_managed(path, nd->flags);
4409 @@ -2400,7 +2503,7 @@ static int may_delete(struct inode *dir,
4410                 return -EPERM;
4411  
4412         if (check_sticky(dir, inode) || IS_APPEND(inode) ||
4413 -           IS_IMMUTABLE(inode) || IS_SWAPFILE(inode))
4414 +               IS_IXORUNLINK(inode) || IS_SWAPFILE(inode))
4415                 return -EPERM;
4416         if (isdir) {
4417                 if (!d_is_directory(victim) && !d_is_autodir(victim))
4418 @@ -2480,19 +2583,25 @@ int vfs_create(struct inode *dir, struct
4419                 bool want_excl)
4420  {
4421         int error = may_create(dir, dentry);
4422 -       if (error)
4423 +       if (error) {
4424 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4425                 return error;
4426 +       }
4427  
4428         if (!dir->i_op->create)
4429                 return -EACCES; /* shouldn't it be ENOSYS? */
4430         mode &= S_IALLUGO;
4431         mode |= S_IFREG;
4432         error = security_inode_create(dir, dentry, mode);
4433 -       if (error)
4434 +       if (error) {
4435 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4436                 return error;
4437 +       }
4438         error = dir->i_op->create(dir, dentry, mode, want_excl);
4439         if (!error)
4440                 fsnotify_create(dir, dentry);
4441 +       else
4442 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4443         return error;
4444  }
4445  
4446 @@ -2527,6 +2636,15 @@ static int may_open(struct path *path, i
4447                 break;
4448         }
4449  
4450 +#ifdef CONFIG_VSERVER_COWBL
4451 +       if (IS_COW(inode) &&
4452 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4453 +               if (IS_COW_LINK(inode))
4454 +                       return -EMLINK;
4455 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4456 +               mark_inode_dirty(inode);
4457 +       }
4458 +#endif
4459         error = inode_permission(inode, acc_mode);
4460         if (error)
4461                 return error;
4462 @@ -3022,6 +3140,16 @@ finish_open:
4463         }
4464  finish_open_created:
4465         error = may_open(&nd->path, acc_mode, open_flag);
4466 +#ifdef CONFIG_VSERVER_COWBL
4467 +       if (error == -EMLINK) {
4468 +               struct dentry *dentry;
4469 +               dentry = cow_break_link(name->name);
4470 +               if (IS_ERR(dentry))
4471 +                       error = PTR_ERR(dentry);
4472 +               else
4473 +                       dput(dentry);
4474 +       }
4475 +#endif
4476         if (error)
4477                 goto out;
4478         file->f_path.mnt = nd->path.mnt;
4479 @@ -3147,6 +3275,7 @@ static struct file *path_openat(int dfd,
4480         int opened = 0;
4481         int error;
4482  
4483 +restart:
4484         file = get_empty_filp();
4485         if (IS_ERR(file))
4486                 return file;
4487 @@ -3188,6 +3317,16 @@ static struct file *path_openat(int dfd,
4488                 error = do_last(nd, &path, file, op, &opened, pathname);
4489                 put_link(nd, &link, cookie);
4490         }
4491 +
4492 +#ifdef CONFIG_VSERVER_COWBL
4493 +       if (error == -EMLINK) {
4494 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4495 +                       path_put(&nd->root);
4496 +               if (base)
4497 +                       fput(base);
4498 +               goto restart;
4499 +       }
4500 +#endif
4501  out:
4502         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4503                 path_put(&nd->root);
4504 @@ -3303,6 +3442,11 @@ struct dentry *kern_path_create(int dfd,
4505                 goto fail;
4506         }
4507         *path = nd.path;
4508 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4509 +               path->dentry, path->dentry->d_name.len,
4510 +               path->dentry->d_name.name, dentry,
4511 +               dentry->d_name.len, dentry->d_name.name,
4512 +               path->dentry->d_inode);
4513         return dentry;
4514  fail:
4515         dput(dentry);
4516 @@ -3850,7 +3994,7 @@ int vfs_link(struct dentry *old_dentry,
4517         /*
4518          * A link to an append-only or immutable file cannot be created.
4519          */
4520 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4521 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4522                 return -EPERM;
4523         if (!dir->i_op->link)
4524                 return -EPERM;
4525 @@ -4305,6 +4449,287 @@ int generic_readlink(struct dentry *dent
4526         return res;
4527  }
4528  
4529 +
4530 +#ifdef CONFIG_VSERVER_COWBL
4531 +
4532 +static inline
4533 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4534 +{
4535 +       loff_t ppos = 0;
4536 +       loff_t opos = 0;
4537 +
4538 +       return do_splice_direct(in, &ppos, out, &opos, len, 0);
4539 +}
4540 +
4541 +struct dentry *cow_break_link(const char *pathname)
4542 +{
4543 +       int ret, mode, pathlen, redo = 0, drop = 1;
4544 +       struct nameidata old_nd, dir_nd;
4545 +       struct path dir_path, *old_path, *new_path;
4546 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4547 +       struct file *old_file;
4548 +       struct file *new_file;
4549 +       char *to, *path, pad='\251';
4550 +       loff_t size;
4551 +
4552 +       vxdprintk(VXD_CBIT(misc, 1),
4553 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4554 +
4555 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4556 +       ret = -ENOMEM;
4557 +       if (!path)
4558 +               goto out;
4559 +
4560 +       /* old_nd.path will have refs to dentry and mnt */
4561 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4562 +       vxdprintk(VXD_CBIT(misc, 2),
4563 +               "do_path_lookup(old): %d", ret);
4564 +       if (ret < 0)
4565 +               goto out_free_path;
4566 +
4567 +       /* dentry/mnt refs handed over to old_path */
4568 +       old_path = &old_nd.path;
4569 +       /* no explicit reference for old_dentry here */
4570 +       old_dentry = old_path->dentry;
4571 +
4572 +       mode = old_dentry->d_inode->i_mode;
4573 +       to = d_path(old_path, path, PATH_MAX-2);
4574 +       pathlen = strlen(to);
4575 +       vxdprintk(VXD_CBIT(misc, 2),
4576 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4577 +               old_dentry,
4578 +               old_dentry->d_name.len, old_dentry->d_name.name,
4579 +               old_dentry->d_name.len);
4580 +
4581 +       to[pathlen + 1] = 0;
4582 +retry:
4583 +       new_dentry = NULL;
4584 +       to[pathlen] = pad--;
4585 +       ret = -ELOOP;
4586 +       if (pad <= '\240')
4587 +               goto out_rel_old;
4588 +
4589 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4590 +
4591 +       /* dir_nd.path will have refs to dentry and mnt */
4592 +       ret = do_path_lookup(AT_FDCWD, to,
4593 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4594 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4595 +       if (ret < 0)
4596 +               goto retry;
4597 +
4598 +       /* this puppy downs the dir inode mutex if successful.
4599 +          dir_path will hold refs to dentry and mnt and
4600 +          we'll have write access to the mnt */
4601 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4602 +       if (!new_dentry || IS_ERR(new_dentry)) {
4603 +               path_put(&dir_nd.path);
4604 +               vxdprintk(VXD_CBIT(misc, 2),
4605 +                       "kern_path_create(new) failed with %ld",
4606 +                       PTR_ERR(new_dentry));
4607 +               goto retry;
4608 +       }
4609 +       vxdprintk(VXD_CBIT(misc, 2),
4610 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4611 +               new_dentry,
4612 +               new_dentry->d_name.len, new_dentry->d_name.name,
4613 +               new_dentry->d_name.len);
4614 +
4615 +       /* take a reference on new_dentry */
4616 +       dget(new_dentry);
4617 +
4618 +       /* dentry/mnt refs handed over to new_path */
4619 +       new_path = &dir_path;
4620 +
4621 +       /* dentry for old/new dir */
4622 +       dir = dir_nd.path.dentry;
4623 +
4624 +       /* give up reference on dir */
4625 +       dput(new_path->dentry);
4626 +
4627 +       /* new_dentry already has a reference */
4628 +       new_path->dentry = new_dentry;
4629 +
4630 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4631 +       vxdprintk(VXD_CBIT(misc, 2),
4632 +               "vfs_create(new): %d", ret);
4633 +       if (ret == -EEXIST) {
4634 +               path_put(&dir_nd.path);
4635 +               mutex_unlock(&dir->d_inode->i_mutex);
4636 +               mnt_drop_write(new_path->mnt);
4637 +               path_put(new_path);
4638 +               new_dentry = NULL;
4639 +               goto retry;
4640 +       }
4641 +       else if (ret < 0)
4642 +               goto out_unlock_new;
4643 +
4644 +       /* drop out early, ret passes ENOENT */
4645 +       ret = -ENOENT;
4646 +       if ((redo = d_unhashed(old_dentry)))
4647 +               goto out_unlock_new;
4648 +
4649 +       /* doesn't change refs for old_path */
4650 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4651 +       vxdprintk(VXD_CBIT(misc, 2),
4652 +               "dentry_open(old): %p", old_file);
4653 +       if (IS_ERR(old_file)) {
4654 +               ret = PTR_ERR(old_file);
4655 +               goto out_unlock_new;
4656 +       }
4657 +
4658 +       /* doesn't change refs for new_path */
4659 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4660 +       vxdprintk(VXD_CBIT(misc, 2),
4661 +               "dentry_open(new): %p", new_file);
4662 +       if (IS_ERR(new_file)) {
4663 +               ret = PTR_ERR(new_file);
4664 +               goto out_fput_old;
4665 +       }
4666 +
4667 +       /* unlock the inode mutex from kern_path_create() */
4668 +       mutex_unlock(&dir->d_inode->i_mutex);
4669 +
4670 +       /* drop write access to mnt */
4671 +       mnt_drop_write(new_path->mnt);
4672 +
4673 +       drop = 0;
4674 +
4675 +       size = i_size_read(old_file->f_dentry->d_inode);
4676 +       ret = do_cow_splice(old_file, new_file, size);
4677 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4678 +       if (ret < 0) {
4679 +               goto out_fput_both;
4680 +       } else if (ret < size) {
4681 +               ret = -ENOSPC;
4682 +               goto out_fput_both;
4683 +       } else {
4684 +               struct inode *old_inode = old_dentry->d_inode;
4685 +               struct inode *new_inode = new_dentry->d_inode;
4686 +               struct iattr attr = {
4687 +                       .ia_uid = old_inode->i_uid,
4688 +                       .ia_gid = old_inode->i_gid,
4689 +                       .ia_valid = ATTR_UID | ATTR_GID
4690 +                       };
4691 +
4692 +               setattr_copy(new_inode, &attr);
4693 +               mark_inode_dirty(new_inode);
4694 +       }
4695 +
4696 +       /* lock rename mutex */
4697 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4698 +
4699 +       /* drop out late */
4700 +       ret = -ENOENT;
4701 +       if ((redo = d_unhashed(old_dentry)))
4702 +               goto out_unlock;
4703 +
4704 +       vxdprintk(VXD_CBIT(misc, 2),
4705 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4706 +               new_dentry->d_name.len, new_dentry->d_name.name,
4707 +               new_dentry->d_name.len,
4708 +               old_dentry->d_name.len, old_dentry->d_name.name,
4709 +               old_dentry->d_name.len);
4710 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4711 +               old_dentry->d_parent->d_inode, old_dentry, NULL);
4712 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4713 +
4714 +out_unlock:
4715 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4716 +
4717 +out_fput_both:
4718 +       vxdprintk(VXD_CBIT(misc, 3),
4719 +               "fput(new_file=%p[#%ld])", new_file,
4720 +               atomic_long_read(&new_file->f_count));
4721 +       fput(new_file);
4722 +
4723 +out_fput_old:
4724 +       vxdprintk(VXD_CBIT(misc, 3),
4725 +               "fput(old_file=%p[#%ld])", old_file,
4726 +               atomic_long_read(&old_file->f_count));
4727 +       fput(old_file);
4728 +
4729 +out_unlock_new:
4730 +       /* drop references from dir_nd.path */
4731 +       path_put(&dir_nd.path);
4732 +
4733 +       if (drop) {
4734 +               /* unlock the inode mutex from kern_path_create() */
4735 +               mutex_unlock(&dir->d_inode->i_mutex);
4736 +
4737 +               /* drop write access to mnt */
4738 +               mnt_drop_write(new_path->mnt);
4739 +       }
4740 +
4741 +       if (!ret)
4742 +               goto out_redo;
4743 +
4744 +       /* error path cleanup */
4745 +       vfs_unlink(dir->d_inode, new_dentry, NULL);
4746 +
4747 +out_redo:
4748 +       if (!redo)
4749 +               goto out_rel_both;
4750 +
4751 +       /* lookup dentry once again
4752 +          old_nd.path will be freed as old_path in out_rel_old */
4753 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4754 +       if (ret)
4755 +               goto out_rel_both;
4756 +
4757 +       /* drop reference on new_dentry */
4758 +       dput(new_dentry);
4759 +       new_dentry = old_path->dentry;
4760 +       dget(new_dentry);
4761 +       vxdprintk(VXD_CBIT(misc, 2),
4762 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4763 +               new_dentry,
4764 +               new_dentry->d_name.len, new_dentry->d_name.name,
4765 +               new_dentry->d_name.len);
4766 +
4767 +out_rel_both:
4768 +       if (new_path)
4769 +               path_put(new_path);
4770 +out_rel_old:
4771 +       path_put(old_path);
4772 +out_free_path:
4773 +       kfree(path);
4774 +out:
4775 +       if (ret) {
4776 +               dput(new_dentry);
4777 +               new_dentry = ERR_PTR(ret);
4778 +       }
4779 +       vxdprintk(VXD_CBIT(misc, 3),
4780 +               "cow_break_link returning with %p", new_dentry);
4781 +       return new_dentry;
4782 +}
4783 +
4784 +#endif
4785 +
4786 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4787 +{
4788 +       struct path path;
4789 +       struct vfsmount *vmnt;
4790 +       char *pstr, *root;
4791 +       int length = 0;
4792 +
4793 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4794 +       if (!pstr)
4795 +               return 0;
4796 +
4797 +       vmnt = &ns->root->mnt;
4798 +       path.mnt = vmnt;
4799 +       path.dentry = vmnt->mnt_root;
4800 +       root = d_path(&path, pstr, PATH_MAX - 2);
4801 +       length = sprintf(buffer + length,
4802 +               "Namespace:\t%p [#%u]\n"
4803 +               "RootPath:\t%s\n",
4804 +               ns, atomic_read(&ns->count),
4805 +               root);
4806 +       kfree(pstr);
4807 +       return length;
4808 +}
4809 +
4810  /* get the link contents into pagecache */
4811  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4812  {
4813 @@ -4427,3 +4852,4 @@ EXPORT_SYMBOL(vfs_symlink);
4814  EXPORT_SYMBOL(vfs_unlink);
4815  EXPORT_SYMBOL(dentry_unhash);
4816  EXPORT_SYMBOL(generic_readlink);
4817 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4818 diff -NurpP --minimal linux-3.13.10/fs/namespace.c linux-3.13.10-vs2.3.6.11/fs/namespace.c
4819 --- linux-3.13.10/fs/namespace.c        2014-04-17 01:12:32.000000000 +0000
4820 +++ linux-3.13.10-vs2.3.6.11/fs/namespace.c     2014-04-17 01:18:37.000000000 +0000
4821 @@ -24,6 +24,11 @@
4822  #include <linux/proc_ns.h>
4823  #include <linux/magic.h>
4824  #include <linux/bootmem.h>
4825 +#include <linux/vs_base.h>
4826 +#include <linux/vs_context.h>
4827 +#include <linux/vs_tag.h>
4828 +#include <linux/vserver/space.h>
4829 +#include <linux/vserver/global.h>
4830  #include "pnode.h"
4831  #include "internal.h"
4832  
4833 @@ -839,6 +844,10 @@ vfs_kern_mount(struct file_system_type *
4834         if (!type)
4835                 return ERR_PTR(-ENODEV);
4836  
4837 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4838 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4839 +               return ERR_PTR(-EPERM);
4840 +
4841         mnt = alloc_vfsmnt(name);
4842         if (!mnt)
4843                 return ERR_PTR(-ENOMEM);
4844 @@ -899,6 +908,7 @@ static struct mount *clone_mnt(struct mo
4845         mnt->mnt.mnt_root = dget(root);
4846         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4847         mnt->mnt_parent = mnt;
4848 +       mnt->mnt_tag = old->mnt_tag;
4849         lock_mount_hash();
4850         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4851         unlock_mount_hash();
4852 @@ -1369,7 +1379,8 @@ static int do_umount(struct mount *mnt,
4853   */
4854  static inline bool may_mount(void)
4855  {
4856 -       return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4857 +       return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4858 +               CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4859  }
4860  
4861  /*
4862 @@ -1785,6 +1796,7 @@ static int do_change_type(struct path *p
4863                 if (err)
4864                         goto out_unlock;
4865         }
4866 +       // mnt->mnt_flags = mnt_flags;
4867  
4868         lock_mount_hash();
4869         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4870 @@ -1813,12 +1825,14 @@ static bool has_locked_children(struct m
4871   * do loopback mount.
4872   */
4873  static int do_loopback(struct path *path, const char *old_name,
4874 -                               int recurse)
4875 +       vtag_t tag, unsigned long flags, int mnt_flags)
4876  {
4877         struct path old_path;
4878         struct mount *mnt = NULL, *old, *parent;
4879         struct mountpoint *mp;
4880 +       int recurse = flags & MS_REC;
4881         int err;
4882 +
4883         if (!old_name || !*old_name)
4884                 return -EINVAL;
4885         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4886 @@ -1898,7 +1912,7 @@ static int change_mount_flags(struct vfs
4887   * on it - tough luck.
4888   */
4889  static int do_remount(struct path *path, int flags, int mnt_flags,
4890 -                     void *data)
4891 +       void *data, vxid_t xid)
4892  {
4893         int err;
4894         struct super_block *sb = path->mnt->mnt_sb;
4895 @@ -2377,6 +2391,7 @@ long do_mount(const char *dev_name, cons
4896         struct path path;
4897         int retval = 0;
4898         int mnt_flags = 0;
4899 +       vtag_t tag = 0;
4900  
4901         /* Discard magic */
4902         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4903 @@ -2406,6 +2421,12 @@ long do_mount(const char *dev_name, cons
4904         if (!(flags & MS_NOATIME))
4905                 mnt_flags |= MNT_RELATIME;
4906  
4907 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4908 +               /* FIXME: bind and re-mounts get the tag flag? */
4909 +               if (flags & (MS_BIND|MS_REMOUNT))
4910 +                       flags |= MS_TAGID;
4911 +       }
4912 +
4913         /* Separate the per-mountpoint flags */
4914         if (flags & MS_NOSUID)
4915                 mnt_flags |= MNT_NOSUID;
4916 @@ -2422,15 +2443,17 @@ long do_mount(const char *dev_name, cons
4917         if (flags & MS_RDONLY)
4918                 mnt_flags |= MNT_READONLY;
4919  
4920 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4921 +               mnt_flags |= MNT_NODEV;
4922         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4923                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4924                    MS_STRICTATIME);
4925  
4926         if (flags & MS_REMOUNT)
4927                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4928 -                                   data_page);
4929 +                                   data_page, tag);
4930         else if (flags & MS_BIND)
4931 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
4932 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4933         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4934                 retval = do_change_type(&path, flags);
4935         else if (flags & MS_MOVE)
4936 @@ -2546,6 +2569,7 @@ struct mnt_namespace *copy_mnt_ns(unsign
4937                         p = next_mnt(p, old);
4938         }
4939         namespace_unlock();
4940 +       atomic_inc(&vs_global_mnt_ns);
4941  
4942         if (rootmnt)
4943                 mntput(rootmnt);
4944 @@ -2727,9 +2751,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4945         new_mnt = real_mount(new.mnt);
4946         root_mnt = real_mount(root.mnt);
4947         old_mnt = real_mount(old.mnt);
4948 -       if (IS_MNT_SHARED(old_mnt) ||
4949 +       if ((IS_MNT_SHARED(old_mnt) ||
4950                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4951 -               IS_MNT_SHARED(root_mnt->mnt_parent))
4952 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4953 +               !vx_flags(VXF_STATE_SETUP, 0))
4954                 goto out4;
4955         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4956                 goto out4;
4957 @@ -2859,6 +2884,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4958         if (!atomic_dec_and_test(&ns->count))
4959                 return;
4960         drop_collected_mounts(&ns->root->mnt);
4961 +       atomic_dec(&vs_global_mnt_ns);
4962         free_mnt_ns(ns);
4963  }
4964  
4965 diff -NurpP --minimal linux-3.13.10/fs/nfs/client.c linux-3.13.10-vs2.3.6.11/fs/nfs/client.c
4966 --- linux-3.13.10/fs/nfs/client.c       2014-01-22 20:39:06.000000000 +0000
4967 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/client.c    2014-01-31 20:38:03.000000000 +0000
4968 @@ -685,6 +685,9 @@ int nfs_init_server_rpcclient(struct nfs
4969         if (server->flags & NFS_MOUNT_SOFT)
4970                 server->client->cl_softrtry = 1;
4971  
4972 +       server->client->cl_tag = 0;
4973 +       if (server->flags & NFS_MOUNT_TAGGED)
4974 +               server->client->cl_tag = 1;
4975         return 0;
4976  }
4977  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4978 @@ -863,6 +866,10 @@ static void nfs_server_set_fsinfo(struct
4979                 server->acdirmin = server->acdirmax = 0;
4980         }
4981  
4982 +       /* FIXME: needs fsinfo
4983 +       if (server->flags & NFS_MOUNT_TAGGED)
4984 +               sb->s_flags |= MS_TAGGED;       */
4985 +
4986         server->maxfilesize = fsinfo->maxfilesize;
4987  
4988         server->time_delta = fsinfo->time_delta;
4989 diff -NurpP --minimal linux-3.13.10/fs/nfs/dir.c linux-3.13.10-vs2.3.6.11/fs/nfs/dir.c
4990 --- linux-3.13.10/fs/nfs/dir.c  2014-04-17 01:12:32.000000000 +0000
4991 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/dir.c       2014-02-25 11:26:10.000000000 +0000
4992 @@ -37,6 +37,7 @@
4993  #include <linux/sched.h>
4994  #include <linux/kmemleak.h>
4995  #include <linux/xattr.h>
4996 +#include <linux/vs_tag.h>
4997  
4998  #include "delegation.h"
4999  #include "iostat.h"
5000 @@ -1319,6 +1320,7 @@ struct dentry *nfs_lookup(struct inode *
5001         /* Success: notify readdir to use READDIRPLUS */
5002         nfs_advise_use_readdirplus(dir);
5003  
5004 +       dx_propagate_tag(nd, inode);
5005  no_entry:
5006         res = d_materialise_unique(dentry, inode);
5007         if (res != NULL) {
5008 diff -NurpP --minimal linux-3.13.10/fs/nfs/inode.c linux-3.13.10-vs2.3.6.11/fs/nfs/inode.c
5009 --- linux-3.13.10/fs/nfs/inode.c        2014-04-17 01:12:32.000000000 +0000
5010 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/inode.c     2014-03-12 15:51:07.000000000 +0000
5011 @@ -38,6 +38,7 @@
5012  #include <linux/slab.h>
5013  #include <linux/compat.h>
5014  #include <linux/freezer.h>
5015 +#include <linux/vs_tag.h>
5016  
5017  #include <asm/uaccess.h>
5018  
5019 @@ -359,6 +360,8 @@ nfs_fhget(struct super_block *sb, struct
5020         if (inode->i_state & I_NEW) {
5021                 struct nfs_inode *nfsi = NFS_I(inode);
5022                 unsigned long now = jiffies;
5023 +               kuid_t kuid;
5024 +               kgid_t kgid;
5025  
5026                 /* We set i_ino for the few things that still rely on it,
5027                  * such as stat(2) */
5028 @@ -403,8 +406,8 @@ nfs_fhget(struct super_block *sb, struct
5029                 inode->i_version = 0;
5030                 inode->i_size = 0;
5031                 clear_nlink(inode);
5032 -               inode->i_uid = make_kuid(&init_user_ns, -2);
5033 -               inode->i_gid = make_kgid(&init_user_ns, -2);
5034 +               kuid = make_kuid(&init_user_ns, -2);
5035 +               kgid = make_kgid(&init_user_ns, -2);
5036                 inode->i_blocks = 0;
5037                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5038                 nfsi->write_io = 0;
5039 @@ -438,11 +441,11 @@ nfs_fhget(struct super_block *sb, struct
5040                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5041                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5042                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5043 -                       inode->i_uid = fattr->uid;
5044 +                       kuid = fattr->uid;
5045                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5046                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5047                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5048 -                       inode->i_gid = fattr->gid;
5049 +                       kgid = fattr->gid;
5050                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5051                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5052                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5053 @@ -453,6 +456,10 @@ nfs_fhget(struct super_block *sb, struct
5054                          */
5055                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5056                 }
5057 +               inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5058 +               inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5059 +               inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
5060 +                               /* maybe fattr->xid someday */
5061  
5062                 nfs_setsecurity(inode, fattr, label);
5063  
5064 @@ -578,6 +585,8 @@ void nfs_setattr_update_inode(struct ino
5065                         inode->i_uid = attr->ia_uid;
5066                 if ((attr->ia_valid & ATTR_GID) != 0)
5067                         inode->i_gid = attr->ia_gid;
5068 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5069 +                       inode->i_tag = attr->ia_tag;
5070                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5071                 spin_unlock(&inode->i_lock);
5072         }
5073 @@ -1092,7 +1101,9 @@ static int nfs_check_inode_attributes(st
5074         struct nfs_inode *nfsi = NFS_I(inode);
5075         loff_t cur_size, new_isize;
5076         unsigned long invalid = 0;
5077 -
5078 +       kuid_t kuid;
5079 +       kgid_t kgid;
5080 +       ktag_t ktag;
5081  
5082         if (nfs_have_delegated_attributes(inode))
5083                 return 0;
5084 @@ -1117,13 +1128,18 @@ static int nfs_check_inode_attributes(st
5085                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5086         }
5087  
5088 +       kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
5089 +       kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
5090 +       ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
5091 +
5092         /* Have any file permissions changed? */
5093         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5094                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5095 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5096 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5097                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5098 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5099 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5100                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5101 +               /* maybe check for tag too? */
5102  
5103         /* Has the link count changed? */
5104         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5105 @@ -1440,6 +1456,9 @@ static int nfs_update_inode(struct inode
5106         unsigned long invalid = 0;
5107         unsigned long now = jiffies;
5108         unsigned long save_cache_validity;
5109 +       kuid_t kuid;
5110 +       kgid_t kgid;
5111 +       ktag_t ktag;
5112  
5113         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5114                         __func__, inode->i_sb->s_id, inode->i_ino,
5115 @@ -1541,6 +1560,9 @@ static int nfs_update_inode(struct inode
5116                                 | NFS_INO_REVAL_PAGECACHE
5117                                 | NFS_INO_REVAL_FORCED);
5118  
5119 +       kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5120 +       kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5121 +       ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
5122  
5123         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5124                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5125 @@ -1583,6 +1605,10 @@ static int nfs_update_inode(struct inode
5126                                 | NFS_INO_INVALID_ACL
5127                                 | NFS_INO_REVAL_FORCED);
5128  
5129 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5130 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5131 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
5132 +
5133         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5134                 if (inode->i_nlink != fattr->nlink) {
5135                         invalid |= NFS_INO_INVALID_ATTR;
5136 diff -NurpP --minimal linux-3.13.10/fs/nfs/nfs3xdr.c linux-3.13.10-vs2.3.6.11/fs/nfs/nfs3xdr.c
5137 --- linux-3.13.10/fs/nfs/nfs3xdr.c      2013-05-31 13:45:24.000000000 +0000
5138 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/nfs3xdr.c   2014-01-31 20:38:03.000000000 +0000
5139 @@ -20,6 +20,7 @@
5140  #include <linux/nfs3.h>
5141  #include <linux/nfs_fs.h>
5142  #include <linux/nfsacl.h>
5143 +#include <linux/vs_tag.h>
5144  #include "internal.h"
5145  
5146  #define NFSDBG_FACILITY                NFSDBG_XDR
5147 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5148   *             set_mtime       mtime;
5149   *     };
5150   */
5151 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5152 +static void encode_sattr3(struct xdr_stream *xdr,
5153 +       const struct iattr *attr, int tag)
5154  {
5155         u32 nbytes;
5156         __be32 *p;
5157 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5158         } else
5159                 *p++ = xdr_zero;
5160  
5161 -       if (attr->ia_valid & ATTR_UID) {
5162 +       if (attr->ia_valid & ATTR_UID ||
5163 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5164                 *p++ = xdr_one;
5165 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5166 +               *p++ = cpu_to_be32(from_kuid(&init_user_ns,
5167 +                       TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
5168         } else
5169                 *p++ = xdr_zero;
5170  
5171 -       if (attr->ia_valid & ATTR_GID) {
5172 +       if (attr->ia_valid & ATTR_GID ||
5173 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5174                 *p++ = xdr_one;
5175 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5176 +               *p++ = cpu_to_be32(from_kgid(&init_user_ns,
5177 +                       TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
5178         } else
5179                 *p++ = xdr_zero;
5180  
5181 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5182                                       const struct nfs3_sattrargs *args)
5183  {
5184         encode_nfs_fh3(xdr, args->fh);
5185 -       encode_sattr3(xdr, args->sattr);
5186 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5187         encode_sattrguard3(xdr, args);
5188  }
5189  
5190 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5191   *     };
5192   */
5193  static void encode_createhow3(struct xdr_stream *xdr,
5194 -                             const struct nfs3_createargs *args)
5195 +       const struct nfs3_createargs *args, int tag)
5196  {
5197         encode_uint32(xdr, args->createmode);
5198         switch (args->createmode) {
5199         case NFS3_CREATE_UNCHECKED:
5200         case NFS3_CREATE_GUARDED:
5201 -               encode_sattr3(xdr, args->sattr);
5202 +               encode_sattr3(xdr, args->sattr, tag);
5203                 break;
5204         case NFS3_CREATE_EXCLUSIVE:
5205                 encode_createverf3(xdr, args->verifier);
5206 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5207                                      const struct nfs3_createargs *args)
5208  {
5209         encode_diropargs3(xdr, args->fh, args->name, args->len);
5210 -       encode_createhow3(xdr, args);
5211 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5212  }
5213  
5214  /*
5215 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5216                                     const struct nfs3_mkdirargs *args)
5217  {
5218         encode_diropargs3(xdr, args->fh, args->name, args->len);
5219 -       encode_sattr3(xdr, args->sattr);
5220 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5221  }
5222  
5223  /*
5224 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5225   *     };
5226   */
5227  static void encode_symlinkdata3(struct xdr_stream *xdr,
5228 -                               const struct nfs3_symlinkargs *args)
5229 +       const struct nfs3_symlinkargs *args, int tag)
5230  {
5231 -       encode_sattr3(xdr, args->sattr);
5232 +       encode_sattr3(xdr, args->sattr, tag);
5233         encode_nfspath3(xdr, args->pages, args->pathlen);
5234  }
5235  
5236 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5237                                       const struct nfs3_symlinkargs *args)
5238  {
5239         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5240 -       encode_symlinkdata3(xdr, args);
5241 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5242  }
5243  
5244  /*
5245 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5246   *     };
5247   */
5248  static void encode_devicedata3(struct xdr_stream *xdr,
5249 -                              const struct nfs3_mknodargs *args)
5250 +       const struct nfs3_mknodargs *args, int tag)
5251  {
5252 -       encode_sattr3(xdr, args->sattr);
5253 +       encode_sattr3(xdr, args->sattr, tag);
5254         encode_specdata3(xdr, args->rdev);
5255  }
5256  
5257  static void encode_mknoddata3(struct xdr_stream *xdr,
5258 -                             const struct nfs3_mknodargs *args)
5259 +       const struct nfs3_mknodargs *args, int tag)
5260  {
5261         encode_ftype3(xdr, args->type);
5262         switch (args->type) {
5263         case NF3CHR:
5264         case NF3BLK:
5265 -               encode_devicedata3(xdr, args);
5266 +               encode_devicedata3(xdr, args, tag);
5267                 break;
5268         case NF3SOCK:
5269         case NF3FIFO:
5270 -               encode_sattr3(xdr, args->sattr);
5271 +               encode_sattr3(xdr, args->sattr, tag);
5272                 break;
5273         case NF3REG:
5274         case NF3DIR:
5275 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5276                                     const struct nfs3_mknodargs *args)
5277  {
5278         encode_diropargs3(xdr, args->fh, args->name, args->len);
5279 -       encode_mknoddata3(xdr, args);
5280 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5281  }
5282  
5283  /*
5284 diff -NurpP --minimal linux-3.13.10/fs/nfs/super.c linux-3.13.10-vs2.3.6.11/fs/nfs/super.c
5285 --- linux-3.13.10/fs/nfs/super.c        2014-01-22 20:39:06.000000000 +0000
5286 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/super.c     2014-01-31 20:38:03.000000000 +0000
5287 @@ -55,6 +55,7 @@
5288  #include <linux/parser.h>
5289  #include <linux/nsproxy.h>
5290  #include <linux/rcupdate.h>
5291 +#include <linux/vs_tag.h>
5292  
5293  #include <asm/uaccess.h>
5294  
5295 @@ -103,6 +104,7 @@ enum {
5296         Opt_mountport,
5297         Opt_mountvers,
5298         Opt_minorversion,
5299 +       Opt_tagid,
5300  
5301         /* Mount options that take string arguments */
5302         Opt_nfsvers,
5303 @@ -115,6 +117,9 @@ enum {
5304         /* Special mount options */
5305         Opt_userspace, Opt_deprecated, Opt_sloppy,
5306  
5307 +       /* Linux-VServer tagging options */
5308 +       Opt_tag, Opt_notag,
5309 +
5310         Opt_err
5311  };
5312  
5313 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5314         { Opt_fscache_uniq, "fsc=%s" },
5315         { Opt_local_lock, "local_lock=%s" },
5316  
5317 +       { Opt_tag, "tag" },
5318 +       { Opt_notag, "notag" },
5319 +       { Opt_tagid, "tagid=%u" },
5320 +
5321         /* The following needs to be listed after all other options */
5322         { Opt_nfsvers, "v%s" },
5323  
5324 @@ -638,6 +647,7 @@ static void nfs_show_mount_options(struc
5325                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5326                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5327                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5328 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5329                 { 0, NULL, NULL }
5330         };
5331         const struct proc_nfs_info *nfs_infop;
5332 @@ -1321,6 +1331,14 @@ static int nfs_parse_mount_options(char
5333                 case Opt_nomigration:
5334                         mnt->options &= NFS_OPTION_MIGRATION;
5335                         break;
5336 +#ifndef CONFIG_TAGGING_NONE
5337 +               case Opt_tag:
5338 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5339 +                       break;
5340 +               case Opt_notag:
5341 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5342 +                       break;
5343 +#endif
5344  
5345                 /*
5346                  * options that take numeric values
5347 @@ -1407,6 +1425,12 @@ static int nfs_parse_mount_options(char
5348                                 goto out_invalid_value;
5349                         mnt->minorversion = option;
5350                         break;
5351 +#ifdef CONFIG_PROPAGATE
5352 +               case Opt_tagid:
5353 +                       /* use args[0] */
5354 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5355 +                       break;
5356 +#endif
5357  
5358                 /*
5359                  * options that take text values
5360 diff -NurpP --minimal linux-3.13.10/fs/nfsd/auth.c linux-3.13.10-vs2.3.6.11/fs/nfsd/auth.c
5361 --- linux-3.13.10/fs/nfsd/auth.c        2013-05-31 13:45:24.000000000 +0000
5362 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/auth.c     2014-01-31 20:38:03.000000000 +0000
5363 @@ -2,6 +2,7 @@
5364  
5365  #include <linux/sched.h>
5366  #include <linux/user_namespace.h>
5367 +#include <linux/vs_tag.h>
5368  #include "nfsd.h"
5369  #include "auth.h"
5370  
5371 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5372  
5373         new->fsuid = rqstp->rq_cred.cr_uid;
5374         new->fsgid = rqstp->rq_cred.cr_gid;
5375 +       /* FIXME: this desperately needs a tag :)
5376 +       new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5377 +                       */
5378  
5379         rqgi = rqstp->rq_cred.cr_group_info;
5380  
5381 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfs3xdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs3xdr.c
5382 --- linux-3.13.10/fs/nfsd/nfs3xdr.c     2013-05-31 13:45:24.000000000 +0000
5383 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs3xdr.c  2014-01-31 20:38:03.000000000 +0000
5384 @@ -8,6 +8,7 @@
5385  
5386  #include <linux/namei.h>
5387  #include <linux/sunrpc/svc_xprt.h>
5388 +#include <linux/vs_tag.h>
5389  #include "xdr3.h"
5390  #include "auth.h"
5391  #include "netns.h"
5392 @@ -98,6 +99,8 @@ static __be32 *
5393  decode_sattr3(__be32 *p, struct iattr *iap)
5394  {
5395         u32     tmp;
5396 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5397 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5398  
5399         iap->ia_valid = 0;
5400  
5401 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5402                 iap->ia_mode = ntohl(*p++);
5403         }
5404         if (*p++) {
5405 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5406 +               kuid = make_kuid(&init_user_ns, ntohl(*p++));
5407                 if (uid_valid(iap->ia_uid))
5408                         iap->ia_valid |= ATTR_UID;
5409         }
5410         if (*p++) {
5411 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5412 +               kgid = make_kgid(&init_user_ns, ntohl(*p++));
5413                 if (gid_valid(iap->ia_gid))
5414                         iap->ia_valid |= ATTR_GID;
5415         }
5416 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5417 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5418 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5419         if (*p++) {
5420                 u64     newsize;
5421  
5422 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5423         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5424         *p++ = htonl((u32) stat->mode);
5425         *p++ = htonl((u32) stat->nlink);
5426 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5427 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5428 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5429 +               TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5430 +               stat->uid, stat->tag)));
5431 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5432 +               TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5433 +               stat->gid, stat->tag)));
5434         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5435                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5436         } else {
5437 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfs4xdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs4xdr.c
5438 --- linux-3.13.10/fs/nfsd/nfs4xdr.c     2014-01-22 20:39:06.000000000 +0000
5439 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs4xdr.c  2014-01-31 20:38:03.000000000 +0000
5440 @@ -46,6 +46,7 @@
5441  #include <linux/utsname.h>
5442  #include <linux/pagemap.h>
5443  #include <linux/sunrpc/svcauth_gss.h>
5444 +#include <linux/vs_tag.h>
5445  
5446  #include "idmap.h"
5447  #include "acl.h"
5448 @@ -2430,10 +2431,14 @@ out_acl:
5449                 WRITE32(stat.nlink);
5450         }
5451         if (bmval1 & FATTR4_WORD1_OWNER) {
5452 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5453 +               status = nfsd4_encode_user(rqstp,
5454 +                       TAGINO_KUID(DX_TAG(dentry->d_inode),
5455 +                       stat.uid, stat.tag), &p, &buflen);
5456                 if (status)
5457                         goto out;
5458         }
5459         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5460 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5461 +               status = nfsd4_encode_group(rqstp,
5462 +                       TAGINO_KGID(DX_TAG(dentry->d_inode),
5463 +                       stat.gid, stat.tag), &p, &buflen);
5464                 if (status)
5465                         goto out;
5466         }
5467 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfsxdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfsxdr.c
5468 --- linux-3.13.10/fs/nfsd/nfsxdr.c      2013-05-31 13:45:24.000000000 +0000
5469 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfsxdr.c   2014-01-31 20:38:03.000000000 +0000
5470 @@ -7,6 +7,7 @@
5471  #include "vfs.h"
5472  #include "xdr.h"
5473  #include "auth.h"
5474 +#include <linux/vs_tag.h>
5475  
5476  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5477  
5478 @@ -89,6 +90,8 @@ static __be32 *
5479  decode_sattr(__be32 *p, struct iattr *iap)
5480  {
5481         u32     tmp, tmp1;
5482 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5483 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5484  
5485         iap->ia_valid = 0;
5486  
5487 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5488                 iap->ia_mode = tmp;
5489         }
5490         if ((tmp = ntohl(*p++)) != (u32)-1) {
5491 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5492 +               kuid = make_kuid(&init_user_ns, tmp);
5493                 if (uid_valid(iap->ia_uid))
5494                         iap->ia_valid |= ATTR_UID;
5495         }
5496         if ((tmp = ntohl(*p++)) != (u32)-1) {
5497 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5498 +               kgid = make_kgid(&init_user_ns, tmp);
5499                 if (gid_valid(iap->ia_gid))
5500                         iap->ia_valid |= ATTR_GID;
5501         }
5502 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5503 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5504 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5505         if ((tmp = ntohl(*p++)) != (u32)-1) {
5506                 iap->ia_valid |= ATTR_SIZE;
5507                 iap->ia_size = tmp;
5508 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5509         *p++ = htonl(nfs_ftypes[type >> 12]);
5510         *p++ = htonl((u32) stat->mode);
5511         *p++ = htonl((u32) stat->nlink);
5512 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5513 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5514 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5515 +               TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5516 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5517 +               TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5518  
5519         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5520                 *p++ = htonl(NFS_MAXPATHLEN);
5521 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/dlmglue.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.c
5522 --- linux-3.13.10/fs/ocfs2/dlmglue.c    2014-01-22 20:39:07.000000000 +0000
5523 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.c 2014-01-31 20:38:03.000000000 +0000
5524 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5525         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5526         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5527         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5528 +       lvb->lvb_itag      = cpu_to_be16(i_tag_read(inode));
5529         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5530         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5531         lvb->lvb_iatime_packed  =
5532 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5533  
5534         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5535         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5536 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5537         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5538         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5539         ocfs2_unpack_timespec(&inode->i_atime,
5540 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/dlmglue.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.h
5541 --- linux-3.13.10/fs/ocfs2/dlmglue.h    2012-12-11 03:30:57.000000000 +0000
5542 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.h 2014-01-31 20:38:03.000000000 +0000
5543 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5544         __be16       lvb_inlink;
5545         __be32       lvb_iattr;
5546         __be32       lvb_igeneration;
5547 -       __be32       lvb_reserved2;
5548 +       __be16       lvb_itag;
5549 +       __be16       lvb_reserved2;
5550  };
5551  
5552  #define OCFS2_QINFO_LVB_VERSION 1
5553 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/file.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/file.c
5554 --- linux-3.13.10/fs/ocfs2/file.c       2014-04-17 01:12:32.000000000 +0000
5555 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/file.c    2014-04-17 01:17:10.000000000 +0000
5556 @@ -1119,7 +1119,7 @@ int ocfs2_setattr(struct dentry *dentry,
5557                 attr->ia_valid &= ~ATTR_SIZE;
5558  
5559  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5560 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5561 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5562         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5563                 return 0;
5564  
5565 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/inode.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.c
5566 --- linux-3.13.10/fs/ocfs2/inode.c      2014-01-22 20:39:07.000000000 +0000
5567 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.c   2014-01-31 20:38:03.000000000 +0000
5568 @@ -28,6 +28,7 @@
5569  #include <linux/highmem.h>
5570  #include <linux/pagemap.h>
5571  #include <linux/quotaops.h>
5572 +#include <linux/vs_tag.h>
5573  
5574  #include <asm/byteorder.h>
5575  
5576 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5577  {
5578         unsigned int flags = OCFS2_I(inode)->ip_attr;
5579  
5580 -       inode->i_flags &= ~(S_IMMUTABLE |
5581 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5582                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5583  
5584         if (flags & OCFS2_IMMUTABLE_FL)
5585                 inode->i_flags |= S_IMMUTABLE;
5586 +       if (flags & OCFS2_IXUNLINK_FL)
5587 +               inode->i_flags |= S_IXUNLINK;
5588  
5589         if (flags & OCFS2_SYNC_FL)
5590                 inode->i_flags |= S_SYNC;
5591 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5592                 inode->i_flags |= S_NOATIME;
5593         if (flags & OCFS2_DIRSYNC_FL)
5594                 inode->i_flags |= S_DIRSYNC;
5595 +
5596 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5597 +
5598 +       if (flags & OCFS2_BARRIER_FL)
5599 +               inode->i_vflags |= V_BARRIER;
5600 +       if (flags & OCFS2_COW_FL)
5601 +               inode->i_vflags |= V_COW;
5602  }
5603  
5604  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5605  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5606  {
5607         unsigned int flags = oi->vfs_inode.i_flags;
5608 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5609 +
5610 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5611 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5612 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5613 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5614 +
5615 +       if (flags & S_IMMUTABLE)
5616 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5617 +       if (flags & S_IXUNLINK)
5618 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5619  
5620 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5621 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5622         if (flags & S_SYNC)
5623                 oi->ip_attr |= OCFS2_SYNC_FL;
5624         if (flags & S_APPEND)
5625                 oi->ip_attr |= OCFS2_APPEND_FL;
5626 -       if (flags & S_IMMUTABLE)
5627 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5628         if (flags & S_NOATIME)
5629                 oi->ip_attr |= OCFS2_NOATIME_FL;
5630         if (flags & S_DIRSYNC)
5631                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5632 +
5633 +       if (vflags & V_BARRIER)
5634 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5635 +       if (vflags & V_COW)
5636 +               oi->ip_attr |= OCFS2_COW_FL;
5637  }
5638  
5639  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5640 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5641         struct super_block *sb;
5642         struct ocfs2_super *osb;
5643         int use_plocks = 1;
5644 +       uid_t uid;
5645 +       gid_t gid;
5646  
5647         sb = inode->i_sb;
5648         osb = OCFS2_SB(sb);
5649 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5650         inode->i_generation = le32_to_cpu(fe->i_generation);
5651         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5652         inode->i_mode = le16_to_cpu(fe->i_mode);
5653 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5654 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5655 +       uid = le32_to_cpu(fe->i_uid);
5656 +       gid = le32_to_cpu(fe->i_gid);
5657 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5658 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5659 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5660 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5661  
5662         /* Fast symlinks will have i_size but no allocated clusters. */
5663         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5664 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/inode.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.h
5665 --- linux-3.13.10/fs/ocfs2/inode.h      2013-07-14 17:01:29.000000000 +0000
5666 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.h   2014-01-31 20:38:03.000000000 +0000
5667 @@ -152,6 +152,7 @@ struct buffer_head *ocfs2_bread(struct i
5668  
5669  void ocfs2_set_inode_flags(struct inode *inode);
5670  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5671 +int ocfs2_sync_flags(struct inode *inode, int, int);
5672  
5673  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5674  {
5675 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/ioctl.c
5676 --- linux-3.13.10/fs/ocfs2/ioctl.c      2013-11-25 15:47:00.000000000 +0000
5677 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ioctl.c   2014-01-31 20:38:03.000000000 +0000
5678 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5679         return status;
5680  }
5681  
5682 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5683 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5684 +{
5685 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5686 +       struct buffer_head *bh = NULL;
5687 +       handle_t *handle = NULL;
5688 +       int status;
5689 +
5690 +       status = ocfs2_inode_lock(inode, &bh, 1);
5691 +       if (status < 0) {
5692 +               mlog_errno(status);
5693 +               return status;
5694 +       }
5695 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5696 +       if (IS_ERR(handle)) {
5697 +               status = PTR_ERR(handle);
5698 +               mlog_errno(status);
5699 +               goto bail_unlock;
5700 +       }
5701 +
5702 +       inode->i_flags = flags;
5703 +       inode->i_vflags = vflags;
5704 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5705 +
5706 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5707 +       if (status < 0)
5708 +               mlog_errno(status);
5709 +
5710 +       ocfs2_commit_trans(osb, handle);
5711 +bail_unlock:
5712 +       ocfs2_inode_unlock(inode, 1);
5713 +       brelse(bh);
5714 +       return status;
5715 +}
5716 +
5717 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5718                                 unsigned mask)
5719  {
5720         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5721 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5722                         goto bail_unlock;
5723         }
5724  
5725 +       if (IS_BARRIER(inode)) {
5726 +               vxwprintk_task(1, "messing with the barrier.");
5727 +               goto bail_unlock;
5728 +       }
5729 +
5730         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5731         if (IS_ERR(handle)) {
5732                 status = PTR_ERR(handle);
5733 @@ -881,6 +920,7 @@ bail:
5734         return status;
5735  }
5736  
5737 +
5738  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5739  {
5740         struct inode *inode = file_inode(filp);
5741 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/namei.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/namei.c
5742 --- linux-3.13.10/fs/ocfs2/namei.c      2014-01-22 20:39:07.000000000 +0000
5743 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/namei.c   2014-01-31 20:38:03.000000000 +0000
5744 @@ -41,6 +41,7 @@
5745  #include <linux/slab.h>
5746  #include <linux/highmem.h>
5747  #include <linux/quotaops.h>
5748 +#include <linux/vs_tag.h>
5749  
5750  #include <cluster/masklog.h>
5751  
5752 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5753         struct ocfs2_dinode *fe = NULL;
5754         struct ocfs2_extent_list *fel;
5755         u16 feat;
5756 +       ktag_t ktag;
5757  
5758         *new_fe_bh = NULL;
5759  
5760 @@ -512,8 +514,13 @@ static int __ocfs2_mknod_locked(struct i
5761         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5762         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5763         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5764 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5765 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5766 +
5767 +       ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5768 +       fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5769 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5770 +       fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5771 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5772 +       inode->i_tag = ktag; /* is this correct? */
5773         fe->i_mode = cpu_to_le16(inode->i_mode);
5774         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5775                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5776 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ocfs2.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2.h
5777 --- linux-3.13.10/fs/ocfs2/ocfs2.h      2013-11-25 15:45:04.000000000 +0000
5778 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2.h   2014-01-31 20:38:03.000000000 +0000
5779 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5780                                                      writes */
5781         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5782         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5783 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5784  };
5785  
5786  #define OCFS2_OSB_SOFT_RO                      0x0001
5787 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ocfs2_fs.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2_fs.h
5788 --- linux-3.13.10/fs/ocfs2/ocfs2_fs.h   2012-12-11 03:30:57.000000000 +0000
5789 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2_fs.h        2014-01-31 20:38:03.000000000 +0000
5790 @@ -266,6 +266,11 @@
5791  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5792  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5793  
5794 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5795 +
5796 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5797 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5798 +
5799  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5800  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5801  
5802 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/super.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/super.c
5803 --- linux-3.13.10/fs/ocfs2/super.c      2014-01-22 20:39:07.000000000 +0000
5804 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/super.c   2014-01-31 20:38:03.000000000 +0000
5805 @@ -185,6 +185,7 @@ enum {
5806         Opt_coherency_full,
5807         Opt_resv_level,
5808         Opt_dir_resv_level,
5809 +       Opt_tag, Opt_notag, Opt_tagid,
5810         Opt_err,
5811  };
5812  
5813 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5814         {Opt_coherency_full, "coherency=full"},
5815         {Opt_resv_level, "resv_level=%u"},
5816         {Opt_dir_resv_level, "dir_resv_level=%u"},
5817 +       {Opt_tag, "tag"},
5818 +       {Opt_notag, "notag"},
5819 +       {Opt_tagid, "tagid=%u"},
5820         {Opt_err, NULL}
5821  };
5822  
5823 @@ -661,6 +665,13 @@ static int ocfs2_remount(struct super_bl
5824                 goto out;
5825         }
5826  
5827 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5828 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5829 +               ret = -EINVAL;
5830 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5831 +               goto out;
5832 +       }
5833 +
5834         /* We're going to/from readonly mode. */
5835         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5836                 /* Disable quota accounting before remounting RO */
5837 @@ -1176,6 +1187,9 @@ static int ocfs2_fill_super(struct super
5838  
5839         ocfs2_complete_mount_recovery(osb);
5840  
5841 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5842 +               sb->s_flags |= MS_TAGGED;
5843 +
5844         if (ocfs2_mount_local(osb))
5845                 snprintf(nodestr, sizeof(nodestr), "local");
5846         else
5847 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
5848                             option < OCFS2_MAX_RESV_LEVEL)
5849                                 mopt->dir_resv_level = option;
5850                         break;
5851 +#ifndef CONFIG_TAGGING_NONE
5852 +               case Opt_tag:
5853 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5854 +                       break;
5855 +               case Opt_notag:
5856 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5857 +                       break;
5858 +#endif
5859 +#ifdef CONFIG_PROPAGATE
5860 +               case Opt_tagid:
5861 +                       /* use args[0] */
5862 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5863 +                       break;
5864 +#endif
5865                 default:
5866                         mlog(ML_ERROR,
5867                              "Unrecognized mount option \"%s\" "
5868 diff -NurpP --minimal linux-3.13.10/fs/open.c linux-3.13.10-vs2.3.6.11/fs/open.c
5869 --- linux-3.13.10/fs/open.c     2014-01-22 20:39:07.000000000 +0000
5870 +++ linux-3.13.10-vs2.3.6.11/fs/open.c  2014-01-31 20:38:03.000000000 +0000
5871 @@ -31,6 +31,11 @@
5872  #include <linux/ima.h>
5873  #include <linux/dnotify.h>
5874  #include <linux/compat.h>
5875 +#include <linux/vs_base.h>
5876 +#include <linux/vs_limit.h>
5877 +#include <linux/vs_tag.h>
5878 +#include <linux/vs_cowbl.h>
5879 +#include <linux/vserver/dlimit.h>
5880  
5881  #include "internal.h"
5882  
5883 @@ -68,6 +73,11 @@ long vfs_truncate(struct path *path, lof
5884         struct inode *inode;
5885         long error;
5886  
5887 +#ifdef CONFIG_VSERVER_COWBL
5888 +       error = cow_check_and_break(path);
5889 +       if (error)
5890 +               goto out;
5891 +#endif
5892         inode = path->dentry->d_inode;
5893  
5894         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5895 @@ -511,6 +521,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5896         unsigned int lookup_flags = LOOKUP_FOLLOW;
5897  retry:
5898         error = user_path_at(dfd, filename, lookup_flags, &path);
5899 +#ifdef CONFIG_VSERVER_COWBL
5900 +       if (!error) {
5901 +               error = cow_check_and_break(&path);
5902 +               if (error)
5903 +                       path_put(&path);
5904 +       }
5905 +#endif
5906         if (!error) {
5907                 error = chmod_common(&path, mode);
5908                 path_put(&path);
5909 @@ -544,13 +561,15 @@ static int chown_common(struct path *pat
5910                 if (!uid_valid(uid))
5911                         return -EINVAL;
5912                 newattrs.ia_valid |= ATTR_UID;
5913 -               newattrs.ia_uid = uid;
5914 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5915 +                       dx_map_uid(user));
5916         }
5917         if (group != (gid_t) -1) {
5918                 if (!gid_valid(gid))
5919                         return -EINVAL;
5920                 newattrs.ia_valid |= ATTR_GID;
5921 -               newattrs.ia_gid = gid;
5922 +               newattrs.ia_gid = make_kgid(&init_user_ns,
5923 +                       dx_map_gid(group));
5924         }
5925         if (!S_ISDIR(inode->i_mode))
5926                 newattrs.ia_valid |=
5927 @@ -589,6 +608,18 @@ retry:
5928         error = mnt_want_write(path.mnt);
5929         if (error)
5930                 goto out_release;
5931 +#ifdef CONFIG_VSERVER_COWBL
5932 +       error = cow_check_and_break(&path);
5933 +       if (!error)
5934 +#endif
5935 +#ifdef CONFIG_VSERVER_COWBL
5936 +       error = cow_check_and_break(&path);
5937 +       if (!error)
5938 +#endif
5939 +#ifdef CONFIG_VSERVER_COWBL
5940 +       error = cow_check_and_break(&path);
5941 +       if (!error)
5942 +#endif
5943         error = chown_common(&path, user, group);
5944         mnt_drop_write(path.mnt);
5945  out_release:
5946 diff -NurpP --minimal linux-3.13.10/fs/proc/array.c linux-3.13.10-vs2.3.6.11/fs/proc/array.c
5947 --- linux-3.13.10/fs/proc/array.c       2014-01-22 20:39:07.000000000 +0000
5948 +++ linux-3.13.10-vs2.3.6.11/fs/proc/array.c    2014-02-01 01:44:54.000000000 +0000
5949 @@ -82,6 +82,8 @@
5950  #include <linux/ptrace.h>
5951  #include <linux/tracehook.h>
5952  #include <linux/user_namespace.h>
5953 +#include <linux/vs_context.h>
5954 +#include <linux/vs_network.h>
5955  
5956  #include <asm/pgtable.h>
5957  #include <asm/processor.h>
5958 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
5959         rcu_read_lock();
5960         ppid = pid_alive(p) ?
5961                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5962 +       if (unlikely(vx_current_initpid(p->pid)))
5963 +               ppid = 0;
5964 +
5965         tpid = 0;
5966         if (pid_alive(p)) {
5967                 struct task_struct *tracer = ptrace_parent(p);
5968 @@ -299,7 +304,7 @@ static inline void task_sig(struct seq_f
5969  }
5970  
5971  static void render_cap_t(struct seq_file *m, const char *header,
5972 -                       kernel_cap_t *a)
5973 +                       struct vx_info *vxi, kernel_cap_t *a)
5974  {
5975         unsigned __capi;
5976  
5977 @@ -333,10 +338,11 @@ static inline void task_cap(struct seq_f
5978         NORM_CAPS(cap_effective);
5979         NORM_CAPS(cap_bset);
5980  
5981 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
5982 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
5983 -       render_cap_t(m, "CapEff:\t", &cap_effective);
5984 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
5985 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5986 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5987 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5988 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5989 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
5990  }
5991  
5992  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
5993 @@ -365,6 +371,43 @@ static void task_cpus_allowed(struct seq
5994         seq_putc(m, '\n');
5995  }
5996  
5997 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
5998 +                       struct pid *pid, struct task_struct *task)
5999 +{
6000 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6001 +                       "Count:\t%u\n"
6002 +                       "uts:\t%p(%c)\n"
6003 +                       "ipc:\t%p(%c)\n"
6004 +                       "mnt:\t%p(%c)\n"
6005 +                       "pid:\t%p(%c)\n"
6006 +                       "net:\t%p(%c)\n",
6007 +                       task->nsproxy,
6008 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6009 +                       atomic_read(&task->nsproxy->count),
6010 +                       task->nsproxy->uts_ns,
6011 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6012 +                       task->nsproxy->ipc_ns,
6013 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6014 +                       task->nsproxy->mnt_ns,
6015 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6016 +                       task->nsproxy->pid_ns_for_children,
6017 +                       (task->nsproxy->pid_ns_for_children ==
6018 +                               init_task.nsproxy->pid_ns_for_children ? 'I' : '-'),
6019 +                       task->nsproxy->net_ns,
6020 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6021 +       return 0;
6022 +}
6023 +
6024 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6025 +{
6026 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6027 +               return;
6028 +
6029 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6030 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6031 +}
6032 +
6033 +
6034  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6035                         struct pid *pid, struct task_struct *task)
6036  {
6037 @@ -382,6 +425,7 @@ int proc_pid_status(struct seq_file *m,
6038         task_seccomp(m, task);
6039         task_cpus_allowed(m, task);
6040         cpuset_task_status_allowed(m, task);
6041 +       task_vs_id(m, task);
6042         task_context_switch_counts(m, task);
6043         return 0;
6044  }
6045 @@ -491,6 +535,17 @@ static int do_task_stat(struct seq_file
6046         /* convert nsec -> ticks */
6047         start_time = nsec_to_clock_t(start_time);
6048  
6049 +       /* fixup start time for virt uptime */
6050 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6051 +               unsigned long long bias =
6052 +                       current->vx_info->cvirt.bias_clock;
6053 +
6054 +               if (start_time > bias)
6055 +                       start_time -= bias;
6056 +               else
6057 +                       start_time = 0;
6058 +       }
6059 +
6060         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6061         seq_put_decimal_ll(m, ' ', ppid);
6062         seq_put_decimal_ll(m, ' ', pgid);
6063 diff -NurpP --minimal linux-3.13.10/fs/proc/base.c linux-3.13.10-vs2.3.6.11/fs/proc/base.c
6064 --- linux-3.13.10/fs/proc/base.c        2014-04-17 01:12:32.000000000 +0000
6065 +++ linux-3.13.10-vs2.3.6.11/fs/proc/base.c     2014-04-17 01:17:10.000000000 +0000
6066 @@ -87,6 +87,8 @@
6067  #include <linux/slab.h>
6068  #include <linux/flex_array.h>
6069  #include <linux/posix-timers.h>
6070 +#include <linux/vs_context.h>
6071 +#include <linux/vs_network.h>
6072  #ifdef CONFIG_HARDWALL
6073  #include <asm/hardwall.h>
6074  #endif
6075 @@ -976,11 +978,15 @@ static ssize_t oom_adj_write(struct file
6076                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6077  
6078         if (oom_adj < task->signal->oom_score_adj &&
6079 -           !capable(CAP_SYS_RESOURCE)) {
6080 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6081                 err = -EACCES;
6082                 goto err_sighand;
6083         }
6084  
6085 +       /* prevent guest processes from circumventing the oom killer */
6086 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6087 +               oom_adj = OOM_ADJUST_MIN;
6088 +
6089         /*
6090          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6091          * /proc/pid/oom_score_adj instead.
6092 @@ -1565,6 +1571,8 @@ struct inode *proc_pid_make_inode(struct
6093                 inode->i_gid = cred->egid;
6094                 rcu_read_unlock();
6095         }
6096 +       /* procfs is xid tagged */
6097 +       i_tag_write(inode, (vtag_t)vx_task_xid(task));
6098         security_task_to_inode(task, inode);
6099  
6100  out:
6101 @@ -1610,6 +1618,8 @@ int pid_getattr(struct vfsmount *mnt, st
6102  
6103  /* dentry stuff */
6104  
6105 +static unsigned name_to_int(struct dentry *dentry);
6106 +
6107  /*
6108   *     Exceptional case: normally we are not allowed to unhash a busy
6109   * directory. In this case, however, we can do it - no aliasing problems
6110 @@ -1638,6 +1648,12 @@ int pid_revalidate(struct dentry *dentry
6111         task = get_proc_task(inode);
6112  
6113         if (task) {
6114 +               unsigned pid = name_to_int(dentry);
6115 +
6116 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6117 +                       put_task_struct(task);
6118 +                       goto drop;
6119 +               }
6120                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6121                     task_dumpable(task)) {
6122                         rcu_read_lock();
6123 @@ -1654,6 +1670,7 @@ int pid_revalidate(struct dentry *dentry
6124                 put_task_struct(task);
6125                 return 1;
6126         }
6127 +drop:
6128         d_drop(dentry);
6129         return 0;
6130  }
6131 @@ -2173,6 +2190,13 @@ static struct dentry *proc_pident_lookup
6132         if (!task)
6133                 goto out_no_task;
6134  
6135 +       /* TODO: maybe we can come up with a generic approach? */
6136 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6137 +               (dentry->d_name.len == 5) &&
6138 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6139 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6140 +               goto out;
6141 +
6142         /*
6143          * Yes, it does not scale. And it should not. Don't add
6144          * new entries into /proc/<tgid>/ without very good reasons.
6145 @@ -2569,6 +2593,9 @@ static int proc_pid_personality(struct s
6146  static const struct file_operations proc_task_operations;
6147  static const struct inode_operations proc_task_inode_operations;
6148  
6149 +extern int proc_pid_vx_info(struct task_struct *, char *);
6150 +extern int proc_pid_nx_info(struct task_struct *, char *);
6151 +
6152  static const struct pid_entry tgid_base_stuff[] = {
6153         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6154         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6155 @@ -2635,6 +2662,8 @@ static const struct pid_entry tgid_base_
6156  #ifdef CONFIG_CGROUPS
6157         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6158  #endif
6159 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6160 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6161         INF("oom_score",  S_IRUGO, proc_oom_score),
6162         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6163         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6164 @@ -2847,7 +2876,7 @@ retry:
6165         iter.task = NULL;
6166         pid = find_ge_pid(iter.tgid, ns);
6167         if (pid) {
6168 -               iter.tgid = pid_nr_ns(pid, ns);
6169 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6170                 iter.task = pid_task(pid, PIDTYPE_PID);
6171                 /* What we to know is if the pid we have find is the
6172                  * pid of a thread_group_leader.  Testing for task
6173 @@ -2900,8 +2929,10 @@ int proc_pid_readdir(struct file *file,
6174                 if (!has_pid_permissions(ns, iter.task, 2))
6175                         continue;
6176  
6177 -               len = snprintf(name, sizeof(name), "%d", iter.tgid);
6178 +               len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6179                 ctx->pos = iter.tgid + TGID_OFFSET;
6180 +               if (!vx_proc_task_visible(iter.task))
6181 +                       continue;
6182                 if (!proc_fill_cache(file, ctx, name, len,
6183                                      proc_pid_instantiate, iter.task, NULL)) {
6184                         put_task_struct(iter.task);
6185 @@ -2994,6 +3025,7 @@ static const struct pid_entry tid_base_s
6186         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6187         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6188  #endif
6189 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6190  };
6191  
6192  static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
6193 @@ -3060,6 +3092,8 @@ static struct dentry *proc_task_lookup(s
6194         tid = name_to_int(dentry);
6195         if (tid == ~0U)
6196                 goto out;
6197 +       if (vx_current_initpid(tid))
6198 +               goto out;
6199  
6200         ns = dentry->d_sb->s_fs_info;
6201         rcu_read_lock();
6202 diff -NurpP --minimal linux-3.13.10/fs/proc/generic.c linux-3.13.10-vs2.3.6.11/fs/proc/generic.c
6203 --- linux-3.13.10/fs/proc/generic.c     2014-01-22 20:39:07.000000000 +0000
6204 +++ linux-3.13.10-vs2.3.6.11/fs/proc/generic.c  2014-02-01 00:07:40.000000000 +0000
6205 @@ -23,6 +23,7 @@
6206  #include <linux/bitops.h>
6207  #include <linux/spinlock.h>
6208  #include <linux/completion.h>
6209 +#include <linux/vserver/inode.h>
6210  #include <asm/uaccess.h>
6211  
6212  #include "internal.h"
6213 @@ -187,6 +188,8 @@ struct dentry *proc_lookup_de(struct pro
6214         for (de = de->subdir; de ; de = de->next) {
6215                 if (de->namelen != dentry->d_name.len)
6216                         continue;
6217 +               if (!vx_hide_check(0, de->vx_flags))
6218 +                       continue;
6219                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6220                         pde_get(de);
6221                         spin_unlock(&proc_subdir_lock);
6222 @@ -195,6 +198,8 @@ struct dentry *proc_lookup_de(struct pro
6223                                 return ERR_PTR(-ENOMEM);
6224                         d_set_d_op(dentry, &simple_dentry_operations);
6225                         d_add(dentry, inode);
6226 +                       /* generic proc entries belong to the host */
6227 +                       i_tag_write(inode, 0);
6228                         return NULL;
6229                 }
6230         }
6231 @@ -242,6 +247,9 @@ int proc_readdir_de(struct proc_dir_entr
6232         do {
6233                 struct proc_dir_entry *next;
6234                 pde_get(de);
6235 +
6236 +               if (!vx_hide_check(0, de->vx_flags))
6237 +                       goto skip;
6238                 spin_unlock(&proc_subdir_lock);
6239                 if (!dir_emit(ctx, de->name, de->namelen,
6240                             de->low_ino, de->mode >> 12)) {
6241 @@ -249,6 +257,7 @@ int proc_readdir_de(struct proc_dir_entr
6242                         return 0;
6243                 }
6244                 spin_lock(&proc_subdir_lock);
6245 +       skip:
6246                 ctx->pos++;
6247                 next = de->next;
6248                 pde_put(de);
6249 @@ -355,6 +364,7 @@ static struct proc_dir_entry *__proc_cre
6250         ent->namelen = len;
6251         ent->mode = mode;
6252         ent->nlink = nlink;
6253 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6254         atomic_set(&ent->count, 1);
6255         spin_lock_init(&ent->pde_unload_lock);
6256         INIT_LIST_HEAD(&ent->pde_openers);
6257 @@ -378,7 +388,8 @@ struct proc_dir_entry *proc_symlink(cons
6258                                 kfree(ent->data);
6259                                 kfree(ent);
6260                                 ent = NULL;
6261 -                       }
6262 +                       } else
6263 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6264                 } else {
6265                         kfree(ent);
6266                         ent = NULL;
6267 diff -NurpP --minimal linux-3.13.10/fs/proc/inode.c linux-3.13.10-vs2.3.6.11/fs/proc/inode.c
6268 --- linux-3.13.10/fs/proc/inode.c       2014-01-22 20:39:07.000000000 +0000
6269 +++ linux-3.13.10-vs2.3.6.11/fs/proc/inode.c    2014-01-31 20:38:03.000000000 +0000
6270 @@ -415,6 +415,8 @@ struct inode *proc_get_inode(struct supe
6271                         inode->i_uid = de->uid;
6272                         inode->i_gid = de->gid;
6273                 }
6274 +               if (de->vx_flags)
6275 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6276                 if (de->size)
6277                         inode->i_size = de->size;
6278                 if (de->nlink)
6279 diff -NurpP --minimal linux-3.13.10/fs/proc/internal.h linux-3.13.10-vs2.3.6.11/fs/proc/internal.h
6280 --- linux-3.13.10/fs/proc/internal.h    2013-11-25 15:45:04.000000000 +0000
6281 +++ linux-3.13.10-vs2.3.6.11/fs/proc/internal.h 2014-01-31 20:38:03.000000000 +0000
6282 @@ -14,6 +14,7 @@
6283  #include <linux/spinlock.h>
6284  #include <linux/atomic.h>
6285  #include <linux/binfmts.h>
6286 +#include <linux/vs_pid.h>
6287  
6288  struct ctl_table_header;
6289  struct mempolicy;
6290 @@ -35,6 +36,7 @@ struct proc_dir_entry {
6291         nlink_t nlink;
6292         kuid_t uid;
6293         kgid_t gid;
6294 +       int vx_flags;
6295         loff_t size;
6296         const struct inode_operations *proc_iops;
6297         const struct file_operations *proc_fops;
6298 @@ -50,16 +52,23 @@ struct proc_dir_entry {
6299         char name[];
6300  };
6301  
6302 +struct vx_info;
6303 +struct nx_info;
6304 +
6305  union proc_op {
6306         int (*proc_get_link)(struct dentry *, struct path *);
6307         int (*proc_read)(struct task_struct *task, char *page);
6308         int (*proc_show)(struct seq_file *m,
6309                 struct pid_namespace *ns, struct pid *pid,
6310                 struct task_struct *task);
6311 +       int (*proc_vs_read)(char *page);
6312 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
6313 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
6314  };
6315  
6316  struct proc_inode {
6317         struct pid *pid;
6318 +       int vx_flags;
6319         int fd;
6320         union proc_op op;
6321         struct proc_dir_entry *pde;
6322 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
6323         return PROC_I(inode)->pid;
6324  }
6325  
6326 -static inline struct task_struct *get_proc_task(struct inode *inode)
6327 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6328  {
6329         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6330  }
6331  
6332 +static inline struct task_struct *get_proc_task(struct inode *inode)
6333 +{
6334 +       return vx_get_proc_task(inode, proc_pid(inode));
6335 +}
6336 +
6337  static inline int task_dumpable(struct task_struct *task)
6338  {
6339         int dumpable = 0;
6340 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6341                            struct pid *, struct task_struct *);
6342  extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6343                           struct pid *, struct task_struct *);
6344 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6345 +                           struct pid *pid, struct task_struct *task);
6346  
6347  /*
6348   * base.c
6349 diff -NurpP --minimal linux-3.13.10/fs/proc/loadavg.c linux-3.13.10-vs2.3.6.11/fs/proc/loadavg.c
6350 --- linux-3.13.10/fs/proc/loadavg.c     2012-12-11 03:30:57.000000000 +0000
6351 +++ linux-3.13.10-vs2.3.6.11/fs/proc/loadavg.c  2014-01-31 20:38:03.000000000 +0000
6352 @@ -12,15 +12,27 @@
6353  
6354  static int loadavg_proc_show(struct seq_file *m, void *v)
6355  {
6356 +       unsigned long running;
6357 +       unsigned int threads;
6358         unsigned long avnrun[3];
6359  
6360         get_avenrun(avnrun, FIXED_1/200, 0);
6361  
6362 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6363 +               struct vx_info *vxi = current_vx_info();
6364 +
6365 +               running = atomic_read(&vxi->cvirt.nr_running);
6366 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6367 +       } else {
6368 +               running = nr_running();
6369 +               threads = nr_threads;
6370 +       }
6371 +
6372         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6373                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6374                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6375                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6376 -               nr_running(), nr_threads,
6377 +               running, threads,
6378                 task_active_pid_ns(current)->last_pid);
6379         return 0;
6380  }
6381 diff -NurpP --minimal linux-3.13.10/fs/proc/meminfo.c linux-3.13.10-vs2.3.6.11/fs/proc/meminfo.c
6382 --- linux-3.13.10/fs/proc/meminfo.c     2014-01-22 20:39:07.000000000 +0000
6383 +++ linux-3.13.10-vs2.3.6.11/fs/proc/meminfo.c  2014-01-31 20:38:03.000000000 +0000
6384 @@ -37,7 +37,8 @@ static int meminfo_proc_show(struct seq_
6385         si_swapinfo(&i);
6386         committed = percpu_counter_read_positive(&vm_committed_as);
6387  
6388 -       cached = global_page_state(NR_FILE_PAGES) -
6389 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6390 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6391                         total_swapcache_pages() - i.bufferram;
6392         if (cached < 0)
6393                 cached = 0;
6394 diff -NurpP --minimal linux-3.13.10/fs/proc/root.c linux-3.13.10-vs2.3.6.11/fs/proc/root.c
6395 --- linux-3.13.10/fs/proc/root.c        2013-11-25 15:47:00.000000000 +0000
6396 +++ linux-3.13.10-vs2.3.6.11/fs/proc/root.c     2014-02-01 00:02:11.000000000 +0000
6397 @@ -20,9 +20,14 @@
6398  #include <linux/mount.h>
6399  #include <linux/pid_namespace.h>
6400  #include <linux/parser.h>
6401 +#include <linux/vserver/inode.h>
6402  
6403  #include "internal.h"
6404  
6405 +struct proc_dir_entry *proc_virtual;
6406 +
6407 +extern void proc_vx_init(void);
6408 +
6409  static int proc_test_super(struct super_block *sb, void *data)
6410  {
6411         return sb->s_fs_info == data;
6412 @@ -114,7 +119,8 @@ static struct dentry *proc_mount(struct
6413                         return ERR_PTR(-EPERM);
6414  
6415                 /* Does the mounter have privilege over the pid namespace? */
6416 -               if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
6417 +               if (!vx_ns_capable(ns->user_ns,
6418 +                       CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6419                         return ERR_PTR(-EPERM);
6420         }
6421  
6422 @@ -188,6 +194,7 @@ void __init proc_root_init(void)
6423  #endif
6424         proc_mkdir("bus", NULL);
6425         proc_sys_init();
6426 +       proc_vx_init();
6427  }
6428  
6429  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6430 @@ -249,6 +256,7 @@ struct proc_dir_entry proc_root = {
6431         .proc_iops      = &proc_root_inode_operations, 
6432         .proc_fops      = &proc_root_operations,
6433         .parent         = &proc_root,
6434 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6435         .name           = "/proc",
6436  };
6437  
6438 diff -NurpP --minimal linux-3.13.10/fs/proc/self.c linux-3.13.10-vs2.3.6.11/fs/proc/self.c
6439 --- linux-3.13.10/fs/proc/self.c        2014-01-22 20:39:07.000000000 +0000
6440 +++ linux-3.13.10-vs2.3.6.11/fs/proc/self.c     2014-01-31 20:38:03.000000000 +0000
6441 @@ -2,6 +2,7 @@
6442  #include <linux/namei.h>
6443  #include <linux/slab.h>
6444  #include <linux/pid_namespace.h>
6445 +#include <linux/vserver/inode.h>
6446  #include "internal.h"
6447  
6448  /*
6449 @@ -54,6 +55,8 @@ int proc_setup_self(struct super_block *
6450         self = d_alloc_name(s->s_root, "self");
6451         if (self) {
6452                 struct inode *inode = new_inode_pseudo(s);
6453 +
6454 +               // self->vx_flags = IATTR_PROC_SYMLINK;
6455                 if (inode) {
6456                         inode->i_ino = self_inum;
6457                         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6458 diff -NurpP --minimal linux-3.13.10/fs/proc/stat.c linux-3.13.10-vs2.3.6.11/fs/proc/stat.c
6459 --- linux-3.13.10/fs/proc/stat.c        2013-07-14 17:01:29.000000000 +0000
6460 +++ linux-3.13.10-vs2.3.6.11/fs/proc/stat.c     2014-01-31 20:38:03.000000000 +0000
6461 @@ -9,8 +9,10 @@
6462  #include <linux/slab.h>
6463  #include <linux/time.h>
6464  #include <linux/irqnr.h>
6465 +#include <linux/vserver/cvirt.h>
6466  #include <asm/cputime.h>
6467  #include <linux/tick.h>
6468 +#include <linux/cpuset.h>
6469  
6470  #ifndef arch_irq_stat_cpu
6471  #define arch_irq_stat_cpu(cpu) 0
6472 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6473         u64 sum_softirq = 0;
6474         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6475         struct timespec boottime;
6476 +       cpumask_var_t cpus_allowed;
6477 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6478  
6479         user = nice = system = idle = iowait =
6480                 irq = softirq = steal = 0;
6481         guest = guest_nice = 0;
6482         getboottime(&boottime);
6483 +
6484 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6485 +               vx_vsi_boottime(&boottime);
6486 +
6487 +       if (virt_cpu)
6488 +               cpuset_cpus_allowed(current, cpus_allowed);
6489 +
6490         jif = boottime.tv_sec;
6491  
6492         for_each_possible_cpu(i) {
6493 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6494 +                       continue;
6495 +
6496                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6497                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6498                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6499 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6500         seq_putc(p, '\n');
6501  
6502         for_each_online_cpu(i) {
6503 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6504 +                       continue;
6505 +
6506                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6507                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6508                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6509 diff -NurpP --minimal linux-3.13.10/fs/proc/uptime.c linux-3.13.10-vs2.3.6.11/fs/proc/uptime.c
6510 --- linux-3.13.10/fs/proc/uptime.c      2013-11-25 15:45:04.000000000 +0000
6511 +++ linux-3.13.10-vs2.3.6.11/fs/proc/uptime.c   2014-01-31 20:38:03.000000000 +0000
6512 @@ -5,6 +5,7 @@
6513  #include <linux/seq_file.h>
6514  #include <linux/time.h>
6515  #include <linux/kernel_stat.h>
6516 +#include <linux/vserver/cvirt.h>
6517  #include <asm/cputime.h>
6518  
6519  static int uptime_proc_show(struct seq_file *m, void *v)
6520 @@ -24,6 +25,10 @@ static int uptime_proc_show(struct seq_f
6521         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6522         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6523         idle.tv_nsec = rem;
6524 +
6525 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6526 +               vx_vsi_uptime(&uptime, &idle);
6527 +
6528         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6529                         (unsigned long) uptime.tv_sec,
6530                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6531 diff -NurpP --minimal linux-3.13.10/fs/proc_namespace.c linux-3.13.10-vs2.3.6.11/fs/proc_namespace.c
6532 --- linux-3.13.10/fs/proc_namespace.c   2014-01-22 20:39:07.000000000 +0000
6533 +++ linux-3.13.10-vs2.3.6.11/fs/proc_namespace.c        2014-02-25 12:43:16.000000000 +0000
6534 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6535                 { MS_SYNCHRONOUS, ",sync" },
6536                 { MS_DIRSYNC, ",dirsync" },
6537                 { MS_MANDLOCK, ",mand" },
6538 +               { MS_TAGGED, ",tag" },
6539 +               { MS_NOTAGCHECK, ",notagcheck" },
6540                 { 0, NULL }
6541         };
6542         const struct proc_fs_info *fs_infop;
6543 @@ -80,6 +82,38 @@ static inline void mangle(struct seq_fil
6544         seq_escape(m, s, " \t\n\\");
6545  }
6546  
6547 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6548 +
6549 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6550 +{
6551 +       struct path root;
6552 +       struct dentry *point;
6553 +       struct mount *mnt = real_mount(vfsmnt);
6554 +       struct mount *root_mnt;
6555 +       int ret;
6556 +
6557 +       if (mnt == mnt->mnt_ns->root)
6558 +               return 1;
6559 +
6560 +       rcu_read_lock();
6561 +       root = current->fs->root;
6562 +       root_mnt = real_mount(root.mnt);
6563 +       point = root.dentry;
6564 +
6565 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6566 +               point = mnt->mnt_mountpoint;
6567 +               mnt = mnt->mnt_parent;
6568 +       }
6569 +       rcu_read_unlock();
6570 +
6571 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6572 +       return ret;
6573 +}
6574 +
6575 +#else
6576 +#define        mnt_is_reachable(v)     (1)
6577 +#endif
6578 +
6579  static void show_type(struct seq_file *m, struct super_block *sb)
6580  {
6581         mangle(m, sb->s_type->name);
6582 @@ -96,6 +130,17 @@ static int show_vfsmnt(struct seq_file *
6583         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6584         struct super_block *sb = mnt_path.dentry->d_sb;
6585  
6586 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6587 +               return SEQ_SKIP;
6588 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6589 +               return SEQ_SKIP;
6590 +
6591 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6592 +               mnt == current->fs->root.mnt) {
6593 +               seq_puts(m, "/dev/root / ");
6594 +               goto type;
6595 +       }
6596 +
6597         if (sb->s_op->show_devname) {
6598                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6599                 if (err)
6600 @@ -106,6 +151,7 @@ static int show_vfsmnt(struct seq_file *
6601         seq_putc(m, ' ');
6602         seq_path(m, &mnt_path, " \t\n\\");
6603         seq_putc(m, ' ');
6604 +type:
6605         show_type(m, sb);
6606         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6607         err = show_sb_opts(m, sb);
6608 @@ -128,6 +174,11 @@ static int show_mountinfo(struct seq_fil
6609         struct path root = p->root;
6610         int err = 0;
6611  
6612 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6613 +               return SEQ_SKIP;
6614 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6615 +               return SEQ_SKIP;
6616 +
6617         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6618                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6619         if (sb->s_op->show_path)
6620 @@ -187,6 +238,17 @@ static int show_vfsstat(struct seq_file
6621         struct super_block *sb = mnt_path.dentry->d_sb;
6622         int err = 0;
6623  
6624 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6625 +               return SEQ_SKIP;
6626 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6627 +               return SEQ_SKIP;
6628 +
6629 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6630 +               mnt == current->fs->root.mnt) {
6631 +               seq_puts(m, "device /dev/root mounted on / ");
6632 +               goto type;
6633 +       }
6634 +
6635         /* device */
6636         if (sb->s_op->show_devname) {
6637                 seq_puts(m, "device ");
6638 @@ -203,7 +265,7 @@ static int show_vfsstat(struct seq_file
6639         seq_puts(m, " mounted on ");
6640         seq_path(m, &mnt_path, " \t\n\\");
6641         seq_putc(m, ' ');
6642 -
6643 +type:
6644         /* file system type */
6645         seq_puts(m, "with fstype ");
6646         show_type(m, sb);
6647 diff -NurpP --minimal linux-3.13.10/fs/quota/dquot.c linux-3.13.10-vs2.3.6.11/fs/quota/dquot.c
6648 --- linux-3.13.10/fs/quota/dquot.c      2014-04-17 01:12:34.000000000 +0000
6649 +++ linux-3.13.10-vs2.3.6.11/fs/quota/dquot.c   2014-03-12 15:51:07.000000000 +0000
6650 @@ -1602,6 +1602,9 @@ int __dquot_alloc_space(struct inode *in
6651         struct dquot **dquots = inode->i_dquot;
6652         int reserve = flags & DQUOT_SPACE_RESERVE;
6653  
6654 +       if ((ret = dl_alloc_space(inode, number)))
6655 +               return ret;
6656 +
6657         /*
6658          * First test before acquiring mutex - solves deadlocks when we
6659          * re-enter the quota code and are already holding the mutex
6660 @@ -1657,6 +1660,9 @@ int dquot_alloc_inode(const struct inode
6661         struct dquot_warn warn[MAXQUOTAS];
6662         struct dquot * const *dquots = inode->i_dquot;
6663  
6664 +       if ((ret = dl_alloc_inode(inode)))
6665 +               return ret;
6666 +
6667         /* First test before acquiring mutex - solves deadlocks when we
6668           * re-enter the quota code and are already holding the mutex */
6669         if (!dquot_active(inode))
6670 @@ -1757,6 +1763,8 @@ void __dquot_free_space(struct inode *in
6671         struct dquot **dquots = inode->i_dquot;
6672         int reserve = flags & DQUOT_SPACE_RESERVE;
6673  
6674 +       dl_free_space(inode, number);
6675 +
6676         /* First test before acquiring mutex - solves deadlocks when we
6677           * re-enter the quota code and are already holding the mutex */
6678         if (!dquot_active(inode)) {
6679 @@ -1801,6 +1809,8 @@ void dquot_free_inode(const struct inode
6680         struct dquot_warn warn[MAXQUOTAS];
6681         struct dquot * const *dquots = inode->i_dquot;
6682  
6683 +       dl_free_inode(inode);
6684 +
6685         /* First test before acquiring mutex - solves deadlocks when we
6686           * re-enter the quota code and are already holding the mutex */
6687         if (!dquot_active(inode))
6688 diff -NurpP --minimal linux-3.13.10/fs/quota/quota.c linux-3.13.10-vs2.3.6.11/fs/quota/quota.c
6689 --- linux-3.13.10/fs/quota/quota.c      2014-01-22 20:39:07.000000000 +0000
6690 +++ linux-3.13.10-vs2.3.6.11/fs/quota/quota.c   2014-01-31 20:38:03.000000000 +0000
6691 @@ -8,6 +8,7 @@
6692  #include <linux/fs.h>
6693  #include <linux/namei.h>
6694  #include <linux/slab.h>
6695 +#include <linux/vs_context.h>
6696  #include <asm/current.h>
6697  #include <linux/uaccess.h>
6698  #include <linux/kernel.h>
6699 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6700                         break;
6701                 /*FALLTHROUGH*/
6702         default:
6703 -               if (!capable(CAP_SYS_ADMIN))
6704 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6705                         return -EPERM;
6706         }
6707  
6708 @@ -338,6 +339,46 @@ static int do_quotactl(struct super_bloc
6709  
6710  #ifdef CONFIG_BLOCK
6711  
6712 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6713 +
6714 +#include <linux/vroot.h>
6715 +#include <linux/major.h>
6716 +#include <linux/module.h>
6717 +#include <linux/kallsyms.h>
6718 +#include <linux/vserver/debug.h>
6719 +
6720 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6721 +
6722 +static DEFINE_SPINLOCK(vroot_grb_lock);
6723 +
6724 +int register_vroot_grb(vroot_grb_func *func) {
6725 +       int ret = -EBUSY;
6726 +
6727 +       spin_lock(&vroot_grb_lock);
6728 +       if (!vroot_get_real_bdev) {
6729 +               vroot_get_real_bdev = func;
6730 +               ret = 0;
6731 +       }
6732 +       spin_unlock(&vroot_grb_lock);
6733 +       return ret;
6734 +}
6735 +EXPORT_SYMBOL(register_vroot_grb);
6736 +
6737 +int unregister_vroot_grb(vroot_grb_func *func) {
6738 +       int ret = -EINVAL;
6739 +
6740 +       spin_lock(&vroot_grb_lock);
6741 +       if (vroot_get_real_bdev) {
6742 +               vroot_get_real_bdev = NULL;
6743 +               ret = 0;
6744 +       }
6745 +       spin_unlock(&vroot_grb_lock);
6746 +       return ret;
6747 +}
6748 +EXPORT_SYMBOL(unregister_vroot_grb);
6749 +
6750 +#endif
6751 +
6752  /* Return 1 if 'cmd' will block on frozen filesystem */
6753  static int quotactl_cmd_write(int cmd)
6754  {
6755 @@ -373,6 +414,22 @@ static struct super_block *quotactl_bloc
6756         putname(tmp);
6757         if (IS_ERR(bdev))
6758                 return ERR_CAST(bdev);
6759 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6760 +       if (bdev && bdev->bd_inode &&
6761 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6762 +               struct block_device *bdnew = (void *)-EINVAL;
6763 +
6764 +               if (vroot_get_real_bdev)
6765 +                       bdnew = vroot_get_real_bdev(bdev);
6766 +               else
6767 +                       vxdprintk(VXD_CBIT(misc, 0),
6768 +                                       "vroot_get_real_bdev not set");
6769 +               bdput(bdev);
6770 +               if (IS_ERR(bdnew))
6771 +                       return ERR_PTR(PTR_ERR(bdnew));
6772 +               bdev = bdnew;
6773 +       }
6774 +#endif
6775         if (quotactl_cmd_write(cmd))
6776                 sb = get_super_thawed(bdev);
6777         else
6778 diff -NurpP --minimal linux-3.13.10/fs/stat.c linux-3.13.10-vs2.3.6.11/fs/stat.c
6779 --- linux-3.13.10/fs/stat.c     2014-01-22 20:39:07.000000000 +0000
6780 +++ linux-3.13.10-vs2.3.6.11/fs/stat.c  2014-01-31 20:38:03.000000000 +0000
6781 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6782         stat->nlink = inode->i_nlink;
6783         stat->uid = inode->i_uid;
6784         stat->gid = inode->i_gid;
6785 +       stat->tag = inode->i_tag;
6786         stat->rdev = inode->i_rdev;
6787         stat->size = i_size_read(inode);
6788         stat->atime = inode->i_atime;
6789 diff -NurpP --minimal linux-3.13.10/fs/statfs.c linux-3.13.10-vs2.3.6.11/fs/statfs.c
6790 --- linux-3.13.10/fs/statfs.c   2013-11-25 15:47:00.000000000 +0000
6791 +++ linux-3.13.10-vs2.3.6.11/fs/statfs.c        2014-01-31 20:38:03.000000000 +0000
6792 @@ -7,6 +7,8 @@
6793  #include <linux/statfs.h>
6794  #include <linux/security.h>
6795  #include <linux/uaccess.h>
6796 +#include <linux/vs_base.h>
6797 +#include <linux/vs_dlimit.h>
6798  #include "internal.h"
6799  
6800  static int flags_by_mnt(int mnt_flags)
6801 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6802         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6803         if (retval == 0 && buf->f_frsize == 0)
6804                 buf->f_frsize = buf->f_bsize;
6805 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6806 +               vx_vsi_statfs(dentry->d_sb, buf);
6807         return retval;
6808  }
6809  
6810 diff -NurpP --minimal linux-3.13.10/fs/super.c linux-3.13.10-vs2.3.6.11/fs/super.c
6811 --- linux-3.13.10/fs/super.c    2014-01-22 20:39:07.000000000 +0000
6812 +++ linux-3.13.10-vs2.3.6.11/fs/super.c 2014-01-31 20:38:03.000000000 +0000
6813 @@ -34,6 +34,8 @@
6814  #include <linux/cleancache.h>
6815  #include <linux/fsnotify.h>
6816  #include <linux/lockdep.h>
6817 +#include <linux/magic.h>
6818 +#include <linux/vs_context.h>
6819  #include "internal.h"
6820  
6821  
6822 @@ -1098,6 +1100,13 @@ mount_fs(struct file_system_type *type,
6823         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6824         sb->s_flags |= MS_BORN;
6825  
6826 +       error = -EPERM;
6827 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6828 +               !sb->s_bdev &&
6829 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6830 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6831 +               goto out_sb;
6832 +
6833         error = security_sb_kern_mount(sb, flags, secdata);
6834         if (error)
6835                 goto out_sb;
6836 diff -NurpP --minimal linux-3.13.10/fs/kernfs/mount.c linux-3.13.10-vs2.3.6.11/fs/kernfs/mount.c
6837 --- linux-3.13.10/fs/kernfs/mount.c     2013-11-25 15:47:00.000000000 +0000
6838 +++ linux-3.13.10-vs2.3.6.11/fs/kernfs/mount.c  2014-01-31 20:38:03.000000000 +0000
6839 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6840  
6841         sb->s_blocksize = PAGE_CACHE_SIZE;
6842         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6843 -       sb->s_magic = SYSFS_MAGIC;
6844 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6845         sb->s_op = &kernfs_sops;
6846         sb->s_time_gran = 1;
6847  
6848 diff -NurpP --minimal linux-3.13.10/fs/utimes.c linux-3.13.10-vs2.3.6.11/fs/utimes.c
6849 --- linux-3.13.10/fs/utimes.c   2014-01-22 20:39:07.000000000 +0000
6850 +++ linux-3.13.10-vs2.3.6.11/fs/utimes.c        2014-01-31 23:49:14.000000000 +0000
6851 @@ -8,6 +8,8 @@
6852  #include <linux/stat.h>
6853  #include <linux/utime.h>
6854  #include <linux/syscalls.h>
6855 +#include <linux/mount.h>
6856 +#include <linux/vs_cowbl.h>
6857  #include <asm/uaccess.h>
6858  #include <asm/unistd.h>
6859  
6860 @@ -52,13 +54,19 @@ static int utimes_common(struct path *pa
6861  {
6862         int error;
6863         struct iattr newattrs;
6864 -       struct inode *inode = path->dentry->d_inode;
6865         struct inode *delegated_inode = NULL;
6866 +       struct inode *inode;
6867 +
6868 +       error = cow_check_and_break(path);
6869 +       if (error)
6870 +               goto out;
6871  
6872         error = mnt_want_write(path->mnt);
6873         if (error)
6874                 goto out;
6875  
6876 +       inode = path->dentry->d_inode;
6877 +
6878         if (times && times[0].tv_nsec == UTIME_NOW &&
6879                      times[1].tv_nsec == UTIME_NOW)
6880                 times = NULL;
6881 diff -NurpP --minimal linux-3.13.10/fs/xattr.c linux-3.13.10-vs2.3.6.11/fs/xattr.c
6882 --- linux-3.13.10/fs/xattr.c    2013-02-19 13:58:49.000000000 +0000
6883 +++ linux-3.13.10-vs2.3.6.11/fs/xattr.c 2014-01-31 20:38:03.000000000 +0000
6884 @@ -21,6 +21,7 @@
6885  #include <linux/audit.h>
6886  #include <linux/vmalloc.h>
6887  #include <linux/posix_acl_xattr.h>
6888 +#include <linux/mount.h>
6889  
6890  #include <asm/uaccess.h>
6891  
6892 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6893          * The trusted.* namespace can only be accessed by privileged users.
6894          */
6895         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6896 -               if (!capable(CAP_SYS_ADMIN))
6897 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6898                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6899                 return 0;
6900         }
6901 diff -NurpP --minimal linux-3.13.10/include/linux/cred.h linux-3.13.10-vs2.3.6.11/include/linux/cred.h
6902 --- linux-3.13.10/include/linux/cred.h  2013-02-19 13:58:50.000000000 +0000
6903 +++ linux-3.13.10-vs2.3.6.11/include/linux/cred.h       2014-01-31 20:38:03.000000000 +0000
6904 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
6905  extern int copy_creds(struct task_struct *, unsigned long);
6906  extern const struct cred *get_task_cred(struct task_struct *);
6907  extern struct cred *cred_alloc_blank(void);
6908 +extern struct cred *__prepare_creds(const struct cred *);
6909  extern struct cred *prepare_creds(void);
6910  extern struct cred *prepare_exec_creds(void);
6911  extern int commit_creds(struct cred *);
6912 @@ -196,6 +197,31 @@ static inline void validate_process_cred
6913  }
6914  #endif
6915  
6916 +static inline void set_cred_subscribers(struct cred *cred, int n)
6917 +{
6918 +#ifdef CONFIG_DEBUG_CREDENTIALS
6919 +       atomic_set(&cred->subscribers, n);
6920 +#endif
6921 +}
6922 +
6923 +static inline int read_cred_subscribers(const struct cred *cred)
6924 +{
6925 +#ifdef CONFIG_DEBUG_CREDENTIALS
6926 +       return atomic_read(&cred->subscribers);
6927 +#else
6928 +       return 0;
6929 +#endif
6930 +}
6931 +
6932 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
6933 +{
6934 +#ifdef CONFIG_DEBUG_CREDENTIALS
6935 +       struct cred *cred = (struct cred *) _cred;
6936 +
6937 +       atomic_add(n, &cred->subscribers);
6938 +#endif
6939 +}
6940 +
6941  /**
6942   * get_new_cred - Get a reference on a new set of credentials
6943   * @cred: The new credentials to reference
6944 diff -NurpP --minimal linux-3.13.10/include/linux/devpts_fs.h linux-3.13.10-vs2.3.6.11/include/linux/devpts_fs.h
6945 --- linux-3.13.10/include/linux/devpts_fs.h     2013-02-19 13:58:50.000000000 +0000
6946 +++ linux-3.13.10-vs2.3.6.11/include/linux/devpts_fs.h  2014-01-31 20:38:03.000000000 +0000
6947 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
6948  
6949  #endif
6950  
6951 -
6952  #endif /* _LINUX_DEVPTS_FS_H */
6953 diff -NurpP --minimal linux-3.13.10/include/linux/fs.h linux-3.13.10-vs2.3.6.11/include/linux/fs.h
6954 --- linux-3.13.10/include/linux/fs.h    2014-01-22 20:39:10.000000000 +0000
6955 +++ linux-3.13.10-vs2.3.6.11/include/linux/fs.h 2014-01-31 23:33:22.000000000 +0000
6956 @@ -213,6 +213,7 @@ typedef void (dio_iodone_t)(struct kiocb
6957  #define ATTR_KILL_PRIV (1 << 14)
6958  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
6959  #define ATTR_TIMES_SET (1 << 16)
6960 +#define ATTR_TAG       (1 << 17)
6961  
6962  /*
6963   * This is the Inode Attributes structure, used for notify_change().  It
6964 @@ -228,6 +229,7 @@ struct iattr {
6965         umode_t         ia_mode;
6966         kuid_t          ia_uid;
6967         kgid_t          ia_gid;
6968 +       ktag_t          ia_tag;
6969         loff_t          ia_size;
6970         struct timespec ia_atime;
6971         struct timespec ia_mtime;
6972 @@ -526,7 +528,9 @@ struct inode {
6973         unsigned short          i_opflags;
6974         kuid_t                  i_uid;
6975         kgid_t                  i_gid;
6976 -       unsigned int            i_flags;
6977 +       ktag_t                  i_tag;
6978 +       unsigned short          i_flags;
6979 +       unsigned short          i_vflags;
6980  
6981  #ifdef CONFIG_FS_POSIX_ACL
6982         struct posix_acl        *i_acl;
6983 @@ -555,6 +559,7 @@ struct inode {
6984                 unsigned int __i_nlink;
6985         };
6986         dev_t                   i_rdev;
6987 +       dev_t                   i_mdev;
6988         loff_t                  i_size;
6989         struct timespec         i_atime;
6990         struct timespec         i_mtime;
6991 @@ -713,6 +718,11 @@ static inline gid_t i_gid_read(const str
6992         return from_kgid(&init_user_ns, inode->i_gid);
6993  }
6994  
6995 +static inline vtag_t i_tag_read(const struct inode *inode)
6996 +{
6997 +       return from_ktag(&init_user_ns, inode->i_tag);
6998 +}
6999 +
7000  static inline void i_uid_write(struct inode *inode, uid_t uid)
7001  {
7002         inode->i_uid = make_kuid(&init_user_ns, uid);
7003 @@ -723,14 +733,19 @@ static inline void i_gid_write(struct in
7004         inode->i_gid = make_kgid(&init_user_ns, gid);
7005  }
7006  
7007 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
7008 +{
7009 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7010 +}
7011 +
7012  static inline unsigned iminor(const struct inode *inode)
7013  {
7014 -       return MINOR(inode->i_rdev);
7015 +       return MINOR(inode->i_mdev);
7016  }
7017  
7018  static inline unsigned imajor(const struct inode *inode)
7019  {
7020 -       return MAJOR(inode->i_rdev);
7021 +       return MAJOR(inode->i_mdev);
7022  }
7023  
7024  extern struct block_device *I_BDEV(struct inode *inode);
7025 @@ -790,6 +805,7 @@ struct file {
7026         loff_t                  f_pos;
7027         struct fown_struct      f_owner;
7028         const struct cred       *f_cred;
7029 +       vxid_t                  f_xid;
7030         struct file_ra_state    f_ra;
7031  
7032         u64                     f_version;
7033 @@ -962,6 +978,7 @@ struct file_lock {
7034         struct file *fl_file;
7035         loff_t fl_start;
7036         loff_t fl_end;
7037 +       vxid_t fl_xid;
7038  
7039         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7040         /* for lease breaks: */
7041 @@ -1573,6 +1590,7 @@ struct inode_operations {
7042         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7043         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7044         int (*removexattr) (struct dentry *, const char *);
7045 +       int (*sync_flags) (struct inode *, int, int);
7046         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7047                       u64 len);
7048         int (*update_time)(struct inode *, struct timespec *, int);
7049 @@ -1586,6 +1604,7 @@ ssize_t rw_copy_check_uvector(int type,
7050                               unsigned long nr_segs, unsigned long fast_segs,
7051                               struct iovec *fast_pointer,
7052                               struct iovec **ret_pointer);
7053 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7054  
7055  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7056  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7057 @@ -1639,6 +1658,14 @@ struct super_operations {
7058  #define S_IMA          1024    /* Inode has an associated IMA struct */
7059  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7060  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7061 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7062 +
7063 +/* Linux-VServer related Inode flags */
7064 +
7065 +#define V_VALID                1
7066 +#define V_XATTR                2
7067 +#define V_BARRIER      4       /* Barrier for chroot() */
7068 +#define V_COW          8       /* Copy on Write */
7069  
7070  /*
7071   * Note that nosuid etc flags are inode-specific: setting some file-system
7072 @@ -1663,10 +1690,13 @@ struct super_operations {
7073  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7074  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7075  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7076 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7077  
7078  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7079  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7080  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7081 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7082 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7083  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7084  
7085  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7086 @@ -1677,6 +1707,16 @@ struct super_operations {
7087  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7088  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7089  
7090 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7091 +
7092 +#ifdef CONFIG_VSERVER_COWBL
7093 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7094 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7095 +#else
7096 +#  define IS_COW(inode)                (0)
7097 +#  define IS_COW_LINK(inode)   (0)
7098 +#endif
7099 +
7100  /*
7101   * Inode state bits.  Protected by inode->i_lock
7102   *
7103 @@ -1920,6 +1960,9 @@ extern struct kobject *fs_kobj;
7104  extern int locks_mandatory_locked(struct inode *);
7105  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7106  
7107 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7108 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7109 +
7110  /*
7111   * Candidates for mandatory locking have the setgid bit set
7112   * but no group execute bit -  an otherwise meaningless combination.
7113 @@ -2605,6 +2648,7 @@ extern int dcache_dir_open(struct inode
7114  extern int dcache_dir_close(struct inode *, struct file *);
7115  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7116  extern int dcache_readdir(struct file *, struct dir_context *);
7117 +extern int dcache_readdir_filter(struct file *, struct dir_context *, int (*)(struct dentry *));
7118  extern int simple_setattr(struct dentry *, struct iattr *);
7119  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7120  extern int simple_statfs(struct dentry *, struct kstatfs *);
7121 diff -NurpP --minimal linux-3.13.10/include/linux/init_task.h linux-3.13.10-vs2.3.6.11/include/linux/init_task.h
7122 --- linux-3.13.10/include/linux/init_task.h     2014-01-22 20:39:11.000000000 +0000
7123 +++ linux-3.13.10-vs2.3.6.11/include/linux/init_task.h  2014-01-31 20:38:03.000000000 +0000
7124 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7125         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7126         INIT_CPUSET_SEQ(tsk)                                            \
7127         INIT_VTIME(tsk)                                                 \
7128 +       .xid            = 0,                                            \
7129 +       .vx_info        = NULL,                                         \
7130 +       .nid            = 0,                                            \
7131 +       .nx_info        = NULL,                                         \
7132  }
7133  
7134  
7135 diff -NurpP --minimal linux-3.13.10/include/linux/ipc.h linux-3.13.10-vs2.3.6.11/include/linux/ipc.h
7136 --- linux-3.13.10/include/linux/ipc.h   2012-12-11 03:30:57.000000000 +0000
7137 +++ linux-3.13.10-vs2.3.6.11/include/linux/ipc.h        2014-01-31 20:38:03.000000000 +0000
7138 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7139         key_t           key;
7140         kuid_t          uid;
7141         kgid_t          gid;
7142 +       vxid_t          xid;
7143         kuid_t          cuid;
7144         kgid_t          cgid;
7145         umode_t         mode; 
7146 diff -NurpP --minimal linux-3.13.10/include/linux/memcontrol.h linux-3.13.10-vs2.3.6.11/include/linux/memcontrol.h
7147 --- linux-3.13.10/include/linux/memcontrol.h    2013-11-25 15:47:01.000000000 +0000
7148 +++ linux-3.13.10-vs2.3.6.11/include/linux/memcontrol.h 2014-01-31 20:38:03.000000000 +0000
7149 @@ -99,6 +99,13 @@ extern struct mem_cgroup *try_get_mem_cg
7150  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7151  extern struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css);
7152  
7153 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7154 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7155 +
7156 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7157 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7158 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7159 +
7160  static inline
7161  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7162  {
7163 diff -NurpP --minimal linux-3.13.10/include/linux/mm_types.h linux-3.13.10-vs2.3.6.11/include/linux/mm_types.h
7164 --- linux-3.13.10/include/linux/mm_types.h      2014-01-22 20:39:11.000000000 +0000
7165 +++ linux-3.13.10-vs2.3.6.11/include/linux/mm_types.h   2014-01-31 20:38:03.000000000 +0000
7166 @@ -397,6 +397,7 @@ struct mm_struct {
7167  
7168         /* Architecture-specific MM context */
7169         mm_context_t context;
7170 +       struct vx_info *mm_vx_info;
7171  
7172         unsigned long flags; /* Must use atomic bitops to access the bits */
7173  
7174 diff -NurpP --minimal linux-3.13.10/include/linux/mount.h linux-3.13.10-vs2.3.6.11/include/linux/mount.h
7175 --- linux-3.13.10/include/linux/mount.h 2014-01-22 20:39:11.000000000 +0000
7176 +++ linux-3.13.10-vs2.3.6.11/include/linux/mount.h      2014-01-31 20:38:03.000000000 +0000
7177 @@ -52,6 +52,9 @@ struct mnt_namespace;
7178  #define MNT_DOOMED             0x1000000
7179  #define MNT_SYNC_UMOUNT                0x2000000
7180  
7181 +#define MNT_TAGID      0x10000
7182 +#define MNT_NOTAG      0x20000
7183 +
7184  struct vfsmount {
7185         struct dentry *mnt_root;        /* root of the mounted tree */
7186         struct super_block *mnt_sb;     /* pointer to superblock */
7187 diff -NurpP --minimal linux-3.13.10/include/linux/net.h linux-3.13.10-vs2.3.6.11/include/linux/net.h
7188 --- linux-3.13.10/include/linux/net.h   2014-01-22 20:39:11.000000000 +0000
7189 +++ linux-3.13.10-vs2.3.6.11/include/linux/net.h        2014-01-31 20:38:03.000000000 +0000
7190 @@ -39,6 +39,7 @@ struct net;
7191  #define SOCK_PASSCRED          3
7192  #define SOCK_PASSSEC           4
7193  #define SOCK_EXTERNALLY_ALLOCATED 5
7194 +#define SOCK_USER_SOCKET       6
7195  
7196  #ifndef ARCH_HAS_SOCKET_TYPES
7197  /**
7198 diff -NurpP --minimal linux-3.13.10/include/linux/netdevice.h linux-3.13.10-vs2.3.6.11/include/linux/netdevice.h
7199 --- linux-3.13.10/include/linux/netdevice.h     2014-04-17 01:12:37.000000000 +0000
7200 +++ linux-3.13.10-vs2.3.6.11/include/linux/netdevice.h  2014-03-12 15:51:07.000000000 +0000
7201 @@ -1839,6 +1839,7 @@ int init_dummy_netdev(struct net_device
7202  
7203  struct net_device *dev_get_by_index(struct net *net, int ifindex);
7204  struct net_device *__dev_get_by_index(struct net *net, int ifindex);
7205 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7206  struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
7207  int netdev_get_name(struct net *net, char *name, int ifindex);
7208  int dev_restart(struct net_device *dev);
7209 diff -NurpP --minimal linux-3.13.10/include/linux/nsproxy.h linux-3.13.10-vs2.3.6.11/include/linux/nsproxy.h
7210 --- linux-3.13.10/include/linux/nsproxy.h       2013-11-25 15:45:06.000000000 +0000
7211 +++ linux-3.13.10-vs2.3.6.11/include/linux/nsproxy.h    2014-01-31 20:38:03.000000000 +0000
7212 @@ -3,6 +3,7 @@
7213  
7214  #include <linux/spinlock.h>
7215  #include <linux/sched.h>
7216 +#include <linux/vserver/debug.h>
7217  
7218  struct mnt_namespace;
7219  struct uts_namespace;
7220 @@ -67,6 +68,7 @@ static inline struct nsproxy *task_nspro
7221  }
7222  
7223  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7224 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7225  void exit_task_namespaces(struct task_struct *tsk);
7226  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7227  void free_nsproxy(struct nsproxy *ns);
7228 @@ -74,16 +76,26 @@ int unshare_nsproxy_namespaces(unsigned
7229         struct cred *, struct fs_struct *);
7230  int __init nsproxy_cache_init(void);
7231  
7232 -static inline void put_nsproxy(struct nsproxy *ns)
7233 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
7234 +
7235 +static inline void __get_nsproxy(struct nsproxy *ns,
7236 +       const char *_file, int _line)
7237  {
7238 -       if (atomic_dec_and_test(&ns->count)) {
7239 -               free_nsproxy(ns);
7240 -       }
7241 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7242 +               ns, atomic_read(&ns->count), _file, _line);
7243 +       atomic_inc(&ns->count);
7244  }
7245  
7246 -static inline void get_nsproxy(struct nsproxy *ns)
7247 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
7248 +
7249 +static inline void __put_nsproxy(struct nsproxy *ns,
7250 +       const char *_file, int _line)
7251  {
7252 -       atomic_inc(&ns->count);
7253 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7254 +               ns, atomic_read(&ns->count), _file, _line);
7255 +       if (atomic_dec_and_test(&ns->count)) {
7256 +               free_nsproxy(ns);
7257 +       }
7258  }
7259  
7260  #endif
7261 diff -NurpP --minimal linux-3.13.10/include/linux/pid.h linux-3.13.10-vs2.3.6.11/include/linux/pid.h
7262 --- linux-3.13.10/include/linux/pid.h   2013-11-25 15:45:06.000000000 +0000
7263 +++ linux-3.13.10-vs2.3.6.11/include/linux/pid.h        2014-01-31 20:38:03.000000000 +0000
7264 @@ -8,7 +8,8 @@ enum pid_type
7265         PIDTYPE_PID,
7266         PIDTYPE_PGID,
7267         PIDTYPE_SID,
7268 -       PIDTYPE_MAX
7269 +       PIDTYPE_MAX,
7270 +       PIDTYPE_REALPID
7271  };
7272  
7273  /*
7274 @@ -170,6 +171,7 @@ static inline pid_t pid_nr(struct pid *p
7275  }
7276  
7277  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7278 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7279  pid_t pid_vnr(struct pid *pid);
7280  
7281  #define do_each_pid_task(pid, type, task)                              \
7282 diff -NurpP --minimal linux-3.13.10/include/linux/quotaops.h linux-3.13.10-vs2.3.6.11/include/linux/quotaops.h
7283 --- linux-3.13.10/include/linux/quotaops.h      2013-11-25 15:47:02.000000000 +0000
7284 +++ linux-3.13.10-vs2.3.6.11/include/linux/quotaops.h   2014-01-31 20:38:03.000000000 +0000
7285 @@ -8,6 +8,7 @@
7286  #define _LINUX_QUOTAOPS_
7287  
7288  #include <linux/fs.h>
7289 +#include <linux/vs_dlimit.h>
7290  
7291  #define DQUOT_SPACE_WARN       0x1
7292  #define DQUOT_SPACE_RESERVE    0x2
7293 @@ -207,11 +208,12 @@ static inline void dquot_drop(struct ino
7294  
7295  static inline int dquot_alloc_inode(const struct inode *inode)
7296  {
7297 -       return 0;
7298 +       return dl_alloc_inode(inode);
7299  }
7300  
7301  static inline void dquot_free_inode(const struct inode *inode)
7302  {
7303 +       dl_free_inode(inode);
7304  }
7305  
7306  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
7307 @@ -222,6 +224,10 @@ static inline int dquot_transfer(struct
7308  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
7309                 int flags)
7310  {
7311 +       int ret = 0;
7312 +
7313 +       if ((ret = dl_alloc_space(inode, number)))
7314 +               return ret;
7315         if (!(flags & DQUOT_SPACE_RESERVE))
7316                 inode_add_bytes(inode, number);
7317         return 0;
7318 @@ -232,6 +238,7 @@ static inline void __dquot_free_space(st
7319  {
7320         if (!(flags & DQUOT_SPACE_RESERVE))
7321                 inode_sub_bytes(inode, number);
7322 +       dl_free_space(inode, number);
7323  }
7324  
7325  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
7326 diff -NurpP --minimal linux-3.13.10/include/linux/sched.h linux-3.13.10-vs2.3.6.11/include/linux/sched.h
7327 --- linux-3.13.10/include/linux/sched.h 2014-01-22 20:39:11.000000000 +0000
7328 +++ linux-3.13.10-vs2.3.6.11/include/linux/sched.h      2014-01-31 20:38:03.000000000 +0000
7329 @@ -1237,6 +1237,14 @@ struct task_struct {
7330  #endif
7331         struct seccomp seccomp;
7332  
7333 +/* vserver context data */
7334 +       struct vx_info *vx_info;
7335 +       struct nx_info *nx_info;
7336 +
7337 +       vxid_t xid;
7338 +       vnid_t nid;
7339 +       vtag_t tag;
7340 +
7341  /* Thread group tracking */
7342         u32 parent_exec_id;
7343         u32 self_exec_id;
7344 @@ -1531,6 +1539,11 @@ struct pid_namespace;
7345  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
7346                         struct pid_namespace *ns);
7347  
7348 +#include <linux/vserver/base.h>
7349 +#include <linux/vserver/context.h>
7350 +#include <linux/vserver/debug.h>
7351 +#include <linux/vserver/pid.h>
7352 +
7353  static inline pid_t task_pid_nr(struct task_struct *tsk)
7354  {
7355         return tsk->pid;
7356 @@ -1544,7 +1557,8 @@ static inline pid_t task_pid_nr_ns(struc
7357  
7358  static inline pid_t task_pid_vnr(struct task_struct *tsk)
7359  {
7360 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7361 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7362 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
7363  }
7364  
7365  
7366 @@ -1557,7 +1571,7 @@ pid_t task_tgid_nr_ns(struct task_struct
7367  
7368  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
7369  {
7370 -       return pid_vnr(task_tgid(tsk));
7371 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
7372  }
7373  
7374  
7375 diff -NurpP --minimal linux-3.13.10/include/linux/shmem_fs.h linux-3.13.10-vs2.3.6.11/include/linux/shmem_fs.h
7376 --- linux-3.13.10/include/linux/shmem_fs.h      2014-01-22 20:39:11.000000000 +0000
7377 +++ linux-3.13.10-vs2.3.6.11/include/linux/shmem_fs.h   2014-01-31 20:38:03.000000000 +0000
7378 @@ -9,6 +9,9 @@
7379  
7380  /* inode in-kernel data */
7381  
7382 +#define TMPFS_SUPER_MAGIC      0x01021994
7383 +
7384 +
7385  struct shmem_inode_info {
7386         spinlock_t              lock;
7387         unsigned long           flags;
7388 diff -NurpP --minimal linux-3.13.10/include/linux/stat.h linux-3.13.10-vs2.3.6.11/include/linux/stat.h
7389 --- linux-3.13.10/include/linux/stat.h  2012-12-11 03:30:57.000000000 +0000
7390 +++ linux-3.13.10-vs2.3.6.11/include/linux/stat.h       2014-01-31 20:38:03.000000000 +0000
7391 @@ -25,6 +25,7 @@ struct kstat {
7392         unsigned int    nlink;
7393         kuid_t          uid;
7394         kgid_t          gid;
7395 +       ktag_t          tag;
7396         dev_t           rdev;
7397         loff_t          size;
7398         struct timespec  atime;
7399 diff -NurpP --minimal linux-3.13.10/include/linux/sunrpc/auth.h linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/auth.h
7400 --- linux-3.13.10/include/linux/sunrpc/auth.h   2013-11-25 15:47:02.000000000 +0000
7401 +++ linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/auth.h        2014-01-31 20:38:03.000000000 +0000
7402 @@ -36,6 +36,7 @@ enum {
7403  struct auth_cred {
7404         kuid_t  uid;
7405         kgid_t  gid;
7406 +       ktag_t  tag;
7407         struct group_info *group_info;
7408         const char *principal;
7409         unsigned long ac_flags;
7410 diff -NurpP --minimal linux-3.13.10/include/linux/sunrpc/clnt.h linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/clnt.h
7411 --- linux-3.13.10/include/linux/sunrpc/clnt.h   2014-01-22 20:39:11.000000000 +0000
7412 +++ linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/clnt.h        2014-01-31 20:38:03.000000000 +0000
7413 @@ -51,7 +51,8 @@ struct rpc_clnt {
7414                                 cl_discrtry : 1,/* disconnect before retry */
7415                                 cl_noretranstimeo: 1,/* No retransmit timeouts */
7416                                 cl_autobind : 1,/* use getport() */
7417 -                               cl_chatty   : 1;/* be verbose */
7418 +                               cl_chatty   : 1,/* be verbose */
7419 +                               cl_tag      : 1;/* context tagging */
7420  
7421         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
7422         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
7423 diff -NurpP --minimal linux-3.13.10/include/linux/sysfs.h linux-3.13.10-vs2.3.6.11/include/linux/sysfs.h
7424 --- linux-3.13.10/include/linux/sysfs.h 2014-01-22 20:39:11.000000000 +0000
7425 +++ linux-3.13.10-vs2.3.6.11/include/linux/sysfs.h      2014-01-31 20:38:03.000000000 +0000
7426 @@ -20,6 +20,8 @@
7427  #include <linux/stat.h>
7428  #include <linux/atomic.h>
7429  
7430 +#define SYSFS_SUPER_MAGIC      0x62656572
7431 +
7432  struct kobject;
7433  struct module;
7434  struct bin_attribute;
7435 diff -NurpP --minimal linux-3.13.10/include/linux/types.h linux-3.13.10-vs2.3.6.11/include/linux/types.h
7436 --- linux-3.13.10/include/linux/types.h 2013-02-19 13:58:52.000000000 +0000
7437 +++ linux-3.13.10-vs2.3.6.11/include/linux/types.h      2014-01-31 20:38:03.000000000 +0000
7438 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
7439  typedef __kernel_gid32_t       gid_t;
7440  typedef __kernel_uid16_t        uid16_t;
7441  typedef __kernel_gid16_t        gid16_t;
7442 +typedef unsigned int           vxid_t;
7443 +typedef unsigned int           vnid_t;
7444 +typedef unsigned int           vtag_t;
7445  
7446  typedef unsigned long          uintptr_t;
7447  
7448 diff -NurpP --minimal linux-3.13.10/include/linux/uidgid.h linux-3.13.10-vs2.3.6.11/include/linux/uidgid.h
7449 --- linux-3.13.10/include/linux/uidgid.h        2012-12-11 03:30:57.000000000 +0000
7450 +++ linux-3.13.10-vs2.3.6.11/include/linux/uidgid.h     2014-01-31 20:38:03.000000000 +0000
7451 @@ -23,13 +23,17 @@ typedef struct {
7452         uid_t val;
7453  } kuid_t;
7454  
7455 -
7456  typedef struct {
7457         gid_t val;
7458  } kgid_t;
7459  
7460 +typedef struct {
7461 +       vtag_t val;
7462 +} ktag_t;
7463 +
7464  #define KUIDT_INIT(value) (kuid_t){ value }
7465  #define KGIDT_INIT(value) (kgid_t){ value }
7466 +#define KTAGT_INIT(value) (ktag_t){ value }
7467  
7468  static inline uid_t __kuid_val(kuid_t uid)
7469  {
7470 @@ -41,11 +45,18 @@ static inline gid_t __kgid_val(kgid_t gi
7471         return gid.val;
7472  }
7473  
7474 +static inline vtag_t __ktag_val(ktag_t tag)
7475 +{
7476 +       return tag.val;
7477 +}
7478 +
7479  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
7480  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
7481 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
7482  
7483  #define INVALID_UID KUIDT_INIT(-1)
7484  #define INVALID_GID KGIDT_INIT(-1)
7485 +#define INVALID_TAG KTAGT_INIT(-1)
7486  
7487  static inline bool uid_eq(kuid_t left, kuid_t right)
7488  {
7489 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
7490         return __kgid_val(left) == __kgid_val(right);
7491  }
7492  
7493 +static inline bool tag_eq(ktag_t left, ktag_t right)
7494 +{
7495 +       return __ktag_val(left) == __ktag_val(right);
7496 +}
7497 +
7498  static inline bool uid_gt(kuid_t left, kuid_t right)
7499  {
7500         return __kuid_val(left) > __kuid_val(right);
7501 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
7502         return !gid_eq(gid, INVALID_GID);
7503  }
7504  
7505 +static inline bool tag_valid(ktag_t tag)
7506 +{
7507 +       return !tag_eq(tag, INVALID_TAG);
7508 +}
7509 +
7510  #ifdef CONFIG_USER_NS
7511  
7512  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
7513  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
7514 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
7515  
7516  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
7517  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
7518 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
7519 +
7520  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
7521  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
7522  
7523 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
7524         return KGIDT_INIT(gid);
7525  }
7526  
7527 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
7528 +{
7529 +       return KTAGT_INIT(tag);
7530 +}
7531 +
7532  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
7533  {
7534         return __kuid_val(kuid);
7535 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
7536         return __kgid_val(kgid);
7537  }
7538  
7539 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
7540 +{
7541 +       return __ktag_val(ktag);
7542 +}
7543 +
7544  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
7545  {
7546         uid_t uid = from_kuid(to, kuid);
7547 diff -NurpP --minimal linux-3.13.10/include/linux/vroot.h linux-3.13.10-vs2.3.6.11/include/linux/vroot.h
7548 --- linux-3.13.10/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
7549 +++ linux-3.13.10-vs2.3.6.11/include/linux/vroot.h      2014-01-31 20:38:03.000000000 +0000
7550 @@ -0,0 +1,51 @@
7551 +
7552 +/*
7553 + * include/linux/vroot.h
7554 + *
7555 + * written by Herbert Pötzl, 9/11/2002
7556 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
7557 + *
7558 + * Copyright (C) 2002-2007 by Herbert Pötzl.
7559 + * Redistribution of this file is permitted under the
7560 + * GNU General Public License.
7561 + */
7562 +
7563 +#ifndef _LINUX_VROOT_H
7564 +#define _LINUX_VROOT_H
7565 +
7566 +
7567 +#ifdef __KERNEL__
7568 +
7569 +/* Possible states of device */
7570 +enum {
7571 +       Vr_unbound,
7572 +       Vr_bound,
7573 +};
7574 +
7575 +struct vroot_device {
7576 +       int             vr_number;
7577 +       int             vr_refcnt;
7578 +
7579 +       struct semaphore        vr_ctl_mutex;
7580 +       struct block_device    *vr_device;
7581 +       int                     vr_state;
7582 +};
7583 +
7584 +
7585 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
7586 +
7587 +extern int register_vroot_grb(vroot_grb_func *);
7588 +extern int unregister_vroot_grb(vroot_grb_func *);
7589 +
7590 +#endif /* __KERNEL__ */
7591 +
7592 +#define MAX_VROOT_DEFAULT      8
7593 +
7594 +/*
7595 + * IOCTL commands --- we will commandeer 0x56 ('V')
7596 + */
7597 +
7598 +#define VROOT_SET_DEV          0x5600
7599 +#define VROOT_CLR_DEV          0x5601
7600 +
7601 +#endif /* _LINUX_VROOT_H */
7602 diff -NurpP --minimal linux-3.13.10/include/linux/vs_base.h linux-3.13.10-vs2.3.6.11/include/linux/vs_base.h
7603 --- linux-3.13.10/include/linux/vs_base.h       1970-01-01 00:00:00.000000000 +0000
7604 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_base.h    2014-01-31 20:38:03.000000000 +0000
7605 @@ -0,0 +1,10 @@
7606 +#ifndef _VS_BASE_H
7607 +#define _VS_BASE_H
7608 +
7609 +#include "vserver/base.h"
7610 +#include "vserver/check.h"
7611 +#include "vserver/debug.h"
7612 +
7613 +#else
7614 +#warning duplicate inclusion
7615 +#endif
7616 diff -NurpP --minimal linux-3.13.10/include/linux/vs_context.h linux-3.13.10-vs2.3.6.11/include/linux/vs_context.h
7617 --- linux-3.13.10/include/linux/vs_context.h    1970-01-01 00:00:00.000000000 +0000
7618 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_context.h 2014-01-31 20:38:03.000000000 +0000
7619 @@ -0,0 +1,242 @@
7620 +#ifndef _VS_CONTEXT_H
7621 +#define _VS_CONTEXT_H
7622 +
7623 +#include "vserver/base.h"
7624 +#include "vserver/check.h"
7625 +#include "vserver/context.h"
7626 +#include "vserver/history.h"
7627 +#include "vserver/debug.h"
7628 +
7629 +#include <linux/sched.h>
7630 +
7631 +
7632 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
7633 +
7634 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
7635 +       const char *_file, int _line, void *_here)
7636 +{
7637 +       if (!vxi)
7638 +               return NULL;
7639 +
7640 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
7641 +               vxi, vxi ? vxi->vx_id : 0,
7642 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7643 +               _file, _line);
7644 +       __vxh_get_vx_info(vxi, _here);
7645 +
7646 +       atomic_inc(&vxi->vx_usecnt);
7647 +       return vxi;
7648 +}
7649 +
7650 +
7651 +extern void free_vx_info(struct vx_info *);
7652 +
7653 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
7654 +
7655 +static inline void __put_vx_info(struct vx_info *vxi,
7656 +       const char *_file, int _line, void *_here)
7657 +{
7658 +       if (!vxi)
7659 +               return;
7660 +
7661 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
7662 +               vxi, vxi ? vxi->vx_id : 0,
7663 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7664 +               _file, _line);
7665 +       __vxh_put_vx_info(vxi, _here);
7666 +
7667 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
7668 +               free_vx_info(vxi);
7669 +}
7670 +
7671 +
7672 +#define init_vx_info(p, i) \
7673 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7674 +
7675 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7676 +       const char *_file, int _line, void *_here)
7677 +{
7678 +       if (vxi) {
7679 +               vxlprintk(VXD_CBIT(xid, 3),
7680 +                       "init_vx_info(%p[#%d.%d])",
7681 +                       vxi, vxi ? vxi->vx_id : 0,
7682 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7683 +                       _file, _line);
7684 +               __vxh_init_vx_info(vxi, vxp, _here);
7685 +
7686 +               atomic_inc(&vxi->vx_usecnt);
7687 +       }
7688 +       *vxp = vxi;
7689 +}
7690 +
7691 +
7692 +#define set_vx_info(p, i) \
7693 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7694 +
7695 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7696 +       const char *_file, int _line, void *_here)
7697 +{
7698 +       struct vx_info *vxo;
7699 +
7700 +       if (!vxi)
7701 +               return;
7702 +
7703 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
7704 +               vxi, vxi ? vxi->vx_id : 0,
7705 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7706 +               _file, _line);
7707 +       __vxh_set_vx_info(vxi, vxp, _here);
7708 +
7709 +       atomic_inc(&vxi->vx_usecnt);
7710 +       vxo = xchg(vxp, vxi);
7711 +       BUG_ON(vxo);
7712 +}
7713 +
7714 +
7715 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
7716 +
7717 +static inline void __clr_vx_info(struct vx_info **vxp,
7718 +       const char *_file, int _line, void *_here)
7719 +{
7720 +       struct vx_info *vxo;
7721 +
7722 +       vxo = xchg(vxp, NULL);
7723 +       if (!vxo)
7724 +               return;
7725 +
7726 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
7727 +               vxo, vxo ? vxo->vx_id : 0,
7728 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
7729 +               _file, _line);
7730 +       __vxh_clr_vx_info(vxo, vxp, _here);
7731 +
7732 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
7733 +               free_vx_info(vxo);
7734 +}
7735 +
7736 +
7737 +#define claim_vx_info(v, p) \
7738 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7739 +
7740 +static inline void __claim_vx_info(struct vx_info *vxi,
7741 +       struct task_struct *task,
7742 +       const char *_file, int _line, void *_here)
7743 +{
7744 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
7745 +               vxi, vxi ? vxi->vx_id : 0,
7746 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7747 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7748 +               task, _file, _line);
7749 +       __vxh_claim_vx_info(vxi, task, _here);
7750 +
7751 +       atomic_inc(&vxi->vx_tasks);
7752 +}
7753 +
7754 +
7755 +extern void unhash_vx_info(struct vx_info *);
7756 +
7757 +#define release_vx_info(v, p) \
7758 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7759 +
7760 +static inline void __release_vx_info(struct vx_info *vxi,
7761 +       struct task_struct *task,
7762 +       const char *_file, int _line, void *_here)
7763 +{
7764 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
7765 +               vxi, vxi ? vxi->vx_id : 0,
7766 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7767 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
7768 +               task, _file, _line);
7769 +       __vxh_release_vx_info(vxi, task, _here);
7770 +
7771 +       might_sleep();
7772 +
7773 +       if (atomic_dec_and_test(&vxi->vx_tasks))
7774 +               unhash_vx_info(vxi);
7775 +}
7776 +
7777 +
7778 +#define task_get_vx_info(p) \
7779 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
7780 +
7781 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
7782 +       const char *_file, int _line, void *_here)
7783 +{
7784 +       struct vx_info *vxi;
7785 +
7786 +       task_lock(p);
7787 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
7788 +               p, _file, _line);
7789 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
7790 +       task_unlock(p);
7791 +       return vxi;
7792 +}
7793 +
7794 +
7795 +static inline void __wakeup_vx_info(struct vx_info *vxi)
7796 +{
7797 +       if (waitqueue_active(&vxi->vx_wait))
7798 +               wake_up_interruptible(&vxi->vx_wait);
7799 +}
7800 +
7801 +
7802 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
7803 +
7804 +static inline void __enter_vx_info(struct vx_info *vxi,
7805 +       struct vx_info_save *vxis, const char *_file, int _line)
7806 +{
7807 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
7808 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
7809 +               current->xid, current->vx_info, _file, _line);
7810 +       vxis->vxi = xchg(&current->vx_info, vxi);
7811 +       vxis->xid = current->xid;
7812 +       current->xid = vxi ? vxi->vx_id : 0;
7813 +}
7814 +
7815 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
7816 +
7817 +static inline void __leave_vx_info(struct vx_info_save *vxis,
7818 +       const char *_file, int _line)
7819 +{
7820 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
7821 +               vxis, vxis->xid, vxis->vxi, current,
7822 +               current->xid, current->vx_info, _file, _line);
7823 +       (void)xchg(&current->vx_info, vxis->vxi);
7824 +       current->xid = vxis->xid;
7825 +}
7826 +
7827 +
7828 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
7829 +{
7830 +       vxis->vxi = xchg(&current->vx_info, NULL);
7831 +       vxis->xid = xchg(&current->xid, (vxid_t)0);
7832 +}
7833 +
7834 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
7835 +{
7836 +       (void)xchg(&current->xid, vxis->xid);
7837 +       (void)xchg(&current->vx_info, vxis->vxi);
7838 +}
7839 +
7840 +#define task_is_init(p) \
7841 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
7842 +
7843 +static inline int __task_is_init(struct task_struct *p,
7844 +       const char *_file, int _line, void *_here)
7845 +{
7846 +       int is_init = is_global_init(p);
7847 +
7848 +       task_lock(p);
7849 +       if (p->vx_info)
7850 +               is_init = p->vx_info->vx_initpid == p->pid;
7851 +       task_unlock(p);
7852 +       return is_init;
7853 +}
7854 +
7855 +extern void exit_vx_info(struct task_struct *, int);
7856 +extern void exit_vx_info_early(struct task_struct *, int);
7857 +
7858 +
7859 +#else
7860 +#warning duplicate inclusion
7861 +#endif
7862 diff -NurpP --minimal linux-3.13.10/include/linux/vs_cowbl.h linux-3.13.10-vs2.3.6.11/include/linux/vs_cowbl.h
7863 --- linux-3.13.10/include/linux/vs_cowbl.h      1970-01-01 00:00:00.000000000 +0000
7864 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_cowbl.h   2014-01-31 20:38:03.000000000 +0000
7865 @@ -0,0 +1,48 @@
7866 +#ifndef _VS_COWBL_H
7867 +#define _VS_COWBL_H
7868 +
7869 +#include <linux/fs.h>
7870 +#include <linux/dcache.h>
7871 +#include <linux/namei.h>
7872 +#include <linux/slab.h>
7873 +
7874 +extern struct dentry *cow_break_link(const char *pathname);
7875 +
7876 +static inline int cow_check_and_break(struct path *path)
7877 +{
7878 +       struct inode *inode = path->dentry->d_inode;
7879 +       int error = 0;
7880 +
7881 +       /* do we need this check? */
7882 +       if (IS_RDONLY(inode))
7883 +               return -EROFS;
7884 +
7885 +       if (IS_COW(inode)) {
7886 +               if (IS_COW_LINK(inode)) {
7887 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
7888 +                       char *pp, *buf;
7889 +
7890 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
7891 +                       if (!buf) {
7892 +                               return -ENOMEM;
7893 +                       }
7894 +                       pp = d_path(path, buf, PATH_MAX);
7895 +                       new_dentry = cow_break_link(pp);
7896 +                       kfree(buf);
7897 +                       if (!IS_ERR(new_dentry)) {
7898 +                               path->dentry = new_dentry;
7899 +                               dput(old_dentry);
7900 +                       } else
7901 +                               error = PTR_ERR(new_dentry);
7902 +               } else {
7903 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
7904 +                       inode->i_ctime = CURRENT_TIME;
7905 +                       mark_inode_dirty(inode);
7906 +               }
7907 +       }
7908 +       return error;
7909 +}
7910 +
7911 +#else
7912 +#warning duplicate inclusion
7913 +#endif
7914 diff -NurpP --minimal linux-3.13.10/include/linux/vs_cvirt.h linux-3.13.10-vs2.3.6.11/include/linux/vs_cvirt.h
7915 --- linux-3.13.10/include/linux/vs_cvirt.h      1970-01-01 00:00:00.000000000 +0000
7916 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_cvirt.h   2014-01-31 20:38:03.000000000 +0000
7917 @@ -0,0 +1,50 @@
7918 +#ifndef _VS_CVIRT_H
7919 +#define _VS_CVIRT_H
7920 +
7921 +#include "vserver/cvirt.h"
7922 +#include "vserver/context.h"
7923 +#include "vserver/base.h"
7924 +#include "vserver/check.h"
7925 +#include "vserver/debug.h"
7926 +
7927 +
7928 +static inline void vx_activate_task(struct task_struct *p)
7929 +{
7930 +       struct vx_info *vxi;
7931 +
7932 +       if ((vxi = p->vx_info)) {
7933 +               vx_update_load(vxi);
7934 +               atomic_inc(&vxi->cvirt.nr_running);
7935 +       }
7936 +}
7937 +
7938 +static inline void vx_deactivate_task(struct task_struct *p)
7939 +{
7940 +       struct vx_info *vxi;
7941 +
7942 +       if ((vxi = p->vx_info)) {
7943 +               vx_update_load(vxi);
7944 +               atomic_dec(&vxi->cvirt.nr_running);
7945 +       }
7946 +}
7947 +
7948 +static inline void vx_uninterruptible_inc(struct task_struct *p)
7949 +{
7950 +       struct vx_info *vxi;
7951 +
7952 +       if ((vxi = p->vx_info))
7953 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
7954 +}
7955 +
7956 +static inline void vx_uninterruptible_dec(struct task_struct *p)
7957 +{
7958 +       struct vx_info *vxi;
7959 +
7960 +       if ((vxi = p->vx_info))
7961 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
7962 +}
7963 +
7964 +
7965 +#else
7966 +#warning duplicate inclusion
7967 +#endif
7968 diff -NurpP --minimal linux-3.13.10/include/linux/vs_device.h linux-3.13.10-vs2.3.6.11/include/linux/vs_device.h
7969 --- linux-3.13.10/include/linux/vs_device.h     1970-01-01 00:00:00.000000000 +0000
7970 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_device.h  2014-01-31 20:38:03.000000000 +0000
7971 @@ -0,0 +1,45 @@
7972 +#ifndef _VS_DEVICE_H
7973 +#define _VS_DEVICE_H
7974 +
7975 +#include "vserver/base.h"
7976 +#include "vserver/device.h"
7977 +#include "vserver/debug.h"
7978 +
7979 +
7980 +#ifdef CONFIG_VSERVER_DEVICE
7981 +
7982 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
7983 +
7984 +#define vs_device_perm(v, d, m, p) \
7985 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
7986 +
7987 +#else
7988 +
7989 +static inline
7990 +int vs_map_device(struct vx_info *vxi,
7991 +       dev_t device, dev_t *target, umode_t mode)
7992 +{
7993 +       if (target)
7994 +               *target = device;
7995 +       return ~0;
7996 +}
7997 +
7998 +#define vs_device_perm(v, d, m, p) ((p) == (p))
7999 +
8000 +#endif
8001 +
8002 +
8003 +#define vs_map_chrdev(d, t, p) \
8004 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8005 +#define vs_map_blkdev(d, t, p) \
8006 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8007 +
8008 +#define vs_chrdev_perm(d, p) \
8009 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8010 +#define vs_blkdev_perm(d, p) \
8011 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8012 +
8013 +
8014 +#else
8015 +#warning duplicate inclusion
8016 +#endif
8017 diff -NurpP --minimal linux-3.13.10/include/linux/vs_dlimit.h linux-3.13.10-vs2.3.6.11/include/linux/vs_dlimit.h
8018 --- linux-3.13.10/include/linux/vs_dlimit.h     1970-01-01 00:00:00.000000000 +0000
8019 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_dlimit.h  2014-01-31 20:38:03.000000000 +0000
8020 @@ -0,0 +1,215 @@
8021 +#ifndef _VS_DLIMIT_H
8022 +#define _VS_DLIMIT_H
8023 +
8024 +#include <linux/fs.h>
8025 +
8026 +#include "vserver/dlimit.h"
8027 +#include "vserver/base.h"
8028 +#include "vserver/debug.h"
8029 +
8030 +
8031 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8032 +
8033 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8034 +       const char *_file, int _line)
8035 +{
8036 +       if (!dli)
8037 +               return NULL;
8038 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8039 +               dli, dli ? dli->dl_tag : 0,
8040 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8041 +               _file, _line);
8042 +       atomic_inc(&dli->dl_usecnt);
8043 +       return dli;
8044 +}
8045 +
8046 +
8047 +#define free_dl_info(i) \
8048 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8049 +
8050 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8051 +
8052 +static inline void __put_dl_info(struct dl_info *dli,
8053 +       const char *_file, int _line)
8054 +{
8055 +       if (!dli)
8056 +               return;
8057 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8058 +               dli, dli ? dli->dl_tag : 0,
8059 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8060 +               _file, _line);
8061 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8062 +               free_dl_info(dli);
8063 +}
8064 +
8065 +
8066 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8067 +
8068 +static inline int __dl_alloc_space(struct super_block *sb,
8069 +       vtag_t tag, dlsize_t nr, const char *file, int line)
8070 +{
8071 +       struct dl_info *dli = NULL;
8072 +       int ret = 0;
8073 +
8074 +       if (nr == 0)
8075 +               goto out;
8076 +       dli = locate_dl_info(sb, tag);
8077 +       if (!dli)
8078 +               goto out;
8079 +
8080 +       spin_lock(&dli->dl_lock);
8081 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
8082 +       if (!ret)
8083 +               dli->dl_space_used += nr;
8084 +       spin_unlock(&dli->dl_lock);
8085 +       put_dl_info(dli);
8086 +out:
8087 +       vxlprintk(VXD_CBIT(dlim, 1),
8088 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
8089 +               sb, tag, __dlimit_char(dli), (long long)nr,
8090 +               ret, file, line);
8091 +       return ret ? -ENOSPC : 0;
8092 +}
8093 +
8094 +static inline void __dl_free_space(struct super_block *sb,
8095 +       vtag_t tag, dlsize_t nr, const char *_file, int _line)
8096 +{
8097 +       struct dl_info *dli = NULL;
8098 +
8099 +       if (nr == 0)
8100 +               goto out;
8101 +       dli = locate_dl_info(sb, tag);
8102 +       if (!dli)
8103 +               goto out;
8104 +
8105 +       spin_lock(&dli->dl_lock);
8106 +       if (dli->dl_space_used > nr)
8107 +               dli->dl_space_used -= nr;
8108 +       else
8109 +               dli->dl_space_used = 0;
8110 +       spin_unlock(&dli->dl_lock);
8111 +       put_dl_info(dli);
8112 +out:
8113 +       vxlprintk(VXD_CBIT(dlim, 1),
8114 +               "FREE  (%p,#%d)%c %lld bytes",
8115 +               sb, tag, __dlimit_char(dli), (long long)nr,
8116 +               _file, _line);
8117 +}
8118 +
8119 +static inline int __dl_alloc_inode(struct super_block *sb,
8120 +       vtag_t tag, const char *_file, int _line)
8121 +{
8122 +       struct dl_info *dli;
8123 +       int ret = 0;
8124 +
8125 +       dli = locate_dl_info(sb, tag);
8126 +       if (!dli)
8127 +               goto out;
8128 +
8129 +       spin_lock(&dli->dl_lock);
8130 +       dli->dl_inodes_used++;
8131 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8132 +       spin_unlock(&dli->dl_lock);
8133 +       put_dl_info(dli);
8134 +out:
8135 +       vxlprintk(VXD_CBIT(dlim, 0),
8136 +               "ALLOC (%p,#%d)%c inode (%d)",
8137 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
8138 +       return ret ? -ENOSPC : 0;
8139 +}
8140 +
8141 +static inline void __dl_free_inode(struct super_block *sb,
8142 +       vtag_t tag, const char *_file, int _line)
8143 +{
8144 +       struct dl_info *dli;
8145 +
8146 +       dli = locate_dl_info(sb, tag);
8147 +       if (!dli)
8148 +               goto out;
8149 +
8150 +       spin_lock(&dli->dl_lock);
8151 +       if (dli->dl_inodes_used > 1)
8152 +               dli->dl_inodes_used--;
8153 +       else
8154 +               dli->dl_inodes_used = 0;
8155 +       spin_unlock(&dli->dl_lock);
8156 +       put_dl_info(dli);
8157 +out:
8158 +       vxlprintk(VXD_CBIT(dlim, 0),
8159 +               "FREE  (%p,#%d)%c inode",
8160 +               sb, tag, __dlimit_char(dli), _file, _line);
8161 +}
8162 +
8163 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
8164 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
8165 +       const char *_file, int _line)
8166 +{
8167 +       struct dl_info *dli;
8168 +       uint64_t broot, bfree;
8169 +
8170 +       dli = locate_dl_info(sb, tag);
8171 +       if (!dli)
8172 +               return;
8173 +
8174 +       spin_lock(&dli->dl_lock);
8175 +       broot = (dli->dl_space_total -
8176 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8177 +               >> sb->s_blocksize_bits;
8178 +       bfree = (dli->dl_space_total - dli->dl_space_used)
8179 +                       >> sb->s_blocksize_bits;
8180 +       spin_unlock(&dli->dl_lock);
8181 +
8182 +       vxlprintk(VXD_CBIT(dlim, 2),
8183 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8184 +               (long long)bfree, (long long)broot,
8185 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
8186 +               _file, _line);
8187 +       if (free_blocks) {
8188 +               if (*free_blocks > bfree)
8189 +                       *free_blocks = bfree;
8190 +       }
8191 +       if (root_blocks) {
8192 +               if (*root_blocks > broot)
8193 +                       *root_blocks = broot;
8194 +       }
8195 +       put_dl_info(dli);
8196 +}
8197 +
8198 +#define dl_prealloc_space(in, bytes) \
8199 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8200 +               __FILE__, __LINE__ )
8201 +
8202 +#define dl_alloc_space(in, bytes) \
8203 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8204 +               __FILE__, __LINE__ )
8205 +
8206 +#define dl_reserve_space(in, bytes) \
8207 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8208 +               __FILE__, __LINE__ )
8209 +
8210 +#define dl_claim_space(in, bytes) (0)
8211 +
8212 +#define dl_release_space(in, bytes) \
8213 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8214 +               __FILE__, __LINE__ )
8215 +
8216 +#define dl_free_space(in, bytes) \
8217 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8218 +               __FILE__, __LINE__ )
8219 +
8220 +
8221 +
8222 +#define dl_alloc_inode(in) \
8223 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8224 +
8225 +#define dl_free_inode(in) \
8226 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8227 +
8228 +
8229 +#define dl_adjust_block(sb, tag, fb, rb) \
8230 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8231 +
8232 +
8233 +#else
8234 +#warning duplicate inclusion
8235 +#endif
8236 diff -NurpP --minimal linux-3.13.10/include/linux/vs_inet.h linux-3.13.10-vs2.3.6.11/include/linux/vs_inet.h
8237 --- linux-3.13.10/include/linux/vs_inet.h       1970-01-01 00:00:00.000000000 +0000
8238 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_inet.h    2014-02-01 00:32:45.000000000 +0000
8239 @@ -0,0 +1,364 @@
8240 +#ifndef _VS_INET_H
8241 +#define _VS_INET_H
8242 +
8243 +#include "vserver/base.h"
8244 +#include "vserver/network.h"
8245 +#include "vserver/debug.h"
8246 +
8247 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
8248 +
8249 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
8250 +                       NIPQUAD((a)->mask), (a)->type
8251 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
8252 +
8253 +#define NIPQUAD(addr) \
8254 +       ((unsigned char *)&addr)[0], \
8255 +       ((unsigned char *)&addr)[1], \
8256 +       ((unsigned char *)&addr)[2], \
8257 +       ((unsigned char *)&addr)[3]
8258 +
8259 +#define NIPQUAD_FMT "%u.%u.%u.%u"
8260 +
8261 +
8262 +static inline
8263 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
8264 +{
8265 +       __be32 ip = nxa->ip[0].s_addr;
8266 +       __be32 mask = nxa->mask.s_addr;
8267 +       __be32 bcast = ip | ~mask;
8268 +       int ret = 0;
8269 +
8270 +       switch (nxa->type & tmask) {
8271 +       case NXA_TYPE_MASK:
8272 +               ret = (ip == (addr & mask));
8273 +               break;
8274 +       case NXA_TYPE_ADDR:
8275 +               ret = 3;
8276 +               if (addr == ip)
8277 +                       break;
8278 +               /* fall through to broadcast */
8279 +       case NXA_MOD_BCAST:
8280 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
8281 +               break;
8282 +       case NXA_TYPE_RANGE:
8283 +               ret = ((nxa->ip[0].s_addr <= addr) &&
8284 +                       (nxa->ip[1].s_addr > addr));
8285 +               break;
8286 +       case NXA_TYPE_ANY:
8287 +               ret = 2;
8288 +               break;
8289 +       }
8290 +
8291 +       vxdprintk(VXD_CBIT(net, 0),
8292 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
8293 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
8294 +       return ret;
8295 +}
8296 +
8297 +static inline
8298 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
8299 +{
8300 +       struct nx_addr_v4 *nxa;
8301 +       unsigned long irqflags;
8302 +       int ret = 1;
8303 +
8304 +       if (!nxi)
8305 +               goto out;
8306 +
8307 +       ret = 2;
8308 +       /* allow 127.0.0.1 when remapping lback */
8309 +       if ((tmask & NXA_LOOPBACK) &&
8310 +               (addr == IPI_LOOPBACK) &&
8311 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8312 +               goto out;
8313 +       ret = 3;
8314 +       /* check for lback address */
8315 +       if ((tmask & NXA_MOD_LBACK) &&
8316 +               (nxi->v4_lback.s_addr == addr))
8317 +               goto out;
8318 +       ret = 4;
8319 +       /* check for broadcast address */
8320 +       if ((tmask & NXA_MOD_BCAST) &&
8321 +               (nxi->v4_bcast.s_addr == addr))
8322 +               goto out;
8323 +       ret = 5;
8324 +
8325 +       /* check for v4 addresses */
8326 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8327 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
8328 +               if (v4_addr_match(nxa, addr, tmask))
8329 +                       goto out_unlock;
8330 +       ret = 0;
8331 +out_unlock:
8332 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8333 +out:
8334 +       vxdprintk(VXD_CBIT(net, 0),
8335 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
8336 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
8337 +       return ret;
8338 +}
8339 +
8340 +static inline
8341 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
8342 +{
8343 +       /* FIXME: needs full range checks */
8344 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
8345 +}
8346 +
8347 +static inline
8348 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
8349 +{
8350 +       struct nx_addr_v4 *ptr;
8351 +       unsigned long irqflags;
8352 +       int ret = 1;
8353 +
8354 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8355 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
8356 +               if (v4_nx_addr_match(ptr, nxa, mask))
8357 +                       goto out_unlock;
8358 +       ret = 0;
8359 +out_unlock:
8360 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8361 +       return ret;
8362 +}
8363 +
8364 +#include <net/inet_sock.h>
8365 +
8366 +/*
8367 + *     Check if a given address matches for a socket
8368 + *
8369 + *     nxi:            the socket's nx_info if any
8370 + *     addr:           to be verified address
8371 + */
8372 +static inline
8373 +int v4_sock_addr_match (
8374 +       struct nx_info *nxi,
8375 +       struct inet_sock *inet,
8376 +       __be32 addr)
8377 +{
8378 +       __be32 saddr = inet->inet_rcv_saddr;
8379 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
8380 +
8381 +       if (addr && (saddr == addr || bcast == addr))
8382 +               return 1;
8383 +       if (!saddr)
8384 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
8385 +       return 0;
8386 +}
8387 +
8388 +
8389 +/* inet related checks and helpers */
8390 +
8391 +
8392 +struct in_ifaddr;
8393 +struct net_device;
8394 +struct sock;
8395 +
8396 +#ifdef CONFIG_INET
8397 +
8398 +#include <linux/netdevice.h>
8399 +#include <linux/inetdevice.h>
8400 +#include <net/inet_sock.h>
8401 +#include <net/inet_timewait_sock.h>
8402 +
8403 +
8404 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8405 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
8406 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
8407 +
8408 +
8409 +/*
8410 + *     check if address is covered by socket
8411 + *
8412 + *     sk:     the socket to check against
8413 + *     addr:   the address in question (must be != 0)
8414 + */
8415 +
8416 +static inline
8417 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
8418 +{
8419 +       struct nx_info *nxi = sk->sk_nx_info;
8420 +       __be32 saddr = sk->sk_rcv_saddr;
8421 +
8422 +       vxdprintk(VXD_CBIT(net, 5),
8423 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
8424 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
8425 +               (sk->sk_socket?sk->sk_socket->flags:0));
8426 +
8427 +       if (saddr) {            /* direct address match */
8428 +               return v4_addr_match(nxa, saddr, -1);
8429 +       } else if (nxi) {       /* match against nx_info */
8430 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
8431 +       } else {                /* unrestricted any socket */
8432 +               return 1;
8433 +       }
8434 +}
8435 +
8436 +
8437 +
8438 +static inline
8439 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
8440 +{
8441 +       vxdprintk(VXD_CBIT(net, 1),
8442 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
8443 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
8444 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
8445 +
8446 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8447 +               return 1;
8448 +       if (dev_in_nx_info(dev, nxi))
8449 +               return 1;
8450 +       return 0;
8451 +}
8452 +
8453 +
8454 +static inline
8455 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
8456 +{
8457 +       if (!nxi)
8458 +               return 1;
8459 +       if (!ifa)
8460 +               return 0;
8461 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
8462 +}
8463 +
8464 +static inline
8465 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
8466 +{
8467 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
8468 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8469 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
8470 +
8471 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8472 +               return 1;
8473 +       if (v4_ifa_in_nx_info(ifa, nxi))
8474 +               return 1;
8475 +       return 0;
8476 +}
8477 +
8478 +
8479 +struct nx_v4_sock_addr {
8480 +       __be32 saddr;   /* Address used for validation */
8481 +       __be32 baddr;   /* Address used for socket bind */
8482 +};
8483 +
8484 +static inline
8485 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
8486 +       struct nx_v4_sock_addr *nsa)
8487 +{
8488 +       struct sock *sk = &inet->sk;
8489 +       struct nx_info *nxi = sk->sk_nx_info;
8490 +       __be32 saddr = addr->sin_addr.s_addr;
8491 +       __be32 baddr = saddr;
8492 +
8493 +       vxdprintk(VXD_CBIT(net, 3),
8494 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
8495 +               sk, sk->sk_nx_info, sk->sk_socket,
8496 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
8497 +               NIPQUAD(saddr));
8498 +
8499 +       if (nxi) {
8500 +               if (saddr == INADDR_ANY) {
8501 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
8502 +                               baddr = nxi->v4.ip[0].s_addr;
8503 +               } else if (saddr == IPI_LOOPBACK) {
8504 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8505 +                               baddr = nxi->v4_lback.s_addr;
8506 +               } else if (!ipv4_is_multicast(saddr) ||
8507 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
8508 +                       /* normal address bind */
8509 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
8510 +                               return -EADDRNOTAVAIL;
8511 +               }
8512 +       }
8513 +
8514 +       vxdprintk(VXD_CBIT(net, 3),
8515 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
8516 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
8517 +
8518 +       nsa->saddr = saddr;
8519 +       nsa->baddr = baddr;
8520 +       return 0;
8521 +}
8522 +
8523 +static inline
8524 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
8525 +{
8526 +       inet->inet_saddr = nsa->baddr;
8527 +       inet->inet_rcv_saddr = nsa->baddr;
8528 +}
8529 +
8530 +
8531 +/*
8532 + *      helper to simplify inet_lookup_listener
8533 + *
8534 + *      nxi:   the socket's nx_info if any
8535 + *      addr:  to be verified address
8536 + *      saddr: socket address
8537 + */
8538 +static inline int v4_inet_addr_match (
8539 +       struct nx_info *nxi,
8540 +       __be32 addr,
8541 +       __be32 saddr)
8542 +{
8543 +       if (addr && (saddr == addr))
8544 +               return 1;
8545 +       if (!saddr)
8546 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
8547 +       return 0;
8548 +}
8549 +
8550 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
8551 +{
8552 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
8553 +               (addr == nxi->v4_lback.s_addr))
8554 +               return IPI_LOOPBACK;
8555 +       return addr;
8556 +}
8557 +
8558 +static inline
8559 +int nx_info_has_v4(struct nx_info *nxi)
8560 +{
8561 +       if (!nxi)
8562 +               return 1;
8563 +       if (NX_IPV4(nxi))
8564 +               return 1;
8565 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8566 +               return 1;
8567 +       return 0;
8568 +}
8569 +
8570 +#else /* CONFIG_INET */
8571 +
8572 +static inline
8573 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
8574 +{
8575 +       return 1;
8576 +}
8577 +
8578 +static inline
8579 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8580 +{
8581 +       return 1;
8582 +}
8583 +
8584 +static inline
8585 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8586 +{
8587 +       return 1;
8588 +}
8589 +
8590 +static inline
8591 +int nx_info_has_v4(struct nx_info *nxi)
8592 +{
8593 +       return 0;
8594 +}
8595 +
8596 +#endif /* CONFIG_INET */
8597 +
8598 +#define current_nx_info_has_v4() \
8599 +       nx_info_has_v4(current_nx_info())
8600 +
8601 +#else
8602 +// #warning duplicate inclusion
8603 +#endif
8604 diff -NurpP --minimal linux-3.13.10/include/linux/vs_inet6.h linux-3.13.10-vs2.3.6.11/include/linux/vs_inet6.h
8605 --- linux-3.13.10/include/linux/vs_inet6.h      1970-01-01 00:00:00.000000000 +0000
8606 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_inet6.h   2014-02-01 00:35:02.000000000 +0000
8607 @@ -0,0 +1,257 @@
8608 +#ifndef _VS_INET6_H
8609 +#define _VS_INET6_H
8610 +
8611 +#include "vserver/base.h"
8612 +#include "vserver/network.h"
8613 +#include "vserver/debug.h"
8614 +
8615 +#include <net/ipv6.h>
8616 +
8617 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
8618 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
8619 +
8620 +
8621 +#ifdef CONFIG_IPV6
8622 +
8623 +static inline
8624 +int v6_addr_match(struct nx_addr_v6 *nxa,
8625 +       const struct in6_addr *addr, uint16_t mask)
8626 +{
8627 +       int ret = 0;
8628 +
8629 +       switch (nxa->type & mask) {
8630 +       case NXA_TYPE_MASK:
8631 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
8632 +               break;
8633 +       case NXA_TYPE_ADDR:
8634 +               ret = ipv6_addr_equal(&nxa->ip, addr);
8635 +               break;
8636 +       case NXA_TYPE_ANY:
8637 +               ret = 1;
8638 +               break;
8639 +       }
8640 +       vxdprintk(VXD_CBIT(net, 0),
8641 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
8642 +               nxa, NXAV6(nxa), addr, mask, ret);
8643 +       return ret;
8644 +}
8645 +
8646 +static inline
8647 +int v6_addr_in_nx_info(struct nx_info *nxi,
8648 +       const struct in6_addr *addr, uint16_t mask)
8649 +{
8650 +       struct nx_addr_v6 *nxa;
8651 +       unsigned long irqflags;
8652 +       int ret = 1;
8653 +
8654 +       if (!nxi)
8655 +               goto out;
8656 +
8657 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8658 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
8659 +               if (v6_addr_match(nxa, addr, mask))
8660 +                       goto out_unlock;
8661 +       ret = 0;
8662 +out_unlock:
8663 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8664 +out:
8665 +       vxdprintk(VXD_CBIT(net, 0),
8666 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
8667 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
8668 +       return ret;
8669 +}
8670 +
8671 +static inline
8672 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
8673 +{
8674 +       /* FIXME: needs full range checks */
8675 +       return v6_addr_match(nxa, &addr->ip, mask);
8676 +}
8677 +
8678 +static inline
8679 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
8680 +{
8681 +       struct nx_addr_v6 *ptr;
8682 +       unsigned long irqflags;
8683 +       int ret = 1;
8684 +
8685 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
8686 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
8687 +               if (v6_nx_addr_match(ptr, nxa, mask))
8688 +                       goto out_unlock;
8689 +       ret = 0;
8690 +out_unlock:
8691 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8692 +       return ret;
8693 +}
8694 +
8695 +
8696 +/*
8697 + *     Check if a given address matches for a socket
8698 + *
8699 + *     nxi:            the socket's nx_info if any
8700 + *     addr:           to be verified address
8701 + */
8702 +static inline
8703 +int v6_sock_addr_match (
8704 +       struct nx_info *nxi,
8705 +       struct inet_sock *inet,
8706 +       struct in6_addr *addr)
8707 +{
8708 +       struct sock *sk = &inet->sk;
8709 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8710 +
8711 +       if (!ipv6_addr_any(addr) &&
8712 +               ipv6_addr_equal(saddr, addr))
8713 +               return 1;
8714 +       if (ipv6_addr_any(saddr))
8715 +               return v6_addr_in_nx_info(nxi, addr, -1);
8716 +       return 0;
8717 +}
8718 +
8719 +/*
8720 + *     check if address is covered by socket
8721 + *
8722 + *     sk:     the socket to check against
8723 + *     addr:   the address in question (must be != 0)
8724 + */
8725 +
8726 +static inline
8727 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
8728 +{
8729 +       struct nx_info *nxi = sk->sk_nx_info;
8730 +       const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8731 +
8732 +       vxdprintk(VXD_CBIT(net, 5),
8733 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
8734 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
8735 +               (sk->sk_socket?sk->sk_socket->flags:0));
8736 +
8737 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
8738 +               return v6_addr_match(nxa, saddr, -1);
8739 +       } else if (nxi) {               /* match against nx_info */
8740 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
8741 +       } else {                        /* unrestricted any socket */
8742 +               return 1;
8743 +       }
8744 +}
8745 +
8746 +
8747 +/* inet related checks and helpers */
8748 +
8749 +
8750 +struct in_ifaddr;
8751 +struct net_device;
8752 +struct sock;
8753 +
8754 +
8755 +#include <linux/netdevice.h>
8756 +#include <linux/inetdevice.h>
8757 +#include <net/inet_timewait_sock.h>
8758 +
8759 +
8760 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8761 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
8762 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
8763 +
8764 +
8765 +
8766 +static inline
8767 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
8768 +{
8769 +       if (!nxi)
8770 +               return 1;
8771 +       if (!ifa)
8772 +               return 0;
8773 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
8774 +}
8775 +
8776 +static inline
8777 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
8778 +{
8779 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
8780 +               nxi, nxi ? nxi->nx_id : 0, ifa,
8781 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
8782 +
8783 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8784 +               return 1;
8785 +       if (v6_ifa_in_nx_info(ifa, nxi))
8786 +               return 1;
8787 +       return 0;
8788 +}
8789 +
8790 +
8791 +struct nx_v6_sock_addr {
8792 +       struct in6_addr saddr;  /* Address used for validation */
8793 +       struct in6_addr baddr;  /* Address used for socket bind */
8794 +};
8795 +
8796 +static inline
8797 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
8798 +       struct nx_v6_sock_addr *nsa)
8799 +{
8800 +       // struct sock *sk = &inet->sk;
8801 +       // struct nx_info *nxi = sk->sk_nx_info;
8802 +       struct in6_addr saddr = addr->sin6_addr;
8803 +       struct in6_addr baddr = saddr;
8804 +
8805 +       nsa->saddr = saddr;
8806 +       nsa->baddr = baddr;
8807 +       return 0;
8808 +}
8809 +
8810 +static inline
8811 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
8812 +{
8813 +       // struct sock *sk = &inet->sk;
8814 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
8815 +
8816 +       // *saddr = nsa->baddr;
8817 +       // inet->inet_saddr = nsa->baddr;
8818 +}
8819 +
8820 +static inline
8821 +int nx_info_has_v6(struct nx_info *nxi)
8822 +{
8823 +       if (!nxi)
8824 +               return 1;
8825 +       if (NX_IPV6(nxi))
8826 +               return 1;
8827 +       return 0;
8828 +}
8829 +
8830 +#else /* CONFIG_IPV6 */
8831 +
8832 +static inline
8833 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
8834 +{
8835 +       return 1;
8836 +}
8837 +
8838 +
8839 +static inline
8840 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8841 +{
8842 +       return 1;
8843 +}
8844 +
8845 +static inline
8846 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8847 +{
8848 +       return 1;
8849 +}
8850 +
8851 +static inline
8852 +int nx_info_has_v6(struct nx_info *nxi)
8853 +{
8854 +       return 0;
8855 +}
8856 +
8857 +#endif /* CONFIG_IPV6 */
8858 +
8859 +#define current_nx_info_has_v6() \
8860 +       nx_info_has_v6(current_nx_info())
8861 +
8862 +#else
8863 +#warning duplicate inclusion
8864 +#endif
8865 diff -NurpP --minimal linux-3.13.10/include/linux/vs_limit.h linux-3.13.10-vs2.3.6.11/include/linux/vs_limit.h
8866 --- linux-3.13.10/include/linux/vs_limit.h      1970-01-01 00:00:00.000000000 +0000
8867 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_limit.h   2014-02-01 01:29:43.000000000 +0000
8868 @@ -0,0 +1,140 @@
8869 +#ifndef _VS_LIMIT_H
8870 +#define _VS_LIMIT_H
8871 +
8872 +#include "vserver/limit.h"
8873 +#include "vserver/base.h"
8874 +#include "vserver/context.h"
8875 +#include "vserver/debug.h"
8876 +#include "vserver/context.h"
8877 +#include "vserver/limit_int.h"
8878 +
8879 +
8880 +#define vx_acc_cres(v, d, p, r) \
8881 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
8882 +
8883 +#define vx_acc_cres_cond(x, d, p, r) \
8884 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8885 +       r, d, p, __FILE__, __LINE__)
8886 +
8887 +
8888 +#define vx_add_cres(v, a, p, r) \
8889 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
8890 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
8891 +
8892 +#define vx_add_cres_cond(x, a, p, r) \
8893 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8894 +       r, a, p, __FILE__, __LINE__)
8895 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
8896 +
8897 +
8898 +/* process and file limits */
8899 +
8900 +#define vx_nproc_inc(p) \
8901 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
8902 +
8903 +#define vx_nproc_dec(p) \
8904 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
8905 +
8906 +#define vx_files_inc(f) \
8907 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
8908 +
8909 +#define vx_files_dec(f) \
8910 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
8911 +
8912 +#define vx_locks_inc(l) \
8913 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
8914 +
8915 +#define vx_locks_dec(l) \
8916 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
8917 +
8918 +#define vx_openfd_inc(f) \
8919 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
8920 +
8921 +#define vx_openfd_dec(f) \
8922 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
8923 +
8924 +
8925 +#define vx_cres_avail(v, n, r) \
8926 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
8927 +
8928 +
8929 +#define vx_nproc_avail(n) \
8930 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
8931 +
8932 +#define vx_files_avail(n) \
8933 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
8934 +
8935 +#define vx_locks_avail(n) \
8936 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
8937 +
8938 +#define vx_openfd_avail(n) \
8939 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
8940 +
8941 +
8942 +/* dentry limits */
8943 +
8944 +#define vx_dentry_inc(d) do {                                          \
8945 +       if (d_count(d) == 1)                                            \
8946 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
8947 +       } while (0)
8948 +
8949 +#define vx_dentry_dec(d) do {                                          \
8950 +       if (d_count(d) == 0)                                            \
8951 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
8952 +       } while (0)
8953 +
8954 +#define vx_dentry_avail(n) \
8955 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
8956 +
8957 +
8958 +/* socket limits */
8959 +
8960 +#define vx_sock_inc(s) \
8961 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
8962 +
8963 +#define vx_sock_dec(s) \
8964 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
8965 +
8966 +#define vx_sock_avail(n) \
8967 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
8968 +
8969 +
8970 +/* ipc resource limits */
8971 +
8972 +#define vx_ipcmsg_add(v, u, a) \
8973 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
8974 +
8975 +#define vx_ipcmsg_sub(v, u, a) \
8976 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
8977 +
8978 +#define vx_ipcmsg_avail(v, a) \
8979 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
8980 +
8981 +
8982 +#define vx_ipcshm_add(v, k, a) \
8983 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8984 +
8985 +#define vx_ipcshm_sub(v, k, a) \
8986 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8987 +
8988 +#define vx_ipcshm_avail(v, a) \
8989 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
8990 +
8991 +
8992 +#define vx_semary_inc(a) \
8993 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
8994 +
8995 +#define vx_semary_dec(a) \
8996 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
8997 +
8998 +
8999 +#define vx_nsems_add(a,n) \
9000 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9001 +
9002 +#define vx_nsems_sub(a,n) \
9003 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9004 +
9005 +
9006 +#else
9007 +#warning duplicate inclusion
9008 +#endif
9009 diff -NurpP --minimal linux-3.13.10/include/linux/vs_network.h linux-3.13.10-vs2.3.6.11/include/linux/vs_network.h
9010 --- linux-3.13.10/include/linux/vs_network.h    1970-01-01 00:00:00.000000000 +0000
9011 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_network.h 2014-01-31 20:38:03.000000000 +0000
9012 @@ -0,0 +1,169 @@
9013 +#ifndef _NX_VS_NETWORK_H
9014 +#define _NX_VS_NETWORK_H
9015 +
9016 +#include "vserver/context.h"
9017 +#include "vserver/network.h"
9018 +#include "vserver/base.h"
9019 +#include "vserver/check.h"
9020 +#include "vserver/debug.h"
9021 +
9022 +#include <linux/sched.h>
9023 +
9024 +
9025 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9026 +
9027 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9028 +       const char *_file, int _line)
9029 +{
9030 +       if (!nxi)
9031 +               return NULL;
9032 +
9033 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9034 +               nxi, nxi ? nxi->nx_id : 0,
9035 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9036 +               _file, _line);
9037 +
9038 +       atomic_inc(&nxi->nx_usecnt);
9039 +       return nxi;
9040 +}
9041 +
9042 +
9043 +extern void free_nx_info(struct nx_info *);
9044 +
9045 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9046 +
9047 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9048 +{
9049 +       if (!nxi)
9050 +               return;
9051 +
9052 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9053 +               nxi, nxi ? nxi->nx_id : 0,
9054 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9055 +               _file, _line);
9056 +
9057 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9058 +               free_nx_info(nxi);
9059 +}
9060 +
9061 +
9062 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9063 +
9064 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9065 +               const char *_file, int _line)
9066 +{
9067 +       if (nxi) {
9068 +               vxlprintk(VXD_CBIT(nid, 3),
9069 +                       "init_nx_info(%p[#%d.%d])",
9070 +                       nxi, nxi ? nxi->nx_id : 0,
9071 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9072 +                       _file, _line);
9073 +
9074 +               atomic_inc(&nxi->nx_usecnt);
9075 +       }
9076 +       *nxp = nxi;
9077 +}
9078 +
9079 +
9080 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9081 +
9082 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9083 +       const char *_file, int _line)
9084 +{
9085 +       struct nx_info *nxo;
9086 +
9087 +       if (!nxi)
9088 +               return;
9089 +
9090 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9091 +               nxi, nxi ? nxi->nx_id : 0,
9092 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9093 +               _file, _line);
9094 +
9095 +       atomic_inc(&nxi->nx_usecnt);
9096 +       nxo = xchg(nxp, nxi);
9097 +       BUG_ON(nxo);
9098 +}
9099 +
9100 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9101 +
9102 +static inline void __clr_nx_info(struct nx_info **nxp,
9103 +       const char *_file, int _line)
9104 +{
9105 +       struct nx_info *nxo;
9106 +
9107 +       nxo = xchg(nxp, NULL);
9108 +       if (!nxo)
9109 +               return;
9110 +
9111 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9112 +               nxo, nxo ? nxo->nx_id : 0,
9113 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9114 +               _file, _line);
9115 +
9116 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
9117 +               free_nx_info(nxo);
9118 +}
9119 +
9120 +
9121 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9122 +
9123 +static inline void __claim_nx_info(struct nx_info *nxi,
9124 +       struct task_struct *task, const char *_file, int _line)
9125 +{
9126 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9127 +               nxi, nxi ? nxi->nx_id : 0,
9128 +               nxi?atomic_read(&nxi->nx_usecnt):0,
9129 +               nxi?atomic_read(&nxi->nx_tasks):0,
9130 +               task, _file, _line);
9131 +
9132 +       atomic_inc(&nxi->nx_tasks);
9133 +}
9134 +
9135 +
9136 +extern void unhash_nx_info(struct nx_info *);
9137 +
9138 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9139 +
9140 +static inline void __release_nx_info(struct nx_info *nxi,
9141 +       struct task_struct *task, const char *_file, int _line)
9142 +{
9143 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9144 +               nxi, nxi ? nxi->nx_id : 0,
9145 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9146 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
9147 +               task, _file, _line);
9148 +
9149 +       might_sleep();
9150 +
9151 +       if (atomic_dec_and_test(&nxi->nx_tasks))
9152 +               unhash_nx_info(nxi);
9153 +}
9154 +
9155 +
9156 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
9157 +
9158 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9159 +       const char *_file, int _line)
9160 +{
9161 +       struct nx_info *nxi;
9162 +
9163 +       task_lock(p);
9164 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9165 +               p, _file, _line);
9166 +       nxi = __get_nx_info(p->nx_info, _file, _line);
9167 +       task_unlock(p);
9168 +       return nxi;
9169 +}
9170 +
9171 +
9172 +static inline void exit_nx_info(struct task_struct *p)
9173 +{
9174 +       if (p->nx_info)
9175 +               release_nx_info(p->nx_info, p);
9176 +}
9177 +
9178 +
9179 +#else
9180 +#warning duplicate inclusion
9181 +#endif
9182 diff -NurpP --minimal linux-3.13.10/include/linux/vs_pid.h linux-3.13.10-vs2.3.6.11/include/linux/vs_pid.h
9183 --- linux-3.13.10/include/linux/vs_pid.h        1970-01-01 00:00:00.000000000 +0000
9184 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_pid.h     2014-01-31 20:38:03.000000000 +0000
9185 @@ -0,0 +1,50 @@
9186 +#ifndef _VS_PID_H
9187 +#define _VS_PID_H
9188 +
9189 +#include "vserver/base.h"
9190 +#include "vserver/check.h"
9191 +#include "vserver/context.h"
9192 +#include "vserver/debug.h"
9193 +#include "vserver/pid.h"
9194 +#include <linux/pid_namespace.h>
9195 +
9196 +
9197 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
9198 +
9199 +static inline
9200 +int vx_proc_task_visible(struct task_struct *task)
9201 +{
9202 +       if ((task->pid == 1) &&
9203 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9204 +               /* show a blend through init */
9205 +               goto visible;
9206 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9207 +               goto visible;
9208 +       return 0;
9209 +visible:
9210 +       return 1;
9211 +}
9212 +
9213 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9214 +
9215 +
9216 +static inline
9217 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9218 +{
9219 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9220 +
9221 +       if (task && !vx_proc_task_visible(task)) {
9222 +               vxdprintk(VXD_CBIT(misc, 6),
9223 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9224 +                       task, task->xid, task->pid,
9225 +                       current, current->xid, current->pid);
9226 +               put_task_struct(task);
9227 +               task = NULL;
9228 +       }
9229 +       return task;
9230 +}
9231 +
9232 +
9233 +#else
9234 +#warning duplicate inclusion
9235 +#endif
9236 diff -NurpP --minimal linux-3.13.10/include/linux/vs_sched.h linux-3.13.10-vs2.3.6.11/include/linux/vs_sched.h
9237 --- linux-3.13.10/include/linux/vs_sched.h      1970-01-01 00:00:00.000000000 +0000
9238 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_sched.h   2014-01-31 20:38:03.000000000 +0000
9239 @@ -0,0 +1,40 @@
9240 +#ifndef _VS_SCHED_H
9241 +#define _VS_SCHED_H
9242 +
9243 +#include "vserver/base.h"
9244 +#include "vserver/context.h"
9245 +#include "vserver/sched.h"
9246 +
9247 +
9248 +#define MAX_PRIO_BIAS           20
9249 +#define MIN_PRIO_BIAS          -20
9250 +
9251 +static inline
9252 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
9253 +{
9254 +       struct vx_info *vxi = p->vx_info;
9255 +
9256 +       if (vxi)
9257 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
9258 +       return prio;
9259 +}
9260 +
9261 +static inline void vx_account_user(struct vx_info *vxi,
9262 +       cputime_t cputime, int nice)
9263 +{
9264 +       if (!vxi)
9265 +               return;
9266 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
9267 +}
9268 +
9269 +static inline void vx_account_system(struct vx_info *vxi,
9270 +       cputime_t cputime, int idle)
9271 +{
9272 +       if (!vxi)
9273 +               return;
9274 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
9275 +}
9276 +
9277 +#else
9278 +#warning duplicate inclusion
9279 +#endif
9280 diff -NurpP --minimal linux-3.13.10/include/linux/vs_socket.h linux-3.13.10-vs2.3.6.11/include/linux/vs_socket.h
9281 --- linux-3.13.10/include/linux/vs_socket.h     1970-01-01 00:00:00.000000000 +0000
9282 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_socket.h  2014-01-31 20:38:03.000000000 +0000
9283 @@ -0,0 +1,67 @@
9284 +#ifndef _VS_SOCKET_H
9285 +#define _VS_SOCKET_H
9286 +
9287 +#include "vserver/debug.h"
9288 +#include "vserver/base.h"
9289 +#include "vserver/cacct.h"
9290 +#include "vserver/context.h"
9291 +#include "vserver/tag.h"
9292 +
9293 +
9294 +/* socket accounting */
9295 +
9296 +#include <linux/socket.h>
9297 +
9298 +static inline int vx_sock_type(int family)
9299 +{
9300 +       switch (family) {
9301 +       case PF_UNSPEC:
9302 +               return VXA_SOCK_UNSPEC;
9303 +       case PF_UNIX:
9304 +               return VXA_SOCK_UNIX;
9305 +       case PF_INET:
9306 +               return VXA_SOCK_INET;
9307 +       case PF_INET6:
9308 +               return VXA_SOCK_INET6;
9309 +       case PF_PACKET:
9310 +               return VXA_SOCK_PACKET;
9311 +       default:
9312 +               return VXA_SOCK_OTHER;
9313 +       }
9314 +}
9315 +
9316 +#define vx_acc_sock(v, f, p, s) \
9317 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
9318 +
9319 +static inline void __vx_acc_sock(struct vx_info *vxi,
9320 +       int family, int pos, int size, char *file, int line)
9321 +{
9322 +       if (vxi) {
9323 +               int type = vx_sock_type(family);
9324 +
9325 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
9326 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
9327 +       }
9328 +}
9329 +
9330 +#define vx_sock_recv(sk, s) \
9331 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
9332 +#define vx_sock_send(sk, s) \
9333 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
9334 +#define vx_sock_fail(sk, s) \
9335 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
9336 +
9337 +
9338 +#define sock_vx_init(s) do {           \
9339 +       (s)->sk_xid = 0;                \
9340 +       (s)->sk_vx_info = NULL;         \
9341 +       } while (0)
9342 +
9343 +#define sock_nx_init(s) do {           \
9344 +       (s)->sk_nid = 0;                \
9345 +       (s)->sk_nx_info = NULL;         \
9346 +       } while (0)
9347 +
9348 +#else
9349 +#warning duplicate inclusion
9350 +#endif
9351 diff -NurpP --minimal linux-3.13.10/include/linux/vs_tag.h linux-3.13.10-vs2.3.6.11/include/linux/vs_tag.h
9352 --- linux-3.13.10/include/linux/vs_tag.h        1970-01-01 00:00:00.000000000 +0000
9353 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_tag.h     2014-01-31 20:38:03.000000000 +0000
9354 @@ -0,0 +1,47 @@
9355 +#ifndef _VS_TAG_H
9356 +#define _VS_TAG_H
9357 +
9358 +#include <linux/vserver/tag.h>
9359 +
9360 +/* check conditions */
9361 +
9362 +#define DX_ADMIN       0x0001
9363 +#define DX_WATCH       0x0002
9364 +#define DX_HOSTID      0x0008
9365 +
9366 +#define DX_IDENT       0x0010
9367 +
9368 +#define DX_ARG_MASK    0x0010
9369 +
9370 +
9371 +#define dx_task_tag(t) ((t)->tag)
9372 +
9373 +#define dx_current_tag() dx_task_tag(current)
9374 +
9375 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
9376 +
9377 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
9378 +
9379 +
9380 +/*
9381 + * check current context for ADMIN/WATCH and
9382 + * optionally against supplied argument
9383 + */
9384 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
9385 +{
9386 +       if (mode & DX_ARG_MASK) {
9387 +               if ((mode & DX_IDENT) && (id == cid))
9388 +                       return 1;
9389 +       }
9390 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
9391 +               ((mode & DX_WATCH) && (cid == 1)) ||
9392 +               ((mode & DX_HOSTID) && (id == 0)));
9393 +}
9394 +
9395 +struct inode;
9396 +int dx_permission(const struct inode *inode, int mask);
9397 +
9398 +
9399 +#else
9400 +#warning duplicate inclusion
9401 +#endif
9402 diff -NurpP --minimal linux-3.13.10/include/linux/vs_time.h linux-3.13.10-vs2.3.6.11/include/linux/vs_time.h
9403 --- linux-3.13.10/include/linux/vs_time.h       1970-01-01 00:00:00.000000000 +0000
9404 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_time.h    2014-01-31 20:38:03.000000000 +0000
9405 @@ -0,0 +1,19 @@
9406 +#ifndef _VS_TIME_H
9407 +#define _VS_TIME_H
9408 +
9409 +
9410 +/* time faking stuff */
9411 +
9412 +#ifdef CONFIG_VSERVER_VTIME
9413 +
9414 +extern void vx_adjust_timespec(struct timespec *ts);
9415 +extern int vx_settimeofday(const struct timespec *ts);
9416 +
9417 +#else
9418 +#define        vx_adjust_timespec(t)   do { } while (0)
9419 +#define        vx_settimeofday(t)      do_settimeofday(t)
9420 +#endif
9421 +
9422 +#else
9423 +#warning duplicate inclusion
9424 +#endif
9425 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/base.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/base.h
9426 --- linux-3.13.10/include/linux/vserver/base.h  1970-01-01 00:00:00.000000000 +0000
9427 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/base.h       2014-01-31 20:38:03.000000000 +0000
9428 @@ -0,0 +1,184 @@
9429 +#ifndef _VSERVER_BASE_H
9430 +#define _VSERVER_BASE_H
9431 +
9432 +
9433 +/* context state changes */
9434 +
9435 +enum {
9436 +       VSC_STARTUP = 1,
9437 +       VSC_SHUTDOWN,
9438 +
9439 +       VSC_NETUP,
9440 +       VSC_NETDOWN,
9441 +};
9442 +
9443 +
9444 +
9445 +#define vx_task_xid(t) ((t)->xid)
9446 +
9447 +#define vx_current_xid() vx_task_xid(current)
9448 +
9449 +#define current_vx_info() (current->vx_info)
9450 +
9451 +
9452 +#define nx_task_nid(t) ((t)->nid)
9453 +
9454 +#define nx_current_nid() nx_task_nid(current)
9455 +
9456 +#define current_nx_info() (current->nx_info)
9457 +
9458 +
9459 +/* generic flag merging */
9460 +
9461 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
9462 +
9463 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
9464 +
9465 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
9466 +
9467 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
9468 +
9469 +
9470 +/* context flags */
9471 +
9472 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
9473 +
9474 +#define vx_current_flags()     __vx_flags(current_vx_info())
9475 +
9476 +#define vx_info_flags(v, m, f) \
9477 +       vs_check_flags(__vx_flags(v), m, f)
9478 +
9479 +#define task_vx_flags(t, m, f) \
9480 +       ((t) && vx_info_flags((t)->vx_info, m, f))
9481 +
9482 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
9483 +
9484 +
9485 +/* context caps */
9486 +
9487 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
9488 +
9489 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
9490 +
9491 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
9492 +
9493 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
9494 +
9495 +
9496 +
9497 +/* network flags */
9498 +
9499 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
9500 +
9501 +#define nx_current_flags()     __nx_flags(current_nx_info())
9502 +
9503 +#define nx_info_flags(n, m, f) \
9504 +       vs_check_flags(__nx_flags(n), m, f)
9505 +
9506 +#define task_nx_flags(t, m, f) \
9507 +       ((t) && nx_info_flags((t)->nx_info, m, f))
9508 +
9509 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
9510 +
9511 +
9512 +/* network caps */
9513 +
9514 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
9515 +
9516 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
9517 +
9518 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
9519 +
9520 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
9521 +
9522 +
9523 +/* context mask capabilities */
9524 +
9525 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
9526 +
9527 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
9528 +
9529 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
9530 +
9531 +
9532 +/* context bcap mask */
9533 +
9534 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
9535 +
9536 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
9537 +
9538 +
9539 +/* mask given bcaps */
9540 +
9541 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
9542 +
9543 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
9544 +
9545 +
9546 +/* masked cap_bset */
9547 +
9548 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
9549 +
9550 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
9551 +
9552 +#if 0
9553 +#define vx_info_mbcap(v, b) \
9554 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
9555 +       vx_info_bcaps(v, b) : (b))
9556 +
9557 +#define task_vx_mbcap(t, b) \
9558 +       vx_info_mbcap((t)->vx_info, (t)->b)
9559 +
9560 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
9561 +#endif
9562 +
9563 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
9564 +
9565 +#define vx_capable(b, c) (capable(b) || \
9566 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9567 +
9568 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
9569 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
9570 +
9571 +#define nx_capable(b, c) (capable(b) || \
9572 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9573 +
9574 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
9575 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
9576 +
9577 +#define vx_task_initpid(t, n) \
9578 +       ((t)->vx_info && \
9579 +       ((t)->vx_info->vx_initpid == (n)))
9580 +
9581 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
9582 +
9583 +
9584 +/* context unshare mask */
9585 +
9586 +#define __vx_umask(v)          ((v)->vx_umask)
9587 +
9588 +#define vx_current_umask()     __vx_umask(current_vx_info())
9589 +
9590 +#define vx_can_unshare(b, f) (capable(b) || \
9591 +       (cap_raised(current_cap(), b) && \
9592 +       !((f) & ~vx_current_umask())))
9593 +
9594 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
9595 +       (cap_raised(current_cap(), b) && \
9596 +       !((f) & ~vx_current_umask())))
9597 +
9598 +#define __vx_wmask(v)          ((v)->vx_wmask)
9599 +
9600 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
9601 +
9602 +
9603 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
9604 +
9605 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
9606 +
9607 +
9608 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
9609 +
9610 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
9611 +
9612 +#endif
9613 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct.h
9614 --- linux-3.13.10/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
9615 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct.h      2014-01-31 20:38:03.000000000 +0000
9616 @@ -0,0 +1,15 @@
9617 +#ifndef _VSERVER_CACCT_H
9618 +#define _VSERVER_CACCT_H
9619 +
9620 +
9621 +enum sock_acc_field {
9622 +       VXA_SOCK_UNSPEC = 0,
9623 +       VXA_SOCK_UNIX,
9624 +       VXA_SOCK_INET,
9625 +       VXA_SOCK_INET6,
9626 +       VXA_SOCK_PACKET,
9627 +       VXA_SOCK_OTHER,
9628 +       VXA_SOCK_SIZE   /* array size */
9629 +};
9630 +
9631 +#endif /* _VSERVER_CACCT_H */
9632 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_cmd.h
9633 --- linux-3.13.10/include/linux/vserver/cacct_cmd.h     1970-01-01 00:00:00.000000000 +0000
9634 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_cmd.h  2014-01-31 20:38:03.000000000 +0000
9635 @@ -0,0 +1,10 @@
9636 +#ifndef _VSERVER_CACCT_CMD_H
9637 +#define _VSERVER_CACCT_CMD_H
9638 +
9639 +
9640 +#include <linux/compiler.h>
9641 +#include <uapi/vserver/cacct_cmd.h>
9642 +
9643 +extern int vc_sock_stat(struct vx_info *, void __user *);
9644 +
9645 +#endif /* _VSERVER_CACCT_CMD_H */
9646 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_def.h
9647 --- linux-3.13.10/include/linux/vserver/cacct_def.h     1970-01-01 00:00:00.000000000 +0000
9648 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_def.h  2014-01-31 20:38:03.000000000 +0000
9649 @@ -0,0 +1,43 @@
9650 +#ifndef _VSERVER_CACCT_DEF_H
9651 +#define _VSERVER_CACCT_DEF_H
9652 +
9653 +#include <asm/atomic.h>
9654 +#include <linux/vserver/cacct.h>
9655 +
9656 +
9657 +struct _vx_sock_acc {
9658 +       atomic_long_t count;
9659 +       atomic_long_t total;
9660 +};
9661 +
9662 +/* context sub struct */
9663 +
9664 +struct _vx_cacct {
9665 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
9666 +       atomic_t slab[8];
9667 +       atomic_t page[6][8];
9668 +};
9669 +
9670 +#ifdef CONFIG_VSERVER_DEBUG
9671 +
9672 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
9673 +{
9674 +       int i, j;
9675 +
9676 +       printk("\t_vx_cacct:");
9677 +       for (i = 0; i < 6; i++) {
9678 +               struct _vx_sock_acc *ptr = cacct->sock[i];
9679 +
9680 +               printk("\t [%d] =", i);
9681 +               for (j = 0; j < 3; j++) {
9682 +                       printk(" [%d] = %8lu, %8lu", j,
9683 +                               atomic_long_read(&ptr[j].count),
9684 +                               atomic_long_read(&ptr[j].total));
9685 +               }
9686 +               printk("\n");
9687 +       }
9688 +}
9689 +
9690 +#endif
9691 +
9692 +#endif /* _VSERVER_CACCT_DEF_H */
9693 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct_int.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_int.h
9694 --- linux-3.13.10/include/linux/vserver/cacct_int.h     1970-01-01 00:00:00.000000000 +0000
9695 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_int.h  2014-01-31 20:38:03.000000000 +0000
9696 @@ -0,0 +1,17 @@
9697 +#ifndef _VSERVER_CACCT_INT_H
9698 +#define _VSERVER_CACCT_INT_H
9699 +
9700 +static inline
9701 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
9702 +{
9703 +       return atomic_long_read(&cacct->sock[type][pos].count);
9704 +}
9705 +
9706 +
9707 +static inline
9708 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
9709 +{
9710 +       return atomic_long_read(&cacct->sock[type][pos].total);
9711 +}
9712 +
9713 +#endif /* _VSERVER_CACCT_INT_H */
9714 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/check.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/check.h
9715 --- linux-3.13.10/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
9716 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/check.h      2014-01-31 20:38:03.000000000 +0000
9717 @@ -0,0 +1,89 @@
9718 +#ifndef _VSERVER_CHECK_H
9719 +#define _VSERVER_CHECK_H
9720 +
9721 +
9722 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
9723 +
9724 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
9725 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
9726 +#else
9727 +#define MIN_D_CONTEXT  65536
9728 +#endif
9729 +
9730 +/* check conditions */
9731 +
9732 +#define VS_ADMIN       0x0001
9733 +#define VS_WATCH       0x0002
9734 +#define VS_HIDE                0x0004
9735 +#define VS_HOSTID      0x0008
9736 +
9737 +#define VS_IDENT       0x0010
9738 +#define VS_EQUIV       0x0020
9739 +#define VS_PARENT      0x0040
9740 +#define VS_CHILD       0x0080
9741 +
9742 +#define VS_ARG_MASK    0x00F0
9743 +
9744 +#define VS_DYNAMIC     0x0100
9745 +#define VS_STATIC      0x0200
9746 +
9747 +#define VS_ATR_MASK    0x0F00
9748 +
9749 +#ifdef CONFIG_VSERVER_PRIVACY
9750 +#define VS_ADMIN_P     (0)
9751 +#define VS_WATCH_P     (0)
9752 +#else
9753 +#define VS_ADMIN_P     VS_ADMIN
9754 +#define VS_WATCH_P     VS_WATCH
9755 +#endif
9756 +
9757 +#define VS_HARDIRQ     0x1000
9758 +#define VS_SOFTIRQ     0x2000
9759 +#define VS_IRQ         0x4000
9760 +
9761 +#define VS_IRQ_MASK    0xF000
9762 +
9763 +#include <linux/hardirq.h>
9764 +
9765 +/*
9766 + * check current context for ADMIN/WATCH and
9767 + * optionally against supplied argument
9768 + */
9769 +static inline int __vs_check(int cid, int id, unsigned int mode)
9770 +{
9771 +       if (mode & VS_ARG_MASK) {
9772 +               if ((mode & VS_IDENT) && (id == cid))
9773 +                       return 1;
9774 +       }
9775 +       if (mode & VS_ATR_MASK) {
9776 +               if ((mode & VS_DYNAMIC) &&
9777 +                       (id >= MIN_D_CONTEXT) &&
9778 +                       (id <= MAX_S_CONTEXT))
9779 +                       return 1;
9780 +               if ((mode & VS_STATIC) &&
9781 +                       (id > 1) && (id < MIN_D_CONTEXT))
9782 +                       return 1;
9783 +       }
9784 +       if (mode & VS_IRQ_MASK) {
9785 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
9786 +                       return 1;
9787 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
9788 +                       return 1;
9789 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
9790 +                       return 1;
9791 +       }
9792 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
9793 +               ((mode & VS_WATCH) && (cid == 1)) ||
9794 +               ((mode & VS_HOSTID) && (id == 0)));
9795 +}
9796 +
9797 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
9798 +
9799 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
9800 +
9801 +
9802 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
9803 +
9804 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
9805 +
9806 +#endif
9807 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/context.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/context.h
9808 --- linux-3.13.10/include/linux/vserver/context.h       1970-01-01 00:00:00.000000000 +0000
9809 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/context.h    2014-01-31 20:38:03.000000000 +0000
9810 @@ -0,0 +1,110 @@
9811 +#ifndef _VSERVER_CONTEXT_H
9812 +#define _VSERVER_CONTEXT_H
9813 +
9814 +
9815 +#include <linux/list.h>
9816 +#include <linux/spinlock.h>
9817 +#include <linux/rcupdate.h>
9818 +#include <uapi/vserver/context.h>
9819 +
9820 +#include "limit_def.h"
9821 +#include "sched_def.h"
9822 +#include "cvirt_def.h"
9823 +#include "cacct_def.h"
9824 +#include "device_def.h"
9825 +
9826 +#define VX_SPACES      2
9827 +
9828 +struct _vx_info_pc {
9829 +       struct _vx_sched_pc sched_pc;
9830 +       struct _vx_cvirt_pc cvirt_pc;
9831 +};
9832 +
9833 +struct _vx_space {
9834 +       unsigned long vx_nsmask;                /* assignment mask */
9835 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
9836 +       struct fs_struct *vx_fs;                /* private namespace fs */
9837 +       const struct cred *vx_cred;             /* task credentials */
9838 +};
9839 +
9840 +struct vx_info {
9841 +       struct hlist_node vx_hlist;             /* linked list of contexts */
9842 +       vxid_t vx_id;                           /* context id */
9843 +       atomic_t vx_usecnt;                     /* usage count */
9844 +       atomic_t vx_tasks;                      /* tasks count */
9845 +       struct vx_info *vx_parent;              /* parent context */
9846 +       int vx_state;                           /* context state */
9847 +
9848 +       struct _vx_space space[VX_SPACES];      /* namespace store */
9849 +
9850 +       uint64_t vx_flags;                      /* context flags */
9851 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
9852 +       uint64_t vx_umask;                      /* unshare mask (guest) */
9853 +       uint64_t vx_wmask;                      /* warn mask (guest) */
9854 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
9855 +
9856 +       struct task_struct *vx_reaper;          /* guest reaper process */
9857 +       pid_t vx_initpid;                       /* PID of guest init */
9858 +       int64_t vx_badness_bias;                /* OOM points bias */
9859 +
9860 +       struct _vx_limit limit;                 /* vserver limits */
9861 +       struct _vx_sched sched;                 /* vserver scheduler */
9862 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
9863 +       struct _vx_cacct cacct;                 /* context accounting */
9864 +
9865 +       struct _vx_device dmap;                 /* default device map targets */
9866 +
9867 +#ifndef CONFIG_SMP
9868 +       struct _vx_info_pc info_pc;             /* per cpu data */
9869 +#else
9870 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
9871 +#endif
9872 +
9873 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
9874 +       int reboot_cmd;                         /* last sys_reboot() cmd */
9875 +       int exit_code;                          /* last process exit code */
9876 +
9877 +       char vx_name[65];                       /* vserver name */
9878 +};
9879 +
9880 +#ifndef CONFIG_SMP
9881 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
9882 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
9883 +#else
9884 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
9885 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
9886 +#endif
9887 +
9888 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
9889 +
9890 +
9891 +struct vx_info_save {
9892 +       struct vx_info *vxi;
9893 +       vxid_t xid;
9894 +};
9895 +
9896 +
9897 +/* status flags */
9898 +
9899 +#define VXS_HASHED     0x0001
9900 +#define VXS_PAUSED     0x0010
9901 +#define VXS_SHUTDOWN   0x0100
9902 +#define VXS_HELPER     0x1000
9903 +#define VXS_RELEASED   0x8000
9904 +
9905 +
9906 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
9907 +extern void release_vx_info(struct vx_info *, struct task_struct *);
9908 +
9909 +extern struct vx_info *lookup_vx_info(int);
9910 +extern struct vx_info *lookup_or_create_vx_info(int);
9911 +
9912 +extern int get_xid_list(int, unsigned int *, int);
9913 +extern int xid_is_hashed(vxid_t);
9914 +
9915 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
9916 +
9917 +extern long vs_state_change(struct vx_info *, unsigned int);
9918 +
9919 +
9920 +#endif /* _VSERVER_CONTEXT_H */
9921 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/context_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/context_cmd.h
9922 --- linux-3.13.10/include/linux/vserver/context_cmd.h   1970-01-01 00:00:00.000000000 +0000
9923 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/context_cmd.h        2014-01-31 20:38:03.000000000 +0000
9924 @@ -0,0 +1,33 @@
9925 +#ifndef _VSERVER_CONTEXT_CMD_H
9926 +#define _VSERVER_CONTEXT_CMD_H
9927 +
9928 +#include <uapi/vserver/context_cmd.h>
9929 +
9930 +extern int vc_task_xid(uint32_t);
9931 +
9932 +extern int vc_vx_info(struct vx_info *, void __user *);
9933 +
9934 +extern int vc_ctx_stat(struct vx_info *, void __user *);
9935 +
9936 +extern int vc_ctx_create(uint32_t, void __user *);
9937 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
9938 +
9939 +extern int vc_get_cflags(struct vx_info *, void __user *);
9940 +extern int vc_set_cflags(struct vx_info *, void __user *);
9941 +
9942 +extern int vc_get_ccaps(struct vx_info *, void __user *);
9943 +extern int vc_set_ccaps(struct vx_info *, void __user *);
9944 +
9945 +extern int vc_get_bcaps(struct vx_info *, void __user *);
9946 +extern int vc_set_bcaps(struct vx_info *, void __user *);
9947 +
9948 +extern int vc_get_umask(struct vx_info *, void __user *);
9949 +extern int vc_set_umask(struct vx_info *, void __user *);
9950 +
9951 +extern int vc_get_wmask(struct vx_info *, void __user *);
9952 +extern int vc_set_wmask(struct vx_info *, void __user *);
9953 +
9954 +extern int vc_get_badness(struct vx_info *, void __user *);
9955 +extern int vc_set_badness(struct vx_info *, void __user *);
9956 +
9957 +#endif /* _VSERVER_CONTEXT_CMD_H */
9958 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cvirt.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt.h
9959 --- linux-3.13.10/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
9960 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt.h      2014-01-31 20:38:03.000000000 +0000
9961 @@ -0,0 +1,18 @@
9962 +#ifndef _VSERVER_CVIRT_H
9963 +#define _VSERVER_CVIRT_H
9964 +
9965 +struct timespec;
9966 +
9967 +void vx_vsi_boottime(struct timespec *);
9968 +
9969 +void vx_vsi_uptime(struct timespec *, struct timespec *);
9970 +
9971 +
9972 +struct vx_info;
9973 +
9974 +void vx_update_load(struct vx_info *);
9975 +
9976 +
9977 +int vx_do_syslog(int, char __user *, int);
9978 +
9979 +#endif /* _VSERVER_CVIRT_H */
9980 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cvirt_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_cmd.h
9981 --- linux-3.13.10/include/linux/vserver/cvirt_cmd.h     1970-01-01 00:00:00.000000000 +0000
9982 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_cmd.h  2014-01-31 20:38:03.000000000 +0000
9983 @@ -0,0 +1,13 @@
9984 +#ifndef _VSERVER_CVIRT_CMD_H
9985 +#define _VSERVER_CVIRT_CMD_H
9986 +
9987 +
9988 +#include <linux/compiler.h>
9989 +#include <uapi/vserver/cvirt_cmd.h>
9990 +
9991 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
9992 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
9993 +
9994 +extern int vc_virt_stat(struct vx_info *, void __user *);
9995 +
9996 +#endif /* _VSERVER_CVIRT_CMD_H */
9997 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cvirt_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_def.h
9998 --- linux-3.13.10/include/linux/vserver/cvirt_def.h     1970-01-01 00:00:00.000000000 +0000
9999 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_def.h  2014-01-31 20:38:03.000000000 +0000
10000 @@ -0,0 +1,80 @@
10001 +#ifndef _VSERVER_CVIRT_DEF_H
10002 +#define _VSERVER_CVIRT_DEF_H
10003 +
10004 +#include <linux/jiffies.h>
10005 +#include <linux/spinlock.h>
10006 +#include <linux/wait.h>
10007 +#include <linux/time.h>
10008 +#include <asm/atomic.h>
10009 +
10010 +
10011 +struct _vx_usage_stat {
10012 +       uint64_t user;
10013 +       uint64_t nice;
10014 +       uint64_t system;
10015 +       uint64_t softirq;
10016 +       uint64_t irq;
10017 +       uint64_t idle;
10018 +       uint64_t iowait;
10019 +};
10020 +
10021 +struct _vx_syslog {
10022 +       wait_queue_head_t log_wait;
10023 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10024 +
10025 +       unsigned long log_start;        /* next char to be read by syslog() */
10026 +       unsigned long con_start;        /* next char to be sent to consoles */
10027 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10028 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10029 +
10030 +       char log_buf[1024];
10031 +};
10032 +
10033 +
10034 +/* context sub struct */
10035 +
10036 +struct _vx_cvirt {
10037 +       atomic_t nr_threads;            /* number of current threads */
10038 +       atomic_t nr_running;            /* number of running threads */
10039 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10040 +
10041 +       atomic_t nr_onhold;             /* processes on hold */
10042 +       uint32_t onhold_last;           /* jiffies when put on hold */
10043 +
10044 +       struct timespec bias_ts;        /* time offset to the host */
10045 +       struct timespec bias_idle;
10046 +       struct timespec bias_uptime;    /* context creation point */
10047 +       uint64_t bias_clock;            /* offset in clock_t */
10048 +
10049 +       spinlock_t load_lock;           /* lock for the load averages */
10050 +       atomic_t load_updates;          /* nr of load updates done so far */
10051 +       uint32_t load_last;             /* last time load was calculated */
10052 +       uint32_t load[3];               /* load averages 1,5,15 */
10053 +
10054 +       atomic_t total_forks;           /* number of forks so far */
10055 +
10056 +       struct _vx_syslog syslog;
10057 +};
10058 +
10059 +struct _vx_cvirt_pc {
10060 +       struct _vx_usage_stat cpustat;
10061 +};
10062 +
10063 +
10064 +#ifdef CONFIG_VSERVER_DEBUG
10065 +
10066 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10067 +{
10068 +       printk("\t_vx_cvirt:\n");
10069 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10070 +               atomic_read(&cvirt->nr_threads),
10071 +               atomic_read(&cvirt->nr_running),
10072 +               atomic_read(&cvirt->nr_uninterruptible),
10073 +               atomic_read(&cvirt->nr_onhold));
10074 +       /* add rest here */
10075 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10076 +}
10077 +
10078 +#endif
10079 +
10080 +#endif /* _VSERVER_CVIRT_DEF_H */
10081 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/debug.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug.h
10082 --- linux-3.13.10/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
10083 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug.h      2014-01-31 20:38:03.000000000 +0000
10084 @@ -0,0 +1,146 @@
10085 +#ifndef _VSERVER_DEBUG_H
10086 +#define _VSERVER_DEBUG_H
10087 +
10088 +
10089 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10090 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10091 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10092 +
10093 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10094 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10095 +#define VXF_DEV                "%p[%lu,%d:%d]"
10096 +
10097 +#if    defined(CONFIG_QUOTES_UTF8)
10098 +#define        VS_Q_LQM        "\xc2\xbb"
10099 +#define        VS_Q_RQM        "\xc2\xab"
10100 +#elif  defined(CONFIG_QUOTES_ASCII)
10101 +#define        VS_Q_LQM        "\x27"
10102 +#define        VS_Q_RQM        "\x27"
10103 +#else
10104 +#define        VS_Q_LQM        "\xbb"
10105 +#define        VS_Q_RQM        "\xab"
10106 +#endif
10107 +
10108 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
10109 +
10110 +
10111 +#define vxd_path(p)                                            \
10112 +       ({ static char _buffer[PATH_MAX];                       \
10113 +          d_path(p, _buffer, sizeof(_buffer)); })
10114 +
10115 +#define vxd_cond_path(n)                                       \
10116 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10117 +
10118 +
10119 +#ifdef CONFIG_VSERVER_DEBUG
10120 +
10121 +extern unsigned int vs_debug_switch;
10122 +extern unsigned int vs_debug_xid;
10123 +extern unsigned int vs_debug_nid;
10124 +extern unsigned int vs_debug_tag;
10125 +extern unsigned int vs_debug_net;
10126 +extern unsigned int vs_debug_limit;
10127 +extern unsigned int vs_debug_cres;
10128 +extern unsigned int vs_debug_dlim;
10129 +extern unsigned int vs_debug_quota;
10130 +extern unsigned int vs_debug_cvirt;
10131 +extern unsigned int vs_debug_space;
10132 +extern unsigned int vs_debug_perm;
10133 +extern unsigned int vs_debug_misc;
10134 +
10135 +
10136 +#define VX_LOGLEVEL    "vxD: "
10137 +#define VX_PROC_FMT    "%p: "
10138 +#define VX_PROCESS     current
10139 +
10140 +#define vxdprintk(c, f, x...)                                  \
10141 +       do {                                                    \
10142 +               if (c)                                          \
10143 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10144 +                               VX_PROCESS , ##x);              \
10145 +       } while (0)
10146 +
10147 +#define vxlprintk(c, f, x...)                                  \
10148 +       do {                                                    \
10149 +               if (c)                                          \
10150 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10151 +       } while (0)
10152 +
10153 +#define vxfprintk(c, f, x...)                                  \
10154 +       do {                                                    \
10155 +               if (c)                                          \
10156 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10157 +       } while (0)
10158 +
10159 +
10160 +struct vx_info;
10161 +
10162 +void dump_vx_info(struct vx_info *, int);
10163 +void dump_vx_info_inactive(int);
10164 +
10165 +#else  /* CONFIG_VSERVER_DEBUG */
10166 +
10167 +#define vs_debug_switch        0
10168 +#define vs_debug_xid   0
10169 +#define vs_debug_nid   0
10170 +#define vs_debug_tag   0
10171 +#define vs_debug_net   0
10172 +#define vs_debug_limit 0
10173 +#define vs_debug_cres  0
10174 +#define vs_debug_dlim  0
10175 +#define vs_debug_quota 0
10176 +#define vs_debug_cvirt 0
10177 +#define vs_debug_space 0
10178 +#define vs_debug_perm  0
10179 +#define vs_debug_misc  0
10180 +
10181 +#define vxdprintk(x...) do { } while (0)
10182 +#define vxlprintk(x...) do { } while (0)
10183 +#define vxfprintk(x...) do { } while (0)
10184 +
10185 +#endif /* CONFIG_VSERVER_DEBUG */
10186 +
10187 +
10188 +#ifdef CONFIG_VSERVER_WARN
10189 +
10190 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
10191 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10192 +#define VX_WARN_XID    "[xid #%u] "
10193 +#define VX_WARN_NID    "[nid #%u] "
10194 +#define VX_WARN_TAG    "[tag #%u] "
10195 +
10196 +#define vxwprintk(c, f, x...)                                  \
10197 +       do {                                                    \
10198 +               if (c)                                          \
10199 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
10200 +       } while (0)
10201 +
10202 +#else  /* CONFIG_VSERVER_WARN */
10203 +
10204 +#define vxwprintk(x...) do { } while (0)
10205 +
10206 +#endif /* CONFIG_VSERVER_WARN */
10207 +
10208 +#define vxwprintk_task(c, f, x...)                             \
10209 +       vxwprintk(c, VX_WARN_TASK f,                            \
10210 +               current->comm, current->pid,                    \
10211 +               current->xid, current->nid,                     \
10212 +               current->tag, ##x)
10213 +#define vxwprintk_xid(c, f, x...)                              \
10214 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
10215 +#define vxwprintk_nid(c, f, x...)                              \
10216 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
10217 +#define vxwprintk_tag(c, f, x...)                              \
10218 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10219 +
10220 +#ifdef CONFIG_VSERVER_DEBUG
10221 +#define vxd_assert_lock(l)     assert_spin_locked(l)
10222 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10223 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10224 +#else
10225 +#define vxd_assert_lock(l)     do { } while (0)
10226 +#define vxd_assert(c, f, x...) do { } while (0)
10227 +#endif
10228 +
10229 +
10230 +#endif /* _VSERVER_DEBUG_H */
10231 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/debug_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug_cmd.h
10232 --- linux-3.13.10/include/linux/vserver/debug_cmd.h     1970-01-01 00:00:00.000000000 +0000
10233 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug_cmd.h  2014-01-31 20:38:03.000000000 +0000
10234 @@ -0,0 +1,37 @@
10235 +#ifndef _VSERVER_DEBUG_CMD_H
10236 +#define _VSERVER_DEBUG_CMD_H
10237 +
10238 +#include <uapi/vserver/debug_cmd.h>
10239 +
10240 +
10241 +#ifdef CONFIG_COMPAT
10242 +
10243 +#include <asm/compat.h>
10244 +
10245 +struct vcmd_read_history_v0_x32 {
10246 +       uint32_t index;
10247 +       uint32_t count;
10248 +       compat_uptr_t data_ptr;
10249 +};
10250 +
10251 +struct vcmd_read_monitor_v0_x32 {
10252 +       uint32_t index;
10253 +       uint32_t count;
10254 +       compat_uptr_t data_ptr;
10255 +};
10256 +
10257 +#endif  /* CONFIG_COMPAT */
10258 +
10259 +extern int vc_dump_history(uint32_t);
10260 +
10261 +extern int vc_read_history(uint32_t, void __user *);
10262 +extern int vc_read_monitor(uint32_t, void __user *);
10263 +
10264 +#ifdef CONFIG_COMPAT
10265 +
10266 +extern int vc_read_history_x32(uint32_t, void __user *);
10267 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10268 +
10269 +#endif  /* CONFIG_COMPAT */
10270 +
10271 +#endif /* _VSERVER_DEBUG_CMD_H */
10272 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/device.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/device.h
10273 --- linux-3.13.10/include/linux/vserver/device.h        1970-01-01 00:00:00.000000000 +0000
10274 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device.h     2014-01-31 20:38:03.000000000 +0000
10275 @@ -0,0 +1,9 @@
10276 +#ifndef _VSERVER_DEVICE_H
10277 +#define _VSERVER_DEVICE_H
10278 +
10279 +
10280 +#include <uapi/vserver/device.h>
10281 +
10282 +#else  /* _VSERVER_DEVICE_H */
10283 +#warning duplicate inclusion
10284 +#endif /* _VSERVER_DEVICE_H */
10285 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/device_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_cmd.h
10286 --- linux-3.13.10/include/linux/vserver/device_cmd.h    1970-01-01 00:00:00.000000000 +0000
10287 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_cmd.h 2014-01-31 20:38:03.000000000 +0000
10288 @@ -0,0 +1,31 @@
10289 +#ifndef _VSERVER_DEVICE_CMD_H
10290 +#define _VSERVER_DEVICE_CMD_H
10291 +
10292 +#include <uapi/vserver/device_cmd.h>
10293 +
10294 +
10295 +#ifdef CONFIG_COMPAT
10296 +
10297 +#include <asm/compat.h>
10298 +
10299 +struct vcmd_set_mapping_v0_x32 {
10300 +       compat_uptr_t device_ptr;
10301 +       compat_uptr_t target_ptr;
10302 +       uint32_t flags;
10303 +};
10304 +
10305 +#endif /* CONFIG_COMPAT */
10306 +
10307 +#include <linux/compiler.h>
10308 +
10309 +extern int vc_set_mapping(struct vx_info *, void __user *);
10310 +extern int vc_unset_mapping(struct vx_info *, void __user *);
10311 +
10312 +#ifdef CONFIG_COMPAT
10313 +
10314 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
10315 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
10316 +
10317 +#endif /* CONFIG_COMPAT */
10318 +
10319 +#endif /* _VSERVER_DEVICE_CMD_H */
10320 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/device_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_def.h
10321 --- linux-3.13.10/include/linux/vserver/device_def.h    1970-01-01 00:00:00.000000000 +0000
10322 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_def.h 2014-01-31 20:38:03.000000000 +0000
10323 @@ -0,0 +1,17 @@
10324 +#ifndef _VSERVER_DEVICE_DEF_H
10325 +#define _VSERVER_DEVICE_DEF_H
10326 +
10327 +#include <linux/types.h>
10328 +
10329 +struct vx_dmap_target {
10330 +       dev_t target;
10331 +       uint32_t flags;
10332 +};
10333 +
10334 +struct _vx_device {
10335 +#ifdef CONFIG_VSERVER_DEVICE
10336 +       struct vx_dmap_target targets[2];
10337 +#endif
10338 +};
10339 +
10340 +#endif /* _VSERVER_DEVICE_DEF_H */
10341 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/dlimit.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit.h
10342 --- linux-3.13.10/include/linux/vserver/dlimit.h        1970-01-01 00:00:00.000000000 +0000
10343 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit.h     2014-01-31 20:38:03.000000000 +0000
10344 @@ -0,0 +1,54 @@
10345 +#ifndef _VSERVER_DLIMIT_H
10346 +#define _VSERVER_DLIMIT_H
10347 +
10348 +#include "switch.h"
10349 +
10350 +
10351 +#ifdef __KERNEL__
10352 +
10353 +/*      keep in sync with CDLIM_INFINITY       */
10354 +
10355 +#define DLIM_INFINITY          (~0ULL)
10356 +
10357 +#include <linux/spinlock.h>
10358 +#include <linux/rcupdate.h>
10359 +
10360 +struct super_block;
10361 +
10362 +struct dl_info {
10363 +       struct hlist_node dl_hlist;             /* linked list of contexts */
10364 +       struct rcu_head dl_rcu;                 /* the rcu head */
10365 +       vtag_t dl_tag;                          /* context tag */
10366 +       atomic_t dl_usecnt;                     /* usage count */
10367 +       atomic_t dl_refcnt;                     /* reference count */
10368 +
10369 +       struct super_block *dl_sb;              /* associated superblock */
10370 +
10371 +       spinlock_t dl_lock;                     /* protect the values */
10372 +
10373 +       unsigned long long dl_space_used;       /* used space in bytes */
10374 +       unsigned long long dl_space_total;      /* maximum space in bytes */
10375 +       unsigned long dl_inodes_used;           /* used inodes */
10376 +       unsigned long dl_inodes_total;          /* maximum inodes */
10377 +
10378 +       unsigned int dl_nrlmult;                /* non root limit mult */
10379 +};
10380 +
10381 +struct rcu_head;
10382 +
10383 +extern void rcu_free_dl_info(struct rcu_head *);
10384 +extern void unhash_dl_info(struct dl_info *);
10385 +
10386 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
10387 +
10388 +
10389 +struct kstatfs;
10390 +
10391 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
10392 +
10393 +typedef uint64_t dlsize_t;
10394 +
10395 +#endif /* __KERNEL__ */
10396 +#else  /* _VSERVER_DLIMIT_H */
10397 +#warning duplicate inclusion
10398 +#endif /* _VSERVER_DLIMIT_H */
10399 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/dlimit_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit_cmd.h
10400 --- linux-3.13.10/include/linux/vserver/dlimit_cmd.h    1970-01-01 00:00:00.000000000 +0000
10401 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit_cmd.h 2014-01-31 20:38:03.000000000 +0000
10402 @@ -0,0 +1,46 @@
10403 +#ifndef _VSERVER_DLIMIT_CMD_H
10404 +#define _VSERVER_DLIMIT_CMD_H
10405 +
10406 +#include <uapi/vserver/dlimit_cmd.h>
10407 +
10408 +
10409 +#ifdef CONFIG_COMPAT
10410 +
10411 +#include <asm/compat.h>
10412 +
10413 +struct vcmd_ctx_dlimit_base_v0_x32 {
10414 +       compat_uptr_t name_ptr;
10415 +       uint32_t flags;
10416 +};
10417 +
10418 +struct vcmd_ctx_dlimit_v0_x32 {
10419 +       compat_uptr_t name_ptr;
10420 +       uint32_t space_used;                    /* used space in kbytes */
10421 +       uint32_t space_total;                   /* maximum space in kbytes */
10422 +       uint32_t inodes_used;                   /* used inodes */
10423 +       uint32_t inodes_total;                  /* maximum inodes */
10424 +       uint32_t reserved;                      /* reserved for root in % */
10425 +       uint32_t flags;
10426 +};
10427 +
10428 +#endif /* CONFIG_COMPAT */
10429 +
10430 +#include <linux/compiler.h>
10431 +
10432 +extern int vc_add_dlimit(uint32_t, void __user *);
10433 +extern int vc_rem_dlimit(uint32_t, void __user *);
10434 +
10435 +extern int vc_set_dlimit(uint32_t, void __user *);
10436 +extern int vc_get_dlimit(uint32_t, void __user *);
10437 +
10438 +#ifdef CONFIG_COMPAT
10439 +
10440 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
10441 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
10442 +
10443 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
10444 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
10445 +
10446 +#endif /* CONFIG_COMPAT */
10447 +
10448 +#endif /* _VSERVER_DLIMIT_CMD_H */
10449 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/global.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/global.h
10450 --- linux-3.13.10/include/linux/vserver/global.h        1970-01-01 00:00:00.000000000 +0000
10451 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/global.h     2014-01-31 20:38:03.000000000 +0000
10452 @@ -0,0 +1,19 @@
10453 +#ifndef _VSERVER_GLOBAL_H
10454 +#define _VSERVER_GLOBAL_H
10455 +
10456 +
10457 +extern atomic_t vx_global_ctotal;
10458 +extern atomic_t vx_global_cactive;
10459 +
10460 +extern atomic_t nx_global_ctotal;
10461 +extern atomic_t nx_global_cactive;
10462 +
10463 +extern atomic_t vs_global_nsproxy;
10464 +extern atomic_t vs_global_fs;
10465 +extern atomic_t vs_global_mnt_ns;
10466 +extern atomic_t vs_global_uts_ns;
10467 +extern atomic_t vs_global_user_ns;
10468 +extern atomic_t vs_global_pid_ns;
10469 +
10470 +
10471 +#endif /* _VSERVER_GLOBAL_H */
10472 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/history.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/history.h
10473 --- linux-3.13.10/include/linux/vserver/history.h       1970-01-01 00:00:00.000000000 +0000
10474 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/history.h    2014-01-31 20:38:03.000000000 +0000
10475 @@ -0,0 +1,197 @@
10476 +#ifndef _VSERVER_HISTORY_H
10477 +#define _VSERVER_HISTORY_H
10478 +
10479 +
10480 +enum {
10481 +       VXH_UNUSED = 0,
10482 +       VXH_THROW_OOPS = 1,
10483 +
10484 +       VXH_GET_VX_INFO,
10485 +       VXH_PUT_VX_INFO,
10486 +       VXH_INIT_VX_INFO,
10487 +       VXH_SET_VX_INFO,
10488 +       VXH_CLR_VX_INFO,
10489 +       VXH_CLAIM_VX_INFO,
10490 +       VXH_RELEASE_VX_INFO,
10491 +       VXH_ALLOC_VX_INFO,
10492 +       VXH_DEALLOC_VX_INFO,
10493 +       VXH_HASH_VX_INFO,
10494 +       VXH_UNHASH_VX_INFO,
10495 +       VXH_LOC_VX_INFO,
10496 +       VXH_LOOKUP_VX_INFO,
10497 +       VXH_CREATE_VX_INFO,
10498 +};
10499 +
10500 +struct _vxhe_vxi {
10501 +       struct vx_info *ptr;
10502 +       unsigned xid;
10503 +       unsigned usecnt;
10504 +       unsigned tasks;
10505 +};
10506 +
10507 +struct _vxhe_set_clr {
10508 +       void *data;
10509 +};
10510 +
10511 +struct _vxhe_loc_lookup {
10512 +       unsigned arg;
10513 +};
10514 +
10515 +struct _vx_hist_entry {
10516 +       void *loc;
10517 +       unsigned short seq;
10518 +       unsigned short type;
10519 +       struct _vxhe_vxi vxi;
10520 +       union {
10521 +               struct _vxhe_set_clr sc;
10522 +               struct _vxhe_loc_lookup ll;
10523 +       };
10524 +};
10525 +
10526 +#ifdef CONFIG_VSERVER_HISTORY
10527 +
10528 +extern unsigned volatile int vxh_active;
10529 +
10530 +struct _vx_hist_entry *vxh_advance(void *loc);
10531 +
10532 +
10533 +static inline
10534 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
10535 +{
10536 +       entry->vxi.ptr = vxi;
10537 +       if (vxi) {
10538 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
10539 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
10540 +               entry->vxi.xid = vxi->vx_id;
10541 +       }
10542 +}
10543 +
10544 +
10545 +#define        __HERE__ current_text_addr()
10546 +
10547 +#define __VXH_BODY(__type, __data, __here)     \
10548 +       struct _vx_hist_entry *entry;           \
10549 +                                               \
10550 +       preempt_disable();                      \
10551 +       entry = vxh_advance(__here);            \
10552 +       __data;                                 \
10553 +       entry->type = __type;                   \
10554 +       preempt_enable();
10555 +
10556 +
10557 +       /* pass vxi only */
10558 +
10559 +#define __VXH_SMPL                             \
10560 +       __vxh_copy_vxi(entry, vxi)
10561 +
10562 +static inline
10563 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
10564 +{
10565 +       __VXH_BODY(__type, __VXH_SMPL, __here)
10566 +}
10567 +
10568 +       /* pass vxi and data (void *) */
10569 +
10570 +#define __VXH_DATA                             \
10571 +       __vxh_copy_vxi(entry, vxi);             \
10572 +       entry->sc.data = data
10573 +
10574 +static inline
10575 +void   __vxh_data(struct vx_info *vxi, void *data,
10576 +                       int __type, void *__here)
10577 +{
10578 +       __VXH_BODY(__type, __VXH_DATA, __here)
10579 +}
10580 +
10581 +       /* pass vxi and arg (long) */
10582 +
10583 +#define __VXH_LONG                             \
10584 +       __vxh_copy_vxi(entry, vxi);             \
10585 +       entry->ll.arg = arg
10586 +
10587 +static inline
10588 +void   __vxh_long(struct vx_info *vxi, long arg,
10589 +                       int __type, void *__here)
10590 +{
10591 +       __VXH_BODY(__type, __VXH_LONG, __here)
10592 +}
10593 +
10594 +
10595 +static inline
10596 +void   __vxh_throw_oops(void *__here)
10597 +{
10598 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
10599 +       /* prevent further acquisition */
10600 +       vxh_active = 0;
10601 +}
10602 +
10603 +
10604 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
10605 +
10606 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
10607 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
10608 +
10609 +#define __vxh_init_vx_info(v, d, h) \
10610 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
10611 +#define __vxh_set_vx_info(v, d, h) \
10612 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
10613 +#define __vxh_clr_vx_info(v, d, h) \
10614 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
10615 +
10616 +#define __vxh_claim_vx_info(v, d, h) \
10617 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
10618 +#define __vxh_release_vx_info(v, d, h) \
10619 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
10620 +
10621 +#define vxh_alloc_vx_info(v) \
10622 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
10623 +#define vxh_dealloc_vx_info(v) \
10624 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
10625 +
10626 +#define vxh_hash_vx_info(v) \
10627 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
10628 +#define vxh_unhash_vx_info(v) \
10629 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
10630 +
10631 +#define vxh_loc_vx_info(v, l) \
10632 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
10633 +#define vxh_lookup_vx_info(v, l) \
10634 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
10635 +#define vxh_create_vx_info(v, l) \
10636 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
10637 +
10638 +extern void vxh_dump_history(void);
10639 +
10640 +
10641 +#else  /* CONFIG_VSERVER_HISTORY */
10642 +
10643 +#define        __HERE__        0
10644 +
10645 +#define vxh_throw_oops()               do { } while (0)
10646 +
10647 +#define __vxh_get_vx_info(v, h)                do { } while (0)
10648 +#define __vxh_put_vx_info(v, h)                do { } while (0)
10649 +
10650 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
10651 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
10652 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
10653 +
10654 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
10655 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
10656 +
10657 +#define vxh_alloc_vx_info(v)           do { } while (0)
10658 +#define vxh_dealloc_vx_info(v)         do { } while (0)
10659 +
10660 +#define vxh_hash_vx_info(v)            do { } while (0)
10661 +#define vxh_unhash_vx_info(v)          do { } while (0)
10662 +
10663 +#define vxh_loc_vx_info(v, l)          do { } while (0)
10664 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
10665 +#define vxh_create_vx_info(v, l)       do { } while (0)
10666 +
10667 +#define vxh_dump_history()             do { } while (0)
10668 +
10669 +
10670 +#endif /* CONFIG_VSERVER_HISTORY */
10671 +
10672 +#endif /* _VSERVER_HISTORY_H */
10673 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/inode.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode.h
10674 --- linux-3.13.10/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
10675 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode.h      2014-01-31 20:38:03.000000000 +0000
10676 @@ -0,0 +1,19 @@
10677 +#ifndef _VSERVER_INODE_H
10678 +#define _VSERVER_INODE_H
10679 +
10680 +#include <uapi/vserver/inode.h>
10681 +
10682 +
10683 +#ifdef CONFIG_VSERVER_PROC_SECURE
10684 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
10685 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10686 +#else
10687 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
10688 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
10689 +#endif
10690 +
10691 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
10692 +
10693 +#else  /* _VSERVER_INODE_H */
10694 +#warning duplicate inclusion
10695 +#endif /* _VSERVER_INODE_H */
10696 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/inode_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode_cmd.h
10697 --- linux-3.13.10/include/linux/vserver/inode_cmd.h     1970-01-01 00:00:00.000000000 +0000
10698 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode_cmd.h  2014-01-31 20:38:03.000000000 +0000
10699 @@ -0,0 +1,36 @@
10700 +#ifndef _VSERVER_INODE_CMD_H
10701 +#define _VSERVER_INODE_CMD_H
10702 +
10703 +#include <uapi/vserver/inode_cmd.h>
10704 +
10705 +
10706 +
10707 +#ifdef CONFIG_COMPAT
10708 +
10709 +#include <asm/compat.h>
10710 +
10711 +struct vcmd_ctx_iattr_v1_x32 {
10712 +       compat_uptr_t name_ptr;
10713 +       uint32_t tag;
10714 +       uint32_t flags;
10715 +       uint32_t mask;
10716 +};
10717 +
10718 +#endif /* CONFIG_COMPAT */
10719 +
10720 +#include <linux/compiler.h>
10721 +
10722 +extern int vc_get_iattr(void __user *);
10723 +extern int vc_set_iattr(void __user *);
10724 +
10725 +extern int vc_fget_iattr(uint32_t, void __user *);
10726 +extern int vc_fset_iattr(uint32_t, void __user *);
10727 +
10728 +#ifdef CONFIG_COMPAT
10729 +
10730 +extern int vc_get_iattr_x32(void __user *);
10731 +extern int vc_set_iattr_x32(void __user *);
10732 +
10733 +#endif /* CONFIG_COMPAT */
10734 +
10735 +#endif /* _VSERVER_INODE_CMD_H */
10736 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit.h
10737 --- linux-3.13.10/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
10738 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit.h      2014-01-31 20:38:03.000000000 +0000
10739 @@ -0,0 +1,61 @@
10740 +#ifndef _VSERVER_LIMIT_H
10741 +#define _VSERVER_LIMIT_H
10742 +
10743 +#include <uapi/vserver/limit.h>
10744 +
10745 +
10746 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
10747 +
10748 +/*     keep in sync with CRLIM_INFINITY */
10749 +
10750 +#define        VLIM_INFINITY   (~0ULL)
10751 +
10752 +#include <asm/atomic.h>
10753 +#include <asm/resource.h>
10754 +
10755 +#ifndef RLIM_INFINITY
10756 +#warning RLIM_INFINITY is undefined
10757 +#endif
10758 +
10759 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
10760 +
10761 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
10762 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
10763 +
10764 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
10765 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
10766 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
10767 +
10768 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
10769 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
10770 +
10771 +typedef atomic_long_t rlim_atomic_t;
10772 +typedef unsigned long rlim_t;
10773 +
10774 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
10775 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
10776 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
10777 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
10778 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
10779 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
10780 +
10781 +
10782 +#if    (RLIM_INFINITY == VLIM_INFINITY)
10783 +#define        VX_VLIM(r) ((long long)(long)(r))
10784 +#define        VX_RLIM(v) ((rlim_t)(v))
10785 +#else
10786 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
10787 +               ? VLIM_INFINITY : (long long)(r))
10788 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
10789 +               ? RLIM_INFINITY : (rlim_t)(v))
10790 +#endif
10791 +
10792 +struct sysinfo;
10793 +
10794 +void vx_vsi_meminfo(struct sysinfo *);
10795 +void vx_vsi_swapinfo(struct sysinfo *);
10796 +long vx_vsi_cached(struct sysinfo *);
10797 +
10798 +#define NUM_LIMITS     24
10799 +
10800 +#endif /* _VSERVER_LIMIT_H */
10801 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_cmd.h
10802 --- linux-3.13.10/include/linux/vserver/limit_cmd.h     1970-01-01 00:00:00.000000000 +0000
10803 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_cmd.h  2014-01-31 20:38:03.000000000 +0000
10804 @@ -0,0 +1,35 @@
10805 +#ifndef _VSERVER_LIMIT_CMD_H
10806 +#define _VSERVER_LIMIT_CMD_H
10807 +
10808 +#include <uapi/vserver/limit_cmd.h>
10809 +
10810 +
10811 +#ifdef CONFIG_IA32_EMULATION
10812 +
10813 +struct vcmd_ctx_rlimit_v0_x32 {
10814 +       uint32_t id;
10815 +       uint64_t minimum;
10816 +       uint64_t softlimit;
10817 +       uint64_t maximum;
10818 +} __attribute__ ((packed));
10819 +
10820 +#endif /* CONFIG_IA32_EMULATION */
10821 +
10822 +#include <linux/compiler.h>
10823 +
10824 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
10825 +extern int vc_get_rlimit(struct vx_info *, void __user *);
10826 +extern int vc_set_rlimit(struct vx_info *, void __user *);
10827 +extern int vc_reset_hits(struct vx_info *, void __user *);
10828 +extern int vc_reset_minmax(struct vx_info *, void __user *);
10829 +
10830 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
10831 +
10832 +#ifdef CONFIG_IA32_EMULATION
10833 +
10834 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
10835 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
10836 +
10837 +#endif /* CONFIG_IA32_EMULATION */
10838 +
10839 +#endif /* _VSERVER_LIMIT_CMD_H */
10840 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_def.h
10841 --- linux-3.13.10/include/linux/vserver/limit_def.h     1970-01-01 00:00:00.000000000 +0000
10842 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_def.h  2014-01-31 20:38:03.000000000 +0000
10843 @@ -0,0 +1,47 @@
10844 +#ifndef _VSERVER_LIMIT_DEF_H
10845 +#define _VSERVER_LIMIT_DEF_H
10846 +
10847 +#include <asm/atomic.h>
10848 +#include <asm/resource.h>
10849 +
10850 +#include "limit.h"
10851 +
10852 +
10853 +struct _vx_res_limit {
10854 +       rlim_t soft;            /* Context soft limit */
10855 +       rlim_t hard;            /* Context hard limit */
10856 +
10857 +       rlim_atomic_t rcur;     /* Current value */
10858 +       rlim_t rmin;            /* Context minimum */
10859 +       rlim_t rmax;            /* Context maximum */
10860 +
10861 +       atomic_t lhit;          /* Limit hits */
10862 +};
10863 +
10864 +/* context sub struct */
10865 +
10866 +struct _vx_limit {
10867 +       struct _vx_res_limit res[NUM_LIMITS];
10868 +};
10869 +
10870 +#ifdef CONFIG_VSERVER_DEBUG
10871 +
10872 +static inline void __dump_vx_limit(struct _vx_limit *limit)
10873 +{
10874 +       int i;
10875 +
10876 +       printk("\t_vx_limit:");
10877 +       for (i = 0; i < NUM_LIMITS; i++) {
10878 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
10879 +                       i, (unsigned long)__rlim_get(limit, i),
10880 +                       (unsigned long)__rlim_rmin(limit, i),
10881 +                       (unsigned long)__rlim_rmax(limit, i),
10882 +                       (long)__rlim_soft(limit, i),
10883 +                       (long)__rlim_hard(limit, i),
10884 +                       atomic_read(&__rlim_lhit(limit, i)));
10885 +       }
10886 +}
10887 +
10888 +#endif
10889 +
10890 +#endif /* _VSERVER_LIMIT_DEF_H */
10891 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit_int.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_int.h
10892 --- linux-3.13.10/include/linux/vserver/limit_int.h     1970-01-01 00:00:00.000000000 +0000
10893 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_int.h  2014-01-31 20:38:03.000000000 +0000
10894 @@ -0,0 +1,193 @@
10895 +#ifndef _VSERVER_LIMIT_INT_H
10896 +#define _VSERVER_LIMIT_INT_H
10897 +
10898 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
10899 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
10900 +
10901 +extern const char *vlimit_name[NUM_LIMITS];
10902 +
10903 +static inline void __vx_acc_cres(struct vx_info *vxi,
10904 +       int res, int dir, void *_data, char *_file, int _line)
10905 +{
10906 +       if (VXD_RCRES_COND(res))
10907 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
10908 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10909 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10910 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
10911 +       if (!vxi)
10912 +               return;
10913 +
10914 +       if (dir > 0)
10915 +               __rlim_inc(&vxi->limit, res);
10916 +       else
10917 +               __rlim_dec(&vxi->limit, res);
10918 +}
10919 +
10920 +static inline void __vx_add_cres(struct vx_info *vxi,
10921 +       int res, int amount, void *_data, char *_file, int _line)
10922 +{
10923 +       if (VXD_RCRES_COND(res))
10924 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
10925 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10926 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10927 +                       amount, _data, _file, _line);
10928 +       if (amount == 0)
10929 +               return;
10930 +       if (!vxi)
10931 +               return;
10932 +       __rlim_add(&vxi->limit, res, amount);
10933 +}
10934 +
10935 +static inline
10936 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
10937 +{
10938 +       int cond = (value > __rlim_rmax(limit, res));
10939 +
10940 +       if (cond)
10941 +               __rlim_rmax(limit, res) = value;
10942 +       return cond;
10943 +}
10944 +
10945 +static inline
10946 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
10947 +{
10948 +       int cond = (value < __rlim_rmin(limit, res));
10949 +
10950 +       if (cond)
10951 +               __rlim_rmin(limit, res) = value;
10952 +       return cond;
10953 +}
10954 +
10955 +static inline
10956 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
10957 +{
10958 +       if (!__vx_cres_adjust_max(limit, res, value))
10959 +               __vx_cres_adjust_min(limit, res, value);
10960 +}
10961 +
10962 +
10963 +/*     return values:
10964 +        +1 ... no limit hit
10965 +        -1 ... over soft limit
10966 +         0 ... over hard limit         */
10967 +
10968 +static inline int __vx_cres_avail(struct vx_info *vxi,
10969 +       int res, int num, char *_file, int _line)
10970 +{
10971 +       struct _vx_limit *limit;
10972 +       rlim_t value;
10973 +
10974 +       if (VXD_RLIMIT_COND(res))
10975 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
10976 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10977 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
10978 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
10979 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10980 +                       num, _file, _line);
10981 +       if (!vxi)
10982 +               return 1;
10983 +
10984 +       limit = &vxi->limit;
10985 +       value = __rlim_get(limit, res);
10986 +
10987 +       if (!__vx_cres_adjust_max(limit, res, value))
10988 +               __vx_cres_adjust_min(limit, res, value);
10989 +
10990 +       if (num == 0)
10991 +               return 1;
10992 +
10993 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
10994 +               return -1;
10995 +       if (value + num <= __rlim_soft(limit, res))
10996 +               return -1;
10997 +
10998 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
10999 +               return 1;
11000 +       if (value + num <= __rlim_hard(limit, res))
11001 +               return 1;
11002 +
11003 +       __rlim_hit(limit, res);
11004 +       return 0;
11005 +}
11006 +
11007 +
11008 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11009 +
11010 +static inline
11011 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11012 +{
11013 +       rlim_t value, sum = 0;
11014 +       int res;
11015 +
11016 +       while ((res = *array++)) {
11017 +               value = __rlim_get(limit, res);
11018 +               __vx_cres_fixup(limit, res, value);
11019 +               sum += value;
11020 +       }
11021 +       return sum;
11022 +}
11023 +
11024 +static inline
11025 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11026 +{
11027 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11028 +       int res = *array;
11029 +
11030 +       if (value == __rlim_get(limit, res))
11031 +               return value;
11032 +
11033 +       __rlim_set(limit, res, value);
11034 +       /* now adjust min/max */
11035 +       if (!__vx_cres_adjust_max(limit, res, value))
11036 +               __vx_cres_adjust_min(limit, res, value);
11037 +
11038 +       return value;
11039 +}
11040 +
11041 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11042 +       const int *array, int num, char *_file, int _line)
11043 +{
11044 +       struct _vx_limit *limit;
11045 +       rlim_t value = 0;
11046 +       int res;
11047 +
11048 +       if (num == 0)
11049 +               return 1;
11050 +       if (!vxi)
11051 +               return 1;
11052 +
11053 +       limit = &vxi->limit;
11054 +       res = *array;
11055 +       value = __vx_cres_array_sum(limit, array + 1);
11056 +
11057 +       __rlim_set(limit, res, value);
11058 +       __vx_cres_fixup(limit, res, value);
11059 +
11060 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11061 +}
11062 +
11063 +
11064 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11065 +{
11066 +       rlim_t value;
11067 +       int res;
11068 +
11069 +       /* complex resources first */
11070 +       if ((id < 0) || (id == RLIMIT_RSS))
11071 +               __vx_cres_array_fixup(limit, VLA_RSS);
11072 +
11073 +       for (res = 0; res < NUM_LIMITS; res++) {
11074 +               if ((id > 0) && (res != id))
11075 +                       continue;
11076 +
11077 +               value = __rlim_get(limit, res);
11078 +               __vx_cres_fixup(limit, res, value);
11079 +
11080 +               /* not supposed to happen, maybe warn? */
11081 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11082 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11083 +       }
11084 +}
11085 +
11086 +
11087 +#endif /* _VSERVER_LIMIT_INT_H */
11088 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/monitor.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/monitor.h
11089 --- linux-3.13.10/include/linux/vserver/monitor.h       1970-01-01 00:00:00.000000000 +0000
11090 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/monitor.h    2014-01-31 20:38:03.000000000 +0000
11091 @@ -0,0 +1,6 @@
11092 +#ifndef _VSERVER_MONITOR_H
11093 +#define _VSERVER_MONITOR_H
11094 +
11095 +#include <uapi/vserver/monitor.h>
11096 +
11097 +#endif /* _VSERVER_MONITOR_H */
11098 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/network.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/network.h
11099 --- linux-3.13.10/include/linux/vserver/network.h       1970-01-01 00:00:00.000000000 +0000
11100 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/network.h    2014-01-31 20:38:03.000000000 +0000
11101 @@ -0,0 +1,76 @@
11102 +#ifndef _VSERVER_NETWORK_H
11103 +#define _VSERVER_NETWORK_H
11104 +
11105 +
11106 +#include <linux/list.h>
11107 +#include <linux/spinlock.h>
11108 +#include <linux/rcupdate.h>
11109 +#include <linux/in.h>
11110 +#include <linux/in6.h>
11111 +#include <asm/atomic.h>
11112 +#include <uapi/vserver/network.h>
11113 +
11114 +struct nx_addr_v4 {
11115 +       struct nx_addr_v4 *next;
11116 +       struct in_addr ip[2];
11117 +       struct in_addr mask;
11118 +       uint16_t type;
11119 +       uint16_t flags;
11120 +};
11121 +
11122 +struct nx_addr_v6 {
11123 +       struct nx_addr_v6 *next;
11124 +       struct in6_addr ip;
11125 +       struct in6_addr mask;
11126 +       uint32_t prefix;
11127 +       uint16_t type;
11128 +       uint16_t flags;
11129 +};
11130 +
11131 +struct nx_info {
11132 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
11133 +       vnid_t nx_id;                   /* vnet id */
11134 +       atomic_t nx_usecnt;             /* usage count */
11135 +       atomic_t nx_tasks;              /* tasks count */
11136 +       int nx_state;                   /* context state */
11137 +
11138 +       uint64_t nx_flags;              /* network flag word */
11139 +       uint64_t nx_ncaps;              /* network capabilities */
11140 +
11141 +       spinlock_t addr_lock;           /* protect address changes */
11142 +       struct in_addr v4_lback;        /* Loopback address */
11143 +       struct in_addr v4_bcast;        /* Broadcast address */
11144 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
11145 +#ifdef CONFIG_IPV6
11146 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
11147 +#endif
11148 +       char nx_name[65];               /* network context name */
11149 +};
11150 +
11151 +
11152 +/* status flags */
11153 +
11154 +#define NXS_HASHED      0x0001
11155 +#define NXS_SHUTDOWN    0x0100
11156 +#define NXS_RELEASED    0x8000
11157 +
11158 +extern struct nx_info *lookup_nx_info(int);
11159 +
11160 +extern int get_nid_list(int, unsigned int *, int);
11161 +extern int nid_is_hashed(vnid_t);
11162 +
11163 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11164 +
11165 +extern long vs_net_change(struct nx_info *, unsigned int);
11166 +
11167 +struct sock;
11168 +
11169 +
11170 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
11171 +#ifdef  CONFIG_IPV6
11172 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
11173 +#else
11174 +#define NX_IPV6(n)     (0)
11175 +#endif
11176 +
11177 +#endif /* _VSERVER_NETWORK_H */
11178 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/network_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/network_cmd.h
11179 --- linux-3.13.10/include/linux/vserver/network_cmd.h   1970-01-01 00:00:00.000000000 +0000
11180 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/network_cmd.h        2014-01-31 20:38:03.000000000 +0000
11181 @@ -0,0 +1,37 @@
11182 +#ifndef _VSERVER_NETWORK_CMD_H
11183 +#define _VSERVER_NETWORK_CMD_H
11184 +
11185 +#include <uapi/vserver/network_cmd.h>
11186 +
11187 +extern int vc_task_nid(uint32_t);
11188 +
11189 +extern int vc_nx_info(struct nx_info *, void __user *);
11190 +
11191 +extern int vc_net_create(uint32_t, void __user *);
11192 +extern int vc_net_migrate(struct nx_info *, void __user *);
11193 +
11194 +extern int vc_net_add(struct nx_info *, void __user *);
11195 +extern int vc_net_remove(struct nx_info *, void __user *);
11196 +
11197 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11198 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11199 +
11200 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11201 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11202 +
11203 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11204 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11205 +
11206 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11207 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11208 +
11209 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11210 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11211 +
11212 +extern int vc_get_nflags(struct nx_info *, void __user *);
11213 +extern int vc_set_nflags(struct nx_info *, void __user *);
11214 +
11215 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11216 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11217 +
11218 +#endif /* _VSERVER_CONTEXT_CMD_H */
11219 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/percpu.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/percpu.h
11220 --- linux-3.13.10/include/linux/vserver/percpu.h        1970-01-01 00:00:00.000000000 +0000
11221 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/percpu.h     2014-01-31 20:38:03.000000000 +0000
11222 @@ -0,0 +1,14 @@
11223 +#ifndef _VSERVER_PERCPU_H
11224 +#define _VSERVER_PERCPU_H
11225 +
11226 +#include "cvirt_def.h"
11227 +#include "sched_def.h"
11228 +
11229 +struct _vx_percpu {
11230 +       struct _vx_cvirt_pc cvirt;
11231 +       struct _vx_sched_pc sched;
11232 +};
11233 +
11234 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
11235 +
11236 +#endif /* _VSERVER_PERCPU_H */
11237 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/pid.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/pid.h
11238 --- linux-3.13.10/include/linux/vserver/pid.h   1970-01-01 00:00:00.000000000 +0000
11239 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/pid.h        2014-01-31 20:38:03.000000000 +0000
11240 @@ -0,0 +1,51 @@
11241 +#ifndef _VSERVER_PID_H
11242 +#define _VSERVER_PID_H
11243 +
11244 +/* pid faking stuff */
11245 +
11246 +#define vx_info_map_pid(v, p) \
11247 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
11248 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
11249 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
11250 +#define vx_map_tgid(p) vx_map_pid(p)
11251 +
11252 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
11253 +       const char *func, const char *file, int line)
11254 +{
11255 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11256 +               vxfprintk(VXD_CBIT(cvirt, 2),
11257 +                       "vx_map_tgid: %p/%llx: %d -> %d",
11258 +                       vxi, (long long)vxi->vx_flags, pid,
11259 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
11260 +                       func, file, line);
11261 +               if (pid == 0)
11262 +                       return 0;
11263 +               if (pid == vxi->vx_initpid)
11264 +                       return 1;
11265 +       }
11266 +       return pid;
11267 +}
11268 +
11269 +#define vx_info_rmap_pid(v, p) \
11270 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
11271 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
11272 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
11273 +
11274 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
11275 +       const char *func, const char *file, int line)
11276 +{
11277 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11278 +               vxfprintk(VXD_CBIT(cvirt, 2),
11279 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
11280 +                       vxi, (long long)vxi->vx_flags, pid,
11281 +                       (pid == 1) ? vxi->vx_initpid : pid,
11282 +                       func, file, line);
11283 +               if ((pid == 1) && vxi->vx_initpid)
11284 +                       return vxi->vx_initpid;
11285 +               if (pid == vxi->vx_initpid)
11286 +                       return ~0U;
11287 +       }
11288 +       return pid;
11289 +}
11290 +
11291 +#endif
11292 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/sched.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched.h
11293 --- linux-3.13.10/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
11294 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched.h      2014-01-31 20:38:03.000000000 +0000
11295 @@ -0,0 +1,23 @@
11296 +#ifndef _VSERVER_SCHED_H
11297 +#define _VSERVER_SCHED_H
11298 +
11299 +
11300 +#ifdef __KERNEL__
11301 +
11302 +struct timespec;
11303 +
11304 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11305 +
11306 +
11307 +struct vx_info;
11308 +
11309 +void vx_update_load(struct vx_info *);
11310 +
11311 +
11312 +void vx_update_sched_param(struct _vx_sched *sched,
11313 +       struct _vx_sched_pc *sched_pc);
11314 +
11315 +#endif /* __KERNEL__ */
11316 +#else  /* _VSERVER_SCHED_H */
11317 +#warning duplicate inclusion
11318 +#endif /* _VSERVER_SCHED_H */
11319 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/sched_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_cmd.h
11320 --- linux-3.13.10/include/linux/vserver/sched_cmd.h     1970-01-01 00:00:00.000000000 +0000
11321 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_cmd.h  2014-01-31 20:38:03.000000000 +0000
11322 @@ -0,0 +1,11 @@
11323 +#ifndef _VSERVER_SCHED_CMD_H
11324 +#define _VSERVER_SCHED_CMD_H
11325 +
11326 +
11327 +#include <linux/compiler.h>
11328 +#include <uapi/vserver/sched_cmd.h>
11329 +
11330 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
11331 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
11332 +
11333 +#endif /* _VSERVER_SCHED_CMD_H */
11334 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/sched_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_def.h
11335 --- linux-3.13.10/include/linux/vserver/sched_def.h     1970-01-01 00:00:00.000000000 +0000
11336 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_def.h  2014-01-31 20:38:03.000000000 +0000
11337 @@ -0,0 +1,38 @@
11338 +#ifndef _VSERVER_SCHED_DEF_H
11339 +#define _VSERVER_SCHED_DEF_H
11340 +
11341 +#include <linux/spinlock.h>
11342 +#include <linux/jiffies.h>
11343 +#include <linux/cpumask.h>
11344 +#include <asm/atomic.h>
11345 +#include <asm/param.h>
11346 +
11347 +
11348 +/* context sub struct */
11349 +
11350 +struct _vx_sched {
11351 +       int prio_bias;                  /* bias offset for priority */
11352 +
11353 +       cpumask_t update;               /* CPUs which should update */
11354 +};
11355 +
11356 +struct _vx_sched_pc {
11357 +       int prio_bias;                  /* bias offset for priority */
11358 +
11359 +       uint64_t user_ticks;            /* token tick events */
11360 +       uint64_t sys_ticks;             /* token tick events */
11361 +       uint64_t hold_ticks;            /* token ticks paused */
11362 +};
11363 +
11364 +
11365 +#ifdef CONFIG_VSERVER_DEBUG
11366 +
11367 +static inline void __dump_vx_sched(struct _vx_sched *sched)
11368 +{
11369 +       printk("\t_vx_sched:\n");
11370 +       printk("\t priority = %4d\n", sched->prio_bias);
11371 +}
11372 +
11373 +#endif
11374 +
11375 +#endif /* _VSERVER_SCHED_DEF_H */
11376 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/signal.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal.h
11377 --- linux-3.13.10/include/linux/vserver/signal.h        1970-01-01 00:00:00.000000000 +0000
11378 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal.h     2014-01-31 20:38:03.000000000 +0000
11379 @@ -0,0 +1,14 @@
11380 +#ifndef _VSERVER_SIGNAL_H
11381 +#define _VSERVER_SIGNAL_H
11382 +
11383 +
11384 +#ifdef __KERNEL__
11385 +
11386 +struct vx_info;
11387 +
11388 +int vx_info_kill(struct vx_info *, int, int);
11389 +
11390 +#endif /* __KERNEL__ */
11391 +#else  /* _VSERVER_SIGNAL_H */
11392 +#warning duplicate inclusion
11393 +#endif /* _VSERVER_SIGNAL_H */
11394 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/signal_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal_cmd.h
11395 --- linux-3.13.10/include/linux/vserver/signal_cmd.h    1970-01-01 00:00:00.000000000 +0000
11396 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal_cmd.h 2014-01-31 20:38:03.000000000 +0000
11397 @@ -0,0 +1,14 @@
11398 +#ifndef _VSERVER_SIGNAL_CMD_H
11399 +#define _VSERVER_SIGNAL_CMD_H
11400 +
11401 +#include <uapi/vserver/signal_cmd.h>
11402 +
11403 +
11404 +extern int vc_ctx_kill(struct vx_info *, void __user *);
11405 +extern int vc_wait_exit(struct vx_info *, void __user *);
11406 +
11407 +
11408 +extern int vc_get_pflags(uint32_t pid, void __user *);
11409 +extern int vc_set_pflags(uint32_t pid, void __user *);
11410 +
11411 +#endif /* _VSERVER_SIGNAL_CMD_H */
11412 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/space.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/space.h
11413 --- linux-3.13.10/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
11414 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/space.h      2014-01-31 20:38:03.000000000 +0000
11415 @@ -0,0 +1,12 @@
11416 +#ifndef _VSERVER_SPACE_H
11417 +#define _VSERVER_SPACE_H
11418 +
11419 +#include <linux/types.h>
11420 +
11421 +struct vx_info;
11422 +
11423 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
11424 +
11425 +#else  /* _VSERVER_SPACE_H */
11426 +#warning duplicate inclusion
11427 +#endif /* _VSERVER_SPACE_H */
11428 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/space_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/space_cmd.h
11429 --- linux-3.13.10/include/linux/vserver/space_cmd.h     1970-01-01 00:00:00.000000000 +0000
11430 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/space_cmd.h  2014-01-31 20:38:03.000000000 +0000
11431 @@ -0,0 +1,13 @@
11432 +#ifndef _VSERVER_SPACE_CMD_H
11433 +#define _VSERVER_SPACE_CMD_H
11434 +
11435 +#include <uapi/vserver/space_cmd.h>
11436 +
11437 +
11438 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
11439 +extern int vc_set_space_v1(struct vx_info *, void __user *);
11440 +extern int vc_enter_space(struct vx_info *, void __user *);
11441 +extern int vc_set_space(struct vx_info *, void __user *);
11442 +extern int vc_get_space_mask(void __user *, int);
11443 +
11444 +#endif /* _VSERVER_SPACE_CMD_H */
11445 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/switch.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/switch.h
11446 --- linux-3.13.10/include/linux/vserver/switch.h        1970-01-01 00:00:00.000000000 +0000
11447 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/switch.h     2014-01-31 20:38:03.000000000 +0000
11448 @@ -0,0 +1,8 @@
11449 +#ifndef _VSERVER_SWITCH_H
11450 +#define _VSERVER_SWITCH_H
11451 +
11452 +
11453 +#include <linux/errno.h>
11454 +#include <uapi/vserver/switch.h>
11455 +
11456 +#endif /* _VSERVER_SWITCH_H */
11457 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/tag.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag.h
11458 --- linux-3.13.10/include/linux/vserver/tag.h   1970-01-01 00:00:00.000000000 +0000
11459 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag.h        2014-01-31 20:38:03.000000000 +0000
11460 @@ -0,0 +1,160 @@
11461 +#ifndef _DX_TAG_H
11462 +#define _DX_TAG_H
11463 +
11464 +#include <linux/types.h>
11465 +#include <linux/uidgid.h>
11466 +
11467 +
11468 +#define DX_TAG(in)     (IS_TAGGED(in))
11469 +
11470 +
11471 +#ifdef CONFIG_TAG_NFSD
11472 +#define DX_TAG_NFSD    1
11473 +#else
11474 +#define DX_TAG_NFSD    0
11475 +#endif
11476 +
11477 +
11478 +#ifdef CONFIG_TAGGING_NONE
11479 +
11480 +#define MAX_UID                0xFFFFFFFF
11481 +#define MAX_GID                0xFFFFFFFF
11482 +
11483 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
11484 +
11485 +#define TAGINO_UID(cond, uid, tag)     (uid)
11486 +#define TAGINO_GID(cond, gid, tag)     (gid)
11487 +
11488 +#endif
11489 +
11490 +
11491 +#ifdef CONFIG_TAGGING_GID16
11492 +
11493 +#define MAX_UID                0xFFFFFFFF
11494 +#define MAX_GID                0x0000FFFF
11495 +
11496 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11497 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
11498 +
11499 +#define TAGINO_UID(cond, uid, tag)     (uid)
11500 +#define TAGINO_GID(cond, gid, tag)     \
11501 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
11502 +
11503 +#endif
11504 +
11505 +
11506 +#ifdef CONFIG_TAGGING_ID24
11507 +
11508 +#define MAX_UID                0x00FFFFFF
11509 +#define MAX_GID                0x00FFFFFF
11510 +
11511 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11512 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
11513 +
11514 +#define TAGINO_UID(cond, uid, tag)     \
11515 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
11516 +#define TAGINO_GID(cond, gid, tag)     \
11517 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
11518 +
11519 +#endif
11520 +
11521 +
11522 +#ifdef CONFIG_TAGGING_UID16
11523 +
11524 +#define MAX_UID                0x0000FFFF
11525 +#define MAX_GID                0xFFFFFFFF
11526 +
11527 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11528 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
11529 +
11530 +#define TAGINO_UID(cond, uid, tag)     \
11531 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
11532 +#define TAGINO_GID(cond, gid, tag)     (gid)
11533 +
11534 +#endif
11535 +
11536 +
11537 +#ifdef CONFIG_TAGGING_INTERN
11538 +
11539 +#define MAX_UID                0xFFFFFFFF
11540 +#define MAX_GID                0xFFFFFFFF
11541 +
11542 +#define INOTAG_TAG(cond, uid, gid, tag)        \
11543 +       ((cond) ? (tag) : 0)
11544 +
11545 +#define TAGINO_UID(cond, uid, tag)     (uid)
11546 +#define TAGINO_GID(cond, gid, tag)     (gid)
11547 +
11548 +#endif
11549 +
11550 +
11551 +#ifndef CONFIG_TAGGING_NONE
11552 +#define dx_current_fstag(sb)   \
11553 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
11554 +#else
11555 +#define dx_current_fstag(sb)   (0)
11556 +#endif
11557 +
11558 +#ifndef CONFIG_TAGGING_INTERN
11559 +#define TAGINO_TAG(cond, tag)  (0)
11560 +#else
11561 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
11562 +#endif
11563 +
11564 +#define TAGINO_KUID(cond, kuid, ktag)  \
11565 +       KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
11566 +#define TAGINO_KGID(cond, kgid, ktag)  \
11567 +       KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
11568 +#define TAGINO_KTAG(cond, ktag)                \
11569 +       KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
11570 +
11571 +
11572 +#define INOTAG_UID(cond, uid, gid)     \
11573 +       ((cond) ? ((uid) & MAX_UID) : (uid))
11574 +#define INOTAG_GID(cond, uid, gid)     \
11575 +       ((cond) ? ((gid) & MAX_GID) : (gid))
11576 +
11577 +#define INOTAG_KUID(cond, kuid, kgid)  \
11578 +       KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11579 +#define INOTAG_KGID(cond, kuid, kgid)  \
11580 +       KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11581 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
11582 +       KTAGT_INIT(INOTAG_TAG(cond, \
11583 +               __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
11584 +
11585 +
11586 +static inline uid_t dx_map_uid(uid_t uid)
11587 +{
11588 +       if ((uid > MAX_UID) && (uid != -1))
11589 +               uid = -2;
11590 +       return (uid & MAX_UID);
11591 +}
11592 +
11593 +static inline gid_t dx_map_gid(gid_t gid)
11594 +{
11595 +       if ((gid > MAX_GID) && (gid != -1))
11596 +               gid = -2;
11597 +       return (gid & MAX_GID);
11598 +}
11599 +
11600 +struct peer_tag {
11601 +       int32_t xid;
11602 +       int32_t nid;
11603 +};
11604 +
11605 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
11606 +
11607 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
11608 +                unsigned long *flags);
11609 +
11610 +#ifdef CONFIG_PROPAGATE
11611 +
11612 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
11613 +
11614 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
11615 +
11616 +#else
11617 +#define dx_propagate_tag(n, i) do { } while (0)
11618 +#endif
11619 +
11620 +#endif /* _DX_TAG_H */
11621 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/tag_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag_cmd.h
11622 --- linux-3.13.10/include/linux/vserver/tag_cmd.h       1970-01-01 00:00:00.000000000 +0000
11623 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag_cmd.h    2014-01-31 20:38:03.000000000 +0000
11624 @@ -0,0 +1,10 @@
11625 +#ifndef _VSERVER_TAG_CMD_H
11626 +#define _VSERVER_TAG_CMD_H
11627 +
11628 +#include <uapi/vserver/tag_cmd.h>
11629 +
11630 +extern int vc_task_tag(uint32_t);
11631 +
11632 +extern int vc_tag_migrate(uint32_t);
11633 +
11634 +#endif /* _VSERVER_TAG_CMD_H */
11635 diff -NurpP --minimal linux-3.13.10/include/net/addrconf.h linux-3.13.10-vs2.3.6.11/include/net/addrconf.h
11636 --- linux-3.13.10/include/net/addrconf.h        2013-11-25 15:47:02.000000000 +0000
11637 +++ linux-3.13.10-vs2.3.6.11/include/net/addrconf.h     2014-01-31 20:39:35.000000000 +0000
11638 @@ -79,7 +79,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
11639  
11640  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dev,
11641                        const struct in6_addr *daddr, unsigned int srcprefs,
11642 -                      struct in6_addr *saddr);
11643 +                      struct in6_addr *saddr, struct nx_info *nxi);
11644  int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
11645                       unsigned char banned_flags);
11646  int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
11647 diff -NurpP --minimal linux-3.13.10/include/net/af_unix.h linux-3.13.10-vs2.3.6.11/include/net/af_unix.h
11648 --- linux-3.13.10/include/net/af_unix.h 2013-11-25 15:47:02.000000000 +0000
11649 +++ linux-3.13.10-vs2.3.6.11/include/net/af_unix.h      2014-01-31 20:38:03.000000000 +0000
11650 @@ -4,6 +4,7 @@
11651  #include <linux/socket.h>
11652  #include <linux/un.h>
11653  #include <linux/mutex.h>
11654 +#include <linux/vs_base.h>
11655  #include <net/sock.h>
11656  
11657  void unix_inflight(struct file *fp);
11658 diff -NurpP --minimal linux-3.13.10/include/net/inet_timewait_sock.h linux-3.13.10-vs2.3.6.11/include/net/inet_timewait_sock.h
11659 --- linux-3.13.10/include/net/inet_timewait_sock.h      2014-01-22 20:39:11.000000000 +0000
11660 +++ linux-3.13.10-vs2.3.6.11/include/net/inet_timewait_sock.h   2014-01-31 20:40:30.000000000 +0000
11661 @@ -121,6 +121,10 @@ struct inet_timewait_sock {
11662  #define tw_v6_rcv_saddr        __tw_common.skc_v6_rcv_saddr
11663  #define tw_dport               __tw_common.skc_dport
11664  #define tw_num                 __tw_common.skc_num
11665 +#define tw_xid                 __tw_common.skc_xid
11666 +#define tw_vx_info             __tw_common.skc_vx_info
11667 +#define tw_nid                 __tw_common.skc_nid
11668 +#define tw_nx_info             __tw_common.skc_nx_info
11669  
11670         int                     tw_timeout;
11671         volatile unsigned char  tw_substate;
11672 diff -NurpP --minimal linux-3.13.10/include/net/ip6_route.h linux-3.13.10-vs2.3.6.11/include/net/ip6_route.h
11673 --- linux-3.13.10/include/net/ip6_route.h       2014-01-22 20:39:11.000000000 +0000
11674 +++ linux-3.13.10-vs2.3.6.11/include/net/ip6_route.h    2014-01-31 20:41:10.000000000 +0000
11675 @@ -90,7 +90,7 @@ int ip6_del_rt(struct rt6_info *);
11676  
11677  int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
11678                         const struct in6_addr *daddr, unsigned int prefs,
11679 -                       struct in6_addr *saddr);
11680 +                       struct in6_addr *saddr, struct nx_info *nxi);
11681  
11682  struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
11683                             const struct in6_addr *saddr, int oif, int flags);
11684 diff -NurpP --minimal linux-3.13.10/include/net/route.h linux-3.13.10-vs2.3.6.11/include/net/route.h
11685 --- linux-3.13.10/include/net/route.h   2014-01-22 20:39:12.000000000 +0000
11686 +++ linux-3.13.10-vs2.3.6.11/include/net/route.h        2014-02-01 12:30:58.000000000 +0000
11687 @@ -203,6 +203,9 @@ static inline void ip_rt_put(struct rtab
11688         dst_release(&rt->dst);
11689  }
11690  
11691 +#include <linux/vs_base.h>
11692 +#include <linux/vs_inet.h>
11693 +
11694  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
11695  
11696  extern const __u8 ip_tos2prio[16];
11697 @@ -252,6 +255,9 @@ static inline void ip_route_connect_init
11698                            protocol, flow_flags, dst, src, dport, sport);
11699  }
11700  
11701 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
11702 +       struct flowi4 *);
11703 +
11704  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
11705                                               __be32 dst, __be32 src, u32 tos,
11706                                               int oif, u8 protocol,
11707 @@ -260,11 +266,25 @@ static inline struct rtable *ip_route_co
11708  {
11709         struct net *net = sock_net(sk);
11710         struct rtable *rt;
11711 +       struct nx_info *nx_info = current_nx_info();
11712  
11713         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
11714                               sport, dport, sk);
11715  
11716 -       if (!dst || !src) {
11717 +       if (sk)
11718 +               nx_info = sk->sk_nx_info;
11719 +
11720 +       vxdprintk(VXD_CBIT(net, 4),
11721 +               "ip_route_connect(%p) %p,%p;%lx",
11722 +               sk, nx_info, sk->sk_socket,
11723 +               (sk->sk_socket?sk->sk_socket->flags:0));
11724 +
11725 +       rt = ip_v4_find_src(net, nx_info, fl4);
11726 +       if (IS_ERR(rt))
11727 +               return rt;
11728 +       ip_rt_put(rt);
11729 +
11730 +       if (!fl4->daddr || !fl4->saddr) {
11731                 rt = __ip_route_output_key(net, fl4);
11732                 if (IS_ERR(rt))
11733                         return rt;
11734 diff -NurpP --minimal linux-3.13.10/include/net/sock.h linux-3.13.10-vs2.3.6.11/include/net/sock.h
11735 --- linux-3.13.10/include/net/sock.h    2014-04-17 01:12:39.000000000 +0000
11736 +++ linux-3.13.10-vs2.3.6.11/include/net/sock.h 2014-04-17 01:17:10.000000000 +0000
11737 @@ -191,6 +191,10 @@ struct sock_common {
11738  #ifdef CONFIG_NET_NS
11739         struct net              *skc_net;
11740  #endif
11741 +       vxid_t                  skc_xid;
11742 +       struct vx_info          *skc_vx_info;
11743 +       vnid_t                  skc_nid;
11744 +       struct nx_info          *skc_nx_info;
11745  
11746  #if IS_ENABLED(CONFIG_IPV6)
11747         struct in6_addr         skc_v6_daddr;
11748 @@ -321,7 +325,11 @@ struct sock {
11749  #define sk_prot                        __sk_common.skc_prot
11750  #define sk_net                 __sk_common.skc_net
11751  #define sk_v6_daddr            __sk_common.skc_v6_daddr
11752 -#define sk_v6_rcv_saddr        __sk_common.skc_v6_rcv_saddr
11753 +#define sk_v6_rcv_saddr                __sk_common.skc_v6_rcv_saddr
11754 +#define sk_xid                 __sk_common.skc_xid
11755 +#define sk_vx_info             __sk_common.skc_vx_info
11756 +#define sk_nid                 __sk_common.skc_nid
11757 +#define sk_nx_info             __sk_common.skc_nx_info
11758  
11759         socket_lock_t           sk_lock;
11760         struct sk_buff_head     sk_receive_queue;
11761 diff -NurpP --minimal linux-3.13.10/include/uapi/Kbuild linux-3.13.10-vs2.3.6.11/include/uapi/Kbuild
11762 --- linux-3.13.10/include/uapi/Kbuild   2012-12-11 03:30:57.000000000 +0000
11763 +++ linux-3.13.10-vs2.3.6.11/include/uapi/Kbuild        2014-01-31 20:38:03.000000000 +0000
11764 @@ -12,3 +12,4 @@ header-y += video/
11765  header-y += drm/
11766  header-y += xen/
11767  header-y += scsi/
11768 +header-y += vserver/
11769 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/capability.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/capability.h
11770 --- linux-3.13.10/include/uapi/linux/capability.h       2012-12-11 03:30:57.000000000 +0000
11771 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/capability.h    2014-01-31 20:38:03.000000000 +0000
11772 @@ -259,6 +259,7 @@ struct vfs_cap_data {
11773     arbitrary SCSI commands */
11774  /* Allow setting encryption key on loopback filesystem */
11775  /* Allow setting zone reclaim policy */
11776 +/* Allow the selection of a security context */
11777  
11778  #define CAP_SYS_ADMIN        21
11779  
11780 @@ -345,7 +346,12 @@ struct vfs_cap_data {
11781  
11782  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
11783  
11784 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
11785 +/* Allow context manipulations */
11786 +/* Allow changing context info on files */
11787 +
11788 +#define CAP_CONTEXT         63
11789 +
11790 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
11791  
11792  /*
11793   * Bit location of each capability (used by user-space library and kernel)
11794 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/fs.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/fs.h
11795 --- linux-3.13.10/include/uapi/linux/fs.h       2013-11-25 15:47:02.000000000 +0000
11796 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/fs.h    2014-01-31 20:38:03.000000000 +0000
11797 @@ -86,6 +86,9 @@ struct inodes_stat_t {
11798  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
11799  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
11800  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
11801 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
11802 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
11803 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
11804  
11805  /* These sb flags are internal to the kernel */
11806  #define MS_NOSEC       (1<<28)
11807 @@ -191,11 +194,14 @@ struct inodes_stat_t {
11808  #define FS_EXTENT_FL                   0x00080000 /* Extents */
11809  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
11810  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
11811 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
11812  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
11813  
11814 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
11815 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
11816 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
11817 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
11818  
11819 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
11820 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
11821  
11822  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
11823  #define SYNC_FILE_RANGE_WRITE          2
11824 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/gfs2_ondisk.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/gfs2_ondisk.h
11825 --- linux-3.13.10/include/uapi/linux/gfs2_ondisk.h      2012-12-11 03:30:57.000000000 +0000
11826 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/gfs2_ondisk.h   2014-01-31 20:38:03.000000000 +0000
11827 @@ -225,6 +225,9 @@ enum {
11828         gfs2fl_Sync             = 8,
11829         gfs2fl_System           = 9,
11830         gfs2fl_TopLevel         = 10,
11831 +       gfs2fl_IXUnlink         = 16,
11832 +       gfs2fl_Barrier          = 17,
11833 +       gfs2fl_Cow              = 18,
11834         gfs2fl_TruncInProg      = 29,
11835         gfs2fl_InheritDirectio  = 30,
11836         gfs2fl_InheritJdata     = 31,
11837 @@ -242,6 +245,9 @@ enum {
11838  #define GFS2_DIF_SYNC                  0x00000100
11839  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
11840  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
11841 +#define GFS2_DIF_IXUNLINK               0x00010000
11842 +#define GFS2_DIF_BARRIER                0x00020000
11843 +#define GFS2_DIF_COW                    0x00040000
11844  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
11845  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
11846  #define GFS2_DIF_INHERIT_JDATA         0x80000000
11847 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/if_tun.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/if_tun.h
11848 --- linux-3.13.10/include/uapi/linux/if_tun.h   2013-11-25 15:47:02.000000000 +0000
11849 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/if_tun.h        2014-01-31 20:45:49.000000000 +0000
11850 @@ -58,6 +58,7 @@
11851  #define TUNSETQUEUE  _IOW('T', 217, int)
11852  #define TUNSETIFINDEX  _IOW('T', 218, unsigned int)
11853  #define TUNGETFILTER _IOR('T', 219, struct sock_fprog)
11854 +#define TUNSETNID     _IOW('T', 220, int)
11855  
11856  /* TUNSETIFF ifr flags */
11857  #define IFF_TUN                0x0001
11858 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/major.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/major.h
11859 --- linux-3.13.10/include/uapi/linux/major.h    2014-01-22 20:39:12.000000000 +0000
11860 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/major.h 2014-01-31 20:38:03.000000000 +0000
11861 @@ -15,6 +15,7 @@
11862  #define HD_MAJOR               IDE0_MAJOR
11863  #define PTY_SLAVE_MAJOR                3
11864  #define TTY_MAJOR              4
11865 +#define VROOT_MAJOR            4
11866  #define TTYAUX_MAJOR           5
11867  #define LP_MAJOR               6
11868  #define VCS_MAJOR              7
11869 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/nfs_mount.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/nfs_mount.h
11870 --- linux-3.13.10/include/uapi/linux/nfs_mount.h        2014-01-22 20:39:12.000000000 +0000
11871 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/nfs_mount.h     2014-01-31 20:38:03.000000000 +0000
11872 @@ -63,7 +63,8 @@ struct nfs_mount_data {
11873  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 non-text parsed mount data only */
11874  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
11875  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
11876 -#define NFS_MOUNT_FLAGMASK     0xFFFF
11877 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
11878 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
11879  
11880  /* The following are for internal use only */
11881  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
11882 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/reboot.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/reboot.h
11883 --- linux-3.13.10/include/uapi/linux/reboot.h   2012-12-11 03:30:57.000000000 +0000
11884 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/reboot.h        2014-01-31 20:38:03.000000000 +0000
11885 @@ -33,7 +33,7 @@
11886  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
11887  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
11888  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
11889 -
11890 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
11891  
11892  
11893  #endif /* _UAPI_LINUX_REBOOT_H */
11894 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/sysctl.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/sysctl.h
11895 --- linux-3.13.10/include/uapi/linux/sysctl.h   2012-12-11 03:30:57.000000000 +0000
11896 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/sysctl.h        2014-01-31 20:38:03.000000000 +0000
11897 @@ -60,6 +60,7 @@ enum
11898         CTL_ABI=9,              /* Binary emulation */
11899         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
11900         CTL_ARLAN=254,          /* arlan wireless driver */
11901 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
11902         CTL_S390DBF=5677,       /* s390 debug */
11903         CTL_SUNRPC=7249,        /* sunrpc debug */
11904         CTL_PM=9899,            /* frv power management */
11905 @@ -94,6 +95,7 @@ enum
11906  
11907         KERN_PANIC=15,          /* int: panic timeout */
11908         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
11909 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
11910  
11911         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
11912         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
11913 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/Kbuild linux-3.13.10-vs2.3.6.11/include/uapi/vserver/Kbuild
11914 --- linux-3.13.10/include/uapi/vserver/Kbuild   1970-01-01 00:00:00.000000000 +0000
11915 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/Kbuild        2014-01-31 20:38:03.000000000 +0000
11916 @@ -0,0 +1,9 @@
11917 +
11918 +header-y += context_cmd.h network_cmd.h space_cmd.h \
11919 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11920 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11921 +       debug_cmd.h device_cmd.h
11922 +
11923 +header-y += switch.h context.h network.h monitor.h \
11924 +       limit.h inode.h device.h
11925 +
11926 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/cacct_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cacct_cmd.h
11927 --- linux-3.13.10/include/uapi/vserver/cacct_cmd.h      1970-01-01 00:00:00.000000000 +0000
11928 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cacct_cmd.h   2014-01-31 20:38:03.000000000 +0000
11929 @@ -0,0 +1,15 @@
11930 +#ifndef _UAPI_VS_CACCT_CMD_H
11931 +#define _UAPI_VS_CACCT_CMD_H
11932 +
11933 +
11934 +/* virtual host info name commands */
11935 +
11936 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
11937 +
11938 +struct vcmd_sock_stat_v0 {
11939 +       uint32_t field;
11940 +       uint32_t count[3];
11941 +       uint64_t total[3];
11942 +};
11943 +
11944 +#endif /* _UAPI_VS_CACCT_CMD_H */
11945 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/context.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context.h
11946 --- linux-3.13.10/include/uapi/vserver/context.h        1970-01-01 00:00:00.000000000 +0000
11947 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context.h     2014-01-31 20:38:03.000000000 +0000
11948 @@ -0,0 +1,81 @@
11949 +#ifndef _UAPI_VS_CONTEXT_H
11950 +#define _UAPI_VS_CONTEXT_H
11951 +
11952 +#include <linux/types.h>
11953 +#include <linux/capability.h>
11954 +
11955 +
11956 +/* context flags */
11957 +
11958 +#define VXF_INFO_SCHED         0x00000002
11959 +#define VXF_INFO_NPROC         0x00000004
11960 +#define VXF_INFO_PRIVATE       0x00000008
11961 +
11962 +#define VXF_INFO_INIT          0x00000010
11963 +#define VXF_INFO_HIDE          0x00000020
11964 +#define VXF_INFO_ULIMIT                0x00000040
11965 +#define VXF_INFO_NSPACE                0x00000080
11966 +
11967 +#define VXF_SCHED_HARD         0x00000100
11968 +#define VXF_SCHED_PRIO         0x00000200
11969 +#define VXF_SCHED_PAUSE                0x00000400
11970 +
11971 +#define VXF_VIRT_MEM           0x00010000
11972 +#define VXF_VIRT_UPTIME                0x00020000
11973 +#define VXF_VIRT_CPU           0x00040000
11974 +#define VXF_VIRT_LOAD          0x00080000
11975 +#define VXF_VIRT_TIME          0x00100000
11976 +
11977 +#define VXF_HIDE_MOUNT         0x01000000
11978 +/* was VXF_HIDE_NETIF          0x02000000 */
11979 +#define VXF_HIDE_VINFO         0x04000000
11980 +
11981 +#define VXF_STATE_SETUP                (1ULL << 32)
11982 +#define VXF_STATE_INIT         (1ULL << 33)
11983 +#define VXF_STATE_ADMIN                (1ULL << 34)
11984 +
11985 +#define VXF_SC_HELPER          (1ULL << 36)
11986 +#define VXF_REBOOT_KILL                (1ULL << 37)
11987 +#define VXF_PERSISTENT         (1ULL << 38)
11988 +
11989 +#define VXF_FORK_RSS           (1ULL << 48)
11990 +#define VXF_PROLIFIC           (1ULL << 49)
11991 +
11992 +#define VXF_IGNEG_NICE         (1ULL << 52)
11993 +
11994 +#define VXF_ONE_TIME           (0x0007ULL << 32)
11995 +
11996 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11997 +
11998 +
11999 +/* context migration */
12000 +
12001 +#define VXM_SET_INIT           0x00000001
12002 +#define VXM_SET_REAPER         0x00000002
12003 +
12004 +/* context caps */
12005 +
12006 +#define VXC_SET_UTSNAME                0x00000001
12007 +#define VXC_SET_RLIMIT         0x00000002
12008 +#define VXC_FS_SECURITY                0x00000004
12009 +#define VXC_FS_TRUSTED         0x00000008
12010 +#define VXC_TIOCSTI            0x00000010
12011 +
12012 +/* was VXC_RAW_ICMP            0x00000100 */
12013 +#define VXC_SYSLOG             0x00001000
12014 +#define VXC_OOM_ADJUST         0x00002000
12015 +#define VXC_AUDIT_CONTROL      0x00004000
12016 +
12017 +#define VXC_SECURE_MOUNT       0x00010000
12018 +/* #define VXC_SECURE_REMOUNT  0x00020000 */
12019 +#define VXC_BINARY_MOUNT       0x00040000
12020 +#define VXC_DEV_MOUNT          0x00080000
12021 +
12022 +#define VXC_QUOTA_CTL          0x00100000
12023 +#define VXC_ADMIN_MAPPER       0x00200000
12024 +#define VXC_ADMIN_CLOOP                0x00400000
12025 +
12026 +#define VXC_KTHREAD            0x01000000
12027 +#define VXC_NAMESPACE          0x02000000
12028 +
12029 +#endif /* _UAPI_VS_CONTEXT_H */
12030 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/context_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context_cmd.h
12031 --- linux-3.13.10/include/uapi/vserver/context_cmd.h    1970-01-01 00:00:00.000000000 +0000
12032 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context_cmd.h 2014-01-31 20:38:03.000000000 +0000
12033 @@ -0,0 +1,115 @@
12034 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12035 +#define _UAPI_VS_CONTEXT_CMD_H
12036 +
12037 +
12038 +/* vinfo commands */
12039 +
12040 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12041 +
12042 +
12043 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12044 +
12045 +struct vcmd_vx_info_v0 {
12046 +       uint32_t xid;
12047 +       uint32_t initpid;
12048 +       /* more to come */
12049 +};
12050 +
12051 +
12052 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12053 +
12054 +struct vcmd_ctx_stat_v0 {
12055 +       uint32_t usecnt;
12056 +       uint32_t tasks;
12057 +       /* more to come */
12058 +};
12059 +
12060 +
12061 +/* context commands */
12062 +
12063 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12064 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12065 +
12066 +struct vcmd_ctx_create {
12067 +       uint64_t flagword;
12068 +};
12069 +
12070 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12071 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12072 +
12073 +struct vcmd_ctx_migrate {
12074 +       uint64_t flagword;
12075 +};
12076 +
12077 +
12078 +
12079 +/* flag commands */
12080 +
12081 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12082 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12083 +
12084 +struct vcmd_ctx_flags_v0 {
12085 +       uint64_t flagword;
12086 +       uint64_t mask;
12087 +};
12088 +
12089 +
12090 +
12091 +/* context caps commands */
12092 +
12093 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12094 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12095 +
12096 +struct vcmd_ctx_caps_v1 {
12097 +       uint64_t ccaps;
12098 +       uint64_t cmask;
12099 +};
12100 +
12101 +
12102 +
12103 +/* bcaps commands */
12104 +
12105 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12106 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12107 +
12108 +struct vcmd_bcaps {
12109 +       uint64_t bcaps;
12110 +       uint64_t bmask;
12111 +};
12112 +
12113 +
12114 +
12115 +/* umask commands */
12116 +
12117 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12118 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12119 +
12120 +struct vcmd_umask {
12121 +       uint64_t umask;
12122 +       uint64_t mask;
12123 +};
12124 +
12125 +
12126 +
12127 +/* wmask commands */
12128 +
12129 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
12130 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
12131 +
12132 +struct vcmd_wmask {
12133 +       uint64_t wmask;
12134 +       uint64_t mask;
12135 +};
12136 +
12137 +
12138 +
12139 +/* OOM badness */
12140 +
12141 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12142 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12143 +
12144 +struct vcmd_badness_v0 {
12145 +       int64_t bias;
12146 +};
12147 +
12148 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12149 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/cvirt_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cvirt_cmd.h
12150 --- linux-3.13.10/include/uapi/vserver/cvirt_cmd.h      1970-01-01 00:00:00.000000000 +0000
12151 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cvirt_cmd.h   2014-01-31 20:38:03.000000000 +0000
12152 @@ -0,0 +1,41 @@
12153 +#ifndef _UAPI_VS_CVIRT_CMD_H
12154 +#define _UAPI_VS_CVIRT_CMD_H
12155 +
12156 +
12157 +/* virtual host info name commands */
12158 +
12159 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12160 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12161 +
12162 +struct vcmd_vhi_name_v0 {
12163 +       uint32_t field;
12164 +       char name[65];
12165 +};
12166 +
12167 +
12168 +enum vhi_name_field {
12169 +       VHIN_CONTEXT = 0,
12170 +       VHIN_SYSNAME,
12171 +       VHIN_NODENAME,
12172 +       VHIN_RELEASE,
12173 +       VHIN_VERSION,
12174 +       VHIN_MACHINE,
12175 +       VHIN_DOMAINNAME,
12176 +};
12177 +
12178 +
12179 +
12180 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12181 +
12182 +struct vcmd_virt_stat_v0 {
12183 +       uint64_t offset;
12184 +       uint64_t uptime;
12185 +       uint32_t nr_threads;
12186 +       uint32_t nr_running;
12187 +       uint32_t nr_uninterruptible;
12188 +       uint32_t nr_onhold;
12189 +       uint32_t nr_forks;
12190 +       uint32_t load[3];
12191 +};
12192 +
12193 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12194 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/debug_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/debug_cmd.h
12195 --- linux-3.13.10/include/uapi/vserver/debug_cmd.h      1970-01-01 00:00:00.000000000 +0000
12196 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/debug_cmd.h   2014-01-31 20:38:03.000000000 +0000
12197 @@ -0,0 +1,24 @@
12198 +#ifndef _UAPI_VS_DEBUG_CMD_H
12199 +#define _UAPI_VS_DEBUG_CMD_H
12200 +
12201 +
12202 +/* debug commands */
12203 +
12204 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12205 +
12206 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12207 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12208 +
12209 +struct  vcmd_read_history_v0 {
12210 +       uint32_t index;
12211 +       uint32_t count;
12212 +       char __user *data;
12213 +};
12214 +
12215 +struct  vcmd_read_monitor_v0 {
12216 +       uint32_t index;
12217 +       uint32_t count;
12218 +       char __user *data;
12219 +};
12220 +
12221 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12222 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/device.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device.h
12223 --- linux-3.13.10/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
12224 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device.h      2014-01-31 20:38:03.000000000 +0000
12225 @@ -0,0 +1,12 @@
12226 +#ifndef _UAPI_VS_DEVICE_H
12227 +#define _UAPI_VS_DEVICE_H
12228 +
12229 +
12230 +#define DATTR_CREATE   0x00000001
12231 +#define DATTR_OPEN     0x00000002
12232 +
12233 +#define DATTR_REMAP    0x00000010
12234 +
12235 +#define DATTR_MASK     0x00000013
12236 +
12237 +#endif /* _UAPI_VS_DEVICE_H */
12238 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/device_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device_cmd.h
12239 --- linux-3.13.10/include/uapi/vserver/device_cmd.h     1970-01-01 00:00:00.000000000 +0000
12240 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device_cmd.h  2014-01-31 20:38:03.000000000 +0000
12241 @@ -0,0 +1,16 @@
12242 +#ifndef _UAPI_VS_DEVICE_CMD_H
12243 +#define _UAPI_VS_DEVICE_CMD_H
12244 +
12245 +
12246 +/*  device vserver commands */
12247 +
12248 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12249 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12250 +
12251 +struct vcmd_set_mapping_v0 {
12252 +       const char __user *device;
12253 +       const char __user *target;
12254 +       uint32_t flags;
12255 +};
12256 +
12257 +#endif /* _UAPI_VS_DEVICE_CMD_H */
12258 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/dlimit_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/dlimit_cmd.h
12259 --- linux-3.13.10/include/uapi/vserver/dlimit_cmd.h     1970-01-01 00:00:00.000000000 +0000
12260 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/dlimit_cmd.h  2014-01-31 20:38:03.000000000 +0000
12261 @@ -0,0 +1,67 @@
12262 +#ifndef _UAPI_VS_DLIMIT_CMD_H
12263 +#define _UAPI_VS_DLIMIT_CMD_H
12264 +
12265 +
12266 +/*  dlimit vserver commands */
12267 +
12268 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12269 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12270 +
12271 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12272 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12273 +
12274 +struct vcmd_ctx_dlimit_base_v0 {
12275 +       const char __user *name;
12276 +       uint32_t flags;
12277 +};
12278 +
12279 +struct vcmd_ctx_dlimit_v0 {
12280 +       const char __user *name;
12281 +       uint32_t space_used;                    /* used space in kbytes */
12282 +       uint32_t space_total;                   /* maximum space in kbytes */
12283 +       uint32_t inodes_used;                   /* used inodes */
12284 +       uint32_t inodes_total;                  /* maximum inodes */
12285 +       uint32_t reserved;                      /* reserved for root in % */
12286 +       uint32_t flags;
12287 +};
12288 +
12289 +#define CDLIM_UNSET            ((uint32_t)0UL)
12290 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12291 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12292 +
12293 +#define DLIME_UNIT     0
12294 +#define DLIME_KILO     1
12295 +#define DLIME_MEGA     2
12296 +#define DLIME_GIGA     3
12297 +
12298 +#define DLIMF_SHIFT    0x10
12299 +
12300 +#define DLIMS_USED     0
12301 +#define DLIMS_TOTAL    2
12302 +
12303 +static inline
12304 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12305 +{
12306 +       int exp = (flags & DLIMF_SHIFT) ?
12307 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12308 +       return ((uint64_t)val) << (10 * exp);
12309 +}
12310 +
12311 +static inline
12312 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12313 +{
12314 +       int exp = 0;
12315 +
12316 +       if (*flags & DLIMF_SHIFT) {
12317 +               while (val > (1LL << 32) && (exp < 3)) {
12318 +                       val >>= 10;
12319 +                       exp++;
12320 +               }
12321 +               *flags &= ~(DLIME_GIGA << shift);
12322 +               *flags |= exp << shift;
12323 +       } else
12324 +               val >>= 10;
12325 +       return val;
12326 +}
12327 +
12328 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
12329 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/inode.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode.h
12330 --- linux-3.13.10/include/uapi/vserver/inode.h  1970-01-01 00:00:00.000000000 +0000
12331 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode.h       2014-01-31 20:38:03.000000000 +0000
12332 @@ -0,0 +1,23 @@
12333 +#ifndef _UAPI_VS_INODE_H
12334 +#define _UAPI_VS_INODE_H
12335 +
12336 +
12337 +#define IATTR_TAG      0x01000000
12338 +
12339 +#define IATTR_ADMIN    0x00000001
12340 +#define IATTR_WATCH    0x00000002
12341 +#define IATTR_HIDE     0x00000004
12342 +#define IATTR_FLAGS    0x00000007
12343 +
12344 +#define IATTR_BARRIER  0x00010000
12345 +#define IATTR_IXUNLINK 0x00020000
12346 +#define IATTR_IMMUTABLE 0x00040000
12347 +#define IATTR_COW      0x00080000
12348 +
12349 +
12350 +/* inode ioctls */
12351 +
12352 +#define FIOC_GETXFLG   _IOR('x', 5, long)
12353 +#define FIOC_SETXFLG   _IOW('x', 6, long)
12354 +
12355 +#endif /* _UAPI_VS_INODE_H */
12356 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/inode_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode_cmd.h
12357 --- linux-3.13.10/include/uapi/vserver/inode_cmd.h      1970-01-01 00:00:00.000000000 +0000
12358 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode_cmd.h   2014-01-31 20:38:03.000000000 +0000
12359 @@ -0,0 +1,26 @@
12360 +#ifndef _UAPI_VS_INODE_CMD_H
12361 +#define _UAPI_VS_INODE_CMD_H
12362 +
12363 +
12364 +/*  inode vserver commands */
12365 +
12366 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
12367 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
12368 +
12369 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
12370 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
12371 +
12372 +struct vcmd_ctx_iattr_v1 {
12373 +       const char __user *name;
12374 +       uint32_t tag;
12375 +       uint32_t flags;
12376 +       uint32_t mask;
12377 +};
12378 +
12379 +struct vcmd_ctx_fiattr_v0 {
12380 +       uint32_t tag;
12381 +       uint32_t flags;
12382 +       uint32_t mask;
12383 +};
12384 +
12385 +#endif /* _UAPI_VS_INODE_CMD_H */
12386 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/limit.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit.h
12387 --- linux-3.13.10/include/uapi/vserver/limit.h  1970-01-01 00:00:00.000000000 +0000
12388 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit.h       2014-01-31 20:38:03.000000000 +0000
12389 @@ -0,0 +1,14 @@
12390 +#ifndef _UAPI_VS_LIMIT_H
12391 +#define _UAPI_VS_LIMIT_H
12392 +
12393 +
12394 +#define VLIMIT_NSOCK   16
12395 +#define VLIMIT_OPENFD  17
12396 +#define VLIMIT_ANON    18
12397 +#define VLIMIT_SHMEM   19
12398 +#define VLIMIT_SEMARY  20
12399 +#define VLIMIT_NSEMS   21
12400 +#define VLIMIT_DENTRY  22
12401 +#define VLIMIT_MAPPED  23
12402 +
12403 +#endif /* _UAPI_VS_LIMIT_H */
12404 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/limit_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit_cmd.h
12405 --- linux-3.13.10/include/uapi/vserver/limit_cmd.h      1970-01-01 00:00:00.000000000 +0000
12406 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit_cmd.h   2014-01-31 20:38:03.000000000 +0000
12407 @@ -0,0 +1,40 @@
12408 +#ifndef _UAPI_VS_LIMIT_CMD_H
12409 +#define _UAPI_VS_LIMIT_CMD_H
12410 +
12411 +
12412 +/*  rlimit vserver commands */
12413 +
12414 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
12415 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
12416 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
12417 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
12418 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
12419 +
12420 +struct vcmd_ctx_rlimit_v0 {
12421 +       uint32_t id;
12422 +       uint64_t minimum;
12423 +       uint64_t softlimit;
12424 +       uint64_t maximum;
12425 +};
12426 +
12427 +struct vcmd_ctx_rlimit_mask_v0 {
12428 +       uint32_t minimum;
12429 +       uint32_t softlimit;
12430 +       uint32_t maximum;
12431 +};
12432 +
12433 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
12434 +
12435 +struct vcmd_rlimit_stat_v0 {
12436 +       uint32_t id;
12437 +       uint32_t hits;
12438 +       uint64_t value;
12439 +       uint64_t minimum;
12440 +       uint64_t maximum;
12441 +};
12442 +
12443 +#define CRLIM_UNSET            (0ULL)
12444 +#define CRLIM_INFINITY         (~0ULL)
12445 +#define CRLIM_KEEP             (~1ULL)
12446 +
12447 +#endif /* _UAPI_VS_LIMIT_CMD_H */
12448 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/monitor.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/monitor.h
12449 --- linux-3.13.10/include/uapi/vserver/monitor.h        1970-01-01 00:00:00.000000000 +0000
12450 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/monitor.h     2014-01-31 20:38:03.000000000 +0000
12451 @@ -0,0 +1,96 @@
12452 +#ifndef _UAPI_VS_MONITOR_H
12453 +#define _UAPI_VS_MONITOR_H
12454 +
12455 +#include <linux/types.h>
12456 +
12457 +
12458 +enum {
12459 +       VXM_UNUSED = 0,
12460 +
12461 +       VXM_SYNC = 0x10,
12462 +
12463 +       VXM_UPDATE = 0x20,
12464 +       VXM_UPDATE_1,
12465 +       VXM_UPDATE_2,
12466 +
12467 +       VXM_RQINFO_1 = 0x24,
12468 +       VXM_RQINFO_2,
12469 +
12470 +       VXM_ACTIVATE = 0x40,
12471 +       VXM_DEACTIVATE,
12472 +       VXM_IDLE,
12473 +
12474 +       VXM_HOLD = 0x44,
12475 +       VXM_UNHOLD,
12476 +
12477 +       VXM_MIGRATE = 0x48,
12478 +       VXM_RESCHED,
12479 +
12480 +       /* all other bits are flags */
12481 +       VXM_SCHED = 0x80,
12482 +};
12483 +
12484 +struct _vxm_update_1 {
12485 +       uint32_t tokens_max;
12486 +       uint32_t fill_rate;
12487 +       uint32_t interval;
12488 +};
12489 +
12490 +struct _vxm_update_2 {
12491 +       uint32_t tokens_min;
12492 +       uint32_t fill_rate;
12493 +       uint32_t interval;
12494 +};
12495 +
12496 +struct _vxm_rqinfo_1 {
12497 +       uint16_t running;
12498 +       uint16_t onhold;
12499 +       uint16_t iowait;
12500 +       uint16_t uintr;
12501 +       uint32_t idle_tokens;
12502 +};
12503 +
12504 +struct _vxm_rqinfo_2 {
12505 +       uint32_t norm_time;
12506 +       uint32_t idle_time;
12507 +       uint32_t idle_skip;
12508 +};
12509 +
12510 +struct _vxm_sched {
12511 +       uint32_t tokens;
12512 +       uint32_t norm_time;
12513 +       uint32_t idle_time;
12514 +};
12515 +
12516 +struct _vxm_task {
12517 +       uint16_t pid;
12518 +       uint16_t state;
12519 +};
12520 +
12521 +struct _vxm_event {
12522 +       uint32_t jif;
12523 +       union {
12524 +               uint32_t seq;
12525 +               uint32_t sec;
12526 +       };
12527 +       union {
12528 +               uint32_t tokens;
12529 +               uint32_t nsec;
12530 +               struct _vxm_task tsk;
12531 +       };
12532 +};
12533 +
12534 +struct _vx_mon_entry {
12535 +       uint16_t type;
12536 +       uint16_t xid;
12537 +       union {
12538 +               struct _vxm_event ev;
12539 +               struct _vxm_sched sd;
12540 +               struct _vxm_update_1 u1;
12541 +               struct _vxm_update_2 u2;
12542 +               struct _vxm_rqinfo_1 q1;
12543 +               struct _vxm_rqinfo_2 q2;
12544 +       };
12545 +};
12546 +
12547 +#endif /* _UAPI_VS_MONITOR_H */
12548 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/network.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network.h
12549 --- linux-3.13.10/include/uapi/vserver/network.h        1970-01-01 00:00:00.000000000 +0000
12550 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network.h     2014-01-31 20:38:03.000000000 +0000
12551 @@ -0,0 +1,76 @@
12552 +#ifndef _UAPI_VS_NETWORK_H
12553 +#define _UAPI_VS_NETWORK_H
12554 +
12555 +#include <linux/types.h>
12556 +
12557 +
12558 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
12559 +
12560 +
12561 +/* network flags */
12562 +
12563 +#define NXF_INFO_PRIVATE       0x00000008
12564 +
12565 +#define NXF_SINGLE_IP          0x00000100
12566 +#define NXF_LBACK_REMAP                0x00000200
12567 +#define NXF_LBACK_ALLOW                0x00000400
12568 +
12569 +#define NXF_HIDE_NETIF         0x02000000
12570 +#define NXF_HIDE_LBACK         0x04000000
12571 +
12572 +#define NXF_STATE_SETUP                (1ULL << 32)
12573 +#define NXF_STATE_ADMIN                (1ULL << 34)
12574 +
12575 +#define NXF_SC_HELPER          (1ULL << 36)
12576 +#define NXF_PERSISTENT         (1ULL << 38)
12577 +
12578 +#define NXF_ONE_TIME           (0x0005ULL << 32)
12579 +
12580 +
12581 +#define        NXF_INIT_SET            (__nxf_init_set())
12582 +
12583 +static inline uint64_t __nxf_init_set(void) {
12584 +       return    NXF_STATE_ADMIN
12585 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12586 +               | NXF_LBACK_REMAP
12587 +               | NXF_HIDE_LBACK
12588 +#endif
12589 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12590 +               | NXF_SINGLE_IP
12591 +#endif
12592 +               | NXF_HIDE_NETIF;
12593 +}
12594 +
12595 +
12596 +/* network caps */
12597 +
12598 +#define NXC_TUN_CREATE         0x00000001
12599 +
12600 +#define NXC_RAW_ICMP           0x00000100
12601 +
12602 +#define NXC_MULTICAST          0x00001000
12603 +
12604 +
12605 +/* address types */
12606 +
12607 +#define NXA_TYPE_IPV4          0x0001
12608 +#define NXA_TYPE_IPV6          0x0002
12609 +
12610 +#define NXA_TYPE_NONE          0x0000
12611 +#define NXA_TYPE_ANY           0x00FF
12612 +
12613 +#define NXA_TYPE_ADDR          0x0010
12614 +#define NXA_TYPE_MASK          0x0020
12615 +#define NXA_TYPE_RANGE         0x0040
12616 +
12617 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12618 +
12619 +#define NXA_MOD_BCAST          0x0100
12620 +#define NXA_MOD_LBACK          0x0200
12621 +
12622 +#define NXA_LOOPBACK           0x1000
12623 +
12624 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12625 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
12626 +
12627 +#endif /* _UAPI_VS_NETWORK_H */
12628 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/network_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network_cmd.h
12629 --- linux-3.13.10/include/uapi/vserver/network_cmd.h    1970-01-01 00:00:00.000000000 +0000
12630 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network_cmd.h 2014-01-31 20:38:03.000000000 +0000
12631 @@ -0,0 +1,123 @@
12632 +#ifndef _UAPI_VS_NETWORK_CMD_H
12633 +#define _UAPI_VS_NETWORK_CMD_H
12634 +
12635 +
12636 +/* vinfo commands */
12637 +
12638 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
12639 +
12640 +
12641 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
12642 +
12643 +struct vcmd_nx_info_v0 {
12644 +       uint32_t nid;
12645 +       /* more to come */
12646 +};
12647 +
12648 +
12649 +#include <linux/in.h>
12650 +#include <linux/in6.h>
12651 +
12652 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
12653 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
12654 +
12655 +struct  vcmd_net_create {
12656 +       uint64_t flagword;
12657 +};
12658 +
12659 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
12660 +
12661 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
12662 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
12663 +
12664 +struct vcmd_net_addr_v0 {
12665 +       uint16_t type;
12666 +       uint16_t count;
12667 +       struct in_addr ip[4];
12668 +       struct in_addr mask[4];
12669 +};
12670 +
12671 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
12672 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
12673 +
12674 +struct vcmd_net_addr_ipv4_v1 {
12675 +       uint16_t type;
12676 +       uint16_t flags;
12677 +       struct in_addr ip;
12678 +       struct in_addr mask;
12679 +};
12680 +
12681 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
12682 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
12683 +
12684 +struct vcmd_net_addr_ipv4_v2 {
12685 +       uint16_t type;
12686 +       uint16_t flags;
12687 +       struct in_addr ip;
12688 +       struct in_addr ip2;
12689 +       struct in_addr mask;
12690 +};
12691 +
12692 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
12693 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
12694 +
12695 +struct vcmd_net_addr_ipv6_v1 {
12696 +       uint16_t type;
12697 +       uint16_t flags;
12698 +       uint32_t prefix;
12699 +       struct in6_addr ip;
12700 +       struct in6_addr mask;
12701 +};
12702 +
12703 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
12704 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
12705 +
12706 +struct vcmd_match_ipv4_v0 {
12707 +       uint16_t type;
12708 +       uint16_t flags;
12709 +       uint16_t parent;
12710 +       uint16_t prefix;
12711 +       struct in_addr ip;
12712 +       struct in_addr ip2;
12713 +       struct in_addr mask;
12714 +};
12715 +
12716 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
12717 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
12718 +
12719 +struct vcmd_match_ipv6_v0 {
12720 +       uint16_t type;
12721 +       uint16_t flags;
12722 +       uint16_t parent;
12723 +       uint16_t prefix;
12724 +       struct in6_addr ip;
12725 +       struct in6_addr ip2;
12726 +       struct in6_addr mask;
12727 +};
12728 +
12729 +
12730 +
12731 +
12732 +/* flag commands */
12733 +
12734 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
12735 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
12736 +
12737 +struct vcmd_net_flags_v0 {
12738 +       uint64_t flagword;
12739 +       uint64_t mask;
12740 +};
12741 +
12742 +
12743 +
12744 +/* network caps commands */
12745 +
12746 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
12747 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
12748 +
12749 +struct vcmd_net_caps_v0 {
12750 +       uint64_t ncaps;
12751 +       uint64_t cmask;
12752 +};
12753 +
12754 +#endif /* _UAPI_VS_NETWORK_CMD_H */
12755 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/sched_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/sched_cmd.h
12756 --- linux-3.13.10/include/uapi/vserver/sched_cmd.h      1970-01-01 00:00:00.000000000 +0000
12757 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/sched_cmd.h   2014-01-31 20:38:03.000000000 +0000
12758 @@ -0,0 +1,13 @@
12759 +#ifndef _UAPI_VS_SCHED_CMD_H
12760 +#define _UAPI_VS_SCHED_CMD_H
12761 +
12762 +
12763 +struct vcmd_prio_bias {
12764 +       int32_t cpu_id;
12765 +       int32_t prio_bias;
12766 +};
12767 +
12768 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
12769 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
12770 +
12771 +#endif /* _UAPI_VS_SCHED_CMD_H */
12772 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/signal_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/signal_cmd.h
12773 --- linux-3.13.10/include/uapi/vserver/signal_cmd.h     1970-01-01 00:00:00.000000000 +0000
12774 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/signal_cmd.h  2014-01-31 20:38:03.000000000 +0000
12775 @@ -0,0 +1,31 @@
12776 +#ifndef _UAPI_VS_SIGNAL_CMD_H
12777 +#define _UAPI_VS_SIGNAL_CMD_H
12778 +
12779 +
12780 +/*  signalling vserver commands */
12781 +
12782 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
12783 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
12784 +
12785 +struct vcmd_ctx_kill_v0 {
12786 +       int32_t pid;
12787 +       int32_t sig;
12788 +};
12789 +
12790 +struct vcmd_wait_exit_v0 {
12791 +       int32_t reboot_cmd;
12792 +       int32_t exit_code;
12793 +};
12794 +
12795 +
12796 +/*  process alteration commands */
12797 +
12798 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
12799 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
12800 +
12801 +struct vcmd_pflags_v0 {
12802 +       uint32_t flagword;
12803 +       uint32_t mask;
12804 +};
12805 +
12806 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
12807 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/space_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/space_cmd.h
12808 --- linux-3.13.10/include/uapi/vserver/space_cmd.h      1970-01-01 00:00:00.000000000 +0000
12809 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/space_cmd.h   2014-01-31 20:38:03.000000000 +0000
12810 @@ -0,0 +1,28 @@
12811 +#ifndef _UAPI_VS_SPACE_CMD_H
12812 +#define _UAPI_VS_SPACE_CMD_H
12813 +
12814 +
12815 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
12816 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
12817 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
12818 +
12819 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
12820 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
12821 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
12822 +
12823 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12824 +
12825 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
12826 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12827 +
12828 +
12829 +struct vcmd_space_mask_v1 {
12830 +       uint64_t mask;
12831 +};
12832 +
12833 +struct vcmd_space_mask_v2 {
12834 +       uint64_t mask;
12835 +       uint32_t index;
12836 +};
12837 +
12838 +#endif /* _UAPI_VS_SPACE_CMD_H */
12839 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/switch.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/switch.h
12840 --- linux-3.13.10/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12841 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/switch.h      2014-01-31 20:38:03.000000000 +0000
12842 @@ -0,0 +1,90 @@
12843 +#ifndef _UAPI_VS_SWITCH_H
12844 +#define _UAPI_VS_SWITCH_H
12845 +
12846 +#include <linux/types.h>
12847 +
12848 +
12849 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
12850 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
12851 +#define VC_VERSION(c)          ((c) & 0xFFF)
12852 +
12853 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
12854 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12855 +
12856 +/*
12857 +
12858 +  Syscall Matrix V2.8
12859 +
12860 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12861 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
12862 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
12863 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12864 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
12865 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
12866 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12867 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
12868 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
12869 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12870 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
12871 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
12872 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12873 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
12874 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
12875 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12876 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
12877 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
12878 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12879 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
12880 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
12881 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12882 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
12883 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
12884 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12885 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
12886 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
12887 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12888 +
12889 +*/
12890 +
12891 +#define VC_CAT_VERSION         0
12892 +
12893 +#define VC_CAT_VSETUP          1
12894 +#define VC_CAT_VHOST           2
12895 +
12896 +#define VC_CAT_DEVICE          6
12897 +
12898 +#define VC_CAT_VPROC           9
12899 +#define VC_CAT_PROCALT         10
12900 +#define VC_CAT_PROCMIG         11
12901 +#define VC_CAT_PROCTRL         12
12902 +
12903 +#define VC_CAT_SCHED           14
12904 +#define VC_CAT_MEMCTRL         20
12905 +
12906 +#define VC_CAT_VNET            25
12907 +#define VC_CAT_NETALT          26
12908 +#define VC_CAT_NETMIG          27
12909 +#define VC_CAT_NETCTRL         28
12910 +
12911 +#define VC_CAT_TAGMIG          35
12912 +#define VC_CAT_DLIMIT          36
12913 +#define VC_CAT_INODE           38
12914 +
12915 +#define VC_CAT_VSTAT           40
12916 +#define VC_CAT_VINFO           46
12917 +#define VC_CAT_EVENT           48
12918 +
12919 +#define VC_CAT_FLAGS           52
12920 +#define VC_CAT_VSPACE          54
12921 +#define VC_CAT_DEBUG           56
12922 +#define VC_CAT_RLIMIT          60
12923 +
12924 +#define VC_CAT_SYSTEST         61
12925 +#define VC_CAT_COMPAT          63
12926 +
12927 +/*  query version */
12928 +
12929 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
12930 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
12931 +
12932 +#endif /* _UAPI_VS_SWITCH_H */
12933 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/tag_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/tag_cmd.h
12934 --- linux-3.13.10/include/uapi/vserver/tag_cmd.h        1970-01-01 00:00:00.000000000 +0000
12935 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/tag_cmd.h     2014-01-31 20:38:03.000000000 +0000
12936 @@ -0,0 +1,14 @@
12937 +#ifndef _UAPI_VS_TAG_CMD_H
12938 +#define _UAPI_VS_TAG_CMD_H
12939 +
12940 +
12941 +/* vinfo commands */
12942 +
12943 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
12944 +
12945 +
12946 +/* context commands */
12947 +
12948 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
12949 +
12950 +#endif /* _UAPI_VS_TAG_CMD_H */
12951 diff -NurpP --minimal linux-3.13.10/init/Kconfig linux-3.13.10-vs2.3.6.11/init/Kconfig
12952 --- linux-3.13.10/init/Kconfig  2014-04-17 01:12:39.000000000 +0000
12953 +++ linux-3.13.10-vs2.3.6.11/init/Kconfig       2014-04-17 01:17:11.000000000 +0000
12954 @@ -855,6 +855,7 @@ config NUMA_BALANCING
12955  
12956  menuconfig CGROUPS
12957         boolean "Control Group support"
12958 +       default y
12959         help
12960           This option adds support for grouping sets of processes together, for
12961           use with process control subsystems such as Cpusets, CFS, memory
12962 @@ -1117,6 +1118,7 @@ config IPC_NS
12963  
12964  config USER_NS
12965         bool "User namespace"
12966 +       depends on VSERVER_DISABLED
12967         default n
12968         help
12969           This allows containers, i.e. vservers, to use user namespaces
12970 diff -NurpP --minimal linux-3.13.10/init/main.c linux-3.13.10-vs2.3.6.11/init/main.c
12971 --- linux-3.13.10/init/main.c   2014-01-22 20:39:12.000000000 +0000
12972 +++ linux-3.13.10-vs2.3.6.11/init/main.c        2014-01-31 20:38:03.000000000 +0000
12973 @@ -77,6 +77,7 @@
12974  #include <linux/sched_clock.h>
12975  #include <linux/context_tracking.h>
12976  #include <linux/random.h>
12977 +#include <linux/vserver/percpu.h>
12978  
12979  #include <asm/io.h>
12980  #include <asm/bugs.h>
12981 diff -NurpP --minimal linux-3.13.10/ipc/mqueue.c linux-3.13.10-vs2.3.6.11/ipc/mqueue.c
12982 --- linux-3.13.10/ipc/mqueue.c  2014-04-17 01:12:39.000000000 +0000
12983 +++ linux-3.13.10-vs2.3.6.11/ipc/mqueue.c       2014-03-12 15:51:08.000000000 +0000
12984 @@ -35,6 +35,8 @@
12985  #include <linux/ipc_namespace.h>
12986  #include <linux/user_namespace.h>
12987  #include <linux/slab.h>
12988 +#include <linux/vs_context.h>
12989 +#include <linux/vs_limit.h>
12990  
12991  #include <net/sock.h>
12992  #include "util.h"
12993 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
12994         struct pid* notify_owner;
12995         struct user_namespace *notify_user_ns;
12996         struct user_struct *user;       /* user who created, for accounting */
12997 +       struct vx_info *vxi;
12998         struct sock *notify_sock;
12999         struct sk_buff *notify_cookie;
13000  
13001 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13002         if (S_ISREG(mode)) {
13003                 struct mqueue_inode_info *info;
13004                 unsigned long mq_bytes, mq_treesize;
13005 +               struct vx_info *vxi = current_vx_info();
13006  
13007                 inode->i_fop = &mqueue_file_operations;
13008                 inode->i_size = FILENT_SIZE;
13009 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13010                 info->notify_user_ns = NULL;
13011                 info->qsize = 0;
13012                 info->user = NULL;      /* set when all is ok */
13013 +               info->vxi = NULL;
13014                 info->msg_tree = RB_ROOT;
13015                 info->node_cache = NULL;
13016                 memset(&info->attr, 0, sizeof(info->attr));
13017 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13018  
13019                 spin_lock(&mq_lock);
13020                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13021 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13022 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13023 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13024                         spin_unlock(&mq_lock);
13025                         /* mqueue_evict_inode() releases info->messages */
13026                         ret = -EMFILE;
13027                         goto out_inode;
13028                 }
13029                 u->mq_bytes += mq_bytes;
13030 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13031                 spin_unlock(&mq_lock);
13032  
13033                 /* all is ok */
13034                 info->user = get_uid(u);
13035 +               info->vxi = get_vx_info(vxi);
13036         } else if (S_ISDIR(mode)) {
13037                 inc_nlink(inode);
13038                 /* Some things misbehave if size == 0 on a directory */
13039 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13040  
13041         user = info->user;
13042         if (user) {
13043 +               struct vx_info *vxi = info->vxi;
13044 +
13045                 spin_lock(&mq_lock);
13046                 user->mq_bytes -= mq_bytes;
13047 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13048                 /*
13049                  * get_ns_from_inode() ensures that the
13050                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13051 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13052                 if (ipc_ns)
13053                         ipc_ns->mq_queues_count--;
13054                 spin_unlock(&mq_lock);
13055 +               put_vx_info(vxi);
13056                 free_uid(user);
13057         }
13058         if (ipc_ns)
13059 diff -NurpP --minimal linux-3.13.10/ipc/msg.c linux-3.13.10-vs2.3.6.11/ipc/msg.c
13060 --- linux-3.13.10/ipc/msg.c     2014-04-17 01:12:39.000000000 +0000
13061 +++ linux-3.13.10-vs2.3.6.11/ipc/msg.c  2014-04-17 01:17:11.000000000 +0000
13062 @@ -37,6 +37,7 @@
13063  #include <linux/rwsem.h>
13064  #include <linux/nsproxy.h>
13065  #include <linux/ipc_namespace.h>
13066 +#include <linux/vs_base.h>
13067  
13068  #include <asm/current.h>
13069  #include <asm/uaccess.h>
13070 @@ -194,6 +195,7 @@ static int newque(struct ipc_namespace *
13071  
13072         msq->q_perm.mode = msgflg & S_IRWXUGO;
13073         msq->q_perm.key = key;
13074 +       msq->q_perm.xid = vx_current_xid();
13075  
13076         msq->q_perm.security = NULL;
13077         retval = security_msg_queue_alloc(msq);
13078 diff -NurpP --minimal linux-3.13.10/ipc/sem.c linux-3.13.10-vs2.3.6.11/ipc/sem.c
13079 --- linux-3.13.10/ipc/sem.c     2013-11-25 15:47:03.000000000 +0000
13080 +++ linux-3.13.10-vs2.3.6.11/ipc/sem.c  2014-01-31 20:38:03.000000000 +0000
13081 @@ -86,6 +86,8 @@
13082  #include <linux/rwsem.h>
13083  #include <linux/nsproxy.h>
13084  #include <linux/ipc_namespace.h>
13085 +#include <linux/vs_base.h>
13086 +#include <linux/vs_limit.h>
13087  
13088  #include <asm/uaccess.h>
13089  #include "util.h"
13090 @@ -500,6 +502,7 @@ static int newary(struct ipc_namespace *
13091  
13092         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13093         sma->sem_perm.key = key;
13094 +       sma->sem_perm.xid = vx_current_xid();
13095  
13096         sma->sem_perm.security = NULL;
13097         retval = security_sem_alloc(sma);
13098 @@ -514,6 +517,9 @@ static int newary(struct ipc_namespace *
13099                 return id;
13100         }
13101         ns->used_sems += nsems;
13102 +       /* FIXME: obsoleted? */
13103 +       vx_semary_inc(sma);
13104 +       vx_nsems_add(sma, nsems);
13105  
13106         sma->sem_base = (struct sem *) &sma[1];
13107  
13108 @@ -1103,6 +1109,9 @@ static void freeary(struct ipc_namespace
13109  
13110         wake_up_sem_queue_do(&tasks);
13111         ns->used_sems -= sma->sem_nsems;
13112 +       /* FIXME: obsoleted? */
13113 +       vx_nsems_sub(sma, sma->sem_nsems);
13114 +       vx_semary_dec(sma);
13115         ipc_rcu_putref(sma, sem_rcu_free);
13116  }
13117  
13118 diff -NurpP --minimal linux-3.13.10/ipc/shm.c linux-3.13.10-vs2.3.6.11/ipc/shm.c
13119 --- linux-3.13.10/ipc/shm.c     2014-01-22 20:39:12.000000000 +0000
13120 +++ linux-3.13.10-vs2.3.6.11/ipc/shm.c  2014-01-31 20:38:03.000000000 +0000
13121 @@ -42,6 +42,8 @@
13122  #include <linux/nsproxy.h>
13123  #include <linux/mount.h>
13124  #include <linux/ipc_namespace.h>
13125 +#include <linux/vs_context.h>
13126 +#include <linux/vs_limit.h>
13127  
13128  #include <asm/uaccess.h>
13129  
13130 @@ -209,10 +211,14 @@ static void shm_open(struct vm_area_stru
13131  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13132  {
13133         struct file *shm_file;
13134 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13135 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13136  
13137         shm_file = shp->shm_file;
13138         shp->shm_file = NULL;
13139 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13140 +       vx_ipcshm_sub(vxi, shp, numpages);
13141 +       ns->shm_tot -= numpages;
13142 +
13143         shm_rmid(ns, shp);
13144         shm_unlock(shp);
13145         if (!is_file_hugepages(shm_file))
13146 @@ -220,6 +226,7 @@ static void shm_destroy(struct ipc_names
13147         else if (shp->mlock_user)
13148                 user_shm_unlock(file_inode(shm_file)->i_size, shp->mlock_user);
13149         fput(shm_file);
13150 +       put_vx_info(vxi);
13151         ipc_rcu_putref(shp, shm_rcu_free);
13152  }
13153  
13154 @@ -497,11 +504,15 @@ static int newseg(struct ipc_namespace *
13155         if (ns->shm_tot + numpages > ns->shm_ctlall)
13156                 return -ENOSPC;
13157  
13158 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13159 +               return -ENOSPC;
13160 +
13161         shp = ipc_rcu_alloc(sizeof(*shp));
13162         if (!shp)
13163                 return -ENOMEM;
13164  
13165         shp->shm_perm.key = key;
13166 +       shp->shm_perm.xid = vx_current_xid();
13167         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13168         shp->mlock_user = NULL;
13169  
13170 @@ -570,6 +581,7 @@ static int newseg(struct ipc_namespace *
13171  
13172         ipc_unlock_object(&shp->shm_perm);
13173         rcu_read_unlock();
13174 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13175         return error;
13176  
13177  no_id:
13178 diff -NurpP --minimal linux-3.13.10/kernel/Makefile linux-3.13.10-vs2.3.6.11/kernel/Makefile
13179 --- linux-3.13.10/kernel/Makefile       2014-01-22 20:39:12.000000000 +0000
13180 +++ linux-3.13.10-vs2.3.6.11/kernel/Makefile    2014-01-31 21:36:22.000000000 +0000
13181 @@ -25,6 +25,7 @@ obj-y += printk/
13182  obj-y += cpu/
13183  obj-y += irq/
13184  obj-y += rcu/
13185 +obj-y += vserver/
13186  
13187  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13188  obj-$(CONFIG_FREEZER) += freezer.o
13189 diff -NurpP --minimal linux-3.13.10/kernel/auditsc.c linux-3.13.10-vs2.3.6.11/kernel/auditsc.c
13190 --- linux-3.13.10/kernel/auditsc.c      2014-04-17 01:12:39.000000000 +0000
13191 +++ linux-3.13.10-vs2.3.6.11/kernel/auditsc.c   2014-04-17 01:17:11.000000000 +0000
13192 @@ -1956,7 +1956,7 @@ static int audit_set_loginuid_perm(kuid_
13193         if (is_audit_feature_set(AUDIT_FEATURE_LOGINUID_IMMUTABLE))
13194                 return -EPERM;
13195         /* it is set, you need permission */
13196 -       if (!capable(CAP_AUDIT_CONTROL))
13197 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13198                 return -EPERM;
13199         /* reject if this is not an unset and we don't allow that */
13200         if (is_audit_feature_set(AUDIT_FEATURE_ONLY_UNSET_LOGINUID) && uid_valid(loginuid))
13201 diff -NurpP --minimal linux-3.13.10/kernel/capability.c linux-3.13.10-vs2.3.6.11/kernel/capability.c
13202 --- linux-3.13.10/kernel/capability.c   2013-11-25 15:47:03.000000000 +0000
13203 +++ linux-3.13.10-vs2.3.6.11/kernel/capability.c        2014-01-31 20:38:03.000000000 +0000
13204 @@ -15,6 +15,7 @@
13205  #include <linux/syscalls.h>
13206  #include <linux/pid_namespace.h>
13207  #include <linux/user_namespace.h>
13208 +#include <linux/vs_context.h>
13209  #include <asm/uaccess.h>
13210  
13211  /*
13212 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13213         return 0;
13214  }
13215  
13216 +
13217  /*
13218   * The only thing that can change the capabilities of the current
13219   * process is the current process. As such, we can't be in this code
13220 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13221         return (ret == 0);
13222  }
13223  
13224 +#include <linux/vserver/base.h>
13225 +
13226  /**
13227   * has_capability_noaudit - Does a task have a capability (unaudited) in the
13228   * initial user ns
13229 diff -NurpP --minimal linux-3.13.10/kernel/compat.c linux-3.13.10-vs2.3.6.11/kernel/compat.c
13230 --- linux-3.13.10/kernel/compat.c       2013-07-14 17:01:34.000000000 +0000
13231 +++ linux-3.13.10-vs2.3.6.11/kernel/compat.c    2014-01-31 20:38:03.000000000 +0000
13232 @@ -27,6 +27,7 @@
13233  #include <linux/times.h>
13234  #include <linux/ptrace.h>
13235  #include <linux/gfp.h>
13236 +#include <linux/vs_time.h>
13237  
13238  #include <asm/uaccess.h>
13239  
13240 @@ -1040,7 +1041,7 @@ asmlinkage long compat_sys_stime(compat_
13241         if (err)
13242                 return err;
13243  
13244 -       do_settimeofday(&tv);
13245 +       vx_settimeofday(&tv);
13246         return 0;
13247  }
13248  
13249 diff -NurpP --minimal linux-3.13.10/kernel/cred.c linux-3.13.10-vs2.3.6.11/kernel/cred.c
13250 --- linux-3.13.10/kernel/cred.c 2013-02-19 13:58:56.000000000 +0000
13251 +++ linux-3.13.10-vs2.3.6.11/kernel/cred.c      2014-01-31 20:38:03.000000000 +0000
13252 @@ -56,31 +56,6 @@ struct cred init_cred = {
13253         .group_info             = &init_groups,
13254  };
13255  
13256 -static inline void set_cred_subscribers(struct cred *cred, int n)
13257 -{
13258 -#ifdef CONFIG_DEBUG_CREDENTIALS
13259 -       atomic_set(&cred->subscribers, n);
13260 -#endif
13261 -}
13262 -
13263 -static inline int read_cred_subscribers(const struct cred *cred)
13264 -{
13265 -#ifdef CONFIG_DEBUG_CREDENTIALS
13266 -       return atomic_read(&cred->subscribers);
13267 -#else
13268 -       return 0;
13269 -#endif
13270 -}
13271 -
13272 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
13273 -{
13274 -#ifdef CONFIG_DEBUG_CREDENTIALS
13275 -       struct cred *cred = (struct cred *) _cred;
13276 -
13277 -       atomic_add(n, &cred->subscribers);
13278 -#endif
13279 -}
13280 -
13281  /*
13282   * The RCU callback to actually dispose of a set of credentials
13283   */
13284 @@ -232,21 +207,16 @@ error:
13285   *
13286   * Call commit_creds() or abort_creds() to clean up.
13287   */
13288 -struct cred *prepare_creds(void)
13289 +struct cred *__prepare_creds(const struct cred *old)
13290  {
13291 -       struct task_struct *task = current;
13292 -       const struct cred *old;
13293         struct cred *new;
13294  
13295 -       validate_process_creds();
13296 -
13297         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13298         if (!new)
13299                 return NULL;
13300  
13301         kdebug("prepare_creds() alloc %p", new);
13302  
13303 -       old = task->cred;
13304         memcpy(new, old, sizeof(struct cred));
13305  
13306         atomic_set(&new->usage, 1);
13307 @@ -275,6 +245,13 @@ error:
13308         abort_creds(new);
13309         return NULL;
13310  }
13311 +
13312 +struct cred *prepare_creds(void)
13313 +{
13314 +       validate_process_creds();
13315 +
13316 +       return __prepare_creds(current->cred);
13317 +}
13318  EXPORT_SYMBOL(prepare_creds);
13319  
13320  /*
13321 diff -NurpP --minimal linux-3.13.10/kernel/exit.c linux-3.13.10-vs2.3.6.11/kernel/exit.c
13322 --- linux-3.13.10/kernel/exit.c 2013-11-25 15:45:07.000000000 +0000
13323 +++ linux-3.13.10-vs2.3.6.11/kernel/exit.c      2014-01-31 20:38:03.000000000 +0000
13324 @@ -48,6 +48,10 @@
13325  #include <linux/fs_struct.h>
13326  #include <linux/init_task.h>
13327  #include <linux/perf_event.h>
13328 +#include <linux/vs_limit.h>
13329 +#include <linux/vs_context.h>
13330 +#include <linux/vs_network.h>
13331 +#include <linux/vs_pid.h>
13332  #include <trace/events/sched.h>
13333  #include <linux/hw_breakpoint.h>
13334  #include <linux/oom.h>
13335 @@ -503,15 +507,25 @@ static struct task_struct *find_new_reap
13336         __acquires(&tasklist_lock)
13337  {
13338         struct pid_namespace *pid_ns = task_active_pid_ns(father);
13339 -       struct task_struct *thread;
13340 +       struct vx_info *vxi = task_get_vx_info(father);
13341 +       struct task_struct *thread = father;
13342 +       struct task_struct *reaper;
13343  
13344 -       thread = father;
13345         while_each_thread(father, thread) {
13346                 if (thread->flags & PF_EXITING)
13347                         continue;
13348                 if (unlikely(pid_ns->child_reaper == father))
13349                         pid_ns->child_reaper = thread;
13350 -               return thread;
13351 +               reaper = thread;
13352 +               goto out_put;
13353 +       }
13354 +
13355 +       reaper = pid_ns->child_reaper;
13356 +       if (vxi) {
13357 +               BUG_ON(!vxi->vx_reaper);
13358 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
13359 +                   vxi->vx_reaper != father)
13360 +                       reaper = vxi->vx_reaper;
13361         }
13362  
13363         if (unlikely(pid_ns->child_reaper == father)) {
13364 @@ -549,7 +563,9 @@ static struct task_struct *find_new_reap
13365                 }
13366         }
13367  
13368 -       return pid_ns->child_reaper;
13369 +out_put:
13370 +       put_vx_info(vxi);
13371 +       return reaper;
13372  }
13373  
13374  /*
13375 @@ -600,10 +616,15 @@ static void forget_original_parent(struc
13376         list_for_each_entry_safe(p, n, &father->children, sibling) {
13377                 struct task_struct *t = p;
13378                 do {
13379 -                       t->real_parent = reaper;
13380 +                       struct task_struct *new_parent = reaper;
13381 +
13382 +                       if (unlikely(p == reaper))
13383 +                               new_parent = task_active_pid_ns(p)->child_reaper;
13384 +
13385 +                       t->real_parent = new_parent;
13386                         if (t->parent == father) {
13387                                 BUG_ON(t->ptrace);
13388 -                               t->parent = t->real_parent;
13389 +                               t->parent = new_parent;
13390                         }
13391                         if (t->pdeath_signal)
13392                                 group_send_sig_info(t->pdeath_signal,
13393 @@ -810,6 +831,9 @@ void do_exit(long code)
13394          */
13395         flush_ptrace_hw_breakpoint(tsk);
13396  
13397 +       /* needs to stay before exit_notify() */
13398 +       exit_vx_info_early(tsk, code);
13399 +
13400         exit_notify(tsk, group_dead);
13401  #ifdef CONFIG_NUMA
13402         task_lock(tsk);
13403 @@ -863,10 +887,15 @@ void do_exit(long code)
13404         smp_mb();
13405         raw_spin_unlock_wait(&tsk->pi_lock);
13406  
13407 +       /* needs to stay after exit_notify() */
13408 +       exit_vx_info(tsk, code);
13409 +       exit_nx_info(tsk);
13410 +
13411         /* causes final put_task_struct in finish_task_switch(). */
13412         tsk->state = TASK_DEAD;
13413         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
13414         schedule();
13415 +       printk("bad task: %p [%lx]\n", current, current->state);
13416         BUG();
13417         /* Avoid "noreturn function does return".  */
13418         for (;;)
13419 diff -NurpP --minimal linux-3.13.10/kernel/fork.c linux-3.13.10-vs2.3.6.11/kernel/fork.c
13420 --- linux-3.13.10/kernel/fork.c 2014-01-22 20:39:13.000000000 +0000
13421 +++ linux-3.13.10-vs2.3.6.11/kernel/fork.c      2014-01-31 20:38:03.000000000 +0000
13422 @@ -71,6 +71,9 @@
13423  #include <linux/signalfd.h>
13424  #include <linux/uprobes.h>
13425  #include <linux/aio.h>
13426 +#include <linux/vs_context.h>
13427 +#include <linux/vs_network.h>
13428 +#include <linux/vs_limit.h>
13429  
13430  #include <asm/pgtable.h>
13431  #include <asm/pgalloc.h>
13432 @@ -211,6 +214,8 @@ void free_task(struct task_struct *tsk)
13433         arch_release_thread_info(tsk->stack);
13434         free_thread_info(tsk->stack);
13435         rt_mutex_debug_task_free(tsk);
13436 +       clr_vx_info(&tsk->vx_info);
13437 +       clr_nx_info(&tsk->nx_info);
13438         ftrace_graph_exit_task(tsk);
13439         put_seccomp_filter(tsk);
13440         arch_release_task_struct(tsk);
13441 @@ -542,6 +547,7 @@ static struct mm_struct *mm_init(struct
13442         if (likely(!mm_alloc_pgd(mm))) {
13443                 mm->def_flags = 0;
13444                 mmu_notifier_mm_init(mm);
13445 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
13446                 return mm;
13447         }
13448  
13449 @@ -594,6 +600,7 @@ void __mmdrop(struct mm_struct *mm)
13450         destroy_context(mm);
13451         mmu_notifier_mm_destroy(mm);
13452         check_mm(mm);
13453 +       clr_vx_info(&mm->mm_vx_info);
13454         free_mm(mm);
13455  }
13456  EXPORT_SYMBOL_GPL(__mmdrop);
13457 @@ -813,6 +820,7 @@ struct mm_struct *dup_mm(struct task_str
13458                 goto fail_nomem;
13459  
13460         memcpy(mm, oldmm, sizeof(*mm));
13461 +       mm->mm_vx_info = NULL;
13462         mm_init_cpumask(mm);
13463  
13464  #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
13465 @@ -851,6 +859,7 @@ fail_nocontext:
13466          * If init_new_context() failed, we cannot use mmput() to free the mm
13467          * because it calls destroy_context()
13468          */
13469 +       clr_vx_info(&mm->mm_vx_info);
13470         mm_free_pgd(mm);
13471         free_mm(mm);
13472         return NULL;
13473 @@ -1135,6 +1144,8 @@ static struct task_struct *copy_process(
13474  {
13475         int retval;
13476         struct task_struct *p;
13477 +       struct vx_info *vxi;
13478 +       struct nx_info *nxi;
13479  
13480         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
13481                 return ERR_PTR(-EINVAL);
13482 @@ -1197,7 +1208,12 @@ static struct task_struct *copy_process(
13483         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
13484         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
13485  #endif
13486 +       init_vx_info(&p->vx_info, current_vx_info());
13487 +       init_nx_info(&p->nx_info, current_nx_info());
13488 +
13489         retval = -EAGAIN;
13490 +       if (!vx_nproc_avail(1))
13491 +               goto bad_fork_free;
13492         if (atomic_read(&p->real_cred->user->processes) >=
13493                         task_rlimit(p, RLIMIT_NPROC)) {
13494                 if (p->real_cred->user != INIT_USER &&
13495 @@ -1479,6 +1495,18 @@ static struct task_struct *copy_process(
13496  
13497         total_forks++;
13498         spin_unlock(&current->sighand->siglock);
13499 +
13500 +       /* p is copy of current */
13501 +       vxi = p->vx_info;
13502 +       if (vxi) {
13503 +               claim_vx_info(vxi, p);
13504 +               atomic_inc(&vxi->cvirt.nr_threads);
13505 +               atomic_inc(&vxi->cvirt.total_forks);
13506 +               vx_nproc_inc(p);
13507 +       }
13508 +       nxi = p->nx_info;
13509 +       if (nxi)
13510 +               claim_nx_info(nxi, p);
13511         write_unlock_irq(&tasklist_lock);
13512         proc_fork_connector(p);
13513         cgroup_post_fork(p);
13514 diff -NurpP --minimal linux-3.13.10/kernel/kthread.c linux-3.13.10-vs2.3.6.11/kernel/kthread.c
13515 --- linux-3.13.10/kernel/kthread.c      2014-01-22 20:39:13.000000000 +0000
13516 +++ linux-3.13.10-vs2.3.6.11/kernel/kthread.c   2014-01-31 20:38:03.000000000 +0000
13517 @@ -18,6 +18,7 @@
13518  #include <linux/freezer.h>
13519  #include <linux/ptrace.h>
13520  #include <linux/uaccess.h>
13521 +#include <linux/vs_pid.h>
13522  #include <trace/events/sched.h>
13523  
13524  static DEFINE_SPINLOCK(kthread_create_lock);
13525 diff -NurpP --minimal linux-3.13.10/kernel/nsproxy.c linux-3.13.10-vs2.3.6.11/kernel/nsproxy.c
13526 --- linux-3.13.10/kernel/nsproxy.c      2013-11-25 15:47:03.000000000 +0000
13527 +++ linux-3.13.10-vs2.3.6.11/kernel/nsproxy.c   2014-02-01 00:17:43.000000000 +0000
13528 @@ -20,11 +20,14 @@
13529  #include <linux/mnt_namespace.h>
13530  #include <linux/utsname.h>
13531  #include <linux/pid_namespace.h>
13532 +#include <linux/vserver/global.h>
13533 +#include <linux/vserver/debug.h>
13534  #include <net/net_namespace.h>
13535  #include <linux/ipc_namespace.h>
13536  #include <linux/proc_ns.h>
13537  #include <linux/file.h>
13538  #include <linux/syscalls.h>
13539 +#include "../fs/mount.h"
13540  
13541  static struct kmem_cache *nsproxy_cachep;
13542  
13543 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
13544         struct nsproxy *nsproxy;
13545  
13546         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
13547 -       if (nsproxy)
13548 +       if (nsproxy) {
13549                 atomic_set(&nsproxy->count, 1);
13550 +               atomic_inc(&vs_global_nsproxy);
13551 +       }
13552 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
13553         return nsproxy;
13554  }
13555  
13556 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
13557   * Return the newly created nsproxy.  Do not attach this to the task,
13558   * leave it to the caller to do proper locking and attach it to task.
13559   */
13560 -static struct nsproxy *create_new_namespaces(unsigned long flags,
13561 -       struct task_struct *tsk, struct user_namespace *user_ns,
13562 -       struct fs_struct *new_fs)
13563 +static struct nsproxy *unshare_namespaces(
13564 +       unsigned long flags,
13565 +       struct nsproxy *orig,
13566 +       struct fs_struct *new_fs,
13567 +       struct user_namespace *new_user,
13568 +       struct pid_namespace *new_pid)
13569  {
13570         struct nsproxy *new_nsp;
13571         int err;
13572 @@ -67,32 +76,31 @@ static struct nsproxy *create_new_namesp
13573         if (!new_nsp)
13574                 return ERR_PTR(-ENOMEM);
13575  
13576 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
13577 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
13578         if (IS_ERR(new_nsp->mnt_ns)) {
13579                 err = PTR_ERR(new_nsp->mnt_ns);
13580                 goto out_ns;
13581         }
13582  
13583 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
13584 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
13585         if (IS_ERR(new_nsp->uts_ns)) {
13586                 err = PTR_ERR(new_nsp->uts_ns);
13587                 goto out_uts;
13588         }
13589  
13590 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
13591 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
13592         if (IS_ERR(new_nsp->ipc_ns)) {
13593                 err = PTR_ERR(new_nsp->ipc_ns);
13594                 goto out_ipc;
13595         }
13596  
13597 -       new_nsp->pid_ns_for_children =
13598 -               copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children);
13599 +       new_nsp->pid_ns_for_children = copy_pid_ns(flags, new_user, new_pid);
13600         if (IS_ERR(new_nsp->pid_ns_for_children)) {
13601                 err = PTR_ERR(new_nsp->pid_ns_for_children);
13602                 goto out_pid;
13603         }
13604  
13605 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
13606 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
13607         if (IS_ERR(new_nsp->net_ns)) {
13608                 err = PTR_ERR(new_nsp->net_ns);
13609                 goto out_net;
13610 @@ -117,6 +125,41 @@ out_ns:
13611         return ERR_PTR(err);
13612  }
13613  
13614 +static struct nsproxy *create_new_namespaces(unsigned long flags,
13615 +       struct task_struct *tsk, struct user_namespace *user_ns,
13616 +       struct fs_struct *new_fs)
13617 +
13618 +{
13619 +       return unshare_namespaces(flags, tsk->nsproxy,
13620 +               new_fs, user_ns, task_active_pid_ns(tsk));
13621 +}
13622 +
13623 +/*
13624 + * copies the nsproxy, setting refcount to 1, and grabbing a
13625 + * reference to all contained namespaces.
13626 + */
13627 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
13628 +{
13629 +       struct nsproxy *ns = create_nsproxy();
13630 +
13631 +       if (ns) {
13632 +               memcpy(ns, orig, sizeof(struct nsproxy));
13633 +               atomic_set(&ns->count, 1);
13634 +
13635 +               if (ns->mnt_ns)
13636 +                       get_mnt_ns(ns->mnt_ns);
13637 +               if (ns->uts_ns)
13638 +                       get_uts_ns(ns->uts_ns);
13639 +               if (ns->ipc_ns)
13640 +                       get_ipc_ns(ns->ipc_ns);
13641 +               if (ns->pid_ns_for_children)
13642 +                       get_pid_ns(ns->pid_ns_for_children);
13643 +               if (ns->net_ns)
13644 +                       get_net(ns->net_ns);
13645 +       }
13646 +       return ns;
13647 +}
13648 +
13649  /*
13650   * called from clone.  This now handles copy for nsproxy and all
13651   * namespaces therein.
13652 @@ -125,7 +168,10 @@ int copy_namespaces(unsigned long flags,
13653  {
13654         struct nsproxy *old_ns = tsk->nsproxy;
13655         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
13656 -       struct nsproxy *new_ns;
13657 +       struct nsproxy *new_ns = NULL;
13658 +
13659 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
13660 +               flags, tsk, old_ns);
13661  
13662         if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13663                               CLONE_NEWPID | CLONE_NEWNET)))) {
13664 @@ -133,7 +179,7 @@ int copy_namespaces(unsigned long flags,
13665                 return 0;
13666         }
13667  
13668 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13669 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags))
13670                 return -EPERM;
13671  
13672         /*
13673 @@ -152,6 +198,9 @@ int copy_namespaces(unsigned long flags,
13674                 return  PTR_ERR(new_ns);
13675  
13676         tsk->nsproxy = new_ns;
13677 +       vxdprintk(VXD_CBIT(space, 3),
13678 +               "copy_namespaces(0x%08lx,%p[%p]) = [%p]",
13679 +               flags, tsk, old_ns, new_ns);
13680         return 0;
13681  }
13682  
13683 @@ -165,7 +214,9 @@ void free_nsproxy(struct nsproxy *ns)
13684                 put_ipc_ns(ns->ipc_ns);
13685         if (ns->pid_ns_for_children)
13686                 put_pid_ns(ns->pid_ns_for_children);
13687 -       put_net(ns->net_ns);
13688 +       if (ns->net_ns)
13689 +               put_net(ns->net_ns);
13690 +       atomic_dec(&vs_global_nsproxy);
13691         kmem_cache_free(nsproxy_cachep, ns);
13692  }
13693  
13694 @@ -179,12 +230,16 @@ int unshare_nsproxy_namespaces(unsigned
13695         struct user_namespace *user_ns;
13696         int err = 0;
13697  
13698 +       vxdprintk(VXD_CBIT(space, 4),
13699 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
13700 +               unshare_flags, current->nsproxy);
13701 +
13702         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13703                                CLONE_NEWNET | CLONE_NEWPID)))
13704                 return 0;
13705  
13706         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
13707 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13708 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
13709                 return -EPERM;
13710  
13711         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
13712 diff -NurpP --minimal linux-3.13.10/kernel/pid.c linux-3.13.10-vs2.3.6.11/kernel/pid.c
13713 --- linux-3.13.10/kernel/pid.c  2013-11-25 15:47:03.000000000 +0000
13714 +++ linux-3.13.10-vs2.3.6.11/kernel/pid.c       2014-01-31 20:38:03.000000000 +0000
13715 @@ -38,6 +38,7 @@
13716  #include <linux/syscalls.h>
13717  #include <linux/proc_ns.h>
13718  #include <linux/proc_fs.h>
13719 +#include <linux/vs_pid.h>
13720  
13721  #define pid_hashfn(nr, ns)     \
13722         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
13723 @@ -373,7 +374,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
13724  
13725  struct pid *find_vpid(int nr)
13726  {
13727 -       return find_pid_ns(nr, task_active_pid_ns(current));
13728 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
13729  }
13730  EXPORT_SYMBOL_GPL(find_vpid);
13731  
13732 @@ -429,6 +430,9 @@ void transfer_pid(struct task_struct *ol
13733  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
13734  {
13735         struct task_struct *result = NULL;
13736 +
13737 +       if (type == PIDTYPE_REALPID)
13738 +               type = PIDTYPE_PID;
13739         if (pid) {
13740                 struct hlist_node *first;
13741                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
13742 @@ -448,7 +452,7 @@ struct task_struct *find_task_by_pid_ns(
13743         rcu_lockdep_assert(rcu_read_lock_held(),
13744                            "find_task_by_pid_ns() needs rcu_read_lock()"
13745                            " protection");
13746 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
13747 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
13748  }
13749  
13750  struct task_struct *find_task_by_vpid(pid_t vnr)
13751 @@ -492,7 +496,7 @@ struct pid *find_get_pid(pid_t nr)
13752  }
13753  EXPORT_SYMBOL_GPL(find_get_pid);
13754  
13755 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13756 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
13757  {
13758         struct upid *upid;
13759         pid_t nr = 0;
13760 @@ -506,6 +510,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
13761  }
13762  EXPORT_SYMBOL_GPL(pid_nr_ns);
13763  
13764 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13765 +{
13766 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
13767 +}
13768 +
13769  pid_t pid_vnr(struct pid *pid)
13770  {
13771         return pid_nr_ns(pid, task_active_pid_ns(current));
13772 diff -NurpP --minimal linux-3.13.10/kernel/pid_namespace.c linux-3.13.10-vs2.3.6.11/kernel/pid_namespace.c
13773 --- linux-3.13.10/kernel/pid_namespace.c        2014-01-22 20:39:13.000000000 +0000
13774 +++ linux-3.13.10-vs2.3.6.11/kernel/pid_namespace.c     2014-02-01 12:23:11.000000000 +0000
13775 @@ -18,6 +18,7 @@
13776  #include <linux/proc_ns.h>
13777  #include <linux/reboot.h>
13778  #include <linux/export.h>
13779 +#include <linux/vserver/global.h>
13780  
13781  struct pid_cache {
13782         int nr_ids;
13783 @@ -110,6 +111,7 @@ static struct pid_namespace *create_pid_
13784                 goto out_free_map;
13785  
13786         kref_init(&ns->kref);
13787 +       atomic_inc(&vs_global_pid_ns);
13788         ns->level = level;
13789         ns->parent = get_pid_ns(parent_pid_ns);
13790         ns->user_ns = get_user_ns(user_ns);
13791 @@ -127,6 +129,7 @@ static struct pid_namespace *create_pid_
13792  out_free_map:
13793         kfree(ns->pidmap[0].page);
13794  out_free:
13795 +       atomic_dec(&vs_global_pid_ns);
13796         kmem_cache_free(pid_ns_cachep, ns);
13797  out:
13798         return ERR_PTR(err);
13799 diff -NurpP --minimal linux-3.13.10/kernel/posix-timers.c linux-3.13.10-vs2.3.6.11/kernel/posix-timers.c
13800 --- linux-3.13.10/kernel/posix-timers.c 2013-07-14 17:01:35.000000000 +0000
13801 +++ linux-3.13.10-vs2.3.6.11/kernel/posix-timers.c      2014-01-31 20:38:03.000000000 +0000
13802 @@ -48,6 +48,7 @@
13803  #include <linux/workqueue.h>
13804  #include <linux/export.h>
13805  #include <linux/hashtable.h>
13806 +#include <linux/vs_context.h>
13807  
13808  /*
13809   * Management arrays for POSIX timers. Timers are now kept in static hash table
13810 @@ -398,6 +399,7 @@ int posix_timer_event(struct k_itimer *t
13811  {
13812         struct task_struct *task;
13813         int shared, ret = -1;
13814 +
13815         /*
13816          * FIXME: if ->sigq is queued we can race with
13817          * dequeue_signal()->do_schedule_next_timer().
13818 @@ -414,10 +416,18 @@ int posix_timer_event(struct k_itimer *t
13819         rcu_read_lock();
13820         task = pid_task(timr->it_pid, PIDTYPE_PID);
13821         if (task) {
13822 +               struct vx_info_save vxis;
13823 +               struct vx_info *vxi;
13824 +
13825 +               vxi = get_vx_info(task->vx_info);
13826 +               enter_vx_info(vxi, &vxis);
13827                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
13828                 ret = send_sigqueue(timr->sigq, task, shared);
13829 +               leave_vx_info(&vxis);
13830 +               put_vx_info(vxi);
13831         }
13832         rcu_read_unlock();
13833 +
13834         /* If we failed to send the signal the timer stops. */
13835         return ret > 0;
13836  }
13837 diff -NurpP --minimal linux-3.13.10/kernel/printk/printk.c linux-3.13.10-vs2.3.6.11/kernel/printk/printk.c
13838 --- linux-3.13.10/kernel/printk/printk.c        2014-04-17 01:12:39.000000000 +0000
13839 +++ linux-3.13.10-vs2.3.6.11/kernel/printk/printk.c     2014-04-17 01:17:11.000000000 +0000
13840 @@ -45,6 +45,7 @@
13841  #include <linux/poll.h>
13842  #include <linux/irq_work.h>
13843  #include <linux/utsname.h>
13844 +#include <linux/vs_cvirt.h>
13845  
13846  #include <asm/uaccess.h>
13847  
13848 @@ -386,7 +387,7 @@ static int check_syslog_permissions(int
13849                 return 0;
13850  
13851         if (syslog_action_restricted(type)) {
13852 -               if (capable(CAP_SYSLOG))
13853 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
13854                         return 0;
13855                 /*
13856                  * For historical reasons, accept CAP_SYS_ADMIN too, with
13857 @@ -1134,12 +1135,9 @@ int do_syslog(int type, char __user *buf
13858         if (error)
13859                 return error;
13860  
13861 -       switch (type) {
13862 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
13863 -               break;
13864 -       case SYSLOG_ACTION_OPEN:        /* Open log */
13865 -               break;
13866 -       case SYSLOG_ACTION_READ:        /* Read from log */
13867 +       if ((type == SYSLOG_ACTION_READ) ||
13868 +           (type == SYSLOG_ACTION_READ_ALL) ||
13869 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
13870                 error = -EINVAL;
13871                 if (!buf || len < 0)
13872                         goto out;
13873 @@ -1150,6 +1148,16 @@ int do_syslog(int type, char __user *buf
13874                         error = -EFAULT;
13875                         goto out;
13876                 }
13877 +       }
13878 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13879 +               return vx_do_syslog(type, buf, len);
13880 +
13881 +       switch (type) {
13882 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
13883 +               break;
13884 +       case SYSLOG_ACTION_OPEN:        /* Open log */
13885 +               break;
13886 +       case SYSLOG_ACTION_READ:        /* Read from log */
13887                 error = wait_event_interruptible(log_wait,
13888                                                  syslog_seq != log_next_seq);
13889                 if (error)
13890 @@ -1162,16 +1170,6 @@ int do_syslog(int type, char __user *buf
13891                 /* FALL THRU */
13892         /* Read last kernel messages */
13893         case SYSLOG_ACTION_READ_ALL:
13894 -               error = -EINVAL;
13895 -               if (!buf || len < 0)
13896 -                       goto out;
13897 -               error = 0;
13898 -               if (!len)
13899 -                       goto out;
13900 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
13901 -                       error = -EFAULT;
13902 -                       goto out;
13903 -               }
13904                 error = syslog_print_all(buf, len, clear);
13905                 break;
13906         /* Clear ring buffer */
13907 diff -NurpP --minimal linux-3.13.10/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/kernel/ptrace.c
13908 --- linux-3.13.10/kernel/ptrace.c       2014-01-22 20:39:13.000000000 +0000
13909 +++ linux-3.13.10-vs2.3.6.11/kernel/ptrace.c    2014-01-31 20:38:03.000000000 +0000
13910 @@ -23,6 +23,7 @@
13911  #include <linux/syscalls.h>
13912  #include <linux/uaccess.h>
13913  #include <linux/regset.h>
13914 +#include <linux/vs_context.h>
13915  #include <linux/hw_breakpoint.h>
13916  #include <linux/cn_proc.h>
13917  #include <linux/compat.h>
13918 @@ -264,6 +265,11 @@ ok:
13919         }
13920         rcu_read_unlock();
13921  
13922 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
13923 +               return -EPERM;
13924 +       if (!vx_check(task->xid, VS_IDENT) &&
13925 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
13926 +               return -EACCES;
13927         return security_ptrace_access_check(task, mode);
13928  }
13929  
13930 diff -NurpP --minimal linux-3.13.10/kernel/reboot.c linux-3.13.10-vs2.3.6.11/kernel/reboot.c
13931 --- linux-3.13.10/kernel/reboot.c       2014-01-22 20:39:13.000000000 +0000
13932 +++ linux-3.13.10-vs2.3.6.11/kernel/reboot.c    2014-02-01 00:19:40.000000000 +0000
13933 @@ -16,6 +16,7 @@
13934  #include <linux/syscalls.h>
13935  #include <linux/syscore_ops.h>
13936  #include <linux/uaccess.h>
13937 +#include <linux/vs_pid.h>
13938  
13939  /*
13940   * this indicates whether you can reboot with ctrl-alt-del: the default is yes
13941 @@ -188,6 +189,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
13942  
13943  static DEFINE_MUTEX(reboot_mutex);
13944  
13945 +long vs_reboot(unsigned int, void __user *);
13946 +
13947  /*
13948   * Reboot system call: for obvious reasons only root may call it,
13949   * and even root needs to set up some magic numbers in the registers
13950 @@ -230,6 +233,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
13951         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
13952                 cmd = LINUX_REBOOT_CMD_HALT;
13953  
13954 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
13955 +               return vs_reboot(cmd, arg);
13956 +
13957         mutex_lock(&reboot_mutex);
13958         switch (cmd) {
13959         case LINUX_REBOOT_CMD_RESTART:
13960 diff -NurpP --minimal linux-3.13.10/kernel/sched/core.c linux-3.13.10-vs2.3.6.11/kernel/sched/core.c
13961 --- linux-3.13.10/kernel/sched/core.c   2014-04-17 01:12:39.000000000 +0000
13962 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/core.c        2014-02-25 11:26:10.000000000 +0000
13963 @@ -73,6 +73,8 @@
13964  #include <linux/init_task.h>
13965  #include <linux/binfmts.h>
13966  #include <linux/context_tracking.h>
13967 +#include <linux/vs_sched.h>
13968 +#include <linux/vs_cvirt.h>
13969  
13970  #include <asm/switch_to.h>
13971  #include <asm/tlb.h>
13972 @@ -2927,7 +2929,7 @@ SYSCALL_DEFINE1(nice, int, increment)
13973                 nice = 19;
13974  
13975         if (increment < 0 && !can_nice(current, nice))
13976 -               return -EPERM;
13977 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
13978  
13979         retval = security_task_setnice(current, nice);
13980         if (retval)
13981 diff -NurpP --minimal linux-3.13.10/kernel/sched/cputime.c linux-3.13.10-vs2.3.6.11/kernel/sched/cputime.c
13982 --- linux-3.13.10/kernel/sched/cputime.c        2013-11-25 15:47:03.000000000 +0000
13983 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/cputime.c     2014-01-31 20:38:03.000000000 +0000
13984 @@ -4,6 +4,7 @@
13985  #include <linux/kernel_stat.h>
13986  #include <linux/static_key.h>
13987  #include <linux/context_tracking.h>
13988 +#include <linux/vs_sched.h>
13989  #include "sched.h"
13990  
13991  
13992 @@ -135,14 +136,17 @@ static inline void task_group_account_fi
13993  void account_user_time(struct task_struct *p, cputime_t cputime,
13994                        cputime_t cputime_scaled)
13995  {
13996 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
13997 +       int nice = (TASK_NICE(p) > 0);
13998         int index;
13999  
14000         /* Add user time to process. */
14001         p->utime += cputime;
14002         p->utimescaled += cputime_scaled;
14003 +       vx_account_user(vxi, cputime, nice);
14004         account_group_user_time(p, cputime);
14005  
14006 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14007 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14008  
14009         /* Add user time to cpustat. */
14010         task_group_account_field(p, index, (__force u64) cputime);
14011 @@ -189,9 +193,12 @@ static inline
14012  void __account_system_time(struct task_struct *p, cputime_t cputime,
14013                         cputime_t cputime_scaled, int index)
14014  {
14015 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14016 +
14017         /* Add system time to process. */
14018         p->stime += cputime;
14019         p->stimescaled += cputime_scaled;
14020 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14021         account_group_system_time(p, cputime);
14022  
14023         /* Add system time to cpustat. */
14024 diff -NurpP --minimal linux-3.13.10/kernel/sched/fair.c linux-3.13.10-vs2.3.6.11/kernel/sched/fair.c
14025 --- linux-3.13.10/kernel/sched/fair.c   2014-04-17 01:12:40.000000000 +0000
14026 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/fair.c        2014-04-17 01:17:11.000000000 +0000
14027 @@ -29,6 +29,7 @@
14028  #include <linux/mempolicy.h>
14029  #include <linux/migrate.h>
14030  #include <linux/task_work.h>
14031 +#include <linux/vs_cvirt.h>
14032  
14033  #include <trace/events/sched.h>
14034  
14035 @@ -2577,6 +2578,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14036                 __enqueue_entity(cfs_rq, se);
14037         se->on_rq = 1;
14038  
14039 +       if (entity_is_task(se))
14040 +               vx_activate_task(task_of(se));
14041         if (cfs_rq->nr_running == 1) {
14042                 list_add_leaf_cfs_rq(cfs_rq);
14043                 check_enqueue_throttle(cfs_rq);
14044 @@ -2658,6 +2661,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14045         if (se != cfs_rq->curr)
14046                 __dequeue_entity(cfs_rq, se);
14047         se->on_rq = 0;
14048 +       if (entity_is_task(se))
14049 +               vx_deactivate_task(task_of(se));
14050         account_entity_dequeue(cfs_rq, se);
14051  
14052         /*
14053 diff -NurpP --minimal linux-3.13.10/kernel/sched/proc.c linux-3.13.10-vs2.3.6.11/kernel/sched/proc.c
14054 --- linux-3.13.10/kernel/sched/proc.c   2013-11-25 15:45:08.000000000 +0000
14055 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/proc.c        2014-01-31 21:22:36.000000000 +0000
14056 @@ -78,9 +78,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14057   */
14058  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14059  {
14060 -       loads[0] = (avenrun[0] + offset) << shift;
14061 -       loads[1] = (avenrun[1] + offset) << shift;
14062 -       loads[2] = (avenrun[2] + offset) << shift;
14063 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14064 +               struct vx_info *vxi = current_vx_info();
14065 +
14066 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14067 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14068 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14069 +       } else {
14070 +               loads[0] = (avenrun[0] + offset) << shift;
14071 +               loads[1] = (avenrun[1] + offset) << shift;
14072 +               loads[2] = (avenrun[2] + offset) << shift;
14073 +       }
14074  }
14075  
14076  long calc_load_fold_active(struct rq *this_rq)
14077 diff -NurpP --minimal linux-3.13.10/kernel/signal.c linux-3.13.10-vs2.3.6.11/kernel/signal.c
14078 --- linux-3.13.10/kernel/signal.c       2014-01-22 20:39:13.000000000 +0000
14079 +++ linux-3.13.10-vs2.3.6.11/kernel/signal.c    2014-01-31 20:38:03.000000000 +0000
14080 @@ -33,6 +33,8 @@
14081  #include <linux/uprobes.h>
14082  #include <linux/compat.h>
14083  #include <linux/cn_proc.h>
14084 +#include <linux/vs_context.h>
14085 +#include <linux/vs_pid.h>
14086  #define CREATE_TRACE_POINTS
14087  #include <trace/events/signal.h>
14088  
14089 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14090         struct pid *sid;
14091         int error;
14092  
14093 +       vxdprintk(VXD_CBIT(misc, 7),
14094 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14095 +               sig, info, t, vx_task_xid(t), t->pid);
14096 +
14097         if (!valid_signal(sig))
14098                 return -EINVAL;
14099  
14100 +/*     FIXME: needed? if so, why?
14101 +       if ((info != SEND_SIG_NOINFO) &&
14102 +               (is_si_special(info) || !si_fromuser(info)))
14103 +               goto skip;      */
14104 +
14105         if (!si_fromuser(info))
14106                 return 0;
14107  
14108 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14109                 }
14110         }
14111  
14112 +       error = -EPERM;
14113 +       if (t->pid == 1 && current->xid)
14114 +               return error;
14115 +
14116 +       error = -ESRCH;
14117 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14118 +                 loops, maybe ENOENT or EACCES? */
14119 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14120 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14121 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14122 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14123 +               return error;
14124 +       }
14125 +/* skip: */
14126         return security_task_kill(t, info, sig, 0);
14127  }
14128  
14129 @@ -1353,7 +1378,7 @@ int kill_pid_info(int sig, struct siginf
14130         rcu_read_lock();
14131  retry:
14132         p = pid_task(pid, PIDTYPE_PID);
14133 -       if (p) {
14134 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14135                 error = group_send_sig_info(sig, info, p);
14136                 if (unlikely(error == -ESRCH))
14137                         /*
14138 @@ -1401,7 +1426,7 @@ int kill_pid_info_as_cred(int sig, struc
14139  
14140         rcu_read_lock();
14141         p = pid_task(pid, PIDTYPE_PID);
14142 -       if (!p) {
14143 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14144                 ret = -ESRCH;
14145                 goto out_unlock;
14146         }
14147 @@ -1453,8 +1478,10 @@ static int kill_something_info(int sig,
14148                 struct task_struct * p;
14149  
14150                 for_each_process(p) {
14151 -                       if (task_pid_vnr(p) > 1 &&
14152 -                                       !same_thread_group(p, current)) {
14153 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14154 +                               task_pid_vnr(p) > 1 &&
14155 +                               !same_thread_group(p, current) &&
14156 +                               !vx_current_initpid(p->pid)) {
14157                                 int err = group_send_sig_info(sig, info, p);
14158                                 ++count;
14159                                 if (err != -EPERM)
14160 @@ -2308,6 +2335,11 @@ relock:
14161                                 !sig_kernel_only(signr))
14162                         continue;
14163  
14164 +               /* virtual init is protected against user signals */
14165 +               if ((info->si_code == SI_USER) &&
14166 +                       vx_current_initpid(current->pid))
14167 +                       continue;
14168 +
14169                 if (sig_kernel_stop(signr)) {
14170                         /*
14171                          * The default action is to stop all threads in
14172 diff -NurpP --minimal linux-3.13.10/kernel/softirq.c linux-3.13.10-vs2.3.6.11/kernel/softirq.c
14173 --- linux-3.13.10/kernel/softirq.c      2014-01-22 20:39:13.000000000 +0000
14174 +++ linux-3.13.10-vs2.3.6.11/kernel/softirq.c   2014-01-31 20:38:03.000000000 +0000
14175 @@ -23,6 +23,7 @@
14176  #include <linux/smp.h>
14177  #include <linux/smpboot.h>
14178  #include <linux/tick.h>
14179 +#include <linux/vs_context.h>
14180  
14181  #define CREATE_TRACE_POINTS
14182  #include <trace/events/irq.h>
14183 diff -NurpP --minimal linux-3.13.10/kernel/sys.c linux-3.13.10-vs2.3.6.11/kernel/sys.c
14184 --- linux-3.13.10/kernel/sys.c  2014-01-22 20:39:13.000000000 +0000
14185 +++ linux-3.13.10-vs2.3.6.11/kernel/sys.c       2014-02-01 00:19:29.000000000 +0000
14186 @@ -54,6 +54,7 @@
14187  #include <linux/cred.h>
14188  
14189  #include <linux/kmsg_dump.h>
14190 +#include <linux/vs_pid.h>
14191  /* Move somewhere else to avoid recompiling? */
14192  #include <generated/utsrelease.h>
14193  
14194 @@ -145,7 +146,10 @@ static int set_one_prio(struct task_stru
14195                 goto out;
14196         }
14197         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14198 -               error = -EACCES;
14199 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14200 +                       error = 0;
14201 +               else
14202 +                       error = -EACCES;
14203                 goto out;
14204         }
14205         no_nice = security_task_setnice(p, niceval);
14206 @@ -196,6 +200,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14207                         else
14208                                 pgrp = task_pgrp(current);
14209                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14210 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14211 +                                       continue;
14212                                 error = set_one_prio(p, niceval, error);
14213                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14214                         break;
14215 @@ -261,6 +267,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14216                         else
14217                                 pgrp = task_pgrp(current);
14218                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14219 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14220 +                                       continue;
14221                                 niceval = 20 - task_nice(p);
14222                                 if (niceval > retval)
14223                                         retval = niceval;
14224 @@ -1198,7 +1206,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14225         int errno;
14226         char tmp[__NEW_UTS_LEN];
14227  
14228 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14229 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14230 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14231                 return -EPERM;
14232  
14233         if (len < 0 || len > __NEW_UTS_LEN)
14234 @@ -1249,7 +1258,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14235         int errno;
14236         char tmp[__NEW_UTS_LEN];
14237  
14238 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14239 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14240 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14241                 return -EPERM;
14242         if (len < 0 || len > __NEW_UTS_LEN)
14243                 return -EINVAL;
14244 @@ -1368,7 +1378,7 @@ int do_prlimit(struct task_struct *tsk,
14245                 /* Keep the capable check against init_user_ns until
14246                    cgroups can contain all limits */
14247                 if (new_rlim->rlim_max > rlim->rlim_max &&
14248 -                               !capable(CAP_SYS_RESOURCE))
14249 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14250                         retval = -EPERM;
14251                 if (!retval)
14252                         retval = security_task_setrlimit(tsk->group_leader,
14253 @@ -1421,7 +1431,8 @@ static int check_prlimit_permission(stru
14254             gid_eq(cred->gid, tcred->sgid) &&
14255             gid_eq(cred->gid, tcred->gid))
14256                 return 0;
14257 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14258 +       if (vx_ns_capable(tcred->user_ns,
14259 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14260                 return 0;
14261  
14262         return -EPERM;
14263 diff -NurpP --minimal linux-3.13.10/kernel/sysctl.c linux-3.13.10-vs2.3.6.11/kernel/sysctl.c
14264 --- linux-3.13.10/kernel/sysctl.c       2014-04-17 01:12:40.000000000 +0000
14265 +++ linux-3.13.10-vs2.3.6.11/kernel/sysctl.c    2014-02-25 11:26:10.000000000 +0000
14266 @@ -83,6 +83,7 @@
14267  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14268  #include <linux/lockdep.h>
14269  #endif
14270 +extern char vshelper_path[];
14271  #ifdef CONFIG_CHR_DEV_SG
14272  #include <scsi/sg.h>
14273  #endif
14274 @@ -650,6 +651,13 @@ static struct ctl_table kern_table[] = {
14275                 .mode           = 0644,
14276                 .proc_handler   = proc_dostring,
14277         },
14278 +       {
14279 +               .procname       = "vshelper",
14280 +               .data           = &vshelper_path,
14281 +               .maxlen         = 256,
14282 +               .mode           = 0644,
14283 +               .proc_handler   = &proc_dostring,
14284 +       },
14285  
14286  #ifdef CONFIG_CHR_DEV_SG
14287         {
14288 diff -NurpP --minimal linux-3.13.10/kernel/sysctl_binary.c linux-3.13.10-vs2.3.6.11/kernel/sysctl_binary.c
14289 --- linux-3.13.10/kernel/sysctl_binary.c        2014-01-22 20:39:13.000000000 +0000
14290 +++ linux-3.13.10-vs2.3.6.11/kernel/sysctl_binary.c     2014-01-31 20:38:03.000000000 +0000
14291 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
14292  
14293         { CTL_INT,      KERN_PANIC,                     "panic" },
14294         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
14295 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
14296  
14297         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
14298         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
14299 diff -NurpP --minimal linux-3.13.10/kernel/time/timekeeping.c linux-3.13.10-vs2.3.6.11/kernel/time/timekeeping.c
14300 --- linux-3.13.10/kernel/time/timekeeping.c     2014-04-17 01:12:40.000000000 +0000
14301 +++ linux-3.13.10-vs2.3.6.11/kernel/time/timekeeping.c  2014-02-25 11:26:10.000000000 +0000
14302 @@ -22,6 +22,7 @@
14303  #include <linux/tick.h>
14304  #include <linux/stop_machine.h>
14305  #include <linux/pvclock_gtod.h>
14306 +#include <linux/vs_time.h>
14307  
14308  #include "tick-internal.h"
14309  #include "ntp_internal.h"
14310 @@ -709,6 +710,7 @@ void getrawmonotonic(struct timespec *ts
14311         } while (read_seqcount_retry(&timekeeper_seq, seq));
14312  
14313         timespec_add_ns(ts, nsecs);
14314 +       vx_adjust_timespec(ts);
14315  }
14316  EXPORT_SYMBOL(getrawmonotonic);
14317  
14318 diff -NurpP --minimal linux-3.13.10/kernel/time.c linux-3.13.10-vs2.3.6.11/kernel/time.c
14319 --- linux-3.13.10/kernel/time.c 2013-11-25 15:45:08.000000000 +0000
14320 +++ linux-3.13.10-vs2.3.6.11/kernel/time.c      2014-01-31 20:38:03.000000000 +0000
14321 @@ -37,6 +37,7 @@
14322  #include <linux/fs.h>
14323  #include <linux/math64.h>
14324  #include <linux/ptrace.h>
14325 +#include <linux/vs_time.h>
14326  
14327  #include <asm/uaccess.h>
14328  #include <asm/unistd.h>
14329 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
14330         if (err)
14331                 return err;
14332  
14333 -       do_settimeofday(&tv);
14334 +       vx_settimeofday(&tv);
14335         return 0;
14336  }
14337  
14338 @@ -181,7 +182,7 @@ int do_sys_settimeofday(const struct tim
14339                 }
14340         }
14341         if (tv)
14342 -               return do_settimeofday(tv);
14343 +               return vx_settimeofday(tv);
14344         return 0;
14345  }
14346  
14347 diff -NurpP --minimal linux-3.13.10/kernel/timer.c linux-3.13.10-vs2.3.6.11/kernel/timer.c
14348 --- linux-3.13.10/kernel/timer.c        2014-01-22 20:39:13.000000000 +0000
14349 +++ linux-3.13.10-vs2.3.6.11/kernel/timer.c     2014-01-31 20:38:03.000000000 +0000
14350 @@ -42,6 +42,10 @@
14351  #include <linux/sched/sysctl.h>
14352  #include <linux/slab.h>
14353  #include <linux/compat.h>
14354 +#include <linux/vs_base.h>
14355 +#include <linux/vs_cvirt.h>
14356 +#include <linux/vs_pid.h>
14357 +#include <linux/vserver/sched.h>
14358  
14359  #include <asm/uaccess.h>
14360  #include <asm/unistd.h>
14361 diff -NurpP --minimal linux-3.13.10/kernel/user_namespace.c linux-3.13.10-vs2.3.6.11/kernel/user_namespace.c
14362 --- linux-3.13.10/kernel/user_namespace.c       2014-01-22 20:39:13.000000000 +0000
14363 +++ linux-3.13.10-vs2.3.6.11/kernel/user_namespace.c    2014-01-31 20:38:03.000000000 +0000
14364 @@ -22,6 +22,7 @@
14365  #include <linux/ctype.h>
14366  #include <linux/projid.h>
14367  #include <linux/fs_struct.h>
14368 +#include <linux/vserver/global.h>
14369  
14370  static struct kmem_cache *user_ns_cachep __read_mostly;
14371  
14372 @@ -94,6 +95,7 @@ int create_user_ns(struct cred *new)
14373  
14374         atomic_set(&ns->count, 1);
14375         /* Leave the new->user_ns reference with the new user namespace. */
14376 +       atomic_inc(&vs_global_user_ns);
14377         ns->parent = parent_ns;
14378         ns->level = parent_ns->level + 1;
14379         ns->owner = owner;
14380 @@ -848,6 +850,8 @@ static void *userns_get(struct task_stru
14381  
14382  static void userns_put(void *ns)
14383  {
14384 +       /* FIXME: maybe move into destroyer? */
14385 +       atomic_dec(&vs_global_user_ns);
14386         put_user_ns(ns);
14387  }
14388  
14389 diff -NurpP --minimal linux-3.13.10/kernel/utsname.c linux-3.13.10-vs2.3.6.11/kernel/utsname.c
14390 --- linux-3.13.10/kernel/utsname.c      2013-11-25 15:47:03.000000000 +0000
14391 +++ linux-3.13.10-vs2.3.6.11/kernel/utsname.c   2014-01-31 20:38:03.000000000 +0000
14392 @@ -16,14 +16,17 @@
14393  #include <linux/slab.h>
14394  #include <linux/user_namespace.h>
14395  #include <linux/proc_ns.h>
14396 +#include <linux/vserver/global.h>
14397  
14398  static struct uts_namespace *create_uts_ns(void)
14399  {
14400         struct uts_namespace *uts_ns;
14401  
14402         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
14403 -       if (uts_ns)
14404 +       if (uts_ns) {
14405                 kref_init(&uts_ns->kref);
14406 +               atomic_inc(&vs_global_uts_ns);
14407 +       }
14408         return uts_ns;
14409  }
14410  
14411 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
14412         ns = container_of(kref, struct uts_namespace, kref);
14413         put_user_ns(ns->user_ns);
14414         proc_free_inum(ns->proc_inum);
14415 +       atomic_dec(&vs_global_uts_ns);
14416         kfree(ns);
14417  }
14418  
14419 diff -NurpP --minimal linux-3.13.10/kernel/vserver/Kconfig linux-3.13.10-vs2.3.6.11/kernel/vserver/Kconfig
14420 --- linux-3.13.10/kernel/vserver/Kconfig        1970-01-01 00:00:00.000000000 +0000
14421 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/Kconfig     2014-01-31 20:38:03.000000000 +0000
14422 @@ -0,0 +1,230 @@
14423 +#
14424 +# Linux VServer configuration
14425 +#
14426 +
14427 +menu "Linux VServer"
14428 +
14429 +config VSERVER_AUTO_LBACK
14430 +       bool    "Automatically Assign Loopback IP"
14431 +       default y
14432 +       help
14433 +         Automatically assign a guest specific loopback
14434 +         IP and add it to the kernel network stack on
14435 +         startup.
14436 +
14437 +config VSERVER_AUTO_SINGLE
14438 +       bool    "Automatic Single IP Special Casing"
14439 +       default n
14440 +       help
14441 +         This allows network contexts with a single IP to
14442 +         automatically remap 0.0.0.0 bindings to that IP,
14443 +         avoiding further network checks and improving
14444 +         performance.
14445 +
14446 +         (note: such guests do not allow to change the ip
14447 +          on the fly and do not show loopback addresses)
14448 +
14449 +config VSERVER_COWBL
14450 +       bool    "Enable COW Immutable Link Breaking"
14451 +       default y
14452 +       help
14453 +         This enables the COW (Copy-On-Write) link break code.
14454 +         It allows you to treat unified files like normal files
14455 +         when writing to them (which will implicitely break the
14456 +         link and create a copy of the unified file)
14457 +
14458 +config VSERVER_VTIME
14459 +       bool    "Enable Virtualized Guest Time (EXPERIMENTAL)"
14460 +       default n
14461 +       help
14462 +         This enables per guest time offsets to allow for
14463 +         adjusting the system clock individually per guest.
14464 +         this adds some overhead to the time functions and
14465 +         therefore should not be enabled without good reason.
14466 +
14467 +config VSERVER_DEVICE
14468 +       bool    "Enable Guest Device Mapping (EXPERIMENTAL)"
14469 +       default n
14470 +       help
14471 +         This enables generic device remapping.
14472 +
14473 +config VSERVER_PROC_SECURE
14474 +       bool    "Enable Proc Security"
14475 +       depends on PROC_FS
14476 +       default y
14477 +       help
14478 +         This configures ProcFS security to initially hide
14479 +         non-process entries for all contexts except the main and
14480 +         spectator context (i.e. for all guests), which is a secure
14481 +         default.
14482 +
14483 +         (note: on 1.2x the entries were visible by default)
14484 +
14485 +choice
14486 +       prompt  "Persistent Inode Tagging"
14487 +       default TAGGING_ID24
14488 +       help
14489 +         This adds persistent context information to filesystems
14490 +         mounted with the tagxid option. Tagging is a requirement
14491 +         for per-context disk limits and per-context quota.
14492 +
14493 +
14494 +config TAGGING_NONE
14495 +       bool    "Disabled"
14496 +       help
14497 +         do not store per-context information in inodes.
14498 +
14499 +config TAGGING_UID16
14500 +       bool    "UID16/GID32"
14501 +       help
14502 +         reduces UID to 16 bit, but leaves GID at 32 bit.
14503 +
14504 +config TAGGING_GID16
14505 +       bool    "UID32/GID16"
14506 +       help
14507 +         reduces GID to 16 bit, but leaves UID at 32 bit.
14508 +
14509 +config TAGGING_ID24
14510 +       bool    "UID24/GID24"
14511 +       help
14512 +         uses the upper 8bit from UID and GID for XID tagging
14513 +         which leaves 24bit for UID/GID each, which should be
14514 +         more than sufficient for normal use.
14515 +
14516 +config TAGGING_INTERN
14517 +       bool    "UID32/GID32"
14518 +       help
14519 +         this uses otherwise reserved inode fields in the on
14520 +         disk representation, which limits the use to a few
14521 +         filesystems (currently ext2 and ext3)
14522 +
14523 +endchoice
14524 +
14525 +config TAG_NFSD
14526 +       bool    "Tag NFSD User Auth and Files"
14527 +       default n
14528 +       help
14529 +         Enable this if you do want the in-kernel NFS
14530 +         Server to use the tagging specified above.
14531 +         (will require patched clients too)
14532 +
14533 +config VSERVER_PRIVACY
14534 +       bool    "Honor Privacy Aspects of Guests"
14535 +       default n
14536 +       help
14537 +         When enabled, most context checks will disallow
14538 +         access to structures assigned to a specific context,
14539 +         like ptys or loop devices.
14540 +
14541 +config VSERVER_CONTEXTS
14542 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
14543 +       range 1 65533
14544 +       default "768"   if 64BIT
14545 +       default "256"
14546 +       help
14547 +         This setting will optimize certain data structures
14548 +         and memory allocations according to the expected
14549 +         maximum.
14550 +
14551 +         note: this is not a strict upper limit.
14552 +
14553 +config VSERVER_WARN
14554 +       bool    "VServer Warnings"
14555 +       default y
14556 +       help
14557 +         This enables various runtime warnings, which will
14558 +         notify about potential manipulation attempts or
14559 +         resource shortage. It is generally considered to
14560 +         be a good idea to have that enabled.
14561 +
14562 +config VSERVER_WARN_DEVPTS
14563 +       bool    "VServer DevPTS Warnings"
14564 +       depends on VSERVER_WARN
14565 +       default y
14566 +       help
14567 +         This enables DevPTS related warnings, issued when a
14568 +         process inside a context tries to lookup or access
14569 +         a dynamic pts from the host or a different context.
14570 +
14571 +config VSERVER_DEBUG
14572 +       bool    "VServer Debugging Code"
14573 +       default n
14574 +       help
14575 +         Set this to yes if you want to be able to activate
14576 +         debugging output at runtime. It adds a very small
14577 +         overhead to all vserver related functions and
14578 +         increases the kernel size by about 20k.
14579 +
14580 +config VSERVER_HISTORY
14581 +       bool    "VServer History Tracing"
14582 +       depends on VSERVER_DEBUG
14583 +       default n
14584 +       help
14585 +         Set this to yes if you want to record the history of
14586 +         linux-vserver activities, so they can be replayed in
14587 +         the event of a kernel panic or oops.
14588 +
14589 +config VSERVER_HISTORY_SIZE
14590 +       int     "Per-CPU History Size (32-65536)"
14591 +       depends on VSERVER_HISTORY
14592 +       range 32 65536
14593 +       default 64
14594 +       help
14595 +         This allows you to specify the number of entries in
14596 +         the per-CPU history buffer.
14597 +
14598 +config VSERVER_EXTRA_MNT_CHECK
14599 +       bool    "Extra Checks for Reachability"
14600 +       default n
14601 +       help
14602 +         Set this to yes if you want to do extra checks for
14603 +         vfsmount reachability in the proc filesystem code.
14604 +         This shouldn't be required on any setup utilizing
14605 +         mnt namespaces.
14606 +
14607 +choice
14608 +       prompt  "Quotes used in debug and warn messages"
14609 +       default QUOTES_ISO8859
14610 +
14611 +config QUOTES_ISO8859
14612 +       bool    "Extended ASCII (ISO 8859) angle quotes"
14613 +       help
14614 +         This uses the extended ASCII characters \xbb
14615 +         and \xab for quoting file and process names.
14616 +
14617 +config QUOTES_UTF8
14618 +       bool    "UTF-8 angle quotes"
14619 +       help
14620 +         This uses the the UTF-8 sequences for angle
14621 +         quotes to quote file and process names.
14622 +
14623 +config QUOTES_ASCII
14624 +       bool    "ASCII single quotes"
14625 +       help
14626 +         This uses the ASCII single quote character
14627 +         (\x27) to quote file and process names.
14628 +
14629 +endchoice
14630 +
14631 +endmenu
14632 +
14633 +
14634 +config VSERVER
14635 +       bool
14636 +       default y
14637 +       select NAMESPACES
14638 +       select UTS_NS
14639 +       select IPC_NS
14640 +#      select USER_NS
14641 +       select SYSVIPC
14642 +
14643 +config VSERVER_SECURITY
14644 +       bool
14645 +       depends on SECURITY
14646 +       default y
14647 +       select SECURITY_CAPABILITIES
14648 +
14649 +config VSERVER_DISABLED
14650 +       bool
14651 +       default n
14652 +
14653 diff -NurpP --minimal linux-3.13.10/kernel/vserver/Makefile linux-3.13.10-vs2.3.6.11/kernel/vserver/Makefile
14654 --- linux-3.13.10/kernel/vserver/Makefile       1970-01-01 00:00:00.000000000 +0000
14655 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/Makefile    2014-01-31 20:38:03.000000000 +0000
14656 @@ -0,0 +1,18 @@
14657 +#
14658 +# Makefile for the Linux vserver routines.
14659 +#
14660 +
14661 +
14662 +obj-y          += vserver.o
14663 +
14664 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
14665 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
14666 +                  dlimit.o tag.o
14667 +
14668 +vserver-$(CONFIG_INET) += inet.o
14669 +vserver-$(CONFIG_PROC_FS) += proc.o
14670 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
14671 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
14672 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
14673 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
14674 +
14675 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cacct.c linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct.c
14676 --- linux-3.13.10/kernel/vserver/cacct.c        1970-01-01 00:00:00.000000000 +0000
14677 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct.c     2014-01-31 20:38:03.000000000 +0000
14678 @@ -0,0 +1,42 @@
14679 +/*
14680 + *  linux/kernel/vserver/cacct.c
14681 + *
14682 + *  Virtual Server: Context Accounting
14683 + *
14684 + *  Copyright (C) 2006-2007 Herbert Pötzl
14685 + *
14686 + *  V0.01  added accounting stats
14687 + *
14688 + */
14689 +
14690 +#include <linux/types.h>
14691 +#include <linux/vs_context.h>
14692 +#include <linux/vserver/cacct_cmd.h>
14693 +#include <linux/vserver/cacct_int.h>
14694 +
14695 +#include <asm/errno.h>
14696 +#include <asm/uaccess.h>
14697 +
14698 +
14699 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
14700 +{
14701 +       struct vcmd_sock_stat_v0 vc_data;
14702 +       int j, field;
14703 +
14704 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
14705 +               return -EFAULT;
14706 +
14707 +       field = vc_data.field;
14708 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
14709 +               return -EINVAL;
14710 +
14711 +       for (j = 0; j < 3; j++) {
14712 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
14713 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
14714 +       }
14715 +
14716 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
14717 +               return -EFAULT;
14718 +       return 0;
14719 +}
14720 +
14721 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cacct_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_init.h
14722 --- linux-3.13.10/kernel/vserver/cacct_init.h   1970-01-01 00:00:00.000000000 +0000
14723 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_init.h        2014-01-31 20:38:03.000000000 +0000
14724 @@ -0,0 +1,25 @@
14725 +
14726 +
14727 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
14728 +{
14729 +       int i, j;
14730 +
14731 +
14732 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14733 +               for (j = 0; j < 3; j++) {
14734 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
14735 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
14736 +               }
14737 +       }
14738 +       for (i = 0; i < 8; i++)
14739 +               atomic_set(&cacct->slab[i], 0);
14740 +       for (i = 0; i < 5; i++)
14741 +               for (j = 0; j < 4; j++)
14742 +                       atomic_set(&cacct->page[i][j], 0);
14743 +}
14744 +
14745 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
14746 +{
14747 +       return;
14748 +}
14749 +
14750 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cacct_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_proc.h
14751 --- linux-3.13.10/kernel/vserver/cacct_proc.h   1970-01-01 00:00:00.000000000 +0000
14752 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_proc.h        2014-01-31 20:38:03.000000000 +0000
14753 @@ -0,0 +1,53 @@
14754 +#ifndef _VX_CACCT_PROC_H
14755 +#define _VX_CACCT_PROC_H
14756 +
14757 +#include <linux/vserver/cacct_int.h>
14758 +
14759 +
14760 +#define VX_SOCKA_TOP   \
14761 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
14762 +
14763 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
14764 +{
14765 +       int i, j, length = 0;
14766 +       static char *type[VXA_SOCK_SIZE] = {
14767 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
14768 +       };
14769 +
14770 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
14771 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
14772 +               length += sprintf(buffer + length, "%s:", type[i]);
14773 +               for (j = 0; j < 3; j++) {
14774 +                       length += sprintf(buffer + length,
14775 +                               "\t%10lu/%-10lu",
14776 +                               vx_sock_count(cacct, i, j),
14777 +                               vx_sock_total(cacct, i, j));
14778 +               }
14779 +               buffer[length++] = '\n';
14780 +       }
14781 +
14782 +       length += sprintf(buffer + length, "\n");
14783 +       length += sprintf(buffer + length,
14784 +               "slab:\t %8u %8u %8u %8u\n",
14785 +               atomic_read(&cacct->slab[1]),
14786 +               atomic_read(&cacct->slab[4]),
14787 +               atomic_read(&cacct->slab[0]),
14788 +               atomic_read(&cacct->slab[2]));
14789 +
14790 +       length += sprintf(buffer + length, "\n");
14791 +       for (i = 0; i < 5; i++) {
14792 +               length += sprintf(buffer + length,
14793 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
14794 +                       atomic_read(&cacct->page[i][0]),
14795 +                       atomic_read(&cacct->page[i][1]),
14796 +                       atomic_read(&cacct->page[i][2]),
14797 +                       atomic_read(&cacct->page[i][3]),
14798 +                       atomic_read(&cacct->page[i][4]),
14799 +                       atomic_read(&cacct->page[i][5]),
14800 +                       atomic_read(&cacct->page[i][6]),
14801 +                       atomic_read(&cacct->page[i][7]));
14802 +       }
14803 +       return length;
14804 +}
14805 +
14806 +#endif /* _VX_CACCT_PROC_H */
14807 diff -NurpP --minimal linux-3.13.10/kernel/vserver/context.c linux-3.13.10-vs2.3.6.11/kernel/vserver/context.c
14808 --- linux-3.13.10/kernel/vserver/context.c      1970-01-01 00:00:00.000000000 +0000
14809 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/context.c   2014-01-31 20:38:03.000000000 +0000
14810 @@ -0,0 +1,1119 @@
14811 +/*
14812 + *  linux/kernel/vserver/context.c
14813 + *
14814 + *  Virtual Server: Context Support
14815 + *
14816 + *  Copyright (C) 2003-2011  Herbert Pötzl
14817 + *
14818 + *  V0.01  context helper
14819 + *  V0.02  vx_ctx_kill syscall command
14820 + *  V0.03  replaced context_info calls
14821 + *  V0.04  redesign of struct (de)alloc
14822 + *  V0.05  rlimit basic implementation
14823 + *  V0.06  task_xid and info commands
14824 + *  V0.07  context flags and caps
14825 + *  V0.08  switch to RCU based hash
14826 + *  V0.09  revert to non RCU for now
14827 + *  V0.10  and back to working RCU hash
14828 + *  V0.11  and back to locking again
14829 + *  V0.12  referenced context store
14830 + *  V0.13  separate per cpu data
14831 + *  V0.14  changed vcmds to vxi arg
14832 + *  V0.15  added context stat
14833 + *  V0.16  have __create claim() the vxi
14834 + *  V0.17  removed older and legacy stuff
14835 + *  V0.18  added user credentials
14836 + *  V0.19  added warn mask
14837 + *
14838 + */
14839 +
14840 +#include <linux/slab.h>
14841 +#include <linux/types.h>
14842 +#include <linux/security.h>
14843 +#include <linux/pid_namespace.h>
14844 +#include <linux/capability.h>
14845 +
14846 +#include <linux/vserver/context.h>
14847 +#include <linux/vserver/network.h>
14848 +#include <linux/vserver/debug.h>
14849 +#include <linux/vserver/limit.h>
14850 +#include <linux/vserver/limit_int.h>
14851 +#include <linux/vserver/space.h>
14852 +#include <linux/init_task.h>
14853 +#include <linux/fs_struct.h>
14854 +#include <linux/cred.h>
14855 +
14856 +#include <linux/vs_context.h>
14857 +#include <linux/vs_limit.h>
14858 +#include <linux/vs_pid.h>
14859 +#include <linux/vserver/context_cmd.h>
14860 +
14861 +#include "cvirt_init.h"
14862 +#include "cacct_init.h"
14863 +#include "limit_init.h"
14864 +#include "sched_init.h"
14865 +
14866 +
14867 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
14868 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
14869 +
14870 +
14871 +/*     now inactive context structures */
14872 +
14873 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
14874 +
14875 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
14876 +
14877 +
14878 +/*     __alloc_vx_info()
14879 +
14880 +       * allocate an initialized vx_info struct
14881 +       * doesn't make it visible (hash)                        */
14882 +
14883 +static struct vx_info *__alloc_vx_info(vxid_t xid)
14884 +{
14885 +       struct vx_info *new = NULL;
14886 +       int cpu, index;
14887 +
14888 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
14889 +
14890 +       /* would this benefit from a slab cache? */
14891 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
14892 +       if (!new)
14893 +               return 0;
14894 +
14895 +       memset(new, 0, sizeof(struct vx_info));
14896 +#ifdef CONFIG_SMP
14897 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
14898 +       if (!new->ptr_pc)
14899 +               goto error;
14900 +#endif
14901 +       new->vx_id = xid;
14902 +       INIT_HLIST_NODE(&new->vx_hlist);
14903 +       atomic_set(&new->vx_usecnt, 0);
14904 +       atomic_set(&new->vx_tasks, 0);
14905 +       new->vx_parent = NULL;
14906 +       new->vx_state = 0;
14907 +       init_waitqueue_head(&new->vx_wait);
14908 +
14909 +       /* prepare reaper */
14910 +       get_task_struct(init_pid_ns.child_reaper);
14911 +       new->vx_reaper = init_pid_ns.child_reaper;
14912 +       new->vx_badness_bias = 0;
14913 +
14914 +       /* rest of init goes here */
14915 +       vx_info_init_limit(&new->limit);
14916 +       vx_info_init_sched(&new->sched);
14917 +       vx_info_init_cvirt(&new->cvirt);
14918 +       vx_info_init_cacct(&new->cacct);
14919 +
14920 +       /* per cpu data structures */
14921 +       for_each_possible_cpu(cpu) {
14922 +               vx_info_init_sched_pc(
14923 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
14924 +               vx_info_init_cvirt_pc(
14925 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
14926 +       }
14927 +
14928 +       new->vx_flags = VXF_INIT_SET;
14929 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
14930 +       new->vx_ccaps = 0;
14931 +       new->vx_umask = 0;
14932 +       new->vx_wmask = 0;
14933 +
14934 +       new->reboot_cmd = 0;
14935 +       new->exit_code = 0;
14936 +
14937 +       // preconfig spaces
14938 +       for (index = 0; index < VX_SPACES; index++) {
14939 +               struct _vx_space *space = &new->space[index];
14940 +
14941 +               // filesystem
14942 +               spin_lock(&init_fs.lock);
14943 +               init_fs.users++;
14944 +               spin_unlock(&init_fs.lock);
14945 +               space->vx_fs = &init_fs;
14946 +
14947 +               /* FIXME: do we want defaults? */
14948 +               // space->vx_real_cred = 0;
14949 +               // space->vx_cred = 0;
14950 +       }
14951 +
14952 +
14953 +       vxdprintk(VXD_CBIT(xid, 0),
14954 +               "alloc_vx_info(%d) = %p", xid, new);
14955 +       vxh_alloc_vx_info(new);
14956 +       atomic_inc(&vx_global_ctotal);
14957 +       return new;
14958 +#ifdef CONFIG_SMP
14959 +error:
14960 +       kfree(new);
14961 +       return 0;
14962 +#endif
14963 +}
14964 +
14965 +/*     __dealloc_vx_info()
14966 +
14967 +       * final disposal of vx_info                             */
14968 +
14969 +static void __dealloc_vx_info(struct vx_info *vxi)
14970 +{
14971 +#ifdef CONFIG_VSERVER_WARN
14972 +       struct vx_info_save vxis;
14973 +       int cpu;
14974 +#endif
14975 +       vxdprintk(VXD_CBIT(xid, 0),
14976 +               "dealloc_vx_info(%p)", vxi);
14977 +       vxh_dealloc_vx_info(vxi);
14978 +
14979 +#ifdef CONFIG_VSERVER_WARN
14980 +       enter_vx_info(vxi, &vxis);
14981 +       vx_info_exit_limit(&vxi->limit);
14982 +       vx_info_exit_sched(&vxi->sched);
14983 +       vx_info_exit_cvirt(&vxi->cvirt);
14984 +       vx_info_exit_cacct(&vxi->cacct);
14985 +
14986 +       for_each_possible_cpu(cpu) {
14987 +               vx_info_exit_sched_pc(
14988 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
14989 +               vx_info_exit_cvirt_pc(
14990 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
14991 +       }
14992 +       leave_vx_info(&vxis);
14993 +#endif
14994 +
14995 +       vxi->vx_id = -1;
14996 +       vxi->vx_state |= VXS_RELEASED;
14997 +
14998 +#ifdef CONFIG_SMP
14999 +       free_percpu(vxi->ptr_pc);
15000 +#endif
15001 +       kfree(vxi);
15002 +       atomic_dec(&vx_global_ctotal);
15003 +}
15004 +
15005 +static void __shutdown_vx_info(struct vx_info *vxi)
15006 +{
15007 +       struct nsproxy *nsproxy;
15008 +       struct fs_struct *fs;
15009 +       struct cred *cred;
15010 +       int index, kill;
15011 +
15012 +       might_sleep();
15013 +
15014 +       vxi->vx_state |= VXS_SHUTDOWN;
15015 +       vs_state_change(vxi, VSC_SHUTDOWN);
15016 +
15017 +       for (index = 0; index < VX_SPACES; index++) {
15018 +               struct _vx_space *space = &vxi->space[index];
15019 +
15020 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15021 +               if (nsproxy)
15022 +                       put_nsproxy(nsproxy);
15023 +
15024 +               fs = xchg(&space->vx_fs, NULL);
15025 +               spin_lock(&fs->lock);
15026 +               kill = !--fs->users;
15027 +               spin_unlock(&fs->lock);
15028 +               if (kill)
15029 +                       free_fs_struct(fs);
15030 +
15031 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15032 +               if (cred)
15033 +                       abort_creds(cred);
15034 +       }
15035 +}
15036 +
15037 +/* exported stuff */
15038 +
15039 +void free_vx_info(struct vx_info *vxi)
15040 +{
15041 +       unsigned long flags;
15042 +       unsigned index;
15043 +
15044 +       /* check for reference counts first */
15045 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15046 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15047 +
15048 +       /* context must not be hashed */
15049 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15050 +
15051 +       /* context shutdown is mandatory */
15052 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15053 +
15054 +       /* spaces check */
15055 +       for (index = 0; index < VX_SPACES; index++) {
15056 +               struct _vx_space *space = &vxi->space[index];
15057 +
15058 +               BUG_ON(space->vx_nsproxy);
15059 +               BUG_ON(space->vx_fs);
15060 +               // BUG_ON(space->vx_real_cred);
15061 +               // BUG_ON(space->vx_cred);
15062 +       }
15063 +
15064 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15065 +       hlist_del(&vxi->vx_hlist);
15066 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15067 +
15068 +       __dealloc_vx_info(vxi);
15069 +}
15070 +
15071 +
15072 +/*     hash table for vx_info hash */
15073 +
15074 +#define VX_HASH_SIZE   13
15075 +
15076 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15077 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15078 +
15079 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15080 +
15081 +
15082 +static inline unsigned int __hashval(vxid_t xid)
15083 +{
15084 +       return (xid % VX_HASH_SIZE);
15085 +}
15086 +
15087 +
15088 +
15089 +/*     __hash_vx_info()
15090 +
15091 +       * add the vxi to the global hash table
15092 +       * requires the hash_lock to be held                     */
15093 +
15094 +static inline void __hash_vx_info(struct vx_info *vxi)
15095 +{
15096 +       struct hlist_head *head;
15097 +
15098 +       vxd_assert_lock(&vx_info_hash_lock);
15099 +       vxdprintk(VXD_CBIT(xid, 4),
15100 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15101 +       vxh_hash_vx_info(vxi);
15102 +
15103 +       /* context must not be hashed */
15104 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15105 +
15106 +       vxi->vx_state |= VXS_HASHED;
15107 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15108 +       hlist_add_head(&vxi->vx_hlist, head);
15109 +       atomic_inc(&vx_global_cactive);
15110 +}
15111 +
15112 +/*     __unhash_vx_info()
15113 +
15114 +       * remove the vxi from the global hash table
15115 +       * requires the hash_lock to be held                     */
15116 +
15117 +static inline void __unhash_vx_info(struct vx_info *vxi)
15118 +{
15119 +       unsigned long flags;
15120 +
15121 +       vxd_assert_lock(&vx_info_hash_lock);
15122 +       vxdprintk(VXD_CBIT(xid, 4),
15123 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15124 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15125 +       vxh_unhash_vx_info(vxi);
15126 +
15127 +       /* context must be hashed */
15128 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15129 +       /* but without tasks */
15130 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15131 +
15132 +       vxi->vx_state &= ~VXS_HASHED;
15133 +       hlist_del_init(&vxi->vx_hlist);
15134 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15135 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15136 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15137 +       atomic_dec(&vx_global_cactive);
15138 +}
15139 +
15140 +
15141 +/*     __lookup_vx_info()
15142 +
15143 +       * requires the hash_lock to be held
15144 +       * doesn't increment the vx_refcnt                       */
15145 +
15146 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
15147 +{
15148 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15149 +       struct hlist_node *pos;
15150 +       struct vx_info *vxi;
15151 +
15152 +       vxd_assert_lock(&vx_info_hash_lock);
15153 +       hlist_for_each(pos, head) {
15154 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15155 +
15156 +               if (vxi->vx_id == xid)
15157 +                       goto found;
15158 +       }
15159 +       vxi = NULL;
15160 +found:
15161 +       vxdprintk(VXD_CBIT(xid, 0),
15162 +               "__lookup_vx_info(#%u): %p[#%u]",
15163 +               xid, vxi, vxi ? vxi->vx_id : 0);
15164 +       vxh_lookup_vx_info(vxi, xid);
15165 +       return vxi;
15166 +}
15167 +
15168 +
15169 +/*     __create_vx_info()
15170 +
15171 +       * create the requested context
15172 +       * get(), claim() and hash it                            */
15173 +
15174 +static struct vx_info *__create_vx_info(int id)
15175 +{
15176 +       struct vx_info *new, *vxi = NULL;
15177 +
15178 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15179 +
15180 +       if (!(new = __alloc_vx_info(id)))
15181 +               return ERR_PTR(-ENOMEM);
15182 +
15183 +       /* required to make dynamic xids unique */
15184 +       spin_lock(&vx_info_hash_lock);
15185 +
15186 +       /* static context requested */
15187 +       if ((vxi = __lookup_vx_info(id))) {
15188 +               vxdprintk(VXD_CBIT(xid, 0),
15189 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15190 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15191 +                       vxi = ERR_PTR(-EBUSY);
15192 +               else
15193 +                       vxi = ERR_PTR(-EEXIST);
15194 +               goto out_unlock;
15195 +       }
15196 +       /* new context */
15197 +       vxdprintk(VXD_CBIT(xid, 0),
15198 +               "create_vx_info(%d) = %p (new)", id, new);
15199 +       claim_vx_info(new, NULL);
15200 +       __hash_vx_info(get_vx_info(new));
15201 +       vxi = new, new = NULL;
15202 +
15203 +out_unlock:
15204 +       spin_unlock(&vx_info_hash_lock);
15205 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15206 +       if (new)
15207 +               __dealloc_vx_info(new);
15208 +       return vxi;
15209 +}
15210 +
15211 +
15212 +/*     exported stuff                                          */
15213 +
15214 +
15215 +void unhash_vx_info(struct vx_info *vxi)
15216 +{
15217 +       spin_lock(&vx_info_hash_lock);
15218 +       __unhash_vx_info(vxi);
15219 +       spin_unlock(&vx_info_hash_lock);
15220 +       __shutdown_vx_info(vxi);
15221 +       __wakeup_vx_info(vxi);
15222 +}
15223 +
15224 +
15225 +/*     lookup_vx_info()
15226 +
15227 +       * search for a vx_info and get() it
15228 +       * negative id means current                             */
15229 +
15230 +struct vx_info *lookup_vx_info(int id)
15231 +{
15232 +       struct vx_info *vxi = NULL;
15233 +
15234 +       if (id < 0) {
15235 +               vxi = get_vx_info(current_vx_info());
15236 +       } else if (id > 1) {
15237 +               spin_lock(&vx_info_hash_lock);
15238 +               vxi = get_vx_info(__lookup_vx_info(id));
15239 +               spin_unlock(&vx_info_hash_lock);
15240 +       }
15241 +       return vxi;
15242 +}
15243 +
15244 +/*     xid_is_hashed()
15245 +
15246 +       * verify that xid is still hashed                       */
15247 +
15248 +int xid_is_hashed(vxid_t xid)
15249 +{
15250 +       int hashed;
15251 +
15252 +       spin_lock(&vx_info_hash_lock);
15253 +       hashed = (__lookup_vx_info(xid) != NULL);
15254 +       spin_unlock(&vx_info_hash_lock);
15255 +       return hashed;
15256 +}
15257 +
15258 +#ifdef CONFIG_PROC_FS
15259 +
15260 +/*     get_xid_list()
15261 +
15262 +       * get a subset of hashed xids for proc
15263 +       * assumes size is at least one                          */
15264 +
15265 +int get_xid_list(int index, unsigned int *xids, int size)
15266 +{
15267 +       int hindex, nr_xids = 0;
15268 +
15269 +       /* only show current and children */
15270 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15271 +               if (index > 0)
15272 +                       return 0;
15273 +               xids[nr_xids] = vx_current_xid();
15274 +               return 1;
15275 +       }
15276 +
15277 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15278 +               struct hlist_head *head = &vx_info_hash[hindex];
15279 +               struct hlist_node *pos;
15280 +
15281 +               spin_lock(&vx_info_hash_lock);
15282 +               hlist_for_each(pos, head) {
15283 +                       struct vx_info *vxi;
15284 +
15285 +                       if (--index > 0)
15286 +                               continue;
15287 +
15288 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15289 +                       xids[nr_xids] = vxi->vx_id;
15290 +                       if (++nr_xids >= size) {
15291 +                               spin_unlock(&vx_info_hash_lock);
15292 +                               goto out;
15293 +                       }
15294 +               }
15295 +               /* keep the lock time short */
15296 +               spin_unlock(&vx_info_hash_lock);
15297 +       }
15298 +out:
15299 +       return nr_xids;
15300 +}
15301 +#endif
15302 +
15303 +#ifdef CONFIG_VSERVER_DEBUG
15304 +
15305 +void   dump_vx_info_inactive(int level)
15306 +{
15307 +       struct hlist_node *entry, *next;
15308 +
15309 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
15310 +               struct vx_info *vxi =
15311 +                       list_entry(entry, struct vx_info, vx_hlist);
15312 +
15313 +               dump_vx_info(vxi, level);
15314 +       }
15315 +}
15316 +
15317 +#endif
15318 +
15319 +#if 0
15320 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
15321 +{
15322 +       struct user_struct *new_user, *old_user;
15323 +
15324 +       if (!p || !vxi)
15325 +               BUG();
15326 +
15327 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
15328 +               return -EACCES;
15329 +
15330 +       new_user = alloc_uid(vxi->vx_id, p->uid);
15331 +       if (!new_user)
15332 +               return -ENOMEM;
15333 +
15334 +       old_user = p->user;
15335 +       if (new_user != old_user) {
15336 +               atomic_inc(&new_user->processes);
15337 +               atomic_dec(&old_user->processes);
15338 +               p->user = new_user;
15339 +       }
15340 +       free_uid(old_user);
15341 +       return 0;
15342 +}
15343 +#endif
15344 +
15345 +#if 0
15346 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
15347 +{
15348 +       // p->cap_effective &= vxi->vx_cap_bset;
15349 +       p->cap_effective =
15350 +               cap_intersect(p->cap_effective, vxi->cap_bset);
15351 +       // p->cap_inheritable &= vxi->vx_cap_bset;
15352 +       p->cap_inheritable =
15353 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
15354 +       // p->cap_permitted &= vxi->vx_cap_bset;
15355 +       p->cap_permitted =
15356 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
15357 +}
15358 +#endif
15359 +
15360 +
15361 +#include <linux/file.h>
15362 +#include <linux/fdtable.h>
15363 +
15364 +static int vx_openfd_task(struct task_struct *tsk)
15365 +{
15366 +       struct files_struct *files = tsk->files;
15367 +       struct fdtable *fdt;
15368 +       const unsigned long *bptr;
15369 +       int count, total;
15370 +
15371 +       /* no rcu_read_lock() because of spin_lock() */
15372 +       spin_lock(&files->file_lock);
15373 +       fdt = files_fdtable(files);
15374 +       bptr = fdt->open_fds;
15375 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
15376 +       for (total = 0; count > 0; count--) {
15377 +               if (*bptr)
15378 +                       total += hweight_long(*bptr);
15379 +               bptr++;
15380 +       }
15381 +       spin_unlock(&files->file_lock);
15382 +       return total;
15383 +}
15384 +
15385 +
15386 +/*     for *space compatibility */
15387 +
15388 +asmlinkage long sys_unshare(unsigned long);
15389 +
15390 +/*
15391 + *     migrate task to new context
15392 + *     gets vxi, puts old_vxi on change
15393 + *     optionally unshares namespaces (hack)
15394 + */
15395 +
15396 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
15397 +{
15398 +       struct vx_info *old_vxi;
15399 +       int ret = 0;
15400 +
15401 +       if (!p || !vxi)
15402 +               BUG();
15403 +
15404 +       vxdprintk(VXD_CBIT(xid, 5),
15405 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
15406 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
15407 +
15408 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
15409 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15410 +               return -EACCES;
15411 +
15412 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
15413 +               return -EFAULT;
15414 +
15415 +       old_vxi = task_get_vx_info(p);
15416 +       if (old_vxi == vxi)
15417 +               goto out;
15418 +
15419 +//     if (!(ret = vx_migrate_user(p, vxi))) {
15420 +       {
15421 +               int openfd;
15422 +
15423 +               task_lock(p);
15424 +               openfd = vx_openfd_task(p);
15425 +
15426 +               if (old_vxi) {
15427 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
15428 +                       atomic_dec(&old_vxi->cvirt.nr_running);
15429 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
15430 +                       /* FIXME: what about the struct files here? */
15431 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
15432 +                       /* account for the executable */
15433 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
15434 +               }
15435 +               atomic_inc(&vxi->cvirt.nr_threads);
15436 +               atomic_inc(&vxi->cvirt.nr_running);
15437 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
15438 +               /* FIXME: what about the struct files here? */
15439 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
15440 +               /* account for the executable */
15441 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
15442 +
15443 +               if (old_vxi) {
15444 +                       release_vx_info(old_vxi, p);
15445 +                       clr_vx_info(&p->vx_info);
15446 +               }
15447 +               claim_vx_info(vxi, p);
15448 +               set_vx_info(&p->vx_info, vxi);
15449 +               p->xid = vxi->vx_id;
15450 +
15451 +               vxdprintk(VXD_CBIT(xid, 5),
15452 +                       "moved task %p into vxi:%p[#%d]",
15453 +                       p, vxi, vxi->vx_id);
15454 +
15455 +               // vx_mask_cap_bset(vxi, p);
15456 +               task_unlock(p);
15457 +
15458 +               /* hack for *spaces to provide compatibility */
15459 +               if (unshare) {
15460 +                       struct nsproxy *old_nsp, *new_nsp;
15461 +
15462 +                       ret = unshare_nsproxy_namespaces(
15463 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
15464 +                               &new_nsp, NULL, NULL);
15465 +                       if (ret)
15466 +                               goto out;
15467 +
15468 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
15469 +                       vx_set_space(vxi,
15470 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
15471 +                       put_nsproxy(old_nsp);
15472 +               }
15473 +       }
15474 +out:
15475 +       put_vx_info(old_vxi);
15476 +       return ret;
15477 +}
15478 +
15479 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
15480 +{
15481 +       struct task_struct *old_reaper;
15482 +       struct vx_info *reaper_vxi;
15483 +
15484 +       if (!vxi)
15485 +               return -EINVAL;
15486 +
15487 +       vxdprintk(VXD_CBIT(xid, 6),
15488 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
15489 +               vxi, vxi->vx_id, p, p->xid, p->pid);
15490 +
15491 +       old_reaper = vxi->vx_reaper;
15492 +       if (old_reaper == p)
15493 +               return 0;
15494 +
15495 +       reaper_vxi = task_get_vx_info(p);
15496 +       if (reaper_vxi && reaper_vxi != vxi) {
15497 +               vxwprintk(1,
15498 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
15499 +                       "for [xid #%u]",
15500 +                       p->comm, p->pid, p->xid, vx_current_xid());
15501 +               goto out;
15502 +       }
15503 +
15504 +       /* set new child reaper */
15505 +       get_task_struct(p);
15506 +       vxi->vx_reaper = p;
15507 +       put_task_struct(old_reaper);
15508 +out:
15509 +       put_vx_info(reaper_vxi);
15510 +       return 0;
15511 +}
15512 +
15513 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
15514 +{
15515 +       if (!vxi)
15516 +               return -EINVAL;
15517 +
15518 +       vxdprintk(VXD_CBIT(xid, 6),
15519 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
15520 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15521 +
15522 +       vxi->vx_flags &= ~VXF_STATE_INIT;
15523 +       // vxi->vx_initpid = p->tgid;
15524 +       vxi->vx_initpid = p->pid;
15525 +       return 0;
15526 +}
15527 +
15528 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
15529 +{
15530 +       vxdprintk(VXD_CBIT(xid, 6),
15531 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
15532 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15533 +
15534 +       vxi->exit_code = code;
15535 +       vxi->vx_initpid = 0;
15536 +}
15537 +
15538 +
15539 +void vx_set_persistent(struct vx_info *vxi)
15540 +{
15541 +       vxdprintk(VXD_CBIT(xid, 6),
15542 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
15543 +
15544 +       get_vx_info(vxi);
15545 +       claim_vx_info(vxi, NULL);
15546 +}
15547 +
15548 +void vx_clear_persistent(struct vx_info *vxi)
15549 +{
15550 +       vxdprintk(VXD_CBIT(xid, 6),
15551 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
15552 +
15553 +       release_vx_info(vxi, NULL);
15554 +       put_vx_info(vxi);
15555 +}
15556 +
15557 +void vx_update_persistent(struct vx_info *vxi)
15558 +{
15559 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
15560 +               vx_set_persistent(vxi);
15561 +       else
15562 +               vx_clear_persistent(vxi);
15563 +}
15564 +
15565 +
15566 +/*     task must be current or locked          */
15567 +
15568 +void   exit_vx_info(struct task_struct *p, int code)
15569 +{
15570 +       struct vx_info *vxi = p->vx_info;
15571 +
15572 +       if (vxi) {
15573 +               atomic_dec(&vxi->cvirt.nr_threads);
15574 +               vx_nproc_dec(p);
15575 +
15576 +               vxi->exit_code = code;
15577 +               release_vx_info(vxi, p);
15578 +       }
15579 +}
15580 +
15581 +void   exit_vx_info_early(struct task_struct *p, int code)
15582 +{
15583 +       struct vx_info *vxi = p->vx_info;
15584 +
15585 +       if (vxi) {
15586 +               if (vxi->vx_initpid == p->pid)
15587 +                       vx_exit_init(vxi, p, code);
15588 +               if (vxi->vx_reaper == p)
15589 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
15590 +       }
15591 +}
15592 +
15593 +
15594 +/* vserver syscall commands below here */
15595 +
15596 +/* taks xid and vx_info functions */
15597 +
15598 +#include <asm/uaccess.h>
15599 +
15600 +
15601 +int vc_task_xid(uint32_t id)
15602 +{
15603 +       vxid_t xid;
15604 +
15605 +       if (id) {
15606 +               struct task_struct *tsk;
15607 +
15608 +               rcu_read_lock();
15609 +               tsk = find_task_by_real_pid(id);
15610 +               xid = (tsk) ? tsk->xid : -ESRCH;
15611 +               rcu_read_unlock();
15612 +       } else
15613 +               xid = vx_current_xid();
15614 +       return xid;
15615 +}
15616 +
15617 +
15618 +int vc_vx_info(struct vx_info *vxi, void __user *data)
15619 +{
15620 +       struct vcmd_vx_info_v0 vc_data;
15621 +
15622 +       vc_data.xid = vxi->vx_id;
15623 +       vc_data.initpid = vxi->vx_initpid;
15624 +
15625 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15626 +               return -EFAULT;
15627 +       return 0;
15628 +}
15629 +
15630 +
15631 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
15632 +{
15633 +       struct vcmd_ctx_stat_v0 vc_data;
15634 +
15635 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
15636 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
15637 +
15638 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15639 +               return -EFAULT;
15640 +       return 0;
15641 +}
15642 +
15643 +
15644 +/* context functions */
15645 +
15646 +int vc_ctx_create(uint32_t xid, void __user *data)
15647 +{
15648 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
15649 +       struct vx_info *new_vxi;
15650 +       int ret;
15651 +
15652 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15653 +               return -EFAULT;
15654 +
15655 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
15656 +               return -EINVAL;
15657 +
15658 +       new_vxi = __create_vx_info(xid);
15659 +       if (IS_ERR(new_vxi))
15660 +               return PTR_ERR(new_vxi);
15661 +
15662 +       /* initial flags */
15663 +       new_vxi->vx_flags = vc_data.flagword;
15664 +
15665 +       ret = -ENOEXEC;
15666 +       if (vs_state_change(new_vxi, VSC_STARTUP))
15667 +               goto out;
15668 +
15669 +       ret = vx_migrate_task(current, new_vxi, (!data));
15670 +       if (ret)
15671 +               goto out;
15672 +
15673 +       /* return context id on success */
15674 +       ret = new_vxi->vx_id;
15675 +
15676 +       /* get a reference for persistent contexts */
15677 +       if ((vc_data.flagword & VXF_PERSISTENT))
15678 +               vx_set_persistent(new_vxi);
15679 +out:
15680 +       release_vx_info(new_vxi, NULL);
15681 +       put_vx_info(new_vxi);
15682 +       return ret;
15683 +}
15684 +
15685 +
15686 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
15687 +{
15688 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
15689 +       int ret;
15690 +
15691 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15692 +               return -EFAULT;
15693 +
15694 +       ret = vx_migrate_task(current, vxi, 0);
15695 +       if (ret)
15696 +               return ret;
15697 +       if (vc_data.flagword & VXM_SET_INIT)
15698 +               ret = vx_set_init(vxi, current);
15699 +       if (ret)
15700 +               return ret;
15701 +       if (vc_data.flagword & VXM_SET_REAPER)
15702 +               ret = vx_set_reaper(vxi, current);
15703 +       return ret;
15704 +}
15705 +
15706 +
15707 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
15708 +{
15709 +       struct vcmd_ctx_flags_v0 vc_data;
15710 +
15711 +       vc_data.flagword = vxi->vx_flags;
15712 +
15713 +       /* special STATE flag handling */
15714 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
15715 +
15716 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15717 +               return -EFAULT;
15718 +       return 0;
15719 +}
15720 +
15721 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
15722 +{
15723 +       struct vcmd_ctx_flags_v0 vc_data;
15724 +       uint64_t mask, trigger;
15725 +
15726 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15727 +               return -EFAULT;
15728 +
15729 +       /* special STATE flag handling */
15730 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
15731 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
15732 +
15733 +       if (vxi == current_vx_info()) {
15734 +               /* if (trigger & VXF_STATE_SETUP)
15735 +                       vx_mask_cap_bset(vxi, current); */
15736 +               if (trigger & VXF_STATE_INIT) {
15737 +                       int ret;
15738 +
15739 +                       ret = vx_set_init(vxi, current);
15740 +                       if (ret)
15741 +                               return ret;
15742 +                       ret = vx_set_reaper(vxi, current);
15743 +                       if (ret)
15744 +                               return ret;
15745 +               }
15746 +       }
15747 +
15748 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
15749 +               vc_data.flagword, mask);
15750 +       if (trigger & VXF_PERSISTENT)
15751 +               vx_update_persistent(vxi);
15752 +
15753 +       return 0;
15754 +}
15755 +
15756 +
15757 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
15758 +{
15759 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
15760 +
15761 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
15762 +       return v;
15763 +}
15764 +
15765 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
15766 +{
15767 +       kernel_cap_t c = __cap_empty_set;
15768 +
15769 +       c.cap[0] = v & 0xFFFFFFFF;
15770 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
15771 +
15772 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
15773 +       return c;
15774 +}
15775 +
15776 +
15777 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
15778 +{
15779 +       if (bcaps)
15780 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
15781 +       if (ccaps)
15782 +               *ccaps = vxi->vx_ccaps;
15783 +
15784 +       return 0;
15785 +}
15786 +
15787 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
15788 +{
15789 +       struct vcmd_ctx_caps_v1 vc_data;
15790 +       int ret;
15791 +
15792 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
15793 +       if (ret)
15794 +               return ret;
15795 +       vc_data.cmask = ~0ULL;
15796 +
15797 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15798 +               return -EFAULT;
15799 +       return 0;
15800 +}
15801 +
15802 +static int do_set_caps(struct vx_info *vxi,
15803 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
15804 +{
15805 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
15806 +
15807 +#if 0
15808 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
15809 +               bcaps, bmask, ccaps, cmask);
15810 +#endif
15811 +       vxi->vx_bcaps = cap_t_from_caps(
15812 +               vs_mask_flags(bcold, bcaps, bmask));
15813 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
15814 +
15815 +       return 0;
15816 +}
15817 +
15818 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
15819 +{
15820 +       struct vcmd_ctx_caps_v1 vc_data;
15821 +
15822 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15823 +               return -EFAULT;
15824 +
15825 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
15826 +}
15827 +
15828 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
15829 +{
15830 +       struct vcmd_bcaps vc_data;
15831 +       int ret;
15832 +
15833 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
15834 +       if (ret)
15835 +               return ret;
15836 +       vc_data.bmask = ~0ULL;
15837 +
15838 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15839 +               return -EFAULT;
15840 +       return 0;
15841 +}
15842 +
15843 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
15844 +{
15845 +       struct vcmd_bcaps vc_data;
15846 +
15847 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15848 +               return -EFAULT;
15849 +
15850 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
15851 +}
15852 +
15853 +
15854 +int vc_get_umask(struct vx_info *vxi, void __user *data)
15855 +{
15856 +       struct vcmd_umask vc_data;
15857 +
15858 +       vc_data.umask = vxi->vx_umask;
15859 +       vc_data.mask = ~0ULL;
15860 +
15861 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15862 +               return -EFAULT;
15863 +       return 0;
15864 +}
15865 +
15866 +int vc_set_umask(struct vx_info *vxi, void __user *data)
15867 +{
15868 +       struct vcmd_umask vc_data;
15869 +
15870 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15871 +               return -EFAULT;
15872 +
15873 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
15874 +               vc_data.umask, vc_data.mask);
15875 +       return 0;
15876 +}
15877 +
15878 +
15879 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
15880 +{
15881 +       struct vcmd_wmask vc_data;
15882 +
15883 +       vc_data.wmask = vxi->vx_wmask;
15884 +       vc_data.mask = ~0ULL;
15885 +
15886 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15887 +               return -EFAULT;
15888 +       return 0;
15889 +}
15890 +
15891 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
15892 +{
15893 +       struct vcmd_wmask vc_data;
15894 +
15895 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15896 +               return -EFAULT;
15897 +
15898 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
15899 +               vc_data.wmask, vc_data.mask);
15900 +       return 0;
15901 +}
15902 +
15903 +
15904 +int vc_get_badness(struct vx_info *vxi, void __user *data)
15905 +{
15906 +       struct vcmd_badness_v0 vc_data;
15907 +
15908 +       vc_data.bias = vxi->vx_badness_bias;
15909 +
15910 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15911 +               return -EFAULT;
15912 +       return 0;
15913 +}
15914 +
15915 +int vc_set_badness(struct vx_info *vxi, void __user *data)
15916 +{
15917 +       struct vcmd_badness_v0 vc_data;
15918 +
15919 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15920 +               return -EFAULT;
15921 +
15922 +       vxi->vx_badness_bias = vc_data.bias;
15923 +       return 0;
15924 +}
15925 +
15926 +#include <linux/module.h>
15927 +
15928 +EXPORT_SYMBOL_GPL(free_vx_info);
15929 +
15930 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cvirt.c linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt.c
15931 --- linux-3.13.10/kernel/vserver/cvirt.c        1970-01-01 00:00:00.000000000 +0000
15932 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt.c     2014-01-31 20:38:04.000000000 +0000
15933 @@ -0,0 +1,313 @@
15934 +/*
15935 + *  linux/kernel/vserver/cvirt.c
15936 + *
15937 + *  Virtual Server: Context Virtualization
15938 + *
15939 + *  Copyright (C) 2004-2007  Herbert Pötzl
15940 + *
15941 + *  V0.01  broken out from limit.c
15942 + *  V0.02  added utsname stuff
15943 + *  V0.03  changed vcmds to vxi arg
15944 + *
15945 + */
15946 +
15947 +#include <linux/types.h>
15948 +#include <linux/utsname.h>
15949 +#include <linux/vs_cvirt.h>
15950 +#include <linux/vserver/switch.h>
15951 +#include <linux/vserver/cvirt_cmd.h>
15952 +
15953 +#include <asm/uaccess.h>
15954 +
15955 +
15956 +void vx_vsi_boottime(struct timespec *boottime)
15957 +{
15958 +       struct vx_info *vxi = current_vx_info();
15959 +
15960 +       set_normalized_timespec(boottime,
15961 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
15962 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
15963 +       return;
15964 +}
15965 +
15966 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
15967 +{
15968 +       struct vx_info *vxi = current_vx_info();
15969 +
15970 +       set_normalized_timespec(uptime,
15971 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
15972 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
15973 +       if (!idle)
15974 +               return;
15975 +       set_normalized_timespec(idle,
15976 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
15977 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
15978 +       return;
15979 +}
15980 +
15981 +uint64_t vx_idle_jiffies(void)
15982 +{
15983 +       return init_task.utime + init_task.stime;
15984 +}
15985 +
15986 +
15987 +
15988 +static inline uint32_t __update_loadavg(uint32_t load,
15989 +       int wsize, int delta, int n)
15990 +{
15991 +       unsigned long long calc, prev;
15992 +
15993 +       /* just set it to n */
15994 +       if (unlikely(delta >= wsize))
15995 +               return (n << FSHIFT);
15996 +
15997 +       calc = delta * n;
15998 +       calc <<= FSHIFT;
15999 +       prev = (wsize - delta);
16000 +       prev *= load;
16001 +       calc += prev;
16002 +       do_div(calc, wsize);
16003 +       return calc;
16004 +}
16005 +
16006 +
16007 +void vx_update_load(struct vx_info *vxi)
16008 +{
16009 +       uint32_t now, last, delta;
16010 +       unsigned int nr_running, nr_uninterruptible;
16011 +       unsigned int total;
16012 +       unsigned long flags;
16013 +
16014 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16015 +
16016 +       now = jiffies;
16017 +       last = vxi->cvirt.load_last;
16018 +       delta = now - last;
16019 +
16020 +       if (delta < 5*HZ)
16021 +               goto out;
16022 +
16023 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16024 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16025 +       total = nr_running + nr_uninterruptible;
16026 +
16027 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16028 +               60*HZ, delta, total);
16029 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16030 +               5*60*HZ, delta, total);
16031 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16032 +               15*60*HZ, delta, total);
16033 +
16034 +       vxi->cvirt.load_last = now;
16035 +out:
16036 +       atomic_inc(&vxi->cvirt.load_updates);
16037 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16038 +}
16039 +
16040 +
16041 +/*
16042 + * Commands to do_syslog:
16043 + *
16044 + *      0 -- Close the log.  Currently a NOP.
16045 + *      1 -- Open the log. Currently a NOP.
16046 + *      2 -- Read from the log.
16047 + *      3 -- Read all messages remaining in the ring buffer.
16048 + *      4 -- Read and clear all messages remaining in the ring buffer
16049 + *      5 -- Clear ring buffer.
16050 + *      6 -- Disable printk's to console
16051 + *      7 -- Enable printk's to console
16052 + *      8 -- Set level of messages printed to console
16053 + *      9 -- Return number of unread characters in the log buffer
16054 + *     10 -- Return size of the log buffer
16055 + */
16056 +int vx_do_syslog(int type, char __user *buf, int len)
16057 +{
16058 +       int error = 0;
16059 +       int do_clear = 0;
16060 +       struct vx_info *vxi = current_vx_info();
16061 +       struct _vx_syslog *log;
16062 +
16063 +       if (!vxi)
16064 +               return -EINVAL;
16065 +       log = &vxi->cvirt.syslog;
16066 +
16067 +       switch (type) {
16068 +       case 0:         /* Close log */
16069 +       case 1:         /* Open log */
16070 +               break;
16071 +       case 2:         /* Read from log */
16072 +               error = wait_event_interruptible(log->log_wait,
16073 +                       (log->log_start - log->log_end));
16074 +               if (error)
16075 +                       break;
16076 +               spin_lock_irq(&log->logbuf_lock);
16077 +               spin_unlock_irq(&log->logbuf_lock);
16078 +               break;
16079 +       case 4:         /* Read/clear last kernel messages */
16080 +               do_clear = 1;
16081 +               /* fall through */
16082 +       case 3:         /* Read last kernel messages */
16083 +               return 0;
16084 +
16085 +       case 5:         /* Clear ring buffer */
16086 +               return 0;
16087 +
16088 +       case 6:         /* Disable logging to console */
16089 +       case 7:         /* Enable logging to console */
16090 +       case 8:         /* Set level of messages printed to console */
16091 +               break;
16092 +
16093 +       case 9:         /* Number of chars in the log buffer */
16094 +               return 0;
16095 +       case 10:        /* Size of the log buffer */
16096 +               return 0;
16097 +       default:
16098 +               error = -EINVAL;
16099 +               break;
16100 +       }
16101 +       return error;
16102 +}
16103 +
16104 +
16105 +/* virtual host info names */
16106 +
16107 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16108 +{
16109 +       struct nsproxy *nsproxy;
16110 +       struct uts_namespace *uts;
16111 +
16112 +       if (id == VHIN_CONTEXT)
16113 +               return vxi->vx_name;
16114 +
16115 +       nsproxy = vxi->space[0].vx_nsproxy;
16116 +       if (!nsproxy)
16117 +               return NULL;
16118 +
16119 +       uts = nsproxy->uts_ns;
16120 +       if (!uts)
16121 +               return NULL;
16122 +
16123 +       switch (id) {
16124 +       case VHIN_SYSNAME:
16125 +               return uts->name.sysname;
16126 +       case VHIN_NODENAME:
16127 +               return uts->name.nodename;
16128 +       case VHIN_RELEASE:
16129 +               return uts->name.release;
16130 +       case VHIN_VERSION:
16131 +               return uts->name.version;
16132 +       case VHIN_MACHINE:
16133 +               return uts->name.machine;
16134 +       case VHIN_DOMAINNAME:
16135 +               return uts->name.domainname;
16136 +       default:
16137 +               return NULL;
16138 +       }
16139 +       return NULL;
16140 +}
16141 +
16142 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16143 +{
16144 +       struct vcmd_vhi_name_v0 vc_data;
16145 +       char *name;
16146 +
16147 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16148 +               return -EFAULT;
16149 +
16150 +       name = vx_vhi_name(vxi, vc_data.field);
16151 +       if (!name)
16152 +               return -EINVAL;
16153 +
16154 +       memcpy(name, vc_data.name, 65);
16155 +       return 0;
16156 +}
16157 +
16158 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16159 +{
16160 +       struct vcmd_vhi_name_v0 vc_data;
16161 +       char *name;
16162 +
16163 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16164 +               return -EFAULT;
16165 +
16166 +       name = vx_vhi_name(vxi, vc_data.field);
16167 +       if (!name)
16168 +               return -EINVAL;
16169 +
16170 +       memcpy(vc_data.name, name, 65);
16171 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16172 +               return -EFAULT;
16173 +       return 0;
16174 +}
16175 +
16176 +
16177 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16178 +{
16179 +       struct vcmd_virt_stat_v0 vc_data;
16180 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16181 +       struct timespec uptime;
16182 +
16183 +       do_posix_clock_monotonic_gettime(&uptime);
16184 +       set_normalized_timespec(&uptime,
16185 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16186 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16187 +
16188 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16189 +       vc_data.uptime = timespec_to_ns(&uptime);
16190 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16191 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16192 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16193 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16194 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16195 +       vc_data.load[0] = cvirt->load[0];
16196 +       vc_data.load[1] = cvirt->load[1];
16197 +       vc_data.load[2] = cvirt->load[2];
16198 +
16199 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16200 +               return -EFAULT;
16201 +       return 0;
16202 +}
16203 +
16204 +
16205 +#ifdef CONFIG_VSERVER_VTIME
16206 +
16207 +/* virtualized time base */
16208 +
16209 +void vx_adjust_timespec(struct timespec *ts)
16210 +{
16211 +       struct vx_info *vxi;
16212 +
16213 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16214 +               return;
16215 +
16216 +       vxi = current_vx_info();
16217 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16218 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16219 +
16220 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
16221 +               ts->tv_sec++;
16222 +               ts->tv_nsec -= NSEC_PER_SEC;
16223 +       } else if (ts->tv_nsec < 0) {
16224 +               ts->tv_sec--;
16225 +               ts->tv_nsec += NSEC_PER_SEC;
16226 +       }
16227 +}
16228 +
16229 +int vx_settimeofday(const struct timespec *ts)
16230 +{
16231 +       struct timespec ats, delta;
16232 +       struct vx_info *vxi;
16233 +
16234 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16235 +               return do_settimeofday(ts);
16236 +
16237 +       getnstimeofday(&ats);
16238 +       delta = timespec_sub(*ts, ats);
16239 +
16240 +       vxi = current_vx_info();
16241 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16242 +       return 0;
16243 +}
16244 +
16245 +#endif
16246 +
16247 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cvirt_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_init.h
16248 --- linux-3.13.10/kernel/vserver/cvirt_init.h   1970-01-01 00:00:00.000000000 +0000
16249 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_init.h        2014-01-31 20:38:04.000000000 +0000
16250 @@ -0,0 +1,70 @@
16251 +
16252 +
16253 +extern uint64_t vx_idle_jiffies(void);
16254 +
16255 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16256 +{
16257 +       uint64_t idle_jiffies = vx_idle_jiffies();
16258 +       uint64_t nsuptime;
16259 +
16260 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16261 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16262 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16263 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16264 +       cvirt->bias_ts.tv_sec = 0;
16265 +       cvirt->bias_ts.tv_nsec = 0;
16266 +
16267 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16268 +       atomic_set(&cvirt->nr_threads, 0);
16269 +       atomic_set(&cvirt->nr_running, 0);
16270 +       atomic_set(&cvirt->nr_uninterruptible, 0);
16271 +       atomic_set(&cvirt->nr_onhold, 0);
16272 +
16273 +       spin_lock_init(&cvirt->load_lock);
16274 +       cvirt->load_last = jiffies;
16275 +       atomic_set(&cvirt->load_updates, 0);
16276 +       cvirt->load[0] = 0;
16277 +       cvirt->load[1] = 0;
16278 +       cvirt->load[2] = 0;
16279 +       atomic_set(&cvirt->total_forks, 0);
16280 +
16281 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
16282 +       init_waitqueue_head(&cvirt->syslog.log_wait);
16283 +       cvirt->syslog.log_start = 0;
16284 +       cvirt->syslog.log_end = 0;
16285 +       cvirt->syslog.con_start = 0;
16286 +       cvirt->syslog.logged_chars = 0;
16287 +}
16288 +
16289 +static inline
16290 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16291 +{
16292 +       // cvirt_pc->cpustat = { 0 };
16293 +}
16294 +
16295 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16296 +{
16297 +#ifdef CONFIG_VSERVER_WARN
16298 +       int value;
16299 +#endif
16300 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16301 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
16302 +               cvirt, value);
16303 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16304 +               "!!! cvirt: %p[nr_running] = %d on exit.",
16305 +               cvirt, value);
16306 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16307 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16308 +               cvirt, value);
16309 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16310 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
16311 +               cvirt, value);
16312 +       return;
16313 +}
16314 +
16315 +static inline
16316 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16317 +{
16318 +       return;
16319 +}
16320 +
16321 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cvirt_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_proc.h
16322 --- linux-3.13.10/kernel/vserver/cvirt_proc.h   1970-01-01 00:00:00.000000000 +0000
16323 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_proc.h        2014-01-31 20:38:04.000000000 +0000
16324 @@ -0,0 +1,123 @@
16325 +#ifndef _VX_CVIRT_PROC_H
16326 +#define _VX_CVIRT_PROC_H
16327 +
16328 +#include <linux/nsproxy.h>
16329 +#include <linux/mnt_namespace.h>
16330 +#include <linux/ipc_namespace.h>
16331 +#include <linux/utsname.h>
16332 +#include <linux/ipc.h>
16333 +
16334 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
16335 +
16336 +static inline
16337 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
16338 +{
16339 +       struct mnt_namespace *ns;
16340 +       struct uts_namespace *uts;
16341 +       struct ipc_namespace *ipc;
16342 +       int length = 0;
16343 +
16344 +       if (!nsproxy)
16345 +               goto out;
16346 +
16347 +       length += sprintf(buffer + length,
16348 +               "NSProxy:\t%p [%p,%p,%p]\n",
16349 +               nsproxy, nsproxy->mnt_ns,
16350 +               nsproxy->uts_ns, nsproxy->ipc_ns);
16351 +
16352 +       ns = nsproxy->mnt_ns;
16353 +       if (!ns)
16354 +               goto skip_ns;
16355 +
16356 +       length += vx_info_mnt_namespace(ns, buffer + length);
16357 +
16358 +skip_ns:
16359 +
16360 +       uts = nsproxy->uts_ns;
16361 +       if (!uts)
16362 +               goto skip_uts;
16363 +
16364 +       length += sprintf(buffer + length,
16365 +               "SysName:\t%.*s\n"
16366 +               "NodeName:\t%.*s\n"
16367 +               "Release:\t%.*s\n"
16368 +               "Version:\t%.*s\n"
16369 +               "Machine:\t%.*s\n"
16370 +               "DomainName:\t%.*s\n",
16371 +               __NEW_UTS_LEN, uts->name.sysname,
16372 +               __NEW_UTS_LEN, uts->name.nodename,
16373 +               __NEW_UTS_LEN, uts->name.release,
16374 +               __NEW_UTS_LEN, uts->name.version,
16375 +               __NEW_UTS_LEN, uts->name.machine,
16376 +               __NEW_UTS_LEN, uts->name.domainname);
16377 +skip_uts:
16378 +
16379 +       ipc = nsproxy->ipc_ns;
16380 +       if (!ipc)
16381 +               goto skip_ipc;
16382 +
16383 +       length += sprintf(buffer + length,
16384 +               "SEMS:\t\t%d %d %d %d  %d\n"
16385 +               "MSG:\t\t%d %d %d\n"
16386 +               "SHM:\t\t%lu %lu  %d %ld\n",
16387 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
16388 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
16389 +               ipc->used_sems,
16390 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
16391 +               (unsigned long)ipc->shm_ctlmax,
16392 +               (unsigned long)ipc->shm_ctlall,
16393 +               ipc->shm_ctlmni, ipc->shm_tot);
16394 +skip_ipc:
16395 +out:
16396 +       return length;
16397 +}
16398 +
16399 +
16400 +#include <linux/sched.h>
16401 +
16402 +#define LOAD_INT(x) ((x) >> FSHIFT)
16403 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
16404 +
16405 +static inline
16406 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
16407 +{
16408 +       int length = 0;
16409 +       int a, b, c;
16410 +
16411 +       length += sprintf(buffer + length,
16412 +               "BiasUptime:\t%lu.%02lu\n",
16413 +               (unsigned long)cvirt->bias_uptime.tv_sec,
16414 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
16415 +
16416 +       a = cvirt->load[0] + (FIXED_1 / 200);
16417 +       b = cvirt->load[1] + (FIXED_1 / 200);
16418 +       c = cvirt->load[2] + (FIXED_1 / 200);
16419 +       length += sprintf(buffer + length,
16420 +               "nr_threads:\t%d\n"
16421 +               "nr_running:\t%d\n"
16422 +               "nr_unintr:\t%d\n"
16423 +               "nr_onhold:\t%d\n"
16424 +               "load_updates:\t%d\n"
16425 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
16426 +               "total_forks:\t%d\n",
16427 +               atomic_read(&cvirt->nr_threads),
16428 +               atomic_read(&cvirt->nr_running),
16429 +               atomic_read(&cvirt->nr_uninterruptible),
16430 +               atomic_read(&cvirt->nr_onhold),
16431 +               atomic_read(&cvirt->load_updates),
16432 +               LOAD_INT(a), LOAD_FRAC(a),
16433 +               LOAD_INT(b), LOAD_FRAC(b),
16434 +               LOAD_INT(c), LOAD_FRAC(c),
16435 +               atomic_read(&cvirt->total_forks));
16436 +       return length;
16437 +}
16438 +
16439 +static inline
16440 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
16441 +       char *buffer, int cpu)
16442 +{
16443 +       int length = 0;
16444 +       return length;
16445 +}
16446 +
16447 +#endif /* _VX_CVIRT_PROC_H */
16448 diff -NurpP --minimal linux-3.13.10/kernel/vserver/debug.c linux-3.13.10-vs2.3.6.11/kernel/vserver/debug.c
16449 --- linux-3.13.10/kernel/vserver/debug.c        1970-01-01 00:00:00.000000000 +0000
16450 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/debug.c     2014-01-31 20:38:04.000000000 +0000
16451 @@ -0,0 +1,32 @@
16452 +/*
16453 + *  kernel/vserver/debug.c
16454 + *
16455 + *  Copyright (C) 2005-2007 Herbert Pötzl
16456 + *
16457 + *  V0.01  vx_info dump support
16458 + *
16459 + */
16460 +
16461 +#include <linux/module.h>
16462 +
16463 +#include <linux/vserver/context.h>
16464 +
16465 +
16466 +void   dump_vx_info(struct vx_info *vxi, int level)
16467 +{
16468 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
16469 +               atomic_read(&vxi->vx_usecnt),
16470 +               atomic_read(&vxi->vx_tasks),
16471 +               vxi->vx_state);
16472 +       if (level > 0) {
16473 +               __dump_vx_limit(&vxi->limit);
16474 +               __dump_vx_sched(&vxi->sched);
16475 +               __dump_vx_cvirt(&vxi->cvirt);
16476 +               __dump_vx_cacct(&vxi->cacct);
16477 +       }
16478 +       printk("---\n");
16479 +}
16480 +
16481 +
16482 +EXPORT_SYMBOL_GPL(dump_vx_info);
16483 +
16484 diff -NurpP --minimal linux-3.13.10/kernel/vserver/device.c linux-3.13.10-vs2.3.6.11/kernel/vserver/device.c
16485 --- linux-3.13.10/kernel/vserver/device.c       1970-01-01 00:00:00.000000000 +0000
16486 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/device.c    2014-01-31 20:38:04.000000000 +0000
16487 @@ -0,0 +1,443 @@
16488 +/*
16489 + *  linux/kernel/vserver/device.c
16490 + *
16491 + *  Linux-VServer: Device Support
16492 + *
16493 + *  Copyright (C) 2006  Herbert Pötzl
16494 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
16495 + *
16496 + *  V0.01  device mapping basics
16497 + *  V0.02  added defaults
16498 + *
16499 + */
16500 +
16501 +#include <linux/slab.h>
16502 +#include <linux/rcupdate.h>
16503 +#include <linux/fs.h>
16504 +#include <linux/namei.h>
16505 +#include <linux/hash.h>
16506 +
16507 +#include <asm/errno.h>
16508 +#include <asm/uaccess.h>
16509 +#include <linux/vserver/base.h>
16510 +#include <linux/vserver/debug.h>
16511 +#include <linux/vserver/context.h>
16512 +#include <linux/vserver/device.h>
16513 +#include <linux/vserver/device_cmd.h>
16514 +
16515 +
16516 +#define DMAP_HASH_BITS 4
16517 +
16518 +
16519 +struct vs_mapping {
16520 +       union {
16521 +               struct hlist_node hlist;
16522 +               struct list_head list;
16523 +       } u;
16524 +#define dm_hlist       u.hlist
16525 +#define dm_list                u.list
16526 +       vxid_t xid;
16527 +       dev_t device;
16528 +       struct vx_dmap_target target;
16529 +};
16530 +
16531 +
16532 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
16533 +
16534 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
16535 +
16536 +static struct vx_dmap_target dmap_defaults[2] = {
16537 +       { .flags = DATTR_OPEN },
16538 +       { .flags = DATTR_OPEN },
16539 +};
16540 +
16541 +
16542 +struct kmem_cache *dmap_cachep __read_mostly;
16543 +
16544 +int __init dmap_cache_init(void)
16545 +{
16546 +       dmap_cachep = kmem_cache_create("dmap_cache",
16547 +               sizeof(struct vs_mapping), 0,
16548 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
16549 +       return 0;
16550 +}
16551 +
16552 +__initcall(dmap_cache_init);
16553 +
16554 +
16555 +static inline unsigned int __hashval(dev_t dev, int bits)
16556 +{
16557 +       return hash_long((unsigned long)dev, bits);
16558 +}
16559 +
16560 +
16561 +/*     __hash_mapping()
16562 + *     add the mapping to the hash table
16563 + */
16564 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
16565 +{
16566 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16567 +       struct hlist_head *head, *hash = dmap_main_hash;
16568 +       int device = vdm->device;
16569 +
16570 +       spin_lock(hash_lock);
16571 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
16572 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
16573 +
16574 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
16575 +       hlist_add_head(&vdm->dm_hlist, head);
16576 +       spin_unlock(hash_lock);
16577 +}
16578 +
16579 +
16580 +static inline int __mode_to_default(umode_t mode)
16581 +{
16582 +       switch (mode) {
16583 +       case S_IFBLK:
16584 +               return 0;
16585 +       case S_IFCHR:
16586 +               return 1;
16587 +       default:
16588 +               BUG();
16589 +       }
16590 +}
16591 +
16592 +
16593 +/*     __set_default()
16594 + *     set a default
16595 + */
16596 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
16597 +       struct vx_dmap_target *vdmt)
16598 +{
16599 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16600 +       spin_lock(hash_lock);
16601 +
16602 +       if (vxi)
16603 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
16604 +       else
16605 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
16606 +
16607 +
16608 +       spin_unlock(hash_lock);
16609 +
16610 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
16611 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
16612 +}
16613 +
16614 +
16615 +/*     __remove_default()
16616 + *     remove a default
16617 + */
16618 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
16619 +{
16620 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16621 +       spin_lock(hash_lock);
16622 +
16623 +       if (vxi)
16624 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
16625 +       else    /* remove == reset */
16626 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
16627 +
16628 +       spin_unlock(hash_lock);
16629 +       return 0;
16630 +}
16631 +
16632 +
16633 +/*     __find_mapping()
16634 + *     find a mapping in the hash table
16635 + *
16636 + *     caller must hold hash_lock
16637 + */
16638 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
16639 +       struct vs_mapping **local, struct vs_mapping **global)
16640 +{
16641 +       struct hlist_head *hash = dmap_main_hash;
16642 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
16643 +       struct hlist_node *pos;
16644 +       struct vs_mapping *vdm;
16645 +
16646 +       *local = NULL;
16647 +       if (global)
16648 +               *global = NULL;
16649 +
16650 +       hlist_for_each(pos, head) {
16651 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
16652 +
16653 +               if ((vdm->device == device) &&
16654 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
16655 +                       if (vdm->xid == xid) {
16656 +                               *local = vdm;
16657 +                               return 1;
16658 +                       } else if (global && vdm->xid == 0)
16659 +                               *global = vdm;
16660 +               }
16661 +       }
16662 +
16663 +       if (global && *global)
16664 +               return 0;
16665 +       else
16666 +               return -ENOENT;
16667 +}
16668 +
16669 +
16670 +/*     __lookup_mapping()
16671 + *     find a mapping and store the result in target and flags
16672 + */
16673 +static inline int __lookup_mapping(struct vx_info *vxi,
16674 +       dev_t device, dev_t *target, int *flags, umode_t mode)
16675 +{
16676 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16677 +       struct vs_mapping *vdm, *global;
16678 +       struct vx_dmap_target *vdmt;
16679 +       int ret = 0;
16680 +       vxid_t xid = vxi->vx_id;
16681 +       int index;
16682 +
16683 +       spin_lock(hash_lock);
16684 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
16685 +               ret = 1;
16686 +               vdmt = &vdm->target;
16687 +               goto found;
16688 +       }
16689 +
16690 +       index = __mode_to_default(mode);
16691 +       if (vxi && vxi->dmap.targets[index].flags) {
16692 +               ret = 2;
16693 +               vdmt = &vxi->dmap.targets[index];
16694 +       } else if (global) {
16695 +               ret = 3;
16696 +               vdmt = &global->target;
16697 +               goto found;
16698 +       } else {
16699 +               ret = 4;
16700 +               vdmt = &dmap_defaults[index];
16701 +       }
16702 +
16703 +found:
16704 +       if (target && (vdmt->flags & DATTR_REMAP))
16705 +               *target = vdmt->target;
16706 +       else if (target)
16707 +               *target = device;
16708 +       if (flags)
16709 +               *flags = vdmt->flags;
16710 +
16711 +       spin_unlock(hash_lock);
16712 +
16713 +       return ret;
16714 +}
16715 +
16716 +
16717 +/*     __remove_mapping()
16718 + *     remove a mapping from the hash table
16719 + */
16720 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
16721 +       umode_t mode)
16722 +{
16723 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
16724 +       struct vs_mapping *vdm = NULL;
16725 +       int ret = 0;
16726 +
16727 +       spin_lock(hash_lock);
16728 +
16729 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
16730 +               NULL);
16731 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
16732 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
16733 +       if (ret < 0)
16734 +               goto out;
16735 +       hlist_del(&vdm->dm_hlist);
16736 +
16737 +out:
16738 +       spin_unlock(hash_lock);
16739 +       if (vdm)
16740 +               kmem_cache_free(dmap_cachep, vdm);
16741 +       return ret;
16742 +}
16743 +
16744 +
16745 +
16746 +int vs_map_device(struct vx_info *vxi,
16747 +       dev_t device, dev_t *target, umode_t mode)
16748 +{
16749 +       int ret, flags = DATTR_MASK;
16750 +
16751 +       if (!vxi) {
16752 +               if (target)
16753 +                       *target = device;
16754 +               goto out;
16755 +       }
16756 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
16757 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
16758 +               device, target ? *target : 0, flags, mode, ret);
16759 +out:
16760 +       return (flags & DATTR_MASK);
16761 +}
16762 +
16763 +
16764 +
16765 +static int do_set_mapping(struct vx_info *vxi,
16766 +       dev_t device, dev_t target, int flags, umode_t mode)
16767 +{
16768 +       if (device) {
16769 +               struct vs_mapping *new;
16770 +
16771 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
16772 +               if (!new)
16773 +                       return -ENOMEM;
16774 +
16775 +               INIT_HLIST_NODE(&new->dm_hlist);
16776 +               new->device = device;
16777 +               new->target.target = target;
16778 +               new->target.flags = flags | mode;
16779 +               new->xid = (vxi ? vxi->vx_id : 0);
16780 +
16781 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
16782 +               __hash_mapping(vxi, new);
16783 +       } else {
16784 +               struct vx_dmap_target new = {
16785 +                       .target = target,
16786 +                       .flags = flags | mode,
16787 +               };
16788 +               __set_default(vxi, mode, &new);
16789 +       }
16790 +       return 0;
16791 +}
16792 +
16793 +
16794 +static int do_unset_mapping(struct vx_info *vxi,
16795 +       dev_t device, dev_t target, int flags, umode_t mode)
16796 +{
16797 +       int ret = -EINVAL;
16798 +
16799 +       if (device) {
16800 +               ret = __remove_mapping(vxi, device, mode);
16801 +               if (ret < 0)
16802 +                       goto out;
16803 +       } else {
16804 +               ret = __remove_default(vxi, mode);
16805 +               if (ret < 0)
16806 +                       goto out;
16807 +       }
16808 +
16809 +out:
16810 +       return ret;
16811 +}
16812 +
16813 +
16814 +static inline int __user_device(const char __user *name, dev_t *dev,
16815 +       umode_t *mode)
16816 +{
16817 +       struct nameidata nd;
16818 +       int ret;
16819 +
16820 +       if (!name) {
16821 +               *dev = 0;
16822 +               return 0;
16823 +       }
16824 +       ret = user_lpath(name, &nd.path);
16825 +       if (ret)
16826 +               return ret;
16827 +       if (nd.path.dentry->d_inode) {
16828 +               *dev = nd.path.dentry->d_inode->i_rdev;
16829 +               *mode = nd.path.dentry->d_inode->i_mode;
16830 +       }
16831 +       path_put(&nd.path);
16832 +       return 0;
16833 +}
16834 +
16835 +static inline int __mapping_mode(dev_t device, dev_t target,
16836 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
16837 +{
16838 +       if (device)
16839 +               *mode = device_mode & S_IFMT;
16840 +       else if (target)
16841 +               *mode = target_mode & S_IFMT;
16842 +       else
16843 +               return -EINVAL;
16844 +
16845 +       /* if both given, device and target mode have to match */
16846 +       if (device && target &&
16847 +               ((device_mode ^ target_mode) & S_IFMT))
16848 +               return -EINVAL;
16849 +       return 0;
16850 +}
16851 +
16852 +
16853 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
16854 +       const char __user *target_path, int flags, int set)
16855 +{
16856 +       dev_t device = ~0, target = ~0;
16857 +       umode_t device_mode = 0, target_mode = 0, mode;
16858 +       int ret;
16859 +
16860 +       ret = __user_device(device_path, &device, &device_mode);
16861 +       if (ret)
16862 +               return ret;
16863 +       ret = __user_device(target_path, &target, &target_mode);
16864 +       if (ret)
16865 +               return ret;
16866 +
16867 +       ret = __mapping_mode(device, target,
16868 +               device_mode, target_mode, &mode);
16869 +       if (ret)
16870 +               return ret;
16871 +
16872 +       if (set)
16873 +               return do_set_mapping(vxi, device, target,
16874 +                       flags, mode);
16875 +       else
16876 +               return do_unset_mapping(vxi, device, target,
16877 +                       flags, mode);
16878 +}
16879 +
16880 +
16881 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
16882 +{
16883 +       struct vcmd_set_mapping_v0 vc_data;
16884 +
16885 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16886 +               return -EFAULT;
16887 +
16888 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16889 +               vc_data.flags, 1);
16890 +}
16891 +
16892 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
16893 +{
16894 +       struct vcmd_set_mapping_v0 vc_data;
16895 +
16896 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16897 +               return -EFAULT;
16898 +
16899 +       return do_mapping(vxi, vc_data.device, vc_data.target,
16900 +               vc_data.flags, 0);
16901 +}
16902 +
16903 +
16904 +#ifdef CONFIG_COMPAT
16905 +
16906 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
16907 +{
16908 +       struct vcmd_set_mapping_v0_x32 vc_data;
16909 +
16910 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16911 +               return -EFAULT;
16912 +
16913 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16914 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
16915 +}
16916 +
16917 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
16918 +{
16919 +       struct vcmd_set_mapping_v0_x32 vc_data;
16920 +
16921 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16922 +               return -EFAULT;
16923 +
16924 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16925 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
16926 +}
16927 +
16928 +#endif /* CONFIG_COMPAT */
16929 +
16930 +
16931 diff -NurpP --minimal linux-3.13.10/kernel/vserver/dlimit.c linux-3.13.10-vs2.3.6.11/kernel/vserver/dlimit.c
16932 --- linux-3.13.10/kernel/vserver/dlimit.c       1970-01-01 00:00:00.000000000 +0000
16933 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/dlimit.c    2014-01-31 20:38:04.000000000 +0000
16934 @@ -0,0 +1,528 @@
16935 +/*
16936 + *  linux/kernel/vserver/dlimit.c
16937 + *
16938 + *  Virtual Server: Context Disk Limits
16939 + *
16940 + *  Copyright (C) 2004-2009  Herbert Pötzl
16941 + *
16942 + *  V0.01  initial version
16943 + *  V0.02  compat32 splitup
16944 + *  V0.03  extended interface
16945 + *
16946 + */
16947 +
16948 +#include <linux/statfs.h>
16949 +#include <linux/sched.h>
16950 +#include <linux/namei.h>
16951 +#include <linux/vs_tag.h>
16952 +#include <linux/vs_dlimit.h>
16953 +#include <linux/vserver/dlimit_cmd.h>
16954 +#include <linux/slab.h>
16955 +// #include <linux/gfp.h>
16956 +
16957 +#include <asm/uaccess.h>
16958 +
16959 +/*     __alloc_dl_info()
16960 +
16961 +       * allocate an initialized dl_info struct
16962 +       * doesn't make it visible (hash)                        */
16963 +
16964 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
16965 +{
16966 +       struct dl_info *new = NULL;
16967 +
16968 +       vxdprintk(VXD_CBIT(dlim, 5),
16969 +               "alloc_dl_info(%p,%d)*", sb, tag);
16970 +
16971 +       /* would this benefit from a slab cache? */
16972 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
16973 +       if (!new)
16974 +               return 0;
16975 +
16976 +       memset(new, 0, sizeof(struct dl_info));
16977 +       new->dl_tag = tag;
16978 +       new->dl_sb = sb;
16979 +       // INIT_RCU_HEAD(&new->dl_rcu);
16980 +       INIT_HLIST_NODE(&new->dl_hlist);
16981 +       spin_lock_init(&new->dl_lock);
16982 +       atomic_set(&new->dl_refcnt, 0);
16983 +       atomic_set(&new->dl_usecnt, 0);
16984 +
16985 +       /* rest of init goes here */
16986 +
16987 +       vxdprintk(VXD_CBIT(dlim, 4),
16988 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
16989 +       return new;
16990 +}
16991 +
16992 +/*     __dealloc_dl_info()
16993 +
16994 +       * final disposal of dl_info                             */
16995 +
16996 +static void __dealloc_dl_info(struct dl_info *dli)
16997 +{
16998 +       vxdprintk(VXD_CBIT(dlim, 4),
16999 +               "dealloc_dl_info(%p)", dli);
17000 +
17001 +       dli->dl_hlist.next = LIST_POISON1;
17002 +       dli->dl_tag = -1;
17003 +       dli->dl_sb = 0;
17004 +
17005 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17006 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17007 +
17008 +       kfree(dli);
17009 +}
17010 +
17011 +
17012 +/*     hash table for dl_info hash */
17013 +
17014 +#define DL_HASH_SIZE   13
17015 +
17016 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17017 +
17018 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17019 +
17020 +
17021 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
17022 +{
17023 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17024 +}
17025 +
17026 +
17027 +
17028 +/*     __hash_dl_info()
17029 +
17030 +       * add the dli to the global hash table
17031 +       * requires the hash_lock to be held                     */
17032 +
17033 +static inline void __hash_dl_info(struct dl_info *dli)
17034 +{
17035 +       struct hlist_head *head;
17036 +
17037 +       vxdprintk(VXD_CBIT(dlim, 6),
17038 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17039 +       get_dl_info(dli);
17040 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17041 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17042 +}
17043 +
17044 +/*     __unhash_dl_info()
17045 +
17046 +       * remove the dli from the global hash table
17047 +       * requires the hash_lock to be held                     */
17048 +
17049 +static inline void __unhash_dl_info(struct dl_info *dli)
17050 +{
17051 +       vxdprintk(VXD_CBIT(dlim, 6),
17052 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17053 +       hlist_del_rcu(&dli->dl_hlist);
17054 +       put_dl_info(dli);
17055 +}
17056 +
17057 +
17058 +/*     __lookup_dl_info()
17059 +
17060 +       * requires the rcu_read_lock()
17061 +       * doesn't increment the dl_refcnt                       */
17062 +
17063 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
17064 +{
17065 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17066 +       struct dl_info *dli;
17067 +
17068 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17069 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
17070 +                       return dli;
17071 +       }
17072 +       return NULL;
17073 +}
17074 +
17075 +
17076 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
17077 +{
17078 +       struct dl_info *dli;
17079 +
17080 +       rcu_read_lock();
17081 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17082 +       vxdprintk(VXD_CBIT(dlim, 7),
17083 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17084 +       rcu_read_unlock();
17085 +       return dli;
17086 +}
17087 +
17088 +void rcu_free_dl_info(struct rcu_head *head)
17089 +{
17090 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17091 +       int usecnt, refcnt;
17092 +
17093 +       BUG_ON(!dli || !head);
17094 +
17095 +       usecnt = atomic_read(&dli->dl_usecnt);
17096 +       BUG_ON(usecnt < 0);
17097 +
17098 +       refcnt = atomic_read(&dli->dl_refcnt);
17099 +       BUG_ON(refcnt < 0);
17100 +
17101 +       vxdprintk(VXD_CBIT(dlim, 3),
17102 +               "rcu_free_dl_info(%p)", dli);
17103 +       if (!usecnt)
17104 +               __dealloc_dl_info(dli);
17105 +       else
17106 +               printk("!!! rcu didn't free\n");
17107 +}
17108 +
17109 +
17110 +
17111 +
17112 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17113 +       uint32_t flags, int add)
17114 +{
17115 +       struct path path;
17116 +       int ret;
17117 +
17118 +       ret = user_lpath(name, &path);
17119 +       if (!ret) {
17120 +               struct super_block *sb;
17121 +               struct dl_info *dli;
17122 +
17123 +               ret = -EINVAL;
17124 +               if (!path.dentry->d_inode)
17125 +                       goto out_release;
17126 +               if (!(sb = path.dentry->d_inode->i_sb))
17127 +                       goto out_release;
17128 +
17129 +               if (add) {
17130 +                       dli = __alloc_dl_info(sb, id);
17131 +                       spin_lock(&dl_info_hash_lock);
17132 +
17133 +                       ret = -EEXIST;
17134 +                       if (__lookup_dl_info(sb, id))
17135 +                               goto out_unlock;
17136 +                       __hash_dl_info(dli);
17137 +                       dli = NULL;
17138 +               } else {
17139 +                       spin_lock(&dl_info_hash_lock);
17140 +                       dli = __lookup_dl_info(sb, id);
17141 +
17142 +                       ret = -ESRCH;
17143 +                       if (!dli)
17144 +                               goto out_unlock;
17145 +                       __unhash_dl_info(dli);
17146 +               }
17147 +               ret = 0;
17148 +       out_unlock:
17149 +               spin_unlock(&dl_info_hash_lock);
17150 +               if (add && dli)
17151 +                       __dealloc_dl_info(dli);
17152 +       out_release:
17153 +               path_put(&path);
17154 +       }
17155 +       return ret;
17156 +}
17157 +
17158 +int vc_add_dlimit(uint32_t id, void __user *data)
17159 +{
17160 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17161 +
17162 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17163 +               return -EFAULT;
17164 +
17165 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17166 +}
17167 +
17168 +int vc_rem_dlimit(uint32_t id, void __user *data)
17169 +{
17170 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17171 +
17172 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17173 +               return -EFAULT;
17174 +
17175 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17176 +}
17177 +
17178 +#ifdef CONFIG_COMPAT
17179 +
17180 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17181 +{
17182 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17183 +
17184 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17185 +               return -EFAULT;
17186 +
17187 +       return do_addrem_dlimit(id,
17188 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17189 +}
17190 +
17191 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17192 +{
17193 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17194 +
17195 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17196 +               return -EFAULT;
17197 +
17198 +       return do_addrem_dlimit(id,
17199 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17200 +}
17201 +
17202 +#endif /* CONFIG_COMPAT */
17203 +
17204 +
17205 +static inline
17206 +int do_set_dlimit(uint32_t id, const char __user *name,
17207 +       uint32_t space_used, uint32_t space_total,
17208 +       uint32_t inodes_used, uint32_t inodes_total,
17209 +       uint32_t reserved, uint32_t flags)
17210 +{
17211 +       struct path path;
17212 +       int ret;
17213 +
17214 +       ret = user_lpath(name, &path);
17215 +       if (!ret) {
17216 +               struct super_block *sb;
17217 +               struct dl_info *dli;
17218 +
17219 +               ret = -EINVAL;
17220 +               if (!path.dentry->d_inode)
17221 +                       goto out_release;
17222 +               if (!(sb = path.dentry->d_inode->i_sb))
17223 +                       goto out_release;
17224 +
17225 +               /* sanity checks */
17226 +               if ((reserved != CDLIM_KEEP &&
17227 +                       reserved > 100) ||
17228 +                       (inodes_used != CDLIM_KEEP &&
17229 +                       inodes_used > inodes_total) ||
17230 +                       (space_used != CDLIM_KEEP &&
17231 +                       space_used > space_total))
17232 +                       goto out_release;
17233 +
17234 +               ret = -ESRCH;
17235 +               dli = locate_dl_info(sb, id);
17236 +               if (!dli)
17237 +                       goto out_release;
17238 +
17239 +               spin_lock(&dli->dl_lock);
17240 +
17241 +               if (inodes_used != CDLIM_KEEP)
17242 +                       dli->dl_inodes_used = inodes_used;
17243 +               if (inodes_total != CDLIM_KEEP)
17244 +                       dli->dl_inodes_total = inodes_total;
17245 +               if (space_used != CDLIM_KEEP)
17246 +                       dli->dl_space_used = dlimit_space_32to64(
17247 +                               space_used, flags, DLIMS_USED);
17248 +
17249 +               if (space_total == CDLIM_INFINITY)
17250 +                       dli->dl_space_total = DLIM_INFINITY;
17251 +               else if (space_total != CDLIM_KEEP)
17252 +                       dli->dl_space_total = dlimit_space_32to64(
17253 +                               space_total, flags, DLIMS_TOTAL);
17254 +
17255 +               if (reserved != CDLIM_KEEP)
17256 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17257 +
17258 +               spin_unlock(&dli->dl_lock);
17259 +
17260 +               put_dl_info(dli);
17261 +               ret = 0;
17262 +
17263 +       out_release:
17264 +               path_put(&path);
17265 +       }
17266 +       return ret;
17267 +}
17268 +
17269 +int vc_set_dlimit(uint32_t id, void __user *data)
17270 +{
17271 +       struct vcmd_ctx_dlimit_v0 vc_data;
17272 +
17273 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17274 +               return -EFAULT;
17275 +
17276 +       return do_set_dlimit(id, vc_data.name,
17277 +               vc_data.space_used, vc_data.space_total,
17278 +               vc_data.inodes_used, vc_data.inodes_total,
17279 +               vc_data.reserved, vc_data.flags);
17280 +}
17281 +
17282 +#ifdef CONFIG_COMPAT
17283 +
17284 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17285 +{
17286 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17287 +
17288 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17289 +               return -EFAULT;
17290 +
17291 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17292 +               vc_data.space_used, vc_data.space_total,
17293 +               vc_data.inodes_used, vc_data.inodes_total,
17294 +               vc_data.reserved, vc_data.flags);
17295 +}
17296 +
17297 +#endif /* CONFIG_COMPAT */
17298 +
17299 +
17300 +static inline
17301 +int do_get_dlimit(uint32_t id, const char __user *name,
17302 +       uint32_t *space_used, uint32_t *space_total,
17303 +       uint32_t *inodes_used, uint32_t *inodes_total,
17304 +       uint32_t *reserved, uint32_t *flags)
17305 +{
17306 +       struct path path;
17307 +       int ret;
17308 +
17309 +       ret = user_lpath(name, &path);
17310 +       if (!ret) {
17311 +               struct super_block *sb;
17312 +               struct dl_info *dli;
17313 +
17314 +               ret = -EINVAL;
17315 +               if (!path.dentry->d_inode)
17316 +                       goto out_release;
17317 +               if (!(sb = path.dentry->d_inode->i_sb))
17318 +                       goto out_release;
17319 +
17320 +               ret = -ESRCH;
17321 +               dli = locate_dl_info(sb, id);
17322 +               if (!dli)
17323 +                       goto out_release;
17324 +
17325 +               spin_lock(&dli->dl_lock);
17326 +               *inodes_used = dli->dl_inodes_used;
17327 +               *inodes_total = dli->dl_inodes_total;
17328 +
17329 +               *space_used = dlimit_space_64to32(
17330 +                       dli->dl_space_used, flags, DLIMS_USED);
17331 +
17332 +               if (dli->dl_space_total == DLIM_INFINITY)
17333 +                       *space_total = CDLIM_INFINITY;
17334 +               else
17335 +                       *space_total = dlimit_space_64to32(
17336 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
17337 +
17338 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
17339 +               spin_unlock(&dli->dl_lock);
17340 +
17341 +               put_dl_info(dli);
17342 +               ret = -EFAULT;
17343 +
17344 +               ret = 0;
17345 +       out_release:
17346 +               path_put(&path);
17347 +       }
17348 +       return ret;
17349 +}
17350 +
17351 +
17352 +int vc_get_dlimit(uint32_t id, void __user *data)
17353 +{
17354 +       struct vcmd_ctx_dlimit_v0 vc_data;
17355 +       int ret;
17356 +
17357 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17358 +               return -EFAULT;
17359 +
17360 +       ret = do_get_dlimit(id, vc_data.name,
17361 +               &vc_data.space_used, &vc_data.space_total,
17362 +               &vc_data.inodes_used, &vc_data.inodes_total,
17363 +               &vc_data.reserved, &vc_data.flags);
17364 +       if (ret)
17365 +               return ret;
17366 +
17367 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17368 +               return -EFAULT;
17369 +       return 0;
17370 +}
17371 +
17372 +#ifdef CONFIG_COMPAT
17373 +
17374 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
17375 +{
17376 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17377 +       int ret;
17378 +
17379 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17380 +               return -EFAULT;
17381 +
17382 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
17383 +               &vc_data.space_used, &vc_data.space_total,
17384 +               &vc_data.inodes_used, &vc_data.inodes_total,
17385 +               &vc_data.reserved, &vc_data.flags);
17386 +       if (ret)
17387 +               return ret;
17388 +
17389 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17390 +               return -EFAULT;
17391 +       return 0;
17392 +}
17393 +
17394 +#endif /* CONFIG_COMPAT */
17395 +
17396 +
17397 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
17398 +{
17399 +       struct dl_info *dli;
17400 +       __u64 blimit, bfree, bavail;
17401 +       __u32 ifree;
17402 +
17403 +       dli = locate_dl_info(sb, dx_current_tag());
17404 +       if (!dli)
17405 +               return;
17406 +
17407 +       spin_lock(&dli->dl_lock);
17408 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
17409 +               goto no_ilim;
17410 +
17411 +       /* reduce max inodes available to limit */
17412 +       if (buf->f_files > dli->dl_inodes_total)
17413 +               buf->f_files = dli->dl_inodes_total;
17414 +
17415 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
17416 +       /* reduce free inodes to min */
17417 +       if (ifree < buf->f_ffree)
17418 +               buf->f_ffree = ifree;
17419 +
17420 +no_ilim:
17421 +       if (dli->dl_space_total == DLIM_INFINITY)
17422 +               goto no_blim;
17423 +
17424 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
17425 +
17426 +       if (dli->dl_space_total < dli->dl_space_used)
17427 +               bfree = 0;
17428 +       else
17429 +               bfree = (dli->dl_space_total - dli->dl_space_used)
17430 +                       >> sb->s_blocksize_bits;
17431 +
17432 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
17433 +       if (bavail < dli->dl_space_used)
17434 +               bavail = 0;
17435 +       else
17436 +               bavail = (bavail - dli->dl_space_used)
17437 +                       >> sb->s_blocksize_bits;
17438 +
17439 +       /* reduce max space available to limit */
17440 +       if (buf->f_blocks > blimit)
17441 +               buf->f_blocks = blimit;
17442 +
17443 +       /* reduce free space to min */
17444 +       if (bfree < buf->f_bfree)
17445 +               buf->f_bfree = bfree;
17446 +
17447 +       /* reduce avail space to min */
17448 +       if (bavail < buf->f_bavail)
17449 +               buf->f_bavail = bavail;
17450 +
17451 +no_blim:
17452 +       spin_unlock(&dli->dl_lock);
17453 +       put_dl_info(dli);
17454 +
17455 +       return;
17456 +}
17457 +
17458 +#include <linux/module.h>
17459 +
17460 +EXPORT_SYMBOL_GPL(locate_dl_info);
17461 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
17462 +
17463 diff -NurpP --minimal linux-3.13.10/kernel/vserver/helper.c linux-3.13.10-vs2.3.6.11/kernel/vserver/helper.c
17464 --- linux-3.13.10/kernel/vserver/helper.c       1970-01-01 00:00:00.000000000 +0000
17465 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/helper.c    2014-01-31 20:38:04.000000000 +0000
17466 @@ -0,0 +1,242 @@
17467 +/*
17468 + *  linux/kernel/vserver/helper.c
17469 + *
17470 + *  Virtual Context Support
17471 + *
17472 + *  Copyright (C) 2004-2007  Herbert Pötzl
17473 + *
17474 + *  V0.01  basic helper
17475 + *
17476 + */
17477 +
17478 +#include <linux/kmod.h>
17479 +#include <linux/reboot.h>
17480 +#include <linux/vs_context.h>
17481 +#include <linux/vs_network.h>
17482 +#include <linux/vserver/signal.h>
17483 +
17484 +
17485 +char vshelper_path[255] = "/sbin/vshelper";
17486 +
17487 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
17488 +{
17489 +       current->flags &= ~PF_NO_SETAFFINITY;
17490 +       return 0;
17491 +}
17492 +
17493 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
17494 +{
17495 +       struct subprocess_info *info;
17496 +       gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
17497 +
17498 +       info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
17499 +                                        vshelper_init, NULL, NULL);
17500 +       if (info == NULL)
17501 +               return -ENOMEM;
17502 +
17503 +       return call_usermodehelper_exec(info, wait);
17504 +}
17505 +
17506 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
17507 +{
17508 +       int ret;
17509 +
17510 +       if ((ret = vs_call_usermodehelper(name, argv, envp,
17511 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
17512 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
17513 +                       name, argv[1], argv[2],
17514 +                       sync ? "sync" : "async", ret);
17515 +       }
17516 +       vxdprintk(VXD_CBIT(switch, 4),
17517 +               "%s: (%s %s) returned %s with %d",
17518 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
17519 +       return ret;
17520 +}
17521 +
17522 +/*
17523 + *      vshelper path is set via /proc/sys
17524 + *      invoked by vserver sys_reboot(), with
17525 + *      the following arguments
17526 + *
17527 + *      argv [0] = vshelper_path;
17528 + *      argv [1] = action: "restart", "halt", "poweroff", ...
17529 + *      argv [2] = context identifier
17530 + *
17531 + *      envp [*] = type-specific parameters
17532 + */
17533 +
17534 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
17535 +{
17536 +       char id_buf[8], cmd_buf[16];
17537 +       char uid_buf[16], pid_buf[16];
17538 +       int ret;
17539 +
17540 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17541 +       char *envp[] = {"HOME=/", "TERM=linux",
17542 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
17543 +                       uid_buf, pid_buf, cmd_buf, 0};
17544 +
17545 +       if (vx_info_state(vxi, VXS_HELPER))
17546 +               return -EAGAIN;
17547 +       vxi->vx_state |= VXS_HELPER;
17548 +
17549 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17550 +
17551 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17552 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
17553 +               from_kuid(&init_user_ns, current_uid()));
17554 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
17555 +
17556 +       switch (cmd) {
17557 +       case LINUX_REBOOT_CMD_RESTART:
17558 +               argv[1] = "restart";
17559 +               break;
17560 +
17561 +       case LINUX_REBOOT_CMD_HALT:
17562 +               argv[1] = "halt";
17563 +               break;
17564 +
17565 +       case LINUX_REBOOT_CMD_POWER_OFF:
17566 +               argv[1] = "poweroff";
17567 +               break;
17568 +
17569 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
17570 +               argv[1] = "swsusp";
17571 +               break;
17572 +
17573 +       case LINUX_REBOOT_CMD_OOM:
17574 +               argv[1] = "oom";
17575 +               break;
17576 +
17577 +       default:
17578 +               vxi->vx_state &= ~VXS_HELPER;
17579 +               return 0;
17580 +       }
17581 +
17582 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
17583 +       vxi->vx_state &= ~VXS_HELPER;
17584 +       __wakeup_vx_info(vxi);
17585 +       return (ret) ? -EPERM : 0;
17586 +}
17587 +
17588 +
17589 +long vs_reboot(unsigned int cmd, void __user *arg)
17590 +{
17591 +       struct vx_info *vxi = current_vx_info();
17592 +       long ret = 0;
17593 +
17594 +       vxdprintk(VXD_CBIT(misc, 5),
17595 +               "vs_reboot(%p[#%d],%u)",
17596 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17597 +
17598 +       ret = vs_reboot_helper(vxi, cmd, arg);
17599 +       if (ret)
17600 +               return ret;
17601 +
17602 +       vxi->reboot_cmd = cmd;
17603 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17604 +               switch (cmd) {
17605 +               case LINUX_REBOOT_CMD_RESTART:
17606 +               case LINUX_REBOOT_CMD_HALT:
17607 +               case LINUX_REBOOT_CMD_POWER_OFF:
17608 +                       vx_info_kill(vxi, 0, SIGKILL);
17609 +                       vx_info_kill(vxi, 1, SIGKILL);
17610 +               default:
17611 +                       break;
17612 +               }
17613 +       }
17614 +       return 0;
17615 +}
17616 +
17617 +long vs_oom_action(unsigned int cmd)
17618 +{
17619 +       struct vx_info *vxi = current_vx_info();
17620 +       long ret = 0;
17621 +
17622 +       vxdprintk(VXD_CBIT(misc, 5),
17623 +               "vs_oom_action(%p[#%d],%u)",
17624 +               vxi, vxi ? vxi->vx_id : 0, cmd);
17625 +
17626 +       ret = vs_reboot_helper(vxi, cmd, NULL);
17627 +       if (ret)
17628 +               return ret;
17629 +
17630 +       vxi->reboot_cmd = cmd;
17631 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17632 +               vx_info_kill(vxi, 0, SIGKILL);
17633 +               vx_info_kill(vxi, 1, SIGKILL);
17634 +       }
17635 +       return 0;
17636 +}
17637 +
17638 +/*
17639 + *      argv [0] = vshelper_path;
17640 + *      argv [1] = action: "startup", "shutdown"
17641 + *      argv [2] = context identifier
17642 + *
17643 + *      envp [*] = type-specific parameters
17644 + */
17645 +
17646 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
17647 +{
17648 +       char id_buf[8], cmd_buf[16];
17649 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17650 +       char *envp[] = {"HOME=/", "TERM=linux",
17651 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17652 +
17653 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
17654 +               return 0;
17655 +
17656 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17657 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17658 +
17659 +       switch (cmd) {
17660 +       case VSC_STARTUP:
17661 +               argv[1] = "startup";
17662 +               break;
17663 +       case VSC_SHUTDOWN:
17664 +               argv[1] = "shutdown";
17665 +               break;
17666 +       default:
17667 +               return 0;
17668 +       }
17669 +
17670 +       return do_vshelper(vshelper_path, argv, envp, 1);
17671 +}
17672 +
17673 +
17674 +/*
17675 + *      argv [0] = vshelper_path;
17676 + *      argv [1] = action: "netup", "netdown"
17677 + *      argv [2] = context identifier
17678 + *
17679 + *      envp [*] = type-specific parameters
17680 + */
17681 +
17682 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
17683 +{
17684 +       char id_buf[8], cmd_buf[16];
17685 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
17686 +       char *envp[] = {"HOME=/", "TERM=linux",
17687 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17688 +
17689 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
17690 +               return 0;
17691 +
17692 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
17693 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17694 +
17695 +       switch (cmd) {
17696 +       case VSC_NETUP:
17697 +               argv[1] = "netup";
17698 +               break;
17699 +       case VSC_NETDOWN:
17700 +               argv[1] = "netdown";
17701 +               break;
17702 +       default:
17703 +               return 0;
17704 +       }
17705 +
17706 +       return do_vshelper(vshelper_path, argv, envp, 1);
17707 +}
17708 +
17709 diff -NurpP --minimal linux-3.13.10/kernel/vserver/history.c linux-3.13.10-vs2.3.6.11/kernel/vserver/history.c
17710 --- linux-3.13.10/kernel/vserver/history.c      1970-01-01 00:00:00.000000000 +0000
17711 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/history.c   2014-01-31 20:38:04.000000000 +0000
17712 @@ -0,0 +1,258 @@
17713 +/*
17714 + *  kernel/vserver/history.c
17715 + *
17716 + *  Virtual Context History Backtrace
17717 + *
17718 + *  Copyright (C) 2004-2007  Herbert Pötzl
17719 + *
17720 + *  V0.01  basic structure
17721 + *  V0.02  hash/unhash and trace
17722 + *  V0.03  preemption fixes
17723 + *
17724 + */
17725 +
17726 +#include <linux/module.h>
17727 +#include <asm/uaccess.h>
17728 +
17729 +#include <linux/vserver/context.h>
17730 +#include <linux/vserver/debug.h>
17731 +#include <linux/vserver/debug_cmd.h>
17732 +#include <linux/vserver/history.h>
17733 +
17734 +
17735 +#ifdef CONFIG_VSERVER_HISTORY
17736 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
17737 +#else
17738 +#define VXH_SIZE       64
17739 +#endif
17740 +
17741 +struct _vx_history {
17742 +       unsigned int counter;
17743 +
17744 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
17745 +};
17746 +
17747 +
17748 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
17749 +
17750 +unsigned volatile int vxh_active = 1;
17751 +
17752 +static atomic_t sequence = ATOMIC_INIT(0);
17753 +
17754 +
17755 +/*     vxh_advance()
17756 +
17757 +       * requires disabled preemption                          */
17758 +
17759 +struct _vx_hist_entry *vxh_advance(void *loc)
17760 +{
17761 +       unsigned int cpu = smp_processor_id();
17762 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17763 +       struct _vx_hist_entry *entry;
17764 +       unsigned int index;
17765 +
17766 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
17767 +       entry = &hist->entry[index];
17768 +
17769 +       entry->seq = atomic_inc_return(&sequence);
17770 +       entry->loc = loc;
17771 +       return entry;
17772 +}
17773 +
17774 +EXPORT_SYMBOL_GPL(vxh_advance);
17775 +
17776 +
17777 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
17778 +
17779 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
17780 +
17781 +
17782 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
17783 +
17784 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
17785 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
17786 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
17787 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
17788 +
17789 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
17790 +{
17791 +       switch (e->type) {
17792 +       case VXH_THROW_OOPS:
17793 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
17794 +               break;
17795 +
17796 +       case VXH_GET_VX_INFO:
17797 +       case VXH_PUT_VX_INFO:
17798 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17799 +                       VXH_LOC_ARGS(e),
17800 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
17801 +                       VXH_VXI_ARGS(e));
17802 +               break;
17803 +
17804 +       case VXH_INIT_VX_INFO:
17805 +       case VXH_SET_VX_INFO:
17806 +       case VXH_CLR_VX_INFO:
17807 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17808 +                       VXH_LOC_ARGS(e),
17809 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
17810 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
17811 +                       VXH_VXI_ARGS(e), e->sc.data);
17812 +               break;
17813 +
17814 +       case VXH_CLAIM_VX_INFO:
17815 +       case VXH_RELEASE_VX_INFO:
17816 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17817 +                       VXH_LOC_ARGS(e),
17818 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
17819 +                       VXH_VXI_ARGS(e), e->sc.data);
17820 +               break;
17821 +
17822 +       case VXH_ALLOC_VX_INFO:
17823 +       case VXH_DEALLOC_VX_INFO:
17824 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17825 +                       VXH_LOC_ARGS(e),
17826 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
17827 +                       VXH_VXI_ARGS(e));
17828 +               break;
17829 +
17830 +       case VXH_HASH_VX_INFO:
17831 +       case VXH_UNHASH_VX_INFO:
17832 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
17833 +                       VXH_LOC_ARGS(e),
17834 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
17835 +                       VXH_VXI_ARGS(e));
17836 +               break;
17837 +
17838 +       case VXH_LOC_VX_INFO:
17839 +       case VXH_LOOKUP_VX_INFO:
17840 +       case VXH_CREATE_VX_INFO:
17841 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
17842 +                       VXH_LOC_ARGS(e),
17843 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
17844 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
17845 +                       e->ll.arg, VXH_VXI_ARGS(e));
17846 +               break;
17847 +       }
17848 +}
17849 +
17850 +static void __vxh_dump_history(void)
17851 +{
17852 +       unsigned int i, cpu;
17853 +
17854 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
17855 +               atomic_read(&sequence), NR_CPUS);
17856 +
17857 +       for (i = 0; i < VXH_SIZE; i++) {
17858 +               for_each_online_cpu(cpu) {
17859 +                       struct _vx_history *hist =
17860 +                               &per_cpu(vx_history_buffer, cpu);
17861 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
17862 +                       struct _vx_hist_entry *entry = &hist->entry[index];
17863 +
17864 +                       vxh_dump_entry(entry, cpu);
17865 +               }
17866 +       }
17867 +}
17868 +
17869 +void   vxh_dump_history(void)
17870 +{
17871 +       vxh_active = 0;
17872 +#ifdef CONFIG_SMP
17873 +       local_irq_enable();
17874 +       smp_send_stop();
17875 +       local_irq_disable();
17876 +#endif
17877 +       __vxh_dump_history();
17878 +}
17879 +
17880 +
17881 +/* vserver syscall commands below here */
17882 +
17883 +
17884 +int vc_dump_history(uint32_t id)
17885 +{
17886 +       vxh_active = 0;
17887 +       __vxh_dump_history();
17888 +       vxh_active = 1;
17889 +
17890 +       return 0;
17891 +}
17892 +
17893 +
17894 +int do_read_history(struct __user _vx_hist_entry *data,
17895 +       int cpu, uint32_t *index, uint32_t *count)
17896 +{
17897 +       int pos, ret = 0;
17898 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17899 +       int end = hist->counter;
17900 +       int start = end - VXH_SIZE + 2;
17901 +       int idx = *index;
17902 +
17903 +       /* special case: get current pos */
17904 +       if (!*count) {
17905 +               *index = end;
17906 +               return 0;
17907 +       }
17908 +
17909 +       /* have we lost some data? */
17910 +       if (idx < start)
17911 +               idx = start;
17912 +
17913 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
17914 +               struct _vx_hist_entry *entry =
17915 +                       &hist->entry[idx % VXH_SIZE];
17916 +
17917 +               /* send entry to userspace */
17918 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
17919 +               if (ret)
17920 +                       break;
17921 +       }
17922 +       /* save new index and count */
17923 +       *index = idx;
17924 +       *count = pos;
17925 +       return ret ? ret : (*index < end);
17926 +}
17927 +
17928 +int vc_read_history(uint32_t id, void __user *data)
17929 +{
17930 +       struct vcmd_read_history_v0 vc_data;
17931 +       int ret;
17932 +
17933 +       if (id >= NR_CPUS)
17934 +               return -EINVAL;
17935 +
17936 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17937 +               return -EFAULT;
17938 +
17939 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
17940 +               id, &vc_data.index, &vc_data.count);
17941 +
17942 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17943 +               return -EFAULT;
17944 +       return ret;
17945 +}
17946 +
17947 +#ifdef CONFIG_COMPAT
17948 +
17949 +int vc_read_history_x32(uint32_t id, void __user *data)
17950 +{
17951 +       struct vcmd_read_history_v0_x32 vc_data;
17952 +       int ret;
17953 +
17954 +       if (id >= NR_CPUS)
17955 +               return -EINVAL;
17956 +
17957 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17958 +               return -EFAULT;
17959 +
17960 +       ret = do_read_history((struct __user _vx_hist_entry *)
17961 +               compat_ptr(vc_data.data_ptr),
17962 +               id, &vc_data.index, &vc_data.count);
17963 +
17964 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17965 +               return -EFAULT;
17966 +       return ret;
17967 +}
17968 +
17969 +#endif /* CONFIG_COMPAT */
17970 +
17971 diff -NurpP --minimal linux-3.13.10/kernel/vserver/inet.c linux-3.13.10-vs2.3.6.11/kernel/vserver/inet.c
17972 --- linux-3.13.10/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
17973 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/inet.c      2014-02-01 00:26:40.000000000 +0000
17974 @@ -0,0 +1,236 @@
17975 +
17976 +#include <linux/in.h>
17977 +#include <linux/inetdevice.h>
17978 +#include <linux/export.h>
17979 +#include <linux/vs_inet.h>
17980 +#include <linux/vs_inet6.h>
17981 +#include <linux/vserver/debug.h>
17982 +#include <net/route.h>
17983 +#include <net/addrconf.h>
17984 +
17985 +
17986 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
17987 +{
17988 +       int ret = 0;
17989 +
17990 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
17991 +               ret = 1;
17992 +       else {
17993 +               struct nx_addr_v4 *ptr;
17994 +               unsigned long irqflags;
17995 +
17996 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
17997 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
17998 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
17999 +                               ret = 1;
18000 +                               break;
18001 +                       }
18002 +               }
18003 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18004 +       }
18005 +
18006 +       vxdprintk(VXD_CBIT(net, 2),
18007 +               "nx_v4_addr_conflict(%p,%p): %d",
18008 +               nxi1, nxi2, ret);
18009 +
18010 +       return ret;
18011 +}
18012 +
18013 +
18014 +#ifdef CONFIG_IPV6
18015 +
18016 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18017 +{
18018 +       int ret = 0;
18019 +
18020 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18021 +               ret = 1;
18022 +       else {
18023 +               struct nx_addr_v6 *ptr;
18024 +               unsigned long irqflags;
18025 +
18026 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18027 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18028 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18029 +                               ret = 1;
18030 +                               break;
18031 +                       }
18032 +               }
18033 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18034 +       }
18035 +
18036 +       vxdprintk(VXD_CBIT(net, 2),
18037 +               "nx_v6_addr_conflict(%p,%p): %d",
18038 +               nxi1, nxi2, ret);
18039 +
18040 +       return ret;
18041 +}
18042 +
18043 +#endif
18044 +
18045 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18046 +{
18047 +       struct in_device *in_dev;
18048 +       struct in_ifaddr **ifap;
18049 +       struct in_ifaddr *ifa;
18050 +       int ret = 0;
18051 +
18052 +       if (!dev)
18053 +               goto out;
18054 +       in_dev = in_dev_get(dev);
18055 +       if (!in_dev)
18056 +               goto out;
18057 +
18058 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18059 +               ifap = &ifa->ifa_next) {
18060 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18061 +                       ret = 1;
18062 +                       break;
18063 +               }
18064 +       }
18065 +       in_dev_put(in_dev);
18066 +out:
18067 +       return ret;
18068 +}
18069 +
18070 +
18071 +#ifdef CONFIG_IPV6
18072 +
18073 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18074 +{
18075 +       struct inet6_dev *in_dev;
18076 +       struct inet6_ifaddr *ifa;
18077 +       int ret = 0;
18078 +
18079 +       if (!dev)
18080 +               goto out;
18081 +       in_dev = in6_dev_get(dev);
18082 +       if (!in_dev)
18083 +               goto out;
18084 +
18085 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18086 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18087 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18088 +                       ret = 1;
18089 +                       break;
18090 +               }
18091 +       }
18092 +       in6_dev_put(in_dev);
18093 +out:
18094 +       return ret;
18095 +}
18096 +
18097 +#endif
18098 +
18099 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18100 +{
18101 +       int ret = 1;
18102 +
18103 +       if (!nxi)
18104 +               goto out;
18105 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18106 +               goto out;
18107 +#ifdef CONFIG_IPV6
18108 +       ret = 2;
18109 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18110 +               goto out;
18111 +#endif
18112 +       ret = 0;
18113 +out:
18114 +       vxdprintk(VXD_CBIT(net, 3),
18115 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18116 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18117 +       return ret;
18118 +}
18119 +
18120 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18121 +       struct flowi4 *fl4)
18122 +{
18123 +       struct rtable *rt;
18124 +
18125 +       if (!nxi)
18126 +               return NULL;
18127 +
18128 +       /* FIXME: handle lback only case */
18129 +       if (!NX_IPV4(nxi))
18130 +               return ERR_PTR(-EPERM);
18131 +
18132 +       vxdprintk(VXD_CBIT(net, 4),
18133 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18134 +               nxi, nxi ? nxi->nx_id : 0,
18135 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18136 +
18137 +       /* single IP is unconditional */
18138 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18139 +               (fl4->saddr == INADDR_ANY))
18140 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18141 +
18142 +       if (fl4->saddr == INADDR_ANY) {
18143 +               struct nx_addr_v4 *ptr;
18144 +               __be32 found = 0;
18145 +
18146 +               rt = __ip_route_output_key(net, fl4);
18147 +               if (!IS_ERR(rt)) {
18148 +                       found = fl4->saddr;
18149 +                       ip_rt_put(rt);
18150 +                       vxdprintk(VXD_CBIT(net, 4),
18151 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18152 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18153 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18154 +                               goto found;
18155 +               }
18156 +
18157 +               WARN_ON_ONCE(in_irq());
18158 +               spin_lock_bh(&nxi->addr_lock);
18159 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18160 +                       __be32 primary = ptr->ip[0].s_addr;
18161 +                       __be32 mask = ptr->mask.s_addr;
18162 +                       __be32 neta = primary & mask;
18163 +
18164 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18165 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18166 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18167 +                               NIPQUAD(mask), NIPQUAD(neta));
18168 +                       if ((found & mask) != neta)
18169 +                               continue;
18170 +
18171 +                       fl4->saddr = primary;
18172 +                       rt = __ip_route_output_key(net, fl4);
18173 +                       vxdprintk(VXD_CBIT(net, 4),
18174 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18175 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18176 +                       if (!IS_ERR(rt)) {
18177 +                               found = fl4->saddr;
18178 +                               ip_rt_put(rt);
18179 +                               if (found == primary)
18180 +                                       goto found_unlock;
18181 +                       }
18182 +               }
18183 +               /* still no source ip? */
18184 +               found = ipv4_is_loopback(fl4->daddr)
18185 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18186 +       found_unlock:
18187 +               spin_unlock_bh(&nxi->addr_lock);
18188 +       found:
18189 +               /* assign src ip to flow */
18190 +               fl4->saddr = found;
18191 +
18192 +       } else {
18193 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18194 +                       return ERR_PTR(-EPERM);
18195 +       }
18196 +
18197 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18198 +               if (ipv4_is_loopback(fl4->daddr))
18199 +                       fl4->daddr = nxi->v4_lback.s_addr;
18200 +               if (ipv4_is_loopback(fl4->saddr))
18201 +                       fl4->saddr = nxi->v4_lback.s_addr;
18202 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18203 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18204 +               return ERR_PTR(-EPERM);
18205 +
18206 +       return NULL;
18207 +}
18208 +
18209 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18210 +
18211 diff -NurpP --minimal linux-3.13.10/kernel/vserver/init.c linux-3.13.10-vs2.3.6.11/kernel/vserver/init.c
18212 --- linux-3.13.10/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
18213 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/init.c      2014-01-31 20:38:04.000000000 +0000
18214 @@ -0,0 +1,45 @@
18215 +/*
18216 + *  linux/kernel/init.c
18217 + *
18218 + *  Virtual Server Init
18219 + *
18220 + *  Copyright (C) 2004-2007  Herbert Pötzl
18221 + *
18222 + *  V0.01  basic structure
18223 + *
18224 + */
18225 +
18226 +#include <linux/init.h>
18227 +
18228 +int    vserver_register_sysctl(void);
18229 +void   vserver_unregister_sysctl(void);
18230 +
18231 +
18232 +static int __init init_vserver(void)
18233 +{
18234 +       int ret = 0;
18235 +
18236 +#ifdef CONFIG_VSERVER_DEBUG
18237 +       vserver_register_sysctl();
18238 +#endif
18239 +       return ret;
18240 +}
18241 +
18242 +
18243 +static void __exit exit_vserver(void)
18244 +{
18245 +
18246 +#ifdef CONFIG_VSERVER_DEBUG
18247 +       vserver_unregister_sysctl();
18248 +#endif
18249 +       return;
18250 +}
18251 +
18252 +/* FIXME: GFP_ZONETYPES gone
18253 +long vx_slab[GFP_ZONETYPES]; */
18254 +long vx_area;
18255 +
18256 +
18257 +module_init(init_vserver);
18258 +module_exit(exit_vserver);
18259 +
18260 diff -NurpP --minimal linux-3.13.10/kernel/vserver/inode.c linux-3.13.10-vs2.3.6.11/kernel/vserver/inode.c
18261 --- linux-3.13.10/kernel/vserver/inode.c        1970-01-01 00:00:00.000000000 +0000
18262 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/inode.c     2014-01-31 20:38:04.000000000 +0000
18263 @@ -0,0 +1,440 @@
18264 +/*
18265 + *  linux/kernel/vserver/inode.c
18266 + *
18267 + *  Virtual Server: File System Support
18268 + *
18269 + *  Copyright (C) 2004-2007  Herbert Pötzl
18270 + *
18271 + *  V0.01  separated from vcontext V0.05
18272 + *  V0.02  moved to tag (instead of xid)
18273 + *
18274 + */
18275 +
18276 +#include <linux/tty.h>
18277 +#include <linux/proc_fs.h>
18278 +#include <linux/devpts_fs.h>
18279 +#include <linux/fs.h>
18280 +#include <linux/file.h>
18281 +#include <linux/mount.h>
18282 +#include <linux/parser.h>
18283 +#include <linux/namei.h>
18284 +#include <linux/magic.h>
18285 +#include <linux/slab.h>
18286 +#include <linux/vserver/inode.h>
18287 +#include <linux/vserver/inode_cmd.h>
18288 +#include <linux/vs_base.h>
18289 +#include <linux/vs_tag.h>
18290 +
18291 +#include <asm/uaccess.h>
18292 +#include <../../fs/proc/internal.h>
18293 +
18294 +
18295 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18296 +{
18297 +       struct proc_dir_entry *entry;
18298 +
18299 +       if (!in || !in->i_sb)
18300 +               return -ESRCH;
18301 +
18302 +       *flags = IATTR_TAG
18303 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18304 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18305 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18306 +               | (IS_COW(in) ? IATTR_COW : 0);
18307 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18308 +
18309 +       if (S_ISDIR(in->i_mode))
18310 +               *mask |= IATTR_BARRIER;
18311 +
18312 +       if (IS_TAGGED(in)) {
18313 +               *tag = i_tag_read(in);
18314 +               *mask |= IATTR_TAG;
18315 +       }
18316 +
18317 +       switch (in->i_sb->s_magic) {
18318 +       case PROC_SUPER_MAGIC:
18319 +               entry = PROC_I(in)->pde;
18320 +
18321 +               /* check for specific inodes? */
18322 +               if (entry)
18323 +                       *mask |= IATTR_FLAGS;
18324 +               if (entry)
18325 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
18326 +               else
18327 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
18328 +               break;
18329 +
18330 +       case DEVPTS_SUPER_MAGIC:
18331 +               *tag = i_tag_read(in);
18332 +               *mask |= IATTR_TAG;
18333 +               break;
18334 +
18335 +       default:
18336 +               break;
18337 +       }
18338 +       return 0;
18339 +}
18340 +
18341 +int vc_get_iattr(void __user *data)
18342 +{
18343 +       struct path path;
18344 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
18345 +       int ret;
18346 +
18347 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18348 +               return -EFAULT;
18349 +
18350 +       ret = user_lpath(vc_data.name, &path);
18351 +       if (!ret) {
18352 +               ret = __vc_get_iattr(path.dentry->d_inode,
18353 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18354 +               path_put(&path);
18355 +       }
18356 +       if (ret)
18357 +               return ret;
18358 +
18359 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18360 +               ret = -EFAULT;
18361 +       return ret;
18362 +}
18363 +
18364 +#ifdef CONFIG_COMPAT
18365 +
18366 +int vc_get_iattr_x32(void __user *data)
18367 +{
18368 +       struct path path;
18369 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
18370 +       int ret;
18371 +
18372 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18373 +               return -EFAULT;
18374 +
18375 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18376 +       if (!ret) {
18377 +               ret = __vc_get_iattr(path.dentry->d_inode,
18378 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18379 +               path_put(&path);
18380 +       }
18381 +       if (ret)
18382 +               return ret;
18383 +
18384 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18385 +               ret = -EFAULT;
18386 +       return ret;
18387 +}
18388 +
18389 +#endif /* CONFIG_COMPAT */
18390 +
18391 +
18392 +int vc_fget_iattr(uint32_t fd, void __user *data)
18393 +{
18394 +       struct file *filp;
18395 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
18396 +       int ret;
18397 +
18398 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18399 +               return -EFAULT;
18400 +
18401 +       filp = fget(fd);
18402 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18403 +               return -EBADF;
18404 +
18405 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
18406 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
18407 +
18408 +       fput(filp);
18409 +
18410 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18411 +               ret = -EFAULT;
18412 +       return ret;
18413 +}
18414 +
18415 +
18416 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18417 +{
18418 +       struct inode *in = de->d_inode;
18419 +       int error = 0, is_proc = 0, has_tag = 0;
18420 +       struct iattr attr = { 0 };
18421 +
18422 +       if (!in || !in->i_sb)
18423 +               return -ESRCH;
18424 +
18425 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
18426 +       if ((*mask & IATTR_FLAGS) && !is_proc)
18427 +               return -EINVAL;
18428 +
18429 +       has_tag = IS_TAGGED(in) ||
18430 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
18431 +       if ((*mask & IATTR_TAG) && !has_tag)
18432 +               return -EINVAL;
18433 +
18434 +       mutex_lock(&in->i_mutex);
18435 +       if (*mask & IATTR_TAG) {
18436 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
18437 +               attr.ia_valid |= ATTR_TAG;
18438 +       }
18439 +
18440 +       if (*mask & IATTR_FLAGS) {
18441 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
18442 +               unsigned int iflags = PROC_I(in)->vx_flags;
18443 +
18444 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
18445 +                       | (*flags & IATTR_FLAGS);
18446 +               PROC_I(in)->vx_flags = iflags;
18447 +               if (entry)
18448 +                       entry->vx_flags = iflags;
18449 +       }
18450 +
18451 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
18452 +               IATTR_BARRIER | IATTR_COW)) {
18453 +               int iflags = in->i_flags;
18454 +               int vflags = in->i_vflags;
18455 +
18456 +               if (*mask & IATTR_IMMUTABLE) {
18457 +                       if (*flags & IATTR_IMMUTABLE)
18458 +                               iflags |= S_IMMUTABLE;
18459 +                       else
18460 +                               iflags &= ~S_IMMUTABLE;
18461 +               }
18462 +               if (*mask & IATTR_IXUNLINK) {
18463 +                       if (*flags & IATTR_IXUNLINK)
18464 +                               iflags |= S_IXUNLINK;
18465 +                       else
18466 +                               iflags &= ~S_IXUNLINK;
18467 +               }
18468 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
18469 +                       if (*flags & IATTR_BARRIER)
18470 +                               vflags |= V_BARRIER;
18471 +                       else
18472 +                               vflags &= ~V_BARRIER;
18473 +               }
18474 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
18475 +                       if (*flags & IATTR_COW)
18476 +                               vflags |= V_COW;
18477 +                       else
18478 +                               vflags &= ~V_COW;
18479 +               }
18480 +               if (in->i_op && in->i_op->sync_flags) {
18481 +                       error = in->i_op->sync_flags(in, iflags, vflags);
18482 +                       if (error)
18483 +                               goto out;
18484 +               }
18485 +       }
18486 +
18487 +       if (attr.ia_valid) {
18488 +               if (in->i_op && in->i_op->setattr)
18489 +                       error = in->i_op->setattr(de, &attr);
18490 +               else {
18491 +                       error = inode_change_ok(in, &attr);
18492 +                       if (!error) {
18493 +                               setattr_copy(in, &attr);
18494 +                               mark_inode_dirty(in);
18495 +                       }
18496 +               }
18497 +       }
18498 +
18499 +out:
18500 +       mutex_unlock(&in->i_mutex);
18501 +       return error;
18502 +}
18503 +
18504 +int vc_set_iattr(void __user *data)
18505 +{
18506 +       struct path path;
18507 +       struct vcmd_ctx_iattr_v1 vc_data;
18508 +       int ret;
18509 +
18510 +       if (!capable(CAP_LINUX_IMMUTABLE))
18511 +               return -EPERM;
18512 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18513 +               return -EFAULT;
18514 +
18515 +       ret = user_lpath(vc_data.name, &path);
18516 +       if (!ret) {
18517 +               ret = __vc_set_iattr(path.dentry,
18518 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18519 +               path_put(&path);
18520 +       }
18521 +
18522 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18523 +               ret = -EFAULT;
18524 +       return ret;
18525 +}
18526 +
18527 +#ifdef CONFIG_COMPAT
18528 +
18529 +int vc_set_iattr_x32(void __user *data)
18530 +{
18531 +       struct path path;
18532 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
18533 +       int ret;
18534 +
18535 +       if (!capable(CAP_LINUX_IMMUTABLE))
18536 +               return -EPERM;
18537 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18538 +               return -EFAULT;
18539 +
18540 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18541 +       if (!ret) {
18542 +               ret = __vc_set_iattr(path.dentry,
18543 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
18544 +               path_put(&path);
18545 +       }
18546 +
18547 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18548 +               ret = -EFAULT;
18549 +       return ret;
18550 +}
18551 +
18552 +#endif /* CONFIG_COMPAT */
18553 +
18554 +int vc_fset_iattr(uint32_t fd, void __user *data)
18555 +{
18556 +       struct file *filp;
18557 +       struct vcmd_ctx_fiattr_v0 vc_data;
18558 +       int ret;
18559 +
18560 +       if (!capable(CAP_LINUX_IMMUTABLE))
18561 +               return -EPERM;
18562 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18563 +               return -EFAULT;
18564 +
18565 +       filp = fget(fd);
18566 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18567 +               return -EBADF;
18568 +
18569 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
18570 +               &vc_data.flags, &vc_data.mask);
18571 +
18572 +       fput(filp);
18573 +
18574 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18575 +               return -EFAULT;
18576 +       return ret;
18577 +}
18578 +
18579 +
18580 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
18581 +
18582 +static match_table_t tokens = {
18583 +       {Opt_notagcheck, "notagcheck"},
18584 +#ifdef CONFIG_PROPAGATE
18585 +       {Opt_notag, "notag"},
18586 +       {Opt_tag, "tag"},
18587 +       {Opt_tagid, "tagid=%u"},
18588 +#endif
18589 +       {Opt_err, NULL}
18590 +};
18591 +
18592 +
18593 +static void __dx_parse_remove(char *string, char *opt)
18594 +{
18595 +       char *p = strstr(string, opt);
18596 +       char *q = p;
18597 +
18598 +       if (p) {
18599 +               while (*q != '\0' && *q != ',')
18600 +                       q++;
18601 +               while (*q)
18602 +                       *p++ = *q++;
18603 +               while (*p)
18604 +                       *p++ = '\0';
18605 +       }
18606 +}
18607 +
18608 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
18609 +                unsigned long *flags)
18610 +{
18611 +       int set = 0;
18612 +       substring_t args[MAX_OPT_ARGS];
18613 +       int token;
18614 +       char *s, *p, *opts;
18615 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
18616 +       int option = 0;
18617 +#endif
18618 +
18619 +       if (!string)
18620 +               return 0;
18621 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
18622 +       if (!s)
18623 +               return 0;
18624 +
18625 +       opts = s;
18626 +       while ((p = strsep(&opts, ",")) != NULL) {
18627 +               token = match_token(p, tokens, args);
18628 +
18629 +               switch (token) {
18630 +#ifdef CONFIG_PROPAGATE
18631 +               case Opt_tag:
18632 +                       if (tag)
18633 +                               *tag = 0;
18634 +                       if (remove)
18635 +                               __dx_parse_remove(s, "tag");
18636 +                       *mnt_flags |= MNT_TAGID;
18637 +                       set |= MNT_TAGID;
18638 +                       break;
18639 +               case Opt_notag:
18640 +                       if (remove)
18641 +                               __dx_parse_remove(s, "notag");
18642 +                       *mnt_flags |= MNT_NOTAG;
18643 +                       set |= MNT_NOTAG;
18644 +                       break;
18645 +               case Opt_tagid:
18646 +                       if (tag && !match_int(args, &option))
18647 +                               *tag = option;
18648 +                       if (remove)
18649 +                               __dx_parse_remove(s, "tagid");
18650 +                       *mnt_flags |= MNT_TAGID;
18651 +                       set |= MNT_TAGID;
18652 +                       break;
18653 +#endif /* CONFIG_PROPAGATE */
18654 +               case Opt_notagcheck:
18655 +                       if (remove)
18656 +                               __dx_parse_remove(s, "notagcheck");
18657 +                       *flags |= MS_NOTAGCHECK;
18658 +                       set |= MS_NOTAGCHECK;
18659 +                       break;
18660 +               }
18661 +               vxdprintk(VXD_CBIT(tag, 7),
18662 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
18663 +                       p, token, option);
18664 +       }
18665 +       if (set)
18666 +               strcpy(string, s);
18667 +       kfree(s);
18668 +       return set;
18669 +}
18670 +
18671 +#ifdef CONFIG_PROPAGATE
18672 +
18673 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
18674 +{
18675 +       vtag_t new_tag = 0;
18676 +       struct vfsmount *mnt;
18677 +       int propagate;
18678 +
18679 +       if (!nd)
18680 +               return;
18681 +       mnt = nd->path.mnt;
18682 +       if (!mnt)
18683 +               return;
18684 +
18685 +       propagate = (mnt->mnt_flags & MNT_TAGID);
18686 +       if (propagate)
18687 +               new_tag = mnt->mnt_tag;
18688 +
18689 +       vxdprintk(VXD_CBIT(tag, 7),
18690 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
18691 +               inode, inode->i_ino, inode->i_tag,
18692 +               new_tag, (propagate) ? 1 : 0);
18693 +
18694 +       if (propagate)
18695 +               i_tag_write(inode, new_tag);
18696 +}
18697 +
18698 +#include <linux/module.h>
18699 +
18700 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
18701 +
18702 +#endif /* CONFIG_PROPAGATE */
18703 +
18704 diff -NurpP --minimal linux-3.13.10/kernel/vserver/limit.c linux-3.13.10-vs2.3.6.11/kernel/vserver/limit.c
18705 --- linux-3.13.10/kernel/vserver/limit.c        1970-01-01 00:00:00.000000000 +0000
18706 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit.c     2014-02-01 00:22:08.000000000 +0000
18707 @@ -0,0 +1,345 @@
18708 +/*
18709 + *  linux/kernel/vserver/limit.c
18710 + *
18711 + *  Virtual Server: Context Limits
18712 + *
18713 + *  Copyright (C) 2004-2010  Herbert Pötzl
18714 + *
18715 + *  V0.01  broken out from vcontext V0.05
18716 + *  V0.02  changed vcmds to vxi arg
18717 + *  V0.03  added memory cgroup support
18718 + *
18719 + */
18720 +
18721 +#include <linux/sched.h>
18722 +#include <linux/module.h>
18723 +#include <linux/memcontrol.h>
18724 +#include <linux/res_counter.h>
18725 +#include <linux/vs_limit.h>
18726 +#include <linux/vserver/limit.h>
18727 +#include <linux/vserver/limit_cmd.h>
18728 +
18729 +#include <asm/uaccess.h>
18730 +
18731 +
18732 +const char *vlimit_name[NUM_LIMITS] = {
18733 +       [RLIMIT_CPU]            = "CPU",
18734 +       [RLIMIT_NPROC]          = "NPROC",
18735 +       [RLIMIT_NOFILE]         = "NOFILE",
18736 +       [RLIMIT_LOCKS]          = "LOCKS",
18737 +       [RLIMIT_SIGPENDING]     = "SIGP",
18738 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
18739 +
18740 +       [VLIMIT_NSOCK]          = "NSOCK",
18741 +       [VLIMIT_OPENFD]         = "OPENFD",
18742 +       [VLIMIT_SHMEM]          = "SHMEM",
18743 +       [VLIMIT_DENTRY]         = "DENTRY",
18744 +};
18745 +
18746 +EXPORT_SYMBOL_GPL(vlimit_name);
18747 +
18748 +#define MASK_ENTRY(x)  (1 << (x))
18749 +
18750 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
18751 +               /* minimum */
18752 +       0
18753 +       ,       /* softlimit */
18754 +       0
18755 +       ,       /* maximum */
18756 +       MASK_ENTRY( RLIMIT_NPROC        ) |
18757 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
18758 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
18759 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
18760 +
18761 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
18762 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
18763 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
18764 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
18765 +       0
18766 +};
18767 +               /* accounting only */
18768 +uint32_t account_mask =
18769 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
18770 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
18771 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
18772 +       0;
18773 +
18774 +
18775 +static int is_valid_vlimit(int id)
18776 +{
18777 +       uint32_t mask = vlimit_mask.minimum |
18778 +               vlimit_mask.softlimit | vlimit_mask.maximum;
18779 +       return mask & (1 << id);
18780 +}
18781 +
18782 +static int is_accounted_vlimit(int id)
18783 +{
18784 +       if (is_valid_vlimit(id))
18785 +               return 1;
18786 +       return account_mask & (1 << id);
18787 +}
18788 +
18789 +
18790 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
18791 +{
18792 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
18793 +       return VX_VLIM(limit);
18794 +}
18795 +
18796 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
18797 +{
18798 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
18799 +       return VX_VLIM(limit);
18800 +}
18801 +
18802 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
18803 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
18804 +{
18805 +       if (!is_valid_vlimit(id))
18806 +               return -EINVAL;
18807 +
18808 +       if (minimum)
18809 +               *minimum = CRLIM_UNSET;
18810 +       if (softlimit)
18811 +               *softlimit = vc_get_soft(vxi, id);
18812 +       if (maximum)
18813 +               *maximum = vc_get_hard(vxi, id);
18814 +       return 0;
18815 +}
18816 +
18817 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
18818 +{
18819 +       struct vcmd_ctx_rlimit_v0 vc_data;
18820 +       int ret;
18821 +
18822 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18823 +               return -EFAULT;
18824 +
18825 +       ret = do_get_rlimit(vxi, vc_data.id,
18826 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18827 +       if (ret)
18828 +               return ret;
18829 +
18830 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18831 +               return -EFAULT;
18832 +       return 0;
18833 +}
18834 +
18835 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
18836 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
18837 +{
18838 +       if (!is_valid_vlimit(id))
18839 +               return -EINVAL;
18840 +
18841 +       if (maximum != CRLIM_KEEP)
18842 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
18843 +       if (softlimit != CRLIM_KEEP)
18844 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
18845 +
18846 +       /* clamp soft limit */
18847 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
18848 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
18849 +
18850 +       return 0;
18851 +}
18852 +
18853 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
18854 +{
18855 +       struct vcmd_ctx_rlimit_v0 vc_data;
18856 +
18857 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18858 +               return -EFAULT;
18859 +
18860 +       return do_set_rlimit(vxi, vc_data.id,
18861 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18862 +}
18863 +
18864 +#ifdef CONFIG_IA32_EMULATION
18865 +
18866 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
18867 +{
18868 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18869 +
18870 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18871 +               return -EFAULT;
18872 +
18873 +       return do_set_rlimit(vxi, vc_data.id,
18874 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18875 +}
18876 +
18877 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
18878 +{
18879 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
18880 +       int ret;
18881 +
18882 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18883 +               return -EFAULT;
18884 +
18885 +       ret = do_get_rlimit(vxi, vc_data.id,
18886 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18887 +       if (ret)
18888 +               return ret;
18889 +
18890 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18891 +               return -EFAULT;
18892 +       return 0;
18893 +}
18894 +
18895 +#endif /* CONFIG_IA32_EMULATION */
18896 +
18897 +
18898 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
18899 +{
18900 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
18901 +               return -EFAULT;
18902 +       return 0;
18903 +}
18904 +
18905 +
18906 +static inline void vx_reset_hits(struct _vx_limit *limit)
18907 +{
18908 +       int lim;
18909 +
18910 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18911 +               atomic_set(&__rlim_lhit(limit, lim), 0);
18912 +       }
18913 +}
18914 +
18915 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
18916 +{
18917 +       vx_reset_hits(&vxi->limit);
18918 +       return 0;
18919 +}
18920 +
18921 +static inline void vx_reset_minmax(struct _vx_limit *limit)
18922 +{
18923 +       rlim_t value;
18924 +       int lim;
18925 +
18926 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
18927 +               value = __rlim_get(limit, lim);
18928 +               __rlim_rmax(limit, lim) = value;
18929 +               __rlim_rmin(limit, lim) = value;
18930 +       }
18931 +}
18932 +
18933 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
18934 +{
18935 +       vx_reset_minmax(&vxi->limit);
18936 +       return 0;
18937 +}
18938 +
18939 +
18940 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
18941 +{
18942 +       struct vcmd_rlimit_stat_v0 vc_data;
18943 +       struct _vx_limit *limit = &vxi->limit;
18944 +       int id;
18945 +
18946 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18947 +               return -EFAULT;
18948 +
18949 +       id = vc_data.id;
18950 +       if (!is_accounted_vlimit(id))
18951 +               return -EINVAL;
18952 +
18953 +       vx_limit_fixup(limit, id);
18954 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
18955 +       vc_data.value = __rlim_get(limit, id);
18956 +       vc_data.minimum = __rlim_rmin(limit, id);
18957 +       vc_data.maximum = __rlim_rmax(limit, id);
18958 +
18959 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18960 +               return -EFAULT;
18961 +       return 0;
18962 +}
18963 +
18964 +
18965 +void vx_vsi_meminfo(struct sysinfo *val)
18966 +{
18967 +#ifdef CONFIG_MEMCG
18968 +       struct mem_cgroup *mcg;
18969 +       u64 res_limit, res_usage;
18970 +
18971 +       rcu_read_lock();
18972 +       mcg = mem_cgroup_from_task(current);
18973 +       rcu_read_unlock();
18974 +       if (!mcg)
18975 +               goto out;
18976 +
18977 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
18978 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
18979 +
18980 +       if (res_limit != RES_COUNTER_MAX)
18981 +               val->totalram = (res_limit >> PAGE_SHIFT);
18982 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
18983 +       val->bufferram = 0;
18984 +       val->totalhigh = 0;
18985 +       val->freehigh = 0;
18986 +out:
18987 +#endif /* CONFIG_MEMCG */
18988 +       return;
18989 +}
18990 +
18991 +void vx_vsi_swapinfo(struct sysinfo *val)
18992 +{
18993 +#ifdef CONFIG_MEMCG
18994 +#ifdef CONFIG_MEMCG_SWAP
18995 +       struct mem_cgroup *mcg;
18996 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
18997 +       s64 swap_limit, swap_usage;
18998 +
18999 +       rcu_read_lock();
19000 +       mcg = mem_cgroup_from_task(current);
19001 +       rcu_read_unlock();
19002 +       if (!mcg)
19003 +               goto out;
19004 +
19005 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19006 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19007 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19008 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19009 +
19010 +       /* memory unlimited */
19011 +       if (res_limit == RES_COUNTER_MAX)
19012 +               goto out;
19013 +
19014 +       swap_limit = memsw_limit - res_limit;
19015 +       /* we have a swap limit? */
19016 +       if (memsw_limit != RES_COUNTER_MAX)
19017 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19018 +
19019 +       /* calculate swap part */
19020 +       swap_usage = (memsw_usage > res_usage) ?
19021 +               memsw_usage - res_usage : 0;
19022 +
19023 +       /* total shown minus usage gives free swap */
19024 +       val->freeswap = (swap_usage < swap_limit) ?
19025 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19026 +out:
19027 +#else  /* !CONFIG_MEMCG_SWAP */
19028 +       val->totalswap = 0;
19029 +       val->freeswap = 0;
19030 +#endif /* !CONFIG_MEMCG_SWAP */
19031 +#endif /* CONFIG_MEMCG */
19032 +       return;
19033 +}
19034 +
19035 +long vx_vsi_cached(struct sysinfo *val)
19036 +{
19037 +       long cache = 0;
19038 +#ifdef CONFIG_MEMCG
19039 +       struct mem_cgroup *mcg;
19040 +
19041 +       rcu_read_lock();
19042 +       mcg = mem_cgroup_from_task(current);
19043 +       rcu_read_unlock();
19044 +       if (!mcg)
19045 +               goto out;
19046 +
19047 +       cache = mem_cgroup_stat_read_cache(mcg);
19048 +out:
19049 +#endif
19050 +       return cache;
19051 +}
19052 +
19053 diff -NurpP --minimal linux-3.13.10/kernel/vserver/limit_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_init.h
19054 --- linux-3.13.10/kernel/vserver/limit_init.h   1970-01-01 00:00:00.000000000 +0000
19055 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_init.h        2014-01-31 20:38:04.000000000 +0000
19056 @@ -0,0 +1,31 @@
19057 +
19058 +
19059 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19060 +{
19061 +       int lim;
19062 +
19063 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19064 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19065 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19066 +               __rlim_set(limit, lim, 0);
19067 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19068 +               __rlim_rmin(limit, lim) = 0;
19069 +               __rlim_rmax(limit, lim) = 0;
19070 +       }
19071 +}
19072 +
19073 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19074 +{
19075 +       rlim_t value;
19076 +       int lim;
19077 +
19078 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19079 +               if ((1 << lim) & VLIM_NOCHECK)
19080 +                       continue;
19081 +               value = __rlim_get(limit, lim);
19082 +               vxwprintk_xid(value,
19083 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19084 +                       limit, vlimit_name[lim], lim, (long)value);
19085 +       }
19086 +}
19087 +
19088 diff -NurpP --minimal linux-3.13.10/kernel/vserver/limit_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_proc.h
19089 --- linux-3.13.10/kernel/vserver/limit_proc.h   1970-01-01 00:00:00.000000000 +0000
19090 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_proc.h        2014-01-31 20:38:04.000000000 +0000
19091 @@ -0,0 +1,57 @@
19092 +#ifndef _VX_LIMIT_PROC_H
19093 +#define _VX_LIMIT_PROC_H
19094 +
19095 +#include <linux/vserver/limit_int.h>
19096 +
19097 +
19098 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19099 +#define VX_LIMIT_TOP   \
19100 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19101 +
19102 +#define VX_LIMIT_ARG(r)                                \
19103 +       (unsigned long)__rlim_get(limit, r),    \
19104 +       (unsigned long)__rlim_rmin(limit, r),   \
19105 +       (unsigned long)__rlim_rmax(limit, r),   \
19106 +       VX_VLIM(__rlim_soft(limit, r)),         \
19107 +       VX_VLIM(__rlim_hard(limit, r)),         \
19108 +       atomic_read(&__rlim_lhit(limit, r))
19109 +
19110 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19111 +{
19112 +       vx_limit_fixup(limit, -1);
19113 +       return sprintf(buffer, VX_LIMIT_TOP
19114 +               "PROC"  VX_LIMIT_FMT
19115 +               "VM"    VX_LIMIT_FMT
19116 +               "VML"   VX_LIMIT_FMT
19117 +               "RSS"   VX_LIMIT_FMT
19118 +               "ANON"  VX_LIMIT_FMT
19119 +               "RMAP"  VX_LIMIT_FMT
19120 +               "FILES" VX_LIMIT_FMT
19121 +               "OFD"   VX_LIMIT_FMT
19122 +               "LOCKS" VX_LIMIT_FMT
19123 +               "SOCK"  VX_LIMIT_FMT
19124 +               "MSGQ"  VX_LIMIT_FMT
19125 +               "SHM"   VX_LIMIT_FMT
19126 +               "SEMA"  VX_LIMIT_FMT
19127 +               "SEMS"  VX_LIMIT_FMT
19128 +               "DENT"  VX_LIMIT_FMT,
19129 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19130 +               VX_LIMIT_ARG(RLIMIT_AS),
19131 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19132 +               VX_LIMIT_ARG(RLIMIT_RSS),
19133 +               VX_LIMIT_ARG(VLIMIT_ANON),
19134 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19135 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19136 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19137 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19138 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19139 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19140 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19141 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19142 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19143 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19144 +}
19145 +
19146 +#endif /* _VX_LIMIT_PROC_H */
19147 +
19148 +
19149 diff -NurpP --minimal linux-3.13.10/kernel/vserver/network.c linux-3.13.10-vs2.3.6.11/kernel/vserver/network.c
19150 --- linux-3.13.10/kernel/vserver/network.c      1970-01-01 00:00:00.000000000 +0000
19151 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/network.c   2014-01-31 20:38:04.000000000 +0000
19152 @@ -0,0 +1,1053 @@
19153 +/*
19154 + *  linux/kernel/vserver/network.c
19155 + *
19156 + *  Virtual Server: Network Support
19157 + *
19158 + *  Copyright (C) 2003-2007  Herbert Pötzl
19159 + *
19160 + *  V0.01  broken out from vcontext V0.05
19161 + *  V0.02  cleaned up implementation
19162 + *  V0.03  added equiv nx commands
19163 + *  V0.04  switch to RCU based hash
19164 + *  V0.05  and back to locking again
19165 + *  V0.06  changed vcmds to nxi arg
19166 + *  V0.07  have __create claim() the nxi
19167 + *
19168 + */
19169 +
19170 +#include <linux/err.h>
19171 +#include <linux/slab.h>
19172 +#include <linux/rcupdate.h>
19173 +#include <net/ipv6.h>
19174 +
19175 +#include <linux/vs_network.h>
19176 +#include <linux/vs_pid.h>
19177 +#include <linux/vserver/network_cmd.h>
19178 +
19179 +
19180 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19181 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19182 +
19183 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19184 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19185 +
19186 +
19187 +static int __init init_network(void)
19188 +{
19189 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19190 +               sizeof(struct nx_addr_v4), 0,
19191 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19192 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19193 +               sizeof(struct nx_addr_v6), 0,
19194 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19195 +       return 0;
19196 +}
19197 +
19198 +
19199 +/*     __alloc_nx_addr_v4()                                    */
19200 +
19201 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19202 +{
19203 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19204 +               nx_addr_v4_cachep, GFP_KERNEL);
19205 +
19206 +       if (!IS_ERR(nxa))
19207 +               memset(nxa, 0, sizeof(*nxa));
19208 +       return nxa;
19209 +}
19210 +
19211 +/*     __dealloc_nx_addr_v4()                                  */
19212 +
19213 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19214 +{
19215 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19216 +}
19217 +
19218 +/*     __dealloc_nx_addr_v4_all()                              */
19219 +
19220 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19221 +{
19222 +       while (nxa) {
19223 +               struct nx_addr_v4 *next = nxa->next;
19224 +
19225 +               __dealloc_nx_addr_v4(nxa);
19226 +               nxa = next;
19227 +       }
19228 +}
19229 +
19230 +
19231 +#ifdef CONFIG_IPV6
19232 +
19233 +/*     __alloc_nx_addr_v6()                                    */
19234 +
19235 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19236 +{
19237 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19238 +               nx_addr_v6_cachep, GFP_KERNEL);
19239 +
19240 +       if (!IS_ERR(nxa))
19241 +               memset(nxa, 0, sizeof(*nxa));
19242 +       return nxa;
19243 +}
19244 +
19245 +/*     __dealloc_nx_addr_v6()                                  */
19246 +
19247 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19248 +{
19249 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19250 +}
19251 +
19252 +/*     __dealloc_nx_addr_v6_all()                              */
19253 +
19254 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19255 +{
19256 +       while (nxa) {
19257 +               struct nx_addr_v6 *next = nxa->next;
19258 +
19259 +               __dealloc_nx_addr_v6(nxa);
19260 +               nxa = next;
19261 +       }
19262 +}
19263 +
19264 +#endif /* CONFIG_IPV6 */
19265 +
19266 +/*     __alloc_nx_info()
19267 +
19268 +       * allocate an initialized nx_info struct
19269 +       * doesn't make it visible (hash)                        */
19270 +
19271 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19272 +{
19273 +       struct nx_info *new = NULL;
19274 +
19275 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19276 +
19277 +       /* would this benefit from a slab cache? */
19278 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19279 +       if (!new)
19280 +               return 0;
19281 +
19282 +       memset(new, 0, sizeof(struct nx_info));
19283 +       new->nx_id = nid;
19284 +       INIT_HLIST_NODE(&new->nx_hlist);
19285 +       atomic_set(&new->nx_usecnt, 0);
19286 +       atomic_set(&new->nx_tasks, 0);
19287 +       spin_lock_init(&new->addr_lock);
19288 +       new->nx_state = 0;
19289 +
19290 +       new->nx_flags = NXF_INIT_SET;
19291 +
19292 +       /* rest of init goes here */
19293 +
19294 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19295 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19296 +
19297 +       vxdprintk(VXD_CBIT(nid, 0),
19298 +               "alloc_nx_info(%d) = %p", nid, new);
19299 +       atomic_inc(&nx_global_ctotal);
19300 +       return new;
19301 +}
19302 +
19303 +/*     __dealloc_nx_info()
19304 +
19305 +       * final disposal of nx_info                             */
19306 +
19307 +static void __dealloc_nx_info(struct nx_info *nxi)
19308 +{
19309 +       vxdprintk(VXD_CBIT(nid, 0),
19310 +               "dealloc_nx_info(%p)", nxi);
19311 +
19312 +       nxi->nx_hlist.next = LIST_POISON1;
19313 +       nxi->nx_id = -1;
19314 +
19315 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19316 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19317 +
19318 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
19319 +#ifdef CONFIG_IPV6
19320 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
19321 +#endif
19322 +
19323 +       nxi->nx_state |= NXS_RELEASED;
19324 +       kfree(nxi);
19325 +       atomic_dec(&nx_global_ctotal);
19326 +}
19327 +
19328 +static void __shutdown_nx_info(struct nx_info *nxi)
19329 +{
19330 +       nxi->nx_state |= NXS_SHUTDOWN;
19331 +       vs_net_change(nxi, VSC_NETDOWN);
19332 +}
19333 +
19334 +/*     exported stuff                                          */
19335 +
19336 +void free_nx_info(struct nx_info *nxi)
19337 +{
19338 +       /* context shutdown is mandatory */
19339 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
19340 +
19341 +       /* context must not be hashed */
19342 +       BUG_ON(nxi->nx_state & NXS_HASHED);
19343 +
19344 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
19345 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19346 +
19347 +       __dealloc_nx_info(nxi);
19348 +}
19349 +
19350 +
19351 +void __nx_set_lback(struct nx_info *nxi)
19352 +{
19353 +       int nid = nxi->nx_id;
19354 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
19355 +
19356 +       nxi->v4_lback.s_addr = lback;
19357 +}
19358 +
19359 +extern int __nx_inet_add_lback(__be32 addr);
19360 +extern int __nx_inet_del_lback(__be32 addr);
19361 +
19362 +
19363 +/*     hash table for nx_info hash */
19364 +
19365 +#define NX_HASH_SIZE   13
19366 +
19367 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
19368 +
19369 +static DEFINE_SPINLOCK(nx_info_hash_lock);
19370 +
19371 +
19372 +static inline unsigned int __hashval(vnid_t nid)
19373 +{
19374 +       return (nid % NX_HASH_SIZE);
19375 +}
19376 +
19377 +
19378 +
19379 +/*     __hash_nx_info()
19380 +
19381 +       * add the nxi to the global hash table
19382 +       * requires the hash_lock to be held                     */
19383 +
19384 +static inline void __hash_nx_info(struct nx_info *nxi)
19385 +{
19386 +       struct hlist_head *head;
19387 +
19388 +       vxd_assert_lock(&nx_info_hash_lock);
19389 +       vxdprintk(VXD_CBIT(nid, 4),
19390 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
19391 +
19392 +       /* context must not be hashed */
19393 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
19394 +
19395 +       nxi->nx_state |= NXS_HASHED;
19396 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
19397 +       hlist_add_head(&nxi->nx_hlist, head);
19398 +       atomic_inc(&nx_global_cactive);
19399 +}
19400 +
19401 +/*     __unhash_nx_info()
19402 +
19403 +       * remove the nxi from the global hash table
19404 +       * requires the hash_lock to be held                     */
19405 +
19406 +static inline void __unhash_nx_info(struct nx_info *nxi)
19407 +{
19408 +       vxd_assert_lock(&nx_info_hash_lock);
19409 +       vxdprintk(VXD_CBIT(nid, 4),
19410 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
19411 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
19412 +
19413 +       /* context must be hashed */
19414 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
19415 +       /* but without tasks */
19416 +       BUG_ON(atomic_read(&nxi->nx_tasks));
19417 +
19418 +       nxi->nx_state &= ~NXS_HASHED;
19419 +       hlist_del(&nxi->nx_hlist);
19420 +       atomic_dec(&nx_global_cactive);
19421 +}
19422 +
19423 +
19424 +/*     __lookup_nx_info()
19425 +
19426 +       * requires the hash_lock to be held
19427 +       * doesn't increment the nx_refcnt                       */
19428 +
19429 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
19430 +{
19431 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
19432 +       struct hlist_node *pos;
19433 +       struct nx_info *nxi;
19434 +
19435 +       vxd_assert_lock(&nx_info_hash_lock);
19436 +       hlist_for_each(pos, head) {
19437 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19438 +
19439 +               if (nxi->nx_id == nid)
19440 +                       goto found;
19441 +       }
19442 +       nxi = NULL;
19443 +found:
19444 +       vxdprintk(VXD_CBIT(nid, 0),
19445 +               "__lookup_nx_info(#%u): %p[#%u]",
19446 +               nid, nxi, nxi ? nxi->nx_id : 0);
19447 +       return nxi;
19448 +}
19449 +
19450 +
19451 +/*     __create_nx_info()
19452 +
19453 +       * create the requested context
19454 +       * get(), claim() and hash it                            */
19455 +
19456 +static struct nx_info *__create_nx_info(int id)
19457 +{
19458 +       struct nx_info *new, *nxi = NULL;
19459 +
19460 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
19461 +
19462 +       if (!(new = __alloc_nx_info(id)))
19463 +               return ERR_PTR(-ENOMEM);
19464 +
19465 +       /* required to make dynamic xids unique */
19466 +       spin_lock(&nx_info_hash_lock);
19467 +
19468 +       /* static context requested */
19469 +       if ((nxi = __lookup_nx_info(id))) {
19470 +               vxdprintk(VXD_CBIT(nid, 0),
19471 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
19472 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19473 +                       nxi = ERR_PTR(-EBUSY);
19474 +               else
19475 +                       nxi = ERR_PTR(-EEXIST);
19476 +               goto out_unlock;
19477 +       }
19478 +       /* new context */
19479 +       vxdprintk(VXD_CBIT(nid, 0),
19480 +               "create_nx_info(%d) = %p (new)", id, new);
19481 +       claim_nx_info(new, NULL);
19482 +       __nx_set_lback(new);
19483 +       __hash_nx_info(get_nx_info(new));
19484 +       nxi = new, new = NULL;
19485 +
19486 +out_unlock:
19487 +       spin_unlock(&nx_info_hash_lock);
19488 +       if (new)
19489 +               __dealloc_nx_info(new);
19490 +       return nxi;
19491 +}
19492 +
19493 +
19494 +
19495 +/*     exported stuff                                          */
19496 +
19497 +
19498 +void unhash_nx_info(struct nx_info *nxi)
19499 +{
19500 +       __shutdown_nx_info(nxi);
19501 +       spin_lock(&nx_info_hash_lock);
19502 +       __unhash_nx_info(nxi);
19503 +       spin_unlock(&nx_info_hash_lock);
19504 +}
19505 +
19506 +/*     lookup_nx_info()
19507 +
19508 +       * search for a nx_info and get() it
19509 +       * negative id means current                             */
19510 +
19511 +struct nx_info *lookup_nx_info(int id)
19512 +{
19513 +       struct nx_info *nxi = NULL;
19514 +
19515 +       if (id < 0) {
19516 +               nxi = get_nx_info(current_nx_info());
19517 +       } else if (id > 1) {
19518 +               spin_lock(&nx_info_hash_lock);
19519 +               nxi = get_nx_info(__lookup_nx_info(id));
19520 +               spin_unlock(&nx_info_hash_lock);
19521 +       }
19522 +       return nxi;
19523 +}
19524 +
19525 +/*     nid_is_hashed()
19526 +
19527 +       * verify that nid is still hashed                       */
19528 +
19529 +int nid_is_hashed(vnid_t nid)
19530 +{
19531 +       int hashed;
19532 +
19533 +       spin_lock(&nx_info_hash_lock);
19534 +       hashed = (__lookup_nx_info(nid) != NULL);
19535 +       spin_unlock(&nx_info_hash_lock);
19536 +       return hashed;
19537 +}
19538 +
19539 +
19540 +#ifdef CONFIG_PROC_FS
19541 +
19542 +/*     get_nid_list()
19543 +
19544 +       * get a subset of hashed nids for proc
19545 +       * assumes size is at least one                          */
19546 +
19547 +int get_nid_list(int index, unsigned int *nids, int size)
19548 +{
19549 +       int hindex, nr_nids = 0;
19550 +
19551 +       /* only show current and children */
19552 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
19553 +               if (index > 0)
19554 +                       return 0;
19555 +               nids[nr_nids] = nx_current_nid();
19556 +               return 1;
19557 +       }
19558 +
19559 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
19560 +               struct hlist_head *head = &nx_info_hash[hindex];
19561 +               struct hlist_node *pos;
19562 +
19563 +               spin_lock(&nx_info_hash_lock);
19564 +               hlist_for_each(pos, head) {
19565 +                       struct nx_info *nxi;
19566 +
19567 +                       if (--index > 0)
19568 +                               continue;
19569 +
19570 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19571 +                       nids[nr_nids] = nxi->nx_id;
19572 +                       if (++nr_nids >= size) {
19573 +                               spin_unlock(&nx_info_hash_lock);
19574 +                               goto out;
19575 +                       }
19576 +               }
19577 +               /* keep the lock time short */
19578 +               spin_unlock(&nx_info_hash_lock);
19579 +       }
19580 +out:
19581 +       return nr_nids;
19582 +}
19583 +#endif
19584 +
19585 +
19586 +/*
19587 + *     migrate task to new network
19588 + *     gets nxi, puts old_nxi on change
19589 + */
19590 +
19591 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
19592 +{
19593 +       struct nx_info *old_nxi;
19594 +       int ret = 0;
19595 +
19596 +       if (!p || !nxi)
19597 +               BUG();
19598 +
19599 +       vxdprintk(VXD_CBIT(nid, 5),
19600 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
19601 +               p, nxi, nxi->nx_id,
19602 +               atomic_read(&nxi->nx_usecnt),
19603 +               atomic_read(&nxi->nx_tasks));
19604 +
19605 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
19606 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19607 +               return -EACCES;
19608 +
19609 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
19610 +               return -EFAULT;
19611 +
19612 +       /* maybe disallow this completely? */
19613 +       old_nxi = task_get_nx_info(p);
19614 +       if (old_nxi == nxi)
19615 +               goto out;
19616 +
19617 +       task_lock(p);
19618 +       if (old_nxi)
19619 +               clr_nx_info(&p->nx_info);
19620 +       claim_nx_info(nxi, p);
19621 +       set_nx_info(&p->nx_info, nxi);
19622 +       p->nid = nxi->nx_id;
19623 +       task_unlock(p);
19624 +
19625 +       vxdprintk(VXD_CBIT(nid, 5),
19626 +               "moved task %p into nxi:%p[#%d]",
19627 +               p, nxi, nxi->nx_id);
19628 +
19629 +       if (old_nxi)
19630 +               release_nx_info(old_nxi, p);
19631 +       ret = 0;
19632 +out:
19633 +       put_nx_info(old_nxi);
19634 +       return ret;
19635 +}
19636 +
19637 +
19638 +void nx_set_persistent(struct nx_info *nxi)
19639 +{
19640 +       vxdprintk(VXD_CBIT(nid, 6),
19641 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
19642 +
19643 +       get_nx_info(nxi);
19644 +       claim_nx_info(nxi, NULL);
19645 +}
19646 +
19647 +void nx_clear_persistent(struct nx_info *nxi)
19648 +{
19649 +       vxdprintk(VXD_CBIT(nid, 6),
19650 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
19651 +
19652 +       release_nx_info(nxi, NULL);
19653 +       put_nx_info(nxi);
19654 +}
19655 +
19656 +void nx_update_persistent(struct nx_info *nxi)
19657 +{
19658 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
19659 +               nx_set_persistent(nxi);
19660 +       else
19661 +               nx_clear_persistent(nxi);
19662 +}
19663 +
19664 +/* vserver syscall commands below here */
19665 +
19666 +/* taks nid and nx_info functions */
19667 +
19668 +#include <asm/uaccess.h>
19669 +
19670 +
19671 +int vc_task_nid(uint32_t id)
19672 +{
19673 +       vnid_t nid;
19674 +
19675 +       if (id) {
19676 +               struct task_struct *tsk;
19677 +
19678 +               rcu_read_lock();
19679 +               tsk = find_task_by_real_pid(id);
19680 +               nid = (tsk) ? tsk->nid : -ESRCH;
19681 +               rcu_read_unlock();
19682 +       } else
19683 +               nid = nx_current_nid();
19684 +       return nid;
19685 +}
19686 +
19687 +
19688 +int vc_nx_info(struct nx_info *nxi, void __user *data)
19689 +{
19690 +       struct vcmd_nx_info_v0 vc_data;
19691 +
19692 +       vc_data.nid = nxi->nx_id;
19693 +
19694 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19695 +               return -EFAULT;
19696 +       return 0;
19697 +}
19698 +
19699 +
19700 +/* network functions */
19701 +
19702 +int vc_net_create(uint32_t nid, void __user *data)
19703 +{
19704 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
19705 +       struct nx_info *new_nxi;
19706 +       int ret;
19707 +
19708 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19709 +               return -EFAULT;
19710 +
19711 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
19712 +               return -EINVAL;
19713 +
19714 +       new_nxi = __create_nx_info(nid);
19715 +       if (IS_ERR(new_nxi))
19716 +               return PTR_ERR(new_nxi);
19717 +
19718 +       /* initial flags */
19719 +       new_nxi->nx_flags = vc_data.flagword;
19720 +
19721 +       ret = -ENOEXEC;
19722 +       if (vs_net_change(new_nxi, VSC_NETUP))
19723 +               goto out;
19724 +
19725 +       ret = nx_migrate_task(current, new_nxi);
19726 +       if (ret)
19727 +               goto out;
19728 +
19729 +       /* return context id on success */
19730 +       ret = new_nxi->nx_id;
19731 +
19732 +       /* get a reference for persistent contexts */
19733 +       if ((vc_data.flagword & NXF_PERSISTENT))
19734 +               nx_set_persistent(new_nxi);
19735 +out:
19736 +       release_nx_info(new_nxi, NULL);
19737 +       put_nx_info(new_nxi);
19738 +       return ret;
19739 +}
19740 +
19741 +
19742 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
19743 +{
19744 +       return nx_migrate_task(current, nxi);
19745 +}
19746 +
19747 +
19748 +static inline
19749 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
19750 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
19751 +       struct nx_addr_v4 **prev)
19752 +{
19753 +       struct nx_addr_v4 *nxa = &nxi->v4;
19754 +
19755 +       for (; nxa; nxa = nxa->next) {
19756 +               if ((nxa->ip[0].s_addr == ip) &&
19757 +                   (nxa->ip[1].s_addr == ip2) &&
19758 +                   (nxa->mask.s_addr == mask) &&
19759 +                   (nxa->type == type) &&
19760 +                   (nxa->flags == flags))
19761 +                   return nxa;
19762 +
19763 +               /* save previous entry */
19764 +               if (prev)
19765 +                       *prev = nxa;
19766 +       }
19767 +       return NULL;
19768 +}
19769 +
19770 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19771 +       uint16_t type, uint16_t flags)
19772 +{
19773 +       struct nx_addr_v4 *nxa = NULL;
19774 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
19775 +       unsigned long irqflags;
19776 +       int ret = -EEXIST;
19777 +
19778 +       if (IS_ERR(new))
19779 +               return PTR_ERR(new);
19780 +
19781 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19782 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
19783 +               goto out_unlock;
19784 +
19785 +       if (NX_IPV4(nxi)) {
19786 +               nxa->next = new;
19787 +               nxa = new;
19788 +               new = NULL;
19789 +
19790 +               /* remove single ip for ip list */
19791 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
19792 +       }
19793 +
19794 +       nxa->ip[0].s_addr = ip;
19795 +       nxa->ip[1].s_addr = ip2;
19796 +       nxa->mask.s_addr = mask;
19797 +       nxa->type = type;
19798 +       nxa->flags = flags;
19799 +       ret = 0;
19800 +out_unlock:
19801 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19802 +       if (new)
19803 +               __dealloc_nx_addr_v4(new);
19804 +       return ret;
19805 +}
19806 +
19807 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19808 +       uint16_t type, uint16_t flags)
19809 +{
19810 +       struct nx_addr_v4 *nxa = NULL;
19811 +       struct nx_addr_v4 *old = NULL;
19812 +       unsigned long irqflags;
19813 +       int ret = 0;
19814 +
19815 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
19816 +       switch (type) {
19817 +       case NXA_TYPE_ADDR:
19818 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
19819 +               if (old) {
19820 +                       if (nxa) {
19821 +                               nxa->next = old->next;
19822 +                               old->next = NULL;
19823 +                       } else {
19824 +                               if (old->next) {
19825 +                                       nxa = old;
19826 +                                       old = old->next;
19827 +                                       *nxa = *old;
19828 +                                       old->next = NULL;
19829 +                               } else {
19830 +                                       memset(old, 0, sizeof(*old));
19831 +                                       old = NULL;
19832 +                               }
19833 +                       }
19834 +               } else
19835 +                       ret = -ESRCH;
19836 +               break;
19837 +
19838 +       case NXA_TYPE_ANY:
19839 +               nxa = &nxi->v4;
19840 +               old = nxa->next;
19841 +               memset(nxa, 0, sizeof(*nxa));
19842 +               break;
19843 +
19844 +       default:
19845 +               ret = -EINVAL;
19846 +       }
19847 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19848 +       __dealloc_nx_addr_v4_all(old);
19849 +       return ret;
19850 +}
19851 +
19852 +
19853 +int vc_net_add(struct nx_info *nxi, void __user *data)
19854 +{
19855 +       struct vcmd_net_addr_v0 vc_data;
19856 +       int index, ret = 0;
19857 +
19858 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19859 +               return -EFAULT;
19860 +
19861 +       switch (vc_data.type) {
19862 +       case NXA_TYPE_IPV4:
19863 +               if ((vc_data.count < 1) || (vc_data.count > 4))
19864 +                       return -EINVAL;
19865 +
19866 +               index = 0;
19867 +               while (index < vc_data.count) {
19868 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
19869 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
19870 +                       if (ret)
19871 +                               return ret;
19872 +                       index++;
19873 +               }
19874 +               ret = index;
19875 +               break;
19876 +
19877 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
19878 +               nxi->v4_bcast = vc_data.ip[0];
19879 +               ret = 1;
19880 +               break;
19881 +
19882 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
19883 +               nxi->v4_lback = vc_data.ip[0];
19884 +               ret = 1;
19885 +               break;
19886 +
19887 +       default:
19888 +               ret = -EINVAL;
19889 +               break;
19890 +       }
19891 +       return ret;
19892 +}
19893 +
19894 +int vc_net_remove(struct nx_info *nxi, void __user *data)
19895 +{
19896 +       struct vcmd_net_addr_v0 vc_data;
19897 +
19898 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19899 +               return -EFAULT;
19900 +
19901 +       switch (vc_data.type) {
19902 +       case NXA_TYPE_ANY:
19903 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
19904 +       default:
19905 +               return -EINVAL;
19906 +       }
19907 +       return 0;
19908 +}
19909 +
19910 +
19911 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
19912 +{
19913 +       struct vcmd_net_addr_ipv4_v1 vc_data;
19914 +
19915 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19916 +               return -EFAULT;
19917 +
19918 +       switch (vc_data.type) {
19919 +       case NXA_TYPE_ADDR:
19920 +       case NXA_TYPE_MASK:
19921 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
19922 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19923 +
19924 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19925 +               nxi->v4_bcast = vc_data.ip;
19926 +               break;
19927 +
19928 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19929 +               nxi->v4_lback = vc_data.ip;
19930 +               break;
19931 +
19932 +       default:
19933 +               return -EINVAL;
19934 +       }
19935 +       return 0;
19936 +}
19937 +
19938 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
19939 +{
19940 +       struct vcmd_net_addr_ipv4_v2 vc_data;
19941 +
19942 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19943 +               return -EFAULT;
19944 +
19945 +       switch (vc_data.type) {
19946 +       case NXA_TYPE_ADDR:
19947 +       case NXA_TYPE_MASK:
19948 +       case NXA_TYPE_RANGE:
19949 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19950 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19951 +
19952 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19953 +               nxi->v4_bcast = vc_data.ip;
19954 +               break;
19955 +
19956 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19957 +               nxi->v4_lback = vc_data.ip;
19958 +               break;
19959 +
19960 +       default:
19961 +               return -EINVAL;
19962 +       }
19963 +       return 0;
19964 +}
19965 +
19966 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
19967 +{
19968 +       struct vcmd_net_addr_ipv4_v1 vc_data;
19969 +
19970 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19971 +               return -EFAULT;
19972 +
19973 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
19974 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19975 +}
19976 +
19977 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
19978 +{
19979 +       struct vcmd_net_addr_ipv4_v2 vc_data;
19980 +
19981 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19982 +               return -EFAULT;
19983 +
19984 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19985 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19986 +}
19987 +
19988 +#ifdef CONFIG_IPV6
19989 +
19990 +static inline
19991 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
19992 +       struct in6_addr *ip, struct in6_addr *mask,
19993 +       uint32_t prefix, uint16_t type, uint16_t flags,
19994 +       struct nx_addr_v6 **prev)
19995 +{
19996 +       struct nx_addr_v6 *nxa = &nxi->v6;
19997 +
19998 +       for (; nxa; nxa = nxa->next) {
19999 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
20000 +                   ipv6_addr_equal(&nxa->mask, mask) &&
20001 +                   (nxa->prefix == prefix) &&
20002 +                   (nxa->type == type) &&
20003 +                   (nxa->flags == flags))
20004 +                   return nxa;
20005 +
20006 +               /* save previous entry */
20007 +               if (prev)
20008 +                       *prev = nxa;
20009 +       }
20010 +       return NULL;
20011 +}
20012 +
20013 +
20014 +int do_add_v6_addr(struct nx_info *nxi,
20015 +       struct in6_addr *ip, struct in6_addr *mask,
20016 +       uint32_t prefix, uint16_t type, uint16_t flags)
20017 +{
20018 +       struct nx_addr_v6 *nxa = NULL;
20019 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20020 +       unsigned long irqflags;
20021 +       int ret = -EEXIST;
20022 +
20023 +       if (IS_ERR(new))
20024 +               return PTR_ERR(new);
20025 +
20026 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20027 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20028 +               goto out_unlock;
20029 +
20030 +       if (NX_IPV6(nxi)) {
20031 +               nxa->next = new;
20032 +               nxa = new;
20033 +               new = NULL;
20034 +       }
20035 +
20036 +       nxa->ip = *ip;
20037 +       nxa->mask = *mask;
20038 +       nxa->prefix = prefix;
20039 +       nxa->type = type;
20040 +       nxa->flags = flags;
20041 +       ret = 0;
20042 +out_unlock:
20043 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20044 +       if (new)
20045 +               __dealloc_nx_addr_v6(new);
20046 +       return ret;
20047 +}
20048 +
20049 +int do_remove_v6_addr(struct nx_info *nxi,
20050 +       struct in6_addr *ip, struct in6_addr *mask,
20051 +       uint32_t prefix, uint16_t type, uint16_t flags)
20052 +{
20053 +       struct nx_addr_v6 *nxa = NULL;
20054 +       struct nx_addr_v6 *old = NULL;
20055 +       unsigned long irqflags;
20056 +       int ret = 0;
20057 +
20058 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20059 +       switch (type) {
20060 +       case NXA_TYPE_ADDR:
20061 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20062 +               if (old) {
20063 +                       if (nxa) {
20064 +                               nxa->next = old->next;
20065 +                               old->next = NULL;
20066 +                       } else {
20067 +                               if (old->next) {
20068 +                                       nxa = old;
20069 +                                       old = old->next;
20070 +                                       *nxa = *old;
20071 +                                       old->next = NULL;
20072 +                               } else {
20073 +                                       memset(old, 0, sizeof(*old));
20074 +                                       old = NULL;
20075 +                               }
20076 +                       }
20077 +               } else
20078 +                       ret = -ESRCH;
20079 +               break;
20080 +
20081 +       case NXA_TYPE_ANY:
20082 +               nxa = &nxi->v6;
20083 +               old = nxa->next;
20084 +               memset(nxa, 0, sizeof(*nxa));
20085 +               break;
20086 +
20087 +       default:
20088 +               ret = -EINVAL;
20089 +       }
20090 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20091 +       __dealloc_nx_addr_v6_all(old);
20092 +       return ret;
20093 +}
20094 +
20095 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20096 +{
20097 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20098 +
20099 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20100 +               return -EFAULT;
20101 +
20102 +       switch (vc_data.type) {
20103 +       case NXA_TYPE_ADDR:
20104 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20105 +               /* fallthrough */
20106 +       case NXA_TYPE_MASK:
20107 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20108 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20109 +       default:
20110 +               return -EINVAL;
20111 +       }
20112 +       return 0;
20113 +}
20114 +
20115 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20116 +{
20117 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20118 +
20119 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20120 +               return -EFAULT;
20121 +
20122 +       switch (vc_data.type) {
20123 +       case NXA_TYPE_ADDR:
20124 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20125 +               /* fallthrough */
20126 +       case NXA_TYPE_MASK:
20127 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20128 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20129 +       case NXA_TYPE_ANY:
20130 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20131 +       default:
20132 +               return -EINVAL;
20133 +       }
20134 +       return 0;
20135 +}
20136 +
20137 +#endif /* CONFIG_IPV6 */
20138 +
20139 +
20140 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20141 +{
20142 +       struct vcmd_net_flags_v0 vc_data;
20143 +
20144 +       vc_data.flagword = nxi->nx_flags;
20145 +
20146 +       /* special STATE flag handling */
20147 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20148 +
20149 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20150 +               return -EFAULT;
20151 +       return 0;
20152 +}
20153 +
20154 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20155 +{
20156 +       struct vcmd_net_flags_v0 vc_data;
20157 +       uint64_t mask, trigger;
20158 +
20159 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20160 +               return -EFAULT;
20161 +
20162 +       /* special STATE flag handling */
20163 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20164 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20165 +
20166 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20167 +               vc_data.flagword, mask);
20168 +       if (trigger & NXF_PERSISTENT)
20169 +               nx_update_persistent(nxi);
20170 +
20171 +       return 0;
20172 +}
20173 +
20174 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20175 +{
20176 +       struct vcmd_net_caps_v0 vc_data;
20177 +
20178 +       vc_data.ncaps = nxi->nx_ncaps;
20179 +       vc_data.cmask = ~0ULL;
20180 +
20181 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20182 +               return -EFAULT;
20183 +       return 0;
20184 +}
20185 +
20186 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20187 +{
20188 +       struct vcmd_net_caps_v0 vc_data;
20189 +
20190 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20191 +               return -EFAULT;
20192 +
20193 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20194 +               vc_data.ncaps, vc_data.cmask);
20195 +       return 0;
20196 +}
20197 +
20198 +
20199 +#include <linux/module.h>
20200 +
20201 +module_init(init_network);
20202 +
20203 +EXPORT_SYMBOL_GPL(free_nx_info);
20204 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20205 +
20206 diff -NurpP --minimal linux-3.13.10/kernel/vserver/proc.c linux-3.13.10-vs2.3.6.11/kernel/vserver/proc.c
20207 --- linux-3.13.10/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
20208 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/proc.c      2014-02-01 01:21:49.000000000 +0000
20209 @@ -0,0 +1,1097 @@
20210 +/*
20211 + *  linux/kernel/vserver/proc.c
20212 + *
20213 + *  Virtual Context Support
20214 + *
20215 + *  Copyright (C) 2003-2011  Herbert Pötzl
20216 + *
20217 + *  V0.01  basic structure
20218 + *  V0.02  adaptation vs1.3.0
20219 + *  V0.03  proc permissions
20220 + *  V0.04  locking/generic
20221 + *  V0.05  next generation procfs
20222 + *  V0.06  inode validation
20223 + *  V0.07  generic rewrite vid
20224 + *  V0.08  remove inode type
20225 + *  V0.09  added u/wmask info
20226 + *
20227 + */
20228 +
20229 +#include <linux/proc_fs.h>
20230 +#include <linux/fs_struct.h>
20231 +#include <linux/mount.h>
20232 +#include <linux/namei.h>
20233 +#include <asm/unistd.h>
20234 +
20235 +#include <linux/vs_context.h>
20236 +#include <linux/vs_network.h>
20237 +#include <linux/vs_cvirt.h>
20238 +
20239 +#include <linux/in.h>
20240 +#include <linux/inetdevice.h>
20241 +#include <linux/vs_inet.h>
20242 +#include <linux/vs_inet6.h>
20243 +
20244 +#include <linux/vserver/global.h>
20245 +
20246 +#include "cvirt_proc.h"
20247 +#include "cacct_proc.h"
20248 +#include "limit_proc.h"
20249 +#include "sched_proc.h"
20250 +#include "vci_config.h"
20251 +
20252 +#include <../../fs/proc/internal.h>
20253 +
20254 +
20255 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20256 +{
20257 +       unsigned __capi;
20258 +
20259 +       CAP_FOR_EACH_U32(__capi) {
20260 +               buffer += sprintf(buffer, "%08x",
20261 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20262 +       }
20263 +       return buffer;
20264 +}
20265 +
20266 +
20267 +static struct proc_dir_entry *proc_virtual;
20268 +
20269 +static struct proc_dir_entry *proc_virtnet;
20270 +
20271 +
20272 +/* first the actual feeds */
20273 +
20274 +
20275 +static int proc_vci(char *buffer)
20276 +{
20277 +       return sprintf(buffer,
20278 +               "VCIVersion:\t%04x:%04x\n"
20279 +               "VCISyscall:\t%d\n"
20280 +               "VCIKernel:\t%08x\n",
20281 +               VCI_VERSION >> 16,
20282 +               VCI_VERSION & 0xFFFF,
20283 +               __NR_vserver,
20284 +               vci_kernel_config());
20285 +}
20286 +
20287 +static int proc_virtual_info(char *buffer)
20288 +{
20289 +       return proc_vci(buffer);
20290 +}
20291 +
20292 +static int proc_virtual_status(char *buffer)
20293 +{
20294 +       return sprintf(buffer,
20295 +               "#CTotal:\t%d\n"
20296 +               "#CActive:\t%d\n"
20297 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20298 +               "#InitTask:\t%d\t%d %d\n",
20299 +               atomic_read(&vx_global_ctotal),
20300 +               atomic_read(&vx_global_cactive),
20301 +               atomic_read(&vs_global_nsproxy),
20302 +               atomic_read(&vs_global_fs),
20303 +               atomic_read(&vs_global_mnt_ns),
20304 +               atomic_read(&vs_global_uts_ns),
20305 +               atomic_read(&nr_ipc_ns),
20306 +               atomic_read(&vs_global_user_ns),
20307 +               atomic_read(&vs_global_pid_ns),
20308 +               atomic_read(&init_task.usage),
20309 +               atomic_read(&init_task.nsproxy->count),
20310 +               init_task.fs->users);
20311 +}
20312 +
20313 +
20314 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20315 +{
20316 +       int length;
20317 +
20318 +       length = sprintf(buffer,
20319 +               "ID:\t%d\n"
20320 +               "Info:\t%p\n"
20321 +               "Init:\t%d\n"
20322 +               "OOM:\t%lld\n",
20323 +               vxi->vx_id,
20324 +               vxi,
20325 +               vxi->vx_initpid,
20326 +               vxi->vx_badness_bias);
20327 +       return length;
20328 +}
20329 +
20330 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
20331 +{
20332 +       char *orig = buffer;
20333 +
20334 +       buffer += sprintf(buffer,
20335 +               "UseCnt:\t%d\n"
20336 +               "Tasks:\t%d\n"
20337 +               "Flags:\t%016llx\n",
20338 +               atomic_read(&vxi->vx_usecnt),
20339 +               atomic_read(&vxi->vx_tasks),
20340 +               (unsigned long long)vxi->vx_flags);
20341 +
20342 +       buffer += sprintf(buffer, "BCaps:\t");
20343 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
20344 +       buffer += sprintf(buffer, "\n");
20345 +
20346 +       buffer += sprintf(buffer,
20347 +               "CCaps:\t%016llx\n"
20348 +               "Umask:\t%16llx\n"
20349 +               "Wmask:\t%16llx\n"
20350 +               "Spaces:\t%08lx %08lx\n",
20351 +               (unsigned long long)vxi->vx_ccaps,
20352 +               (unsigned long long)vxi->vx_umask,
20353 +               (unsigned long long)vxi->vx_wmask,
20354 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
20355 +       return buffer - orig;
20356 +}
20357 +
20358 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
20359 +{
20360 +       return vx_info_proc_limit(&vxi->limit, buffer);
20361 +}
20362 +
20363 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
20364 +{
20365 +       int cpu, length;
20366 +
20367 +       length = vx_info_proc_sched(&vxi->sched, buffer);
20368 +       for_each_online_cpu(cpu) {
20369 +               length += vx_info_proc_sched_pc(
20370 +                       &vx_per_cpu(vxi, sched_pc, cpu),
20371 +                       buffer + length, cpu);
20372 +       }
20373 +       return length;
20374 +}
20375 +
20376 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
20377 +{
20378 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
20379 +}
20380 +
20381 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
20382 +{
20383 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
20384 +}
20385 +
20386 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
20387 +{
20388 +       int cpu, length;
20389 +
20390 +       vx_update_load(vxi);
20391 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
20392 +       for_each_online_cpu(cpu) {
20393 +               length += vx_info_proc_cvirt_pc(
20394 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
20395 +                       buffer + length, cpu);
20396 +       }
20397 +       return length;
20398 +}
20399 +
20400 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
20401 +{
20402 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
20403 +}
20404 +
20405 +
20406 +static int proc_virtnet_info(char *buffer)
20407 +{
20408 +       return proc_vci(buffer);
20409 +}
20410 +
20411 +static int proc_virtnet_status(char *buffer)
20412 +{
20413 +       return sprintf(buffer,
20414 +               "#CTotal:\t%d\n"
20415 +               "#CActive:\t%d\n",
20416 +               atomic_read(&nx_global_ctotal),
20417 +               atomic_read(&nx_global_cactive));
20418 +}
20419 +
20420 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
20421 +{
20422 +       struct nx_addr_v4 *v4a;
20423 +#ifdef CONFIG_IPV6
20424 +       struct nx_addr_v6 *v6a;
20425 +#endif
20426 +       int length, i;
20427 +
20428 +       length = sprintf(buffer,
20429 +               "ID:\t%d\n"
20430 +               "Info:\t%p\n"
20431 +               "Bcast:\t" NIPQUAD_FMT "\n"
20432 +               "Lback:\t" NIPQUAD_FMT "\n",
20433 +               nxi->nx_id,
20434 +               nxi,
20435 +               NIPQUAD(nxi->v4_bcast.s_addr),
20436 +               NIPQUAD(nxi->v4_lback.s_addr));
20437 +
20438 +       if (!NX_IPV4(nxi))
20439 +               goto skip_v4;
20440 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20441 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
20442 +                       i, NXAV4(v4a));
20443 +skip_v4:
20444 +#ifdef CONFIG_IPV6
20445 +       if (!NX_IPV6(nxi))
20446 +               goto skip_v6;
20447 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20448 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
20449 +                       i, NXAV6(v6a));
20450 +skip_v6:
20451 +#endif
20452 +       return length;
20453 +}
20454 +
20455 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
20456 +{
20457 +       int length;
20458 +
20459 +       length = sprintf(buffer,
20460 +               "UseCnt:\t%d\n"
20461 +               "Tasks:\t%d\n"
20462 +               "Flags:\t%016llx\n"
20463 +               "NCaps:\t%016llx\n",
20464 +               atomic_read(&nxi->nx_usecnt),
20465 +               atomic_read(&nxi->nx_tasks),
20466 +               (unsigned long long)nxi->nx_flags,
20467 +               (unsigned long long)nxi->nx_ncaps);
20468 +       return length;
20469 +}
20470 +
20471 +
20472 +
20473 +/* here the inode helpers */
20474 +
20475 +struct vs_entry {
20476 +       int len;
20477 +       char *name;
20478 +       mode_t mode;
20479 +       struct inode_operations *iop;
20480 +       struct file_operations *fop;
20481 +       union proc_op op;
20482 +};
20483 +
20484 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
20485 +{
20486 +       struct inode *inode = new_inode(sb);
20487 +
20488 +       if (!inode)
20489 +               goto out;
20490 +
20491 +       inode->i_mode = p->mode;
20492 +       if (p->iop)
20493 +               inode->i_op = p->iop;
20494 +       if (p->fop)
20495 +               inode->i_fop = p->fop;
20496 +
20497 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
20498 +       inode->i_flags |= S_IMMUTABLE;
20499 +
20500 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
20501 +
20502 +       i_uid_write(inode, 0);
20503 +       i_gid_write(inode, 0);
20504 +       i_tag_write(inode, 0);
20505 +out:
20506 +       return inode;
20507 +}
20508 +
20509 +static struct dentry *vs_proc_instantiate(struct inode *dir,
20510 +       struct dentry *dentry, int id, void *ptr)
20511 +{
20512 +       struct vs_entry *p = ptr;
20513 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
20514 +       struct dentry *error = ERR_PTR(-EINVAL);
20515 +
20516 +       if (!inode)
20517 +               goto out;
20518 +
20519 +       PROC_I(inode)->op = p->op;
20520 +       PROC_I(inode)->fd = id;
20521 +       d_add(dentry, inode);
20522 +       error = NULL;
20523 +out:
20524 +       return error;
20525 +}
20526 +
20527 +/* Lookups */
20528 +
20529 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
20530 +
20531 +
20532 +/*
20533 + * Fill a directory entry.
20534 + *
20535 + * If possible create the dcache entry and derive our inode number and
20536 + * file type from dcache entry.
20537 + *
20538 + * Since all of the proc inode numbers are dynamically generated, the inode
20539 + * numbers do not exist until the inode is cache.  This means creating the
20540 + * the dcache entry in iterate is necessary to keep the inode numbers
20541 + * reported by iterate in sync with the inode numbers reported
20542 + * by stat.
20543 + */
20544 +static int vx_proc_fill_cache(struct file *filp, struct dir_context *ctx,
20545 +       char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
20546 +{
20547 +       struct dentry *child, *dir = filp->f_dentry;
20548 +       struct inode *inode;
20549 +       struct qstr qname;
20550 +       ino_t ino = 0;
20551 +       unsigned type = DT_UNKNOWN;
20552 +
20553 +       qname.name = name;
20554 +       qname.len  = len;
20555 +       qname.hash = full_name_hash(name, len);
20556 +
20557 +       child = d_lookup(dir, &qname);
20558 +       if (!child) {
20559 +               struct dentry *new;
20560 +               new = d_alloc(dir, &qname);
20561 +               if (new) {
20562 +                       child = instantiate(dir->d_inode, new, id, ptr);
20563 +                       if (child)
20564 +                               dput(new);
20565 +                       else
20566 +                               child = new;
20567 +               }
20568 +       }
20569 +       if (!child || IS_ERR(child) || !child->d_inode)
20570 +               goto end_instantiate;
20571 +       inode = child->d_inode;
20572 +       if (inode) {
20573 +               ino = inode->i_ino;
20574 +               type = inode->i_mode >> 12;
20575 +       }
20576 +       dput(child);
20577 +end_instantiate:
20578 +       if (!ino)
20579 +               ino = 1;
20580 +       return !dir_emit(ctx, name, len, ino, type);
20581 +}
20582 +
20583 +
20584 +
20585 +/* get and revalidate vx_info/xid */
20586 +
20587 +static inline
20588 +struct vx_info *get_proc_vx_info(struct inode *inode)
20589 +{
20590 +       return lookup_vx_info(PROC_I(inode)->fd);
20591 +}
20592 +
20593 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
20594 +{
20595 +       struct inode *inode = dentry->d_inode;
20596 +       vxid_t xid = PROC_I(inode)->fd;
20597 +
20598 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20599 +               return -ECHILD;
20600 +
20601 +       if (!xid || xid_is_hashed(xid))
20602 +               return 1;
20603 +       d_drop(dentry);
20604 +       return 0;
20605 +}
20606 +
20607 +
20608 +/* get and revalidate nx_info/nid */
20609 +
20610 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
20611 +{
20612 +       struct inode *inode = dentry->d_inode;
20613 +       vnid_t nid = PROC_I(inode)->fd;
20614 +
20615 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20616 +               return -ECHILD;
20617 +
20618 +       if (!nid || nid_is_hashed(nid))
20619 +               return 1;
20620 +       d_drop(dentry);
20621 +       return 0;
20622 +}
20623 +
20624 +
20625 +
20626 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
20627 +
20628 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
20629 +                         size_t count, loff_t *ppos)
20630 +{
20631 +       struct inode *inode = file->f_dentry->d_inode;
20632 +       unsigned long page;
20633 +       ssize_t length = 0;
20634 +
20635 +       if (count > PROC_BLOCK_SIZE)
20636 +               count = PROC_BLOCK_SIZE;
20637 +
20638 +       /* fade that out as soon as stable */
20639 +       WARN_ON(PROC_I(inode)->fd);
20640 +
20641 +       if (!(page = __get_free_page(GFP_KERNEL)))
20642 +               return -ENOMEM;
20643 +
20644 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
20645 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
20646 +
20647 +       if (length >= 0)
20648 +               length = simple_read_from_buffer(buf, count, ppos,
20649 +                       (char *)page, length);
20650 +
20651 +       free_page(page);
20652 +       return length;
20653 +}
20654 +
20655 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
20656 +                         size_t count, loff_t *ppos)
20657 +{
20658 +       struct inode *inode = file->f_dentry->d_inode;
20659 +       struct vx_info *vxi = NULL;
20660 +       vxid_t xid = PROC_I(inode)->fd;
20661 +       unsigned long page;
20662 +       ssize_t length = 0;
20663 +
20664 +       if (count > PROC_BLOCK_SIZE)
20665 +               count = PROC_BLOCK_SIZE;
20666 +
20667 +       /* fade that out as soon as stable */
20668 +       WARN_ON(!xid);
20669 +       vxi = lookup_vx_info(xid);
20670 +       if (!vxi)
20671 +               goto out;
20672 +
20673 +       length = -ENOMEM;
20674 +       if (!(page = __get_free_page(GFP_KERNEL)))
20675 +               goto out_put;
20676 +
20677 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
20678 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
20679 +
20680 +       if (length >= 0)
20681 +               length = simple_read_from_buffer(buf, count, ppos,
20682 +                       (char *)page, length);
20683 +
20684 +       free_page(page);
20685 +out_put:
20686 +       put_vx_info(vxi);
20687 +out:
20688 +       return length;
20689 +}
20690 +
20691 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
20692 +                         size_t count, loff_t *ppos)
20693 +{
20694 +       struct inode *inode = file->f_dentry->d_inode;
20695 +       struct nx_info *nxi = NULL;
20696 +       vnid_t nid = PROC_I(inode)->fd;
20697 +       unsigned long page;
20698 +       ssize_t length = 0;
20699 +
20700 +       if (count > PROC_BLOCK_SIZE)
20701 +               count = PROC_BLOCK_SIZE;
20702 +
20703 +       /* fade that out as soon as stable */
20704 +       WARN_ON(!nid);
20705 +       nxi = lookup_nx_info(nid);
20706 +       if (!nxi)
20707 +               goto out;
20708 +
20709 +       length = -ENOMEM;
20710 +       if (!(page = __get_free_page(GFP_KERNEL)))
20711 +               goto out_put;
20712 +
20713 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
20714 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
20715 +
20716 +       if (length >= 0)
20717 +               length = simple_read_from_buffer(buf, count, ppos,
20718 +                       (char *)page, length);
20719 +
20720 +       free_page(page);
20721 +out_put:
20722 +       put_nx_info(nxi);
20723 +out:
20724 +       return length;
20725 +}
20726 +
20727 +
20728 +
20729 +/* here comes the lower level */
20730 +
20731 +
20732 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
20733 +       .len  = sizeof(NAME) - 1,       \
20734 +       .name = (NAME),                 \
20735 +       .mode = MODE,                   \
20736 +       .iop  = IOP,                    \
20737 +       .fop  = FOP,                    \
20738 +       .op   = OP,                     \
20739 +}
20740 +
20741 +
20742 +#define DIR(NAME, MODE, OTYPE)                         \
20743 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
20744 +               &proc_ ## OTYPE ## _inode_operations,   \
20745 +               &proc_ ## OTYPE ## _file_operations, { } )
20746 +
20747 +#define INF(NAME, MODE, OTYPE)                         \
20748 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20749 +               &proc_vs_info_file_operations,          \
20750 +               { .proc_vs_read = &proc_##OTYPE } )
20751 +
20752 +#define VINF(NAME, MODE, OTYPE)                                \
20753 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20754 +               &proc_vx_info_file_operations,          \
20755 +               { .proc_vxi_read = &proc_##OTYPE } )
20756 +
20757 +#define NINF(NAME, MODE, OTYPE)                                \
20758 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
20759 +               &proc_nx_info_file_operations,          \
20760 +               { .proc_nxi_read = &proc_##OTYPE } )
20761 +
20762 +
20763 +static struct file_operations proc_vs_info_file_operations = {
20764 +       .read =         proc_vs_info_read,
20765 +};
20766 +
20767 +static struct file_operations proc_vx_info_file_operations = {
20768 +       .read =         proc_vx_info_read,
20769 +};
20770 +
20771 +static struct dentry_operations proc_xid_dentry_operations = {
20772 +       .d_revalidate = proc_xid_revalidate,
20773 +};
20774 +
20775 +static struct vs_entry vx_base_stuff[] = {
20776 +       VINF("info",    S_IRUGO, vxi_info),
20777 +       VINF("status",  S_IRUGO, vxi_status),
20778 +       VINF("limit",   S_IRUGO, vxi_limit),
20779 +       VINF("sched",   S_IRUGO, vxi_sched),
20780 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
20781 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
20782 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
20783 +       VINF("cacct",   S_IRUGO, vxi_cacct),
20784 +       {}
20785 +};
20786 +
20787 +
20788 +
20789 +
20790 +static struct dentry *proc_xid_instantiate(struct inode *dir,
20791 +       struct dentry *dentry, int id, void *ptr)
20792 +{
20793 +       dentry->d_op = &proc_xid_dentry_operations;
20794 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20795 +}
20796 +
20797 +static struct dentry *proc_xid_lookup(struct inode *dir,
20798 +       struct dentry *dentry, unsigned int flags)
20799 +{
20800 +       struct vs_entry *p = vx_base_stuff;
20801 +       struct dentry *error = ERR_PTR(-ENOENT);
20802 +
20803 +       for (; p->name; p++) {
20804 +               if (p->len != dentry->d_name.len)
20805 +                       continue;
20806 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20807 +                       break;
20808 +       }
20809 +       if (!p->name)
20810 +               goto out;
20811 +
20812 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20813 +out:
20814 +       return error;
20815 +}
20816 +
20817 +static int proc_xid_iterate(struct file *filp, struct dir_context *ctx)
20818 +{
20819 +       struct dentry *dentry = filp->f_dentry;
20820 +       struct inode *inode = dentry->d_inode;
20821 +       struct vs_entry *p = vx_base_stuff;
20822 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
20823 +       int index;
20824 +       u64 ino;
20825 +
20826 +       switch (ctx->pos) {
20827 +       case 0:
20828 +               ino = inode->i_ino;
20829 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20830 +                       goto out;
20831 +               ctx->pos++;
20832 +               /* fall through */
20833 +       case 1:
20834 +               ino = parent_ino(dentry);
20835 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20836 +                       goto out;
20837 +               ctx->pos++;
20838 +               /* fall through */
20839 +       default:
20840 +               index = ctx->pos - 2;
20841 +               if (index >= size)
20842 +                       goto out;
20843 +               for (p += index; p->name; p++) {
20844 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20845 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20846 +                               goto out;
20847 +                       ctx->pos++;
20848 +               }
20849 +       }
20850 +out:
20851 +       return 1;
20852 +}
20853 +
20854 +
20855 +
20856 +static struct file_operations proc_nx_info_file_operations = {
20857 +       .read =         proc_nx_info_read,
20858 +};
20859 +
20860 +static struct dentry_operations proc_nid_dentry_operations = {
20861 +       .d_revalidate = proc_nid_revalidate,
20862 +};
20863 +
20864 +static struct vs_entry nx_base_stuff[] = {
20865 +       NINF("info",    S_IRUGO, nxi_info),
20866 +       NINF("status",  S_IRUGO, nxi_status),
20867 +       {}
20868 +};
20869 +
20870 +
20871 +static struct dentry *proc_nid_instantiate(struct inode *dir,
20872 +       struct dentry *dentry, int id, void *ptr)
20873 +{
20874 +       dentry->d_op = &proc_nid_dentry_operations;
20875 +       return vs_proc_instantiate(dir, dentry, id, ptr);
20876 +}
20877 +
20878 +static struct dentry *proc_nid_lookup(struct inode *dir,
20879 +       struct dentry *dentry, unsigned int flags)
20880 +{
20881 +       struct vs_entry *p = nx_base_stuff;
20882 +       struct dentry *error = ERR_PTR(-ENOENT);
20883 +
20884 +       for (; p->name; p++) {
20885 +               if (p->len != dentry->d_name.len)
20886 +                       continue;
20887 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20888 +                       break;
20889 +       }
20890 +       if (!p->name)
20891 +               goto out;
20892 +
20893 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20894 +out:
20895 +       return error;
20896 +}
20897 +
20898 +static int proc_nid_iterate(struct file *filp, struct dir_context *ctx)
20899 +{
20900 +       struct dentry *dentry = filp->f_dentry;
20901 +       struct inode *inode = dentry->d_inode;
20902 +       struct vs_entry *p = nx_base_stuff;
20903 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
20904 +       int index;
20905 +       u64 ino;
20906 +
20907 +       switch (ctx->pos) {
20908 +       case 0:
20909 +               ino = inode->i_ino;
20910 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20911 +                       goto out;
20912 +               ctx->pos++;
20913 +               /* fall through */
20914 +       case 1:
20915 +               ino = parent_ino(dentry);
20916 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20917 +                       goto out;
20918 +               ctx->pos++;
20919 +               /* fall through */
20920 +       default:
20921 +               index = ctx->pos - 2;
20922 +               if (index >= size)
20923 +                       goto out;
20924 +               for (p += index; p->name; p++) {
20925 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20926 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
20927 +                               goto out;
20928 +                       ctx->pos++;
20929 +               }
20930 +       }
20931 +out:
20932 +       return 1;
20933 +}
20934 +
20935 +
20936 +#define MAX_MULBY10    ((~0U - 9) / 10)
20937 +
20938 +static inline int atovid(const char *str, int len)
20939 +{
20940 +       int vid, c;
20941 +
20942 +       vid = 0;
20943 +       while (len-- > 0) {
20944 +               c = *str - '0';
20945 +               str++;
20946 +               if (c > 9)
20947 +                       return -1;
20948 +               if (vid >= MAX_MULBY10)
20949 +                       return -1;
20950 +               vid *= 10;
20951 +               vid += c;
20952 +               if (!vid)
20953 +                       return -1;
20954 +       }
20955 +       return vid;
20956 +}
20957 +
20958 +/* now the upper level (virtual) */
20959 +
20960 +
20961 +static struct file_operations proc_xid_file_operations = {
20962 +       .read =         generic_read_dir,
20963 +       .iterate =      proc_xid_iterate,
20964 +};
20965 +
20966 +static struct inode_operations proc_xid_inode_operations = {
20967 +       .lookup =       proc_xid_lookup,
20968 +};
20969 +
20970 +static struct vs_entry vx_virtual_stuff[] = {
20971 +       INF("info",     S_IRUGO, virtual_info),
20972 +       INF("status",   S_IRUGO, virtual_status),
20973 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
20974 +};
20975 +
20976 +
20977 +static struct dentry *proc_virtual_lookup(struct inode *dir,
20978 +       struct dentry *dentry, unsigned int flags)
20979 +{
20980 +       struct vs_entry *p = vx_virtual_stuff;
20981 +       struct dentry *error = ERR_PTR(-ENOENT);
20982 +       int id = 0;
20983 +
20984 +       for (; p->name; p++) {
20985 +               if (p->len != dentry->d_name.len)
20986 +                       continue;
20987 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
20988 +                       break;
20989 +       }
20990 +       if (p->name)
20991 +               goto instantiate;
20992 +
20993 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
20994 +       if ((id < 0) || !xid_is_hashed(id))
20995 +               goto out;
20996 +
20997 +instantiate:
20998 +       error = proc_xid_instantiate(dir, dentry, id, p);
20999 +out:
21000 +       return error;
21001 +}
21002 +
21003 +static struct file_operations proc_nid_file_operations = {
21004 +       .read =         generic_read_dir,
21005 +       .iterate =      proc_nid_iterate,
21006 +};
21007 +
21008 +static struct inode_operations proc_nid_inode_operations = {
21009 +       .lookup =       proc_nid_lookup,
21010 +};
21011 +
21012 +static struct vs_entry nx_virtnet_stuff[] = {
21013 +       INF("info",     S_IRUGO, virtnet_info),
21014 +       INF("status",   S_IRUGO, virtnet_status),
21015 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21016 +};
21017 +
21018 +
21019 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21020 +       struct dentry *dentry, unsigned int flags)
21021 +{
21022 +       struct vs_entry *p = nx_virtnet_stuff;
21023 +       struct dentry *error = ERR_PTR(-ENOENT);
21024 +       int id = 0;
21025 +
21026 +       for (; p->name; p++) {
21027 +               if (p->len != dentry->d_name.len)
21028 +                       continue;
21029 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21030 +                       break;
21031 +       }
21032 +       if (p->name)
21033 +               goto instantiate;
21034 +
21035 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21036 +       if ((id < 0) || !nid_is_hashed(id))
21037 +               goto out;
21038 +
21039 +instantiate:
21040 +       error = proc_nid_instantiate(dir, dentry, id, p);
21041 +out:
21042 +       return error;
21043 +}
21044 +
21045 +
21046 +#define PROC_MAXVIDS 32
21047 +
21048 +int proc_virtual_iterate(struct file *filp, struct dir_context *ctx)
21049 +{
21050 +       struct dentry *dentry = filp->f_dentry;
21051 +       struct inode *inode = dentry->d_inode;
21052 +       struct vs_entry *p = vx_virtual_stuff;
21053 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21054 +       int index;
21055 +       unsigned int xid_array[PROC_MAXVIDS];
21056 +       char buf[PROC_NUMBUF];
21057 +       unsigned int nr_xids, i;
21058 +       u64 ino;
21059 +
21060 +       switch (ctx->pos) {
21061 +       case 0:
21062 +               ino = inode->i_ino;
21063 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21064 +                       goto out;
21065 +               ctx->pos++;
21066 +               /* fall through */
21067 +       case 1:
21068 +               ino = parent_ino(dentry);
21069 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21070 +                       goto out;
21071 +               ctx->pos++;
21072 +               /* fall through */
21073 +       default:
21074 +               index = ctx->pos - 2;
21075 +               if (index >= size)
21076 +                       goto entries;
21077 +               for (p += index; p->name; p++) {
21078 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21079 +                               vs_proc_instantiate, 0, p))
21080 +                               goto out;
21081 +                       ctx->pos++;
21082 +               }
21083 +       entries:
21084 +               index = ctx->pos - size;
21085 +               p = &vx_virtual_stuff[size - 1];
21086 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21087 +               for (i = 0; i < nr_xids; i++) {
21088 +                       int n, xid = xid_array[i];
21089 +                       unsigned int j = PROC_NUMBUF;
21090 +
21091 +                       n = xid;
21092 +                       do
21093 +                               buf[--j] = '0' + (n % 10);
21094 +                       while (n /= 10);
21095 +
21096 +                       if (vx_proc_fill_cache(filp, ctx,
21097 +                               buf + j, PROC_NUMBUF - j,
21098 +                               vs_proc_instantiate, xid, p))
21099 +                               goto out;
21100 +                       ctx->pos++;
21101 +               }
21102 +       }
21103 +out:
21104 +       return 0;
21105 +}
21106 +
21107 +static int proc_virtual_getattr(struct vfsmount *mnt,
21108 +       struct dentry *dentry, struct kstat *stat)
21109 +{
21110 +       struct inode *inode = dentry->d_inode;
21111 +
21112 +       generic_fillattr(inode, stat);
21113 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21114 +       return 0;
21115 +}
21116 +
21117 +static struct file_operations proc_virtual_dir_operations = {
21118 +       .read =         generic_read_dir,
21119 +       .iterate =      proc_virtual_iterate,
21120 +};
21121 +
21122 +static struct inode_operations proc_virtual_dir_inode_operations = {
21123 +       .getattr =      proc_virtual_getattr,
21124 +       .lookup =       proc_virtual_lookup,
21125 +};
21126 +
21127 +
21128 +
21129 +int proc_virtnet_iterate(struct file *filp, struct dir_context *ctx)
21130 +{
21131 +       struct dentry *dentry = filp->f_dentry;
21132 +       struct inode *inode = dentry->d_inode;
21133 +       struct vs_entry *p = nx_virtnet_stuff;
21134 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21135 +       int index;
21136 +       unsigned int nid_array[PROC_MAXVIDS];
21137 +       char buf[PROC_NUMBUF];
21138 +       unsigned int nr_nids, i;
21139 +       u64 ino;
21140 +
21141 +       switch (ctx->pos) {
21142 +       case 0:
21143 +               ino = inode->i_ino;
21144 +               if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21145 +                       goto out;
21146 +               ctx->pos++;
21147 +               /* fall through */
21148 +       case 1:
21149 +               ino = parent_ino(dentry);
21150 +               if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21151 +                       goto out;
21152 +               ctx->pos++;
21153 +               /* fall through */
21154 +       default:
21155 +               index = ctx->pos - 2;
21156 +               if (index >= size)
21157 +                       goto entries;
21158 +               for (p += index; p->name; p++) {
21159 +                       if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21160 +                               vs_proc_instantiate, 0, p))
21161 +                               goto out;
21162 +                       ctx->pos++;
21163 +               }
21164 +       entries:
21165 +               index = ctx->pos - size;
21166 +               p = &nx_virtnet_stuff[size - 1];
21167 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21168 +               for (i = 0; i < nr_nids; i++) {
21169 +                       int n, nid = nid_array[i];
21170 +                       unsigned int j = PROC_NUMBUF;
21171 +
21172 +                       n = nid;
21173 +                       do
21174 +                               buf[--j] = '0' + (n % 10);
21175 +                       while (n /= 10);
21176 +
21177 +                       if (vx_proc_fill_cache(filp, ctx,
21178 +                               buf + j, PROC_NUMBUF - j,
21179 +                               vs_proc_instantiate, nid, p))
21180 +                               goto out;
21181 +                       ctx->pos++;
21182 +               }
21183 +       }
21184 +out:
21185 +       return 0;
21186 +}
21187 +
21188 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21189 +       struct dentry *dentry, struct kstat *stat)
21190 +{
21191 +       struct inode *inode = dentry->d_inode;
21192 +
21193 +       generic_fillattr(inode, stat);
21194 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21195 +       return 0;
21196 +}
21197 +
21198 +static struct file_operations proc_virtnet_dir_operations = {
21199 +       .read =         generic_read_dir,
21200 +       .iterate =      proc_virtnet_iterate,
21201 +};
21202 +
21203 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21204 +       .getattr =      proc_virtnet_getattr,
21205 +       .lookup =       proc_virtnet_lookup,
21206 +};
21207 +
21208 +
21209 +
21210 +void proc_vx_init(void)
21211 +{
21212 +       struct proc_dir_entry *ent;
21213 +
21214 +       ent = proc_mkdir("virtual", 0);
21215 +       if (ent) {
21216 +               ent->proc_fops = &proc_virtual_dir_operations;
21217 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21218 +       }
21219 +       proc_virtual = ent;
21220 +
21221 +       ent = proc_mkdir("virtnet", 0);
21222 +       if (ent) {
21223 +               ent->proc_fops = &proc_virtnet_dir_operations;
21224 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21225 +       }
21226 +       proc_virtnet = ent;
21227 +}
21228 +
21229 +
21230 +
21231 +
21232 +/* per pid info */
21233 +
21234 +
21235 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21236 +{
21237 +       struct vx_info *vxi;
21238 +       char *orig = buffer;
21239 +
21240 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21241 +
21242 +       vxi = task_get_vx_info(p);
21243 +       if (!vxi)
21244 +               goto out;
21245 +
21246 +       buffer += sprintf(buffer, "BCaps:\t");
21247 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21248 +       buffer += sprintf(buffer, "\n");
21249 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21250 +               (unsigned long long)vxi->vx_ccaps);
21251 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21252 +               (unsigned long long)vxi->vx_flags);
21253 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21254 +
21255 +       put_vx_info(vxi);
21256 +out:
21257 +       return buffer - orig;
21258 +}
21259 +
21260 +
21261 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21262 +{
21263 +       struct nx_info *nxi;
21264 +       struct nx_addr_v4 *v4a;
21265 +#ifdef CONFIG_IPV6
21266 +       struct nx_addr_v6 *v6a;
21267 +#endif
21268 +       char *orig = buffer;
21269 +       int i;
21270 +
21271 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21272 +
21273 +       nxi = task_get_nx_info(p);
21274 +       if (!nxi)
21275 +               goto out;
21276 +
21277 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21278 +               (unsigned long long)nxi->nx_ncaps);
21279 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21280 +               (unsigned long long)nxi->nx_flags);
21281 +
21282 +       buffer += sprintf(buffer,
21283 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21284 +               NIPQUAD(nxi->v4_bcast.s_addr));
21285 +       buffer += sprintf (buffer,
21286 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21287 +               NIPQUAD(nxi->v4_lback.s_addr));
21288 +       if (!NX_IPV4(nxi))
21289 +               goto skip_v4;
21290 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21291 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21292 +                       i, NXAV4(v4a));
21293 +skip_v4:
21294 +#ifdef CONFIG_IPV6
21295 +       if (!NX_IPV6(nxi))
21296 +               goto skip_v6;
21297 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21298 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
21299 +                       i, NXAV6(v6a));
21300 +skip_v6:
21301 +#endif
21302 +       put_nx_info(nxi);
21303 +out:
21304 +       return buffer - orig;
21305 +}
21306 +
21307 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sched.c linux-3.13.10-vs2.3.6.11/kernel/vserver/sched.c
21308 --- linux-3.13.10/kernel/vserver/sched.c        1970-01-01 00:00:00.000000000 +0000
21309 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched.c     2014-01-31 20:38:04.000000000 +0000
21310 @@ -0,0 +1,83 @@
21311 +/*
21312 + *  linux/kernel/vserver/sched.c
21313 + *
21314 + *  Virtual Server: Scheduler Support
21315 + *
21316 + *  Copyright (C) 2004-2010  Herbert Pötzl
21317 + *
21318 + *  V0.01  adapted Sam Vilains version to 2.6.3
21319 + *  V0.02  removed legacy interface
21320 + *  V0.03  changed vcmds to vxi arg
21321 + *  V0.04  removed older and legacy interfaces
21322 + *  V0.05  removed scheduler code/commands
21323 + *
21324 + */
21325 +
21326 +#include <linux/vs_context.h>
21327 +#include <linux/vs_sched.h>
21328 +#include <linux/cpumask.h>
21329 +#include <linux/vserver/sched_cmd.h>
21330 +
21331 +#include <asm/uaccess.h>
21332 +
21333 +
21334 +void vx_update_sched_param(struct _vx_sched *sched,
21335 +       struct _vx_sched_pc *sched_pc)
21336 +{
21337 +       sched_pc->prio_bias = sched->prio_bias;
21338 +}
21339 +
21340 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
21341 +{
21342 +       int cpu;
21343 +
21344 +       if (data->prio_bias > MAX_PRIO_BIAS)
21345 +               data->prio_bias = MAX_PRIO_BIAS;
21346 +       if (data->prio_bias < MIN_PRIO_BIAS)
21347 +               data->prio_bias = MIN_PRIO_BIAS;
21348 +
21349 +       if (data->cpu_id != ~0) {
21350 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
21351 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
21352 +                       cpu_online_mask);
21353 +       } else
21354 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
21355 +
21356 +       for_each_cpu_mask(cpu, vxi->sched.update)
21357 +               vx_update_sched_param(&vxi->sched,
21358 +                       &vx_per_cpu(vxi, sched_pc, cpu));
21359 +       return 0;
21360 +}
21361 +
21362 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
21363 +{
21364 +       struct vcmd_prio_bias vc_data;
21365 +
21366 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21367 +               return -EFAULT;
21368 +
21369 +       return do_set_prio_bias(vxi, &vc_data);
21370 +}
21371 +
21372 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
21373 +{
21374 +       struct vcmd_prio_bias vc_data;
21375 +       struct _vx_sched_pc *pcd;
21376 +       int cpu;
21377 +
21378 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21379 +               return -EFAULT;
21380 +
21381 +       cpu = vc_data.cpu_id;
21382 +
21383 +       if (!cpu_possible(cpu))
21384 +               return -EINVAL;
21385 +
21386 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
21387 +       vc_data.prio_bias = pcd->prio_bias;
21388 +
21389 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21390 +               return -EFAULT;
21391 +       return 0;
21392 +}
21393 +
21394 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sched_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_init.h
21395 --- linux-3.13.10/kernel/vserver/sched_init.h   1970-01-01 00:00:00.000000000 +0000
21396 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_init.h        2014-01-31 20:38:04.000000000 +0000
21397 @@ -0,0 +1,27 @@
21398 +
21399 +static inline void vx_info_init_sched(struct _vx_sched *sched)
21400 +{
21401 +       /* scheduling; hard code starting values as constants */
21402 +       sched->prio_bias = 0;
21403 +}
21404 +
21405 +static inline
21406 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21407 +{
21408 +       sched_pc->prio_bias = 0;
21409 +
21410 +       sched_pc->user_ticks = 0;
21411 +       sched_pc->sys_ticks = 0;
21412 +       sched_pc->hold_ticks = 0;
21413 +}
21414 +
21415 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
21416 +{
21417 +       return;
21418 +}
21419 +
21420 +static inline
21421 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21422 +{
21423 +       return;
21424 +}
21425 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sched_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_proc.h
21426 --- linux-3.13.10/kernel/vserver/sched_proc.h   1970-01-01 00:00:00.000000000 +0000
21427 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_proc.h        2014-01-31 20:38:04.000000000 +0000
21428 @@ -0,0 +1,32 @@
21429 +#ifndef _VX_SCHED_PROC_H
21430 +#define _VX_SCHED_PROC_H
21431 +
21432 +
21433 +static inline
21434 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
21435 +{
21436 +       int length = 0;
21437 +
21438 +       length += sprintf(buffer,
21439 +               "PrioBias:\t%8d\n",
21440 +               sched->prio_bias);
21441 +       return length;
21442 +}
21443 +
21444 +static inline
21445 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
21446 +       char *buffer, int cpu)
21447 +{
21448 +       int length = 0;
21449 +
21450 +       length += sprintf(buffer + length,
21451 +               "cpu %d: %lld %lld %lld", cpu,
21452 +               (unsigned long long)sched_pc->user_ticks,
21453 +               (unsigned long long)sched_pc->sys_ticks,
21454 +               (unsigned long long)sched_pc->hold_ticks);
21455 +       length += sprintf(buffer + length,
21456 +               " %d\n", sched_pc->prio_bias);
21457 +       return length;
21458 +}
21459 +
21460 +#endif /* _VX_SCHED_PROC_H */
21461 diff -NurpP --minimal linux-3.13.10/kernel/vserver/signal.c linux-3.13.10-vs2.3.6.11/kernel/vserver/signal.c
21462 --- linux-3.13.10/kernel/vserver/signal.c       1970-01-01 00:00:00.000000000 +0000
21463 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/signal.c    2014-01-31 20:38:04.000000000 +0000
21464 @@ -0,0 +1,134 @@
21465 +/*
21466 + *  linux/kernel/vserver/signal.c
21467 + *
21468 + *  Virtual Server: Signal Support
21469 + *
21470 + *  Copyright (C) 2003-2007  Herbert Pötzl
21471 + *
21472 + *  V0.01  broken out from vcontext V0.05
21473 + *  V0.02  changed vcmds to vxi arg
21474 + *  V0.03  adjusted siginfo for kill
21475 + *
21476 + */
21477 +
21478 +#include <asm/uaccess.h>
21479 +
21480 +#include <linux/vs_context.h>
21481 +#include <linux/vs_pid.h>
21482 +#include <linux/vserver/signal_cmd.h>
21483 +
21484 +
21485 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
21486 +{
21487 +       int retval, count = 0;
21488 +       struct task_struct *p;
21489 +       struct siginfo *sip = SEND_SIG_PRIV;
21490 +
21491 +       retval = -ESRCH;
21492 +       vxdprintk(VXD_CBIT(misc, 4),
21493 +               "vx_info_kill(%p[#%d],%d,%d)*",
21494 +               vxi, vxi->vx_id, pid, sig);
21495 +       read_lock(&tasklist_lock);
21496 +       switch (pid) {
21497 +       case  0:
21498 +       case -1:
21499 +               for_each_process(p) {
21500 +                       int err = 0;
21501 +
21502 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
21503 +                               (pid && vxi->vx_initpid == p->pid))
21504 +                               continue;
21505 +
21506 +                       err = group_send_sig_info(sig, sip, p);
21507 +                       ++count;
21508 +                       if (err != -EPERM)
21509 +                               retval = err;
21510 +               }
21511 +               break;
21512 +
21513 +       case 1:
21514 +               if (vxi->vx_initpid) {
21515 +                       pid = vxi->vx_initpid;
21516 +                       /* for now, only SIGINT to private init ... */
21517 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21518 +                               /* ... as long as there are tasks left */
21519 +                               (atomic_read(&vxi->vx_tasks) > 1))
21520 +                               sig = SIGINT;
21521 +               }
21522 +               /* fallthrough */
21523 +       default:
21524 +               rcu_read_lock();
21525 +               p = find_task_by_real_pid(pid);
21526 +               rcu_read_unlock();
21527 +               if (p) {
21528 +                       if (vx_task_xid(p) == vxi->vx_id)
21529 +                               retval = group_send_sig_info(sig, sip, p);
21530 +               }
21531 +               break;
21532 +       }
21533 +       read_unlock(&tasklist_lock);
21534 +       vxdprintk(VXD_CBIT(misc, 4),
21535 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
21536 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
21537 +       return retval;
21538 +}
21539 +
21540 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
21541 +{
21542 +       struct vcmd_ctx_kill_v0 vc_data;
21543 +
21544 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21545 +               return -EFAULT;
21546 +
21547 +       /* special check to allow guest shutdown */
21548 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21549 +               /* forbid killall pid=0 when init is present */
21550 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
21551 +               (vc_data.pid > 1)))
21552 +               return -EACCES;
21553 +
21554 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
21555 +}
21556 +
21557 +
21558 +static int __wait_exit(struct vx_info *vxi)
21559 +{
21560 +       DECLARE_WAITQUEUE(wait, current);
21561 +       int ret = 0;
21562 +
21563 +       add_wait_queue(&vxi->vx_wait, &wait);
21564 +       set_current_state(TASK_INTERRUPTIBLE);
21565 +
21566 +wait:
21567 +       if (vx_info_state(vxi,
21568 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
21569 +               goto out;
21570 +       if (signal_pending(current)) {
21571 +               ret = -ERESTARTSYS;
21572 +               goto out;
21573 +       }
21574 +       schedule();
21575 +       goto wait;
21576 +
21577 +out:
21578 +       set_current_state(TASK_RUNNING);
21579 +       remove_wait_queue(&vxi->vx_wait, &wait);
21580 +       return ret;
21581 +}
21582 +
21583 +
21584 +
21585 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
21586 +{
21587 +       struct vcmd_wait_exit_v0 vc_data;
21588 +       int ret;
21589 +
21590 +       ret = __wait_exit(vxi);
21591 +       vc_data.reboot_cmd = vxi->reboot_cmd;
21592 +       vc_data.exit_code = vxi->exit_code;
21593 +
21594 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21595 +               ret = -EFAULT;
21596 +       return ret;
21597 +}
21598 +
21599 diff -NurpP --minimal linux-3.13.10/kernel/vserver/space.c linux-3.13.10-vs2.3.6.11/kernel/vserver/space.c
21600 --- linux-3.13.10/kernel/vserver/space.c        1970-01-01 00:00:00.000000000 +0000
21601 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/space.c     2014-02-01 12:21:24.000000000 +0000
21602 @@ -0,0 +1,436 @@
21603 +/*
21604 + *  linux/kernel/vserver/space.c
21605 + *
21606 + *  Virtual Server: Context Space Support
21607 + *
21608 + *  Copyright (C) 2003-2010  Herbert Pötzl
21609 + *
21610 + *  V0.01  broken out from context.c 0.07
21611 + *  V0.02  added task locking for namespace
21612 + *  V0.03  broken out vx_enter_namespace
21613 + *  V0.04  added *space support and commands
21614 + *  V0.05  added credential support
21615 + *
21616 + */
21617 +
21618 +#include <linux/utsname.h>
21619 +#include <linux/nsproxy.h>
21620 +#include <linux/err.h>
21621 +#include <linux/fs_struct.h>
21622 +#include <linux/cred.h>
21623 +#include <asm/uaccess.h>
21624 +
21625 +#include <linux/vs_context.h>
21626 +#include <linux/vserver/space.h>
21627 +#include <linux/vserver/space_cmd.h>
21628 +
21629 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
21630 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
21631 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
21632 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
21633 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
21634 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
21635 +
21636 +
21637 +/* namespace functions */
21638 +
21639 +#include <linux/mnt_namespace.h>
21640 +#include <linux/user_namespace.h>
21641 +#include <linux/pid_namespace.h>
21642 +#include <linux/ipc_namespace.h>
21643 +#include <net/net_namespace.h>
21644 +#include "../fs/mount.h"
21645 +
21646 +
21647 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
21648 +       .mask = CLONE_FS |
21649 +               CLONE_NEWNS |
21650 +#ifdef CONFIG_UTS_NS
21651 +               CLONE_NEWUTS |
21652 +#endif
21653 +#ifdef CONFIG_IPC_NS
21654 +               CLONE_NEWIPC |
21655 +#endif
21656 +#ifdef CONFIG_USER_NS
21657 +               CLONE_NEWUSER |
21658 +#endif
21659 +               0
21660 +};
21661 +
21662 +static const struct vcmd_space_mask_v1 space_mask = {
21663 +       .mask = CLONE_FS |
21664 +               CLONE_NEWNS |
21665 +#ifdef CONFIG_UTS_NS
21666 +               CLONE_NEWUTS |
21667 +#endif
21668 +#ifdef CONFIG_IPC_NS
21669 +               CLONE_NEWIPC |
21670 +#endif
21671 +#ifdef CONFIG_USER_NS
21672 +               CLONE_NEWUSER |
21673 +#endif
21674 +#ifdef CONFIG_PID_NS
21675 +               CLONE_NEWPID |
21676 +#endif
21677 +#ifdef CONFIG_NET_NS
21678 +               CLONE_NEWNET |
21679 +#endif
21680 +               0
21681 +};
21682 +
21683 +static const struct vcmd_space_mask_v1 default_space_mask = {
21684 +       .mask = CLONE_FS |
21685 +               CLONE_NEWNS |
21686 +#ifdef CONFIG_UTS_NS
21687 +               CLONE_NEWUTS |
21688 +#endif
21689 +#ifdef CONFIG_IPC_NS
21690 +               CLONE_NEWIPC |
21691 +#endif
21692 +#ifdef CONFIG_USER_NS
21693 +               CLONE_NEWUSER |
21694 +#endif
21695 +#ifdef CONFIG_PID_NS
21696 +//             CLONE_NEWPID |
21697 +#endif
21698 +               0
21699 +};
21700 +
21701 +/*
21702 + *     build a new nsproxy mix
21703 + *      assumes that both proxies are 'const'
21704 + *     does not touch nsproxy refcounts
21705 + *     will hold a reference on the result.
21706 + */
21707 +
21708 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
21709 +       struct nsproxy *new_nsproxy, unsigned long mask)
21710 +{
21711 +       struct mnt_namespace *old_ns;
21712 +       struct uts_namespace *old_uts;
21713 +       struct ipc_namespace *old_ipc;
21714 +#ifdef CONFIG_PID_NS
21715 +       struct pid_namespace *old_pid;
21716 +#endif
21717 +#ifdef CONFIG_NET_NS
21718 +       struct net *old_net;
21719 +#endif
21720 +       struct nsproxy *nsproxy;
21721 +
21722 +       nsproxy = copy_nsproxy(old_nsproxy);
21723 +       if (!nsproxy)
21724 +               goto out;
21725 +
21726 +       if (mask & CLONE_NEWNS) {
21727 +               old_ns = nsproxy->mnt_ns;
21728 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
21729 +               if (nsproxy->mnt_ns)
21730 +                       get_mnt_ns(nsproxy->mnt_ns);
21731 +       } else
21732 +               old_ns = NULL;
21733 +
21734 +       if (mask & CLONE_NEWUTS) {
21735 +               old_uts = nsproxy->uts_ns;
21736 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
21737 +               if (nsproxy->uts_ns)
21738 +                       get_uts_ns(nsproxy->uts_ns);
21739 +       } else
21740 +               old_uts = NULL;
21741 +
21742 +       if (mask & CLONE_NEWIPC) {
21743 +               old_ipc = nsproxy->ipc_ns;
21744 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
21745 +               if (nsproxy->ipc_ns)
21746 +                       get_ipc_ns(nsproxy->ipc_ns);
21747 +       } else
21748 +               old_ipc = NULL;
21749 +
21750 +#ifdef CONFIG_PID_NS
21751 +       if (mask & CLONE_NEWPID) {
21752 +               old_pid = nsproxy->pid_ns_for_children;
21753 +               nsproxy->pid_ns_for_children = new_nsproxy->pid_ns_for_children;
21754 +               if (nsproxy->pid_ns_for_children)
21755 +                       get_pid_ns(nsproxy->pid_ns_for_children);
21756 +       } else
21757 +               old_pid = NULL;
21758 +#endif
21759 +#ifdef CONFIG_NET_NS
21760 +       if (mask & CLONE_NEWNET) {
21761 +               old_net = nsproxy->net_ns;
21762 +               nsproxy->net_ns = new_nsproxy->net_ns;
21763 +               if (nsproxy->net_ns)
21764 +                       get_net(nsproxy->net_ns);
21765 +       } else
21766 +               old_net = NULL;
21767 +#endif
21768 +       if (old_ns)
21769 +               put_mnt_ns(old_ns);
21770 +       if (old_uts)
21771 +               put_uts_ns(old_uts);
21772 +       if (old_ipc)
21773 +               put_ipc_ns(old_ipc);
21774 +#ifdef CONFIG_PID_NS
21775 +       if (old_pid)
21776 +               put_pid_ns(old_pid);
21777 +#endif
21778 +#ifdef CONFIG_NET_NS
21779 +       if (old_net)
21780 +               put_net(old_net);
21781 +#endif
21782 +out:
21783 +       return nsproxy;
21784 +}
21785 +
21786 +
21787 +/*
21788 + *     merge two nsproxy structs into a new one.
21789 + *     will hold a reference on the result.
21790 + */
21791 +
21792 +static inline
21793 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
21794 +       struct nsproxy *proxy, unsigned long mask)
21795 +{
21796 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
21797 +
21798 +       if (!proxy)
21799 +               return NULL;
21800 +
21801 +       if (mask) {
21802 +               /* vs_mix_nsproxy returns with reference */
21803 +               return vs_mix_nsproxy(old ? old : &null_proxy,
21804 +                       proxy, mask);
21805 +       }
21806 +       get_nsproxy(proxy);
21807 +       return proxy;
21808 +}
21809 +
21810 +
21811 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21812 +{
21813 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
21814 +       struct fs_struct *fs_cur, *fs = NULL;
21815 +       struct _vx_space *space;
21816 +       int ret, kill = 0;
21817 +
21818 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
21819 +               vxi, vxi->vx_id, mask, index);
21820 +
21821 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
21822 +               return -EACCES;
21823 +
21824 +       if (index >= VX_SPACES)
21825 +               return -EINVAL;
21826 +
21827 +       space = &vxi->space[index];
21828 +
21829 +       if (!mask)
21830 +               mask = space->vx_nsmask;
21831 +
21832 +       if ((mask & space->vx_nsmask) != mask)
21833 +               return -EINVAL;
21834 +
21835 +       if (mask & CLONE_FS) {
21836 +               fs = copy_fs_struct(space->vx_fs);
21837 +               if (!fs)
21838 +                       return -ENOMEM;
21839 +       }
21840 +       proxy = space->vx_nsproxy;
21841 +
21842 +       vxdprintk(VXD_CBIT(space, 9),
21843 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
21844 +               vxi, vxi->vx_id, mask, index, proxy, fs);
21845 +
21846 +       task_lock(current);
21847 +       fs_cur = current->fs;
21848 +
21849 +       if (mask & CLONE_FS) {
21850 +               spin_lock(&fs_cur->lock);
21851 +               current->fs = fs;
21852 +               kill = !--fs_cur->users;
21853 +               spin_unlock(&fs_cur->lock);
21854 +       }
21855 +
21856 +       proxy_cur = current->nsproxy;
21857 +       get_nsproxy(proxy_cur);
21858 +       task_unlock(current);
21859 +
21860 +       if (kill)
21861 +               free_fs_struct(fs_cur);
21862 +
21863 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
21864 +       if (IS_ERR(proxy_new)) {
21865 +               ret = PTR_ERR(proxy_new);
21866 +               goto out_put;
21867 +       }
21868 +
21869 +       proxy_new = xchg(&current->nsproxy, proxy_new);
21870 +
21871 +       if (mask & CLONE_NEWUSER) {
21872 +               struct cred *cred;
21873 +
21874 +               vxdprintk(VXD_CBIT(space, 10),
21875 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
21876 +                       vxi, vxi->vx_id, space->vx_cred,
21877 +                       current->real_cred, current->cred);
21878 +
21879 +               if (space->vx_cred) {
21880 +                       cred = __prepare_creds(space->vx_cred);
21881 +                       if (cred)
21882 +                               commit_creds(cred);
21883 +               }
21884 +       }
21885 +
21886 +       ret = 0;
21887 +
21888 +       if (proxy_new)
21889 +               put_nsproxy(proxy_new);
21890 +out_put:
21891 +       if (proxy_cur)
21892 +               put_nsproxy(proxy_cur);
21893 +       return ret;
21894 +}
21895 +
21896 +
21897 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21898 +{
21899 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
21900 +       struct fs_struct *fs_vxi, *fs = NULL;
21901 +       struct _vx_space *space;
21902 +       int ret, kill = 0;
21903 +
21904 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
21905 +               vxi, vxi->vx_id, mask, index);
21906 +
21907 +       if ((mask & space_mask.mask) != mask)
21908 +               return -EINVAL;
21909 +
21910 +       if (index >= VX_SPACES)
21911 +               return -EINVAL;
21912 +
21913 +       space = &vxi->space[index];
21914 +
21915 +       proxy_vxi = space->vx_nsproxy;
21916 +       fs_vxi = space->vx_fs;
21917 +
21918 +       if (mask & CLONE_FS) {
21919 +               fs = copy_fs_struct(current->fs);
21920 +               if (!fs)
21921 +                       return -ENOMEM;
21922 +       }
21923 +
21924 +       task_lock(current);
21925 +
21926 +       if (mask & CLONE_FS) {
21927 +               spin_lock(&fs_vxi->lock);
21928 +               space->vx_fs = fs;
21929 +               kill = !--fs_vxi->users;
21930 +               spin_unlock(&fs_vxi->lock);
21931 +       }
21932 +
21933 +       proxy_cur = current->nsproxy;
21934 +       get_nsproxy(proxy_cur);
21935 +       task_unlock(current);
21936 +
21937 +       if (kill)
21938 +               free_fs_struct(fs_vxi);
21939 +
21940 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
21941 +       if (IS_ERR(proxy_new)) {
21942 +               ret = PTR_ERR(proxy_new);
21943 +               goto out_put;
21944 +       }
21945 +
21946 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
21947 +       space->vx_nsmask |= mask;
21948 +
21949 +       if (mask & CLONE_NEWUSER) {
21950 +               struct cred *cred;
21951 +
21952 +               vxdprintk(VXD_CBIT(space, 10),
21953 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
21954 +                       vxi, vxi->vx_id, space->vx_cred,
21955 +                       current->real_cred, current->cred);
21956 +
21957 +               cred = prepare_creds();
21958 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
21959 +               if (cred)
21960 +                       abort_creds(cred);
21961 +       }
21962 +
21963 +       ret = 0;
21964 +
21965 +       if (proxy_new)
21966 +               put_nsproxy(proxy_new);
21967 +out_put:
21968 +       if (proxy_cur)
21969 +               put_nsproxy(proxy_cur);
21970 +       return ret;
21971 +}
21972 +
21973 +
21974 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
21975 +{
21976 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21977 +
21978 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21979 +               return -EFAULT;
21980 +
21981 +       return vx_enter_space(vxi, vc_data.mask, 0);
21982 +}
21983 +
21984 +int vc_enter_space(struct vx_info *vxi, void __user *data)
21985 +{
21986 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21987 +
21988 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21989 +               return -EFAULT;
21990 +
21991 +       if (vc_data.index >= VX_SPACES)
21992 +               return -EINVAL;
21993 +
21994 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
21995 +}
21996 +
21997 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
21998 +{
21999 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22000 +
22001 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22002 +               return -EFAULT;
22003 +
22004 +       return vx_set_space(vxi, vc_data.mask, 0);
22005 +}
22006 +
22007 +int vc_set_space(struct vx_info *vxi, void __user *data)
22008 +{
22009 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22010 +
22011 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22012 +               return -EFAULT;
22013 +
22014 +       if (vc_data.index >= VX_SPACES)
22015 +               return -EINVAL;
22016 +
22017 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22018 +}
22019 +
22020 +int vc_get_space_mask(void __user *data, int type)
22021 +{
22022 +       const struct vcmd_space_mask_v1 *mask;
22023 +
22024 +       if (type == 0)
22025 +               mask = &space_mask_v0;
22026 +       else if (type == 1)
22027 +               mask = &space_mask;
22028 +       else
22029 +               mask = &default_space_mask;
22030 +
22031 +       vxdprintk(VXD_CBIT(space, 10),
22032 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22033 +
22034 +       if (copy_to_user(data, mask, sizeof(*mask)))
22035 +               return -EFAULT;
22036 +       return 0;
22037 +}
22038 +
22039 diff -NurpP --minimal linux-3.13.10/kernel/vserver/switch.c linux-3.13.10-vs2.3.6.11/kernel/vserver/switch.c
22040 --- linux-3.13.10/kernel/vserver/switch.c       1970-01-01 00:00:00.000000000 +0000
22041 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/switch.c    2014-01-31 20:38:04.000000000 +0000
22042 @@ -0,0 +1,556 @@
22043 +/*
22044 + *  linux/kernel/vserver/switch.c
22045 + *
22046 + *  Virtual Server: Syscall Switch
22047 + *
22048 + *  Copyright (C) 2003-2011  Herbert Pötzl
22049 + *
22050 + *  V0.01  syscall switch
22051 + *  V0.02  added signal to context
22052 + *  V0.03  added rlimit functions
22053 + *  V0.04  added iattr, task/xid functions
22054 + *  V0.05  added debug/history stuff
22055 + *  V0.06  added compat32 layer
22056 + *  V0.07  vcmd args and perms
22057 + *  V0.08  added status commands
22058 + *  V0.09  added tag commands
22059 + *  V0.10  added oom bias
22060 + *  V0.11  added device commands
22061 + *  V0.12  added warn mask
22062 + *
22063 + */
22064 +
22065 +#include <linux/vs_context.h>
22066 +#include <linux/vs_network.h>
22067 +#include <linux/vserver/switch.h>
22068 +
22069 +#include "vci_config.h"
22070 +
22071 +
22072 +static inline
22073 +int vc_get_version(uint32_t id)
22074 +{
22075 +       return VCI_VERSION;
22076 +}
22077 +
22078 +static inline
22079 +int vc_get_vci(uint32_t id)
22080 +{
22081 +       return vci_kernel_config();
22082 +}
22083 +
22084 +#include <linux/vserver/context_cmd.h>
22085 +#include <linux/vserver/cvirt_cmd.h>
22086 +#include <linux/vserver/cacct_cmd.h>
22087 +#include <linux/vserver/limit_cmd.h>
22088 +#include <linux/vserver/network_cmd.h>
22089 +#include <linux/vserver/sched_cmd.h>
22090 +#include <linux/vserver/debug_cmd.h>
22091 +#include <linux/vserver/inode_cmd.h>
22092 +#include <linux/vserver/dlimit_cmd.h>
22093 +#include <linux/vserver/signal_cmd.h>
22094 +#include <linux/vserver/space_cmd.h>
22095 +#include <linux/vserver/tag_cmd.h>
22096 +#include <linux/vserver/device_cmd.h>
22097 +
22098 +#include <linux/vserver/inode.h>
22099 +#include <linux/vserver/dlimit.h>
22100 +
22101 +
22102 +#ifdef CONFIG_COMPAT
22103 +#define __COMPAT(name, id, data, compat)       \
22104 +       (compat) ? name ## _x32(id, data) : name(id, data)
22105 +#define __COMPAT_NO_ID(name, data, compat)     \
22106 +       (compat) ? name ## _x32(data) : name(data)
22107 +#else
22108 +#define __COMPAT(name, id, data, compat)       \
22109 +       name(id, data)
22110 +#define __COMPAT_NO_ID(name, data, compat)     \
22111 +       name(data)
22112 +#endif
22113 +
22114 +
22115 +static inline
22116 +long do_vcmd(uint32_t cmd, uint32_t id,
22117 +       struct vx_info *vxi, struct nx_info *nxi,
22118 +       void __user *data, int compat)
22119 +{
22120 +       switch (cmd) {
22121 +
22122 +       case VCMD_get_version:
22123 +               return vc_get_version(id);
22124 +       case VCMD_get_vci:
22125 +               return vc_get_vci(id);
22126 +
22127 +       case VCMD_task_xid:
22128 +               return vc_task_xid(id);
22129 +       case VCMD_vx_info:
22130 +               return vc_vx_info(vxi, data);
22131 +
22132 +       case VCMD_task_nid:
22133 +               return vc_task_nid(id);
22134 +       case VCMD_nx_info:
22135 +               return vc_nx_info(nxi, data);
22136 +
22137 +       case VCMD_task_tag:
22138 +               return vc_task_tag(id);
22139 +
22140 +       case VCMD_set_space_v1:
22141 +               return vc_set_space_v1(vxi, data);
22142 +       /* this is version 2 */
22143 +       case VCMD_set_space:
22144 +               return vc_set_space(vxi, data);
22145 +
22146 +       case VCMD_get_space_mask_v0:
22147 +               return vc_get_space_mask(data, 0);
22148 +       /* this is version 1 */
22149 +       case VCMD_get_space_mask:
22150 +               return vc_get_space_mask(data, 1);
22151 +
22152 +       case VCMD_get_space_default:
22153 +               return vc_get_space_mask(data, -1);
22154 +
22155 +       case VCMD_set_umask:
22156 +               return vc_set_umask(vxi, data);
22157 +
22158 +       case VCMD_get_umask:
22159 +               return vc_get_umask(vxi, data);
22160 +
22161 +       case VCMD_set_wmask:
22162 +               return vc_set_wmask(vxi, data);
22163 +
22164 +       case VCMD_get_wmask:
22165 +               return vc_get_wmask(vxi, data);
22166 +#ifdef CONFIG_IA32_EMULATION
22167 +       case VCMD_get_rlimit:
22168 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22169 +       case VCMD_set_rlimit:
22170 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22171 +#else
22172 +       case VCMD_get_rlimit:
22173 +               return vc_get_rlimit(vxi, data);
22174 +       case VCMD_set_rlimit:
22175 +               return vc_set_rlimit(vxi, data);
22176 +#endif
22177 +       case VCMD_get_rlimit_mask:
22178 +               return vc_get_rlimit_mask(id, data);
22179 +       case VCMD_reset_hits:
22180 +               return vc_reset_hits(vxi, data);
22181 +       case VCMD_reset_minmax:
22182 +               return vc_reset_minmax(vxi, data);
22183 +
22184 +       case VCMD_get_vhi_name:
22185 +               return vc_get_vhi_name(vxi, data);
22186 +       case VCMD_set_vhi_name:
22187 +               return vc_set_vhi_name(vxi, data);
22188 +
22189 +       case VCMD_ctx_stat:
22190 +               return vc_ctx_stat(vxi, data);
22191 +       case VCMD_virt_stat:
22192 +               return vc_virt_stat(vxi, data);
22193 +       case VCMD_sock_stat:
22194 +               return vc_sock_stat(vxi, data);
22195 +       case VCMD_rlimit_stat:
22196 +               return vc_rlimit_stat(vxi, data);
22197 +
22198 +       case VCMD_set_cflags:
22199 +               return vc_set_cflags(vxi, data);
22200 +       case VCMD_get_cflags:
22201 +               return vc_get_cflags(vxi, data);
22202 +
22203 +       /* this is version 1 */
22204 +       case VCMD_set_ccaps:
22205 +               return vc_set_ccaps(vxi, data);
22206 +       /* this is version 1 */
22207 +       case VCMD_get_ccaps:
22208 +               return vc_get_ccaps(vxi, data);
22209 +       case VCMD_set_bcaps:
22210 +               return vc_set_bcaps(vxi, data);
22211 +       case VCMD_get_bcaps:
22212 +               return vc_get_bcaps(vxi, data);
22213 +
22214 +       case VCMD_set_badness:
22215 +               return vc_set_badness(vxi, data);
22216 +       case VCMD_get_badness:
22217 +               return vc_get_badness(vxi, data);
22218 +
22219 +       case VCMD_set_nflags:
22220 +               return vc_set_nflags(nxi, data);
22221 +       case VCMD_get_nflags:
22222 +               return vc_get_nflags(nxi, data);
22223 +
22224 +       case VCMD_set_ncaps:
22225 +               return vc_set_ncaps(nxi, data);
22226 +       case VCMD_get_ncaps:
22227 +               return vc_get_ncaps(nxi, data);
22228 +
22229 +       case VCMD_set_prio_bias:
22230 +               return vc_set_prio_bias(vxi, data);
22231 +       case VCMD_get_prio_bias:
22232 +               return vc_get_prio_bias(vxi, data);
22233 +       case VCMD_add_dlimit:
22234 +               return __COMPAT(vc_add_dlimit, id, data, compat);
22235 +       case VCMD_rem_dlimit:
22236 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
22237 +       case VCMD_set_dlimit:
22238 +               return __COMPAT(vc_set_dlimit, id, data, compat);
22239 +       case VCMD_get_dlimit:
22240 +               return __COMPAT(vc_get_dlimit, id, data, compat);
22241 +
22242 +       case VCMD_ctx_kill:
22243 +               return vc_ctx_kill(vxi, data);
22244 +
22245 +       case VCMD_wait_exit:
22246 +               return vc_wait_exit(vxi, data);
22247 +
22248 +       case VCMD_get_iattr:
22249 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22250 +       case VCMD_set_iattr:
22251 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22252 +
22253 +       case VCMD_fget_iattr:
22254 +               return vc_fget_iattr(id, data);
22255 +       case VCMD_fset_iattr:
22256 +               return vc_fset_iattr(id, data);
22257 +
22258 +       case VCMD_enter_space_v0:
22259 +               return vc_enter_space_v1(vxi, NULL);
22260 +       case VCMD_enter_space_v1:
22261 +               return vc_enter_space_v1(vxi, data);
22262 +       /* this is version 2 */
22263 +       case VCMD_enter_space:
22264 +               return vc_enter_space(vxi, data);
22265 +
22266 +       case VCMD_ctx_create_v0:
22267 +               return vc_ctx_create(id, NULL);
22268 +       case VCMD_ctx_create:
22269 +               return vc_ctx_create(id, data);
22270 +       case VCMD_ctx_migrate_v0:
22271 +               return vc_ctx_migrate(vxi, NULL);
22272 +       case VCMD_ctx_migrate:
22273 +               return vc_ctx_migrate(vxi, data);
22274 +
22275 +       case VCMD_net_create_v0:
22276 +               return vc_net_create(id, NULL);
22277 +       case VCMD_net_create:
22278 +               return vc_net_create(id, data);
22279 +       case VCMD_net_migrate:
22280 +               return vc_net_migrate(nxi, data);
22281 +
22282 +       case VCMD_tag_migrate:
22283 +               return vc_tag_migrate(id);
22284 +
22285 +       case VCMD_net_add:
22286 +               return vc_net_add(nxi, data);
22287 +       case VCMD_net_remove:
22288 +               return vc_net_remove(nxi, data);
22289 +
22290 +       case VCMD_net_add_ipv4_v1:
22291 +               return vc_net_add_ipv4_v1(nxi, data);
22292 +       /* this is version 2 */
22293 +       case VCMD_net_add_ipv4:
22294 +               return vc_net_add_ipv4(nxi, data);
22295 +
22296 +       case VCMD_net_rem_ipv4_v1:
22297 +               return vc_net_rem_ipv4_v1(nxi, data);
22298 +       /* this is version 2 */
22299 +       case VCMD_net_rem_ipv4:
22300 +               return vc_net_rem_ipv4(nxi, data);
22301 +#ifdef CONFIG_IPV6
22302 +       case VCMD_net_add_ipv6:
22303 +               return vc_net_add_ipv6(nxi, data);
22304 +       case VCMD_net_remove_ipv6:
22305 +               return vc_net_remove_ipv6(nxi, data);
22306 +#endif
22307 +/*     case VCMD_add_match_ipv4:
22308 +               return vc_add_match_ipv4(nxi, data);
22309 +       case VCMD_get_match_ipv4:
22310 +               return vc_get_match_ipv4(nxi, data);
22311 +#ifdef CONFIG_IPV6
22312 +       case VCMD_add_match_ipv6:
22313 +               return vc_add_match_ipv6(nxi, data);
22314 +       case VCMD_get_match_ipv6:
22315 +               return vc_get_match_ipv6(nxi, data);
22316 +#endif */
22317 +
22318 +#ifdef CONFIG_VSERVER_DEVICE
22319 +       case VCMD_set_mapping:
22320 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
22321 +       case VCMD_unset_mapping:
22322 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
22323 +#endif
22324 +#ifdef CONFIG_VSERVER_HISTORY
22325 +       case VCMD_dump_history:
22326 +               return vc_dump_history(id);
22327 +       case VCMD_read_history:
22328 +               return __COMPAT(vc_read_history, id, data, compat);
22329 +#endif
22330 +       default:
22331 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
22332 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
22333 +       }
22334 +       return -ENOSYS;
22335 +}
22336 +
22337 +
22338 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
22339 +       case VCMD_ ## vcmd: perm = _perm;               \
22340 +               args = _args; flags = _flags; break
22341 +
22342 +
22343 +#define VCA_NONE       0x00
22344 +#define VCA_VXI                0x01
22345 +#define VCA_NXI                0x02
22346 +
22347 +#define VCF_NONE       0x00
22348 +#define VCF_INFO       0x01
22349 +#define VCF_ADMIN      0x02
22350 +#define VCF_ARES       0x06    /* includes admin */
22351 +#define VCF_SETUP      0x08
22352 +
22353 +#define VCF_ZIDOK      0x10    /* zero id okay */
22354 +
22355 +
22356 +static inline
22357 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
22358 +{
22359 +       long ret;
22360 +       int permit = -1, state = 0;
22361 +       int perm = -1, args = 0, flags = 0;
22362 +       struct vx_info *vxi = NULL;
22363 +       struct nx_info *nxi = NULL;
22364 +
22365 +       switch (cmd) {
22366 +       /* unpriviledged commands */
22367 +       __VCMD(get_version,      0, VCA_NONE,   0);
22368 +       __VCMD(get_vci,          0, VCA_NONE,   0);
22369 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
22370 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
22371 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
22372 +       __VCMD(get_space_default,0, VCA_NONE,   0);
22373 +
22374 +       /* info commands */
22375 +       __VCMD(task_xid,         2, VCA_NONE,   0);
22376 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
22377 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
22378 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
22379 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
22380 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
22381 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
22382 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
22383 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
22384 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
22385 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
22386 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
22387 +
22388 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
22389 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
22390 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
22391 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
22392 +
22393 +       __VCMD(task_nid,         2, VCA_NONE,   0);
22394 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
22395 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
22396 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
22397 +
22398 +       __VCMD(task_tag,         2, VCA_NONE,   0);
22399 +
22400 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
22401 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
22402 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
22403 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
22404 +
22405 +       /* lower admin commands */
22406 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
22407 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
22408 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
22409 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
22410 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
22411 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
22412 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
22413 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
22414 +
22415 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
22416 +       __VCMD(net_create,       5, VCA_NONE,   0);
22417 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
22418 +
22419 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
22420 +
22421 +       /* higher admin commands */
22422 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
22423 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22424 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22425 +
22426 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22427 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22428 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22429 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22430 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22431 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22432 +
22433 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22434 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22435 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
22436 +
22437 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22438 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
22439 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22440 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22441 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22442 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22443 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22444 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22445 +#ifdef CONFIG_IPV6
22446 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22447 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
22448 +#endif
22449 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
22450 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
22451 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
22452 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
22453 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
22454 +
22455 +#ifdef CONFIG_VSERVER_DEVICE
22456 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22457 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
22458 +#endif
22459 +       /* debug level admin commands */
22460 +#ifdef CONFIG_VSERVER_HISTORY
22461 +       __VCMD(dump_history,     9, VCA_NONE,   0);
22462 +       __VCMD(read_history,     9, VCA_NONE,   0);
22463 +#endif
22464 +
22465 +       default:
22466 +               perm = -1;
22467 +       }
22468 +
22469 +       vxdprintk(VXD_CBIT(switch, 0),
22470 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
22471 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22472 +               VC_VERSION(cmd), id, data, compat,
22473 +               perm, args, flags);
22474 +
22475 +       ret = -ENOSYS;
22476 +       if (perm < 0)
22477 +               goto out;
22478 +
22479 +       state = 1;
22480 +       if (!capable(CAP_CONTEXT))
22481 +               goto out;
22482 +
22483 +       state = 2;
22484 +       /* moved here from the individual commands */
22485 +       ret = -EPERM;
22486 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
22487 +               goto out;
22488 +
22489 +       state = 3;
22490 +       /* vcmd involves resource management  */
22491 +       ret = -EPERM;
22492 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
22493 +               goto out;
22494 +
22495 +       state = 4;
22496 +       /* various legacy exceptions */
22497 +       switch (cmd) {
22498 +       /* will go away when spectator is a cap */
22499 +       case VCMD_ctx_migrate_v0:
22500 +       case VCMD_ctx_migrate:
22501 +               if (id == 1) {
22502 +                       current->xid = 1;
22503 +                       ret = 1;
22504 +                       goto out;
22505 +               }
22506 +               break;
22507 +
22508 +       /* will go away when spectator is a cap */
22509 +       case VCMD_net_migrate:
22510 +               if (id == 1) {
22511 +                       current->nid = 1;
22512 +                       ret = 1;
22513 +                       goto out;
22514 +               }
22515 +               break;
22516 +       }
22517 +
22518 +       /* vcmds are fine by default */
22519 +       permit = 1;
22520 +
22521 +       /* admin type vcmds require admin ... */
22522 +       if (flags & VCF_ADMIN)
22523 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
22524 +
22525 +       /* ... but setup type vcmds override that */
22526 +       if (!permit && (flags & VCF_SETUP))
22527 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
22528 +
22529 +       state = 5;
22530 +       ret = -EPERM;
22531 +       if (!permit)
22532 +               goto out;
22533 +
22534 +       state = 6;
22535 +       if (!id && (flags & VCF_ZIDOK))
22536 +               goto skip_id;
22537 +
22538 +       ret = -ESRCH;
22539 +       if (args & VCA_VXI) {
22540 +               vxi = lookup_vx_info(id);
22541 +               if (!vxi)
22542 +                       goto out;
22543 +
22544 +               if ((flags & VCF_ADMIN) &&
22545 +                       /* special case kill for shutdown */
22546 +                       (cmd != VCMD_ctx_kill) &&
22547 +                       /* can context be administrated? */
22548 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
22549 +                       ret = -EACCES;
22550 +                       goto out_vxi;
22551 +               }
22552 +       }
22553 +       state = 7;
22554 +       if (args & VCA_NXI) {
22555 +               nxi = lookup_nx_info(id);
22556 +               if (!nxi)
22557 +                       goto out_vxi;
22558 +
22559 +               if ((flags & VCF_ADMIN) &&
22560 +                       /* can context be administrated? */
22561 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
22562 +                       ret = -EACCES;
22563 +                       goto out_nxi;
22564 +               }
22565 +       }
22566 +skip_id:
22567 +       state = 8;
22568 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
22569 +
22570 +out_nxi:
22571 +       if ((args & VCA_NXI) && nxi)
22572 +               put_nx_info(nxi);
22573 +out_vxi:
22574 +       if ((args & VCA_VXI) && vxi)
22575 +               put_vx_info(vxi);
22576 +out:
22577 +       vxdprintk(VXD_CBIT(switch, 1),
22578 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
22579 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
22580 +               VC_VERSION(cmd), ret, ret, state, permit);
22581 +       return ret;
22582 +}
22583 +
22584 +asmlinkage long
22585 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
22586 +{
22587 +       return do_vserver(cmd, id, data, 0);
22588 +}
22589 +
22590 +#ifdef CONFIG_COMPAT
22591 +
22592 +asmlinkage long
22593 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
22594 +{
22595 +       return do_vserver(cmd, id, data, 1);
22596 +}
22597 +
22598 +#endif /* CONFIG_COMPAT */
22599 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sysctl.c linux-3.13.10-vs2.3.6.11/kernel/vserver/sysctl.c
22600 --- linux-3.13.10/kernel/vserver/sysctl.c       1970-01-01 00:00:00.000000000 +0000
22601 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sysctl.c    2014-01-31 20:38:04.000000000 +0000
22602 @@ -0,0 +1,247 @@
22603 +/*
22604 + *  kernel/vserver/sysctl.c
22605 + *
22606 + *  Virtual Context Support
22607 + *
22608 + *  Copyright (C) 2004-2007  Herbert Pötzl
22609 + *
22610 + *  V0.01  basic structure
22611 + *
22612 + */
22613 +
22614 +#include <linux/module.h>
22615 +#include <linux/ctype.h>
22616 +#include <linux/sysctl.h>
22617 +#include <linux/parser.h>
22618 +#include <asm/uaccess.h>
22619 +
22620 +enum {
22621 +       CTL_DEBUG_ERROR         = 0,
22622 +       CTL_DEBUG_SWITCH        = 1,
22623 +       CTL_DEBUG_XID,
22624 +       CTL_DEBUG_NID,
22625 +       CTL_DEBUG_TAG,
22626 +       CTL_DEBUG_NET,
22627 +       CTL_DEBUG_LIMIT,
22628 +       CTL_DEBUG_CRES,
22629 +       CTL_DEBUG_DLIM,
22630 +       CTL_DEBUG_QUOTA,
22631 +       CTL_DEBUG_CVIRT,
22632 +       CTL_DEBUG_SPACE,
22633 +       CTL_DEBUG_PERM,
22634 +       CTL_DEBUG_MISC,
22635 +};
22636 +
22637 +
22638 +unsigned int vs_debug_switch   = 0;
22639 +unsigned int vs_debug_xid      = 0;
22640 +unsigned int vs_debug_nid      = 0;
22641 +unsigned int vs_debug_tag      = 0;
22642 +unsigned int vs_debug_net      = 0;
22643 +unsigned int vs_debug_limit    = 0;
22644 +unsigned int vs_debug_cres     = 0;
22645 +unsigned int vs_debug_dlim     = 0;
22646 +unsigned int vs_debug_quota    = 0;
22647 +unsigned int vs_debug_cvirt    = 0;
22648 +unsigned int vs_debug_space    = 0;
22649 +unsigned int vs_debug_perm     = 0;
22650 +unsigned int vs_debug_misc     = 0;
22651 +
22652 +
22653 +static struct ctl_table_header *vserver_table_header;
22654 +static ctl_table vserver_root_table[];
22655 +
22656 +
22657 +void vserver_register_sysctl(void)
22658 +{
22659 +       if (!vserver_table_header) {
22660 +               vserver_table_header = register_sysctl_table(vserver_root_table);
22661 +       }
22662 +
22663 +}
22664 +
22665 +void vserver_unregister_sysctl(void)
22666 +{
22667 +       if (vserver_table_header) {
22668 +               unregister_sysctl_table(vserver_table_header);
22669 +               vserver_table_header = NULL;
22670 +       }
22671 +}
22672 +
22673 +
22674 +static int proc_dodebug(ctl_table *table, int write,
22675 +       void __user *buffer, size_t *lenp, loff_t *ppos)
22676 +{
22677 +       char            tmpbuf[20], *p, c;
22678 +       unsigned int    value;
22679 +       size_t          left, len;
22680 +
22681 +       if ((*ppos && !write) || !*lenp) {
22682 +               *lenp = 0;
22683 +               return 0;
22684 +       }
22685 +
22686 +       left = *lenp;
22687 +
22688 +       if (write) {
22689 +               if (!access_ok(VERIFY_READ, buffer, left))
22690 +                       return -EFAULT;
22691 +               p = (char *)buffer;
22692 +               while (left && __get_user(c, p) >= 0 && isspace(c))
22693 +                       left--, p++;
22694 +               if (!left)
22695 +                       goto done;
22696 +
22697 +               if (left > sizeof(tmpbuf) - 1)
22698 +                       return -EINVAL;
22699 +               if (copy_from_user(tmpbuf, p, left))
22700 +                       return -EFAULT;
22701 +               tmpbuf[left] = '\0';
22702 +
22703 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
22704 +                       value = 10 * value + (*p - '0');
22705 +               if (*p && !isspace(*p))
22706 +                       return -EINVAL;
22707 +               while (left && isspace(*p))
22708 +                       left--, p++;
22709 +               *(unsigned int *)table->data = value;
22710 +       } else {
22711 +               if (!access_ok(VERIFY_WRITE, buffer, left))
22712 +                       return -EFAULT;
22713 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
22714 +               if (len > left)
22715 +                       len = left;
22716 +               if (__copy_to_user(buffer, tmpbuf, len))
22717 +                       return -EFAULT;
22718 +               if ((left -= len) > 0) {
22719 +                       if (put_user('\n', (char *)buffer + len))
22720 +                               return -EFAULT;
22721 +                       left--;
22722 +               }
22723 +       }
22724 +
22725 +done:
22726 +       *lenp -= left;
22727 +       *ppos += *lenp;
22728 +       return 0;
22729 +}
22730 +
22731 +static int zero;
22732 +
22733 +#define        CTL_ENTRY(ctl, name)                            \
22734 +       {                                               \
22735 +               .procname       = #name,                \
22736 +               .data           = &vs_ ## name,         \
22737 +               .maxlen         = sizeof(int),          \
22738 +               .mode           = 0644,                 \
22739 +               .proc_handler   = &proc_dodebug,        \
22740 +               .extra1         = &zero,                \
22741 +               .extra2         = &zero,                \
22742 +       }
22743 +
22744 +static ctl_table vserver_debug_table[] = {
22745 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
22746 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
22747 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
22748 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
22749 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
22750 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
22751 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
22752 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
22753 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
22754 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
22755 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
22756 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
22757 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
22758 +       { 0 }
22759 +};
22760 +
22761 +static ctl_table vserver_root_table[] = {
22762 +       {
22763 +               .procname       = "vserver",
22764 +               .mode           = 0555,
22765 +               .child          = vserver_debug_table
22766 +       },
22767 +       { 0 }
22768 +};
22769 +
22770 +
22771 +static match_table_t tokens = {
22772 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
22773 +       { CTL_DEBUG_XID,        "xid=%x"        },
22774 +       { CTL_DEBUG_NID,        "nid=%x"        },
22775 +       { CTL_DEBUG_TAG,        "tag=%x"        },
22776 +       { CTL_DEBUG_NET,        "net=%x"        },
22777 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
22778 +       { CTL_DEBUG_CRES,       "cres=%x"       },
22779 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
22780 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
22781 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
22782 +       { CTL_DEBUG_SPACE,      "space=%x"      },
22783 +       { CTL_DEBUG_PERM,       "perm=%x"       },
22784 +       { CTL_DEBUG_MISC,       "misc=%x"       },
22785 +       { CTL_DEBUG_ERROR,      NULL            }
22786 +};
22787 +
22788 +#define        HANDLE_CASE(id, name, val)                              \
22789 +       case CTL_DEBUG_ ## id:                                  \
22790 +               vs_debug_ ## name = val;                        \
22791 +               printk("vs_debug_" #name "=0x%x\n", val);       \
22792 +               break
22793 +
22794 +
22795 +static int __init vs_debug_setup(char *str)
22796 +{
22797 +       char *p;
22798 +       int token;
22799 +
22800 +       printk("vs_debug_setup(%s)\n", str);
22801 +       while ((p = strsep(&str, ",")) != NULL) {
22802 +               substring_t args[MAX_OPT_ARGS];
22803 +               unsigned int value;
22804 +
22805 +               if (!*p)
22806 +                       continue;
22807 +
22808 +               token = match_token(p, tokens, args);
22809 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
22810 +
22811 +               switch (token) {
22812 +               HANDLE_CASE(SWITCH, switch, value);
22813 +               HANDLE_CASE(XID,    xid,    value);
22814 +               HANDLE_CASE(NID,    nid,    value);
22815 +               HANDLE_CASE(TAG,    tag,    value);
22816 +               HANDLE_CASE(NET,    net,    value);
22817 +               HANDLE_CASE(LIMIT,  limit,  value);
22818 +               HANDLE_CASE(CRES,   cres,   value);
22819 +               HANDLE_CASE(DLIM,   dlim,   value);
22820 +               HANDLE_CASE(QUOTA,  quota,  value);
22821 +               HANDLE_CASE(CVIRT,  cvirt,  value);
22822 +               HANDLE_CASE(SPACE,  space,  value);
22823 +               HANDLE_CASE(PERM,   perm,   value);
22824 +               HANDLE_CASE(MISC,   misc,   value);
22825 +               default:
22826 +                       return -EINVAL;
22827 +                       break;
22828 +               }
22829 +       }
22830 +       return 1;
22831 +}
22832 +
22833 +__setup("vsdebug=", vs_debug_setup);
22834 +
22835 +
22836 +
22837 +EXPORT_SYMBOL_GPL(vs_debug_switch);
22838 +EXPORT_SYMBOL_GPL(vs_debug_xid);
22839 +EXPORT_SYMBOL_GPL(vs_debug_nid);
22840 +EXPORT_SYMBOL_GPL(vs_debug_net);
22841 +EXPORT_SYMBOL_GPL(vs_debug_limit);
22842 +EXPORT_SYMBOL_GPL(vs_debug_cres);
22843 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
22844 +EXPORT_SYMBOL_GPL(vs_debug_quota);
22845 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
22846 +EXPORT_SYMBOL_GPL(vs_debug_space);
22847 +EXPORT_SYMBOL_GPL(vs_debug_perm);
22848 +EXPORT_SYMBOL_GPL(vs_debug_misc);
22849 +
22850 diff -NurpP --minimal linux-3.13.10/kernel/vserver/tag.c linux-3.13.10-vs2.3.6.11/kernel/vserver/tag.c
22851 --- linux-3.13.10/kernel/vserver/tag.c  1970-01-01 00:00:00.000000000 +0000
22852 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/tag.c       2014-01-31 20:38:04.000000000 +0000
22853 @@ -0,0 +1,63 @@
22854 +/*
22855 + *  linux/kernel/vserver/tag.c
22856 + *
22857 + *  Virtual Server: Shallow Tag Space
22858 + *
22859 + *  Copyright (C) 2007  Herbert Pötzl
22860 + *
22861 + *  V0.01  basic implementation
22862 + *
22863 + */
22864 +
22865 +#include <linux/sched.h>
22866 +#include <linux/vserver/debug.h>
22867 +#include <linux/vs_pid.h>
22868 +#include <linux/vs_tag.h>
22869 +
22870 +#include <linux/vserver/tag_cmd.h>
22871 +
22872 +
22873 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
22874 +{
22875 +       if (!p)
22876 +               BUG();
22877 +
22878 +       vxdprintk(VXD_CBIT(tag, 5),
22879 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
22880 +
22881 +       task_lock(p);
22882 +       p->tag = tag;
22883 +       task_unlock(p);
22884 +
22885 +       vxdprintk(VXD_CBIT(tag, 5),
22886 +               "moved task %p into [#%d]", p, tag);
22887 +       return 0;
22888 +}
22889 +
22890 +/* vserver syscall commands below here */
22891 +
22892 +/* taks xid and vx_info functions */
22893 +
22894 +
22895 +int vc_task_tag(uint32_t id)
22896 +{
22897 +       vtag_t tag;
22898 +
22899 +       if (id) {
22900 +               struct task_struct *tsk;
22901 +               rcu_read_lock();
22902 +               tsk = find_task_by_real_pid(id);
22903 +               tag = (tsk) ? tsk->tag : -ESRCH;
22904 +               rcu_read_unlock();
22905 +       } else
22906 +               tag = dx_current_tag();
22907 +       return tag;
22908 +}
22909 +
22910 +
22911 +int vc_tag_migrate(uint32_t tag)
22912 +{
22913 +       return dx_migrate_task(current, tag & 0xFFFF);
22914 +}
22915 +
22916 +
22917 diff -NurpP --minimal linux-3.13.10/kernel/vserver/vci_config.h linux-3.13.10-vs2.3.6.11/kernel/vserver/vci_config.h
22918 --- linux-3.13.10/kernel/vserver/vci_config.h   1970-01-01 00:00:00.000000000 +0000
22919 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/vci_config.h        2014-01-31 20:38:04.000000000 +0000
22920 @@ -0,0 +1,80 @@
22921 +
22922 +/*  interface version */
22923 +
22924 +#define VCI_VERSION            0x00020308
22925 +
22926 +
22927 +enum {
22928 +       VCI_KCBIT_NO_DYNAMIC = 0,
22929 +
22930 +       VCI_KCBIT_PROC_SECURE = 4,
22931 +       /* VCI_KCBIT_HARDCPU = 5, */
22932 +       /* VCI_KCBIT_IDLELIMIT = 6, */
22933 +       /* VCI_KCBIT_IDLETIME = 7, */
22934 +
22935 +       VCI_KCBIT_COWBL = 8,
22936 +       VCI_KCBIT_FULLCOWBL = 9,
22937 +       VCI_KCBIT_SPACES = 10,
22938 +       VCI_KCBIT_NETV2 = 11,
22939 +       VCI_KCBIT_MEMCG = 12,
22940 +       VCI_KCBIT_MEMCG_SWAP = 13,
22941 +
22942 +       VCI_KCBIT_DEBUG = 16,
22943 +       VCI_KCBIT_HISTORY = 20,
22944 +       VCI_KCBIT_TAGGED = 24,
22945 +       VCI_KCBIT_PPTAG = 28,
22946 +
22947 +       VCI_KCBIT_MORE = 31,
22948 +};
22949 +
22950 +
22951 +static inline uint32_t vci_kernel_config(void)
22952 +{
22953 +       return
22954 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
22955 +
22956 +       /* configured features */
22957 +#ifdef CONFIG_VSERVER_PROC_SECURE
22958 +       (1 << VCI_KCBIT_PROC_SECURE) |
22959 +#endif
22960 +#ifdef CONFIG_VSERVER_COWBL
22961 +       (1 << VCI_KCBIT_COWBL) |
22962 +       (1 << VCI_KCBIT_FULLCOWBL) |
22963 +#endif
22964 +       (1 << VCI_KCBIT_SPACES) |
22965 +       (1 << VCI_KCBIT_NETV2) |
22966 +#ifdef CONFIG_MEMCG
22967 +       (1 << VCI_KCBIT_MEMCG) |
22968 +#endif
22969 +#ifdef CONFIG_MEMCG_SWAP
22970 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
22971 +#endif
22972 +
22973 +       /* debug options */
22974 +#ifdef CONFIG_VSERVER_DEBUG
22975 +       (1 << VCI_KCBIT_DEBUG) |
22976 +#endif
22977 +#ifdef CONFIG_VSERVER_HISTORY
22978 +       (1 << VCI_KCBIT_HISTORY) |
22979 +#endif
22980 +
22981 +       /* inode context tagging */
22982 +#if    defined(CONFIG_TAGGING_NONE)
22983 +       (0 << VCI_KCBIT_TAGGED) |
22984 +#elif  defined(CONFIG_TAGGING_UID16)
22985 +       (1 << VCI_KCBIT_TAGGED) |
22986 +#elif  defined(CONFIG_TAGGING_GID16)
22987 +       (2 << VCI_KCBIT_TAGGED) |
22988 +#elif  defined(CONFIG_TAGGING_ID24)
22989 +       (3 << VCI_KCBIT_TAGGED) |
22990 +#elif  defined(CONFIG_TAGGING_INTERN)
22991 +       (4 << VCI_KCBIT_TAGGED) |
22992 +#elif  defined(CONFIG_TAGGING_RUNTIME)
22993 +       (5 << VCI_KCBIT_TAGGED) |
22994 +#else
22995 +       (7 << VCI_KCBIT_TAGGED) |
22996 +#endif
22997 +       (1 << VCI_KCBIT_PPTAG) |
22998 +       0;
22999 +}
23000 +
23001 diff -NurpP --minimal linux-3.13.10/mm/memcontrol.c linux-3.13.10-vs2.3.6.11/mm/memcontrol.c
23002 --- linux-3.13.10/mm/memcontrol.c       2014-04-17 01:12:40.000000000 +0000
23003 +++ linux-3.13.10-vs2.3.6.11/mm/memcontrol.c    2014-04-17 01:17:11.000000000 +0000
23004 @@ -1056,6 +1056,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23005         return mem_cgroup_from_css(task_css(p, mem_cgroup_subsys_id));
23006  }
23007  
23008 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23009 +{
23010 +       return res_counter_read_u64(&mem->res, member);
23011 +}
23012 +
23013 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23014 +{
23015 +       return res_counter_read_u64(&mem->memsw, member);
23016 +}
23017 +
23018 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23019 +{
23020 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23021 +}
23022 +
23023 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23024 +{
23025 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23026 +}
23027 +
23028 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23029 +{
23030 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23031 +}
23032 +
23033  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23034  {
23035         struct mem_cgroup *memcg = NULL;
23036 diff -NurpP --minimal linux-3.13.10/mm/oom_kill.c linux-3.13.10-vs2.3.6.11/mm/oom_kill.c
23037 --- linux-3.13.10/mm/oom_kill.c 2014-04-17 01:12:40.000000000 +0000
23038 +++ linux-3.13.10-vs2.3.6.11/mm/oom_kill.c      2014-02-25 11:26:10.000000000 +0000
23039 @@ -35,6 +35,8 @@
23040  #include <linux/freezer.h>
23041  #include <linux/ftrace.h>
23042  #include <linux/ratelimit.h>
23043 +#include <linux/reboot.h>
23044 +#include <linux/vs_context.h>
23045  
23046  #define CREATE_TRACE_POINTS
23047  #include <trace/events/oom.h>
23048 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23049  static bool oom_unkillable_task(struct task_struct *p,
23050                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23051  {
23052 -       if (is_global_init(p))
23053 +       unsigned xid = vx_current_xid();
23054 +
23055 +       /* skip the init task, global and per guest */
23056 +       if (task_is_init(p))
23057                 return true;
23058         if (p->flags & PF_KTHREAD)
23059                 return true;
23060  
23061 +       /* skip other guest and host processes if oom in guest */
23062 +       if (xid && vx_task_xid(p) != xid)
23063 +               return true;
23064 +
23065         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23066         if (memcg && !task_in_mem_cgroup(p, memcg))
23067                 return true;
23068 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23069                 dump_header(p, gfp_mask, order, memcg, nodemask);
23070  
23071         task_lock(p);
23072 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23073 -               message, task_pid_nr(p), p->comm, points);
23074 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23075 +               message, task_pid_nr(p), p->xid, p->comm, points);
23076         task_unlock(p);
23077  
23078         /*
23079 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23080  
23081         /* mm cannot safely be dereferenced after task_unlock(victim) */
23082         mm = victim->mm;
23083 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23084 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23085 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23086 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23087                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23088                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23089         task_unlock(victim);
23090 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23091  }
23092  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23093  
23094 +long vs_oom_action(unsigned int);
23095 +
23096  /*
23097   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23098   * if a parallel OOM killing is already taking place that includes a zone in
23099 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23100         /* Found nothing?!?! Either we hang forever, or we panic. */
23101         if (!p) {
23102                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23103 -               panic("Out of memory and no killable processes...\n");
23104 +
23105 +               /* avoid panic for guest OOM */
23106 +               if (vx_current_xid())
23107 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23108 +               else
23109 +                       panic("Out of memory and no killable processes...\n");
23110         }
23111         if (p != (void *)-1UL) {
23112                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23113 diff -NurpP --minimal linux-3.13.10/mm/page_alloc.c linux-3.13.10-vs2.3.6.11/mm/page_alloc.c
23114 --- linux-3.13.10/mm/page_alloc.c       2014-04-17 01:12:40.000000000 +0000
23115 +++ linux-3.13.10-vs2.3.6.11/mm/page_alloc.c    2014-04-17 01:17:11.000000000 +0000
23116 @@ -61,6 +61,8 @@
23117  #include <linux/page-debug-flags.h>
23118  #include <linux/hugetlb.h>
23119  #include <linux/sched/rt.h>
23120 +#include <linux/vs_base.h>
23121 +#include <linux/vs_limit.h>
23122  
23123  #include <asm/sections.h>
23124  #include <asm/tlbflush.h>
23125 @@ -2983,6 +2985,9 @@ void si_meminfo(struct sysinfo *val)
23126         val->totalhigh = totalhigh_pages;
23127         val->freehigh = nr_free_highpages();
23128         val->mem_unit = PAGE_SIZE;
23129 +
23130 +       if (vx_flags(VXF_VIRT_MEM, 0))
23131 +               vx_vsi_meminfo(val);
23132  }
23133  
23134  EXPORT_SYMBOL(si_meminfo);
23135 @@ -3007,6 +3012,9 @@ void si_meminfo_node(struct sysinfo *val
23136         val->freehigh = 0;
23137  #endif
23138         val->mem_unit = PAGE_SIZE;
23139 +
23140 +       if (vx_flags(VXF_VIRT_MEM, 0))
23141 +               vx_vsi_meminfo(val);
23142  }
23143  #endif
23144  
23145 diff -NurpP --minimal linux-3.13.10/mm/pgtable-generic.c linux-3.13.10-vs2.3.6.11/mm/pgtable-generic.c
23146 --- linux-3.13.10/mm/pgtable-generic.c  2014-01-22 20:39:14.000000000 +0000
23147 +++ linux-3.13.10-vs2.3.6.11/mm/pgtable-generic.c       2014-01-31 20:38:04.000000000 +0000
23148 @@ -6,6 +6,8 @@
23149   *  Copyright (C) 2010  Linus Torvalds
23150   */
23151  
23152 +#include <linux/mm.h>
23153 +
23154  #include <linux/pagemap.h>
23155  #include <asm/tlb.h>
23156  #include <asm-generic/pgtable.h>
23157 diff -NurpP --minimal linux-3.13.10/mm/shmem.c linux-3.13.10-vs2.3.6.11/mm/shmem.c
23158 --- linux-3.13.10/mm/shmem.c    2014-01-22 20:39:14.000000000 +0000
23159 +++ linux-3.13.10-vs2.3.6.11/mm/shmem.c 2014-01-31 20:38:04.000000000 +0000
23160 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23161  {
23162         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23163  
23164 -       buf->f_type = TMPFS_MAGIC;
23165 +       buf->f_type = TMPFS_SUPER_MAGIC;
23166         buf->f_bsize = PAGE_CACHE_SIZE;
23167         buf->f_namelen = NAME_MAX;
23168         if (sbinfo->max_blocks) {
23169 @@ -2639,7 +2639,7 @@ int shmem_fill_super(struct super_block
23170         sb->s_maxbytes = MAX_LFS_FILESIZE;
23171         sb->s_blocksize = PAGE_CACHE_SIZE;
23172         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23173 -       sb->s_magic = TMPFS_MAGIC;
23174 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23175         sb->s_op = &shmem_ops;
23176         sb->s_time_gran = 1;
23177  #ifdef CONFIG_TMPFS_XATTR
23178 diff -NurpP --minimal linux-3.13.10/mm/slab.c linux-3.13.10-vs2.3.6.11/mm/slab.c
23179 --- linux-3.13.10/mm/slab.c     2014-01-22 20:39:14.000000000 +0000
23180 +++ linux-3.13.10-vs2.3.6.11/mm/slab.c  2014-01-31 20:38:04.000000000 +0000
23181 @@ -322,6 +322,8 @@ static void kmem_cache_node_init(struct
23182  #define STATS_INC_FREEMISS(x)  do { } while (0)
23183  #endif
23184  
23185 +#include "slab_vs.h"
23186 +
23187  #if DEBUG
23188  
23189  /*
23190 @@ -3240,6 +3242,7 @@ slab_alloc_node(struct kmem_cache *cache
23191         /* ___cache_alloc_node can fall back to other nodes */
23192         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23193    out:
23194 +       vx_slab_alloc(cachep, flags);
23195         local_irq_restore(save_flags);
23196         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23197         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23198 @@ -3430,6 +3433,7 @@ static inline void __cache_free(struct k
23199         check_irq_off();
23200         kmemleak_free_recursive(objp, cachep->flags);
23201         objp = cache_free_debugcheck(cachep, objp, caller);
23202 +       vx_slab_free(cachep);
23203  
23204         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23205  
23206 diff -NurpP --minimal linux-3.13.10/mm/slab_vs.h linux-3.13.10-vs2.3.6.11/mm/slab_vs.h
23207 --- linux-3.13.10/mm/slab_vs.h  1970-01-01 00:00:00.000000000 +0000
23208 +++ linux-3.13.10-vs2.3.6.11/mm/slab_vs.h       2014-01-31 20:38:04.000000000 +0000
23209 @@ -0,0 +1,29 @@
23210 +
23211 +#include <linux/vserver/context.h>
23212 +
23213 +#include <linux/vs_context.h>
23214 +
23215 +static inline
23216 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23217 +{
23218 +       int what = gfp_zone(cachep->allocflags);
23219 +       struct vx_info *vxi = current_vx_info();
23220 +
23221 +       if (!vxi)
23222 +               return;
23223 +
23224 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
23225 +}
23226 +
23227 +static inline
23228 +void vx_slab_free(struct kmem_cache *cachep)
23229 +{
23230 +       int what = gfp_zone(cachep->allocflags);
23231 +       struct vx_info *vxi = current_vx_info();
23232 +
23233 +       if (!vxi)
23234 +               return;
23235 +
23236 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23237 +}
23238 +
23239 diff -NurpP --minimal linux-3.13.10/mm/swapfile.c linux-3.13.10-vs2.3.6.11/mm/swapfile.c
23240 --- linux-3.13.10/mm/swapfile.c 2014-04-17 01:12:40.000000000 +0000
23241 +++ linux-3.13.10-vs2.3.6.11/mm/swapfile.c      2014-02-25 11:26:10.000000000 +0000
23242 @@ -39,6 +39,7 @@
23243  #include <asm/tlbflush.h>
23244  #include <linux/swapops.h>
23245  #include <linux/page_cgroup.h>
23246 +#include <linux/vs_base.h>
23247  
23248  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23249                                  unsigned char);
23250 @@ -2042,6 +2043,16 @@ static int swap_show(struct seq_file *sw
23251  
23252         if (si == SEQ_START_TOKEN) {
23253                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23254 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
23255 +                       struct sysinfo si;
23256 +
23257 +                       vx_vsi_swapinfo(&si);
23258 +                       if (si.totalswap < (1 << 10))
23259 +                               return 0;
23260 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23261 +                               "hdv0", "partition", si.totalswap >> 10,
23262 +                               (si.totalswap - si.freeswap) >> 10, -1);
23263 +               }
23264                 return 0;
23265         }
23266  
23267 @@ -2589,6 +2600,8 @@ void si_swapinfo(struct sysinfo *val)
23268         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
23269         val->totalswap = total_swap_pages + nr_to_be_unused;
23270         spin_unlock(&swap_lock);
23271 +       if (vx_flags(VXF_VIRT_MEM, 0))
23272 +               vx_vsi_swapinfo(val);
23273  }
23274  
23275  /*
23276 diff -NurpP --minimal linux-3.13.10/net/bridge/br_multicast.c linux-3.13.10-vs2.3.6.11/net/bridge/br_multicast.c
23277 --- linux-3.13.10/net/bridge/br_multicast.c     2014-04-17 01:12:40.000000000 +0000
23278 +++ linux-3.13.10-vs2.3.6.11/net/bridge/br_multicast.c  2014-04-17 01:17:11.000000000 +0000
23279 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
23280         ip6h->hop_limit = 1;
23281         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23282         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23283 -                              &ip6h->saddr)) {
23284 +                              &ip6h->saddr, NULL)) {
23285                 kfree_skb(skb);
23286                 return NULL;
23287         }
23288 diff -NurpP --minimal linux-3.13.10/net/core/dev.c linux-3.13.10-vs2.3.6.11/net/core/dev.c
23289 --- linux-3.13.10/net/core/dev.c        2014-04-17 01:12:41.000000000 +0000
23290 +++ linux-3.13.10-vs2.3.6.11/net/core/dev.c     2014-03-12 15:51:08.000000000 +0000
23291 @@ -122,6 +122,7 @@
23292  #include <linux/in.h>
23293  #include <linux/jhash.h>
23294  #include <linux/random.h>
23295 +#include <linux/vs_inet.h>
23296  #include <trace/events/napi.h>
23297  #include <trace/events/net.h>
23298  #include <trace/events/skb.h>
23299 @@ -669,7 +670,8 @@ struct net_device *__dev_get_by_name(str
23300         struct hlist_head *head = dev_name_hash(net, name);
23301  
23302         hlist_for_each_entry(dev, head, name_hlist)
23303 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23304 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23305 +                   nx_dev_visible(current_nx_info(), dev))
23306                         return dev;
23307  
23308         return NULL;
23309 @@ -694,7 +696,8 @@ struct net_device *dev_get_by_name_rcu(s
23310         struct hlist_head *head = dev_name_hash(net, name);
23311  
23312         hlist_for_each_entry_rcu(dev, head, name_hlist)
23313 -               if (!strncmp(dev->name, name, IFNAMSIZ))
23314 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
23315 +                   nx_dev_visible(current_nx_info(), dev))
23316                         return dev;
23317  
23318         return NULL;
23319 @@ -744,7 +747,8 @@ struct net_device *__dev_get_by_index(st
23320         struct hlist_head *head = dev_index_hash(net, ifindex);
23321  
23322         hlist_for_each_entry(dev, head, index_hlist)
23323 -               if (dev->ifindex == ifindex)
23324 +               if ((dev->ifindex == ifindex) &&
23325 +                   nx_dev_visible(current_nx_info(), dev))
23326                         return dev;
23327  
23328         return NULL;
23329 @@ -762,7 +766,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
23330   *     about locking. The caller must hold RCU lock.
23331   */
23332  
23333 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23334 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
23335  {
23336         struct net_device *dev;
23337         struct hlist_head *head = dev_index_hash(net, ifindex);
23338 @@ -773,6 +777,16 @@ struct net_device *dev_get_by_index_rcu(
23339  
23340         return NULL;
23341  }
23342 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
23343 +
23344 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23345 +{
23346 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
23347 +
23348 +       if (nx_dev_visible(current_nx_info(), dev))
23349 +               return dev;
23350 +       return NULL;
23351 +}
23352  EXPORT_SYMBOL(dev_get_by_index_rcu);
23353  
23354  
23355 @@ -855,7 +869,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
23356  
23357         for_each_netdev_rcu(net, dev)
23358                 if (dev->type == type &&
23359 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
23360 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
23361 +                   nx_dev_visible(current_nx_info(), dev))
23362                         return dev;
23363  
23364         return NULL;
23365 @@ -867,9 +882,11 @@ struct net_device *__dev_getfirstbyhwtyp
23366         struct net_device *dev;
23367  
23368         ASSERT_RTNL();
23369 -       for_each_netdev(net, dev)
23370 -               if (dev->type == type)
23371 +       for_each_netdev(net, dev) {
23372 +               if ((dev->type == type) &&
23373 +                   nx_dev_visible(current_nx_info(), dev))
23374                         return dev;
23375 +       }
23376  
23377         return NULL;
23378  }
23379 @@ -881,7 +898,8 @@ struct net_device *dev_getfirstbyhwtype(
23380  
23381         rcu_read_lock();
23382         for_each_netdev_rcu(net, dev)
23383 -               if (dev->type == type) {
23384 +               if ((dev->type == type) &&
23385 +                   nx_dev_visible(current_nx_info(), dev)) {
23386                         dev_hold(dev);
23387                         ret = dev;
23388                         break;
23389 @@ -909,7 +927,8 @@ struct net_device *dev_get_by_flags_rcu(
23390  
23391         ret = NULL;
23392         for_each_netdev_rcu(net, dev) {
23393 -               if (((dev->flags ^ if_flags) & mask) == 0) {
23394 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
23395 +                       nx_dev_visible(current_nx_info(), dev)) {
23396                         ret = dev;
23397                         break;
23398                 }
23399 @@ -987,6 +1006,8 @@ static int __dev_alloc_name(struct net *
23400                                 continue;
23401                         if (i < 0 || i >= max_netdevices)
23402                                 continue;
23403 +                       if (!nx_dev_visible(current_nx_info(), d))
23404 +                               continue;
23405  
23406                         /*  avoid cases where sscanf is not exact inverse of printf */
23407                         snprintf(buf, IFNAMSIZ, name, i);
23408 diff -NurpP --minimal linux-3.13.10/net/core/net-procfs.c linux-3.13.10-vs2.3.6.11/net/core/net-procfs.c
23409 --- linux-3.13.10/net/core/net-procfs.c 2013-11-25 15:45:09.000000000 +0000
23410 +++ linux-3.13.10-vs2.3.6.11/net/core/net-procfs.c      2014-01-31 20:38:04.000000000 +0000
23411 @@ -1,6 +1,7 @@
23412  #include <linux/netdevice.h>
23413  #include <linux/proc_fs.h>
23414  #include <linux/seq_file.h>
23415 +#include <linux/vs_inet.h>
23416  #include <net/wext.h>
23417  
23418  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
23419 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
23420  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
23421  {
23422         struct rtnl_link_stats64 temp;
23423 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
23424 +       const struct rtnl_link_stats64 *stats;
23425 +
23426 +       /* device visible inside network context? */
23427 +       if (!nx_dev_visible(current_nx_info(), dev))
23428 +               return;
23429  
23430 +       stats = dev_get_stats(dev, &temp);
23431         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
23432                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
23433                    dev->name, stats->rx_bytes, stats->rx_packets,
23434 diff -NurpP --minimal linux-3.13.10/net/core/rtnetlink.c linux-3.13.10-vs2.3.6.11/net/core/rtnetlink.c
23435 --- linux-3.13.10/net/core/rtnetlink.c  2014-04-17 01:12:41.000000000 +0000
23436 +++ linux-3.13.10-vs2.3.6.11/net/core/rtnetlink.c       2014-04-17 01:17:11.000000000 +0000
23437 @@ -1090,6 +1090,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
23438                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
23439                         if (idx < s_idx)
23440                                 goto cont;
23441 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
23442 +                               continue;
23443                         err = rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
23444                                                NETLINK_CB(cb->skb).portid,
23445                                                cb->nlh->nlmsg_seq, 0,
23446 @@ -1992,6 +1994,9 @@ void rtmsg_ifinfo(int type, struct net_d
23447         int err = -ENOBUFS;
23448         size_t if_info_size;
23449  
23450 +       if (!nx_dev_visible(current_nx_info(), dev))
23451 +               return;
23452 +
23453         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), flags);
23454         if (skb == NULL)
23455                 goto errout;
23456 diff -NurpP --minimal linux-3.13.10/net/core/sock.c linux-3.13.10-vs2.3.6.11/net/core/sock.c
23457 --- linux-3.13.10/net/core/sock.c       2014-04-17 01:12:41.000000000 +0000
23458 +++ linux-3.13.10-vs2.3.6.11/net/core/sock.c    2014-04-17 01:17:11.000000000 +0000
23459 @@ -133,6 +133,10 @@
23460  #include <net/netprio_cgroup.h>
23461  
23462  #include <linux/filter.h>
23463 +#include <linux/vs_socket.h>
23464 +#include <linux/vs_limit.h>
23465 +#include <linux/vs_context.h>
23466 +#include <linux/vs_network.h>
23467  
23468  #include <trace/events/sock.h>
23469  
23470 @@ -1279,6 +1283,8 @@ static struct sock *sk_prot_alloc(struct
23471                         goto out_free_sec;
23472                 sk_tx_queue_clear(sk);
23473         }
23474 +               sock_vx_init(sk);
23475 +               sock_nx_init(sk);
23476  
23477         return sk;
23478  
23479 @@ -1387,6 +1393,11 @@ static void __sk_free(struct sock *sk)
23480                 put_cred(sk->sk_peer_cred);
23481         put_pid(sk->sk_peer_pid);
23482         put_net(sock_net(sk));
23483 +       vx_sock_dec(sk);
23484 +       clr_vx_info(&sk->sk_vx_info);
23485 +       sk->sk_xid = -1;
23486 +       clr_nx_info(&sk->sk_nx_info);
23487 +       sk->sk_nid = -1;
23488         sk_prot_free(sk->sk_prot_creator, sk);
23489  }
23490  
23491 @@ -1447,6 +1458,8 @@ struct sock *sk_clone_lock(const struct
23492  
23493                 /* SANITY */
23494                 get_net(sock_net(newsk));
23495 +               sock_vx_init(newsk);
23496 +               sock_nx_init(newsk);
23497                 sk_node_init(&newsk->sk_node);
23498                 sock_lock_init(newsk);
23499                 bh_lock_sock(newsk);
23500 @@ -1503,6 +1516,12 @@ struct sock *sk_clone_lock(const struct
23501                 smp_wmb();
23502                 atomic_set(&newsk->sk_refcnt, 2);
23503  
23504 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
23505 +               newsk->sk_xid = sk->sk_xid;
23506 +               vx_sock_inc(newsk);
23507 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
23508 +               newsk->sk_nid = sk->sk_nid;
23509 +
23510                 /*
23511                  * Increment the counter in the same struct proto as the master
23512                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
23513 @@ -2340,6 +2359,12 @@ void sock_init_data(struct socket *sock,
23514  
23515         sk->sk_stamp = ktime_set(-1L, 0);
23516  
23517 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
23518 +       sk->sk_xid = vx_current_xid();
23519 +       vx_sock_inc(sk);
23520 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
23521 +       sk->sk_nid = nx_current_nid();
23522 +
23523  #ifdef CONFIG_NET_RX_BUSY_POLL
23524         sk->sk_napi_id          =       0;
23525         sk->sk_ll_usec          =       sysctl_net_busy_read;
23526 diff -NurpP --minimal linux-3.13.10/net/ipv4/af_inet.c linux-3.13.10-vs2.3.6.11/net/ipv4/af_inet.c
23527 --- linux-3.13.10/net/ipv4/af_inet.c    2014-04-17 01:12:41.000000000 +0000
23528 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/af_inet.c 2014-04-17 01:17:11.000000000 +0000
23529 @@ -118,6 +118,7 @@
23530  #ifdef CONFIG_IP_MROUTE
23531  #include <linux/mroute.h>
23532  #endif
23533 +#include <linux/vs_limit.h>
23534  
23535  
23536  /* The inetsw table contains everything that inet_create needs to
23537 @@ -309,10 +310,13 @@ lookup_protocol:
23538         }
23539  
23540         err = -EPERM;
23541 +       if ((protocol == IPPROTO_ICMP) &&
23542 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
23543 +               goto override;
23544         if (sock->type == SOCK_RAW && !kern &&
23545             !ns_capable(net->user_ns, CAP_NET_RAW))
23546                 goto out_rcu_unlock;
23547 -
23548 +override:
23549         sock->ops = answer->ops;
23550         answer_prot = answer->prot;
23551         answer_no_check = answer->no_check;
23552 @@ -433,6 +437,7 @@ int inet_bind(struct socket *sock, struc
23553         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
23554         struct sock *sk = sock->sk;
23555         struct inet_sock *inet = inet_sk(sk);
23556 +       struct nx_v4_sock_addr nsa;
23557         struct net *net = sock_net(sk);
23558         unsigned short snum;
23559         int chk_addr_ret;
23560 @@ -457,7 +462,11 @@ int inet_bind(struct socket *sock, struc
23561                         goto out;
23562         }
23563  
23564 -       chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
23565 +       err = v4_map_sock_addr(inet, addr, &nsa);
23566 +       if (err)
23567 +               goto out;
23568 +
23569 +       chk_addr_ret = inet_addr_type(net, nsa.saddr);
23570  
23571         /* Not specified by any standard per-se, however it breaks too
23572          * many applications when removed.  It is unfortunate since
23573 @@ -469,7 +478,7 @@ int inet_bind(struct socket *sock, struc
23574         err = -EADDRNOTAVAIL;
23575         if (!sysctl_ip_nonlocal_bind &&
23576             !(inet->freebind || inet->transparent) &&
23577 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
23578 +           nsa.saddr != htonl(INADDR_ANY) &&
23579             chk_addr_ret != RTN_LOCAL &&
23580             chk_addr_ret != RTN_MULTICAST &&
23581             chk_addr_ret != RTN_BROADCAST)
23582 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
23583         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
23584                 goto out_release_sock;
23585  
23586 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23587 +       v4_set_sock_addr(inet, &nsa);
23588         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23589                 inet->inet_saddr = 0;  /* Use device */
23590  
23591 @@ -714,11 +723,13 @@ int inet_getname(struct socket *sock, st
23592                      peer == 1))
23593                         return -ENOTCONN;
23594                 sin->sin_port = inet->inet_dport;
23595 -               sin->sin_addr.s_addr = inet->inet_daddr;
23596 +               sin->sin_addr.s_addr =
23597 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
23598         } else {
23599                 __be32 addr = inet->inet_rcv_saddr;
23600                 if (!addr)
23601                         addr = inet->inet_saddr;
23602 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
23603                 sin->sin_port = inet->inet_sport;
23604                 sin->sin_addr.s_addr = addr;
23605         }
23606 diff -NurpP --minimal linux-3.13.10/net/ipv4/arp.c linux-3.13.10-vs2.3.6.11/net/ipv4/arp.c
23607 --- linux-3.13.10/net/ipv4/arp.c        2013-11-25 15:47:06.000000000 +0000
23608 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/arp.c     2014-01-31 20:38:04.000000000 +0000
23609 @@ -1336,6 +1336,7 @@ static void arp_format_neigh_entry(struc
23610         struct net_device *dev = n->dev;
23611         int hatype = dev->type;
23612  
23613 +       /* FIXME: check for network context */
23614         read_lock(&n->lock);
23615         /* Convert hardware address to XX:XX:XX:XX ... form. */
23616  #if IS_ENABLED(CONFIG_AX25)
23617 @@ -1367,6 +1368,7 @@ static void arp_format_pneigh_entry(stru
23618         int hatype = dev ? dev->type : 0;
23619         char tbuf[16];
23620  
23621 +       /* FIXME: check for network context */
23622         sprintf(tbuf, "%pI4", n->key);
23623         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
23624                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
23625 diff -NurpP --minimal linux-3.13.10/net/ipv4/devinet.c linux-3.13.10-vs2.3.6.11/net/ipv4/devinet.c
23626 --- linux-3.13.10/net/ipv4/devinet.c    2014-04-17 01:12:41.000000000 +0000
23627 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/devinet.c 2014-03-12 15:51:08.000000000 +0000
23628 @@ -527,6 +527,7 @@ struct in_device *inetdev_by_index(struc
23629  }
23630  EXPORT_SYMBOL(inetdev_by_index);
23631  
23632 +
23633  /* Called only from RTNL semaphored context. No locks. */
23634  
23635  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
23636 @@ -947,6 +948,8 @@ int devinet_ioctl(struct net *net, unsig
23637  
23638         in_dev = __in_dev_get_rtnl(dev);
23639         if (in_dev) {
23640 +               struct nx_info *nxi = current_nx_info();
23641 +
23642                 if (tryaddrmatch) {
23643                         /* Matthias Andree */
23644                         /* compare label and address (4.4BSD style) */
23645 @@ -955,6 +958,8 @@ int devinet_ioctl(struct net *net, unsig
23646                            This is checked above. */
23647                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23648                              ifap = &ifa->ifa_next) {
23649 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23650 +                                       continue;
23651                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
23652                                     sin_orig.sin_addr.s_addr ==
23653                                                         ifa->ifa_local) {
23654 @@ -967,9 +972,12 @@ int devinet_ioctl(struct net *net, unsig
23655                    comparing just the label */
23656                 if (!ifa) {
23657                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23658 -                            ifap = &ifa->ifa_next)
23659 +                            ifap = &ifa->ifa_next) {
23660 +                               if (!nx_v4_ifa_visible(nxi, ifa))
23661 +                                       continue;
23662                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
23663                                         break;
23664 +                       }
23665                 }
23666         }
23667  
23668 @@ -1123,6 +1131,8 @@ static int inet_gifconf(struct net_devic
23669                 goto out;
23670  
23671         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
23672 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
23673 +                       continue;
23674                 if (!buf) {
23675                         done += sizeof(ifr);
23676                         continue;
23677 @@ -1524,6 +1534,7 @@ static int inet_dump_ifaddr(struct sk_bu
23678         struct net_device *dev;
23679         struct in_device *in_dev;
23680         struct in_ifaddr *ifa;
23681 +       struct sock *sk = skb->sk;
23682         struct hlist_head *head;
23683  
23684         s_h = cb->args[0];
23685 @@ -1547,6 +1558,8 @@ static int inet_dump_ifaddr(struct sk_bu
23686  
23687                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
23688                              ifa = ifa->ifa_next, ip_idx++) {
23689 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
23690 +                               continue;
23691                                 if (ip_idx < s_ip_idx)
23692                                         continue;
23693                                 if (inet_fill_ifaddr(skb, ifa,
23694 diff -NurpP --minimal linux-3.13.10/net/ipv4/fib_trie.c linux-3.13.10-vs2.3.6.11/net/ipv4/fib_trie.c
23695 --- linux-3.13.10/net/ipv4/fib_trie.c   2014-01-22 20:39:15.000000000 +0000
23696 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/fib_trie.c        2014-01-31 20:38:04.000000000 +0000
23697 @@ -2530,6 +2530,7 @@ static int fib_route_seq_show(struct seq
23698  
23699                         seq_setwidth(seq, 127);
23700  
23701 +                       /* FIXME: check for network context? */
23702                         if (fi)
23703                                 seq_printf(seq,
23704                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
23705 diff -NurpP --minimal linux-3.13.10/net/ipv4/inet_connection_sock.c linux-3.13.10-vs2.3.6.11/net/ipv4/inet_connection_sock.c
23706 --- linux-3.13.10/net/ipv4/inet_connection_sock.c       2014-01-22 20:39:15.000000000 +0000
23707 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_connection_sock.c    2014-02-01 00:33:11.000000000 +0000
23708 @@ -45,6 +45,37 @@ void inet_get_local_port_range(struct ne
23709  }
23710  EXPORT_SYMBOL(inet_get_local_port_range);
23711  
23712 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
23713 +{
23714 +       __be32  sk1_rcv_saddr = sk1->sk_rcv_saddr,
23715 +               sk2_rcv_saddr = sk2->sk_rcv_saddr;
23716 +
23717 +       if (inet_v6_ipv6only(sk2))
23718 +               return 0;
23719 +
23720 +       if (sk1_rcv_saddr &&
23721 +           sk2_rcv_saddr &&
23722 +           sk1_rcv_saddr == sk2_rcv_saddr)
23723 +               return 1;
23724 +
23725 +       if (sk1_rcv_saddr &&
23726 +           !sk2_rcv_saddr &&
23727 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
23728 +               return 1;
23729 +
23730 +       if (sk2_rcv_saddr &&
23731 +           !sk1_rcv_saddr &&
23732 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
23733 +               return 1;
23734 +
23735 +       if (!sk1_rcv_saddr &&
23736 +           !sk2_rcv_saddr &&
23737 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
23738 +               return 1;
23739 +
23740 +       return 0;
23741 +}
23742 +
23743  int inet_csk_bind_conflict(const struct sock *sk,
23744                            const struct inet_bind_bucket *tb, bool relax)
23745  {
23746 @@ -72,15 +103,13 @@ int inet_csk_bind_conflict(const struct
23747                             (sk2->sk_state != TCP_TIME_WAIT &&
23748                              !uid_eq(uid, sock_i_uid(sk2))))) {
23749  
23750 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23751 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23752 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23753                                         break;
23754                         }
23755                         if (!relax && reuse && sk2->sk_reuse &&
23756                             sk2->sk_state != TCP_LISTEN) {
23757  
23758 -                               if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23759 -                                   sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23760 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
23761                                         break;
23762                         }
23763                 }
23764 diff -NurpP --minimal linux-3.13.10/net/ipv4/inet_diag.c linux-3.13.10-vs2.3.6.11/net/ipv4/inet_diag.c
23765 --- linux-3.13.10/net/ipv4/inet_diag.c  2014-02-01 02:17:51.000000000 +0000
23766 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_diag.c       2014-02-01 02:32:22.000000000 +0000
23767 @@ -31,6 +31,8 @@
23768  
23769  #include <linux/inet.h>
23770  #include <linux/stddef.h>
23771 +#include <linux/vs_network.h>
23772 +#include <linux/vs_inet.h>
23773  
23774  #include <linux/inet_diag.h>
23775  #include <linux/sock_diag.h>
23776 @@ -110,8 +112,10 @@ int inet_sk_diag_fill(struct sock *sk, s
23777         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23778         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23779  
23780 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
23781 -       r->id.idiag_dst[0] = inet->inet_daddr;
23782 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
23783 +               inet->inet_rcv_saddr);
23784 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
23785 +               inet->inet_daddr);
23786  
23787         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
23788                 goto errout;
23789 @@ -254,8 +258,8 @@ static int inet_twsk_diag_fill(struct in
23790         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23791         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23792  
23793 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
23794 -       r->id.idiag_dst[0]    = tw->tw_daddr;
23795 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
23796 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
23797  
23798         r->idiag_state        = tw->tw_substate;
23799         r->idiag_timer        = 3;
23800 @@ -298,12 +302,14 @@ int inet_diag_dump_one_icsk(struct inet_
23801  
23802         err = -EINVAL;
23803         if (req->sdiag_family == AF_INET) {
23804 +               /* TODO: lback */
23805                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
23806                                  req->id.idiag_dport, req->id.idiag_src[0],
23807                                  req->id.idiag_sport, req->id.idiag_if);
23808         }
23809  #if IS_ENABLED(CONFIG_IPV6)
23810         else if (req->sdiag_family == AF_INET6) {
23811 +               /* TODO: lback */
23812                 sk = inet6_lookup(net, hashinfo,
23813                                   (struct in6_addr *)req->id.idiag_dst,
23814                                   req->id.idiag_dport,
23815 @@ -501,6 +507,7 @@ int inet_diag_bc_sk(const struct nlattr
23816         } else
23817  #endif
23818         {
23819 +                       /* TODO: lback */
23820                 entry.saddr = &inet->inet_rcv_saddr;
23821                 entry.daddr = &inet->inet_daddr;
23822         }
23823 @@ -659,6 +666,7 @@ static int inet_twsk_diag_dump(struct so
23824                 } else
23825  #endif
23826                 {
23827 +                       /* TODO: lback */
23828                         entry.saddr = &tw->tw_rcv_saddr;
23829                         entry.daddr = &tw->tw_daddr;
23830                 }
23831 @@ -741,8 +749,8 @@ static int inet_diag_fill_req(struct sk_
23832         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23833         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23834  
23835 -       r->id.idiag_src[0] = ireq->ir_loc_addr;
23836 -       r->id.idiag_dst[0] = ireq->ir_rmt_addr;
23837 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_loc_addr);
23838 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_rmt_addr);
23839  
23840         r->idiag_expires = jiffies_to_msecs(tmo);
23841         r->idiag_rqueue = 0;
23842 @@ -806,6 +814,7 @@ static int inet_diag_dump_reqs(struct sk
23843                             r->id.idiag_dport)
23844                                 continue;
23845  
23846 +                       /* TODO: lback */
23847                         if (bc) {
23848                                 inet_diag_req_addrs(sk, req, &entry);
23849                                 entry.dport = ntohs(ireq->ir_rmt_port);
23850 @@ -862,6 +871,8 @@ void inet_diag_dump_icsk(struct inet_has
23851                                 if (!net_eq(sock_net(sk), net))
23852                                         continue;
23853  
23854 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23855 +                                       continue;
23856                                 if (num < s_num) {
23857                                         num++;
23858                                         continue;
23859 @@ -934,6 +945,8 @@ skip_listen_ht:
23860  
23861                         if (!net_eq(sock_net(sk), net))
23862                                 continue;
23863 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23864 +                               continue;
23865                         if (num < s_num)
23866                                 goto next_normal;
23867                         state = (sk->sk_state == TCP_TIME_WAIT) ?
23868 diff -NurpP --minimal linux-3.13.10/net/ipv4/inet_hashtables.c linux-3.13.10-vs2.3.6.11/net/ipv4/inet_hashtables.c
23869 --- linux-3.13.10/net/ipv4/inet_hashtables.c    2014-01-22 20:39:15.000000000 +0000
23870 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_hashtables.c 2014-01-31 20:38:04.000000000 +0000
23871 @@ -22,6 +22,7 @@
23872  #include <net/inet_connection_sock.h>
23873  #include <net/inet_hashtables.h>
23874  #include <net/secure_seq.h>
23875 +#include <net/route.h>
23876  #include <net/ip.h>
23877  
23878  static unsigned int inet_ehashfn(struct net *net, const __be32 laddr,
23879 @@ -181,6 +182,11 @@ static inline int compute_score(struct s
23880                         if (rcv_saddr != daddr)
23881                                 return -1;
23882                         score += 4;
23883 +               } else {
23884 +                       /* block non nx_info ips */
23885 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
23886 +                               daddr, NXA_MASK_BIND))
23887 +                               return -1;
23888                 }
23889                 if (sk->sk_bound_dev_if) {
23890                         if (sk->sk_bound_dev_if != dif)
23891 @@ -198,7 +204,6 @@ static inline int compute_score(struct s
23892   * wildcarded during the search since they can never be otherwise.
23893   */
23894  
23895 -
23896  struct sock *__inet_lookup_listener(struct net *net,
23897                                     struct inet_hashinfo *hashinfo,
23898                                     const __be32 saddr, __be16 sport,
23899 @@ -234,6 +239,7 @@ begin:
23900                         phash = next_pseudo_random32(phash);
23901                 }
23902         }
23903 +
23904         /*
23905          * if the nulls value we got at the end of this lookup is
23906          * not the expected one, we must restart lookup.
23907 diff -NurpP --minimal linux-3.13.10/net/ipv4/netfilter.c linux-3.13.10-vs2.3.6.11/net/ipv4/netfilter.c
23908 --- linux-3.13.10/net/ipv4/netfilter.c  2013-07-14 17:01:37.000000000 +0000
23909 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/netfilter.c       2014-01-31 20:38:04.000000000 +0000
23910 @@ -11,7 +11,7 @@
23911  #include <linux/skbuff.h>
23912  #include <linux/gfp.h>
23913  #include <linux/export.h>
23914 -#include <net/route.h>
23915 +// #include <net/route.h>
23916  #include <net/xfrm.h>
23917  #include <net/ip.h>
23918  #include <net/netfilter/nf_queue.h>
23919 diff -NurpP --minimal linux-3.13.10/net/ipv4/raw.c linux-3.13.10-vs2.3.6.11/net/ipv4/raw.c
23920 --- linux-3.13.10/net/ipv4/raw.c        2014-01-22 20:39:15.000000000 +0000
23921 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/raw.c     2014-01-31 20:38:04.000000000 +0000
23922 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
23923  
23924                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
23925                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
23926 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
23927 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
23928                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23929                         goto found; /* gotcha */
23930         }
23931 @@ -397,6 +397,12 @@ static int raw_send_hdrinc(struct sock *
23932                 icmp_out_count(net, ((struct icmphdr *)
23933                         skb_transport_header(skb))->type);
23934  
23935 +       err = -EPERM;
23936 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
23937 +               sk->sk_nx_info &&
23938 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
23939 +               goto error_free;
23940 +
23941         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
23942                       rt->dst.dev, dst_output);
23943         if (err > 0)
23944 @@ -585,6 +591,16 @@ static int raw_sendmsg(struct kiocb *ioc
23945                         goto done;
23946         }
23947  
23948 +       if (sk->sk_nx_info) {
23949 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
23950 +               if (IS_ERR(rt)) {
23951 +                       err = PTR_ERR(rt);
23952 +                       rt = NULL;
23953 +                       goto done;
23954 +               }
23955 +               ip_rt_put(rt);
23956 +       }
23957 +
23958         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
23959         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
23960         if (IS_ERR(rt)) {
23961 @@ -661,17 +677,19 @@ static int raw_bind(struct sock *sk, str
23962  {
23963         struct inet_sock *inet = inet_sk(sk);
23964         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
23965 +       struct nx_v4_sock_addr nsa = { 0 };
23966         int ret = -EINVAL;
23967         int chk_addr_ret;
23968  
23969         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
23970                 goto out;
23971 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
23972 +       v4_map_sock_addr(inet, addr, &nsa);
23973 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
23974         ret = -EADDRNOTAVAIL;
23975 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
23976 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
23977             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
23978                 goto out;
23979 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23980 +       v4_set_sock_addr(inet, &nsa);
23981         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23982                 inet->inet_saddr = 0;  /* Use device */
23983         sk_dst_reset(sk);
23984 @@ -720,7 +738,8 @@ static int raw_recvmsg(struct kiocb *ioc
23985         /* Copy the address. */
23986         if (sin) {
23987                 sin->sin_family = AF_INET;
23988 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
23989 +               sin->sin_addr.s_addr =
23990 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
23991                 sin->sin_port = 0;
23992                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
23993                 *addr_len = sizeof(*sin);
23994 @@ -916,7 +935,8 @@ static struct sock *raw_get_first(struct
23995         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
23996                         ++state->bucket) {
23997                 sk_for_each(sk, &state->h->ht[state->bucket])
23998 -                       if (sock_net(sk) == seq_file_net(seq))
23999 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24000 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24001                                 goto found;
24002         }
24003         sk = NULL;
24004 @@ -932,7 +952,8 @@ static struct sock *raw_get_next(struct
24005                 sk = sk_next(sk);
24006  try_again:
24007                 ;
24008 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24009 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24010 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24011  
24012         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24013                 sk = sk_head(&state->h->ht[state->bucket]);
24014 diff -NurpP --minimal linux-3.13.10/net/ipv4/route.c linux-3.13.10-vs2.3.6.11/net/ipv4/route.c
24015 --- linux-3.13.10/net/ipv4/route.c      2014-04-17 01:12:41.000000000 +0000
24016 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/route.c   2014-03-12 15:51:08.000000000 +0000
24017 @@ -2063,7 +2063,7 @@ struct rtable *__ip_route_output_key(str
24018  
24019  
24020         if (fl4->flowi4_oif) {
24021 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24022 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24023                 rth = ERR_PTR(-ENODEV);
24024                 if (dev_out == NULL)
24025                         goto out;
24026 diff -NurpP --minimal linux-3.13.10/net/ipv4/tcp.c linux-3.13.10-vs2.3.6.11/net/ipv4/tcp.c
24027 --- linux-3.13.10/net/ipv4/tcp.c        2014-04-17 01:12:41.000000000 +0000
24028 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp.c     2014-04-17 01:17:11.000000000 +0000
24029 @@ -268,6 +268,7 @@
24030  #include <linux/crypto.h>
24031  #include <linux/time.h>
24032  #include <linux/slab.h>
24033 +#include <linux/in.h>
24034  
24035  #include <net/icmp.h>
24036  #include <net/inet_common.h>
24037 diff -NurpP --minimal linux-3.13.10/net/ipv4/tcp_ipv4.c linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_ipv4.c
24038 --- linux-3.13.10/net/ipv4/tcp_ipv4.c   2014-04-17 01:12:41.000000000 +0000
24039 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_ipv4.c        2014-04-17 01:17:11.000000000 +0000
24040 @@ -2227,6 +2227,12 @@ static void *listening_get_next(struct s
24041                 req = req->dl_next;
24042                 while (1) {
24043                         while (req) {
24044 +                               vxdprintk(VXD_CBIT(net, 6),
24045 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24046 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24047 +                               if (req->sk &&
24048 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24049 +                                       continue;
24050                                 if (req->rsk_ops->family == st->family) {
24051                                         cur = req;
24052                                         goto out;
24053 @@ -2251,6 +2257,10 @@ get_req:
24054         }
24055  get_sk:
24056         sk_nulls_for_each_from(sk, node) {
24057 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24058 +                       sk, sk->sk_nid, nx_current_nid());
24059 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24060 +                       continue;
24061                 if (!net_eq(sock_net(sk), net))
24062                         continue;
24063                 if (sk->sk_family == st->family) {
24064 @@ -2325,6 +2335,11 @@ static void *established_get_first(struc
24065  
24066                 spin_lock_bh(lock);
24067                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24068 +                       vxdprintk(VXD_CBIT(net, 6),
24069 +                               "sk,egf: %p [#%d] (from %d)",
24070 +                               sk, sk->sk_nid, nx_current_nid());
24071 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24072 +                               continue;
24073                         if (sk->sk_family != st->family ||
24074                             !net_eq(sock_net(sk), net)) {
24075                                 continue;
24076 @@ -2351,6 +2366,11 @@ static void *established_get_next(struct
24077         sk = sk_nulls_next(sk);
24078  
24079         sk_nulls_for_each_from(sk, node) {
24080 +               vxdprintk(VXD_CBIT(net, 6),
24081 +                       "sk,egn: %p [#%d] (from %d)",
24082 +                       sk, sk->sk_nid, nx_current_nid());
24083 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24084 +                       continue;
24085                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24086                         return sk;
24087         }
24088 @@ -2549,9 +2569,9 @@ static void get_openreq4(const struct so
24089         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24090                 " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d %pK",
24091                 i,
24092 -               ireq->ir_loc_addr,
24093 +               nx_map_sock_lback(current_nx_info(), ireq->ir_loc_addr),
24094                 ntohs(inet_sk(sk)->inet_sport),
24095 -               ireq->ir_rmt_addr,
24096 +               nx_map_sock_lback(current_nx_info(), ireq->ir_rmt_addr),
24097                 ntohs(ireq->ir_rmt_port),
24098                 TCP_SYN_RECV,
24099                 0, 0, /* could print option size, but that is af dependent. */
24100 @@ -2573,8 +2593,8 @@ static void get_tcp4_sock(struct sock *s
24101         const struct inet_connection_sock *icsk = inet_csk(sk);
24102         const struct inet_sock *inet = inet_sk(sk);
24103         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24104 -       __be32 dest = inet->inet_daddr;
24105 -       __be32 src = inet->inet_rcv_saddr;
24106 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24107 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24108         __u16 destp = ntohs(inet->inet_dport);
24109         __u16 srcp = ntohs(inet->inet_sport);
24110         int rx_queue;
24111 @@ -2631,8 +2651,8 @@ static void get_timewait4_sock(const str
24112         __u16 destp, srcp;
24113         s32 delta = tw->tw_ttd - inet_tw_time_stamp();
24114  
24115 -       dest  = tw->tw_daddr;
24116 -       src   = tw->tw_rcv_saddr;
24117 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24118 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24119         destp = ntohs(tw->tw_dport);
24120         srcp  = ntohs(tw->tw_sport);
24121  
24122 diff -NurpP --minimal linux-3.13.10/net/ipv4/tcp_minisocks.c linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_minisocks.c
24123 --- linux-3.13.10/net/ipv4/tcp_minisocks.c      2014-01-22 20:39:15.000000000 +0000
24124 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_minisocks.c   2014-01-31 20:38:04.000000000 +0000
24125 @@ -23,6 +23,9 @@
24126  #include <linux/slab.h>
24127  #include <linux/sysctl.h>
24128  #include <linux/workqueue.h>
24129 +#include <linux/vs_limit.h>
24130 +#include <linux/vs_socket.h>
24131 +#include <linux/vs_context.h>
24132  #include <net/tcp.h>
24133  #include <net/inet_common.h>
24134  #include <net/xfrm.h>
24135 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int
24136                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24137                 tcptw->tw_ts_offset     = tp->tsoffset;
24138  
24139 +               tw->tw_xid              = sk->sk_xid;
24140 +               tw->tw_vx_info          = NULL;
24141 +               tw->tw_nid              = sk->sk_nid;
24142 +               tw->tw_nx_info          = NULL;
24143 +
24144  #if IS_ENABLED(CONFIG_IPV6)
24145                 if (tw->tw_family == PF_INET6) {
24146                         struct ipv6_pinfo *np = inet6_sk(sk);
24147 diff -NurpP --minimal linux-3.13.10/net/ipv4/udp.c linux-3.13.10-vs2.3.6.11/net/ipv4/udp.c
24148 --- linux-3.13.10/net/ipv4/udp.c        2014-01-22 20:39:15.000000000 +0000
24149 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/udp.c     2014-01-31 22:20:27.000000000 +0000
24150 @@ -308,14 +308,7 @@ fail:
24151  }
24152  EXPORT_SYMBOL(udp_lib_get_port);
24153  
24154 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24155 -{
24156 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24157 -
24158 -       return  (!ipv6_only_sock(sk2)  &&
24159 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24160 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24161 -}
24162 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24163  
24164  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24165                                        unsigned int port)
24166 @@ -350,6 +343,11 @@ static inline int compute_score(struct s
24167                         if (inet->inet_rcv_saddr != daddr)
24168                                 return -1;
24169                         score += 4;
24170 +               } else {
24171 +                       /* block non nx_info ips */
24172 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24173 +                               daddr, NXA_MASK_BIND))
24174 +                               return -1;
24175                 }
24176                 if (inet->inet_daddr) {
24177                         if (inet->inet_daddr != saddr)
24178 @@ -472,6 +470,7 @@ begin:
24179         return result;
24180  }
24181  
24182 +
24183  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24184   * harder than this. -DaveM
24185   */
24186 @@ -518,6 +517,11 @@ begin:
24187         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24188                 score = compute_score(sk, net, saddr, hnum, sport,
24189                                       daddr, dport, dif);
24190 +               /* FIXME: disabled?
24191 +               if (score == 9) {
24192 +                       result = sk;
24193 +                       break;
24194 +               } else */
24195                 if (score > badness) {
24196                         result = sk;
24197                         badness = score;
24198 @@ -542,6 +546,7 @@ begin:
24199         if (get_nulls_value(node) != slot)
24200                 goto begin;
24201  
24202 +
24203         if (result) {
24204                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24205                         result = NULL;
24206 @@ -551,6 +556,7 @@ begin:
24207                         goto begin;
24208                 }
24209         }
24210 +
24211         rcu_read_unlock();
24212         return result;
24213  }
24214 @@ -585,7 +591,7 @@ static inline bool __udp_is_mcast_sock(s
24215             udp_sk(sk)->udp_port_hash != hnum ||
24216             (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24217             (inet->inet_dport != rmt_port && inet->inet_dport) ||
24218 -           (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||
24219 +           !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24220             ipv6_only_sock(sk) ||
24221             (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24222                 return false;
24223 @@ -989,6 +995,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24224                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24225                                    faddr, saddr, dport, inet->inet_sport);
24226  
24227 +               if (sk->sk_nx_info) {
24228 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24229 +                       if (IS_ERR(rt)) {
24230 +                               err = PTR_ERR(rt);
24231 +                               rt = NULL;
24232 +                               goto out;
24233 +                       }
24234 +                       ip_rt_put(rt);
24235 +               }
24236 +
24237                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24238                 rt = ip_route_output_flow(net, fl4, sk);
24239                 if (IS_ERR(rt)) {
24240 @@ -1293,7 +1309,8 @@ try_again:
24241         if (sin) {
24242                 sin->sin_family = AF_INET;
24243                 sin->sin_port = udp_hdr(skb)->source;
24244 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24245 +               sin->sin_addr.s_addr = nx_map_sock_lback(
24246 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24247                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24248                 *addr_len = sizeof(*sin);
24249         }
24250 @@ -2223,6 +2240,8 @@ static struct sock *udp_get_first(struct
24251                 sk_nulls_for_each(sk, node, &hslot->head) {
24252                         if (!net_eq(sock_net(sk), net))
24253                                 continue;
24254 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24255 +                               continue;
24256                         if (sk->sk_family == state->family)
24257                                 goto found;
24258                 }
24259 @@ -2240,7 +2259,9 @@ static struct sock *udp_get_next(struct
24260  
24261         do {
24262                 sk = sk_nulls_next(sk);
24263 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
24264 +       } while (sk && (!net_eq(sock_net(sk), net) ||
24265 +               sk->sk_family != state->family ||
24266 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24267  
24268         if (!sk) {
24269                 if (state->bucket <= state->udp_table->mask)
24270 @@ -2336,8 +2357,8 @@ static void udp4_format_sock(struct sock
24271                 int bucket)
24272  {
24273         struct inet_sock *inet = inet_sk(sp);
24274 -       __be32 dest = inet->inet_daddr;
24275 -       __be32 src  = inet->inet_rcv_saddr;
24276 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24277 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24278         __u16 destp       = ntohs(inet->inet_dport);
24279         __u16 srcp        = ntohs(inet->inet_sport);
24280  
24281 diff -NurpP --minimal linux-3.13.10/net/ipv6/Kconfig linux-3.13.10-vs2.3.6.11/net/ipv6/Kconfig
24282 --- linux-3.13.10/net/ipv6/Kconfig      2014-01-22 20:39:15.000000000 +0000
24283 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/Kconfig   2014-01-31 20:38:04.000000000 +0000
24284 @@ -4,8 +4,8 @@
24285  
24286  #   IPv6 as module will cause a CRASH if you try to unload it
24287  menuconfig IPV6
24288 -       tristate "The IPv6 protocol"
24289 -       default m
24290 +       bool "The IPv6 protocol"
24291 +       default n
24292         ---help---
24293           This is complemental support for the IP version 6.
24294           You will still be able to do traditional IPv4 networking as well.
24295 diff -NurpP --minimal linux-3.13.10/net/ipv6/addrconf.c linux-3.13.10-vs2.3.6.11/net/ipv6/addrconf.c
24296 --- linux-3.13.10/net/ipv6/addrconf.c   2014-04-17 01:12:41.000000000 +0000
24297 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/addrconf.c        2014-04-17 01:17:11.000000000 +0000
24298 @@ -90,6 +90,8 @@
24299  #include <linux/proc_fs.h>
24300  #include <linux/seq_file.h>
24301  #include <linux/export.h>
24302 +#include <linux/vs_network.h>
24303 +#include <linux/vs_inet6.h>
24304  
24305  /* Set to 3 to get tracing... */
24306  #define ACONF_DEBUG 2
24307 @@ -1284,7 +1286,7 @@ out:
24308  
24309  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
24310                        const struct in6_addr *daddr, unsigned int prefs,
24311 -                      struct in6_addr *saddr)
24312 +                      struct in6_addr *saddr, struct nx_info *nxi)
24313  {
24314         struct ipv6_saddr_score scores[2],
24315                                 *score = &scores[0], *hiscore = &scores[1];
24316 @@ -1356,6 +1358,8 @@ int ipv6_dev_get_saddr(struct net *net,
24317                                                dev->name);
24318                                 continue;
24319                         }
24320 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
24321 +                               continue;
24322  
24323                         score->rule = -1;
24324                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
24325 @@ -3371,7 +3375,10 @@ static void if6_seq_stop(struct seq_file
24326  static int if6_seq_show(struct seq_file *seq, void *v)
24327  {
24328         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
24329 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24330 +
24331 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
24332 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
24333 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24334                    &ifp->addr,
24335                    ifp->idev->dev->ifindex,
24336                    ifp->prefix_len,
24337 @@ -3892,6 +3899,11 @@ static int in6_dump_addrs(struct inet6_d
24338         struct ifacaddr6 *ifaca;
24339         int err = 1;
24340         int ip_idx = *p_ip_idx;
24341 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24342 +
24343 +       /* disable ipv6 on non v6 guests */
24344 +       if (nxi && !nx_info_has_v6(nxi))
24345 +               return skb->len;
24346  
24347         read_lock_bh(&idev->lock);
24348         switch (type) {
24349 @@ -3902,6 +3914,8 @@ static int in6_dump_addrs(struct inet6_d
24350                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
24351                         if (++ip_idx < s_ip_idx)
24352                                 continue;
24353 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
24354 +                                       continue;
24355                         err = inet6_fill_ifaddr(skb, ifa,
24356                                                 NETLINK_CB(cb->skb).portid,
24357                                                 cb->nlh->nlmsg_seq,
24358 @@ -3919,6 +3933,8 @@ static int in6_dump_addrs(struct inet6_d
24359                      ifmca = ifmca->next, ip_idx++) {
24360                         if (ip_idx < s_ip_idx)
24361                                 continue;
24362 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
24363 +                                       continue;
24364                         err = inet6_fill_ifmcaddr(skb, ifmca,
24365                                                   NETLINK_CB(cb->skb).portid,
24366                                                   cb->nlh->nlmsg_seq,
24367 @@ -3934,6 +3950,8 @@ static int in6_dump_addrs(struct inet6_d
24368                      ifaca = ifaca->aca_next, ip_idx++) {
24369                         if (ip_idx < s_ip_idx)
24370                                 continue;
24371 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
24372 +                                       continue;
24373                         err = inet6_fill_ifacaddr(skb, ifaca,
24374                                                   NETLINK_CB(cb->skb).portid,
24375                                                   cb->nlh->nlmsg_seq,
24376 @@ -3962,6 +3980,10 @@ static int inet6_dump_addr(struct sk_buf
24377         struct inet6_dev *idev;
24378         struct hlist_head *head;
24379  
24380 +       /* FIXME: maybe disable ipv6 on non v6 guests?
24381 +       if (skb->sk && skb->sk->sk_vx_info)
24382 +               return skb->len; */
24383 +
24384         s_h = cb->args[0];
24385         s_idx = idx = cb->args[1];
24386         s_ip_idx = ip_idx = cb->args[2];
24387 @@ -4404,6 +4426,7 @@ static int inet6_dump_ifinfo(struct sk_b
24388         struct net_device *dev;
24389         struct inet6_dev *idev;
24390         struct hlist_head *head;
24391 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24392  
24393         s_h = cb->args[0];
24394         s_idx = cb->args[1];
24395 @@ -4415,6 +4438,8 @@ static int inet6_dump_ifinfo(struct sk_b
24396                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24397                         if (idx < s_idx)
24398                                 goto cont;
24399 +                       if (!v6_dev_in_nx_info(dev, nxi))
24400 +                               goto cont;
24401                         idev = __in6_dev_get(dev);
24402                         if (!idev)
24403                                 goto cont;
24404 diff -NurpP --minimal linux-3.13.10/net/ipv6/af_inet6.c linux-3.13.10-vs2.3.6.11/net/ipv6/af_inet6.c
24405 --- linux-3.13.10/net/ipv6/af_inet6.c   2014-01-22 20:39:15.000000000 +0000
24406 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/af_inet6.c        2014-01-31 21:39:03.000000000 +0000
24407 @@ -43,6 +43,8 @@
24408  #include <linux/netdevice.h>
24409  #include <linux/icmpv6.h>
24410  #include <linux/netfilter_ipv6.h>
24411 +#include <linux/vs_inet.h>
24412 +#include <linux/vs_inet6.h>
24413  
24414  #include <net/ip.h>
24415  #include <net/ipv6.h>
24416 @@ -156,10 +158,13 @@ lookup_protocol:
24417         }
24418  
24419         err = -EPERM;
24420 +       if ((protocol == IPPROTO_ICMPV6) &&
24421 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24422 +               goto override;
24423         if (sock->type == SOCK_RAW && !kern &&
24424             !ns_capable(net->user_ns, CAP_NET_RAW))
24425                 goto out_rcu_unlock;
24426 -
24427 +override:
24428         sock->ops = answer->ops;
24429         answer_prot = answer->prot;
24430         answer_no_check = answer->no_check;
24431 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
24432         struct inet_sock *inet = inet_sk(sk);
24433         struct ipv6_pinfo *np = inet6_sk(sk);
24434         struct net *net = sock_net(sk);
24435 +       struct nx_v6_sock_addr nsa;
24436         __be32 v4addr = 0;
24437         unsigned short snum;
24438         int addr_type = 0;
24439 @@ -274,6 +280,10 @@ int inet6_bind(struct socket *sock, stru
24440         if (addr->sin6_family != AF_INET6)
24441                 return -EAFNOSUPPORT;
24442  
24443 +       err = v6_map_sock_addr(inet, addr, &nsa);
24444 +       if (err)
24445 +               return err;
24446 +
24447         addr_type = ipv6_addr_type(&addr->sin6_addr);
24448         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
24449                 return -EINVAL;
24450 @@ -305,6 +315,7 @@ int inet6_bind(struct socket *sock, stru
24451                 /* Reproduce AF_INET checks to make the bindings consistent */
24452                 v4addr = addr->sin6_addr.s6_addr32[3];
24453                 chk_addr_ret = inet_addr_type(net, v4addr);
24454 +
24455                 if (!sysctl_ip_nonlocal_bind &&
24456                     !(inet->freebind || inet->transparent) &&
24457                     v4addr != htonl(INADDR_ANY) &&
24458 @@ -314,6 +325,10 @@ int inet6_bind(struct socket *sock, stru
24459                         err = -EADDRNOTAVAIL;
24460                         goto out;
24461                 }
24462 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
24463 +                       err = -EADDRNOTAVAIL;
24464 +                       goto out;
24465 +               }
24466         } else {
24467                 if (addr_type != IPV6_ADDR_ANY) {
24468                         struct net_device *dev = NULL;
24469 @@ -340,6 +355,11 @@ int inet6_bind(struct socket *sock, stru
24470                                 }
24471                         }
24472  
24473 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24474 +                               err = -EADDRNOTAVAIL;
24475 +                               goto out_unlock;
24476 +                       }
24477 +
24478                         /* ipv4 addr of the socket is invalid.  Only the
24479                          * unspecified and mapped address have a v4 equivalent.
24480                          */
24481 @@ -356,6 +376,9 @@ int inet6_bind(struct socket *sock, stru
24482                 }
24483         }
24484  
24485 +       /* what's that for? */
24486 +       v6_set_sock_addr(inet, &nsa);
24487 +
24488         inet->inet_rcv_saddr = v4addr;
24489         inet->inet_saddr = v4addr;
24490  
24491 @@ -457,9 +480,11 @@ int inet6_getname(struct socket *sock, s
24492                         return -ENOTCONN;
24493                 sin->sin6_port = inet->inet_dport;
24494                 sin->sin6_addr = sk->sk_v6_daddr;
24495 +               /* FIXME: remap lback? */
24496                 if (np->sndflow)
24497                         sin->sin6_flowinfo = np->flow_label;
24498         } else {
24499 +               /* FIXME: remap lback? */
24500                 if (ipv6_addr_any(&sk->sk_v6_rcv_saddr))
24501                         sin->sin6_addr = np->saddr;
24502                 else
24503 diff -NurpP --minimal linux-3.13.10/net/ipv6/datagram.c linux-3.13.10-vs2.3.6.11/net/ipv6/datagram.c
24504 --- linux-3.13.10/net/ipv6/datagram.c   2014-01-22 20:39:15.000000000 +0000
24505 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/datagram.c        2014-01-31 20:38:04.000000000 +0000
24506 @@ -655,7 +655,7 @@ int ip6_datagram_send_ctl(struct net *ne
24507  
24508                         rcu_read_lock();
24509                         if (fl6->flowi6_oif) {
24510 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
24511 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
24512                                 if (!dev) {
24513                                         rcu_read_unlock();
24514                                         return -ENODEV;
24515 diff -NurpP --minimal linux-3.13.10/net/ipv6/fib6_rules.c linux-3.13.10-vs2.3.6.11/net/ipv6/fib6_rules.c
24516 --- linux-3.13.10/net/ipv6/fib6_rules.c 2014-01-22 20:39:15.000000000 +0000
24517 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/fib6_rules.c      2014-01-31 20:38:04.000000000 +0000
24518 @@ -97,7 +97,7 @@ static int fib6_rule_action(struct fib_r
24519                                                ip6_dst_idev(&rt->dst)->dev,
24520                                                &flp6->daddr,
24521                                                rt6_flags2srcprefs(flags),
24522 -                                              &saddr))
24523 +                                              &saddr, NULL))
24524                                 goto again;
24525                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
24526                                                r->src.plen))
24527 diff -NurpP --minimal linux-3.13.10/net/ipv6/inet6_hashtables.c linux-3.13.10-vs2.3.6.11/net/ipv6/inet6_hashtables.c
24528 --- linux-3.13.10/net/ipv6/inet6_hashtables.c   2014-01-22 20:39:15.000000000 +0000
24529 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/inet6_hashtables.c        2014-01-31 20:38:04.000000000 +0000
24530 @@ -16,6 +16,7 @@
24531  
24532  #include <linux/module.h>
24533  #include <linux/random.h>
24534 +#include <linux/vs_inet6.h>
24535  
24536  #include <net/inet_connection_sock.h>
24537  #include <net/inet_hashtables.h>
24538 @@ -116,7 +117,6 @@ struct sock *__inet6_lookup_established(
24539         unsigned int slot = hash & hashinfo->ehash_mask;
24540         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
24541  
24542 -
24543         rcu_read_lock();
24544  begin:
24545         sk_nulls_for_each_rcu(sk, node, &head->chain) {
24546 @@ -158,6 +158,9 @@ static inline int compute_score(struct s
24547                         if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24548                                 return -1;
24549                         score++;
24550 +               } else {
24551 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24552 +                               return -1;
24553                 }
24554                 if (sk->sk_bound_dev_if) {
24555                         if (sk->sk_bound_dev_if != dif)
24556 diff -NurpP --minimal linux-3.13.10/net/ipv6/ip6_fib.c linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_fib.c
24557 --- linux-3.13.10/net/ipv6/ip6_fib.c    2014-01-22 20:39:15.000000000 +0000
24558 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_fib.c 2014-01-31 21:48:35.000000000 +0000
24559 @@ -1779,6 +1779,7 @@ static int ipv6_route_seq_show(struct se
24560         struct rt6_info *rt = v;
24561         struct ipv6_route_iter *iter = seq->private;
24562  
24563 +       /* FIXME: check for network context? */
24564         seq_printf(seq, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
24565  
24566  #ifdef CONFIG_IPV6_SUBTREES
24567 diff -NurpP --minimal linux-3.13.10/net/ipv6/ip6_output.c linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_output.c
24568 --- linux-3.13.10/net/ipv6/ip6_output.c 2014-04-17 01:12:41.000000000 +0000
24569 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_output.c      2014-04-17 01:17:11.000000000 +0000
24570 @@ -872,7 +872,8 @@ static int ip6_dst_lookup_tail(struct so
24571                 struct rt6_info *rt = (struct rt6_info *) *dst;
24572                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
24573                                           sk ? inet6_sk(sk)->srcprefs : 0,
24574 -                                         &fl6->saddr);
24575 +                                         &fl6->saddr,
24576 +                                         sk ? sk->sk_nx_info : NULL);
24577                 if (err)
24578                         goto out_err_release;
24579         }
24580 diff -NurpP --minimal linux-3.13.10/net/ipv6/ndisc.c linux-3.13.10-vs2.3.6.11/net/ipv6/ndisc.c
24581 --- linux-3.13.10/net/ipv6/ndisc.c      2014-01-22 20:39:15.000000000 +0000
24582 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ndisc.c   2014-01-31 20:38:04.000000000 +0000
24583 @@ -486,7 +486,7 @@ void ndisc_send_na(struct net_device *de
24584         } else {
24585                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
24586                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
24587 -                                      &tmpaddr))
24588 +                                      &tmpaddr, NULL))
24589                         return;
24590                 src_addr = &tmpaddr;
24591         }
24592 diff -NurpP --minimal linux-3.13.10/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.13.10-vs2.3.6.11/net/ipv6/netfilter/ip6t_MASQUERADE.c
24593 --- linux-3.13.10/net/ipv6/netfilter/ip6t_MASQUERADE.c  2013-11-25 15:47:07.000000000 +0000
24594 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/netfilter/ip6t_MASQUERADE.c       2014-01-31 20:38:04.000000000 +0000
24595 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
24596                             ctinfo == IP_CT_RELATED_REPLY));
24597  
24598         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
24599 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
24600 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
24601                 return NF_DROP;
24602  
24603         nfct_nat(ct)->masq_index = par->out->ifindex;
24604 diff -NurpP --minimal linux-3.13.10/net/ipv6/raw.c linux-3.13.10-vs2.3.6.11/net/ipv6/raw.c
24605 --- linux-3.13.10/net/ipv6/raw.c        2014-01-22 20:39:15.000000000 +0000
24606 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/raw.c     2014-01-31 20:38:04.000000000 +0000
24607 @@ -30,6 +30,7 @@
24608  #include <linux/icmpv6.h>
24609  #include <linux/netfilter.h>
24610  #include <linux/netfilter_ipv6.h>
24611 +#include <linux/vs_inet6.h>
24612  #include <linux/skbuff.h>
24613  #include <linux/compat.h>
24614  #include <asm/uaccess.h>
24615 @@ -287,6 +288,13 @@ static int rawv6_bind(struct sock *sk, s
24616                                 goto out_unlock;
24617                 }
24618  
24619 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24620 +                       err = -EADDRNOTAVAIL;
24621 +                       if (dev)
24622 +                               dev_put(dev);
24623 +                       goto out;
24624 +               }
24625 +
24626                 /* ipv4 addr of the socket is invalid.  Only the
24627                  * unspecified and mapped address have a v4 equivalent.
24628                  */
24629 diff -NurpP --minimal linux-3.13.10/net/ipv6/route.c linux-3.13.10-vs2.3.6.11/net/ipv6/route.c
24630 --- linux-3.13.10/net/ipv6/route.c      2014-04-17 01:12:41.000000000 +0000
24631 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/route.c   2014-04-17 01:17:11.000000000 +0000
24632 @@ -58,6 +58,7 @@
24633  #include <net/netevent.h>
24634  #include <net/netlink.h>
24635  #include <net/nexthop.h>
24636 +#include <linux/vs_inet6.h>
24637  
24638  #include <asm/uaccess.h>
24639  
24640 @@ -2196,15 +2197,17 @@ int ip6_route_get_saddr(struct net *net,
24641                         struct rt6_info *rt,
24642                         const struct in6_addr *daddr,
24643                         unsigned int prefs,
24644 -                       struct in6_addr *saddr)
24645 +                       struct in6_addr *saddr,
24646 +                       struct nx_info *nxi)
24647  {
24648         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
24649         int err = 0;
24650 -       if (rt->rt6i_prefsrc.plen)
24651 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
24652 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
24653                 *saddr = rt->rt6i_prefsrc.addr;
24654         else
24655                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
24656 -                                        daddr, prefs, saddr);
24657 +                                        daddr, prefs, saddr, nxi);
24658         return err;
24659  }
24660  
24661 @@ -2624,7 +2627,8 @@ static int rt6_fill_node(struct net *net
24662                                 goto nla_put_failure;
24663         } else if (dst) {
24664                 struct in6_addr saddr_buf;
24665 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
24666 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
24667 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
24668                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
24669                         goto nla_put_failure;
24670         }
24671 diff -NurpP --minimal linux-3.13.10/net/ipv6/tcp_ipv6.c linux-3.13.10-vs2.3.6.11/net/ipv6/tcp_ipv6.c
24672 --- linux-3.13.10/net/ipv6/tcp_ipv6.c   2014-01-22 20:39:15.000000000 +0000
24673 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/tcp_ipv6.c        2014-01-31 20:38:04.000000000 +0000
24674 @@ -72,6 +72,7 @@
24675  
24676  #include <linux/crypto.h>
24677  #include <linux/scatterlist.h>
24678 +#include <linux/vs_inet6.h>
24679  
24680  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
24681  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
24682 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
24683          *      connect() to INADDR_ANY means loopback (BSD'ism).
24684          */
24685  
24686 -       if (ipv6_addr_any(&usin->sin6_addr))
24687 -               usin->sin6_addr.s6_addr[15] = 0x1;
24688 +       if (ipv6_addr_any(&usin->sin6_addr)) {
24689 +               struct nx_info *nxi =  sk->sk_nx_info;
24690 +
24691 +               if (nxi && nx_info_has_v6(nxi))
24692 +                       /* FIXME: remap lback? */
24693 +                       usin->sin6_addr = nxi->v6.ip;
24694 +               else
24695 +                       usin->sin6_addr.s6_addr[15] = 0x1;
24696 +       }
24697  
24698         addr_type = ipv6_addr_type(&usin->sin6_addr);
24699  
24700 diff -NurpP --minimal linux-3.13.10/net/ipv6/udp.c linux-3.13.10-vs2.3.6.11/net/ipv6/udp.c
24701 --- linux-3.13.10/net/ipv6/udp.c        2014-01-22 20:39:15.000000000 +0000
24702 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/udp.c     2014-02-01 02:33:38.000000000 +0000
24703 @@ -47,6 +47,7 @@
24704  #include <net/xfrm.h>
24705  #include <net/inet6_hashtables.h>
24706  #include <net/busy_poll.h>
24707 +#include <linux/vs_inet6.h>
24708  
24709  #include <linux/proc_fs.h>
24710  #include <linux/seq_file.h>
24711 @@ -76,33 +77,61 @@ static unsigned int udp6_ehashfn(struct
24712                                udp_ipv6_hash_secret + net_hash_mix(net));
24713  }
24714  
24715 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
24716 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24717  {
24718 +       const struct in6_addr *sk1_rcv_saddr6 = inet6_rcv_saddr(sk1);
24719         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
24720 -       int sk_ipv6only = ipv6_only_sock(sk);
24721 +       __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr;
24722 +       __be32 sk2_rcv_saddr = sk2->sk_rcv_saddr;
24723 +       int sk1_ipv6only = ipv6_only_sock(sk1);
24724         int sk2_ipv6only = inet_v6_ipv6only(sk2);
24725 -       int addr_type = ipv6_addr_type(&sk->sk_v6_rcv_saddr);
24726 +       int addr_type1 = ipv6_addr_type(sk1_rcv_saddr6);
24727         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
24728  
24729         /* if both are mapped, treat as IPv4 */
24730 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
24731 -               return (!sk2_ipv6only &&
24732 -                       (!sk->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24733 -                         sk->sk_rcv_saddr == sk2->sk_rcv_saddr));
24734 +       if (addr_type1 == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
24735 +               if (!sk2_ipv6only &&
24736 +                       (!sk1->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24737 +                         sk1->sk_rcv_saddr == sk2->sk_rcv_saddr))
24738 +                       goto vs_v4;
24739 +               else
24740 +                       return 0;
24741 +       }
24742  
24743         if (addr_type2 == IPV6_ADDR_ANY &&
24744 -           !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
24745 -               return 1;
24746 +           !(sk2_ipv6only && addr_type1 == IPV6_ADDR_MAPPED))
24747 +               goto vs;
24748  
24749 -       if (addr_type == IPV6_ADDR_ANY &&
24750 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24751 -               return 1;
24752 +       if (addr_type1 == IPV6_ADDR_ANY &&
24753 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24754 +               goto vs;
24755  
24756         if (sk2_rcv_saddr6 &&
24757 -           ipv6_addr_equal(&sk->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24758 -               return 1;
24759 +           ipv6_addr_equal(&sk1->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24760 +               goto vs;
24761  
24762         return 0;
24763 +
24764 +vs_v4:
24765 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
24766 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24767 +       if (!sk2_rcv_saddr)
24768 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
24769 +       if (!sk1_rcv_saddr)
24770 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
24771 +       return 1;
24772 +vs:
24773 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type1 == IPV6_ADDR_ANY)
24774 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24775 +       else if (addr_type2 == IPV6_ADDR_ANY)
24776 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
24777 +       else if (addr_type1 == IPV6_ADDR_ANY) {
24778 +               if (addr_type2 == IPV6_ADDR_MAPPED)
24779 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24780 +               else
24781 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
24782 +       }
24783 +       return 1;
24784  }
24785  
24786  static unsigned int udp6_portaddr_hash(struct net *net,
24787 @@ -160,6 +189,10 @@ static inline int compute_score(struct s
24788                         if (inet->inet_dport != sport)
24789                                 return -1;
24790                         score++;
24791 +               } else {
24792 +                       /* block non nx_info ips */
24793 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24794 +                               return -1;
24795                 }
24796                 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
24797                         if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24798 diff -NurpP --minimal linux-3.13.10/net/ipv6/xfrm6_policy.c linux-3.13.10-vs2.3.6.11/net/ipv6/xfrm6_policy.c
24799 --- linux-3.13.10/net/ipv6/xfrm6_policy.c       2014-01-22 20:39:15.000000000 +0000
24800 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/xfrm6_policy.c    2014-01-31 20:38:04.000000000 +0000
24801 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
24802         dev = ip6_dst_idev(dst)->dev;
24803         ipv6_dev_get_saddr(dev_net(dev), dev,
24804                            (struct in6_addr *)&daddr->a6, 0,
24805 -                          (struct in6_addr *)&saddr->a6);
24806 +                          (struct in6_addr *)&saddr->a6, NULL);
24807         dst_release(dst);
24808         return 0;
24809  }
24810 diff -NurpP --minimal linux-3.13.10/net/netfilter/ipvs/ip_vs_xmit.c linux-3.13.10-vs2.3.6.11/net/netfilter/ipvs/ip_vs_xmit.c
24811 --- linux-3.13.10/net/netfilter/ipvs/ip_vs_xmit.c       2013-11-25 15:47:07.000000000 +0000
24812 +++ linux-3.13.10-vs2.3.6.11/net/netfilter/ipvs/ip_vs_xmit.c    2014-01-31 20:38:04.000000000 +0000
24813 @@ -316,7 +316,7 @@ __ip_vs_route_output_v6(struct net *net,
24814                 return dst;
24815         if (ipv6_addr_any(&fl6.saddr) &&
24816             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
24817 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
24818 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
24819                 goto out_err;
24820         if (do_xfrm) {
24821                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
24822 diff -NurpP --minimal linux-3.13.10/net/netlink/af_netlink.c linux-3.13.10-vs2.3.6.11/net/netlink/af_netlink.c
24823 --- linux-3.13.10/net/netlink/af_netlink.c      2014-01-22 20:39:16.000000000 +0000
24824 +++ linux-3.13.10-vs2.3.6.11/net/netlink/af_netlink.c   2014-02-25 11:47:07.000000000 +0000
24825 @@ -58,6 +58,9 @@
24826  #include <linux/mutex.h>
24827  #include <linux/vmalloc.h>
24828  #include <linux/if_arp.h>
24829 +#include <linux/vs_context.h>
24830 +#include <linux/vs_network.h>
24831 +#include <linux/vs_limit.h>
24832  #include <asm/cacheflush.h>
24833  
24834  #include <net/net_namespace.h>
24835 @@ -2850,6 +2853,8 @@ static struct sock *netlink_seq_socket_i
24836                         sk_for_each(s, &hash->table[j]) {
24837                                 if (sock_net(s) != seq_file_net(seq))
24838                                         continue;
24839 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
24840 +                                       continue;
24841                                 if (off == pos) {
24842                                         iter->link = i;
24843                                         iter->hash_idx = j;
24844 @@ -2886,7 +2891,8 @@ static void *netlink_seq_next(struct seq
24845         s = v;
24846         do {
24847                 s = sk_next(s);
24848 -       } while (s && !nl_table[s->sk_protocol].compare(net, s));
24849 +       } while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24850 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
24851         if (s)
24852                 return s;
24853  
24854 @@ -2899,7 +2905,8 @@ static void *netlink_seq_next(struct seq
24855                 for (; j <= hash->mask; j++) {
24856                         s = sk_head(&hash->table[j]);
24857  
24858 -                       while (s && !nl_table[s->sk_protocol].compare(net, s))
24859 +                       while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24860 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
24861                                 s = sk_next(s);
24862                         if (s) {
24863                                 iter->link = i;
24864 diff -NurpP --minimal linux-3.13.10/net/socket.c linux-3.13.10-vs2.3.6.11/net/socket.c
24865 --- linux-3.13.10/net/socket.c  2014-04-17 01:12:42.000000000 +0000
24866 +++ linux-3.13.10-vs2.3.6.11/net/socket.c       2014-04-17 01:17:11.000000000 +0000
24867 @@ -98,6 +98,9 @@
24868  
24869  #include <net/sock.h>
24870  #include <linux/netfilter.h>
24871 +#include <linux/vs_socket.h>
24872 +#include <linux/vs_inet.h>
24873 +#include <linux/vs_inet6.h>
24874  
24875  #include <linux/if_tun.h>
24876  #include <linux/ipv6_route.h>
24877 @@ -623,13 +626,29 @@ static inline int __sock_sendmsg_nosec(s
24878                                        struct msghdr *msg, size_t size)
24879  {
24880         struct sock_iocb *si = kiocb_to_siocb(iocb);
24881 +       size_t len;
24882  
24883         si->sock = sock;
24884         si->scm = NULL;
24885         si->msg = msg;
24886         si->size = size;
24887  
24888 -       return sock->ops->sendmsg(iocb, sock, msg, size);
24889 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
24890 +       if (sock->sk) {
24891 +               if (len == size)
24892 +                       vx_sock_send(sock->sk, size);
24893 +               else
24894 +                       vx_sock_fail(sock->sk, size);
24895 +       }
24896 +       vxdprintk(VXD_CBIT(net, 7),
24897 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
24898 +               sock, sock->sk,
24899 +               (sock->sk)?sock->sk->sk_nx_info:0,
24900 +               (sock->sk)?sock->sk->sk_vx_info:0,
24901 +               (sock->sk)?sock->sk->sk_xid:0,
24902 +               (sock->sk)?sock->sk->sk_nid:0,
24903 +               (unsigned int)size, len);
24904 +       return len;
24905  }
24906  
24907  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
24908 @@ -773,6 +792,7 @@ static inline int __sock_recvmsg_nosec(s
24909                                        struct msghdr *msg, size_t size, int flags)
24910  {
24911         struct sock_iocb *si = kiocb_to_siocb(iocb);
24912 +       int len;
24913  
24914         si->sock = sock;
24915         si->scm = NULL;
24916 @@ -780,7 +800,18 @@ static inline int __sock_recvmsg_nosec(s
24917         si->size = size;
24918         si->flags = flags;
24919  
24920 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
24921 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
24922 +       if ((len >= 0) && sock->sk)
24923 +               vx_sock_recv(sock->sk, len);
24924 +       vxdprintk(VXD_CBIT(net, 7),
24925 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
24926 +               sock, sock->sk,
24927 +               (sock->sk)?sock->sk->sk_nx_info:0,
24928 +               (sock->sk)?sock->sk->sk_vx_info:0,
24929 +               (sock->sk)?sock->sk->sk_xid:0,
24930 +               (sock->sk)?sock->sk->sk_nid:0,
24931 +               (unsigned int)size, len);
24932 +       return len;
24933  }
24934  
24935  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
24936 @@ -1256,6 +1287,13 @@ int __sock_create(struct net *net, int f
24937         if (type < 0 || type >= SOCK_MAX)
24938                 return -EINVAL;
24939  
24940 +       if (!nx_check(0, VS_ADMIN)) {
24941 +               if (family == PF_INET && !current_nx_info_has_v4())
24942 +                       return -EAFNOSUPPORT;
24943 +               if (family == PF_INET6 && !current_nx_info_has_v6())
24944 +                       return -EAFNOSUPPORT;
24945 +       }
24946 +
24947         /* Compatibility.
24948  
24949            This uglymoron is moved from INET layer to here to avoid
24950 @@ -1390,6 +1428,7 @@ SYSCALL_DEFINE3(socket, int, family, int
24951         if (retval < 0)
24952                 goto out;
24953  
24954 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
24955         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
24956         if (retval < 0)
24957                 goto out_release;
24958 @@ -1431,10 +1470,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
24959         err = sock_create(family, type, protocol, &sock1);
24960         if (err < 0)
24961                 goto out;
24962 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
24963  
24964         err = sock_create(family, type, protocol, &sock2);
24965         if (err < 0)
24966                 goto out_release_1;
24967 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
24968  
24969         err = sock1->ops->socketpair(sock1, sock2);
24970         if (err < 0)
24971 diff -NurpP --minimal linux-3.13.10/net/sunrpc/auth.c linux-3.13.10-vs2.3.6.11/net/sunrpc/auth.c
24972 --- linux-3.13.10/net/sunrpc/auth.c     2013-11-25 15:47:08.000000000 +0000
24973 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/auth.c  2014-01-31 20:38:04.000000000 +0000
24974 @@ -15,6 +15,7 @@
24975  #include <linux/sunrpc/clnt.h>
24976  #include <linux/sunrpc/gss_api.h>
24977  #include <linux/spinlock.h>
24978 +#include <linux/vs_tag.h>
24979  
24980  #ifdef RPC_DEBUG
24981  # define RPCDBG_FACILITY       RPCDBG_AUTH
24982 @@ -586,6 +587,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
24983         memset(&acred, 0, sizeof(acred));
24984         acred.uid = cred->fsuid;
24985         acred.gid = cred->fsgid;
24986 +       acred.tag = make_ktag(&init_user_ns, dx_current_tag());
24987         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
24988  
24989         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
24990 @@ -626,6 +628,7 @@ rpcauth_bind_root_cred(struct rpc_task *
24991         struct auth_cred acred = {
24992                 .uid = GLOBAL_ROOT_UID,
24993                 .gid = GLOBAL_ROOT_GID,
24994 +               .tag = KTAGT_INIT(dx_current_tag()),
24995         };
24996  
24997         dprintk("RPC: %5u looking up %s cred\n",
24998 diff -NurpP --minimal linux-3.13.10/net/sunrpc/auth_unix.c linux-3.13.10-vs2.3.6.11/net/sunrpc/auth_unix.c
24999 --- linux-3.13.10/net/sunrpc/auth_unix.c        2013-11-25 15:47:08.000000000 +0000
25000 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/auth_unix.c     2014-01-31 20:38:04.000000000 +0000
25001 @@ -13,11 +13,13 @@
25002  #include <linux/sunrpc/clnt.h>
25003  #include <linux/sunrpc/auth.h>
25004  #include <linux/user_namespace.h>
25005 +#include <linux/vs_tag.h>
25006  
25007  #define NFS_NGROUPS    16
25008  
25009  struct unx_cred {
25010         struct rpc_cred         uc_base;
25011 +       ktag_t                  uc_tag;
25012         kgid_t                  uc_gid;
25013         kgid_t                  uc_gids[NFS_NGROUPS];
25014  };
25015 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25016                 groups = NFS_NGROUPS;
25017  
25018         cred->uc_gid = acred->gid;
25019 +       cred->uc_tag = acred->tag;
25020         for (i = 0; i < groups; i++)
25021                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25022         if (i < NFS_NGROUPS)
25023 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25024         unsigned int i;
25025  
25026  
25027 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25028 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
25029 +           !gid_eq(cred->uc_gid, acred->gid) ||
25030 +           !tag_eq(cred->uc_tag, acred->tag))
25031                 return 0;
25032  
25033         if (acred->group_info != NULL)
25034 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25035         struct rpc_clnt *clnt = task->tk_client;
25036         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25037         __be32          *base, *hold;
25038 -       int             i;
25039 +       int             i, tag;
25040  
25041         *p++ = htonl(RPC_AUTH_UNIX);
25042         base = p++;
25043 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
25044          */
25045         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25046  
25047 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25048 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25049 +       tag = task->tk_client->cl_tag;
25050 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
25051 +               TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
25052 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
25053 +               TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
25054         hold = p++;
25055         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25056                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25057 diff -NurpP --minimal linux-3.13.10/net/sunrpc/clnt.c linux-3.13.10-vs2.3.6.11/net/sunrpc/clnt.c
25058 --- linux-3.13.10/net/sunrpc/clnt.c     2014-04-17 01:12:42.000000000 +0000
25059 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/clnt.c  2014-02-25 11:26:10.000000000 +0000
25060 @@ -31,6 +31,7 @@
25061  #include <linux/in.h>
25062  #include <linux/in6.h>
25063  #include <linux/un.h>
25064 +#include <linux/vs_cvirt.h>
25065  
25066  #include <linux/sunrpc/clnt.h>
25067  #include <linux/sunrpc/addr.h>
25068 @@ -538,6 +539,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25069         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25070                 clnt->cl_chatty = 1;
25071  
25072 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25073 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25074 +               clnt->cl_tag = 1; */
25075         return clnt;
25076  }
25077  EXPORT_SYMBOL_GPL(rpc_create);
25078 diff -NurpP --minimal linux-3.13.10/net/unix/af_unix.c linux-3.13.10-vs2.3.6.11/net/unix/af_unix.c
25079 --- linux-3.13.10/net/unix/af_unix.c    2014-04-17 01:12:42.000000000 +0000
25080 +++ linux-3.13.10-vs2.3.6.11/net/unix/af_unix.c 2014-04-17 01:17:11.000000000 +0000
25081 @@ -115,6 +115,8 @@
25082  #include <net/checksum.h>
25083  #include <linux/security.h>
25084  #include <linux/freezer.h>
25085 +#include <linux/vs_context.h>
25086 +#include <linux/vs_limit.h>
25087  
25088  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25089  EXPORT_SYMBOL_GPL(unix_socket_table);
25090 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25091                 if (!net_eq(sock_net(s), net))
25092                         continue;
25093  
25094 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25095 +                       continue;
25096                 if (u->addr->len == len &&
25097                     !memcmp(u->addr->name, sunname, len))
25098                         goto found;
25099 @@ -2275,6 +2279,8 @@ static struct sock *unix_from_bucket(str
25100         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25101                 if (sock_net(sk) != seq_file_net(seq))
25102                         continue;
25103 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25104 +                       continue;
25105                 if (++count == offset)
25106                         break;
25107         }
25108 @@ -2292,6 +2298,8 @@ static struct sock *unix_next_socket(str
25109                 sk = sk_next(sk);
25110                 if (!sk)
25111                         goto next_bucket;
25112 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25113 +                       continue;
25114                 if (sock_net(sk) == seq_file_net(seq))
25115                         return sk;
25116         }
25117 diff -NurpP --minimal linux-3.13.10/scripts/checksyscalls.sh linux-3.13.10-vs2.3.6.11/scripts/checksyscalls.sh
25118 --- linux-3.13.10/scripts/checksyscalls.sh      2012-12-11 03:30:57.000000000 +0000
25119 +++ linux-3.13.10-vs2.3.6.11/scripts/checksyscalls.sh   2014-01-31 20:38:04.000000000 +0000
25120 @@ -193,7 +193,6 @@ cat << EOF
25121  #define __IGNORE_afs_syscall
25122  #define __IGNORE_getpmsg
25123  #define __IGNORE_putpmsg
25124 -#define __IGNORE_vserver
25125  EOF
25126  }
25127  
25128 diff -NurpP --minimal linux-3.13.10/security/commoncap.c linux-3.13.10-vs2.3.6.11/security/commoncap.c
25129 --- linux-3.13.10/security/commoncap.c  2013-11-25 15:47:08.000000000 +0000
25130 +++ linux-3.13.10-vs2.3.6.11/security/commoncap.c       2014-01-31 20:38:04.000000000 +0000
25131 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25132  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25133                 int cap, int audit)
25134  {
25135 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25136         struct user_namespace *ns = targ_ns;
25137  
25138         /* See if cred has the capability in the target user namespace
25139 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25140          */
25141         for (;;) {
25142                 /* Do we have the necessary capabilities? */
25143 -               if (ns == cred->user_ns)
25144 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25145 +               if (ns == cred->user_ns) {
25146 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25147 +                           cap_raised(cred->cap_effective, cap))
25148 +                               return 0;
25149 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25150 +               }
25151  
25152                 /* Have we tried all of the parent namespaces? */
25153                 if (ns == &init_user_ns)
25154 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25155  
25156         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25157                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25158 -           !capable(CAP_SYS_ADMIN))
25159 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25160                 return -EPERM;
25161         return 0;
25162  }
25163 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25164  
25165         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25166                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25167 -           !capable(CAP_SYS_ADMIN))
25168 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25169                 return -EPERM;
25170         return 0;
25171  }
25172 diff -NurpP --minimal linux-3.13.10/security/selinux/hooks.c linux-3.13.10-vs2.3.6.11/security/selinux/hooks.c
25173 --- linux-3.13.10/security/selinux/hooks.c      2014-04-17 01:12:42.000000000 +0000
25174 +++ linux-3.13.10-vs2.3.6.11/security/selinux/hooks.c   2014-04-17 01:17:11.000000000 +0000
25175 @@ -68,7 +68,6 @@
25176  #include <linux/dccp.h>
25177  #include <linux/quota.h>
25178  #include <linux/un.h>          /* for Unix socket types */
25179 -#include <net/af_unix.h>       /* for Unix socket types */
25180  #include <linux/parser.h>
25181  #include <linux/nfs_mount.h>
25182  #include <net/ipv6.h>
This page took 3.143701 seconds and 3 git commands to generate.