]> git.pld-linux.org Git - packages/kernel.git/blob - kernel-vserver-2.3.patch
- updated vserver patch to
[packages/kernel.git] / kernel-vserver-2.3.patch
1 diff -NurpP --minimal linux-3.10.40/Documentation/vserver/debug.txt linux-3.10.40-vs2.3.6.8/Documentation/vserver/debug.txt
2 --- linux-3.10.40/Documentation/vserver/debug.txt       1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.10.40-vs2.3.6.8/Documentation/vserver/debug.txt     2013-08-22 20:29:59.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.10.40/arch/alpha/Kconfig linux-3.10.40-vs2.3.6.8/arch/alpha/Kconfig
160 --- linux-3.10.40/arch/alpha/Kconfig    2013-07-14 17:00:13.000000000 +0000
161 +++ linux-3.10.40-vs2.3.6.8/arch/alpha/Kconfig  2013-08-22 20:29:59.000000000 +0000
162 @@ -665,6 +665,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.10.40/arch/alpha/kernel/systbls.S linux-3.10.40-vs2.3.6.8/arch/alpha/kernel/systbls.S
172 --- linux-3.10.40/arch/alpha/kernel/systbls.S   2013-02-19 13:56:11.000000000 +0000
173 +++ linux-3.10.40-vs2.3.6.8/arch/alpha/kernel/systbls.S 2013-08-22 20:29:59.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.10.40/arch/alpha/kernel/traps.c linux-3.10.40-vs2.3.6.8/arch/alpha/kernel/traps.c
184 --- linux-3.10.40/arch/alpha/kernel/traps.c     2013-07-14 17:00:13.000000000 +0000
185 +++ linux-3.10.40-vs2.3.6.8/arch/alpha/kernel/traps.c   2013-08-22 20:29:59.000000000 +0000
186 @@ -177,7 +177,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.10.40/arch/arm/Kconfig linux-3.10.40-vs2.3.6.8/arch/arm/Kconfig
197 --- linux-3.10.40/arch/arm/Kconfig      2014-05-20 04:09:18.000000000 +0000
198 +++ linux-3.10.40-vs2.3.6.8/arch/arm/Kconfig    2013-11-13 17:17:15.000000000 +0000
199 @@ -2238,6 +2238,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.10.40/arch/arm/kernel/calls.S linux-3.10.40-vs2.3.6.8/arch/arm/kernel/calls.S
209 --- linux-3.10.40/arch/arm/kernel/calls.S       2013-05-31 13:44:29.000000000 +0000
210 +++ linux-3.10.40-vs2.3.6.8/arch/arm/kernel/calls.S     2013-08-22 20:29:59.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.10.40/arch/arm/kernel/traps.c linux-3.10.40-vs2.3.6.8/arch/arm/kernel/traps.c
221 --- linux-3.10.40/arch/arm/kernel/traps.c       2014-05-20 04:09:18.000000000 +0000
222 +++ linux-3.10.40-vs2.3.6.8/arch/arm/kernel/traps.c     2014-01-22 19:00:34.000000000 +0000
223 @@ -246,8 +246,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.10.40/arch/cris/Kconfig linux-3.10.40-vs2.3.6.8/arch/cris/Kconfig
235 --- linux-3.10.40/arch/cris/Kconfig     2013-07-14 17:00:25.000000000 +0000
236 +++ linux-3.10.40-vs2.3.6.8/arch/cris/Kconfig   2013-08-22 20:29:59.000000000 +0000
237 @@ -673,6 +673,8 @@ source "drivers/staging/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.10.40/arch/h8300/Kconfig linux-3.10.40-vs2.3.6.8/arch/h8300/Kconfig
247 --- linux-3.10.40/arch/h8300/Kconfig    2013-07-14 17:00:25.000000000 +0000
248 +++ linux-3.10.40-vs2.3.6.8/arch/h8300/Kconfig  2013-08-22 20:29:59.000000000 +0000
249 @@ -218,6 +218,8 @@ source "fs/Kconfig"
250  
251  source "arch/h8300/Kconfig.debug"
252  
253 +source "kernel/vserver/Kconfig"
254 +
255  source "security/Kconfig"
256  
257  source "crypto/Kconfig"
258 diff -NurpP --minimal linux-3.10.40/arch/ia64/Kconfig linux-3.10.40-vs2.3.6.8/arch/ia64/Kconfig
259 --- linux-3.10.40/arch/ia64/Kconfig     2013-07-14 17:00:25.000000000 +0000
260 +++ linux-3.10.40-vs2.3.6.8/arch/ia64/Kconfig   2013-08-22 20:29:59.000000000 +0000
261 @@ -643,6 +643,8 @@ source "fs/Kconfig"
262  
263  source "arch/ia64/Kconfig.debug"
264  
265 +source "kernel/vserver/Kconfig"
266 +
267  source "security/Kconfig"
268  
269  source "crypto/Kconfig"
270 diff -NurpP --minimal linux-3.10.40/arch/ia64/kernel/entry.S linux-3.10.40-vs2.3.6.8/arch/ia64/kernel/entry.S
271 --- linux-3.10.40/arch/ia64/kernel/entry.S      2013-05-31 13:44:38.000000000 +0000
272 +++ linux-3.10.40-vs2.3.6.8/arch/ia64/kernel/entry.S    2013-08-22 20:29:59.000000000 +0000
273 @@ -1719,7 +1719,7 @@ sys_call_table:
274         data8 sys_mq_notify
275         data8 sys_mq_getsetattr
276         data8 sys_kexec_load
277 -       data8 sys_ni_syscall                    // reserved for vserver
278 +       data8 sys_vserver
279         data8 sys_waitid                        // 1270
280         data8 sys_add_key
281         data8 sys_request_key
282 diff -NurpP --minimal linux-3.10.40/arch/ia64/kernel/ptrace.c linux-3.10.40-vs2.3.6.8/arch/ia64/kernel/ptrace.c
283 --- linux-3.10.40/arch/ia64/kernel/ptrace.c     2013-02-19 13:56:51.000000000 +0000
284 +++ linux-3.10.40-vs2.3.6.8/arch/ia64/kernel/ptrace.c   2013-08-22 20:29:59.000000000 +0000
285 @@ -21,6 +21,7 @@
286  #include <linux/regset.h>
287  #include <linux/elf.h>
288  #include <linux/tracehook.h>
289 +#include <linux/vs_base.h>
290  
291  #include <asm/pgtable.h>
292  #include <asm/processor.h>
293 diff -NurpP --minimal linux-3.10.40/arch/ia64/kernel/traps.c linux-3.10.40-vs2.3.6.8/arch/ia64/kernel/traps.c
294 --- linux-3.10.40/arch/ia64/kernel/traps.c      2013-05-31 13:44:38.000000000 +0000
295 +++ linux-3.10.40-vs2.3.6.8/arch/ia64/kernel/traps.c    2013-08-22 20:29:59.000000000 +0000
296 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
297         put_cpu();
298  
299         if (++die.lock_owner_depth < 3) {
300 -               printk("%s[%d]: %s %ld [%d]\n",
301 -               current->comm, task_pid_nr(current), str, err, ++die_counter);
302 +               printk("%s[%d:#%u]: %s %ld [%d]\n",
303 +                       current->comm, task_pid_nr(current), current->xid,
304 +                       str, err, ++die_counter);
305                 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
306                     != NOTIFY_STOP)
307                         show_regs(regs);
308 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
309                         if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
310                                 last.time = current_jiffies + 5 * HZ;
311                                 printk(KERN_WARNING
312 -                                       "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
313 -                                       current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
314 +                                       "%s(%d:#%u): floating-point assist fault at ip %016lx, isr %016lx\n",
315 +                                       current->comm, task_pid_nr(current), current->xid,
316 +                                       regs->cr_iip + ia64_psr(regs)->ri, isr);
317                         }
318                 }
319         }
320 diff -NurpP --minimal linux-3.10.40/arch/m32r/kernel/traps.c linux-3.10.40-vs2.3.6.8/arch/m32r/kernel/traps.c
321 --- linux-3.10.40/arch/m32r/kernel/traps.c      2013-07-14 17:00:26.000000000 +0000
322 +++ linux-3.10.40-vs2.3.6.8/arch/m32r/kernel/traps.c    2013-08-22 20:29:59.000000000 +0000
323 @@ -184,8 +184,9 @@ static void show_registers(struct pt_reg
324         } else {
325                 printk("SPI: %08lx\n", sp);
326         }
327 -       printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
328 -               current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
329 +       printk("Process %s (pid: %d:#%u, process nr: %d, stackpage=%08lx)",
330 +               current->comm, task_pid_nr(current), current->xid,
331 +               0xffff & i, 4096+(unsigned long)current);
332  
333         /*
334          * When in-kernel, we also print out the stack and code at the
335 diff -NurpP --minimal linux-3.10.40/arch/m68k/Kconfig linux-3.10.40-vs2.3.6.8/arch/m68k/Kconfig
336 --- linux-3.10.40/arch/m68k/Kconfig     2014-05-20 04:09:19.000000000 +0000
337 +++ linux-3.10.40-vs2.3.6.8/arch/m68k/Kconfig   2014-04-22 03:48:10.000000000 +0000
338 @@ -135,6 +135,8 @@ source "fs/Kconfig"
339  
340  source "arch/m68k/Kconfig.debug"
341  
342 +source "kernel/vserver/Kconfig"
343 +
344  source "security/Kconfig"
345  
346  source "crypto/Kconfig"
347 diff -NurpP --minimal linux-3.10.40/arch/mips/Kconfig linux-3.10.40-vs2.3.6.8/arch/mips/Kconfig
348 --- linux-3.10.40/arch/mips/Kconfig     2014-05-20 04:09:19.000000000 +0000
349 +++ linux-3.10.40-vs2.3.6.8/arch/mips/Kconfig   2013-11-13 17:17:15.000000000 +0000
350 @@ -2583,6 +2583,8 @@ source "fs/Kconfig"
351  
352  source "arch/mips/Kconfig.debug"
353  
354 +source "kernel/vserver/Kconfig"
355 +
356  source "security/Kconfig"
357  
358  source "crypto/Kconfig"
359 diff -NurpP --minimal linux-3.10.40/arch/mips/kernel/ptrace.c linux-3.10.40-vs2.3.6.8/arch/mips/kernel/ptrace.c
360 --- linux-3.10.40/arch/mips/kernel/ptrace.c     2013-05-31 13:44:42.000000000 +0000
361 +++ linux-3.10.40-vs2.3.6.8/arch/mips/kernel/ptrace.c   2013-08-22 20:29:59.000000000 +0000
362 @@ -25,6 +25,7 @@
363  #include <linux/security.h>
364  #include <linux/audit.h>
365  #include <linux/seccomp.h>
366 +#include <linux/vs_base.h>
367  
368  #include <asm/byteorder.h>
369  #include <asm/cpu.h>
370 @@ -262,6 +263,9 @@ long arch_ptrace(struct task_struct *chi
371         void __user *datavp = (void __user *) data;
372         unsigned long __user *datalp = (void __user *) data;
373  
374 +       if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
375 +               goto out;
376 +
377         switch (request) {
378         /* when I and D space are separate, these will need to be fixed. */
379         case PTRACE_PEEKTEXT: /* read word at location addr. */
380 diff -NurpP --minimal linux-3.10.40/arch/mips/kernel/scall32-o32.S linux-3.10.40-vs2.3.6.8/arch/mips/kernel/scall32-o32.S
381 --- linux-3.10.40/arch/mips/kernel/scall32-o32.S        2013-07-14 17:00:28.000000000 +0000
382 +++ linux-3.10.40-vs2.3.6.8/arch/mips/kernel/scall32-o32.S      2013-08-22 20:29:59.000000000 +0000
383 @@ -521,7 +521,7 @@ einval: li  v0, -ENOSYS
384         sys     sys_mq_timedreceive     5
385         sys     sys_mq_notify           2       /* 4275 */
386         sys     sys_mq_getsetattr       3
387 -       sys     sys_ni_syscall          0       /* sys_vserver */
388 +       sys     sys_vserver             3
389         sys     sys_waitid              5
390         sys     sys_ni_syscall          0       /* available, was setaltroot */
391         sys     sys_add_key             5       /* 4280 */
392 diff -NurpP --minimal linux-3.10.40/arch/mips/kernel/scall64-64.S linux-3.10.40-vs2.3.6.8/arch/mips/kernel/scall64-64.S
393 --- linux-3.10.40/arch/mips/kernel/scall64-64.S 2013-07-14 17:00:28.000000000 +0000
394 +++ linux-3.10.40-vs2.3.6.8/arch/mips/kernel/scall64-64.S       2013-08-22 20:29:59.000000000 +0000
395 @@ -351,7 +351,7 @@ sys_call_table:
396         PTR     sys_mq_timedreceive
397         PTR     sys_mq_notify
398         PTR     sys_mq_getsetattr               /* 5235 */
399 -       PTR     sys_ni_syscall                  /* sys_vserver */
400 +       PTR     sys_vserver
401         PTR     sys_waitid
402         PTR     sys_ni_syscall                  /* available, was setaltroot */
403         PTR     sys_add_key
404 diff -NurpP --minimal linux-3.10.40/arch/mips/kernel/scall64-n32.S linux-3.10.40-vs2.3.6.8/arch/mips/kernel/scall64-n32.S
405 --- linux-3.10.40/arch/mips/kernel/scall64-n32.S        2013-07-14 17:00:28.000000000 +0000
406 +++ linux-3.10.40-vs2.3.6.8/arch/mips/kernel/scall64-n32.S      2013-08-22 20:29:59.000000000 +0000
407 @@ -344,7 +344,7 @@ EXPORT(sysn32_call_table)
408         PTR     compat_sys_mq_timedreceive
409         PTR     compat_sys_mq_notify
410         PTR     compat_sys_mq_getsetattr
411 -       PTR     sys_ni_syscall                  /* 6240, sys_vserver */
412 +       PTR     sys32_vserver                   /* 6240 */
413         PTR     compat_sys_waitid
414         PTR     sys_ni_syscall                  /* available, was setaltroot */
415         PTR     sys_add_key
416 diff -NurpP --minimal linux-3.10.40/arch/mips/kernel/scall64-o32.S linux-3.10.40-vs2.3.6.8/arch/mips/kernel/scall64-o32.S
417 --- linux-3.10.40/arch/mips/kernel/scall64-o32.S        2013-07-14 17:00:28.000000000 +0000
418 +++ linux-3.10.40-vs2.3.6.8/arch/mips/kernel/scall64-o32.S      2013-08-22 20:29:59.000000000 +0000
419 @@ -469,7 +469,7 @@ sys_call_table:
420         PTR     compat_sys_mq_timedreceive
421         PTR     compat_sys_mq_notify            /* 4275 */
422         PTR     compat_sys_mq_getsetattr
423 -       PTR     sys_ni_syscall                  /* sys_vserver */
424 +       PTR     sys32_vserver
425         PTR     compat_sys_waitid
426         PTR     sys_ni_syscall                  /* available, was setaltroot */
427         PTR     sys_add_key                     /* 4280 */
428 diff -NurpP --minimal linux-3.10.40/arch/mips/kernel/traps.c linux-3.10.40-vs2.3.6.8/arch/mips/kernel/traps.c
429 --- linux-3.10.40/arch/mips/kernel/traps.c      2013-07-14 17:00:28.000000000 +0000
430 +++ linux-3.10.40-vs2.3.6.8/arch/mips/kernel/traps.c    2013-08-22 20:29:59.000000000 +0000
431 @@ -331,9 +331,10 @@ void show_registers(struct pt_regs *regs
432  
433         __show_regs(regs);
434         print_modules();
435 -       printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
436 -              current->comm, current->pid, current_thread_info(), current,
437 -             field, current_thread_info()->tp_value);
438 +       printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
439 +               current->comm, task_pid_nr(current), current->xid,
440 +               current_thread_info(), current,
441 +               field, current_thread_info()->tp_value);
442         if (cpu_has_userlocal) {
443                 unsigned long tls;
444  
445 diff -NurpP --minimal linux-3.10.40/arch/parisc/Kconfig linux-3.10.40-vs2.3.6.8/arch/parisc/Kconfig
446 --- linux-3.10.40/arch/parisc/Kconfig   2013-07-14 17:00:29.000000000 +0000
447 +++ linux-3.10.40-vs2.3.6.8/arch/parisc/Kconfig 2013-08-22 20:29:59.000000000 +0000
448 @@ -318,6 +318,8 @@ source "fs/Kconfig"
449  
450  source "arch/parisc/Kconfig.debug"
451  
452 +source "kernel/vserver/Kconfig"
453 +
454  source "security/Kconfig"
455  
456  source "crypto/Kconfig"
457 diff -NurpP --minimal linux-3.10.40/arch/parisc/kernel/syscall_table.S linux-3.10.40-vs2.3.6.8/arch/parisc/kernel/syscall_table.S
458 --- linux-3.10.40/arch/parisc/kernel/syscall_table.S    2013-07-14 17:00:31.000000000 +0000
459 +++ linux-3.10.40-vs2.3.6.8/arch/parisc/kernel/syscall_table.S  2013-08-22 20:29:59.000000000 +0000
460 @@ -358,7 +358,7 @@
461         ENTRY_COMP(mbind)               /* 260 */
462         ENTRY_COMP(get_mempolicy)
463         ENTRY_COMP(set_mempolicy)
464 -       ENTRY_SAME(ni_syscall)  /* 263: reserved for vserver */
465 +       ENTRY_DIFF(vserver)
466         ENTRY_SAME(add_key)
467         ENTRY_SAME(request_key)         /* 265 */
468         ENTRY_SAME(keyctl)
469 diff -NurpP --minimal linux-3.10.40/arch/parisc/kernel/traps.c linux-3.10.40-vs2.3.6.8/arch/parisc/kernel/traps.c
470 --- linux-3.10.40/arch/parisc/kernel/traps.c    2014-05-20 04:09:19.000000000 +0000
471 +++ linux-3.10.40-vs2.3.6.8/arch/parisc/kernel/traps.c  2013-11-13 17:17:15.000000000 +0000
472 @@ -229,8 +229,9 @@ void die_if_kernel(char *str, struct pt_
473                 if (err == 0)
474                         return; /* STFU */
475  
476 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
477 -                       current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
478 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
479 +                       current->comm, task_pid_nr(current), current->xid,
480 +                       str, err, regs->iaoq[0]);
481  #ifdef PRINT_USER_FAULTS
482                 /* XXX for debugging only */
483                 show_regs(regs);
484 @@ -263,8 +264,8 @@ void die_if_kernel(char *str, struct pt_
485                 pdc_console_restart();
486         
487         if (err)
488 -               printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
489 -                       current->comm, task_pid_nr(current), str, err);
490 +               printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
491 +                       current->comm, task_pid_nr(current), current->xid, str, err);
492  
493         /* Wot's wrong wif bein' racy? */
494         if (current->thread.flags & PARISC_KERNEL_DEATH) {
495 diff -NurpP --minimal linux-3.10.40/arch/parisc/mm/fault.c linux-3.10.40-vs2.3.6.8/arch/parisc/mm/fault.c
496 --- linux-3.10.40/arch/parisc/mm/fault.c        2013-05-31 13:44:44.000000000 +0000
497 +++ linux-3.10.40-vs2.3.6.8/arch/parisc/mm/fault.c      2013-08-22 20:29:59.000000000 +0000
498 @@ -257,8 +257,9 @@ bad_area:
499  
500  #ifdef PRINT_USER_FAULTS
501                 printk(KERN_DEBUG "\n");
502 -               printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
503 -                   task_pid_nr(tsk), tsk->comm, code, address);
504 +               printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
505 +                   "command='%s' type=%lu address=0x%08lx\n",
506 +                   task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
507                 if (vma) {
508                         printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
509                                         vma->vm_start, vma->vm_end);
510 diff -NurpP --minimal linux-3.10.40/arch/powerpc/Kconfig linux-3.10.40-vs2.3.6.8/arch/powerpc/Kconfig
511 --- linux-3.10.40/arch/powerpc/Kconfig  2014-05-20 04:09:19.000000000 +0000
512 +++ linux-3.10.40-vs2.3.6.8/arch/powerpc/Kconfig        2013-11-13 17:17:15.000000000 +0000
513 @@ -1010,6 +1010,8 @@ source "lib/Kconfig"
514  
515  source "arch/powerpc/Kconfig.debug"
516  
517 +source "kernel/vserver/Kconfig"
518 +
519  source "security/Kconfig"
520  
521  config KEYS_COMPAT
522 diff -NurpP --minimal linux-3.10.40/arch/powerpc/include/uapi/asm/unistd.h linux-3.10.40-vs2.3.6.8/arch/powerpc/include/uapi/asm/unistd.h
523 --- linux-3.10.40/arch/powerpc/include/uapi/asm/unistd.h        2013-05-31 13:44:44.000000000 +0000
524 +++ linux-3.10.40-vs2.3.6.8/arch/powerpc/include/uapi/asm/unistd.h      2013-08-22 20:29:59.000000000 +0000
525 @@ -275,7 +275,7 @@
526  #endif
527  #define __NR_rtas              255
528  #define __NR_sys_debug_setcontext 256
529 -/* Number 257 is reserved for vserver */
530 +#define __NR_vserver           257
531  #define __NR_migrate_pages     258
532  #define __NR_mbind             259
533  #define __NR_get_mempolicy     260
534 diff -NurpP --minimal linux-3.10.40/arch/powerpc/kernel/traps.c linux-3.10.40-vs2.3.6.8/arch/powerpc/kernel/traps.c
535 --- linux-3.10.40/arch/powerpc/kernel/traps.c   2014-05-20 04:09:20.000000000 +0000
536 +++ linux-3.10.40-vs2.3.6.8/arch/powerpc/kernel/traps.c 2013-11-13 17:17:15.000000000 +0000
537 @@ -1231,8 +1231,9 @@ void nonrecoverable_exception(struct pt_
538  
539  void trace_syscall(struct pt_regs *regs)
540  {
541 -       printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
542 -              current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
543 +       printk("Task: %p(%d:#%u), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld    %s\n",
544 +              current, task_pid_nr(current), current->xid,
545 +              regs->nip, regs->link, regs->gpr[0],
546                regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
547  }
548  
549 diff -NurpP --minimal linux-3.10.40/arch/s390/Kconfig linux-3.10.40-vs2.3.6.8/arch/s390/Kconfig
550 --- linux-3.10.40/arch/s390/Kconfig     2014-05-20 04:09:20.000000000 +0000
551 +++ linux-3.10.40-vs2.3.6.8/arch/s390/Kconfig   2014-04-22 03:48:10.000000000 +0000
552 @@ -580,6 +580,8 @@ source "fs/Kconfig"
553  
554  source "arch/s390/Kconfig.debug"
555  
556 +source "kernel/vserver/Kconfig"
557 +
558  source "security/Kconfig"
559  
560  source "crypto/Kconfig"
561 diff -NurpP --minimal linux-3.10.40/arch/s390/include/asm/tlb.h linux-3.10.40-vs2.3.6.8/arch/s390/include/asm/tlb.h
562 --- linux-3.10.40/arch/s390/include/asm/tlb.h   2014-05-20 04:09:20.000000000 +0000
563 +++ linux-3.10.40-vs2.3.6.8/arch/s390/include/asm/tlb.h 2013-11-13 17:17:15.000000000 +0000
564 @@ -24,6 +24,7 @@
565  #include <linux/mm.h>
566  #include <linux/pagemap.h>
567  #include <linux/swap.h>
568 +
569  #include <asm/processor.h>
570  #include <asm/pgalloc.h>
571  #include <asm/tlbflush.h>
572 diff -NurpP --minimal linux-3.10.40/arch/s390/include/uapi/asm/unistd.h linux-3.10.40-vs2.3.6.8/arch/s390/include/uapi/asm/unistd.h
573 --- linux-3.10.40/arch/s390/include/uapi/asm/unistd.h   2013-02-19 13:57:16.000000000 +0000
574 +++ linux-3.10.40-vs2.3.6.8/arch/s390/include/uapi/asm/unistd.h 2013-08-22 20:29:59.000000000 +0000
575 @@ -200,7 +200,7 @@
576  #define __NR_clock_gettime     (__NR_timer_create+6)
577  #define __NR_clock_getres      (__NR_timer_create+7)
578  #define __NR_clock_nanosleep   (__NR_timer_create+8)
579 -/* Number 263 is reserved for vserver */
580 +#define __NR_vserver           263
581  #define __NR_statfs64          265
582  #define __NR_fstatfs64         266
583  #define __NR_remap_file_pages  267
584 diff -NurpP --minimal linux-3.10.40/arch/s390/kernel/ptrace.c linux-3.10.40-vs2.3.6.8/arch/s390/kernel/ptrace.c
585 --- linux-3.10.40/arch/s390/kernel/ptrace.c     2012-12-11 03:30:57.000000000 +0000
586 +++ linux-3.10.40-vs2.3.6.8/arch/s390/kernel/ptrace.c   2013-08-22 20:29:59.000000000 +0000
587 @@ -21,6 +21,7 @@
588  #include <linux/tracehook.h>
589  #include <linux/seccomp.h>
590  #include <linux/compat.h>
591 +#include <linux/vs_base.h>
592  #include <trace/syscall.h>
593  #include <asm/segment.h>
594  #include <asm/page.h>
595 diff -NurpP --minimal linux-3.10.40/arch/s390/kernel/syscalls.S linux-3.10.40-vs2.3.6.8/arch/s390/kernel/syscalls.S
596 --- linux-3.10.40/arch/s390/kernel/syscalls.S   2013-07-14 17:00:34.000000000 +0000
597 +++ linux-3.10.40-vs2.3.6.8/arch/s390/kernel/syscalls.S 2013-08-22 20:29:59.000000000 +0000
598 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
599  SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper)       /* 260 */
600  SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
601  SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
602 -NI_SYSCALL                                                     /* reserved for vserver */
603 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
604  SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
605  SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
606  SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
607 diff -NurpP --minimal linux-3.10.40/arch/sh/Kconfig linux-3.10.40-vs2.3.6.8/arch/sh/Kconfig
608 --- linux-3.10.40/arch/sh/Kconfig       2013-07-14 17:00:35.000000000 +0000
609 +++ linux-3.10.40-vs2.3.6.8/arch/sh/Kconfig     2013-08-22 20:29:59.000000000 +0000
610 @@ -928,6 +928,8 @@ source "fs/Kconfig"
611  
612  source "arch/sh/Kconfig.debug"
613  
614 +source "kernel/vserver/Kconfig"
615 +
616  source "security/Kconfig"
617  
618  source "crypto/Kconfig"
619 diff -NurpP --minimal linux-3.10.40/arch/sh/kernel/irq.c linux-3.10.40-vs2.3.6.8/arch/sh/kernel/irq.c
620 --- linux-3.10.40/arch/sh/kernel/irq.c  2012-12-11 03:30:57.000000000 +0000
621 +++ linux-3.10.40-vs2.3.6.8/arch/sh/kernel/irq.c        2013-08-22 20:29:59.000000000 +0000
622 @@ -14,6 +14,7 @@
623  #include <linux/ftrace.h>
624  #include <linux/delay.h>
625  #include <linux/ratelimit.h>
626 +// #include <linux/vs_context.h>
627  #include <asm/processor.h>
628  #include <asm/machvec.h>
629  #include <asm/uaccess.h>
630 diff -NurpP --minimal linux-3.10.40/arch/sparc/Kconfig linux-3.10.40-vs2.3.6.8/arch/sparc/Kconfig
631 --- linux-3.10.40/arch/sparc/Kconfig    2014-05-20 04:09:20.000000000 +0000
632 +++ linux-3.10.40-vs2.3.6.8/arch/sparc/Kconfig  2014-05-20 04:31:54.000000000 +0000
633 @@ -550,6 +550,8 @@ source "fs/Kconfig"
634  
635  source "arch/sparc/Kconfig.debug"
636  
637 +source "kernel/vserver/Kconfig"
638 +
639  source "security/Kconfig"
640  
641  source "crypto/Kconfig"
642 diff -NurpP --minimal linux-3.10.40/arch/sparc/include/uapi/asm/unistd.h linux-3.10.40-vs2.3.6.8/arch/sparc/include/uapi/asm/unistd.h
643 --- linux-3.10.40/arch/sparc/include/uapi/asm/unistd.h  2013-02-19 13:57:17.000000000 +0000
644 +++ linux-3.10.40-vs2.3.6.8/arch/sparc/include/uapi/asm/unistd.h        2013-08-22 20:29:59.000000000 +0000
645 @@ -332,7 +332,7 @@
646  #define __NR_timer_getoverrun  264
647  #define __NR_timer_delete      265
648  #define __NR_timer_create      266
649 -/* #define __NR_vserver                267 Reserved for VSERVER */
650 +#define __NR_vserver           267
651  #define __NR_io_setup          268
652  #define __NR_io_destroy                269
653  #define __NR_io_submit         270
654 diff -NurpP --minimal linux-3.10.40/arch/sparc/kernel/systbls_32.S linux-3.10.40-vs2.3.6.8/arch/sparc/kernel/systbls_32.S
655 --- linux-3.10.40/arch/sparc/kernel/systbls_32.S        2013-05-31 13:44:48.000000000 +0000
656 +++ linux-3.10.40-vs2.3.6.8/arch/sparc/kernel/systbls_32.S      2013-08-22 20:29:59.000000000 +0000
657 @@ -70,7 +70,7 @@ sys_call_table:
658  /*250*/        .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
659  /*255*/        .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
660  /*260*/        .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
661 -/*265*/        .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
662 +/*265*/        .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
663  /*270*/        .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
664  /*275*/        .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
665  /*280*/        .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
666 diff -NurpP --minimal linux-3.10.40/arch/sparc/kernel/systbls_64.S linux-3.10.40-vs2.3.6.8/arch/sparc/kernel/systbls_64.S
667 --- linux-3.10.40/arch/sparc/kernel/systbls_64.S        2013-07-14 17:00:35.000000000 +0000
668 +++ linux-3.10.40-vs2.3.6.8/arch/sparc/kernel/systbls_64.S      2013-08-22 20:29:59.000000000 +0000
669 @@ -71,7 +71,7 @@ sys_call_table32:
670  /*250*/        .word sys_mremap, compat_sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
671         .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
672  /*260*/        .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
673 -       .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
674 +       .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
675  /*270*/        .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
676         .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
677  /*280*/        .word sys_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
678 @@ -149,7 +149,7 @@ sys_call_table:
679  /*250*/        .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
680         .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
681  /*260*/        .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
682 -       .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
683 +       .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
684  /*270*/        .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
685         .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
686  /*280*/        .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
687 diff -NurpP --minimal linux-3.10.40/arch/um/Kconfig.rest linux-3.10.40-vs2.3.6.8/arch/um/Kconfig.rest
688 --- linux-3.10.40/arch/um/Kconfig.rest  2012-12-11 03:30:57.000000000 +0000
689 +++ linux-3.10.40-vs2.3.6.8/arch/um/Kconfig.rest        2013-08-22 20:29:59.000000000 +0000
690 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
691  
692  source "fs/Kconfig"
693  
694 +source "kernel/vserver/Kconfig"
695 +
696  source "security/Kconfig"
697  
698  source "crypto/Kconfig"
699 diff -NurpP --minimal linux-3.10.40/arch/x86/Kconfig linux-3.10.40-vs2.3.6.8/arch/x86/Kconfig
700 --- linux-3.10.40/arch/x86/Kconfig      2013-07-14 17:00:36.000000000 +0000
701 +++ linux-3.10.40-vs2.3.6.8/arch/x86/Kconfig    2013-08-22 20:29:59.000000000 +0000
702 @@ -2339,6 +2339,8 @@ source "fs/Kconfig"
703  
704  source "arch/x86/Kconfig.debug"
705  
706 +source "kernel/vserver/Kconfig"
707 +
708  source "security/Kconfig"
709  
710  source "crypto/Kconfig"
711 diff -NurpP --minimal linux-3.10.40/arch/x86/syscalls/syscall_32.tbl linux-3.10.40-vs2.3.6.8/arch/x86/syscalls/syscall_32.tbl
712 --- linux-3.10.40/arch/x86/syscalls/syscall_32.tbl      2013-07-14 17:00:37.000000000 +0000
713 +++ linux-3.10.40-vs2.3.6.8/arch/x86/syscalls/syscall_32.tbl    2013-08-22 20:29:59.000000000 +0000
714 @@ -279,7 +279,7 @@
715  270    i386    tgkill                  sys_tgkill
716  271    i386    utimes                  sys_utimes                      compat_sys_utimes
717  272    i386    fadvise64_64            sys_fadvise64_64                sys32_fadvise64_64
718 -273    i386    vserver
719 +273    i386    vserver                 sys_vserver                     sys32_vserver
720  274    i386    mbind                   sys_mbind
721  275    i386    get_mempolicy           sys_get_mempolicy               compat_sys_get_mempolicy
722  276    i386    set_mempolicy           sys_set_mempolicy
723 diff -NurpP --minimal linux-3.10.40/arch/x86/syscalls/syscall_64.tbl linux-3.10.40-vs2.3.6.8/arch/x86/syscalls/syscall_64.tbl
724 --- linux-3.10.40/arch/x86/syscalls/syscall_64.tbl      2013-05-31 13:44:50.000000000 +0000
725 +++ linux-3.10.40-vs2.3.6.8/arch/x86/syscalls/syscall_64.tbl    2013-08-22 20:29:59.000000000 +0000
726 @@ -242,7 +242,7 @@
727  233    common  epoll_ctl               sys_epoll_ctl
728  234    common  tgkill                  sys_tgkill
729  235    common  utimes                  sys_utimes
730 -236    64      vserver
731 +236    64      vserver                 sys_vserver
732  237    common  mbind                   sys_mbind
733  238    common  set_mempolicy           sys_set_mempolicy
734  239    common  get_mempolicy           sys_get_mempolicy
735 diff -NurpP --minimal linux-3.10.40/drivers/block/Kconfig linux-3.10.40-vs2.3.6.8/drivers/block/Kconfig
736 --- linux-3.10.40/drivers/block/Kconfig 2013-05-31 13:44:51.000000000 +0000
737 +++ linux-3.10.40-vs2.3.6.8/drivers/block/Kconfig       2013-08-22 20:29:59.000000000 +0000
738 @@ -278,6 +278,13 @@ config BLK_DEV_CRYPTOLOOP
739  
740  source "drivers/block/drbd/Kconfig"
741  
742 +config BLK_DEV_VROOT
743 +       tristate "Virtual Root device support"
744 +       depends on QUOTACTL
745 +       ---help---
746 +         Saying Y here will allow you to use quota/fs ioctls on a shared
747 +         partition within a virtual server without compromising security.
748 +
749  config BLK_DEV_NBD
750         tristate "Network block device support"
751         depends on NET
752 diff -NurpP --minimal linux-3.10.40/drivers/block/Makefile linux-3.10.40-vs2.3.6.8/drivers/block/Makefile
753 --- linux-3.10.40/drivers/block/Makefile        2013-07-14 17:00:41.000000000 +0000
754 +++ linux-3.10.40-vs2.3.6.8/drivers/block/Makefile      2013-08-22 20:29:59.000000000 +0000
755 @@ -33,6 +33,7 @@ obj-$(CONFIG_VIRTIO_BLK)      += virtio_blk.o
756  obj-$(CONFIG_VIODASD)          += viodasd.o
757  obj-$(CONFIG_BLK_DEV_SX8)      += sx8.o
758  obj-$(CONFIG_BLK_DEV_HD)       += hd.o
759 +obj-$(CONFIG_BLK_DEV_VROOT)    += vroot.o
760  
761  obj-$(CONFIG_XEN_BLKDEV_FRONTEND)      += xen-blkfront.o
762  obj-$(CONFIG_XEN_BLKDEV_BACKEND)       += xen-blkback/
763 diff -NurpP --minimal linux-3.10.40/drivers/block/loop.c linux-3.10.40-vs2.3.6.8/drivers/block/loop.c
764 --- linux-3.10.40/drivers/block/loop.c  2014-05-20 04:09:22.000000000 +0000
765 +++ linux-3.10.40-vs2.3.6.8/drivers/block/loop.c        2013-12-23 17:42:39.000000000 +0000
766 @@ -76,6 +76,7 @@
767  #include <linux/sysfs.h>
768  #include <linux/miscdevice.h>
769  #include <linux/falloc.h>
770 +#include <linux/vs_context.h>
771  
772  #include <asm/uaccess.h>
773  
774 @@ -884,6 +885,7 @@ static int loop_set_fd(struct loop_devic
775         lo->lo_blocksize = lo_blocksize;
776         lo->lo_device = bdev;
777         lo->lo_flags = lo_flags;
778 +       lo->lo_xid = vx_current_xid();
779         lo->lo_backing_file = file;
780         lo->transfer = transfer_none;
781         lo->ioctl = NULL;
782 @@ -1028,6 +1030,7 @@ static int loop_clr_fd(struct loop_devic
783         lo->lo_sizelimit = 0;
784         lo->lo_encrypt_key_size = 0;
785         lo->lo_thread = NULL;
786 +       lo->lo_xid = 0;
787         memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
788         memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
789         memset(lo->lo_file_name, 0, LO_NAME_SIZE);
790 @@ -1071,7 +1074,7 @@ loop_set_status(struct loop_device *lo,
791  
792         if (lo->lo_encrypt_key_size &&
793             !uid_eq(lo->lo_key_owner, uid) &&
794 -           !capable(CAP_SYS_ADMIN))
795 +           !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
796                 return -EPERM;
797         if (lo->lo_state != Lo_bound)
798                 return -ENXIO;
799 @@ -1161,7 +1164,8 @@ loop_get_status(struct loop_device *lo,
800         memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
801         info->lo_encrypt_type =
802                 lo->lo_encryption ? lo->lo_encryption->number : 0;
803 -       if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
804 +       if (lo->lo_encrypt_key_size &&
805 +               vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
806                 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
807                 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
808                        lo->lo_encrypt_key_size);
809 @@ -1503,6 +1507,11 @@ static int lo_open(struct block_device *
810                 goto out;
811         }
812  
813 +       if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
814 +               err = -EACCES;
815 +               goto out;
816 +       }
817 +
818         mutex_lock(&lo->lo_ctl_mutex);
819         lo->lo_refcnt++;
820         mutex_unlock(&lo->lo_ctl_mutex);
821 diff -NurpP --minimal linux-3.10.40/drivers/block/vroot.c linux-3.10.40-vs2.3.6.8/drivers/block/vroot.c
822 --- linux-3.10.40/drivers/block/vroot.c 1970-01-01 00:00:00.000000000 +0000
823 +++ linux-3.10.40-vs2.3.6.8/drivers/block/vroot.c       2013-08-23 00:23:45.000000000 +0000
824 @@ -0,0 +1,290 @@
825 +/*
826 + *  linux/drivers/block/vroot.c
827 + *
828 + *  written by Herbert Pötzl, 9/11/2002
829 + *  ported to 2.6.10 by Herbert Pötzl, 30/12/2004
830 + *
831 + *  based on the loop.c code by Theodore Ts'o.
832 + *
833 + * Copyright (C) 2002-2007 by Herbert Pötzl.
834 + * Redistribution of this file is permitted under the
835 + * GNU General Public License.
836 + *
837 + */
838 +
839 +#include <linux/module.h>
840 +#include <linux/moduleparam.h>
841 +#include <linux/file.h>
842 +#include <linux/major.h>
843 +#include <linux/blkdev.h>
844 +#include <linux/slab.h>
845 +
846 +#include <linux/vroot.h>
847 +#include <linux/vs_context.h>
848 +
849 +
850 +static int max_vroot = 8;
851 +
852 +static struct vroot_device *vroot_dev;
853 +static struct gendisk **disks;
854 +
855 +
856 +static int vroot_set_dev(
857 +       struct vroot_device *vr,
858 +       struct block_device *bdev,
859 +       unsigned int arg)
860 +{
861 +       struct block_device *real_bdev;
862 +       struct file *file;
863 +       struct inode *inode;
864 +       int error;
865 +
866 +       error = -EBUSY;
867 +       if (vr->vr_state != Vr_unbound)
868 +               goto out;
869 +
870 +       error = -EBADF;
871 +       file = fget(arg);
872 +       if (!file)
873 +               goto out;
874 +
875 +       error = -EINVAL;
876 +       inode = file->f_dentry->d_inode;
877 +
878 +
879 +       if (S_ISBLK(inode->i_mode)) {
880 +               real_bdev = inode->i_bdev;
881 +               vr->vr_device = real_bdev;
882 +               __iget(real_bdev->bd_inode);
883 +       } else
884 +               goto out_fput;
885 +
886 +       vxdprintk(VXD_CBIT(misc, 0),
887 +               "vroot[%d]_set_dev: dev=" VXF_DEV,
888 +               vr->vr_number, VXD_DEV(real_bdev));
889 +
890 +       vr->vr_state = Vr_bound;
891 +       error = 0;
892 +
893 + out_fput:
894 +       fput(file);
895 + out:
896 +       return error;
897 +}
898 +
899 +static int vroot_clr_dev(
900 +       struct vroot_device *vr,
901 +       struct block_device *bdev)
902 +{
903 +       struct block_device *real_bdev;
904 +
905 +       if (vr->vr_state != Vr_bound)
906 +               return -ENXIO;
907 +       if (vr->vr_refcnt > 1)  /* we needed one fd for the ioctl */
908 +               return -EBUSY;
909 +
910 +       real_bdev = vr->vr_device;
911 +
912 +       vxdprintk(VXD_CBIT(misc, 0),
913 +               "vroot[%d]_clr_dev: dev=" VXF_DEV,
914 +               vr->vr_number, VXD_DEV(real_bdev));
915 +
916 +       bdput(real_bdev);
917 +       vr->vr_state = Vr_unbound;
918 +       vr->vr_device = NULL;
919 +       return 0;
920 +}
921 +
922 +
923 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
924 +       unsigned int cmd, unsigned long arg)
925 +{
926 +       struct vroot_device *vr = bdev->bd_disk->private_data;
927 +       int err;
928 +
929 +       down(&vr->vr_ctl_mutex);
930 +       switch (cmd) {
931 +       case VROOT_SET_DEV:
932 +               err = vroot_set_dev(vr, bdev, arg);
933 +               break;
934 +       case VROOT_CLR_DEV:
935 +               err = vroot_clr_dev(vr, bdev);
936 +               break;
937 +       default:
938 +               err = -EINVAL;
939 +               break;
940 +       }
941 +       up(&vr->vr_ctl_mutex);
942 +       return err;
943 +}
944 +
945 +static int vr_open(struct block_device *bdev, fmode_t mode)
946 +{
947 +       struct vroot_device *vr = bdev->bd_disk->private_data;
948 +
949 +       down(&vr->vr_ctl_mutex);
950 +       vr->vr_refcnt++;
951 +       up(&vr->vr_ctl_mutex);
952 +       return 0;
953 +}
954 +
955 +static void vr_release(struct gendisk *disk, fmode_t mode)
956 +{
957 +       struct vroot_device *vr = disk->private_data;
958 +
959 +       down(&vr->vr_ctl_mutex);
960 +       --vr->vr_refcnt;
961 +       up(&vr->vr_ctl_mutex);
962 +}
963 +
964 +static struct block_device_operations vr_fops = {
965 +       .owner =        THIS_MODULE,
966 +       .open =         vr_open,
967 +       .release =      vr_release,
968 +       .ioctl =        vr_ioctl,
969 +};
970 +
971 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
972 +{
973 +       printk("vroot_make_request %p, %p\n", q, bio);
974 +       bio_io_error(bio);
975 +}
976 +
977 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
978 +{
979 +       struct inode *inode = bdev->bd_inode;
980 +       struct vroot_device *vr;
981 +       struct block_device *real_bdev;
982 +       int minor = iminor(inode);
983 +
984 +       vr = &vroot_dev[minor];
985 +       real_bdev = vr->vr_device;
986 +
987 +       vxdprintk(VXD_CBIT(misc, 0),
988 +               "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
989 +               vr->vr_number, VXD_DEV(real_bdev));
990 +
991 +       if (vr->vr_state != Vr_bound)
992 +               return ERR_PTR(-ENXIO);
993 +
994 +       __iget(real_bdev->bd_inode);
995 +       return real_bdev;
996 +}
997 +
998 +
999 +
1000 +/*
1001 + * And now the modules code and kernel interface.
1002 + */
1003 +
1004 +module_param(max_vroot, int, 0);
1005 +
1006 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1007 +MODULE_LICENSE("GPL");
1008 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1009 +
1010 +MODULE_AUTHOR ("Herbert Pötzl");
1011 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1012 +
1013 +
1014 +int __init vroot_init(void)
1015 +{
1016 +       int err, i;
1017 +
1018 +       if (max_vroot < 1 || max_vroot > 256) {
1019 +               max_vroot = MAX_VROOT_DEFAULT;
1020 +               printk(KERN_WARNING "vroot: invalid max_vroot "
1021 +                       "(must be between 1 and 256), "
1022 +                       "using default (%d)\n", max_vroot);
1023 +       }
1024 +
1025 +       if (register_blkdev(VROOT_MAJOR, "vroot"))
1026 +               return -EIO;
1027 +
1028 +       err = -ENOMEM;
1029 +       vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1030 +       if (!vroot_dev)
1031 +               goto out_mem1;
1032 +       memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1033 +
1034 +       disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1035 +       if (!disks)
1036 +               goto out_mem2;
1037 +
1038 +       for (i = 0; i < max_vroot; i++) {
1039 +               disks[i] = alloc_disk(1);
1040 +               if (!disks[i])
1041 +                       goto out_mem3;
1042 +               disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1043 +               if (!disks[i]->queue)
1044 +                       goto out_mem3;
1045 +               blk_queue_make_request(disks[i]->queue, vroot_make_request);
1046 +       }
1047 +
1048 +       for (i = 0; i < max_vroot; i++) {
1049 +               struct vroot_device *vr = &vroot_dev[i];
1050 +               struct gendisk *disk = disks[i];
1051 +
1052 +               memset(vr, 0, sizeof(*vr));
1053 +               sema_init(&vr->vr_ctl_mutex, 1);
1054 +               vr->vr_number = i;
1055 +               disk->major = VROOT_MAJOR;
1056 +               disk->first_minor = i;
1057 +               disk->fops = &vr_fops;
1058 +               sprintf(disk->disk_name, "vroot%d", i);
1059 +               disk->private_data = vr;
1060 +       }
1061 +
1062 +       err = register_vroot_grb(&__vroot_get_real_bdev);
1063 +       if (err)
1064 +               goto out_mem3;
1065 +
1066 +       for (i = 0; i < max_vroot; i++)
1067 +               add_disk(disks[i]);
1068 +       printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1069 +       return 0;
1070 +
1071 +out_mem3:
1072 +       while (i--)
1073 +               put_disk(disks[i]);
1074 +       kfree(disks);
1075 +out_mem2:
1076 +       kfree(vroot_dev);
1077 +out_mem1:
1078 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1079 +       printk(KERN_ERR "vroot: ran out of memory\n");
1080 +       return err;
1081 +}
1082 +
1083 +void vroot_exit(void)
1084 +{
1085 +       int i;
1086 +
1087 +       if (unregister_vroot_grb(&__vroot_get_real_bdev))
1088 +               printk(KERN_WARNING "vroot: cannot unregister grb\n");
1089 +
1090 +       for (i = 0; i < max_vroot; i++) {
1091 +               del_gendisk(disks[i]);
1092 +               put_disk(disks[i]);
1093 +       }
1094 +       unregister_blkdev(VROOT_MAJOR, "vroot");
1095 +
1096 +       kfree(disks);
1097 +       kfree(vroot_dev);
1098 +}
1099 +
1100 +module_init(vroot_init);
1101 +module_exit(vroot_exit);
1102 +
1103 +#ifndef MODULE
1104 +
1105 +static int __init max_vroot_setup(char *str)
1106 +{
1107 +       max_vroot = simple_strtol(str, NULL, 0);
1108 +       return 1;
1109 +}
1110 +
1111 +__setup("max_vroot=", max_vroot_setup);
1112 +
1113 +#endif
1114 +
1115 diff -NurpP --minimal linux-3.10.40/drivers/infiniband/Kconfig linux-3.10.40-vs2.3.6.8/drivers/infiniband/Kconfig
1116 --- linux-3.10.40/drivers/infiniband/Kconfig    2013-07-14 17:00:49.000000000 +0000
1117 +++ linux-3.10.40-vs2.3.6.8/drivers/infiniband/Kconfig  2013-08-22 20:29:59.000000000 +0000
1118 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1119  config INFINIBAND_ADDR_TRANS
1120         bool
1121         depends on INET
1122 -       depends on !(INFINIBAND = y && IPV6 = m)
1123 +       depends on !(INFINIBAND = y && IPV6 = y)
1124         default y
1125  
1126  source "drivers/infiniband/hw/mthca/Kconfig"
1127 diff -NurpP --minimal linux-3.10.40/drivers/infiniband/core/addr.c linux-3.10.40-vs2.3.6.8/drivers/infiniband/core/addr.c
1128 --- linux-3.10.40/drivers/infiniband/core/addr.c        2012-12-11 03:30:57.000000000 +0000
1129 +++ linux-3.10.40-vs2.3.6.8/drivers/infiniband/core/addr.c      2013-08-22 20:29:59.000000000 +0000
1130 @@ -261,7 +261,7 @@ static int addr6_resolve(struct sockaddr
1131  
1132         if (ipv6_addr_any(&fl6.saddr)) {
1133                 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1134 -                                        &fl6.daddr, 0, &fl6.saddr);
1135 +                                        &fl6.daddr, 0, &fl6.saddr, NULL);
1136                 if (ret)
1137                         goto put;
1138  
1139 diff -NurpP --minimal linux-3.10.40/drivers/md/dm-ioctl.c linux-3.10.40-vs2.3.6.8/drivers/md/dm-ioctl.c
1140 --- linux-3.10.40/drivers/md/dm-ioctl.c 2014-05-20 04:09:25.000000000 +0000
1141 +++ linux-3.10.40-vs2.3.6.8/drivers/md/dm-ioctl.c       2013-11-13 17:17:15.000000000 +0000
1142 @@ -16,6 +16,7 @@
1143  #include <linux/dm-ioctl.h>
1144  #include <linux/hdreg.h>
1145  #include <linux/compat.h>
1146 +#include <linux/vs_context.h>
1147  
1148  #include <asm/uaccess.h>
1149  
1150 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1151         unsigned int h = hash_str(str);
1152  
1153         list_for_each_entry (hc, _name_buckets + h, name_list)
1154 -               if (!strcmp(hc->name, str)) {
1155 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1156 +                       !strcmp(hc->name, str)) {
1157                         dm_get(hc->md);
1158                         return hc;
1159                 }
1160 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1161         unsigned int h = hash_str(str);
1162  
1163         list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1164 -               if (!strcmp(hc->uuid, str)) {
1165 +               if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1166 +                       !strcmp(hc->uuid, str)) {
1167                         dm_get(hc->md);
1168                         return hc;
1169                 }
1170 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1171  static struct hash_cell *__get_dev_cell(uint64_t dev)
1172  {
1173         struct mapped_device *md;
1174 -       struct hash_cell *hc;
1175 +       struct hash_cell *hc = NULL;
1176  
1177         md = dm_get_md(huge_decode_dev(dev));
1178         if (!md)
1179                 return NULL;
1180  
1181 -       hc = dm_get_mdptr(md);
1182 +       if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1183 +               hc = dm_get_mdptr(md);
1184 +
1185         if (!hc) {
1186                 dm_put(md);
1187                 return NULL;
1188 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1189  
1190  static int remove_all(struct dm_ioctl *param, size_t param_size)
1191  {
1192 +       if (!vx_check(0, VS_ADMIN))
1193 +               return -EPERM;
1194 +
1195         dm_hash_remove_all(1);
1196         param->data_size = 0;
1197         return 0;
1198 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl
1199          */
1200         for (i = 0; i < NUM_BUCKETS; i++) {
1201                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1202 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1203 +                               continue;
1204                         needed += sizeof(struct dm_name_list);
1205                         needed += strlen(hc->name) + 1;
1206                         needed += ALIGN_MASK;
1207 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl
1208          */
1209         for (i = 0; i < NUM_BUCKETS; i++) {
1210                 list_for_each_entry (hc, _name_buckets + i, name_list) {
1211 +                       if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1212 +                               continue;
1213                         if (old_nl)
1214                                 old_nl->next = (uint32_t) ((void *) nl -
1215                                                            (void *) old_nl);
1216 @@ -1725,8 +1737,8 @@ static int ctl_ioctl(uint command, struc
1217         size_t input_param_size;
1218         struct dm_ioctl param_kernel;
1219  
1220 -       /* only root can play with this */
1221 -       if (!capable(CAP_SYS_ADMIN))
1222 +       /* only root and certain contexts can play with this */
1223 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1224                 return -EACCES;
1225  
1226         if (_IOC_TYPE(command) != DM_IOCTL)
1227 diff -NurpP --minimal linux-3.10.40/drivers/md/dm.c linux-3.10.40-vs2.3.6.8/drivers/md/dm.c
1228 --- linux-3.10.40/drivers/md/dm.c       2014-05-20 04:09:25.000000000 +0000
1229 +++ linux-3.10.40-vs2.3.6.8/drivers/md/dm.c     2014-03-12 13:18:23.000000000 +0000
1230 @@ -19,6 +19,7 @@
1231  #include <linux/idr.h>
1232  #include <linux/hdreg.h>
1233  #include <linux/delay.h>
1234 +#include <linux/vs_base.h>
1235  
1236  #include <trace/events/block.h>
1237  
1238 @@ -125,6 +126,7 @@ struct mapped_device {
1239         rwlock_t map_lock;
1240         atomic_t holders;
1241         atomic_t open_count;
1242 +       vxid_t xid;
1243  
1244         unsigned long flags;
1245  
1246 @@ -317,6 +319,7 @@ int dm_deleting_md(struct mapped_device
1247  static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1248  {
1249         struct mapped_device *md;
1250 +       int ret = -ENXIO;
1251  
1252         spin_lock(&_minor_lock);
1253  
1254 @@ -325,18 +328,19 @@ static int dm_blk_open(struct block_devi
1255                 goto out;
1256  
1257         if (test_bit(DMF_FREEING, &md->flags) ||
1258 -           dm_deleting_md(md)) {
1259 -               md = NULL;
1260 +           dm_deleting_md(md))
1261 +               goto out;
1262 +
1263 +       ret = -EACCES;
1264 +       if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1265                 goto out;
1266 -       }
1267  
1268         dm_get(md);
1269         atomic_inc(&md->open_count);
1270 -
1271 +       ret = 0;
1272  out:
1273         spin_unlock(&_minor_lock);
1274 -
1275 -       return md ? 0 : -ENXIO;
1276 +       return ret;
1277  }
1278  
1279  static void dm_blk_close(struct gendisk *disk, fmode_t mode)
1280 @@ -552,6 +556,14 @@ int dm_set_geometry(struct mapped_device
1281         return 0;
1282  }
1283  
1284 +/*
1285 + * Get the xid associated with a dm device
1286 + */
1287 +vxid_t dm_get_xid(struct mapped_device *md)
1288 +{
1289 +       return md->xid;
1290 +}
1291 +
1292  /*-----------------------------------------------------------------
1293   * CRUD START:
1294   *   A more elegant soln is in the works that uses the queue
1295 @@ -1889,6 +1901,7 @@ static struct mapped_device *alloc_dev(i
1296         INIT_LIST_HEAD(&md->uevent_list);
1297         spin_lock_init(&md->uevent_lock);
1298  
1299 +       md->xid = vx_current_xid();
1300         md->queue = blk_alloc_queue(GFP_KERNEL);
1301         if (!md->queue)
1302                 goto bad_queue;
1303 diff -NurpP --minimal linux-3.10.40/drivers/md/dm.h linux-3.10.40-vs2.3.6.8/drivers/md/dm.h
1304 --- linux-3.10.40/drivers/md/dm.h       2014-05-20 04:09:25.000000000 +0000
1305 +++ linux-3.10.40-vs2.3.6.8/drivers/md/dm.h     2014-03-12 13:18:23.000000000 +0000
1306 @@ -48,6 +48,8 @@ struct dm_dev_internal {
1307  struct dm_table;
1308  struct dm_md_mempools;
1309  
1310 +vxid_t dm_get_xid(struct mapped_device *md);
1311 +
1312  /*-----------------------------------------------------------------
1313   * Internal table functions.
1314   *---------------------------------------------------------------*/
1315 diff -NurpP --minimal linux-3.10.40/drivers/net/tun.c linux-3.10.40-vs2.3.6.8/drivers/net/tun.c
1316 --- linux-3.10.40/drivers/net/tun.c     2014-05-20 04:09:31.000000000 +0000
1317 +++ linux-3.10.40-vs2.3.6.8/drivers/net/tun.c   2014-01-22 19:00:34.000000000 +0000
1318 @@ -64,6 +64,7 @@
1319  #include <linux/nsproxy.h>
1320  #include <linux/virtio_net.h>
1321  #include <linux/rcupdate.h>
1322 +#include <linux/vs_network.h>
1323  #include <net/net_namespace.h>
1324  #include <net/netns/generic.h>
1325  #include <net/rtnetlink.h>
1326 @@ -164,6 +165,7 @@ struct tun_struct {
1327         unsigned int            flags;
1328         kuid_t                  owner;
1329         kgid_t                  group;
1330 +       vnid_t                  nid;
1331  
1332         struct net_device       *dev;
1333         netdev_features_t       set_features;
1334 @@ -380,6 +382,7 @@ static inline bool tun_not_capable(struc
1335         return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1336                   (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1337                 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1338 +               /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1339  }
1340  
1341  static void tun_set_real_num_queues(struct tun_struct *tun)
1342 @@ -1435,6 +1438,7 @@ static void tun_setup(struct net_device
1343  
1344         tun->owner = INVALID_UID;
1345         tun->group = INVALID_GID;
1346 +       tun->nid = nx_current_nid();
1347  
1348         dev->ethtool_ops = &tun_ethtool_ops;
1349         dev->destructor = tun_free_netdev;
1350 @@ -1626,6 +1630,9 @@ static int tun_set_iff(struct net *net,
1351                 if (err < 0)
1352                         return err;
1353  
1354 +               if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1355 +                       return -EPERM;
1356 +
1357                 err = tun_attach(tun, file);
1358                 if (err < 0)
1359                         return err;
1360 @@ -1644,7 +1651,7 @@ static int tun_set_iff(struct net *net,
1361                 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1362                              MAX_TAP_QUEUES : 1;
1363  
1364 -               if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1365 +               if (!nx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1366                         return -EPERM;
1367                 err = security_tun_dev_create();
1368                 if (err < 0)
1369 @@ -1995,6 +2002,16 @@ static long __tun_chr_ioctl(struct file
1370                           from_kgid(&init_user_ns, tun->group));
1371                 break;
1372  
1373 +       case TUNSETNID:
1374 +               if (!capable(CAP_CONTEXT))
1375 +                       return -EPERM;
1376 +
1377 +               /* Set nid owner of the device */
1378 +               tun->nid = (vnid_t) arg;
1379 +
1380 +               tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1381 +               break;
1382 +
1383         case TUNSETLINK:
1384                 /* Only allow setting the type when the interface is down */
1385                 if (tun->dev->flags & IFF_UP) {
1386 diff -NurpP --minimal linux-3.10.40/drivers/tty/sysrq.c linux-3.10.40-vs2.3.6.8/drivers/tty/sysrq.c
1387 --- linux-3.10.40/drivers/tty/sysrq.c   2013-07-14 17:01:22.000000000 +0000
1388 +++ linux-3.10.40-vs2.3.6.8/drivers/tty/sysrq.c 2013-08-22 20:58:35.000000000 +0000
1389 @@ -44,6 +44,7 @@
1390  #include <linux/uaccess.h>
1391  #include <linux/moduleparam.h>
1392  #include <linux/jiffies.h>
1393 +#include <linux/vserver/debug.h>
1394  
1395  #include <asm/ptrace.h>
1396  #include <asm/irq_regs.h>
1397 @@ -405,6 +406,21 @@ static struct sysrq_key_op sysrq_unrt_op
1398         .enable_mask    = SYSRQ_ENABLE_RTNICE,
1399  };
1400  
1401 +
1402 +#ifdef CONFIG_VSERVER_DEBUG
1403 +static void sysrq_handle_vxinfo(int key)
1404 +{
1405 +       dump_vx_info_inactive((key == 'x') ? 0 : 1);
1406 +}
1407 +
1408 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1409 +       .handler        = sysrq_handle_vxinfo,
1410 +       .help_msg       = "conteXt",
1411 +       .action_msg     = "Show Context Info",
1412 +       .enable_mask    = SYSRQ_ENABLE_DUMP,
1413 +};
1414 +#endif
1415 +
1416  /* Key Operations table and lock */
1417  static DEFINE_SPINLOCK(sysrq_key_table_lock);
1418  
1419 @@ -460,7 +476,11 @@ static struct sysrq_key_op *sysrq_key_ta
1420         &sysrq_showstate_blocked_op,    /* w */
1421         /* x: May be registered on ppc/powerpc for xmon */
1422         /* x: May be registered on sparc64 for global PMU dump */
1423 +#ifdef CONFIG_VSERVER_DEBUG
1424 +       &sysrq_showvxinfo_op,           /* x */
1425 +#else
1426         NULL,                           /* x */
1427 +#endif
1428         /* y: May be registered on sparc64 for global register dump */
1429         NULL,                           /* y */
1430         &sysrq_ftrace_dump_op,          /* z */
1431 @@ -475,6 +495,8 @@ static int sysrq_key_table_key2index(int
1432                 retval = key - '0';
1433         else if ((key >= 'a') && (key <= 'z'))
1434                 retval = key + 10 - 'a';
1435 +       else if ((key >= 'A') && (key <= 'Z'))
1436 +               retval = key + 10 - 'A';
1437         else
1438                 retval = -1;
1439         return retval;
1440 diff -NurpP --minimal linux-3.10.40/drivers/tty/tty_io.c linux-3.10.40-vs2.3.6.8/drivers/tty/tty_io.c
1441 --- linux-3.10.40/drivers/tty/tty_io.c  2014-05-20 04:09:35.000000000 +0000
1442 +++ linux-3.10.40-vs2.3.6.8/drivers/tty/tty_io.c        2014-05-20 04:31:55.000000000 +0000
1443 @@ -104,6 +104,7 @@
1444  
1445  #include <linux/kmod.h>
1446  #include <linux/nsproxy.h>
1447 +#include <linux/vs_pid.h>
1448  
1449  #undef TTY_DEBUG_HANGUP
1450  
1451 @@ -2214,7 +2215,8 @@ static int tiocsti(struct tty_struct *tt
1452         char ch, mbz = 0;
1453         struct tty_ldisc *ld;
1454  
1455 -       if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1456 +       if (((current->signal->tty != tty) &&
1457 +               !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1458                 return -EPERM;
1459         if (get_user(ch, p))
1460                 return -EFAULT;
1461 @@ -2502,6 +2504,7 @@ static int tiocspgrp(struct tty_struct *
1462                 return -ENOTTY;
1463         if (get_user(pgrp_nr, p))
1464                 return -EFAULT;
1465 +       pgrp_nr = vx_rmap_pid(pgrp_nr);
1466         if (pgrp_nr < 0)
1467                 return -EINVAL;
1468         rcu_read_lock();
1469 diff -NurpP --minimal linux-3.10.40/fs/attr.c linux-3.10.40-vs2.3.6.8/fs/attr.c
1470 --- linux-3.10.40/fs/attr.c     2014-05-20 04:09:35.000000000 +0000
1471 +++ linux-3.10.40-vs2.3.6.8/fs/attr.c   2014-03-12 13:18:32.000000000 +0000
1472 @@ -15,6 +15,9 @@
1473  #include <linux/security.h>
1474  #include <linux/evm.h>
1475  #include <linux/ima.h>
1476 +#include <linux/proc_fs.h>
1477 +#include <linux/devpts_fs.h>
1478 +#include <linux/vs_tag.h>
1479  
1480  /**
1481   * inode_change_ok - check if attribute changes to an inode are allowed
1482 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1483                         return -EPERM;
1484         }
1485  
1486 +       /* check for inode tag permission */
1487 +       if (dx_permission(inode, MAY_WRITE))
1488 +               return -EACCES;
1489 +
1490         return 0;
1491  }
1492  EXPORT_SYMBOL(inode_change_ok);
1493 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1494                 inode->i_uid = attr->ia_uid;
1495         if (ia_valid & ATTR_GID)
1496                 inode->i_gid = attr->ia_gid;
1497 +       if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1498 +               inode->i_tag = attr->ia_tag;
1499         if (ia_valid & ATTR_ATIME)
1500                 inode->i_atime = timespec_trunc(attr->ia_atime,
1501                                                 inode->i_sb->s_time_gran);
1502 @@ -177,7 +186,8 @@ int notify_change(struct dentry * dentry
1503  
1504         WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1505  
1506 -       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1507 +       if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1508 +               ATTR_TAG | ATTR_TIMES_SET)) {
1509                 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1510                         return -EPERM;
1511         }
1512 diff -NurpP --minimal linux-3.10.40/fs/block_dev.c linux-3.10.40-vs2.3.6.8/fs/block_dev.c
1513 --- linux-3.10.40/fs/block_dev.c        2014-05-20 04:09:36.000000000 +0000
1514 +++ linux-3.10.40-vs2.3.6.8/fs/block_dev.c      2013-11-13 17:17:15.000000000 +0000
1515 @@ -28,6 +28,7 @@
1516  #include <linux/log2.h>
1517  #include <linux/cleancache.h>
1518  #include <linux/aio.h>
1519 +#include <linux/vs_device.h>
1520  #include <asm/uaccess.h>
1521  #include "internal.h"
1522  
1523 @@ -536,6 +537,7 @@ struct block_device *bdget(dev_t dev)
1524                 bdev->bd_invalidated = 0;
1525                 inode->i_mode = S_IFBLK;
1526                 inode->i_rdev = dev;
1527 +               inode->i_mdev = dev;
1528                 inode->i_bdev = bdev;
1529                 inode->i_data.a_ops = &def_blk_aops;
1530                 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1531 @@ -583,6 +585,11 @@ EXPORT_SYMBOL(bdput);
1532  static struct block_device *bd_acquire(struct inode *inode)
1533  {
1534         struct block_device *bdev;
1535 +       dev_t mdev;
1536 +
1537 +       if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1538 +               return NULL;
1539 +       inode->i_mdev = mdev;
1540  
1541         spin_lock(&bdev_lock);
1542         bdev = inode->i_bdev;
1543 @@ -593,7 +600,7 @@ static struct block_device *bd_acquire(s
1544         }
1545         spin_unlock(&bdev_lock);
1546  
1547 -       bdev = bdget(inode->i_rdev);
1548 +       bdev = bdget(mdev);
1549         if (bdev) {
1550                 spin_lock(&bdev_lock);
1551                 if (!inode->i_bdev) {
1552 diff -NurpP --minimal linux-3.10.40/fs/btrfs/ctree.h linux-3.10.40-vs2.3.6.8/fs/btrfs/ctree.h
1553 --- linux-3.10.40/fs/btrfs/ctree.h      2013-07-14 17:01:26.000000000 +0000
1554 +++ linux-3.10.40-vs2.3.6.8/fs/btrfs/ctree.h    2013-08-22 20:29:59.000000000 +0000
1555 @@ -707,11 +707,14 @@ struct btrfs_inode_item {
1556         /* modification sequence number for NFS */
1557         __le64 sequence;
1558  
1559 +       __le16 tag;
1560         /*
1561          * a little future expansion, for more than this we can
1562          * just grow the inode item and version it
1563          */
1564 -       __le64 reserved[4];
1565 +       __le16 reserved16;
1566 +       __le32 reserved32;
1567 +       __le64 reserved[3];
1568         struct btrfs_timespec atime;
1569         struct btrfs_timespec ctime;
1570         struct btrfs_timespec mtime;
1571 @@ -1928,6 +1931,8 @@ struct btrfs_ioctl_defrag_range_args {
1572  #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1573  #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR       (1 << 22)
1574  
1575 +#define BTRFS_MOUNT_TAGGED             (1 << 24)
1576 +
1577  #define btrfs_clear_opt(o, opt)                ((o) &= ~BTRFS_MOUNT_##opt)
1578  #define btrfs_set_opt(o, opt)          ((o) |= BTRFS_MOUNT_##opt)
1579  #define btrfs_raw_test_opt(o, opt)     ((o) & BTRFS_MOUNT_##opt)
1580 @@ -2197,6 +2202,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1581  BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1582  BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1583  BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1584 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1585  BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1586  BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1587  BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1588 @@ -2250,6 +2256,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1589  
1590  BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1591  
1592 +#define BTRFS_INODE_IXUNLINK           (1 << 24)
1593 +#define BTRFS_INODE_BARRIER            (1 << 25)
1594 +#define BTRFS_INODE_COW                        (1 << 26)
1595 +
1596  
1597  BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1598  
1599 @@ -3578,6 +3588,7 @@ extern const struct dentry_operations bt
1600  long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1601  void btrfs_update_iflags(struct inode *inode);
1602  void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1603 +int btrfs_sync_flags(struct inode *inode, int, int);
1604  int btrfs_defrag_file(struct inode *inode, struct file *file,
1605                       struct btrfs_ioctl_defrag_range_args *range,
1606                       u64 newer_than, unsigned long max_pages);
1607 diff -NurpP --minimal linux-3.10.40/fs/btrfs/disk-io.c linux-3.10.40-vs2.3.6.8/fs/btrfs/disk-io.c
1608 --- linux-3.10.40/fs/btrfs/disk-io.c    2014-05-20 04:09:36.000000000 +0000
1609 +++ linux-3.10.40-vs2.3.6.8/fs/btrfs/disk-io.c  2014-05-20 04:31:55.000000000 +0000
1610 @@ -2360,6 +2360,9 @@ int open_ctree(struct super_block *sb,
1611                 goto fail_alloc;
1612         }
1613  
1614 +       if (btrfs_test_opt(tree_root, TAGGED))
1615 +               sb->s_flags |= MS_TAGGED;
1616 +
1617         features = btrfs_super_incompat_flags(disk_super) &
1618                 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1619         if (features) {
1620 diff -NurpP --minimal linux-3.10.40/fs/btrfs/inode.c linux-3.10.40-vs2.3.6.8/fs/btrfs/inode.c
1621 --- linux-3.10.40/fs/btrfs/inode.c      2014-05-20 04:09:36.000000000 +0000
1622 +++ linux-3.10.40-vs2.3.6.8/fs/btrfs/inode.c    2014-03-12 13:18:32.000000000 +0000
1623 @@ -42,6 +42,7 @@
1624  #include <linux/mount.h>
1625  #include <linux/btrfs.h>
1626  #include <linux/blkdev.h>
1627 +#include <linux/vs_tag.h>
1628  #include "compat.h"
1629  #include "ctree.h"
1630  #include "disk-io.h"
1631 @@ -3336,6 +3337,9 @@ static void btrfs_read_locked_inode(stru
1632         struct btrfs_key location;
1633         int maybe_acls;
1634         u32 rdev;
1635 +       kuid_t kuid;
1636 +       kgid_t kgid;
1637 +       ktag_t ktag;
1638         int ret;
1639         bool filled = false;
1640  
1641 @@ -3363,8 +3367,14 @@ static void btrfs_read_locked_inode(stru
1642                                     struct btrfs_inode_item);
1643         inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1644         set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1645 -       i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1646 -       i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1647 +
1648 +       kuid = make_kuid(&init_user_ns, btrfs_inode_uid(leaf, inode_item));
1649 +       kgid = make_kgid(&init_user_ns, btrfs_inode_gid(leaf, inode_item));
1650 +       ktag = make_ktag(&init_user_ns, btrfs_inode_tag(leaf, inode_item));
1651 +
1652 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
1653 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
1654 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
1655         btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1656  
1657         tspec = btrfs_inode_atime(inode_item);
1658 @@ -3455,11 +3465,18 @@ static void fill_inode_item(struct btrfs
1659                             struct inode *inode)
1660  {
1661         struct btrfs_map_token token;
1662 +       uid_t uid = from_kuid(&init_user_ns,
1663 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
1664 +       gid_t gid = from_kgid(&init_user_ns,
1665 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
1666  
1667         btrfs_init_map_token(&token);
1668  
1669 -       btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1670 -       btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1671 +       btrfs_set_token_inode_uid(leaf, item, uid, &token);
1672 +       btrfs_set_token_inode_gid(leaf, item, gid, &token);
1673 +#ifdef CONFIG_TAGGING_INTERN
1674 +       btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1675 +#endif
1676         btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1677                                    &token);
1678         btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1679 @@ -8733,11 +8750,13 @@ static const struct inode_operations btr
1680         .listxattr      = btrfs_listxattr,
1681         .removexattr    = btrfs_removexattr,
1682         .permission     = btrfs_permission,
1683 +       .sync_flags     = btrfs_sync_flags,
1684         .get_acl        = btrfs_get_acl,
1685  };
1686  static const struct inode_operations btrfs_dir_ro_inode_operations = {
1687         .lookup         = btrfs_lookup,
1688         .permission     = btrfs_permission,
1689 +       .sync_flags     = btrfs_sync_flags,
1690         .get_acl        = btrfs_get_acl,
1691  };
1692  
1693 diff -NurpP --minimal linux-3.10.40/fs/btrfs/ioctl.c linux-3.10.40-vs2.3.6.8/fs/btrfs/ioctl.c
1694 --- linux-3.10.40/fs/btrfs/ioctl.c      2014-05-20 04:09:36.000000000 +0000
1695 +++ linux-3.10.40-vs2.3.6.8/fs/btrfs/ioctl.c    2014-03-12 13:18:23.000000000 +0000
1696 @@ -75,10 +75,13 @@ static unsigned int btrfs_flags_to_ioctl
1697  {
1698         unsigned int iflags = 0;
1699  
1700 -       if (flags & BTRFS_INODE_SYNC)
1701 -               iflags |= FS_SYNC_FL;
1702         if (flags & BTRFS_INODE_IMMUTABLE)
1703                 iflags |= FS_IMMUTABLE_FL;
1704 +       if (flags & BTRFS_INODE_IXUNLINK)
1705 +               iflags |= FS_IXUNLINK_FL;
1706 +
1707 +       if (flags & BTRFS_INODE_SYNC)
1708 +               iflags |= FS_SYNC_FL;
1709         if (flags & BTRFS_INODE_APPEND)
1710                 iflags |= FS_APPEND_FL;
1711         if (flags & BTRFS_INODE_NODUMP)
1712 @@ -95,28 +98,78 @@ static unsigned int btrfs_flags_to_ioctl
1713         else if (flags & BTRFS_INODE_NOCOMPRESS)
1714                 iflags |= FS_NOCOMP_FL;
1715  
1716 +       if (flags & BTRFS_INODE_BARRIER)
1717 +               iflags |= FS_BARRIER_FL;
1718 +       if (flags & BTRFS_INODE_COW)
1719 +               iflags |= FS_COW_FL;
1720         return iflags;
1721  }
1722  
1723  /*
1724 - * Update inode->i_flags based on the btrfs internal flags.
1725 + * Update inode->i_(v)flags based on the btrfs internal flags.
1726   */
1727  void btrfs_update_iflags(struct inode *inode)
1728  {
1729         struct btrfs_inode *ip = BTRFS_I(inode);
1730  
1731 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1732 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1733 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1734  
1735 -       if (ip->flags & BTRFS_INODE_SYNC)
1736 -               inode->i_flags |= S_SYNC;
1737         if (ip->flags & BTRFS_INODE_IMMUTABLE)
1738                 inode->i_flags |= S_IMMUTABLE;
1739 +       if (ip->flags & BTRFS_INODE_IXUNLINK)
1740 +               inode->i_flags |= S_IXUNLINK;
1741 +
1742 +       if (ip->flags & BTRFS_INODE_SYNC)
1743 +               inode->i_flags |= S_SYNC;
1744         if (ip->flags & BTRFS_INODE_APPEND)
1745                 inode->i_flags |= S_APPEND;
1746         if (ip->flags & BTRFS_INODE_NOATIME)
1747                 inode->i_flags |= S_NOATIME;
1748         if (ip->flags & BTRFS_INODE_DIRSYNC)
1749                 inode->i_flags |= S_DIRSYNC;
1750 +
1751 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
1752 +
1753 +       if (ip->flags & BTRFS_INODE_BARRIER)
1754 +               inode->i_vflags |= V_BARRIER;
1755 +       if (ip->flags & BTRFS_INODE_COW)
1756 +               inode->i_vflags |= V_COW;
1757 +}
1758 +
1759 +/*
1760 + * Update btrfs internal flags from inode->i_(v)flags.
1761 + */
1762 +void btrfs_update_flags(struct inode *inode)
1763 +{
1764 +       struct btrfs_inode *ip = BTRFS_I(inode);
1765 +
1766 +       unsigned int flags = inode->i_flags;
1767 +       unsigned int vflags = inode->i_vflags;
1768 +
1769 +       ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1770 +                       BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1771 +                       BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1772 +                       BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1773 +
1774 +       if (flags & S_IMMUTABLE)
1775 +               ip->flags |= BTRFS_INODE_IMMUTABLE;
1776 +       if (flags & S_IXUNLINK)
1777 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1778 +
1779 +       if (flags & S_SYNC)
1780 +               ip->flags |= BTRFS_INODE_SYNC;
1781 +       if (flags & S_APPEND)
1782 +               ip->flags |= BTRFS_INODE_APPEND;
1783 +       if (flags & S_NOATIME)
1784 +               ip->flags |= BTRFS_INODE_NOATIME;
1785 +       if (flags & S_DIRSYNC)
1786 +               ip->flags |= BTRFS_INODE_DIRSYNC;
1787 +
1788 +       if (vflags & V_BARRIER)
1789 +               ip->flags |= BTRFS_INODE_BARRIER;
1790 +       if (vflags & V_COW)
1791 +               ip->flags |= BTRFS_INODE_COW;
1792  }
1793  
1794  /*
1795 @@ -132,6 +185,7 @@ void btrfs_inherit_iflags(struct inode *
1796                 return;
1797  
1798         flags = BTRFS_I(dir)->flags;
1799 +       flags &= ~BTRFS_INODE_BARRIER;
1800  
1801         if (flags & BTRFS_INODE_NOCOMPRESS) {
1802                 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1803 @@ -150,6 +204,30 @@ void btrfs_inherit_iflags(struct inode *
1804         btrfs_update_iflags(inode);
1805  }
1806  
1807 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1808 +{
1809 +       struct btrfs_inode *ip = BTRFS_I(inode);
1810 +       struct btrfs_root *root = ip->root;
1811 +       struct btrfs_trans_handle *trans;
1812 +       int ret;
1813 +
1814 +       trans = btrfs_join_transaction(root);
1815 +       BUG_ON(!trans);
1816 +
1817 +       inode->i_flags = flags;
1818 +       inode->i_vflags = vflags;
1819 +       btrfs_update_flags(inode);
1820 +
1821 +       ret = btrfs_update_inode(trans, root, inode);
1822 +       BUG_ON(ret);
1823 +
1824 +       btrfs_update_iflags(inode);
1825 +       inode->i_ctime = CURRENT_TIME;
1826 +       btrfs_end_transaction(trans, root);
1827 +
1828 +       return 0;
1829 +}
1830 +
1831  static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1832  {
1833         struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1834 @@ -212,21 +290,27 @@ static int btrfs_ioctl_setflags(struct f
1835  
1836         flags = btrfs_mask_flags(inode->i_mode, flags);
1837         oldflags = btrfs_flags_to_ioctl(ip->flags);
1838 -       if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1839 +       if ((flags ^ oldflags) & (FS_APPEND_FL |
1840 +               FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1841                 if (!capable(CAP_LINUX_IMMUTABLE)) {
1842                         ret = -EPERM;
1843                         goto out_unlock;
1844                 }
1845         }
1846  
1847 -       if (flags & FS_SYNC_FL)
1848 -               ip->flags |= BTRFS_INODE_SYNC;
1849 -       else
1850 -               ip->flags &= ~BTRFS_INODE_SYNC;
1851         if (flags & FS_IMMUTABLE_FL)
1852                 ip->flags |= BTRFS_INODE_IMMUTABLE;
1853         else
1854                 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1855 +       if (flags & FS_IXUNLINK_FL)
1856 +               ip->flags |= BTRFS_INODE_IXUNLINK;
1857 +       else
1858 +               ip->flags &= ~BTRFS_INODE_IXUNLINK;
1859 +
1860 +       if (flags & FS_SYNC_FL)
1861 +               ip->flags |= BTRFS_INODE_SYNC;
1862 +       else
1863 +               ip->flags &= ~BTRFS_INODE_SYNC;
1864         if (flags & FS_APPEND_FL)
1865                 ip->flags |= BTRFS_INODE_APPEND;
1866         else
1867 diff -NurpP --minimal linux-3.10.40/fs/btrfs/super.c linux-3.10.40-vs2.3.6.8/fs/btrfs/super.c
1868 --- linux-3.10.40/fs/btrfs/super.c      2013-07-14 17:01:26.000000000 +0000
1869 +++ linux-3.10.40-vs2.3.6.8/fs/btrfs/super.c    2013-08-22 20:29:59.000000000 +0000
1870 @@ -319,7 +319,7 @@ enum {
1871         Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
1872         Opt_check_integrity, Opt_check_integrity_including_extent_data,
1873         Opt_check_integrity_print_mask, Opt_fatal_errors,
1874 -       Opt_err,
1875 +       Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1876  };
1877  
1878  static match_table_t tokens = {
1879 @@ -359,6 +359,9 @@ static match_table_t tokens = {
1880         {Opt_check_integrity_including_extent_data, "check_int_data"},
1881         {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
1882         {Opt_fatal_errors, "fatal_errors=%s"},
1883 +       {Opt_tag, "tag"},
1884 +       {Opt_notag, "notag"},
1885 +       {Opt_tagid, "tagid=%u"},
1886         {Opt_err, NULL},
1887  };
1888  
1889 @@ -624,6 +627,22 @@ int btrfs_parse_options(struct btrfs_roo
1890                                 goto out;
1891                         }
1892                         break;
1893 +#ifndef CONFIG_TAGGING_NONE
1894 +               case Opt_tag:
1895 +                       printk(KERN_INFO "btrfs: use tagging\n");
1896 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1897 +                       break;
1898 +               case Opt_notag:
1899 +                       printk(KERN_INFO "btrfs: disabled tagging\n");
1900 +                       btrfs_clear_opt(info->mount_opt, TAGGED);
1901 +                       break;
1902 +#endif
1903 +#ifdef CONFIG_PROPAGATE
1904 +               case Opt_tagid:
1905 +                       /* use args[0] */
1906 +                       btrfs_set_opt(info->mount_opt, TAGGED);
1907 +                       break;
1908 +#endif
1909                 case Opt_err:
1910                         printk(KERN_INFO "btrfs: unrecognized mount option "
1911                                "'%s'\n", p);
1912 @@ -1251,6 +1270,12 @@ static int btrfs_remount(struct super_bl
1913         btrfs_resize_thread_pool(fs_info,
1914                 fs_info->thread_pool_size, old_thread_pool_size);
1915  
1916 +       if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1917 +               printk("btrfs: %s: tagging not permitted on remount.\n",
1918 +                       sb->s_id);
1919 +               return -EINVAL;
1920 +       }
1921 +
1922         if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1923                 goto out;
1924  
1925 diff -NurpP --minimal linux-3.10.40/fs/char_dev.c linux-3.10.40-vs2.3.6.8/fs/char_dev.c
1926 --- linux-3.10.40/fs/char_dev.c 2012-12-11 03:30:57.000000000 +0000
1927 +++ linux-3.10.40-vs2.3.6.8/fs/char_dev.c       2013-08-22 20:29:59.000000000 +0000
1928 @@ -21,6 +21,8 @@
1929  #include <linux/mutex.h>
1930  #include <linux/backing-dev.h>
1931  #include <linux/tty.h>
1932 +#include <linux/vs_context.h>
1933 +#include <linux/vs_device.h>
1934  
1935  #include "internal.h"
1936  
1937 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
1938         struct cdev *p;
1939         struct cdev *new = NULL;
1940         int ret = 0;
1941 +       dev_t mdev;
1942 +
1943 +       if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
1944 +               return -EPERM;
1945 +       inode->i_mdev = mdev;
1946  
1947         spin_lock(&cdev_lock);
1948         p = inode->i_cdev;
1949         if (!p) {
1950                 struct kobject *kobj;
1951                 int idx;
1952 +
1953                 spin_unlock(&cdev_lock);
1954 -               kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
1955 +
1956 +               kobj = kobj_lookup(cdev_map, mdev, &idx);
1957                 if (!kobj)
1958                         return -ENXIO;
1959                 new = container_of(kobj, struct cdev, kobj);
1960 diff -NurpP --minimal linux-3.10.40/fs/dcache.c linux-3.10.40-vs2.3.6.8/fs/dcache.c
1961 --- linux-3.10.40/fs/dcache.c   2014-05-20 04:09:36.000000000 +0000
1962 +++ linux-3.10.40-vs2.3.6.8/fs/dcache.c 2014-03-12 13:18:23.000000000 +0000
1963 @@ -37,6 +37,7 @@
1964  #include <linux/rculist_bl.h>
1965  #include <linux/prefetch.h>
1966  #include <linux/ratelimit.h>
1967 +#include <linux/vs_limit.h>
1968  #include "internal.h"
1969  #include "mount.h"
1970  
1971 @@ -578,6 +579,8 @@ int d_invalidate(struct dentry * dentry)
1972                 spin_lock(&dentry->d_lock);
1973         }
1974  
1975 +       vx_dentry_dec(dentry);
1976 +
1977         /*
1978          * Somebody else still using it?
1979          *
1980 @@ -607,6 +610,7 @@ EXPORT_SYMBOL(d_invalidate);
1981  static inline void __dget_dlock(struct dentry *dentry)
1982  {
1983         dentry->d_count++;
1984 +       vx_dentry_inc(dentry);
1985  }
1986  
1987  static inline void __dget(struct dentry *dentry)
1988 @@ -1239,6 +1243,9 @@ struct dentry *__d_alloc(struct super_bl
1989         struct dentry *dentry;
1990         char *dname;
1991  
1992 +       if (!vx_dentry_avail(1))
1993 +               return NULL;
1994 +
1995         dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
1996         if (!dentry)
1997                 return NULL;
1998 @@ -1271,6 +1278,7 @@ struct dentry *__d_alloc(struct super_bl
1999  
2000         dentry->d_count = 1;
2001         dentry->d_flags = 0;
2002 +       vx_dentry_inc(dentry);
2003         spin_lock_init(&dentry->d_lock);
2004         seqcount_init(&dentry->d_seq);
2005         dentry->d_inode = NULL;
2006 @@ -1971,6 +1979,7 @@ struct dentry *__d_lookup(const struct d
2007                 }
2008  
2009                 dentry->d_count++;
2010 +               vx_dentry_inc(dentry);
2011                 found = dentry;
2012                 spin_unlock(&dentry->d_lock);
2013                 break;
2014 diff -NurpP --minimal linux-3.10.40/fs/devpts/inode.c linux-3.10.40-vs2.3.6.8/fs/devpts/inode.c
2015 --- linux-3.10.40/fs/devpts/inode.c     2014-05-20 04:09:38.000000000 +0000
2016 +++ linux-3.10.40-vs2.3.6.8/fs/devpts/inode.c   2013-12-23 17:42:40.000000000 +0000
2017 @@ -25,6 +25,7 @@
2018  #include <linux/parser.h>
2019  #include <linux/fsnotify.h>
2020  #include <linux/seq_file.h>
2021 +#include <linux/vs_base.h>
2022  
2023  #define DEVPTS_DEFAULT_MODE 0600
2024  /*
2025 @@ -36,6 +37,21 @@
2026  #define DEVPTS_DEFAULT_PTMX_MODE 0000
2027  #define PTMX_MINOR     2
2028  
2029 +static int devpts_permission(struct inode *inode, int mask)
2030 +{
2031 +       int ret = -EACCES;
2032 +
2033 +       /* devpts is xid tagged */
2034 +       if (vx_check((vxid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2035 +               ret = generic_permission(inode, mask);
2036 +       return ret;
2037 +}
2038 +
2039 +static struct inode_operations devpts_file_inode_operations = {
2040 +       .permission     = devpts_permission,
2041 +};
2042 +
2043 +
2044  /*
2045   * sysctl support for setting limits on the number of Unix98 ptys allocated.
2046   * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2047 @@ -345,6 +361,34 @@ static int devpts_show_options(struct se
2048         return 0;
2049  }
2050  
2051 +static int devpts_filter(struct dentry *de)
2052 +{
2053 +       vxid_t xid = 0;
2054 +
2055 +       /* devpts is xid tagged */
2056 +       if (de && de->d_inode)
2057 +               xid = (vxid_t)i_tag_read(de->d_inode);
2058 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2059 +       else
2060 +               vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2061 +                       de->d_name.len, de->d_name.name);
2062 +#endif
2063 +       return vx_check(xid, VS_WATCH_P | VS_IDENT);
2064 +}
2065 +
2066 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2067 +{
2068 +       return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2069 +}
2070 +
2071 +static struct file_operations devpts_dir_operations = {
2072 +       .open           = dcache_dir_open,
2073 +       .release        = dcache_dir_close,
2074 +       .llseek         = dcache_dir_lseek,
2075 +       .read           = generic_read_dir,
2076 +       .readdir        = devpts_readdir,
2077 +};
2078 +
2079  static const struct super_operations devpts_sops = {
2080         .statfs         = simple_statfs,
2081         .remount_fs     = devpts_remount,
2082 @@ -388,8 +432,10 @@ devpts_fill_super(struct super_block *s,
2083         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2084         inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2085         inode->i_op = &simple_dir_inode_operations;
2086 -       inode->i_fop = &simple_dir_operations;
2087 +       inode->i_fop = &devpts_dir_operations;
2088         set_nlink(inode, 2);
2089 +       /* devpts is xid tagged */
2090 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2091  
2092         s->s_root = d_make_root(inode);
2093         if (s->s_root)
2094 @@ -593,6 +639,9 @@ struct inode *devpts_pty_new(struct inod
2095         inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2096         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2097         init_special_inode(inode, S_IFCHR|opts->mode, device);
2098 +       /* devpts is xid tagged */
2099 +       i_tag_write(inode, (vtag_t)vx_current_xid());
2100 +       inode->i_op = &devpts_file_inode_operations;
2101         inode->i_private = priv;
2102  
2103         sprintf(s, "%d", index);
2104 diff -NurpP --minimal linux-3.10.40/fs/ext2/balloc.c linux-3.10.40-vs2.3.6.8/fs/ext2/balloc.c
2105 --- linux-3.10.40/fs/ext2/balloc.c      2013-05-31 13:45:23.000000000 +0000
2106 +++ linux-3.10.40-vs2.3.6.8/fs/ext2/balloc.c    2013-08-22 20:29:59.000000000 +0000
2107 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2108                         start = 0;
2109                 end = EXT2_BLOCKS_PER_GROUP(sb);
2110         }
2111 -
2112         BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2113  
2114  repeat:
2115 diff -NurpP --minimal linux-3.10.40/fs/ext2/ext2.h linux-3.10.40-vs2.3.6.8/fs/ext2/ext2.h
2116 --- linux-3.10.40/fs/ext2/ext2.h        2012-12-11 03:30:57.000000000 +0000
2117 +++ linux-3.10.40-vs2.3.6.8/fs/ext2/ext2.h      2013-08-22 20:29:59.000000000 +0000
2118 @@ -244,8 +244,12 @@ struct ext2_group_desc
2119  #define EXT2_NOTAIL_FL                 FS_NOTAIL_FL    /* file tail should not be merged */
2120  #define EXT2_DIRSYNC_FL                        FS_DIRSYNC_FL   /* dirsync behaviour (directories only) */
2121  #define EXT2_TOPDIR_FL                 FS_TOPDIR_FL    /* Top of directory hierarchies*/
2122 +#define EXT2_IXUNLINK_FL               FS_IXUNLINK_FL  /* Immutable invert on unlink */
2123  #define EXT2_RESERVED_FL               FS_RESERVED_FL  /* reserved for ext2 lib */
2124  
2125 +#define EXT2_BARRIER_FL                        FS_BARRIER_FL   /* Barrier for chroot() */
2126 +#define EXT2_COW_FL                    FS_COW_FL       /* Copy on Write marker */
2127 +
2128  #define EXT2_FL_USER_VISIBLE           FS_FL_USER_VISIBLE      /* User visible flags */
2129  #define EXT2_FL_USER_MODIFIABLE                FS_FL_USER_MODIFIABLE   /* User modifiable flags */
2130  
2131 @@ -329,7 +333,8 @@ struct ext2_inode {
2132                         __u16   i_pad1;
2133                         __le16  l_i_uid_high;   /* these 2 fields    */
2134                         __le16  l_i_gid_high;   /* were reserved2[0] */
2135 -                       __u32   l_i_reserved2;
2136 +                       __le16  l_i_tag;        /* Context Tag */
2137 +                       __u16   l_i_reserved2;
2138                 } linux2;
2139                 struct {
2140                         __u8    h_i_frag;       /* Fragment number */
2141 @@ -357,6 +362,7 @@ struct ext2_inode {
2142  #define i_gid_low      i_gid
2143  #define i_uid_high     osd2.linux2.l_i_uid_high
2144  #define i_gid_high     osd2.linux2.l_i_gid_high
2145 +#define i_raw_tag      osd2.linux2.l_i_tag
2146  #define i_reserved2    osd2.linux2.l_i_reserved2
2147  
2148  /*
2149 @@ -384,6 +390,7 @@ struct ext2_inode {
2150  #define EXT2_MOUNT_USRQUOTA            0x020000  /* user quota */
2151  #define EXT2_MOUNT_GRPQUOTA            0x040000  /* group quota */
2152  #define EXT2_MOUNT_RESERVATION         0x080000  /* Preallocation */
2153 +#define EXT2_MOUNT_TAGGED              (1<<24)   /* Enable Context Tags */
2154  
2155  
2156  #define clear_opt(o, opt)              o &= ~EXT2_MOUNT_##opt
2157 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2158  extern void ext2_get_inode_flags(struct ext2_inode_info *);
2159  extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2160                        u64 start, u64 len);
2161 +extern int ext2_sync_flags(struct inode *, int, int);
2162  
2163  /* ioctl.c */
2164  extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2165 diff -NurpP --minimal linux-3.10.40/fs/ext2/file.c linux-3.10.40-vs2.3.6.8/fs/ext2/file.c
2166 --- linux-3.10.40/fs/ext2/file.c        2012-12-11 03:30:57.000000000 +0000
2167 +++ linux-3.10.40-vs2.3.6.8/fs/ext2/file.c      2013-08-22 20:29:59.000000000 +0000
2168 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2169         .setattr        = ext2_setattr,
2170         .get_acl        = ext2_get_acl,
2171         .fiemap         = ext2_fiemap,
2172 +       .sync_flags     = ext2_sync_flags,
2173  };
2174 diff -NurpP --minimal linux-3.10.40/fs/ext2/ialloc.c linux-3.10.40-vs2.3.6.8/fs/ext2/ialloc.c
2175 --- linux-3.10.40/fs/ext2/ialloc.c      2013-05-31 13:45:23.000000000 +0000
2176 +++ linux-3.10.40-vs2.3.6.8/fs/ext2/ialloc.c    2013-08-22 20:29:59.000000000 +0000
2177 @@ -17,6 +17,7 @@
2178  #include <linux/backing-dev.h>
2179  #include <linux/buffer_head.h>
2180  #include <linux/random.h>
2181 +#include <linux/vs_tag.h>
2182  #include "ext2.h"
2183  #include "xattr.h"
2184  #include "acl.h"
2185 @@ -546,6 +547,7 @@ got:
2186                 inode->i_mode = mode;
2187                 inode->i_uid = current_fsuid();
2188                 inode->i_gid = dir->i_gid;
2189 +               i_tag_write(inode, dx_current_fstag(sb));
2190         } else
2191                 inode_init_owner(inode, dir, mode);
2192  
2193 diff -NurpP --minimal linux-3.10.40/fs/ext2/inode.c linux-3.10.40-vs2.3.6.8/fs/ext2/inode.c
2194 --- linux-3.10.40/fs/ext2/inode.c       2013-07-14 17:01:27.000000000 +0000
2195 +++ linux-3.10.40-vs2.3.6.8/fs/ext2/inode.c     2013-08-22 21:46:54.000000000 +0000
2196 @@ -32,6 +32,7 @@
2197  #include <linux/fiemap.h>
2198  #include <linux/namei.h>
2199  #include <linux/aio.h>
2200 +#include <linux/vs_tag.h>
2201  #include "ext2.h"
2202  #include "acl.h"
2203  #include "xip.h"
2204 @@ -1180,7 +1181,7 @@ static void ext2_truncate_blocks(struct
2205                 return;
2206         if (ext2_inode_is_fast_symlink(inode))
2207                 return;
2208 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2209 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2210                 return;
2211         __ext2_truncate_blocks(inode, offset);
2212  }
2213 @@ -1271,36 +1272,61 @@ void ext2_set_inode_flags(struct inode *
2214  {
2215         unsigned int flags = EXT2_I(inode)->i_flags;
2216  
2217 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2218 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2219 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2220 +
2221 +
2222 +       if (flags & EXT2_IMMUTABLE_FL)
2223 +               inode->i_flags |= S_IMMUTABLE;
2224 +       if (flags & EXT2_IXUNLINK_FL)
2225 +               inode->i_flags |= S_IXUNLINK;
2226 +
2227         if (flags & EXT2_SYNC_FL)
2228                 inode->i_flags |= S_SYNC;
2229         if (flags & EXT2_APPEND_FL)
2230                 inode->i_flags |= S_APPEND;
2231 -       if (flags & EXT2_IMMUTABLE_FL)
2232 -               inode->i_flags |= S_IMMUTABLE;
2233         if (flags & EXT2_NOATIME_FL)
2234                 inode->i_flags |= S_NOATIME;
2235         if (flags & EXT2_DIRSYNC_FL)
2236                 inode->i_flags |= S_DIRSYNC;
2237 +
2238 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2239 +
2240 +       if (flags & EXT2_BARRIER_FL)
2241 +               inode->i_vflags |= V_BARRIER;
2242 +       if (flags & EXT2_COW_FL)
2243 +               inode->i_vflags |= V_COW;
2244  }
2245  
2246  /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2247  void ext2_get_inode_flags(struct ext2_inode_info *ei)
2248  {
2249         unsigned int flags = ei->vfs_inode.i_flags;
2250 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2251 +
2252 +       ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2253 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2254 +                       EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2255 +                       EXT2_BARRIER_FL | EXT2_COW_FL);
2256 +
2257 +       if (flags & S_IMMUTABLE)
2258 +               ei->i_flags |= EXT2_IMMUTABLE_FL;
2259 +       if (flags & S_IXUNLINK)
2260 +               ei->i_flags |= EXT2_IXUNLINK_FL;
2261  
2262 -       ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2263 -                       EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2264         if (flags & S_SYNC)
2265                 ei->i_flags |= EXT2_SYNC_FL;
2266         if (flags & S_APPEND)
2267                 ei->i_flags |= EXT2_APPEND_FL;
2268 -       if (flags & S_IMMUTABLE)
2269 -               ei->i_flags |= EXT2_IMMUTABLE_FL;
2270         if (flags & S_NOATIME)
2271                 ei->i_flags |= EXT2_NOATIME_FL;
2272         if (flags & S_DIRSYNC)
2273                 ei->i_flags |= EXT2_DIRSYNC_FL;
2274 +
2275 +       if (vflags & V_BARRIER)
2276 +               ei->i_flags |= EXT2_BARRIER_FL;
2277 +       if (vflags & V_COW)
2278 +               ei->i_flags |= EXT2_COW_FL;
2279  }
2280  
2281  struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2282 @@ -1336,8 +1362,10 @@ struct inode *ext2_iget (struct super_bl
2283                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2284                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2285         }
2286 -       i_uid_write(inode, i_uid);
2287 -       i_gid_write(inode, i_gid);
2288 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2289 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2290 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2291 +               le16_to_cpu(raw_inode->i_raw_tag)));
2292         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2293         inode->i_size = le32_to_cpu(raw_inode->i_size);
2294         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2295 @@ -1435,8 +1463,10 @@ static int __ext2_write_inode(struct ino
2296         struct ext2_inode_info *ei = EXT2_I(inode);
2297         struct super_block *sb = inode->i_sb;
2298         ino_t ino = inode->i_ino;
2299 -       uid_t uid = i_uid_read(inode);
2300 -       gid_t gid = i_gid_read(inode);
2301 +       uid_t uid = from_kuid(&init_user_ns,
2302 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2303 +       gid_t gid = from_kgid(&init_user_ns,
2304 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2305         struct buffer_head * bh;
2306         struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2307         int n;
2308 @@ -1472,6 +1502,9 @@ static int __ext2_write_inode(struct ino
2309                 raw_inode->i_uid_high = 0;
2310                 raw_inode->i_gid_high = 0;
2311         }
2312 +#ifdef CONFIG_TAGGING_INTERN
2313 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2314 +#endif
2315         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2316         raw_inode->i_size = cpu_to_le32(inode->i_size);
2317         raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2318 @@ -1552,7 +1585,8 @@ int ext2_setattr(struct dentry *dentry,
2319         if (is_quota_modification(inode, iattr))
2320                 dquot_initialize(inode);
2321         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2322 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2323 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2324 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2325                 error = dquot_transfer(inode, iattr);
2326                 if (error)
2327                         return error;
2328 diff -NurpP --minimal linux-3.10.40/fs/ext2/ioctl.c linux-3.10.40-vs2.3.6.8/fs/ext2/ioctl.c
2329 --- linux-3.10.40/fs/ext2/ioctl.c       2013-05-31 13:45:23.000000000 +0000
2330 +++ linux-3.10.40-vs2.3.6.8/fs/ext2/ioctl.c     2013-08-22 20:29:59.000000000 +0000
2331 @@ -17,6 +17,16 @@
2332  #include <asm/uaccess.h>
2333  
2334  
2335 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2336 +{
2337 +       inode->i_flags = flags;
2338 +       inode->i_vflags = vflags;
2339 +       ext2_get_inode_flags(EXT2_I(inode));
2340 +       inode->i_ctime = CURRENT_TIME_SEC;
2341 +       mark_inode_dirty(inode);
2342 +       return 0;
2343 +}
2344 +
2345  long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2346  {
2347         struct inode *inode = file_inode(filp);
2348 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2349  
2350                 flags = ext2_mask_flags(inode->i_mode, flags);
2351  
2352 +               if (IS_BARRIER(inode)) {
2353 +                       vxwprintk_task(1, "messing with the barrier.");
2354 +                       return -EACCES;
2355 +               }
2356 +
2357                 mutex_lock(&inode->i_mutex);
2358                 /* Is it quota file? Do not allow user to mess with it */
2359                 if (IS_NOQUOTA(inode)) {
2360 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2361                  *
2362                  * This test looks nicer. Thanks to Pauline Middelink
2363                  */
2364 -               if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2365 +               if ((oldflags & EXT2_IMMUTABLE_FL) ||
2366 +                       ((flags ^ oldflags) & (EXT2_APPEND_FL |
2367 +                       EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2368                         if (!capable(CAP_LINUX_IMMUTABLE)) {
2369                                 mutex_unlock(&inode->i_mutex);
2370                                 ret = -EPERM;
2371 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2372                         }
2373                 }
2374  
2375 -               flags = flags & EXT2_FL_USER_MODIFIABLE;
2376 +               flags &= EXT2_FL_USER_MODIFIABLE;
2377                 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2378                 ei->i_flags = flags;
2379  
2380 diff -NurpP --minimal linux-3.10.40/fs/ext2/namei.c linux-3.10.40-vs2.3.6.8/fs/ext2/namei.c
2381 --- linux-3.10.40/fs/ext2/namei.c       2012-12-11 03:30:57.000000000 +0000
2382 +++ linux-3.10.40-vs2.3.6.8/fs/ext2/namei.c     2013-08-22 20:29:59.000000000 +0000
2383 @@ -32,6 +32,7 @@
2384  
2385  #include <linux/pagemap.h>
2386  #include <linux/quotaops.h>
2387 +#include <linux/vs_tag.h>
2388  #include "ext2.h"
2389  #include "xattr.h"
2390  #include "acl.h"
2391 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2392                                         (unsigned long) ino);
2393                         return ERR_PTR(-EIO);
2394                 }
2395 +               dx_propagate_tag(nd, inode);
2396         }
2397         return d_splice_alias(inode, dentry);
2398  }
2399 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2400         .removexattr    = generic_removexattr,
2401  #endif
2402         .setattr        = ext2_setattr,
2403 +       .sync_flags     = ext2_sync_flags,
2404         .get_acl        = ext2_get_acl,
2405  };
2406  
2407 diff -NurpP --minimal linux-3.10.40/fs/ext2/super.c linux-3.10.40-vs2.3.6.8/fs/ext2/super.c
2408 --- linux-3.10.40/fs/ext2/super.c       2013-05-31 13:45:23.000000000 +0000
2409 +++ linux-3.10.40-vs2.3.6.8/fs/ext2/super.c     2013-08-22 20:29:59.000000000 +0000
2410 @@ -395,7 +395,8 @@ enum {
2411         Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2412         Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2413         Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2414 -       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2415 +       Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2416 +       Opt_tag, Opt_notag, Opt_tagid
2417  };
2418  
2419  static const match_table_t tokens = {
2420 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2421         {Opt_acl, "acl"},
2422         {Opt_noacl, "noacl"},
2423         {Opt_xip, "xip"},
2424 +       {Opt_tag, "tag"},
2425 +       {Opt_notag, "notag"},
2426 +       {Opt_tagid, "tagid=%u"},
2427         {Opt_grpquota, "grpquota"},
2428         {Opt_ignore, "noquota"},
2429         {Opt_quota, "quota"},
2430 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2431                 case Opt_nouid32:
2432                         set_opt (sbi->s_mount_opt, NO_UID32);
2433                         break;
2434 +#ifndef CONFIG_TAGGING_NONE
2435 +               case Opt_tag:
2436 +                       set_opt (sbi->s_mount_opt, TAGGED);
2437 +                       break;
2438 +               case Opt_notag:
2439 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2440 +                       break;
2441 +#endif
2442 +#ifdef CONFIG_PROPAGATE
2443 +               case Opt_tagid:
2444 +                       /* use args[0] */
2445 +                       set_opt (sbi->s_mount_opt, TAGGED);
2446 +                       break;
2447 +#endif
2448                 case Opt_nocheck:
2449                         clear_opt (sbi->s_mount_opt, CHECK);
2450                         break;
2451 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2452         if (!parse_options((char *) data, sb))
2453                 goto failed_mount;
2454  
2455 +       if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2456 +               sb->s_flags |= MS_TAGGED;
2457         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2458                 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2459                  MS_POSIXACL : 0);
2460 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2461                 err = -EINVAL;
2462                 goto restore_opts;
2463         }
2464 +
2465 +       if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2466 +               !(sb->s_flags & MS_TAGGED)) {
2467 +               printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2468 +                      sb->s_id);
2469 +               err = -EINVAL;
2470 +               goto restore_opts;
2471 +       }
2472  
2473         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2474                 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2475 diff -NurpP --minimal linux-3.10.40/fs/ext3/ext3.h linux-3.10.40-vs2.3.6.8/fs/ext3/ext3.h
2476 --- linux-3.10.40/fs/ext3/ext3.h        2012-12-11 03:30:57.000000000 +0000
2477 +++ linux-3.10.40-vs2.3.6.8/fs/ext3/ext3.h      2013-08-22 20:29:59.000000000 +0000
2478 @@ -151,10 +151,14 @@ struct ext3_group_desc
2479  #define EXT3_NOTAIL_FL                 0x00008000 /* file tail should not be merged */
2480  #define EXT3_DIRSYNC_FL                        0x00010000 /* dirsync behaviour (directories only) */
2481  #define EXT3_TOPDIR_FL                 0x00020000 /* Top of directory hierarchies*/
2482 +#define EXT3_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2483  #define EXT3_RESERVED_FL               0x80000000 /* reserved for ext3 lib */
2484  
2485 -#define EXT3_FL_USER_VISIBLE           0x0003DFFF /* User visible flags */
2486 -#define EXT3_FL_USER_MODIFIABLE                0x000380FF /* User modifiable flags */
2487 +#define EXT3_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2488 +#define EXT3_COW_FL                    0x20000000 /* Copy on Write marker */
2489 +
2490 +#define EXT3_FL_USER_VISIBLE           0x0103DFFF /* User visible flags */
2491 +#define EXT3_FL_USER_MODIFIABLE                0x010380FF /* User modifiable flags */
2492  
2493  /* Flags that should be inherited by new inodes from their parent. */
2494  #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2495 @@ -290,7 +294,8 @@ struct ext3_inode {
2496                         __u16   i_pad1;
2497                         __le16  l_i_uid_high;   /* these 2 fields    */
2498                         __le16  l_i_gid_high;   /* were reserved2[0] */
2499 -                       __u32   l_i_reserved2;
2500 +                       __le16  l_i_tag;        /* Context Tag */
2501 +                       __u16   l_i_reserved2;
2502                 } linux2;
2503                 struct {
2504                         __u8    h_i_frag;       /* Fragment number */
2505 @@ -320,6 +325,7 @@ struct ext3_inode {
2506  #define i_gid_low      i_gid
2507  #define i_uid_high     osd2.linux2.l_i_uid_high
2508  #define i_gid_high     osd2.linux2.l_i_gid_high
2509 +#define i_raw_tag      osd2.linux2.l_i_tag
2510  #define i_reserved2    osd2.linux2.l_i_reserved2
2511  
2512  /*
2513 @@ -364,6 +370,7 @@ struct ext3_inode {
2514  #define EXT3_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2515  #define EXT3_MOUNT_DATA_ERR_ABORT      0x400000 /* Abort on file data write
2516                                                   * error in ordered mode */
2517 +#define EXT3_MOUNT_TAGGED              (1<<24) /* Enable Context Tags */
2518  
2519  /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2520  #ifndef _LINUX_EXT2_FS_H
2521 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2522  extern void ext3_set_aops(struct inode *inode);
2523  extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2524                        u64 start, u64 len);
2525 +extern int ext3_sync_flags(struct inode *, int, int);
2526  
2527  /* ioctl.c */
2528  extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2529 diff -NurpP --minimal linux-3.10.40/fs/ext3/file.c linux-3.10.40-vs2.3.6.8/fs/ext3/file.c
2530 --- linux-3.10.40/fs/ext3/file.c        2012-12-11 03:30:57.000000000 +0000
2531 +++ linux-3.10.40-vs2.3.6.8/fs/ext3/file.c      2013-08-22 20:29:59.000000000 +0000
2532 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2533  #endif
2534         .get_acl        = ext3_get_acl,
2535         .fiemap         = ext3_fiemap,
2536 +       .sync_flags     = ext3_sync_flags,
2537  };
2538  
2539 diff -NurpP --minimal linux-3.10.40/fs/ext3/ialloc.c linux-3.10.40-vs2.3.6.8/fs/ext3/ialloc.c
2540 --- linux-3.10.40/fs/ext3/ialloc.c      2012-12-11 03:30:57.000000000 +0000
2541 +++ linux-3.10.40-vs2.3.6.8/fs/ext3/ialloc.c    2013-08-22 20:29:59.000000000 +0000
2542 @@ -14,6 +14,7 @@
2543  
2544  #include <linux/quotaops.h>
2545  #include <linux/random.h>
2546 +#include <linux/vs_tag.h>
2547  
2548  #include "ext3.h"
2549  #include "xattr.h"
2550 @@ -469,6 +470,7 @@ got:
2551                 inode->i_mode = mode;
2552                 inode->i_uid = current_fsuid();
2553                 inode->i_gid = dir->i_gid;
2554 +               i_tag_write(inode, dx_current_fstag(sb));
2555         } else
2556                 inode_init_owner(inode, dir, mode);
2557  
2558 diff -NurpP --minimal linux-3.10.40/fs/ext3/inode.c linux-3.10.40-vs2.3.6.8/fs/ext3/inode.c
2559 --- linux-3.10.40/fs/ext3/inode.c       2013-07-14 17:01:27.000000000 +0000
2560 +++ linux-3.10.40-vs2.3.6.8/fs/ext3/inode.c     2013-08-22 21:21:18.000000000 +0000
2561 @@ -28,6 +28,8 @@
2562  #include <linux/mpage.h>
2563  #include <linux/namei.h>
2564  #include <linux/aio.h>
2565 +#include <linux/vs_tag.h>
2566 +
2567  #include "ext3.h"
2568  #include "xattr.h"
2569  #include "acl.h"
2570 @@ -2853,36 +2855,60 @@ void ext3_set_inode_flags(struct inode *
2571  {
2572         unsigned int flags = EXT3_I(inode)->i_flags;
2573  
2574 -       inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2575 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2576 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2577 +
2578 +       if (flags & EXT3_IMMUTABLE_FL)
2579 +               inode->i_flags |= S_IMMUTABLE;
2580 +       if (flags & EXT3_IXUNLINK_FL)
2581 +               inode->i_flags |= S_IXUNLINK;
2582 +
2583         if (flags & EXT3_SYNC_FL)
2584                 inode->i_flags |= S_SYNC;
2585         if (flags & EXT3_APPEND_FL)
2586                 inode->i_flags |= S_APPEND;
2587 -       if (flags & EXT3_IMMUTABLE_FL)
2588 -               inode->i_flags |= S_IMMUTABLE;
2589         if (flags & EXT3_NOATIME_FL)
2590                 inode->i_flags |= S_NOATIME;
2591         if (flags & EXT3_DIRSYNC_FL)
2592                 inode->i_flags |= S_DIRSYNC;
2593 +
2594 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
2595 +
2596 +       if (flags & EXT3_BARRIER_FL)
2597 +               inode->i_vflags |= V_BARRIER;
2598 +       if (flags & EXT3_COW_FL)
2599 +               inode->i_vflags |= V_COW;
2600  }
2601  
2602  /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2603  void ext3_get_inode_flags(struct ext3_inode_info *ei)
2604  {
2605         unsigned int flags = ei->vfs_inode.i_flags;
2606 +       unsigned int vflags = ei->vfs_inode.i_vflags;
2607 +
2608 +       ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2609 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2610 +                       EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2611 +                       EXT3_BARRIER_FL | EXT3_COW_FL);
2612 +
2613 +       if (flags & S_IMMUTABLE)
2614 +               ei->i_flags |= EXT3_IMMUTABLE_FL;
2615 +       if (flags & S_IXUNLINK)
2616 +               ei->i_flags |= EXT3_IXUNLINK_FL;
2617  
2618 -       ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2619 -                       EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2620         if (flags & S_SYNC)
2621                 ei->i_flags |= EXT3_SYNC_FL;
2622         if (flags & S_APPEND)
2623                 ei->i_flags |= EXT3_APPEND_FL;
2624 -       if (flags & S_IMMUTABLE)
2625 -               ei->i_flags |= EXT3_IMMUTABLE_FL;
2626         if (flags & S_NOATIME)
2627                 ei->i_flags |= EXT3_NOATIME_FL;
2628         if (flags & S_DIRSYNC)
2629                 ei->i_flags |= EXT3_DIRSYNC_FL;
2630 +
2631 +       if (vflags & V_BARRIER)
2632 +               ei->i_flags |= EXT3_BARRIER_FL;
2633 +       if (vflags & V_COW)
2634 +               ei->i_flags |= EXT3_COW_FL;
2635  }
2636  
2637  struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2638 @@ -2920,8 +2946,10 @@ struct inode *ext3_iget(struct super_blo
2639                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2640                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2641         }
2642 -       i_uid_write(inode, i_uid);
2643 -       i_gid_write(inode, i_gid);
2644 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2645 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2646 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2647 +               le16_to_cpu(raw_inode->i_raw_tag)));
2648         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2649         inode->i_size = le32_to_cpu(raw_inode->i_size);
2650         inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2651 @@ -3093,8 +3121,10 @@ again:
2652  
2653         ext3_get_inode_flags(ei);
2654         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2655 -       i_uid = i_uid_read(inode);
2656 -       i_gid = i_gid_read(inode);
2657 +       i_uid = from_kuid(&init_user_ns,
2658 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2659 +       i_gid = from_kgid(&init_user_ns,
2660 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2661         if(!(test_opt(inode->i_sb, NO_UID32))) {
2662                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2663                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2664 @@ -3119,6 +3149,9 @@ again:
2665                 raw_inode->i_uid_high = 0;
2666                 raw_inode->i_gid_high = 0;
2667         }
2668 +#ifdef CONFIG_TAGGING_INTERN
2669 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2670 +#endif
2671         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2672         disksize = cpu_to_le32(ei->i_disksize);
2673         if (disksize != raw_inode->i_size) {
2674 @@ -3287,7 +3320,8 @@ int ext3_setattr(struct dentry *dentry,
2675         if (is_quota_modification(inode, attr))
2676                 dquot_initialize(inode);
2677         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2678 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2679 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2680 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2681                 handle_t *handle;
2682  
2683                 /* (user+group)*(old+new) structure, inode write (sb,
2684 @@ -3309,6 +3343,8 @@ int ext3_setattr(struct dentry *dentry,
2685                         inode->i_uid = attr->ia_uid;
2686                 if (attr->ia_valid & ATTR_GID)
2687                         inode->i_gid = attr->ia_gid;
2688 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2689 +                       inode->i_tag = attr->ia_tag;
2690                 error = ext3_mark_inode_dirty(handle, inode);
2691                 ext3_journal_stop(handle);
2692         }
2693 diff -NurpP --minimal linux-3.10.40/fs/ext3/ioctl.c linux-3.10.40-vs2.3.6.8/fs/ext3/ioctl.c
2694 --- linux-3.10.40/fs/ext3/ioctl.c       2013-05-31 13:45:23.000000000 +0000
2695 +++ linux-3.10.40-vs2.3.6.8/fs/ext3/ioctl.c     2013-08-22 20:29:59.000000000 +0000
2696 @@ -12,6 +12,34 @@
2697  #include <asm/uaccess.h>
2698  #include "ext3.h"
2699  
2700 +
2701 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2702 +{
2703 +       handle_t *handle = NULL;
2704 +       struct ext3_iloc iloc;
2705 +       int err;
2706 +
2707 +       handle = ext3_journal_start(inode, 1);
2708 +       if (IS_ERR(handle))
2709 +               return PTR_ERR(handle);
2710 +
2711 +       if (IS_SYNC(inode))
2712 +               handle->h_sync = 1;
2713 +       err = ext3_reserve_inode_write(handle, inode, &iloc);
2714 +       if (err)
2715 +               goto flags_err;
2716 +
2717 +       inode->i_flags = flags;
2718 +       inode->i_vflags = vflags;
2719 +       ext3_get_inode_flags(EXT3_I(inode));
2720 +       inode->i_ctime = CURRENT_TIME_SEC;
2721 +
2722 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2723 +flags_err:
2724 +       ext3_journal_stop(handle);
2725 +       return err;
2726 +}
2727 +
2728  long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2729  {
2730         struct inode *inode = file_inode(filp);
2731 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2732  
2733                 flags = ext3_mask_flags(inode->i_mode, flags);
2734  
2735 +               if (IS_BARRIER(inode)) {
2736 +                       vxwprintk_task(1, "messing with the barrier.");
2737 +                       return -EACCES;
2738 +               }
2739 +
2740                 mutex_lock(&inode->i_mutex);
2741  
2742                 /* Is it quota file? Do not allow user to mess with it */
2743 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2744                  *
2745                  * This test looks nicer. Thanks to Pauline Middelink
2746                  */
2747 -               if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2748 +               if ((oldflags & EXT3_IMMUTABLE_FL) ||
2749 +                       ((flags ^ oldflags) & (EXT3_APPEND_FL |
2750 +                       EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2751                         if (!capable(CAP_LINUX_IMMUTABLE))
2752                                 goto flags_out;
2753                 }
2754 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2755                 if (err)
2756                         goto flags_err;
2757  
2758 -               flags = flags & EXT3_FL_USER_MODIFIABLE;
2759 +               flags &= EXT3_FL_USER_MODIFIABLE;
2760                 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2761                 ei->i_flags = flags;
2762  
2763 diff -NurpP --minimal linux-3.10.40/fs/ext3/namei.c linux-3.10.40-vs2.3.6.8/fs/ext3/namei.c
2764 --- linux-3.10.40/fs/ext3/namei.c       2014-05-20 04:09:39.000000000 +0000
2765 +++ linux-3.10.40-vs2.3.6.8/fs/ext3/namei.c     2013-11-13 17:17:16.000000000 +0000
2766 @@ -25,6 +25,8 @@
2767   */
2768  
2769  #include <linux/quotaops.h>
2770 +#include <linux/vs_tag.h>
2771 +
2772  #include "ext3.h"
2773  #include "namei.h"
2774  #include "xattr.h"
2775 @@ -915,6 +917,7 @@ restart:
2776                                         submit_bh(READ | REQ_META | REQ_PRIO,
2777                                                   bh);
2778                                 }
2779 +               dx_propagate_tag(nd, inode);
2780                         }
2781                 }
2782                 if ((bh = bh_use[ra_ptr++]) == NULL)
2783 @@ -2524,6 +2527,7 @@ const struct inode_operations ext3_dir_i
2784         .listxattr      = ext3_listxattr,
2785         .removexattr    = generic_removexattr,
2786  #endif
2787 +       .sync_flags     = ext3_sync_flags,
2788         .get_acl        = ext3_get_acl,
2789  };
2790  
2791 diff -NurpP --minimal linux-3.10.40/fs/ext3/super.c linux-3.10.40-vs2.3.6.8/fs/ext3/super.c
2792 --- linux-3.10.40/fs/ext3/super.c       2013-07-14 17:01:27.000000000 +0000
2793 +++ linux-3.10.40-vs2.3.6.8/fs/ext3/super.c     2013-08-22 20:29:59.000000000 +0000
2794 @@ -813,7 +813,8 @@ enum {
2795         Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2796         Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2797         Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2798 -       Opt_resize, Opt_usrquota, Opt_grpquota
2799 +       Opt_resize, Opt_usrquota, Opt_grpquota,
2800 +       Opt_tag, Opt_notag, Opt_tagid
2801  };
2802  
2803  static const match_table_t tokens = {
2804 @@ -870,6 +871,9 @@ static const match_table_t tokens = {
2805         {Opt_barrier, "barrier"},
2806         {Opt_nobarrier, "nobarrier"},
2807         {Opt_resize, "resize"},
2808 +       {Opt_tag, "tag"},
2809 +       {Opt_notag, "notag"},
2810 +       {Opt_tagid, "tagid=%u"},
2811         {Opt_err, NULL},
2812  };
2813  
2814 @@ -1037,6 +1041,20 @@ static int parse_options (char *options,
2815                 case Opt_nouid32:
2816                         set_opt (sbi->s_mount_opt, NO_UID32);
2817                         break;
2818 +#ifndef CONFIG_TAGGING_NONE
2819 +               case Opt_tag:
2820 +                       set_opt (sbi->s_mount_opt, TAGGED);
2821 +                       break;
2822 +               case Opt_notag:
2823 +                       clear_opt (sbi->s_mount_opt, TAGGED);
2824 +                       break;
2825 +#endif
2826 +#ifdef CONFIG_PROPAGATE
2827 +               case Opt_tagid:
2828 +                       /* use args[0] */
2829 +                       set_opt (sbi->s_mount_opt, TAGGED);
2830 +                       break;
2831 +#endif
2832                 case Opt_nocheck:
2833                         clear_opt (sbi->s_mount_opt, CHECK);
2834                         break;
2835 @@ -1734,6 +1752,9 @@ static int ext3_fill_super (struct super
2836                             NULL, 0))
2837                 goto failed_mount;
2838  
2839 +       if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2840 +               sb->s_flags |= MS_TAGGED;
2841 +
2842         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2843                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2844  
2845 @@ -2629,6 +2650,14 @@ static int ext3_remount (struct super_bl
2846         if (test_opt(sb, ABORT))
2847                 ext3_abort(sb, __func__, "Abort forced by user");
2848  
2849 +       if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2850 +               !(sb->s_flags & MS_TAGGED)) {
2851 +               printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2852 +                       sb->s_id);
2853 +               err = -EINVAL;
2854 +               goto restore_opts;
2855 +       }
2856 +
2857         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2858                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2859  
2860 diff -NurpP --minimal linux-3.10.40/fs/ext4/ext4.h linux-3.10.40-vs2.3.6.8/fs/ext4/ext4.h
2861 --- linux-3.10.40/fs/ext4/ext4.h        2014-05-20 04:09:39.000000000 +0000
2862 +++ linux-3.10.40-vs2.3.6.8/fs/ext4/ext4.h      2014-03-12 13:18:32.000000000 +0000
2863 @@ -397,7 +397,10 @@ struct flex_groups {
2864  #define EXT4_EXTENTS_FL                        0x00080000 /* Inode uses extents */
2865  #define EXT4_EA_INODE_FL               0x00200000 /* Inode used for large EA */
2866  #define EXT4_EOFBLOCKS_FL              0x00400000 /* Blocks allocated beyond EOF */
2867 +#define EXT4_BARRIER_FL                        0x04000000 /* Barrier for chroot() */
2868 +#define EXT4_IXUNLINK_FL               0x08000000 /* Immutable invert on unlink */
2869  #define EXT4_INLINE_DATA_FL            0x10000000 /* Inode has inline data. */
2870 +#define EXT4_COW_FL                    0x20000000 /* Copy on Write marker */
2871  #define EXT4_RESERVED_FL               0x80000000 /* reserved for ext4 lib */
2872  
2873  #define EXT4_FL_USER_VISIBLE           0x004BDFFF /* User visible flags */
2874 @@ -673,7 +676,7 @@ struct ext4_inode {
2875                         __le16  l_i_uid_high;   /* these 2 fields */
2876                         __le16  l_i_gid_high;   /* were reserved2[0] */
2877                         __le16  l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2878 -                       __le16  l_i_reserved;
2879 +                       __le16  l_i_tag;        /* Context Tag */
2880                 } linux2;
2881                 struct {
2882                         __le16  h_i_reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
2883 @@ -793,6 +796,7 @@ do {                                                                               \
2884  #define i_gid_low      i_gid
2885  #define i_uid_high     osd2.linux2.l_i_uid_high
2886  #define i_gid_high     osd2.linux2.l_i_gid_high
2887 +#define i_raw_tag      osd2.linux2.l_i_tag
2888  #define i_checksum_lo  osd2.linux2.l_i_checksum_lo
2889  
2890  #elif defined(__GNU__)
2891 @@ -970,6 +974,7 @@ struct ext4_inode_info {
2892  #define EXT4_MOUNT_POSIX_ACL           0x08000 /* POSIX Access Control Lists */
2893  #define EXT4_MOUNT_NO_AUTO_DA_ALLOC    0x10000 /* No auto delalloc mapping */
2894  #define EXT4_MOUNT_BARRIER             0x20000 /* Use block barriers */
2895 +#define EXT4_MOUNT_TAGGED              0x40000 /* Enable Context Tags */
2896  #define EXT4_MOUNT_QUOTA               0x80000 /* Some quota option set */
2897  #define EXT4_MOUNT_USRQUOTA            0x100000 /* "old" user quota */
2898  #define EXT4_MOUNT_GRPQUOTA            0x200000 /* "old" group quota */
2899 @@ -2550,6 +2555,7 @@ extern struct buffer_head *ext4_get_firs
2900  extern int ext4_inline_data_fiemap(struct inode *inode,
2901                                    struct fiemap_extent_info *fieinfo,
2902                                    int *has_inline);
2903 +extern int ext4_sync_flags(struct inode *, int, int);
2904  extern int ext4_try_to_evict_inline_data(handle_t *handle,
2905                                          struct inode *inode,
2906                                          int needed);
2907 diff -NurpP --minimal linux-3.10.40/fs/ext4/file.c linux-3.10.40-vs2.3.6.8/fs/ext4/file.c
2908 --- linux-3.10.40/fs/ext4/file.c        2014-05-20 04:09:39.000000000 +0000
2909 +++ linux-3.10.40-vs2.3.6.8/fs/ext4/file.c      2014-05-20 04:31:55.000000000 +0000
2910 @@ -651,5 +651,6 @@ const struct inode_operations ext4_file_
2911         .removexattr    = generic_removexattr,
2912         .get_acl        = ext4_get_acl,
2913         .fiemap         = ext4_fiemap,
2914 +       .sync_flags     = ext4_sync_flags,
2915  };
2916  
2917 diff -NurpP --minimal linux-3.10.40/fs/ext4/ialloc.c linux-3.10.40-vs2.3.6.8/fs/ext4/ialloc.c
2918 --- linux-3.10.40/fs/ext4/ialloc.c      2014-05-20 04:09:39.000000000 +0000
2919 +++ linux-3.10.40-vs2.3.6.8/fs/ext4/ialloc.c    2013-11-13 17:17:16.000000000 +0000
2920 @@ -22,6 +22,7 @@
2921  #include <linux/random.h>
2922  #include <linux/bitops.h>
2923  #include <linux/blkdev.h>
2924 +#include <linux/vs_tag.h>
2925  #include <asm/byteorder.h>
2926  
2927  #include "ext4.h"
2928 @@ -679,6 +680,7 @@ struct inode *__ext4_new_inode(handle_t
2929                 inode->i_mode = mode;
2930                 inode->i_uid = current_fsuid();
2931                 inode->i_gid = dir->i_gid;
2932 +               i_tag_write(inode, dx_current_fstag(sb));
2933         } else
2934                 inode_init_owner(inode, dir, mode);
2935         dquot_initialize(inode);
2936 diff -NurpP --minimal linux-3.10.40/fs/ext4/inode.c linux-3.10.40-vs2.3.6.8/fs/ext4/inode.c
2937 --- linux-3.10.40/fs/ext4/inode.c       2014-05-20 04:09:39.000000000 +0000
2938 +++ linux-3.10.40-vs2.3.6.8/fs/ext4/inode.c     2014-04-22 03:51:19.000000000 +0000
2939 @@ -39,6 +39,7 @@
2940  #include <linux/ratelimit.h>
2941  #include <linux/aio.h>
2942  #include <linux/bitops.h>
2943 +#include <linux/vs_tag.h>
2944  
2945  #include "ext4_jbd2.h"
2946  #include "xattr.h"
2947 @@ -4047,42 +4048,67 @@ void ext4_set_inode_flags(struct inode *
2948         unsigned int flags = EXT4_I(inode)->i_flags;
2949         unsigned int new_fl = 0;
2950  
2951 +       if (flags & EXT4_IMMUTABLE_FL)
2952 +               new_fl |= S_IMMUTABLE;
2953 +       if (flags & EXT4_IXUNLINK_FL)
2954 +               new_fl |= S_IXUNLINK;
2955 +
2956         if (flags & EXT4_SYNC_FL)
2957                 new_fl |= S_SYNC;
2958         if (flags & EXT4_APPEND_FL)
2959                 new_fl |= S_APPEND;
2960 -       if (flags & EXT4_IMMUTABLE_FL)
2961 -               new_fl |= S_IMMUTABLE;
2962         if (flags & EXT4_NOATIME_FL)
2963                 new_fl |= S_NOATIME;
2964         if (flags & EXT4_DIRSYNC_FL)
2965                 new_fl |= S_DIRSYNC;
2966 +
2967         set_mask_bits(&inode->i_flags,
2968 -                     S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC, new_fl);
2969 +               S_IXUNLINK | S_IMMUTABLE |
2970 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC, new_fl);
2971 +
2972 +       new_fl = 0;
2973 +       if (flags & EXT4_BARRIER_FL)
2974 +               new_fl |= V_BARRIER;
2975 +       if (flags & EXT4_COW_FL)
2976 +               new_fl |= V_COW;
2977 +
2978 +       set_mask_bits(&inode->i_vflags,
2979 +               V_BARRIER | V_COW, new_fl);
2980  }
2981  
2982  /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2983  void ext4_get_inode_flags(struct ext4_inode_info *ei)
2984  {
2985 -       unsigned int vfs_fl;
2986 +       unsigned int vfs_fl, vfs_vf;
2987         unsigned long old_fl, new_fl;
2988  
2989         do {
2990                 vfs_fl = ei->vfs_inode.i_flags;
2991 +               vfs_vf = ei->vfs_inode.i_vflags;
2992                 old_fl = ei->i_flags;
2993                 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2994                                 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
2995 -                               EXT4_DIRSYNC_FL);
2996 +                               EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
2997 +                               EXT4_COW_FL);
2998 +
2999 +               if (vfs_fl & S_IMMUTABLE)
3000 +                       new_fl |= EXT4_IMMUTABLE_FL;
3001 +               if (vfs_fl & S_IXUNLINK)
3002 +                       new_fl |= EXT4_IXUNLINK_FL;
3003 +
3004                 if (vfs_fl & S_SYNC)
3005                         new_fl |= EXT4_SYNC_FL;
3006                 if (vfs_fl & S_APPEND)
3007                         new_fl |= EXT4_APPEND_FL;
3008 -               if (vfs_fl & S_IMMUTABLE)
3009 -                       new_fl |= EXT4_IMMUTABLE_FL;
3010                 if (vfs_fl & S_NOATIME)
3011                         new_fl |= EXT4_NOATIME_FL;
3012                 if (vfs_fl & S_DIRSYNC)
3013                         new_fl |= EXT4_DIRSYNC_FL;
3014 +
3015 +               if (vfs_vf & V_BARRIER)
3016 +                       new_fl |= EXT4_BARRIER_FL;
3017 +               if (vfs_vf & V_COW)
3018 +                       new_fl |= EXT4_COW_FL;
3019         } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3020  }
3021  
3022 @@ -4187,8 +4213,10 @@ struct inode *ext4_iget(struct super_blo
3023                 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3024                 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3025         }
3026 -       i_uid_write(inode, i_uid);
3027 -       i_gid_write(inode, i_gid);
3028 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3029 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3030 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3031 +               le16_to_cpu(raw_inode->i_raw_tag)));
3032         set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3033  
3034         ext4_clear_state_flags(ei);     /* Only relevant on 32-bit archs */
3035 @@ -4416,8 +4444,10 @@ static int ext4_do_update_inode(handle_t
3036  
3037         ext4_get_inode_flags(ei);
3038         raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3039 -       i_uid = i_uid_read(inode);
3040 -       i_gid = i_gid_read(inode);
3041 +       i_uid = from_kuid(&init_user_ns,
3042 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
3043 +       i_gid = from_kgid(&init_user_ns,
3044 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
3045         if (!(test_opt(inode->i_sb, NO_UID32))) {
3046                 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3047                 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3048 @@ -4440,6 +4470,9 @@ static int ext4_do_update_inode(handle_t
3049                 raw_inode->i_uid_high = 0;
3050                 raw_inode->i_gid_high = 0;
3051         }
3052 +#ifdef CONFIG_TAGGING_INTERN
3053 +       raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3054 +#endif
3055         raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3056  
3057         EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3058 @@ -4670,7 +4703,8 @@ int ext4_setattr(struct dentry *dentry,
3059         if (is_quota_modification(inode, attr))
3060                 dquot_initialize(inode);
3061         if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3062 -           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3063 +           (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3064 +           (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3065                 handle_t *handle;
3066  
3067                 /* (user+group)*(old+new) structure, inode write (sb,
3068 @@ -4693,6 +4727,8 @@ int ext4_setattr(struct dentry *dentry,
3069                         inode->i_uid = attr->ia_uid;
3070                 if (attr->ia_valid & ATTR_GID)
3071                         inode->i_gid = attr->ia_gid;
3072 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3073 +                       inode->i_tag = attr->ia_tag;
3074                 error = ext4_mark_inode_dirty(handle, inode);
3075                 ext4_journal_stop(handle);
3076         }
3077 diff -NurpP --minimal linux-3.10.40/fs/ext4/ioctl.c linux-3.10.40-vs2.3.6.8/fs/ext4/ioctl.c
3078 --- linux-3.10.40/fs/ext4/ioctl.c       2014-05-20 04:09:39.000000000 +0000
3079 +++ linux-3.10.40-vs2.3.6.8/fs/ext4/ioctl.c     2014-03-12 13:18:32.000000000 +0000
3080 @@ -14,6 +14,7 @@
3081  #include <linux/compat.h>
3082  #include <linux/mount.h>
3083  #include <linux/file.h>
3084 +#include <linux/vs_tag.h>
3085  #include <asm/uaccess.h>
3086  #include "ext4_jbd2.h"
3087  #include "ext4.h"
3088 @@ -215,6 +216,33 @@ swap_boot_out:
3089         return err;
3090  }
3091  
3092 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3093 +{
3094 +       handle_t *handle = NULL;
3095 +       struct ext4_iloc iloc;
3096 +       int err;
3097 +
3098 +       handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3099 +       if (IS_ERR(handle))
3100 +               return PTR_ERR(handle);
3101 +
3102 +       if (IS_SYNC(inode))
3103 +               ext4_handle_sync(handle);
3104 +       err = ext4_reserve_inode_write(handle, inode, &iloc);
3105 +       if (err)
3106 +               goto flags_err;
3107 +
3108 +       inode->i_flags = flags;
3109 +       inode->i_vflags = vflags;
3110 +       ext4_get_inode_flags(EXT4_I(inode));
3111 +       inode->i_ctime = ext4_current_time(inode);
3112 +
3113 +       err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3114 +flags_err:
3115 +       ext4_journal_stop(handle);
3116 +       return err;
3117 +}
3118 +
3119  long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3120  {
3121         struct inode *inode = file_inode(filp);
3122 @@ -248,6 +276,11 @@ long ext4_ioctl(struct file *filp, unsig
3123  
3124                 flags = ext4_mask_flags(inode->i_mode, flags);
3125  
3126 +               if (IS_BARRIER(inode)) {
3127 +                       vxwprintk_task(1, "messing with the barrier.");
3128 +                       return -EACCES;
3129 +               }
3130 +
3131                 err = -EPERM;
3132                 mutex_lock(&inode->i_mutex);
3133                 /* Is it quota file? Do not allow user to mess with it */
3134 @@ -265,7 +298,9 @@ long ext4_ioctl(struct file *filp, unsig
3135                  *
3136                  * This test looks nicer. Thanks to Pauline Middelink
3137                  */
3138 -               if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3139 +               if ((oldflags & EXT4_IMMUTABLE_FL) ||
3140 +                       ((flags ^ oldflags) & (EXT4_APPEND_FL |
3141 +                       EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3142                         if (!capable(CAP_LINUX_IMMUTABLE))
3143                                 goto flags_out;
3144                 }
3145 diff -NurpP --minimal linux-3.10.40/fs/ext4/namei.c linux-3.10.40-vs2.3.6.8/fs/ext4/namei.c
3146 --- linux-3.10.40/fs/ext4/namei.c       2014-05-20 04:09:39.000000000 +0000
3147 +++ linux-3.10.40-vs2.3.6.8/fs/ext4/namei.c     2013-11-13 17:17:16.000000000 +0000
3148 @@ -34,6 +34,7 @@
3149  #include <linux/quotaops.h>
3150  #include <linux/buffer_head.h>
3151  #include <linux/bio.h>
3152 +#include <linux/vs_tag.h>
3153  #include "ext4.h"
3154  #include "ext4_jbd2.h"
3155  
3156 @@ -1299,6 +1300,7 @@ restart:
3157                                         ll_rw_block(READ | REQ_META | REQ_PRIO,
3158                                                     1, &bh);
3159                         }
3160 +               dx_propagate_tag(nd, inode);
3161                 }
3162                 if ((bh = bh_use[ra_ptr++]) == NULL)
3163                         goto next;
3164 @@ -3177,6 +3179,7 @@ const struct inode_operations ext4_dir_i
3165         .removexattr    = generic_removexattr,
3166         .get_acl        = ext4_get_acl,
3167         .fiemap         = ext4_fiemap,
3168 +       .sync_flags     = ext4_sync_flags,
3169  };
3170  
3171  const struct inode_operations ext4_special_inode_operations = {
3172 diff -NurpP --minimal linux-3.10.40/fs/ext4/super.c linux-3.10.40-vs2.3.6.8/fs/ext4/super.c
3173 --- linux-3.10.40/fs/ext4/super.c       2014-05-20 04:09:39.000000000 +0000
3174 +++ linux-3.10.40-vs2.3.6.8/fs/ext4/super.c     2014-03-12 13:18:32.000000000 +0000
3175 @@ -1129,7 +1129,7 @@ enum {
3176         Opt_inode_readahead_blks, Opt_journal_ioprio,
3177         Opt_dioread_nolock, Opt_dioread_lock,
3178         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3179 -       Opt_max_dir_size_kb,
3180 +       Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3181  };
3182  
3183  static const match_table_t tokens = {
3184 @@ -1209,6 +1209,9 @@ static const match_table_t tokens = {
3185         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
3186         {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3187         {Opt_removed, "journal=%u"},    /* mount option from ext2/3 */
3188 +       {Opt_tag, "tag"},
3189 +       {Opt_notag, "notag"},
3190 +       {Opt_tagid, "tagid=%u"},
3191         {Opt_err, NULL},
3192  };
3193  
3194 @@ -1439,6 +1442,20 @@ static int handle_mount_opt(struct super
3195         case Opt_i_version:
3196                 sb->s_flags |= MS_I_VERSION;
3197                 return 1;
3198 +#ifndef CONFIG_TAGGING_NONE
3199 +       case Opt_tag:
3200 +               set_opt(sb, TAGGED);
3201 +               return 1;
3202 +       case Opt_notag:
3203 +               clear_opt(sb, TAGGED);
3204 +               return 1;
3205 +#endif
3206 +#ifdef CONFIG_PROPAGATE
3207 +       case Opt_tagid:
3208 +               /* use args[0] */
3209 +               set_opt(sb, TAGGED);
3210 +               return 1;
3211 +#endif
3212         }
3213  
3214         for (m = ext4_mount_opts; m->token != Opt_err; m++)
3215 @@ -3461,6 +3478,9 @@ static int ext4_fill_super(struct super_
3216                         clear_opt(sb, DELALLOC);
3217         }
3218  
3219 +       if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3220 +               sb->s_flags |= MS_TAGGED;
3221 +
3222         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3223                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3224  
3225 @@ -4679,6 +4699,14 @@ static int ext4_remount(struct super_blo
3226         if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3227                 ext4_abort(sb, "Abort forced by user");
3228  
3229 +       if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3230 +               !(sb->s_flags & MS_TAGGED)) {
3231 +               printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3232 +                       sb->s_id);
3233 +               err = -EINVAL;
3234 +               goto restore_opts;
3235 +       }
3236 +
3237         sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3238                 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3239  
3240 diff -NurpP --minimal linux-3.10.40/fs/fcntl.c linux-3.10.40-vs2.3.6.8/fs/fcntl.c
3241 --- linux-3.10.40/fs/fcntl.c    2013-05-31 13:45:23.000000000 +0000
3242 +++ linux-3.10.40-vs2.3.6.8/fs/fcntl.c  2013-08-22 20:29:59.000000000 +0000
3243 @@ -21,6 +21,7 @@
3244  #include <linux/rcupdate.h>
3245  #include <linux/pid_namespace.h>
3246  #include <linux/user_namespace.h>
3247 +#include <linux/vs_limit.h>
3248  
3249  #include <asm/poll.h>
3250  #include <asm/siginfo.h>
3251 @@ -378,6 +379,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3252  
3253         if (!f.file)
3254                 goto out;
3255 +       if (!vx_files_avail(1))
3256 +               goto out;
3257  
3258         if (unlikely(f.file->f_mode & FMODE_PATH)) {
3259                 if (!check_fcntl_cmd(cmd))
3260 diff -NurpP --minimal linux-3.10.40/fs/file.c linux-3.10.40-vs2.3.6.8/fs/file.c
3261 --- linux-3.10.40/fs/file.c     2014-05-20 04:09:39.000000000 +0000
3262 +++ linux-3.10.40-vs2.3.6.8/fs/file.c   2014-03-12 13:18:23.000000000 +0000
3263 @@ -22,6 +22,7 @@
3264  #include <linux/spinlock.h>
3265  #include <linux/rcupdate.h>
3266  #include <linux/workqueue.h>
3267 +#include <linux/vs_limit.h>
3268  
3269  int sysctl_nr_open __read_mostly = 1024*1024;
3270  int sysctl_nr_open_min = BITS_PER_LONG;
3271 @@ -311,6 +312,8 @@ struct files_struct *dup_fd(struct files
3272                 struct file *f = *old_fds++;
3273                 if (f) {
3274                         get_file(f);
3275 +                       /* TODO: sum it first for check and performance */
3276 +                       vx_openfd_inc(open_files - i);
3277                 } else {
3278                         /*
3279                          * The fd may be claimed in the fd bitmap but not yet
3280 @@ -376,9 +379,11 @@ static void close_files(struct files_str
3281                                         filp_close(file, files);
3282                                         cond_resched();
3283                                 }
3284 +                               vx_openfd_dec(i);
3285                         }
3286                         i++;
3287                         set >>= 1;
3288 +                       cond_resched();
3289                 }
3290         }
3291  }
3292 @@ -503,6 +508,7 @@ repeat:
3293         else
3294                 __clear_close_on_exec(fd, fdt);
3295         error = fd;
3296 +       vx_openfd_inc(fd);
3297  #if 1
3298         /* Sanity check */
3299         if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3300 @@ -533,6 +539,7 @@ static void __put_unused_fd(struct files
3301         __clear_open_fd(fd, fdt);
3302         if (fd < files->next_fd)
3303                 files->next_fd = fd;
3304 +       vx_openfd_dec(fd);
3305  }
3306  
3307  void put_unused_fd(unsigned int fd)
3308 @@ -812,6 +819,8 @@ static int do_dup2(struct files_struct *
3309  
3310         if (tofree)
3311                 filp_close(tofree, files);
3312 +       else
3313 +               vx_openfd_inc(fd);      /* fd was unused */
3314  
3315         return fd;
3316  
3317 diff -NurpP --minimal linux-3.10.40/fs/file_table.c linux-3.10.40-vs2.3.6.8/fs/file_table.c
3318 --- linux-3.10.40/fs/file_table.c       2013-07-14 17:01:28.000000000 +0000
3319 +++ linux-3.10.40-vs2.3.6.8/fs/file_table.c     2013-08-22 20:29:59.000000000 +0000
3320 @@ -26,6 +26,8 @@
3321  #include <linux/hardirq.h>
3322  #include <linux/task_work.h>
3323  #include <linux/ima.h>
3324 +#include <linux/vs_limit.h>
3325 +#include <linux/vs_context.h>
3326  
3327  #include <linux/atomic.h>
3328  
3329 @@ -140,6 +142,8 @@ struct file *get_empty_filp(void)
3330         spin_lock_init(&f->f_lock);
3331         eventpoll_init_file(f);
3332         /* f->f_version: 0 */
3333 +       f->f_xid = vx_current_xid();
3334 +       vx_files_inc(f);
3335         return f;
3336  
3337  over:
3338 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3339                 i_readcount_dec(inode);
3340         if (file->f_mode & FMODE_WRITE)
3341                 drop_file_write_access(file);
3342 +       vx_files_dec(file);
3343 +       file->f_xid = 0;
3344         file->f_path.dentry = NULL;
3345         file->f_path.mnt = NULL;
3346         file->f_inode = NULL;
3347 @@ -345,6 +351,8 @@ void put_filp(struct file *file)
3348  {
3349         if (atomic_long_dec_and_test(&file->f_count)) {
3350                 security_file_free(file);
3351 +               vx_files_dec(file);
3352 +               file->f_xid = 0;
3353                 file_sb_list_del(file);
3354                 file_free(file);
3355         }
3356 diff -NurpP --minimal linux-3.10.40/fs/fs_struct.c linux-3.10.40-vs2.3.6.8/fs/fs_struct.c
3357 --- linux-3.10.40/fs/fs_struct.c        2013-05-31 13:45:23.000000000 +0000
3358 +++ linux-3.10.40-vs2.3.6.8/fs/fs_struct.c      2013-08-22 20:29:59.000000000 +0000
3359 @@ -4,6 +4,7 @@
3360  #include <linux/path.h>
3361  #include <linux/slab.h>
3362  #include <linux/fs_struct.h>
3363 +#include <linux/vserver/global.h>
3364  #include "internal.h"
3365  
3366  /*
3367 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3368  {
3369         path_put(&fs->root);
3370         path_put(&fs->pwd);
3371 +       atomic_dec(&vs_global_fs);
3372         kmem_cache_free(fs_cachep, fs);
3373  }
3374  
3375 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3376                 fs->pwd = old->pwd;
3377                 path_get(&fs->pwd);
3378                 spin_unlock(&old->lock);
3379 +               atomic_inc(&vs_global_fs);
3380         }
3381         return fs;
3382  }
3383 diff -NurpP --minimal linux-3.10.40/fs/gfs2/file.c linux-3.10.40-vs2.3.6.8/fs/gfs2/file.c
3384 --- linux-3.10.40/fs/gfs2/file.c        2013-07-14 17:01:28.000000000 +0000
3385 +++ linux-3.10.40-vs2.3.6.8/fs/gfs2/file.c      2013-08-22 20:29:59.000000000 +0000
3386 @@ -144,6 +144,9 @@ static const u32 fsflags_to_gfs2[32] = {
3387         [12] = GFS2_DIF_EXHASH,
3388         [14] = GFS2_DIF_INHERIT_JDATA,
3389         [17] = GFS2_DIF_TOPDIR,
3390 +       [27] = GFS2_DIF_IXUNLINK,
3391 +       [26] = GFS2_DIF_BARRIER,
3392 +       [29] = GFS2_DIF_COW,
3393  };
3394  
3395  static const u32 gfs2_to_fsflags[32] = {
3396 @@ -154,6 +157,9 @@ static const u32 gfs2_to_fsflags[32] = {
3397         [gfs2fl_ExHash] = FS_INDEX_FL,
3398         [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3399         [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3400 +       [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3401 +       [gfs2fl_Barrier] = FS_BARRIER_FL,
3402 +       [gfs2fl_Cow] = FS_COW_FL,
3403  };
3404  
3405  static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3406 @@ -184,12 +190,18 @@ void gfs2_set_inode_flags(struct inode *
3407  {
3408         struct gfs2_inode *ip = GFS2_I(inode);
3409         unsigned int flags = inode->i_flags;
3410 +       unsigned int vflags = inode->i_vflags;
3411 +
3412 +       flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3413 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3414  
3415 -       flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3416         if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3417                 inode->i_flags |= S_NOSEC;
3418         if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3419                 flags |= S_IMMUTABLE;
3420 +       if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3421 +               flags |= S_IXUNLINK;
3422 +
3423         if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3424                 flags |= S_APPEND;
3425         if (ip->i_diskflags & GFS2_DIF_NOATIME)
3426 @@ -197,6 +209,43 @@ void gfs2_set_inode_flags(struct inode *
3427         if (ip->i_diskflags & GFS2_DIF_SYNC)
3428                 flags |= S_SYNC;
3429         inode->i_flags = flags;
3430 +
3431 +       vflags &= ~(V_BARRIER | V_COW);
3432 +
3433 +       if (ip->i_diskflags & GFS2_DIF_BARRIER)
3434 +               vflags |= V_BARRIER;
3435 +       if (ip->i_diskflags & GFS2_DIF_COW)
3436 +               vflags |= V_COW;
3437 +       inode->i_vflags = vflags;
3438 +}
3439 +
3440 +void gfs2_get_inode_flags(struct inode *inode)
3441 +{
3442 +       struct gfs2_inode *ip = GFS2_I(inode);
3443 +       unsigned int flags = inode->i_flags;
3444 +       unsigned int vflags = inode->i_vflags;
3445 +
3446 +       ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3447 +                       GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3448 +                       GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3449 +                       GFS2_DIF_BARRIER | GFS2_DIF_COW);
3450 +
3451 +       if (flags & S_IMMUTABLE)
3452 +               ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3453 +       if (flags & S_IXUNLINK)
3454 +               ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3455 +
3456 +       if (flags & S_APPEND)
3457 +               ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3458 +       if (flags & S_NOATIME)
3459 +               ip->i_diskflags |= GFS2_DIF_NOATIME;
3460 +       if (flags & S_SYNC)
3461 +               ip->i_diskflags |= GFS2_DIF_SYNC;
3462 +
3463 +       if (vflags & V_BARRIER)
3464 +               ip->i_diskflags |= GFS2_DIF_BARRIER;
3465 +       if (vflags & V_COW)
3466 +               ip->i_diskflags |= GFS2_DIF_COW;
3467  }
3468  
3469  /* Flags that can be set by user space */
3470 @@ -310,6 +359,37 @@ static int gfs2_set_flags(struct file *f
3471         return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3472  }
3473  
3474 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3475 +{
3476 +       struct gfs2_inode *ip = GFS2_I(inode);
3477 +       struct gfs2_sbd *sdp = GFS2_SB(inode);
3478 +       struct buffer_head *bh;
3479 +       struct gfs2_holder gh;
3480 +       int error;
3481 +
3482 +       error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3483 +       if (error)
3484 +               return error;
3485 +       error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3486 +       if (error)
3487 +               goto out;
3488 +       error = gfs2_meta_inode_buffer(ip, &bh);
3489 +       if (error)
3490 +               goto out_trans_end;
3491 +       gfs2_trans_add_meta(ip->i_gl, bh);
3492 +       inode->i_flags = flags;
3493 +       inode->i_vflags = vflags;
3494 +       gfs2_get_inode_flags(inode);
3495 +       gfs2_dinode_out(ip, bh->b_data);
3496 +       brelse(bh);
3497 +       gfs2_set_aops(inode);
3498 +out_trans_end:
3499 +       gfs2_trans_end(sdp);
3500 +out:
3501 +       gfs2_glock_dq_uninit(&gh);
3502 +       return error;
3503 +}
3504 +
3505  static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3506  {
3507         switch(cmd) {
3508 diff -NurpP --minimal linux-3.10.40/fs/gfs2/inode.h linux-3.10.40-vs2.3.6.8/fs/gfs2/inode.h
3509 --- linux-3.10.40/fs/gfs2/inode.h       2012-12-11 03:30:57.000000000 +0000
3510 +++ linux-3.10.40-vs2.3.6.8/fs/gfs2/inode.h     2013-08-22 20:29:59.000000000 +0000
3511 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3512  extern const struct file_operations gfs2_dir_fops_nolock;
3513  
3514  extern void gfs2_set_inode_flags(struct inode *inode);
3515 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3516   
3517  #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3518  extern const struct file_operations gfs2_file_fops;
3519 diff -NurpP --minimal linux-3.10.40/fs/hostfs/hostfs.h linux-3.10.40-vs2.3.6.8/fs/hostfs/hostfs.h
3520 --- linux-3.10.40/fs/hostfs/hostfs.h    2012-12-11 03:30:57.000000000 +0000
3521 +++ linux-3.10.40-vs2.3.6.8/fs/hostfs/hostfs.h  2013-08-22 20:29:59.000000000 +0000
3522 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3523         unsigned short  ia_mode;
3524         uid_t           ia_uid;
3525         gid_t           ia_gid;
3526 +       vtag_t          ia_tag;
3527         loff_t          ia_size;
3528         struct timespec ia_atime;
3529         struct timespec ia_mtime;
3530 diff -NurpP --minimal linux-3.10.40/fs/inode.c linux-3.10.40-vs2.3.6.8/fs/inode.c
3531 --- linux-3.10.40/fs/inode.c    2013-07-14 17:01:28.000000000 +0000
3532 +++ linux-3.10.40-vs2.3.6.8/fs/inode.c  2013-08-22 20:29:59.000000000 +0000
3533 @@ -17,6 +17,7 @@
3534  #include <linux/prefetch.h>
3535  #include <linux/buffer_head.h> /* for inode_has_buffers */
3536  #include <linux/ratelimit.h>
3537 +#include <linux/vs_tag.h>
3538  #include "internal.h"
3539  
3540  /*
3541 @@ -128,6 +129,8 @@ int inode_init_always(struct super_block
3542         struct address_space *const mapping = &inode->i_data;
3543  
3544         inode->i_sb = sb;
3545 +
3546 +       /* essential because of inode slab reuse */
3547         inode->i_blkbits = sb->s_blocksize_bits;
3548         inode->i_flags = 0;
3549         atomic_set(&inode->i_count, 1);
3550 @@ -137,6 +140,7 @@ int inode_init_always(struct super_block
3551         inode->i_opflags = 0;
3552         i_uid_write(inode, 0);
3553         i_gid_write(inode, 0);
3554 +       i_tag_write(inode, 0);
3555         atomic_set(&inode->i_writecount, 0);
3556         inode->i_size = 0;
3557         inode->i_blocks = 0;
3558 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3559         inode->i_bdev = NULL;
3560         inode->i_cdev = NULL;
3561         inode->i_rdev = 0;
3562 +       inode->i_mdev = 0;
3563         inode->dirtied_when = 0;
3564  
3565         if (security_inode_alloc(inode))
3566 @@ -483,6 +488,8 @@ void __insert_inode_hash(struct inode *i
3567  }
3568  EXPORT_SYMBOL(__insert_inode_hash);
3569  
3570 +EXPORT_SYMBOL_GPL(__iget);
3571 +
3572  /**
3573   *     __remove_inode_hash - remove an inode from the hash
3574   *     @inode: inode to unhash
3575 @@ -1799,9 +1806,11 @@ void init_special_inode(struct inode *in
3576         if (S_ISCHR(mode)) {
3577                 inode->i_fop = &def_chr_fops;
3578                 inode->i_rdev = rdev;
3579 +               inode->i_mdev = rdev;
3580         } else if (S_ISBLK(mode)) {
3581                 inode->i_fop = &def_blk_fops;
3582                 inode->i_rdev = rdev;
3583 +               inode->i_mdev = rdev;
3584         } else if (S_ISFIFO(mode))
3585                 inode->i_fop = &pipefifo_fops;
3586         else if (S_ISSOCK(mode))
3587 @@ -1830,6 +1839,7 @@ void inode_init_owner(struct inode *inod
3588         } else
3589                 inode->i_gid = current_fsgid();
3590         inode->i_mode = mode;
3591 +       i_tag_write(inode, dx_current_fstag(inode->i_sb));
3592  }
3593  EXPORT_SYMBOL(inode_init_owner);
3594  
3595 diff -NurpP --minimal linux-3.10.40/fs/ioctl.c linux-3.10.40-vs2.3.6.8/fs/ioctl.c
3596 --- linux-3.10.40/fs/ioctl.c    2013-05-31 13:45:24.000000000 +0000
3597 +++ linux-3.10.40-vs2.3.6.8/fs/ioctl.c  2013-08-22 20:29:59.000000000 +0000
3598 @@ -15,6 +15,9 @@
3599  #include <linux/writeback.h>
3600  #include <linux/buffer_head.h>
3601  #include <linux/falloc.h>
3602 +#include <linux/proc_fs.h>
3603 +#include <linux/vserver/inode.h>
3604 +#include <linux/vs_tag.h>
3605  
3606  #include <asm/ioctls.h>
3607  
3608 diff -NurpP --minimal linux-3.10.40/fs/ioprio.c linux-3.10.40-vs2.3.6.8/fs/ioprio.c
3609 --- linux-3.10.40/fs/ioprio.c   2012-12-11 03:30:57.000000000 +0000
3610 +++ linux-3.10.40-vs2.3.6.8/fs/ioprio.c 2013-08-22 20:29:59.000000000 +0000
3611 @@ -28,6 +28,7 @@
3612  #include <linux/syscalls.h>
3613  #include <linux/security.h>
3614  #include <linux/pid_namespace.h>
3615 +#include <linux/vs_base.h>
3616  
3617  int set_task_ioprio(struct task_struct *task, int ioprio)
3618  {
3619 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3620                         else
3621                                 pgrp = find_vpid(who);
3622                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3623 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3624 +                                       continue;
3625                                 ret = set_task_ioprio(p, ioprio);
3626                                 if (ret)
3627                                         break;
3628 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3629                         else
3630                                 pgrp = find_vpid(who);
3631                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3632 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3633 +                                       continue;
3634                                 tmpio = get_task_ioprio(p);
3635                                 if (tmpio < 0)
3636                                         continue;
3637 diff -NurpP --minimal linux-3.10.40/fs/jfs/file.c linux-3.10.40-vs2.3.6.8/fs/jfs/file.c
3638 --- linux-3.10.40/fs/jfs/file.c 2013-02-19 13:58:48.000000000 +0000
3639 +++ linux-3.10.40-vs2.3.6.8/fs/jfs/file.c       2013-08-22 20:29:59.000000000 +0000
3640 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3641         if (is_quota_modification(inode, iattr))
3642                 dquot_initialize(inode);
3643         if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3644 -           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3645 +           (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3646 +           (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3647                 rc = dquot_transfer(inode, iattr);
3648                 if (rc)
3649                         return rc;
3650 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3651  #ifdef CONFIG_JFS_POSIX_ACL
3652         .get_acl        = jfs_get_acl,
3653  #endif
3654 +       .sync_flags     = jfs_sync_flags,
3655  };
3656  
3657  const struct file_operations jfs_file_operations = {
3658 diff -NurpP --minimal linux-3.10.40/fs/jfs/ioctl.c linux-3.10.40-vs2.3.6.8/fs/jfs/ioctl.c
3659 --- linux-3.10.40/fs/jfs/ioctl.c        2013-05-31 13:45:24.000000000 +0000
3660 +++ linux-3.10.40-vs2.3.6.8/fs/jfs/ioctl.c      2013-08-22 20:29:59.000000000 +0000
3661 @@ -12,6 +12,7 @@
3662  #include <linux/time.h>
3663  #include <linux/sched.h>
3664  #include <linux/blkdev.h>
3665 +#include <linux/mount.h>
3666  #include <asm/current.h>
3667  #include <asm/uaccess.h>
3668  
3669 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3670  }
3671  
3672  
3673 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3674 +{
3675 +       inode->i_flags = flags;
3676 +       inode->i_vflags = vflags;
3677 +       jfs_get_inode_flags(JFS_IP(inode));
3678 +       inode->i_ctime = CURRENT_TIME_SEC;
3679 +       mark_inode_dirty(inode);
3680 +       return 0;
3681 +}
3682 +
3683  long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3684  {
3685         struct inode *inode = file_inode(filp);
3686 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3687                 if (!S_ISDIR(inode->i_mode))
3688                         flags &= ~JFS_DIRSYNC_FL;
3689  
3690 +               if (IS_BARRIER(inode)) {
3691 +                       vxwprintk_task(1, "messing with the barrier.");
3692 +                       return -EACCES;
3693 +               }
3694 +
3695                 /* Is it quota file? Do not allow user to mess with it */
3696                 if (IS_NOQUOTA(inode)) {
3697                         err = -EPERM;
3698 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3699                  * the relevant capability.
3700                  */
3701                 if ((oldflags & JFS_IMMUTABLE_FL) ||
3702 -                       ((flags ^ oldflags) &
3703 -                       (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3704 +                       ((flags ^ oldflags) & (JFS_APPEND_FL |
3705 +                       JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3706                         if (!capable(CAP_LINUX_IMMUTABLE)) {
3707                                 mutex_unlock(&inode->i_mutex);
3708                                 err = -EPERM;
3709 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3710                         }
3711                 }
3712  
3713 -               flags = flags & JFS_FL_USER_MODIFIABLE;
3714 +               flags &= JFS_FL_USER_MODIFIABLE;
3715                 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3716                 jfs_inode->mode2 = flags;
3717  
3718 diff -NurpP --minimal linux-3.10.40/fs/jfs/jfs_dinode.h linux-3.10.40-vs2.3.6.8/fs/jfs/jfs_dinode.h
3719 --- linux-3.10.40/fs/jfs/jfs_dinode.h   2012-12-11 03:30:57.000000000 +0000
3720 +++ linux-3.10.40-vs2.3.6.8/fs/jfs/jfs_dinode.h 2013-08-22 20:29:59.000000000 +0000
3721 @@ -161,9 +161,13 @@ struct dinode {
3722  
3723  #define JFS_APPEND_FL          0x01000000 /* writes to file may only append */
3724  #define JFS_IMMUTABLE_FL       0x02000000 /* Immutable file */
3725 +#define JFS_IXUNLINK_FL                0x08000000 /* Immutable invert on unlink */
3726  
3727 -#define JFS_FL_USER_VISIBLE    0x03F80000
3728 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3729 +#define JFS_BARRIER_FL         0x04000000 /* Barrier for chroot() */
3730 +#define JFS_COW_FL             0x20000000 /* Copy on Write marker */
3731 +
3732 +#define JFS_FL_USER_VISIBLE    0x07F80000
3733 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3734  #define JFS_FL_INHERIT         0x03C80000
3735  
3736  /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3737 diff -NurpP --minimal linux-3.10.40/fs/jfs/jfs_filsys.h linux-3.10.40-vs2.3.6.8/fs/jfs/jfs_filsys.h
3738 --- linux-3.10.40/fs/jfs/jfs_filsys.h   2012-12-11 03:30:57.000000000 +0000
3739 +++ linux-3.10.40-vs2.3.6.8/fs/jfs/jfs_filsys.h 2013-08-22 20:29:59.000000000 +0000
3740 @@ -266,6 +266,7 @@
3741  #define JFS_NAME_MAX   255
3742  #define JFS_PATH_MAX   BPSIZE
3743  
3744 +#define JFS_TAGGED             0x00800000      /* Context Tagging */
3745  
3746  /*
3747   *     file system state (superblock state)
3748 diff -NurpP --minimal linux-3.10.40/fs/jfs/jfs_imap.c linux-3.10.40-vs2.3.6.8/fs/jfs/jfs_imap.c
3749 --- linux-3.10.40/fs/jfs/jfs_imap.c     2013-07-14 17:01:28.000000000 +0000
3750 +++ linux-3.10.40-vs2.3.6.8/fs/jfs/jfs_imap.c   2013-08-22 20:29:59.000000000 +0000
3751 @@ -46,6 +46,7 @@
3752  #include <linux/pagemap.h>
3753  #include <linux/quotaops.h>
3754  #include <linux/slab.h>
3755 +#include <linux/vs_tag.h>
3756  
3757  #include "jfs_incore.h"
3758  #include "jfs_inode.h"
3759 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3760  {
3761         struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3762         struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3763 +       kuid_t kuid;
3764 +       kgid_t kgid;
3765  
3766         jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3767         jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3768 @@ -3078,14 +3081,18 @@ static int copy_from_dinode(struct dinod
3769         }
3770         set_nlink(ip, le32_to_cpu(dip->di_nlink));
3771  
3772 -       jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3773 +       kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3774 +       kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3775 +       ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3776 +
3777 +       jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3778         if (!uid_valid(sbi->uid))
3779                 ip->i_uid = jfs_ip->saved_uid;
3780         else {
3781                 ip->i_uid = sbi->uid;
3782         }
3783  
3784 -       jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3785 +       jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3786         if (!gid_valid(sbi->gid))
3787                 ip->i_gid = jfs_ip->saved_gid;
3788         else {
3789 @@ -3150,16 +3157,14 @@ static void copy_to_dinode(struct dinode
3790         dip->di_size = cpu_to_le64(ip->i_size);
3791         dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3792         dip->di_nlink = cpu_to_le32(ip->i_nlink);
3793 -       if (!uid_valid(sbi->uid))
3794 -               dip->di_uid = cpu_to_le32(i_uid_read(ip));
3795 -       else
3796 -               dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3797 -                                                  jfs_ip->saved_uid));
3798 -       if (!gid_valid(sbi->gid))
3799 -               dip->di_gid = cpu_to_le32(i_gid_read(ip));
3800 -       else
3801 -               dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3802 -                                                   jfs_ip->saved_gid));
3803 +       dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3804 +               TAGINO_KUID(DX_TAG(ip),
3805 +               !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3806 +               ip->i_tag)));
3807 +       dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3808 +               TAGINO_KGID(DX_TAG(ip),
3809 +               !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3810 +               ip->i_tag)));
3811         jfs_get_inode_flags(jfs_ip);
3812         /*
3813          * mode2 is only needed for storing the higher order bits.
3814 diff -NurpP --minimal linux-3.10.40/fs/jfs/jfs_inode.c linux-3.10.40-vs2.3.6.8/fs/jfs/jfs_inode.c
3815 --- linux-3.10.40/fs/jfs/jfs_inode.c    2014-05-20 04:09:39.000000000 +0000
3816 +++ linux-3.10.40-vs2.3.6.8/fs/jfs/jfs_inode.c  2013-11-13 17:22:25.000000000 +0000
3817 @@ -18,6 +18,7 @@
3818  
3819  #include <linux/fs.h>
3820  #include <linux/quotaops.h>
3821 +#include <linux/vs_tag.h>
3822  #include "jfs_incore.h"
3823  #include "jfs_inode.h"
3824  #include "jfs_filsys.h"
3825 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3826  {
3827         unsigned int flags = JFS_IP(inode)->mode2;
3828  
3829 -       inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3830 -               S_NOATIME | S_DIRSYNC | S_SYNC);
3831 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3832 +               S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3833  
3834         if (flags & JFS_IMMUTABLE_FL)
3835                 inode->i_flags |= S_IMMUTABLE;
3836 +       if (flags & JFS_IXUNLINK_FL)
3837 +               inode->i_flags |= S_IXUNLINK;
3838 +
3839 +       if (flags & JFS_SYNC_FL)
3840 +               inode->i_flags |= S_SYNC;
3841         if (flags & JFS_APPEND_FL)
3842                 inode->i_flags |= S_APPEND;
3843         if (flags & JFS_NOATIME_FL)
3844                 inode->i_flags |= S_NOATIME;
3845         if (flags & JFS_DIRSYNC_FL)
3846                 inode->i_flags |= S_DIRSYNC;
3847 -       if (flags & JFS_SYNC_FL)
3848 -               inode->i_flags |= S_SYNC;
3849 +
3850 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
3851 +
3852 +       if (flags & JFS_BARRIER_FL)
3853 +               inode->i_vflags |= V_BARRIER;
3854 +       if (flags & JFS_COW_FL)
3855 +               inode->i_vflags |= V_COW;
3856  }
3857  
3858  void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3859  {
3860         unsigned int flags = jfs_ip->vfs_inode.i_flags;
3861 +       unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3862 +
3863 +       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3864 +                          JFS_APPEND_FL | JFS_NOATIME_FL |
3865 +                          JFS_DIRSYNC_FL | JFS_SYNC_FL |
3866 +                          JFS_BARRIER_FL | JFS_COW_FL);
3867  
3868 -       jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3869 -                          JFS_DIRSYNC_FL | JFS_SYNC_FL);
3870         if (flags & S_IMMUTABLE)
3871                 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3872 +       if (flags & S_IXUNLINK)
3873 +               jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3874 +
3875         if (flags & S_APPEND)
3876                 jfs_ip->mode2 |= JFS_APPEND_FL;
3877         if (flags & S_NOATIME)
3878 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3879                 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3880         if (flags & S_SYNC)
3881                 jfs_ip->mode2 |= JFS_SYNC_FL;
3882 +
3883 +       if (vflags & V_BARRIER)
3884 +               jfs_ip->mode2 |= JFS_BARRIER_FL;
3885 +       if (vflags & V_COW)
3886 +               jfs_ip->mode2 |= JFS_COW_FL;
3887  }
3888  
3889  /*
3890 diff -NurpP --minimal linux-3.10.40/fs/jfs/jfs_inode.h linux-3.10.40-vs2.3.6.8/fs/jfs/jfs_inode.h
3891 --- linux-3.10.40/fs/jfs/jfs_inode.h    2012-12-11 03:30:57.000000000 +0000
3892 +++ linux-3.10.40-vs2.3.6.8/fs/jfs/jfs_inode.h  2013-08-22 20:29:59.000000000 +0000
3893 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3894  extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3895         int fh_len, int fh_type);
3896  extern void jfs_set_inode_flags(struct inode *);
3897 +extern int jfs_sync_flags(struct inode *, int, int);
3898  extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3899  extern int jfs_setattr(struct dentry *, struct iattr *);
3900  
3901 diff -NurpP --minimal linux-3.10.40/fs/jfs/namei.c linux-3.10.40-vs2.3.6.8/fs/jfs/namei.c
3902 --- linux-3.10.40/fs/jfs/namei.c        2012-12-11 03:30:57.000000000 +0000
3903 +++ linux-3.10.40-vs2.3.6.8/fs/jfs/namei.c      2013-08-22 20:29:59.000000000 +0000
3904 @@ -22,6 +22,7 @@
3905  #include <linux/ctype.h>
3906  #include <linux/quotaops.h>
3907  #include <linux/exportfs.h>
3908 +#include <linux/vs_tag.h>
3909  #include "jfs_incore.h"
3910  #include "jfs_superblock.h"
3911  #include "jfs_inode.h"
3912 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3913                         jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3914         }
3915  
3916 +       dx_propagate_tag(nd, ip);
3917         return d_splice_alias(ip, dentry);
3918  }
3919  
3920 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
3921  #ifdef CONFIG_JFS_POSIX_ACL
3922         .get_acl        = jfs_get_acl,
3923  #endif
3924 +       .sync_flags     = jfs_sync_flags,
3925  };
3926  
3927  const struct file_operations jfs_dir_operations = {
3928 diff -NurpP --minimal linux-3.10.40/fs/jfs/super.c linux-3.10.40-vs2.3.6.8/fs/jfs/super.c
3929 --- linux-3.10.40/fs/jfs/super.c        2013-07-14 17:01:28.000000000 +0000
3930 +++ linux-3.10.40-vs2.3.6.8/fs/jfs/super.c      2013-08-22 20:29:59.000000000 +0000
3931 @@ -199,7 +199,8 @@ enum {
3932         Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
3933         Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
3934         Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
3935 -       Opt_discard, Opt_nodiscard, Opt_discard_minblk
3936 +       Opt_discard, Opt_nodiscard, Opt_discard_minblk,
3937 +       Opt_tag, Opt_notag, Opt_tagid
3938  };
3939  
3940  static const match_table_t tokens = {
3941 @@ -209,6 +210,10 @@ static const match_table_t tokens = {
3942         {Opt_resize, "resize=%u"},
3943         {Opt_resize_nosize, "resize"},
3944         {Opt_errors, "errors=%s"},
3945 +       {Opt_tag, "tag"},
3946 +       {Opt_notag, "notag"},
3947 +       {Opt_tagid, "tagid=%u"},
3948 +       {Opt_tag, "tagxid"},
3949         {Opt_ignore, "noquota"},
3950         {Opt_ignore, "quota"},
3951         {Opt_usrquota, "usrquota"},
3952 @@ -385,7 +390,20 @@ static int parse_options(char *options,
3953                         }
3954                         break;
3955                 }
3956 -
3957 +#ifndef CONFIG_TAGGING_NONE
3958 +               case Opt_tag:
3959 +                       *flag |= JFS_TAGGED;
3960 +                       break;
3961 +               case Opt_notag:
3962 +                       *flag &= JFS_TAGGED;
3963 +                       break;
3964 +#endif
3965 +#ifdef CONFIG_PROPAGATE
3966 +               case Opt_tagid:
3967 +                       /* use args[0] */
3968 +                       *flag |= JFS_TAGGED;
3969 +                       break;
3970 +#endif
3971                 default:
3972                         printk("jfs: Unrecognized mount option \"%s\" "
3973                                         " or missing value\n", p);
3974 @@ -417,6 +435,12 @@ static int jfs_remount(struct super_bloc
3975                 return -EINVAL;
3976         }
3977  
3978 +       if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
3979 +               printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
3980 +                       sb->s_id);
3981 +               return -EINVAL;
3982 +       }
3983 +
3984         if (newLVSize) {
3985                 if (sb->s_flags & MS_RDONLY) {
3986                         pr_err("JFS: resize requires volume" \
3987 @@ -502,6 +526,9 @@ static int jfs_fill_super(struct super_b
3988  #ifdef CONFIG_JFS_POSIX_ACL
3989         sb->s_flags |= MS_POSIXACL;
3990  #endif
3991 +       /* map mount option tagxid */
3992 +       if (sbi->flag & JFS_TAGGED)
3993 +               sb->s_flags |= MS_TAGGED;
3994  
3995         if (newLVSize) {
3996                 pr_err("resize option for remount only\n");
3997 diff -NurpP --minimal linux-3.10.40/fs/libfs.c linux-3.10.40-vs2.3.6.8/fs/libfs.c
3998 --- linux-3.10.40/fs/libfs.c    2013-02-19 13:58:48.000000000 +0000
3999 +++ linux-3.10.40-vs2.3.6.8/fs/libfs.c  2013-08-22 20:29:59.000000000 +0000
4000 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4001   * both impossible due to the lock on directory.
4002   */
4003  
4004 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4005 +static inline int do_dcache_readdir_filter(struct file *filp,
4006 +       void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4007  {
4008         struct dentry *dentry = filp->f_path.dentry;
4009         struct dentry *cursor = filp->private_data;
4010 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4011                         for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4012                                 struct dentry *next;
4013                                 next = list_entry(p, struct dentry, d_u.d_child);
4014 +                               if (filter && !filter(next))
4015 +                                       continue;
4016                                 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4017                                 if (!simple_positive(next)) {
4018                                         spin_unlock(&next->d_lock);
4019 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4020         return 0;
4021  }
4022  
4023 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4024 +{
4025 +       return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4026 +}
4027 +
4028 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4029 +       int (*filter)(struct dentry *))
4030 +{
4031 +       return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4032 +}
4033 +
4034  ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4035  {
4036         return -EISDIR;
4037 @@ -981,6 +995,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4038  EXPORT_SYMBOL(dcache_dir_lseek);
4039  EXPORT_SYMBOL(dcache_dir_open);
4040  EXPORT_SYMBOL(dcache_readdir);
4041 +EXPORT_SYMBOL(dcache_readdir_filter);
4042  EXPORT_SYMBOL(generic_read_dir);
4043  EXPORT_SYMBOL(mount_pseudo);
4044  EXPORT_SYMBOL(simple_write_begin);
4045 diff -NurpP --minimal linux-3.10.40/fs/locks.c linux-3.10.40-vs2.3.6.8/fs/locks.c
4046 --- linux-3.10.40/fs/locks.c    2014-05-20 04:09:39.000000000 +0000
4047 +++ linux-3.10.40-vs2.3.6.8/fs/locks.c  2014-05-20 04:31:55.000000000 +0000
4048 @@ -126,6 +126,8 @@
4049  #include <linux/time.h>
4050  #include <linux/rcupdate.h>
4051  #include <linux/pid_namespace.h>
4052 +#include <linux/vs_base.h>
4053 +#include <linux/vs_limit.h>
4054  
4055  #include <asm/uaccess.h>
4056  
4057 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4058  /* Allocate an empty lock structure. */
4059  struct file_lock *locks_alloc_lock(void)
4060  {
4061 -       struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4062 +       struct file_lock *fl;
4063  
4064 -       if (fl)
4065 -               locks_init_lock_heads(fl);
4066 +       if (!vx_locks_avail(1))
4067 +               return NULL;
4068  
4069 +       fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4070 +
4071 +       if (fl) {
4072 +               locks_init_lock_heads(fl);
4073 +               fl->fl_xid = -1;
4074 +       }
4075         return fl;
4076  }
4077  EXPORT_SYMBOL_GPL(locks_alloc_lock);
4078 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4079         BUG_ON(!list_empty(&fl->fl_block));
4080         BUG_ON(!list_empty(&fl->fl_link));
4081  
4082 +       vx_locks_dec(fl);
4083         locks_release_private(fl);
4084         kmem_cache_free(filelock_cache, fl);
4085  }
4086 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4087  {
4088         memset(fl, 0, sizeof(struct file_lock));
4089         locks_init_lock_heads(fl);
4090 +       fl->fl_xid = -1;
4091  }
4092  
4093  EXPORT_SYMBOL(locks_init_lock);
4094 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4095         new->fl_file = fl->fl_file;
4096         new->fl_ops = fl->fl_ops;
4097         new->fl_lmops = fl->fl_lmops;
4098 +       new->fl_xid = fl->fl_xid;
4099  
4100         locks_copy_private(new, fl);
4101  }
4102 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4103         fl->fl_flags = FL_FLOCK;
4104         fl->fl_type = type;
4105         fl->fl_end = OFFSET_MAX;
4106 +
4107 +       vxd_assert(filp->f_xid == vx_current_xid(),
4108 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4109 +       fl->fl_xid = filp->f_xid;
4110 +       vx_locks_inc(fl);
4111         
4112         *lock = fl;
4113         return 0;
4114 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4115  
4116         fl->fl_owner = current->files;
4117         fl->fl_pid = current->tgid;
4118 +       fl->fl_xid = vx_current_xid();
4119  
4120         fl->fl_file = filp;
4121         fl->fl_flags = FL_LEASE;
4122 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4123         if (fl == NULL)
4124                 return ERR_PTR(error);
4125  
4126 +       fl->fl_xid = vx_current_xid();
4127 +       if (filp)
4128 +               vxd_assert(filp->f_xid == fl->fl_xid,
4129 +                       "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4130 +       vx_locks_inc(fl);
4131         error = lease_init(filp, type, fl);
4132         if (error) {
4133                 locks_free_lock(fl);
4134 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4135                 lock_flocks();
4136         }
4137  
4138 +       new_fl->fl_xid = -1;
4139  find_conflict:
4140         for_each_lock(inode, before) {
4141                 struct file_lock *fl = *before;
4142 @@ -773,6 +796,7 @@ find_conflict:
4143                 goto out;
4144         locks_copy_lock(new_fl, request);
4145         locks_insert_lock(before, new_fl);
4146 +       vx_locks_inc(new_fl);
4147         new_fl = NULL;
4148         error = 0;
4149  
4150 @@ -783,7 +807,8 @@ out:
4151         return error;
4152  }
4153  
4154 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4155 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4156 +       struct file_lock *conflock, vxid_t xid)
4157  {
4158         struct file_lock *fl;
4159         struct file_lock *new_fl = NULL;
4160 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4161         struct file_lock **before;
4162         int error, added = 0;
4163  
4164 +       vxd_assert(xid == vx_current_xid(),
4165 +               "xid(%d) == current(%d)", xid, vx_current_xid());
4166         /*
4167          * We may need two file_lock structures for this operation,
4168          * so we get them in advance to avoid races.
4169 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4170             (request->fl_type != F_UNLCK ||
4171              request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4172                 new_fl = locks_alloc_lock();
4173 +               new_fl->fl_xid = xid;
4174 +               vx_locks_inc(new_fl);
4175                 new_fl2 = locks_alloc_lock();
4176 +               new_fl2->fl_xid = xid;
4177 +               vx_locks_inc(new_fl2);
4178         }
4179  
4180         lock_flocks();
4181 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4182  int posix_lock_file(struct file *filp, struct file_lock *fl,
4183                         struct file_lock *conflock)
4184  {
4185 -       return __posix_lock_file(file_inode(filp), fl, conflock);
4186 +       return __posix_lock_file(file_inode(filp),
4187 +               fl, conflock, filp->f_xid);
4188  }
4189  EXPORT_SYMBOL(posix_lock_file);
4190  
4191 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4192         fl.fl_end = offset + count - 1;
4193  
4194         for (;;) {
4195 -               error = __posix_lock_file(inode, &fl, NULL);
4196 +               error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4197                 if (error != FILE_LOCK_DEFERRED)
4198                         break;
4199                 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4200 @@ -1396,6 +1428,7 @@ int generic_add_lease(struct file *filp,
4201                 goto out;
4202  
4203         locks_insert_lock(before, lease);
4204 +       vx_locks_inc(lease);
4205         return 0;
4206  
4207  out:
4208 @@ -1835,6 +1868,11 @@ int fcntl_setlk(unsigned int fd, struct
4209         if (file_lock == NULL)
4210                 return -ENOLCK;
4211  
4212 +       vxd_assert(filp->f_xid == vx_current_xid(),
4213 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4214 +       file_lock->fl_xid = filp->f_xid;
4215 +       vx_locks_inc(file_lock);
4216 +
4217         /*
4218          * This might block, so we do it before checking the inode.
4219          */
4220 @@ -1953,6 +1991,11 @@ int fcntl_setlk64(unsigned int fd, struc
4221         if (file_lock == NULL)
4222                 return -ENOLCK;
4223  
4224 +       vxd_assert(filp->f_xid == vx_current_xid(),
4225 +               "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4226 +       file_lock->fl_xid = filp->f_xid;
4227 +       vx_locks_inc(file_lock);
4228 +
4229         /*
4230          * This might block, so we do it before checking the inode.
4231          */
4232 @@ -2218,8 +2261,11 @@ static int locks_show(struct seq_file *f
4233  
4234         lock_get_status(f, fl, *((loff_t *)f->private), "");
4235  
4236 -       list_for_each_entry(bfl, &fl->fl_block, fl_block)
4237 +       list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4238 +               if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4239 +                       continue;
4240                 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4241 +       }
4242  
4243         return 0;
4244  }
4245 diff -NurpP --minimal linux-3.10.40/fs/mount.h linux-3.10.40-vs2.3.6.8/fs/mount.h
4246 --- linux-3.10.40/fs/mount.h    2014-05-20 04:09:39.000000000 +0000
4247 +++ linux-3.10.40-vs2.3.6.8/fs/mount.h  2014-03-12 13:18:23.000000000 +0000
4248 @@ -56,6 +56,7 @@ struct mount {
4249         int mnt_expiry_mark;            /* true if marked for expiry */
4250         int mnt_pinned;
4251         int mnt_ghosts;
4252 +       vtag_t mnt_tag;                 /* tagging used for vfsmount */
4253  };
4254  
4255  #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4256 diff -NurpP --minimal linux-3.10.40/fs/namei.c linux-3.10.40-vs2.3.6.8/fs/namei.c
4257 --- linux-3.10.40/fs/namei.c    2014-05-20 04:09:39.000000000 +0000
4258 +++ linux-3.10.40-vs2.3.6.8/fs/namei.c  2014-04-22 03:48:11.000000000 +0000
4259 @@ -34,9 +34,19 @@
4260  #include <linux/device_cgroup.h>
4261  #include <linux/fs_struct.h>
4262  #include <linux/posix_acl.h>
4263 +#include <linux/proc_fs.h>
4264 +#include <linux/magic.h>
4265 +#include <linux/vserver/inode.h>
4266 +#include <linux/vs_base.h>
4267 +#include <linux/vs_tag.h>
4268 +#include <linux/vs_cowbl.h>
4269 +#include <linux/vs_device.h>
4270 +#include <linux/vs_context.h>
4271 +#include <linux/pid_namespace.h>
4272  #include <asm/uaccess.h>
4273  
4274  #include "internal.h"
4275 +#include "proc/internal.h"
4276  #include "mount.h"
4277  
4278  /* [Feb-1997 T. Schoebel-Theuer]
4279 @@ -266,6 +276,89 @@ static int check_acl(struct inode *inode
4280         return -EAGAIN;
4281  }
4282  
4283 +static inline int dx_barrier(const struct inode *inode)
4284 +{
4285 +       if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4286 +               vxwprintk_task(1, "did hit the barrier.");
4287 +               return 1;
4288 +       }
4289 +       return 0;
4290 +}
4291 +
4292 +static int __dx_permission(const struct inode *inode, int mask)
4293 +{
4294 +       if (dx_barrier(inode))
4295 +               return -EACCES;
4296 +
4297 +       if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4298 +               /* devpts is xid tagged */
4299 +               if (S_ISDIR(inode->i_mode) ||
4300 +                   vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4301 +                       return 0;
4302 +
4303 +               /* just pretend we didn't find anything */
4304 +               return -ENOENT;
4305 +       }
4306 +       else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4307 +               struct proc_dir_entry *de = PDE(inode);
4308 +
4309 +               if (de && !vx_hide_check(0, de->vx_flags))
4310 +                       goto out;
4311 +
4312 +               if ((mask & (MAY_WRITE | MAY_APPEND))) {
4313 +                       struct pid *pid;
4314 +                       struct task_struct *tsk;
4315 +
4316 +                       if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4317 +                           vx_flags(VXF_STATE_SETUP, 0))
4318 +                               return 0;
4319 +
4320 +                       pid = PROC_I(inode)->pid;
4321 +                       if (!pid)
4322 +                               goto out;
4323 +
4324 +                       rcu_read_lock();
4325 +                       tsk = pid_task(pid, PIDTYPE_PID);
4326 +                       vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4327 +                                 tsk, (tsk ? vx_task_xid(tsk) : 0));
4328 +                       if (tsk &&
4329 +                               vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4330 +                               rcu_read_unlock();
4331 +                               return 0;
4332 +                       }
4333 +                       rcu_read_unlock();
4334 +               }
4335 +               else {
4336 +                       /* FIXME: Should we block some entries here? */
4337 +                       return 0;
4338 +               }
4339 +       }
4340 +       else {
4341 +               if (dx_notagcheck(inode->i_sb) ||
4342 +                   dx_check((vxid_t)i_tag_read(inode),
4343 +                       DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4344 +                       return 0;
4345 +       }
4346 +
4347 +out:
4348 +       return -EACCES;
4349 +}
4350 +
4351 +int dx_permission(const struct inode *inode, int mask)
4352 +{
4353 +       int ret = __dx_permission(inode, mask);
4354 +       if (unlikely(ret)) {
4355 +#ifndef        CONFIG_VSERVER_WARN_DEVPTS
4356 +               if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4357 +#endif
4358 +                   vxwprintk_task(1,
4359 +                       "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4360 +                       mask, inode->i_sb->s_id, inode,
4361 +                       i_tag_read(inode), inode->i_ino);
4362 +       }
4363 +       return ret;
4364 +}
4365 +
4366  /*
4367   * This does the basic permission checking
4368   */
4369 @@ -388,10 +481,14 @@ int __inode_permission(struct inode *ino
4370                 /*
4371                  * Nobody gets write access to an immutable file.
4372                  */
4373 -               if (IS_IMMUTABLE(inode))
4374 +               if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4375                         return -EACCES;
4376         }
4377  
4378 +       retval = dx_permission(inode, mask);
4379 +       if (retval)
4380 +               return retval;
4381 +
4382         retval = do_inode_permission(inode, mask);
4383         if (retval)
4384                 return retval;
4385 @@ -1238,7 +1335,8 @@ static void follow_dotdot(struct nameida
4386  
4387                 if (nd->path.dentry == nd->root.dentry &&
4388                     nd->path.mnt == nd->root.mnt) {
4389 -                       break;
4390 +                       /* for sane '/' avoid follow_mount() */
4391 +                       return;
4392                 }
4393                 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4394                         /* rare case of legitimate dget_parent()... */
4395 @@ -1383,6 +1481,9 @@ static int lookup_fast(struct nameidata
4396                                 goto unlazy;
4397                         }
4398                 }
4399 +
4400 +               /* FIXME: check dx permission */
4401 +
4402                 path->mnt = mnt;
4403                 path->dentry = dentry;
4404                 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4405 @@ -1413,6 +1514,8 @@ unlazy:
4406                 }
4407         }
4408  
4409 +       /* FIXME: check dx permission */
4410 +
4411         path->mnt = mnt;
4412         path->dentry = dentry;
4413         err = follow_managed(path, nd->flags);
4414 @@ -2237,7 +2340,7 @@ static int may_delete(struct inode *dir,
4415         if (IS_APPEND(dir))
4416                 return -EPERM;
4417         if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4418 -           IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4419 +               IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4420                 return -EPERM;
4421         if (isdir) {
4422                 if (!S_ISDIR(victim->d_inode->i_mode))
4423 @@ -2317,19 +2420,25 @@ int vfs_create(struct inode *dir, struct
4424                 bool want_excl)
4425  {
4426         int error = may_create(dir, dentry);
4427 -       if (error)
4428 +       if (error) {
4429 +               vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4430                 return error;
4431 +       }
4432  
4433         if (!dir->i_op->create)
4434                 return -EACCES; /* shouldn't it be ENOSYS? */
4435         mode &= S_IALLUGO;
4436         mode |= S_IFREG;
4437         error = security_inode_create(dir, dentry, mode);
4438 -       if (error)
4439 +       if (error) {
4440 +               vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4441                 return error;
4442 +       }
4443         error = dir->i_op->create(dir, dentry, mode, want_excl);
4444         if (!error)
4445                 fsnotify_create(dir, dentry);
4446 +       else
4447 +               vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4448         return error;
4449  }
4450  
4451 @@ -2364,6 +2473,15 @@ static int may_open(struct path *path, i
4452                 break;
4453         }
4454  
4455 +#ifdef CONFIG_VSERVER_COWBL
4456 +       if (IS_COW(inode) &&
4457 +               ((flag & O_ACCMODE) != O_RDONLY)) {
4458 +               if (IS_COW_LINK(inode))
4459 +                       return -EMLINK;
4460 +               inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4461 +               mark_inode_dirty(inode);
4462 +       }
4463 +#endif
4464         error = inode_permission(inode, acc_mode);
4465         if (error)
4466                 return error;
4467 @@ -2866,6 +2984,16 @@ finish_open:
4468         }
4469  finish_open_created:
4470         error = may_open(&nd->path, acc_mode, open_flag);
4471 +#ifdef CONFIG_VSERVER_COWBL
4472 +       if (error == -EMLINK) {
4473 +               struct dentry *dentry;
4474 +               dentry = cow_break_link(name->name);
4475 +               if (IS_ERR(dentry))
4476 +                       error = PTR_ERR(dentry);
4477 +               else
4478 +                       dput(dentry);
4479 +       }
4480 +#endif
4481         if (error)
4482                 goto out;
4483         file->f_path.mnt = nd->path.mnt;
4484 @@ -2930,6 +3058,7 @@ static struct file *path_openat(int dfd,
4485         int opened = 0;
4486         int error;
4487  
4488 +restart:
4489         file = get_empty_filp();
4490         if (IS_ERR(file))
4491                 return file;
4492 @@ -2966,6 +3095,16 @@ static struct file *path_openat(int dfd,
4493                 error = do_last(nd, &path, file, op, &opened, pathname);
4494                 put_link(nd, &link, cookie);
4495         }
4496 +
4497 +#ifdef CONFIG_VSERVER_COWBL
4498 +       if (error == -EMLINK) {
4499 +               if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4500 +                       path_put(&nd->root);
4501 +               if (base)
4502 +                       fput(base);
4503 +               goto restart;
4504 +       }
4505 +#endif
4506  out:
4507         if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4508                 path_put(&nd->root);
4509 @@ -3080,6 +3219,11 @@ struct dentry *kern_path_create(int dfd,
4510                 goto fail;
4511         }
4512         *path = nd.path;
4513 +       vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4514 +               path->dentry, path->dentry->d_name.len,
4515 +               path->dentry->d_name.name, dentry,
4516 +               dentry->d_name.len, dentry->d_name.name,
4517 +               path->dentry->d_inode);
4518         return dentry;
4519  fail:
4520         dput(dentry);
4521 @@ -3574,7 +3718,7 @@ int vfs_link(struct dentry *old_dentry,
4522         /*
4523          * A link to an append-only or immutable file cannot be created.
4524          */
4525 -       if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4526 +       if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4527                 return -EPERM;
4528         if (!dir->i_op->link)
4529                 return -EPERM;
4530 @@ -3978,6 +4122,287 @@ int vfs_follow_link(struct nameidata *nd
4531         return __vfs_follow_link(nd, link);
4532  }
4533  
4534 +
4535 +#ifdef CONFIG_VSERVER_COWBL
4536 +
4537 +static inline
4538 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4539 +{
4540 +       loff_t ppos = 0;
4541 +       loff_t opos = 0;
4542 +
4543 +       return do_splice_direct(in, &ppos, out, &opos, len, 0);
4544 +}
4545 +
4546 +struct dentry *cow_break_link(const char *pathname)
4547 +{
4548 +       int ret, mode, pathlen, redo = 0, drop = 1;
4549 +       struct nameidata old_nd, dir_nd;
4550 +       struct path dir_path, *old_path, *new_path;
4551 +       struct dentry *dir, *old_dentry, *new_dentry = NULL;
4552 +       struct file *old_file;
4553 +       struct file *new_file;
4554 +       char *to, *path, pad='\251';
4555 +       loff_t size;
4556 +
4557 +       vxdprintk(VXD_CBIT(misc, 1),
4558 +               "cow_break_link(" VS_Q("%s") ")", pathname);
4559 +
4560 +       path = kmalloc(PATH_MAX, GFP_KERNEL);
4561 +       ret = -ENOMEM;
4562 +       if (!path)
4563 +               goto out;
4564 +
4565 +       /* old_nd.path will have refs to dentry and mnt */
4566 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4567 +       vxdprintk(VXD_CBIT(misc, 2),
4568 +               "do_path_lookup(old): %d", ret);
4569 +       if (ret < 0)
4570 +               goto out_free_path;
4571 +
4572 +       /* dentry/mnt refs handed over to old_path */
4573 +       old_path = &old_nd.path;
4574 +       /* no explicit reference for old_dentry here */
4575 +       old_dentry = old_path->dentry;
4576 +
4577 +       mode = old_dentry->d_inode->i_mode;
4578 +       to = d_path(old_path, path, PATH_MAX-2);
4579 +       pathlen = strlen(to);
4580 +       vxdprintk(VXD_CBIT(misc, 2),
4581 +               "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4582 +               old_dentry,
4583 +               old_dentry->d_name.len, old_dentry->d_name.name,
4584 +               old_dentry->d_name.len);
4585 +
4586 +       to[pathlen + 1] = 0;
4587 +retry:
4588 +       new_dentry = NULL;
4589 +       to[pathlen] = pad--;
4590 +       ret = -ELOOP;
4591 +       if (pad <= '\240')
4592 +               goto out_rel_old;
4593 +
4594 +       vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4595 +
4596 +       /* dir_nd.path will have refs to dentry and mnt */
4597 +       ret = do_path_lookup(AT_FDCWD, to,
4598 +               LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4599 +       vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4600 +       if (ret < 0)
4601 +               goto retry;
4602 +
4603 +       /* this puppy downs the dir inode mutex if successful.
4604 +          dir_path will hold refs to dentry and mnt and
4605 +          we'll have write access to the mnt */
4606 +       new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4607 +       if (!new_dentry || IS_ERR(new_dentry)) {
4608 +               path_put(&dir_nd.path);
4609 +               vxdprintk(VXD_CBIT(misc, 2),
4610 +                       "kern_path_create(new) failed with %ld",
4611 +                       PTR_ERR(new_dentry));
4612 +               goto retry;
4613 +       }
4614 +       vxdprintk(VXD_CBIT(misc, 2),
4615 +               "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4616 +               new_dentry,
4617 +               new_dentry->d_name.len, new_dentry->d_name.name,
4618 +               new_dentry->d_name.len);
4619 +
4620 +       /* take a reference on new_dentry */
4621 +       dget(new_dentry);
4622 +
4623 +       /* dentry/mnt refs handed over to new_path */
4624 +       new_path = &dir_path;
4625 +
4626 +       /* dentry for old/new dir */
4627 +       dir = dir_nd.path.dentry;
4628 +
4629 +       /* give up reference on dir */
4630 +       dput(new_path->dentry);
4631 +
4632 +       /* new_dentry already has a reference */
4633 +       new_path->dentry = new_dentry;
4634 +
4635 +       ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4636 +       vxdprintk(VXD_CBIT(misc, 2),
4637 +               "vfs_create(new): %d", ret);
4638 +       if (ret == -EEXIST) {
4639 +               path_put(&dir_nd.path);
4640 +               mutex_unlock(&dir->d_inode->i_mutex);
4641 +               mnt_drop_write(new_path->mnt);
4642 +               path_put(new_path);
4643 +               new_dentry = NULL;
4644 +               goto retry;
4645 +       }
4646 +       else if (ret < 0)
4647 +               goto out_unlock_new;
4648 +
4649 +       /* drop out early, ret passes ENOENT */
4650 +       ret = -ENOENT;
4651 +       if ((redo = d_unhashed(old_dentry)))
4652 +               goto out_unlock_new;
4653 +
4654 +       /* doesn't change refs for old_path */
4655 +       old_file = dentry_open(old_path, O_RDONLY, current_cred());
4656 +       vxdprintk(VXD_CBIT(misc, 2),
4657 +               "dentry_open(old): %p", old_file);
4658 +       if (IS_ERR(old_file)) {
4659 +               ret = PTR_ERR(old_file);
4660 +               goto out_unlock_new;
4661 +       }
4662 +
4663 +       /* doesn't change refs for new_path */
4664 +       new_file = dentry_open(new_path, O_WRONLY, current_cred());
4665 +       vxdprintk(VXD_CBIT(misc, 2),
4666 +               "dentry_open(new): %p", new_file);
4667 +       if (IS_ERR(new_file)) {
4668 +               ret = PTR_ERR(new_file);
4669 +               goto out_fput_old;
4670 +       }
4671 +
4672 +       /* unlock the inode mutex from kern_path_create() */
4673 +       mutex_unlock(&dir->d_inode->i_mutex);
4674 +
4675 +       /* drop write access to mnt */
4676 +       mnt_drop_write(new_path->mnt);
4677 +
4678 +       drop = 0;
4679 +
4680 +       size = i_size_read(old_file->f_dentry->d_inode);
4681 +       ret = do_cow_splice(old_file, new_file, size);
4682 +       vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4683 +       if (ret < 0) {
4684 +               goto out_fput_both;
4685 +       } else if (ret < size) {
4686 +               ret = -ENOSPC;
4687 +               goto out_fput_both;
4688 +       } else {
4689 +               struct inode *old_inode = old_dentry->d_inode;
4690 +               struct inode *new_inode = new_dentry->d_inode;
4691 +               struct iattr attr = {
4692 +                       .ia_uid = old_inode->i_uid,
4693 +                       .ia_gid = old_inode->i_gid,
4694 +                       .ia_valid = ATTR_UID | ATTR_GID
4695 +                       };
4696 +
4697 +               setattr_copy(new_inode, &attr);
4698 +               mark_inode_dirty(new_inode);
4699 +       }
4700 +
4701 +       /* lock rename mutex */
4702 +       mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4703 +
4704 +       /* drop out late */
4705 +       ret = -ENOENT;
4706 +       if ((redo = d_unhashed(old_dentry)))
4707 +               goto out_unlock;
4708 +
4709 +       vxdprintk(VXD_CBIT(misc, 2),
4710 +               "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4711 +               new_dentry->d_name.len, new_dentry->d_name.name,
4712 +               new_dentry->d_name.len,
4713 +               old_dentry->d_name.len, old_dentry->d_name.name,
4714 +               old_dentry->d_name.len);
4715 +       ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4716 +               old_dentry->d_parent->d_inode, old_dentry);
4717 +       vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4718 +
4719 +out_unlock:
4720 +       mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4721 +
4722 +out_fput_both:
4723 +       vxdprintk(VXD_CBIT(misc, 3),
4724 +               "fput(new_file=%p[#%ld])", new_file,
4725 +               atomic_long_read(&new_file->f_count));
4726 +       fput(new_file);
4727 +
4728 +out_fput_old:
4729 +       vxdprintk(VXD_CBIT(misc, 3),
4730 +               "fput(old_file=%p[#%ld])", old_file,
4731 +               atomic_long_read(&old_file->f_count));
4732 +       fput(old_file);
4733 +
4734 +out_unlock_new:
4735 +       /* drop references from dir_nd.path */
4736 +       path_put(&dir_nd.path);
4737 +
4738 +       if (drop) {
4739 +               /* unlock the inode mutex from kern_path_create() */
4740 +               mutex_unlock(&dir->d_inode->i_mutex);
4741 +
4742 +               /* drop write access to mnt */
4743 +               mnt_drop_write(new_path->mnt);
4744 +       }
4745 +
4746 +       if (!ret)
4747 +               goto out_redo;
4748 +
4749 +       /* error path cleanup */
4750 +       vfs_unlink(dir->d_inode, new_dentry);
4751 +
4752 +out_redo:
4753 +       if (!redo)
4754 +               goto out_rel_both;
4755 +
4756 +       /* lookup dentry once again
4757 +          old_nd.path will be freed as old_path in out_rel_old */
4758 +       ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4759 +       if (ret)
4760 +               goto out_rel_both;
4761 +
4762 +       /* drop reference on new_dentry */
4763 +       dput(new_dentry);
4764 +       new_dentry = old_path->dentry;
4765 +       dget(new_dentry);
4766 +       vxdprintk(VXD_CBIT(misc, 2),
4767 +               "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4768 +               new_dentry,
4769 +               new_dentry->d_name.len, new_dentry->d_name.name,
4770 +               new_dentry->d_name.len);
4771 +
4772 +out_rel_both:
4773 +       if (new_path)
4774 +               path_put(new_path);
4775 +out_rel_old:
4776 +       path_put(old_path);
4777 +out_free_path:
4778 +       kfree(path);
4779 +out:
4780 +       if (ret) {
4781 +               dput(new_dentry);
4782 +               new_dentry = ERR_PTR(ret);
4783 +       }
4784 +       vxdprintk(VXD_CBIT(misc, 3),
4785 +               "cow_break_link returning with %p", new_dentry);
4786 +       return new_dentry;
4787 +}
4788 +
4789 +#endif
4790 +
4791 +int    vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4792 +{
4793 +       struct path path;
4794 +       struct vfsmount *vmnt;
4795 +       char *pstr, *root;
4796 +       int length = 0;
4797 +
4798 +       pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4799 +       if (!pstr)
4800 +               return 0;
4801 +
4802 +       vmnt = &ns->root->mnt;
4803 +       path.mnt = vmnt;
4804 +       path.dentry = vmnt->mnt_root;
4805 +       root = d_path(&path, pstr, PATH_MAX - 2);
4806 +       length = sprintf(buffer + length,
4807 +               "Namespace:\t%p [#%u]\n"
4808 +               "RootPath:\t%s\n",
4809 +               ns, atomic_read(&ns->count),
4810 +               root);
4811 +       kfree(pstr);
4812 +       return length;
4813 +}
4814 +
4815  /* get the link contents into pagecache */
4816  static char *page_getlink(struct dentry * dentry, struct page **ppage)
4817  {
4818 @@ -4101,3 +4526,4 @@ EXPORT_SYMBOL(vfs_symlink);
4819  EXPORT_SYMBOL(vfs_unlink);
4820  EXPORT_SYMBOL(dentry_unhash);
4821  EXPORT_SYMBOL(generic_readlink);
4822 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4823 diff -NurpP --minimal linux-3.10.40/fs/namespace.c linux-3.10.40-vs2.3.6.8/fs/namespace.c
4824 --- linux-3.10.40/fs/namespace.c        2014-05-20 04:09:39.000000000 +0000
4825 +++ linux-3.10.40-vs2.3.6.8/fs/namespace.c      2013-11-13 17:17:16.000000000 +0000
4826 @@ -23,6 +23,11 @@
4827  #include <linux/uaccess.h>
4828  #include <linux/proc_ns.h>
4829  #include <linux/magic.h>
4830 +#include <linux/vs_base.h>
4831 +#include <linux/vs_context.h>
4832 +#include <linux/vs_tag.h>
4833 +#include <linux/vserver/space.h>
4834 +#include <linux/vserver/global.h>
4835  #include "pnode.h"
4836  #include "internal.h"
4837  
4838 @@ -780,6 +785,10 @@ vfs_kern_mount(struct file_system_type *
4839         if (!type)
4840                 return ERR_PTR(-ENODEV);
4841  
4842 +       if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4843 +               !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4844 +               return ERR_PTR(-EPERM);
4845 +
4846         mnt = alloc_vfsmnt(name);
4847         if (!mnt)
4848                 return ERR_PTR(-ENOMEM);
4849 @@ -836,6 +845,7 @@ static struct mount *clone_mnt(struct mo
4850         mnt->mnt.mnt_root = dget(root);
4851         mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4852         mnt->mnt_parent = mnt;
4853 +               mnt->mnt_tag = old->mnt_tag;
4854         br_write_lock(&vfsmount_lock);
4855         list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4856         br_write_unlock(&vfsmount_lock);
4857 @@ -1291,7 +1301,8 @@ static int do_umount(struct mount *mnt,
4858   */
4859  static inline bool may_mount(void)
4860  {
4861 -       return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4862 +       return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4863 +               CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4864  }
4865  
4866  /*
4867 @@ -1685,6 +1696,7 @@ static int do_change_type(struct path *p
4868                 if (err)
4869                         goto out_unlock;
4870         }
4871 +       // mnt->mnt_flags = mnt_flags;
4872  
4873         br_write_lock(&vfsmount_lock);
4874         for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4875 @@ -1700,12 +1712,14 @@ static int do_change_type(struct path *p
4876   * do loopback mount.
4877   */
4878  static int do_loopback(struct path *path, const char *old_name,
4879 -                               int recurse)
4880 +       vtag_t tag, unsigned long flags, int mnt_flags)
4881  {
4882         struct path old_path;
4883         struct mount *mnt = NULL, *old, *parent;
4884         struct mountpoint *mp;
4885 +       int recurse = flags & MS_REC;
4886         int err;
4887 +
4888         if (!old_name || !*old_name)
4889                 return -EINVAL;
4890         err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4891 @@ -1780,7 +1794,7 @@ static int change_mount_flags(struct vfs
4892   * on it - tough luck.
4893   */
4894  static int do_remount(struct path *path, int flags, int mnt_flags,
4895 -                     void *data)
4896 +       void *data, vxid_t xid)
4897  {
4898         int err;
4899         struct super_block *sb = path->mnt->mnt_sb;
4900 @@ -2264,6 +2278,7 @@ long do_mount(const char *dev_name, cons
4901         struct path path;
4902         int retval = 0;
4903         int mnt_flags = 0;
4904 +       vtag_t tag = 0;
4905  
4906         /* Discard magic */
4907         if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4908 @@ -2293,6 +2308,12 @@ long do_mount(const char *dev_name, cons
4909         if (!(flags & MS_NOATIME))
4910                 mnt_flags |= MNT_RELATIME;
4911  
4912 +       if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4913 +               /* FIXME: bind and re-mounts get the tag flag? */
4914 +               if (flags & (MS_BIND|MS_REMOUNT))
4915 +                       flags |= MS_TAGID;
4916 +       }
4917 +
4918         /* Separate the per-mountpoint flags */
4919         if (flags & MS_NOSUID)
4920                 mnt_flags |= MNT_NOSUID;
4921 @@ -2309,15 +2330,17 @@ long do_mount(const char *dev_name, cons
4922         if (flags & MS_RDONLY)
4923                 mnt_flags |= MNT_READONLY;
4924  
4925 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4926 +               mnt_flags |= MNT_NODEV;
4927         flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4928                    MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4929                    MS_STRICTATIME);
4930  
4931         if (flags & MS_REMOUNT)
4932                 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4933 -                                   data_page);
4934 +                                   data_page, tag);
4935         else if (flags & MS_BIND)
4936 -               retval = do_loopback(&path, dev_name, flags & MS_REC);
4937 +               retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4938         else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4939                 retval = do_change_type(&path, flags);
4940         else if (flags & MS_MOVE)
4941 @@ -2426,6 +2449,7 @@ static struct mnt_namespace *dup_mnt_ns(
4942                 q = next_mnt(q, new);
4943         }
4944         namespace_unlock();
4945 +       atomic_inc(&vs_global_mnt_ns);
4946  
4947         if (rootmnt)
4948                 mntput(rootmnt);
4949 @@ -2624,9 +2648,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4950         new_mnt = real_mount(new.mnt);
4951         root_mnt = real_mount(root.mnt);
4952         old_mnt = real_mount(old.mnt);
4953 -       if (IS_MNT_SHARED(old_mnt) ||
4954 +       if ((IS_MNT_SHARED(old_mnt) ||
4955                 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4956 -               IS_MNT_SHARED(root_mnt->mnt_parent))
4957 +               IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4958 +               !vx_flags(VXF_STATE_SETUP, 0))
4959                 goto out4;
4960         if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4961                 goto out4;
4962 @@ -2752,6 +2777,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4963         umount_tree(ns->root, 0);
4964         br_write_unlock(&vfsmount_lock);
4965         namespace_unlock();
4966 +       atomic_dec(&vs_global_mnt_ns);
4967         free_mnt_ns(ns);
4968  }
4969  
4970 diff -NurpP --minimal linux-3.10.40/fs/nfs/client.c linux-3.10.40-vs2.3.6.8/fs/nfs/client.c
4971 --- linux-3.10.40/fs/nfs/client.c       2013-07-14 17:01:28.000000000 +0000
4972 +++ linux-3.10.40-vs2.3.6.8/fs/nfs/client.c     2013-08-22 20:29:59.000000000 +0000
4973 @@ -684,6 +684,9 @@ int nfs_init_server_rpcclient(struct nfs
4974         if (server->flags & NFS_MOUNT_SOFT)
4975                 server->client->cl_softrtry = 1;
4976  
4977 +       server->client->cl_tag = 0;
4978 +       if (server->flags & NFS_MOUNT_TAGGED)
4979 +               server->client->cl_tag = 1;
4980         return 0;
4981  }
4982  EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4983 @@ -863,6 +866,10 @@ static void nfs_server_set_fsinfo(struct
4984                 server->acdirmin = server->acdirmax = 0;
4985         }
4986  
4987 +       /* FIXME: needs fsinfo
4988 +       if (server->flags & NFS_MOUNT_TAGGED)
4989 +               sb->s_flags |= MS_TAGGED;       */
4990 +
4991         server->maxfilesize = fsinfo->maxfilesize;
4992  
4993         server->time_delta = fsinfo->time_delta;
4994 diff -NurpP --minimal linux-3.10.40/fs/nfs/dir.c linux-3.10.40-vs2.3.6.8/fs/nfs/dir.c
4995 --- linux-3.10.40/fs/nfs/dir.c  2013-07-14 17:01:28.000000000 +0000
4996 +++ linux-3.10.40-vs2.3.6.8/fs/nfs/dir.c        2013-08-22 20:29:59.000000000 +0000
4997 @@ -36,6 +36,7 @@
4998  #include <linux/sched.h>
4999  #include <linux/kmemleak.h>
5000  #include <linux/xattr.h>
5001 +#include <linux/vs_tag.h>
5002  
5003  #include "delegation.h"
5004  #include "iostat.h"
5005 @@ -1300,6 +1301,7 @@ struct dentry *nfs_lookup(struct inode *
5006         /* Success: notify readdir to use READDIRPLUS */
5007         nfs_advise_use_readdirplus(dir);
5008  
5009 +       dx_propagate_tag(nd, inode);
5010  no_entry:
5011         res = d_materialise_unique(dentry, inode);
5012         if (res != NULL) {
5013 diff -NurpP --minimal linux-3.10.40/fs/nfs/inode.c linux-3.10.40-vs2.3.6.8/fs/nfs/inode.c
5014 --- linux-3.10.40/fs/nfs/inode.c        2013-07-14 17:01:28.000000000 +0000
5015 +++ linux-3.10.40-vs2.3.6.8/fs/nfs/inode.c      2013-08-22 20:29:59.000000000 +0000
5016 @@ -39,6 +39,7 @@
5017  #include <linux/compat.h>
5018  #include <linux/freezer.h>
5019  #include <linux/crc32.h>
5020 +#include <linux/vs_tag.h>
5021  
5022  #include <asm/uaccess.h>
5023  
5024 @@ -290,6 +291,8 @@ nfs_fhget(struct super_block *sb, struct
5025         if (inode->i_state & I_NEW) {
5026                 struct nfs_inode *nfsi = NFS_I(inode);
5027                 unsigned long now = jiffies;
5028 +               kuid_t kuid;
5029 +               kgid_t kgid;
5030  
5031                 /* We set i_ino for the few things that still rely on it,
5032                  * such as stat(2) */
5033 @@ -334,8 +337,8 @@ nfs_fhget(struct super_block *sb, struct
5034                 inode->i_version = 0;
5035                 inode->i_size = 0;
5036                 clear_nlink(inode);
5037 -               inode->i_uid = make_kuid(&init_user_ns, -2);
5038 -               inode->i_gid = make_kgid(&init_user_ns, -2);
5039 +               kuid = make_kuid(&init_user_ns, -2);
5040 +               kgid = make_kgid(&init_user_ns, -2);
5041                 inode->i_blocks = 0;
5042                 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5043                 nfsi->write_io = 0;
5044 @@ -369,11 +372,11 @@ nfs_fhget(struct super_block *sb, struct
5045                 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5046                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5047                 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5048 -                       inode->i_uid = fattr->uid;
5049 +                       kuid = fattr->uid;
5050                 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5051                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5052                 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5053 -                       inode->i_gid = fattr->gid;
5054 +                       kgid = fattr->gid;
5055                 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5056                         nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5057                 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5058 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5059                          */
5060                         inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5061                 }
5062 +               inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5063 +               inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5064 +               inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
5065 +                               /* maybe fattr->xid someday */
5066 +
5067                 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5068                 nfsi->attrtimeo_timestamp = now;
5069                 nfsi->access_cache = RB_ROOT;
5070 @@ -505,6 +513,8 @@ void nfs_setattr_update_inode(struct ino
5071                         inode->i_uid = attr->ia_uid;
5072                 if ((attr->ia_valid & ATTR_GID) != 0)
5073                         inode->i_gid = attr->ia_gid;
5074 +               if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5075 +                       inode->i_tag = attr->ia_tag;
5076                 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5077                 spin_unlock(&inode->i_lock);
5078         }
5079 @@ -982,7 +992,9 @@ static int nfs_check_inode_attributes(st
5080         struct nfs_inode *nfsi = NFS_I(inode);
5081         loff_t cur_size, new_isize;
5082         unsigned long invalid = 0;
5083 -
5084 +       kuid_t kuid;
5085 +       kgid_t kgid;
5086 +       ktag_t ktag;
5087  
5088         if (nfs_have_delegated_attributes(inode))
5089                 return 0;
5090 @@ -1007,13 +1019,18 @@ static int nfs_check_inode_attributes(st
5091                         invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5092         }
5093  
5094 +       kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
5095 +       kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
5096 +       ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
5097 +
5098         /* Have any file permissions changed? */
5099         if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5100                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5101 -       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5102 +       if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5103                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5104 -       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5105 +       if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5106                 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5107 +               /* maybe check for tag too? */
5108  
5109         /* Has the link count changed? */
5110         if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5111 @@ -1319,6 +1336,9 @@ static int nfs_update_inode(struct inode
5112         unsigned long invalid = 0;
5113         unsigned long now = jiffies;
5114         unsigned long save_cache_validity;
5115 +       kuid_t kuid;
5116 +       kgid_t kgid;
5117 +       ktag_t ktag;
5118  
5119         dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5120                         __func__, inode->i_sb->s_id, inode->i_ino,
5121 @@ -1420,6 +1440,9 @@ static int nfs_update_inode(struct inode
5122                                 | NFS_INO_REVAL_PAGECACHE
5123                                 | NFS_INO_REVAL_FORCED);
5124  
5125 +       kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5126 +       kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5127 +       ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
5128  
5129         if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5130                 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5131 @@ -1462,6 +1485,10 @@ static int nfs_update_inode(struct inode
5132                                 | NFS_INO_INVALID_ACL
5133                                 | NFS_INO_REVAL_FORCED);
5134  
5135 +       inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5136 +       inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5137 +       inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
5138 +
5139         if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5140                 if (inode->i_nlink != fattr->nlink) {
5141                         invalid |= NFS_INO_INVALID_ATTR;
5142 diff -NurpP --minimal linux-3.10.40/fs/nfs/nfs3xdr.c linux-3.10.40-vs2.3.6.8/fs/nfs/nfs3xdr.c
5143 --- linux-3.10.40/fs/nfs/nfs3xdr.c      2013-05-31 13:45:24.000000000 +0000
5144 +++ linux-3.10.40-vs2.3.6.8/fs/nfs/nfs3xdr.c    2013-08-22 20:29:59.000000000 +0000
5145 @@ -20,6 +20,7 @@
5146  #include <linux/nfs3.h>
5147  #include <linux/nfs_fs.h>
5148  #include <linux/nfsacl.h>
5149 +#include <linux/vs_tag.h>
5150  #include "internal.h"
5151  
5152  #define NFSDBG_FACILITY                NFSDBG_XDR
5153 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5154   *             set_mtime       mtime;
5155   *     };
5156   */
5157 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5158 +static void encode_sattr3(struct xdr_stream *xdr,
5159 +       const struct iattr *attr, int tag)
5160  {
5161         u32 nbytes;
5162         __be32 *p;
5163 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5164         } else
5165                 *p++ = xdr_zero;
5166  
5167 -       if (attr->ia_valid & ATTR_UID) {
5168 +       if (attr->ia_valid & ATTR_UID ||
5169 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5170                 *p++ = xdr_one;
5171 -               *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5172 +               *p++ = cpu_to_be32(from_kuid(&init_user_ns,
5173 +                       TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
5174         } else
5175                 *p++ = xdr_zero;
5176  
5177 -       if (attr->ia_valid & ATTR_GID) {
5178 +       if (attr->ia_valid & ATTR_GID ||
5179 +               (tag && (attr->ia_valid & ATTR_TAG))) {
5180                 *p++ = xdr_one;
5181 -               *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5182 +               *p++ = cpu_to_be32(from_kgid(&init_user_ns,
5183 +                       TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
5184         } else
5185                 *p++ = xdr_zero;
5186  
5187 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5188                                       const struct nfs3_sattrargs *args)
5189  {
5190         encode_nfs_fh3(xdr, args->fh);
5191 -       encode_sattr3(xdr, args->sattr);
5192 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5193         encode_sattrguard3(xdr, args);
5194  }
5195  
5196 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5197   *     };
5198   */
5199  static void encode_createhow3(struct xdr_stream *xdr,
5200 -                             const struct nfs3_createargs *args)
5201 +       const struct nfs3_createargs *args, int tag)
5202  {
5203         encode_uint32(xdr, args->createmode);
5204         switch (args->createmode) {
5205         case NFS3_CREATE_UNCHECKED:
5206         case NFS3_CREATE_GUARDED:
5207 -               encode_sattr3(xdr, args->sattr);
5208 +               encode_sattr3(xdr, args->sattr, tag);
5209                 break;
5210         case NFS3_CREATE_EXCLUSIVE:
5211                 encode_createverf3(xdr, args->verifier);
5212 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5213                                      const struct nfs3_createargs *args)
5214  {
5215         encode_diropargs3(xdr, args->fh, args->name, args->len);
5216 -       encode_createhow3(xdr, args);
5217 +       encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5218  }
5219  
5220  /*
5221 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5222                                     const struct nfs3_mkdirargs *args)
5223  {
5224         encode_diropargs3(xdr, args->fh, args->name, args->len);
5225 -       encode_sattr3(xdr, args->sattr);
5226 +       encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5227  }
5228  
5229  /*
5230 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5231   *     };
5232   */
5233  static void encode_symlinkdata3(struct xdr_stream *xdr,
5234 -                               const struct nfs3_symlinkargs *args)
5235 +       const struct nfs3_symlinkargs *args, int tag)
5236  {
5237 -       encode_sattr3(xdr, args->sattr);
5238 +       encode_sattr3(xdr, args->sattr, tag);
5239         encode_nfspath3(xdr, args->pages, args->pathlen);
5240  }
5241  
5242 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5243                                       const struct nfs3_symlinkargs *args)
5244  {
5245         encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5246 -       encode_symlinkdata3(xdr, args);
5247 +       encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5248  }
5249  
5250  /*
5251 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5252   *     };
5253   */
5254  static void encode_devicedata3(struct xdr_stream *xdr,
5255 -                              const struct nfs3_mknodargs *args)
5256 +       const struct nfs3_mknodargs *args, int tag)
5257  {
5258 -       encode_sattr3(xdr, args->sattr);
5259 +       encode_sattr3(xdr, args->sattr, tag);
5260         encode_specdata3(xdr, args->rdev);
5261  }
5262  
5263  static void encode_mknoddata3(struct xdr_stream *xdr,
5264 -                             const struct nfs3_mknodargs *args)
5265 +       const struct nfs3_mknodargs *args, int tag)
5266  {
5267         encode_ftype3(xdr, args->type);
5268         switch (args->type) {
5269         case NF3CHR:
5270         case NF3BLK:
5271 -               encode_devicedata3(xdr, args);
5272 +               encode_devicedata3(xdr, args, tag);
5273                 break;
5274         case NF3SOCK:
5275         case NF3FIFO:
5276 -               encode_sattr3(xdr, args->sattr);
5277 +               encode_sattr3(xdr, args->sattr, tag);
5278                 break;
5279         case NF3REG:
5280         case NF3DIR:
5281 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5282                                     const struct nfs3_mknodargs *args)
5283  {
5284         encode_diropargs3(xdr, args->fh, args->name, args->len);
5285 -       encode_mknoddata3(xdr, args);
5286 +       encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5287  }
5288  
5289  /*
5290 diff -NurpP --minimal linux-3.10.40/fs/nfs/super.c linux-3.10.40-vs2.3.6.8/fs/nfs/super.c
5291 --- linux-3.10.40/fs/nfs/super.c        2013-07-14 17:01:28.000000000 +0000
5292 +++ linux-3.10.40-vs2.3.6.8/fs/nfs/super.c      2013-08-22 20:29:59.000000000 +0000
5293 @@ -55,6 +55,7 @@
5294  #include <linux/parser.h>
5295  #include <linux/nsproxy.h>
5296  #include <linux/rcupdate.h>
5297 +#include <linux/vs_tag.h>
5298  
5299  #include <asm/uaccess.h>
5300  
5301 @@ -103,6 +104,7 @@ enum {
5302         Opt_mountport,
5303         Opt_mountvers,
5304         Opt_minorversion,
5305 +       Opt_tagid,
5306  
5307         /* Mount options that take string arguments */
5308         Opt_nfsvers,
5309 @@ -115,6 +117,9 @@ enum {
5310         /* Special mount options */
5311         Opt_userspace, Opt_deprecated, Opt_sloppy,
5312  
5313 +       /* Linux-VServer tagging options */
5314 +       Opt_tag, Opt_notag,
5315 +
5316         Opt_err
5317  };
5318  
5319 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5320         { Opt_fscache_uniq, "fsc=%s" },
5321         { Opt_local_lock, "local_lock=%s" },
5322  
5323 +       { Opt_tag, "tag" },
5324 +       { Opt_notag, "notag" },
5325 +       { Opt_tagid, "tagid=%u" },
5326 +
5327         /* The following needs to be listed after all other options */
5328         { Opt_nfsvers, "v%s" },
5329  
5330 @@ -635,6 +644,7 @@ static void nfs_show_mount_options(struc
5331                 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5332                 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5333                 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5334 +               { NFS_MOUNT_TAGGED, ",tag", "" },
5335                 { 0, NULL, NULL }
5336         };
5337         const struct proc_nfs_info *nfs_infop;
5338 @@ -1261,6 +1271,14 @@ static int nfs_parse_mount_options(char
5339                 case Opt_nomigration:
5340                         mnt->options &= NFS_OPTION_MIGRATION;
5341                         break;
5342 +#ifndef CONFIG_TAGGING_NONE
5343 +               case Opt_tag:
5344 +                       mnt->flags |= NFS_MOUNT_TAGGED;
5345 +                       break;
5346 +               case Opt_notag:
5347 +                       mnt->flags &= ~NFS_MOUNT_TAGGED;
5348 +                       break;
5349 +#endif
5350  
5351                 /*
5352                  * options that take numeric values
5353 @@ -1347,6 +1365,12 @@ static int nfs_parse_mount_options(char
5354                                 goto out_invalid_value;
5355                         mnt->minorversion = option;
5356                         break;
5357 +#ifdef CONFIG_PROPAGATE
5358 +               case Opt_tagid:
5359 +                       /* use args[0] */
5360 +                       nfs_data.flags |= NFS_MOUNT_TAGGED;
5361 +                       break;
5362 +#endif
5363  
5364                 /*
5365                  * options that take text values
5366 diff -NurpP --minimal linux-3.10.40/fs/nfsd/auth.c linux-3.10.40-vs2.3.6.8/fs/nfsd/auth.c
5367 --- linux-3.10.40/fs/nfsd/auth.c        2013-05-31 13:45:24.000000000 +0000
5368 +++ linux-3.10.40-vs2.3.6.8/fs/nfsd/auth.c      2013-08-22 20:29:59.000000000 +0000
5369 @@ -2,6 +2,7 @@
5370  
5371  #include <linux/sched.h>
5372  #include <linux/user_namespace.h>
5373 +#include <linux/vs_tag.h>
5374  #include "nfsd.h"
5375  #include "auth.h"
5376  
5377 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5378  
5379         new->fsuid = rqstp->rq_cred.cr_uid;
5380         new->fsgid = rqstp->rq_cred.cr_gid;
5381 +       /* FIXME: this desperately needs a tag :)
5382 +       new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5383 +                       */
5384  
5385         rqgi = rqstp->rq_cred.cr_group_info;
5386  
5387 diff -NurpP --minimal linux-3.10.40/fs/nfsd/nfs3xdr.c linux-3.10.40-vs2.3.6.8/fs/nfsd/nfs3xdr.c
5388 --- linux-3.10.40/fs/nfsd/nfs3xdr.c     2013-05-31 13:45:24.000000000 +0000
5389 +++ linux-3.10.40-vs2.3.6.8/fs/nfsd/nfs3xdr.c   2013-08-22 20:29:59.000000000 +0000
5390 @@ -8,6 +8,7 @@
5391  
5392  #include <linux/namei.h>
5393  #include <linux/sunrpc/svc_xprt.h>
5394 +#include <linux/vs_tag.h>
5395  #include "xdr3.h"
5396  #include "auth.h"
5397  #include "netns.h"
5398 @@ -98,6 +99,8 @@ static __be32 *
5399  decode_sattr3(__be32 *p, struct iattr *iap)
5400  {
5401         u32     tmp;
5402 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5403 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5404  
5405         iap->ia_valid = 0;
5406  
5407 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5408                 iap->ia_mode = ntohl(*p++);
5409         }
5410         if (*p++) {
5411 -               iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5412 +               kuid = make_kuid(&init_user_ns, ntohl(*p++));
5413                 if (uid_valid(iap->ia_uid))
5414                         iap->ia_valid |= ATTR_UID;
5415         }
5416         if (*p++) {
5417 -               iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5418 +               kgid = make_kgid(&init_user_ns, ntohl(*p++));
5419                 if (gid_valid(iap->ia_gid))
5420                         iap->ia_valid |= ATTR_GID;
5421         }
5422 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5423 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5424 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5425         if (*p++) {
5426                 u64     newsize;
5427  
5428 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5429         *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5430         *p++ = htonl((u32) stat->mode);
5431         *p++ = htonl((u32) stat->nlink);
5432 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5433 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5434 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5435 +               TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5436 +               stat->uid, stat->tag)));
5437 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5438 +               TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5439 +               stat->gid, stat->tag)));
5440         if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5441                 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5442         } else {
5443 diff -NurpP --minimal linux-3.10.40/fs/nfsd/nfs4xdr.c linux-3.10.40-vs2.3.6.8/fs/nfsd/nfs4xdr.c
5444 --- linux-3.10.40/fs/nfsd/nfs4xdr.c     2014-05-20 04:09:39.000000000 +0000
5445 +++ linux-3.10.40-vs2.3.6.8/fs/nfsd/nfs4xdr.c   2014-05-20 04:31:55.000000000 +0000
5446 @@ -46,6 +46,7 @@
5447  #include <linux/utsname.h>
5448  #include <linux/pagemap.h>
5449  #include <linux/sunrpc/svcauth_gss.h>
5450 +#include <linux/vs_tag.h>
5451  
5452  #include "idmap.h"
5453  #include "acl.h"
5454 @@ -2320,14 +2321,18 @@ out_acl:
5455                 WRITE32(stat.nlink);
5456         }
5457         if (bmval1 & FATTR4_WORD1_OWNER) {
5458 -               status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5459 +               status = nfsd4_encode_user(rqstp,
5460 +                       TAGINO_KUID(DX_TAG(dentry->d_inode),
5461 +                       stat.uid, stat.tag), &p, &buflen);
5462                 if (status == nfserr_resource)
5463                         goto out_resource;
5464                 if (status)
5465                         goto out;
5466         }
5467         if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5468 -               status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5469 +               status = nfsd4_encode_group(rqstp,
5470 +                       TAGINO_KGID(DX_TAG(dentry->d_inode),
5471 +                       stat.gid, stat.tag), &p, &buflen);
5472                 if (status == nfserr_resource)
5473                         goto out_resource;
5474                 if (status)
5475 diff -NurpP --minimal linux-3.10.40/fs/nfsd/nfsxdr.c linux-3.10.40-vs2.3.6.8/fs/nfsd/nfsxdr.c
5476 --- linux-3.10.40/fs/nfsd/nfsxdr.c      2013-05-31 13:45:24.000000000 +0000
5477 +++ linux-3.10.40-vs2.3.6.8/fs/nfsd/nfsxdr.c    2013-08-22 20:29:59.000000000 +0000
5478 @@ -7,6 +7,7 @@
5479  #include "vfs.h"
5480  #include "xdr.h"
5481  #include "auth.h"
5482 +#include <linux/vs_tag.h>
5483  
5484  #define NFSDDBG_FACILITY               NFSDDBG_XDR
5485  
5486 @@ -89,6 +90,8 @@ static __be32 *
5487  decode_sattr(__be32 *p, struct iattr *iap)
5488  {
5489         u32     tmp, tmp1;
5490 +       kuid_t  kuid = GLOBAL_ROOT_UID;
5491 +       kgid_t  kgid = GLOBAL_ROOT_GID;
5492  
5493         iap->ia_valid = 0;
5494  
5495 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5496                 iap->ia_mode = tmp;
5497         }
5498         if ((tmp = ntohl(*p++)) != (u32)-1) {
5499 -               iap->ia_uid = make_kuid(&init_user_ns, tmp);
5500 +               kuid = make_kuid(&init_user_ns, tmp);
5501                 if (uid_valid(iap->ia_uid))
5502                         iap->ia_valid |= ATTR_UID;
5503         }
5504         if ((tmp = ntohl(*p++)) != (u32)-1) {
5505 -               iap->ia_gid = make_kgid(&init_user_ns, tmp);
5506 +               kgid = make_kgid(&init_user_ns, tmp);
5507                 if (gid_valid(iap->ia_gid))
5508                         iap->ia_valid |= ATTR_GID;
5509         }
5510 +       iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5511 +       iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5512 +       iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5513         if ((tmp = ntohl(*p++)) != (u32)-1) {
5514                 iap->ia_valid |= ATTR_SIZE;
5515                 iap->ia_size = tmp;
5516 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5517         *p++ = htonl(nfs_ftypes[type >> 12]);
5518         *p++ = htonl((u32) stat->mode);
5519         *p++ = htonl((u32) stat->nlink);
5520 -       *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5521 -       *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5522 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
5523 +               TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5524 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
5525 +               TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5526  
5527         if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5528                 *p++ = htonl(NFS_MAXPATHLEN);
5529 diff -NurpP --minimal linux-3.10.40/fs/ocfs2/dlmglue.c linux-3.10.40-vs2.3.6.8/fs/ocfs2/dlmglue.c
5530 --- linux-3.10.40/fs/ocfs2/dlmglue.c    2013-07-14 17:01:29.000000000 +0000
5531 +++ linux-3.10.40-vs2.3.6.8/fs/ocfs2/dlmglue.c  2013-08-22 20:29:59.000000000 +0000
5532 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5533         lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5534         lvb->lvb_iuid      = cpu_to_be32(i_uid_read(inode));
5535         lvb->lvb_igid      = cpu_to_be32(i_gid_read(inode));
5536 +       lvb->lvb_itag      = cpu_to_be16(i_tag_read(inode));
5537         lvb->lvb_imode     = cpu_to_be16(inode->i_mode);
5538         lvb->lvb_inlink    = cpu_to_be16(inode->i_nlink);
5539         lvb->lvb_iatime_packed  =
5540 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5541  
5542         i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5543         i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5544 +       i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5545         inode->i_mode    = be16_to_cpu(lvb->lvb_imode);
5546         set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5547         ocfs2_unpack_timespec(&inode->i_atime,
5548 diff -NurpP --minimal linux-3.10.40/fs/ocfs2/dlmglue.h linux-3.10.40-vs2.3.6.8/fs/ocfs2/dlmglue.h
5549 --- linux-3.10.40/fs/ocfs2/dlmglue.h    2012-12-11 03:30:57.000000000 +0000
5550 +++ linux-3.10.40-vs2.3.6.8/fs/ocfs2/dlmglue.h  2013-08-22 20:29:59.000000000 +0000
5551 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5552         __be16       lvb_inlink;
5553         __be32       lvb_iattr;
5554         __be32       lvb_igeneration;
5555 -       __be32       lvb_reserved2;
5556 +       __be16       lvb_itag;
5557 +       __be16       lvb_reserved2;
5558  };
5559  
5560  #define OCFS2_QINFO_LVB_VERSION 1
5561 diff -NurpP --minimal linux-3.10.40/fs/ocfs2/file.c linux-3.10.40-vs2.3.6.8/fs/ocfs2/file.c
5562 --- linux-3.10.40/fs/ocfs2/file.c       2014-05-20 04:09:39.000000000 +0000
5563 +++ linux-3.10.40-vs2.3.6.8/fs/ocfs2/file.c     2014-04-22 03:48:11.000000000 +0000
5564 @@ -1124,7 +1124,7 @@ int ocfs2_setattr(struct dentry *dentry,
5565                 attr->ia_valid &= ~ATTR_SIZE;
5566  
5567  #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5568 -                          | ATTR_GID | ATTR_UID | ATTR_MODE)
5569 +                          | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5570         if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5571                 return 0;
5572  
5573 diff -NurpP --minimal linux-3.10.40/fs/ocfs2/inode.c linux-3.10.40-vs2.3.6.8/fs/ocfs2/inode.c
5574 --- linux-3.10.40/fs/ocfs2/inode.c      2013-05-31 13:45:24.000000000 +0000
5575 +++ linux-3.10.40-vs2.3.6.8/fs/ocfs2/inode.c    2013-08-22 20:29:59.000000000 +0000
5576 @@ -28,6 +28,7 @@
5577  #include <linux/highmem.h>
5578  #include <linux/pagemap.h>
5579  #include <linux/quotaops.h>
5580 +#include <linux/vs_tag.h>
5581  
5582  #include <asm/byteorder.h>
5583  
5584 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5585  {
5586         unsigned int flags = OCFS2_I(inode)->ip_attr;
5587  
5588 -       inode->i_flags &= ~(S_IMMUTABLE |
5589 +       inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5590                 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5591  
5592         if (flags & OCFS2_IMMUTABLE_FL)
5593                 inode->i_flags |= S_IMMUTABLE;
5594 +       if (flags & OCFS2_IXUNLINK_FL)
5595 +               inode->i_flags |= S_IXUNLINK;
5596  
5597         if (flags & OCFS2_SYNC_FL)
5598                 inode->i_flags |= S_SYNC;
5599 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5600                 inode->i_flags |= S_NOATIME;
5601         if (flags & OCFS2_DIRSYNC_FL)
5602                 inode->i_flags |= S_DIRSYNC;
5603 +
5604 +       inode->i_vflags &= ~(V_BARRIER | V_COW);
5605 +
5606 +       if (flags & OCFS2_BARRIER_FL)
5607 +               inode->i_vflags |= V_BARRIER;
5608 +       if (flags & OCFS2_COW_FL)
5609 +               inode->i_vflags |= V_COW;
5610  }
5611  
5612  /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5613  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5614  {
5615         unsigned int flags = oi->vfs_inode.i_flags;
5616 +       unsigned int vflags = oi->vfs_inode.i_vflags;
5617 +
5618 +       oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5619 +                       OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5620 +                       OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5621 +                       OCFS2_BARRIER_FL | OCFS2_COW_FL);
5622 +
5623 +       if (flags & S_IMMUTABLE)
5624 +               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5625 +       if (flags & S_IXUNLINK)
5626 +               oi->ip_attr |= OCFS2_IXUNLINK_FL;
5627  
5628 -       oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5629 -                       OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5630         if (flags & S_SYNC)
5631                 oi->ip_attr |= OCFS2_SYNC_FL;
5632         if (flags & S_APPEND)
5633                 oi->ip_attr |= OCFS2_APPEND_FL;
5634 -       if (flags & S_IMMUTABLE)
5635 -               oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5636         if (flags & S_NOATIME)
5637                 oi->ip_attr |= OCFS2_NOATIME_FL;
5638         if (flags & S_DIRSYNC)
5639                 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5640 +
5641 +       if (vflags & V_BARRIER)
5642 +               oi->ip_attr |= OCFS2_BARRIER_FL;
5643 +       if (vflags & V_COW)
5644 +               oi->ip_attr |= OCFS2_COW_FL;
5645  }
5646  
5647  struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5648 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5649         struct super_block *sb;
5650         struct ocfs2_super *osb;
5651         int use_plocks = 1;
5652 +       uid_t uid;
5653 +       gid_t gid;
5654  
5655         sb = inode->i_sb;
5656         osb = OCFS2_SB(sb);
5657 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5658         inode->i_generation = le32_to_cpu(fe->i_generation);
5659         inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5660         inode->i_mode = le16_to_cpu(fe->i_mode);
5661 -       i_uid_write(inode, le32_to_cpu(fe->i_uid));
5662 -       i_gid_write(inode, le32_to_cpu(fe->i_gid));
5663 +       uid = le32_to_cpu(fe->i_uid);
5664 +       gid = le32_to_cpu(fe->i_gid);
5665 +       i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5666 +       i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5667 +       i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5668 +               /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5669  
5670         /* Fast symlinks will have i_size but no allocated clusters. */
5671         if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5672 diff -NurpP --minimal linux-3.10.40/fs/ocfs2/inode.h linux-3.10.40-vs2.3.6.8/fs/ocfs2/inode.h
5673 --- linux-3.10.40/fs/ocfs2/inode.h      2013-07-14 17:01:29.000000000 +0000
5674 +++ linux-3.10.40-vs2.3.6.8/fs/ocfs2/inode.h    2013-08-22 20:29:59.000000000 +0000
5675 @@ -152,6 +152,7 @@ struct buffer_head *ocfs2_bread(struct i
5676  
5677  void ocfs2_set_inode_flags(struct inode *inode);
5678  void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5679 +int ocfs2_sync_flags(struct inode *inode, int, int);
5680  
5681  static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5682  {
5683 diff -NurpP --minimal linux-3.10.40/fs/ocfs2/ioctl.c linux-3.10.40-vs2.3.6.8/fs/ocfs2/ioctl.c
5684 --- linux-3.10.40/fs/ocfs2/ioctl.c      2013-07-14 17:01:29.000000000 +0000
5685 +++ linux-3.10.40-vs2.3.6.8/fs/ocfs2/ioctl.c    2013-08-22 20:29:59.000000000 +0000
5686 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5687         return status;
5688  }
5689  
5690 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5691 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5692 +{
5693 +       struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5694 +       struct buffer_head *bh = NULL;
5695 +       handle_t *handle = NULL;
5696 +       int status;
5697 +
5698 +       status = ocfs2_inode_lock(inode, &bh, 1);
5699 +       if (status < 0) {
5700 +               mlog_errno(status);
5701 +               return status;
5702 +       }
5703 +       handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5704 +       if (IS_ERR(handle)) {
5705 +               status = PTR_ERR(handle);
5706 +               mlog_errno(status);
5707 +               goto bail_unlock;
5708 +       }
5709 +
5710 +       inode->i_flags = flags;
5711 +       inode->i_vflags = vflags;
5712 +       ocfs2_get_inode_flags(OCFS2_I(inode));
5713 +
5714 +       status = ocfs2_mark_inode_dirty(handle, inode, bh);
5715 +       if (status < 0)
5716 +               mlog_errno(status);
5717 +
5718 +       ocfs2_commit_trans(osb, handle);
5719 +bail_unlock:
5720 +       ocfs2_inode_unlock(inode, 1);
5721 +       brelse(bh);
5722 +       return status;
5723 +}
5724 +
5725 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5726                                 unsigned mask)
5727  {
5728         struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5729 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5730                         goto bail_unlock;
5731         }
5732  
5733 +       if (IS_BARRIER(inode)) {
5734 +               vxwprintk_task(1, "messing with the barrier.");
5735 +               goto bail_unlock;
5736 +       }
5737 +
5738         handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5739         if (IS_ERR(handle)) {
5740                 status = PTR_ERR(handle);
5741 @@ -881,6 +920,7 @@ bail:
5742         return status;
5743  }
5744  
5745 +
5746  long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5747  {
5748         struct inode *inode = file_inode(filp);
5749 diff -NurpP --minimal linux-3.10.40/fs/ocfs2/namei.c linux-3.10.40-vs2.3.6.8/fs/ocfs2/namei.c
5750 --- linux-3.10.40/fs/ocfs2/namei.c      2013-07-14 17:01:29.000000000 +0000
5751 +++ linux-3.10.40-vs2.3.6.8/fs/ocfs2/namei.c    2013-08-22 20:29:59.000000000 +0000
5752 @@ -41,6 +41,7 @@
5753  #include <linux/slab.h>
5754  #include <linux/highmem.h>
5755  #include <linux/quotaops.h>
5756 +#include <linux/vs_tag.h>
5757  
5758  #include <cluster/masklog.h>
5759  
5760 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5761         struct ocfs2_dinode *fe = NULL;
5762         struct ocfs2_extent_list *fel;
5763         u16 feat;
5764 +       ktag_t ktag;
5765  
5766         *new_fe_bh = NULL;
5767  
5768 @@ -512,8 +514,13 @@ static int __ocfs2_mknod_locked(struct i
5769         fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5770         fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5771         fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5772 -       fe->i_uid = cpu_to_le32(i_uid_read(inode));
5773 -       fe->i_gid = cpu_to_le32(i_gid_read(inode));
5774 +
5775 +       ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5776 +       fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5777 +               TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5778 +       fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5779 +               TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5780 +       inode->i_tag = ktag; /* is this correct? */
5781         fe->i_mode = cpu_to_le16(inode->i_mode);
5782         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5783                 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5784 diff -NurpP --minimal linux-3.10.40/fs/ocfs2/ocfs2.h linux-3.10.40-vs2.3.6.8/fs/ocfs2/ocfs2.h
5785 --- linux-3.10.40/fs/ocfs2/ocfs2.h      2012-12-11 03:30:57.000000000 +0000
5786 +++ linux-3.10.40-vs2.3.6.8/fs/ocfs2/ocfs2.h    2013-08-22 20:29:59.000000000 +0000
5787 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5788                                                      writes */
5789         OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5790         OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5791 +       OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5792  };
5793  
5794  #define OCFS2_OSB_SOFT_RO                      0x0001
5795 diff -NurpP --minimal linux-3.10.40/fs/ocfs2/ocfs2_fs.h linux-3.10.40-vs2.3.6.8/fs/ocfs2/ocfs2_fs.h
5796 --- linux-3.10.40/fs/ocfs2/ocfs2_fs.h   2012-12-11 03:30:57.000000000 +0000
5797 +++ linux-3.10.40-vs2.3.6.8/fs/ocfs2/ocfs2_fs.h 2013-08-22 20:29:59.000000000 +0000
5798 @@ -266,6 +266,11 @@
5799  #define OCFS2_TOPDIR_FL                        FS_TOPDIR_FL    /* Top of directory hierarchies*/
5800  #define OCFS2_RESERVED_FL              FS_RESERVED_FL  /* reserved for ext2 lib */
5801  
5802 +#define OCFS2_IXUNLINK_FL              FS_IXUNLINK_FL  /* Immutable invert on unlink */
5803 +
5804 +#define OCFS2_BARRIER_FL               FS_BARRIER_FL   /* Barrier for chroot() */
5805 +#define OCFS2_COW_FL                   FS_COW_FL       /* Copy on Write marker */
5806 +
5807  #define OCFS2_FL_VISIBLE               FS_FL_USER_VISIBLE      /* User visible flags */
5808  #define OCFS2_FL_MODIFIABLE            FS_FL_USER_MODIFIABLE   /* User modifiable flags */
5809  
5810 diff -NurpP --minimal linux-3.10.40/fs/ocfs2/super.c linux-3.10.40-vs2.3.6.8/fs/ocfs2/super.c
5811 --- linux-3.10.40/fs/ocfs2/super.c      2013-05-31 13:45:25.000000000 +0000
5812 +++ linux-3.10.40-vs2.3.6.8/fs/ocfs2/super.c    2013-08-22 20:29:59.000000000 +0000
5813 @@ -185,6 +185,7 @@ enum {
5814         Opt_coherency_full,
5815         Opt_resv_level,
5816         Opt_dir_resv_level,
5817 +       Opt_tag, Opt_notag, Opt_tagid,
5818         Opt_err,
5819  };
5820  
5821 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5822         {Opt_coherency_full, "coherency=full"},
5823         {Opt_resv_level, "resv_level=%u"},
5824         {Opt_dir_resv_level, "dir_resv_level=%u"},
5825 +       {Opt_tag, "tag"},
5826 +       {Opt_notag, "notag"},
5827 +       {Opt_tagid, "tagid=%u"},
5828         {Opt_err, NULL}
5829  };
5830  
5831 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5832                 goto out;
5833         }
5834  
5835 +       if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5836 +           (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5837 +               ret = -EINVAL;
5838 +               mlog(ML_ERROR, "Cannot change tagging on remount\n");
5839 +               goto out;
5840 +       }
5841 +
5842         /* We're going to/from readonly mode. */
5843         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5844                 /* Disable quota accounting before remounting RO */
5845 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5846  
5847         ocfs2_complete_mount_recovery(osb);
5848  
5849 +       if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5850 +               sb->s_flags |= MS_TAGGED;
5851 +
5852         if (ocfs2_mount_local(osb))
5853                 snprintf(nodestr, sizeof(nodestr), "local");
5854         else
5855 @@ -1504,6 +1518,20 @@ static int ocfs2_parse_options(struct su
5856                             option < OCFS2_MAX_RESV_LEVEL)
5857                                 mopt->dir_resv_level = option;
5858                         break;
5859 +#ifndef CONFIG_TAGGING_NONE
5860 +               case Opt_tag:
5861 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5862 +                       break;
5863 +               case Opt_notag:
5864 +                       mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5865 +                       break;
5866 +#endif
5867 +#ifdef CONFIG_PROPAGATE
5868 +               case Opt_tagid:
5869 +                       /* use args[0] */
5870 +                       mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5871 +                       break;
5872 +#endif
5873                 default:
5874                         mlog(ML_ERROR,
5875                              "Unrecognized mount option \"%s\" "
5876 diff -NurpP --minimal linux-3.10.40/fs/open.c linux-3.10.40-vs2.3.6.8/fs/open.c
5877 --- linux-3.10.40/fs/open.c     2013-07-14 17:01:29.000000000 +0000
5878 +++ linux-3.10.40-vs2.3.6.8/fs/open.c   2013-08-22 20:29:59.000000000 +0000
5879 @@ -31,6 +31,11 @@
5880  #include <linux/ima.h>
5881  #include <linux/dnotify.h>
5882  #include <linux/compat.h>
5883 +#include <linux/vs_base.h>
5884 +#include <linux/vs_limit.h>
5885 +#include <linux/vs_tag.h>
5886 +#include <linux/vs_cowbl.h>
5887 +#include <linux/vserver/dlimit.h>
5888  
5889  #include "internal.h"
5890  
5891 @@ -67,6 +72,11 @@ long vfs_truncate(struct path *path, lof
5892         struct inode *inode;
5893         long error;
5894  
5895 +#ifdef CONFIG_VSERVER_COWBL
5896 +       error = cow_check_and_break(path);
5897 +       if (error)
5898 +               goto out;
5899 +#endif
5900         inode = path->dentry->d_inode;
5901  
5902         /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5903 @@ -504,6 +514,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5904         unsigned int lookup_flags = LOOKUP_FOLLOW;
5905  retry:
5906         error = user_path_at(dfd, filename, lookup_flags, &path);
5907 +#ifdef CONFIG_VSERVER_COWBL
5908 +       if (!error) {
5909 +               error = cow_check_and_break(&path);
5910 +               if (error)
5911 +                       path_put(&path);
5912 +       }
5913 +#endif
5914         if (!error) {
5915                 error = chmod_common(&path, mode);
5916                 path_put(&path);
5917 @@ -536,13 +553,15 @@ static int chown_common(struct path *pat
5918                 if (!uid_valid(uid))
5919                         return -EINVAL;
5920                 newattrs.ia_valid |= ATTR_UID;
5921 -               newattrs.ia_uid = uid;
5922 +               newattrs.ia_uid = make_kuid(&init_user_ns,
5923 +                       dx_map_uid(user));
5924         }
5925         if (group != (gid_t) -1) {
5926                 if (!gid_valid(gid))
5927                         return -EINVAL;
5928                 newattrs.ia_valid |= ATTR_GID;
5929 -               newattrs.ia_gid = gid;
5930 +               newattrs.ia_gid = make_kgid(&init_user_ns,
5931 +                       dx_map_gid(group));
5932         }
5933         if (!S_ISDIR(inode->i_mode))
5934                 newattrs.ia_valid |=
5935 @@ -576,6 +595,18 @@ retry:
5936         error = mnt_want_write(path.mnt);
5937         if (error)
5938                 goto out_release;
5939 +#ifdef CONFIG_VSERVER_COWBL
5940 +       error = cow_check_and_break(&path);
5941 +       if (!error)
5942 +#endif
5943 +#ifdef CONFIG_VSERVER_COWBL
5944 +       error = cow_check_and_break(&path);
5945 +       if (!error)
5946 +#endif
5947 +#ifdef CONFIG_VSERVER_COWBL
5948 +       error = cow_check_and_break(&path);
5949 +       if (!error)
5950 +#endif
5951         error = chown_common(&path, user, group);
5952         mnt_drop_write(path.mnt);
5953  out_release:
5954 diff -NurpP --minimal linux-3.10.40/fs/proc/array.c linux-3.10.40-vs2.3.6.8/fs/proc/array.c
5955 --- linux-3.10.40/fs/proc/array.c       2013-05-31 13:45:25.000000000 +0000
5956 +++ linux-3.10.40-vs2.3.6.8/fs/proc/array.c     2013-08-22 20:29:59.000000000 +0000
5957 @@ -82,6 +82,8 @@
5958  #include <linux/ptrace.h>
5959  #include <linux/tracehook.h>
5960  #include <linux/user_namespace.h>
5961 +#include <linux/vs_context.h>
5962 +#include <linux/vs_network.h>
5963  
5964  #include <asm/pgtable.h>
5965  #include <asm/processor.h>
5966 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
5967         rcu_read_lock();
5968         ppid = pid_alive(p) ?
5969                 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5970 +       if (unlikely(vx_current_initpid(p->pid)))
5971 +               ppid = 0;
5972 +
5973         tpid = 0;
5974         if (pid_alive(p)) {
5975                 struct task_struct *tracer = ptrace_parent(p);
5976 @@ -297,7 +302,7 @@ static inline void task_sig(struct seq_f
5977  }
5978  
5979  static void render_cap_t(struct seq_file *m, const char *header,
5980 -                       kernel_cap_t *a)
5981 +                       struct vx_info *vxi, kernel_cap_t *a)
5982  {
5983         unsigned __capi;
5984  
5985 @@ -331,10 +336,11 @@ static inline void task_cap(struct seq_f
5986         NORM_CAPS(cap_effective);
5987         NORM_CAPS(cap_bset);
5988  
5989 -       render_cap_t(m, "CapInh:\t", &cap_inheritable);
5990 -       render_cap_t(m, "CapPrm:\t", &cap_permitted);
5991 -       render_cap_t(m, "CapEff:\t", &cap_effective);
5992 -       render_cap_t(m, "CapBnd:\t", &cap_bset);
5993 +       /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5994 +       render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5995 +       render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5996 +       render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5997 +       render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
5998  }
5999  
6000  static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
6001 @@ -363,6 +369,42 @@ static void task_cpus_allowed(struct seq
6002         seq_putc(m, '\n');
6003  }
6004  
6005 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6006 +                       struct pid *pid, struct task_struct *task)
6007 +{
6008 +       seq_printf(m,   "Proxy:\t%p(%c)\n"
6009 +                       "Count:\t%u\n"
6010 +                       "uts:\t%p(%c)\n"
6011 +                       "ipc:\t%p(%c)\n"
6012 +                       "mnt:\t%p(%c)\n"
6013 +                       "pid:\t%p(%c)\n"
6014 +                       "net:\t%p(%c)\n",
6015 +                       task->nsproxy,
6016 +                       (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6017 +                       atomic_read(&task->nsproxy->count),
6018 +                       task->nsproxy->uts_ns,
6019 +                       (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6020 +                       task->nsproxy->ipc_ns,
6021 +                       (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6022 +                       task->nsproxy->mnt_ns,
6023 +                       (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6024 +                       task->nsproxy->pid_ns,
6025 +                       (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6026 +                       task->nsproxy->net_ns,
6027 +                       (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6028 +       return 0;
6029 +}
6030 +
6031 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6032 +{
6033 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6034 +               return;
6035 +
6036 +       seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6037 +       seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6038 +}
6039 +
6040 +
6041  int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6042                         struct pid *pid, struct task_struct *task)
6043  {
6044 @@ -380,6 +422,7 @@ int proc_pid_status(struct seq_file *m,
6045         task_seccomp(m, task);
6046         task_cpus_allowed(m, task);
6047         cpuset_task_status_allowed(m, task);
6048 +       task_vs_id(m, task);
6049         task_context_switch_counts(m, task);
6050         return 0;
6051  }
6052 @@ -489,6 +532,17 @@ static int do_task_stat(struct seq_file
6053         /* convert nsec -> ticks */
6054         start_time = nsec_to_clock_t(start_time);
6055  
6056 +       /* fixup start time for virt uptime */
6057 +       if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6058 +               unsigned long long bias =
6059 +                       current->vx_info->cvirt.bias_clock;
6060 +
6061 +               if (start_time > bias)
6062 +                       start_time -= bias;
6063 +               else
6064 +                       start_time = 0;
6065 +       }
6066 +
6067         seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6068         seq_put_decimal_ll(m, ' ', ppid);
6069         seq_put_decimal_ll(m, ' ', pgid);
6070 diff -NurpP --minimal linux-3.10.40/fs/proc/base.c linux-3.10.40-vs2.3.6.8/fs/proc/base.c
6071 --- linux-3.10.40/fs/proc/base.c        2014-05-20 04:09:40.000000000 +0000
6072 +++ linux-3.10.40-vs2.3.6.8/fs/proc/base.c      2014-04-22 03:48:11.000000000 +0000
6073 @@ -87,6 +87,8 @@
6074  #include <linux/slab.h>
6075  #include <linux/flex_array.h>
6076  #include <linux/posix-timers.h>
6077 +#include <linux/vs_context.h>
6078 +#include <linux/vs_network.h>
6079  #ifdef CONFIG_HARDWALL
6080  #include <asm/hardwall.h>
6081  #endif
6082 @@ -976,11 +978,15 @@ static ssize_t oom_adj_write(struct file
6083                 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6084  
6085         if (oom_adj < task->signal->oom_score_adj &&
6086 -           !capable(CAP_SYS_RESOURCE)) {
6087 +           !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6088                 err = -EACCES;
6089                 goto err_sighand;
6090         }
6091  
6092 +       /* prevent guest processes from circumventing the oom killer */
6093 +       if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6094 +               oom_adj = OOM_ADJUST_MIN;
6095 +
6096         /*
6097          * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6098          * /proc/pid/oom_score_adj instead.
6099 @@ -1559,6 +1565,8 @@ struct inode *proc_pid_make_inode(struct
6100                 inode->i_gid = cred->egid;
6101                 rcu_read_unlock();
6102         }
6103 +       /* procfs is xid tagged */
6104 +       i_tag_write(inode, (vtag_t)vx_task_xid(task));
6105         security_task_to_inode(task, inode);
6106  
6107  out:
6108 @@ -1604,6 +1612,8 @@ int pid_getattr(struct vfsmount *mnt, st
6109  
6110  /* dentry stuff */
6111  
6112 +static unsigned name_to_int(struct dentry *dentry);
6113 +
6114  /*
6115   *     Exceptional case: normally we are not allowed to unhash a busy
6116   * directory. In this case, however, we can do it - no aliasing problems
6117 @@ -1632,6 +1642,12 @@ int pid_revalidate(struct dentry *dentry
6118         task = get_proc_task(inode);
6119  
6120         if (task) {
6121 +               unsigned pid = name_to_int(dentry);
6122 +
6123 +               if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6124 +                       put_task_struct(task);
6125 +                       goto drop;
6126 +               }
6127                 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6128                     task_dumpable(task)) {
6129                         rcu_read_lock();
6130 @@ -1648,6 +1664,7 @@ int pid_revalidate(struct dentry *dentry
6131                 put_task_struct(task);
6132                 return 1;
6133         }
6134 +drop:
6135         d_drop(dentry);
6136         return 0;
6137  }
6138 @@ -2197,6 +2214,13 @@ static struct dentry *proc_pident_lookup
6139         if (!task)
6140                 goto out_no_task;
6141  
6142 +       /* TODO: maybe we can come up with a generic approach? */
6143 +       if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6144 +               (dentry->d_name.len == 5) &&
6145 +               (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6146 +               !memcmp(dentry->d_name.name, "ninfo", 5)))
6147 +               goto out;
6148 +
6149         /*
6150          * Yes, it does not scale. And it should not. Don't add
6151          * new entries into /proc/<tgid>/ without very good reasons.
6152 @@ -2631,6 +2655,9 @@ static int proc_pid_personality(struct s
6153  static const struct file_operations proc_task_operations;
6154  static const struct inode_operations proc_task_inode_operations;
6155  
6156 +extern int proc_pid_vx_info(struct task_struct *, char *);
6157 +extern int proc_pid_nx_info(struct task_struct *, char *);
6158 +
6159  static const struct pid_entry tgid_base_stuff[] = {
6160         DIR("task",       S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6161         DIR("fd",         S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6162 @@ -2697,6 +2724,8 @@ static const struct pid_entry tgid_base_
6163  #ifdef CONFIG_CGROUPS
6164         REG("cgroup",  S_IRUGO, proc_cgroup_operations),
6165  #endif
6166 +       INF("vinfo",      S_IRUGO, proc_pid_vx_info),
6167 +       INF("ninfo",      S_IRUGO, proc_pid_nx_info),
6168         INF("oom_score",  S_IRUGO, proc_oom_score),
6169         REG("oom_adj",    S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6170         REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6171 @@ -2911,7 +2940,7 @@ retry:
6172         iter.task = NULL;
6173         pid = find_ge_pid(iter.tgid, ns);
6174         if (pid) {
6175 -               iter.tgid = pid_nr_ns(pid, ns);
6176 +               iter.tgid = pid_unmapped_nr_ns(pid, ns);
6177                 iter.task = pid_task(pid, PIDTYPE_PID);
6178                 /* What we to know is if the pid we have find is the
6179                  * pid of a thread_group_leader.  Testing for task
6180 @@ -2941,7 +2970,7 @@ static int proc_pid_fill_cache(struct fi
6181         struct tgid_iter iter)
6182  {
6183         char name[PROC_NUMBUF];
6184 -       int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6185 +       int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6186         return proc_fill_cache(filp, dirent, filldir, name, len,
6187                                 proc_pid_instantiate, iter.task, NULL);
6188  }
6189 @@ -2982,6 +3011,8 @@ int proc_pid_readdir(struct file * filp,
6190                         __filldir = fake_filldir;
6191  
6192                 filp->f_pos = iter.tgid + TGID_OFFSET;
6193 +               if (!vx_proc_task_visible(iter.task))
6194 +                       continue;
6195                 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6196                         put_task_struct(iter.task);
6197                         goto out;
6198 @@ -3074,6 +3105,7 @@ static const struct pid_entry tid_base_s
6199         REG("gid_map",    S_IRUGO|S_IWUSR, proc_gid_map_operations),
6200         REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6201  #endif
6202 +       ONE("nsproxy",  S_IRUGO, proc_pid_nsproxy),
6203  };
6204  
6205  static int proc_tid_base_readdir(struct file * filp,
6206 @@ -3142,6 +3174,8 @@ static struct dentry *proc_task_lookup(s
6207         tid = name_to_int(dentry);
6208         if (tid == ~0U)
6209                 goto out;
6210 +       if (vx_current_initpid(tid))
6211 +               goto out;
6212  
6213         ns = dentry->d_sb->s_fs_info;
6214         rcu_read_lock();
6215 diff -NurpP --minimal linux-3.10.40/fs/proc/generic.c linux-3.10.40-vs2.3.6.8/fs/proc/generic.c
6216 --- linux-3.10.40/fs/proc/generic.c     2013-07-14 17:01:29.000000000 +0000
6217 +++ linux-3.10.40-vs2.3.6.8/fs/proc/generic.c   2013-08-22 20:29:59.000000000 +0000
6218 @@ -23,6 +23,7 @@
6219  #include <linux/bitops.h>
6220  #include <linux/spinlock.h>
6221  #include <linux/completion.h>
6222 +#include <linux/vserver/inode.h>
6223  #include <asm/uaccess.h>
6224  
6225  #include "internal.h"
6226 @@ -203,6 +204,8 @@ struct dentry *proc_lookup_de(struct pro
6227         for (de = de->subdir; de ; de = de->next) {
6228                 if (de->namelen != dentry->d_name.len)
6229                         continue;
6230 +               if (!vx_hide_check(0, de->vx_flags))
6231 +                       continue;
6232                 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6233                         pde_get(de);
6234                         spin_unlock(&proc_subdir_lock);
6235 @@ -211,6 +214,8 @@ struct dentry *proc_lookup_de(struct pro
6236                                 return ERR_PTR(-ENOMEM);
6237                         d_set_d_op(dentry, &proc_dentry_operations);
6238                         d_add(dentry, inode);
6239 +                       /* generic proc entries belong to the host */
6240 +                       i_tag_write(inode, 0);
6241                         return NULL;
6242                 }
6243         }
6244 @@ -279,6 +284,8 @@ int proc_readdir_de(struct proc_dir_entr
6245  
6246                                 /* filldir passes info to user space */
6247                                 pde_get(de);
6248 +                               if (!vx_hide_check(0, de->vx_flags))
6249 +                                       goto skip;
6250                                 spin_unlock(&proc_subdir_lock);
6251                                 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6252                                             de->low_ino, de->mode >> 12) < 0) {
6253 @@ -286,6 +293,7 @@ int proc_readdir_de(struct proc_dir_entr
6254                                         goto out;
6255                                 }
6256                                 spin_lock(&proc_subdir_lock);
6257 +                       skip:
6258                                 filp->f_pos++;
6259                                 next = de->next;
6260                                 pde_put(de);
6261 @@ -395,6 +403,7 @@ static struct proc_dir_entry *__proc_cre
6262         ent->namelen = len;
6263         ent->mode = mode;
6264         ent->nlink = nlink;
6265 +       ent->vx_flags = IATTR_PROC_DEFAULT;
6266         atomic_set(&ent->count, 1);
6267         spin_lock_init(&ent->pde_unload_lock);
6268         INIT_LIST_HEAD(&ent->pde_openers);
6269 @@ -418,7 +427,8 @@ struct proc_dir_entry *proc_symlink(cons
6270                                 kfree(ent->data);
6271                                 kfree(ent);
6272                                 ent = NULL;
6273 -                       }
6274 +                       } else
6275 +                               ent->vx_flags = IATTR_PROC_SYMLINK;
6276                 } else {
6277                         kfree(ent);
6278                         ent = NULL;
6279 diff -NurpP --minimal linux-3.10.40/fs/proc/inode.c linux-3.10.40-vs2.3.6.8/fs/proc/inode.c
6280 --- linux-3.10.40/fs/proc/inode.c       2013-07-14 17:01:29.000000000 +0000
6281 +++ linux-3.10.40-vs2.3.6.8/fs/proc/inode.c     2013-08-22 20:29:59.000000000 +0000
6282 @@ -387,6 +387,8 @@ struct inode *proc_get_inode(struct supe
6283                         inode->i_uid = de->uid;
6284                         inode->i_gid = de->gid;
6285                 }
6286 +               if (de->vx_flags)
6287 +                       PROC_I(inode)->vx_flags = de->vx_flags;
6288                 if (de->size)
6289                         inode->i_size = de->size;
6290                 if (de->nlink)
6291 diff -NurpP --minimal linux-3.10.40/fs/proc/internal.h linux-3.10.40-vs2.3.6.8/fs/proc/internal.h
6292 --- linux-3.10.40/fs/proc/internal.h    2013-07-14 17:01:29.000000000 +0000
6293 +++ linux-3.10.40-vs2.3.6.8/fs/proc/internal.h  2013-08-22 21:52:30.000000000 +0000
6294 @@ -14,6 +14,7 @@
6295  #include <linux/spinlock.h>
6296  #include <linux/atomic.h>
6297  #include <linux/binfmts.h>
6298 +#include <linux/vs_pid.h>
6299  
6300  struct ctl_table_header;
6301  struct mempolicy;
6302 @@ -35,6 +36,7 @@ struct proc_dir_entry {
6303         nlink_t nlink;
6304         kuid_t uid;
6305         kgid_t gid;
6306 +       int vx_flags;
6307         loff_t size;
6308         const struct inode_operations *proc_iops;
6309         const struct file_operations *proc_fops;
6310 @@ -50,16 +52,23 @@ struct proc_dir_entry {
6311         char name[];
6312  };
6313  
6314 +struct vx_info;
6315 +struct nx_info;
6316 +
6317  union proc_op {
6318         int (*proc_get_link)(struct dentry *, struct path *);
6319         int (*proc_read)(struct task_struct *task, char *page);
6320         int (*proc_show)(struct seq_file *m,
6321                 struct pid_namespace *ns, struct pid *pid,
6322                 struct task_struct *task);
6323 +       int (*proc_vs_read)(char *page);
6324 +       int (*proc_vxi_read)(struct vx_info *vxi, char *page);
6325 +       int (*proc_nxi_read)(struct nx_info *nxi, char *page);
6326  };
6327  
6328  struct proc_inode {
6329         struct pid *pid;
6330 +       int vx_flags;
6331         int fd;
6332         union proc_op op;
6333         struct proc_dir_entry *pde;
6334 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
6335         return PROC_I(inode)->pid;
6336  }
6337  
6338 -static inline struct task_struct *get_proc_task(struct inode *inode)
6339 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6340  {
6341         return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6342  }
6343  
6344 +static inline struct task_struct *get_proc_task(struct inode *inode)
6345 +{
6346 +       return vx_get_proc_task(inode, proc_pid(inode));
6347 +}
6348 +
6349  static inline int task_dumpable(struct task_struct *task)
6350  {
6351         int dumpable = 0;
6352 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6353                            struct pid *, struct task_struct *);
6354  extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6355                           struct pid *, struct task_struct *);
6356 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6357 +                           struct pid *pid, struct task_struct *task);
6358  
6359  /*
6360   * base.c
6361 diff -NurpP --minimal linux-3.10.40/fs/proc/loadavg.c linux-3.10.40-vs2.3.6.8/fs/proc/loadavg.c
6362 --- linux-3.10.40/fs/proc/loadavg.c     2012-12-11 03:30:57.000000000 +0000
6363 +++ linux-3.10.40-vs2.3.6.8/fs/proc/loadavg.c   2013-08-22 20:30:00.000000000 +0000
6364 @@ -12,15 +12,27 @@
6365  
6366  static int loadavg_proc_show(struct seq_file *m, void *v)
6367  {
6368 +       unsigned long running;
6369 +       unsigned int threads;
6370         unsigned long avnrun[3];
6371  
6372         get_avenrun(avnrun, FIXED_1/200, 0);
6373  
6374 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
6375 +               struct vx_info *vxi = current_vx_info();
6376 +
6377 +               running = atomic_read(&vxi->cvirt.nr_running);
6378 +               threads = atomic_read(&vxi->cvirt.nr_threads);
6379 +       } else {
6380 +               running = nr_running();
6381 +               threads = nr_threads;
6382 +       }
6383 +
6384         seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6385                 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6386                 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6387                 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6388 -               nr_running(), nr_threads,
6389 +               running, threads,
6390                 task_active_pid_ns(current)->last_pid);
6391         return 0;
6392  }
6393 diff -NurpP --minimal linux-3.10.40/fs/proc/meminfo.c linux-3.10.40-vs2.3.6.8/fs/proc/meminfo.c
6394 --- linux-3.10.40/fs/proc/meminfo.c     2013-07-14 17:01:29.000000000 +0000
6395 +++ linux-3.10.40-vs2.3.6.8/fs/proc/meminfo.c   2013-08-22 20:30:00.000000000 +0000
6396 @@ -40,7 +40,8 @@ static int meminfo_proc_show(struct seq_
6397         allowed = ((totalram_pages - hugetlb_total_pages())
6398                 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6399  
6400 -       cached = global_page_state(NR_FILE_PAGES) -
6401 +       cached = vx_flags(VXF_VIRT_MEM, 0) ?
6402 +               vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6403                         total_swapcache_pages() - i.bufferram;
6404         if (cached < 0)
6405                 cached = 0;
6406 diff -NurpP --minimal linux-3.10.40/fs/proc/root.c linux-3.10.40-vs2.3.6.8/fs/proc/root.c
6407 --- linux-3.10.40/fs/proc/root.c        2014-05-20 04:09:40.000000000 +0000
6408 +++ linux-3.10.40-vs2.3.6.8/fs/proc/root.c      2013-11-13 17:19:37.000000000 +0000
6409 @@ -20,9 +20,14 @@
6410  #include <linux/mount.h>
6411  #include <linux/pid_namespace.h>
6412  #include <linux/parser.h>
6413 +#include <linux/vserver/inode.h>
6414  
6415  #include "internal.h"
6416  
6417 +struct proc_dir_entry *proc_virtual;
6418 +
6419 +extern void proc_vx_init(void);
6420 +
6421  static int proc_test_super(struct super_block *sb, void *data)
6422  {
6423         return sb->s_fs_info == data;
6424 @@ -111,7 +116,8 @@ static struct dentry *proc_mount(struct
6425                 options = data;
6426  
6427                 if (!current_user_ns()->may_mount_proc ||
6428 -                   !ns_capable(ns->user_ns, CAP_SYS_ADMIN))
6429 +                   !vx_ns_capable(ns->user_ns,
6430 +                       CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6431                         return ERR_PTR(-EPERM);
6432         }
6433  
6434 @@ -185,6 +191,7 @@ void __init proc_root_init(void)
6435  #endif
6436         proc_mkdir("bus", NULL);
6437         proc_sys_init();
6438 +       proc_vx_init();
6439  }
6440  
6441  static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6442 @@ -251,6 +258,7 @@ struct proc_dir_entry proc_root = {
6443         .proc_iops      = &proc_root_inode_operations, 
6444         .proc_fops      = &proc_root_operations,
6445         .parent         = &proc_root,
6446 +       .vx_flags       = IATTR_ADMIN | IATTR_WATCH,
6447         .name           = "/proc",
6448  };
6449  
6450 diff -NurpP --minimal linux-3.10.40/fs/proc/self.c linux-3.10.40-vs2.3.6.8/fs/proc/self.c
6451 --- linux-3.10.40/fs/proc/self.c        2013-07-14 17:01:29.000000000 +0000
6452 +++ linux-3.10.40-vs2.3.6.8/fs/proc/self.c      2013-08-23 00:07:45.000000000 +0000
6453 @@ -2,6 +2,7 @@
6454  #include <linux/namei.h>
6455  #include <linux/slab.h>
6456  #include <linux/pid_namespace.h>
6457 +#include <linux/vserver/inode.h>
6458  #include "internal.h"
6459  
6460  /*
6461 @@ -62,6 +63,8 @@ int proc_setup_self(struct super_block *
6462         self = d_alloc_name(s->s_root, "self");
6463         if (self) {
6464                 struct inode *inode = new_inode_pseudo(s);
6465 +
6466 +               // self->vx_flags = IATTR_PROC_SYMLINK;
6467                 if (inode) {
6468                         inode->i_ino = self_inum;
6469                         inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6470 diff -NurpP --minimal linux-3.10.40/fs/proc/stat.c linux-3.10.40-vs2.3.6.8/fs/proc/stat.c
6471 --- linux-3.10.40/fs/proc/stat.c        2013-07-14 17:01:29.000000000 +0000
6472 +++ linux-3.10.40-vs2.3.6.8/fs/proc/stat.c      2013-08-22 20:30:00.000000000 +0000
6473 @@ -9,8 +9,10 @@
6474  #include <linux/slab.h>
6475  #include <linux/time.h>
6476  #include <linux/irqnr.h>
6477 +#include <linux/vserver/cvirt.h>
6478  #include <asm/cputime.h>
6479  #include <linux/tick.h>
6480 +#include <linux/cpuset.h>
6481  
6482  #ifndef arch_irq_stat_cpu
6483  #define arch_irq_stat_cpu(cpu) 0
6484 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6485         u64 sum_softirq = 0;
6486         unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6487         struct timespec boottime;
6488 +       cpumask_var_t cpus_allowed;
6489 +       bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6490  
6491         user = nice = system = idle = iowait =
6492                 irq = softirq = steal = 0;
6493         guest = guest_nice = 0;
6494         getboottime(&boottime);
6495 +
6496 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6497 +               vx_vsi_boottime(&boottime);
6498 +
6499 +       if (virt_cpu)
6500 +               cpuset_cpus_allowed(current, cpus_allowed);
6501 +
6502         jif = boottime.tv_sec;
6503  
6504         for_each_possible_cpu(i) {
6505 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6506 +                       continue;
6507 +
6508                 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6509                 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6510                 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6511 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6512         seq_putc(p, '\n');
6513  
6514         for_each_online_cpu(i) {
6515 +               if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6516 +                       continue;
6517 +
6518                 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6519                 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6520                 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6521 diff -NurpP --minimal linux-3.10.40/fs/proc/uptime.c linux-3.10.40-vs2.3.6.8/fs/proc/uptime.c
6522 --- linux-3.10.40/fs/proc/uptime.c      2012-12-11 03:30:57.000000000 +0000
6523 +++ linux-3.10.40-vs2.3.6.8/fs/proc/uptime.c    2013-08-22 20:30:00.000000000 +0000
6524 @@ -5,6 +5,7 @@
6525  #include <linux/seq_file.h>
6526  #include <linux/time.h>
6527  #include <linux/kernel_stat.h>
6528 +#include <linux/vserver/cvirt.h>
6529  #include <asm/cputime.h>
6530  
6531  static int uptime_proc_show(struct seq_file *m, void *v)
6532 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6533         nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6534         idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6535         idle.tv_nsec = rem;
6536 +
6537 +       if (vx_flags(VXF_VIRT_UPTIME, 0))
6538 +               vx_vsi_uptime(&uptime, &idle);
6539 +
6540         seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6541                         (unsigned long) uptime.tv_sec,
6542                         (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6543 diff -NurpP --minimal linux-3.10.40/fs/proc_namespace.c linux-3.10.40-vs2.3.6.8/fs/proc_namespace.c
6544 --- linux-3.10.40/fs/proc_namespace.c   2012-12-11 03:30:57.000000000 +0000
6545 +++ linux-3.10.40-vs2.3.6.8/fs/proc_namespace.c 2013-08-22 20:30:00.000000000 +0000
6546 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6547                 { MS_SYNCHRONOUS, ",sync" },
6548                 { MS_DIRSYNC, ",dirsync" },
6549                 { MS_MANDLOCK, ",mand" },
6550 +               { MS_TAGGED, ",tag" },
6551 +               { MS_NOTAGCHECK, ",notagcheck" },
6552                 { 0, NULL }
6553         };
6554         const struct proc_fs_info *fs_infop;
6555 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6556         seq_escape(m, s, " \t\n\\");
6557  }
6558  
6559 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6560 +
6561 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6562 +{
6563 +       struct path root;
6564 +       struct dentry *point;
6565 +       struct mount *mnt = real_mount(vfsmnt);
6566 +       struct mount *root_mnt;
6567 +       int ret;
6568 +
6569 +       if (mnt == mnt->mnt_ns->root)
6570 +               return 1;
6571 +
6572 +       br_read_lock(&vfsmount_lock);
6573 +       root = current->fs->root;
6574 +       root_mnt = real_mount(root.mnt);
6575 +       point = root.dentry;
6576 +
6577 +       while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6578 +               point = mnt->mnt_mountpoint;
6579 +               mnt = mnt->mnt_parent;
6580 +       }
6581 +
6582 +       ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6583 +
6584 +       br_read_unlock(&vfsmount_lock);
6585 +
6586 +       return ret;
6587 +}
6588 +
6589 +#else
6590 +#define        mnt_is_reachable(v)     (1)
6591 +#endif
6592 +
6593  static void show_type(struct seq_file *m, struct super_block *sb)
6594  {
6595         mangle(m, sb->s_type->name);
6596 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6597         struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6598         struct super_block *sb = mnt_path.dentry->d_sb;
6599  
6600 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6601 +               return SEQ_SKIP;
6602 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6603 +               return SEQ_SKIP;
6604 +
6605 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6606 +               mnt == current->fs->root.mnt) {
6607 +               seq_puts(m, "/dev/root / ");
6608 +               goto type;
6609 +       }
6610 +
6611         if (sb->s_op->show_devname) {
6612                 err = sb->s_op->show_devname(m, mnt_path.dentry);
6613                 if (err)
6614 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6615         seq_putc(m, ' ');
6616         seq_path(m, &mnt_path, " \t\n\\");
6617         seq_putc(m, ' ');
6618 +type:
6619         show_type(m, sb);
6620         seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6621         err = show_sb_opts(m, sb);
6622 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6623         struct path root = p->root;
6624         int err = 0;
6625  
6626 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6627 +               return SEQ_SKIP;
6628 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6629 +               return SEQ_SKIP;
6630 +
6631         seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6632                    MAJOR(sb->s_dev), MINOR(sb->s_dev));
6633         if (sb->s_op->show_path)
6634 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6635         struct super_block *sb = mnt_path.dentry->d_sb;
6636         int err = 0;
6637  
6638 +       if (vx_flags(VXF_HIDE_MOUNT, 0))
6639 +               return SEQ_SKIP;
6640 +       if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6641 +               return SEQ_SKIP;
6642 +
6643 +       if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6644 +               mnt == current->fs->root.mnt) {
6645 +               seq_puts(m, "device /dev/root mounted on / ");
6646 +               goto type;
6647 +       }
6648 +
6649         /* device */
6650         if (sb->s_op->show_devname) {
6651                 seq_puts(m, "device ");
6652 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6653         seq_puts(m, " mounted on ");
6654         seq_path(m, &mnt_path, " \t\n\\");
6655         seq_putc(m, ' ');
6656 -
6657 +type:
6658         /* file system type */
6659         seq_puts(m, "with fstype ");
6660         show_type(m, sb);
6661 diff -NurpP --minimal linux-3.10.40/fs/quota/dquot.c linux-3.10.40-vs2.3.6.8/fs/quota/dquot.c
6662 --- linux-3.10.40/fs/quota/dquot.c      2014-05-20 04:09:40.000000000 +0000
6663 +++ linux-3.10.40-vs2.3.6.8/fs/quota/dquot.c    2014-03-12 13:18:32.000000000 +0000
6664 @@ -1593,6 +1593,9 @@ int __dquot_alloc_space(struct inode *in
6665         struct dquot **dquots = inode->i_dquot;
6666         int reserve = flags & DQUOT_SPACE_RESERVE;
6667  
6668 +       if ((ret = dl_alloc_space(inode, number)))
6669 +               return ret;
6670 +
6671         /*
6672          * First test before acquiring mutex - solves deadlocks when we
6673          * re-enter the quota code and are already holding the mutex
6674 @@ -1648,6 +1651,9 @@ int dquot_alloc_inode(const struct inode
6675         struct dquot_warn warn[MAXQUOTAS];
6676         struct dquot * const *dquots = inode->i_dquot;
6677  
6678 +       if ((ret = dl_alloc_inode(inode)))
6679 +               return ret;
6680 +
6681         /* First test before acquiring mutex - solves deadlocks when we
6682           * re-enter the quota code and are already holding the mutex */
6683         if (!dquot_active(inode))
6684 @@ -1719,6 +1725,8 @@ void __dquot_free_space(struct inode *in
6685         struct dquot **dquots = inode->i_dquot;
6686         int reserve = flags & DQUOT_SPACE_RESERVE;
6687  
6688 +       dl_free_space(inode, number);
6689 +
6690         /* First test before acquiring mutex - solves deadlocks when we
6691           * re-enter the quota code and are already holding the mutex */
6692         if (!dquot_active(inode)) {
6693 @@ -1763,6 +1771,8 @@ void dquot_free_inode(const struct inode
6694         struct dquot_warn warn[MAXQUOTAS];
6695         struct dquot * const *dquots = inode->i_dquot;
6696  
6697 +       dl_free_inode(inode);
6698 +
6699         /* First test before acquiring mutex - solves deadlocks when we
6700           * re-enter the quota code and are already holding the mutex */
6701         if (!dquot_active(inode))
6702 diff -NurpP --minimal linux-3.10.40/fs/quota/quota.c linux-3.10.40-vs2.3.6.8/fs/quota/quota.c
6703 --- linux-3.10.40/fs/quota/quota.c      2013-02-19 13:58:49.000000000 +0000
6704 +++ linux-3.10.40-vs2.3.6.8/fs/quota/quota.c    2013-08-22 20:30:00.000000000 +0000
6705 @@ -8,6 +8,7 @@
6706  #include <linux/fs.h>
6707  #include <linux/namei.h>
6708  #include <linux/slab.h>
6709 +#include <linux/vs_context.h>
6710  #include <asm/current.h>
6711  #include <linux/uaccess.h>
6712  #include <linux/kernel.h>
6713 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6714                         break;
6715                 /*FALLTHROUGH*/
6716         default:
6717 -               if (!capable(CAP_SYS_ADMIN))
6718 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6719                         return -EPERM;
6720         }
6721  
6722 @@ -309,6 +310,46 @@ static int do_quotactl(struct super_bloc
6723  
6724  #ifdef CONFIG_BLOCK
6725  
6726 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6727 +
6728 +#include <linux/vroot.h>
6729 +#include <linux/major.h>
6730 +#include <linux/module.h>
6731 +#include <linux/kallsyms.h>
6732 +#include <linux/vserver/debug.h>
6733 +
6734 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6735 +
6736 +static DEFINE_SPINLOCK(vroot_grb_lock);
6737 +
6738 +int register_vroot_grb(vroot_grb_func *func) {
6739 +       int ret = -EBUSY;
6740 +
6741 +       spin_lock(&vroot_grb_lock);
6742 +       if (!vroot_get_real_bdev) {
6743 +               vroot_get_real_bdev = func;
6744 +               ret = 0;
6745 +       }
6746 +       spin_unlock(&vroot_grb_lock);
6747 +       return ret;
6748 +}
6749 +EXPORT_SYMBOL(register_vroot_grb);
6750 +
6751 +int unregister_vroot_grb(vroot_grb_func *func) {
6752 +       int ret = -EINVAL;
6753 +
6754 +       spin_lock(&vroot_grb_lock);
6755 +       if (vroot_get_real_bdev) {
6756 +               vroot_get_real_bdev = NULL;
6757 +               ret = 0;
6758 +       }
6759 +       spin_unlock(&vroot_grb_lock);
6760 +       return ret;
6761 +}
6762 +EXPORT_SYMBOL(unregister_vroot_grb);
6763 +
6764 +#endif
6765 +
6766  /* Return 1 if 'cmd' will block on frozen filesystem */
6767  static int quotactl_cmd_write(int cmd)
6768  {
6769 @@ -343,6 +384,22 @@ static struct super_block *quotactl_bloc
6770         putname(tmp);
6771         if (IS_ERR(bdev))
6772                 return ERR_CAST(bdev);
6773 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6774 +       if (bdev && bdev->bd_inode &&
6775 +               imajor(bdev->bd_inode) == VROOT_MAJOR) {
6776 +               struct block_device *bdnew = (void *)-EINVAL;
6777 +
6778 +               if (vroot_get_real_bdev)
6779 +                       bdnew = vroot_get_real_bdev(bdev);
6780 +               else
6781 +                       vxdprintk(VXD_CBIT(misc, 0),
6782 +                                       "vroot_get_real_bdev not set");
6783 +               bdput(bdev);
6784 +               if (IS_ERR(bdnew))
6785 +                       return ERR_PTR(PTR_ERR(bdnew));
6786 +               bdev = bdnew;
6787 +       }
6788 +#endif
6789         if (quotactl_cmd_write(cmd))
6790                 sb = get_super_thawed(bdev);
6791         else
6792 diff -NurpP --minimal linux-3.10.40/fs/stat.c linux-3.10.40-vs2.3.6.8/fs/stat.c
6793 --- linux-3.10.40/fs/stat.c     2013-05-31 13:45:25.000000000 +0000
6794 +++ linux-3.10.40-vs2.3.6.8/fs/stat.c   2013-08-22 20:30:00.000000000 +0000
6795 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6796         stat->nlink = inode->i_nlink;
6797         stat->uid = inode->i_uid;
6798         stat->gid = inode->i_gid;
6799 +       stat->tag = inode->i_tag;
6800         stat->rdev = inode->i_rdev;
6801         stat->size = i_size_read(inode);
6802         stat->atime = inode->i_atime;
6803 diff -NurpP --minimal linux-3.10.40/fs/statfs.c linux-3.10.40-vs2.3.6.8/fs/statfs.c
6804 --- linux-3.10.40/fs/statfs.c   2014-05-20 04:09:40.000000000 +0000
6805 +++ linux-3.10.40-vs2.3.6.8/fs/statfs.c 2013-11-13 17:17:16.000000000 +0000
6806 @@ -7,6 +7,8 @@
6807  #include <linux/statfs.h>
6808  #include <linux/security.h>
6809  #include <linux/uaccess.h>
6810 +#include <linux/vs_base.h>
6811 +#include <linux/vs_dlimit.h>
6812  #include "internal.h"
6813  
6814  static int flags_by_mnt(int mnt_flags)
6815 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6816         retval = dentry->d_sb->s_op->statfs(dentry, buf);
6817         if (retval == 0 && buf->f_frsize == 0)
6818                 buf->f_frsize = buf->f_bsize;
6819 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
6820 +               vx_vsi_statfs(dentry->d_sb, buf);
6821         return retval;
6822  }
6823  
6824 diff -NurpP --minimal linux-3.10.40/fs/super.c linux-3.10.40-vs2.3.6.8/fs/super.c
6825 --- linux-3.10.40/fs/super.c    2014-05-20 04:09:40.000000000 +0000
6826 +++ linux-3.10.40-vs2.3.6.8/fs/super.c  2013-11-13 17:17:16.000000000 +0000
6827 @@ -34,6 +34,8 @@
6828  #include <linux/cleancache.h>
6829  #include <linux/fsnotify.h>
6830  #include <linux/lockdep.h>
6831 +#include <linux/magic.h>
6832 +#include <linux/vs_context.h>
6833  #include "internal.h"
6834  
6835  
6836 @@ -1112,6 +1114,13 @@ mount_fs(struct file_system_type *type,
6837         WARN_ON(sb->s_bdi == &default_backing_dev_info);
6838         sb->s_flags |= MS_BORN;
6839  
6840 +       error = -EPERM;
6841 +       if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6842 +               !sb->s_bdev &&
6843 +               (sb->s_magic != PROC_SUPER_MAGIC) &&
6844 +               (sb->s_magic != DEVPTS_SUPER_MAGIC))
6845 +               goto out_sb;
6846 +
6847         error = security_sb_kern_mount(sb, flags, secdata);
6848         if (error)
6849                 goto out_sb;
6850 diff -NurpP --minimal linux-3.10.40/fs/sysfs/mount.c linux-3.10.40-vs2.3.6.8/fs/sysfs/mount.c
6851 --- linux-3.10.40/fs/sysfs/mount.c      2013-05-31 13:45:25.000000000 +0000
6852 +++ linux-3.10.40-vs2.3.6.8/fs/sysfs/mount.c    2013-08-22 20:30:00.000000000 +0000
6853 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6854  
6855         sb->s_blocksize = PAGE_CACHE_SIZE;
6856         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6857 -       sb->s_magic = SYSFS_MAGIC;
6858 +       sb->s_magic = SYSFS_SUPER_MAGIC;
6859         sb->s_op = &sysfs_ops;
6860         sb->s_time_gran = 1;
6861  
6862 diff -NurpP --minimal linux-3.10.40/fs/utimes.c linux-3.10.40-vs2.3.6.8/fs/utimes.c
6863 --- linux-3.10.40/fs/utimes.c   2013-02-19 13:58:49.000000000 +0000
6864 +++ linux-3.10.40-vs2.3.6.8/fs/utimes.c 2013-08-22 20:30:00.000000000 +0000
6865 @@ -8,6 +8,8 @@
6866  #include <linux/stat.h>
6867  #include <linux/utime.h>
6868  #include <linux/syscalls.h>
6869 +#include <linux/mount.h>
6870 +#include <linux/vs_cowbl.h>
6871  #include <asm/uaccess.h>
6872  #include <asm/unistd.h>
6873  
6874 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
6875  {
6876         int error;
6877         struct iattr newattrs;
6878 -       struct inode *inode = path->dentry->d_inode;
6879 +       struct inode *inode;
6880 +
6881 +       error = cow_check_and_break(path);
6882 +       if (error)
6883 +               goto out;
6884  
6885         error = mnt_want_write(path->mnt);
6886         if (error)
6887                 goto out;
6888  
6889 +       inode = path->dentry->d_inode;
6890 +
6891         if (times && times[0].tv_nsec == UTIME_NOW &&
6892                      times[1].tv_nsec == UTIME_NOW)
6893                 times = NULL;
6894 diff -NurpP --minimal linux-3.10.40/fs/xattr.c linux-3.10.40-vs2.3.6.8/fs/xattr.c
6895 --- linux-3.10.40/fs/xattr.c    2013-02-19 13:58:49.000000000 +0000
6896 +++ linux-3.10.40-vs2.3.6.8/fs/xattr.c  2013-08-22 20:30:00.000000000 +0000
6897 @@ -21,6 +21,7 @@
6898  #include <linux/audit.h>
6899  #include <linux/vmalloc.h>
6900  #include <linux/posix_acl_xattr.h>
6901 +#include <linux/mount.h>
6902  
6903  #include <asm/uaccess.h>
6904  
6905 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6906          * The trusted.* namespace can only be accessed by privileged users.
6907          */
6908         if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6909 -               if (!capable(CAP_SYS_ADMIN))
6910 +               if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6911                         return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6912                 return 0;
6913         }
6914 diff -NurpP --minimal linux-3.10.40/fs/xfs/xfs_dinode.h linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_dinode.h
6915 --- linux-3.10.40/fs/xfs/xfs_dinode.h   2013-07-14 17:01:29.000000000 +0000
6916 +++ linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_dinode.h 2013-08-22 20:30:00.000000000 +0000
6917 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
6918         __be32          di_nlink;       /* number of links to file */
6919         __be16          di_projid_lo;   /* lower part of owner's project id */
6920         __be16          di_projid_hi;   /* higher part owner's project id */
6921 -       __u8            di_pad[6];      /* unused, zeroed space */
6922 +       __u8            di_pad[2];      /* unused, zeroed space */
6923 +       __be16          di_tag;         /* context tagging */
6924 +       __be16          di_vflags;      /* vserver specific flags */
6925         __be16          di_flushiter;   /* incremented on flush */
6926         xfs_timestamp_t di_atime;       /* time last accessed */
6927         xfs_timestamp_t di_mtime;       /* time last modified */
6928 @@ -209,6 +211,8 @@ static inline void xfs_dinode_put_rdev(s
6929  #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
6930  #define XFS_DIFLAG_NODEFRAG_BIT     13 /* do not reorganize/defragment */
6931  #define XFS_DIFLAG_FILESTREAM_BIT   14  /* use filestream allocator */
6932 +#define XFS_DIFLAG_IXUNLINK_BIT     15 /* Immutable inver on unlink */
6933 +
6934  #define XFS_DIFLAG_REALTIME      (1 << XFS_DIFLAG_REALTIME_BIT)
6935  #define XFS_DIFLAG_PREALLOC      (1 << XFS_DIFLAG_PREALLOC_BIT)
6936  #define XFS_DIFLAG_NEWRTBM       (1 << XFS_DIFLAG_NEWRTBM_BIT)
6937 @@ -224,6 +228,7 @@ static inline void xfs_dinode_put_rdev(s
6938  #define XFS_DIFLAG_EXTSZINHERIT  (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
6939  #define XFS_DIFLAG_NODEFRAG      (1 << XFS_DIFLAG_NODEFRAG_BIT)
6940  #define XFS_DIFLAG_FILESTREAM    (1 << XFS_DIFLAG_FILESTREAM_BIT)
6941 +#define XFS_DIFLAG_IXUNLINK      (1 << XFS_DIFLAG_IXUNLINK_BIT)
6942  
6943  #ifdef CONFIG_XFS_RT
6944  #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
6945 @@ -236,6 +241,10 @@ static inline void xfs_dinode_put_rdev(s
6946          XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
6947          XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
6948          XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
6949 -        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
6950 +        XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
6951 +        XFS_DIFLAG_IXUNLINK)
6952 +
6953 +#define XFS_DIVFLAG_BARRIER    0x01
6954 +#define XFS_DIVFLAG_COW                0x02
6955  
6956  #endif /* __XFS_DINODE_H__ */
6957 diff -NurpP --minimal linux-3.10.40/fs/xfs/xfs_fs.h linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_fs.h
6958 --- linux-3.10.40/fs/xfs/xfs_fs.h       2013-07-14 17:01:29.000000000 +0000
6959 +++ linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_fs.h     2013-08-22 20:30:00.000000000 +0000
6960 @@ -67,6 +67,9 @@ struct fsxattr {
6961  #define XFS_XFLAG_EXTSZINHERIT 0x00001000      /* inherit inode extent size */
6962  #define XFS_XFLAG_NODEFRAG     0x00002000      /* do not defragment */
6963  #define XFS_XFLAG_FILESTREAM   0x00004000      /* use filestream allocator */
6964 +#define XFS_XFLAG_IXUNLINK     0x00008000      /* immutable invert on unlink */
6965 +#define XFS_XFLAG_BARRIER      0x10000000      /* chroot() barrier */
6966 +#define XFS_XFLAG_COW          0x20000000      /* copy on write mark */
6967  #define XFS_XFLAG_HASATTR      0x80000000      /* no DIFLAG for this   */
6968  
6969  /*
6970 @@ -304,7 +307,8 @@ typedef struct xfs_bstat {
6971  #define        bs_projid       bs_projid_lo    /* (previously just bs_projid)  */
6972         __u16           bs_forkoff;     /* inode fork offset in bytes   */
6973         __u16           bs_projid_hi;   /* higher part of project id    */
6974 -       unsigned char   bs_pad[10];     /* pad space, unused            */
6975 +       unsigned char   bs_pad[8];      /* pad space, unused            */
6976 +       __u16           bs_tag;         /* context tagging              */
6977         __u32           bs_dmevmask;    /* DMIG event mask              */
6978         __u16           bs_dmstate;     /* DMIG state info              */
6979         __u16           bs_aextents;    /* attribute number of extents  */
6980 diff -NurpP --minimal linux-3.10.40/fs/xfs/xfs_ialloc.c linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_ialloc.c
6981 --- linux-3.10.40/fs/xfs/xfs_ialloc.c   2013-07-14 17:01:29.000000000 +0000
6982 +++ linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_ialloc.c 2013-08-22 20:30:00.000000000 +0000
6983 @@ -39,7 +39,6 @@
6984  #include "xfs_cksum.h"
6985  #include "xfs_buf_item.h"
6986  
6987 -
6988  /*
6989   * Allocation group level functions.
6990   */
6991 diff -NurpP --minimal linux-3.10.40/fs/xfs/xfs_inode.c linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_inode.c
6992 --- linux-3.10.40/fs/xfs/xfs_inode.c    2013-07-14 17:01:29.000000000 +0000
6993 +++ linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_inode.c  2013-08-22 21:50:34.000000000 +0000
6994 @@ -16,6 +16,7 @@
6995   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
6996   */
6997  #include <linux/log2.h>
6998 +#include <linux/vs_tag.h>
6999  
7000  #include "xfs.h"
7001  #include "xfs_fs.h"
7002 @@ -836,15 +837,25 @@ xfs_iformat_btree(
7003  STATIC void
7004  xfs_dinode_from_disk(
7005         xfs_icdinode_t          *to,
7006 -       xfs_dinode_t            *from)
7007 +       xfs_dinode_t            *from,
7008 +       int                     tagged)
7009  {
7010 +       uint32_t uid, gid, tag;
7011 +
7012         to->di_magic = be16_to_cpu(from->di_magic);
7013         to->di_mode = be16_to_cpu(from->di_mode);
7014         to->di_version = from ->di_version;
7015         to->di_format = from->di_format;
7016         to->di_onlink = be16_to_cpu(from->di_onlink);
7017 -       to->di_uid = be32_to_cpu(from->di_uid);
7018 -       to->di_gid = be32_to_cpu(from->di_gid);
7019 +
7020 +       uid = be32_to_cpu(from->di_uid);
7021 +       gid = be32_to_cpu(from->di_gid);
7022 +       tag = be16_to_cpu(from->di_tag);
7023 +
7024 +       to->di_uid = INOTAG_UID(tagged, uid, gid);
7025 +       to->di_gid = INOTAG_GID(tagged, uid, gid);
7026 +       to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7027 +
7028         to->di_nlink = be32_to_cpu(from->di_nlink);
7029         to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7030         to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7031 @@ -866,6 +877,7 @@ xfs_dinode_from_disk(
7032         to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7033         to->di_dmstate  = be16_to_cpu(from->di_dmstate);
7034         to->di_flags    = be16_to_cpu(from->di_flags);
7035 +       to->di_vflags   = be16_to_cpu(from->di_vflags);
7036         to->di_gen      = be32_to_cpu(from->di_gen);
7037  
7038         if (to->di_version == 3) {
7039 @@ -883,15 +895,19 @@ xfs_dinode_from_disk(
7040  void
7041  xfs_dinode_to_disk(
7042         xfs_dinode_t            *to,
7043 -       xfs_icdinode_t          *from)
7044 +       xfs_icdinode_t          *from,
7045 +       int                     tagged)
7046  {
7047         to->di_magic = cpu_to_be16(from->di_magic);
7048         to->di_mode = cpu_to_be16(from->di_mode);
7049         to->di_version = from ->di_version;
7050         to->di_format = from->di_format;
7051         to->di_onlink = cpu_to_be16(from->di_onlink);
7052 -       to->di_uid = cpu_to_be32(from->di_uid);
7053 -       to->di_gid = cpu_to_be32(from->di_gid);
7054 +
7055 +       to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7056 +       to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7057 +       to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7058 +
7059         to->di_nlink = cpu_to_be32(from->di_nlink);
7060         to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7061         to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7062 @@ -913,6 +929,7 @@ xfs_dinode_to_disk(
7063         to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7064         to->di_dmstate = cpu_to_be16(from->di_dmstate);
7065         to->di_flags = cpu_to_be16(from->di_flags);
7066 +       to->di_vflags = cpu_to_be16(from->di_vflags);
7067         to->di_gen = cpu_to_be32(from->di_gen);
7068  
7069         if (from->di_version == 3) {
7070 @@ -929,7 +946,8 @@ xfs_dinode_to_disk(
7071  
7072  STATIC uint
7073  _xfs_dic2xflags(
7074 -       __uint16_t              di_flags)
7075 +       __uint16_t              di_flags,
7076 +       __uint16_t              di_vflags)
7077  {
7078         uint                    flags = 0;
7079  
7080 @@ -940,6 +958,8 @@ _xfs_dic2xflags(
7081                         flags |= XFS_XFLAG_PREALLOC;
7082                 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7083                         flags |= XFS_XFLAG_IMMUTABLE;
7084 +               if (di_flags & XFS_DIFLAG_IXUNLINK)
7085 +                       flags |= XFS_XFLAG_IXUNLINK;
7086                 if (di_flags & XFS_DIFLAG_APPEND)
7087                         flags |= XFS_XFLAG_APPEND;
7088                 if (di_flags & XFS_DIFLAG_SYNC)
7089 @@ -964,6 +984,10 @@ _xfs_dic2xflags(
7090                         flags |= XFS_XFLAG_FILESTREAM;
7091         }
7092  
7093 +       if (di_vflags & XFS_DIVFLAG_BARRIER)
7094 +               flags |= FS_BARRIER_FL;
7095 +       if (di_vflags & XFS_DIVFLAG_COW)
7096 +               flags |= FS_COW_FL;
7097         return flags;
7098  }
7099  
7100 @@ -973,7 +997,7 @@ xfs_ip2xflags(
7101  {
7102         xfs_icdinode_t          *dic = &ip->i_d;
7103  
7104 -       return _xfs_dic2xflags(dic->di_flags) |
7105 +       return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7106                                 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7107  }
7108  
7109 @@ -981,7 +1005,8 @@ uint
7110  xfs_dic2xflags(
7111         xfs_dinode_t            *dip)
7112  {
7113 -       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7114 +       return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7115 +                               be16_to_cpu(dip->di_vflags)) |
7116                                 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7117  }
7118  
7119 @@ -1072,7 +1097,8 @@ xfs_iread(
7120          * Otherwise, just get the truly permanent information.
7121          */
7122         if (dip->di_mode) {
7123 -               xfs_dinode_from_disk(&ip->i_d, dip);
7124 +               xfs_dinode_from_disk(&ip->i_d, dip,
7125 +                       mp->m_flags & XFS_MOUNT_TAGGED);
7126                 error = xfs_iformat(ip, dip);
7127                 if (error)  {
7128  #ifdef DEBUG
7129 @@ -1270,6 +1296,7 @@ xfs_ialloc(
7130         ASSERT(ip->i_d.di_nlink == nlink);
7131         ip->i_d.di_uid = current_fsuid();
7132         ip->i_d.di_gid = current_fsgid();
7133 +       ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7134         xfs_set_projid(ip, prid);
7135         memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7136  
7137 @@ -1329,6 +1356,7 @@ xfs_ialloc(
7138         ip->i_d.di_dmevmask = 0;
7139         ip->i_d.di_dmstate = 0;
7140         ip->i_d.di_flags = 0;
7141 +       ip->i_d.di_vflags = 0;
7142  
7143         if (ip->i_d.di_version == 3) {
7144                 ASSERT(ip->i_d.di_ino == ino);
7145 @@ -2052,6 +2080,7 @@ xfs_ifree(
7146         }
7147         ip->i_d.di_mode = 0;            /* mark incore inode as free */
7148         ip->i_d.di_flags = 0;
7149 +       ip->i_d.di_vflags = 0;
7150         ip->i_d.di_dmevmask = 0;
7151         ip->i_d.di_forkoff = 0;         /* mark the attr fork not in use */
7152         ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7153 @@ -2219,7 +2248,6 @@ xfs_iroot_realloc(
7154         return;
7155  }
7156  
7157 -
7158  /*
7159   * This is called when the amount of space needed for if_data
7160   * is increased or decreased.  The change in size is indicated by
7161 @@ -2899,7 +2927,8 @@ xfs_iflush_int(
7162          * because if the inode is dirty at all the core must
7163          * be.
7164          */
7165 -       xfs_dinode_to_disk(dip, &ip->i_d);
7166 +       xfs_dinode_to_disk(dip, &ip->i_d,
7167 +               mp->m_flags & XFS_MOUNT_TAGGED);
7168  
7169         /* Wrap, we never let the log put out DI_MAX_FLUSH */
7170         if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7171 diff -NurpP --minimal linux-3.10.40/fs/xfs/xfs_inode.h linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_inode.h
7172 --- linux-3.10.40/fs/xfs/xfs_inode.h    2013-07-14 17:01:30.000000000 +0000
7173 +++ linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_inode.h  2013-08-22 20:30:00.000000000 +0000
7174 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7175         __uint32_t      di_nlink;       /* number of links to file */
7176         __uint16_t      di_projid_lo;   /* lower part of owner's project id */
7177         __uint16_t      di_projid_hi;   /* higher part of owner's project id */
7178 -       __uint8_t       di_pad[6];      /* unused, zeroed space */
7179 +       __uint8_t       di_pad[2];      /* unused, zeroed space */
7180 +       __uint16_t      di_tag;         /* context tagging */
7181 +       __uint16_t      di_vflags;      /* vserver specific flags */
7182         __uint16_t      di_flushiter;   /* incremented on flush */
7183         xfs_ictimestamp_t di_atime;     /* time last accessed */
7184         xfs_ictimestamp_t di_mtime;     /* time last modified */
7185 @@ -583,7 +585,7 @@ int         xfs_iread(struct xfs_mount *, struc
7186                           struct xfs_inode *, uint);
7187  void           xfs_dinode_calc_crc(struct xfs_mount *, struct xfs_dinode *);
7188  void           xfs_dinode_to_disk(struct xfs_dinode *,
7189 -                                  struct xfs_icdinode *);
7190 +                                  struct xfs_icdinode *, int);
7191  void           xfs_idestroy_fork(struct xfs_inode *, int);
7192  void           xfs_idata_realloc(struct xfs_inode *, int, int);
7193  void           xfs_iroot_realloc(struct xfs_inode *, int, int);
7194 diff -NurpP --minimal linux-3.10.40/fs/xfs/xfs_ioctl.c linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_ioctl.c
7195 --- linux-3.10.40/fs/xfs/xfs_ioctl.c    2014-05-20 04:09:40.000000000 +0000
7196 +++ linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_ioctl.c  2013-12-23 17:42:40.000000000 +0000
7197 @@ -26,7 +26,7 @@
7198  #include "xfs_bmap_btree.h"
7199  #include "xfs_dinode.h"
7200  #include "xfs_inode.h"
7201 -#include "xfs_ioctl.h"
7202 +// #include "xfs_ioctl.h"
7203  #include "xfs_rtalloc.h"
7204  #include "xfs_itable.h"
7205  #include "xfs_error.h"
7206 @@ -770,6 +770,10 @@ xfs_merge_ioc_xflags(
7207                 xflags |= XFS_XFLAG_IMMUTABLE;
7208         else
7209                 xflags &= ~XFS_XFLAG_IMMUTABLE;
7210 +       if (flags & FS_IXUNLINK_FL)
7211 +               xflags |= XFS_XFLAG_IXUNLINK;
7212 +       else
7213 +               xflags &= ~XFS_XFLAG_IXUNLINK;
7214         if (flags & FS_APPEND_FL)
7215                 xflags |= XFS_XFLAG_APPEND;
7216         else
7217 @@ -798,6 +802,8 @@ xfs_di2lxflags(
7218  
7219         if (di_flags & XFS_DIFLAG_IMMUTABLE)
7220                 flags |= FS_IMMUTABLE_FL;
7221 +       if (di_flags & XFS_DIFLAG_IXUNLINK)
7222 +               flags |= FS_IXUNLINK_FL;
7223         if (di_flags & XFS_DIFLAG_APPEND)
7224                 flags |= FS_APPEND_FL;
7225         if (di_flags & XFS_DIFLAG_SYNC)
7226 @@ -858,6 +864,8 @@ xfs_set_diflags(
7227         di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7228         if (xflags & XFS_XFLAG_IMMUTABLE)
7229                 di_flags |= XFS_DIFLAG_IMMUTABLE;
7230 +       if (xflags & XFS_XFLAG_IXUNLINK)
7231 +               di_flags |= XFS_DIFLAG_IXUNLINK;
7232         if (xflags & XFS_XFLAG_APPEND)
7233                 di_flags |= XFS_DIFLAG_APPEND;
7234         if (xflags & XFS_XFLAG_SYNC)
7235 @@ -900,6 +908,10 @@ xfs_diflags_to_linux(
7236                 inode->i_flags |= S_IMMUTABLE;
7237         else
7238                 inode->i_flags &= ~S_IMMUTABLE;
7239 +       if (xflags & XFS_XFLAG_IXUNLINK)
7240 +               inode->i_flags |= S_IXUNLINK;
7241 +       else
7242 +               inode->i_flags &= ~S_IXUNLINK;
7243         if (xflags & XFS_XFLAG_APPEND)
7244                 inode->i_flags |= S_APPEND;
7245         else
7246 @@ -1404,10 +1416,18 @@ xfs_file_ioctl(
7247         case XFS_IOC_FSGETXATTRA:
7248                 return xfs_ioc_fsgetxattr(ip, 1, arg);
7249         case XFS_IOC_FSSETXATTR:
7250 +               if (IS_BARRIER(inode)) {
7251 +                       vxwprintk_task(1, "messing with the barrier.");
7252 +                       return -XFS_ERROR(EACCES);
7253 +               }
7254                 return xfs_ioc_fssetxattr(ip, filp, arg);
7255         case XFS_IOC_GETXFLAGS:
7256                 return xfs_ioc_getxflags(ip, arg);
7257         case XFS_IOC_SETXFLAGS:
7258 +               if (IS_BARRIER(inode)) {
7259 +                       vxwprintk_task(1, "messing with the barrier.");
7260 +                       return -XFS_ERROR(EACCES);
7261 +               }
7262                 return xfs_ioc_setxflags(ip, filp, arg);
7263  
7264         case XFS_IOC_FSSETDM: {
7265 diff -NurpP --minimal linux-3.10.40/fs/xfs/xfs_ioctl.h linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_ioctl.h
7266 --- linux-3.10.40/fs/xfs/xfs_ioctl.h    2012-12-11 03:30:57.000000000 +0000
7267 +++ linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_ioctl.h  2013-08-22 20:30:00.000000000 +0000
7268 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7269         void __user             *uhandle,
7270         u32                     hlen);
7271  
7272 +extern int
7273 +xfs_sync_flags(
7274 +       struct inode            *inode,
7275 +       int                     flags,
7276 +       int                     vflags);
7277 +
7278  extern long
7279  xfs_file_ioctl(
7280         struct file             *filp,
7281 diff -NurpP --minimal linux-3.10.40/fs/xfs/xfs_iops.c linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_iops.c
7282 --- linux-3.10.40/fs/xfs/xfs_iops.c     2013-07-14 17:01:30.000000000 +0000
7283 +++ linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_iops.c   2013-08-22 20:30:00.000000000 +0000
7284 @@ -28,6 +28,7 @@
7285  #include "xfs_bmap_btree.h"
7286  #include "xfs_dinode.h"
7287  #include "xfs_inode.h"
7288 +#include "xfs_ioctl.h"
7289  #include "xfs_bmap.h"
7290  #include "xfs_rtalloc.h"
7291  #include "xfs_error.h"
7292 @@ -47,6 +48,7 @@
7293  #include <linux/security.h>
7294  #include <linux/fiemap.h>
7295  #include <linux/slab.h>
7296 +#include <linux/vs_tag.h>
7297  
7298  static int
7299  xfs_initxattrs(
7300 @@ -422,6 +424,7 @@ xfs_vn_getattr(
7301         stat->nlink = ip->i_d.di_nlink;
7302         stat->uid = ip->i_d.di_uid;
7303         stat->gid = ip->i_d.di_gid;
7304 +       stat->tag = ip->i_d.di_tag;
7305         stat->ino = ip->i_ino;
7306         stat->atime = inode->i_atime;
7307         stat->mtime = inode->i_mtime;
7308 @@ -1054,6 +1057,7 @@ static const struct inode_operations xfs
7309         .listxattr              = xfs_vn_listxattr,
7310         .fiemap                 = xfs_vn_fiemap,
7311         .update_time            = xfs_vn_update_time,
7312 +       .sync_flags             = xfs_sync_flags,
7313  };
7314  
7315  static const struct inode_operations xfs_dir_inode_operations = {
7316 @@ -1080,6 +1084,7 @@ static const struct inode_operations xfs
7317         .removexattr            = generic_removexattr,
7318         .listxattr              = xfs_vn_listxattr,
7319         .update_time            = xfs_vn_update_time,
7320 +       .sync_flags             = xfs_sync_flags,
7321  };
7322  
7323  static const struct inode_operations xfs_dir_ci_inode_operations = {
7324 @@ -1131,6 +1136,10 @@ xfs_diflags_to_iflags(
7325                 inode->i_flags |= S_IMMUTABLE;
7326         else
7327                 inode->i_flags &= ~S_IMMUTABLE;
7328 +       if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7329 +               inode->i_flags |= S_IXUNLINK;
7330 +       else
7331 +               inode->i_flags &= ~S_IXUNLINK;
7332         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7333                 inode->i_flags |= S_APPEND;
7334         else
7335 @@ -1143,6 +1152,15 @@ xfs_diflags_to_iflags(
7336                 inode->i_flags |= S_NOATIME;
7337         else
7338                 inode->i_flags &= ~S_NOATIME;
7339 +
7340 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7341 +               inode->i_vflags |= V_BARRIER;
7342 +       else
7343 +               inode->i_vflags &= ~V_BARRIER;
7344 +       if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7345 +               inode->i_vflags |= V_COW;
7346 +       else
7347 +               inode->i_vflags &= ~V_COW;
7348  }
7349  
7350  /*
7351 @@ -1174,6 +1192,7 @@ xfs_setup_inode(
7352         set_nlink(inode, ip->i_d.di_nlink);
7353         inode->i_uid    = ip->i_d.di_uid;
7354         inode->i_gid    = ip->i_d.di_gid;
7355 +       inode->i_tag    = ip->i_d.di_tag;
7356  
7357         switch (inode->i_mode & S_IFMT) {
7358         case S_IFBLK:
7359 diff -NurpP --minimal linux-3.10.40/fs/xfs/xfs_itable.c linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_itable.c
7360 --- linux-3.10.40/fs/xfs/xfs_itable.c   2013-02-19 13:58:49.000000000 +0000
7361 +++ linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_itable.c 2013-08-22 20:30:00.000000000 +0000
7362 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
7363         buf->bs_mode = dic->di_mode;
7364         buf->bs_uid = dic->di_uid;
7365         buf->bs_gid = dic->di_gid;
7366 +       buf->bs_tag = dic->di_tag;
7367         buf->bs_size = dic->di_size;
7368         buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7369         buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7370 diff -NurpP --minimal linux-3.10.40/fs/xfs/xfs_linux.h linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_linux.h
7371 --- linux-3.10.40/fs/xfs/xfs_linux.h    2013-07-14 17:01:30.000000000 +0000
7372 +++ linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_linux.h  2013-08-22 20:30:00.000000000 +0000
7373 @@ -124,6 +124,7 @@
7374  
7375  #define current_cpu()          (raw_smp_processor_id())
7376  #define current_pid()          (current->pid)
7377 +#define current_fstag(vp)      (dx_current_fstag((vp)->i_sb))
7378  #define current_test_flags(f)  (current->flags & (f))
7379  #define current_set_flags_nested(sp, f)                \
7380                 (*(sp) = current->flags, current->flags |= (f))
7381 diff -NurpP --minimal linux-3.10.40/fs/xfs/xfs_log_recover.c linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_log_recover.c
7382 --- linux-3.10.40/fs/xfs/xfs_log_recover.c      2013-07-14 17:01:31.000000000 +0000
7383 +++ linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_log_recover.c    2013-08-22 21:48:01.000000000 +0000
7384 @@ -2662,7 +2662,7 @@ xlog_recover_inode_pass2(
7385         }
7386  
7387         /* The core is in in-core format */
7388 -       xfs_dinode_to_disk(dip, dicp);
7389 +       xfs_dinode_to_disk(dip, dicp, mp->m_flags & XFS_MOUNT_TAGGED);
7390  
7391         /* the rest is in on-disk format */
7392         if (item->ri_buf[1].i_len > isize) {
7393 diff -NurpP --minimal linux-3.10.40/fs/xfs/xfs_mount.h linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_mount.h
7394 --- linux-3.10.40/fs/xfs/xfs_mount.h    2013-07-14 17:01:31.000000000 +0000
7395 +++ linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_mount.h  2013-08-22 20:30:00.000000000 +0000
7396 @@ -253,6 +253,7 @@ typedef struct xfs_mount {
7397                                                    allocator */
7398  #define XFS_MOUNT_NOATTR2      (1ULL << 25)    /* disable use of attr2 format */
7399  
7400 +#define XFS_MOUNT_TAGGED       (1ULL << 31)    /* context tagging */
7401  
7402  /*
7403   * Default minimum read and write sizes.
7404 diff -NurpP --minimal linux-3.10.40/fs/xfs/xfs_super.c linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_super.c
7405 --- linux-3.10.40/fs/xfs/xfs_super.c    2013-07-14 17:01:31.000000000 +0000
7406 +++ linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_super.c  2013-08-22 20:30:00.000000000 +0000
7407 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7408  #define MNTOPT_NODELAYLOG  "nodelaylog"        /* Delayed logging disabled */
7409  #define MNTOPT_DISCARD    "discard"    /* Discard unused blocks */
7410  #define MNTOPT_NODISCARD   "nodiscard" /* Do not discard unused blocks */
7411 +#define MNTOPT_TAGXID  "tagxid"        /* context tagging for inodes */
7412 +#define MNTOPT_TAGGED  "tag"           /* context tagging for inodes */
7413 +#define MNTOPT_NOTAGTAG        "notag"         /* do not use context tagging */
7414  
7415  /*
7416   * Table driven mount option parser.
7417 @@ -126,6 +129,8 @@ enum {
7418         Opt_nobarrier,
7419         Opt_inode64,
7420         Opt_inode32,
7421 +       Opt_tag,
7422 +       Opt_notag,
7423         Opt_err
7424  };
7425  
7426 @@ -134,6 +139,9 @@ static const match_table_t tokens = {
7427         {Opt_nobarrier, "nobarrier"},
7428         {Opt_inode64, "inode64"},
7429         {Opt_inode32, "inode32"},
7430 +       {Opt_tag, "tagxid"},
7431 +       {Opt_tag, "tag"},
7432 +       {Opt_notag, "notag"},
7433         {Opt_err, NULL}
7434  };
7435  
7436 @@ -392,6 +400,19 @@ xfs_parseargs(
7437                 } else if (!strcmp(this_char, "irixsgid")) {
7438                         xfs_warn(mp,
7439         "irixsgid is now a sysctl(2) variable, option is deprecated.");
7440 +#ifndef CONFIG_TAGGING_NONE
7441 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7442 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7443 +               } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7444 +                       mp->m_flags &= ~XFS_MOUNT_TAGGED;
7445 +               } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7446 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7447 +#endif
7448 +#ifdef CONFIG_PROPAGATE
7449 +               } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7450 +                       /* use value */
7451 +                       mp->m_flags |= XFS_MOUNT_TAGGED;
7452 +#endif
7453                 } else {
7454                         xfs_warn(mp, "unknown mount option [%s].", this_char);
7455                         return EINVAL;
7456 @@ -1238,6 +1259,16 @@ xfs_fs_remount(
7457                 case Opt_inode32:
7458                         mp->m_maxagi = xfs_set_inode32(mp);
7459                         break;
7460 +               case Opt_tag:
7461 +                       if (!(sb->s_flags & MS_TAGGED)) {
7462 +                               printk(KERN_INFO
7463 +                                       "XFS: %s: tagging not permitted on remount.\n",
7464 +                                       sb->s_id);
7465 +                               return -EINVAL;
7466 +                       }
7467 +                       break;
7468 +               case Opt_notag:
7469 +                       break;
7470                 default:
7471                         /*
7472                          * Logically we would return an error here to prevent
7473 @@ -1469,6 +1500,9 @@ xfs_fs_fill_super(
7474         if (error)
7475                 goto out_free_sb;
7476  
7477 +       if (mp->m_flags & XFS_MOUNT_TAGGED)
7478 +               sb->s_flags |= MS_TAGGED;
7479 +
7480         /*
7481          * we must configure the block size in the superblock before we run the
7482          * full mount process as the mount process can lookup and cache inodes.
7483 diff -NurpP --minimal linux-3.10.40/fs/xfs/xfs_vnodeops.c linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_vnodeops.c
7484 --- linux-3.10.40/fs/xfs/xfs_vnodeops.c 2013-07-14 17:01:31.000000000 +0000
7485 +++ linux-3.10.40-vs2.3.6.8/fs/xfs/xfs_vnodeops.c       2013-08-22 20:30:00.000000000 +0000
7486 @@ -155,6 +155,77 @@ xfs_free_eofblocks(
7487         return error;
7488  }
7489  
7490 +
7491 +STATIC void
7492 +xfs_get_inode_flags(
7493 +       xfs_inode_t     *ip)
7494 +{
7495 +       struct inode    *inode = VFS_I(ip);
7496 +       unsigned int    flags = inode->i_flags;
7497 +       unsigned int    vflags = inode->i_vflags;
7498 +
7499 +       if (flags & S_IMMUTABLE)
7500 +               ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7501 +       else
7502 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7503 +       if (flags & S_IXUNLINK)
7504 +               ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7505 +       else
7506 +               ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7507 +
7508 +       if (vflags & V_BARRIER)
7509 +               ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7510 +       else
7511 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7512 +       if (vflags & V_COW)
7513 +               ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7514 +       else
7515 +               ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7516 +}
7517 +
7518 +int
7519 +xfs_sync_flags(
7520 +       struct inode            *inode,
7521 +       int                     flags,
7522 +       int                     vflags)
7523 +{
7524 +       struct xfs_inode        *ip = XFS_I(inode);
7525 +       struct xfs_mount        *mp = ip->i_mount;
7526 +       struct xfs_trans        *tp;
7527 +       unsigned int            lock_flags = 0;
7528 +       int                     code;
7529 +
7530 +       tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7531 +       code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7532 +       if (code)
7533 +               goto error_out;
7534 +
7535 +       xfs_ilock(ip, XFS_ILOCK_EXCL);
7536 +       xfs_trans_ijoin(tp, ip, 0);
7537 +
7538 +       inode->i_flags = flags;
7539 +       inode->i_vflags = vflags;
7540 +       xfs_get_inode_flags(ip);
7541 +
7542 +       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7543 +       xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7544 +
7545 +       XFS_STATS_INC(xs_ig_attrchg);
7546 +
7547 +       if (mp->m_flags & XFS_MOUNT_WSYNC)
7548 +               xfs_trans_set_sync(tp);
7549 +       code = xfs_trans_commit(tp, 0);
7550 +       xfs_iunlock(ip, XFS_ILOCK_EXCL);
7551 +       return code;
7552 +
7553 +error_out:
7554 +       xfs_trans_cancel(tp, 0);
7555 +       if (lock_flags)
7556 +               xfs_iunlock(ip, XFS_ILOCK_EXCL);
7557 +       return code;
7558 +}
7559 +
7560 +
7561  int
7562  xfs_release(
7563         xfs_inode_t     *ip)
7564 diff -NurpP --minimal linux-3.10.40/include/linux/cred.h linux-3.10.40-vs2.3.6.8/include/linux/cred.h
7565 --- linux-3.10.40/include/linux/cred.h  2013-02-19 13:58:50.000000000 +0000
7566 +++ linux-3.10.40-vs2.3.6.8/include/linux/cred.h        2013-08-22 20:30:00.000000000 +0000
7567 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
7568  extern int copy_creds(struct task_struct *, unsigned long);
7569  extern const struct cred *get_task_cred(struct task_struct *);
7570  extern struct cred *cred_alloc_blank(void);
7571 +extern struct cred *__prepare_creds(const struct cred *);
7572  extern struct cred *prepare_creds(void);
7573  extern struct cred *prepare_exec_creds(void);
7574  extern int commit_creds(struct cred *);
7575 @@ -196,6 +197,31 @@ static inline void validate_process_cred
7576  }
7577  #endif
7578  
7579 +static inline void set_cred_subscribers(struct cred *cred, int n)
7580 +{
7581 +#ifdef CONFIG_DEBUG_CREDENTIALS
7582 +       atomic_set(&cred->subscribers, n);
7583 +#endif
7584 +}
7585 +
7586 +static inline int read_cred_subscribers(const struct cred *cred)
7587 +{
7588 +#ifdef CONFIG_DEBUG_CREDENTIALS
7589 +       return atomic_read(&cred->subscribers);
7590 +#else
7591 +       return 0;
7592 +#endif
7593 +}
7594 +
7595 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7596 +{
7597 +#ifdef CONFIG_DEBUG_CREDENTIALS
7598 +       struct cred *cred = (struct cred *) _cred;
7599 +
7600 +       atomic_add(n, &cred->subscribers);
7601 +#endif
7602 +}
7603 +
7604  /**
7605   * get_new_cred - Get a reference on a new set of credentials
7606   * @cred: The new credentials to reference
7607 diff -NurpP --minimal linux-3.10.40/include/linux/devpts_fs.h linux-3.10.40-vs2.3.6.8/include/linux/devpts_fs.h
7608 --- linux-3.10.40/include/linux/devpts_fs.h     2013-02-19 13:58:50.000000000 +0000
7609 +++ linux-3.10.40-vs2.3.6.8/include/linux/devpts_fs.h   2013-08-22 20:30:00.000000000 +0000
7610 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7611  
7612  #endif
7613  
7614 -
7615  #endif /* _LINUX_DEVPTS_FS_H */
7616 diff -NurpP --minimal linux-3.10.40/include/linux/fs.h linux-3.10.40-vs2.3.6.8/include/linux/fs.h
7617 --- linux-3.10.40/include/linux/fs.h    2013-07-14 17:01:32.000000000 +0000
7618 +++ linux-3.10.40-vs2.3.6.8/include/linux/fs.h  2013-08-22 20:30:00.000000000 +0000
7619 @@ -211,6 +211,7 @@ typedef void (dio_iodone_t)(struct kiocb
7620  #define ATTR_KILL_PRIV (1 << 14)
7621  #define ATTR_OPEN      (1 << 15) /* Truncating from open(O_TRUNC) */
7622  #define ATTR_TIMES_SET (1 << 16)
7623 +#define ATTR_TAG       (1 << 17)
7624  
7625  /*
7626   * This is the Inode Attributes structure, used for notify_change().  It
7627 @@ -226,6 +227,7 @@ struct iattr {
7628         umode_t         ia_mode;
7629         kuid_t          ia_uid;
7630         kgid_t          ia_gid;
7631 +       ktag_t          ia_tag;
7632         loff_t          ia_size;
7633         struct timespec ia_atime;
7634         struct timespec ia_mtime;
7635 @@ -523,7 +525,9 @@ struct inode {
7636         unsigned short          i_opflags;
7637         kuid_t                  i_uid;
7638         kgid_t                  i_gid;
7639 -       unsigned int            i_flags;
7640 +       ktag_t                  i_tag;
7641 +       unsigned short          i_flags;
7642 +       unsigned short          i_vflags;
7643  
7644  #ifdef CONFIG_FS_POSIX_ACL
7645         struct posix_acl        *i_acl;
7646 @@ -552,6 +556,7 @@ struct inode {
7647                 unsigned int __i_nlink;
7648         };
7649         dev_t                   i_rdev;
7650 +       dev_t                   i_mdev;
7651         loff_t                  i_size;
7652         struct timespec         i_atime;
7653         struct timespec         i_mtime;
7654 @@ -704,6 +709,11 @@ static inline gid_t i_gid_read(const str
7655         return from_kgid(&init_user_ns, inode->i_gid);
7656  }
7657  
7658 +static inline vtag_t i_tag_read(const struct inode *inode)
7659 +{
7660 +       return from_ktag(&init_user_ns, inode->i_tag);
7661 +}
7662 +
7663  static inline void i_uid_write(struct inode *inode, uid_t uid)
7664  {
7665         inode->i_uid = make_kuid(&init_user_ns, uid);
7666 @@ -714,14 +724,19 @@ static inline void i_gid_write(struct in
7667         inode->i_gid = make_kgid(&init_user_ns, gid);
7668  }
7669  
7670 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
7671 +{
7672 +       inode->i_tag = make_ktag(&init_user_ns, tag);
7673 +}
7674 +
7675  static inline unsigned iminor(const struct inode *inode)
7676  {
7677 -       return MINOR(inode->i_rdev);
7678 +       return MINOR(inode->i_mdev);
7679  }
7680  
7681  static inline unsigned imajor(const struct inode *inode)
7682  {
7683 -       return MAJOR(inode->i_rdev);
7684 +       return MAJOR(inode->i_mdev);
7685  }
7686  
7687  extern struct block_device *I_BDEV(struct inode *inode);
7688 @@ -788,6 +803,7 @@ struct file {
7689         loff_t                  f_pos;
7690         struct fown_struct      f_owner;
7691         const struct cred       *f_cred;
7692 +       vxid_t                  f_xid;
7693         struct file_ra_state    f_ra;
7694  
7695         u64                     f_version;
7696 @@ -939,6 +955,7 @@ struct file_lock {
7697         struct file *fl_file;
7698         loff_t fl_start;
7699         loff_t fl_end;
7700 +       vxid_t fl_xid;
7701  
7702         struct fasync_struct *  fl_fasync; /* for lease break notifications */
7703         /* for lease breaks: */
7704 @@ -1569,6 +1586,7 @@ struct inode_operations {
7705         ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7706         ssize_t (*listxattr) (struct dentry *, char *, size_t);
7707         int (*removexattr) (struct dentry *, const char *);
7708 +       int (*sync_flags) (struct inode *, int, int);
7709         int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7710                       u64 len);
7711         int (*update_time)(struct inode *, struct timespec *, int);
7712 @@ -1581,6 +1599,7 @@ ssize_t rw_copy_check_uvector(int type,
7713                               unsigned long nr_segs, unsigned long fast_segs,
7714                               struct iovec *fast_pointer,
7715                               struct iovec **ret_pointer);
7716 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7717  
7718  extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7719  extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7720 @@ -1634,6 +1653,14 @@ struct super_operations {
7721  #define S_IMA          1024    /* Inode has an associated IMA struct */
7722  #define S_AUTOMOUNT    2048    /* Automount/referral quasi-directory */
7723  #define S_NOSEC                4096    /* no suid or xattr security attributes */
7724 +#define S_IXUNLINK     8192    /* Immutable Invert on unlink */
7725 +
7726 +/* Linux-VServer related Inode flags */
7727 +
7728 +#define V_VALID                1
7729 +#define V_XATTR                2
7730 +#define V_BARRIER      4       /* Barrier for chroot() */
7731 +#define V_COW          8       /* Copy on Write */
7732  
7733  /*
7734   * Note that nosuid etc flags are inode-specific: setting some file-system
7735 @@ -1658,10 +1685,13 @@ struct super_operations {
7736  #define IS_MANDLOCK(inode)     __IS_FLG(inode, MS_MANDLOCK)
7737  #define IS_NOATIME(inode)      __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7738  #define IS_I_VERSION(inode)    __IS_FLG(inode, MS_I_VERSION)
7739 +#define IS_TAGGED(inode)       __IS_FLG(inode, MS_TAGGED)
7740  
7741  #define IS_NOQUOTA(inode)      ((inode)->i_flags & S_NOQUOTA)
7742  #define IS_APPEND(inode)       ((inode)->i_flags & S_APPEND)
7743  #define IS_IMMUTABLE(inode)    ((inode)->i_flags & S_IMMUTABLE)
7744 +#define IS_IXUNLINK(inode)     ((inode)->i_flags & S_IXUNLINK)
7745 +#define IS_IXORUNLINK(inode)   ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7746  #define IS_POSIXACL(inode)     __IS_FLG(inode, MS_POSIXACL)
7747  
7748  #define IS_DEADDIR(inode)      ((inode)->i_flags & S_DEAD)
7749 @@ -1672,6 +1702,16 @@ struct super_operations {
7750  #define IS_AUTOMOUNT(inode)    ((inode)->i_flags & S_AUTOMOUNT)
7751  #define IS_NOSEC(inode)                ((inode)->i_flags & S_NOSEC)
7752  
7753 +#define IS_BARRIER(inode)      (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7754 +
7755 +#ifdef CONFIG_VSERVER_COWBL
7756 +#  define IS_COW(inode)                (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7757 +#  define IS_COW_LINK(inode)   (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7758 +#else
7759 +#  define IS_COW(inode)                (0)
7760 +#  define IS_COW_LINK(inode)   (0)
7761 +#endif
7762 +
7763  /*
7764   * Inode state bits.  Protected by inode->i_lock
7765   *
7766 @@ -1900,6 +1940,9 @@ extern int rw_verify_area(int, struct fi
7767  extern int locks_mandatory_locked(struct inode *);
7768  extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7769  
7770 +#define ATTR_FLAG_BARRIER      512     /* Barrier for chroot() */
7771 +#define ATTR_FLAG_IXUNLINK     1024    /* Immutable invert on unlink */
7772 +
7773  /*
7774   * Candidates for mandatory locking have the setgid bit set
7775   * but no group execute bit -  an otherwise meaningless combination.
7776 @@ -2525,6 +2568,7 @@ extern int dcache_dir_open(struct inode
7777  extern int dcache_dir_close(struct inode *, struct file *);
7778  extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7779  extern int dcache_readdir(struct file *, void *, filldir_t);
7780 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
7781  extern int simple_setattr(struct dentry *, struct iattr *);
7782  extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7783  extern int simple_statfs(struct dentry *, struct kstatfs *);
7784 diff -NurpP --minimal linux-3.10.40/include/linux/init_task.h linux-3.10.40-vs2.3.6.8/include/linux/init_task.h
7785 --- linux-3.10.40/include/linux/init_task.h     2013-05-31 13:45:27.000000000 +0000
7786 +++ linux-3.10.40-vs2.3.6.8/include/linux/init_task.h   2013-08-22 20:30:00.000000000 +0000
7787 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7788         INIT_TASK_RCU_PREEMPT(tsk)                                      \
7789         INIT_CPUSET_SEQ                                                 \
7790         INIT_VTIME(tsk)                                                 \
7791 +       .xid            = 0,                                            \
7792 +       .vx_info        = NULL,                                         \
7793 +       .nid            = 0,                                            \
7794 +       .nx_info        = NULL,                                         \
7795  }
7796  
7797  
7798 diff -NurpP --minimal linux-3.10.40/include/linux/ipc.h linux-3.10.40-vs2.3.6.8/include/linux/ipc.h
7799 --- linux-3.10.40/include/linux/ipc.h   2012-12-11 03:30:57.000000000 +0000
7800 +++ linux-3.10.40-vs2.3.6.8/include/linux/ipc.h 2013-08-22 20:30:00.000000000 +0000
7801 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7802         key_t           key;
7803         kuid_t          uid;
7804         kgid_t          gid;
7805 +       vxid_t          xid;
7806         kuid_t          cuid;
7807         kgid_t          cgid;
7808         umode_t         mode; 
7809 diff -NurpP --minimal linux-3.10.40/include/linux/loop.h linux-3.10.40-vs2.3.6.8/include/linux/loop.h
7810 --- linux-3.10.40/include/linux/loop.h  2013-02-19 13:58:51.000000000 +0000
7811 +++ linux-3.10.40-vs2.3.6.8/include/linux/loop.h        2013-08-22 20:30:00.000000000 +0000
7812 @@ -41,6 +41,7 @@ struct loop_device {
7813         struct loop_func_table *lo_encryption;
7814         __u32           lo_init[2];
7815         kuid_t          lo_key_owner;   /* Who set the key */
7816 +       vxid_t          lo_xid;
7817         int             (*ioctl)(struct loop_device *, int cmd, 
7818                                  unsigned long arg); 
7819  
7820 diff -NurpP --minimal linux-3.10.40/include/linux/memcontrol.h linux-3.10.40-vs2.3.6.8/include/linux/memcontrol.h
7821 --- linux-3.10.40/include/linux/memcontrol.h    2013-05-31 13:45:28.000000000 +0000
7822 +++ linux-3.10.40-vs2.3.6.8/include/linux/memcontrol.h  2013-08-22 20:30:00.000000000 +0000
7823 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
7824  extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7825  extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
7826  
7827 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7828 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7829 +
7830 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7831 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7832 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7833 +
7834  static inline
7835  bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7836  {
7837 diff -NurpP --minimal linux-3.10.40/include/linux/mm_types.h linux-3.10.40-vs2.3.6.8/include/linux/mm_types.h
7838 --- linux-3.10.40/include/linux/mm_types.h      2014-05-20 04:09:40.000000000 +0000
7839 +++ linux-3.10.40-vs2.3.6.8/include/linux/mm_types.h    2014-01-22 19:00:34.000000000 +0000
7840 @@ -381,6 +381,7 @@ struct mm_struct {
7841  
7842         /* Architecture-specific MM context */
7843         mm_context_t context;
7844 +       struct vx_info *mm_vx_info;
7845  
7846         unsigned long flags; /* Must use atomic bitops to access the bits */
7847  
7848 diff -NurpP --minimal linux-3.10.40/include/linux/mount.h linux-3.10.40-vs2.3.6.8/include/linux/mount.h
7849 --- linux-3.10.40/include/linux/mount.h 2013-05-31 13:45:28.000000000 +0000
7850 +++ linux-3.10.40-vs2.3.6.8/include/linux/mount.h       2013-08-22 20:30:00.000000000 +0000
7851 @@ -49,6 +49,9 @@ struct mnt_namespace;
7852  
7853  #define MNT_LOCK_READONLY      0x400000
7854  
7855 +#define MNT_TAGID      0x10000
7856 +#define MNT_NOTAG      0x20000
7857 +
7858  struct vfsmount {
7859         struct dentry *mnt_root;        /* root of the mounted tree */
7860         struct super_block *mnt_sb;     /* pointer to superblock */
7861 diff -NurpP --minimal linux-3.10.40/include/linux/net.h linux-3.10.40-vs2.3.6.8/include/linux/net.h
7862 --- linux-3.10.40/include/linux/net.h   2014-05-20 04:09:40.000000000 +0000
7863 +++ linux-3.10.40-vs2.3.6.8/include/linux/net.h 2014-01-22 19:00:34.000000000 +0000
7864 @@ -38,6 +38,7 @@ struct net;
7865  #define SOCK_PASSCRED          3
7866  #define SOCK_PASSSEC           4
7867  #define SOCK_EXTERNALLY_ALLOCATED 5
7868 +#define SOCK_USER_SOCKET       6
7869  
7870  #ifndef ARCH_HAS_SOCKET_TYPES
7871  /**
7872 diff -NurpP --minimal linux-3.10.40/include/linux/netdevice.h linux-3.10.40-vs2.3.6.8/include/linux/netdevice.h
7873 --- linux-3.10.40/include/linux/netdevice.h     2014-05-20 04:09:40.000000000 +0000
7874 +++ linux-3.10.40-vs2.3.6.8/include/linux/netdevice.h   2014-03-12 13:18:32.000000000 +0000
7875 @@ -1694,6 +1694,7 @@ extern int                init_dummy_netdev(struct net
7876  
7877  extern struct net_device       *dev_get_by_index(struct net *net, int ifindex);
7878  extern struct net_device       *__dev_get_by_index(struct net *net, int ifindex);
7879 +extern struct net_device       *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7880  extern struct net_device       *dev_get_by_index_rcu(struct net *net, int ifindex);
7881  extern int             netdev_get_name(struct net *net, char *name, int ifindex);
7882  extern int             dev_restart(struct net_device *dev);
7883 diff -NurpP --minimal linux-3.10.40/include/linux/nsproxy.h linux-3.10.40-vs2.3.6.8/include/linux/nsproxy.h
7884 --- linux-3.10.40/include/linux/nsproxy.h       2013-02-19 13:58:51.000000000 +0000
7885 +++ linux-3.10.40-vs2.3.6.8/include/linux/nsproxy.h     2013-08-22 20:30:00.000000000 +0000
7886 @@ -3,6 +3,7 @@
7887  
7888  #include <linux/spinlock.h>
7889  #include <linux/sched.h>
7890 +#include <linux/vserver/debug.h>
7891  
7892  struct mnt_namespace;
7893  struct uts_namespace;
7894 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
7895  }
7896  
7897  int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7898 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7899  void exit_task_namespaces(struct task_struct *tsk);
7900  void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7901  void free_nsproxy(struct nsproxy *ns);
7902 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
7903         struct cred *, struct fs_struct *);
7904  int __init nsproxy_cache_init(void);
7905  
7906 -static inline void put_nsproxy(struct nsproxy *ns)
7907 +#define        get_nsproxy(n)  __get_nsproxy(n, __FILE__, __LINE__)
7908 +
7909 +static inline void __get_nsproxy(struct nsproxy *ns,
7910 +       const char *_file, int _line)
7911  {
7912 -       if (atomic_dec_and_test(&ns->count)) {
7913 -               free_nsproxy(ns);
7914 -       }
7915 +       vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7916 +               ns, atomic_read(&ns->count), _file, _line);
7917 +       atomic_inc(&ns->count);
7918  }
7919  
7920 -static inline void get_nsproxy(struct nsproxy *ns)
7921 +#define        put_nsproxy(n)  __put_nsproxy(n, __FILE__, __LINE__)
7922 +
7923 +static inline void __put_nsproxy(struct nsproxy *ns,
7924 +       const char *_file, int _line)
7925  {
7926 -       atomic_inc(&ns->count);
7927 +       vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7928 +               ns, atomic_read(&ns->count), _file, _line);
7929 +       if (atomic_dec_and_test(&ns->count)) {
7930 +               free_nsproxy(ns);
7931 +       }
7932  }
7933  
7934  #endif
7935 diff -NurpP --minimal linux-3.10.40/include/linux/pid.h linux-3.10.40-vs2.3.6.8/include/linux/pid.h
7936 --- linux-3.10.40/include/linux/pid.h   2013-05-31 13:45:28.000000000 +0000
7937 +++ linux-3.10.40-vs2.3.6.8/include/linux/pid.h 2013-08-22 20:30:00.000000000 +0000
7938 @@ -8,7 +8,8 @@ enum pid_type
7939         PIDTYPE_PID,
7940         PIDTYPE_PGID,
7941         PIDTYPE_SID,
7942 -       PIDTYPE_MAX
7943 +       PIDTYPE_MAX,
7944 +       PIDTYPE_REALPID
7945  };
7946  
7947  /*
7948 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
7949  }
7950  
7951  pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7952 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7953  pid_t pid_vnr(struct pid *pid);
7954  
7955  #define do_each_pid_task(pid, type, task)                              \
7956 diff -NurpP --minimal linux-3.10.40/include/linux/quotaops.h linux-3.10.40-vs2.3.6.8/include/linux/quotaops.h
7957 --- linux-3.10.40/include/linux/quotaops.h      2012-12-11 03:30:57.000000000 +0000
7958 +++ linux-3.10.40-vs2.3.6.8/include/linux/quotaops.h    2013-08-22 20:30:00.000000000 +0000
7959 @@ -8,6 +8,7 @@
7960  #define _LINUX_QUOTAOPS_
7961  
7962  #include <linux/fs.h>
7963 +#include <linux/vs_dlimit.h>
7964  
7965  #define DQUOT_SPACE_WARN       0x1
7966  #define DQUOT_SPACE_RESERVE    0x2
7967 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
7968  
7969  static inline int dquot_alloc_inode(const struct inode *inode)
7970  {
7971 -       return 0;
7972 +       return dl_alloc_inode(inode);
7973  }
7974  
7975  static inline void dquot_free_inode(const struct inode *inode)
7976  {
7977 +       dl_free_inode(inode);
7978  }
7979  
7980  static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
7981 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
7982  static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
7983                 int flags)
7984  {
7985 +       int ret = 0;
7986 +
7987 +       if ((ret = dl_alloc_space(inode, number)))
7988 +               return ret;
7989         if (!(flags & DQUOT_SPACE_RESERVE))
7990                 inode_add_bytes(inode, number);
7991         return 0;
7992 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
7993  {
7994         if (!(flags & DQUOT_SPACE_RESERVE))
7995                 inode_sub_bytes(inode, number);
7996 +       dl_free_space(inode, number);
7997  }
7998  
7999  static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8000 diff -NurpP --minimal linux-3.10.40/include/linux/sched.h linux-3.10.40-vs2.3.6.8/include/linux/sched.h
8001 --- linux-3.10.40/include/linux/sched.h 2014-05-20 04:09:40.000000000 +0000
8002 +++ linux-3.10.40-vs2.3.6.8/include/linux/sched.h       2013-11-30 07:53:00.000000000 +0000
8003 @@ -1237,6 +1237,14 @@ struct task_struct {
8004  #endif
8005         struct seccomp seccomp;
8006  
8007 +/* vserver context data */
8008 +       struct vx_info *vx_info;
8009 +       struct nx_info *nx_info;
8010 +
8011 +       vxid_t xid;
8012 +       vnid_t nid;
8013 +       vtag_t tag;
8014 +
8015  /* Thread group tracking */
8016         u32 parent_exec_id;
8017         u32 self_exec_id;
8018 @@ -1480,6 +1488,11 @@ struct pid_namespace;
8019  pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8020                         struct pid_namespace *ns);
8021  
8022 +#include <linux/vserver/base.h>
8023 +#include <linux/vserver/context.h>
8024 +#include <linux/vserver/debug.h>
8025 +#include <linux/vserver/pid.h>
8026 +
8027  static inline pid_t task_pid_nr(struct task_struct *tsk)
8028  {
8029         return tsk->pid;
8030 @@ -1493,7 +1506,8 @@ static inline pid_t task_pid_nr_ns(struc
8031  
8032  static inline pid_t task_pid_vnr(struct task_struct *tsk)
8033  {
8034 -       return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8035 +       // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8036 +       return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8037  }
8038  
8039  
8040 @@ -1506,7 +1520,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8041  
8042  static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8043  {
8044 -       return pid_vnr(task_tgid(tsk));
8045 +       return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8046  }
8047  
8048  
8049 diff -NurpP --minimal linux-3.10.40/include/linux/shmem_fs.h linux-3.10.40-vs2.3.6.8/include/linux/shmem_fs.h
8050 --- linux-3.10.40/include/linux/shmem_fs.h      2012-12-11 03:30:57.000000000 +0000
8051 +++ linux-3.10.40-vs2.3.6.8/include/linux/shmem_fs.h    2013-08-22 20:30:00.000000000 +0000
8052 @@ -9,6 +9,9 @@
8053  
8054  /* inode in-kernel data */
8055  
8056 +#define TMPFS_SUPER_MAGIC      0x01021994
8057 +
8058 +
8059  struct shmem_inode_info {
8060         spinlock_t              lock;
8061         unsigned long           flags;
8062 diff -NurpP --minimal linux-3.10.40/include/linux/stat.h linux-3.10.40-vs2.3.6.8/include/linux/stat.h
8063 --- linux-3.10.40/include/linux/stat.h  2012-12-11 03:30:57.000000000 +0000
8064 +++ linux-3.10.40-vs2.3.6.8/include/linux/stat.h        2013-08-22 20:30:00.000000000 +0000
8065 @@ -25,6 +25,7 @@ struct kstat {
8066         unsigned int    nlink;
8067         kuid_t          uid;
8068         kgid_t          gid;
8069 +       ktag_t          tag;
8070         dev_t           rdev;
8071         loff_t          size;
8072         struct timespec  atime;
8073 diff -NurpP --minimal linux-3.10.40/include/linux/sunrpc/auth.h linux-3.10.40-vs2.3.6.8/include/linux/sunrpc/auth.h
8074 --- linux-3.10.40/include/linux/sunrpc/auth.h   2013-07-14 17:01:33.000000000 +0000
8075 +++ linux-3.10.40-vs2.3.6.8/include/linux/sunrpc/auth.h 2013-08-22 20:30:00.000000000 +0000
8076 @@ -28,6 +28,7 @@ struct rpcsec_gss_info;
8077  struct auth_cred {
8078         kuid_t  uid;
8079         kgid_t  gid;
8080 +       ktag_t  tag;
8081         struct group_info *group_info;
8082         const char *principal;
8083         unsigned char machine_cred : 1;
8084 diff -NurpP --minimal linux-3.10.40/include/linux/sunrpc/clnt.h linux-3.10.40-vs2.3.6.8/include/linux/sunrpc/clnt.h
8085 --- linux-3.10.40/include/linux/sunrpc/clnt.h   2013-07-14 17:01:33.000000000 +0000
8086 +++ linux-3.10.40-vs2.3.6.8/include/linux/sunrpc/clnt.h 2013-08-22 20:30:00.000000000 +0000
8087 @@ -49,7 +49,8 @@ struct rpc_clnt {
8088         unsigned int            cl_softrtry : 1,/* soft timeouts */
8089                                 cl_discrtry : 1,/* disconnect before retry */
8090                                 cl_autobind : 1,/* use getport() */
8091 -                               cl_chatty   : 1;/* be verbose */
8092 +                               cl_chatty   : 1,/* be verbose */
8093 +                               cl_tag      : 1;/* context tagging */
8094  
8095         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
8096         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
8097 diff -NurpP --minimal linux-3.10.40/include/linux/sysfs.h linux-3.10.40-vs2.3.6.8/include/linux/sysfs.h
8098 --- linux-3.10.40/include/linux/sysfs.h 2013-05-31 13:45:28.000000000 +0000
8099 +++ linux-3.10.40-vs2.3.6.8/include/linux/sysfs.h       2013-08-22 20:30:00.000000000 +0000
8100 @@ -19,6 +19,8 @@
8101  #include <linux/kobject_ns.h>
8102  #include <linux/atomic.h>
8103  
8104 +#define SYSFS_SUPER_MAGIC      0x62656572
8105 +
8106  struct kobject;
8107  struct module;
8108  enum kobj_ns_type;
8109 diff -NurpP --minimal linux-3.10.40/include/linux/types.h linux-3.10.40-vs2.3.6.8/include/linux/types.h
8110 --- linux-3.10.40/include/linux/types.h 2013-02-19 13:58:52.000000000 +0000
8111 +++ linux-3.10.40-vs2.3.6.8/include/linux/types.h       2013-08-22 20:30:00.000000000 +0000
8112 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t      uid_t;
8113  typedef __kernel_gid32_t       gid_t;
8114  typedef __kernel_uid16_t        uid16_t;
8115  typedef __kernel_gid16_t        gid16_t;
8116 +typedef unsigned int           vxid_t;
8117 +typedef unsigned int           vnid_t;
8118 +typedef unsigned int           vtag_t;
8119  
8120  typedef unsigned long          uintptr_t;
8121  
8122 diff -NurpP --minimal linux-3.10.40/include/linux/uidgid.h linux-3.10.40-vs2.3.6.8/include/linux/uidgid.h
8123 --- linux-3.10.40/include/linux/uidgid.h        2012-12-11 03:30:57.000000000 +0000
8124 +++ linux-3.10.40-vs2.3.6.8/include/linux/uidgid.h      2013-08-22 20:30:00.000000000 +0000
8125 @@ -23,13 +23,17 @@ typedef struct {
8126         uid_t val;
8127  } kuid_t;
8128  
8129 -
8130  typedef struct {
8131         gid_t val;
8132  } kgid_t;
8133  
8134 +typedef struct {
8135 +       vtag_t val;
8136 +} ktag_t;
8137 +
8138  #define KUIDT_INIT(value) (kuid_t){ value }
8139  #define KGIDT_INIT(value) (kgid_t){ value }
8140 +#define KTAGT_INIT(value) (ktag_t){ value }
8141  
8142  static inline uid_t __kuid_val(kuid_t uid)
8143  {
8144 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
8145         return gid.val;
8146  }
8147  
8148 +static inline vtag_t __ktag_val(ktag_t tag)
8149 +{
8150 +       return tag.val;
8151 +}
8152 +
8153  #else
8154  
8155  typedef uid_t kuid_t;
8156  typedef gid_t kgid_t;
8157 +typedef vtag_t ktag_t;
8158  
8159  static inline uid_t __kuid_val(kuid_t uid)
8160  {
8161 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
8162         return gid;
8163  }
8164  
8165 +static inline vtag_t __ktag_val(ktag_t tag)
8166 +{
8167 +       return tag;
8168 +}
8169 +
8170  #define KUIDT_INIT(value) ((kuid_t) value )
8171  #define KGIDT_INIT(value) ((kgid_t) value )
8172 +#define KTAGT_INIT(value) ((ktag_t) value )
8173  
8174  #endif
8175  
8176  #define GLOBAL_ROOT_UID KUIDT_INIT(0)
8177  #define GLOBAL_ROOT_GID KGIDT_INIT(0)
8178 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
8179  
8180  #define INVALID_UID KUIDT_INIT(-1)
8181  #define INVALID_GID KGIDT_INIT(-1)
8182 +#define INVALID_TAG KTAGT_INIT(-1)
8183  
8184  static inline bool uid_eq(kuid_t left, kuid_t right)
8185  {
8186 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
8187         return __kgid_val(left) == __kgid_val(right);
8188  }
8189  
8190 +static inline bool tag_eq(ktag_t left, ktag_t right)
8191 +{
8192 +       return __ktag_val(left) == __ktag_val(right);
8193 +}
8194 +
8195  static inline bool uid_gt(kuid_t left, kuid_t right)
8196  {
8197         return __kuid_val(left) > __kuid_val(right);
8198 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
8199         return !gid_eq(gid, INVALID_GID);
8200  }
8201  
8202 +static inline bool tag_valid(ktag_t tag)
8203 +{
8204 +       return !tag_eq(tag, INVALID_TAG);
8205 +}
8206 +
8207  #ifdef CONFIG_USER_NS
8208  
8209  extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
8210  extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
8211 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
8212  
8213  extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
8214  extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
8215 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
8216 +
8217  extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
8218  extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
8219  
8220 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
8221         return KGIDT_INIT(gid);
8222  }
8223  
8224 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
8225 +{
8226 +       return KTAGT_INIT(tag);
8227 +}
8228 +
8229  static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
8230  {
8231         return __kuid_val(kuid);
8232 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
8233         return __kgid_val(kgid);
8234  }
8235  
8236 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
8237 +{
8238 +       return __ktag_val(ktag);
8239 +}
8240 +
8241  static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
8242  {
8243         uid_t uid = from_kuid(to, kuid);
8244 diff -NurpP --minimal linux-3.10.40/include/linux/vroot.h linux-3.10.40-vs2.3.6.8/include/linux/vroot.h
8245 --- linux-3.10.40/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
8246 +++ linux-3.10.40-vs2.3.6.8/include/linux/vroot.h       2013-08-22 20:30:00.000000000 +0000
8247 @@ -0,0 +1,51 @@
8248 +
8249 +/*
8250 + * include/linux/vroot.h
8251 + *
8252 + * written by Herbert Pötzl, 9/11/2002
8253 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8254 + *
8255 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8256 + * Redistribution of this file is permitted under the
8257 + * GNU General Public License.
8258 + */
8259 +
8260 +#ifndef _LINUX_VROOT_H
8261 +#define _LINUX_VROOT_H
8262 +
8263 +
8264 +#ifdef __KERNEL__
8265 +
8266 +/* Possible states of device */
8267 +enum {
8268 +       Vr_unbound,
8269 +       Vr_bound,
8270 +};
8271 +
8272 +struct vroot_device {
8273 +       int             vr_number;
8274 +       int             vr_refcnt;
8275 +
8276 +       struct semaphore        vr_ctl_mutex;
8277 +       struct block_device    *vr_device;
8278 +       int                     vr_state;
8279 +};
8280 +
8281 +
8282 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8283 +
8284 +extern int register_vroot_grb(vroot_grb_func *);
8285 +extern int unregister_vroot_grb(vroot_grb_func *);
8286 +
8287 +#endif /* __KERNEL__ */
8288 +
8289 +#define MAX_VROOT_DEFAULT      8
8290 +
8291 +/*
8292 + * IOCTL commands --- we will commandeer 0x56 ('V')
8293 + */
8294 +
8295 +#define VROOT_SET_DEV          0x5600
8296 +#define VROOT_CLR_DEV          0x5601
8297 +
8298 +#endif /* _LINUX_VROOT_H */
8299 diff -NurpP --minimal linux-3.10.40/include/linux/vs_base.h linux-3.10.40-vs2.3.6.8/include/linux/vs_base.h
8300 --- linux-3.10.40/include/linux/vs_base.h       1970-01-01 00:00:00.000000000 +0000
8301 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_base.h     2013-08-22 20:30:00.000000000 +0000
8302 @@ -0,0 +1,10 @@
8303 +#ifndef _VS_BASE_H
8304 +#define _VS_BASE_H
8305 +
8306 +#include "vserver/base.h"
8307 +#include "vserver/check.h"
8308 +#include "vserver/debug.h"
8309 +
8310 +#else
8311 +#warning duplicate inclusion
8312 +#endif
8313 diff -NurpP --minimal linux-3.10.40/include/linux/vs_context.h linux-3.10.40-vs2.3.6.8/include/linux/vs_context.h
8314 --- linux-3.10.40/include/linux/vs_context.h    1970-01-01 00:00:00.000000000 +0000
8315 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_context.h  2013-08-22 20:30:00.000000000 +0000
8316 @@ -0,0 +1,242 @@
8317 +#ifndef _VS_CONTEXT_H
8318 +#define _VS_CONTEXT_H
8319 +
8320 +#include "vserver/base.h"
8321 +#include "vserver/check.h"
8322 +#include "vserver/context.h"
8323 +#include "vserver/history.h"
8324 +#include "vserver/debug.h"
8325 +
8326 +#include <linux/sched.h>
8327 +
8328 +
8329 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8330 +
8331 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8332 +       const char *_file, int _line, void *_here)
8333 +{
8334 +       if (!vxi)
8335 +               return NULL;
8336 +
8337 +       vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8338 +               vxi, vxi ? vxi->vx_id : 0,
8339 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8340 +               _file, _line);
8341 +       __vxh_get_vx_info(vxi, _here);
8342 +
8343 +       atomic_inc(&vxi->vx_usecnt);
8344 +       return vxi;
8345 +}
8346 +
8347 +
8348 +extern void free_vx_info(struct vx_info *);
8349 +
8350 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8351 +
8352 +static inline void __put_vx_info(struct vx_info *vxi,
8353 +       const char *_file, int _line, void *_here)
8354 +{
8355 +       if (!vxi)
8356 +               return;
8357 +
8358 +       vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8359 +               vxi, vxi ? vxi->vx_id : 0,
8360 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8361 +               _file, _line);
8362 +       __vxh_put_vx_info(vxi, _here);
8363 +
8364 +       if (atomic_dec_and_test(&vxi->vx_usecnt))
8365 +               free_vx_info(vxi);
8366 +}
8367 +
8368 +
8369 +#define init_vx_info(p, i) \
8370 +       __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8371 +
8372 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8373 +       const char *_file, int _line, void *_here)
8374 +{
8375 +       if (vxi) {
8376 +               vxlprintk(VXD_CBIT(xid, 3),
8377 +                       "init_vx_info(%p[#%d.%d])",
8378 +                       vxi, vxi ? vxi->vx_id : 0,
8379 +                       vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8380 +                       _file, _line);
8381 +               __vxh_init_vx_info(vxi, vxp, _here);
8382 +
8383 +               atomic_inc(&vxi->vx_usecnt);
8384 +       }
8385 +       *vxp = vxi;
8386 +}
8387 +
8388 +
8389 +#define set_vx_info(p, i) \
8390 +       __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8391 +
8392 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8393 +       const char *_file, int _line, void *_here)
8394 +{
8395 +       struct vx_info *vxo;
8396 +
8397 +       if (!vxi)
8398 +               return;
8399 +
8400 +       vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8401 +               vxi, vxi ? vxi->vx_id : 0,
8402 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8403 +               _file, _line);
8404 +       __vxh_set_vx_info(vxi, vxp, _here);
8405 +
8406 +       atomic_inc(&vxi->vx_usecnt);
8407 +       vxo = xchg(vxp, vxi);
8408 +       BUG_ON(vxo);
8409 +}
8410 +
8411 +
8412 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8413 +
8414 +static inline void __clr_vx_info(struct vx_info **vxp,
8415 +       const char *_file, int _line, void *_here)
8416 +{
8417 +       struct vx_info *vxo;
8418 +
8419 +       vxo = xchg(vxp, NULL);
8420 +       if (!vxo)
8421 +               return;
8422 +
8423 +       vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8424 +               vxo, vxo ? vxo->vx_id : 0,
8425 +               vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8426 +               _file, _line);
8427 +       __vxh_clr_vx_info(vxo, vxp, _here);
8428 +
8429 +       if (atomic_dec_and_test(&vxo->vx_usecnt))
8430 +               free_vx_info(vxo);
8431 +}
8432 +
8433 +
8434 +#define claim_vx_info(v, p) \
8435 +       __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8436 +
8437 +static inline void __claim_vx_info(struct vx_info *vxi,
8438 +       struct task_struct *task,
8439 +       const char *_file, int _line, void *_here)
8440 +{
8441 +       vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8442 +               vxi, vxi ? vxi->vx_id : 0,
8443 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8444 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8445 +               task, _file, _line);
8446 +       __vxh_claim_vx_info(vxi, task, _here);
8447 +
8448 +       atomic_inc(&vxi->vx_tasks);
8449 +}
8450 +
8451 +
8452 +extern void unhash_vx_info(struct vx_info *);
8453 +
8454 +#define release_vx_info(v, p) \
8455 +       __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8456 +
8457 +static inline void __release_vx_info(struct vx_info *vxi,
8458 +       struct task_struct *task,
8459 +       const char *_file, int _line, void *_here)
8460 +{
8461 +       vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8462 +               vxi, vxi ? vxi->vx_id : 0,
8463 +               vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8464 +               vxi ? atomic_read(&vxi->vx_tasks) : 0,
8465 +               task, _file, _line);
8466 +       __vxh_release_vx_info(vxi, task, _here);
8467 +
8468 +       might_sleep();
8469 +
8470 +       if (atomic_dec_and_test(&vxi->vx_tasks))
8471 +               unhash_vx_info(vxi);
8472 +}
8473 +
8474 +
8475 +#define task_get_vx_info(p) \
8476 +       __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8477 +
8478 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8479 +       const char *_file, int _line, void *_here)
8480 +{
8481 +       struct vx_info *vxi;
8482 +
8483 +       task_lock(p);
8484 +       vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8485 +               p, _file, _line);
8486 +       vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8487 +       task_unlock(p);
8488 +       return vxi;
8489 +}
8490 +
8491 +
8492 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8493 +{
8494 +       if (waitqueue_active(&vxi->vx_wait))
8495 +               wake_up_interruptible(&vxi->vx_wait);
8496 +}
8497 +
8498 +
8499 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8500 +
8501 +static inline void __enter_vx_info(struct vx_info *vxi,
8502 +       struct vx_info_save *vxis, const char *_file, int _line)
8503 +{
8504 +       vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8505 +               vxi, vxi ? vxi->vx_id : 0, vxis, current,
8506 +               current->xid, current->vx_info, _file, _line);
8507 +       vxis->vxi = xchg(&current->vx_info, vxi);
8508 +       vxis->xid = current->xid;
8509 +       current->xid = vxi ? vxi->vx_id : 0;
8510 +}
8511 +
8512 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8513 +
8514 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8515 +       const char *_file, int _line)
8516 +{
8517 +       vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8518 +               vxis, vxis->xid, vxis->vxi, current,
8519 +               current->xid, current->vx_info, _file, _line);
8520 +       (void)xchg(&current->vx_info, vxis->vxi);
8521 +       current->xid = vxis->xid;
8522 +}
8523 +
8524 +
8525 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8526 +{
8527 +       vxis->vxi = xchg(&current->vx_info, NULL);
8528 +       vxis->xid = xchg(&current->xid, (vxid_t)0);
8529 +}
8530 +
8531 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8532 +{
8533 +       (void)xchg(&current->xid, vxis->xid);
8534 +       (void)xchg(&current->vx_info, vxis->vxi);
8535 +}
8536 +
8537 +#define task_is_init(p) \
8538 +       __task_is_init(p, __FILE__, __LINE__, __HERE__)
8539 +
8540 +static inline int __task_is_init(struct task_struct *p,
8541 +       const char *_file, int _line, void *_here)
8542 +{
8543 +       int is_init = is_global_init(p);
8544 +
8545 +       task_lock(p);
8546 +       if (p->vx_info)
8547 +               is_init = p->vx_info->vx_initpid == p->pid;
8548 +       task_unlock(p);
8549 +       return is_init;
8550 +}
8551 +
8552 +extern void exit_vx_info(struct task_struct *, int);
8553 +extern void exit_vx_info_early(struct task_struct *, int);
8554 +
8555 +
8556 +#else
8557 +#warning duplicate inclusion
8558 +#endif
8559 diff -NurpP --minimal linux-3.10.40/include/linux/vs_cowbl.h linux-3.10.40-vs2.3.6.8/include/linux/vs_cowbl.h
8560 --- linux-3.10.40/include/linux/vs_cowbl.h      1970-01-01 00:00:00.000000000 +0000
8561 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_cowbl.h    2013-08-22 20:30:00.000000000 +0000
8562 @@ -0,0 +1,48 @@
8563 +#ifndef _VS_COWBL_H
8564 +#define _VS_COWBL_H
8565 +
8566 +#include <linux/fs.h>
8567 +#include <linux/dcache.h>
8568 +#include <linux/namei.h>
8569 +#include <linux/slab.h>
8570 +
8571 +extern struct dentry *cow_break_link(const char *pathname);
8572 +
8573 +static inline int cow_check_and_break(struct path *path)
8574 +{
8575 +       struct inode *inode = path->dentry->d_inode;
8576 +       int error = 0;
8577 +
8578 +       /* do we need this check? */
8579 +       if (IS_RDONLY(inode))
8580 +               return -EROFS;
8581 +
8582 +       if (IS_COW(inode)) {
8583 +               if (IS_COW_LINK(inode)) {
8584 +                       struct dentry *new_dentry, *old_dentry = path->dentry;
8585 +                       char *pp, *buf;
8586 +
8587 +                       buf = kmalloc(PATH_MAX, GFP_KERNEL);
8588 +                       if (!buf) {
8589 +                               return -ENOMEM;
8590 +                       }
8591 +                       pp = d_path(path, buf, PATH_MAX);
8592 +                       new_dentry = cow_break_link(pp);
8593 +                       kfree(buf);
8594 +                       if (!IS_ERR(new_dentry)) {
8595 +                               path->dentry = new_dentry;
8596 +                               dput(old_dentry);
8597 +                       } else
8598 +                               error = PTR_ERR(new_dentry);
8599 +               } else {
8600 +                       inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8601 +                       inode->i_ctime = CURRENT_TIME;
8602 +                       mark_inode_dirty(inode);
8603 +               }
8604 +       }
8605 +       return error;
8606 +}
8607 +
8608 +#else
8609 +#warning duplicate inclusion
8610 +#endif
8611 diff -NurpP --minimal linux-3.10.40/include/linux/vs_cvirt.h linux-3.10.40-vs2.3.6.8/include/linux/vs_cvirt.h
8612 --- linux-3.10.40/include/linux/vs_cvirt.h      1970-01-01 00:00:00.000000000 +0000
8613 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_cvirt.h    2013-08-22 20:30:00.000000000 +0000
8614 @@ -0,0 +1,50 @@
8615 +#ifndef _VS_CVIRT_H
8616 +#define _VS_CVIRT_H
8617 +
8618 +#include "vserver/cvirt.h"
8619 +#include "vserver/context.h"
8620 +#include "vserver/base.h"
8621 +#include "vserver/check.h"
8622 +#include "vserver/debug.h"
8623 +
8624 +
8625 +static inline void vx_activate_task(struct task_struct *p)
8626 +{
8627 +       struct vx_info *vxi;
8628 +
8629 +       if ((vxi = p->vx_info)) {
8630 +               vx_update_load(vxi);
8631 +               atomic_inc(&vxi->cvirt.nr_running);
8632 +       }
8633 +}
8634 +
8635 +static inline void vx_deactivate_task(struct task_struct *p)
8636 +{
8637 +       struct vx_info *vxi;
8638 +
8639 +       if ((vxi = p->vx_info)) {
8640 +               vx_update_load(vxi);
8641 +               atomic_dec(&vxi->cvirt.nr_running);
8642 +       }
8643 +}
8644 +
8645 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8646 +{
8647 +       struct vx_info *vxi;
8648 +
8649 +       if ((vxi = p->vx_info))
8650 +               atomic_inc(&vxi->cvirt.nr_uninterruptible);
8651 +}
8652 +
8653 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8654 +{
8655 +       struct vx_info *vxi;
8656 +
8657 +       if ((vxi = p->vx_info))
8658 +               atomic_dec(&vxi->cvirt.nr_uninterruptible);
8659 +}
8660 +
8661 +
8662 +#else
8663 +#warning duplicate inclusion
8664 +#endif
8665 diff -NurpP --minimal linux-3.10.40/include/linux/vs_device.h linux-3.10.40-vs2.3.6.8/include/linux/vs_device.h
8666 --- linux-3.10.40/include/linux/vs_device.h     1970-01-01 00:00:00.000000000 +0000
8667 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_device.h   2013-08-22 20:30:00.000000000 +0000
8668 @@ -0,0 +1,45 @@
8669 +#ifndef _VS_DEVICE_H
8670 +#define _VS_DEVICE_H
8671 +
8672 +#include "vserver/base.h"
8673 +#include "vserver/device.h"
8674 +#include "vserver/debug.h"
8675 +
8676 +
8677 +#ifdef CONFIG_VSERVER_DEVICE
8678 +
8679 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8680 +
8681 +#define vs_device_perm(v, d, m, p) \
8682 +       ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8683 +
8684 +#else
8685 +
8686 +static inline
8687 +int vs_map_device(struct vx_info *vxi,
8688 +       dev_t device, dev_t *target, umode_t mode)
8689 +{
8690 +       if (target)
8691 +               *target = device;
8692 +       return ~0;
8693 +}
8694 +
8695 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8696 +
8697 +#endif
8698 +
8699 +
8700 +#define vs_map_chrdev(d, t, p) \
8701 +       ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8702 +#define vs_map_blkdev(d, t, p) \
8703 +       ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8704 +
8705 +#define vs_chrdev_perm(d, p) \
8706 +       vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8707 +#define vs_blkdev_perm(d, p) \
8708 +       vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8709 +
8710 +
8711 +#else
8712 +#warning duplicate inclusion
8713 +#endif
8714 diff -NurpP --minimal linux-3.10.40/include/linux/vs_dlimit.h linux-3.10.40-vs2.3.6.8/include/linux/vs_dlimit.h
8715 --- linux-3.10.40/include/linux/vs_dlimit.h     1970-01-01 00:00:00.000000000 +0000
8716 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_dlimit.h   2013-08-22 20:30:00.000000000 +0000
8717 @@ -0,0 +1,215 @@
8718 +#ifndef _VS_DLIMIT_H
8719 +#define _VS_DLIMIT_H
8720 +
8721 +#include <linux/fs.h>
8722 +
8723 +#include "vserver/dlimit.h"
8724 +#include "vserver/base.h"
8725 +#include "vserver/debug.h"
8726 +
8727 +
8728 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8729 +
8730 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8731 +       const char *_file, int _line)
8732 +{
8733 +       if (!dli)
8734 +               return NULL;
8735 +       vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8736 +               dli, dli ? dli->dl_tag : 0,
8737 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8738 +               _file, _line);
8739 +       atomic_inc(&dli->dl_usecnt);
8740 +       return dli;
8741 +}
8742 +
8743 +
8744 +#define free_dl_info(i) \
8745 +       call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8746 +
8747 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8748 +
8749 +static inline void __put_dl_info(struct dl_info *dli,
8750 +       const char *_file, int _line)
8751 +{
8752 +       if (!dli)
8753 +               return;
8754 +       vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8755 +               dli, dli ? dli->dl_tag : 0,
8756 +               dli ? atomic_read(&dli->dl_usecnt) : 0,
8757 +               _file, _line);
8758 +       if (atomic_dec_and_test(&dli->dl_usecnt))
8759 +               free_dl_info(dli);
8760 +}
8761 +
8762 +
8763 +#define __dlimit_char(d)       ((d) ? '*' : ' ')
8764 +
8765 +static inline int __dl_alloc_space(struct super_block *sb,
8766 +       vtag_t tag, dlsize_t nr, const char *file, int line)
8767 +{
8768 +       struct dl_info *dli = NULL;
8769 +       int ret = 0;
8770 +
8771 +       if (nr == 0)
8772 +               goto out;
8773 +       dli = locate_dl_info(sb, tag);
8774 +       if (!dli)
8775 +               goto out;
8776 +
8777 +       spin_lock(&dli->dl_lock);
8778 +       ret = (dli->dl_space_used + nr > dli->dl_space_total);
8779 +       if (!ret)
8780 +               dli->dl_space_used += nr;
8781 +       spin_unlock(&dli->dl_lock);
8782 +       put_dl_info(dli);
8783 +out:
8784 +       vxlprintk(VXD_CBIT(dlim, 1),
8785 +               "ALLOC (%p,#%d)%c %lld bytes (%d)",
8786 +               sb, tag, __dlimit_char(dli), (long long)nr,
8787 +               ret, file, line);
8788 +       return ret ? -ENOSPC : 0;
8789 +}
8790 +
8791 +static inline void __dl_free_space(struct super_block *sb,
8792 +       vtag_t tag, dlsize_t nr, const char *_file, int _line)
8793 +{
8794 +       struct dl_info *dli = NULL;
8795 +
8796 +       if (nr == 0)
8797 +               goto out;
8798 +       dli = locate_dl_info(sb, tag);
8799 +       if (!dli)
8800 +               goto out;
8801 +
8802 +       spin_lock(&dli->dl_lock);
8803 +       if (dli->dl_space_used > nr)
8804 +               dli->dl_space_used -= nr;
8805 +       else
8806 +               dli->dl_space_used = 0;
8807 +       spin_unlock(&dli->dl_lock);
8808 +       put_dl_info(dli);
8809 +out:
8810 +       vxlprintk(VXD_CBIT(dlim, 1),
8811 +               "FREE  (%p,#%d)%c %lld bytes",
8812 +               sb, tag, __dlimit_char(dli), (long long)nr,
8813 +               _file, _line);
8814 +}
8815 +
8816 +static inline int __dl_alloc_inode(struct super_block *sb,
8817 +       vtag_t tag, const char *_file, int _line)
8818 +{
8819 +       struct dl_info *dli;
8820 +       int ret = 0;
8821 +
8822 +       dli = locate_dl_info(sb, tag);
8823 +       if (!dli)
8824 +               goto out;
8825 +
8826 +       spin_lock(&dli->dl_lock);
8827 +       dli->dl_inodes_used++;
8828 +       ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8829 +       spin_unlock(&dli->dl_lock);
8830 +       put_dl_info(dli);
8831 +out:
8832 +       vxlprintk(VXD_CBIT(dlim, 0),
8833 +               "ALLOC (%p,#%d)%c inode (%d)",
8834 +               sb, tag, __dlimit_char(dli), ret, _file, _line);
8835 +       return ret ? -ENOSPC : 0;
8836 +}
8837 +
8838 +static inline void __dl_free_inode(struct super_block *sb,
8839 +       vtag_t tag, const char *_file, int _line)
8840 +{
8841 +       struct dl_info *dli;
8842 +
8843 +       dli = locate_dl_info(sb, tag);
8844 +       if (!dli)
8845 +               goto out;
8846 +
8847 +       spin_lock(&dli->dl_lock);
8848 +       if (dli->dl_inodes_used > 1)
8849 +               dli->dl_inodes_used--;
8850 +       else
8851 +               dli->dl_inodes_used = 0;
8852 +       spin_unlock(&dli->dl_lock);
8853 +       put_dl_info(dli);
8854 +out:
8855 +       vxlprintk(VXD_CBIT(dlim, 0),
8856 +               "FREE  (%p,#%d)%c inode",
8857 +               sb, tag, __dlimit_char(dli), _file, _line);
8858 +}
8859 +
8860 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
8861 +       unsigned long long *free_blocks, unsigned long long *root_blocks,
8862 +       const char *_file, int _line)
8863 +{
8864 +       struct dl_info *dli;
8865 +       uint64_t broot, bfree;
8866 +
8867 +       dli = locate_dl_info(sb, tag);
8868 +       if (!dli)
8869 +               return;
8870 +
8871 +       spin_lock(&dli->dl_lock);
8872 +       broot = (dli->dl_space_total -
8873 +               (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8874 +               >> sb->s_blocksize_bits;
8875 +       bfree = (dli->dl_space_total - dli->dl_space_used)
8876 +                       >> sb->s_blocksize_bits;
8877 +       spin_unlock(&dli->dl_lock);
8878 +
8879 +       vxlprintk(VXD_CBIT(dlim, 2),
8880 +               "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8881 +               (long long)bfree, (long long)broot,
8882 +               *free_blocks, *root_blocks, dli->dl_nrlmult,
8883 +               _file, _line);
8884 +       if (free_blocks) {
8885 +               if (*free_blocks > bfree)
8886 +                       *free_blocks = bfree;
8887 +       }
8888 +       if (root_blocks) {
8889 +               if (*root_blocks > broot)
8890 +                       *root_blocks = broot;
8891 +       }
8892 +       put_dl_info(dli);
8893 +}
8894 +
8895 +#define dl_prealloc_space(in, bytes) \
8896 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8897 +               __FILE__, __LINE__ )
8898 +
8899 +#define dl_alloc_space(in, bytes) \
8900 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8901 +               __FILE__, __LINE__ )
8902 +
8903 +#define dl_reserve_space(in, bytes) \
8904 +       __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8905 +               __FILE__, __LINE__ )
8906 +
8907 +#define dl_claim_space(in, bytes) (0)
8908 +
8909 +#define dl_release_space(in, bytes) \
8910 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8911 +               __FILE__, __LINE__ )
8912 +
8913 +#define dl_free_space(in, bytes) \
8914 +       __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8915 +               __FILE__, __LINE__ )
8916 +
8917 +
8918 +
8919 +#define dl_alloc_inode(in) \
8920 +       __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8921 +
8922 +#define dl_free_inode(in) \
8923 +       __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8924 +
8925 +
8926 +#define dl_adjust_block(sb, tag, fb, rb) \
8927 +       __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8928 +
8929 +
8930 +#else
8931 +#warning duplicate inclusion
8932 +#endif
8933 diff -NurpP --minimal linux-3.10.40/include/linux/vs_inet.h linux-3.10.40-vs2.3.6.8/include/linux/vs_inet.h
8934 --- linux-3.10.40/include/linux/vs_inet.h       1970-01-01 00:00:00.000000000 +0000
8935 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_inet.h     2013-08-22 20:30:00.000000000 +0000
8936 @@ -0,0 +1,364 @@
8937 +#ifndef _VS_INET_H
8938 +#define _VS_INET_H
8939 +
8940 +#include "vserver/base.h"
8941 +#include "vserver/network.h"
8942 +#include "vserver/debug.h"
8943 +
8944 +#define IPI_LOOPBACK   htonl(INADDR_LOOPBACK)
8945 +
8946 +#define NXAV4(a)       NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
8947 +                       NIPQUAD((a)->mask), (a)->type
8948 +#define NXAV4_FMT      "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
8949 +
8950 +#define NIPQUAD(addr) \
8951 +       ((unsigned char *)&addr)[0], \
8952 +       ((unsigned char *)&addr)[1], \
8953 +       ((unsigned char *)&addr)[2], \
8954 +       ((unsigned char *)&addr)[3]
8955 +
8956 +#define NIPQUAD_FMT "%u.%u.%u.%u"
8957 +
8958 +
8959 +static inline
8960 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
8961 +{
8962 +       __be32 ip = nxa->ip[0].s_addr;
8963 +       __be32 mask = nxa->mask.s_addr;
8964 +       __be32 bcast = ip | ~mask;
8965 +       int ret = 0;
8966 +
8967 +       switch (nxa->type & tmask) {
8968 +       case NXA_TYPE_MASK:
8969 +               ret = (ip == (addr & mask));
8970 +               break;
8971 +       case NXA_TYPE_ADDR:
8972 +               ret = 3;
8973 +               if (addr == ip)
8974 +                       break;
8975 +               /* fall through to broadcast */
8976 +       case NXA_MOD_BCAST:
8977 +               ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
8978 +               break;
8979 +       case NXA_TYPE_RANGE:
8980 +               ret = ((nxa->ip[0].s_addr <= addr) &&
8981 +                       (nxa->ip[1].s_addr > addr));
8982 +               break;
8983 +       case NXA_TYPE_ANY:
8984 +               ret = 2;
8985 +               break;
8986 +       }
8987 +
8988 +       vxdprintk(VXD_CBIT(net, 0),
8989 +               "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
8990 +               nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
8991 +       return ret;
8992 +}
8993 +
8994 +static inline
8995 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
8996 +{
8997 +       struct nx_addr_v4 *nxa;
8998 +       unsigned long irqflags;
8999 +       int ret = 1;
9000 +
9001 +       if (!nxi)
9002 +               goto out;
9003 +
9004 +       ret = 2;
9005 +       /* allow 127.0.0.1 when remapping lback */
9006 +       if ((tmask & NXA_LOOPBACK) &&
9007 +               (addr == IPI_LOOPBACK) &&
9008 +               nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9009 +               goto out;
9010 +       ret = 3;
9011 +       /* check for lback address */
9012 +       if ((tmask & NXA_MOD_LBACK) &&
9013 +               (nxi->v4_lback.s_addr == addr))
9014 +               goto out;
9015 +       ret = 4;
9016 +       /* check for broadcast address */
9017 +       if ((tmask & NXA_MOD_BCAST) &&
9018 +               (nxi->v4_bcast.s_addr == addr))
9019 +               goto out;
9020 +       ret = 5;
9021 +
9022 +       /* check for v4 addresses */
9023 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9024 +       for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9025 +               if (v4_addr_match(nxa, addr, tmask))
9026 +                       goto out_unlock;
9027 +       ret = 0;
9028 +out_unlock:
9029 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9030 +out:
9031 +       vxdprintk(VXD_CBIT(net, 0),
9032 +               "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9033 +               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9034 +       return ret;
9035 +}
9036 +
9037 +static inline
9038 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9039 +{
9040 +       /* FIXME: needs full range checks */
9041 +       return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9042 +}
9043 +
9044 +static inline
9045 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9046 +{
9047 +       struct nx_addr_v4 *ptr;
9048 +       unsigned long irqflags;
9049 +       int ret = 1;
9050 +
9051 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9052 +       for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9053 +               if (v4_nx_addr_match(ptr, nxa, mask))
9054 +                       goto out_unlock;
9055 +       ret = 0;
9056 +out_unlock:
9057 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9058 +       return ret;
9059 +}
9060 +
9061 +#include <net/inet_sock.h>
9062 +
9063 +/*
9064 + *     Check if a given address matches for a socket
9065 + *
9066 + *     nxi:            the socket's nx_info if any
9067 + *     addr:           to be verified address
9068 + */
9069 +static inline
9070 +int v4_sock_addr_match (
9071 +       struct nx_info *nxi,
9072 +       struct inet_sock *inet,
9073 +       __be32 addr)
9074 +{
9075 +       __be32 saddr = inet->inet_rcv_saddr;
9076 +       __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9077 +
9078 +       if (addr && (saddr == addr || bcast == addr))
9079 +               return 1;
9080 +       if (!saddr)
9081 +               return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9082 +       return 0;
9083 +}
9084 +
9085 +
9086 +/* inet related checks and helpers */
9087 +
9088 +
9089 +struct in_ifaddr;
9090 +struct net_device;
9091 +struct sock;
9092 +
9093 +#ifdef CONFIG_INET
9094 +
9095 +#include <linux/netdevice.h>
9096 +#include <linux/inetdevice.h>
9097 +#include <net/inet_sock.h>
9098 +#include <net/inet_timewait_sock.h>
9099 +
9100 +
9101 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9102 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9103 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9104 +
9105 +
9106 +/*
9107 + *     check if address is covered by socket
9108 + *
9109 + *     sk:     the socket to check against
9110 + *     addr:   the address in question (must be != 0)
9111 + */
9112 +
9113 +static inline
9114 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9115 +{
9116 +       struct nx_info *nxi = sk->sk_nx_info;
9117 +       __be32 saddr = sk_rcv_saddr(sk);
9118 +
9119 +       vxdprintk(VXD_CBIT(net, 5),
9120 +               "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9121 +               sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9122 +               (sk->sk_socket?sk->sk_socket->flags:0));
9123 +
9124 +       if (saddr) {            /* direct address match */
9125 +               return v4_addr_match(nxa, saddr, -1);
9126 +       } else if (nxi) {       /* match against nx_info */
9127 +               return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9128 +       } else {                /* unrestricted any socket */
9129 +               return 1;
9130 +       }
9131 +}
9132 +
9133 +
9134 +
9135 +static inline
9136 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9137 +{
9138 +       vxdprintk(VXD_CBIT(net, 1),
9139 +               "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9140 +               nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9141 +               nxi ? dev_in_nx_info(dev, nxi) : 0);
9142 +
9143 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9144 +               return 1;
9145 +       if (dev_in_nx_info(dev, nxi))
9146 +               return 1;
9147 +       return 0;
9148 +}
9149 +
9150 +
9151 +static inline
9152 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9153 +{
9154 +       if (!nxi)
9155 +               return 1;
9156 +       if (!ifa)
9157 +               return 0;
9158 +       return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9159 +}
9160 +
9161 +static inline
9162 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9163 +{
9164 +       vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9165 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9166 +               nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9167 +
9168 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9169 +               return 1;
9170 +       if (v4_ifa_in_nx_info(ifa, nxi))
9171 +               return 1;
9172 +       return 0;
9173 +}
9174 +
9175 +
9176 +struct nx_v4_sock_addr {
9177 +       __be32 saddr;   /* Address used for validation */
9178 +       __be32 baddr;   /* Address used for socket bind */
9179 +};
9180 +
9181 +static inline
9182 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9183 +       struct nx_v4_sock_addr *nsa)
9184 +{
9185 +       struct sock *sk = &inet->sk;
9186 +       struct nx_info *nxi = sk->sk_nx_info;
9187 +       __be32 saddr = addr->sin_addr.s_addr;
9188 +       __be32 baddr = saddr;
9189 +
9190 +       vxdprintk(VXD_CBIT(net, 3),
9191 +               "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9192 +               sk, sk->sk_nx_info, sk->sk_socket,
9193 +               (sk->sk_socket ? sk->sk_socket->flags : 0),
9194 +               NIPQUAD(saddr));
9195 +
9196 +       if (nxi) {
9197 +               if (saddr == INADDR_ANY) {
9198 +                       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9199 +                               baddr = nxi->v4.ip[0].s_addr;
9200 +               } else if (saddr == IPI_LOOPBACK) {
9201 +                       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9202 +                               baddr = nxi->v4_lback.s_addr;
9203 +               } else if (!ipv4_is_multicast(saddr) ||
9204 +                       !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9205 +                       /* normal address bind */
9206 +                       if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9207 +                               return -EADDRNOTAVAIL;
9208 +               }
9209 +       }
9210 +
9211 +       vxdprintk(VXD_CBIT(net, 3),
9212 +               "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9213 +               sk, NIPQUAD(saddr), NIPQUAD(baddr));
9214 +
9215 +       nsa->saddr = saddr;
9216 +       nsa->baddr = baddr;
9217 +       return 0;
9218 +}
9219 +
9220 +static inline
9221 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9222 +{
9223 +       inet->inet_saddr = nsa->baddr;
9224 +       inet->inet_rcv_saddr = nsa->baddr;
9225 +}
9226 +
9227 +
9228 +/*
9229 + *      helper to simplify inet_lookup_listener
9230 + *
9231 + *      nxi:   the socket's nx_info if any
9232 + *      addr:  to be verified address
9233 + *      saddr: socket address
9234 + */
9235 +static inline int v4_inet_addr_match (
9236 +       struct nx_info *nxi,
9237 +       __be32 addr,
9238 +       __be32 saddr)
9239 +{
9240 +       if (addr && (saddr == addr))
9241 +               return 1;
9242 +       if (!saddr)
9243 +               return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9244 +       return 0;
9245 +}
9246 +
9247 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9248 +{
9249 +       if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9250 +               (addr == nxi->v4_lback.s_addr))
9251 +               return IPI_LOOPBACK;
9252 +       return addr;
9253 +}
9254 +
9255 +static inline
9256 +int nx_info_has_v4(struct nx_info *nxi)
9257 +{
9258 +       if (!nxi)
9259 +               return 1;
9260 +       if (NX_IPV4(nxi))
9261 +               return 1;
9262 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9263 +               return 1;
9264 +       return 0;
9265 +}
9266 +
9267 +#else /* CONFIG_INET */
9268 +
9269 +static inline
9270 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9271 +{
9272 +       return 1;
9273 +}
9274 +
9275 +static inline
9276 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9277 +{
9278 +       return 1;
9279 +}
9280 +
9281 +static inline
9282 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9283 +{
9284 +       return 1;
9285 +}
9286 +
9287 +static inline
9288 +int nx_info_has_v4(struct nx_info *nxi)
9289 +{
9290 +       return 0;
9291 +}
9292 +
9293 +#endif /* CONFIG_INET */
9294 +
9295 +#define current_nx_info_has_v4() \
9296 +       nx_info_has_v4(current_nx_info())
9297 +
9298 +#else
9299 +// #warning duplicate inclusion
9300 +#endif
9301 diff -NurpP --minimal linux-3.10.40/include/linux/vs_inet6.h linux-3.10.40-vs2.3.6.8/include/linux/vs_inet6.h
9302 --- linux-3.10.40/include/linux/vs_inet6.h      1970-01-01 00:00:00.000000000 +0000
9303 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_inet6.h    2013-08-22 20:30:00.000000000 +0000
9304 @@ -0,0 +1,257 @@
9305 +#ifndef _VS_INET6_H
9306 +#define _VS_INET6_H
9307 +
9308 +#include "vserver/base.h"
9309 +#include "vserver/network.h"
9310 +#include "vserver/debug.h"
9311 +
9312 +#include <net/ipv6.h>
9313 +
9314 +#define NXAV6(a)       &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9315 +#define NXAV6_FMT      "[%pI6/%pI6/%d:%04x]"
9316 +
9317 +
9318 +#ifdef CONFIG_IPV6
9319 +
9320 +static inline
9321 +int v6_addr_match(struct nx_addr_v6 *nxa,
9322 +       const struct in6_addr *addr, uint16_t mask)
9323 +{
9324 +       int ret = 0;
9325 +
9326 +       switch (nxa->type & mask) {
9327 +       case NXA_TYPE_MASK:
9328 +               ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9329 +               break;
9330 +       case NXA_TYPE_ADDR:
9331 +               ret = ipv6_addr_equal(&nxa->ip, addr);
9332 +               break;
9333 +       case NXA_TYPE_ANY:
9334 +               ret = 1;
9335 +               break;
9336 +       }
9337 +       vxdprintk(VXD_CBIT(net, 0),
9338 +               "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9339 +               nxa, NXAV6(nxa), addr, mask, ret);
9340 +       return ret;
9341 +}
9342 +
9343 +static inline
9344 +int v6_addr_in_nx_info(struct nx_info *nxi,
9345 +       const struct in6_addr *addr, uint16_t mask)
9346 +{
9347 +       struct nx_addr_v6 *nxa;
9348 +       unsigned long irqflags;
9349 +       int ret = 1;
9350 +
9351 +       if (!nxi)
9352 +               goto out;
9353 +
9354 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9355 +       for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9356 +               if (v6_addr_match(nxa, addr, mask))
9357 +                       goto out_unlock;
9358 +       ret = 0;
9359 +out_unlock:
9360 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9361 +out:
9362 +       vxdprintk(VXD_CBIT(net, 0),
9363 +               "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9364 +               nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9365 +       return ret;
9366 +}
9367 +
9368 +static inline
9369 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9370 +{
9371 +       /* FIXME: needs full range checks */
9372 +       return v6_addr_match(nxa, &addr->ip, mask);
9373 +}
9374 +
9375 +static inline
9376 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9377 +{
9378 +       struct nx_addr_v6 *ptr;
9379 +       unsigned long irqflags;
9380 +       int ret = 1;
9381 +
9382 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
9383 +       for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9384 +               if (v6_nx_addr_match(ptr, nxa, mask))
9385 +                       goto out_unlock;
9386 +       ret = 0;
9387 +out_unlock:
9388 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9389 +       return ret;
9390 +}
9391 +
9392 +
9393 +/*
9394 + *     Check if a given address matches for a socket
9395 + *
9396 + *     nxi:            the socket's nx_info if any
9397 + *     addr:           to be verified address
9398 + */
9399 +static inline
9400 +int v6_sock_addr_match (
9401 +       struct nx_info *nxi,
9402 +       struct inet_sock *inet,
9403 +       struct in6_addr *addr)
9404 +{
9405 +       struct sock *sk = &inet->sk;
9406 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9407 +
9408 +       if (!ipv6_addr_any(addr) &&
9409 +               ipv6_addr_equal(saddr, addr))
9410 +               return 1;
9411 +       if (ipv6_addr_any(saddr))
9412 +               return v6_addr_in_nx_info(nxi, addr, -1);
9413 +       return 0;
9414 +}
9415 +
9416 +/*
9417 + *     check if address is covered by socket
9418 + *
9419 + *     sk:     the socket to check against
9420 + *     addr:   the address in question (must be != 0)
9421 + */
9422 +
9423 +static inline
9424 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9425 +{
9426 +       struct nx_info *nxi = sk->sk_nx_info;
9427 +       struct in6_addr *saddr = inet6_rcv_saddr(sk);
9428 +
9429 +       vxdprintk(VXD_CBIT(net, 5),
9430 +               "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9431 +               sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9432 +               (sk->sk_socket?sk->sk_socket->flags:0));
9433 +
9434 +       if (!ipv6_addr_any(saddr)) {    /* direct address match */
9435 +               return v6_addr_match(nxa, saddr, -1);
9436 +       } else if (nxi) {               /* match against nx_info */
9437 +               return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9438 +       } else {                        /* unrestricted any socket */
9439 +               return 1;
9440 +       }
9441 +}
9442 +
9443 +
9444 +/* inet related checks and helpers */
9445 +
9446 +
9447 +struct in_ifaddr;
9448 +struct net_device;
9449 +struct sock;
9450 +
9451 +
9452 +#include <linux/netdevice.h>
9453 +#include <linux/inetdevice.h>
9454 +#include <net/inet_timewait_sock.h>
9455 +
9456 +
9457 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9458 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9459 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9460 +
9461 +
9462 +
9463 +static inline
9464 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9465 +{
9466 +       if (!nxi)
9467 +               return 1;
9468 +       if (!ifa)
9469 +               return 0;
9470 +       return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9471 +}
9472 +
9473 +static inline
9474 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9475 +{
9476 +       vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9477 +               nxi, nxi ? nxi->nx_id : 0, ifa,
9478 +               nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9479 +
9480 +       if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9481 +               return 1;
9482 +       if (v6_ifa_in_nx_info(ifa, nxi))
9483 +               return 1;
9484 +       return 0;
9485 +}
9486 +
9487 +
9488 +struct nx_v6_sock_addr {
9489 +       struct in6_addr saddr;  /* Address used for validation */
9490 +       struct in6_addr baddr;  /* Address used for socket bind */
9491 +};
9492 +
9493 +static inline
9494 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9495 +       struct nx_v6_sock_addr *nsa)
9496 +{
9497 +       // struct sock *sk = &inet->sk;
9498 +       // struct nx_info *nxi = sk->sk_nx_info;
9499 +       struct in6_addr saddr = addr->sin6_addr;
9500 +       struct in6_addr baddr = saddr;
9501 +
9502 +       nsa->saddr = saddr;
9503 +       nsa->baddr = baddr;
9504 +       return 0;
9505 +}
9506 +
9507 +static inline
9508 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9509 +{
9510 +       // struct sock *sk = &inet->sk;
9511 +       // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9512 +
9513 +       // *saddr = nsa->baddr;
9514 +       // inet->inet_saddr = nsa->baddr;
9515 +}
9516 +
9517 +static inline
9518 +int nx_info_has_v6(struct nx_info *nxi)
9519 +{
9520 +       if (!nxi)
9521 +               return 1;
9522 +       if (NX_IPV6(nxi))
9523 +               return 1;
9524 +       return 0;
9525 +}
9526 +
9527 +#else /* CONFIG_IPV6 */
9528 +
9529 +static inline
9530 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9531 +{
9532 +       return 1;
9533 +}
9534 +
9535 +
9536 +static inline
9537 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9538 +{
9539 +       return 1;
9540 +}
9541 +
9542 +static inline
9543 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9544 +{
9545 +       return 1;
9546 +}
9547 +
9548 +static inline
9549 +int nx_info_has_v6(struct nx_info *nxi)
9550 +{
9551 +       return 0;
9552 +}
9553 +
9554 +#endif /* CONFIG_IPV6 */
9555 +
9556 +#define current_nx_info_has_v6() \
9557 +       nx_info_has_v6(current_nx_info())
9558 +
9559 +#else
9560 +#warning duplicate inclusion
9561 +#endif
9562 diff -NurpP --minimal linux-3.10.40/include/linux/vs_limit.h linux-3.10.40-vs2.3.6.8/include/linux/vs_limit.h
9563 --- linux-3.10.40/include/linux/vs_limit.h      1970-01-01 00:00:00.000000000 +0000
9564 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_limit.h    2013-08-22 20:30:00.000000000 +0000
9565 @@ -0,0 +1,140 @@
9566 +#ifndef _VS_LIMIT_H
9567 +#define _VS_LIMIT_H
9568 +
9569 +#include "vserver/limit.h"
9570 +#include "vserver/base.h"
9571 +#include "vserver/context.h"
9572 +#include "vserver/debug.h"
9573 +#include "vserver/context.h"
9574 +#include "vserver/limit_int.h"
9575 +
9576 +
9577 +#define vx_acc_cres(v, d, p, r) \
9578 +       __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9579 +
9580 +#define vx_acc_cres_cond(x, d, p, r) \
9581 +       __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9582 +       r, d, p, __FILE__, __LINE__)
9583 +
9584 +
9585 +#define vx_add_cres(v, a, p, r) \
9586 +       __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9587 +#define vx_sub_cres(v, a, p, r)                vx_add_cres(v, -(a), p, r)
9588 +
9589 +#define vx_add_cres_cond(x, a, p, r) \
9590 +       __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9591 +       r, a, p, __FILE__, __LINE__)
9592 +#define vx_sub_cres_cond(x, a, p, r)   vx_add_cres_cond(x, -(a), p, r)
9593 +
9594 +
9595 +/* process and file limits */
9596 +
9597 +#define vx_nproc_inc(p) \
9598 +       vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9599 +
9600 +#define vx_nproc_dec(p) \
9601 +       vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9602 +
9603 +#define vx_files_inc(f) \
9604 +       vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9605 +
9606 +#define vx_files_dec(f) \
9607 +       vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9608 +
9609 +#define vx_locks_inc(l) \
9610 +       vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9611 +
9612 +#define vx_locks_dec(l) \
9613 +       vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9614 +
9615 +#define vx_openfd_inc(f) \
9616 +       vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9617 +
9618 +#define vx_openfd_dec(f) \
9619 +       vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9620 +
9621 +
9622 +#define vx_cres_avail(v, n, r) \
9623 +       __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9624 +
9625 +
9626 +#define vx_nproc_avail(n) \
9627 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9628 +
9629 +#define vx_files_avail(n) \
9630 +       vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9631 +
9632 +#define vx_locks_avail(n) \
9633 +       vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9634 +
9635 +#define vx_openfd_avail(n) \
9636 +       vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9637 +
9638 +
9639 +/* dentry limits */
9640 +
9641 +#define vx_dentry_inc(d) do {                                          \
9642 +       if ((d)->d_count == 1)                                          \
9643 +               vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY);    \
9644 +       } while (0)
9645 +
9646 +#define vx_dentry_dec(d) do {                                          \
9647 +       if ((d)->d_count == 0)                                          \
9648 +               vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY);    \
9649 +       } while (0)
9650 +
9651 +#define vx_dentry_avail(n) \
9652 +       vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9653 +
9654 +
9655 +/* socket limits */
9656 +
9657 +#define vx_sock_inc(s) \
9658 +       vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9659 +
9660 +#define vx_sock_dec(s) \
9661 +       vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9662 +
9663 +#define vx_sock_avail(n) \
9664 +       vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9665 +
9666 +
9667 +/* ipc resource limits */
9668 +
9669 +#define vx_ipcmsg_add(v, u, a) \
9670 +       vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9671 +
9672 +#define vx_ipcmsg_sub(v, u, a) \
9673 +       vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9674 +
9675 +#define vx_ipcmsg_avail(v, a) \
9676 +       vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9677 +
9678 +
9679 +#define vx_ipcshm_add(v, k, a) \
9680 +       vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9681 +
9682 +#define vx_ipcshm_sub(v, k, a) \
9683 +       vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9684 +
9685 +#define vx_ipcshm_avail(v, a) \
9686 +       vx_cres_avail(v, a, VLIMIT_SHMEM)
9687 +
9688 +
9689 +#define vx_semary_inc(a) \
9690 +       vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9691 +
9692 +#define vx_semary_dec(a) \
9693 +       vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9694 +
9695 +
9696 +#define vx_nsems_add(a,n) \
9697 +       vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9698 +
9699 +#define vx_nsems_sub(a,n) \
9700 +       vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9701 +
9702 +
9703 +#else
9704 +#warning duplicate inclusion
9705 +#endif
9706 diff -NurpP --minimal linux-3.10.40/include/linux/vs_network.h linux-3.10.40-vs2.3.6.8/include/linux/vs_network.h
9707 --- linux-3.10.40/include/linux/vs_network.h    1970-01-01 00:00:00.000000000 +0000
9708 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_network.h  2013-08-22 20:30:00.000000000 +0000
9709 @@ -0,0 +1,169 @@
9710 +#ifndef _NX_VS_NETWORK_H
9711 +#define _NX_VS_NETWORK_H
9712 +
9713 +#include "vserver/context.h"
9714 +#include "vserver/network.h"
9715 +#include "vserver/base.h"
9716 +#include "vserver/check.h"
9717 +#include "vserver/debug.h"
9718 +
9719 +#include <linux/sched.h>
9720 +
9721 +
9722 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9723 +
9724 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9725 +       const char *_file, int _line)
9726 +{
9727 +       if (!nxi)
9728 +               return NULL;
9729 +
9730 +       vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9731 +               nxi, nxi ? nxi->nx_id : 0,
9732 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9733 +               _file, _line);
9734 +
9735 +       atomic_inc(&nxi->nx_usecnt);
9736 +       return nxi;
9737 +}
9738 +
9739 +
9740 +extern void free_nx_info(struct nx_info *);
9741 +
9742 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9743 +
9744 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9745 +{
9746 +       if (!nxi)
9747 +               return;
9748 +
9749 +       vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9750 +               nxi, nxi ? nxi->nx_id : 0,
9751 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9752 +               _file, _line);
9753 +
9754 +       if (atomic_dec_and_test(&nxi->nx_usecnt))
9755 +               free_nx_info(nxi);
9756 +}
9757 +
9758 +
9759 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9760 +
9761 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9762 +               const char *_file, int _line)
9763 +{
9764 +       if (nxi) {
9765 +               vxlprintk(VXD_CBIT(nid, 3),
9766 +                       "init_nx_info(%p[#%d.%d])",
9767 +                       nxi, nxi ? nxi->nx_id : 0,
9768 +                       nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9769 +                       _file, _line);
9770 +
9771 +               atomic_inc(&nxi->nx_usecnt);
9772 +       }
9773 +       *nxp = nxi;
9774 +}
9775 +
9776 +
9777 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9778 +
9779 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9780 +       const char *_file, int _line)
9781 +{
9782 +       struct nx_info *nxo;
9783 +
9784 +       if (!nxi)
9785 +               return;
9786 +
9787 +       vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9788 +               nxi, nxi ? nxi->nx_id : 0,
9789 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9790 +               _file, _line);
9791 +
9792 +       atomic_inc(&nxi->nx_usecnt);
9793 +       nxo = xchg(nxp, nxi);
9794 +       BUG_ON(nxo);
9795 +}
9796 +
9797 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9798 +
9799 +static inline void __clr_nx_info(struct nx_info **nxp,
9800 +       const char *_file, int _line)
9801 +{
9802 +       struct nx_info *nxo;
9803 +
9804 +       nxo = xchg(nxp, NULL);
9805 +       if (!nxo)
9806 +               return;
9807 +
9808 +       vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9809 +               nxo, nxo ? nxo->nx_id : 0,
9810 +               nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9811 +               _file, _line);
9812 +
9813 +       if (atomic_dec_and_test(&nxo->nx_usecnt))
9814 +               free_nx_info(nxo);
9815 +}
9816 +
9817 +
9818 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9819 +
9820 +static inline void __claim_nx_info(struct nx_info *nxi,
9821 +       struct task_struct *task, const char *_file, int _line)
9822 +{
9823 +       vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9824 +               nxi, nxi ? nxi->nx_id : 0,
9825 +               nxi?atomic_read(&nxi->nx_usecnt):0,
9826 +               nxi?atomic_read(&nxi->nx_tasks):0,
9827 +               task, _file, _line);
9828 +
9829 +       atomic_inc(&nxi->nx_tasks);
9830 +}
9831 +
9832 +
9833 +extern void unhash_nx_info(struct nx_info *);
9834 +
9835 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9836 +
9837 +static inline void __release_nx_info(struct nx_info *nxi,
9838 +       struct task_struct *task, const char *_file, int _line)
9839 +{
9840 +       vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9841 +               nxi, nxi ? nxi->nx_id : 0,
9842 +               nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9843 +               nxi ? atomic_read(&nxi->nx_tasks) : 0,
9844 +               task, _file, _line);
9845 +
9846 +       might_sleep();
9847 +
9848 +       if (atomic_dec_and_test(&nxi->nx_tasks))
9849 +               unhash_nx_info(nxi);
9850 +}
9851 +
9852 +
9853 +#define task_get_nx_info(i)    __task_get_nx_info(i, __FILE__, __LINE__)
9854 +
9855 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9856 +       const char *_file, int _line)
9857 +{
9858 +       struct nx_info *nxi;
9859 +
9860 +       task_lock(p);
9861 +       vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9862 +               p, _file, _line);
9863 +       nxi = __get_nx_info(p->nx_info, _file, _line);
9864 +       task_unlock(p);
9865 +       return nxi;
9866 +}
9867 +
9868 +
9869 +static inline void exit_nx_info(struct task_struct *p)
9870 +{
9871 +       if (p->nx_info)
9872 +               release_nx_info(p->nx_info, p);
9873 +}
9874 +
9875 +
9876 +#else
9877 +#warning duplicate inclusion
9878 +#endif
9879 diff -NurpP --minimal linux-3.10.40/include/linux/vs_pid.h linux-3.10.40-vs2.3.6.8/include/linux/vs_pid.h
9880 --- linux-3.10.40/include/linux/vs_pid.h        1970-01-01 00:00:00.000000000 +0000
9881 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_pid.h      2013-08-22 20:30:00.000000000 +0000
9882 @@ -0,0 +1,50 @@
9883 +#ifndef _VS_PID_H
9884 +#define _VS_PID_H
9885 +
9886 +#include "vserver/base.h"
9887 +#include "vserver/check.h"
9888 +#include "vserver/context.h"
9889 +#include "vserver/debug.h"
9890 +#include "vserver/pid.h"
9891 +#include <linux/pid_namespace.h>
9892 +
9893 +
9894 +#define VXF_FAKE_INIT  (VXF_INFO_INIT | VXF_STATE_INIT)
9895 +
9896 +static inline
9897 +int vx_proc_task_visible(struct task_struct *task)
9898 +{
9899 +       if ((task->pid == 1) &&
9900 +               !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9901 +               /* show a blend through init */
9902 +               goto visible;
9903 +       if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9904 +               goto visible;
9905 +       return 0;
9906 +visible:
9907 +       return 1;
9908 +}
9909 +
9910 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9911 +
9912 +
9913 +static inline
9914 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9915 +{
9916 +       struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9917 +
9918 +       if (task && !vx_proc_task_visible(task)) {
9919 +               vxdprintk(VXD_CBIT(misc, 6),
9920 +                       "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9921 +                       task, task->xid, task->pid,
9922 +                       current, current->xid, current->pid);
9923 +               put_task_struct(task);
9924 +               task = NULL;
9925 +       }
9926 +       return task;
9927 +}
9928 +
9929 +
9930 +#else
9931 +#warning duplicate inclusion
9932 +#endif
9933 diff -NurpP --minimal linux-3.10.40/include/linux/vs_sched.h linux-3.10.40-vs2.3.6.8/include/linux/vs_sched.h
9934 --- linux-3.10.40/include/linux/vs_sched.h      1970-01-01 00:00:00.000000000 +0000
9935 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_sched.h    2013-08-22 20:30:00.000000000 +0000
9936 @@ -0,0 +1,40 @@
9937 +#ifndef _VS_SCHED_H
9938 +#define _VS_SCHED_H
9939 +
9940 +#include "vserver/base.h"
9941 +#include "vserver/context.h"
9942 +#include "vserver/sched.h"
9943 +
9944 +
9945 +#define MAX_PRIO_BIAS           20
9946 +#define MIN_PRIO_BIAS          -20
9947 +
9948 +static inline
9949 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
9950 +{
9951 +       struct vx_info *vxi = p->vx_info;
9952 +
9953 +       if (vxi)
9954 +               prio += vx_cpu(vxi, sched_pc).prio_bias;
9955 +       return prio;
9956 +}
9957 +
9958 +static inline void vx_account_user(struct vx_info *vxi,
9959 +       cputime_t cputime, int nice)
9960 +{
9961 +       if (!vxi)
9962 +               return;
9963 +       vx_cpu(vxi, sched_pc).user_ticks += cputime;
9964 +}
9965 +
9966 +static inline void vx_account_system(struct vx_info *vxi,
9967 +       cputime_t cputime, int idle)
9968 +{
9969 +       if (!vxi)
9970 +               return;
9971 +       vx_cpu(vxi, sched_pc).sys_ticks += cputime;
9972 +}
9973 +
9974 +#else
9975 +#warning duplicate inclusion
9976 +#endif
9977 diff -NurpP --minimal linux-3.10.40/include/linux/vs_socket.h linux-3.10.40-vs2.3.6.8/include/linux/vs_socket.h
9978 --- linux-3.10.40/include/linux/vs_socket.h     1970-01-01 00:00:00.000000000 +0000
9979 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_socket.h   2013-08-22 20:30:00.000000000 +0000
9980 @@ -0,0 +1,67 @@
9981 +#ifndef _VS_SOCKET_H
9982 +#define _VS_SOCKET_H
9983 +
9984 +#include "vserver/debug.h"
9985 +#include "vserver/base.h"
9986 +#include "vserver/cacct.h"
9987 +#include "vserver/context.h"
9988 +#include "vserver/tag.h"
9989 +
9990 +
9991 +/* socket accounting */
9992 +
9993 +#include <linux/socket.h>
9994 +
9995 +static inline int vx_sock_type(int family)
9996 +{
9997 +       switch (family) {
9998 +       case PF_UNSPEC:
9999 +               return VXA_SOCK_UNSPEC;
10000 +       case PF_UNIX:
10001 +               return VXA_SOCK_UNIX;
10002 +       case PF_INET:
10003 +               return VXA_SOCK_INET;
10004 +       case PF_INET6:
10005 +               return VXA_SOCK_INET6;
10006 +       case PF_PACKET:
10007 +               return VXA_SOCK_PACKET;
10008 +       default:
10009 +               return VXA_SOCK_OTHER;
10010 +       }
10011 +}
10012 +
10013 +#define vx_acc_sock(v, f, p, s) \
10014 +       __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10015 +
10016 +static inline void __vx_acc_sock(struct vx_info *vxi,
10017 +       int family, int pos, int size, char *file, int line)
10018 +{
10019 +       if (vxi) {
10020 +               int type = vx_sock_type(family);
10021 +
10022 +               atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10023 +               atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10024 +       }
10025 +}
10026 +
10027 +#define vx_sock_recv(sk, s) \
10028 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10029 +#define vx_sock_send(sk, s) \
10030 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10031 +#define vx_sock_fail(sk, s) \
10032 +       vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10033 +
10034 +
10035 +#define sock_vx_init(s) do {           \
10036 +       (s)->sk_xid = 0;                \
10037 +       (s)->sk_vx_info = NULL;         \
10038 +       } while (0)
10039 +
10040 +#define sock_nx_init(s) do {           \
10041 +       (s)->sk_nid = 0;                \
10042 +       (s)->sk_nx_info = NULL;         \
10043 +       } while (0)
10044 +
10045 +#else
10046 +#warning duplicate inclusion
10047 +#endif
10048 diff -NurpP --minimal linux-3.10.40/include/linux/vs_tag.h linux-3.10.40-vs2.3.6.8/include/linux/vs_tag.h
10049 --- linux-3.10.40/include/linux/vs_tag.h        1970-01-01 00:00:00.000000000 +0000
10050 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_tag.h      2013-08-22 20:30:00.000000000 +0000
10051 @@ -0,0 +1,47 @@
10052 +#ifndef _VS_TAG_H
10053 +#define _VS_TAG_H
10054 +
10055 +#include <linux/vserver/tag.h>
10056 +
10057 +/* check conditions */
10058 +
10059 +#define DX_ADMIN       0x0001
10060 +#define DX_WATCH       0x0002
10061 +#define DX_HOSTID      0x0008
10062 +
10063 +#define DX_IDENT       0x0010
10064 +
10065 +#define DX_ARG_MASK    0x0010
10066 +
10067 +
10068 +#define dx_task_tag(t) ((t)->tag)
10069 +
10070 +#define dx_current_tag() dx_task_tag(current)
10071 +
10072 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10073 +
10074 +#define dx_weak_check(c, m)    ((m) ? dx_check(c, m) : 1)
10075 +
10076 +
10077 +/*
10078 + * check current context for ADMIN/WATCH and
10079 + * optionally against supplied argument
10080 + */
10081 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
10082 +{
10083 +       if (mode & DX_ARG_MASK) {
10084 +               if ((mode & DX_IDENT) && (id == cid))
10085 +                       return 1;
10086 +       }
10087 +       return (((mode & DX_ADMIN) && (cid == 0)) ||
10088 +               ((mode & DX_WATCH) && (cid == 1)) ||
10089 +               ((mode & DX_HOSTID) && (id == 0)));
10090 +}
10091 +
10092 +struct inode;
10093 +int dx_permission(const struct inode *inode, int mask);
10094 +
10095 +
10096 +#else
10097 +#warning duplicate inclusion
10098 +#endif
10099 diff -NurpP --minimal linux-3.10.40/include/linux/vs_time.h linux-3.10.40-vs2.3.6.8/include/linux/vs_time.h
10100 --- linux-3.10.40/include/linux/vs_time.h       1970-01-01 00:00:00.000000000 +0000
10101 +++ linux-3.10.40-vs2.3.6.8/include/linux/vs_time.h     2013-08-22 20:30:00.000000000 +0000
10102 @@ -0,0 +1,19 @@
10103 +#ifndef _VS_TIME_H
10104 +#define _VS_TIME_H
10105 +
10106 +
10107 +/* time faking stuff */
10108 +
10109 +#ifdef CONFIG_VSERVER_VTIME
10110 +
10111 +extern void vx_adjust_timespec(struct timespec *ts);
10112 +extern int vx_settimeofday(const struct timespec *ts);
10113 +
10114 +#else
10115 +#define        vx_adjust_timespec(t)   do { } while (0)
10116 +#define        vx_settimeofday(t)      do_settimeofday(t)
10117 +#endif
10118 +
10119 +#else
10120 +#warning duplicate inclusion
10121 +#endif
10122 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/base.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/base.h
10123 --- linux-3.10.40/include/linux/vserver/base.h  1970-01-01 00:00:00.000000000 +0000
10124 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/base.h        2013-10-27 03:40:46.000000000 +0000
10125 @@ -0,0 +1,184 @@
10126 +#ifndef _VSERVER_BASE_H
10127 +#define _VSERVER_BASE_H
10128 +
10129 +
10130 +/* context state changes */
10131 +
10132 +enum {
10133 +       VSC_STARTUP = 1,
10134 +       VSC_SHUTDOWN,
10135 +
10136 +       VSC_NETUP,
10137 +       VSC_NETDOWN,
10138 +};
10139 +
10140 +
10141 +
10142 +#define vx_task_xid(t) ((t)->xid)
10143 +
10144 +#define vx_current_xid() vx_task_xid(current)
10145 +
10146 +#define current_vx_info() (current->vx_info)
10147 +
10148 +
10149 +#define nx_task_nid(t) ((t)->nid)
10150 +
10151 +#define nx_current_nid() nx_task_nid(current)
10152 +
10153 +#define current_nx_info() (current->nx_info)
10154 +
10155 +
10156 +/* generic flag merging */
10157 +
10158 +#define vs_check_flags(v, m, f)        (((v) & (m)) ^ (f))
10159 +
10160 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10161 +
10162 +#define vs_mask_mask(v, f, m)  (((v) & ~(m)) | ((v) & (f) & (m)))
10163 +
10164 +#define vs_check_bit(v, n)     ((v) & (1LL << (n)))
10165 +
10166 +
10167 +/* context flags */
10168 +
10169 +#define __vx_flags(v)  ((v) ? (v)->vx_flags : 0)
10170 +
10171 +#define vx_current_flags()     __vx_flags(current_vx_info())
10172 +
10173 +#define vx_info_flags(v, m, f) \
10174 +       vs_check_flags(__vx_flags(v), m, f)
10175 +
10176 +#define task_vx_flags(t, m, f) \
10177 +       ((t) && vx_info_flags((t)->vx_info, m, f))
10178 +
10179 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10180 +
10181 +
10182 +/* context caps */
10183 +
10184 +#define __vx_ccaps(v)  ((v) ? (v)->vx_ccaps : 0)
10185 +
10186 +#define vx_current_ccaps()     __vx_ccaps(current_vx_info())
10187 +
10188 +#define vx_info_ccaps(v, c)    (__vx_ccaps(v) & (c))
10189 +
10190 +#define vx_ccaps(c)    vx_info_ccaps(current_vx_info(), (c))
10191 +
10192 +
10193 +
10194 +/* network flags */
10195 +
10196 +#define __nx_flags(n)  ((n) ? (n)->nx_flags : 0)
10197 +
10198 +#define nx_current_flags()     __nx_flags(current_nx_info())
10199 +
10200 +#define nx_info_flags(n, m, f) \
10201 +       vs_check_flags(__nx_flags(n), m, f)
10202 +
10203 +#define task_nx_flags(t, m, f) \
10204 +       ((t) && nx_info_flags((t)->nx_info, m, f))
10205 +
10206 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10207 +
10208 +
10209 +/* network caps */
10210 +
10211 +#define __nx_ncaps(n)  ((n) ? (n)->nx_ncaps : 0)
10212 +
10213 +#define nx_current_ncaps()     __nx_ncaps(current_nx_info())
10214 +
10215 +#define nx_info_ncaps(n, c)    (__nx_ncaps(n) & (c))
10216 +
10217 +#define nx_ncaps(c)    nx_info_ncaps(current_nx_info(), c)
10218 +
10219 +
10220 +/* context mask capabilities */
10221 +
10222 +#define __vx_mcaps(v)  ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10223 +
10224 +#define vx_info_mcaps(v, c)    (__vx_mcaps(v) & (c))
10225 +
10226 +#define vx_mcaps(c)    vx_info_mcaps(current_vx_info(), c)
10227 +
10228 +
10229 +/* context bcap mask */
10230 +
10231 +#define __vx_bcaps(v)          ((v)->vx_bcaps)
10232 +
10233 +#define vx_current_bcaps()     __vx_bcaps(current_vx_info())
10234 +
10235 +
10236 +/* mask given bcaps */
10237 +
10238 +#define vx_info_mbcaps(v, c)   ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10239 +
10240 +#define vx_mbcaps(c)           vx_info_mbcaps(current_vx_info(), c)
10241 +
10242 +
10243 +/* masked cap_bset */
10244 +
10245 +#define vx_info_cap_bset(v)    vx_info_mbcaps(v, current->cap_bset)
10246 +
10247 +#define vx_current_cap_bset()  vx_info_cap_bset(current_vx_info())
10248 +
10249 +#if 0
10250 +#define vx_info_mbcap(v, b) \
10251 +       (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10252 +       vx_info_bcaps(v, b) : (b))
10253 +
10254 +#define task_vx_mbcap(t, b) \
10255 +       vx_info_mbcap((t)->vx_info, (t)->b)
10256 +
10257 +#define vx_mbcap(b)    task_vx_mbcap(current, b)
10258 +#endif
10259 +
10260 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10261 +
10262 +#define vx_capable(b, c) (capable(b) || \
10263 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10264 +
10265 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10266 +       (cap_raised(current_cap(), b) && vx_ccaps(c)))
10267 +
10268 +#define nx_capable(b, c) (capable(b) || \
10269 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10270 +
10271 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
10272 +       (cap_raised(current_cap(), b) && nx_ncaps(c)))
10273 +
10274 +#define vx_task_initpid(t, n) \
10275 +       ((t)->vx_info && \
10276 +       ((t)->vx_info->vx_initpid == (n)))
10277 +
10278 +#define vx_current_initpid(n)  vx_task_initpid(current, n)
10279 +
10280 +
10281 +/* context unshare mask */
10282 +
10283 +#define __vx_umask(v)          ((v)->vx_umask)
10284 +
10285 +#define vx_current_umask()     __vx_umask(current_vx_info())
10286 +
10287 +#define vx_can_unshare(b, f) (capable(b) || \
10288 +       (cap_raised(current_cap(), b) && \
10289 +       !((f) & ~vx_current_umask())))
10290 +
10291 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
10292 +       (cap_raised(current_cap(), b) && \
10293 +       !((f) & ~vx_current_umask())))
10294 +
10295 +#define __vx_wmask(v)          ((v)->vx_wmask)
10296 +
10297 +#define vx_current_wmask()     __vx_wmask(current_vx_info())
10298 +
10299 +
10300 +#define __vx_state(v)  ((v) ? ((v)->vx_state) : 0)
10301 +
10302 +#define vx_info_state(v, m)    (__vx_state(v) & (m))
10303 +
10304 +
10305 +#define __nx_state(n)  ((n) ? ((n)->nx_state) : 0)
10306 +
10307 +#define nx_info_state(n, m)    (__nx_state(n) & (m))
10308 +
10309 +#endif
10310 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/cacct.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/cacct.h
10311 --- linux-3.10.40/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
10312 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/cacct.h       2013-08-22 20:30:00.000000000 +0000
10313 @@ -0,0 +1,15 @@
10314 +#ifndef _VSERVER_CACCT_H
10315 +#define _VSERVER_CACCT_H
10316 +
10317 +
10318 +enum sock_acc_field {
10319 +       VXA_SOCK_UNSPEC = 0,
10320 +       VXA_SOCK_UNIX,
10321 +       VXA_SOCK_INET,
10322 +       VXA_SOCK_INET6,
10323 +       VXA_SOCK_PACKET,
10324 +       VXA_SOCK_OTHER,
10325 +       VXA_SOCK_SIZE   /* array size */
10326 +};
10327 +
10328 +#endif /* _VSERVER_CACCT_H */
10329 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/cacct_cmd.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/cacct_cmd.h
10330 --- linux-3.10.40/include/linux/vserver/cacct_cmd.h     1970-01-01 00:00:00.000000000 +0000
10331 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/cacct_cmd.h   2013-08-22 20:30:00.000000000 +0000
10332 @@ -0,0 +1,10 @@
10333 +#ifndef _VSERVER_CACCT_CMD_H
10334 +#define _VSERVER_CACCT_CMD_H
10335 +
10336 +
10337 +#include <linux/compiler.h>
10338 +#include <uapi/vserver/cacct_cmd.h>
10339 +
10340 +extern int vc_sock_stat(struct vx_info *, void __user *);
10341 +
10342 +#endif /* _VSERVER_CACCT_CMD_H */
10343 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/cacct_def.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/cacct_def.h
10344 --- linux-3.10.40/include/linux/vserver/cacct_def.h     1970-01-01 00:00:00.000000000 +0000
10345 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/cacct_def.h   2013-08-22 20:30:00.000000000 +0000
10346 @@ -0,0 +1,43 @@
10347 +#ifndef _VSERVER_CACCT_DEF_H
10348 +#define _VSERVER_CACCT_DEF_H
10349 +
10350 +#include <asm/atomic.h>
10351 +#include <linux/vserver/cacct.h>
10352 +
10353 +
10354 +struct _vx_sock_acc {
10355 +       atomic_long_t count;
10356 +       atomic_long_t total;
10357 +};
10358 +
10359 +/* context sub struct */
10360 +
10361 +struct _vx_cacct {
10362 +       struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10363 +       atomic_t slab[8];
10364 +       atomic_t page[6][8];
10365 +};
10366 +
10367 +#ifdef CONFIG_VSERVER_DEBUG
10368 +
10369 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10370 +{
10371 +       int i, j;
10372 +
10373 +       printk("\t_vx_cacct:");
10374 +       for (i = 0; i < 6; i++) {
10375 +               struct _vx_sock_acc *ptr = cacct->sock[i];
10376 +
10377 +               printk("\t [%d] =", i);
10378 +               for (j = 0; j < 3; j++) {
10379 +                       printk(" [%d] = %8lu, %8lu", j,
10380 +                               atomic_long_read(&ptr[j].count),
10381 +                               atomic_long_read(&ptr[j].total));
10382 +               }
10383 +               printk("\n");
10384 +       }
10385 +}
10386 +
10387 +#endif
10388 +
10389 +#endif /* _VSERVER_CACCT_DEF_H */
10390 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/cacct_int.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/cacct_int.h
10391 --- linux-3.10.40/include/linux/vserver/cacct_int.h     1970-01-01 00:00:00.000000000 +0000
10392 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/cacct_int.h   2013-08-22 20:30:00.000000000 +0000
10393 @@ -0,0 +1,17 @@
10394 +#ifndef _VSERVER_CACCT_INT_H
10395 +#define _VSERVER_CACCT_INT_H
10396 +
10397 +static inline
10398 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10399 +{
10400 +       return atomic_long_read(&cacct->sock[type][pos].count);
10401 +}
10402 +
10403 +
10404 +static inline
10405 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10406 +{
10407 +       return atomic_long_read(&cacct->sock[type][pos].total);
10408 +}
10409 +
10410 +#endif /* _VSERVER_CACCT_INT_H */
10411 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/check.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/check.h
10412 --- linux-3.10.40/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
10413 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/check.h       2013-08-22 20:30:00.000000000 +0000
10414 @@ -0,0 +1,89 @@
10415 +#ifndef _VSERVER_CHECK_H
10416 +#define _VSERVER_CHECK_H
10417 +
10418 +
10419 +#define MAX_S_CONTEXT  65535   /* Arbitrary limit */
10420 +
10421 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10422 +#define MIN_D_CONTEXT  49152   /* dynamic contexts start here */
10423 +#else
10424 +#define MIN_D_CONTEXT  65536
10425 +#endif
10426 +
10427 +/* check conditions */
10428 +
10429 +#define VS_ADMIN       0x0001
10430 +#define VS_WATCH       0x0002
10431 +#define VS_HIDE                0x0004
10432 +#define VS_HOSTID      0x0008
10433 +
10434 +#define VS_IDENT       0x0010
10435 +#define VS_EQUIV       0x0020
10436 +#define VS_PARENT      0x0040
10437 +#define VS_CHILD       0x0080
10438 +
10439 +#define VS_ARG_MASK    0x00F0
10440 +
10441 +#define VS_DYNAMIC     0x0100
10442 +#define VS_STATIC      0x0200
10443 +
10444 +#define VS_ATR_MASK    0x0F00
10445 +
10446 +#ifdef CONFIG_VSERVER_PRIVACY
10447 +#define VS_ADMIN_P     (0)
10448 +#define VS_WATCH_P     (0)
10449 +#else
10450 +#define VS_ADMIN_P     VS_ADMIN
10451 +#define VS_WATCH_P     VS_WATCH
10452 +#endif
10453 +
10454 +#define VS_HARDIRQ     0x1000
10455 +#define VS_SOFTIRQ     0x2000
10456 +#define VS_IRQ         0x4000
10457 +
10458 +#define VS_IRQ_MASK    0xF000
10459 +
10460 +#include <linux/hardirq.h>
10461 +
10462 +/*
10463 + * check current context for ADMIN/WATCH and
10464 + * optionally against supplied argument
10465 + */
10466 +static inline int __vs_check(int cid, int id, unsigned int mode)
10467 +{
10468 +       if (mode & VS_ARG_MASK) {
10469 +               if ((mode & VS_IDENT) && (id == cid))
10470 +                       return 1;
10471 +       }
10472 +       if (mode & VS_ATR_MASK) {
10473 +               if ((mode & VS_DYNAMIC) &&
10474 +                       (id >= MIN_D_CONTEXT) &&
10475 +                       (id <= MAX_S_CONTEXT))
10476 +                       return 1;
10477 +               if ((mode & VS_STATIC) &&
10478 +                       (id > 1) && (id < MIN_D_CONTEXT))
10479 +                       return 1;
10480 +       }
10481 +       if (mode & VS_IRQ_MASK) {
10482 +               if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10483 +                       return 1;
10484 +               if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10485 +                       return 1;
10486 +               if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10487 +                       return 1;
10488 +       }
10489 +       return (((mode & VS_ADMIN) && (cid == 0)) ||
10490 +               ((mode & VS_WATCH) && (cid == 1)) ||
10491 +               ((mode & VS_HOSTID) && (id == 0)));
10492 +}
10493 +
10494 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10495 +
10496 +#define vx_weak_check(c, m)    ((m) ? vx_check(c, m) : 1)
10497 +
10498 +
10499 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10500 +
10501 +#define nx_weak_check(c, m)    ((m) ? nx_check(c, m) : 1)
10502 +
10503 +#endif
10504 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/context.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/context.h
10505 --- linux-3.10.40/include/linux/vserver/context.h       1970-01-01 00:00:00.000000000 +0000
10506 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/context.h     2013-08-22 20:30:00.000000000 +0000
10507 @@ -0,0 +1,110 @@
10508 +#ifndef _VSERVER_CONTEXT_H
10509 +#define _VSERVER_CONTEXT_H
10510 +
10511 +
10512 +#include <linux/list.h>
10513 +#include <linux/spinlock.h>
10514 +#include <linux/rcupdate.h>
10515 +#include <uapi/vserver/context.h>
10516 +
10517 +#include "limit_def.h"
10518 +#include "sched_def.h"
10519 +#include "cvirt_def.h"
10520 +#include "cacct_def.h"
10521 +#include "device_def.h"
10522 +
10523 +#define VX_SPACES      2
10524 +
10525 +struct _vx_info_pc {
10526 +       struct _vx_sched_pc sched_pc;
10527 +       struct _vx_cvirt_pc cvirt_pc;
10528 +};
10529 +
10530 +struct _vx_space {
10531 +       unsigned long vx_nsmask;                /* assignment mask */
10532 +       struct nsproxy *vx_nsproxy;             /* private namespaces */
10533 +       struct fs_struct *vx_fs;                /* private namespace fs */
10534 +       const struct cred *vx_cred;             /* task credentials */
10535 +};
10536 +
10537 +struct vx_info {
10538 +       struct hlist_node vx_hlist;             /* linked list of contexts */
10539 +       vxid_t vx_id;                           /* context id */
10540 +       atomic_t vx_usecnt;                     /* usage count */
10541 +       atomic_t vx_tasks;                      /* tasks count */
10542 +       struct vx_info *vx_parent;              /* parent context */
10543 +       int vx_state;                           /* context state */
10544 +
10545 +       struct _vx_space space[VX_SPACES];      /* namespace store */
10546 +
10547 +       uint64_t vx_flags;                      /* context flags */
10548 +       uint64_t vx_ccaps;                      /* context caps (vserver) */
10549 +       uint64_t vx_umask;                      /* unshare mask (guest) */
10550 +       uint64_t vx_wmask;                      /* warn mask (guest) */
10551 +       kernel_cap_t vx_bcaps;                  /* bounding caps (system) */
10552 +
10553 +       struct task_struct *vx_reaper;          /* guest reaper process */
10554 +       pid_t vx_initpid;                       /* PID of guest init */
10555 +       int64_t vx_badness_bias;                /* OOM points bias */
10556 +
10557 +       struct _vx_limit limit;                 /* vserver limits */
10558 +       struct _vx_sched sched;                 /* vserver scheduler */
10559 +       struct _vx_cvirt cvirt;                 /* virtual/bias stuff */
10560 +       struct _vx_cacct cacct;                 /* context accounting */
10561 +
10562 +       struct _vx_device dmap;                 /* default device map targets */
10563 +
10564 +#ifndef CONFIG_SMP
10565 +       struct _vx_info_pc info_pc;             /* per cpu data */
10566 +#else
10567 +       struct _vx_info_pc *ptr_pc;             /* per cpu array */
10568 +#endif
10569 +
10570 +       wait_queue_head_t vx_wait;              /* context exit waitqueue */
10571 +       int reboot_cmd;                         /* last sys_reboot() cmd */
10572 +       int exit_code;                          /* last process exit code */
10573 +
10574 +       char vx_name[65];                       /* vserver name */
10575 +};
10576 +
10577 +#ifndef CONFIG_SMP
10578 +#define        vx_ptr_pc(vxi)          (&(vxi)->info_pc)
10579 +#define        vx_per_cpu(vxi, v, id)  vx_ptr_pc(vxi)->v
10580 +#else
10581 +#define        vx_ptr_pc(vxi)          ((vxi)->ptr_pc)
10582 +#define        vx_per_cpu(vxi, v, id)  per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10583 +#endif
10584 +
10585 +#define        vx_cpu(vxi, v)          vx_per_cpu(vxi, v, smp_processor_id())
10586 +
10587 +
10588 +struct vx_info_save {
10589 +       struct vx_info *vxi;
10590 +       vxid_t xid;
10591 +};
10592 +
10593 +
10594 +/* status flags */
10595 +
10596 +#define VXS_HASHED     0x0001
10597 +#define VXS_PAUSED     0x0010
10598 +#define VXS_SHUTDOWN   0x0100
10599 +#define VXS_HELPER     0x1000
10600 +#define VXS_RELEASED   0x8000
10601 +
10602 +
10603 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10604 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10605 +
10606 +extern struct vx_info *lookup_vx_info(int);
10607 +extern struct vx_info *lookup_or_create_vx_info(int);
10608 +
10609 +extern int get_xid_list(int, unsigned int *, int);
10610 +extern int xid_is_hashed(vxid_t);
10611 +
10612 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10613 +
10614 +extern long vs_state_change(struct vx_info *, unsigned int);
10615 +
10616 +
10617 +#endif /* _VSERVER_CONTEXT_H */
10618 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/context_cmd.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/context_cmd.h
10619 --- linux-3.10.40/include/linux/vserver/context_cmd.h   1970-01-01 00:00:00.000000000 +0000
10620 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/context_cmd.h 2013-08-22 20:30:00.000000000 +0000
10621 @@ -0,0 +1,33 @@
10622 +#ifndef _VSERVER_CONTEXT_CMD_H
10623 +#define _VSERVER_CONTEXT_CMD_H
10624 +
10625 +#include <uapi/vserver/context_cmd.h>
10626 +
10627 +extern int vc_task_xid(uint32_t);
10628 +
10629 +extern int vc_vx_info(struct vx_info *, void __user *);
10630 +
10631 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10632 +
10633 +extern int vc_ctx_create(uint32_t, void __user *);
10634 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10635 +
10636 +extern int vc_get_cflags(struct vx_info *, void __user *);
10637 +extern int vc_set_cflags(struct vx_info *, void __user *);
10638 +
10639 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10640 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10641 +
10642 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10643 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10644 +
10645 +extern int vc_get_umask(struct vx_info *, void __user *);
10646 +extern int vc_set_umask(struct vx_info *, void __user *);
10647 +
10648 +extern int vc_get_wmask(struct vx_info *, void __user *);
10649 +extern int vc_set_wmask(struct vx_info *, void __user *);
10650 +
10651 +extern int vc_get_badness(struct vx_info *, void __user *);
10652 +extern int vc_set_badness(struct vx_info *, void __user *);
10653 +
10654 +#endif /* _VSERVER_CONTEXT_CMD_H */
10655 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/cvirt.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/cvirt.h
10656 --- linux-3.10.40/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
10657 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/cvirt.h       2013-08-22 20:30:00.000000000 +0000
10658 @@ -0,0 +1,18 @@
10659 +#ifndef _VSERVER_CVIRT_H
10660 +#define _VSERVER_CVIRT_H
10661 +
10662 +struct timespec;
10663 +
10664 +void vx_vsi_boottime(struct timespec *);
10665 +
10666 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10667 +
10668 +
10669 +struct vx_info;
10670 +
10671 +void vx_update_load(struct vx_info *);
10672 +
10673 +
10674 +int vx_do_syslog(int, char __user *, int);
10675 +
10676 +#endif /* _VSERVER_CVIRT_H */
10677 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/cvirt_cmd.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/cvirt_cmd.h
10678 --- linux-3.10.40/include/linux/vserver/cvirt_cmd.h     1970-01-01 00:00:00.000000000 +0000
10679 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/cvirt_cmd.h   2013-08-22 20:30:00.000000000 +0000
10680 @@ -0,0 +1,13 @@
10681 +#ifndef _VSERVER_CVIRT_CMD_H
10682 +#define _VSERVER_CVIRT_CMD_H
10683 +
10684 +
10685 +#include <linux/compiler.h>
10686 +#include <uapi/vserver/cvirt_cmd.h>
10687 +
10688 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10689 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10690 +
10691 +extern int vc_virt_stat(struct vx_info *, void __user *);
10692 +
10693 +#endif /* _VSERVER_CVIRT_CMD_H */
10694 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/cvirt_def.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/cvirt_def.h
10695 --- linux-3.10.40/include/linux/vserver/cvirt_def.h     1970-01-01 00:00:00.000000000 +0000
10696 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/cvirt_def.h   2013-08-22 20:30:00.000000000 +0000
10697 @@ -0,0 +1,80 @@
10698 +#ifndef _VSERVER_CVIRT_DEF_H
10699 +#define _VSERVER_CVIRT_DEF_H
10700 +
10701 +#include <linux/jiffies.h>
10702 +#include <linux/spinlock.h>
10703 +#include <linux/wait.h>
10704 +#include <linux/time.h>
10705 +#include <asm/atomic.h>
10706 +
10707 +
10708 +struct _vx_usage_stat {
10709 +       uint64_t user;
10710 +       uint64_t nice;
10711 +       uint64_t system;
10712 +       uint64_t softirq;
10713 +       uint64_t irq;
10714 +       uint64_t idle;
10715 +       uint64_t iowait;
10716 +};
10717 +
10718 +struct _vx_syslog {
10719 +       wait_queue_head_t log_wait;
10720 +       spinlock_t logbuf_lock;         /* lock for the log buffer */
10721 +
10722 +       unsigned long log_start;        /* next char to be read by syslog() */
10723 +       unsigned long con_start;        /* next char to be sent to consoles */
10724 +       unsigned long log_end;  /* most-recently-written-char + 1 */
10725 +       unsigned long logged_chars;     /* #chars since last read+clear operation */
10726 +
10727 +       char log_buf[1024];
10728 +};
10729 +
10730 +
10731 +/* context sub struct */
10732 +
10733 +struct _vx_cvirt {
10734 +       atomic_t nr_threads;            /* number of current threads */
10735 +       atomic_t nr_running;            /* number of running threads */
10736 +       atomic_t nr_uninterruptible;    /* number of uninterruptible threads */
10737 +
10738 +       atomic_t nr_onhold;             /* processes on hold */
10739 +       uint32_t onhold_last;           /* jiffies when put on hold */
10740 +
10741 +       struct timespec bias_ts;        /* time offset to the host */
10742 +       struct timespec bias_idle;
10743 +       struct timespec bias_uptime;    /* context creation point */
10744 +       uint64_t bias_clock;            /* offset in clock_t */
10745 +
10746 +       spinlock_t load_lock;           /* lock for the load averages */
10747 +       atomic_t load_updates;          /* nr of load updates done so far */
10748 +       uint32_t load_last;             /* last time load was calculated */
10749 +       uint32_t load[3];               /* load averages 1,5,15 */
10750 +
10751 +       atomic_t total_forks;           /* number of forks so far */
10752 +
10753 +       struct _vx_syslog syslog;
10754 +};
10755 +
10756 +struct _vx_cvirt_pc {
10757 +       struct _vx_usage_stat cpustat;
10758 +};
10759 +
10760 +
10761 +#ifdef CONFIG_VSERVER_DEBUG
10762 +
10763 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10764 +{
10765 +       printk("\t_vx_cvirt:\n");
10766 +       printk("\t threads: %4d, %4d, %4d, %4d\n",
10767 +               atomic_read(&cvirt->nr_threads),
10768 +               atomic_read(&cvirt->nr_running),
10769 +               atomic_read(&cvirt->nr_uninterruptible),
10770 +               atomic_read(&cvirt->nr_onhold));
10771 +       /* add rest here */
10772 +       printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10773 +}
10774 +
10775 +#endif
10776 +
10777 +#endif /* _VSERVER_CVIRT_DEF_H */
10778 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/debug.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/debug.h
10779 --- linux-3.10.40/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
10780 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/debug.h       2013-08-22 20:30:00.000000000 +0000
10781 @@ -0,0 +1,146 @@
10782 +#ifndef _VSERVER_DEBUG_H
10783 +#define _VSERVER_DEBUG_H
10784 +
10785 +
10786 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10787 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10788 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10789 +
10790 +#define VXD_DEV(d)     (d), (d)->bd_inode->i_ino,              \
10791 +                       imajor((d)->bd_inode), iminor((d)->bd_inode)
10792 +#define VXF_DEV                "%p[%lu,%d:%d]"
10793 +
10794 +#if    defined(CONFIG_QUOTES_UTF8)
10795 +#define        VS_Q_LQM        "\xc2\xbb"
10796 +#define        VS_Q_RQM        "\xc2\xab"
10797 +#elif  defined(CONFIG_QUOTES_ASCII)
10798 +#define        VS_Q_LQM        "\x27"
10799 +#define        VS_Q_RQM        "\x27"
10800 +#else
10801 +#define        VS_Q_LQM        "\xbb"
10802 +#define        VS_Q_RQM        "\xab"
10803 +#endif
10804 +
10805 +#define        VS_Q(f)         VS_Q_LQM f VS_Q_RQM
10806 +
10807 +
10808 +#define vxd_path(p)                                            \
10809 +       ({ static char _buffer[PATH_MAX];                       \
10810 +          d_path(p, _buffer, sizeof(_buffer)); })
10811 +
10812 +#define vxd_cond_path(n)                                       \
10813 +       ((n) ? vxd_path(&(n)->path) : "<null>" )
10814 +
10815 +
10816 +#ifdef CONFIG_VSERVER_DEBUG
10817 +
10818 +extern unsigned int vs_debug_switch;
10819 +extern unsigned int vs_debug_xid;
10820 +extern unsigned int vs_debug_nid;
10821 +extern unsigned int vs_debug_tag;
10822 +extern unsigned int vs_debug_net;
10823 +extern unsigned int vs_debug_limit;
10824 +extern unsigned int vs_debug_cres;
10825 +extern unsigned int vs_debug_dlim;
10826 +extern unsigned int vs_debug_quota;
10827 +extern unsigned int vs_debug_cvirt;
10828 +extern unsigned int vs_debug_space;
10829 +extern unsigned int vs_debug_perm;
10830 +extern unsigned int vs_debug_misc;
10831 +
10832 +
10833 +#define VX_LOGLEVEL    "vxD: "
10834 +#define VX_PROC_FMT    "%p: "
10835 +#define VX_PROCESS     current
10836 +
10837 +#define vxdprintk(c, f, x...)                                  \
10838 +       do {                                                    \
10839 +               if (c)                                          \
10840 +                       printk(VX_LOGLEVEL VX_PROC_FMT f "\n",  \
10841 +                               VX_PROCESS , ##x);              \
10842 +       } while (0)
10843 +
10844 +#define vxlprintk(c, f, x...)                                  \
10845 +       do {                                                    \
10846 +               if (c)                                          \
10847 +                       printk(VX_LOGLEVEL f " @%s:%d\n", x);   \
10848 +       } while (0)
10849 +
10850 +#define vxfprintk(c, f, x...)                                  \
10851 +       do {                                                    \
10852 +               if (c)                                          \
10853 +                       printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10854 +       } while (0)
10855 +
10856 +
10857 +struct vx_info;
10858 +
10859 +void dump_vx_info(struct vx_info *, int);
10860 +void dump_vx_info_inactive(int);
10861 +
10862 +#else  /* CONFIG_VSERVER_DEBUG */
10863 +
10864 +#define vs_debug_switch        0
10865 +#define vs_debug_xid   0
10866 +#define vs_debug_nid   0
10867 +#define vs_debug_tag   0
10868 +#define vs_debug_net   0
10869 +#define vs_debug_limit 0
10870 +#define vs_debug_cres  0
10871 +#define vs_debug_dlim  0
10872 +#define vs_debug_quota 0
10873 +#define vs_debug_cvirt 0
10874 +#define vs_debug_space 0
10875 +#define vs_debug_perm  0
10876 +#define vs_debug_misc  0
10877 +
10878 +#define vxdprintk(x...) do { } while (0)
10879 +#define vxlprintk(x...) do { } while (0)
10880 +#define vxfprintk(x...) do { } while (0)
10881 +
10882 +#endif /* CONFIG_VSERVER_DEBUG */
10883 +
10884 +
10885 +#ifdef CONFIG_VSERVER_WARN
10886 +
10887 +#define VX_WARNLEVEL   KERN_WARNING "vxW: "
10888 +#define VX_WARN_TASK   "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10889 +#define VX_WARN_XID    "[xid #%u] "
10890 +#define VX_WARN_NID    "[nid #%u] "
10891 +#define VX_WARN_TAG    "[tag #%u] "
10892 +
10893 +#define vxwprintk(c, f, x...)                                  \
10894 +       do {                                                    \
10895 +               if (c)                                          \
10896 +                       printk(VX_WARNLEVEL f "\n", ##x);       \
10897 +       } while (0)
10898 +
10899 +#else  /* CONFIG_VSERVER_WARN */
10900 +
10901 +#define vxwprintk(x...) do { } while (0)
10902 +
10903 +#endif /* CONFIG_VSERVER_WARN */
10904 +
10905 +#define vxwprintk_task(c, f, x...)                             \
10906 +       vxwprintk(c, VX_WARN_TASK f,                            \
10907 +               current->comm, current->pid,                    \
10908 +               current->xid, current->nid,                     \
10909 +               current->tag, ##x)
10910 +#define vxwprintk_xid(c, f, x...)                              \
10911 +       vxwprintk(c, VX_WARN_XID f, current->xid, x)
10912 +#define vxwprintk_nid(c, f, x...)                              \
10913 +       vxwprintk(c, VX_WARN_NID f, current->nid, x)
10914 +#define vxwprintk_tag(c, f, x...)                              \
10915 +       vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10916 +
10917 +#ifdef CONFIG_VSERVER_DEBUG
10918 +#define vxd_assert_lock(l)     assert_spin_locked(l)
10919 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10920 +       "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10921 +#else
10922 +#define vxd_assert_lock(l)     do { } while (0)
10923 +#define vxd_assert(c, f, x...) do { } while (0)
10924 +#endif
10925 +
10926 +
10927 +#endif /* _VSERVER_DEBUG_H */
10928 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/debug_cmd.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/debug_cmd.h
10929 --- linux-3.10.40/include/linux/vserver/debug_cmd.h     1970-01-01 00:00:00.000000000 +0000
10930 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/debug_cmd.h   2013-08-22 20:30:00.000000000 +0000
10931 @@ -0,0 +1,37 @@
10932 +#ifndef _VSERVER_DEBUG_CMD_H
10933 +#define _VSERVER_DEBUG_CMD_H
10934 +
10935 +#include <uapi/vserver/debug_cmd.h>
10936 +
10937 +
10938 +#ifdef CONFIG_COMPAT
10939 +
10940 +#include <asm/compat.h>
10941 +
10942 +struct vcmd_read_history_v0_x32 {
10943 +       uint32_t index;
10944 +       uint32_t count;
10945 +       compat_uptr_t data_ptr;
10946 +};
10947 +
10948 +struct vcmd_read_monitor_v0_x32 {
10949 +       uint32_t index;
10950 +       uint32_t count;
10951 +       compat_uptr_t data_ptr;
10952 +};
10953 +
10954 +#endif  /* CONFIG_COMPAT */
10955 +
10956 +extern int vc_dump_history(uint32_t);
10957 +
10958 +extern int vc_read_history(uint32_t, void __user *);
10959 +extern int vc_read_monitor(uint32_t, void __user *);
10960 +
10961 +#ifdef CONFIG_COMPAT
10962 +
10963 +extern int vc_read_history_x32(uint32_t, void __user *);
10964 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10965 +
10966 +#endif  /* CONFIG_COMPAT */
10967 +
10968 +#endif /* _VSERVER_DEBUG_CMD_H */
10969 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/device.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/device.h
10970 --- linux-3.10.40/include/linux/vserver/device.h        1970-01-01 00:00:00.000000000 +0000
10971 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/device.h      2013-08-22 20:30:00.000000000 +0000
10972 @@ -0,0 +1,9 @@
10973 +#ifndef _VSERVER_DEVICE_H
10974 +#define _VSERVER_DEVICE_H
10975 +
10976 +
10977 +#include <uapi/vserver/device.h>
10978 +
10979 +#else  /* _VSERVER_DEVICE_H */
10980 +#warning duplicate inclusion
10981 +#endif /* _VSERVER_DEVICE_H */
10982 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/device_cmd.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/device_cmd.h
10983 --- linux-3.10.40/include/linux/vserver/device_cmd.h    1970-01-01 00:00:00.000000000 +0000
10984 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/device_cmd.h  2013-08-22 20:30:00.000000000 +0000
10985 @@ -0,0 +1,31 @@
10986 +#ifndef _VSERVER_DEVICE_CMD_H
10987 +#define _VSERVER_DEVICE_CMD_H
10988 +
10989 +#include <uapi/vserver/device_cmd.h>
10990 +
10991 +
10992 +#ifdef CONFIG_COMPAT
10993 +
10994 +#include <asm/compat.h>
10995 +
10996 +struct vcmd_set_mapping_v0_x32 {
10997 +       compat_uptr_t device_ptr;
10998 +       compat_uptr_t target_ptr;
10999 +       uint32_t flags;
11000 +};
11001 +
11002 +#endif /* CONFIG_COMPAT */
11003 +
11004 +#include <linux/compiler.h>
11005 +
11006 +extern int vc_set_mapping(struct vx_info *, void __user *);
11007 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11008 +
11009 +#ifdef CONFIG_COMPAT
11010 +
11011 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11012 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11013 +
11014 +#endif /* CONFIG_COMPAT */
11015 +
11016 +#endif /* _VSERVER_DEVICE_CMD_H */
11017 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/device_def.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/device_def.h
11018 --- linux-3.10.40/include/linux/vserver/device_def.h    1970-01-01 00:00:00.000000000 +0000
11019 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/device_def.h  2013-08-22 20:30:00.000000000 +0000
11020 @@ -0,0 +1,17 @@
11021 +#ifndef _VSERVER_DEVICE_DEF_H
11022 +#define _VSERVER_DEVICE_DEF_H
11023 +
11024 +#include <linux/types.h>
11025 +
11026 +struct vx_dmap_target {
11027 +       dev_t target;
11028 +       uint32_t flags;
11029 +};
11030 +
11031 +struct _vx_device {
11032 +#ifdef CONFIG_VSERVER_DEVICE
11033 +       struct vx_dmap_target targets[2];
11034 +#endif
11035 +};
11036 +
11037 +#endif /* _VSERVER_DEVICE_DEF_H */
11038 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/dlimit.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/dlimit.h
11039 --- linux-3.10.40/include/linux/vserver/dlimit.h        1970-01-01 00:00:00.000000000 +0000
11040 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/dlimit.h      2013-08-22 20:30:00.000000000 +0000
11041 @@ -0,0 +1,54 @@
11042 +#ifndef _VSERVER_DLIMIT_H
11043 +#define _VSERVER_DLIMIT_H
11044 +
11045 +#include "switch.h"
11046 +
11047 +
11048 +#ifdef __KERNEL__
11049 +
11050 +/*      keep in sync with CDLIM_INFINITY       */
11051 +
11052 +#define DLIM_INFINITY          (~0ULL)
11053 +
11054 +#include <linux/spinlock.h>
11055 +#include <linux/rcupdate.h>
11056 +
11057 +struct super_block;
11058 +
11059 +struct dl_info {
11060 +       struct hlist_node dl_hlist;             /* linked list of contexts */
11061 +       struct rcu_head dl_rcu;                 /* the rcu head */
11062 +       vtag_t dl_tag;                          /* context tag */
11063 +       atomic_t dl_usecnt;                     /* usage count */
11064 +       atomic_t dl_refcnt;                     /* reference count */
11065 +
11066 +       struct super_block *dl_sb;              /* associated superblock */
11067 +
11068 +       spinlock_t dl_lock;                     /* protect the values */
11069 +
11070 +       unsigned long long dl_space_used;       /* used space in bytes */
11071 +       unsigned long long dl_space_total;      /* maximum space in bytes */
11072 +       unsigned long dl_inodes_used;           /* used inodes */
11073 +       unsigned long dl_inodes_total;          /* maximum inodes */
11074 +
11075 +       unsigned int dl_nrlmult;                /* non root limit mult */
11076 +};
11077 +
11078 +struct rcu_head;
11079 +
11080 +extern void rcu_free_dl_info(struct rcu_head *);
11081 +extern void unhash_dl_info(struct dl_info *);
11082 +
11083 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
11084 +
11085 +
11086 +struct kstatfs;
11087 +
11088 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11089 +
11090 +typedef uint64_t dlsize_t;
11091 +
11092 +#endif /* __KERNEL__ */
11093 +#else  /* _VSERVER_DLIMIT_H */
11094 +#warning duplicate inclusion
11095 +#endif /* _VSERVER_DLIMIT_H */
11096 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/dlimit_cmd.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/dlimit_cmd.h
11097 --- linux-3.10.40/include/linux/vserver/dlimit_cmd.h    1970-01-01 00:00:00.000000000 +0000
11098 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/dlimit_cmd.h  2013-08-22 20:30:00.000000000 +0000
11099 @@ -0,0 +1,46 @@
11100 +#ifndef _VSERVER_DLIMIT_CMD_H
11101 +#define _VSERVER_DLIMIT_CMD_H
11102 +
11103 +#include <uapi/vserver/dlimit_cmd.h>
11104 +
11105 +
11106 +#ifdef CONFIG_COMPAT
11107 +
11108 +#include <asm/compat.h>
11109 +
11110 +struct vcmd_ctx_dlimit_base_v0_x32 {
11111 +       compat_uptr_t name_ptr;
11112 +       uint32_t flags;
11113 +};
11114 +
11115 +struct vcmd_ctx_dlimit_v0_x32 {
11116 +       compat_uptr_t name_ptr;
11117 +       uint32_t space_used;                    /* used space in kbytes */
11118 +       uint32_t space_total;                   /* maximum space in kbytes */
11119 +       uint32_t inodes_used;                   /* used inodes */
11120 +       uint32_t inodes_total;                  /* maximum inodes */
11121 +       uint32_t reserved;                      /* reserved for root in % */
11122 +       uint32_t flags;
11123 +};
11124 +
11125 +#endif /* CONFIG_COMPAT */
11126 +
11127 +#include <linux/compiler.h>
11128 +
11129 +extern int vc_add_dlimit(uint32_t, void __user *);
11130 +extern int vc_rem_dlimit(uint32_t, void __user *);
11131 +
11132 +extern int vc_set_dlimit(uint32_t, void __user *);
11133 +extern int vc_get_dlimit(uint32_t, void __user *);
11134 +
11135 +#ifdef CONFIG_COMPAT
11136 +
11137 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11138 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11139 +
11140 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11141 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11142 +
11143 +#endif /* CONFIG_COMPAT */
11144 +
11145 +#endif /* _VSERVER_DLIMIT_CMD_H */
11146 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/global.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/global.h
11147 --- linux-3.10.40/include/linux/vserver/global.h        1970-01-01 00:00:00.000000000 +0000
11148 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/global.h      2013-08-22 20:30:00.000000000 +0000
11149 @@ -0,0 +1,19 @@
11150 +#ifndef _VSERVER_GLOBAL_H
11151 +#define _VSERVER_GLOBAL_H
11152 +
11153 +
11154 +extern atomic_t vx_global_ctotal;
11155 +extern atomic_t vx_global_cactive;
11156 +
11157 +extern atomic_t nx_global_ctotal;
11158 +extern atomic_t nx_global_cactive;
11159 +
11160 +extern atomic_t vs_global_nsproxy;
11161 +extern atomic_t vs_global_fs;
11162 +extern atomic_t vs_global_mnt_ns;
11163 +extern atomic_t vs_global_uts_ns;
11164 +extern atomic_t vs_global_user_ns;
11165 +extern atomic_t vs_global_pid_ns;
11166 +
11167 +
11168 +#endif /* _VSERVER_GLOBAL_H */
11169 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/history.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/history.h
11170 --- linux-3.10.40/include/linux/vserver/history.h       1970-01-01 00:00:00.000000000 +0000
11171 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/history.h     2013-08-22 20:30:00.000000000 +0000
11172 @@ -0,0 +1,197 @@
11173 +#ifndef _VSERVER_HISTORY_H
11174 +#define _VSERVER_HISTORY_H
11175 +
11176 +
11177 +enum {
11178 +       VXH_UNUSED = 0,
11179 +       VXH_THROW_OOPS = 1,
11180 +
11181 +       VXH_GET_VX_INFO,
11182 +       VXH_PUT_VX_INFO,
11183 +       VXH_INIT_VX_INFO,
11184 +       VXH_SET_VX_INFO,
11185 +       VXH_CLR_VX_INFO,
11186 +       VXH_CLAIM_VX_INFO,
11187 +       VXH_RELEASE_VX_INFO,
11188 +       VXH_ALLOC_VX_INFO,
11189 +       VXH_DEALLOC_VX_INFO,
11190 +       VXH_HASH_VX_INFO,
11191 +       VXH_UNHASH_VX_INFO,
11192 +       VXH_LOC_VX_INFO,
11193 +       VXH_LOOKUP_VX_INFO,
11194 +       VXH_CREATE_VX_INFO,
11195 +};
11196 +
11197 +struct _vxhe_vxi {
11198 +       struct vx_info *ptr;
11199 +       unsigned xid;
11200 +       unsigned usecnt;
11201 +       unsigned tasks;
11202 +};
11203 +
11204 +struct _vxhe_set_clr {
11205 +       void *data;
11206 +};
11207 +
11208 +struct _vxhe_loc_lookup {
11209 +       unsigned arg;
11210 +};
11211 +
11212 +struct _vx_hist_entry {
11213 +       void *loc;
11214 +       unsigned short seq;
11215 +       unsigned short type;
11216 +       struct _vxhe_vxi vxi;
11217 +       union {
11218 +               struct _vxhe_set_clr sc;
11219 +               struct _vxhe_loc_lookup ll;
11220 +       };
11221 +};
11222 +
11223 +#ifdef CONFIG_VSERVER_HISTORY
11224 +
11225 +extern unsigned volatile int vxh_active;
11226 +
11227 +struct _vx_hist_entry *vxh_advance(void *loc);
11228 +
11229 +
11230 +static inline
11231 +void   __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11232 +{
11233 +       entry->vxi.ptr = vxi;
11234 +       if (vxi) {
11235 +               entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11236 +               entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11237 +               entry->vxi.xid = vxi->vx_id;
11238 +       }
11239 +}
11240 +
11241 +
11242 +#define        __HERE__ current_text_addr()
11243 +
11244 +#define __VXH_BODY(__type, __data, __here)     \
11245 +       struct _vx_hist_entry *entry;           \
11246 +                                               \
11247 +       preempt_disable();                      \
11248 +       entry = vxh_advance(__here);            \
11249 +       __data;                                 \
11250 +       entry->type = __type;                   \
11251 +       preempt_enable();
11252 +
11253 +
11254 +       /* pass vxi only */
11255 +
11256 +#define __VXH_SMPL                             \
11257 +       __vxh_copy_vxi(entry, vxi)
11258 +
11259 +static inline
11260 +void   __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11261 +{
11262 +       __VXH_BODY(__type, __VXH_SMPL, __here)
11263 +}
11264 +
11265 +       /* pass vxi and data (void *) */
11266 +
11267 +#define __VXH_DATA                             \
11268 +       __vxh_copy_vxi(entry, vxi);             \
11269 +       entry->sc.data = data
11270 +
11271 +static inline
11272 +void   __vxh_data(struct vx_info *vxi, void *data,
11273 +                       int __type, void *__here)
11274 +{
11275 +       __VXH_BODY(__type, __VXH_DATA, __here)
11276 +}
11277 +
11278 +       /* pass vxi and arg (long) */
11279 +
11280 +#define __VXH_LONG                             \
11281 +       __vxh_copy_vxi(entry, vxi);             \
11282 +       entry->ll.arg = arg
11283 +
11284 +static inline
11285 +void   __vxh_long(struct vx_info *vxi, long arg,
11286 +                       int __type, void *__here)
11287 +{
11288 +       __VXH_BODY(__type, __VXH_LONG, __here)
11289 +}
11290 +
11291 +
11292 +static inline
11293 +void   __vxh_throw_oops(void *__here)
11294 +{
11295 +       __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11296 +       /* prevent further acquisition */
11297 +       vxh_active = 0;
11298 +}
11299 +
11300 +
11301 +#define vxh_throw_oops()       __vxh_throw_oops(__HERE__);
11302 +
11303 +#define __vxh_get_vx_info(v, h)        __vxh_smpl(v, VXH_GET_VX_INFO, h);
11304 +#define __vxh_put_vx_info(v, h)        __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11305 +
11306 +#define __vxh_init_vx_info(v, d, h) \
11307 +       __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11308 +#define __vxh_set_vx_info(v, d, h) \
11309 +       __vxh_data(v, d, VXH_SET_VX_INFO, h);
11310 +#define __vxh_clr_vx_info(v, d, h) \
11311 +       __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11312 +
11313 +#define __vxh_claim_vx_info(v, d, h) \
11314 +       __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11315 +#define __vxh_release_vx_info(v, d, h) \
11316 +       __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11317 +
11318 +#define vxh_alloc_vx_info(v) \
11319 +       __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11320 +#define vxh_dealloc_vx_info(v) \
11321 +       __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11322 +
11323 +#define vxh_hash_vx_info(v) \
11324 +       __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11325 +#define vxh_unhash_vx_info(v) \
11326 +       __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11327 +
11328 +#define vxh_loc_vx_info(v, l) \
11329 +       __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11330 +#define vxh_lookup_vx_info(v, l) \
11331 +       __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11332 +#define vxh_create_vx_info(v, l) \
11333 +       __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11334 +
11335 +extern void vxh_dump_history(void);
11336 +
11337 +
11338 +#else  /* CONFIG_VSERVER_HISTORY */
11339 +
11340 +#define        __HERE__        0
11341 +
11342 +#define vxh_throw_oops()               do { } while (0)
11343 +
11344 +#define __vxh_get_vx_info(v, h)                do { } while (0)
11345 +#define __vxh_put_vx_info(v, h)                do { } while (0)
11346 +
11347 +#define __vxh_init_vx_info(v, d, h)    do { } while (0)
11348 +#define __vxh_set_vx_info(v, d, h)     do { } while (0)
11349 +#define __vxh_clr_vx_info(v, d, h)     do { } while (0)
11350 +
11351 +#define __vxh_claim_vx_info(v, d, h)   do { } while (0)
11352 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11353 +
11354 +#define vxh_alloc_vx_info(v)           do { } while (0)
11355 +#define vxh_dealloc_vx_info(v)         do { } while (0)
11356 +
11357 +#define vxh_hash_vx_info(v)            do { } while (0)
11358 +#define vxh_unhash_vx_info(v)          do { } while (0)
11359 +
11360 +#define vxh_loc_vx_info(v, l)          do { } while (0)
11361 +#define vxh_lookup_vx_info(v, l)       do { } while (0)
11362 +#define vxh_create_vx_info(v, l)       do { } while (0)
11363 +
11364 +#define vxh_dump_history()             do { } while (0)
11365 +
11366 +
11367 +#endif /* CONFIG_VSERVER_HISTORY */
11368 +
11369 +#endif /* _VSERVER_HISTORY_H */
11370 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/inode.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/inode.h
11371 --- linux-3.10.40/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
11372 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/inode.h       2013-08-22 20:30:00.000000000 +0000
11373 @@ -0,0 +1,19 @@
11374 +#ifndef _VSERVER_INODE_H
11375 +#define _VSERVER_INODE_H
11376 +
11377 +#include <uapi/vserver/inode.h>
11378 +
11379 +
11380 +#ifdef CONFIG_VSERVER_PROC_SECURE
11381 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN | IATTR_HIDE )
11382 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11383 +#else
11384 +#define IATTR_PROC_DEFAULT     ( IATTR_ADMIN )
11385 +#define IATTR_PROC_SYMLINK     ( IATTR_ADMIN )
11386 +#endif
11387 +
11388 +#define vx_hide_check(c, m)    (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11389 +
11390 +#else  /* _VSERVER_INODE_H */
11391 +#warning duplicate inclusion
11392 +#endif /* _VSERVER_INODE_H */
11393 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/inode_cmd.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/inode_cmd.h
11394 --- linux-3.10.40/include/linux/vserver/inode_cmd.h     1970-01-01 00:00:00.000000000 +0000
11395 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/inode_cmd.h   2013-08-22 20:30:00.000000000 +0000
11396 @@ -0,0 +1,36 @@
11397 +#ifndef _VSERVER_INODE_CMD_H
11398 +#define _VSERVER_INODE_CMD_H
11399 +
11400 +#include <uapi/vserver/inode_cmd.h>
11401 +
11402 +
11403 +
11404 +#ifdef CONFIG_COMPAT
11405 +
11406 +#include <asm/compat.h>
11407 +
11408 +struct vcmd_ctx_iattr_v1_x32 {
11409 +       compat_uptr_t name_ptr;
11410 +       uint32_t tag;
11411 +       uint32_t flags;
11412 +       uint32_t mask;
11413 +};
11414 +
11415 +#endif /* CONFIG_COMPAT */
11416 +
11417 +#include <linux/compiler.h>
11418 +
11419 +extern int vc_get_iattr(void __user *);
11420 +extern int vc_set_iattr(void __user *);
11421 +
11422 +extern int vc_fget_iattr(uint32_t, void __user *);
11423 +extern int vc_fset_iattr(uint32_t, void __user *);
11424 +
11425 +#ifdef CONFIG_COMPAT
11426 +
11427 +extern int vc_get_iattr_x32(void __user *);
11428 +extern int vc_set_iattr_x32(void __user *);
11429 +
11430 +#endif /* CONFIG_COMPAT */
11431 +
11432 +#endif /* _VSERVER_INODE_CMD_H */
11433 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/limit.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/limit.h
11434 --- linux-3.10.40/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
11435 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/limit.h       2013-08-22 20:30:00.000000000 +0000
11436 @@ -0,0 +1,61 @@
11437 +#ifndef _VSERVER_LIMIT_H
11438 +#define _VSERVER_LIMIT_H
11439 +
11440 +#include <uapi/vserver/limit.h>
11441 +
11442 +
11443 +#define        VLIM_NOCHECK    ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11444 +
11445 +/*     keep in sync with CRLIM_INFINITY */
11446 +
11447 +#define        VLIM_INFINITY   (~0ULL)
11448 +
11449 +#include <asm/atomic.h>
11450 +#include <asm/resource.h>
11451 +
11452 +#ifndef RLIM_INFINITY
11453 +#warning RLIM_INFINITY is undefined
11454 +#endif
11455 +
11456 +#define __rlim_val(l, r, v)    ((l)->res[r].v)
11457 +
11458 +#define __rlim_soft(l, r)      __rlim_val(l, r, soft)
11459 +#define __rlim_hard(l, r)      __rlim_val(l, r, hard)
11460 +
11461 +#define __rlim_rcur(l, r)      __rlim_val(l, r, rcur)
11462 +#define __rlim_rmin(l, r)      __rlim_val(l, r, rmin)
11463 +#define __rlim_rmax(l, r)      __rlim_val(l, r, rmax)
11464 +
11465 +#define __rlim_lhit(l, r)      __rlim_val(l, r, lhit)
11466 +#define __rlim_hit(l, r)       atomic_inc(&__rlim_lhit(l, r))
11467 +
11468 +typedef atomic_long_t rlim_atomic_t;
11469 +typedef unsigned long rlim_t;
11470 +
11471 +#define __rlim_get(l, r)       atomic_long_read(&__rlim_rcur(l, r))
11472 +#define __rlim_set(l, r, v)    atomic_long_set(&__rlim_rcur(l, r), v)
11473 +#define __rlim_inc(l, r)       atomic_long_inc(&__rlim_rcur(l, r))
11474 +#define __rlim_dec(l, r)       atomic_long_dec(&__rlim_rcur(l, r))
11475 +#define __rlim_add(l, r, v)    atomic_long_add(v, &__rlim_rcur(l, r))
11476 +#define __rlim_sub(l, r, v)    atomic_long_sub(v, &__rlim_rcur(l, r))
11477 +
11478 +
11479 +#if    (RLIM_INFINITY == VLIM_INFINITY)
11480 +#define        VX_VLIM(r) ((long long)(long)(r))
11481 +#define        VX_RLIM(v) ((rlim_t)(v))
11482 +#else
11483 +#define        VX_VLIM(r) (((r) == RLIM_INFINITY) \
11484 +               ? VLIM_INFINITY : (long long)(r))
11485 +#define        VX_RLIM(v) (((v) == VLIM_INFINITY) \
11486 +               ? RLIM_INFINITY : (rlim_t)(v))
11487 +#endif
11488 +
11489 +struct sysinfo;
11490 +
11491 +void vx_vsi_meminfo(struct sysinfo *);
11492 +void vx_vsi_swapinfo(struct sysinfo *);
11493 +long vx_vsi_cached(struct sysinfo *);
11494 +
11495 +#define NUM_LIMITS     24
11496 +
11497 +#endif /* _VSERVER_LIMIT_H */
11498 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/limit_cmd.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/limit_cmd.h
11499 --- linux-3.10.40/include/linux/vserver/limit_cmd.h     1970-01-01 00:00:00.000000000 +0000
11500 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/limit_cmd.h   2013-08-22 20:30:00.000000000 +0000
11501 @@ -0,0 +1,35 @@
11502 +#ifndef _VSERVER_LIMIT_CMD_H
11503 +#define _VSERVER_LIMIT_CMD_H
11504 +
11505 +#include <uapi/vserver/limit_cmd.h>
11506 +
11507 +
11508 +#ifdef CONFIG_IA32_EMULATION
11509 +
11510 +struct vcmd_ctx_rlimit_v0_x32 {
11511 +       uint32_t id;
11512 +       uint64_t minimum;
11513 +       uint64_t softlimit;
11514 +       uint64_t maximum;
11515 +} __attribute__ ((packed));
11516 +
11517 +#endif /* CONFIG_IA32_EMULATION */
11518 +
11519 +#include <linux/compiler.h>
11520 +
11521 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11522 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11523 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11524 +extern int vc_reset_hits(struct vx_info *, void __user *);
11525 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11526 +
11527 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11528 +
11529 +#ifdef CONFIG_IA32_EMULATION
11530 +
11531 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11532 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11533 +
11534 +#endif /* CONFIG_IA32_EMULATION */
11535 +
11536 +#endif /* _VSERVER_LIMIT_CMD_H */
11537 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/limit_def.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/limit_def.h
11538 --- linux-3.10.40/include/linux/vserver/limit_def.h     1970-01-01 00:00:00.000000000 +0000
11539 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/limit_def.h   2013-08-22 20:30:00.000000000 +0000
11540 @@ -0,0 +1,47 @@
11541 +#ifndef _VSERVER_LIMIT_DEF_H
11542 +#define _VSERVER_LIMIT_DEF_H
11543 +
11544 +#include <asm/atomic.h>
11545 +#include <asm/resource.h>
11546 +
11547 +#include "limit.h"
11548 +
11549 +
11550 +struct _vx_res_limit {
11551 +       rlim_t soft;            /* Context soft limit */
11552 +       rlim_t hard;            /* Context hard limit */
11553 +
11554 +       rlim_atomic_t rcur;     /* Current value */
11555 +       rlim_t rmin;            /* Context minimum */
11556 +       rlim_t rmax;            /* Context maximum */
11557 +
11558 +       atomic_t lhit;          /* Limit hits */
11559 +};
11560 +
11561 +/* context sub struct */
11562 +
11563 +struct _vx_limit {
11564 +       struct _vx_res_limit res[NUM_LIMITS];
11565 +};
11566 +
11567 +#ifdef CONFIG_VSERVER_DEBUG
11568 +
11569 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11570 +{
11571 +       int i;
11572 +
11573 +       printk("\t_vx_limit:");
11574 +       for (i = 0; i < NUM_LIMITS; i++) {
11575 +               printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11576 +                       i, (unsigned long)__rlim_get(limit, i),
11577 +                       (unsigned long)__rlim_rmin(limit, i),
11578 +                       (unsigned long)__rlim_rmax(limit, i),
11579 +                       (long)__rlim_soft(limit, i),
11580 +                       (long)__rlim_hard(limit, i),
11581 +                       atomic_read(&__rlim_lhit(limit, i)));
11582 +       }
11583 +}
11584 +
11585 +#endif
11586 +
11587 +#endif /* _VSERVER_LIMIT_DEF_H */
11588 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/limit_int.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/limit_int.h
11589 --- linux-3.10.40/include/linux/vserver/limit_int.h     1970-01-01 00:00:00.000000000 +0000
11590 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/limit_int.h   2013-08-22 20:30:00.000000000 +0000
11591 @@ -0,0 +1,193 @@
11592 +#ifndef _VSERVER_LIMIT_INT_H
11593 +#define _VSERVER_LIMIT_INT_H
11594 +
11595 +#define VXD_RCRES_COND(r)      VXD_CBIT(cres, r)
11596 +#define VXD_RLIMIT_COND(r)     VXD_CBIT(limit, r)
11597 +
11598 +extern const char *vlimit_name[NUM_LIMITS];
11599 +
11600 +static inline void __vx_acc_cres(struct vx_info *vxi,
11601 +       int res, int dir, void *_data, char *_file, int _line)
11602 +{
11603 +       if (VXD_RCRES_COND(res))
11604 +               vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11605 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11606 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11607 +                       (dir > 0) ? "++" : "--", _data, _file, _line);
11608 +       if (!vxi)
11609 +               return;
11610 +
11611 +       if (dir > 0)
11612 +               __rlim_inc(&vxi->limit, res);
11613 +       else
11614 +               __rlim_dec(&vxi->limit, res);
11615 +}
11616 +
11617 +static inline void __vx_add_cres(struct vx_info *vxi,
11618 +       int res, int amount, void *_data, char *_file, int _line)
11619 +{
11620 +       if (VXD_RCRES_COND(res))
11621 +               vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11622 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11623 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11624 +                       amount, _data, _file, _line);
11625 +       if (amount == 0)
11626 +               return;
11627 +       if (!vxi)
11628 +               return;
11629 +       __rlim_add(&vxi->limit, res, amount);
11630 +}
11631 +
11632 +static inline
11633 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11634 +{
11635 +       int cond = (value > __rlim_rmax(limit, res));
11636 +
11637 +       if (cond)
11638 +               __rlim_rmax(limit, res) = value;
11639 +       return cond;
11640 +}
11641 +
11642 +static inline
11643 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11644 +{
11645 +       int cond = (value < __rlim_rmin(limit, res));
11646 +
11647 +       if (cond)
11648 +               __rlim_rmin(limit, res) = value;
11649 +       return cond;
11650 +}
11651 +
11652 +static inline
11653 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11654 +{
11655 +       if (!__vx_cres_adjust_max(limit, res, value))
11656 +               __vx_cres_adjust_min(limit, res, value);
11657 +}
11658 +
11659 +
11660 +/*     return values:
11661 +        +1 ... no limit hit
11662 +        -1 ... over soft limit
11663 +         0 ... over hard limit         */
11664 +
11665 +static inline int __vx_cres_avail(struct vx_info *vxi,
11666 +       int res, int num, char *_file, int _line)
11667 +{
11668 +       struct _vx_limit *limit;
11669 +       rlim_t value;
11670 +
11671 +       if (VXD_RLIMIT_COND(res))
11672 +               vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11673 +                       (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11674 +                       (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11675 +                       (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11676 +                       (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11677 +                       num, _file, _line);
11678 +       if (!vxi)
11679 +               return 1;
11680 +
11681 +       limit = &vxi->limit;
11682 +       value = __rlim_get(limit, res);
11683 +
11684 +       if (!__vx_cres_adjust_max(limit, res, value))
11685 +               __vx_cres_adjust_min(limit, res, value);
11686 +
11687 +       if (num == 0)
11688 +               return 1;
11689 +
11690 +       if (__rlim_soft(limit, res) == RLIM_INFINITY)
11691 +               return -1;
11692 +       if (value + num <= __rlim_soft(limit, res))
11693 +               return -1;
11694 +
11695 +       if (__rlim_hard(limit, res) == RLIM_INFINITY)
11696 +               return 1;
11697 +       if (value + num <= __rlim_hard(limit, res))
11698 +               return 1;
11699 +
11700 +       __rlim_hit(limit, res);
11701 +       return 0;
11702 +}
11703 +
11704 +
11705 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11706 +
11707 +static inline
11708 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11709 +{
11710 +       rlim_t value, sum = 0;
11711 +       int res;
11712 +
11713 +       while ((res = *array++)) {
11714 +               value = __rlim_get(limit, res);
11715 +               __vx_cres_fixup(limit, res, value);
11716 +               sum += value;
11717 +       }
11718 +       return sum;
11719 +}
11720 +
11721 +static inline
11722 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11723 +{
11724 +       rlim_t value = __vx_cres_array_sum(limit, array + 1);
11725 +       int res = *array;
11726 +
11727 +       if (value == __rlim_get(limit, res))
11728 +               return value;
11729 +
11730 +       __rlim_set(limit, res, value);
11731 +       /* now adjust min/max */
11732 +       if (!__vx_cres_adjust_max(limit, res, value))
11733 +               __vx_cres_adjust_min(limit, res, value);
11734 +
11735 +       return value;
11736 +}
11737 +
11738 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11739 +       const int *array, int num, char *_file, int _line)
11740 +{
11741 +       struct _vx_limit *limit;
11742 +       rlim_t value = 0;
11743 +       int res;
11744 +
11745 +       if (num == 0)
11746 +               return 1;
11747 +       if (!vxi)
11748 +               return 1;
11749 +
11750 +       limit = &vxi->limit;
11751 +       res = *array;
11752 +       value = __vx_cres_array_sum(limit, array + 1);
11753 +
11754 +       __rlim_set(limit, res, value);
11755 +       __vx_cres_fixup(limit, res, value);
11756 +
11757 +       return __vx_cres_avail(vxi, res, num, _file, _line);
11758 +}
11759 +
11760 +
11761 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11762 +{
11763 +       rlim_t value;
11764 +       int res;
11765 +
11766 +       /* complex resources first */
11767 +       if ((id < 0) || (id == RLIMIT_RSS))
11768 +               __vx_cres_array_fixup(limit, VLA_RSS);
11769 +
11770 +       for (res = 0; res < NUM_LIMITS; res++) {
11771 +               if ((id > 0) && (res != id))
11772 +                       continue;
11773 +
11774 +               value = __rlim_get(limit, res);
11775 +               __vx_cres_fixup(limit, res, value);
11776 +
11777 +               /* not supposed to happen, maybe warn? */
11778 +               if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11779 +                       __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11780 +       }
11781 +}
11782 +
11783 +
11784 +#endif /* _VSERVER_LIMIT_INT_H */
11785 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/monitor.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/monitor.h
11786 --- linux-3.10.40/include/linux/vserver/monitor.h       1970-01-01 00:00:00.000000000 +0000
11787 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/monitor.h     2013-08-22 20:30:00.000000000 +0000
11788 @@ -0,0 +1,6 @@
11789 +#ifndef _VSERVER_MONITOR_H
11790 +#define _VSERVER_MONITOR_H
11791 +
11792 +#include <uapi/vserver/monitor.h>
11793 +
11794 +#endif /* _VSERVER_MONITOR_H */
11795 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/network.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/network.h
11796 --- linux-3.10.40/include/linux/vserver/network.h       1970-01-01 00:00:00.000000000 +0000
11797 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/network.h     2013-08-22 20:30:00.000000000 +0000
11798 @@ -0,0 +1,76 @@
11799 +#ifndef _VSERVER_NETWORK_H
11800 +#define _VSERVER_NETWORK_H
11801 +
11802 +
11803 +#include <linux/list.h>
11804 +#include <linux/spinlock.h>
11805 +#include <linux/rcupdate.h>
11806 +#include <linux/in.h>
11807 +#include <linux/in6.h>
11808 +#include <asm/atomic.h>
11809 +#include <uapi/vserver/network.h>
11810 +
11811 +struct nx_addr_v4 {
11812 +       struct nx_addr_v4 *next;
11813 +       struct in_addr ip[2];
11814 +       struct in_addr mask;
11815 +       uint16_t type;
11816 +       uint16_t flags;
11817 +};
11818 +
11819 +struct nx_addr_v6 {
11820 +       struct nx_addr_v6 *next;
11821 +       struct in6_addr ip;
11822 +       struct in6_addr mask;
11823 +       uint32_t prefix;
11824 +       uint16_t type;
11825 +       uint16_t flags;
11826 +};
11827 +
11828 +struct nx_info {
11829 +       struct hlist_node nx_hlist;     /* linked list of nxinfos */
11830 +       vnid_t nx_id;                   /* vnet id */
11831 +       atomic_t nx_usecnt;             /* usage count */
11832 +       atomic_t nx_tasks;              /* tasks count */
11833 +       int nx_state;                   /* context state */
11834 +
11835 +       uint64_t nx_flags;              /* network flag word */
11836 +       uint64_t nx_ncaps;              /* network capabilities */
11837 +
11838 +       spinlock_t addr_lock;           /* protect address changes */
11839 +       struct in_addr v4_lback;        /* Loopback address */
11840 +       struct in_addr v4_bcast;        /* Broadcast address */
11841 +       struct nx_addr_v4 v4;           /* First/Single ipv4 address */
11842 +#ifdef CONFIG_IPV6
11843 +       struct nx_addr_v6 v6;           /* First/Single ipv6 address */
11844 +#endif
11845 +       char nx_name[65];               /* network context name */
11846 +};
11847 +
11848 +
11849 +/* status flags */
11850 +
11851 +#define NXS_HASHED      0x0001
11852 +#define NXS_SHUTDOWN    0x0100
11853 +#define NXS_RELEASED    0x8000
11854 +
11855 +extern struct nx_info *lookup_nx_info(int);
11856 +
11857 +extern int get_nid_list(int, unsigned int *, int);
11858 +extern int nid_is_hashed(vnid_t);
11859 +
11860 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11861 +
11862 +extern long vs_net_change(struct nx_info *, unsigned int);
11863 +
11864 +struct sock;
11865 +
11866 +
11867 +#define NX_IPV4(n)     ((n)->v4.type != NXA_TYPE_NONE)
11868 +#ifdef  CONFIG_IPV6
11869 +#define NX_IPV6(n)     ((n)->v6.type != NXA_TYPE_NONE)
11870 +#else
11871 +#define NX_IPV6(n)     (0)
11872 +#endif
11873 +
11874 +#endif /* _VSERVER_NETWORK_H */
11875 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/network_cmd.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/network_cmd.h
11876 --- linux-3.10.40/include/linux/vserver/network_cmd.h   1970-01-01 00:00:00.000000000 +0000
11877 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/network_cmd.h 2013-08-22 20:30:00.000000000 +0000
11878 @@ -0,0 +1,37 @@
11879 +#ifndef _VSERVER_NETWORK_CMD_H
11880 +#define _VSERVER_NETWORK_CMD_H
11881 +
11882 +#include <uapi/vserver/network_cmd.h>
11883 +
11884 +extern int vc_task_nid(uint32_t);
11885 +
11886 +extern int vc_nx_info(struct nx_info *, void __user *);
11887 +
11888 +extern int vc_net_create(uint32_t, void __user *);
11889 +extern int vc_net_migrate(struct nx_info *, void __user *);
11890 +
11891 +extern int vc_net_add(struct nx_info *, void __user *);
11892 +extern int vc_net_remove(struct nx_info *, void __user *);
11893 +
11894 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11895 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11896 +
11897 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11898 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11899 +
11900 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11901 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11902 +
11903 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11904 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11905 +
11906 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11907 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11908 +
11909 +extern int vc_get_nflags(struct nx_info *, void __user *);
11910 +extern int vc_set_nflags(struct nx_info *, void __user *);
11911 +
11912 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11913 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11914 +
11915 +#endif /* _VSERVER_CONTEXT_CMD_H */
11916 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/percpu.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/percpu.h
11917 --- linux-3.10.40/include/linux/vserver/percpu.h        1970-01-01 00:00:00.000000000 +0000
11918 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/percpu.h      2013-08-22 20:30:00.000000000 +0000
11919 @@ -0,0 +1,14 @@
11920 +#ifndef _VSERVER_PERCPU_H
11921 +#define _VSERVER_PERCPU_H
11922 +
11923 +#include "cvirt_def.h"
11924 +#include "sched_def.h"
11925 +
11926 +struct _vx_percpu {
11927 +       struct _vx_cvirt_pc cvirt;
11928 +       struct _vx_sched_pc sched;
11929 +};
11930 +
11931 +#define        PERCPU_PERCTX   (sizeof(struct _vx_percpu))
11932 +
11933 +#endif /* _VSERVER_PERCPU_H */
11934 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/pid.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/pid.h
11935 --- linux-3.10.40/include/linux/vserver/pid.h   1970-01-01 00:00:00.000000000 +0000
11936 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/pid.h 2013-08-22 20:30:00.000000000 +0000
11937 @@ -0,0 +1,51 @@
11938 +#ifndef _VSERVER_PID_H
11939 +#define _VSERVER_PID_H
11940 +
11941 +/* pid faking stuff */
11942 +
11943 +#define vx_info_map_pid(v, p) \
11944 +       __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
11945 +#define vx_info_map_tgid(v,p)  vx_info_map_pid(v,p)
11946 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
11947 +#define vx_map_tgid(p) vx_map_pid(p)
11948 +
11949 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
11950 +       const char *func, const char *file, int line)
11951 +{
11952 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11953 +               vxfprintk(VXD_CBIT(cvirt, 2),
11954 +                       "vx_map_tgid: %p/%llx: %d -> %d",
11955 +                       vxi, (long long)vxi->vx_flags, pid,
11956 +                       (pid && pid == vxi->vx_initpid) ? 1 : pid,
11957 +                       func, file, line);
11958 +               if (pid == 0)
11959 +                       return 0;
11960 +               if (pid == vxi->vx_initpid)
11961 +                       return 1;
11962 +       }
11963 +       return pid;
11964 +}
11965 +
11966 +#define vx_info_rmap_pid(v, p) \
11967 +       __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
11968 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
11969 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
11970 +
11971 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
11972 +       const char *func, const char *file, int line)
11973 +{
11974 +       if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11975 +               vxfprintk(VXD_CBIT(cvirt, 2),
11976 +                       "vx_rmap_tgid: %p/%llx: %d -> %d",
11977 +                       vxi, (long long)vxi->vx_flags, pid,
11978 +                       (pid == 1) ? vxi->vx_initpid : pid,
11979 +                       func, file, line);
11980 +               if ((pid == 1) && vxi->vx_initpid)
11981 +                       return vxi->vx_initpid;
11982 +               if (pid == vxi->vx_initpid)
11983 +                       return ~0U;
11984 +       }
11985 +       return pid;
11986 +}
11987 +
11988 +#endif
11989 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/sched.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/sched.h
11990 --- linux-3.10.40/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
11991 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/sched.h       2013-08-22 20:30:00.000000000 +0000
11992 @@ -0,0 +1,23 @@
11993 +#ifndef _VSERVER_SCHED_H
11994 +#define _VSERVER_SCHED_H
11995 +
11996 +
11997 +#ifdef __KERNEL__
11998 +
11999 +struct timespec;
12000 +
12001 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12002 +
12003 +
12004 +struct vx_info;
12005 +
12006 +void vx_update_load(struct vx_info *);
12007 +
12008 +
12009 +void vx_update_sched_param(struct _vx_sched *sched,
12010 +       struct _vx_sched_pc *sched_pc);
12011 +
12012 +#endif /* __KERNEL__ */
12013 +#else  /* _VSERVER_SCHED_H */
12014 +#warning duplicate inclusion
12015 +#endif /* _VSERVER_SCHED_H */
12016 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/sched_cmd.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/sched_cmd.h
12017 --- linux-3.10.40/include/linux/vserver/sched_cmd.h     1970-01-01 00:00:00.000000000 +0000
12018 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/sched_cmd.h   2013-08-22 20:30:00.000000000 +0000
12019 @@ -0,0 +1,11 @@
12020 +#ifndef _VSERVER_SCHED_CMD_H
12021 +#define _VSERVER_SCHED_CMD_H
12022 +
12023 +
12024 +#include <linux/compiler.h>
12025 +#include <uapi/vserver/sched_cmd.h>
12026 +
12027 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12028 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12029 +
12030 +#endif /* _VSERVER_SCHED_CMD_H */
12031 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/sched_def.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/sched_def.h
12032 --- linux-3.10.40/include/linux/vserver/sched_def.h     1970-01-01 00:00:00.000000000 +0000
12033 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/sched_def.h   2013-08-22 20:30:00.000000000 +0000
12034 @@ -0,0 +1,38 @@
12035 +#ifndef _VSERVER_SCHED_DEF_H
12036 +#define _VSERVER_SCHED_DEF_H
12037 +
12038 +#include <linux/spinlock.h>
12039 +#include <linux/jiffies.h>
12040 +#include <linux/cpumask.h>
12041 +#include <asm/atomic.h>
12042 +#include <asm/param.h>
12043 +
12044 +
12045 +/* context sub struct */
12046 +
12047 +struct _vx_sched {
12048 +       int prio_bias;                  /* bias offset for priority */
12049 +
12050 +       cpumask_t update;               /* CPUs which should update */
12051 +};
12052 +
12053 +struct _vx_sched_pc {
12054 +       int prio_bias;                  /* bias offset for priority */
12055 +
12056 +       uint64_t user_ticks;            /* token tick events */
12057 +       uint64_t sys_ticks;             /* token tick events */
12058 +       uint64_t hold_ticks;            /* token ticks paused */
12059 +};
12060 +
12061 +
12062 +#ifdef CONFIG_VSERVER_DEBUG
12063 +
12064 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12065 +{
12066 +       printk("\t_vx_sched:\n");
12067 +       printk("\t priority = %4d\n", sched->prio_bias);
12068 +}
12069 +
12070 +#endif
12071 +
12072 +#endif /* _VSERVER_SCHED_DEF_H */
12073 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/signal.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/signal.h
12074 --- linux-3.10.40/include/linux/vserver/signal.h        1970-01-01 00:00:00.000000000 +0000
12075 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/signal.h      2013-08-22 20:30:00.000000000 +0000
12076 @@ -0,0 +1,14 @@
12077 +#ifndef _VSERVER_SIGNAL_H
12078 +#define _VSERVER_SIGNAL_H
12079 +
12080 +
12081 +#ifdef __KERNEL__
12082 +
12083 +struct vx_info;
12084 +
12085 +int vx_info_kill(struct vx_info *, int, int);
12086 +
12087 +#endif /* __KERNEL__ */
12088 +#else  /* _VSERVER_SIGNAL_H */
12089 +#warning duplicate inclusion
12090 +#endif /* _VSERVER_SIGNAL_H */
12091 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/signal_cmd.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/signal_cmd.h
12092 --- linux-3.10.40/include/linux/vserver/signal_cmd.h    1970-01-01 00:00:00.000000000 +0000
12093 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/signal_cmd.h  2013-08-22 20:30:00.000000000 +0000
12094 @@ -0,0 +1,14 @@
12095 +#ifndef _VSERVER_SIGNAL_CMD_H
12096 +#define _VSERVER_SIGNAL_CMD_H
12097 +
12098 +#include <uapi/vserver/signal_cmd.h>
12099 +
12100 +
12101 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12102 +extern int vc_wait_exit(struct vx_info *, void __user *);
12103 +
12104 +
12105 +extern int vc_get_pflags(uint32_t pid, void __user *);
12106 +extern int vc_set_pflags(uint32_t pid, void __user *);
12107 +
12108 +#endif /* _VSERVER_SIGNAL_CMD_H */
12109 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/space.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/space.h
12110 --- linux-3.10.40/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
12111 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/space.h       2013-08-22 20:30:00.000000000 +0000
12112 @@ -0,0 +1,12 @@
12113 +#ifndef _VSERVER_SPACE_H
12114 +#define _VSERVER_SPACE_H
12115 +
12116 +#include <linux/types.h>
12117 +
12118 +struct vx_info;
12119 +
12120 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12121 +
12122 +#else  /* _VSERVER_SPACE_H */
12123 +#warning duplicate inclusion
12124 +#endif /* _VSERVER_SPACE_H */
12125 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/space_cmd.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/space_cmd.h
12126 --- linux-3.10.40/include/linux/vserver/space_cmd.h     1970-01-01 00:00:00.000000000 +0000
12127 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/space_cmd.h   2013-08-22 20:30:00.000000000 +0000
12128 @@ -0,0 +1,13 @@
12129 +#ifndef _VSERVER_SPACE_CMD_H
12130 +#define _VSERVER_SPACE_CMD_H
12131 +
12132 +#include <uapi/vserver/space_cmd.h>
12133 +
12134 +
12135 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12136 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12137 +extern int vc_enter_space(struct vx_info *, void __user *);
12138 +extern int vc_set_space(struct vx_info *, void __user *);
12139 +extern int vc_get_space_mask(void __user *, int);
12140 +
12141 +#endif /* _VSERVER_SPACE_CMD_H */
12142 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/switch.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/switch.h
12143 --- linux-3.10.40/include/linux/vserver/switch.h        1970-01-01 00:00:00.000000000 +0000
12144 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/switch.h      2013-08-22 20:30:00.000000000 +0000
12145 @@ -0,0 +1,8 @@
12146 +#ifndef _VSERVER_SWITCH_H
12147 +#define _VSERVER_SWITCH_H
12148 +
12149 +
12150 +#include <linux/errno.h>
12151 +#include <uapi/vserver/switch.h>
12152 +
12153 +#endif /* _VSERVER_SWITCH_H */
12154 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/tag.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/tag.h
12155 --- linux-3.10.40/include/linux/vserver/tag.h   1970-01-01 00:00:00.000000000 +0000
12156 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/tag.h 2013-08-22 20:30:00.000000000 +0000
12157 @@ -0,0 +1,160 @@
12158 +#ifndef _DX_TAG_H
12159 +#define _DX_TAG_H
12160 +
12161 +#include <linux/types.h>
12162 +#include <linux/uidgid.h>
12163 +
12164 +
12165 +#define DX_TAG(in)     (IS_TAGGED(in))
12166 +
12167 +
12168 +#ifdef CONFIG_TAG_NFSD
12169 +#define DX_TAG_NFSD    1
12170 +#else
12171 +#define DX_TAG_NFSD    0
12172 +#endif
12173 +
12174 +
12175 +#ifdef CONFIG_TAGGING_NONE
12176 +
12177 +#define MAX_UID                0xFFFFFFFF
12178 +#define MAX_GID                0xFFFFFFFF
12179 +
12180 +#define INOTAG_TAG(cond, uid, gid, tag)        (0)
12181 +
12182 +#define TAGINO_UID(cond, uid, tag)     (uid)
12183 +#define TAGINO_GID(cond, gid, tag)     (gid)
12184 +
12185 +#endif
12186 +
12187 +
12188 +#ifdef CONFIG_TAGGING_GID16
12189 +
12190 +#define MAX_UID                0xFFFFFFFF
12191 +#define MAX_GID                0x0000FFFF
12192 +
12193 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12194 +       ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
12195 +
12196 +#define TAGINO_UID(cond, uid, tag)     (uid)
12197 +#define TAGINO_GID(cond, gid, tag)     \
12198 +       ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
12199 +
12200 +#endif
12201 +
12202 +
12203 +#ifdef CONFIG_TAGGING_ID24
12204 +
12205 +#define MAX_UID                0x00FFFFFF
12206 +#define MAX_GID                0x00FFFFFF
12207 +
12208 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12209 +       ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
12210 +
12211 +#define TAGINO_UID(cond, uid, tag)     \
12212 +       ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
12213 +#define TAGINO_GID(cond, gid, tag)     \
12214 +       ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
12215 +
12216 +#endif
12217 +
12218 +
12219 +#ifdef CONFIG_TAGGING_UID16
12220 +
12221 +#define MAX_UID                0x0000FFFF
12222 +#define MAX_GID                0xFFFFFFFF
12223 +
12224 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12225 +       ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
12226 +
12227 +#define TAGINO_UID(cond, uid, tag)     \
12228 +       ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
12229 +#define TAGINO_GID(cond, gid, tag)     (gid)
12230 +
12231 +#endif
12232 +
12233 +
12234 +#ifdef CONFIG_TAGGING_INTERN
12235 +
12236 +#define MAX_UID                0xFFFFFFFF
12237 +#define MAX_GID                0xFFFFFFFF
12238 +
12239 +#define INOTAG_TAG(cond, uid, gid, tag)        \
12240 +       ((cond) ? (tag) : 0)
12241 +
12242 +#define TAGINO_UID(cond, uid, tag)     (uid)
12243 +#define TAGINO_GID(cond, gid, tag)     (gid)
12244 +
12245 +#endif
12246 +
12247 +
12248 +#ifndef CONFIG_TAGGING_NONE
12249 +#define dx_current_fstag(sb)   \
12250 +       ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
12251 +#else
12252 +#define dx_current_fstag(sb)   (0)
12253 +#endif
12254 +
12255 +#ifndef CONFIG_TAGGING_INTERN
12256 +#define TAGINO_TAG(cond, tag)  (0)
12257 +#else
12258 +#define TAGINO_TAG(cond, tag)  ((cond) ? (tag) : 0)
12259 +#endif
12260 +
12261 +#define TAGINO_KUID(cond, kuid, ktag)  \
12262 +       KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
12263 +#define TAGINO_KGID(cond, kgid, ktag)  \
12264 +       KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
12265 +#define TAGINO_KTAG(cond, ktag)                \
12266 +       KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
12267 +
12268 +
12269 +#define INOTAG_UID(cond, uid, gid)     \
12270 +       ((cond) ? ((uid) & MAX_UID) : (uid))
12271 +#define INOTAG_GID(cond, uid, gid)     \
12272 +       ((cond) ? ((gid) & MAX_GID) : (gid))
12273 +
12274 +#define INOTAG_KUID(cond, kuid, kgid)  \
12275 +       KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
12276 +#define INOTAG_KGID(cond, kuid, kgid)  \
12277 +       KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
12278 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
12279 +       KTAGT_INIT(INOTAG_TAG(cond, \
12280 +               __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
12281 +
12282 +
12283 +static inline uid_t dx_map_uid(uid_t uid)
12284 +{
12285 +       if ((uid > MAX_UID) && (uid != -1))
12286 +               uid = -2;
12287 +       return (uid & MAX_UID);
12288 +}
12289 +
12290 +static inline gid_t dx_map_gid(gid_t gid)
12291 +{
12292 +       if ((gid > MAX_GID) && (gid != -1))
12293 +               gid = -2;
12294 +       return (gid & MAX_GID);
12295 +}
12296 +
12297 +struct peer_tag {
12298 +       int32_t xid;
12299 +       int32_t nid;
12300 +};
12301 +
12302 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
12303 +
12304 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
12305 +                unsigned long *flags);
12306 +
12307 +#ifdef CONFIG_PROPAGATE
12308 +
12309 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
12310 +
12311 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
12312 +
12313 +#else
12314 +#define dx_propagate_tag(n, i) do { } while (0)
12315 +#endif
12316 +
12317 +#endif /* _DX_TAG_H */
12318 diff -NurpP --minimal linux-3.10.40/include/linux/vserver/tag_cmd.h linux-3.10.40-vs2.3.6.8/include/linux/vserver/tag_cmd.h
12319 --- linux-3.10.40/include/linux/vserver/tag_cmd.h       1970-01-01 00:00:00.000000000 +0000
12320 +++ linux-3.10.40-vs2.3.6.8/include/linux/vserver/tag_cmd.h     2013-08-22 20:30:00.000000000 +0000
12321 @@ -0,0 +1,10 @@
12322 +#ifndef _VSERVER_TAG_CMD_H
12323 +#define _VSERVER_TAG_CMD_H
12324 +
12325 +#include <uapi/vserver/tag_cmd.h>
12326 +
12327 +extern int vc_task_tag(uint32_t);
12328 +
12329 +extern int vc_tag_migrate(uint32_t);
12330 +
12331 +#endif /* _VSERVER_TAG_CMD_H */
12332 diff -NurpP --minimal linux-3.10.40/include/net/addrconf.h linux-3.10.40-vs2.3.6.8/include/net/addrconf.h
12333 --- linux-3.10.40/include/net/addrconf.h        2014-05-20 04:09:41.000000000 +0000
12334 +++ linux-3.10.40-vs2.3.6.8/include/net/addrconf.h      2013-11-13 17:19:37.000000000 +0000
12335 @@ -89,7 +89,8 @@ extern int                    ipv6_dev_get_saddr(struct n
12336                                                const struct net_device *dev,
12337                                                const struct in6_addr *daddr,
12338                                                unsigned int srcprefs,
12339 -                                              struct in6_addr *saddr);
12340 +                                              struct in6_addr *saddr,
12341 +                                              struct nx_info *nxi);
12342  extern int                     __ipv6_get_lladdr(struct inet6_dev *idev,
12343                                                   struct in6_addr *addr,
12344                                                   unsigned char banned_flags);
12345 diff -NurpP --minimal linux-3.10.40/include/net/af_unix.h linux-3.10.40-vs2.3.6.8/include/net/af_unix.h
12346 --- linux-3.10.40/include/net/af_unix.h 2013-07-14 17:01:33.000000000 +0000
12347 +++ linux-3.10.40-vs2.3.6.8/include/net/af_unix.h       2013-08-22 20:30:00.000000000 +0000
12348 @@ -4,6 +4,7 @@
12349  #include <linux/socket.h>
12350  #include <linux/un.h>
12351  #include <linux/mutex.h>
12352 +#include <linux/vs_base.h>
12353  #include <net/sock.h>
12354  
12355  extern void unix_inflight(struct file *fp);
12356 diff -NurpP --minimal linux-3.10.40/include/net/inet_timewait_sock.h linux-3.10.40-vs2.3.6.8/include/net/inet_timewait_sock.h
12357 --- linux-3.10.40/include/net/inet_timewait_sock.h      2013-05-31 13:45:28.000000000 +0000
12358 +++ linux-3.10.40-vs2.3.6.8/include/net/inet_timewait_sock.h    2013-08-22 20:30:00.000000000 +0000
12359 @@ -116,6 +116,10 @@ struct inet_timewait_sock {
12360  #define tw_dport               __tw_common.skc_dport
12361  #define tw_num                 __tw_common.skc_num
12362  #define tw_portpair            __tw_common.skc_portpair
12363 +#define tw_xid                 __tw_common.skc_xid
12364 +#define tw_vx_info             __tw_common.skc_vx_info
12365 +#define tw_nid                 __tw_common.skc_nid
12366 +#define tw_nx_info             __tw_common.skc_nx_info
12367  
12368         int                     tw_timeout;
12369         volatile unsigned char  tw_substate;
12370 diff -NurpP --minimal linux-3.10.40/include/net/ip6_route.h linux-3.10.40-vs2.3.6.8/include/net/ip6_route.h
12371 --- linux-3.10.40/include/net/ip6_route.h       2014-05-20 04:09:41.000000000 +0000
12372 +++ linux-3.10.40-vs2.3.6.8/include/net/ip6_route.h     2013-11-13 17:22:25.000000000 +0000
12373 @@ -95,7 +95,8 @@ extern int                    ip6_route_get_saddr(struct
12374                                                     struct rt6_info *rt,
12375                                                     const struct in6_addr *daddr,
12376                                                     unsigned int prefs,
12377 -                                                   struct in6_addr *saddr);
12378 +                                                   struct in6_addr *saddr,
12379 +                                                   struct nx_info *nxi);
12380  
12381  extern struct rt6_info         *rt6_lookup(struct net *net,
12382                                             const struct in6_addr *daddr,
12383 diff -NurpP --minimal linux-3.10.40/include/net/route.h linux-3.10.40-vs2.3.6.8/include/net/route.h
12384 --- linux-3.10.40/include/net/route.h   2013-02-19 13:58:52.000000000 +0000
12385 +++ linux-3.10.40-vs2.3.6.8/include/net/route.h 2013-08-22 20:30:00.000000000 +0000
12386 @@ -207,6 +207,9 @@ static inline void ip_rt_put(struct rtab
12387         dst_release(&rt->dst);
12388  }
12389  
12390 +#include <linux/vs_base.h>
12391 +#include <linux/vs_inet.h>
12392 +
12393  #define IPTOS_RT_MASK  (IPTOS_TOS_MASK & ~3)
12394  
12395  extern const __u8 ip_tos2prio[16];
12396 @@ -256,6 +259,9 @@ static inline void ip_route_connect_init
12397                            protocol, flow_flags, dst, src, dport, sport);
12398  }
12399  
12400 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
12401 +       struct flowi4 *);
12402 +
12403  static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
12404                                               __be32 dst, __be32 src, u32 tos,
12405                                               int oif, u8 protocol,
12406 @@ -264,11 +270,25 @@ static inline struct rtable *ip_route_co
12407  {
12408         struct net *net = sock_net(sk);
12409         struct rtable *rt;
12410 +       struct nx_info *nx_info = current_nx_info();
12411  
12412         ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
12413                               sport, dport, sk, can_sleep);
12414  
12415 -       if (!dst || !src) {
12416 +       if (sk)
12417 +               nx_info = sk->sk_nx_info;
12418 +
12419 +       vxdprintk(VXD_CBIT(net, 4),
12420 +               "ip_route_connect(%p) %p,%p;%lx",
12421 +               sk, nx_info, sk->sk_socket,
12422 +               (sk->sk_socket?sk->sk_socket->flags:0));
12423 +
12424 +       rt = ip_v4_find_src(net, nx_info, fl4);
12425 +       if (IS_ERR(rt))
12426 +               return rt;
12427 +       ip_rt_put(rt);
12428 +
12429 +       if (!fl4->daddr || !fl4->saddr) {
12430                 rt = __ip_route_output_key(net, fl4);
12431                 if (IS_ERR(rt))
12432                         return rt;
12433 diff -NurpP --minimal linux-3.10.40/include/net/sock.h linux-3.10.40-vs2.3.6.8/include/net/sock.h
12434 --- linux-3.10.40/include/net/sock.h    2014-05-20 04:09:41.000000000 +0000
12435 +++ linux-3.10.40-vs2.3.6.8/include/net/sock.h  2014-04-22 03:48:11.000000000 +0000
12436 @@ -191,6 +191,10 @@ struct sock_common {
12437  #ifdef CONFIG_NET_NS
12438         struct net              *skc_net;
12439  #endif
12440 +       vxid_t                  skc_xid;
12441 +       struct vx_info          *skc_vx_info;
12442 +       vnid_t                  skc_nid;
12443 +       struct nx_info          *skc_nx_info;
12444         /*
12445          * fields between dontcopy_begin/dontcopy_end
12446          * are not copied in sock_copy()
12447 @@ -305,6 +309,10 @@ struct sock {
12448  #define sk_bind_node           __sk_common.skc_bind_node
12449  #define sk_prot                        __sk_common.skc_prot
12450  #define sk_net                 __sk_common.skc_net
12451 +#define sk_xid                 __sk_common.skc_xid
12452 +#define sk_vx_info             __sk_common.skc_vx_info
12453 +#define sk_nid                 __sk_common.skc_nid
12454 +#define sk_nx_info             __sk_common.skc_nx_info
12455         socket_lock_t           sk_lock;
12456         struct sk_buff_head     sk_receive_queue;
12457         /*
12458 diff -NurpP --minimal linux-3.10.40/include/uapi/Kbuild linux-3.10.40-vs2.3.6.8/include/uapi/Kbuild
12459 --- linux-3.10.40/include/uapi/Kbuild   2012-12-11 03:30:57.000000000 +0000
12460 +++ linux-3.10.40-vs2.3.6.8/include/uapi/Kbuild 2013-08-22 20:30:00.000000000 +0000
12461 @@ -12,3 +12,4 @@ header-y += video/
12462  header-y += drm/
12463  header-y += xen/
12464  header-y += scsi/
12465 +header-y += vserver/
12466 diff -NurpP --minimal linux-3.10.40/include/uapi/linux/capability.h linux-3.10.40-vs2.3.6.8/include/uapi/linux/capability.h
12467 --- linux-3.10.40/include/uapi/linux/capability.h       2012-12-11 03:30:57.000000000 +0000
12468 +++ linux-3.10.40-vs2.3.6.8/include/uapi/linux/capability.h     2013-08-22 20:30:00.000000000 +0000
12469 @@ -259,6 +259,7 @@ struct vfs_cap_data {
12470     arbitrary SCSI commands */
12471  /* Allow setting encryption key on loopback filesystem */
12472  /* Allow setting zone reclaim policy */
12473 +/* Allow the selection of a security context */
12474  
12475  #define CAP_SYS_ADMIN        21
12476  
12477 @@ -345,7 +346,12 @@ struct vfs_cap_data {
12478  
12479  #define CAP_LAST_CAP         CAP_BLOCK_SUSPEND
12480  
12481 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
12482 +/* Allow context manipulations */
12483 +/* Allow changing context info on files */
12484 +
12485 +#define CAP_CONTEXT         63
12486 +
12487 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
12488  
12489  /*
12490   * Bit location of each capability (used by user-space library and kernel)
12491 diff -NurpP --minimal linux-3.10.40/include/uapi/linux/fs.h linux-3.10.40-vs2.3.6.8/include/uapi/linux/fs.h
12492 --- linux-3.10.40/include/uapi/linux/fs.h       2013-07-14 17:01:34.000000000 +0000
12493 +++ linux-3.10.40-vs2.3.6.8/include/uapi/linux/fs.h     2013-08-22 20:30:00.000000000 +0000
12494 @@ -86,6 +86,9 @@ struct inodes_stat_t {
12495  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
12496  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
12497  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
12498 +#define MS_TAGGED      (1<<8)  /* use generic inode tagging */
12499 +#define MS_NOTAGCHECK  (1<<9)  /* don't check tags */
12500 +#define MS_TAGID       (1<<25) /* use specific tag for this mount */
12501  
12502  /* These sb flags are internal to the kernel */
12503  #define MS_NOSEC       (1<<28)
12504 @@ -191,11 +194,14 @@ struct inodes_stat_t {
12505  #define FS_EXTENT_FL                   0x00080000 /* Extents */
12506  #define FS_DIRECTIO_FL                 0x00100000 /* Use direct i/o */
12507  #define FS_NOCOW_FL                    0x00800000 /* Do not cow file */
12508 +#define FS_IXUNLINK_FL                 0x08000000 /* Immutable invert on unlink */
12509  #define FS_RESERVED_FL                 0x80000000 /* reserved for ext2 lib */
12510  
12511 -#define FS_FL_USER_VISIBLE             0x0003DFFF /* User visible flags */
12512 -#define FS_FL_USER_MODIFIABLE          0x000380FF /* User modifiable flags */
12513 +#define FS_BARRIER_FL                  0x04000000 /* Barrier for chroot() */
12514 +#define FS_COW_FL                      0x20000000 /* Copy on Write marker */
12515  
12516 +#define FS_FL_USER_VISIBLE             0x0103DFFF /* User visible flags */
12517 +#define FS_FL_USER_MODIFIABLE          0x010380FF /* User modifiable flags */
12518  
12519  #define SYNC_FILE_RANGE_WAIT_BEFORE    1
12520  #define SYNC_FILE_RANGE_WRITE          2
12521 diff -NurpP --minimal linux-3.10.40/include/uapi/linux/gfs2_ondisk.h linux-3.10.40-vs2.3.6.8/include/uapi/linux/gfs2_ondisk.h
12522 --- linux-3.10.40/include/uapi/linux/gfs2_ondisk.h      2012-12-11 03:30:57.000000000 +0000
12523 +++ linux-3.10.40-vs2.3.6.8/include/uapi/linux/gfs2_ondisk.h    2013-08-22 20:30:00.000000000 +0000
12524 @@ -225,6 +225,9 @@ enum {
12525         gfs2fl_Sync             = 8,
12526         gfs2fl_System           = 9,
12527         gfs2fl_TopLevel         = 10,
12528 +       gfs2fl_IXUnlink         = 16,
12529 +       gfs2fl_Barrier          = 17,
12530 +       gfs2fl_Cow              = 18,
12531         gfs2fl_TruncInProg      = 29,
12532         gfs2fl_InheritDirectio  = 30,
12533         gfs2fl_InheritJdata     = 31,
12534 @@ -242,6 +245,9 @@ enum {
12535  #define GFS2_DIF_SYNC                  0x00000100
12536  #define GFS2_DIF_SYSTEM                        0x00000200 /* New in gfs2 */
12537  #define GFS2_DIF_TOPDIR                        0x00000400 /* New in gfs2 */
12538 +#define GFS2_DIF_IXUNLINK               0x00010000
12539 +#define GFS2_DIF_BARRIER                0x00020000
12540 +#define GFS2_DIF_COW                    0x00040000
12541  #define GFS2_DIF_TRUNC_IN_PROG         0x20000000 /* New in gfs2 */
12542  #define GFS2_DIF_INHERIT_DIRECTIO      0x40000000 /* only in gfs1 */
12543  #define GFS2_DIF_INHERIT_JDATA         0x80000000
12544 diff -NurpP --minimal linux-3.10.40/include/uapi/linux/if_tun.h linux-3.10.40-vs2.3.6.8/include/uapi/linux/if_tun.h
12545 --- linux-3.10.40/include/uapi/linux/if_tun.h   2013-02-19 13:58:55.000000000 +0000
12546 +++ linux-3.10.40-vs2.3.6.8/include/uapi/linux/if_tun.h 2013-08-22 20:30:00.000000000 +0000
12547 @@ -56,6 +56,7 @@
12548  #define TUNGETVNETHDRSZ _IOR('T', 215, int)
12549  #define TUNSETVNETHDRSZ _IOW('T', 216, int)
12550  #define TUNSETQUEUE  _IOW('T', 217, int)
12551 +#define TUNSETNID     _IOW('T', 218, int)
12552  
12553  /* TUNSETIFF ifr flags */
12554  #define IFF_TUN                0x0001
12555 diff -NurpP --minimal linux-3.10.40/include/uapi/linux/major.h linux-3.10.40-vs2.3.6.8/include/uapi/linux/major.h
12556 --- linux-3.10.40/include/uapi/linux/major.h    2012-12-11 03:30:57.000000000 +0000
12557 +++ linux-3.10.40-vs2.3.6.8/include/uapi/linux/major.h  2013-08-22 20:30:00.000000000 +0000
12558 @@ -15,6 +15,7 @@
12559  #define HD_MAJOR               IDE0_MAJOR
12560  #define PTY_SLAVE_MAJOR                3
12561  #define TTY_MAJOR              4
12562 +#define VROOT_MAJOR            4
12563  #define TTYAUX_MAJOR           5
12564  #define LP_MAJOR               6
12565  #define VCS_MAJOR              7
12566 diff -NurpP --minimal linux-3.10.40/include/uapi/linux/nfs_mount.h linux-3.10.40-vs2.3.6.8/include/uapi/linux/nfs_mount.h
12567 --- linux-3.10.40/include/uapi/linux/nfs_mount.h        2012-12-11 03:30:57.000000000 +0000
12568 +++ linux-3.10.40-vs2.3.6.8/include/uapi/linux/nfs_mount.h      2013-08-22 20:30:00.000000000 +0000
12569 @@ -63,7 +63,8 @@ struct nfs_mount_data {
12570  #define NFS_MOUNT_SECFLAVOUR   0x2000  /* 5 */
12571  #define NFS_MOUNT_NORDIRPLUS   0x4000  /* 5 */
12572  #define NFS_MOUNT_UNSHARED     0x8000  /* 5 */
12573 -#define NFS_MOUNT_FLAGMASK     0xFFFF
12574 +#define NFS_MOUNT_TAGGED       0x10000 /* context tagging */
12575 +#define NFS_MOUNT_FLAGMASK     0x1FFFF
12576  
12577  /* The following are for internal use only */
12578  #define NFS_MOUNT_LOOKUP_CACHE_NONEG   0x10000
12579 diff -NurpP --minimal linux-3.10.40/include/uapi/linux/reboot.h linux-3.10.40-vs2.3.6.8/include/uapi/linux/reboot.h
12580 --- linux-3.10.40/include/uapi/linux/reboot.h   2012-12-11 03:30:57.000000000 +0000
12581 +++ linux-3.10.40-vs2.3.6.8/include/uapi/linux/reboot.h 2013-08-22 20:30:00.000000000 +0000
12582 @@ -33,7 +33,7 @@
12583  #define        LINUX_REBOOT_CMD_RESTART2       0xA1B2C3D4
12584  #define        LINUX_REBOOT_CMD_SW_SUSPEND     0xD000FCE2
12585  #define        LINUX_REBOOT_CMD_KEXEC          0x45584543
12586 -
12587 +#define        LINUX_REBOOT_CMD_OOM            0xDEADBEEF
12588  
12589  
12590  #endif /* _UAPI_LINUX_REBOOT_H */
12591 diff -NurpP --minimal linux-3.10.40/include/uapi/linux/sysctl.h linux-3.10.40-vs2.3.6.8/include/uapi/linux/sysctl.h
12592 --- linux-3.10.40/include/uapi/linux/sysctl.h   2012-12-11 03:30:57.000000000 +0000
12593 +++ linux-3.10.40-vs2.3.6.8/include/uapi/linux/sysctl.h 2013-08-22 20:30:00.000000000 +0000
12594 @@ -60,6 +60,7 @@ enum
12595         CTL_ABI=9,              /* Binary emulation */
12596         CTL_CPU=10,             /* CPU stuff (speed scaling, etc) */
12597         CTL_ARLAN=254,          /* arlan wireless driver */
12598 +       CTL_VSERVER=4242,       /* Linux-VServer debug */
12599         CTL_S390DBF=5677,       /* s390 debug */
12600         CTL_SUNRPC=7249,        /* sunrpc debug */
12601         CTL_PM=9899,            /* frv power management */
12602 @@ -94,6 +95,7 @@ enum
12603  
12604         KERN_PANIC=15,          /* int: panic timeout */
12605         KERN_REALROOTDEV=16,    /* real root device to mount after initrd */
12606 +       KERN_VSHELPER=17,       /* string: path to vshelper policy agent */
12607  
12608         KERN_SPARC_REBOOT=21,   /* reboot command on Sparc */
12609         KERN_CTLALTDEL=22,      /* int: allow ctl-alt-del to reboot */
12610 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/Kbuild linux-3.10.40-vs2.3.6.8/include/uapi/vserver/Kbuild
12611 --- linux-3.10.40/include/uapi/vserver/Kbuild   1970-01-01 00:00:00.000000000 +0000
12612 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/Kbuild 2013-08-22 20:30:00.000000000 +0000
12613 @@ -0,0 +1,9 @@
12614 +
12615 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12616 +       cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12617 +       inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12618 +       debug_cmd.h device_cmd.h
12619 +
12620 +header-y += switch.h context.h network.h monitor.h \
12621 +       limit.h inode.h device.h
12622 +
12623 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/cacct_cmd.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/cacct_cmd.h
12624 --- linux-3.10.40/include/uapi/vserver/cacct_cmd.h      1970-01-01 00:00:00.000000000 +0000
12625 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/cacct_cmd.h    2013-08-22 20:30:00.000000000 +0000
12626 @@ -0,0 +1,15 @@
12627 +#ifndef _UAPI_VS_CACCT_CMD_H
12628 +#define _UAPI_VS_CACCT_CMD_H
12629 +
12630 +
12631 +/* virtual host info name commands */
12632 +
12633 +#define VCMD_sock_stat         VC_CMD(VSTAT, 5, 0)
12634 +
12635 +struct vcmd_sock_stat_v0 {
12636 +       uint32_t field;
12637 +       uint32_t count[3];
12638 +       uint64_t total[3];
12639 +};
12640 +
12641 +#endif /* _UAPI_VS_CACCT_CMD_H */
12642 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/context.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/context.h
12643 --- linux-3.10.40/include/uapi/vserver/context.h        1970-01-01 00:00:00.000000000 +0000
12644 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/context.h      2013-10-27 03:43:35.000000000 +0000
12645 @@ -0,0 +1,81 @@
12646 +#ifndef _UAPI_VS_CONTEXT_H
12647 +#define _UAPI_VS_CONTEXT_H
12648 +
12649 +#include <linux/types.h>
12650 +#include <linux/capability.h>
12651 +
12652 +
12653 +/* context flags */
12654 +
12655 +#define VXF_INFO_SCHED         0x00000002
12656 +#define VXF_INFO_NPROC         0x00000004
12657 +#define VXF_INFO_PRIVATE       0x00000008
12658 +
12659 +#define VXF_INFO_INIT          0x00000010
12660 +#define VXF_INFO_HIDE          0x00000020
12661 +#define VXF_INFO_ULIMIT                0x00000040
12662 +#define VXF_INFO_NSPACE                0x00000080
12663 +
12664 +#define VXF_SCHED_HARD         0x00000100
12665 +#define VXF_SCHED_PRIO         0x00000200
12666 +#define VXF_SCHED_PAUSE                0x00000400
12667 +
12668 +#define VXF_VIRT_MEM           0x00010000
12669 +#define VXF_VIRT_UPTIME                0x00020000
12670 +#define VXF_VIRT_CPU           0x00040000
12671 +#define VXF_VIRT_LOAD          0x00080000
12672 +#define VXF_VIRT_TIME          0x00100000
12673 +
12674 +#define VXF_HIDE_MOUNT         0x01000000
12675 +/* was VXF_HIDE_NETIF          0x02000000 */
12676 +#define VXF_HIDE_VINFO         0x04000000
12677 +
12678 +#define VXF_STATE_SETUP                (1ULL << 32)
12679 +#define VXF_STATE_INIT         (1ULL << 33)
12680 +#define VXF_STATE_ADMIN                (1ULL << 34)
12681 +
12682 +#define VXF_SC_HELPER          (1ULL << 36)
12683 +#define VXF_REBOOT_KILL                (1ULL << 37)
12684 +#define VXF_PERSISTENT         (1ULL << 38)
12685 +
12686 +#define VXF_FORK_RSS           (1ULL << 48)
12687 +#define VXF_PROLIFIC           (1ULL << 49)
12688 +
12689 +#define VXF_IGNEG_NICE         (1ULL << 52)
12690 +
12691 +#define VXF_ONE_TIME           (0x0007ULL << 32)
12692 +
12693 +#define VXF_INIT_SET           (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12694 +
12695 +
12696 +/* context migration */
12697 +
12698 +#define VXM_SET_INIT           0x00000001
12699 +#define VXM_SET_REAPER         0x00000002
12700 +
12701 +/* context caps */
12702 +
12703 +#define VXC_SET_UTSNAME                0x00000001
12704 +#define VXC_SET_RLIMIT         0x00000002
12705 +#define VXC_FS_SECURITY                0x00000004
12706 +#define VXC_FS_TRUSTED         0x00000008
12707 +#define VXC_TIOCSTI            0x00000010
12708 +
12709 +/* was VXC_RAW_ICMP            0x00000100 */
12710 +#define VXC_SYSLOG             0x00001000
12711 +#define VXC_OOM_ADJUST         0x00002000
12712 +#define VXC_AUDIT_CONTROL      0x00004000
12713 +
12714 +#define VXC_SECURE_MOUNT       0x00010000
12715 +/* #define VXC_SECURE_REMOUNT  0x00020000 */
12716 +#define VXC_BINARY_MOUNT       0x00040000
12717 +#define VXC_DEV_MOUNT          0x00080000
12718 +
12719 +#define VXC_QUOTA_CTL          0x00100000
12720 +#define VXC_ADMIN_MAPPER       0x00200000
12721 +#define VXC_ADMIN_CLOOP                0x00400000
12722 +
12723 +#define VXC_KTHREAD            0x01000000
12724 +#define VXC_NAMESPACE          0x02000000
12725 +
12726 +#endif /* _UAPI_VS_CONTEXT_H */
12727 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/context_cmd.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/context_cmd.h
12728 --- linux-3.10.40/include/uapi/vserver/context_cmd.h    1970-01-01 00:00:00.000000000 +0000
12729 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/context_cmd.h  2013-08-22 20:30:00.000000000 +0000
12730 @@ -0,0 +1,115 @@
12731 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12732 +#define _UAPI_VS_CONTEXT_CMD_H
12733 +
12734 +
12735 +/* vinfo commands */
12736 +
12737 +#define VCMD_task_xid          VC_CMD(VINFO, 1, 0)
12738 +
12739 +
12740 +#define VCMD_vx_info           VC_CMD(VINFO, 5, 0)
12741 +
12742 +struct vcmd_vx_info_v0 {
12743 +       uint32_t xid;
12744 +       uint32_t initpid;
12745 +       /* more to come */
12746 +};
12747 +
12748 +
12749 +#define VCMD_ctx_stat          VC_CMD(VSTAT, 0, 0)
12750 +
12751 +struct vcmd_ctx_stat_v0 {
12752 +       uint32_t usecnt;
12753 +       uint32_t tasks;
12754 +       /* more to come */
12755 +};
12756 +
12757 +
12758 +/* context commands */
12759 +
12760 +#define VCMD_ctx_create_v0     VC_CMD(VPROC, 1, 0)
12761 +#define VCMD_ctx_create                VC_CMD(VPROC, 1, 1)
12762 +
12763 +struct vcmd_ctx_create {
12764 +       uint64_t flagword;
12765 +};
12766 +
12767 +#define VCMD_ctx_migrate_v0    VC_CMD(PROCMIG, 1, 0)
12768 +#define VCMD_ctx_migrate       VC_CMD(PROCMIG, 1, 1)
12769 +
12770 +struct vcmd_ctx_migrate {
12771 +       uint64_t flagword;
12772 +};
12773 +
12774 +
12775 +
12776 +/* flag commands */
12777 +
12778 +#define VCMD_get_cflags                VC_CMD(FLAGS, 1, 0)
12779 +#define VCMD_set_cflags                VC_CMD(FLAGS, 2, 0)
12780 +
12781 +struct vcmd_ctx_flags_v0 {
12782 +       uint64_t flagword;
12783 +       uint64_t mask;
12784 +};
12785 +
12786 +
12787 +
12788 +/* context caps commands */
12789 +
12790 +#define VCMD_get_ccaps         VC_CMD(FLAGS, 3, 1)
12791 +#define VCMD_set_ccaps         VC_CMD(FLAGS, 4, 1)
12792 +
12793 +struct vcmd_ctx_caps_v1 {
12794 +       uint64_t ccaps;
12795 +       uint64_t cmask;
12796 +};
12797 +
12798 +
12799 +
12800 +/* bcaps commands */
12801 +
12802 +#define VCMD_get_bcaps         VC_CMD(FLAGS, 9, 0)
12803 +#define VCMD_set_bcaps         VC_CMD(FLAGS, 10, 0)
12804 +
12805 +struct vcmd_bcaps {
12806 +       uint64_t bcaps;
12807 +       uint64_t bmask;
12808 +};
12809 +
12810 +
12811 +
12812 +/* umask commands */
12813 +
12814 +#define VCMD_get_umask         VC_CMD(FLAGS, 13, 0)
12815 +#define VCMD_set_umask         VC_CMD(FLAGS, 14, 0)
12816 +
12817 +struct vcmd_umask {
12818 +       uint64_t umask;
12819 +       uint64_t mask;
12820 +};
12821 +
12822 +
12823 +
12824 +/* wmask commands */
12825 +
12826 +#define VCMD_get_wmask         VC_CMD(FLAGS, 15, 0)
12827 +#define VCMD_set_wmask         VC_CMD(FLAGS, 16, 0)
12828 +
12829 +struct vcmd_wmask {
12830 +       uint64_t wmask;
12831 +       uint64_t mask;
12832 +};
12833 +
12834 +
12835 +
12836 +/* OOM badness */
12837 +
12838 +#define VCMD_get_badness       VC_CMD(MEMCTRL, 5, 0)
12839 +#define VCMD_set_badness       VC_CMD(MEMCTRL, 6, 0)
12840 +
12841 +struct vcmd_badness_v0 {
12842 +       int64_t bias;
12843 +};
12844 +
12845 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12846 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/cvirt_cmd.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/cvirt_cmd.h
12847 --- linux-3.10.40/include/uapi/vserver/cvirt_cmd.h      1970-01-01 00:00:00.000000000 +0000
12848 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/cvirt_cmd.h    2013-08-22 20:30:00.000000000 +0000
12849 @@ -0,0 +1,41 @@
12850 +#ifndef _UAPI_VS_CVIRT_CMD_H
12851 +#define _UAPI_VS_CVIRT_CMD_H
12852 +
12853 +
12854 +/* virtual host info name commands */
12855 +
12856 +#define VCMD_set_vhi_name      VC_CMD(VHOST, 1, 0)
12857 +#define VCMD_get_vhi_name      VC_CMD(VHOST, 2, 0)
12858 +
12859 +struct vcmd_vhi_name_v0 {
12860 +       uint32_t field;
12861 +       char name[65];
12862 +};
12863 +
12864 +
12865 +enum vhi_name_field {
12866 +       VHIN_CONTEXT = 0,
12867 +       VHIN_SYSNAME,
12868 +       VHIN_NODENAME,
12869 +       VHIN_RELEASE,
12870 +       VHIN_VERSION,
12871 +       VHIN_MACHINE,
12872 +       VHIN_DOMAINNAME,
12873 +};
12874 +
12875 +
12876 +
12877 +#define VCMD_virt_stat         VC_CMD(VSTAT, 3, 0)
12878 +
12879 +struct vcmd_virt_stat_v0 {
12880 +       uint64_t offset;
12881 +       uint64_t uptime;
12882 +       uint32_t nr_threads;
12883 +       uint32_t nr_running;
12884 +       uint32_t nr_uninterruptible;
12885 +       uint32_t nr_onhold;
12886 +       uint32_t nr_forks;
12887 +       uint32_t load[3];
12888 +};
12889 +
12890 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12891 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/debug_cmd.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/debug_cmd.h
12892 --- linux-3.10.40/include/uapi/vserver/debug_cmd.h      1970-01-01 00:00:00.000000000 +0000
12893 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/debug_cmd.h    2013-08-22 20:30:00.000000000 +0000
12894 @@ -0,0 +1,24 @@
12895 +#ifndef _UAPI_VS_DEBUG_CMD_H
12896 +#define _UAPI_VS_DEBUG_CMD_H
12897 +
12898 +
12899 +/* debug commands */
12900 +
12901 +#define VCMD_dump_history      VC_CMD(DEBUG, 1, 0)
12902 +
12903 +#define VCMD_read_history      VC_CMD(DEBUG, 5, 0)
12904 +#define VCMD_read_monitor      VC_CMD(DEBUG, 6, 0)
12905 +
12906 +struct  vcmd_read_history_v0 {
12907 +       uint32_t index;
12908 +       uint32_t count;
12909 +       char __user *data;
12910 +};
12911 +
12912 +struct  vcmd_read_monitor_v0 {
12913 +       uint32_t index;
12914 +       uint32_t count;
12915 +       char __user *data;
12916 +};
12917 +
12918 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12919 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/device.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/device.h
12920 --- linux-3.10.40/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
12921 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/device.h       2013-08-22 20:30:00.000000000 +0000
12922 @@ -0,0 +1,12 @@
12923 +#ifndef _UAPI_VS_DEVICE_H
12924 +#define _UAPI_VS_DEVICE_H
12925 +
12926 +
12927 +#define DATTR_CREATE   0x00000001
12928 +#define DATTR_OPEN     0x00000002
12929 +
12930 +#define DATTR_REMAP    0x00000010
12931 +
12932 +#define DATTR_MASK     0x00000013
12933 +
12934 +#endif /* _UAPI_VS_DEVICE_H */
12935 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/device_cmd.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/device_cmd.h
12936 --- linux-3.10.40/include/uapi/vserver/device_cmd.h     1970-01-01 00:00:00.000000000 +0000
12937 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/device_cmd.h   2013-08-22 20:30:00.000000000 +0000
12938 @@ -0,0 +1,16 @@
12939 +#ifndef _UAPI_VS_DEVICE_CMD_H
12940 +#define _UAPI_VS_DEVICE_CMD_H
12941 +
12942 +
12943 +/*  device vserver commands */
12944 +
12945 +#define VCMD_set_mapping       VC_CMD(DEVICE, 1, 0)
12946 +#define VCMD_unset_mapping     VC_CMD(DEVICE, 2, 0)
12947 +
12948 +struct vcmd_set_mapping_v0 {
12949 +       const char __user *device;
12950 +       const char __user *target;
12951 +       uint32_t flags;
12952 +};
12953 +
12954 +#endif /* _UAPI_VS_DEVICE_CMD_H */
12955 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/dlimit_cmd.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/dlimit_cmd.h
12956 --- linux-3.10.40/include/uapi/vserver/dlimit_cmd.h     1970-01-01 00:00:00.000000000 +0000
12957 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/dlimit_cmd.h   2013-08-22 20:30:00.000000000 +0000
12958 @@ -0,0 +1,67 @@
12959 +#ifndef _UAPI_VS_DLIMIT_CMD_H
12960 +#define _UAPI_VS_DLIMIT_CMD_H
12961 +
12962 +
12963 +/*  dlimit vserver commands */
12964 +
12965 +#define VCMD_add_dlimit                VC_CMD(DLIMIT, 1, 0)
12966 +#define VCMD_rem_dlimit                VC_CMD(DLIMIT, 2, 0)
12967 +
12968 +#define VCMD_set_dlimit                VC_CMD(DLIMIT, 5, 0)
12969 +#define VCMD_get_dlimit                VC_CMD(DLIMIT, 6, 0)
12970 +
12971 +struct vcmd_ctx_dlimit_base_v0 {
12972 +       const char __user *name;
12973 +       uint32_t flags;
12974 +};
12975 +
12976 +struct vcmd_ctx_dlimit_v0 {
12977 +       const char __user *name;
12978 +       uint32_t space_used;                    /* used space in kbytes */
12979 +       uint32_t space_total;                   /* maximum space in kbytes */
12980 +       uint32_t inodes_used;                   /* used inodes */
12981 +       uint32_t inodes_total;                  /* maximum inodes */
12982 +       uint32_t reserved;                      /* reserved for root in % */
12983 +       uint32_t flags;
12984 +};
12985 +
12986 +#define CDLIM_UNSET            ((uint32_t)0UL)
12987 +#define CDLIM_INFINITY         ((uint32_t)~0UL)
12988 +#define CDLIM_KEEP             ((uint32_t)~1UL)
12989 +
12990 +#define DLIME_UNIT     0
12991 +#define DLIME_KILO     1
12992 +#define DLIME_MEGA     2
12993 +#define DLIME_GIGA     3
12994 +
12995 +#define DLIMF_SHIFT    0x10
12996 +
12997 +#define DLIMS_USED     0
12998 +#define DLIMS_TOTAL    2
12999 +
13000 +static inline
13001 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
13002 +{
13003 +       int exp = (flags & DLIMF_SHIFT) ?
13004 +               (flags >> shift) & DLIME_GIGA : DLIME_KILO;
13005 +       return ((uint64_t)val) << (10 * exp);
13006 +}
13007 +
13008 +static inline
13009 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
13010 +{
13011 +       int exp = 0;
13012 +
13013 +       if (*flags & DLIMF_SHIFT) {
13014 +               while (val > (1LL << 32) && (exp < 3)) {
13015 +                       val >>= 10;
13016 +                       exp++;
13017 +               }
13018 +               *flags &= ~(DLIME_GIGA << shift);
13019 +               *flags |= exp << shift;
13020 +       } else
13021 +               val >>= 10;
13022 +       return val;
13023 +}
13024 +
13025 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
13026 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/inode.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/inode.h
13027 --- linux-3.10.40/include/uapi/vserver/inode.h  1970-01-01 00:00:00.000000000 +0000
13028 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/inode.h        2013-08-22 20:30:00.000000000 +0000
13029 @@ -0,0 +1,23 @@
13030 +#ifndef _UAPI_VS_INODE_H
13031 +#define _UAPI_VS_INODE_H
13032 +
13033 +
13034 +#define IATTR_TAG      0x01000000
13035 +
13036 +#define IATTR_ADMIN    0x00000001
13037 +#define IATTR_WATCH    0x00000002
13038 +#define IATTR_HIDE     0x00000004
13039 +#define IATTR_FLAGS    0x00000007
13040 +
13041 +#define IATTR_BARRIER  0x00010000
13042 +#define IATTR_IXUNLINK 0x00020000
13043 +#define IATTR_IMMUTABLE 0x00040000
13044 +#define IATTR_COW      0x00080000
13045 +
13046 +
13047 +/* inode ioctls */
13048 +
13049 +#define FIOC_GETXFLG   _IOR('x', 5, long)
13050 +#define FIOC_SETXFLG   _IOW('x', 6, long)
13051 +
13052 +#endif /* _UAPI_VS_INODE_H */
13053 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/inode_cmd.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/inode_cmd.h
13054 --- linux-3.10.40/include/uapi/vserver/inode_cmd.h      1970-01-01 00:00:00.000000000 +0000
13055 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/inode_cmd.h    2013-08-22 20:30:00.000000000 +0000
13056 @@ -0,0 +1,26 @@
13057 +#ifndef _UAPI_VS_INODE_CMD_H
13058 +#define _UAPI_VS_INODE_CMD_H
13059 +
13060 +
13061 +/*  inode vserver commands */
13062 +
13063 +#define VCMD_get_iattr         VC_CMD(INODE, 1, 1)
13064 +#define VCMD_set_iattr         VC_CMD(INODE, 2, 1)
13065 +
13066 +#define VCMD_fget_iattr                VC_CMD(INODE, 3, 0)
13067 +#define VCMD_fset_iattr                VC_CMD(INODE, 4, 0)
13068 +
13069 +struct vcmd_ctx_iattr_v1 {
13070 +       const char __user *name;
13071 +       uint32_t tag;
13072 +       uint32_t flags;
13073 +       uint32_t mask;
13074 +};
13075 +
13076 +struct vcmd_ctx_fiattr_v0 {
13077 +       uint32_t tag;
13078 +       uint32_t flags;
13079 +       uint32_t mask;
13080 +};
13081 +
13082 +#endif /* _UAPI_VS_INODE_CMD_H */
13083 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/limit.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/limit.h
13084 --- linux-3.10.40/include/uapi/vserver/limit.h  1970-01-01 00:00:00.000000000 +0000
13085 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/limit.h        2013-08-22 20:30:00.000000000 +0000
13086 @@ -0,0 +1,14 @@
13087 +#ifndef _UAPI_VS_LIMIT_H
13088 +#define _UAPI_VS_LIMIT_H
13089 +
13090 +
13091 +#define VLIMIT_NSOCK   16
13092 +#define VLIMIT_OPENFD  17
13093 +#define VLIMIT_ANON    18
13094 +#define VLIMIT_SHMEM   19
13095 +#define VLIMIT_SEMARY  20
13096 +#define VLIMIT_NSEMS   21
13097 +#define VLIMIT_DENTRY  22
13098 +#define VLIMIT_MAPPED  23
13099 +
13100 +#endif /* _UAPI_VS_LIMIT_H */
13101 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/limit_cmd.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/limit_cmd.h
13102 --- linux-3.10.40/include/uapi/vserver/limit_cmd.h      1970-01-01 00:00:00.000000000 +0000
13103 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/limit_cmd.h    2013-08-22 20:30:00.000000000 +0000
13104 @@ -0,0 +1,40 @@
13105 +#ifndef _UAPI_VS_LIMIT_CMD_H
13106 +#define _UAPI_VS_LIMIT_CMD_H
13107 +
13108 +
13109 +/*  rlimit vserver commands */
13110 +
13111 +#define VCMD_get_rlimit                VC_CMD(RLIMIT, 1, 0)
13112 +#define VCMD_set_rlimit                VC_CMD(RLIMIT, 2, 0)
13113 +#define VCMD_get_rlimit_mask   VC_CMD(RLIMIT, 3, 0)
13114 +#define VCMD_reset_hits                VC_CMD(RLIMIT, 7, 0)
13115 +#define VCMD_reset_minmax      VC_CMD(RLIMIT, 9, 0)
13116 +
13117 +struct vcmd_ctx_rlimit_v0 {
13118 +       uint32_t id;
13119 +       uint64_t minimum;
13120 +       uint64_t softlimit;
13121 +       uint64_t maximum;
13122 +};
13123 +
13124 +struct vcmd_ctx_rlimit_mask_v0 {
13125 +       uint32_t minimum;
13126 +       uint32_t softlimit;
13127 +       uint32_t maximum;
13128 +};
13129 +
13130 +#define VCMD_rlimit_stat       VC_CMD(VSTAT, 1, 0)
13131 +
13132 +struct vcmd_rlimit_stat_v0 {
13133 +       uint32_t id;
13134 +       uint32_t hits;
13135 +       uint64_t value;
13136 +       uint64_t minimum;
13137 +       uint64_t maximum;
13138 +};
13139 +
13140 +#define CRLIM_UNSET            (0ULL)
13141 +#define CRLIM_INFINITY         (~0ULL)
13142 +#define CRLIM_KEEP             (~1ULL)
13143 +
13144 +#endif /* _UAPI_VS_LIMIT_CMD_H */
13145 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/monitor.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/monitor.h
13146 --- linux-3.10.40/include/uapi/vserver/monitor.h        1970-01-01 00:00:00.000000000 +0000
13147 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/monitor.h      2013-08-22 20:30:00.000000000 +0000
13148 @@ -0,0 +1,96 @@
13149 +#ifndef _UAPI_VS_MONITOR_H
13150 +#define _UAPI_VS_MONITOR_H
13151 +
13152 +#include <linux/types.h>
13153 +
13154 +
13155 +enum {
13156 +       VXM_UNUSED = 0,
13157 +
13158 +       VXM_SYNC = 0x10,
13159 +
13160 +       VXM_UPDATE = 0x20,
13161 +       VXM_UPDATE_1,
13162 +       VXM_UPDATE_2,
13163 +
13164 +       VXM_RQINFO_1 = 0x24,
13165 +       VXM_RQINFO_2,
13166 +
13167 +       VXM_ACTIVATE = 0x40,
13168 +       VXM_DEACTIVATE,
13169 +       VXM_IDLE,
13170 +
13171 +       VXM_HOLD = 0x44,
13172 +       VXM_UNHOLD,
13173 +
13174 +       VXM_MIGRATE = 0x48,
13175 +       VXM_RESCHED,
13176 +
13177 +       /* all other bits are flags */
13178 +       VXM_SCHED = 0x80,
13179 +};
13180 +
13181 +struct _vxm_update_1 {
13182 +       uint32_t tokens_max;
13183 +       uint32_t fill_rate;
13184 +       uint32_t interval;
13185 +};
13186 +
13187 +struct _vxm_update_2 {
13188 +       uint32_t tokens_min;
13189 +       uint32_t fill_rate;
13190 +       uint32_t interval;
13191 +};
13192 +
13193 +struct _vxm_rqinfo_1 {
13194 +       uint16_t running;
13195 +       uint16_t onhold;
13196 +       uint16_t iowait;
13197 +       uint16_t uintr;
13198 +       uint32_t idle_tokens;
13199 +};
13200 +
13201 +struct _vxm_rqinfo_2 {
13202 +       uint32_t norm_time;
13203 +       uint32_t idle_time;
13204 +       uint32_t idle_skip;
13205 +};
13206 +
13207 +struct _vxm_sched {
13208 +       uint32_t tokens;
13209 +       uint32_t norm_time;
13210 +       uint32_t idle_time;
13211 +};
13212 +
13213 +struct _vxm_task {
13214 +       uint16_t pid;
13215 +       uint16_t state;
13216 +};
13217 +
13218 +struct _vxm_event {
13219 +       uint32_t jif;
13220 +       union {
13221 +               uint32_t seq;
13222 +               uint32_t sec;
13223 +       };
13224 +       union {
13225 +               uint32_t tokens;
13226 +               uint32_t nsec;
13227 +               struct _vxm_task tsk;
13228 +       };
13229 +};
13230 +
13231 +struct _vx_mon_entry {
13232 +       uint16_t type;
13233 +       uint16_t xid;
13234 +       union {
13235 +               struct _vxm_event ev;
13236 +               struct _vxm_sched sd;
13237 +               struct _vxm_update_1 u1;
13238 +               struct _vxm_update_2 u2;
13239 +               struct _vxm_rqinfo_1 q1;
13240 +               struct _vxm_rqinfo_2 q2;
13241 +       };
13242 +};
13243 +
13244 +#endif /* _UAPI_VS_MONITOR_H */
13245 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/network.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/network.h
13246 --- linux-3.10.40/include/uapi/vserver/network.h        1970-01-01 00:00:00.000000000 +0000
13247 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/network.h      2013-08-22 20:30:00.000000000 +0000
13248 @@ -0,0 +1,76 @@
13249 +#ifndef _UAPI_VS_NETWORK_H
13250 +#define _UAPI_VS_NETWORK_H
13251 +
13252 +#include <linux/types.h>
13253 +
13254 +
13255 +#define MAX_N_CONTEXT  65535   /* Arbitrary limit */
13256 +
13257 +
13258 +/* network flags */
13259 +
13260 +#define NXF_INFO_PRIVATE       0x00000008
13261 +
13262 +#define NXF_SINGLE_IP          0x00000100
13263 +#define NXF_LBACK_REMAP                0x00000200
13264 +#define NXF_LBACK_ALLOW                0x00000400
13265 +
13266 +#define NXF_HIDE_NETIF         0x02000000
13267 +#define NXF_HIDE_LBACK         0x04000000
13268 +
13269 +#define NXF_STATE_SETUP                (1ULL << 32)
13270 +#define NXF_STATE_ADMIN                (1ULL << 34)
13271 +
13272 +#define NXF_SC_HELPER          (1ULL << 36)
13273 +#define NXF_PERSISTENT         (1ULL << 38)
13274 +
13275 +#define NXF_ONE_TIME           (0x0005ULL << 32)
13276 +
13277 +
13278 +#define        NXF_INIT_SET            (__nxf_init_set())
13279 +
13280 +static inline uint64_t __nxf_init_set(void) {
13281 +       return    NXF_STATE_ADMIN
13282 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13283 +               | NXF_LBACK_REMAP
13284 +               | NXF_HIDE_LBACK
13285 +#endif
13286 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13287 +               | NXF_SINGLE_IP
13288 +#endif
13289 +               | NXF_HIDE_NETIF;
13290 +}
13291 +
13292 +
13293 +/* network caps */
13294 +
13295 +#define NXC_TUN_CREATE         0x00000001
13296 +
13297 +#define NXC_RAW_ICMP           0x00000100
13298 +
13299 +#define NXC_MULTICAST          0x00001000
13300 +
13301 +
13302 +/* address types */
13303 +
13304 +#define NXA_TYPE_IPV4          0x0001
13305 +#define NXA_TYPE_IPV6          0x0002
13306 +
13307 +#define NXA_TYPE_NONE          0x0000
13308 +#define NXA_TYPE_ANY           0x00FF
13309 +
13310 +#define NXA_TYPE_ADDR          0x0010
13311 +#define NXA_TYPE_MASK          0x0020
13312 +#define NXA_TYPE_RANGE         0x0040
13313 +
13314 +#define NXA_MASK_ALL           (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13315 +
13316 +#define NXA_MOD_BCAST          0x0100
13317 +#define NXA_MOD_LBACK          0x0200
13318 +
13319 +#define NXA_LOOPBACK           0x1000
13320 +
13321 +#define NXA_MASK_BIND          (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13322 +#define NXA_MASK_SHOW          (NXA_MASK_ALL | NXA_LOOPBACK)
13323 +
13324 +#endif /* _UAPI_VS_NETWORK_H */
13325 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/network_cmd.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/network_cmd.h
13326 --- linux-3.10.40/include/uapi/vserver/network_cmd.h    1970-01-01 00:00:00.000000000 +0000
13327 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/network_cmd.h  2013-08-22 20:30:00.000000000 +0000
13328 @@ -0,0 +1,123 @@
13329 +#ifndef _UAPI_VS_NETWORK_CMD_H
13330 +#define _UAPI_VS_NETWORK_CMD_H
13331 +
13332 +
13333 +/* vinfo commands */
13334 +
13335 +#define VCMD_task_nid          VC_CMD(VINFO, 2, 0)
13336 +
13337 +
13338 +#define VCMD_nx_info           VC_CMD(VINFO, 6, 0)
13339 +
13340 +struct vcmd_nx_info_v0 {
13341 +       uint32_t nid;
13342 +       /* more to come */
13343 +};
13344 +
13345 +
13346 +#include <linux/in.h>
13347 +#include <linux/in6.h>
13348 +
13349 +#define VCMD_net_create_v0     VC_CMD(VNET, 1, 0)
13350 +#define VCMD_net_create                VC_CMD(VNET, 1, 1)
13351 +
13352 +struct  vcmd_net_create {
13353 +       uint64_t flagword;
13354 +};
13355 +
13356 +#define VCMD_net_migrate       VC_CMD(NETMIG, 1, 0)
13357 +
13358 +#define VCMD_net_add           VC_CMD(NETALT, 1, 0)
13359 +#define VCMD_net_remove                VC_CMD(NETALT, 2, 0)
13360 +
13361 +struct vcmd_net_addr_v0 {
13362 +       uint16_t type;
13363 +       uint16_t count;
13364 +       struct in_addr ip[4];
13365 +       struct in_addr mask[4];
13366 +};
13367 +
13368 +#define VCMD_net_add_ipv4_v1   VC_CMD(NETALT, 1, 1)
13369 +#define VCMD_net_rem_ipv4_v1   VC_CMD(NETALT, 2, 1)
13370 +
13371 +struct vcmd_net_addr_ipv4_v1 {
13372 +       uint16_t type;
13373 +       uint16_t flags;
13374 +       struct in_addr ip;
13375 +       struct in_addr mask;
13376 +};
13377 +
13378 +#define VCMD_net_add_ipv4      VC_CMD(NETALT, 1, 2)
13379 +#define VCMD_net_rem_ipv4      VC_CMD(NETALT, 2, 2)
13380 +
13381 +struct vcmd_net_addr_ipv4_v2 {
13382 +       uint16_t type;
13383 +       uint16_t flags;
13384 +       struct in_addr ip;
13385 +       struct in_addr ip2;
13386 +       struct in_addr mask;
13387 +};
13388 +
13389 +#define VCMD_net_add_ipv6      VC_CMD(NETALT, 3, 1)
13390 +#define VCMD_net_remove_ipv6   VC_CMD(NETALT, 4, 1)
13391 +
13392 +struct vcmd_net_addr_ipv6_v1 {
13393 +       uint16_t type;
13394 +       uint16_t flags;
13395 +       uint32_t prefix;
13396 +       struct in6_addr ip;
13397 +       struct in6_addr mask;
13398 +};
13399 +
13400 +#define VCMD_add_match_ipv4    VC_CMD(NETALT, 5, 0)
13401 +#define VCMD_get_match_ipv4    VC_CMD(NETALT, 6, 0)
13402 +
13403 +struct vcmd_match_ipv4_v0 {
13404 +       uint16_t type;
13405 +       uint16_t flags;
13406 +       uint16_t parent;
13407 +       uint16_t prefix;
13408 +       struct in_addr ip;
13409 +       struct in_addr ip2;
13410 +       struct in_addr mask;
13411 +};
13412 +
13413 +#define VCMD_add_match_ipv6    VC_CMD(NETALT, 7, 0)
13414 +#define VCMD_get_match_ipv6    VC_CMD(NETALT, 8, 0)
13415 +
13416 +struct vcmd_match_ipv6_v0 {
13417 +       uint16_t type;
13418 +       uint16_t flags;
13419 +       uint16_t parent;
13420 +       uint16_t prefix;
13421 +       struct in6_addr ip;
13422 +       struct in6_addr ip2;
13423 +       struct in6_addr mask;
13424 +};
13425 +
13426 +
13427 +
13428 +
13429 +/* flag commands */
13430 +
13431 +#define VCMD_get_nflags                VC_CMD(FLAGS, 5, 0)
13432 +#define VCMD_set_nflags                VC_CMD(FLAGS, 6, 0)
13433 +
13434 +struct vcmd_net_flags_v0 {
13435 +       uint64_t flagword;
13436 +       uint64_t mask;
13437 +};
13438 +
13439 +
13440 +
13441 +/* network caps commands */
13442 +
13443 +#define VCMD_get_ncaps         VC_CMD(FLAGS, 7, 0)
13444 +#define VCMD_set_ncaps         VC_CMD(FLAGS, 8, 0)
13445 +
13446 +struct vcmd_net_caps_v0 {
13447 +       uint64_t ncaps;
13448 +       uint64_t cmask;
13449 +};
13450 +
13451 +#endif /* _UAPI_VS_NETWORK_CMD_H */
13452 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/sched_cmd.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/sched_cmd.h
13453 --- linux-3.10.40/include/uapi/vserver/sched_cmd.h      1970-01-01 00:00:00.000000000 +0000
13454 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/sched_cmd.h    2013-08-22 20:30:00.000000000 +0000
13455 @@ -0,0 +1,13 @@
13456 +#ifndef _UAPI_VS_SCHED_CMD_H
13457 +#define _UAPI_VS_SCHED_CMD_H
13458 +
13459 +
13460 +struct vcmd_prio_bias {
13461 +       int32_t cpu_id;
13462 +       int32_t prio_bias;
13463 +};
13464 +
13465 +#define VCMD_set_prio_bias     VC_CMD(SCHED, 4, 0)
13466 +#define VCMD_get_prio_bias     VC_CMD(SCHED, 5, 0)
13467 +
13468 +#endif /* _UAPI_VS_SCHED_CMD_H */
13469 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/signal_cmd.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/signal_cmd.h
13470 --- linux-3.10.40/include/uapi/vserver/signal_cmd.h     1970-01-01 00:00:00.000000000 +0000
13471 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/signal_cmd.h   2013-08-22 20:30:00.000000000 +0000
13472 @@ -0,0 +1,31 @@
13473 +#ifndef _UAPI_VS_SIGNAL_CMD_H
13474 +#define _UAPI_VS_SIGNAL_CMD_H
13475 +
13476 +
13477 +/*  signalling vserver commands */
13478 +
13479 +#define VCMD_ctx_kill          VC_CMD(PROCTRL, 1, 0)
13480 +#define VCMD_wait_exit         VC_CMD(EVENT, 99, 0)
13481 +
13482 +struct vcmd_ctx_kill_v0 {
13483 +       int32_t pid;
13484 +       int32_t sig;
13485 +};
13486 +
13487 +struct vcmd_wait_exit_v0 {
13488 +       int32_t reboot_cmd;
13489 +       int32_t exit_code;
13490 +};
13491 +
13492 +
13493 +/*  process alteration commands */
13494 +
13495 +#define VCMD_get_pflags                VC_CMD(PROCALT, 5, 0)
13496 +#define VCMD_set_pflags                VC_CMD(PROCALT, 6, 0)
13497 +
13498 +struct vcmd_pflags_v0 {
13499 +       uint32_t flagword;
13500 +       uint32_t mask;
13501 +};
13502 +
13503 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
13504 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/space_cmd.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/space_cmd.h
13505 --- linux-3.10.40/include/uapi/vserver/space_cmd.h      1970-01-01 00:00:00.000000000 +0000
13506 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/space_cmd.h    2013-08-22 20:30:00.000000000 +0000
13507 @@ -0,0 +1,28 @@
13508 +#ifndef _UAPI_VS_SPACE_CMD_H
13509 +#define _UAPI_VS_SPACE_CMD_H
13510 +
13511 +
13512 +#define VCMD_enter_space_v0    VC_CMD(PROCALT, 1, 0)
13513 +#define VCMD_enter_space_v1    VC_CMD(PROCALT, 1, 1)
13514 +#define VCMD_enter_space       VC_CMD(PROCALT, 1, 2)
13515 +
13516 +#define VCMD_set_space_v0      VC_CMD(PROCALT, 3, 0)
13517 +#define VCMD_set_space_v1      VC_CMD(PROCALT, 3, 1)
13518 +#define VCMD_set_space         VC_CMD(PROCALT, 3, 2)
13519 +
13520 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13521 +
13522 +#define VCMD_get_space_mask    VC_CMD(VSPACE, 0, 1)
13523 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13524 +
13525 +
13526 +struct vcmd_space_mask_v1 {
13527 +       uint64_t mask;
13528 +};
13529 +
13530 +struct vcmd_space_mask_v2 {
13531 +       uint64_t mask;
13532 +       uint32_t index;
13533 +};
13534 +
13535 +#endif /* _UAPI_VS_SPACE_CMD_H */
13536 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/switch.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/switch.h
13537 --- linux-3.10.40/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
13538 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/switch.h       2013-08-22 20:30:00.000000000 +0000
13539 @@ -0,0 +1,90 @@
13540 +#ifndef _UAPI_VS_SWITCH_H
13541 +#define _UAPI_VS_SWITCH_H
13542 +
13543 +#include <linux/types.h>
13544 +
13545 +
13546 +#define VC_CATEGORY(c)         (((c) >> 24) & 0x3F)
13547 +#define VC_COMMAND(c)          (((c) >> 16) & 0xFF)
13548 +#define VC_VERSION(c)          ((c) & 0xFFF)
13549 +
13550 +#define VC_CMD(c, i, v)                ((((VC_CAT_ ## c) & 0x3F) << 24) \
13551 +                               | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13552 +
13553 +/*
13554 +
13555 +  Syscall Matrix V2.8
13556 +
13557 +        |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13558 +        |STATS  |DESTROY|ALTER  |CHANGE |LIMIT  |TEST   | |       |       |
13559 +        |INFO   |SETUP  |       |MOVE   |       |       | |       |       |
13560 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13561 +  SYSTEM |VERSION|VSETUP |VHOST  |       |       |       | |DEVICE |       |
13562 +  HOST   |     00|     01|     02|     03|     04|     05| |     06|     07|
13563 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13564 +  CPU    |       |VPROC  |PROCALT|PROCMIG|PROCTRL|       | |SCHED. |       |
13565 +  PROCESS|     08|     09|     10|     11|     12|     13| |     14|     15|
13566 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13567 +  MEMORY |       |       |       |       |MEMCTRL|       | |SWAP   |       |
13568 +        |     16|     17|     18|     19|     20|     21| |     22|     23|
13569 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13570 +  NETWORK|       |VNET   |NETALT |NETMIG |NETCTL |       | |SERIAL |       |
13571 +        |     24|     25|     26|     27|     28|     29| |     30|     31|
13572 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13573 +  DISK   |       |       |       |TAGMIG |DLIMIT |       | |INODE  |       |
13574 +  VFS    |     32|     33|     34|     35|     36|     37| |     38|     39|
13575 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13576 +  OTHER  |VSTAT  |       |       |       |       |       | |VINFO  |       |
13577 +        |     40|     41|     42|     43|     44|     45| |     46|     47|
13578 +  =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13579 +  SPECIAL|EVENT  |       |       |       |FLAGS  |       | |VSPACE |       |
13580 +        |     48|     49|     50|     51|     52|     53| |     54|     55|
13581 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13582 +  SPECIAL|DEBUG  |       |       |       |RLIMIT |SYSCALL| |       |COMPAT |
13583 +        |     56|     57|     58|     59|     60|TEST 61| |     62|     63|
13584 +  -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13585 +
13586 +*/
13587 +
13588 +#define VC_CAT_VERSION         0
13589 +
13590 +#define VC_CAT_VSETUP          1
13591 +#define VC_CAT_VHOST           2
13592 +
13593 +#define VC_CAT_DEVICE          6
13594 +
13595 +#define VC_CAT_VPROC           9
13596 +#define VC_CAT_PROCALT         10
13597 +#define VC_CAT_PROCMIG         11
13598 +#define VC_CAT_PROCTRL         12
13599 +
13600 +#define VC_CAT_SCHED           14
13601 +#define VC_CAT_MEMCTRL         20
13602 +
13603 +#define VC_CAT_VNET            25
13604 +#define VC_CAT_NETALT          26
13605 +#define VC_CAT_NETMIG          27
13606 +#define VC_CAT_NETCTRL         28
13607 +
13608 +#define VC_CAT_TAGMIG          35
13609 +#define VC_CAT_DLIMIT          36
13610 +#define VC_CAT_INODE           38
13611 +
13612 +#define VC_CAT_VSTAT           40
13613 +#define VC_CAT_VINFO           46
13614 +#define VC_CAT_EVENT           48
13615 +
13616 +#define VC_CAT_FLAGS           52
13617 +#define VC_CAT_VSPACE          54
13618 +#define VC_CAT_DEBUG           56
13619 +#define VC_CAT_RLIMIT          60
13620 +
13621 +#define VC_CAT_SYSTEST         61
13622 +#define VC_CAT_COMPAT          63
13623 +
13624 +/*  query version */
13625 +
13626 +#define VCMD_get_version       VC_CMD(VERSION, 0, 0)
13627 +#define VCMD_get_vci           VC_CMD(VERSION, 1, 0)
13628 +
13629 +#endif /* _UAPI_VS_SWITCH_H */
13630 diff -NurpP --minimal linux-3.10.40/include/uapi/vserver/tag_cmd.h linux-3.10.40-vs2.3.6.8/include/uapi/vserver/tag_cmd.h
13631 --- linux-3.10.40/include/uapi/vserver/tag_cmd.h        1970-01-01 00:00:00.000000000 +0000
13632 +++ linux-3.10.40-vs2.3.6.8/include/uapi/vserver/tag_cmd.h      2013-08-22 20:30:00.000000000 +0000
13633 @@ -0,0 +1,14 @@
13634 +#ifndef _UAPI_VS_TAG_CMD_H
13635 +#define _UAPI_VS_TAG_CMD_H
13636 +
13637 +
13638 +/* vinfo commands */
13639 +
13640 +#define VCMD_task_tag          VC_CMD(VINFO, 3, 0)
13641 +
13642 +
13643 +/* context commands */
13644 +
13645 +#define VCMD_tag_migrate       VC_CMD(TAGMIG, 1, 0)
13646 +
13647 +#endif /* _UAPI_VS_TAG_CMD_H */
13648 diff -NurpP --minimal linux-3.10.40/init/Kconfig linux-3.10.40-vs2.3.6.8/init/Kconfig
13649 --- linux-3.10.40/init/Kconfig  2014-05-20 04:09:41.000000000 +0000
13650 +++ linux-3.10.40-vs2.3.6.8/init/Kconfig        2014-04-22 03:48:11.000000000 +0000
13651 @@ -805,6 +805,7 @@ config NUMA_BALANCING
13652  menuconfig CGROUPS
13653         boolean "Control Group support"
13654         depends on EVENTFD
13655 +       default y
13656         help
13657           This option adds support for grouping sets of processes together, for
13658           use with process control subsystems such as Cpusets, CFS, memory
13659 @@ -1067,6 +1068,7 @@ config IPC_NS
13660  config USER_NS
13661         bool "User namespace"
13662         depends on UIDGID_CONVERTED
13663 +       depends on VSERVER_DISABLED
13664         select UIDGID_STRICT_TYPE_CHECKS
13665  
13666         default n
13667 diff -NurpP --minimal linux-3.10.40/init/main.c linux-3.10.40-vs2.3.6.8/init/main.c
13668 --- linux-3.10.40/init/main.c   2014-05-20 04:09:41.000000000 +0000
13669 +++ linux-3.10.40-vs2.3.6.8/init/main.c 2013-11-13 17:19:37.000000000 +0000
13670 @@ -75,6 +75,7 @@
13671  #include <linux/blkdev.h>
13672  #include <linux/elevator.h>
13673  #include <linux/random.h>
13674 +#include <linux/vserver/percpu.h>
13675  
13676  #include <asm/io.h>
13677  #include <asm/bugs.h>
13678 diff -NurpP --minimal linux-3.10.40/ipc/mqueue.c linux-3.10.40-vs2.3.6.8/ipc/mqueue.c
13679 --- linux-3.10.40/ipc/mqueue.c  2014-05-20 04:09:41.000000000 +0000
13680 +++ linux-3.10.40-vs2.3.6.8/ipc/mqueue.c        2014-03-12 13:18:33.000000000 +0000
13681 @@ -35,6 +35,8 @@
13682  #include <linux/ipc_namespace.h>
13683  #include <linux/user_namespace.h>
13684  #include <linux/slab.h>
13685 +#include <linux/vs_context.h>
13686 +#include <linux/vs_limit.h>
13687  
13688  #include <net/sock.h>
13689  #include "util.h"
13690 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13691         struct pid* notify_owner;
13692         struct user_namespace *notify_user_ns;
13693         struct user_struct *user;       /* user who created, for accounting */
13694 +       struct vx_info *vxi;
13695         struct sock *notify_sock;
13696         struct sk_buff *notify_cookie;
13697  
13698 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13699         if (S_ISREG(mode)) {
13700                 struct mqueue_inode_info *info;
13701                 unsigned long mq_bytes, mq_treesize;
13702 +               struct vx_info *vxi = current_vx_info();
13703  
13704                 inode->i_fop = &mqueue_file_operations;
13705                 inode->i_size = FILENT_SIZE;
13706 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13707                 info->notify_user_ns = NULL;
13708                 info->qsize = 0;
13709                 info->user = NULL;      /* set when all is ok */
13710 +               info->vxi = NULL;
13711                 info->msg_tree = RB_ROOT;
13712                 info->node_cache = NULL;
13713                 memset(&info->attr, 0, sizeof(info->attr));
13714 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13715  
13716                 spin_lock(&mq_lock);
13717                 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13718 -                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13719 +                   u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13720 +                   !vx_ipcmsg_avail(vxi, mq_bytes)) {
13721                         spin_unlock(&mq_lock);
13722                         /* mqueue_evict_inode() releases info->messages */
13723                         ret = -EMFILE;
13724                         goto out_inode;
13725                 }
13726                 u->mq_bytes += mq_bytes;
13727 +               vx_ipcmsg_add(vxi, u, mq_bytes);
13728                 spin_unlock(&mq_lock);
13729  
13730                 /* all is ok */
13731                 info->user = get_uid(u);
13732 +               info->vxi = get_vx_info(vxi);
13733         } else if (S_ISDIR(mode)) {
13734                 inc_nlink(inode);
13735                 /* Some things misbehave if size == 0 on a directory */
13736 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13737  
13738         user = info->user;
13739         if (user) {
13740 +               struct vx_info *vxi = info->vxi;
13741 +
13742                 spin_lock(&mq_lock);
13743                 user->mq_bytes -= mq_bytes;
13744 +               vx_ipcmsg_sub(vxi, user, mq_bytes);
13745                 /*
13746                  * get_ns_from_inode() ensures that the
13747                  * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13748 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13749                 if (ipc_ns)
13750                         ipc_ns->mq_queues_count--;
13751                 spin_unlock(&mq_lock);
13752 +               put_vx_info(vxi);
13753                 free_uid(user);
13754         }
13755         if (ipc_ns)
13756 diff -NurpP --minimal linux-3.10.40/ipc/msg.c linux-3.10.40-vs2.3.6.8/ipc/msg.c
13757 --- linux-3.10.40/ipc/msg.c     2014-05-20 04:09:41.000000000 +0000
13758 +++ linux-3.10.40-vs2.3.6.8/ipc/msg.c   2014-04-22 03:48:11.000000000 +0000
13759 @@ -37,6 +37,7 @@
13760  #include <linux/rwsem.h>
13761  #include <linux/nsproxy.h>
13762  #include <linux/ipc_namespace.h>
13763 +#include <linux/vs_base.h>
13764  
13765  #include <asm/current.h>
13766  #include <asm/uaccess.h>
13767 @@ -194,6 +195,7 @@ static int newque(struct ipc_namespace *
13768  
13769         msq->q_perm.mode = msgflg & S_IRWXUGO;
13770         msq->q_perm.key = key;
13771 +       msq->q_perm.xid = vx_current_xid();
13772  
13773         msq->q_perm.security = NULL;
13774         retval = security_msg_queue_alloc(msq);
13775 diff -NurpP --minimal linux-3.10.40/ipc/sem.c linux-3.10.40-vs2.3.6.8/ipc/sem.c
13776 --- linux-3.10.40/ipc/sem.c     2014-05-20 04:09:41.000000000 +0000
13777 +++ linux-3.10.40-vs2.3.6.8/ipc/sem.c   2013-12-23 17:42:40.000000000 +0000
13778 @@ -86,6 +86,8 @@
13779  #include <linux/rwsem.h>
13780  #include <linux/nsproxy.h>
13781  #include <linux/ipc_namespace.h>
13782 +#include <linux/vs_base.h>
13783 +#include <linux/vs_limit.h>
13784  
13785  #include <asm/uaccess.h>
13786  #include "util.h"
13787 @@ -500,6 +502,7 @@ static int newary(struct ipc_namespace *
13788  
13789         sma->sem_perm.mode = (semflg & S_IRWXUGO);
13790         sma->sem_perm.key = key;
13791 +       sma->sem_perm.xid = vx_current_xid();
13792  
13793         sma->sem_perm.security = NULL;
13794         retval = security_sem_alloc(sma);
13795 @@ -514,6 +517,9 @@ static int newary(struct ipc_namespace *
13796                 return id;
13797         }
13798         ns->used_sems += nsems;
13799 +       /* FIXME: obsoleted? */
13800 +       vx_semary_inc(sma);
13801 +       vx_nsems_add(sma, nsems);
13802  
13803         sma->sem_base = (struct sem *) &sma[1];
13804  
13805 @@ -1103,6 +1109,9 @@ static void freeary(struct ipc_namespace
13806  
13807         wake_up_sem_queue_do(&tasks);
13808         ns->used_sems -= sma->sem_nsems;
13809 +       /* FIXME: obsoleted? */
13810 +       vx_nsems_sub(sma, sma->sem_nsems);
13811 +       vx_semary_dec(sma);
13812         ipc_rcu_putref(sma, sem_rcu_free);
13813  }
13814  
13815 diff -NurpP --minimal linux-3.10.40/ipc/shm.c linux-3.10.40-vs2.3.6.8/ipc/shm.c
13816 --- linux-3.10.40/ipc/shm.c     2014-05-20 04:09:41.000000000 +0000
13817 +++ linux-3.10.40-vs2.3.6.8/ipc/shm.c   2013-11-30 07:55:52.000000000 +0000
13818 @@ -42,6 +42,8 @@
13819  #include <linux/nsproxy.h>
13820  #include <linux/mount.h>
13821  #include <linux/ipc_namespace.h>
13822 +#include <linux/vs_context.h>
13823 +#include <linux/vs_limit.h>
13824  
13825  #include <asm/uaccess.h>
13826  
13827 @@ -209,10 +211,14 @@ static void shm_open(struct vm_area_stru
13828  static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13829  {
13830         struct file *shm_file;
13831 +       struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13832 +       int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13833  
13834         shm_file = shp->shm_file;
13835         shp->shm_file = NULL;
13836 -       ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13837 +       vx_ipcshm_sub(vxi, shp, numpages);
13838 +       ns->shm_tot -= numpages;
13839 +
13840         shm_rmid(ns, shp);
13841         shm_unlock(shp);
13842         if (!is_file_hugepages(shm_file))
13843 @@ -220,6 +226,7 @@ static void shm_destroy(struct ipc_names
13844         else if (shp->mlock_user)
13845                 user_shm_unlock(file_inode(shm_file)->i_size, shp->mlock_user);
13846         fput(shm_file);
13847 +       put_vx_info(vxi);
13848         ipc_rcu_putref(shp, shm_rcu_free);
13849  }
13850  
13851 @@ -497,11 +504,15 @@ static int newseg(struct ipc_namespace *
13852         if (ns->shm_tot + numpages > ns->shm_ctlall)
13853                 return -ENOSPC;
13854  
13855 +       if (!vx_ipcshm_avail(current_vx_info(), numpages))
13856 +               return -ENOSPC;
13857 +
13858         shp = ipc_rcu_alloc(sizeof(*shp));
13859         if (!shp)
13860                 return -ENOMEM;
13861  
13862         shp->shm_perm.key = key;
13863 +       shp->shm_perm.xid = vx_current_xid();
13864         shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13865         shp->mlock_user = NULL;
13866  
13867 @@ -570,6 +581,7 @@ static int newseg(struct ipc_namespace *
13868  
13869         ipc_unlock_object(&shp->shm_perm);
13870         rcu_read_unlock();
13871 +       vx_ipcshm_add(current_vx_info(), key, numpages);
13872         return error;
13873  
13874  no_id:
13875 diff -NurpP --minimal linux-3.10.40/kernel/Makefile linux-3.10.40-vs2.3.6.8/kernel/Makefile
13876 --- linux-3.10.40/kernel/Makefile       2013-07-14 17:01:34.000000000 +0000
13877 +++ linux-3.10.40-vs2.3.6.8/kernel/Makefile     2013-08-22 21:18:32.000000000 +0000
13878 @@ -25,6 +25,7 @@ endif
13879  obj-y += sched/
13880  obj-y += power/
13881  obj-y += cpu/
13882 +obj-y += vserver/
13883  
13884  obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13885  obj-$(CONFIG_FREEZER) += freezer.o
13886 diff -NurpP --minimal linux-3.10.40/kernel/auditsc.c linux-3.10.40-vs2.3.6.8/kernel/auditsc.c
13887 --- linux-3.10.40/kernel/auditsc.c      2014-05-20 04:09:41.000000000 +0000
13888 +++ linux-3.10.40-vs2.3.6.8/kernel/auditsc.c    2013-12-23 17:42:40.000000000 +0000
13889 @@ -1982,7 +1982,7 @@ int audit_set_loginuid(kuid_t loginuid)
13890         if (audit_loginuid_set(task))
13891                 return -EPERM;
13892  #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13893 -       if (!capable(CAP_AUDIT_CONTROL))
13894 +       if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13895                 return -EPERM;
13896  #endif  /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13897  
13898 diff -NurpP --minimal linux-3.10.40/kernel/capability.c linux-3.10.40-vs2.3.6.8/kernel/capability.c
13899 --- linux-3.10.40/kernel/capability.c   2013-05-31 13:45:29.000000000 +0000
13900 +++ linux-3.10.40-vs2.3.6.8/kernel/capability.c 2013-08-22 20:30:00.000000000 +0000
13901 @@ -15,6 +15,7 @@
13902  #include <linux/syscalls.h>
13903  #include <linux/pid_namespace.h>
13904  #include <linux/user_namespace.h>
13905 +#include <linux/vs_context.h>
13906  #include <asm/uaccess.h>
13907  
13908  /*
13909 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13910         return 0;
13911  }
13912  
13913 +
13914  /*
13915   * The only thing that can change the capabilities of the current
13916   * process is the current process. As such, we can't be in this code
13917 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13918         return (ret == 0);
13919  }
13920  
13921 +#include <linux/vserver/base.h>
13922 +
13923  /**
13924   * has_capability_noaudit - Does a task have a capability (unaudited) in the
13925   * initial user ns
13926 diff -NurpP --minimal linux-3.10.40/kernel/compat.c linux-3.10.40-vs2.3.6.8/kernel/compat.c
13927 --- linux-3.10.40/kernel/compat.c       2013-07-14 17:01:34.000000000 +0000
13928 +++ linux-3.10.40-vs2.3.6.8/kernel/compat.c     2013-08-22 20:30:00.000000000 +0000
13929 @@ -27,6 +27,7 @@
13930  #include <linux/times.h>
13931  #include <linux/ptrace.h>
13932  #include <linux/gfp.h>
13933 +#include <linux/vs_time.h>
13934  
13935  #include <asm/uaccess.h>
13936  
13937 @@ -1040,7 +1041,7 @@ asmlinkage long compat_sys_stime(compat_
13938         if (err)
13939                 return err;
13940  
13941 -       do_settimeofday(&tv);
13942 +       vx_settimeofday(&tv);
13943         return 0;
13944  }
13945  
13946 diff -NurpP --minimal linux-3.10.40/kernel/cred.c linux-3.10.40-vs2.3.6.8/kernel/cred.c
13947 --- linux-3.10.40/kernel/cred.c 2013-02-19 13:58:56.000000000 +0000
13948 +++ linux-3.10.40-vs2.3.6.8/kernel/cred.c       2013-08-22 20:30:00.000000000 +0000
13949 @@ -56,31 +56,6 @@ struct cred init_cred = {
13950         .group_info             = &init_groups,
13951  };
13952  
13953 -static inline void set_cred_subscribers(struct cred *cred, int n)
13954 -{
13955 -#ifdef CONFIG_DEBUG_CREDENTIALS
13956 -       atomic_set(&cred->subscribers, n);
13957 -#endif
13958 -}
13959 -
13960 -static inline int read_cred_subscribers(const struct cred *cred)
13961 -{
13962 -#ifdef CONFIG_DEBUG_CREDENTIALS
13963 -       return atomic_read(&cred->subscribers);
13964 -#else
13965 -       return 0;
13966 -#endif
13967 -}
13968 -
13969 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
13970 -{
13971 -#ifdef CONFIG_DEBUG_CREDENTIALS
13972 -       struct cred *cred = (struct cred *) _cred;
13973 -
13974 -       atomic_add(n, &cred->subscribers);
13975 -#endif
13976 -}
13977 -
13978  /*
13979   * The RCU callback to actually dispose of a set of credentials
13980   */
13981 @@ -232,21 +207,16 @@ error:
13982   *
13983   * Call commit_creds() or abort_creds() to clean up.
13984   */
13985 -struct cred *prepare_creds(void)
13986 +struct cred *__prepare_creds(const struct cred *old)
13987  {
13988 -       struct task_struct *task = current;
13989 -       const struct cred *old;
13990         struct cred *new;
13991  
13992 -       validate_process_creds();
13993 -
13994         new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13995         if (!new)
13996                 return NULL;
13997  
13998         kdebug("prepare_creds() alloc %p", new);
13999  
14000 -       old = task->cred;
14001         memcpy(new, old, sizeof(struct cred));
14002  
14003         atomic_set(&new->usage, 1);
14004 @@ -275,6 +245,13 @@ error:
14005         abort_creds(new);
14006         return NULL;
14007  }
14008 +
14009 +struct cred *prepare_creds(void)
14010 +{
14011 +       validate_process_creds();
14012 +
14013 +       return __prepare_creds(current->cred);
14014 +}
14015  EXPORT_SYMBOL(prepare_creds);
14016  
14017  /*
14018 diff -NurpP --minimal linux-3.10.40/kernel/exit.c linux-3.10.40-vs2.3.6.8/kernel/exit.c
14019 --- linux-3.10.40/kernel/exit.c 2014-05-20 04:09:41.000000000 +0000
14020 +++ linux-3.10.40-vs2.3.6.8/kernel/exit.c       2014-05-20 04:31:56.000000000 +0000
14021 @@ -48,6 +48,10 @@
14022  #include <linux/fs_struct.h>
14023  #include <linux/init_task.h>
14024  #include <linux/perf_event.h>
14025 +#include <linux/vs_limit.h>
14026 +#include <linux/vs_context.h>
14027 +#include <linux/vs_network.h>
14028 +#include <linux/vs_pid.h>
14029  #include <trace/events/sched.h>
14030  #include <linux/hw_breakpoint.h>
14031  #include <linux/oom.h>
14032 @@ -514,15 +518,25 @@ static struct task_struct *find_new_reap
14033         __acquires(&tasklist_lock)
14034  {
14035         struct pid_namespace *pid_ns = task_active_pid_ns(father);
14036 -       struct task_struct *thread;
14037 +       struct vx_info *vxi = task_get_vx_info(father);
14038 +       struct task_struct *thread = father;
14039 +       struct task_struct *reaper;
14040  
14041 -       thread = father;
14042         while_each_thread(father, thread) {
14043                 if (thread->flags & PF_EXITING)
14044                         continue;
14045                 if (unlikely(pid_ns->child_reaper == father))
14046                         pid_ns->child_reaper = thread;
14047 -               return thread;
14048 +               reaper = thread;
14049 +               goto out_put;
14050 +       }
14051 +
14052 +       reaper = pid_ns->child_reaper;
14053 +       if (vxi) {
14054 +               BUG_ON(!vxi->vx_reaper);
14055 +               if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14056 +                   vxi->vx_reaper != father)
14057 +                       reaper = vxi->vx_reaper;
14058         }
14059  
14060         if (unlikely(pid_ns->child_reaper == father)) {
14061 @@ -560,7 +574,9 @@ static struct task_struct *find_new_reap
14062                 }
14063         }
14064  
14065 -       return pid_ns->child_reaper;
14066 +out_put:
14067 +       put_vx_info(vxi);
14068 +       return reaper;
14069  }
14070  
14071  /*
14072 @@ -618,10 +634,15 @@ static void forget_original_parent(struc
14073         list_for_each_entry_safe(p, n, &father->children, sibling) {
14074                 struct task_struct *t = p;
14075                 do {
14076 -                       t->real_parent = reaper;
14077 +                       struct task_struct *new_parent = reaper;
14078 +
14079 +                       if (unlikely(p == reaper))
14080 +                               new_parent = task_active_pid_ns(p)->child_reaper;
14081 +
14082 +                       t->real_parent = new_parent;
14083                         if (t->parent == father) {
14084                                 BUG_ON(t->ptrace);
14085 -                               t->parent = t->real_parent;
14086 +                               t->parent = new_parent;
14087                         }
14088                         if (t->pdeath_signal)
14089                                 group_send_sig_info(t->pdeath_signal,
14090 @@ -826,6 +847,9 @@ void do_exit(long code)
14091          */
14092         ptrace_put_breakpoints(tsk);
14093  
14094 +       /* needs to stay before exit_notify() */
14095 +       exit_vx_info_early(tsk, code);
14096 +
14097         exit_notify(tsk, group_dead);
14098  #ifdef CONFIG_NUMA
14099         task_lock(tsk);
14100 @@ -879,10 +903,15 @@ void do_exit(long code)
14101         smp_mb();
14102         raw_spin_unlock_wait(&tsk->pi_lock);
14103  
14104 +       /* needs to stay after exit_notify() */
14105 +       exit_vx_info(tsk, code);
14106 +       exit_nx_info(tsk);
14107 +
14108         /* causes final put_task_struct in finish_task_switch(). */
14109         tsk->state = TASK_DEAD;
14110         tsk->flags |= PF_NOFREEZE;      /* tell freezer to ignore us */
14111         schedule();
14112 +       printk("bad task: %p [%lx]\n", current, current->state);
14113         BUG();
14114         /* Avoid "noreturn function does return".  */
14115         for (;;)
14116 diff -NurpP --minimal linux-3.10.40/kernel/fork.c linux-3.10.40-vs2.3.6.8/kernel/fork.c
14117 --- linux-3.10.40/kernel/fork.c 2014-05-20 04:09:41.000000000 +0000
14118 +++ linux-3.10.40-vs2.3.6.8/kernel/fork.c       2014-01-22 19:00:34.000000000 +0000
14119 @@ -71,6 +71,9 @@
14120  #include <linux/signalfd.h>
14121  #include <linux/uprobes.h>
14122  #include <linux/aio.h>
14123 +#include <linux/vs_context.h>
14124 +#include <linux/vs_network.h>
14125 +#include <linux/vs_limit.h>
14126  
14127  #include <asm/pgtable.h>
14128  #include <asm/pgalloc.h>
14129 @@ -211,6 +214,8 @@ void free_task(struct task_struct *tsk)
14130         arch_release_thread_info(tsk->stack);
14131         free_thread_info(tsk->stack);
14132         rt_mutex_debug_task_free(tsk);
14133 +       clr_vx_info(&tsk->vx_info);
14134 +       clr_nx_info(&tsk->nx_info);
14135         ftrace_graph_exit_task(tsk);
14136         put_seccomp_filter(tsk);
14137         arch_release_task_struct(tsk);
14138 @@ -549,6 +554,7 @@ static struct mm_struct *mm_init(struct
14139         if (likely(!mm_alloc_pgd(mm))) {
14140                 mm->def_flags = 0;
14141                 mmu_notifier_mm_init(mm);
14142 +               set_vx_info(&mm->mm_vx_info, p->vx_info);
14143                 return mm;
14144         }
14145  
14146 @@ -601,6 +607,7 @@ void __mmdrop(struct mm_struct *mm)
14147         destroy_context(mm);
14148         mmu_notifier_mm_destroy(mm);
14149         check_mm(mm);
14150 +       clr_vx_info(&mm->mm_vx_info);
14151         free_mm(mm);
14152  }
14153  EXPORT_SYMBOL_GPL(__mmdrop);
14154 @@ -820,6 +827,7 @@ struct mm_struct *dup_mm(struct task_str
14155                 goto fail_nomem;
14156  
14157         memcpy(mm, oldmm, sizeof(*mm));
14158 +       mm->mm_vx_info = NULL;
14159         mm_init_cpumask(mm);
14160  
14161  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14162 @@ -861,6 +869,7 @@ fail_nocontext:
14163          * If init_new_context() failed, we cannot use mmput() to free the mm
14164          * because it calls destroy_context()
14165          */
14166 +       clr_vx_info(&mm->mm_vx_info);
14167         mm_free_pgd(mm);
14168         free_mm(mm);
14169         return NULL;
14170 @@ -1139,6 +1148,8 @@ static struct task_struct *copy_process(
14171  {
14172         int retval;
14173         struct task_struct *p;
14174 +       struct vx_info *vxi;
14175 +       struct nx_info *nxi;
14176  
14177         if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14178                 return ERR_PTR(-EINVAL);
14179 @@ -1198,7 +1209,12 @@ static struct task_struct *copy_process(
14180         DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14181         DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14182  #endif
14183 +       init_vx_info(&p->vx_info, current_vx_info());
14184 +       init_nx_info(&p->nx_info, current_nx_info());
14185 +
14186         retval = -EAGAIN;
14187 +       if (!vx_nproc_avail(1))
14188 +               goto bad_fork_free;
14189         if (atomic_read(&p->real_cred->user->processes) >=
14190                         task_rlimit(p, RLIMIT_NPROC)) {
14191                 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14192 @@ -1479,6 +1495,18 @@ static struct task_struct *copy_process(
14193  
14194         total_forks++;
14195         spin_unlock(&current->sighand->siglock);
14196 +
14197 +       /* p is copy of current */
14198 +       vxi = p->vx_info;
14199 +       if (vxi) {
14200 +               claim_vx_info(vxi, p);
14201 +               atomic_inc(&vxi->cvirt.nr_threads);
14202 +               atomic_inc(&vxi->cvirt.total_forks);
14203 +               vx_nproc_inc(p);
14204 +       }
14205 +       nxi = p->nx_info;
14206 +       if (nxi)
14207 +               claim_nx_info(nxi, p);
14208         write_unlock_irq(&tasklist_lock);
14209         proc_fork_connector(p);
14210         cgroup_post_fork(p);
14211 diff -NurpP --minimal linux-3.10.40/kernel/kthread.c linux-3.10.40-vs2.3.6.8/kernel/kthread.c
14212 --- linux-3.10.40/kernel/kthread.c      2013-07-14 17:01:35.000000000 +0000
14213 +++ linux-3.10.40-vs2.3.6.8/kernel/kthread.c    2013-08-22 21:14:28.000000000 +0000
14214 @@ -18,6 +18,7 @@
14215  #include <linux/freezer.h>
14216  #include <linux/ptrace.h>
14217  #include <linux/uaccess.h>
14218 +#include <linux/vs_pid.h>
14219  #include <trace/events/sched.h>
14220  
14221  static DEFINE_SPINLOCK(kthread_create_lock);
14222 diff -NurpP --minimal linux-3.10.40/kernel/nsproxy.c linux-3.10.40-vs2.3.6.8/kernel/nsproxy.c
14223 --- linux-3.10.40/kernel/nsproxy.c      2013-07-14 17:01:35.000000000 +0000
14224 +++ linux-3.10.40-vs2.3.6.8/kernel/nsproxy.c    2013-08-22 21:09:55.000000000 +0000
14225 @@ -20,11 +20,14 @@
14226  #include <linux/mnt_namespace.h>
14227  #include <linux/utsname.h>
14228  #include <linux/pid_namespace.h>
14229 +#include <linux/vserver/global.h>
14230 +#include <linux/vserver/debug.h>
14231  #include <net/net_namespace.h>
14232  #include <linux/ipc_namespace.h>
14233  #include <linux/proc_ns.h>
14234  #include <linux/file.h>
14235  #include <linux/syscalls.h>
14236 +#include "../fs/mount.h"
14237  
14238  static struct kmem_cache *nsproxy_cachep;
14239  
14240 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14241         struct nsproxy *nsproxy;
14242  
14243         nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14244 -       if (nsproxy)
14245 +       if (nsproxy) {
14246                 atomic_set(&nsproxy->count, 1);
14247 +               atomic_inc(&vs_global_nsproxy);
14248 +       }
14249 +       vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14250         return nsproxy;
14251  }
14252  
14253 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
14254   * Return the newly created nsproxy.  Do not attach this to the task,
14255   * leave it to the caller to do proper locking and attach it to task.
14256   */
14257 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14258 -       struct task_struct *tsk, struct user_namespace *user_ns,
14259 -       struct fs_struct *new_fs)
14260 +static struct nsproxy *unshare_namespaces(
14261 +       unsigned long flags,
14262 +       struct nsproxy *orig,
14263 +       struct fs_struct *new_fs,
14264 +       struct user_namespace *new_user,
14265 +       struct pid_namespace *new_pid)
14266  {
14267         struct nsproxy *new_nsp;
14268         int err;
14269 @@ -67,31 +76,31 @@ static struct nsproxy *create_new_namesp
14270         if (!new_nsp)
14271                 return ERR_PTR(-ENOMEM);
14272  
14273 -       new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
14274 +       new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
14275         if (IS_ERR(new_nsp->mnt_ns)) {
14276                 err = PTR_ERR(new_nsp->mnt_ns);
14277                 goto out_ns;
14278         }
14279  
14280 -       new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
14281 +       new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
14282         if (IS_ERR(new_nsp->uts_ns)) {
14283                 err = PTR_ERR(new_nsp->uts_ns);
14284                 goto out_uts;
14285         }
14286  
14287 -       new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
14288 +       new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
14289         if (IS_ERR(new_nsp->ipc_ns)) {
14290                 err = PTR_ERR(new_nsp->ipc_ns);
14291                 goto out_ipc;
14292         }
14293  
14294 -       new_nsp->pid_ns = copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns);
14295 +       new_nsp->pid_ns = copy_pid_ns(flags, new_user, new_pid);
14296         if (IS_ERR(new_nsp->pid_ns)) {
14297                 err = PTR_ERR(new_nsp->pid_ns);
14298                 goto out_pid;
14299         }
14300  
14301 -       new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
14302 +       new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
14303         if (IS_ERR(new_nsp->net_ns)) {
14304                 err = PTR_ERR(new_nsp->net_ns);
14305                 goto out_net;
14306 @@ -116,6 +125,41 @@ out_ns:
14307         return ERR_PTR(err);
14308  }
14309  
14310 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14311 +       struct task_struct *tsk, struct user_namespace *user_ns,
14312 +       struct fs_struct *new_fs)
14313 +
14314 +{
14315 +       return unshare_namespaces(flags, tsk->nsproxy,
14316 +               new_fs, user_ns, task_active_pid_ns(tsk));
14317 +}
14318 +
14319 +/*
14320 + * copies the nsproxy, setting refcount to 1, and grabbing a
14321 + * reference to all contained namespaces.
14322 + */
14323 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14324 +{
14325 +       struct nsproxy *ns = create_nsproxy();
14326 +
14327 +       if (ns) {
14328 +               memcpy(ns, orig, sizeof(struct nsproxy));
14329 +               atomic_set(&ns->count, 1);
14330 +
14331 +               if (ns->mnt_ns)
14332 +                       get_mnt_ns(ns->mnt_ns);
14333 +               if (ns->uts_ns)
14334 +                       get_uts_ns(ns->uts_ns);
14335 +               if (ns->ipc_ns)
14336 +                       get_ipc_ns(ns->ipc_ns);
14337 +               if (ns->pid_ns)
14338 +                       get_pid_ns(ns->pid_ns);
14339 +               if (ns->net_ns)
14340 +                       get_net(ns->net_ns);
14341 +       }
14342 +       return ns;
14343 +}
14344 +
14345  /*
14346   * called from clone.  This now handles copy for nsproxy and all
14347   * namespaces therein.
14348 @@ -124,9 +168,12 @@ int copy_namespaces(unsigned long flags,
14349  {
14350         struct nsproxy *old_ns = tsk->nsproxy;
14351         struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
14352 -       struct nsproxy *new_ns;
14353 +       struct nsproxy *new_ns = NULL;
14354         int err = 0;
14355  
14356 +       vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14357 +               flags, tsk, old_ns);
14358 +
14359         if (!old_ns)
14360                 return 0;
14361  
14362 @@ -136,7 +183,7 @@ int copy_namespaces(unsigned long flags,
14363                                 CLONE_NEWPID | CLONE_NEWNET)))
14364                 return 0;
14365  
14366 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
14367 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags)) {
14368                 err = -EPERM;
14369                 goto out;
14370         }
14371 @@ -163,6 +210,9 @@ int copy_namespaces(unsigned long flags,
14372  
14373  out:
14374         put_nsproxy(old_ns);
14375 +       vxdprintk(VXD_CBIT(space, 3),
14376 +               "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14377 +               flags, tsk, old_ns, err, new_ns);
14378         return err;
14379  }
14380  
14381 @@ -176,7 +226,9 @@ void free_nsproxy(struct nsproxy *ns)
14382                 put_ipc_ns(ns->ipc_ns);
14383         if (ns->pid_ns)
14384                 put_pid_ns(ns->pid_ns);
14385 -       put_net(ns->net_ns);
14386 +       if (ns->net_ns)
14387 +               put_net(ns->net_ns);
14388 +       atomic_dec(&vs_global_nsproxy);
14389         kmem_cache_free(nsproxy_cachep, ns);
14390  }
14391  
14392 @@ -190,12 +242,16 @@ int unshare_nsproxy_namespaces(unsigned
14393         struct user_namespace *user_ns;
14394         int err = 0;
14395  
14396 +       vxdprintk(VXD_CBIT(space, 4),
14397 +               "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14398 +               unshare_flags, current->nsproxy);
14399 +
14400         if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14401                                CLONE_NEWNET | CLONE_NEWPID)))
14402                 return 0;
14403  
14404         user_ns = new_cred ? new_cred->user_ns : current_user_ns();
14405 -       if (!ns_capable(user_ns, CAP_SYS_ADMIN))
14406 +       if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
14407                 return -EPERM;
14408  
14409         *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
14410 diff -NurpP --minimal linux-3.10.40/kernel/pid.c linux-3.10.40-vs2.3.6.8/kernel/pid.c
14411 --- linux-3.10.40/kernel/pid.c  2014-05-20 04:09:41.000000000 +0000
14412 +++ linux-3.10.40-vs2.3.6.8/kernel/pid.c        2013-11-13 17:17:16.000000000 +0000
14413 @@ -38,6 +38,7 @@
14414  #include <linux/syscalls.h>
14415  #include <linux/proc_ns.h>
14416  #include <linux/proc_fs.h>
14417 +#include <linux/vs_pid.h>
14418  
14419  #define pid_hashfn(nr, ns)     \
14420         hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14421 @@ -367,7 +368,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14422  
14423  struct pid *find_vpid(int nr)
14424  {
14425 -       return find_pid_ns(nr, task_active_pid_ns(current));
14426 +       return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
14427  }
14428  EXPORT_SYMBOL_GPL(find_vpid);
14429  
14430 @@ -427,6 +428,9 @@ void transfer_pid(struct task_struct *ol
14431  struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14432  {
14433         struct task_struct *result = NULL;
14434 +
14435 +       if (type == PIDTYPE_REALPID)
14436 +               type = PIDTYPE_PID;
14437         if (pid) {
14438                 struct hlist_node *first;
14439                 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14440 @@ -446,7 +450,7 @@ struct task_struct *find_task_by_pid_ns(
14441         rcu_lockdep_assert(rcu_read_lock_held(),
14442                            "find_task_by_pid_ns() needs rcu_read_lock()"
14443                            " protection");
14444 -       return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14445 +       return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14446  }
14447  
14448  struct task_struct *find_task_by_vpid(pid_t vnr)
14449 @@ -490,7 +494,7 @@ struct pid *find_get_pid(pid_t nr)
14450  }
14451  EXPORT_SYMBOL_GPL(find_get_pid);
14452  
14453 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14454 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14455  {
14456         struct upid *upid;
14457         pid_t nr = 0;
14458 @@ -504,6 +508,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14459  }
14460  EXPORT_SYMBOL_GPL(pid_nr_ns);
14461  
14462 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14463 +{
14464 +       return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14465 +}
14466 +
14467  pid_t pid_vnr(struct pid *pid)
14468  {
14469         return pid_nr_ns(pid, task_active_pid_ns(current));
14470 diff -NurpP --minimal linux-3.10.40/kernel/pid_namespace.c linux-3.10.40-vs2.3.6.8/kernel/pid_namespace.c
14471 --- linux-3.10.40/kernel/pid_namespace.c        2014-05-20 04:09:41.000000000 +0000
14472 +++ linux-3.10.40-vs2.3.6.8/kernel/pid_namespace.c      2014-05-20 04:31:56.000000000 +0000
14473 @@ -18,6 +18,7 @@
14474  #include <linux/proc_ns.h>
14475  #include <linux/reboot.h>
14476  #include <linux/export.h>
14477 +#include <linux/vserver/global.h>
14478  
14479  struct pid_cache {
14480         int nr_ids;
14481 @@ -110,6 +111,7 @@ static struct pid_namespace *create_pid_
14482                 goto out_free_map;
14483  
14484         kref_init(&ns->kref);
14485 +       atomic_inc(&vs_global_pid_ns);
14486         ns->level = level;
14487         ns->parent = get_pid_ns(parent_pid_ns);
14488         ns->user_ns = get_user_ns(user_ns);
14489 @@ -140,6 +142,7 @@ static void destroy_pid_namespace(struct
14490         for (i = 0; i < PIDMAP_ENTRIES; i++)
14491                 kfree(ns->pidmap[i].page);
14492         put_user_ns(ns->user_ns);
14493 +       atomic_dec(&vs_global_pid_ns);
14494         kmem_cache_free(pid_ns_cachep, ns);
14495  }
14496  
14497 diff -NurpP --minimal linux-3.10.40/kernel/posix-timers.c linux-3.10.40-vs2.3.6.8/kernel/posix-timers.c
14498 --- linux-3.10.40/kernel/posix-timers.c 2013-07-14 17:01:35.000000000 +0000
14499 +++ linux-3.10.40-vs2.3.6.8/kernel/posix-timers.c       2013-08-22 21:10:34.000000000 +0000
14500 @@ -48,6 +48,7 @@
14501  #include <linux/workqueue.h>
14502  #include <linux/export.h>
14503  #include <linux/hashtable.h>
14504 +#include <linux/vs_context.h>
14505  
14506  /*
14507   * Management arrays for POSIX timers. Timers are now kept in static hash table
14508 @@ -398,6 +399,7 @@ int posix_timer_event(struct k_itimer *t
14509  {
14510         struct task_struct *task;
14511         int shared, ret = -1;
14512 +
14513         /*
14514          * FIXME: if ->sigq is queued we can race with
14515          * dequeue_signal()->do_schedule_next_timer().
14516 @@ -414,10 +416,18 @@ int posix_timer_event(struct k_itimer *t
14517         rcu_read_lock();
14518         task = pid_task(timr->it_pid, PIDTYPE_PID);
14519         if (task) {
14520 +               struct vx_info_save vxis;
14521 +               struct vx_info *vxi;
14522 +
14523 +               vxi = get_vx_info(task->vx_info);
14524 +               enter_vx_info(vxi, &vxis);
14525                 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14526                 ret = send_sigqueue(timr->sigq, task, shared);
14527 +               leave_vx_info(&vxis);
14528 +               put_vx_info(vxi);
14529         }
14530         rcu_read_unlock();
14531 +
14532         /* If we failed to send the signal the timer stops. */
14533         return ret > 0;
14534  }
14535 diff -NurpP --minimal linux-3.10.40/kernel/printk.c linux-3.10.40-vs2.3.6.8/kernel/printk.c
14536 --- linux-3.10.40/kernel/printk.c       2014-05-20 04:09:41.000000000 +0000
14537 +++ linux-3.10.40-vs2.3.6.8/kernel/printk.c     2013-11-13 17:17:16.000000000 +0000
14538 @@ -45,6 +45,7 @@
14539  #include <linux/poll.h>
14540  #include <linux/irq_work.h>
14541  #include <linux/utsname.h>
14542 +#include <linux/vs_cvirt.h>
14543  
14544  #include <asm/uaccess.h>
14545  
14546 @@ -391,7 +392,7 @@ static int check_syslog_permissions(int
14547                 return 0;
14548  
14549         if (syslog_action_restricted(type)) {
14550 -               if (capable(CAP_SYSLOG))
14551 +               if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14552                         return 0;
14553                 /*
14554                  * For historical reasons, accept CAP_SYS_ADMIN too, with
14555 @@ -1140,12 +1141,9 @@ int do_syslog(int type, char __user *buf
14556         if (error)
14557                 return error;
14558  
14559 -       switch (type) {
14560 -       case SYSLOG_ACTION_CLOSE:       /* Close log */
14561 -               break;
14562 -       case SYSLOG_ACTION_OPEN:        /* Open log */
14563 -               break;
14564 -       case SYSLOG_ACTION_READ:        /* Read from log */
14565 +       if ((type == SYSLOG_ACTION_READ) ||
14566 +           (type == SYSLOG_ACTION_READ_ALL) ||
14567 +           (type == SYSLOG_ACTION_READ_CLEAR)) {
14568                 error = -EINVAL;
14569                 if (!buf || len < 0)
14570                         goto out;
14571 @@ -1156,6 +1154,16 @@ int do_syslog(int type, char __user *buf
14572                         error = -EFAULT;
14573                         goto out;
14574                 }
14575 +       }
14576 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14577 +               return vx_do_syslog(type, buf, len);
14578 +
14579 +       switch (type) {
14580 +       case SYSLOG_ACTION_CLOSE:       /* Close log */
14581 +               break;
14582 +       case SYSLOG_ACTION_OPEN:        /* Open log */
14583 +               break;
14584 +       case SYSLOG_ACTION_READ:        /* Read from log */
14585                 error = wait_event_interruptible(log_wait,
14586                                                  syslog_seq != log_next_seq);
14587                 if (error)
14588 @@ -1168,16 +1176,6 @@ int do_syslog(int type, char __user *buf
14589                 /* FALL THRU */
14590         /* Read last kernel messages */
14591         case SYSLOG_ACTION_READ_ALL:
14592 -               error = -EINVAL;
14593 -               if (!buf || len < 0)
14594 -                       goto out;
14595 -               error = 0;
14596 -               if (!len)
14597 -                       goto out;
14598 -               if (!access_ok(VERIFY_WRITE, buf, len)) {
14599 -                       error = -EFAULT;
14600 -                       goto out;
14601 -               }
14602                 error = syslog_print_all(buf, len, clear);
14603                 break;
14604         /* Clear ring buffer */
14605 diff -NurpP --minimal linux-3.10.40/kernel/ptrace.c linux-3.10.40-vs2.3.6.8/kernel/ptrace.c
14606 --- linux-3.10.40/kernel/ptrace.c       2014-05-20 04:09:41.000000000 +0000
14607 +++ linux-3.10.40-vs2.3.6.8/kernel/ptrace.c     2013-11-30 07:53:00.000000000 +0000
14608 @@ -23,6 +23,7 @@
14609  #include <linux/syscalls.h>
14610  #include <linux/uaccess.h>
14611  #include <linux/regset.h>
14612 +#include <linux/vs_context.h>
14613  #include <linux/hw_breakpoint.h>
14614  #include <linux/cn_proc.h>
14615  #include <linux/compat.h>
14616 @@ -264,6 +265,11 @@ ok:
14617         }
14618         rcu_read_unlock();
14619  
14620 +       if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14621 +               return -EPERM;
14622 +       if (!vx_check(task->xid, VS_IDENT) &&
14623 +               !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14624 +               return -EACCES;
14625         return security_ptrace_access_check(task, mode);
14626  }
14627  
14628 diff -NurpP --minimal linux-3.10.40/kernel/sched/core.c linux-3.10.40-vs2.3.6.8/kernel/sched/core.c
14629 --- linux-3.10.40/kernel/sched/core.c   2014-05-20 04:09:42.000000000 +0000
14630 +++ linux-3.10.40-vs2.3.6.8/kernel/sched/core.c 2014-01-22 19:00:34.000000000 +0000
14631 @@ -73,6 +73,8 @@
14632  #include <linux/init_task.h>
14633  #include <linux/binfmts.h>
14634  #include <linux/context_tracking.h>
14635 +#include <linux/vs_sched.h>
14636 +#include <linux/vs_cvirt.h>
14637  
14638  #include <asm/switch_to.h>
14639  #include <asm/tlb.h>
14640 @@ -2145,9 +2147,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14641   */
14642  void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14643  {
14644 -       loads[0] = (avenrun[0] + offset) << shift;
14645 -       loads[1] = (avenrun[1] + offset) << shift;
14646 -       loads[2] = (avenrun[2] + offset) << shift;
14647 +       if (vx_flags(VXF_VIRT_LOAD, 0)) {
14648 +               struct vx_info *vxi = current_vx_info();
14649 +
14650 +               loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14651 +               loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14652 +               loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14653 +       } else {
14654 +               loads[0] = (avenrun[0] + offset) << shift;
14655 +               loads[1] = (avenrun[1] + offset) << shift;
14656 +               loads[2] = (avenrun[2] + offset) << shift;
14657 +       }
14658  }
14659  
14660  static long calc_load_fold_active(struct rq *this_rq)
14661 @@ -3750,7 +3760,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14662                 nice = 19;
14663  
14664         if (increment < 0 && !can_nice(current, nice))
14665 -               return -EPERM;
14666 +               return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14667  
14668         retval = security_task_setnice(current, nice);
14669         if (retval)
14670 diff -NurpP --minimal linux-3.10.40/kernel/sched/cputime.c linux-3.10.40-vs2.3.6.8/kernel/sched/cputime.c
14671 --- linux-3.10.40/kernel/sched/cputime.c        2014-05-20 04:09:42.000000000 +0000
14672 +++ linux-3.10.40-vs2.3.6.8/kernel/sched/cputime.c      2013-11-13 17:17:16.000000000 +0000
14673 @@ -4,6 +4,7 @@
14674  #include <linux/kernel_stat.h>
14675  #include <linux/static_key.h>
14676  #include <linux/context_tracking.h>
14677 +#include <linux/vs_sched.h>
14678  #include "sched.h"
14679  
14680  
14681 @@ -135,14 +136,17 @@ static inline void task_group_account_fi
14682  void account_user_time(struct task_struct *p, cputime_t cputime,
14683                        cputime_t cputime_scaled)
14684  {
14685 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14686 +       int nice = (TASK_NICE(p) > 0);
14687         int index;
14688  
14689         /* Add user time to process. */
14690         p->utime += cputime;
14691         p->utimescaled += cputime_scaled;
14692 +       vx_account_user(vxi, cputime, nice);
14693         account_group_user_time(p, cputime);
14694  
14695 -       index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14696 +       index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14697  
14698         /* Add user time to cpustat. */
14699         task_group_account_field(p, index, (__force u64) cputime);
14700 @@ -189,9 +193,12 @@ static inline
14701  void __account_system_time(struct task_struct *p, cputime_t cputime,
14702                         cputime_t cputime_scaled, int index)
14703  {
14704 +       struct vx_info *vxi = p->vx_info;  /* p is _always_ current */
14705 +
14706         /* Add system time to process. */
14707         p->stime += cputime;
14708         p->stimescaled += cputime_scaled;
14709 +       vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14710         account_group_system_time(p, cputime);
14711  
14712         /* Add system time to cpustat. */
14713 diff -NurpP --minimal linux-3.10.40/kernel/sched/fair.c linux-3.10.40-vs2.3.6.8/kernel/sched/fair.c
14714 --- linux-3.10.40/kernel/sched/fair.c   2014-05-20 04:09:42.000000000 +0000
14715 +++ linux-3.10.40-vs2.3.6.8/kernel/sched/fair.c 2014-04-22 03:48:11.000000000 +0000
14716 @@ -29,6 +29,7 @@
14717  #include <linux/mempolicy.h>
14718  #include <linux/migrate.h>
14719  #include <linux/task_work.h>
14720 +#include <linux/vs_cvirt.h>
14721  
14722  #include <trace/events/sched.h>
14723  
14724 @@ -1743,6 +1744,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14725                 __enqueue_entity(cfs_rq, se);
14726         se->on_rq = 1;
14727  
14728 +       if (entity_is_task(se))
14729 +               vx_activate_task(task_of(se));
14730         if (cfs_rq->nr_running == 1) {
14731                 list_add_leaf_cfs_rq(cfs_rq);
14732                 check_enqueue_throttle(cfs_rq);
14733 @@ -1824,6 +1827,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14734         if (se != cfs_rq->curr)
14735                 __dequeue_entity(cfs_rq, se);
14736         se->on_rq = 0;
14737 +       if (entity_is_task(se))
14738 +               vx_deactivate_task(task_of(se));
14739         account_entity_dequeue(cfs_rq, se);
14740  
14741         /*
14742 diff -NurpP --minimal linux-3.10.40/kernel/signal.c linux-3.10.40-vs2.3.6.8/kernel/signal.c
14743 --- linux-3.10.40/kernel/signal.c       2013-07-14 17:01:35.000000000 +0000
14744 +++ linux-3.10.40-vs2.3.6.8/kernel/signal.c     2013-08-22 21:13:50.000000000 +0000
14745 @@ -33,6 +33,8 @@
14746  #include <linux/uprobes.h>
14747  #include <linux/compat.h>
14748  #include <linux/cn_proc.h>
14749 +#include <linux/vs_context.h>
14750 +#include <linux/vs_pid.h>
14751  #define CREATE_TRACE_POINTS
14752  #include <trace/events/signal.h>
14753  
14754 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14755         struct pid *sid;
14756         int error;
14757  
14758 +       vxdprintk(VXD_CBIT(misc, 7),
14759 +               "check_kill_permission(%d,%p,%p[#%u,%u])",
14760 +               sig, info, t, vx_task_xid(t), t->pid);
14761 +
14762         if (!valid_signal(sig))
14763                 return -EINVAL;
14764  
14765 +/*     FIXME: needed? if so, why?
14766 +       if ((info != SEND_SIG_NOINFO) &&
14767 +               (is_si_special(info) || !si_fromuser(info)))
14768 +               goto skip;      */
14769 +
14770         if (!si_fromuser(info))
14771                 return 0;
14772  
14773 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14774                 }
14775         }
14776  
14777 +       error = -EPERM;
14778 +       if (t->pid == 1 && current->xid)
14779 +               return error;
14780 +
14781 +       error = -ESRCH;
14782 +       /* FIXME: we shouldn't return ESRCH ever, to avoid
14783 +                 loops, maybe ENOENT or EACCES? */
14784 +       if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14785 +               vxdprintk(current->xid || VXD_CBIT(misc, 7),
14786 +                       "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14787 +                       sig, info, t, vx_task_xid(t), t->pid, current->xid);
14788 +               return error;
14789 +       }
14790 +/* skip: */
14791         return security_task_kill(t, info, sig, 0);
14792  }
14793  
14794 @@ -1353,7 +1378,7 @@ int kill_pid_info(int sig, struct siginf
14795         rcu_read_lock();
14796  retry:
14797         p = pid_task(pid, PIDTYPE_PID);
14798 -       if (p) {
14799 +       if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14800                 error = group_send_sig_info(sig, info, p);
14801                 if (unlikely(error == -ESRCH))
14802                         /*
14803 @@ -1401,7 +1426,7 @@ int kill_pid_info_as_cred(int sig, struc
14804  
14805         rcu_read_lock();
14806         p = pid_task(pid, PIDTYPE_PID);
14807 -       if (!p) {
14808 +       if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14809                 ret = -ESRCH;
14810                 goto out_unlock;
14811         }
14812 @@ -1453,8 +1478,10 @@ static int kill_something_info(int sig,
14813                 struct task_struct * p;
14814  
14815                 for_each_process(p) {
14816 -                       if (task_pid_vnr(p) > 1 &&
14817 -                                       !same_thread_group(p, current)) {
14818 +                       if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14819 +                               task_pid_vnr(p) > 1 &&
14820 +                               !same_thread_group(p, current) &&
14821 +                               !vx_current_initpid(p->pid)) {
14822                                 int err = group_send_sig_info(sig, info, p);
14823                                 ++count;
14824                                 if (err != -EPERM)
14825 @@ -2308,6 +2335,11 @@ relock:
14826                                 !sig_kernel_only(signr))
14827                         continue;
14828  
14829 +               /* virtual init is protected against user signals */
14830 +               if ((info->si_code == SI_USER) &&
14831 +                       vx_current_initpid(current->pid))
14832 +                       continue;
14833 +
14834                 if (sig_kernel_stop(signr)) {
14835                         /*
14836                          * The default action is to stop all threads in
14837 diff -NurpP --minimal linux-3.10.40/kernel/softirq.c linux-3.10.40-vs2.3.6.8/kernel/softirq.c
14838 --- linux-3.10.40/kernel/softirq.c      2014-05-20 04:09:42.000000000 +0000
14839 +++ linux-3.10.40-vs2.3.6.8/kernel/softirq.c    2013-11-13 17:17:16.000000000 +0000
14840 @@ -25,6 +25,7 @@
14841  #include <linux/smp.h>
14842  #include <linux/smpboot.h>
14843  #include <linux/tick.h>
14844 +#include <linux/vs_context.h>
14845  
14846  #define CREATE_TRACE_POINTS
14847  #include <trace/events/irq.h>
14848 diff -NurpP --minimal linux-3.10.40/kernel/sys.c linux-3.10.40-vs2.3.6.8/kernel/sys.c
14849 --- linux-3.10.40/kernel/sys.c  2013-07-14 17:01:35.000000000 +0000
14850 +++ linux-3.10.40-vs2.3.6.8/kernel/sys.c        2013-08-22 20:30:00.000000000 +0000
14851 @@ -55,6 +55,7 @@
14852  #include <linux/cred.h>
14853  
14854  #include <linux/kmsg_dump.h>
14855 +#include <linux/vs_pid.h>
14856  /* Move somewhere else to avoid recompiling? */
14857  #include <generated/utsrelease.h>
14858  
14859 @@ -160,7 +161,10 @@ static int set_one_prio(struct task_stru
14860                 goto out;
14861         }
14862         if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14863 -               error = -EACCES;
14864 +               if (vx_flags(VXF_IGNEG_NICE, 0))
14865 +                       error = 0;
14866 +               else
14867 +                       error = -EACCES;
14868                 goto out;
14869         }
14870         no_nice = security_task_setnice(p, niceval);
14871 @@ -211,6 +215,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14872                         else
14873                                 pgrp = task_pgrp(current);
14874                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14875 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14876 +                                       continue;
14877                                 error = set_one_prio(p, niceval, error);
14878                         } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14879                         break;
14880 @@ -276,6 +282,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14881                         else
14882                                 pgrp = task_pgrp(current);
14883                         do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14884 +                               if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14885 +                                       continue;
14886                                 niceval = 20 - task_nice(p);
14887                                 if (niceval > retval)
14888                                         retval = niceval;
14889 @@ -452,6 +460,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
14890  
14891  static DEFINE_MUTEX(reboot_mutex);
14892  
14893 +long vs_reboot(unsigned int, void __user *);
14894 +
14895  /*
14896   * Reboot system call: for obvious reasons only root may call it,
14897   * and even root needs to set up some magic numbers in the registers
14898 @@ -494,6 +504,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
14899         if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
14900                 cmd = LINUX_REBOOT_CMD_HALT;
14901  
14902 +       if (!vx_check(0, VS_ADMIN|VS_WATCH))
14903 +               return vs_reboot(cmd, arg);
14904 +
14905         mutex_lock(&reboot_mutex);
14906         switch (cmd) {
14907         case LINUX_REBOOT_CMD_RESTART:
14908 @@ -1462,7 +1475,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14909         int errno;
14910         char tmp[__NEW_UTS_LEN];
14911  
14912 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14913 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14914 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14915                 return -EPERM;
14916  
14917         if (len < 0 || len > __NEW_UTS_LEN)
14918 @@ -1513,7 +1527,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14919         int errno;
14920         char tmp[__NEW_UTS_LEN];
14921  
14922 -       if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14923 +       if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14924 +               CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14925                 return -EPERM;
14926         if (len < 0 || len > __NEW_UTS_LEN)
14927                 return -EINVAL;
14928 @@ -1632,7 +1647,7 @@ int do_prlimit(struct task_struct *tsk,
14929                 /* Keep the capable check against init_user_ns until
14930                    cgroups can contain all limits */
14931                 if (new_rlim->rlim_max > rlim->rlim_max &&
14932 -                               !capable(CAP_SYS_RESOURCE))
14933 +                       !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14934                         retval = -EPERM;
14935                 if (!retval)
14936                         retval = security_task_setrlimit(tsk->group_leader,
14937 @@ -1685,7 +1700,8 @@ static int check_prlimit_permission(stru
14938             gid_eq(cred->gid, tcred->sgid) &&
14939             gid_eq(cred->gid, tcred->gid))
14940                 return 0;
14941 -       if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14942 +       if (vx_ns_capable(tcred->user_ns,
14943 +               CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14944                 return 0;
14945  
14946         return -EPERM;
14947 diff -NurpP --minimal linux-3.10.40/kernel/sysctl.c linux-3.10.40-vs2.3.6.8/kernel/sysctl.c
14948 --- linux-3.10.40/kernel/sysctl.c       2014-05-20 04:09:42.000000000 +0000
14949 +++ linux-3.10.40-vs2.3.6.8/kernel/sysctl.c     2014-05-20 04:31:56.000000000 +0000
14950 @@ -83,6 +83,7 @@
14951  #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14952  #include <linux/lockdep.h>
14953  #endif
14954 +extern char vshelper_path[];
14955  #ifdef CONFIG_CHR_DEV_SG
14956  #include <scsi/sg.h>
14957  #endif
14958 @@ -633,6 +634,13 @@ static struct ctl_table kern_table[] = {
14959                 .mode           = 0644,
14960                 .proc_handler   = proc_dostring,
14961         },
14962 +       {
14963 +               .procname       = "vshelper",
14964 +               .data           = &vshelper_path,
14965 +               .maxlen         = 256,
14966 +               .mode           = 0644,
14967 +               .proc_handler   = &proc_dostring,
14968 +       },
14969  
14970  #ifdef CONFIG_CHR_DEV_SG
14971         {
14972 diff -NurpP --minimal linux-3.10.40/kernel/sysctl_binary.c linux-3.10.40-vs2.3.6.8/kernel/sysctl_binary.c
14973 --- linux-3.10.40/kernel/sysctl_binary.c        2013-07-14 17:01:35.000000000 +0000
14974 +++ linux-3.10.40-vs2.3.6.8/kernel/sysctl_binary.c      2013-08-22 20:30:00.000000000 +0000
14975 @@ -74,6 +74,7 @@ static const struct bin_table bin_kern_t
14976  
14977         { CTL_INT,      KERN_PANIC,                     "panic" },
14978         { CTL_INT,      KERN_REALROOTDEV,               "real-root-dev" },
14979 +       { CTL_STR,      KERN_VSHELPER,                  "vshelper" },
14980  
14981         { CTL_STR,      KERN_SPARC_REBOOT,              "reboot-cmd" },
14982         { CTL_INT,      KERN_CTLALTDEL,                 "ctrl-alt-del" },
14983 diff -NurpP --minimal linux-3.10.40/kernel/time/timekeeping.c linux-3.10.40-vs2.3.6.8/kernel/time/timekeeping.c
14984 --- linux-3.10.40/kernel/time/timekeeping.c     2014-05-20 04:09:42.000000000 +0000
14985 +++ linux-3.10.40-vs2.3.6.8/kernel/time/timekeeping.c   2014-03-12 13:18:23.000000000 +0000
14986 @@ -22,6 +22,7 @@
14987  #include <linux/tick.h>
14988  #include <linux/stop_machine.h>
14989  #include <linux/pvclock_gtod.h>
14990 +#include <linux/vs_time.h>
14991  
14992  #include "tick-internal.h"
14993  #include "ntp_internal.h"
14994 @@ -694,6 +695,7 @@ void getrawmonotonic(struct timespec *ts
14995         } while (read_seqcount_retry(&timekeeper_seq, seq));
14996  
14997         timespec_add_ns(ts, nsecs);
14998 +       vx_adjust_timespec(ts);
14999  }
15000  EXPORT_SYMBOL(getrawmonotonic);
15001  
15002 diff -NurpP --minimal linux-3.10.40/kernel/time.c linux-3.10.40-vs2.3.6.8/kernel/time.c
15003 --- linux-3.10.40/kernel/time.c 2013-07-14 17:01:35.000000000 +0000
15004 +++ linux-3.10.40-vs2.3.6.8/kernel/time.c       2013-08-22 20:30:00.000000000 +0000
15005 @@ -37,6 +37,7 @@
15006  #include <linux/fs.h>
15007  #include <linux/math64.h>
15008  #include <linux/ptrace.h>
15009 +#include <linux/vs_time.h>
15010  
15011  #include <asm/uaccess.h>
15012  #include <asm/unistd.h>
15013 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15014         if (err)
15015                 return err;
15016  
15017 -       do_settimeofday(&tv);
15018 +       vx_settimeofday(&tv);
15019         return 0;
15020  }
15021  
15022 @@ -181,7 +182,7 @@ int do_sys_settimeofday(const struct tim
15023                 }
15024         }
15025         if (tv)
15026 -               return do_settimeofday(tv);
15027 +               return vx_settimeofday(tv);
15028         return 0;
15029  }
15030  
15031 diff -NurpP --minimal linux-3.10.40/kernel/timer.c linux-3.10.40-vs2.3.6.8/kernel/timer.c
15032 --- linux-3.10.40/kernel/timer.c        2014-05-20 04:09:42.000000000 +0000
15033 +++ linux-3.10.40-vs2.3.6.8/kernel/timer.c      2013-11-13 17:17:16.000000000 +0000
15034 @@ -42,6 +42,10 @@
15035  #include <linux/sched/sysctl.h>
15036  #include <linux/slab.h>
15037  #include <linux/compat.h>
15038 +#include <linux/vs_base.h>
15039 +#include <linux/vs_cvirt.h>
15040 +#include <linux/vs_pid.h>
15041 +#include <linux/vserver/sched.h>
15042  
15043  #include <asm/uaccess.h>
15044  #include <asm/unistd.h>
15045 diff -NurpP --minimal linux-3.10.40/kernel/user_namespace.c linux-3.10.40-vs2.3.6.8/kernel/user_namespace.c
15046 --- linux-3.10.40/kernel/user_namespace.c       2014-05-20 04:09:42.000000000 +0000
15047 +++ linux-3.10.40-vs2.3.6.8/kernel/user_namespace.c     2014-05-20 04:31:56.000000000 +0000
15048 @@ -22,6 +22,7 @@
15049  #include <linux/ctype.h>
15050  #include <linux/projid.h>
15051  #include <linux/fs_struct.h>
15052 +#include <linux/vserver/global.h>
15053  
15054  static struct kmem_cache *user_ns_cachep __read_mostly;
15055  
15056 @@ -94,6 +95,7 @@ int create_user_ns(struct cred *new)
15057  
15058         atomic_set(&ns->count, 1);
15059         /* Leave the new->user_ns reference with the new user namespace. */
15060 +       atomic_inc(&vs_global_user_ns);
15061         ns->parent = parent_ns;
15062         ns->level = parent_ns->level + 1;
15063         ns->owner = owner;
15064 @@ -843,6 +845,8 @@ static void *userns_get(struct task_stru
15065  
15066  static void userns_put(void *ns)
15067  {
15068 +       /* FIXME: maybe move into destroyer? */
15069 +       atomic_dec(&vs_global_user_ns);
15070         put_user_ns(ns);
15071  }
15072  
15073 diff -NurpP --minimal linux-3.10.40/kernel/utsname.c linux-3.10.40-vs2.3.6.8/kernel/utsname.c
15074 --- linux-3.10.40/kernel/utsname.c      2013-07-14 17:01:35.000000000 +0000
15075 +++ linux-3.10.40-vs2.3.6.8/kernel/utsname.c    2013-08-22 21:03:08.000000000 +0000
15076 @@ -16,14 +16,17 @@
15077  #include <linux/slab.h>
15078  #include <linux/user_namespace.h>
15079  #include <linux/proc_ns.h>
15080 +#include <linux/vserver/global.h>
15081  
15082  static struct uts_namespace *create_uts_ns(void)
15083  {
15084         struct uts_namespace *uts_ns;
15085  
15086         uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15087 -       if (uts_ns)
15088 -               kref_init(&uts_ns->kref);
15089 +       if (uts_ns) {
15090 +               kref_init(&uts_ns->kref);
15091 +               atomic_inc(&vs_global_uts_ns);
15092 +       }
15093         return uts_ns;
15094  }
15095  
15096 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
15097         ns = container_of(kref, struct uts_namespace, kref);
15098         put_user_ns(ns->user_ns);
15099         proc_free_inum(ns->proc_inum);
15100 +       atomic_dec(&vs_global_uts_ns);
15101         kfree(ns);
15102  }
15103  
15104 diff -NurpP --minimal linux-3.10.40/kernel/vserver/Kconfig linux-3.10.40-vs2.3.6.8/kernel/vserver/Kconfig
15105 --- linux-3.10.40/kernel/vserver/Kconfig        1970-01-01 00:00:00.000000000 +0000
15106 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/Kconfig      2013-11-14 04:29:47.000000000 +0000
15107 @@ -0,0 +1,230 @@
15108 +#
15109 +# Linux VServer configuration
15110 +#
15111 +
15112 +menu "Linux VServer"
15113 +
15114 +config VSERVER_AUTO_LBACK
15115 +       bool    "Automatically Assign Loopback IP"
15116 +       default y
15117 +       help
15118 +         Automatically assign a guest specific loopback
15119 +         IP and add it to the kernel network stack on
15120 +         startup.
15121 +
15122 +config VSERVER_AUTO_SINGLE
15123 +       bool    "Automatic Single IP Special Casing"
15124 +       default n
15125 +       help
15126 +         This allows network contexts with a single IP to
15127 +         automatically remap 0.0.0.0 bindings to that IP,
15128 +         avoiding further network checks and improving
15129 +         performance.
15130 +
15131 +         (note: such guests do not allow to change the ip
15132 +          on the fly and do not show loopback addresses)
15133 +
15134 +config VSERVER_COWBL
15135 +       bool    "Enable COW Immutable Link Breaking"
15136 +       default y
15137 +       help
15138 +         This enables the COW (Copy-On-Write) link break code.
15139 +         It allows you to treat unified files like normal files
15140 +         when writing to them (which will implicitely break the
15141 +         link and create a copy of the unified file)
15142 +
15143 +config VSERVER_VTIME
15144 +       bool    "Enable Virtualized Guest Time (EXPERIMENTAL)"
15145 +       default n
15146 +       help
15147 +         This enables per guest time offsets to allow for
15148 +         adjusting the system clock individually per guest.
15149 +         this adds some overhead to the time functions and
15150 +         therefore should not be enabled without good reason.
15151 +
15152 +config VSERVER_DEVICE
15153 +       bool    "Enable Guest Device Mapping (EXPERIMENTAL)"
15154 +       default n
15155 +       help
15156 +         This enables generic device remapping.
15157 +
15158 +config VSERVER_PROC_SECURE
15159 +       bool    "Enable Proc Security"
15160 +       depends on PROC_FS
15161 +       default y
15162 +       help
15163 +         This configures ProcFS security to initially hide
15164 +         non-process entries for all contexts except the main and
15165 +         spectator context (i.e. for all guests), which is a secure
15166 +         default.
15167 +
15168 +         (note: on 1.2x the entries were visible by default)
15169 +
15170 +choice
15171 +       prompt  "Persistent Inode Tagging"
15172 +       default TAGGING_ID24
15173 +       help
15174 +         This adds persistent context information to filesystems
15175 +         mounted with the tagxid option. Tagging is a requirement
15176 +         for per-context disk limits and per-context quota.
15177 +
15178 +
15179 +config TAGGING_NONE
15180 +       bool    "Disabled"
15181 +       help
15182 +         do not store per-context information in inodes.
15183 +
15184 +config TAGGING_UID16
15185 +       bool    "UID16/GID32"
15186 +       help
15187 +         reduces UID to 16 bit, but leaves GID at 32 bit.
15188 +
15189 +config TAGGING_GID16
15190 +       bool    "UID32/GID16"
15191 +       help
15192 +         reduces GID to 16 bit, but leaves UID at 32 bit.
15193 +
15194 +config TAGGING_ID24
15195 +       bool    "UID24/GID24"
15196 +       help
15197 +         uses the upper 8bit from UID and GID for XID tagging
15198 +         which leaves 24bit for UID/GID each, which should be
15199 +         more than sufficient for normal use.
15200 +
15201 +config TAGGING_INTERN
15202 +       bool    "UID32/GID32"
15203 +       help
15204 +         this uses otherwise reserved inode fields in the on
15205 +         disk representation, which limits the use to a few
15206 +         filesystems (currently ext2 and ext3)
15207 +
15208 +endchoice
15209 +
15210 +config TAG_NFSD
15211 +       bool    "Tag NFSD User Auth and Files"
15212 +       default n
15213 +       help
15214 +         Enable this if you do want the in-kernel NFS
15215 +         Server to use the tagging specified above.
15216 +         (will require patched clients too)
15217 +
15218 +config VSERVER_PRIVACY
15219 +       bool    "Honor Privacy Aspects of Guests"
15220 +       default n
15221 +       help
15222 +         When enabled, most context checks will disallow
15223 +         access to structures assigned to a specific context,
15224 +         like ptys or loop devices.
15225 +
15226 +config VSERVER_CONTEXTS
15227 +       int     "Maximum number of Contexts (1-65533)"  if EMBEDDED
15228 +       range 1 65533
15229 +       default "768"   if 64BIT
15230 +       default "256"
15231 +       help
15232 +         This setting will optimize certain data structures
15233 +         and memory allocations according to the expected
15234 +         maximum.
15235 +
15236 +         note: this is not a strict upper limit.
15237 +
15238 +config VSERVER_WARN
15239 +       bool    "VServer Warnings"
15240 +       default y
15241 +       help
15242 +         This enables various runtime warnings, which will
15243 +         notify about potential manipulation attempts or
15244 +         resource shortage. It is generally considered to
15245 +         be a good idea to have that enabled.
15246 +
15247 +config VSERVER_WARN_DEVPTS
15248 +       bool    "VServer DevPTS Warnings"
15249 +       depends on VSERVER_WARN
15250 +       default y
15251 +       help
15252 +         This enables DevPTS related warnings, issued when a
15253 +         process inside a context tries to lookup or access
15254 +         a dynamic pts from the host or a different context.
15255 +
15256 +config VSERVER_DEBUG
15257 +       bool    "VServer Debugging Code"
15258 +       default n
15259 +       help
15260 +         Set this to yes if you want to be able to activate
15261 +         debugging output at runtime. It adds a very small
15262 +         overhead to all vserver related functions and
15263 +         increases the kernel size by about 20k.
15264 +
15265 +config VSERVER_HISTORY
15266 +       bool    "VServer History Tracing"
15267 +       depends on VSERVER_DEBUG
15268 +       default n
15269 +       help
15270 +         Set this to yes if you want to record the history of
15271 +         linux-vserver activities, so they can be replayed in
15272 +         the event of a kernel panic or oops.
15273 +
15274 +config VSERVER_HISTORY_SIZE
15275 +       int     "Per-CPU History Size (32-65536)"
15276 +       depends on VSERVER_HISTORY
15277 +       range 32 65536
15278 +       default 64
15279 +       help
15280 +         This allows you to specify the number of entries in
15281 +         the per-CPU history buffer.
15282 +
15283 +config VSERVER_EXTRA_MNT_CHECK
15284 +       bool    "Extra Checks for Reachability"
15285 +       default n
15286 +       help
15287 +         Set this to yes if you want to do extra checks for
15288 +         vfsmount reachability in the proc filesystem code.
15289 +         This shouldn't be required on any setup utilizing
15290 +         mnt namespaces.
15291 +
15292 +choice
15293 +       prompt  "Quotes used in debug and warn messages"
15294 +       default QUOTES_ISO8859
15295 +
15296 +config QUOTES_ISO8859
15297 +       bool    "Extended ASCII (ISO 8859) angle quotes"
15298 +       help
15299 +         This uses the extended ASCII characters \xbb
15300 +         and \xab for quoting file and process names.
15301 +
15302 +config QUOTES_UTF8
15303 +       bool    "UTF-8 angle quotes"
15304 +       help
15305 +         This uses the the UTF-8 sequences for angle
15306 +         quotes to quote file and process names.
15307 +
15308 +config QUOTES_ASCII
15309 +       bool    "ASCII single quotes"
15310 +       help
15311 +         This uses the ASCII single quote character
15312 +         (\x27) to quote file and process names.
15313 +
15314 +endchoice
15315 +
15316 +endmenu
15317 +
15318 +
15319 +config VSERVER
15320 +       bool
15321 +       default y
15322 +       select NAMESPACES
15323 +       select UTS_NS
15324 +       select IPC_NS
15325 +#      select USER_NS
15326 +       select SYSVIPC
15327 +
15328 +config VSERVER_SECURITY
15329 +       bool
15330 +       depends on SECURITY
15331 +       default y
15332 +       select SECURITY_CAPABILITIES
15333 +
15334 +config VSERVER_DISABLED
15335 +       bool
15336 +       default n
15337 +
15338 diff -NurpP --minimal linux-3.10.40/kernel/vserver/Makefile linux-3.10.40-vs2.3.6.8/kernel/vserver/Makefile
15339 --- linux-3.10.40/kernel/vserver/Makefile       1970-01-01 00:00:00.000000000 +0000
15340 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/Makefile     2013-08-22 20:30:00.000000000 +0000
15341 @@ -0,0 +1,18 @@
15342 +#
15343 +# Makefile for the Linux vserver routines.
15344 +#
15345 +
15346 +
15347 +obj-y          += vserver.o
15348 +
15349 +vserver-y      := switch.o context.o space.o sched.o network.o inode.o \
15350 +                  limit.o cvirt.o cacct.o signal.o helper.o init.o \
15351 +                  dlimit.o tag.o
15352 +
15353 +vserver-$(CONFIG_INET) += inet.o
15354 +vserver-$(CONFIG_PROC_FS) += proc.o
15355 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15356 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15357 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15358 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15359 +
15360 diff -NurpP --minimal linux-3.10.40/kernel/vserver/cacct.c linux-3.10.40-vs2.3.6.8/kernel/vserver/cacct.c
15361 --- linux-3.10.40/kernel/vserver/cacct.c        1970-01-01 00:00:00.000000000 +0000
15362 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/cacct.c      2013-08-22 20:30:00.000000000 +0000
15363 @@ -0,0 +1,42 @@
15364 +/*
15365 + *  linux/kernel/vserver/cacct.c
15366 + *
15367 + *  Virtual Server: Context Accounting
15368 + *
15369 + *  Copyright (C) 2006-2007 Herbert Pötzl
15370 + *
15371 + *  V0.01  added accounting stats
15372 + *
15373 + */
15374 +
15375 +#include <linux/types.h>
15376 +#include <linux/vs_context.h>
15377 +#include <linux/vserver/cacct_cmd.h>
15378 +#include <linux/vserver/cacct_int.h>
15379 +
15380 +#include <asm/errno.h>
15381 +#include <asm/uaccess.h>
15382 +
15383 +
15384 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15385 +{
15386 +       struct vcmd_sock_stat_v0 vc_data;
15387 +       int j, field;
15388 +
15389 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15390 +               return -EFAULT;
15391 +
15392 +       field = vc_data.field;
15393 +       if ((field < 0) || (field >= VXA_SOCK_SIZE))
15394 +               return -EINVAL;
15395 +
15396 +       for (j = 0; j < 3; j++) {
15397 +               vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15398 +               vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15399 +       }
15400 +
15401 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15402 +               return -EFAULT;
15403 +       return 0;
15404 +}
15405 +
15406 diff -NurpP --minimal linux-3.10.40/kernel/vserver/cacct_init.h linux-3.10.40-vs2.3.6.8/kernel/vserver/cacct_init.h
15407 --- linux-3.10.40/kernel/vserver/cacct_init.h   1970-01-01 00:00:00.000000000 +0000
15408 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/cacct_init.h 2013-08-22 20:30:00.000000000 +0000
15409 @@ -0,0 +1,25 @@
15410 +
15411 +
15412 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15413 +{
15414 +       int i, j;
15415 +
15416 +
15417 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15418 +               for (j = 0; j < 3; j++) {
15419 +                       atomic_long_set(&cacct->sock[i][j].count, 0);
15420 +                       atomic_long_set(&cacct->sock[i][j].total, 0);
15421 +               }
15422 +       }
15423 +       for (i = 0; i < 8; i++)
15424 +               atomic_set(&cacct->slab[i], 0);
15425 +       for (i = 0; i < 5; i++)
15426 +               for (j = 0; j < 4; j++)
15427 +                       atomic_set(&cacct->page[i][j], 0);
15428 +}
15429 +
15430 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15431 +{
15432 +       return;
15433 +}
15434 +
15435 diff -NurpP --minimal linux-3.10.40/kernel/vserver/cacct_proc.h linux-3.10.40-vs2.3.6.8/kernel/vserver/cacct_proc.h
15436 --- linux-3.10.40/kernel/vserver/cacct_proc.h   1970-01-01 00:00:00.000000000 +0000
15437 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/cacct_proc.h 2013-08-22 20:30:00.000000000 +0000
15438 @@ -0,0 +1,53 @@
15439 +#ifndef _VX_CACCT_PROC_H
15440 +#define _VX_CACCT_PROC_H
15441 +
15442 +#include <linux/vserver/cacct_int.h>
15443 +
15444 +
15445 +#define VX_SOCKA_TOP   \
15446 +       "Type\t    recv #/bytes\t\t   send #/bytes\t\t    fail #/bytes\n"
15447 +
15448 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15449 +{
15450 +       int i, j, length = 0;
15451 +       static char *type[VXA_SOCK_SIZE] = {
15452 +               "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15453 +       };
15454 +
15455 +       length += sprintf(buffer + length, VX_SOCKA_TOP);
15456 +       for (i = 0; i < VXA_SOCK_SIZE; i++) {
15457 +               length += sprintf(buffer + length, "%s:", type[i]);
15458 +               for (j = 0; j < 3; j++) {
15459 +                       length += sprintf(buffer + length,
15460 +                               "\t%10lu/%-10lu",
15461 +                               vx_sock_count(cacct, i, j),
15462 +                               vx_sock_total(cacct, i, j));
15463 +               }
15464 +               buffer[length++] = '\n';
15465 +       }
15466 +
15467 +       length += sprintf(buffer + length, "\n");
15468 +       length += sprintf(buffer + length,
15469 +               "slab:\t %8u %8u %8u %8u\n",
15470 +               atomic_read(&cacct->slab[1]),
15471 +               atomic_read(&cacct->slab[4]),
15472 +               atomic_read(&cacct->slab[0]),
15473 +               atomic_read(&cacct->slab[2]));
15474 +
15475 +       length += sprintf(buffer + length, "\n");
15476 +       for (i = 0; i < 5; i++) {
15477 +               length += sprintf(buffer + length,
15478 +                       "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15479 +                       atomic_read(&cacct->page[i][0]),
15480 +                       atomic_read(&cacct->page[i][1]),
15481 +                       atomic_read(&cacct->page[i][2]),
15482 +                       atomic_read(&cacct->page[i][3]),
15483 +                       atomic_read(&cacct->page[i][4]),
15484 +                       atomic_read(&cacct->page[i][5]),
15485 +                       atomic_read(&cacct->page[i][6]),
15486 +                       atomic_read(&cacct->page[i][7]));
15487 +       }
15488 +       return length;
15489 +}
15490 +
15491 +#endif /* _VX_CACCT_PROC_H */
15492 diff -NurpP --minimal linux-3.10.40/kernel/vserver/context.c linux-3.10.40-vs2.3.6.8/kernel/vserver/context.c
15493 --- linux-3.10.40/kernel/vserver/context.c      1970-01-01 00:00:00.000000000 +0000
15494 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/context.c    2013-08-22 20:30:00.000000000 +0000
15495 @@ -0,0 +1,1119 @@
15496 +/*
15497 + *  linux/kernel/vserver/context.c
15498 + *
15499 + *  Virtual Server: Context Support
15500 + *
15501 + *  Copyright (C) 2003-2011  Herbert Pötzl
15502 + *
15503 + *  V0.01  context helper
15504 + *  V0.02  vx_ctx_kill syscall command
15505 + *  V0.03  replaced context_info calls
15506 + *  V0.04  redesign of struct (de)alloc
15507 + *  V0.05  rlimit basic implementation
15508 + *  V0.06  task_xid and info commands
15509 + *  V0.07  context flags and caps
15510 + *  V0.08  switch to RCU based hash
15511 + *  V0.09  revert to non RCU for now
15512 + *  V0.10  and back to working RCU hash
15513 + *  V0.11  and back to locking again
15514 + *  V0.12  referenced context store
15515 + *  V0.13  separate per cpu data
15516 + *  V0.14  changed vcmds to vxi arg
15517 + *  V0.15  added context stat
15518 + *  V0.16  have __create claim() the vxi
15519 + *  V0.17  removed older and legacy stuff
15520 + *  V0.18  added user credentials
15521 + *  V0.19  added warn mask
15522 + *
15523 + */
15524 +
15525 +#include <linux/slab.h>
15526 +#include <linux/types.h>
15527 +#include <linux/security.h>
15528 +#include <linux/pid_namespace.h>
15529 +#include <linux/capability.h>
15530 +
15531 +#include <linux/vserver/context.h>
15532 +#include <linux/vserver/network.h>
15533 +#include <linux/vserver/debug.h>
15534 +#include <linux/vserver/limit.h>
15535 +#include <linux/vserver/limit_int.h>
15536 +#include <linux/vserver/space.h>
15537 +#include <linux/init_task.h>
15538 +#include <linux/fs_struct.h>
15539 +#include <linux/cred.h>
15540 +
15541 +#include <linux/vs_context.h>
15542 +#include <linux/vs_limit.h>
15543 +#include <linux/vs_pid.h>
15544 +#include <linux/vserver/context_cmd.h>
15545 +
15546 +#include "cvirt_init.h"
15547 +#include "cacct_init.h"
15548 +#include "limit_init.h"
15549 +#include "sched_init.h"
15550 +
15551 +
15552 +atomic_t vx_global_ctotal      = ATOMIC_INIT(0);
15553 +atomic_t vx_global_cactive     = ATOMIC_INIT(0);
15554 +
15555 +
15556 +/*     now inactive context structures */
15557 +
15558 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15559 +
15560 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15561 +
15562 +
15563 +/*     __alloc_vx_info()
15564 +
15565 +       * allocate an initialized vx_info struct
15566 +       * doesn't make it visible (hash)                        */
15567 +
15568 +static struct vx_info *__alloc_vx_info(vxid_t xid)
15569 +{
15570 +       struct vx_info *new = NULL;
15571 +       int cpu, index;
15572 +
15573 +       vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15574 +
15575 +       /* would this benefit from a slab cache? */
15576 +       new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15577 +       if (!new)
15578 +               return 0;
15579 +
15580 +       memset(new, 0, sizeof(struct vx_info));
15581 +#ifdef CONFIG_SMP
15582 +       new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15583 +       if (!new->ptr_pc)
15584 +               goto error;
15585 +#endif
15586 +       new->vx_id = xid;
15587 +       INIT_HLIST_NODE(&new->vx_hlist);
15588 +       atomic_set(&new->vx_usecnt, 0);
15589 +       atomic_set(&new->vx_tasks, 0);
15590 +       new->vx_parent = NULL;
15591 +       new->vx_state = 0;
15592 +       init_waitqueue_head(&new->vx_wait);
15593 +
15594 +       /* prepare reaper */
15595 +       get_task_struct(init_pid_ns.child_reaper);
15596 +       new->vx_reaper = init_pid_ns.child_reaper;
15597 +       new->vx_badness_bias = 0;
15598 +
15599 +       /* rest of init goes here */
15600 +       vx_info_init_limit(&new->limit);
15601 +       vx_info_init_sched(&new->sched);
15602 +       vx_info_init_cvirt(&new->cvirt);
15603 +       vx_info_init_cacct(&new->cacct);
15604 +
15605 +       /* per cpu data structures */
15606 +       for_each_possible_cpu(cpu) {
15607 +               vx_info_init_sched_pc(
15608 +                       &vx_per_cpu(new, sched_pc, cpu), cpu);
15609 +               vx_info_init_cvirt_pc(
15610 +                       &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15611 +       }
15612 +
15613 +       new->vx_flags = VXF_INIT_SET;
15614 +       new->vx_bcaps = CAP_FULL_SET;   // maybe ~CAP_SETPCAP
15615 +       new->vx_ccaps = 0;
15616 +       new->vx_umask = 0;
15617 +       new->vx_wmask = 0;
15618 +
15619 +       new->reboot_cmd = 0;
15620 +       new->exit_code = 0;
15621 +
15622 +       // preconfig spaces
15623 +       for (index = 0; index < VX_SPACES; index++) {
15624 +               struct _vx_space *space = &new->space[index];
15625 +
15626 +               // filesystem
15627 +               spin_lock(&init_fs.lock);
15628 +               init_fs.users++;
15629 +               spin_unlock(&init_fs.lock);
15630 +               space->vx_fs = &init_fs;
15631 +
15632 +               /* FIXME: do we want defaults? */
15633 +               // space->vx_real_cred = 0;
15634 +               // space->vx_cred = 0;
15635 +       }
15636 +
15637 +
15638 +       vxdprintk(VXD_CBIT(xid, 0),
15639 +               "alloc_vx_info(%d) = %p", xid, new);
15640 +       vxh_alloc_vx_info(new);
15641 +       atomic_inc(&vx_global_ctotal);
15642 +       return new;
15643 +#ifdef CONFIG_SMP
15644 +error:
15645 +       kfree(new);
15646 +       return 0;
15647 +#endif
15648 +}
15649 +
15650 +/*     __dealloc_vx_info()
15651 +
15652 +       * final disposal of vx_info                             */
15653 +
15654 +static void __dealloc_vx_info(struct vx_info *vxi)
15655 +{
15656 +#ifdef CONFIG_VSERVER_WARN
15657 +       struct vx_info_save vxis;
15658 +       int cpu;
15659 +#endif
15660 +       vxdprintk(VXD_CBIT(xid, 0),
15661 +               "dealloc_vx_info(%p)", vxi);
15662 +       vxh_dealloc_vx_info(vxi);
15663 +
15664 +#ifdef CONFIG_VSERVER_WARN
15665 +       enter_vx_info(vxi, &vxis);
15666 +       vx_info_exit_limit(&vxi->limit);
15667 +       vx_info_exit_sched(&vxi->sched);
15668 +       vx_info_exit_cvirt(&vxi->cvirt);
15669 +       vx_info_exit_cacct(&vxi->cacct);
15670 +
15671 +       for_each_possible_cpu(cpu) {
15672 +               vx_info_exit_sched_pc(
15673 +                       &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15674 +               vx_info_exit_cvirt_pc(
15675 +                       &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15676 +       }
15677 +       leave_vx_info(&vxis);
15678 +#endif
15679 +
15680 +       vxi->vx_id = -1;
15681 +       vxi->vx_state |= VXS_RELEASED;
15682 +
15683 +#ifdef CONFIG_SMP
15684 +       free_percpu(vxi->ptr_pc);
15685 +#endif
15686 +       kfree(vxi);
15687 +       atomic_dec(&vx_global_ctotal);
15688 +}
15689 +
15690 +static void __shutdown_vx_info(struct vx_info *vxi)
15691 +{
15692 +       struct nsproxy *nsproxy;
15693 +       struct fs_struct *fs;
15694 +       struct cred *cred;
15695 +       int index, kill;
15696 +
15697 +       might_sleep();
15698 +
15699 +       vxi->vx_state |= VXS_SHUTDOWN;
15700 +       vs_state_change(vxi, VSC_SHUTDOWN);
15701 +
15702 +       for (index = 0; index < VX_SPACES; index++) {
15703 +               struct _vx_space *space = &vxi->space[index];
15704 +
15705 +               nsproxy = xchg(&space->vx_nsproxy, NULL);
15706 +               if (nsproxy)
15707 +                       put_nsproxy(nsproxy);
15708 +
15709 +               fs = xchg(&space->vx_fs, NULL);
15710 +               spin_lock(&fs->lock);
15711 +               kill = !--fs->users;
15712 +               spin_unlock(&fs->lock);
15713 +               if (kill)
15714 +                       free_fs_struct(fs);
15715 +
15716 +               cred = (struct cred *)xchg(&space->vx_cred, NULL);
15717 +               if (cred)
15718 +                       abort_creds(cred);
15719 +       }
15720 +}
15721 +
15722 +/* exported stuff */
15723 +
15724 +void free_vx_info(struct vx_info *vxi)
15725 +{
15726 +       unsigned long flags;
15727 +       unsigned index;
15728 +
15729 +       /* check for reference counts first */
15730 +       BUG_ON(atomic_read(&vxi->vx_usecnt));
15731 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15732 +
15733 +       /* context must not be hashed */
15734 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15735 +
15736 +       /* context shutdown is mandatory */
15737 +       BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15738 +
15739 +       /* spaces check */
15740 +       for (index = 0; index < VX_SPACES; index++) {
15741 +               struct _vx_space *space = &vxi->space[index];
15742 +
15743 +               BUG_ON(space->vx_nsproxy);
15744 +               BUG_ON(space->vx_fs);
15745 +               // BUG_ON(space->vx_real_cred);
15746 +               // BUG_ON(space->vx_cred);
15747 +       }
15748 +
15749 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15750 +       hlist_del(&vxi->vx_hlist);
15751 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15752 +
15753 +       __dealloc_vx_info(vxi);
15754 +}
15755 +
15756 +
15757 +/*     hash table for vx_info hash */
15758 +
15759 +#define VX_HASH_SIZE   13
15760 +
15761 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15762 +       { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15763 +
15764 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15765 +
15766 +
15767 +static inline unsigned int __hashval(vxid_t xid)
15768 +{
15769 +       return (xid % VX_HASH_SIZE);
15770 +}
15771 +
15772 +
15773 +
15774 +/*     __hash_vx_info()
15775 +
15776 +       * add the vxi to the global hash table
15777 +       * requires the hash_lock to be held                     */
15778 +
15779 +static inline void __hash_vx_info(struct vx_info *vxi)
15780 +{
15781 +       struct hlist_head *head;
15782 +
15783 +       vxd_assert_lock(&vx_info_hash_lock);
15784 +       vxdprintk(VXD_CBIT(xid, 4),
15785 +               "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15786 +       vxh_hash_vx_info(vxi);
15787 +
15788 +       /* context must not be hashed */
15789 +       BUG_ON(vx_info_state(vxi, VXS_HASHED));
15790 +
15791 +       vxi->vx_state |= VXS_HASHED;
15792 +       head = &vx_info_hash[__hashval(vxi->vx_id)];
15793 +       hlist_add_head(&vxi->vx_hlist, head);
15794 +       atomic_inc(&vx_global_cactive);
15795 +}
15796 +
15797 +/*     __unhash_vx_info()
15798 +
15799 +       * remove the vxi from the global hash table
15800 +       * requires the hash_lock to be held                     */
15801 +
15802 +static inline void __unhash_vx_info(struct vx_info *vxi)
15803 +{
15804 +       unsigned long flags;
15805 +
15806 +       vxd_assert_lock(&vx_info_hash_lock);
15807 +       vxdprintk(VXD_CBIT(xid, 4),
15808 +               "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15809 +               atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15810 +       vxh_unhash_vx_info(vxi);
15811 +
15812 +       /* context must be hashed */
15813 +       BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15814 +       /* but without tasks */
15815 +       BUG_ON(atomic_read(&vxi->vx_tasks));
15816 +
15817 +       vxi->vx_state &= ~VXS_HASHED;
15818 +       hlist_del_init(&vxi->vx_hlist);
15819 +       spin_lock_irqsave(&vx_info_inactive_lock, flags);
15820 +       hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15821 +       spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15822 +       atomic_dec(&vx_global_cactive);
15823 +}
15824 +
15825 +
15826 +/*     __lookup_vx_info()
15827 +
15828 +       * requires the hash_lock to be held
15829 +       * doesn't increment the vx_refcnt                       */
15830 +
15831 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
15832 +{
15833 +       struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15834 +       struct hlist_node *pos;
15835 +       struct vx_info *vxi;
15836 +
15837 +       vxd_assert_lock(&vx_info_hash_lock);
15838 +       hlist_for_each(pos, head) {
15839 +               vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15840 +
15841 +               if (vxi->vx_id == xid)
15842 +                       goto found;
15843 +       }
15844 +       vxi = NULL;
15845 +found:
15846 +       vxdprintk(VXD_CBIT(xid, 0),
15847 +               "__lookup_vx_info(#%u): %p[#%u]",
15848 +               xid, vxi, vxi ? vxi->vx_id : 0);
15849 +       vxh_lookup_vx_info(vxi, xid);
15850 +       return vxi;
15851 +}
15852 +
15853 +
15854 +/*     __create_vx_info()
15855 +
15856 +       * create the requested context
15857 +       * get(), claim() and hash it                            */
15858 +
15859 +static struct vx_info *__create_vx_info(int id)
15860 +{
15861 +       struct vx_info *new, *vxi = NULL;
15862 +
15863 +       vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15864 +
15865 +       if (!(new = __alloc_vx_info(id)))
15866 +               return ERR_PTR(-ENOMEM);
15867 +
15868 +       /* required to make dynamic xids unique */
15869 +       spin_lock(&vx_info_hash_lock);
15870 +
15871 +       /* static context requested */
15872 +       if ((vxi = __lookup_vx_info(id))) {
15873 +               vxdprintk(VXD_CBIT(xid, 0),
15874 +                       "create_vx_info(%d) = %p (already there)", id, vxi);
15875 +               if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15876 +                       vxi = ERR_PTR(-EBUSY);
15877 +               else
15878 +                       vxi = ERR_PTR(-EEXIST);
15879 +               goto out_unlock;
15880 +       }
15881 +       /* new context */
15882 +       vxdprintk(VXD_CBIT(xid, 0),
15883 +               "create_vx_info(%d) = %p (new)", id, new);
15884 +       claim_vx_info(new, NULL);
15885 +       __hash_vx_info(get_vx_info(new));
15886 +       vxi = new, new = NULL;
15887 +
15888 +out_unlock:
15889 +       spin_unlock(&vx_info_hash_lock);
15890 +       vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15891 +       if (new)
15892 +               __dealloc_vx_info(new);
15893 +       return vxi;
15894 +}
15895 +
15896 +
15897 +/*     exported stuff                                          */
15898 +
15899 +
15900 +void unhash_vx_info(struct vx_info *vxi)
15901 +{
15902 +       spin_lock(&vx_info_hash_lock);
15903 +       __unhash_vx_info(vxi);
15904 +       spin_unlock(&vx_info_hash_lock);
15905 +       __shutdown_vx_info(vxi);
15906 +       __wakeup_vx_info(vxi);
15907 +}
15908 +
15909 +
15910 +/*     lookup_vx_info()
15911 +
15912 +       * search for a vx_info and get() it
15913 +       * negative id means current                             */
15914 +
15915 +struct vx_info *lookup_vx_info(int id)
15916 +{
15917 +       struct vx_info *vxi = NULL;
15918 +
15919 +       if (id < 0) {
15920 +               vxi = get_vx_info(current_vx_info());
15921 +       } else if (id > 1) {
15922 +               spin_lock(&vx_info_hash_lock);
15923 +               vxi = get_vx_info(__lookup_vx_info(id));
15924 +               spin_unlock(&vx_info_hash_lock);
15925 +       }
15926 +       return vxi;
15927 +}
15928 +
15929 +/*     xid_is_hashed()
15930 +
15931 +       * verify that xid is still hashed                       */
15932 +
15933 +int xid_is_hashed(vxid_t xid)
15934 +{
15935 +       int hashed;
15936 +
15937 +       spin_lock(&vx_info_hash_lock);
15938 +       hashed = (__lookup_vx_info(xid) != NULL);
15939 +       spin_unlock(&vx_info_hash_lock);
15940 +       return hashed;
15941 +}
15942 +
15943 +#ifdef CONFIG_PROC_FS
15944 +
15945 +/*     get_xid_list()
15946 +
15947 +       * get a subset of hashed xids for proc
15948 +       * assumes size is at least one                          */
15949 +
15950 +int get_xid_list(int index, unsigned int *xids, int size)
15951 +{
15952 +       int hindex, nr_xids = 0;
15953 +
15954 +       /* only show current and children */
15955 +       if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15956 +               if (index > 0)
15957 +                       return 0;
15958 +               xids[nr_xids] = vx_current_xid();
15959 +               return 1;
15960 +       }
15961 +
15962 +       for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15963 +               struct hlist_head *head = &vx_info_hash[hindex];
15964 +               struct hlist_node *pos;
15965 +
15966 +               spin_lock(&vx_info_hash_lock);
15967 +               hlist_for_each(pos, head) {
15968 +                       struct vx_info *vxi;
15969 +
15970 +                       if (--index > 0)
15971 +                               continue;
15972 +
15973 +                       vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15974 +                       xids[nr_xids] = vxi->vx_id;
15975 +                       if (++nr_xids >= size) {
15976 +                               spin_unlock(&vx_info_hash_lock);
15977 +                               goto out;
15978 +                       }
15979 +               }
15980 +               /* keep the lock time short */
15981 +               spin_unlock(&vx_info_hash_lock);
15982 +       }
15983 +out:
15984 +       return nr_xids;
15985 +}
15986 +#endif
15987 +
15988 +#ifdef CONFIG_VSERVER_DEBUG
15989 +
15990 +void   dump_vx_info_inactive(int level)
15991 +{
15992 +       struct hlist_node *entry, *next;
15993 +
15994 +       hlist_for_each_safe(entry, next, &vx_info_inactive) {
15995 +               struct vx_info *vxi =
15996 +                       list_entry(entry, struct vx_info, vx_hlist);
15997 +
15998 +               dump_vx_info(vxi, level);
15999 +       }
16000 +}
16001 +
16002 +#endif
16003 +
16004 +#if 0
16005 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16006 +{
16007 +       struct user_struct *new_user, *old_user;
16008 +
16009 +       if (!p || !vxi)
16010 +               BUG();
16011 +
16012 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16013 +               return -EACCES;
16014 +
16015 +       new_user = alloc_uid(vxi->vx_id, p->uid);
16016 +       if (!new_user)
16017 +               return -ENOMEM;
16018 +
16019 +       old_user = p->user;
16020 +       if (new_user != old_user) {
16021 +               atomic_inc(&new_user->processes);
16022 +               atomic_dec(&old_user->processes);
16023 +               p->user = new_user;
16024 +       }
16025 +       free_uid(old_user);
16026 +       return 0;
16027 +}
16028 +#endif
16029 +
16030 +#if 0
16031 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16032 +{
16033 +       // p->cap_effective &= vxi->vx_cap_bset;
16034 +       p->cap_effective =
16035 +               cap_intersect(p->cap_effective, vxi->cap_bset);
16036 +       // p->cap_inheritable &= vxi->vx_cap_bset;
16037 +       p->cap_inheritable =
16038 +               cap_intersect(p->cap_inheritable, vxi->cap_bset);
16039 +       // p->cap_permitted &= vxi->vx_cap_bset;
16040 +       p->cap_permitted =
16041 +               cap_intersect(p->cap_permitted, vxi->cap_bset);
16042 +}
16043 +#endif
16044 +
16045 +
16046 +#include <linux/file.h>
16047 +#include <linux/fdtable.h>
16048 +
16049 +static int vx_openfd_task(struct task_struct *tsk)
16050 +{
16051 +       struct files_struct *files = tsk->files;
16052 +       struct fdtable *fdt;
16053 +       const unsigned long *bptr;
16054 +       int count, total;
16055 +
16056 +       /* no rcu_read_lock() because of spin_lock() */
16057 +       spin_lock(&files->file_lock);
16058 +       fdt = files_fdtable(files);
16059 +       bptr = fdt->open_fds;
16060 +       count = fdt->max_fds / (sizeof(unsigned long) * 8);
16061 +       for (total = 0; count > 0; count--) {
16062 +               if (*bptr)
16063 +                       total += hweight_long(*bptr);
16064 +               bptr++;
16065 +       }
16066 +       spin_unlock(&files->file_lock);
16067 +       return total;
16068 +}
16069 +
16070 +
16071 +/*     for *space compatibility */
16072 +
16073 +asmlinkage long sys_unshare(unsigned long);
16074 +
16075 +/*
16076 + *     migrate task to new context
16077 + *     gets vxi, puts old_vxi on change
16078 + *     optionally unshares namespaces (hack)
16079 + */
16080 +
16081 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16082 +{
16083 +       struct vx_info *old_vxi;
16084 +       int ret = 0;
16085 +
16086 +       if (!p || !vxi)
16087 +               BUG();
16088 +
16089 +       vxdprintk(VXD_CBIT(xid, 5),
16090 +               "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16091 +               vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16092 +
16093 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16094 +               !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16095 +               return -EACCES;
16096 +
16097 +       if (vx_info_state(vxi, VXS_SHUTDOWN))
16098 +               return -EFAULT;
16099 +
16100 +       old_vxi = task_get_vx_info(p);
16101 +       if (old_vxi == vxi)
16102 +               goto out;
16103 +
16104 +//     if (!(ret = vx_migrate_user(p, vxi))) {
16105 +       {
16106 +               int openfd;
16107 +
16108 +               task_lock(p);
16109 +               openfd = vx_openfd_task(p);
16110 +
16111 +               if (old_vxi) {
16112 +                       atomic_dec(&old_vxi->cvirt.nr_threads);
16113 +                       atomic_dec(&old_vxi->cvirt.nr_running);
16114 +                       __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16115 +                       /* FIXME: what about the struct files here? */
16116 +                       __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16117 +                       /* account for the executable */
16118 +                       __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16119 +               }
16120 +               atomic_inc(&vxi->cvirt.nr_threads);
16121 +               atomic_inc(&vxi->cvirt.nr_running);
16122 +               __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16123 +               /* FIXME: what about the struct files here? */
16124 +               __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16125 +               /* account for the executable */
16126 +               __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16127 +
16128 +               if (old_vxi) {
16129 +                       release_vx_info(old_vxi, p);
16130 +                       clr_vx_info(&p->vx_info);
16131 +               }
16132 +               claim_vx_info(vxi, p);
16133 +               set_vx_info(&p->vx_info, vxi);
16134 +               p->xid = vxi->vx_id;
16135 +
16136 +               vxdprintk(VXD_CBIT(xid, 5),
16137 +                       "moved task %p into vxi:%p[#%d]",
16138 +                       p, vxi, vxi->vx_id);
16139 +
16140 +               // vx_mask_cap_bset(vxi, p);
16141 +               task_unlock(p);
16142 +
16143 +               /* hack for *spaces to provide compatibility */
16144 +               if (unshare) {
16145 +                       struct nsproxy *old_nsp, *new_nsp;
16146 +
16147 +                       ret = unshare_nsproxy_namespaces(
16148 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16149 +                               &new_nsp, NULL, NULL);
16150 +                       if (ret)
16151 +                               goto out;
16152 +
16153 +                       old_nsp = xchg(&p->nsproxy, new_nsp);
16154 +                       vx_set_space(vxi,
16155 +                               CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16156 +                       put_nsproxy(old_nsp);
16157 +               }
16158 +       }
16159 +out:
16160 +       put_vx_info(old_vxi);
16161 +       return ret;
16162 +}
16163 +
16164 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16165 +{
16166 +       struct task_struct *old_reaper;
16167 +       struct vx_info *reaper_vxi;
16168 +
16169 +       if (!vxi)
16170 +               return -EINVAL;
16171 +
16172 +       vxdprintk(VXD_CBIT(xid, 6),
16173 +               "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16174 +               vxi, vxi->vx_id, p, p->xid, p->pid);
16175 +
16176 +       old_reaper = vxi->vx_reaper;
16177 +       if (old_reaper == p)
16178 +               return 0;
16179 +
16180 +       reaper_vxi = task_get_vx_info(p);
16181 +       if (reaper_vxi && reaper_vxi != vxi) {
16182 +               vxwprintk(1,
16183 +                       "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16184 +                       "for [xid #%u]",
16185 +                       p->comm, p->pid, p->xid, vx_current_xid());
16186 +               goto out;
16187 +       }
16188 +
16189 +       /* set new child reaper */
16190 +       get_task_struct(p);
16191 +       vxi->vx_reaper = p;
16192 +       put_task_struct(old_reaper);
16193 +out:
16194 +       put_vx_info(reaper_vxi);
16195 +       return 0;
16196 +}
16197 +
16198 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16199 +{
16200 +       if (!vxi)
16201 +               return -EINVAL;
16202 +
16203 +       vxdprintk(VXD_CBIT(xid, 6),
16204 +               "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16205 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16206 +
16207 +       vxi->vx_flags &= ~VXF_STATE_INIT;
16208 +       // vxi->vx_initpid = p->tgid;
16209 +       vxi->vx_initpid = p->pid;
16210 +       return 0;
16211 +}
16212 +
16213 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16214 +{
16215 +       vxdprintk(VXD_CBIT(xid, 6),
16216 +               "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16217 +               vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16218 +
16219 +       vxi->exit_code = code;
16220 +       vxi->vx_initpid = 0;
16221 +}
16222 +
16223 +
16224 +void vx_set_persistent(struct vx_info *vxi)
16225 +{
16226 +       vxdprintk(VXD_CBIT(xid, 6),
16227 +               "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16228 +
16229 +       get_vx_info(vxi);
16230 +       claim_vx_info(vxi, NULL);
16231 +}
16232 +
16233 +void vx_clear_persistent(struct vx_info *vxi)
16234 +{
16235 +       vxdprintk(VXD_CBIT(xid, 6),
16236 +               "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16237 +
16238 +       release_vx_info(vxi, NULL);
16239 +       put_vx_info(vxi);
16240 +}
16241 +
16242 +void vx_update_persistent(struct vx_info *vxi)
16243 +{
16244 +       if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16245 +               vx_set_persistent(vxi);
16246 +       else
16247 +               vx_clear_persistent(vxi);
16248 +}
16249 +
16250 +
16251 +/*     task must be current or locked          */
16252 +
16253 +void   exit_vx_info(struct task_struct *p, int code)
16254 +{
16255 +       struct vx_info *vxi = p->vx_info;
16256 +
16257 +       if (vxi) {
16258 +               atomic_dec(&vxi->cvirt.nr_threads);
16259 +               vx_nproc_dec(p);
16260 +
16261 +               vxi->exit_code = code;
16262 +               release_vx_info(vxi, p);
16263 +       }
16264 +}
16265 +
16266 +void   exit_vx_info_early(struct task_struct *p, int code)
16267 +{
16268 +       struct vx_info *vxi = p->vx_info;
16269 +
16270 +       if (vxi) {
16271 +               if (vxi->vx_initpid == p->pid)
16272 +                       vx_exit_init(vxi, p, code);
16273 +               if (vxi->vx_reaper == p)
16274 +                       vx_set_reaper(vxi, init_pid_ns.child_reaper);
16275 +       }
16276 +}
16277 +
16278 +
16279 +/* vserver syscall commands below here */
16280 +
16281 +/* taks xid and vx_info functions */
16282 +
16283 +#include <asm/uaccess.h>
16284 +
16285 +
16286 +int vc_task_xid(uint32_t id)
16287 +{
16288 +       vxid_t xid;
16289 +
16290 +       if (id) {
16291 +               struct task_struct *tsk;
16292 +
16293 +               rcu_read_lock();
16294 +               tsk = find_task_by_real_pid(id);
16295 +               xid = (tsk) ? tsk->xid : -ESRCH;
16296 +               rcu_read_unlock();
16297 +       } else
16298 +               xid = vx_current_xid();
16299 +       return xid;
16300 +}
16301 +
16302 +
16303 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16304 +{
16305 +       struct vcmd_vx_info_v0 vc_data;
16306 +
16307 +       vc_data.xid = vxi->vx_id;
16308 +       vc_data.initpid = vxi->vx_initpid;
16309 +
16310 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16311 +               return -EFAULT;
16312 +       return 0;
16313 +}
16314 +
16315 +
16316 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16317 +{
16318 +       struct vcmd_ctx_stat_v0 vc_data;
16319 +
16320 +       vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16321 +       vc_data.tasks = atomic_read(&vxi->vx_tasks);
16322 +
16323 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16324 +               return -EFAULT;
16325 +       return 0;
16326 +}
16327 +
16328 +
16329 +/* context functions */
16330 +
16331 +int vc_ctx_create(uint32_t xid, void __user *data)
16332 +{
16333 +       struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16334 +       struct vx_info *new_vxi;
16335 +       int ret;
16336 +
16337 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16338 +               return -EFAULT;
16339 +
16340 +       if ((xid > MAX_S_CONTEXT) || (xid < 2))
16341 +               return -EINVAL;
16342 +
16343 +       new_vxi = __create_vx_info(xid);
16344 +       if (IS_ERR(new_vxi))
16345 +               return PTR_ERR(new_vxi);
16346 +
16347 +       /* initial flags */
16348 +       new_vxi->vx_flags = vc_data.flagword;
16349 +
16350 +       ret = -ENOEXEC;
16351 +       if (vs_state_change(new_vxi, VSC_STARTUP))
16352 +               goto out;
16353 +
16354 +       ret = vx_migrate_task(current, new_vxi, (!data));
16355 +       if (ret)
16356 +               goto out;
16357 +
16358 +       /* return context id on success */
16359 +       ret = new_vxi->vx_id;
16360 +
16361 +       /* get a reference for persistent contexts */
16362 +       if ((vc_data.flagword & VXF_PERSISTENT))
16363 +               vx_set_persistent(new_vxi);
16364 +out:
16365 +       release_vx_info(new_vxi, NULL);
16366 +       put_vx_info(new_vxi);
16367 +       return ret;
16368 +}
16369 +
16370 +
16371 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16372 +{
16373 +       struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16374 +       int ret;
16375 +
16376 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16377 +               return -EFAULT;
16378 +
16379 +       ret = vx_migrate_task(current, vxi, 0);
16380 +       if (ret)
16381 +               return ret;
16382 +       if (vc_data.flagword & VXM_SET_INIT)
16383 +               ret = vx_set_init(vxi, current);
16384 +       if (ret)
16385 +               return ret;
16386 +       if (vc_data.flagword & VXM_SET_REAPER)
16387 +               ret = vx_set_reaper(vxi, current);
16388 +       return ret;
16389 +}
16390 +
16391 +
16392 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16393 +{
16394 +       struct vcmd_ctx_flags_v0 vc_data;
16395 +
16396 +       vc_data.flagword = vxi->vx_flags;
16397 +
16398 +       /* special STATE flag handling */
16399 +       vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16400 +
16401 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16402 +               return -EFAULT;
16403 +       return 0;
16404 +}
16405 +
16406 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16407 +{
16408 +       struct vcmd_ctx_flags_v0 vc_data;
16409 +       uint64_t mask, trigger;
16410 +
16411 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16412 +               return -EFAULT;
16413 +
16414 +       /* special STATE flag handling */
16415 +       mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16416 +       trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16417 +
16418 +       if (vxi == current_vx_info()) {
16419 +               /* if (trigger & VXF_STATE_SETUP)
16420 +                       vx_mask_cap_bset(vxi, current); */
16421 +               if (trigger & VXF_STATE_INIT) {
16422 +                       int ret;
16423 +
16424 +                       ret = vx_set_init(vxi, current);
16425 +                       if (ret)
16426 +                               return ret;
16427 +                       ret = vx_set_reaper(vxi, current);
16428 +                       if (ret)
16429 +                               return ret;
16430 +               }
16431 +       }
16432 +
16433 +       vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16434 +               vc_data.flagword, mask);
16435 +       if (trigger & VXF_PERSISTENT)
16436 +               vx_update_persistent(vxi);
16437 +
16438 +       return 0;
16439 +}
16440 +
16441 +
16442 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16443 +{
16444 +       uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16445 +
16446 +       // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16447 +       return v;
16448 +}
16449 +
16450 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16451 +{
16452 +       kernel_cap_t c = __cap_empty_set;
16453 +
16454 +       c.cap[0] = v & 0xFFFFFFFF;
16455 +       c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16456 +
16457 +       // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16458 +       return c;
16459 +}
16460 +
16461 +
16462 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16463 +{
16464 +       if (bcaps)
16465 +               *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16466 +       if (ccaps)
16467 +               *ccaps = vxi->vx_ccaps;
16468 +
16469 +       return 0;
16470 +}
16471 +
16472 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16473 +{
16474 +       struct vcmd_ctx_caps_v1 vc_data;
16475 +       int ret;
16476 +
16477 +       ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16478 +       if (ret)
16479 +               return ret;
16480 +       vc_data.cmask = ~0ULL;
16481 +
16482 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16483 +               return -EFAULT;
16484 +       return 0;
16485 +}
16486 +
16487 +static int do_set_caps(struct vx_info *vxi,
16488 +       uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16489 +{
16490 +       uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16491 +
16492 +#if 0
16493 +       printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16494 +               bcaps, bmask, ccaps, cmask);
16495 +#endif
16496 +       vxi->vx_bcaps = cap_t_from_caps(
16497 +               vs_mask_flags(bcold, bcaps, bmask));
16498 +       vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16499 +
16500 +       return 0;
16501 +}
16502 +
16503 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16504 +{
16505 +       struct vcmd_ctx_caps_v1 vc_data;
16506 +
16507 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16508 +               return -EFAULT;
16509 +
16510 +       return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16511 +}
16512 +
16513 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16514 +{
16515 +       struct vcmd_bcaps vc_data;
16516 +       int ret;
16517 +
16518 +       ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16519 +       if (ret)
16520 +               return ret;
16521 +       vc_data.bmask = ~0ULL;
16522 +
16523 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16524 +               return -EFAULT;
16525 +       return 0;
16526 +}
16527 +
16528 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16529 +{
16530 +       struct vcmd_bcaps vc_data;
16531 +
16532 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16533 +               return -EFAULT;
16534 +
16535 +       return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16536 +}
16537 +
16538 +
16539 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16540 +{
16541 +       struct vcmd_umask vc_data;
16542 +
16543 +       vc_data.umask = vxi->vx_umask;
16544 +       vc_data.mask = ~0ULL;
16545 +
16546 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16547 +               return -EFAULT;
16548 +       return 0;
16549 +}
16550 +
16551 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16552 +{
16553 +       struct vcmd_umask vc_data;
16554 +
16555 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16556 +               return -EFAULT;
16557 +
16558 +       vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16559 +               vc_data.umask, vc_data.mask);
16560 +       return 0;
16561 +}
16562 +
16563 +
16564 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16565 +{
16566 +       struct vcmd_wmask vc_data;
16567 +
16568 +       vc_data.wmask = vxi->vx_wmask;
16569 +       vc_data.mask = ~0ULL;
16570 +
16571 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16572 +               return -EFAULT;
16573 +       return 0;
16574 +}
16575 +
16576 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16577 +{
16578 +       struct vcmd_wmask vc_data;
16579 +
16580 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16581 +               return -EFAULT;
16582 +
16583 +       vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16584 +               vc_data.wmask, vc_data.mask);
16585 +       return 0;
16586 +}
16587 +
16588 +
16589 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16590 +{
16591 +       struct vcmd_badness_v0 vc_data;
16592 +
16593 +       vc_data.bias = vxi->vx_badness_bias;
16594 +
16595 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16596 +               return -EFAULT;
16597 +       return 0;
16598 +}
16599 +
16600 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16601 +{
16602 +       struct vcmd_badness_v0 vc_data;
16603 +
16604 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16605 +               return -EFAULT;
16606 +
16607 +       vxi->vx_badness_bias = vc_data.bias;
16608 +       return 0;
16609 +}
16610 +
16611 +#include <linux/module.h>
16612 +
16613 +EXPORT_SYMBOL_GPL(free_vx_info);
16614 +
16615 diff -NurpP --minimal linux-3.10.40/kernel/vserver/cvirt.c linux-3.10.40-vs2.3.6.8/kernel/vserver/cvirt.c
16616 --- linux-3.10.40/kernel/vserver/cvirt.c        1970-01-01 00:00:00.000000000 +0000
16617 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/cvirt.c      2013-08-22 20:30:00.000000000 +0000
16618 @@ -0,0 +1,313 @@
16619 +/*
16620 + *  linux/kernel/vserver/cvirt.c
16621 + *
16622 + *  Virtual Server: Context Virtualization
16623 + *
16624 + *  Copyright (C) 2004-2007  Herbert Pötzl
16625 + *
16626 + *  V0.01  broken out from limit.c
16627 + *  V0.02  added utsname stuff
16628 + *  V0.03  changed vcmds to vxi arg
16629 + *
16630 + */
16631 +
16632 +#include <linux/types.h>
16633 +#include <linux/utsname.h>
16634 +#include <linux/vs_cvirt.h>
16635 +#include <linux/vserver/switch.h>
16636 +#include <linux/vserver/cvirt_cmd.h>
16637 +
16638 +#include <asm/uaccess.h>
16639 +
16640 +
16641 +void vx_vsi_boottime(struct timespec *boottime)
16642 +{
16643 +       struct vx_info *vxi = current_vx_info();
16644 +
16645 +       set_normalized_timespec(boottime,
16646 +               boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16647 +               boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16648 +       return;
16649 +}
16650 +
16651 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16652 +{
16653 +       struct vx_info *vxi = current_vx_info();
16654 +
16655 +       set_normalized_timespec(uptime,
16656 +               uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16657 +               uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16658 +       if (!idle)
16659 +               return;
16660 +       set_normalized_timespec(idle,
16661 +               idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16662 +               idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16663 +       return;
16664 +}
16665 +
16666 +uint64_t vx_idle_jiffies(void)
16667 +{
16668 +       return init_task.utime + init_task.stime;
16669 +}
16670 +
16671 +
16672 +
16673 +static inline uint32_t __update_loadavg(uint32_t load,
16674 +       int wsize, int delta, int n)
16675 +{
16676 +       unsigned long long calc, prev;
16677 +
16678 +       /* just set it to n */
16679 +       if (unlikely(delta >= wsize))
16680 +               return (n << FSHIFT);
16681 +
16682 +       calc = delta * n;
16683 +       calc <<= FSHIFT;
16684 +       prev = (wsize - delta);
16685 +       prev *= load;
16686 +       calc += prev;
16687 +       do_div(calc, wsize);
16688 +       return calc;
16689 +}
16690 +
16691 +
16692 +void vx_update_load(struct vx_info *vxi)
16693 +{
16694 +       uint32_t now, last, delta;
16695 +       unsigned int nr_running, nr_uninterruptible;
16696 +       unsigned int total;
16697 +       unsigned long flags;
16698 +
16699 +       spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16700 +
16701 +       now = jiffies;
16702 +       last = vxi->cvirt.load_last;
16703 +       delta = now - last;
16704 +
16705 +       if (delta < 5*HZ)
16706 +               goto out;
16707 +
16708 +       nr_running = atomic_read(&vxi->cvirt.nr_running);
16709 +       nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16710 +       total = nr_running + nr_uninterruptible;
16711 +
16712 +       vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16713 +               60*HZ, delta, total);
16714 +       vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16715 +               5*60*HZ, delta, total);
16716 +       vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16717 +               15*60*HZ, delta, total);
16718 +
16719 +       vxi->cvirt.load_last = now;
16720 +out:
16721 +       atomic_inc(&vxi->cvirt.load_updates);
16722 +       spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16723 +}
16724 +
16725 +
16726 +/*
16727 + * Commands to do_syslog:
16728 + *
16729 + *      0 -- Close the log.  Currently a NOP.
16730 + *      1 -- Open the log. Currently a NOP.
16731 + *      2 -- Read from the log.
16732 + *      3 -- Read all messages remaining in the ring buffer.
16733 + *      4 -- Read and clear all messages remaining in the ring buffer
16734 + *      5 -- Clear ring buffer.
16735 + *      6 -- Disable printk's to console
16736 + *      7 -- Enable printk's to console
16737 + *      8 -- Set level of messages printed to console
16738 + *      9 -- Return number of unread characters in the log buffer
16739 + *     10 -- Return size of the log buffer
16740 + */
16741 +int vx_do_syslog(int type, char __user *buf, int len)
16742 +{
16743 +       int error = 0;
16744 +       int do_clear = 0;
16745 +       struct vx_info *vxi = current_vx_info();
16746 +       struct _vx_syslog *log;
16747 +
16748 +       if (!vxi)
16749 +               return -EINVAL;
16750 +       log = &vxi->cvirt.syslog;
16751 +
16752 +       switch (type) {
16753 +       case 0:         /* Close log */
16754 +       case 1:         /* Open log */
16755 +               break;
16756 +       case 2:         /* Read from log */
16757 +               error = wait_event_interruptible(log->log_wait,
16758 +                       (log->log_start - log->log_end));
16759 +               if (error)
16760 +                       break;
16761 +               spin_lock_irq(&log->logbuf_lock);
16762 +               spin_unlock_irq(&log->logbuf_lock);
16763 +               break;
16764 +       case 4:         /* Read/clear last kernel messages */
16765 +               do_clear = 1;
16766 +               /* fall through */
16767 +       case 3:         /* Read last kernel messages */
16768 +               return 0;
16769 +
16770 +       case 5:         /* Clear ring buffer */
16771 +               return 0;
16772 +
16773 +       case 6:         /* Disable logging to console */
16774 +       case 7:         /* Enable logging to console */
16775 +       case 8:         /* Set level of messages printed to console */
16776 +               break;
16777 +
16778 +       case 9:         /* Number of chars in the log buffer */
16779 +               return 0;
16780 +       case 10:        /* Size of the log buffer */
16781 +               return 0;
16782 +       default:
16783 +               error = -EINVAL;
16784 +               break;
16785 +       }
16786 +       return error;
16787 +}
16788 +
16789 +
16790 +/* virtual host info names */
16791 +
16792 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16793 +{
16794 +       struct nsproxy *nsproxy;
16795 +       struct uts_namespace *uts;
16796 +
16797 +       if (id == VHIN_CONTEXT)
16798 +               return vxi->vx_name;
16799 +
16800 +       nsproxy = vxi->space[0].vx_nsproxy;
16801 +       if (!nsproxy)
16802 +               return NULL;
16803 +
16804 +       uts = nsproxy->uts_ns;
16805 +       if (!uts)
16806 +               return NULL;
16807 +
16808 +       switch (id) {
16809 +       case VHIN_SYSNAME:
16810 +               return uts->name.sysname;
16811 +       case VHIN_NODENAME:
16812 +               return uts->name.nodename;
16813 +       case VHIN_RELEASE:
16814 +               return uts->name.release;
16815 +       case VHIN_VERSION:
16816 +               return uts->name.version;
16817 +       case VHIN_MACHINE:
16818 +               return uts->name.machine;
16819 +       case VHIN_DOMAINNAME:
16820 +               return uts->name.domainname;
16821 +       default:
16822 +               return NULL;
16823 +       }
16824 +       return NULL;
16825 +}
16826 +
16827 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16828 +{
16829 +       struct vcmd_vhi_name_v0 vc_data;
16830 +       char *name;
16831 +
16832 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16833 +               return -EFAULT;
16834 +
16835 +       name = vx_vhi_name(vxi, vc_data.field);
16836 +       if (!name)
16837 +               return -EINVAL;
16838 +
16839 +       memcpy(name, vc_data.name, 65);
16840 +       return 0;
16841 +}
16842 +
16843 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16844 +{
16845 +       struct vcmd_vhi_name_v0 vc_data;
16846 +       char *name;
16847 +
16848 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16849 +               return -EFAULT;
16850 +
16851 +       name = vx_vhi_name(vxi, vc_data.field);
16852 +       if (!name)
16853 +               return -EINVAL;
16854 +
16855 +       memcpy(vc_data.name, name, 65);
16856 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16857 +               return -EFAULT;
16858 +       return 0;
16859 +}
16860 +
16861 +
16862 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16863 +{
16864 +       struct vcmd_virt_stat_v0 vc_data;
16865 +       struct _vx_cvirt *cvirt = &vxi->cvirt;
16866 +       struct timespec uptime;
16867 +
16868 +       do_posix_clock_monotonic_gettime(&uptime);
16869 +       set_normalized_timespec(&uptime,
16870 +               uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16871 +               uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16872 +
16873 +       vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16874 +       vc_data.uptime = timespec_to_ns(&uptime);
16875 +       vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16876 +       vc_data.nr_running = atomic_read(&cvirt->nr_running);
16877 +       vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16878 +       vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16879 +       vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16880 +       vc_data.load[0] = cvirt->load[0];
16881 +       vc_data.load[1] = cvirt->load[1];
16882 +       vc_data.load[2] = cvirt->load[2];
16883 +
16884 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16885 +               return -EFAULT;
16886 +       return 0;
16887 +}
16888 +
16889 +
16890 +#ifdef CONFIG_VSERVER_VTIME
16891 +
16892 +/* virtualized time base */
16893 +
16894 +void vx_adjust_timespec(struct timespec *ts)
16895 +{
16896 +       struct vx_info *vxi;
16897 +
16898 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16899 +               return;
16900 +
16901 +       vxi = current_vx_info();
16902 +       ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16903 +       ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16904 +
16905 +       if (ts->tv_nsec >= NSEC_PER_SEC) {
16906 +               ts->tv_sec++;
16907 +               ts->tv_nsec -= NSEC_PER_SEC;
16908 +       } else if (ts->tv_nsec < 0) {
16909 +               ts->tv_sec--;
16910 +               ts->tv_nsec += NSEC_PER_SEC;
16911 +       }
16912 +}
16913 +
16914 +int vx_settimeofday(const struct timespec *ts)
16915 +{
16916 +       struct timespec ats, delta;
16917 +       struct vx_info *vxi;
16918 +
16919 +       if (!vx_flags(VXF_VIRT_TIME, 0))
16920 +               return do_settimeofday(ts);
16921 +
16922 +       getnstimeofday(&ats);
16923 +       delta = timespec_sub(*ts, ats);
16924 +
16925 +       vxi = current_vx_info();
16926 +       vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16927 +       return 0;
16928 +}
16929 +
16930 +#endif
16931 +
16932 diff -NurpP --minimal linux-3.10.40/kernel/vserver/cvirt_init.h linux-3.10.40-vs2.3.6.8/kernel/vserver/cvirt_init.h
16933 --- linux-3.10.40/kernel/vserver/cvirt_init.h   1970-01-01 00:00:00.000000000 +0000
16934 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/cvirt_init.h 2013-08-22 20:30:00.000000000 +0000
16935 @@ -0,0 +1,70 @@
16936 +
16937 +
16938 +extern uint64_t vx_idle_jiffies(void);
16939 +
16940 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16941 +{
16942 +       uint64_t idle_jiffies = vx_idle_jiffies();
16943 +       uint64_t nsuptime;
16944 +
16945 +       do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16946 +       nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16947 +               * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16948 +       cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16949 +       cvirt->bias_ts.tv_sec = 0;
16950 +       cvirt->bias_ts.tv_nsec = 0;
16951 +
16952 +       jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16953 +       atomic_set(&cvirt->nr_threads, 0);
16954 +       atomic_set(&cvirt->nr_running, 0);
16955 +       atomic_set(&cvirt->nr_uninterruptible, 0);
16956 +       atomic_set(&cvirt->nr_onhold, 0);
16957 +
16958 +       spin_lock_init(&cvirt->load_lock);
16959 +       cvirt->load_last = jiffies;
16960 +       atomic_set(&cvirt->load_updates, 0);
16961 +       cvirt->load[0] = 0;
16962 +       cvirt->load[1] = 0;
16963 +       cvirt->load[2] = 0;
16964 +       atomic_set(&cvirt->total_forks, 0);
16965 +
16966 +       spin_lock_init(&cvirt->syslog.logbuf_lock);
16967 +       init_waitqueue_head(&cvirt->syslog.log_wait);
16968 +       cvirt->syslog.log_start = 0;
16969 +       cvirt->syslog.log_end = 0;
16970 +       cvirt->syslog.con_start = 0;
16971 +       cvirt->syslog.logged_chars = 0;
16972 +}
16973 +
16974 +static inline
16975 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16976 +{
16977 +       // cvirt_pc->cpustat = { 0 };
16978 +}
16979 +
16980 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16981 +{
16982 +#ifdef CONFIG_VSERVER_WARN
16983 +       int value;
16984 +#endif
16985 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16986 +               "!!! cvirt: %p[nr_threads] = %d on exit.",
16987 +               cvirt, value);
16988 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16989 +               "!!! cvirt: %p[nr_running] = %d on exit.",
16990 +               cvirt, value);
16991 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16992 +               "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16993 +               cvirt, value);
16994 +       vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16995 +               "!!! cvirt: %p[nr_onhold] = %d on exit.",
16996 +               cvirt, value);
16997 +       return;
16998 +}
16999 +
17000 +static inline
17001 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17002 +{
17003 +       return;
17004 +}
17005 +
17006 diff -NurpP --minimal linux-3.10.40/kernel/vserver/cvirt_proc.h linux-3.10.40-vs2.3.6.8/kernel/vserver/cvirt_proc.h
17007 --- linux-3.10.40/kernel/vserver/cvirt_proc.h   1970-01-01 00:00:00.000000000 +0000
17008 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/cvirt_proc.h 2013-08-22 20:30:00.000000000 +0000
17009 @@ -0,0 +1,123 @@
17010 +#ifndef _VX_CVIRT_PROC_H
17011 +#define _VX_CVIRT_PROC_H
17012 +
17013 +#include <linux/nsproxy.h>
17014 +#include <linux/mnt_namespace.h>
17015 +#include <linux/ipc_namespace.h>
17016 +#include <linux/utsname.h>
17017 +#include <linux/ipc.h>
17018 +
17019 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17020 +
17021 +static inline
17022 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17023 +{
17024 +       struct mnt_namespace *ns;
17025 +       struct uts_namespace *uts;
17026 +       struct ipc_namespace *ipc;
17027 +       int length = 0;
17028 +
17029 +       if (!nsproxy)
17030 +               goto out;
17031 +
17032 +       length += sprintf(buffer + length,
17033 +               "NSProxy:\t%p [%p,%p,%p]\n",
17034 +               nsproxy, nsproxy->mnt_ns,
17035 +               nsproxy->uts_ns, nsproxy->ipc_ns);
17036 +
17037 +       ns = nsproxy->mnt_ns;
17038 +       if (!ns)
17039 +               goto skip_ns;
17040 +
17041 +       length += vx_info_mnt_namespace(ns, buffer + length);
17042 +
17043 +skip_ns:
17044 +
17045 +       uts = nsproxy->uts_ns;
17046 +       if (!uts)
17047 +               goto skip_uts;
17048 +
17049 +       length += sprintf(buffer + length,
17050 +               "SysName:\t%.*s\n"
17051 +               "NodeName:\t%.*s\n"
17052 +               "Release:\t%.*s\n"
17053 +               "Version:\t%.*s\n"
17054 +               "Machine:\t%.*s\n"
17055 +               "DomainName:\t%.*s\n",
17056 +               __NEW_UTS_LEN, uts->name.sysname,
17057 +               __NEW_UTS_LEN, uts->name.nodename,
17058 +               __NEW_UTS_LEN, uts->name.release,
17059 +               __NEW_UTS_LEN, uts->name.version,
17060 +               __NEW_UTS_LEN, uts->name.machine,
17061 +               __NEW_UTS_LEN, uts->name.domainname);
17062 +skip_uts:
17063 +
17064 +       ipc = nsproxy->ipc_ns;
17065 +       if (!ipc)
17066 +               goto skip_ipc;
17067 +
17068 +       length += sprintf(buffer + length,
17069 +               "SEMS:\t\t%d %d %d %d  %d\n"
17070 +               "MSG:\t\t%d %d %d\n"
17071 +               "SHM:\t\t%lu %lu  %d %ld\n",
17072 +               ipc->sem_ctls[0], ipc->sem_ctls[1],
17073 +               ipc->sem_ctls[2], ipc->sem_ctls[3],
17074 +               ipc->used_sems,
17075 +               ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17076 +               (unsigned long)ipc->shm_ctlmax,
17077 +               (unsigned long)ipc->shm_ctlall,
17078 +               ipc->shm_ctlmni, ipc->shm_tot);
17079 +skip_ipc:
17080 +out:
17081 +       return length;
17082 +}
17083 +
17084 +
17085 +#include <linux/sched.h>
17086 +
17087 +#define LOAD_INT(x) ((x) >> FSHIFT)
17088 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17089 +
17090 +static inline
17091 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17092 +{
17093 +       int length = 0;
17094 +       int a, b, c;
17095 +
17096 +       length += sprintf(buffer + length,
17097 +               "BiasUptime:\t%lu.%02lu\n",
17098 +               (unsigned long)cvirt->bias_uptime.tv_sec,
17099 +               (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17100 +
17101 +       a = cvirt->load[0] + (FIXED_1 / 200);
17102 +       b = cvirt->load[1] + (FIXED_1 / 200);
17103 +       c = cvirt->load[2] + (FIXED_1 / 200);
17104 +       length += sprintf(buffer + length,
17105 +               "nr_threads:\t%d\n"
17106 +               "nr_running:\t%d\n"
17107 +               "nr_unintr:\t%d\n"
17108 +               "nr_onhold:\t%d\n"
17109 +               "load_updates:\t%d\n"
17110 +               "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17111 +               "total_forks:\t%d\n",
17112 +               atomic_read(&cvirt->nr_threads),
17113 +               atomic_read(&cvirt->nr_running),
17114 +               atomic_read(&cvirt->nr_uninterruptible),
17115 +               atomic_read(&cvirt->nr_onhold),
17116 +               atomic_read(&cvirt->load_updates),
17117 +               LOAD_INT(a), LOAD_FRAC(a),
17118 +               LOAD_INT(b), LOAD_FRAC(b),
17119 +               LOAD_INT(c), LOAD_FRAC(c),
17120 +               atomic_read(&cvirt->total_forks));
17121 +       return length;
17122 +}
17123 +
17124 +static inline
17125 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17126 +       char *buffer, int cpu)
17127 +{
17128 +       int length = 0;
17129 +       return length;
17130 +}
17131 +
17132 +#endif /* _VX_CVIRT_PROC_H */
17133 diff -NurpP --minimal linux-3.10.40/kernel/vserver/debug.c linux-3.10.40-vs2.3.6.8/kernel/vserver/debug.c
17134 --- linux-3.10.40/kernel/vserver/debug.c        1970-01-01 00:00:00.000000000 +0000
17135 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/debug.c      2013-08-22 20:30:00.000000000 +0000
17136 @@ -0,0 +1,32 @@
17137 +/*
17138 + *  kernel/vserver/debug.c
17139 + *
17140 + *  Copyright (C) 2005-2007 Herbert Pötzl
17141 + *
17142 + *  V0.01  vx_info dump support
17143 + *
17144 + */
17145 +
17146 +#include <linux/module.h>
17147 +
17148 +#include <linux/vserver/context.h>
17149 +
17150 +
17151 +void   dump_vx_info(struct vx_info *vxi, int level)
17152 +{
17153 +       printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17154 +               atomic_read(&vxi->vx_usecnt),
17155 +               atomic_read(&vxi->vx_tasks),
17156 +               vxi->vx_state);
17157 +       if (level > 0) {
17158 +               __dump_vx_limit(&vxi->limit);
17159 +               __dump_vx_sched(&vxi->sched);
17160 +               __dump_vx_cvirt(&vxi->cvirt);
17161 +               __dump_vx_cacct(&vxi->cacct);
17162 +       }
17163 +       printk("---\n");
17164 +}
17165 +
17166 +
17167 +EXPORT_SYMBOL_GPL(dump_vx_info);
17168 +
17169 diff -NurpP --minimal linux-3.10.40/kernel/vserver/device.c linux-3.10.40-vs2.3.6.8/kernel/vserver/device.c
17170 --- linux-3.10.40/kernel/vserver/device.c       1970-01-01 00:00:00.000000000 +0000
17171 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/device.c     2013-08-22 20:30:00.000000000 +0000
17172 @@ -0,0 +1,443 @@
17173 +/*
17174 + *  linux/kernel/vserver/device.c
17175 + *
17176 + *  Linux-VServer: Device Support
17177 + *
17178 + *  Copyright (C) 2006  Herbert Pötzl
17179 + *  Copyright (C) 2007  Daniel Hokka Zakrisson
17180 + *
17181 + *  V0.01  device mapping basics
17182 + *  V0.02  added defaults
17183 + *
17184 + */
17185 +
17186 +#include <linux/slab.h>
17187 +#include <linux/rcupdate.h>
17188 +#include <linux/fs.h>
17189 +#include <linux/namei.h>
17190 +#include <linux/hash.h>
17191 +
17192 +#include <asm/errno.h>
17193 +#include <asm/uaccess.h>
17194 +#include <linux/vserver/base.h>
17195 +#include <linux/vserver/debug.h>
17196 +#include <linux/vserver/context.h>
17197 +#include <linux/vserver/device.h>
17198 +#include <linux/vserver/device_cmd.h>
17199 +
17200 +
17201 +#define DMAP_HASH_BITS 4
17202 +
17203 +
17204 +struct vs_mapping {
17205 +       union {
17206 +               struct hlist_node hlist;
17207 +               struct list_head list;
17208 +       } u;
17209 +#define dm_hlist       u.hlist
17210 +#define dm_list                u.list
17211 +       vxid_t xid;
17212 +       dev_t device;
17213 +       struct vx_dmap_target target;
17214 +};
17215 +
17216 +
17217 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17218 +
17219 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17220 +
17221 +static struct vx_dmap_target dmap_defaults[2] = {
17222 +       { .flags = DATTR_OPEN },
17223 +       { .flags = DATTR_OPEN },
17224 +};
17225 +
17226 +
17227 +struct kmem_cache *dmap_cachep __read_mostly;
17228 +
17229 +int __init dmap_cache_init(void)
17230 +{
17231 +       dmap_cachep = kmem_cache_create("dmap_cache",
17232 +               sizeof(struct vs_mapping), 0,
17233 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17234 +       return 0;
17235 +}
17236 +
17237 +__initcall(dmap_cache_init);
17238 +
17239 +
17240 +static inline unsigned int __hashval(dev_t dev, int bits)
17241 +{
17242 +       return hash_long((unsigned long)dev, bits);
17243 +}
17244 +
17245 +
17246 +/*     __hash_mapping()
17247 + *     add the mapping to the hash table
17248 + */
17249 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17250 +{
17251 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17252 +       struct hlist_head *head, *hash = dmap_main_hash;
17253 +       int device = vdm->device;
17254 +
17255 +       spin_lock(hash_lock);
17256 +       vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17257 +               vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17258 +
17259 +       head = &hash[__hashval(device, DMAP_HASH_BITS)];
17260 +       hlist_add_head(&vdm->dm_hlist, head);
17261 +       spin_unlock(hash_lock);
17262 +}
17263 +
17264 +
17265 +static inline int __mode_to_default(umode_t mode)
17266 +{
17267 +       switch (mode) {
17268 +       case S_IFBLK:
17269 +               return 0;
17270 +       case S_IFCHR:
17271 +               return 1;
17272 +       default:
17273 +               BUG();
17274 +       }
17275 +}
17276 +
17277 +
17278 +/*     __set_default()
17279 + *     set a default
17280 + */
17281 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17282 +       struct vx_dmap_target *vdmt)
17283 +{
17284 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17285 +       spin_lock(hash_lock);
17286 +
17287 +       if (vxi)
17288 +               vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17289 +       else
17290 +               dmap_defaults[__mode_to_default(mode)] = *vdmt;
17291 +
17292 +
17293 +       spin_unlock(hash_lock);
17294 +
17295 +       vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17296 +                 vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17297 +}
17298 +
17299 +
17300 +/*     __remove_default()
17301 + *     remove a default
17302 + */
17303 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17304 +{
17305 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17306 +       spin_lock(hash_lock);
17307 +
17308 +       if (vxi)
17309 +               vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17310 +       else    /* remove == reset */
17311 +               dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17312 +
17313 +       spin_unlock(hash_lock);
17314 +       return 0;
17315 +}
17316 +
17317 +
17318 +/*     __find_mapping()
17319 + *     find a mapping in the hash table
17320 + *
17321 + *     caller must hold hash_lock
17322 + */
17323 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
17324 +       struct vs_mapping **local, struct vs_mapping **global)
17325 +{
17326 +       struct hlist_head *hash = dmap_main_hash;
17327 +       struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17328 +       struct hlist_node *pos;
17329 +       struct vs_mapping *vdm;
17330 +
17331 +       *local = NULL;
17332 +       if (global)
17333 +               *global = NULL;
17334 +
17335 +       hlist_for_each(pos, head) {
17336 +               vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17337 +
17338 +               if ((vdm->device == device) &&
17339 +                       !((vdm->target.flags ^ mode) & S_IFMT)) {
17340 +                       if (vdm->xid == xid) {
17341 +                               *local = vdm;
17342 +                               return 1;
17343 +                       } else if (global && vdm->xid == 0)
17344 +                               *global = vdm;
17345 +               }
17346 +       }
17347 +
17348 +       if (global && *global)
17349 +               return 0;
17350 +       else
17351 +               return -ENOENT;
17352 +}
17353 +
17354 +
17355 +/*     __lookup_mapping()
17356 + *     find a mapping and store the result in target and flags
17357 + */
17358 +static inline int __lookup_mapping(struct vx_info *vxi,
17359 +       dev_t device, dev_t *target, int *flags, umode_t mode)
17360 +{
17361 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17362 +       struct vs_mapping *vdm, *global;
17363 +       struct vx_dmap_target *vdmt;
17364 +       int ret = 0;
17365 +       vxid_t xid = vxi->vx_id;
17366 +       int index;
17367 +
17368 +       spin_lock(hash_lock);
17369 +       if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17370 +               ret = 1;
17371 +               vdmt = &vdm->target;
17372 +               goto found;
17373 +       }
17374 +
17375 +       index = __mode_to_default(mode);
17376 +       if (vxi && vxi->dmap.targets[index].flags) {
17377 +               ret = 2;
17378 +               vdmt = &vxi->dmap.targets[index];
17379 +       } else if (global) {
17380 +               ret = 3;
17381 +               vdmt = &global->target;
17382 +               goto found;
17383 +       } else {
17384 +               ret = 4;
17385 +               vdmt = &dmap_defaults[index];
17386 +       }
17387 +
17388 +found:
17389 +       if (target && (vdmt->flags & DATTR_REMAP))
17390 +               *target = vdmt->target;
17391 +       else if (target)
17392 +               *target = device;
17393 +       if (flags)
17394 +               *flags = vdmt->flags;
17395 +
17396 +       spin_unlock(hash_lock);
17397 +
17398 +       return ret;
17399 +}
17400 +
17401 +
17402 +/*     __remove_mapping()
17403 + *     remove a mapping from the hash table
17404 + */
17405 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17406 +       umode_t mode)
17407 +{
17408 +       spinlock_t *hash_lock = &dmap_main_hash_lock;
17409 +       struct vs_mapping *vdm = NULL;
17410 +       int ret = 0;
17411 +
17412 +       spin_lock(hash_lock);
17413 +
17414 +       ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17415 +               NULL);
17416 +       vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17417 +               vxi, vxi ? vxi->vx_id : 0, device, mode);
17418 +       if (ret < 0)
17419 +               goto out;
17420 +       hlist_del(&vdm->dm_hlist);
17421 +
17422 +out:
17423 +       spin_unlock(hash_lock);
17424 +       if (vdm)
17425 +               kmem_cache_free(dmap_cachep, vdm);
17426 +       return ret;
17427 +}
17428 +
17429 +
17430 +
17431 +int vs_map_device(struct vx_info *vxi,
17432 +       dev_t device, dev_t *target, umode_t mode)
17433 +{
17434 +       int ret, flags = DATTR_MASK;
17435 +
17436 +       if (!vxi) {
17437 +               if (target)
17438 +                       *target = device;
17439 +               goto out;
17440 +       }
17441 +       ret = __lookup_mapping(vxi, device, target, &flags, mode);
17442 +       vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17443 +               device, target ? *target : 0, flags, mode, ret);
17444 +out:
17445 +       return (flags & DATTR_MASK);
17446 +}
17447 +
17448 +
17449 +
17450 +static int do_set_mapping(struct vx_info *vxi,
17451 +       dev_t device, dev_t target, int flags, umode_t mode)
17452 +{
17453 +       if (device) {
17454 +               struct vs_mapping *new;
17455 +
17456 +               new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17457 +               if (!new)
17458 +                       return -ENOMEM;
17459 +
17460 +               INIT_HLIST_NODE(&new->dm_hlist);
17461 +               new->device = device;
17462 +               new->target.target = target;
17463 +               new->target.flags = flags | mode;
17464 +               new->xid = (vxi ? vxi->vx_id : 0);
17465 +
17466 +               vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17467 +               __hash_mapping(vxi, new);
17468 +       } else {
17469 +               struct vx_dmap_target new = {
17470 +                       .target = target,
17471 +                       .flags = flags | mode,
17472 +               };
17473 +               __set_default(vxi, mode, &new);
17474 +       }
17475 +       return 0;
17476 +}
17477 +
17478 +
17479 +static int do_unset_mapping(struct vx_info *vxi,
17480 +       dev_t device, dev_t target, int flags, umode_t mode)
17481 +{
17482 +       int ret = -EINVAL;
17483 +
17484 +       if (device) {
17485 +               ret = __remove_mapping(vxi, device, mode);
17486 +               if (ret < 0)
17487 +                       goto out;
17488 +       } else {
17489 +               ret = __remove_default(vxi, mode);
17490 +               if (ret < 0)
17491 +                       goto out;
17492 +       }
17493 +
17494 +out:
17495 +       return ret;
17496 +}
17497 +
17498 +
17499 +static inline int __user_device(const char __user *name, dev_t *dev,
17500 +       umode_t *mode)
17501 +{
17502 +       struct nameidata nd;
17503 +       int ret;
17504 +
17505 +       if (!name) {
17506 +               *dev = 0;
17507 +               return 0;
17508 +       }
17509 +       ret = user_lpath(name, &nd.path);
17510 +       if (ret)
17511 +               return ret;
17512 +       if (nd.path.dentry->d_inode) {
17513 +               *dev = nd.path.dentry->d_inode->i_rdev;
17514 +               *mode = nd.path.dentry->d_inode->i_mode;
17515 +       }
17516 +       path_put(&nd.path);
17517 +       return 0;
17518 +}
17519 +
17520 +static inline int __mapping_mode(dev_t device, dev_t target,
17521 +       umode_t device_mode, umode_t target_mode, umode_t *mode)
17522 +{
17523 +       if (device)
17524 +               *mode = device_mode & S_IFMT;
17525 +       else if (target)
17526 +               *mode = target_mode & S_IFMT;
17527 +       else
17528 +               return -EINVAL;
17529 +
17530 +       /* if both given, device and target mode have to match */
17531 +       if (device && target &&
17532 +               ((device_mode ^ target_mode) & S_IFMT))
17533 +               return -EINVAL;
17534 +       return 0;
17535 +}
17536 +
17537 +
17538 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17539 +       const char __user *target_path, int flags, int set)
17540 +{
17541 +       dev_t device = ~0, target = ~0;
17542 +       umode_t device_mode = 0, target_mode = 0, mode;
17543 +       int ret;
17544 +
17545 +       ret = __user_device(device_path, &device, &device_mode);
17546 +       if (ret)
17547 +               return ret;
17548 +       ret = __user_device(target_path, &target, &target_mode);
17549 +       if (ret)
17550 +               return ret;
17551 +
17552 +       ret = __mapping_mode(device, target,
17553 +               device_mode, target_mode, &mode);
17554 +       if (ret)
17555 +               return ret;
17556 +
17557 +       if (set)
17558 +               return do_set_mapping(vxi, device, target,
17559 +                       flags, mode);
17560 +       else
17561 +               return do_unset_mapping(vxi, device, target,
17562 +                       flags, mode);
17563 +}
17564 +
17565 +
17566 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17567 +{
17568 +       struct vcmd_set_mapping_v0 vc_data;
17569 +
17570 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17571 +               return -EFAULT;
17572 +
17573 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17574 +               vc_data.flags, 1);
17575 +}
17576 +
17577 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17578 +{
17579 +       struct vcmd_set_mapping_v0 vc_data;
17580 +
17581 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17582 +               return -EFAULT;
17583 +
17584 +       return do_mapping(vxi, vc_data.device, vc_data.target,
17585 +               vc_data.flags, 0);
17586 +}
17587 +
17588 +
17589 +#ifdef CONFIG_COMPAT
17590 +
17591 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17592 +{
17593 +       struct vcmd_set_mapping_v0_x32 vc_data;
17594 +
17595 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17596 +               return -EFAULT;
17597 +
17598 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17599 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17600 +}
17601 +
17602 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17603 +{
17604 +       struct vcmd_set_mapping_v0_x32 vc_data;
17605 +
17606 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17607 +               return -EFAULT;
17608 +
17609 +       return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17610 +               compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17611 +}
17612 +
17613 +#endif /* CONFIG_COMPAT */
17614 +
17615 +
17616 diff -NurpP --minimal linux-3.10.40/kernel/vserver/dlimit.c linux-3.10.40-vs2.3.6.8/kernel/vserver/dlimit.c
17617 --- linux-3.10.40/kernel/vserver/dlimit.c       1970-01-01 00:00:00.000000000 +0000
17618 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/dlimit.c     2013-08-22 20:30:00.000000000 +0000
17619 @@ -0,0 +1,528 @@
17620 +/*
17621 + *  linux/kernel/vserver/dlimit.c
17622 + *
17623 + *  Virtual Server: Context Disk Limits
17624 + *
17625 + *  Copyright (C) 2004-2009  Herbert Pötzl
17626 + *
17627 + *  V0.01  initial version
17628 + *  V0.02  compat32 splitup
17629 + *  V0.03  extended interface
17630 + *
17631 + */
17632 +
17633 +#include <linux/statfs.h>
17634 +#include <linux/sched.h>
17635 +#include <linux/namei.h>
17636 +#include <linux/vs_tag.h>
17637 +#include <linux/vs_dlimit.h>
17638 +#include <linux/vserver/dlimit_cmd.h>
17639 +#include <linux/slab.h>
17640 +// #include <linux/gfp.h>
17641 +
17642 +#include <asm/uaccess.h>
17643 +
17644 +/*     __alloc_dl_info()
17645 +
17646 +       * allocate an initialized dl_info struct
17647 +       * doesn't make it visible (hash)                        */
17648 +
17649 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
17650 +{
17651 +       struct dl_info *new = NULL;
17652 +
17653 +       vxdprintk(VXD_CBIT(dlim, 5),
17654 +               "alloc_dl_info(%p,%d)*", sb, tag);
17655 +
17656 +       /* would this benefit from a slab cache? */
17657 +       new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17658 +       if (!new)
17659 +               return 0;
17660 +
17661 +       memset(new, 0, sizeof(struct dl_info));
17662 +       new->dl_tag = tag;
17663 +       new->dl_sb = sb;
17664 +       // INIT_RCU_HEAD(&new->dl_rcu);
17665 +       INIT_HLIST_NODE(&new->dl_hlist);
17666 +       spin_lock_init(&new->dl_lock);
17667 +       atomic_set(&new->dl_refcnt, 0);
17668 +       atomic_set(&new->dl_usecnt, 0);
17669 +
17670 +       /* rest of init goes here */
17671 +
17672 +       vxdprintk(VXD_CBIT(dlim, 4),
17673 +               "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17674 +       return new;
17675 +}
17676 +
17677 +/*     __dealloc_dl_info()
17678 +
17679 +       * final disposal of dl_info                             */
17680 +
17681 +static void __dealloc_dl_info(struct dl_info *dli)
17682 +{
17683 +       vxdprintk(VXD_CBIT(dlim, 4),
17684 +               "dealloc_dl_info(%p)", dli);
17685 +
17686 +       dli->dl_hlist.next = LIST_POISON1;
17687 +       dli->dl_tag = -1;
17688 +       dli->dl_sb = 0;
17689 +
17690 +       BUG_ON(atomic_read(&dli->dl_usecnt));
17691 +       BUG_ON(atomic_read(&dli->dl_refcnt));
17692 +
17693 +       kfree(dli);
17694 +}
17695 +
17696 +
17697 +/*     hash table for dl_info hash */
17698 +
17699 +#define DL_HASH_SIZE   13
17700 +
17701 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17702 +
17703 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17704 +
17705 +
17706 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
17707 +{
17708 +       return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17709 +}
17710 +
17711 +
17712 +
17713 +/*     __hash_dl_info()
17714 +
17715 +       * add the dli to the global hash table
17716 +       * requires the hash_lock to be held                     */
17717 +
17718 +static inline void __hash_dl_info(struct dl_info *dli)
17719 +{
17720 +       struct hlist_head *head;
17721 +
17722 +       vxdprintk(VXD_CBIT(dlim, 6),
17723 +               "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17724 +       get_dl_info(dli);
17725 +       head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17726 +       hlist_add_head_rcu(&dli->dl_hlist, head);
17727 +}
17728 +
17729 +/*     __unhash_dl_info()
17730 +
17731 +       * remove the dli from the global hash table
17732 +       * requires the hash_lock to be held                     */
17733 +
17734 +static inline void __unhash_dl_info(struct dl_info *dli)
17735 +{
17736 +       vxdprintk(VXD_CBIT(dlim, 6),
17737 +               "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17738 +       hlist_del_rcu(&dli->dl_hlist);
17739 +       put_dl_info(dli);
17740 +}
17741 +
17742 +
17743 +/*     __lookup_dl_info()
17744 +
17745 +       * requires the rcu_read_lock()
17746 +       * doesn't increment the dl_refcnt                       */
17747 +
17748 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
17749 +{
17750 +       struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17751 +       struct dl_info *dli;
17752 +
17753 +       hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17754 +               if (dli->dl_tag == tag && dli->dl_sb == sb)
17755 +                       return dli;
17756 +       }
17757 +       return NULL;
17758 +}
17759 +
17760 +
17761 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
17762 +{
17763 +       struct dl_info *dli;
17764 +
17765 +       rcu_read_lock();
17766 +       dli = get_dl_info(__lookup_dl_info(sb, tag));
17767 +       vxdprintk(VXD_CBIT(dlim, 7),
17768 +               "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17769 +       rcu_read_unlock();
17770 +       return dli;
17771 +}
17772 +
17773 +void rcu_free_dl_info(struct rcu_head *head)
17774 +{
17775 +       struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17776 +       int usecnt, refcnt;
17777 +
17778 +       BUG_ON(!dli || !head);
17779 +
17780 +       usecnt = atomic_read(&dli->dl_usecnt);
17781 +       BUG_ON(usecnt < 0);
17782 +
17783 +       refcnt = atomic_read(&dli->dl_refcnt);
17784 +       BUG_ON(refcnt < 0);
17785 +
17786 +       vxdprintk(VXD_CBIT(dlim, 3),
17787 +               "rcu_free_dl_info(%p)", dli);
17788 +       if (!usecnt)
17789 +               __dealloc_dl_info(dli);
17790 +       else
17791 +               printk("!!! rcu didn't free\n");
17792 +}
17793 +
17794 +
17795 +
17796 +
17797 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17798 +       uint32_t flags, int add)
17799 +{
17800 +       struct path path;
17801 +       int ret;
17802 +
17803 +       ret = user_lpath(name, &path);
17804 +       if (!ret) {
17805 +               struct super_block *sb;
17806 +               struct dl_info *dli;
17807 +
17808 +               ret = -EINVAL;
17809 +               if (!path.dentry->d_inode)
17810 +                       goto out_release;
17811 +               if (!(sb = path.dentry->d_inode->i_sb))
17812 +                       goto out_release;
17813 +
17814 +               if (add) {
17815 +                       dli = __alloc_dl_info(sb, id);
17816 +                       spin_lock(&dl_info_hash_lock);
17817 +
17818 +                       ret = -EEXIST;
17819 +                       if (__lookup_dl_info(sb, id))
17820 +                               goto out_unlock;
17821 +                       __hash_dl_info(dli);
17822 +                       dli = NULL;
17823 +               } else {
17824 +                       spin_lock(&dl_info_hash_lock);
17825 +                       dli = __lookup_dl_info(sb, id);
17826 +
17827 +                       ret = -ESRCH;
17828 +                       if (!dli)
17829 +                               goto out_unlock;
17830 +                       __unhash_dl_info(dli);
17831 +               }
17832 +               ret = 0;
17833 +       out_unlock:
17834 +               spin_unlock(&dl_info_hash_lock);
17835 +               if (add && dli)
17836 +                       __dealloc_dl_info(dli);
17837 +       out_release:
17838 +               path_put(&path);
17839 +       }
17840 +       return ret;
17841 +}
17842 +
17843 +int vc_add_dlimit(uint32_t id, void __user *data)
17844 +{
17845 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17846 +
17847 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17848 +               return -EFAULT;
17849 +
17850 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17851 +}
17852 +
17853 +int vc_rem_dlimit(uint32_t id, void __user *data)
17854 +{
17855 +       struct vcmd_ctx_dlimit_base_v0 vc_data;
17856 +
17857 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17858 +               return -EFAULT;
17859 +
17860 +       return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17861 +}
17862 +
17863 +#ifdef CONFIG_COMPAT
17864 +
17865 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17866 +{
17867 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17868 +
17869 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17870 +               return -EFAULT;
17871 +
17872 +       return do_addrem_dlimit(id,
17873 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17874 +}
17875 +
17876 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17877 +{
17878 +       struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17879 +
17880 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17881 +               return -EFAULT;
17882 +
17883 +       return do_addrem_dlimit(id,
17884 +               compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17885 +}
17886 +
17887 +#endif /* CONFIG_COMPAT */
17888 +
17889 +
17890 +static inline
17891 +int do_set_dlimit(uint32_t id, const char __user *name,
17892 +       uint32_t space_used, uint32_t space_total,
17893 +       uint32_t inodes_used, uint32_t inodes_total,
17894 +       uint32_t reserved, uint32_t flags)
17895 +{
17896 +       struct path path;
17897 +       int ret;
17898 +
17899 +       ret = user_lpath(name, &path);
17900 +       if (!ret) {
17901 +               struct super_block *sb;
17902 +               struct dl_info *dli;
17903 +
17904 +               ret = -EINVAL;
17905 +               if (!path.dentry->d_inode)
17906 +                       goto out_release;
17907 +               if (!(sb = path.dentry->d_inode->i_sb))
17908 +                       goto out_release;
17909 +
17910 +               /* sanity checks */
17911 +               if ((reserved != CDLIM_KEEP &&
17912 +                       reserved > 100) ||
17913 +                       (inodes_used != CDLIM_KEEP &&
17914 +                       inodes_used > inodes_total) ||
17915 +                       (space_used != CDLIM_KEEP &&
17916 +                       space_used > space_total))
17917 +                       goto out_release;
17918 +
17919 +               ret = -ESRCH;
17920 +               dli = locate_dl_info(sb, id);
17921 +               if (!dli)
17922 +                       goto out_release;
17923 +
17924 +               spin_lock(&dli->dl_lock);
17925 +
17926 +               if (inodes_used != CDLIM_KEEP)
17927 +                       dli->dl_inodes_used = inodes_used;
17928 +               if (inodes_total != CDLIM_KEEP)
17929 +                       dli->dl_inodes_total = inodes_total;
17930 +               if (space_used != CDLIM_KEEP)
17931 +                       dli->dl_space_used = dlimit_space_32to64(
17932 +                               space_used, flags, DLIMS_USED);
17933 +
17934 +               if (space_total == CDLIM_INFINITY)
17935 +                       dli->dl_space_total = DLIM_INFINITY;
17936 +               else if (space_total != CDLIM_KEEP)
17937 +                       dli->dl_space_total = dlimit_space_32to64(
17938 +                               space_total, flags, DLIMS_TOTAL);
17939 +
17940 +               if (reserved != CDLIM_KEEP)
17941 +                       dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17942 +
17943 +               spin_unlock(&dli->dl_lock);
17944 +
17945 +               put_dl_info(dli);
17946 +               ret = 0;
17947 +
17948 +       out_release:
17949 +               path_put(&path);
17950 +       }
17951 +       return ret;
17952 +}
17953 +
17954 +int vc_set_dlimit(uint32_t id, void __user *data)
17955 +{
17956 +       struct vcmd_ctx_dlimit_v0 vc_data;
17957 +
17958 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17959 +               return -EFAULT;
17960 +
17961 +       return do_set_dlimit(id, vc_data.name,
17962 +               vc_data.space_used, vc_data.space_total,
17963 +               vc_data.inodes_used, vc_data.inodes_total,
17964 +               vc_data.reserved, vc_data.flags);
17965 +}
17966 +
17967 +#ifdef CONFIG_COMPAT
17968 +
17969 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17970 +{
17971 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
17972 +
17973 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17974 +               return -EFAULT;
17975 +
17976 +       return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17977 +               vc_data.space_used, vc_data.space_total,
17978 +               vc_data.inodes_used, vc_data.inodes_total,
17979 +               vc_data.reserved, vc_data.flags);
17980 +}
17981 +
17982 +#endif /* CONFIG_COMPAT */
17983 +
17984 +
17985 +static inline
17986 +int do_get_dlimit(uint32_t id, const char __user *name,
17987 +       uint32_t *space_used, uint32_t *space_total,
17988 +       uint32_t *inodes_used, uint32_t *inodes_total,
17989 +       uint32_t *reserved, uint32_t *flags)
17990 +{
17991 +       struct path path;
17992 +       int ret;
17993 +
17994 +       ret = user_lpath(name, &path);
17995 +       if (!ret) {
17996 +               struct super_block *sb;
17997 +               struct dl_info *dli;
17998 +
17999 +               ret = -EINVAL;
18000 +               if (!path.dentry->d_inode)
18001 +                       goto out_release;
18002 +               if (!(sb = path.dentry->d_inode->i_sb))
18003 +                       goto out_release;
18004 +
18005 +               ret = -ESRCH;
18006 +               dli = locate_dl_info(sb, id);
18007 +               if (!dli)
18008 +                       goto out_release;
18009 +
18010 +               spin_lock(&dli->dl_lock);
18011 +               *inodes_used = dli->dl_inodes_used;
18012 +               *inodes_total = dli->dl_inodes_total;
18013 +
18014 +               *space_used = dlimit_space_64to32(
18015 +                       dli->dl_space_used, flags, DLIMS_USED);
18016 +
18017 +               if (dli->dl_space_total == DLIM_INFINITY)
18018 +                       *space_total = CDLIM_INFINITY;
18019 +               else
18020 +                       *space_total = dlimit_space_64to32(
18021 +                               dli->dl_space_total, flags, DLIMS_TOTAL);
18022 +
18023 +               *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18024 +               spin_unlock(&dli->dl_lock);
18025 +
18026 +               put_dl_info(dli);
18027 +               ret = -EFAULT;
18028 +
18029 +               ret = 0;
18030 +       out_release:
18031 +               path_put(&path);
18032 +       }
18033 +       return ret;
18034 +}
18035 +
18036 +
18037 +int vc_get_dlimit(uint32_t id, void __user *data)
18038 +{
18039 +       struct vcmd_ctx_dlimit_v0 vc_data;
18040 +       int ret;
18041 +
18042 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18043 +               return -EFAULT;
18044 +
18045 +       ret = do_get_dlimit(id, vc_data.name,
18046 +               &vc_data.space_used, &vc_data.space_total,
18047 +               &vc_data.inodes_used, &vc_data.inodes_total,
18048 +               &vc_data.reserved, &vc_data.flags);
18049 +       if (ret)
18050 +               return ret;
18051 +
18052 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18053 +               return -EFAULT;
18054 +       return 0;
18055 +}
18056 +
18057 +#ifdef CONFIG_COMPAT
18058 +
18059 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18060 +{
18061 +       struct vcmd_ctx_dlimit_v0_x32 vc_data;
18062 +       int ret;
18063 +
18064 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18065 +               return -EFAULT;
18066 +
18067 +       ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18068 +               &vc_data.space_used, &vc_data.space_total,
18069 +               &vc_data.inodes_used, &vc_data.inodes_total,
18070 +               &vc_data.reserved, &vc_data.flags);
18071 +       if (ret)
18072 +               return ret;
18073 +
18074 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18075 +               return -EFAULT;
18076 +       return 0;
18077 +}
18078 +
18079 +#endif /* CONFIG_COMPAT */
18080 +
18081 +
18082 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18083 +{
18084 +       struct dl_info *dli;
18085 +       __u64 blimit, bfree, bavail;
18086 +       __u32 ifree;
18087 +
18088 +       dli = locate_dl_info(sb, dx_current_tag());
18089 +       if (!dli)
18090 +               return;
18091 +
18092 +       spin_lock(&dli->dl_lock);
18093 +       if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18094 +               goto no_ilim;
18095 +
18096 +       /* reduce max inodes available to limit */
18097 +       if (buf->f_files > dli->dl_inodes_total)
18098 +               buf->f_files = dli->dl_inodes_total;
18099 +
18100 +       ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18101 +       /* reduce free inodes to min */
18102 +       if (ifree < buf->f_ffree)
18103 +               buf->f_ffree = ifree;
18104 +
18105 +no_ilim:
18106 +       if (dli->dl_space_total == DLIM_INFINITY)
18107 +               goto no_blim;
18108 +
18109 +       blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18110 +
18111 +       if (dli->dl_space_total < dli->dl_space_used)
18112 +               bfree = 0;
18113 +       else
18114 +               bfree = (dli->dl_space_total - dli->dl_space_used)
18115 +                       >> sb->s_blocksize_bits;
18116 +
18117 +       bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18118 +       if (bavail < dli->dl_space_used)
18119 +               bavail = 0;
18120 +       else
18121 +               bavail = (bavail - dli->dl_space_used)
18122 +                       >> sb->s_blocksize_bits;
18123 +
18124 +       /* reduce max space available to limit */
18125 +       if (buf->f_blocks > blimit)
18126 +               buf->f_blocks = blimit;
18127 +
18128 +       /* reduce free space to min */
18129 +       if (bfree < buf->f_bfree)
18130 +               buf->f_bfree = bfree;
18131 +
18132 +       /* reduce avail space to min */
18133 +       if (bavail < buf->f_bavail)
18134 +               buf->f_bavail = bavail;
18135 +
18136 +no_blim:
18137 +       spin_unlock(&dli->dl_lock);
18138 +       put_dl_info(dli);
18139 +
18140 +       return;
18141 +}
18142 +
18143 +#include <linux/module.h>
18144 +
18145 +EXPORT_SYMBOL_GPL(locate_dl_info);
18146 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18147 +
18148 diff -NurpP --minimal linux-3.10.40/kernel/vserver/helper.c linux-3.10.40-vs2.3.6.8/kernel/vserver/helper.c
18149 --- linux-3.10.40/kernel/vserver/helper.c       1970-01-01 00:00:00.000000000 +0000
18150 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/helper.c     2013-08-23 00:55:48.000000000 +0000
18151 @@ -0,0 +1,242 @@
18152 +/*
18153 + *  linux/kernel/vserver/helper.c
18154 + *
18155 + *  Virtual Context Support
18156 + *
18157 + *  Copyright (C) 2004-2007  Herbert Pötzl
18158 + *
18159 + *  V0.01  basic helper
18160 + *
18161 + */
18162 +
18163 +#include <linux/kmod.h>
18164 +#include <linux/reboot.h>
18165 +#include <linux/vs_context.h>
18166 +#include <linux/vs_network.h>
18167 +#include <linux/vserver/signal.h>
18168 +
18169 +
18170 +char vshelper_path[255] = "/sbin/vshelper";
18171 +
18172 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18173 +{
18174 +       current->flags &= ~PF_NO_SETAFFINITY;
18175 +       return 0;
18176 +}
18177 +
18178 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
18179 +{
18180 +       struct subprocess_info *info;
18181 +       gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
18182 +
18183 +       info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
18184 +                                        vshelper_init, NULL, NULL);
18185 +       if (info == NULL)
18186 +               return -ENOMEM;
18187 +
18188 +       return call_usermodehelper_exec(info, wait);
18189 +}
18190 +
18191 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18192 +{
18193 +       int ret;
18194 +
18195 +       if ((ret = vs_call_usermodehelper(name, argv, envp,
18196 +               sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
18197 +               printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18198 +                       name, argv[1], argv[2],
18199 +                       sync ? "sync" : "async", ret);
18200 +       }
18201 +       vxdprintk(VXD_CBIT(switch, 4),
18202 +               "%s: (%s %s) returned %s with %d",
18203 +               name, argv[1], argv[2], sync ? "sync" : "async", ret);
18204 +       return ret;
18205 +}
18206 +
18207 +/*
18208 + *      vshelper path is set via /proc/sys
18209 + *      invoked by vserver sys_reboot(), with
18210 + *      the following arguments
18211 + *
18212 + *      argv [0] = vshelper_path;
18213 + *      argv [1] = action: "restart", "halt", "poweroff", ...
18214 + *      argv [2] = context identifier
18215 + *
18216 + *      envp [*] = type-specific parameters
18217 + */
18218 +
18219 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18220 +{
18221 +       char id_buf[8], cmd_buf[16];
18222 +       char uid_buf[16], pid_buf[16];
18223 +       int ret;
18224 +
18225 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18226 +       char *envp[] = {"HOME=/", "TERM=linux",
18227 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18228 +                       uid_buf, pid_buf, cmd_buf, 0};
18229 +
18230 +       if (vx_info_state(vxi, VXS_HELPER))
18231 +               return -EAGAIN;
18232 +       vxi->vx_state |= VXS_HELPER;
18233 +
18234 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18235 +
18236 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18237 +       snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
18238 +               from_kuid(&init_user_ns, current_uid()));
18239 +       snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18240 +
18241 +       switch (cmd) {
18242 +       case LINUX_REBOOT_CMD_RESTART:
18243 +               argv[1] = "restart";
18244 +               break;
18245 +
18246 +       case LINUX_REBOOT_CMD_HALT:
18247 +               argv[1] = "halt";
18248 +               break;
18249 +
18250 +       case LINUX_REBOOT_CMD_POWER_OFF:
18251 +               argv[1] = "poweroff";
18252 +               break;
18253 +
18254 +       case LINUX_REBOOT_CMD_SW_SUSPEND:
18255 +               argv[1] = "swsusp";
18256 +               break;
18257 +
18258 +       case LINUX_REBOOT_CMD_OOM:
18259 +               argv[1] = "oom";
18260 +               break;
18261 +
18262 +       default:
18263 +               vxi->vx_state &= ~VXS_HELPER;
18264 +               return 0;
18265 +       }
18266 +
18267 +       ret = do_vshelper(vshelper_path, argv, envp, 0);
18268 +       vxi->vx_state &= ~VXS_HELPER;
18269 +       __wakeup_vx_info(vxi);
18270 +       return (ret) ? -EPERM : 0;
18271 +}
18272 +
18273 +
18274 +long vs_reboot(unsigned int cmd, void __user *arg)
18275 +{
18276 +       struct vx_info *vxi = current_vx_info();
18277 +       long ret = 0;
18278 +
18279 +       vxdprintk(VXD_CBIT(misc, 5),
18280 +               "vs_reboot(%p[#%d],%u)",
18281 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18282 +
18283 +       ret = vs_reboot_helper(vxi, cmd, arg);
18284 +       if (ret)
18285 +               return ret;
18286 +
18287 +       vxi->reboot_cmd = cmd;
18288 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18289 +               switch (cmd) {
18290 +               case LINUX_REBOOT_CMD_RESTART:
18291 +               case LINUX_REBOOT_CMD_HALT:
18292 +               case LINUX_REBOOT_CMD_POWER_OFF:
18293 +                       vx_info_kill(vxi, 0, SIGKILL);
18294 +                       vx_info_kill(vxi, 1, SIGKILL);
18295 +               default:
18296 +                       break;
18297 +               }
18298 +       }
18299 +       return 0;
18300 +}
18301 +
18302 +long vs_oom_action(unsigned int cmd)
18303 +{
18304 +       struct vx_info *vxi = current_vx_info();
18305 +       long ret = 0;
18306 +
18307 +       vxdprintk(VXD_CBIT(misc, 5),
18308 +               "vs_oom_action(%p[#%d],%u)",
18309 +               vxi, vxi ? vxi->vx_id : 0, cmd);
18310 +
18311 +       ret = vs_reboot_helper(vxi, cmd, NULL);
18312 +       if (ret)
18313 +               return ret;
18314 +
18315 +       vxi->reboot_cmd = cmd;
18316 +       if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18317 +               vx_info_kill(vxi, 0, SIGKILL);
18318 +               vx_info_kill(vxi, 1, SIGKILL);
18319 +       }
18320 +       return 0;
18321 +}
18322 +
18323 +/*
18324 + *      argv [0] = vshelper_path;
18325 + *      argv [1] = action: "startup", "shutdown"
18326 + *      argv [2] = context identifier
18327 + *
18328 + *      envp [*] = type-specific parameters
18329 + */
18330 +
18331 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18332 +{
18333 +       char id_buf[8], cmd_buf[16];
18334 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18335 +       char *envp[] = {"HOME=/", "TERM=linux",
18336 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18337 +
18338 +       if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18339 +               return 0;
18340 +
18341 +       snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18342 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18343 +
18344 +       switch (cmd) {
18345 +       case VSC_STARTUP:
18346 +               argv[1] = "startup";
18347 +               break;
18348 +       case VSC_SHUTDOWN:
18349 +               argv[1] = "shutdown";
18350 +               break;
18351 +       default:
18352 +               return 0;
18353 +       }
18354 +
18355 +       return do_vshelper(vshelper_path, argv, envp, 1);
18356 +}
18357 +
18358 +
18359 +/*
18360 + *      argv [0] = vshelper_path;
18361 + *      argv [1] = action: "netup", "netdown"
18362 + *      argv [2] = context identifier
18363 + *
18364 + *      envp [*] = type-specific parameters
18365 + */
18366 +
18367 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18368 +{
18369 +       char id_buf[8], cmd_buf[16];
18370 +       char *argv[] = {vshelper_path, NULL, id_buf, 0};
18371 +       char *envp[] = {"HOME=/", "TERM=linux",
18372 +                       "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18373 +
18374 +       if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18375 +               return 0;
18376 +
18377 +       snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18378 +       snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18379 +
18380 +       switch (cmd) {
18381 +       case VSC_NETUP:
18382 +               argv[1] = "netup";
18383 +               break;
18384 +       case VSC_NETDOWN:
18385 +               argv[1] = "netdown";
18386 +               break;
18387 +       default:
18388 +               return 0;
18389 +       }
18390 +
18391 +       return do_vshelper(vshelper_path, argv, envp, 1);
18392 +}
18393 +
18394 diff -NurpP --minimal linux-3.10.40/kernel/vserver/history.c linux-3.10.40-vs2.3.6.8/kernel/vserver/history.c
18395 --- linux-3.10.40/kernel/vserver/history.c      1970-01-01 00:00:00.000000000 +0000
18396 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/history.c    2013-08-22 20:30:00.000000000 +0000
18397 @@ -0,0 +1,258 @@
18398 +/*
18399 + *  kernel/vserver/history.c
18400 + *
18401 + *  Virtual Context History Backtrace
18402 + *
18403 + *  Copyright (C) 2004-2007  Herbert Pötzl
18404 + *
18405 + *  V0.01  basic structure
18406 + *  V0.02  hash/unhash and trace
18407 + *  V0.03  preemption fixes
18408 + *
18409 + */
18410 +
18411 +#include <linux/module.h>
18412 +#include <asm/uaccess.h>
18413 +
18414 +#include <linux/vserver/context.h>
18415 +#include <linux/vserver/debug.h>
18416 +#include <linux/vserver/debug_cmd.h>
18417 +#include <linux/vserver/history.h>
18418 +
18419 +
18420 +#ifdef CONFIG_VSERVER_HISTORY
18421 +#define VXH_SIZE       CONFIG_VSERVER_HISTORY_SIZE
18422 +#else
18423 +#define VXH_SIZE       64
18424 +#endif
18425 +
18426 +struct _vx_history {
18427 +       unsigned int counter;
18428 +
18429 +       struct _vx_hist_entry entry[VXH_SIZE + 1];
18430 +};
18431 +
18432 +
18433 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18434 +
18435 +unsigned volatile int vxh_active = 1;
18436 +
18437 +static atomic_t sequence = ATOMIC_INIT(0);
18438 +
18439 +
18440 +/*     vxh_advance()
18441 +
18442 +       * requires disabled preemption                          */
18443 +
18444 +struct _vx_hist_entry *vxh_advance(void *loc)
18445 +{
18446 +       unsigned int cpu = smp_processor_id();
18447 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18448 +       struct _vx_hist_entry *entry;
18449 +       unsigned int index;
18450 +
18451 +       index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18452 +       entry = &hist->entry[index];
18453 +
18454 +       entry->seq = atomic_inc_return(&sequence);
18455 +       entry->loc = loc;
18456 +       return entry;
18457 +}
18458 +
18459 +EXPORT_SYMBOL_GPL(vxh_advance);
18460 +
18461 +
18462 +#define VXH_LOC_FMTS   "(#%04x,*%d):%p"
18463 +
18464 +#define VXH_LOC_ARGS(e)        (e)->seq, cpu, (e)->loc
18465 +
18466 +
18467 +#define VXH_VXI_FMTS   "%p[#%d,%d.%d]"
18468 +
18469 +#define VXH_VXI_ARGS(e)        (e)->vxi.ptr,                           \
18470 +                       (e)->vxi.ptr ? (e)->vxi.xid : 0,        \
18471 +                       (e)->vxi.ptr ? (e)->vxi.usecnt : 0,     \
18472 +                       (e)->vxi.ptr ? (e)->vxi.tasks : 0
18473 +
18474 +void   vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18475 +{
18476 +       switch (e->type) {
18477 +       case VXH_THROW_OOPS:
18478 +               printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18479 +               break;
18480 +
18481 +       case VXH_GET_VX_INFO:
18482 +       case VXH_PUT_VX_INFO:
18483 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18484 +                       VXH_LOC_ARGS(e),
18485 +                       (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18486 +                       VXH_VXI_ARGS(e));
18487 +               break;
18488 +
18489 +       case VXH_INIT_VX_INFO:
18490 +       case VXH_SET_VX_INFO:
18491 +       case VXH_CLR_VX_INFO:
18492 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18493 +                       VXH_LOC_ARGS(e),
18494 +                       (e->type == VXH_INIT_VX_INFO) ? "init" :
18495 +                       ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18496 +                       VXH_VXI_ARGS(e), e->sc.data);
18497 +               break;
18498 +
18499 +       case VXH_CLAIM_VX_INFO:
18500 +       case VXH_RELEASE_VX_INFO:
18501 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18502 +                       VXH_LOC_ARGS(e),
18503 +                       (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18504 +                       VXH_VXI_ARGS(e), e->sc.data);
18505 +               break;
18506 +
18507 +       case VXH_ALLOC_VX_INFO:
18508 +       case VXH_DEALLOC_VX_INFO:
18509 +               printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18510 +                       VXH_LOC_ARGS(e),
18511 +                       (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18512 +                       VXH_VXI_ARGS(e));
18513 +               break;
18514 +
18515 +       case VXH_HASH_VX_INFO:
18516 +       case VXH_UNHASH_VX_INFO:
18517 +               printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18518 +                       VXH_LOC_ARGS(e),
18519 +                       (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18520 +                       VXH_VXI_ARGS(e));
18521 +               break;
18522 +
18523 +       case VXH_LOC_VX_INFO:
18524 +       case VXH_LOOKUP_VX_INFO:
18525 +       case VXH_CREATE_VX_INFO:
18526 +               printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18527 +                       VXH_LOC_ARGS(e),
18528 +                       (e->type == VXH_CREATE_VX_INFO) ? "create" :
18529 +                       ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18530 +                       e->ll.arg, VXH_VXI_ARGS(e));
18531 +               break;
18532 +       }
18533 +}
18534 +
18535 +static void __vxh_dump_history(void)
18536 +{
18537 +       unsigned int i, cpu;
18538 +
18539 +       printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18540 +               atomic_read(&sequence), NR_CPUS);
18541 +
18542 +       for (i = 0; i < VXH_SIZE; i++) {
18543 +               for_each_online_cpu(cpu) {
18544 +                       struct _vx_history *hist =
18545 +                               &per_cpu(vx_history_buffer, cpu);
18546 +                       unsigned int index = (hist->counter - i) % VXH_SIZE;
18547 +                       struct _vx_hist_entry *entry = &hist->entry[index];
18548 +
18549 +                       vxh_dump_entry(entry, cpu);
18550 +               }
18551 +       }
18552 +}
18553 +
18554 +void   vxh_dump_history(void)
18555 +{
18556 +       vxh_active = 0;
18557 +#ifdef CONFIG_SMP
18558 +       local_irq_enable();
18559 +       smp_send_stop();
18560 +       local_irq_disable();
18561 +#endif
18562 +       __vxh_dump_history();
18563 +}
18564 +
18565 +
18566 +/* vserver syscall commands below here */
18567 +
18568 +
18569 +int vc_dump_history(uint32_t id)
18570 +{
18571 +       vxh_active = 0;
18572 +       __vxh_dump_history();
18573 +       vxh_active = 1;
18574 +
18575 +       return 0;
18576 +}
18577 +
18578 +
18579 +int do_read_history(struct __user _vx_hist_entry *data,
18580 +       int cpu, uint32_t *index, uint32_t *count)
18581 +{
18582 +       int pos, ret = 0;
18583 +       struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18584 +       int end = hist->counter;
18585 +       int start = end - VXH_SIZE + 2;
18586 +       int idx = *index;
18587 +
18588 +       /* special case: get current pos */
18589 +       if (!*count) {
18590 +               *index = end;
18591 +               return 0;
18592 +       }
18593 +
18594 +       /* have we lost some data? */
18595 +       if (idx < start)
18596 +               idx = start;
18597 +
18598 +       for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18599 +               struct _vx_hist_entry *entry =
18600 +                       &hist->entry[idx % VXH_SIZE];
18601 +
18602 +               /* send entry to userspace */
18603 +               ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18604 +               if (ret)
18605 +                       break;
18606 +       }
18607 +       /* save new index and count */
18608 +       *index = idx;
18609 +       *count = pos;
18610 +       return ret ? ret : (*index < end);
18611 +}
18612 +
18613 +int vc_read_history(uint32_t id, void __user *data)
18614 +{
18615 +       struct vcmd_read_history_v0 vc_data;
18616 +       int ret;
18617 +
18618 +       if (id >= NR_CPUS)
18619 +               return -EINVAL;
18620 +
18621 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18622 +               return -EFAULT;
18623 +
18624 +       ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18625 +               id, &vc_data.index, &vc_data.count);
18626 +
18627 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18628 +               return -EFAULT;
18629 +       return ret;
18630 +}
18631 +
18632 +#ifdef CONFIG_COMPAT
18633 +
18634 +int vc_read_history_x32(uint32_t id, void __user *data)
18635 +{
18636 +       struct vcmd_read_history_v0_x32 vc_data;
18637 +       int ret;
18638 +
18639 +       if (id >= NR_CPUS)
18640 +               return -EINVAL;
18641 +
18642 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18643 +               return -EFAULT;
18644 +
18645 +       ret = do_read_history((struct __user _vx_hist_entry *)
18646 +               compat_ptr(vc_data.data_ptr),
18647 +               id, &vc_data.index, &vc_data.count);
18648 +
18649 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18650 +               return -EFAULT;
18651 +       return ret;
18652 +}
18653 +
18654 +#endif /* CONFIG_COMPAT */
18655 +
18656 diff -NurpP --minimal linux-3.10.40/kernel/vserver/inet.c linux-3.10.40-vs2.3.6.8/kernel/vserver/inet.c
18657 --- linux-3.10.40/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
18658 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/inet.c       2013-08-22 20:30:00.000000000 +0000
18659 @@ -0,0 +1,236 @@
18660 +
18661 +#include <linux/in.h>
18662 +#include <linux/inetdevice.h>
18663 +#include <linux/export.h>
18664 +#include <linux/vs_inet.h>
18665 +#include <linux/vs_inet6.h>
18666 +#include <linux/vserver/debug.h>
18667 +#include <net/route.h>
18668 +#include <net/addrconf.h>
18669 +
18670 +
18671 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18672 +{
18673 +       int ret = 0;
18674 +
18675 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18676 +               ret = 1;
18677 +       else {
18678 +               struct nx_addr_v4 *ptr;
18679 +               unsigned long irqflags;
18680 +
18681 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18682 +               for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18683 +                       if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18684 +                               ret = 1;
18685 +                               break;
18686 +                       }
18687 +               }
18688 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18689 +       }
18690 +
18691 +       vxdprintk(VXD_CBIT(net, 2),
18692 +               "nx_v4_addr_conflict(%p,%p): %d",
18693 +               nxi1, nxi2, ret);
18694 +
18695 +       return ret;
18696 +}
18697 +
18698 +
18699 +#ifdef CONFIG_IPV6
18700 +
18701 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18702 +{
18703 +       int ret = 0;
18704 +
18705 +       if (!nxi1 || !nxi2 || nxi1 == nxi2)
18706 +               ret = 1;
18707 +       else {
18708 +               struct nx_addr_v6 *ptr;
18709 +               unsigned long irqflags;
18710 +
18711 +               spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18712 +               for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18713 +                       if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18714 +                               ret = 1;
18715 +                               break;
18716 +                       }
18717 +               }
18718 +               spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18719 +       }
18720 +
18721 +       vxdprintk(VXD_CBIT(net, 2),
18722 +               "nx_v6_addr_conflict(%p,%p): %d",
18723 +               nxi1, nxi2, ret);
18724 +
18725 +       return ret;
18726 +}
18727 +
18728 +#endif
18729 +
18730 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18731 +{
18732 +       struct in_device *in_dev;
18733 +       struct in_ifaddr **ifap;
18734 +       struct in_ifaddr *ifa;
18735 +       int ret = 0;
18736 +
18737 +       if (!dev)
18738 +               goto out;
18739 +       in_dev = in_dev_get(dev);
18740 +       if (!in_dev)
18741 +               goto out;
18742 +
18743 +       for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18744 +               ifap = &ifa->ifa_next) {
18745 +               if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18746 +                       ret = 1;
18747 +                       break;
18748 +               }
18749 +       }
18750 +       in_dev_put(in_dev);
18751 +out:
18752 +       return ret;
18753 +}
18754 +
18755 +
18756 +#ifdef CONFIG_IPV6
18757 +
18758 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18759 +{
18760 +       struct inet6_dev *in_dev;
18761 +       struct inet6_ifaddr *ifa;
18762 +       int ret = 0;
18763 +
18764 +       if (!dev)
18765 +               goto out;
18766 +       in_dev = in6_dev_get(dev);
18767 +       if (!in_dev)
18768 +               goto out;
18769 +
18770 +       // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18771 +       list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18772 +               if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18773 +                       ret = 1;
18774 +                       break;
18775 +               }
18776 +       }
18777 +       in6_dev_put(in_dev);
18778 +out:
18779 +       return ret;
18780 +}
18781 +
18782 +#endif
18783 +
18784 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18785 +{
18786 +       int ret = 1;
18787 +
18788 +       if (!nxi)
18789 +               goto out;
18790 +       if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18791 +               goto out;
18792 +#ifdef CONFIG_IPV6
18793 +       ret = 2;
18794 +       if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18795 +               goto out;
18796 +#endif
18797 +       ret = 0;
18798 +out:
18799 +       vxdprintk(VXD_CBIT(net, 3),
18800 +               "dev_in_nx_info(%p,%p[#%d]) = %d",
18801 +               dev, nxi, nxi ? nxi->nx_id : 0, ret);
18802 +       return ret;
18803 +}
18804 +
18805 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18806 +       struct flowi4 *fl4)
18807 +{
18808 +       struct rtable *rt;
18809 +
18810 +       if (!nxi)
18811 +               return NULL;
18812 +
18813 +       /* FIXME: handle lback only case */
18814 +       if (!NX_IPV4(nxi))
18815 +               return ERR_PTR(-EPERM);
18816 +
18817 +       vxdprintk(VXD_CBIT(net, 4),
18818 +               "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18819 +               nxi, nxi ? nxi->nx_id : 0,
18820 +               NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18821 +
18822 +       /* single IP is unconditional */
18823 +       if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18824 +               (fl4->saddr == INADDR_ANY))
18825 +               fl4->saddr = nxi->v4.ip[0].s_addr;
18826 +
18827 +       if (fl4->saddr == INADDR_ANY) {
18828 +               struct nx_addr_v4 *ptr;
18829 +               __be32 found = 0;
18830 +
18831 +               rt = __ip_route_output_key(net, fl4);
18832 +               if (!IS_ERR(rt)) {
18833 +                       found = fl4->saddr;
18834 +                       ip_rt_put(rt);
18835 +                       vxdprintk(VXD_CBIT(net, 4),
18836 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18837 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18838 +                       if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18839 +                               goto found;
18840 +               }
18841 +
18842 +               WARN_ON_ONCE(in_irq());
18843 +               spin_lock_bh(&nxi->addr_lock);
18844 +               for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18845 +                       __be32 primary = ptr->ip[0].s_addr;
18846 +                       __be32 mask = ptr->mask.s_addr;
18847 +                       __be32 neta = primary & mask;
18848 +
18849 +                       vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18850 +                               NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18851 +                               nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18852 +                               NIPQUAD(mask), NIPQUAD(neta));
18853 +                       if ((found & mask) != neta)
18854 +                               continue;
18855 +
18856 +                       fl4->saddr = primary;
18857 +                       rt = __ip_route_output_key(net, fl4);
18858 +                       vxdprintk(VXD_CBIT(net, 4),
18859 +                               "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18860 +                               nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18861 +                       if (!IS_ERR(rt)) {
18862 +                               found = fl4->saddr;
18863 +                               ip_rt_put(rt);
18864 +                               if (found == primary)
18865 +                                       goto found_unlock;
18866 +                       }
18867 +               }
18868 +               /* still no source ip? */
18869 +               found = ipv4_is_loopback(fl4->daddr)
18870 +                       ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18871 +       found_unlock:
18872 +               spin_unlock_bh(&nxi->addr_lock);
18873 +       found:
18874 +               /* assign src ip to flow */
18875 +               fl4->saddr = found;
18876 +
18877 +       } else {
18878 +               if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18879 +                       return ERR_PTR(-EPERM);
18880 +       }
18881 +
18882 +       if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18883 +               if (ipv4_is_loopback(fl4->daddr))
18884 +                       fl4->daddr = nxi->v4_lback.s_addr;
18885 +               if (ipv4_is_loopback(fl4->saddr))
18886 +                       fl4->saddr = nxi->v4_lback.s_addr;
18887 +       } else if (ipv4_is_loopback(fl4->daddr) &&
18888 +               !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18889 +               return ERR_PTR(-EPERM);
18890 +
18891 +       return NULL;
18892 +}
18893 +
18894 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18895 +
18896 diff -NurpP --minimal linux-3.10.40/kernel/vserver/init.c linux-3.10.40-vs2.3.6.8/kernel/vserver/init.c
18897 --- linux-3.10.40/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
18898 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/init.c       2013-08-22 20:30:00.000000000 +0000
18899 @@ -0,0 +1,45 @@
18900 +/*
18901 + *  linux/kernel/init.c
18902 + *
18903 + *  Virtual Server Init
18904 + *
18905 + *  Copyright (C) 2004-2007  Herbert Pötzl
18906 + *
18907 + *  V0.01  basic structure
18908 + *
18909 + */
18910 +
18911 +#include <linux/init.h>
18912 +
18913 +int    vserver_register_sysctl(void);
18914 +void   vserver_unregister_sysctl(void);
18915 +
18916 +
18917 +static int __init init_vserver(void)
18918 +{
18919 +       int ret = 0;
18920 +
18921 +#ifdef CONFIG_VSERVER_DEBUG
18922 +       vserver_register_sysctl();
18923 +#endif
18924 +       return ret;
18925 +}
18926 +
18927 +
18928 +static void __exit exit_vserver(void)
18929 +{
18930 +
18931 +#ifdef CONFIG_VSERVER_DEBUG
18932 +       vserver_unregister_sysctl();
18933 +#endif
18934 +       return;
18935 +}
18936 +
18937 +/* FIXME: GFP_ZONETYPES gone
18938 +long vx_slab[GFP_ZONETYPES]; */
18939 +long vx_area;
18940 +
18941 +
18942 +module_init(init_vserver);
18943 +module_exit(exit_vserver);
18944 +
18945 diff -NurpP --minimal linux-3.10.40/kernel/vserver/inode.c linux-3.10.40-vs2.3.6.8/kernel/vserver/inode.c
18946 --- linux-3.10.40/kernel/vserver/inode.c        1970-01-01 00:00:00.000000000 +0000
18947 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/inode.c      2013-08-22 23:14:01.000000000 +0000
18948 @@ -0,0 +1,440 @@
18949 +/*
18950 + *  linux/kernel/vserver/inode.c
18951 + *
18952 + *  Virtual Server: File System Support
18953 + *
18954 + *  Copyright (C) 2004-2007  Herbert Pötzl
18955 + *
18956 + *  V0.01  separated from vcontext V0.05
18957 + *  V0.02  moved to tag (instead of xid)
18958 + *
18959 + */
18960 +
18961 +#include <linux/tty.h>
18962 +#include <linux/proc_fs.h>
18963 +#include <linux/devpts_fs.h>
18964 +#include <linux/fs.h>
18965 +#include <linux/file.h>
18966 +#include <linux/mount.h>
18967 +#include <linux/parser.h>
18968 +#include <linux/namei.h>
18969 +#include <linux/magic.h>
18970 +#include <linux/slab.h>
18971 +#include <linux/vserver/inode.h>
18972 +#include <linux/vserver/inode_cmd.h>
18973 +#include <linux/vs_base.h>
18974 +#include <linux/vs_tag.h>
18975 +
18976 +#include <asm/uaccess.h>
18977 +#include <../../fs/proc/internal.h>
18978 +
18979 +
18980 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18981 +{
18982 +       struct proc_dir_entry *entry;
18983 +
18984 +       if (!in || !in->i_sb)
18985 +               return -ESRCH;
18986 +
18987 +       *flags = IATTR_TAG
18988 +               | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18989 +               | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18990 +               | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18991 +               | (IS_COW(in) ? IATTR_COW : 0);
18992 +       *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18993 +
18994 +       if (S_ISDIR(in->i_mode))
18995 +               *mask |= IATTR_BARRIER;
18996 +
18997 +       if (IS_TAGGED(in)) {
18998 +               *tag = i_tag_read(in);
18999 +               *mask |= IATTR_TAG;
19000 +       }
19001 +
19002 +       switch (in->i_sb->s_magic) {
19003 +       case PROC_SUPER_MAGIC:
19004 +               entry = PROC_I(in)->pde;
19005 +
19006 +               /* check for specific inodes? */
19007 +               if (entry)
19008 +                       *mask |= IATTR_FLAGS;
19009 +               if (entry)
19010 +                       *flags |= (entry->vx_flags & IATTR_FLAGS);
19011 +               else
19012 +                       *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19013 +               break;
19014 +
19015 +       case DEVPTS_SUPER_MAGIC:
19016 +               *tag = i_tag_read(in);
19017 +               *mask |= IATTR_TAG;
19018 +               break;
19019 +
19020 +       default:
19021 +               break;
19022 +       }
19023 +       return 0;
19024 +}
19025 +
19026 +int vc_get_iattr(void __user *data)
19027 +{
19028 +       struct path path;
19029 +       struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19030 +       int ret;
19031 +
19032 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19033 +               return -EFAULT;
19034 +
19035 +       ret = user_lpath(vc_data.name, &path);
19036 +       if (!ret) {
19037 +               ret = __vc_get_iattr(path.dentry->d_inode,
19038 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19039 +               path_put(&path);
19040 +       }
19041 +       if (ret)
19042 +               return ret;
19043 +
19044 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19045 +               ret = -EFAULT;
19046 +       return ret;
19047 +}
19048 +
19049 +#ifdef CONFIG_COMPAT
19050 +
19051 +int vc_get_iattr_x32(void __user *data)
19052 +{
19053 +       struct path path;
19054 +       struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19055 +       int ret;
19056 +
19057 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19058 +               return -EFAULT;
19059 +
19060 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19061 +       if (!ret) {
19062 +               ret = __vc_get_iattr(path.dentry->d_inode,
19063 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19064 +               path_put(&path);
19065 +       }
19066 +       if (ret)
19067 +               return ret;
19068 +
19069 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19070 +               ret = -EFAULT;
19071 +       return ret;
19072 +}
19073 +
19074 +#endif /* CONFIG_COMPAT */
19075 +
19076 +
19077 +int vc_fget_iattr(uint32_t fd, void __user *data)
19078 +{
19079 +       struct file *filp;
19080 +       struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19081 +       int ret;
19082 +
19083 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19084 +               return -EFAULT;
19085 +
19086 +       filp = fget(fd);
19087 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19088 +               return -EBADF;
19089 +
19090 +       ret = __vc_get_iattr(filp->f_dentry->d_inode,
19091 +               &vc_data.tag, &vc_data.flags, &vc_data.mask);
19092 +
19093 +       fput(filp);
19094 +
19095 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19096 +               ret = -EFAULT;
19097 +       return ret;
19098 +}
19099 +
19100 +
19101 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19102 +{
19103 +       struct inode *in = de->d_inode;
19104 +       int error = 0, is_proc = 0, has_tag = 0;
19105 +       struct iattr attr = { 0 };
19106 +
19107 +       if (!in || !in->i_sb)
19108 +               return -ESRCH;
19109 +
19110 +       is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19111 +       if ((*mask & IATTR_FLAGS) && !is_proc)
19112 +               return -EINVAL;
19113 +
19114 +       has_tag = IS_TAGGED(in) ||
19115 +               (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19116 +       if ((*mask & IATTR_TAG) && !has_tag)
19117 +               return -EINVAL;
19118 +
19119 +       mutex_lock(&in->i_mutex);
19120 +       if (*mask & IATTR_TAG) {
19121 +               attr.ia_tag = make_ktag(&init_user_ns, *tag);
19122 +               attr.ia_valid |= ATTR_TAG;
19123 +       }
19124 +
19125 +       if (*mask & IATTR_FLAGS) {
19126 +               struct proc_dir_entry *entry = PROC_I(in)->pde;
19127 +               unsigned int iflags = PROC_I(in)->vx_flags;
19128 +
19129 +               iflags = (iflags & ~(*mask & IATTR_FLAGS))
19130 +                       | (*flags & IATTR_FLAGS);
19131 +               PROC_I(in)->vx_flags = iflags;
19132 +               if (entry)
19133 +                       entry->vx_flags = iflags;
19134 +       }
19135 +
19136 +       if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19137 +               IATTR_BARRIER | IATTR_COW)) {
19138 +               int iflags = in->i_flags;
19139 +               int vflags = in->i_vflags;
19140 +
19141 +               if (*mask & IATTR_IMMUTABLE) {
19142 +                       if (*flags & IATTR_IMMUTABLE)
19143 +                               iflags |= S_IMMUTABLE;
19144 +                       else
19145 +                               iflags &= ~S_IMMUTABLE;
19146 +               }
19147 +               if (*mask & IATTR_IXUNLINK) {
19148 +                       if (*flags & IATTR_IXUNLINK)
19149 +                               iflags |= S_IXUNLINK;
19150 +                       else
19151 +                               iflags &= ~S_IXUNLINK;
19152 +               }
19153 +               if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19154 +                       if (*flags & IATTR_BARRIER)
19155 +                               vflags |= V_BARRIER;
19156 +                       else
19157 +                               vflags &= ~V_BARRIER;
19158 +               }
19159 +               if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19160 +                       if (*flags & IATTR_COW)
19161 +                               vflags |= V_COW;
19162 +                       else
19163 +                               vflags &= ~V_COW;
19164 +               }
19165 +               if (in->i_op && in->i_op->sync_flags) {
19166 +                       error = in->i_op->sync_flags(in, iflags, vflags);
19167 +                       if (error)
19168 +                               goto out;
19169 +               }
19170 +       }
19171 +
19172 +       if (attr.ia_valid) {
19173 +               if (in->i_op && in->i_op->setattr)
19174 +                       error = in->i_op->setattr(de, &attr);
19175 +               else {
19176 +                       error = inode_change_ok(in, &attr);
19177 +                       if (!error) {
19178 +                               setattr_copy(in, &attr);
19179 +                               mark_inode_dirty(in);
19180 +                       }
19181 +               }
19182 +       }
19183 +
19184 +out:
19185 +       mutex_unlock(&in->i_mutex);
19186 +       return error;
19187 +}
19188 +
19189 +int vc_set_iattr(void __user *data)
19190 +{
19191 +       struct path path;
19192 +       struct vcmd_ctx_iattr_v1 vc_data;
19193 +       int ret;
19194 +
19195 +       if (!capable(CAP_LINUX_IMMUTABLE))
19196 +               return -EPERM;
19197 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19198 +               return -EFAULT;
19199 +
19200 +       ret = user_lpath(vc_data.name, &path);
19201 +       if (!ret) {
19202 +               ret = __vc_set_iattr(path.dentry,
19203 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19204 +               path_put(&path);
19205 +       }
19206 +
19207 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19208 +               ret = -EFAULT;
19209 +       return ret;
19210 +}
19211 +
19212 +#ifdef CONFIG_COMPAT
19213 +
19214 +int vc_set_iattr_x32(void __user *data)
19215 +{
19216 +       struct path path;
19217 +       struct vcmd_ctx_iattr_v1_x32 vc_data;
19218 +       int ret;
19219 +
19220 +       if (!capable(CAP_LINUX_IMMUTABLE))
19221 +               return -EPERM;
19222 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19223 +               return -EFAULT;
19224 +
19225 +       ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19226 +       if (!ret) {
19227 +               ret = __vc_set_iattr(path.dentry,
19228 +                       &vc_data.tag, &vc_data.flags, &vc_data.mask);
19229 +               path_put(&path);
19230 +       }
19231 +
19232 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19233 +               ret = -EFAULT;
19234 +       return ret;
19235 +}
19236 +
19237 +#endif /* CONFIG_COMPAT */
19238 +
19239 +int vc_fset_iattr(uint32_t fd, void __user *data)
19240 +{
19241 +       struct file *filp;
19242 +       struct vcmd_ctx_fiattr_v0 vc_data;
19243 +       int ret;
19244 +
19245 +       if (!capable(CAP_LINUX_IMMUTABLE))
19246 +               return -EPERM;
19247 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19248 +               return -EFAULT;
19249 +
19250 +       filp = fget(fd);
19251 +       if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19252 +               return -EBADF;
19253 +
19254 +       ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19255 +               &vc_data.flags, &vc_data.mask);
19256 +
19257 +       fput(filp);
19258 +
19259 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19260 +               return -EFAULT;
19261 +       return ret;
19262 +}
19263 +
19264 +
19265 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19266 +
19267 +static match_table_t tokens = {
19268 +       {Opt_notagcheck, "notagcheck"},
19269 +#ifdef CONFIG_PROPAGATE
19270 +       {Opt_notag, "notag"},
19271 +       {Opt_tag, "tag"},
19272 +       {Opt_tagid, "tagid=%u"},
19273 +#endif
19274 +       {Opt_err, NULL}
19275 +};
19276 +
19277 +
19278 +static void __dx_parse_remove(char *string, char *opt)
19279 +{
19280 +       char *p = strstr(string, opt);
19281 +       char *q = p;
19282 +
19283 +       if (p) {
19284 +               while (*q != '\0' && *q != ',')
19285 +                       q++;
19286 +               while (*q)
19287 +                       *p++ = *q++;
19288 +               while (*p)
19289 +                       *p++ = '\0';
19290 +       }
19291 +}
19292 +
19293 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
19294 +                unsigned long *flags)
19295 +{
19296 +       int set = 0;
19297 +       substring_t args[MAX_OPT_ARGS];
19298 +       int token;
19299 +       char *s, *p, *opts;
19300 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19301 +       int option = 0;
19302 +#endif
19303 +
19304 +       if (!string)
19305 +               return 0;
19306 +       s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19307 +       if (!s)
19308 +               return 0;
19309 +
19310 +       opts = s;
19311 +       while ((p = strsep(&opts, ",")) != NULL) {
19312 +               token = match_token(p, tokens, args);
19313 +
19314 +               switch (token) {
19315 +#ifdef CONFIG_PROPAGATE
19316 +               case Opt_tag:
19317 +                       if (tag)
19318 +                               *tag = 0;
19319 +                       if (remove)
19320 +                               __dx_parse_remove(s, "tag");
19321 +                       *mnt_flags |= MNT_TAGID;
19322 +                       set |= MNT_TAGID;
19323 +                       break;
19324 +               case Opt_notag:
19325 +                       if (remove)
19326 +                               __dx_parse_remove(s, "notag");
19327 +                       *mnt_flags |= MNT_NOTAG;
19328 +                       set |= MNT_NOTAG;
19329 +                       break;
19330 +               case Opt_tagid:
19331 +                       if (tag && !match_int(args, &option))
19332 +                               *tag = option;
19333 +                       if (remove)
19334 +                               __dx_parse_remove(s, "tagid");
19335 +                       *mnt_flags |= MNT_TAGID;
19336 +                       set |= MNT_TAGID;
19337 +                       break;
19338 +#endif /* CONFIG_PROPAGATE */
19339 +               case Opt_notagcheck:
19340 +                       if (remove)
19341 +                               __dx_parse_remove(s, "notagcheck");
19342 +                       *flags |= MS_NOTAGCHECK;
19343 +                       set |= MS_NOTAGCHECK;
19344 +                       break;
19345 +               }
19346 +               vxdprintk(VXD_CBIT(tag, 7),
19347 +                       "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19348 +                       p, token, option);
19349 +       }
19350 +       if (set)
19351 +               strcpy(string, s);
19352 +       kfree(s);
19353 +       return set;
19354 +}
19355 +
19356 +#ifdef CONFIG_PROPAGATE
19357 +
19358 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19359 +{
19360 +       vtag_t new_tag = 0;
19361 +       struct vfsmount *mnt;
19362 +       int propagate;
19363 +
19364 +       if (!nd)
19365 +               return;
19366 +       mnt = nd->path.mnt;
19367 +       if (!mnt)
19368 +               return;
19369 +
19370 +       propagate = (mnt->mnt_flags & MNT_TAGID);
19371 +       if (propagate)
19372 +               new_tag = mnt->mnt_tag;
19373 +
19374 +       vxdprintk(VXD_CBIT(tag, 7),
19375 +               "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19376 +               inode, inode->i_ino, inode->i_tag,
19377 +               new_tag, (propagate) ? 1 : 0);
19378 +
19379 +       if (propagate)
19380 +               i_tag_write(inode, new_tag);
19381 +}
19382 +
19383 +#include <linux/module.h>
19384 +
19385 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19386 +
19387 +#endif /* CONFIG_PROPAGATE */
19388 +
19389 diff -NurpP --minimal linux-3.10.40/kernel/vserver/limit.c linux-3.10.40-vs2.3.6.8/kernel/vserver/limit.c
19390 --- linux-3.10.40/kernel/vserver/limit.c        1970-01-01 00:00:00.000000000 +0000
19391 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/limit.c      2013-08-22 20:30:00.000000000 +0000
19392 @@ -0,0 +1,345 @@
19393 +/*
19394 + *  linux/kernel/vserver/limit.c
19395 + *
19396 + *  Virtual Server: Context Limits
19397 + *
19398 + *  Copyright (C) 2004-2010  Herbert Pötzl
19399 + *
19400 + *  V0.01  broken out from vcontext V0.05
19401 + *  V0.02  changed vcmds to vxi arg
19402 + *  V0.03  added memory cgroup support
19403 + *
19404 + */
19405 +
19406 +#include <linux/sched.h>
19407 +#include <linux/module.h>
19408 +#include <linux/memcontrol.h>
19409 +#include <linux/res_counter.h>
19410 +#include <linux/vs_limit.h>
19411 +#include <linux/vserver/limit.h>
19412 +#include <linux/vserver/limit_cmd.h>
19413 +
19414 +#include <asm/uaccess.h>
19415 +
19416 +
19417 +const char *vlimit_name[NUM_LIMITS] = {
19418 +       [RLIMIT_CPU]            = "CPU",
19419 +       [RLIMIT_NPROC]          = "NPROC",
19420 +       [RLIMIT_NOFILE]         = "NOFILE",
19421 +       [RLIMIT_LOCKS]          = "LOCKS",
19422 +       [RLIMIT_SIGPENDING]     = "SIGP",
19423 +       [RLIMIT_MSGQUEUE]       = "MSGQ",
19424 +
19425 +       [VLIMIT_NSOCK]          = "NSOCK",
19426 +       [VLIMIT_OPENFD]         = "OPENFD",
19427 +       [VLIMIT_SHMEM]          = "SHMEM",
19428 +       [VLIMIT_DENTRY]         = "DENTRY",
19429 +};
19430 +
19431 +EXPORT_SYMBOL_GPL(vlimit_name);
19432 +
19433 +#define MASK_ENTRY(x)  (1 << (x))
19434 +
19435 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19436 +               /* minimum */
19437 +       0
19438 +       ,       /* softlimit */
19439 +       0
19440 +       ,       /* maximum */
19441 +       MASK_ENTRY( RLIMIT_NPROC        ) |
19442 +       MASK_ENTRY( RLIMIT_NOFILE       ) |
19443 +       MASK_ENTRY( RLIMIT_LOCKS        ) |
19444 +       MASK_ENTRY( RLIMIT_MSGQUEUE     ) |
19445 +
19446 +       MASK_ENTRY( VLIMIT_NSOCK        ) |
19447 +       MASK_ENTRY( VLIMIT_OPENFD       ) |
19448 +       MASK_ENTRY( VLIMIT_SHMEM        ) |
19449 +       MASK_ENTRY( VLIMIT_DENTRY       ) |
19450 +       0
19451 +};
19452 +               /* accounting only */
19453 +uint32_t account_mask =
19454 +       MASK_ENTRY( VLIMIT_SEMARY       ) |
19455 +       MASK_ENTRY( VLIMIT_NSEMS        ) |
19456 +       MASK_ENTRY( VLIMIT_MAPPED       ) |
19457 +       0;
19458 +
19459 +
19460 +static int is_valid_vlimit(int id)
19461 +{
19462 +       uint32_t mask = vlimit_mask.minimum |
19463 +               vlimit_mask.softlimit | vlimit_mask.maximum;
19464 +       return mask & (1 << id);
19465 +}
19466 +
19467 +static int is_accounted_vlimit(int id)
19468 +{
19469 +       if (is_valid_vlimit(id))
19470 +               return 1;
19471 +       return account_mask & (1 << id);
19472 +}
19473 +
19474 +
19475 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19476 +{
19477 +       rlim_t limit = __rlim_soft(&vxi->limit, id);
19478 +       return VX_VLIM(limit);
19479 +}
19480 +
19481 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19482 +{
19483 +       rlim_t limit = __rlim_hard(&vxi->limit, id);
19484 +       return VX_VLIM(limit);
19485 +}
19486 +
19487 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19488 +       uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19489 +{
19490 +       if (!is_valid_vlimit(id))
19491 +               return -EINVAL;
19492 +
19493 +       if (minimum)
19494 +               *minimum = CRLIM_UNSET;
19495 +       if (softlimit)
19496 +               *softlimit = vc_get_soft(vxi, id);
19497 +       if (maximum)
19498 +               *maximum = vc_get_hard(vxi, id);
19499 +       return 0;
19500 +}
19501 +
19502 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19503 +{
19504 +       struct vcmd_ctx_rlimit_v0 vc_data;
19505 +       int ret;
19506 +
19507 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19508 +               return -EFAULT;
19509 +
19510 +       ret = do_get_rlimit(vxi, vc_data.id,
19511 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19512 +       if (ret)
19513 +               return ret;
19514 +
19515 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19516 +               return -EFAULT;
19517 +       return 0;
19518 +}
19519 +
19520 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19521 +       uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19522 +{
19523 +       if (!is_valid_vlimit(id))
19524 +               return -EINVAL;
19525 +
19526 +       if (maximum != CRLIM_KEEP)
19527 +               __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19528 +       if (softlimit != CRLIM_KEEP)
19529 +               __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19530 +
19531 +       /* clamp soft limit */
19532 +       if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19533 +               __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19534 +
19535 +       return 0;
19536 +}
19537 +
19538 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19539 +{
19540 +       struct vcmd_ctx_rlimit_v0 vc_data;
19541 +
19542 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19543 +               return -EFAULT;
19544 +
19545 +       return do_set_rlimit(vxi, vc_data.id,
19546 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19547 +}
19548 +
19549 +#ifdef CONFIG_IA32_EMULATION
19550 +
19551 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19552 +{
19553 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19554 +
19555 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19556 +               return -EFAULT;
19557 +
19558 +       return do_set_rlimit(vxi, vc_data.id,
19559 +               vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19560 +}
19561 +
19562 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19563 +{
19564 +       struct vcmd_ctx_rlimit_v0_x32 vc_data;
19565 +       int ret;
19566 +
19567 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19568 +               return -EFAULT;
19569 +
19570 +       ret = do_get_rlimit(vxi, vc_data.id,
19571 +               &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19572 +       if (ret)
19573 +               return ret;
19574 +
19575 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19576 +               return -EFAULT;
19577 +       return 0;
19578 +}
19579 +
19580 +#endif /* CONFIG_IA32_EMULATION */
19581 +
19582 +
19583 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19584 +{
19585 +       if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19586 +               return -EFAULT;
19587 +       return 0;
19588 +}
19589 +
19590 +
19591 +static inline void vx_reset_hits(struct _vx_limit *limit)
19592 +{
19593 +       int lim;
19594 +
19595 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19596 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19597 +       }
19598 +}
19599 +
19600 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19601 +{
19602 +       vx_reset_hits(&vxi->limit);
19603 +       return 0;
19604 +}
19605 +
19606 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19607 +{
19608 +       rlim_t value;
19609 +       int lim;
19610 +
19611 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19612 +               value = __rlim_get(limit, lim);
19613 +               __rlim_rmax(limit, lim) = value;
19614 +               __rlim_rmin(limit, lim) = value;
19615 +       }
19616 +}
19617 +
19618 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19619 +{
19620 +       vx_reset_minmax(&vxi->limit);
19621 +       return 0;
19622 +}
19623 +
19624 +
19625 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19626 +{
19627 +       struct vcmd_rlimit_stat_v0 vc_data;
19628 +       struct _vx_limit *limit = &vxi->limit;
19629 +       int id;
19630 +
19631 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19632 +               return -EFAULT;
19633 +
19634 +       id = vc_data.id;
19635 +       if (!is_accounted_vlimit(id))
19636 +               return -EINVAL;
19637 +
19638 +       vx_limit_fixup(limit, id);
19639 +       vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19640 +       vc_data.value = __rlim_get(limit, id);
19641 +       vc_data.minimum = __rlim_rmin(limit, id);
19642 +       vc_data.maximum = __rlim_rmax(limit, id);
19643 +
19644 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19645 +               return -EFAULT;
19646 +       return 0;
19647 +}
19648 +
19649 +
19650 +void vx_vsi_meminfo(struct sysinfo *val)
19651 +{
19652 +#ifdef CONFIG_MEMCG
19653 +       struct mem_cgroup *mcg;
19654 +       u64 res_limit, res_usage;
19655 +
19656 +       rcu_read_lock();
19657 +       mcg = mem_cgroup_from_task(current);
19658 +       rcu_read_unlock();
19659 +       if (!mcg)
19660 +               goto out;
19661 +
19662 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19663 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19664 +
19665 +       if (res_limit != RESOURCE_MAX)
19666 +               val->totalram = (res_limit >> PAGE_SHIFT);
19667 +       val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19668 +       val->bufferram = 0;
19669 +       val->totalhigh = 0;
19670 +       val->freehigh = 0;
19671 +out:
19672 +#endif /* CONFIG_MEMCG */
19673 +       return;
19674 +}
19675 +
19676 +void vx_vsi_swapinfo(struct sysinfo *val)
19677 +{
19678 +#ifdef CONFIG_MEMCG
19679 +#ifdef CONFIG_MEMCG_SWAP
19680 +       struct mem_cgroup *mcg;
19681 +       u64 res_limit, res_usage, memsw_limit, memsw_usage;
19682 +       s64 swap_limit, swap_usage;
19683 +
19684 +       rcu_read_lock();
19685 +       mcg = mem_cgroup_from_task(current);
19686 +       rcu_read_unlock();
19687 +       if (!mcg)
19688 +               goto out;
19689 +
19690 +       res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19691 +       res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19692 +       memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19693 +       memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19694 +
19695 +       /* memory unlimited */
19696 +       if (res_limit == RESOURCE_MAX)
19697 +               goto out;
19698 +
19699 +       swap_limit = memsw_limit - res_limit;
19700 +       /* we have a swap limit? */
19701 +       if (memsw_limit != RESOURCE_MAX)
19702 +               val->totalswap = swap_limit >> PAGE_SHIFT;
19703 +
19704 +       /* calculate swap part */
19705 +       swap_usage = (memsw_usage > res_usage) ?
19706 +               memsw_usage - res_usage : 0;
19707 +
19708 +       /* total shown minus usage gives free swap */
19709 +       val->freeswap = (swap_usage < swap_limit) ?
19710 +               val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19711 +out:
19712 +#else  /* !CONFIG_MEMCG_SWAP */
19713 +       val->totalswap = 0;
19714 +       val->freeswap = 0;
19715 +#endif /* !CONFIG_MEMCG_SWAP */
19716 +#endif /* CONFIG_MEMCG */
19717 +       return;
19718 +}
19719 +
19720 +long vx_vsi_cached(struct sysinfo *val)
19721 +{
19722 +       long cache = 0;
19723 +#ifdef CONFIG_MEMCG
19724 +       struct mem_cgroup *mcg;
19725 +
19726 +       rcu_read_lock();
19727 +       mcg = mem_cgroup_from_task(current);
19728 +       rcu_read_unlock();
19729 +       if (!mcg)
19730 +               goto out;
19731 +
19732 +       cache = mem_cgroup_stat_read_cache(mcg);
19733 +out:
19734 +#endif
19735 +       return cache;
19736 +}
19737 +
19738 diff -NurpP --minimal linux-3.10.40/kernel/vserver/limit_init.h linux-3.10.40-vs2.3.6.8/kernel/vserver/limit_init.h
19739 --- linux-3.10.40/kernel/vserver/limit_init.h   1970-01-01 00:00:00.000000000 +0000
19740 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/limit_init.h 2013-08-22 20:30:00.000000000 +0000
19741 @@ -0,0 +1,31 @@
19742 +
19743 +
19744 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19745 +{
19746 +       int lim;
19747 +
19748 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19749 +               __rlim_soft(limit, lim) = RLIM_INFINITY;
19750 +               __rlim_hard(limit, lim) = RLIM_INFINITY;
19751 +               __rlim_set(limit, lim, 0);
19752 +               atomic_set(&__rlim_lhit(limit, lim), 0);
19753 +               __rlim_rmin(limit, lim) = 0;
19754 +               __rlim_rmax(limit, lim) = 0;
19755 +       }
19756 +}
19757 +
19758 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19759 +{
19760 +       rlim_t value;
19761 +       int lim;
19762 +
19763 +       for (lim = 0; lim < NUM_LIMITS; lim++) {
19764 +               if ((1 << lim) & VLIM_NOCHECK)
19765 +                       continue;
19766 +               value = __rlim_get(limit, lim);
19767 +               vxwprintk_xid(value,
19768 +                       "!!! limit: %p[%s,%d] = %ld on exit.",
19769 +                       limit, vlimit_name[lim], lim, (long)value);
19770 +       }
19771 +}
19772 +
19773 diff -NurpP --minimal linux-3.10.40/kernel/vserver/limit_proc.h linux-3.10.40-vs2.3.6.8/kernel/vserver/limit_proc.h
19774 --- linux-3.10.40/kernel/vserver/limit_proc.h   1970-01-01 00:00:00.000000000 +0000
19775 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/limit_proc.h 2013-08-22 20:30:00.000000000 +0000
19776 @@ -0,0 +1,57 @@
19777 +#ifndef _VX_LIMIT_PROC_H
19778 +#define _VX_LIMIT_PROC_H
19779 +
19780 +#include <linux/vserver/limit_int.h>
19781 +
19782 +
19783 +#define VX_LIMIT_FMT   ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19784 +#define VX_LIMIT_TOP   \
19785 +       "Limit\t current\t     min/max\t\t    soft/hard\t\thits\n"
19786 +
19787 +#define VX_LIMIT_ARG(r)                                \
19788 +       (unsigned long)__rlim_get(limit, r),    \
19789 +       (unsigned long)__rlim_rmin(limit, r),   \
19790 +       (unsigned long)__rlim_rmax(limit, r),   \
19791 +       VX_VLIM(__rlim_soft(limit, r)),         \
19792 +       VX_VLIM(__rlim_hard(limit, r)),         \
19793 +       atomic_read(&__rlim_lhit(limit, r))
19794 +
19795 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19796 +{
19797 +       vx_limit_fixup(limit, -1);
19798 +       return sprintf(buffer, VX_LIMIT_TOP
19799 +               "PROC"  VX_LIMIT_FMT
19800 +               "VM"    VX_LIMIT_FMT
19801 +               "VML"   VX_LIMIT_FMT
19802 +               "RSS"   VX_LIMIT_FMT
19803 +               "ANON"  VX_LIMIT_FMT
19804 +               "RMAP"  VX_LIMIT_FMT
19805 +               "FILES" VX_LIMIT_FMT
19806 +               "OFD"   VX_LIMIT_FMT
19807 +               "LOCKS" VX_LIMIT_FMT
19808 +               "SOCK"  VX_LIMIT_FMT
19809 +               "MSGQ"  VX_LIMIT_FMT
19810 +               "SHM"   VX_LIMIT_FMT
19811 +               "SEMA"  VX_LIMIT_FMT
19812 +               "SEMS"  VX_LIMIT_FMT
19813 +               "DENT"  VX_LIMIT_FMT,
19814 +               VX_LIMIT_ARG(RLIMIT_NPROC),
19815 +               VX_LIMIT_ARG(RLIMIT_AS),
19816 +               VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19817 +               VX_LIMIT_ARG(RLIMIT_RSS),
19818 +               VX_LIMIT_ARG(VLIMIT_ANON),
19819 +               VX_LIMIT_ARG(VLIMIT_MAPPED),
19820 +               VX_LIMIT_ARG(RLIMIT_NOFILE),
19821 +               VX_LIMIT_ARG(VLIMIT_OPENFD),
19822 +               VX_LIMIT_ARG(RLIMIT_LOCKS),
19823 +               VX_LIMIT_ARG(VLIMIT_NSOCK),
19824 +               VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19825 +               VX_LIMIT_ARG(VLIMIT_SHMEM),
19826 +               VX_LIMIT_ARG(VLIMIT_SEMARY),
19827 +               VX_LIMIT_ARG(VLIMIT_NSEMS),
19828 +               VX_LIMIT_ARG(VLIMIT_DENTRY));
19829 +}
19830 +
19831 +#endif /* _VX_LIMIT_PROC_H */
19832 +
19833 +
19834 diff -NurpP --minimal linux-3.10.40/kernel/vserver/network.c linux-3.10.40-vs2.3.6.8/kernel/vserver/network.c
19835 --- linux-3.10.40/kernel/vserver/network.c      1970-01-01 00:00:00.000000000 +0000
19836 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/network.c    2013-08-22 20:30:00.000000000 +0000
19837 @@ -0,0 +1,1053 @@
19838 +/*
19839 + *  linux/kernel/vserver/network.c
19840 + *
19841 + *  Virtual Server: Network Support
19842 + *
19843 + *  Copyright (C) 2003-2007  Herbert Pötzl
19844 + *
19845 + *  V0.01  broken out from vcontext V0.05
19846 + *  V0.02  cleaned up implementation
19847 + *  V0.03  added equiv nx commands
19848 + *  V0.04  switch to RCU based hash
19849 + *  V0.05  and back to locking again
19850 + *  V0.06  changed vcmds to nxi arg
19851 + *  V0.07  have __create claim() the nxi
19852 + *
19853 + */
19854 +
19855 +#include <linux/err.h>
19856 +#include <linux/slab.h>
19857 +#include <linux/rcupdate.h>
19858 +#include <net/ipv6.h>
19859 +
19860 +#include <linux/vs_network.h>
19861 +#include <linux/vs_pid.h>
19862 +#include <linux/vserver/network_cmd.h>
19863 +
19864 +
19865 +atomic_t nx_global_ctotal      = ATOMIC_INIT(0);
19866 +atomic_t nx_global_cactive     = ATOMIC_INIT(0);
19867 +
19868 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19869 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19870 +
19871 +
19872 +static int __init init_network(void)
19873 +{
19874 +       nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19875 +               sizeof(struct nx_addr_v4), 0,
19876 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19877 +       nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19878 +               sizeof(struct nx_addr_v6), 0,
19879 +               SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19880 +       return 0;
19881 +}
19882 +
19883 +
19884 +/*     __alloc_nx_addr_v4()                                    */
19885 +
19886 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19887 +{
19888 +       struct nx_addr_v4 *nxa = kmem_cache_alloc(
19889 +               nx_addr_v4_cachep, GFP_KERNEL);
19890 +
19891 +       if (!IS_ERR(nxa))
19892 +               memset(nxa, 0, sizeof(*nxa));
19893 +       return nxa;
19894 +}
19895 +
19896 +/*     __dealloc_nx_addr_v4()                                  */
19897 +
19898 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19899 +{
19900 +       kmem_cache_free(nx_addr_v4_cachep, nxa);
19901 +}
19902 +
19903 +/*     __dealloc_nx_addr_v4_all()                              */
19904 +
19905 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19906 +{
19907 +       while (nxa) {
19908 +               struct nx_addr_v4 *next = nxa->next;
19909 +
19910 +               __dealloc_nx_addr_v4(nxa);
19911 +               nxa = next;
19912 +       }
19913 +}
19914 +
19915 +
19916 +#ifdef CONFIG_IPV6
19917 +
19918 +/*     __alloc_nx_addr_v6()                                    */
19919 +
19920 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19921 +{
19922 +       struct nx_addr_v6 *nxa = kmem_cache_alloc(
19923 +               nx_addr_v6_cachep, GFP_KERNEL);
19924 +
19925 +       if (!IS_ERR(nxa))
19926 +               memset(nxa, 0, sizeof(*nxa));
19927 +       return nxa;
19928 +}
19929 +
19930 +/*     __dealloc_nx_addr_v6()                                  */
19931 +
19932 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19933 +{
19934 +       kmem_cache_free(nx_addr_v6_cachep, nxa);
19935 +}
19936 +
19937 +/*     __dealloc_nx_addr_v6_all()                              */
19938 +
19939 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19940 +{
19941 +       while (nxa) {
19942 +               struct nx_addr_v6 *next = nxa->next;
19943 +
19944 +               __dealloc_nx_addr_v6(nxa);
19945 +               nxa = next;
19946 +       }
19947 +}
19948 +
19949 +#endif /* CONFIG_IPV6 */
19950 +
19951 +/*     __alloc_nx_info()
19952 +
19953 +       * allocate an initialized nx_info struct
19954 +       * doesn't make it visible (hash)                        */
19955 +
19956 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19957 +{
19958 +       struct nx_info *new = NULL;
19959 +
19960 +       vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19961 +
19962 +       /* would this benefit from a slab cache? */
19963 +       new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19964 +       if (!new)
19965 +               return 0;
19966 +
19967 +       memset(new, 0, sizeof(struct nx_info));
19968 +       new->nx_id = nid;
19969 +       INIT_HLIST_NODE(&new->nx_hlist);
19970 +       atomic_set(&new->nx_usecnt, 0);
19971 +       atomic_set(&new->nx_tasks, 0);
19972 +       spin_lock_init(&new->addr_lock);
19973 +       new->nx_state = 0;
19974 +
19975 +       new->nx_flags = NXF_INIT_SET;
19976 +
19977 +       /* rest of init goes here */
19978 +
19979 +       new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19980 +       new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19981 +
19982 +       vxdprintk(VXD_CBIT(nid, 0),
19983 +               "alloc_nx_info(%d) = %p", nid, new);
19984 +       atomic_inc(&nx_global_ctotal);
19985 +       return new;
19986 +}
19987 +
19988 +/*     __dealloc_nx_info()
19989 +
19990 +       * final disposal of nx_info                             */
19991 +
19992 +static void __dealloc_nx_info(struct nx_info *nxi)
19993 +{
19994 +       vxdprintk(VXD_CBIT(nid, 0),
19995 +               "dealloc_nx_info(%p)", nxi);
19996 +
19997 +       nxi->nx_hlist.next = LIST_POISON1;
19998 +       nxi->nx_id = -1;
19999 +
20000 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20001 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20002 +
20003 +       __dealloc_nx_addr_v4_all(nxi->v4.next);
20004 +#ifdef CONFIG_IPV6
20005 +       __dealloc_nx_addr_v6_all(nxi->v6.next);
20006 +#endif
20007 +
20008 +       nxi->nx_state |= NXS_RELEASED;
20009 +       kfree(nxi);
20010 +       atomic_dec(&nx_global_ctotal);
20011 +}
20012 +
20013 +static void __shutdown_nx_info(struct nx_info *nxi)
20014 +{
20015 +       nxi->nx_state |= NXS_SHUTDOWN;
20016 +       vs_net_change(nxi, VSC_NETDOWN);
20017 +}
20018 +
20019 +/*     exported stuff                                          */
20020 +
20021 +void free_nx_info(struct nx_info *nxi)
20022 +{
20023 +       /* context shutdown is mandatory */
20024 +       BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20025 +
20026 +       /* context must not be hashed */
20027 +       BUG_ON(nxi->nx_state & NXS_HASHED);
20028 +
20029 +       BUG_ON(atomic_read(&nxi->nx_usecnt));
20030 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20031 +
20032 +       __dealloc_nx_info(nxi);
20033 +}
20034 +
20035 +
20036 +void __nx_set_lback(struct nx_info *nxi)
20037 +{
20038 +       int nid = nxi->nx_id;
20039 +       __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20040 +
20041 +       nxi->v4_lback.s_addr = lback;
20042 +}
20043 +
20044 +extern int __nx_inet_add_lback(__be32 addr);
20045 +extern int __nx_inet_del_lback(__be32 addr);
20046 +
20047 +
20048 +/*     hash table for nx_info hash */
20049 +
20050 +#define NX_HASH_SIZE   13
20051 +
20052 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20053 +
20054 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20055 +
20056 +
20057 +static inline unsigned int __hashval(vnid_t nid)
20058 +{
20059 +       return (nid % NX_HASH_SIZE);
20060 +}
20061 +
20062 +
20063 +
20064 +/*     __hash_nx_info()
20065 +
20066 +       * add the nxi to the global hash table
20067 +       * requires the hash_lock to be held                     */
20068 +
20069 +static inline void __hash_nx_info(struct nx_info *nxi)
20070 +{
20071 +       struct hlist_head *head;
20072 +
20073 +       vxd_assert_lock(&nx_info_hash_lock);
20074 +       vxdprintk(VXD_CBIT(nid, 4),
20075 +               "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20076 +
20077 +       /* context must not be hashed */
20078 +       BUG_ON(nx_info_state(nxi, NXS_HASHED));
20079 +
20080 +       nxi->nx_state |= NXS_HASHED;
20081 +       head = &nx_info_hash[__hashval(nxi->nx_id)];
20082 +       hlist_add_head(&nxi->nx_hlist, head);
20083 +       atomic_inc(&nx_global_cactive);
20084 +}
20085 +
20086 +/*     __unhash_nx_info()
20087 +
20088 +       * remove the nxi from the global hash table
20089 +       * requires the hash_lock to be held                     */
20090 +
20091 +static inline void __unhash_nx_info(struct nx_info *nxi)
20092 +{
20093 +       vxd_assert_lock(&nx_info_hash_lock);
20094 +       vxdprintk(VXD_CBIT(nid, 4),
20095 +               "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20096 +               atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20097 +
20098 +       /* context must be hashed */
20099 +       BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20100 +       /* but without tasks */
20101 +       BUG_ON(atomic_read(&nxi->nx_tasks));
20102 +
20103 +       nxi->nx_state &= ~NXS_HASHED;
20104 +       hlist_del(&nxi->nx_hlist);
20105 +       atomic_dec(&nx_global_cactive);
20106 +}
20107 +
20108 +
20109 +/*     __lookup_nx_info()
20110 +
20111 +       * requires the hash_lock to be held
20112 +       * doesn't increment the nx_refcnt                       */
20113 +
20114 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
20115 +{
20116 +       struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20117 +       struct hlist_node *pos;
20118 +       struct nx_info *nxi;
20119 +
20120 +       vxd_assert_lock(&nx_info_hash_lock);
20121 +       hlist_for_each(pos, head) {
20122 +               nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20123 +
20124 +               if (nxi->nx_id == nid)
20125 +                       goto found;
20126 +       }
20127 +       nxi = NULL;
20128 +found:
20129 +       vxdprintk(VXD_CBIT(nid, 0),
20130 +               "__lookup_nx_info(#%u): %p[#%u]",
20131 +               nid, nxi, nxi ? nxi->nx_id : 0);
20132 +       return nxi;
20133 +}
20134 +
20135 +
20136 +/*     __create_nx_info()
20137 +
20138 +       * create the requested context
20139 +       * get(), claim() and hash it                            */
20140 +
20141 +static struct nx_info *__create_nx_info(int id)
20142 +{
20143 +       struct nx_info *new, *nxi = NULL;
20144 +
20145 +       vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20146 +
20147 +       if (!(new = __alloc_nx_info(id)))
20148 +               return ERR_PTR(-ENOMEM);
20149 +
20150 +       /* required to make dynamic xids unique */
20151 +       spin_lock(&nx_info_hash_lock);
20152 +
20153 +       /* static context requested */
20154 +       if ((nxi = __lookup_nx_info(id))) {
20155 +               vxdprintk(VXD_CBIT(nid, 0),
20156 +                       "create_nx_info(%d) = %p (already there)", id, nxi);
20157 +               if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20158 +                       nxi = ERR_PTR(-EBUSY);
20159 +               else
20160 +                       nxi = ERR_PTR(-EEXIST);
20161 +               goto out_unlock;
20162 +       }
20163 +       /* new context */
20164 +       vxdprintk(VXD_CBIT(nid, 0),
20165 +               "create_nx_info(%d) = %p (new)", id, new);
20166 +       claim_nx_info(new, NULL);
20167 +       __nx_set_lback(new);
20168 +       __hash_nx_info(get_nx_info(new));
20169 +       nxi = new, new = NULL;
20170 +
20171 +out_unlock:
20172 +       spin_unlock(&nx_info_hash_lock);
20173 +       if (new)
20174 +               __dealloc_nx_info(new);
20175 +       return nxi;
20176 +}
20177 +
20178 +
20179 +
20180 +/*     exported stuff                                          */
20181 +
20182 +
20183 +void unhash_nx_info(struct nx_info *nxi)
20184 +{
20185 +       __shutdown_nx_info(nxi);
20186 +       spin_lock(&nx_info_hash_lock);
20187 +       __unhash_nx_info(nxi);
20188 +       spin_unlock(&nx_info_hash_lock);
20189 +}
20190 +
20191 +/*     lookup_nx_info()
20192 +
20193 +       * search for a nx_info and get() it
20194 +       * negative id means current                             */
20195 +
20196 +struct nx_info *lookup_nx_info(int id)
20197 +{
20198 +       struct nx_info *nxi = NULL;
20199 +
20200 +       if (id < 0) {
20201 +               nxi = get_nx_info(current_nx_info());
20202 +       } else if (id > 1) {
20203 +               spin_lock(&nx_info_hash_lock);
20204 +               nxi = get_nx_info(__lookup_nx_info(id));
20205 +               spin_unlock(&nx_info_hash_lock);
20206 +       }
20207 +       return nxi;
20208 +}
20209 +
20210 +/*     nid_is_hashed()
20211 +
20212 +       * verify that nid is still hashed                       */
20213 +
20214 +int nid_is_hashed(vnid_t nid)
20215 +{
20216 +       int hashed;
20217 +
20218 +       spin_lock(&nx_info_hash_lock);
20219 +       hashed = (__lookup_nx_info(nid) != NULL);
20220 +       spin_unlock(&nx_info_hash_lock);
20221 +       return hashed;
20222 +}
20223 +
20224 +
20225 +#ifdef CONFIG_PROC_FS
20226 +
20227 +/*     get_nid_list()
20228 +
20229 +       * get a subset of hashed nids for proc
20230 +       * assumes size is at least one                          */
20231 +
20232 +int get_nid_list(int index, unsigned int *nids, int size)
20233 +{
20234 +       int hindex, nr_nids = 0;
20235 +
20236 +       /* only show current and children */
20237 +       if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20238 +               if (index > 0)
20239 +                       return 0;
20240 +               nids[nr_nids] = nx_current_nid();
20241 +               return 1;
20242 +       }
20243 +
20244 +       for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20245 +               struct hlist_head *head = &nx_info_hash[hindex];
20246 +               struct hlist_node *pos;
20247 +
20248 +               spin_lock(&nx_info_hash_lock);
20249 +               hlist_for_each(pos, head) {
20250 +                       struct nx_info *nxi;
20251 +
20252 +                       if (--index > 0)
20253 +                               continue;
20254 +
20255 +                       nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20256 +                       nids[nr_nids] = nxi->nx_id;
20257 +                       if (++nr_nids >= size) {
20258 +                               spin_unlock(&nx_info_hash_lock);
20259 +                               goto out;
20260 +                       }
20261 +               }
20262 +               /* keep the lock time short */
20263 +               spin_unlock(&nx_info_hash_lock);
20264 +       }
20265 +out:
20266 +       return nr_nids;
20267 +}
20268 +#endif
20269 +
20270 +
20271 +/*
20272 + *     migrate task to new network
20273 + *     gets nxi, puts old_nxi on change
20274 + */
20275 +
20276 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20277 +{
20278 +       struct nx_info *old_nxi;
20279 +       int ret = 0;
20280 +
20281 +       if (!p || !nxi)
20282 +               BUG();
20283 +
20284 +       vxdprintk(VXD_CBIT(nid, 5),
20285 +               "nx_migrate_task(%p,%p[#%d.%d.%d])",
20286 +               p, nxi, nxi->nx_id,
20287 +               atomic_read(&nxi->nx_usecnt),
20288 +               atomic_read(&nxi->nx_tasks));
20289 +
20290 +       if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20291 +               !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20292 +               return -EACCES;
20293 +
20294 +       if (nx_info_state(nxi, NXS_SHUTDOWN))
20295 +               return -EFAULT;
20296 +
20297 +       /* maybe disallow this completely? */
20298 +       old_nxi = task_get_nx_info(p);
20299 +       if (old_nxi == nxi)
20300 +               goto out;
20301 +
20302 +       task_lock(p);
20303 +       if (old_nxi)
20304 +               clr_nx_info(&p->nx_info);
20305 +       claim_nx_info(nxi, p);
20306 +       set_nx_info(&p->nx_info, nxi);
20307 +       p->nid = nxi->nx_id;
20308 +       task_unlock(p);
20309 +
20310 +       vxdprintk(VXD_CBIT(nid, 5),
20311 +               "moved task %p into nxi:%p[#%d]",
20312 +               p, nxi, nxi->nx_id);
20313 +
20314 +       if (old_nxi)
20315 +               release_nx_info(old_nxi, p);
20316 +       ret = 0;
20317 +out:
20318 +       put_nx_info(old_nxi);
20319 +       return ret;
20320 +}
20321 +
20322 +
20323 +void nx_set_persistent(struct nx_info *nxi)
20324 +{
20325 +       vxdprintk(VXD_CBIT(nid, 6),
20326 +               "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20327 +
20328 +       get_nx_info(nxi);
20329 +       claim_nx_info(nxi, NULL);
20330 +}
20331 +
20332 +void nx_clear_persistent(struct nx_info *nxi)
20333 +{
20334 +       vxdprintk(VXD_CBIT(nid, 6),
20335 +               "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20336 +
20337 +       release_nx_info(nxi, NULL);
20338 +       put_nx_info(nxi);
20339 +}
20340 +
20341 +void nx_update_persistent(struct nx_info *nxi)
20342 +{
20343 +       if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20344 +               nx_set_persistent(nxi);
20345 +       else
20346 +               nx_clear_persistent(nxi);
20347 +}
20348 +
20349 +/* vserver syscall commands below here */
20350 +
20351 +/* taks nid and nx_info functions */
20352 +
20353 +#include <asm/uaccess.h>
20354 +
20355 +
20356 +int vc_task_nid(uint32_t id)
20357 +{
20358 +       vnid_t nid;
20359 +
20360 +       if (id) {
20361 +               struct task_struct *tsk;
20362 +
20363 +               rcu_read_lock();
20364 +               tsk = find_task_by_real_pid(id);
20365 +               nid = (tsk) ? tsk->nid : -ESRCH;
20366 +               rcu_read_unlock();
20367 +       } else
20368 +               nid = nx_current_nid();
20369 +       return nid;
20370 +}
20371 +
20372 +
20373 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20374 +{
20375 +       struct vcmd_nx_info_v0 vc_data;
20376 +
20377 +       vc_data.nid = nxi->nx_id;
20378 +
20379 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20380 +               return -EFAULT;
20381 +       return 0;
20382 +}
20383 +
20384 +
20385 +/* network functions */
20386 +
20387 +int vc_net_create(uint32_t nid, void __user *data)
20388 +{
20389 +       struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20390 +       struct nx_info *new_nxi;
20391 +       int ret;
20392 +
20393 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20394 +               return -EFAULT;
20395 +
20396 +       if ((nid > MAX_S_CONTEXT) || (nid < 2))
20397 +               return -EINVAL;
20398 +
20399 +       new_nxi = __create_nx_info(nid);
20400 +       if (IS_ERR(new_nxi))
20401 +               return PTR_ERR(new_nxi);
20402 +
20403 +       /* initial flags */
20404 +       new_nxi->nx_flags = vc_data.flagword;
20405 +
20406 +       ret = -ENOEXEC;
20407 +       if (vs_net_change(new_nxi, VSC_NETUP))
20408 +               goto out;
20409 +
20410 +       ret = nx_migrate_task(current, new_nxi);
20411 +       if (ret)
20412 +               goto out;
20413 +
20414 +       /* return context id on success */
20415 +       ret = new_nxi->nx_id;
20416 +
20417 +       /* get a reference for persistent contexts */
20418 +       if ((vc_data.flagword & NXF_PERSISTENT))
20419 +               nx_set_persistent(new_nxi);
20420 +out:
20421 +       release_nx_info(new_nxi, NULL);
20422 +       put_nx_info(new_nxi);
20423 +       return ret;
20424 +}
20425 +
20426 +
20427 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20428 +{
20429 +       return nx_migrate_task(current, nxi);
20430 +}
20431 +
20432 +
20433 +static inline
20434 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
20435 +       __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
20436 +       struct nx_addr_v4 **prev)
20437 +{
20438 +       struct nx_addr_v4 *nxa = &nxi->v4;
20439 +
20440 +       for (; nxa; nxa = nxa->next) {
20441 +               if ((nxa->ip[0].s_addr == ip) &&
20442 +                   (nxa->ip[1].s_addr == ip2) &&
20443 +                   (nxa->mask.s_addr == mask) &&
20444 +                   (nxa->type == type) &&
20445 +                   (nxa->flags == flags))
20446 +                   return nxa;
20447 +
20448 +               /* save previous entry */
20449 +               if (prev)
20450 +                       *prev = nxa;
20451 +       }
20452 +       return NULL;
20453 +}
20454 +
20455 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20456 +       uint16_t type, uint16_t flags)
20457 +{
20458 +       struct nx_addr_v4 *nxa = NULL;
20459 +       struct nx_addr_v4 *new = __alloc_nx_addr_v4();
20460 +       unsigned long irqflags;
20461 +       int ret = -EEXIST;
20462 +
20463 +       if (IS_ERR(new))
20464 +               return PTR_ERR(new);
20465 +
20466 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20467 +       if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
20468 +               goto out_unlock;
20469 +
20470 +       if (NX_IPV4(nxi)) {
20471 +               nxa->next = new;
20472 +               nxa = new;
20473 +               new = NULL;
20474 +
20475 +               /* remove single ip for ip list */
20476 +               nxi->nx_flags &= ~NXF_SINGLE_IP;
20477 +       }
20478 +
20479 +       nxa->ip[0].s_addr = ip;
20480 +       nxa->ip[1].s_addr = ip2;
20481 +       nxa->mask.s_addr = mask;
20482 +       nxa->type = type;
20483 +       nxa->flags = flags;
20484 +       ret = 0;
20485 +out_unlock:
20486 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20487 +       if (new)
20488 +               __dealloc_nx_addr_v4(new);
20489 +       return ret;
20490 +}
20491 +
20492 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20493 +       uint16_t type, uint16_t flags)
20494 +{
20495 +       struct nx_addr_v4 *nxa = NULL;
20496 +       struct nx_addr_v4 *old = NULL;
20497 +       unsigned long irqflags;
20498 +       int ret = 0;
20499 +
20500 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20501 +       switch (type) {
20502 +       case NXA_TYPE_ADDR:
20503 +               old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
20504 +               if (old) {
20505 +                       if (nxa) {
20506 +                               nxa->next = old->next;
20507 +                               old->next = NULL;
20508 +                       } else {
20509 +                               if (old->next) {
20510 +                                       nxa = old;
20511 +                                       old = old->next;
20512 +                                       *nxa = *old;
20513 +                                       old->next = NULL;
20514 +                               } else {
20515 +                                       memset(old, 0, sizeof(*old));
20516 +                                       old = NULL;
20517 +                               }
20518 +                       }
20519 +               } else
20520 +                       ret = -ESRCH;
20521 +               break;
20522 +
20523 +       case NXA_TYPE_ANY:
20524 +               nxa = &nxi->v4;
20525 +               old = nxa->next;
20526 +               memset(nxa, 0, sizeof(*nxa));
20527 +               break;
20528 +
20529 +       default:
20530 +               ret = -EINVAL;
20531 +       }
20532 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20533 +       __dealloc_nx_addr_v4_all(old);
20534 +       return ret;
20535 +}
20536 +
20537 +
20538 +int vc_net_add(struct nx_info *nxi, void __user *data)
20539 +{
20540 +       struct vcmd_net_addr_v0 vc_data;
20541 +       int index, ret = 0;
20542 +
20543 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20544 +               return -EFAULT;
20545 +
20546 +       switch (vc_data.type) {
20547 +       case NXA_TYPE_IPV4:
20548 +               if ((vc_data.count < 1) || (vc_data.count > 4))
20549 +                       return -EINVAL;
20550 +
20551 +               index = 0;
20552 +               while (index < vc_data.count) {
20553 +                       ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20554 +                               vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20555 +                       if (ret)
20556 +                               return ret;
20557 +                       index++;
20558 +               }
20559 +               ret = index;
20560 +               break;
20561 +
20562 +       case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20563 +               nxi->v4_bcast = vc_data.ip[0];
20564 +               ret = 1;
20565 +               break;
20566 +
20567 +       case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20568 +               nxi->v4_lback = vc_data.ip[0];
20569 +               ret = 1;
20570 +               break;
20571 +
20572 +       default:
20573 +               ret = -EINVAL;
20574 +               break;
20575 +       }
20576 +       return ret;
20577 +}
20578 +
20579 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20580 +{
20581 +       struct vcmd_net_addr_v0 vc_data;
20582 +
20583 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20584 +               return -EFAULT;
20585 +
20586 +       switch (vc_data.type) {
20587 +       case NXA_TYPE_ANY:
20588 +               return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
20589 +       default:
20590 +               return -EINVAL;
20591 +       }
20592 +       return 0;
20593 +}
20594 +
20595 +
20596 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20597 +{
20598 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20599 +
20600 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20601 +               return -EFAULT;
20602 +
20603 +       switch (vc_data.type) {
20604 +       case NXA_TYPE_ADDR:
20605 +       case NXA_TYPE_MASK:
20606 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20607 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20608 +
20609 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20610 +               nxi->v4_bcast = vc_data.ip;
20611 +               break;
20612 +
20613 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20614 +               nxi->v4_lback = vc_data.ip;
20615 +               break;
20616 +
20617 +       default:
20618 +               return -EINVAL;
20619 +       }
20620 +       return 0;
20621 +}
20622 +
20623 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20624 +{
20625 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20626 +
20627 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20628 +               return -EFAULT;
20629 +
20630 +       switch (vc_data.type) {
20631 +       case NXA_TYPE_ADDR:
20632 +       case NXA_TYPE_MASK:
20633 +       case NXA_TYPE_RANGE:
20634 +               return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20635 +                       vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20636 +
20637 +       case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20638 +               nxi->v4_bcast = vc_data.ip;
20639 +               break;
20640 +
20641 +       case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20642 +               nxi->v4_lback = vc_data.ip;
20643 +               break;
20644 +
20645 +       default:
20646 +               return -EINVAL;
20647 +       }
20648 +       return 0;
20649 +}
20650 +
20651 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20652 +{
20653 +       struct vcmd_net_addr_ipv4_v1 vc_data;
20654 +
20655 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20656 +               return -EFAULT;
20657 +
20658 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20659 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20660 +}
20661 +
20662 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20663 +{
20664 +       struct vcmd_net_addr_ipv4_v2 vc_data;
20665 +
20666 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20667 +               return -EFAULT;
20668 +
20669 +       return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20670 +               vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20671 +}
20672 +
20673 +#ifdef CONFIG_IPV6
20674 +
20675 +static inline
20676 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20677 +       struct in6_addr *ip, struct in6_addr *mask,
20678 +       uint32_t prefix, uint16_t type, uint16_t flags,
20679 +       struct nx_addr_v6 **prev)
20680 +{
20681 +       struct nx_addr_v6 *nxa = &nxi->v6;
20682 +
20683 +       for (; nxa; nxa = nxa->next) {
20684 +               if (ipv6_addr_equal(&nxa->ip, ip) &&
20685 +                   ipv6_addr_equal(&nxa->mask, mask) &&
20686 +                   (nxa->prefix == prefix) &&
20687 +                   (nxa->type == type) &&
20688 +                   (nxa->flags == flags))
20689 +                   return nxa;
20690 +
20691 +               /* save previous entry */
20692 +               if (prev)
20693 +                       *prev = nxa;
20694 +       }
20695 +       return NULL;
20696 +}
20697 +
20698 +
20699 +int do_add_v6_addr(struct nx_info *nxi,
20700 +       struct in6_addr *ip, struct in6_addr *mask,
20701 +       uint32_t prefix, uint16_t type, uint16_t flags)
20702 +{
20703 +       struct nx_addr_v6 *nxa = NULL;
20704 +       struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20705 +       unsigned long irqflags;
20706 +       int ret = -EEXIST;
20707 +
20708 +       if (IS_ERR(new))
20709 +               return PTR_ERR(new);
20710 +
20711 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20712 +       if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20713 +               goto out_unlock;
20714 +
20715 +       if (NX_IPV6(nxi)) {
20716 +               nxa->next = new;
20717 +               nxa = new;
20718 +               new = NULL;
20719 +       }
20720 +
20721 +       nxa->ip = *ip;
20722 +       nxa->mask = *mask;
20723 +       nxa->prefix = prefix;
20724 +       nxa->type = type;
20725 +       nxa->flags = flags;
20726 +       ret = 0;
20727 +out_unlock:
20728 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20729 +       if (new)
20730 +               __dealloc_nx_addr_v6(new);
20731 +       return ret;
20732 +}
20733 +
20734 +int do_remove_v6_addr(struct nx_info *nxi,
20735 +       struct in6_addr *ip, struct in6_addr *mask,
20736 +       uint32_t prefix, uint16_t type, uint16_t flags)
20737 +{
20738 +       struct nx_addr_v6 *nxa = NULL;
20739 +       struct nx_addr_v6 *old = NULL;
20740 +       unsigned long irqflags;
20741 +       int ret = 0;
20742 +
20743 +       spin_lock_irqsave(&nxi->addr_lock, irqflags);
20744 +       switch (type) {
20745 +       case NXA_TYPE_ADDR:
20746 +               old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20747 +               if (old) {
20748 +                       if (nxa) {
20749 +                               nxa->next = old->next;
20750 +                               old->next = NULL;
20751 +                       } else {
20752 +                               if (old->next) {
20753 +                                       nxa = old;
20754 +                                       old = old->next;
20755 +                                       *nxa = *old;
20756 +                                       old->next = NULL;
20757 +                               } else {
20758 +                                       memset(old, 0, sizeof(*old));
20759 +                                       old = NULL;
20760 +                               }
20761 +                       }
20762 +               } else
20763 +                       ret = -ESRCH;
20764 +               break;
20765 +
20766 +       case NXA_TYPE_ANY:
20767 +               nxa = &nxi->v6;
20768 +               old = nxa->next;
20769 +               memset(nxa, 0, sizeof(*nxa));
20770 +               break;
20771 +
20772 +       default:
20773 +               ret = -EINVAL;
20774 +       }
20775 +       spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20776 +       __dealloc_nx_addr_v6_all(old);
20777 +       return ret;
20778 +}
20779 +
20780 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20781 +{
20782 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20783 +
20784 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20785 +               return -EFAULT;
20786 +
20787 +       switch (vc_data.type) {
20788 +       case NXA_TYPE_ADDR:
20789 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20790 +               /* fallthrough */
20791 +       case NXA_TYPE_MASK:
20792 +               return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20793 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20794 +       default:
20795 +               return -EINVAL;
20796 +       }
20797 +       return 0;
20798 +}
20799 +
20800 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20801 +{
20802 +       struct vcmd_net_addr_ipv6_v1 vc_data;
20803 +
20804 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20805 +               return -EFAULT;
20806 +
20807 +       switch (vc_data.type) {
20808 +       case NXA_TYPE_ADDR:
20809 +               memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20810 +               /* fallthrough */
20811 +       case NXA_TYPE_MASK:
20812 +               return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20813 +                       vc_data.prefix, vc_data.type, vc_data.flags);
20814 +       case NXA_TYPE_ANY:
20815 +               return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20816 +       default:
20817 +               return -EINVAL;
20818 +       }
20819 +       return 0;
20820 +}
20821 +
20822 +#endif /* CONFIG_IPV6 */
20823 +
20824 +
20825 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20826 +{
20827 +       struct vcmd_net_flags_v0 vc_data;
20828 +
20829 +       vc_data.flagword = nxi->nx_flags;
20830 +
20831 +       /* special STATE flag handling */
20832 +       vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20833 +
20834 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20835 +               return -EFAULT;
20836 +       return 0;
20837 +}
20838 +
20839 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20840 +{
20841 +       struct vcmd_net_flags_v0 vc_data;
20842 +       uint64_t mask, trigger;
20843 +
20844 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20845 +               return -EFAULT;
20846 +
20847 +       /* special STATE flag handling */
20848 +       mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20849 +       trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20850 +
20851 +       nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20852 +               vc_data.flagword, mask);
20853 +       if (trigger & NXF_PERSISTENT)
20854 +               nx_update_persistent(nxi);
20855 +
20856 +       return 0;
20857 +}
20858 +
20859 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20860 +{
20861 +       struct vcmd_net_caps_v0 vc_data;
20862 +
20863 +       vc_data.ncaps = nxi->nx_ncaps;
20864 +       vc_data.cmask = ~0ULL;
20865 +
20866 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20867 +               return -EFAULT;
20868 +       return 0;
20869 +}
20870 +
20871 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20872 +{
20873 +       struct vcmd_net_caps_v0 vc_data;
20874 +
20875 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20876 +               return -EFAULT;
20877 +
20878 +       nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20879 +               vc_data.ncaps, vc_data.cmask);
20880 +       return 0;
20881 +}
20882 +
20883 +
20884 +#include <linux/module.h>
20885 +
20886 +module_init(init_network);
20887 +
20888 +EXPORT_SYMBOL_GPL(free_nx_info);
20889 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20890 +
20891 diff -NurpP --minimal linux-3.10.40/kernel/vserver/proc.c linux-3.10.40-vs2.3.6.8/kernel/vserver/proc.c
20892 --- linux-3.10.40/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
20893 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/proc.c       2013-08-22 23:31:37.000000000 +0000
20894 @@ -0,0 +1,1113 @@
20895 +/*
20896 + *  linux/kernel/vserver/proc.c
20897 + *
20898 + *  Virtual Context Support
20899 + *
20900 + *  Copyright (C) 2003-2011  Herbert Pötzl
20901 + *
20902 + *  V0.01  basic structure
20903 + *  V0.02  adaptation vs1.3.0
20904 + *  V0.03  proc permissions
20905 + *  V0.04  locking/generic
20906 + *  V0.05  next generation procfs
20907 + *  V0.06  inode validation
20908 + *  V0.07  generic rewrite vid
20909 + *  V0.08  remove inode type
20910 + *  V0.09  added u/wmask info
20911 + *
20912 + */
20913 +
20914 +#include <linux/proc_fs.h>
20915 +#include <linux/fs_struct.h>
20916 +#include <linux/mount.h>
20917 +#include <linux/namei.h>
20918 +#include <asm/unistd.h>
20919 +
20920 +#include <linux/vs_context.h>
20921 +#include <linux/vs_network.h>
20922 +#include <linux/vs_cvirt.h>
20923 +
20924 +#include <linux/in.h>
20925 +#include <linux/inetdevice.h>
20926 +#include <linux/vs_inet.h>
20927 +#include <linux/vs_inet6.h>
20928 +
20929 +#include <linux/vserver/global.h>
20930 +
20931 +#include "cvirt_proc.h"
20932 +#include "cacct_proc.h"
20933 +#include "limit_proc.h"
20934 +#include "sched_proc.h"
20935 +#include "vci_config.h"
20936 +
20937 +#include <../../fs/proc/internal.h>
20938 +
20939 +
20940 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20941 +{
20942 +       unsigned __capi;
20943 +
20944 +       CAP_FOR_EACH_U32(__capi) {
20945 +               buffer += sprintf(buffer, "%08x",
20946 +                       c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20947 +       }
20948 +       return buffer;
20949 +}
20950 +
20951 +
20952 +static struct proc_dir_entry *proc_virtual;
20953 +
20954 +static struct proc_dir_entry *proc_virtnet;
20955 +
20956 +
20957 +/* first the actual feeds */
20958 +
20959 +
20960 +static int proc_vci(char *buffer)
20961 +{
20962 +       return sprintf(buffer,
20963 +               "VCIVersion:\t%04x:%04x\n"
20964 +               "VCISyscall:\t%d\n"
20965 +               "VCIKernel:\t%08x\n",
20966 +               VCI_VERSION >> 16,
20967 +               VCI_VERSION & 0xFFFF,
20968 +               __NR_vserver,
20969 +               vci_kernel_config());
20970 +}
20971 +
20972 +static int proc_virtual_info(char *buffer)
20973 +{
20974 +       return proc_vci(buffer);
20975 +}
20976 +
20977 +static int proc_virtual_status(char *buffer)
20978 +{
20979 +       return sprintf(buffer,
20980 +               "#CTotal:\t%d\n"
20981 +               "#CActive:\t%d\n"
20982 +               "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20983 +               "#InitTask:\t%d\t%d %d\n",
20984 +               atomic_read(&vx_global_ctotal),
20985 +               atomic_read(&vx_global_cactive),
20986 +               atomic_read(&vs_global_nsproxy),
20987 +               atomic_read(&vs_global_fs),
20988 +               atomic_read(&vs_global_mnt_ns),
20989 +               atomic_read(&vs_global_uts_ns),
20990 +               atomic_read(&nr_ipc_ns),
20991 +               atomic_read(&vs_global_user_ns),
20992 +               atomic_read(&vs_global_pid_ns),
20993 +               atomic_read(&init_task.usage),
20994 +               atomic_read(&init_task.nsproxy->count),
20995 +               init_task.fs->users);
20996 +}
20997 +
20998 +
20999 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21000 +{
21001 +       int length;
21002 +
21003 +       length = sprintf(buffer,
21004 +               "ID:\t%d\n"
21005 +               "Info:\t%p\n"
21006 +               "Init:\t%d\n"
21007 +               "OOM:\t%lld\n",
21008 +               vxi->vx_id,
21009 +               vxi,
21010 +               vxi->vx_initpid,
21011 +               vxi->vx_badness_bias);
21012 +       return length;
21013 +}
21014 +
21015 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21016 +{
21017 +       char *orig = buffer;
21018 +
21019 +       buffer += sprintf(buffer,
21020 +               "UseCnt:\t%d\n"
21021 +               "Tasks:\t%d\n"
21022 +               "Flags:\t%016llx\n",
21023 +               atomic_read(&vxi->vx_usecnt),
21024 +               atomic_read(&vxi->vx_tasks),
21025 +               (unsigned long long)vxi->vx_flags);
21026 +
21027 +       buffer += sprintf(buffer, "BCaps:\t");
21028 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21029 +       buffer += sprintf(buffer, "\n");
21030 +
21031 +       buffer += sprintf(buffer,
21032 +               "CCaps:\t%016llx\n"
21033 +               "Umask:\t%16llx\n"
21034 +               "Wmask:\t%16llx\n"
21035 +               "Spaces:\t%08lx %08lx\n",
21036 +               (unsigned long long)vxi->vx_ccaps,
21037 +               (unsigned long long)vxi->vx_umask,
21038 +               (unsigned long long)vxi->vx_wmask,
21039 +               vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21040 +       return buffer - orig;
21041 +}
21042 +
21043 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21044 +{
21045 +       return vx_info_proc_limit(&vxi->limit, buffer);
21046 +}
21047 +
21048 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21049 +{
21050 +       int cpu, length;
21051 +
21052 +       length = vx_info_proc_sched(&vxi->sched, buffer);
21053 +       for_each_online_cpu(cpu) {
21054 +               length += vx_info_proc_sched_pc(
21055 +                       &vx_per_cpu(vxi, sched_pc, cpu),
21056 +                       buffer + length, cpu);
21057 +       }
21058 +       return length;
21059 +}
21060 +
21061 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21062 +{
21063 +       return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21064 +}
21065 +
21066 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21067 +{
21068 +       return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21069 +}
21070 +
21071 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21072 +{
21073 +       int cpu, length;
21074 +
21075 +       vx_update_load(vxi);
21076 +       length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21077 +       for_each_online_cpu(cpu) {
21078 +               length += vx_info_proc_cvirt_pc(
21079 +                       &vx_per_cpu(vxi, cvirt_pc, cpu),
21080 +                       buffer + length, cpu);
21081 +       }
21082 +       return length;
21083 +}
21084 +
21085 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21086 +{
21087 +       return vx_info_proc_cacct(&vxi->cacct, buffer);
21088 +}
21089 +
21090 +
21091 +static int proc_virtnet_info(char *buffer)
21092 +{
21093 +       return proc_vci(buffer);
21094 +}
21095 +
21096 +static int proc_virtnet_status(char *buffer)
21097 +{
21098 +       return sprintf(buffer,
21099 +               "#CTotal:\t%d\n"
21100 +               "#CActive:\t%d\n",
21101 +               atomic_read(&nx_global_ctotal),
21102 +               atomic_read(&nx_global_cactive));
21103 +}
21104 +
21105 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21106 +{
21107 +       struct nx_addr_v4 *v4a;
21108 +#ifdef CONFIG_IPV6
21109 +       struct nx_addr_v6 *v6a;
21110 +#endif
21111 +       int length, i;
21112 +
21113 +       length = sprintf(buffer,
21114 +               "ID:\t%d\n"
21115 +               "Info:\t%p\n"
21116 +               "Bcast:\t" NIPQUAD_FMT "\n"
21117 +               "Lback:\t" NIPQUAD_FMT "\n",
21118 +               nxi->nx_id,
21119 +               nxi,
21120 +               NIPQUAD(nxi->v4_bcast.s_addr),
21121 +               NIPQUAD(nxi->v4_lback.s_addr));
21122 +
21123 +       if (!NX_IPV4(nxi))
21124 +               goto skip_v4;
21125 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21126 +               length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21127 +                       i, NXAV4(v4a));
21128 +skip_v4:
21129 +#ifdef CONFIG_IPV6
21130 +       if (!NX_IPV6(nxi))
21131 +               goto skip_v6;
21132 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21133 +               length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21134 +                       i, NXAV6(v6a));
21135 +skip_v6:
21136 +#endif
21137 +       return length;
21138 +}
21139 +
21140 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21141 +{
21142 +       int length;
21143 +
21144 +       length = sprintf(buffer,
21145 +               "UseCnt:\t%d\n"
21146 +               "Tasks:\t%d\n"
21147 +               "Flags:\t%016llx\n"
21148 +               "NCaps:\t%016llx\n",
21149 +               atomic_read(&nxi->nx_usecnt),
21150 +               atomic_read(&nxi->nx_tasks),
21151 +               (unsigned long long)nxi->nx_flags,
21152 +               (unsigned long long)nxi->nx_ncaps);
21153 +       return length;
21154 +}
21155 +
21156 +
21157 +
21158 +/* here the inode helpers */
21159 +
21160 +struct vs_entry {
21161 +       int len;
21162 +       char *name;
21163 +       mode_t mode;
21164 +       struct inode_operations *iop;
21165 +       struct file_operations *fop;
21166 +       union proc_op op;
21167 +};
21168 +
21169 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21170 +{
21171 +       struct inode *inode = new_inode(sb);
21172 +
21173 +       if (!inode)
21174 +               goto out;
21175 +
21176 +       inode->i_mode = p->mode;
21177 +       if (p->iop)
21178 +               inode->i_op = p->iop;
21179 +       if (p->fop)
21180 +               inode->i_fop = p->fop;
21181 +
21182 +       set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21183 +       inode->i_flags |= S_IMMUTABLE;
21184 +
21185 +       inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21186 +
21187 +       i_uid_write(inode, 0);
21188 +       i_gid_write(inode, 0);
21189 +       i_tag_write(inode, 0);
21190 +out:
21191 +       return inode;
21192 +}
21193 +
21194 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21195 +       struct dentry *dentry, int id, void *ptr)
21196 +{
21197 +       struct vs_entry *p = ptr;
21198 +       struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21199 +       struct dentry *error = ERR_PTR(-EINVAL);
21200 +
21201 +       if (!inode)
21202 +               goto out;
21203 +
21204 +       PROC_I(inode)->op = p->op;
21205 +       PROC_I(inode)->fd = id;
21206 +       d_add(dentry, inode);
21207 +       error = NULL;
21208 +out:
21209 +       return error;
21210 +}
21211 +
21212 +/* Lookups */
21213 +
21214 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
21215 +
21216 +
21217 +/*
21218 + * Fill a directory entry.
21219 + *
21220 + * If possible create the dcache entry and derive our inode number and
21221 + * file type from dcache entry.
21222 + *
21223 + * Since all of the proc inode numbers are dynamically generated, the inode
21224 + * numbers do not exist until the inode is cache.  This means creating the
21225 + * the dcache entry in readdir is necessary to keep the inode numbers
21226 + * reported by readdir in sync with the inode numbers reported
21227 + * by stat.
21228 + */
21229 +static int vx_proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21230 +       char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
21231 +{
21232 +       struct dentry *child, *dir = filp->f_dentry;
21233 +       struct inode *inode;
21234 +       struct qstr qname;
21235 +       ino_t ino = 0;
21236 +       unsigned type = DT_UNKNOWN;
21237 +
21238 +       qname.name = name;
21239 +       qname.len  = len;
21240 +       qname.hash = full_name_hash(name, len);
21241 +
21242 +       child = d_lookup(dir, &qname);
21243 +       if (!child) {
21244 +               struct dentry *new;
21245 +               new = d_alloc(dir, &qname);
21246 +               if (new) {
21247 +                       child = instantiate(dir->d_inode, new, id, ptr);
21248 +                       if (child)
21249 +                               dput(new);
21250 +                       else
21251 +                               child = new;
21252 +               }
21253 +       }
21254 +       if (!child || IS_ERR(child) || !child->d_inode)
21255 +               goto end_instantiate;
21256 +       inode = child->d_inode;
21257 +       if (inode) {
21258 +               ino = inode->i_ino;
21259 +               type = inode->i_mode >> 12;
21260 +       }
21261 +       dput(child);
21262 +end_instantiate:
21263 +       if (!ino)
21264 +               ino = find_inode_number(dir, &qname);
21265 +       if (!ino)
21266 +               ino = 1;
21267 +       return filldir(dirent, name, len, filp->f_pos, ino, type);
21268 +}
21269 +
21270 +
21271 +
21272 +/* get and revalidate vx_info/xid */
21273 +
21274 +static inline
21275 +struct vx_info *get_proc_vx_info(struct inode *inode)
21276 +{
21277 +       return lookup_vx_info(PROC_I(inode)->fd);
21278 +}
21279 +
21280 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21281 +{
21282 +       struct inode *inode = dentry->d_inode;
21283 +       vxid_t xid = PROC_I(inode)->fd;
21284 +
21285 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21286 +               return -ECHILD;
21287 +
21288 +       if (!xid || xid_is_hashed(xid))
21289 +               return 1;
21290 +       d_drop(dentry);
21291 +       return 0;
21292 +}
21293 +
21294 +
21295 +/* get and revalidate nx_info/nid */
21296 +
21297 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21298 +{
21299 +       struct inode *inode = dentry->d_inode;
21300 +       vnid_t nid = PROC_I(inode)->fd;
21301 +
21302 +       if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21303 +               return -ECHILD;
21304 +
21305 +       if (!nid || nid_is_hashed(nid))
21306 +               return 1;
21307 +       d_drop(dentry);
21308 +       return 0;
21309 +}
21310 +
21311 +
21312 +
21313 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21314 +
21315 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21316 +                         size_t count, loff_t *ppos)
21317 +{
21318 +       struct inode *inode = file->f_dentry->d_inode;
21319 +       unsigned long page;
21320 +       ssize_t length = 0;
21321 +
21322 +       if (count > PROC_BLOCK_SIZE)
21323 +               count = PROC_BLOCK_SIZE;
21324 +
21325 +       /* fade that out as soon as stable */
21326 +       WARN_ON(PROC_I(inode)->fd);
21327 +
21328 +       if (!(page = __get_free_page(GFP_KERNEL)))
21329 +               return -ENOMEM;
21330 +
21331 +       BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21332 +       length = PROC_I(inode)->op.proc_vs_read((char *)page);
21333 +
21334 +       if (length >= 0)
21335 +               length = simple_read_from_buffer(buf, count, ppos,
21336 +                       (char *)page, length);
21337 +
21338 +       free_page(page);
21339 +       return length;
21340 +}
21341 +
21342 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21343 +                         size_t count, loff_t *ppos)
21344 +{
21345 +       struct inode *inode = file->f_dentry->d_inode;
21346 +       struct vx_info *vxi = NULL;
21347 +       vxid_t xid = PROC_I(inode)->fd;
21348 +       unsigned long page;
21349 +       ssize_t length = 0;
21350 +
21351 +       if (count > PROC_BLOCK_SIZE)
21352 +               count = PROC_BLOCK_SIZE;
21353 +
21354 +       /* fade that out as soon as stable */
21355 +       WARN_ON(!xid);
21356 +       vxi = lookup_vx_info(xid);
21357 +       if (!vxi)
21358 +               goto out;
21359 +
21360 +       length = -ENOMEM;
21361 +       if (!(page = __get_free_page(GFP_KERNEL)))
21362 +               goto out_put;
21363 +
21364 +       BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21365 +       length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21366 +
21367 +       if (length >= 0)
21368 +               length = simple_read_from_buffer(buf, count, ppos,
21369 +                       (char *)page, length);
21370 +
21371 +       free_page(page);
21372 +out_put:
21373 +       put_vx_info(vxi);
21374 +out:
21375 +       return length;
21376 +}
21377 +
21378 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21379 +                         size_t count, loff_t *ppos)
21380 +{
21381 +       struct inode *inode = file->f_dentry->d_inode;
21382 +       struct nx_info *nxi = NULL;
21383 +       vnid_t nid = PROC_I(inode)->fd;
21384 +       unsigned long page;
21385 +       ssize_t length = 0;
21386 +
21387 +       if (count > PROC_BLOCK_SIZE)
21388 +               count = PROC_BLOCK_SIZE;
21389 +
21390 +       /* fade that out as soon as stable */
21391 +       WARN_ON(!nid);
21392 +       nxi = lookup_nx_info(nid);
21393 +       if (!nxi)
21394 +               goto out;
21395 +
21396 +       length = -ENOMEM;
21397 +       if (!(page = __get_free_page(GFP_KERNEL)))
21398 +               goto out_put;
21399 +
21400 +       BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21401 +       length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21402 +
21403 +       if (length >= 0)
21404 +               length = simple_read_from_buffer(buf, count, ppos,
21405 +                       (char *)page, length);
21406 +
21407 +       free_page(page);
21408 +out_put:
21409 +       put_nx_info(nxi);
21410 +out:
21411 +       return length;
21412 +}
21413 +
21414 +
21415 +
21416 +/* here comes the lower level */
21417 +
21418 +
21419 +#define NOD(NAME, MODE, IOP, FOP, OP) {        \
21420 +       .len  = sizeof(NAME) - 1,       \
21421 +       .name = (NAME),                 \
21422 +       .mode = MODE,                   \
21423 +       .iop  = IOP,                    \
21424 +       .fop  = FOP,                    \
21425 +       .op   = OP,                     \
21426 +}
21427 +
21428 +
21429 +#define DIR(NAME, MODE, OTYPE)                         \
21430 +       NOD(NAME, (S_IFDIR | (MODE)),                   \
21431 +               &proc_ ## OTYPE ## _inode_operations,   \
21432 +               &proc_ ## OTYPE ## _file_operations, { } )
21433 +
21434 +#define INF(NAME, MODE, OTYPE)                         \
21435 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21436 +               &proc_vs_info_file_operations,          \
21437 +               { .proc_vs_read = &proc_##OTYPE } )
21438 +
21439 +#define VINF(NAME, MODE, OTYPE)                                \
21440 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21441 +               &proc_vx_info_file_operations,          \
21442 +               { .proc_vxi_read = &proc_##OTYPE } )
21443 +
21444 +#define NINF(NAME, MODE, OTYPE)                                \
21445 +       NOD(NAME, (S_IFREG | (MODE)), NULL,             \
21446 +               &proc_nx_info_file_operations,          \
21447 +               { .proc_nxi_read = &proc_##OTYPE } )
21448 +
21449 +
21450 +static struct file_operations proc_vs_info_file_operations = {
21451 +       .read =         proc_vs_info_read,
21452 +};
21453 +
21454 +static struct file_operations proc_vx_info_file_operations = {
21455 +       .read =         proc_vx_info_read,
21456 +};
21457 +
21458 +static struct dentry_operations proc_xid_dentry_operations = {
21459 +       .d_revalidate = proc_xid_revalidate,
21460 +};
21461 +
21462 +static struct vs_entry vx_base_stuff[] = {
21463 +       VINF("info",    S_IRUGO, vxi_info),
21464 +       VINF("status",  S_IRUGO, vxi_status),
21465 +       VINF("limit",   S_IRUGO, vxi_limit),
21466 +       VINF("sched",   S_IRUGO, vxi_sched),
21467 +       VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21468 +       VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21469 +       VINF("cvirt",   S_IRUGO, vxi_cvirt),
21470 +       VINF("cacct",   S_IRUGO, vxi_cacct),
21471 +       {}
21472 +};
21473 +
21474 +
21475 +
21476 +
21477 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21478 +       struct dentry *dentry, int id, void *ptr)
21479 +{
21480 +       dentry->d_op = &proc_xid_dentry_operations;
21481 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21482 +}
21483 +
21484 +static struct dentry *proc_xid_lookup(struct inode *dir,
21485 +       struct dentry *dentry, unsigned int flags)
21486 +{
21487 +       struct vs_entry *p = vx_base_stuff;
21488 +       struct dentry *error = ERR_PTR(-ENOENT);
21489 +
21490 +       for (; p->name; p++) {
21491 +               if (p->len != dentry->d_name.len)
21492 +                       continue;
21493 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21494 +                       break;
21495 +       }
21496 +       if (!p->name)
21497 +               goto out;
21498 +
21499 +       error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21500 +out:
21501 +       return error;
21502 +}
21503 +
21504 +static int proc_xid_readdir(struct file *filp,
21505 +       void *dirent, filldir_t filldir)
21506 +{
21507 +       struct dentry *dentry = filp->f_dentry;
21508 +       struct inode *inode = dentry->d_inode;
21509 +       struct vs_entry *p = vx_base_stuff;
21510 +       int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21511 +       int pos, index;
21512 +       u64 ino;
21513 +
21514 +       pos = filp->f_pos;
21515 +       switch (pos) {
21516 +       case 0:
21517 +               ino = inode->i_ino;
21518 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21519 +                       goto out;
21520 +               pos++;
21521 +               /* fall through */
21522 +       case 1:
21523 +               ino = parent_ino(dentry);
21524 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21525 +                       goto out;
21526 +               pos++;
21527 +               /* fall through */
21528 +       default:
21529 +               index = pos - 2;
21530 +               if (index >= size)
21531 +                       goto out;
21532 +               for (p += index; p->name; p++) {
21533 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21534 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21535 +                               goto out;
21536 +                       pos++;
21537 +               }
21538 +       }
21539 +out:
21540 +       filp->f_pos = pos;
21541 +       return 1;
21542 +}
21543 +
21544 +
21545 +
21546 +static struct file_operations proc_nx_info_file_operations = {
21547 +       .read =         proc_nx_info_read,
21548 +};
21549 +
21550 +static struct dentry_operations proc_nid_dentry_operations = {
21551 +       .d_revalidate = proc_nid_revalidate,
21552 +};
21553 +
21554 +static struct vs_entry nx_base_stuff[] = {
21555 +       NINF("info",    S_IRUGO, nxi_info),
21556 +       NINF("status",  S_IRUGO, nxi_status),
21557 +       {}
21558 +};
21559 +
21560 +
21561 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21562 +       struct dentry *dentry, int id, void *ptr)
21563 +{
21564 +       dentry->d_op = &proc_nid_dentry_operations;
21565 +       return vs_proc_instantiate(dir, dentry, id, ptr);
21566 +}
21567 +
21568 +static struct dentry *proc_nid_lookup(struct inode *dir,
21569 +       struct dentry *dentry, unsigned int flags)
21570 +{
21571 +       struct vs_entry *p = nx_base_stuff;
21572 +       struct dentry *error = ERR_PTR(-ENOENT);
21573 +
21574 +       for (; p->name; p++) {
21575 +               if (p->len != dentry->d_name.len)
21576 +                       continue;
21577 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21578 +                       break;
21579 +       }
21580 +       if (!p->name)
21581 +               goto out;
21582 +
21583 +       error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21584 +out:
21585 +       return error;
21586 +}
21587 +
21588 +static int proc_nid_readdir(struct file *filp,
21589 +       void *dirent, filldir_t filldir)
21590 +{
21591 +       struct dentry *dentry = filp->f_dentry;
21592 +       struct inode *inode = dentry->d_inode;
21593 +       struct vs_entry *p = nx_base_stuff;
21594 +       int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21595 +       int pos, index;
21596 +       u64 ino;
21597 +
21598 +       pos = filp->f_pos;
21599 +       switch (pos) {
21600 +       case 0:
21601 +               ino = inode->i_ino;
21602 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21603 +                       goto out;
21604 +               pos++;
21605 +               /* fall through */
21606 +       case 1:
21607 +               ino = parent_ino(dentry);
21608 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21609 +                       goto out;
21610 +               pos++;
21611 +               /* fall through */
21612 +       default:
21613 +               index = pos - 2;
21614 +               if (index >= size)
21615 +                       goto out;
21616 +               for (p += index; p->name; p++) {
21617 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21618 +                               vs_proc_instantiate, PROC_I(inode)->fd, p))
21619 +                               goto out;
21620 +                       pos++;
21621 +               }
21622 +       }
21623 +out:
21624 +       filp->f_pos = pos;
21625 +       return 1;
21626 +}
21627 +
21628 +
21629 +#define MAX_MULBY10    ((~0U - 9) / 10)
21630 +
21631 +static inline int atovid(const char *str, int len)
21632 +{
21633 +       int vid, c;
21634 +
21635 +       vid = 0;
21636 +       while (len-- > 0) {
21637 +               c = *str - '0';
21638 +               str++;
21639 +               if (c > 9)
21640 +                       return -1;
21641 +               if (vid >= MAX_MULBY10)
21642 +                       return -1;
21643 +               vid *= 10;
21644 +               vid += c;
21645 +               if (!vid)
21646 +                       return -1;
21647 +       }
21648 +       return vid;
21649 +}
21650 +
21651 +/* now the upper level (virtual) */
21652 +
21653 +
21654 +static struct file_operations proc_xid_file_operations = {
21655 +       .read =         generic_read_dir,
21656 +       .readdir =      proc_xid_readdir,
21657 +};
21658 +
21659 +static struct inode_operations proc_xid_inode_operations = {
21660 +       .lookup =       proc_xid_lookup,
21661 +};
21662 +
21663 +static struct vs_entry vx_virtual_stuff[] = {
21664 +       INF("info",     S_IRUGO, virtual_info),
21665 +       INF("status",   S_IRUGO, virtual_status),
21666 +       DIR(NULL,       S_IRUGO | S_IXUGO, xid),
21667 +};
21668 +
21669 +
21670 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21671 +       struct dentry *dentry, unsigned int flags)
21672 +{
21673 +       struct vs_entry *p = vx_virtual_stuff;
21674 +       struct dentry *error = ERR_PTR(-ENOENT);
21675 +       int id = 0;
21676 +
21677 +       for (; p->name; p++) {
21678 +               if (p->len != dentry->d_name.len)
21679 +                       continue;
21680 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21681 +                       break;
21682 +       }
21683 +       if (p->name)
21684 +               goto instantiate;
21685 +
21686 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21687 +       if ((id < 0) || !xid_is_hashed(id))
21688 +               goto out;
21689 +
21690 +instantiate:
21691 +       error = proc_xid_instantiate(dir, dentry, id, p);
21692 +out:
21693 +       return error;
21694 +}
21695 +
21696 +static struct file_operations proc_nid_file_operations = {
21697 +       .read =         generic_read_dir,
21698 +       .readdir =      proc_nid_readdir,
21699 +};
21700 +
21701 +static struct inode_operations proc_nid_inode_operations = {
21702 +       .lookup =       proc_nid_lookup,
21703 +};
21704 +
21705 +static struct vs_entry nx_virtnet_stuff[] = {
21706 +       INF("info",     S_IRUGO, virtnet_info),
21707 +       INF("status",   S_IRUGO, virtnet_status),
21708 +       DIR(NULL,       S_IRUGO | S_IXUGO, nid),
21709 +};
21710 +
21711 +
21712 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21713 +       struct dentry *dentry, unsigned int flags)
21714 +{
21715 +       struct vs_entry *p = nx_virtnet_stuff;
21716 +       struct dentry *error = ERR_PTR(-ENOENT);
21717 +       int id = 0;
21718 +
21719 +       for (; p->name; p++) {
21720 +               if (p->len != dentry->d_name.len)
21721 +                       continue;
21722 +               if (!memcmp(dentry->d_name.name, p->name, p->len))
21723 +                       break;
21724 +       }
21725 +       if (p->name)
21726 +               goto instantiate;
21727 +
21728 +       id = atovid(dentry->d_name.name, dentry->d_name.len);
21729 +       if ((id < 0) || !nid_is_hashed(id))
21730 +               goto out;
21731 +
21732 +instantiate:
21733 +       error = proc_nid_instantiate(dir, dentry, id, p);
21734 +out:
21735 +       return error;
21736 +}
21737 +
21738 +
21739 +#define PROC_MAXVIDS 32
21740 +
21741 +int proc_virtual_readdir(struct file *filp,
21742 +       void *dirent, filldir_t filldir)
21743 +{
21744 +       struct dentry *dentry = filp->f_dentry;
21745 +       struct inode *inode = dentry->d_inode;
21746 +       struct vs_entry *p = vx_virtual_stuff;
21747 +       int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21748 +       int pos, index;
21749 +       unsigned int xid_array[PROC_MAXVIDS];
21750 +       char buf[PROC_NUMBUF];
21751 +       unsigned int nr_xids, i;
21752 +       u64 ino;
21753 +
21754 +       pos = filp->f_pos;
21755 +       switch (pos) {
21756 +       case 0:
21757 +               ino = inode->i_ino;
21758 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21759 +                       goto out;
21760 +               pos++;
21761 +               /* fall through */
21762 +       case 1:
21763 +               ino = parent_ino(dentry);
21764 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21765 +                       goto out;
21766 +               pos++;
21767 +               /* fall through */
21768 +       default:
21769 +               index = pos - 2;
21770 +               if (index >= size)
21771 +                       goto entries;
21772 +               for (p += index; p->name; p++) {
21773 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21774 +                               vs_proc_instantiate, 0, p))
21775 +                               goto out;
21776 +                       pos++;
21777 +               }
21778 +       entries:
21779 +               index = pos - size;
21780 +               p = &vx_virtual_stuff[size - 1];
21781 +               nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21782 +               for (i = 0; i < nr_xids; i++) {
21783 +                       int n, xid = xid_array[i];
21784 +                       unsigned int j = PROC_NUMBUF;
21785 +
21786 +                       n = xid;
21787 +                       do
21788 +                               buf[--j] = '0' + (n % 10);
21789 +                       while (n /= 10);
21790 +
21791 +                       if (vx_proc_fill_cache(filp, dirent, filldir,
21792 +                               buf + j, PROC_NUMBUF - j,
21793 +                               vs_proc_instantiate, xid, p))
21794 +                               goto out;
21795 +                       pos++;
21796 +               }
21797 +       }
21798 +out:
21799 +       filp->f_pos = pos;
21800 +       return 0;
21801 +}
21802 +
21803 +static int proc_virtual_getattr(struct vfsmount *mnt,
21804 +       struct dentry *dentry, struct kstat *stat)
21805 +{
21806 +       struct inode *inode = dentry->d_inode;
21807 +
21808 +       generic_fillattr(inode, stat);
21809 +       stat->nlink = 2 + atomic_read(&vx_global_cactive);
21810 +       return 0;
21811 +}
21812 +
21813 +static struct file_operations proc_virtual_dir_operations = {
21814 +       .read =         generic_read_dir,
21815 +       .readdir =      proc_virtual_readdir,
21816 +};
21817 +
21818 +static struct inode_operations proc_virtual_dir_inode_operations = {
21819 +       .getattr =      proc_virtual_getattr,
21820 +       .lookup =       proc_virtual_lookup,
21821 +};
21822 +
21823 +
21824 +
21825 +
21826 +
21827 +int proc_virtnet_readdir(struct file *filp,
21828 +       void *dirent, filldir_t filldir)
21829 +{
21830 +       struct dentry *dentry = filp->f_dentry;
21831 +       struct inode *inode = dentry->d_inode;
21832 +       struct vs_entry *p = nx_virtnet_stuff;
21833 +       int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21834 +       int pos, index;
21835 +       unsigned int nid_array[PROC_MAXVIDS];
21836 +       char buf[PROC_NUMBUF];
21837 +       unsigned int nr_nids, i;
21838 +       u64 ino;
21839 +
21840 +       pos = filp->f_pos;
21841 +       switch (pos) {
21842 +       case 0:
21843 +               ino = inode->i_ino;
21844 +               if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21845 +                       goto out;
21846 +               pos++;
21847 +               /* fall through */
21848 +       case 1:
21849 +               ino = parent_ino(dentry);
21850 +               if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21851 +                       goto out;
21852 +               pos++;
21853 +               /* fall through */
21854 +       default:
21855 +               index = pos - 2;
21856 +               if (index >= size)
21857 +                       goto entries;
21858 +               for (p += index; p->name; p++) {
21859 +                       if (vx_proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21860 +                               vs_proc_instantiate, 0, p))
21861 +                               goto out;
21862 +                       pos++;
21863 +               }
21864 +       entries:
21865 +               index = pos - size;
21866 +               p = &nx_virtnet_stuff[size - 1];
21867 +               nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21868 +               for (i = 0; i < nr_nids; i++) {
21869 +                       int n, nid = nid_array[i];
21870 +                       unsigned int j = PROC_NUMBUF;
21871 +
21872 +                       n = nid;
21873 +                       do
21874 +                               buf[--j] = '0' + (n % 10);
21875 +                       while (n /= 10);
21876 +
21877 +                       if (vx_proc_fill_cache(filp, dirent, filldir,
21878 +                               buf + j, PROC_NUMBUF - j,
21879 +                               vs_proc_instantiate, nid, p))
21880 +                               goto out;
21881 +                       pos++;
21882 +               }
21883 +       }
21884 +out:
21885 +       filp->f_pos = pos;
21886 +       return 0;
21887 +}
21888 +
21889 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21890 +       struct dentry *dentry, struct kstat *stat)
21891 +{
21892 +       struct inode *inode = dentry->d_inode;
21893 +
21894 +       generic_fillattr(inode, stat);
21895 +       stat->nlink = 2 + atomic_read(&nx_global_cactive);
21896 +       return 0;
21897 +}
21898 +
21899 +static struct file_operations proc_virtnet_dir_operations = {
21900 +       .read =         generic_read_dir,
21901 +       .readdir =      proc_virtnet_readdir,
21902 +};
21903 +
21904 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21905 +       .getattr =      proc_virtnet_getattr,
21906 +       .lookup =       proc_virtnet_lookup,
21907 +};
21908 +
21909 +
21910 +
21911 +void proc_vx_init(void)
21912 +{
21913 +       struct proc_dir_entry *ent;
21914 +
21915 +       ent = proc_mkdir("virtual", 0);
21916 +       if (ent) {
21917 +               ent->proc_fops = &proc_virtual_dir_operations;
21918 +               ent->proc_iops = &proc_virtual_dir_inode_operations;
21919 +       }
21920 +       proc_virtual = ent;
21921 +
21922 +       ent = proc_mkdir("virtnet", 0);
21923 +       if (ent) {
21924 +               ent->proc_fops = &proc_virtnet_dir_operations;
21925 +               ent->proc_iops = &proc_virtnet_dir_inode_operations;
21926 +       }
21927 +       proc_virtnet = ent;
21928 +}
21929 +
21930 +
21931 +
21932 +
21933 +/* per pid info */
21934 +
21935 +
21936 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21937 +{
21938 +       struct vx_info *vxi;
21939 +       char *orig = buffer;
21940 +
21941 +       buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21942 +
21943 +       vxi = task_get_vx_info(p);
21944 +       if (!vxi)
21945 +               goto out;
21946 +
21947 +       buffer += sprintf(buffer, "BCaps:\t");
21948 +       buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21949 +       buffer += sprintf(buffer, "\n");
21950 +       buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21951 +               (unsigned long long)vxi->vx_ccaps);
21952 +       buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21953 +               (unsigned long long)vxi->vx_flags);
21954 +       buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21955 +
21956 +       put_vx_info(vxi);
21957 +out:
21958 +       return buffer - orig;
21959 +}
21960 +
21961 +
21962 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21963 +{
21964 +       struct nx_info *nxi;
21965 +       struct nx_addr_v4 *v4a;
21966 +#ifdef CONFIG_IPV6
21967 +       struct nx_addr_v6 *v6a;
21968 +#endif
21969 +       char *orig = buffer;
21970 +       int i;
21971 +
21972 +       buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21973 +
21974 +       nxi = task_get_nx_info(p);
21975 +       if (!nxi)
21976 +               goto out;
21977 +
21978 +       buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21979 +               (unsigned long long)nxi->nx_ncaps);
21980 +       buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21981 +               (unsigned long long)nxi->nx_flags);
21982 +
21983 +       buffer += sprintf(buffer,
21984 +               "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21985 +               NIPQUAD(nxi->v4_bcast.s_addr));
21986 +       buffer += sprintf (buffer,
21987 +               "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21988 +               NIPQUAD(nxi->v4_lback.s_addr));
21989 +       if (!NX_IPV4(nxi))
21990 +               goto skip_v4;
21991 +       for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21992 +               buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21993 +                       i, NXAV4(v4a));
21994 +skip_v4:
21995 +#ifdef CONFIG_IPV6
21996 +       if (!NX_IPV6(nxi))
21997 +               goto skip_v6;
21998 +       for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21999 +               buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22000 +                       i, NXAV6(v6a));
22001 +skip_v6:
22002 +#endif
22003 +       put_nx_info(nxi);
22004 +out:
22005 +       return buffer - orig;
22006 +}
22007 +
22008 diff -NurpP --minimal linux-3.10.40/kernel/vserver/sched.c linux-3.10.40-vs2.3.6.8/kernel/vserver/sched.c
22009 --- linux-3.10.40/kernel/vserver/sched.c        1970-01-01 00:00:00.000000000 +0000
22010 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/sched.c      2013-08-22 20:30:00.000000000 +0000
22011 @@ -0,0 +1,83 @@
22012 +/*
22013 + *  linux/kernel/vserver/sched.c
22014 + *
22015 + *  Virtual Server: Scheduler Support
22016 + *
22017 + *  Copyright (C) 2004-2010  Herbert Pötzl
22018 + *
22019 + *  V0.01  adapted Sam Vilains version to 2.6.3
22020 + *  V0.02  removed legacy interface
22021 + *  V0.03  changed vcmds to vxi arg
22022 + *  V0.04  removed older and legacy interfaces
22023 + *  V0.05  removed scheduler code/commands
22024 + *
22025 + */
22026 +
22027 +#include <linux/vs_context.h>
22028 +#include <linux/vs_sched.h>
22029 +#include <linux/cpumask.h>
22030 +#include <linux/vserver/sched_cmd.h>
22031 +
22032 +#include <asm/uaccess.h>
22033 +
22034 +
22035 +void vx_update_sched_param(struct _vx_sched *sched,
22036 +       struct _vx_sched_pc *sched_pc)
22037 +{
22038 +       sched_pc->prio_bias = sched->prio_bias;
22039 +}
22040 +
22041 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22042 +{
22043 +       int cpu;
22044 +
22045 +       if (data->prio_bias > MAX_PRIO_BIAS)
22046 +               data->prio_bias = MAX_PRIO_BIAS;
22047 +       if (data->prio_bias < MIN_PRIO_BIAS)
22048 +               data->prio_bias = MIN_PRIO_BIAS;
22049 +
22050 +       if (data->cpu_id != ~0) {
22051 +               vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22052 +               cpumask_and(&vxi->sched.update, &vxi->sched.update,
22053 +                       cpu_online_mask);
22054 +       } else
22055 +               cpumask_copy(&vxi->sched.update, cpu_online_mask);
22056 +
22057 +       for_each_cpu_mask(cpu, vxi->sched.update)
22058 +               vx_update_sched_param(&vxi->sched,
22059 +                       &vx_per_cpu(vxi, sched_pc, cpu));
22060 +       return 0;
22061 +}
22062 +
22063 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22064 +{
22065 +       struct vcmd_prio_bias vc_data;
22066 +
22067 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22068 +               return -EFAULT;
22069 +
22070 +       return do_set_prio_bias(vxi, &vc_data);
22071 +}
22072 +
22073 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22074 +{
22075 +       struct vcmd_prio_bias vc_data;
22076 +       struct _vx_sched_pc *pcd;
22077 +       int cpu;
22078 +
22079 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22080 +               return -EFAULT;
22081 +
22082 +       cpu = vc_data.cpu_id;
22083 +
22084 +       if (!cpu_possible(cpu))
22085 +               return -EINVAL;
22086 +
22087 +       pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22088 +       vc_data.prio_bias = pcd->prio_bias;
22089 +
22090 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22091 +               return -EFAULT;
22092 +       return 0;
22093 +}
22094 +
22095 diff -NurpP --minimal linux-3.10.40/kernel/vserver/sched_init.h linux-3.10.40-vs2.3.6.8/kernel/vserver/sched_init.h
22096 --- linux-3.10.40/kernel/vserver/sched_init.h   1970-01-01 00:00:00.000000000 +0000
22097 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/sched_init.h 2013-08-22 20:30:00.000000000 +0000
22098 @@ -0,0 +1,27 @@
22099 +
22100 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22101 +{
22102 +       /* scheduling; hard code starting values as constants */
22103 +       sched->prio_bias = 0;
22104 +}
22105 +
22106 +static inline
22107 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22108 +{
22109 +       sched_pc->prio_bias = 0;
22110 +
22111 +       sched_pc->user_ticks = 0;
22112 +       sched_pc->sys_ticks = 0;
22113 +       sched_pc->hold_ticks = 0;
22114 +}
22115 +
22116 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22117 +{
22118 +       return;
22119 +}
22120 +
22121 +static inline
22122 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22123 +{
22124 +       return;
22125 +}
22126 diff -NurpP --minimal linux-3.10.40/kernel/vserver/sched_proc.h linux-3.10.40-vs2.3.6.8/kernel/vserver/sched_proc.h
22127 --- linux-3.10.40/kernel/vserver/sched_proc.h   1970-01-01 00:00:00.000000000 +0000
22128 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/sched_proc.h 2013-08-22 20:30:00.000000000 +0000
22129 @@ -0,0 +1,32 @@
22130 +#ifndef _VX_SCHED_PROC_H
22131 +#define _VX_SCHED_PROC_H
22132 +
22133 +
22134 +static inline
22135 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22136 +{
22137 +       int length = 0;
22138 +
22139 +       length += sprintf(buffer,
22140 +               "PrioBias:\t%8d\n",
22141 +               sched->prio_bias);
22142 +       return length;
22143 +}
22144 +
22145 +static inline
22146 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22147 +       char *buffer, int cpu)
22148 +{
22149 +       int length = 0;
22150 +
22151 +       length += sprintf(buffer + length,
22152 +               "cpu %d: %lld %lld %lld", cpu,
22153 +               (unsigned long long)sched_pc->user_ticks,
22154 +               (unsigned long long)sched_pc->sys_ticks,
22155 +               (unsigned long long)sched_pc->hold_ticks);
22156 +       length += sprintf(buffer + length,
22157 +               " %d\n", sched_pc->prio_bias);
22158 +       return length;
22159 +}
22160 +
22161 +#endif /* _VX_SCHED_PROC_H */
22162 diff -NurpP --minimal linux-3.10.40/kernel/vserver/signal.c linux-3.10.40-vs2.3.6.8/kernel/vserver/signal.c
22163 --- linux-3.10.40/kernel/vserver/signal.c       1970-01-01 00:00:00.000000000 +0000
22164 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/signal.c     2013-08-22 20:30:00.000000000 +0000
22165 @@ -0,0 +1,134 @@
22166 +/*
22167 + *  linux/kernel/vserver/signal.c
22168 + *
22169 + *  Virtual Server: Signal Support
22170 + *
22171 + *  Copyright (C) 2003-2007  Herbert Pötzl
22172 + *
22173 + *  V0.01  broken out from vcontext V0.05
22174 + *  V0.02  changed vcmds to vxi arg
22175 + *  V0.03  adjusted siginfo for kill
22176 + *
22177 + */
22178 +
22179 +#include <asm/uaccess.h>
22180 +
22181 +#include <linux/vs_context.h>
22182 +#include <linux/vs_pid.h>
22183 +#include <linux/vserver/signal_cmd.h>
22184 +
22185 +
22186 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22187 +{
22188 +       int retval, count = 0;
22189 +       struct task_struct *p;
22190 +       struct siginfo *sip = SEND_SIG_PRIV;
22191 +
22192 +       retval = -ESRCH;
22193 +       vxdprintk(VXD_CBIT(misc, 4),
22194 +               "vx_info_kill(%p[#%d],%d,%d)*",
22195 +               vxi, vxi->vx_id, pid, sig);
22196 +       read_lock(&tasklist_lock);
22197 +       switch (pid) {
22198 +       case  0:
22199 +       case -1:
22200 +               for_each_process(p) {
22201 +                       int err = 0;
22202 +
22203 +                       if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22204 +                               (pid && vxi->vx_initpid == p->pid))
22205 +                               continue;
22206 +
22207 +                       err = group_send_sig_info(sig, sip, p);
22208 +                       ++count;
22209 +                       if (err != -EPERM)
22210 +                               retval = err;
22211 +               }
22212 +               break;
22213 +
22214 +       case 1:
22215 +               if (vxi->vx_initpid) {
22216 +                       pid = vxi->vx_initpid;
22217 +                       /* for now, only SIGINT to private init ... */
22218 +                       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22219 +                               /* ... as long as there are tasks left */
22220 +                               (atomic_read(&vxi->vx_tasks) > 1))
22221 +                               sig = SIGINT;
22222 +               }
22223 +               /* fallthrough */
22224 +       default:
22225 +               rcu_read_lock();
22226 +               p = find_task_by_real_pid(pid);
22227 +               rcu_read_unlock();
22228 +               if (p) {
22229 +                       if (vx_task_xid(p) == vxi->vx_id)
22230 +                               retval = group_send_sig_info(sig, sip, p);
22231 +               }
22232 +               break;
22233 +       }
22234 +       read_unlock(&tasklist_lock);
22235 +       vxdprintk(VXD_CBIT(misc, 4),
22236 +               "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22237 +               vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22238 +       return retval;
22239 +}
22240 +
22241 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22242 +{
22243 +       struct vcmd_ctx_kill_v0 vc_data;
22244 +
22245 +       if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22246 +               return -EFAULT;
22247 +
22248 +       /* special check to allow guest shutdown */
22249 +       if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22250 +               /* forbid killall pid=0 when init is present */
22251 +               (((vc_data.pid < 1) && vxi->vx_initpid) ||
22252 +               (vc_data.pid > 1)))
22253 +               return -EACCES;
22254 +
22255 +       return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22256 +}
22257 +
22258 +
22259 +static int __wait_exit(struct vx_info *vxi)
22260 +{
22261 +       DECLARE_WAITQUEUE(wait, current);
22262 +       int ret = 0;
22263 +
22264 +       add_wait_queue(&vxi->vx_wait, &wait);
22265 +       set_current_state(TASK_INTERRUPTIBLE);
22266 +
22267 +wait:
22268 +       if (vx_info_state(vxi,
22269 +               VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22270 +               goto out;
22271 +       if (signal_pending(current)) {
22272 +               ret = -ERESTARTSYS;
22273 +               goto out;
22274 +       }
22275 +       schedule();
22276 +       goto wait;
22277 +
22278 +out:
22279 +       set_current_state(TASK_RUNNING);
22280 +       remove_wait_queue(&vxi->vx_wait, &wait);
22281 +       return ret;
22282 +}
22283 +
22284 +
22285 +
22286 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22287 +{
22288 +       struct vcmd_wait_exit_v0 vc_data;
22289 +       int ret;
22290 +
22291 +       ret = __wait_exit(vxi);
22292 +       vc_data.reboot_cmd = vxi->reboot_cmd;
22293 +       vc_data.exit_code = vxi->exit_code;
22294 +
22295 +       if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22296 +               ret = -EFAULT;
22297 +       return ret;
22298 +}
22299 +
22300 diff -NurpP --minimal linux-3.10.40/kernel/vserver/space.c linux-3.10.40-vs2.3.6.8/kernel/vserver/space.c
22301 --- linux-3.10.40/kernel/vserver/space.c        1970-01-01 00:00:00.000000000 +0000
22302 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/space.c      2013-08-22 20:30:00.000000000 +0000
22303 @@ -0,0 +1,436 @@
22304 +/*
22305 + *  linux/kernel/vserver/space.c
22306 + *
22307 + *  Virtual Server: Context Space Support
22308 + *
22309 + *  Copyright (C) 2003-2010  Herbert Pötzl
22310 + *
22311 + *  V0.01  broken out from context.c 0.07
22312 + *  V0.02  added task locking for namespace
22313 + *  V0.03  broken out vx_enter_namespace
22314 + *  V0.04  added *space support and commands
22315 + *  V0.05  added credential support
22316 + *
22317 + */
22318 +
22319 +#include <linux/utsname.h>
22320 +#include <linux/nsproxy.h>
22321 +#include <linux/err.h>
22322 +#include <linux/fs_struct.h>
22323 +#include <linux/cred.h>
22324 +#include <asm/uaccess.h>
22325 +
22326 +#include <linux/vs_context.h>
22327 +#include <linux/vserver/space.h>
22328 +#include <linux/vserver/space_cmd.h>
22329 +
22330 +atomic_t vs_global_nsproxy     = ATOMIC_INIT(0);
22331 +atomic_t vs_global_fs          = ATOMIC_INIT(0);
22332 +atomic_t vs_global_mnt_ns      = ATOMIC_INIT(0);
22333 +atomic_t vs_global_uts_ns      = ATOMIC_INIT(0);
22334 +atomic_t vs_global_user_ns     = ATOMIC_INIT(0);
22335 +atomic_t vs_global_pid_ns      = ATOMIC_INIT(0);
22336 +
22337 +
22338 +/* namespace functions */
22339 +
22340 +#include <linux/mnt_namespace.h>
22341 +#include <linux/user_namespace.h>
22342 +#include <linux/pid_namespace.h>
22343 +#include <linux/ipc_namespace.h>
22344 +#include <net/net_namespace.h>
22345 +#include "../fs/mount.h"
22346 +
22347 +
22348 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22349 +       .mask = CLONE_FS |
22350 +               CLONE_NEWNS |
22351 +#ifdef CONFIG_UTS_NS
22352 +               CLONE_NEWUTS |
22353 +#endif
22354 +#ifdef CONFIG_IPC_NS
22355 +               CLONE_NEWIPC |
22356 +#endif
22357 +#ifdef CONFIG_USER_NS
22358 +               CLONE_NEWUSER |
22359 +#endif
22360 +               0
22361 +};
22362 +
22363 +static const struct vcmd_space_mask_v1 space_mask = {
22364 +       .mask = CLONE_FS |
22365 +               CLONE_NEWNS |
22366 +#ifdef CONFIG_UTS_NS
22367 +               CLONE_NEWUTS |
22368 +#endif
22369 +#ifdef CONFIG_IPC_NS
22370 +               CLONE_NEWIPC |
22371 +#endif
22372 +#ifdef CONFIG_USER_NS
22373 +               CLONE_NEWUSER |
22374 +#endif
22375 +#ifdef CONFIG_PID_NS
22376 +               CLONE_NEWPID |
22377 +#endif
22378 +#ifdef CONFIG_NET_NS
22379 +               CLONE_NEWNET |
22380 +#endif
22381 +               0
22382 +};
22383 +
22384 +static const struct vcmd_space_mask_v1 default_space_mask = {
22385 +       .mask = CLONE_FS |
22386 +               CLONE_NEWNS |
22387 +#ifdef CONFIG_UTS_NS
22388 +               CLONE_NEWUTS |
22389 +#endif
22390 +#ifdef CONFIG_IPC_NS
22391 +               CLONE_NEWIPC |
22392 +#endif
22393 +#ifdef CONFIG_USER_NS
22394 +               CLONE_NEWUSER |
22395 +#endif
22396 +#ifdef CONFIG_PID_NS
22397 +//             CLONE_NEWPID |
22398 +#endif
22399 +               0
22400 +};
22401 +
22402 +/*
22403 + *     build a new nsproxy mix
22404 + *      assumes that both proxies are 'const'
22405 + *     does not touch nsproxy refcounts
22406 + *     will hold a reference on the result.
22407 + */
22408 +
22409 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22410 +       struct nsproxy *new_nsproxy, unsigned long mask)
22411 +{
22412 +       struct mnt_namespace *old_ns;
22413 +       struct uts_namespace *old_uts;
22414 +       struct ipc_namespace *old_ipc;
22415 +#ifdef CONFIG_PID_NS
22416 +       struct pid_namespace *old_pid;
22417 +#endif
22418 +#ifdef CONFIG_NET_NS
22419 +       struct net *old_net;
22420 +#endif
22421 +       struct nsproxy *nsproxy;
22422 +
22423 +       nsproxy = copy_nsproxy(old_nsproxy);
22424 +       if (!nsproxy)
22425 +               goto out;
22426 +
22427 +       if (mask & CLONE_NEWNS) {
22428 +               old_ns = nsproxy->mnt_ns;
22429 +               nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22430 +               if (nsproxy->mnt_ns)
22431 +                       get_mnt_ns(nsproxy->mnt_ns);
22432 +       } else
22433 +               old_ns = NULL;
22434 +
22435 +       if (mask & CLONE_NEWUTS) {
22436 +               old_uts = nsproxy->uts_ns;
22437 +               nsproxy->uts_ns = new_nsproxy->uts_ns;
22438 +               if (nsproxy->uts_ns)
22439 +                       get_uts_ns(nsproxy->uts_ns);
22440 +       } else
22441 +               old_uts = NULL;
22442 +
22443 +       if (mask & CLONE_NEWIPC) {
22444 +               old_ipc = nsproxy->ipc_ns;
22445 +               nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22446 +               if (nsproxy->ipc_ns)
22447 +                       get_ipc_ns(nsproxy->ipc_ns);
22448 +       } else
22449 +               old_ipc = NULL;
22450 +
22451 +#ifdef CONFIG_PID_NS
22452 +       if (mask & CLONE_NEWPID) {
22453 +               old_pid = nsproxy->pid_ns;
22454 +               nsproxy->pid_ns = new_nsproxy->pid_ns;
22455 +               if (nsproxy->pid_ns)
22456 +                       get_pid_ns(nsproxy->pid_ns);
22457 +       } else
22458 +               old_pid = NULL;
22459 +#endif
22460 +#ifdef CONFIG_NET_NS
22461 +       if (mask & CLONE_NEWNET) {
22462 +               old_net = nsproxy->net_ns;
22463 +               nsproxy->net_ns = new_nsproxy->net_ns;
22464 +               if (nsproxy->net_ns)
22465 +                       get_net(nsproxy->net_ns);
22466 +       } else
22467 +               old_net = NULL;
22468 +#endif
22469 +       if (old_ns)
22470 +               put_mnt_ns(old_ns);
22471 +       if (old_uts)
22472 +               put_uts_ns(old_uts);
22473 +       if (old_ipc)
22474 +               put_ipc_ns(old_ipc);
22475 +#ifdef CONFIG_PID_NS
22476 +       if (old_pid)
22477 +               put_pid_ns(old_pid);
22478 +#endif
22479 +#ifdef CONFIG_NET_NS
22480 +       if (old_net)
22481 +               put_net(old_net);
22482 +#endif
22483 +out:
22484 +       return nsproxy;
22485 +}
22486 +
22487 +
22488 +/*
22489 + *     merge two nsproxy structs into a new one.
22490 + *     will hold a reference on the result.
22491 + */
22492 +
22493 +static inline
22494 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22495 +       struct nsproxy *proxy, unsigned long mask)
22496 +{
22497 +       struct nsproxy null_proxy = { .mnt_ns = NULL };
22498 +
22499 +       if (!proxy)
22500 +               return NULL;
22501 +
22502 +       if (mask) {
22503 +               /* vs_mix_nsproxy returns with reference */
22504 +               return vs_mix_nsproxy(old ? old : &null_proxy,
22505 +                       proxy, mask);
22506 +       }
22507 +       get_nsproxy(proxy);
22508 +       return proxy;
22509 +}
22510 +
22511 +
22512 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22513 +{
22514 +       struct nsproxy *proxy, *proxy_cur, *proxy_new;
22515 +       struct fs_struct *fs_cur, *fs = NULL;
22516 +       struct _vx_space *space;
22517 +       int ret, kill = 0;
22518 +
22519 +       vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22520 +               vxi, vxi->vx_id, mask, index);
22521 +
22522 +       if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22523 +               return -EACCES;
22524 +
22525 +       if (index >= VX_SPACES)
22526 +               return -EINVAL;
22527 +
22528 +       space = &vxi->space[index];
22529 +
22530 +       if (!mask)
22531 +               mask = space->vx_nsmask;
22532 +
22533 +       if ((mask & space->vx_nsmask) != mask)
22534 +               return -EINVAL;
22535 +
22536 +       if (mask & CLONE_FS) {
22537 +               fs = copy_fs_struct(space->vx_fs);
22538 +               if (!fs)
22539 +                       return -ENOMEM;
22540 +       }
22541 +       proxy = space->vx_nsproxy;
22542 +
22543 +       vxdprintk(VXD_CBIT(space, 9),
22544 +               "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22545 +               vxi, vxi->vx_id, mask, index, proxy, fs);
22546 +
22547 +       task_lock(current);
22548 +       fs_cur = current->fs;
22549 +
22550 +       if (mask & CLONE_FS) {
22551 +               spin_lock(&fs_cur->lock);
22552 +               current->fs = fs;
22553 +               kill = !--fs_cur->users;
22554 +               spin_unlock(&fs_cur->lock);
22555 +       }
22556 +
22557 +       proxy_cur = current->nsproxy;
22558 +       get_nsproxy(proxy_cur);
22559 +       task_unlock(current);
22560 +
22561 +       if (kill)
22562 +               free_fs_struct(fs_cur);
22563 +
22564 +       proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22565 +       if (IS_ERR(proxy_new)) {
22566 +               ret = PTR_ERR(proxy_new);
22567 +               goto out_put;
22568 +       }
22569 +
22570 +       proxy_new = xchg(&current->nsproxy, proxy_new);
22571 +
22572 +       if (mask & CLONE_NEWUSER) {
22573 +               struct cred *cred;
22574 +
22575 +               vxdprintk(VXD_CBIT(space, 10),
22576 +                       "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22577 +                       vxi, vxi->vx_id, space->vx_cred,
22578 +                       current->real_cred, current->cred);
22579 +
22580 +               if (space->vx_cred) {
22581 +                       cred = __prepare_creds(space->vx_cred);
22582 +                       if (cred)
22583 +                               commit_creds(cred);
22584 +               }
22585 +       }
22586 +
22587 +       ret = 0;
22588 +
22589 +       if (proxy_new)
22590 +               put_nsproxy(proxy_new);
22591 +out_put:
22592 +       if (proxy_cur)
22593 +               put_nsproxy(proxy_cur);
22594 +       return ret;
22595 +}
22596 +
22597 +
22598 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22599 +{
22600 +       struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22601 +       struct fs_struct *fs_vxi, *fs = NULL;
22602 +       struct _vx_space *space;
22603 +       int ret, kill = 0;
22604 +
22605 +       vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22606 +               vxi, vxi->vx_id, mask, index);
22607 +
22608 +       if ((mask & space_mask.mask) != mask)
22609 +               return -EINVAL;
22610 +
22611 +       if (index >= VX_SPACES)
22612 +               return -EINVAL;
22613 +
22614 +       space = &vxi->space[index];
22615 +
22616 +       proxy_vxi = space->vx_nsproxy;
22617 +       fs_vxi = space->vx_fs;
22618 +
22619 +       if (mask & CLONE_FS) {
22620 +               fs = copy_fs_struct(current->fs);
22621 +               if (!fs)
22622 +                       return -ENOMEM;
22623 +       }
22624 +
22625 +       task_lock(current);
22626 +
22627 +       if (mask & CLONE_FS) {
22628 +               spin_lock(&fs_vxi->lock);
22629 +               space->vx_fs = fs;
22630 +               kill = !--fs_vxi->users;
22631 +               spin_unlock(&fs_vxi->lock);
22632 +       }
22633 +
22634 +       proxy_cur = current->nsproxy;
22635 +       get_nsproxy(proxy_cur);
22636 +       task_unlock(current);
22637 +
22638 +       if (kill)
22639 +               free_fs_struct(fs_vxi);
22640 +
22641 +       proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22642 +       if (IS_ERR(proxy_new)) {
22643 +               ret = PTR_ERR(proxy_new);
22644 +               goto out_put;
22645 +       }
22646 +
22647 +       proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22648 +       space->vx_nsmask |= mask;
22649 +
22650 +       if (mask & CLONE_NEWUSER) {
22651 +               struct cred *cred;
22652 +
22653 +               vxdprintk(VXD_CBIT(space, 10),
22654 +                       "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22655 +                       vxi, vxi->vx_id, space->vx_cred,
22656 +                       current->real_cred, current->cred);
22657 +
22658 +               cred = prepare_creds();
22659 +               cred = (struct cred *)xchg(&space->vx_cred, cred);
22660 +               if (cred)
22661 +                       abort_creds(cred);
22662 +       }
22663 +
22664 +       ret = 0;
22665 +
22666 +       if (proxy_new)
22667 +               put_nsproxy(proxy_new);
22668 +out_put:
22669 +       if (proxy_cur)
22670 +               put_nsproxy(proxy_cur);
22671 +       return ret;
22672 +}
22673 +
22674 +
22675 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22676 +{
22677 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22678 +
22679 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22680 +               return -EFAULT;
22681 +
22682 +       return vx_enter_space(vxi, vc_data.mask, 0);
22683 +}
22684 +
22685 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22686 +{
22687 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22688 +
22689 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22690 +               return -EFAULT;
22691 +
22692 +       if (vc_data.index >= VX_SPACES)
22693 +               return -EINVAL;
22694 +
22695 +       return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22696 +}
22697 +
22698 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22699 +{
22700 +       struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22701 +
22702 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22703 +               return -EFAULT;
22704 +
22705 +       return vx_set_space(vxi, vc_data.mask, 0);
22706 +}
22707 +
22708 +int vc_set_space(struct vx_info *vxi, void __user *data)
22709 +{
22710 +       struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22711 +
22712 +       if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22713 +               return -EFAULT;
22714 +
22715 +       if (vc_data.index >= VX_SPACES)
22716 +               return -EINVAL;
22717 +
22718 +       return vx_set_space(vxi, vc_data.mask, vc_data.index);
22719 +}
22720 +
22721 +int vc_get_space_mask(void __user *data, int type)
22722 +{
22723 +       const struct vcmd_space_mask_v1 *mask;
22724 +
22725 +       if (type == 0)
22726 +               mask = &space_mask_v0;
22727 +       else if (type == 1)
22728 +               mask = &space_mask;
22729 +       else
22730 +               mask = &default_space_mask;
22731 +
22732 +       vxdprintk(VXD_CBIT(space, 10),
22733 +               "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22734 +
22735 +       if (copy_to_user(data, mask, sizeof(*mask)))
22736 +               return -EFAULT;
22737 +       return 0;
22738 +}
22739 +
22740 diff -NurpP --minimal linux-3.10.40/kernel/vserver/switch.c linux-3.10.40-vs2.3.6.8/kernel/vserver/switch.c
22741 --- linux-3.10.40/kernel/vserver/switch.c       1970-01-01 00:00:00.000000000 +0000
22742 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/switch.c     2013-08-22 20:30:00.000000000 +0000
22743 @@ -0,0 +1,556 @@
22744 +/*
22745 + *  linux/kernel/vserver/switch.c
22746 + *
22747 + *  Virtual Server: Syscall Switch
22748 + *
22749 + *  Copyright (C) 2003-2011  Herbert Pötzl
22750 + *
22751 + *  V0.01  syscall switch
22752 + *  V0.02  added signal to context
22753 + *  V0.03  added rlimit functions
22754 + *  V0.04  added iattr, task/xid functions
22755 + *  V0.05  added debug/history stuff
22756 + *  V0.06  added compat32 layer
22757 + *  V0.07  vcmd args and perms
22758 + *  V0.08  added status commands
22759 + *  V0.09  added tag commands
22760 + *  V0.10  added oom bias
22761 + *  V0.11  added device commands
22762 + *  V0.12  added warn mask
22763 + *
22764 + */
22765 +
22766 +#include <linux/vs_context.h>
22767 +#include <linux/vs_network.h>
22768 +#include <linux/vserver/switch.h>
22769 +
22770 +#include "vci_config.h"
22771 +
22772 +
22773 +static inline
22774 +int vc_get_version(uint32_t id)
22775 +{
22776 +       return VCI_VERSION;
22777 +}
22778 +
22779 +static inline
22780 +int vc_get_vci(uint32_t id)
22781 +{
22782 +       return vci_kernel_config();
22783 +}
22784 +
22785 +#include <linux/vserver/context_cmd.h>
22786 +#include <linux/vserver/cvirt_cmd.h>
22787 +#include <linux/vserver/cacct_cmd.h>
22788 +#include <linux/vserver/limit_cmd.h>
22789 +#include <linux/vserver/network_cmd.h>
22790 +#include <linux/vserver/sched_cmd.h>
22791 +#include <linux/vserver/debug_cmd.h>
22792 +#include <linux/vserver/inode_cmd.h>
22793 +#include <linux/vserver/dlimit_cmd.h>
22794 +#include <linux/vserver/signal_cmd.h>
22795 +#include <linux/vserver/space_cmd.h>
22796 +#include <linux/vserver/tag_cmd.h>
22797 +#include <linux/vserver/device_cmd.h>
22798 +
22799 +#include <linux/vserver/inode.h>
22800 +#include <linux/vserver/dlimit.h>
22801 +
22802 +
22803 +#ifdef CONFIG_COMPAT
22804 +#define __COMPAT(name, id, data, compat)       \
22805 +       (compat) ? name ## _x32(id, data) : name(id, data)
22806 +#define __COMPAT_NO_ID(name, data, compat)     \
22807 +       (compat) ? name ## _x32(data) : name(data)
22808 +#else
22809 +#define __COMPAT(name, id, data, compat)       \
22810 +       name(id, data)
22811 +#define __COMPAT_NO_ID(name, data, compat)     \
22812 +       name(data)
22813 +#endif
22814 +
22815 +
22816 +static inline
22817 +long do_vcmd(uint32_t cmd, uint32_t id,
22818 +       struct vx_info *vxi, struct nx_info *nxi,
22819 +       void __user *data, int compat)
22820 +{
22821 +       switch (cmd) {
22822 +
22823 +       case VCMD_get_version:
22824 +               return vc_get_version(id);
22825 +       case VCMD_get_vci:
22826 +               return vc_get_vci(id);
22827 +
22828 +       case VCMD_task_xid:
22829 +               return vc_task_xid(id);
22830 +       case VCMD_vx_info:
22831 +               return vc_vx_info(vxi, data);
22832 +
22833 +       case VCMD_task_nid:
22834 +               return vc_task_nid(id);
22835 +       case VCMD_nx_info:
22836 +               return vc_nx_info(nxi, data);
22837 +
22838 +       case VCMD_task_tag:
22839 +               return vc_task_tag(id);
22840 +
22841 +       case VCMD_set_space_v1:
22842 +               return vc_set_space_v1(vxi, data);
22843 +       /* this is version 2 */
22844 +       case VCMD_set_space:
22845 +               return vc_set_space(vxi, data);
22846 +
22847 +       case VCMD_get_space_mask_v0:
22848 +               return vc_get_space_mask(data, 0);
22849 +       /* this is version 1 */
22850 +       case VCMD_get_space_mask:
22851 +               return vc_get_space_mask(data, 1);
22852 +
22853 +       case VCMD_get_space_default:
22854 +               return vc_get_space_mask(data, -1);
22855 +
22856 +       case VCMD_set_umask:
22857 +               return vc_set_umask(vxi, data);
22858 +
22859 +       case VCMD_get_umask:
22860 +               return vc_get_umask(vxi, data);
22861 +
22862 +       case VCMD_set_wmask:
22863 +               return vc_set_wmask(vxi, data);
22864 +
22865 +       case VCMD_get_wmask:
22866 +               return vc_get_wmask(vxi, data);
22867 +#ifdef CONFIG_IA32_EMULATION
22868 +       case VCMD_get_rlimit:
22869 +               return __COMPAT(vc_get_rlimit, vxi, data, compat);
22870 +       case VCMD_set_rlimit:
22871 +               return __COMPAT(vc_set_rlimit, vxi, data, compat);
22872 +#else
22873 +       case VCMD_get_rlimit:
22874 +               return vc_get_rlimit(vxi, data);
22875 +       case VCMD_set_rlimit:
22876 +               return vc_set_rlimit(vxi, data);
22877 +#endif
22878 +       case VCMD_get_rlimit_mask:
22879 +               return vc_get_rlimit_mask(id, data);
22880 +       case VCMD_reset_hits:
22881 +               return vc_reset_hits(vxi, data);
22882 +       case VCMD_reset_minmax:
22883 +               return vc_reset_minmax(vxi, data);
22884 +
22885 +       case VCMD_get_vhi_name:
22886 +               return vc_get_vhi_name(vxi, data);
22887 +       case VCMD_set_vhi_name:
22888 +               return vc_set_vhi_name(vxi, data);
22889 +
22890 +       case VCMD_ctx_stat:
22891 +               return vc_ctx_stat(vxi, data);
22892 +       case VCMD_virt_stat:
22893 +               return vc_virt_stat(vxi, data);
22894 +       case VCMD_sock_stat:
22895 +               return vc_sock_stat(vxi, data);
22896 +       case VCMD_rlimit_stat:
22897 +               return vc_rlimit_stat(vxi, data);
22898 +
22899 +       case VCMD_set_cflags:
22900 +               return vc_set_cflags(vxi, data);
22901 +       case VCMD_get_cflags:
22902 +               return vc_get_cflags(vxi, data);
22903 +
22904 +       /* this is version 1 */
22905 +       case VCMD_set_ccaps:
22906 +               return vc_set_ccaps(vxi, data);
22907 +       /* this is version 1 */
22908 +       case VCMD_get_ccaps:
22909 +               return vc_get_ccaps(vxi, data);
22910 +       case VCMD_set_bcaps:
22911 +               return vc_set_bcaps(vxi, data);
22912 +       case VCMD_get_bcaps:
22913 +               return vc_get_bcaps(vxi, data);
22914 +
22915 +       case VCMD_set_badness:
22916 +               return vc_set_badness(vxi, data);
22917 +       case VCMD_get_badness:
22918 +               return vc_get_badness(vxi, data);
22919 +
22920 +       case VCMD_set_nflags:
22921 +               return vc_set_nflags(nxi, data);
22922 +       case VCMD_get_nflags:
22923 +               return vc_get_nflags(nxi, data);
22924 +
22925 +       case VCMD_set_ncaps:
22926 +               return vc_set_ncaps(nxi, data);
22927 +       case VCMD_get_ncaps:
22928 +               return vc_get_ncaps(nxi, data);
22929 +
22930 +       case VCMD_set_prio_bias:
22931 +               return vc_set_prio_bias(vxi, data);
22932 +       case VCMD_get_prio_bias:
22933 +               return vc_get_prio_bias(vxi, data);
22934 +       case VCMD_add_dlimit:
22935 +               return __COMPAT(vc_add_dlimit, id, data, compat);
22936 +       case VCMD_rem_dlimit:
22937 +               return __COMPAT(vc_rem_dlimit, id, data, compat);
22938 +       case VCMD_set_dlimit:
22939 +               return __COMPAT(vc_set_dlimit, id, data, compat);
22940 +       case VCMD_get_dlimit:
22941 +               return __COMPAT(vc_get_dlimit, id, data, compat);
22942 +
22943 +       case VCMD_ctx_kill:
22944 +               return vc_ctx_kill(vxi, data);
22945 +
22946 +       case VCMD_wait_exit:
22947 +               return vc_wait_exit(vxi, data);
22948 +
22949 +       case VCMD_get_iattr:
22950 +               return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22951 +       case VCMD_set_iattr:
22952 +               return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22953 +
22954 +       case VCMD_fget_iattr:
22955 +               return vc_fget_iattr(id, data);
22956 +       case VCMD_fset_iattr:
22957 +               return vc_fset_iattr(id, data);
22958 +
22959 +       case VCMD_enter_space_v0:
22960 +               return vc_enter_space_v1(vxi, NULL);
22961 +       case VCMD_enter_space_v1:
22962 +               return vc_enter_space_v1(vxi, data);
22963 +       /* this is version 2 */
22964 +       case VCMD_enter_space:
22965 +               return vc_enter_space(vxi, data);
22966 +
22967 +       case VCMD_ctx_create_v0:
22968 +               return vc_ctx_create(id, NULL);
22969 +       case VCMD_ctx_create:
22970 +               return vc_ctx_create(id, data);
22971 +       case VCMD_ctx_migrate_v0:
22972 +               return vc_ctx_migrate(vxi, NULL);
22973 +       case VCMD_ctx_migrate:
22974 +               return vc_ctx_migrate(vxi, data);
22975 +
22976 +       case VCMD_net_create_v0:
22977 +               return vc_net_create(id, NULL);
22978 +       case VCMD_net_create:
22979 +               return vc_net_create(id, data);
22980 +       case VCMD_net_migrate:
22981 +               return vc_net_migrate(nxi, data);
22982 +
22983 +       case VCMD_tag_migrate:
22984 +               return vc_tag_migrate(id);
22985 +
22986 +       case VCMD_net_add:
22987 +               return vc_net_add(nxi, data);
22988 +       case VCMD_net_remove:
22989 +               return vc_net_remove(nxi, data);
22990 +
22991 +       case VCMD_net_add_ipv4_v1:
22992 +               return vc_net_add_ipv4_v1(nxi, data);
22993 +       /* this is version 2 */
22994 +       case VCMD_net_add_ipv4:
22995 +               return vc_net_add_ipv4(nxi, data);
22996 +
22997 +       case VCMD_net_rem_ipv4_v1:
22998 +               return vc_net_rem_ipv4_v1(nxi, data);
22999 +       /* this is version 2 */
23000 +       case VCMD_net_rem_ipv4:
23001 +               return vc_net_rem_ipv4(nxi, data);
23002 +#ifdef CONFIG_IPV6
23003 +       case VCMD_net_add_ipv6:
23004 +               return vc_net_add_ipv6(nxi, data);
23005 +       case VCMD_net_remove_ipv6:
23006 +               return vc_net_remove_ipv6(nxi, data);
23007 +#endif
23008 +/*     case VCMD_add_match_ipv4:
23009 +               return vc_add_match_ipv4(nxi, data);
23010 +       case VCMD_get_match_ipv4:
23011 +               return vc_get_match_ipv4(nxi, data);
23012 +#ifdef CONFIG_IPV6
23013 +       case VCMD_add_match_ipv6:
23014 +               return vc_add_match_ipv6(nxi, data);
23015 +       case VCMD_get_match_ipv6:
23016 +               return vc_get_match_ipv6(nxi, data);
23017 +#endif */
23018 +
23019 +#ifdef CONFIG_VSERVER_DEVICE
23020 +       case VCMD_set_mapping:
23021 +               return __COMPAT(vc_set_mapping, vxi, data, compat);
23022 +       case VCMD_unset_mapping:
23023 +               return __COMPAT(vc_unset_mapping, vxi, data, compat);
23024 +#endif
23025 +#ifdef CONFIG_VSERVER_HISTORY
23026 +       case VCMD_dump_history:
23027 +               return vc_dump_history(id);
23028 +       case VCMD_read_history:
23029 +               return __COMPAT(vc_read_history, id, data, compat);
23030 +#endif
23031 +       default:
23032 +               vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23033 +                       VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23034 +       }
23035 +       return -ENOSYS;
23036 +}
23037 +
23038 +
23039 +#define        __VCMD(vcmd, _perm, _args, _flags)              \
23040 +       case VCMD_ ## vcmd: perm = _perm;               \
23041 +               args = _args; flags = _flags; break
23042 +
23043 +
23044 +#define VCA_NONE       0x00
23045 +#define VCA_VXI                0x01
23046 +#define VCA_NXI                0x02
23047 +
23048 +#define VCF_NONE       0x00
23049 +#define VCF_INFO       0x01
23050 +#define VCF_ADMIN      0x02
23051 +#define VCF_ARES       0x06    /* includes admin */
23052 +#define VCF_SETUP      0x08
23053 +
23054 +#define VCF_ZIDOK      0x10    /* zero id okay */
23055 +
23056 +
23057 +static inline
23058 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23059 +{
23060 +       long ret;
23061 +       int permit = -1, state = 0;
23062 +       int perm = -1, args = 0, flags = 0;
23063 +       struct vx_info *vxi = NULL;
23064 +       struct nx_info *nxi = NULL;
23065 +
23066 +       switch (cmd) {
23067 +       /* unpriviledged commands */
23068 +       __VCMD(get_version,      0, VCA_NONE,   0);
23069 +       __VCMD(get_vci,          0, VCA_NONE,   0);
23070 +       __VCMD(get_rlimit_mask,  0, VCA_NONE,   0);
23071 +       __VCMD(get_space_mask_v0,0, VCA_NONE,   0);
23072 +       __VCMD(get_space_mask,   0, VCA_NONE,   0);
23073 +       __VCMD(get_space_default,0, VCA_NONE,   0);
23074 +
23075 +       /* info commands */
23076 +       __VCMD(task_xid,         2, VCA_NONE,   0);
23077 +       __VCMD(reset_hits,       2, VCA_VXI,    0);
23078 +       __VCMD(reset_minmax,     2, VCA_VXI,    0);
23079 +       __VCMD(vx_info,          3, VCA_VXI,    VCF_INFO);
23080 +       __VCMD(get_bcaps,        3, VCA_VXI,    VCF_INFO);
23081 +       __VCMD(get_ccaps,        3, VCA_VXI,    VCF_INFO);
23082 +       __VCMD(get_cflags,       3, VCA_VXI,    VCF_INFO);
23083 +       __VCMD(get_umask,        3, VCA_VXI,    VCF_INFO);
23084 +       __VCMD(get_wmask,        3, VCA_VXI,    VCF_INFO);
23085 +       __VCMD(get_badness,      3, VCA_VXI,    VCF_INFO);
23086 +       __VCMD(get_vhi_name,     3, VCA_VXI,    VCF_INFO);
23087 +       __VCMD(get_rlimit,       3, VCA_VXI,    VCF_INFO);
23088 +
23089 +       __VCMD(ctx_stat,         3, VCA_VXI,    VCF_INFO);
23090 +       __VCMD(virt_stat,        3, VCA_VXI,    VCF_INFO);
23091 +       __VCMD(sock_stat,        3, VCA_VXI,    VCF_INFO);
23092 +       __VCMD(rlimit_stat,      3, VCA_VXI,    VCF_INFO);
23093 +
23094 +       __VCMD(task_nid,         2, VCA_NONE,   0);
23095 +       __VCMD(nx_info,          3, VCA_NXI,    VCF_INFO);
23096 +       __VCMD(get_ncaps,        3, VCA_NXI,    VCF_INFO);
23097 +       __VCMD(get_nflags,       3, VCA_NXI,    VCF_INFO);
23098 +
23099 +       __VCMD(task_tag,         2, VCA_NONE,   0);
23100 +
23101 +       __VCMD(get_iattr,        2, VCA_NONE,   0);
23102 +       __VCMD(fget_iattr,       2, VCA_NONE,   0);
23103 +       __VCMD(get_dlimit,       3, VCA_NONE,   VCF_INFO);
23104 +       __VCMD(get_prio_bias,    3, VCA_VXI,    VCF_INFO);
23105 +
23106 +       /* lower admin commands */
23107 +       __VCMD(wait_exit,        4, VCA_VXI,    VCF_INFO);
23108 +       __VCMD(ctx_create_v0,    5, VCA_NONE,   0);
23109 +       __VCMD(ctx_create,       5, VCA_NONE,   0);
23110 +       __VCMD(ctx_migrate_v0,   5, VCA_VXI,    VCF_ADMIN);
23111 +       __VCMD(ctx_migrate,      5, VCA_VXI,    VCF_ADMIN);
23112 +       __VCMD(enter_space_v0,   5, VCA_VXI,    VCF_ADMIN);
23113 +       __VCMD(enter_space_v1,   5, VCA_VXI,    VCF_ADMIN);
23114 +       __VCMD(enter_space,      5, VCA_VXI,    VCF_ADMIN);
23115 +
23116 +       __VCMD(net_create_v0,    5, VCA_NONE,   0);
23117 +       __VCMD(net_create,       5, VCA_NONE,   0);
23118 +       __VCMD(net_migrate,      5, VCA_NXI,    VCF_ADMIN);
23119 +
23120 +       __VCMD(tag_migrate,      5, VCA_NONE,   VCF_ADMIN);
23121 +
23122 +       /* higher admin commands */
23123 +       __VCMD(ctx_kill,         6, VCA_VXI,    VCF_ARES);
23124 +       __VCMD(set_space_v1,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23125 +       __VCMD(set_space,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23126 +
23127 +       __VCMD(set_ccaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23128 +       __VCMD(set_bcaps,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23129 +       __VCMD(set_cflags,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23130 +       __VCMD(set_umask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23131 +       __VCMD(set_wmask,        7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23132 +       __VCMD(set_badness,      7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23133 +
23134 +       __VCMD(set_vhi_name,     7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23135 +       __VCMD(set_rlimit,       7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23136 +       __VCMD(set_prio_bias,    7, VCA_VXI,    VCF_ARES | VCF_SETUP);
23137 +
23138 +       __VCMD(set_ncaps,        7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23139 +       __VCMD(set_nflags,       7, VCA_NXI,    VCF_ARES | VCF_SETUP);
23140 +       __VCMD(net_add,          8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23141 +       __VCMD(net_remove,       8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23142 +       __VCMD(net_add_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23143 +       __VCMD(net_rem_ipv4_v1,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23144 +       __VCMD(net_add_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23145 +       __VCMD(net_rem_ipv4,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23146 +#ifdef CONFIG_IPV6
23147 +       __VCMD(net_add_ipv6,     8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23148 +       __VCMD(net_remove_ipv6,  8, VCA_NXI,    VCF_ARES | VCF_SETUP);
23149 +#endif
23150 +       __VCMD(set_iattr,        7, VCA_NONE,   0);
23151 +       __VCMD(fset_iattr,       7, VCA_NONE,   0);
23152 +       __VCMD(set_dlimit,       7, VCA_NONE,   VCF_ARES);
23153 +       __VCMD(add_dlimit,       8, VCA_NONE,   VCF_ARES);
23154 +       __VCMD(rem_dlimit,       8, VCA_NONE,   VCF_ARES);
23155 +
23156 +#ifdef CONFIG_VSERVER_DEVICE
23157 +       __VCMD(set_mapping,      8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23158 +       __VCMD(unset_mapping,    8, VCA_VXI,    VCF_ARES|VCF_ZIDOK);
23159 +#endif
23160 +       /* debug level admin commands */
23161 +#ifdef CONFIG_VSERVER_HISTORY
23162 +       __VCMD(dump_history,     9, VCA_NONE,   0);
23163 +       __VCMD(read_history,     9, VCA_NONE,   0);
23164 +#endif
23165 +
23166 +       default:
23167 +               perm = -1;
23168 +       }
23169 +
23170 +       vxdprintk(VXD_CBIT(switch, 0),
23171 +               "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23172 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23173 +               VC_VERSION(cmd), id, data, compat,
23174 +               perm, args, flags);
23175 +
23176 +       ret = -ENOSYS;
23177 +       if (perm < 0)
23178 +               goto out;
23179 +
23180 +       state = 1;
23181 +       if (!capable(CAP_CONTEXT))
23182 +               goto out;
23183 +
23184 +       state = 2;
23185 +       /* moved here from the individual commands */
23186 +       ret = -EPERM;
23187 +       if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23188 +               goto out;
23189 +
23190 +       state = 3;
23191 +       /* vcmd involves resource management  */
23192 +       ret = -EPERM;
23193 +       if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23194 +               goto out;
23195 +
23196 +       state = 4;
23197 +       /* various legacy exceptions */
23198 +       switch (cmd) {
23199 +       /* will go away when spectator is a cap */
23200 +       case VCMD_ctx_migrate_v0:
23201 +       case VCMD_ctx_migrate:
23202 +               if (id == 1) {
23203 +                       current->xid = 1;
23204 +                       ret = 1;
23205 +                       goto out;
23206 +               }
23207 +               break;
23208 +
23209 +       /* will go away when spectator is a cap */
23210 +       case VCMD_net_migrate:
23211 +               if (id == 1) {
23212 +                       current->nid = 1;
23213 +                       ret = 1;
23214 +                       goto out;
23215 +               }
23216 +               break;
23217 +       }
23218 +
23219 +       /* vcmds are fine by default */
23220 +       permit = 1;
23221 +
23222 +       /* admin type vcmds require admin ... */
23223 +       if (flags & VCF_ADMIN)
23224 +               permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23225 +
23226 +       /* ... but setup type vcmds override that */
23227 +       if (!permit && (flags & VCF_SETUP))
23228 +               permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23229 +
23230 +       state = 5;
23231 +       ret = -EPERM;
23232 +       if (!permit)
23233 +               goto out;
23234 +
23235 +       state = 6;
23236 +       if (!id && (flags & VCF_ZIDOK))
23237 +               goto skip_id;
23238 +
23239 +       ret = -ESRCH;
23240 +       if (args & VCA_VXI) {
23241 +               vxi = lookup_vx_info(id);
23242 +               if (!vxi)
23243 +                       goto out;
23244 +
23245 +               if ((flags & VCF_ADMIN) &&
23246 +                       /* special case kill for shutdown */
23247 +                       (cmd != VCMD_ctx_kill) &&
23248 +                       /* can context be administrated? */
23249 +                       !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23250 +                       ret = -EACCES;
23251 +                       goto out_vxi;
23252 +               }
23253 +       }
23254 +       state = 7;
23255 +       if (args & VCA_NXI) {
23256 +               nxi = lookup_nx_info(id);
23257 +               if (!nxi)
23258 +                       goto out_vxi;
23259 +
23260 +               if ((flags & VCF_ADMIN) &&
23261 +                       /* can context be administrated? */
23262 +                       !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23263 +                       ret = -EACCES;
23264 +                       goto out_nxi;
23265 +               }
23266 +       }
23267 +skip_id:
23268 +       state = 8;
23269 +       ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23270 +
23271 +out_nxi:
23272 +       if ((args & VCA_NXI) && nxi)
23273 +               put_nx_info(nxi);
23274 +out_vxi:
23275 +       if ((args & VCA_VXI) && vxi)
23276 +               put_vx_info(vxi);
23277 +out:
23278 +       vxdprintk(VXD_CBIT(switch, 1),
23279 +               "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23280 +               VC_CATEGORY(cmd), VC_COMMAND(cmd),
23281 +               VC_VERSION(cmd), ret, ret, state, permit);
23282 +       return ret;
23283 +}
23284 +
23285 +asmlinkage long
23286 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23287 +{
23288 +       return do_vserver(cmd, id, data, 0);
23289 +}
23290 +
23291 +#ifdef CONFIG_COMPAT
23292 +
23293 +asmlinkage long
23294 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23295 +{
23296 +       return do_vserver(cmd, id, data, 1);
23297 +}
23298 +
23299 +#endif /* CONFIG_COMPAT */
23300 diff -NurpP --minimal linux-3.10.40/kernel/vserver/sysctl.c linux-3.10.40-vs2.3.6.8/kernel/vserver/sysctl.c
23301 --- linux-3.10.40/kernel/vserver/sysctl.c       1970-01-01 00:00:00.000000000 +0000
23302 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/sysctl.c     2013-08-22 20:30:00.000000000 +0000
23303 @@ -0,0 +1,247 @@
23304 +/*
23305 + *  kernel/vserver/sysctl.c
23306 + *
23307 + *  Virtual Context Support
23308 + *
23309 + *  Copyright (C) 2004-2007  Herbert Pötzl
23310 + *
23311 + *  V0.01  basic structure
23312 + *
23313 + */
23314 +
23315 +#include <linux/module.h>
23316 +#include <linux/ctype.h>
23317 +#include <linux/sysctl.h>
23318 +#include <linux/parser.h>
23319 +#include <asm/uaccess.h>
23320 +
23321 +enum {
23322 +       CTL_DEBUG_ERROR         = 0,
23323 +       CTL_DEBUG_SWITCH        = 1,
23324 +       CTL_DEBUG_XID,
23325 +       CTL_DEBUG_NID,
23326 +       CTL_DEBUG_TAG,
23327 +       CTL_DEBUG_NET,
23328 +       CTL_DEBUG_LIMIT,
23329 +       CTL_DEBUG_CRES,
23330 +       CTL_DEBUG_DLIM,
23331 +       CTL_DEBUG_QUOTA,
23332 +       CTL_DEBUG_CVIRT,
23333 +       CTL_DEBUG_SPACE,
23334 +       CTL_DEBUG_PERM,
23335 +       CTL_DEBUG_MISC,
23336 +};
23337 +
23338 +
23339 +unsigned int vs_debug_switch   = 0;
23340 +unsigned int vs_debug_xid      = 0;
23341 +unsigned int vs_debug_nid      = 0;
23342 +unsigned int vs_debug_tag      = 0;
23343 +unsigned int vs_debug_net      = 0;
23344 +unsigned int vs_debug_limit    = 0;
23345 +unsigned int vs_debug_cres     = 0;
23346 +unsigned int vs_debug_dlim     = 0;
23347 +unsigned int vs_debug_quota    = 0;
23348 +unsigned int vs_debug_cvirt    = 0;
23349 +unsigned int vs_debug_space    = 0;
23350 +unsigned int vs_debug_perm     = 0;
23351 +unsigned int vs_debug_misc     = 0;
23352 +
23353 +
23354 +static struct ctl_table_header *vserver_table_header;
23355 +static ctl_table vserver_root_table[];
23356 +
23357 +
23358 +void vserver_register_sysctl(void)
23359 +{
23360 +       if (!vserver_table_header) {
23361 +               vserver_table_header = register_sysctl_table(vserver_root_table);
23362 +       }
23363 +
23364 +}
23365 +
23366 +void vserver_unregister_sysctl(void)
23367 +{
23368 +       if (vserver_table_header) {
23369 +               unregister_sysctl_table(vserver_table_header);
23370 +               vserver_table_header = NULL;
23371 +       }
23372 +}
23373 +
23374 +
23375 +static int proc_dodebug(ctl_table *table, int write,
23376 +       void __user *buffer, size_t *lenp, loff_t *ppos)
23377 +{
23378 +       char            tmpbuf[20], *p, c;
23379 +       unsigned int    value;
23380 +       size_t          left, len;
23381 +
23382 +       if ((*ppos && !write) || !*lenp) {
23383 +               *lenp = 0;
23384 +               return 0;
23385 +       }
23386 +
23387 +       left = *lenp;
23388 +
23389 +       if (write) {
23390 +               if (!access_ok(VERIFY_READ, buffer, left))
23391 +                       return -EFAULT;
23392 +               p = (char *)buffer;
23393 +               while (left && __get_user(c, p) >= 0 && isspace(c))
23394 +                       left--, p++;
23395 +               if (!left)
23396 +                       goto done;
23397 +
23398 +               if (left > sizeof(tmpbuf) - 1)
23399 +                       return -EINVAL;
23400 +               if (copy_from_user(tmpbuf, p, left))
23401 +                       return -EFAULT;
23402 +               tmpbuf[left] = '\0';
23403 +
23404 +               for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23405 +                       value = 10 * value + (*p - '0');
23406 +               if (*p && !isspace(*p))
23407 +                       return -EINVAL;
23408 +               while (left && isspace(*p))
23409 +                       left--, p++;
23410 +               *(unsigned int *)table->data = value;
23411 +       } else {
23412 +               if (!access_ok(VERIFY_WRITE, buffer, left))
23413 +                       return -EFAULT;
23414 +               len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23415 +               if (len > left)
23416 +                       len = left;
23417 +               if (__copy_to_user(buffer, tmpbuf, len))
23418 +                       return -EFAULT;
23419 +               if ((left -= len) > 0) {
23420 +                       if (put_user('\n', (char *)buffer + len))
23421 +                               return -EFAULT;
23422 +                       left--;
23423 +               }
23424 +       }
23425 +
23426 +done:
23427 +       *lenp -= left;
23428 +       *ppos += *lenp;
23429 +       return 0;
23430 +}
23431 +
23432 +static int zero;
23433 +
23434 +#define        CTL_ENTRY(ctl, name)                            \
23435 +       {                                               \
23436 +               .procname       = #name,                \
23437 +               .data           = &vs_ ## name,         \
23438 +               .maxlen         = sizeof(int),          \
23439 +               .mode           = 0644,                 \
23440 +               .proc_handler   = &proc_dodebug,        \
23441 +               .extra1         = &zero,                \
23442 +               .extra2         = &zero,                \
23443 +       }
23444 +
23445 +static ctl_table vserver_debug_table[] = {
23446 +       CTL_ENTRY(CTL_DEBUG_SWITCH,     debug_switch),
23447 +       CTL_ENTRY(CTL_DEBUG_XID,        debug_xid),
23448 +       CTL_ENTRY(CTL_DEBUG_NID,        debug_nid),
23449 +       CTL_ENTRY(CTL_DEBUG_TAG,        debug_tag),
23450 +       CTL_ENTRY(CTL_DEBUG_NET,        debug_net),
23451 +       CTL_ENTRY(CTL_DEBUG_LIMIT,      debug_limit),
23452 +       CTL_ENTRY(CTL_DEBUG_CRES,       debug_cres),
23453 +       CTL_ENTRY(CTL_DEBUG_DLIM,       debug_dlim),
23454 +       CTL_ENTRY(CTL_DEBUG_QUOTA,      debug_quota),
23455 +       CTL_ENTRY(CTL_DEBUG_CVIRT,      debug_cvirt),
23456 +       CTL_ENTRY(CTL_DEBUG_SPACE,      debug_space),
23457 +       CTL_ENTRY(CTL_DEBUG_PERM,       debug_perm),
23458 +       CTL_ENTRY(CTL_DEBUG_MISC,       debug_misc),
23459 +       { 0 }
23460 +};
23461 +
23462 +static ctl_table vserver_root_table[] = {
23463 +       {
23464 +               .procname       = "vserver",
23465 +               .mode           = 0555,
23466 +               .child          = vserver_debug_table
23467 +       },
23468 +       { 0 }
23469 +};
23470 +
23471 +
23472 +static match_table_t tokens = {
23473 +       { CTL_DEBUG_SWITCH,     "switch=%x"     },
23474 +       { CTL_DEBUG_XID,        "xid=%x"        },
23475 +       { CTL_DEBUG_NID,        "nid=%x"        },
23476 +       { CTL_DEBUG_TAG,        "tag=%x"        },
23477 +       { CTL_DEBUG_NET,        "net=%x"        },
23478 +       { CTL_DEBUG_LIMIT,      "limit=%x"      },
23479 +       { CTL_DEBUG_CRES,       "cres=%x"       },
23480 +       { CTL_DEBUG_DLIM,       "dlim=%x"       },
23481 +       { CTL_DEBUG_QUOTA,      "quota=%x"      },
23482 +       { CTL_DEBUG_CVIRT,      "cvirt=%x"      },
23483 +       { CTL_DEBUG_SPACE,      "space=%x"      },
23484 +       { CTL_DEBUG_PERM,       "perm=%x"       },
23485 +       { CTL_DEBUG_MISC,       "misc=%x"       },
23486 +       { CTL_DEBUG_ERROR,      NULL            }
23487 +};
23488 +
23489 +#define        HANDLE_CASE(id, name, val)                              \
23490 +       case CTL_DEBUG_ ## id:                                  \
23491 +               vs_debug_ ## name = val;                        \
23492 +               printk("vs_debug_" #name "=0x%x\n", val);       \
23493 +               break
23494 +
23495 +
23496 +static int __init vs_debug_setup(char *str)
23497 +{
23498 +       char *p;
23499 +       int token;
23500 +
23501 +       printk("vs_debug_setup(%s)\n", str);
23502 +       while ((p = strsep(&str, ",")) != NULL) {
23503 +               substring_t args[MAX_OPT_ARGS];
23504 +               unsigned int value;
23505 +
23506 +               if (!*p)
23507 +                       continue;
23508 +
23509 +               token = match_token(p, tokens, args);
23510 +               value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23511 +
23512 +               switch (token) {
23513 +               HANDLE_CASE(SWITCH, switch, value);
23514 +               HANDLE_CASE(XID,    xid,    value);
23515 +               HANDLE_CASE(NID,    nid,    value);
23516 +               HANDLE_CASE(TAG,    tag,    value);
23517 +               HANDLE_CASE(NET,    net,    value);
23518 +               HANDLE_CASE(LIMIT,  limit,  value);
23519 +               HANDLE_CASE(CRES,   cres,   value);
23520 +               HANDLE_CASE(DLIM,   dlim,   value);
23521 +               HANDLE_CASE(QUOTA,  quota,  value);
23522 +               HANDLE_CASE(CVIRT,  cvirt,  value);
23523 +               HANDLE_CASE(SPACE,  space,  value);
23524 +               HANDLE_CASE(PERM,   perm,   value);
23525 +               HANDLE_CASE(MISC,   misc,   value);
23526 +               default:
23527 +                       return -EINVAL;
23528 +                       break;
23529 +               }
23530 +       }
23531 +       return 1;
23532 +}
23533 +
23534 +__setup("vsdebug=", vs_debug_setup);
23535 +
23536 +
23537 +
23538 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23539 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23540 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23541 +EXPORT_SYMBOL_GPL(vs_debug_net);
23542 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23543 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23544 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23545 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23546 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23547 +EXPORT_SYMBOL_GPL(vs_debug_space);
23548 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23549 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23550 +
23551 diff -NurpP --minimal linux-3.10.40/kernel/vserver/tag.c linux-3.10.40-vs2.3.6.8/kernel/vserver/tag.c
23552 --- linux-3.10.40/kernel/vserver/tag.c  1970-01-01 00:00:00.000000000 +0000
23553 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/tag.c        2013-08-22 20:30:00.000000000 +0000
23554 @@ -0,0 +1,63 @@
23555 +/*
23556 + *  linux/kernel/vserver/tag.c
23557 + *
23558 + *  Virtual Server: Shallow Tag Space
23559 + *
23560 + *  Copyright (C) 2007  Herbert Pötzl
23561 + *
23562 + *  V0.01  basic implementation
23563 + *
23564 + */
23565 +
23566 +#include <linux/sched.h>
23567 +#include <linux/vserver/debug.h>
23568 +#include <linux/vs_pid.h>
23569 +#include <linux/vs_tag.h>
23570 +
23571 +#include <linux/vserver/tag_cmd.h>
23572 +
23573 +
23574 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
23575 +{
23576 +       if (!p)
23577 +               BUG();
23578 +
23579 +       vxdprintk(VXD_CBIT(tag, 5),
23580 +               "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23581 +
23582 +       task_lock(p);
23583 +       p->tag = tag;
23584 +       task_unlock(p);
23585 +
23586 +       vxdprintk(VXD_CBIT(tag, 5),
23587 +               "moved task %p into [#%d]", p, tag);
23588 +       return 0;
23589 +}
23590 +
23591 +/* vserver syscall commands below here */
23592 +
23593 +/* taks xid and vx_info functions */
23594 +
23595 +
23596 +int vc_task_tag(uint32_t id)
23597 +{
23598 +       vtag_t tag;
23599 +
23600 +       if (id) {
23601 +               struct task_struct *tsk;
23602 +               rcu_read_lock();
23603 +               tsk = find_task_by_real_pid(id);
23604 +               tag = (tsk) ? tsk->tag : -ESRCH;
23605 +               rcu_read_unlock();
23606 +       } else
23607 +               tag = dx_current_tag();
23608 +       return tag;
23609 +}
23610 +
23611 +
23612 +int vc_tag_migrate(uint32_t tag)
23613 +{
23614 +       return dx_migrate_task(current, tag & 0xFFFF);
23615 +}
23616 +
23617 +
23618 diff -NurpP --minimal linux-3.10.40/kernel/vserver/vci_config.h linux-3.10.40-vs2.3.6.8/kernel/vserver/vci_config.h
23619 --- linux-3.10.40/kernel/vserver/vci_config.h   1970-01-01 00:00:00.000000000 +0000
23620 +++ linux-3.10.40-vs2.3.6.8/kernel/vserver/vci_config.h 2013-08-22 20:30:00.000000000 +0000
23621 @@ -0,0 +1,80 @@
23622 +
23623 +/*  interface version */
23624 +
23625 +#define VCI_VERSION            0x00020308
23626 +
23627 +
23628 +enum {
23629 +       VCI_KCBIT_NO_DYNAMIC = 0,
23630 +
23631 +       VCI_KCBIT_PROC_SECURE = 4,
23632 +       /* VCI_KCBIT_HARDCPU = 5, */
23633 +       /* VCI_KCBIT_IDLELIMIT = 6, */
23634 +       /* VCI_KCBIT_IDLETIME = 7, */
23635 +
23636 +       VCI_KCBIT_COWBL = 8,
23637 +       VCI_KCBIT_FULLCOWBL = 9,
23638 +       VCI_KCBIT_SPACES = 10,
23639 +       VCI_KCBIT_NETV2 = 11,
23640 +       VCI_KCBIT_MEMCG = 12,
23641 +       VCI_KCBIT_MEMCG_SWAP = 13,
23642 +
23643 +       VCI_KCBIT_DEBUG = 16,
23644 +       VCI_KCBIT_HISTORY = 20,
23645 +       VCI_KCBIT_TAGGED = 24,
23646 +       VCI_KCBIT_PPTAG = 28,
23647 +
23648 +       VCI_KCBIT_MORE = 31,
23649 +};
23650 +
23651 +
23652 +static inline uint32_t vci_kernel_config(void)
23653 +{
23654 +       return
23655 +       (1 << VCI_KCBIT_NO_DYNAMIC) |
23656 +
23657 +       /* configured features */
23658 +#ifdef CONFIG_VSERVER_PROC_SECURE
23659 +       (1 << VCI_KCBIT_PROC_SECURE) |
23660 +#endif
23661 +#ifdef CONFIG_VSERVER_COWBL
23662 +       (1 << VCI_KCBIT_COWBL) |
23663 +       (1 << VCI_KCBIT_FULLCOWBL) |
23664 +#endif
23665 +       (1 << VCI_KCBIT_SPACES) |
23666 +       (1 << VCI_KCBIT_NETV2) |
23667 +#ifdef CONFIG_MEMCG
23668 +       (1 << VCI_KCBIT_MEMCG) |
23669 +#endif
23670 +#ifdef CONFIG_MEMCG_SWAP
23671 +       (1 << VCI_KCBIT_MEMCG_SWAP) |
23672 +#endif
23673 +
23674 +       /* debug options */
23675 +#ifdef CONFIG_VSERVER_DEBUG
23676 +       (1 << VCI_KCBIT_DEBUG) |
23677 +#endif
23678 +#ifdef CONFIG_VSERVER_HISTORY
23679 +       (1 << VCI_KCBIT_HISTORY) |
23680 +#endif
23681 +
23682 +       /* inode context tagging */
23683 +#if    defined(CONFIG_TAGGING_NONE)
23684 +       (0 << VCI_KCBIT_TAGGED) |
23685 +#elif  defined(CONFIG_TAGGING_UID16)
23686 +       (1 << VCI_KCBIT_TAGGED) |
23687 +#elif  defined(CONFIG_TAGGING_GID16)
23688 +       (2 << VCI_KCBIT_TAGGED) |
23689 +#elif  defined(CONFIG_TAGGING_ID24)
23690 +       (3 << VCI_KCBIT_TAGGED) |
23691 +#elif  defined(CONFIG_TAGGING_INTERN)
23692 +       (4 << VCI_KCBIT_TAGGED) |
23693 +#elif  defined(CONFIG_TAGGING_RUNTIME)
23694 +       (5 << VCI_KCBIT_TAGGED) |
23695 +#else
23696 +       (7 << VCI_KCBIT_TAGGED) |
23697 +#endif
23698 +       (1 << VCI_KCBIT_PPTAG) |
23699 +       0;
23700 +}
23701 +
23702 diff -NurpP --minimal linux-3.10.40/mm/memcontrol.c linux-3.10.40-vs2.3.6.8/mm/memcontrol.c
23703 --- linux-3.10.40/mm/memcontrol.c       2014-05-20 04:09:42.000000000 +0000
23704 +++ linux-3.10.40-vs2.3.6.8/mm/memcontrol.c     2014-04-22 03:48:11.000000000 +0000
23705 @@ -1082,6 +1082,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23706         return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23707  }
23708  
23709 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23710 +{
23711 +       return res_counter_read_u64(&mem->res, member);
23712 +}
23713 +
23714 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23715 +{
23716 +       return res_counter_read_u64(&mem->memsw, member);
23717 +}
23718 +
23719 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23720 +{
23721 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23722 +}
23723 +
23724 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23725 +{
23726 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23727 +}
23728 +
23729 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23730 +{
23731 +       return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23732 +}
23733 +
23734  struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23735  {
23736         struct mem_cgroup *memcg = NULL;
23737 diff -NurpP --minimal linux-3.10.40/mm/oom_kill.c linux-3.10.40-vs2.3.6.8/mm/oom_kill.c
23738 --- linux-3.10.40/mm/oom_kill.c 2014-05-20 04:09:42.000000000 +0000
23739 +++ linux-3.10.40-vs2.3.6.8/mm/oom_kill.c       2014-03-12 13:18:23.000000000 +0000
23740 @@ -35,6 +35,8 @@
23741  #include <linux/freezer.h>
23742  #include <linux/ftrace.h>
23743  #include <linux/ratelimit.h>
23744 +#include <linux/reboot.h>
23745 +#include <linux/vs_context.h>
23746  
23747  #define CREATE_TRACE_POINTS
23748  #include <trace/events/oom.h>
23749 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23750  static bool oom_unkillable_task(struct task_struct *p,
23751                 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23752  {
23753 -       if (is_global_init(p))
23754 +       unsigned xid = vx_current_xid();
23755 +
23756 +       /* skip the init task, global and per guest */
23757 +       if (task_is_init(p))
23758                 return true;
23759         if (p->flags & PF_KTHREAD)
23760                 return true;
23761  
23762 +       /* skip other guest and host processes if oom in guest */
23763 +       if (xid && vx_task_xid(p) != xid)
23764 +               return true;
23765 +
23766         /* When mem_cgroup_out_of_memory() and p is not member of the group */
23767         if (memcg && !task_in_mem_cgroup(p, memcg))
23768                 return true;
23769 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23770                 dump_header(p, gfp_mask, order, memcg, nodemask);
23771  
23772         task_lock(p);
23773 -       pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23774 -               message, task_pid_nr(p), p->comm, points);
23775 +       pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23776 +               message, task_pid_nr(p), p->xid, p->comm, points);
23777         task_unlock(p);
23778  
23779         /*
23780 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23781  
23782         /* mm cannot safely be dereferenced after task_unlock(victim) */
23783         mm = victim->mm;
23784 -       pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23785 -               task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23786 +       pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23787 +               task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23788                 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23789                 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23790         task_unlock(victim);
23791 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23792  }
23793  EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23794  
23795 +long vs_oom_action(unsigned int);
23796 +
23797  /*
23798   * Try to acquire the OOM killer lock for the zones in zonelist.  Returns zero
23799   * if a parallel OOM killing is already taking place that includes a zone in
23800 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23801         /* Found nothing?!?! Either we hang forever, or we panic. */
23802         if (!p) {
23803                 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23804 -               panic("Out of memory and no killable processes...\n");
23805 +
23806 +               /* avoid panic for guest OOM */
23807 +               if (vx_current_xid())
23808 +                       vs_oom_action(LINUX_REBOOT_CMD_OOM);
23809 +               else
23810 +                       panic("Out of memory and no killable processes...\n");
23811         }
23812         if (PTR_ERR(p) != -1UL) {
23813                 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23814 diff -NurpP --minimal linux-3.10.40/mm/page_alloc.c linux-3.10.40-vs2.3.6.8/mm/page_alloc.c
23815 --- linux-3.10.40/mm/page_alloc.c       2014-05-20 04:09:42.000000000 +0000
23816 +++ linux-3.10.40-vs2.3.6.8/mm/page_alloc.c     2014-04-22 03:48:11.000000000 +0000
23817 @@ -60,6 +60,8 @@
23818  #include <linux/page-debug-flags.h>
23819  #include <linux/hugetlb.h>
23820  #include <linux/sched/rt.h>
23821 +#include <linux/vs_base.h>
23822 +#include <linux/vs_limit.h>
23823  
23824  #include <asm/tlbflush.h>
23825  #include <asm/div64.h>
23826 @@ -2901,6 +2903,9 @@ void si_meminfo(struct sysinfo *val)
23827         val->totalhigh = totalhigh_pages;
23828         val->freehigh = nr_free_highpages();
23829         val->mem_unit = PAGE_SIZE;
23830 +
23831 +       if (vx_flags(VXF_VIRT_MEM, 0))
23832 +               vx_vsi_meminfo(val);
23833  }
23834  
23835  EXPORT_SYMBOL(si_meminfo);
23836 @@ -2921,6 +2926,9 @@ void si_meminfo_node(struct sysinfo *val
23837         val->freehigh = 0;
23838  #endif
23839         val->mem_unit = PAGE_SIZE;
23840 +
23841 +       if (vx_flags(VXF_VIRT_MEM, 0))
23842 +               vx_vsi_meminfo(val);
23843  }
23844  #endif
23845  
23846 diff -NurpP --minimal linux-3.10.40/mm/pgtable-generic.c linux-3.10.40-vs2.3.6.8/mm/pgtable-generic.c
23847 --- linux-3.10.40/mm/pgtable-generic.c  2014-05-20 04:09:42.000000000 +0000
23848 +++ linux-3.10.40-vs2.3.6.8/mm/pgtable-generic.c        2014-01-22 19:00:34.000000000 +0000
23849 @@ -6,6 +6,8 @@
23850   *  Copyright (C) 2010  Linus Torvalds
23851   */
23852  
23853 +#include <linux/mm.h>
23854 +
23855  #include <linux/pagemap.h>
23856  #include <asm/tlb.h>
23857  #include <asm-generic/pgtable.h>
23858 diff -NurpP --minimal linux-3.10.40/mm/shmem.c linux-3.10.40-vs2.3.6.8/mm/shmem.c
23859 --- linux-3.10.40/mm/shmem.c    2014-05-20 04:09:42.000000000 +0000
23860 +++ linux-3.10.40-vs2.3.6.8/mm/shmem.c  2013-11-13 17:17:16.000000000 +0000
23861 @@ -1911,7 +1911,7 @@ static int shmem_statfs(struct dentry *d
23862  {
23863         struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23864  
23865 -       buf->f_type = TMPFS_MAGIC;
23866 +       buf->f_type = TMPFS_SUPER_MAGIC;
23867         buf->f_bsize = PAGE_CACHE_SIZE;
23868         buf->f_namelen = NAME_MAX;
23869         if (sbinfo->max_blocks) {
23870 @@ -2608,7 +2608,7 @@ int shmem_fill_super(struct super_block
23871         sb->s_maxbytes = MAX_LFS_FILESIZE;
23872         sb->s_blocksize = PAGE_CACHE_SIZE;
23873         sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23874 -       sb->s_magic = TMPFS_MAGIC;
23875 +       sb->s_magic = TMPFS_SUPER_MAGIC;
23876         sb->s_op = &shmem_ops;
23877         sb->s_time_gran = 1;
23878  #ifdef CONFIG_TMPFS_XATTR
23879 diff -NurpP --minimal linux-3.10.40/mm/slab.c linux-3.10.40-vs2.3.6.8/mm/slab.c
23880 --- linux-3.10.40/mm/slab.c     2014-05-20 04:09:42.000000000 +0000
23881 +++ linux-3.10.40-vs2.3.6.8/mm/slab.c   2013-11-13 17:17:16.000000000 +0000
23882 @@ -388,6 +388,8 @@ static void kmem_cache_node_init(struct
23883  #define STATS_INC_FREEMISS(x)  do { } while (0)
23884  #endif
23885  
23886 +#include "slab_vs.h"
23887 +
23888  #if DEBUG
23889  
23890  /*
23891 @@ -3314,6 +3316,7 @@ retry:
23892  
23893         obj = slab_get_obj(cachep, slabp, nodeid);
23894         check_slabp(cachep, slabp);
23895 +       vx_slab_alloc(cachep, flags);
23896         n->free_objects--;
23897         /* move slabp to correct slabp list: */
23898         list_del(&slabp->list);
23899 @@ -3393,6 +3396,7 @@ slab_alloc_node(struct kmem_cache *cache
23900         /* ___cache_alloc_node can fall back to other nodes */
23901         ptr = ____cache_alloc_node(cachep, flags, nodeid);
23902    out:
23903 +       vx_slab_alloc(cachep, flags);
23904         local_irq_restore(save_flags);
23905         ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23906         kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23907 @@ -3585,6 +3589,7 @@ static inline void __cache_free(struct k
23908         check_irq_off();
23909         kmemleak_free_recursive(objp, cachep->flags);
23910         objp = cache_free_debugcheck(cachep, objp, caller);
23911 +       vx_slab_free(cachep);
23912  
23913         kmemcheck_slab_free(cachep, objp, cachep->object_size);
23914  
23915 diff -NurpP --minimal linux-3.10.40/mm/slab_vs.h linux-3.10.40-vs2.3.6.8/mm/slab_vs.h
23916 --- linux-3.10.40/mm/slab_vs.h  1970-01-01 00:00:00.000000000 +0000
23917 +++ linux-3.10.40-vs2.3.6.8/mm/slab_vs.h        2013-08-22 20:30:00.000000000 +0000
23918 @@ -0,0 +1,29 @@
23919 +
23920 +#include <linux/vserver/context.h>
23921 +
23922 +#include <linux/vs_context.h>
23923 +
23924 +static inline
23925 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23926 +{
23927 +       int what = gfp_zone(cachep->allocflags);
23928 +       struct vx_info *vxi = current_vx_info();
23929 +
23930 +       if (!vxi)
23931 +               return;
23932 +
23933 +       atomic_add(cachep->size, &vxi->cacct.slab[what]);
23934 +}
23935 +
23936 +static inline
23937 +void vx_slab_free(struct kmem_cache *cachep)
23938 +{
23939 +       int what = gfp_zone(cachep->allocflags);
23940 +       struct vx_info *vxi = current_vx_info();
23941 +
23942 +       if (!vxi)
23943 +               return;
23944 +
23945 +       atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23946 +}
23947 +
23948 diff -NurpP --minimal linux-3.10.40/mm/swapfile.c linux-3.10.40-vs2.3.6.8/mm/swapfile.c
23949 --- linux-3.10.40/mm/swapfile.c 2013-07-14 17:01:36.000000000 +0000
23950 +++ linux-3.10.40-vs2.3.6.8/mm/swapfile.c       2013-08-22 20:30:00.000000000 +0000
23951 @@ -39,6 +39,7 @@
23952  #include <asm/tlbflush.h>
23953  #include <linux/swapops.h>
23954  #include <linux/page_cgroup.h>
23955 +#include <linux/vs_base.h>
23956  
23957  static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23958                                  unsigned char);
23959 @@ -1768,6 +1769,16 @@ static int swap_show(struct seq_file *sw
23960  
23961         if (si == SEQ_START_TOKEN) {
23962                 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23963 +               if (vx_flags(VXF_VIRT_MEM, 0)) {
23964 +                       struct sysinfo si;
23965 +
23966 +                       vx_vsi_swapinfo(&si);
23967 +                       if (si.totalswap < (1 << 10))
23968 +                               return 0;
23969 +                       seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23970 +                               "hdv0", "partition", si.totalswap >> 10,
23971 +                               (si.totalswap - si.freeswap) >> 10, -1);
23972 +               }
23973                 return 0;
23974         }
23975  
23976 @@ -2196,6 +2207,8 @@ void si_swapinfo(struct sysinfo *val)
23977         val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
23978         val->totalswap = total_swap_pages + nr_to_be_unused;
23979         spin_unlock(&swap_lock);
23980 +       if (vx_flags(VXF_VIRT_MEM, 0))
23981 +               vx_vsi_swapinfo(val);
23982  }
23983  
23984  /*
23985 diff -NurpP --minimal linux-3.10.40/net/bridge/br_multicast.c linux-3.10.40-vs2.3.6.8/net/bridge/br_multicast.c
23986 --- linux-3.10.40/net/bridge/br_multicast.c     2014-05-20 04:09:42.000000000 +0000
23987 +++ linux-3.10.40-vs2.3.6.8/net/bridge/br_multicast.c   2014-04-22 03:48:11.000000000 +0000
23988 @@ -443,7 +443,7 @@ static struct sk_buff *br_ip6_multicast_
23989         ip6h->hop_limit = 1;
23990         ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23991         if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23992 -                              &ip6h->saddr)) {
23993 +                              &ip6h->saddr, NULL)) {
23994                 kfree_skb(skb);
23995                 return NULL;
23996         }
23997 diff -NurpP --minimal linux-3.10.40/net/core/dev.c linux-3.10.40-vs2.3.6.8/net/core/dev.c
23998 --- linux-3.10.40/net/core/dev.c        2014-05-20 04:09:43.000000000 +0000
23999 +++ linux-3.10.40-vs2.3.6.8/net/core/dev.c      2014-03-12 13:18:33.000000000 +0000
24000 @@ -122,6 +122,7 @@
24001  #include <linux/in.h>
24002  #include <linux/jhash.h>
24003  #include <linux/random.h>
24004 +#include <linux/vs_inet.h>
24005  #include <trace/events/napi.h>
24006  #include <trace/events/net.h>
24007  #include <trace/events/skb.h>
24008 @@ -660,7 +661,8 @@ struct net_device *__dev_get_by_name(str
24009         struct hlist_head *head = dev_name_hash(net, name);
24010  
24011         hlist_for_each_entry(dev, head, name_hlist)
24012 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24013 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24014 +                   nx_dev_visible(current_nx_info(), dev))
24015                         return dev;
24016  
24017         return NULL;
24018 @@ -685,7 +687,8 @@ struct net_device *dev_get_by_name_rcu(s
24019         struct hlist_head *head = dev_name_hash(net, name);
24020  
24021         hlist_for_each_entry_rcu(dev, head, name_hlist)
24022 -               if (!strncmp(dev->name, name, IFNAMSIZ))
24023 +               if (!strncmp(dev->name, name, IFNAMSIZ) &&
24024 +                   nx_dev_visible(current_nx_info(), dev))
24025                         return dev;
24026  
24027         return NULL;
24028 @@ -735,7 +738,8 @@ struct net_device *__dev_get_by_index(st
24029         struct hlist_head *head = dev_index_hash(net, ifindex);
24030  
24031         hlist_for_each_entry(dev, head, index_hlist)
24032 -               if (dev->ifindex == ifindex)
24033 +               if ((dev->ifindex == ifindex) &&
24034 +                   nx_dev_visible(current_nx_info(), dev))
24035                         return dev;
24036  
24037         return NULL;
24038 @@ -753,7 +757,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24039   *     about locking. The caller must hold RCU lock.
24040   */
24041  
24042 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24043 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24044  {
24045         struct net_device *dev;
24046         struct hlist_head *head = dev_index_hash(net, ifindex);
24047 @@ -764,6 +768,16 @@ struct net_device *dev_get_by_index_rcu(
24048  
24049         return NULL;
24050  }
24051 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24052 +
24053 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24054 +{
24055 +       struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24056 +
24057 +       if (nx_dev_visible(current_nx_info(), dev))
24058 +               return dev;
24059 +       return NULL;
24060 +}
24061  EXPORT_SYMBOL(dev_get_by_index_rcu);
24062  
24063  
24064 @@ -846,7 +860,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24065  
24066         for_each_netdev_rcu(net, dev)
24067                 if (dev->type == type &&
24068 -                   !memcmp(dev->dev_addr, ha, dev->addr_len))
24069 +                   !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24070 +                   nx_dev_visible(current_nx_info(), dev))
24071                         return dev;
24072  
24073         return NULL;
24074 @@ -858,9 +873,11 @@ struct net_device *__dev_getfirstbyhwtyp
24075         struct net_device *dev;
24076  
24077         ASSERT_RTNL();
24078 -       for_each_netdev(net, dev)
24079 -               if (dev->type == type)
24080 +       for_each_netdev(net, dev) {
24081 +               if ((dev->type == type) &&
24082 +                   nx_dev_visible(current_nx_info(), dev))
24083                         return dev;
24084 +       }
24085  
24086         return NULL;
24087  }
24088 @@ -872,7 +889,8 @@ struct net_device *dev_getfirstbyhwtype(
24089  
24090         rcu_read_lock();
24091         for_each_netdev_rcu(net, dev)
24092 -               if (dev->type == type) {
24093 +               if ((dev->type == type) &&
24094 +                   nx_dev_visible(current_nx_info(), dev)) {
24095                         dev_hold(dev);
24096                         ret = dev;
24097                         break;
24098 @@ -900,7 +918,8 @@ struct net_device *dev_get_by_flags_rcu(
24099  
24100         ret = NULL;
24101         for_each_netdev_rcu(net, dev) {
24102 -               if (((dev->flags ^ if_flags) & mask) == 0) {
24103 +               if ((((dev->flags ^ if_flags) & mask) == 0) &&
24104 +                       nx_dev_visible(current_nx_info(), dev)) {
24105                         ret = dev;
24106                         break;
24107                 }
24108 @@ -978,6 +997,8 @@ static int __dev_alloc_name(struct net *
24109                                 continue;
24110                         if (i < 0 || i >= max_netdevices)
24111                                 continue;
24112 +                       if (!nx_dev_visible(current_nx_info(), d))
24113 +                               continue;
24114  
24115                         /*  avoid cases where sscanf is not exact inverse of printf */
24116                         snprintf(buf, IFNAMSIZ, name, i);
24117 diff -NurpP --minimal linux-3.10.40/net/core/net-procfs.c linux-3.10.40-vs2.3.6.8/net/core/net-procfs.c
24118 --- linux-3.10.40/net/core/net-procfs.c 2013-07-14 17:01:37.000000000 +0000
24119 +++ linux-3.10.40-vs2.3.6.8/net/core/net-procfs.c       2013-08-22 20:30:00.000000000 +0000
24120 @@ -1,6 +1,7 @@
24121  #include <linux/netdevice.h>
24122  #include <linux/proc_fs.h>
24123  #include <linux/seq_file.h>
24124 +#include <linux/vs_inet.h>
24125  #include <net/wext.h>
24126  
24127  #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
24128 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
24129  static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
24130  {
24131         struct rtnl_link_stats64 temp;
24132 -       const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24133 +       const struct rtnl_link_stats64 *stats;
24134 +
24135 +       /* device visible inside network context? */
24136 +       if (!nx_dev_visible(current_nx_info(), dev))
24137 +               return;
24138  
24139 +       stats = dev_get_stats(dev, &temp);
24140         seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24141                    "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24142                    dev->name, stats->rx_bytes, stats->rx_packets,
24143 diff -NurpP --minimal linux-3.10.40/net/core/rtnetlink.c linux-3.10.40-vs2.3.6.8/net/core/rtnetlink.c
24144 --- linux-3.10.40/net/core/rtnetlink.c  2014-05-20 04:09:43.000000000 +0000
24145 +++ linux-3.10.40-vs2.3.6.8/net/core/rtnetlink.c        2014-04-22 03:48:11.000000000 +0000
24146 @@ -1059,6 +1059,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24147                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24148                         if (idx < s_idx)
24149                                 goto cont;
24150 +                       if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24151 +                               continue;
24152                         if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24153                                              NETLINK_CB(cb->skb).portid,
24154                                              cb->nlh->nlmsg_seq, 0,
24155 @@ -1951,6 +1953,9 @@ void rtmsg_ifinfo(int type, struct net_d
24156         int err = -ENOBUFS;
24157         size_t if_info_size;
24158  
24159 +       if (!nx_dev_visible(current_nx_info(), dev))
24160 +               return;
24161 +
24162         skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24163         if (skb == NULL)
24164                 goto errout;
24165 diff -NurpP --minimal linux-3.10.40/net/core/sock.c linux-3.10.40-vs2.3.6.8/net/core/sock.c
24166 --- linux-3.10.40/net/core/sock.c       2014-05-20 04:09:43.000000000 +0000
24167 +++ linux-3.10.40-vs2.3.6.8/net/core/sock.c     2014-04-22 03:48:11.000000000 +0000
24168 @@ -132,6 +132,10 @@
24169  #include <net/netprio_cgroup.h>
24170  
24171  #include <linux/filter.h>
24172 +#include <linux/vs_socket.h>
24173 +#include <linux/vs_limit.h>
24174 +#include <linux/vs_context.h>
24175 +#include <linux/vs_network.h>
24176  
24177  #include <trace/events/sock.h>
24178  
24179 @@ -1252,6 +1256,8 @@ static struct sock *sk_prot_alloc(struct
24180                         goto out_free_sec;
24181                 sk_tx_queue_clear(sk);
24182         }
24183 +               sock_vx_init(sk);
24184 +               sock_nx_init(sk);
24185  
24186         return sk;
24187  
24188 @@ -1360,6 +1366,11 @@ static void __sk_free(struct sock *sk)
24189                 put_cred(sk->sk_peer_cred);
24190         put_pid(sk->sk_peer_pid);
24191         put_net(sock_net(sk));
24192 +       vx_sock_dec(sk);
24193 +       clr_vx_info(&sk->sk_vx_info);
24194 +       sk->sk_xid = -1;
24195 +       clr_nx_info(&sk->sk_nx_info);
24196 +       sk->sk_nid = -1;
24197         sk_prot_free(sk->sk_prot_creator, sk);
24198  }
24199  
24200 @@ -1420,6 +1431,8 @@ struct sock *sk_clone_lock(const struct
24201  
24202                 /* SANITY */
24203                 get_net(sock_net(newsk));
24204 +               sock_vx_init(newsk);
24205 +               sock_nx_init(newsk);
24206                 sk_node_init(&newsk->sk_node);
24207                 sock_lock_init(newsk);
24208                 bh_lock_sock(newsk);
24209 @@ -1476,6 +1489,12 @@ struct sock *sk_clone_lock(const struct
24210                 smp_wmb();
24211                 atomic_set(&newsk->sk_refcnt, 2);
24212  
24213 +               set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24214 +               newsk->sk_xid = sk->sk_xid;
24215 +               vx_sock_inc(newsk);
24216 +               set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24217 +               newsk->sk_nid = sk->sk_nid;
24218 +
24219                 /*
24220                  * Increment the counter in the same struct proto as the master
24221                  * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24222 @@ -2271,6 +2290,12 @@ void sock_init_data(struct socket *sock,
24223  
24224         sk->sk_stamp = ktime_set(-1L, 0);
24225  
24226 +       set_vx_info(&sk->sk_vx_info, current_vx_info());
24227 +       sk->sk_xid = vx_current_xid();
24228 +       vx_sock_inc(sk);
24229 +       set_nx_info(&sk->sk_nx_info, current_nx_info());
24230 +       sk->sk_nid = nx_current_nid();
24231 +
24232         sk->sk_pacing_rate = ~0U;
24233         /*
24234          * Before updating sk_refcnt, we must commit prior changes to memory
24235 diff -NurpP --minimal linux-3.10.40/net/ipv4/af_inet.c linux-3.10.40-vs2.3.6.8/net/ipv4/af_inet.c
24236 --- linux-3.10.40/net/ipv4/af_inet.c    2014-05-20 04:09:43.000000000 +0000
24237 +++ linux-3.10.40-vs2.3.6.8/net/ipv4/af_inet.c  2013-11-13 17:17:16.000000000 +0000
24238 @@ -118,6 +118,7 @@
24239  #ifdef CONFIG_IP_MROUTE
24240  #include <linux/mroute.h>
24241  #endif
24242 +#include <linux/vs_limit.h>
24243  
24244  
24245  /* The inetsw table contains everything that inet_create needs to
24246 @@ -336,10 +337,13 @@ lookup_protocol:
24247         }
24248  
24249         err = -EPERM;
24250 +       if ((protocol == IPPROTO_ICMP) &&
24251 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24252 +               goto override;
24253         if (sock->type == SOCK_RAW && !kern &&
24254             !ns_capable(net->user_ns, CAP_NET_RAW))
24255                 goto out_rcu_unlock;
24256 -
24257 +override:
24258         sock->ops = answer->ops;
24259         answer_prot = answer->prot;
24260         answer_no_check = answer->no_check;
24261 @@ -460,6 +464,7 @@ int inet_bind(struct socket *sock, struc
24262         struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24263         struct sock *sk = sock->sk;
24264         struct inet_sock *inet = inet_sk(sk);
24265 +       struct nx_v4_sock_addr nsa;
24266         struct net *net = sock_net(sk);
24267         unsigned short snum;
24268         int chk_addr_ret;
24269 @@ -484,7 +489,11 @@ int inet_bind(struct socket *sock, struc
24270                         goto out;
24271         }
24272  
24273 -       chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
24274 +       err = v4_map_sock_addr(inet, addr, &nsa);
24275 +       if (err)
24276 +               goto out;
24277 +
24278 +       chk_addr_ret = inet_addr_type(net, nsa.saddr);
24279  
24280         /* Not specified by any standard per-se, however it breaks too
24281          * many applications when removed.  It is unfortunate since
24282 @@ -496,7 +505,7 @@ int inet_bind(struct socket *sock, struc
24283         err = -EADDRNOTAVAIL;
24284         if (!sysctl_ip_nonlocal_bind &&
24285             !(inet->freebind || inet->transparent) &&
24286 -           addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24287 +           nsa.saddr != htonl(INADDR_ANY) &&
24288             chk_addr_ret != RTN_LOCAL &&
24289             chk_addr_ret != RTN_MULTICAST &&
24290             chk_addr_ret != RTN_BROADCAST)
24291 @@ -522,7 +531,7 @@ int inet_bind(struct socket *sock, struc
24292         if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24293                 goto out_release_sock;
24294  
24295 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24296 +       v4_set_sock_addr(inet, &nsa);
24297         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24298                 inet->inet_saddr = 0;  /* Use device */
24299  
24300 @@ -741,11 +750,13 @@ int inet_getname(struct socket *sock, st
24301                      peer == 1))
24302                         return -ENOTCONN;
24303                 sin->sin_port = inet->inet_dport;
24304 -               sin->sin_addr.s_addr = inet->inet_daddr;
24305 +               sin->sin_addr.s_addr =
24306 +                       nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24307         } else {
24308                 __be32 addr = inet->inet_rcv_saddr;
24309                 if (!addr)
24310                         addr = inet->inet_saddr;
24311 +               addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24312                 sin->sin_port = inet->inet_sport;
24313                 sin->sin_addr.s_addr = addr;
24314         }
24315 diff -NurpP --minimal linux-3.10.40/net/ipv4/arp.c linux-3.10.40-vs2.3.6.8/net/ipv4/arp.c
24316 --- linux-3.10.40/net/ipv4/arp.c        2013-07-14 17:01:37.000000000 +0000
24317 +++ linux-3.10.40-vs2.3.6.8/net/ipv4/arp.c      2013-08-22 20:30:00.000000000 +0000
24318 @@ -1332,6 +1332,7 @@ static void arp_format_neigh_entry(struc
24319         struct net_device *dev = n->dev;
24320         int hatype = dev->type;
24321  
24322 +       /* FIXME: check for network context */
24323         read_lock(&n->lock);
24324         /* Convert hardware address to XX:XX:XX:XX ... form. */
24325  #if IS_ENABLED(CONFIG_AX25)
24326 @@ -1363,6 +1364,7 @@ static void arp_format_pneigh_entry(stru
24327         int hatype = dev ? dev->type : 0;
24328         char tbuf[16];
24329  
24330 +       /* FIXME: check for network context */
24331         sprintf(tbuf, "%pI4", n->key);
24332         seq_printf(seq, "%-16s 0x%-10x0x%-10x%s     *        %s\n",
24333                    tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24334 diff -NurpP --minimal linux-3.10.40/net/ipv4/devinet.c linux-3.10.40-vs2.3.6.8/net/ipv4/devinet.c
24335 --- linux-3.10.40/net/ipv4/devinet.c    2014-05-20 04:09:43.000000000 +0000
24336 +++ linux-3.10.40-vs2.3.6.8/net/ipv4/devinet.c  2014-03-12 13:18:33.000000000 +0000
24337 @@ -522,6 +522,7 @@ struct in_device *inetdev_by_index(struc
24338  }
24339  EXPORT_SYMBOL(inetdev_by_index);
24340  
24341 +
24342  /* Called only from RTNL semaphored context. No locks. */
24343  
24344  struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24345 @@ -942,6 +943,8 @@ int devinet_ioctl(struct net *net, unsig
24346  
24347         in_dev = __in_dev_get_rtnl(dev);
24348         if (in_dev) {
24349 +               struct nx_info *nxi = current_nx_info();
24350 +
24351                 if (tryaddrmatch) {
24352                         /* Matthias Andree */
24353                         /* compare label and address (4.4BSD style) */
24354 @@ -950,6 +953,8 @@ int devinet_ioctl(struct net *net, unsig
24355                            This is checked above. */
24356                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24357                              ifap = &ifa->ifa_next) {
24358 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24359 +                                       continue;
24360                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24361                                     sin_orig.sin_addr.s_addr ==
24362                                                         ifa->ifa_local) {
24363 @@ -962,9 +967,12 @@ int devinet_ioctl(struct net *net, unsig
24364                    comparing just the label */
24365                 if (!ifa) {
24366                         for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24367 -                            ifap = &ifa->ifa_next)
24368 +                            ifap = &ifa->ifa_next) {
24369 +                               if (!nx_v4_ifa_visible(nxi, ifa))
24370 +                                       continue;
24371                                 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24372                                         break;
24373 +                       }
24374                 }
24375         }
24376  
24377 @@ -1118,6 +1126,8 @@ static int inet_gifconf(struct net_devic
24378                 goto out;
24379  
24380         for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24381 +               if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24382 +                       continue;
24383                 if (!buf) {
24384                         done += sizeof(ifr);
24385                         continue;
24386 @@ -1522,6 +1532,7 @@ static int inet_dump_ifaddr(struct sk_bu
24387         struct net_device *dev;
24388         struct in_device *in_dev;
24389         struct in_ifaddr *ifa;
24390 +       struct sock *sk = skb->sk;
24391         struct hlist_head *head;
24392  
24393         s_h = cb->args[0];
24394 @@ -1545,6 +1556,8 @@ static int inet_dump_ifaddr(struct sk_bu
24395  
24396                         for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24397                              ifa = ifa->ifa_next, ip_idx++) {
24398 +                       if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24399 +                               continue;
24400                                 if (ip_idx < s_ip_idx)
24401                                         continue;
24402                                 if (inet_fill_ifaddr(skb, ifa,
24403 diff -NurpP --minimal linux-3.10.40/net/ipv4/fib_trie.c linux-3.10.40-vs2.3.6.8/net/ipv4/fib_trie.c
24404 --- linux-3.10.40/net/ipv4/fib_trie.c   2014-05-20 04:09:43.000000000 +0000
24405 +++ linux-3.10.40-vs2.3.6.8/net/ipv4/fib_trie.c 2013-11-13 17:17:16.000000000 +0000
24406 @@ -2536,6 +2536,7 @@ static int fib_route_seq_show(struct seq
24407                             || fa->fa_type == RTN_MULTICAST)
24408                                 continue;
24409  
24410 +                       /* FIXME: check for network context? */
24411                         if (fi)
24412                                 seq_printf(seq,
24413                                          "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24414 diff -NurpP --minimal linux-3.10.40/net/ipv4/inet_connection_sock.c linux-3.10.40-vs2.3.6.8/net/ipv4/inet_connection_sock.c
24415 --- linux-3.10.40/net/ipv4/inet_connection_sock.c       2013-07-14 17:01:37.000000000 +0000
24416 +++ linux-3.10.40-vs2.3.6.8/net/ipv4/inet_connection_sock.c     2013-08-22 20:30:00.000000000 +0000
24417 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24418  }
24419  EXPORT_SYMBOL(inet_get_local_port_range);
24420  
24421 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24422 +{
24423 +       __be32  sk1_rcv_saddr = sk_rcv_saddr(sk1),
24424 +               sk2_rcv_saddr = sk_rcv_saddr(sk2);
24425 +
24426 +       if (inet_v6_ipv6only(sk2))
24427 +               return 0;
24428 +
24429 +       if (sk1_rcv_saddr &&
24430 +           sk2_rcv_saddr &&
24431 +           sk1_rcv_saddr == sk2_rcv_saddr)
24432 +               return 1;
24433 +
24434 +       if (sk1_rcv_saddr &&
24435 +           !sk2_rcv_saddr &&
24436 +           v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24437 +               return 1;
24438 +
24439 +       if (sk2_rcv_saddr &&
24440 +           !sk1_rcv_saddr &&
24441 +           v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24442 +               return 1;
24443 +
24444 +       if (!sk1_rcv_saddr &&
24445 +           !sk2_rcv_saddr &&
24446 +           nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24447 +               return 1;
24448 +
24449 +       return 0;
24450 +}
24451 +
24452  int inet_csk_bind_conflict(const struct sock *sk,
24453                            const struct inet_bind_bucket *tb, bool relax)
24454  {
24455 @@ -79,17 +110,12 @@ int inet_csk_bind_conflict(const struct
24456                             (!reuseport || !sk2->sk_reuseport ||
24457                             (sk2->sk_state != TCP_TIME_WAIT &&
24458                              !uid_eq(uid, sock_i_uid(sk2))))) {
24459 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24460 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24461 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24462 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24463                                         break;
24464                         }
24465                         if (!relax && reuse && sk2->sk_reuse &&
24466                             sk2->sk_state != TCP_LISTEN) {
24467 -                               const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24468 -
24469 -                               if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24470 -                                   sk2_rcv_saddr == sk_rcv_saddr(sk))
24471 +                               if (ipv4_rcv_saddr_equal(sk, sk2))
24472                                         break;
24473                         }
24474                 }
24475 diff -NurpP --minimal linux-3.10.40/net/ipv4/inet_diag.c linux-3.10.40-vs2.3.6.8/net/ipv4/inet_diag.c
24476 --- linux-3.10.40/net/ipv4/inet_diag.c  2014-05-20 04:09:43.000000000 +0000
24477 +++ linux-3.10.40-vs2.3.6.8/net/ipv4/inet_diag.c        2014-03-12 13:18:23.000000000 +0000
24478 @@ -31,6 +31,8 @@
24479  
24480  #include <linux/inet.h>
24481  #include <linux/stddef.h>
24482 +#include <linux/vs_network.h>
24483 +#include <linux/vs_inet.h>
24484  
24485  #include <linux/inet_diag.h>
24486  #include <linux/sock_diag.h>
24487 @@ -110,8 +112,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24488         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
24489         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
24490  
24491 -       r->id.idiag_src[0] = inet->inet_rcv_saddr;
24492 -       r->id.idiag_dst[0] = inet->inet_daddr;
24493 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24494 +               inet->inet_rcv_saddr);
24495 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24496 +               inet->inet_daddr);
24497  
24498         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
24499                 goto errout;
24500 @@ -254,8 +258,8 @@ static int inet_twsk_diag_fill(struct in
24501         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
24502         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
24503  
24504 -       r->id.idiag_src[0]    = tw->tw_rcv_saddr;
24505 -       r->id.idiag_dst[0]    = tw->tw_daddr;
24506 +       r->id.idiag_src[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24507 +       r->id.idiag_dst[0]    = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24508  
24509         r->idiag_state        = tw->tw_substate;
24510         r->idiag_timer        = 3;
24511 @@ -300,12 +304,14 @@ int inet_diag_dump_one_icsk(struct inet_
24512  
24513         err = -EINVAL;
24514         if (req->sdiag_family == AF_INET) {
24515 +               /* TODO: lback */
24516                 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24517                                  req->id.idiag_dport, req->id.idiag_src[0],
24518                                  req->id.idiag_sport, req->id.idiag_if);
24519         }
24520  #if IS_ENABLED(CONFIG_IPV6)
24521         else if (req->sdiag_family == AF_INET6) {
24522 +               /* TODO: lback */
24523                 sk = inet6_lookup(net, hashinfo,
24524                                   (struct in6_addr *)req->id.idiag_dst,
24525                                   req->id.idiag_dport,
24526 @@ -507,6 +513,7 @@ int inet_diag_bc_sk(const struct nlattr
24527         } else
24528  #endif
24529         {
24530 +                       /* TODO: lback */
24531                 entry.saddr = &inet->inet_rcv_saddr;
24532                 entry.daddr = &inet->inet_daddr;
24533         }
24534 @@ -665,6 +672,7 @@ static int inet_twsk_diag_dump(struct in
24535                 } else
24536  #endif
24537                 {
24538 +                       /* TODO: lback */
24539                         entry.saddr = &tw->tw_rcv_saddr;
24540                         entry.daddr = &tw->tw_daddr;
24541                 }
24542 @@ -747,8 +755,8 @@ static int inet_diag_fill_req(struct sk_
24543         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
24544         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
24545  
24546 -       r->id.idiag_src[0] = ireq->loc_addr;
24547 -       r->id.idiag_dst[0] = ireq->rmt_addr;
24548 +       r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24549 +       r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24550  
24551         r->idiag_expires = jiffies_to_msecs(tmo);
24552         r->idiag_rqueue = 0;
24553 @@ -812,6 +820,7 @@ static int inet_diag_dump_reqs(struct sk
24554                             r->id.idiag_dport)
24555                                 continue;
24556  
24557 +                       /* TODO: lback */
24558                         if (bc) {
24559                                 inet_diag_req_addrs(sk, req, &entry);
24560                                 entry.dport = ntohs(ireq->rmt_port);
24561 @@ -868,6 +877,8 @@ void inet_diag_dump_icsk(struct inet_has
24562                                 if (!net_eq(sock_net(sk), net))
24563                                         continue;
24564  
24565 +                               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24566 +                                       continue;
24567                                 if (num < s_num) {
24568                                         num++;
24569                                         continue;
24570 @@ -940,6 +951,8 @@ skip_listen_ht:
24571  
24572                         if (!net_eq(sock_net(sk), net))
24573                                 continue;
24574 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24575 +                               continue;
24576                         if (num < s_num)
24577                                 goto next_normal;
24578                         if (!(r->idiag_states & (1 << sk->sk_state)))
24579 @@ -968,7 +981,8 @@ next_normal:
24580                                     &head->twchain) {
24581                                 if (!net_eq(twsk_net(tw), net))
24582                                         continue;
24583 -
24584 +                               if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24585 +                                       continue;
24586                                 if (num < s_num)
24587                                         goto next_dying;
24588                                 if (!(r->idiag_states & (1 << tw->tw_substate)))
24589 diff -NurpP --minimal linux-3.10.40/net/ipv4/inet_hashtables.c linux-3.10.40-vs2.3.6.8/net/ipv4/inet_hashtables.c
24590 --- linux-3.10.40/net/ipv4/inet_hashtables.c    2014-05-20 04:09:43.000000000 +0000
24591 +++ linux-3.10.40-vs2.3.6.8/net/ipv4/inet_hashtables.c  2013-11-13 17:22:25.000000000 +0000
24592 @@ -22,6 +22,7 @@
24593  #include <net/inet_connection_sock.h>
24594  #include <net/inet_hashtables.h>
24595  #include <net/secure_seq.h>
24596 +#include <net/route.h>
24597  #include <net/ip.h>
24598  
24599  /*
24600 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24601                         if (rcv_saddr != daddr)
24602                                 return -1;
24603                         score += 4;
24604 +               } else {
24605 +                       /* block non nx_info ips */
24606 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24607 +                               daddr, NXA_MASK_BIND))
24608 +                               return -1;
24609                 }
24610                 if (sk->sk_bound_dev_if) {
24611                         if (sk->sk_bound_dev_if != dif)
24612 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24613   * wildcarded during the search since they can never be otherwise.
24614   */
24615  
24616 -
24617  struct sock *__inet_lookup_listener(struct net *net,
24618                                     struct inet_hashinfo *hashinfo,
24619                                     const __be32 saddr, __be16 sport,
24620 @@ -209,6 +214,7 @@ begin:
24621                         phash = next_pseudo_random32(phash);
24622                 }
24623         }
24624 +
24625         /*
24626          * if the nulls value we got at the end of this lookup is
24627          * not the expected one, we must restart lookup.
24628 diff -NurpP --minimal linux-3.10.40/net/ipv4/netfilter.c linux-3.10.40-vs2.3.6.8/net/ipv4/netfilter.c
24629 --- linux-3.10.40/net/ipv4/netfilter.c  2013-07-14 17:01:37.000000000 +0000
24630 +++ linux-3.10.40-vs2.3.6.8/net/ipv4/netfilter.c        2013-08-22 20:30:00.000000000 +0000
24631 @@ -11,7 +11,7 @@
24632  #include <linux/skbuff.h>
24633  #include <linux/gfp.h>
24634  #include <linux/export.h>
24635 -#include <net/route.h>
24636 +// #include <net/route.h>
24637  #include <net/xfrm.h>
24638  #include <net/ip.h>
24639  #include <net/netfilter/nf_queue.h>
24640 diff -NurpP --minimal linux-3.10.40/net/ipv4/raw.c linux-3.10.40-vs2.3.6.8/net/ipv4/raw.c
24641 --- linux-3.10.40/net/ipv4/raw.c        2014-05-20 04:09:43.000000000 +0000
24642 +++ linux-3.10.40-vs2.3.6.8/net/ipv4/raw.c      2013-12-23 17:42:40.000000000 +0000
24643 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
24644  
24645                 if (net_eq(sock_net(sk), net) && inet->inet_num == num  &&
24646                     !(inet->inet_daddr && inet->inet_daddr != raddr)    &&
24647 -                   !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24648 +                   v4_sock_addr_match(sk->sk_nx_info, inet, laddr)     &&
24649                     !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24650                         goto found; /* gotcha */
24651         }
24652 @@ -395,6 +395,12 @@ static int raw_send_hdrinc(struct sock *
24653                 icmp_out_count(net, ((struct icmphdr *)
24654                         skb_transport_header(skb))->type);
24655  
24656 +       err = -EPERM;
24657 +       if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24658 +               sk->sk_nx_info &&
24659 +               !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24660 +               goto error_free;
24661 +
24662         err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24663                       rt->dst.dev, dst_output);
24664         if (err > 0)
24665 @@ -581,6 +587,16 @@ static int raw_sendmsg(struct kiocb *ioc
24666                         goto done;
24667         }
24668  
24669 +       if (sk->sk_nx_info) {
24670 +               rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24671 +               if (IS_ERR(rt)) {
24672 +                       err = PTR_ERR(rt);
24673 +                       rt = NULL;
24674 +                       goto done;
24675 +               }
24676 +               ip_rt_put(rt);
24677 +       }
24678 +
24679         security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24680         rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24681         if (IS_ERR(rt)) {
24682 @@ -657,17 +673,19 @@ static int raw_bind(struct sock *sk, str
24683  {
24684         struct inet_sock *inet = inet_sk(sk);
24685         struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24686 +       struct nx_v4_sock_addr nsa = { 0 };
24687         int ret = -EINVAL;
24688         int chk_addr_ret;
24689  
24690         if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24691                 goto out;
24692 -       chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24693 +       v4_map_sock_addr(inet, addr, &nsa);
24694 +       chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24695         ret = -EADDRNOTAVAIL;
24696 -       if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24697 +       if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24698             chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24699                 goto out;
24700 -       inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24701 +       v4_set_sock_addr(inet, &nsa);
24702         if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24703                 inet->inet_saddr = 0;  /* Use device */
24704         sk_dst_reset(sk);
24705 @@ -716,7 +734,8 @@ static int raw_recvmsg(struct kiocb *ioc
24706         /* Copy the address. */
24707         if (sin) {
24708                 sin->sin_family = AF_INET;
24709 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24710 +               sin->sin_addr.s_addr =
24711 +                       nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24712                 sin->sin_port = 0;
24713                 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24714                 *addr_len = sizeof(*sin);
24715 @@ -912,7 +931,8 @@ static struct sock *raw_get_first(struct
24716         for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24717                         ++state->bucket) {
24718                 sk_for_each(sk, &state->h->ht[state->bucket])
24719 -                       if (sock_net(sk) == seq_file_net(seq))
24720 +                       if ((sock_net(sk) == seq_file_net(seq)) &&
24721 +                           nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24722                                 goto found;
24723         }
24724         sk = NULL;
24725 @@ -928,7 +948,8 @@ static struct sock *raw_get_next(struct
24726                 sk = sk_next(sk);
24727  try_again:
24728                 ;
24729 -       } while (sk && sock_net(sk) != seq_file_net(seq));
24730 +       } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24731 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24732  
24733         if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24734                 sk = sk_head(&state->h->ht[state->bucket]);
24735 diff -NurpP --minimal linux-3.10.40/net/ipv4/route.c linux-3.10.40-vs2.3.6.8/net/ipv4/route.c
24736 --- linux-3.10.40/net/ipv4/route.c      2014-05-20 04:09:43.000000000 +0000
24737 +++ linux-3.10.40-vs2.3.6.8/net/ipv4/route.c    2014-03-12 13:18:33.000000000 +0000
24738 @@ -2007,7 +2007,7 @@ struct rtable *__ip_route_output_key(str
24739  
24740  
24741         if (fl4->flowi4_oif) {
24742 -               dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24743 +               dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24744                 rth = ERR_PTR(-ENODEV);
24745                 if (dev_out == NULL)
24746                         goto out;
24747 diff -NurpP --minimal linux-3.10.40/net/ipv4/tcp.c linux-3.10.40-vs2.3.6.8/net/ipv4/tcp.c
24748 --- linux-3.10.40/net/ipv4/tcp.c        2014-05-20 04:09:43.000000000 +0000
24749 +++ linux-3.10.40-vs2.3.6.8/net/ipv4/tcp.c      2014-04-22 03:48:11.000000000 +0000
24750 @@ -268,6 +268,7 @@
24751  #include <linux/crypto.h>
24752  #include <linux/time.h>
24753  #include <linux/slab.h>
24754 +#include <linux/in.h>
24755  
24756  #include <net/icmp.h>
24757  #include <net/inet_common.h>
24758 diff -NurpP --minimal linux-3.10.40/net/ipv4/tcp_ipv4.c linux-3.10.40-vs2.3.6.8/net/ipv4/tcp_ipv4.c
24759 --- linux-3.10.40/net/ipv4/tcp_ipv4.c   2014-05-20 04:09:43.000000000 +0000
24760 +++ linux-3.10.40-vs2.3.6.8/net/ipv4/tcp_ipv4.c 2013-12-23 17:42:40.000000000 +0000
24761 @@ -2263,6 +2263,12 @@ static void *listening_get_next(struct s
24762                 req = req->dl_next;
24763                 while (1) {
24764                         while (req) {
24765 +                               vxdprintk(VXD_CBIT(net, 6),
24766 +                                       "sk,req: %p [#%d] (from %d)", req->sk,
24767 +                                       (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24768 +                               if (req->sk &&
24769 +                                       !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24770 +                                       continue;
24771                                 if (req->rsk_ops->family == st->family) {
24772                                         cur = req;
24773                                         goto out;
24774 @@ -2287,6 +2293,10 @@ get_req:
24775         }
24776  get_sk:
24777         sk_nulls_for_each_from(sk, node) {
24778 +               vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24779 +                       sk, sk->sk_nid, nx_current_nid());
24780 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24781 +                       continue;
24782                 if (!net_eq(sock_net(sk), net))
24783                         continue;
24784                 if (sk->sk_family == st->family) {
24785 @@ -2363,6 +2373,11 @@ static void *established_get_first(struc
24786  
24787                 spin_lock_bh(lock);
24788                 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24789 +                       vxdprintk(VXD_CBIT(net, 6),
24790 +                               "sk,egf: %p [#%d] (from %d)",
24791 +                               sk, sk->sk_nid, nx_current_nid());
24792 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24793 +                               continue;
24794                         if (sk->sk_family != st->family ||
24795                             !net_eq(sock_net(sk), net)) {
24796                                 continue;
24797 @@ -2373,6 +2388,11 @@ static void *established_get_first(struc
24798                 st->state = TCP_SEQ_STATE_TIME_WAIT;
24799                 inet_twsk_for_each(tw, node,
24800                                    &tcp_hashinfo.ehash[st->bucket].twchain) {
24801 +                       vxdprintk(VXD_CBIT(net, 6),
24802 +                               "tw: %p [#%d] (from %d)",
24803 +                               tw, tw->tw_nid, nx_current_nid());
24804 +                       if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24805 +                               continue;
24806                         if (tw->tw_family != st->family ||
24807                             !net_eq(twsk_net(tw), net)) {
24808                                 continue;
24809 @@ -2402,7 +2422,9 @@ static void *established_get_next(struct
24810                 tw = cur;
24811                 tw = tw_next(tw);
24812  get_tw:
24813 -               while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24814 +               while (tw && (tw->tw_family != st->family ||
24815 +                       !net_eq(twsk_net(tw), net) ||
24816 +                       !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24817                         tw = tw_next(tw);
24818                 }
24819                 if (tw) {
24820 @@ -2426,6 +2448,11 @@ get_tw:
24821                 sk = sk_nulls_next(sk);
24822  
24823         sk_nulls_for_each_from(sk, node) {
24824 +               vxdprintk(VXD_CBIT(net, 6),
24825 +                       "sk,egn: %p [#%d] (from %d)",
24826 +                       sk, sk->sk_nid, nx_current_nid());
24827 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24828 +                       continue;
24829                 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24830                         goto found;
24831         }
24832 @@ -2631,9 +2658,9 @@ static void get_openreq4(const struct so
24833         seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24834                 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24835                 i,
24836 -               ireq->loc_addr,
24837 +               nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24838                 ntohs(inet_sk(sk)->inet_sport),
24839 -               ireq->rmt_addr,
24840 +               nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24841                 ntohs(ireq->rmt_port),
24842                 TCP_SYN_RECV,
24843                 0, 0, /* could print option size, but that is af dependent. */
24844 @@ -2656,8 +2683,8 @@ static void get_tcp4_sock(struct sock *s
24845         const struct inet_connection_sock *icsk = inet_csk(sk);
24846         const struct inet_sock *inet = inet_sk(sk);
24847         struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24848 -       __be32 dest = inet->inet_daddr;
24849 -       __be32 src = inet->inet_rcv_saddr;
24850 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24851 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24852         __u16 destp = ntohs(inet->inet_dport);
24853         __u16 srcp = ntohs(inet->inet_sport);
24854         int rx_queue;
24855 @@ -2715,8 +2742,8 @@ static void get_timewait4_sock(const str
24856         __u16 destp, srcp;
24857         long delta = tw->tw_ttd - jiffies;
24858  
24859 -       dest  = tw->tw_daddr;
24860 -       src   = tw->tw_rcv_saddr;
24861 +       dest  = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24862 +       src   = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24863         destp = ntohs(tw->tw_dport);
24864         srcp  = ntohs(tw->tw_sport);
24865  
24866 diff -NurpP --minimal linux-3.10.40/net/ipv4/tcp_minisocks.c linux-3.10.40-vs2.3.6.8/net/ipv4/tcp_minisocks.c
24867 --- linux-3.10.40/net/ipv4/tcp_minisocks.c      2013-07-14 17:01:37.000000000 +0000
24868 +++ linux-3.10.40-vs2.3.6.8/net/ipv4/tcp_minisocks.c    2013-08-22 20:30:00.000000000 +0000
24869 @@ -23,6 +23,9 @@
24870  #include <linux/slab.h>
24871  #include <linux/sysctl.h>
24872  #include <linux/workqueue.h>
24873 +#include <linux/vs_limit.h>
24874 +#include <linux/vs_socket.h>
24875 +#include <linux/vs_context.h>
24876  #include <net/tcp.h>
24877  #include <net/inet_common.h>
24878  #include <net/xfrm.h>
24879 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int
24880                 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24881                 tcptw->tw_ts_offset     = tp->tsoffset;
24882  
24883 +               tw->tw_xid              = sk->sk_xid;
24884 +               tw->tw_vx_info          = NULL;
24885 +               tw->tw_nid              = sk->sk_nid;
24886 +               tw->tw_nx_info          = NULL;
24887 +
24888  #if IS_ENABLED(CONFIG_IPV6)
24889                 if (tw->tw_family == PF_INET6) {
24890                         struct ipv6_pinfo *np = inet6_sk(sk);
24891 diff -NurpP --minimal linux-3.10.40/net/ipv4/udp.c linux-3.10.40-vs2.3.6.8/net/ipv4/udp.c
24892 --- linux-3.10.40/net/ipv4/udp.c        2014-05-20 04:09:43.000000000 +0000
24893 +++ linux-3.10.40-vs2.3.6.8/net/ipv4/udp.c      2013-12-23 17:42:40.000000000 +0000
24894 @@ -306,14 +306,7 @@ fail:
24895  }
24896  EXPORT_SYMBOL(udp_lib_get_port);
24897  
24898 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24899 -{
24900 -       struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24901 -
24902 -       return  (!ipv6_only_sock(sk2)  &&
24903 -                (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24904 -                  inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24905 -}
24906 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24907  
24908  static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24909                                        unsigned int port)
24910 @@ -348,6 +341,11 @@ static inline int compute_score(struct s
24911                         if (inet->inet_rcv_saddr != daddr)
24912                                 return -1;
24913                         score += 4;
24914 +               } else {
24915 +                       /* block non nx_info ips */
24916 +                       if (!v4_addr_in_nx_info(sk->sk_nx_info,
24917 +                               daddr, NXA_MASK_BIND))
24918 +                               return -1;
24919                 }
24920                 if (inet->inet_daddr) {
24921                         if (inet->inet_daddr != saddr)
24922 @@ -458,6 +456,7 @@ begin:
24923         return result;
24924  }
24925  
24926 +
24927  /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24928   * harder than this. -DaveM
24929   */
24930 @@ -504,6 +503,11 @@ begin:
24931         sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24932                 score = compute_score(sk, net, saddr, hnum, sport,
24933                                       daddr, dport, dif);
24934 +               /* FIXME: disabled?
24935 +               if (score == 9) {
24936 +                       result = sk;
24937 +                       break;
24938 +               } else */
24939                 if (score > badness) {
24940                         result = sk;
24941                         badness = score;
24942 @@ -528,6 +532,7 @@ begin:
24943         if (get_nulls_value(node) != slot)
24944                 goto begin;
24945  
24946 +
24947         if (result) {
24948                 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24949                         result = NULL;
24950 @@ -537,6 +542,7 @@ begin:
24951                         goto begin;
24952                 }
24953         }
24954 +
24955         rcu_read_unlock();
24956         return result;
24957  }
24958 @@ -580,8 +586,7 @@ static inline struct sock *udp_v4_mcast_
24959                     udp_sk(s)->udp_port_hash != hnum ||
24960                     (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24961                     (inet->inet_dport != rmt_port && inet->inet_dport) ||
24962 -                   (inet->inet_rcv_saddr &&
24963 -                    inet->inet_rcv_saddr != loc_addr) ||
24964 +                   !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24965                     ipv6_only_sock(s) ||
24966                     (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
24967                         continue;
24968 @@ -965,6 +970,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24969                                    inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24970                                    faddr, saddr, dport, inet->inet_sport);
24971  
24972 +               if (sk->sk_nx_info) {
24973 +                       rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24974 +                       if (IS_ERR(rt)) {
24975 +                               err = PTR_ERR(rt);
24976 +                               rt = NULL;
24977 +                               goto out;
24978 +                       }
24979 +                       ip_rt_put(rt);
24980 +               }
24981 +
24982                 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24983                 rt = ip_route_output_flow(net, fl4, sk);
24984                 if (IS_ERR(rt)) {
24985 @@ -1269,7 +1284,8 @@ try_again:
24986         if (sin) {
24987                 sin->sin_family = AF_INET;
24988                 sin->sin_port = udp_hdr(skb)->source;
24989 -               sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24990 +               sin->sin_addr.s_addr = nx_map_sock_lback(
24991 +                       skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24992                 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24993                 *addr_len = sizeof(*sin);
24994         }
24995 @@ -2031,6 +2047,8 @@ static struct sock *udp_get_first(struct
24996                 sk_nulls_for_each(sk, node, &hslot->head) {
24997                         if (!net_eq(sock_net(sk), net))
24998                                 continue;
24999 +                       if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25000 +                               continue;
25001                         if (sk->sk_family == state->family)
25002                                 goto found;
25003                 }
25004 @@ -2048,7 +2066,9 @@ static struct sock *udp_get_next(struct
25005  
25006         do {
25007                 sk = sk_nulls_next(sk);
25008 -       } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25009 +       } while (sk && (!net_eq(sock_net(sk), net) ||
25010 +               sk->sk_family != state->family ||
25011 +               !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25012  
25013         if (!sk) {
25014                 if (state->bucket <= state->udp_table->mask)
25015 @@ -2144,8 +2164,8 @@ static void udp4_format_sock(struct sock
25016                 int bucket, int *len)
25017  {
25018         struct inet_sock *inet = inet_sk(sp);
25019 -       __be32 dest = inet->inet_daddr;
25020 -       __be32 src  = inet->inet_rcv_saddr;
25021 +       __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25022 +       __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25023         __u16 destp       = ntohs(inet->inet_dport);
25024         __u16 srcp        = ntohs(inet->inet_sport);
25025  
25026 diff -NurpP --minimal linux-3.10.40/net/ipv6/Kconfig linux-3.10.40-vs2.3.6.8/net/ipv6/Kconfig
25027 --- linux-3.10.40/net/ipv6/Kconfig      2013-07-14 17:01:38.000000000 +0000
25028 +++ linux-3.10.40-vs2.3.6.8/net/ipv6/Kconfig    2013-08-22 20:30:00.000000000 +0000
25029 @@ -4,8 +4,8 @@
25030  
25031  #   IPv6 as module will cause a CRASH if you try to unload it
25032  menuconfig IPV6
25033 -       tristate "The IPv6 protocol"
25034 -       default m
25035 +       bool "The IPv6 protocol"
25036 +       default n
25037         ---help---
25038           This is complemental support for the IP version 6.
25039           You will still be able to do traditional IPv4 networking as well.
25040 diff -NurpP --minimal linux-3.10.40/net/ipv6/addrconf.c linux-3.10.40-vs2.3.6.8/net/ipv6/addrconf.c
25041 --- linux-3.10.40/net/ipv6/addrconf.c   2014-05-20 04:09:43.000000000 +0000
25042 +++ linux-3.10.40-vs2.3.6.8/net/ipv6/addrconf.c 2014-04-22 03:48:11.000000000 +0000
25043 @@ -94,6 +94,8 @@
25044  #include <linux/proc_fs.h>
25045  #include <linux/seq_file.h>
25046  #include <linux/export.h>
25047 +#include <linux/vs_network.h>
25048 +#include <linux/vs_inet6.h>
25049  
25050  /* Set to 3 to get tracing... */
25051  #define ACONF_DEBUG 2
25052 @@ -1324,7 +1326,7 @@ out:
25053  
25054  int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
25055                        const struct in6_addr *daddr, unsigned int prefs,
25056 -                      struct in6_addr *saddr)
25057 +                      struct in6_addr *saddr, struct nx_info *nxi)
25058  {
25059         struct ipv6_saddr_score scores[2],
25060                                 *score = &scores[0], *hiscore = &scores[1];
25061 @@ -1396,6 +1398,8 @@ int ipv6_dev_get_saddr(struct net *net,
25062                                                dev->name);
25063                                 continue;
25064                         }
25065 +                       if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25066 +                               continue;
25067  
25068                         score->rule = -1;
25069                         bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25070 @@ -3451,7 +3455,10 @@ static void if6_seq_stop(struct seq_file
25071  static int if6_seq_show(struct seq_file *seq, void *v)
25072  {
25073         struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25074 -       seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25075 +
25076 +       if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25077 +           v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25078 +               seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25079                    &ifp->addr,
25080                    ifp->idev->dev->ifindex,
25081                    ifp->prefix_len,
25082 @@ -3955,6 +3962,11 @@ static int in6_dump_addrs(struct inet6_d
25083         struct ifacaddr6 *ifaca;
25084         int err = 1;
25085         int ip_idx = *p_ip_idx;
25086 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25087 +
25088 +       /* disable ipv6 on non v6 guests */
25089 +       if (nxi && !nx_info_has_v6(nxi))
25090 +               return skb->len;
25091  
25092         read_lock_bh(&idev->lock);
25093         switch (type) {
25094 @@ -3965,6 +3977,8 @@ static int in6_dump_addrs(struct inet6_d
25095                 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25096                         if (++ip_idx < s_ip_idx)
25097                                 continue;
25098 +                               if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25099 +                                       continue;
25100                         err = inet6_fill_ifaddr(skb, ifa,
25101                                                 NETLINK_CB(cb->skb).portid,
25102                                                 cb->nlh->nlmsg_seq,
25103 @@ -3982,6 +3996,8 @@ static int in6_dump_addrs(struct inet6_d
25104                      ifmca = ifmca->next, ip_idx++) {
25105                         if (ip_idx < s_ip_idx)
25106                                 continue;
25107 +                               if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25108 +                                       continue;
25109                         err = inet6_fill_ifmcaddr(skb, ifmca,
25110                                                   NETLINK_CB(cb->skb).portid,
25111                                                   cb->nlh->nlmsg_seq,
25112 @@ -3997,6 +4013,8 @@ static int in6_dump_addrs(struct inet6_d
25113                      ifaca = ifaca->aca_next, ip_idx++) {
25114                         if (ip_idx < s_ip_idx)
25115                                 continue;
25116 +                               if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25117 +                                       continue;
25118                         err = inet6_fill_ifacaddr(skb, ifaca,
25119                                                   NETLINK_CB(cb->skb).portid,
25120                                                   cb->nlh->nlmsg_seq,
25121 @@ -4025,6 +4043,10 @@ static int inet6_dump_addr(struct sk_buf
25122         struct inet6_dev *idev;
25123         struct hlist_head *head;
25124  
25125 +       /* FIXME: maybe disable ipv6 on non v6 guests?
25126 +       if (skb->sk && skb->sk->sk_vx_info)
25127 +               return skb->len; */
25128 +
25129         s_h = cb->args[0];
25130         s_idx = idx = cb->args[1];
25131         s_ip_idx = ip_idx = cb->args[2];
25132 @@ -4460,6 +4482,7 @@ static int inet6_dump_ifinfo(struct sk_b
25133         struct net_device *dev;
25134         struct inet6_dev *idev;
25135         struct hlist_head *head;
25136 +       struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25137  
25138         s_h = cb->args[0];
25139         s_idx = cb->args[1];
25140 @@ -4471,6 +4494,8 @@ static int inet6_dump_ifinfo(struct sk_b
25141                 hlist_for_each_entry_rcu(dev, head, index_hlist) {
25142                         if (idx < s_idx)
25143                                 goto cont;
25144 +                       if (!v6_dev_in_nx_info(dev, nxi))
25145 +                               goto cont;
25146                         idev = __in6_dev_get(dev);
25147                         if (!idev)
25148                                 goto cont;
25149 diff -NurpP --minimal linux-3.10.40/net/ipv6/af_inet6.c linux-3.10.40-vs2.3.6.8/net/ipv6/af_inet6.c
25150 --- linux-3.10.40/net/ipv6/af_inet6.c   2013-07-14 17:01:38.000000000 +0000
25151 +++ linux-3.10.40-vs2.3.6.8/net/ipv6/af_inet6.c 2013-08-22 20:30:00.000000000 +0000
25152 @@ -43,6 +43,8 @@
25153  #include <linux/netdevice.h>
25154  #include <linux/icmpv6.h>
25155  #include <linux/netfilter_ipv6.h>
25156 +#include <linux/vs_inet.h>
25157 +#include <linux/vs_inet6.h>
25158  
25159  #include <net/ip.h>
25160  #include <net/ipv6.h>
25161 @@ -159,10 +161,13 @@ lookup_protocol:
25162         }
25163  
25164         err = -EPERM;
25165 +       if ((protocol == IPPROTO_ICMPV6) &&
25166 +               nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25167 +               goto override;
25168         if (sock->type == SOCK_RAW && !kern &&
25169             !ns_capable(net->user_ns, CAP_NET_RAW))
25170                 goto out_rcu_unlock;
25171 -
25172 +override:
25173         sock->ops = answer->ops;
25174         answer_prot = answer->prot;
25175         answer_no_check = answer->no_check;
25176 @@ -262,6 +267,7 @@ int inet6_bind(struct socket *sock, stru
25177         struct inet_sock *inet = inet_sk(sk);
25178         struct ipv6_pinfo *np = inet6_sk(sk);
25179         struct net *net = sock_net(sk);
25180 +       struct nx_v6_sock_addr nsa;
25181         __be32 v4addr = 0;
25182         unsigned short snum;
25183         int addr_type = 0;
25184 @@ -277,6 +283,10 @@ int inet6_bind(struct socket *sock, stru
25185         if (addr->sin6_family != AF_INET6)
25186                 return -EAFNOSUPPORT;
25187  
25188 +       err = v6_map_sock_addr(inet, addr, &nsa);
25189 +       if (err)
25190 +               return err;
25191 +
25192         addr_type = ipv6_addr_type(&addr->sin6_addr);
25193         if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25194                 return -EINVAL;
25195 @@ -308,6 +318,7 @@ int inet6_bind(struct socket *sock, stru
25196                 /* Reproduce AF_INET checks to make the bindings consistent */
25197                 v4addr = addr->sin6_addr.s6_addr32[3];
25198                 chk_addr_ret = inet_addr_type(net, v4addr);
25199 +
25200                 if (!sysctl_ip_nonlocal_bind &&
25201                     !(inet->freebind || inet->transparent) &&
25202                     v4addr != htonl(INADDR_ANY) &&
25203 @@ -317,6 +328,10 @@ int inet6_bind(struct socket *sock, stru
25204                         err = -EADDRNOTAVAIL;
25205                         goto out;
25206                 }
25207 +               if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25208 +                       err = -EADDRNOTAVAIL;
25209 +                       goto out;
25210 +               }
25211         } else {
25212                 if (addr_type != IPV6_ADDR_ANY) {
25213                         struct net_device *dev = NULL;
25214 @@ -343,6 +358,11 @@ int inet6_bind(struct socket *sock, stru
25215                                 }
25216                         }
25217  
25218 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25219 +                               err = -EADDRNOTAVAIL;
25220 +                               goto out_unlock;
25221 +                       }
25222 +
25223                         /* ipv4 addr of the socket is invalid.  Only the
25224                          * unspecified and mapped address have a v4 equivalent.
25225                          */
25226 @@ -359,6 +379,9 @@ int inet6_bind(struct socket *sock, stru
25227                 }
25228         }
25229  
25230 +       /* what's that for? */
25231 +       v6_set_sock_addr(inet, &nsa);
25232 +
25233         inet->inet_rcv_saddr = v4addr;
25234         inet->inet_saddr = v4addr;
25235  
25236 @@ -460,9 +483,11 @@ int inet6_getname(struct socket *sock, s
25237                         return -ENOTCONN;
25238                 sin->sin6_port = inet->inet_dport;
25239                 sin->sin6_addr = np->daddr;
25240 +               /* FIXME: remap lback? */
25241                 if (np->sndflow)
25242                         sin->sin6_flowinfo = np->flow_label;
25243         } else {
25244 +               /* FIXME: remap lback? */
25245                 if (ipv6_addr_any(&np->rcv_saddr))
25246                         sin->sin6_addr = np->saddr;
25247                 else
25248 diff -NurpP --minimal linux-3.10.40/net/ipv6/datagram.c linux-3.10.40-vs2.3.6.8/net/ipv6/datagram.c
25249 --- linux-3.10.40/net/ipv6/datagram.c   2014-05-20 04:09:43.000000000 +0000
25250 +++ linux-3.10.40-vs2.3.6.8/net/ipv6/datagram.c 2013-12-23 17:42:40.000000000 +0000
25251 @@ -656,7 +656,7 @@ int ip6_datagram_send_ctl(struct net *ne
25252  
25253                         rcu_read_lock();
25254                         if (fl6->flowi6_oif) {
25255 -                               dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25256 +                               dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25257                                 if (!dev) {
25258                                         rcu_read_unlock();
25259                                         return -ENODEV;
25260 diff -NurpP --minimal linux-3.10.40/net/ipv6/fib6_rules.c linux-3.10.40-vs2.3.6.8/net/ipv6/fib6_rules.c
25261 --- linux-3.10.40/net/ipv6/fib6_rules.c 2013-02-19 13:58:58.000000000 +0000
25262 +++ linux-3.10.40-vs2.3.6.8/net/ipv6/fib6_rules.c       2013-08-22 20:30:00.000000000 +0000
25263 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25264                                                ip6_dst_idev(&rt->dst)->dev,
25265                                                &flp6->daddr,
25266                                                rt6_flags2srcprefs(flags),
25267 -                                              &saddr))
25268 +                                              &saddr, NULL))
25269                                 goto again;
25270                         if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25271                                                r->src.plen))
25272 diff -NurpP --minimal linux-3.10.40/net/ipv6/inet6_hashtables.c linux-3.10.40-vs2.3.6.8/net/ipv6/inet6_hashtables.c
25273 --- linux-3.10.40/net/ipv6/inet6_hashtables.c   2014-05-20 04:09:43.000000000 +0000
25274 +++ linux-3.10.40-vs2.3.6.8/net/ipv6/inet6_hashtables.c 2013-11-13 17:22:25.000000000 +0000
25275 @@ -16,6 +16,7 @@
25276  
25277  #include <linux/module.h>
25278  #include <linux/random.h>
25279 +#include <linux/vs_inet6.h>
25280  
25281  #include <net/inet_connection_sock.h>
25282  #include <net/inet_hashtables.h>
25283 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25284         unsigned int slot = hash & hashinfo->ehash_mask;
25285         struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25286  
25287 -
25288         rcu_read_lock();
25289  begin:
25290         sk_nulls_for_each_rcu(sk, node, &head->chain) {
25291 @@ -97,7 +97,7 @@ begin:
25292                                 sock_put(sk);
25293                                 goto begin;
25294                         }
25295 -               goto out;
25296 +                       goto out;
25297                 }
25298         }
25299         if (get_nulls_value(node) != slot)
25300 @@ -147,6 +147,9 @@ static inline int compute_score(struct s
25301                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25302                                 return -1;
25303                         score++;
25304 +               } else {
25305 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25306 +                               return -1;
25307                 }
25308                 if (sk->sk_bound_dev_if) {
25309                         if (sk->sk_bound_dev_if != dif)
25310 diff -NurpP --minimal linux-3.10.40/net/ipv6/ip6_output.c linux-3.10.40-vs2.3.6.8/net/ipv6/ip6_output.c
25311 --- linux-3.10.40/net/ipv6/ip6_output.c 2014-05-20 04:09:43.000000000 +0000
25312 +++ linux-3.10.40-vs2.3.6.8/net/ipv6/ip6_output.c       2014-04-22 03:48:11.000000000 +0000
25313 @@ -896,7 +896,8 @@ static int ip6_dst_lookup_tail(struct so
25314                 struct rt6_info *rt = (struct rt6_info *) *dst;
25315                 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25316                                           sk ? inet6_sk(sk)->srcprefs : 0,
25317 -                                         &fl6->saddr);
25318 +                                         &fl6->saddr,
25319 +                                         sk ? sk->sk_nx_info : NULL);
25320                 if (err)
25321                         goto out_err_release;
25322         }
25323 diff -NurpP --minimal linux-3.10.40/net/ipv6/ndisc.c linux-3.10.40-vs2.3.6.8/net/ipv6/ndisc.c
25324 --- linux-3.10.40/net/ipv6/ndisc.c      2014-05-20 04:09:43.000000000 +0000
25325 +++ linux-3.10.40-vs2.3.6.8/net/ipv6/ndisc.c    2013-11-13 17:17:16.000000000 +0000
25326 @@ -487,7 +487,7 @@ static void ndisc_send_na(struct net_dev
25327         } else {
25328                 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25329                                        inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25330 -                                      &tmpaddr))
25331 +                                      &tmpaddr, NULL))
25332                         return;
25333                 src_addr = &tmpaddr;
25334         }
25335 diff -NurpP --minimal linux-3.10.40/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.10.40-vs2.3.6.8/net/ipv6/netfilter/ip6t_MASQUERADE.c
25336 --- linux-3.10.40/net/ipv6/netfilter/ip6t_MASQUERADE.c  2012-12-11 03:30:57.000000000 +0000
25337 +++ linux-3.10.40-vs2.3.6.8/net/ipv6/netfilter/ip6t_MASQUERADE.c        2013-08-22 20:30:00.000000000 +0000
25338 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
25339                             ctinfo == IP_CT_RELATED_REPLY));
25340  
25341         if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
25342 -                              &ipv6_hdr(skb)->daddr, 0, &src) < 0)
25343 +                              &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
25344                 return NF_DROP;
25345  
25346         nfct_nat(ct)->masq_index = par->out->ifindex;
25347 diff -NurpP --minimal linux-3.10.40/net/ipv6/raw.c linux-3.10.40-vs2.3.6.8/net/ipv6/raw.c
25348 --- linux-3.10.40/net/ipv6/raw.c        2014-05-20 04:09:43.000000000 +0000
25349 +++ linux-3.10.40-vs2.3.6.8/net/ipv6/raw.c      2013-12-23 17:42:40.000000000 +0000
25350 @@ -30,6 +30,7 @@
25351  #include <linux/icmpv6.h>
25352  #include <linux/netfilter.h>
25353  #include <linux/netfilter_ipv6.h>
25354 +#include <linux/vs_inet6.h>
25355  #include <linux/skbuff.h>
25356  #include <linux/compat.h>
25357  #include <asm/uaccess.h>
25358 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
25359                                 goto out_unlock;
25360                 }
25361  
25362 +               if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25363 +                       err = -EADDRNOTAVAIL;
25364 +                       if (dev)
25365 +                               dev_put(dev);
25366 +                       goto out;
25367 +               }
25368 +
25369                 /* ipv4 addr of the socket is invalid.  Only the
25370                  * unspecified and mapped address have a v4 equivalent.
25371                  */
25372 diff -NurpP --minimal linux-3.10.40/net/ipv6/route.c linux-3.10.40-vs2.3.6.8/net/ipv6/route.c
25373 --- linux-3.10.40/net/ipv6/route.c      2014-05-20 04:09:43.000000000 +0000
25374 +++ linux-3.10.40-vs2.3.6.8/net/ipv6/route.c    2014-04-22 03:48:11.000000000 +0000
25375 @@ -58,6 +58,7 @@
25376  #include <net/netevent.h>
25377  #include <net/netlink.h>
25378  #include <net/nexthop.h>
25379 +#include <linux/vs_inet6.h>
25380  
25381  #include <asm/uaccess.h>
25382  
25383 @@ -2129,15 +2130,17 @@ int ip6_route_get_saddr(struct net *net,
25384                         struct rt6_info *rt,
25385                         const struct in6_addr *daddr,
25386                         unsigned int prefs,
25387 -                       struct in6_addr *saddr)
25388 +                       struct in6_addr *saddr,
25389 +                       struct nx_info *nxi)
25390  {
25391         struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25392         int err = 0;
25393 -       if (rt->rt6i_prefsrc.plen)
25394 +       if (rt->rt6i_prefsrc.plen && (!nxi ||
25395 +           v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25396                 *saddr = rt->rt6i_prefsrc.addr;
25397         else
25398                 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25399 -                                        daddr, prefs, saddr);
25400 +                                        daddr, prefs, saddr, nxi);
25401         return err;
25402  }
25403  
25404 @@ -2557,7 +2560,8 @@ static int rt6_fill_node(struct net *net
25405                                 goto nla_put_failure;
25406         } else if (dst) {
25407                 struct in6_addr saddr_buf;
25408 -               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25409 +               if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25410 +                   (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25411                     nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25412                         goto nla_put_failure;
25413         }
25414 @@ -2769,6 +2773,7 @@ static int rt6_info_route(struct rt6_inf
25415  {
25416         struct seq_file *m = p_arg;
25417  
25418 +       /* FIXME: check for network context? */
25419         seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25420  
25421  #ifdef CONFIG_IPV6_SUBTREES
25422 diff -NurpP --minimal linux-3.10.40/net/ipv6/tcp_ipv6.c linux-3.10.40-vs2.3.6.8/net/ipv6/tcp_ipv6.c
25423 --- linux-3.10.40/net/ipv6/tcp_ipv6.c   2014-05-20 04:09:43.000000000 +0000
25424 +++ linux-3.10.40-vs2.3.6.8/net/ipv6/tcp_ipv6.c 2013-11-13 17:17:16.000000000 +0000
25425 @@ -71,6 +71,7 @@
25426  
25427  #include <linux/crypto.h>
25428  #include <linux/scatterlist.h>
25429 +#include <linux/vs_inet6.h>
25430  
25431  static void    tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25432  static void    tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25433 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
25434          *      connect() to INADDR_ANY means loopback (BSD'ism).
25435          */
25436  
25437 -       if(ipv6_addr_any(&usin->sin6_addr))
25438 -               usin->sin6_addr.s6_addr[15] = 0x1;
25439 +       if(ipv6_addr_any(&usin->sin6_addr)) {
25440 +               struct nx_info *nxi =  sk->sk_nx_info;
25441 +
25442 +               if (nxi && nx_info_has_v6(nxi))
25443 +                       /* FIXME: remap lback? */
25444 +                       usin->sin6_addr = nxi->v6.ip;
25445 +               else
25446 +                       usin->sin6_addr.s6_addr[15] = 0x1;
25447 +       }
25448  
25449         addr_type = ipv6_addr_type(&usin->sin6_addr);
25450  
25451 diff -NurpP --minimal linux-3.10.40/net/ipv6/udp.c linux-3.10.40-vs2.3.6.8/net/ipv6/udp.c
25452 --- linux-3.10.40/net/ipv6/udp.c        2014-05-20 04:09:43.000000000 +0000
25453 +++ linux-3.10.40-vs2.3.6.8/net/ipv6/udp.c      2013-12-23 17:42:40.000000000 +0000
25454 @@ -46,42 +46,68 @@
25455  #include <net/ip6_checksum.h>
25456  #include <net/xfrm.h>
25457  #include <net/inet6_hashtables.h>
25458 +#include <linux/vs_inet6.h>
25459  
25460  #include <linux/proc_fs.h>
25461  #include <linux/seq_file.h>
25462  #include <trace/events/skb.h>
25463  #include "udp_impl.h"
25464  
25465 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25466 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25467  {
25468 -       const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25469 +       const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25470         const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25471 -       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25472 +       __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25473         __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25474 -       int sk_ipv6only = ipv6_only_sock(sk);
25475 +       int sk1_ipv6only = ipv6_only_sock(sk1);
25476         int sk2_ipv6only = inet_v6_ipv6only(sk2);
25477 -       int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25478 +       int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25479         int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25480  
25481         /* if both are mapped, treat as IPv4 */
25482 -       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25483 -               return (!sk2_ipv6only &&
25484 +       if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25485 +               if (!sk2_ipv6only &&
25486                         (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25487 -                         sk1_rcv_saddr == sk2_rcv_saddr));
25488 +                         sk1_rcv_saddr == sk2_rcv_saddr))
25489 +                       goto vs_v4;
25490 +               else
25491 +                       return 0;
25492 +       }
25493  
25494         if (addr_type2 == IPV6_ADDR_ANY &&
25495             !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25496 -               return 1;
25497 +               goto vs;
25498  
25499         if (addr_type == IPV6_ADDR_ANY &&
25500 -           !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25501 -               return 1;
25502 +           !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25503 +               goto vs;
25504  
25505         if (sk2_rcv_saddr6 &&
25506 -           ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25507 -               return 1;
25508 +           ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25509 +               goto vs;
25510  
25511         return 0;
25512 +
25513 +vs_v4:
25514 +       if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25515 +               return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25516 +       if (!sk2_rcv_saddr)
25517 +               return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25518 +       if (!sk1_rcv_saddr)
25519 +               return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25520 +       return 1;
25521 +vs:
25522 +       if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25523 +               return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25524 +       else if (addr_type2 == IPV6_ADDR_ANY)
25525 +               return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25526 +       else if (addr_type == IPV6_ADDR_ANY) {
25527 +               if (addr_type2 == IPV6_ADDR_MAPPED)
25528 +                       return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25529 +               else
25530 +                       return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25531 +       }
25532 +       return 1;
25533  }
25534  
25535  static unsigned int udp6_portaddr_hash(struct net *net,
25536 @@ -145,6 +171,10 @@ static inline int compute_score(struct s
25537                         if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25538                                 return -1;
25539                         score++;
25540 +               } else {
25541 +                       /* block non nx_info ips */
25542 +                       if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25543 +                               return -1;
25544                 }
25545                 if (!ipv6_addr_any(&np->daddr)) {
25546                         if (!ipv6_addr_equal(&np->daddr, saddr))
25547 diff -NurpP --minimal linux-3.10.40/net/ipv6/xfrm6_policy.c linux-3.10.40-vs2.3.6.8/net/ipv6/xfrm6_policy.c
25548 --- linux-3.10.40/net/ipv6/xfrm6_policy.c       2013-07-14 17:01:38.000000000 +0000
25549 +++ linux-3.10.40-vs2.3.6.8/net/ipv6/xfrm6_policy.c     2013-08-22 20:30:00.000000000 +0000
25550 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25551         dev = ip6_dst_idev(dst)->dev;
25552         ipv6_dev_get_saddr(dev_net(dev), dev,
25553                            (struct in6_addr *)&daddr->a6, 0,
25554 -                          (struct in6_addr *)&saddr->a6);
25555 +                          (struct in6_addr *)&saddr->a6, NULL);
25556         dst_release(dst);
25557         return 0;
25558  }
25559 diff -NurpP --minimal linux-3.10.40/net/netfilter/ipvs/ip_vs_xmit.c linux-3.10.40-vs2.3.6.8/net/netfilter/ipvs/ip_vs_xmit.c
25560 --- linux-3.10.40/net/netfilter/ipvs/ip_vs_xmit.c       2014-05-20 04:09:44.000000000 +0000
25561 +++ linux-3.10.40-vs2.3.6.8/net/netfilter/ipvs/ip_vs_xmit.c     2013-11-13 17:17:16.000000000 +0000
25562 @@ -316,7 +316,7 @@ __ip_vs_route_output_v6(struct net *net,
25563                 return dst;
25564         if (ipv6_addr_any(&fl6.saddr) &&
25565             ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25566 -                              &fl6.daddr, 0, &fl6.saddr) < 0)
25567 +                              &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25568                 goto out_err;
25569         if (do_xfrm) {
25570                 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25571 diff -NurpP --minimal linux-3.10.40/net/netlink/af_netlink.c linux-3.10.40-vs2.3.6.8/net/netlink/af_netlink.c
25572 --- linux-3.10.40/net/netlink/af_netlink.c      2014-05-20 04:09:44.000000000 +0000
25573 +++ linux-3.10.40-vs2.3.6.8/net/netlink/af_netlink.c    2013-12-23 17:42:40.000000000 +0000
25574 @@ -57,6 +57,9 @@
25575  #include <linux/audit.h>
25576  #include <linux/mutex.h>
25577  #include <linux/vmalloc.h>
25578 +#include <linux/vs_context.h>
25579 +#include <linux/vs_network.h>
25580 +#include <linux/vs_limit.h>
25581  #include <asm/cacheflush.h>
25582  
25583  #include <net/net_namespace.h>
25584 @@ -2682,6 +2685,8 @@ static struct sock *netlink_seq_socket_i
25585                         sk_for_each(s, &hash->table[j]) {
25586                                 if (sock_net(s) != seq_file_net(seq))
25587                                         continue;
25588 +                               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25589 +                                       continue;
25590                                 if (off == pos) {
25591                                         iter->link = i;
25592                                         iter->hash_idx = j;
25593 @@ -2716,7 +2721,8 @@ static void *netlink_seq_next(struct seq
25594         s = v;
25595         do {
25596                 s = sk_next(s);
25597 -       } while (s && sock_net(s) != seq_file_net(seq));
25598 +       } while (s && (sock_net(s) != seq_file_net(seq) ||
25599 +               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25600         if (s)
25601                 return s;
25602  
25603 @@ -2728,7 +2734,8 @@ static void *netlink_seq_next(struct seq
25604  
25605                 for (; j <= hash->mask; j++) {
25606                         s = sk_head(&hash->table[j]);
25607 -                       while (s && sock_net(s) != seq_file_net(seq))
25608 +                       while (s && (sock_net(s) != seq_file_net(seq) ||
25609 +                               !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25610                                 s = sk_next(s);
25611                         if (s) {
25612                                 iter->link = i;
25613 diff -NurpP --minimal linux-3.10.40/net/socket.c linux-3.10.40-vs2.3.6.8/net/socket.c
25614 --- linux-3.10.40/net/socket.c  2014-05-20 04:09:44.000000000 +0000
25615 +++ linux-3.10.40-vs2.3.6.8/net/socket.c        2014-04-22 03:48:11.000000000 +0000
25616 @@ -98,6 +98,10 @@
25617  
25618  #include <net/sock.h>
25619  #include <linux/netfilter.h>
25620 +#include <linux/vs_base.h>
25621 +#include <linux/vs_socket.h>
25622 +#include <linux/vs_inet.h>
25623 +#include <linux/vs_inet6.h>
25624  
25625  #include <linux/if_tun.h>
25626  #include <linux/ipv6_route.h>
25627 @@ -617,13 +621,29 @@ static inline int __sock_sendmsg_nosec(s
25628                                        struct msghdr *msg, size_t size)
25629  {
25630         struct sock_iocb *si = kiocb_to_siocb(iocb);
25631 +       size_t len;
25632  
25633         si->sock = sock;
25634         si->scm = NULL;
25635         si->msg = msg;
25636         si->size = size;
25637  
25638 -       return sock->ops->sendmsg(iocb, sock, msg, size);
25639 +       len = sock->ops->sendmsg(iocb, sock, msg, size);
25640 +       if (sock->sk) {
25641 +               if (len == size)
25642 +                       vx_sock_send(sock->sk, size);
25643 +               else
25644 +                       vx_sock_fail(sock->sk, size);
25645 +       }
25646 +       vxdprintk(VXD_CBIT(net, 7),
25647 +               "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25648 +               sock, sock->sk,
25649 +               (sock->sk)?sock->sk->sk_nx_info:0,
25650 +               (sock->sk)?sock->sk->sk_vx_info:0,
25651 +               (sock->sk)?sock->sk->sk_xid:0,
25652 +               (sock->sk)?sock->sk->sk_nid:0,
25653 +               (unsigned int)size, len);
25654 +       return len;
25655  }
25656  
25657  static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25658 @@ -767,6 +787,7 @@ static inline int __sock_recvmsg_nosec(s
25659                                        struct msghdr *msg, size_t size, int flags)
25660  {
25661         struct sock_iocb *si = kiocb_to_siocb(iocb);
25662 +       int len;
25663  
25664         si->sock = sock;
25665         si->scm = NULL;
25666 @@ -774,7 +795,18 @@ static inline int __sock_recvmsg_nosec(s
25667         si->size = size;
25668         si->flags = flags;
25669  
25670 -       return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25671 +       len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25672 +       if ((len >= 0) && sock->sk)
25673 +               vx_sock_recv(sock->sk, len);
25674 +       vxdprintk(VXD_CBIT(net, 7),
25675 +               "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25676 +               sock, sock->sk,
25677 +               (sock->sk)?sock->sk->sk_nx_info:0,
25678 +               (sock->sk)?sock->sk->sk_vx_info:0,
25679 +               (sock->sk)?sock->sk->sk_xid:0,
25680 +               (sock->sk)?sock->sk->sk_nid:0,
25681 +               (unsigned int)size, len);
25682 +       return len;
25683  }
25684  
25685  static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25686 @@ -1248,6 +1280,13 @@ int __sock_create(struct net *net, int f
25687         if (type < 0 || type >= SOCK_MAX)
25688                 return -EINVAL;
25689  
25690 +       if (!nx_check(0, VS_ADMIN)) {
25691 +               if (family == PF_INET && !current_nx_info_has_v4())
25692 +                       return -EAFNOSUPPORT;
25693 +               if (family == PF_INET6 && !current_nx_info_has_v6())
25694 +                       return -EAFNOSUPPORT;
25695 +       }
25696 +
25697         /* Compatibility.
25698  
25699            This uglymoron is moved from INET layer to here to avoid
25700 @@ -1382,6 +1421,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25701         if (retval < 0)
25702                 goto out;
25703  
25704 +       set_bit(SOCK_USER_SOCKET, &sock->flags);
25705         retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25706         if (retval < 0)
25707                 goto out_release;
25708 @@ -1423,10 +1463,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25709         err = sock_create(family, type, protocol, &sock1);
25710         if (err < 0)
25711                 goto out;
25712 +       set_bit(SOCK_USER_SOCKET, &sock1->flags);
25713  
25714         err = sock_create(family, type, protocol, &sock2);
25715         if (err < 0)
25716                 goto out_release_1;
25717 +       set_bit(SOCK_USER_SOCKET, &sock2->flags);
25718  
25719         err = sock1->ops->socketpair(sock1, sock2);
25720         if (err < 0)
25721 diff -NurpP --minimal linux-3.10.40/net/sunrpc/auth.c linux-3.10.40-vs2.3.6.8/net/sunrpc/auth.c
25722 --- linux-3.10.40/net/sunrpc/auth.c     2013-07-14 17:01:39.000000000 +0000
25723 +++ linux-3.10.40-vs2.3.6.8/net/sunrpc/auth.c   2013-08-22 20:30:00.000000000 +0000
25724 @@ -15,6 +15,7 @@
25725  #include <linux/sunrpc/clnt.h>
25726  #include <linux/sunrpc/gss_api.h>
25727  #include <linux/spinlock.h>
25728 +#include <linux/vs_tag.h>
25729  
25730  #ifdef RPC_DEBUG
25731  # define RPCDBG_FACILITY       RPCDBG_AUTH
25732 @@ -553,6 +554,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25733         memset(&acred, 0, sizeof(acred));
25734         acred.uid = cred->fsuid;
25735         acred.gid = cred->fsgid;
25736 +       acred.tag = make_ktag(&init_user_ns, dx_current_tag());
25737         acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25738  
25739         ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25740 @@ -593,6 +595,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25741         struct auth_cred acred = {
25742                 .uid = GLOBAL_ROOT_UID,
25743                 .gid = GLOBAL_ROOT_GID,
25744 +               .tag = KTAGT_INIT(dx_current_tag()),
25745         };
25746  
25747         dprintk("RPC: %5u looking up %s cred\n",
25748 diff -NurpP --minimal linux-3.10.40/net/sunrpc/auth_unix.c linux-3.10.40-vs2.3.6.8/net/sunrpc/auth_unix.c
25749 --- linux-3.10.40/net/sunrpc/auth_unix.c        2013-05-31 13:45:33.000000000 +0000
25750 +++ linux-3.10.40-vs2.3.6.8/net/sunrpc/auth_unix.c      2013-08-22 20:30:00.000000000 +0000
25751 @@ -13,11 +13,13 @@
25752  #include <linux/sunrpc/clnt.h>
25753  #include <linux/sunrpc/auth.h>
25754  #include <linux/user_namespace.h>
25755 +#include <linux/vs_tag.h>
25756  
25757  #define NFS_NGROUPS    16
25758  
25759  struct unx_cred {
25760         struct rpc_cred         uc_base;
25761 +       ktag_t                  uc_tag;
25762         kgid_t                  uc_gid;
25763         kgid_t                  uc_gids[NFS_NGROUPS];
25764  };
25765 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25766                 groups = NFS_NGROUPS;
25767  
25768         cred->uc_gid = acred->gid;
25769 +       cred->uc_tag = acred->tag;
25770         for (i = 0; i < groups; i++)
25771                 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25772         if (i < NFS_NGROUPS)
25773 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25774         unsigned int i;
25775  
25776  
25777 -       if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25778 +       if (!uid_eq(cred->uc_uid, acred->uid) ||
25779 +           !gid_eq(cred->uc_gid, acred->gid) ||
25780 +           !tag_eq(cred->uc_tag, acred->tag))
25781                 return 0;
25782  
25783         if (acred->group_info != NULL)
25784 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25785         struct rpc_clnt *clnt = task->tk_client;
25786         struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25787         __be32          *base, *hold;
25788 -       int             i;
25789 +       int             i, tag;
25790  
25791         *p++ = htonl(RPC_AUTH_UNIX);
25792         base = p++;
25793 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
25794          */
25795         p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25796  
25797 -       *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25798 -       *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25799 +       tag = task->tk_client->cl_tag;
25800 +       *p++ = htonl((u32) from_kuid(&init_user_ns,
25801 +               TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
25802 +       *p++ = htonl((u32) from_kgid(&init_user_ns,
25803 +               TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
25804         hold = p++;
25805         for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25806                 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25807 diff -NurpP --minimal linux-3.10.40/net/sunrpc/clnt.c linux-3.10.40-vs2.3.6.8/net/sunrpc/clnt.c
25808 --- linux-3.10.40/net/sunrpc/clnt.c     2014-05-20 04:09:44.000000000 +0000
25809 +++ linux-3.10.40-vs2.3.6.8/net/sunrpc/clnt.c   2014-03-12 13:18:24.000000000 +0000
25810 @@ -31,6 +31,7 @@
25811  #include <linux/in6.h>
25812  #include <linux/un.h>
25813  #include <linux/rcupdate.h>
25814 +#include <linux/vs_cvirt.h>
25815  
25816  #include <linux/sunrpc/clnt.h>
25817  #include <linux/sunrpc/addr.h>
25818 @@ -486,6 +487,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25819         if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25820                 clnt->cl_chatty = 1;
25821  
25822 +       /* TODO: handle RPC_CLNT_CREATE_TAGGED
25823 +       if (args->flags & RPC_CLNT_CREATE_TAGGED)
25824 +               clnt->cl_tag = 1; */
25825         return clnt;
25826  }
25827  EXPORT_SYMBOL_GPL(rpc_create);
25828 diff -NurpP --minimal linux-3.10.40/net/unix/af_unix.c linux-3.10.40-vs2.3.6.8/net/unix/af_unix.c
25829 --- linux-3.10.40/net/unix/af_unix.c    2014-05-20 04:09:44.000000000 +0000
25830 +++ linux-3.10.40-vs2.3.6.8/net/unix/af_unix.c  2014-04-22 03:48:11.000000000 +0000
25831 @@ -114,6 +114,8 @@
25832  #include <linux/mount.h>
25833  #include <net/checksum.h>
25834  #include <linux/security.h>
25835 +#include <linux/vs_context.h>
25836 +#include <linux/vs_limit.h>
25837  
25838  struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25839  EXPORT_SYMBOL_GPL(unix_socket_table);
25840 @@ -269,6 +271,8 @@ static struct sock *__unix_find_socket_b
25841                 if (!net_eq(sock_net(s), net))
25842                         continue;
25843  
25844 +               if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25845 +                       continue;
25846                 if (u->addr->len == len &&
25847                     !memcmp(u->addr->name, sunname, len))
25848                         goto found;
25849 @@ -2276,6 +2280,8 @@ static struct sock *unix_from_bucket(str
25850         for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25851                 if (sock_net(sk) != seq_file_net(seq))
25852                         continue;
25853 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25854 +                       continue;
25855                 if (++count == offset)
25856                         break;
25857         }
25858 @@ -2293,6 +2299,8 @@ static struct sock *unix_next_socket(str
25859                 sk = sk_next(sk);
25860                 if (!sk)
25861                         goto next_bucket;
25862 +               if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25863 +                       continue;
25864                 if (sock_net(sk) == seq_file_net(seq))
25865                         return sk;
25866         }
25867 diff -NurpP --minimal linux-3.10.40/scripts/checksyscalls.sh linux-3.10.40-vs2.3.6.8/scripts/checksyscalls.sh
25868 --- linux-3.10.40/scripts/checksyscalls.sh      2012-12-11 03:30:57.000000000 +0000
25869 +++ linux-3.10.40-vs2.3.6.8/scripts/checksyscalls.sh    2013-08-22 20:30:00.000000000 +0000
25870 @@ -193,7 +193,6 @@ cat << EOF
25871  #define __IGNORE_afs_syscall
25872  #define __IGNORE_getpmsg
25873  #define __IGNORE_putpmsg
25874 -#define __IGNORE_vserver
25875  EOF
25876  }
25877  
25878 diff -NurpP --minimal linux-3.10.40/security/commoncap.c linux-3.10.40-vs2.3.6.8/security/commoncap.c
25879 --- linux-3.10.40/security/commoncap.c  2013-05-31 13:45:34.000000000 +0000
25880 +++ linux-3.10.40-vs2.3.6.8/security/commoncap.c        2013-08-22 20:30:00.000000000 +0000
25881 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25882  int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25883                 int cap, int audit)
25884  {
25885 +       struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25886         struct user_namespace *ns = targ_ns;
25887  
25888         /* See if cred has the capability in the target user namespace
25889 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25890          */
25891         for (;;) {
25892                 /* Do we have the necessary capabilities? */
25893 -               if (ns == cred->user_ns)
25894 -                       return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25895 +               if (ns == cred->user_ns) {
25896 +                       if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25897 +                           cap_raised(cred->cap_effective, cap))
25898 +                               return 0;
25899 +                       return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25900 +               }
25901  
25902                 /* Have we tried all of the parent namespaces? */
25903                 if (ns == &init_user_ns)
25904 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25905  
25906         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25907                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25908 -           !capable(CAP_SYS_ADMIN))
25909 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25910                 return -EPERM;
25911         return 0;
25912  }
25913 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25914  
25915         if (!strncmp(name, XATTR_SECURITY_PREFIX,
25916                      sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25917 -           !capable(CAP_SYS_ADMIN))
25918 +               !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25919                 return -EPERM;
25920         return 0;
25921  }
25922 diff -NurpP --minimal linux-3.10.40/security/selinux/hooks.c linux-3.10.40-vs2.3.6.8/security/selinux/hooks.c
25923 --- linux-3.10.40/security/selinux/hooks.c      2014-05-20 04:09:45.000000000 +0000
25924 +++ linux-3.10.40-vs2.3.6.8/security/selinux/hooks.c    2014-04-22 03:48:11.000000000 +0000
25925 @@ -68,7 +68,6 @@
25926  #include <linux/dccp.h>
25927  #include <linux/quota.h>
25928  #include <linux/un.h>          /* for Unix socket types */
25929 -#include <net/af_unix.h>       /* for Unix socket types */
25930  #include <linux/parser.h>
25931  #include <linux/nfs_mount.h>
25932  #include <net/ipv6.h>
This page took 2.088644 seconds and 4 git commands to generate.