1 diff -NurpP --minimal linux-3.13.6/Documentation/vserver/debug.txt linux-3.13.6-vs2.3.6.11/Documentation/vserver/debug.txt
2 --- linux-3.13.6/Documentation/vserver/debug.txt 1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.13.6-vs2.3.6.11/Documentation/vserver/debug.txt 2014-01-31 20:38:03.000000000 +0000
8 + 2 4 "vx_map_tgid: %p/%llx: %d -> %d"
9 + "vx_rmap_tgid: %p/%llx: %d -> %d"
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"
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«)"
40 + 2 4 "dentry_open(new): %p"
41 + "dentry_open(old): %p"
42 + "lookup_create(new): %p"
44 + "path_lookup(old): %d"
45 + "vfs_create(new): %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]"
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"
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])"
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)"
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"
111 + 7 80 "dx_parse_tag(»%s«): %d:#%d"
112 + "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
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)*"
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]"
153 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
154 + "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
156 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
157 + "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
158 + "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
159 diff -NurpP --minimal linux-3.13.6/arch/alpha/Kconfig linux-3.13.6-vs2.3.6.11/arch/alpha/Kconfig
160 --- linux-3.13.6/arch/alpha/Kconfig 2014-01-22 20:38:09.000000000 +0000
161 +++ linux-3.13.6-vs2.3.6.11/arch/alpha/Kconfig 2014-01-31 20:38:03.000000000 +0000
162 @@ -735,6 +735,8 @@ config DUMMY_CONSOLE
166 +source "kernel/vserver/Kconfig"
168 source "security/Kconfig"
170 source "crypto/Kconfig"
171 diff -NurpP --minimal linux-3.13.6/arch/alpha/kernel/systbls.S linux-3.13.6-vs2.3.6.11/arch/alpha/kernel/systbls.S
172 --- linux-3.13.6/arch/alpha/kernel/systbls.S 2013-11-25 15:44:11.000000000 +0000
173 +++ linux-3.13.6-vs2.3.6.11/arch/alpha/kernel/systbls.S 2014-01-31 20:38:03.000000000 +0000
174 @@ -446,7 +446,7 @@ sys_call_table:
175 .quad sys_stat64 /* 425 */
178 - .quad sys_ni_syscall /* sys_vserver */
179 + .quad sys_vserver /* sys_vserver */
180 .quad sys_ni_syscall /* sys_mbind */
181 .quad sys_ni_syscall /* sys_get_mempolicy */
182 .quad sys_ni_syscall /* sys_set_mempolicy */
183 diff -NurpP --minimal linux-3.13.6/arch/alpha/kernel/traps.c linux-3.13.6-vs2.3.6.11/arch/alpha/kernel/traps.c
184 --- linux-3.13.6/arch/alpha/kernel/traps.c 2014-01-22 20:38:10.000000000 +0000
185 +++ linux-3.13.6-vs2.3.6.11/arch/alpha/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
186 @@ -175,7 +175,8 @@ die_if_kernel(char * str, struct pt_regs
188 printk("CPU %d ", hard_smp_processor_id());
190 - printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
191 + printk("%s(%d:#%u): %s %ld\n", current->comm,
192 + task_pid_nr(current), current->xid, str, err);
193 dik_show_regs(regs, r9_15);
194 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
195 dik_show_trace((unsigned long *)(regs+1));
196 diff -NurpP --minimal linux-3.13.6/arch/arm/Kconfig linux-3.13.6-vs2.3.6.11/arch/arm/Kconfig
197 --- linux-3.13.6/arch/arm/Kconfig 2014-01-22 20:38:10.000000000 +0000
198 +++ linux-3.13.6-vs2.3.6.11/arch/arm/Kconfig 2014-01-31 20:38:03.000000000 +0000
199 @@ -2265,6 +2265,8 @@ source "fs/Kconfig"
201 source "arch/arm/Kconfig.debug"
203 +source "kernel/vserver/Kconfig"
205 source "security/Kconfig"
207 source "crypto/Kconfig"
208 diff -NurpP --minimal linux-3.13.6/arch/arm/kernel/calls.S linux-3.13.6-vs2.3.6.11/arch/arm/kernel/calls.S
209 --- linux-3.13.6/arch/arm/kernel/calls.S 2013-05-31 13:44:29.000000000 +0000
210 +++ linux-3.13.6-vs2.3.6.11/arch/arm/kernel/calls.S 2014-01-31 20:38:03.000000000 +0000
212 /* 310 */ CALL(sys_request_key)
214 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
215 -/* vserver */ CALL(sys_ni_syscall)
218 /* 315 */ CALL(sys_ioprio_get)
219 CALL(sys_inotify_init)
220 diff -NurpP --minimal linux-3.13.6/arch/arm/kernel/traps.c linux-3.13.6-vs2.3.6.11/arch/arm/kernel/traps.c
221 --- linux-3.13.6/arch/arm/kernel/traps.c 2014-01-22 20:38:11.000000000 +0000
222 +++ linux-3.13.6-vs2.3.6.11/arch/arm/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
223 @@ -247,8 +247,8 @@ static int __die(const char *str, int er
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));
232 if (!user_mode(regs) || in_interrupt()) {
233 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
234 diff -NurpP --minimal linux-3.13.6/arch/cris/Kconfig linux-3.13.6-vs2.3.6.11/arch/cris/Kconfig
235 --- linux-3.13.6/arch/cris/Kconfig 2014-01-22 20:38:15.000000000 +0000
236 +++ linux-3.13.6-vs2.3.6.11/arch/cris/Kconfig 2014-01-31 20:38:03.000000000 +0000
237 @@ -561,6 +561,8 @@ source "fs/Kconfig"
239 source "arch/cris/Kconfig.debug"
241 +source "kernel/vserver/Kconfig"
243 source "security/Kconfig"
245 source "crypto/Kconfig"
246 diff -NurpP --minimal linux-3.13.6/arch/ia64/Kconfig linux-3.13.6-vs2.3.6.11/arch/ia64/Kconfig
247 --- linux-3.13.6/arch/ia64/Kconfig 2014-01-22 20:38:16.000000000 +0000
248 +++ linux-3.13.6-vs2.3.6.11/arch/ia64/Kconfig 2014-01-31 20:38:03.000000000 +0000
249 @@ -641,6 +641,8 @@ source "fs/Kconfig"
251 source "arch/ia64/Kconfig.debug"
253 +source "kernel/vserver/Kconfig"
255 source "security/Kconfig"
257 source "crypto/Kconfig"
258 diff -NurpP --minimal linux-3.13.6/arch/ia64/kernel/entry.S linux-3.13.6-vs2.3.6.11/arch/ia64/kernel/entry.S
259 --- linux-3.13.6/arch/ia64/kernel/entry.S 2014-01-22 20:38:16.000000000 +0000
260 +++ linux-3.13.6-vs2.3.6.11/arch/ia64/kernel/entry.S 2014-01-31 20:38:03.000000000 +0000
261 @@ -1706,7 +1706,7 @@ sys_call_table:
263 data8 sys_mq_getsetattr
265 - data8 sys_ni_syscall // reserved for vserver
267 data8 sys_waitid // 1270
269 data8 sys_request_key
270 diff -NurpP --minimal linux-3.13.6/arch/ia64/kernel/ptrace.c linux-3.13.6-vs2.3.6.11/arch/ia64/kernel/ptrace.c
271 --- linux-3.13.6/arch/ia64/kernel/ptrace.c 2013-02-19 13:56:51.000000000 +0000
272 +++ linux-3.13.6-vs2.3.6.11/arch/ia64/kernel/ptrace.c 2014-01-31 20:38:03.000000000 +0000
274 #include <linux/regset.h>
275 #include <linux/elf.h>
276 #include <linux/tracehook.h>
277 +#include <linux/vs_base.h>
279 #include <asm/pgtable.h>
280 #include <asm/processor.h>
281 diff -NurpP --minimal linux-3.13.6/arch/ia64/kernel/traps.c linux-3.13.6-vs2.3.6.11/arch/ia64/kernel/traps.c
282 --- linux-3.13.6/arch/ia64/kernel/traps.c 2013-11-25 15:44:20.000000000 +0000
283 +++ linux-3.13.6-vs2.3.6.11/arch/ia64/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
284 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
287 if (++die.lock_owner_depth < 3) {
288 - printk("%s[%d]: %s %ld [%d]\n",
289 - current->comm, task_pid_nr(current), str, err, ++die_counter);
290 + printk("%s[%d:#%u]: %s %ld [%d]\n",
291 + current->comm, task_pid_nr(current), current->xid,
292 + str, err, ++die_counter);
293 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
296 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
297 if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
298 last.time = current_jiffies + 5 * HZ;
300 - "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
301 - current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
302 + "%s(%d:#%u): floating-point assist fault at ip %016lx, isr %016lx\n",
303 + current->comm, task_pid_nr(current), current->xid,
304 + regs->cr_iip + ia64_psr(regs)->ri, isr);
308 diff -NurpP --minimal linux-3.13.6/arch/m32r/kernel/traps.c linux-3.13.6-vs2.3.6.11/arch/m32r/kernel/traps.c
309 --- linux-3.13.6/arch/m32r/kernel/traps.c 2013-07-14 17:00:26.000000000 +0000
310 +++ linux-3.13.6-vs2.3.6.11/arch/m32r/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
311 @@ -184,8 +184,9 @@ static void show_registers(struct pt_reg
313 printk("SPI: %08lx\n", sp);
315 - printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
316 - current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
317 + printk("Process %s (pid: %d:#%u, process nr: %d, stackpage=%08lx)",
318 + current->comm, task_pid_nr(current), current->xid,
319 + 0xffff & i, 4096+(unsigned long)current);
322 * When in-kernel, we also print out the stack and code at the
323 diff -NurpP --minimal linux-3.13.6/arch/m68k/Kconfig linux-3.13.6-vs2.3.6.11/arch/m68k/Kconfig
324 --- linux-3.13.6/arch/m68k/Kconfig 2014-01-22 20:38:16.000000000 +0000
325 +++ linux-3.13.6-vs2.3.6.11/arch/m68k/Kconfig 2014-01-31 20:38:03.000000000 +0000
326 @@ -134,6 +134,8 @@ source "fs/Kconfig"
328 source "arch/m68k/Kconfig.debug"
330 +source "kernel/vserver/Kconfig"
332 source "security/Kconfig"
334 source "crypto/Kconfig"
335 diff -NurpP --minimal linux-3.13.6/arch/mips/Kconfig linux-3.13.6-vs2.3.6.11/arch/mips/Kconfig
336 --- linux-3.13.6/arch/mips/Kconfig 2014-01-22 20:38:16.000000000 +0000
337 +++ linux-3.13.6-vs2.3.6.11/arch/mips/Kconfig 2014-01-31 20:38:03.000000000 +0000
338 @@ -2539,6 +2539,8 @@ source "fs/Kconfig"
340 source "arch/mips/Kconfig.debug"
342 +source "kernel/vserver/Kconfig"
344 source "security/Kconfig"
346 source "crypto/Kconfig"
347 diff -NurpP --minimal linux-3.13.6/arch/mips/kernel/ptrace.c linux-3.13.6-vs2.3.6.11/arch/mips/kernel/ptrace.c
348 --- linux-3.13.6/arch/mips/kernel/ptrace.c 2014-01-22 20:38:17.000000000 +0000
349 +++ linux-3.13.6-vs2.3.6.11/arch/mips/kernel/ptrace.c 2014-01-31 20:53:13.000000000 +0000
351 #include <linux/audit.h>
352 #include <linux/seccomp.h>
353 #include <linux/ftrace.h>
354 +#include <linux/vs_base.h>
356 #include <asm/byteorder.h>
358 @@ -398,6 +399,9 @@ long arch_ptrace(struct task_struct *chi
359 void __user *datavp = (void __user *) data;
360 unsigned long __user *datalp = (void __user *) data;
362 + if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
366 /* when I and D space are separate, these will need to be fixed. */
367 case PTRACE_PEEKTEXT: /* read word at location addr. */
368 diff -NurpP --minimal linux-3.13.6/arch/mips/kernel/scall32-o32.S linux-3.13.6-vs2.3.6.11/arch/mips/kernel/scall32-o32.S
369 --- linux-3.13.6/arch/mips/kernel/scall32-o32.S 2014-01-22 20:38:17.000000000 +0000
370 +++ linux-3.13.6-vs2.3.6.11/arch/mips/kernel/scall32-o32.S 2014-01-31 20:48:18.000000000 +0000
371 @@ -491,7 +491,7 @@ EXPORT(sys_call_table)
372 PTR sys_mq_timedreceive
373 PTR sys_mq_notify /* 4275 */
374 PTR sys_mq_getsetattr
375 - PTR sys_ni_syscall /* sys_vserver */
378 PTR sys_ni_syscall /* available, was setaltroot */
379 PTR sys_add_key /* 4280 */
380 diff -NurpP --minimal linux-3.13.6/arch/mips/kernel/scall64-64.S linux-3.13.6-vs2.3.6.11/arch/mips/kernel/scall64-64.S
381 --- linux-3.13.6/arch/mips/kernel/scall64-64.S 2014-01-22 20:38:17.000000000 +0000
382 +++ linux-3.13.6-vs2.3.6.11/arch/mips/kernel/scall64-64.S 2014-01-31 20:38:03.000000000 +0000
383 @@ -352,7 +352,7 @@ EXPORT(sys_call_table)
384 PTR sys_mq_timedreceive
386 PTR sys_mq_getsetattr /* 5235 */
387 - PTR sys_ni_syscall /* sys_vserver */
390 PTR sys_ni_syscall /* available, was setaltroot */
392 diff -NurpP --minimal linux-3.13.6/arch/mips/kernel/scall64-n32.S linux-3.13.6-vs2.3.6.11/arch/mips/kernel/scall64-n32.S
393 --- linux-3.13.6/arch/mips/kernel/scall64-n32.S 2014-01-22 20:38:17.000000000 +0000
394 +++ linux-3.13.6-vs2.3.6.11/arch/mips/kernel/scall64-n32.S 2014-01-31 20:38:03.000000000 +0000
395 @@ -345,7 +345,7 @@ EXPORT(sysn32_call_table)
396 PTR compat_sys_mq_timedreceive
397 PTR compat_sys_mq_notify
398 PTR compat_sys_mq_getsetattr
399 - PTR sys_ni_syscall /* 6240, sys_vserver */
400 + PTR sys32_vserver /* 6240 */
401 PTR compat_sys_waitid
402 PTR sys_ni_syscall /* available, was setaltroot */
404 diff -NurpP --minimal linux-3.13.6/arch/mips/kernel/scall64-o32.S linux-3.13.6-vs2.3.6.11/arch/mips/kernel/scall64-o32.S
405 --- linux-3.13.6/arch/mips/kernel/scall64-o32.S 2014-01-22 20:38:17.000000000 +0000
406 +++ linux-3.13.6-vs2.3.6.11/arch/mips/kernel/scall64-o32.S 2014-01-31 20:38:03.000000000 +0000
407 @@ -469,7 +469,7 @@ EXPORT(sys32_call_table)
408 PTR compat_sys_mq_timedreceive
409 PTR compat_sys_mq_notify /* 4275 */
410 PTR compat_sys_mq_getsetattr
411 - PTR sys_ni_syscall /* sys_vserver */
413 PTR compat_sys_waitid
414 PTR sys_ni_syscall /* available, was setaltroot */
415 PTR sys_add_key /* 4280 */
416 diff -NurpP --minimal linux-3.13.6/arch/mips/kernel/traps.c linux-3.13.6-vs2.3.6.11/arch/mips/kernel/traps.c
417 --- linux-3.13.6/arch/mips/kernel/traps.c 2014-01-22 20:38:17.000000000 +0000
418 +++ linux-3.13.6-vs2.3.6.11/arch/mips/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
419 @@ -334,9 +334,10 @@ void show_registers(struct pt_regs *regs
423 - printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
424 - current->comm, current->pid, current_thread_info(), current,
425 - field, current_thread_info()->tp_value);
426 + printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
427 + current->comm, task_pid_nr(current), current->xid,
428 + current_thread_info(), current,
429 + field, current_thread_info()->tp_value);
430 if (cpu_has_userlocal) {
433 diff -NurpP --minimal linux-3.13.6/arch/parisc/Kconfig linux-3.13.6-vs2.3.6.11/arch/parisc/Kconfig
434 --- linux-3.13.6/arch/parisc/Kconfig 2014-01-22 20:38:18.000000000 +0000
435 +++ linux-3.13.6-vs2.3.6.11/arch/parisc/Kconfig 2014-01-31 20:38:03.000000000 +0000
436 @@ -320,6 +320,8 @@ source "fs/Kconfig"
438 source "arch/parisc/Kconfig.debug"
440 +source "kernel/vserver/Kconfig"
442 source "security/Kconfig"
444 source "crypto/Kconfig"
445 diff -NurpP --minimal linux-3.13.6/arch/parisc/kernel/syscall_table.S linux-3.13.6-vs2.3.6.11/arch/parisc/kernel/syscall_table.S
446 --- linux-3.13.6/arch/parisc/kernel/syscall_table.S 2013-07-14 17:00:31.000000000 +0000
447 +++ linux-3.13.6-vs2.3.6.11/arch/parisc/kernel/syscall_table.S 2014-01-31 20:38:03.000000000 +0000
449 ENTRY_COMP(mbind) /* 260 */
450 ENTRY_COMP(get_mempolicy)
451 ENTRY_COMP(set_mempolicy)
452 - ENTRY_SAME(ni_syscall) /* 263: reserved for vserver */
453 + ENTRY_DIFF(vserver)
455 ENTRY_SAME(request_key) /* 265 */
457 diff -NurpP --minimal linux-3.13.6/arch/parisc/kernel/traps.c linux-3.13.6-vs2.3.6.11/arch/parisc/kernel/traps.c
458 --- linux-3.13.6/arch/parisc/kernel/traps.c 2013-11-25 15:46:28.000000000 +0000
459 +++ linux-3.13.6-vs2.3.6.11/arch/parisc/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
460 @@ -229,8 +229,9 @@ void die_if_kernel(char *str, struct pt_
464 - printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
465 - current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
466 + printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
467 + current->comm, task_pid_nr(current), current->xid,
468 + str, err, regs->iaoq[0]);
469 #ifdef PRINT_USER_FAULTS
470 /* XXX for debugging only */
472 @@ -263,8 +264,8 @@ void die_if_kernel(char *str, struct pt_
473 pdc_console_restart();
476 - printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
477 - current->comm, task_pid_nr(current), str, err);
478 + printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
479 + current->comm, task_pid_nr(current), current->xid, str, err);
481 /* Wot's wrong wif bein' racy? */
482 if (current->thread.flags & PARISC_KERNEL_DEATH) {
483 diff -NurpP --minimal linux-3.13.6/arch/parisc/mm/fault.c linux-3.13.6-vs2.3.6.11/arch/parisc/mm/fault.c
484 --- linux-3.13.6/arch/parisc/mm/fault.c 2014-01-22 20:38:18.000000000 +0000
485 +++ linux-3.13.6-vs2.3.6.11/arch/parisc/mm/fault.c 2014-01-31 20:38:03.000000000 +0000
486 @@ -272,8 +272,9 @@ bad_area:
488 #ifdef PRINT_USER_FAULTS
489 printk(KERN_DEBUG "\n");
490 - printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
491 - task_pid_nr(tsk), tsk->comm, code, address);
492 + printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
493 + "command='%s' type=%lu address=0x%08lx\n",
494 + task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
496 printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
497 vma->vm_start, vma->vm_end);
498 diff -NurpP --minimal linux-3.13.6/arch/powerpc/Kconfig linux-3.13.6-vs2.3.6.11/arch/powerpc/Kconfig
499 --- linux-3.13.6/arch/powerpc/Kconfig 2014-01-22 20:38:18.000000000 +0000
500 +++ linux-3.13.6-vs2.3.6.11/arch/powerpc/Kconfig 2014-01-31 20:38:03.000000000 +0000
501 @@ -1028,6 +1028,8 @@ source "lib/Kconfig"
503 source "arch/powerpc/Kconfig.debug"
505 +source "kernel/vserver/Kconfig"
507 source "security/Kconfig"
510 diff -NurpP --minimal linux-3.13.6/arch/powerpc/include/uapi/asm/unistd.h linux-3.13.6-vs2.3.6.11/arch/powerpc/include/uapi/asm/unistd.h
511 --- linux-3.13.6/arch/powerpc/include/uapi/asm/unistd.h 2013-05-31 13:44:44.000000000 +0000
512 +++ linux-3.13.6-vs2.3.6.11/arch/powerpc/include/uapi/asm/unistd.h 2014-01-31 20:38:03.000000000 +0000
515 #define __NR_rtas 255
516 #define __NR_sys_debug_setcontext 256
517 -/* Number 257 is reserved for vserver */
518 +#define __NR_vserver 257
519 #define __NR_migrate_pages 258
520 #define __NR_mbind 259
521 #define __NR_get_mempolicy 260
522 diff -NurpP --minimal linux-3.13.6/arch/powerpc/kernel/traps.c linux-3.13.6-vs2.3.6.11/arch/powerpc/kernel/traps.c
523 --- linux-3.13.6/arch/powerpc/kernel/traps.c 2014-01-22 20:38:23.000000000 +0000
524 +++ linux-3.13.6-vs2.3.6.11/arch/powerpc/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
525 @@ -1272,8 +1272,9 @@ void nonrecoverable_exception(struct pt_
527 void trace_syscall(struct pt_regs *regs)
529 - printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
530 - current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
531 + printk("Task: %p(%d:#%u), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
532 + current, task_pid_nr(current), current->xid,
533 + regs->nip, regs->link, regs->gpr[0],
534 regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
537 diff -NurpP --minimal linux-3.13.6/arch/s390/Kconfig linux-3.13.6-vs2.3.6.11/arch/s390/Kconfig
538 --- linux-3.13.6/arch/s390/Kconfig 2014-01-22 20:38:24.000000000 +0000
539 +++ linux-3.13.6-vs2.3.6.11/arch/s390/Kconfig 2014-01-31 20:38:03.000000000 +0000
540 @@ -649,6 +649,8 @@ source "fs/Kconfig"
542 source "arch/s390/Kconfig.debug"
544 +source "kernel/vserver/Kconfig"
546 source "security/Kconfig"
548 source "crypto/Kconfig"
549 diff -NurpP --minimal linux-3.13.6/arch/s390/include/asm/tlb.h linux-3.13.6-vs2.3.6.11/arch/s390/include/asm/tlb.h
550 --- linux-3.13.6/arch/s390/include/asm/tlb.h 2013-11-25 15:46:29.000000000 +0000
551 +++ linux-3.13.6-vs2.3.6.11/arch/s390/include/asm/tlb.h 2014-01-31 20:38:03.000000000 +0000
553 #include <linux/mm.h>
554 #include <linux/pagemap.h>
555 #include <linux/swap.h>
557 #include <asm/processor.h>
558 #include <asm/pgalloc.h>
559 #include <asm/tlbflush.h>
560 diff -NurpP --minimal linux-3.13.6/arch/s390/include/uapi/asm/unistd.h linux-3.13.6-vs2.3.6.11/arch/s390/include/uapi/asm/unistd.h
561 --- linux-3.13.6/arch/s390/include/uapi/asm/unistd.h 2013-02-19 13:57:16.000000000 +0000
562 +++ linux-3.13.6-vs2.3.6.11/arch/s390/include/uapi/asm/unistd.h 2014-01-31 20:38:03.000000000 +0000
564 #define __NR_clock_gettime (__NR_timer_create+6)
565 #define __NR_clock_getres (__NR_timer_create+7)
566 #define __NR_clock_nanosleep (__NR_timer_create+8)
567 -/* Number 263 is reserved for vserver */
568 +#define __NR_vserver 263
569 #define __NR_statfs64 265
570 #define __NR_fstatfs64 266
571 #define __NR_remap_file_pages 267
572 diff -NurpP --minimal linux-3.13.6/arch/s390/kernel/ptrace.c linux-3.13.6-vs2.3.6.11/arch/s390/kernel/ptrace.c
573 --- linux-3.13.6/arch/s390/kernel/ptrace.c 2014-01-22 20:38:24.000000000 +0000
574 +++ linux-3.13.6-vs2.3.6.11/arch/s390/kernel/ptrace.c 2014-01-31 20:38:03.000000000 +0000
576 #include <linux/tracehook.h>
577 #include <linux/seccomp.h>
578 #include <linux/compat.h>
579 +#include <linux/vs_base.h>
580 #include <trace/syscall.h>
581 #include <asm/segment.h>
582 #include <asm/page.h>
583 diff -NurpP --minimal linux-3.13.6/arch/s390/kernel/syscalls.S linux-3.13.6-vs2.3.6.11/arch/s390/kernel/syscalls.S
584 --- linux-3.13.6/arch/s390/kernel/syscalls.S 2013-07-14 17:00:34.000000000 +0000
585 +++ linux-3.13.6-vs2.3.6.11/arch/s390/kernel/syscalls.S 2014-01-31 20:38:03.000000000 +0000
586 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
587 SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper) /* 260 */
588 SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
589 SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
590 -NI_SYSCALL /* reserved for vserver */
591 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
592 SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
593 SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
594 SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
595 diff -NurpP --minimal linux-3.13.6/arch/sh/Kconfig linux-3.13.6-vs2.3.6.11/arch/sh/Kconfig
596 --- linux-3.13.6/arch/sh/Kconfig 2014-01-22 20:38:24.000000000 +0000
597 +++ linux-3.13.6-vs2.3.6.11/arch/sh/Kconfig 2014-01-31 20:38:03.000000000 +0000
598 @@ -927,6 +927,8 @@ source "fs/Kconfig"
600 source "arch/sh/Kconfig.debug"
602 +source "kernel/vserver/Kconfig"
604 source "security/Kconfig"
606 source "crypto/Kconfig"
607 diff -NurpP --minimal linux-3.13.6/arch/sh/kernel/irq.c linux-3.13.6-vs2.3.6.11/arch/sh/kernel/irq.c
608 --- linux-3.13.6/arch/sh/kernel/irq.c 2014-01-22 20:38:24.000000000 +0000
609 +++ linux-3.13.6-vs2.3.6.11/arch/sh/kernel/irq.c 2014-01-31 20:38:03.000000000 +0000
611 #include <linux/ftrace.h>
612 #include <linux/delay.h>
613 #include <linux/ratelimit.h>
614 +// #include <linux/vs_context.h>
615 #include <asm/processor.h>
616 #include <asm/machvec.h>
617 #include <asm/uaccess.h>
618 diff -NurpP --minimal linux-3.13.6/arch/sparc/Kconfig linux-3.13.6-vs2.3.6.11/arch/sparc/Kconfig
619 --- linux-3.13.6/arch/sparc/Kconfig 2014-01-22 20:38:24.000000000 +0000
620 +++ linux-3.13.6-vs2.3.6.11/arch/sparc/Kconfig 2014-01-31 20:38:03.000000000 +0000
621 @@ -553,6 +553,8 @@ source "fs/Kconfig"
623 source "arch/sparc/Kconfig.debug"
625 +source "kernel/vserver/Kconfig"
627 source "security/Kconfig"
629 source "crypto/Kconfig"
630 diff -NurpP --minimal linux-3.13.6/arch/sparc/include/uapi/asm/unistd.h linux-3.13.6-vs2.3.6.11/arch/sparc/include/uapi/asm/unistd.h
631 --- linux-3.13.6/arch/sparc/include/uapi/asm/unistd.h 2013-02-19 13:57:17.000000000 +0000
632 +++ linux-3.13.6-vs2.3.6.11/arch/sparc/include/uapi/asm/unistd.h 2014-01-31 20:38:03.000000000 +0000
634 #define __NR_timer_getoverrun 264
635 #define __NR_timer_delete 265
636 #define __NR_timer_create 266
637 -/* #define __NR_vserver 267 Reserved for VSERVER */
638 +#define __NR_vserver 267
639 #define __NR_io_setup 268
640 #define __NR_io_destroy 269
641 #define __NR_io_submit 270
642 diff -NurpP --minimal linux-3.13.6/arch/sparc/kernel/systbls_32.S linux-3.13.6-vs2.3.6.11/arch/sparc/kernel/systbls_32.S
643 --- linux-3.13.6/arch/sparc/kernel/systbls_32.S 2013-05-31 13:44:48.000000000 +0000
644 +++ linux-3.13.6-vs2.3.6.11/arch/sparc/kernel/systbls_32.S 2014-01-31 20:38:03.000000000 +0000
645 @@ -70,7 +70,7 @@ sys_call_table:
646 /*250*/ .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
647 /*255*/ .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
648 /*260*/ .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
649 -/*265*/ .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
650 +/*265*/ .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
651 /*270*/ .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
652 /*275*/ .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
653 /*280*/ .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
654 diff -NurpP --minimal linux-3.13.6/arch/sparc/kernel/systbls_64.S linux-3.13.6-vs2.3.6.11/arch/sparc/kernel/systbls_64.S
655 --- linux-3.13.6/arch/sparc/kernel/systbls_64.S 2013-07-14 17:00:35.000000000 +0000
656 +++ linux-3.13.6-vs2.3.6.11/arch/sparc/kernel/systbls_64.S 2014-01-31 20:38:03.000000000 +0000
657 @@ -71,7 +71,7 @@ sys_call_table32:
658 /*250*/ .word sys_mremap, compat_sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
659 .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
660 /*260*/ .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
661 - .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
662 + .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
663 /*270*/ .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
664 .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
665 /*280*/ .word sys_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
666 @@ -149,7 +149,7 @@ sys_call_table:
667 /*250*/ .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
668 .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
669 /*260*/ .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
670 - .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
671 + .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
672 /*270*/ .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
673 .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
674 /*280*/ .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
675 diff -NurpP --minimal linux-3.13.6/arch/um/Kconfig.rest linux-3.13.6-vs2.3.6.11/arch/um/Kconfig.rest
676 --- linux-3.13.6/arch/um/Kconfig.rest 2012-12-11 03:30:57.000000000 +0000
677 +++ linux-3.13.6-vs2.3.6.11/arch/um/Kconfig.rest 2014-01-31 20:38:03.000000000 +0000
678 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
682 +source "kernel/vserver/Kconfig"
684 source "security/Kconfig"
686 source "crypto/Kconfig"
687 diff -NurpP --minimal linux-3.13.6/arch/x86/Kconfig linux-3.13.6-vs2.3.6.11/arch/x86/Kconfig
688 --- linux-3.13.6/arch/x86/Kconfig 2014-01-22 20:38:25.000000000 +0000
689 +++ linux-3.13.6-vs2.3.6.11/arch/x86/Kconfig 2014-01-31 20:38:03.000000000 +0000
690 @@ -2403,6 +2403,8 @@ source "fs/Kconfig"
692 source "arch/x86/Kconfig.debug"
694 +source "kernel/vserver/Kconfig"
696 source "security/Kconfig"
698 source "crypto/Kconfig"
699 diff -NurpP --minimal linux-3.13.6/arch/x86/syscalls/syscall_32.tbl linux-3.13.6-vs2.3.6.11/arch/x86/syscalls/syscall_32.tbl
700 --- linux-3.13.6/arch/x86/syscalls/syscall_32.tbl 2013-07-14 17:00:37.000000000 +0000
701 +++ linux-3.13.6-vs2.3.6.11/arch/x86/syscalls/syscall_32.tbl 2014-01-31 20:38:03.000000000 +0000
703 270 i386 tgkill sys_tgkill
704 271 i386 utimes sys_utimes compat_sys_utimes
705 272 i386 fadvise64_64 sys_fadvise64_64 sys32_fadvise64_64
707 +273 i386 vserver sys_vserver sys32_vserver
708 274 i386 mbind sys_mbind
709 275 i386 get_mempolicy sys_get_mempolicy compat_sys_get_mempolicy
710 276 i386 set_mempolicy sys_set_mempolicy
711 diff -NurpP --minimal linux-3.13.6/arch/x86/syscalls/syscall_64.tbl linux-3.13.6-vs2.3.6.11/arch/x86/syscalls/syscall_64.tbl
712 --- linux-3.13.6/arch/x86/syscalls/syscall_64.tbl 2013-05-31 13:44:50.000000000 +0000
713 +++ linux-3.13.6-vs2.3.6.11/arch/x86/syscalls/syscall_64.tbl 2014-01-31 20:38:03.000000000 +0000
715 233 common epoll_ctl sys_epoll_ctl
716 234 common tgkill sys_tgkill
717 235 common utimes sys_utimes
719 +236 64 vserver sys_vserver
720 237 common mbind sys_mbind
721 238 common set_mempolicy sys_set_mempolicy
722 239 common get_mempolicy sys_get_mempolicy
723 diff -NurpP --minimal linux-3.13.6/drivers/block/Kconfig linux-3.13.6-vs2.3.6.11/drivers/block/Kconfig
724 --- linux-3.13.6/drivers/block/Kconfig 2014-01-22 20:38:27.000000000 +0000
725 +++ linux-3.13.6-vs2.3.6.11/drivers/block/Kconfig 2014-01-31 20:38:03.000000000 +0000
726 @@ -281,6 +281,13 @@ config BLK_DEV_CRYPTOLOOP
728 source "drivers/block/drbd/Kconfig"
730 +config BLK_DEV_VROOT
731 + tristate "Virtual Root device support"
732 + depends on QUOTACTL
734 + Saying Y here will allow you to use quota/fs ioctls on a shared
735 + partition within a virtual server without compromising security.
738 tristate "Network block device support"
740 diff -NurpP --minimal linux-3.13.6/drivers/block/Makefile linux-3.13.6-vs2.3.6.11/drivers/block/Makefile
741 --- linux-3.13.6/drivers/block/Makefile 2014-01-22 20:38:27.000000000 +0000
742 +++ linux-3.13.6-vs2.3.6.11/drivers/block/Makefile 2014-01-31 20:38:03.000000000 +0000
743 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
744 obj-$(CONFIG_VIODASD) += viodasd.o
745 obj-$(CONFIG_BLK_DEV_SX8) += sx8.o
746 obj-$(CONFIG_BLK_DEV_HD) += hd.o
747 +obj-$(CONFIG_BLK_DEV_VROOT) += vroot.o
749 obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o
750 obj-$(CONFIG_XEN_BLKDEV_BACKEND) += xen-blkback/
751 diff -NurpP --minimal linux-3.13.6/drivers/block/loop.c linux-3.13.6-vs2.3.6.11/drivers/block/loop.c
752 --- linux-3.13.6/drivers/block/loop.c 2014-01-22 20:38:27.000000000 +0000
753 +++ linux-3.13.6-vs2.3.6.11/drivers/block/loop.c 2014-01-31 20:55:14.000000000 +0000
755 #include <linux/sysfs.h>
756 #include <linux/miscdevice.h>
757 #include <linux/falloc.h>
758 +#include <linux/vs_context.h>
761 #include <asm/uaccess.h>
762 @@ -884,6 +885,7 @@ static int loop_set_fd(struct loop_devic
763 lo->lo_blocksize = lo_blocksize;
764 lo->lo_device = bdev;
765 lo->lo_flags = lo_flags;
766 + lo->lo_xid = vx_current_xid();
767 lo->lo_backing_file = file;
768 lo->transfer = transfer_none;
770 @@ -1028,6 +1030,7 @@ static int loop_clr_fd(struct loop_devic
771 lo->lo_sizelimit = 0;
772 lo->lo_encrypt_key_size = 0;
773 lo->lo_thread = NULL;
775 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
776 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
777 memset(lo->lo_file_name, 0, LO_NAME_SIZE);
778 @@ -1071,7 +1074,7 @@ loop_set_status(struct loop_device *lo,
780 if (lo->lo_encrypt_key_size &&
781 !uid_eq(lo->lo_key_owner, uid) &&
782 - !capable(CAP_SYS_ADMIN))
783 + !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
785 if (lo->lo_state != Lo_bound)
787 @@ -1161,7 +1164,8 @@ loop_get_status(struct loop_device *lo,
788 memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
789 info->lo_encrypt_type =
790 lo->lo_encryption ? lo->lo_encryption->number : 0;
791 - if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
792 + if (lo->lo_encrypt_key_size &&
793 + vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
794 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
795 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
796 lo->lo_encrypt_key_size);
797 @@ -1503,6 +1507,11 @@ static int lo_open(struct block_device *
801 + if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
806 mutex_lock(&lo->lo_ctl_mutex);
808 mutex_unlock(&lo->lo_ctl_mutex);
809 diff -NurpP --minimal linux-3.13.6/drivers/block/loop.h linux-3.13.6-vs2.3.6.11/drivers/block/loop.h
810 --- linux-3.13.6/drivers/block/loop.h 2013-11-25 15:44:28.000000000 +0000
811 +++ linux-3.13.6-vs2.3.6.11/drivers/block/loop.h 2014-02-01 01:57:49.000000000 +0000
812 @@ -41,6 +41,7 @@ struct loop_device {
813 struct loop_func_table *lo_encryption;
815 kuid_t lo_key_owner; /* Who set the key */
817 int (*ioctl)(struct loop_device *, int cmd,
820 diff -NurpP --minimal linux-3.13.6/drivers/block/vroot.c linux-3.13.6-vs2.3.6.11/drivers/block/vroot.c
821 --- linux-3.13.6/drivers/block/vroot.c 1970-01-01 00:00:00.000000000 +0000
822 +++ linux-3.13.6-vs2.3.6.11/drivers/block/vroot.c 2014-01-31 20:38:03.000000000 +0000
825 + * linux/drivers/block/vroot.c
827 + * written by Herbert Pötzl, 9/11/2002
828 + * ported to 2.6.10 by Herbert Pötzl, 30/12/2004
830 + * based on the loop.c code by Theodore Ts'o.
832 + * Copyright (C) 2002-2007 by Herbert Pötzl.
833 + * Redistribution of this file is permitted under the
834 + * GNU General Public License.
838 +#include <linux/module.h>
839 +#include <linux/moduleparam.h>
840 +#include <linux/file.h>
841 +#include <linux/major.h>
842 +#include <linux/blkdev.h>
843 +#include <linux/slab.h>
845 +#include <linux/vroot.h>
846 +#include <linux/vs_context.h>
849 +static int max_vroot = 8;
851 +static struct vroot_device *vroot_dev;
852 +static struct gendisk **disks;
855 +static int vroot_set_dev(
856 + struct vroot_device *vr,
857 + struct block_device *bdev,
860 + struct block_device *real_bdev;
862 + struct inode *inode;
866 + if (vr->vr_state != Vr_unbound)
875 + inode = file->f_dentry->d_inode;
878 + if (S_ISBLK(inode->i_mode)) {
879 + real_bdev = inode->i_bdev;
880 + vr->vr_device = real_bdev;
881 + __iget(real_bdev->bd_inode);
885 + vxdprintk(VXD_CBIT(misc, 0),
886 + "vroot[%d]_set_dev: dev=" VXF_DEV,
887 + vr->vr_number, VXD_DEV(real_bdev));
889 + vr->vr_state = Vr_bound;
898 +static int vroot_clr_dev(
899 + struct vroot_device *vr,
900 + struct block_device *bdev)
902 + struct block_device *real_bdev;
904 + if (vr->vr_state != Vr_bound)
906 + if (vr->vr_refcnt > 1) /* we needed one fd for the ioctl */
909 + real_bdev = vr->vr_device;
911 + vxdprintk(VXD_CBIT(misc, 0),
912 + "vroot[%d]_clr_dev: dev=" VXF_DEV,
913 + vr->vr_number, VXD_DEV(real_bdev));
916 + vr->vr_state = Vr_unbound;
917 + vr->vr_device = NULL;
922 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
923 + unsigned int cmd, unsigned long arg)
925 + struct vroot_device *vr = bdev->bd_disk->private_data;
928 + down(&vr->vr_ctl_mutex);
930 + case VROOT_SET_DEV:
931 + err = vroot_set_dev(vr, bdev, arg);
933 + case VROOT_CLR_DEV:
934 + err = vroot_clr_dev(vr, bdev);
940 + up(&vr->vr_ctl_mutex);
944 +static int vr_open(struct block_device *bdev, fmode_t mode)
946 + struct vroot_device *vr = bdev->bd_disk->private_data;
948 + down(&vr->vr_ctl_mutex);
950 + up(&vr->vr_ctl_mutex);
954 +static void vr_release(struct gendisk *disk, fmode_t mode)
956 + struct vroot_device *vr = disk->private_data;
958 + down(&vr->vr_ctl_mutex);
960 + up(&vr->vr_ctl_mutex);
963 +static struct block_device_operations vr_fops = {
964 + .owner = THIS_MODULE,
966 + .release = vr_release,
970 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
972 + printk("vroot_make_request %p, %p\n", q, bio);
976 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
978 + struct inode *inode = bdev->bd_inode;
979 + struct vroot_device *vr;
980 + struct block_device *real_bdev;
981 + int minor = iminor(inode);
983 + vr = &vroot_dev[minor];
984 + real_bdev = vr->vr_device;
986 + vxdprintk(VXD_CBIT(misc, 0),
987 + "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
988 + vr->vr_number, VXD_DEV(real_bdev));
990 + if (vr->vr_state != Vr_bound)
991 + return ERR_PTR(-ENXIO);
993 + __iget(real_bdev->bd_inode);
1000 + * And now the modules code and kernel interface.
1003 +module_param(max_vroot, int, 0);
1005 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1006 +MODULE_LICENSE("GPL");
1007 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1009 +MODULE_AUTHOR ("Herbert Pötzl");
1010 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1013 +int __init vroot_init(void)
1017 + if (max_vroot < 1 || max_vroot > 256) {
1018 + max_vroot = MAX_VROOT_DEFAULT;
1019 + printk(KERN_WARNING "vroot: invalid max_vroot "
1020 + "(must be between 1 and 256), "
1021 + "using default (%d)\n", max_vroot);
1024 + if (register_blkdev(VROOT_MAJOR, "vroot"))
1028 + vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1031 + memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1033 + disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1037 + for (i = 0; i < max_vroot; i++) {
1038 + disks[i] = alloc_disk(1);
1041 + disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1042 + if (!disks[i]->queue)
1044 + blk_queue_make_request(disks[i]->queue, vroot_make_request);
1047 + for (i = 0; i < max_vroot; i++) {
1048 + struct vroot_device *vr = &vroot_dev[i];
1049 + struct gendisk *disk = disks[i];
1051 + memset(vr, 0, sizeof(*vr));
1052 + sema_init(&vr->vr_ctl_mutex, 1);
1053 + vr->vr_number = i;
1054 + disk->major = VROOT_MAJOR;
1055 + disk->first_minor = i;
1056 + disk->fops = &vr_fops;
1057 + sprintf(disk->disk_name, "vroot%d", i);
1058 + disk->private_data = vr;
1061 + err = register_vroot_grb(&__vroot_get_real_bdev);
1065 + for (i = 0; i < max_vroot; i++)
1066 + add_disk(disks[i]);
1067 + printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1072 + put_disk(disks[i]);
1077 + unregister_blkdev(VROOT_MAJOR, "vroot");
1078 + printk(KERN_ERR "vroot: ran out of memory\n");
1082 +void vroot_exit(void)
1086 + if (unregister_vroot_grb(&__vroot_get_real_bdev))
1087 + printk(KERN_WARNING "vroot: cannot unregister grb\n");
1089 + for (i = 0; i < max_vroot; i++) {
1090 + del_gendisk(disks[i]);
1091 + put_disk(disks[i]);
1093 + unregister_blkdev(VROOT_MAJOR, "vroot");
1099 +module_init(vroot_init);
1100 +module_exit(vroot_exit);
1104 +static int __init max_vroot_setup(char *str)
1106 + max_vroot = simple_strtol(str, NULL, 0);
1110 +__setup("max_vroot=", max_vroot_setup);
1114 diff -NurpP --minimal linux-3.13.6/drivers/infiniband/Kconfig linux-3.13.6-vs2.3.6.11/drivers/infiniband/Kconfig
1115 --- linux-3.13.6/drivers/infiniband/Kconfig 2014-01-22 20:38:35.000000000 +0000
1116 +++ linux-3.13.6-vs2.3.6.11/drivers/infiniband/Kconfig 2014-01-31 20:38:03.000000000 +0000
1117 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1118 config INFINIBAND_ADDR_TRANS
1121 - depends on !(INFINIBAND = y && IPV6 = m)
1122 + depends on !(INFINIBAND = y && IPV6 = y)
1125 source "drivers/infiniband/hw/mthca/Kconfig"
1126 diff -NurpP --minimal linux-3.13.6/drivers/infiniband/core/addr.c linux-3.13.6-vs2.3.6.11/drivers/infiniband/core/addr.c
1127 --- linux-3.13.6/drivers/infiniband/core/addr.c 2013-11-25 15:44:35.000000000 +0000
1128 +++ linux-3.13.6-vs2.3.6.11/drivers/infiniband/core/addr.c 2014-01-31 20:38:03.000000000 +0000
1129 @@ -277,7 +277,7 @@ static int addr6_resolve(struct sockaddr
1131 if (ipv6_addr_any(&fl6.saddr)) {
1132 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1133 - &fl6.daddr, 0, &fl6.saddr);
1134 + &fl6.daddr, 0, &fl6.saddr, NULL);
1138 diff -NurpP --minimal linux-3.13.6/drivers/md/dm-ioctl.c linux-3.13.6-vs2.3.6.11/drivers/md/dm-ioctl.c
1139 --- linux-3.13.6/drivers/md/dm-ioctl.c 2014-01-22 20:38:36.000000000 +0000
1140 +++ linux-3.13.6-vs2.3.6.11/drivers/md/dm-ioctl.c 2014-01-31 21:01:49.000000000 +0000
1142 #include <linux/dm-ioctl.h>
1143 #include <linux/hdreg.h>
1144 #include <linux/compat.h>
1145 +#include <linux/vs_context.h>
1147 #include <asm/uaccess.h>
1149 @@ -114,7 +115,8 @@ static struct hash_cell *__get_name_cell
1150 unsigned int h = hash_str(str);
1152 list_for_each_entry (hc, _name_buckets + h, name_list)
1153 - if (!strcmp(hc->name, str)) {
1154 + if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1155 + !strcmp(hc->name, str)) {
1159 @@ -128,7 +130,8 @@ static struct hash_cell *__get_uuid_cell
1160 unsigned int h = hash_str(str);
1162 list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1163 - if (!strcmp(hc->uuid, str)) {
1164 + if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1165 + !strcmp(hc->uuid, str)) {
1169 @@ -139,13 +142,15 @@ static struct hash_cell *__get_uuid_cell
1170 static struct hash_cell *__get_dev_cell(uint64_t dev)
1172 struct mapped_device *md;
1173 - struct hash_cell *hc;
1174 + struct hash_cell *hc = NULL;
1176 md = dm_get_md(huge_decode_dev(dev));
1180 - hc = dm_get_mdptr(md);
1181 + if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1182 + hc = dm_get_mdptr(md);
1187 @@ -467,6 +472,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1189 static int remove_all(struct dm_ioctl *param, size_t param_size)
1191 + if (!vx_check(0, VS_ADMIN))
1194 dm_hash_remove_all(true, !!(param->flags & DM_DEFERRED_REMOVE), false);
1195 param->data_size = 0;
1197 @@ -514,6 +522,8 @@ static int list_devices(struct dm_ioctl
1199 for (i = 0; i < NUM_BUCKETS; i++) {
1200 list_for_each_entry (hc, _name_buckets + i, name_list) {
1201 + if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1203 needed += sizeof(struct dm_name_list);
1204 needed += strlen(hc->name) + 1;
1205 needed += ALIGN_MASK;
1206 @@ -537,6 +547,8 @@ static int list_devices(struct dm_ioctl
1208 for (i = 0; i < NUM_BUCKETS; i++) {
1209 list_for_each_entry (hc, _name_buckets + i, name_list) {
1210 + if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1213 old_nl->next = (uint32_t) ((void *) nl -
1215 @@ -1797,8 +1809,8 @@ static int ctl_ioctl(uint command, struc
1216 size_t input_param_size;
1217 struct dm_ioctl param_kernel;
1219 - /* only root can play with this */
1220 - if (!capable(CAP_SYS_ADMIN))
1221 + /* only root and certain contexts can play with this */
1222 + if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1225 if (_IOC_TYPE(command) != DM_IOCTL)
1226 diff -NurpP --minimal linux-3.13.6/drivers/md/dm.c linux-3.13.6-vs2.3.6.11/drivers/md/dm.c
1227 --- linux-3.13.6/drivers/md/dm.c 2014-03-12 13:51:16.000000000 +0000
1228 +++ linux-3.13.6-vs2.3.6.11/drivers/md/dm.c 2014-02-25 11:26:09.000000000 +0000
1230 #include <linux/idr.h>
1231 #include <linux/hdreg.h>
1232 #include <linux/delay.h>
1233 +#include <linux/vs_base.h>
1235 #include <trace/events/block.h>
1237 @@ -139,6 +140,7 @@ struct mapped_device {
1238 struct mutex suspend_lock;
1240 atomic_t open_count;
1244 * The current mapping.
1245 @@ -384,6 +386,7 @@ int dm_deleting_md(struct mapped_device
1246 static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1248 struct mapped_device *md;
1251 spin_lock(&_minor_lock);
1253 @@ -392,18 +395,19 @@ static int dm_blk_open(struct block_devi
1256 if (test_bit(DMF_FREEING, &md->flags) ||
1257 - dm_deleting_md(md)) {
1259 + dm_deleting_md(md))
1263 + if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1268 atomic_inc(&md->open_count);
1272 spin_unlock(&_minor_lock);
1274 - return md ? 0 : -ENXIO;
1278 static void dm_blk_close(struct gendisk *disk, fmode_t mode)
1279 @@ -687,6 +691,14 @@ int dm_set_geometry(struct mapped_device
1284 + * Get the xid associated with a dm device
1286 +vxid_t dm_get_xid(struct mapped_device *md)
1291 /*-----------------------------------------------------------------
1293 * A more elegant soln is in the works that uses the queue
1294 @@ -2026,6 +2038,7 @@ static struct mapped_device *alloc_dev(i
1295 INIT_LIST_HEAD(&md->uevent_list);
1296 spin_lock_init(&md->uevent_lock);
1298 + md->xid = vx_current_xid();
1299 md->queue = blk_alloc_queue(GFP_KERNEL);
1302 diff -NurpP --minimal linux-3.13.6/drivers/md/dm.h linux-3.13.6-vs2.3.6.11/drivers/md/dm.h
1303 --- linux-3.13.6/drivers/md/dm.h 2014-03-12 13:51:16.000000000 +0000
1304 +++ linux-3.13.6-vs2.3.6.11/drivers/md/dm.h 2014-02-25 11:26:09.000000000 +0000
1305 @@ -50,6 +50,8 @@ struct dm_dev_internal {
1307 struct dm_md_mempools;
1309 +vxid_t dm_get_xid(struct mapped_device *md);
1311 /*-----------------------------------------------------------------
1312 * Internal table functions.
1313 *---------------------------------------------------------------*/
1314 diff -NurpP --minimal linux-3.13.6/drivers/net/tun.c linux-3.13.6-vs2.3.6.11/drivers/net/tun.c
1315 --- linux-3.13.6/drivers/net/tun.c 2014-01-22 20:38:45.000000000 +0000
1316 +++ linux-3.13.6-vs2.3.6.11/drivers/net/tun.c 2014-01-31 20:38:03.000000000 +0000
1318 #include <linux/nsproxy.h>
1319 #include <linux/virtio_net.h>
1320 #include <linux/rcupdate.h>
1321 +#include <linux/vs_network.h>
1322 #include <net/net_namespace.h>
1323 #include <net/netns/generic.h>
1324 #include <net/rtnetlink.h>
1325 @@ -168,6 +169,7 @@ struct tun_struct {
1331 struct net_device *dev;
1332 netdev_features_t set_features;
1333 @@ -385,6 +387,7 @@ static inline bool tun_not_capable(struc
1334 return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1335 (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1336 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1337 + /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1340 static void tun_set_real_num_queues(struct tun_struct *tun)
1341 @@ -1382,6 +1385,7 @@ static void tun_setup(struct net_device
1343 tun->owner = INVALID_UID;
1344 tun->group = INVALID_GID;
1345 + tun->nid = nx_current_nid();
1347 dev->ethtool_ops = &tun_ethtool_ops;
1348 dev->destructor = tun_free_netdev;
1349 @@ -1598,7 +1602,7 @@ static int tun_set_iff(struct net *net,
1350 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1353 - if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1354 + if (!nx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1356 err = security_tun_dev_create();
1358 @@ -1967,6 +1971,16 @@ static long __tun_chr_ioctl(struct file
1359 from_kgid(&init_user_ns, tun->group));
1363 + if (!capable(CAP_CONTEXT))
1366 + /* Set nid owner of the device */
1367 + tun->nid = (vnid_t) arg;
1369 + tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1373 /* Only allow setting the type when the interface is down */
1374 if (tun->dev->flags & IFF_UP) {
1375 diff -NurpP --minimal linux-3.13.6/drivers/tty/sysrq.c linux-3.13.6-vs2.3.6.11/drivers/tty/sysrq.c
1376 --- linux-3.13.6/drivers/tty/sysrq.c 2014-01-22 20:39:02.000000000 +0000
1377 +++ linux-3.13.6-vs2.3.6.11/drivers/tty/sysrq.c 2014-01-31 20:55:49.000000000 +0000
1379 #include <linux/jiffies.h>
1380 #include <linux/syscalls.h>
1381 #include <linux/of.h>
1382 +#include <linux/vserver/debug.h>
1384 #include <asm/ptrace.h>
1385 #include <asm/irq_regs.h>
1386 @@ -407,6 +408,21 @@ static struct sysrq_key_op sysrq_unrt_op
1387 .enable_mask = SYSRQ_ENABLE_RTNICE,
1391 +#ifdef CONFIG_VSERVER_DEBUG
1392 +static void sysrq_handle_vxinfo(int key)
1394 + dump_vx_info_inactive((key == 'x') ? 0 : 1);
1397 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1398 + .handler = sysrq_handle_vxinfo,
1399 + .help_msg = "conteXt",
1400 + .action_msg = "Show Context Info",
1401 + .enable_mask = SYSRQ_ENABLE_DUMP,
1405 /* Key Operations table and lock */
1406 static DEFINE_SPINLOCK(sysrq_key_table_lock);
1408 @@ -462,7 +478,11 @@ static struct sysrq_key_op *sysrq_key_ta
1409 &sysrq_showstate_blocked_op, /* w */
1410 /* x: May be registered on ppc/powerpc for xmon */
1411 /* x: May be registered on sparc64 for global PMU dump */
1412 +#ifdef CONFIG_VSERVER_DEBUG
1413 + &sysrq_showvxinfo_op, /* x */
1417 /* y: May be registered on sparc64 for global register dump */
1419 &sysrq_ftrace_dump_op, /* z */
1420 @@ -477,6 +497,8 @@ static int sysrq_key_table_key2index(int
1422 else if ((key >= 'a') && (key <= 'z'))
1423 retval = key + 10 - 'a';
1424 + else if ((key >= 'A') && (key <= 'Z'))
1425 + retval = key + 10 - 'A';
1429 diff -NurpP --minimal linux-3.13.6/drivers/tty/tty_io.c linux-3.13.6-vs2.3.6.11/drivers/tty/tty_io.c
1430 --- linux-3.13.6/drivers/tty/tty_io.c 2014-01-22 20:39:02.000000000 +0000
1431 +++ linux-3.13.6-vs2.3.6.11/drivers/tty/tty_io.c 2014-01-31 20:38:03.000000000 +0000
1434 #include <linux/kmod.h>
1435 #include <linux/nsproxy.h>
1436 +#include <linux/vs_pid.h>
1438 #undef TTY_DEBUG_HANGUP
1440 @@ -2218,7 +2219,8 @@ static int tiocsti(struct tty_struct *tt
1442 struct tty_ldisc *ld;
1444 - if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1445 + if (((current->signal->tty != tty) &&
1446 + !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1448 if (get_user(ch, p))
1450 @@ -2506,6 +2508,7 @@ static int tiocspgrp(struct tty_struct *
1452 if (get_user(pgrp_nr, p))
1454 + pgrp_nr = vx_rmap_pid(pgrp_nr);
1458 diff -NurpP --minimal linux-3.13.6/fs/attr.c linux-3.13.6-vs2.3.6.11/fs/attr.c
1459 --- linux-3.13.6/fs/attr.c 2014-03-12 13:51:19.000000000 +0000
1460 +++ linux-3.13.6-vs2.3.6.11/fs/attr.c 2014-03-12 15:51:07.000000000 +0000
1462 #include <linux/security.h>
1463 #include <linux/evm.h>
1464 #include <linux/ima.h>
1465 +#include <linux/proc_fs.h>
1466 +#include <linux/devpts_fs.h>
1467 +#include <linux/vs_tag.h>
1470 * inode_change_ok - check if attribute changes to an inode are allowed
1471 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1475 + /* check for inode tag permission */
1476 + if (dx_permission(inode, MAY_WRITE))
1481 EXPORT_SYMBOL(inode_change_ok);
1482 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1483 inode->i_uid = attr->ia_uid;
1484 if (ia_valid & ATTR_GID)
1485 inode->i_gid = attr->ia_gid;
1486 + if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1487 + inode->i_tag = attr->ia_tag;
1488 if (ia_valid & ATTR_ATIME)
1489 inode->i_atime = timespec_trunc(attr->ia_atime,
1490 inode->i_sb->s_time_gran);
1491 @@ -197,7 +206,8 @@ int notify_change(struct dentry * dentry
1493 WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1495 - if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1496 + if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1497 + ATTR_TAG | ATTR_TIMES_SET)) {
1498 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1501 diff -NurpP --minimal linux-3.13.6/fs/block_dev.c linux-3.13.6-vs2.3.6.11/fs/block_dev.c
1502 --- linux-3.13.6/fs/block_dev.c 2013-11-25 15:46:58.000000000 +0000
1503 +++ linux-3.13.6-vs2.3.6.11/fs/block_dev.c 2014-01-31 20:38:03.000000000 +0000
1505 #include <linux/log2.h>
1506 #include <linux/cleancache.h>
1507 #include <linux/aio.h>
1508 +#include <linux/vs_device.h>
1509 #include <asm/uaccess.h>
1510 #include "internal.h"
1512 @@ -515,6 +516,7 @@ struct block_device *bdget(dev_t dev)
1513 bdev->bd_invalidated = 0;
1514 inode->i_mode = S_IFBLK;
1515 inode->i_rdev = dev;
1516 + inode->i_mdev = dev;
1517 inode->i_bdev = bdev;
1518 inode->i_data.a_ops = &def_blk_aops;
1519 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1520 @@ -562,6 +564,11 @@ EXPORT_SYMBOL(bdput);
1521 static struct block_device *bd_acquire(struct inode *inode)
1523 struct block_device *bdev;
1526 + if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1528 + inode->i_mdev = mdev;
1530 spin_lock(&bdev_lock);
1531 bdev = inode->i_bdev;
1532 @@ -572,7 +579,7 @@ static struct block_device *bd_acquire(s
1534 spin_unlock(&bdev_lock);
1536 - bdev = bdget(inode->i_rdev);
1537 + bdev = bdget(mdev);
1539 spin_lock(&bdev_lock);
1540 if (!inode->i_bdev) {
1541 diff -NurpP --minimal linux-3.13.6/fs/btrfs/ctree.h linux-3.13.6-vs2.3.6.11/fs/btrfs/ctree.h
1542 --- linux-3.13.6/fs/btrfs/ctree.h 2014-01-22 20:39:05.000000000 +0000
1543 +++ linux-3.13.6-vs2.3.6.11/fs/btrfs/ctree.h 2014-01-31 23:58:35.000000000 +0000
1544 @@ -718,11 +718,14 @@ struct btrfs_inode_item {
1545 /* modification sequence number for NFS */
1550 * a little future expansion, for more than this we can
1551 * just grow the inode item and version it
1553 - __le64 reserved[4];
1554 + __le16 reserved16;
1555 + __le32 reserved32;
1556 + __le64 reserved[3];
1557 struct btrfs_timespec atime;
1558 struct btrfs_timespec ctime;
1559 struct btrfs_timespec mtime;
1560 @@ -2000,6 +2003,8 @@ struct btrfs_ioctl_defrag_range_args {
1562 #define BTRFS_DEFAULT_COMMIT_INTERVAL (30)
1564 +#define BTRFS_MOUNT_TAGGED (1 << 24)
1566 #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
1567 #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
1568 #define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt)
1569 @@ -2269,6 +2274,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1570 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1571 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1572 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1573 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1574 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1575 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1576 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1577 @@ -2341,6 +2347,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1579 BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1581 +#define BTRFS_INODE_IXUNLINK (1 << 24)
1582 +#define BTRFS_INODE_BARRIER (1 << 25)
1583 +#define BTRFS_INODE_COW (1 << 26)
1586 BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1588 @@ -3722,6 +3732,7 @@ long btrfs_ioctl(struct file *file, unsi
1589 void btrfs_update_iflags(struct inode *inode);
1590 void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1591 int btrfs_is_empty_uuid(u8 *uuid);
1592 +int btrfs_sync_flags(struct inode *inode, int, int);
1593 int btrfs_defrag_file(struct inode *inode, struct file *file,
1594 struct btrfs_ioctl_defrag_range_args *range,
1595 u64 newer_than, unsigned long max_pages);
1596 diff -NurpP --minimal linux-3.13.6/fs/btrfs/disk-io.c linux-3.13.6-vs2.3.6.11/fs/btrfs/disk-io.c
1597 --- linux-3.13.6/fs/btrfs/disk-io.c 2014-01-22 20:39:05.000000000 +0000
1598 +++ linux-3.13.6-vs2.3.6.11/fs/btrfs/disk-io.c 2014-01-31 20:38:03.000000000 +0000
1599 @@ -2388,6 +2388,9 @@ int open_ctree(struct super_block *sb,
1603 + if (btrfs_test_opt(tree_root, TAGGED))
1604 + sb->s_flags |= MS_TAGGED;
1606 features = btrfs_super_incompat_flags(disk_super) &
1607 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1609 diff -NurpP --minimal linux-3.13.6/fs/btrfs/inode.c linux-3.13.6-vs2.3.6.11/fs/btrfs/inode.c
1610 --- linux-3.13.6/fs/btrfs/inode.c 2014-03-12 13:51:20.000000000 +0000
1611 +++ linux-3.13.6-vs2.3.6.11/fs/btrfs/inode.c 2014-03-12 15:51:07.000000000 +0000
1613 #include <linux/btrfs.h>
1614 #include <linux/blkdev.h>
1615 #include <linux/posix_acl_xattr.h>
1616 +#include <linux/vs_tag.h>
1618 #include "disk-io.h"
1619 #include "transaction.h"
1620 @@ -3317,6 +3318,9 @@ static void btrfs_read_locked_inode(stru
1621 struct btrfs_key location;
1628 bool filled = false;
1630 @@ -3344,8 +3348,14 @@ static void btrfs_read_locked_inode(stru
1631 struct btrfs_inode_item);
1632 inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1633 set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1634 - i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1635 - i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1637 + kuid = make_kuid(&init_user_ns, btrfs_inode_uid(leaf, inode_item));
1638 + kgid = make_kgid(&init_user_ns, btrfs_inode_gid(leaf, inode_item));
1639 + ktag = make_ktag(&init_user_ns, btrfs_inode_tag(leaf, inode_item));
1641 + inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
1642 + inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
1643 + inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
1644 btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1646 tspec = btrfs_inode_atime(inode_item);
1647 @@ -3436,11 +3446,18 @@ static void fill_inode_item(struct btrfs
1648 struct inode *inode)
1650 struct btrfs_map_token token;
1651 + uid_t uid = from_kuid(&init_user_ns,
1652 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
1653 + gid_t gid = from_kgid(&init_user_ns,
1654 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
1656 btrfs_init_map_token(&token);
1658 - btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1659 - btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1660 + btrfs_set_token_inode_uid(leaf, item, uid, &token);
1661 + btrfs_set_token_inode_gid(leaf, item, gid, &token);
1662 +#ifdef CONFIG_TAGGING_INTERN
1663 + btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1665 btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1667 btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1668 @@ -8652,12 +8669,15 @@ static const struct inode_operations btr
1669 .listxattr = btrfs_listxattr,
1670 .removexattr = btrfs_removexattr,
1671 .permission = btrfs_permission,
1672 + .sync_flags = btrfs_sync_flags,
1673 .get_acl = btrfs_get_acl,
1674 .update_time = btrfs_update_time,
1677 static const struct inode_operations btrfs_dir_ro_inode_operations = {
1678 .lookup = btrfs_lookup,
1679 .permission = btrfs_permission,
1680 + .sync_flags = btrfs_sync_flags,
1681 .get_acl = btrfs_get_acl,
1682 .update_time = btrfs_update_time,
1684 @@ -8727,6 +8747,7 @@ static const struct inode_operations btr
1685 .removexattr = btrfs_removexattr,
1686 .permission = btrfs_permission,
1687 .fiemap = btrfs_fiemap,
1688 + .sync_flags = btrfs_sync_flags,
1689 .get_acl = btrfs_get_acl,
1690 .update_time = btrfs_update_time,
1692 diff -NurpP --minimal linux-3.13.6/fs/btrfs/ioctl.c linux-3.13.6-vs2.3.6.11/fs/btrfs/ioctl.c
1693 --- linux-3.13.6/fs/btrfs/ioctl.c 2014-03-12 13:51:20.000000000 +0000
1694 +++ linux-3.13.6-vs2.3.6.11/fs/btrfs/ioctl.c 2014-02-25 11:26:09.000000000 +0000
1695 @@ -78,10 +78,13 @@ static unsigned int btrfs_flags_to_ioctl
1697 unsigned int iflags = 0;
1699 - if (flags & BTRFS_INODE_SYNC)
1700 - iflags |= FS_SYNC_FL;
1701 if (flags & BTRFS_INODE_IMMUTABLE)
1702 iflags |= FS_IMMUTABLE_FL;
1703 + if (flags & BTRFS_INODE_IXUNLINK)
1704 + iflags |= FS_IXUNLINK_FL;
1706 + if (flags & BTRFS_INODE_SYNC)
1707 + iflags |= FS_SYNC_FL;
1708 if (flags & BTRFS_INODE_APPEND)
1709 iflags |= FS_APPEND_FL;
1710 if (flags & BTRFS_INODE_NODUMP)
1711 @@ -98,28 +101,78 @@ static unsigned int btrfs_flags_to_ioctl
1712 else if (flags & BTRFS_INODE_NOCOMPRESS)
1713 iflags |= FS_NOCOMP_FL;
1715 + if (flags & BTRFS_INODE_BARRIER)
1716 + iflags |= FS_BARRIER_FL;
1717 + if (flags & BTRFS_INODE_COW)
1718 + iflags |= FS_COW_FL;
1723 - * Update inode->i_flags based on the btrfs internal flags.
1724 + * Update inode->i_(v)flags based on the btrfs internal flags.
1726 void btrfs_update_iflags(struct inode *inode)
1728 struct btrfs_inode *ip = BTRFS_I(inode);
1730 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1731 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1732 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1734 - if (ip->flags & BTRFS_INODE_SYNC)
1735 - inode->i_flags |= S_SYNC;
1736 if (ip->flags & BTRFS_INODE_IMMUTABLE)
1737 inode->i_flags |= S_IMMUTABLE;
1738 + if (ip->flags & BTRFS_INODE_IXUNLINK)
1739 + inode->i_flags |= S_IXUNLINK;
1741 + if (ip->flags & BTRFS_INODE_SYNC)
1742 + inode->i_flags |= S_SYNC;
1743 if (ip->flags & BTRFS_INODE_APPEND)
1744 inode->i_flags |= S_APPEND;
1745 if (ip->flags & BTRFS_INODE_NOATIME)
1746 inode->i_flags |= S_NOATIME;
1747 if (ip->flags & BTRFS_INODE_DIRSYNC)
1748 inode->i_flags |= S_DIRSYNC;
1750 + inode->i_vflags &= ~(V_BARRIER | V_COW);
1752 + if (ip->flags & BTRFS_INODE_BARRIER)
1753 + inode->i_vflags |= V_BARRIER;
1754 + if (ip->flags & BTRFS_INODE_COW)
1755 + inode->i_vflags |= V_COW;
1759 + * Update btrfs internal flags from inode->i_(v)flags.
1761 +void btrfs_update_flags(struct inode *inode)
1763 + struct btrfs_inode *ip = BTRFS_I(inode);
1765 + unsigned int flags = inode->i_flags;
1766 + unsigned int vflags = inode->i_vflags;
1768 + ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1769 + BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1770 + BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1771 + BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1773 + if (flags & S_IMMUTABLE)
1774 + ip->flags |= BTRFS_INODE_IMMUTABLE;
1775 + if (flags & S_IXUNLINK)
1776 + ip->flags |= BTRFS_INODE_IXUNLINK;
1778 + if (flags & S_SYNC)
1779 + ip->flags |= BTRFS_INODE_SYNC;
1780 + if (flags & S_APPEND)
1781 + ip->flags |= BTRFS_INODE_APPEND;
1782 + if (flags & S_NOATIME)
1783 + ip->flags |= BTRFS_INODE_NOATIME;
1784 + if (flags & S_DIRSYNC)
1785 + ip->flags |= BTRFS_INODE_DIRSYNC;
1787 + if (vflags & V_BARRIER)
1788 + ip->flags |= BTRFS_INODE_BARRIER;
1789 + if (vflags & V_COW)
1790 + ip->flags |= BTRFS_INODE_COW;
1794 @@ -135,6 +188,7 @@ void btrfs_inherit_iflags(struct inode *
1797 flags = BTRFS_I(dir)->flags;
1798 + flags &= ~BTRFS_INODE_BARRIER;
1800 if (flags & BTRFS_INODE_NOCOMPRESS) {
1801 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1802 @@ -153,6 +207,30 @@ void btrfs_inherit_iflags(struct inode *
1803 btrfs_update_iflags(inode);
1806 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1808 + struct btrfs_inode *ip = BTRFS_I(inode);
1809 + struct btrfs_root *root = ip->root;
1810 + struct btrfs_trans_handle *trans;
1813 + trans = btrfs_join_transaction(root);
1816 + inode->i_flags = flags;
1817 + inode->i_vflags = vflags;
1818 + btrfs_update_flags(inode);
1820 + ret = btrfs_update_inode(trans, root, inode);
1823 + btrfs_update_iflags(inode);
1824 + inode->i_ctime = CURRENT_TIME;
1825 + btrfs_end_transaction(trans, root);
1830 static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1832 struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1833 @@ -215,21 +293,27 @@ static int btrfs_ioctl_setflags(struct f
1835 flags = btrfs_mask_flags(inode->i_mode, flags);
1836 oldflags = btrfs_flags_to_ioctl(ip->flags);
1837 - if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1838 + if ((flags ^ oldflags) & (FS_APPEND_FL |
1839 + FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1840 if (!capable(CAP_LINUX_IMMUTABLE)) {
1846 - if (flags & FS_SYNC_FL)
1847 - ip->flags |= BTRFS_INODE_SYNC;
1849 - ip->flags &= ~BTRFS_INODE_SYNC;
1850 if (flags & FS_IMMUTABLE_FL)
1851 ip->flags |= BTRFS_INODE_IMMUTABLE;
1853 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1854 + if (flags & FS_IXUNLINK_FL)
1855 + ip->flags |= BTRFS_INODE_IXUNLINK;
1857 + ip->flags &= ~BTRFS_INODE_IXUNLINK;
1859 + if (flags & FS_SYNC_FL)
1860 + ip->flags |= BTRFS_INODE_SYNC;
1862 + ip->flags &= ~BTRFS_INODE_SYNC;
1863 if (flags & FS_APPEND_FL)
1864 ip->flags |= BTRFS_INODE_APPEND;
1866 diff -NurpP --minimal linux-3.13.6/fs/btrfs/super.c linux-3.13.6-vs2.3.6.11/fs/btrfs/super.c
1867 --- linux-3.13.6/fs/btrfs/super.c 2014-01-22 20:39:05.000000000 +0000
1868 +++ linux-3.13.6-vs2.3.6.11/fs/btrfs/super.c 2014-01-31 23:58:08.000000000 +0000
1869 @@ -323,7 +323,7 @@ enum {
1870 Opt_check_integrity, Opt_check_integrity_including_extent_data,
1871 Opt_check_integrity_print_mask, Opt_fatal_errors, Opt_rescan_uuid_tree,
1872 Opt_commit_interval,
1874 + Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1877 static match_table_t tokens = {
1878 @@ -365,6 +365,9 @@ static match_table_t tokens = {
1879 {Opt_rescan_uuid_tree, "rescan_uuid_tree"},
1880 {Opt_fatal_errors, "fatal_errors=%s"},
1881 {Opt_commit_interval, "commit=%d"},
1883 + {Opt_notag, "notag"},
1884 + {Opt_tagid, "tagid=%u"},
1888 @@ -674,6 +677,22 @@ int btrfs_parse_options(struct btrfs_roo
1889 info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
1892 +#ifndef CONFIG_TAGGING_NONE
1894 + printk(KERN_INFO "btrfs: use tagging\n");
1895 + btrfs_set_opt(info->mount_opt, TAGGED);
1898 + printk(KERN_INFO "btrfs: disabled tagging\n");
1899 + btrfs_clear_opt(info->mount_opt, TAGGED);
1902 +#ifdef CONFIG_PROPAGATE
1905 + btrfs_set_opt(info->mount_opt, TAGGED);
1909 printk(KERN_INFO "btrfs: unrecognized mount option "
1911 @@ -1320,6 +1339,12 @@ static int btrfs_remount(struct super_bl
1912 btrfs_resize_thread_pool(fs_info,
1913 fs_info->thread_pool_size, old_thread_pool_size);
1915 + if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1916 + printk("btrfs: %s: tagging not permitted on remount.\n",
1921 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1924 diff -NurpP --minimal linux-3.13.6/fs/char_dev.c linux-3.13.6-vs2.3.6.11/fs/char_dev.c
1925 --- linux-3.13.6/fs/char_dev.c 2014-01-22 20:39:05.000000000 +0000
1926 +++ linux-3.13.6-vs2.3.6.11/fs/char_dev.c 2014-01-31 20:38:03.000000000 +0000
1928 #include <linux/mutex.h>
1929 #include <linux/backing-dev.h>
1930 #include <linux/tty.h>
1931 +#include <linux/vs_context.h>
1932 +#include <linux/vs_device.h>
1934 #include "internal.h"
1936 @@ -372,14 +374,21 @@ static int chrdev_open(struct inode *ino
1938 struct cdev *new = NULL;
1942 + if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
1944 + inode->i_mdev = mdev;
1946 spin_lock(&cdev_lock);
1949 struct kobject *kobj;
1952 spin_unlock(&cdev_lock);
1953 - kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
1955 + kobj = kobj_lookup(cdev_map, mdev, &idx);
1958 new = container_of(kobj, struct cdev, kobj);
1959 diff -NurpP --minimal linux-3.13.6/fs/dcache.c linux-3.13.6-vs2.3.6.11/fs/dcache.c
1960 --- linux-3.13.6/fs/dcache.c 2014-03-12 13:51:20.000000000 +0000
1961 +++ linux-3.13.6-vs2.3.6.11/fs/dcache.c 2014-02-25 11:26:09.000000000 +0000
1963 #include <linux/prefetch.h>
1964 #include <linux/ratelimit.h>
1965 #include <linux/list_lru.h>
1966 +#include <linux/vs_limit.h>
1967 #include "internal.h"
1970 @@ -640,6 +641,8 @@ int d_invalidate(struct dentry * dentry)
1971 spin_lock(&dentry->d_lock);
1974 + vx_dentry_dec(dentry);
1977 * Somebody else still using it?
1979 @@ -669,6 +672,7 @@ EXPORT_SYMBOL(d_invalidate);
1980 static inline void __dget_dlock(struct dentry *dentry)
1982 dentry->d_lockref.count++;
1983 + vx_dentry_inc(dentry);
1986 static inline void __dget(struct dentry *dentry)
1987 @@ -1483,6 +1487,9 @@ struct dentry *__d_alloc(struct super_bl
1988 struct dentry *dentry;
1991 + if (!vx_dentry_avail(1))
1994 dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
1997 @@ -1515,6 +1522,7 @@ struct dentry *__d_alloc(struct super_bl
1999 dentry->d_lockref.count = 1;
2000 dentry->d_flags = 0;
2001 + vx_dentry_inc(dentry);
2002 spin_lock_init(&dentry->d_lock);
2003 seqcount_init(&dentry->d_seq);
2004 dentry->d_inode = NULL;
2005 @@ -2278,6 +2286,7 @@ struct dentry *__d_lookup(const struct d
2008 dentry->d_lockref.count++;
2009 + vx_dentry_inc(dentry);
2011 spin_unlock(&dentry->d_lock);
2013 diff -NurpP --minimal linux-3.13.6/fs/devpts/inode.c linux-3.13.6-vs2.3.6.11/fs/devpts/inode.c
2014 --- linux-3.13.6/fs/devpts/inode.c 2014-01-22 20:39:06.000000000 +0000
2015 +++ linux-3.13.6-vs2.3.6.11/fs/devpts/inode.c 2014-02-01 01:40:53.000000000 +0000
2017 #include <linux/parser.h>
2018 #include <linux/fsnotify.h>
2019 #include <linux/seq_file.h>
2020 +#include <linux/vs_base.h>
2022 #define DEVPTS_DEFAULT_MODE 0600
2025 #define DEVPTS_DEFAULT_PTMX_MODE 0000
2026 #define PTMX_MINOR 2
2028 +static int devpts_permission(struct inode *inode, int mask)
2030 + int ret = -EACCES;
2032 + /* devpts is xid tagged */
2033 + if (vx_check((vxid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2034 + ret = generic_permission(inode, mask);
2038 +static struct inode_operations devpts_file_inode_operations = {
2039 + .permission = devpts_permission,
2044 * sysctl support for setting limits on the number of Unix98 ptys allocated.
2045 * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2046 @@ -345,6 +361,34 @@ static int devpts_show_options(struct se
2050 +static int devpts_filter(struct dentry *de)
2054 + /* devpts is xid tagged */
2055 + if (de && de->d_inode)
2056 + xid = (vxid_t)i_tag_read(de->d_inode);
2057 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2059 + vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2060 + de->d_name.len, de->d_name.name);
2062 + return vx_check(xid, VS_WATCH_P | VS_IDENT);
2065 +static int devpts_readdir(struct file * filp, struct dir_context *ctx)
2067 + return dcache_readdir_filter(filp, ctx, devpts_filter);
2070 +static struct file_operations devpts_dir_operations = {
2071 + .open = dcache_dir_open,
2072 + .release = dcache_dir_close,
2073 + .llseek = dcache_dir_lseek,
2074 + .read = generic_read_dir,
2075 + .iterate = devpts_readdir,
2078 static const struct super_operations devpts_sops = {
2079 .statfs = simple_statfs,
2080 .remount_fs = devpts_remount,
2081 @@ -388,8 +432,10 @@ devpts_fill_super(struct super_block *s,
2082 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2083 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2084 inode->i_op = &simple_dir_inode_operations;
2085 - inode->i_fop = &simple_dir_operations;
2086 + inode->i_fop = &devpts_dir_operations;
2087 set_nlink(inode, 2);
2088 + /* devpts is xid tagged */
2089 + i_tag_write(inode, (vtag_t)vx_current_xid());
2091 s->s_root = d_make_root(inode);
2093 @@ -593,6 +639,9 @@ struct inode *devpts_pty_new(struct inod
2094 inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2095 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2096 init_special_inode(inode, S_IFCHR|opts->mode, device);
2097 + /* devpts is xid tagged */
2098 + i_tag_write(inode, (vtag_t)vx_current_xid());
2099 + inode->i_op = &devpts_file_inode_operations;
2100 inode->i_private = priv;
2102 sprintf(s, "%d", index);
2103 diff -NurpP --minimal linux-3.13.6/fs/ext2/balloc.c linux-3.13.6-vs2.3.6.11/fs/ext2/balloc.c
2104 --- linux-3.13.6/fs/ext2/balloc.c 2013-05-31 13:45:23.000000000 +0000
2105 +++ linux-3.13.6-vs2.3.6.11/fs/ext2/balloc.c 2014-01-31 20:38:03.000000000 +0000
2106 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2108 end = EXT2_BLOCKS_PER_GROUP(sb);
2111 BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2114 diff -NurpP --minimal linux-3.13.6/fs/ext2/ext2.h linux-3.13.6-vs2.3.6.11/fs/ext2/ext2.h
2115 --- linux-3.13.6/fs/ext2/ext2.h 2012-12-11 03:30:57.000000000 +0000
2116 +++ linux-3.13.6-vs2.3.6.11/fs/ext2/ext2.h 2014-01-31 20:38:03.000000000 +0000
2117 @@ -244,8 +244,12 @@ struct ext2_group_desc
2118 #define EXT2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
2119 #define EXT2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
2120 #define EXT2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
2121 +#define EXT2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
2122 #define EXT2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
2124 +#define EXT2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
2125 +#define EXT2_COW_FL FS_COW_FL /* Copy on Write marker */
2127 #define EXT2_FL_USER_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
2128 #define EXT2_FL_USER_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
2130 @@ -329,7 +333,8 @@ struct ext2_inode {
2132 __le16 l_i_uid_high; /* these 2 fields */
2133 __le16 l_i_gid_high; /* were reserved2[0] */
2134 - __u32 l_i_reserved2;
2135 + __le16 l_i_tag; /* Context Tag */
2136 + __u16 l_i_reserved2;
2139 __u8 h_i_frag; /* Fragment number */
2140 @@ -357,6 +362,7 @@ struct ext2_inode {
2141 #define i_gid_low i_gid
2142 #define i_uid_high osd2.linux2.l_i_uid_high
2143 #define i_gid_high osd2.linux2.l_i_gid_high
2144 +#define i_raw_tag osd2.linux2.l_i_tag
2145 #define i_reserved2 osd2.linux2.l_i_reserved2
2148 @@ -384,6 +390,7 @@ struct ext2_inode {
2149 #define EXT2_MOUNT_USRQUOTA 0x020000 /* user quota */
2150 #define EXT2_MOUNT_GRPQUOTA 0x040000 /* group quota */
2151 #define EXT2_MOUNT_RESERVATION 0x080000 /* Preallocation */
2152 +#define EXT2_MOUNT_TAGGED (1<<24) /* Enable Context Tags */
2155 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
2156 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2157 extern void ext2_get_inode_flags(struct ext2_inode_info *);
2158 extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2159 u64 start, u64 len);
2160 +extern int ext2_sync_flags(struct inode *, int, int);
2163 extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2164 diff -NurpP --minimal linux-3.13.6/fs/ext2/file.c linux-3.13.6-vs2.3.6.11/fs/ext2/file.c
2165 --- linux-3.13.6/fs/ext2/file.c 2012-12-11 03:30:57.000000000 +0000
2166 +++ linux-3.13.6-vs2.3.6.11/fs/ext2/file.c 2014-01-31 20:38:03.000000000 +0000
2167 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2168 .setattr = ext2_setattr,
2169 .get_acl = ext2_get_acl,
2170 .fiemap = ext2_fiemap,
2171 + .sync_flags = ext2_sync_flags,
2173 diff -NurpP --minimal linux-3.13.6/fs/ext2/ialloc.c linux-3.13.6-vs2.3.6.11/fs/ext2/ialloc.c
2174 --- linux-3.13.6/fs/ext2/ialloc.c 2013-05-31 13:45:23.000000000 +0000
2175 +++ linux-3.13.6-vs2.3.6.11/fs/ext2/ialloc.c 2014-01-31 20:38:03.000000000 +0000
2177 #include <linux/backing-dev.h>
2178 #include <linux/buffer_head.h>
2179 #include <linux/random.h>
2180 +#include <linux/vs_tag.h>
2184 @@ -546,6 +547,7 @@ got:
2185 inode->i_mode = mode;
2186 inode->i_uid = current_fsuid();
2187 inode->i_gid = dir->i_gid;
2188 + i_tag_write(inode, dx_current_fstag(sb));
2190 inode_init_owner(inode, dir, mode);
2192 diff -NurpP --minimal linux-3.13.6/fs/ext2/inode.c linux-3.13.6-vs2.3.6.11/fs/ext2/inode.c
2193 --- linux-3.13.6/fs/ext2/inode.c 2014-01-22 20:39:06.000000000 +0000
2194 +++ linux-3.13.6-vs2.3.6.11/fs/ext2/inode.c 2014-01-31 20:38:03.000000000 +0000
2196 #include <linux/fiemap.h>
2197 #include <linux/namei.h>
2198 #include <linux/aio.h>
2199 +#include <linux/vs_tag.h>
2203 @@ -1182,7 +1183,7 @@ static void ext2_truncate_blocks(struct
2205 if (ext2_inode_is_fast_symlink(inode))
2207 - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2208 + if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2210 __ext2_truncate_blocks(inode, offset);
2212 @@ -1273,36 +1274,61 @@ void ext2_set_inode_flags(struct inode *
2214 unsigned int flags = EXT2_I(inode)->i_flags;
2216 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2217 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2218 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2221 + if (flags & EXT2_IMMUTABLE_FL)
2222 + inode->i_flags |= S_IMMUTABLE;
2223 + if (flags & EXT2_IXUNLINK_FL)
2224 + inode->i_flags |= S_IXUNLINK;
2226 if (flags & EXT2_SYNC_FL)
2227 inode->i_flags |= S_SYNC;
2228 if (flags & EXT2_APPEND_FL)
2229 inode->i_flags |= S_APPEND;
2230 - if (flags & EXT2_IMMUTABLE_FL)
2231 - inode->i_flags |= S_IMMUTABLE;
2232 if (flags & EXT2_NOATIME_FL)
2233 inode->i_flags |= S_NOATIME;
2234 if (flags & EXT2_DIRSYNC_FL)
2235 inode->i_flags |= S_DIRSYNC;
2237 + inode->i_vflags &= ~(V_BARRIER | V_COW);
2239 + if (flags & EXT2_BARRIER_FL)
2240 + inode->i_vflags |= V_BARRIER;
2241 + if (flags & EXT2_COW_FL)
2242 + inode->i_vflags |= V_COW;
2245 /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2246 void ext2_get_inode_flags(struct ext2_inode_info *ei)
2248 unsigned int flags = ei->vfs_inode.i_flags;
2249 + unsigned int vflags = ei->vfs_inode.i_vflags;
2251 + ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2252 + EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2253 + EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2254 + EXT2_BARRIER_FL | EXT2_COW_FL);
2256 + if (flags & S_IMMUTABLE)
2257 + ei->i_flags |= EXT2_IMMUTABLE_FL;
2258 + if (flags & S_IXUNLINK)
2259 + ei->i_flags |= EXT2_IXUNLINK_FL;
2261 - ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2262 - EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2264 ei->i_flags |= EXT2_SYNC_FL;
2265 if (flags & S_APPEND)
2266 ei->i_flags |= EXT2_APPEND_FL;
2267 - if (flags & S_IMMUTABLE)
2268 - ei->i_flags |= EXT2_IMMUTABLE_FL;
2269 if (flags & S_NOATIME)
2270 ei->i_flags |= EXT2_NOATIME_FL;
2271 if (flags & S_DIRSYNC)
2272 ei->i_flags |= EXT2_DIRSYNC_FL;
2274 + if (vflags & V_BARRIER)
2275 + ei->i_flags |= EXT2_BARRIER_FL;
2276 + if (vflags & V_COW)
2277 + ei->i_flags |= EXT2_COW_FL;
2280 struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2281 @@ -1338,8 +1364,10 @@ struct inode *ext2_iget (struct super_bl
2282 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2283 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2285 - i_uid_write(inode, i_uid);
2286 - i_gid_write(inode, i_gid);
2287 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2288 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2289 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2290 + le16_to_cpu(raw_inode->i_raw_tag)));
2291 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2292 inode->i_size = le32_to_cpu(raw_inode->i_size);
2293 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2294 @@ -1437,8 +1465,10 @@ static int __ext2_write_inode(struct ino
2295 struct ext2_inode_info *ei = EXT2_I(inode);
2296 struct super_block *sb = inode->i_sb;
2297 ino_t ino = inode->i_ino;
2298 - uid_t uid = i_uid_read(inode);
2299 - gid_t gid = i_gid_read(inode);
2300 + uid_t uid = from_kuid(&init_user_ns,
2301 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2302 + gid_t gid = from_kgid(&init_user_ns,
2303 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2304 struct buffer_head * bh;
2305 struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2307 @@ -1474,6 +1504,9 @@ static int __ext2_write_inode(struct ino
2308 raw_inode->i_uid_high = 0;
2309 raw_inode->i_gid_high = 0;
2311 +#ifdef CONFIG_TAGGING_INTERN
2312 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2314 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2315 raw_inode->i_size = cpu_to_le32(inode->i_size);
2316 raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2317 @@ -1554,7 +1587,8 @@ int ext2_setattr(struct dentry *dentry,
2318 if (is_quota_modification(inode, iattr))
2319 dquot_initialize(inode);
2320 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2321 - (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2322 + (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2323 + (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2324 error = dquot_transfer(inode, iattr);
2327 diff -NurpP --minimal linux-3.13.6/fs/ext2/ioctl.c linux-3.13.6-vs2.3.6.11/fs/ext2/ioctl.c
2328 --- linux-3.13.6/fs/ext2/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2329 +++ linux-3.13.6-vs2.3.6.11/fs/ext2/ioctl.c 2014-01-31 20:38:03.000000000 +0000
2331 #include <asm/uaccess.h>
2334 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2336 + inode->i_flags = flags;
2337 + inode->i_vflags = vflags;
2338 + ext2_get_inode_flags(EXT2_I(inode));
2339 + inode->i_ctime = CURRENT_TIME_SEC;
2340 + mark_inode_dirty(inode);
2344 long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2346 struct inode *inode = file_inode(filp);
2347 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2349 flags = ext2_mask_flags(inode->i_mode, flags);
2351 + if (IS_BARRIER(inode)) {
2352 + vxwprintk_task(1, "messing with the barrier.");
2356 mutex_lock(&inode->i_mutex);
2357 /* Is it quota file? Do not allow user to mess with it */
2358 if (IS_NOQUOTA(inode)) {
2359 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2361 * This test looks nicer. Thanks to Pauline Middelink
2363 - if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2364 + if ((oldflags & EXT2_IMMUTABLE_FL) ||
2365 + ((flags ^ oldflags) & (EXT2_APPEND_FL |
2366 + EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2367 if (!capable(CAP_LINUX_IMMUTABLE)) {
2368 mutex_unlock(&inode->i_mutex);
2370 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2374 - flags = flags & EXT2_FL_USER_MODIFIABLE;
2375 + flags &= EXT2_FL_USER_MODIFIABLE;
2376 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2377 ei->i_flags = flags;
2379 diff -NurpP --minimal linux-3.13.6/fs/ext2/namei.c linux-3.13.6-vs2.3.6.11/fs/ext2/namei.c
2380 --- linux-3.13.6/fs/ext2/namei.c 2013-11-25 15:45:01.000000000 +0000
2381 +++ linux-3.13.6-vs2.3.6.11/fs/ext2/namei.c 2014-01-31 20:38:03.000000000 +0000
2384 #include <linux/pagemap.h>
2385 #include <linux/quotaops.h>
2386 +#include <linux/vs_tag.h>
2390 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2391 (unsigned long) ino);
2392 return ERR_PTR(-EIO);
2394 + dx_propagate_tag(nd, inode);
2396 return d_splice_alias(inode, dentry);
2398 @@ -432,5 +434,6 @@ const struct inode_operations ext2_speci
2399 .removexattr = generic_removexattr,
2401 .setattr = ext2_setattr,
2402 + .sync_flags = ext2_sync_flags,
2403 .get_acl = ext2_get_acl,
2405 diff -NurpP --minimal linux-3.13.6/fs/ext2/super.c linux-3.13.6-vs2.3.6.11/fs/ext2/super.c
2406 --- linux-3.13.6/fs/ext2/super.c 2014-01-22 20:39:06.000000000 +0000
2407 +++ linux-3.13.6-vs2.3.6.11/fs/ext2/super.c 2014-01-31 20:38:03.000000000 +0000
2408 @@ -395,7 +395,8 @@ enum {
2409 Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2410 Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2411 Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2412 - Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2413 + Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2414 + Opt_tag, Opt_notag, Opt_tagid
2417 static const match_table_t tokens = {
2418 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2420 {Opt_noacl, "noacl"},
2423 + {Opt_notag, "notag"},
2424 + {Opt_tagid, "tagid=%u"},
2425 {Opt_grpquota, "grpquota"},
2426 {Opt_ignore, "noquota"},
2427 {Opt_quota, "quota"},
2428 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2430 set_opt (sbi->s_mount_opt, NO_UID32);
2432 +#ifndef CONFIG_TAGGING_NONE
2434 + set_opt (sbi->s_mount_opt, TAGGED);
2437 + clear_opt (sbi->s_mount_opt, TAGGED);
2440 +#ifdef CONFIG_PROPAGATE
2443 + set_opt (sbi->s_mount_opt, TAGGED);
2447 clear_opt (sbi->s_mount_opt, CHECK);
2449 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2450 if (!parse_options((char *) data, sb))
2453 + if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2454 + sb->s_flags |= MS_TAGGED;
2455 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2456 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2458 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2463 + if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2464 + !(sb->s_flags & MS_TAGGED)) {
2465 + printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2468 + goto restore_opts;
2471 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2472 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2473 diff -NurpP --minimal linux-3.13.6/fs/ext3/ext3.h linux-3.13.6-vs2.3.6.11/fs/ext3/ext3.h
2474 --- linux-3.13.6/fs/ext3/ext3.h 2012-12-11 03:30:57.000000000 +0000
2475 +++ linux-3.13.6-vs2.3.6.11/fs/ext3/ext3.h 2014-01-31 20:38:03.000000000 +0000
2476 @@ -151,10 +151,14 @@ struct ext3_group_desc
2477 #define EXT3_NOTAIL_FL 0x00008000 /* file tail should not be merged */
2478 #define EXT3_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
2479 #define EXT3_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
2480 +#define EXT3_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
2481 #define EXT3_RESERVED_FL 0x80000000 /* reserved for ext3 lib */
2483 -#define EXT3_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
2484 -#define EXT3_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
2485 +#define EXT3_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2486 +#define EXT3_COW_FL 0x20000000 /* Copy on Write marker */
2488 +#define EXT3_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
2489 +#define EXT3_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
2491 /* Flags that should be inherited by new inodes from their parent. */
2492 #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2493 @@ -290,7 +294,8 @@ struct ext3_inode {
2495 __le16 l_i_uid_high; /* these 2 fields */
2496 __le16 l_i_gid_high; /* were reserved2[0] */
2497 - __u32 l_i_reserved2;
2498 + __le16 l_i_tag; /* Context Tag */
2499 + __u16 l_i_reserved2;
2502 __u8 h_i_frag; /* Fragment number */
2503 @@ -320,6 +325,7 @@ struct ext3_inode {
2504 #define i_gid_low i_gid
2505 #define i_uid_high osd2.linux2.l_i_uid_high
2506 #define i_gid_high osd2.linux2.l_i_gid_high
2507 +#define i_raw_tag osd2.linux2.l_i_tag
2508 #define i_reserved2 osd2.linux2.l_i_reserved2
2511 @@ -364,6 +370,7 @@ struct ext3_inode {
2512 #define EXT3_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
2513 #define EXT3_MOUNT_DATA_ERR_ABORT 0x400000 /* Abort on file data write
2514 * error in ordered mode */
2515 +#define EXT3_MOUNT_TAGGED (1<<24) /* Enable Context Tags */
2517 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2518 #ifndef _LINUX_EXT2_FS_H
2519 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2520 extern void ext3_set_aops(struct inode *inode);
2521 extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2522 u64 start, u64 len);
2523 +extern int ext3_sync_flags(struct inode *, int, int);
2526 extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2527 diff -NurpP --minimal linux-3.13.6/fs/ext3/file.c linux-3.13.6-vs2.3.6.11/fs/ext3/file.c
2528 --- linux-3.13.6/fs/ext3/file.c 2012-12-11 03:30:57.000000000 +0000
2529 +++ linux-3.13.6-vs2.3.6.11/fs/ext3/file.c 2014-01-31 20:38:03.000000000 +0000
2530 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2532 .get_acl = ext3_get_acl,
2533 .fiemap = ext3_fiemap,
2534 + .sync_flags = ext3_sync_flags,
2537 diff -NurpP --minimal linux-3.13.6/fs/ext3/ialloc.c linux-3.13.6-vs2.3.6.11/fs/ext3/ialloc.c
2538 --- linux-3.13.6/fs/ext3/ialloc.c 2012-12-11 03:30:57.000000000 +0000
2539 +++ linux-3.13.6-vs2.3.6.11/fs/ext3/ialloc.c 2014-01-31 20:38:03.000000000 +0000
2542 #include <linux/quotaops.h>
2543 #include <linux/random.h>
2544 +#include <linux/vs_tag.h>
2548 @@ -469,6 +470,7 @@ got:
2549 inode->i_mode = mode;
2550 inode->i_uid = current_fsuid();
2551 inode->i_gid = dir->i_gid;
2552 + i_tag_write(inode, dx_current_fstag(sb));
2554 inode_init_owner(inode, dir, mode);
2556 diff -NurpP --minimal linux-3.13.6/fs/ext3/inode.c linux-3.13.6-vs2.3.6.11/fs/ext3/inode.c
2557 --- linux-3.13.6/fs/ext3/inode.c 2013-11-25 15:45:01.000000000 +0000
2558 +++ linux-3.13.6-vs2.3.6.11/fs/ext3/inode.c 2014-01-31 20:38:03.000000000 +0000
2560 #include <linux/mpage.h>
2561 #include <linux/namei.h>
2562 #include <linux/aio.h>
2563 +#include <linux/vs_tag.h>
2568 @@ -2855,36 +2857,60 @@ void ext3_set_inode_flags(struct inode *
2570 unsigned int flags = EXT3_I(inode)->i_flags;
2572 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2573 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2574 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2576 + if (flags & EXT3_IMMUTABLE_FL)
2577 + inode->i_flags |= S_IMMUTABLE;
2578 + if (flags & EXT3_IXUNLINK_FL)
2579 + inode->i_flags |= S_IXUNLINK;
2581 if (flags & EXT3_SYNC_FL)
2582 inode->i_flags |= S_SYNC;
2583 if (flags & EXT3_APPEND_FL)
2584 inode->i_flags |= S_APPEND;
2585 - if (flags & EXT3_IMMUTABLE_FL)
2586 - inode->i_flags |= S_IMMUTABLE;
2587 if (flags & EXT3_NOATIME_FL)
2588 inode->i_flags |= S_NOATIME;
2589 if (flags & EXT3_DIRSYNC_FL)
2590 inode->i_flags |= S_DIRSYNC;
2592 + inode->i_vflags &= ~(V_BARRIER | V_COW);
2594 + if (flags & EXT3_BARRIER_FL)
2595 + inode->i_vflags |= V_BARRIER;
2596 + if (flags & EXT3_COW_FL)
2597 + inode->i_vflags |= V_COW;
2600 /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2601 void ext3_get_inode_flags(struct ext3_inode_info *ei)
2603 unsigned int flags = ei->vfs_inode.i_flags;
2604 + unsigned int vflags = ei->vfs_inode.i_vflags;
2606 + ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2607 + EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2608 + EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2609 + EXT3_BARRIER_FL | EXT3_COW_FL);
2611 + if (flags & S_IMMUTABLE)
2612 + ei->i_flags |= EXT3_IMMUTABLE_FL;
2613 + if (flags & S_IXUNLINK)
2614 + ei->i_flags |= EXT3_IXUNLINK_FL;
2616 - ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2617 - EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2619 ei->i_flags |= EXT3_SYNC_FL;
2620 if (flags & S_APPEND)
2621 ei->i_flags |= EXT3_APPEND_FL;
2622 - if (flags & S_IMMUTABLE)
2623 - ei->i_flags |= EXT3_IMMUTABLE_FL;
2624 if (flags & S_NOATIME)
2625 ei->i_flags |= EXT3_NOATIME_FL;
2626 if (flags & S_DIRSYNC)
2627 ei->i_flags |= EXT3_DIRSYNC_FL;
2629 + if (vflags & V_BARRIER)
2630 + ei->i_flags |= EXT3_BARRIER_FL;
2631 + if (vflags & V_COW)
2632 + ei->i_flags |= EXT3_COW_FL;
2635 struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2636 @@ -2922,8 +2948,10 @@ struct inode *ext3_iget(struct super_blo
2637 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2638 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2640 - i_uid_write(inode, i_uid);
2641 - i_gid_write(inode, i_gid);
2642 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2643 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2644 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2645 + le16_to_cpu(raw_inode->i_raw_tag)));
2646 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2647 inode->i_size = le32_to_cpu(raw_inode->i_size);
2648 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2649 @@ -3095,8 +3123,10 @@ again:
2651 ext3_get_inode_flags(ei);
2652 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2653 - i_uid = i_uid_read(inode);
2654 - i_gid = i_gid_read(inode);
2655 + i_uid = from_kuid(&init_user_ns,
2656 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2657 + i_gid = from_kgid(&init_user_ns,
2658 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2659 if(!(test_opt(inode->i_sb, NO_UID32))) {
2660 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2661 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2662 @@ -3121,6 +3151,9 @@ again:
2663 raw_inode->i_uid_high = 0;
2664 raw_inode->i_gid_high = 0;
2666 +#ifdef CONFIG_TAGGING_INTERN
2667 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2669 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2670 disksize = cpu_to_le32(ei->i_disksize);
2671 if (disksize != raw_inode->i_size) {
2672 @@ -3289,7 +3322,8 @@ int ext3_setattr(struct dentry *dentry,
2673 if (is_quota_modification(inode, attr))
2674 dquot_initialize(inode);
2675 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2676 - (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2677 + (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2678 + (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2681 /* (user+group)*(old+new) structure, inode write (sb,
2682 @@ -3311,6 +3345,8 @@ int ext3_setattr(struct dentry *dentry,
2683 inode->i_uid = attr->ia_uid;
2684 if (attr->ia_valid & ATTR_GID)
2685 inode->i_gid = attr->ia_gid;
2686 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2687 + inode->i_tag = attr->ia_tag;
2688 error = ext3_mark_inode_dirty(handle, inode);
2689 ext3_journal_stop(handle);
2691 diff -NurpP --minimal linux-3.13.6/fs/ext3/ioctl.c linux-3.13.6-vs2.3.6.11/fs/ext3/ioctl.c
2692 --- linux-3.13.6/fs/ext3/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2693 +++ linux-3.13.6-vs2.3.6.11/fs/ext3/ioctl.c 2014-01-31 20:38:03.000000000 +0000
2695 #include <asm/uaccess.h>
2699 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2701 + handle_t *handle = NULL;
2702 + struct ext3_iloc iloc;
2705 + handle = ext3_journal_start(inode, 1);
2706 + if (IS_ERR(handle))
2707 + return PTR_ERR(handle);
2709 + if (IS_SYNC(inode))
2710 + handle->h_sync = 1;
2711 + err = ext3_reserve_inode_write(handle, inode, &iloc);
2715 + inode->i_flags = flags;
2716 + inode->i_vflags = vflags;
2717 + ext3_get_inode_flags(EXT3_I(inode));
2718 + inode->i_ctime = CURRENT_TIME_SEC;
2720 + err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2722 + ext3_journal_stop(handle);
2726 long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2728 struct inode *inode = file_inode(filp);
2729 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2731 flags = ext3_mask_flags(inode->i_mode, flags);
2733 + if (IS_BARRIER(inode)) {
2734 + vxwprintk_task(1, "messing with the barrier.");
2738 mutex_lock(&inode->i_mutex);
2740 /* Is it quota file? Do not allow user to mess with it */
2741 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2743 * This test looks nicer. Thanks to Pauline Middelink
2745 - if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2746 + if ((oldflags & EXT3_IMMUTABLE_FL) ||
2747 + ((flags ^ oldflags) & (EXT3_APPEND_FL |
2748 + EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2749 if (!capable(CAP_LINUX_IMMUTABLE))
2752 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2756 - flags = flags & EXT3_FL_USER_MODIFIABLE;
2757 + flags &= EXT3_FL_USER_MODIFIABLE;
2758 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2759 ei->i_flags = flags;
2761 diff -NurpP --minimal linux-3.13.6/fs/ext3/namei.c linux-3.13.6-vs2.3.6.11/fs/ext3/namei.c
2762 --- linux-3.13.6/fs/ext3/namei.c 2013-11-25 15:46:59.000000000 +0000
2763 +++ linux-3.13.6-vs2.3.6.11/fs/ext3/namei.c 2014-01-31 20:38:03.000000000 +0000
2767 #include <linux/quotaops.h>
2768 +#include <linux/vs_tag.h>
2773 @@ -915,6 +917,7 @@ restart:
2774 submit_bh(READ | REQ_META | REQ_PRIO,
2777 + dx_propagate_tag(nd, inode);
2780 if ((bh = bh_use[ra_ptr++]) == NULL)
2781 @@ -2568,6 +2571,7 @@ const struct inode_operations ext3_dir_i
2782 .listxattr = ext3_listxattr,
2783 .removexattr = generic_removexattr,
2785 + .sync_flags = ext3_sync_flags,
2786 .get_acl = ext3_get_acl,
2789 diff -NurpP --minimal linux-3.13.6/fs/ext3/super.c linux-3.13.6-vs2.3.6.11/fs/ext3/super.c
2790 --- linux-3.13.6/fs/ext3/super.c 2014-01-22 20:39:06.000000000 +0000
2791 +++ linux-3.13.6-vs2.3.6.11/fs/ext3/super.c 2014-01-31 20:38:03.000000000 +0000
2792 @@ -826,7 +826,8 @@ enum {
2793 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2794 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2795 Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2796 - Opt_resize, Opt_usrquota, Opt_grpquota
2797 + Opt_resize, Opt_usrquota, Opt_grpquota,
2798 + Opt_tag, Opt_notag, Opt_tagid
2801 static const match_table_t tokens = {
2802 @@ -884,6 +885,9 @@ static const match_table_t tokens = {
2803 {Opt_barrier, "barrier"},
2804 {Opt_nobarrier, "nobarrier"},
2805 {Opt_resize, "resize"},
2807 + {Opt_notag, "notag"},
2808 + {Opt_tagid, "tagid=%u"},
2812 @@ -1056,6 +1060,20 @@ static int parse_options (char *options,
2814 set_opt (sbi->s_mount_opt, NO_UID32);
2816 +#ifndef CONFIG_TAGGING_NONE
2818 + set_opt (sbi->s_mount_opt, TAGGED);
2821 + clear_opt (sbi->s_mount_opt, TAGGED);
2824 +#ifdef CONFIG_PROPAGATE
2827 + set_opt (sbi->s_mount_opt, TAGGED);
2831 clear_opt (sbi->s_mount_opt, CHECK);
2833 @@ -1788,6 +1806,9 @@ static int ext3_fill_super (struct super
2837 + if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2838 + sb->s_flags |= MS_TAGGED;
2840 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2841 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2843 @@ -2683,6 +2704,14 @@ static int ext3_remount (struct super_bl
2844 if (test_opt(sb, ABORT))
2845 ext3_abort(sb, __func__, "Abort forced by user");
2847 + if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2848 + !(sb->s_flags & MS_TAGGED)) {
2849 + printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2852 + goto restore_opts;
2855 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2856 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2858 diff -NurpP --minimal linux-3.13.6/fs/ext4/ext4.h linux-3.13.6-vs2.3.6.11/fs/ext4/ext4.h
2859 --- linux-3.13.6/fs/ext4/ext4.h 2014-03-12 13:51:20.000000000 +0000
2860 +++ linux-3.13.6-vs2.3.6.11/fs/ext4/ext4.h 2014-03-12 15:51:07.000000000 +0000
2861 @@ -385,7 +385,10 @@ struct flex_groups {
2862 #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
2863 #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
2864 #define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
2865 +#define EXT4_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2866 +#define EXT4_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
2867 #define EXT4_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */
2868 +#define EXT4_COW_FL 0x20000000 /* Copy on Write marker */
2869 #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
2871 #define EXT4_FL_USER_VISIBLE 0x004BDFFF /* User visible flags */
2872 @@ -670,7 +673,7 @@ struct ext4_inode {
2873 __le16 l_i_uid_high; /* these 2 fields */
2874 __le16 l_i_gid_high; /* were reserved2[0] */
2875 __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2876 - __le16 l_i_reserved;
2877 + __le16 l_i_tag; /* Context Tag */
2880 __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
2881 @@ -790,6 +793,7 @@ do { \
2882 #define i_gid_low i_gid
2883 #define i_uid_high osd2.linux2.l_i_uid_high
2884 #define i_gid_high osd2.linux2.l_i_gid_high
2885 +#define i_raw_tag osd2.linux2.l_i_tag
2886 #define i_checksum_lo osd2.linux2.l_i_checksum_lo
2888 #elif defined(__GNU__)
2889 @@ -976,6 +980,7 @@ struct ext4_inode_info {
2890 #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
2891 #define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */
2892 #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */
2893 +#define EXT4_MOUNT_TAGGED 0x40000 /* Enable Context Tags */
2894 #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */
2895 #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
2896 #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
2897 @@ -2653,6 +2658,7 @@ extern struct buffer_head *ext4_get_firs
2898 extern int ext4_inline_data_fiemap(struct inode *inode,
2899 struct fiemap_extent_info *fieinfo,
2901 +extern int ext4_sync_flags(struct inode *, int, int);
2902 extern int ext4_try_to_evict_inline_data(handle_t *handle,
2903 struct inode *inode,
2905 diff -NurpP --minimal linux-3.13.6/fs/ext4/file.c linux-3.13.6-vs2.3.6.11/fs/ext4/file.c
2906 --- linux-3.13.6/fs/ext4/file.c 2013-11-25 15:46:59.000000000 +0000
2907 +++ linux-3.13.6-vs2.3.6.11/fs/ext4/file.c 2014-01-31 20:38:03.000000000 +0000
2908 @@ -618,5 +618,6 @@ const struct inode_operations ext4_file_
2909 .removexattr = generic_removexattr,
2910 .get_acl = ext4_get_acl,
2911 .fiemap = ext4_fiemap,
2912 + .sync_flags = ext4_sync_flags,
2915 diff -NurpP --minimal linux-3.13.6/fs/ext4/ialloc.c linux-3.13.6-vs2.3.6.11/fs/ext4/ialloc.c
2916 --- linux-3.13.6/fs/ext4/ialloc.c 2014-01-22 20:39:06.000000000 +0000
2917 +++ linux-3.13.6-vs2.3.6.11/fs/ext4/ialloc.c 2014-01-31 20:38:03.000000000 +0000
2919 #include <linux/random.h>
2920 #include <linux/bitops.h>
2921 #include <linux/blkdev.h>
2922 +#include <linux/vs_tag.h>
2923 #include <asm/byteorder.h>
2926 @@ -731,6 +732,7 @@ struct inode *__ext4_new_inode(handle_t
2927 inode->i_mode = mode;
2928 inode->i_uid = current_fsuid();
2929 inode->i_gid = dir->i_gid;
2930 + i_tag_write(inode, dx_current_fstag(sb));
2932 inode_init_owner(inode, dir, mode);
2933 dquot_initialize(inode);
2934 diff -NurpP --minimal linux-3.13.6/fs/ext4/inode.c linux-3.13.6-vs2.3.6.11/fs/ext4/inode.c
2935 --- linux-3.13.6/fs/ext4/inode.c 2014-03-12 13:51:20.000000000 +0000
2936 +++ linux-3.13.6-vs2.3.6.11/fs/ext4/inode.c 2014-03-12 15:51:07.000000000 +0000
2938 #include <linux/slab.h>
2939 #include <linux/ratelimit.h>
2940 #include <linux/aio.h>
2941 +#include <linux/vs_tag.h>
2943 #include "ext4_jbd2.h"
2945 @@ -3927,41 +3928,64 @@ void ext4_set_inode_flags(struct inode *
2947 unsigned int flags = EXT4_I(inode)->i_flags;
2949 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2950 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2951 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2953 + if (flags & EXT4_IMMUTABLE_FL)
2954 + inode->i_flags |= S_IMMUTABLE;
2955 + if (flags & EXT4_IXUNLINK_FL)
2956 + inode->i_flags |= S_IXUNLINK;
2958 if (flags & EXT4_SYNC_FL)
2959 inode->i_flags |= S_SYNC;
2960 if (flags & EXT4_APPEND_FL)
2961 inode->i_flags |= S_APPEND;
2962 - if (flags & EXT4_IMMUTABLE_FL)
2963 - inode->i_flags |= S_IMMUTABLE;
2964 if (flags & EXT4_NOATIME_FL)
2965 inode->i_flags |= S_NOATIME;
2966 if (flags & EXT4_DIRSYNC_FL)
2967 inode->i_flags |= S_DIRSYNC;
2969 + inode->i_vflags &= ~(V_BARRIER | V_COW);
2971 + if (flags & EXT4_BARRIER_FL)
2972 + inode->i_vflags |= V_BARRIER;
2973 + if (flags & EXT4_COW_FL)
2974 + inode->i_vflags |= V_COW;
2977 /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2978 void ext4_get_inode_flags(struct ext4_inode_info *ei)
2980 - unsigned int vfs_fl;
2981 + unsigned int vfs_fl, vfs_vf;
2982 unsigned long old_fl, new_fl;
2985 vfs_fl = ei->vfs_inode.i_flags;
2986 + vfs_vf = ei->vfs_inode.i_vflags;
2987 old_fl = ei->i_flags;
2988 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2989 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
2991 + EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
2994 + if (vfs_fl & S_IMMUTABLE)
2995 + new_fl |= EXT4_IMMUTABLE_FL;
2996 + if (vfs_fl & S_IXUNLINK)
2997 + new_fl |= EXT4_IXUNLINK_FL;
2999 if (vfs_fl & S_SYNC)
3000 new_fl |= EXT4_SYNC_FL;
3001 if (vfs_fl & S_APPEND)
3002 new_fl |= EXT4_APPEND_FL;
3003 - if (vfs_fl & S_IMMUTABLE)
3004 - new_fl |= EXT4_IMMUTABLE_FL;
3005 if (vfs_fl & S_NOATIME)
3006 new_fl |= EXT4_NOATIME_FL;
3007 if (vfs_fl & S_DIRSYNC)
3008 new_fl |= EXT4_DIRSYNC_FL;
3010 + if (vfs_vf & V_BARRIER)
3011 + new_fl |= EXT4_BARRIER_FL;
3012 + if (vfs_vf & V_COW)
3013 + new_fl |= EXT4_COW_FL;
3014 } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3017 @@ -4066,8 +4090,10 @@ struct inode *ext4_iget(struct super_blo
3018 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3019 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3021 - i_uid_write(inode, i_uid);
3022 - i_gid_write(inode, i_gid);
3023 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3024 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3025 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3026 + le16_to_cpu(raw_inode->i_raw_tag)));
3027 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3029 ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */
3030 @@ -4295,8 +4321,10 @@ static int ext4_do_update_inode(handle_t
3032 ext4_get_inode_flags(ei);
3033 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3034 - i_uid = i_uid_read(inode);
3035 - i_gid = i_gid_read(inode);
3036 + i_uid = from_kuid(&init_user_ns,
3037 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
3038 + i_gid = from_kgid(&init_user_ns,
3039 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
3040 if (!(test_opt(inode->i_sb, NO_UID32))) {
3041 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3042 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3043 @@ -4319,6 +4347,9 @@ static int ext4_do_update_inode(handle_t
3044 raw_inode->i_uid_high = 0;
3045 raw_inode->i_gid_high = 0;
3047 +#ifdef CONFIG_TAGGING_INTERN
3048 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3050 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3052 EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3053 @@ -4550,7 +4581,8 @@ int ext4_setattr(struct dentry *dentry,
3054 if (is_quota_modification(inode, attr))
3055 dquot_initialize(inode);
3056 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3057 - (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3058 + (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3059 + (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3062 /* (user+group)*(old+new) structure, inode write (sb,
3063 @@ -4573,6 +4605,8 @@ int ext4_setattr(struct dentry *dentry,
3064 inode->i_uid = attr->ia_uid;
3065 if (attr->ia_valid & ATTR_GID)
3066 inode->i_gid = attr->ia_gid;
3067 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3068 + inode->i_tag = attr->ia_tag;
3069 error = ext4_mark_inode_dirty(handle, inode);
3070 ext4_journal_stop(handle);
3072 diff -NurpP --minimal linux-3.13.6/fs/ext4/ioctl.c linux-3.13.6-vs2.3.6.11/fs/ext4/ioctl.c
3073 --- linux-3.13.6/fs/ext4/ioctl.c 2014-03-12 13:51:20.000000000 +0000
3074 +++ linux-3.13.6-vs2.3.6.11/fs/ext4/ioctl.c 2014-03-12 15:51:07.000000000 +0000
3076 #include <linux/compat.h>
3077 #include <linux/mount.h>
3078 #include <linux/file.h>
3079 +#include <linux/vs_tag.h>
3080 #include <asm/uaccess.h>
3081 #include "ext4_jbd2.h"
3083 @@ -214,6 +215,33 @@ swap_boot_out:
3087 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3089 + handle_t *handle = NULL;
3090 + struct ext4_iloc iloc;
3093 + handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3094 + if (IS_ERR(handle))
3095 + return PTR_ERR(handle);
3097 + if (IS_SYNC(inode))
3098 + ext4_handle_sync(handle);
3099 + err = ext4_reserve_inode_write(handle, inode, &iloc);
3103 + inode->i_flags = flags;
3104 + inode->i_vflags = vflags;
3105 + ext4_get_inode_flags(EXT4_I(inode));
3106 + inode->i_ctime = ext4_current_time(inode);
3108 + err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3110 + ext4_journal_stop(handle);
3114 long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3116 struct inode *inode = file_inode(filp);
3117 @@ -247,6 +275,11 @@ long ext4_ioctl(struct file *filp, unsig
3119 flags = ext4_mask_flags(inode->i_mode, flags);
3121 + if (IS_BARRIER(inode)) {
3122 + vxwprintk_task(1, "messing with the barrier.");
3127 mutex_lock(&inode->i_mutex);
3128 /* Is it quota file? Do not allow user to mess with it */
3129 @@ -264,7 +297,9 @@ long ext4_ioctl(struct file *filp, unsig
3131 * This test looks nicer. Thanks to Pauline Middelink
3133 - if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3134 + if ((oldflags & EXT4_IMMUTABLE_FL) ||
3135 + ((flags ^ oldflags) & (EXT4_APPEND_FL |
3136 + EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3137 if (!capable(CAP_LINUX_IMMUTABLE))
3140 diff -NurpP --minimal linux-3.13.6/fs/ext4/namei.c linux-3.13.6-vs2.3.6.11/fs/ext4/namei.c
3141 --- linux-3.13.6/fs/ext4/namei.c 2013-11-25 15:46:59.000000000 +0000
3142 +++ linux-3.13.6-vs2.3.6.11/fs/ext4/namei.c 2014-01-31 20:38:03.000000000 +0000
3144 #include <linux/quotaops.h>
3145 #include <linux/buffer_head.h>
3146 #include <linux/bio.h>
3147 +#include <linux/vs_tag.h>
3149 #include "ext4_jbd2.h"
3151 @@ -1299,6 +1300,7 @@ restart:
3152 ll_rw_block(READ | REQ_META | REQ_PRIO,
3155 + dx_propagate_tag(nd, inode);
3157 if ((bh = bh_use[ra_ptr++]) == NULL)
3159 @@ -3226,6 +3228,7 @@ const struct inode_operations ext4_dir_i
3160 .removexattr = generic_removexattr,
3161 .get_acl = ext4_get_acl,
3162 .fiemap = ext4_fiemap,
3163 + .sync_flags = ext4_sync_flags,
3166 const struct inode_operations ext4_special_inode_operations = {
3167 diff -NurpP --minimal linux-3.13.6/fs/ext4/super.c linux-3.13.6-vs2.3.6.11/fs/ext4/super.c
3168 --- linux-3.13.6/fs/ext4/super.c 2014-03-12 13:51:20.000000000 +0000
3169 +++ linux-3.13.6-vs2.3.6.11/fs/ext4/super.c 2014-03-12 15:51:07.000000000 +0000
3170 @@ -1162,7 +1162,7 @@ enum {
3171 Opt_inode_readahead_blks, Opt_journal_ioprio,
3172 Opt_dioread_nolock, Opt_dioread_lock,
3173 Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3174 - Opt_max_dir_size_kb,
3175 + Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3178 static const match_table_t tokens = {
3179 @@ -1243,6 +1243,9 @@ static const match_table_t tokens = {
3180 {Opt_removed, "reservation"}, /* mount option from ext2/3 */
3181 {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3182 {Opt_removed, "journal=%u"}, /* mount option from ext2/3 */
3184 + {Opt_notag, "notag"},
3185 + {Opt_tagid, "tagid=%u"},
3189 @@ -1475,6 +1478,20 @@ static int handle_mount_opt(struct super
3191 sb->s_flags |= MS_I_VERSION;
3193 +#ifndef CONFIG_TAGGING_NONE
3195 + set_opt(sb, TAGGED);
3198 + clear_opt(sb, TAGGED);
3201 +#ifdef CONFIG_PROPAGATE
3204 + set_opt(sb, TAGGED);
3209 for (m = ext4_mount_opts; m->token != Opt_err; m++)
3210 @@ -3564,6 +3581,9 @@ static int ext4_fill_super(struct super_
3211 clear_opt(sb, DELALLOC);
3214 + if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3215 + sb->s_flags |= MS_TAGGED;
3217 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3218 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3220 @@ -4818,6 +4838,14 @@ static int ext4_remount(struct super_blo
3221 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3222 ext4_abort(sb, "Abort forced by user");
3224 + if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3225 + !(sb->s_flags & MS_TAGGED)) {
3226 + printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3229 + goto restore_opts;
3232 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3233 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3235 diff -NurpP --minimal linux-3.13.6/fs/fcntl.c linux-3.13.6-vs2.3.6.11/fs/fcntl.c
3236 --- linux-3.13.6/fs/fcntl.c 2014-01-22 20:39:06.000000000 +0000
3237 +++ linux-3.13.6-vs2.3.6.11/fs/fcntl.c 2014-01-31 20:38:03.000000000 +0000
3239 #include <linux/rcupdate.h>
3240 #include <linux/pid_namespace.h>
3241 #include <linux/user_namespace.h>
3242 +#include <linux/vs_limit.h>
3244 #include <asm/poll.h>
3245 #include <asm/siginfo.h>
3246 @@ -377,6 +378,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3250 + if (!vx_files_avail(1))
3253 if (unlikely(f.file->f_mode & FMODE_PATH)) {
3254 if (!check_fcntl_cmd(cmd))
3255 diff -NurpP --minimal linux-3.13.6/fs/file.c linux-3.13.6-vs2.3.6.11/fs/file.c
3256 --- linux-3.13.6/fs/file.c 2014-03-12 13:51:20.000000000 +0000
3257 +++ linux-3.13.6-vs2.3.6.11/fs/file.c 2014-02-25 11:26:09.000000000 +0000
3259 #include <linux/spinlock.h>
3260 #include <linux/rcupdate.h>
3261 #include <linux/workqueue.h>
3262 +#include <linux/vs_limit.h>
3264 int sysctl_nr_open __read_mostly = 1024*1024;
3265 int sysctl_nr_open_min = BITS_PER_LONG;
3266 @@ -311,6 +312,8 @@ struct files_struct *dup_fd(struct files
3267 struct file *f = *old_fds++;
3270 + /* TODO: sum it first for check and performance */
3271 + vx_openfd_inc(open_files - i);
3274 * The fd may be claimed in the fd bitmap but not yet
3275 @@ -376,9 +379,11 @@ static void close_files(struct files_str
3276 filp_close(file, files);
3287 @@ -503,6 +508,7 @@ repeat:
3289 __clear_close_on_exec(fd, fdt);
3291 + vx_openfd_inc(fd);
3294 if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3295 @@ -533,6 +539,7 @@ static void __put_unused_fd(struct files
3296 __clear_open_fd(fd, fdt);
3297 if (fd < files->next_fd)
3298 files->next_fd = fd;
3299 + vx_openfd_dec(fd);
3302 void put_unused_fd(unsigned int fd)
3303 @@ -812,6 +819,8 @@ static int do_dup2(struct files_struct *
3306 filp_close(tofree, files);
3308 + vx_openfd_inc(fd); /* fd was unused */
3312 diff -NurpP --minimal linux-3.13.6/fs/file_table.c linux-3.13.6-vs2.3.6.11/fs/file_table.c
3313 --- linux-3.13.6/fs/file_table.c 2014-01-22 20:39:06.000000000 +0000
3314 +++ linux-3.13.6-vs2.3.6.11/fs/file_table.c 2014-02-01 00:00:01.000000000 +0000
3316 #include <linux/hardirq.h>
3317 #include <linux/task_work.h>
3318 #include <linux/ima.h>
3319 +#include <linux/vs_limit.h>
3320 +#include <linux/vs_context.h>
3322 #include <linux/atomic.h>
3324 @@ -137,6 +139,8 @@ struct file *get_empty_filp(void)
3325 spin_lock_init(&f->f_lock);
3326 eventpoll_init_file(f);
3327 /* f->f_version: 0 */
3328 + f->f_xid = vx_current_xid();
3333 @@ -254,6 +258,8 @@ static void __fput(struct file *file)
3334 i_readcount_dec(inode);
3335 if (file->f_mode & FMODE_WRITE)
3336 drop_file_write_access(file);
3337 + vx_files_dec(file);
3339 file->f_path.dentry = NULL;
3340 file->f_path.mnt = NULL;
3341 file->f_inode = NULL;
3342 @@ -340,6 +346,8 @@ void put_filp(struct file *file)
3344 if (atomic_long_dec_and_test(&file->f_count)) {
3345 security_file_free(file);
3346 + vx_files_dec(file);
3351 diff -NurpP --minimal linux-3.13.6/fs/fs_struct.c linux-3.13.6-vs2.3.6.11/fs/fs_struct.c
3352 --- linux-3.13.6/fs/fs_struct.c 2014-01-22 20:39:06.000000000 +0000
3353 +++ linux-3.13.6-vs2.3.6.11/fs/fs_struct.c 2014-01-31 20:38:03.000000000 +0000
3355 #include <linux/path.h>
3356 #include <linux/slab.h>
3357 #include <linux/fs_struct.h>
3358 +#include <linux/vserver/global.h>
3359 #include "internal.h"
3362 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3364 path_put(&fs->root);
3366 + atomic_dec(&vs_global_fs);
3367 kmem_cache_free(fs_cachep, fs);
3370 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3373 spin_unlock(&old->lock);
3374 + atomic_inc(&vs_global_fs);
3378 diff -NurpP --minimal linux-3.13.6/fs/gfs2/file.c linux-3.13.6-vs2.3.6.11/fs/gfs2/file.c
3379 --- linux-3.13.6/fs/gfs2/file.c 2014-01-22 20:39:06.000000000 +0000
3380 +++ linux-3.13.6-vs2.3.6.11/fs/gfs2/file.c 2014-01-31 20:38:03.000000000 +0000
3381 @@ -137,6 +137,9 @@ static const u32 fsflags_to_gfs2[32] = {
3382 [12] = GFS2_DIF_EXHASH,
3383 [14] = GFS2_DIF_INHERIT_JDATA,
3384 [17] = GFS2_DIF_TOPDIR,
3385 + [27] = GFS2_DIF_IXUNLINK,
3386 + [26] = GFS2_DIF_BARRIER,
3387 + [29] = GFS2_DIF_COW,
3390 static const u32 gfs2_to_fsflags[32] = {
3391 @@ -147,6 +150,9 @@ static const u32 gfs2_to_fsflags[32] = {
3392 [gfs2fl_ExHash] = FS_INDEX_FL,
3393 [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3394 [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3395 + [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3396 + [gfs2fl_Barrier] = FS_BARRIER_FL,
3397 + [gfs2fl_Cow] = FS_COW_FL,
3400 static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3401 @@ -177,12 +183,18 @@ void gfs2_set_inode_flags(struct inode *
3403 struct gfs2_inode *ip = GFS2_I(inode);
3404 unsigned int flags = inode->i_flags;
3405 + unsigned int vflags = inode->i_vflags;
3407 + flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3408 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3410 - flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3411 if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3412 inode->i_flags |= S_NOSEC;
3413 if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3414 flags |= S_IMMUTABLE;
3415 + if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3416 + flags |= S_IXUNLINK;
3418 if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3420 if (ip->i_diskflags & GFS2_DIF_NOATIME)
3421 @@ -190,6 +202,43 @@ void gfs2_set_inode_flags(struct inode *
3422 if (ip->i_diskflags & GFS2_DIF_SYNC)
3424 inode->i_flags = flags;
3426 + vflags &= ~(V_BARRIER | V_COW);
3428 + if (ip->i_diskflags & GFS2_DIF_BARRIER)
3429 + vflags |= V_BARRIER;
3430 + if (ip->i_diskflags & GFS2_DIF_COW)
3432 + inode->i_vflags = vflags;
3435 +void gfs2_get_inode_flags(struct inode *inode)
3437 + struct gfs2_inode *ip = GFS2_I(inode);
3438 + unsigned int flags = inode->i_flags;
3439 + unsigned int vflags = inode->i_vflags;
3441 + ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3442 + GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3443 + GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3444 + GFS2_DIF_BARRIER | GFS2_DIF_COW);
3446 + if (flags & S_IMMUTABLE)
3447 + ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3448 + if (flags & S_IXUNLINK)
3449 + ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3451 + if (flags & S_APPEND)
3452 + ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3453 + if (flags & S_NOATIME)
3454 + ip->i_diskflags |= GFS2_DIF_NOATIME;
3455 + if (flags & S_SYNC)
3456 + ip->i_diskflags |= GFS2_DIF_SYNC;
3458 + if (vflags & V_BARRIER)
3459 + ip->i_diskflags |= GFS2_DIF_BARRIER;
3460 + if (vflags & V_COW)
3461 + ip->i_diskflags |= GFS2_DIF_COW;
3464 /* Flags that can be set by user space */
3465 @@ -303,6 +352,37 @@ static int gfs2_set_flags(struct file *f
3466 return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3469 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3471 + struct gfs2_inode *ip = GFS2_I(inode);
3472 + struct gfs2_sbd *sdp = GFS2_SB(inode);
3473 + struct buffer_head *bh;
3474 + struct gfs2_holder gh;
3477 + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3480 + error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3483 + error = gfs2_meta_inode_buffer(ip, &bh);
3485 + goto out_trans_end;
3486 + gfs2_trans_add_meta(ip->i_gl, bh);
3487 + inode->i_flags = flags;
3488 + inode->i_vflags = vflags;
3489 + gfs2_get_inode_flags(inode);
3490 + gfs2_dinode_out(ip, bh->b_data);
3492 + gfs2_set_aops(inode);
3494 + gfs2_trans_end(sdp);
3496 + gfs2_glock_dq_uninit(&gh);
3500 static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3503 diff -NurpP --minimal linux-3.13.6/fs/gfs2/inode.h linux-3.13.6-vs2.3.6.11/fs/gfs2/inode.h
3504 --- linux-3.13.6/fs/gfs2/inode.h 2013-11-25 15:45:01.000000000 +0000
3505 +++ linux-3.13.6-vs2.3.6.11/fs/gfs2/inode.h 2014-01-31 20:38:03.000000000 +0000
3506 @@ -118,6 +118,7 @@ extern const struct file_operations gfs2
3507 extern const struct file_operations gfs2_dir_fops_nolock;
3509 extern void gfs2_set_inode_flags(struct inode *inode);
3510 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3512 #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3513 extern const struct file_operations gfs2_file_fops;
3514 diff -NurpP --minimal linux-3.13.6/fs/hostfs/hostfs.h linux-3.13.6-vs2.3.6.11/fs/hostfs/hostfs.h
3515 --- linux-3.13.6/fs/hostfs/hostfs.h 2012-12-11 03:30:57.000000000 +0000
3516 +++ linux-3.13.6-vs2.3.6.11/fs/hostfs/hostfs.h 2014-01-31 20:38:03.000000000 +0000
3517 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3518 unsigned short ia_mode;
3523 struct timespec ia_atime;
3524 struct timespec ia_mtime;
3525 diff -NurpP --minimal linux-3.13.6/fs/inode.c linux-3.13.6-vs2.3.6.11/fs/inode.c
3526 --- linux-3.13.6/fs/inode.c 2014-01-22 20:39:06.000000000 +0000
3527 +++ linux-3.13.6-vs2.3.6.11/fs/inode.c 2014-01-31 23:33:47.000000000 +0000
3529 #include <linux/buffer_head.h> /* for inode_has_buffers */
3530 #include <linux/ratelimit.h>
3531 #include <linux/list_lru.h>
3532 +#include <linux/vs_tag.h>
3533 #include "internal.h"
3536 @@ -129,6 +130,8 @@ int inode_init_always(struct super_block
3537 struct address_space *const mapping = &inode->i_data;
3541 + /* essential because of inode slab reuse */
3542 inode->i_blkbits = sb->s_blocksize_bits;
3544 atomic_set(&inode->i_count, 1);
3545 @@ -138,6 +141,7 @@ int inode_init_always(struct super_block
3546 inode->i_opflags = 0;
3547 i_uid_write(inode, 0);
3548 i_gid_write(inode, 0);
3549 + i_tag_write(inode, 0);
3550 atomic_set(&inode->i_writecount, 0);
3552 inode->i_blocks = 0;
3553 @@ -150,6 +154,7 @@ int inode_init_always(struct super_block
3554 inode->i_bdev = NULL;
3555 inode->i_cdev = NULL;
3557 + inode->i_mdev = 0;
3558 inode->dirtied_when = 0;
3560 if (security_inode_alloc(inode))
3561 @@ -477,6 +482,8 @@ void __insert_inode_hash(struct inode *i
3563 EXPORT_SYMBOL(__insert_inode_hash);
3565 +EXPORT_SYMBOL_GPL(__iget);
3568 * __remove_inode_hash - remove an inode from the hash
3569 * @inode: inode to unhash
3570 @@ -1802,9 +1809,11 @@ void init_special_inode(struct inode *in
3571 if (S_ISCHR(mode)) {
3572 inode->i_fop = &def_chr_fops;
3573 inode->i_rdev = rdev;
3574 + inode->i_mdev = rdev;
3575 } else if (S_ISBLK(mode)) {
3576 inode->i_fop = &def_blk_fops;
3577 inode->i_rdev = rdev;
3578 + inode->i_mdev = rdev;
3579 } else if (S_ISFIFO(mode))
3580 inode->i_fop = &pipefifo_fops;
3581 else if (S_ISSOCK(mode))
3582 @@ -1833,6 +1842,7 @@ void inode_init_owner(struct inode *inod
3584 inode->i_gid = current_fsgid();
3585 inode->i_mode = mode;
3586 + i_tag_write(inode, dx_current_fstag(inode->i_sb));
3588 EXPORT_SYMBOL(inode_init_owner);
3590 diff -NurpP --minimal linux-3.13.6/fs/ioctl.c linux-3.13.6-vs2.3.6.11/fs/ioctl.c
3591 --- linux-3.13.6/fs/ioctl.c 2014-01-22 20:39:06.000000000 +0000
3592 +++ linux-3.13.6-vs2.3.6.11/fs/ioctl.c 2014-01-31 20:38:03.000000000 +0000
3594 #include <linux/writeback.h>
3595 #include <linux/buffer_head.h>
3596 #include <linux/falloc.h>
3597 +#include <linux/proc_fs.h>
3598 +#include <linux/vserver/inode.h>
3599 +#include <linux/vs_tag.h>
3601 #include <asm/ioctls.h>
3603 diff -NurpP --minimal linux-3.13.6/fs/ioprio.c linux-3.13.6-vs2.3.6.11/fs/ioprio.c
3604 --- linux-3.13.6/fs/ioprio.c 2012-12-11 03:30:57.000000000 +0000
3605 +++ linux-3.13.6-vs2.3.6.11/fs/ioprio.c 2014-01-31 20:38:03.000000000 +0000
3607 #include <linux/syscalls.h>
3608 #include <linux/security.h>
3609 #include <linux/pid_namespace.h>
3610 +#include <linux/vs_base.h>
3612 int set_task_ioprio(struct task_struct *task, int ioprio)
3614 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3616 pgrp = find_vpid(who);
3617 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3618 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3620 ret = set_task_ioprio(p, ioprio);
3623 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3625 pgrp = find_vpid(who);
3626 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3627 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3629 tmpio = get_task_ioprio(p);
3632 diff -NurpP --minimal linux-3.13.6/fs/jfs/file.c linux-3.13.6-vs2.3.6.11/fs/jfs/file.c
3633 --- linux-3.13.6/fs/jfs/file.c 2013-02-19 13:58:48.000000000 +0000
3634 +++ linux-3.13.6-vs2.3.6.11/fs/jfs/file.c 2014-01-31 20:38:03.000000000 +0000
3635 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3636 if (is_quota_modification(inode, iattr))
3637 dquot_initialize(inode);
3638 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3639 - (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3640 + (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3641 + (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3642 rc = dquot_transfer(inode, iattr);
3645 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3646 #ifdef CONFIG_JFS_POSIX_ACL
3647 .get_acl = jfs_get_acl,
3649 + .sync_flags = jfs_sync_flags,
3652 const struct file_operations jfs_file_operations = {
3653 diff -NurpP --minimal linux-3.13.6/fs/jfs/ioctl.c linux-3.13.6-vs2.3.6.11/fs/jfs/ioctl.c
3654 --- linux-3.13.6/fs/jfs/ioctl.c 2013-05-31 13:45:24.000000000 +0000
3655 +++ linux-3.13.6-vs2.3.6.11/fs/jfs/ioctl.c 2014-01-31 20:38:03.000000000 +0000
3657 #include <linux/time.h>
3658 #include <linux/sched.h>
3659 #include <linux/blkdev.h>
3660 +#include <linux/mount.h>
3661 #include <asm/current.h>
3662 #include <asm/uaccess.h>
3664 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3668 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3670 + inode->i_flags = flags;
3671 + inode->i_vflags = vflags;
3672 + jfs_get_inode_flags(JFS_IP(inode));
3673 + inode->i_ctime = CURRENT_TIME_SEC;
3674 + mark_inode_dirty(inode);
3678 long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3680 struct inode *inode = file_inode(filp);
3681 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3682 if (!S_ISDIR(inode->i_mode))
3683 flags &= ~JFS_DIRSYNC_FL;
3685 + if (IS_BARRIER(inode)) {
3686 + vxwprintk_task(1, "messing with the barrier.");
3690 /* Is it quota file? Do not allow user to mess with it */
3691 if (IS_NOQUOTA(inode)) {
3693 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3694 * the relevant capability.
3696 if ((oldflags & JFS_IMMUTABLE_FL) ||
3697 - ((flags ^ oldflags) &
3698 - (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3699 + ((flags ^ oldflags) & (JFS_APPEND_FL |
3700 + JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3701 if (!capable(CAP_LINUX_IMMUTABLE)) {
3702 mutex_unlock(&inode->i_mutex);
3704 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3708 - flags = flags & JFS_FL_USER_MODIFIABLE;
3709 + flags &= JFS_FL_USER_MODIFIABLE;
3710 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3711 jfs_inode->mode2 = flags;
3713 diff -NurpP --minimal linux-3.13.6/fs/jfs/jfs_dinode.h linux-3.13.6-vs2.3.6.11/fs/jfs/jfs_dinode.h
3714 --- linux-3.13.6/fs/jfs/jfs_dinode.h 2012-12-11 03:30:57.000000000 +0000
3715 +++ linux-3.13.6-vs2.3.6.11/fs/jfs/jfs_dinode.h 2014-01-31 20:38:03.000000000 +0000
3716 @@ -161,9 +161,13 @@ struct dinode {
3718 #define JFS_APPEND_FL 0x01000000 /* writes to file may only append */
3719 #define JFS_IMMUTABLE_FL 0x02000000 /* Immutable file */
3720 +#define JFS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
3722 -#define JFS_FL_USER_VISIBLE 0x03F80000
3723 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3724 +#define JFS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
3725 +#define JFS_COW_FL 0x20000000 /* Copy on Write marker */
3727 +#define JFS_FL_USER_VISIBLE 0x07F80000
3728 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3729 #define JFS_FL_INHERIT 0x03C80000
3731 /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3732 diff -NurpP --minimal linux-3.13.6/fs/jfs/jfs_filsys.h linux-3.13.6-vs2.3.6.11/fs/jfs/jfs_filsys.h
3733 --- linux-3.13.6/fs/jfs/jfs_filsys.h 2012-12-11 03:30:57.000000000 +0000
3734 +++ linux-3.13.6-vs2.3.6.11/fs/jfs/jfs_filsys.h 2014-01-31 20:38:03.000000000 +0000
3736 #define JFS_NAME_MAX 255
3737 #define JFS_PATH_MAX BPSIZE
3739 +#define JFS_TAGGED 0x00800000 /* Context Tagging */
3742 * file system state (superblock state)
3743 diff -NurpP --minimal linux-3.13.6/fs/jfs/jfs_imap.c linux-3.13.6-vs2.3.6.11/fs/jfs/jfs_imap.c
3744 --- linux-3.13.6/fs/jfs/jfs_imap.c 2013-11-25 15:45:01.000000000 +0000
3745 +++ linux-3.13.6-vs2.3.6.11/fs/jfs/jfs_imap.c 2014-01-31 20:38:03.000000000 +0000
3747 #include <linux/pagemap.h>
3748 #include <linux/quotaops.h>
3749 #include <linux/slab.h>
3750 +#include <linux/vs_tag.h>
3752 #include "jfs_incore.h"
3753 #include "jfs_inode.h"
3754 @@ -3047,6 +3048,8 @@ static int copy_from_dinode(struct dinod
3756 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3757 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3761 jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3762 jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3763 @@ -3067,14 +3070,18 @@ static int copy_from_dinode(struct dinod
3765 set_nlink(ip, le32_to_cpu(dip->di_nlink));
3767 - jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3768 + kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3769 + kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3770 + ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3772 + jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3773 if (!uid_valid(sbi->uid))
3774 ip->i_uid = jfs_ip->saved_uid;
3776 ip->i_uid = sbi->uid;
3779 - jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3780 + jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3781 if (!gid_valid(sbi->gid))
3782 ip->i_gid = jfs_ip->saved_gid;
3784 @@ -3139,16 +3146,14 @@ static void copy_to_dinode(struct dinode
3785 dip->di_size = cpu_to_le64(ip->i_size);
3786 dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3787 dip->di_nlink = cpu_to_le32(ip->i_nlink);
3788 - if (!uid_valid(sbi->uid))
3789 - dip->di_uid = cpu_to_le32(i_uid_read(ip));
3791 - dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3792 - jfs_ip->saved_uid));
3793 - if (!gid_valid(sbi->gid))
3794 - dip->di_gid = cpu_to_le32(i_gid_read(ip));
3796 - dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3797 - jfs_ip->saved_gid));
3798 + dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3799 + TAGINO_KUID(DX_TAG(ip),
3800 + !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3802 + dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3803 + TAGINO_KGID(DX_TAG(ip),
3804 + !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3806 jfs_get_inode_flags(jfs_ip);
3808 * mode2 is only needed for storing the higher order bits.
3809 diff -NurpP --minimal linux-3.13.6/fs/jfs/jfs_inode.c linux-3.13.6-vs2.3.6.11/fs/jfs/jfs_inode.c
3810 --- linux-3.13.6/fs/jfs/jfs_inode.c 2013-11-25 15:46:59.000000000 +0000
3811 +++ linux-3.13.6-vs2.3.6.11/fs/jfs/jfs_inode.c 2014-01-31 20:38:03.000000000 +0000
3814 #include <linux/fs.h>
3815 #include <linux/quotaops.h>
3816 +#include <linux/vs_tag.h>
3817 #include "jfs_incore.h"
3818 #include "jfs_inode.h"
3819 #include "jfs_filsys.h"
3820 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3822 unsigned int flags = JFS_IP(inode)->mode2;
3824 - inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3825 - S_NOATIME | S_DIRSYNC | S_SYNC);
3826 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3827 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3829 if (flags & JFS_IMMUTABLE_FL)
3830 inode->i_flags |= S_IMMUTABLE;
3831 + if (flags & JFS_IXUNLINK_FL)
3832 + inode->i_flags |= S_IXUNLINK;
3834 + if (flags & JFS_SYNC_FL)
3835 + inode->i_flags |= S_SYNC;
3836 if (flags & JFS_APPEND_FL)
3837 inode->i_flags |= S_APPEND;
3838 if (flags & JFS_NOATIME_FL)
3839 inode->i_flags |= S_NOATIME;
3840 if (flags & JFS_DIRSYNC_FL)
3841 inode->i_flags |= S_DIRSYNC;
3842 - if (flags & JFS_SYNC_FL)
3843 - inode->i_flags |= S_SYNC;
3845 + inode->i_vflags &= ~(V_BARRIER | V_COW);
3847 + if (flags & JFS_BARRIER_FL)
3848 + inode->i_vflags |= V_BARRIER;
3849 + if (flags & JFS_COW_FL)
3850 + inode->i_vflags |= V_COW;
3853 void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3855 unsigned int flags = jfs_ip->vfs_inode.i_flags;
3856 + unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3858 + jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3859 + JFS_APPEND_FL | JFS_NOATIME_FL |
3860 + JFS_DIRSYNC_FL | JFS_SYNC_FL |
3861 + JFS_BARRIER_FL | JFS_COW_FL);
3863 - jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3864 - JFS_DIRSYNC_FL | JFS_SYNC_FL);
3865 if (flags & S_IMMUTABLE)
3866 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3867 + if (flags & S_IXUNLINK)
3868 + jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3870 if (flags & S_APPEND)
3871 jfs_ip->mode2 |= JFS_APPEND_FL;
3872 if (flags & S_NOATIME)
3873 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3874 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3876 jfs_ip->mode2 |= JFS_SYNC_FL;
3878 + if (vflags & V_BARRIER)
3879 + jfs_ip->mode2 |= JFS_BARRIER_FL;
3880 + if (vflags & V_COW)
3881 + jfs_ip->mode2 |= JFS_COW_FL;
3885 diff -NurpP --minimal linux-3.13.6/fs/jfs/jfs_inode.h linux-3.13.6-vs2.3.6.11/fs/jfs/jfs_inode.h
3886 --- linux-3.13.6/fs/jfs/jfs_inode.h 2012-12-11 03:30:57.000000000 +0000
3887 +++ linux-3.13.6-vs2.3.6.11/fs/jfs/jfs_inode.h 2014-01-31 20:38:03.000000000 +0000
3888 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3889 extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3890 int fh_len, int fh_type);
3891 extern void jfs_set_inode_flags(struct inode *);
3892 +extern int jfs_sync_flags(struct inode *, int, int);
3893 extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3894 extern int jfs_setattr(struct dentry *, struct iattr *);
3896 diff -NurpP --minimal linux-3.13.6/fs/jfs/namei.c linux-3.13.6-vs2.3.6.11/fs/jfs/namei.c
3897 --- linux-3.13.6/fs/jfs/namei.c 2013-11-25 15:45:01.000000000 +0000
3898 +++ linux-3.13.6-vs2.3.6.11/fs/jfs/namei.c 2014-01-31 20:38:03.000000000 +0000
3900 #include <linux/ctype.h>
3901 #include <linux/quotaops.h>
3902 #include <linux/exportfs.h>
3903 +#include <linux/vs_tag.h>
3904 #include "jfs_incore.h"
3905 #include "jfs_superblock.h"
3906 #include "jfs_inode.h"
3907 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3908 jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3911 + dx_propagate_tag(nd, ip);
3912 return d_splice_alias(ip, dentry);
3915 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
3916 #ifdef CONFIG_JFS_POSIX_ACL
3917 .get_acl = jfs_get_acl,
3919 + .sync_flags = jfs_sync_flags,
3922 const struct file_operations jfs_dir_operations = {
3923 diff -NurpP --minimal linux-3.13.6/fs/jfs/super.c linux-3.13.6-vs2.3.6.11/fs/jfs/super.c
3924 --- linux-3.13.6/fs/jfs/super.c 2013-11-25 15:45:01.000000000 +0000
3925 +++ linux-3.13.6-vs2.3.6.11/fs/jfs/super.c 2014-01-31 20:38:03.000000000 +0000
3926 @@ -203,7 +203,8 @@ enum {
3927 Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
3928 Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
3929 Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
3930 - Opt_discard, Opt_nodiscard, Opt_discard_minblk
3931 + Opt_discard, Opt_nodiscard, Opt_discard_minblk,
3932 + Opt_tag, Opt_notag, Opt_tagid
3935 static const match_table_t tokens = {
3936 @@ -213,6 +214,10 @@ static const match_table_t tokens = {
3937 {Opt_resize, "resize=%u"},
3938 {Opt_resize_nosize, "resize"},
3939 {Opt_errors, "errors=%s"},
3941 + {Opt_notag, "notag"},
3942 + {Opt_tagid, "tagid=%u"},
3943 + {Opt_tag, "tagxid"},
3944 {Opt_ignore, "noquota"},
3945 {Opt_ignore, "quota"},
3946 {Opt_usrquota, "usrquota"},
3947 @@ -389,7 +394,20 @@ static int parse_options(char *options,
3952 +#ifndef CONFIG_TAGGING_NONE
3954 + *flag |= JFS_TAGGED;
3957 + *flag &= JFS_TAGGED;
3960 +#ifdef CONFIG_PROPAGATE
3963 + *flag |= JFS_TAGGED;
3967 printk("jfs: Unrecognized mount option \"%s\" "
3968 " or missing value\n", p);
3969 @@ -421,6 +439,12 @@ static int jfs_remount(struct super_bloc
3973 + if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
3974 + printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
3980 if (sb->s_flags & MS_RDONLY) {
3981 pr_err("JFS: resize requires volume" \
3982 @@ -506,6 +530,9 @@ static int jfs_fill_super(struct super_b
3983 #ifdef CONFIG_JFS_POSIX_ACL
3984 sb->s_flags |= MS_POSIXACL;
3986 + /* map mount option tagxid */
3987 + if (sbi->flag & JFS_TAGGED)
3988 + sb->s_flags |= MS_TAGGED;
3991 pr_err("resize option for remount only\n");
3992 diff -NurpP --minimal linux-3.13.6/fs/libfs.c linux-3.13.6-vs2.3.6.11/fs/libfs.c
3993 --- linux-3.13.6/fs/libfs.c 2014-01-22 20:39:06.000000000 +0000
3994 +++ linux-3.13.6-vs2.3.6.11/fs/libfs.c 2014-02-01 01:35:46.000000000 +0000
3995 @@ -145,13 +145,14 @@ static inline unsigned char dt_type(stru
3996 * both impossible due to the lock on directory.
3999 -int dcache_readdir(struct file *file, struct dir_context *ctx)
4000 +static inline int do_dcache_readdir_filter(struct file *filp,
4001 + struct dir_context *ctx, int (*filter)(struct dentry *dentry))
4003 - struct dentry *dentry = file->f_path.dentry;
4004 - struct dentry *cursor = file->private_data;
4005 + struct dentry *dentry = filp->f_path.dentry;
4006 + struct dentry *cursor = filp->private_data;
4007 struct list_head *p, *q = &cursor->d_u.d_child;
4009 - if (!dir_emit_dots(file, ctx))
4010 + if (!dir_emit_dots(filp, ctx))
4012 spin_lock(&dentry->d_lock);
4014 @@ -159,6 +160,8 @@ int dcache_readdir(struct file *file, st
4016 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
4017 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
4018 + if (filter && !filter(next))
4020 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4021 if (!simple_positive(next)) {
4022 spin_unlock(&next->d_lock);
4023 @@ -181,8 +184,22 @@ int dcache_readdir(struct file *file, st
4024 spin_unlock(&dentry->d_lock);
4028 EXPORT_SYMBOL(dcache_readdir);
4030 +int dcache_readdir(struct file *filp, struct dir_context *ctx)
4032 + return do_dcache_readdir_filter(filp, ctx, NULL);
4035 +EXPORT_SYMBOL(dcache_readdir_filter);
4037 +int dcache_readdir_filter(struct file *filp, struct dir_context *ctx,
4038 + int (*filter)(struct dentry *))
4040 + return do_dcache_readdir_filter(filp, ctx, filter);
4043 ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4046 diff -NurpP --minimal linux-3.13.6/fs/locks.c linux-3.13.6-vs2.3.6.11/fs/locks.c
4047 --- linux-3.13.6/fs/locks.c 2014-01-22 20:39:06.000000000 +0000
4048 +++ linux-3.13.6-vs2.3.6.11/fs/locks.c 2014-01-31 23:51:55.000000000 +0000
4050 #include <linux/hashtable.h>
4051 #include <linux/percpu.h>
4052 #include <linux/lglock.h>
4053 +#include <linux/vs_base.h>
4054 +#include <linux/vs_limit.h>
4056 #include <asm/uaccess.h>
4058 @@ -210,11 +212,17 @@ static void locks_init_lock_heads(struct
4059 /* Allocate an empty lock structure. */
4060 struct file_lock *locks_alloc_lock(void)
4062 - struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4063 + struct file_lock *fl;
4066 - locks_init_lock_heads(fl);
4067 + if (!vx_locks_avail(1))
4070 + fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4073 + locks_init_lock_heads(fl);
4078 EXPORT_SYMBOL_GPL(locks_alloc_lock);
4079 @@ -238,6 +246,7 @@ void locks_free_lock(struct file_lock *f
4080 BUG_ON(!list_empty(&fl->fl_block));
4081 BUG_ON(!hlist_unhashed(&fl->fl_link));
4084 locks_release_private(fl);
4085 kmem_cache_free(filelock_cache, fl);
4087 @@ -247,6 +256,7 @@ void locks_init_lock(struct file_lock *f
4089 memset(fl, 0, sizeof(struct file_lock));
4090 locks_init_lock_heads(fl);
4094 EXPORT_SYMBOL(locks_init_lock);
4095 @@ -287,6 +297,7 @@ void locks_copy_lock(struct file_lock *n
4096 new->fl_file = fl->fl_file;
4097 new->fl_ops = fl->fl_ops;
4098 new->fl_lmops = fl->fl_lmops;
4099 + new->fl_xid = fl->fl_xid;
4101 locks_copy_private(new, fl);
4103 @@ -325,6 +336,11 @@ static int flock_make_lock(struct file *
4104 fl->fl_flags = FL_FLOCK;
4106 fl->fl_end = OFFSET_MAX;
4108 + vxd_assert(filp->f_xid == vx_current_xid(),
4109 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4110 + fl->fl_xid = filp->f_xid;
4115 @@ -464,6 +480,7 @@ static int lease_init(struct file *filp,
4117 fl->fl_owner = current->files;
4118 fl->fl_pid = current->tgid;
4119 + fl->fl_xid = vx_current_xid();
4122 fl->fl_flags = FL_LEASE;
4123 @@ -483,6 +500,11 @@ static struct file_lock *lease_alloc(str
4125 return ERR_PTR(error);
4127 + fl->fl_xid = vx_current_xid();
4129 + vxd_assert(filp->f_xid == fl->fl_xid,
4130 + "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4132 error = lease_init(filp, type, fl);
4134 locks_free_lock(fl);
4135 @@ -858,6 +880,7 @@ static int flock_lock_file(struct file *
4136 spin_lock(&inode->i_lock);
4139 + new_fl->fl_xid = -1;
4141 for_each_lock(inode, before) {
4142 struct file_lock *fl = *before;
4143 @@ -878,6 +901,7 @@ find_conflict:
4145 locks_copy_lock(new_fl, request);
4146 locks_insert_lock(before, new_fl);
4147 + vx_locks_inc(new_fl);
4151 @@ -888,7 +912,8 @@ out:
4155 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4156 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4157 + struct file_lock *conflock, vxid_t xid)
4159 struct file_lock *fl;
4160 struct file_lock *new_fl = NULL;
4161 @@ -899,6 +924,8 @@ static int __posix_lock_file(struct inod
4165 + vxd_assert(xid == vx_current_xid(),
4166 + "xid(%d) == current(%d)", xid, vx_current_xid());
4168 * We may need two file_lock structures for this operation,
4169 * so we get them in advance to avoid races.
4170 @@ -909,7 +936,11 @@ static int __posix_lock_file(struct inod
4171 (request->fl_type != F_UNLCK ||
4172 request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4173 new_fl = locks_alloc_lock();
4174 + new_fl->fl_xid = xid;
4175 + vx_locks_inc(new_fl);
4176 new_fl2 = locks_alloc_lock();
4177 + new_fl2->fl_xid = xid;
4178 + vx_locks_inc(new_fl2);
4181 spin_lock(&inode->i_lock);
4182 @@ -1118,7 +1149,8 @@ static int __posix_lock_file(struct inod
4183 int posix_lock_file(struct file *filp, struct file_lock *fl,
4184 struct file_lock *conflock)
4186 - return __posix_lock_file(file_inode(filp), fl, conflock);
4187 + return __posix_lock_file(file_inode(filp),
4188 + fl, conflock, filp->f_xid);
4190 EXPORT_SYMBOL(posix_lock_file);
4192 @@ -1208,7 +1240,7 @@ int locks_mandatory_area(int read_write,
4193 fl.fl_end = offset + count - 1;
4196 - error = __posix_lock_file(inode, &fl, NULL);
4197 + error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4198 if (error != FILE_LOCK_DEFERRED)
4200 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4201 @@ -1549,6 +1581,7 @@ static int generic_add_lease(struct file
4204 locks_insert_lock(before, lease);
4205 + vx_locks_inc(lease);
4209 @@ -1991,6 +2024,11 @@ int fcntl_setlk(unsigned int fd, struct
4210 if (file_lock == NULL)
4213 + vxd_assert(filp->f_xid == vx_current_xid(),
4214 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4215 + file_lock->fl_xid = filp->f_xid;
4216 + vx_locks_inc(file_lock);
4219 * This might block, so we do it before checking the inode.
4221 @@ -2109,6 +2147,11 @@ int fcntl_setlk64(unsigned int fd, struc
4222 if (file_lock == NULL)
4225 + vxd_assert(filp->f_xid == vx_current_xid(),
4226 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4227 + file_lock->fl_xid = filp->f_xid;
4228 + vx_locks_inc(file_lock);
4231 * This might block, so we do it before checking the inode.
4233 @@ -2378,8 +2421,11 @@ static int locks_show(struct seq_file *f
4235 lock_get_status(f, fl, iter->li_pos, "");
4237 - list_for_each_entry(bfl, &fl->fl_block, fl_block)
4238 - lock_get_status(f, bfl, iter->li_pos, " ->");
4239 + list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4240 + if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4242 + lock_get_status(f, bfl, iter->li_pos, " ->");
4247 diff -NurpP --minimal linux-3.13.6/fs/mount.h linux-3.13.6-vs2.3.6.11/fs/mount.h
4248 --- linux-3.13.6/fs/mount.h 2014-03-12 13:51:21.000000000 +0000
4249 +++ linux-3.13.6-vs2.3.6.11/fs/mount.h 2014-02-25 11:26:09.000000000 +0000
4250 @@ -57,6 +57,7 @@ struct mount {
4251 int mnt_expiry_mark; /* true if marked for expiry */
4253 struct path mnt_ex_mountpoint;
4254 + vtag_t mnt_tag; /* tagging used for vfsmount */
4257 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4258 diff -NurpP --minimal linux-3.13.6/fs/namei.c linux-3.13.6-vs2.3.6.11/fs/namei.c
4259 --- linux-3.13.6/fs/namei.c 2014-01-22 20:39:06.000000000 +0000
4260 +++ linux-3.13.6-vs2.3.6.11/fs/namei.c 2014-02-01 01:26:19.000000000 +0000
4262 #include <linux/device_cgroup.h>
4263 #include <linux/fs_struct.h>
4264 #include <linux/posix_acl.h>
4265 +#include <linux/proc_fs.h>
4266 +#include <linux/magic.h>
4267 +#include <linux/vserver/inode.h>
4268 +#include <linux/vs_base.h>
4269 +#include <linux/vs_tag.h>
4270 +#include <linux/vs_cowbl.h>
4271 +#include <linux/vs_device.h>
4272 +#include <linux/vs_context.h>
4273 +#include <linux/pid_namespace.h>
4274 #include <asm/uaccess.h>
4276 #include "internal.h"
4277 +#include "proc/internal.h"
4280 /* [Feb-1997 T. Schoebel-Theuer]
4281 @@ -266,6 +276,89 @@ static int check_acl(struct inode *inode
4285 +static inline int dx_barrier(const struct inode *inode)
4287 + if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4288 + vxwprintk_task(1, "did hit the barrier.");
4294 +static int __dx_permission(const struct inode *inode, int mask)
4296 + if (dx_barrier(inode))
4299 + if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4300 + /* devpts is xid tagged */
4301 + if (S_ISDIR(inode->i_mode) ||
4302 + vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4305 + /* just pretend we didn't find anything */
4308 + else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4309 + struct proc_dir_entry *de = PDE(inode);
4311 + if (de && !vx_hide_check(0, de->vx_flags))
4314 + if ((mask & (MAY_WRITE | MAY_APPEND))) {
4316 + struct task_struct *tsk;
4318 + if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4319 + vx_flags(VXF_STATE_SETUP, 0))
4322 + pid = PROC_I(inode)->pid;
4327 + tsk = pid_task(pid, PIDTYPE_PID);
4328 + vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4329 + tsk, (tsk ? vx_task_xid(tsk) : 0));
4331 + vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4332 + rcu_read_unlock();
4335 + rcu_read_unlock();
4338 + /* FIXME: Should we block some entries here? */
4343 + if (dx_notagcheck(inode->i_sb) ||
4344 + dx_check((vxid_t)i_tag_read(inode),
4345 + DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4353 +int dx_permission(const struct inode *inode, int mask)
4355 + int ret = __dx_permission(inode, mask);
4356 + if (unlikely(ret)) {
4357 +#ifndef CONFIG_VSERVER_WARN_DEVPTS
4358 + if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4361 + "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4362 + mask, inode->i_sb->s_id, inode,
4363 + i_tag_read(inode), inode->i_ino);
4369 * This does the basic permission checking
4371 @@ -388,10 +481,14 @@ int __inode_permission(struct inode *ino
4373 * Nobody gets write access to an immutable file.
4375 - if (IS_IMMUTABLE(inode))
4376 + if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4380 + retval = dx_permission(inode, mask);
4384 retval = do_inode_permission(inode, mask);
4387 @@ -1241,7 +1338,8 @@ static void follow_dotdot(struct nameida
4389 if (nd->path.dentry == nd->root.dentry &&
4390 nd->path.mnt == nd->root.mnt) {
4392 + /* for sane '/' avoid follow_mount() */
4395 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4396 /* rare case of legitimate dget_parent()... */
4397 @@ -1386,6 +1484,9 @@ static int lookup_fast(struct nameidata
4402 + /* FIXME: check dx permission */
4405 path->dentry = dentry;
4406 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4407 @@ -1416,6 +1517,8 @@ unlazy:
4411 + /* FIXME: check dx permission */
4414 path->dentry = dentry;
4415 err = follow_managed(path, nd->flags);
4416 @@ -2403,7 +2506,7 @@ static int may_delete(struct inode *dir,
4419 if (check_sticky(dir, inode) || IS_APPEND(inode) ||
4420 - IS_IMMUTABLE(inode) || IS_SWAPFILE(inode))
4421 + IS_IXORUNLINK(inode) || IS_SWAPFILE(inode))
4424 if (!d_is_directory(victim) && !d_is_autodir(victim))
4425 @@ -2483,19 +2586,25 @@ int vfs_create(struct inode *dir, struct
4428 int error = may_create(dir, dentry);
4431 + vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4435 if (!dir->i_op->create)
4436 return -EACCES; /* shouldn't it be ENOSYS? */
4439 error = security_inode_create(dir, dentry, mode);
4442 + vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4445 error = dir->i_op->create(dir, dentry, mode, want_excl);
4447 fsnotify_create(dir, dentry);
4449 + vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4453 @@ -2530,6 +2639,15 @@ static int may_open(struct path *path, i
4457 +#ifdef CONFIG_VSERVER_COWBL
4458 + if (IS_COW(inode) &&
4459 + ((flag & O_ACCMODE) != O_RDONLY)) {
4460 + if (IS_COW_LINK(inode))
4462 + inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4463 + mark_inode_dirty(inode);
4466 error = inode_permission(inode, acc_mode);
4469 @@ -3025,6 +3143,16 @@ finish_open:
4471 finish_open_created:
4472 error = may_open(&nd->path, acc_mode, open_flag);
4473 +#ifdef CONFIG_VSERVER_COWBL
4474 + if (error == -EMLINK) {
4475 + struct dentry *dentry;
4476 + dentry = cow_break_link(name->name);
4477 + if (IS_ERR(dentry))
4478 + error = PTR_ERR(dentry);
4485 file->f_path.mnt = nd->path.mnt;
4486 @@ -3150,6 +3278,7 @@ static struct file *path_openat(int dfd,
4491 file = get_empty_filp();
4494 @@ -3191,6 +3320,16 @@ static struct file *path_openat(int dfd,
4495 error = do_last(nd, &path, file, op, &opened, pathname);
4496 put_link(nd, &link, cookie);
4499 +#ifdef CONFIG_VSERVER_COWBL
4500 + if (error == -EMLINK) {
4501 + if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4502 + path_put(&nd->root);
4509 if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4510 path_put(&nd->root);
4511 @@ -3306,6 +3445,11 @@ struct dentry *kern_path_create(int dfd,
4515 + vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4516 + path->dentry, path->dentry->d_name.len,
4517 + path->dentry->d_name.name, dentry,
4518 + dentry->d_name.len, dentry->d_name.name,
4519 + path->dentry->d_inode);
4523 @@ -3853,7 +3997,7 @@ int vfs_link(struct dentry *old_dentry,
4525 * A link to an append-only or immutable file cannot be created.
4527 - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4528 + if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4530 if (!dir->i_op->link)
4532 @@ -4305,6 +4449,287 @@ int generic_readlink(struct dentry *dent
4537 +#ifdef CONFIG_VSERVER_COWBL
4540 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4545 + return do_splice_direct(in, &ppos, out, &opos, len, 0);
4548 +struct dentry *cow_break_link(const char *pathname)
4550 + int ret, mode, pathlen, redo = 0, drop = 1;
4551 + struct nameidata old_nd, dir_nd;
4552 + struct path dir_path, *old_path, *new_path;
4553 + struct dentry *dir, *old_dentry, *new_dentry = NULL;
4554 + struct file *old_file;
4555 + struct file *new_file;
4556 + char *to, *path, pad='\251';
4559 + vxdprintk(VXD_CBIT(misc, 1),
4560 + "cow_break_link(" VS_Q("%s") ")", pathname);
4562 + path = kmalloc(PATH_MAX, GFP_KERNEL);
4567 + /* old_nd.path will have refs to dentry and mnt */
4568 + ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4569 + vxdprintk(VXD_CBIT(misc, 2),
4570 + "do_path_lookup(old): %d", ret);
4572 + goto out_free_path;
4574 + /* dentry/mnt refs handed over to old_path */
4575 + old_path = &old_nd.path;
4576 + /* no explicit reference for old_dentry here */
4577 + old_dentry = old_path->dentry;
4579 + mode = old_dentry->d_inode->i_mode;
4580 + to = d_path(old_path, path, PATH_MAX-2);
4581 + pathlen = strlen(to);
4582 + vxdprintk(VXD_CBIT(misc, 2),
4583 + "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4585 + old_dentry->d_name.len, old_dentry->d_name.name,
4586 + old_dentry->d_name.len);
4588 + to[pathlen + 1] = 0;
4590 + new_dentry = NULL;
4591 + to[pathlen] = pad--;
4593 + if (pad <= '\240')
4596 + vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4598 + /* dir_nd.path will have refs to dentry and mnt */
4599 + ret = do_path_lookup(AT_FDCWD, to,
4600 + LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4601 + vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4605 + /* this puppy downs the dir inode mutex if successful.
4606 + dir_path will hold refs to dentry and mnt and
4607 + we'll have write access to the mnt */
4608 + new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4609 + if (!new_dentry || IS_ERR(new_dentry)) {
4610 + path_put(&dir_nd.path);
4611 + vxdprintk(VXD_CBIT(misc, 2),
4612 + "kern_path_create(new) failed with %ld",
4613 + PTR_ERR(new_dentry));
4616 + vxdprintk(VXD_CBIT(misc, 2),
4617 + "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4619 + new_dentry->d_name.len, new_dentry->d_name.name,
4620 + new_dentry->d_name.len);
4622 + /* take a reference on new_dentry */
4625 + /* dentry/mnt refs handed over to new_path */
4626 + new_path = &dir_path;
4628 + /* dentry for old/new dir */
4629 + dir = dir_nd.path.dentry;
4631 + /* give up reference on dir */
4632 + dput(new_path->dentry);
4634 + /* new_dentry already has a reference */
4635 + new_path->dentry = new_dentry;
4637 + ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4638 + vxdprintk(VXD_CBIT(misc, 2),
4639 + "vfs_create(new): %d", ret);
4640 + if (ret == -EEXIST) {
4641 + path_put(&dir_nd.path);
4642 + mutex_unlock(&dir->d_inode->i_mutex);
4643 + mnt_drop_write(new_path->mnt);
4644 + path_put(new_path);
4645 + new_dentry = NULL;
4649 + goto out_unlock_new;
4651 + /* drop out early, ret passes ENOENT */
4653 + if ((redo = d_unhashed(old_dentry)))
4654 + goto out_unlock_new;
4656 + /* doesn't change refs for old_path */
4657 + old_file = dentry_open(old_path, O_RDONLY, current_cred());
4658 + vxdprintk(VXD_CBIT(misc, 2),
4659 + "dentry_open(old): %p", old_file);
4660 + if (IS_ERR(old_file)) {
4661 + ret = PTR_ERR(old_file);
4662 + goto out_unlock_new;
4665 + /* doesn't change refs for new_path */
4666 + new_file = dentry_open(new_path, O_WRONLY, current_cred());
4667 + vxdprintk(VXD_CBIT(misc, 2),
4668 + "dentry_open(new): %p", new_file);
4669 + if (IS_ERR(new_file)) {
4670 + ret = PTR_ERR(new_file);
4671 + goto out_fput_old;
4674 + /* unlock the inode mutex from kern_path_create() */
4675 + mutex_unlock(&dir->d_inode->i_mutex);
4677 + /* drop write access to mnt */
4678 + mnt_drop_write(new_path->mnt);
4682 + size = i_size_read(old_file->f_dentry->d_inode);
4683 + ret = do_cow_splice(old_file, new_file, size);
4684 + vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4686 + goto out_fput_both;
4687 + } else if (ret < size) {
4689 + goto out_fput_both;
4691 + struct inode *old_inode = old_dentry->d_inode;
4692 + struct inode *new_inode = new_dentry->d_inode;
4693 + struct iattr attr = {
4694 + .ia_uid = old_inode->i_uid,
4695 + .ia_gid = old_inode->i_gid,
4696 + .ia_valid = ATTR_UID | ATTR_GID
4699 + setattr_copy(new_inode, &attr);
4700 + mark_inode_dirty(new_inode);
4703 + /* lock rename mutex */
4704 + mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4706 + /* drop out late */
4708 + if ((redo = d_unhashed(old_dentry)))
4711 + vxdprintk(VXD_CBIT(misc, 2),
4712 + "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4713 + new_dentry->d_name.len, new_dentry->d_name.name,
4714 + new_dentry->d_name.len,
4715 + old_dentry->d_name.len, old_dentry->d_name.name,
4716 + old_dentry->d_name.len);
4717 + ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4718 + old_dentry->d_parent->d_inode, old_dentry, NULL);
4719 + vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4722 + mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4725 + vxdprintk(VXD_CBIT(misc, 3),
4726 + "fput(new_file=%p[#%ld])", new_file,
4727 + atomic_long_read(&new_file->f_count));
4731 + vxdprintk(VXD_CBIT(misc, 3),
4732 + "fput(old_file=%p[#%ld])", old_file,
4733 + atomic_long_read(&old_file->f_count));
4737 + /* drop references from dir_nd.path */
4738 + path_put(&dir_nd.path);
4741 + /* unlock the inode mutex from kern_path_create() */
4742 + mutex_unlock(&dir->d_inode->i_mutex);
4744 + /* drop write access to mnt */
4745 + mnt_drop_write(new_path->mnt);
4751 + /* error path cleanup */
4752 + vfs_unlink(dir->d_inode, new_dentry, NULL);
4756 + goto out_rel_both;
4758 + /* lookup dentry once again
4759 + old_nd.path will be freed as old_path in out_rel_old */
4760 + ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4762 + goto out_rel_both;
4764 + /* drop reference on new_dentry */
4766 + new_dentry = old_path->dentry;
4768 + vxdprintk(VXD_CBIT(misc, 2),
4769 + "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4771 + new_dentry->d_name.len, new_dentry->d_name.name,
4772 + new_dentry->d_name.len);
4776 + path_put(new_path);
4778 + path_put(old_path);
4784 + new_dentry = ERR_PTR(ret);
4786 + vxdprintk(VXD_CBIT(misc, 3),
4787 + "cow_break_link returning with %p", new_dentry);
4788 + return new_dentry;
4793 +int vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4796 + struct vfsmount *vmnt;
4797 + char *pstr, *root;
4800 + pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4804 + vmnt = &ns->root->mnt;
4806 + path.dentry = vmnt->mnt_root;
4807 + root = d_path(&path, pstr, PATH_MAX - 2);
4808 + length = sprintf(buffer + length,
4809 + "Namespace:\t%p [#%u]\n"
4810 + "RootPath:\t%s\n",
4811 + ns, atomic_read(&ns->count),
4817 /* get the link contents into pagecache */
4818 static char *page_getlink(struct dentry * dentry, struct page **ppage)
4820 @@ -4427,3 +4852,4 @@ EXPORT_SYMBOL(vfs_symlink);
4821 EXPORT_SYMBOL(vfs_unlink);
4822 EXPORT_SYMBOL(dentry_unhash);
4823 EXPORT_SYMBOL(generic_readlink);
4824 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4825 diff -NurpP --minimal linux-3.13.6/fs/namespace.c linux-3.13.6-vs2.3.6.11/fs/namespace.c
4826 --- linux-3.13.6/fs/namespace.c 2014-01-22 20:39:06.000000000 +0000
4827 +++ linux-3.13.6-vs2.3.6.11/fs/namespace.c 2014-01-31 23:44:28.000000000 +0000
4829 #include <linux/uaccess.h>
4830 #include <linux/proc_ns.h>
4831 #include <linux/magic.h>
4832 +#include <linux/vs_base.h>
4833 +#include <linux/vs_context.h>
4834 +#include <linux/vs_tag.h>
4835 +#include <linux/vserver/space.h>
4836 +#include <linux/vserver/global.h>
4838 #include "internal.h"
4840 @@ -803,6 +808,10 @@ vfs_kern_mount(struct file_system_type *
4842 return ERR_PTR(-ENODEV);
4844 + if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4845 + !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4846 + return ERR_PTR(-EPERM);
4848 mnt = alloc_vfsmnt(name);
4850 return ERR_PTR(-ENOMEM);
4851 @@ -863,6 +872,7 @@ static struct mount *clone_mnt(struct mo
4852 mnt->mnt.mnt_root = dget(root);
4853 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4854 mnt->mnt_parent = mnt;
4855 + mnt->mnt_tag = old->mnt_tag;
4857 list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4858 unlock_mount_hash();
4859 @@ -1323,7 +1333,8 @@ static int do_umount(struct mount *mnt,
4861 static inline bool may_mount(void)
4863 - return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4864 + return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4865 + CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4869 @@ -1738,6 +1749,7 @@ static int do_change_type(struct path *p
4873 + // mnt->mnt_flags = mnt_flags;
4876 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4877 @@ -1766,12 +1778,14 @@ static bool has_locked_children(struct m
4878 * do loopback mount.
4880 static int do_loopback(struct path *path, const char *old_name,
4882 + vtag_t tag, unsigned long flags, int mnt_flags)
4884 struct path old_path;
4885 struct mount *mnt = NULL, *old, *parent;
4886 struct mountpoint *mp;
4887 + int recurse = flags & MS_REC;
4890 if (!old_name || !*old_name)
4892 err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4893 @@ -1851,7 +1865,7 @@ static int change_mount_flags(struct vfs
4894 * on it - tough luck.
4896 static int do_remount(struct path *path, int flags, int mnt_flags,
4898 + void *data, vxid_t xid)
4901 struct super_block *sb = path->mnt->mnt_sb;
4902 @@ -2330,6 +2344,7 @@ long do_mount(const char *dev_name, cons
4909 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4910 @@ -2359,6 +2374,12 @@ long do_mount(const char *dev_name, cons
4911 if (!(flags & MS_NOATIME))
4912 mnt_flags |= MNT_RELATIME;
4914 + if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4915 + /* FIXME: bind and re-mounts get the tag flag? */
4916 + if (flags & (MS_BIND|MS_REMOUNT))
4917 + flags |= MS_TAGID;
4920 /* Separate the per-mountpoint flags */
4921 if (flags & MS_NOSUID)
4922 mnt_flags |= MNT_NOSUID;
4923 @@ -2375,15 +2396,17 @@ long do_mount(const char *dev_name, cons
4924 if (flags & MS_RDONLY)
4925 mnt_flags |= MNT_READONLY;
4927 + if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4928 + mnt_flags |= MNT_NODEV;
4929 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4930 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4933 if (flags & MS_REMOUNT)
4934 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4937 else if (flags & MS_BIND)
4938 - retval = do_loopback(&path, dev_name, flags & MS_REC);
4939 + retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4940 else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4941 retval = do_change_type(&path, flags);
4942 else if (flags & MS_MOVE)
4943 @@ -2499,6 +2522,7 @@ struct mnt_namespace *copy_mnt_ns(unsign
4944 p = next_mnt(p, old);
4947 + atomic_inc(&vs_global_mnt_ns);
4951 @@ -2680,9 +2704,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4952 new_mnt = real_mount(new.mnt);
4953 root_mnt = real_mount(root.mnt);
4954 old_mnt = real_mount(old.mnt);
4955 - if (IS_MNT_SHARED(old_mnt) ||
4956 + if ((IS_MNT_SHARED(old_mnt) ||
4957 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4958 - IS_MNT_SHARED(root_mnt->mnt_parent))
4959 + IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4960 + !vx_flags(VXF_STATE_SETUP, 0))
4962 if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4964 @@ -2806,6 +2831,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4965 if (!atomic_dec_and_test(&ns->count))
4967 drop_collected_mounts(&ns->root->mnt);
4968 + atomic_dec(&vs_global_mnt_ns);
4972 diff -NurpP --minimal linux-3.13.6/fs/nfs/client.c linux-3.13.6-vs2.3.6.11/fs/nfs/client.c
4973 --- linux-3.13.6/fs/nfs/client.c 2014-01-22 20:39:06.000000000 +0000
4974 +++ linux-3.13.6-vs2.3.6.11/fs/nfs/client.c 2014-01-31 20:38:03.000000000 +0000
4975 @@ -685,6 +685,9 @@ int nfs_init_server_rpcclient(struct nfs
4976 if (server->flags & NFS_MOUNT_SOFT)
4977 server->client->cl_softrtry = 1;
4979 + server->client->cl_tag = 0;
4980 + if (server->flags & NFS_MOUNT_TAGGED)
4981 + server->client->cl_tag = 1;
4984 EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4985 @@ -863,6 +866,10 @@ static void nfs_server_set_fsinfo(struct
4986 server->acdirmin = server->acdirmax = 0;
4989 + /* FIXME: needs fsinfo
4990 + if (server->flags & NFS_MOUNT_TAGGED)
4991 + sb->s_flags |= MS_TAGGED; */
4993 server->maxfilesize = fsinfo->maxfilesize;
4995 server->time_delta = fsinfo->time_delta;
4996 diff -NurpP --minimal linux-3.13.6/fs/nfs/dir.c linux-3.13.6-vs2.3.6.11/fs/nfs/dir.c
4997 --- linux-3.13.6/fs/nfs/dir.c 2014-03-12 13:51:21.000000000 +0000
4998 +++ linux-3.13.6-vs2.3.6.11/fs/nfs/dir.c 2014-02-25 11:26:10.000000000 +0000
5000 #include <linux/sched.h>
5001 #include <linux/kmemleak.h>
5002 #include <linux/xattr.h>
5003 +#include <linux/vs_tag.h>
5005 #include "delegation.h"
5007 @@ -1319,6 +1320,7 @@ struct dentry *nfs_lookup(struct inode *
5008 /* Success: notify readdir to use READDIRPLUS */
5009 nfs_advise_use_readdirplus(dir);
5011 + dx_propagate_tag(nd, inode);
5013 res = d_materialise_unique(dentry, inode);
5015 diff -NurpP --minimal linux-3.13.6/fs/nfs/inode.c linux-3.13.6-vs2.3.6.11/fs/nfs/inode.c
5016 --- linux-3.13.6/fs/nfs/inode.c 2014-03-12 13:51:21.000000000 +0000
5017 +++ linux-3.13.6-vs2.3.6.11/fs/nfs/inode.c 2014-03-12 15:51:07.000000000 +0000
5019 #include <linux/slab.h>
5020 #include <linux/compat.h>
5021 #include <linux/freezer.h>
5022 +#include <linux/vs_tag.h>
5024 #include <asm/uaccess.h>
5026 @@ -359,6 +360,8 @@ nfs_fhget(struct super_block *sb, struct
5027 if (inode->i_state & I_NEW) {
5028 struct nfs_inode *nfsi = NFS_I(inode);
5029 unsigned long now = jiffies;
5033 /* We set i_ino for the few things that still rely on it,
5034 * such as stat(2) */
5035 @@ -403,8 +406,8 @@ nfs_fhget(struct super_block *sb, struct
5036 inode->i_version = 0;
5039 - inode->i_uid = make_kuid(&init_user_ns, -2);
5040 - inode->i_gid = make_kgid(&init_user_ns, -2);
5041 + kuid = make_kuid(&init_user_ns, -2);
5042 + kgid = make_kgid(&init_user_ns, -2);
5043 inode->i_blocks = 0;
5044 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5046 @@ -438,11 +441,11 @@ nfs_fhget(struct super_block *sb, struct
5047 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5048 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5049 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5050 - inode->i_uid = fattr->uid;
5051 + kuid = fattr->uid;
5052 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5053 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5054 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5055 - inode->i_gid = fattr->gid;
5056 + kgid = fattr->gid;
5057 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5058 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5059 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5060 @@ -453,6 +456,10 @@ nfs_fhget(struct super_block *sb, struct
5062 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5064 + inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5065 + inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5066 + inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
5067 + /* maybe fattr->xid someday */
5069 nfs_setsecurity(inode, fattr, label);
5071 @@ -578,6 +585,8 @@ void nfs_setattr_update_inode(struct ino
5072 inode->i_uid = attr->ia_uid;
5073 if ((attr->ia_valid & ATTR_GID) != 0)
5074 inode->i_gid = attr->ia_gid;
5075 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5076 + inode->i_tag = attr->ia_tag;
5077 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5078 spin_unlock(&inode->i_lock);
5080 @@ -1092,7 +1101,9 @@ static int nfs_check_inode_attributes(st
5081 struct nfs_inode *nfsi = NFS_I(inode);
5082 loff_t cur_size, new_isize;
5083 unsigned long invalid = 0;
5089 if (nfs_have_delegated_attributes(inode))
5091 @@ -1117,13 +1128,18 @@ static int nfs_check_inode_attributes(st
5092 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5095 + kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
5096 + kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
5097 + ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
5099 /* Have any file permissions changed? */
5100 if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5101 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5102 - if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5103 + if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5104 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5105 - if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5106 + if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5107 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5108 + /* maybe check for tag too? */
5110 /* Has the link count changed? */
5111 if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5112 @@ -1440,6 +1456,9 @@ static int nfs_update_inode(struct inode
5113 unsigned long invalid = 0;
5114 unsigned long now = jiffies;
5115 unsigned long save_cache_validity;
5120 dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5121 __func__, inode->i_sb->s_id, inode->i_ino,
5122 @@ -1541,6 +1560,9 @@ static int nfs_update_inode(struct inode
5123 | NFS_INO_REVAL_PAGECACHE
5124 | NFS_INO_REVAL_FORCED);
5126 + kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5127 + kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5128 + ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
5130 if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5131 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5132 @@ -1583,6 +1605,10 @@ static int nfs_update_inode(struct inode
5133 | NFS_INO_INVALID_ACL
5134 | NFS_INO_REVAL_FORCED);
5136 + inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5137 + inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5138 + inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
5140 if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5141 if (inode->i_nlink != fattr->nlink) {
5142 invalid |= NFS_INO_INVALID_ATTR;
5143 diff -NurpP --minimal linux-3.13.6/fs/nfs/nfs3xdr.c linux-3.13.6-vs2.3.6.11/fs/nfs/nfs3xdr.c
5144 --- linux-3.13.6/fs/nfs/nfs3xdr.c 2013-05-31 13:45:24.000000000 +0000
5145 +++ linux-3.13.6-vs2.3.6.11/fs/nfs/nfs3xdr.c 2014-01-31 20:38:03.000000000 +0000
5147 #include <linux/nfs3.h>
5148 #include <linux/nfs_fs.h>
5149 #include <linux/nfsacl.h>
5150 +#include <linux/vs_tag.h>
5151 #include "internal.h"
5153 #define NFSDBG_FACILITY NFSDBG_XDR
5154 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5158 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5159 +static void encode_sattr3(struct xdr_stream *xdr,
5160 + const struct iattr *attr, int tag)
5164 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5168 - if (attr->ia_valid & ATTR_UID) {
5169 + if (attr->ia_valid & ATTR_UID ||
5170 + (tag && (attr->ia_valid & ATTR_TAG))) {
5172 - *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5173 + *p++ = cpu_to_be32(from_kuid(&init_user_ns,
5174 + TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
5178 - if (attr->ia_valid & ATTR_GID) {
5179 + if (attr->ia_valid & ATTR_GID ||
5180 + (tag && (attr->ia_valid & ATTR_TAG))) {
5182 - *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5183 + *p++ = cpu_to_be32(from_kgid(&init_user_ns,
5184 + TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
5188 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5189 const struct nfs3_sattrargs *args)
5191 encode_nfs_fh3(xdr, args->fh);
5192 - encode_sattr3(xdr, args->sattr);
5193 + encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5194 encode_sattrguard3(xdr, args);
5197 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5200 static void encode_createhow3(struct xdr_stream *xdr,
5201 - const struct nfs3_createargs *args)
5202 + const struct nfs3_createargs *args, int tag)
5204 encode_uint32(xdr, args->createmode);
5205 switch (args->createmode) {
5206 case NFS3_CREATE_UNCHECKED:
5207 case NFS3_CREATE_GUARDED:
5208 - encode_sattr3(xdr, args->sattr);
5209 + encode_sattr3(xdr, args->sattr, tag);
5211 case NFS3_CREATE_EXCLUSIVE:
5212 encode_createverf3(xdr, args->verifier);
5213 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5214 const struct nfs3_createargs *args)
5216 encode_diropargs3(xdr, args->fh, args->name, args->len);
5217 - encode_createhow3(xdr, args);
5218 + encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5222 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5223 const struct nfs3_mkdirargs *args)
5225 encode_diropargs3(xdr, args->fh, args->name, args->len);
5226 - encode_sattr3(xdr, args->sattr);
5227 + encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5231 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5234 static void encode_symlinkdata3(struct xdr_stream *xdr,
5235 - const struct nfs3_symlinkargs *args)
5236 + const struct nfs3_symlinkargs *args, int tag)
5238 - encode_sattr3(xdr, args->sattr);
5239 + encode_sattr3(xdr, args->sattr, tag);
5240 encode_nfspath3(xdr, args->pages, args->pathlen);
5243 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5244 const struct nfs3_symlinkargs *args)
5246 encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5247 - encode_symlinkdata3(xdr, args);
5248 + encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5252 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5255 static void encode_devicedata3(struct xdr_stream *xdr,
5256 - const struct nfs3_mknodargs *args)
5257 + const struct nfs3_mknodargs *args, int tag)
5259 - encode_sattr3(xdr, args->sattr);
5260 + encode_sattr3(xdr, args->sattr, tag);
5261 encode_specdata3(xdr, args->rdev);
5264 static void encode_mknoddata3(struct xdr_stream *xdr,
5265 - const struct nfs3_mknodargs *args)
5266 + const struct nfs3_mknodargs *args, int tag)
5268 encode_ftype3(xdr, args->type);
5269 switch (args->type) {
5272 - encode_devicedata3(xdr, args);
5273 + encode_devicedata3(xdr, args, tag);
5277 - encode_sattr3(xdr, args->sattr);
5278 + encode_sattr3(xdr, args->sattr, tag);
5282 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5283 const struct nfs3_mknodargs *args)
5285 encode_diropargs3(xdr, args->fh, args->name, args->len);
5286 - encode_mknoddata3(xdr, args);
5287 + encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5291 diff -NurpP --minimal linux-3.13.6/fs/nfs/super.c linux-3.13.6-vs2.3.6.11/fs/nfs/super.c
5292 --- linux-3.13.6/fs/nfs/super.c 2014-01-22 20:39:06.000000000 +0000
5293 +++ linux-3.13.6-vs2.3.6.11/fs/nfs/super.c 2014-01-31 20:38:03.000000000 +0000
5295 #include <linux/parser.h>
5296 #include <linux/nsproxy.h>
5297 #include <linux/rcupdate.h>
5298 +#include <linux/vs_tag.h>
5300 #include <asm/uaccess.h>
5302 @@ -103,6 +104,7 @@ enum {
5308 /* Mount options that take string arguments */
5310 @@ -115,6 +117,9 @@ enum {
5311 /* Special mount options */
5312 Opt_userspace, Opt_deprecated, Opt_sloppy,
5314 + /* Linux-VServer tagging options */
5315 + Opt_tag, Opt_notag,
5320 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5321 { Opt_fscache_uniq, "fsc=%s" },
5322 { Opt_local_lock, "local_lock=%s" },
5324 + { Opt_tag, "tag" },
5325 + { Opt_notag, "notag" },
5326 + { Opt_tagid, "tagid=%u" },
5328 /* The following needs to be listed after all other options */
5329 { Opt_nfsvers, "v%s" },
5331 @@ -638,6 +647,7 @@ static void nfs_show_mount_options(struc
5332 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5333 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5334 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5335 + { NFS_MOUNT_TAGGED, ",tag", "" },
5338 const struct proc_nfs_info *nfs_infop;
5339 @@ -1321,6 +1331,14 @@ static int nfs_parse_mount_options(char
5340 case Opt_nomigration:
5341 mnt->options &= NFS_OPTION_MIGRATION;
5343 +#ifndef CONFIG_TAGGING_NONE
5345 + mnt->flags |= NFS_MOUNT_TAGGED;
5348 + mnt->flags &= ~NFS_MOUNT_TAGGED;
5353 * options that take numeric values
5354 @@ -1407,6 +1425,12 @@ static int nfs_parse_mount_options(char
5355 goto out_invalid_value;
5356 mnt->minorversion = option;
5358 +#ifdef CONFIG_PROPAGATE
5361 + nfs_data.flags |= NFS_MOUNT_TAGGED;
5366 * options that take text values
5367 diff -NurpP --minimal linux-3.13.6/fs/nfsd/auth.c linux-3.13.6-vs2.3.6.11/fs/nfsd/auth.c
5368 --- linux-3.13.6/fs/nfsd/auth.c 2013-05-31 13:45:24.000000000 +0000
5369 +++ linux-3.13.6-vs2.3.6.11/fs/nfsd/auth.c 2014-01-31 20:38:03.000000000 +0000
5372 #include <linux/sched.h>
5373 #include <linux/user_namespace.h>
5374 +#include <linux/vs_tag.h>
5378 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5380 new->fsuid = rqstp->rq_cred.cr_uid;
5381 new->fsgid = rqstp->rq_cred.cr_gid;
5382 + /* FIXME: this desperately needs a tag :)
5383 + new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5386 rqgi = rqstp->rq_cred.cr_group_info;
5388 diff -NurpP --minimal linux-3.13.6/fs/nfsd/nfs3xdr.c linux-3.13.6-vs2.3.6.11/fs/nfsd/nfs3xdr.c
5389 --- linux-3.13.6/fs/nfsd/nfs3xdr.c 2013-05-31 13:45:24.000000000 +0000
5390 +++ linux-3.13.6-vs2.3.6.11/fs/nfsd/nfs3xdr.c 2014-01-31 20:38:03.000000000 +0000
5393 #include <linux/namei.h>
5394 #include <linux/sunrpc/svc_xprt.h>
5395 +#include <linux/vs_tag.h>
5399 @@ -98,6 +99,8 @@ static __be32 *
5400 decode_sattr3(__be32 *p, struct iattr *iap)
5403 + kuid_t kuid = GLOBAL_ROOT_UID;
5404 + kgid_t kgid = GLOBAL_ROOT_GID;
5408 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5409 iap->ia_mode = ntohl(*p++);
5412 - iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5413 + kuid = make_kuid(&init_user_ns, ntohl(*p++));
5414 if (uid_valid(iap->ia_uid))
5415 iap->ia_valid |= ATTR_UID;
5418 - iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5419 + kgid = make_kgid(&init_user_ns, ntohl(*p++));
5420 if (gid_valid(iap->ia_gid))
5421 iap->ia_valid |= ATTR_GID;
5423 + iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5424 + iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5425 + iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5429 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5430 *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5431 *p++ = htonl((u32) stat->mode);
5432 *p++ = htonl((u32) stat->nlink);
5433 - *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5434 - *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5435 + *p++ = htonl((u32) from_kuid(&init_user_ns,
5436 + TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5437 + stat->uid, stat->tag)));
5438 + *p++ = htonl((u32) from_kgid(&init_user_ns,
5439 + TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5440 + stat->gid, stat->tag)));
5441 if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5442 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5444 diff -NurpP --minimal linux-3.13.6/fs/nfsd/nfs4xdr.c linux-3.13.6-vs2.3.6.11/fs/nfsd/nfs4xdr.c
5445 --- linux-3.13.6/fs/nfsd/nfs4xdr.c 2014-01-22 20:39:06.000000000 +0000
5446 +++ linux-3.13.6-vs2.3.6.11/fs/nfsd/nfs4xdr.c 2014-01-31 20:38:03.000000000 +0000
5448 #include <linux/utsname.h>
5449 #include <linux/pagemap.h>
5450 #include <linux/sunrpc/svcauth_gss.h>
5451 +#include <linux/vs_tag.h>
5455 @@ -2430,14 +2431,18 @@ out_acl:
5456 WRITE32(stat.nlink);
5458 if (bmval1 & FATTR4_WORD1_OWNER) {
5459 - status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5460 + status = nfsd4_encode_user(rqstp,
5461 + TAGINO_KUID(DX_TAG(dentry->d_inode),
5462 + stat.uid, stat.tag), &p, &buflen);
5463 if (status == nfserr_resource)
5468 if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5469 - status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5470 + status = nfsd4_encode_group(rqstp,
5471 + TAGINO_KGID(DX_TAG(dentry->d_inode),
5472 + stat.gid, stat.tag), &p, &buflen);
5473 if (status == nfserr_resource)
5476 diff -NurpP --minimal linux-3.13.6/fs/nfsd/nfsxdr.c linux-3.13.6-vs2.3.6.11/fs/nfsd/nfsxdr.c
5477 --- linux-3.13.6/fs/nfsd/nfsxdr.c 2013-05-31 13:45:24.000000000 +0000
5478 +++ linux-3.13.6-vs2.3.6.11/fs/nfsd/nfsxdr.c 2014-01-31 20:38:03.000000000 +0000
5483 +#include <linux/vs_tag.h>
5485 #define NFSDDBG_FACILITY NFSDDBG_XDR
5487 @@ -89,6 +90,8 @@ static __be32 *
5488 decode_sattr(__be32 *p, struct iattr *iap)
5491 + kuid_t kuid = GLOBAL_ROOT_UID;
5492 + kgid_t kgid = GLOBAL_ROOT_GID;
5496 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5499 if ((tmp = ntohl(*p++)) != (u32)-1) {
5500 - iap->ia_uid = make_kuid(&init_user_ns, tmp);
5501 + kuid = make_kuid(&init_user_ns, tmp);
5502 if (uid_valid(iap->ia_uid))
5503 iap->ia_valid |= ATTR_UID;
5505 if ((tmp = ntohl(*p++)) != (u32)-1) {
5506 - iap->ia_gid = make_kgid(&init_user_ns, tmp);
5507 + kgid = make_kgid(&init_user_ns, tmp);
5508 if (gid_valid(iap->ia_gid))
5509 iap->ia_valid |= ATTR_GID;
5511 + iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5512 + iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5513 + iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5514 if ((tmp = ntohl(*p++)) != (u32)-1) {
5515 iap->ia_valid |= ATTR_SIZE;
5517 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5518 *p++ = htonl(nfs_ftypes[type >> 12]);
5519 *p++ = htonl((u32) stat->mode);
5520 *p++ = htonl((u32) stat->nlink);
5521 - *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5522 - *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5523 + *p++ = htonl((u32) from_kuid(&init_user_ns,
5524 + TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5525 + *p++ = htonl((u32) from_kgid(&init_user_ns,
5526 + TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5528 if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5529 *p++ = htonl(NFS_MAXPATHLEN);
5530 diff -NurpP --minimal linux-3.13.6/fs/ocfs2/dlmglue.c linux-3.13.6-vs2.3.6.11/fs/ocfs2/dlmglue.c
5531 --- linux-3.13.6/fs/ocfs2/dlmglue.c 2014-01-22 20:39:07.000000000 +0000
5532 +++ linux-3.13.6-vs2.3.6.11/fs/ocfs2/dlmglue.c 2014-01-31 20:38:03.000000000 +0000
5533 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5534 lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5535 lvb->lvb_iuid = cpu_to_be32(i_uid_read(inode));
5536 lvb->lvb_igid = cpu_to_be32(i_gid_read(inode));
5537 + lvb->lvb_itag = cpu_to_be16(i_tag_read(inode));
5538 lvb->lvb_imode = cpu_to_be16(inode->i_mode);
5539 lvb->lvb_inlink = cpu_to_be16(inode->i_nlink);
5540 lvb->lvb_iatime_packed =
5541 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5543 i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5544 i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5545 + i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5546 inode->i_mode = be16_to_cpu(lvb->lvb_imode);
5547 set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5548 ocfs2_unpack_timespec(&inode->i_atime,
5549 diff -NurpP --minimal linux-3.13.6/fs/ocfs2/dlmglue.h linux-3.13.6-vs2.3.6.11/fs/ocfs2/dlmglue.h
5550 --- linux-3.13.6/fs/ocfs2/dlmglue.h 2012-12-11 03:30:57.000000000 +0000
5551 +++ linux-3.13.6-vs2.3.6.11/fs/ocfs2/dlmglue.h 2014-01-31 20:38:03.000000000 +0000
5552 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5555 __be32 lvb_igeneration;
5556 - __be32 lvb_reserved2;
5558 + __be16 lvb_reserved2;
5561 #define OCFS2_QINFO_LVB_VERSION 1
5562 diff -NurpP --minimal linux-3.13.6/fs/ocfs2/file.c linux-3.13.6-vs2.3.6.11/fs/ocfs2/file.c
5563 --- linux-3.13.6/fs/ocfs2/file.c 2014-01-22 20:39:07.000000000 +0000
5564 +++ linux-3.13.6-vs2.3.6.11/fs/ocfs2/file.c 2014-01-31 20:38:03.000000000 +0000
5565 @@ -1119,7 +1119,7 @@ int ocfs2_setattr(struct dentry *dentry,
5566 attr->ia_valid &= ~ATTR_SIZE;
5568 #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5569 - | ATTR_GID | ATTR_UID | ATTR_MODE)
5570 + | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5571 if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5574 diff -NurpP --minimal linux-3.13.6/fs/ocfs2/inode.c linux-3.13.6-vs2.3.6.11/fs/ocfs2/inode.c
5575 --- linux-3.13.6/fs/ocfs2/inode.c 2014-01-22 20:39:07.000000000 +0000
5576 +++ linux-3.13.6-vs2.3.6.11/fs/ocfs2/inode.c 2014-01-31 20:38:03.000000000 +0000
5578 #include <linux/highmem.h>
5579 #include <linux/pagemap.h>
5580 #include <linux/quotaops.h>
5581 +#include <linux/vs_tag.h>
5583 #include <asm/byteorder.h>
5585 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5587 unsigned int flags = OCFS2_I(inode)->ip_attr;
5589 - inode->i_flags &= ~(S_IMMUTABLE |
5590 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5591 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5593 if (flags & OCFS2_IMMUTABLE_FL)
5594 inode->i_flags |= S_IMMUTABLE;
5595 + if (flags & OCFS2_IXUNLINK_FL)
5596 + inode->i_flags |= S_IXUNLINK;
5598 if (flags & OCFS2_SYNC_FL)
5599 inode->i_flags |= S_SYNC;
5600 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5601 inode->i_flags |= S_NOATIME;
5602 if (flags & OCFS2_DIRSYNC_FL)
5603 inode->i_flags |= S_DIRSYNC;
5605 + inode->i_vflags &= ~(V_BARRIER | V_COW);
5607 + if (flags & OCFS2_BARRIER_FL)
5608 + inode->i_vflags |= V_BARRIER;
5609 + if (flags & OCFS2_COW_FL)
5610 + inode->i_vflags |= V_COW;
5613 /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5614 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5616 unsigned int flags = oi->vfs_inode.i_flags;
5617 + unsigned int vflags = oi->vfs_inode.i_vflags;
5619 + oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5620 + OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5621 + OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5622 + OCFS2_BARRIER_FL | OCFS2_COW_FL);
5624 + if (flags & S_IMMUTABLE)
5625 + oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5626 + if (flags & S_IXUNLINK)
5627 + oi->ip_attr |= OCFS2_IXUNLINK_FL;
5629 - oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5630 - OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5632 oi->ip_attr |= OCFS2_SYNC_FL;
5633 if (flags & S_APPEND)
5634 oi->ip_attr |= OCFS2_APPEND_FL;
5635 - if (flags & S_IMMUTABLE)
5636 - oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5637 if (flags & S_NOATIME)
5638 oi->ip_attr |= OCFS2_NOATIME_FL;
5639 if (flags & S_DIRSYNC)
5640 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5642 + if (vflags & V_BARRIER)
5643 + oi->ip_attr |= OCFS2_BARRIER_FL;
5644 + if (vflags & V_COW)
5645 + oi->ip_attr |= OCFS2_COW_FL;
5648 struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5649 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5650 struct super_block *sb;
5651 struct ocfs2_super *osb;
5658 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5659 inode->i_generation = le32_to_cpu(fe->i_generation);
5660 inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5661 inode->i_mode = le16_to_cpu(fe->i_mode);
5662 - i_uid_write(inode, le32_to_cpu(fe->i_uid));
5663 - i_gid_write(inode, le32_to_cpu(fe->i_gid));
5664 + uid = le32_to_cpu(fe->i_uid);
5665 + gid = le32_to_cpu(fe->i_gid);
5666 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5667 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5668 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5669 + /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5671 /* Fast symlinks will have i_size but no allocated clusters. */
5672 if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5673 diff -NurpP --minimal linux-3.13.6/fs/ocfs2/inode.h linux-3.13.6-vs2.3.6.11/fs/ocfs2/inode.h
5674 --- linux-3.13.6/fs/ocfs2/inode.h 2013-07-14 17:01:29.000000000 +0000
5675 +++ linux-3.13.6-vs2.3.6.11/fs/ocfs2/inode.h 2014-01-31 20:38:03.000000000 +0000
5676 @@ -152,6 +152,7 @@ struct buffer_head *ocfs2_bread(struct i
5678 void ocfs2_set_inode_flags(struct inode *inode);
5679 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5680 +int ocfs2_sync_flags(struct inode *inode, int, int);
5682 static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5684 diff -NurpP --minimal linux-3.13.6/fs/ocfs2/ioctl.c linux-3.13.6-vs2.3.6.11/fs/ocfs2/ioctl.c
5685 --- linux-3.13.6/fs/ocfs2/ioctl.c 2013-11-25 15:47:00.000000000 +0000
5686 +++ linux-3.13.6-vs2.3.6.11/fs/ocfs2/ioctl.c 2014-01-31 20:38:03.000000000 +0000
5687 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5691 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5692 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5694 + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5695 + struct buffer_head *bh = NULL;
5696 + handle_t *handle = NULL;
5699 + status = ocfs2_inode_lock(inode, &bh, 1);
5701 + mlog_errno(status);
5704 + handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5705 + if (IS_ERR(handle)) {
5706 + status = PTR_ERR(handle);
5707 + mlog_errno(status);
5711 + inode->i_flags = flags;
5712 + inode->i_vflags = vflags;
5713 + ocfs2_get_inode_flags(OCFS2_I(inode));
5715 + status = ocfs2_mark_inode_dirty(handle, inode, bh);
5717 + mlog_errno(status);
5719 + ocfs2_commit_trans(osb, handle);
5721 + ocfs2_inode_unlock(inode, 1);
5726 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5729 struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5730 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5734 + if (IS_BARRIER(inode)) {
5735 + vxwprintk_task(1, "messing with the barrier.");
5739 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5740 if (IS_ERR(handle)) {
5741 status = PTR_ERR(handle);
5742 @@ -881,6 +920,7 @@ bail:
5747 long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5749 struct inode *inode = file_inode(filp);
5750 diff -NurpP --minimal linux-3.13.6/fs/ocfs2/namei.c linux-3.13.6-vs2.3.6.11/fs/ocfs2/namei.c
5751 --- linux-3.13.6/fs/ocfs2/namei.c 2014-01-22 20:39:07.000000000 +0000
5752 +++ linux-3.13.6-vs2.3.6.11/fs/ocfs2/namei.c 2014-01-31 20:38:03.000000000 +0000
5754 #include <linux/slab.h>
5755 #include <linux/highmem.h>
5756 #include <linux/quotaops.h>
5757 +#include <linux/vs_tag.h>
5759 #include <cluster/masklog.h>
5761 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5762 struct ocfs2_dinode *fe = NULL;
5763 struct ocfs2_extent_list *fel;
5769 @@ -512,8 +514,13 @@ static int __ocfs2_mknod_locked(struct i
5770 fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5771 fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5772 fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5773 - fe->i_uid = cpu_to_le32(i_uid_read(inode));
5774 - fe->i_gid = cpu_to_le32(i_gid_read(inode));
5776 + ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5777 + fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5778 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5779 + fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5780 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5781 + inode->i_tag = ktag; /* is this correct? */
5782 fe->i_mode = cpu_to_le16(inode->i_mode);
5783 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5784 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5785 diff -NurpP --minimal linux-3.13.6/fs/ocfs2/ocfs2.h linux-3.13.6-vs2.3.6.11/fs/ocfs2/ocfs2.h
5786 --- linux-3.13.6/fs/ocfs2/ocfs2.h 2013-11-25 15:45:04.000000000 +0000
5787 +++ linux-3.13.6-vs2.3.6.11/fs/ocfs2/ocfs2.h 2014-01-31 20:38:03.000000000 +0000
5788 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5790 OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5791 OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5792 + OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5795 #define OCFS2_OSB_SOFT_RO 0x0001
5796 diff -NurpP --minimal linux-3.13.6/fs/ocfs2/ocfs2_fs.h linux-3.13.6-vs2.3.6.11/fs/ocfs2/ocfs2_fs.h
5797 --- linux-3.13.6/fs/ocfs2/ocfs2_fs.h 2012-12-11 03:30:57.000000000 +0000
5798 +++ linux-3.13.6-vs2.3.6.11/fs/ocfs2/ocfs2_fs.h 2014-01-31 20:38:03.000000000 +0000
5799 @@ -266,6 +266,11 @@
5800 #define OCFS2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
5801 #define OCFS2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
5803 +#define OCFS2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
5805 +#define OCFS2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
5806 +#define OCFS2_COW_FL FS_COW_FL /* Copy on Write marker */
5808 #define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
5809 #define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
5811 diff -NurpP --minimal linux-3.13.6/fs/ocfs2/super.c linux-3.13.6-vs2.3.6.11/fs/ocfs2/super.c
5812 --- linux-3.13.6/fs/ocfs2/super.c 2014-01-22 20:39:07.000000000 +0000
5813 +++ linux-3.13.6-vs2.3.6.11/fs/ocfs2/super.c 2014-01-31 20:38:03.000000000 +0000
5814 @@ -185,6 +185,7 @@ enum {
5818 + Opt_tag, Opt_notag, Opt_tagid,
5822 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5823 {Opt_coherency_full, "coherency=full"},
5824 {Opt_resv_level, "resv_level=%u"},
5825 {Opt_dir_resv_level, "dir_resv_level=%u"},
5827 + {Opt_notag, "notag"},
5828 + {Opt_tagid, "tagid=%u"},
5832 @@ -661,6 +665,13 @@ static int ocfs2_remount(struct super_bl
5836 + if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5837 + (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5839 + mlog(ML_ERROR, "Cannot change tagging on remount\n");
5843 /* We're going to/from readonly mode. */
5844 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5845 /* Disable quota accounting before remounting RO */
5846 @@ -1176,6 +1187,9 @@ static int ocfs2_fill_super(struct super
5848 ocfs2_complete_mount_recovery(osb);
5850 + if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5851 + sb->s_flags |= MS_TAGGED;
5853 if (ocfs2_mount_local(osb))
5854 snprintf(nodestr, sizeof(nodestr), "local");
5856 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
5857 option < OCFS2_MAX_RESV_LEVEL)
5858 mopt->dir_resv_level = option;
5860 +#ifndef CONFIG_TAGGING_NONE
5862 + mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5865 + mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5868 +#ifdef CONFIG_PROPAGATE
5871 + mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5876 "Unrecognized mount option \"%s\" "
5877 diff -NurpP --minimal linux-3.13.6/fs/open.c linux-3.13.6-vs2.3.6.11/fs/open.c
5878 --- linux-3.13.6/fs/open.c 2014-01-22 20:39:07.000000000 +0000
5879 +++ linux-3.13.6-vs2.3.6.11/fs/open.c 2014-01-31 20:38:03.000000000 +0000
5881 #include <linux/ima.h>
5882 #include <linux/dnotify.h>
5883 #include <linux/compat.h>
5884 +#include <linux/vs_base.h>
5885 +#include <linux/vs_limit.h>
5886 +#include <linux/vs_tag.h>
5887 +#include <linux/vs_cowbl.h>
5888 +#include <linux/vserver/dlimit.h>
5890 #include "internal.h"
5892 @@ -68,6 +73,11 @@ long vfs_truncate(struct path *path, lof
5893 struct inode *inode;
5896 +#ifdef CONFIG_VSERVER_COWBL
5897 + error = cow_check_and_break(path);
5901 inode = path->dentry->d_inode;
5903 /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5904 @@ -511,6 +521,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5905 unsigned int lookup_flags = LOOKUP_FOLLOW;
5907 error = user_path_at(dfd, filename, lookup_flags, &path);
5908 +#ifdef CONFIG_VSERVER_COWBL
5910 + error = cow_check_and_break(&path);
5916 error = chmod_common(&path, mode);
5918 @@ -544,13 +561,15 @@ static int chown_common(struct path *pat
5919 if (!uid_valid(uid))
5921 newattrs.ia_valid |= ATTR_UID;
5922 - newattrs.ia_uid = uid;
5923 + newattrs.ia_uid = make_kuid(&init_user_ns,
5924 + dx_map_uid(user));
5926 if (group != (gid_t) -1) {
5927 if (!gid_valid(gid))
5929 newattrs.ia_valid |= ATTR_GID;
5930 - newattrs.ia_gid = gid;
5931 + newattrs.ia_gid = make_kgid(&init_user_ns,
5932 + dx_map_gid(group));
5934 if (!S_ISDIR(inode->i_mode))
5935 newattrs.ia_valid |=
5936 @@ -589,6 +608,18 @@ retry:
5937 error = mnt_want_write(path.mnt);
5940 +#ifdef CONFIG_VSERVER_COWBL
5941 + error = cow_check_and_break(&path);
5944 +#ifdef CONFIG_VSERVER_COWBL
5945 + error = cow_check_and_break(&path);
5948 +#ifdef CONFIG_VSERVER_COWBL
5949 + error = cow_check_and_break(&path);
5952 error = chown_common(&path, user, group);
5953 mnt_drop_write(path.mnt);
5955 diff -NurpP --minimal linux-3.13.6/fs/proc/array.c linux-3.13.6-vs2.3.6.11/fs/proc/array.c
5956 --- linux-3.13.6/fs/proc/array.c 2014-01-22 20:39:07.000000000 +0000
5957 +++ linux-3.13.6-vs2.3.6.11/fs/proc/array.c 2014-02-01 01:44:54.000000000 +0000
5959 #include <linux/ptrace.h>
5960 #include <linux/tracehook.h>
5961 #include <linux/user_namespace.h>
5962 +#include <linux/vs_context.h>
5963 +#include <linux/vs_network.h>
5965 #include <asm/pgtable.h>
5966 #include <asm/processor.h>
5967 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
5969 ppid = pid_alive(p) ?
5970 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5971 + if (unlikely(vx_current_initpid(p->pid)))
5976 struct task_struct *tracer = ptrace_parent(p);
5977 @@ -299,7 +304,7 @@ static inline void task_sig(struct seq_f
5980 static void render_cap_t(struct seq_file *m, const char *header,
5982 + struct vx_info *vxi, kernel_cap_t *a)
5986 @@ -333,10 +338,11 @@ static inline void task_cap(struct seq_f
5987 NORM_CAPS(cap_effective);
5988 NORM_CAPS(cap_bset);
5990 - render_cap_t(m, "CapInh:\t", &cap_inheritable);
5991 - render_cap_t(m, "CapPrm:\t", &cap_permitted);
5992 - render_cap_t(m, "CapEff:\t", &cap_effective);
5993 - render_cap_t(m, "CapBnd:\t", &cap_bset);
5994 + /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5995 + render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5996 + render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5997 + render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5998 + render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6001 static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
6002 @@ -365,6 +371,43 @@ static void task_cpus_allowed(struct seq
6006 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6007 + struct pid *pid, struct task_struct *task)
6009 + seq_printf(m, "Proxy:\t%p(%c)\n"
6017 + (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6018 + atomic_read(&task->nsproxy->count),
6019 + task->nsproxy->uts_ns,
6020 + (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6021 + task->nsproxy->ipc_ns,
6022 + (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6023 + task->nsproxy->mnt_ns,
6024 + (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6025 + task->nsproxy->pid_ns_for_children,
6026 + (task->nsproxy->pid_ns_for_children ==
6027 + init_task.nsproxy->pid_ns_for_children ? 'I' : '-'),
6028 + task->nsproxy->net_ns,
6029 + (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6033 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6035 + if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6038 + seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6039 + seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6043 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6044 struct pid *pid, struct task_struct *task)
6046 @@ -382,6 +425,7 @@ int proc_pid_status(struct seq_file *m,
6047 task_seccomp(m, task);
6048 task_cpus_allowed(m, task);
6049 cpuset_task_status_allowed(m, task);
6050 + task_vs_id(m, task);
6051 task_context_switch_counts(m, task);
6054 @@ -491,6 +535,17 @@ static int do_task_stat(struct seq_file
6055 /* convert nsec -> ticks */
6056 start_time = nsec_to_clock_t(start_time);
6058 + /* fixup start time for virt uptime */
6059 + if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6060 + unsigned long long bias =
6061 + current->vx_info->cvirt.bias_clock;
6063 + if (start_time > bias)
6064 + start_time -= bias;
6069 seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6070 seq_put_decimal_ll(m, ' ', ppid);
6071 seq_put_decimal_ll(m, ' ', pgid);
6072 diff -NurpP --minimal linux-3.13.6/fs/proc/base.c linux-3.13.6-vs2.3.6.11/fs/proc/base.c
6073 --- linux-3.13.6/fs/proc/base.c 2014-01-22 20:39:07.000000000 +0000
6074 +++ linux-3.13.6-vs2.3.6.11/fs/proc/base.c 2014-02-01 00:05:10.000000000 +0000
6076 #include <linux/slab.h>
6077 #include <linux/flex_array.h>
6078 #include <linux/posix-timers.h>
6079 +#include <linux/vs_context.h>
6080 +#include <linux/vs_network.h>
6081 #ifdef CONFIG_HARDWALL
6082 #include <asm/hardwall.h>
6084 @@ -976,11 +978,15 @@ static ssize_t oom_adj_write(struct file
6085 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6087 if (oom_adj < task->signal->oom_score_adj &&
6088 - !capable(CAP_SYS_RESOURCE)) {
6089 + !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6094 + /* prevent guest processes from circumventing the oom killer */
6095 + if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6096 + oom_adj = OOM_ADJUST_MIN;
6099 * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6100 * /proc/pid/oom_score_adj instead.
6101 @@ -1565,6 +1571,8 @@ struct inode *proc_pid_make_inode(struct
6102 inode->i_gid = cred->egid;
6105 + /* procfs is xid tagged */
6106 + i_tag_write(inode, (vtag_t)vx_task_xid(task));
6107 security_task_to_inode(task, inode);
6110 @@ -1610,6 +1618,8 @@ int pid_getattr(struct vfsmount *mnt, st
6114 +static unsigned name_to_int(struct dentry *dentry);
6117 * Exceptional case: normally we are not allowed to unhash a busy
6118 * directory. In this case, however, we can do it - no aliasing problems
6119 @@ -1638,6 +1648,12 @@ int pid_revalidate(struct dentry *dentry
6120 task = get_proc_task(inode);
6123 + unsigned pid = name_to_int(dentry);
6125 + if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6126 + put_task_struct(task);
6129 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6130 task_dumpable(task)) {
6132 @@ -1654,6 +1670,7 @@ int pid_revalidate(struct dentry *dentry
6133 put_task_struct(task);
6140 @@ -2172,6 +2189,13 @@ static struct dentry *proc_pident_lookup
6144 + /* TODO: maybe we can come up with a generic approach? */
6145 + if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6146 + (dentry->d_name.len == 5) &&
6147 + (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6148 + !memcmp(dentry->d_name.name, "ninfo", 5)))
6152 * Yes, it does not scale. And it should not. Don't add
6153 * new entries into /proc/<tgid>/ without very good reasons.
6154 @@ -2568,6 +2592,9 @@ static int proc_pid_personality(struct s
6155 static const struct file_operations proc_task_operations;
6156 static const struct inode_operations proc_task_inode_operations;
6158 +extern int proc_pid_vx_info(struct task_struct *, char *);
6159 +extern int proc_pid_nx_info(struct task_struct *, char *);
6161 static const struct pid_entry tgid_base_stuff[] = {
6162 DIR("task", S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6163 DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6164 @@ -2634,6 +2661,8 @@ static const struct pid_entry tgid_base_
6165 #ifdef CONFIG_CGROUPS
6166 REG("cgroup", S_IRUGO, proc_cgroup_operations),
6168 + INF("vinfo", S_IRUGO, proc_pid_vx_info),
6169 + INF("ninfo", S_IRUGO, proc_pid_nx_info),
6170 INF("oom_score", S_IRUGO, proc_oom_score),
6171 REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6172 REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6173 @@ -2846,7 +2875,7 @@ retry:
6175 pid = find_ge_pid(iter.tgid, ns);
6177 - iter.tgid = pid_nr_ns(pid, ns);
6178 + iter.tgid = pid_unmapped_nr_ns(pid, ns);
6179 iter.task = pid_task(pid, PIDTYPE_PID);
6180 /* What we to know is if the pid we have find is the
6181 * pid of a thread_group_leader. Testing for task
6182 @@ -2899,8 +2928,10 @@ int proc_pid_readdir(struct file *file,
6183 if (!has_pid_permissions(ns, iter.task, 2))
6186 - len = snprintf(name, sizeof(name), "%d", iter.tgid);
6187 + len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6188 ctx->pos = iter.tgid + TGID_OFFSET;
6189 + if (!vx_proc_task_visible(iter.task))
6191 if (!proc_fill_cache(file, ctx, name, len,
6192 proc_pid_instantiate, iter.task, NULL)) {
6193 put_task_struct(iter.task);
6194 @@ -2993,6 +3024,7 @@ static const struct pid_entry tid_base_s
6195 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
6196 REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6198 + ONE("nsproxy", S_IRUGO, proc_pid_nsproxy),
6201 static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
6202 @@ -3059,6 +3091,8 @@ static struct dentry *proc_task_lookup(s
6203 tid = name_to_int(dentry);
6206 + if (vx_current_initpid(tid))
6209 ns = dentry->d_sb->s_fs_info;
6211 diff -NurpP --minimal linux-3.13.6/fs/proc/generic.c linux-3.13.6-vs2.3.6.11/fs/proc/generic.c
6212 --- linux-3.13.6/fs/proc/generic.c 2014-01-22 20:39:07.000000000 +0000
6213 +++ linux-3.13.6-vs2.3.6.11/fs/proc/generic.c 2014-02-01 00:07:40.000000000 +0000
6215 #include <linux/bitops.h>
6216 #include <linux/spinlock.h>
6217 #include <linux/completion.h>
6218 +#include <linux/vserver/inode.h>
6219 #include <asm/uaccess.h>
6221 #include "internal.h"
6222 @@ -187,6 +188,8 @@ struct dentry *proc_lookup_de(struct pro
6223 for (de = de->subdir; de ; de = de->next) {
6224 if (de->namelen != dentry->d_name.len)
6226 + if (!vx_hide_check(0, de->vx_flags))
6228 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6230 spin_unlock(&proc_subdir_lock);
6231 @@ -195,6 +198,8 @@ struct dentry *proc_lookup_de(struct pro
6232 return ERR_PTR(-ENOMEM);
6233 d_set_d_op(dentry, &simple_dentry_operations);
6234 d_add(dentry, inode);
6235 + /* generic proc entries belong to the host */
6236 + i_tag_write(inode, 0);
6240 @@ -242,6 +247,9 @@ int proc_readdir_de(struct proc_dir_entr
6242 struct proc_dir_entry *next;
6245 + if (!vx_hide_check(0, de->vx_flags))
6247 spin_unlock(&proc_subdir_lock);
6248 if (!dir_emit(ctx, de->name, de->namelen,
6249 de->low_ino, de->mode >> 12)) {
6250 @@ -249,6 +257,7 @@ int proc_readdir_de(struct proc_dir_entr
6253 spin_lock(&proc_subdir_lock);
6258 @@ -355,6 +364,7 @@ static struct proc_dir_entry *__proc_cre
6262 + ent->vx_flags = IATTR_PROC_DEFAULT;
6263 atomic_set(&ent->count, 1);
6264 spin_lock_init(&ent->pde_unload_lock);
6265 INIT_LIST_HEAD(&ent->pde_openers);
6266 @@ -378,7 +388,8 @@ struct proc_dir_entry *proc_symlink(cons
6272 + ent->vx_flags = IATTR_PROC_SYMLINK;
6276 diff -NurpP --minimal linux-3.13.6/fs/proc/inode.c linux-3.13.6-vs2.3.6.11/fs/proc/inode.c
6277 --- linux-3.13.6/fs/proc/inode.c 2014-01-22 20:39:07.000000000 +0000
6278 +++ linux-3.13.6-vs2.3.6.11/fs/proc/inode.c 2014-01-31 20:38:03.000000000 +0000
6279 @@ -415,6 +415,8 @@ struct inode *proc_get_inode(struct supe
6280 inode->i_uid = de->uid;
6281 inode->i_gid = de->gid;
6284 + PROC_I(inode)->vx_flags = de->vx_flags;
6286 inode->i_size = de->size;
6288 diff -NurpP --minimal linux-3.13.6/fs/proc/internal.h linux-3.13.6-vs2.3.6.11/fs/proc/internal.h
6289 --- linux-3.13.6/fs/proc/internal.h 2013-11-25 15:45:04.000000000 +0000
6290 +++ linux-3.13.6-vs2.3.6.11/fs/proc/internal.h 2014-01-31 20:38:03.000000000 +0000
6292 #include <linux/spinlock.h>
6293 #include <linux/atomic.h>
6294 #include <linux/binfmts.h>
6295 +#include <linux/vs_pid.h>
6297 struct ctl_table_header;
6299 @@ -35,6 +36,7 @@ struct proc_dir_entry {
6305 const struct inode_operations *proc_iops;
6306 const struct file_operations *proc_fops;
6307 @@ -50,16 +52,23 @@ struct proc_dir_entry {
6315 int (*proc_get_link)(struct dentry *, struct path *);
6316 int (*proc_read)(struct task_struct *task, char *page);
6317 int (*proc_show)(struct seq_file *m,
6318 struct pid_namespace *ns, struct pid *pid,
6319 struct task_struct *task);
6320 + int (*proc_vs_read)(char *page);
6321 + int (*proc_vxi_read)(struct vx_info *vxi, char *page);
6322 + int (*proc_nxi_read)(struct nx_info *nxi, char *page);
6330 struct proc_dir_entry *pde;
6331 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
6332 return PROC_I(inode)->pid;
6335 -static inline struct task_struct *get_proc_task(struct inode *inode)
6336 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6338 return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6341 +static inline struct task_struct *get_proc_task(struct inode *inode)
6343 + return vx_get_proc_task(inode, proc_pid(inode));
6346 static inline int task_dumpable(struct task_struct *task)
6349 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6350 struct pid *, struct task_struct *);
6351 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6352 struct pid *, struct task_struct *);
6353 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6354 + struct pid *pid, struct task_struct *task);
6358 diff -NurpP --minimal linux-3.13.6/fs/proc/loadavg.c linux-3.13.6-vs2.3.6.11/fs/proc/loadavg.c
6359 --- linux-3.13.6/fs/proc/loadavg.c 2012-12-11 03:30:57.000000000 +0000
6360 +++ linux-3.13.6-vs2.3.6.11/fs/proc/loadavg.c 2014-01-31 20:38:03.000000000 +0000
6363 static int loadavg_proc_show(struct seq_file *m, void *v)
6365 + unsigned long running;
6366 + unsigned int threads;
6367 unsigned long avnrun[3];
6369 get_avenrun(avnrun, FIXED_1/200, 0);
6371 + if (vx_flags(VXF_VIRT_LOAD, 0)) {
6372 + struct vx_info *vxi = current_vx_info();
6374 + running = atomic_read(&vxi->cvirt.nr_running);
6375 + threads = atomic_read(&vxi->cvirt.nr_threads);
6377 + running = nr_running();
6378 + threads = nr_threads;
6381 seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6382 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6383 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6384 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6385 - nr_running(), nr_threads,
6387 task_active_pid_ns(current)->last_pid);
6390 diff -NurpP --minimal linux-3.13.6/fs/proc/meminfo.c linux-3.13.6-vs2.3.6.11/fs/proc/meminfo.c
6391 --- linux-3.13.6/fs/proc/meminfo.c 2014-01-22 20:39:07.000000000 +0000
6392 +++ linux-3.13.6-vs2.3.6.11/fs/proc/meminfo.c 2014-01-31 20:38:03.000000000 +0000
6393 @@ -37,7 +37,8 @@ static int meminfo_proc_show(struct seq_
6395 committed = percpu_counter_read_positive(&vm_committed_as);
6397 - cached = global_page_state(NR_FILE_PAGES) -
6398 + cached = vx_flags(VXF_VIRT_MEM, 0) ?
6399 + vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6400 total_swapcache_pages() - i.bufferram;
6403 diff -NurpP --minimal linux-3.13.6/fs/proc/root.c linux-3.13.6-vs2.3.6.11/fs/proc/root.c
6404 --- linux-3.13.6/fs/proc/root.c 2013-11-25 15:47:00.000000000 +0000
6405 +++ linux-3.13.6-vs2.3.6.11/fs/proc/root.c 2014-02-01 00:02:11.000000000 +0000
6407 #include <linux/mount.h>
6408 #include <linux/pid_namespace.h>
6409 #include <linux/parser.h>
6410 +#include <linux/vserver/inode.h>
6412 #include "internal.h"
6414 +struct proc_dir_entry *proc_virtual;
6416 +extern void proc_vx_init(void);
6418 static int proc_test_super(struct super_block *sb, void *data)
6420 return sb->s_fs_info == data;
6421 @@ -114,7 +119,8 @@ static struct dentry *proc_mount(struct
6422 return ERR_PTR(-EPERM);
6424 /* Does the mounter have privilege over the pid namespace? */
6425 - if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
6426 + if (!vx_ns_capable(ns->user_ns,
6427 + CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6428 return ERR_PTR(-EPERM);
6431 @@ -188,6 +194,7 @@ void __init proc_root_init(void)
6433 proc_mkdir("bus", NULL);
6438 static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6439 @@ -249,6 +256,7 @@ struct proc_dir_entry proc_root = {
6440 .proc_iops = &proc_root_inode_operations,
6441 .proc_fops = &proc_root_operations,
6442 .parent = &proc_root,
6443 + .vx_flags = IATTR_ADMIN | IATTR_WATCH,
6447 diff -NurpP --minimal linux-3.13.6/fs/proc/self.c linux-3.13.6-vs2.3.6.11/fs/proc/self.c
6448 --- linux-3.13.6/fs/proc/self.c 2014-01-22 20:39:07.000000000 +0000
6449 +++ linux-3.13.6-vs2.3.6.11/fs/proc/self.c 2014-01-31 20:38:03.000000000 +0000
6451 #include <linux/namei.h>
6452 #include <linux/slab.h>
6453 #include <linux/pid_namespace.h>
6454 +#include <linux/vserver/inode.h>
6455 #include "internal.h"
6458 @@ -54,6 +55,8 @@ int proc_setup_self(struct super_block *
6459 self = d_alloc_name(s->s_root, "self");
6461 struct inode *inode = new_inode_pseudo(s);
6463 + // self->vx_flags = IATTR_PROC_SYMLINK;
6465 inode->i_ino = self_inum;
6466 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6467 diff -NurpP --minimal linux-3.13.6/fs/proc/stat.c linux-3.13.6-vs2.3.6.11/fs/proc/stat.c
6468 --- linux-3.13.6/fs/proc/stat.c 2013-07-14 17:01:29.000000000 +0000
6469 +++ linux-3.13.6-vs2.3.6.11/fs/proc/stat.c 2014-01-31 20:38:03.000000000 +0000
6471 #include <linux/slab.h>
6472 #include <linux/time.h>
6473 #include <linux/irqnr.h>
6474 +#include <linux/vserver/cvirt.h>
6475 #include <asm/cputime.h>
6476 #include <linux/tick.h>
6477 +#include <linux/cpuset.h>
6479 #ifndef arch_irq_stat_cpu
6480 #define arch_irq_stat_cpu(cpu) 0
6481 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6482 u64 sum_softirq = 0;
6483 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6484 struct timespec boottime;
6485 + cpumask_var_t cpus_allowed;
6486 + bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6488 user = nice = system = idle = iowait =
6489 irq = softirq = steal = 0;
6490 guest = guest_nice = 0;
6491 getboottime(&boottime);
6493 + if (vx_flags(VXF_VIRT_UPTIME, 0))
6494 + vx_vsi_boottime(&boottime);
6497 + cpuset_cpus_allowed(current, cpus_allowed);
6499 jif = boottime.tv_sec;
6501 for_each_possible_cpu(i) {
6502 + if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6505 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6506 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6507 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6508 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6511 for_each_online_cpu(i) {
6512 + if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6515 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6516 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6517 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6518 diff -NurpP --minimal linux-3.13.6/fs/proc/uptime.c linux-3.13.6-vs2.3.6.11/fs/proc/uptime.c
6519 --- linux-3.13.6/fs/proc/uptime.c 2013-11-25 15:45:04.000000000 +0000
6520 +++ linux-3.13.6-vs2.3.6.11/fs/proc/uptime.c 2014-01-31 20:38:03.000000000 +0000
6522 #include <linux/seq_file.h>
6523 #include <linux/time.h>
6524 #include <linux/kernel_stat.h>
6525 +#include <linux/vserver/cvirt.h>
6526 #include <asm/cputime.h>
6528 static int uptime_proc_show(struct seq_file *m, void *v)
6529 @@ -24,6 +25,10 @@ static int uptime_proc_show(struct seq_f
6530 nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6531 idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6534 + if (vx_flags(VXF_VIRT_UPTIME, 0))
6535 + vx_vsi_uptime(&uptime, &idle);
6537 seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6538 (unsigned long) uptime.tv_sec,
6539 (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6540 diff -NurpP --minimal linux-3.13.6/fs/proc_namespace.c linux-3.13.6-vs2.3.6.11/fs/proc_namespace.c
6541 --- linux-3.13.6/fs/proc_namespace.c 2014-01-22 20:39:07.000000000 +0000
6542 +++ linux-3.13.6-vs2.3.6.11/fs/proc_namespace.c 2014-02-25 12:43:16.000000000 +0000
6543 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6544 { MS_SYNCHRONOUS, ",sync" },
6545 { MS_DIRSYNC, ",dirsync" },
6546 { MS_MANDLOCK, ",mand" },
6547 + { MS_TAGGED, ",tag" },
6548 + { MS_NOTAGCHECK, ",notagcheck" },
6551 const struct proc_fs_info *fs_infop;
6552 @@ -80,6 +82,38 @@ static inline void mangle(struct seq_fil
6553 seq_escape(m, s, " \t\n\\");
6556 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6558 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6561 + struct dentry *point;
6562 + struct mount *mnt = real_mount(vfsmnt);
6563 + struct mount *root_mnt;
6566 + if (mnt == mnt->mnt_ns->root)
6570 + root = current->fs->root;
6571 + root_mnt = real_mount(root.mnt);
6572 + point = root.dentry;
6574 + while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6575 + point = mnt->mnt_mountpoint;
6576 + mnt = mnt->mnt_parent;
6578 + rcu_read_unlock();
6580 + ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6585 +#define mnt_is_reachable(v) (1)
6588 static void show_type(struct seq_file *m, struct super_block *sb)
6590 mangle(m, sb->s_type->name);
6591 @@ -96,6 +130,17 @@ static int show_vfsmnt(struct seq_file *
6592 struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6593 struct super_block *sb = mnt_path.dentry->d_sb;
6595 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6597 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6600 + if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6601 + mnt == current->fs->root.mnt) {
6602 + seq_puts(m, "/dev/root / ");
6606 if (sb->s_op->show_devname) {
6607 err = sb->s_op->show_devname(m, mnt_path.dentry);
6609 @@ -106,6 +151,7 @@ static int show_vfsmnt(struct seq_file *
6611 seq_path(m, &mnt_path, " \t\n\\");
6615 seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6616 err = show_sb_opts(m, sb);
6617 @@ -128,6 +174,11 @@ static int show_mountinfo(struct seq_fil
6618 struct path root = p->root;
6621 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6623 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6626 seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6627 MAJOR(sb->s_dev), MINOR(sb->s_dev));
6628 if (sb->s_op->show_path)
6629 @@ -187,6 +238,17 @@ static int show_vfsstat(struct seq_file
6630 struct super_block *sb = mnt_path.dentry->d_sb;
6633 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6635 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6638 + if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6639 + mnt == current->fs->root.mnt) {
6640 + seq_puts(m, "device /dev/root mounted on / ");
6645 if (sb->s_op->show_devname) {
6646 seq_puts(m, "device ");
6647 @@ -203,7 +265,7 @@ static int show_vfsstat(struct seq_file
6648 seq_puts(m, " mounted on ");
6649 seq_path(m, &mnt_path, " \t\n\\");
6653 /* file system type */
6654 seq_puts(m, "with fstype ");
6656 diff -NurpP --minimal linux-3.13.6/fs/quota/dquot.c linux-3.13.6-vs2.3.6.11/fs/quota/dquot.c
6657 --- linux-3.13.6/fs/quota/dquot.c 2014-03-12 13:51:21.000000000 +0000
6658 +++ linux-3.13.6-vs2.3.6.11/fs/quota/dquot.c 2014-03-12 15:51:07.000000000 +0000
6659 @@ -1602,6 +1602,9 @@ int __dquot_alloc_space(struct inode *in
6660 struct dquot **dquots = inode->i_dquot;
6661 int reserve = flags & DQUOT_SPACE_RESERVE;
6663 + if ((ret = dl_alloc_space(inode, number)))
6667 * First test before acquiring mutex - solves deadlocks when we
6668 * re-enter the quota code and are already holding the mutex
6669 @@ -1657,6 +1660,9 @@ int dquot_alloc_inode(const struct inode
6670 struct dquot_warn warn[MAXQUOTAS];
6671 struct dquot * const *dquots = inode->i_dquot;
6673 + if ((ret = dl_alloc_inode(inode)))
6676 /* First test before acquiring mutex - solves deadlocks when we
6677 * re-enter the quota code and are already holding the mutex */
6678 if (!dquot_active(inode))
6679 @@ -1757,6 +1763,8 @@ void __dquot_free_space(struct inode *in
6680 struct dquot **dquots = inode->i_dquot;
6681 int reserve = flags & DQUOT_SPACE_RESERVE;
6683 + dl_free_space(inode, number);
6685 /* First test before acquiring mutex - solves deadlocks when we
6686 * re-enter the quota code and are already holding the mutex */
6687 if (!dquot_active(inode)) {
6688 @@ -1801,6 +1809,8 @@ void dquot_free_inode(const struct inode
6689 struct dquot_warn warn[MAXQUOTAS];
6690 struct dquot * const *dquots = inode->i_dquot;
6692 + dl_free_inode(inode);
6694 /* First test before acquiring mutex - solves deadlocks when we
6695 * re-enter the quota code and are already holding the mutex */
6696 if (!dquot_active(inode))
6697 diff -NurpP --minimal linux-3.13.6/fs/quota/quota.c linux-3.13.6-vs2.3.6.11/fs/quota/quota.c
6698 --- linux-3.13.6/fs/quota/quota.c 2014-01-22 20:39:07.000000000 +0000
6699 +++ linux-3.13.6-vs2.3.6.11/fs/quota/quota.c 2014-01-31 20:38:03.000000000 +0000
6701 #include <linux/fs.h>
6702 #include <linux/namei.h>
6703 #include <linux/slab.h>
6704 +#include <linux/vs_context.h>
6705 #include <asm/current.h>
6706 #include <linux/uaccess.h>
6707 #include <linux/kernel.h>
6708 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6712 - if (!capable(CAP_SYS_ADMIN))
6713 + if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6717 @@ -338,6 +339,46 @@ static int do_quotactl(struct super_bloc
6721 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6723 +#include <linux/vroot.h>
6724 +#include <linux/major.h>
6725 +#include <linux/module.h>
6726 +#include <linux/kallsyms.h>
6727 +#include <linux/vserver/debug.h>
6729 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6731 +static DEFINE_SPINLOCK(vroot_grb_lock);
6733 +int register_vroot_grb(vroot_grb_func *func) {
6736 + spin_lock(&vroot_grb_lock);
6737 + if (!vroot_get_real_bdev) {
6738 + vroot_get_real_bdev = func;
6741 + spin_unlock(&vroot_grb_lock);
6744 +EXPORT_SYMBOL(register_vroot_grb);
6746 +int unregister_vroot_grb(vroot_grb_func *func) {
6747 + int ret = -EINVAL;
6749 + spin_lock(&vroot_grb_lock);
6750 + if (vroot_get_real_bdev) {
6751 + vroot_get_real_bdev = NULL;
6754 + spin_unlock(&vroot_grb_lock);
6757 +EXPORT_SYMBOL(unregister_vroot_grb);
6761 /* Return 1 if 'cmd' will block on frozen filesystem */
6762 static int quotactl_cmd_write(int cmd)
6764 @@ -373,6 +414,22 @@ static struct super_block *quotactl_bloc
6767 return ERR_CAST(bdev);
6768 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6769 + if (bdev && bdev->bd_inode &&
6770 + imajor(bdev->bd_inode) == VROOT_MAJOR) {
6771 + struct block_device *bdnew = (void *)-EINVAL;
6773 + if (vroot_get_real_bdev)
6774 + bdnew = vroot_get_real_bdev(bdev);
6776 + vxdprintk(VXD_CBIT(misc, 0),
6777 + "vroot_get_real_bdev not set");
6779 + if (IS_ERR(bdnew))
6780 + return ERR_PTR(PTR_ERR(bdnew));
6784 if (quotactl_cmd_write(cmd))
6785 sb = get_super_thawed(bdev);
6787 diff -NurpP --minimal linux-3.13.6/fs/stat.c linux-3.13.6-vs2.3.6.11/fs/stat.c
6788 --- linux-3.13.6/fs/stat.c 2014-01-22 20:39:07.000000000 +0000
6789 +++ linux-3.13.6-vs2.3.6.11/fs/stat.c 2014-01-31 20:38:03.000000000 +0000
6790 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6791 stat->nlink = inode->i_nlink;
6792 stat->uid = inode->i_uid;
6793 stat->gid = inode->i_gid;
6794 + stat->tag = inode->i_tag;
6795 stat->rdev = inode->i_rdev;
6796 stat->size = i_size_read(inode);
6797 stat->atime = inode->i_atime;
6798 diff -NurpP --minimal linux-3.13.6/fs/statfs.c linux-3.13.6-vs2.3.6.11/fs/statfs.c
6799 --- linux-3.13.6/fs/statfs.c 2013-11-25 15:47:00.000000000 +0000
6800 +++ linux-3.13.6-vs2.3.6.11/fs/statfs.c 2014-01-31 20:38:03.000000000 +0000
6802 #include <linux/statfs.h>
6803 #include <linux/security.h>
6804 #include <linux/uaccess.h>
6805 +#include <linux/vs_base.h>
6806 +#include <linux/vs_dlimit.h>
6807 #include "internal.h"
6809 static int flags_by_mnt(int mnt_flags)
6810 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6811 retval = dentry->d_sb->s_op->statfs(dentry, buf);
6812 if (retval == 0 && buf->f_frsize == 0)
6813 buf->f_frsize = buf->f_bsize;
6814 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
6815 + vx_vsi_statfs(dentry->d_sb, buf);
6819 diff -NurpP --minimal linux-3.13.6/fs/super.c linux-3.13.6-vs2.3.6.11/fs/super.c
6820 --- linux-3.13.6/fs/super.c 2014-01-22 20:39:07.000000000 +0000
6821 +++ linux-3.13.6-vs2.3.6.11/fs/super.c 2014-01-31 20:38:03.000000000 +0000
6823 #include <linux/cleancache.h>
6824 #include <linux/fsnotify.h>
6825 #include <linux/lockdep.h>
6826 +#include <linux/magic.h>
6827 +#include <linux/vs_context.h>
6828 #include "internal.h"
6831 @@ -1098,6 +1100,13 @@ mount_fs(struct file_system_type *type,
6832 WARN_ON(sb->s_bdi == &default_backing_dev_info);
6833 sb->s_flags |= MS_BORN;
6836 + if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6838 + (sb->s_magic != PROC_SUPER_MAGIC) &&
6839 + (sb->s_magic != DEVPTS_SUPER_MAGIC))
6842 error = security_sb_kern_mount(sb, flags, secdata);
6845 diff -NurpP --minimal linux-3.13.6/fs/sysfs/mount.c linux-3.13.6-vs2.3.6.11/fs/sysfs/mount.c
6846 --- linux-3.13.6/fs/sysfs/mount.c 2013-11-25 15:47:00.000000000 +0000
6847 +++ linux-3.13.6-vs2.3.6.11/fs/sysfs/mount.c 2014-01-31 20:38:03.000000000 +0000
6848 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6850 sb->s_blocksize = PAGE_CACHE_SIZE;
6851 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6852 - sb->s_magic = SYSFS_MAGIC;
6853 + sb->s_magic = SYSFS_SUPER_MAGIC;
6854 sb->s_op = &sysfs_ops;
6855 sb->s_time_gran = 1;
6857 diff -NurpP --minimal linux-3.13.6/fs/utimes.c linux-3.13.6-vs2.3.6.11/fs/utimes.c
6858 --- linux-3.13.6/fs/utimes.c 2014-01-22 20:39:07.000000000 +0000
6859 +++ linux-3.13.6-vs2.3.6.11/fs/utimes.c 2014-01-31 23:49:14.000000000 +0000
6861 #include <linux/stat.h>
6862 #include <linux/utime.h>
6863 #include <linux/syscalls.h>
6864 +#include <linux/mount.h>
6865 +#include <linux/vs_cowbl.h>
6866 #include <asm/uaccess.h>
6867 #include <asm/unistd.h>
6869 @@ -52,13 +54,19 @@ static int utimes_common(struct path *pa
6872 struct iattr newattrs;
6873 - struct inode *inode = path->dentry->d_inode;
6874 struct inode *delegated_inode = NULL;
6875 + struct inode *inode;
6877 + error = cow_check_and_break(path);
6881 error = mnt_want_write(path->mnt);
6885 + inode = path->dentry->d_inode;
6887 if (times && times[0].tv_nsec == UTIME_NOW &&
6888 times[1].tv_nsec == UTIME_NOW)
6890 diff -NurpP --minimal linux-3.13.6/fs/xattr.c linux-3.13.6-vs2.3.6.11/fs/xattr.c
6891 --- linux-3.13.6/fs/xattr.c 2013-02-19 13:58:49.000000000 +0000
6892 +++ linux-3.13.6-vs2.3.6.11/fs/xattr.c 2014-01-31 20:38:03.000000000 +0000
6894 #include <linux/audit.h>
6895 #include <linux/vmalloc.h>
6896 #include <linux/posix_acl_xattr.h>
6897 +#include <linux/mount.h>
6899 #include <asm/uaccess.h>
6901 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6902 * The trusted.* namespace can only be accessed by privileged users.
6904 if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6905 - if (!capable(CAP_SYS_ADMIN))
6906 + if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6907 return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6910 diff -NurpP --minimal linux-3.13.6/include/linux/cred.h linux-3.13.6-vs2.3.6.11/include/linux/cred.h
6911 --- linux-3.13.6/include/linux/cred.h 2013-02-19 13:58:50.000000000 +0000
6912 +++ linux-3.13.6-vs2.3.6.11/include/linux/cred.h 2014-01-31 20:38:03.000000000 +0000
6913 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
6914 extern int copy_creds(struct task_struct *, unsigned long);
6915 extern const struct cred *get_task_cred(struct task_struct *);
6916 extern struct cred *cred_alloc_blank(void);
6917 +extern struct cred *__prepare_creds(const struct cred *);
6918 extern struct cred *prepare_creds(void);
6919 extern struct cred *prepare_exec_creds(void);
6920 extern int commit_creds(struct cred *);
6921 @@ -196,6 +197,31 @@ static inline void validate_process_cred
6925 +static inline void set_cred_subscribers(struct cred *cred, int n)
6927 +#ifdef CONFIG_DEBUG_CREDENTIALS
6928 + atomic_set(&cred->subscribers, n);
6932 +static inline int read_cred_subscribers(const struct cred *cred)
6934 +#ifdef CONFIG_DEBUG_CREDENTIALS
6935 + return atomic_read(&cred->subscribers);
6941 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
6943 +#ifdef CONFIG_DEBUG_CREDENTIALS
6944 + struct cred *cred = (struct cred *) _cred;
6946 + atomic_add(n, &cred->subscribers);
6951 * get_new_cred - Get a reference on a new set of credentials
6952 * @cred: The new credentials to reference
6953 diff -NurpP --minimal linux-3.13.6/include/linux/devpts_fs.h linux-3.13.6-vs2.3.6.11/include/linux/devpts_fs.h
6954 --- linux-3.13.6/include/linux/devpts_fs.h 2013-02-19 13:58:50.000000000 +0000
6955 +++ linux-3.13.6-vs2.3.6.11/include/linux/devpts_fs.h 2014-01-31 20:38:03.000000000 +0000
6956 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
6961 #endif /* _LINUX_DEVPTS_FS_H */
6962 diff -NurpP --minimal linux-3.13.6/include/linux/fs.h linux-3.13.6-vs2.3.6.11/include/linux/fs.h
6963 --- linux-3.13.6/include/linux/fs.h 2014-01-22 20:39:10.000000000 +0000
6964 +++ linux-3.13.6-vs2.3.6.11/include/linux/fs.h 2014-01-31 23:33:22.000000000 +0000
6965 @@ -213,6 +213,7 @@ typedef void (dio_iodone_t)(struct kiocb
6966 #define ATTR_KILL_PRIV (1 << 14)
6967 #define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */
6968 #define ATTR_TIMES_SET (1 << 16)
6969 +#define ATTR_TAG (1 << 17)
6972 * This is the Inode Attributes structure, used for notify_change(). It
6973 @@ -228,6 +229,7 @@ struct iattr {
6979 struct timespec ia_atime;
6980 struct timespec ia_mtime;
6981 @@ -526,7 +528,9 @@ struct inode {
6982 unsigned short i_opflags;
6985 - unsigned int i_flags;
6987 + unsigned short i_flags;
6988 + unsigned short i_vflags;
6990 #ifdef CONFIG_FS_POSIX_ACL
6991 struct posix_acl *i_acl;
6992 @@ -555,6 +559,7 @@ struct inode {
6993 unsigned int __i_nlink;
6998 struct timespec i_atime;
6999 struct timespec i_mtime;
7000 @@ -713,6 +718,11 @@ static inline gid_t i_gid_read(const str
7001 return from_kgid(&init_user_ns, inode->i_gid);
7004 +static inline vtag_t i_tag_read(const struct inode *inode)
7006 + return from_ktag(&init_user_ns, inode->i_tag);
7009 static inline void i_uid_write(struct inode *inode, uid_t uid)
7011 inode->i_uid = make_kuid(&init_user_ns, uid);
7012 @@ -723,14 +733,19 @@ static inline void i_gid_write(struct in
7013 inode->i_gid = make_kgid(&init_user_ns, gid);
7016 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
7018 + inode->i_tag = make_ktag(&init_user_ns, tag);
7021 static inline unsigned iminor(const struct inode *inode)
7023 - return MINOR(inode->i_rdev);
7024 + return MINOR(inode->i_mdev);
7027 static inline unsigned imajor(const struct inode *inode)
7029 - return MAJOR(inode->i_rdev);
7030 + return MAJOR(inode->i_mdev);
7033 extern struct block_device *I_BDEV(struct inode *inode);
7034 @@ -790,6 +805,7 @@ struct file {
7036 struct fown_struct f_owner;
7037 const struct cred *f_cred;
7039 struct file_ra_state f_ra;
7042 @@ -962,6 +978,7 @@ struct file_lock {
7043 struct file *fl_file;
7048 struct fasync_struct * fl_fasync; /* for lease break notifications */
7049 /* for lease breaks: */
7050 @@ -1573,6 +1590,7 @@ struct inode_operations {
7051 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7052 ssize_t (*listxattr) (struct dentry *, char *, size_t);
7053 int (*removexattr) (struct dentry *, const char *);
7054 + int (*sync_flags) (struct inode *, int, int);
7055 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7057 int (*update_time)(struct inode *, struct timespec *, int);
7058 @@ -1586,6 +1604,7 @@ ssize_t rw_copy_check_uvector(int type,
7059 unsigned long nr_segs, unsigned long fast_segs,
7060 struct iovec *fast_pointer,
7061 struct iovec **ret_pointer);
7062 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7064 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7065 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7066 @@ -1639,6 +1658,14 @@ struct super_operations {
7067 #define S_IMA 1024 /* Inode has an associated IMA struct */
7068 #define S_AUTOMOUNT 2048 /* Automount/referral quasi-directory */
7069 #define S_NOSEC 4096 /* no suid or xattr security attributes */
7070 +#define S_IXUNLINK 8192 /* Immutable Invert on unlink */
7072 +/* Linux-VServer related Inode flags */
7076 +#define V_BARRIER 4 /* Barrier for chroot() */
7077 +#define V_COW 8 /* Copy on Write */
7080 * Note that nosuid etc flags are inode-specific: setting some file-system
7081 @@ -1663,10 +1690,13 @@ struct super_operations {
7082 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
7083 #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7084 #define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION)
7085 +#define IS_TAGGED(inode) __IS_FLG(inode, MS_TAGGED)
7087 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
7088 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
7089 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
7090 +#define IS_IXUNLINK(inode) ((inode)->i_flags & S_IXUNLINK)
7091 +#define IS_IXORUNLINK(inode) ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7092 #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL)
7094 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
7095 @@ -1677,6 +1707,16 @@ struct super_operations {
7096 #define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT)
7097 #define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC)
7099 +#define IS_BARRIER(inode) (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7101 +#ifdef CONFIG_VSERVER_COWBL
7102 +# define IS_COW(inode) (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7103 +# define IS_COW_LINK(inode) (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7105 +# define IS_COW(inode) (0)
7106 +# define IS_COW_LINK(inode) (0)
7110 * Inode state bits. Protected by inode->i_lock
7112 @@ -1920,6 +1960,9 @@ extern struct kobject *fs_kobj;
7113 extern int locks_mandatory_locked(struct inode *);
7114 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7116 +#define ATTR_FLAG_BARRIER 512 /* Barrier for chroot() */
7117 +#define ATTR_FLAG_IXUNLINK 1024 /* Immutable invert on unlink */
7120 * Candidates for mandatory locking have the setgid bit set
7121 * but no group execute bit - an otherwise meaningless combination.
7122 @@ -2605,6 +2648,7 @@ extern int dcache_dir_open(struct inode
7123 extern int dcache_dir_close(struct inode *, struct file *);
7124 extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7125 extern int dcache_readdir(struct file *, struct dir_context *);
7126 +extern int dcache_readdir_filter(struct file *, struct dir_context *, int (*)(struct dentry *));
7127 extern int simple_setattr(struct dentry *, struct iattr *);
7128 extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7129 extern int simple_statfs(struct dentry *, struct kstatfs *);
7130 diff -NurpP --minimal linux-3.13.6/include/linux/init_task.h linux-3.13.6-vs2.3.6.11/include/linux/init_task.h
7131 --- linux-3.13.6/include/linux/init_task.h 2014-01-22 20:39:11.000000000 +0000
7132 +++ linux-3.13.6-vs2.3.6.11/include/linux/init_task.h 2014-01-31 20:38:03.000000000 +0000
7133 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7134 INIT_TASK_RCU_PREEMPT(tsk) \
7135 INIT_CPUSET_SEQ(tsk) \
7138 + .vx_info = NULL, \
7140 + .nx_info = NULL, \
7144 diff -NurpP --minimal linux-3.13.6/include/linux/ipc.h linux-3.13.6-vs2.3.6.11/include/linux/ipc.h
7145 --- linux-3.13.6/include/linux/ipc.h 2012-12-11 03:30:57.000000000 +0000
7146 +++ linux-3.13.6-vs2.3.6.11/include/linux/ipc.h 2014-01-31 20:38:03.000000000 +0000
7147 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7155 diff -NurpP --minimal linux-3.13.6/include/linux/memcontrol.h linux-3.13.6-vs2.3.6.11/include/linux/memcontrol.h
7156 --- linux-3.13.6/include/linux/memcontrol.h 2013-11-25 15:47:01.000000000 +0000
7157 +++ linux-3.13.6-vs2.3.6.11/include/linux/memcontrol.h 2014-01-31 20:38:03.000000000 +0000
7158 @@ -99,6 +99,13 @@ extern struct mem_cgroup *try_get_mem_cg
7159 extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7160 extern struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css);
7162 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7163 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7165 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7166 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7167 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7170 bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7172 diff -NurpP --minimal linux-3.13.6/include/linux/mm_types.h linux-3.13.6-vs2.3.6.11/include/linux/mm_types.h
7173 --- linux-3.13.6/include/linux/mm_types.h 2014-01-22 20:39:11.000000000 +0000
7174 +++ linux-3.13.6-vs2.3.6.11/include/linux/mm_types.h 2014-01-31 20:38:03.000000000 +0000
7175 @@ -397,6 +397,7 @@ struct mm_struct {
7177 /* Architecture-specific MM context */
7178 mm_context_t context;
7179 + struct vx_info *mm_vx_info;
7181 unsigned long flags; /* Must use atomic bitops to access the bits */
7183 diff -NurpP --minimal linux-3.13.6/include/linux/mount.h linux-3.13.6-vs2.3.6.11/include/linux/mount.h
7184 --- linux-3.13.6/include/linux/mount.h 2014-01-22 20:39:11.000000000 +0000
7185 +++ linux-3.13.6-vs2.3.6.11/include/linux/mount.h 2014-01-31 20:38:03.000000000 +0000
7186 @@ -52,6 +52,9 @@ struct mnt_namespace;
7187 #define MNT_DOOMED 0x1000000
7188 #define MNT_SYNC_UMOUNT 0x2000000
7190 +#define MNT_TAGID 0x10000
7191 +#define MNT_NOTAG 0x20000
7194 struct dentry *mnt_root; /* root of the mounted tree */
7195 struct super_block *mnt_sb; /* pointer to superblock */
7196 diff -NurpP --minimal linux-3.13.6/include/linux/net.h linux-3.13.6-vs2.3.6.11/include/linux/net.h
7197 --- linux-3.13.6/include/linux/net.h 2014-01-22 20:39:11.000000000 +0000
7198 +++ linux-3.13.6-vs2.3.6.11/include/linux/net.h 2014-01-31 20:38:03.000000000 +0000
7199 @@ -39,6 +39,7 @@ struct net;
7200 #define SOCK_PASSCRED 3
7201 #define SOCK_PASSSEC 4
7202 #define SOCK_EXTERNALLY_ALLOCATED 5
7203 +#define SOCK_USER_SOCKET 6
7205 #ifndef ARCH_HAS_SOCKET_TYPES
7207 diff -NurpP --minimal linux-3.13.6/include/linux/netdevice.h linux-3.13.6-vs2.3.6.11/include/linux/netdevice.h
7208 --- linux-3.13.6/include/linux/netdevice.h 2014-03-12 13:51:21.000000000 +0000
7209 +++ linux-3.13.6-vs2.3.6.11/include/linux/netdevice.h 2014-03-12 15:51:07.000000000 +0000
7210 @@ -1839,6 +1839,7 @@ int init_dummy_netdev(struct net_device
7212 struct net_device *dev_get_by_index(struct net *net, int ifindex);
7213 struct net_device *__dev_get_by_index(struct net *net, int ifindex);
7214 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7215 struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
7216 int netdev_get_name(struct net *net, char *name, int ifindex);
7217 int dev_restart(struct net_device *dev);
7218 diff -NurpP --minimal linux-3.13.6/include/linux/nsproxy.h linux-3.13.6-vs2.3.6.11/include/linux/nsproxy.h
7219 --- linux-3.13.6/include/linux/nsproxy.h 2013-11-25 15:45:06.000000000 +0000
7220 +++ linux-3.13.6-vs2.3.6.11/include/linux/nsproxy.h 2014-01-31 20:38:03.000000000 +0000
7223 #include <linux/spinlock.h>
7224 #include <linux/sched.h>
7225 +#include <linux/vserver/debug.h>
7227 struct mnt_namespace;
7228 struct uts_namespace;
7229 @@ -67,6 +68,7 @@ static inline struct nsproxy *task_nspro
7232 int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7233 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7234 void exit_task_namespaces(struct task_struct *tsk);
7235 void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7236 void free_nsproxy(struct nsproxy *ns);
7237 @@ -74,16 +76,26 @@ int unshare_nsproxy_namespaces(unsigned
7238 struct cred *, struct fs_struct *);
7239 int __init nsproxy_cache_init(void);
7241 -static inline void put_nsproxy(struct nsproxy *ns)
7242 +#define get_nsproxy(n) __get_nsproxy(n, __FILE__, __LINE__)
7244 +static inline void __get_nsproxy(struct nsproxy *ns,
7245 + const char *_file, int _line)
7247 - if (atomic_dec_and_test(&ns->count)) {
7250 + vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7251 + ns, atomic_read(&ns->count), _file, _line);
7252 + atomic_inc(&ns->count);
7255 -static inline void get_nsproxy(struct nsproxy *ns)
7256 +#define put_nsproxy(n) __put_nsproxy(n, __FILE__, __LINE__)
7258 +static inline void __put_nsproxy(struct nsproxy *ns,
7259 + const char *_file, int _line)
7261 - atomic_inc(&ns->count);
7262 + vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7263 + ns, atomic_read(&ns->count), _file, _line);
7264 + if (atomic_dec_and_test(&ns->count)) {
7270 diff -NurpP --minimal linux-3.13.6/include/linux/pid.h linux-3.13.6-vs2.3.6.11/include/linux/pid.h
7271 --- linux-3.13.6/include/linux/pid.h 2013-11-25 15:45:06.000000000 +0000
7272 +++ linux-3.13.6-vs2.3.6.11/include/linux/pid.h 2014-01-31 20:38:03.000000000 +0000
7273 @@ -8,7 +8,8 @@ enum pid_type
7283 @@ -170,6 +171,7 @@ static inline pid_t pid_nr(struct pid *p
7286 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7287 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7288 pid_t pid_vnr(struct pid *pid);
7290 #define do_each_pid_task(pid, type, task) \
7291 diff -NurpP --minimal linux-3.13.6/include/linux/quotaops.h linux-3.13.6-vs2.3.6.11/include/linux/quotaops.h
7292 --- linux-3.13.6/include/linux/quotaops.h 2013-11-25 15:47:02.000000000 +0000
7293 +++ linux-3.13.6-vs2.3.6.11/include/linux/quotaops.h 2014-01-31 20:38:03.000000000 +0000
7295 #define _LINUX_QUOTAOPS_
7297 #include <linux/fs.h>
7298 +#include <linux/vs_dlimit.h>
7300 #define DQUOT_SPACE_WARN 0x1
7301 #define DQUOT_SPACE_RESERVE 0x2
7302 @@ -207,11 +208,12 @@ static inline void dquot_drop(struct ino
7304 static inline int dquot_alloc_inode(const struct inode *inode)
7307 + return dl_alloc_inode(inode);
7310 static inline void dquot_free_inode(const struct inode *inode)
7312 + dl_free_inode(inode);
7315 static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
7316 @@ -222,6 +224,10 @@ static inline int dquot_transfer(struct
7317 static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
7322 + if ((ret = dl_alloc_space(inode, number)))
7324 if (!(flags & DQUOT_SPACE_RESERVE))
7325 inode_add_bytes(inode, number);
7327 @@ -232,6 +238,7 @@ static inline void __dquot_free_space(st
7329 if (!(flags & DQUOT_SPACE_RESERVE))
7330 inode_sub_bytes(inode, number);
7331 + dl_free_space(inode, number);
7334 static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
7335 diff -NurpP --minimal linux-3.13.6/include/linux/sched.h linux-3.13.6-vs2.3.6.11/include/linux/sched.h
7336 --- linux-3.13.6/include/linux/sched.h 2014-01-22 20:39:11.000000000 +0000
7337 +++ linux-3.13.6-vs2.3.6.11/include/linux/sched.h 2014-01-31 20:38:03.000000000 +0000
7338 @@ -1237,6 +1237,14 @@ struct task_struct {
7340 struct seccomp seccomp;
7342 +/* vserver context data */
7343 + struct vx_info *vx_info;
7344 + struct nx_info *nx_info;
7350 /* Thread group tracking */
7353 @@ -1531,6 +1539,11 @@ struct pid_namespace;
7354 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
7355 struct pid_namespace *ns);
7357 +#include <linux/vserver/base.h>
7358 +#include <linux/vserver/context.h>
7359 +#include <linux/vserver/debug.h>
7360 +#include <linux/vserver/pid.h>
7362 static inline pid_t task_pid_nr(struct task_struct *tsk)
7365 @@ -1544,7 +1557,8 @@ static inline pid_t task_pid_nr_ns(struc
7367 static inline pid_t task_pid_vnr(struct task_struct *tsk)
7369 - return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7370 + // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7371 + return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
7375 @@ -1557,7 +1571,7 @@ pid_t task_tgid_nr_ns(struct task_struct
7377 static inline pid_t task_tgid_vnr(struct task_struct *tsk)
7379 - return pid_vnr(task_tgid(tsk));
7380 + return vx_map_tgid(pid_vnr(task_tgid(tsk)));
7384 diff -NurpP --minimal linux-3.13.6/include/linux/shmem_fs.h linux-3.13.6-vs2.3.6.11/include/linux/shmem_fs.h
7385 --- linux-3.13.6/include/linux/shmem_fs.h 2014-01-22 20:39:11.000000000 +0000
7386 +++ linux-3.13.6-vs2.3.6.11/include/linux/shmem_fs.h 2014-01-31 20:38:03.000000000 +0000
7389 /* inode in-kernel data */
7391 +#define TMPFS_SUPER_MAGIC 0x01021994
7394 struct shmem_inode_info {
7396 unsigned long flags;
7397 diff -NurpP --minimal linux-3.13.6/include/linux/stat.h linux-3.13.6-vs2.3.6.11/include/linux/stat.h
7398 --- linux-3.13.6/include/linux/stat.h 2012-12-11 03:30:57.000000000 +0000
7399 +++ linux-3.13.6-vs2.3.6.11/include/linux/stat.h 2014-01-31 20:38:03.000000000 +0000
7400 @@ -25,6 +25,7 @@ struct kstat {
7407 struct timespec atime;
7408 diff -NurpP --minimal linux-3.13.6/include/linux/sunrpc/auth.h linux-3.13.6-vs2.3.6.11/include/linux/sunrpc/auth.h
7409 --- linux-3.13.6/include/linux/sunrpc/auth.h 2013-11-25 15:47:02.000000000 +0000
7410 +++ linux-3.13.6-vs2.3.6.11/include/linux/sunrpc/auth.h 2014-01-31 20:38:03.000000000 +0000
7411 @@ -36,6 +36,7 @@ enum {
7416 struct group_info *group_info;
7417 const char *principal;
7418 unsigned long ac_flags;
7419 diff -NurpP --minimal linux-3.13.6/include/linux/sunrpc/clnt.h linux-3.13.6-vs2.3.6.11/include/linux/sunrpc/clnt.h
7420 --- linux-3.13.6/include/linux/sunrpc/clnt.h 2014-01-22 20:39:11.000000000 +0000
7421 +++ linux-3.13.6-vs2.3.6.11/include/linux/sunrpc/clnt.h 2014-01-31 20:38:03.000000000 +0000
7422 @@ -51,7 +51,8 @@ struct rpc_clnt {
7423 cl_discrtry : 1,/* disconnect before retry */
7424 cl_noretranstimeo: 1,/* No retransmit timeouts */
7425 cl_autobind : 1,/* use getport() */
7426 - cl_chatty : 1;/* be verbose */
7427 + cl_chatty : 1,/* be verbose */
7428 + cl_tag : 1;/* context tagging */
7430 struct rpc_rtt * cl_rtt; /* RTO estimator data */
7431 const struct rpc_timeout *cl_timeout; /* Timeout strategy */
7432 diff -NurpP --minimal linux-3.13.6/include/linux/sysfs.h linux-3.13.6-vs2.3.6.11/include/linux/sysfs.h
7433 --- linux-3.13.6/include/linux/sysfs.h 2014-01-22 20:39:11.000000000 +0000
7434 +++ linux-3.13.6-vs2.3.6.11/include/linux/sysfs.h 2014-01-31 20:38:03.000000000 +0000
7436 #include <linux/stat.h>
7437 #include <linux/atomic.h>
7439 +#define SYSFS_SUPER_MAGIC 0x62656572
7443 struct bin_attribute;
7444 diff -NurpP --minimal linux-3.13.6/include/linux/types.h linux-3.13.6-vs2.3.6.11/include/linux/types.h
7445 --- linux-3.13.6/include/linux/types.h 2013-02-19 13:58:52.000000000 +0000
7446 +++ linux-3.13.6-vs2.3.6.11/include/linux/types.h 2014-01-31 20:38:03.000000000 +0000
7447 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t uid_t;
7448 typedef __kernel_gid32_t gid_t;
7449 typedef __kernel_uid16_t uid16_t;
7450 typedef __kernel_gid16_t gid16_t;
7451 +typedef unsigned int vxid_t;
7452 +typedef unsigned int vnid_t;
7453 +typedef unsigned int vtag_t;
7455 typedef unsigned long uintptr_t;
7457 diff -NurpP --minimal linux-3.13.6/include/linux/uidgid.h linux-3.13.6-vs2.3.6.11/include/linux/uidgid.h
7458 --- linux-3.13.6/include/linux/uidgid.h 2012-12-11 03:30:57.000000000 +0000
7459 +++ linux-3.13.6-vs2.3.6.11/include/linux/uidgid.h 2014-01-31 20:38:03.000000000 +0000
7460 @@ -23,13 +23,17 @@ typedef struct {
7473 #define KUIDT_INIT(value) (kuid_t){ value }
7474 #define KGIDT_INIT(value) (kgid_t){ value }
7475 +#define KTAGT_INIT(value) (ktag_t){ value }
7477 static inline uid_t __kuid_val(kuid_t uid)
7479 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
7483 +static inline vtag_t __ktag_val(ktag_t tag)
7490 typedef uid_t kuid_t;
7491 typedef gid_t kgid_t;
7492 +typedef vtag_t ktag_t;
7494 static inline uid_t __kuid_val(kuid_t uid)
7496 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
7500 +static inline vtag_t __ktag_val(ktag_t tag)
7505 #define KUIDT_INIT(value) ((kuid_t) value )
7506 #define KGIDT_INIT(value) ((kgid_t) value )
7507 +#define KTAGT_INIT(value) ((ktag_t) value )
7511 #define GLOBAL_ROOT_UID KUIDT_INIT(0)
7512 #define GLOBAL_ROOT_GID KGIDT_INIT(0)
7513 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
7515 #define INVALID_UID KUIDT_INIT(-1)
7516 #define INVALID_GID KGIDT_INIT(-1)
7517 +#define INVALID_TAG KTAGT_INIT(-1)
7519 static inline bool uid_eq(kuid_t left, kuid_t right)
7521 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
7522 return __kgid_val(left) == __kgid_val(right);
7525 +static inline bool tag_eq(ktag_t left, ktag_t right)
7527 + return __ktag_val(left) == __ktag_val(right);
7530 static inline bool uid_gt(kuid_t left, kuid_t right)
7532 return __kuid_val(left) > __kuid_val(right);
7533 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
7534 return !gid_eq(gid, INVALID_GID);
7537 +static inline bool tag_valid(ktag_t tag)
7539 + return !tag_eq(tag, INVALID_TAG);
7542 #ifdef CONFIG_USER_NS
7544 extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
7545 extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
7546 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
7548 extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
7549 extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
7550 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
7552 extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
7553 extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
7555 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
7556 return KGIDT_INIT(gid);
7559 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
7561 + return KTAGT_INIT(tag);
7564 static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
7566 return __kuid_val(kuid);
7567 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
7568 return __kgid_val(kgid);
7571 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
7573 + return __ktag_val(ktag);
7576 static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
7578 uid_t uid = from_kuid(to, kuid);
7579 diff -NurpP --minimal linux-3.13.6/include/linux/vroot.h linux-3.13.6-vs2.3.6.11/include/linux/vroot.h
7580 --- linux-3.13.6/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
7581 +++ linux-3.13.6-vs2.3.6.11/include/linux/vroot.h 2014-01-31 20:38:03.000000000 +0000
7585 + * include/linux/vroot.h
7587 + * written by Herbert Pötzl, 9/11/2002
7588 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
7590 + * Copyright (C) 2002-2007 by Herbert Pötzl.
7591 + * Redistribution of this file is permitted under the
7592 + * GNU General Public License.
7595 +#ifndef _LINUX_VROOT_H
7596 +#define _LINUX_VROOT_H
7601 +/* Possible states of device */
7607 +struct vroot_device {
7611 + struct semaphore vr_ctl_mutex;
7612 + struct block_device *vr_device;
7617 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
7619 +extern int register_vroot_grb(vroot_grb_func *);
7620 +extern int unregister_vroot_grb(vroot_grb_func *);
7622 +#endif /* __KERNEL__ */
7624 +#define MAX_VROOT_DEFAULT 8
7627 + * IOCTL commands --- we will commandeer 0x56 ('V')
7630 +#define VROOT_SET_DEV 0x5600
7631 +#define VROOT_CLR_DEV 0x5601
7633 +#endif /* _LINUX_VROOT_H */
7634 diff -NurpP --minimal linux-3.13.6/include/linux/vs_base.h linux-3.13.6-vs2.3.6.11/include/linux/vs_base.h
7635 --- linux-3.13.6/include/linux/vs_base.h 1970-01-01 00:00:00.000000000 +0000
7636 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_base.h 2014-01-31 20:38:03.000000000 +0000
7641 +#include "vserver/base.h"
7642 +#include "vserver/check.h"
7643 +#include "vserver/debug.h"
7646 +#warning duplicate inclusion
7648 diff -NurpP --minimal linux-3.13.6/include/linux/vs_context.h linux-3.13.6-vs2.3.6.11/include/linux/vs_context.h
7649 --- linux-3.13.6/include/linux/vs_context.h 1970-01-01 00:00:00.000000000 +0000
7650 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_context.h 2014-01-31 20:38:03.000000000 +0000
7652 +#ifndef _VS_CONTEXT_H
7653 +#define _VS_CONTEXT_H
7655 +#include "vserver/base.h"
7656 +#include "vserver/check.h"
7657 +#include "vserver/context.h"
7658 +#include "vserver/history.h"
7659 +#include "vserver/debug.h"
7661 +#include <linux/sched.h>
7664 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
7666 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
7667 + const char *_file, int _line, void *_here)
7672 + vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
7673 + vxi, vxi ? vxi->vx_id : 0,
7674 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7676 + __vxh_get_vx_info(vxi, _here);
7678 + atomic_inc(&vxi->vx_usecnt);
7683 +extern void free_vx_info(struct vx_info *);
7685 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
7687 +static inline void __put_vx_info(struct vx_info *vxi,
7688 + const char *_file, int _line, void *_here)
7693 + vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
7694 + vxi, vxi ? vxi->vx_id : 0,
7695 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7697 + __vxh_put_vx_info(vxi, _here);
7699 + if (atomic_dec_and_test(&vxi->vx_usecnt))
7700 + free_vx_info(vxi);
7704 +#define init_vx_info(p, i) \
7705 + __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7707 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7708 + const char *_file, int _line, void *_here)
7711 + vxlprintk(VXD_CBIT(xid, 3),
7712 + "init_vx_info(%p[#%d.%d])",
7713 + vxi, vxi ? vxi->vx_id : 0,
7714 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7716 + __vxh_init_vx_info(vxi, vxp, _here);
7718 + atomic_inc(&vxi->vx_usecnt);
7724 +#define set_vx_info(p, i) \
7725 + __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7727 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7728 + const char *_file, int _line, void *_here)
7730 + struct vx_info *vxo;
7735 + vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
7736 + vxi, vxi ? vxi->vx_id : 0,
7737 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7739 + __vxh_set_vx_info(vxi, vxp, _here);
7741 + atomic_inc(&vxi->vx_usecnt);
7742 + vxo = xchg(vxp, vxi);
7747 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
7749 +static inline void __clr_vx_info(struct vx_info **vxp,
7750 + const char *_file, int _line, void *_here)
7752 + struct vx_info *vxo;
7754 + vxo = xchg(vxp, NULL);
7758 + vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
7759 + vxo, vxo ? vxo->vx_id : 0,
7760 + vxo ? atomic_read(&vxo->vx_usecnt) : 0,
7762 + __vxh_clr_vx_info(vxo, vxp, _here);
7764 + if (atomic_dec_and_test(&vxo->vx_usecnt))
7765 + free_vx_info(vxo);
7769 +#define claim_vx_info(v, p) \
7770 + __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7772 +static inline void __claim_vx_info(struct vx_info *vxi,
7773 + struct task_struct *task,
7774 + const char *_file, int _line, void *_here)
7776 + vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
7777 + vxi, vxi ? vxi->vx_id : 0,
7778 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7779 + vxi ? atomic_read(&vxi->vx_tasks) : 0,
7780 + task, _file, _line);
7781 + __vxh_claim_vx_info(vxi, task, _here);
7783 + atomic_inc(&vxi->vx_tasks);
7787 +extern void unhash_vx_info(struct vx_info *);
7789 +#define release_vx_info(v, p) \
7790 + __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7792 +static inline void __release_vx_info(struct vx_info *vxi,
7793 + struct task_struct *task,
7794 + const char *_file, int _line, void *_here)
7796 + vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
7797 + vxi, vxi ? vxi->vx_id : 0,
7798 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7799 + vxi ? atomic_read(&vxi->vx_tasks) : 0,
7800 + task, _file, _line);
7801 + __vxh_release_vx_info(vxi, task, _here);
7805 + if (atomic_dec_and_test(&vxi->vx_tasks))
7806 + unhash_vx_info(vxi);
7810 +#define task_get_vx_info(p) \
7811 + __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
7813 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
7814 + const char *_file, int _line, void *_here)
7816 + struct vx_info *vxi;
7819 + vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
7821 + vxi = __get_vx_info(p->vx_info, _file, _line, _here);
7827 +static inline void __wakeup_vx_info(struct vx_info *vxi)
7829 + if (waitqueue_active(&vxi->vx_wait))
7830 + wake_up_interruptible(&vxi->vx_wait);
7834 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
7836 +static inline void __enter_vx_info(struct vx_info *vxi,
7837 + struct vx_info_save *vxis, const char *_file, int _line)
7839 + vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
7840 + vxi, vxi ? vxi->vx_id : 0, vxis, current,
7841 + current->xid, current->vx_info, _file, _line);
7842 + vxis->vxi = xchg(¤t->vx_info, vxi);
7843 + vxis->xid = current->xid;
7844 + current->xid = vxi ? vxi->vx_id : 0;
7847 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
7849 +static inline void __leave_vx_info(struct vx_info_save *vxis,
7850 + const char *_file, int _line)
7852 + vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
7853 + vxis, vxis->xid, vxis->vxi, current,
7854 + current->xid, current->vx_info, _file, _line);
7855 + (void)xchg(¤t->vx_info, vxis->vxi);
7856 + current->xid = vxis->xid;
7860 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
7862 + vxis->vxi = xchg(¤t->vx_info, NULL);
7863 + vxis->xid = xchg(¤t->xid, (vxid_t)0);
7866 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
7868 + (void)xchg(¤t->xid, vxis->xid);
7869 + (void)xchg(¤t->vx_info, vxis->vxi);
7872 +#define task_is_init(p) \
7873 + __task_is_init(p, __FILE__, __LINE__, __HERE__)
7875 +static inline int __task_is_init(struct task_struct *p,
7876 + const char *_file, int _line, void *_here)
7878 + int is_init = is_global_init(p);
7882 + is_init = p->vx_info->vx_initpid == p->pid;
7887 +extern void exit_vx_info(struct task_struct *, int);
7888 +extern void exit_vx_info_early(struct task_struct *, int);
7892 +#warning duplicate inclusion
7894 diff -NurpP --minimal linux-3.13.6/include/linux/vs_cowbl.h linux-3.13.6-vs2.3.6.11/include/linux/vs_cowbl.h
7895 --- linux-3.13.6/include/linux/vs_cowbl.h 1970-01-01 00:00:00.000000000 +0000
7896 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_cowbl.h 2014-01-31 20:38:03.000000000 +0000
7898 +#ifndef _VS_COWBL_H
7899 +#define _VS_COWBL_H
7901 +#include <linux/fs.h>
7902 +#include <linux/dcache.h>
7903 +#include <linux/namei.h>
7904 +#include <linux/slab.h>
7906 +extern struct dentry *cow_break_link(const char *pathname);
7908 +static inline int cow_check_and_break(struct path *path)
7910 + struct inode *inode = path->dentry->d_inode;
7913 + /* do we need this check? */
7914 + if (IS_RDONLY(inode))
7917 + if (IS_COW(inode)) {
7918 + if (IS_COW_LINK(inode)) {
7919 + struct dentry *new_dentry, *old_dentry = path->dentry;
7922 + buf = kmalloc(PATH_MAX, GFP_KERNEL);
7926 + pp = d_path(path, buf, PATH_MAX);
7927 + new_dentry = cow_break_link(pp);
7929 + if (!IS_ERR(new_dentry)) {
7930 + path->dentry = new_dentry;
7933 + error = PTR_ERR(new_dentry);
7935 + inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
7936 + inode->i_ctime = CURRENT_TIME;
7937 + mark_inode_dirty(inode);
7944 +#warning duplicate inclusion
7946 diff -NurpP --minimal linux-3.13.6/include/linux/vs_cvirt.h linux-3.13.6-vs2.3.6.11/include/linux/vs_cvirt.h
7947 --- linux-3.13.6/include/linux/vs_cvirt.h 1970-01-01 00:00:00.000000000 +0000
7948 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_cvirt.h 2014-01-31 20:38:03.000000000 +0000
7950 +#ifndef _VS_CVIRT_H
7951 +#define _VS_CVIRT_H
7953 +#include "vserver/cvirt.h"
7954 +#include "vserver/context.h"
7955 +#include "vserver/base.h"
7956 +#include "vserver/check.h"
7957 +#include "vserver/debug.h"
7960 +static inline void vx_activate_task(struct task_struct *p)
7962 + struct vx_info *vxi;
7964 + if ((vxi = p->vx_info)) {
7965 + vx_update_load(vxi);
7966 + atomic_inc(&vxi->cvirt.nr_running);
7970 +static inline void vx_deactivate_task(struct task_struct *p)
7972 + struct vx_info *vxi;
7974 + if ((vxi = p->vx_info)) {
7975 + vx_update_load(vxi);
7976 + atomic_dec(&vxi->cvirt.nr_running);
7980 +static inline void vx_uninterruptible_inc(struct task_struct *p)
7982 + struct vx_info *vxi;
7984 + if ((vxi = p->vx_info))
7985 + atomic_inc(&vxi->cvirt.nr_uninterruptible);
7988 +static inline void vx_uninterruptible_dec(struct task_struct *p)
7990 + struct vx_info *vxi;
7992 + if ((vxi = p->vx_info))
7993 + atomic_dec(&vxi->cvirt.nr_uninterruptible);
7998 +#warning duplicate inclusion
8000 diff -NurpP --minimal linux-3.13.6/include/linux/vs_device.h linux-3.13.6-vs2.3.6.11/include/linux/vs_device.h
8001 --- linux-3.13.6/include/linux/vs_device.h 1970-01-01 00:00:00.000000000 +0000
8002 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_device.h 2014-01-31 20:38:03.000000000 +0000
8004 +#ifndef _VS_DEVICE_H
8005 +#define _VS_DEVICE_H
8007 +#include "vserver/base.h"
8008 +#include "vserver/device.h"
8009 +#include "vserver/debug.h"
8012 +#ifdef CONFIG_VSERVER_DEVICE
8014 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8016 +#define vs_device_perm(v, d, m, p) \
8017 + ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8022 +int vs_map_device(struct vx_info *vxi,
8023 + dev_t device, dev_t *target, umode_t mode)
8030 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8035 +#define vs_map_chrdev(d, t, p) \
8036 + ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8037 +#define vs_map_blkdev(d, t, p) \
8038 + ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8040 +#define vs_chrdev_perm(d, p) \
8041 + vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8042 +#define vs_blkdev_perm(d, p) \
8043 + vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8047 +#warning duplicate inclusion
8049 diff -NurpP --minimal linux-3.13.6/include/linux/vs_dlimit.h linux-3.13.6-vs2.3.6.11/include/linux/vs_dlimit.h
8050 --- linux-3.13.6/include/linux/vs_dlimit.h 1970-01-01 00:00:00.000000000 +0000
8051 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_dlimit.h 2014-01-31 20:38:03.000000000 +0000
8053 +#ifndef _VS_DLIMIT_H
8054 +#define _VS_DLIMIT_H
8056 +#include <linux/fs.h>
8058 +#include "vserver/dlimit.h"
8059 +#include "vserver/base.h"
8060 +#include "vserver/debug.h"
8063 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8065 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8066 + const char *_file, int _line)
8070 + vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8071 + dli, dli ? dli->dl_tag : 0,
8072 + dli ? atomic_read(&dli->dl_usecnt) : 0,
8074 + atomic_inc(&dli->dl_usecnt);
8079 +#define free_dl_info(i) \
8080 + call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8082 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8084 +static inline void __put_dl_info(struct dl_info *dli,
8085 + const char *_file, int _line)
8089 + vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8090 + dli, dli ? dli->dl_tag : 0,
8091 + dli ? atomic_read(&dli->dl_usecnt) : 0,
8093 + if (atomic_dec_and_test(&dli->dl_usecnt))
8094 + free_dl_info(dli);
8098 +#define __dlimit_char(d) ((d) ? '*' : ' ')
8100 +static inline int __dl_alloc_space(struct super_block *sb,
8101 + vtag_t tag, dlsize_t nr, const char *file, int line)
8103 + struct dl_info *dli = NULL;
8108 + dli = locate_dl_info(sb, tag);
8112 + spin_lock(&dli->dl_lock);
8113 + ret = (dli->dl_space_used + nr > dli->dl_space_total);
8115 + dli->dl_space_used += nr;
8116 + spin_unlock(&dli->dl_lock);
8119 + vxlprintk(VXD_CBIT(dlim, 1),
8120 + "ALLOC (%p,#%d)%c %lld bytes (%d)",
8121 + sb, tag, __dlimit_char(dli), (long long)nr,
8123 + return ret ? -ENOSPC : 0;
8126 +static inline void __dl_free_space(struct super_block *sb,
8127 + vtag_t tag, dlsize_t nr, const char *_file, int _line)
8129 + struct dl_info *dli = NULL;
8133 + dli = locate_dl_info(sb, tag);
8137 + spin_lock(&dli->dl_lock);
8138 + if (dli->dl_space_used > nr)
8139 + dli->dl_space_used -= nr;
8141 + dli->dl_space_used = 0;
8142 + spin_unlock(&dli->dl_lock);
8145 + vxlprintk(VXD_CBIT(dlim, 1),
8146 + "FREE (%p,#%d)%c %lld bytes",
8147 + sb, tag, __dlimit_char(dli), (long long)nr,
8151 +static inline int __dl_alloc_inode(struct super_block *sb,
8152 + vtag_t tag, const char *_file, int _line)
8154 + struct dl_info *dli;
8157 + dli = locate_dl_info(sb, tag);
8161 + spin_lock(&dli->dl_lock);
8162 + dli->dl_inodes_used++;
8163 + ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8164 + spin_unlock(&dli->dl_lock);
8167 + vxlprintk(VXD_CBIT(dlim, 0),
8168 + "ALLOC (%p,#%d)%c inode (%d)",
8169 + sb, tag, __dlimit_char(dli), ret, _file, _line);
8170 + return ret ? -ENOSPC : 0;
8173 +static inline void __dl_free_inode(struct super_block *sb,
8174 + vtag_t tag, const char *_file, int _line)
8176 + struct dl_info *dli;
8178 + dli = locate_dl_info(sb, tag);
8182 + spin_lock(&dli->dl_lock);
8183 + if (dli->dl_inodes_used > 1)
8184 + dli->dl_inodes_used--;
8186 + dli->dl_inodes_used = 0;
8187 + spin_unlock(&dli->dl_lock);
8190 + vxlprintk(VXD_CBIT(dlim, 0),
8191 + "FREE (%p,#%d)%c inode",
8192 + sb, tag, __dlimit_char(dli), _file, _line);
8195 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
8196 + unsigned long long *free_blocks, unsigned long long *root_blocks,
8197 + const char *_file, int _line)
8199 + struct dl_info *dli;
8200 + uint64_t broot, bfree;
8202 + dli = locate_dl_info(sb, tag);
8206 + spin_lock(&dli->dl_lock);
8207 + broot = (dli->dl_space_total -
8208 + (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8209 + >> sb->s_blocksize_bits;
8210 + bfree = (dli->dl_space_total - dli->dl_space_used)
8211 + >> sb->s_blocksize_bits;
8212 + spin_unlock(&dli->dl_lock);
8214 + vxlprintk(VXD_CBIT(dlim, 2),
8215 + "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8216 + (long long)bfree, (long long)broot,
8217 + *free_blocks, *root_blocks, dli->dl_nrlmult,
8219 + if (free_blocks) {
8220 + if (*free_blocks > bfree)
8221 + *free_blocks = bfree;
8223 + if (root_blocks) {
8224 + if (*root_blocks > broot)
8225 + *root_blocks = broot;
8230 +#define dl_prealloc_space(in, bytes) \
8231 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8232 + __FILE__, __LINE__ )
8234 +#define dl_alloc_space(in, bytes) \
8235 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8236 + __FILE__, __LINE__ )
8238 +#define dl_reserve_space(in, bytes) \
8239 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8240 + __FILE__, __LINE__ )
8242 +#define dl_claim_space(in, bytes) (0)
8244 +#define dl_release_space(in, bytes) \
8245 + __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8246 + __FILE__, __LINE__ )
8248 +#define dl_free_space(in, bytes) \
8249 + __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8250 + __FILE__, __LINE__ )
8254 +#define dl_alloc_inode(in) \
8255 + __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8257 +#define dl_free_inode(in) \
8258 + __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8261 +#define dl_adjust_block(sb, tag, fb, rb) \
8262 + __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8266 +#warning duplicate inclusion
8268 diff -NurpP --minimal linux-3.13.6/include/linux/vs_inet.h linux-3.13.6-vs2.3.6.11/include/linux/vs_inet.h
8269 --- linux-3.13.6/include/linux/vs_inet.h 1970-01-01 00:00:00.000000000 +0000
8270 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_inet.h 2014-02-01 00:32:45.000000000 +0000
8275 +#include "vserver/base.h"
8276 +#include "vserver/network.h"
8277 +#include "vserver/debug.h"
8279 +#define IPI_LOOPBACK htonl(INADDR_LOOPBACK)
8281 +#define NXAV4(a) NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
8282 + NIPQUAD((a)->mask), (a)->type
8283 +#define NXAV4_FMT "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
8285 +#define NIPQUAD(addr) \
8286 + ((unsigned char *)&addr)[0], \
8287 + ((unsigned char *)&addr)[1], \
8288 + ((unsigned char *)&addr)[2], \
8289 + ((unsigned char *)&addr)[3]
8291 +#define NIPQUAD_FMT "%u.%u.%u.%u"
8295 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
8297 + __be32 ip = nxa->ip[0].s_addr;
8298 + __be32 mask = nxa->mask.s_addr;
8299 + __be32 bcast = ip | ~mask;
8302 + switch (nxa->type & tmask) {
8303 + case NXA_TYPE_MASK:
8304 + ret = (ip == (addr & mask));
8306 + case NXA_TYPE_ADDR:
8310 + /* fall through to broadcast */
8311 + case NXA_MOD_BCAST:
8312 + ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
8314 + case NXA_TYPE_RANGE:
8315 + ret = ((nxa->ip[0].s_addr <= addr) &&
8316 + (nxa->ip[1].s_addr > addr));
8318 + case NXA_TYPE_ANY:
8323 + vxdprintk(VXD_CBIT(net, 0),
8324 + "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
8325 + nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
8330 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
8332 + struct nx_addr_v4 *nxa;
8333 + unsigned long irqflags;
8340 + /* allow 127.0.0.1 when remapping lback */
8341 + if ((tmask & NXA_LOOPBACK) &&
8342 + (addr == IPI_LOOPBACK) &&
8343 + nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8346 + /* check for lback address */
8347 + if ((tmask & NXA_MOD_LBACK) &&
8348 + (nxi->v4_lback.s_addr == addr))
8351 + /* check for broadcast address */
8352 + if ((tmask & NXA_MOD_BCAST) &&
8353 + (nxi->v4_bcast.s_addr == addr))
8357 + /* check for v4 addresses */
8358 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
8359 + for (nxa = &nxi->v4; nxa; nxa = nxa->next)
8360 + if (v4_addr_match(nxa, addr, tmask))
8364 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8366 + vxdprintk(VXD_CBIT(net, 0),
8367 + "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
8368 + nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
8373 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
8375 + /* FIXME: needs full range checks */
8376 + return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
8380 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
8382 + struct nx_addr_v4 *ptr;
8383 + unsigned long irqflags;
8386 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
8387 + for (ptr = &nxi->v4; ptr; ptr = ptr->next)
8388 + if (v4_nx_addr_match(ptr, nxa, mask))
8392 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8396 +#include <net/inet_sock.h>
8399 + * Check if a given address matches for a socket
8401 + * nxi: the socket's nx_info if any
8402 + * addr: to be verified address
8405 +int v4_sock_addr_match (
8406 + struct nx_info *nxi,
8407 + struct inet_sock *inet,
8410 + __be32 saddr = inet->inet_rcv_saddr;
8411 + __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
8413 + if (addr && (saddr == addr || bcast == addr))
8416 + return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
8421 +/* inet related checks and helpers */
8430 +#include <linux/netdevice.h>
8431 +#include <linux/inetdevice.h>
8432 +#include <net/inet_sock.h>
8433 +#include <net/inet_timewait_sock.h>
8436 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8437 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
8438 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
8442 + * check if address is covered by socket
8444 + * sk: the socket to check against
8445 + * addr: the address in question (must be != 0)
8449 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
8451 + struct nx_info *nxi = sk->sk_nx_info;
8452 + __be32 saddr = sk->sk_rcv_saddr;
8454 + vxdprintk(VXD_CBIT(net, 5),
8455 + "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
8456 + sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
8457 + (sk->sk_socket?sk->sk_socket->flags:0));
8459 + if (saddr) { /* direct address match */
8460 + return v4_addr_match(nxa, saddr, -1);
8461 + } else if (nxi) { /* match against nx_info */
8462 + return v4_nx_addr_in_nx_info(nxi, nxa, -1);
8463 + } else { /* unrestricted any socket */
8471 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
8473 + vxdprintk(VXD_CBIT(net, 1),
8474 + "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
8475 + nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
8476 + nxi ? dev_in_nx_info(dev, nxi) : 0);
8478 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8480 + if (dev_in_nx_info(dev, nxi))
8487 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
8493 + return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
8497 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
8499 + vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
8500 + nxi, nxi ? nxi->nx_id : 0, ifa,
8501 + nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
8503 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8505 + if (v4_ifa_in_nx_info(ifa, nxi))
8511 +struct nx_v4_sock_addr {
8512 + __be32 saddr; /* Address used for validation */
8513 + __be32 baddr; /* Address used for socket bind */
8517 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
8518 + struct nx_v4_sock_addr *nsa)
8520 + struct sock *sk = &inet->sk;
8521 + struct nx_info *nxi = sk->sk_nx_info;
8522 + __be32 saddr = addr->sin_addr.s_addr;
8523 + __be32 baddr = saddr;
8525 + vxdprintk(VXD_CBIT(net, 3),
8526 + "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
8527 + sk, sk->sk_nx_info, sk->sk_socket,
8528 + (sk->sk_socket ? sk->sk_socket->flags : 0),
8532 + if (saddr == INADDR_ANY) {
8533 + if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
8534 + baddr = nxi->v4.ip[0].s_addr;
8535 + } else if (saddr == IPI_LOOPBACK) {
8536 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8537 + baddr = nxi->v4_lback.s_addr;
8538 + } else if (!ipv4_is_multicast(saddr) ||
8539 + !nx_info_ncaps(nxi, NXC_MULTICAST)) {
8540 + /* normal address bind */
8541 + if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
8542 + return -EADDRNOTAVAIL;
8546 + vxdprintk(VXD_CBIT(net, 3),
8547 + "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
8548 + sk, NIPQUAD(saddr), NIPQUAD(baddr));
8550 + nsa->saddr = saddr;
8551 + nsa->baddr = baddr;
8556 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
8558 + inet->inet_saddr = nsa->baddr;
8559 + inet->inet_rcv_saddr = nsa->baddr;
8564 + * helper to simplify inet_lookup_listener
8566 + * nxi: the socket's nx_info if any
8567 + * addr: to be verified address
8568 + * saddr: socket address
8570 +static inline int v4_inet_addr_match (
8571 + struct nx_info *nxi,
8575 + if (addr && (saddr == addr))
8578 + return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
8582 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
8584 + if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
8585 + (addr == nxi->v4_lback.s_addr))
8586 + return IPI_LOOPBACK;
8591 +int nx_info_has_v4(struct nx_info *nxi)
8597 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8602 +#else /* CONFIG_INET */
8605 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
8611 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8617 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8623 +int nx_info_has_v4(struct nx_info *nxi)
8628 +#endif /* CONFIG_INET */
8630 +#define current_nx_info_has_v4() \
8631 + nx_info_has_v4(current_nx_info())
8634 +// #warning duplicate inclusion
8636 diff -NurpP --minimal linux-3.13.6/include/linux/vs_inet6.h linux-3.13.6-vs2.3.6.11/include/linux/vs_inet6.h
8637 --- linux-3.13.6/include/linux/vs_inet6.h 1970-01-01 00:00:00.000000000 +0000
8638 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_inet6.h 2014-02-01 00:35:02.000000000 +0000
8640 +#ifndef _VS_INET6_H
8641 +#define _VS_INET6_H
8643 +#include "vserver/base.h"
8644 +#include "vserver/network.h"
8645 +#include "vserver/debug.h"
8647 +#include <net/ipv6.h>
8649 +#define NXAV6(a) &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
8650 +#define NXAV6_FMT "[%pI6/%pI6/%d:%04x]"
8656 +int v6_addr_match(struct nx_addr_v6 *nxa,
8657 + const struct in6_addr *addr, uint16_t mask)
8661 + switch (nxa->type & mask) {
8662 + case NXA_TYPE_MASK:
8663 + ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
8665 + case NXA_TYPE_ADDR:
8666 + ret = ipv6_addr_equal(&nxa->ip, addr);
8668 + case NXA_TYPE_ANY:
8672 + vxdprintk(VXD_CBIT(net, 0),
8673 + "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
8674 + nxa, NXAV6(nxa), addr, mask, ret);
8679 +int v6_addr_in_nx_info(struct nx_info *nxi,
8680 + const struct in6_addr *addr, uint16_t mask)
8682 + struct nx_addr_v6 *nxa;
8683 + unsigned long irqflags;
8689 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
8690 + for (nxa = &nxi->v6; nxa; nxa = nxa->next)
8691 + if (v6_addr_match(nxa, addr, mask))
8695 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8697 + vxdprintk(VXD_CBIT(net, 0),
8698 + "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
8699 + nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
8704 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
8706 + /* FIXME: needs full range checks */
8707 + return v6_addr_match(nxa, &addr->ip, mask);
8711 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
8713 + struct nx_addr_v6 *ptr;
8714 + unsigned long irqflags;
8717 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
8718 + for (ptr = &nxi->v6; ptr; ptr = ptr->next)
8719 + if (v6_nx_addr_match(ptr, nxa, mask))
8723 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8729 + * Check if a given address matches for a socket
8731 + * nxi: the socket's nx_info if any
8732 + * addr: to be verified address
8735 +int v6_sock_addr_match (
8736 + struct nx_info *nxi,
8737 + struct inet_sock *inet,
8738 + struct in6_addr *addr)
8740 + struct sock *sk = &inet->sk;
8741 + const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8743 + if (!ipv6_addr_any(addr) &&
8744 + ipv6_addr_equal(saddr, addr))
8746 + if (ipv6_addr_any(saddr))
8747 + return v6_addr_in_nx_info(nxi, addr, -1);
8752 + * check if address is covered by socket
8754 + * sk: the socket to check against
8755 + * addr: the address in question (must be != 0)
8759 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
8761 + struct nx_info *nxi = sk->sk_nx_info;
8762 + const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8764 + vxdprintk(VXD_CBIT(net, 5),
8765 + "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
8766 + sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
8767 + (sk->sk_socket?sk->sk_socket->flags:0));
8769 + if (!ipv6_addr_any(saddr)) { /* direct address match */
8770 + return v6_addr_match(nxa, saddr, -1);
8771 + } else if (nxi) { /* match against nx_info */
8772 + return v6_nx_addr_in_nx_info(nxi, nxa, -1);
8773 + } else { /* unrestricted any socket */
8779 +/* inet related checks and helpers */
8787 +#include <linux/netdevice.h>
8788 +#include <linux/inetdevice.h>
8789 +#include <net/inet_timewait_sock.h>
8792 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8793 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
8794 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
8799 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
8805 + return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
8809 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
8811 + vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
8812 + nxi, nxi ? nxi->nx_id : 0, ifa,
8813 + nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
8815 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8817 + if (v6_ifa_in_nx_info(ifa, nxi))
8823 +struct nx_v6_sock_addr {
8824 + struct in6_addr saddr; /* Address used for validation */
8825 + struct in6_addr baddr; /* Address used for socket bind */
8829 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
8830 + struct nx_v6_sock_addr *nsa)
8832 + // struct sock *sk = &inet->sk;
8833 + // struct nx_info *nxi = sk->sk_nx_info;
8834 + struct in6_addr saddr = addr->sin6_addr;
8835 + struct in6_addr baddr = saddr;
8837 + nsa->saddr = saddr;
8838 + nsa->baddr = baddr;
8843 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
8845 + // struct sock *sk = &inet->sk;
8846 + // struct in6_addr *saddr = inet6_rcv_saddr(sk);
8848 + // *saddr = nsa->baddr;
8849 + // inet->inet_saddr = nsa->baddr;
8853 +int nx_info_has_v6(struct nx_info *nxi)
8862 +#else /* CONFIG_IPV6 */
8865 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
8872 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8878 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8884 +int nx_info_has_v6(struct nx_info *nxi)
8889 +#endif /* CONFIG_IPV6 */
8891 +#define current_nx_info_has_v6() \
8892 + nx_info_has_v6(current_nx_info())
8895 +#warning duplicate inclusion
8897 diff -NurpP --minimal linux-3.13.6/include/linux/vs_limit.h linux-3.13.6-vs2.3.6.11/include/linux/vs_limit.h
8898 --- linux-3.13.6/include/linux/vs_limit.h 1970-01-01 00:00:00.000000000 +0000
8899 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_limit.h 2014-02-01 01:29:43.000000000 +0000
8901 +#ifndef _VS_LIMIT_H
8902 +#define _VS_LIMIT_H
8904 +#include "vserver/limit.h"
8905 +#include "vserver/base.h"
8906 +#include "vserver/context.h"
8907 +#include "vserver/debug.h"
8908 +#include "vserver/context.h"
8909 +#include "vserver/limit_int.h"
8912 +#define vx_acc_cres(v, d, p, r) \
8913 + __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
8915 +#define vx_acc_cres_cond(x, d, p, r) \
8916 + __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8917 + r, d, p, __FILE__, __LINE__)
8920 +#define vx_add_cres(v, a, p, r) \
8921 + __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
8922 +#define vx_sub_cres(v, a, p, r) vx_add_cres(v, -(a), p, r)
8924 +#define vx_add_cres_cond(x, a, p, r) \
8925 + __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8926 + r, a, p, __FILE__, __LINE__)
8927 +#define vx_sub_cres_cond(x, a, p, r) vx_add_cres_cond(x, -(a), p, r)
8930 +/* process and file limits */
8932 +#define vx_nproc_inc(p) \
8933 + vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
8935 +#define vx_nproc_dec(p) \
8936 + vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
8938 +#define vx_files_inc(f) \
8939 + vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
8941 +#define vx_files_dec(f) \
8942 + vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
8944 +#define vx_locks_inc(l) \
8945 + vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
8947 +#define vx_locks_dec(l) \
8948 + vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
8950 +#define vx_openfd_inc(f) \
8951 + vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
8953 +#define vx_openfd_dec(f) \
8954 + vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
8957 +#define vx_cres_avail(v, n, r) \
8958 + __vx_cres_avail(v, r, n, __FILE__, __LINE__)
8961 +#define vx_nproc_avail(n) \
8962 + vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
8964 +#define vx_files_avail(n) \
8965 + vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
8967 +#define vx_locks_avail(n) \
8968 + vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
8970 +#define vx_openfd_avail(n) \
8971 + vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
8974 +/* dentry limits */
8976 +#define vx_dentry_inc(d) do { \
8977 + if (d_count(d) == 1) \
8978 + vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY); \
8981 +#define vx_dentry_dec(d) do { \
8982 + if (d_count(d) == 0) \
8983 + vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY); \
8986 +#define vx_dentry_avail(n) \
8987 + vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
8990 +/* socket limits */
8992 +#define vx_sock_inc(s) \
8993 + vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
8995 +#define vx_sock_dec(s) \
8996 + vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
8998 +#define vx_sock_avail(n) \
8999 + vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9002 +/* ipc resource limits */
9004 +#define vx_ipcmsg_add(v, u, a) \
9005 + vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9007 +#define vx_ipcmsg_sub(v, u, a) \
9008 + vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9010 +#define vx_ipcmsg_avail(v, a) \
9011 + vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9014 +#define vx_ipcshm_add(v, k, a) \
9015 + vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9017 +#define vx_ipcshm_sub(v, k, a) \
9018 + vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9020 +#define vx_ipcshm_avail(v, a) \
9021 + vx_cres_avail(v, a, VLIMIT_SHMEM)
9024 +#define vx_semary_inc(a) \
9025 + vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9027 +#define vx_semary_dec(a) \
9028 + vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9031 +#define vx_nsems_add(a,n) \
9032 + vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9034 +#define vx_nsems_sub(a,n) \
9035 + vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9039 +#warning duplicate inclusion
9041 diff -NurpP --minimal linux-3.13.6/include/linux/vs_network.h linux-3.13.6-vs2.3.6.11/include/linux/vs_network.h
9042 --- linux-3.13.6/include/linux/vs_network.h 1970-01-01 00:00:00.000000000 +0000
9043 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_network.h 2014-01-31 20:38:03.000000000 +0000
9045 +#ifndef _NX_VS_NETWORK_H
9046 +#define _NX_VS_NETWORK_H
9048 +#include "vserver/context.h"
9049 +#include "vserver/network.h"
9050 +#include "vserver/base.h"
9051 +#include "vserver/check.h"
9052 +#include "vserver/debug.h"
9054 +#include <linux/sched.h>
9057 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9059 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9060 + const char *_file, int _line)
9065 + vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9066 + nxi, nxi ? nxi->nx_id : 0,
9067 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9070 + atomic_inc(&nxi->nx_usecnt);
9075 +extern void free_nx_info(struct nx_info *);
9077 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9079 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9084 + vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9085 + nxi, nxi ? nxi->nx_id : 0,
9086 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9089 + if (atomic_dec_and_test(&nxi->nx_usecnt))
9090 + free_nx_info(nxi);
9094 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9096 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9097 + const char *_file, int _line)
9100 + vxlprintk(VXD_CBIT(nid, 3),
9101 + "init_nx_info(%p[#%d.%d])",
9102 + nxi, nxi ? nxi->nx_id : 0,
9103 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9106 + atomic_inc(&nxi->nx_usecnt);
9112 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9114 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9115 + const char *_file, int _line)
9117 + struct nx_info *nxo;
9122 + vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9123 + nxi, nxi ? nxi->nx_id : 0,
9124 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9127 + atomic_inc(&nxi->nx_usecnt);
9128 + nxo = xchg(nxp, nxi);
9132 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9134 +static inline void __clr_nx_info(struct nx_info **nxp,
9135 + const char *_file, int _line)
9137 + struct nx_info *nxo;
9139 + nxo = xchg(nxp, NULL);
9143 + vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9144 + nxo, nxo ? nxo->nx_id : 0,
9145 + nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9148 + if (atomic_dec_and_test(&nxo->nx_usecnt))
9149 + free_nx_info(nxo);
9153 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9155 +static inline void __claim_nx_info(struct nx_info *nxi,
9156 + struct task_struct *task, const char *_file, int _line)
9158 + vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9159 + nxi, nxi ? nxi->nx_id : 0,
9160 + nxi?atomic_read(&nxi->nx_usecnt):0,
9161 + nxi?atomic_read(&nxi->nx_tasks):0,
9162 + task, _file, _line);
9164 + atomic_inc(&nxi->nx_tasks);
9168 +extern void unhash_nx_info(struct nx_info *);
9170 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9172 +static inline void __release_nx_info(struct nx_info *nxi,
9173 + struct task_struct *task, const char *_file, int _line)
9175 + vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9176 + nxi, nxi ? nxi->nx_id : 0,
9177 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9178 + nxi ? atomic_read(&nxi->nx_tasks) : 0,
9179 + task, _file, _line);
9183 + if (atomic_dec_and_test(&nxi->nx_tasks))
9184 + unhash_nx_info(nxi);
9188 +#define task_get_nx_info(i) __task_get_nx_info(i, __FILE__, __LINE__)
9190 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9191 + const char *_file, int _line)
9193 + struct nx_info *nxi;
9196 + vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9198 + nxi = __get_nx_info(p->nx_info, _file, _line);
9204 +static inline void exit_nx_info(struct task_struct *p)
9207 + release_nx_info(p->nx_info, p);
9212 +#warning duplicate inclusion
9214 diff -NurpP --minimal linux-3.13.6/include/linux/vs_pid.h linux-3.13.6-vs2.3.6.11/include/linux/vs_pid.h
9215 --- linux-3.13.6/include/linux/vs_pid.h 1970-01-01 00:00:00.000000000 +0000
9216 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_pid.h 2014-01-31 20:38:03.000000000 +0000
9221 +#include "vserver/base.h"
9222 +#include "vserver/check.h"
9223 +#include "vserver/context.h"
9224 +#include "vserver/debug.h"
9225 +#include "vserver/pid.h"
9226 +#include <linux/pid_namespace.h>
9229 +#define VXF_FAKE_INIT (VXF_INFO_INIT | VXF_STATE_INIT)
9232 +int vx_proc_task_visible(struct task_struct *task)
9234 + if ((task->pid == 1) &&
9235 + !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9236 + /* show a blend through init */
9238 + if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9245 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9249 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9251 + struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9253 + if (task && !vx_proc_task_visible(task)) {
9254 + vxdprintk(VXD_CBIT(misc, 6),
9255 + "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9256 + task, task->xid, task->pid,
9257 + current, current->xid, current->pid);
9258 + put_task_struct(task);
9266 +#warning duplicate inclusion
9268 diff -NurpP --minimal linux-3.13.6/include/linux/vs_sched.h linux-3.13.6-vs2.3.6.11/include/linux/vs_sched.h
9269 --- linux-3.13.6/include/linux/vs_sched.h 1970-01-01 00:00:00.000000000 +0000
9270 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_sched.h 2014-01-31 20:38:03.000000000 +0000
9272 +#ifndef _VS_SCHED_H
9273 +#define _VS_SCHED_H
9275 +#include "vserver/base.h"
9276 +#include "vserver/context.h"
9277 +#include "vserver/sched.h"
9280 +#define MAX_PRIO_BIAS 20
9281 +#define MIN_PRIO_BIAS -20
9284 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
9286 + struct vx_info *vxi = p->vx_info;
9289 + prio += vx_cpu(vxi, sched_pc).prio_bias;
9293 +static inline void vx_account_user(struct vx_info *vxi,
9294 + cputime_t cputime, int nice)
9298 + vx_cpu(vxi, sched_pc).user_ticks += cputime;
9301 +static inline void vx_account_system(struct vx_info *vxi,
9302 + cputime_t cputime, int idle)
9306 + vx_cpu(vxi, sched_pc).sys_ticks += cputime;
9310 +#warning duplicate inclusion
9312 diff -NurpP --minimal linux-3.13.6/include/linux/vs_socket.h linux-3.13.6-vs2.3.6.11/include/linux/vs_socket.h
9313 --- linux-3.13.6/include/linux/vs_socket.h 1970-01-01 00:00:00.000000000 +0000
9314 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_socket.h 2014-01-31 20:38:03.000000000 +0000
9316 +#ifndef _VS_SOCKET_H
9317 +#define _VS_SOCKET_H
9319 +#include "vserver/debug.h"
9320 +#include "vserver/base.h"
9321 +#include "vserver/cacct.h"
9322 +#include "vserver/context.h"
9323 +#include "vserver/tag.h"
9326 +/* socket accounting */
9328 +#include <linux/socket.h>
9330 +static inline int vx_sock_type(int family)
9334 + return VXA_SOCK_UNSPEC;
9336 + return VXA_SOCK_UNIX;
9338 + return VXA_SOCK_INET;
9340 + return VXA_SOCK_INET6;
9342 + return VXA_SOCK_PACKET;
9344 + return VXA_SOCK_OTHER;
9348 +#define vx_acc_sock(v, f, p, s) \
9349 + __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
9351 +static inline void __vx_acc_sock(struct vx_info *vxi,
9352 + int family, int pos, int size, char *file, int line)
9355 + int type = vx_sock_type(family);
9357 + atomic_long_inc(&vxi->cacct.sock[type][pos].count);
9358 + atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
9362 +#define vx_sock_recv(sk, s) \
9363 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
9364 +#define vx_sock_send(sk, s) \
9365 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
9366 +#define vx_sock_fail(sk, s) \
9367 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
9370 +#define sock_vx_init(s) do { \
9371 + (s)->sk_xid = 0; \
9372 + (s)->sk_vx_info = NULL; \
9375 +#define sock_nx_init(s) do { \
9376 + (s)->sk_nid = 0; \
9377 + (s)->sk_nx_info = NULL; \
9381 +#warning duplicate inclusion
9383 diff -NurpP --minimal linux-3.13.6/include/linux/vs_tag.h linux-3.13.6-vs2.3.6.11/include/linux/vs_tag.h
9384 --- linux-3.13.6/include/linux/vs_tag.h 1970-01-01 00:00:00.000000000 +0000
9385 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_tag.h 2014-01-31 20:38:03.000000000 +0000
9390 +#include <linux/vserver/tag.h>
9392 +/* check conditions */
9394 +#define DX_ADMIN 0x0001
9395 +#define DX_WATCH 0x0002
9396 +#define DX_HOSTID 0x0008
9398 +#define DX_IDENT 0x0010
9400 +#define DX_ARG_MASK 0x0010
9403 +#define dx_task_tag(t) ((t)->tag)
9405 +#define dx_current_tag() dx_task_tag(current)
9407 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
9409 +#define dx_weak_check(c, m) ((m) ? dx_check(c, m) : 1)
9413 + * check current context for ADMIN/WATCH and
9414 + * optionally against supplied argument
9416 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
9418 + if (mode & DX_ARG_MASK) {
9419 + if ((mode & DX_IDENT) && (id == cid))
9422 + return (((mode & DX_ADMIN) && (cid == 0)) ||
9423 + ((mode & DX_WATCH) && (cid == 1)) ||
9424 + ((mode & DX_HOSTID) && (id == 0)));
9428 +int dx_permission(const struct inode *inode, int mask);
9432 +#warning duplicate inclusion
9434 diff -NurpP --minimal linux-3.13.6/include/linux/vs_time.h linux-3.13.6-vs2.3.6.11/include/linux/vs_time.h
9435 --- linux-3.13.6/include/linux/vs_time.h 1970-01-01 00:00:00.000000000 +0000
9436 +++ linux-3.13.6-vs2.3.6.11/include/linux/vs_time.h 2014-01-31 20:38:03.000000000 +0000
9442 +/* time faking stuff */
9444 +#ifdef CONFIG_VSERVER_VTIME
9446 +extern void vx_adjust_timespec(struct timespec *ts);
9447 +extern int vx_settimeofday(const struct timespec *ts);
9450 +#define vx_adjust_timespec(t) do { } while (0)
9451 +#define vx_settimeofday(t) do_settimeofday(t)
9455 +#warning duplicate inclusion
9457 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/base.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/base.h
9458 --- linux-3.13.6/include/linux/vserver/base.h 1970-01-01 00:00:00.000000000 +0000
9459 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/base.h 2014-01-31 20:38:03.000000000 +0000
9461 +#ifndef _VSERVER_BASE_H
9462 +#define _VSERVER_BASE_H
9465 +/* context state changes */
9477 +#define vx_task_xid(t) ((t)->xid)
9479 +#define vx_current_xid() vx_task_xid(current)
9481 +#define current_vx_info() (current->vx_info)
9484 +#define nx_task_nid(t) ((t)->nid)
9486 +#define nx_current_nid() nx_task_nid(current)
9488 +#define current_nx_info() (current->nx_info)
9491 +/* generic flag merging */
9493 +#define vs_check_flags(v, m, f) (((v) & (m)) ^ (f))
9495 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
9497 +#define vs_mask_mask(v, f, m) (((v) & ~(m)) | ((v) & (f) & (m)))
9499 +#define vs_check_bit(v, n) ((v) & (1LL << (n)))
9502 +/* context flags */
9504 +#define __vx_flags(v) ((v) ? (v)->vx_flags : 0)
9506 +#define vx_current_flags() __vx_flags(current_vx_info())
9508 +#define vx_info_flags(v, m, f) \
9509 + vs_check_flags(__vx_flags(v), m, f)
9511 +#define task_vx_flags(t, m, f) \
9512 + ((t) && vx_info_flags((t)->vx_info, m, f))
9514 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
9519 +#define __vx_ccaps(v) ((v) ? (v)->vx_ccaps : 0)
9521 +#define vx_current_ccaps() __vx_ccaps(current_vx_info())
9523 +#define vx_info_ccaps(v, c) (__vx_ccaps(v) & (c))
9525 +#define vx_ccaps(c) vx_info_ccaps(current_vx_info(), (c))
9529 +/* network flags */
9531 +#define __nx_flags(n) ((n) ? (n)->nx_flags : 0)
9533 +#define nx_current_flags() __nx_flags(current_nx_info())
9535 +#define nx_info_flags(n, m, f) \
9536 + vs_check_flags(__nx_flags(n), m, f)
9538 +#define task_nx_flags(t, m, f) \
9539 + ((t) && nx_info_flags((t)->nx_info, m, f))
9541 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
9546 +#define __nx_ncaps(n) ((n) ? (n)->nx_ncaps : 0)
9548 +#define nx_current_ncaps() __nx_ncaps(current_nx_info())
9550 +#define nx_info_ncaps(n, c) (__nx_ncaps(n) & (c))
9552 +#define nx_ncaps(c) nx_info_ncaps(current_nx_info(), c)
9555 +/* context mask capabilities */
9557 +#define __vx_mcaps(v) ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
9559 +#define vx_info_mcaps(v, c) (__vx_mcaps(v) & (c))
9561 +#define vx_mcaps(c) vx_info_mcaps(current_vx_info(), c)
9564 +/* context bcap mask */
9566 +#define __vx_bcaps(v) ((v)->vx_bcaps)
9568 +#define vx_current_bcaps() __vx_bcaps(current_vx_info())
9571 +/* mask given bcaps */
9573 +#define vx_info_mbcaps(v, c) ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
9575 +#define vx_mbcaps(c) vx_info_mbcaps(current_vx_info(), c)
9578 +/* masked cap_bset */
9580 +#define vx_info_cap_bset(v) vx_info_mbcaps(v, current->cap_bset)
9582 +#define vx_current_cap_bset() vx_info_cap_bset(current_vx_info())
9585 +#define vx_info_mbcap(v, b) \
9586 + (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
9587 + vx_info_bcaps(v, b) : (b))
9589 +#define task_vx_mbcap(t, b) \
9590 + vx_info_mbcap((t)->vx_info, (t)->b)
9592 +#define vx_mbcap(b) task_vx_mbcap(current, b)
9595 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
9597 +#define vx_capable(b, c) (capable(b) || \
9598 + (cap_raised(current_cap(), b) && vx_ccaps(c)))
9600 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
9601 + (cap_raised(current_cap(), b) && vx_ccaps(c)))
9603 +#define nx_capable(b, c) (capable(b) || \
9604 + (cap_raised(current_cap(), b) && nx_ncaps(c)))
9606 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
9607 + (cap_raised(current_cap(), b) && nx_ncaps(c)))
9609 +#define vx_task_initpid(t, n) \
9610 + ((t)->vx_info && \
9611 + ((t)->vx_info->vx_initpid == (n)))
9613 +#define vx_current_initpid(n) vx_task_initpid(current, n)
9616 +/* context unshare mask */
9618 +#define __vx_umask(v) ((v)->vx_umask)
9620 +#define vx_current_umask() __vx_umask(current_vx_info())
9622 +#define vx_can_unshare(b, f) (capable(b) || \
9623 + (cap_raised(current_cap(), b) && \
9624 + !((f) & ~vx_current_umask())))
9626 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
9627 + (cap_raised(current_cap(), b) && \
9628 + !((f) & ~vx_current_umask())))
9630 +#define __vx_wmask(v) ((v)->vx_wmask)
9632 +#define vx_current_wmask() __vx_wmask(current_vx_info())
9635 +#define __vx_state(v) ((v) ? ((v)->vx_state) : 0)
9637 +#define vx_info_state(v, m) (__vx_state(v) & (m))
9640 +#define __nx_state(n) ((n) ? ((n)->nx_state) : 0)
9642 +#define nx_info_state(n, m) (__nx_state(n) & (m))
9645 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/cacct.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/cacct.h
9646 --- linux-3.13.6/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
9647 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/cacct.h 2014-01-31 20:38:03.000000000 +0000
9649 +#ifndef _VSERVER_CACCT_H
9650 +#define _VSERVER_CACCT_H
9653 +enum sock_acc_field {
9654 + VXA_SOCK_UNSPEC = 0,
9660 + VXA_SOCK_SIZE /* array size */
9663 +#endif /* _VSERVER_CACCT_H */
9664 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/cacct_cmd.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/cacct_cmd.h
9665 --- linux-3.13.6/include/linux/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
9666 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/cacct_cmd.h 2014-01-31 20:38:03.000000000 +0000
9668 +#ifndef _VSERVER_CACCT_CMD_H
9669 +#define _VSERVER_CACCT_CMD_H
9672 +#include <linux/compiler.h>
9673 +#include <uapi/vserver/cacct_cmd.h>
9675 +extern int vc_sock_stat(struct vx_info *, void __user *);
9677 +#endif /* _VSERVER_CACCT_CMD_H */
9678 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/cacct_def.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/cacct_def.h
9679 --- linux-3.13.6/include/linux/vserver/cacct_def.h 1970-01-01 00:00:00.000000000 +0000
9680 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/cacct_def.h 2014-01-31 20:38:03.000000000 +0000
9682 +#ifndef _VSERVER_CACCT_DEF_H
9683 +#define _VSERVER_CACCT_DEF_H
9685 +#include <asm/atomic.h>
9686 +#include <linux/vserver/cacct.h>
9689 +struct _vx_sock_acc {
9690 + atomic_long_t count;
9691 + atomic_long_t total;
9694 +/* context sub struct */
9697 + struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
9699 + atomic_t page[6][8];
9702 +#ifdef CONFIG_VSERVER_DEBUG
9704 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
9708 + printk("\t_vx_cacct:");
9709 + for (i = 0; i < 6; i++) {
9710 + struct _vx_sock_acc *ptr = cacct->sock[i];
9712 + printk("\t [%d] =", i);
9713 + for (j = 0; j < 3; j++) {
9714 + printk(" [%d] = %8lu, %8lu", j,
9715 + atomic_long_read(&ptr[j].count),
9716 + atomic_long_read(&ptr[j].total));
9724 +#endif /* _VSERVER_CACCT_DEF_H */
9725 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/cacct_int.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/cacct_int.h
9726 --- linux-3.13.6/include/linux/vserver/cacct_int.h 1970-01-01 00:00:00.000000000 +0000
9727 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/cacct_int.h 2014-01-31 20:38:03.000000000 +0000
9729 +#ifndef _VSERVER_CACCT_INT_H
9730 +#define _VSERVER_CACCT_INT_H
9733 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
9735 + return atomic_long_read(&cacct->sock[type][pos].count);
9740 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
9742 + return atomic_long_read(&cacct->sock[type][pos].total);
9745 +#endif /* _VSERVER_CACCT_INT_H */
9746 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/check.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/check.h
9747 --- linux-3.13.6/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
9748 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/check.h 2014-01-31 20:38:03.000000000 +0000
9750 +#ifndef _VSERVER_CHECK_H
9751 +#define _VSERVER_CHECK_H
9754 +#define MAX_S_CONTEXT 65535 /* Arbitrary limit */
9756 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
9757 +#define MIN_D_CONTEXT 49152 /* dynamic contexts start here */
9759 +#define MIN_D_CONTEXT 65536
9762 +/* check conditions */
9764 +#define VS_ADMIN 0x0001
9765 +#define VS_WATCH 0x0002
9766 +#define VS_HIDE 0x0004
9767 +#define VS_HOSTID 0x0008
9769 +#define VS_IDENT 0x0010
9770 +#define VS_EQUIV 0x0020
9771 +#define VS_PARENT 0x0040
9772 +#define VS_CHILD 0x0080
9774 +#define VS_ARG_MASK 0x00F0
9776 +#define VS_DYNAMIC 0x0100
9777 +#define VS_STATIC 0x0200
9779 +#define VS_ATR_MASK 0x0F00
9781 +#ifdef CONFIG_VSERVER_PRIVACY
9782 +#define VS_ADMIN_P (0)
9783 +#define VS_WATCH_P (0)
9785 +#define VS_ADMIN_P VS_ADMIN
9786 +#define VS_WATCH_P VS_WATCH
9789 +#define VS_HARDIRQ 0x1000
9790 +#define VS_SOFTIRQ 0x2000
9791 +#define VS_IRQ 0x4000
9793 +#define VS_IRQ_MASK 0xF000
9795 +#include <linux/hardirq.h>
9798 + * check current context for ADMIN/WATCH and
9799 + * optionally against supplied argument
9801 +static inline int __vs_check(int cid, int id, unsigned int mode)
9803 + if (mode & VS_ARG_MASK) {
9804 + if ((mode & VS_IDENT) && (id == cid))
9807 + if (mode & VS_ATR_MASK) {
9808 + if ((mode & VS_DYNAMIC) &&
9809 + (id >= MIN_D_CONTEXT) &&
9810 + (id <= MAX_S_CONTEXT))
9812 + if ((mode & VS_STATIC) &&
9813 + (id > 1) && (id < MIN_D_CONTEXT))
9816 + if (mode & VS_IRQ_MASK) {
9817 + if ((mode & VS_IRQ) && unlikely(in_interrupt()))
9819 + if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
9821 + if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
9824 + return (((mode & VS_ADMIN) && (cid == 0)) ||
9825 + ((mode & VS_WATCH) && (cid == 1)) ||
9826 + ((mode & VS_HOSTID) && (id == 0)));
9829 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
9831 +#define vx_weak_check(c, m) ((m) ? vx_check(c, m) : 1)
9834 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
9836 +#define nx_weak_check(c, m) ((m) ? nx_check(c, m) : 1)
9839 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/context.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/context.h
9840 --- linux-3.13.6/include/linux/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
9841 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/context.h 2014-01-31 20:38:03.000000000 +0000
9843 +#ifndef _VSERVER_CONTEXT_H
9844 +#define _VSERVER_CONTEXT_H
9847 +#include <linux/list.h>
9848 +#include <linux/spinlock.h>
9849 +#include <linux/rcupdate.h>
9850 +#include <uapi/vserver/context.h>
9852 +#include "limit_def.h"
9853 +#include "sched_def.h"
9854 +#include "cvirt_def.h"
9855 +#include "cacct_def.h"
9856 +#include "device_def.h"
9858 +#define VX_SPACES 2
9860 +struct _vx_info_pc {
9861 + struct _vx_sched_pc sched_pc;
9862 + struct _vx_cvirt_pc cvirt_pc;
9866 + unsigned long vx_nsmask; /* assignment mask */
9867 + struct nsproxy *vx_nsproxy; /* private namespaces */
9868 + struct fs_struct *vx_fs; /* private namespace fs */
9869 + const struct cred *vx_cred; /* task credentials */
9873 + struct hlist_node vx_hlist; /* linked list of contexts */
9874 + vxid_t vx_id; /* context id */
9875 + atomic_t vx_usecnt; /* usage count */
9876 + atomic_t vx_tasks; /* tasks count */
9877 + struct vx_info *vx_parent; /* parent context */
9878 + int vx_state; /* context state */
9880 + struct _vx_space space[VX_SPACES]; /* namespace store */
9882 + uint64_t vx_flags; /* context flags */
9883 + uint64_t vx_ccaps; /* context caps (vserver) */
9884 + uint64_t vx_umask; /* unshare mask (guest) */
9885 + uint64_t vx_wmask; /* warn mask (guest) */
9886 + kernel_cap_t vx_bcaps; /* bounding caps (system) */
9888 + struct task_struct *vx_reaper; /* guest reaper process */
9889 + pid_t vx_initpid; /* PID of guest init */
9890 + int64_t vx_badness_bias; /* OOM points bias */
9892 + struct _vx_limit limit; /* vserver limits */
9893 + struct _vx_sched sched; /* vserver scheduler */
9894 + struct _vx_cvirt cvirt; /* virtual/bias stuff */
9895 + struct _vx_cacct cacct; /* context accounting */
9897 + struct _vx_device dmap; /* default device map targets */
9900 + struct _vx_info_pc info_pc; /* per cpu data */
9902 + struct _vx_info_pc *ptr_pc; /* per cpu array */
9905 + wait_queue_head_t vx_wait; /* context exit waitqueue */
9906 + int reboot_cmd; /* last sys_reboot() cmd */
9907 + int exit_code; /* last process exit code */
9909 + char vx_name[65]; /* vserver name */
9913 +#define vx_ptr_pc(vxi) (&(vxi)->info_pc)
9914 +#define vx_per_cpu(vxi, v, id) vx_ptr_pc(vxi)->v
9916 +#define vx_ptr_pc(vxi) ((vxi)->ptr_pc)
9917 +#define vx_per_cpu(vxi, v, id) per_cpu_ptr(vx_ptr_pc(vxi), id)->v
9920 +#define vx_cpu(vxi, v) vx_per_cpu(vxi, v, smp_processor_id())
9923 +struct vx_info_save {
9924 + struct vx_info *vxi;
9931 +#define VXS_HASHED 0x0001
9932 +#define VXS_PAUSED 0x0010
9933 +#define VXS_SHUTDOWN 0x0100
9934 +#define VXS_HELPER 0x1000
9935 +#define VXS_RELEASED 0x8000
9938 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
9939 +extern void release_vx_info(struct vx_info *, struct task_struct *);
9941 +extern struct vx_info *lookup_vx_info(int);
9942 +extern struct vx_info *lookup_or_create_vx_info(int);
9944 +extern int get_xid_list(int, unsigned int *, int);
9945 +extern int xid_is_hashed(vxid_t);
9947 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
9949 +extern long vs_state_change(struct vx_info *, unsigned int);
9952 +#endif /* _VSERVER_CONTEXT_H */
9953 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/context_cmd.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/context_cmd.h
9954 --- linux-3.13.6/include/linux/vserver/context_cmd.h 1970-01-01 00:00:00.000000000 +0000
9955 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/context_cmd.h 2014-01-31 20:38:03.000000000 +0000
9957 +#ifndef _VSERVER_CONTEXT_CMD_H
9958 +#define _VSERVER_CONTEXT_CMD_H
9960 +#include <uapi/vserver/context_cmd.h>
9962 +extern int vc_task_xid(uint32_t);
9964 +extern int vc_vx_info(struct vx_info *, void __user *);
9966 +extern int vc_ctx_stat(struct vx_info *, void __user *);
9968 +extern int vc_ctx_create(uint32_t, void __user *);
9969 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
9971 +extern int vc_get_cflags(struct vx_info *, void __user *);
9972 +extern int vc_set_cflags(struct vx_info *, void __user *);
9974 +extern int vc_get_ccaps(struct vx_info *, void __user *);
9975 +extern int vc_set_ccaps(struct vx_info *, void __user *);
9977 +extern int vc_get_bcaps(struct vx_info *, void __user *);
9978 +extern int vc_set_bcaps(struct vx_info *, void __user *);
9980 +extern int vc_get_umask(struct vx_info *, void __user *);
9981 +extern int vc_set_umask(struct vx_info *, void __user *);
9983 +extern int vc_get_wmask(struct vx_info *, void __user *);
9984 +extern int vc_set_wmask(struct vx_info *, void __user *);
9986 +extern int vc_get_badness(struct vx_info *, void __user *);
9987 +extern int vc_set_badness(struct vx_info *, void __user *);
9989 +#endif /* _VSERVER_CONTEXT_CMD_H */
9990 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/cvirt.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/cvirt.h
9991 --- linux-3.13.6/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
9992 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/cvirt.h 2014-01-31 20:38:03.000000000 +0000
9994 +#ifndef _VSERVER_CVIRT_H
9995 +#define _VSERVER_CVIRT_H
9999 +void vx_vsi_boottime(struct timespec *);
10001 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10006 +void vx_update_load(struct vx_info *);
10009 +int vx_do_syslog(int, char __user *, int);
10011 +#endif /* _VSERVER_CVIRT_H */
10012 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/cvirt_cmd.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/cvirt_cmd.h
10013 --- linux-3.13.6/include/linux/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
10014 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/cvirt_cmd.h 2014-01-31 20:38:03.000000000 +0000
10016 +#ifndef _VSERVER_CVIRT_CMD_H
10017 +#define _VSERVER_CVIRT_CMD_H
10020 +#include <linux/compiler.h>
10021 +#include <uapi/vserver/cvirt_cmd.h>
10023 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10024 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10026 +extern int vc_virt_stat(struct vx_info *, void __user *);
10028 +#endif /* _VSERVER_CVIRT_CMD_H */
10029 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/cvirt_def.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/cvirt_def.h
10030 --- linux-3.13.6/include/linux/vserver/cvirt_def.h 1970-01-01 00:00:00.000000000 +0000
10031 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/cvirt_def.h 2014-01-31 20:38:03.000000000 +0000
10033 +#ifndef _VSERVER_CVIRT_DEF_H
10034 +#define _VSERVER_CVIRT_DEF_H
10036 +#include <linux/jiffies.h>
10037 +#include <linux/spinlock.h>
10038 +#include <linux/wait.h>
10039 +#include <linux/time.h>
10040 +#include <asm/atomic.h>
10043 +struct _vx_usage_stat {
10047 + uint64_t softirq;
10053 +struct _vx_syslog {
10054 + wait_queue_head_t log_wait;
10055 + spinlock_t logbuf_lock; /* lock for the log buffer */
10057 + unsigned long log_start; /* next char to be read by syslog() */
10058 + unsigned long con_start; /* next char to be sent to consoles */
10059 + unsigned long log_end; /* most-recently-written-char + 1 */
10060 + unsigned long logged_chars; /* #chars since last read+clear operation */
10062 + char log_buf[1024];
10066 +/* context sub struct */
10068 +struct _vx_cvirt {
10069 + atomic_t nr_threads; /* number of current threads */
10070 + atomic_t nr_running; /* number of running threads */
10071 + atomic_t nr_uninterruptible; /* number of uninterruptible threads */
10073 + atomic_t nr_onhold; /* processes on hold */
10074 + uint32_t onhold_last; /* jiffies when put on hold */
10076 + struct timespec bias_ts; /* time offset to the host */
10077 + struct timespec bias_idle;
10078 + struct timespec bias_uptime; /* context creation point */
10079 + uint64_t bias_clock; /* offset in clock_t */
10081 + spinlock_t load_lock; /* lock for the load averages */
10082 + atomic_t load_updates; /* nr of load updates done so far */
10083 + uint32_t load_last; /* last time load was calculated */
10084 + uint32_t load[3]; /* load averages 1,5,15 */
10086 + atomic_t total_forks; /* number of forks so far */
10088 + struct _vx_syslog syslog;
10091 +struct _vx_cvirt_pc {
10092 + struct _vx_usage_stat cpustat;
10096 +#ifdef CONFIG_VSERVER_DEBUG
10098 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10100 + printk("\t_vx_cvirt:\n");
10101 + printk("\t threads: %4d, %4d, %4d, %4d\n",
10102 + atomic_read(&cvirt->nr_threads),
10103 + atomic_read(&cvirt->nr_running),
10104 + atomic_read(&cvirt->nr_uninterruptible),
10105 + atomic_read(&cvirt->nr_onhold));
10106 + /* add rest here */
10107 + printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10112 +#endif /* _VSERVER_CVIRT_DEF_H */
10113 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/debug.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/debug.h
10114 --- linux-3.13.6/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
10115 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/debug.h 2014-01-31 20:38:03.000000000 +0000
10117 +#ifndef _VSERVER_DEBUG_H
10118 +#define _VSERVER_DEBUG_H
10121 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10122 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10123 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10125 +#define VXD_DEV(d) (d), (d)->bd_inode->i_ino, \
10126 + imajor((d)->bd_inode), iminor((d)->bd_inode)
10127 +#define VXF_DEV "%p[%lu,%d:%d]"
10129 +#if defined(CONFIG_QUOTES_UTF8)
10130 +#define VS_Q_LQM "\xc2\xbb"
10131 +#define VS_Q_RQM "\xc2\xab"
10132 +#elif defined(CONFIG_QUOTES_ASCII)
10133 +#define VS_Q_LQM "\x27"
10134 +#define VS_Q_RQM "\x27"
10136 +#define VS_Q_LQM "\xbb"
10137 +#define VS_Q_RQM "\xab"
10140 +#define VS_Q(f) VS_Q_LQM f VS_Q_RQM
10143 +#define vxd_path(p) \
10144 + ({ static char _buffer[PATH_MAX]; \
10145 + d_path(p, _buffer, sizeof(_buffer)); })
10147 +#define vxd_cond_path(n) \
10148 + ((n) ? vxd_path(&(n)->path) : "<null>" )
10151 +#ifdef CONFIG_VSERVER_DEBUG
10153 +extern unsigned int vs_debug_switch;
10154 +extern unsigned int vs_debug_xid;
10155 +extern unsigned int vs_debug_nid;
10156 +extern unsigned int vs_debug_tag;
10157 +extern unsigned int vs_debug_net;
10158 +extern unsigned int vs_debug_limit;
10159 +extern unsigned int vs_debug_cres;
10160 +extern unsigned int vs_debug_dlim;
10161 +extern unsigned int vs_debug_quota;
10162 +extern unsigned int vs_debug_cvirt;
10163 +extern unsigned int vs_debug_space;
10164 +extern unsigned int vs_debug_perm;
10165 +extern unsigned int vs_debug_misc;
10168 +#define VX_LOGLEVEL "vxD: "
10169 +#define VX_PROC_FMT "%p: "
10170 +#define VX_PROCESS current
10172 +#define vxdprintk(c, f, x...) \
10175 + printk(VX_LOGLEVEL VX_PROC_FMT f "\n", \
10176 + VX_PROCESS , ##x); \
10179 +#define vxlprintk(c, f, x...) \
10182 + printk(VX_LOGLEVEL f " @%s:%d\n", x); \
10185 +#define vxfprintk(c, f, x...) \
10188 + printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10194 +void dump_vx_info(struct vx_info *, int);
10195 +void dump_vx_info_inactive(int);
10197 +#else /* CONFIG_VSERVER_DEBUG */
10199 +#define vs_debug_switch 0
10200 +#define vs_debug_xid 0
10201 +#define vs_debug_nid 0
10202 +#define vs_debug_tag 0
10203 +#define vs_debug_net 0
10204 +#define vs_debug_limit 0
10205 +#define vs_debug_cres 0
10206 +#define vs_debug_dlim 0
10207 +#define vs_debug_quota 0
10208 +#define vs_debug_cvirt 0
10209 +#define vs_debug_space 0
10210 +#define vs_debug_perm 0
10211 +#define vs_debug_misc 0
10213 +#define vxdprintk(x...) do { } while (0)
10214 +#define vxlprintk(x...) do { } while (0)
10215 +#define vxfprintk(x...) do { } while (0)
10217 +#endif /* CONFIG_VSERVER_DEBUG */
10220 +#ifdef CONFIG_VSERVER_WARN
10222 +#define VX_WARNLEVEL KERN_WARNING "vxW: "
10223 +#define VX_WARN_TASK "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10224 +#define VX_WARN_XID "[xid #%u] "
10225 +#define VX_WARN_NID "[nid #%u] "
10226 +#define VX_WARN_TAG "[tag #%u] "
10228 +#define vxwprintk(c, f, x...) \
10231 + printk(VX_WARNLEVEL f "\n", ##x); \
10234 +#else /* CONFIG_VSERVER_WARN */
10236 +#define vxwprintk(x...) do { } while (0)
10238 +#endif /* CONFIG_VSERVER_WARN */
10240 +#define vxwprintk_task(c, f, x...) \
10241 + vxwprintk(c, VX_WARN_TASK f, \
10242 + current->comm, current->pid, \
10243 + current->xid, current->nid, \
10244 + current->tag, ##x)
10245 +#define vxwprintk_xid(c, f, x...) \
10246 + vxwprintk(c, VX_WARN_XID f, current->xid, x)
10247 +#define vxwprintk_nid(c, f, x...) \
10248 + vxwprintk(c, VX_WARN_NID f, current->nid, x)
10249 +#define vxwprintk_tag(c, f, x...) \
10250 + vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10252 +#ifdef CONFIG_VSERVER_DEBUG
10253 +#define vxd_assert_lock(l) assert_spin_locked(l)
10254 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10255 + "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10257 +#define vxd_assert_lock(l) do { } while (0)
10258 +#define vxd_assert(c, f, x...) do { } while (0)
10262 +#endif /* _VSERVER_DEBUG_H */
10263 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/debug_cmd.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/debug_cmd.h
10264 --- linux-3.13.6/include/linux/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
10265 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/debug_cmd.h 2014-01-31 20:38:03.000000000 +0000
10267 +#ifndef _VSERVER_DEBUG_CMD_H
10268 +#define _VSERVER_DEBUG_CMD_H
10270 +#include <uapi/vserver/debug_cmd.h>
10273 +#ifdef CONFIG_COMPAT
10275 +#include <asm/compat.h>
10277 +struct vcmd_read_history_v0_x32 {
10280 + compat_uptr_t data_ptr;
10283 +struct vcmd_read_monitor_v0_x32 {
10286 + compat_uptr_t data_ptr;
10289 +#endif /* CONFIG_COMPAT */
10291 +extern int vc_dump_history(uint32_t);
10293 +extern int vc_read_history(uint32_t, void __user *);
10294 +extern int vc_read_monitor(uint32_t, void __user *);
10296 +#ifdef CONFIG_COMPAT
10298 +extern int vc_read_history_x32(uint32_t, void __user *);
10299 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10301 +#endif /* CONFIG_COMPAT */
10303 +#endif /* _VSERVER_DEBUG_CMD_H */
10304 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/device.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/device.h
10305 --- linux-3.13.6/include/linux/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
10306 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/device.h 2014-01-31 20:38:03.000000000 +0000
10308 +#ifndef _VSERVER_DEVICE_H
10309 +#define _VSERVER_DEVICE_H
10312 +#include <uapi/vserver/device.h>
10314 +#else /* _VSERVER_DEVICE_H */
10315 +#warning duplicate inclusion
10316 +#endif /* _VSERVER_DEVICE_H */
10317 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/device_cmd.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/device_cmd.h
10318 --- linux-3.13.6/include/linux/vserver/device_cmd.h 1970-01-01 00:00:00.000000000 +0000
10319 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/device_cmd.h 2014-01-31 20:38:03.000000000 +0000
10321 +#ifndef _VSERVER_DEVICE_CMD_H
10322 +#define _VSERVER_DEVICE_CMD_H
10324 +#include <uapi/vserver/device_cmd.h>
10327 +#ifdef CONFIG_COMPAT
10329 +#include <asm/compat.h>
10331 +struct vcmd_set_mapping_v0_x32 {
10332 + compat_uptr_t device_ptr;
10333 + compat_uptr_t target_ptr;
10337 +#endif /* CONFIG_COMPAT */
10339 +#include <linux/compiler.h>
10341 +extern int vc_set_mapping(struct vx_info *, void __user *);
10342 +extern int vc_unset_mapping(struct vx_info *, void __user *);
10344 +#ifdef CONFIG_COMPAT
10346 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
10347 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
10349 +#endif /* CONFIG_COMPAT */
10351 +#endif /* _VSERVER_DEVICE_CMD_H */
10352 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/device_def.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/device_def.h
10353 --- linux-3.13.6/include/linux/vserver/device_def.h 1970-01-01 00:00:00.000000000 +0000
10354 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/device_def.h 2014-01-31 20:38:03.000000000 +0000
10356 +#ifndef _VSERVER_DEVICE_DEF_H
10357 +#define _VSERVER_DEVICE_DEF_H
10359 +#include <linux/types.h>
10361 +struct vx_dmap_target {
10366 +struct _vx_device {
10367 +#ifdef CONFIG_VSERVER_DEVICE
10368 + struct vx_dmap_target targets[2];
10372 +#endif /* _VSERVER_DEVICE_DEF_H */
10373 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/dlimit.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/dlimit.h
10374 --- linux-3.13.6/include/linux/vserver/dlimit.h 1970-01-01 00:00:00.000000000 +0000
10375 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/dlimit.h 2014-01-31 20:38:03.000000000 +0000
10377 +#ifndef _VSERVER_DLIMIT_H
10378 +#define _VSERVER_DLIMIT_H
10380 +#include "switch.h"
10385 +/* keep in sync with CDLIM_INFINITY */
10387 +#define DLIM_INFINITY (~0ULL)
10389 +#include <linux/spinlock.h>
10390 +#include <linux/rcupdate.h>
10392 +struct super_block;
10395 + struct hlist_node dl_hlist; /* linked list of contexts */
10396 + struct rcu_head dl_rcu; /* the rcu head */
10397 + vtag_t dl_tag; /* context tag */
10398 + atomic_t dl_usecnt; /* usage count */
10399 + atomic_t dl_refcnt; /* reference count */
10401 + struct super_block *dl_sb; /* associated superblock */
10403 + spinlock_t dl_lock; /* protect the values */
10405 + unsigned long long dl_space_used; /* used space in bytes */
10406 + unsigned long long dl_space_total; /* maximum space in bytes */
10407 + unsigned long dl_inodes_used; /* used inodes */
10408 + unsigned long dl_inodes_total; /* maximum inodes */
10410 + unsigned int dl_nrlmult; /* non root limit mult */
10415 +extern void rcu_free_dl_info(struct rcu_head *);
10416 +extern void unhash_dl_info(struct dl_info *);
10418 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
10423 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
10425 +typedef uint64_t dlsize_t;
10427 +#endif /* __KERNEL__ */
10428 +#else /* _VSERVER_DLIMIT_H */
10429 +#warning duplicate inclusion
10430 +#endif /* _VSERVER_DLIMIT_H */
10431 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/dlimit_cmd.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/dlimit_cmd.h
10432 --- linux-3.13.6/include/linux/vserver/dlimit_cmd.h 1970-01-01 00:00:00.000000000 +0000
10433 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/dlimit_cmd.h 2014-01-31 20:38:03.000000000 +0000
10435 +#ifndef _VSERVER_DLIMIT_CMD_H
10436 +#define _VSERVER_DLIMIT_CMD_H
10438 +#include <uapi/vserver/dlimit_cmd.h>
10441 +#ifdef CONFIG_COMPAT
10443 +#include <asm/compat.h>
10445 +struct vcmd_ctx_dlimit_base_v0_x32 {
10446 + compat_uptr_t name_ptr;
10450 +struct vcmd_ctx_dlimit_v0_x32 {
10451 + compat_uptr_t name_ptr;
10452 + uint32_t space_used; /* used space in kbytes */
10453 + uint32_t space_total; /* maximum space in kbytes */
10454 + uint32_t inodes_used; /* used inodes */
10455 + uint32_t inodes_total; /* maximum inodes */
10456 + uint32_t reserved; /* reserved for root in % */
10460 +#endif /* CONFIG_COMPAT */
10462 +#include <linux/compiler.h>
10464 +extern int vc_add_dlimit(uint32_t, void __user *);
10465 +extern int vc_rem_dlimit(uint32_t, void __user *);
10467 +extern int vc_set_dlimit(uint32_t, void __user *);
10468 +extern int vc_get_dlimit(uint32_t, void __user *);
10470 +#ifdef CONFIG_COMPAT
10472 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
10473 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
10475 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
10476 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
10478 +#endif /* CONFIG_COMPAT */
10480 +#endif /* _VSERVER_DLIMIT_CMD_H */
10481 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/global.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/global.h
10482 --- linux-3.13.6/include/linux/vserver/global.h 1970-01-01 00:00:00.000000000 +0000
10483 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/global.h 2014-01-31 20:38:03.000000000 +0000
10485 +#ifndef _VSERVER_GLOBAL_H
10486 +#define _VSERVER_GLOBAL_H
10489 +extern atomic_t vx_global_ctotal;
10490 +extern atomic_t vx_global_cactive;
10492 +extern atomic_t nx_global_ctotal;
10493 +extern atomic_t nx_global_cactive;
10495 +extern atomic_t vs_global_nsproxy;
10496 +extern atomic_t vs_global_fs;
10497 +extern atomic_t vs_global_mnt_ns;
10498 +extern atomic_t vs_global_uts_ns;
10499 +extern atomic_t vs_global_user_ns;
10500 +extern atomic_t vs_global_pid_ns;
10503 +#endif /* _VSERVER_GLOBAL_H */
10504 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/history.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/history.h
10505 --- linux-3.13.6/include/linux/vserver/history.h 1970-01-01 00:00:00.000000000 +0000
10506 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/history.h 2014-01-31 20:38:03.000000000 +0000
10508 +#ifndef _VSERVER_HISTORY_H
10509 +#define _VSERVER_HISTORY_H
10514 + VXH_THROW_OOPS = 1,
10518 + VXH_INIT_VX_INFO,
10521 + VXH_CLAIM_VX_INFO,
10522 + VXH_RELEASE_VX_INFO,
10523 + VXH_ALLOC_VX_INFO,
10524 + VXH_DEALLOC_VX_INFO,
10525 + VXH_HASH_VX_INFO,
10526 + VXH_UNHASH_VX_INFO,
10528 + VXH_LOOKUP_VX_INFO,
10529 + VXH_CREATE_VX_INFO,
10532 +struct _vxhe_vxi {
10533 + struct vx_info *ptr;
10539 +struct _vxhe_set_clr {
10543 +struct _vxhe_loc_lookup {
10547 +struct _vx_hist_entry {
10549 + unsigned short seq;
10550 + unsigned short type;
10551 + struct _vxhe_vxi vxi;
10553 + struct _vxhe_set_clr sc;
10554 + struct _vxhe_loc_lookup ll;
10558 +#ifdef CONFIG_VSERVER_HISTORY
10560 +extern unsigned volatile int vxh_active;
10562 +struct _vx_hist_entry *vxh_advance(void *loc);
10566 +void __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
10568 + entry->vxi.ptr = vxi;
10570 + entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
10571 + entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
10572 + entry->vxi.xid = vxi->vx_id;
10577 +#define __HERE__ current_text_addr()
10579 +#define __VXH_BODY(__type, __data, __here) \
10580 + struct _vx_hist_entry *entry; \
10582 + preempt_disable(); \
10583 + entry = vxh_advance(__here); \
10585 + entry->type = __type; \
10586 + preempt_enable();
10589 + /* pass vxi only */
10591 +#define __VXH_SMPL \
10592 + __vxh_copy_vxi(entry, vxi)
10595 +void __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
10597 + __VXH_BODY(__type, __VXH_SMPL, __here)
10600 + /* pass vxi and data (void *) */
10602 +#define __VXH_DATA \
10603 + __vxh_copy_vxi(entry, vxi); \
10604 + entry->sc.data = data
10607 +void __vxh_data(struct vx_info *vxi, void *data,
10608 + int __type, void *__here)
10610 + __VXH_BODY(__type, __VXH_DATA, __here)
10613 + /* pass vxi and arg (long) */
10615 +#define __VXH_LONG \
10616 + __vxh_copy_vxi(entry, vxi); \
10617 + entry->ll.arg = arg
10620 +void __vxh_long(struct vx_info *vxi, long arg,
10621 + int __type, void *__here)
10623 + __VXH_BODY(__type, __VXH_LONG, __here)
10628 +void __vxh_throw_oops(void *__here)
10630 + __VXH_BODY(VXH_THROW_OOPS, {}, __here);
10631 + /* prevent further acquisition */
10636 +#define vxh_throw_oops() __vxh_throw_oops(__HERE__);
10638 +#define __vxh_get_vx_info(v, h) __vxh_smpl(v, VXH_GET_VX_INFO, h);
10639 +#define __vxh_put_vx_info(v, h) __vxh_smpl(v, VXH_PUT_VX_INFO, h);
10641 +#define __vxh_init_vx_info(v, d, h) \
10642 + __vxh_data(v, d, VXH_INIT_VX_INFO, h);
10643 +#define __vxh_set_vx_info(v, d, h) \
10644 + __vxh_data(v, d, VXH_SET_VX_INFO, h);
10645 +#define __vxh_clr_vx_info(v, d, h) \
10646 + __vxh_data(v, d, VXH_CLR_VX_INFO, h);
10648 +#define __vxh_claim_vx_info(v, d, h) \
10649 + __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
10650 +#define __vxh_release_vx_info(v, d, h) \
10651 + __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
10653 +#define vxh_alloc_vx_info(v) \
10654 + __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
10655 +#define vxh_dealloc_vx_info(v) \
10656 + __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
10658 +#define vxh_hash_vx_info(v) \
10659 + __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
10660 +#define vxh_unhash_vx_info(v) \
10661 + __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
10663 +#define vxh_loc_vx_info(v, l) \
10664 + __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
10665 +#define vxh_lookup_vx_info(v, l) \
10666 + __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
10667 +#define vxh_create_vx_info(v, l) \
10668 + __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
10670 +extern void vxh_dump_history(void);
10673 +#else /* CONFIG_VSERVER_HISTORY */
10675 +#define __HERE__ 0
10677 +#define vxh_throw_oops() do { } while (0)
10679 +#define __vxh_get_vx_info(v, h) do { } while (0)
10680 +#define __vxh_put_vx_info(v, h) do { } while (0)
10682 +#define __vxh_init_vx_info(v, d, h) do { } while (0)
10683 +#define __vxh_set_vx_info(v, d, h) do { } while (0)
10684 +#define __vxh_clr_vx_info(v, d, h) do { } while (0)
10686 +#define __vxh_claim_vx_info(v, d, h) do { } while (0)
10687 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
10689 +#define vxh_alloc_vx_info(v) do { } while (0)
10690 +#define vxh_dealloc_vx_info(v) do { } while (0)
10692 +#define vxh_hash_vx_info(v) do { } while (0)
10693 +#define vxh_unhash_vx_info(v) do { } while (0)
10695 +#define vxh_loc_vx_info(v, l) do { } while (0)
10696 +#define vxh_lookup_vx_info(v, l) do { } while (0)
10697 +#define vxh_create_vx_info(v, l) do { } while (0)
10699 +#define vxh_dump_history() do { } while (0)
10702 +#endif /* CONFIG_VSERVER_HISTORY */
10704 +#endif /* _VSERVER_HISTORY_H */
10705 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/inode.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/inode.h
10706 --- linux-3.13.6/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
10707 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/inode.h 2014-01-31 20:38:03.000000000 +0000
10709 +#ifndef _VSERVER_INODE_H
10710 +#define _VSERVER_INODE_H
10712 +#include <uapi/vserver/inode.h>
10715 +#ifdef CONFIG_VSERVER_PROC_SECURE
10716 +#define IATTR_PROC_DEFAULT ( IATTR_ADMIN | IATTR_HIDE )
10717 +#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
10719 +#define IATTR_PROC_DEFAULT ( IATTR_ADMIN )
10720 +#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
10723 +#define vx_hide_check(c, m) (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
10725 +#else /* _VSERVER_INODE_H */
10726 +#warning duplicate inclusion
10727 +#endif /* _VSERVER_INODE_H */
10728 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/inode_cmd.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/inode_cmd.h
10729 --- linux-3.13.6/include/linux/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
10730 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/inode_cmd.h 2014-01-31 20:38:03.000000000 +0000
10732 +#ifndef _VSERVER_INODE_CMD_H
10733 +#define _VSERVER_INODE_CMD_H
10735 +#include <uapi/vserver/inode_cmd.h>
10739 +#ifdef CONFIG_COMPAT
10741 +#include <asm/compat.h>
10743 +struct vcmd_ctx_iattr_v1_x32 {
10744 + compat_uptr_t name_ptr;
10750 +#endif /* CONFIG_COMPAT */
10752 +#include <linux/compiler.h>
10754 +extern int vc_get_iattr(void __user *);
10755 +extern int vc_set_iattr(void __user *);
10757 +extern int vc_fget_iattr(uint32_t, void __user *);
10758 +extern int vc_fset_iattr(uint32_t, void __user *);
10760 +#ifdef CONFIG_COMPAT
10762 +extern int vc_get_iattr_x32(void __user *);
10763 +extern int vc_set_iattr_x32(void __user *);
10765 +#endif /* CONFIG_COMPAT */
10767 +#endif /* _VSERVER_INODE_CMD_H */
10768 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/limit.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/limit.h
10769 --- linux-3.13.6/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
10770 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/limit.h 2014-01-31 20:38:03.000000000 +0000
10772 +#ifndef _VSERVER_LIMIT_H
10773 +#define _VSERVER_LIMIT_H
10775 +#include <uapi/vserver/limit.h>
10778 +#define VLIM_NOCHECK ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
10780 +/* keep in sync with CRLIM_INFINITY */
10782 +#define VLIM_INFINITY (~0ULL)
10784 +#include <asm/atomic.h>
10785 +#include <asm/resource.h>
10787 +#ifndef RLIM_INFINITY
10788 +#warning RLIM_INFINITY is undefined
10791 +#define __rlim_val(l, r, v) ((l)->res[r].v)
10793 +#define __rlim_soft(l, r) __rlim_val(l, r, soft)
10794 +#define __rlim_hard(l, r) __rlim_val(l, r, hard)
10796 +#define __rlim_rcur(l, r) __rlim_val(l, r, rcur)
10797 +#define __rlim_rmin(l, r) __rlim_val(l, r, rmin)
10798 +#define __rlim_rmax(l, r) __rlim_val(l, r, rmax)
10800 +#define __rlim_lhit(l, r) __rlim_val(l, r, lhit)
10801 +#define __rlim_hit(l, r) atomic_inc(&__rlim_lhit(l, r))
10803 +typedef atomic_long_t rlim_atomic_t;
10804 +typedef unsigned long rlim_t;
10806 +#define __rlim_get(l, r) atomic_long_read(&__rlim_rcur(l, r))
10807 +#define __rlim_set(l, r, v) atomic_long_set(&__rlim_rcur(l, r), v)
10808 +#define __rlim_inc(l, r) atomic_long_inc(&__rlim_rcur(l, r))
10809 +#define __rlim_dec(l, r) atomic_long_dec(&__rlim_rcur(l, r))
10810 +#define __rlim_add(l, r, v) atomic_long_add(v, &__rlim_rcur(l, r))
10811 +#define __rlim_sub(l, r, v) atomic_long_sub(v, &__rlim_rcur(l, r))
10814 +#if (RLIM_INFINITY == VLIM_INFINITY)
10815 +#define VX_VLIM(r) ((long long)(long)(r))
10816 +#define VX_RLIM(v) ((rlim_t)(v))
10818 +#define VX_VLIM(r) (((r) == RLIM_INFINITY) \
10819 + ? VLIM_INFINITY : (long long)(r))
10820 +#define VX_RLIM(v) (((v) == VLIM_INFINITY) \
10821 + ? RLIM_INFINITY : (rlim_t)(v))
10826 +void vx_vsi_meminfo(struct sysinfo *);
10827 +void vx_vsi_swapinfo(struct sysinfo *);
10828 +long vx_vsi_cached(struct sysinfo *);
10830 +#define NUM_LIMITS 24
10832 +#endif /* _VSERVER_LIMIT_H */
10833 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/limit_cmd.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/limit_cmd.h
10834 --- linux-3.13.6/include/linux/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
10835 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/limit_cmd.h 2014-01-31 20:38:03.000000000 +0000
10837 +#ifndef _VSERVER_LIMIT_CMD_H
10838 +#define _VSERVER_LIMIT_CMD_H
10840 +#include <uapi/vserver/limit_cmd.h>
10843 +#ifdef CONFIG_IA32_EMULATION
10845 +struct vcmd_ctx_rlimit_v0_x32 {
10847 + uint64_t minimum;
10848 + uint64_t softlimit;
10849 + uint64_t maximum;
10850 +} __attribute__ ((packed));
10852 +#endif /* CONFIG_IA32_EMULATION */
10854 +#include <linux/compiler.h>
10856 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
10857 +extern int vc_get_rlimit(struct vx_info *, void __user *);
10858 +extern int vc_set_rlimit(struct vx_info *, void __user *);
10859 +extern int vc_reset_hits(struct vx_info *, void __user *);
10860 +extern int vc_reset_minmax(struct vx_info *, void __user *);
10862 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
10864 +#ifdef CONFIG_IA32_EMULATION
10866 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
10867 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
10869 +#endif /* CONFIG_IA32_EMULATION */
10871 +#endif /* _VSERVER_LIMIT_CMD_H */
10872 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/limit_def.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/limit_def.h
10873 --- linux-3.13.6/include/linux/vserver/limit_def.h 1970-01-01 00:00:00.000000000 +0000
10874 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/limit_def.h 2014-01-31 20:38:03.000000000 +0000
10876 +#ifndef _VSERVER_LIMIT_DEF_H
10877 +#define _VSERVER_LIMIT_DEF_H
10879 +#include <asm/atomic.h>
10880 +#include <asm/resource.h>
10882 +#include "limit.h"
10885 +struct _vx_res_limit {
10886 + rlim_t soft; /* Context soft limit */
10887 + rlim_t hard; /* Context hard limit */
10889 + rlim_atomic_t rcur; /* Current value */
10890 + rlim_t rmin; /* Context minimum */
10891 + rlim_t rmax; /* Context maximum */
10893 + atomic_t lhit; /* Limit hits */
10896 +/* context sub struct */
10898 +struct _vx_limit {
10899 + struct _vx_res_limit res[NUM_LIMITS];
10902 +#ifdef CONFIG_VSERVER_DEBUG
10904 +static inline void __dump_vx_limit(struct _vx_limit *limit)
10908 + printk("\t_vx_limit:");
10909 + for (i = 0; i < NUM_LIMITS; i++) {
10910 + printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
10911 + i, (unsigned long)__rlim_get(limit, i),
10912 + (unsigned long)__rlim_rmin(limit, i),
10913 + (unsigned long)__rlim_rmax(limit, i),
10914 + (long)__rlim_soft(limit, i),
10915 + (long)__rlim_hard(limit, i),
10916 + atomic_read(&__rlim_lhit(limit, i)));
10922 +#endif /* _VSERVER_LIMIT_DEF_H */
10923 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/limit_int.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/limit_int.h
10924 --- linux-3.13.6/include/linux/vserver/limit_int.h 1970-01-01 00:00:00.000000000 +0000
10925 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/limit_int.h 2014-01-31 20:38:03.000000000 +0000
10927 +#ifndef _VSERVER_LIMIT_INT_H
10928 +#define _VSERVER_LIMIT_INT_H
10930 +#define VXD_RCRES_COND(r) VXD_CBIT(cres, r)
10931 +#define VXD_RLIMIT_COND(r) VXD_CBIT(limit, r)
10933 +extern const char *vlimit_name[NUM_LIMITS];
10935 +static inline void __vx_acc_cres(struct vx_info *vxi,
10936 + int res, int dir, void *_data, char *_file, int _line)
10938 + if (VXD_RCRES_COND(res))
10939 + vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
10940 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10941 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10942 + (dir > 0) ? "++" : "--", _data, _file, _line);
10947 + __rlim_inc(&vxi->limit, res);
10949 + __rlim_dec(&vxi->limit, res);
10952 +static inline void __vx_add_cres(struct vx_info *vxi,
10953 + int res, int amount, void *_data, char *_file, int _line)
10955 + if (VXD_RCRES_COND(res))
10956 + vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
10957 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10958 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10959 + amount, _data, _file, _line);
10964 + __rlim_add(&vxi->limit, res, amount);
10968 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
10970 + int cond = (value > __rlim_rmax(limit, res));
10973 + __rlim_rmax(limit, res) = value;
10978 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
10980 + int cond = (value < __rlim_rmin(limit, res));
10983 + __rlim_rmin(limit, res) = value;
10988 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
10990 + if (!__vx_cres_adjust_max(limit, res, value))
10991 + __vx_cres_adjust_min(limit, res, value);
10996 + +1 ... no limit hit
10997 + -1 ... over soft limit
10998 + 0 ... over hard limit */
11000 +static inline int __vx_cres_avail(struct vx_info *vxi,
11001 + int res, int num, char *_file, int _line)
11003 + struct _vx_limit *limit;
11006 + if (VXD_RLIMIT_COND(res))
11007 + vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11008 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11009 + (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11010 + (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11011 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11012 + num, _file, _line);
11016 + limit = &vxi->limit;
11017 + value = __rlim_get(limit, res);
11019 + if (!__vx_cres_adjust_max(limit, res, value))
11020 + __vx_cres_adjust_min(limit, res, value);
11025 + if (__rlim_soft(limit, res) == RLIM_INFINITY)
11027 + if (value + num <= __rlim_soft(limit, res))
11030 + if (__rlim_hard(limit, res) == RLIM_INFINITY)
11032 + if (value + num <= __rlim_hard(limit, res))
11035 + __rlim_hit(limit, res);
11040 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11043 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11045 + rlim_t value, sum = 0;
11048 + while ((res = *array++)) {
11049 + value = __rlim_get(limit, res);
11050 + __vx_cres_fixup(limit, res, value);
11057 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11059 + rlim_t value = __vx_cres_array_sum(limit, array + 1);
11060 + int res = *array;
11062 + if (value == __rlim_get(limit, res))
11065 + __rlim_set(limit, res, value);
11066 + /* now adjust min/max */
11067 + if (!__vx_cres_adjust_max(limit, res, value))
11068 + __vx_cres_adjust_min(limit, res, value);
11073 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11074 + const int *array, int num, char *_file, int _line)
11076 + struct _vx_limit *limit;
11077 + rlim_t value = 0;
11085 + limit = &vxi->limit;
11087 + value = __vx_cres_array_sum(limit, array + 1);
11089 + __rlim_set(limit, res, value);
11090 + __vx_cres_fixup(limit, res, value);
11092 + return __vx_cres_avail(vxi, res, num, _file, _line);
11096 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11101 + /* complex resources first */
11102 + if ((id < 0) || (id == RLIMIT_RSS))
11103 + __vx_cres_array_fixup(limit, VLA_RSS);
11105 + for (res = 0; res < NUM_LIMITS; res++) {
11106 + if ((id > 0) && (res != id))
11109 + value = __rlim_get(limit, res);
11110 + __vx_cres_fixup(limit, res, value);
11112 + /* not supposed to happen, maybe warn? */
11113 + if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11114 + __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11119 +#endif /* _VSERVER_LIMIT_INT_H */
11120 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/monitor.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/monitor.h
11121 --- linux-3.13.6/include/linux/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
11122 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/monitor.h 2014-01-31 20:38:03.000000000 +0000
11124 +#ifndef _VSERVER_MONITOR_H
11125 +#define _VSERVER_MONITOR_H
11127 +#include <uapi/vserver/monitor.h>
11129 +#endif /* _VSERVER_MONITOR_H */
11130 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/network.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/network.h
11131 --- linux-3.13.6/include/linux/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
11132 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/network.h 2014-01-31 20:38:03.000000000 +0000
11134 +#ifndef _VSERVER_NETWORK_H
11135 +#define _VSERVER_NETWORK_H
11138 +#include <linux/list.h>
11139 +#include <linux/spinlock.h>
11140 +#include <linux/rcupdate.h>
11141 +#include <linux/in.h>
11142 +#include <linux/in6.h>
11143 +#include <asm/atomic.h>
11144 +#include <uapi/vserver/network.h>
11146 +struct nx_addr_v4 {
11147 + struct nx_addr_v4 *next;
11148 + struct in_addr ip[2];
11149 + struct in_addr mask;
11154 +struct nx_addr_v6 {
11155 + struct nx_addr_v6 *next;
11156 + struct in6_addr ip;
11157 + struct in6_addr mask;
11164 + struct hlist_node nx_hlist; /* linked list of nxinfos */
11165 + vnid_t nx_id; /* vnet id */
11166 + atomic_t nx_usecnt; /* usage count */
11167 + atomic_t nx_tasks; /* tasks count */
11168 + int nx_state; /* context state */
11170 + uint64_t nx_flags; /* network flag word */
11171 + uint64_t nx_ncaps; /* network capabilities */
11173 + spinlock_t addr_lock; /* protect address changes */
11174 + struct in_addr v4_lback; /* Loopback address */
11175 + struct in_addr v4_bcast; /* Broadcast address */
11176 + struct nx_addr_v4 v4; /* First/Single ipv4 address */
11177 +#ifdef CONFIG_IPV6
11178 + struct nx_addr_v6 v6; /* First/Single ipv6 address */
11180 + char nx_name[65]; /* network context name */
11184 +/* status flags */
11186 +#define NXS_HASHED 0x0001
11187 +#define NXS_SHUTDOWN 0x0100
11188 +#define NXS_RELEASED 0x8000
11190 +extern struct nx_info *lookup_nx_info(int);
11192 +extern int get_nid_list(int, unsigned int *, int);
11193 +extern int nid_is_hashed(vnid_t);
11195 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11197 +extern long vs_net_change(struct nx_info *, unsigned int);
11202 +#define NX_IPV4(n) ((n)->v4.type != NXA_TYPE_NONE)
11203 +#ifdef CONFIG_IPV6
11204 +#define NX_IPV6(n) ((n)->v6.type != NXA_TYPE_NONE)
11206 +#define NX_IPV6(n) (0)
11209 +#endif /* _VSERVER_NETWORK_H */
11210 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/network_cmd.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/network_cmd.h
11211 --- linux-3.13.6/include/linux/vserver/network_cmd.h 1970-01-01 00:00:00.000000000 +0000
11212 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/network_cmd.h 2014-01-31 20:38:03.000000000 +0000
11214 +#ifndef _VSERVER_NETWORK_CMD_H
11215 +#define _VSERVER_NETWORK_CMD_H
11217 +#include <uapi/vserver/network_cmd.h>
11219 +extern int vc_task_nid(uint32_t);
11221 +extern int vc_nx_info(struct nx_info *, void __user *);
11223 +extern int vc_net_create(uint32_t, void __user *);
11224 +extern int vc_net_migrate(struct nx_info *, void __user *);
11226 +extern int vc_net_add(struct nx_info *, void __user *);
11227 +extern int vc_net_remove(struct nx_info *, void __user *);
11229 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11230 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11232 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11233 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11235 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11236 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11238 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11239 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11241 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11242 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11244 +extern int vc_get_nflags(struct nx_info *, void __user *);
11245 +extern int vc_set_nflags(struct nx_info *, void __user *);
11247 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11248 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11250 +#endif /* _VSERVER_CONTEXT_CMD_H */
11251 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/percpu.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/percpu.h
11252 --- linux-3.13.6/include/linux/vserver/percpu.h 1970-01-01 00:00:00.000000000 +0000
11253 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/percpu.h 2014-01-31 20:38:03.000000000 +0000
11255 +#ifndef _VSERVER_PERCPU_H
11256 +#define _VSERVER_PERCPU_H
11258 +#include "cvirt_def.h"
11259 +#include "sched_def.h"
11261 +struct _vx_percpu {
11262 + struct _vx_cvirt_pc cvirt;
11263 + struct _vx_sched_pc sched;
11266 +#define PERCPU_PERCTX (sizeof(struct _vx_percpu))
11268 +#endif /* _VSERVER_PERCPU_H */
11269 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/pid.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/pid.h
11270 --- linux-3.13.6/include/linux/vserver/pid.h 1970-01-01 00:00:00.000000000 +0000
11271 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/pid.h 2014-01-31 20:38:03.000000000 +0000
11273 +#ifndef _VSERVER_PID_H
11274 +#define _VSERVER_PID_H
11276 +/* pid faking stuff */
11278 +#define vx_info_map_pid(v, p) \
11279 + __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
11280 +#define vx_info_map_tgid(v,p) vx_info_map_pid(v,p)
11281 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
11282 +#define vx_map_tgid(p) vx_map_pid(p)
11284 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
11285 + const char *func, const char *file, int line)
11287 + if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11288 + vxfprintk(VXD_CBIT(cvirt, 2),
11289 + "vx_map_tgid: %p/%llx: %d -> %d",
11290 + vxi, (long long)vxi->vx_flags, pid,
11291 + (pid && pid == vxi->vx_initpid) ? 1 : pid,
11292 + func, file, line);
11295 + if (pid == vxi->vx_initpid)
11301 +#define vx_info_rmap_pid(v, p) \
11302 + __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
11303 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
11304 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
11306 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
11307 + const char *func, const char *file, int line)
11309 + if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11310 + vxfprintk(VXD_CBIT(cvirt, 2),
11311 + "vx_rmap_tgid: %p/%llx: %d -> %d",
11312 + vxi, (long long)vxi->vx_flags, pid,
11313 + (pid == 1) ? vxi->vx_initpid : pid,
11314 + func, file, line);
11315 + if ((pid == 1) && vxi->vx_initpid)
11316 + return vxi->vx_initpid;
11317 + if (pid == vxi->vx_initpid)
11324 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/sched.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/sched.h
11325 --- linux-3.13.6/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
11326 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/sched.h 2014-01-31 20:38:03.000000000 +0000
11328 +#ifndef _VSERVER_SCHED_H
11329 +#define _VSERVER_SCHED_H
11336 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11341 +void vx_update_load(struct vx_info *);
11344 +void vx_update_sched_param(struct _vx_sched *sched,
11345 + struct _vx_sched_pc *sched_pc);
11347 +#endif /* __KERNEL__ */
11348 +#else /* _VSERVER_SCHED_H */
11349 +#warning duplicate inclusion
11350 +#endif /* _VSERVER_SCHED_H */
11351 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/sched_cmd.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/sched_cmd.h
11352 --- linux-3.13.6/include/linux/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
11353 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/sched_cmd.h 2014-01-31 20:38:03.000000000 +0000
11355 +#ifndef _VSERVER_SCHED_CMD_H
11356 +#define _VSERVER_SCHED_CMD_H
11359 +#include <linux/compiler.h>
11360 +#include <uapi/vserver/sched_cmd.h>
11362 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
11363 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
11365 +#endif /* _VSERVER_SCHED_CMD_H */
11366 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/sched_def.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/sched_def.h
11367 --- linux-3.13.6/include/linux/vserver/sched_def.h 1970-01-01 00:00:00.000000000 +0000
11368 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/sched_def.h 2014-01-31 20:38:03.000000000 +0000
11370 +#ifndef _VSERVER_SCHED_DEF_H
11371 +#define _VSERVER_SCHED_DEF_H
11373 +#include <linux/spinlock.h>
11374 +#include <linux/jiffies.h>
11375 +#include <linux/cpumask.h>
11376 +#include <asm/atomic.h>
11377 +#include <asm/param.h>
11380 +/* context sub struct */
11382 +struct _vx_sched {
11383 + int prio_bias; /* bias offset for priority */
11385 + cpumask_t update; /* CPUs which should update */
11388 +struct _vx_sched_pc {
11389 + int prio_bias; /* bias offset for priority */
11391 + uint64_t user_ticks; /* token tick events */
11392 + uint64_t sys_ticks; /* token tick events */
11393 + uint64_t hold_ticks; /* token ticks paused */
11397 +#ifdef CONFIG_VSERVER_DEBUG
11399 +static inline void __dump_vx_sched(struct _vx_sched *sched)
11401 + printk("\t_vx_sched:\n");
11402 + printk("\t priority = %4d\n", sched->prio_bias);
11407 +#endif /* _VSERVER_SCHED_DEF_H */
11408 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/signal.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/signal.h
11409 --- linux-3.13.6/include/linux/vserver/signal.h 1970-01-01 00:00:00.000000000 +0000
11410 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/signal.h 2014-01-31 20:38:03.000000000 +0000
11412 +#ifndef _VSERVER_SIGNAL_H
11413 +#define _VSERVER_SIGNAL_H
11420 +int vx_info_kill(struct vx_info *, int, int);
11422 +#endif /* __KERNEL__ */
11423 +#else /* _VSERVER_SIGNAL_H */
11424 +#warning duplicate inclusion
11425 +#endif /* _VSERVER_SIGNAL_H */
11426 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/signal_cmd.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/signal_cmd.h
11427 --- linux-3.13.6/include/linux/vserver/signal_cmd.h 1970-01-01 00:00:00.000000000 +0000
11428 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/signal_cmd.h 2014-01-31 20:38:03.000000000 +0000
11430 +#ifndef _VSERVER_SIGNAL_CMD_H
11431 +#define _VSERVER_SIGNAL_CMD_H
11433 +#include <uapi/vserver/signal_cmd.h>
11436 +extern int vc_ctx_kill(struct vx_info *, void __user *);
11437 +extern int vc_wait_exit(struct vx_info *, void __user *);
11440 +extern int vc_get_pflags(uint32_t pid, void __user *);
11441 +extern int vc_set_pflags(uint32_t pid, void __user *);
11443 +#endif /* _VSERVER_SIGNAL_CMD_H */
11444 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/space.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/space.h
11445 --- linux-3.13.6/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
11446 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/space.h 2014-01-31 20:38:03.000000000 +0000
11448 +#ifndef _VSERVER_SPACE_H
11449 +#define _VSERVER_SPACE_H
11451 +#include <linux/types.h>
11455 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
11457 +#else /* _VSERVER_SPACE_H */
11458 +#warning duplicate inclusion
11459 +#endif /* _VSERVER_SPACE_H */
11460 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/space_cmd.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/space_cmd.h
11461 --- linux-3.13.6/include/linux/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
11462 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/space_cmd.h 2014-01-31 20:38:03.000000000 +0000
11464 +#ifndef _VSERVER_SPACE_CMD_H
11465 +#define _VSERVER_SPACE_CMD_H
11467 +#include <uapi/vserver/space_cmd.h>
11470 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
11471 +extern int vc_set_space_v1(struct vx_info *, void __user *);
11472 +extern int vc_enter_space(struct vx_info *, void __user *);
11473 +extern int vc_set_space(struct vx_info *, void __user *);
11474 +extern int vc_get_space_mask(void __user *, int);
11476 +#endif /* _VSERVER_SPACE_CMD_H */
11477 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/switch.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/switch.h
11478 --- linux-3.13.6/include/linux/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
11479 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/switch.h 2014-01-31 20:38:03.000000000 +0000
11481 +#ifndef _VSERVER_SWITCH_H
11482 +#define _VSERVER_SWITCH_H
11485 +#include <linux/errno.h>
11486 +#include <uapi/vserver/switch.h>
11488 +#endif /* _VSERVER_SWITCH_H */
11489 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/tag.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/tag.h
11490 --- linux-3.13.6/include/linux/vserver/tag.h 1970-01-01 00:00:00.000000000 +0000
11491 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/tag.h 2014-01-31 20:38:03.000000000 +0000
11496 +#include <linux/types.h>
11497 +#include <linux/uidgid.h>
11500 +#define DX_TAG(in) (IS_TAGGED(in))
11503 +#ifdef CONFIG_TAG_NFSD
11504 +#define DX_TAG_NFSD 1
11506 +#define DX_TAG_NFSD 0
11510 +#ifdef CONFIG_TAGGING_NONE
11512 +#define MAX_UID 0xFFFFFFFF
11513 +#define MAX_GID 0xFFFFFFFF
11515 +#define INOTAG_TAG(cond, uid, gid, tag) (0)
11517 +#define TAGINO_UID(cond, uid, tag) (uid)
11518 +#define TAGINO_GID(cond, gid, tag) (gid)
11523 +#ifdef CONFIG_TAGGING_GID16
11525 +#define MAX_UID 0xFFFFFFFF
11526 +#define MAX_GID 0x0000FFFF
11528 +#define INOTAG_TAG(cond, uid, gid, tag) \
11529 + ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
11531 +#define TAGINO_UID(cond, uid, tag) (uid)
11532 +#define TAGINO_GID(cond, gid, tag) \
11533 + ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
11538 +#ifdef CONFIG_TAGGING_ID24
11540 +#define MAX_UID 0x00FFFFFF
11541 +#define MAX_GID 0x00FFFFFF
11543 +#define INOTAG_TAG(cond, uid, gid, tag) \
11544 + ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
11546 +#define TAGINO_UID(cond, uid, tag) \
11547 + ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
11548 +#define TAGINO_GID(cond, gid, tag) \
11549 + ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
11554 +#ifdef CONFIG_TAGGING_UID16
11556 +#define MAX_UID 0x0000FFFF
11557 +#define MAX_GID 0xFFFFFFFF
11559 +#define INOTAG_TAG(cond, uid, gid, tag) \
11560 + ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
11562 +#define TAGINO_UID(cond, uid, tag) \
11563 + ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
11564 +#define TAGINO_GID(cond, gid, tag) (gid)
11569 +#ifdef CONFIG_TAGGING_INTERN
11571 +#define MAX_UID 0xFFFFFFFF
11572 +#define MAX_GID 0xFFFFFFFF
11574 +#define INOTAG_TAG(cond, uid, gid, tag) \
11575 + ((cond) ? (tag) : 0)
11577 +#define TAGINO_UID(cond, uid, tag) (uid)
11578 +#define TAGINO_GID(cond, gid, tag) (gid)
11583 +#ifndef CONFIG_TAGGING_NONE
11584 +#define dx_current_fstag(sb) \
11585 + ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
11587 +#define dx_current_fstag(sb) (0)
11590 +#ifndef CONFIG_TAGGING_INTERN
11591 +#define TAGINO_TAG(cond, tag) (0)
11593 +#define TAGINO_TAG(cond, tag) ((cond) ? (tag) : 0)
11596 +#define TAGINO_KUID(cond, kuid, ktag) \
11597 + KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
11598 +#define TAGINO_KGID(cond, kgid, ktag) \
11599 + KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
11600 +#define TAGINO_KTAG(cond, ktag) \
11601 + KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
11604 +#define INOTAG_UID(cond, uid, gid) \
11605 + ((cond) ? ((uid) & MAX_UID) : (uid))
11606 +#define INOTAG_GID(cond, uid, gid) \
11607 + ((cond) ? ((gid) & MAX_GID) : (gid))
11609 +#define INOTAG_KUID(cond, kuid, kgid) \
11610 + KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11611 +#define INOTAG_KGID(cond, kuid, kgid) \
11612 + KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11613 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
11614 + KTAGT_INIT(INOTAG_TAG(cond, \
11615 + __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
11618 +static inline uid_t dx_map_uid(uid_t uid)
11620 + if ((uid > MAX_UID) && (uid != -1))
11622 + return (uid & MAX_UID);
11625 +static inline gid_t dx_map_gid(gid_t gid)
11627 + if ((gid > MAX_GID) && (gid != -1))
11629 + return (gid & MAX_GID);
11637 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
11639 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
11640 + unsigned long *flags);
11642 +#ifdef CONFIG_PROPAGATE
11644 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
11646 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
11649 +#define dx_propagate_tag(n, i) do { } while (0)
11652 +#endif /* _DX_TAG_H */
11653 diff -NurpP --minimal linux-3.13.6/include/linux/vserver/tag_cmd.h linux-3.13.6-vs2.3.6.11/include/linux/vserver/tag_cmd.h
11654 --- linux-3.13.6/include/linux/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
11655 +++ linux-3.13.6-vs2.3.6.11/include/linux/vserver/tag_cmd.h 2014-01-31 20:38:03.000000000 +0000
11657 +#ifndef _VSERVER_TAG_CMD_H
11658 +#define _VSERVER_TAG_CMD_H
11660 +#include <uapi/vserver/tag_cmd.h>
11662 +extern int vc_task_tag(uint32_t);
11664 +extern int vc_tag_migrate(uint32_t);
11666 +#endif /* _VSERVER_TAG_CMD_H */
11667 diff -NurpP --minimal linux-3.13.6/include/net/addrconf.h linux-3.13.6-vs2.3.6.11/include/net/addrconf.h
11668 --- linux-3.13.6/include/net/addrconf.h 2013-11-25 15:47:02.000000000 +0000
11669 +++ linux-3.13.6-vs2.3.6.11/include/net/addrconf.h 2014-01-31 20:39:35.000000000 +0000
11670 @@ -79,7 +79,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
11672 int ipv6_dev_get_saddr(struct net *net, const struct net_device *dev,
11673 const struct in6_addr *daddr, unsigned int srcprefs,
11674 - struct in6_addr *saddr);
11675 + struct in6_addr *saddr, struct nx_info *nxi);
11676 int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
11677 unsigned char banned_flags);
11678 int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
11679 diff -NurpP --minimal linux-3.13.6/include/net/af_unix.h linux-3.13.6-vs2.3.6.11/include/net/af_unix.h
11680 --- linux-3.13.6/include/net/af_unix.h 2013-11-25 15:47:02.000000000 +0000
11681 +++ linux-3.13.6-vs2.3.6.11/include/net/af_unix.h 2014-01-31 20:38:03.000000000 +0000
11683 #include <linux/socket.h>
11684 #include <linux/un.h>
11685 #include <linux/mutex.h>
11686 +#include <linux/vs_base.h>
11687 #include <net/sock.h>
11689 void unix_inflight(struct file *fp);
11690 diff -NurpP --minimal linux-3.13.6/include/net/inet_timewait_sock.h linux-3.13.6-vs2.3.6.11/include/net/inet_timewait_sock.h
11691 --- linux-3.13.6/include/net/inet_timewait_sock.h 2014-01-22 20:39:11.000000000 +0000
11692 +++ linux-3.13.6-vs2.3.6.11/include/net/inet_timewait_sock.h 2014-01-31 20:40:30.000000000 +0000
11693 @@ -121,6 +121,10 @@ struct inet_timewait_sock {
11694 #define tw_v6_rcv_saddr __tw_common.skc_v6_rcv_saddr
11695 #define tw_dport __tw_common.skc_dport
11696 #define tw_num __tw_common.skc_num
11697 +#define tw_xid __tw_common.skc_xid
11698 +#define tw_vx_info __tw_common.skc_vx_info
11699 +#define tw_nid __tw_common.skc_nid
11700 +#define tw_nx_info __tw_common.skc_nx_info
11703 volatile unsigned char tw_substate;
11704 diff -NurpP --minimal linux-3.13.6/include/net/ip6_route.h linux-3.13.6-vs2.3.6.11/include/net/ip6_route.h
11705 --- linux-3.13.6/include/net/ip6_route.h 2014-01-22 20:39:11.000000000 +0000
11706 +++ linux-3.13.6-vs2.3.6.11/include/net/ip6_route.h 2014-01-31 20:41:10.000000000 +0000
11707 @@ -90,7 +90,7 @@ int ip6_del_rt(struct rt6_info *);
11709 int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
11710 const struct in6_addr *daddr, unsigned int prefs,
11711 - struct in6_addr *saddr);
11712 + struct in6_addr *saddr, struct nx_info *nxi);
11714 struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
11715 const struct in6_addr *saddr, int oif, int flags);
11716 diff -NurpP --minimal linux-3.13.6/include/net/route.h linux-3.13.6-vs2.3.6.11/include/net/route.h
11717 --- linux-3.13.6/include/net/route.h 2014-01-22 20:39:12.000000000 +0000
11718 +++ linux-3.13.6-vs2.3.6.11/include/net/route.h 2014-02-01 12:30:58.000000000 +0000
11719 @@ -203,6 +203,9 @@ static inline void ip_rt_put(struct rtab
11720 dst_release(&rt->dst);
11723 +#include <linux/vs_base.h>
11724 +#include <linux/vs_inet.h>
11726 #define IPTOS_RT_MASK (IPTOS_TOS_MASK & ~3)
11728 extern const __u8 ip_tos2prio[16];
11729 @@ -252,6 +255,9 @@ static inline void ip_route_connect_init
11730 protocol, flow_flags, dst, src, dport, sport);
11733 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
11734 + struct flowi4 *);
11736 static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
11737 __be32 dst, __be32 src, u32 tos,
11738 int oif, u8 protocol,
11739 @@ -260,11 +266,25 @@ static inline struct rtable *ip_route_co
11741 struct net *net = sock_net(sk);
11743 + struct nx_info *nx_info = current_nx_info();
11745 ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
11746 sport, dport, sk, can_sleep);
11748 - if (!dst || !src) {
11750 + nx_info = sk->sk_nx_info;
11752 + vxdprintk(VXD_CBIT(net, 4),
11753 + "ip_route_connect(%p) %p,%p;%lx",
11754 + sk, nx_info, sk->sk_socket,
11755 + (sk->sk_socket?sk->sk_socket->flags:0));
11757 + rt = ip_v4_find_src(net, nx_info, fl4);
11762 + if (!fl4->daddr || !fl4->saddr) {
11763 rt = __ip_route_output_key(net, fl4);
11766 diff -NurpP --minimal linux-3.13.6/include/net/sock.h linux-3.13.6-vs2.3.6.11/include/net/sock.h
11767 --- linux-3.13.6/include/net/sock.h 2014-01-22 20:39:12.000000000 +0000
11768 +++ linux-3.13.6-vs2.3.6.11/include/net/sock.h 2014-01-31 20:42:22.000000000 +0000
11769 @@ -191,6 +191,10 @@ struct sock_common {
11770 #ifdef CONFIG_NET_NS
11771 struct net *skc_net;
11774 + struct vx_info *skc_vx_info;
11776 + struct nx_info *skc_nx_info;
11778 #if IS_ENABLED(CONFIG_IPV6)
11779 struct in6_addr skc_v6_daddr;
11780 @@ -321,7 +325,11 @@ struct sock {
11781 #define sk_prot __sk_common.skc_prot
11782 #define sk_net __sk_common.skc_net
11783 #define sk_v6_daddr __sk_common.skc_v6_daddr
11784 -#define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
11785 +#define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
11786 +#define sk_xid __sk_common.skc_xid
11787 +#define sk_vx_info __sk_common.skc_vx_info
11788 +#define sk_nid __sk_common.skc_nid
11789 +#define sk_nx_info __sk_common.skc_nx_info
11791 socket_lock_t sk_lock;
11792 struct sk_buff_head sk_receive_queue;
11793 diff -NurpP --minimal linux-3.13.6/include/uapi/Kbuild linux-3.13.6-vs2.3.6.11/include/uapi/Kbuild
11794 --- linux-3.13.6/include/uapi/Kbuild 2012-12-11 03:30:57.000000000 +0000
11795 +++ linux-3.13.6-vs2.3.6.11/include/uapi/Kbuild 2014-01-31 20:38:03.000000000 +0000
11796 @@ -12,3 +12,4 @@ header-y += video/
11800 +header-y += vserver/
11801 diff -NurpP --minimal linux-3.13.6/include/uapi/linux/capability.h linux-3.13.6-vs2.3.6.11/include/uapi/linux/capability.h
11802 --- linux-3.13.6/include/uapi/linux/capability.h 2012-12-11 03:30:57.000000000 +0000
11803 +++ linux-3.13.6-vs2.3.6.11/include/uapi/linux/capability.h 2014-01-31 20:38:03.000000000 +0000
11804 @@ -259,6 +259,7 @@ struct vfs_cap_data {
11805 arbitrary SCSI commands */
11806 /* Allow setting encryption key on loopback filesystem */
11807 /* Allow setting zone reclaim policy */
11808 +/* Allow the selection of a security context */
11810 #define CAP_SYS_ADMIN 21
11812 @@ -345,7 +346,12 @@ struct vfs_cap_data {
11814 #define CAP_LAST_CAP CAP_BLOCK_SUSPEND
11816 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
11817 +/* Allow context manipulations */
11818 +/* Allow changing context info on files */
11820 +#define CAP_CONTEXT 63
11822 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
11825 * Bit location of each capability (used by user-space library and kernel)
11826 diff -NurpP --minimal linux-3.13.6/include/uapi/linux/fs.h linux-3.13.6-vs2.3.6.11/include/uapi/linux/fs.h
11827 --- linux-3.13.6/include/uapi/linux/fs.h 2013-11-25 15:47:02.000000000 +0000
11828 +++ linux-3.13.6-vs2.3.6.11/include/uapi/linux/fs.h 2014-01-31 20:38:03.000000000 +0000
11829 @@ -86,6 +86,9 @@ struct inodes_stat_t {
11830 #define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */
11831 #define MS_I_VERSION (1<<23) /* Update inode I_version field */
11832 #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
11833 +#define MS_TAGGED (1<<8) /* use generic inode tagging */
11834 +#define MS_NOTAGCHECK (1<<9) /* don't check tags */
11835 +#define MS_TAGID (1<<25) /* use specific tag for this mount */
11837 /* These sb flags are internal to the kernel */
11838 #define MS_NOSEC (1<<28)
11839 @@ -191,11 +194,14 @@ struct inodes_stat_t {
11840 #define FS_EXTENT_FL 0x00080000 /* Extents */
11841 #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */
11842 #define FS_NOCOW_FL 0x00800000 /* Do not cow file */
11843 +#define FS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
11844 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
11846 -#define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
11847 -#define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
11848 +#define FS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
11849 +#define FS_COW_FL 0x20000000 /* Copy on Write marker */
11851 +#define FS_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
11852 +#define FS_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
11854 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
11855 #define SYNC_FILE_RANGE_WRITE 2
11856 diff -NurpP --minimal linux-3.13.6/include/uapi/linux/gfs2_ondisk.h linux-3.13.6-vs2.3.6.11/include/uapi/linux/gfs2_ondisk.h
11857 --- linux-3.13.6/include/uapi/linux/gfs2_ondisk.h 2012-12-11 03:30:57.000000000 +0000
11858 +++ linux-3.13.6-vs2.3.6.11/include/uapi/linux/gfs2_ondisk.h 2014-01-31 20:38:03.000000000 +0000
11859 @@ -225,6 +225,9 @@ enum {
11862 gfs2fl_TopLevel = 10,
11863 + gfs2fl_IXUnlink = 16,
11864 + gfs2fl_Barrier = 17,
11866 gfs2fl_TruncInProg = 29,
11867 gfs2fl_InheritDirectio = 30,
11868 gfs2fl_InheritJdata = 31,
11869 @@ -242,6 +245,9 @@ enum {
11870 #define GFS2_DIF_SYNC 0x00000100
11871 #define GFS2_DIF_SYSTEM 0x00000200 /* New in gfs2 */
11872 #define GFS2_DIF_TOPDIR 0x00000400 /* New in gfs2 */
11873 +#define GFS2_DIF_IXUNLINK 0x00010000
11874 +#define GFS2_DIF_BARRIER 0x00020000
11875 +#define GFS2_DIF_COW 0x00040000
11876 #define GFS2_DIF_TRUNC_IN_PROG 0x20000000 /* New in gfs2 */
11877 #define GFS2_DIF_INHERIT_DIRECTIO 0x40000000 /* only in gfs1 */
11878 #define GFS2_DIF_INHERIT_JDATA 0x80000000
11879 diff -NurpP --minimal linux-3.13.6/include/uapi/linux/if_tun.h linux-3.13.6-vs2.3.6.11/include/uapi/linux/if_tun.h
11880 --- linux-3.13.6/include/uapi/linux/if_tun.h 2013-11-25 15:47:02.000000000 +0000
11881 +++ linux-3.13.6-vs2.3.6.11/include/uapi/linux/if_tun.h 2014-01-31 20:45:49.000000000 +0000
11883 #define TUNSETQUEUE _IOW('T', 217, int)
11884 #define TUNSETIFINDEX _IOW('T', 218, unsigned int)
11885 #define TUNGETFILTER _IOR('T', 219, struct sock_fprog)
11886 +#define TUNSETNID _IOW('T', 220, int)
11888 /* TUNSETIFF ifr flags */
11889 #define IFF_TUN 0x0001
11890 diff -NurpP --minimal linux-3.13.6/include/uapi/linux/major.h linux-3.13.6-vs2.3.6.11/include/uapi/linux/major.h
11891 --- linux-3.13.6/include/uapi/linux/major.h 2014-01-22 20:39:12.000000000 +0000
11892 +++ linux-3.13.6-vs2.3.6.11/include/uapi/linux/major.h 2014-01-31 20:38:03.000000000 +0000
11894 #define HD_MAJOR IDE0_MAJOR
11895 #define PTY_SLAVE_MAJOR 3
11896 #define TTY_MAJOR 4
11897 +#define VROOT_MAJOR 4
11898 #define TTYAUX_MAJOR 5
11900 #define VCS_MAJOR 7
11901 diff -NurpP --minimal linux-3.13.6/include/uapi/linux/nfs_mount.h linux-3.13.6-vs2.3.6.11/include/uapi/linux/nfs_mount.h
11902 --- linux-3.13.6/include/uapi/linux/nfs_mount.h 2014-01-22 20:39:12.000000000 +0000
11903 +++ linux-3.13.6-vs2.3.6.11/include/uapi/linux/nfs_mount.h 2014-01-31 20:38:03.000000000 +0000
11904 @@ -63,7 +63,8 @@ struct nfs_mount_data {
11905 #define NFS_MOUNT_SECFLAVOUR 0x2000 /* 5 non-text parsed mount data only */
11906 #define NFS_MOUNT_NORDIRPLUS 0x4000 /* 5 */
11907 #define NFS_MOUNT_UNSHARED 0x8000 /* 5 */
11908 -#define NFS_MOUNT_FLAGMASK 0xFFFF
11909 +#define NFS_MOUNT_TAGGED 0x10000 /* context tagging */
11910 +#define NFS_MOUNT_FLAGMASK 0x1FFFF
11912 /* The following are for internal use only */
11913 #define NFS_MOUNT_LOOKUP_CACHE_NONEG 0x10000
11914 diff -NurpP --minimal linux-3.13.6/include/uapi/linux/reboot.h linux-3.13.6-vs2.3.6.11/include/uapi/linux/reboot.h
11915 --- linux-3.13.6/include/uapi/linux/reboot.h 2012-12-11 03:30:57.000000000 +0000
11916 +++ linux-3.13.6-vs2.3.6.11/include/uapi/linux/reboot.h 2014-01-31 20:38:03.000000000 +0000
11918 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
11919 #define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
11920 #define LINUX_REBOOT_CMD_KEXEC 0x45584543
11922 +#define LINUX_REBOOT_CMD_OOM 0xDEADBEEF
11925 #endif /* _UAPI_LINUX_REBOOT_H */
11926 diff -NurpP --minimal linux-3.13.6/include/uapi/linux/sysctl.h linux-3.13.6-vs2.3.6.11/include/uapi/linux/sysctl.h
11927 --- linux-3.13.6/include/uapi/linux/sysctl.h 2012-12-11 03:30:57.000000000 +0000
11928 +++ linux-3.13.6-vs2.3.6.11/include/uapi/linux/sysctl.h 2014-01-31 20:38:03.000000000 +0000
11929 @@ -60,6 +60,7 @@ enum
11930 CTL_ABI=9, /* Binary emulation */
11931 CTL_CPU=10, /* CPU stuff (speed scaling, etc) */
11932 CTL_ARLAN=254, /* arlan wireless driver */
11933 + CTL_VSERVER=4242, /* Linux-VServer debug */
11934 CTL_S390DBF=5677, /* s390 debug */
11935 CTL_SUNRPC=7249, /* sunrpc debug */
11936 CTL_PM=9899, /* frv power management */
11937 @@ -94,6 +95,7 @@ enum
11939 KERN_PANIC=15, /* int: panic timeout */
11940 KERN_REALROOTDEV=16, /* real root device to mount after initrd */
11941 + KERN_VSHELPER=17, /* string: path to vshelper policy agent */
11943 KERN_SPARC_REBOOT=21, /* reboot command on Sparc */
11944 KERN_CTLALTDEL=22, /* int: allow ctl-alt-del to reboot */
11945 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/Kbuild linux-3.13.6-vs2.3.6.11/include/uapi/vserver/Kbuild
11946 --- linux-3.13.6/include/uapi/vserver/Kbuild 1970-01-01 00:00:00.000000000 +0000
11947 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/Kbuild 2014-01-31 20:38:03.000000000 +0000
11950 +header-y += context_cmd.h network_cmd.h space_cmd.h \
11951 + cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11952 + inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11953 + debug_cmd.h device_cmd.h
11955 +header-y += switch.h context.h network.h monitor.h \
11956 + limit.h inode.h device.h
11958 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/cacct_cmd.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/cacct_cmd.h
11959 --- linux-3.13.6/include/uapi/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
11960 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/cacct_cmd.h 2014-01-31 20:38:03.000000000 +0000
11962 +#ifndef _UAPI_VS_CACCT_CMD_H
11963 +#define _UAPI_VS_CACCT_CMD_H
11966 +/* virtual host info name commands */
11968 +#define VCMD_sock_stat VC_CMD(VSTAT, 5, 0)
11970 +struct vcmd_sock_stat_v0 {
11972 + uint32_t count[3];
11973 + uint64_t total[3];
11976 +#endif /* _UAPI_VS_CACCT_CMD_H */
11977 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/context.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/context.h
11978 --- linux-3.13.6/include/uapi/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
11979 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/context.h 2014-01-31 20:38:03.000000000 +0000
11981 +#ifndef _UAPI_VS_CONTEXT_H
11982 +#define _UAPI_VS_CONTEXT_H
11984 +#include <linux/types.h>
11985 +#include <linux/capability.h>
11988 +/* context flags */
11990 +#define VXF_INFO_SCHED 0x00000002
11991 +#define VXF_INFO_NPROC 0x00000004
11992 +#define VXF_INFO_PRIVATE 0x00000008
11994 +#define VXF_INFO_INIT 0x00000010
11995 +#define VXF_INFO_HIDE 0x00000020
11996 +#define VXF_INFO_ULIMIT 0x00000040
11997 +#define VXF_INFO_NSPACE 0x00000080
11999 +#define VXF_SCHED_HARD 0x00000100
12000 +#define VXF_SCHED_PRIO 0x00000200
12001 +#define VXF_SCHED_PAUSE 0x00000400
12003 +#define VXF_VIRT_MEM 0x00010000
12004 +#define VXF_VIRT_UPTIME 0x00020000
12005 +#define VXF_VIRT_CPU 0x00040000
12006 +#define VXF_VIRT_LOAD 0x00080000
12007 +#define VXF_VIRT_TIME 0x00100000
12009 +#define VXF_HIDE_MOUNT 0x01000000
12010 +/* was VXF_HIDE_NETIF 0x02000000 */
12011 +#define VXF_HIDE_VINFO 0x04000000
12013 +#define VXF_STATE_SETUP (1ULL << 32)
12014 +#define VXF_STATE_INIT (1ULL << 33)
12015 +#define VXF_STATE_ADMIN (1ULL << 34)
12017 +#define VXF_SC_HELPER (1ULL << 36)
12018 +#define VXF_REBOOT_KILL (1ULL << 37)
12019 +#define VXF_PERSISTENT (1ULL << 38)
12021 +#define VXF_FORK_RSS (1ULL << 48)
12022 +#define VXF_PROLIFIC (1ULL << 49)
12024 +#define VXF_IGNEG_NICE (1ULL << 52)
12026 +#define VXF_ONE_TIME (0x0007ULL << 32)
12028 +#define VXF_INIT_SET (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12031 +/* context migration */
12033 +#define VXM_SET_INIT 0x00000001
12034 +#define VXM_SET_REAPER 0x00000002
12036 +/* context caps */
12038 +#define VXC_SET_UTSNAME 0x00000001
12039 +#define VXC_SET_RLIMIT 0x00000002
12040 +#define VXC_FS_SECURITY 0x00000004
12041 +#define VXC_FS_TRUSTED 0x00000008
12042 +#define VXC_TIOCSTI 0x00000010
12044 +/* was VXC_RAW_ICMP 0x00000100 */
12045 +#define VXC_SYSLOG 0x00001000
12046 +#define VXC_OOM_ADJUST 0x00002000
12047 +#define VXC_AUDIT_CONTROL 0x00004000
12049 +#define VXC_SECURE_MOUNT 0x00010000
12050 +/* #define VXC_SECURE_REMOUNT 0x00020000 */
12051 +#define VXC_BINARY_MOUNT 0x00040000
12052 +#define VXC_DEV_MOUNT 0x00080000
12054 +#define VXC_QUOTA_CTL 0x00100000
12055 +#define VXC_ADMIN_MAPPER 0x00200000
12056 +#define VXC_ADMIN_CLOOP 0x00400000
12058 +#define VXC_KTHREAD 0x01000000
12059 +#define VXC_NAMESPACE 0x02000000
12061 +#endif /* _UAPI_VS_CONTEXT_H */
12062 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/context_cmd.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/context_cmd.h
12063 --- linux-3.13.6/include/uapi/vserver/context_cmd.h 1970-01-01 00:00:00.000000000 +0000
12064 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/context_cmd.h 2014-01-31 20:38:03.000000000 +0000
12066 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12067 +#define _UAPI_VS_CONTEXT_CMD_H
12070 +/* vinfo commands */
12072 +#define VCMD_task_xid VC_CMD(VINFO, 1, 0)
12075 +#define VCMD_vx_info VC_CMD(VINFO, 5, 0)
12077 +struct vcmd_vx_info_v0 {
12079 + uint32_t initpid;
12080 + /* more to come */
12084 +#define VCMD_ctx_stat VC_CMD(VSTAT, 0, 0)
12086 +struct vcmd_ctx_stat_v0 {
12089 + /* more to come */
12093 +/* context commands */
12095 +#define VCMD_ctx_create_v0 VC_CMD(VPROC, 1, 0)
12096 +#define VCMD_ctx_create VC_CMD(VPROC, 1, 1)
12098 +struct vcmd_ctx_create {
12099 + uint64_t flagword;
12102 +#define VCMD_ctx_migrate_v0 VC_CMD(PROCMIG, 1, 0)
12103 +#define VCMD_ctx_migrate VC_CMD(PROCMIG, 1, 1)
12105 +struct vcmd_ctx_migrate {
12106 + uint64_t flagword;
12111 +/* flag commands */
12113 +#define VCMD_get_cflags VC_CMD(FLAGS, 1, 0)
12114 +#define VCMD_set_cflags VC_CMD(FLAGS, 2, 0)
12116 +struct vcmd_ctx_flags_v0 {
12117 + uint64_t flagword;
12123 +/* context caps commands */
12125 +#define VCMD_get_ccaps VC_CMD(FLAGS, 3, 1)
12126 +#define VCMD_set_ccaps VC_CMD(FLAGS, 4, 1)
12128 +struct vcmd_ctx_caps_v1 {
12135 +/* bcaps commands */
12137 +#define VCMD_get_bcaps VC_CMD(FLAGS, 9, 0)
12138 +#define VCMD_set_bcaps VC_CMD(FLAGS, 10, 0)
12140 +struct vcmd_bcaps {
12147 +/* umask commands */
12149 +#define VCMD_get_umask VC_CMD(FLAGS, 13, 0)
12150 +#define VCMD_set_umask VC_CMD(FLAGS, 14, 0)
12152 +struct vcmd_umask {
12159 +/* wmask commands */
12161 +#define VCMD_get_wmask VC_CMD(FLAGS, 15, 0)
12162 +#define VCMD_set_wmask VC_CMD(FLAGS, 16, 0)
12164 +struct vcmd_wmask {
12173 +#define VCMD_get_badness VC_CMD(MEMCTRL, 5, 0)
12174 +#define VCMD_set_badness VC_CMD(MEMCTRL, 6, 0)
12176 +struct vcmd_badness_v0 {
12180 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12181 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/cvirt_cmd.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/cvirt_cmd.h
12182 --- linux-3.13.6/include/uapi/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
12183 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/cvirt_cmd.h 2014-01-31 20:38:03.000000000 +0000
12185 +#ifndef _UAPI_VS_CVIRT_CMD_H
12186 +#define _UAPI_VS_CVIRT_CMD_H
12189 +/* virtual host info name commands */
12191 +#define VCMD_set_vhi_name VC_CMD(VHOST, 1, 0)
12192 +#define VCMD_get_vhi_name VC_CMD(VHOST, 2, 0)
12194 +struct vcmd_vhi_name_v0 {
12200 +enum vhi_name_field {
12201 + VHIN_CONTEXT = 0,
12212 +#define VCMD_virt_stat VC_CMD(VSTAT, 3, 0)
12214 +struct vcmd_virt_stat_v0 {
12217 + uint32_t nr_threads;
12218 + uint32_t nr_running;
12219 + uint32_t nr_uninterruptible;
12220 + uint32_t nr_onhold;
12221 + uint32_t nr_forks;
12222 + uint32_t load[3];
12225 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12226 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/debug_cmd.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/debug_cmd.h
12227 --- linux-3.13.6/include/uapi/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
12228 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/debug_cmd.h 2014-01-31 20:38:03.000000000 +0000
12230 +#ifndef _UAPI_VS_DEBUG_CMD_H
12231 +#define _UAPI_VS_DEBUG_CMD_H
12234 +/* debug commands */
12236 +#define VCMD_dump_history VC_CMD(DEBUG, 1, 0)
12238 +#define VCMD_read_history VC_CMD(DEBUG, 5, 0)
12239 +#define VCMD_read_monitor VC_CMD(DEBUG, 6, 0)
12241 +struct vcmd_read_history_v0 {
12244 + char __user *data;
12247 +struct vcmd_read_monitor_v0 {
12250 + char __user *data;
12253 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12254 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/device.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/device.h
12255 --- linux-3.13.6/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
12256 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/device.h 2014-01-31 20:38:03.000000000 +0000
12258 +#ifndef _UAPI_VS_DEVICE_H
12259 +#define _UAPI_VS_DEVICE_H
12262 +#define DATTR_CREATE 0x00000001
12263 +#define DATTR_OPEN 0x00000002
12265 +#define DATTR_REMAP 0x00000010
12267 +#define DATTR_MASK 0x00000013
12269 +#endif /* _UAPI_VS_DEVICE_H */
12270 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/device_cmd.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/device_cmd.h
12271 --- linux-3.13.6/include/uapi/vserver/device_cmd.h 1970-01-01 00:00:00.000000000 +0000
12272 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/device_cmd.h 2014-01-31 20:38:03.000000000 +0000
12274 +#ifndef _UAPI_VS_DEVICE_CMD_H
12275 +#define _UAPI_VS_DEVICE_CMD_H
12278 +/* device vserver commands */
12280 +#define VCMD_set_mapping VC_CMD(DEVICE, 1, 0)
12281 +#define VCMD_unset_mapping VC_CMD(DEVICE, 2, 0)
12283 +struct vcmd_set_mapping_v0 {
12284 + const char __user *device;
12285 + const char __user *target;
12289 +#endif /* _UAPI_VS_DEVICE_CMD_H */
12290 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/dlimit_cmd.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/dlimit_cmd.h
12291 --- linux-3.13.6/include/uapi/vserver/dlimit_cmd.h 1970-01-01 00:00:00.000000000 +0000
12292 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/dlimit_cmd.h 2014-01-31 20:38:03.000000000 +0000
12294 +#ifndef _UAPI_VS_DLIMIT_CMD_H
12295 +#define _UAPI_VS_DLIMIT_CMD_H
12298 +/* dlimit vserver commands */
12300 +#define VCMD_add_dlimit VC_CMD(DLIMIT, 1, 0)
12301 +#define VCMD_rem_dlimit VC_CMD(DLIMIT, 2, 0)
12303 +#define VCMD_set_dlimit VC_CMD(DLIMIT, 5, 0)
12304 +#define VCMD_get_dlimit VC_CMD(DLIMIT, 6, 0)
12306 +struct vcmd_ctx_dlimit_base_v0 {
12307 + const char __user *name;
12311 +struct vcmd_ctx_dlimit_v0 {
12312 + const char __user *name;
12313 + uint32_t space_used; /* used space in kbytes */
12314 + uint32_t space_total; /* maximum space in kbytes */
12315 + uint32_t inodes_used; /* used inodes */
12316 + uint32_t inodes_total; /* maximum inodes */
12317 + uint32_t reserved; /* reserved for root in % */
12321 +#define CDLIM_UNSET ((uint32_t)0UL)
12322 +#define CDLIM_INFINITY ((uint32_t)~0UL)
12323 +#define CDLIM_KEEP ((uint32_t)~1UL)
12325 +#define DLIME_UNIT 0
12326 +#define DLIME_KILO 1
12327 +#define DLIME_MEGA 2
12328 +#define DLIME_GIGA 3
12330 +#define DLIMF_SHIFT 0x10
12332 +#define DLIMS_USED 0
12333 +#define DLIMS_TOTAL 2
12336 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12338 + int exp = (flags & DLIMF_SHIFT) ?
12339 + (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12340 + return ((uint64_t)val) << (10 * exp);
12344 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12348 + if (*flags & DLIMF_SHIFT) {
12349 + while (val > (1LL << 32) && (exp < 3)) {
12353 + *flags &= ~(DLIME_GIGA << shift);
12354 + *flags |= exp << shift;
12360 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
12361 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/inode.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/inode.h
12362 --- linux-3.13.6/include/uapi/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
12363 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/inode.h 2014-01-31 20:38:03.000000000 +0000
12365 +#ifndef _UAPI_VS_INODE_H
12366 +#define _UAPI_VS_INODE_H
12369 +#define IATTR_TAG 0x01000000
12371 +#define IATTR_ADMIN 0x00000001
12372 +#define IATTR_WATCH 0x00000002
12373 +#define IATTR_HIDE 0x00000004
12374 +#define IATTR_FLAGS 0x00000007
12376 +#define IATTR_BARRIER 0x00010000
12377 +#define IATTR_IXUNLINK 0x00020000
12378 +#define IATTR_IMMUTABLE 0x00040000
12379 +#define IATTR_COW 0x00080000
12382 +/* inode ioctls */
12384 +#define FIOC_GETXFLG _IOR('x', 5, long)
12385 +#define FIOC_SETXFLG _IOW('x', 6, long)
12387 +#endif /* _UAPI_VS_INODE_H */
12388 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/inode_cmd.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/inode_cmd.h
12389 --- linux-3.13.6/include/uapi/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
12390 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/inode_cmd.h 2014-01-31 20:38:03.000000000 +0000
12392 +#ifndef _UAPI_VS_INODE_CMD_H
12393 +#define _UAPI_VS_INODE_CMD_H
12396 +/* inode vserver commands */
12398 +#define VCMD_get_iattr VC_CMD(INODE, 1, 1)
12399 +#define VCMD_set_iattr VC_CMD(INODE, 2, 1)
12401 +#define VCMD_fget_iattr VC_CMD(INODE, 3, 0)
12402 +#define VCMD_fset_iattr VC_CMD(INODE, 4, 0)
12404 +struct vcmd_ctx_iattr_v1 {
12405 + const char __user *name;
12411 +struct vcmd_ctx_fiattr_v0 {
12417 +#endif /* _UAPI_VS_INODE_CMD_H */
12418 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/limit.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/limit.h
12419 --- linux-3.13.6/include/uapi/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
12420 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/limit.h 2014-01-31 20:38:03.000000000 +0000
12422 +#ifndef _UAPI_VS_LIMIT_H
12423 +#define _UAPI_VS_LIMIT_H
12426 +#define VLIMIT_NSOCK 16
12427 +#define VLIMIT_OPENFD 17
12428 +#define VLIMIT_ANON 18
12429 +#define VLIMIT_SHMEM 19
12430 +#define VLIMIT_SEMARY 20
12431 +#define VLIMIT_NSEMS 21
12432 +#define VLIMIT_DENTRY 22
12433 +#define VLIMIT_MAPPED 23
12435 +#endif /* _UAPI_VS_LIMIT_H */
12436 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/limit_cmd.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/limit_cmd.h
12437 --- linux-3.13.6/include/uapi/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
12438 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/limit_cmd.h 2014-01-31 20:38:03.000000000 +0000
12440 +#ifndef _UAPI_VS_LIMIT_CMD_H
12441 +#define _UAPI_VS_LIMIT_CMD_H
12444 +/* rlimit vserver commands */
12446 +#define VCMD_get_rlimit VC_CMD(RLIMIT, 1, 0)
12447 +#define VCMD_set_rlimit VC_CMD(RLIMIT, 2, 0)
12448 +#define VCMD_get_rlimit_mask VC_CMD(RLIMIT, 3, 0)
12449 +#define VCMD_reset_hits VC_CMD(RLIMIT, 7, 0)
12450 +#define VCMD_reset_minmax VC_CMD(RLIMIT, 9, 0)
12452 +struct vcmd_ctx_rlimit_v0 {
12454 + uint64_t minimum;
12455 + uint64_t softlimit;
12456 + uint64_t maximum;
12459 +struct vcmd_ctx_rlimit_mask_v0 {
12460 + uint32_t minimum;
12461 + uint32_t softlimit;
12462 + uint32_t maximum;
12465 +#define VCMD_rlimit_stat VC_CMD(VSTAT, 1, 0)
12467 +struct vcmd_rlimit_stat_v0 {
12471 + uint64_t minimum;
12472 + uint64_t maximum;
12475 +#define CRLIM_UNSET (0ULL)
12476 +#define CRLIM_INFINITY (~0ULL)
12477 +#define CRLIM_KEEP (~1ULL)
12479 +#endif /* _UAPI_VS_LIMIT_CMD_H */
12480 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/monitor.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/monitor.h
12481 --- linux-3.13.6/include/uapi/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
12482 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/monitor.h 2014-01-31 20:38:03.000000000 +0000
12484 +#ifndef _UAPI_VS_MONITOR_H
12485 +#define _UAPI_VS_MONITOR_H
12487 +#include <linux/types.h>
12495 + VXM_UPDATE = 0x20,
12499 + VXM_RQINFO_1 = 0x24,
12502 + VXM_ACTIVATE = 0x40,
12509 + VXM_MIGRATE = 0x48,
12512 + /* all other bits are flags */
12513 + VXM_SCHED = 0x80,
12516 +struct _vxm_update_1 {
12517 + uint32_t tokens_max;
12518 + uint32_t fill_rate;
12519 + uint32_t interval;
12522 +struct _vxm_update_2 {
12523 + uint32_t tokens_min;
12524 + uint32_t fill_rate;
12525 + uint32_t interval;
12528 +struct _vxm_rqinfo_1 {
12529 + uint16_t running;
12533 + uint32_t idle_tokens;
12536 +struct _vxm_rqinfo_2 {
12537 + uint32_t norm_time;
12538 + uint32_t idle_time;
12539 + uint32_t idle_skip;
12542 +struct _vxm_sched {
12544 + uint32_t norm_time;
12545 + uint32_t idle_time;
12548 +struct _vxm_task {
12553 +struct _vxm_event {
12562 + struct _vxm_task tsk;
12566 +struct _vx_mon_entry {
12570 + struct _vxm_event ev;
12571 + struct _vxm_sched sd;
12572 + struct _vxm_update_1 u1;
12573 + struct _vxm_update_2 u2;
12574 + struct _vxm_rqinfo_1 q1;
12575 + struct _vxm_rqinfo_2 q2;
12579 +#endif /* _UAPI_VS_MONITOR_H */
12580 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/network.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/network.h
12581 --- linux-3.13.6/include/uapi/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
12582 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/network.h 2014-01-31 20:38:03.000000000 +0000
12584 +#ifndef _UAPI_VS_NETWORK_H
12585 +#define _UAPI_VS_NETWORK_H
12587 +#include <linux/types.h>
12590 +#define MAX_N_CONTEXT 65535 /* Arbitrary limit */
12593 +/* network flags */
12595 +#define NXF_INFO_PRIVATE 0x00000008
12597 +#define NXF_SINGLE_IP 0x00000100
12598 +#define NXF_LBACK_REMAP 0x00000200
12599 +#define NXF_LBACK_ALLOW 0x00000400
12601 +#define NXF_HIDE_NETIF 0x02000000
12602 +#define NXF_HIDE_LBACK 0x04000000
12604 +#define NXF_STATE_SETUP (1ULL << 32)
12605 +#define NXF_STATE_ADMIN (1ULL << 34)
12607 +#define NXF_SC_HELPER (1ULL << 36)
12608 +#define NXF_PERSISTENT (1ULL << 38)
12610 +#define NXF_ONE_TIME (0x0005ULL << 32)
12613 +#define NXF_INIT_SET (__nxf_init_set())
12615 +static inline uint64_t __nxf_init_set(void) {
12616 + return NXF_STATE_ADMIN
12617 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12618 + | NXF_LBACK_REMAP
12621 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12624 + | NXF_HIDE_NETIF;
12628 +/* network caps */
12630 +#define NXC_TUN_CREATE 0x00000001
12632 +#define NXC_RAW_ICMP 0x00000100
12634 +#define NXC_MULTICAST 0x00001000
12637 +/* address types */
12639 +#define NXA_TYPE_IPV4 0x0001
12640 +#define NXA_TYPE_IPV6 0x0002
12642 +#define NXA_TYPE_NONE 0x0000
12643 +#define NXA_TYPE_ANY 0x00FF
12645 +#define NXA_TYPE_ADDR 0x0010
12646 +#define NXA_TYPE_MASK 0x0020
12647 +#define NXA_TYPE_RANGE 0x0040
12649 +#define NXA_MASK_ALL (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12651 +#define NXA_MOD_BCAST 0x0100
12652 +#define NXA_MOD_LBACK 0x0200
12654 +#define NXA_LOOPBACK 0x1000
12656 +#define NXA_MASK_BIND (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12657 +#define NXA_MASK_SHOW (NXA_MASK_ALL | NXA_LOOPBACK)
12659 +#endif /* _UAPI_VS_NETWORK_H */
12660 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/network_cmd.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/network_cmd.h
12661 --- linux-3.13.6/include/uapi/vserver/network_cmd.h 1970-01-01 00:00:00.000000000 +0000
12662 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/network_cmd.h 2014-01-31 20:38:03.000000000 +0000
12664 +#ifndef _UAPI_VS_NETWORK_CMD_H
12665 +#define _UAPI_VS_NETWORK_CMD_H
12668 +/* vinfo commands */
12670 +#define VCMD_task_nid VC_CMD(VINFO, 2, 0)
12673 +#define VCMD_nx_info VC_CMD(VINFO, 6, 0)
12675 +struct vcmd_nx_info_v0 {
12677 + /* more to come */
12681 +#include <linux/in.h>
12682 +#include <linux/in6.h>
12684 +#define VCMD_net_create_v0 VC_CMD(VNET, 1, 0)
12685 +#define VCMD_net_create VC_CMD(VNET, 1, 1)
12687 +struct vcmd_net_create {
12688 + uint64_t flagword;
12691 +#define VCMD_net_migrate VC_CMD(NETMIG, 1, 0)
12693 +#define VCMD_net_add VC_CMD(NETALT, 1, 0)
12694 +#define VCMD_net_remove VC_CMD(NETALT, 2, 0)
12696 +struct vcmd_net_addr_v0 {
12699 + struct in_addr ip[4];
12700 + struct in_addr mask[4];
12703 +#define VCMD_net_add_ipv4_v1 VC_CMD(NETALT, 1, 1)
12704 +#define VCMD_net_rem_ipv4_v1 VC_CMD(NETALT, 2, 1)
12706 +struct vcmd_net_addr_ipv4_v1 {
12709 + struct in_addr ip;
12710 + struct in_addr mask;
12713 +#define VCMD_net_add_ipv4 VC_CMD(NETALT, 1, 2)
12714 +#define VCMD_net_rem_ipv4 VC_CMD(NETALT, 2, 2)
12716 +struct vcmd_net_addr_ipv4_v2 {
12719 + struct in_addr ip;
12720 + struct in_addr ip2;
12721 + struct in_addr mask;
12724 +#define VCMD_net_add_ipv6 VC_CMD(NETALT, 3, 1)
12725 +#define VCMD_net_remove_ipv6 VC_CMD(NETALT, 4, 1)
12727 +struct vcmd_net_addr_ipv6_v1 {
12731 + struct in6_addr ip;
12732 + struct in6_addr mask;
12735 +#define VCMD_add_match_ipv4 VC_CMD(NETALT, 5, 0)
12736 +#define VCMD_get_match_ipv4 VC_CMD(NETALT, 6, 0)
12738 +struct vcmd_match_ipv4_v0 {
12743 + struct in_addr ip;
12744 + struct in_addr ip2;
12745 + struct in_addr mask;
12748 +#define VCMD_add_match_ipv6 VC_CMD(NETALT, 7, 0)
12749 +#define VCMD_get_match_ipv6 VC_CMD(NETALT, 8, 0)
12751 +struct vcmd_match_ipv6_v0 {
12756 + struct in6_addr ip;
12757 + struct in6_addr ip2;
12758 + struct in6_addr mask;
12764 +/* flag commands */
12766 +#define VCMD_get_nflags VC_CMD(FLAGS, 5, 0)
12767 +#define VCMD_set_nflags VC_CMD(FLAGS, 6, 0)
12769 +struct vcmd_net_flags_v0 {
12770 + uint64_t flagword;
12776 +/* network caps commands */
12778 +#define VCMD_get_ncaps VC_CMD(FLAGS, 7, 0)
12779 +#define VCMD_set_ncaps VC_CMD(FLAGS, 8, 0)
12781 +struct vcmd_net_caps_v0 {
12786 +#endif /* _UAPI_VS_NETWORK_CMD_H */
12787 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/sched_cmd.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/sched_cmd.h
12788 --- linux-3.13.6/include/uapi/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
12789 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/sched_cmd.h 2014-01-31 20:38:03.000000000 +0000
12791 +#ifndef _UAPI_VS_SCHED_CMD_H
12792 +#define _UAPI_VS_SCHED_CMD_H
12795 +struct vcmd_prio_bias {
12797 + int32_t prio_bias;
12800 +#define VCMD_set_prio_bias VC_CMD(SCHED, 4, 0)
12801 +#define VCMD_get_prio_bias VC_CMD(SCHED, 5, 0)
12803 +#endif /* _UAPI_VS_SCHED_CMD_H */
12804 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/signal_cmd.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/signal_cmd.h
12805 --- linux-3.13.6/include/uapi/vserver/signal_cmd.h 1970-01-01 00:00:00.000000000 +0000
12806 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/signal_cmd.h 2014-01-31 20:38:03.000000000 +0000
12808 +#ifndef _UAPI_VS_SIGNAL_CMD_H
12809 +#define _UAPI_VS_SIGNAL_CMD_H
12812 +/* signalling vserver commands */
12814 +#define VCMD_ctx_kill VC_CMD(PROCTRL, 1, 0)
12815 +#define VCMD_wait_exit VC_CMD(EVENT, 99, 0)
12817 +struct vcmd_ctx_kill_v0 {
12822 +struct vcmd_wait_exit_v0 {
12823 + int32_t reboot_cmd;
12824 + int32_t exit_code;
12828 +/* process alteration commands */
12830 +#define VCMD_get_pflags VC_CMD(PROCALT, 5, 0)
12831 +#define VCMD_set_pflags VC_CMD(PROCALT, 6, 0)
12833 +struct vcmd_pflags_v0 {
12834 + uint32_t flagword;
12838 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
12839 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/space_cmd.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/space_cmd.h
12840 --- linux-3.13.6/include/uapi/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
12841 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/space_cmd.h 2014-01-31 20:38:03.000000000 +0000
12843 +#ifndef _UAPI_VS_SPACE_CMD_H
12844 +#define _UAPI_VS_SPACE_CMD_H
12847 +#define VCMD_enter_space_v0 VC_CMD(PROCALT, 1, 0)
12848 +#define VCMD_enter_space_v1 VC_CMD(PROCALT, 1, 1)
12849 +#define VCMD_enter_space VC_CMD(PROCALT, 1, 2)
12851 +#define VCMD_set_space_v0 VC_CMD(PROCALT, 3, 0)
12852 +#define VCMD_set_space_v1 VC_CMD(PROCALT, 3, 1)
12853 +#define VCMD_set_space VC_CMD(PROCALT, 3, 2)
12855 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12857 +#define VCMD_get_space_mask VC_CMD(VSPACE, 0, 1)
12858 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12861 +struct vcmd_space_mask_v1 {
12865 +struct vcmd_space_mask_v2 {
12870 +#endif /* _UAPI_VS_SPACE_CMD_H */
12871 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/switch.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/switch.h
12872 --- linux-3.13.6/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12873 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/switch.h 2014-01-31 20:38:03.000000000 +0000
12875 +#ifndef _UAPI_VS_SWITCH_H
12876 +#define _UAPI_VS_SWITCH_H
12878 +#include <linux/types.h>
12881 +#define VC_CATEGORY(c) (((c) >> 24) & 0x3F)
12882 +#define VC_COMMAND(c) (((c) >> 16) & 0xFF)
12883 +#define VC_VERSION(c) ((c) & 0xFFF)
12885 +#define VC_CMD(c, i, v) ((((VC_CAT_ ## c) & 0x3F) << 24) \
12886 + | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12890 + Syscall Matrix V2.8
12892 + |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12893 + |STATS |DESTROY|ALTER |CHANGE |LIMIT |TEST | | | |
12894 + |INFO |SETUP | |MOVE | | | | | |
12895 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12896 + SYSTEM |VERSION|VSETUP |VHOST | | | | |DEVICE | |
12897 + HOST | 00| 01| 02| 03| 04| 05| | 06| 07|
12898 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12899 + CPU | |VPROC |PROCALT|PROCMIG|PROCTRL| | |SCHED. | |
12900 + PROCESS| 08| 09| 10| 11| 12| 13| | 14| 15|
12901 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12902 + MEMORY | | | | |MEMCTRL| | |SWAP | |
12903 + | 16| 17| 18| 19| 20| 21| | 22| 23|
12904 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12905 + NETWORK| |VNET |NETALT |NETMIG |NETCTL | | |SERIAL | |
12906 + | 24| 25| 26| 27| 28| 29| | 30| 31|
12907 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12908 + DISK | | | |TAGMIG |DLIMIT | | |INODE | |
12909 + VFS | 32| 33| 34| 35| 36| 37| | 38| 39|
12910 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12911 + OTHER |VSTAT | | | | | | |VINFO | |
12912 + | 40| 41| 42| 43| 44| 45| | 46| 47|
12913 + =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12914 + SPECIAL|EVENT | | | |FLAGS | | |VSPACE | |
12915 + | 48| 49| 50| 51| 52| 53| | 54| 55|
12916 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12917 + SPECIAL|DEBUG | | | |RLIMIT |SYSCALL| | |COMPAT |
12918 + | 56| 57| 58| 59| 60|TEST 61| | 62| 63|
12919 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12923 +#define VC_CAT_VERSION 0
12925 +#define VC_CAT_VSETUP 1
12926 +#define VC_CAT_VHOST 2
12928 +#define VC_CAT_DEVICE 6
12930 +#define VC_CAT_VPROC 9
12931 +#define VC_CAT_PROCALT 10
12932 +#define VC_CAT_PROCMIG 11
12933 +#define VC_CAT_PROCTRL 12
12935 +#define VC_CAT_SCHED 14
12936 +#define VC_CAT_MEMCTRL 20
12938 +#define VC_CAT_VNET 25
12939 +#define VC_CAT_NETALT 26
12940 +#define VC_CAT_NETMIG 27
12941 +#define VC_CAT_NETCTRL 28
12943 +#define VC_CAT_TAGMIG 35
12944 +#define VC_CAT_DLIMIT 36
12945 +#define VC_CAT_INODE 38
12947 +#define VC_CAT_VSTAT 40
12948 +#define VC_CAT_VINFO 46
12949 +#define VC_CAT_EVENT 48
12951 +#define VC_CAT_FLAGS 52
12952 +#define VC_CAT_VSPACE 54
12953 +#define VC_CAT_DEBUG 56
12954 +#define VC_CAT_RLIMIT 60
12956 +#define VC_CAT_SYSTEST 61
12957 +#define VC_CAT_COMPAT 63
12959 +/* query version */
12961 +#define VCMD_get_version VC_CMD(VERSION, 0, 0)
12962 +#define VCMD_get_vci VC_CMD(VERSION, 1, 0)
12964 +#endif /* _UAPI_VS_SWITCH_H */
12965 diff -NurpP --minimal linux-3.13.6/include/uapi/vserver/tag_cmd.h linux-3.13.6-vs2.3.6.11/include/uapi/vserver/tag_cmd.h
12966 --- linux-3.13.6/include/uapi/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
12967 +++ linux-3.13.6-vs2.3.6.11/include/uapi/vserver/tag_cmd.h 2014-01-31 20:38:03.000000000 +0000
12969 +#ifndef _UAPI_VS_TAG_CMD_H
12970 +#define _UAPI_VS_TAG_CMD_H
12973 +/* vinfo commands */
12975 +#define VCMD_task_tag VC_CMD(VINFO, 3, 0)
12978 +/* context commands */
12980 +#define VCMD_tag_migrate VC_CMD(TAGMIG, 1, 0)
12982 +#endif /* _UAPI_VS_TAG_CMD_H */
12983 diff -NurpP --minimal linux-3.13.6/init/Kconfig linux-3.13.6-vs2.3.6.11/init/Kconfig
12984 --- linux-3.13.6/init/Kconfig 2014-01-22 20:39:12.000000000 +0000
12985 +++ linux-3.13.6-vs2.3.6.11/init/Kconfig 2014-01-31 21:05:27.000000000 +0000
12986 @@ -855,6 +855,7 @@ config NUMA_BALANCING
12988 boolean "Control Group support"
12992 This option adds support for grouping sets of processes together, for
12993 use with process control subsystems such as Cpusets, CFS, memory
12994 @@ -1117,6 +1118,7 @@ config IPC_NS
12996 bool "User namespace"
12997 select UIDGID_STRICT_TYPE_CHECKS
12998 + depends on VSERVER_DISABLED
13002 diff -NurpP --minimal linux-3.13.6/init/main.c linux-3.13.6-vs2.3.6.11/init/main.c
13003 --- linux-3.13.6/init/main.c 2014-01-22 20:39:12.000000000 +0000
13004 +++ linux-3.13.6-vs2.3.6.11/init/main.c 2014-01-31 20:38:03.000000000 +0000
13006 #include <linux/sched_clock.h>
13007 #include <linux/context_tracking.h>
13008 #include <linux/random.h>
13009 +#include <linux/vserver/percpu.h>
13011 #include <asm/io.h>
13012 #include <asm/bugs.h>
13013 diff -NurpP --minimal linux-3.13.6/ipc/mqueue.c linux-3.13.6-vs2.3.6.11/ipc/mqueue.c
13014 --- linux-3.13.6/ipc/mqueue.c 2014-03-12 13:51:24.000000000 +0000
13015 +++ linux-3.13.6-vs2.3.6.11/ipc/mqueue.c 2014-03-12 15:51:08.000000000 +0000
13017 #include <linux/ipc_namespace.h>
13018 #include <linux/user_namespace.h>
13019 #include <linux/slab.h>
13020 +#include <linux/vs_context.h>
13021 +#include <linux/vs_limit.h>
13023 #include <net/sock.h>
13025 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13026 struct pid* notify_owner;
13027 struct user_namespace *notify_user_ns;
13028 struct user_struct *user; /* user who created, for accounting */
13029 + struct vx_info *vxi;
13030 struct sock *notify_sock;
13031 struct sk_buff *notify_cookie;
13033 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13034 if (S_ISREG(mode)) {
13035 struct mqueue_inode_info *info;
13036 unsigned long mq_bytes, mq_treesize;
13037 + struct vx_info *vxi = current_vx_info();
13039 inode->i_fop = &mqueue_file_operations;
13040 inode->i_size = FILENT_SIZE;
13041 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13042 info->notify_user_ns = NULL;
13044 info->user = NULL; /* set when all is ok */
13045 + info->vxi = NULL;
13046 info->msg_tree = RB_ROOT;
13047 info->node_cache = NULL;
13048 memset(&info->attr, 0, sizeof(info->attr));
13049 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13051 spin_lock(&mq_lock);
13052 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13053 - u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13054 + u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13055 + !vx_ipcmsg_avail(vxi, mq_bytes)) {
13056 spin_unlock(&mq_lock);
13057 /* mqueue_evict_inode() releases info->messages */
13061 u->mq_bytes += mq_bytes;
13062 + vx_ipcmsg_add(vxi, u, mq_bytes);
13063 spin_unlock(&mq_lock);
13066 info->user = get_uid(u);
13067 + info->vxi = get_vx_info(vxi);
13068 } else if (S_ISDIR(mode)) {
13070 /* Some things misbehave if size == 0 on a directory */
13071 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13075 + struct vx_info *vxi = info->vxi;
13077 spin_lock(&mq_lock);
13078 user->mq_bytes -= mq_bytes;
13079 + vx_ipcmsg_sub(vxi, user, mq_bytes);
13081 * get_ns_from_inode() ensures that the
13082 * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13083 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13085 ipc_ns->mq_queues_count--;
13086 spin_unlock(&mq_lock);
13087 + put_vx_info(vxi);
13091 diff -NurpP --minimal linux-3.13.6/ipc/msg.c linux-3.13.6-vs2.3.6.11/ipc/msg.c
13092 --- linux-3.13.6/ipc/msg.c 2013-11-25 15:47:03.000000000 +0000
13093 +++ linux-3.13.6-vs2.3.6.11/ipc/msg.c 2014-01-31 20:38:03.000000000 +0000
13095 #include <linux/rwsem.h>
13096 #include <linux/nsproxy.h>
13097 #include <linux/ipc_namespace.h>
13098 +#include <linux/vs_base.h>
13100 #include <asm/current.h>
13101 #include <asm/uaccess.h>
13102 @@ -194,6 +195,7 @@ static int newque(struct ipc_namespace *
13104 msq->q_perm.mode = msgflg & S_IRWXUGO;
13105 msq->q_perm.key = key;
13106 + msq->q_perm.xid = vx_current_xid();
13108 msq->q_perm.security = NULL;
13109 retval = security_msg_queue_alloc(msq);
13110 diff -NurpP --minimal linux-3.13.6/ipc/sem.c linux-3.13.6-vs2.3.6.11/ipc/sem.c
13111 --- linux-3.13.6/ipc/sem.c 2013-11-25 15:47:03.000000000 +0000
13112 +++ linux-3.13.6-vs2.3.6.11/ipc/sem.c 2014-01-31 20:38:03.000000000 +0000
13114 #include <linux/rwsem.h>
13115 #include <linux/nsproxy.h>
13116 #include <linux/ipc_namespace.h>
13117 +#include <linux/vs_base.h>
13118 +#include <linux/vs_limit.h>
13120 #include <asm/uaccess.h>
13122 @@ -500,6 +502,7 @@ static int newary(struct ipc_namespace *
13124 sma->sem_perm.mode = (semflg & S_IRWXUGO);
13125 sma->sem_perm.key = key;
13126 + sma->sem_perm.xid = vx_current_xid();
13128 sma->sem_perm.security = NULL;
13129 retval = security_sem_alloc(sma);
13130 @@ -514,6 +517,9 @@ static int newary(struct ipc_namespace *
13133 ns->used_sems += nsems;
13134 + /* FIXME: obsoleted? */
13135 + vx_semary_inc(sma);
13136 + vx_nsems_add(sma, nsems);
13138 sma->sem_base = (struct sem *) &sma[1];
13140 @@ -1103,6 +1109,9 @@ static void freeary(struct ipc_namespace
13142 wake_up_sem_queue_do(&tasks);
13143 ns->used_sems -= sma->sem_nsems;
13144 + /* FIXME: obsoleted? */
13145 + vx_nsems_sub(sma, sma->sem_nsems);
13146 + vx_semary_dec(sma);
13147 ipc_rcu_putref(sma, sem_rcu_free);
13150 diff -NurpP --minimal linux-3.13.6/ipc/shm.c linux-3.13.6-vs2.3.6.11/ipc/shm.c
13151 --- linux-3.13.6/ipc/shm.c 2014-01-22 20:39:12.000000000 +0000
13152 +++ linux-3.13.6-vs2.3.6.11/ipc/shm.c 2014-01-31 20:38:03.000000000 +0000
13154 #include <linux/nsproxy.h>
13155 #include <linux/mount.h>
13156 #include <linux/ipc_namespace.h>
13157 +#include <linux/vs_context.h>
13158 +#include <linux/vs_limit.h>
13160 #include <asm/uaccess.h>
13162 @@ -209,10 +211,14 @@ static void shm_open(struct vm_area_stru
13163 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13165 struct file *shm_file;
13166 + struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13167 + int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13169 shm_file = shp->shm_file;
13170 shp->shm_file = NULL;
13171 - ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13172 + vx_ipcshm_sub(vxi, shp, numpages);
13173 + ns->shm_tot -= numpages;
13177 if (!is_file_hugepages(shm_file))
13178 @@ -220,6 +226,7 @@ static void shm_destroy(struct ipc_names
13179 else if (shp->mlock_user)
13180 user_shm_unlock(file_inode(shm_file)->i_size, shp->mlock_user);
13182 + put_vx_info(vxi);
13183 ipc_rcu_putref(shp, shm_rcu_free);
13186 @@ -497,11 +504,15 @@ static int newseg(struct ipc_namespace *
13187 if (ns->shm_tot + numpages > ns->shm_ctlall)
13190 + if (!vx_ipcshm_avail(current_vx_info(), numpages))
13193 shp = ipc_rcu_alloc(sizeof(*shp));
13197 shp->shm_perm.key = key;
13198 + shp->shm_perm.xid = vx_current_xid();
13199 shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13200 shp->mlock_user = NULL;
13202 @@ -570,6 +581,7 @@ static int newseg(struct ipc_namespace *
13204 ipc_unlock_object(&shp->shm_perm);
13206 + vx_ipcshm_add(current_vx_info(), key, numpages);
13210 diff -NurpP --minimal linux-3.13.6/kernel/Makefile linux-3.13.6-vs2.3.6.11/kernel/Makefile
13211 --- linux-3.13.6/kernel/Makefile 2014-01-22 20:39:12.000000000 +0000
13212 +++ linux-3.13.6-vs2.3.6.11/kernel/Makefile 2014-01-31 21:36:22.000000000 +0000
13213 @@ -25,6 +25,7 @@ obj-y += printk/
13219 obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13220 obj-$(CONFIG_FREEZER) += freezer.o
13221 diff -NurpP --minimal linux-3.13.6/kernel/auditsc.c linux-3.13.6-vs2.3.6.11/kernel/auditsc.c
13222 --- linux-3.13.6/kernel/auditsc.c 2014-01-22 20:39:12.000000000 +0000
13223 +++ linux-3.13.6-vs2.3.6.11/kernel/auditsc.c 2014-01-31 21:07:11.000000000 +0000
13224 @@ -1956,7 +1956,7 @@ static int audit_set_loginuid_perm(kuid_
13225 if (is_audit_feature_set(AUDIT_FEATURE_LOGINUID_IMMUTABLE))
13227 /* it is set, you need permission */
13228 - if (!capable(CAP_AUDIT_CONTROL))
13229 + if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13231 /* reject if this is not an unset and we don't allow that */
13232 if (is_audit_feature_set(AUDIT_FEATURE_ONLY_UNSET_LOGINUID) && uid_valid(loginuid))
13233 diff -NurpP --minimal linux-3.13.6/kernel/capability.c linux-3.13.6-vs2.3.6.11/kernel/capability.c
13234 --- linux-3.13.6/kernel/capability.c 2013-11-25 15:47:03.000000000 +0000
13235 +++ linux-3.13.6-vs2.3.6.11/kernel/capability.c 2014-01-31 20:38:03.000000000 +0000
13237 #include <linux/syscalls.h>
13238 #include <linux/pid_namespace.h>
13239 #include <linux/user_namespace.h>
13240 +#include <linux/vs_context.h>
13241 #include <asm/uaccess.h>
13244 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13250 * The only thing that can change the capabilities of the current
13251 * process is the current process. As such, we can't be in this code
13252 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13256 +#include <linux/vserver/base.h>
13259 * has_capability_noaudit - Does a task have a capability (unaudited) in the
13261 diff -NurpP --minimal linux-3.13.6/kernel/compat.c linux-3.13.6-vs2.3.6.11/kernel/compat.c
13262 --- linux-3.13.6/kernel/compat.c 2013-07-14 17:01:34.000000000 +0000
13263 +++ linux-3.13.6-vs2.3.6.11/kernel/compat.c 2014-01-31 20:38:03.000000000 +0000
13265 #include <linux/times.h>
13266 #include <linux/ptrace.h>
13267 #include <linux/gfp.h>
13268 +#include <linux/vs_time.h>
13270 #include <asm/uaccess.h>
13272 @@ -1040,7 +1041,7 @@ asmlinkage long compat_sys_stime(compat_
13276 - do_settimeofday(&tv);
13277 + vx_settimeofday(&tv);
13281 diff -NurpP --minimal linux-3.13.6/kernel/cred.c linux-3.13.6-vs2.3.6.11/kernel/cred.c
13282 --- linux-3.13.6/kernel/cred.c 2013-02-19 13:58:56.000000000 +0000
13283 +++ linux-3.13.6-vs2.3.6.11/kernel/cred.c 2014-01-31 20:38:03.000000000 +0000
13284 @@ -56,31 +56,6 @@ struct cred init_cred = {
13285 .group_info = &init_groups,
13288 -static inline void set_cred_subscribers(struct cred *cred, int n)
13290 -#ifdef CONFIG_DEBUG_CREDENTIALS
13291 - atomic_set(&cred->subscribers, n);
13295 -static inline int read_cred_subscribers(const struct cred *cred)
13297 -#ifdef CONFIG_DEBUG_CREDENTIALS
13298 - return atomic_read(&cred->subscribers);
13304 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
13306 -#ifdef CONFIG_DEBUG_CREDENTIALS
13307 - struct cred *cred = (struct cred *) _cred;
13309 - atomic_add(n, &cred->subscribers);
13314 * The RCU callback to actually dispose of a set of credentials
13316 @@ -232,21 +207,16 @@ error:
13318 * Call commit_creds() or abort_creds() to clean up.
13320 -struct cred *prepare_creds(void)
13321 +struct cred *__prepare_creds(const struct cred *old)
13323 - struct task_struct *task = current;
13324 - const struct cred *old;
13327 - validate_process_creds();
13329 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13333 kdebug("prepare_creds() alloc %p", new);
13335 - old = task->cred;
13336 memcpy(new, old, sizeof(struct cred));
13338 atomic_set(&new->usage, 1);
13339 @@ -275,6 +245,13 @@ error:
13344 +struct cred *prepare_creds(void)
13346 + validate_process_creds();
13348 + return __prepare_creds(current->cred);
13350 EXPORT_SYMBOL(prepare_creds);
13353 diff -NurpP --minimal linux-3.13.6/kernel/exit.c linux-3.13.6-vs2.3.6.11/kernel/exit.c
13354 --- linux-3.13.6/kernel/exit.c 2013-11-25 15:45:07.000000000 +0000
13355 +++ linux-3.13.6-vs2.3.6.11/kernel/exit.c 2014-01-31 20:38:03.000000000 +0000
13357 #include <linux/fs_struct.h>
13358 #include <linux/init_task.h>
13359 #include <linux/perf_event.h>
13360 +#include <linux/vs_limit.h>
13361 +#include <linux/vs_context.h>
13362 +#include <linux/vs_network.h>
13363 +#include <linux/vs_pid.h>
13364 #include <trace/events/sched.h>
13365 #include <linux/hw_breakpoint.h>
13366 #include <linux/oom.h>
13367 @@ -503,15 +507,25 @@ static struct task_struct *find_new_reap
13368 __acquires(&tasklist_lock)
13370 struct pid_namespace *pid_ns = task_active_pid_ns(father);
13371 - struct task_struct *thread;
13372 + struct vx_info *vxi = task_get_vx_info(father);
13373 + struct task_struct *thread = father;
13374 + struct task_struct *reaper;
13377 while_each_thread(father, thread) {
13378 if (thread->flags & PF_EXITING)
13380 if (unlikely(pid_ns->child_reaper == father))
13381 pid_ns->child_reaper = thread;
13387 + reaper = pid_ns->child_reaper;
13389 + BUG_ON(!vxi->vx_reaper);
13390 + if (vxi->vx_reaper != init_pid_ns.child_reaper &&
13391 + vxi->vx_reaper != father)
13392 + reaper = vxi->vx_reaper;
13395 if (unlikely(pid_ns->child_reaper == father)) {
13396 @@ -549,7 +563,9 @@ static struct task_struct *find_new_reap
13400 - return pid_ns->child_reaper;
13402 + put_vx_info(vxi);
13407 @@ -600,10 +616,15 @@ static void forget_original_parent(struc
13408 list_for_each_entry_safe(p, n, &father->children, sibling) {
13409 struct task_struct *t = p;
13411 - t->real_parent = reaper;
13412 + struct task_struct *new_parent = reaper;
13414 + if (unlikely(p == reaper))
13415 + new_parent = task_active_pid_ns(p)->child_reaper;
13417 + t->real_parent = new_parent;
13418 if (t->parent == father) {
13420 - t->parent = t->real_parent;
13421 + t->parent = new_parent;
13423 if (t->pdeath_signal)
13424 group_send_sig_info(t->pdeath_signal,
13425 @@ -810,6 +831,9 @@ void do_exit(long code)
13427 flush_ptrace_hw_breakpoint(tsk);
13429 + /* needs to stay before exit_notify() */
13430 + exit_vx_info_early(tsk, code);
13432 exit_notify(tsk, group_dead);
13435 @@ -863,10 +887,15 @@ void do_exit(long code)
13437 raw_spin_unlock_wait(&tsk->pi_lock);
13439 + /* needs to stay after exit_notify() */
13440 + exit_vx_info(tsk, code);
13441 + exit_nx_info(tsk);
13443 /* causes final put_task_struct in finish_task_switch(). */
13444 tsk->state = TASK_DEAD;
13445 tsk->flags |= PF_NOFREEZE; /* tell freezer to ignore us */
13447 + printk("bad task: %p [%lx]\n", current, current->state);
13449 /* Avoid "noreturn function does return". */
13451 diff -NurpP --minimal linux-3.13.6/kernel/fork.c linux-3.13.6-vs2.3.6.11/kernel/fork.c
13452 --- linux-3.13.6/kernel/fork.c 2014-01-22 20:39:13.000000000 +0000
13453 +++ linux-3.13.6-vs2.3.6.11/kernel/fork.c 2014-01-31 20:38:03.000000000 +0000
13455 #include <linux/signalfd.h>
13456 #include <linux/uprobes.h>
13457 #include <linux/aio.h>
13458 +#include <linux/vs_context.h>
13459 +#include <linux/vs_network.h>
13460 +#include <linux/vs_limit.h>
13462 #include <asm/pgtable.h>
13463 #include <asm/pgalloc.h>
13464 @@ -211,6 +214,8 @@ void free_task(struct task_struct *tsk)
13465 arch_release_thread_info(tsk->stack);
13466 free_thread_info(tsk->stack);
13467 rt_mutex_debug_task_free(tsk);
13468 + clr_vx_info(&tsk->vx_info);
13469 + clr_nx_info(&tsk->nx_info);
13470 ftrace_graph_exit_task(tsk);
13471 put_seccomp_filter(tsk);
13472 arch_release_task_struct(tsk);
13473 @@ -542,6 +547,7 @@ static struct mm_struct *mm_init(struct
13474 if (likely(!mm_alloc_pgd(mm))) {
13476 mmu_notifier_mm_init(mm);
13477 + set_vx_info(&mm->mm_vx_info, p->vx_info);
13481 @@ -594,6 +600,7 @@ void __mmdrop(struct mm_struct *mm)
13482 destroy_context(mm);
13483 mmu_notifier_mm_destroy(mm);
13485 + clr_vx_info(&mm->mm_vx_info);
13488 EXPORT_SYMBOL_GPL(__mmdrop);
13489 @@ -813,6 +820,7 @@ struct mm_struct *dup_mm(struct task_str
13492 memcpy(mm, oldmm, sizeof(*mm));
13493 + mm->mm_vx_info = NULL;
13494 mm_init_cpumask(mm);
13496 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
13497 @@ -851,6 +859,7 @@ fail_nocontext:
13498 * If init_new_context() failed, we cannot use mmput() to free the mm
13499 * because it calls destroy_context()
13501 + clr_vx_info(&mm->mm_vx_info);
13505 @@ -1135,6 +1144,8 @@ static struct task_struct *copy_process(
13508 struct task_struct *p;
13509 + struct vx_info *vxi;
13510 + struct nx_info *nxi;
13512 if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
13513 return ERR_PTR(-EINVAL);
13514 @@ -1197,7 +1208,12 @@ static struct task_struct *copy_process(
13515 DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
13516 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
13518 + init_vx_info(&p->vx_info, current_vx_info());
13519 + init_nx_info(&p->nx_info, current_nx_info());
13522 + if (!vx_nproc_avail(1))
13523 + goto bad_fork_free;
13524 if (atomic_read(&p->real_cred->user->processes) >=
13525 task_rlimit(p, RLIMIT_NPROC)) {
13526 if (p->real_cred->user != INIT_USER &&
13527 @@ -1479,6 +1495,18 @@ static struct task_struct *copy_process(
13530 spin_unlock(¤t->sighand->siglock);
13532 + /* p is copy of current */
13533 + vxi = p->vx_info;
13535 + claim_vx_info(vxi, p);
13536 + atomic_inc(&vxi->cvirt.nr_threads);
13537 + atomic_inc(&vxi->cvirt.total_forks);
13540 + nxi = p->nx_info;
13542 + claim_nx_info(nxi, p);
13543 write_unlock_irq(&tasklist_lock);
13544 proc_fork_connector(p);
13545 cgroup_post_fork(p);
13546 diff -NurpP --minimal linux-3.13.6/kernel/kthread.c linux-3.13.6-vs2.3.6.11/kernel/kthread.c
13547 --- linux-3.13.6/kernel/kthread.c 2014-01-22 20:39:13.000000000 +0000
13548 +++ linux-3.13.6-vs2.3.6.11/kernel/kthread.c 2014-01-31 20:38:03.000000000 +0000
13550 #include <linux/freezer.h>
13551 #include <linux/ptrace.h>
13552 #include <linux/uaccess.h>
13553 +#include <linux/vs_pid.h>
13554 #include <trace/events/sched.h>
13556 static DEFINE_SPINLOCK(kthread_create_lock);
13557 diff -NurpP --minimal linux-3.13.6/kernel/nsproxy.c linux-3.13.6-vs2.3.6.11/kernel/nsproxy.c
13558 --- linux-3.13.6/kernel/nsproxy.c 2013-11-25 15:47:03.000000000 +0000
13559 +++ linux-3.13.6-vs2.3.6.11/kernel/nsproxy.c 2014-02-01 00:17:43.000000000 +0000
13560 @@ -20,11 +20,14 @@
13561 #include <linux/mnt_namespace.h>
13562 #include <linux/utsname.h>
13563 #include <linux/pid_namespace.h>
13564 +#include <linux/vserver/global.h>
13565 +#include <linux/vserver/debug.h>
13566 #include <net/net_namespace.h>
13567 #include <linux/ipc_namespace.h>
13568 #include <linux/proc_ns.h>
13569 #include <linux/file.h>
13570 #include <linux/syscalls.h>
13571 +#include "../fs/mount.h"
13573 static struct kmem_cache *nsproxy_cachep;
13575 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
13576 struct nsproxy *nsproxy;
13578 nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
13581 atomic_set(&nsproxy->count, 1);
13582 + atomic_inc(&vs_global_nsproxy);
13584 + vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
13588 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
13589 * Return the newly created nsproxy. Do not attach this to the task,
13590 * leave it to the caller to do proper locking and attach it to task.
13592 -static struct nsproxy *create_new_namespaces(unsigned long flags,
13593 - struct task_struct *tsk, struct user_namespace *user_ns,
13594 - struct fs_struct *new_fs)
13595 +static struct nsproxy *unshare_namespaces(
13596 + unsigned long flags,
13597 + struct nsproxy *orig,
13598 + struct fs_struct *new_fs,
13599 + struct user_namespace *new_user,
13600 + struct pid_namespace *new_pid)
13602 struct nsproxy *new_nsp;
13604 @@ -67,32 +76,31 @@ static struct nsproxy *create_new_namesp
13606 return ERR_PTR(-ENOMEM);
13608 - new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
13609 + new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
13610 if (IS_ERR(new_nsp->mnt_ns)) {
13611 err = PTR_ERR(new_nsp->mnt_ns);
13615 - new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
13616 + new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
13617 if (IS_ERR(new_nsp->uts_ns)) {
13618 err = PTR_ERR(new_nsp->uts_ns);
13622 - new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
13623 + new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
13624 if (IS_ERR(new_nsp->ipc_ns)) {
13625 err = PTR_ERR(new_nsp->ipc_ns);
13629 - new_nsp->pid_ns_for_children =
13630 - copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children);
13631 + new_nsp->pid_ns_for_children = copy_pid_ns(flags, new_user, new_pid);
13632 if (IS_ERR(new_nsp->pid_ns_for_children)) {
13633 err = PTR_ERR(new_nsp->pid_ns_for_children);
13637 - new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
13638 + new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
13639 if (IS_ERR(new_nsp->net_ns)) {
13640 err = PTR_ERR(new_nsp->net_ns);
13642 @@ -117,6 +125,41 @@ out_ns:
13643 return ERR_PTR(err);
13646 +static struct nsproxy *create_new_namespaces(unsigned long flags,
13647 + struct task_struct *tsk, struct user_namespace *user_ns,
13648 + struct fs_struct *new_fs)
13651 + return unshare_namespaces(flags, tsk->nsproxy,
13652 + new_fs, user_ns, task_active_pid_ns(tsk));
13656 + * copies the nsproxy, setting refcount to 1, and grabbing a
13657 + * reference to all contained namespaces.
13659 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
13661 + struct nsproxy *ns = create_nsproxy();
13664 + memcpy(ns, orig, sizeof(struct nsproxy));
13665 + atomic_set(&ns->count, 1);
13668 + get_mnt_ns(ns->mnt_ns);
13670 + get_uts_ns(ns->uts_ns);
13672 + get_ipc_ns(ns->ipc_ns);
13673 + if (ns->pid_ns_for_children)
13674 + get_pid_ns(ns->pid_ns_for_children);
13676 + get_net(ns->net_ns);
13682 * called from clone. This now handles copy for nsproxy and all
13683 * namespaces therein.
13684 @@ -125,7 +168,10 @@ int copy_namespaces(unsigned long flags,
13686 struct nsproxy *old_ns = tsk->nsproxy;
13687 struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
13688 - struct nsproxy *new_ns;
13689 + struct nsproxy *new_ns = NULL;
13691 + vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
13692 + flags, tsk, old_ns);
13694 if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13695 CLONE_NEWPID | CLONE_NEWNET)))) {
13696 @@ -133,7 +179,7 @@ int copy_namespaces(unsigned long flags,
13700 - if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13701 + if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags))
13705 @@ -152,6 +198,9 @@ int copy_namespaces(unsigned long flags,
13706 return PTR_ERR(new_ns);
13708 tsk->nsproxy = new_ns;
13709 + vxdprintk(VXD_CBIT(space, 3),
13710 + "copy_namespaces(0x%08lx,%p[%p]) = [%p]",
13711 + flags, tsk, old_ns, new_ns);
13715 @@ -165,7 +214,9 @@ void free_nsproxy(struct nsproxy *ns)
13716 put_ipc_ns(ns->ipc_ns);
13717 if (ns->pid_ns_for_children)
13718 put_pid_ns(ns->pid_ns_for_children);
13719 - put_net(ns->net_ns);
13721 + put_net(ns->net_ns);
13722 + atomic_dec(&vs_global_nsproxy);
13723 kmem_cache_free(nsproxy_cachep, ns);
13726 @@ -179,12 +230,16 @@ int unshare_nsproxy_namespaces(unsigned
13727 struct user_namespace *user_ns;
13730 + vxdprintk(VXD_CBIT(space, 4),
13731 + "unshare_nsproxy_namespaces(0x%08lx,[%p])",
13732 + unshare_flags, current->nsproxy);
13734 if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13735 CLONE_NEWNET | CLONE_NEWPID)))
13738 user_ns = new_cred ? new_cred->user_ns : current_user_ns();
13739 - if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13740 + if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
13743 *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
13744 diff -NurpP --minimal linux-3.13.6/kernel/pid.c linux-3.13.6-vs2.3.6.11/kernel/pid.c
13745 --- linux-3.13.6/kernel/pid.c 2013-11-25 15:47:03.000000000 +0000
13746 +++ linux-3.13.6-vs2.3.6.11/kernel/pid.c 2014-01-31 20:38:03.000000000 +0000
13748 #include <linux/syscalls.h>
13749 #include <linux/proc_ns.h>
13750 #include <linux/proc_fs.h>
13751 +#include <linux/vs_pid.h>
13753 #define pid_hashfn(nr, ns) \
13754 hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
13755 @@ -373,7 +374,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
13757 struct pid *find_vpid(int nr)
13759 - return find_pid_ns(nr, task_active_pid_ns(current));
13760 + return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
13762 EXPORT_SYMBOL_GPL(find_vpid);
13764 @@ -429,6 +430,9 @@ void transfer_pid(struct task_struct *ol
13765 struct task_struct *pid_task(struct pid *pid, enum pid_type type)
13767 struct task_struct *result = NULL;
13769 + if (type == PIDTYPE_REALPID)
13770 + type = PIDTYPE_PID;
13772 struct hlist_node *first;
13773 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
13774 @@ -448,7 +452,7 @@ struct task_struct *find_task_by_pid_ns(
13775 rcu_lockdep_assert(rcu_read_lock_held(),
13776 "find_task_by_pid_ns() needs rcu_read_lock()"
13778 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
13779 + return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
13782 struct task_struct *find_task_by_vpid(pid_t vnr)
13783 @@ -492,7 +496,7 @@ struct pid *find_get_pid(pid_t nr)
13785 EXPORT_SYMBOL_GPL(find_get_pid);
13787 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13788 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
13792 @@ -506,6 +510,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
13794 EXPORT_SYMBOL_GPL(pid_nr_ns);
13796 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13798 + return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
13801 pid_t pid_vnr(struct pid *pid)
13803 return pid_nr_ns(pid, task_active_pid_ns(current));
13804 diff -NurpP --minimal linux-3.13.6/kernel/pid_namespace.c linux-3.13.6-vs2.3.6.11/kernel/pid_namespace.c
13805 --- linux-3.13.6/kernel/pid_namespace.c 2014-01-22 20:39:13.000000000 +0000
13806 +++ linux-3.13.6-vs2.3.6.11/kernel/pid_namespace.c 2014-02-01 12:23:11.000000000 +0000
13808 #include <linux/proc_ns.h>
13809 #include <linux/reboot.h>
13810 #include <linux/export.h>
13811 +#include <linux/vserver/global.h>
13815 @@ -110,6 +111,7 @@ static struct pid_namespace *create_pid_
13818 kref_init(&ns->kref);
13819 + atomic_inc(&vs_global_pid_ns);
13821 ns->parent = get_pid_ns(parent_pid_ns);
13822 ns->user_ns = get_user_ns(user_ns);
13823 @@ -127,6 +129,7 @@ static struct pid_namespace *create_pid_
13825 kfree(ns->pidmap[0].page);
13827 + atomic_dec(&vs_global_pid_ns);
13828 kmem_cache_free(pid_ns_cachep, ns);
13830 return ERR_PTR(err);
13831 diff -NurpP --minimal linux-3.13.6/kernel/posix-timers.c linux-3.13.6-vs2.3.6.11/kernel/posix-timers.c
13832 --- linux-3.13.6/kernel/posix-timers.c 2013-07-14 17:01:35.000000000 +0000
13833 +++ linux-3.13.6-vs2.3.6.11/kernel/posix-timers.c 2014-01-31 20:38:03.000000000 +0000
13835 #include <linux/workqueue.h>
13836 #include <linux/export.h>
13837 #include <linux/hashtable.h>
13838 +#include <linux/vs_context.h>
13841 * Management arrays for POSIX timers. Timers are now kept in static hash table
13842 @@ -398,6 +399,7 @@ int posix_timer_event(struct k_itimer *t
13844 struct task_struct *task;
13845 int shared, ret = -1;
13848 * FIXME: if ->sigq is queued we can race with
13849 * dequeue_signal()->do_schedule_next_timer().
13850 @@ -414,10 +416,18 @@ int posix_timer_event(struct k_itimer *t
13852 task = pid_task(timr->it_pid, PIDTYPE_PID);
13854 + struct vx_info_save vxis;
13855 + struct vx_info *vxi;
13857 + vxi = get_vx_info(task->vx_info);
13858 + enter_vx_info(vxi, &vxis);
13859 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
13860 ret = send_sigqueue(timr->sigq, task, shared);
13861 + leave_vx_info(&vxis);
13862 + put_vx_info(vxi);
13866 /* If we failed to send the signal the timer stops. */
13869 diff -NurpP --minimal linux-3.13.6/kernel/printk/printk.c linux-3.13.6-vs2.3.6.11/kernel/printk/printk.c
13870 --- linux-3.13.6/kernel/printk/printk.c 2014-01-22 20:39:13.000000000 +0000
13871 +++ linux-3.13.6-vs2.3.6.11/kernel/printk/printk.c 2014-02-01 01:59:45.000000000 +0000
13873 #include <linux/poll.h>
13874 #include <linux/irq_work.h>
13875 #include <linux/utsname.h>
13876 +#include <linux/vs_cvirt.h>
13878 #include <asm/uaccess.h>
13880 @@ -386,7 +387,7 @@ static int check_syslog_permissions(int
13883 if (syslog_action_restricted(type)) {
13884 - if (capable(CAP_SYSLOG))
13885 + if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
13888 * For historical reasons, accept CAP_SYS_ADMIN too, with
13889 @@ -1135,12 +1136,9 @@ int do_syslog(int type, char __user *buf
13894 - case SYSLOG_ACTION_CLOSE: /* Close log */
13896 - case SYSLOG_ACTION_OPEN: /* Open log */
13898 - case SYSLOG_ACTION_READ: /* Read from log */
13899 + if ((type == SYSLOG_ACTION_READ) ||
13900 + (type == SYSLOG_ACTION_READ_ALL) ||
13901 + (type == SYSLOG_ACTION_READ_CLEAR)) {
13903 if (!buf || len < 0)
13905 @@ -1151,6 +1149,16 @@ int do_syslog(int type, char __user *buf
13910 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
13911 + return vx_do_syslog(type, buf, len);
13914 + case SYSLOG_ACTION_CLOSE: /* Close log */
13916 + case SYSLOG_ACTION_OPEN: /* Open log */
13918 + case SYSLOG_ACTION_READ: /* Read from log */
13919 error = wait_event_interruptible(log_wait,
13920 syslog_seq != log_next_seq);
13922 @@ -1163,16 +1171,6 @@ int do_syslog(int type, char __user *buf
13924 /* Read last kernel messages */
13925 case SYSLOG_ACTION_READ_ALL:
13927 - if (!buf || len < 0)
13932 - if (!access_ok(VERIFY_WRITE, buf, len)) {
13936 error = syslog_print_all(buf, len, clear);
13938 /* Clear ring buffer */
13939 diff -NurpP --minimal linux-3.13.6/kernel/ptrace.c linux-3.13.6-vs2.3.6.11/kernel/ptrace.c
13940 --- linux-3.13.6/kernel/ptrace.c 2014-01-22 20:39:13.000000000 +0000
13941 +++ linux-3.13.6-vs2.3.6.11/kernel/ptrace.c 2014-01-31 20:38:03.000000000 +0000
13943 #include <linux/syscalls.h>
13944 #include <linux/uaccess.h>
13945 #include <linux/regset.h>
13946 +#include <linux/vs_context.h>
13947 #include <linux/hw_breakpoint.h>
13948 #include <linux/cn_proc.h>
13949 #include <linux/compat.h>
13950 @@ -264,6 +265,11 @@ ok:
13954 + if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
13956 + if (!vx_check(task->xid, VS_IDENT) &&
13957 + !task_vx_flags(task, VXF_STATE_ADMIN, 0))
13959 return security_ptrace_access_check(task, mode);
13962 diff -NurpP --minimal linux-3.13.6/kernel/reboot.c linux-3.13.6-vs2.3.6.11/kernel/reboot.c
13963 --- linux-3.13.6/kernel/reboot.c 2014-01-22 20:39:13.000000000 +0000
13964 +++ linux-3.13.6-vs2.3.6.11/kernel/reboot.c 2014-02-01 00:19:40.000000000 +0000
13966 #include <linux/syscalls.h>
13967 #include <linux/syscore_ops.h>
13968 #include <linux/uaccess.h>
13969 +#include <linux/vs_pid.h>
13972 * this indicates whether you can reboot with ctrl-alt-del: the default is yes
13973 @@ -188,6 +189,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
13975 static DEFINE_MUTEX(reboot_mutex);
13977 +long vs_reboot(unsigned int, void __user *);
13980 * Reboot system call: for obvious reasons only root may call it,
13981 * and even root needs to set up some magic numbers in the registers
13982 @@ -230,6 +233,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
13983 if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
13984 cmd = LINUX_REBOOT_CMD_HALT;
13986 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
13987 + return vs_reboot(cmd, arg);
13989 mutex_lock(&reboot_mutex);
13991 case LINUX_REBOOT_CMD_RESTART:
13992 diff -NurpP --minimal linux-3.13.6/kernel/sched/core.c linux-3.13.6-vs2.3.6.11/kernel/sched/core.c
13993 --- linux-3.13.6/kernel/sched/core.c 2014-03-12 13:51:24.000000000 +0000
13994 +++ linux-3.13.6-vs2.3.6.11/kernel/sched/core.c 2014-02-25 11:26:10.000000000 +0000
13996 #include <linux/init_task.h>
13997 #include <linux/binfmts.h>
13998 #include <linux/context_tracking.h>
13999 +#include <linux/vs_sched.h>
14000 +#include <linux/vs_cvirt.h>
14002 #include <asm/switch_to.h>
14003 #include <asm/tlb.h>
14004 @@ -2927,7 +2929,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14007 if (increment < 0 && !can_nice(current, nice))
14009 + return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14011 retval = security_task_setnice(current, nice);
14013 diff -NurpP --minimal linux-3.13.6/kernel/sched/cputime.c linux-3.13.6-vs2.3.6.11/kernel/sched/cputime.c
14014 --- linux-3.13.6/kernel/sched/cputime.c 2013-11-25 15:47:03.000000000 +0000
14015 +++ linux-3.13.6-vs2.3.6.11/kernel/sched/cputime.c 2014-01-31 20:38:03.000000000 +0000
14017 #include <linux/kernel_stat.h>
14018 #include <linux/static_key.h>
14019 #include <linux/context_tracking.h>
14020 +#include <linux/vs_sched.h>
14024 @@ -135,14 +136,17 @@ static inline void task_group_account_fi
14025 void account_user_time(struct task_struct *p, cputime_t cputime,
14026 cputime_t cputime_scaled)
14028 + struct vx_info *vxi = p->vx_info; /* p is _always_ current */
14029 + int nice = (TASK_NICE(p) > 0);
14032 /* Add user time to process. */
14033 p->utime += cputime;
14034 p->utimescaled += cputime_scaled;
14035 + vx_account_user(vxi, cputime, nice);
14036 account_group_user_time(p, cputime);
14038 - index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14039 + index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14041 /* Add user time to cpustat. */
14042 task_group_account_field(p, index, (__force u64) cputime);
14043 @@ -189,9 +193,12 @@ static inline
14044 void __account_system_time(struct task_struct *p, cputime_t cputime,
14045 cputime_t cputime_scaled, int index)
14047 + struct vx_info *vxi = p->vx_info; /* p is _always_ current */
14049 /* Add system time to process. */
14050 p->stime += cputime;
14051 p->stimescaled += cputime_scaled;
14052 + vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14053 account_group_system_time(p, cputime);
14055 /* Add system time to cpustat. */
14056 diff -NurpP --minimal linux-3.13.6/kernel/sched/fair.c linux-3.13.6-vs2.3.6.11/kernel/sched/fair.c
14057 --- linux-3.13.6/kernel/sched/fair.c 2014-01-22 20:39:13.000000000 +0000
14058 +++ linux-3.13.6-vs2.3.6.11/kernel/sched/fair.c 2014-01-31 20:38:03.000000000 +0000
14060 #include <linux/mempolicy.h>
14061 #include <linux/migrate.h>
14062 #include <linux/task_work.h>
14063 +#include <linux/vs_cvirt.h>
14065 #include <trace/events/sched.h>
14067 @@ -2577,6 +2578,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14068 __enqueue_entity(cfs_rq, se);
14071 + if (entity_is_task(se))
14072 + vx_activate_task(task_of(se));
14073 if (cfs_rq->nr_running == 1) {
14074 list_add_leaf_cfs_rq(cfs_rq);
14075 check_enqueue_throttle(cfs_rq);
14076 @@ -2658,6 +2661,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14077 if (se != cfs_rq->curr)
14078 __dequeue_entity(cfs_rq, se);
14080 + if (entity_is_task(se))
14081 + vx_deactivate_task(task_of(se));
14082 account_entity_dequeue(cfs_rq, se);
14085 diff -NurpP --minimal linux-3.13.6/kernel/sched/proc.c linux-3.13.6-vs2.3.6.11/kernel/sched/proc.c
14086 --- linux-3.13.6/kernel/sched/proc.c 2013-11-25 15:45:08.000000000 +0000
14087 +++ linux-3.13.6-vs2.3.6.11/kernel/sched/proc.c 2014-01-31 21:22:36.000000000 +0000
14088 @@ -78,9 +78,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14090 void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14092 - loads[0] = (avenrun[0] + offset) << shift;
14093 - loads[1] = (avenrun[1] + offset) << shift;
14094 - loads[2] = (avenrun[2] + offset) << shift;
14095 + if (vx_flags(VXF_VIRT_LOAD, 0)) {
14096 + struct vx_info *vxi = current_vx_info();
14098 + loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14099 + loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14100 + loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14102 + loads[0] = (avenrun[0] + offset) << shift;
14103 + loads[1] = (avenrun[1] + offset) << shift;
14104 + loads[2] = (avenrun[2] + offset) << shift;
14108 long calc_load_fold_active(struct rq *this_rq)
14109 diff -NurpP --minimal linux-3.13.6/kernel/signal.c linux-3.13.6-vs2.3.6.11/kernel/signal.c
14110 --- linux-3.13.6/kernel/signal.c 2014-01-22 20:39:13.000000000 +0000
14111 +++ linux-3.13.6-vs2.3.6.11/kernel/signal.c 2014-01-31 20:38:03.000000000 +0000
14113 #include <linux/uprobes.h>
14114 #include <linux/compat.h>
14115 #include <linux/cn_proc.h>
14116 +#include <linux/vs_context.h>
14117 +#include <linux/vs_pid.h>
14118 #define CREATE_TRACE_POINTS
14119 #include <trace/events/signal.h>
14121 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14125 + vxdprintk(VXD_CBIT(misc, 7),
14126 + "check_kill_permission(%d,%p,%p[#%u,%u])",
14127 + sig, info, t, vx_task_xid(t), t->pid);
14129 if (!valid_signal(sig))
14132 +/* FIXME: needed? if so, why?
14133 + if ((info != SEND_SIG_NOINFO) &&
14134 + (is_si_special(info) || !si_fromuser(info)))
14137 if (!si_fromuser(info))
14140 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14145 + if (t->pid == 1 && current->xid)
14149 + /* FIXME: we shouldn't return ESRCH ever, to avoid
14150 + loops, maybe ENOENT or EACCES? */
14151 + if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14152 + vxdprintk(current->xid || VXD_CBIT(misc, 7),
14153 + "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14154 + sig, info, t, vx_task_xid(t), t->pid, current->xid);
14158 return security_task_kill(t, info, sig, 0);
14161 @@ -1353,7 +1378,7 @@ int kill_pid_info(int sig, struct siginf
14164 p = pid_task(pid, PIDTYPE_PID);
14166 + if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14167 error = group_send_sig_info(sig, info, p);
14168 if (unlikely(error == -ESRCH))
14170 @@ -1401,7 +1426,7 @@ int kill_pid_info_as_cred(int sig, struc
14173 p = pid_task(pid, PIDTYPE_PID);
14175 + if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14179 @@ -1453,8 +1478,10 @@ static int kill_something_info(int sig,
14180 struct task_struct * p;
14182 for_each_process(p) {
14183 - if (task_pid_vnr(p) > 1 &&
14184 - !same_thread_group(p, current)) {
14185 + if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14186 + task_pid_vnr(p) > 1 &&
14187 + !same_thread_group(p, current) &&
14188 + !vx_current_initpid(p->pid)) {
14189 int err = group_send_sig_info(sig, info, p);
14192 @@ -2308,6 +2335,11 @@ relock:
14193 !sig_kernel_only(signr))
14196 + /* virtual init is protected against user signals */
14197 + if ((info->si_code == SI_USER) &&
14198 + vx_current_initpid(current->pid))
14201 if (sig_kernel_stop(signr)) {
14203 * The default action is to stop all threads in
14204 diff -NurpP --minimal linux-3.13.6/kernel/softirq.c linux-3.13.6-vs2.3.6.11/kernel/softirq.c
14205 --- linux-3.13.6/kernel/softirq.c 2014-01-22 20:39:13.000000000 +0000
14206 +++ linux-3.13.6-vs2.3.6.11/kernel/softirq.c 2014-01-31 20:38:03.000000000 +0000
14208 #include <linux/smp.h>
14209 #include <linux/smpboot.h>
14210 #include <linux/tick.h>
14211 +#include <linux/vs_context.h>
14213 #define CREATE_TRACE_POINTS
14214 #include <trace/events/irq.h>
14215 diff -NurpP --minimal linux-3.13.6/kernel/sys.c linux-3.13.6-vs2.3.6.11/kernel/sys.c
14216 --- linux-3.13.6/kernel/sys.c 2014-01-22 20:39:13.000000000 +0000
14217 +++ linux-3.13.6-vs2.3.6.11/kernel/sys.c 2014-02-01 00:19:29.000000000 +0000
14219 #include <linux/cred.h>
14221 #include <linux/kmsg_dump.h>
14222 +#include <linux/vs_pid.h>
14223 /* Move somewhere else to avoid recompiling? */
14224 #include <generated/utsrelease.h>
14226 @@ -145,7 +146,10 @@ static int set_one_prio(struct task_stru
14229 if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14231 + if (vx_flags(VXF_IGNEG_NICE, 0))
14237 no_nice = security_task_setnice(p, niceval);
14238 @@ -196,6 +200,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14240 pgrp = task_pgrp(current);
14241 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14242 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14244 error = set_one_prio(p, niceval, error);
14245 } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14247 @@ -261,6 +267,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14249 pgrp = task_pgrp(current);
14250 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14251 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14253 niceval = 20 - task_nice(p);
14254 if (niceval > retval)
14256 @@ -1198,7 +1206,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14258 char tmp[__NEW_UTS_LEN];
14260 - if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14261 + if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14262 + CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14265 if (len < 0 || len > __NEW_UTS_LEN)
14266 @@ -1249,7 +1258,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14268 char tmp[__NEW_UTS_LEN];
14270 - if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14271 + if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14272 + CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14274 if (len < 0 || len > __NEW_UTS_LEN)
14276 @@ -1368,7 +1378,7 @@ int do_prlimit(struct task_struct *tsk,
14277 /* Keep the capable check against init_user_ns until
14278 cgroups can contain all limits */
14279 if (new_rlim->rlim_max > rlim->rlim_max &&
14280 - !capable(CAP_SYS_RESOURCE))
14281 + !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14284 retval = security_task_setrlimit(tsk->group_leader,
14285 @@ -1421,7 +1431,8 @@ static int check_prlimit_permission(stru
14286 gid_eq(cred->gid, tcred->sgid) &&
14287 gid_eq(cred->gid, tcred->gid))
14289 - if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14290 + if (vx_ns_capable(tcred->user_ns,
14291 + CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14295 diff -NurpP --minimal linux-3.13.6/kernel/sysctl.c linux-3.13.6-vs2.3.6.11/kernel/sysctl.c
14296 --- linux-3.13.6/kernel/sysctl.c 2014-03-12 13:51:24.000000000 +0000
14297 +++ linux-3.13.6-vs2.3.6.11/kernel/sysctl.c 2014-02-25 11:26:10.000000000 +0000
14299 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14300 #include <linux/lockdep.h>
14302 +extern char vshelper_path[];
14303 #ifdef CONFIG_CHR_DEV_SG
14304 #include <scsi/sg.h>
14306 @@ -650,6 +651,13 @@ static struct ctl_table kern_table[] = {
14308 .proc_handler = proc_dostring,
14311 + .procname = "vshelper",
14312 + .data = &vshelper_path,
14315 + .proc_handler = &proc_dostring,
14318 #ifdef CONFIG_CHR_DEV_SG
14320 diff -NurpP --minimal linux-3.13.6/kernel/sysctl_binary.c linux-3.13.6-vs2.3.6.11/kernel/sysctl_binary.c
14321 --- linux-3.13.6/kernel/sysctl_binary.c 2014-01-22 20:39:13.000000000 +0000
14322 +++ linux-3.13.6-vs2.3.6.11/kernel/sysctl_binary.c 2014-01-31 20:38:03.000000000 +0000
14323 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
14325 { CTL_INT, KERN_PANIC, "panic" },
14326 { CTL_INT, KERN_REALROOTDEV, "real-root-dev" },
14327 + { CTL_STR, KERN_VSHELPER, "vshelper" },
14329 { CTL_STR, KERN_SPARC_REBOOT, "reboot-cmd" },
14330 { CTL_INT, KERN_CTLALTDEL, "ctrl-alt-del" },
14331 diff -NurpP --minimal linux-3.13.6/kernel/time/timekeeping.c linux-3.13.6-vs2.3.6.11/kernel/time/timekeeping.c
14332 --- linux-3.13.6/kernel/time/timekeeping.c 2014-03-12 13:51:24.000000000 +0000
14333 +++ linux-3.13.6-vs2.3.6.11/kernel/time/timekeeping.c 2014-02-25 11:26:10.000000000 +0000
14335 #include <linux/tick.h>
14336 #include <linux/stop_machine.h>
14337 #include <linux/pvclock_gtod.h>
14338 +#include <linux/vs_time.h>
14340 #include "tick-internal.h"
14341 #include "ntp_internal.h"
14342 @@ -709,6 +710,7 @@ void getrawmonotonic(struct timespec *ts
14343 } while (read_seqcount_retry(&timekeeper_seq, seq));
14345 timespec_add_ns(ts, nsecs);
14346 + vx_adjust_timespec(ts);
14348 EXPORT_SYMBOL(getrawmonotonic);
14350 diff -NurpP --minimal linux-3.13.6/kernel/time.c linux-3.13.6-vs2.3.6.11/kernel/time.c
14351 --- linux-3.13.6/kernel/time.c 2013-11-25 15:45:08.000000000 +0000
14352 +++ linux-3.13.6-vs2.3.6.11/kernel/time.c 2014-01-31 20:38:03.000000000 +0000
14354 #include <linux/fs.h>
14355 #include <linux/math64.h>
14356 #include <linux/ptrace.h>
14357 +#include <linux/vs_time.h>
14359 #include <asm/uaccess.h>
14360 #include <asm/unistd.h>
14361 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
14365 - do_settimeofday(&tv);
14366 + vx_settimeofday(&tv);
14370 @@ -181,7 +182,7 @@ int do_sys_settimeofday(const struct tim
14374 - return do_settimeofday(tv);
14375 + return vx_settimeofday(tv);
14379 diff -NurpP --minimal linux-3.13.6/kernel/timer.c linux-3.13.6-vs2.3.6.11/kernel/timer.c
14380 --- linux-3.13.6/kernel/timer.c 2014-01-22 20:39:13.000000000 +0000
14381 +++ linux-3.13.6-vs2.3.6.11/kernel/timer.c 2014-01-31 20:38:03.000000000 +0000
14383 #include <linux/sched/sysctl.h>
14384 #include <linux/slab.h>
14385 #include <linux/compat.h>
14386 +#include <linux/vs_base.h>
14387 +#include <linux/vs_cvirt.h>
14388 +#include <linux/vs_pid.h>
14389 +#include <linux/vserver/sched.h>
14391 #include <asm/uaccess.h>
14392 #include <asm/unistd.h>
14393 diff -NurpP --minimal linux-3.13.6/kernel/user_namespace.c linux-3.13.6-vs2.3.6.11/kernel/user_namespace.c
14394 --- linux-3.13.6/kernel/user_namespace.c 2014-01-22 20:39:13.000000000 +0000
14395 +++ linux-3.13.6-vs2.3.6.11/kernel/user_namespace.c 2014-01-31 20:38:03.000000000 +0000
14397 #include <linux/ctype.h>
14398 #include <linux/projid.h>
14399 #include <linux/fs_struct.h>
14400 +#include <linux/vserver/global.h>
14402 static struct kmem_cache *user_ns_cachep __read_mostly;
14404 @@ -94,6 +95,7 @@ int create_user_ns(struct cred *new)
14406 atomic_set(&ns->count, 1);
14407 /* Leave the new->user_ns reference with the new user namespace. */
14408 + atomic_inc(&vs_global_user_ns);
14409 ns->parent = parent_ns;
14410 ns->level = parent_ns->level + 1;
14412 @@ -848,6 +850,8 @@ static void *userns_get(struct task_stru
14414 static void userns_put(void *ns)
14416 + /* FIXME: maybe move into destroyer? */
14417 + atomic_dec(&vs_global_user_ns);
14421 diff -NurpP --minimal linux-3.13.6/kernel/utsname.c linux-3.13.6-vs2.3.6.11/kernel/utsname.c
14422 --- linux-3.13.6/kernel/utsname.c 2013-11-25 15:47:03.000000000 +0000
14423 +++ linux-3.13.6-vs2.3.6.11/kernel/utsname.c 2014-01-31 20:38:03.000000000 +0000
14424 @@ -16,14 +16,17 @@
14425 #include <linux/slab.h>
14426 #include <linux/user_namespace.h>
14427 #include <linux/proc_ns.h>
14428 +#include <linux/vserver/global.h>
14430 static struct uts_namespace *create_uts_ns(void)
14432 struct uts_namespace *uts_ns;
14434 uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
14437 kref_init(&uts_ns->kref);
14438 + atomic_inc(&vs_global_uts_ns);
14443 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
14444 ns = container_of(kref, struct uts_namespace, kref);
14445 put_user_ns(ns->user_ns);
14446 proc_free_inum(ns->proc_inum);
14447 + atomic_dec(&vs_global_uts_ns);
14451 diff -NurpP --minimal linux-3.13.6/kernel/vserver/Kconfig linux-3.13.6-vs2.3.6.11/kernel/vserver/Kconfig
14452 --- linux-3.13.6/kernel/vserver/Kconfig 1970-01-01 00:00:00.000000000 +0000
14453 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/Kconfig 2014-01-31 20:38:03.000000000 +0000
14456 +# Linux VServer configuration
14459 +menu "Linux VServer"
14461 +config VSERVER_AUTO_LBACK
14462 + bool "Automatically Assign Loopback IP"
14465 + Automatically assign a guest specific loopback
14466 + IP and add it to the kernel network stack on
14469 +config VSERVER_AUTO_SINGLE
14470 + bool "Automatic Single IP Special Casing"
14473 + This allows network contexts with a single IP to
14474 + automatically remap 0.0.0.0 bindings to that IP,
14475 + avoiding further network checks and improving
14478 + (note: such guests do not allow to change the ip
14479 + on the fly and do not show loopback addresses)
14481 +config VSERVER_COWBL
14482 + bool "Enable COW Immutable Link Breaking"
14485 + This enables the COW (Copy-On-Write) link break code.
14486 + It allows you to treat unified files like normal files
14487 + when writing to them (which will implicitely break the
14488 + link and create a copy of the unified file)
14490 +config VSERVER_VTIME
14491 + bool "Enable Virtualized Guest Time (EXPERIMENTAL)"
14494 + This enables per guest time offsets to allow for
14495 + adjusting the system clock individually per guest.
14496 + this adds some overhead to the time functions and
14497 + therefore should not be enabled without good reason.
14499 +config VSERVER_DEVICE
14500 + bool "Enable Guest Device Mapping (EXPERIMENTAL)"
14503 + This enables generic device remapping.
14505 +config VSERVER_PROC_SECURE
14506 + bool "Enable Proc Security"
14507 + depends on PROC_FS
14510 + This configures ProcFS security to initially hide
14511 + non-process entries for all contexts except the main and
14512 + spectator context (i.e. for all guests), which is a secure
14515 + (note: on 1.2x the entries were visible by default)
14518 + prompt "Persistent Inode Tagging"
14519 + default TAGGING_ID24
14521 + This adds persistent context information to filesystems
14522 + mounted with the tagxid option. Tagging is a requirement
14523 + for per-context disk limits and per-context quota.
14526 +config TAGGING_NONE
14529 + do not store per-context information in inodes.
14531 +config TAGGING_UID16
14532 + bool "UID16/GID32"
14534 + reduces UID to 16 bit, but leaves GID at 32 bit.
14536 +config TAGGING_GID16
14537 + bool "UID32/GID16"
14539 + reduces GID to 16 bit, but leaves UID at 32 bit.
14541 +config TAGGING_ID24
14542 + bool "UID24/GID24"
14544 + uses the upper 8bit from UID and GID for XID tagging
14545 + which leaves 24bit for UID/GID each, which should be
14546 + more than sufficient for normal use.
14548 +config TAGGING_INTERN
14549 + bool "UID32/GID32"
14551 + this uses otherwise reserved inode fields in the on
14552 + disk representation, which limits the use to a few
14553 + filesystems (currently ext2 and ext3)
14558 + bool "Tag NFSD User Auth and Files"
14561 + Enable this if you do want the in-kernel NFS
14562 + Server to use the tagging specified above.
14563 + (will require patched clients too)
14565 +config VSERVER_PRIVACY
14566 + bool "Honor Privacy Aspects of Guests"
14569 + When enabled, most context checks will disallow
14570 + access to structures assigned to a specific context,
14571 + like ptys or loop devices.
14573 +config VSERVER_CONTEXTS
14574 + int "Maximum number of Contexts (1-65533)" if EMBEDDED
14576 + default "768" if 64BIT
14579 + This setting will optimize certain data structures
14580 + and memory allocations according to the expected
14583 + note: this is not a strict upper limit.
14585 +config VSERVER_WARN
14586 + bool "VServer Warnings"
14589 + This enables various runtime warnings, which will
14590 + notify about potential manipulation attempts or
14591 + resource shortage. It is generally considered to
14592 + be a good idea to have that enabled.
14594 +config VSERVER_WARN_DEVPTS
14595 + bool "VServer DevPTS Warnings"
14596 + depends on VSERVER_WARN
14599 + This enables DevPTS related warnings, issued when a
14600 + process inside a context tries to lookup or access
14601 + a dynamic pts from the host or a different context.
14603 +config VSERVER_DEBUG
14604 + bool "VServer Debugging Code"
14607 + Set this to yes if you want to be able to activate
14608 + debugging output at runtime. It adds a very small
14609 + overhead to all vserver related functions and
14610 + increases the kernel size by about 20k.
14612 +config VSERVER_HISTORY
14613 + bool "VServer History Tracing"
14614 + depends on VSERVER_DEBUG
14617 + Set this to yes if you want to record the history of
14618 + linux-vserver activities, so they can be replayed in
14619 + the event of a kernel panic or oops.
14621 +config VSERVER_HISTORY_SIZE
14622 + int "Per-CPU History Size (32-65536)"
14623 + depends on VSERVER_HISTORY
14627 + This allows you to specify the number of entries in
14628 + the per-CPU history buffer.
14630 +config VSERVER_EXTRA_MNT_CHECK
14631 + bool "Extra Checks for Reachability"
14634 + Set this to yes if you want to do extra checks for
14635 + vfsmount reachability in the proc filesystem code.
14636 + This shouldn't be required on any setup utilizing
14640 + prompt "Quotes used in debug and warn messages"
14641 + default QUOTES_ISO8859
14643 +config QUOTES_ISO8859
14644 + bool "Extended ASCII (ISO 8859) angle quotes"
14646 + This uses the extended ASCII characters \xbb
14647 + and \xab for quoting file and process names.
14649 +config QUOTES_UTF8
14650 + bool "UTF-8 angle quotes"
14652 + This uses the the UTF-8 sequences for angle
14653 + quotes to quote file and process names.
14655 +config QUOTES_ASCII
14656 + bool "ASCII single quotes"
14658 + This uses the ASCII single quote character
14659 + (\x27) to quote file and process names.
14669 + select NAMESPACES
14675 +config VSERVER_SECURITY
14677 + depends on SECURITY
14679 + select SECURITY_CAPABILITIES
14681 +config VSERVER_DISABLED
14685 diff -NurpP --minimal linux-3.13.6/kernel/vserver/Makefile linux-3.13.6-vs2.3.6.11/kernel/vserver/Makefile
14686 --- linux-3.13.6/kernel/vserver/Makefile 1970-01-01 00:00:00.000000000 +0000
14687 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/Makefile 2014-01-31 20:38:03.000000000 +0000
14690 +# Makefile for the Linux vserver routines.
14694 +obj-y += vserver.o
14696 +vserver-y := switch.o context.o space.o sched.o network.o inode.o \
14697 + limit.o cvirt.o cacct.o signal.o helper.o init.o \
14700 +vserver-$(CONFIG_INET) += inet.o
14701 +vserver-$(CONFIG_PROC_FS) += proc.o
14702 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
14703 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
14704 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
14705 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
14707 diff -NurpP --minimal linux-3.13.6/kernel/vserver/cacct.c linux-3.13.6-vs2.3.6.11/kernel/vserver/cacct.c
14708 --- linux-3.13.6/kernel/vserver/cacct.c 1970-01-01 00:00:00.000000000 +0000
14709 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/cacct.c 2014-01-31 20:38:03.000000000 +0000
14712 + * linux/kernel/vserver/cacct.c
14714 + * Virtual Server: Context Accounting
14716 + * Copyright (C) 2006-2007 Herbert Pötzl
14718 + * V0.01 added accounting stats
14722 +#include <linux/types.h>
14723 +#include <linux/vs_context.h>
14724 +#include <linux/vserver/cacct_cmd.h>
14725 +#include <linux/vserver/cacct_int.h>
14727 +#include <asm/errno.h>
14728 +#include <asm/uaccess.h>
14731 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
14733 + struct vcmd_sock_stat_v0 vc_data;
14736 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
14739 + field = vc_data.field;
14740 + if ((field < 0) || (field >= VXA_SOCK_SIZE))
14743 + for (j = 0; j < 3; j++) {
14744 + vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
14745 + vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
14748 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
14753 diff -NurpP --minimal linux-3.13.6/kernel/vserver/cacct_init.h linux-3.13.6-vs2.3.6.11/kernel/vserver/cacct_init.h
14754 --- linux-3.13.6/kernel/vserver/cacct_init.h 1970-01-01 00:00:00.000000000 +0000
14755 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/cacct_init.h 2014-01-31 20:38:03.000000000 +0000
14759 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
14764 + for (i = 0; i < VXA_SOCK_SIZE; i++) {
14765 + for (j = 0; j < 3; j++) {
14766 + atomic_long_set(&cacct->sock[i][j].count, 0);
14767 + atomic_long_set(&cacct->sock[i][j].total, 0);
14770 + for (i = 0; i < 8; i++)
14771 + atomic_set(&cacct->slab[i], 0);
14772 + for (i = 0; i < 5; i++)
14773 + for (j = 0; j < 4; j++)
14774 + atomic_set(&cacct->page[i][j], 0);
14777 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
14782 diff -NurpP --minimal linux-3.13.6/kernel/vserver/cacct_proc.h linux-3.13.6-vs2.3.6.11/kernel/vserver/cacct_proc.h
14783 --- linux-3.13.6/kernel/vserver/cacct_proc.h 1970-01-01 00:00:00.000000000 +0000
14784 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/cacct_proc.h 2014-01-31 20:38:03.000000000 +0000
14786 +#ifndef _VX_CACCT_PROC_H
14787 +#define _VX_CACCT_PROC_H
14789 +#include <linux/vserver/cacct_int.h>
14792 +#define VX_SOCKA_TOP \
14793 + "Type\t recv #/bytes\t\t send #/bytes\t\t fail #/bytes\n"
14795 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
14797 + int i, j, length = 0;
14798 + static char *type[VXA_SOCK_SIZE] = {
14799 + "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
14802 + length += sprintf(buffer + length, VX_SOCKA_TOP);
14803 + for (i = 0; i < VXA_SOCK_SIZE; i++) {
14804 + length += sprintf(buffer + length, "%s:", type[i]);
14805 + for (j = 0; j < 3; j++) {
14806 + length += sprintf(buffer + length,
14807 + "\t%10lu/%-10lu",
14808 + vx_sock_count(cacct, i, j),
14809 + vx_sock_total(cacct, i, j));
14811 + buffer[length++] = '\n';
14814 + length += sprintf(buffer + length, "\n");
14815 + length += sprintf(buffer + length,
14816 + "slab:\t %8u %8u %8u %8u\n",
14817 + atomic_read(&cacct->slab[1]),
14818 + atomic_read(&cacct->slab[4]),
14819 + atomic_read(&cacct->slab[0]),
14820 + atomic_read(&cacct->slab[2]));
14822 + length += sprintf(buffer + length, "\n");
14823 + for (i = 0; i < 5; i++) {
14824 + length += sprintf(buffer + length,
14825 + "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
14826 + atomic_read(&cacct->page[i][0]),
14827 + atomic_read(&cacct->page[i][1]),
14828 + atomic_read(&cacct->page[i][2]),
14829 + atomic_read(&cacct->page[i][3]),
14830 + atomic_read(&cacct->page[i][4]),
14831 + atomic_read(&cacct->page[i][5]),
14832 + atomic_read(&cacct->page[i][6]),
14833 + atomic_read(&cacct->page[i][7]));
14838 +#endif /* _VX_CACCT_PROC_H */
14839 diff -NurpP --minimal linux-3.13.6/kernel/vserver/context.c linux-3.13.6-vs2.3.6.11/kernel/vserver/context.c
14840 --- linux-3.13.6/kernel/vserver/context.c 1970-01-01 00:00:00.000000000 +0000
14841 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/context.c 2014-01-31 20:38:03.000000000 +0000
14844 + * linux/kernel/vserver/context.c
14846 + * Virtual Server: Context Support
14848 + * Copyright (C) 2003-2011 Herbert Pötzl
14850 + * V0.01 context helper
14851 + * V0.02 vx_ctx_kill syscall command
14852 + * V0.03 replaced context_info calls
14853 + * V0.04 redesign of struct (de)alloc
14854 + * V0.05 rlimit basic implementation
14855 + * V0.06 task_xid and info commands
14856 + * V0.07 context flags and caps
14857 + * V0.08 switch to RCU based hash
14858 + * V0.09 revert to non RCU for now
14859 + * V0.10 and back to working RCU hash
14860 + * V0.11 and back to locking again
14861 + * V0.12 referenced context store
14862 + * V0.13 separate per cpu data
14863 + * V0.14 changed vcmds to vxi arg
14864 + * V0.15 added context stat
14865 + * V0.16 have __create claim() the vxi
14866 + * V0.17 removed older and legacy stuff
14867 + * V0.18 added user credentials
14868 + * V0.19 added warn mask
14872 +#include <linux/slab.h>
14873 +#include <linux/types.h>
14874 +#include <linux/security.h>
14875 +#include <linux/pid_namespace.h>
14876 +#include <linux/capability.h>
14878 +#include <linux/vserver/context.h>
14879 +#include <linux/vserver/network.h>
14880 +#include <linux/vserver/debug.h>
14881 +#include <linux/vserver/limit.h>
14882 +#include <linux/vserver/limit_int.h>
14883 +#include <linux/vserver/space.h>
14884 +#include <linux/init_task.h>
14885 +#include <linux/fs_struct.h>
14886 +#include <linux/cred.h>
14888 +#include <linux/vs_context.h>
14889 +#include <linux/vs_limit.h>
14890 +#include <linux/vs_pid.h>
14891 +#include <linux/vserver/context_cmd.h>
14893 +#include "cvirt_init.h"
14894 +#include "cacct_init.h"
14895 +#include "limit_init.h"
14896 +#include "sched_init.h"
14899 +atomic_t vx_global_ctotal = ATOMIC_INIT(0);
14900 +atomic_t vx_global_cactive = ATOMIC_INIT(0);
14903 +/* now inactive context structures */
14905 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
14907 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
14910 +/* __alloc_vx_info()
14912 + * allocate an initialized vx_info struct
14913 + * doesn't make it visible (hash) */
14915 +static struct vx_info *__alloc_vx_info(vxid_t xid)
14917 + struct vx_info *new = NULL;
14920 + vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
14922 + /* would this benefit from a slab cache? */
14923 + new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
14927 + memset(new, 0, sizeof(struct vx_info));
14929 + new->ptr_pc = alloc_percpu(struct _vx_info_pc);
14930 + if (!new->ptr_pc)
14933 + new->vx_id = xid;
14934 + INIT_HLIST_NODE(&new->vx_hlist);
14935 + atomic_set(&new->vx_usecnt, 0);
14936 + atomic_set(&new->vx_tasks, 0);
14937 + new->vx_parent = NULL;
14938 + new->vx_state = 0;
14939 + init_waitqueue_head(&new->vx_wait);
14941 + /* prepare reaper */
14942 + get_task_struct(init_pid_ns.child_reaper);
14943 + new->vx_reaper = init_pid_ns.child_reaper;
14944 + new->vx_badness_bias = 0;
14946 + /* rest of init goes here */
14947 + vx_info_init_limit(&new->limit);
14948 + vx_info_init_sched(&new->sched);
14949 + vx_info_init_cvirt(&new->cvirt);
14950 + vx_info_init_cacct(&new->cacct);
14952 + /* per cpu data structures */
14953 + for_each_possible_cpu(cpu) {
14954 + vx_info_init_sched_pc(
14955 + &vx_per_cpu(new, sched_pc, cpu), cpu);
14956 + vx_info_init_cvirt_pc(
14957 + &vx_per_cpu(new, cvirt_pc, cpu), cpu);
14960 + new->vx_flags = VXF_INIT_SET;
14961 + new->vx_bcaps = CAP_FULL_SET; // maybe ~CAP_SETPCAP
14962 + new->vx_ccaps = 0;
14963 + new->vx_umask = 0;
14964 + new->vx_wmask = 0;
14966 + new->reboot_cmd = 0;
14967 + new->exit_code = 0;
14969 + // preconfig spaces
14970 + for (index = 0; index < VX_SPACES; index++) {
14971 + struct _vx_space *space = &new->space[index];
14974 + spin_lock(&init_fs.lock);
14976 + spin_unlock(&init_fs.lock);
14977 + space->vx_fs = &init_fs;
14979 + /* FIXME: do we want defaults? */
14980 + // space->vx_real_cred = 0;
14981 + // space->vx_cred = 0;
14985 + vxdprintk(VXD_CBIT(xid, 0),
14986 + "alloc_vx_info(%d) = %p", xid, new);
14987 + vxh_alloc_vx_info(new);
14988 + atomic_inc(&vx_global_ctotal);
14997 +/* __dealloc_vx_info()
14999 + * final disposal of vx_info */
15001 +static void __dealloc_vx_info(struct vx_info *vxi)
15003 +#ifdef CONFIG_VSERVER_WARN
15004 + struct vx_info_save vxis;
15007 + vxdprintk(VXD_CBIT(xid, 0),
15008 + "dealloc_vx_info(%p)", vxi);
15009 + vxh_dealloc_vx_info(vxi);
15011 +#ifdef CONFIG_VSERVER_WARN
15012 + enter_vx_info(vxi, &vxis);
15013 + vx_info_exit_limit(&vxi->limit);
15014 + vx_info_exit_sched(&vxi->sched);
15015 + vx_info_exit_cvirt(&vxi->cvirt);
15016 + vx_info_exit_cacct(&vxi->cacct);
15018 + for_each_possible_cpu(cpu) {
15019 + vx_info_exit_sched_pc(
15020 + &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15021 + vx_info_exit_cvirt_pc(
15022 + &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15024 + leave_vx_info(&vxis);
15028 + vxi->vx_state |= VXS_RELEASED;
15031 + free_percpu(vxi->ptr_pc);
15034 + atomic_dec(&vx_global_ctotal);
15037 +static void __shutdown_vx_info(struct vx_info *vxi)
15039 + struct nsproxy *nsproxy;
15040 + struct fs_struct *fs;
15041 + struct cred *cred;
15046 + vxi->vx_state |= VXS_SHUTDOWN;
15047 + vs_state_change(vxi, VSC_SHUTDOWN);
15049 + for (index = 0; index < VX_SPACES; index++) {
15050 + struct _vx_space *space = &vxi->space[index];
15052 + nsproxy = xchg(&space->vx_nsproxy, NULL);
15054 + put_nsproxy(nsproxy);
15056 + fs = xchg(&space->vx_fs, NULL);
15057 + spin_lock(&fs->lock);
15058 + kill = !--fs->users;
15059 + spin_unlock(&fs->lock);
15061 + free_fs_struct(fs);
15063 + cred = (struct cred *)xchg(&space->vx_cred, NULL);
15065 + abort_creds(cred);
15069 +/* exported stuff */
15071 +void free_vx_info(struct vx_info *vxi)
15073 + unsigned long flags;
15076 + /* check for reference counts first */
15077 + BUG_ON(atomic_read(&vxi->vx_usecnt));
15078 + BUG_ON(atomic_read(&vxi->vx_tasks));
15080 + /* context must not be hashed */
15081 + BUG_ON(vx_info_state(vxi, VXS_HASHED));
15083 + /* context shutdown is mandatory */
15084 + BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15086 + /* spaces check */
15087 + for (index = 0; index < VX_SPACES; index++) {
15088 + struct _vx_space *space = &vxi->space[index];
15090 + BUG_ON(space->vx_nsproxy);
15091 + BUG_ON(space->vx_fs);
15092 + // BUG_ON(space->vx_real_cred);
15093 + // BUG_ON(space->vx_cred);
15096 + spin_lock_irqsave(&vx_info_inactive_lock, flags);
15097 + hlist_del(&vxi->vx_hlist);
15098 + spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15100 + __dealloc_vx_info(vxi);
15104 +/* hash table for vx_info hash */
15106 +#define VX_HASH_SIZE 13
15108 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15109 + { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15111 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15114 +static inline unsigned int __hashval(vxid_t xid)
15116 + return (xid % VX_HASH_SIZE);
15121 +/* __hash_vx_info()
15123 + * add the vxi to the global hash table
15124 + * requires the hash_lock to be held */
15126 +static inline void __hash_vx_info(struct vx_info *vxi)
15128 + struct hlist_head *head;
15130 + vxd_assert_lock(&vx_info_hash_lock);
15131 + vxdprintk(VXD_CBIT(xid, 4),
15132 + "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15133 + vxh_hash_vx_info(vxi);
15135 + /* context must not be hashed */
15136 + BUG_ON(vx_info_state(vxi, VXS_HASHED));
15138 + vxi->vx_state |= VXS_HASHED;
15139 + head = &vx_info_hash[__hashval(vxi->vx_id)];
15140 + hlist_add_head(&vxi->vx_hlist, head);
15141 + atomic_inc(&vx_global_cactive);
15144 +/* __unhash_vx_info()
15146 + * remove the vxi from the global hash table
15147 + * requires the hash_lock to be held */
15149 +static inline void __unhash_vx_info(struct vx_info *vxi)
15151 + unsigned long flags;
15153 + vxd_assert_lock(&vx_info_hash_lock);
15154 + vxdprintk(VXD_CBIT(xid, 4),
15155 + "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15156 + atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15157 + vxh_unhash_vx_info(vxi);
15159 + /* context must be hashed */
15160 + BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15161 + /* but without tasks */
15162 + BUG_ON(atomic_read(&vxi->vx_tasks));
15164 + vxi->vx_state &= ~VXS_HASHED;
15165 + hlist_del_init(&vxi->vx_hlist);
15166 + spin_lock_irqsave(&vx_info_inactive_lock, flags);
15167 + hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15168 + spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15169 + atomic_dec(&vx_global_cactive);
15173 +/* __lookup_vx_info()
15175 + * requires the hash_lock to be held
15176 + * doesn't increment the vx_refcnt */
15178 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
15180 + struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15181 + struct hlist_node *pos;
15182 + struct vx_info *vxi;
15184 + vxd_assert_lock(&vx_info_hash_lock);
15185 + hlist_for_each(pos, head) {
15186 + vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15188 + if (vxi->vx_id == xid)
15193 + vxdprintk(VXD_CBIT(xid, 0),
15194 + "__lookup_vx_info(#%u): %p[#%u]",
15195 + xid, vxi, vxi ? vxi->vx_id : 0);
15196 + vxh_lookup_vx_info(vxi, xid);
15201 +/* __create_vx_info()
15203 + * create the requested context
15204 + * get(), claim() and hash it */
15206 +static struct vx_info *__create_vx_info(int id)
15208 + struct vx_info *new, *vxi = NULL;
15210 + vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15212 + if (!(new = __alloc_vx_info(id)))
15213 + return ERR_PTR(-ENOMEM);
15215 + /* required to make dynamic xids unique */
15216 + spin_lock(&vx_info_hash_lock);
15218 + /* static context requested */
15219 + if ((vxi = __lookup_vx_info(id))) {
15220 + vxdprintk(VXD_CBIT(xid, 0),
15221 + "create_vx_info(%d) = %p (already there)", id, vxi);
15222 + if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15223 + vxi = ERR_PTR(-EBUSY);
15225 + vxi = ERR_PTR(-EEXIST);
15228 + /* new context */
15229 + vxdprintk(VXD_CBIT(xid, 0),
15230 + "create_vx_info(%d) = %p (new)", id, new);
15231 + claim_vx_info(new, NULL);
15232 + __hash_vx_info(get_vx_info(new));
15233 + vxi = new, new = NULL;
15236 + spin_unlock(&vx_info_hash_lock);
15237 + vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15239 + __dealloc_vx_info(new);
15244 +/* exported stuff */
15247 +void unhash_vx_info(struct vx_info *vxi)
15249 + spin_lock(&vx_info_hash_lock);
15250 + __unhash_vx_info(vxi);
15251 + spin_unlock(&vx_info_hash_lock);
15252 + __shutdown_vx_info(vxi);
15253 + __wakeup_vx_info(vxi);
15257 +/* lookup_vx_info()
15259 + * search for a vx_info and get() it
15260 + * negative id means current */
15262 +struct vx_info *lookup_vx_info(int id)
15264 + struct vx_info *vxi = NULL;
15267 + vxi = get_vx_info(current_vx_info());
15268 + } else if (id > 1) {
15269 + spin_lock(&vx_info_hash_lock);
15270 + vxi = get_vx_info(__lookup_vx_info(id));
15271 + spin_unlock(&vx_info_hash_lock);
15276 +/* xid_is_hashed()
15278 + * verify that xid is still hashed */
15280 +int xid_is_hashed(vxid_t xid)
15284 + spin_lock(&vx_info_hash_lock);
15285 + hashed = (__lookup_vx_info(xid) != NULL);
15286 + spin_unlock(&vx_info_hash_lock);
15290 +#ifdef CONFIG_PROC_FS
15294 + * get a subset of hashed xids for proc
15295 + * assumes size is at least one */
15297 +int get_xid_list(int index, unsigned int *xids, int size)
15299 + int hindex, nr_xids = 0;
15301 + /* only show current and children */
15302 + if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15305 + xids[nr_xids] = vx_current_xid();
15309 + for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15310 + struct hlist_head *head = &vx_info_hash[hindex];
15311 + struct hlist_node *pos;
15313 + spin_lock(&vx_info_hash_lock);
15314 + hlist_for_each(pos, head) {
15315 + struct vx_info *vxi;
15320 + vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15321 + xids[nr_xids] = vxi->vx_id;
15322 + if (++nr_xids >= size) {
15323 + spin_unlock(&vx_info_hash_lock);
15327 + /* keep the lock time short */
15328 + spin_unlock(&vx_info_hash_lock);
15335 +#ifdef CONFIG_VSERVER_DEBUG
15337 +void dump_vx_info_inactive(int level)
15339 + struct hlist_node *entry, *next;
15341 + hlist_for_each_safe(entry, next, &vx_info_inactive) {
15342 + struct vx_info *vxi =
15343 + list_entry(entry, struct vx_info, vx_hlist);
15345 + dump_vx_info(vxi, level);
15352 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
15354 + struct user_struct *new_user, *old_user;
15359 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
15362 + new_user = alloc_uid(vxi->vx_id, p->uid);
15366 + old_user = p->user;
15367 + if (new_user != old_user) {
15368 + atomic_inc(&new_user->processes);
15369 + atomic_dec(&old_user->processes);
15370 + p->user = new_user;
15372 + free_uid(old_user);
15378 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
15380 + // p->cap_effective &= vxi->vx_cap_bset;
15381 + p->cap_effective =
15382 + cap_intersect(p->cap_effective, vxi->cap_bset);
15383 + // p->cap_inheritable &= vxi->vx_cap_bset;
15384 + p->cap_inheritable =
15385 + cap_intersect(p->cap_inheritable, vxi->cap_bset);
15386 + // p->cap_permitted &= vxi->vx_cap_bset;
15387 + p->cap_permitted =
15388 + cap_intersect(p->cap_permitted, vxi->cap_bset);
15393 +#include <linux/file.h>
15394 +#include <linux/fdtable.h>
15396 +static int vx_openfd_task(struct task_struct *tsk)
15398 + struct files_struct *files = tsk->files;
15399 + struct fdtable *fdt;
15400 + const unsigned long *bptr;
15401 + int count, total;
15403 + /* no rcu_read_lock() because of spin_lock() */
15404 + spin_lock(&files->file_lock);
15405 + fdt = files_fdtable(files);
15406 + bptr = fdt->open_fds;
15407 + count = fdt->max_fds / (sizeof(unsigned long) * 8);
15408 + for (total = 0; count > 0; count--) {
15410 + total += hweight_long(*bptr);
15413 + spin_unlock(&files->file_lock);
15418 +/* for *space compatibility */
15420 +asmlinkage long sys_unshare(unsigned long);
15423 + * migrate task to new context
15424 + * gets vxi, puts old_vxi on change
15425 + * optionally unshares namespaces (hack)
15428 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
15430 + struct vx_info *old_vxi;
15436 + vxdprintk(VXD_CBIT(xid, 5),
15437 + "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
15438 + vxi->vx_id, atomic_read(&vxi->vx_usecnt));
15440 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
15441 + !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15444 + if (vx_info_state(vxi, VXS_SHUTDOWN))
15447 + old_vxi = task_get_vx_info(p);
15448 + if (old_vxi == vxi)
15451 +// if (!(ret = vx_migrate_user(p, vxi))) {
15456 + openfd = vx_openfd_task(p);
15459 + atomic_dec(&old_vxi->cvirt.nr_threads);
15460 + atomic_dec(&old_vxi->cvirt.nr_running);
15461 + __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
15462 + /* FIXME: what about the struct files here? */
15463 + __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
15464 + /* account for the executable */
15465 + __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
15467 + atomic_inc(&vxi->cvirt.nr_threads);
15468 + atomic_inc(&vxi->cvirt.nr_running);
15469 + __rlim_inc(&vxi->limit, RLIMIT_NPROC);
15470 + /* FIXME: what about the struct files here? */
15471 + __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
15472 + /* account for the executable */
15473 + __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
15476 + release_vx_info(old_vxi, p);
15477 + clr_vx_info(&p->vx_info);
15479 + claim_vx_info(vxi, p);
15480 + set_vx_info(&p->vx_info, vxi);
15481 + p->xid = vxi->vx_id;
15483 + vxdprintk(VXD_CBIT(xid, 5),
15484 + "moved task %p into vxi:%p[#%d]",
15485 + p, vxi, vxi->vx_id);
15487 + // vx_mask_cap_bset(vxi, p);
15490 + /* hack for *spaces to provide compatibility */
15492 + struct nsproxy *old_nsp, *new_nsp;
15494 + ret = unshare_nsproxy_namespaces(
15495 + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
15496 + &new_nsp, NULL, NULL);
15500 + old_nsp = xchg(&p->nsproxy, new_nsp);
15501 + vx_set_space(vxi,
15502 + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
15503 + put_nsproxy(old_nsp);
15507 + put_vx_info(old_vxi);
15511 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
15513 + struct task_struct *old_reaper;
15514 + struct vx_info *reaper_vxi;
15519 + vxdprintk(VXD_CBIT(xid, 6),
15520 + "vx_set_reaper(%p[#%d],%p[#%d,%d])",
15521 + vxi, vxi->vx_id, p, p->xid, p->pid);
15523 + old_reaper = vxi->vx_reaper;
15524 + if (old_reaper == p)
15527 + reaper_vxi = task_get_vx_info(p);
15528 + if (reaper_vxi && reaper_vxi != vxi) {
15530 + "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
15532 + p->comm, p->pid, p->xid, vx_current_xid());
15536 + /* set new child reaper */
15537 + get_task_struct(p);
15538 + vxi->vx_reaper = p;
15539 + put_task_struct(old_reaper);
15541 + put_vx_info(reaper_vxi);
15545 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
15550 + vxdprintk(VXD_CBIT(xid, 6),
15551 + "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
15552 + vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15554 + vxi->vx_flags &= ~VXF_STATE_INIT;
15555 + // vxi->vx_initpid = p->tgid;
15556 + vxi->vx_initpid = p->pid;
15560 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
15562 + vxdprintk(VXD_CBIT(xid, 6),
15563 + "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
15564 + vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15566 + vxi->exit_code = code;
15567 + vxi->vx_initpid = 0;
15571 +void vx_set_persistent(struct vx_info *vxi)
15573 + vxdprintk(VXD_CBIT(xid, 6),
15574 + "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
15576 + get_vx_info(vxi);
15577 + claim_vx_info(vxi, NULL);
15580 +void vx_clear_persistent(struct vx_info *vxi)
15582 + vxdprintk(VXD_CBIT(xid, 6),
15583 + "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
15585 + release_vx_info(vxi, NULL);
15586 + put_vx_info(vxi);
15589 +void vx_update_persistent(struct vx_info *vxi)
15591 + if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
15592 + vx_set_persistent(vxi);
15594 + vx_clear_persistent(vxi);
15598 +/* task must be current or locked */
15600 +void exit_vx_info(struct task_struct *p, int code)
15602 + struct vx_info *vxi = p->vx_info;
15605 + atomic_dec(&vxi->cvirt.nr_threads);
15608 + vxi->exit_code = code;
15609 + release_vx_info(vxi, p);
15613 +void exit_vx_info_early(struct task_struct *p, int code)
15615 + struct vx_info *vxi = p->vx_info;
15618 + if (vxi->vx_initpid == p->pid)
15619 + vx_exit_init(vxi, p, code);
15620 + if (vxi->vx_reaper == p)
15621 + vx_set_reaper(vxi, init_pid_ns.child_reaper);
15626 +/* vserver syscall commands below here */
15628 +/* taks xid and vx_info functions */
15630 +#include <asm/uaccess.h>
15633 +int vc_task_xid(uint32_t id)
15638 + struct task_struct *tsk;
15641 + tsk = find_task_by_real_pid(id);
15642 + xid = (tsk) ? tsk->xid : -ESRCH;
15643 + rcu_read_unlock();
15645 + xid = vx_current_xid();
15650 +int vc_vx_info(struct vx_info *vxi, void __user *data)
15652 + struct vcmd_vx_info_v0 vc_data;
15654 + vc_data.xid = vxi->vx_id;
15655 + vc_data.initpid = vxi->vx_initpid;
15657 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15663 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
15665 + struct vcmd_ctx_stat_v0 vc_data;
15667 + vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
15668 + vc_data.tasks = atomic_read(&vxi->vx_tasks);
15670 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15676 +/* context functions */
15678 +int vc_ctx_create(uint32_t xid, void __user *data)
15680 + struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
15681 + struct vx_info *new_vxi;
15684 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15687 + if ((xid > MAX_S_CONTEXT) || (xid < 2))
15690 + new_vxi = __create_vx_info(xid);
15691 + if (IS_ERR(new_vxi))
15692 + return PTR_ERR(new_vxi);
15694 + /* initial flags */
15695 + new_vxi->vx_flags = vc_data.flagword;
15698 + if (vs_state_change(new_vxi, VSC_STARTUP))
15701 + ret = vx_migrate_task(current, new_vxi, (!data));
15705 + /* return context id on success */
15706 + ret = new_vxi->vx_id;
15708 + /* get a reference for persistent contexts */
15709 + if ((vc_data.flagword & VXF_PERSISTENT))
15710 + vx_set_persistent(new_vxi);
15712 + release_vx_info(new_vxi, NULL);
15713 + put_vx_info(new_vxi);
15718 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
15720 + struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
15723 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15726 + ret = vx_migrate_task(current, vxi, 0);
15729 + if (vc_data.flagword & VXM_SET_INIT)
15730 + ret = vx_set_init(vxi, current);
15733 + if (vc_data.flagword & VXM_SET_REAPER)
15734 + ret = vx_set_reaper(vxi, current);
15739 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
15741 + struct vcmd_ctx_flags_v0 vc_data;
15743 + vc_data.flagword = vxi->vx_flags;
15745 + /* special STATE flag handling */
15746 + vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
15748 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15753 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
15755 + struct vcmd_ctx_flags_v0 vc_data;
15756 + uint64_t mask, trigger;
15758 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15761 + /* special STATE flag handling */
15762 + mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
15763 + trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
15765 + if (vxi == current_vx_info()) {
15766 + /* if (trigger & VXF_STATE_SETUP)
15767 + vx_mask_cap_bset(vxi, current); */
15768 + if (trigger & VXF_STATE_INIT) {
15771 + ret = vx_set_init(vxi, current);
15774 + ret = vx_set_reaper(vxi, current);
15780 + vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
15781 + vc_data.flagword, mask);
15782 + if (trigger & VXF_PERSISTENT)
15783 + vx_update_persistent(vxi);
15789 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
15791 + uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
15793 + // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
15797 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
15799 + kernel_cap_t c = __cap_empty_set;
15801 + c.cap[0] = v & 0xFFFFFFFF;
15802 + c.cap[1] = (v >> 32) & 0xFFFFFFFF;
15804 + // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
15809 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
15812 + *bcaps = caps_from_cap_t(vxi->vx_bcaps);
15814 + *ccaps = vxi->vx_ccaps;
15819 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
15821 + struct vcmd_ctx_caps_v1 vc_data;
15824 + ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
15827 + vc_data.cmask = ~0ULL;
15829 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15834 +static int do_set_caps(struct vx_info *vxi,
15835 + uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
15837 + uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
15840 + printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
15841 + bcaps, bmask, ccaps, cmask);
15843 + vxi->vx_bcaps = cap_t_from_caps(
15844 + vs_mask_flags(bcold, bcaps, bmask));
15845 + vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
15850 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
15852 + struct vcmd_ctx_caps_v1 vc_data;
15854 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15857 + return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
15860 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
15862 + struct vcmd_bcaps vc_data;
15865 + ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
15868 + vc_data.bmask = ~0ULL;
15870 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15875 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
15877 + struct vcmd_bcaps vc_data;
15879 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15882 + return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
15886 +int vc_get_umask(struct vx_info *vxi, void __user *data)
15888 + struct vcmd_umask vc_data;
15890 + vc_data.umask = vxi->vx_umask;
15891 + vc_data.mask = ~0ULL;
15893 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15898 +int vc_set_umask(struct vx_info *vxi, void __user *data)
15900 + struct vcmd_umask vc_data;
15902 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15905 + vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
15906 + vc_data.umask, vc_data.mask);
15911 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
15913 + struct vcmd_wmask vc_data;
15915 + vc_data.wmask = vxi->vx_wmask;
15916 + vc_data.mask = ~0ULL;
15918 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15923 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
15925 + struct vcmd_wmask vc_data;
15927 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15930 + vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
15931 + vc_data.wmask, vc_data.mask);
15936 +int vc_get_badness(struct vx_info *vxi, void __user *data)
15938 + struct vcmd_badness_v0 vc_data;
15940 + vc_data.bias = vxi->vx_badness_bias;
15942 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15947 +int vc_set_badness(struct vx_info *vxi, void __user *data)
15949 + struct vcmd_badness_v0 vc_data;
15951 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15954 + vxi->vx_badness_bias = vc_data.bias;
15958 +#include <linux/module.h>
15960 +EXPORT_SYMBOL_GPL(free_vx_info);
15962 diff -NurpP --minimal linux-3.13.6/kernel/vserver/cvirt.c linux-3.13.6-vs2.3.6.11/kernel/vserver/cvirt.c
15963 --- linux-3.13.6/kernel/vserver/cvirt.c 1970-01-01 00:00:00.000000000 +0000
15964 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/cvirt.c 2014-01-31 20:38:04.000000000 +0000
15967 + * linux/kernel/vserver/cvirt.c
15969 + * Virtual Server: Context Virtualization
15971 + * Copyright (C) 2004-2007 Herbert Pötzl
15973 + * V0.01 broken out from limit.c
15974 + * V0.02 added utsname stuff
15975 + * V0.03 changed vcmds to vxi arg
15979 +#include <linux/types.h>
15980 +#include <linux/utsname.h>
15981 +#include <linux/vs_cvirt.h>
15982 +#include <linux/vserver/switch.h>
15983 +#include <linux/vserver/cvirt_cmd.h>
15985 +#include <asm/uaccess.h>
15988 +void vx_vsi_boottime(struct timespec *boottime)
15990 + struct vx_info *vxi = current_vx_info();
15992 + set_normalized_timespec(boottime,
15993 + boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
15994 + boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
15998 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16000 + struct vx_info *vxi = current_vx_info();
16002 + set_normalized_timespec(uptime,
16003 + uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16004 + uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16007 + set_normalized_timespec(idle,
16008 + idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16009 + idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16013 +uint64_t vx_idle_jiffies(void)
16015 + return init_task.utime + init_task.stime;
16020 +static inline uint32_t __update_loadavg(uint32_t load,
16021 + int wsize, int delta, int n)
16023 + unsigned long long calc, prev;
16025 + /* just set it to n */
16026 + if (unlikely(delta >= wsize))
16027 + return (n << FSHIFT);
16029 + calc = delta * n;
16031 + prev = (wsize - delta);
16034 + do_div(calc, wsize);
16039 +void vx_update_load(struct vx_info *vxi)
16041 + uint32_t now, last, delta;
16042 + unsigned int nr_running, nr_uninterruptible;
16043 + unsigned int total;
16044 + unsigned long flags;
16046 + spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16049 + last = vxi->cvirt.load_last;
16050 + delta = now - last;
16052 + if (delta < 5*HZ)
16055 + nr_running = atomic_read(&vxi->cvirt.nr_running);
16056 + nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16057 + total = nr_running + nr_uninterruptible;
16059 + vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16060 + 60*HZ, delta, total);
16061 + vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16062 + 5*60*HZ, delta, total);
16063 + vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16064 + 15*60*HZ, delta, total);
16066 + vxi->cvirt.load_last = now;
16068 + atomic_inc(&vxi->cvirt.load_updates);
16069 + spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16074 + * Commands to do_syslog:
16076 + * 0 -- Close the log. Currently a NOP.
16077 + * 1 -- Open the log. Currently a NOP.
16078 + * 2 -- Read from the log.
16079 + * 3 -- Read all messages remaining in the ring buffer.
16080 + * 4 -- Read and clear all messages remaining in the ring buffer
16081 + * 5 -- Clear ring buffer.
16082 + * 6 -- Disable printk's to console
16083 + * 7 -- Enable printk's to console
16084 + * 8 -- Set level of messages printed to console
16085 + * 9 -- Return number of unread characters in the log buffer
16086 + * 10 -- Return size of the log buffer
16088 +int vx_do_syslog(int type, char __user *buf, int len)
16091 + int do_clear = 0;
16092 + struct vx_info *vxi = current_vx_info();
16093 + struct _vx_syslog *log;
16097 + log = &vxi->cvirt.syslog;
16100 + case 0: /* Close log */
16101 + case 1: /* Open log */
16103 + case 2: /* Read from log */
16104 + error = wait_event_interruptible(log->log_wait,
16105 + (log->log_start - log->log_end));
16108 + spin_lock_irq(&log->logbuf_lock);
16109 + spin_unlock_irq(&log->logbuf_lock);
16111 + case 4: /* Read/clear last kernel messages */
16113 + /* fall through */
16114 + case 3: /* Read last kernel messages */
16117 + case 5: /* Clear ring buffer */
16120 + case 6: /* Disable logging to console */
16121 + case 7: /* Enable logging to console */
16122 + case 8: /* Set level of messages printed to console */
16125 + case 9: /* Number of chars in the log buffer */
16127 + case 10: /* Size of the log buffer */
16137 +/* virtual host info names */
16139 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16141 + struct nsproxy *nsproxy;
16142 + struct uts_namespace *uts;
16144 + if (id == VHIN_CONTEXT)
16145 + return vxi->vx_name;
16147 + nsproxy = vxi->space[0].vx_nsproxy;
16151 + uts = nsproxy->uts_ns;
16156 + case VHIN_SYSNAME:
16157 + return uts->name.sysname;
16158 + case VHIN_NODENAME:
16159 + return uts->name.nodename;
16160 + case VHIN_RELEASE:
16161 + return uts->name.release;
16162 + case VHIN_VERSION:
16163 + return uts->name.version;
16164 + case VHIN_MACHINE:
16165 + return uts->name.machine;
16166 + case VHIN_DOMAINNAME:
16167 + return uts->name.domainname;
16174 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16176 + struct vcmd_vhi_name_v0 vc_data;
16179 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16182 + name = vx_vhi_name(vxi, vc_data.field);
16186 + memcpy(name, vc_data.name, 65);
16190 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16192 + struct vcmd_vhi_name_v0 vc_data;
16195 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16198 + name = vx_vhi_name(vxi, vc_data.field);
16202 + memcpy(vc_data.name, name, 65);
16203 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16209 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16211 + struct vcmd_virt_stat_v0 vc_data;
16212 + struct _vx_cvirt *cvirt = &vxi->cvirt;
16213 + struct timespec uptime;
16215 + do_posix_clock_monotonic_gettime(&uptime);
16216 + set_normalized_timespec(&uptime,
16217 + uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16218 + uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16220 + vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16221 + vc_data.uptime = timespec_to_ns(&uptime);
16222 + vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16223 + vc_data.nr_running = atomic_read(&cvirt->nr_running);
16224 + vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16225 + vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16226 + vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16227 + vc_data.load[0] = cvirt->load[0];
16228 + vc_data.load[1] = cvirt->load[1];
16229 + vc_data.load[2] = cvirt->load[2];
16231 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16237 +#ifdef CONFIG_VSERVER_VTIME
16239 +/* virtualized time base */
16241 +void vx_adjust_timespec(struct timespec *ts)
16243 + struct vx_info *vxi;
16245 + if (!vx_flags(VXF_VIRT_TIME, 0))
16248 + vxi = current_vx_info();
16249 + ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16250 + ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16252 + if (ts->tv_nsec >= NSEC_PER_SEC) {
16254 + ts->tv_nsec -= NSEC_PER_SEC;
16255 + } else if (ts->tv_nsec < 0) {
16257 + ts->tv_nsec += NSEC_PER_SEC;
16261 +int vx_settimeofday(const struct timespec *ts)
16263 + struct timespec ats, delta;
16264 + struct vx_info *vxi;
16266 + if (!vx_flags(VXF_VIRT_TIME, 0))
16267 + return do_settimeofday(ts);
16269 + getnstimeofday(&ats);
16270 + delta = timespec_sub(*ts, ats);
16272 + vxi = current_vx_info();
16273 + vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16279 diff -NurpP --minimal linux-3.13.6/kernel/vserver/cvirt_init.h linux-3.13.6-vs2.3.6.11/kernel/vserver/cvirt_init.h
16280 --- linux-3.13.6/kernel/vserver/cvirt_init.h 1970-01-01 00:00:00.000000000 +0000
16281 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/cvirt_init.h 2014-01-31 20:38:04.000000000 +0000
16285 +extern uint64_t vx_idle_jiffies(void);
16287 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16289 + uint64_t idle_jiffies = vx_idle_jiffies();
16290 + uint64_t nsuptime;
16292 + do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16293 + nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16294 + * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16295 + cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16296 + cvirt->bias_ts.tv_sec = 0;
16297 + cvirt->bias_ts.tv_nsec = 0;
16299 + jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16300 + atomic_set(&cvirt->nr_threads, 0);
16301 + atomic_set(&cvirt->nr_running, 0);
16302 + atomic_set(&cvirt->nr_uninterruptible, 0);
16303 + atomic_set(&cvirt->nr_onhold, 0);
16305 + spin_lock_init(&cvirt->load_lock);
16306 + cvirt->load_last = jiffies;
16307 + atomic_set(&cvirt->load_updates, 0);
16308 + cvirt->load[0] = 0;
16309 + cvirt->load[1] = 0;
16310 + cvirt->load[2] = 0;
16311 + atomic_set(&cvirt->total_forks, 0);
16313 + spin_lock_init(&cvirt->syslog.logbuf_lock);
16314 + init_waitqueue_head(&cvirt->syslog.log_wait);
16315 + cvirt->syslog.log_start = 0;
16316 + cvirt->syslog.log_end = 0;
16317 + cvirt->syslog.con_start = 0;
16318 + cvirt->syslog.logged_chars = 0;
16322 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16324 + // cvirt_pc->cpustat = { 0 };
16327 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16329 +#ifdef CONFIG_VSERVER_WARN
16332 + vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16333 + "!!! cvirt: %p[nr_threads] = %d on exit.",
16335 + vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16336 + "!!! cvirt: %p[nr_running] = %d on exit.",
16338 + vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16339 + "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16341 + vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16342 + "!!! cvirt: %p[nr_onhold] = %d on exit.",
16348 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16353 diff -NurpP --minimal linux-3.13.6/kernel/vserver/cvirt_proc.h linux-3.13.6-vs2.3.6.11/kernel/vserver/cvirt_proc.h
16354 --- linux-3.13.6/kernel/vserver/cvirt_proc.h 1970-01-01 00:00:00.000000000 +0000
16355 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/cvirt_proc.h 2014-01-31 20:38:04.000000000 +0000
16357 +#ifndef _VX_CVIRT_PROC_H
16358 +#define _VX_CVIRT_PROC_H
16360 +#include <linux/nsproxy.h>
16361 +#include <linux/mnt_namespace.h>
16362 +#include <linux/ipc_namespace.h>
16363 +#include <linux/utsname.h>
16364 +#include <linux/ipc.h>
16366 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
16369 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
16371 + struct mnt_namespace *ns;
16372 + struct uts_namespace *uts;
16373 + struct ipc_namespace *ipc;
16379 + length += sprintf(buffer + length,
16380 + "NSProxy:\t%p [%p,%p,%p]\n",
16381 + nsproxy, nsproxy->mnt_ns,
16382 + nsproxy->uts_ns, nsproxy->ipc_ns);
16384 + ns = nsproxy->mnt_ns;
16388 + length += vx_info_mnt_namespace(ns, buffer + length);
16392 + uts = nsproxy->uts_ns;
16396 + length += sprintf(buffer + length,
16397 + "SysName:\t%.*s\n"
16398 + "NodeName:\t%.*s\n"
16399 + "Release:\t%.*s\n"
16400 + "Version:\t%.*s\n"
16401 + "Machine:\t%.*s\n"
16402 + "DomainName:\t%.*s\n",
16403 + __NEW_UTS_LEN, uts->name.sysname,
16404 + __NEW_UTS_LEN, uts->name.nodename,
16405 + __NEW_UTS_LEN, uts->name.release,
16406 + __NEW_UTS_LEN, uts->name.version,
16407 + __NEW_UTS_LEN, uts->name.machine,
16408 + __NEW_UTS_LEN, uts->name.domainname);
16411 + ipc = nsproxy->ipc_ns;
16415 + length += sprintf(buffer + length,
16416 + "SEMS:\t\t%d %d %d %d %d\n"
16417 + "MSG:\t\t%d %d %d\n"
16418 + "SHM:\t\t%lu %lu %d %ld\n",
16419 + ipc->sem_ctls[0], ipc->sem_ctls[1],
16420 + ipc->sem_ctls[2], ipc->sem_ctls[3],
16422 + ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
16423 + (unsigned long)ipc->shm_ctlmax,
16424 + (unsigned long)ipc->shm_ctlall,
16425 + ipc->shm_ctlmni, ipc->shm_tot);
16432 +#include <linux/sched.h>
16434 +#define LOAD_INT(x) ((x) >> FSHIFT)
16435 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
16438 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
16443 + length += sprintf(buffer + length,
16444 + "BiasUptime:\t%lu.%02lu\n",
16445 + (unsigned long)cvirt->bias_uptime.tv_sec,
16446 + (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
16448 + a = cvirt->load[0] + (FIXED_1 / 200);
16449 + b = cvirt->load[1] + (FIXED_1 / 200);
16450 + c = cvirt->load[2] + (FIXED_1 / 200);
16451 + length += sprintf(buffer + length,
16452 + "nr_threads:\t%d\n"
16453 + "nr_running:\t%d\n"
16454 + "nr_unintr:\t%d\n"
16455 + "nr_onhold:\t%d\n"
16456 + "load_updates:\t%d\n"
16457 + "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
16458 + "total_forks:\t%d\n",
16459 + atomic_read(&cvirt->nr_threads),
16460 + atomic_read(&cvirt->nr_running),
16461 + atomic_read(&cvirt->nr_uninterruptible),
16462 + atomic_read(&cvirt->nr_onhold),
16463 + atomic_read(&cvirt->load_updates),
16464 + LOAD_INT(a), LOAD_FRAC(a),
16465 + LOAD_INT(b), LOAD_FRAC(b),
16466 + LOAD_INT(c), LOAD_FRAC(c),
16467 + atomic_read(&cvirt->total_forks));
16472 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
16473 + char *buffer, int cpu)
16479 +#endif /* _VX_CVIRT_PROC_H */
16480 diff -NurpP --minimal linux-3.13.6/kernel/vserver/debug.c linux-3.13.6-vs2.3.6.11/kernel/vserver/debug.c
16481 --- linux-3.13.6/kernel/vserver/debug.c 1970-01-01 00:00:00.000000000 +0000
16482 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/debug.c 2014-01-31 20:38:04.000000000 +0000
16485 + * kernel/vserver/debug.c
16487 + * Copyright (C) 2005-2007 Herbert Pötzl
16489 + * V0.01 vx_info dump support
16493 +#include <linux/module.h>
16495 +#include <linux/vserver/context.h>
16498 +void dump_vx_info(struct vx_info *vxi, int level)
16500 + printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
16501 + atomic_read(&vxi->vx_usecnt),
16502 + atomic_read(&vxi->vx_tasks),
16505 + __dump_vx_limit(&vxi->limit);
16506 + __dump_vx_sched(&vxi->sched);
16507 + __dump_vx_cvirt(&vxi->cvirt);
16508 + __dump_vx_cacct(&vxi->cacct);
16514 +EXPORT_SYMBOL_GPL(dump_vx_info);
16516 diff -NurpP --minimal linux-3.13.6/kernel/vserver/device.c linux-3.13.6-vs2.3.6.11/kernel/vserver/device.c
16517 --- linux-3.13.6/kernel/vserver/device.c 1970-01-01 00:00:00.000000000 +0000
16518 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/device.c 2014-01-31 20:38:04.000000000 +0000
16521 + * linux/kernel/vserver/device.c
16523 + * Linux-VServer: Device Support
16525 + * Copyright (C) 2006 Herbert Pötzl
16526 + * Copyright (C) 2007 Daniel Hokka Zakrisson
16528 + * V0.01 device mapping basics
16529 + * V0.02 added defaults
16533 +#include <linux/slab.h>
16534 +#include <linux/rcupdate.h>
16535 +#include <linux/fs.h>
16536 +#include <linux/namei.h>
16537 +#include <linux/hash.h>
16539 +#include <asm/errno.h>
16540 +#include <asm/uaccess.h>
16541 +#include <linux/vserver/base.h>
16542 +#include <linux/vserver/debug.h>
16543 +#include <linux/vserver/context.h>
16544 +#include <linux/vserver/device.h>
16545 +#include <linux/vserver/device_cmd.h>
16548 +#define DMAP_HASH_BITS 4
16551 +struct vs_mapping {
16553 + struct hlist_node hlist;
16554 + struct list_head list;
16556 +#define dm_hlist u.hlist
16557 +#define dm_list u.list
16560 + struct vx_dmap_target target;
16564 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
16566 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
16568 +static struct vx_dmap_target dmap_defaults[2] = {
16569 + { .flags = DATTR_OPEN },
16570 + { .flags = DATTR_OPEN },
16574 +struct kmem_cache *dmap_cachep __read_mostly;
16576 +int __init dmap_cache_init(void)
16578 + dmap_cachep = kmem_cache_create("dmap_cache",
16579 + sizeof(struct vs_mapping), 0,
16580 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
16584 +__initcall(dmap_cache_init);
16587 +static inline unsigned int __hashval(dev_t dev, int bits)
16589 + return hash_long((unsigned long)dev, bits);
16593 +/* __hash_mapping()
16594 + * add the mapping to the hash table
16596 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
16598 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16599 + struct hlist_head *head, *hash = dmap_main_hash;
16600 + int device = vdm->device;
16602 + spin_lock(hash_lock);
16603 + vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
16604 + vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
16606 + head = &hash[__hashval(device, DMAP_HASH_BITS)];
16607 + hlist_add_head(&vdm->dm_hlist, head);
16608 + spin_unlock(hash_lock);
16612 +static inline int __mode_to_default(umode_t mode)
16625 +/* __set_default()
16628 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
16629 + struct vx_dmap_target *vdmt)
16631 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16632 + spin_lock(hash_lock);
16635 + vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
16637 + dmap_defaults[__mode_to_default(mode)] = *vdmt;
16640 + spin_unlock(hash_lock);
16642 + vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
16643 + vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
16647 +/* __remove_default()
16648 + * remove a default
16650 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
16652 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16653 + spin_lock(hash_lock);
16656 + vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
16657 + else /* remove == reset */
16658 + dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
16660 + spin_unlock(hash_lock);
16665 +/* __find_mapping()
16666 + * find a mapping in the hash table
16668 + * caller must hold hash_lock
16670 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
16671 + struct vs_mapping **local, struct vs_mapping **global)
16673 + struct hlist_head *hash = dmap_main_hash;
16674 + struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
16675 + struct hlist_node *pos;
16676 + struct vs_mapping *vdm;
16682 + hlist_for_each(pos, head) {
16683 + vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
16685 + if ((vdm->device == device) &&
16686 + !((vdm->target.flags ^ mode) & S_IFMT)) {
16687 + if (vdm->xid == xid) {
16690 + } else if (global && vdm->xid == 0)
16695 + if (global && *global)
16702 +/* __lookup_mapping()
16703 + * find a mapping and store the result in target and flags
16705 +static inline int __lookup_mapping(struct vx_info *vxi,
16706 + dev_t device, dev_t *target, int *flags, umode_t mode)
16708 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16709 + struct vs_mapping *vdm, *global;
16710 + struct vx_dmap_target *vdmt;
16712 + vxid_t xid = vxi->vx_id;
16715 + spin_lock(hash_lock);
16716 + if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
16718 + vdmt = &vdm->target;
16722 + index = __mode_to_default(mode);
16723 + if (vxi && vxi->dmap.targets[index].flags) {
16725 + vdmt = &vxi->dmap.targets[index];
16726 + } else if (global) {
16728 + vdmt = &global->target;
16732 + vdmt = &dmap_defaults[index];
16736 + if (target && (vdmt->flags & DATTR_REMAP))
16737 + *target = vdmt->target;
16739 + *target = device;
16741 + *flags = vdmt->flags;
16743 + spin_unlock(hash_lock);
16749 +/* __remove_mapping()
16750 + * remove a mapping from the hash table
16752 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
16755 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16756 + struct vs_mapping *vdm = NULL;
16759 + spin_lock(hash_lock);
16761 + ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
16763 + vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
16764 + vxi, vxi ? vxi->vx_id : 0, device, mode);
16767 + hlist_del(&vdm->dm_hlist);
16770 + spin_unlock(hash_lock);
16772 + kmem_cache_free(dmap_cachep, vdm);
16778 +int vs_map_device(struct vx_info *vxi,
16779 + dev_t device, dev_t *target, umode_t mode)
16781 + int ret, flags = DATTR_MASK;
16785 + *target = device;
16788 + ret = __lookup_mapping(vxi, device, target, &flags, mode);
16789 + vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
16790 + device, target ? *target : 0, flags, mode, ret);
16792 + return (flags & DATTR_MASK);
16797 +static int do_set_mapping(struct vx_info *vxi,
16798 + dev_t device, dev_t target, int flags, umode_t mode)
16801 + struct vs_mapping *new;
16803 + new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
16807 + INIT_HLIST_NODE(&new->dm_hlist);
16808 + new->device = device;
16809 + new->target.target = target;
16810 + new->target.flags = flags | mode;
16811 + new->xid = (vxi ? vxi->vx_id : 0);
16813 + vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
16814 + __hash_mapping(vxi, new);
16816 + struct vx_dmap_target new = {
16817 + .target = target,
16818 + .flags = flags | mode,
16820 + __set_default(vxi, mode, &new);
16826 +static int do_unset_mapping(struct vx_info *vxi,
16827 + dev_t device, dev_t target, int flags, umode_t mode)
16829 + int ret = -EINVAL;
16832 + ret = __remove_mapping(vxi, device, mode);
16836 + ret = __remove_default(vxi, mode);
16846 +static inline int __user_device(const char __user *name, dev_t *dev,
16849 + struct nameidata nd;
16856 + ret = user_lpath(name, &nd.path);
16859 + if (nd.path.dentry->d_inode) {
16860 + *dev = nd.path.dentry->d_inode->i_rdev;
16861 + *mode = nd.path.dentry->d_inode->i_mode;
16863 + path_put(&nd.path);
16867 +static inline int __mapping_mode(dev_t device, dev_t target,
16868 + umode_t device_mode, umode_t target_mode, umode_t *mode)
16871 + *mode = device_mode & S_IFMT;
16873 + *mode = target_mode & S_IFMT;
16877 + /* if both given, device and target mode have to match */
16878 + if (device && target &&
16879 + ((device_mode ^ target_mode) & S_IFMT))
16885 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
16886 + const char __user *target_path, int flags, int set)
16888 + dev_t device = ~0, target = ~0;
16889 + umode_t device_mode = 0, target_mode = 0, mode;
16892 + ret = __user_device(device_path, &device, &device_mode);
16895 + ret = __user_device(target_path, &target, &target_mode);
16899 + ret = __mapping_mode(device, target,
16900 + device_mode, target_mode, &mode);
16905 + return do_set_mapping(vxi, device, target,
16908 + return do_unset_mapping(vxi, device, target,
16913 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
16915 + struct vcmd_set_mapping_v0 vc_data;
16917 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16920 + return do_mapping(vxi, vc_data.device, vc_data.target,
16921 + vc_data.flags, 1);
16924 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
16926 + struct vcmd_set_mapping_v0 vc_data;
16928 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16931 + return do_mapping(vxi, vc_data.device, vc_data.target,
16932 + vc_data.flags, 0);
16936 +#ifdef CONFIG_COMPAT
16938 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
16940 + struct vcmd_set_mapping_v0_x32 vc_data;
16942 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16945 + return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16946 + compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
16949 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
16951 + struct vcmd_set_mapping_v0_x32 vc_data;
16953 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16956 + return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16957 + compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
16960 +#endif /* CONFIG_COMPAT */
16963 diff -NurpP --minimal linux-3.13.6/kernel/vserver/dlimit.c linux-3.13.6-vs2.3.6.11/kernel/vserver/dlimit.c
16964 --- linux-3.13.6/kernel/vserver/dlimit.c 1970-01-01 00:00:00.000000000 +0000
16965 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/dlimit.c 2014-01-31 20:38:04.000000000 +0000
16968 + * linux/kernel/vserver/dlimit.c
16970 + * Virtual Server: Context Disk Limits
16972 + * Copyright (C) 2004-2009 Herbert Pötzl
16974 + * V0.01 initial version
16975 + * V0.02 compat32 splitup
16976 + * V0.03 extended interface
16980 +#include <linux/statfs.h>
16981 +#include <linux/sched.h>
16982 +#include <linux/namei.h>
16983 +#include <linux/vs_tag.h>
16984 +#include <linux/vs_dlimit.h>
16985 +#include <linux/vserver/dlimit_cmd.h>
16986 +#include <linux/slab.h>
16987 +// #include <linux/gfp.h>
16989 +#include <asm/uaccess.h>
16991 +/* __alloc_dl_info()
16993 + * allocate an initialized dl_info struct
16994 + * doesn't make it visible (hash) */
16996 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
16998 + struct dl_info *new = NULL;
17000 + vxdprintk(VXD_CBIT(dlim, 5),
17001 + "alloc_dl_info(%p,%d)*", sb, tag);
17003 + /* would this benefit from a slab cache? */
17004 + new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17008 + memset(new, 0, sizeof(struct dl_info));
17009 + new->dl_tag = tag;
17011 + // INIT_RCU_HEAD(&new->dl_rcu);
17012 + INIT_HLIST_NODE(&new->dl_hlist);
17013 + spin_lock_init(&new->dl_lock);
17014 + atomic_set(&new->dl_refcnt, 0);
17015 + atomic_set(&new->dl_usecnt, 0);
17017 + /* rest of init goes here */
17019 + vxdprintk(VXD_CBIT(dlim, 4),
17020 + "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17024 +/* __dealloc_dl_info()
17026 + * final disposal of dl_info */
17028 +static void __dealloc_dl_info(struct dl_info *dli)
17030 + vxdprintk(VXD_CBIT(dlim, 4),
17031 + "dealloc_dl_info(%p)", dli);
17033 + dli->dl_hlist.next = LIST_POISON1;
17034 + dli->dl_tag = -1;
17037 + BUG_ON(atomic_read(&dli->dl_usecnt));
17038 + BUG_ON(atomic_read(&dli->dl_refcnt));
17044 +/* hash table for dl_info hash */
17046 +#define DL_HASH_SIZE 13
17048 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17050 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17053 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
17055 + return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17060 +/* __hash_dl_info()
17062 + * add the dli to the global hash table
17063 + * requires the hash_lock to be held */
17065 +static inline void __hash_dl_info(struct dl_info *dli)
17067 + struct hlist_head *head;
17069 + vxdprintk(VXD_CBIT(dlim, 6),
17070 + "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17071 + get_dl_info(dli);
17072 + head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17073 + hlist_add_head_rcu(&dli->dl_hlist, head);
17076 +/* __unhash_dl_info()
17078 + * remove the dli from the global hash table
17079 + * requires the hash_lock to be held */
17081 +static inline void __unhash_dl_info(struct dl_info *dli)
17083 + vxdprintk(VXD_CBIT(dlim, 6),
17084 + "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17085 + hlist_del_rcu(&dli->dl_hlist);
17086 + put_dl_info(dli);
17090 +/* __lookup_dl_info()
17092 + * requires the rcu_read_lock()
17093 + * doesn't increment the dl_refcnt */
17095 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
17097 + struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17098 + struct dl_info *dli;
17100 + hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17101 + if (dli->dl_tag == tag && dli->dl_sb == sb)
17108 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
17110 + struct dl_info *dli;
17113 + dli = get_dl_info(__lookup_dl_info(sb, tag));
17114 + vxdprintk(VXD_CBIT(dlim, 7),
17115 + "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17116 + rcu_read_unlock();
17120 +void rcu_free_dl_info(struct rcu_head *head)
17122 + struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17123 + int usecnt, refcnt;
17125 + BUG_ON(!dli || !head);
17127 + usecnt = atomic_read(&dli->dl_usecnt);
17128 + BUG_ON(usecnt < 0);
17130 + refcnt = atomic_read(&dli->dl_refcnt);
17131 + BUG_ON(refcnt < 0);
17133 + vxdprintk(VXD_CBIT(dlim, 3),
17134 + "rcu_free_dl_info(%p)", dli);
17136 + __dealloc_dl_info(dli);
17138 + printk("!!! rcu didn't free\n");
17144 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17145 + uint32_t flags, int add)
17147 + struct path path;
17150 + ret = user_lpath(name, &path);
17152 + struct super_block *sb;
17153 + struct dl_info *dli;
17156 + if (!path.dentry->d_inode)
17157 + goto out_release;
17158 + if (!(sb = path.dentry->d_inode->i_sb))
17159 + goto out_release;
17162 + dli = __alloc_dl_info(sb, id);
17163 + spin_lock(&dl_info_hash_lock);
17166 + if (__lookup_dl_info(sb, id))
17168 + __hash_dl_info(dli);
17171 + spin_lock(&dl_info_hash_lock);
17172 + dli = __lookup_dl_info(sb, id);
17177 + __unhash_dl_info(dli);
17181 + spin_unlock(&dl_info_hash_lock);
17183 + __dealloc_dl_info(dli);
17190 +int vc_add_dlimit(uint32_t id, void __user *data)
17192 + struct vcmd_ctx_dlimit_base_v0 vc_data;
17194 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17197 + return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17200 +int vc_rem_dlimit(uint32_t id, void __user *data)
17202 + struct vcmd_ctx_dlimit_base_v0 vc_data;
17204 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17207 + return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17210 +#ifdef CONFIG_COMPAT
17212 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17214 + struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17216 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17219 + return do_addrem_dlimit(id,
17220 + compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17223 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17225 + struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17227 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17230 + return do_addrem_dlimit(id,
17231 + compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17234 +#endif /* CONFIG_COMPAT */
17238 +int do_set_dlimit(uint32_t id, const char __user *name,
17239 + uint32_t space_used, uint32_t space_total,
17240 + uint32_t inodes_used, uint32_t inodes_total,
17241 + uint32_t reserved, uint32_t flags)
17243 + struct path path;
17246 + ret = user_lpath(name, &path);
17248 + struct super_block *sb;
17249 + struct dl_info *dli;
17252 + if (!path.dentry->d_inode)
17253 + goto out_release;
17254 + if (!(sb = path.dentry->d_inode->i_sb))
17255 + goto out_release;
17257 + /* sanity checks */
17258 + if ((reserved != CDLIM_KEEP &&
17259 + reserved > 100) ||
17260 + (inodes_used != CDLIM_KEEP &&
17261 + inodes_used > inodes_total) ||
17262 + (space_used != CDLIM_KEEP &&
17263 + space_used > space_total))
17264 + goto out_release;
17267 + dli = locate_dl_info(sb, id);
17269 + goto out_release;
17271 + spin_lock(&dli->dl_lock);
17273 + if (inodes_used != CDLIM_KEEP)
17274 + dli->dl_inodes_used = inodes_used;
17275 + if (inodes_total != CDLIM_KEEP)
17276 + dli->dl_inodes_total = inodes_total;
17277 + if (space_used != CDLIM_KEEP)
17278 + dli->dl_space_used = dlimit_space_32to64(
17279 + space_used, flags, DLIMS_USED);
17281 + if (space_total == CDLIM_INFINITY)
17282 + dli->dl_space_total = DLIM_INFINITY;
17283 + else if (space_total != CDLIM_KEEP)
17284 + dli->dl_space_total = dlimit_space_32to64(
17285 + space_total, flags, DLIMS_TOTAL);
17287 + if (reserved != CDLIM_KEEP)
17288 + dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17290 + spin_unlock(&dli->dl_lock);
17292 + put_dl_info(dli);
17301 +int vc_set_dlimit(uint32_t id, void __user *data)
17303 + struct vcmd_ctx_dlimit_v0 vc_data;
17305 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17308 + return do_set_dlimit(id, vc_data.name,
17309 + vc_data.space_used, vc_data.space_total,
17310 + vc_data.inodes_used, vc_data.inodes_total,
17311 + vc_data.reserved, vc_data.flags);
17314 +#ifdef CONFIG_COMPAT
17316 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17318 + struct vcmd_ctx_dlimit_v0_x32 vc_data;
17320 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17323 + return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17324 + vc_data.space_used, vc_data.space_total,
17325 + vc_data.inodes_used, vc_data.inodes_total,
17326 + vc_data.reserved, vc_data.flags);
17329 +#endif /* CONFIG_COMPAT */
17333 +int do_get_dlimit(uint32_t id, const char __user *name,
17334 + uint32_t *space_used, uint32_t *space_total,
17335 + uint32_t *inodes_used, uint32_t *inodes_total,
17336 + uint32_t *reserved, uint32_t *flags)
17338 + struct path path;
17341 + ret = user_lpath(name, &path);
17343 + struct super_block *sb;
17344 + struct dl_info *dli;
17347 + if (!path.dentry->d_inode)
17348 + goto out_release;
17349 + if (!(sb = path.dentry->d_inode->i_sb))
17350 + goto out_release;
17353 + dli = locate_dl_info(sb, id);
17355 + goto out_release;
17357 + spin_lock(&dli->dl_lock);
17358 + *inodes_used = dli->dl_inodes_used;
17359 + *inodes_total = dli->dl_inodes_total;
17361 + *space_used = dlimit_space_64to32(
17362 + dli->dl_space_used, flags, DLIMS_USED);
17364 + if (dli->dl_space_total == DLIM_INFINITY)
17365 + *space_total = CDLIM_INFINITY;
17367 + *space_total = dlimit_space_64to32(
17368 + dli->dl_space_total, flags, DLIMS_TOTAL);
17370 + *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
17371 + spin_unlock(&dli->dl_lock);
17373 + put_dl_info(dli);
17384 +int vc_get_dlimit(uint32_t id, void __user *data)
17386 + struct vcmd_ctx_dlimit_v0 vc_data;
17389 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17392 + ret = do_get_dlimit(id, vc_data.name,
17393 + &vc_data.space_used, &vc_data.space_total,
17394 + &vc_data.inodes_used, &vc_data.inodes_total,
17395 + &vc_data.reserved, &vc_data.flags);
17399 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17404 +#ifdef CONFIG_COMPAT
17406 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
17408 + struct vcmd_ctx_dlimit_v0_x32 vc_data;
17411 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17414 + ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
17415 + &vc_data.space_used, &vc_data.space_total,
17416 + &vc_data.inodes_used, &vc_data.inodes_total,
17417 + &vc_data.reserved, &vc_data.flags);
17421 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17426 +#endif /* CONFIG_COMPAT */
17429 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
17431 + struct dl_info *dli;
17432 + __u64 blimit, bfree, bavail;
17435 + dli = locate_dl_info(sb, dx_current_tag());
17439 + spin_lock(&dli->dl_lock);
17440 + if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
17443 + /* reduce max inodes available to limit */
17444 + if (buf->f_files > dli->dl_inodes_total)
17445 + buf->f_files = dli->dl_inodes_total;
17447 + ifree = dli->dl_inodes_total - dli->dl_inodes_used;
17448 + /* reduce free inodes to min */
17449 + if (ifree < buf->f_ffree)
17450 + buf->f_ffree = ifree;
17453 + if (dli->dl_space_total == DLIM_INFINITY)
17456 + blimit = dli->dl_space_total >> sb->s_blocksize_bits;
17458 + if (dli->dl_space_total < dli->dl_space_used)
17461 + bfree = (dli->dl_space_total - dli->dl_space_used)
17462 + >> sb->s_blocksize_bits;
17464 + bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
17465 + if (bavail < dli->dl_space_used)
17468 + bavail = (bavail - dli->dl_space_used)
17469 + >> sb->s_blocksize_bits;
17471 + /* reduce max space available to limit */
17472 + if (buf->f_blocks > blimit)
17473 + buf->f_blocks = blimit;
17475 + /* reduce free space to min */
17476 + if (bfree < buf->f_bfree)
17477 + buf->f_bfree = bfree;
17479 + /* reduce avail space to min */
17480 + if (bavail < buf->f_bavail)
17481 + buf->f_bavail = bavail;
17484 + spin_unlock(&dli->dl_lock);
17485 + put_dl_info(dli);
17490 +#include <linux/module.h>
17492 +EXPORT_SYMBOL_GPL(locate_dl_info);
17493 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
17495 diff -NurpP --minimal linux-3.13.6/kernel/vserver/helper.c linux-3.13.6-vs2.3.6.11/kernel/vserver/helper.c
17496 --- linux-3.13.6/kernel/vserver/helper.c 1970-01-01 00:00:00.000000000 +0000
17497 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/helper.c 2014-01-31 20:38:04.000000000 +0000
17500 + * linux/kernel/vserver/helper.c
17502 + * Virtual Context Support
17504 + * Copyright (C) 2004-2007 Herbert Pötzl
17506 + * V0.01 basic helper
17510 +#include <linux/kmod.h>
17511 +#include <linux/reboot.h>
17512 +#include <linux/vs_context.h>
17513 +#include <linux/vs_network.h>
17514 +#include <linux/vserver/signal.h>
17517 +char vshelper_path[255] = "/sbin/vshelper";
17519 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
17521 + current->flags &= ~PF_NO_SETAFFINITY;
17525 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
17527 + struct subprocess_info *info;
17528 + gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
17530 + info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
17531 + vshelper_init, NULL, NULL);
17532 + if (info == NULL)
17535 + return call_usermodehelper_exec(info, wait);
17538 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
17542 + if ((ret = vs_call_usermodehelper(name, argv, envp,
17543 + sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
17544 + printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
17545 + name, argv[1], argv[2],
17546 + sync ? "sync" : "async", ret);
17548 + vxdprintk(VXD_CBIT(switch, 4),
17549 + "%s: (%s %s) returned %s with %d",
17550 + name, argv[1], argv[2], sync ? "sync" : "async", ret);
17555 + * vshelper path is set via /proc/sys
17556 + * invoked by vserver sys_reboot(), with
17557 + * the following arguments
17559 + * argv [0] = vshelper_path;
17560 + * argv [1] = action: "restart", "halt", "poweroff", ...
17561 + * argv [2] = context identifier
17563 + * envp [*] = type-specific parameters
17566 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
17568 + char id_buf[8], cmd_buf[16];
17569 + char uid_buf[16], pid_buf[16];
17572 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
17573 + char *envp[] = {"HOME=/", "TERM=linux",
17574 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
17575 + uid_buf, pid_buf, cmd_buf, 0};
17577 + if (vx_info_state(vxi, VXS_HELPER))
17579 + vxi->vx_state |= VXS_HELPER;
17581 + snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17583 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17584 + snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
17585 + from_kuid(&init_user_ns, current_uid()));
17586 + snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
17589 + case LINUX_REBOOT_CMD_RESTART:
17590 + argv[1] = "restart";
17593 + case LINUX_REBOOT_CMD_HALT:
17594 + argv[1] = "halt";
17597 + case LINUX_REBOOT_CMD_POWER_OFF:
17598 + argv[1] = "poweroff";
17601 + case LINUX_REBOOT_CMD_SW_SUSPEND:
17602 + argv[1] = "swsusp";
17605 + case LINUX_REBOOT_CMD_OOM:
17610 + vxi->vx_state &= ~VXS_HELPER;
17614 + ret = do_vshelper(vshelper_path, argv, envp, 0);
17615 + vxi->vx_state &= ~VXS_HELPER;
17616 + __wakeup_vx_info(vxi);
17617 + return (ret) ? -EPERM : 0;
17621 +long vs_reboot(unsigned int cmd, void __user *arg)
17623 + struct vx_info *vxi = current_vx_info();
17626 + vxdprintk(VXD_CBIT(misc, 5),
17627 + "vs_reboot(%p[#%d],%u)",
17628 + vxi, vxi ? vxi->vx_id : 0, cmd);
17630 + ret = vs_reboot_helper(vxi, cmd, arg);
17634 + vxi->reboot_cmd = cmd;
17635 + if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17637 + case LINUX_REBOOT_CMD_RESTART:
17638 + case LINUX_REBOOT_CMD_HALT:
17639 + case LINUX_REBOOT_CMD_POWER_OFF:
17640 + vx_info_kill(vxi, 0, SIGKILL);
17641 + vx_info_kill(vxi, 1, SIGKILL);
17649 +long vs_oom_action(unsigned int cmd)
17651 + struct vx_info *vxi = current_vx_info();
17654 + vxdprintk(VXD_CBIT(misc, 5),
17655 + "vs_oom_action(%p[#%d],%u)",
17656 + vxi, vxi ? vxi->vx_id : 0, cmd);
17658 + ret = vs_reboot_helper(vxi, cmd, NULL);
17662 + vxi->reboot_cmd = cmd;
17663 + if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17664 + vx_info_kill(vxi, 0, SIGKILL);
17665 + vx_info_kill(vxi, 1, SIGKILL);
17671 + * argv [0] = vshelper_path;
17672 + * argv [1] = action: "startup", "shutdown"
17673 + * argv [2] = context identifier
17675 + * envp [*] = type-specific parameters
17678 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
17680 + char id_buf[8], cmd_buf[16];
17681 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
17682 + char *envp[] = {"HOME=/", "TERM=linux",
17683 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17685 + if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
17688 + snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17689 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17692 + case VSC_STARTUP:
17693 + argv[1] = "startup";
17695 + case VSC_SHUTDOWN:
17696 + argv[1] = "shutdown";
17702 + return do_vshelper(vshelper_path, argv, envp, 1);
17707 + * argv [0] = vshelper_path;
17708 + * argv [1] = action: "netup", "netdown"
17709 + * argv [2] = context identifier
17711 + * envp [*] = type-specific parameters
17714 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
17716 + char id_buf[8], cmd_buf[16];
17717 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
17718 + char *envp[] = {"HOME=/", "TERM=linux",
17719 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17721 + if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
17724 + snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
17725 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17729 + argv[1] = "netup";
17731 + case VSC_NETDOWN:
17732 + argv[1] = "netdown";
17738 + return do_vshelper(vshelper_path, argv, envp, 1);
17741 diff -NurpP --minimal linux-3.13.6/kernel/vserver/history.c linux-3.13.6-vs2.3.6.11/kernel/vserver/history.c
17742 --- linux-3.13.6/kernel/vserver/history.c 1970-01-01 00:00:00.000000000 +0000
17743 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/history.c 2014-01-31 20:38:04.000000000 +0000
17746 + * kernel/vserver/history.c
17748 + * Virtual Context History Backtrace
17750 + * Copyright (C) 2004-2007 Herbert Pötzl
17752 + * V0.01 basic structure
17753 + * V0.02 hash/unhash and trace
17754 + * V0.03 preemption fixes
17758 +#include <linux/module.h>
17759 +#include <asm/uaccess.h>
17761 +#include <linux/vserver/context.h>
17762 +#include <linux/vserver/debug.h>
17763 +#include <linux/vserver/debug_cmd.h>
17764 +#include <linux/vserver/history.h>
17767 +#ifdef CONFIG_VSERVER_HISTORY
17768 +#define VXH_SIZE CONFIG_VSERVER_HISTORY_SIZE
17770 +#define VXH_SIZE 64
17773 +struct _vx_history {
17774 + unsigned int counter;
17776 + struct _vx_hist_entry entry[VXH_SIZE + 1];
17780 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
17782 +unsigned volatile int vxh_active = 1;
17784 +static atomic_t sequence = ATOMIC_INIT(0);
17789 + * requires disabled preemption */
17791 +struct _vx_hist_entry *vxh_advance(void *loc)
17793 + unsigned int cpu = smp_processor_id();
17794 + struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17795 + struct _vx_hist_entry *entry;
17796 + unsigned int index;
17798 + index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
17799 + entry = &hist->entry[index];
17801 + entry->seq = atomic_inc_return(&sequence);
17802 + entry->loc = loc;
17806 +EXPORT_SYMBOL_GPL(vxh_advance);
17809 +#define VXH_LOC_FMTS "(#%04x,*%d):%p"
17811 +#define VXH_LOC_ARGS(e) (e)->seq, cpu, (e)->loc
17814 +#define VXH_VXI_FMTS "%p[#%d,%d.%d]"
17816 +#define VXH_VXI_ARGS(e) (e)->vxi.ptr, \
17817 + (e)->vxi.ptr ? (e)->vxi.xid : 0, \
17818 + (e)->vxi.ptr ? (e)->vxi.usecnt : 0, \
17819 + (e)->vxi.ptr ? (e)->vxi.tasks : 0
17821 +void vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
17823 + switch (e->type) {
17824 + case VXH_THROW_OOPS:
17825 + printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
17828 + case VXH_GET_VX_INFO:
17829 + case VXH_PUT_VX_INFO:
17830 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17832 + (e->type == VXH_GET_VX_INFO) ? "get" : "put",
17833 + VXH_VXI_ARGS(e));
17836 + case VXH_INIT_VX_INFO:
17837 + case VXH_SET_VX_INFO:
17838 + case VXH_CLR_VX_INFO:
17839 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17841 + (e->type == VXH_INIT_VX_INFO) ? "init" :
17842 + ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
17843 + VXH_VXI_ARGS(e), e->sc.data);
17846 + case VXH_CLAIM_VX_INFO:
17847 + case VXH_RELEASE_VX_INFO:
17848 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17850 + (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
17851 + VXH_VXI_ARGS(e), e->sc.data);
17854 + case VXH_ALLOC_VX_INFO:
17855 + case VXH_DEALLOC_VX_INFO:
17856 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17858 + (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
17859 + VXH_VXI_ARGS(e));
17862 + case VXH_HASH_VX_INFO:
17863 + case VXH_UNHASH_VX_INFO:
17864 + printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
17866 + (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
17867 + VXH_VXI_ARGS(e));
17870 + case VXH_LOC_VX_INFO:
17871 + case VXH_LOOKUP_VX_INFO:
17872 + case VXH_CREATE_VX_INFO:
17873 + printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
17875 + (e->type == VXH_CREATE_VX_INFO) ? "create" :
17876 + ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
17877 + e->ll.arg, VXH_VXI_ARGS(e));
17882 +static void __vxh_dump_history(void)
17884 + unsigned int i, cpu;
17886 + printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
17887 + atomic_read(&sequence), NR_CPUS);
17889 + for (i = 0; i < VXH_SIZE; i++) {
17890 + for_each_online_cpu(cpu) {
17891 + struct _vx_history *hist =
17892 + &per_cpu(vx_history_buffer, cpu);
17893 + unsigned int index = (hist->counter - i) % VXH_SIZE;
17894 + struct _vx_hist_entry *entry = &hist->entry[index];
17896 + vxh_dump_entry(entry, cpu);
17901 +void vxh_dump_history(void)
17905 + local_irq_enable();
17907 + local_irq_disable();
17909 + __vxh_dump_history();
17913 +/* vserver syscall commands below here */
17916 +int vc_dump_history(uint32_t id)
17919 + __vxh_dump_history();
17926 +int do_read_history(struct __user _vx_hist_entry *data,
17927 + int cpu, uint32_t *index, uint32_t *count)
17929 + int pos, ret = 0;
17930 + struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17931 + int end = hist->counter;
17932 + int start = end - VXH_SIZE + 2;
17933 + int idx = *index;
17935 + /* special case: get current pos */
17941 + /* have we lost some data? */
17945 + for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
17946 + struct _vx_hist_entry *entry =
17947 + &hist->entry[idx % VXH_SIZE];
17949 + /* send entry to userspace */
17950 + ret = copy_to_user(&data[pos], entry, sizeof(*entry));
17954 + /* save new index and count */
17957 + return ret ? ret : (*index < end);
17960 +int vc_read_history(uint32_t id, void __user *data)
17962 + struct vcmd_read_history_v0 vc_data;
17965 + if (id >= NR_CPUS)
17968 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17971 + ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
17972 + id, &vc_data.index, &vc_data.count);
17974 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17979 +#ifdef CONFIG_COMPAT
17981 +int vc_read_history_x32(uint32_t id, void __user *data)
17983 + struct vcmd_read_history_v0_x32 vc_data;
17986 + if (id >= NR_CPUS)
17989 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17992 + ret = do_read_history((struct __user _vx_hist_entry *)
17993 + compat_ptr(vc_data.data_ptr),
17994 + id, &vc_data.index, &vc_data.count);
17996 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18001 +#endif /* CONFIG_COMPAT */
18003 diff -NurpP --minimal linux-3.13.6/kernel/vserver/inet.c linux-3.13.6-vs2.3.6.11/kernel/vserver/inet.c
18004 --- linux-3.13.6/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
18005 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/inet.c 2014-02-01 00:26:40.000000000 +0000
18008 +#include <linux/in.h>
18009 +#include <linux/inetdevice.h>
18010 +#include <linux/export.h>
18011 +#include <linux/vs_inet.h>
18012 +#include <linux/vs_inet6.h>
18013 +#include <linux/vserver/debug.h>
18014 +#include <net/route.h>
18015 +#include <net/addrconf.h>
18018 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18022 + if (!nxi1 || !nxi2 || nxi1 == nxi2)
18025 + struct nx_addr_v4 *ptr;
18026 + unsigned long irqflags;
18028 + spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18029 + for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18030 + if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18035 + spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18038 + vxdprintk(VXD_CBIT(net, 2),
18039 + "nx_v4_addr_conflict(%p,%p): %d",
18040 + nxi1, nxi2, ret);
18046 +#ifdef CONFIG_IPV6
18048 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18052 + if (!nxi1 || !nxi2 || nxi1 == nxi2)
18055 + struct nx_addr_v6 *ptr;
18056 + unsigned long irqflags;
18058 + spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18059 + for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18060 + if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18065 + spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18068 + vxdprintk(VXD_CBIT(net, 2),
18069 + "nx_v6_addr_conflict(%p,%p): %d",
18070 + nxi1, nxi2, ret);
18077 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18079 + struct in_device *in_dev;
18080 + struct in_ifaddr **ifap;
18081 + struct in_ifaddr *ifa;
18086 + in_dev = in_dev_get(dev);
18090 + for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18091 + ifap = &ifa->ifa_next) {
18092 + if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18097 + in_dev_put(in_dev);
18103 +#ifdef CONFIG_IPV6
18105 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18107 + struct inet6_dev *in_dev;
18108 + struct inet6_ifaddr *ifa;
18113 + in_dev = in6_dev_get(dev);
18117 + // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18118 + list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18119 + if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18124 + in6_dev_put(in_dev);
18131 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18137 + if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18139 +#ifdef CONFIG_IPV6
18141 + if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18146 + vxdprintk(VXD_CBIT(net, 3),
18147 + "dev_in_nx_info(%p,%p[#%d]) = %d",
18148 + dev, nxi, nxi ? nxi->nx_id : 0, ret);
18152 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18153 + struct flowi4 *fl4)
18155 + struct rtable *rt;
18160 + /* FIXME: handle lback only case */
18161 + if (!NX_IPV4(nxi))
18162 + return ERR_PTR(-EPERM);
18164 + vxdprintk(VXD_CBIT(net, 4),
18165 + "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18166 + nxi, nxi ? nxi->nx_id : 0,
18167 + NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18169 + /* single IP is unconditional */
18170 + if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18171 + (fl4->saddr == INADDR_ANY))
18172 + fl4->saddr = nxi->v4.ip[0].s_addr;
18174 + if (fl4->saddr == INADDR_ANY) {
18175 + struct nx_addr_v4 *ptr;
18176 + __be32 found = 0;
18178 + rt = __ip_route_output_key(net, fl4);
18179 + if (!IS_ERR(rt)) {
18180 + found = fl4->saddr;
18182 + vxdprintk(VXD_CBIT(net, 4),
18183 + "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18184 + nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18185 + if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18189 + WARN_ON_ONCE(in_irq());
18190 + spin_lock_bh(&nxi->addr_lock);
18191 + for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18192 + __be32 primary = ptr->ip[0].s_addr;
18193 + __be32 mask = ptr->mask.s_addr;
18194 + __be32 neta = primary & mask;
18196 + vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18197 + NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18198 + nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18199 + NIPQUAD(mask), NIPQUAD(neta));
18200 + if ((found & mask) != neta)
18203 + fl4->saddr = primary;
18204 + rt = __ip_route_output_key(net, fl4);
18205 + vxdprintk(VXD_CBIT(net, 4),
18206 + "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18207 + nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18208 + if (!IS_ERR(rt)) {
18209 + found = fl4->saddr;
18211 + if (found == primary)
18212 + goto found_unlock;
18215 + /* still no source ip? */
18216 + found = ipv4_is_loopback(fl4->daddr)
18217 + ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18219 + spin_unlock_bh(&nxi->addr_lock);
18221 + /* assign src ip to flow */
18222 + fl4->saddr = found;
18225 + if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18226 + return ERR_PTR(-EPERM);
18229 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18230 + if (ipv4_is_loopback(fl4->daddr))
18231 + fl4->daddr = nxi->v4_lback.s_addr;
18232 + if (ipv4_is_loopback(fl4->saddr))
18233 + fl4->saddr = nxi->v4_lback.s_addr;
18234 + } else if (ipv4_is_loopback(fl4->daddr) &&
18235 + !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18236 + return ERR_PTR(-EPERM);
18241 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18243 diff -NurpP --minimal linux-3.13.6/kernel/vserver/init.c linux-3.13.6-vs2.3.6.11/kernel/vserver/init.c
18244 --- linux-3.13.6/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
18245 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/init.c 2014-01-31 20:38:04.000000000 +0000
18248 + * linux/kernel/init.c
18250 + * Virtual Server Init
18252 + * Copyright (C) 2004-2007 Herbert Pötzl
18254 + * V0.01 basic structure
18258 +#include <linux/init.h>
18260 +int vserver_register_sysctl(void);
18261 +void vserver_unregister_sysctl(void);
18264 +static int __init init_vserver(void)
18268 +#ifdef CONFIG_VSERVER_DEBUG
18269 + vserver_register_sysctl();
18275 +static void __exit exit_vserver(void)
18278 +#ifdef CONFIG_VSERVER_DEBUG
18279 + vserver_unregister_sysctl();
18284 +/* FIXME: GFP_ZONETYPES gone
18285 +long vx_slab[GFP_ZONETYPES]; */
18289 +module_init(init_vserver);
18290 +module_exit(exit_vserver);
18292 diff -NurpP --minimal linux-3.13.6/kernel/vserver/inode.c linux-3.13.6-vs2.3.6.11/kernel/vserver/inode.c
18293 --- linux-3.13.6/kernel/vserver/inode.c 1970-01-01 00:00:00.000000000 +0000
18294 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/inode.c 2014-01-31 20:38:04.000000000 +0000
18297 + * linux/kernel/vserver/inode.c
18299 + * Virtual Server: File System Support
18301 + * Copyright (C) 2004-2007 Herbert Pötzl
18303 + * V0.01 separated from vcontext V0.05
18304 + * V0.02 moved to tag (instead of xid)
18308 +#include <linux/tty.h>
18309 +#include <linux/proc_fs.h>
18310 +#include <linux/devpts_fs.h>
18311 +#include <linux/fs.h>
18312 +#include <linux/file.h>
18313 +#include <linux/mount.h>
18314 +#include <linux/parser.h>
18315 +#include <linux/namei.h>
18316 +#include <linux/magic.h>
18317 +#include <linux/slab.h>
18318 +#include <linux/vserver/inode.h>
18319 +#include <linux/vserver/inode_cmd.h>
18320 +#include <linux/vs_base.h>
18321 +#include <linux/vs_tag.h>
18323 +#include <asm/uaccess.h>
18324 +#include <../../fs/proc/internal.h>
18327 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18329 + struct proc_dir_entry *entry;
18331 + if (!in || !in->i_sb)
18334 + *flags = IATTR_TAG
18335 + | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18336 + | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18337 + | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18338 + | (IS_COW(in) ? IATTR_COW : 0);
18339 + *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18341 + if (S_ISDIR(in->i_mode))
18342 + *mask |= IATTR_BARRIER;
18344 + if (IS_TAGGED(in)) {
18345 + *tag = i_tag_read(in);
18346 + *mask |= IATTR_TAG;
18349 + switch (in->i_sb->s_magic) {
18350 + case PROC_SUPER_MAGIC:
18351 + entry = PROC_I(in)->pde;
18353 + /* check for specific inodes? */
18355 + *mask |= IATTR_FLAGS;
18357 + *flags |= (entry->vx_flags & IATTR_FLAGS);
18359 + *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
18362 + case DEVPTS_SUPER_MAGIC:
18363 + *tag = i_tag_read(in);
18364 + *mask |= IATTR_TAG;
18373 +int vc_get_iattr(void __user *data)
18375 + struct path path;
18376 + struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
18379 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18382 + ret = user_lpath(vc_data.name, &path);
18384 + ret = __vc_get_iattr(path.dentry->d_inode,
18385 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18391 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18396 +#ifdef CONFIG_COMPAT
18398 +int vc_get_iattr_x32(void __user *data)
18400 + struct path path;
18401 + struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
18404 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18407 + ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18409 + ret = __vc_get_iattr(path.dentry->d_inode,
18410 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18416 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18421 +#endif /* CONFIG_COMPAT */
18424 +int vc_fget_iattr(uint32_t fd, void __user *data)
18426 + struct file *filp;
18427 + struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
18430 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18434 + if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18437 + ret = __vc_get_iattr(filp->f_dentry->d_inode,
18438 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18442 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18448 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18450 + struct inode *in = de->d_inode;
18451 + int error = 0, is_proc = 0, has_tag = 0;
18452 + struct iattr attr = { 0 };
18454 + if (!in || !in->i_sb)
18457 + is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
18458 + if ((*mask & IATTR_FLAGS) && !is_proc)
18461 + has_tag = IS_TAGGED(in) ||
18462 + (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
18463 + if ((*mask & IATTR_TAG) && !has_tag)
18466 + mutex_lock(&in->i_mutex);
18467 + if (*mask & IATTR_TAG) {
18468 + attr.ia_tag = make_ktag(&init_user_ns, *tag);
18469 + attr.ia_valid |= ATTR_TAG;
18472 + if (*mask & IATTR_FLAGS) {
18473 + struct proc_dir_entry *entry = PROC_I(in)->pde;
18474 + unsigned int iflags = PROC_I(in)->vx_flags;
18476 + iflags = (iflags & ~(*mask & IATTR_FLAGS))
18477 + | (*flags & IATTR_FLAGS);
18478 + PROC_I(in)->vx_flags = iflags;
18480 + entry->vx_flags = iflags;
18483 + if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
18484 + IATTR_BARRIER | IATTR_COW)) {
18485 + int iflags = in->i_flags;
18486 + int vflags = in->i_vflags;
18488 + if (*mask & IATTR_IMMUTABLE) {
18489 + if (*flags & IATTR_IMMUTABLE)
18490 + iflags |= S_IMMUTABLE;
18492 + iflags &= ~S_IMMUTABLE;
18494 + if (*mask & IATTR_IXUNLINK) {
18495 + if (*flags & IATTR_IXUNLINK)
18496 + iflags |= S_IXUNLINK;
18498 + iflags &= ~S_IXUNLINK;
18500 + if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
18501 + if (*flags & IATTR_BARRIER)
18502 + vflags |= V_BARRIER;
18504 + vflags &= ~V_BARRIER;
18506 + if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
18507 + if (*flags & IATTR_COW)
18510 + vflags &= ~V_COW;
18512 + if (in->i_op && in->i_op->sync_flags) {
18513 + error = in->i_op->sync_flags(in, iflags, vflags);
18519 + if (attr.ia_valid) {
18520 + if (in->i_op && in->i_op->setattr)
18521 + error = in->i_op->setattr(de, &attr);
18523 + error = inode_change_ok(in, &attr);
18525 + setattr_copy(in, &attr);
18526 + mark_inode_dirty(in);
18532 + mutex_unlock(&in->i_mutex);
18536 +int vc_set_iattr(void __user *data)
18538 + struct path path;
18539 + struct vcmd_ctx_iattr_v1 vc_data;
18542 + if (!capable(CAP_LINUX_IMMUTABLE))
18544 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18547 + ret = user_lpath(vc_data.name, &path);
18549 + ret = __vc_set_iattr(path.dentry,
18550 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18554 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18559 +#ifdef CONFIG_COMPAT
18561 +int vc_set_iattr_x32(void __user *data)
18563 + struct path path;
18564 + struct vcmd_ctx_iattr_v1_x32 vc_data;
18567 + if (!capable(CAP_LINUX_IMMUTABLE))
18569 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18572 + ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18574 + ret = __vc_set_iattr(path.dentry,
18575 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18579 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18584 +#endif /* CONFIG_COMPAT */
18586 +int vc_fset_iattr(uint32_t fd, void __user *data)
18588 + struct file *filp;
18589 + struct vcmd_ctx_fiattr_v0 vc_data;
18592 + if (!capable(CAP_LINUX_IMMUTABLE))
18594 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18598 + if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18601 + ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
18602 + &vc_data.flags, &vc_data.mask);
18606 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18612 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
18614 +static match_table_t tokens = {
18615 + {Opt_notagcheck, "notagcheck"},
18616 +#ifdef CONFIG_PROPAGATE
18617 + {Opt_notag, "notag"},
18618 + {Opt_tag, "tag"},
18619 + {Opt_tagid, "tagid=%u"},
18625 +static void __dx_parse_remove(char *string, char *opt)
18627 + char *p = strstr(string, opt);
18631 + while (*q != '\0' && *q != ',')
18640 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
18641 + unsigned long *flags)
18644 + substring_t args[MAX_OPT_ARGS];
18646 + char *s, *p, *opts;
18647 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
18653 + s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
18658 + while ((p = strsep(&opts, ",")) != NULL) {
18659 + token = match_token(p, tokens, args);
18662 +#ifdef CONFIG_PROPAGATE
18667 + __dx_parse_remove(s, "tag");
18668 + *mnt_flags |= MNT_TAGID;
18669 + set |= MNT_TAGID;
18673 + __dx_parse_remove(s, "notag");
18674 + *mnt_flags |= MNT_NOTAG;
18675 + set |= MNT_NOTAG;
18678 + if (tag && !match_int(args, &option))
18681 + __dx_parse_remove(s, "tagid");
18682 + *mnt_flags |= MNT_TAGID;
18683 + set |= MNT_TAGID;
18685 +#endif /* CONFIG_PROPAGATE */
18686 + case Opt_notagcheck:
18688 + __dx_parse_remove(s, "notagcheck");
18689 + *flags |= MS_NOTAGCHECK;
18690 + set |= MS_NOTAGCHECK;
18693 + vxdprintk(VXD_CBIT(tag, 7),
18694 + "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
18695 + p, token, option);
18698 + strcpy(string, s);
18703 +#ifdef CONFIG_PROPAGATE
18705 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
18707 + vtag_t new_tag = 0;
18708 + struct vfsmount *mnt;
18713 + mnt = nd->path.mnt;
18717 + propagate = (mnt->mnt_flags & MNT_TAGID);
18719 + new_tag = mnt->mnt_tag;
18721 + vxdprintk(VXD_CBIT(tag, 7),
18722 + "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
18723 + inode, inode->i_ino, inode->i_tag,
18724 + new_tag, (propagate) ? 1 : 0);
18727 + i_tag_write(inode, new_tag);
18730 +#include <linux/module.h>
18732 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
18734 +#endif /* CONFIG_PROPAGATE */
18736 diff -NurpP --minimal linux-3.13.6/kernel/vserver/limit.c linux-3.13.6-vs2.3.6.11/kernel/vserver/limit.c
18737 --- linux-3.13.6/kernel/vserver/limit.c 1970-01-01 00:00:00.000000000 +0000
18738 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/limit.c 2014-02-01 00:22:08.000000000 +0000
18741 + * linux/kernel/vserver/limit.c
18743 + * Virtual Server: Context Limits
18745 + * Copyright (C) 2004-2010 Herbert Pötzl
18747 + * V0.01 broken out from vcontext V0.05
18748 + * V0.02 changed vcmds to vxi arg
18749 + * V0.03 added memory cgroup support
18753 +#include <linux/sched.h>
18754 +#include <linux/module.h>
18755 +#include <linux/memcontrol.h>
18756 +#include <linux/res_counter.h>
18757 +#include <linux/vs_limit.h>
18758 +#include <linux/vserver/limit.h>
18759 +#include <linux/vserver/limit_cmd.h>
18761 +#include <asm/uaccess.h>
18764 +const char *vlimit_name[NUM_LIMITS] = {
18765 + [RLIMIT_CPU] = "CPU",
18766 + [RLIMIT_NPROC] = "NPROC",
18767 + [RLIMIT_NOFILE] = "NOFILE",
18768 + [RLIMIT_LOCKS] = "LOCKS",
18769 + [RLIMIT_SIGPENDING] = "SIGP",
18770 + [RLIMIT_MSGQUEUE] = "MSGQ",
18772 + [VLIMIT_NSOCK] = "NSOCK",
18773 + [VLIMIT_OPENFD] = "OPENFD",
18774 + [VLIMIT_SHMEM] = "SHMEM",
18775 + [VLIMIT_DENTRY] = "DENTRY",
18778 +EXPORT_SYMBOL_GPL(vlimit_name);
18780 +#define MASK_ENTRY(x) (1 << (x))
18782 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
18785 + , /* softlimit */
18788 + MASK_ENTRY( RLIMIT_NPROC ) |
18789 + MASK_ENTRY( RLIMIT_NOFILE ) |
18790 + MASK_ENTRY( RLIMIT_LOCKS ) |
18791 + MASK_ENTRY( RLIMIT_MSGQUEUE ) |
18793 + MASK_ENTRY( VLIMIT_NSOCK ) |
18794 + MASK_ENTRY( VLIMIT_OPENFD ) |
18795 + MASK_ENTRY( VLIMIT_SHMEM ) |
18796 + MASK_ENTRY( VLIMIT_DENTRY ) |
18799 + /* accounting only */
18800 +uint32_t account_mask =
18801 + MASK_ENTRY( VLIMIT_SEMARY ) |
18802 + MASK_ENTRY( VLIMIT_NSEMS ) |
18803 + MASK_ENTRY( VLIMIT_MAPPED ) |
18807 +static int is_valid_vlimit(int id)
18809 + uint32_t mask = vlimit_mask.minimum |
18810 + vlimit_mask.softlimit | vlimit_mask.maximum;
18811 + return mask & (1 << id);
18814 +static int is_accounted_vlimit(int id)
18816 + if (is_valid_vlimit(id))
18818 + return account_mask & (1 << id);
18822 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
18824 + rlim_t limit = __rlim_soft(&vxi->limit, id);
18825 + return VX_VLIM(limit);
18828 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
18830 + rlim_t limit = __rlim_hard(&vxi->limit, id);
18831 + return VX_VLIM(limit);
18834 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
18835 + uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
18837 + if (!is_valid_vlimit(id))
18841 + *minimum = CRLIM_UNSET;
18843 + *softlimit = vc_get_soft(vxi, id);
18845 + *maximum = vc_get_hard(vxi, id);
18849 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
18851 + struct vcmd_ctx_rlimit_v0 vc_data;
18854 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18857 + ret = do_get_rlimit(vxi, vc_data.id,
18858 + &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18862 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18867 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
18868 + uint64_t minimum, uint64_t softlimit, uint64_t maximum)
18870 + if (!is_valid_vlimit(id))
18873 + if (maximum != CRLIM_KEEP)
18874 + __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
18875 + if (softlimit != CRLIM_KEEP)
18876 + __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
18878 + /* clamp soft limit */
18879 + if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
18880 + __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
18885 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
18887 + struct vcmd_ctx_rlimit_v0 vc_data;
18889 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18892 + return do_set_rlimit(vxi, vc_data.id,
18893 + vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18896 +#ifdef CONFIG_IA32_EMULATION
18898 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
18900 + struct vcmd_ctx_rlimit_v0_x32 vc_data;
18902 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18905 + return do_set_rlimit(vxi, vc_data.id,
18906 + vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18909 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
18911 + struct vcmd_ctx_rlimit_v0_x32 vc_data;
18914 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18917 + ret = do_get_rlimit(vxi, vc_data.id,
18918 + &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18922 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18927 +#endif /* CONFIG_IA32_EMULATION */
18930 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
18932 + if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
18938 +static inline void vx_reset_hits(struct _vx_limit *limit)
18942 + for (lim = 0; lim < NUM_LIMITS; lim++) {
18943 + atomic_set(&__rlim_lhit(limit, lim), 0);
18947 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
18949 + vx_reset_hits(&vxi->limit);
18953 +static inline void vx_reset_minmax(struct _vx_limit *limit)
18958 + for (lim = 0; lim < NUM_LIMITS; lim++) {
18959 + value = __rlim_get(limit, lim);
18960 + __rlim_rmax(limit, lim) = value;
18961 + __rlim_rmin(limit, lim) = value;
18965 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
18967 + vx_reset_minmax(&vxi->limit);
18972 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
18974 + struct vcmd_rlimit_stat_v0 vc_data;
18975 + struct _vx_limit *limit = &vxi->limit;
18978 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18982 + if (!is_accounted_vlimit(id))
18985 + vx_limit_fixup(limit, id);
18986 + vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
18987 + vc_data.value = __rlim_get(limit, id);
18988 + vc_data.minimum = __rlim_rmin(limit, id);
18989 + vc_data.maximum = __rlim_rmax(limit, id);
18991 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18997 +void vx_vsi_meminfo(struct sysinfo *val)
18999 +#ifdef CONFIG_MEMCG
19000 + struct mem_cgroup *mcg;
19001 + u64 res_limit, res_usage;
19004 + mcg = mem_cgroup_from_task(current);
19005 + rcu_read_unlock();
19009 + res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19010 + res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19012 + if (res_limit != RES_COUNTER_MAX)
19013 + val->totalram = (res_limit >> PAGE_SHIFT);
19014 + val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19015 + val->bufferram = 0;
19016 + val->totalhigh = 0;
19017 + val->freehigh = 0;
19019 +#endif /* CONFIG_MEMCG */
19023 +void vx_vsi_swapinfo(struct sysinfo *val)
19025 +#ifdef CONFIG_MEMCG
19026 +#ifdef CONFIG_MEMCG_SWAP
19027 + struct mem_cgroup *mcg;
19028 + u64 res_limit, res_usage, memsw_limit, memsw_usage;
19029 + s64 swap_limit, swap_usage;
19032 + mcg = mem_cgroup_from_task(current);
19033 + rcu_read_unlock();
19037 + res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19038 + res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19039 + memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19040 + memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19042 + /* memory unlimited */
19043 + if (res_limit == RES_COUNTER_MAX)
19046 + swap_limit = memsw_limit - res_limit;
19047 + /* we have a swap limit? */
19048 + if (memsw_limit != RES_COUNTER_MAX)
19049 + val->totalswap = swap_limit >> PAGE_SHIFT;
19051 + /* calculate swap part */
19052 + swap_usage = (memsw_usage > res_usage) ?
19053 + memsw_usage - res_usage : 0;
19055 + /* total shown minus usage gives free swap */
19056 + val->freeswap = (swap_usage < swap_limit) ?
19057 + val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19059 +#else /* !CONFIG_MEMCG_SWAP */
19060 + val->totalswap = 0;
19061 + val->freeswap = 0;
19062 +#endif /* !CONFIG_MEMCG_SWAP */
19063 +#endif /* CONFIG_MEMCG */
19067 +long vx_vsi_cached(struct sysinfo *val)
19070 +#ifdef CONFIG_MEMCG
19071 + struct mem_cgroup *mcg;
19074 + mcg = mem_cgroup_from_task(current);
19075 + rcu_read_unlock();
19079 + cache = mem_cgroup_stat_read_cache(mcg);
19085 diff -NurpP --minimal linux-3.13.6/kernel/vserver/limit_init.h linux-3.13.6-vs2.3.6.11/kernel/vserver/limit_init.h
19086 --- linux-3.13.6/kernel/vserver/limit_init.h 1970-01-01 00:00:00.000000000 +0000
19087 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/limit_init.h 2014-01-31 20:38:04.000000000 +0000
19091 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19095 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19096 + __rlim_soft(limit, lim) = RLIM_INFINITY;
19097 + __rlim_hard(limit, lim) = RLIM_INFINITY;
19098 + __rlim_set(limit, lim, 0);
19099 + atomic_set(&__rlim_lhit(limit, lim), 0);
19100 + __rlim_rmin(limit, lim) = 0;
19101 + __rlim_rmax(limit, lim) = 0;
19105 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19110 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19111 + if ((1 << lim) & VLIM_NOCHECK)
19113 + value = __rlim_get(limit, lim);
19114 + vxwprintk_xid(value,
19115 + "!!! limit: %p[%s,%d] = %ld on exit.",
19116 + limit, vlimit_name[lim], lim, (long)value);
19120 diff -NurpP --minimal linux-3.13.6/kernel/vserver/limit_proc.h linux-3.13.6-vs2.3.6.11/kernel/vserver/limit_proc.h
19121 --- linux-3.13.6/kernel/vserver/limit_proc.h 1970-01-01 00:00:00.000000000 +0000
19122 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/limit_proc.h 2014-01-31 20:38:04.000000000 +0000
19124 +#ifndef _VX_LIMIT_PROC_H
19125 +#define _VX_LIMIT_PROC_H
19127 +#include <linux/vserver/limit_int.h>
19130 +#define VX_LIMIT_FMT ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19131 +#define VX_LIMIT_TOP \
19132 + "Limit\t current\t min/max\t\t soft/hard\t\thits\n"
19134 +#define VX_LIMIT_ARG(r) \
19135 + (unsigned long)__rlim_get(limit, r), \
19136 + (unsigned long)__rlim_rmin(limit, r), \
19137 + (unsigned long)__rlim_rmax(limit, r), \
19138 + VX_VLIM(__rlim_soft(limit, r)), \
19139 + VX_VLIM(__rlim_hard(limit, r)), \
19140 + atomic_read(&__rlim_lhit(limit, r))
19142 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19144 + vx_limit_fixup(limit, -1);
19145 + return sprintf(buffer, VX_LIMIT_TOP
19146 + "PROC" VX_LIMIT_FMT
19147 + "VM" VX_LIMIT_FMT
19148 + "VML" VX_LIMIT_FMT
19149 + "RSS" VX_LIMIT_FMT
19150 + "ANON" VX_LIMIT_FMT
19151 + "RMAP" VX_LIMIT_FMT
19152 + "FILES" VX_LIMIT_FMT
19153 + "OFD" VX_LIMIT_FMT
19154 + "LOCKS" VX_LIMIT_FMT
19155 + "SOCK" VX_LIMIT_FMT
19156 + "MSGQ" VX_LIMIT_FMT
19157 + "SHM" VX_LIMIT_FMT
19158 + "SEMA" VX_LIMIT_FMT
19159 + "SEMS" VX_LIMIT_FMT
19160 + "DENT" VX_LIMIT_FMT,
19161 + VX_LIMIT_ARG(RLIMIT_NPROC),
19162 + VX_LIMIT_ARG(RLIMIT_AS),
19163 + VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19164 + VX_LIMIT_ARG(RLIMIT_RSS),
19165 + VX_LIMIT_ARG(VLIMIT_ANON),
19166 + VX_LIMIT_ARG(VLIMIT_MAPPED),
19167 + VX_LIMIT_ARG(RLIMIT_NOFILE),
19168 + VX_LIMIT_ARG(VLIMIT_OPENFD),
19169 + VX_LIMIT_ARG(RLIMIT_LOCKS),
19170 + VX_LIMIT_ARG(VLIMIT_NSOCK),
19171 + VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19172 + VX_LIMIT_ARG(VLIMIT_SHMEM),
19173 + VX_LIMIT_ARG(VLIMIT_SEMARY),
19174 + VX_LIMIT_ARG(VLIMIT_NSEMS),
19175 + VX_LIMIT_ARG(VLIMIT_DENTRY));
19178 +#endif /* _VX_LIMIT_PROC_H */
19181 diff -NurpP --minimal linux-3.13.6/kernel/vserver/network.c linux-3.13.6-vs2.3.6.11/kernel/vserver/network.c
19182 --- linux-3.13.6/kernel/vserver/network.c 1970-01-01 00:00:00.000000000 +0000
19183 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/network.c 2014-01-31 20:38:04.000000000 +0000
19186 + * linux/kernel/vserver/network.c
19188 + * Virtual Server: Network Support
19190 + * Copyright (C) 2003-2007 Herbert Pötzl
19192 + * V0.01 broken out from vcontext V0.05
19193 + * V0.02 cleaned up implementation
19194 + * V0.03 added equiv nx commands
19195 + * V0.04 switch to RCU based hash
19196 + * V0.05 and back to locking again
19197 + * V0.06 changed vcmds to nxi arg
19198 + * V0.07 have __create claim() the nxi
19202 +#include <linux/err.h>
19203 +#include <linux/slab.h>
19204 +#include <linux/rcupdate.h>
19205 +#include <net/ipv6.h>
19207 +#include <linux/vs_network.h>
19208 +#include <linux/vs_pid.h>
19209 +#include <linux/vserver/network_cmd.h>
19212 +atomic_t nx_global_ctotal = ATOMIC_INIT(0);
19213 +atomic_t nx_global_cactive = ATOMIC_INIT(0);
19215 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19216 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19219 +static int __init init_network(void)
19221 + nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19222 + sizeof(struct nx_addr_v4), 0,
19223 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19224 + nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19225 + sizeof(struct nx_addr_v6), 0,
19226 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19231 +/* __alloc_nx_addr_v4() */
19233 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19235 + struct nx_addr_v4 *nxa = kmem_cache_alloc(
19236 + nx_addr_v4_cachep, GFP_KERNEL);
19238 + if (!IS_ERR(nxa))
19239 + memset(nxa, 0, sizeof(*nxa));
19243 +/* __dealloc_nx_addr_v4() */
19245 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19247 + kmem_cache_free(nx_addr_v4_cachep, nxa);
19250 +/* __dealloc_nx_addr_v4_all() */
19252 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19255 + struct nx_addr_v4 *next = nxa->next;
19257 + __dealloc_nx_addr_v4(nxa);
19263 +#ifdef CONFIG_IPV6
19265 +/* __alloc_nx_addr_v6() */
19267 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19269 + struct nx_addr_v6 *nxa = kmem_cache_alloc(
19270 + nx_addr_v6_cachep, GFP_KERNEL);
19272 + if (!IS_ERR(nxa))
19273 + memset(nxa, 0, sizeof(*nxa));
19277 +/* __dealloc_nx_addr_v6() */
19279 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19281 + kmem_cache_free(nx_addr_v6_cachep, nxa);
19284 +/* __dealloc_nx_addr_v6_all() */
19286 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19289 + struct nx_addr_v6 *next = nxa->next;
19291 + __dealloc_nx_addr_v6(nxa);
19296 +#endif /* CONFIG_IPV6 */
19298 +/* __alloc_nx_info()
19300 + * allocate an initialized nx_info struct
19301 + * doesn't make it visible (hash) */
19303 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19305 + struct nx_info *new = NULL;
19307 + vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19309 + /* would this benefit from a slab cache? */
19310 + new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19314 + memset(new, 0, sizeof(struct nx_info));
19315 + new->nx_id = nid;
19316 + INIT_HLIST_NODE(&new->nx_hlist);
19317 + atomic_set(&new->nx_usecnt, 0);
19318 + atomic_set(&new->nx_tasks, 0);
19319 + spin_lock_init(&new->addr_lock);
19320 + new->nx_state = 0;
19322 + new->nx_flags = NXF_INIT_SET;
19324 + /* rest of init goes here */
19326 + new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19327 + new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19329 + vxdprintk(VXD_CBIT(nid, 0),
19330 + "alloc_nx_info(%d) = %p", nid, new);
19331 + atomic_inc(&nx_global_ctotal);
19335 +/* __dealloc_nx_info()
19337 + * final disposal of nx_info */
19339 +static void __dealloc_nx_info(struct nx_info *nxi)
19341 + vxdprintk(VXD_CBIT(nid, 0),
19342 + "dealloc_nx_info(%p)", nxi);
19344 + nxi->nx_hlist.next = LIST_POISON1;
19347 + BUG_ON(atomic_read(&nxi->nx_usecnt));
19348 + BUG_ON(atomic_read(&nxi->nx_tasks));
19350 + __dealloc_nx_addr_v4_all(nxi->v4.next);
19351 +#ifdef CONFIG_IPV6
19352 + __dealloc_nx_addr_v6_all(nxi->v6.next);
19355 + nxi->nx_state |= NXS_RELEASED;
19357 + atomic_dec(&nx_global_ctotal);
19360 +static void __shutdown_nx_info(struct nx_info *nxi)
19362 + nxi->nx_state |= NXS_SHUTDOWN;
19363 + vs_net_change(nxi, VSC_NETDOWN);
19366 +/* exported stuff */
19368 +void free_nx_info(struct nx_info *nxi)
19370 + /* context shutdown is mandatory */
19371 + BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
19373 + /* context must not be hashed */
19374 + BUG_ON(nxi->nx_state & NXS_HASHED);
19376 + BUG_ON(atomic_read(&nxi->nx_usecnt));
19377 + BUG_ON(atomic_read(&nxi->nx_tasks));
19379 + __dealloc_nx_info(nxi);
19383 +void __nx_set_lback(struct nx_info *nxi)
19385 + int nid = nxi->nx_id;
19386 + __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
19388 + nxi->v4_lback.s_addr = lback;
19391 +extern int __nx_inet_add_lback(__be32 addr);
19392 +extern int __nx_inet_del_lback(__be32 addr);
19395 +/* hash table for nx_info hash */
19397 +#define NX_HASH_SIZE 13
19399 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
19401 +static DEFINE_SPINLOCK(nx_info_hash_lock);
19404 +static inline unsigned int __hashval(vnid_t nid)
19406 + return (nid % NX_HASH_SIZE);
19411 +/* __hash_nx_info()
19413 + * add the nxi to the global hash table
19414 + * requires the hash_lock to be held */
19416 +static inline void __hash_nx_info(struct nx_info *nxi)
19418 + struct hlist_head *head;
19420 + vxd_assert_lock(&nx_info_hash_lock);
19421 + vxdprintk(VXD_CBIT(nid, 4),
19422 + "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
19424 + /* context must not be hashed */
19425 + BUG_ON(nx_info_state(nxi, NXS_HASHED));
19427 + nxi->nx_state |= NXS_HASHED;
19428 + head = &nx_info_hash[__hashval(nxi->nx_id)];
19429 + hlist_add_head(&nxi->nx_hlist, head);
19430 + atomic_inc(&nx_global_cactive);
19433 +/* __unhash_nx_info()
19435 + * remove the nxi from the global hash table
19436 + * requires the hash_lock to be held */
19438 +static inline void __unhash_nx_info(struct nx_info *nxi)
19440 + vxd_assert_lock(&nx_info_hash_lock);
19441 + vxdprintk(VXD_CBIT(nid, 4),
19442 + "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
19443 + atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
19445 + /* context must be hashed */
19446 + BUG_ON(!nx_info_state(nxi, NXS_HASHED));
19447 + /* but without tasks */
19448 + BUG_ON(atomic_read(&nxi->nx_tasks));
19450 + nxi->nx_state &= ~NXS_HASHED;
19451 + hlist_del(&nxi->nx_hlist);
19452 + atomic_dec(&nx_global_cactive);
19456 +/* __lookup_nx_info()
19458 + * requires the hash_lock to be held
19459 + * doesn't increment the nx_refcnt */
19461 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
19463 + struct hlist_head *head = &nx_info_hash[__hashval(nid)];
19464 + struct hlist_node *pos;
19465 + struct nx_info *nxi;
19467 + vxd_assert_lock(&nx_info_hash_lock);
19468 + hlist_for_each(pos, head) {
19469 + nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19471 + if (nxi->nx_id == nid)
19476 + vxdprintk(VXD_CBIT(nid, 0),
19477 + "__lookup_nx_info(#%u): %p[#%u]",
19478 + nid, nxi, nxi ? nxi->nx_id : 0);
19483 +/* __create_nx_info()
19485 + * create the requested context
19486 + * get(), claim() and hash it */
19488 +static struct nx_info *__create_nx_info(int id)
19490 + struct nx_info *new, *nxi = NULL;
19492 + vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
19494 + if (!(new = __alloc_nx_info(id)))
19495 + return ERR_PTR(-ENOMEM);
19497 + /* required to make dynamic xids unique */
19498 + spin_lock(&nx_info_hash_lock);
19500 + /* static context requested */
19501 + if ((nxi = __lookup_nx_info(id))) {
19502 + vxdprintk(VXD_CBIT(nid, 0),
19503 + "create_nx_info(%d) = %p (already there)", id, nxi);
19504 + if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19505 + nxi = ERR_PTR(-EBUSY);
19507 + nxi = ERR_PTR(-EEXIST);
19510 + /* new context */
19511 + vxdprintk(VXD_CBIT(nid, 0),
19512 + "create_nx_info(%d) = %p (new)", id, new);
19513 + claim_nx_info(new, NULL);
19514 + __nx_set_lback(new);
19515 + __hash_nx_info(get_nx_info(new));
19516 + nxi = new, new = NULL;
19519 + spin_unlock(&nx_info_hash_lock);
19521 + __dealloc_nx_info(new);
19527 +/* exported stuff */
19530 +void unhash_nx_info(struct nx_info *nxi)
19532 + __shutdown_nx_info(nxi);
19533 + spin_lock(&nx_info_hash_lock);
19534 + __unhash_nx_info(nxi);
19535 + spin_unlock(&nx_info_hash_lock);
19538 +/* lookup_nx_info()
19540 + * search for a nx_info and get() it
19541 + * negative id means current */
19543 +struct nx_info *lookup_nx_info(int id)
19545 + struct nx_info *nxi = NULL;
19548 + nxi = get_nx_info(current_nx_info());
19549 + } else if (id > 1) {
19550 + spin_lock(&nx_info_hash_lock);
19551 + nxi = get_nx_info(__lookup_nx_info(id));
19552 + spin_unlock(&nx_info_hash_lock);
19557 +/* nid_is_hashed()
19559 + * verify that nid is still hashed */
19561 +int nid_is_hashed(vnid_t nid)
19565 + spin_lock(&nx_info_hash_lock);
19566 + hashed = (__lookup_nx_info(nid) != NULL);
19567 + spin_unlock(&nx_info_hash_lock);
19572 +#ifdef CONFIG_PROC_FS
19576 + * get a subset of hashed nids for proc
19577 + * assumes size is at least one */
19579 +int get_nid_list(int index, unsigned int *nids, int size)
19581 + int hindex, nr_nids = 0;
19583 + /* only show current and children */
19584 + if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
19587 + nids[nr_nids] = nx_current_nid();
19591 + for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
19592 + struct hlist_head *head = &nx_info_hash[hindex];
19593 + struct hlist_node *pos;
19595 + spin_lock(&nx_info_hash_lock);
19596 + hlist_for_each(pos, head) {
19597 + struct nx_info *nxi;
19602 + nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19603 + nids[nr_nids] = nxi->nx_id;
19604 + if (++nr_nids >= size) {
19605 + spin_unlock(&nx_info_hash_lock);
19609 + /* keep the lock time short */
19610 + spin_unlock(&nx_info_hash_lock);
19619 + * migrate task to new network
19620 + * gets nxi, puts old_nxi on change
19623 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
19625 + struct nx_info *old_nxi;
19631 + vxdprintk(VXD_CBIT(nid, 5),
19632 + "nx_migrate_task(%p,%p[#%d.%d.%d])",
19633 + p, nxi, nxi->nx_id,
19634 + atomic_read(&nxi->nx_usecnt),
19635 + atomic_read(&nxi->nx_tasks));
19637 + if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
19638 + !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19641 + if (nx_info_state(nxi, NXS_SHUTDOWN))
19644 + /* maybe disallow this completely? */
19645 + old_nxi = task_get_nx_info(p);
19646 + if (old_nxi == nxi)
19651 + clr_nx_info(&p->nx_info);
19652 + claim_nx_info(nxi, p);
19653 + set_nx_info(&p->nx_info, nxi);
19654 + p->nid = nxi->nx_id;
19657 + vxdprintk(VXD_CBIT(nid, 5),
19658 + "moved task %p into nxi:%p[#%d]",
19659 + p, nxi, nxi->nx_id);
19662 + release_nx_info(old_nxi, p);
19665 + put_nx_info(old_nxi);
19670 +void nx_set_persistent(struct nx_info *nxi)
19672 + vxdprintk(VXD_CBIT(nid, 6),
19673 + "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
19675 + get_nx_info(nxi);
19676 + claim_nx_info(nxi, NULL);
19679 +void nx_clear_persistent(struct nx_info *nxi)
19681 + vxdprintk(VXD_CBIT(nid, 6),
19682 + "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
19684 + release_nx_info(nxi, NULL);
19685 + put_nx_info(nxi);
19688 +void nx_update_persistent(struct nx_info *nxi)
19690 + if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
19691 + nx_set_persistent(nxi);
19693 + nx_clear_persistent(nxi);
19696 +/* vserver syscall commands below here */
19698 +/* taks nid and nx_info functions */
19700 +#include <asm/uaccess.h>
19703 +int vc_task_nid(uint32_t id)
19708 + struct task_struct *tsk;
19711 + tsk = find_task_by_real_pid(id);
19712 + nid = (tsk) ? tsk->nid : -ESRCH;
19713 + rcu_read_unlock();
19715 + nid = nx_current_nid();
19720 +int vc_nx_info(struct nx_info *nxi, void __user *data)
19722 + struct vcmd_nx_info_v0 vc_data;
19724 + vc_data.nid = nxi->nx_id;
19726 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19732 +/* network functions */
19734 +int vc_net_create(uint32_t nid, void __user *data)
19736 + struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
19737 + struct nx_info *new_nxi;
19740 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19743 + if ((nid > MAX_S_CONTEXT) || (nid < 2))
19746 + new_nxi = __create_nx_info(nid);
19747 + if (IS_ERR(new_nxi))
19748 + return PTR_ERR(new_nxi);
19750 + /* initial flags */
19751 + new_nxi->nx_flags = vc_data.flagword;
19754 + if (vs_net_change(new_nxi, VSC_NETUP))
19757 + ret = nx_migrate_task(current, new_nxi);
19761 + /* return context id on success */
19762 + ret = new_nxi->nx_id;
19764 + /* get a reference for persistent contexts */
19765 + if ((vc_data.flagword & NXF_PERSISTENT))
19766 + nx_set_persistent(new_nxi);
19768 + release_nx_info(new_nxi, NULL);
19769 + put_nx_info(new_nxi);
19774 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
19776 + return nx_migrate_task(current, nxi);
19781 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
19782 + __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
19783 + struct nx_addr_v4 **prev)
19785 + struct nx_addr_v4 *nxa = &nxi->v4;
19787 + for (; nxa; nxa = nxa->next) {
19788 + if ((nxa->ip[0].s_addr == ip) &&
19789 + (nxa->ip[1].s_addr == ip2) &&
19790 + (nxa->mask.s_addr == mask) &&
19791 + (nxa->type == type) &&
19792 + (nxa->flags == flags))
19795 + /* save previous entry */
19802 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19803 + uint16_t type, uint16_t flags)
19805 + struct nx_addr_v4 *nxa = NULL;
19806 + struct nx_addr_v4 *new = __alloc_nx_addr_v4();
19807 + unsigned long irqflags;
19808 + int ret = -EEXIST;
19811 + return PTR_ERR(new);
19813 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
19814 + if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
19817 + if (NX_IPV4(nxi)) {
19822 + /* remove single ip for ip list */
19823 + nxi->nx_flags &= ~NXF_SINGLE_IP;
19826 + nxa->ip[0].s_addr = ip;
19827 + nxa->ip[1].s_addr = ip2;
19828 + nxa->mask.s_addr = mask;
19829 + nxa->type = type;
19830 + nxa->flags = flags;
19833 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19835 + __dealloc_nx_addr_v4(new);
19839 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19840 + uint16_t type, uint16_t flags)
19842 + struct nx_addr_v4 *nxa = NULL;
19843 + struct nx_addr_v4 *old = NULL;
19844 + unsigned long irqflags;
19847 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
19849 + case NXA_TYPE_ADDR:
19850 + old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
19853 + nxa->next = old->next;
19854 + old->next = NULL;
19860 + old->next = NULL;
19862 + memset(old, 0, sizeof(*old));
19870 + case NXA_TYPE_ANY:
19873 + memset(nxa, 0, sizeof(*nxa));
19879 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19880 + __dealloc_nx_addr_v4_all(old);
19885 +int vc_net_add(struct nx_info *nxi, void __user *data)
19887 + struct vcmd_net_addr_v0 vc_data;
19888 + int index, ret = 0;
19890 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19893 + switch (vc_data.type) {
19894 + case NXA_TYPE_IPV4:
19895 + if ((vc_data.count < 1) || (vc_data.count > 4))
19899 + while (index < vc_data.count) {
19900 + ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
19901 + vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
19909 + case NXA_TYPE_IPV4|NXA_MOD_BCAST:
19910 + nxi->v4_bcast = vc_data.ip[0];
19914 + case NXA_TYPE_IPV4|NXA_MOD_LBACK:
19915 + nxi->v4_lback = vc_data.ip[0];
19926 +int vc_net_remove(struct nx_info *nxi, void __user *data)
19928 + struct vcmd_net_addr_v0 vc_data;
19930 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19933 + switch (vc_data.type) {
19934 + case NXA_TYPE_ANY:
19935 + return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
19943 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
19945 + struct vcmd_net_addr_ipv4_v1 vc_data;
19947 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19950 + switch (vc_data.type) {
19951 + case NXA_TYPE_ADDR:
19952 + case NXA_TYPE_MASK:
19953 + return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
19954 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19956 + case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19957 + nxi->v4_bcast = vc_data.ip;
19960 + case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19961 + nxi->v4_lback = vc_data.ip;
19970 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
19972 + struct vcmd_net_addr_ipv4_v2 vc_data;
19974 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19977 + switch (vc_data.type) {
19978 + case NXA_TYPE_ADDR:
19979 + case NXA_TYPE_MASK:
19980 + case NXA_TYPE_RANGE:
19981 + return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19982 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19984 + case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19985 + nxi->v4_bcast = vc_data.ip;
19988 + case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19989 + nxi->v4_lback = vc_data.ip;
19998 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20000 + struct vcmd_net_addr_ipv4_v1 vc_data;
20002 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20005 + return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20006 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20009 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20011 + struct vcmd_net_addr_ipv4_v2 vc_data;
20013 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20016 + return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20017 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20020 +#ifdef CONFIG_IPV6
20023 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20024 + struct in6_addr *ip, struct in6_addr *mask,
20025 + uint32_t prefix, uint16_t type, uint16_t flags,
20026 + struct nx_addr_v6 **prev)
20028 + struct nx_addr_v6 *nxa = &nxi->v6;
20030 + for (; nxa; nxa = nxa->next) {
20031 + if (ipv6_addr_equal(&nxa->ip, ip) &&
20032 + ipv6_addr_equal(&nxa->mask, mask) &&
20033 + (nxa->prefix == prefix) &&
20034 + (nxa->type == type) &&
20035 + (nxa->flags == flags))
20038 + /* save previous entry */
20046 +int do_add_v6_addr(struct nx_info *nxi,
20047 + struct in6_addr *ip, struct in6_addr *mask,
20048 + uint32_t prefix, uint16_t type, uint16_t flags)
20050 + struct nx_addr_v6 *nxa = NULL;
20051 + struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20052 + unsigned long irqflags;
20053 + int ret = -EEXIST;
20056 + return PTR_ERR(new);
20058 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20059 + if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20062 + if (NX_IPV6(nxi)) {
20069 + nxa->mask = *mask;
20070 + nxa->prefix = prefix;
20071 + nxa->type = type;
20072 + nxa->flags = flags;
20075 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20077 + __dealloc_nx_addr_v6(new);
20081 +int do_remove_v6_addr(struct nx_info *nxi,
20082 + struct in6_addr *ip, struct in6_addr *mask,
20083 + uint32_t prefix, uint16_t type, uint16_t flags)
20085 + struct nx_addr_v6 *nxa = NULL;
20086 + struct nx_addr_v6 *old = NULL;
20087 + unsigned long irqflags;
20090 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20092 + case NXA_TYPE_ADDR:
20093 + old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20096 + nxa->next = old->next;
20097 + old->next = NULL;
20103 + old->next = NULL;
20105 + memset(old, 0, sizeof(*old));
20113 + case NXA_TYPE_ANY:
20116 + memset(nxa, 0, sizeof(*nxa));
20122 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20123 + __dealloc_nx_addr_v6_all(old);
20127 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20129 + struct vcmd_net_addr_ipv6_v1 vc_data;
20131 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20134 + switch (vc_data.type) {
20135 + case NXA_TYPE_ADDR:
20136 + memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20137 + /* fallthrough */
20138 + case NXA_TYPE_MASK:
20139 + return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20140 + vc_data.prefix, vc_data.type, vc_data.flags);
20147 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20149 + struct vcmd_net_addr_ipv6_v1 vc_data;
20151 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20154 + switch (vc_data.type) {
20155 + case NXA_TYPE_ADDR:
20156 + memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20157 + /* fallthrough */
20158 + case NXA_TYPE_MASK:
20159 + return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20160 + vc_data.prefix, vc_data.type, vc_data.flags);
20161 + case NXA_TYPE_ANY:
20162 + return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20169 +#endif /* CONFIG_IPV6 */
20172 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20174 + struct vcmd_net_flags_v0 vc_data;
20176 + vc_data.flagword = nxi->nx_flags;
20178 + /* special STATE flag handling */
20179 + vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20181 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20186 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20188 + struct vcmd_net_flags_v0 vc_data;
20189 + uint64_t mask, trigger;
20191 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20194 + /* special STATE flag handling */
20195 + mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20196 + trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20198 + nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20199 + vc_data.flagword, mask);
20200 + if (trigger & NXF_PERSISTENT)
20201 + nx_update_persistent(nxi);
20206 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20208 + struct vcmd_net_caps_v0 vc_data;
20210 + vc_data.ncaps = nxi->nx_ncaps;
20211 + vc_data.cmask = ~0ULL;
20213 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20218 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20220 + struct vcmd_net_caps_v0 vc_data;
20222 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20225 + nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20226 + vc_data.ncaps, vc_data.cmask);
20231 +#include <linux/module.h>
20233 +module_init(init_network);
20235 +EXPORT_SYMBOL_GPL(free_nx_info);
20236 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20238 diff -NurpP --minimal linux-3.13.6/kernel/vserver/proc.c linux-3.13.6-vs2.3.6.11/kernel/vserver/proc.c
20239 --- linux-3.13.6/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
20240 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/proc.c 2014-02-01 01:21:49.000000000 +0000
20243 + * linux/kernel/vserver/proc.c
20245 + * Virtual Context Support
20247 + * Copyright (C) 2003-2011 Herbert Pötzl
20249 + * V0.01 basic structure
20250 + * V0.02 adaptation vs1.3.0
20251 + * V0.03 proc permissions
20252 + * V0.04 locking/generic
20253 + * V0.05 next generation procfs
20254 + * V0.06 inode validation
20255 + * V0.07 generic rewrite vid
20256 + * V0.08 remove inode type
20257 + * V0.09 added u/wmask info
20261 +#include <linux/proc_fs.h>
20262 +#include <linux/fs_struct.h>
20263 +#include <linux/mount.h>
20264 +#include <linux/namei.h>
20265 +#include <asm/unistd.h>
20267 +#include <linux/vs_context.h>
20268 +#include <linux/vs_network.h>
20269 +#include <linux/vs_cvirt.h>
20271 +#include <linux/in.h>
20272 +#include <linux/inetdevice.h>
20273 +#include <linux/vs_inet.h>
20274 +#include <linux/vs_inet6.h>
20276 +#include <linux/vserver/global.h>
20278 +#include "cvirt_proc.h"
20279 +#include "cacct_proc.h"
20280 +#include "limit_proc.h"
20281 +#include "sched_proc.h"
20282 +#include "vci_config.h"
20284 +#include <../../fs/proc/internal.h>
20287 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20291 + CAP_FOR_EACH_U32(__capi) {
20292 + buffer += sprintf(buffer, "%08x",
20293 + c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20299 +static struct proc_dir_entry *proc_virtual;
20301 +static struct proc_dir_entry *proc_virtnet;
20304 +/* first the actual feeds */
20307 +static int proc_vci(char *buffer)
20309 + return sprintf(buffer,
20310 + "VCIVersion:\t%04x:%04x\n"
20311 + "VCISyscall:\t%d\n"
20312 + "VCIKernel:\t%08x\n",
20313 + VCI_VERSION >> 16,
20314 + VCI_VERSION & 0xFFFF,
20316 + vci_kernel_config());
20319 +static int proc_virtual_info(char *buffer)
20321 + return proc_vci(buffer);
20324 +static int proc_virtual_status(char *buffer)
20326 + return sprintf(buffer,
20328 + "#CActive:\t%d\n"
20329 + "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20330 + "#InitTask:\t%d\t%d %d\n",
20331 + atomic_read(&vx_global_ctotal),
20332 + atomic_read(&vx_global_cactive),
20333 + atomic_read(&vs_global_nsproxy),
20334 + atomic_read(&vs_global_fs),
20335 + atomic_read(&vs_global_mnt_ns),
20336 + atomic_read(&vs_global_uts_ns),
20337 + atomic_read(&nr_ipc_ns),
20338 + atomic_read(&vs_global_user_ns),
20339 + atomic_read(&vs_global_pid_ns),
20340 + atomic_read(&init_task.usage),
20341 + atomic_read(&init_task.nsproxy->count),
20342 + init_task.fs->users);
20346 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20350 + length = sprintf(buffer,
20358 + vxi->vx_badness_bias);
20362 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
20364 + char *orig = buffer;
20366 + buffer += sprintf(buffer,
20369 + "Flags:\t%016llx\n",
20370 + atomic_read(&vxi->vx_usecnt),
20371 + atomic_read(&vxi->vx_tasks),
20372 + (unsigned long long)vxi->vx_flags);
20374 + buffer += sprintf(buffer, "BCaps:\t");
20375 + buffer = print_cap_t(buffer, &vxi->vx_bcaps);
20376 + buffer += sprintf(buffer, "\n");
20378 + buffer += sprintf(buffer,
20379 + "CCaps:\t%016llx\n"
20380 + "Umask:\t%16llx\n"
20381 + "Wmask:\t%16llx\n"
20382 + "Spaces:\t%08lx %08lx\n",
20383 + (unsigned long long)vxi->vx_ccaps,
20384 + (unsigned long long)vxi->vx_umask,
20385 + (unsigned long long)vxi->vx_wmask,
20386 + vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
20387 + return buffer - orig;
20390 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
20392 + return vx_info_proc_limit(&vxi->limit, buffer);
20395 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
20399 + length = vx_info_proc_sched(&vxi->sched, buffer);
20400 + for_each_online_cpu(cpu) {
20401 + length += vx_info_proc_sched_pc(
20402 + &vx_per_cpu(vxi, sched_pc, cpu),
20403 + buffer + length, cpu);
20408 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
20410 + return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
20413 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
20415 + return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
20418 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
20422 + vx_update_load(vxi);
20423 + length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
20424 + for_each_online_cpu(cpu) {
20425 + length += vx_info_proc_cvirt_pc(
20426 + &vx_per_cpu(vxi, cvirt_pc, cpu),
20427 + buffer + length, cpu);
20432 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
20434 + return vx_info_proc_cacct(&vxi->cacct, buffer);
20438 +static int proc_virtnet_info(char *buffer)
20440 + return proc_vci(buffer);
20443 +static int proc_virtnet_status(char *buffer)
20445 + return sprintf(buffer,
20447 + "#CActive:\t%d\n",
20448 + atomic_read(&nx_global_ctotal),
20449 + atomic_read(&nx_global_cactive));
20452 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
20454 + struct nx_addr_v4 *v4a;
20455 +#ifdef CONFIG_IPV6
20456 + struct nx_addr_v6 *v6a;
20460 + length = sprintf(buffer,
20463 + "Bcast:\t" NIPQUAD_FMT "\n"
20464 + "Lback:\t" NIPQUAD_FMT "\n",
20467 + NIPQUAD(nxi->v4_bcast.s_addr),
20468 + NIPQUAD(nxi->v4_lback.s_addr));
20470 + if (!NX_IPV4(nxi))
20472 + for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20473 + length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
20476 +#ifdef CONFIG_IPV6
20477 + if (!NX_IPV6(nxi))
20479 + for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20480 + length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
20487 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
20491 + length = sprintf(buffer,
20494 + "Flags:\t%016llx\n"
20495 + "NCaps:\t%016llx\n",
20496 + atomic_read(&nxi->nx_usecnt),
20497 + atomic_read(&nxi->nx_tasks),
20498 + (unsigned long long)nxi->nx_flags,
20499 + (unsigned long long)nxi->nx_ncaps);
20505 +/* here the inode helpers */
20511 + struct inode_operations *iop;
20512 + struct file_operations *fop;
20513 + union proc_op op;
20516 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
20518 + struct inode *inode = new_inode(sb);
20523 + inode->i_mode = p->mode;
20525 + inode->i_op = p->iop;
20527 + inode->i_fop = p->fop;
20529 + set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
20530 + inode->i_flags |= S_IMMUTABLE;
20532 + inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
20534 + i_uid_write(inode, 0);
20535 + i_gid_write(inode, 0);
20536 + i_tag_write(inode, 0);
20541 +static struct dentry *vs_proc_instantiate(struct inode *dir,
20542 + struct dentry *dentry, int id, void *ptr)
20544 + struct vs_entry *p = ptr;
20545 + struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
20546 + struct dentry *error = ERR_PTR(-EINVAL);
20551 + PROC_I(inode)->op = p->op;
20552 + PROC_I(inode)->fd = id;
20553 + d_add(dentry, inode);
20561 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
20565 + * Fill a directory entry.
20567 + * If possible create the dcache entry and derive our inode number and
20568 + * file type from dcache entry.
20570 + * Since all of the proc inode numbers are dynamically generated, the inode
20571 + * numbers do not exist until the inode is cache. This means creating the
20572 + * the dcache entry in iterate is necessary to keep the inode numbers
20573 + * reported by iterate in sync with the inode numbers reported
20576 +static int vx_proc_fill_cache(struct file *filp, struct dir_context *ctx,
20577 + char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
20579 + struct dentry *child, *dir = filp->f_dentry;
20580 + struct inode *inode;
20581 + struct qstr qname;
20583 + unsigned type = DT_UNKNOWN;
20585 + qname.name = name;
20587 + qname.hash = full_name_hash(name, len);
20589 + child = d_lookup(dir, &qname);
20591 + struct dentry *new;
20592 + new = d_alloc(dir, &qname);
20594 + child = instantiate(dir->d_inode, new, id, ptr);
20601 + if (!child || IS_ERR(child) || !child->d_inode)
20602 + goto end_instantiate;
20603 + inode = child->d_inode;
20605 + ino = inode->i_ino;
20606 + type = inode->i_mode >> 12;
20612 + return !dir_emit(ctx, name, len, ino, type);
20617 +/* get and revalidate vx_info/xid */
20620 +struct vx_info *get_proc_vx_info(struct inode *inode)
20622 + return lookup_vx_info(PROC_I(inode)->fd);
20625 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
20627 + struct inode *inode = dentry->d_inode;
20628 + vxid_t xid = PROC_I(inode)->fd;
20630 + if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20633 + if (!xid || xid_is_hashed(xid))
20640 +/* get and revalidate nx_info/nid */
20642 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
20644 + struct inode *inode = dentry->d_inode;
20645 + vnid_t nid = PROC_I(inode)->fd;
20647 + if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20650 + if (!nid || nid_is_hashed(nid))
20658 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
20660 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
20661 + size_t count, loff_t *ppos)
20663 + struct inode *inode = file->f_dentry->d_inode;
20664 + unsigned long page;
20665 + ssize_t length = 0;
20667 + if (count > PROC_BLOCK_SIZE)
20668 + count = PROC_BLOCK_SIZE;
20670 + /* fade that out as soon as stable */
20671 + WARN_ON(PROC_I(inode)->fd);
20673 + if (!(page = __get_free_page(GFP_KERNEL)))
20676 + BUG_ON(!PROC_I(inode)->op.proc_vs_read);
20677 + length = PROC_I(inode)->op.proc_vs_read((char *)page);
20680 + length = simple_read_from_buffer(buf, count, ppos,
20681 + (char *)page, length);
20687 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
20688 + size_t count, loff_t *ppos)
20690 + struct inode *inode = file->f_dentry->d_inode;
20691 + struct vx_info *vxi = NULL;
20692 + vxid_t xid = PROC_I(inode)->fd;
20693 + unsigned long page;
20694 + ssize_t length = 0;
20696 + if (count > PROC_BLOCK_SIZE)
20697 + count = PROC_BLOCK_SIZE;
20699 + /* fade that out as soon as stable */
20701 + vxi = lookup_vx_info(xid);
20705 + length = -ENOMEM;
20706 + if (!(page = __get_free_page(GFP_KERNEL)))
20709 + BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
20710 + length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
20713 + length = simple_read_from_buffer(buf, count, ppos,
20714 + (char *)page, length);
20718 + put_vx_info(vxi);
20723 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
20724 + size_t count, loff_t *ppos)
20726 + struct inode *inode = file->f_dentry->d_inode;
20727 + struct nx_info *nxi = NULL;
20728 + vnid_t nid = PROC_I(inode)->fd;
20729 + unsigned long page;
20730 + ssize_t length = 0;
20732 + if (count > PROC_BLOCK_SIZE)
20733 + count = PROC_BLOCK_SIZE;
20735 + /* fade that out as soon as stable */
20737 + nxi = lookup_nx_info(nid);
20741 + length = -ENOMEM;
20742 + if (!(page = __get_free_page(GFP_KERNEL)))
20745 + BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
20746 + length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
20749 + length = simple_read_from_buffer(buf, count, ppos,
20750 + (char *)page, length);
20754 + put_nx_info(nxi);
20761 +/* here comes the lower level */
20764 +#define NOD(NAME, MODE, IOP, FOP, OP) { \
20765 + .len = sizeof(NAME) - 1, \
20766 + .name = (NAME), \
20774 +#define DIR(NAME, MODE, OTYPE) \
20775 + NOD(NAME, (S_IFDIR | (MODE)), \
20776 + &proc_ ## OTYPE ## _inode_operations, \
20777 + &proc_ ## OTYPE ## _file_operations, { } )
20779 +#define INF(NAME, MODE, OTYPE) \
20780 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
20781 + &proc_vs_info_file_operations, \
20782 + { .proc_vs_read = &proc_##OTYPE } )
20784 +#define VINF(NAME, MODE, OTYPE) \
20785 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
20786 + &proc_vx_info_file_operations, \
20787 + { .proc_vxi_read = &proc_##OTYPE } )
20789 +#define NINF(NAME, MODE, OTYPE) \
20790 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
20791 + &proc_nx_info_file_operations, \
20792 + { .proc_nxi_read = &proc_##OTYPE } )
20795 +static struct file_operations proc_vs_info_file_operations = {
20796 + .read = proc_vs_info_read,
20799 +static struct file_operations proc_vx_info_file_operations = {
20800 + .read = proc_vx_info_read,
20803 +static struct dentry_operations proc_xid_dentry_operations = {
20804 + .d_revalidate = proc_xid_revalidate,
20807 +static struct vs_entry vx_base_stuff[] = {
20808 + VINF("info", S_IRUGO, vxi_info),
20809 + VINF("status", S_IRUGO, vxi_status),
20810 + VINF("limit", S_IRUGO, vxi_limit),
20811 + VINF("sched", S_IRUGO, vxi_sched),
20812 + VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
20813 + VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
20814 + VINF("cvirt", S_IRUGO, vxi_cvirt),
20815 + VINF("cacct", S_IRUGO, vxi_cacct),
20822 +static struct dentry *proc_xid_instantiate(struct inode *dir,
20823 + struct dentry *dentry, int id, void *ptr)
20825 + dentry->d_op = &proc_xid_dentry_operations;
20826 + return vs_proc_instantiate(dir, dentry, id, ptr);
20829 +static struct dentry *proc_xid_lookup(struct inode *dir,
20830 + struct dentry *dentry, unsigned int flags)
20832 + struct vs_entry *p = vx_base_stuff;
20833 + struct dentry *error = ERR_PTR(-ENOENT);
20835 + for (; p->name; p++) {
20836 + if (p->len != dentry->d_name.len)
20838 + if (!memcmp(dentry->d_name.name, p->name, p->len))
20844 + error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20849 +static int proc_xid_iterate(struct file *filp, struct dir_context *ctx)
20851 + struct dentry *dentry = filp->f_dentry;
20852 + struct inode *inode = dentry->d_inode;
20853 + struct vs_entry *p = vx_base_stuff;
20854 + int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
20858 + switch (ctx->pos) {
20860 + ino = inode->i_ino;
20861 + if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20864 + /* fall through */
20866 + ino = parent_ino(dentry);
20867 + if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20870 + /* fall through */
20872 + index = ctx->pos - 2;
20873 + if (index >= size)
20875 + for (p += index; p->name; p++) {
20876 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20877 + vs_proc_instantiate, PROC_I(inode)->fd, p))
20888 +static struct file_operations proc_nx_info_file_operations = {
20889 + .read = proc_nx_info_read,
20892 +static struct dentry_operations proc_nid_dentry_operations = {
20893 + .d_revalidate = proc_nid_revalidate,
20896 +static struct vs_entry nx_base_stuff[] = {
20897 + NINF("info", S_IRUGO, nxi_info),
20898 + NINF("status", S_IRUGO, nxi_status),
20903 +static struct dentry *proc_nid_instantiate(struct inode *dir,
20904 + struct dentry *dentry, int id, void *ptr)
20906 + dentry->d_op = &proc_nid_dentry_operations;
20907 + return vs_proc_instantiate(dir, dentry, id, ptr);
20910 +static struct dentry *proc_nid_lookup(struct inode *dir,
20911 + struct dentry *dentry, unsigned int flags)
20913 + struct vs_entry *p = nx_base_stuff;
20914 + struct dentry *error = ERR_PTR(-ENOENT);
20916 + for (; p->name; p++) {
20917 + if (p->len != dentry->d_name.len)
20919 + if (!memcmp(dentry->d_name.name, p->name, p->len))
20925 + error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20930 +static int proc_nid_iterate(struct file *filp, struct dir_context *ctx)
20932 + struct dentry *dentry = filp->f_dentry;
20933 + struct inode *inode = dentry->d_inode;
20934 + struct vs_entry *p = nx_base_stuff;
20935 + int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
20939 + switch (ctx->pos) {
20941 + ino = inode->i_ino;
20942 + if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20945 + /* fall through */
20947 + ino = parent_ino(dentry);
20948 + if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20951 + /* fall through */
20953 + index = ctx->pos - 2;
20954 + if (index >= size)
20956 + for (p += index; p->name; p++) {
20957 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20958 + vs_proc_instantiate, PROC_I(inode)->fd, p))
20968 +#define MAX_MULBY10 ((~0U - 9) / 10)
20970 +static inline int atovid(const char *str, int len)
20975 + while (len-- > 0) {
20980 + if (vid >= MAX_MULBY10)
20990 +/* now the upper level (virtual) */
20993 +static struct file_operations proc_xid_file_operations = {
20994 + .read = generic_read_dir,
20995 + .iterate = proc_xid_iterate,
20998 +static struct inode_operations proc_xid_inode_operations = {
20999 + .lookup = proc_xid_lookup,
21002 +static struct vs_entry vx_virtual_stuff[] = {
21003 + INF("info", S_IRUGO, virtual_info),
21004 + INF("status", S_IRUGO, virtual_status),
21005 + DIR(NULL, S_IRUGO | S_IXUGO, xid),
21009 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21010 + struct dentry *dentry, unsigned int flags)
21012 + struct vs_entry *p = vx_virtual_stuff;
21013 + struct dentry *error = ERR_PTR(-ENOENT);
21016 + for (; p->name; p++) {
21017 + if (p->len != dentry->d_name.len)
21019 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21023 + goto instantiate;
21025 + id = atovid(dentry->d_name.name, dentry->d_name.len);
21026 + if ((id < 0) || !xid_is_hashed(id))
21030 + error = proc_xid_instantiate(dir, dentry, id, p);
21035 +static struct file_operations proc_nid_file_operations = {
21036 + .read = generic_read_dir,
21037 + .iterate = proc_nid_iterate,
21040 +static struct inode_operations proc_nid_inode_operations = {
21041 + .lookup = proc_nid_lookup,
21044 +static struct vs_entry nx_virtnet_stuff[] = {
21045 + INF("info", S_IRUGO, virtnet_info),
21046 + INF("status", S_IRUGO, virtnet_status),
21047 + DIR(NULL, S_IRUGO | S_IXUGO, nid),
21051 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21052 + struct dentry *dentry, unsigned int flags)
21054 + struct vs_entry *p = nx_virtnet_stuff;
21055 + struct dentry *error = ERR_PTR(-ENOENT);
21058 + for (; p->name; p++) {
21059 + if (p->len != dentry->d_name.len)
21061 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21065 + goto instantiate;
21067 + id = atovid(dentry->d_name.name, dentry->d_name.len);
21068 + if ((id < 0) || !nid_is_hashed(id))
21072 + error = proc_nid_instantiate(dir, dentry, id, p);
21078 +#define PROC_MAXVIDS 32
21080 +int proc_virtual_iterate(struct file *filp, struct dir_context *ctx)
21082 + struct dentry *dentry = filp->f_dentry;
21083 + struct inode *inode = dentry->d_inode;
21084 + struct vs_entry *p = vx_virtual_stuff;
21085 + int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21087 + unsigned int xid_array[PROC_MAXVIDS];
21088 + char buf[PROC_NUMBUF];
21089 + unsigned int nr_xids, i;
21092 + switch (ctx->pos) {
21094 + ino = inode->i_ino;
21095 + if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21098 + /* fall through */
21100 + ino = parent_ino(dentry);
21101 + if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21104 + /* fall through */
21106 + index = ctx->pos - 2;
21107 + if (index >= size)
21109 + for (p += index; p->name; p++) {
21110 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21111 + vs_proc_instantiate, 0, p))
21116 + index = ctx->pos - size;
21117 + p = &vx_virtual_stuff[size - 1];
21118 + nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21119 + for (i = 0; i < nr_xids; i++) {
21120 + int n, xid = xid_array[i];
21121 + unsigned int j = PROC_NUMBUF;
21125 + buf[--j] = '0' + (n % 10);
21128 + if (vx_proc_fill_cache(filp, ctx,
21129 + buf + j, PROC_NUMBUF - j,
21130 + vs_proc_instantiate, xid, p))
21139 +static int proc_virtual_getattr(struct vfsmount *mnt,
21140 + struct dentry *dentry, struct kstat *stat)
21142 + struct inode *inode = dentry->d_inode;
21144 + generic_fillattr(inode, stat);
21145 + stat->nlink = 2 + atomic_read(&vx_global_cactive);
21149 +static struct file_operations proc_virtual_dir_operations = {
21150 + .read = generic_read_dir,
21151 + .iterate = proc_virtual_iterate,
21154 +static struct inode_operations proc_virtual_dir_inode_operations = {
21155 + .getattr = proc_virtual_getattr,
21156 + .lookup = proc_virtual_lookup,
21161 +int proc_virtnet_iterate(struct file *filp, struct dir_context *ctx)
21163 + struct dentry *dentry = filp->f_dentry;
21164 + struct inode *inode = dentry->d_inode;
21165 + struct vs_entry *p = nx_virtnet_stuff;
21166 + int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21168 + unsigned int nid_array[PROC_MAXVIDS];
21169 + char buf[PROC_NUMBUF];
21170 + unsigned int nr_nids, i;
21173 + switch (ctx->pos) {
21175 + ino = inode->i_ino;
21176 + if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21179 + /* fall through */
21181 + ino = parent_ino(dentry);
21182 + if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21185 + /* fall through */
21187 + index = ctx->pos - 2;
21188 + if (index >= size)
21190 + for (p += index; p->name; p++) {
21191 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21192 + vs_proc_instantiate, 0, p))
21197 + index = ctx->pos - size;
21198 + p = &nx_virtnet_stuff[size - 1];
21199 + nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21200 + for (i = 0; i < nr_nids; i++) {
21201 + int n, nid = nid_array[i];
21202 + unsigned int j = PROC_NUMBUF;
21206 + buf[--j] = '0' + (n % 10);
21209 + if (vx_proc_fill_cache(filp, ctx,
21210 + buf + j, PROC_NUMBUF - j,
21211 + vs_proc_instantiate, nid, p))
21220 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21221 + struct dentry *dentry, struct kstat *stat)
21223 + struct inode *inode = dentry->d_inode;
21225 + generic_fillattr(inode, stat);
21226 + stat->nlink = 2 + atomic_read(&nx_global_cactive);
21230 +static struct file_operations proc_virtnet_dir_operations = {
21231 + .read = generic_read_dir,
21232 + .iterate = proc_virtnet_iterate,
21235 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21236 + .getattr = proc_virtnet_getattr,
21237 + .lookup = proc_virtnet_lookup,
21242 +void proc_vx_init(void)
21244 + struct proc_dir_entry *ent;
21246 + ent = proc_mkdir("virtual", 0);
21248 + ent->proc_fops = &proc_virtual_dir_operations;
21249 + ent->proc_iops = &proc_virtual_dir_inode_operations;
21251 + proc_virtual = ent;
21253 + ent = proc_mkdir("virtnet", 0);
21255 + ent->proc_fops = &proc_virtnet_dir_operations;
21256 + ent->proc_iops = &proc_virtnet_dir_inode_operations;
21258 + proc_virtnet = ent;
21264 +/* per pid info */
21267 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21269 + struct vx_info *vxi;
21270 + char *orig = buffer;
21272 + buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21274 + vxi = task_get_vx_info(p);
21278 + buffer += sprintf(buffer, "BCaps:\t");
21279 + buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21280 + buffer += sprintf(buffer, "\n");
21281 + buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21282 + (unsigned long long)vxi->vx_ccaps);
21283 + buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21284 + (unsigned long long)vxi->vx_flags);
21285 + buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21287 + put_vx_info(vxi);
21289 + return buffer - orig;
21293 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21295 + struct nx_info *nxi;
21296 + struct nx_addr_v4 *v4a;
21297 +#ifdef CONFIG_IPV6
21298 + struct nx_addr_v6 *v6a;
21300 + char *orig = buffer;
21303 + buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21305 + nxi = task_get_nx_info(p);
21309 + buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21310 + (unsigned long long)nxi->nx_ncaps);
21311 + buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21312 + (unsigned long long)nxi->nx_flags);
21314 + buffer += sprintf(buffer,
21315 + "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21316 + NIPQUAD(nxi->v4_bcast.s_addr));
21317 + buffer += sprintf (buffer,
21318 + "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21319 + NIPQUAD(nxi->v4_lback.s_addr));
21320 + if (!NX_IPV4(nxi))
21322 + for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21323 + buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21326 +#ifdef CONFIG_IPV6
21327 + if (!NX_IPV6(nxi))
21329 + for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21330 + buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
21334 + put_nx_info(nxi);
21336 + return buffer - orig;
21339 diff -NurpP --minimal linux-3.13.6/kernel/vserver/sched.c linux-3.13.6-vs2.3.6.11/kernel/vserver/sched.c
21340 --- linux-3.13.6/kernel/vserver/sched.c 1970-01-01 00:00:00.000000000 +0000
21341 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/sched.c 2014-01-31 20:38:04.000000000 +0000
21344 + * linux/kernel/vserver/sched.c
21346 + * Virtual Server: Scheduler Support
21348 + * Copyright (C) 2004-2010 Herbert Pötzl
21350 + * V0.01 adapted Sam Vilains version to 2.6.3
21351 + * V0.02 removed legacy interface
21352 + * V0.03 changed vcmds to vxi arg
21353 + * V0.04 removed older and legacy interfaces
21354 + * V0.05 removed scheduler code/commands
21358 +#include <linux/vs_context.h>
21359 +#include <linux/vs_sched.h>
21360 +#include <linux/cpumask.h>
21361 +#include <linux/vserver/sched_cmd.h>
21363 +#include <asm/uaccess.h>
21366 +void vx_update_sched_param(struct _vx_sched *sched,
21367 + struct _vx_sched_pc *sched_pc)
21369 + sched_pc->prio_bias = sched->prio_bias;
21372 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
21376 + if (data->prio_bias > MAX_PRIO_BIAS)
21377 + data->prio_bias = MAX_PRIO_BIAS;
21378 + if (data->prio_bias < MIN_PRIO_BIAS)
21379 + data->prio_bias = MIN_PRIO_BIAS;
21381 + if (data->cpu_id != ~0) {
21382 + vxi->sched.update = cpumask_of_cpu(data->cpu_id);
21383 + cpumask_and(&vxi->sched.update, &vxi->sched.update,
21384 + cpu_online_mask);
21386 + cpumask_copy(&vxi->sched.update, cpu_online_mask);
21388 + for_each_cpu_mask(cpu, vxi->sched.update)
21389 + vx_update_sched_param(&vxi->sched,
21390 + &vx_per_cpu(vxi, sched_pc, cpu));
21394 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
21396 + struct vcmd_prio_bias vc_data;
21398 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21401 + return do_set_prio_bias(vxi, &vc_data);
21404 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
21406 + struct vcmd_prio_bias vc_data;
21407 + struct _vx_sched_pc *pcd;
21410 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21413 + cpu = vc_data.cpu_id;
21415 + if (!cpu_possible(cpu))
21418 + pcd = &vx_per_cpu(vxi, sched_pc, cpu);
21419 + vc_data.prio_bias = pcd->prio_bias;
21421 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21426 diff -NurpP --minimal linux-3.13.6/kernel/vserver/sched_init.h linux-3.13.6-vs2.3.6.11/kernel/vserver/sched_init.h
21427 --- linux-3.13.6/kernel/vserver/sched_init.h 1970-01-01 00:00:00.000000000 +0000
21428 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/sched_init.h 2014-01-31 20:38:04.000000000 +0000
21431 +static inline void vx_info_init_sched(struct _vx_sched *sched)
21433 + /* scheduling; hard code starting values as constants */
21434 + sched->prio_bias = 0;
21438 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21440 + sched_pc->prio_bias = 0;
21442 + sched_pc->user_ticks = 0;
21443 + sched_pc->sys_ticks = 0;
21444 + sched_pc->hold_ticks = 0;
21447 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
21453 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21457 diff -NurpP --minimal linux-3.13.6/kernel/vserver/sched_proc.h linux-3.13.6-vs2.3.6.11/kernel/vserver/sched_proc.h
21458 --- linux-3.13.6/kernel/vserver/sched_proc.h 1970-01-01 00:00:00.000000000 +0000
21459 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/sched_proc.h 2014-01-31 20:38:04.000000000 +0000
21461 +#ifndef _VX_SCHED_PROC_H
21462 +#define _VX_SCHED_PROC_H
21466 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
21470 + length += sprintf(buffer,
21471 + "PrioBias:\t%8d\n",
21472 + sched->prio_bias);
21477 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
21478 + char *buffer, int cpu)
21482 + length += sprintf(buffer + length,
21483 + "cpu %d: %lld %lld %lld", cpu,
21484 + (unsigned long long)sched_pc->user_ticks,
21485 + (unsigned long long)sched_pc->sys_ticks,
21486 + (unsigned long long)sched_pc->hold_ticks);
21487 + length += sprintf(buffer + length,
21488 + " %d\n", sched_pc->prio_bias);
21492 +#endif /* _VX_SCHED_PROC_H */
21493 diff -NurpP --minimal linux-3.13.6/kernel/vserver/signal.c linux-3.13.6-vs2.3.6.11/kernel/vserver/signal.c
21494 --- linux-3.13.6/kernel/vserver/signal.c 1970-01-01 00:00:00.000000000 +0000
21495 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/signal.c 2014-01-31 20:38:04.000000000 +0000
21498 + * linux/kernel/vserver/signal.c
21500 + * Virtual Server: Signal Support
21502 + * Copyright (C) 2003-2007 Herbert Pötzl
21504 + * V0.01 broken out from vcontext V0.05
21505 + * V0.02 changed vcmds to vxi arg
21506 + * V0.03 adjusted siginfo for kill
21510 +#include <asm/uaccess.h>
21512 +#include <linux/vs_context.h>
21513 +#include <linux/vs_pid.h>
21514 +#include <linux/vserver/signal_cmd.h>
21517 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
21519 + int retval, count = 0;
21520 + struct task_struct *p;
21521 + struct siginfo *sip = SEND_SIG_PRIV;
21524 + vxdprintk(VXD_CBIT(misc, 4),
21525 + "vx_info_kill(%p[#%d],%d,%d)*",
21526 + vxi, vxi->vx_id, pid, sig);
21527 + read_lock(&tasklist_lock);
21531 + for_each_process(p) {
21534 + if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
21535 + (pid && vxi->vx_initpid == p->pid))
21538 + err = group_send_sig_info(sig, sip, p);
21540 + if (err != -EPERM)
21546 + if (vxi->vx_initpid) {
21547 + pid = vxi->vx_initpid;
21548 + /* for now, only SIGINT to private init ... */
21549 + if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21550 + /* ... as long as there are tasks left */
21551 + (atomic_read(&vxi->vx_tasks) > 1))
21554 + /* fallthrough */
21557 + p = find_task_by_real_pid(pid);
21558 + rcu_read_unlock();
21560 + if (vx_task_xid(p) == vxi->vx_id)
21561 + retval = group_send_sig_info(sig, sip, p);
21565 + read_unlock(&tasklist_lock);
21566 + vxdprintk(VXD_CBIT(misc, 4),
21567 + "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
21568 + vxi, vxi->vx_id, pid, sig, (long)sip, retval);
21572 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
21574 + struct vcmd_ctx_kill_v0 vc_data;
21576 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21579 + /* special check to allow guest shutdown */
21580 + if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21581 + /* forbid killall pid=0 when init is present */
21582 + (((vc_data.pid < 1) && vxi->vx_initpid) ||
21583 + (vc_data.pid > 1)))
21586 + return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
21590 +static int __wait_exit(struct vx_info *vxi)
21592 + DECLARE_WAITQUEUE(wait, current);
21595 + add_wait_queue(&vxi->vx_wait, &wait);
21596 + set_current_state(TASK_INTERRUPTIBLE);
21599 + if (vx_info_state(vxi,
21600 + VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
21602 + if (signal_pending(current)) {
21603 + ret = -ERESTARTSYS;
21610 + set_current_state(TASK_RUNNING);
21611 + remove_wait_queue(&vxi->vx_wait, &wait);
21617 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
21619 + struct vcmd_wait_exit_v0 vc_data;
21622 + ret = __wait_exit(vxi);
21623 + vc_data.reboot_cmd = vxi->reboot_cmd;
21624 + vc_data.exit_code = vxi->exit_code;
21626 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21631 diff -NurpP --minimal linux-3.13.6/kernel/vserver/space.c linux-3.13.6-vs2.3.6.11/kernel/vserver/space.c
21632 --- linux-3.13.6/kernel/vserver/space.c 1970-01-01 00:00:00.000000000 +0000
21633 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/space.c 2014-02-01 12:21:24.000000000 +0000
21636 + * linux/kernel/vserver/space.c
21638 + * Virtual Server: Context Space Support
21640 + * Copyright (C) 2003-2010 Herbert Pötzl
21642 + * V0.01 broken out from context.c 0.07
21643 + * V0.02 added task locking for namespace
21644 + * V0.03 broken out vx_enter_namespace
21645 + * V0.04 added *space support and commands
21646 + * V0.05 added credential support
21650 +#include <linux/utsname.h>
21651 +#include <linux/nsproxy.h>
21652 +#include <linux/err.h>
21653 +#include <linux/fs_struct.h>
21654 +#include <linux/cred.h>
21655 +#include <asm/uaccess.h>
21657 +#include <linux/vs_context.h>
21658 +#include <linux/vserver/space.h>
21659 +#include <linux/vserver/space_cmd.h>
21661 +atomic_t vs_global_nsproxy = ATOMIC_INIT(0);
21662 +atomic_t vs_global_fs = ATOMIC_INIT(0);
21663 +atomic_t vs_global_mnt_ns = ATOMIC_INIT(0);
21664 +atomic_t vs_global_uts_ns = ATOMIC_INIT(0);
21665 +atomic_t vs_global_user_ns = ATOMIC_INIT(0);
21666 +atomic_t vs_global_pid_ns = ATOMIC_INIT(0);
21669 +/* namespace functions */
21671 +#include <linux/mnt_namespace.h>
21672 +#include <linux/user_namespace.h>
21673 +#include <linux/pid_namespace.h>
21674 +#include <linux/ipc_namespace.h>
21675 +#include <net/net_namespace.h>
21676 +#include "../fs/mount.h"
21679 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
21680 + .mask = CLONE_FS |
21682 +#ifdef CONFIG_UTS_NS
21685 +#ifdef CONFIG_IPC_NS
21688 +#ifdef CONFIG_USER_NS
21694 +static const struct vcmd_space_mask_v1 space_mask = {
21695 + .mask = CLONE_FS |
21697 +#ifdef CONFIG_UTS_NS
21700 +#ifdef CONFIG_IPC_NS
21703 +#ifdef CONFIG_USER_NS
21706 +#ifdef CONFIG_PID_NS
21709 +#ifdef CONFIG_NET_NS
21715 +static const struct vcmd_space_mask_v1 default_space_mask = {
21716 + .mask = CLONE_FS |
21718 +#ifdef CONFIG_UTS_NS
21721 +#ifdef CONFIG_IPC_NS
21724 +#ifdef CONFIG_USER_NS
21727 +#ifdef CONFIG_PID_NS
21734 + * build a new nsproxy mix
21735 + * assumes that both proxies are 'const'
21736 + * does not touch nsproxy refcounts
21737 + * will hold a reference on the result.
21740 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
21741 + struct nsproxy *new_nsproxy, unsigned long mask)
21743 + struct mnt_namespace *old_ns;
21744 + struct uts_namespace *old_uts;
21745 + struct ipc_namespace *old_ipc;
21746 +#ifdef CONFIG_PID_NS
21747 + struct pid_namespace *old_pid;
21749 +#ifdef CONFIG_NET_NS
21750 + struct net *old_net;
21752 + struct nsproxy *nsproxy;
21754 + nsproxy = copy_nsproxy(old_nsproxy);
21758 + if (mask & CLONE_NEWNS) {
21759 + old_ns = nsproxy->mnt_ns;
21760 + nsproxy->mnt_ns = new_nsproxy->mnt_ns;
21761 + if (nsproxy->mnt_ns)
21762 + get_mnt_ns(nsproxy->mnt_ns);
21766 + if (mask & CLONE_NEWUTS) {
21767 + old_uts = nsproxy->uts_ns;
21768 + nsproxy->uts_ns = new_nsproxy->uts_ns;
21769 + if (nsproxy->uts_ns)
21770 + get_uts_ns(nsproxy->uts_ns);
21774 + if (mask & CLONE_NEWIPC) {
21775 + old_ipc = nsproxy->ipc_ns;
21776 + nsproxy->ipc_ns = new_nsproxy->ipc_ns;
21777 + if (nsproxy->ipc_ns)
21778 + get_ipc_ns(nsproxy->ipc_ns);
21782 +#ifdef CONFIG_PID_NS
21783 + if (mask & CLONE_NEWPID) {
21784 + old_pid = nsproxy->pid_ns_for_children;
21785 + nsproxy->pid_ns_for_children = new_nsproxy->pid_ns_for_children;
21786 + if (nsproxy->pid_ns_for_children)
21787 + get_pid_ns(nsproxy->pid_ns_for_children);
21791 +#ifdef CONFIG_NET_NS
21792 + if (mask & CLONE_NEWNET) {
21793 + old_net = nsproxy->net_ns;
21794 + nsproxy->net_ns = new_nsproxy->net_ns;
21795 + if (nsproxy->net_ns)
21796 + get_net(nsproxy->net_ns);
21801 + put_mnt_ns(old_ns);
21803 + put_uts_ns(old_uts);
21805 + put_ipc_ns(old_ipc);
21806 +#ifdef CONFIG_PID_NS
21808 + put_pid_ns(old_pid);
21810 +#ifdef CONFIG_NET_NS
21812 + put_net(old_net);
21820 + * merge two nsproxy structs into a new one.
21821 + * will hold a reference on the result.
21825 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
21826 + struct nsproxy *proxy, unsigned long mask)
21828 + struct nsproxy null_proxy = { .mnt_ns = NULL };
21834 + /* vs_mix_nsproxy returns with reference */
21835 + return vs_mix_nsproxy(old ? old : &null_proxy,
21838 + get_nsproxy(proxy);
21843 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21845 + struct nsproxy *proxy, *proxy_cur, *proxy_new;
21846 + struct fs_struct *fs_cur, *fs = NULL;
21847 + struct _vx_space *space;
21848 + int ret, kill = 0;
21850 + vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
21851 + vxi, vxi->vx_id, mask, index);
21853 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
21856 + if (index >= VX_SPACES)
21859 + space = &vxi->space[index];
21862 + mask = space->vx_nsmask;
21864 + if ((mask & space->vx_nsmask) != mask)
21867 + if (mask & CLONE_FS) {
21868 + fs = copy_fs_struct(space->vx_fs);
21872 + proxy = space->vx_nsproxy;
21874 + vxdprintk(VXD_CBIT(space, 9),
21875 + "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
21876 + vxi, vxi->vx_id, mask, index, proxy, fs);
21878 + task_lock(current);
21879 + fs_cur = current->fs;
21881 + if (mask & CLONE_FS) {
21882 + spin_lock(&fs_cur->lock);
21883 + current->fs = fs;
21884 + kill = !--fs_cur->users;
21885 + spin_unlock(&fs_cur->lock);
21888 + proxy_cur = current->nsproxy;
21889 + get_nsproxy(proxy_cur);
21890 + task_unlock(current);
21893 + free_fs_struct(fs_cur);
21895 + proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
21896 + if (IS_ERR(proxy_new)) {
21897 + ret = PTR_ERR(proxy_new);
21901 + proxy_new = xchg(¤t->nsproxy, proxy_new);
21903 + if (mask & CLONE_NEWUSER) {
21904 + struct cred *cred;
21906 + vxdprintk(VXD_CBIT(space, 10),
21907 + "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
21908 + vxi, vxi->vx_id, space->vx_cred,
21909 + current->real_cred, current->cred);
21911 + if (space->vx_cred) {
21912 + cred = __prepare_creds(space->vx_cred);
21914 + commit_creds(cred);
21921 + put_nsproxy(proxy_new);
21924 + put_nsproxy(proxy_cur);
21929 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21931 + struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
21932 + struct fs_struct *fs_vxi, *fs = NULL;
21933 + struct _vx_space *space;
21934 + int ret, kill = 0;
21936 + vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
21937 + vxi, vxi->vx_id, mask, index);
21939 + if ((mask & space_mask.mask) != mask)
21942 + if (index >= VX_SPACES)
21945 + space = &vxi->space[index];
21947 + proxy_vxi = space->vx_nsproxy;
21948 + fs_vxi = space->vx_fs;
21950 + if (mask & CLONE_FS) {
21951 + fs = copy_fs_struct(current->fs);
21956 + task_lock(current);
21958 + if (mask & CLONE_FS) {
21959 + spin_lock(&fs_vxi->lock);
21960 + space->vx_fs = fs;
21961 + kill = !--fs_vxi->users;
21962 + spin_unlock(&fs_vxi->lock);
21965 + proxy_cur = current->nsproxy;
21966 + get_nsproxy(proxy_cur);
21967 + task_unlock(current);
21970 + free_fs_struct(fs_vxi);
21972 + proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
21973 + if (IS_ERR(proxy_new)) {
21974 + ret = PTR_ERR(proxy_new);
21978 + proxy_new = xchg(&space->vx_nsproxy, proxy_new);
21979 + space->vx_nsmask |= mask;
21981 + if (mask & CLONE_NEWUSER) {
21982 + struct cred *cred;
21984 + vxdprintk(VXD_CBIT(space, 10),
21985 + "vx_set_space(%p[#%u],%p) cred (%p,%p)",
21986 + vxi, vxi->vx_id, space->vx_cred,
21987 + current->real_cred, current->cred);
21989 + cred = prepare_creds();
21990 + cred = (struct cred *)xchg(&space->vx_cred, cred);
21992 + abort_creds(cred);
21998 + put_nsproxy(proxy_new);
22001 + put_nsproxy(proxy_cur);
22006 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22008 + struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22010 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22013 + return vx_enter_space(vxi, vc_data.mask, 0);
22016 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22018 + struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22020 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22023 + if (vc_data.index >= VX_SPACES)
22026 + return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22029 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22031 + struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22033 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22036 + return vx_set_space(vxi, vc_data.mask, 0);
22039 +int vc_set_space(struct vx_info *vxi, void __user *data)
22041 + struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22043 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22046 + if (vc_data.index >= VX_SPACES)
22049 + return vx_set_space(vxi, vc_data.mask, vc_data.index);
22052 +int vc_get_space_mask(void __user *data, int type)
22054 + const struct vcmd_space_mask_v1 *mask;
22057 + mask = &space_mask_v0;
22058 + else if (type == 1)
22059 + mask = &space_mask;
22061 + mask = &default_space_mask;
22063 + vxdprintk(VXD_CBIT(space, 10),
22064 + "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22066 + if (copy_to_user(data, mask, sizeof(*mask)))
22071 diff -NurpP --minimal linux-3.13.6/kernel/vserver/switch.c linux-3.13.6-vs2.3.6.11/kernel/vserver/switch.c
22072 --- linux-3.13.6/kernel/vserver/switch.c 1970-01-01 00:00:00.000000000 +0000
22073 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/switch.c 2014-01-31 20:38:04.000000000 +0000
22076 + * linux/kernel/vserver/switch.c
22078 + * Virtual Server: Syscall Switch
22080 + * Copyright (C) 2003-2011 Herbert Pötzl
22082 + * V0.01 syscall switch
22083 + * V0.02 added signal to context
22084 + * V0.03 added rlimit functions
22085 + * V0.04 added iattr, task/xid functions
22086 + * V0.05 added debug/history stuff
22087 + * V0.06 added compat32 layer
22088 + * V0.07 vcmd args and perms
22089 + * V0.08 added status commands
22090 + * V0.09 added tag commands
22091 + * V0.10 added oom bias
22092 + * V0.11 added device commands
22093 + * V0.12 added warn mask
22097 +#include <linux/vs_context.h>
22098 +#include <linux/vs_network.h>
22099 +#include <linux/vserver/switch.h>
22101 +#include "vci_config.h"
22105 +int vc_get_version(uint32_t id)
22107 + return VCI_VERSION;
22111 +int vc_get_vci(uint32_t id)
22113 + return vci_kernel_config();
22116 +#include <linux/vserver/context_cmd.h>
22117 +#include <linux/vserver/cvirt_cmd.h>
22118 +#include <linux/vserver/cacct_cmd.h>
22119 +#include <linux/vserver/limit_cmd.h>
22120 +#include <linux/vserver/network_cmd.h>
22121 +#include <linux/vserver/sched_cmd.h>
22122 +#include <linux/vserver/debug_cmd.h>
22123 +#include <linux/vserver/inode_cmd.h>
22124 +#include <linux/vserver/dlimit_cmd.h>
22125 +#include <linux/vserver/signal_cmd.h>
22126 +#include <linux/vserver/space_cmd.h>
22127 +#include <linux/vserver/tag_cmd.h>
22128 +#include <linux/vserver/device_cmd.h>
22130 +#include <linux/vserver/inode.h>
22131 +#include <linux/vserver/dlimit.h>
22134 +#ifdef CONFIG_COMPAT
22135 +#define __COMPAT(name, id, data, compat) \
22136 + (compat) ? name ## _x32(id, data) : name(id, data)
22137 +#define __COMPAT_NO_ID(name, data, compat) \
22138 + (compat) ? name ## _x32(data) : name(data)
22140 +#define __COMPAT(name, id, data, compat) \
22142 +#define __COMPAT_NO_ID(name, data, compat) \
22148 +long do_vcmd(uint32_t cmd, uint32_t id,
22149 + struct vx_info *vxi, struct nx_info *nxi,
22150 + void __user *data, int compat)
22154 + case VCMD_get_version:
22155 + return vc_get_version(id);
22156 + case VCMD_get_vci:
22157 + return vc_get_vci(id);
22159 + case VCMD_task_xid:
22160 + return vc_task_xid(id);
22161 + case VCMD_vx_info:
22162 + return vc_vx_info(vxi, data);
22164 + case VCMD_task_nid:
22165 + return vc_task_nid(id);
22166 + case VCMD_nx_info:
22167 + return vc_nx_info(nxi, data);
22169 + case VCMD_task_tag:
22170 + return vc_task_tag(id);
22172 + case VCMD_set_space_v1:
22173 + return vc_set_space_v1(vxi, data);
22174 + /* this is version 2 */
22175 + case VCMD_set_space:
22176 + return vc_set_space(vxi, data);
22178 + case VCMD_get_space_mask_v0:
22179 + return vc_get_space_mask(data, 0);
22180 + /* this is version 1 */
22181 + case VCMD_get_space_mask:
22182 + return vc_get_space_mask(data, 1);
22184 + case VCMD_get_space_default:
22185 + return vc_get_space_mask(data, -1);
22187 + case VCMD_set_umask:
22188 + return vc_set_umask(vxi, data);
22190 + case VCMD_get_umask:
22191 + return vc_get_umask(vxi, data);
22193 + case VCMD_set_wmask:
22194 + return vc_set_wmask(vxi, data);
22196 + case VCMD_get_wmask:
22197 + return vc_get_wmask(vxi, data);
22198 +#ifdef CONFIG_IA32_EMULATION
22199 + case VCMD_get_rlimit:
22200 + return __COMPAT(vc_get_rlimit, vxi, data, compat);
22201 + case VCMD_set_rlimit:
22202 + return __COMPAT(vc_set_rlimit, vxi, data, compat);
22204 + case VCMD_get_rlimit:
22205 + return vc_get_rlimit(vxi, data);
22206 + case VCMD_set_rlimit:
22207 + return vc_set_rlimit(vxi, data);
22209 + case VCMD_get_rlimit_mask:
22210 + return vc_get_rlimit_mask(id, data);
22211 + case VCMD_reset_hits:
22212 + return vc_reset_hits(vxi, data);
22213 + case VCMD_reset_minmax:
22214 + return vc_reset_minmax(vxi, data);
22216 + case VCMD_get_vhi_name:
22217 + return vc_get_vhi_name(vxi, data);
22218 + case VCMD_set_vhi_name:
22219 + return vc_set_vhi_name(vxi, data);
22221 + case VCMD_ctx_stat:
22222 + return vc_ctx_stat(vxi, data);
22223 + case VCMD_virt_stat:
22224 + return vc_virt_stat(vxi, data);
22225 + case VCMD_sock_stat:
22226 + return vc_sock_stat(vxi, data);
22227 + case VCMD_rlimit_stat:
22228 + return vc_rlimit_stat(vxi, data);
22230 + case VCMD_set_cflags:
22231 + return vc_set_cflags(vxi, data);
22232 + case VCMD_get_cflags:
22233 + return vc_get_cflags(vxi, data);
22235 + /* this is version 1 */
22236 + case VCMD_set_ccaps:
22237 + return vc_set_ccaps(vxi, data);
22238 + /* this is version 1 */
22239 + case VCMD_get_ccaps:
22240 + return vc_get_ccaps(vxi, data);
22241 + case VCMD_set_bcaps:
22242 + return vc_set_bcaps(vxi, data);
22243 + case VCMD_get_bcaps:
22244 + return vc_get_bcaps(vxi, data);
22246 + case VCMD_set_badness:
22247 + return vc_set_badness(vxi, data);
22248 + case VCMD_get_badness:
22249 + return vc_get_badness(vxi, data);
22251 + case VCMD_set_nflags:
22252 + return vc_set_nflags(nxi, data);
22253 + case VCMD_get_nflags:
22254 + return vc_get_nflags(nxi, data);
22256 + case VCMD_set_ncaps:
22257 + return vc_set_ncaps(nxi, data);
22258 + case VCMD_get_ncaps:
22259 + return vc_get_ncaps(nxi, data);
22261 + case VCMD_set_prio_bias:
22262 + return vc_set_prio_bias(vxi, data);
22263 + case VCMD_get_prio_bias:
22264 + return vc_get_prio_bias(vxi, data);
22265 + case VCMD_add_dlimit:
22266 + return __COMPAT(vc_add_dlimit, id, data, compat);
22267 + case VCMD_rem_dlimit:
22268 + return __COMPAT(vc_rem_dlimit, id, data, compat);
22269 + case VCMD_set_dlimit:
22270 + return __COMPAT(vc_set_dlimit, id, data, compat);
22271 + case VCMD_get_dlimit:
22272 + return __COMPAT(vc_get_dlimit, id, data, compat);
22274 + case VCMD_ctx_kill:
22275 + return vc_ctx_kill(vxi, data);
22277 + case VCMD_wait_exit:
22278 + return vc_wait_exit(vxi, data);
22280 + case VCMD_get_iattr:
22281 + return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22282 + case VCMD_set_iattr:
22283 + return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22285 + case VCMD_fget_iattr:
22286 + return vc_fget_iattr(id, data);
22287 + case VCMD_fset_iattr:
22288 + return vc_fset_iattr(id, data);
22290 + case VCMD_enter_space_v0:
22291 + return vc_enter_space_v1(vxi, NULL);
22292 + case VCMD_enter_space_v1:
22293 + return vc_enter_space_v1(vxi, data);
22294 + /* this is version 2 */
22295 + case VCMD_enter_space:
22296 + return vc_enter_space(vxi, data);
22298 + case VCMD_ctx_create_v0:
22299 + return vc_ctx_create(id, NULL);
22300 + case VCMD_ctx_create:
22301 + return vc_ctx_create(id, data);
22302 + case VCMD_ctx_migrate_v0:
22303 + return vc_ctx_migrate(vxi, NULL);
22304 + case VCMD_ctx_migrate:
22305 + return vc_ctx_migrate(vxi, data);
22307 + case VCMD_net_create_v0:
22308 + return vc_net_create(id, NULL);
22309 + case VCMD_net_create:
22310 + return vc_net_create(id, data);
22311 + case VCMD_net_migrate:
22312 + return vc_net_migrate(nxi, data);
22314 + case VCMD_tag_migrate:
22315 + return vc_tag_migrate(id);
22317 + case VCMD_net_add:
22318 + return vc_net_add(nxi, data);
22319 + case VCMD_net_remove:
22320 + return vc_net_remove(nxi, data);
22322 + case VCMD_net_add_ipv4_v1:
22323 + return vc_net_add_ipv4_v1(nxi, data);
22324 + /* this is version 2 */
22325 + case VCMD_net_add_ipv4:
22326 + return vc_net_add_ipv4(nxi, data);
22328 + case VCMD_net_rem_ipv4_v1:
22329 + return vc_net_rem_ipv4_v1(nxi, data);
22330 + /* this is version 2 */
22331 + case VCMD_net_rem_ipv4:
22332 + return vc_net_rem_ipv4(nxi, data);
22333 +#ifdef CONFIG_IPV6
22334 + case VCMD_net_add_ipv6:
22335 + return vc_net_add_ipv6(nxi, data);
22336 + case VCMD_net_remove_ipv6:
22337 + return vc_net_remove_ipv6(nxi, data);
22339 +/* case VCMD_add_match_ipv4:
22340 + return vc_add_match_ipv4(nxi, data);
22341 + case VCMD_get_match_ipv4:
22342 + return vc_get_match_ipv4(nxi, data);
22343 +#ifdef CONFIG_IPV6
22344 + case VCMD_add_match_ipv6:
22345 + return vc_add_match_ipv6(nxi, data);
22346 + case VCMD_get_match_ipv6:
22347 + return vc_get_match_ipv6(nxi, data);
22350 +#ifdef CONFIG_VSERVER_DEVICE
22351 + case VCMD_set_mapping:
22352 + return __COMPAT(vc_set_mapping, vxi, data, compat);
22353 + case VCMD_unset_mapping:
22354 + return __COMPAT(vc_unset_mapping, vxi, data, compat);
22356 +#ifdef CONFIG_VSERVER_HISTORY
22357 + case VCMD_dump_history:
22358 + return vc_dump_history(id);
22359 + case VCMD_read_history:
22360 + return __COMPAT(vc_read_history, id, data, compat);
22363 + vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
22364 + VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
22370 +#define __VCMD(vcmd, _perm, _args, _flags) \
22371 + case VCMD_ ## vcmd: perm = _perm; \
22372 + args = _args; flags = _flags; break
22375 +#define VCA_NONE 0x00
22376 +#define VCA_VXI 0x01
22377 +#define VCA_NXI 0x02
22379 +#define VCF_NONE 0x00
22380 +#define VCF_INFO 0x01
22381 +#define VCF_ADMIN 0x02
22382 +#define VCF_ARES 0x06 /* includes admin */
22383 +#define VCF_SETUP 0x08
22385 +#define VCF_ZIDOK 0x10 /* zero id okay */
22389 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
22392 + int permit = -1, state = 0;
22393 + int perm = -1, args = 0, flags = 0;
22394 + struct vx_info *vxi = NULL;
22395 + struct nx_info *nxi = NULL;
22398 + /* unpriviledged commands */
22399 + __VCMD(get_version, 0, VCA_NONE, 0);
22400 + __VCMD(get_vci, 0, VCA_NONE, 0);
22401 + __VCMD(get_rlimit_mask, 0, VCA_NONE, 0);
22402 + __VCMD(get_space_mask_v0,0, VCA_NONE, 0);
22403 + __VCMD(get_space_mask, 0, VCA_NONE, 0);
22404 + __VCMD(get_space_default,0, VCA_NONE, 0);
22406 + /* info commands */
22407 + __VCMD(task_xid, 2, VCA_NONE, 0);
22408 + __VCMD(reset_hits, 2, VCA_VXI, 0);
22409 + __VCMD(reset_minmax, 2, VCA_VXI, 0);
22410 + __VCMD(vx_info, 3, VCA_VXI, VCF_INFO);
22411 + __VCMD(get_bcaps, 3, VCA_VXI, VCF_INFO);
22412 + __VCMD(get_ccaps, 3, VCA_VXI, VCF_INFO);
22413 + __VCMD(get_cflags, 3, VCA_VXI, VCF_INFO);
22414 + __VCMD(get_umask, 3, VCA_VXI, VCF_INFO);
22415 + __VCMD(get_wmask, 3, VCA_VXI, VCF_INFO);
22416 + __VCMD(get_badness, 3, VCA_VXI, VCF_INFO);
22417 + __VCMD(get_vhi_name, 3, VCA_VXI, VCF_INFO);
22418 + __VCMD(get_rlimit, 3, VCA_VXI, VCF_INFO);
22420 + __VCMD(ctx_stat, 3, VCA_VXI, VCF_INFO);
22421 + __VCMD(virt_stat, 3, VCA_VXI, VCF_INFO);
22422 + __VCMD(sock_stat, 3, VCA_VXI, VCF_INFO);
22423 + __VCMD(rlimit_stat, 3, VCA_VXI, VCF_INFO);
22425 + __VCMD(task_nid, 2, VCA_NONE, 0);
22426 + __VCMD(nx_info, 3, VCA_NXI, VCF_INFO);
22427 + __VCMD(get_ncaps, 3, VCA_NXI, VCF_INFO);
22428 + __VCMD(get_nflags, 3, VCA_NXI, VCF_INFO);
22430 + __VCMD(task_tag, 2, VCA_NONE, 0);
22432 + __VCMD(get_iattr, 2, VCA_NONE, 0);
22433 + __VCMD(fget_iattr, 2, VCA_NONE, 0);
22434 + __VCMD(get_dlimit, 3, VCA_NONE, VCF_INFO);
22435 + __VCMD(get_prio_bias, 3, VCA_VXI, VCF_INFO);
22437 + /* lower admin commands */
22438 + __VCMD(wait_exit, 4, VCA_VXI, VCF_INFO);
22439 + __VCMD(ctx_create_v0, 5, VCA_NONE, 0);
22440 + __VCMD(ctx_create, 5, VCA_NONE, 0);
22441 + __VCMD(ctx_migrate_v0, 5, VCA_VXI, VCF_ADMIN);
22442 + __VCMD(ctx_migrate, 5, VCA_VXI, VCF_ADMIN);
22443 + __VCMD(enter_space_v0, 5, VCA_VXI, VCF_ADMIN);
22444 + __VCMD(enter_space_v1, 5, VCA_VXI, VCF_ADMIN);
22445 + __VCMD(enter_space, 5, VCA_VXI, VCF_ADMIN);
22447 + __VCMD(net_create_v0, 5, VCA_NONE, 0);
22448 + __VCMD(net_create, 5, VCA_NONE, 0);
22449 + __VCMD(net_migrate, 5, VCA_NXI, VCF_ADMIN);
22451 + __VCMD(tag_migrate, 5, VCA_NONE, VCF_ADMIN);
22453 + /* higher admin commands */
22454 + __VCMD(ctx_kill, 6, VCA_VXI, VCF_ARES);
22455 + __VCMD(set_space_v1, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22456 + __VCMD(set_space, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22458 + __VCMD(set_ccaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22459 + __VCMD(set_bcaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22460 + __VCMD(set_cflags, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22461 + __VCMD(set_umask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22462 + __VCMD(set_wmask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22463 + __VCMD(set_badness, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22465 + __VCMD(set_vhi_name, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22466 + __VCMD(set_rlimit, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22467 + __VCMD(set_prio_bias, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22469 + __VCMD(set_ncaps, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
22470 + __VCMD(set_nflags, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
22471 + __VCMD(net_add, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22472 + __VCMD(net_remove, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22473 + __VCMD(net_add_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22474 + __VCMD(net_rem_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22475 + __VCMD(net_add_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22476 + __VCMD(net_rem_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22477 +#ifdef CONFIG_IPV6
22478 + __VCMD(net_add_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22479 + __VCMD(net_remove_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22481 + __VCMD(set_iattr, 7, VCA_NONE, 0);
22482 + __VCMD(fset_iattr, 7, VCA_NONE, 0);
22483 + __VCMD(set_dlimit, 7, VCA_NONE, VCF_ARES);
22484 + __VCMD(add_dlimit, 8, VCA_NONE, VCF_ARES);
22485 + __VCMD(rem_dlimit, 8, VCA_NONE, VCF_ARES);
22487 +#ifdef CONFIG_VSERVER_DEVICE
22488 + __VCMD(set_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
22489 + __VCMD(unset_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
22491 + /* debug level admin commands */
22492 +#ifdef CONFIG_VSERVER_HISTORY
22493 + __VCMD(dump_history, 9, VCA_NONE, 0);
22494 + __VCMD(read_history, 9, VCA_NONE, 0);
22501 + vxdprintk(VXD_CBIT(switch, 0),
22502 + "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
22503 + VC_CATEGORY(cmd), VC_COMMAND(cmd),
22504 + VC_VERSION(cmd), id, data, compat,
22505 + perm, args, flags);
22512 + if (!capable(CAP_CONTEXT))
22516 + /* moved here from the individual commands */
22518 + if ((perm > 1) && !capable(CAP_SYS_ADMIN))
22522 + /* vcmd involves resource management */
22524 + if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
22528 + /* various legacy exceptions */
22530 + /* will go away when spectator is a cap */
22531 + case VCMD_ctx_migrate_v0:
22532 + case VCMD_ctx_migrate:
22534 + current->xid = 1;
22540 + /* will go away when spectator is a cap */
22541 + case VCMD_net_migrate:
22543 + current->nid = 1;
22550 + /* vcmds are fine by default */
22553 + /* admin type vcmds require admin ... */
22554 + if (flags & VCF_ADMIN)
22555 + permit = vx_check(0, VS_ADMIN) ? 1 : 0;
22557 + /* ... but setup type vcmds override that */
22558 + if (!permit && (flags & VCF_SETUP))
22559 + permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
22567 + if (!id && (flags & VCF_ZIDOK))
22571 + if (args & VCA_VXI) {
22572 + vxi = lookup_vx_info(id);
22576 + if ((flags & VCF_ADMIN) &&
22577 + /* special case kill for shutdown */
22578 + (cmd != VCMD_ctx_kill) &&
22579 + /* can context be administrated? */
22580 + !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
22586 + if (args & VCA_NXI) {
22587 + nxi = lookup_nx_info(id);
22591 + if ((flags & VCF_ADMIN) &&
22592 + /* can context be administrated? */
22593 + !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
22600 + ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
22603 + if ((args & VCA_NXI) && nxi)
22604 + put_nx_info(nxi);
22606 + if ((args & VCA_VXI) && vxi)
22607 + put_vx_info(vxi);
22609 + vxdprintk(VXD_CBIT(switch, 1),
22610 + "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
22611 + VC_CATEGORY(cmd), VC_COMMAND(cmd),
22612 + VC_VERSION(cmd), ret, ret, state, permit);
22617 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
22619 + return do_vserver(cmd, id, data, 0);
22622 +#ifdef CONFIG_COMPAT
22625 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
22627 + return do_vserver(cmd, id, data, 1);
22630 +#endif /* CONFIG_COMPAT */
22631 diff -NurpP --minimal linux-3.13.6/kernel/vserver/sysctl.c linux-3.13.6-vs2.3.6.11/kernel/vserver/sysctl.c
22632 --- linux-3.13.6/kernel/vserver/sysctl.c 1970-01-01 00:00:00.000000000 +0000
22633 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/sysctl.c 2014-01-31 20:38:04.000000000 +0000
22636 + * kernel/vserver/sysctl.c
22638 + * Virtual Context Support
22640 + * Copyright (C) 2004-2007 Herbert Pötzl
22642 + * V0.01 basic structure
22646 +#include <linux/module.h>
22647 +#include <linux/ctype.h>
22648 +#include <linux/sysctl.h>
22649 +#include <linux/parser.h>
22650 +#include <asm/uaccess.h>
22653 + CTL_DEBUG_ERROR = 0,
22654 + CTL_DEBUG_SWITCH = 1,
22670 +unsigned int vs_debug_switch = 0;
22671 +unsigned int vs_debug_xid = 0;
22672 +unsigned int vs_debug_nid = 0;
22673 +unsigned int vs_debug_tag = 0;
22674 +unsigned int vs_debug_net = 0;
22675 +unsigned int vs_debug_limit = 0;
22676 +unsigned int vs_debug_cres = 0;
22677 +unsigned int vs_debug_dlim = 0;
22678 +unsigned int vs_debug_quota = 0;
22679 +unsigned int vs_debug_cvirt = 0;
22680 +unsigned int vs_debug_space = 0;
22681 +unsigned int vs_debug_perm = 0;
22682 +unsigned int vs_debug_misc = 0;
22685 +static struct ctl_table_header *vserver_table_header;
22686 +static ctl_table vserver_root_table[];
22689 +void vserver_register_sysctl(void)
22691 + if (!vserver_table_header) {
22692 + vserver_table_header = register_sysctl_table(vserver_root_table);
22697 +void vserver_unregister_sysctl(void)
22699 + if (vserver_table_header) {
22700 + unregister_sysctl_table(vserver_table_header);
22701 + vserver_table_header = NULL;
22706 +static int proc_dodebug(ctl_table *table, int write,
22707 + void __user *buffer, size_t *lenp, loff_t *ppos)
22709 + char tmpbuf[20], *p, c;
22710 + unsigned int value;
22711 + size_t left, len;
22713 + if ((*ppos && !write) || !*lenp) {
22721 + if (!access_ok(VERIFY_READ, buffer, left))
22723 + p = (char *)buffer;
22724 + while (left && __get_user(c, p) >= 0 && isspace(c))
22729 + if (left > sizeof(tmpbuf) - 1)
22731 + if (copy_from_user(tmpbuf, p, left))
22733 + tmpbuf[left] = '\0';
22735 + for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
22736 + value = 10 * value + (*p - '0');
22737 + if (*p && !isspace(*p))
22739 + while (left && isspace(*p))
22741 + *(unsigned int *)table->data = value;
22743 + if (!access_ok(VERIFY_WRITE, buffer, left))
22745 + len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
22748 + if (__copy_to_user(buffer, tmpbuf, len))
22750 + if ((left -= len) > 0) {
22751 + if (put_user('\n', (char *)buffer + len))
22765 +#define CTL_ENTRY(ctl, name) \
22767 + .procname = #name, \
22768 + .data = &vs_ ## name, \
22769 + .maxlen = sizeof(int), \
22771 + .proc_handler = &proc_dodebug, \
22772 + .extra1 = &zero, \
22773 + .extra2 = &zero, \
22776 +static ctl_table vserver_debug_table[] = {
22777 + CTL_ENTRY(CTL_DEBUG_SWITCH, debug_switch),
22778 + CTL_ENTRY(CTL_DEBUG_XID, debug_xid),
22779 + CTL_ENTRY(CTL_DEBUG_NID, debug_nid),
22780 + CTL_ENTRY(CTL_DEBUG_TAG, debug_tag),
22781 + CTL_ENTRY(CTL_DEBUG_NET, debug_net),
22782 + CTL_ENTRY(CTL_DEBUG_LIMIT, debug_limit),
22783 + CTL_ENTRY(CTL_DEBUG_CRES, debug_cres),
22784 + CTL_ENTRY(CTL_DEBUG_DLIM, debug_dlim),
22785 + CTL_ENTRY(CTL_DEBUG_QUOTA, debug_quota),
22786 + CTL_ENTRY(CTL_DEBUG_CVIRT, debug_cvirt),
22787 + CTL_ENTRY(CTL_DEBUG_SPACE, debug_space),
22788 + CTL_ENTRY(CTL_DEBUG_PERM, debug_perm),
22789 + CTL_ENTRY(CTL_DEBUG_MISC, debug_misc),
22793 +static ctl_table vserver_root_table[] = {
22795 + .procname = "vserver",
22797 + .child = vserver_debug_table
22803 +static match_table_t tokens = {
22804 + { CTL_DEBUG_SWITCH, "switch=%x" },
22805 + { CTL_DEBUG_XID, "xid=%x" },
22806 + { CTL_DEBUG_NID, "nid=%x" },
22807 + { CTL_DEBUG_TAG, "tag=%x" },
22808 + { CTL_DEBUG_NET, "net=%x" },
22809 + { CTL_DEBUG_LIMIT, "limit=%x" },
22810 + { CTL_DEBUG_CRES, "cres=%x" },
22811 + { CTL_DEBUG_DLIM, "dlim=%x" },
22812 + { CTL_DEBUG_QUOTA, "quota=%x" },
22813 + { CTL_DEBUG_CVIRT, "cvirt=%x" },
22814 + { CTL_DEBUG_SPACE, "space=%x" },
22815 + { CTL_DEBUG_PERM, "perm=%x" },
22816 + { CTL_DEBUG_MISC, "misc=%x" },
22817 + { CTL_DEBUG_ERROR, NULL }
22820 +#define HANDLE_CASE(id, name, val) \
22821 + case CTL_DEBUG_ ## id: \
22822 + vs_debug_ ## name = val; \
22823 + printk("vs_debug_" #name "=0x%x\n", val); \
22827 +static int __init vs_debug_setup(char *str)
22832 + printk("vs_debug_setup(%s)\n", str);
22833 + while ((p = strsep(&str, ",")) != NULL) {
22834 + substring_t args[MAX_OPT_ARGS];
22835 + unsigned int value;
22840 + token = match_token(p, tokens, args);
22841 + value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
22844 + HANDLE_CASE(SWITCH, switch, value);
22845 + HANDLE_CASE(XID, xid, value);
22846 + HANDLE_CASE(NID, nid, value);
22847 + HANDLE_CASE(TAG, tag, value);
22848 + HANDLE_CASE(NET, net, value);
22849 + HANDLE_CASE(LIMIT, limit, value);
22850 + HANDLE_CASE(CRES, cres, value);
22851 + HANDLE_CASE(DLIM, dlim, value);
22852 + HANDLE_CASE(QUOTA, quota, value);
22853 + HANDLE_CASE(CVIRT, cvirt, value);
22854 + HANDLE_CASE(SPACE, space, value);
22855 + HANDLE_CASE(PERM, perm, value);
22856 + HANDLE_CASE(MISC, misc, value);
22865 +__setup("vsdebug=", vs_debug_setup);
22869 +EXPORT_SYMBOL_GPL(vs_debug_switch);
22870 +EXPORT_SYMBOL_GPL(vs_debug_xid);
22871 +EXPORT_SYMBOL_GPL(vs_debug_nid);
22872 +EXPORT_SYMBOL_GPL(vs_debug_net);
22873 +EXPORT_SYMBOL_GPL(vs_debug_limit);
22874 +EXPORT_SYMBOL_GPL(vs_debug_cres);
22875 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
22876 +EXPORT_SYMBOL_GPL(vs_debug_quota);
22877 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
22878 +EXPORT_SYMBOL_GPL(vs_debug_space);
22879 +EXPORT_SYMBOL_GPL(vs_debug_perm);
22880 +EXPORT_SYMBOL_GPL(vs_debug_misc);
22882 diff -NurpP --minimal linux-3.13.6/kernel/vserver/tag.c linux-3.13.6-vs2.3.6.11/kernel/vserver/tag.c
22883 --- linux-3.13.6/kernel/vserver/tag.c 1970-01-01 00:00:00.000000000 +0000
22884 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/tag.c 2014-01-31 20:38:04.000000000 +0000
22887 + * linux/kernel/vserver/tag.c
22889 + * Virtual Server: Shallow Tag Space
22891 + * Copyright (C) 2007 Herbert Pötzl
22893 + * V0.01 basic implementation
22897 +#include <linux/sched.h>
22898 +#include <linux/vserver/debug.h>
22899 +#include <linux/vs_pid.h>
22900 +#include <linux/vs_tag.h>
22902 +#include <linux/vserver/tag_cmd.h>
22905 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
22910 + vxdprintk(VXD_CBIT(tag, 5),
22911 + "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
22917 + vxdprintk(VXD_CBIT(tag, 5),
22918 + "moved task %p into [#%d]", p, tag);
22922 +/* vserver syscall commands below here */
22924 +/* taks xid and vx_info functions */
22927 +int vc_task_tag(uint32_t id)
22932 + struct task_struct *tsk;
22934 + tsk = find_task_by_real_pid(id);
22935 + tag = (tsk) ? tsk->tag : -ESRCH;
22936 + rcu_read_unlock();
22938 + tag = dx_current_tag();
22943 +int vc_tag_migrate(uint32_t tag)
22945 + return dx_migrate_task(current, tag & 0xFFFF);
22949 diff -NurpP --minimal linux-3.13.6/kernel/vserver/vci_config.h linux-3.13.6-vs2.3.6.11/kernel/vserver/vci_config.h
22950 --- linux-3.13.6/kernel/vserver/vci_config.h 1970-01-01 00:00:00.000000000 +0000
22951 +++ linux-3.13.6-vs2.3.6.11/kernel/vserver/vci_config.h 2014-01-31 20:38:04.000000000 +0000
22954 +/* interface version */
22956 +#define VCI_VERSION 0x00020308
22960 + VCI_KCBIT_NO_DYNAMIC = 0,
22962 + VCI_KCBIT_PROC_SECURE = 4,
22963 + /* VCI_KCBIT_HARDCPU = 5, */
22964 + /* VCI_KCBIT_IDLELIMIT = 6, */
22965 + /* VCI_KCBIT_IDLETIME = 7, */
22967 + VCI_KCBIT_COWBL = 8,
22968 + VCI_KCBIT_FULLCOWBL = 9,
22969 + VCI_KCBIT_SPACES = 10,
22970 + VCI_KCBIT_NETV2 = 11,
22971 + VCI_KCBIT_MEMCG = 12,
22972 + VCI_KCBIT_MEMCG_SWAP = 13,
22974 + VCI_KCBIT_DEBUG = 16,
22975 + VCI_KCBIT_HISTORY = 20,
22976 + VCI_KCBIT_TAGGED = 24,
22977 + VCI_KCBIT_PPTAG = 28,
22979 + VCI_KCBIT_MORE = 31,
22983 +static inline uint32_t vci_kernel_config(void)
22986 + (1 << VCI_KCBIT_NO_DYNAMIC) |
22988 + /* configured features */
22989 +#ifdef CONFIG_VSERVER_PROC_SECURE
22990 + (1 << VCI_KCBIT_PROC_SECURE) |
22992 +#ifdef CONFIG_VSERVER_COWBL
22993 + (1 << VCI_KCBIT_COWBL) |
22994 + (1 << VCI_KCBIT_FULLCOWBL) |
22996 + (1 << VCI_KCBIT_SPACES) |
22997 + (1 << VCI_KCBIT_NETV2) |
22998 +#ifdef CONFIG_MEMCG
22999 + (1 << VCI_KCBIT_MEMCG) |
23001 +#ifdef CONFIG_MEMCG_SWAP
23002 + (1 << VCI_KCBIT_MEMCG_SWAP) |
23005 + /* debug options */
23006 +#ifdef CONFIG_VSERVER_DEBUG
23007 + (1 << VCI_KCBIT_DEBUG) |
23009 +#ifdef CONFIG_VSERVER_HISTORY
23010 + (1 << VCI_KCBIT_HISTORY) |
23013 + /* inode context tagging */
23014 +#if defined(CONFIG_TAGGING_NONE)
23015 + (0 << VCI_KCBIT_TAGGED) |
23016 +#elif defined(CONFIG_TAGGING_UID16)
23017 + (1 << VCI_KCBIT_TAGGED) |
23018 +#elif defined(CONFIG_TAGGING_GID16)
23019 + (2 << VCI_KCBIT_TAGGED) |
23020 +#elif defined(CONFIG_TAGGING_ID24)
23021 + (3 << VCI_KCBIT_TAGGED) |
23022 +#elif defined(CONFIG_TAGGING_INTERN)
23023 + (4 << VCI_KCBIT_TAGGED) |
23024 +#elif defined(CONFIG_TAGGING_RUNTIME)
23025 + (5 << VCI_KCBIT_TAGGED) |
23027 + (7 << VCI_KCBIT_TAGGED) |
23029 + (1 << VCI_KCBIT_PPTAG) |
23033 diff -NurpP --minimal linux-3.13.6/mm/memcontrol.c linux-3.13.6-vs2.3.6.11/mm/memcontrol.c
23034 --- linux-3.13.6/mm/memcontrol.c 2014-03-12 13:51:24.000000000 +0000
23035 +++ linux-3.13.6-vs2.3.6.11/mm/memcontrol.c 2014-02-25 11:26:10.000000000 +0000
23036 @@ -1056,6 +1056,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23037 return mem_cgroup_from_css(task_css(p, mem_cgroup_subsys_id));
23040 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23042 + return res_counter_read_u64(&mem->res, member);
23045 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23047 + return res_counter_read_u64(&mem->memsw, member);
23050 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23052 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23055 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23057 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23060 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23062 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23065 struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23067 struct mem_cgroup *memcg = NULL;
23068 diff -NurpP --minimal linux-3.13.6/mm/oom_kill.c linux-3.13.6-vs2.3.6.11/mm/oom_kill.c
23069 --- linux-3.13.6/mm/oom_kill.c 2014-03-12 13:51:24.000000000 +0000
23070 +++ linux-3.13.6-vs2.3.6.11/mm/oom_kill.c 2014-02-25 11:26:10.000000000 +0000
23072 #include <linux/freezer.h>
23073 #include <linux/ftrace.h>
23074 #include <linux/ratelimit.h>
23075 +#include <linux/reboot.h>
23076 +#include <linux/vs_context.h>
23078 #define CREATE_TRACE_POINTS
23079 #include <trace/events/oom.h>
23080 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23081 static bool oom_unkillable_task(struct task_struct *p,
23082 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23084 - if (is_global_init(p))
23085 + unsigned xid = vx_current_xid();
23087 + /* skip the init task, global and per guest */
23088 + if (task_is_init(p))
23090 if (p->flags & PF_KTHREAD)
23093 + /* skip other guest and host processes if oom in guest */
23094 + if (xid && vx_task_xid(p) != xid)
23097 /* When mem_cgroup_out_of_memory() and p is not member of the group */
23098 if (memcg && !task_in_mem_cgroup(p, memcg))
23100 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23101 dump_header(p, gfp_mask, order, memcg, nodemask);
23104 - pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23105 - message, task_pid_nr(p), p->comm, points);
23106 + pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23107 + message, task_pid_nr(p), p->xid, p->comm, points);
23111 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23113 /* mm cannot safely be dereferenced after task_unlock(victim) */
23115 - pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23116 - task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23117 + pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23118 + task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23119 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23120 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23121 task_unlock(victim);
23122 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23124 EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23126 +long vs_oom_action(unsigned int);
23129 * Try to acquire the OOM killer lock for the zones in zonelist. Returns zero
23130 * if a parallel OOM killing is already taking place that includes a zone in
23131 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23132 /* Found nothing?!?! Either we hang forever, or we panic. */
23134 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23135 - panic("Out of memory and no killable processes...\n");
23137 + /* avoid panic for guest OOM */
23138 + if (vx_current_xid())
23139 + vs_oom_action(LINUX_REBOOT_CMD_OOM);
23141 + panic("Out of memory and no killable processes...\n");
23143 if (p != (void *)-1UL) {
23144 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23145 diff -NurpP --minimal linux-3.13.6/mm/page_alloc.c linux-3.13.6-vs2.3.6.11/mm/page_alloc.c
23146 --- linux-3.13.6/mm/page_alloc.c 2014-01-22 20:39:14.000000000 +0000
23147 +++ linux-3.13.6-vs2.3.6.11/mm/page_alloc.c 2014-01-31 20:38:04.000000000 +0000
23149 #include <linux/page-debug-flags.h>
23150 #include <linux/hugetlb.h>
23151 #include <linux/sched/rt.h>
23152 +#include <linux/vs_base.h>
23153 +#include <linux/vs_limit.h>
23155 #include <asm/sections.h>
23156 #include <asm/tlbflush.h>
23157 @@ -2963,6 +2965,9 @@ void si_meminfo(struct sysinfo *val)
23158 val->totalhigh = totalhigh_pages;
23159 val->freehigh = nr_free_highpages();
23160 val->mem_unit = PAGE_SIZE;
23162 + if (vx_flags(VXF_VIRT_MEM, 0))
23163 + vx_vsi_meminfo(val);
23166 EXPORT_SYMBOL(si_meminfo);
23167 @@ -2987,6 +2992,9 @@ void si_meminfo_node(struct sysinfo *val
23170 val->mem_unit = PAGE_SIZE;
23172 + if (vx_flags(VXF_VIRT_MEM, 0))
23173 + vx_vsi_meminfo(val);
23177 diff -NurpP --minimal linux-3.13.6/mm/pgtable-generic.c linux-3.13.6-vs2.3.6.11/mm/pgtable-generic.c
23178 --- linux-3.13.6/mm/pgtable-generic.c 2014-01-22 20:39:14.000000000 +0000
23179 +++ linux-3.13.6-vs2.3.6.11/mm/pgtable-generic.c 2014-01-31 20:38:04.000000000 +0000
23181 * Copyright (C) 2010 Linus Torvalds
23184 +#include <linux/mm.h>
23186 #include <linux/pagemap.h>
23187 #include <asm/tlb.h>
23188 #include <asm-generic/pgtable.h>
23189 diff -NurpP --minimal linux-3.13.6/mm/shmem.c linux-3.13.6-vs2.3.6.11/mm/shmem.c
23190 --- linux-3.13.6/mm/shmem.c 2014-01-22 20:39:14.000000000 +0000
23191 +++ linux-3.13.6-vs2.3.6.11/mm/shmem.c 2014-01-31 20:38:04.000000000 +0000
23192 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23194 struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23196 - buf->f_type = TMPFS_MAGIC;
23197 + buf->f_type = TMPFS_SUPER_MAGIC;
23198 buf->f_bsize = PAGE_CACHE_SIZE;
23199 buf->f_namelen = NAME_MAX;
23200 if (sbinfo->max_blocks) {
23201 @@ -2639,7 +2639,7 @@ int shmem_fill_super(struct super_block
23202 sb->s_maxbytes = MAX_LFS_FILESIZE;
23203 sb->s_blocksize = PAGE_CACHE_SIZE;
23204 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23205 - sb->s_magic = TMPFS_MAGIC;
23206 + sb->s_magic = TMPFS_SUPER_MAGIC;
23207 sb->s_op = &shmem_ops;
23208 sb->s_time_gran = 1;
23209 #ifdef CONFIG_TMPFS_XATTR
23210 diff -NurpP --minimal linux-3.13.6/mm/slab.c linux-3.13.6-vs2.3.6.11/mm/slab.c
23211 --- linux-3.13.6/mm/slab.c 2014-01-22 20:39:14.000000000 +0000
23212 +++ linux-3.13.6-vs2.3.6.11/mm/slab.c 2014-01-31 20:38:04.000000000 +0000
23213 @@ -322,6 +322,8 @@ static void kmem_cache_node_init(struct
23214 #define STATS_INC_FREEMISS(x) do { } while (0)
23217 +#include "slab_vs.h"
23222 @@ -3240,6 +3242,7 @@ slab_alloc_node(struct kmem_cache *cache
23223 /* ___cache_alloc_node can fall back to other nodes */
23224 ptr = ____cache_alloc_node(cachep, flags, nodeid);
23226 + vx_slab_alloc(cachep, flags);
23227 local_irq_restore(save_flags);
23228 ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23229 kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23230 @@ -3430,6 +3433,7 @@ static inline void __cache_free(struct k
23232 kmemleak_free_recursive(objp, cachep->flags);
23233 objp = cache_free_debugcheck(cachep, objp, caller);
23234 + vx_slab_free(cachep);
23236 kmemcheck_slab_free(cachep, objp, cachep->object_size);
23238 diff -NurpP --minimal linux-3.13.6/mm/slab_vs.h linux-3.13.6-vs2.3.6.11/mm/slab_vs.h
23239 --- linux-3.13.6/mm/slab_vs.h 1970-01-01 00:00:00.000000000 +0000
23240 +++ linux-3.13.6-vs2.3.6.11/mm/slab_vs.h 2014-01-31 20:38:04.000000000 +0000
23243 +#include <linux/vserver/context.h>
23245 +#include <linux/vs_context.h>
23248 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23250 + int what = gfp_zone(cachep->allocflags);
23251 + struct vx_info *vxi = current_vx_info();
23256 + atomic_add(cachep->size, &vxi->cacct.slab[what]);
23260 +void vx_slab_free(struct kmem_cache *cachep)
23262 + int what = gfp_zone(cachep->allocflags);
23263 + struct vx_info *vxi = current_vx_info();
23268 + atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23271 diff -NurpP --minimal linux-3.13.6/mm/swapfile.c linux-3.13.6-vs2.3.6.11/mm/swapfile.c
23272 --- linux-3.13.6/mm/swapfile.c 2014-03-12 13:51:25.000000000 +0000
23273 +++ linux-3.13.6-vs2.3.6.11/mm/swapfile.c 2014-02-25 11:26:10.000000000 +0000
23275 #include <asm/tlbflush.h>
23276 #include <linux/swapops.h>
23277 #include <linux/page_cgroup.h>
23278 +#include <linux/vs_base.h>
23280 static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23282 @@ -2042,6 +2043,16 @@ static int swap_show(struct seq_file *sw
23284 if (si == SEQ_START_TOKEN) {
23285 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23286 + if (vx_flags(VXF_VIRT_MEM, 0)) {
23287 + struct sysinfo si;
23289 + vx_vsi_swapinfo(&si);
23290 + if (si.totalswap < (1 << 10))
23292 + seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23293 + "hdv0", "partition", si.totalswap >> 10,
23294 + (si.totalswap - si.freeswap) >> 10, -1);
23299 @@ -2589,6 +2600,8 @@ void si_swapinfo(struct sysinfo *val)
23300 val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
23301 val->totalswap = total_swap_pages + nr_to_be_unused;
23302 spin_unlock(&swap_lock);
23303 + if (vx_flags(VXF_VIRT_MEM, 0))
23304 + vx_vsi_swapinfo(val);
23308 diff -NurpP --minimal linux-3.13.6/net/bridge/br_multicast.c linux-3.13.6-vs2.3.6.11/net/bridge/br_multicast.c
23309 --- linux-3.13.6/net/bridge/br_multicast.c 2014-01-22 20:39:14.000000000 +0000
23310 +++ linux-3.13.6-vs2.3.6.11/net/bridge/br_multicast.c 2014-01-31 20:38:04.000000000 +0000
23311 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
23312 ip6h->hop_limit = 1;
23313 ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23314 if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23316 + &ip6h->saddr, NULL)) {
23320 diff -NurpP --minimal linux-3.13.6/net/core/dev.c linux-3.13.6-vs2.3.6.11/net/core/dev.c
23321 --- linux-3.13.6/net/core/dev.c 2014-03-12 13:51:25.000000000 +0000
23322 +++ linux-3.13.6-vs2.3.6.11/net/core/dev.c 2014-03-12 15:51:08.000000000 +0000
23323 @@ -122,6 +122,7 @@
23324 #include <linux/in.h>
23325 #include <linux/jhash.h>
23326 #include <linux/random.h>
23327 +#include <linux/vs_inet.h>
23328 #include <trace/events/napi.h>
23329 #include <trace/events/net.h>
23330 #include <trace/events/skb.h>
23331 @@ -669,7 +670,8 @@ struct net_device *__dev_get_by_name(str
23332 struct hlist_head *head = dev_name_hash(net, name);
23334 hlist_for_each_entry(dev, head, name_hlist)
23335 - if (!strncmp(dev->name, name, IFNAMSIZ))
23336 + if (!strncmp(dev->name, name, IFNAMSIZ) &&
23337 + nx_dev_visible(current_nx_info(), dev))
23341 @@ -694,7 +696,8 @@ struct net_device *dev_get_by_name_rcu(s
23342 struct hlist_head *head = dev_name_hash(net, name);
23344 hlist_for_each_entry_rcu(dev, head, name_hlist)
23345 - if (!strncmp(dev->name, name, IFNAMSIZ))
23346 + if (!strncmp(dev->name, name, IFNAMSIZ) &&
23347 + nx_dev_visible(current_nx_info(), dev))
23351 @@ -744,7 +747,8 @@ struct net_device *__dev_get_by_index(st
23352 struct hlist_head *head = dev_index_hash(net, ifindex);
23354 hlist_for_each_entry(dev, head, index_hlist)
23355 - if (dev->ifindex == ifindex)
23356 + if ((dev->ifindex == ifindex) &&
23357 + nx_dev_visible(current_nx_info(), dev))
23361 @@ -762,7 +766,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
23362 * about locking. The caller must hold RCU lock.
23365 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23366 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
23368 struct net_device *dev;
23369 struct hlist_head *head = dev_index_hash(net, ifindex);
23370 @@ -773,6 +777,16 @@ struct net_device *dev_get_by_index_rcu(
23374 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
23376 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23378 + struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
23380 + if (nx_dev_visible(current_nx_info(), dev))
23384 EXPORT_SYMBOL(dev_get_by_index_rcu);
23387 @@ -855,7 +869,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
23389 for_each_netdev_rcu(net, dev)
23390 if (dev->type == type &&
23391 - !memcmp(dev->dev_addr, ha, dev->addr_len))
23392 + !memcmp(dev->dev_addr, ha, dev->addr_len) &&
23393 + nx_dev_visible(current_nx_info(), dev))
23397 @@ -867,9 +882,11 @@ struct net_device *__dev_getfirstbyhwtyp
23398 struct net_device *dev;
23401 - for_each_netdev(net, dev)
23402 - if (dev->type == type)
23403 + for_each_netdev(net, dev) {
23404 + if ((dev->type == type) &&
23405 + nx_dev_visible(current_nx_info(), dev))
23411 @@ -881,7 +898,8 @@ struct net_device *dev_getfirstbyhwtype(
23414 for_each_netdev_rcu(net, dev)
23415 - if (dev->type == type) {
23416 + if ((dev->type == type) &&
23417 + nx_dev_visible(current_nx_info(), dev)) {
23421 @@ -909,7 +927,8 @@ struct net_device *dev_get_by_flags_rcu(
23424 for_each_netdev_rcu(net, dev) {
23425 - if (((dev->flags ^ if_flags) & mask) == 0) {
23426 + if ((((dev->flags ^ if_flags) & mask) == 0) &&
23427 + nx_dev_visible(current_nx_info(), dev)) {
23431 @@ -987,6 +1006,8 @@ static int __dev_alloc_name(struct net *
23433 if (i < 0 || i >= max_netdevices)
23435 + if (!nx_dev_visible(current_nx_info(), d))
23438 /* avoid cases where sscanf is not exact inverse of printf */
23439 snprintf(buf, IFNAMSIZ, name, i);
23440 diff -NurpP --minimal linux-3.13.6/net/core/net-procfs.c linux-3.13.6-vs2.3.6.11/net/core/net-procfs.c
23441 --- linux-3.13.6/net/core/net-procfs.c 2013-11-25 15:45:09.000000000 +0000
23442 +++ linux-3.13.6-vs2.3.6.11/net/core/net-procfs.c 2014-01-31 20:38:04.000000000 +0000
23444 #include <linux/netdevice.h>
23445 #include <linux/proc_fs.h>
23446 #include <linux/seq_file.h>
23447 +#include <linux/vs_inet.h>
23448 #include <net/wext.h>
23450 #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
23451 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
23452 static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
23454 struct rtnl_link_stats64 temp;
23455 - const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
23456 + const struct rtnl_link_stats64 *stats;
23458 + /* device visible inside network context? */
23459 + if (!nx_dev_visible(current_nx_info(), dev))
23462 + stats = dev_get_stats(dev, &temp);
23463 seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
23464 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
23465 dev->name, stats->rx_bytes, stats->rx_packets,
23466 diff -NurpP --minimal linux-3.13.6/net/core/rtnetlink.c linux-3.13.6-vs2.3.6.11/net/core/rtnetlink.c
23467 --- linux-3.13.6/net/core/rtnetlink.c 2014-01-22 20:39:15.000000000 +0000
23468 +++ linux-3.13.6-vs2.3.6.11/net/core/rtnetlink.c 2014-01-31 22:32:10.000000000 +0000
23469 @@ -1090,6 +1090,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
23470 hlist_for_each_entry_rcu(dev, head, index_hlist) {
23473 + if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
23475 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
23476 NETLINK_CB(cb->skb).portid,
23477 cb->nlh->nlmsg_seq, 0,
23478 @@ -1992,6 +1994,9 @@ void rtmsg_ifinfo(int type, struct net_d
23479 int err = -ENOBUFS;
23480 size_t if_info_size;
23482 + if (!nx_dev_visible(current_nx_info(), dev))
23485 skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), flags);
23488 diff -NurpP --minimal linux-3.13.6/net/core/sock.c linux-3.13.6-vs2.3.6.11/net/core/sock.c
23489 --- linux-3.13.6/net/core/sock.c 2014-03-12 13:51:25.000000000 +0000
23490 +++ linux-3.13.6-vs2.3.6.11/net/core/sock.c 2014-03-12 15:51:08.000000000 +0000
23491 @@ -133,6 +133,10 @@
23492 #include <net/netprio_cgroup.h>
23494 #include <linux/filter.h>
23495 +#include <linux/vs_socket.h>
23496 +#include <linux/vs_limit.h>
23497 +#include <linux/vs_context.h>
23498 +#include <linux/vs_network.h>
23500 #include <trace/events/sock.h>
23502 @@ -1279,6 +1283,8 @@ static struct sock *sk_prot_alloc(struct
23504 sk_tx_queue_clear(sk);
23506 + sock_vx_init(sk);
23507 + sock_nx_init(sk);
23511 @@ -1387,6 +1393,11 @@ static void __sk_free(struct sock *sk)
23512 put_cred(sk->sk_peer_cred);
23513 put_pid(sk->sk_peer_pid);
23514 put_net(sock_net(sk));
23516 + clr_vx_info(&sk->sk_vx_info);
23518 + clr_nx_info(&sk->sk_nx_info);
23520 sk_prot_free(sk->sk_prot_creator, sk);
23523 @@ -1447,6 +1458,8 @@ struct sock *sk_clone_lock(const struct
23526 get_net(sock_net(newsk));
23527 + sock_vx_init(newsk);
23528 + sock_nx_init(newsk);
23529 sk_node_init(&newsk->sk_node);
23530 sock_lock_init(newsk);
23531 bh_lock_sock(newsk);
23532 @@ -1503,6 +1516,12 @@ struct sock *sk_clone_lock(const struct
23534 atomic_set(&newsk->sk_refcnt, 2);
23536 + set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
23537 + newsk->sk_xid = sk->sk_xid;
23538 + vx_sock_inc(newsk);
23539 + set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
23540 + newsk->sk_nid = sk->sk_nid;
23543 * Increment the counter in the same struct proto as the master
23544 * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
23545 @@ -2340,6 +2359,12 @@ void sock_init_data(struct socket *sock,
23547 sk->sk_stamp = ktime_set(-1L, 0);
23549 + set_vx_info(&sk->sk_vx_info, current_vx_info());
23550 + sk->sk_xid = vx_current_xid();
23552 + set_nx_info(&sk->sk_nx_info, current_nx_info());
23553 + sk->sk_nid = nx_current_nid();
23555 #ifdef CONFIG_NET_RX_BUSY_POLL
23556 sk->sk_napi_id = 0;
23557 sk->sk_ll_usec = sysctl_net_busy_read;
23558 diff -NurpP --minimal linux-3.13.6/net/ipv4/af_inet.c linux-3.13.6-vs2.3.6.11/net/ipv4/af_inet.c
23559 --- linux-3.13.6/net/ipv4/af_inet.c 2014-01-22 20:39:15.000000000 +0000
23560 +++ linux-3.13.6-vs2.3.6.11/net/ipv4/af_inet.c 2014-01-31 20:38:04.000000000 +0000
23561 @@ -118,6 +118,7 @@
23562 #ifdef CONFIG_IP_MROUTE
23563 #include <linux/mroute.h>
23565 +#include <linux/vs_limit.h>
23568 /* The inetsw table contains everything that inet_create needs to
23569 @@ -309,10 +310,13 @@ lookup_protocol:
23573 + if ((protocol == IPPROTO_ICMP) &&
23574 + nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
23576 if (sock->type == SOCK_RAW && !kern &&
23577 !ns_capable(net->user_ns, CAP_NET_RAW))
23578 goto out_rcu_unlock;
23581 sock->ops = answer->ops;
23582 answer_prot = answer->prot;
23583 answer_no_check = answer->no_check;
23584 @@ -433,6 +437,7 @@ int inet_bind(struct socket *sock, struc
23585 struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
23586 struct sock *sk = sock->sk;
23587 struct inet_sock *inet = inet_sk(sk);
23588 + struct nx_v4_sock_addr nsa;
23589 struct net *net = sock_net(sk);
23590 unsigned short snum;
23592 @@ -457,7 +462,11 @@ int inet_bind(struct socket *sock, struc
23596 - chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
23597 + err = v4_map_sock_addr(inet, addr, &nsa);
23601 + chk_addr_ret = inet_addr_type(net, nsa.saddr);
23603 /* Not specified by any standard per-se, however it breaks too
23604 * many applications when removed. It is unfortunate since
23605 @@ -469,7 +478,7 @@ int inet_bind(struct socket *sock, struc
23606 err = -EADDRNOTAVAIL;
23607 if (!sysctl_ip_nonlocal_bind &&
23608 !(inet->freebind || inet->transparent) &&
23609 - addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
23610 + nsa.saddr != htonl(INADDR_ANY) &&
23611 chk_addr_ret != RTN_LOCAL &&
23612 chk_addr_ret != RTN_MULTICAST &&
23613 chk_addr_ret != RTN_BROADCAST)
23614 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
23615 if (sk->sk_state != TCP_CLOSE || inet->inet_num)
23616 goto out_release_sock;
23618 - inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23619 + v4_set_sock_addr(inet, &nsa);
23620 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23621 inet->inet_saddr = 0; /* Use device */
23623 @@ -714,11 +723,13 @@ int inet_getname(struct socket *sock, st
23626 sin->sin_port = inet->inet_dport;
23627 - sin->sin_addr.s_addr = inet->inet_daddr;
23628 + sin->sin_addr.s_addr =
23629 + nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
23631 __be32 addr = inet->inet_rcv_saddr;
23633 addr = inet->inet_saddr;
23634 + addr = nx_map_sock_lback(sk->sk_nx_info, addr);
23635 sin->sin_port = inet->inet_sport;
23636 sin->sin_addr.s_addr = addr;
23638 diff -NurpP --minimal linux-3.13.6/net/ipv4/arp.c linux-3.13.6-vs2.3.6.11/net/ipv4/arp.c
23639 --- linux-3.13.6/net/ipv4/arp.c 2013-11-25 15:47:06.000000000 +0000
23640 +++ linux-3.13.6-vs2.3.6.11/net/ipv4/arp.c 2014-01-31 20:38:04.000000000 +0000
23641 @@ -1336,6 +1336,7 @@ static void arp_format_neigh_entry(struc
23642 struct net_device *dev = n->dev;
23643 int hatype = dev->type;
23645 + /* FIXME: check for network context */
23646 read_lock(&n->lock);
23647 /* Convert hardware address to XX:XX:XX:XX ... form. */
23648 #if IS_ENABLED(CONFIG_AX25)
23649 @@ -1367,6 +1368,7 @@ static void arp_format_pneigh_entry(stru
23650 int hatype = dev ? dev->type : 0;
23653 + /* FIXME: check for network context */
23654 sprintf(tbuf, "%pI4", n->key);
23655 seq_printf(seq, "%-16s 0x%-10x0x%-10x%s * %s\n",
23656 tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
23657 diff -NurpP --minimal linux-3.13.6/net/ipv4/devinet.c linux-3.13.6-vs2.3.6.11/net/ipv4/devinet.c
23658 --- linux-3.13.6/net/ipv4/devinet.c 2014-03-12 13:51:25.000000000 +0000
23659 +++ linux-3.13.6-vs2.3.6.11/net/ipv4/devinet.c 2014-03-12 15:51:08.000000000 +0000
23660 @@ -527,6 +527,7 @@ struct in_device *inetdev_by_index(struc
23662 EXPORT_SYMBOL(inetdev_by_index);
23665 /* Called only from RTNL semaphored context. No locks. */
23667 struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
23668 @@ -947,6 +948,8 @@ int devinet_ioctl(struct net *net, unsig
23670 in_dev = __in_dev_get_rtnl(dev);
23672 + struct nx_info *nxi = current_nx_info();
23674 if (tryaddrmatch) {
23675 /* Matthias Andree */
23676 /* compare label and address (4.4BSD style) */
23677 @@ -955,6 +958,8 @@ int devinet_ioctl(struct net *net, unsig
23678 This is checked above. */
23679 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23680 ifap = &ifa->ifa_next) {
23681 + if (!nx_v4_ifa_visible(nxi, ifa))
23683 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
23684 sin_orig.sin_addr.s_addr ==
23686 @@ -967,9 +972,12 @@ int devinet_ioctl(struct net *net, unsig
23687 comparing just the label */
23689 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23690 - ifap = &ifa->ifa_next)
23691 + ifap = &ifa->ifa_next) {
23692 + if (!nx_v4_ifa_visible(nxi, ifa))
23694 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
23700 @@ -1123,6 +1131,8 @@ static int inet_gifconf(struct net_devic
23703 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
23704 + if (!nx_v4_ifa_visible(current_nx_info(), ifa))
23707 done += sizeof(ifr);
23709 @@ -1524,6 +1534,7 @@ static int inet_dump_ifaddr(struct sk_bu
23710 struct net_device *dev;
23711 struct in_device *in_dev;
23712 struct in_ifaddr *ifa;
23713 + struct sock *sk = skb->sk;
23714 struct hlist_head *head;
23717 @@ -1547,6 +1558,8 @@ static int inet_dump_ifaddr(struct sk_bu
23719 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
23720 ifa = ifa->ifa_next, ip_idx++) {
23721 + if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
23723 if (ip_idx < s_ip_idx)
23725 if (inet_fill_ifaddr(skb, ifa,
23726 diff -NurpP --minimal linux-3.13.6/net/ipv4/fib_trie.c linux-3.13.6-vs2.3.6.11/net/ipv4/fib_trie.c
23727 --- linux-3.13.6/net/ipv4/fib_trie.c 2014-01-22 20:39:15.000000000 +0000
23728 +++ linux-3.13.6-vs2.3.6.11/net/ipv4/fib_trie.c 2014-01-31 20:38:04.000000000 +0000
23729 @@ -2530,6 +2530,7 @@ static int fib_route_seq_show(struct seq
23731 seq_setwidth(seq, 127);
23733 + /* FIXME: check for network context? */
23736 "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
23737 diff -NurpP --minimal linux-3.13.6/net/ipv4/inet_connection_sock.c linux-3.13.6-vs2.3.6.11/net/ipv4/inet_connection_sock.c
23738 --- linux-3.13.6/net/ipv4/inet_connection_sock.c 2014-01-22 20:39:15.000000000 +0000
23739 +++ linux-3.13.6-vs2.3.6.11/net/ipv4/inet_connection_sock.c 2014-02-01 00:33:11.000000000 +0000
23740 @@ -45,6 +45,37 @@ void inet_get_local_port_range(struct ne
23742 EXPORT_SYMBOL(inet_get_local_port_range);
23744 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
23746 + __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr,
23747 + sk2_rcv_saddr = sk2->sk_rcv_saddr;
23749 + if (inet_v6_ipv6only(sk2))
23752 + if (sk1_rcv_saddr &&
23754 + sk1_rcv_saddr == sk2_rcv_saddr)
23757 + if (sk1_rcv_saddr &&
23758 + !sk2_rcv_saddr &&
23759 + v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
23762 + if (sk2_rcv_saddr &&
23763 + !sk1_rcv_saddr &&
23764 + v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
23767 + if (!sk1_rcv_saddr &&
23768 + !sk2_rcv_saddr &&
23769 + nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
23775 int inet_csk_bind_conflict(const struct sock *sk,
23776 const struct inet_bind_bucket *tb, bool relax)
23778 @@ -72,15 +103,13 @@ int inet_csk_bind_conflict(const struct
23779 (sk2->sk_state != TCP_TIME_WAIT &&
23780 !uid_eq(uid, sock_i_uid(sk2))))) {
23782 - if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23783 - sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23784 + if (ipv4_rcv_saddr_equal(sk, sk2))
23787 if (!relax && reuse && sk2->sk_reuse &&
23788 sk2->sk_state != TCP_LISTEN) {
23790 - if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23791 - sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23792 + if (ipv4_rcv_saddr_equal(sk, sk2))
23796 diff -NurpP --minimal linux-3.13.6/net/ipv4/inet_diag.c linux-3.13.6-vs2.3.6.11/net/ipv4/inet_diag.c
23797 --- linux-3.13.6/net/ipv4/inet_diag.c 2014-02-01 02:17:51.000000000 +0000
23798 +++ linux-3.13.6-vs2.3.6.11/net/ipv4/inet_diag.c 2014-02-01 02:32:22.000000000 +0000
23801 #include <linux/inet.h>
23802 #include <linux/stddef.h>
23803 +#include <linux/vs_network.h>
23804 +#include <linux/vs_inet.h>
23806 #include <linux/inet_diag.h>
23807 #include <linux/sock_diag.h>
23808 @@ -110,8 +112,10 @@ int inet_sk_diag_fill(struct sock *sk, s
23809 memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23810 memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23812 - r->id.idiag_src[0] = inet->inet_rcv_saddr;
23813 - r->id.idiag_dst[0] = inet->inet_daddr;
23814 + r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
23815 + inet->inet_rcv_saddr);
23816 + r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
23817 + inet->inet_daddr);
23819 if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
23821 @@ -254,8 +258,8 @@ static int inet_twsk_diag_fill(struct in
23822 memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23823 memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23825 - r->id.idiag_src[0] = tw->tw_rcv_saddr;
23826 - r->id.idiag_dst[0] = tw->tw_daddr;
23827 + r->id.idiag_src[0] = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
23828 + r->id.idiag_dst[0] = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
23830 r->idiag_state = tw->tw_substate;
23831 r->idiag_timer = 3;
23832 @@ -298,12 +302,14 @@ int inet_diag_dump_one_icsk(struct inet_
23835 if (req->sdiag_family == AF_INET) {
23836 + /* TODO: lback */
23837 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
23838 req->id.idiag_dport, req->id.idiag_src[0],
23839 req->id.idiag_sport, req->id.idiag_if);
23841 #if IS_ENABLED(CONFIG_IPV6)
23842 else if (req->sdiag_family == AF_INET6) {
23843 + /* TODO: lback */
23844 sk = inet6_lookup(net, hashinfo,
23845 (struct in6_addr *)req->id.idiag_dst,
23846 req->id.idiag_dport,
23847 @@ -501,6 +507,7 @@ int inet_diag_bc_sk(const struct nlattr
23851 + /* TODO: lback */
23852 entry.saddr = &inet->inet_rcv_saddr;
23853 entry.daddr = &inet->inet_daddr;
23855 @@ -659,6 +666,7 @@ static int inet_twsk_diag_dump(struct so
23859 + /* TODO: lback */
23860 entry.saddr = &tw->tw_rcv_saddr;
23861 entry.daddr = &tw->tw_daddr;
23863 @@ -741,8 +749,8 @@ static int inet_diag_fill_req(struct sk_
23864 memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23865 memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23867 - r->id.idiag_src[0] = ireq->ir_loc_addr;
23868 - r->id.idiag_dst[0] = ireq->ir_rmt_addr;
23869 + r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_loc_addr);
23870 + r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_rmt_addr);
23872 r->idiag_expires = jiffies_to_msecs(tmo);
23873 r->idiag_rqueue = 0;
23874 @@ -806,6 +814,7 @@ static int inet_diag_dump_reqs(struct sk
23878 + /* TODO: lback */
23880 inet_diag_req_addrs(sk, req, &entry);
23881 entry.dport = ntohs(ireq->ir_rmt_port);
23882 @@ -862,6 +871,8 @@ void inet_diag_dump_icsk(struct inet_has
23883 if (!net_eq(sock_net(sk), net))
23886 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23891 @@ -934,6 +945,8 @@ skip_listen_ht:
23893 if (!net_eq(sock_net(sk), net))
23895 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23899 state = (sk->sk_state == TCP_TIME_WAIT) ?
23900 diff -NurpP --minimal linux-3.13.6/net/ipv4/inet_hashtables.c linux-3.13.6-vs2.3.6.11/net/ipv4/inet_hashtables.c
23901 --- linux-3.13.6/net/ipv4/inet_hashtables.c 2014-01-22 20:39:15.000000000 +0000
23902 +++ linux-3.13.6-vs2.3.6.11/net/ipv4/inet_hashtables.c 2014-01-31 20:38:04.000000000 +0000
23904 #include <net/inet_connection_sock.h>
23905 #include <net/inet_hashtables.h>
23906 #include <net/secure_seq.h>
23907 +#include <net/route.h>
23908 #include <net/ip.h>
23910 static unsigned int inet_ehashfn(struct net *net, const __be32 laddr,
23911 @@ -181,6 +182,11 @@ static inline int compute_score(struct s
23912 if (rcv_saddr != daddr)
23916 + /* block non nx_info ips */
23917 + if (!v4_addr_in_nx_info(sk->sk_nx_info,
23918 + daddr, NXA_MASK_BIND))
23921 if (sk->sk_bound_dev_if) {
23922 if (sk->sk_bound_dev_if != dif)
23923 @@ -198,7 +204,6 @@ static inline int compute_score(struct s
23924 * wildcarded during the search since they can never be otherwise.
23928 struct sock *__inet_lookup_listener(struct net *net,
23929 struct inet_hashinfo *hashinfo,
23930 const __be32 saddr, __be16 sport,
23931 @@ -234,6 +239,7 @@ begin:
23932 phash = next_pseudo_random32(phash);
23937 * if the nulls value we got at the end of this lookup is
23938 * not the expected one, we must restart lookup.
23939 diff -NurpP --minimal linux-3.13.6/net/ipv4/netfilter.c linux-3.13.6-vs2.3.6.11/net/ipv4/netfilter.c
23940 --- linux-3.13.6/net/ipv4/netfilter.c 2013-07-14 17:01:37.000000000 +0000
23941 +++ linux-3.13.6-vs2.3.6.11/net/ipv4/netfilter.c 2014-01-31 20:38:04.000000000 +0000
23943 #include <linux/skbuff.h>
23944 #include <linux/gfp.h>
23945 #include <linux/export.h>
23946 -#include <net/route.h>
23947 +// #include <net/route.h>
23948 #include <net/xfrm.h>
23949 #include <net/ip.h>
23950 #include <net/netfilter/nf_queue.h>
23951 diff -NurpP --minimal linux-3.13.6/net/ipv4/raw.c linux-3.13.6-vs2.3.6.11/net/ipv4/raw.c
23952 --- linux-3.13.6/net/ipv4/raw.c 2014-01-22 20:39:15.000000000 +0000
23953 +++ linux-3.13.6-vs2.3.6.11/net/ipv4/raw.c 2014-01-31 20:38:04.000000000 +0000
23954 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
23956 if (net_eq(sock_net(sk), net) && inet->inet_num == num &&
23957 !(inet->inet_daddr && inet->inet_daddr != raddr) &&
23958 - !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
23959 + v4_sock_addr_match(sk->sk_nx_info, inet, laddr) &&
23960 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23961 goto found; /* gotcha */
23963 @@ -397,6 +397,12 @@ static int raw_send_hdrinc(struct sock *
23964 icmp_out_count(net, ((struct icmphdr *)
23965 skb_transport_header(skb))->type);
23968 + if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
23969 + sk->sk_nx_info &&
23970 + !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
23973 err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
23974 rt->dst.dev, dst_output);
23976 @@ -585,6 +591,16 @@ static int raw_sendmsg(struct kiocb *ioc
23980 + if (sk->sk_nx_info) {
23981 + rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
23982 + if (IS_ERR(rt)) {
23983 + err = PTR_ERR(rt);
23990 security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
23991 rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
23993 @@ -661,17 +677,19 @@ static int raw_bind(struct sock *sk, str
23995 struct inet_sock *inet = inet_sk(sk);
23996 struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
23997 + struct nx_v4_sock_addr nsa = { 0 };
24001 if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24003 - chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24004 + v4_map_sock_addr(inet, addr, &nsa);
24005 + chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24006 ret = -EADDRNOTAVAIL;
24007 - if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24008 + if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24009 chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24011 - inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24012 + v4_set_sock_addr(inet, &nsa);
24013 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24014 inet->inet_saddr = 0; /* Use device */
24016 @@ -720,7 +738,8 @@ static int raw_recvmsg(struct kiocb *ioc
24017 /* Copy the address. */
24019 sin->sin_family = AF_INET;
24020 - sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24021 + sin->sin_addr.s_addr =
24022 + nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24024 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24025 *addr_len = sizeof(*sin);
24026 @@ -916,7 +935,8 @@ static struct sock *raw_get_first(struct
24027 for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24029 sk_for_each(sk, &state->h->ht[state->bucket])
24030 - if (sock_net(sk) == seq_file_net(seq))
24031 + if ((sock_net(sk) == seq_file_net(seq)) &&
24032 + nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24036 @@ -932,7 +952,8 @@ static struct sock *raw_get_next(struct
24040 - } while (sk && sock_net(sk) != seq_file_net(seq));
24041 + } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24042 + !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24044 if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24045 sk = sk_head(&state->h->ht[state->bucket]);
24046 diff -NurpP --minimal linux-3.13.6/net/ipv4/route.c linux-3.13.6-vs2.3.6.11/net/ipv4/route.c
24047 --- linux-3.13.6/net/ipv4/route.c 2014-03-12 13:51:25.000000000 +0000
24048 +++ linux-3.13.6-vs2.3.6.11/net/ipv4/route.c 2014-03-12 15:51:08.000000000 +0000
24049 @@ -2063,7 +2063,7 @@ struct rtable *__ip_route_output_key(str
24052 if (fl4->flowi4_oif) {
24053 - dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24054 + dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24055 rth = ERR_PTR(-ENODEV);
24056 if (dev_out == NULL)
24058 diff -NurpP --minimal linux-3.13.6/net/ipv4/tcp.c linux-3.13.6-vs2.3.6.11/net/ipv4/tcp.c
24059 --- linux-3.13.6/net/ipv4/tcp.c 2014-01-22 20:39:15.000000000 +0000
24060 +++ linux-3.13.6-vs2.3.6.11/net/ipv4/tcp.c 2014-01-31 20:38:04.000000000 +0000
24061 @@ -268,6 +268,7 @@
24062 #include <linux/crypto.h>
24063 #include <linux/time.h>
24064 #include <linux/slab.h>
24065 +#include <linux/in.h>
24067 #include <net/icmp.h>
24068 #include <net/inet_common.h>
24069 diff -NurpP --minimal linux-3.13.6/net/ipv4/tcp_ipv4.c linux-3.13.6-vs2.3.6.11/net/ipv4/tcp_ipv4.c
24070 --- linux-3.13.6/net/ipv4/tcp_ipv4.c 2014-01-22 20:39:15.000000000 +0000
24071 +++ linux-3.13.6-vs2.3.6.11/net/ipv4/tcp_ipv4.c 2014-02-01 12:30:30.000000000 +0000
24072 @@ -2227,6 +2227,12 @@ static void *listening_get_next(struct s
24073 req = req->dl_next;
24076 + vxdprintk(VXD_CBIT(net, 6),
24077 + "sk,req: %p [#%d] (from %d)", req->sk,
24078 + (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24080 + !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24082 if (req->rsk_ops->family == st->family) {
24085 @@ -2251,6 +2257,10 @@ get_req:
24088 sk_nulls_for_each_from(sk, node) {
24089 + vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24090 + sk, sk->sk_nid, nx_current_nid());
24091 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24093 if (!net_eq(sock_net(sk), net))
24095 if (sk->sk_family == st->family) {
24096 @@ -2325,6 +2335,11 @@ static void *established_get_first(struc
24098 spin_lock_bh(lock);
24099 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24100 + vxdprintk(VXD_CBIT(net, 6),
24101 + "sk,egf: %p [#%d] (from %d)",
24102 + sk, sk->sk_nid, nx_current_nid());
24103 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24105 if (sk->sk_family != st->family ||
24106 !net_eq(sock_net(sk), net)) {
24108 @@ -2351,6 +2366,11 @@ static void *established_get_next(struct
24109 sk = sk_nulls_next(sk);
24111 sk_nulls_for_each_from(sk, node) {
24112 + vxdprintk(VXD_CBIT(net, 6),
24113 + "sk,egn: %p [#%d] (from %d)",
24114 + sk, sk->sk_nid, nx_current_nid());
24115 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24117 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24120 @@ -2549,9 +2569,9 @@ static void get_openreq4(const struct so
24121 seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24122 " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d %pK",
24124 - ireq->ir_loc_addr,
24125 + nx_map_sock_lback(current_nx_info(), ireq->ir_loc_addr),
24126 ntohs(inet_sk(sk)->inet_sport),
24127 - ireq->ir_rmt_addr,
24128 + nx_map_sock_lback(current_nx_info(), ireq->ir_rmt_addr),
24129 ntohs(ireq->ir_rmt_port),
24131 0, 0, /* could print option size, but that is af dependent. */
24132 @@ -2573,8 +2593,8 @@ static void get_tcp4_sock(struct sock *s
24133 const struct inet_connection_sock *icsk = inet_csk(sk);
24134 const struct inet_sock *inet = inet_sk(sk);
24135 struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24136 - __be32 dest = inet->inet_daddr;
24137 - __be32 src = inet->inet_rcv_saddr;
24138 + __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24139 + __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24140 __u16 destp = ntohs(inet->inet_dport);
24141 __u16 srcp = ntohs(inet->inet_sport);
24143 @@ -2631,8 +2651,8 @@ static void get_timewait4_sock(const str
24145 long delta = tw->tw_ttd - jiffies;
24147 - dest = tw->tw_daddr;
24148 - src = tw->tw_rcv_saddr;
24149 + dest = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24150 + src = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24151 destp = ntohs(tw->tw_dport);
24152 srcp = ntohs(tw->tw_sport);
24154 diff -NurpP --minimal linux-3.13.6/net/ipv4/tcp_minisocks.c linux-3.13.6-vs2.3.6.11/net/ipv4/tcp_minisocks.c
24155 --- linux-3.13.6/net/ipv4/tcp_minisocks.c 2014-01-22 20:39:15.000000000 +0000
24156 +++ linux-3.13.6-vs2.3.6.11/net/ipv4/tcp_minisocks.c 2014-01-31 20:38:04.000000000 +0000
24158 #include <linux/slab.h>
24159 #include <linux/sysctl.h>
24160 #include <linux/workqueue.h>
24161 +#include <linux/vs_limit.h>
24162 +#include <linux/vs_socket.h>
24163 +#include <linux/vs_context.h>
24164 #include <net/tcp.h>
24165 #include <net/inet_common.h>
24166 #include <net/xfrm.h>
24167 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int
24168 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24169 tcptw->tw_ts_offset = tp->tsoffset;
24171 + tw->tw_xid = sk->sk_xid;
24172 + tw->tw_vx_info = NULL;
24173 + tw->tw_nid = sk->sk_nid;
24174 + tw->tw_nx_info = NULL;
24176 #if IS_ENABLED(CONFIG_IPV6)
24177 if (tw->tw_family == PF_INET6) {
24178 struct ipv6_pinfo *np = inet6_sk(sk);
24179 diff -NurpP --minimal linux-3.13.6/net/ipv4/udp.c linux-3.13.6-vs2.3.6.11/net/ipv4/udp.c
24180 --- linux-3.13.6/net/ipv4/udp.c 2014-01-22 20:39:15.000000000 +0000
24181 +++ linux-3.13.6-vs2.3.6.11/net/ipv4/udp.c 2014-01-31 22:20:27.000000000 +0000
24182 @@ -308,14 +308,7 @@ fail:
24184 EXPORT_SYMBOL(udp_lib_get_port);
24186 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24188 - struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24190 - return (!ipv6_only_sock(sk2) &&
24191 - (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24192 - inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24194 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24196 static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24198 @@ -350,6 +343,11 @@ static inline int compute_score(struct s
24199 if (inet->inet_rcv_saddr != daddr)
24203 + /* block non nx_info ips */
24204 + if (!v4_addr_in_nx_info(sk->sk_nx_info,
24205 + daddr, NXA_MASK_BIND))
24208 if (inet->inet_daddr) {
24209 if (inet->inet_daddr != saddr)
24210 @@ -472,6 +470,7 @@ begin:
24215 /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24216 * harder than this. -DaveM
24218 @@ -518,6 +517,11 @@ begin:
24219 sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24220 score = compute_score(sk, net, saddr, hnum, sport,
24221 daddr, dport, dif);
24222 + /* FIXME: disabled?
24223 + if (score == 9) {
24227 if (score > badness) {
24230 @@ -542,6 +546,7 @@ begin:
24231 if (get_nulls_value(node) != slot)
24236 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24238 @@ -551,6 +556,7 @@ begin:
24246 @@ -585,7 +591,7 @@ static inline bool __udp_is_mcast_sock(s
24247 udp_sk(sk)->udp_port_hash != hnum ||
24248 (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24249 (inet->inet_dport != rmt_port && inet->inet_dport) ||
24250 - (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||
24251 + !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24252 ipv6_only_sock(sk) ||
24253 (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24255 @@ -989,6 +995,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24256 inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24257 faddr, saddr, dport, inet->inet_sport);
24259 + if (sk->sk_nx_info) {
24260 + rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24261 + if (IS_ERR(rt)) {
24262 + err = PTR_ERR(rt);
24269 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24270 rt = ip_route_output_flow(net, fl4, sk);
24272 @@ -1293,7 +1309,8 @@ try_again:
24274 sin->sin_family = AF_INET;
24275 sin->sin_port = udp_hdr(skb)->source;
24276 - sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24277 + sin->sin_addr.s_addr = nx_map_sock_lback(
24278 + skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24279 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24280 *addr_len = sizeof(*sin);
24282 @@ -2223,6 +2240,8 @@ static struct sock *udp_get_first(struct
24283 sk_nulls_for_each(sk, node, &hslot->head) {
24284 if (!net_eq(sock_net(sk), net))
24286 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24288 if (sk->sk_family == state->family)
24291 @@ -2240,7 +2259,9 @@ static struct sock *udp_get_next(struct
24294 sk = sk_nulls_next(sk);
24295 - } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
24296 + } while (sk && (!net_eq(sock_net(sk), net) ||
24297 + sk->sk_family != state->family ||
24298 + !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24301 if (state->bucket <= state->udp_table->mask)
24302 @@ -2336,8 +2357,8 @@ static void udp4_format_sock(struct sock
24305 struct inet_sock *inet = inet_sk(sp);
24306 - __be32 dest = inet->inet_daddr;
24307 - __be32 src = inet->inet_rcv_saddr;
24308 + __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24309 + __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24310 __u16 destp = ntohs(inet->inet_dport);
24311 __u16 srcp = ntohs(inet->inet_sport);
24313 diff -NurpP --minimal linux-3.13.6/net/ipv6/Kconfig linux-3.13.6-vs2.3.6.11/net/ipv6/Kconfig
24314 --- linux-3.13.6/net/ipv6/Kconfig 2014-01-22 20:39:15.000000000 +0000
24315 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/Kconfig 2014-01-31 20:38:04.000000000 +0000
24318 # IPv6 as module will cause a CRASH if you try to unload it
24320 - tristate "The IPv6 protocol"
24322 + bool "The IPv6 protocol"
24325 This is complemental support for the IP version 6.
24326 You will still be able to do traditional IPv4 networking as well.
24327 diff -NurpP --minimal linux-3.13.6/net/ipv6/addrconf.c linux-3.13.6-vs2.3.6.11/net/ipv6/addrconf.c
24328 --- linux-3.13.6/net/ipv6/addrconf.c 2014-03-12 13:51:25.000000000 +0000
24329 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/addrconf.c 2014-03-12 15:51:08.000000000 +0000
24331 #include <linux/proc_fs.h>
24332 #include <linux/seq_file.h>
24333 #include <linux/export.h>
24334 +#include <linux/vs_network.h>
24335 +#include <linux/vs_inet6.h>
24337 /* Set to 3 to get tracing... */
24338 #define ACONF_DEBUG 2
24339 @@ -1281,7 +1283,7 @@ out:
24341 int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
24342 const struct in6_addr *daddr, unsigned int prefs,
24343 - struct in6_addr *saddr)
24344 + struct in6_addr *saddr, struct nx_info *nxi)
24346 struct ipv6_saddr_score scores[2],
24347 *score = &scores[0], *hiscore = &scores[1];
24348 @@ -1353,6 +1355,8 @@ int ipv6_dev_get_saddr(struct net *net,
24352 + if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
24356 bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
24357 @@ -3368,7 +3372,10 @@ static void if6_seq_stop(struct seq_file
24358 static int if6_seq_show(struct seq_file *seq, void *v)
24360 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
24361 - seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24363 + if (nx_check(0, VS_ADMIN|VS_WATCH) ||
24364 + v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
24365 + seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24367 ifp->idev->dev->ifindex,
24369 @@ -3889,6 +3896,11 @@ static int in6_dump_addrs(struct inet6_d
24370 struct ifacaddr6 *ifaca;
24372 int ip_idx = *p_ip_idx;
24373 + struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24375 + /* disable ipv6 on non v6 guests */
24376 + if (nxi && !nx_info_has_v6(nxi))
24379 read_lock_bh(&idev->lock);
24381 @@ -3899,6 +3911,8 @@ static int in6_dump_addrs(struct inet6_d
24382 list_for_each_entry(ifa, &idev->addr_list, if_list) {
24383 if (++ip_idx < s_ip_idx)
24385 + if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
24387 err = inet6_fill_ifaddr(skb, ifa,
24388 NETLINK_CB(cb->skb).portid,
24389 cb->nlh->nlmsg_seq,
24390 @@ -3916,6 +3930,8 @@ static int in6_dump_addrs(struct inet6_d
24391 ifmca = ifmca->next, ip_idx++) {
24392 if (ip_idx < s_ip_idx)
24394 + if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
24396 err = inet6_fill_ifmcaddr(skb, ifmca,
24397 NETLINK_CB(cb->skb).portid,
24398 cb->nlh->nlmsg_seq,
24399 @@ -3931,6 +3947,8 @@ static int in6_dump_addrs(struct inet6_d
24400 ifaca = ifaca->aca_next, ip_idx++) {
24401 if (ip_idx < s_ip_idx)
24403 + if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
24405 err = inet6_fill_ifacaddr(skb, ifaca,
24406 NETLINK_CB(cb->skb).portid,
24407 cb->nlh->nlmsg_seq,
24408 @@ -3959,6 +3977,10 @@ static int inet6_dump_addr(struct sk_buf
24409 struct inet6_dev *idev;
24410 struct hlist_head *head;
24412 + /* FIXME: maybe disable ipv6 on non v6 guests?
24413 + if (skb->sk && skb->sk->sk_vx_info)
24414 + return skb->len; */
24417 s_idx = idx = cb->args[1];
24418 s_ip_idx = ip_idx = cb->args[2];
24419 @@ -4401,6 +4423,7 @@ static int inet6_dump_ifinfo(struct sk_b
24420 struct net_device *dev;
24421 struct inet6_dev *idev;
24422 struct hlist_head *head;
24423 + struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24426 s_idx = cb->args[1];
24427 @@ -4412,6 +4435,8 @@ static int inet6_dump_ifinfo(struct sk_b
24428 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24431 + if (!v6_dev_in_nx_info(dev, nxi))
24433 idev = __in6_dev_get(dev);
24436 diff -NurpP --minimal linux-3.13.6/net/ipv6/af_inet6.c linux-3.13.6-vs2.3.6.11/net/ipv6/af_inet6.c
24437 --- linux-3.13.6/net/ipv6/af_inet6.c 2014-01-22 20:39:15.000000000 +0000
24438 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/af_inet6.c 2014-01-31 21:39:03.000000000 +0000
24440 #include <linux/netdevice.h>
24441 #include <linux/icmpv6.h>
24442 #include <linux/netfilter_ipv6.h>
24443 +#include <linux/vs_inet.h>
24444 +#include <linux/vs_inet6.h>
24446 #include <net/ip.h>
24447 #include <net/ipv6.h>
24448 @@ -156,10 +158,13 @@ lookup_protocol:
24452 + if ((protocol == IPPROTO_ICMPV6) &&
24453 + nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24455 if (sock->type == SOCK_RAW && !kern &&
24456 !ns_capable(net->user_ns, CAP_NET_RAW))
24457 goto out_rcu_unlock;
24460 sock->ops = answer->ops;
24461 answer_prot = answer->prot;
24462 answer_no_check = answer->no_check;
24463 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
24464 struct inet_sock *inet = inet_sk(sk);
24465 struct ipv6_pinfo *np = inet6_sk(sk);
24466 struct net *net = sock_net(sk);
24467 + struct nx_v6_sock_addr nsa;
24469 unsigned short snum;
24471 @@ -274,6 +280,10 @@ int inet6_bind(struct socket *sock, stru
24472 if (addr->sin6_family != AF_INET6)
24473 return -EAFNOSUPPORT;
24475 + err = v6_map_sock_addr(inet, addr, &nsa);
24479 addr_type = ipv6_addr_type(&addr->sin6_addr);
24480 if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
24482 @@ -305,6 +315,7 @@ int inet6_bind(struct socket *sock, stru
24483 /* Reproduce AF_INET checks to make the bindings consistent */
24484 v4addr = addr->sin6_addr.s6_addr32[3];
24485 chk_addr_ret = inet_addr_type(net, v4addr);
24487 if (!sysctl_ip_nonlocal_bind &&
24488 !(inet->freebind || inet->transparent) &&
24489 v4addr != htonl(INADDR_ANY) &&
24490 @@ -314,6 +325,10 @@ int inet6_bind(struct socket *sock, stru
24491 err = -EADDRNOTAVAIL;
24494 + if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
24495 + err = -EADDRNOTAVAIL;
24499 if (addr_type != IPV6_ADDR_ANY) {
24500 struct net_device *dev = NULL;
24501 @@ -340,6 +355,11 @@ int inet6_bind(struct socket *sock, stru
24505 + if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24506 + err = -EADDRNOTAVAIL;
24510 /* ipv4 addr of the socket is invalid. Only the
24511 * unspecified and mapped address have a v4 equivalent.
24513 @@ -356,6 +376,9 @@ int inet6_bind(struct socket *sock, stru
24517 + /* what's that for? */
24518 + v6_set_sock_addr(inet, &nsa);
24520 inet->inet_rcv_saddr = v4addr;
24521 inet->inet_saddr = v4addr;
24523 @@ -457,9 +480,11 @@ int inet6_getname(struct socket *sock, s
24525 sin->sin6_port = inet->inet_dport;
24526 sin->sin6_addr = sk->sk_v6_daddr;
24527 + /* FIXME: remap lback? */
24529 sin->sin6_flowinfo = np->flow_label;
24531 + /* FIXME: remap lback? */
24532 if (ipv6_addr_any(&sk->sk_v6_rcv_saddr))
24533 sin->sin6_addr = np->saddr;
24535 diff -NurpP --minimal linux-3.13.6/net/ipv6/datagram.c linux-3.13.6-vs2.3.6.11/net/ipv6/datagram.c
24536 --- linux-3.13.6/net/ipv6/datagram.c 2014-01-22 20:39:15.000000000 +0000
24537 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/datagram.c 2014-01-31 20:38:04.000000000 +0000
24538 @@ -655,7 +655,7 @@ int ip6_datagram_send_ctl(struct net *ne
24541 if (fl6->flowi6_oif) {
24542 - dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
24543 + dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
24547 diff -NurpP --minimal linux-3.13.6/net/ipv6/fib6_rules.c linux-3.13.6-vs2.3.6.11/net/ipv6/fib6_rules.c
24548 --- linux-3.13.6/net/ipv6/fib6_rules.c 2014-01-22 20:39:15.000000000 +0000
24549 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/fib6_rules.c 2014-01-31 20:38:04.000000000 +0000
24550 @@ -97,7 +97,7 @@ static int fib6_rule_action(struct fib_r
24551 ip6_dst_idev(&rt->dst)->dev,
24553 rt6_flags2srcprefs(flags),
24557 if (!ipv6_prefix_equal(&saddr, &r->src.addr,
24559 diff -NurpP --minimal linux-3.13.6/net/ipv6/inet6_hashtables.c linux-3.13.6-vs2.3.6.11/net/ipv6/inet6_hashtables.c
24560 --- linux-3.13.6/net/ipv6/inet6_hashtables.c 2014-01-22 20:39:15.000000000 +0000
24561 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/inet6_hashtables.c 2014-01-31 20:38:04.000000000 +0000
24564 #include <linux/module.h>
24565 #include <linux/random.h>
24566 +#include <linux/vs_inet6.h>
24568 #include <net/inet_connection_sock.h>
24569 #include <net/inet_hashtables.h>
24570 @@ -116,7 +117,6 @@ struct sock *__inet6_lookup_established(
24571 unsigned int slot = hash & hashinfo->ehash_mask;
24572 struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
24577 sk_nulls_for_each_rcu(sk, node, &head->chain) {
24578 @@ -158,6 +158,9 @@ static inline int compute_score(struct s
24579 if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24583 + if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24586 if (sk->sk_bound_dev_if) {
24587 if (sk->sk_bound_dev_if != dif)
24588 diff -NurpP --minimal linux-3.13.6/net/ipv6/ip6_fib.c linux-3.13.6-vs2.3.6.11/net/ipv6/ip6_fib.c
24589 --- linux-3.13.6/net/ipv6/ip6_fib.c 2014-01-22 20:39:15.000000000 +0000
24590 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/ip6_fib.c 2014-01-31 21:48:35.000000000 +0000
24591 @@ -1779,6 +1779,7 @@ static int ipv6_route_seq_show(struct se
24592 struct rt6_info *rt = v;
24593 struct ipv6_route_iter *iter = seq->private;
24595 + /* FIXME: check for network context? */
24596 seq_printf(seq, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
24598 #ifdef CONFIG_IPV6_SUBTREES
24599 diff -NurpP --minimal linux-3.13.6/net/ipv6/ip6_output.c linux-3.13.6-vs2.3.6.11/net/ipv6/ip6_output.c
24600 --- linux-3.13.6/net/ipv6/ip6_output.c 2014-03-12 13:51:25.000000000 +0000
24601 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/ip6_output.c 2014-03-12 15:51:08.000000000 +0000
24602 @@ -872,7 +872,8 @@ static int ip6_dst_lookup_tail(struct so
24603 struct rt6_info *rt = (struct rt6_info *) *dst;
24604 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
24605 sk ? inet6_sk(sk)->srcprefs : 0,
24608 + sk ? sk->sk_nx_info : NULL);
24610 goto out_err_release;
24612 diff -NurpP --minimal linux-3.13.6/net/ipv6/ndisc.c linux-3.13.6-vs2.3.6.11/net/ipv6/ndisc.c
24613 --- linux-3.13.6/net/ipv6/ndisc.c 2014-01-22 20:39:15.000000000 +0000
24614 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/ndisc.c 2014-01-31 20:38:04.000000000 +0000
24615 @@ -486,7 +486,7 @@ void ndisc_send_na(struct net_device *de
24617 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
24618 inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
24622 src_addr = &tmpaddr;
24624 diff -NurpP --minimal linux-3.13.6/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.13.6-vs2.3.6.11/net/ipv6/netfilter/ip6t_MASQUERADE.c
24625 --- linux-3.13.6/net/ipv6/netfilter/ip6t_MASQUERADE.c 2013-11-25 15:47:07.000000000 +0000
24626 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/netfilter/ip6t_MASQUERADE.c 2014-01-31 20:38:04.000000000 +0000
24627 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
24628 ctinfo == IP_CT_RELATED_REPLY));
24630 if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
24631 - &ipv6_hdr(skb)->daddr, 0, &src) < 0)
24632 + &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
24635 nfct_nat(ct)->masq_index = par->out->ifindex;
24636 diff -NurpP --minimal linux-3.13.6/net/ipv6/raw.c linux-3.13.6-vs2.3.6.11/net/ipv6/raw.c
24637 --- linux-3.13.6/net/ipv6/raw.c 2014-01-22 20:39:15.000000000 +0000
24638 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/raw.c 2014-01-31 20:38:04.000000000 +0000
24640 #include <linux/icmpv6.h>
24641 #include <linux/netfilter.h>
24642 #include <linux/netfilter_ipv6.h>
24643 +#include <linux/vs_inet6.h>
24644 #include <linux/skbuff.h>
24645 #include <linux/compat.h>
24646 #include <asm/uaccess.h>
24647 @@ -287,6 +288,13 @@ static int rawv6_bind(struct sock *sk, s
24651 + if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24652 + err = -EADDRNOTAVAIL;
24658 /* ipv4 addr of the socket is invalid. Only the
24659 * unspecified and mapped address have a v4 equivalent.
24661 diff -NurpP --minimal linux-3.13.6/net/ipv6/route.c linux-3.13.6-vs2.3.6.11/net/ipv6/route.c
24662 --- linux-3.13.6/net/ipv6/route.c 2014-01-22 20:39:15.000000000 +0000
24663 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/route.c 2014-01-31 20:38:04.000000000 +0000
24665 #include <net/netevent.h>
24666 #include <net/netlink.h>
24667 #include <net/nexthop.h>
24668 +#include <linux/vs_inet6.h>
24670 #include <asm/uaccess.h>
24672 @@ -2196,15 +2197,17 @@ int ip6_route_get_saddr(struct net *net,
24673 struct rt6_info *rt,
24674 const struct in6_addr *daddr,
24675 unsigned int prefs,
24676 - struct in6_addr *saddr)
24677 + struct in6_addr *saddr,
24678 + struct nx_info *nxi)
24680 struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
24682 - if (rt->rt6i_prefsrc.plen)
24683 + if (rt->rt6i_prefsrc.plen && (!nxi ||
24684 + v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
24685 *saddr = rt->rt6i_prefsrc.addr;
24687 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
24688 - daddr, prefs, saddr);
24689 + daddr, prefs, saddr, nxi);
24693 @@ -2624,7 +2627,8 @@ static int rt6_fill_node(struct net *net
24694 goto nla_put_failure;
24696 struct in6_addr saddr_buf;
24697 - if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
24698 + if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
24699 + (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
24700 nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
24701 goto nla_put_failure;
24703 diff -NurpP --minimal linux-3.13.6/net/ipv6/tcp_ipv6.c linux-3.13.6-vs2.3.6.11/net/ipv6/tcp_ipv6.c
24704 --- linux-3.13.6/net/ipv6/tcp_ipv6.c 2014-01-22 20:39:15.000000000 +0000
24705 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/tcp_ipv6.c 2014-01-31 20:38:04.000000000 +0000
24708 #include <linux/crypto.h>
24709 #include <linux/scatterlist.h>
24710 +#include <linux/vs_inet6.h>
24712 static void tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
24713 static void tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
24714 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
24715 * connect() to INADDR_ANY means loopback (BSD'ism).
24718 - if(ipv6_addr_any(&usin->sin6_addr))
24719 - usin->sin6_addr.s6_addr[15] = 0x1;
24720 + if(ipv6_addr_any(&usin->sin6_addr)) {
24721 + struct nx_info *nxi = sk->sk_nx_info;
24723 + if (nxi && nx_info_has_v6(nxi))
24724 + /* FIXME: remap lback? */
24725 + usin->sin6_addr = nxi->v6.ip;
24727 + usin->sin6_addr.s6_addr[15] = 0x1;
24730 addr_type = ipv6_addr_type(&usin->sin6_addr);
24732 diff -NurpP --minimal linux-3.13.6/net/ipv6/udp.c linux-3.13.6-vs2.3.6.11/net/ipv6/udp.c
24733 --- linux-3.13.6/net/ipv6/udp.c 2014-01-22 20:39:15.000000000 +0000
24734 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/udp.c 2014-02-01 02:33:38.000000000 +0000
24736 #include <net/xfrm.h>
24737 #include <net/inet6_hashtables.h>
24738 #include <net/busy_poll.h>
24739 +#include <linux/vs_inet6.h>
24741 #include <linux/proc_fs.h>
24742 #include <linux/seq_file.h>
24743 @@ -76,33 +77,61 @@ static unsigned int udp6_ehashfn(struct
24744 udp_ipv6_hash_secret + net_hash_mix(net));
24747 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
24748 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24750 + const struct in6_addr *sk1_rcv_saddr6 = inet6_rcv_saddr(sk1);
24751 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
24752 - int sk_ipv6only = ipv6_only_sock(sk);
24753 + __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr;
24754 + __be32 sk2_rcv_saddr = sk2->sk_rcv_saddr;
24755 + int sk1_ipv6only = ipv6_only_sock(sk1);
24756 int sk2_ipv6only = inet_v6_ipv6only(sk2);
24757 - int addr_type = ipv6_addr_type(&sk->sk_v6_rcv_saddr);
24758 + int addr_type1 = ipv6_addr_type(sk1_rcv_saddr6);
24759 int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
24761 /* if both are mapped, treat as IPv4 */
24762 - if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
24763 - return (!sk2_ipv6only &&
24764 - (!sk->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24765 - sk->sk_rcv_saddr == sk2->sk_rcv_saddr));
24766 + if (addr_type1 == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
24767 + if (!sk2_ipv6only &&
24768 + (!sk1->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24769 + sk1->sk_rcv_saddr == sk2->sk_rcv_saddr))
24775 if (addr_type2 == IPV6_ADDR_ANY &&
24776 - !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
24778 + !(sk2_ipv6only && addr_type1 == IPV6_ADDR_MAPPED))
24781 - if (addr_type == IPV6_ADDR_ANY &&
24782 - !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24784 + if (addr_type1 == IPV6_ADDR_ANY &&
24785 + !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24788 if (sk2_rcv_saddr6 &&
24789 - ipv6_addr_equal(&sk->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24791 + ipv6_addr_equal(&sk1->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24797 + if (!sk1_rcv_saddr && !sk2_rcv_saddr)
24798 + return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24799 + if (!sk2_rcv_saddr)
24800 + return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
24801 + if (!sk1_rcv_saddr)
24802 + return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
24805 + if (addr_type2 == IPV6_ADDR_ANY && addr_type1 == IPV6_ADDR_ANY)
24806 + return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24807 + else if (addr_type2 == IPV6_ADDR_ANY)
24808 + return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
24809 + else if (addr_type1 == IPV6_ADDR_ANY) {
24810 + if (addr_type2 == IPV6_ADDR_MAPPED)
24811 + return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24813 + return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
24818 static unsigned int udp6_portaddr_hash(struct net *net,
24819 @@ -160,6 +189,10 @@ static inline int compute_score(struct s
24820 if (inet->inet_dport != sport)
24824 + /* block non nx_info ips */
24825 + if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24828 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
24829 if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24830 diff -NurpP --minimal linux-3.13.6/net/ipv6/xfrm6_policy.c linux-3.13.6-vs2.3.6.11/net/ipv6/xfrm6_policy.c
24831 --- linux-3.13.6/net/ipv6/xfrm6_policy.c 2014-01-22 20:39:15.000000000 +0000
24832 +++ linux-3.13.6-vs2.3.6.11/net/ipv6/xfrm6_policy.c 2014-01-31 20:38:04.000000000 +0000
24833 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
24834 dev = ip6_dst_idev(dst)->dev;
24835 ipv6_dev_get_saddr(dev_net(dev), dev,
24836 (struct in6_addr *)&daddr->a6, 0,
24837 - (struct in6_addr *)&saddr->a6);
24838 + (struct in6_addr *)&saddr->a6, NULL);
24842 diff -NurpP --minimal linux-3.13.6/net/netfilter/ipvs/ip_vs_xmit.c linux-3.13.6-vs2.3.6.11/net/netfilter/ipvs/ip_vs_xmit.c
24843 --- linux-3.13.6/net/netfilter/ipvs/ip_vs_xmit.c 2013-11-25 15:47:07.000000000 +0000
24844 +++ linux-3.13.6-vs2.3.6.11/net/netfilter/ipvs/ip_vs_xmit.c 2014-01-31 20:38:04.000000000 +0000
24845 @@ -316,7 +316,7 @@ __ip_vs_route_output_v6(struct net *net,
24847 if (ipv6_addr_any(&fl6.saddr) &&
24848 ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
24849 - &fl6.daddr, 0, &fl6.saddr) < 0)
24850 + &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
24853 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
24854 diff -NurpP --minimal linux-3.13.6/net/netlink/af_netlink.c linux-3.13.6-vs2.3.6.11/net/netlink/af_netlink.c
24855 --- linux-3.13.6/net/netlink/af_netlink.c 2014-01-22 20:39:16.000000000 +0000
24856 +++ linux-3.13.6-vs2.3.6.11/net/netlink/af_netlink.c 2014-02-25 11:47:07.000000000 +0000
24858 #include <linux/mutex.h>
24859 #include <linux/vmalloc.h>
24860 #include <linux/if_arp.h>
24861 +#include <linux/vs_context.h>
24862 +#include <linux/vs_network.h>
24863 +#include <linux/vs_limit.h>
24864 #include <asm/cacheflush.h>
24866 #include <net/net_namespace.h>
24867 @@ -2850,6 +2853,8 @@ static struct sock *netlink_seq_socket_i
24868 sk_for_each(s, &hash->table[j]) {
24869 if (sock_net(s) != seq_file_net(seq))
24871 + if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
24875 iter->hash_idx = j;
24876 @@ -2886,7 +2891,8 @@ static void *netlink_seq_next(struct seq
24880 - } while (s && !nl_table[s->sk_protocol].compare(net, s));
24881 + } while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24882 + !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
24886 @@ -2899,7 +2905,8 @@ static void *netlink_seq_next(struct seq
24887 for (; j <= hash->mask; j++) {
24888 s = sk_head(&hash->table[j]);
24890 - while (s && !nl_table[s->sk_protocol].compare(net, s))
24891 + while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24892 + !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
24896 diff -NurpP --minimal linux-3.13.6/net/socket.c linux-3.13.6-vs2.3.6.11/net/socket.c
24897 --- linux-3.13.6/net/socket.c 2014-01-22 20:39:17.000000000 +0000
24898 +++ linux-3.13.6-vs2.3.6.11/net/socket.c 2014-02-01 12:32:53.000000000 +0000
24901 #include <net/sock.h>
24902 #include <linux/netfilter.h>
24903 +#include <linux/vs_socket.h>
24904 +#include <linux/vs_inet.h>
24905 +#include <linux/vs_inet6.h>
24907 #include <linux/if_tun.h>
24908 #include <linux/ipv6_route.h>
24909 @@ -623,13 +626,29 @@ static inline int __sock_sendmsg_nosec(s
24910 struct msghdr *msg, size_t size)
24912 struct sock_iocb *si = kiocb_to_siocb(iocb);
24920 - return sock->ops->sendmsg(iocb, sock, msg, size);
24921 + len = sock->ops->sendmsg(iocb, sock, msg, size);
24924 + vx_sock_send(sock->sk, size);
24926 + vx_sock_fail(sock->sk, size);
24928 + vxdprintk(VXD_CBIT(net, 7),
24929 + "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
24931 + (sock->sk)?sock->sk->sk_nx_info:0,
24932 + (sock->sk)?sock->sk->sk_vx_info:0,
24933 + (sock->sk)?sock->sk->sk_xid:0,
24934 + (sock->sk)?sock->sk->sk_nid:0,
24935 + (unsigned int)size, len);
24939 static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
24940 @@ -773,6 +792,7 @@ static inline int __sock_recvmsg_nosec(s
24941 struct msghdr *msg, size_t size, int flags)
24943 struct sock_iocb *si = kiocb_to_siocb(iocb);
24948 @@ -780,7 +800,18 @@ static inline int __sock_recvmsg_nosec(s
24952 - return sock->ops->recvmsg(iocb, sock, msg, size, flags);
24953 + len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
24954 + if ((len >= 0) && sock->sk)
24955 + vx_sock_recv(sock->sk, len);
24956 + vxdprintk(VXD_CBIT(net, 7),
24957 + "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
24959 + (sock->sk)?sock->sk->sk_nx_info:0,
24960 + (sock->sk)?sock->sk->sk_vx_info:0,
24961 + (sock->sk)?sock->sk->sk_xid:0,
24962 + (sock->sk)?sock->sk->sk_nid:0,
24963 + (unsigned int)size, len);
24967 static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
24968 @@ -1256,6 +1287,13 @@ int __sock_create(struct net *net, int f
24969 if (type < 0 || type >= SOCK_MAX)
24972 + if (!nx_check(0, VS_ADMIN)) {
24973 + if (family == PF_INET && !current_nx_info_has_v4())
24974 + return -EAFNOSUPPORT;
24975 + if (family == PF_INET6 && !current_nx_info_has_v6())
24976 + return -EAFNOSUPPORT;
24981 This uglymoron is moved from INET layer to here to avoid
24982 @@ -1390,6 +1428,7 @@ SYSCALL_DEFINE3(socket, int, family, int
24986 + set_bit(SOCK_USER_SOCKET, &sock->flags);
24987 retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
24990 @@ -1431,10 +1470,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
24991 err = sock_create(family, type, protocol, &sock1);
24994 + set_bit(SOCK_USER_SOCKET, &sock1->flags);
24996 err = sock_create(family, type, protocol, &sock2);
24998 goto out_release_1;
24999 + set_bit(SOCK_USER_SOCKET, &sock2->flags);
25001 err = sock1->ops->socketpair(sock1, sock2);
25003 diff -NurpP --minimal linux-3.13.6/net/sunrpc/auth.c linux-3.13.6-vs2.3.6.11/net/sunrpc/auth.c
25004 --- linux-3.13.6/net/sunrpc/auth.c 2013-11-25 15:47:08.000000000 +0000
25005 +++ linux-3.13.6-vs2.3.6.11/net/sunrpc/auth.c 2014-01-31 20:38:04.000000000 +0000
25007 #include <linux/sunrpc/clnt.h>
25008 #include <linux/sunrpc/gss_api.h>
25009 #include <linux/spinlock.h>
25010 +#include <linux/vs_tag.h>
25013 # define RPCDBG_FACILITY RPCDBG_AUTH
25014 @@ -586,6 +587,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25015 memset(&acred, 0, sizeof(acred));
25016 acred.uid = cred->fsuid;
25017 acred.gid = cred->fsgid;
25018 + acred.tag = make_ktag(&init_user_ns, dx_current_tag());
25019 acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25021 ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25022 @@ -626,6 +628,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25023 struct auth_cred acred = {
25024 .uid = GLOBAL_ROOT_UID,
25025 .gid = GLOBAL_ROOT_GID,
25026 + .tag = KTAGT_INIT(dx_current_tag()),
25029 dprintk("RPC: %5u looking up %s cred\n",
25030 diff -NurpP --minimal linux-3.13.6/net/sunrpc/auth_unix.c linux-3.13.6-vs2.3.6.11/net/sunrpc/auth_unix.c
25031 --- linux-3.13.6/net/sunrpc/auth_unix.c 2013-11-25 15:47:08.000000000 +0000
25032 +++ linux-3.13.6-vs2.3.6.11/net/sunrpc/auth_unix.c 2014-01-31 20:38:04.000000000 +0000
25033 @@ -13,11 +13,13 @@
25034 #include <linux/sunrpc/clnt.h>
25035 #include <linux/sunrpc/auth.h>
25036 #include <linux/user_namespace.h>
25037 +#include <linux/vs_tag.h>
25039 #define NFS_NGROUPS 16
25042 struct rpc_cred uc_base;
25045 kgid_t uc_gids[NFS_NGROUPS];
25047 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25048 groups = NFS_NGROUPS;
25050 cred->uc_gid = acred->gid;
25051 + cred->uc_tag = acred->tag;
25052 for (i = 0; i < groups; i++)
25053 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25054 if (i < NFS_NGROUPS)
25055 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25059 - if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25060 + if (!uid_eq(cred->uc_uid, acred->uid) ||
25061 + !gid_eq(cred->uc_gid, acred->gid) ||
25062 + !tag_eq(cred->uc_tag, acred->tag))
25065 if (acred->group_info != NULL)
25066 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25067 struct rpc_clnt *clnt = task->tk_client;
25068 struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25069 __be32 *base, *hold;
25073 *p++ = htonl(RPC_AUTH_UNIX);
25075 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
25077 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25079 - *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25080 - *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25081 + tag = task->tk_client->cl_tag;
25082 + *p++ = htonl((u32) from_kuid(&init_user_ns,
25083 + TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
25084 + *p++ = htonl((u32) from_kgid(&init_user_ns,
25085 + TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
25087 for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25088 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25089 diff -NurpP --minimal linux-3.13.6/net/sunrpc/clnt.c linux-3.13.6-vs2.3.6.11/net/sunrpc/clnt.c
25090 --- linux-3.13.6/net/sunrpc/clnt.c 2014-03-12 13:51:25.000000000 +0000
25091 +++ linux-3.13.6-vs2.3.6.11/net/sunrpc/clnt.c 2014-02-25 11:26:10.000000000 +0000
25093 #include <linux/in.h>
25094 #include <linux/in6.h>
25095 #include <linux/un.h>
25096 +#include <linux/vs_cvirt.h>
25098 #include <linux/sunrpc/clnt.h>
25099 #include <linux/sunrpc/addr.h>
25100 @@ -538,6 +539,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25101 if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25102 clnt->cl_chatty = 1;
25104 + /* TODO: handle RPC_CLNT_CREATE_TAGGED
25105 + if (args->flags & RPC_CLNT_CREATE_TAGGED)
25106 + clnt->cl_tag = 1; */
25109 EXPORT_SYMBOL_GPL(rpc_create);
25110 diff -NurpP --minimal linux-3.13.6/net/unix/af_unix.c linux-3.13.6-vs2.3.6.11/net/unix/af_unix.c
25111 --- linux-3.13.6/net/unix/af_unix.c 2014-01-22 20:39:17.000000000 +0000
25112 +++ linux-3.13.6-vs2.3.6.11/net/unix/af_unix.c 2014-01-31 22:42:26.000000000 +0000
25113 @@ -115,6 +115,8 @@
25114 #include <net/checksum.h>
25115 #include <linux/security.h>
25116 #include <linux/freezer.h>
25117 +#include <linux/vs_context.h>
25118 +#include <linux/vs_limit.h>
25120 struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25121 EXPORT_SYMBOL_GPL(unix_socket_table);
25122 @@ -271,6 +273,8 @@ static struct sock *__unix_find_socket_b
25123 if (!net_eq(sock_net(s), net))
25126 + if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25128 if (u->addr->len == len &&
25129 !memcmp(u->addr->name, sunname, len))
25131 @@ -2269,6 +2273,8 @@ static struct sock *unix_from_bucket(str
25132 for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25133 if (sock_net(sk) != seq_file_net(seq))
25135 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25137 if (++count == offset)
25140 @@ -2286,6 +2292,8 @@ static struct sock *unix_next_socket(str
25144 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25146 if (sock_net(sk) == seq_file_net(seq))
25149 diff -NurpP --minimal linux-3.13.6/scripts/checksyscalls.sh linux-3.13.6-vs2.3.6.11/scripts/checksyscalls.sh
25150 --- linux-3.13.6/scripts/checksyscalls.sh 2012-12-11 03:30:57.000000000 +0000
25151 +++ linux-3.13.6-vs2.3.6.11/scripts/checksyscalls.sh 2014-01-31 20:38:04.000000000 +0000
25152 @@ -193,7 +193,6 @@ cat << EOF
25153 #define __IGNORE_afs_syscall
25154 #define __IGNORE_getpmsg
25155 #define __IGNORE_putpmsg
25156 -#define __IGNORE_vserver
25160 diff -NurpP --minimal linux-3.13.6/security/commoncap.c linux-3.13.6-vs2.3.6.11/security/commoncap.c
25161 --- linux-3.13.6/security/commoncap.c 2013-11-25 15:47:08.000000000 +0000
25162 +++ linux-3.13.6-vs2.3.6.11/security/commoncap.c 2014-01-31 20:38:04.000000000 +0000
25163 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25164 int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25165 int cap, int audit)
25167 + struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25168 struct user_namespace *ns = targ_ns;
25170 /* See if cred has the capability in the target user namespace
25171 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25174 /* Do we have the necessary capabilities? */
25175 - if (ns == cred->user_ns)
25176 - return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25177 + if (ns == cred->user_ns) {
25178 + if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25179 + cap_raised(cred->cap_effective, cap))
25181 + return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25184 /* Have we tried all of the parent namespaces? */
25185 if (ns == &init_user_ns)
25186 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25188 if (!strncmp(name, XATTR_SECURITY_PREFIX,
25189 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25190 - !capable(CAP_SYS_ADMIN))
25191 + !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25195 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25197 if (!strncmp(name, XATTR_SECURITY_PREFIX,
25198 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25199 - !capable(CAP_SYS_ADMIN))
25200 + !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25204 diff -NurpP --minimal linux-3.13.6/security/selinux/hooks.c linux-3.13.6-vs2.3.6.11/security/selinux/hooks.c
25205 --- linux-3.13.6/security/selinux/hooks.c 2014-01-22 20:39:21.000000000 +0000
25206 +++ linux-3.13.6-vs2.3.6.11/security/selinux/hooks.c 2014-01-31 20:38:04.000000000 +0000
25208 #include <linux/dccp.h>
25209 #include <linux/quota.h>
25210 #include <linux/un.h> /* for Unix socket types */
25211 -#include <net/af_unix.h> /* for Unix socket types */
25212 #include <linux/parser.h>
25213 #include <linux/nfs_mount.h>
25214 #include <net/ipv6.h>