1 diff -NurpP --minimal linux-3.13.10/Documentation/vserver/debug.txt linux-3.13.10-vs2.3.6.11/Documentation/vserver/debug.txt
2 --- linux-3.13.10/Documentation/vserver/debug.txt 1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.13.10-vs2.3.6.11/Documentation/vserver/debug.txt 2014-01-31 20:38:03.000000000 +0000
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.10/arch/alpha/Kconfig linux-3.13.10-vs2.3.6.11/arch/alpha/Kconfig
160 --- linux-3.13.10/arch/alpha/Kconfig 2014-01-22 20:38:09.000000000 +0000
161 +++ linux-3.13.10-vs2.3.6.11/arch/alpha/Kconfig 2014-01-31 20:38:03.000000000 +0000
162 @@ -735,6 +735,8 @@ config DUMMY_CONSOLE
166 +source "kernel/vserver/Kconfig"
168 source "security/Kconfig"
170 source "crypto/Kconfig"
171 diff -NurpP --minimal linux-3.13.10/arch/alpha/kernel/systbls.S linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/systbls.S
172 --- linux-3.13.10/arch/alpha/kernel/systbls.S 2013-11-25 15:44:11.000000000 +0000
173 +++ linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/systbls.S 2014-01-31 20:38:03.000000000 +0000
174 @@ -446,7 +446,7 @@ sys_call_table:
175 .quad sys_stat64 /* 425 */
178 - .quad sys_ni_syscall /* sys_vserver */
179 + .quad sys_vserver /* sys_vserver */
180 .quad sys_ni_syscall /* sys_mbind */
181 .quad sys_ni_syscall /* sys_get_mempolicy */
182 .quad sys_ni_syscall /* sys_set_mempolicy */
183 diff -NurpP --minimal linux-3.13.10/arch/alpha/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/traps.c
184 --- linux-3.13.10/arch/alpha/kernel/traps.c 2014-01-22 20:38:10.000000000 +0000
185 +++ linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
186 @@ -175,7 +175,8 @@ die_if_kernel(char * str, struct pt_regs
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.10/arch/arm/Kconfig linux-3.13.10-vs2.3.6.11/arch/arm/Kconfig
197 --- linux-3.13.10/arch/arm/Kconfig 2014-04-17 01:12:06.000000000 +0000
198 +++ linux-3.13.10-vs2.3.6.11/arch/arm/Kconfig 2014-04-17 01:17:10.000000000 +0000
199 @@ -2267,6 +2267,8 @@ source "fs/Kconfig"
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.10/arch/arm/kernel/calls.S linux-3.13.10-vs2.3.6.11/arch/arm/kernel/calls.S
209 --- linux-3.13.10/arch/arm/kernel/calls.S 2013-05-31 13:44:29.000000000 +0000
210 +++ linux-3.13.10-vs2.3.6.11/arch/arm/kernel/calls.S 2014-01-31 20:38:03.000000000 +0000
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.10/arch/arm/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/arm/kernel/traps.c
221 --- linux-3.13.10/arch/arm/kernel/traps.c 2014-01-22 20:38:11.000000000 +0000
222 +++ linux-3.13.10-vs2.3.6.11/arch/arm/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
223 @@ -247,8 +247,8 @@ static int __die(const char *str, int er
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.10/arch/cris/Kconfig linux-3.13.10-vs2.3.6.11/arch/cris/Kconfig
235 --- linux-3.13.10/arch/cris/Kconfig 2014-01-22 20:38:15.000000000 +0000
236 +++ linux-3.13.10-vs2.3.6.11/arch/cris/Kconfig 2014-01-31 20:38:03.000000000 +0000
237 @@ -561,6 +561,8 @@ source "fs/Kconfig"
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.10/arch/ia64/Kconfig linux-3.13.10-vs2.3.6.11/arch/ia64/Kconfig
247 --- linux-3.13.10/arch/ia64/Kconfig 2014-01-22 20:38:16.000000000 +0000
248 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/Kconfig 2014-01-31 20:38:03.000000000 +0000
249 @@ -641,6 +641,8 @@ source "fs/Kconfig"
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.10/arch/ia64/kernel/entry.S linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/entry.S
259 --- linux-3.13.10/arch/ia64/kernel/entry.S 2014-01-22 20:38:16.000000000 +0000
260 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/entry.S 2014-01-31 20:38:03.000000000 +0000
261 @@ -1706,7 +1706,7 @@ sys_call_table:
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.10/arch/ia64/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/ptrace.c
271 --- linux-3.13.10/arch/ia64/kernel/ptrace.c 2013-02-19 13:56:51.000000000 +0000
272 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/ptrace.c 2014-01-31 20:38:03.000000000 +0000
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.10/arch/ia64/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/traps.c
282 --- linux-3.13.10/arch/ia64/kernel/traps.c 2013-11-25 15:44:20.000000000 +0000
283 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
284 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
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.10/arch/m32r/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/m32r/kernel/traps.c
309 --- linux-3.13.10/arch/m32r/kernel/traps.c 2013-07-14 17:00:26.000000000 +0000
310 +++ linux-3.13.10-vs2.3.6.11/arch/m32r/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
311 @@ -184,8 +184,9 @@ static void show_registers(struct pt_reg
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.10/arch/m68k/Kconfig linux-3.13.10-vs2.3.6.11/arch/m68k/Kconfig
324 --- linux-3.13.10/arch/m68k/Kconfig 2014-04-17 01:12:07.000000000 +0000
325 +++ linux-3.13.10-vs2.3.6.11/arch/m68k/Kconfig 2014-04-17 01:17:10.000000000 +0000
326 @@ -135,6 +135,8 @@ source "fs/Kconfig"
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.10/arch/mips/Kconfig linux-3.13.10-vs2.3.6.11/arch/mips/Kconfig
336 --- linux-3.13.10/arch/mips/Kconfig 2014-01-22 20:38:16.000000000 +0000
337 +++ linux-3.13.10-vs2.3.6.11/arch/mips/Kconfig 2014-01-31 20:38:03.000000000 +0000
338 @@ -2539,6 +2539,8 @@ source "fs/Kconfig"
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.10/arch/mips/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/arch/mips/kernel/ptrace.c
348 --- linux-3.13.10/arch/mips/kernel/ptrace.c 2014-01-22 20:38:17.000000000 +0000
349 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/ptrace.c 2014-01-31 20:53:13.000000000 +0000
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.10/arch/mips/kernel/scall32-o32.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall32-o32.S
369 --- linux-3.13.10/arch/mips/kernel/scall32-o32.S 2014-01-22 20:38:17.000000000 +0000
370 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall32-o32.S 2014-01-31 20:48:18.000000000 +0000
371 @@ -491,7 +491,7 @@ EXPORT(sys_call_table)
372 PTR sys_mq_timedreceive
373 PTR sys_mq_notify /* 4275 */
374 PTR sys_mq_getsetattr
375 - PTR sys_ni_syscall /* sys_vserver */
378 PTR sys_ni_syscall /* available, was setaltroot */
379 PTR sys_add_key /* 4280 */
380 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/scall64-64.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-64.S
381 --- linux-3.13.10/arch/mips/kernel/scall64-64.S 2014-01-22 20:38:17.000000000 +0000
382 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-64.S 2014-01-31 20:38:03.000000000 +0000
383 @@ -352,7 +352,7 @@ EXPORT(sys_call_table)
384 PTR sys_mq_timedreceive
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.10/arch/mips/kernel/scall64-n32.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-n32.S
393 --- linux-3.13.10/arch/mips/kernel/scall64-n32.S 2014-01-22 20:38:17.000000000 +0000
394 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-n32.S 2014-01-31 20:38:03.000000000 +0000
395 @@ -345,7 +345,7 @@ EXPORT(sysn32_call_table)
396 PTR compat_sys_mq_timedreceive
397 PTR compat_sys_mq_notify
398 PTR compat_sys_mq_getsetattr
399 - PTR sys_ni_syscall /* 6240, sys_vserver */
400 + PTR sys32_vserver /* 6240 */
401 PTR compat_sys_waitid
402 PTR sys_ni_syscall /* available, was setaltroot */
404 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/scall64-o32.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-o32.S
405 --- linux-3.13.10/arch/mips/kernel/scall64-o32.S 2014-01-22 20:38:17.000000000 +0000
406 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-o32.S 2014-01-31 20:38:03.000000000 +0000
407 @@ -469,7 +469,7 @@ EXPORT(sys32_call_table)
408 PTR compat_sys_mq_timedreceive
409 PTR compat_sys_mq_notify /* 4275 */
410 PTR compat_sys_mq_getsetattr
411 - PTR sys_ni_syscall /* sys_vserver */
413 PTR compat_sys_waitid
414 PTR sys_ni_syscall /* available, was setaltroot */
415 PTR sys_add_key /* 4280 */
416 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/mips/kernel/traps.c
417 --- linux-3.13.10/arch/mips/kernel/traps.c 2014-01-22 20:38:17.000000000 +0000
418 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
419 @@ -334,9 +334,10 @@ void show_registers(struct pt_regs *regs
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.10/arch/parisc/Kconfig linux-3.13.10-vs2.3.6.11/arch/parisc/Kconfig
434 --- linux-3.13.10/arch/parisc/Kconfig 2014-01-22 20:38:18.000000000 +0000
435 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/Kconfig 2014-01-31 20:38:03.000000000 +0000
436 @@ -320,6 +320,8 @@ source "fs/Kconfig"
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.10/arch/parisc/kernel/syscall_table.S linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/syscall_table.S
446 --- linux-3.13.10/arch/parisc/kernel/syscall_table.S 2013-07-14 17:00:31.000000000 +0000
447 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/syscall_table.S 2014-01-31 20:38:03.000000000 +0000
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.10/arch/parisc/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/traps.c
458 --- linux-3.13.10/arch/parisc/kernel/traps.c 2013-11-25 15:46:28.000000000 +0000
459 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
460 @@ -229,8 +229,9 @@ void die_if_kernel(char *str, struct pt_
463 parisc_printk_ratelimited(1, regs,
464 - KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
465 - current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
466 + 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]);
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.10/arch/powerpc/Kconfig linux-3.13.10-vs2.3.6.11/arch/powerpc/Kconfig
484 --- linux-3.13.10/arch/powerpc/Kconfig 2014-01-22 20:38:18.000000000 +0000
485 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/Kconfig 2014-01-31 20:38:03.000000000 +0000
486 @@ -1028,6 +1028,8 @@ source "lib/Kconfig"
488 source "arch/powerpc/Kconfig.debug"
490 +source "kernel/vserver/Kconfig"
492 source "security/Kconfig"
495 diff -NurpP --minimal linux-3.13.10/arch/powerpc/include/uapi/asm/unistd.h linux-3.13.10-vs2.3.6.11/arch/powerpc/include/uapi/asm/unistd.h
496 --- linux-3.13.10/arch/powerpc/include/uapi/asm/unistd.h 2013-05-31 13:44:44.000000000 +0000
497 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/include/uapi/asm/unistd.h 2014-01-31 20:38:03.000000000 +0000
500 #define __NR_rtas 255
501 #define __NR_sys_debug_setcontext 256
502 -/* Number 257 is reserved for vserver */
503 +#define __NR_vserver 257
504 #define __NR_migrate_pages 258
505 #define __NR_mbind 259
506 #define __NR_get_mempolicy 260
507 diff -NurpP --minimal linux-3.13.10/arch/powerpc/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/powerpc/kernel/traps.c
508 --- linux-3.13.10/arch/powerpc/kernel/traps.c 2014-01-22 20:38:23.000000000 +0000
509 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
510 @@ -1272,8 +1272,9 @@ void nonrecoverable_exception(struct pt_
512 void trace_syscall(struct pt_regs *regs)
514 - printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
515 - current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
516 + printk("Task: %p(%d:#%u), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
517 + current, task_pid_nr(current), current->xid,
518 + regs->nip, regs->link, regs->gpr[0],
519 regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
522 diff -NurpP --minimal linux-3.13.10/arch/s390/Kconfig linux-3.13.10-vs2.3.6.11/arch/s390/Kconfig
523 --- linux-3.13.10/arch/s390/Kconfig 2014-04-17 01:12:08.000000000 +0000
524 +++ linux-3.13.10-vs2.3.6.11/arch/s390/Kconfig 2014-04-17 01:17:10.000000000 +0000
525 @@ -650,6 +650,8 @@ source "fs/Kconfig"
527 source "arch/s390/Kconfig.debug"
529 +source "kernel/vserver/Kconfig"
531 source "security/Kconfig"
533 source "crypto/Kconfig"
534 diff -NurpP --minimal linux-3.13.10/arch/s390/include/asm/tlb.h linux-3.13.10-vs2.3.6.11/arch/s390/include/asm/tlb.h
535 --- linux-3.13.10/arch/s390/include/asm/tlb.h 2013-11-25 15:46:29.000000000 +0000
536 +++ linux-3.13.10-vs2.3.6.11/arch/s390/include/asm/tlb.h 2014-01-31 20:38:03.000000000 +0000
538 #include <linux/mm.h>
539 #include <linux/pagemap.h>
540 #include <linux/swap.h>
542 #include <asm/processor.h>
543 #include <asm/pgalloc.h>
544 #include <asm/tlbflush.h>
545 diff -NurpP --minimal linux-3.13.10/arch/s390/include/uapi/asm/unistd.h linux-3.13.10-vs2.3.6.11/arch/s390/include/uapi/asm/unistd.h
546 --- linux-3.13.10/arch/s390/include/uapi/asm/unistd.h 2013-02-19 13:57:16.000000000 +0000
547 +++ linux-3.13.10-vs2.3.6.11/arch/s390/include/uapi/asm/unistd.h 2014-01-31 20:38:03.000000000 +0000
549 #define __NR_clock_gettime (__NR_timer_create+6)
550 #define __NR_clock_getres (__NR_timer_create+7)
551 #define __NR_clock_nanosleep (__NR_timer_create+8)
552 -/* Number 263 is reserved for vserver */
553 +#define __NR_vserver 263
554 #define __NR_statfs64 265
555 #define __NR_fstatfs64 266
556 #define __NR_remap_file_pages 267
557 diff -NurpP --minimal linux-3.13.10/arch/s390/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/arch/s390/kernel/ptrace.c
558 --- linux-3.13.10/arch/s390/kernel/ptrace.c 2014-01-22 20:38:24.000000000 +0000
559 +++ linux-3.13.10-vs2.3.6.11/arch/s390/kernel/ptrace.c 2014-01-31 20:38:03.000000000 +0000
561 #include <linux/tracehook.h>
562 #include <linux/seccomp.h>
563 #include <linux/compat.h>
564 +#include <linux/vs_base.h>
565 #include <trace/syscall.h>
566 #include <asm/segment.h>
567 #include <asm/page.h>
568 diff -NurpP --minimal linux-3.13.10/arch/s390/kernel/syscalls.S linux-3.13.10-vs2.3.6.11/arch/s390/kernel/syscalls.S
569 --- linux-3.13.10/arch/s390/kernel/syscalls.S 2013-07-14 17:00:34.000000000 +0000
570 +++ linux-3.13.10-vs2.3.6.11/arch/s390/kernel/syscalls.S 2014-01-31 20:38:03.000000000 +0000
571 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
572 SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper) /* 260 */
573 SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
574 SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
575 -NI_SYSCALL /* reserved for vserver */
576 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
577 SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
578 SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
579 SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
580 diff -NurpP --minimal linux-3.13.10/arch/sh/Kconfig linux-3.13.10-vs2.3.6.11/arch/sh/Kconfig
581 --- linux-3.13.10/arch/sh/Kconfig 2014-01-22 20:38:24.000000000 +0000
582 +++ linux-3.13.10-vs2.3.6.11/arch/sh/Kconfig 2014-01-31 20:38:03.000000000 +0000
583 @@ -927,6 +927,8 @@ source "fs/Kconfig"
585 source "arch/sh/Kconfig.debug"
587 +source "kernel/vserver/Kconfig"
589 source "security/Kconfig"
591 source "crypto/Kconfig"
592 diff -NurpP --minimal linux-3.13.10/arch/sh/kernel/irq.c linux-3.13.10-vs2.3.6.11/arch/sh/kernel/irq.c
593 --- linux-3.13.10/arch/sh/kernel/irq.c 2014-01-22 20:38:24.000000000 +0000
594 +++ linux-3.13.10-vs2.3.6.11/arch/sh/kernel/irq.c 2014-01-31 20:38:03.000000000 +0000
596 #include <linux/ftrace.h>
597 #include <linux/delay.h>
598 #include <linux/ratelimit.h>
599 +// #include <linux/vs_context.h>
600 #include <asm/processor.h>
601 #include <asm/machvec.h>
602 #include <asm/uaccess.h>
603 diff -NurpP --minimal linux-3.13.10/arch/sparc/Kconfig linux-3.13.10-vs2.3.6.11/arch/sparc/Kconfig
604 --- linux-3.13.10/arch/sparc/Kconfig 2014-01-22 20:38:24.000000000 +0000
605 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/Kconfig 2014-01-31 20:38:03.000000000 +0000
606 @@ -553,6 +553,8 @@ source "fs/Kconfig"
608 source "arch/sparc/Kconfig.debug"
610 +source "kernel/vserver/Kconfig"
612 source "security/Kconfig"
614 source "crypto/Kconfig"
615 diff -NurpP --minimal linux-3.13.10/arch/sparc/include/uapi/asm/unistd.h linux-3.13.10-vs2.3.6.11/arch/sparc/include/uapi/asm/unistd.h
616 --- linux-3.13.10/arch/sparc/include/uapi/asm/unistd.h 2013-02-19 13:57:17.000000000 +0000
617 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/include/uapi/asm/unistd.h 2014-01-31 20:38:03.000000000 +0000
619 #define __NR_timer_getoverrun 264
620 #define __NR_timer_delete 265
621 #define __NR_timer_create 266
622 -/* #define __NR_vserver 267 Reserved for VSERVER */
623 +#define __NR_vserver 267
624 #define __NR_io_setup 268
625 #define __NR_io_destroy 269
626 #define __NR_io_submit 270
627 diff -NurpP --minimal linux-3.13.10/arch/sparc/kernel/systbls_32.S linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_32.S
628 --- linux-3.13.10/arch/sparc/kernel/systbls_32.S 2013-05-31 13:44:48.000000000 +0000
629 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_32.S 2014-01-31 20:38:03.000000000 +0000
630 @@ -70,7 +70,7 @@ sys_call_table:
631 /*250*/ .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
632 /*255*/ .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
633 /*260*/ .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
634 -/*265*/ .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
635 +/*265*/ .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
636 /*270*/ .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
637 /*275*/ .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
638 /*280*/ .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
639 diff -NurpP --minimal linux-3.13.10/arch/sparc/kernel/systbls_64.S linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_64.S
640 --- linux-3.13.10/arch/sparc/kernel/systbls_64.S 2013-07-14 17:00:35.000000000 +0000
641 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_64.S 2014-01-31 20:38:03.000000000 +0000
642 @@ -71,7 +71,7 @@ sys_call_table32:
643 /*250*/ .word sys_mremap, compat_sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
644 .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
645 /*260*/ .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
646 - .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
647 + .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
648 /*270*/ .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
649 .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
650 /*280*/ .word sys_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
651 @@ -149,7 +149,7 @@ sys_call_table:
652 /*250*/ .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
653 .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
654 /*260*/ .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
655 - .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
656 + .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
657 /*270*/ .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
658 .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
659 /*280*/ .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
660 diff -NurpP --minimal linux-3.13.10/arch/um/Kconfig.rest linux-3.13.10-vs2.3.6.11/arch/um/Kconfig.rest
661 --- linux-3.13.10/arch/um/Kconfig.rest 2012-12-11 03:30:57.000000000 +0000
662 +++ linux-3.13.10-vs2.3.6.11/arch/um/Kconfig.rest 2014-01-31 20:38:03.000000000 +0000
663 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
667 +source "kernel/vserver/Kconfig"
669 source "security/Kconfig"
671 source "crypto/Kconfig"
672 diff -NurpP --minimal linux-3.13.10/arch/x86/Kconfig linux-3.13.10-vs2.3.6.11/arch/x86/Kconfig
673 --- linux-3.13.10/arch/x86/Kconfig 2014-01-22 20:38:25.000000000 +0000
674 +++ linux-3.13.10-vs2.3.6.11/arch/x86/Kconfig 2014-01-31 20:38:03.000000000 +0000
675 @@ -2403,6 +2403,8 @@ source "fs/Kconfig"
677 source "arch/x86/Kconfig.debug"
679 +source "kernel/vserver/Kconfig"
681 source "security/Kconfig"
683 source "crypto/Kconfig"
684 diff -NurpP --minimal linux-3.13.10/arch/x86/syscalls/syscall_32.tbl linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_32.tbl
685 --- linux-3.13.10/arch/x86/syscalls/syscall_32.tbl 2013-07-14 17:00:37.000000000 +0000
686 +++ linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_32.tbl 2014-01-31 20:38:03.000000000 +0000
688 270 i386 tgkill sys_tgkill
689 271 i386 utimes sys_utimes compat_sys_utimes
690 272 i386 fadvise64_64 sys_fadvise64_64 sys32_fadvise64_64
692 +273 i386 vserver sys_vserver sys32_vserver
693 274 i386 mbind sys_mbind
694 275 i386 get_mempolicy sys_get_mempolicy compat_sys_get_mempolicy
695 276 i386 set_mempolicy sys_set_mempolicy
696 diff -NurpP --minimal linux-3.13.10/arch/x86/syscalls/syscall_64.tbl linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_64.tbl
697 --- linux-3.13.10/arch/x86/syscalls/syscall_64.tbl 2013-05-31 13:44:50.000000000 +0000
698 +++ linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_64.tbl 2014-01-31 20:38:03.000000000 +0000
700 233 common epoll_ctl sys_epoll_ctl
701 234 common tgkill sys_tgkill
702 235 common utimes sys_utimes
704 +236 64 vserver sys_vserver
705 237 common mbind sys_mbind
706 238 common set_mempolicy sys_set_mempolicy
707 239 common get_mempolicy sys_get_mempolicy
708 diff -NurpP --minimal linux-3.13.10/drivers/block/Kconfig linux-3.13.10-vs2.3.6.11/drivers/block/Kconfig
709 --- linux-3.13.10/drivers/block/Kconfig 2014-01-22 20:38:27.000000000 +0000
710 +++ linux-3.13.10-vs2.3.6.11/drivers/block/Kconfig 2014-01-31 20:38:03.000000000 +0000
711 @@ -281,6 +281,13 @@ config BLK_DEV_CRYPTOLOOP
713 source "drivers/block/drbd/Kconfig"
715 +config BLK_DEV_VROOT
716 + tristate "Virtual Root device support"
717 + depends on QUOTACTL
719 + Saying Y here will allow you to use quota/fs ioctls on a shared
720 + partition within a virtual server without compromising security.
723 tristate "Network block device support"
725 diff -NurpP --minimal linux-3.13.10/drivers/block/Makefile linux-3.13.10-vs2.3.6.11/drivers/block/Makefile
726 --- linux-3.13.10/drivers/block/Makefile 2014-01-22 20:38:27.000000000 +0000
727 +++ linux-3.13.10-vs2.3.6.11/drivers/block/Makefile 2014-01-31 20:38:03.000000000 +0000
728 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
729 obj-$(CONFIG_VIODASD) += viodasd.o
730 obj-$(CONFIG_BLK_DEV_SX8) += sx8.o
731 obj-$(CONFIG_BLK_DEV_HD) += hd.o
732 +obj-$(CONFIG_BLK_DEV_VROOT) += vroot.o
734 obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o
735 obj-$(CONFIG_XEN_BLKDEV_BACKEND) += xen-blkback/
736 diff -NurpP --minimal linux-3.13.10/drivers/block/loop.c linux-3.13.10-vs2.3.6.11/drivers/block/loop.c
737 --- linux-3.13.10/drivers/block/loop.c 2014-01-22 20:38:27.000000000 +0000
738 +++ linux-3.13.10-vs2.3.6.11/drivers/block/loop.c 2014-01-31 20:55:14.000000000 +0000
740 #include <linux/sysfs.h>
741 #include <linux/miscdevice.h>
742 #include <linux/falloc.h>
743 +#include <linux/vs_context.h>
746 #include <asm/uaccess.h>
747 @@ -884,6 +885,7 @@ static int loop_set_fd(struct loop_devic
748 lo->lo_blocksize = lo_blocksize;
749 lo->lo_device = bdev;
750 lo->lo_flags = lo_flags;
751 + lo->lo_xid = vx_current_xid();
752 lo->lo_backing_file = file;
753 lo->transfer = transfer_none;
755 @@ -1028,6 +1030,7 @@ static int loop_clr_fd(struct loop_devic
756 lo->lo_sizelimit = 0;
757 lo->lo_encrypt_key_size = 0;
758 lo->lo_thread = NULL;
760 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
761 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
762 memset(lo->lo_file_name, 0, LO_NAME_SIZE);
763 @@ -1071,7 +1074,7 @@ loop_set_status(struct loop_device *lo,
765 if (lo->lo_encrypt_key_size &&
766 !uid_eq(lo->lo_key_owner, uid) &&
767 - !capable(CAP_SYS_ADMIN))
768 + !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
770 if (lo->lo_state != Lo_bound)
772 @@ -1161,7 +1164,8 @@ loop_get_status(struct loop_device *lo,
773 memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
774 info->lo_encrypt_type =
775 lo->lo_encryption ? lo->lo_encryption->number : 0;
776 - if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
777 + if (lo->lo_encrypt_key_size &&
778 + vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
779 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
780 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
781 lo->lo_encrypt_key_size);
782 @@ -1503,6 +1507,11 @@ static int lo_open(struct block_device *
786 + if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
791 mutex_lock(&lo->lo_ctl_mutex);
793 mutex_unlock(&lo->lo_ctl_mutex);
794 diff -NurpP --minimal linux-3.13.10/drivers/block/loop.h linux-3.13.10-vs2.3.6.11/drivers/block/loop.h
795 --- linux-3.13.10/drivers/block/loop.h 2013-11-25 15:44:28.000000000 +0000
796 +++ linux-3.13.10-vs2.3.6.11/drivers/block/loop.h 2014-02-01 01:57:49.000000000 +0000
797 @@ -41,6 +41,7 @@ struct loop_device {
798 struct loop_func_table *lo_encryption;
800 kuid_t lo_key_owner; /* Who set the key */
802 int (*ioctl)(struct loop_device *, int cmd,
805 diff -NurpP --minimal linux-3.13.10/drivers/block/vroot.c linux-3.13.10-vs2.3.6.11/drivers/block/vroot.c
806 --- linux-3.13.10/drivers/block/vroot.c 1970-01-01 00:00:00.000000000 +0000
807 +++ linux-3.13.10-vs2.3.6.11/drivers/block/vroot.c 2014-01-31 20:38:03.000000000 +0000
810 + * linux/drivers/block/vroot.c
812 + * written by Herbert Pötzl, 9/11/2002
813 + * ported to 2.6.10 by Herbert Pötzl, 30/12/2004
815 + * based on the loop.c code by Theodore Ts'o.
817 + * Copyright (C) 2002-2007 by Herbert Pötzl.
818 + * Redistribution of this file is permitted under the
819 + * GNU General Public License.
823 +#include <linux/module.h>
824 +#include <linux/moduleparam.h>
825 +#include <linux/file.h>
826 +#include <linux/major.h>
827 +#include <linux/blkdev.h>
828 +#include <linux/slab.h>
830 +#include <linux/vroot.h>
831 +#include <linux/vs_context.h>
834 +static int max_vroot = 8;
836 +static struct vroot_device *vroot_dev;
837 +static struct gendisk **disks;
840 +static int vroot_set_dev(
841 + struct vroot_device *vr,
842 + struct block_device *bdev,
845 + struct block_device *real_bdev;
847 + struct inode *inode;
851 + if (vr->vr_state != Vr_unbound)
860 + inode = file->f_dentry->d_inode;
863 + if (S_ISBLK(inode->i_mode)) {
864 + real_bdev = inode->i_bdev;
865 + vr->vr_device = real_bdev;
866 + __iget(real_bdev->bd_inode);
870 + vxdprintk(VXD_CBIT(misc, 0),
871 + "vroot[%d]_set_dev: dev=" VXF_DEV,
872 + vr->vr_number, VXD_DEV(real_bdev));
874 + vr->vr_state = Vr_bound;
883 +static int vroot_clr_dev(
884 + struct vroot_device *vr,
885 + struct block_device *bdev)
887 + struct block_device *real_bdev;
889 + if (vr->vr_state != Vr_bound)
891 + if (vr->vr_refcnt > 1) /* we needed one fd for the ioctl */
894 + real_bdev = vr->vr_device;
896 + vxdprintk(VXD_CBIT(misc, 0),
897 + "vroot[%d]_clr_dev: dev=" VXF_DEV,
898 + vr->vr_number, VXD_DEV(real_bdev));
901 + vr->vr_state = Vr_unbound;
902 + vr->vr_device = NULL;
907 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
908 + unsigned int cmd, unsigned long arg)
910 + struct vroot_device *vr = bdev->bd_disk->private_data;
913 + down(&vr->vr_ctl_mutex);
915 + case VROOT_SET_DEV:
916 + err = vroot_set_dev(vr, bdev, arg);
918 + case VROOT_CLR_DEV:
919 + err = vroot_clr_dev(vr, bdev);
925 + up(&vr->vr_ctl_mutex);
929 +static int vr_open(struct block_device *bdev, fmode_t mode)
931 + struct vroot_device *vr = bdev->bd_disk->private_data;
933 + down(&vr->vr_ctl_mutex);
935 + up(&vr->vr_ctl_mutex);
939 +static void vr_release(struct gendisk *disk, fmode_t mode)
941 + struct vroot_device *vr = disk->private_data;
943 + down(&vr->vr_ctl_mutex);
945 + up(&vr->vr_ctl_mutex);
948 +static struct block_device_operations vr_fops = {
949 + .owner = THIS_MODULE,
951 + .release = vr_release,
955 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
957 + printk("vroot_make_request %p, %p\n", q, bio);
961 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
963 + struct inode *inode = bdev->bd_inode;
964 + struct vroot_device *vr;
965 + struct block_device *real_bdev;
966 + int minor = iminor(inode);
968 + vr = &vroot_dev[minor];
969 + real_bdev = vr->vr_device;
971 + vxdprintk(VXD_CBIT(misc, 0),
972 + "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
973 + vr->vr_number, VXD_DEV(real_bdev));
975 + if (vr->vr_state != Vr_bound)
976 + return ERR_PTR(-ENXIO);
978 + __iget(real_bdev->bd_inode);
985 + * And now the modules code and kernel interface.
988 +module_param(max_vroot, int, 0);
990 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
991 +MODULE_LICENSE("GPL");
992 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
994 +MODULE_AUTHOR ("Herbert Pötzl");
995 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
998 +int __init vroot_init(void)
1002 + if (max_vroot < 1 || max_vroot > 256) {
1003 + max_vroot = MAX_VROOT_DEFAULT;
1004 + printk(KERN_WARNING "vroot: invalid max_vroot "
1005 + "(must be between 1 and 256), "
1006 + "using default (%d)\n", max_vroot);
1009 + if (register_blkdev(VROOT_MAJOR, "vroot"))
1013 + vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1016 + memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1018 + disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1022 + for (i = 0; i < max_vroot; i++) {
1023 + disks[i] = alloc_disk(1);
1026 + disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1027 + if (!disks[i]->queue)
1029 + blk_queue_make_request(disks[i]->queue, vroot_make_request);
1032 + for (i = 0; i < max_vroot; i++) {
1033 + struct vroot_device *vr = &vroot_dev[i];
1034 + struct gendisk *disk = disks[i];
1036 + memset(vr, 0, sizeof(*vr));
1037 + sema_init(&vr->vr_ctl_mutex, 1);
1038 + vr->vr_number = i;
1039 + disk->major = VROOT_MAJOR;
1040 + disk->first_minor = i;
1041 + disk->fops = &vr_fops;
1042 + sprintf(disk->disk_name, "vroot%d", i);
1043 + disk->private_data = vr;
1046 + err = register_vroot_grb(&__vroot_get_real_bdev);
1050 + for (i = 0; i < max_vroot; i++)
1051 + add_disk(disks[i]);
1052 + printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1057 + put_disk(disks[i]);
1062 + unregister_blkdev(VROOT_MAJOR, "vroot");
1063 + printk(KERN_ERR "vroot: ran out of memory\n");
1067 +void vroot_exit(void)
1071 + if (unregister_vroot_grb(&__vroot_get_real_bdev))
1072 + printk(KERN_WARNING "vroot: cannot unregister grb\n");
1074 + for (i = 0; i < max_vroot; i++) {
1075 + del_gendisk(disks[i]);
1076 + put_disk(disks[i]);
1078 + unregister_blkdev(VROOT_MAJOR, "vroot");
1084 +module_init(vroot_init);
1085 +module_exit(vroot_exit);
1089 +static int __init max_vroot_setup(char *str)
1091 + max_vroot = simple_strtol(str, NULL, 0);
1095 +__setup("max_vroot=", max_vroot_setup);
1099 diff -NurpP --minimal linux-3.13.10/drivers/infiniband/core/addr.c linux-3.13.10-vs2.3.6.11/drivers/infiniband/core/addr.c
1100 --- linux-3.13.10/drivers/infiniband/core/addr.c 2013-11-25 15:44:35.000000000 +0000
1101 +++ linux-3.13.10-vs2.3.6.11/drivers/infiniband/core/addr.c 2014-01-31 20:38:03.000000000 +0000
1102 @@ -277,7 +277,7 @@ static int addr6_resolve(struct sockaddr
1104 if (ipv6_addr_any(&fl6.saddr)) {
1105 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1106 - &fl6.daddr, 0, &fl6.saddr);
1107 + &fl6.daddr, 0, &fl6.saddr, NULL);
1111 diff -NurpP --minimal linux-3.13.10/drivers/md/dm-ioctl.c linux-3.13.10-vs2.3.6.11/drivers/md/dm-ioctl.c
1112 --- linux-3.13.10/drivers/md/dm-ioctl.c 2014-01-22 20:38:36.000000000 +0000
1113 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm-ioctl.c 2014-01-31 21:01:49.000000000 +0000
1115 #include <linux/dm-ioctl.h>
1116 #include <linux/hdreg.h>
1117 #include <linux/compat.h>
1118 +#include <linux/vs_context.h>
1120 #include <asm/uaccess.h>
1122 @@ -114,7 +115,8 @@ static struct hash_cell *__get_name_cell
1123 unsigned int h = hash_str(str);
1125 list_for_each_entry (hc, _name_buckets + h, name_list)
1126 - if (!strcmp(hc->name, str)) {
1127 + if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1128 + !strcmp(hc->name, str)) {
1132 @@ -128,7 +130,8 @@ static struct hash_cell *__get_uuid_cell
1133 unsigned int h = hash_str(str);
1135 list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1136 - if (!strcmp(hc->uuid, str)) {
1137 + if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1138 + !strcmp(hc->uuid, str)) {
1142 @@ -139,13 +142,15 @@ static struct hash_cell *__get_uuid_cell
1143 static struct hash_cell *__get_dev_cell(uint64_t dev)
1145 struct mapped_device *md;
1146 - struct hash_cell *hc;
1147 + struct hash_cell *hc = NULL;
1149 md = dm_get_md(huge_decode_dev(dev));
1153 - hc = dm_get_mdptr(md);
1154 + if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1155 + hc = dm_get_mdptr(md);
1160 @@ -467,6 +472,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1162 static int remove_all(struct dm_ioctl *param, size_t param_size)
1164 + if (!vx_check(0, VS_ADMIN))
1167 dm_hash_remove_all(true, !!(param->flags & DM_DEFERRED_REMOVE), false);
1168 param->data_size = 0;
1170 @@ -514,6 +522,8 @@ static int list_devices(struct dm_ioctl
1172 for (i = 0; i < NUM_BUCKETS; i++) {
1173 list_for_each_entry (hc, _name_buckets + i, name_list) {
1174 + if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1176 needed += sizeof(struct dm_name_list);
1177 needed += strlen(hc->name) + 1;
1178 needed += ALIGN_MASK;
1179 @@ -537,6 +547,8 @@ static int list_devices(struct dm_ioctl
1181 for (i = 0; i < NUM_BUCKETS; i++) {
1182 list_for_each_entry (hc, _name_buckets + i, name_list) {
1183 + if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1186 old_nl->next = (uint32_t) ((void *) nl -
1188 @@ -1797,8 +1809,8 @@ static int ctl_ioctl(uint command, struc
1189 size_t input_param_size;
1190 struct dm_ioctl param_kernel;
1192 - /* only root can play with this */
1193 - if (!capable(CAP_SYS_ADMIN))
1194 + /* only root and certain contexts can play with this */
1195 + if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1198 if (_IOC_TYPE(command) != DM_IOCTL)
1199 diff -NurpP --minimal linux-3.13.10/drivers/md/dm.c linux-3.13.10-vs2.3.6.11/drivers/md/dm.c
1200 --- linux-3.13.10/drivers/md/dm.c 2014-04-17 01:12:19.000000000 +0000
1201 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm.c 2014-02-25 11:26:09.000000000 +0000
1203 #include <linux/idr.h>
1204 #include <linux/hdreg.h>
1205 #include <linux/delay.h>
1206 +#include <linux/vs_base.h>
1208 #include <trace/events/block.h>
1210 @@ -139,6 +140,7 @@ struct mapped_device {
1211 struct mutex suspend_lock;
1213 atomic_t open_count;
1217 * The current mapping.
1218 @@ -384,6 +386,7 @@ int dm_deleting_md(struct mapped_device
1219 static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1221 struct mapped_device *md;
1224 spin_lock(&_minor_lock);
1226 @@ -392,18 +395,19 @@ static int dm_blk_open(struct block_devi
1229 if (test_bit(DMF_FREEING, &md->flags) ||
1230 - dm_deleting_md(md)) {
1232 + dm_deleting_md(md))
1236 + if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1241 atomic_inc(&md->open_count);
1245 spin_unlock(&_minor_lock);
1247 - return md ? 0 : -ENXIO;
1251 static void dm_blk_close(struct gendisk *disk, fmode_t mode)
1252 @@ -687,6 +691,14 @@ int dm_set_geometry(struct mapped_device
1257 + * Get the xid associated with a dm device
1259 +vxid_t dm_get_xid(struct mapped_device *md)
1264 /*-----------------------------------------------------------------
1266 * A more elegant soln is in the works that uses the queue
1267 @@ -2026,6 +2038,7 @@ static struct mapped_device *alloc_dev(i
1268 INIT_LIST_HEAD(&md->uevent_list);
1269 spin_lock_init(&md->uevent_lock);
1271 + md->xid = vx_current_xid();
1272 md->queue = blk_alloc_queue(GFP_KERNEL);
1275 diff -NurpP --minimal linux-3.13.10/drivers/md/dm.h linux-3.13.10-vs2.3.6.11/drivers/md/dm.h
1276 --- linux-3.13.10/drivers/md/dm.h 2014-04-17 01:12:19.000000000 +0000
1277 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm.h 2014-02-25 11:26:09.000000000 +0000
1278 @@ -50,6 +50,8 @@ struct dm_dev_internal {
1280 struct dm_md_mempools;
1282 +vxid_t dm_get_xid(struct mapped_device *md);
1284 /*-----------------------------------------------------------------
1285 * Internal table functions.
1286 *---------------------------------------------------------------*/
1287 diff -NurpP --minimal linux-3.13.10/drivers/net/tun.c linux-3.13.10-vs2.3.6.11/drivers/net/tun.c
1288 --- linux-3.13.10/drivers/net/tun.c 2014-04-17 01:12:21.000000000 +0000
1289 +++ linux-3.13.10-vs2.3.6.11/drivers/net/tun.c 2014-04-17 01:17:10.000000000 +0000
1291 #include <linux/nsproxy.h>
1292 #include <linux/virtio_net.h>
1293 #include <linux/rcupdate.h>
1294 +#include <linux/vs_network.h>
1295 #include <net/net_namespace.h>
1296 #include <net/netns/generic.h>
1297 #include <net/rtnetlink.h>
1298 @@ -168,6 +169,7 @@ struct tun_struct {
1304 struct net_device *dev;
1305 netdev_features_t set_features;
1306 @@ -385,6 +387,7 @@ static inline bool tun_not_capable(struc
1307 return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1308 (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1309 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1310 + /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1313 static void tun_set_real_num_queues(struct tun_struct *tun)
1314 @@ -1382,6 +1385,7 @@ static void tun_setup(struct net_device
1316 tun->owner = INVALID_UID;
1317 tun->group = INVALID_GID;
1318 + tun->nid = nx_current_nid();
1320 dev->ethtool_ops = &tun_ethtool_ops;
1321 dev->destructor = tun_free_netdev;
1322 @@ -1598,7 +1602,7 @@ static int tun_set_iff(struct net *net,
1323 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1326 - if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1327 + if (!nx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1329 err = security_tun_dev_create();
1331 @@ -1969,6 +1973,16 @@ static long __tun_chr_ioctl(struct file
1332 from_kgid(&init_user_ns, tun->group));
1336 + if (!capable(CAP_CONTEXT))
1339 + /* Set nid owner of the device */
1340 + tun->nid = (vnid_t) arg;
1342 + tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1346 /* Only allow setting the type when the interface is down */
1347 if (tun->dev->flags & IFF_UP) {
1348 diff -NurpP --minimal linux-3.13.10/drivers/tty/sysrq.c linux-3.13.10-vs2.3.6.11/drivers/tty/sysrq.c
1349 --- linux-3.13.10/drivers/tty/sysrq.c 2014-01-22 20:39:02.000000000 +0000
1350 +++ linux-3.13.10-vs2.3.6.11/drivers/tty/sysrq.c 2014-01-31 20:55:49.000000000 +0000
1352 #include <linux/jiffies.h>
1353 #include <linux/syscalls.h>
1354 #include <linux/of.h>
1355 +#include <linux/vserver/debug.h>
1357 #include <asm/ptrace.h>
1358 #include <asm/irq_regs.h>
1359 @@ -407,6 +408,21 @@ static struct sysrq_key_op sysrq_unrt_op
1360 .enable_mask = SYSRQ_ENABLE_RTNICE,
1364 +#ifdef CONFIG_VSERVER_DEBUG
1365 +static void sysrq_handle_vxinfo(int key)
1367 + dump_vx_info_inactive((key == 'x') ? 0 : 1);
1370 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1371 + .handler = sysrq_handle_vxinfo,
1372 + .help_msg = "conteXt",
1373 + .action_msg = "Show Context Info",
1374 + .enable_mask = SYSRQ_ENABLE_DUMP,
1378 /* Key Operations table and lock */
1379 static DEFINE_SPINLOCK(sysrq_key_table_lock);
1381 @@ -462,7 +478,11 @@ static struct sysrq_key_op *sysrq_key_ta
1382 &sysrq_showstate_blocked_op, /* w */
1383 /* x: May be registered on ppc/powerpc for xmon */
1384 /* x: May be registered on sparc64 for global PMU dump */
1385 +#ifdef CONFIG_VSERVER_DEBUG
1386 + &sysrq_showvxinfo_op, /* x */
1390 /* y: May be registered on sparc64 for global register dump */
1392 &sysrq_ftrace_dump_op, /* z */
1393 @@ -477,6 +497,8 @@ static int sysrq_key_table_key2index(int
1395 else if ((key >= 'a') && (key <= 'z'))
1396 retval = key + 10 - 'a';
1397 + else if ((key >= 'A') && (key <= 'Z'))
1398 + retval = key + 10 - 'A';
1402 diff -NurpP --minimal linux-3.13.10/drivers/tty/tty_io.c linux-3.13.10-vs2.3.6.11/drivers/tty/tty_io.c
1403 --- linux-3.13.10/drivers/tty/tty_io.c 2014-01-22 20:39:02.000000000 +0000
1404 +++ linux-3.13.10-vs2.3.6.11/drivers/tty/tty_io.c 2014-01-31 20:38:03.000000000 +0000
1407 #include <linux/kmod.h>
1408 #include <linux/nsproxy.h>
1409 +#include <linux/vs_pid.h>
1411 #undef TTY_DEBUG_HANGUP
1413 @@ -2218,7 +2219,8 @@ static int tiocsti(struct tty_struct *tt
1415 struct tty_ldisc *ld;
1417 - if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1418 + if (((current->signal->tty != tty) &&
1419 + !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1421 if (get_user(ch, p))
1423 @@ -2506,6 +2508,7 @@ static int tiocspgrp(struct tty_struct *
1425 if (get_user(pgrp_nr, p))
1427 + pgrp_nr = vx_rmap_pid(pgrp_nr);
1431 diff -NurpP --minimal linux-3.13.10/fs/attr.c linux-3.13.10-vs2.3.6.11/fs/attr.c
1432 --- linux-3.13.10/fs/attr.c 2014-04-17 01:12:31.000000000 +0000
1433 +++ linux-3.13.10-vs2.3.6.11/fs/attr.c 2014-03-12 15:51:07.000000000 +0000
1435 #include <linux/security.h>
1436 #include <linux/evm.h>
1437 #include <linux/ima.h>
1438 +#include <linux/proc_fs.h>
1439 +#include <linux/devpts_fs.h>
1440 +#include <linux/vs_tag.h>
1443 * inode_change_ok - check if attribute changes to an inode are allowed
1444 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1448 + /* check for inode tag permission */
1449 + if (dx_permission(inode, MAY_WRITE))
1454 EXPORT_SYMBOL(inode_change_ok);
1455 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1456 inode->i_uid = attr->ia_uid;
1457 if (ia_valid & ATTR_GID)
1458 inode->i_gid = attr->ia_gid;
1459 + if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1460 + inode->i_tag = attr->ia_tag;
1461 if (ia_valid & ATTR_ATIME)
1462 inode->i_atime = timespec_trunc(attr->ia_atime,
1463 inode->i_sb->s_time_gran);
1464 @@ -197,7 +206,8 @@ int notify_change(struct dentry * dentry
1466 WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1468 - if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1469 + if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1470 + ATTR_TAG | ATTR_TIMES_SET)) {
1471 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1474 diff -NurpP --minimal linux-3.13.10/fs/block_dev.c linux-3.13.10-vs2.3.6.11/fs/block_dev.c
1475 --- linux-3.13.10/fs/block_dev.c 2013-11-25 15:46:58.000000000 +0000
1476 +++ linux-3.13.10-vs2.3.6.11/fs/block_dev.c 2014-01-31 20:38:03.000000000 +0000
1478 #include <linux/log2.h>
1479 #include <linux/cleancache.h>
1480 #include <linux/aio.h>
1481 +#include <linux/vs_device.h>
1482 #include <asm/uaccess.h>
1483 #include "internal.h"
1485 @@ -515,6 +516,7 @@ struct block_device *bdget(dev_t dev)
1486 bdev->bd_invalidated = 0;
1487 inode->i_mode = S_IFBLK;
1488 inode->i_rdev = dev;
1489 + inode->i_mdev = dev;
1490 inode->i_bdev = bdev;
1491 inode->i_data.a_ops = &def_blk_aops;
1492 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1493 @@ -562,6 +564,11 @@ EXPORT_SYMBOL(bdput);
1494 static struct block_device *bd_acquire(struct inode *inode)
1496 struct block_device *bdev;
1499 + if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1501 + inode->i_mdev = mdev;
1503 spin_lock(&bdev_lock);
1504 bdev = inode->i_bdev;
1505 @@ -572,7 +579,7 @@ static struct block_device *bd_acquire(s
1507 spin_unlock(&bdev_lock);
1509 - bdev = bdget(inode->i_rdev);
1510 + bdev = bdget(mdev);
1512 spin_lock(&bdev_lock);
1513 if (!inode->i_bdev) {
1514 diff -NurpP --minimal linux-3.13.10/fs/btrfs/ctree.h linux-3.13.10-vs2.3.6.11/fs/btrfs/ctree.h
1515 --- linux-3.13.10/fs/btrfs/ctree.h 2014-01-22 20:39:05.000000000 +0000
1516 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/ctree.h 2014-01-31 23:58:35.000000000 +0000
1517 @@ -718,11 +718,14 @@ struct btrfs_inode_item {
1518 /* modification sequence number for NFS */
1523 * a little future expansion, for more than this we can
1524 * just grow the inode item and version it
1526 - __le64 reserved[4];
1527 + __le16 reserved16;
1528 + __le32 reserved32;
1529 + __le64 reserved[3];
1530 struct btrfs_timespec atime;
1531 struct btrfs_timespec ctime;
1532 struct btrfs_timespec mtime;
1533 @@ -2000,6 +2003,8 @@ struct btrfs_ioctl_defrag_range_args {
1535 #define BTRFS_DEFAULT_COMMIT_INTERVAL (30)
1537 +#define BTRFS_MOUNT_TAGGED (1 << 24)
1539 #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
1540 #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
1541 #define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt)
1542 @@ -2269,6 +2274,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1543 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1544 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1545 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1546 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1547 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1548 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1549 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1550 @@ -2341,6 +2347,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1552 BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1554 +#define BTRFS_INODE_IXUNLINK (1 << 24)
1555 +#define BTRFS_INODE_BARRIER (1 << 25)
1556 +#define BTRFS_INODE_COW (1 << 26)
1559 BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1561 @@ -3722,6 +3732,7 @@ long btrfs_ioctl(struct file *file, unsi
1562 void btrfs_update_iflags(struct inode *inode);
1563 void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1564 int btrfs_is_empty_uuid(u8 *uuid);
1565 +int btrfs_sync_flags(struct inode *inode, int, int);
1566 int btrfs_defrag_file(struct inode *inode, struct file *file,
1567 struct btrfs_ioctl_defrag_range_args *range,
1568 u64 newer_than, unsigned long max_pages);
1569 diff -NurpP --minimal linux-3.13.10/fs/btrfs/disk-io.c linux-3.13.10-vs2.3.6.11/fs/btrfs/disk-io.c
1570 --- linux-3.13.10/fs/btrfs/disk-io.c 2014-01-22 20:39:05.000000000 +0000
1571 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/disk-io.c 2014-01-31 20:38:03.000000000 +0000
1572 @@ -2388,6 +2388,9 @@ int open_ctree(struct super_block *sb,
1576 + if (btrfs_test_opt(tree_root, TAGGED))
1577 + sb->s_flags |= MS_TAGGED;
1579 features = btrfs_super_incompat_flags(disk_super) &
1580 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1582 diff -NurpP --minimal linux-3.13.10/fs/btrfs/inode.c linux-3.13.10-vs2.3.6.11/fs/btrfs/inode.c
1583 --- linux-3.13.10/fs/btrfs/inode.c 2014-04-17 01:12:31.000000000 +0000
1584 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/inode.c 2014-03-12 15:51:07.000000000 +0000
1586 #include <linux/btrfs.h>
1587 #include <linux/blkdev.h>
1588 #include <linux/posix_acl_xattr.h>
1589 +#include <linux/vs_tag.h>
1591 #include "disk-io.h"
1592 #include "transaction.h"
1593 @@ -3317,6 +3318,9 @@ static void btrfs_read_locked_inode(stru
1594 struct btrfs_key location;
1601 bool filled = false;
1603 @@ -3344,8 +3348,14 @@ static void btrfs_read_locked_inode(stru
1604 struct btrfs_inode_item);
1605 inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1606 set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1607 - i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1608 - i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1610 + kuid = make_kuid(&init_user_ns, btrfs_inode_uid(leaf, inode_item));
1611 + kgid = make_kgid(&init_user_ns, btrfs_inode_gid(leaf, inode_item));
1612 + ktag = make_ktag(&init_user_ns, btrfs_inode_tag(leaf, inode_item));
1614 + inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
1615 + inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
1616 + inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
1617 btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1619 tspec = btrfs_inode_atime(inode_item);
1620 @@ -3436,11 +3446,18 @@ static void fill_inode_item(struct btrfs
1621 struct inode *inode)
1623 struct btrfs_map_token token;
1624 + uid_t uid = from_kuid(&init_user_ns,
1625 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
1626 + gid_t gid = from_kgid(&init_user_ns,
1627 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
1629 btrfs_init_map_token(&token);
1631 - btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1632 - btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1633 + btrfs_set_token_inode_uid(leaf, item, uid, &token);
1634 + btrfs_set_token_inode_gid(leaf, item, gid, &token);
1635 +#ifdef CONFIG_TAGGING_INTERN
1636 + btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1638 btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1640 btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1641 @@ -8652,14 +8669,17 @@ static const struct inode_operations btr
1642 .listxattr = btrfs_listxattr,
1643 .removexattr = btrfs_removexattr,
1644 .permission = btrfs_permission,
1645 + .sync_flags = btrfs_sync_flags,
1646 .get_acl = btrfs_get_acl,
1647 .set_acl = btrfs_set_acl,
1648 .update_time = btrfs_update_time,
1651 static const struct inode_operations btrfs_dir_ro_inode_operations = {
1652 .lookup = btrfs_lookup,
1653 .permission = btrfs_permission,
1654 + .sync_flags = btrfs_sync_flags,
1655 .get_acl = btrfs_get_acl,
1656 .set_acl = btrfs_set_acl,
1657 .update_time = btrfs_update_time,
1659 @@ -8727,6 +8747,7 @@ static const struct inode_operations btr
1660 .removexattr = btrfs_removexattr,
1661 .permission = btrfs_permission,
1662 .fiemap = btrfs_fiemap,
1663 + .sync_flags = btrfs_sync_flags,
1664 .get_acl = btrfs_get_acl,
1665 .update_time = btrfs_update_time,
1667 diff -NurpP --minimal linux-3.13.10/fs/btrfs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/btrfs/ioctl.c
1668 --- linux-3.13.10/fs/btrfs/ioctl.c 2014-04-17 01:12:31.000000000 +0000
1669 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/ioctl.c 2014-02-25 11:26:09.000000000 +0000
1670 @@ -78,10 +78,13 @@ static unsigned int btrfs_flags_to_ioctl
1672 unsigned int iflags = 0;
1674 - if (flags & BTRFS_INODE_SYNC)
1675 - iflags |= FS_SYNC_FL;
1676 if (flags & BTRFS_INODE_IMMUTABLE)
1677 iflags |= FS_IMMUTABLE_FL;
1678 + if (flags & BTRFS_INODE_IXUNLINK)
1679 + iflags |= FS_IXUNLINK_FL;
1681 + if (flags & BTRFS_INODE_SYNC)
1682 + iflags |= FS_SYNC_FL;
1683 if (flags & BTRFS_INODE_APPEND)
1684 iflags |= FS_APPEND_FL;
1685 if (flags & BTRFS_INODE_NODUMP)
1686 @@ -98,28 +101,78 @@ static unsigned int btrfs_flags_to_ioctl
1687 else if (flags & BTRFS_INODE_NOCOMPRESS)
1688 iflags |= FS_NOCOMP_FL;
1690 + if (flags & BTRFS_INODE_BARRIER)
1691 + iflags |= FS_BARRIER_FL;
1692 + if (flags & BTRFS_INODE_COW)
1693 + iflags |= FS_COW_FL;
1698 - * Update inode->i_flags based on the btrfs internal flags.
1699 + * Update inode->i_(v)flags based on the btrfs internal flags.
1701 void btrfs_update_iflags(struct inode *inode)
1703 struct btrfs_inode *ip = BTRFS_I(inode);
1705 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1706 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1707 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1709 - if (ip->flags & BTRFS_INODE_SYNC)
1710 - inode->i_flags |= S_SYNC;
1711 if (ip->flags & BTRFS_INODE_IMMUTABLE)
1712 inode->i_flags |= S_IMMUTABLE;
1713 + if (ip->flags & BTRFS_INODE_IXUNLINK)
1714 + inode->i_flags |= S_IXUNLINK;
1716 + if (ip->flags & BTRFS_INODE_SYNC)
1717 + inode->i_flags |= S_SYNC;
1718 if (ip->flags & BTRFS_INODE_APPEND)
1719 inode->i_flags |= S_APPEND;
1720 if (ip->flags & BTRFS_INODE_NOATIME)
1721 inode->i_flags |= S_NOATIME;
1722 if (ip->flags & BTRFS_INODE_DIRSYNC)
1723 inode->i_flags |= S_DIRSYNC;
1725 + inode->i_vflags &= ~(V_BARRIER | V_COW);
1727 + if (ip->flags & BTRFS_INODE_BARRIER)
1728 + inode->i_vflags |= V_BARRIER;
1729 + if (ip->flags & BTRFS_INODE_COW)
1730 + inode->i_vflags |= V_COW;
1734 + * Update btrfs internal flags from inode->i_(v)flags.
1736 +void btrfs_update_flags(struct inode *inode)
1738 + struct btrfs_inode *ip = BTRFS_I(inode);
1740 + unsigned int flags = inode->i_flags;
1741 + unsigned int vflags = inode->i_vflags;
1743 + ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1744 + BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1745 + BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1746 + BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1748 + if (flags & S_IMMUTABLE)
1749 + ip->flags |= BTRFS_INODE_IMMUTABLE;
1750 + if (flags & S_IXUNLINK)
1751 + ip->flags |= BTRFS_INODE_IXUNLINK;
1753 + if (flags & S_SYNC)
1754 + ip->flags |= BTRFS_INODE_SYNC;
1755 + if (flags & S_APPEND)
1756 + ip->flags |= BTRFS_INODE_APPEND;
1757 + if (flags & S_NOATIME)
1758 + ip->flags |= BTRFS_INODE_NOATIME;
1759 + if (flags & S_DIRSYNC)
1760 + ip->flags |= BTRFS_INODE_DIRSYNC;
1762 + if (vflags & V_BARRIER)
1763 + ip->flags |= BTRFS_INODE_BARRIER;
1764 + if (vflags & V_COW)
1765 + ip->flags |= BTRFS_INODE_COW;
1769 @@ -135,6 +188,7 @@ void btrfs_inherit_iflags(struct inode *
1772 flags = BTRFS_I(dir)->flags;
1773 + flags &= ~BTRFS_INODE_BARRIER;
1775 if (flags & BTRFS_INODE_NOCOMPRESS) {
1776 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1777 @@ -153,6 +207,30 @@ void btrfs_inherit_iflags(struct inode *
1778 btrfs_update_iflags(inode);
1781 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1783 + struct btrfs_inode *ip = BTRFS_I(inode);
1784 + struct btrfs_root *root = ip->root;
1785 + struct btrfs_trans_handle *trans;
1788 + trans = btrfs_join_transaction(root);
1791 + inode->i_flags = flags;
1792 + inode->i_vflags = vflags;
1793 + btrfs_update_flags(inode);
1795 + ret = btrfs_update_inode(trans, root, inode);
1798 + btrfs_update_iflags(inode);
1799 + inode->i_ctime = CURRENT_TIME;
1800 + btrfs_end_transaction(trans, root);
1805 static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1807 struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1808 @@ -215,21 +293,27 @@ static int btrfs_ioctl_setflags(struct f
1810 flags = btrfs_mask_flags(inode->i_mode, flags);
1811 oldflags = btrfs_flags_to_ioctl(ip->flags);
1812 - if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1813 + if ((flags ^ oldflags) & (FS_APPEND_FL |
1814 + FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1815 if (!capable(CAP_LINUX_IMMUTABLE)) {
1821 - if (flags & FS_SYNC_FL)
1822 - ip->flags |= BTRFS_INODE_SYNC;
1824 - ip->flags &= ~BTRFS_INODE_SYNC;
1825 if (flags & FS_IMMUTABLE_FL)
1826 ip->flags |= BTRFS_INODE_IMMUTABLE;
1828 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1829 + if (flags & FS_IXUNLINK_FL)
1830 + ip->flags |= BTRFS_INODE_IXUNLINK;
1832 + ip->flags &= ~BTRFS_INODE_IXUNLINK;
1834 + if (flags & FS_SYNC_FL)
1835 + ip->flags |= BTRFS_INODE_SYNC;
1837 + ip->flags &= ~BTRFS_INODE_SYNC;
1838 if (flags & FS_APPEND_FL)
1839 ip->flags |= BTRFS_INODE_APPEND;
1841 diff -NurpP --minimal linux-3.13.10/fs/btrfs/super.c linux-3.13.10-vs2.3.6.11/fs/btrfs/super.c
1842 --- linux-3.13.10/fs/btrfs/super.c 2014-01-22 20:39:05.000000000 +0000
1843 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/super.c 2014-01-31 23:58:08.000000000 +0000
1844 @@ -323,7 +323,7 @@ enum {
1845 Opt_commit_interval, Opt_barrier, Opt_nodefrag, Opt_nodiscard,
1846 Opt_noenospc_debug, Opt_noflushoncommit, Opt_acl, Opt_datacow,
1847 Opt_datasum, Opt_treelog, Opt_noinode_cache,
1849 + Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1852 static match_table_t tokens = {
1853 @@ -365,6 +365,9 @@ static match_table_t tokens = {
1854 {Opt_rescan_uuid_tree, "rescan_uuid_tree"},
1855 {Opt_fatal_errors, "fatal_errors=%s"},
1856 {Opt_commit_interval, "commit=%d"},
1858 + {Opt_notag, "notag"},
1859 + {Opt_tagid, "tagid=%u"},
1863 @@ -674,6 +677,22 @@ int btrfs_parse_options(struct btrfs_roo
1864 info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
1867 +#ifndef CONFIG_TAGGING_NONE
1869 + printk(KERN_INFO "btrfs: use tagging\n");
1870 + btrfs_set_opt(info->mount_opt, TAGGED);
1873 + printk(KERN_INFO "btrfs: disabled tagging\n");
1874 + btrfs_clear_opt(info->mount_opt, TAGGED);
1877 +#ifdef CONFIG_PROPAGATE
1880 + btrfs_set_opt(info->mount_opt, TAGGED);
1884 printk(KERN_INFO "btrfs: unrecognized mount option "
1886 @@ -1320,6 +1339,12 @@ static int btrfs_remount(struct super_bl
1887 btrfs_resize_thread_pool(fs_info,
1888 fs_info->thread_pool_size, old_thread_pool_size);
1890 + if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1891 + printk("btrfs: %s: tagging not permitted on remount.\n",
1896 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1899 diff -NurpP --minimal linux-3.13.10/fs/char_dev.c linux-3.13.10-vs2.3.6.11/fs/char_dev.c
1900 --- linux-3.13.10/fs/char_dev.c 2014-01-22 20:39:05.000000000 +0000
1901 +++ linux-3.13.10-vs2.3.6.11/fs/char_dev.c 2014-01-31 20:38:03.000000000 +0000
1903 #include <linux/mutex.h>
1904 #include <linux/backing-dev.h>
1905 #include <linux/tty.h>
1906 +#include <linux/vs_context.h>
1907 +#include <linux/vs_device.h>
1909 #include "internal.h"
1911 @@ -372,14 +374,21 @@ static int chrdev_open(struct inode *ino
1913 struct cdev *new = NULL;
1917 + if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
1919 + inode->i_mdev = mdev;
1921 spin_lock(&cdev_lock);
1924 struct kobject *kobj;
1927 spin_unlock(&cdev_lock);
1928 - kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
1930 + kobj = kobj_lookup(cdev_map, mdev, &idx);
1933 new = container_of(kobj, struct cdev, kobj);
1934 diff -NurpP --minimal linux-3.13.10/fs/dcache.c linux-3.13.10-vs2.3.6.11/fs/dcache.c
1935 --- linux-3.13.10/fs/dcache.c 2014-04-17 01:12:32.000000000 +0000
1936 +++ linux-3.13.10-vs2.3.6.11/fs/dcache.c 2014-04-17 01:17:10.000000000 +0000
1938 #include <linux/prefetch.h>
1939 #include <linux/ratelimit.h>
1940 #include <linux/list_lru.h>
1941 +#include <linux/vs_limit.h>
1942 #include "internal.h"
1945 @@ -640,6 +641,8 @@ int d_invalidate(struct dentry * dentry)
1946 spin_lock(&dentry->d_lock);
1949 + vx_dentry_dec(dentry);
1952 * Somebody else still using it?
1954 @@ -669,6 +672,7 @@ EXPORT_SYMBOL(d_invalidate);
1955 static inline void __dget_dlock(struct dentry *dentry)
1957 dentry->d_lockref.count++;
1958 + vx_dentry_inc(dentry);
1961 static inline void __dget(struct dentry *dentry)
1962 @@ -1483,6 +1487,9 @@ struct dentry *__d_alloc(struct super_bl
1963 struct dentry *dentry;
1966 + if (!vx_dentry_avail(1))
1969 dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
1972 @@ -1515,6 +1522,7 @@ struct dentry *__d_alloc(struct super_bl
1974 dentry->d_lockref.count = 1;
1975 dentry->d_flags = 0;
1976 + vx_dentry_inc(dentry);
1977 spin_lock_init(&dentry->d_lock);
1978 seqcount_init(&dentry->d_seq);
1979 dentry->d_inode = NULL;
1980 @@ -2278,6 +2286,7 @@ struct dentry *__d_lookup(const struct d
1983 dentry->d_lockref.count++;
1984 + vx_dentry_inc(dentry);
1986 spin_unlock(&dentry->d_lock);
1988 diff -NurpP --minimal linux-3.13.10/fs/devpts/inode.c linux-3.13.10-vs2.3.6.11/fs/devpts/inode.c
1989 --- linux-3.13.10/fs/devpts/inode.c 2014-01-22 20:39:06.000000000 +0000
1990 +++ linux-3.13.10-vs2.3.6.11/fs/devpts/inode.c 2014-02-01 01:40:53.000000000 +0000
1992 #include <linux/parser.h>
1993 #include <linux/fsnotify.h>
1994 #include <linux/seq_file.h>
1995 +#include <linux/vs_base.h>
1997 #define DEVPTS_DEFAULT_MODE 0600
2000 #define DEVPTS_DEFAULT_PTMX_MODE 0000
2001 #define PTMX_MINOR 2
2003 +static int devpts_permission(struct inode *inode, int mask)
2005 + int ret = -EACCES;
2007 + /* devpts is xid tagged */
2008 + if (vx_check((vxid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2009 + ret = generic_permission(inode, mask);
2013 +static struct inode_operations devpts_file_inode_operations = {
2014 + .permission = devpts_permission,
2019 * sysctl support for setting limits on the number of Unix98 ptys allocated.
2020 * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2021 @@ -345,6 +361,34 @@ static int devpts_show_options(struct se
2025 +static int devpts_filter(struct dentry *de)
2029 + /* devpts is xid tagged */
2030 + if (de && de->d_inode)
2031 + xid = (vxid_t)i_tag_read(de->d_inode);
2032 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2034 + vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2035 + de->d_name.len, de->d_name.name);
2037 + return vx_check(xid, VS_WATCH_P | VS_IDENT);
2040 +static int devpts_readdir(struct file * filp, struct dir_context *ctx)
2042 + return dcache_readdir_filter(filp, ctx, devpts_filter);
2045 +static struct file_operations devpts_dir_operations = {
2046 + .open = dcache_dir_open,
2047 + .release = dcache_dir_close,
2048 + .llseek = dcache_dir_lseek,
2049 + .read = generic_read_dir,
2050 + .iterate = devpts_readdir,
2053 static const struct super_operations devpts_sops = {
2054 .statfs = simple_statfs,
2055 .remount_fs = devpts_remount,
2056 @@ -388,8 +432,10 @@ devpts_fill_super(struct super_block *s,
2057 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2058 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2059 inode->i_op = &simple_dir_inode_operations;
2060 - inode->i_fop = &simple_dir_operations;
2061 + inode->i_fop = &devpts_dir_operations;
2062 set_nlink(inode, 2);
2063 + /* devpts is xid tagged */
2064 + i_tag_write(inode, (vtag_t)vx_current_xid());
2066 s->s_root = d_make_root(inode);
2068 @@ -593,6 +639,9 @@ struct inode *devpts_pty_new(struct inod
2069 inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2070 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2071 init_special_inode(inode, S_IFCHR|opts->mode, device);
2072 + /* devpts is xid tagged */
2073 + i_tag_write(inode, (vtag_t)vx_current_xid());
2074 + inode->i_op = &devpts_file_inode_operations;
2075 inode->i_private = priv;
2077 sprintf(s, "%d", index);
2078 diff -NurpP --minimal linux-3.13.10/fs/ext2/balloc.c linux-3.13.10-vs2.3.6.11/fs/ext2/balloc.c
2079 --- linux-3.13.10/fs/ext2/balloc.c 2013-05-31 13:45:23.000000000 +0000
2080 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/balloc.c 2014-01-31 20:38:03.000000000 +0000
2081 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2083 end = EXT2_BLOCKS_PER_GROUP(sb);
2086 BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2089 diff -NurpP --minimal linux-3.13.10/fs/ext2/ext2.h linux-3.13.10-vs2.3.6.11/fs/ext2/ext2.h
2090 --- linux-3.13.10/fs/ext2/ext2.h 2012-12-11 03:30:57.000000000 +0000
2091 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ext2.h 2014-01-31 20:38:03.000000000 +0000
2092 @@ -244,8 +244,12 @@ struct ext2_group_desc
2093 #define EXT2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
2094 #define EXT2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
2095 #define EXT2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
2096 +#define EXT2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
2097 #define EXT2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
2099 +#define EXT2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
2100 +#define EXT2_COW_FL FS_COW_FL /* Copy on Write marker */
2102 #define EXT2_FL_USER_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
2103 #define EXT2_FL_USER_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
2105 @@ -329,7 +333,8 @@ struct ext2_inode {
2107 __le16 l_i_uid_high; /* these 2 fields */
2108 __le16 l_i_gid_high; /* were reserved2[0] */
2109 - __u32 l_i_reserved2;
2110 + __le16 l_i_tag; /* Context Tag */
2111 + __u16 l_i_reserved2;
2114 __u8 h_i_frag; /* Fragment number */
2115 @@ -357,6 +362,7 @@ struct ext2_inode {
2116 #define i_gid_low i_gid
2117 #define i_uid_high osd2.linux2.l_i_uid_high
2118 #define i_gid_high osd2.linux2.l_i_gid_high
2119 +#define i_raw_tag osd2.linux2.l_i_tag
2120 #define i_reserved2 osd2.linux2.l_i_reserved2
2123 @@ -384,6 +390,7 @@ struct ext2_inode {
2124 #define EXT2_MOUNT_USRQUOTA 0x020000 /* user quota */
2125 #define EXT2_MOUNT_GRPQUOTA 0x040000 /* group quota */
2126 #define EXT2_MOUNT_RESERVATION 0x080000 /* Preallocation */
2127 +#define EXT2_MOUNT_TAGGED (1<<24) /* Enable Context Tags */
2130 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
2131 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2132 extern void ext2_get_inode_flags(struct ext2_inode_info *);
2133 extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2134 u64 start, u64 len);
2135 +extern int ext2_sync_flags(struct inode *, int, int);
2138 extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2139 diff -NurpP --minimal linux-3.13.10/fs/ext2/file.c linux-3.13.10-vs2.3.6.11/fs/ext2/file.c
2140 --- linux-3.13.10/fs/ext2/file.c 2012-12-11 03:30:57.000000000 +0000
2141 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/file.c 2014-01-31 20:38:03.000000000 +0000
2142 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2143 .setattr = ext2_setattr,
2144 .get_acl = ext2_get_acl,
2145 .fiemap = ext2_fiemap,
2146 + .sync_flags = ext2_sync_flags,
2148 diff -NurpP --minimal linux-3.13.10/fs/ext2/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext2/ialloc.c
2149 --- linux-3.13.10/fs/ext2/ialloc.c 2013-05-31 13:45:23.000000000 +0000
2150 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ialloc.c 2014-01-31 20:38:03.000000000 +0000
2152 #include <linux/backing-dev.h>
2153 #include <linux/buffer_head.h>
2154 #include <linux/random.h>
2155 +#include <linux/vs_tag.h>
2159 @@ -546,6 +547,7 @@ got:
2160 inode->i_mode = mode;
2161 inode->i_uid = current_fsuid();
2162 inode->i_gid = dir->i_gid;
2163 + i_tag_write(inode, dx_current_fstag(sb));
2165 inode_init_owner(inode, dir, mode);
2167 diff -NurpP --minimal linux-3.13.10/fs/ext2/inode.c linux-3.13.10-vs2.3.6.11/fs/ext2/inode.c
2168 --- linux-3.13.10/fs/ext2/inode.c 2014-01-22 20:39:06.000000000 +0000
2169 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/inode.c 2014-01-31 20:38:03.000000000 +0000
2171 #include <linux/fiemap.h>
2172 #include <linux/namei.h>
2173 #include <linux/aio.h>
2174 +#include <linux/vs_tag.h>
2178 @@ -1182,7 +1183,7 @@ static void ext2_truncate_blocks(struct
2180 if (ext2_inode_is_fast_symlink(inode))
2182 - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2183 + if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2185 __ext2_truncate_blocks(inode, offset);
2187 @@ -1273,36 +1274,61 @@ void ext2_set_inode_flags(struct inode *
2189 unsigned int flags = EXT2_I(inode)->i_flags;
2191 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2192 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2193 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2196 + if (flags & EXT2_IMMUTABLE_FL)
2197 + inode->i_flags |= S_IMMUTABLE;
2198 + if (flags & EXT2_IXUNLINK_FL)
2199 + inode->i_flags |= S_IXUNLINK;
2201 if (flags & EXT2_SYNC_FL)
2202 inode->i_flags |= S_SYNC;
2203 if (flags & EXT2_APPEND_FL)
2204 inode->i_flags |= S_APPEND;
2205 - if (flags & EXT2_IMMUTABLE_FL)
2206 - inode->i_flags |= S_IMMUTABLE;
2207 if (flags & EXT2_NOATIME_FL)
2208 inode->i_flags |= S_NOATIME;
2209 if (flags & EXT2_DIRSYNC_FL)
2210 inode->i_flags |= S_DIRSYNC;
2212 + inode->i_vflags &= ~(V_BARRIER | V_COW);
2214 + if (flags & EXT2_BARRIER_FL)
2215 + inode->i_vflags |= V_BARRIER;
2216 + if (flags & EXT2_COW_FL)
2217 + inode->i_vflags |= V_COW;
2220 /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2221 void ext2_get_inode_flags(struct ext2_inode_info *ei)
2223 unsigned int flags = ei->vfs_inode.i_flags;
2224 + unsigned int vflags = ei->vfs_inode.i_vflags;
2226 + ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2227 + EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2228 + EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2229 + EXT2_BARRIER_FL | EXT2_COW_FL);
2231 + if (flags & S_IMMUTABLE)
2232 + ei->i_flags |= EXT2_IMMUTABLE_FL;
2233 + if (flags & S_IXUNLINK)
2234 + ei->i_flags |= EXT2_IXUNLINK_FL;
2236 - ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2237 - EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2239 ei->i_flags |= EXT2_SYNC_FL;
2240 if (flags & S_APPEND)
2241 ei->i_flags |= EXT2_APPEND_FL;
2242 - if (flags & S_IMMUTABLE)
2243 - ei->i_flags |= EXT2_IMMUTABLE_FL;
2244 if (flags & S_NOATIME)
2245 ei->i_flags |= EXT2_NOATIME_FL;
2246 if (flags & S_DIRSYNC)
2247 ei->i_flags |= EXT2_DIRSYNC_FL;
2249 + if (vflags & V_BARRIER)
2250 + ei->i_flags |= EXT2_BARRIER_FL;
2251 + if (vflags & V_COW)
2252 + ei->i_flags |= EXT2_COW_FL;
2255 struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2256 @@ -1338,8 +1364,10 @@ struct inode *ext2_iget (struct super_bl
2257 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2258 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2260 - i_uid_write(inode, i_uid);
2261 - i_gid_write(inode, i_gid);
2262 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2263 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2264 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2265 + le16_to_cpu(raw_inode->i_raw_tag)));
2266 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2267 inode->i_size = le32_to_cpu(raw_inode->i_size);
2268 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2269 @@ -1437,8 +1465,10 @@ static int __ext2_write_inode(struct ino
2270 struct ext2_inode_info *ei = EXT2_I(inode);
2271 struct super_block *sb = inode->i_sb;
2272 ino_t ino = inode->i_ino;
2273 - uid_t uid = i_uid_read(inode);
2274 - gid_t gid = i_gid_read(inode);
2275 + uid_t uid = from_kuid(&init_user_ns,
2276 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2277 + gid_t gid = from_kgid(&init_user_ns,
2278 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2279 struct buffer_head * bh;
2280 struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2282 @@ -1474,6 +1504,9 @@ static int __ext2_write_inode(struct ino
2283 raw_inode->i_uid_high = 0;
2284 raw_inode->i_gid_high = 0;
2286 +#ifdef CONFIG_TAGGING_INTERN
2287 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2289 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2290 raw_inode->i_size = cpu_to_le32(inode->i_size);
2291 raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2292 @@ -1554,7 +1587,8 @@ int ext2_setattr(struct dentry *dentry,
2293 if (is_quota_modification(inode, iattr))
2294 dquot_initialize(inode);
2295 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2296 - (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2297 + (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2298 + (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2299 error = dquot_transfer(inode, iattr);
2302 diff -NurpP --minimal linux-3.13.10/fs/ext2/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext2/ioctl.c
2303 --- linux-3.13.10/fs/ext2/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2304 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ioctl.c 2014-01-31 20:38:03.000000000 +0000
2306 #include <asm/uaccess.h>
2309 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2311 + inode->i_flags = flags;
2312 + inode->i_vflags = vflags;
2313 + ext2_get_inode_flags(EXT2_I(inode));
2314 + inode->i_ctime = CURRENT_TIME_SEC;
2315 + mark_inode_dirty(inode);
2319 long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2321 struct inode *inode = file_inode(filp);
2322 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2324 flags = ext2_mask_flags(inode->i_mode, flags);
2326 + if (IS_BARRIER(inode)) {
2327 + vxwprintk_task(1, "messing with the barrier.");
2331 mutex_lock(&inode->i_mutex);
2332 /* Is it quota file? Do not allow user to mess with it */
2333 if (IS_NOQUOTA(inode)) {
2334 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2336 * This test looks nicer. Thanks to Pauline Middelink
2338 - if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2339 + if ((oldflags & EXT2_IMMUTABLE_FL) ||
2340 + ((flags ^ oldflags) & (EXT2_APPEND_FL |
2341 + EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2342 if (!capable(CAP_LINUX_IMMUTABLE)) {
2343 mutex_unlock(&inode->i_mutex);
2345 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2349 - flags = flags & EXT2_FL_USER_MODIFIABLE;
2350 + flags &= EXT2_FL_USER_MODIFIABLE;
2351 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2352 ei->i_flags = flags;
2354 diff -NurpP --minimal linux-3.13.10/fs/ext2/namei.c linux-3.13.10-vs2.3.6.11/fs/ext2/namei.c
2355 --- linux-3.13.10/fs/ext2/namei.c 2013-11-25 15:45:01.000000000 +0000
2356 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/namei.c 2014-01-31 20:38:03.000000000 +0000
2359 #include <linux/pagemap.h>
2360 #include <linux/quotaops.h>
2361 +#include <linux/vs_tag.h>
2365 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2366 (unsigned long) ino);
2367 return ERR_PTR(-EIO);
2369 + dx_propagate_tag(nd, inode);
2371 return d_splice_alias(inode, dentry);
2373 @@ -432,5 +434,6 @@ const struct inode_operations ext2_speci
2374 .removexattr = generic_removexattr,
2376 .setattr = ext2_setattr,
2377 + .sync_flags = ext2_sync_flags,
2378 .get_acl = ext2_get_acl,
2380 diff -NurpP --minimal linux-3.13.10/fs/ext2/super.c linux-3.13.10-vs2.3.6.11/fs/ext2/super.c
2381 --- linux-3.13.10/fs/ext2/super.c 2014-01-22 20:39:06.000000000 +0000
2382 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/super.c 2014-01-31 20:38:03.000000000 +0000
2383 @@ -395,7 +395,8 @@ enum {
2384 Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2385 Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2386 Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2387 - Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2388 + Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2389 + Opt_tag, Opt_notag, Opt_tagid
2392 static const match_table_t tokens = {
2393 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2395 {Opt_noacl, "noacl"},
2398 + {Opt_notag, "notag"},
2399 + {Opt_tagid, "tagid=%u"},
2400 {Opt_grpquota, "grpquota"},
2401 {Opt_ignore, "noquota"},
2402 {Opt_quota, "quota"},
2403 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2405 set_opt (sbi->s_mount_opt, NO_UID32);
2407 +#ifndef CONFIG_TAGGING_NONE
2409 + set_opt (sbi->s_mount_opt, TAGGED);
2412 + clear_opt (sbi->s_mount_opt, TAGGED);
2415 +#ifdef CONFIG_PROPAGATE
2418 + set_opt (sbi->s_mount_opt, TAGGED);
2422 clear_opt (sbi->s_mount_opt, CHECK);
2424 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2425 if (!parse_options((char *) data, sb))
2428 + if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2429 + sb->s_flags |= MS_TAGGED;
2430 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2431 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2433 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2438 + if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2439 + !(sb->s_flags & MS_TAGGED)) {
2440 + printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2443 + goto restore_opts;
2446 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2447 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2448 diff -NurpP --minimal linux-3.13.10/fs/ext3/ext3.h linux-3.13.10-vs2.3.6.11/fs/ext3/ext3.h
2449 --- linux-3.13.10/fs/ext3/ext3.h 2012-12-11 03:30:57.000000000 +0000
2450 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ext3.h 2014-01-31 20:38:03.000000000 +0000
2451 @@ -151,10 +151,14 @@ struct ext3_group_desc
2452 #define EXT3_NOTAIL_FL 0x00008000 /* file tail should not be merged */
2453 #define EXT3_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
2454 #define EXT3_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
2455 +#define EXT3_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
2456 #define EXT3_RESERVED_FL 0x80000000 /* reserved for ext3 lib */
2458 -#define EXT3_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
2459 -#define EXT3_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
2460 +#define EXT3_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2461 +#define EXT3_COW_FL 0x20000000 /* Copy on Write marker */
2463 +#define EXT3_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
2464 +#define EXT3_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
2466 /* Flags that should be inherited by new inodes from their parent. */
2467 #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2468 @@ -290,7 +294,8 @@ struct ext3_inode {
2470 __le16 l_i_uid_high; /* these 2 fields */
2471 __le16 l_i_gid_high; /* were reserved2[0] */
2472 - __u32 l_i_reserved2;
2473 + __le16 l_i_tag; /* Context Tag */
2474 + __u16 l_i_reserved2;
2477 __u8 h_i_frag; /* Fragment number */
2478 @@ -320,6 +325,7 @@ struct ext3_inode {
2479 #define i_gid_low i_gid
2480 #define i_uid_high osd2.linux2.l_i_uid_high
2481 #define i_gid_high osd2.linux2.l_i_gid_high
2482 +#define i_raw_tag osd2.linux2.l_i_tag
2483 #define i_reserved2 osd2.linux2.l_i_reserved2
2486 @@ -364,6 +370,7 @@ struct ext3_inode {
2487 #define EXT3_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
2488 #define EXT3_MOUNT_DATA_ERR_ABORT 0x400000 /* Abort on file data write
2489 * error in ordered mode */
2490 +#define EXT3_MOUNT_TAGGED (1<<24) /* Enable Context Tags */
2492 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2493 #ifndef _LINUX_EXT2_FS_H
2494 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2495 extern void ext3_set_aops(struct inode *inode);
2496 extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2497 u64 start, u64 len);
2498 +extern int ext3_sync_flags(struct inode *, int, int);
2501 extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2502 diff -NurpP --minimal linux-3.13.10/fs/ext3/file.c linux-3.13.10-vs2.3.6.11/fs/ext3/file.c
2503 --- linux-3.13.10/fs/ext3/file.c 2012-12-11 03:30:57.000000000 +0000
2504 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/file.c 2014-01-31 20:38:03.000000000 +0000
2505 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2507 .get_acl = ext3_get_acl,
2508 .fiemap = ext3_fiemap,
2509 + .sync_flags = ext3_sync_flags,
2512 diff -NurpP --minimal linux-3.13.10/fs/ext3/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext3/ialloc.c
2513 --- linux-3.13.10/fs/ext3/ialloc.c 2012-12-11 03:30:57.000000000 +0000
2514 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ialloc.c 2014-01-31 20:38:03.000000000 +0000
2517 #include <linux/quotaops.h>
2518 #include <linux/random.h>
2519 +#include <linux/vs_tag.h>
2523 @@ -469,6 +470,7 @@ got:
2524 inode->i_mode = mode;
2525 inode->i_uid = current_fsuid();
2526 inode->i_gid = dir->i_gid;
2527 + i_tag_write(inode, dx_current_fstag(sb));
2529 inode_init_owner(inode, dir, mode);
2531 diff -NurpP --minimal linux-3.13.10/fs/ext3/inode.c linux-3.13.10-vs2.3.6.11/fs/ext3/inode.c
2532 --- linux-3.13.10/fs/ext3/inode.c 2013-11-25 15:45:01.000000000 +0000
2533 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/inode.c 2014-01-31 20:38:03.000000000 +0000
2535 #include <linux/mpage.h>
2536 #include <linux/namei.h>
2537 #include <linux/aio.h>
2538 +#include <linux/vs_tag.h>
2543 @@ -2855,36 +2857,60 @@ void ext3_set_inode_flags(struct inode *
2545 unsigned int flags = EXT3_I(inode)->i_flags;
2547 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2548 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2549 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2551 + if (flags & EXT3_IMMUTABLE_FL)
2552 + inode->i_flags |= S_IMMUTABLE;
2553 + if (flags & EXT3_IXUNLINK_FL)
2554 + inode->i_flags |= S_IXUNLINK;
2556 if (flags & EXT3_SYNC_FL)
2557 inode->i_flags |= S_SYNC;
2558 if (flags & EXT3_APPEND_FL)
2559 inode->i_flags |= S_APPEND;
2560 - if (flags & EXT3_IMMUTABLE_FL)
2561 - inode->i_flags |= S_IMMUTABLE;
2562 if (flags & EXT3_NOATIME_FL)
2563 inode->i_flags |= S_NOATIME;
2564 if (flags & EXT3_DIRSYNC_FL)
2565 inode->i_flags |= S_DIRSYNC;
2567 + inode->i_vflags &= ~(V_BARRIER | V_COW);
2569 + if (flags & EXT3_BARRIER_FL)
2570 + inode->i_vflags |= V_BARRIER;
2571 + if (flags & EXT3_COW_FL)
2572 + inode->i_vflags |= V_COW;
2575 /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2576 void ext3_get_inode_flags(struct ext3_inode_info *ei)
2578 unsigned int flags = ei->vfs_inode.i_flags;
2579 + unsigned int vflags = ei->vfs_inode.i_vflags;
2581 + ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2582 + EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2583 + EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2584 + EXT3_BARRIER_FL | EXT3_COW_FL);
2586 + if (flags & S_IMMUTABLE)
2587 + ei->i_flags |= EXT3_IMMUTABLE_FL;
2588 + if (flags & S_IXUNLINK)
2589 + ei->i_flags |= EXT3_IXUNLINK_FL;
2591 - ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2592 - EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2594 ei->i_flags |= EXT3_SYNC_FL;
2595 if (flags & S_APPEND)
2596 ei->i_flags |= EXT3_APPEND_FL;
2597 - if (flags & S_IMMUTABLE)
2598 - ei->i_flags |= EXT3_IMMUTABLE_FL;
2599 if (flags & S_NOATIME)
2600 ei->i_flags |= EXT3_NOATIME_FL;
2601 if (flags & S_DIRSYNC)
2602 ei->i_flags |= EXT3_DIRSYNC_FL;
2604 + if (vflags & V_BARRIER)
2605 + ei->i_flags |= EXT3_BARRIER_FL;
2606 + if (vflags & V_COW)
2607 + ei->i_flags |= EXT3_COW_FL;
2610 struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2611 @@ -2922,8 +2948,10 @@ struct inode *ext3_iget(struct super_blo
2612 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2613 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2615 - i_uid_write(inode, i_uid);
2616 - i_gid_write(inode, i_gid);
2617 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2618 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2619 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2620 + le16_to_cpu(raw_inode->i_raw_tag)));
2621 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2622 inode->i_size = le32_to_cpu(raw_inode->i_size);
2623 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2624 @@ -3095,8 +3123,10 @@ again:
2626 ext3_get_inode_flags(ei);
2627 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2628 - i_uid = i_uid_read(inode);
2629 - i_gid = i_gid_read(inode);
2630 + i_uid = from_kuid(&init_user_ns,
2631 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2632 + i_gid = from_kgid(&init_user_ns,
2633 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2634 if(!(test_opt(inode->i_sb, NO_UID32))) {
2635 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2636 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2637 @@ -3121,6 +3151,9 @@ again:
2638 raw_inode->i_uid_high = 0;
2639 raw_inode->i_gid_high = 0;
2641 +#ifdef CONFIG_TAGGING_INTERN
2642 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2644 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2645 disksize = cpu_to_le32(ei->i_disksize);
2646 if (disksize != raw_inode->i_size) {
2647 @@ -3289,7 +3322,8 @@ int ext3_setattr(struct dentry *dentry,
2648 if (is_quota_modification(inode, attr))
2649 dquot_initialize(inode);
2650 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2651 - (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2652 + (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2653 + (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2656 /* (user+group)*(old+new) structure, inode write (sb,
2657 @@ -3311,6 +3345,8 @@ int ext3_setattr(struct dentry *dentry,
2658 inode->i_uid = attr->ia_uid;
2659 if (attr->ia_valid & ATTR_GID)
2660 inode->i_gid = attr->ia_gid;
2661 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2662 + inode->i_tag = attr->ia_tag;
2663 error = ext3_mark_inode_dirty(handle, inode);
2664 ext3_journal_stop(handle);
2666 diff -NurpP --minimal linux-3.13.10/fs/ext3/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext3/ioctl.c
2667 --- linux-3.13.10/fs/ext3/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2668 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ioctl.c 2014-01-31 20:38:03.000000000 +0000
2670 #include <asm/uaccess.h>
2674 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2676 + handle_t *handle = NULL;
2677 + struct ext3_iloc iloc;
2680 + handle = ext3_journal_start(inode, 1);
2681 + if (IS_ERR(handle))
2682 + return PTR_ERR(handle);
2684 + if (IS_SYNC(inode))
2685 + handle->h_sync = 1;
2686 + err = ext3_reserve_inode_write(handle, inode, &iloc);
2690 + inode->i_flags = flags;
2691 + inode->i_vflags = vflags;
2692 + ext3_get_inode_flags(EXT3_I(inode));
2693 + inode->i_ctime = CURRENT_TIME_SEC;
2695 + err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2697 + ext3_journal_stop(handle);
2701 long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2703 struct inode *inode = file_inode(filp);
2704 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2706 flags = ext3_mask_flags(inode->i_mode, flags);
2708 + if (IS_BARRIER(inode)) {
2709 + vxwprintk_task(1, "messing with the barrier.");
2713 mutex_lock(&inode->i_mutex);
2715 /* Is it quota file? Do not allow user to mess with it */
2716 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2718 * This test looks nicer. Thanks to Pauline Middelink
2720 - if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2721 + if ((oldflags & EXT3_IMMUTABLE_FL) ||
2722 + ((flags ^ oldflags) & (EXT3_APPEND_FL |
2723 + EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2724 if (!capable(CAP_LINUX_IMMUTABLE))
2727 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2731 - flags = flags & EXT3_FL_USER_MODIFIABLE;
2732 + flags &= EXT3_FL_USER_MODIFIABLE;
2733 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2734 ei->i_flags = flags;
2736 diff -NurpP --minimal linux-3.13.10/fs/ext3/namei.c linux-3.13.10-vs2.3.6.11/fs/ext3/namei.c
2737 --- linux-3.13.10/fs/ext3/namei.c 2013-11-25 15:46:59.000000000 +0000
2738 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/namei.c 2014-01-31 20:38:03.000000000 +0000
2742 #include <linux/quotaops.h>
2743 +#include <linux/vs_tag.h>
2748 @@ -915,6 +917,7 @@ restart:
2749 submit_bh(READ | REQ_META | REQ_PRIO,
2752 + dx_propagate_tag(nd, inode);
2755 if ((bh = bh_use[ra_ptr++]) == NULL)
2756 @@ -2568,6 +2571,7 @@ const struct inode_operations ext3_dir_i
2757 .listxattr = ext3_listxattr,
2758 .removexattr = generic_removexattr,
2760 + .sync_flags = ext3_sync_flags,
2761 .get_acl = ext3_get_acl,
2764 diff -NurpP --minimal linux-3.13.10/fs/ext3/super.c linux-3.13.10-vs2.3.6.11/fs/ext3/super.c
2765 --- linux-3.13.10/fs/ext3/super.c 2014-01-22 20:39:06.000000000 +0000
2766 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/super.c 2014-01-31 20:38:03.000000000 +0000
2767 @@ -826,7 +826,8 @@ enum {
2768 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2769 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2770 Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2771 - Opt_resize, Opt_usrquota, Opt_grpquota
2772 + Opt_resize, Opt_usrquota, Opt_grpquota,
2773 + Opt_tag, Opt_notag, Opt_tagid
2776 static const match_table_t tokens = {
2777 @@ -884,6 +885,9 @@ static const match_table_t tokens = {
2778 {Opt_barrier, "barrier"},
2779 {Opt_nobarrier, "nobarrier"},
2780 {Opt_resize, "resize"},
2782 + {Opt_notag, "notag"},
2783 + {Opt_tagid, "tagid=%u"},
2787 @@ -1056,6 +1060,20 @@ static int parse_options (char *options,
2789 set_opt (sbi->s_mount_opt, NO_UID32);
2791 +#ifndef CONFIG_TAGGING_NONE
2793 + set_opt (sbi->s_mount_opt, TAGGED);
2796 + clear_opt (sbi->s_mount_opt, TAGGED);
2799 +#ifdef CONFIG_PROPAGATE
2802 + set_opt (sbi->s_mount_opt, TAGGED);
2806 clear_opt (sbi->s_mount_opt, CHECK);
2808 @@ -1788,6 +1806,9 @@ static int ext3_fill_super (struct super
2812 + if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2813 + sb->s_flags |= MS_TAGGED;
2815 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2816 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2818 @@ -2683,6 +2704,14 @@ static int ext3_remount (struct super_bl
2819 if (test_opt(sb, ABORT))
2820 ext3_abort(sb, __func__, "Abort forced by user");
2822 + if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2823 + !(sb->s_flags & MS_TAGGED)) {
2824 + printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2827 + goto restore_opts;
2830 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2831 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2833 diff -NurpP --minimal linux-3.13.10/fs/ext4/ext4.h linux-3.13.10-vs2.3.6.11/fs/ext4/ext4.h
2834 --- linux-3.13.10/fs/ext4/ext4.h 2014-04-17 01:12:32.000000000 +0000
2835 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ext4.h 2014-03-12 15:51:07.000000000 +0000
2836 @@ -385,7 +385,10 @@ struct flex_groups {
2837 #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
2838 #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
2839 #define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
2840 +#define EXT4_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2841 +#define EXT4_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
2842 #define EXT4_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */
2843 +#define EXT4_COW_FL 0x20000000 /* Copy on Write marker */
2844 #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
2846 #define EXT4_FL_USER_VISIBLE 0x004BDFFF /* User visible flags */
2847 @@ -670,7 +673,7 @@ struct ext4_inode {
2848 __le16 l_i_uid_high; /* these 2 fields */
2849 __le16 l_i_gid_high; /* were reserved2[0] */
2850 __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2851 - __le16 l_i_reserved;
2852 + __le16 l_i_tag; /* Context Tag */
2855 __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
2856 @@ -790,6 +793,7 @@ do { \
2857 #define i_gid_low i_gid
2858 #define i_uid_high osd2.linux2.l_i_uid_high
2859 #define i_gid_high osd2.linux2.l_i_gid_high
2860 +#define i_raw_tag osd2.linux2.l_i_tag
2861 #define i_checksum_lo osd2.linux2.l_i_checksum_lo
2863 #elif defined(__GNU__)
2864 @@ -976,6 +980,7 @@ struct ext4_inode_info {
2865 #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
2866 #define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */
2867 #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */
2868 +#define EXT4_MOUNT_TAGGED 0x40000 /* Enable Context Tags */
2869 #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */
2870 #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
2871 #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
2872 @@ -2653,6 +2658,7 @@ extern struct buffer_head *ext4_get_firs
2873 extern int ext4_inline_data_fiemap(struct inode *inode,
2874 struct fiemap_extent_info *fieinfo,
2876 +extern int ext4_sync_flags(struct inode *, int, int);
2877 extern int ext4_try_to_evict_inline_data(handle_t *handle,
2878 struct inode *inode,
2880 diff -NurpP --minimal linux-3.13.10/fs/ext4/file.c linux-3.13.10-vs2.3.6.11/fs/ext4/file.c
2881 --- linux-3.13.10/fs/ext4/file.c 2013-11-25 15:46:59.000000000 +0000
2882 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/file.c 2014-01-31 20:38:03.000000000 +0000
2883 @@ -618,5 +618,6 @@ const struct inode_operations ext4_file_
2884 .removexattr = generic_removexattr,
2885 .get_acl = ext4_get_acl,
2886 .fiemap = ext4_fiemap,
2887 + .sync_flags = ext4_sync_flags,
2890 diff -NurpP --minimal linux-3.13.10/fs/ext4/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext4/ialloc.c
2891 --- linux-3.13.10/fs/ext4/ialloc.c 2014-01-22 20:39:06.000000000 +0000
2892 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ialloc.c 2014-01-31 20:38:03.000000000 +0000
2894 #include <linux/random.h>
2895 #include <linux/bitops.h>
2896 #include <linux/blkdev.h>
2897 +#include <linux/vs_tag.h>
2898 #include <asm/byteorder.h>
2901 @@ -731,6 +732,7 @@ struct inode *__ext4_new_inode(handle_t
2902 inode->i_mode = mode;
2903 inode->i_uid = current_fsuid();
2904 inode->i_gid = dir->i_gid;
2905 + i_tag_write(inode, dx_current_fstag(sb));
2907 inode_init_owner(inode, dir, mode);
2908 dquot_initialize(inode);
2909 diff -NurpP --minimal linux-3.13.10/fs/ext4/inode.c linux-3.13.10-vs2.3.6.11/fs/ext4/inode.c
2910 --- linux-3.13.10/fs/ext4/inode.c 2014-04-17 01:12:32.000000000 +0000
2911 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/inode.c 2014-04-17 01:28:13.000000000 +0000
2913 #include <linux/ratelimit.h>
2914 #include <linux/aio.h>
2915 #include <linux/bitops.h>
2916 +#include <linux/vs_tag.h>
2918 #include "ext4_jbd2.h"
2920 @@ -3929,42 +3930,67 @@ void ext4_set_inode_flags(struct inode *
2921 unsigned int flags = EXT4_I(inode)->i_flags;
2922 unsigned int new_fl = 0;
2924 + if (flags & EXT4_IMMUTABLE_FL)
2925 + new_fl |= S_IMMUTABLE;
2926 + if (flags & EXT4_IXUNLINK_FL)
2927 + new_fl |= S_IXUNLINK;
2929 if (flags & EXT4_SYNC_FL)
2931 if (flags & EXT4_APPEND_FL)
2933 - if (flags & EXT4_IMMUTABLE_FL)
2934 - new_fl |= S_IMMUTABLE;
2935 if (flags & EXT4_NOATIME_FL)
2936 new_fl |= S_NOATIME;
2937 if (flags & EXT4_DIRSYNC_FL)
2938 new_fl |= S_DIRSYNC;
2940 set_mask_bits(&inode->i_flags,
2941 - S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC, new_fl);
2942 + S_IXUNLINK | S_IMMUTABLE |
2943 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC, new_fl);
2946 + if (flags & EXT4_BARRIER_FL)
2947 + new_fl |= V_BARRIER;
2948 + if (flags & EXT4_COW_FL)
2951 + set_mask_bits(&inode->i_vflags,
2952 + V_BARRIER | V_COW, new_fl);
2955 /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2956 void ext4_get_inode_flags(struct ext4_inode_info *ei)
2958 - unsigned int vfs_fl;
2959 + unsigned int vfs_fl, vfs_vf;
2960 unsigned long old_fl, new_fl;
2963 vfs_fl = ei->vfs_inode.i_flags;
2964 + vfs_vf = ei->vfs_inode.i_vflags;
2965 old_fl = ei->i_flags;
2966 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2967 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
2969 + EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
2972 + if (vfs_fl & S_IMMUTABLE)
2973 + new_fl |= EXT4_IMMUTABLE_FL;
2974 + if (vfs_fl & S_IXUNLINK)
2975 + new_fl |= EXT4_IXUNLINK_FL;
2977 if (vfs_fl & S_SYNC)
2978 new_fl |= EXT4_SYNC_FL;
2979 if (vfs_fl & S_APPEND)
2980 new_fl |= EXT4_APPEND_FL;
2981 - if (vfs_fl & S_IMMUTABLE)
2982 - new_fl |= EXT4_IMMUTABLE_FL;
2983 if (vfs_fl & S_NOATIME)
2984 new_fl |= EXT4_NOATIME_FL;
2985 if (vfs_fl & S_DIRSYNC)
2986 new_fl |= EXT4_DIRSYNC_FL;
2988 + if (vfs_vf & V_BARRIER)
2989 + new_fl |= EXT4_BARRIER_FL;
2990 + if (vfs_vf & V_COW)
2991 + new_fl |= EXT4_COW_FL;
2992 } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
2995 @@ -4069,8 +4095,10 @@ struct inode *ext4_iget(struct super_blo
2996 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2997 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2999 - i_uid_write(inode, i_uid);
3000 - i_gid_write(inode, i_gid);
3001 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3002 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3003 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3004 + le16_to_cpu(raw_inode->i_raw_tag)));
3005 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3007 ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */
3008 @@ -4298,8 +4326,10 @@ static int ext4_do_update_inode(handle_t
3010 ext4_get_inode_flags(ei);
3011 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3012 - i_uid = i_uid_read(inode);
3013 - i_gid = i_gid_read(inode);
3014 + i_uid = from_kuid(&init_user_ns,
3015 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
3016 + i_gid = from_kgid(&init_user_ns,
3017 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
3018 if (!(test_opt(inode->i_sb, NO_UID32))) {
3019 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3020 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3021 @@ -4322,6 +4352,9 @@ static int ext4_do_update_inode(handle_t
3022 raw_inode->i_uid_high = 0;
3023 raw_inode->i_gid_high = 0;
3025 +#ifdef CONFIG_TAGGING_INTERN
3026 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3028 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3030 EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3031 @@ -4553,7 +4586,8 @@ int ext4_setattr(struct dentry *dentry,
3032 if (is_quota_modification(inode, attr))
3033 dquot_initialize(inode);
3034 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3035 - (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3036 + (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3037 + (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3040 /* (user+group)*(old+new) structure, inode write (sb,
3041 @@ -4576,6 +4610,8 @@ int ext4_setattr(struct dentry *dentry,
3042 inode->i_uid = attr->ia_uid;
3043 if (attr->ia_valid & ATTR_GID)
3044 inode->i_gid = attr->ia_gid;
3045 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3046 + inode->i_tag = attr->ia_tag;
3047 error = ext4_mark_inode_dirty(handle, inode);
3048 ext4_journal_stop(handle);
3050 diff -NurpP --minimal linux-3.13.10/fs/ext4/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext4/ioctl.c
3051 --- linux-3.13.10/fs/ext4/ioctl.c 2014-04-17 01:12:32.000000000 +0000
3052 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ioctl.c 2014-03-12 15:51:07.000000000 +0000
3054 #include <linux/compat.h>
3055 #include <linux/mount.h>
3056 #include <linux/file.h>
3057 +#include <linux/vs_tag.h>
3058 #include <asm/uaccess.h>
3059 #include "ext4_jbd2.h"
3061 @@ -214,6 +215,33 @@ swap_boot_out:
3065 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3067 + handle_t *handle = NULL;
3068 + struct ext4_iloc iloc;
3071 + handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3072 + if (IS_ERR(handle))
3073 + return PTR_ERR(handle);
3075 + if (IS_SYNC(inode))
3076 + ext4_handle_sync(handle);
3077 + err = ext4_reserve_inode_write(handle, inode, &iloc);
3081 + inode->i_flags = flags;
3082 + inode->i_vflags = vflags;
3083 + ext4_get_inode_flags(EXT4_I(inode));
3084 + inode->i_ctime = ext4_current_time(inode);
3086 + err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3088 + ext4_journal_stop(handle);
3092 long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3094 struct inode *inode = file_inode(filp);
3095 @@ -247,6 +275,11 @@ long ext4_ioctl(struct file *filp, unsig
3097 flags = ext4_mask_flags(inode->i_mode, flags);
3099 + if (IS_BARRIER(inode)) {
3100 + vxwprintk_task(1, "messing with the barrier.");
3105 mutex_lock(&inode->i_mutex);
3106 /* Is it quota file? Do not allow user to mess with it */
3107 @@ -264,7 +297,9 @@ long ext4_ioctl(struct file *filp, unsig
3109 * This test looks nicer. Thanks to Pauline Middelink
3111 - if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3112 + if ((oldflags & EXT4_IMMUTABLE_FL) ||
3113 + ((flags ^ oldflags) & (EXT4_APPEND_FL |
3114 + EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3115 if (!capable(CAP_LINUX_IMMUTABLE))
3118 diff -NurpP --minimal linux-3.13.10/fs/ext4/namei.c linux-3.13.10-vs2.3.6.11/fs/ext4/namei.c
3119 --- linux-3.13.10/fs/ext4/namei.c 2013-11-25 15:46:59.000000000 +0000
3120 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/namei.c 2014-01-31 20:38:03.000000000 +0000
3122 #include <linux/quotaops.h>
3123 #include <linux/buffer_head.h>
3124 #include <linux/bio.h>
3125 +#include <linux/vs_tag.h>
3127 #include "ext4_jbd2.h"
3129 @@ -1299,6 +1300,7 @@ restart:
3130 ll_rw_block(READ | REQ_META | REQ_PRIO,
3133 + dx_propagate_tag(nd, inode);
3135 if ((bh = bh_use[ra_ptr++]) == NULL)
3137 @@ -3226,6 +3228,7 @@ const struct inode_operations ext4_dir_i
3138 .removexattr = generic_removexattr,
3139 .get_acl = ext4_get_acl,
3140 .fiemap = ext4_fiemap,
3141 + .sync_flags = ext4_sync_flags,
3144 const struct inode_operations ext4_special_inode_operations = {
3145 diff -NurpP --minimal linux-3.13.10/fs/ext4/super.c linux-3.13.10-vs2.3.6.11/fs/ext4/super.c
3146 --- linux-3.13.10/fs/ext4/super.c 2014-04-17 01:12:32.000000000 +0000
3147 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/super.c 2014-03-12 15:51:07.000000000 +0000
3148 @@ -1162,7 +1162,7 @@ enum {
3149 Opt_inode_readahead_blks, Opt_journal_ioprio,
3150 Opt_dioread_nolock, Opt_dioread_lock,
3151 Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3152 - Opt_max_dir_size_kb,
3153 + Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3156 static const match_table_t tokens = {
3157 @@ -1243,6 +1243,9 @@ static const match_table_t tokens = {
3158 {Opt_removed, "reservation"}, /* mount option from ext2/3 */
3159 {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3160 {Opt_removed, "journal=%u"}, /* mount option from ext2/3 */
3162 + {Opt_notag, "notag"},
3163 + {Opt_tagid, "tagid=%u"},
3167 @@ -1475,6 +1478,20 @@ static int handle_mount_opt(struct super
3169 sb->s_flags |= MS_I_VERSION;
3171 +#ifndef CONFIG_TAGGING_NONE
3173 + set_opt(sb, TAGGED);
3176 + clear_opt(sb, TAGGED);
3179 +#ifdef CONFIG_PROPAGATE
3182 + set_opt(sb, TAGGED);
3187 for (m = ext4_mount_opts; m->token != Opt_err; m++)
3188 @@ -3564,6 +3581,9 @@ static int ext4_fill_super(struct super_
3189 clear_opt(sb, DELALLOC);
3192 + if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3193 + sb->s_flags |= MS_TAGGED;
3195 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3196 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3198 @@ -4818,6 +4838,14 @@ static int ext4_remount(struct super_blo
3199 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3200 ext4_abort(sb, "Abort forced by user");
3202 + if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3203 + !(sb->s_flags & MS_TAGGED)) {
3204 + printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3207 + goto restore_opts;
3210 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3211 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3213 diff -NurpP --minimal linux-3.13.10/fs/fcntl.c linux-3.13.10-vs2.3.6.11/fs/fcntl.c
3214 --- linux-3.13.10/fs/fcntl.c 2014-01-22 20:39:06.000000000 +0000
3215 +++ linux-3.13.10-vs2.3.6.11/fs/fcntl.c 2014-01-31 20:38:03.000000000 +0000
3217 #include <linux/rcupdate.h>
3218 #include <linux/pid_namespace.h>
3219 #include <linux/user_namespace.h>
3220 +#include <linux/vs_limit.h>
3222 #include <asm/poll.h>
3223 #include <asm/siginfo.h>
3224 @@ -377,6 +378,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3228 + if (!vx_files_avail(1))
3231 if (unlikely(f.file->f_mode & FMODE_PATH)) {
3232 if (!check_fcntl_cmd(cmd))
3233 diff -NurpP --minimal linux-3.13.10/fs/file.c linux-3.13.10-vs2.3.6.11/fs/file.c
3234 --- linux-3.13.10/fs/file.c 2014-04-17 01:12:32.000000000 +0000
3235 +++ linux-3.13.10-vs2.3.6.11/fs/file.c 2014-02-25 11:26:09.000000000 +0000
3237 #include <linux/spinlock.h>
3238 #include <linux/rcupdate.h>
3239 #include <linux/workqueue.h>
3240 +#include <linux/vs_limit.h>
3242 int sysctl_nr_open __read_mostly = 1024*1024;
3243 int sysctl_nr_open_min = BITS_PER_LONG;
3244 @@ -311,6 +312,8 @@ struct files_struct *dup_fd(struct files
3245 struct file *f = *old_fds++;
3248 + /* TODO: sum it first for check and performance */
3249 + vx_openfd_inc(open_files - i);
3252 * The fd may be claimed in the fd bitmap but not yet
3253 @@ -376,9 +379,11 @@ static void close_files(struct files_str
3254 filp_close(file, files);
3265 @@ -503,6 +508,7 @@ repeat:
3267 __clear_close_on_exec(fd, fdt);
3269 + vx_openfd_inc(fd);
3272 if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3273 @@ -533,6 +539,7 @@ static void __put_unused_fd(struct files
3274 __clear_open_fd(fd, fdt);
3275 if (fd < files->next_fd)
3276 files->next_fd = fd;
3277 + vx_openfd_dec(fd);
3280 void put_unused_fd(unsigned int fd)
3281 @@ -812,6 +819,8 @@ static int do_dup2(struct files_struct *
3284 filp_close(tofree, files);
3286 + vx_openfd_inc(fd); /* fd was unused */
3290 diff -NurpP --minimal linux-3.13.10/fs/file_table.c linux-3.13.10-vs2.3.6.11/fs/file_table.c
3291 --- linux-3.13.10/fs/file_table.c 2014-01-22 20:39:06.000000000 +0000
3292 +++ linux-3.13.10-vs2.3.6.11/fs/file_table.c 2014-02-01 00:00:01.000000000 +0000
3294 #include <linux/hardirq.h>
3295 #include <linux/task_work.h>
3296 #include <linux/ima.h>
3297 +#include <linux/vs_limit.h>
3298 +#include <linux/vs_context.h>
3300 #include <linux/atomic.h>
3302 @@ -137,6 +139,8 @@ struct file *get_empty_filp(void)
3303 spin_lock_init(&f->f_lock);
3304 eventpoll_init_file(f);
3305 /* f->f_version: 0 */
3306 + f->f_xid = vx_current_xid();
3311 @@ -254,6 +258,8 @@ static void __fput(struct file *file)
3312 i_readcount_dec(inode);
3313 if (file->f_mode & FMODE_WRITE)
3314 drop_file_write_access(file);
3315 + vx_files_dec(file);
3317 file->f_path.dentry = NULL;
3318 file->f_path.mnt = NULL;
3319 file->f_inode = NULL;
3320 @@ -340,6 +346,8 @@ void put_filp(struct file *file)
3322 if (atomic_long_dec_and_test(&file->f_count)) {
3323 security_file_free(file);
3324 + vx_files_dec(file);
3329 diff -NurpP --minimal linux-3.13.10/fs/fs_struct.c linux-3.13.10-vs2.3.6.11/fs/fs_struct.c
3330 --- linux-3.13.10/fs/fs_struct.c 2014-01-22 20:39:06.000000000 +0000
3331 +++ linux-3.13.10-vs2.3.6.11/fs/fs_struct.c 2014-01-31 20:38:03.000000000 +0000
3333 #include <linux/path.h>
3334 #include <linux/slab.h>
3335 #include <linux/fs_struct.h>
3336 +#include <linux/vserver/global.h>
3337 #include "internal.h"
3340 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3342 path_put(&fs->root);
3344 + atomic_dec(&vs_global_fs);
3345 kmem_cache_free(fs_cachep, fs);
3348 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3351 spin_unlock(&old->lock);
3352 + atomic_inc(&vs_global_fs);
3356 diff -NurpP --minimal linux-3.13.10/fs/gfs2/file.c linux-3.13.10-vs2.3.6.11/fs/gfs2/file.c
3357 --- linux-3.13.10/fs/gfs2/file.c 2014-01-22 20:39:06.000000000 +0000
3358 +++ linux-3.13.10-vs2.3.6.11/fs/gfs2/file.c 2014-01-31 20:38:03.000000000 +0000
3359 @@ -137,6 +137,9 @@ static const u32 fsflags_to_gfs2[32] = {
3360 [12] = GFS2_DIF_EXHASH,
3361 [14] = GFS2_DIF_INHERIT_JDATA,
3362 [17] = GFS2_DIF_TOPDIR,
3363 + [27] = GFS2_DIF_IXUNLINK,
3364 + [26] = GFS2_DIF_BARRIER,
3365 + [29] = GFS2_DIF_COW,
3368 static const u32 gfs2_to_fsflags[32] = {
3369 @@ -147,6 +150,9 @@ static const u32 gfs2_to_fsflags[32] = {
3370 [gfs2fl_ExHash] = FS_INDEX_FL,
3371 [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3372 [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3373 + [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3374 + [gfs2fl_Barrier] = FS_BARRIER_FL,
3375 + [gfs2fl_Cow] = FS_COW_FL,
3378 static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3379 @@ -177,12 +183,18 @@ void gfs2_set_inode_flags(struct inode *
3381 struct gfs2_inode *ip = GFS2_I(inode);
3382 unsigned int flags = inode->i_flags;
3383 + unsigned int vflags = inode->i_vflags;
3385 + flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3386 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3388 - flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3389 if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3390 inode->i_flags |= S_NOSEC;
3391 if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3392 flags |= S_IMMUTABLE;
3393 + if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3394 + flags |= S_IXUNLINK;
3396 if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3398 if (ip->i_diskflags & GFS2_DIF_NOATIME)
3399 @@ -190,6 +202,43 @@ void gfs2_set_inode_flags(struct inode *
3400 if (ip->i_diskflags & GFS2_DIF_SYNC)
3402 inode->i_flags = flags;
3404 + vflags &= ~(V_BARRIER | V_COW);
3406 + if (ip->i_diskflags & GFS2_DIF_BARRIER)
3407 + vflags |= V_BARRIER;
3408 + if (ip->i_diskflags & GFS2_DIF_COW)
3410 + inode->i_vflags = vflags;
3413 +void gfs2_get_inode_flags(struct inode *inode)
3415 + struct gfs2_inode *ip = GFS2_I(inode);
3416 + unsigned int flags = inode->i_flags;
3417 + unsigned int vflags = inode->i_vflags;
3419 + ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3420 + GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3421 + GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3422 + GFS2_DIF_BARRIER | GFS2_DIF_COW);
3424 + if (flags & S_IMMUTABLE)
3425 + ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3426 + if (flags & S_IXUNLINK)
3427 + ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3429 + if (flags & S_APPEND)
3430 + ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3431 + if (flags & S_NOATIME)
3432 + ip->i_diskflags |= GFS2_DIF_NOATIME;
3433 + if (flags & S_SYNC)
3434 + ip->i_diskflags |= GFS2_DIF_SYNC;
3436 + if (vflags & V_BARRIER)
3437 + ip->i_diskflags |= GFS2_DIF_BARRIER;
3438 + if (vflags & V_COW)
3439 + ip->i_diskflags |= GFS2_DIF_COW;
3442 /* Flags that can be set by user space */
3443 @@ -303,6 +352,37 @@ static int gfs2_set_flags(struct file *f
3444 return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3447 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3449 + struct gfs2_inode *ip = GFS2_I(inode);
3450 + struct gfs2_sbd *sdp = GFS2_SB(inode);
3451 + struct buffer_head *bh;
3452 + struct gfs2_holder gh;
3455 + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3458 + error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3461 + error = gfs2_meta_inode_buffer(ip, &bh);
3463 + goto out_trans_end;
3464 + gfs2_trans_add_meta(ip->i_gl, bh);
3465 + inode->i_flags = flags;
3466 + inode->i_vflags = vflags;
3467 + gfs2_get_inode_flags(inode);
3468 + gfs2_dinode_out(ip, bh->b_data);
3470 + gfs2_set_aops(inode);
3472 + gfs2_trans_end(sdp);
3474 + gfs2_glock_dq_uninit(&gh);
3478 static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3481 diff -NurpP --minimal linux-3.13.10/fs/gfs2/inode.h linux-3.13.10-vs2.3.6.11/fs/gfs2/inode.h
3482 --- linux-3.13.10/fs/gfs2/inode.h 2013-11-25 15:45:01.000000000 +0000
3483 +++ linux-3.13.10-vs2.3.6.11/fs/gfs2/inode.h 2014-01-31 20:38:03.000000000 +0000
3484 @@ -118,6 +118,7 @@ extern const struct file_operations gfs2
3485 extern const struct file_operations gfs2_dir_fops_nolock;
3487 extern void gfs2_set_inode_flags(struct inode *inode);
3488 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3490 #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3491 extern const struct file_operations gfs2_file_fops;
3492 diff -NurpP --minimal linux-3.13.10/fs/hostfs/hostfs.h linux-3.13.10-vs2.3.6.11/fs/hostfs/hostfs.h
3493 --- linux-3.13.10/fs/hostfs/hostfs.h 2012-12-11 03:30:57.000000000 +0000
3494 +++ linux-3.13.10-vs2.3.6.11/fs/hostfs/hostfs.h 2014-01-31 20:38:03.000000000 +0000
3495 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3496 unsigned short ia_mode;
3501 struct timespec ia_atime;
3502 struct timespec ia_mtime;
3503 diff -NurpP --minimal linux-3.13.10/fs/inode.c linux-3.13.10-vs2.3.6.11/fs/inode.c
3504 --- linux-3.13.10/fs/inode.c 2014-01-22 20:39:06.000000000 +0000
3505 +++ linux-3.13.10-vs2.3.6.11/fs/inode.c 2014-01-31 23:33:47.000000000 +0000
3507 #include <linux/buffer_head.h> /* for inode_has_buffers */
3508 #include <linux/ratelimit.h>
3509 #include <linux/list_lru.h>
3510 +#include <linux/vs_tag.h>
3511 #include "internal.h"
3514 @@ -129,6 +130,8 @@ int inode_init_always(struct super_block
3515 struct address_space *const mapping = &inode->i_data;
3519 + /* essential because of inode slab reuse */
3520 inode->i_blkbits = sb->s_blocksize_bits;
3522 atomic_set(&inode->i_count, 1);
3523 @@ -138,6 +141,7 @@ int inode_init_always(struct super_block
3524 inode->i_opflags = 0;
3525 i_uid_write(inode, 0);
3526 i_gid_write(inode, 0);
3527 + i_tag_write(inode, 0);
3528 atomic_set(&inode->i_writecount, 0);
3530 inode->i_blocks = 0;
3531 @@ -150,6 +154,7 @@ int inode_init_always(struct super_block
3532 inode->i_bdev = NULL;
3533 inode->i_cdev = NULL;
3535 + inode->i_mdev = 0;
3536 inode->dirtied_when = 0;
3538 if (security_inode_alloc(inode))
3539 @@ -477,6 +482,8 @@ void __insert_inode_hash(struct inode *i
3541 EXPORT_SYMBOL(__insert_inode_hash);
3543 +EXPORT_SYMBOL_GPL(__iget);
3546 * __remove_inode_hash - remove an inode from the hash
3547 * @inode: inode to unhash
3548 @@ -1802,9 +1809,11 @@ void init_special_inode(struct inode *in
3549 if (S_ISCHR(mode)) {
3550 inode->i_fop = &def_chr_fops;
3551 inode->i_rdev = rdev;
3552 + inode->i_mdev = rdev;
3553 } else if (S_ISBLK(mode)) {
3554 inode->i_fop = &def_blk_fops;
3555 inode->i_rdev = rdev;
3556 + inode->i_mdev = rdev;
3557 } else if (S_ISFIFO(mode))
3558 inode->i_fop = &pipefifo_fops;
3559 else if (S_ISSOCK(mode))
3560 @@ -1833,6 +1842,7 @@ void inode_init_owner(struct inode *inod
3562 inode->i_gid = current_fsgid();
3563 inode->i_mode = mode;
3564 + i_tag_write(inode, dx_current_fstag(inode->i_sb));
3566 EXPORT_SYMBOL(inode_init_owner);
3568 diff -NurpP --minimal linux-3.13.10/fs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ioctl.c
3569 --- linux-3.13.10/fs/ioctl.c 2014-01-22 20:39:06.000000000 +0000
3570 +++ linux-3.13.10-vs2.3.6.11/fs/ioctl.c 2014-01-31 20:38:03.000000000 +0000
3572 #include <linux/writeback.h>
3573 #include <linux/buffer_head.h>
3574 #include <linux/falloc.h>
3575 +#include <linux/proc_fs.h>
3576 +#include <linux/vserver/inode.h>
3577 +#include <linux/vs_tag.h>
3579 #include <asm/ioctls.h>
3581 diff -NurpP --minimal linux-3.13.10/fs/ioprio.c linux-3.13.10-vs2.3.6.11/fs/ioprio.c
3582 --- linux-3.13.10/fs/ioprio.c 2012-12-11 03:30:57.000000000 +0000
3583 +++ linux-3.13.10-vs2.3.6.11/fs/ioprio.c 2014-01-31 20:38:03.000000000 +0000
3585 #include <linux/syscalls.h>
3586 #include <linux/security.h>
3587 #include <linux/pid_namespace.h>
3588 +#include <linux/vs_base.h>
3590 int set_task_ioprio(struct task_struct *task, int ioprio)
3592 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3594 pgrp = find_vpid(who);
3595 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3596 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3598 ret = set_task_ioprio(p, ioprio);
3601 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3603 pgrp = find_vpid(who);
3604 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3605 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3607 tmpio = get_task_ioprio(p);
3610 diff -NurpP --minimal linux-3.13.10/fs/jfs/file.c linux-3.13.10-vs2.3.6.11/fs/jfs/file.c
3611 --- linux-3.13.10/fs/jfs/file.c 2013-02-19 13:58:48.000000000 +0000
3612 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/file.c 2014-01-31 20:38:03.000000000 +0000
3613 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3614 if (is_quota_modification(inode, iattr))
3615 dquot_initialize(inode);
3616 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3617 - (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3618 + (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3619 + (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3620 rc = dquot_transfer(inode, iattr);
3623 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3624 #ifdef CONFIG_JFS_POSIX_ACL
3625 .get_acl = jfs_get_acl,
3627 + .sync_flags = jfs_sync_flags,
3630 const struct file_operations jfs_file_operations = {
3631 diff -NurpP --minimal linux-3.13.10/fs/jfs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/jfs/ioctl.c
3632 --- linux-3.13.10/fs/jfs/ioctl.c 2013-05-31 13:45:24.000000000 +0000
3633 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/ioctl.c 2014-01-31 20:38:03.000000000 +0000
3635 #include <linux/time.h>
3636 #include <linux/sched.h>
3637 #include <linux/blkdev.h>
3638 +#include <linux/mount.h>
3639 #include <asm/current.h>
3640 #include <asm/uaccess.h>
3642 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3646 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3648 + inode->i_flags = flags;
3649 + inode->i_vflags = vflags;
3650 + jfs_get_inode_flags(JFS_IP(inode));
3651 + inode->i_ctime = CURRENT_TIME_SEC;
3652 + mark_inode_dirty(inode);
3656 long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3658 struct inode *inode = file_inode(filp);
3659 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3660 if (!S_ISDIR(inode->i_mode))
3661 flags &= ~JFS_DIRSYNC_FL;
3663 + if (IS_BARRIER(inode)) {
3664 + vxwprintk_task(1, "messing with the barrier.");
3668 /* Is it quota file? Do not allow user to mess with it */
3669 if (IS_NOQUOTA(inode)) {
3671 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3672 * the relevant capability.
3674 if ((oldflags & JFS_IMMUTABLE_FL) ||
3675 - ((flags ^ oldflags) &
3676 - (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3677 + ((flags ^ oldflags) & (JFS_APPEND_FL |
3678 + JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3679 if (!capable(CAP_LINUX_IMMUTABLE)) {
3680 mutex_unlock(&inode->i_mutex);
3682 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3686 - flags = flags & JFS_FL_USER_MODIFIABLE;
3687 + flags &= JFS_FL_USER_MODIFIABLE;
3688 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3689 jfs_inode->mode2 = flags;
3691 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_dinode.h linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_dinode.h
3692 --- linux-3.13.10/fs/jfs/jfs_dinode.h 2012-12-11 03:30:57.000000000 +0000
3693 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_dinode.h 2014-01-31 20:38:03.000000000 +0000
3694 @@ -161,9 +161,13 @@ struct dinode {
3696 #define JFS_APPEND_FL 0x01000000 /* writes to file may only append */
3697 #define JFS_IMMUTABLE_FL 0x02000000 /* Immutable file */
3698 +#define JFS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
3700 -#define JFS_FL_USER_VISIBLE 0x03F80000
3701 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3702 +#define JFS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
3703 +#define JFS_COW_FL 0x20000000 /* Copy on Write marker */
3705 +#define JFS_FL_USER_VISIBLE 0x07F80000
3706 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3707 #define JFS_FL_INHERIT 0x03C80000
3709 /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3710 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_filsys.h linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_filsys.h
3711 --- linux-3.13.10/fs/jfs/jfs_filsys.h 2012-12-11 03:30:57.000000000 +0000
3712 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_filsys.h 2014-01-31 20:38:03.000000000 +0000
3714 #define JFS_NAME_MAX 255
3715 #define JFS_PATH_MAX BPSIZE
3717 +#define JFS_TAGGED 0x00800000 /* Context Tagging */
3720 * file system state (superblock state)
3721 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_imap.c linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_imap.c
3722 --- linux-3.13.10/fs/jfs/jfs_imap.c 2013-11-25 15:45:01.000000000 +0000
3723 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_imap.c 2014-01-31 20:38:03.000000000 +0000
3725 #include <linux/pagemap.h>
3726 #include <linux/quotaops.h>
3727 #include <linux/slab.h>
3728 +#include <linux/vs_tag.h>
3730 #include "jfs_incore.h"
3731 #include "jfs_inode.h"
3732 @@ -3047,6 +3048,8 @@ static int copy_from_dinode(struct dinod
3734 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3735 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3739 jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3740 jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3741 @@ -3067,14 +3070,18 @@ static int copy_from_dinode(struct dinod
3743 set_nlink(ip, le32_to_cpu(dip->di_nlink));
3745 - jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3746 + kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3747 + kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3748 + ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3750 + jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3751 if (!uid_valid(sbi->uid))
3752 ip->i_uid = jfs_ip->saved_uid;
3754 ip->i_uid = sbi->uid;
3757 - jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3758 + jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3759 if (!gid_valid(sbi->gid))
3760 ip->i_gid = jfs_ip->saved_gid;
3762 @@ -3139,16 +3146,14 @@ static void copy_to_dinode(struct dinode
3763 dip->di_size = cpu_to_le64(ip->i_size);
3764 dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3765 dip->di_nlink = cpu_to_le32(ip->i_nlink);
3766 - if (!uid_valid(sbi->uid))
3767 - dip->di_uid = cpu_to_le32(i_uid_read(ip));
3769 - dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3770 - jfs_ip->saved_uid));
3771 - if (!gid_valid(sbi->gid))
3772 - dip->di_gid = cpu_to_le32(i_gid_read(ip));
3774 - dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3775 - jfs_ip->saved_gid));
3776 + dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3777 + TAGINO_KUID(DX_TAG(ip),
3778 + !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3780 + dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3781 + TAGINO_KGID(DX_TAG(ip),
3782 + !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3784 jfs_get_inode_flags(jfs_ip);
3786 * mode2 is only needed for storing the higher order bits.
3787 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_inode.c linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.c
3788 --- linux-3.13.10/fs/jfs/jfs_inode.c 2013-11-25 15:46:59.000000000 +0000
3789 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.c 2014-01-31 20:38:03.000000000 +0000
3792 #include <linux/fs.h>
3793 #include <linux/quotaops.h>
3794 +#include <linux/vs_tag.h>
3795 #include "jfs_incore.h"
3796 #include "jfs_inode.h"
3797 #include "jfs_filsys.h"
3798 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3800 unsigned int flags = JFS_IP(inode)->mode2;
3802 - inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3803 - S_NOATIME | S_DIRSYNC | S_SYNC);
3804 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3805 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3807 if (flags & JFS_IMMUTABLE_FL)
3808 inode->i_flags |= S_IMMUTABLE;
3809 + if (flags & JFS_IXUNLINK_FL)
3810 + inode->i_flags |= S_IXUNLINK;
3812 + if (flags & JFS_SYNC_FL)
3813 + inode->i_flags |= S_SYNC;
3814 if (flags & JFS_APPEND_FL)
3815 inode->i_flags |= S_APPEND;
3816 if (flags & JFS_NOATIME_FL)
3817 inode->i_flags |= S_NOATIME;
3818 if (flags & JFS_DIRSYNC_FL)
3819 inode->i_flags |= S_DIRSYNC;
3820 - if (flags & JFS_SYNC_FL)
3821 - inode->i_flags |= S_SYNC;
3823 + inode->i_vflags &= ~(V_BARRIER | V_COW);
3825 + if (flags & JFS_BARRIER_FL)
3826 + inode->i_vflags |= V_BARRIER;
3827 + if (flags & JFS_COW_FL)
3828 + inode->i_vflags |= V_COW;
3831 void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3833 unsigned int flags = jfs_ip->vfs_inode.i_flags;
3834 + unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3836 + jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3837 + JFS_APPEND_FL | JFS_NOATIME_FL |
3838 + JFS_DIRSYNC_FL | JFS_SYNC_FL |
3839 + JFS_BARRIER_FL | JFS_COW_FL);
3841 - jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3842 - JFS_DIRSYNC_FL | JFS_SYNC_FL);
3843 if (flags & S_IMMUTABLE)
3844 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3845 + if (flags & S_IXUNLINK)
3846 + jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3848 if (flags & S_APPEND)
3849 jfs_ip->mode2 |= JFS_APPEND_FL;
3850 if (flags & S_NOATIME)
3851 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3852 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3854 jfs_ip->mode2 |= JFS_SYNC_FL;
3856 + if (vflags & V_BARRIER)
3857 + jfs_ip->mode2 |= JFS_BARRIER_FL;
3858 + if (vflags & V_COW)
3859 + jfs_ip->mode2 |= JFS_COW_FL;
3863 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_inode.h linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.h
3864 --- linux-3.13.10/fs/jfs/jfs_inode.h 2012-12-11 03:30:57.000000000 +0000
3865 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.h 2014-01-31 20:38:03.000000000 +0000
3866 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3867 extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3868 int fh_len, int fh_type);
3869 extern void jfs_set_inode_flags(struct inode *);
3870 +extern int jfs_sync_flags(struct inode *, int, int);
3871 extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3872 extern int jfs_setattr(struct dentry *, struct iattr *);
3874 diff -NurpP --minimal linux-3.13.10/fs/jfs/namei.c linux-3.13.10-vs2.3.6.11/fs/jfs/namei.c
3875 --- linux-3.13.10/fs/jfs/namei.c 2013-11-25 15:45:01.000000000 +0000
3876 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/namei.c 2014-01-31 20:38:03.000000000 +0000
3878 #include <linux/ctype.h>
3879 #include <linux/quotaops.h>
3880 #include <linux/exportfs.h>
3881 +#include <linux/vs_tag.h>
3882 #include "jfs_incore.h"
3883 #include "jfs_superblock.h"
3884 #include "jfs_inode.h"
3885 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3886 jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3889 + dx_propagate_tag(nd, ip);
3890 return d_splice_alias(ip, dentry);
3893 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
3894 #ifdef CONFIG_JFS_POSIX_ACL
3895 .get_acl = jfs_get_acl,
3897 + .sync_flags = jfs_sync_flags,
3900 const struct file_operations jfs_dir_operations = {
3901 diff -NurpP --minimal linux-3.13.10/fs/jfs/super.c linux-3.13.10-vs2.3.6.11/fs/jfs/super.c
3902 --- linux-3.13.10/fs/jfs/super.c 2013-11-25 15:45:01.000000000 +0000
3903 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/super.c 2014-01-31 20:38:03.000000000 +0000
3904 @@ -203,7 +203,8 @@ enum {
3905 Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
3906 Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
3907 Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
3908 - Opt_discard, Opt_nodiscard, Opt_discard_minblk
3909 + Opt_discard, Opt_nodiscard, Opt_discard_minblk,
3910 + Opt_tag, Opt_notag, Opt_tagid
3913 static const match_table_t tokens = {
3914 @@ -213,6 +214,10 @@ static const match_table_t tokens = {
3915 {Opt_resize, "resize=%u"},
3916 {Opt_resize_nosize, "resize"},
3917 {Opt_errors, "errors=%s"},
3919 + {Opt_notag, "notag"},
3920 + {Opt_tagid, "tagid=%u"},
3921 + {Opt_tag, "tagxid"},
3922 {Opt_ignore, "noquota"},
3923 {Opt_ignore, "quota"},
3924 {Opt_usrquota, "usrquota"},
3925 @@ -389,7 +394,20 @@ static int parse_options(char *options,
3930 +#ifndef CONFIG_TAGGING_NONE
3932 + *flag |= JFS_TAGGED;
3935 + *flag &= JFS_TAGGED;
3938 +#ifdef CONFIG_PROPAGATE
3941 + *flag |= JFS_TAGGED;
3945 printk("jfs: Unrecognized mount option \"%s\" "
3946 " or missing value\n", p);
3947 @@ -421,6 +439,12 @@ static int jfs_remount(struct super_bloc
3951 + if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
3952 + printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
3958 if (sb->s_flags & MS_RDONLY) {
3959 pr_err("JFS: resize requires volume" \
3960 @@ -506,6 +530,9 @@ static int jfs_fill_super(struct super_b
3961 #ifdef CONFIG_JFS_POSIX_ACL
3962 sb->s_flags |= MS_POSIXACL;
3964 + /* map mount option tagxid */
3965 + if (sbi->flag & JFS_TAGGED)
3966 + sb->s_flags |= MS_TAGGED;
3969 pr_err("resize option for remount only\n");
3970 diff -NurpP --minimal linux-3.13.10/fs/libfs.c linux-3.13.10-vs2.3.6.11/fs/libfs.c
3971 --- linux-3.13.10/fs/libfs.c 2014-01-22 20:39:06.000000000 +0000
3972 +++ linux-3.13.10-vs2.3.6.11/fs/libfs.c 2014-02-01 01:35:46.000000000 +0000
3973 @@ -145,13 +145,14 @@ static inline unsigned char dt_type(stru
3974 * both impossible due to the lock on directory.
3977 -int dcache_readdir(struct file *file, struct dir_context *ctx)
3978 +static inline int do_dcache_readdir_filter(struct file *filp,
3979 + struct dir_context *ctx, int (*filter)(struct dentry *dentry))
3981 - struct dentry *dentry = file->f_path.dentry;
3982 - struct dentry *cursor = file->private_data;
3983 + struct dentry *dentry = filp->f_path.dentry;
3984 + struct dentry *cursor = filp->private_data;
3985 struct list_head *p, *q = &cursor->d_u.d_child;
3987 - if (!dir_emit_dots(file, ctx))
3988 + if (!dir_emit_dots(filp, ctx))
3990 spin_lock(&dentry->d_lock);
3992 @@ -159,6 +160,8 @@ int dcache_readdir(struct file *file, st
3994 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
3995 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
3996 + if (filter && !filter(next))
3998 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
3999 if (!simple_positive(next)) {
4000 spin_unlock(&next->d_lock);
4001 @@ -181,8 +184,22 @@ int dcache_readdir(struct file *file, st
4002 spin_unlock(&dentry->d_lock);
4006 EXPORT_SYMBOL(dcache_readdir);
4008 +int dcache_readdir(struct file *filp, struct dir_context *ctx)
4010 + return do_dcache_readdir_filter(filp, ctx, NULL);
4013 +EXPORT_SYMBOL(dcache_readdir_filter);
4015 +int dcache_readdir_filter(struct file *filp, struct dir_context *ctx,
4016 + int (*filter)(struct dentry *))
4018 + return do_dcache_readdir_filter(filp, ctx, filter);
4021 ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4024 diff -NurpP --minimal linux-3.13.10/fs/locks.c linux-3.13.10-vs2.3.6.11/fs/locks.c
4025 --- linux-3.13.10/fs/locks.c 2014-01-22 20:39:06.000000000 +0000
4026 +++ linux-3.13.10-vs2.3.6.11/fs/locks.c 2014-01-31 23:51:55.000000000 +0000
4028 #include <linux/hashtable.h>
4029 #include <linux/percpu.h>
4030 #include <linux/lglock.h>
4031 +#include <linux/vs_base.h>
4032 +#include <linux/vs_limit.h>
4034 #include <asm/uaccess.h>
4036 @@ -210,11 +212,17 @@ static void locks_init_lock_heads(struct
4037 /* Allocate an empty lock structure. */
4038 struct file_lock *locks_alloc_lock(void)
4040 - struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4041 + struct file_lock *fl;
4044 - locks_init_lock_heads(fl);
4045 + if (!vx_locks_avail(1))
4048 + fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4051 + locks_init_lock_heads(fl);
4056 EXPORT_SYMBOL_GPL(locks_alloc_lock);
4057 @@ -238,6 +246,7 @@ void locks_free_lock(struct file_lock *f
4058 BUG_ON(!list_empty(&fl->fl_block));
4059 BUG_ON(!hlist_unhashed(&fl->fl_link));
4062 locks_release_private(fl);
4063 kmem_cache_free(filelock_cache, fl);
4065 @@ -247,6 +256,7 @@ void locks_init_lock(struct file_lock *f
4067 memset(fl, 0, sizeof(struct file_lock));
4068 locks_init_lock_heads(fl);
4072 EXPORT_SYMBOL(locks_init_lock);
4073 @@ -287,6 +297,7 @@ void locks_copy_lock(struct file_lock *n
4074 new->fl_file = fl->fl_file;
4075 new->fl_ops = fl->fl_ops;
4076 new->fl_lmops = fl->fl_lmops;
4077 + new->fl_xid = fl->fl_xid;
4079 locks_copy_private(new, fl);
4081 @@ -325,6 +336,11 @@ static int flock_make_lock(struct file *
4082 fl->fl_flags = FL_FLOCK;
4084 fl->fl_end = OFFSET_MAX;
4086 + vxd_assert(filp->f_xid == vx_current_xid(),
4087 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4088 + fl->fl_xid = filp->f_xid;
4093 @@ -464,6 +480,7 @@ static int lease_init(struct file *filp,
4095 fl->fl_owner = current->files;
4096 fl->fl_pid = current->tgid;
4097 + fl->fl_xid = vx_current_xid();
4100 fl->fl_flags = FL_LEASE;
4101 @@ -483,6 +500,11 @@ static struct file_lock *lease_alloc(str
4103 return ERR_PTR(error);
4105 + fl->fl_xid = vx_current_xid();
4107 + vxd_assert(filp->f_xid == fl->fl_xid,
4108 + "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4110 error = lease_init(filp, type, fl);
4112 locks_free_lock(fl);
4113 @@ -858,6 +880,7 @@ static int flock_lock_file(struct file *
4114 spin_lock(&inode->i_lock);
4117 + new_fl->fl_xid = -1;
4119 for_each_lock(inode, before) {
4120 struct file_lock *fl = *before;
4121 @@ -878,6 +901,7 @@ find_conflict:
4123 locks_copy_lock(new_fl, request);
4124 locks_insert_lock(before, new_fl);
4125 + vx_locks_inc(new_fl);
4129 @@ -888,7 +912,8 @@ out:
4133 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4134 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4135 + struct file_lock *conflock, vxid_t xid)
4137 struct file_lock *fl;
4138 struct file_lock *new_fl = NULL;
4139 @@ -899,6 +924,8 @@ static int __posix_lock_file(struct inod
4143 + vxd_assert(xid == vx_current_xid(),
4144 + "xid(%d) == current(%d)", xid, vx_current_xid());
4146 * We may need two file_lock structures for this operation,
4147 * so we get them in advance to avoid races.
4148 @@ -909,7 +936,11 @@ static int __posix_lock_file(struct inod
4149 (request->fl_type != F_UNLCK ||
4150 request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4151 new_fl = locks_alloc_lock();
4152 + new_fl->fl_xid = xid;
4153 + vx_locks_inc(new_fl);
4154 new_fl2 = locks_alloc_lock();
4155 + new_fl2->fl_xid = xid;
4156 + vx_locks_inc(new_fl2);
4159 spin_lock(&inode->i_lock);
4160 @@ -1118,7 +1149,8 @@ static int __posix_lock_file(struct inod
4161 int posix_lock_file(struct file *filp, struct file_lock *fl,
4162 struct file_lock *conflock)
4164 - return __posix_lock_file(file_inode(filp), fl, conflock);
4165 + return __posix_lock_file(file_inode(filp),
4166 + fl, conflock, filp->f_xid);
4168 EXPORT_SYMBOL(posix_lock_file);
4170 @@ -1208,7 +1240,7 @@ int locks_mandatory_area(int read_write,
4171 fl.fl_end = offset + count - 1;
4174 - error = __posix_lock_file(inode, &fl, NULL);
4175 + error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4176 if (error != FILE_LOCK_DEFERRED)
4178 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4179 @@ -1549,6 +1581,7 @@ static int generic_add_lease(struct file
4182 locks_insert_lock(before, lease);
4183 + vx_locks_inc(lease);
4187 @@ -1991,6 +2024,11 @@ int fcntl_setlk(unsigned int fd, struct
4188 if (file_lock == NULL)
4191 + vxd_assert(filp->f_xid == vx_current_xid(),
4192 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4193 + file_lock->fl_xid = filp->f_xid;
4194 + vx_locks_inc(file_lock);
4197 * This might block, so we do it before checking the inode.
4199 @@ -2109,6 +2147,11 @@ int fcntl_setlk64(unsigned int fd, struc
4200 if (file_lock == NULL)
4203 + vxd_assert(filp->f_xid == vx_current_xid(),
4204 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4205 + file_lock->fl_xid = filp->f_xid;
4206 + vx_locks_inc(file_lock);
4209 * This might block, so we do it before checking the inode.
4211 @@ -2378,8 +2421,11 @@ static int locks_show(struct seq_file *f
4213 lock_get_status(f, fl, iter->li_pos, "");
4215 - list_for_each_entry(bfl, &fl->fl_block, fl_block)
4216 - lock_get_status(f, bfl, iter->li_pos, " ->");
4217 + list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4218 + if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4220 + lock_get_status(f, bfl, iter->li_pos, " ->");
4225 diff -NurpP --minimal linux-3.13.10/fs/mount.h linux-3.13.10-vs2.3.6.11/fs/mount.h
4226 --- linux-3.13.10/fs/mount.h 2014-04-17 01:12:32.000000000 +0000
4227 +++ linux-3.13.10-vs2.3.6.11/fs/mount.h 2014-04-17 01:17:10.000000000 +0000
4228 @@ -57,6 +57,7 @@ struct mount {
4229 int mnt_expiry_mark; /* true if marked for expiry */
4231 struct path mnt_ex_mountpoint;
4232 + vtag_t mnt_tag; /* tagging used for vfsmount */
4235 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4236 diff -NurpP --minimal linux-3.13.10/fs/namei.c linux-3.13.10-vs2.3.6.11/fs/namei.c
4237 --- linux-3.13.10/fs/namei.c 2014-04-17 01:12:32.000000000 +0000
4238 +++ linux-3.13.10-vs2.3.6.11/fs/namei.c 2014-04-17 01:17:10.000000000 +0000
4240 #include <linux/device_cgroup.h>
4241 #include <linux/fs_struct.h>
4242 #include <linux/posix_acl.h>
4243 +#include <linux/proc_fs.h>
4244 +#include <linux/magic.h>
4245 +#include <linux/vserver/inode.h>
4246 +#include <linux/vs_base.h>
4247 +#include <linux/vs_tag.h>
4248 +#include <linux/vs_cowbl.h>
4249 +#include <linux/vs_device.h>
4250 +#include <linux/vs_context.h>
4251 +#include <linux/pid_namespace.h>
4252 #include <asm/uaccess.h>
4254 #include "internal.h"
4255 +#include "proc/internal.h"
4258 /* [Feb-1997 T. Schoebel-Theuer]
4259 @@ -266,6 +276,89 @@ static int check_acl(struct inode *inode
4263 +static inline int dx_barrier(const struct inode *inode)
4265 + if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4266 + vxwprintk_task(1, "did hit the barrier.");
4272 +static int __dx_permission(const struct inode *inode, int mask)
4274 + if (dx_barrier(inode))
4277 + if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4278 + /* devpts is xid tagged */
4279 + if (S_ISDIR(inode->i_mode) ||
4280 + vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4283 + /* just pretend we didn't find anything */
4286 + else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4287 + struct proc_dir_entry *de = PDE(inode);
4289 + if (de && !vx_hide_check(0, de->vx_flags))
4292 + if ((mask & (MAY_WRITE | MAY_APPEND))) {
4294 + struct task_struct *tsk;
4296 + if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4297 + vx_flags(VXF_STATE_SETUP, 0))
4300 + pid = PROC_I(inode)->pid;
4305 + tsk = pid_task(pid, PIDTYPE_PID);
4306 + vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4307 + tsk, (tsk ? vx_task_xid(tsk) : 0));
4309 + vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4310 + rcu_read_unlock();
4313 + rcu_read_unlock();
4316 + /* FIXME: Should we block some entries here? */
4321 + if (dx_notagcheck(inode->i_sb) ||
4322 + dx_check((vxid_t)i_tag_read(inode),
4323 + DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4331 +int dx_permission(const struct inode *inode, int mask)
4333 + int ret = __dx_permission(inode, mask);
4334 + if (unlikely(ret)) {
4335 +#ifndef CONFIG_VSERVER_WARN_DEVPTS
4336 + if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4339 + "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4340 + mask, inode->i_sb->s_id, inode,
4341 + i_tag_read(inode), inode->i_ino);
4347 * This does the basic permission checking
4349 @@ -388,10 +481,14 @@ int __inode_permission(struct inode *ino
4351 * Nobody gets write access to an immutable file.
4353 - if (IS_IMMUTABLE(inode))
4354 + if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4358 + retval = dx_permission(inode, mask);
4362 retval = do_inode_permission(inode, mask);
4365 @@ -1238,7 +1335,8 @@ static void follow_dotdot(struct nameida
4367 if (nd->path.dentry == nd->root.dentry &&
4368 nd->path.mnt == nd->root.mnt) {
4370 + /* for sane '/' avoid follow_mount() */
4373 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4374 /* rare case of legitimate dget_parent()... */
4375 @@ -1383,6 +1481,9 @@ static int lookup_fast(struct nameidata
4380 + /* FIXME: check dx permission */
4383 path->dentry = dentry;
4384 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4385 @@ -1413,6 +1514,8 @@ unlazy:
4389 + /* FIXME: check dx permission */
4392 path->dentry = dentry;
4393 err = follow_managed(path, nd->flags);
4394 @@ -2400,7 +2503,7 @@ static int may_delete(struct inode *dir,
4397 if (check_sticky(dir, inode) || IS_APPEND(inode) ||
4398 - IS_IMMUTABLE(inode) || IS_SWAPFILE(inode))
4399 + IS_IXORUNLINK(inode) || IS_SWAPFILE(inode))
4402 if (!d_is_directory(victim) && !d_is_autodir(victim))
4403 @@ -2480,19 +2583,25 @@ int vfs_create(struct inode *dir, struct
4406 int error = may_create(dir, dentry);
4409 + vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4413 if (!dir->i_op->create)
4414 return -EACCES; /* shouldn't it be ENOSYS? */
4417 error = security_inode_create(dir, dentry, mode);
4420 + vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4423 error = dir->i_op->create(dir, dentry, mode, want_excl);
4425 fsnotify_create(dir, dentry);
4427 + vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4431 @@ -2527,6 +2636,15 @@ static int may_open(struct path *path, i
4435 +#ifdef CONFIG_VSERVER_COWBL
4436 + if (IS_COW(inode) &&
4437 + ((flag & O_ACCMODE) != O_RDONLY)) {
4438 + if (IS_COW_LINK(inode))
4440 + inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4441 + mark_inode_dirty(inode);
4444 error = inode_permission(inode, acc_mode);
4447 @@ -3022,6 +3140,16 @@ finish_open:
4449 finish_open_created:
4450 error = may_open(&nd->path, acc_mode, open_flag);
4451 +#ifdef CONFIG_VSERVER_COWBL
4452 + if (error == -EMLINK) {
4453 + struct dentry *dentry;
4454 + dentry = cow_break_link(name->name);
4455 + if (IS_ERR(dentry))
4456 + error = PTR_ERR(dentry);
4463 file->f_path.mnt = nd->path.mnt;
4464 @@ -3147,6 +3275,7 @@ static struct file *path_openat(int dfd,
4469 file = get_empty_filp();
4472 @@ -3188,6 +3317,16 @@ static struct file *path_openat(int dfd,
4473 error = do_last(nd, &path, file, op, &opened, pathname);
4474 put_link(nd, &link, cookie);
4477 +#ifdef CONFIG_VSERVER_COWBL
4478 + if (error == -EMLINK) {
4479 + if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4480 + path_put(&nd->root);
4487 if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4488 path_put(&nd->root);
4489 @@ -3303,6 +3442,11 @@ struct dentry *kern_path_create(int dfd,
4493 + vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4494 + path->dentry, path->dentry->d_name.len,
4495 + path->dentry->d_name.name, dentry,
4496 + dentry->d_name.len, dentry->d_name.name,
4497 + path->dentry->d_inode);
4501 @@ -3850,7 +3994,7 @@ int vfs_link(struct dentry *old_dentry,
4503 * A link to an append-only or immutable file cannot be created.
4505 - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4506 + if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4508 if (!dir->i_op->link)
4510 @@ -4305,6 +4449,287 @@ int generic_readlink(struct dentry *dent
4515 +#ifdef CONFIG_VSERVER_COWBL
4518 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4523 + return do_splice_direct(in, &ppos, out, &opos, len, 0);
4526 +struct dentry *cow_break_link(const char *pathname)
4528 + int ret, mode, pathlen, redo = 0, drop = 1;
4529 + struct nameidata old_nd, dir_nd;
4530 + struct path dir_path, *old_path, *new_path;
4531 + struct dentry *dir, *old_dentry, *new_dentry = NULL;
4532 + struct file *old_file;
4533 + struct file *new_file;
4534 + char *to, *path, pad='\251';
4537 + vxdprintk(VXD_CBIT(misc, 1),
4538 + "cow_break_link(" VS_Q("%s") ")", pathname);
4540 + path = kmalloc(PATH_MAX, GFP_KERNEL);
4545 + /* old_nd.path will have refs to dentry and mnt */
4546 + ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4547 + vxdprintk(VXD_CBIT(misc, 2),
4548 + "do_path_lookup(old): %d", ret);
4550 + goto out_free_path;
4552 + /* dentry/mnt refs handed over to old_path */
4553 + old_path = &old_nd.path;
4554 + /* no explicit reference for old_dentry here */
4555 + old_dentry = old_path->dentry;
4557 + mode = old_dentry->d_inode->i_mode;
4558 + to = d_path(old_path, path, PATH_MAX-2);
4559 + pathlen = strlen(to);
4560 + vxdprintk(VXD_CBIT(misc, 2),
4561 + "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4563 + old_dentry->d_name.len, old_dentry->d_name.name,
4564 + old_dentry->d_name.len);
4566 + to[pathlen + 1] = 0;
4568 + new_dentry = NULL;
4569 + to[pathlen] = pad--;
4571 + if (pad <= '\240')
4574 + vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4576 + /* dir_nd.path will have refs to dentry and mnt */
4577 + ret = do_path_lookup(AT_FDCWD, to,
4578 + LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4579 + vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4583 + /* this puppy downs the dir inode mutex if successful.
4584 + dir_path will hold refs to dentry and mnt and
4585 + we'll have write access to the mnt */
4586 + new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4587 + if (!new_dentry || IS_ERR(new_dentry)) {
4588 + path_put(&dir_nd.path);
4589 + vxdprintk(VXD_CBIT(misc, 2),
4590 + "kern_path_create(new) failed with %ld",
4591 + PTR_ERR(new_dentry));
4594 + vxdprintk(VXD_CBIT(misc, 2),
4595 + "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4597 + new_dentry->d_name.len, new_dentry->d_name.name,
4598 + new_dentry->d_name.len);
4600 + /* take a reference on new_dentry */
4603 + /* dentry/mnt refs handed over to new_path */
4604 + new_path = &dir_path;
4606 + /* dentry for old/new dir */
4607 + dir = dir_nd.path.dentry;
4609 + /* give up reference on dir */
4610 + dput(new_path->dentry);
4612 + /* new_dentry already has a reference */
4613 + new_path->dentry = new_dentry;
4615 + ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4616 + vxdprintk(VXD_CBIT(misc, 2),
4617 + "vfs_create(new): %d", ret);
4618 + if (ret == -EEXIST) {
4619 + path_put(&dir_nd.path);
4620 + mutex_unlock(&dir->d_inode->i_mutex);
4621 + mnt_drop_write(new_path->mnt);
4622 + path_put(new_path);
4623 + new_dentry = NULL;
4627 + goto out_unlock_new;
4629 + /* drop out early, ret passes ENOENT */
4631 + if ((redo = d_unhashed(old_dentry)))
4632 + goto out_unlock_new;
4634 + /* doesn't change refs for old_path */
4635 + old_file = dentry_open(old_path, O_RDONLY, current_cred());
4636 + vxdprintk(VXD_CBIT(misc, 2),
4637 + "dentry_open(old): %p", old_file);
4638 + if (IS_ERR(old_file)) {
4639 + ret = PTR_ERR(old_file);
4640 + goto out_unlock_new;
4643 + /* doesn't change refs for new_path */
4644 + new_file = dentry_open(new_path, O_WRONLY, current_cred());
4645 + vxdprintk(VXD_CBIT(misc, 2),
4646 + "dentry_open(new): %p", new_file);
4647 + if (IS_ERR(new_file)) {
4648 + ret = PTR_ERR(new_file);
4649 + goto out_fput_old;
4652 + /* unlock the inode mutex from kern_path_create() */
4653 + mutex_unlock(&dir->d_inode->i_mutex);
4655 + /* drop write access to mnt */
4656 + mnt_drop_write(new_path->mnt);
4660 + size = i_size_read(old_file->f_dentry->d_inode);
4661 + ret = do_cow_splice(old_file, new_file, size);
4662 + vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4664 + goto out_fput_both;
4665 + } else if (ret < size) {
4667 + goto out_fput_both;
4669 + struct inode *old_inode = old_dentry->d_inode;
4670 + struct inode *new_inode = new_dentry->d_inode;
4671 + struct iattr attr = {
4672 + .ia_uid = old_inode->i_uid,
4673 + .ia_gid = old_inode->i_gid,
4674 + .ia_valid = ATTR_UID | ATTR_GID
4677 + setattr_copy(new_inode, &attr);
4678 + mark_inode_dirty(new_inode);
4681 + /* lock rename mutex */
4682 + mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4684 + /* drop out late */
4686 + if ((redo = d_unhashed(old_dentry)))
4689 + vxdprintk(VXD_CBIT(misc, 2),
4690 + "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4691 + new_dentry->d_name.len, new_dentry->d_name.name,
4692 + new_dentry->d_name.len,
4693 + old_dentry->d_name.len, old_dentry->d_name.name,
4694 + old_dentry->d_name.len);
4695 + ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4696 + old_dentry->d_parent->d_inode, old_dentry, NULL);
4697 + vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4700 + mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4703 + vxdprintk(VXD_CBIT(misc, 3),
4704 + "fput(new_file=%p[#%ld])", new_file,
4705 + atomic_long_read(&new_file->f_count));
4709 + vxdprintk(VXD_CBIT(misc, 3),
4710 + "fput(old_file=%p[#%ld])", old_file,
4711 + atomic_long_read(&old_file->f_count));
4715 + /* drop references from dir_nd.path */
4716 + path_put(&dir_nd.path);
4719 + /* unlock the inode mutex from kern_path_create() */
4720 + mutex_unlock(&dir->d_inode->i_mutex);
4722 + /* drop write access to mnt */
4723 + mnt_drop_write(new_path->mnt);
4729 + /* error path cleanup */
4730 + vfs_unlink(dir->d_inode, new_dentry, NULL);
4734 + goto out_rel_both;
4736 + /* lookup dentry once again
4737 + old_nd.path will be freed as old_path in out_rel_old */
4738 + ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4740 + goto out_rel_both;
4742 + /* drop reference on new_dentry */
4744 + new_dentry = old_path->dentry;
4746 + vxdprintk(VXD_CBIT(misc, 2),
4747 + "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4749 + new_dentry->d_name.len, new_dentry->d_name.name,
4750 + new_dentry->d_name.len);
4754 + path_put(new_path);
4756 + path_put(old_path);
4762 + new_dentry = ERR_PTR(ret);
4764 + vxdprintk(VXD_CBIT(misc, 3),
4765 + "cow_break_link returning with %p", new_dentry);
4766 + return new_dentry;
4771 +int vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4774 + struct vfsmount *vmnt;
4775 + char *pstr, *root;
4778 + pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4782 + vmnt = &ns->root->mnt;
4784 + path.dentry = vmnt->mnt_root;
4785 + root = d_path(&path, pstr, PATH_MAX - 2);
4786 + length = sprintf(buffer + length,
4787 + "Namespace:\t%p [#%u]\n"
4788 + "RootPath:\t%s\n",
4789 + ns, atomic_read(&ns->count),
4795 /* get the link contents into pagecache */
4796 static char *page_getlink(struct dentry * dentry, struct page **ppage)
4798 @@ -4427,3 +4852,4 @@ EXPORT_SYMBOL(vfs_symlink);
4799 EXPORT_SYMBOL(vfs_unlink);
4800 EXPORT_SYMBOL(dentry_unhash);
4801 EXPORT_SYMBOL(generic_readlink);
4802 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4803 diff -NurpP --minimal linux-3.13.10/fs/namespace.c linux-3.13.10-vs2.3.6.11/fs/namespace.c
4804 --- linux-3.13.10/fs/namespace.c 2014-04-17 01:12:32.000000000 +0000
4805 +++ linux-3.13.10-vs2.3.6.11/fs/namespace.c 2014-04-17 01:18:37.000000000 +0000
4807 #include <linux/proc_ns.h>
4808 #include <linux/magic.h>
4809 #include <linux/bootmem.h>
4810 +#include <linux/vs_base.h>
4811 +#include <linux/vs_context.h>
4812 +#include <linux/vs_tag.h>
4813 +#include <linux/vserver/space.h>
4814 +#include <linux/vserver/global.h>
4816 #include "internal.h"
4818 @@ -839,6 +844,10 @@ vfs_kern_mount(struct file_system_type *
4820 return ERR_PTR(-ENODEV);
4822 + if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4823 + !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4824 + return ERR_PTR(-EPERM);
4826 mnt = alloc_vfsmnt(name);
4828 return ERR_PTR(-ENOMEM);
4829 @@ -899,6 +908,7 @@ static struct mount *clone_mnt(struct mo
4830 mnt->mnt.mnt_root = dget(root);
4831 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4832 mnt->mnt_parent = mnt;
4833 + mnt->mnt_tag = old->mnt_tag;
4835 list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4836 unlock_mount_hash();
4837 @@ -1369,7 +1379,8 @@ static int do_umount(struct mount *mnt,
4839 static inline bool may_mount(void)
4841 - return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4842 + return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4843 + CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4847 @@ -1785,6 +1796,7 @@ static int do_change_type(struct path *p
4851 + // mnt->mnt_flags = mnt_flags;
4854 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4855 @@ -1813,12 +1825,14 @@ static bool has_locked_children(struct m
4856 * do loopback mount.
4858 static int do_loopback(struct path *path, const char *old_name,
4860 + vtag_t tag, unsigned long flags, int mnt_flags)
4862 struct path old_path;
4863 struct mount *mnt = NULL, *old, *parent;
4864 struct mountpoint *mp;
4865 + int recurse = flags & MS_REC;
4868 if (!old_name || !*old_name)
4870 err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4871 @@ -1898,7 +1912,7 @@ static int change_mount_flags(struct vfs
4872 * on it - tough luck.
4874 static int do_remount(struct path *path, int flags, int mnt_flags,
4876 + void *data, vxid_t xid)
4879 struct super_block *sb = path->mnt->mnt_sb;
4880 @@ -2377,6 +2391,7 @@ long do_mount(const char *dev_name, cons
4887 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4888 @@ -2406,6 +2421,12 @@ long do_mount(const char *dev_name, cons
4889 if (!(flags & MS_NOATIME))
4890 mnt_flags |= MNT_RELATIME;
4892 + if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4893 + /* FIXME: bind and re-mounts get the tag flag? */
4894 + if (flags & (MS_BIND|MS_REMOUNT))
4895 + flags |= MS_TAGID;
4898 /* Separate the per-mountpoint flags */
4899 if (flags & MS_NOSUID)
4900 mnt_flags |= MNT_NOSUID;
4901 @@ -2422,15 +2443,17 @@ long do_mount(const char *dev_name, cons
4902 if (flags & MS_RDONLY)
4903 mnt_flags |= MNT_READONLY;
4905 + if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4906 + mnt_flags |= MNT_NODEV;
4907 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4908 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4911 if (flags & MS_REMOUNT)
4912 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4915 else if (flags & MS_BIND)
4916 - retval = do_loopback(&path, dev_name, flags & MS_REC);
4917 + retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4918 else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4919 retval = do_change_type(&path, flags);
4920 else if (flags & MS_MOVE)
4921 @@ -2546,6 +2569,7 @@ struct mnt_namespace *copy_mnt_ns(unsign
4922 p = next_mnt(p, old);
4925 + atomic_inc(&vs_global_mnt_ns);
4929 @@ -2727,9 +2751,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4930 new_mnt = real_mount(new.mnt);
4931 root_mnt = real_mount(root.mnt);
4932 old_mnt = real_mount(old.mnt);
4933 - if (IS_MNT_SHARED(old_mnt) ||
4934 + if ((IS_MNT_SHARED(old_mnt) ||
4935 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4936 - IS_MNT_SHARED(root_mnt->mnt_parent))
4937 + IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4938 + !vx_flags(VXF_STATE_SETUP, 0))
4940 if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4942 @@ -2859,6 +2884,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4943 if (!atomic_dec_and_test(&ns->count))
4945 drop_collected_mounts(&ns->root->mnt);
4946 + atomic_dec(&vs_global_mnt_ns);
4950 diff -NurpP --minimal linux-3.13.10/fs/nfs/client.c linux-3.13.10-vs2.3.6.11/fs/nfs/client.c
4951 --- linux-3.13.10/fs/nfs/client.c 2014-01-22 20:39:06.000000000 +0000
4952 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/client.c 2014-01-31 20:38:03.000000000 +0000
4953 @@ -685,6 +685,9 @@ int nfs_init_server_rpcclient(struct nfs
4954 if (server->flags & NFS_MOUNT_SOFT)
4955 server->client->cl_softrtry = 1;
4957 + server->client->cl_tag = 0;
4958 + if (server->flags & NFS_MOUNT_TAGGED)
4959 + server->client->cl_tag = 1;
4962 EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4963 @@ -863,6 +866,10 @@ static void nfs_server_set_fsinfo(struct
4964 server->acdirmin = server->acdirmax = 0;
4967 + /* FIXME: needs fsinfo
4968 + if (server->flags & NFS_MOUNT_TAGGED)
4969 + sb->s_flags |= MS_TAGGED; */
4971 server->maxfilesize = fsinfo->maxfilesize;
4973 server->time_delta = fsinfo->time_delta;
4974 diff -NurpP --minimal linux-3.13.10/fs/nfs/dir.c linux-3.13.10-vs2.3.6.11/fs/nfs/dir.c
4975 --- linux-3.13.10/fs/nfs/dir.c 2014-04-17 01:12:32.000000000 +0000
4976 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/dir.c 2014-02-25 11:26:10.000000000 +0000
4978 #include <linux/sched.h>
4979 #include <linux/kmemleak.h>
4980 #include <linux/xattr.h>
4981 +#include <linux/vs_tag.h>
4983 #include "delegation.h"
4985 @@ -1319,6 +1320,7 @@ struct dentry *nfs_lookup(struct inode *
4986 /* Success: notify readdir to use READDIRPLUS */
4987 nfs_advise_use_readdirplus(dir);
4989 + dx_propagate_tag(nd, inode);
4991 res = d_materialise_unique(dentry, inode);
4993 diff -NurpP --minimal linux-3.13.10/fs/nfs/inode.c linux-3.13.10-vs2.3.6.11/fs/nfs/inode.c
4994 --- linux-3.13.10/fs/nfs/inode.c 2014-04-17 01:12:32.000000000 +0000
4995 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/inode.c 2014-03-12 15:51:07.000000000 +0000
4997 #include <linux/slab.h>
4998 #include <linux/compat.h>
4999 #include <linux/freezer.h>
5000 +#include <linux/vs_tag.h>
5002 #include <asm/uaccess.h>
5004 @@ -359,6 +360,8 @@ nfs_fhget(struct super_block *sb, struct
5005 if (inode->i_state & I_NEW) {
5006 struct nfs_inode *nfsi = NFS_I(inode);
5007 unsigned long now = jiffies;
5011 /* We set i_ino for the few things that still rely on it,
5012 * such as stat(2) */
5013 @@ -403,8 +406,8 @@ nfs_fhget(struct super_block *sb, struct
5014 inode->i_version = 0;
5017 - inode->i_uid = make_kuid(&init_user_ns, -2);
5018 - inode->i_gid = make_kgid(&init_user_ns, -2);
5019 + kuid = make_kuid(&init_user_ns, -2);
5020 + kgid = make_kgid(&init_user_ns, -2);
5021 inode->i_blocks = 0;
5022 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5024 @@ -438,11 +441,11 @@ nfs_fhget(struct super_block *sb, struct
5025 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5026 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5027 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5028 - inode->i_uid = fattr->uid;
5029 + kuid = fattr->uid;
5030 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5031 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5032 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5033 - inode->i_gid = fattr->gid;
5034 + kgid = fattr->gid;
5035 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5036 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5037 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5038 @@ -453,6 +456,10 @@ nfs_fhget(struct super_block *sb, struct
5040 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5042 + inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5043 + inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5044 + inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
5045 + /* maybe fattr->xid someday */
5047 nfs_setsecurity(inode, fattr, label);
5049 @@ -578,6 +585,8 @@ void nfs_setattr_update_inode(struct ino
5050 inode->i_uid = attr->ia_uid;
5051 if ((attr->ia_valid & ATTR_GID) != 0)
5052 inode->i_gid = attr->ia_gid;
5053 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5054 + inode->i_tag = attr->ia_tag;
5055 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5056 spin_unlock(&inode->i_lock);
5058 @@ -1092,7 +1101,9 @@ static int nfs_check_inode_attributes(st
5059 struct nfs_inode *nfsi = NFS_I(inode);
5060 loff_t cur_size, new_isize;
5061 unsigned long invalid = 0;
5067 if (nfs_have_delegated_attributes(inode))
5069 @@ -1117,13 +1128,18 @@ static int nfs_check_inode_attributes(st
5070 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5073 + kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
5074 + kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
5075 + ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
5077 /* Have any file permissions changed? */
5078 if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5079 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5080 - if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5081 + if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5082 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5083 - if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5084 + if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5085 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5086 + /* maybe check for tag too? */
5088 /* Has the link count changed? */
5089 if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5090 @@ -1440,6 +1456,9 @@ static int nfs_update_inode(struct inode
5091 unsigned long invalid = 0;
5092 unsigned long now = jiffies;
5093 unsigned long save_cache_validity;
5098 dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5099 __func__, inode->i_sb->s_id, inode->i_ino,
5100 @@ -1541,6 +1560,9 @@ static int nfs_update_inode(struct inode
5101 | NFS_INO_REVAL_PAGECACHE
5102 | NFS_INO_REVAL_FORCED);
5104 + kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5105 + kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5106 + ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
5108 if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5109 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5110 @@ -1583,6 +1605,10 @@ static int nfs_update_inode(struct inode
5111 | NFS_INO_INVALID_ACL
5112 | NFS_INO_REVAL_FORCED);
5114 + inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5115 + inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5116 + inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
5118 if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5119 if (inode->i_nlink != fattr->nlink) {
5120 invalid |= NFS_INO_INVALID_ATTR;
5121 diff -NurpP --minimal linux-3.13.10/fs/nfs/nfs3xdr.c linux-3.13.10-vs2.3.6.11/fs/nfs/nfs3xdr.c
5122 --- linux-3.13.10/fs/nfs/nfs3xdr.c 2013-05-31 13:45:24.000000000 +0000
5123 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/nfs3xdr.c 2014-01-31 20:38:03.000000000 +0000
5125 #include <linux/nfs3.h>
5126 #include <linux/nfs_fs.h>
5127 #include <linux/nfsacl.h>
5128 +#include <linux/vs_tag.h>
5129 #include "internal.h"
5131 #define NFSDBG_FACILITY NFSDBG_XDR
5132 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5136 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5137 +static void encode_sattr3(struct xdr_stream *xdr,
5138 + const struct iattr *attr, int tag)
5142 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5146 - if (attr->ia_valid & ATTR_UID) {
5147 + if (attr->ia_valid & ATTR_UID ||
5148 + (tag && (attr->ia_valid & ATTR_TAG))) {
5150 - *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5151 + *p++ = cpu_to_be32(from_kuid(&init_user_ns,
5152 + TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
5156 - if (attr->ia_valid & ATTR_GID) {
5157 + if (attr->ia_valid & ATTR_GID ||
5158 + (tag && (attr->ia_valid & ATTR_TAG))) {
5160 - *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5161 + *p++ = cpu_to_be32(from_kgid(&init_user_ns,
5162 + TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
5166 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5167 const struct nfs3_sattrargs *args)
5169 encode_nfs_fh3(xdr, args->fh);
5170 - encode_sattr3(xdr, args->sattr);
5171 + encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5172 encode_sattrguard3(xdr, args);
5175 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5178 static void encode_createhow3(struct xdr_stream *xdr,
5179 - const struct nfs3_createargs *args)
5180 + const struct nfs3_createargs *args, int tag)
5182 encode_uint32(xdr, args->createmode);
5183 switch (args->createmode) {
5184 case NFS3_CREATE_UNCHECKED:
5185 case NFS3_CREATE_GUARDED:
5186 - encode_sattr3(xdr, args->sattr);
5187 + encode_sattr3(xdr, args->sattr, tag);
5189 case NFS3_CREATE_EXCLUSIVE:
5190 encode_createverf3(xdr, args->verifier);
5191 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5192 const struct nfs3_createargs *args)
5194 encode_diropargs3(xdr, args->fh, args->name, args->len);
5195 - encode_createhow3(xdr, args);
5196 + encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5200 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5201 const struct nfs3_mkdirargs *args)
5203 encode_diropargs3(xdr, args->fh, args->name, args->len);
5204 - encode_sattr3(xdr, args->sattr);
5205 + encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5209 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5212 static void encode_symlinkdata3(struct xdr_stream *xdr,
5213 - const struct nfs3_symlinkargs *args)
5214 + const struct nfs3_symlinkargs *args, int tag)
5216 - encode_sattr3(xdr, args->sattr);
5217 + encode_sattr3(xdr, args->sattr, tag);
5218 encode_nfspath3(xdr, args->pages, args->pathlen);
5221 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5222 const struct nfs3_symlinkargs *args)
5224 encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5225 - encode_symlinkdata3(xdr, args);
5226 + encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5230 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5233 static void encode_devicedata3(struct xdr_stream *xdr,
5234 - const struct nfs3_mknodargs *args)
5235 + const struct nfs3_mknodargs *args, int tag)
5237 - encode_sattr3(xdr, args->sattr);
5238 + encode_sattr3(xdr, args->sattr, tag);
5239 encode_specdata3(xdr, args->rdev);
5242 static void encode_mknoddata3(struct xdr_stream *xdr,
5243 - const struct nfs3_mknodargs *args)
5244 + const struct nfs3_mknodargs *args, int tag)
5246 encode_ftype3(xdr, args->type);
5247 switch (args->type) {
5250 - encode_devicedata3(xdr, args);
5251 + encode_devicedata3(xdr, args, tag);
5255 - encode_sattr3(xdr, args->sattr);
5256 + encode_sattr3(xdr, args->sattr, tag);
5260 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5261 const struct nfs3_mknodargs *args)
5263 encode_diropargs3(xdr, args->fh, args->name, args->len);
5264 - encode_mknoddata3(xdr, args);
5265 + encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5269 diff -NurpP --minimal linux-3.13.10/fs/nfs/super.c linux-3.13.10-vs2.3.6.11/fs/nfs/super.c
5270 --- linux-3.13.10/fs/nfs/super.c 2014-01-22 20:39:06.000000000 +0000
5271 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/super.c 2014-01-31 20:38:03.000000000 +0000
5273 #include <linux/parser.h>
5274 #include <linux/nsproxy.h>
5275 #include <linux/rcupdate.h>
5276 +#include <linux/vs_tag.h>
5278 #include <asm/uaccess.h>
5280 @@ -103,6 +104,7 @@ enum {
5286 /* Mount options that take string arguments */
5288 @@ -115,6 +117,9 @@ enum {
5289 /* Special mount options */
5290 Opt_userspace, Opt_deprecated, Opt_sloppy,
5292 + /* Linux-VServer tagging options */
5293 + Opt_tag, Opt_notag,
5298 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5299 { Opt_fscache_uniq, "fsc=%s" },
5300 { Opt_local_lock, "local_lock=%s" },
5302 + { Opt_tag, "tag" },
5303 + { Opt_notag, "notag" },
5304 + { Opt_tagid, "tagid=%u" },
5306 /* The following needs to be listed after all other options */
5307 { Opt_nfsvers, "v%s" },
5309 @@ -638,6 +647,7 @@ static void nfs_show_mount_options(struc
5310 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5311 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5312 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5313 + { NFS_MOUNT_TAGGED, ",tag", "" },
5316 const struct proc_nfs_info *nfs_infop;
5317 @@ -1321,6 +1331,14 @@ static int nfs_parse_mount_options(char
5318 case Opt_nomigration:
5319 mnt->options &= NFS_OPTION_MIGRATION;
5321 +#ifndef CONFIG_TAGGING_NONE
5323 + mnt->flags |= NFS_MOUNT_TAGGED;
5326 + mnt->flags &= ~NFS_MOUNT_TAGGED;
5331 * options that take numeric values
5332 @@ -1407,6 +1425,12 @@ static int nfs_parse_mount_options(char
5333 goto out_invalid_value;
5334 mnt->minorversion = option;
5336 +#ifdef CONFIG_PROPAGATE
5339 + nfs_data.flags |= NFS_MOUNT_TAGGED;
5344 * options that take text values
5345 diff -NurpP --minimal linux-3.13.10/fs/nfsd/auth.c linux-3.13.10-vs2.3.6.11/fs/nfsd/auth.c
5346 --- linux-3.13.10/fs/nfsd/auth.c 2013-05-31 13:45:24.000000000 +0000
5347 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/auth.c 2014-01-31 20:38:03.000000000 +0000
5350 #include <linux/sched.h>
5351 #include <linux/user_namespace.h>
5352 +#include <linux/vs_tag.h>
5356 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5358 new->fsuid = rqstp->rq_cred.cr_uid;
5359 new->fsgid = rqstp->rq_cred.cr_gid;
5360 + /* FIXME: this desperately needs a tag :)
5361 + new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5364 rqgi = rqstp->rq_cred.cr_group_info;
5366 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfs3xdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs3xdr.c
5367 --- linux-3.13.10/fs/nfsd/nfs3xdr.c 2013-05-31 13:45:24.000000000 +0000
5368 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs3xdr.c 2014-01-31 20:38:03.000000000 +0000
5371 #include <linux/namei.h>
5372 #include <linux/sunrpc/svc_xprt.h>
5373 +#include <linux/vs_tag.h>
5377 @@ -98,6 +99,8 @@ static __be32 *
5378 decode_sattr3(__be32 *p, struct iattr *iap)
5381 + kuid_t kuid = GLOBAL_ROOT_UID;
5382 + kgid_t kgid = GLOBAL_ROOT_GID;
5386 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5387 iap->ia_mode = ntohl(*p++);
5390 - iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5391 + kuid = make_kuid(&init_user_ns, ntohl(*p++));
5392 if (uid_valid(iap->ia_uid))
5393 iap->ia_valid |= ATTR_UID;
5396 - iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5397 + kgid = make_kgid(&init_user_ns, ntohl(*p++));
5398 if (gid_valid(iap->ia_gid))
5399 iap->ia_valid |= ATTR_GID;
5401 + iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5402 + iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5403 + iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5407 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5408 *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5409 *p++ = htonl((u32) stat->mode);
5410 *p++ = htonl((u32) stat->nlink);
5411 - *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5412 - *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5413 + *p++ = htonl((u32) from_kuid(&init_user_ns,
5414 + TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5415 + stat->uid, stat->tag)));
5416 + *p++ = htonl((u32) from_kgid(&init_user_ns,
5417 + TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5418 + stat->gid, stat->tag)));
5419 if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5420 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5422 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfs4xdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs4xdr.c
5423 --- linux-3.13.10/fs/nfsd/nfs4xdr.c 2014-01-22 20:39:06.000000000 +0000
5424 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs4xdr.c 2014-01-31 20:38:03.000000000 +0000
5426 #include <linux/utsname.h>
5427 #include <linux/pagemap.h>
5428 #include <linux/sunrpc/svcauth_gss.h>
5429 +#include <linux/vs_tag.h>
5433 @@ -2430,10 +2431,14 @@ out_acl:
5434 WRITE32(stat.nlink);
5436 if (bmval1 & FATTR4_WORD1_OWNER) {
5437 - status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5438 + status = nfsd4_encode_user(rqstp,
5439 + TAGINO_KUID(DX_TAG(dentry->d_inode),
5440 + stat.uid, stat.tag), &p, &buflen);
5444 if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5445 - status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5446 + status = nfsd4_encode_group(rqstp,
5447 + TAGINO_KGID(DX_TAG(dentry->d_inode),
5448 + stat.gid, stat.tag), &p, &buflen);
5452 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfsxdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfsxdr.c
5453 --- linux-3.13.10/fs/nfsd/nfsxdr.c 2013-05-31 13:45:24.000000000 +0000
5454 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfsxdr.c 2014-01-31 20:38:03.000000000 +0000
5459 +#include <linux/vs_tag.h>
5461 #define NFSDDBG_FACILITY NFSDDBG_XDR
5463 @@ -89,6 +90,8 @@ static __be32 *
5464 decode_sattr(__be32 *p, struct iattr *iap)
5467 + kuid_t kuid = GLOBAL_ROOT_UID;
5468 + kgid_t kgid = GLOBAL_ROOT_GID;
5472 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5475 if ((tmp = ntohl(*p++)) != (u32)-1) {
5476 - iap->ia_uid = make_kuid(&init_user_ns, tmp);
5477 + kuid = make_kuid(&init_user_ns, tmp);
5478 if (uid_valid(iap->ia_uid))
5479 iap->ia_valid |= ATTR_UID;
5481 if ((tmp = ntohl(*p++)) != (u32)-1) {
5482 - iap->ia_gid = make_kgid(&init_user_ns, tmp);
5483 + kgid = make_kgid(&init_user_ns, tmp);
5484 if (gid_valid(iap->ia_gid))
5485 iap->ia_valid |= ATTR_GID;
5487 + iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5488 + iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5489 + iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5490 if ((tmp = ntohl(*p++)) != (u32)-1) {
5491 iap->ia_valid |= ATTR_SIZE;
5493 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5494 *p++ = htonl(nfs_ftypes[type >> 12]);
5495 *p++ = htonl((u32) stat->mode);
5496 *p++ = htonl((u32) stat->nlink);
5497 - *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5498 - *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5499 + *p++ = htonl((u32) from_kuid(&init_user_ns,
5500 + TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5501 + *p++ = htonl((u32) from_kgid(&init_user_ns,
5502 + TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5504 if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5505 *p++ = htonl(NFS_MAXPATHLEN);
5506 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/dlmglue.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.c
5507 --- linux-3.13.10/fs/ocfs2/dlmglue.c 2014-01-22 20:39:07.000000000 +0000
5508 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.c 2014-01-31 20:38:03.000000000 +0000
5509 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5510 lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5511 lvb->lvb_iuid = cpu_to_be32(i_uid_read(inode));
5512 lvb->lvb_igid = cpu_to_be32(i_gid_read(inode));
5513 + lvb->lvb_itag = cpu_to_be16(i_tag_read(inode));
5514 lvb->lvb_imode = cpu_to_be16(inode->i_mode);
5515 lvb->lvb_inlink = cpu_to_be16(inode->i_nlink);
5516 lvb->lvb_iatime_packed =
5517 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5519 i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5520 i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5521 + i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5522 inode->i_mode = be16_to_cpu(lvb->lvb_imode);
5523 set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5524 ocfs2_unpack_timespec(&inode->i_atime,
5525 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/dlmglue.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.h
5526 --- linux-3.13.10/fs/ocfs2/dlmglue.h 2012-12-11 03:30:57.000000000 +0000
5527 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.h 2014-01-31 20:38:03.000000000 +0000
5528 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5531 __be32 lvb_igeneration;
5532 - __be32 lvb_reserved2;
5534 + __be16 lvb_reserved2;
5537 #define OCFS2_QINFO_LVB_VERSION 1
5538 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/file.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/file.c
5539 --- linux-3.13.10/fs/ocfs2/file.c 2014-04-17 01:12:32.000000000 +0000
5540 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/file.c 2014-04-17 01:17:10.000000000 +0000
5541 @@ -1119,7 +1119,7 @@ int ocfs2_setattr(struct dentry *dentry,
5542 attr->ia_valid &= ~ATTR_SIZE;
5544 #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5545 - | ATTR_GID | ATTR_UID | ATTR_MODE)
5546 + | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5547 if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5550 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/inode.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.c
5551 --- linux-3.13.10/fs/ocfs2/inode.c 2014-01-22 20:39:07.000000000 +0000
5552 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.c 2014-01-31 20:38:03.000000000 +0000
5554 #include <linux/highmem.h>
5555 #include <linux/pagemap.h>
5556 #include <linux/quotaops.h>
5557 +#include <linux/vs_tag.h>
5559 #include <asm/byteorder.h>
5561 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5563 unsigned int flags = OCFS2_I(inode)->ip_attr;
5565 - inode->i_flags &= ~(S_IMMUTABLE |
5566 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5567 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5569 if (flags & OCFS2_IMMUTABLE_FL)
5570 inode->i_flags |= S_IMMUTABLE;
5571 + if (flags & OCFS2_IXUNLINK_FL)
5572 + inode->i_flags |= S_IXUNLINK;
5574 if (flags & OCFS2_SYNC_FL)
5575 inode->i_flags |= S_SYNC;
5576 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5577 inode->i_flags |= S_NOATIME;
5578 if (flags & OCFS2_DIRSYNC_FL)
5579 inode->i_flags |= S_DIRSYNC;
5581 + inode->i_vflags &= ~(V_BARRIER | V_COW);
5583 + if (flags & OCFS2_BARRIER_FL)
5584 + inode->i_vflags |= V_BARRIER;
5585 + if (flags & OCFS2_COW_FL)
5586 + inode->i_vflags |= V_COW;
5589 /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5590 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5592 unsigned int flags = oi->vfs_inode.i_flags;
5593 + unsigned int vflags = oi->vfs_inode.i_vflags;
5595 + oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5596 + OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5597 + OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5598 + OCFS2_BARRIER_FL | OCFS2_COW_FL);
5600 + if (flags & S_IMMUTABLE)
5601 + oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5602 + if (flags & S_IXUNLINK)
5603 + oi->ip_attr |= OCFS2_IXUNLINK_FL;
5605 - oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5606 - OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5608 oi->ip_attr |= OCFS2_SYNC_FL;
5609 if (flags & S_APPEND)
5610 oi->ip_attr |= OCFS2_APPEND_FL;
5611 - if (flags & S_IMMUTABLE)
5612 - oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5613 if (flags & S_NOATIME)
5614 oi->ip_attr |= OCFS2_NOATIME_FL;
5615 if (flags & S_DIRSYNC)
5616 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5618 + if (vflags & V_BARRIER)
5619 + oi->ip_attr |= OCFS2_BARRIER_FL;
5620 + if (vflags & V_COW)
5621 + oi->ip_attr |= OCFS2_COW_FL;
5624 struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5625 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5626 struct super_block *sb;
5627 struct ocfs2_super *osb;
5634 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5635 inode->i_generation = le32_to_cpu(fe->i_generation);
5636 inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5637 inode->i_mode = le16_to_cpu(fe->i_mode);
5638 - i_uid_write(inode, le32_to_cpu(fe->i_uid));
5639 - i_gid_write(inode, le32_to_cpu(fe->i_gid));
5640 + uid = le32_to_cpu(fe->i_uid);
5641 + gid = le32_to_cpu(fe->i_gid);
5642 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5643 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5644 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5645 + /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5647 /* Fast symlinks will have i_size but no allocated clusters. */
5648 if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5649 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/inode.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.h
5650 --- linux-3.13.10/fs/ocfs2/inode.h 2013-07-14 17:01:29.000000000 +0000
5651 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.h 2014-01-31 20:38:03.000000000 +0000
5652 @@ -152,6 +152,7 @@ struct buffer_head *ocfs2_bread(struct i
5654 void ocfs2_set_inode_flags(struct inode *inode);
5655 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5656 +int ocfs2_sync_flags(struct inode *inode, int, int);
5658 static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5660 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/ioctl.c
5661 --- linux-3.13.10/fs/ocfs2/ioctl.c 2013-11-25 15:47:00.000000000 +0000
5662 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ioctl.c 2014-01-31 20:38:03.000000000 +0000
5663 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5667 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5668 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5670 + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5671 + struct buffer_head *bh = NULL;
5672 + handle_t *handle = NULL;
5675 + status = ocfs2_inode_lock(inode, &bh, 1);
5677 + mlog_errno(status);
5680 + handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5681 + if (IS_ERR(handle)) {
5682 + status = PTR_ERR(handle);
5683 + mlog_errno(status);
5687 + inode->i_flags = flags;
5688 + inode->i_vflags = vflags;
5689 + ocfs2_get_inode_flags(OCFS2_I(inode));
5691 + status = ocfs2_mark_inode_dirty(handle, inode, bh);
5693 + mlog_errno(status);
5695 + ocfs2_commit_trans(osb, handle);
5697 + ocfs2_inode_unlock(inode, 1);
5702 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5705 struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5706 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5710 + if (IS_BARRIER(inode)) {
5711 + vxwprintk_task(1, "messing with the barrier.");
5715 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5716 if (IS_ERR(handle)) {
5717 status = PTR_ERR(handle);
5718 @@ -881,6 +920,7 @@ bail:
5723 long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5725 struct inode *inode = file_inode(filp);
5726 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/namei.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/namei.c
5727 --- linux-3.13.10/fs/ocfs2/namei.c 2014-01-22 20:39:07.000000000 +0000
5728 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/namei.c 2014-01-31 20:38:03.000000000 +0000
5730 #include <linux/slab.h>
5731 #include <linux/highmem.h>
5732 #include <linux/quotaops.h>
5733 +#include <linux/vs_tag.h>
5735 #include <cluster/masklog.h>
5737 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5738 struct ocfs2_dinode *fe = NULL;
5739 struct ocfs2_extent_list *fel;
5745 @@ -512,8 +514,13 @@ static int __ocfs2_mknod_locked(struct i
5746 fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5747 fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5748 fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5749 - fe->i_uid = cpu_to_le32(i_uid_read(inode));
5750 - fe->i_gid = cpu_to_le32(i_gid_read(inode));
5752 + ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5753 + fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5754 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5755 + fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5756 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5757 + inode->i_tag = ktag; /* is this correct? */
5758 fe->i_mode = cpu_to_le16(inode->i_mode);
5759 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5760 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5761 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ocfs2.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2.h
5762 --- linux-3.13.10/fs/ocfs2/ocfs2.h 2013-11-25 15:45:04.000000000 +0000
5763 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2.h 2014-01-31 20:38:03.000000000 +0000
5764 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5766 OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5767 OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5768 + OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5771 #define OCFS2_OSB_SOFT_RO 0x0001
5772 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ocfs2_fs.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2_fs.h
5773 --- linux-3.13.10/fs/ocfs2/ocfs2_fs.h 2012-12-11 03:30:57.000000000 +0000
5774 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2_fs.h 2014-01-31 20:38:03.000000000 +0000
5775 @@ -266,6 +266,11 @@
5776 #define OCFS2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
5777 #define OCFS2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
5779 +#define OCFS2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
5781 +#define OCFS2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
5782 +#define OCFS2_COW_FL FS_COW_FL /* Copy on Write marker */
5784 #define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
5785 #define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
5787 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/super.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/super.c
5788 --- linux-3.13.10/fs/ocfs2/super.c 2014-01-22 20:39:07.000000000 +0000
5789 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/super.c 2014-01-31 20:38:03.000000000 +0000
5790 @@ -185,6 +185,7 @@ enum {
5794 + Opt_tag, Opt_notag, Opt_tagid,
5798 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5799 {Opt_coherency_full, "coherency=full"},
5800 {Opt_resv_level, "resv_level=%u"},
5801 {Opt_dir_resv_level, "dir_resv_level=%u"},
5803 + {Opt_notag, "notag"},
5804 + {Opt_tagid, "tagid=%u"},
5808 @@ -661,6 +665,13 @@ static int ocfs2_remount(struct super_bl
5812 + if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5813 + (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5815 + mlog(ML_ERROR, "Cannot change tagging on remount\n");
5819 /* We're going to/from readonly mode. */
5820 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5821 /* Disable quota accounting before remounting RO */
5822 @@ -1176,6 +1187,9 @@ static int ocfs2_fill_super(struct super
5824 ocfs2_complete_mount_recovery(osb);
5826 + if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5827 + sb->s_flags |= MS_TAGGED;
5829 if (ocfs2_mount_local(osb))
5830 snprintf(nodestr, sizeof(nodestr), "local");
5832 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
5833 option < OCFS2_MAX_RESV_LEVEL)
5834 mopt->dir_resv_level = option;
5836 +#ifndef CONFIG_TAGGING_NONE
5838 + mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5841 + mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5844 +#ifdef CONFIG_PROPAGATE
5847 + mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5852 "Unrecognized mount option \"%s\" "
5853 diff -NurpP --minimal linux-3.13.10/fs/open.c linux-3.13.10-vs2.3.6.11/fs/open.c
5854 --- linux-3.13.10/fs/open.c 2014-01-22 20:39:07.000000000 +0000
5855 +++ linux-3.13.10-vs2.3.6.11/fs/open.c 2014-01-31 20:38:03.000000000 +0000
5857 #include <linux/ima.h>
5858 #include <linux/dnotify.h>
5859 #include <linux/compat.h>
5860 +#include <linux/vs_base.h>
5861 +#include <linux/vs_limit.h>
5862 +#include <linux/vs_tag.h>
5863 +#include <linux/vs_cowbl.h>
5864 +#include <linux/vserver/dlimit.h>
5866 #include "internal.h"
5868 @@ -68,6 +73,11 @@ long vfs_truncate(struct path *path, lof
5869 struct inode *inode;
5872 +#ifdef CONFIG_VSERVER_COWBL
5873 + error = cow_check_and_break(path);
5877 inode = path->dentry->d_inode;
5879 /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5880 @@ -511,6 +521,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5881 unsigned int lookup_flags = LOOKUP_FOLLOW;
5883 error = user_path_at(dfd, filename, lookup_flags, &path);
5884 +#ifdef CONFIG_VSERVER_COWBL
5886 + error = cow_check_and_break(&path);
5892 error = chmod_common(&path, mode);
5894 @@ -544,13 +561,15 @@ static int chown_common(struct path *pat
5895 if (!uid_valid(uid))
5897 newattrs.ia_valid |= ATTR_UID;
5898 - newattrs.ia_uid = uid;
5899 + newattrs.ia_uid = make_kuid(&init_user_ns,
5900 + dx_map_uid(user));
5902 if (group != (gid_t) -1) {
5903 if (!gid_valid(gid))
5905 newattrs.ia_valid |= ATTR_GID;
5906 - newattrs.ia_gid = gid;
5907 + newattrs.ia_gid = make_kgid(&init_user_ns,
5908 + dx_map_gid(group));
5910 if (!S_ISDIR(inode->i_mode))
5911 newattrs.ia_valid |=
5912 @@ -589,6 +608,18 @@ retry:
5913 error = mnt_want_write(path.mnt);
5916 +#ifdef CONFIG_VSERVER_COWBL
5917 + error = cow_check_and_break(&path);
5920 +#ifdef CONFIG_VSERVER_COWBL
5921 + error = cow_check_and_break(&path);
5924 +#ifdef CONFIG_VSERVER_COWBL
5925 + error = cow_check_and_break(&path);
5928 error = chown_common(&path, user, group);
5929 mnt_drop_write(path.mnt);
5931 diff -NurpP --minimal linux-3.13.10/fs/proc/array.c linux-3.13.10-vs2.3.6.11/fs/proc/array.c
5932 --- linux-3.13.10/fs/proc/array.c 2014-01-22 20:39:07.000000000 +0000
5933 +++ linux-3.13.10-vs2.3.6.11/fs/proc/array.c 2014-02-01 01:44:54.000000000 +0000
5935 #include <linux/ptrace.h>
5936 #include <linux/tracehook.h>
5937 #include <linux/user_namespace.h>
5938 +#include <linux/vs_context.h>
5939 +#include <linux/vs_network.h>
5941 #include <asm/pgtable.h>
5942 #include <asm/processor.h>
5943 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
5945 ppid = pid_alive(p) ?
5946 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5947 + if (unlikely(vx_current_initpid(p->pid)))
5952 struct task_struct *tracer = ptrace_parent(p);
5953 @@ -299,7 +304,7 @@ static inline void task_sig(struct seq_f
5956 static void render_cap_t(struct seq_file *m, const char *header,
5958 + struct vx_info *vxi, kernel_cap_t *a)
5962 @@ -333,10 +338,11 @@ static inline void task_cap(struct seq_f
5963 NORM_CAPS(cap_effective);
5964 NORM_CAPS(cap_bset);
5966 - render_cap_t(m, "CapInh:\t", &cap_inheritable);
5967 - render_cap_t(m, "CapPrm:\t", &cap_permitted);
5968 - render_cap_t(m, "CapEff:\t", &cap_effective);
5969 - render_cap_t(m, "CapBnd:\t", &cap_bset);
5970 + /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5971 + render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5972 + render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5973 + render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5974 + render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
5977 static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
5978 @@ -365,6 +371,43 @@ static void task_cpus_allowed(struct seq
5982 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
5983 + struct pid *pid, struct task_struct *task)
5985 + seq_printf(m, "Proxy:\t%p(%c)\n"
5993 + (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
5994 + atomic_read(&task->nsproxy->count),
5995 + task->nsproxy->uts_ns,
5996 + (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
5997 + task->nsproxy->ipc_ns,
5998 + (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
5999 + task->nsproxy->mnt_ns,
6000 + (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6001 + task->nsproxy->pid_ns_for_children,
6002 + (task->nsproxy->pid_ns_for_children ==
6003 + init_task.nsproxy->pid_ns_for_children ? 'I' : '-'),
6004 + task->nsproxy->net_ns,
6005 + (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6009 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6011 + if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6014 + seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6015 + seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6019 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6020 struct pid *pid, struct task_struct *task)
6022 @@ -382,6 +425,7 @@ int proc_pid_status(struct seq_file *m,
6023 task_seccomp(m, task);
6024 task_cpus_allowed(m, task);
6025 cpuset_task_status_allowed(m, task);
6026 + task_vs_id(m, task);
6027 task_context_switch_counts(m, task);
6030 @@ -491,6 +535,17 @@ static int do_task_stat(struct seq_file
6031 /* convert nsec -> ticks */
6032 start_time = nsec_to_clock_t(start_time);
6034 + /* fixup start time for virt uptime */
6035 + if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6036 + unsigned long long bias =
6037 + current->vx_info->cvirt.bias_clock;
6039 + if (start_time > bias)
6040 + start_time -= bias;
6045 seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6046 seq_put_decimal_ll(m, ' ', ppid);
6047 seq_put_decimal_ll(m, ' ', pgid);
6048 diff -NurpP --minimal linux-3.13.10/fs/proc/base.c linux-3.13.10-vs2.3.6.11/fs/proc/base.c
6049 --- linux-3.13.10/fs/proc/base.c 2014-04-17 01:12:32.000000000 +0000
6050 +++ linux-3.13.10-vs2.3.6.11/fs/proc/base.c 2014-04-17 01:17:10.000000000 +0000
6052 #include <linux/slab.h>
6053 #include <linux/flex_array.h>
6054 #include <linux/posix-timers.h>
6055 +#include <linux/vs_context.h>
6056 +#include <linux/vs_network.h>
6057 #ifdef CONFIG_HARDWALL
6058 #include <asm/hardwall.h>
6060 @@ -976,11 +978,15 @@ static ssize_t oom_adj_write(struct file
6061 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6063 if (oom_adj < task->signal->oom_score_adj &&
6064 - !capable(CAP_SYS_RESOURCE)) {
6065 + !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6070 + /* prevent guest processes from circumventing the oom killer */
6071 + if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6072 + oom_adj = OOM_ADJUST_MIN;
6075 * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6076 * /proc/pid/oom_score_adj instead.
6077 @@ -1565,6 +1571,8 @@ struct inode *proc_pid_make_inode(struct
6078 inode->i_gid = cred->egid;
6081 + /* procfs is xid tagged */
6082 + i_tag_write(inode, (vtag_t)vx_task_xid(task));
6083 security_task_to_inode(task, inode);
6086 @@ -1610,6 +1618,8 @@ int pid_getattr(struct vfsmount *mnt, st
6090 +static unsigned name_to_int(struct dentry *dentry);
6093 * Exceptional case: normally we are not allowed to unhash a busy
6094 * directory. In this case, however, we can do it - no aliasing problems
6095 @@ -1638,6 +1648,12 @@ int pid_revalidate(struct dentry *dentry
6096 task = get_proc_task(inode);
6099 + unsigned pid = name_to_int(dentry);
6101 + if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6102 + put_task_struct(task);
6105 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6106 task_dumpable(task)) {
6108 @@ -1654,6 +1670,7 @@ int pid_revalidate(struct dentry *dentry
6109 put_task_struct(task);
6116 @@ -2173,6 +2190,13 @@ static struct dentry *proc_pident_lookup
6120 + /* TODO: maybe we can come up with a generic approach? */
6121 + if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6122 + (dentry->d_name.len == 5) &&
6123 + (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6124 + !memcmp(dentry->d_name.name, "ninfo", 5)))
6128 * Yes, it does not scale. And it should not. Don't add
6129 * new entries into /proc/<tgid>/ without very good reasons.
6130 @@ -2569,6 +2593,9 @@ static int proc_pid_personality(struct s
6131 static const struct file_operations proc_task_operations;
6132 static const struct inode_operations proc_task_inode_operations;
6134 +extern int proc_pid_vx_info(struct task_struct *, char *);
6135 +extern int proc_pid_nx_info(struct task_struct *, char *);
6137 static const struct pid_entry tgid_base_stuff[] = {
6138 DIR("task", S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6139 DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6140 @@ -2635,6 +2662,8 @@ static const struct pid_entry tgid_base_
6141 #ifdef CONFIG_CGROUPS
6142 REG("cgroup", S_IRUGO, proc_cgroup_operations),
6144 + INF("vinfo", S_IRUGO, proc_pid_vx_info),
6145 + INF("ninfo", S_IRUGO, proc_pid_nx_info),
6146 INF("oom_score", S_IRUGO, proc_oom_score),
6147 REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6148 REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6149 @@ -2847,7 +2876,7 @@ retry:
6151 pid = find_ge_pid(iter.tgid, ns);
6153 - iter.tgid = pid_nr_ns(pid, ns);
6154 + iter.tgid = pid_unmapped_nr_ns(pid, ns);
6155 iter.task = pid_task(pid, PIDTYPE_PID);
6156 /* What we to know is if the pid we have find is the
6157 * pid of a thread_group_leader. Testing for task
6158 @@ -2900,8 +2929,10 @@ int proc_pid_readdir(struct file *file,
6159 if (!has_pid_permissions(ns, iter.task, 2))
6162 - len = snprintf(name, sizeof(name), "%d", iter.tgid);
6163 + len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6164 ctx->pos = iter.tgid + TGID_OFFSET;
6165 + if (!vx_proc_task_visible(iter.task))
6167 if (!proc_fill_cache(file, ctx, name, len,
6168 proc_pid_instantiate, iter.task, NULL)) {
6169 put_task_struct(iter.task);
6170 @@ -2994,6 +3025,7 @@ static const struct pid_entry tid_base_s
6171 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
6172 REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6174 + ONE("nsproxy", S_IRUGO, proc_pid_nsproxy),
6177 static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
6178 @@ -3060,6 +3092,8 @@ static struct dentry *proc_task_lookup(s
6179 tid = name_to_int(dentry);
6182 + if (vx_current_initpid(tid))
6185 ns = dentry->d_sb->s_fs_info;
6187 diff -NurpP --minimal linux-3.13.10/fs/proc/generic.c linux-3.13.10-vs2.3.6.11/fs/proc/generic.c
6188 --- linux-3.13.10/fs/proc/generic.c 2014-01-22 20:39:07.000000000 +0000
6189 +++ linux-3.13.10-vs2.3.6.11/fs/proc/generic.c 2014-02-01 00:07:40.000000000 +0000
6191 #include <linux/bitops.h>
6192 #include <linux/spinlock.h>
6193 #include <linux/completion.h>
6194 +#include <linux/vserver/inode.h>
6195 #include <asm/uaccess.h>
6197 #include "internal.h"
6198 @@ -187,6 +188,8 @@ struct dentry *proc_lookup_de(struct pro
6199 for (de = de->subdir; de ; de = de->next) {
6200 if (de->namelen != dentry->d_name.len)
6202 + if (!vx_hide_check(0, de->vx_flags))
6204 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6206 spin_unlock(&proc_subdir_lock);
6207 @@ -195,6 +198,8 @@ struct dentry *proc_lookup_de(struct pro
6208 return ERR_PTR(-ENOMEM);
6209 d_set_d_op(dentry, &simple_dentry_operations);
6210 d_add(dentry, inode);
6211 + /* generic proc entries belong to the host */
6212 + i_tag_write(inode, 0);
6216 @@ -242,6 +247,9 @@ int proc_readdir_de(struct proc_dir_entr
6218 struct proc_dir_entry *next;
6221 + if (!vx_hide_check(0, de->vx_flags))
6223 spin_unlock(&proc_subdir_lock);
6224 if (!dir_emit(ctx, de->name, de->namelen,
6225 de->low_ino, de->mode >> 12)) {
6226 @@ -249,6 +257,7 @@ int proc_readdir_de(struct proc_dir_entr
6229 spin_lock(&proc_subdir_lock);
6234 @@ -355,6 +364,7 @@ static struct proc_dir_entry *__proc_cre
6238 + ent->vx_flags = IATTR_PROC_DEFAULT;
6239 atomic_set(&ent->count, 1);
6240 spin_lock_init(&ent->pde_unload_lock);
6241 INIT_LIST_HEAD(&ent->pde_openers);
6242 @@ -378,7 +388,8 @@ struct proc_dir_entry *proc_symlink(cons
6248 + ent->vx_flags = IATTR_PROC_SYMLINK;
6252 diff -NurpP --minimal linux-3.13.10/fs/proc/inode.c linux-3.13.10-vs2.3.6.11/fs/proc/inode.c
6253 --- linux-3.13.10/fs/proc/inode.c 2014-01-22 20:39:07.000000000 +0000
6254 +++ linux-3.13.10-vs2.3.6.11/fs/proc/inode.c 2014-01-31 20:38:03.000000000 +0000
6255 @@ -415,6 +415,8 @@ struct inode *proc_get_inode(struct supe
6256 inode->i_uid = de->uid;
6257 inode->i_gid = de->gid;
6260 + PROC_I(inode)->vx_flags = de->vx_flags;
6262 inode->i_size = de->size;
6264 diff -NurpP --minimal linux-3.13.10/fs/proc/internal.h linux-3.13.10-vs2.3.6.11/fs/proc/internal.h
6265 --- linux-3.13.10/fs/proc/internal.h 2013-11-25 15:45:04.000000000 +0000
6266 +++ linux-3.13.10-vs2.3.6.11/fs/proc/internal.h 2014-01-31 20:38:03.000000000 +0000
6268 #include <linux/spinlock.h>
6269 #include <linux/atomic.h>
6270 #include <linux/binfmts.h>
6271 +#include <linux/vs_pid.h>
6273 struct ctl_table_header;
6275 @@ -35,6 +36,7 @@ struct proc_dir_entry {
6281 const struct inode_operations *proc_iops;
6282 const struct file_operations *proc_fops;
6283 @@ -50,16 +52,23 @@ struct proc_dir_entry {
6291 int (*proc_get_link)(struct dentry *, struct path *);
6292 int (*proc_read)(struct task_struct *task, char *page);
6293 int (*proc_show)(struct seq_file *m,
6294 struct pid_namespace *ns, struct pid *pid,
6295 struct task_struct *task);
6296 + int (*proc_vs_read)(char *page);
6297 + int (*proc_vxi_read)(struct vx_info *vxi, char *page);
6298 + int (*proc_nxi_read)(struct nx_info *nxi, char *page);
6306 struct proc_dir_entry *pde;
6307 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
6308 return PROC_I(inode)->pid;
6311 -static inline struct task_struct *get_proc_task(struct inode *inode)
6312 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6314 return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6317 +static inline struct task_struct *get_proc_task(struct inode *inode)
6319 + return vx_get_proc_task(inode, proc_pid(inode));
6322 static inline int task_dumpable(struct task_struct *task)
6325 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6326 struct pid *, struct task_struct *);
6327 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6328 struct pid *, struct task_struct *);
6329 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6330 + struct pid *pid, struct task_struct *task);
6334 diff -NurpP --minimal linux-3.13.10/fs/proc/loadavg.c linux-3.13.10-vs2.3.6.11/fs/proc/loadavg.c
6335 --- linux-3.13.10/fs/proc/loadavg.c 2012-12-11 03:30:57.000000000 +0000
6336 +++ linux-3.13.10-vs2.3.6.11/fs/proc/loadavg.c 2014-01-31 20:38:03.000000000 +0000
6339 static int loadavg_proc_show(struct seq_file *m, void *v)
6341 + unsigned long running;
6342 + unsigned int threads;
6343 unsigned long avnrun[3];
6345 get_avenrun(avnrun, FIXED_1/200, 0);
6347 + if (vx_flags(VXF_VIRT_LOAD, 0)) {
6348 + struct vx_info *vxi = current_vx_info();
6350 + running = atomic_read(&vxi->cvirt.nr_running);
6351 + threads = atomic_read(&vxi->cvirt.nr_threads);
6353 + running = nr_running();
6354 + threads = nr_threads;
6357 seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6358 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6359 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6360 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6361 - nr_running(), nr_threads,
6363 task_active_pid_ns(current)->last_pid);
6366 diff -NurpP --minimal linux-3.13.10/fs/proc/meminfo.c linux-3.13.10-vs2.3.6.11/fs/proc/meminfo.c
6367 --- linux-3.13.10/fs/proc/meminfo.c 2014-01-22 20:39:07.000000000 +0000
6368 +++ linux-3.13.10-vs2.3.6.11/fs/proc/meminfo.c 2014-01-31 20:38:03.000000000 +0000
6369 @@ -37,7 +37,8 @@ static int meminfo_proc_show(struct seq_
6371 committed = percpu_counter_read_positive(&vm_committed_as);
6373 - cached = global_page_state(NR_FILE_PAGES) -
6374 + cached = vx_flags(VXF_VIRT_MEM, 0) ?
6375 + vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6376 total_swapcache_pages() - i.bufferram;
6379 diff -NurpP --minimal linux-3.13.10/fs/proc/root.c linux-3.13.10-vs2.3.6.11/fs/proc/root.c
6380 --- linux-3.13.10/fs/proc/root.c 2013-11-25 15:47:00.000000000 +0000
6381 +++ linux-3.13.10-vs2.3.6.11/fs/proc/root.c 2014-02-01 00:02:11.000000000 +0000
6383 #include <linux/mount.h>
6384 #include <linux/pid_namespace.h>
6385 #include <linux/parser.h>
6386 +#include <linux/vserver/inode.h>
6388 #include "internal.h"
6390 +struct proc_dir_entry *proc_virtual;
6392 +extern void proc_vx_init(void);
6394 static int proc_test_super(struct super_block *sb, void *data)
6396 return sb->s_fs_info == data;
6397 @@ -114,7 +119,8 @@ static struct dentry *proc_mount(struct
6398 return ERR_PTR(-EPERM);
6400 /* Does the mounter have privilege over the pid namespace? */
6401 - if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
6402 + if (!vx_ns_capable(ns->user_ns,
6403 + CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6404 return ERR_PTR(-EPERM);
6407 @@ -188,6 +194,7 @@ void __init proc_root_init(void)
6409 proc_mkdir("bus", NULL);
6414 static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6415 @@ -249,6 +256,7 @@ struct proc_dir_entry proc_root = {
6416 .proc_iops = &proc_root_inode_operations,
6417 .proc_fops = &proc_root_operations,
6418 .parent = &proc_root,
6419 + .vx_flags = IATTR_ADMIN | IATTR_WATCH,
6423 diff -NurpP --minimal linux-3.13.10/fs/proc/self.c linux-3.13.10-vs2.3.6.11/fs/proc/self.c
6424 --- linux-3.13.10/fs/proc/self.c 2014-01-22 20:39:07.000000000 +0000
6425 +++ linux-3.13.10-vs2.3.6.11/fs/proc/self.c 2014-01-31 20:38:03.000000000 +0000
6427 #include <linux/namei.h>
6428 #include <linux/slab.h>
6429 #include <linux/pid_namespace.h>
6430 +#include <linux/vserver/inode.h>
6431 #include "internal.h"
6434 @@ -54,6 +55,8 @@ int proc_setup_self(struct super_block *
6435 self = d_alloc_name(s->s_root, "self");
6437 struct inode *inode = new_inode_pseudo(s);
6439 + // self->vx_flags = IATTR_PROC_SYMLINK;
6441 inode->i_ino = self_inum;
6442 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6443 diff -NurpP --minimal linux-3.13.10/fs/proc/stat.c linux-3.13.10-vs2.3.6.11/fs/proc/stat.c
6444 --- linux-3.13.10/fs/proc/stat.c 2013-07-14 17:01:29.000000000 +0000
6445 +++ linux-3.13.10-vs2.3.6.11/fs/proc/stat.c 2014-01-31 20:38:03.000000000 +0000
6447 #include <linux/slab.h>
6448 #include <linux/time.h>
6449 #include <linux/irqnr.h>
6450 +#include <linux/vserver/cvirt.h>
6451 #include <asm/cputime.h>
6452 #include <linux/tick.h>
6453 +#include <linux/cpuset.h>
6455 #ifndef arch_irq_stat_cpu
6456 #define arch_irq_stat_cpu(cpu) 0
6457 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6458 u64 sum_softirq = 0;
6459 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6460 struct timespec boottime;
6461 + cpumask_var_t cpus_allowed;
6462 + bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6464 user = nice = system = idle = iowait =
6465 irq = softirq = steal = 0;
6466 guest = guest_nice = 0;
6467 getboottime(&boottime);
6469 + if (vx_flags(VXF_VIRT_UPTIME, 0))
6470 + vx_vsi_boottime(&boottime);
6473 + cpuset_cpus_allowed(current, cpus_allowed);
6475 jif = boottime.tv_sec;
6477 for_each_possible_cpu(i) {
6478 + if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6481 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6482 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6483 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6484 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6487 for_each_online_cpu(i) {
6488 + if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6491 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6492 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6493 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6494 diff -NurpP --minimal linux-3.13.10/fs/proc/uptime.c linux-3.13.10-vs2.3.6.11/fs/proc/uptime.c
6495 --- linux-3.13.10/fs/proc/uptime.c 2013-11-25 15:45:04.000000000 +0000
6496 +++ linux-3.13.10-vs2.3.6.11/fs/proc/uptime.c 2014-01-31 20:38:03.000000000 +0000
6498 #include <linux/seq_file.h>
6499 #include <linux/time.h>
6500 #include <linux/kernel_stat.h>
6501 +#include <linux/vserver/cvirt.h>
6502 #include <asm/cputime.h>
6504 static int uptime_proc_show(struct seq_file *m, void *v)
6505 @@ -24,6 +25,10 @@ static int uptime_proc_show(struct seq_f
6506 nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6507 idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6510 + if (vx_flags(VXF_VIRT_UPTIME, 0))
6511 + vx_vsi_uptime(&uptime, &idle);
6513 seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6514 (unsigned long) uptime.tv_sec,
6515 (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6516 diff -NurpP --minimal linux-3.13.10/fs/proc_namespace.c linux-3.13.10-vs2.3.6.11/fs/proc_namespace.c
6517 --- linux-3.13.10/fs/proc_namespace.c 2014-01-22 20:39:07.000000000 +0000
6518 +++ linux-3.13.10-vs2.3.6.11/fs/proc_namespace.c 2014-02-25 12:43:16.000000000 +0000
6519 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6520 { MS_SYNCHRONOUS, ",sync" },
6521 { MS_DIRSYNC, ",dirsync" },
6522 { MS_MANDLOCK, ",mand" },
6523 + { MS_TAGGED, ",tag" },
6524 + { MS_NOTAGCHECK, ",notagcheck" },
6527 const struct proc_fs_info *fs_infop;
6528 @@ -80,6 +82,38 @@ static inline void mangle(struct seq_fil
6529 seq_escape(m, s, " \t\n\\");
6532 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6534 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6537 + struct dentry *point;
6538 + struct mount *mnt = real_mount(vfsmnt);
6539 + struct mount *root_mnt;
6542 + if (mnt == mnt->mnt_ns->root)
6546 + root = current->fs->root;
6547 + root_mnt = real_mount(root.mnt);
6548 + point = root.dentry;
6550 + while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6551 + point = mnt->mnt_mountpoint;
6552 + mnt = mnt->mnt_parent;
6554 + rcu_read_unlock();
6556 + ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6561 +#define mnt_is_reachable(v) (1)
6564 static void show_type(struct seq_file *m, struct super_block *sb)
6566 mangle(m, sb->s_type->name);
6567 @@ -96,6 +130,17 @@ static int show_vfsmnt(struct seq_file *
6568 struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6569 struct super_block *sb = mnt_path.dentry->d_sb;
6571 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6573 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6576 + if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6577 + mnt == current->fs->root.mnt) {
6578 + seq_puts(m, "/dev/root / ");
6582 if (sb->s_op->show_devname) {
6583 err = sb->s_op->show_devname(m, mnt_path.dentry);
6585 @@ -106,6 +151,7 @@ static int show_vfsmnt(struct seq_file *
6587 seq_path(m, &mnt_path, " \t\n\\");
6591 seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6592 err = show_sb_opts(m, sb);
6593 @@ -128,6 +174,11 @@ static int show_mountinfo(struct seq_fil
6594 struct path root = p->root;
6597 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6599 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6602 seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6603 MAJOR(sb->s_dev), MINOR(sb->s_dev));
6604 if (sb->s_op->show_path)
6605 @@ -187,6 +238,17 @@ static int show_vfsstat(struct seq_file
6606 struct super_block *sb = mnt_path.dentry->d_sb;
6609 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6611 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6614 + if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6615 + mnt == current->fs->root.mnt) {
6616 + seq_puts(m, "device /dev/root mounted on / ");
6621 if (sb->s_op->show_devname) {
6622 seq_puts(m, "device ");
6623 @@ -203,7 +265,7 @@ static int show_vfsstat(struct seq_file
6624 seq_puts(m, " mounted on ");
6625 seq_path(m, &mnt_path, " \t\n\\");
6629 /* file system type */
6630 seq_puts(m, "with fstype ");
6632 diff -NurpP --minimal linux-3.13.10/fs/quota/dquot.c linux-3.13.10-vs2.3.6.11/fs/quota/dquot.c
6633 --- linux-3.13.10/fs/quota/dquot.c 2014-04-17 01:12:34.000000000 +0000
6634 +++ linux-3.13.10-vs2.3.6.11/fs/quota/dquot.c 2014-03-12 15:51:07.000000000 +0000
6635 @@ -1602,6 +1602,9 @@ int __dquot_alloc_space(struct inode *in
6636 struct dquot **dquots = inode->i_dquot;
6637 int reserve = flags & DQUOT_SPACE_RESERVE;
6639 + if ((ret = dl_alloc_space(inode, number)))
6643 * First test before acquiring mutex - solves deadlocks when we
6644 * re-enter the quota code and are already holding the mutex
6645 @@ -1657,6 +1660,9 @@ int dquot_alloc_inode(const struct inode
6646 struct dquot_warn warn[MAXQUOTAS];
6647 struct dquot * const *dquots = inode->i_dquot;
6649 + if ((ret = dl_alloc_inode(inode)))
6652 /* First test before acquiring mutex - solves deadlocks when we
6653 * re-enter the quota code and are already holding the mutex */
6654 if (!dquot_active(inode))
6655 @@ -1757,6 +1763,8 @@ void __dquot_free_space(struct inode *in
6656 struct dquot **dquots = inode->i_dquot;
6657 int reserve = flags & DQUOT_SPACE_RESERVE;
6659 + dl_free_space(inode, number);
6661 /* First test before acquiring mutex - solves deadlocks when we
6662 * re-enter the quota code and are already holding the mutex */
6663 if (!dquot_active(inode)) {
6664 @@ -1801,6 +1809,8 @@ void dquot_free_inode(const struct inode
6665 struct dquot_warn warn[MAXQUOTAS];
6666 struct dquot * const *dquots = inode->i_dquot;
6668 + dl_free_inode(inode);
6670 /* First test before acquiring mutex - solves deadlocks when we
6671 * re-enter the quota code and are already holding the mutex */
6672 if (!dquot_active(inode))
6673 diff -NurpP --minimal linux-3.13.10/fs/quota/quota.c linux-3.13.10-vs2.3.6.11/fs/quota/quota.c
6674 --- linux-3.13.10/fs/quota/quota.c 2014-01-22 20:39:07.000000000 +0000
6675 +++ linux-3.13.10-vs2.3.6.11/fs/quota/quota.c 2014-01-31 20:38:03.000000000 +0000
6677 #include <linux/fs.h>
6678 #include <linux/namei.h>
6679 #include <linux/slab.h>
6680 +#include <linux/vs_context.h>
6681 #include <asm/current.h>
6682 #include <linux/uaccess.h>
6683 #include <linux/kernel.h>
6684 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6688 - if (!capable(CAP_SYS_ADMIN))
6689 + if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6693 @@ -338,6 +339,46 @@ static int do_quotactl(struct super_bloc
6697 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6699 +#include <linux/vroot.h>
6700 +#include <linux/major.h>
6701 +#include <linux/module.h>
6702 +#include <linux/kallsyms.h>
6703 +#include <linux/vserver/debug.h>
6705 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6707 +static DEFINE_SPINLOCK(vroot_grb_lock);
6709 +int register_vroot_grb(vroot_grb_func *func) {
6712 + spin_lock(&vroot_grb_lock);
6713 + if (!vroot_get_real_bdev) {
6714 + vroot_get_real_bdev = func;
6717 + spin_unlock(&vroot_grb_lock);
6720 +EXPORT_SYMBOL(register_vroot_grb);
6722 +int unregister_vroot_grb(vroot_grb_func *func) {
6723 + int ret = -EINVAL;
6725 + spin_lock(&vroot_grb_lock);
6726 + if (vroot_get_real_bdev) {
6727 + vroot_get_real_bdev = NULL;
6730 + spin_unlock(&vroot_grb_lock);
6733 +EXPORT_SYMBOL(unregister_vroot_grb);
6737 /* Return 1 if 'cmd' will block on frozen filesystem */
6738 static int quotactl_cmd_write(int cmd)
6740 @@ -373,6 +414,22 @@ static struct super_block *quotactl_bloc
6743 return ERR_CAST(bdev);
6744 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6745 + if (bdev && bdev->bd_inode &&
6746 + imajor(bdev->bd_inode) == VROOT_MAJOR) {
6747 + struct block_device *bdnew = (void *)-EINVAL;
6749 + if (vroot_get_real_bdev)
6750 + bdnew = vroot_get_real_bdev(bdev);
6752 + vxdprintk(VXD_CBIT(misc, 0),
6753 + "vroot_get_real_bdev not set");
6755 + if (IS_ERR(bdnew))
6756 + return ERR_PTR(PTR_ERR(bdnew));
6760 if (quotactl_cmd_write(cmd))
6761 sb = get_super_thawed(bdev);
6763 diff -NurpP --minimal linux-3.13.10/fs/stat.c linux-3.13.10-vs2.3.6.11/fs/stat.c
6764 --- linux-3.13.10/fs/stat.c 2014-01-22 20:39:07.000000000 +0000
6765 +++ linux-3.13.10-vs2.3.6.11/fs/stat.c 2014-01-31 20:38:03.000000000 +0000
6766 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6767 stat->nlink = inode->i_nlink;
6768 stat->uid = inode->i_uid;
6769 stat->gid = inode->i_gid;
6770 + stat->tag = inode->i_tag;
6771 stat->rdev = inode->i_rdev;
6772 stat->size = i_size_read(inode);
6773 stat->atime = inode->i_atime;
6774 diff -NurpP --minimal linux-3.13.10/fs/statfs.c linux-3.13.10-vs2.3.6.11/fs/statfs.c
6775 --- linux-3.13.10/fs/statfs.c 2013-11-25 15:47:00.000000000 +0000
6776 +++ linux-3.13.10-vs2.3.6.11/fs/statfs.c 2014-01-31 20:38:03.000000000 +0000
6778 #include <linux/statfs.h>
6779 #include <linux/security.h>
6780 #include <linux/uaccess.h>
6781 +#include <linux/vs_base.h>
6782 +#include <linux/vs_dlimit.h>
6783 #include "internal.h"
6785 static int flags_by_mnt(int mnt_flags)
6786 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6787 retval = dentry->d_sb->s_op->statfs(dentry, buf);
6788 if (retval == 0 && buf->f_frsize == 0)
6789 buf->f_frsize = buf->f_bsize;
6790 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
6791 + vx_vsi_statfs(dentry->d_sb, buf);
6795 diff -NurpP --minimal linux-3.13.10/fs/super.c linux-3.13.10-vs2.3.6.11/fs/super.c
6796 --- linux-3.13.10/fs/super.c 2014-01-22 20:39:07.000000000 +0000
6797 +++ linux-3.13.10-vs2.3.6.11/fs/super.c 2014-01-31 20:38:03.000000000 +0000
6799 #include <linux/cleancache.h>
6800 #include <linux/fsnotify.h>
6801 #include <linux/lockdep.h>
6802 +#include <linux/magic.h>
6803 +#include <linux/vs_context.h>
6804 #include "internal.h"
6807 @@ -1098,6 +1100,13 @@ mount_fs(struct file_system_type *type,
6808 WARN_ON(sb->s_bdi == &default_backing_dev_info);
6809 sb->s_flags |= MS_BORN;
6812 + if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6814 + (sb->s_magic != PROC_SUPER_MAGIC) &&
6815 + (sb->s_magic != DEVPTS_SUPER_MAGIC))
6818 error = security_sb_kern_mount(sb, flags, secdata);
6821 diff -NurpP --minimal linux-3.13.10/fs/kernfs/mount.c linux-3.13.10-vs2.3.6.11/fs/kernfs/mount.c
6822 --- linux-3.13.10/fs/kernfs/mount.c 2013-11-25 15:47:00.000000000 +0000
6823 +++ linux-3.13.10-vs2.3.6.11/fs/kernfs/mount.c 2014-01-31 20:38:03.000000000 +0000
6824 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6826 sb->s_blocksize = PAGE_CACHE_SIZE;
6827 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6828 - sb->s_magic = SYSFS_MAGIC;
6829 + sb->s_magic = SYSFS_SUPER_MAGIC;
6830 sb->s_op = &kernfs_sops;
6831 sb->s_time_gran = 1;
6833 diff -NurpP --minimal linux-3.13.10/fs/utimes.c linux-3.13.10-vs2.3.6.11/fs/utimes.c
6834 --- linux-3.13.10/fs/utimes.c 2014-01-22 20:39:07.000000000 +0000
6835 +++ linux-3.13.10-vs2.3.6.11/fs/utimes.c 2014-01-31 23:49:14.000000000 +0000
6837 #include <linux/stat.h>
6838 #include <linux/utime.h>
6839 #include <linux/syscalls.h>
6840 +#include <linux/mount.h>
6841 +#include <linux/vs_cowbl.h>
6842 #include <asm/uaccess.h>
6843 #include <asm/unistd.h>
6845 @@ -52,13 +54,19 @@ static int utimes_common(struct path *pa
6848 struct iattr newattrs;
6849 - struct inode *inode = path->dentry->d_inode;
6850 struct inode *delegated_inode = NULL;
6851 + struct inode *inode;
6853 + error = cow_check_and_break(path);
6857 error = mnt_want_write(path->mnt);
6861 + inode = path->dentry->d_inode;
6863 if (times && times[0].tv_nsec == UTIME_NOW &&
6864 times[1].tv_nsec == UTIME_NOW)
6866 diff -NurpP --minimal linux-3.13.10/fs/xattr.c linux-3.13.10-vs2.3.6.11/fs/xattr.c
6867 --- linux-3.13.10/fs/xattr.c 2013-02-19 13:58:49.000000000 +0000
6868 +++ linux-3.13.10-vs2.3.6.11/fs/xattr.c 2014-01-31 20:38:03.000000000 +0000
6870 #include <linux/audit.h>
6871 #include <linux/vmalloc.h>
6872 #include <linux/posix_acl_xattr.h>
6873 +#include <linux/mount.h>
6875 #include <asm/uaccess.h>
6877 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6878 * The trusted.* namespace can only be accessed by privileged users.
6880 if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6881 - if (!capable(CAP_SYS_ADMIN))
6882 + if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6883 return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6886 diff -NurpP --minimal linux-3.13.10/include/linux/cred.h linux-3.13.10-vs2.3.6.11/include/linux/cred.h
6887 --- linux-3.13.10/include/linux/cred.h 2013-02-19 13:58:50.000000000 +0000
6888 +++ linux-3.13.10-vs2.3.6.11/include/linux/cred.h 2014-01-31 20:38:03.000000000 +0000
6889 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
6890 extern int copy_creds(struct task_struct *, unsigned long);
6891 extern const struct cred *get_task_cred(struct task_struct *);
6892 extern struct cred *cred_alloc_blank(void);
6893 +extern struct cred *__prepare_creds(const struct cred *);
6894 extern struct cred *prepare_creds(void);
6895 extern struct cred *prepare_exec_creds(void);
6896 extern int commit_creds(struct cred *);
6897 @@ -196,6 +197,31 @@ static inline void validate_process_cred
6901 +static inline void set_cred_subscribers(struct cred *cred, int n)
6903 +#ifdef CONFIG_DEBUG_CREDENTIALS
6904 + atomic_set(&cred->subscribers, n);
6908 +static inline int read_cred_subscribers(const struct cred *cred)
6910 +#ifdef CONFIG_DEBUG_CREDENTIALS
6911 + return atomic_read(&cred->subscribers);
6917 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
6919 +#ifdef CONFIG_DEBUG_CREDENTIALS
6920 + struct cred *cred = (struct cred *) _cred;
6922 + atomic_add(n, &cred->subscribers);
6927 * get_new_cred - Get a reference on a new set of credentials
6928 * @cred: The new credentials to reference
6929 diff -NurpP --minimal linux-3.13.10/include/linux/devpts_fs.h linux-3.13.10-vs2.3.6.11/include/linux/devpts_fs.h
6930 --- linux-3.13.10/include/linux/devpts_fs.h 2013-02-19 13:58:50.000000000 +0000
6931 +++ linux-3.13.10-vs2.3.6.11/include/linux/devpts_fs.h 2014-01-31 20:38:03.000000000 +0000
6932 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
6937 #endif /* _LINUX_DEVPTS_FS_H */
6938 diff -NurpP --minimal linux-3.13.10/include/linux/fs.h linux-3.13.10-vs2.3.6.11/include/linux/fs.h
6939 --- linux-3.13.10/include/linux/fs.h 2014-01-22 20:39:10.000000000 +0000
6940 +++ linux-3.13.10-vs2.3.6.11/include/linux/fs.h 2014-01-31 23:33:22.000000000 +0000
6941 @@ -213,6 +213,7 @@ typedef void (dio_iodone_t)(struct kiocb
6942 #define ATTR_KILL_PRIV (1 << 14)
6943 #define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */
6944 #define ATTR_TIMES_SET (1 << 16)
6945 +#define ATTR_TAG (1 << 17)
6948 * This is the Inode Attributes structure, used for notify_change(). It
6949 @@ -228,6 +229,7 @@ struct iattr {
6955 struct timespec ia_atime;
6956 struct timespec ia_mtime;
6957 @@ -526,7 +528,9 @@ struct inode {
6958 unsigned short i_opflags;
6961 - unsigned int i_flags;
6963 + unsigned short i_flags;
6964 + unsigned short i_vflags;
6966 #ifdef CONFIG_FS_POSIX_ACL
6967 struct posix_acl *i_acl;
6968 @@ -555,6 +559,7 @@ struct inode {
6969 unsigned int __i_nlink;
6974 struct timespec i_atime;
6975 struct timespec i_mtime;
6976 @@ -713,6 +718,11 @@ static inline gid_t i_gid_read(const str
6977 return from_kgid(&init_user_ns, inode->i_gid);
6980 +static inline vtag_t i_tag_read(const struct inode *inode)
6982 + return from_ktag(&init_user_ns, inode->i_tag);
6985 static inline void i_uid_write(struct inode *inode, uid_t uid)
6987 inode->i_uid = make_kuid(&init_user_ns, uid);
6988 @@ -723,14 +733,19 @@ static inline void i_gid_write(struct in
6989 inode->i_gid = make_kgid(&init_user_ns, gid);
6992 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
6994 + inode->i_tag = make_ktag(&init_user_ns, tag);
6997 static inline unsigned iminor(const struct inode *inode)
6999 - return MINOR(inode->i_rdev);
7000 + return MINOR(inode->i_mdev);
7003 static inline unsigned imajor(const struct inode *inode)
7005 - return MAJOR(inode->i_rdev);
7006 + return MAJOR(inode->i_mdev);
7009 extern struct block_device *I_BDEV(struct inode *inode);
7010 @@ -790,6 +805,7 @@ struct file {
7012 struct fown_struct f_owner;
7013 const struct cred *f_cred;
7015 struct file_ra_state f_ra;
7018 @@ -962,6 +978,7 @@ struct file_lock {
7019 struct file *fl_file;
7024 struct fasync_struct * fl_fasync; /* for lease break notifications */
7025 /* for lease breaks: */
7026 @@ -1573,6 +1590,7 @@ struct inode_operations {
7027 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7028 ssize_t (*listxattr) (struct dentry *, char *, size_t);
7029 int (*removexattr) (struct dentry *, const char *);
7030 + int (*sync_flags) (struct inode *, int, int);
7031 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7033 int (*update_time)(struct inode *, struct timespec *, int);
7034 @@ -1586,6 +1604,7 @@ ssize_t rw_copy_check_uvector(int type,
7035 unsigned long nr_segs, unsigned long fast_segs,
7036 struct iovec *fast_pointer,
7037 struct iovec **ret_pointer);
7038 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7040 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7041 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7042 @@ -1639,6 +1658,14 @@ struct super_operations {
7043 #define S_IMA 1024 /* Inode has an associated IMA struct */
7044 #define S_AUTOMOUNT 2048 /* Automount/referral quasi-directory */
7045 #define S_NOSEC 4096 /* no suid or xattr security attributes */
7046 +#define S_IXUNLINK 8192 /* Immutable Invert on unlink */
7048 +/* Linux-VServer related Inode flags */
7052 +#define V_BARRIER 4 /* Barrier for chroot() */
7053 +#define V_COW 8 /* Copy on Write */
7056 * Note that nosuid etc flags are inode-specific: setting some file-system
7057 @@ -1663,10 +1690,13 @@ struct super_operations {
7058 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
7059 #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7060 #define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION)
7061 +#define IS_TAGGED(inode) __IS_FLG(inode, MS_TAGGED)
7063 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
7064 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
7065 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
7066 +#define IS_IXUNLINK(inode) ((inode)->i_flags & S_IXUNLINK)
7067 +#define IS_IXORUNLINK(inode) ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7068 #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL)
7070 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
7071 @@ -1677,6 +1707,16 @@ struct super_operations {
7072 #define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT)
7073 #define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC)
7075 +#define IS_BARRIER(inode) (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7077 +#ifdef CONFIG_VSERVER_COWBL
7078 +# define IS_COW(inode) (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7079 +# define IS_COW_LINK(inode) (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7081 +# define IS_COW(inode) (0)
7082 +# define IS_COW_LINK(inode) (0)
7086 * Inode state bits. Protected by inode->i_lock
7088 @@ -1920,6 +1960,9 @@ extern struct kobject *fs_kobj;
7089 extern int locks_mandatory_locked(struct inode *);
7090 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7092 +#define ATTR_FLAG_BARRIER 512 /* Barrier for chroot() */
7093 +#define ATTR_FLAG_IXUNLINK 1024 /* Immutable invert on unlink */
7096 * Candidates for mandatory locking have the setgid bit set
7097 * but no group execute bit - an otherwise meaningless combination.
7098 @@ -2605,6 +2648,7 @@ extern int dcache_dir_open(struct inode
7099 extern int dcache_dir_close(struct inode *, struct file *);
7100 extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7101 extern int dcache_readdir(struct file *, struct dir_context *);
7102 +extern int dcache_readdir_filter(struct file *, struct dir_context *, int (*)(struct dentry *));
7103 extern int simple_setattr(struct dentry *, struct iattr *);
7104 extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7105 extern int simple_statfs(struct dentry *, struct kstatfs *);
7106 diff -NurpP --minimal linux-3.13.10/include/linux/init_task.h linux-3.13.10-vs2.3.6.11/include/linux/init_task.h
7107 --- linux-3.13.10/include/linux/init_task.h 2014-01-22 20:39:11.000000000 +0000
7108 +++ linux-3.13.10-vs2.3.6.11/include/linux/init_task.h 2014-01-31 20:38:03.000000000 +0000
7109 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7110 INIT_TASK_RCU_PREEMPT(tsk) \
7111 INIT_CPUSET_SEQ(tsk) \
7114 + .vx_info = NULL, \
7116 + .nx_info = NULL, \
7120 diff -NurpP --minimal linux-3.13.10/include/linux/ipc.h linux-3.13.10-vs2.3.6.11/include/linux/ipc.h
7121 --- linux-3.13.10/include/linux/ipc.h 2012-12-11 03:30:57.000000000 +0000
7122 +++ linux-3.13.10-vs2.3.6.11/include/linux/ipc.h 2014-01-31 20:38:03.000000000 +0000
7123 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7131 diff -NurpP --minimal linux-3.13.10/include/linux/memcontrol.h linux-3.13.10-vs2.3.6.11/include/linux/memcontrol.h
7132 --- linux-3.13.10/include/linux/memcontrol.h 2013-11-25 15:47:01.000000000 +0000
7133 +++ linux-3.13.10-vs2.3.6.11/include/linux/memcontrol.h 2014-01-31 20:38:03.000000000 +0000
7134 @@ -99,6 +99,13 @@ extern struct mem_cgroup *try_get_mem_cg
7135 extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7136 extern struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css);
7138 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7139 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7141 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7142 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7143 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7146 bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7148 diff -NurpP --minimal linux-3.13.10/include/linux/mm_types.h linux-3.13.10-vs2.3.6.11/include/linux/mm_types.h
7149 --- linux-3.13.10/include/linux/mm_types.h 2014-01-22 20:39:11.000000000 +0000
7150 +++ linux-3.13.10-vs2.3.6.11/include/linux/mm_types.h 2014-01-31 20:38:03.000000000 +0000
7151 @@ -397,6 +397,7 @@ struct mm_struct {
7153 /* Architecture-specific MM context */
7154 mm_context_t context;
7155 + struct vx_info *mm_vx_info;
7157 unsigned long flags; /* Must use atomic bitops to access the bits */
7159 diff -NurpP --minimal linux-3.13.10/include/linux/mount.h linux-3.13.10-vs2.3.6.11/include/linux/mount.h
7160 --- linux-3.13.10/include/linux/mount.h 2014-01-22 20:39:11.000000000 +0000
7161 +++ linux-3.13.10-vs2.3.6.11/include/linux/mount.h 2014-01-31 20:38:03.000000000 +0000
7162 @@ -52,6 +52,9 @@ struct mnt_namespace;
7163 #define MNT_DOOMED 0x1000000
7164 #define MNT_SYNC_UMOUNT 0x2000000
7166 +#define MNT_TAGID 0x10000
7167 +#define MNT_NOTAG 0x20000
7170 struct dentry *mnt_root; /* root of the mounted tree */
7171 struct super_block *mnt_sb; /* pointer to superblock */
7172 diff -NurpP --minimal linux-3.13.10/include/linux/net.h linux-3.13.10-vs2.3.6.11/include/linux/net.h
7173 --- linux-3.13.10/include/linux/net.h 2014-01-22 20:39:11.000000000 +0000
7174 +++ linux-3.13.10-vs2.3.6.11/include/linux/net.h 2014-01-31 20:38:03.000000000 +0000
7175 @@ -39,6 +39,7 @@ struct net;
7176 #define SOCK_PASSCRED 3
7177 #define SOCK_PASSSEC 4
7178 #define SOCK_EXTERNALLY_ALLOCATED 5
7179 +#define SOCK_USER_SOCKET 6
7181 #ifndef ARCH_HAS_SOCKET_TYPES
7183 diff -NurpP --minimal linux-3.13.10/include/linux/netdevice.h linux-3.13.10-vs2.3.6.11/include/linux/netdevice.h
7184 --- linux-3.13.10/include/linux/netdevice.h 2014-04-17 01:12:37.000000000 +0000
7185 +++ linux-3.13.10-vs2.3.6.11/include/linux/netdevice.h 2014-03-12 15:51:07.000000000 +0000
7186 @@ -1839,6 +1839,7 @@ int init_dummy_netdev(struct net_device
7188 struct net_device *dev_get_by_index(struct net *net, int ifindex);
7189 struct net_device *__dev_get_by_index(struct net *net, int ifindex);
7190 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7191 struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
7192 int netdev_get_name(struct net *net, char *name, int ifindex);
7193 int dev_restart(struct net_device *dev);
7194 diff -NurpP --minimal linux-3.13.10/include/linux/nsproxy.h linux-3.13.10-vs2.3.6.11/include/linux/nsproxy.h
7195 --- linux-3.13.10/include/linux/nsproxy.h 2013-11-25 15:45:06.000000000 +0000
7196 +++ linux-3.13.10-vs2.3.6.11/include/linux/nsproxy.h 2014-01-31 20:38:03.000000000 +0000
7199 #include <linux/spinlock.h>
7200 #include <linux/sched.h>
7201 +#include <linux/vserver/debug.h>
7203 struct mnt_namespace;
7204 struct uts_namespace;
7205 @@ -67,6 +68,7 @@ static inline struct nsproxy *task_nspro
7208 int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7209 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7210 void exit_task_namespaces(struct task_struct *tsk);
7211 void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7212 void free_nsproxy(struct nsproxy *ns);
7213 @@ -74,16 +76,26 @@ int unshare_nsproxy_namespaces(unsigned
7214 struct cred *, struct fs_struct *);
7215 int __init nsproxy_cache_init(void);
7217 -static inline void put_nsproxy(struct nsproxy *ns)
7218 +#define get_nsproxy(n) __get_nsproxy(n, __FILE__, __LINE__)
7220 +static inline void __get_nsproxy(struct nsproxy *ns,
7221 + const char *_file, int _line)
7223 - if (atomic_dec_and_test(&ns->count)) {
7226 + vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7227 + ns, atomic_read(&ns->count), _file, _line);
7228 + atomic_inc(&ns->count);
7231 -static inline void get_nsproxy(struct nsproxy *ns)
7232 +#define put_nsproxy(n) __put_nsproxy(n, __FILE__, __LINE__)
7234 +static inline void __put_nsproxy(struct nsproxy *ns,
7235 + const char *_file, int _line)
7237 - atomic_inc(&ns->count);
7238 + vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7239 + ns, atomic_read(&ns->count), _file, _line);
7240 + if (atomic_dec_and_test(&ns->count)) {
7246 diff -NurpP --minimal linux-3.13.10/include/linux/pid.h linux-3.13.10-vs2.3.6.11/include/linux/pid.h
7247 --- linux-3.13.10/include/linux/pid.h 2013-11-25 15:45:06.000000000 +0000
7248 +++ linux-3.13.10-vs2.3.6.11/include/linux/pid.h 2014-01-31 20:38:03.000000000 +0000
7249 @@ -8,7 +8,8 @@ enum pid_type
7259 @@ -170,6 +171,7 @@ static inline pid_t pid_nr(struct pid *p
7262 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7263 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7264 pid_t pid_vnr(struct pid *pid);
7266 #define do_each_pid_task(pid, type, task) \
7267 diff -NurpP --minimal linux-3.13.10/include/linux/quotaops.h linux-3.13.10-vs2.3.6.11/include/linux/quotaops.h
7268 --- linux-3.13.10/include/linux/quotaops.h 2013-11-25 15:47:02.000000000 +0000
7269 +++ linux-3.13.10-vs2.3.6.11/include/linux/quotaops.h 2014-01-31 20:38:03.000000000 +0000
7271 #define _LINUX_QUOTAOPS_
7273 #include <linux/fs.h>
7274 +#include <linux/vs_dlimit.h>
7276 #define DQUOT_SPACE_WARN 0x1
7277 #define DQUOT_SPACE_RESERVE 0x2
7278 @@ -207,11 +208,12 @@ static inline void dquot_drop(struct ino
7280 static inline int dquot_alloc_inode(const struct inode *inode)
7283 + return dl_alloc_inode(inode);
7286 static inline void dquot_free_inode(const struct inode *inode)
7288 + dl_free_inode(inode);
7291 static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
7292 @@ -222,6 +224,10 @@ static inline int dquot_transfer(struct
7293 static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
7298 + if ((ret = dl_alloc_space(inode, number)))
7300 if (!(flags & DQUOT_SPACE_RESERVE))
7301 inode_add_bytes(inode, number);
7303 @@ -232,6 +238,7 @@ static inline void __dquot_free_space(st
7305 if (!(flags & DQUOT_SPACE_RESERVE))
7306 inode_sub_bytes(inode, number);
7307 + dl_free_space(inode, number);
7310 static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
7311 diff -NurpP --minimal linux-3.13.10/include/linux/sched.h linux-3.13.10-vs2.3.6.11/include/linux/sched.h
7312 --- linux-3.13.10/include/linux/sched.h 2014-01-22 20:39:11.000000000 +0000
7313 +++ linux-3.13.10-vs2.3.6.11/include/linux/sched.h 2014-01-31 20:38:03.000000000 +0000
7314 @@ -1237,6 +1237,14 @@ struct task_struct {
7316 struct seccomp seccomp;
7318 +/* vserver context data */
7319 + struct vx_info *vx_info;
7320 + struct nx_info *nx_info;
7326 /* Thread group tracking */
7329 @@ -1531,6 +1539,11 @@ struct pid_namespace;
7330 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
7331 struct pid_namespace *ns);
7333 +#include <linux/vserver/base.h>
7334 +#include <linux/vserver/context.h>
7335 +#include <linux/vserver/debug.h>
7336 +#include <linux/vserver/pid.h>
7338 static inline pid_t task_pid_nr(struct task_struct *tsk)
7341 @@ -1544,7 +1557,8 @@ static inline pid_t task_pid_nr_ns(struc
7343 static inline pid_t task_pid_vnr(struct task_struct *tsk)
7345 - return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7346 + // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7347 + return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
7351 @@ -1557,7 +1571,7 @@ pid_t task_tgid_nr_ns(struct task_struct
7353 static inline pid_t task_tgid_vnr(struct task_struct *tsk)
7355 - return pid_vnr(task_tgid(tsk));
7356 + return vx_map_tgid(pid_vnr(task_tgid(tsk)));
7360 diff -NurpP --minimal linux-3.13.10/include/linux/shmem_fs.h linux-3.13.10-vs2.3.6.11/include/linux/shmem_fs.h
7361 --- linux-3.13.10/include/linux/shmem_fs.h 2014-01-22 20:39:11.000000000 +0000
7362 +++ linux-3.13.10-vs2.3.6.11/include/linux/shmem_fs.h 2014-01-31 20:38:03.000000000 +0000
7365 /* inode in-kernel data */
7367 +#define TMPFS_SUPER_MAGIC 0x01021994
7370 struct shmem_inode_info {
7372 unsigned long flags;
7373 diff -NurpP --minimal linux-3.13.10/include/linux/stat.h linux-3.13.10-vs2.3.6.11/include/linux/stat.h
7374 --- linux-3.13.10/include/linux/stat.h 2012-12-11 03:30:57.000000000 +0000
7375 +++ linux-3.13.10-vs2.3.6.11/include/linux/stat.h 2014-01-31 20:38:03.000000000 +0000
7376 @@ -25,6 +25,7 @@ struct kstat {
7383 struct timespec atime;
7384 diff -NurpP --minimal linux-3.13.10/include/linux/sunrpc/auth.h linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/auth.h
7385 --- linux-3.13.10/include/linux/sunrpc/auth.h 2013-11-25 15:47:02.000000000 +0000
7386 +++ linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/auth.h 2014-01-31 20:38:03.000000000 +0000
7387 @@ -36,6 +36,7 @@ enum {
7392 struct group_info *group_info;
7393 const char *principal;
7394 unsigned long ac_flags;
7395 diff -NurpP --minimal linux-3.13.10/include/linux/sunrpc/clnt.h linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/clnt.h
7396 --- linux-3.13.10/include/linux/sunrpc/clnt.h 2014-01-22 20:39:11.000000000 +0000
7397 +++ linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/clnt.h 2014-01-31 20:38:03.000000000 +0000
7398 @@ -51,7 +51,8 @@ struct rpc_clnt {
7399 cl_discrtry : 1,/* disconnect before retry */
7400 cl_noretranstimeo: 1,/* No retransmit timeouts */
7401 cl_autobind : 1,/* use getport() */
7402 - cl_chatty : 1;/* be verbose */
7403 + cl_chatty : 1,/* be verbose */
7404 + cl_tag : 1;/* context tagging */
7406 struct rpc_rtt * cl_rtt; /* RTO estimator data */
7407 const struct rpc_timeout *cl_timeout; /* Timeout strategy */
7408 diff -NurpP --minimal linux-3.13.10/include/linux/sysfs.h linux-3.13.10-vs2.3.6.11/include/linux/sysfs.h
7409 --- linux-3.13.10/include/linux/sysfs.h 2014-01-22 20:39:11.000000000 +0000
7410 +++ linux-3.13.10-vs2.3.6.11/include/linux/sysfs.h 2014-01-31 20:38:03.000000000 +0000
7412 #include <linux/stat.h>
7413 #include <linux/atomic.h>
7415 +#define SYSFS_SUPER_MAGIC 0x62656572
7419 struct bin_attribute;
7420 diff -NurpP --minimal linux-3.13.10/include/linux/types.h linux-3.13.10-vs2.3.6.11/include/linux/types.h
7421 --- linux-3.13.10/include/linux/types.h 2013-02-19 13:58:52.000000000 +0000
7422 +++ linux-3.13.10-vs2.3.6.11/include/linux/types.h 2014-01-31 20:38:03.000000000 +0000
7423 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t uid_t;
7424 typedef __kernel_gid32_t gid_t;
7425 typedef __kernel_uid16_t uid16_t;
7426 typedef __kernel_gid16_t gid16_t;
7427 +typedef unsigned int vxid_t;
7428 +typedef unsigned int vnid_t;
7429 +typedef unsigned int vtag_t;
7431 typedef unsigned long uintptr_t;
7433 diff -NurpP --minimal linux-3.13.10/include/linux/uidgid.h linux-3.13.10-vs2.3.6.11/include/linux/uidgid.h
7434 --- linux-3.13.10/include/linux/uidgid.h 2012-12-11 03:30:57.000000000 +0000
7435 +++ linux-3.13.10-vs2.3.6.11/include/linux/uidgid.h 2014-01-31 20:38:03.000000000 +0000
7436 @@ -23,13 +23,17 @@ typedef struct {
7449 #define KUIDT_INIT(value) (kuid_t){ value }
7450 #define KGIDT_INIT(value) (kgid_t){ value }
7451 +#define KTAGT_INIT(value) (ktag_t){ value }
7453 static inline uid_t __kuid_val(kuid_t uid)
7455 @@ -41,11 +45,18 @@ static inline gid_t __kgid_val(kgid_t gi
7459 +static inline vtag_t __ktag_val(ktag_t tag)
7464 #define GLOBAL_ROOT_UID KUIDT_INIT(0)
7465 #define GLOBAL_ROOT_GID KGIDT_INIT(0)
7466 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
7468 #define INVALID_UID KUIDT_INIT(-1)
7469 #define INVALID_GID KGIDT_INIT(-1)
7470 +#define INVALID_TAG KTAGT_INIT(-1)
7472 static inline bool uid_eq(kuid_t left, kuid_t right)
7474 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
7475 return __kgid_val(left) == __kgid_val(right);
7478 +static inline bool tag_eq(ktag_t left, ktag_t right)
7480 + return __ktag_val(left) == __ktag_val(right);
7483 static inline bool uid_gt(kuid_t left, kuid_t right)
7485 return __kuid_val(left) > __kuid_val(right);
7486 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
7487 return !gid_eq(gid, INVALID_GID);
7490 +static inline bool tag_valid(ktag_t tag)
7492 + return !tag_eq(tag, INVALID_TAG);
7495 #ifdef CONFIG_USER_NS
7497 extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
7498 extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
7499 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
7501 extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
7502 extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
7503 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
7505 extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
7506 extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
7508 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
7509 return KGIDT_INIT(gid);
7512 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
7514 + return KTAGT_INIT(tag);
7517 static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
7519 return __kuid_val(kuid);
7520 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
7521 return __kgid_val(kgid);
7524 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
7526 + return __ktag_val(ktag);
7529 static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
7531 uid_t uid = from_kuid(to, kuid);
7532 diff -NurpP --minimal linux-3.13.10/include/linux/vroot.h linux-3.13.10-vs2.3.6.11/include/linux/vroot.h
7533 --- linux-3.13.10/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
7534 +++ linux-3.13.10-vs2.3.6.11/include/linux/vroot.h 2014-01-31 20:38:03.000000000 +0000
7538 + * include/linux/vroot.h
7540 + * written by Herbert Pötzl, 9/11/2002
7541 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
7543 + * Copyright (C) 2002-2007 by Herbert Pötzl.
7544 + * Redistribution of this file is permitted under the
7545 + * GNU General Public License.
7548 +#ifndef _LINUX_VROOT_H
7549 +#define _LINUX_VROOT_H
7554 +/* Possible states of device */
7560 +struct vroot_device {
7564 + struct semaphore vr_ctl_mutex;
7565 + struct block_device *vr_device;
7570 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
7572 +extern int register_vroot_grb(vroot_grb_func *);
7573 +extern int unregister_vroot_grb(vroot_grb_func *);
7575 +#endif /* __KERNEL__ */
7577 +#define MAX_VROOT_DEFAULT 8
7580 + * IOCTL commands --- we will commandeer 0x56 ('V')
7583 +#define VROOT_SET_DEV 0x5600
7584 +#define VROOT_CLR_DEV 0x5601
7586 +#endif /* _LINUX_VROOT_H */
7587 diff -NurpP --minimal linux-3.13.10/include/linux/vs_base.h linux-3.13.10-vs2.3.6.11/include/linux/vs_base.h
7588 --- linux-3.13.10/include/linux/vs_base.h 1970-01-01 00:00:00.000000000 +0000
7589 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_base.h 2014-01-31 20:38:03.000000000 +0000
7594 +#include "vserver/base.h"
7595 +#include "vserver/check.h"
7596 +#include "vserver/debug.h"
7599 +#warning duplicate inclusion
7601 diff -NurpP --minimal linux-3.13.10/include/linux/vs_context.h linux-3.13.10-vs2.3.6.11/include/linux/vs_context.h
7602 --- linux-3.13.10/include/linux/vs_context.h 1970-01-01 00:00:00.000000000 +0000
7603 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_context.h 2014-01-31 20:38:03.000000000 +0000
7605 +#ifndef _VS_CONTEXT_H
7606 +#define _VS_CONTEXT_H
7608 +#include "vserver/base.h"
7609 +#include "vserver/check.h"
7610 +#include "vserver/context.h"
7611 +#include "vserver/history.h"
7612 +#include "vserver/debug.h"
7614 +#include <linux/sched.h>
7617 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
7619 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
7620 + const char *_file, int _line, void *_here)
7625 + vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
7626 + vxi, vxi ? vxi->vx_id : 0,
7627 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7629 + __vxh_get_vx_info(vxi, _here);
7631 + atomic_inc(&vxi->vx_usecnt);
7636 +extern void free_vx_info(struct vx_info *);
7638 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
7640 +static inline void __put_vx_info(struct vx_info *vxi,
7641 + const char *_file, int _line, void *_here)
7646 + vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
7647 + vxi, vxi ? vxi->vx_id : 0,
7648 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7650 + __vxh_put_vx_info(vxi, _here);
7652 + if (atomic_dec_and_test(&vxi->vx_usecnt))
7653 + free_vx_info(vxi);
7657 +#define init_vx_info(p, i) \
7658 + __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7660 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7661 + const char *_file, int _line, void *_here)
7664 + vxlprintk(VXD_CBIT(xid, 3),
7665 + "init_vx_info(%p[#%d.%d])",
7666 + vxi, vxi ? vxi->vx_id : 0,
7667 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7669 + __vxh_init_vx_info(vxi, vxp, _here);
7671 + atomic_inc(&vxi->vx_usecnt);
7677 +#define set_vx_info(p, i) \
7678 + __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7680 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7681 + const char *_file, int _line, void *_here)
7683 + struct vx_info *vxo;
7688 + vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
7689 + vxi, vxi ? vxi->vx_id : 0,
7690 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7692 + __vxh_set_vx_info(vxi, vxp, _here);
7694 + atomic_inc(&vxi->vx_usecnt);
7695 + vxo = xchg(vxp, vxi);
7700 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
7702 +static inline void __clr_vx_info(struct vx_info **vxp,
7703 + const char *_file, int _line, void *_here)
7705 + struct vx_info *vxo;
7707 + vxo = xchg(vxp, NULL);
7711 + vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
7712 + vxo, vxo ? vxo->vx_id : 0,
7713 + vxo ? atomic_read(&vxo->vx_usecnt) : 0,
7715 + __vxh_clr_vx_info(vxo, vxp, _here);
7717 + if (atomic_dec_and_test(&vxo->vx_usecnt))
7718 + free_vx_info(vxo);
7722 +#define claim_vx_info(v, p) \
7723 + __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7725 +static inline void __claim_vx_info(struct vx_info *vxi,
7726 + struct task_struct *task,
7727 + const char *_file, int _line, void *_here)
7729 + vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
7730 + vxi, vxi ? vxi->vx_id : 0,
7731 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7732 + vxi ? atomic_read(&vxi->vx_tasks) : 0,
7733 + task, _file, _line);
7734 + __vxh_claim_vx_info(vxi, task, _here);
7736 + atomic_inc(&vxi->vx_tasks);
7740 +extern void unhash_vx_info(struct vx_info *);
7742 +#define release_vx_info(v, p) \
7743 + __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7745 +static inline void __release_vx_info(struct vx_info *vxi,
7746 + struct task_struct *task,
7747 + const char *_file, int _line, void *_here)
7749 + vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
7750 + vxi, vxi ? vxi->vx_id : 0,
7751 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7752 + vxi ? atomic_read(&vxi->vx_tasks) : 0,
7753 + task, _file, _line);
7754 + __vxh_release_vx_info(vxi, task, _here);
7758 + if (atomic_dec_and_test(&vxi->vx_tasks))
7759 + unhash_vx_info(vxi);
7763 +#define task_get_vx_info(p) \
7764 + __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
7766 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
7767 + const char *_file, int _line, void *_here)
7769 + struct vx_info *vxi;
7772 + vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
7774 + vxi = __get_vx_info(p->vx_info, _file, _line, _here);
7780 +static inline void __wakeup_vx_info(struct vx_info *vxi)
7782 + if (waitqueue_active(&vxi->vx_wait))
7783 + wake_up_interruptible(&vxi->vx_wait);
7787 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
7789 +static inline void __enter_vx_info(struct vx_info *vxi,
7790 + struct vx_info_save *vxis, const char *_file, int _line)
7792 + vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
7793 + vxi, vxi ? vxi->vx_id : 0, vxis, current,
7794 + current->xid, current->vx_info, _file, _line);
7795 + vxis->vxi = xchg(¤t->vx_info, vxi);
7796 + vxis->xid = current->xid;
7797 + current->xid = vxi ? vxi->vx_id : 0;
7800 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
7802 +static inline void __leave_vx_info(struct vx_info_save *vxis,
7803 + const char *_file, int _line)
7805 + vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
7806 + vxis, vxis->xid, vxis->vxi, current,
7807 + current->xid, current->vx_info, _file, _line);
7808 + (void)xchg(¤t->vx_info, vxis->vxi);
7809 + current->xid = vxis->xid;
7813 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
7815 + vxis->vxi = xchg(¤t->vx_info, NULL);
7816 + vxis->xid = xchg(¤t->xid, (vxid_t)0);
7819 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
7821 + (void)xchg(¤t->xid, vxis->xid);
7822 + (void)xchg(¤t->vx_info, vxis->vxi);
7825 +#define task_is_init(p) \
7826 + __task_is_init(p, __FILE__, __LINE__, __HERE__)
7828 +static inline int __task_is_init(struct task_struct *p,
7829 + const char *_file, int _line, void *_here)
7831 + int is_init = is_global_init(p);
7835 + is_init = p->vx_info->vx_initpid == p->pid;
7840 +extern void exit_vx_info(struct task_struct *, int);
7841 +extern void exit_vx_info_early(struct task_struct *, int);
7845 +#warning duplicate inclusion
7847 diff -NurpP --minimal linux-3.13.10/include/linux/vs_cowbl.h linux-3.13.10-vs2.3.6.11/include/linux/vs_cowbl.h
7848 --- linux-3.13.10/include/linux/vs_cowbl.h 1970-01-01 00:00:00.000000000 +0000
7849 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_cowbl.h 2014-01-31 20:38:03.000000000 +0000
7851 +#ifndef _VS_COWBL_H
7852 +#define _VS_COWBL_H
7854 +#include <linux/fs.h>
7855 +#include <linux/dcache.h>
7856 +#include <linux/namei.h>
7857 +#include <linux/slab.h>
7859 +extern struct dentry *cow_break_link(const char *pathname);
7861 +static inline int cow_check_and_break(struct path *path)
7863 + struct inode *inode = path->dentry->d_inode;
7866 + /* do we need this check? */
7867 + if (IS_RDONLY(inode))
7870 + if (IS_COW(inode)) {
7871 + if (IS_COW_LINK(inode)) {
7872 + struct dentry *new_dentry, *old_dentry = path->dentry;
7875 + buf = kmalloc(PATH_MAX, GFP_KERNEL);
7879 + pp = d_path(path, buf, PATH_MAX);
7880 + new_dentry = cow_break_link(pp);
7882 + if (!IS_ERR(new_dentry)) {
7883 + path->dentry = new_dentry;
7886 + error = PTR_ERR(new_dentry);
7888 + inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
7889 + inode->i_ctime = CURRENT_TIME;
7890 + mark_inode_dirty(inode);
7897 +#warning duplicate inclusion
7899 diff -NurpP --minimal linux-3.13.10/include/linux/vs_cvirt.h linux-3.13.10-vs2.3.6.11/include/linux/vs_cvirt.h
7900 --- linux-3.13.10/include/linux/vs_cvirt.h 1970-01-01 00:00:00.000000000 +0000
7901 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_cvirt.h 2014-01-31 20:38:03.000000000 +0000
7903 +#ifndef _VS_CVIRT_H
7904 +#define _VS_CVIRT_H
7906 +#include "vserver/cvirt.h"
7907 +#include "vserver/context.h"
7908 +#include "vserver/base.h"
7909 +#include "vserver/check.h"
7910 +#include "vserver/debug.h"
7913 +static inline void vx_activate_task(struct task_struct *p)
7915 + struct vx_info *vxi;
7917 + if ((vxi = p->vx_info)) {
7918 + vx_update_load(vxi);
7919 + atomic_inc(&vxi->cvirt.nr_running);
7923 +static inline void vx_deactivate_task(struct task_struct *p)
7925 + struct vx_info *vxi;
7927 + if ((vxi = p->vx_info)) {
7928 + vx_update_load(vxi);
7929 + atomic_dec(&vxi->cvirt.nr_running);
7933 +static inline void vx_uninterruptible_inc(struct task_struct *p)
7935 + struct vx_info *vxi;
7937 + if ((vxi = p->vx_info))
7938 + atomic_inc(&vxi->cvirt.nr_uninterruptible);
7941 +static inline void vx_uninterruptible_dec(struct task_struct *p)
7943 + struct vx_info *vxi;
7945 + if ((vxi = p->vx_info))
7946 + atomic_dec(&vxi->cvirt.nr_uninterruptible);
7951 +#warning duplicate inclusion
7953 diff -NurpP --minimal linux-3.13.10/include/linux/vs_device.h linux-3.13.10-vs2.3.6.11/include/linux/vs_device.h
7954 --- linux-3.13.10/include/linux/vs_device.h 1970-01-01 00:00:00.000000000 +0000
7955 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_device.h 2014-01-31 20:38:03.000000000 +0000
7957 +#ifndef _VS_DEVICE_H
7958 +#define _VS_DEVICE_H
7960 +#include "vserver/base.h"
7961 +#include "vserver/device.h"
7962 +#include "vserver/debug.h"
7965 +#ifdef CONFIG_VSERVER_DEVICE
7967 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
7969 +#define vs_device_perm(v, d, m, p) \
7970 + ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
7975 +int vs_map_device(struct vx_info *vxi,
7976 + dev_t device, dev_t *target, umode_t mode)
7983 +#define vs_device_perm(v, d, m, p) ((p) == (p))
7988 +#define vs_map_chrdev(d, t, p) \
7989 + ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
7990 +#define vs_map_blkdev(d, t, p) \
7991 + ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
7993 +#define vs_chrdev_perm(d, p) \
7994 + vs_device_perm(current_vx_info(), d, S_IFCHR, p)
7995 +#define vs_blkdev_perm(d, p) \
7996 + vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8000 +#warning duplicate inclusion
8002 diff -NurpP --minimal linux-3.13.10/include/linux/vs_dlimit.h linux-3.13.10-vs2.3.6.11/include/linux/vs_dlimit.h
8003 --- linux-3.13.10/include/linux/vs_dlimit.h 1970-01-01 00:00:00.000000000 +0000
8004 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_dlimit.h 2014-01-31 20:38:03.000000000 +0000
8006 +#ifndef _VS_DLIMIT_H
8007 +#define _VS_DLIMIT_H
8009 +#include <linux/fs.h>
8011 +#include "vserver/dlimit.h"
8012 +#include "vserver/base.h"
8013 +#include "vserver/debug.h"
8016 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8018 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8019 + const char *_file, int _line)
8023 + vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8024 + dli, dli ? dli->dl_tag : 0,
8025 + dli ? atomic_read(&dli->dl_usecnt) : 0,
8027 + atomic_inc(&dli->dl_usecnt);
8032 +#define free_dl_info(i) \
8033 + call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8035 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8037 +static inline void __put_dl_info(struct dl_info *dli,
8038 + const char *_file, int _line)
8042 + vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8043 + dli, dli ? dli->dl_tag : 0,
8044 + dli ? atomic_read(&dli->dl_usecnt) : 0,
8046 + if (atomic_dec_and_test(&dli->dl_usecnt))
8047 + free_dl_info(dli);
8051 +#define __dlimit_char(d) ((d) ? '*' : ' ')
8053 +static inline int __dl_alloc_space(struct super_block *sb,
8054 + vtag_t tag, dlsize_t nr, const char *file, int line)
8056 + struct dl_info *dli = NULL;
8061 + dli = locate_dl_info(sb, tag);
8065 + spin_lock(&dli->dl_lock);
8066 + ret = (dli->dl_space_used + nr > dli->dl_space_total);
8068 + dli->dl_space_used += nr;
8069 + spin_unlock(&dli->dl_lock);
8072 + vxlprintk(VXD_CBIT(dlim, 1),
8073 + "ALLOC (%p,#%d)%c %lld bytes (%d)",
8074 + sb, tag, __dlimit_char(dli), (long long)nr,
8076 + return ret ? -ENOSPC : 0;
8079 +static inline void __dl_free_space(struct super_block *sb,
8080 + vtag_t tag, dlsize_t nr, const char *_file, int _line)
8082 + struct dl_info *dli = NULL;
8086 + dli = locate_dl_info(sb, tag);
8090 + spin_lock(&dli->dl_lock);
8091 + if (dli->dl_space_used > nr)
8092 + dli->dl_space_used -= nr;
8094 + dli->dl_space_used = 0;
8095 + spin_unlock(&dli->dl_lock);
8098 + vxlprintk(VXD_CBIT(dlim, 1),
8099 + "FREE (%p,#%d)%c %lld bytes",
8100 + sb, tag, __dlimit_char(dli), (long long)nr,
8104 +static inline int __dl_alloc_inode(struct super_block *sb,
8105 + vtag_t tag, const char *_file, int _line)
8107 + struct dl_info *dli;
8110 + dli = locate_dl_info(sb, tag);
8114 + spin_lock(&dli->dl_lock);
8115 + dli->dl_inodes_used++;
8116 + ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8117 + spin_unlock(&dli->dl_lock);
8120 + vxlprintk(VXD_CBIT(dlim, 0),
8121 + "ALLOC (%p,#%d)%c inode (%d)",
8122 + sb, tag, __dlimit_char(dli), ret, _file, _line);
8123 + return ret ? -ENOSPC : 0;
8126 +static inline void __dl_free_inode(struct super_block *sb,
8127 + vtag_t tag, const char *_file, int _line)
8129 + struct dl_info *dli;
8131 + dli = locate_dl_info(sb, tag);
8135 + spin_lock(&dli->dl_lock);
8136 + if (dli->dl_inodes_used > 1)
8137 + dli->dl_inodes_used--;
8139 + dli->dl_inodes_used = 0;
8140 + spin_unlock(&dli->dl_lock);
8143 + vxlprintk(VXD_CBIT(dlim, 0),
8144 + "FREE (%p,#%d)%c inode",
8145 + sb, tag, __dlimit_char(dli), _file, _line);
8148 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
8149 + unsigned long long *free_blocks, unsigned long long *root_blocks,
8150 + const char *_file, int _line)
8152 + struct dl_info *dli;
8153 + uint64_t broot, bfree;
8155 + dli = locate_dl_info(sb, tag);
8159 + spin_lock(&dli->dl_lock);
8160 + broot = (dli->dl_space_total -
8161 + (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8162 + >> sb->s_blocksize_bits;
8163 + bfree = (dli->dl_space_total - dli->dl_space_used)
8164 + >> sb->s_blocksize_bits;
8165 + spin_unlock(&dli->dl_lock);
8167 + vxlprintk(VXD_CBIT(dlim, 2),
8168 + "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8169 + (long long)bfree, (long long)broot,
8170 + *free_blocks, *root_blocks, dli->dl_nrlmult,
8172 + if (free_blocks) {
8173 + if (*free_blocks > bfree)
8174 + *free_blocks = bfree;
8176 + if (root_blocks) {
8177 + if (*root_blocks > broot)
8178 + *root_blocks = broot;
8183 +#define dl_prealloc_space(in, bytes) \
8184 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8185 + __FILE__, __LINE__ )
8187 +#define dl_alloc_space(in, bytes) \
8188 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8189 + __FILE__, __LINE__ )
8191 +#define dl_reserve_space(in, bytes) \
8192 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8193 + __FILE__, __LINE__ )
8195 +#define dl_claim_space(in, bytes) (0)
8197 +#define dl_release_space(in, bytes) \
8198 + __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8199 + __FILE__, __LINE__ )
8201 +#define dl_free_space(in, bytes) \
8202 + __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8203 + __FILE__, __LINE__ )
8207 +#define dl_alloc_inode(in) \
8208 + __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8210 +#define dl_free_inode(in) \
8211 + __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8214 +#define dl_adjust_block(sb, tag, fb, rb) \
8215 + __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8219 +#warning duplicate inclusion
8221 diff -NurpP --minimal linux-3.13.10/include/linux/vs_inet.h linux-3.13.10-vs2.3.6.11/include/linux/vs_inet.h
8222 --- linux-3.13.10/include/linux/vs_inet.h 1970-01-01 00:00:00.000000000 +0000
8223 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_inet.h 2014-02-01 00:32:45.000000000 +0000
8228 +#include "vserver/base.h"
8229 +#include "vserver/network.h"
8230 +#include "vserver/debug.h"
8232 +#define IPI_LOOPBACK htonl(INADDR_LOOPBACK)
8234 +#define NXAV4(a) NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
8235 + NIPQUAD((a)->mask), (a)->type
8236 +#define NXAV4_FMT "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
8238 +#define NIPQUAD(addr) \
8239 + ((unsigned char *)&addr)[0], \
8240 + ((unsigned char *)&addr)[1], \
8241 + ((unsigned char *)&addr)[2], \
8242 + ((unsigned char *)&addr)[3]
8244 +#define NIPQUAD_FMT "%u.%u.%u.%u"
8248 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
8250 + __be32 ip = nxa->ip[0].s_addr;
8251 + __be32 mask = nxa->mask.s_addr;
8252 + __be32 bcast = ip | ~mask;
8255 + switch (nxa->type & tmask) {
8256 + case NXA_TYPE_MASK:
8257 + ret = (ip == (addr & mask));
8259 + case NXA_TYPE_ADDR:
8263 + /* fall through to broadcast */
8264 + case NXA_MOD_BCAST:
8265 + ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
8267 + case NXA_TYPE_RANGE:
8268 + ret = ((nxa->ip[0].s_addr <= addr) &&
8269 + (nxa->ip[1].s_addr > addr));
8271 + case NXA_TYPE_ANY:
8276 + vxdprintk(VXD_CBIT(net, 0),
8277 + "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
8278 + nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
8283 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
8285 + struct nx_addr_v4 *nxa;
8286 + unsigned long irqflags;
8293 + /* allow 127.0.0.1 when remapping lback */
8294 + if ((tmask & NXA_LOOPBACK) &&
8295 + (addr == IPI_LOOPBACK) &&
8296 + nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8299 + /* check for lback address */
8300 + if ((tmask & NXA_MOD_LBACK) &&
8301 + (nxi->v4_lback.s_addr == addr))
8304 + /* check for broadcast address */
8305 + if ((tmask & NXA_MOD_BCAST) &&
8306 + (nxi->v4_bcast.s_addr == addr))
8310 + /* check for v4 addresses */
8311 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
8312 + for (nxa = &nxi->v4; nxa; nxa = nxa->next)
8313 + if (v4_addr_match(nxa, addr, tmask))
8317 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8319 + vxdprintk(VXD_CBIT(net, 0),
8320 + "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
8321 + nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
8326 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
8328 + /* FIXME: needs full range checks */
8329 + return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
8333 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
8335 + struct nx_addr_v4 *ptr;
8336 + unsigned long irqflags;
8339 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
8340 + for (ptr = &nxi->v4; ptr; ptr = ptr->next)
8341 + if (v4_nx_addr_match(ptr, nxa, mask))
8345 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8349 +#include <net/inet_sock.h>
8352 + * Check if a given address matches for a socket
8354 + * nxi: the socket's nx_info if any
8355 + * addr: to be verified address
8358 +int v4_sock_addr_match (
8359 + struct nx_info *nxi,
8360 + struct inet_sock *inet,
8363 + __be32 saddr = inet->inet_rcv_saddr;
8364 + __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
8366 + if (addr && (saddr == addr || bcast == addr))
8369 + return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
8374 +/* inet related checks and helpers */
8383 +#include <linux/netdevice.h>
8384 +#include <linux/inetdevice.h>
8385 +#include <net/inet_sock.h>
8386 +#include <net/inet_timewait_sock.h>
8389 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8390 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
8391 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
8395 + * check if address is covered by socket
8397 + * sk: the socket to check against
8398 + * addr: the address in question (must be != 0)
8402 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
8404 + struct nx_info *nxi = sk->sk_nx_info;
8405 + __be32 saddr = sk->sk_rcv_saddr;
8407 + vxdprintk(VXD_CBIT(net, 5),
8408 + "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
8409 + sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
8410 + (sk->sk_socket?sk->sk_socket->flags:0));
8412 + if (saddr) { /* direct address match */
8413 + return v4_addr_match(nxa, saddr, -1);
8414 + } else if (nxi) { /* match against nx_info */
8415 + return v4_nx_addr_in_nx_info(nxi, nxa, -1);
8416 + } else { /* unrestricted any socket */
8424 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
8426 + vxdprintk(VXD_CBIT(net, 1),
8427 + "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
8428 + nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
8429 + nxi ? dev_in_nx_info(dev, nxi) : 0);
8431 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8433 + if (dev_in_nx_info(dev, nxi))
8440 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
8446 + return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
8450 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
8452 + vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
8453 + nxi, nxi ? nxi->nx_id : 0, ifa,
8454 + nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
8456 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8458 + if (v4_ifa_in_nx_info(ifa, nxi))
8464 +struct nx_v4_sock_addr {
8465 + __be32 saddr; /* Address used for validation */
8466 + __be32 baddr; /* Address used for socket bind */
8470 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
8471 + struct nx_v4_sock_addr *nsa)
8473 + struct sock *sk = &inet->sk;
8474 + struct nx_info *nxi = sk->sk_nx_info;
8475 + __be32 saddr = addr->sin_addr.s_addr;
8476 + __be32 baddr = saddr;
8478 + vxdprintk(VXD_CBIT(net, 3),
8479 + "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
8480 + sk, sk->sk_nx_info, sk->sk_socket,
8481 + (sk->sk_socket ? sk->sk_socket->flags : 0),
8485 + if (saddr == INADDR_ANY) {
8486 + if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
8487 + baddr = nxi->v4.ip[0].s_addr;
8488 + } else if (saddr == IPI_LOOPBACK) {
8489 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8490 + baddr = nxi->v4_lback.s_addr;
8491 + } else if (!ipv4_is_multicast(saddr) ||
8492 + !nx_info_ncaps(nxi, NXC_MULTICAST)) {
8493 + /* normal address bind */
8494 + if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
8495 + return -EADDRNOTAVAIL;
8499 + vxdprintk(VXD_CBIT(net, 3),
8500 + "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
8501 + sk, NIPQUAD(saddr), NIPQUAD(baddr));
8503 + nsa->saddr = saddr;
8504 + nsa->baddr = baddr;
8509 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
8511 + inet->inet_saddr = nsa->baddr;
8512 + inet->inet_rcv_saddr = nsa->baddr;
8517 + * helper to simplify inet_lookup_listener
8519 + * nxi: the socket's nx_info if any
8520 + * addr: to be verified address
8521 + * saddr: socket address
8523 +static inline int v4_inet_addr_match (
8524 + struct nx_info *nxi,
8528 + if (addr && (saddr == addr))
8531 + return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
8535 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
8537 + if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
8538 + (addr == nxi->v4_lback.s_addr))
8539 + return IPI_LOOPBACK;
8544 +int nx_info_has_v4(struct nx_info *nxi)
8550 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8555 +#else /* CONFIG_INET */
8558 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
8564 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8570 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8576 +int nx_info_has_v4(struct nx_info *nxi)
8581 +#endif /* CONFIG_INET */
8583 +#define current_nx_info_has_v4() \
8584 + nx_info_has_v4(current_nx_info())
8587 +// #warning duplicate inclusion
8589 diff -NurpP --minimal linux-3.13.10/include/linux/vs_inet6.h linux-3.13.10-vs2.3.6.11/include/linux/vs_inet6.h
8590 --- linux-3.13.10/include/linux/vs_inet6.h 1970-01-01 00:00:00.000000000 +0000
8591 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_inet6.h 2014-02-01 00:35:02.000000000 +0000
8593 +#ifndef _VS_INET6_H
8594 +#define _VS_INET6_H
8596 +#include "vserver/base.h"
8597 +#include "vserver/network.h"
8598 +#include "vserver/debug.h"
8600 +#include <net/ipv6.h>
8602 +#define NXAV6(a) &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
8603 +#define NXAV6_FMT "[%pI6/%pI6/%d:%04x]"
8609 +int v6_addr_match(struct nx_addr_v6 *nxa,
8610 + const struct in6_addr *addr, uint16_t mask)
8614 + switch (nxa->type & mask) {
8615 + case NXA_TYPE_MASK:
8616 + ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
8618 + case NXA_TYPE_ADDR:
8619 + ret = ipv6_addr_equal(&nxa->ip, addr);
8621 + case NXA_TYPE_ANY:
8625 + vxdprintk(VXD_CBIT(net, 0),
8626 + "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
8627 + nxa, NXAV6(nxa), addr, mask, ret);
8632 +int v6_addr_in_nx_info(struct nx_info *nxi,
8633 + const struct in6_addr *addr, uint16_t mask)
8635 + struct nx_addr_v6 *nxa;
8636 + unsigned long irqflags;
8642 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
8643 + for (nxa = &nxi->v6; nxa; nxa = nxa->next)
8644 + if (v6_addr_match(nxa, addr, mask))
8648 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8650 + vxdprintk(VXD_CBIT(net, 0),
8651 + "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
8652 + nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
8657 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
8659 + /* FIXME: needs full range checks */
8660 + return v6_addr_match(nxa, &addr->ip, mask);
8664 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
8666 + struct nx_addr_v6 *ptr;
8667 + unsigned long irqflags;
8670 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
8671 + for (ptr = &nxi->v6; ptr; ptr = ptr->next)
8672 + if (v6_nx_addr_match(ptr, nxa, mask))
8676 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8682 + * Check if a given address matches for a socket
8684 + * nxi: the socket's nx_info if any
8685 + * addr: to be verified address
8688 +int v6_sock_addr_match (
8689 + struct nx_info *nxi,
8690 + struct inet_sock *inet,
8691 + struct in6_addr *addr)
8693 + struct sock *sk = &inet->sk;
8694 + const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8696 + if (!ipv6_addr_any(addr) &&
8697 + ipv6_addr_equal(saddr, addr))
8699 + if (ipv6_addr_any(saddr))
8700 + return v6_addr_in_nx_info(nxi, addr, -1);
8705 + * check if address is covered by socket
8707 + * sk: the socket to check against
8708 + * addr: the address in question (must be != 0)
8712 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
8714 + struct nx_info *nxi = sk->sk_nx_info;
8715 + const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8717 + vxdprintk(VXD_CBIT(net, 5),
8718 + "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
8719 + sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
8720 + (sk->sk_socket?sk->sk_socket->flags:0));
8722 + if (!ipv6_addr_any(saddr)) { /* direct address match */
8723 + return v6_addr_match(nxa, saddr, -1);
8724 + } else if (nxi) { /* match against nx_info */
8725 + return v6_nx_addr_in_nx_info(nxi, nxa, -1);
8726 + } else { /* unrestricted any socket */
8732 +/* inet related checks and helpers */
8740 +#include <linux/netdevice.h>
8741 +#include <linux/inetdevice.h>
8742 +#include <net/inet_timewait_sock.h>
8745 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8746 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
8747 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
8752 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
8758 + return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
8762 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
8764 + vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
8765 + nxi, nxi ? nxi->nx_id : 0, ifa,
8766 + nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
8768 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8770 + if (v6_ifa_in_nx_info(ifa, nxi))
8776 +struct nx_v6_sock_addr {
8777 + struct in6_addr saddr; /* Address used for validation */
8778 + struct in6_addr baddr; /* Address used for socket bind */
8782 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
8783 + struct nx_v6_sock_addr *nsa)
8785 + // struct sock *sk = &inet->sk;
8786 + // struct nx_info *nxi = sk->sk_nx_info;
8787 + struct in6_addr saddr = addr->sin6_addr;
8788 + struct in6_addr baddr = saddr;
8790 + nsa->saddr = saddr;
8791 + nsa->baddr = baddr;
8796 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
8798 + // struct sock *sk = &inet->sk;
8799 + // struct in6_addr *saddr = inet6_rcv_saddr(sk);
8801 + // *saddr = nsa->baddr;
8802 + // inet->inet_saddr = nsa->baddr;
8806 +int nx_info_has_v6(struct nx_info *nxi)
8815 +#else /* CONFIG_IPV6 */
8818 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
8825 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8831 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8837 +int nx_info_has_v6(struct nx_info *nxi)
8842 +#endif /* CONFIG_IPV6 */
8844 +#define current_nx_info_has_v6() \
8845 + nx_info_has_v6(current_nx_info())
8848 +#warning duplicate inclusion
8850 diff -NurpP --minimal linux-3.13.10/include/linux/vs_limit.h linux-3.13.10-vs2.3.6.11/include/linux/vs_limit.h
8851 --- linux-3.13.10/include/linux/vs_limit.h 1970-01-01 00:00:00.000000000 +0000
8852 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_limit.h 2014-02-01 01:29:43.000000000 +0000
8854 +#ifndef _VS_LIMIT_H
8855 +#define _VS_LIMIT_H
8857 +#include "vserver/limit.h"
8858 +#include "vserver/base.h"
8859 +#include "vserver/context.h"
8860 +#include "vserver/debug.h"
8861 +#include "vserver/context.h"
8862 +#include "vserver/limit_int.h"
8865 +#define vx_acc_cres(v, d, p, r) \
8866 + __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
8868 +#define vx_acc_cres_cond(x, d, p, r) \
8869 + __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8870 + r, d, p, __FILE__, __LINE__)
8873 +#define vx_add_cres(v, a, p, r) \
8874 + __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
8875 +#define vx_sub_cres(v, a, p, r) vx_add_cres(v, -(a), p, r)
8877 +#define vx_add_cres_cond(x, a, p, r) \
8878 + __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8879 + r, a, p, __FILE__, __LINE__)
8880 +#define vx_sub_cres_cond(x, a, p, r) vx_add_cres_cond(x, -(a), p, r)
8883 +/* process and file limits */
8885 +#define vx_nproc_inc(p) \
8886 + vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
8888 +#define vx_nproc_dec(p) \
8889 + vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
8891 +#define vx_files_inc(f) \
8892 + vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
8894 +#define vx_files_dec(f) \
8895 + vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
8897 +#define vx_locks_inc(l) \
8898 + vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
8900 +#define vx_locks_dec(l) \
8901 + vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
8903 +#define vx_openfd_inc(f) \
8904 + vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
8906 +#define vx_openfd_dec(f) \
8907 + vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
8910 +#define vx_cres_avail(v, n, r) \
8911 + __vx_cres_avail(v, r, n, __FILE__, __LINE__)
8914 +#define vx_nproc_avail(n) \
8915 + vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
8917 +#define vx_files_avail(n) \
8918 + vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
8920 +#define vx_locks_avail(n) \
8921 + vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
8923 +#define vx_openfd_avail(n) \
8924 + vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
8927 +/* dentry limits */
8929 +#define vx_dentry_inc(d) do { \
8930 + if (d_count(d) == 1) \
8931 + vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY); \
8934 +#define vx_dentry_dec(d) do { \
8935 + if (d_count(d) == 0) \
8936 + vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY); \
8939 +#define vx_dentry_avail(n) \
8940 + vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
8943 +/* socket limits */
8945 +#define vx_sock_inc(s) \
8946 + vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
8948 +#define vx_sock_dec(s) \
8949 + vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
8951 +#define vx_sock_avail(n) \
8952 + vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
8955 +/* ipc resource limits */
8957 +#define vx_ipcmsg_add(v, u, a) \
8958 + vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
8960 +#define vx_ipcmsg_sub(v, u, a) \
8961 + vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
8963 +#define vx_ipcmsg_avail(v, a) \
8964 + vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
8967 +#define vx_ipcshm_add(v, k, a) \
8968 + vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8970 +#define vx_ipcshm_sub(v, k, a) \
8971 + vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8973 +#define vx_ipcshm_avail(v, a) \
8974 + vx_cres_avail(v, a, VLIMIT_SHMEM)
8977 +#define vx_semary_inc(a) \
8978 + vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
8980 +#define vx_semary_dec(a) \
8981 + vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
8984 +#define vx_nsems_add(a,n) \
8985 + vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
8987 +#define vx_nsems_sub(a,n) \
8988 + vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
8992 +#warning duplicate inclusion
8994 diff -NurpP --minimal linux-3.13.10/include/linux/vs_network.h linux-3.13.10-vs2.3.6.11/include/linux/vs_network.h
8995 --- linux-3.13.10/include/linux/vs_network.h 1970-01-01 00:00:00.000000000 +0000
8996 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_network.h 2014-01-31 20:38:03.000000000 +0000
8998 +#ifndef _NX_VS_NETWORK_H
8999 +#define _NX_VS_NETWORK_H
9001 +#include "vserver/context.h"
9002 +#include "vserver/network.h"
9003 +#include "vserver/base.h"
9004 +#include "vserver/check.h"
9005 +#include "vserver/debug.h"
9007 +#include <linux/sched.h>
9010 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9012 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9013 + const char *_file, int _line)
9018 + vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9019 + nxi, nxi ? nxi->nx_id : 0,
9020 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9023 + atomic_inc(&nxi->nx_usecnt);
9028 +extern void free_nx_info(struct nx_info *);
9030 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9032 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9037 + vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9038 + nxi, nxi ? nxi->nx_id : 0,
9039 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9042 + if (atomic_dec_and_test(&nxi->nx_usecnt))
9043 + free_nx_info(nxi);
9047 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9049 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9050 + const char *_file, int _line)
9053 + vxlprintk(VXD_CBIT(nid, 3),
9054 + "init_nx_info(%p[#%d.%d])",
9055 + nxi, nxi ? nxi->nx_id : 0,
9056 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9059 + atomic_inc(&nxi->nx_usecnt);
9065 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9067 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9068 + const char *_file, int _line)
9070 + struct nx_info *nxo;
9075 + vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9076 + nxi, nxi ? nxi->nx_id : 0,
9077 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9080 + atomic_inc(&nxi->nx_usecnt);
9081 + nxo = xchg(nxp, nxi);
9085 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9087 +static inline void __clr_nx_info(struct nx_info **nxp,
9088 + const char *_file, int _line)
9090 + struct nx_info *nxo;
9092 + nxo = xchg(nxp, NULL);
9096 + vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9097 + nxo, nxo ? nxo->nx_id : 0,
9098 + nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9101 + if (atomic_dec_and_test(&nxo->nx_usecnt))
9102 + free_nx_info(nxo);
9106 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9108 +static inline void __claim_nx_info(struct nx_info *nxi,
9109 + struct task_struct *task, const char *_file, int _line)
9111 + vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9112 + nxi, nxi ? nxi->nx_id : 0,
9113 + nxi?atomic_read(&nxi->nx_usecnt):0,
9114 + nxi?atomic_read(&nxi->nx_tasks):0,
9115 + task, _file, _line);
9117 + atomic_inc(&nxi->nx_tasks);
9121 +extern void unhash_nx_info(struct nx_info *);
9123 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9125 +static inline void __release_nx_info(struct nx_info *nxi,
9126 + struct task_struct *task, const char *_file, int _line)
9128 + vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9129 + nxi, nxi ? nxi->nx_id : 0,
9130 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9131 + nxi ? atomic_read(&nxi->nx_tasks) : 0,
9132 + task, _file, _line);
9136 + if (atomic_dec_and_test(&nxi->nx_tasks))
9137 + unhash_nx_info(nxi);
9141 +#define task_get_nx_info(i) __task_get_nx_info(i, __FILE__, __LINE__)
9143 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9144 + const char *_file, int _line)
9146 + struct nx_info *nxi;
9149 + vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9151 + nxi = __get_nx_info(p->nx_info, _file, _line);
9157 +static inline void exit_nx_info(struct task_struct *p)
9160 + release_nx_info(p->nx_info, p);
9165 +#warning duplicate inclusion
9167 diff -NurpP --minimal linux-3.13.10/include/linux/vs_pid.h linux-3.13.10-vs2.3.6.11/include/linux/vs_pid.h
9168 --- linux-3.13.10/include/linux/vs_pid.h 1970-01-01 00:00:00.000000000 +0000
9169 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_pid.h 2014-01-31 20:38:03.000000000 +0000
9174 +#include "vserver/base.h"
9175 +#include "vserver/check.h"
9176 +#include "vserver/context.h"
9177 +#include "vserver/debug.h"
9178 +#include "vserver/pid.h"
9179 +#include <linux/pid_namespace.h>
9182 +#define VXF_FAKE_INIT (VXF_INFO_INIT | VXF_STATE_INIT)
9185 +int vx_proc_task_visible(struct task_struct *task)
9187 + if ((task->pid == 1) &&
9188 + !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9189 + /* show a blend through init */
9191 + if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9198 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9202 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9204 + struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9206 + if (task && !vx_proc_task_visible(task)) {
9207 + vxdprintk(VXD_CBIT(misc, 6),
9208 + "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9209 + task, task->xid, task->pid,
9210 + current, current->xid, current->pid);
9211 + put_task_struct(task);
9219 +#warning duplicate inclusion
9221 diff -NurpP --minimal linux-3.13.10/include/linux/vs_sched.h linux-3.13.10-vs2.3.6.11/include/linux/vs_sched.h
9222 --- linux-3.13.10/include/linux/vs_sched.h 1970-01-01 00:00:00.000000000 +0000
9223 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_sched.h 2014-01-31 20:38:03.000000000 +0000
9225 +#ifndef _VS_SCHED_H
9226 +#define _VS_SCHED_H
9228 +#include "vserver/base.h"
9229 +#include "vserver/context.h"
9230 +#include "vserver/sched.h"
9233 +#define MAX_PRIO_BIAS 20
9234 +#define MIN_PRIO_BIAS -20
9237 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
9239 + struct vx_info *vxi = p->vx_info;
9242 + prio += vx_cpu(vxi, sched_pc).prio_bias;
9246 +static inline void vx_account_user(struct vx_info *vxi,
9247 + cputime_t cputime, int nice)
9251 + vx_cpu(vxi, sched_pc).user_ticks += cputime;
9254 +static inline void vx_account_system(struct vx_info *vxi,
9255 + cputime_t cputime, int idle)
9259 + vx_cpu(vxi, sched_pc).sys_ticks += cputime;
9263 +#warning duplicate inclusion
9265 diff -NurpP --minimal linux-3.13.10/include/linux/vs_socket.h linux-3.13.10-vs2.3.6.11/include/linux/vs_socket.h
9266 --- linux-3.13.10/include/linux/vs_socket.h 1970-01-01 00:00:00.000000000 +0000
9267 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_socket.h 2014-01-31 20:38:03.000000000 +0000
9269 +#ifndef _VS_SOCKET_H
9270 +#define _VS_SOCKET_H
9272 +#include "vserver/debug.h"
9273 +#include "vserver/base.h"
9274 +#include "vserver/cacct.h"
9275 +#include "vserver/context.h"
9276 +#include "vserver/tag.h"
9279 +/* socket accounting */
9281 +#include <linux/socket.h>
9283 +static inline int vx_sock_type(int family)
9287 + return VXA_SOCK_UNSPEC;
9289 + return VXA_SOCK_UNIX;
9291 + return VXA_SOCK_INET;
9293 + return VXA_SOCK_INET6;
9295 + return VXA_SOCK_PACKET;
9297 + return VXA_SOCK_OTHER;
9301 +#define vx_acc_sock(v, f, p, s) \
9302 + __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
9304 +static inline void __vx_acc_sock(struct vx_info *vxi,
9305 + int family, int pos, int size, char *file, int line)
9308 + int type = vx_sock_type(family);
9310 + atomic_long_inc(&vxi->cacct.sock[type][pos].count);
9311 + atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
9315 +#define vx_sock_recv(sk, s) \
9316 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
9317 +#define vx_sock_send(sk, s) \
9318 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
9319 +#define vx_sock_fail(sk, s) \
9320 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
9323 +#define sock_vx_init(s) do { \
9324 + (s)->sk_xid = 0; \
9325 + (s)->sk_vx_info = NULL; \
9328 +#define sock_nx_init(s) do { \
9329 + (s)->sk_nid = 0; \
9330 + (s)->sk_nx_info = NULL; \
9334 +#warning duplicate inclusion
9336 diff -NurpP --minimal linux-3.13.10/include/linux/vs_tag.h linux-3.13.10-vs2.3.6.11/include/linux/vs_tag.h
9337 --- linux-3.13.10/include/linux/vs_tag.h 1970-01-01 00:00:00.000000000 +0000
9338 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_tag.h 2014-01-31 20:38:03.000000000 +0000
9343 +#include <linux/vserver/tag.h>
9345 +/* check conditions */
9347 +#define DX_ADMIN 0x0001
9348 +#define DX_WATCH 0x0002
9349 +#define DX_HOSTID 0x0008
9351 +#define DX_IDENT 0x0010
9353 +#define DX_ARG_MASK 0x0010
9356 +#define dx_task_tag(t) ((t)->tag)
9358 +#define dx_current_tag() dx_task_tag(current)
9360 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
9362 +#define dx_weak_check(c, m) ((m) ? dx_check(c, m) : 1)
9366 + * check current context for ADMIN/WATCH and
9367 + * optionally against supplied argument
9369 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
9371 + if (mode & DX_ARG_MASK) {
9372 + if ((mode & DX_IDENT) && (id == cid))
9375 + return (((mode & DX_ADMIN) && (cid == 0)) ||
9376 + ((mode & DX_WATCH) && (cid == 1)) ||
9377 + ((mode & DX_HOSTID) && (id == 0)));
9381 +int dx_permission(const struct inode *inode, int mask);
9385 +#warning duplicate inclusion
9387 diff -NurpP --minimal linux-3.13.10/include/linux/vs_time.h linux-3.13.10-vs2.3.6.11/include/linux/vs_time.h
9388 --- linux-3.13.10/include/linux/vs_time.h 1970-01-01 00:00:00.000000000 +0000
9389 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_time.h 2014-01-31 20:38:03.000000000 +0000
9395 +/* time faking stuff */
9397 +#ifdef CONFIG_VSERVER_VTIME
9399 +extern void vx_adjust_timespec(struct timespec *ts);
9400 +extern int vx_settimeofday(const struct timespec *ts);
9403 +#define vx_adjust_timespec(t) do { } while (0)
9404 +#define vx_settimeofday(t) do_settimeofday(t)
9408 +#warning duplicate inclusion
9410 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/base.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/base.h
9411 --- linux-3.13.10/include/linux/vserver/base.h 1970-01-01 00:00:00.000000000 +0000
9412 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/base.h 2014-01-31 20:38:03.000000000 +0000
9414 +#ifndef _VSERVER_BASE_H
9415 +#define _VSERVER_BASE_H
9418 +/* context state changes */
9430 +#define vx_task_xid(t) ((t)->xid)
9432 +#define vx_current_xid() vx_task_xid(current)
9434 +#define current_vx_info() (current->vx_info)
9437 +#define nx_task_nid(t) ((t)->nid)
9439 +#define nx_current_nid() nx_task_nid(current)
9441 +#define current_nx_info() (current->nx_info)
9444 +/* generic flag merging */
9446 +#define vs_check_flags(v, m, f) (((v) & (m)) ^ (f))
9448 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
9450 +#define vs_mask_mask(v, f, m) (((v) & ~(m)) | ((v) & (f) & (m)))
9452 +#define vs_check_bit(v, n) ((v) & (1LL << (n)))
9455 +/* context flags */
9457 +#define __vx_flags(v) ((v) ? (v)->vx_flags : 0)
9459 +#define vx_current_flags() __vx_flags(current_vx_info())
9461 +#define vx_info_flags(v, m, f) \
9462 + vs_check_flags(__vx_flags(v), m, f)
9464 +#define task_vx_flags(t, m, f) \
9465 + ((t) && vx_info_flags((t)->vx_info, m, f))
9467 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
9472 +#define __vx_ccaps(v) ((v) ? (v)->vx_ccaps : 0)
9474 +#define vx_current_ccaps() __vx_ccaps(current_vx_info())
9476 +#define vx_info_ccaps(v, c) (__vx_ccaps(v) & (c))
9478 +#define vx_ccaps(c) vx_info_ccaps(current_vx_info(), (c))
9482 +/* network flags */
9484 +#define __nx_flags(n) ((n) ? (n)->nx_flags : 0)
9486 +#define nx_current_flags() __nx_flags(current_nx_info())
9488 +#define nx_info_flags(n, m, f) \
9489 + vs_check_flags(__nx_flags(n), m, f)
9491 +#define task_nx_flags(t, m, f) \
9492 + ((t) && nx_info_flags((t)->nx_info, m, f))
9494 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
9499 +#define __nx_ncaps(n) ((n) ? (n)->nx_ncaps : 0)
9501 +#define nx_current_ncaps() __nx_ncaps(current_nx_info())
9503 +#define nx_info_ncaps(n, c) (__nx_ncaps(n) & (c))
9505 +#define nx_ncaps(c) nx_info_ncaps(current_nx_info(), c)
9508 +/* context mask capabilities */
9510 +#define __vx_mcaps(v) ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
9512 +#define vx_info_mcaps(v, c) (__vx_mcaps(v) & (c))
9514 +#define vx_mcaps(c) vx_info_mcaps(current_vx_info(), c)
9517 +/* context bcap mask */
9519 +#define __vx_bcaps(v) ((v)->vx_bcaps)
9521 +#define vx_current_bcaps() __vx_bcaps(current_vx_info())
9524 +/* mask given bcaps */
9526 +#define vx_info_mbcaps(v, c) ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
9528 +#define vx_mbcaps(c) vx_info_mbcaps(current_vx_info(), c)
9531 +/* masked cap_bset */
9533 +#define vx_info_cap_bset(v) vx_info_mbcaps(v, current->cap_bset)
9535 +#define vx_current_cap_bset() vx_info_cap_bset(current_vx_info())
9538 +#define vx_info_mbcap(v, b) \
9539 + (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
9540 + vx_info_bcaps(v, b) : (b))
9542 +#define task_vx_mbcap(t, b) \
9543 + vx_info_mbcap((t)->vx_info, (t)->b)
9545 +#define vx_mbcap(b) task_vx_mbcap(current, b)
9548 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
9550 +#define vx_capable(b, c) (capable(b) || \
9551 + (cap_raised(current_cap(), b) && vx_ccaps(c)))
9553 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
9554 + (cap_raised(current_cap(), b) && vx_ccaps(c)))
9556 +#define nx_capable(b, c) (capable(b) || \
9557 + (cap_raised(current_cap(), b) && nx_ncaps(c)))
9559 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
9560 + (cap_raised(current_cap(), b) && nx_ncaps(c)))
9562 +#define vx_task_initpid(t, n) \
9563 + ((t)->vx_info && \
9564 + ((t)->vx_info->vx_initpid == (n)))
9566 +#define vx_current_initpid(n) vx_task_initpid(current, n)
9569 +/* context unshare mask */
9571 +#define __vx_umask(v) ((v)->vx_umask)
9573 +#define vx_current_umask() __vx_umask(current_vx_info())
9575 +#define vx_can_unshare(b, f) (capable(b) || \
9576 + (cap_raised(current_cap(), b) && \
9577 + !((f) & ~vx_current_umask())))
9579 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
9580 + (cap_raised(current_cap(), b) && \
9581 + !((f) & ~vx_current_umask())))
9583 +#define __vx_wmask(v) ((v)->vx_wmask)
9585 +#define vx_current_wmask() __vx_wmask(current_vx_info())
9588 +#define __vx_state(v) ((v) ? ((v)->vx_state) : 0)
9590 +#define vx_info_state(v, m) (__vx_state(v) & (m))
9593 +#define __nx_state(n) ((n) ? ((n)->nx_state) : 0)
9595 +#define nx_info_state(n, m) (__nx_state(n) & (m))
9598 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct.h
9599 --- linux-3.13.10/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
9600 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct.h 2014-01-31 20:38:03.000000000 +0000
9602 +#ifndef _VSERVER_CACCT_H
9603 +#define _VSERVER_CACCT_H
9606 +enum sock_acc_field {
9607 + VXA_SOCK_UNSPEC = 0,
9613 + VXA_SOCK_SIZE /* array size */
9616 +#endif /* _VSERVER_CACCT_H */
9617 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_cmd.h
9618 --- linux-3.13.10/include/linux/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
9619 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_cmd.h 2014-01-31 20:38:03.000000000 +0000
9621 +#ifndef _VSERVER_CACCT_CMD_H
9622 +#define _VSERVER_CACCT_CMD_H
9625 +#include <linux/compiler.h>
9626 +#include <uapi/vserver/cacct_cmd.h>
9628 +extern int vc_sock_stat(struct vx_info *, void __user *);
9630 +#endif /* _VSERVER_CACCT_CMD_H */
9631 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_def.h
9632 --- linux-3.13.10/include/linux/vserver/cacct_def.h 1970-01-01 00:00:00.000000000 +0000
9633 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_def.h 2014-01-31 20:38:03.000000000 +0000
9635 +#ifndef _VSERVER_CACCT_DEF_H
9636 +#define _VSERVER_CACCT_DEF_H
9638 +#include <asm/atomic.h>
9639 +#include <linux/vserver/cacct.h>
9642 +struct _vx_sock_acc {
9643 + atomic_long_t count;
9644 + atomic_long_t total;
9647 +/* context sub struct */
9650 + struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
9652 + atomic_t page[6][8];
9655 +#ifdef CONFIG_VSERVER_DEBUG
9657 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
9661 + printk("\t_vx_cacct:");
9662 + for (i = 0; i < 6; i++) {
9663 + struct _vx_sock_acc *ptr = cacct->sock[i];
9665 + printk("\t [%d] =", i);
9666 + for (j = 0; j < 3; j++) {
9667 + printk(" [%d] = %8lu, %8lu", j,
9668 + atomic_long_read(&ptr[j].count),
9669 + atomic_long_read(&ptr[j].total));
9677 +#endif /* _VSERVER_CACCT_DEF_H */
9678 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct_int.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_int.h
9679 --- linux-3.13.10/include/linux/vserver/cacct_int.h 1970-01-01 00:00:00.000000000 +0000
9680 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_int.h 2014-01-31 20:38:03.000000000 +0000
9682 +#ifndef _VSERVER_CACCT_INT_H
9683 +#define _VSERVER_CACCT_INT_H
9686 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
9688 + return atomic_long_read(&cacct->sock[type][pos].count);
9693 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
9695 + return atomic_long_read(&cacct->sock[type][pos].total);
9698 +#endif /* _VSERVER_CACCT_INT_H */
9699 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/check.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/check.h
9700 --- linux-3.13.10/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
9701 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/check.h 2014-01-31 20:38:03.000000000 +0000
9703 +#ifndef _VSERVER_CHECK_H
9704 +#define _VSERVER_CHECK_H
9707 +#define MAX_S_CONTEXT 65535 /* Arbitrary limit */
9709 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
9710 +#define MIN_D_CONTEXT 49152 /* dynamic contexts start here */
9712 +#define MIN_D_CONTEXT 65536
9715 +/* check conditions */
9717 +#define VS_ADMIN 0x0001
9718 +#define VS_WATCH 0x0002
9719 +#define VS_HIDE 0x0004
9720 +#define VS_HOSTID 0x0008
9722 +#define VS_IDENT 0x0010
9723 +#define VS_EQUIV 0x0020
9724 +#define VS_PARENT 0x0040
9725 +#define VS_CHILD 0x0080
9727 +#define VS_ARG_MASK 0x00F0
9729 +#define VS_DYNAMIC 0x0100
9730 +#define VS_STATIC 0x0200
9732 +#define VS_ATR_MASK 0x0F00
9734 +#ifdef CONFIG_VSERVER_PRIVACY
9735 +#define VS_ADMIN_P (0)
9736 +#define VS_WATCH_P (0)
9738 +#define VS_ADMIN_P VS_ADMIN
9739 +#define VS_WATCH_P VS_WATCH
9742 +#define VS_HARDIRQ 0x1000
9743 +#define VS_SOFTIRQ 0x2000
9744 +#define VS_IRQ 0x4000
9746 +#define VS_IRQ_MASK 0xF000
9748 +#include <linux/hardirq.h>
9751 + * check current context for ADMIN/WATCH and
9752 + * optionally against supplied argument
9754 +static inline int __vs_check(int cid, int id, unsigned int mode)
9756 + if (mode & VS_ARG_MASK) {
9757 + if ((mode & VS_IDENT) && (id == cid))
9760 + if (mode & VS_ATR_MASK) {
9761 + if ((mode & VS_DYNAMIC) &&
9762 + (id >= MIN_D_CONTEXT) &&
9763 + (id <= MAX_S_CONTEXT))
9765 + if ((mode & VS_STATIC) &&
9766 + (id > 1) && (id < MIN_D_CONTEXT))
9769 + if (mode & VS_IRQ_MASK) {
9770 + if ((mode & VS_IRQ) && unlikely(in_interrupt()))
9772 + if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
9774 + if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
9777 + return (((mode & VS_ADMIN) && (cid == 0)) ||
9778 + ((mode & VS_WATCH) && (cid == 1)) ||
9779 + ((mode & VS_HOSTID) && (id == 0)));
9782 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
9784 +#define vx_weak_check(c, m) ((m) ? vx_check(c, m) : 1)
9787 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
9789 +#define nx_weak_check(c, m) ((m) ? nx_check(c, m) : 1)
9792 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/context.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/context.h
9793 --- linux-3.13.10/include/linux/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
9794 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/context.h 2014-01-31 20:38:03.000000000 +0000
9796 +#ifndef _VSERVER_CONTEXT_H
9797 +#define _VSERVER_CONTEXT_H
9800 +#include <linux/list.h>
9801 +#include <linux/spinlock.h>
9802 +#include <linux/rcupdate.h>
9803 +#include <uapi/vserver/context.h>
9805 +#include "limit_def.h"
9806 +#include "sched_def.h"
9807 +#include "cvirt_def.h"
9808 +#include "cacct_def.h"
9809 +#include "device_def.h"
9811 +#define VX_SPACES 2
9813 +struct _vx_info_pc {
9814 + struct _vx_sched_pc sched_pc;
9815 + struct _vx_cvirt_pc cvirt_pc;
9819 + unsigned long vx_nsmask; /* assignment mask */
9820 + struct nsproxy *vx_nsproxy; /* private namespaces */
9821 + struct fs_struct *vx_fs; /* private namespace fs */
9822 + const struct cred *vx_cred; /* task credentials */
9826 + struct hlist_node vx_hlist; /* linked list of contexts */
9827 + vxid_t vx_id; /* context id */
9828 + atomic_t vx_usecnt; /* usage count */
9829 + atomic_t vx_tasks; /* tasks count */
9830 + struct vx_info *vx_parent; /* parent context */
9831 + int vx_state; /* context state */
9833 + struct _vx_space space[VX_SPACES]; /* namespace store */
9835 + uint64_t vx_flags; /* context flags */
9836 + uint64_t vx_ccaps; /* context caps (vserver) */
9837 + uint64_t vx_umask; /* unshare mask (guest) */
9838 + uint64_t vx_wmask; /* warn mask (guest) */
9839 + kernel_cap_t vx_bcaps; /* bounding caps (system) */
9841 + struct task_struct *vx_reaper; /* guest reaper process */
9842 + pid_t vx_initpid; /* PID of guest init */
9843 + int64_t vx_badness_bias; /* OOM points bias */
9845 + struct _vx_limit limit; /* vserver limits */
9846 + struct _vx_sched sched; /* vserver scheduler */
9847 + struct _vx_cvirt cvirt; /* virtual/bias stuff */
9848 + struct _vx_cacct cacct; /* context accounting */
9850 + struct _vx_device dmap; /* default device map targets */
9853 + struct _vx_info_pc info_pc; /* per cpu data */
9855 + struct _vx_info_pc *ptr_pc; /* per cpu array */
9858 + wait_queue_head_t vx_wait; /* context exit waitqueue */
9859 + int reboot_cmd; /* last sys_reboot() cmd */
9860 + int exit_code; /* last process exit code */
9862 + char vx_name[65]; /* vserver name */
9866 +#define vx_ptr_pc(vxi) (&(vxi)->info_pc)
9867 +#define vx_per_cpu(vxi, v, id) vx_ptr_pc(vxi)->v
9869 +#define vx_ptr_pc(vxi) ((vxi)->ptr_pc)
9870 +#define vx_per_cpu(vxi, v, id) per_cpu_ptr(vx_ptr_pc(vxi), id)->v
9873 +#define vx_cpu(vxi, v) vx_per_cpu(vxi, v, smp_processor_id())
9876 +struct vx_info_save {
9877 + struct vx_info *vxi;
9884 +#define VXS_HASHED 0x0001
9885 +#define VXS_PAUSED 0x0010
9886 +#define VXS_SHUTDOWN 0x0100
9887 +#define VXS_HELPER 0x1000
9888 +#define VXS_RELEASED 0x8000
9891 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
9892 +extern void release_vx_info(struct vx_info *, struct task_struct *);
9894 +extern struct vx_info *lookup_vx_info(int);
9895 +extern struct vx_info *lookup_or_create_vx_info(int);
9897 +extern int get_xid_list(int, unsigned int *, int);
9898 +extern int xid_is_hashed(vxid_t);
9900 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
9902 +extern long vs_state_change(struct vx_info *, unsigned int);
9905 +#endif /* _VSERVER_CONTEXT_H */
9906 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/context_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/context_cmd.h
9907 --- linux-3.13.10/include/linux/vserver/context_cmd.h 1970-01-01 00:00:00.000000000 +0000
9908 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/context_cmd.h 2014-01-31 20:38:03.000000000 +0000
9910 +#ifndef _VSERVER_CONTEXT_CMD_H
9911 +#define _VSERVER_CONTEXT_CMD_H
9913 +#include <uapi/vserver/context_cmd.h>
9915 +extern int vc_task_xid(uint32_t);
9917 +extern int vc_vx_info(struct vx_info *, void __user *);
9919 +extern int vc_ctx_stat(struct vx_info *, void __user *);
9921 +extern int vc_ctx_create(uint32_t, void __user *);
9922 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
9924 +extern int vc_get_cflags(struct vx_info *, void __user *);
9925 +extern int vc_set_cflags(struct vx_info *, void __user *);
9927 +extern int vc_get_ccaps(struct vx_info *, void __user *);
9928 +extern int vc_set_ccaps(struct vx_info *, void __user *);
9930 +extern int vc_get_bcaps(struct vx_info *, void __user *);
9931 +extern int vc_set_bcaps(struct vx_info *, void __user *);
9933 +extern int vc_get_umask(struct vx_info *, void __user *);
9934 +extern int vc_set_umask(struct vx_info *, void __user *);
9936 +extern int vc_get_wmask(struct vx_info *, void __user *);
9937 +extern int vc_set_wmask(struct vx_info *, void __user *);
9939 +extern int vc_get_badness(struct vx_info *, void __user *);
9940 +extern int vc_set_badness(struct vx_info *, void __user *);
9942 +#endif /* _VSERVER_CONTEXT_CMD_H */
9943 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cvirt.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt.h
9944 --- linux-3.13.10/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
9945 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt.h 2014-01-31 20:38:03.000000000 +0000
9947 +#ifndef _VSERVER_CVIRT_H
9948 +#define _VSERVER_CVIRT_H
9952 +void vx_vsi_boottime(struct timespec *);
9954 +void vx_vsi_uptime(struct timespec *, struct timespec *);
9959 +void vx_update_load(struct vx_info *);
9962 +int vx_do_syslog(int, char __user *, int);
9964 +#endif /* _VSERVER_CVIRT_H */
9965 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cvirt_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_cmd.h
9966 --- linux-3.13.10/include/linux/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
9967 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_cmd.h 2014-01-31 20:38:03.000000000 +0000
9969 +#ifndef _VSERVER_CVIRT_CMD_H
9970 +#define _VSERVER_CVIRT_CMD_H
9973 +#include <linux/compiler.h>
9974 +#include <uapi/vserver/cvirt_cmd.h>
9976 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
9977 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
9979 +extern int vc_virt_stat(struct vx_info *, void __user *);
9981 +#endif /* _VSERVER_CVIRT_CMD_H */
9982 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cvirt_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_def.h
9983 --- linux-3.13.10/include/linux/vserver/cvirt_def.h 1970-01-01 00:00:00.000000000 +0000
9984 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_def.h 2014-01-31 20:38:03.000000000 +0000
9986 +#ifndef _VSERVER_CVIRT_DEF_H
9987 +#define _VSERVER_CVIRT_DEF_H
9989 +#include <linux/jiffies.h>
9990 +#include <linux/spinlock.h>
9991 +#include <linux/wait.h>
9992 +#include <linux/time.h>
9993 +#include <asm/atomic.h>
9996 +struct _vx_usage_stat {
10000 + uint64_t softirq;
10006 +struct _vx_syslog {
10007 + wait_queue_head_t log_wait;
10008 + spinlock_t logbuf_lock; /* lock for the log buffer */
10010 + unsigned long log_start; /* next char to be read by syslog() */
10011 + unsigned long con_start; /* next char to be sent to consoles */
10012 + unsigned long log_end; /* most-recently-written-char + 1 */
10013 + unsigned long logged_chars; /* #chars since last read+clear operation */
10015 + char log_buf[1024];
10019 +/* context sub struct */
10021 +struct _vx_cvirt {
10022 + atomic_t nr_threads; /* number of current threads */
10023 + atomic_t nr_running; /* number of running threads */
10024 + atomic_t nr_uninterruptible; /* number of uninterruptible threads */
10026 + atomic_t nr_onhold; /* processes on hold */
10027 + uint32_t onhold_last; /* jiffies when put on hold */
10029 + struct timespec bias_ts; /* time offset to the host */
10030 + struct timespec bias_idle;
10031 + struct timespec bias_uptime; /* context creation point */
10032 + uint64_t bias_clock; /* offset in clock_t */
10034 + spinlock_t load_lock; /* lock for the load averages */
10035 + atomic_t load_updates; /* nr of load updates done so far */
10036 + uint32_t load_last; /* last time load was calculated */
10037 + uint32_t load[3]; /* load averages 1,5,15 */
10039 + atomic_t total_forks; /* number of forks so far */
10041 + struct _vx_syslog syslog;
10044 +struct _vx_cvirt_pc {
10045 + struct _vx_usage_stat cpustat;
10049 +#ifdef CONFIG_VSERVER_DEBUG
10051 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10053 + printk("\t_vx_cvirt:\n");
10054 + printk("\t threads: %4d, %4d, %4d, %4d\n",
10055 + atomic_read(&cvirt->nr_threads),
10056 + atomic_read(&cvirt->nr_running),
10057 + atomic_read(&cvirt->nr_uninterruptible),
10058 + atomic_read(&cvirt->nr_onhold));
10059 + /* add rest here */
10060 + printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10065 +#endif /* _VSERVER_CVIRT_DEF_H */
10066 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/debug.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug.h
10067 --- linux-3.13.10/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
10068 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug.h 2014-01-31 20:38:03.000000000 +0000
10070 +#ifndef _VSERVER_DEBUG_H
10071 +#define _VSERVER_DEBUG_H
10074 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10075 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10076 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10078 +#define VXD_DEV(d) (d), (d)->bd_inode->i_ino, \
10079 + imajor((d)->bd_inode), iminor((d)->bd_inode)
10080 +#define VXF_DEV "%p[%lu,%d:%d]"
10082 +#if defined(CONFIG_QUOTES_UTF8)
10083 +#define VS_Q_LQM "\xc2\xbb"
10084 +#define VS_Q_RQM "\xc2\xab"
10085 +#elif defined(CONFIG_QUOTES_ASCII)
10086 +#define VS_Q_LQM "\x27"
10087 +#define VS_Q_RQM "\x27"
10089 +#define VS_Q_LQM "\xbb"
10090 +#define VS_Q_RQM "\xab"
10093 +#define VS_Q(f) VS_Q_LQM f VS_Q_RQM
10096 +#define vxd_path(p) \
10097 + ({ static char _buffer[PATH_MAX]; \
10098 + d_path(p, _buffer, sizeof(_buffer)); })
10100 +#define vxd_cond_path(n) \
10101 + ((n) ? vxd_path(&(n)->path) : "<null>" )
10104 +#ifdef CONFIG_VSERVER_DEBUG
10106 +extern unsigned int vs_debug_switch;
10107 +extern unsigned int vs_debug_xid;
10108 +extern unsigned int vs_debug_nid;
10109 +extern unsigned int vs_debug_tag;
10110 +extern unsigned int vs_debug_net;
10111 +extern unsigned int vs_debug_limit;
10112 +extern unsigned int vs_debug_cres;
10113 +extern unsigned int vs_debug_dlim;
10114 +extern unsigned int vs_debug_quota;
10115 +extern unsigned int vs_debug_cvirt;
10116 +extern unsigned int vs_debug_space;
10117 +extern unsigned int vs_debug_perm;
10118 +extern unsigned int vs_debug_misc;
10121 +#define VX_LOGLEVEL "vxD: "
10122 +#define VX_PROC_FMT "%p: "
10123 +#define VX_PROCESS current
10125 +#define vxdprintk(c, f, x...) \
10128 + printk(VX_LOGLEVEL VX_PROC_FMT f "\n", \
10129 + VX_PROCESS , ##x); \
10132 +#define vxlprintk(c, f, x...) \
10135 + printk(VX_LOGLEVEL f " @%s:%d\n", x); \
10138 +#define vxfprintk(c, f, x...) \
10141 + printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10147 +void dump_vx_info(struct vx_info *, int);
10148 +void dump_vx_info_inactive(int);
10150 +#else /* CONFIG_VSERVER_DEBUG */
10152 +#define vs_debug_switch 0
10153 +#define vs_debug_xid 0
10154 +#define vs_debug_nid 0
10155 +#define vs_debug_tag 0
10156 +#define vs_debug_net 0
10157 +#define vs_debug_limit 0
10158 +#define vs_debug_cres 0
10159 +#define vs_debug_dlim 0
10160 +#define vs_debug_quota 0
10161 +#define vs_debug_cvirt 0
10162 +#define vs_debug_space 0
10163 +#define vs_debug_perm 0
10164 +#define vs_debug_misc 0
10166 +#define vxdprintk(x...) do { } while (0)
10167 +#define vxlprintk(x...) do { } while (0)
10168 +#define vxfprintk(x...) do { } while (0)
10170 +#endif /* CONFIG_VSERVER_DEBUG */
10173 +#ifdef CONFIG_VSERVER_WARN
10175 +#define VX_WARNLEVEL KERN_WARNING "vxW: "
10176 +#define VX_WARN_TASK "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10177 +#define VX_WARN_XID "[xid #%u] "
10178 +#define VX_WARN_NID "[nid #%u] "
10179 +#define VX_WARN_TAG "[tag #%u] "
10181 +#define vxwprintk(c, f, x...) \
10184 + printk(VX_WARNLEVEL f "\n", ##x); \
10187 +#else /* CONFIG_VSERVER_WARN */
10189 +#define vxwprintk(x...) do { } while (0)
10191 +#endif /* CONFIG_VSERVER_WARN */
10193 +#define vxwprintk_task(c, f, x...) \
10194 + vxwprintk(c, VX_WARN_TASK f, \
10195 + current->comm, current->pid, \
10196 + current->xid, current->nid, \
10197 + current->tag, ##x)
10198 +#define vxwprintk_xid(c, f, x...) \
10199 + vxwprintk(c, VX_WARN_XID f, current->xid, x)
10200 +#define vxwprintk_nid(c, f, x...) \
10201 + vxwprintk(c, VX_WARN_NID f, current->nid, x)
10202 +#define vxwprintk_tag(c, f, x...) \
10203 + vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10205 +#ifdef CONFIG_VSERVER_DEBUG
10206 +#define vxd_assert_lock(l) assert_spin_locked(l)
10207 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10208 + "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10210 +#define vxd_assert_lock(l) do { } while (0)
10211 +#define vxd_assert(c, f, x...) do { } while (0)
10215 +#endif /* _VSERVER_DEBUG_H */
10216 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/debug_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug_cmd.h
10217 --- linux-3.13.10/include/linux/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
10218 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug_cmd.h 2014-01-31 20:38:03.000000000 +0000
10220 +#ifndef _VSERVER_DEBUG_CMD_H
10221 +#define _VSERVER_DEBUG_CMD_H
10223 +#include <uapi/vserver/debug_cmd.h>
10226 +#ifdef CONFIG_COMPAT
10228 +#include <asm/compat.h>
10230 +struct vcmd_read_history_v0_x32 {
10233 + compat_uptr_t data_ptr;
10236 +struct vcmd_read_monitor_v0_x32 {
10239 + compat_uptr_t data_ptr;
10242 +#endif /* CONFIG_COMPAT */
10244 +extern int vc_dump_history(uint32_t);
10246 +extern int vc_read_history(uint32_t, void __user *);
10247 +extern int vc_read_monitor(uint32_t, void __user *);
10249 +#ifdef CONFIG_COMPAT
10251 +extern int vc_read_history_x32(uint32_t, void __user *);
10252 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10254 +#endif /* CONFIG_COMPAT */
10256 +#endif /* _VSERVER_DEBUG_CMD_H */
10257 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/device.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/device.h
10258 --- linux-3.13.10/include/linux/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
10259 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device.h 2014-01-31 20:38:03.000000000 +0000
10261 +#ifndef _VSERVER_DEVICE_H
10262 +#define _VSERVER_DEVICE_H
10265 +#include <uapi/vserver/device.h>
10267 +#else /* _VSERVER_DEVICE_H */
10268 +#warning duplicate inclusion
10269 +#endif /* _VSERVER_DEVICE_H */
10270 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/device_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_cmd.h
10271 --- linux-3.13.10/include/linux/vserver/device_cmd.h 1970-01-01 00:00:00.000000000 +0000
10272 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_cmd.h 2014-01-31 20:38:03.000000000 +0000
10274 +#ifndef _VSERVER_DEVICE_CMD_H
10275 +#define _VSERVER_DEVICE_CMD_H
10277 +#include <uapi/vserver/device_cmd.h>
10280 +#ifdef CONFIG_COMPAT
10282 +#include <asm/compat.h>
10284 +struct vcmd_set_mapping_v0_x32 {
10285 + compat_uptr_t device_ptr;
10286 + compat_uptr_t target_ptr;
10290 +#endif /* CONFIG_COMPAT */
10292 +#include <linux/compiler.h>
10294 +extern int vc_set_mapping(struct vx_info *, void __user *);
10295 +extern int vc_unset_mapping(struct vx_info *, void __user *);
10297 +#ifdef CONFIG_COMPAT
10299 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
10300 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
10302 +#endif /* CONFIG_COMPAT */
10304 +#endif /* _VSERVER_DEVICE_CMD_H */
10305 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/device_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_def.h
10306 --- linux-3.13.10/include/linux/vserver/device_def.h 1970-01-01 00:00:00.000000000 +0000
10307 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_def.h 2014-01-31 20:38:03.000000000 +0000
10309 +#ifndef _VSERVER_DEVICE_DEF_H
10310 +#define _VSERVER_DEVICE_DEF_H
10312 +#include <linux/types.h>
10314 +struct vx_dmap_target {
10319 +struct _vx_device {
10320 +#ifdef CONFIG_VSERVER_DEVICE
10321 + struct vx_dmap_target targets[2];
10325 +#endif /* _VSERVER_DEVICE_DEF_H */
10326 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/dlimit.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit.h
10327 --- linux-3.13.10/include/linux/vserver/dlimit.h 1970-01-01 00:00:00.000000000 +0000
10328 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit.h 2014-01-31 20:38:03.000000000 +0000
10330 +#ifndef _VSERVER_DLIMIT_H
10331 +#define _VSERVER_DLIMIT_H
10333 +#include "switch.h"
10338 +/* keep in sync with CDLIM_INFINITY */
10340 +#define DLIM_INFINITY (~0ULL)
10342 +#include <linux/spinlock.h>
10343 +#include <linux/rcupdate.h>
10345 +struct super_block;
10348 + struct hlist_node dl_hlist; /* linked list of contexts */
10349 + struct rcu_head dl_rcu; /* the rcu head */
10350 + vtag_t dl_tag; /* context tag */
10351 + atomic_t dl_usecnt; /* usage count */
10352 + atomic_t dl_refcnt; /* reference count */
10354 + struct super_block *dl_sb; /* associated superblock */
10356 + spinlock_t dl_lock; /* protect the values */
10358 + unsigned long long dl_space_used; /* used space in bytes */
10359 + unsigned long long dl_space_total; /* maximum space in bytes */
10360 + unsigned long dl_inodes_used; /* used inodes */
10361 + unsigned long dl_inodes_total; /* maximum inodes */
10363 + unsigned int dl_nrlmult; /* non root limit mult */
10368 +extern void rcu_free_dl_info(struct rcu_head *);
10369 +extern void unhash_dl_info(struct dl_info *);
10371 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
10376 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
10378 +typedef uint64_t dlsize_t;
10380 +#endif /* __KERNEL__ */
10381 +#else /* _VSERVER_DLIMIT_H */
10382 +#warning duplicate inclusion
10383 +#endif /* _VSERVER_DLIMIT_H */
10384 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/dlimit_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit_cmd.h
10385 --- linux-3.13.10/include/linux/vserver/dlimit_cmd.h 1970-01-01 00:00:00.000000000 +0000
10386 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit_cmd.h 2014-01-31 20:38:03.000000000 +0000
10388 +#ifndef _VSERVER_DLIMIT_CMD_H
10389 +#define _VSERVER_DLIMIT_CMD_H
10391 +#include <uapi/vserver/dlimit_cmd.h>
10394 +#ifdef CONFIG_COMPAT
10396 +#include <asm/compat.h>
10398 +struct vcmd_ctx_dlimit_base_v0_x32 {
10399 + compat_uptr_t name_ptr;
10403 +struct vcmd_ctx_dlimit_v0_x32 {
10404 + compat_uptr_t name_ptr;
10405 + uint32_t space_used; /* used space in kbytes */
10406 + uint32_t space_total; /* maximum space in kbytes */
10407 + uint32_t inodes_used; /* used inodes */
10408 + uint32_t inodes_total; /* maximum inodes */
10409 + uint32_t reserved; /* reserved for root in % */
10413 +#endif /* CONFIG_COMPAT */
10415 +#include <linux/compiler.h>
10417 +extern int vc_add_dlimit(uint32_t, void __user *);
10418 +extern int vc_rem_dlimit(uint32_t, void __user *);
10420 +extern int vc_set_dlimit(uint32_t, void __user *);
10421 +extern int vc_get_dlimit(uint32_t, void __user *);
10423 +#ifdef CONFIG_COMPAT
10425 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
10426 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
10428 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
10429 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
10431 +#endif /* CONFIG_COMPAT */
10433 +#endif /* _VSERVER_DLIMIT_CMD_H */
10434 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/global.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/global.h
10435 --- linux-3.13.10/include/linux/vserver/global.h 1970-01-01 00:00:00.000000000 +0000
10436 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/global.h 2014-01-31 20:38:03.000000000 +0000
10438 +#ifndef _VSERVER_GLOBAL_H
10439 +#define _VSERVER_GLOBAL_H
10442 +extern atomic_t vx_global_ctotal;
10443 +extern atomic_t vx_global_cactive;
10445 +extern atomic_t nx_global_ctotal;
10446 +extern atomic_t nx_global_cactive;
10448 +extern atomic_t vs_global_nsproxy;
10449 +extern atomic_t vs_global_fs;
10450 +extern atomic_t vs_global_mnt_ns;
10451 +extern atomic_t vs_global_uts_ns;
10452 +extern atomic_t vs_global_user_ns;
10453 +extern atomic_t vs_global_pid_ns;
10456 +#endif /* _VSERVER_GLOBAL_H */
10457 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/history.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/history.h
10458 --- linux-3.13.10/include/linux/vserver/history.h 1970-01-01 00:00:00.000000000 +0000
10459 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/history.h 2014-01-31 20:38:03.000000000 +0000
10461 +#ifndef _VSERVER_HISTORY_H
10462 +#define _VSERVER_HISTORY_H
10467 + VXH_THROW_OOPS = 1,
10471 + VXH_INIT_VX_INFO,
10474 + VXH_CLAIM_VX_INFO,
10475 + VXH_RELEASE_VX_INFO,
10476 + VXH_ALLOC_VX_INFO,
10477 + VXH_DEALLOC_VX_INFO,
10478 + VXH_HASH_VX_INFO,
10479 + VXH_UNHASH_VX_INFO,
10481 + VXH_LOOKUP_VX_INFO,
10482 + VXH_CREATE_VX_INFO,
10485 +struct _vxhe_vxi {
10486 + struct vx_info *ptr;
10492 +struct _vxhe_set_clr {
10496 +struct _vxhe_loc_lookup {
10500 +struct _vx_hist_entry {
10502 + unsigned short seq;
10503 + unsigned short type;
10504 + struct _vxhe_vxi vxi;
10506 + struct _vxhe_set_clr sc;
10507 + struct _vxhe_loc_lookup ll;
10511 +#ifdef CONFIG_VSERVER_HISTORY
10513 +extern unsigned volatile int vxh_active;
10515 +struct _vx_hist_entry *vxh_advance(void *loc);
10519 +void __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
10521 + entry->vxi.ptr = vxi;
10523 + entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
10524 + entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
10525 + entry->vxi.xid = vxi->vx_id;
10530 +#define __HERE__ current_text_addr()
10532 +#define __VXH_BODY(__type, __data, __here) \
10533 + struct _vx_hist_entry *entry; \
10535 + preempt_disable(); \
10536 + entry = vxh_advance(__here); \
10538 + entry->type = __type; \
10539 + preempt_enable();
10542 + /* pass vxi only */
10544 +#define __VXH_SMPL \
10545 + __vxh_copy_vxi(entry, vxi)
10548 +void __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
10550 + __VXH_BODY(__type, __VXH_SMPL, __here)
10553 + /* pass vxi and data (void *) */
10555 +#define __VXH_DATA \
10556 + __vxh_copy_vxi(entry, vxi); \
10557 + entry->sc.data = data
10560 +void __vxh_data(struct vx_info *vxi, void *data,
10561 + int __type, void *__here)
10563 + __VXH_BODY(__type, __VXH_DATA, __here)
10566 + /* pass vxi and arg (long) */
10568 +#define __VXH_LONG \
10569 + __vxh_copy_vxi(entry, vxi); \
10570 + entry->ll.arg = arg
10573 +void __vxh_long(struct vx_info *vxi, long arg,
10574 + int __type, void *__here)
10576 + __VXH_BODY(__type, __VXH_LONG, __here)
10581 +void __vxh_throw_oops(void *__here)
10583 + __VXH_BODY(VXH_THROW_OOPS, {}, __here);
10584 + /* prevent further acquisition */
10589 +#define vxh_throw_oops() __vxh_throw_oops(__HERE__);
10591 +#define __vxh_get_vx_info(v, h) __vxh_smpl(v, VXH_GET_VX_INFO, h);
10592 +#define __vxh_put_vx_info(v, h) __vxh_smpl(v, VXH_PUT_VX_INFO, h);
10594 +#define __vxh_init_vx_info(v, d, h) \
10595 + __vxh_data(v, d, VXH_INIT_VX_INFO, h);
10596 +#define __vxh_set_vx_info(v, d, h) \
10597 + __vxh_data(v, d, VXH_SET_VX_INFO, h);
10598 +#define __vxh_clr_vx_info(v, d, h) \
10599 + __vxh_data(v, d, VXH_CLR_VX_INFO, h);
10601 +#define __vxh_claim_vx_info(v, d, h) \
10602 + __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
10603 +#define __vxh_release_vx_info(v, d, h) \
10604 + __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
10606 +#define vxh_alloc_vx_info(v) \
10607 + __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
10608 +#define vxh_dealloc_vx_info(v) \
10609 + __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
10611 +#define vxh_hash_vx_info(v) \
10612 + __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
10613 +#define vxh_unhash_vx_info(v) \
10614 + __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
10616 +#define vxh_loc_vx_info(v, l) \
10617 + __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
10618 +#define vxh_lookup_vx_info(v, l) \
10619 + __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
10620 +#define vxh_create_vx_info(v, l) \
10621 + __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
10623 +extern void vxh_dump_history(void);
10626 +#else /* CONFIG_VSERVER_HISTORY */
10628 +#define __HERE__ 0
10630 +#define vxh_throw_oops() do { } while (0)
10632 +#define __vxh_get_vx_info(v, h) do { } while (0)
10633 +#define __vxh_put_vx_info(v, h) do { } while (0)
10635 +#define __vxh_init_vx_info(v, d, h) do { } while (0)
10636 +#define __vxh_set_vx_info(v, d, h) do { } while (0)
10637 +#define __vxh_clr_vx_info(v, d, h) do { } while (0)
10639 +#define __vxh_claim_vx_info(v, d, h) do { } while (0)
10640 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
10642 +#define vxh_alloc_vx_info(v) do { } while (0)
10643 +#define vxh_dealloc_vx_info(v) do { } while (0)
10645 +#define vxh_hash_vx_info(v) do { } while (0)
10646 +#define vxh_unhash_vx_info(v) do { } while (0)
10648 +#define vxh_loc_vx_info(v, l) do { } while (0)
10649 +#define vxh_lookup_vx_info(v, l) do { } while (0)
10650 +#define vxh_create_vx_info(v, l) do { } while (0)
10652 +#define vxh_dump_history() do { } while (0)
10655 +#endif /* CONFIG_VSERVER_HISTORY */
10657 +#endif /* _VSERVER_HISTORY_H */
10658 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/inode.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode.h
10659 --- linux-3.13.10/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
10660 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode.h 2014-01-31 20:38:03.000000000 +0000
10662 +#ifndef _VSERVER_INODE_H
10663 +#define _VSERVER_INODE_H
10665 +#include <uapi/vserver/inode.h>
10668 +#ifdef CONFIG_VSERVER_PROC_SECURE
10669 +#define IATTR_PROC_DEFAULT ( IATTR_ADMIN | IATTR_HIDE )
10670 +#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
10672 +#define IATTR_PROC_DEFAULT ( IATTR_ADMIN )
10673 +#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
10676 +#define vx_hide_check(c, m) (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
10678 +#else /* _VSERVER_INODE_H */
10679 +#warning duplicate inclusion
10680 +#endif /* _VSERVER_INODE_H */
10681 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/inode_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode_cmd.h
10682 --- linux-3.13.10/include/linux/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
10683 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode_cmd.h 2014-01-31 20:38:03.000000000 +0000
10685 +#ifndef _VSERVER_INODE_CMD_H
10686 +#define _VSERVER_INODE_CMD_H
10688 +#include <uapi/vserver/inode_cmd.h>
10692 +#ifdef CONFIG_COMPAT
10694 +#include <asm/compat.h>
10696 +struct vcmd_ctx_iattr_v1_x32 {
10697 + compat_uptr_t name_ptr;
10703 +#endif /* CONFIG_COMPAT */
10705 +#include <linux/compiler.h>
10707 +extern int vc_get_iattr(void __user *);
10708 +extern int vc_set_iattr(void __user *);
10710 +extern int vc_fget_iattr(uint32_t, void __user *);
10711 +extern int vc_fset_iattr(uint32_t, void __user *);
10713 +#ifdef CONFIG_COMPAT
10715 +extern int vc_get_iattr_x32(void __user *);
10716 +extern int vc_set_iattr_x32(void __user *);
10718 +#endif /* CONFIG_COMPAT */
10720 +#endif /* _VSERVER_INODE_CMD_H */
10721 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit.h
10722 --- linux-3.13.10/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
10723 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit.h 2014-01-31 20:38:03.000000000 +0000
10725 +#ifndef _VSERVER_LIMIT_H
10726 +#define _VSERVER_LIMIT_H
10728 +#include <uapi/vserver/limit.h>
10731 +#define VLIM_NOCHECK ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
10733 +/* keep in sync with CRLIM_INFINITY */
10735 +#define VLIM_INFINITY (~0ULL)
10737 +#include <asm/atomic.h>
10738 +#include <asm/resource.h>
10740 +#ifndef RLIM_INFINITY
10741 +#warning RLIM_INFINITY is undefined
10744 +#define __rlim_val(l, r, v) ((l)->res[r].v)
10746 +#define __rlim_soft(l, r) __rlim_val(l, r, soft)
10747 +#define __rlim_hard(l, r) __rlim_val(l, r, hard)
10749 +#define __rlim_rcur(l, r) __rlim_val(l, r, rcur)
10750 +#define __rlim_rmin(l, r) __rlim_val(l, r, rmin)
10751 +#define __rlim_rmax(l, r) __rlim_val(l, r, rmax)
10753 +#define __rlim_lhit(l, r) __rlim_val(l, r, lhit)
10754 +#define __rlim_hit(l, r) atomic_inc(&__rlim_lhit(l, r))
10756 +typedef atomic_long_t rlim_atomic_t;
10757 +typedef unsigned long rlim_t;
10759 +#define __rlim_get(l, r) atomic_long_read(&__rlim_rcur(l, r))
10760 +#define __rlim_set(l, r, v) atomic_long_set(&__rlim_rcur(l, r), v)
10761 +#define __rlim_inc(l, r) atomic_long_inc(&__rlim_rcur(l, r))
10762 +#define __rlim_dec(l, r) atomic_long_dec(&__rlim_rcur(l, r))
10763 +#define __rlim_add(l, r, v) atomic_long_add(v, &__rlim_rcur(l, r))
10764 +#define __rlim_sub(l, r, v) atomic_long_sub(v, &__rlim_rcur(l, r))
10767 +#if (RLIM_INFINITY == VLIM_INFINITY)
10768 +#define VX_VLIM(r) ((long long)(long)(r))
10769 +#define VX_RLIM(v) ((rlim_t)(v))
10771 +#define VX_VLIM(r) (((r) == RLIM_INFINITY) \
10772 + ? VLIM_INFINITY : (long long)(r))
10773 +#define VX_RLIM(v) (((v) == VLIM_INFINITY) \
10774 + ? RLIM_INFINITY : (rlim_t)(v))
10779 +void vx_vsi_meminfo(struct sysinfo *);
10780 +void vx_vsi_swapinfo(struct sysinfo *);
10781 +long vx_vsi_cached(struct sysinfo *);
10783 +#define NUM_LIMITS 24
10785 +#endif /* _VSERVER_LIMIT_H */
10786 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_cmd.h
10787 --- linux-3.13.10/include/linux/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
10788 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_cmd.h 2014-01-31 20:38:03.000000000 +0000
10790 +#ifndef _VSERVER_LIMIT_CMD_H
10791 +#define _VSERVER_LIMIT_CMD_H
10793 +#include <uapi/vserver/limit_cmd.h>
10796 +#ifdef CONFIG_IA32_EMULATION
10798 +struct vcmd_ctx_rlimit_v0_x32 {
10800 + uint64_t minimum;
10801 + uint64_t softlimit;
10802 + uint64_t maximum;
10803 +} __attribute__ ((packed));
10805 +#endif /* CONFIG_IA32_EMULATION */
10807 +#include <linux/compiler.h>
10809 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
10810 +extern int vc_get_rlimit(struct vx_info *, void __user *);
10811 +extern int vc_set_rlimit(struct vx_info *, void __user *);
10812 +extern int vc_reset_hits(struct vx_info *, void __user *);
10813 +extern int vc_reset_minmax(struct vx_info *, void __user *);
10815 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
10817 +#ifdef CONFIG_IA32_EMULATION
10819 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
10820 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
10822 +#endif /* CONFIG_IA32_EMULATION */
10824 +#endif /* _VSERVER_LIMIT_CMD_H */
10825 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_def.h
10826 --- linux-3.13.10/include/linux/vserver/limit_def.h 1970-01-01 00:00:00.000000000 +0000
10827 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_def.h 2014-01-31 20:38:03.000000000 +0000
10829 +#ifndef _VSERVER_LIMIT_DEF_H
10830 +#define _VSERVER_LIMIT_DEF_H
10832 +#include <asm/atomic.h>
10833 +#include <asm/resource.h>
10835 +#include "limit.h"
10838 +struct _vx_res_limit {
10839 + rlim_t soft; /* Context soft limit */
10840 + rlim_t hard; /* Context hard limit */
10842 + rlim_atomic_t rcur; /* Current value */
10843 + rlim_t rmin; /* Context minimum */
10844 + rlim_t rmax; /* Context maximum */
10846 + atomic_t lhit; /* Limit hits */
10849 +/* context sub struct */
10851 +struct _vx_limit {
10852 + struct _vx_res_limit res[NUM_LIMITS];
10855 +#ifdef CONFIG_VSERVER_DEBUG
10857 +static inline void __dump_vx_limit(struct _vx_limit *limit)
10861 + printk("\t_vx_limit:");
10862 + for (i = 0; i < NUM_LIMITS; i++) {
10863 + printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
10864 + i, (unsigned long)__rlim_get(limit, i),
10865 + (unsigned long)__rlim_rmin(limit, i),
10866 + (unsigned long)__rlim_rmax(limit, i),
10867 + (long)__rlim_soft(limit, i),
10868 + (long)__rlim_hard(limit, i),
10869 + atomic_read(&__rlim_lhit(limit, i)));
10875 +#endif /* _VSERVER_LIMIT_DEF_H */
10876 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit_int.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_int.h
10877 --- linux-3.13.10/include/linux/vserver/limit_int.h 1970-01-01 00:00:00.000000000 +0000
10878 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_int.h 2014-01-31 20:38:03.000000000 +0000
10880 +#ifndef _VSERVER_LIMIT_INT_H
10881 +#define _VSERVER_LIMIT_INT_H
10883 +#define VXD_RCRES_COND(r) VXD_CBIT(cres, r)
10884 +#define VXD_RLIMIT_COND(r) VXD_CBIT(limit, r)
10886 +extern const char *vlimit_name[NUM_LIMITS];
10888 +static inline void __vx_acc_cres(struct vx_info *vxi,
10889 + int res, int dir, void *_data, char *_file, int _line)
10891 + if (VXD_RCRES_COND(res))
10892 + vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
10893 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10894 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10895 + (dir > 0) ? "++" : "--", _data, _file, _line);
10900 + __rlim_inc(&vxi->limit, res);
10902 + __rlim_dec(&vxi->limit, res);
10905 +static inline void __vx_add_cres(struct vx_info *vxi,
10906 + int res, int amount, void *_data, char *_file, int _line)
10908 + if (VXD_RCRES_COND(res))
10909 + vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
10910 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10911 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10912 + amount, _data, _file, _line);
10917 + __rlim_add(&vxi->limit, res, amount);
10921 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
10923 + int cond = (value > __rlim_rmax(limit, res));
10926 + __rlim_rmax(limit, res) = value;
10931 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
10933 + int cond = (value < __rlim_rmin(limit, res));
10936 + __rlim_rmin(limit, res) = value;
10941 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
10943 + if (!__vx_cres_adjust_max(limit, res, value))
10944 + __vx_cres_adjust_min(limit, res, value);
10949 + +1 ... no limit hit
10950 + -1 ... over soft limit
10951 + 0 ... over hard limit */
10953 +static inline int __vx_cres_avail(struct vx_info *vxi,
10954 + int res, int num, char *_file, int _line)
10956 + struct _vx_limit *limit;
10959 + if (VXD_RLIMIT_COND(res))
10960 + vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
10961 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10962 + (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
10963 + (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
10964 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10965 + num, _file, _line);
10969 + limit = &vxi->limit;
10970 + value = __rlim_get(limit, res);
10972 + if (!__vx_cres_adjust_max(limit, res, value))
10973 + __vx_cres_adjust_min(limit, res, value);
10978 + if (__rlim_soft(limit, res) == RLIM_INFINITY)
10980 + if (value + num <= __rlim_soft(limit, res))
10983 + if (__rlim_hard(limit, res) == RLIM_INFINITY)
10985 + if (value + num <= __rlim_hard(limit, res))
10988 + __rlim_hit(limit, res);
10993 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
10996 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
10998 + rlim_t value, sum = 0;
11001 + while ((res = *array++)) {
11002 + value = __rlim_get(limit, res);
11003 + __vx_cres_fixup(limit, res, value);
11010 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11012 + rlim_t value = __vx_cres_array_sum(limit, array + 1);
11013 + int res = *array;
11015 + if (value == __rlim_get(limit, res))
11018 + __rlim_set(limit, res, value);
11019 + /* now adjust min/max */
11020 + if (!__vx_cres_adjust_max(limit, res, value))
11021 + __vx_cres_adjust_min(limit, res, value);
11026 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11027 + const int *array, int num, char *_file, int _line)
11029 + struct _vx_limit *limit;
11030 + rlim_t value = 0;
11038 + limit = &vxi->limit;
11040 + value = __vx_cres_array_sum(limit, array + 1);
11042 + __rlim_set(limit, res, value);
11043 + __vx_cres_fixup(limit, res, value);
11045 + return __vx_cres_avail(vxi, res, num, _file, _line);
11049 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11054 + /* complex resources first */
11055 + if ((id < 0) || (id == RLIMIT_RSS))
11056 + __vx_cres_array_fixup(limit, VLA_RSS);
11058 + for (res = 0; res < NUM_LIMITS; res++) {
11059 + if ((id > 0) && (res != id))
11062 + value = __rlim_get(limit, res);
11063 + __vx_cres_fixup(limit, res, value);
11065 + /* not supposed to happen, maybe warn? */
11066 + if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11067 + __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11072 +#endif /* _VSERVER_LIMIT_INT_H */
11073 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/monitor.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/monitor.h
11074 --- linux-3.13.10/include/linux/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
11075 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/monitor.h 2014-01-31 20:38:03.000000000 +0000
11077 +#ifndef _VSERVER_MONITOR_H
11078 +#define _VSERVER_MONITOR_H
11080 +#include <uapi/vserver/monitor.h>
11082 +#endif /* _VSERVER_MONITOR_H */
11083 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/network.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/network.h
11084 --- linux-3.13.10/include/linux/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
11085 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/network.h 2014-01-31 20:38:03.000000000 +0000
11087 +#ifndef _VSERVER_NETWORK_H
11088 +#define _VSERVER_NETWORK_H
11091 +#include <linux/list.h>
11092 +#include <linux/spinlock.h>
11093 +#include <linux/rcupdate.h>
11094 +#include <linux/in.h>
11095 +#include <linux/in6.h>
11096 +#include <asm/atomic.h>
11097 +#include <uapi/vserver/network.h>
11099 +struct nx_addr_v4 {
11100 + struct nx_addr_v4 *next;
11101 + struct in_addr ip[2];
11102 + struct in_addr mask;
11107 +struct nx_addr_v6 {
11108 + struct nx_addr_v6 *next;
11109 + struct in6_addr ip;
11110 + struct in6_addr mask;
11117 + struct hlist_node nx_hlist; /* linked list of nxinfos */
11118 + vnid_t nx_id; /* vnet id */
11119 + atomic_t nx_usecnt; /* usage count */
11120 + atomic_t nx_tasks; /* tasks count */
11121 + int nx_state; /* context state */
11123 + uint64_t nx_flags; /* network flag word */
11124 + uint64_t nx_ncaps; /* network capabilities */
11126 + spinlock_t addr_lock; /* protect address changes */
11127 + struct in_addr v4_lback; /* Loopback address */
11128 + struct in_addr v4_bcast; /* Broadcast address */
11129 + struct nx_addr_v4 v4; /* First/Single ipv4 address */
11130 +#ifdef CONFIG_IPV6
11131 + struct nx_addr_v6 v6; /* First/Single ipv6 address */
11133 + char nx_name[65]; /* network context name */
11137 +/* status flags */
11139 +#define NXS_HASHED 0x0001
11140 +#define NXS_SHUTDOWN 0x0100
11141 +#define NXS_RELEASED 0x8000
11143 +extern struct nx_info *lookup_nx_info(int);
11145 +extern int get_nid_list(int, unsigned int *, int);
11146 +extern int nid_is_hashed(vnid_t);
11148 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11150 +extern long vs_net_change(struct nx_info *, unsigned int);
11155 +#define NX_IPV4(n) ((n)->v4.type != NXA_TYPE_NONE)
11156 +#ifdef CONFIG_IPV6
11157 +#define NX_IPV6(n) ((n)->v6.type != NXA_TYPE_NONE)
11159 +#define NX_IPV6(n) (0)
11162 +#endif /* _VSERVER_NETWORK_H */
11163 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/network_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/network_cmd.h
11164 --- linux-3.13.10/include/linux/vserver/network_cmd.h 1970-01-01 00:00:00.000000000 +0000
11165 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/network_cmd.h 2014-01-31 20:38:03.000000000 +0000
11167 +#ifndef _VSERVER_NETWORK_CMD_H
11168 +#define _VSERVER_NETWORK_CMD_H
11170 +#include <uapi/vserver/network_cmd.h>
11172 +extern int vc_task_nid(uint32_t);
11174 +extern int vc_nx_info(struct nx_info *, void __user *);
11176 +extern int vc_net_create(uint32_t, void __user *);
11177 +extern int vc_net_migrate(struct nx_info *, void __user *);
11179 +extern int vc_net_add(struct nx_info *, void __user *);
11180 +extern int vc_net_remove(struct nx_info *, void __user *);
11182 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11183 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11185 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11186 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11188 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11189 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11191 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11192 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11194 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11195 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11197 +extern int vc_get_nflags(struct nx_info *, void __user *);
11198 +extern int vc_set_nflags(struct nx_info *, void __user *);
11200 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11201 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11203 +#endif /* _VSERVER_CONTEXT_CMD_H */
11204 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/percpu.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/percpu.h
11205 --- linux-3.13.10/include/linux/vserver/percpu.h 1970-01-01 00:00:00.000000000 +0000
11206 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/percpu.h 2014-01-31 20:38:03.000000000 +0000
11208 +#ifndef _VSERVER_PERCPU_H
11209 +#define _VSERVER_PERCPU_H
11211 +#include "cvirt_def.h"
11212 +#include "sched_def.h"
11214 +struct _vx_percpu {
11215 + struct _vx_cvirt_pc cvirt;
11216 + struct _vx_sched_pc sched;
11219 +#define PERCPU_PERCTX (sizeof(struct _vx_percpu))
11221 +#endif /* _VSERVER_PERCPU_H */
11222 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/pid.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/pid.h
11223 --- linux-3.13.10/include/linux/vserver/pid.h 1970-01-01 00:00:00.000000000 +0000
11224 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/pid.h 2014-01-31 20:38:03.000000000 +0000
11226 +#ifndef _VSERVER_PID_H
11227 +#define _VSERVER_PID_H
11229 +/* pid faking stuff */
11231 +#define vx_info_map_pid(v, p) \
11232 + __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
11233 +#define vx_info_map_tgid(v,p) vx_info_map_pid(v,p)
11234 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
11235 +#define vx_map_tgid(p) vx_map_pid(p)
11237 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
11238 + const char *func, const char *file, int line)
11240 + if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11241 + vxfprintk(VXD_CBIT(cvirt, 2),
11242 + "vx_map_tgid: %p/%llx: %d -> %d",
11243 + vxi, (long long)vxi->vx_flags, pid,
11244 + (pid && pid == vxi->vx_initpid) ? 1 : pid,
11245 + func, file, line);
11248 + if (pid == vxi->vx_initpid)
11254 +#define vx_info_rmap_pid(v, p) \
11255 + __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
11256 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
11257 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
11259 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
11260 + const char *func, const char *file, int line)
11262 + if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11263 + vxfprintk(VXD_CBIT(cvirt, 2),
11264 + "vx_rmap_tgid: %p/%llx: %d -> %d",
11265 + vxi, (long long)vxi->vx_flags, pid,
11266 + (pid == 1) ? vxi->vx_initpid : pid,
11267 + func, file, line);
11268 + if ((pid == 1) && vxi->vx_initpid)
11269 + return vxi->vx_initpid;
11270 + if (pid == vxi->vx_initpid)
11277 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/sched.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched.h
11278 --- linux-3.13.10/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
11279 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched.h 2014-01-31 20:38:03.000000000 +0000
11281 +#ifndef _VSERVER_SCHED_H
11282 +#define _VSERVER_SCHED_H
11289 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11294 +void vx_update_load(struct vx_info *);
11297 +void vx_update_sched_param(struct _vx_sched *sched,
11298 + struct _vx_sched_pc *sched_pc);
11300 +#endif /* __KERNEL__ */
11301 +#else /* _VSERVER_SCHED_H */
11302 +#warning duplicate inclusion
11303 +#endif /* _VSERVER_SCHED_H */
11304 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/sched_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_cmd.h
11305 --- linux-3.13.10/include/linux/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
11306 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_cmd.h 2014-01-31 20:38:03.000000000 +0000
11308 +#ifndef _VSERVER_SCHED_CMD_H
11309 +#define _VSERVER_SCHED_CMD_H
11312 +#include <linux/compiler.h>
11313 +#include <uapi/vserver/sched_cmd.h>
11315 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
11316 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
11318 +#endif /* _VSERVER_SCHED_CMD_H */
11319 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/sched_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_def.h
11320 --- linux-3.13.10/include/linux/vserver/sched_def.h 1970-01-01 00:00:00.000000000 +0000
11321 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_def.h 2014-01-31 20:38:03.000000000 +0000
11323 +#ifndef _VSERVER_SCHED_DEF_H
11324 +#define _VSERVER_SCHED_DEF_H
11326 +#include <linux/spinlock.h>
11327 +#include <linux/jiffies.h>
11328 +#include <linux/cpumask.h>
11329 +#include <asm/atomic.h>
11330 +#include <asm/param.h>
11333 +/* context sub struct */
11335 +struct _vx_sched {
11336 + int prio_bias; /* bias offset for priority */
11338 + cpumask_t update; /* CPUs which should update */
11341 +struct _vx_sched_pc {
11342 + int prio_bias; /* bias offset for priority */
11344 + uint64_t user_ticks; /* token tick events */
11345 + uint64_t sys_ticks; /* token tick events */
11346 + uint64_t hold_ticks; /* token ticks paused */
11350 +#ifdef CONFIG_VSERVER_DEBUG
11352 +static inline void __dump_vx_sched(struct _vx_sched *sched)
11354 + printk("\t_vx_sched:\n");
11355 + printk("\t priority = %4d\n", sched->prio_bias);
11360 +#endif /* _VSERVER_SCHED_DEF_H */
11361 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/signal.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal.h
11362 --- linux-3.13.10/include/linux/vserver/signal.h 1970-01-01 00:00:00.000000000 +0000
11363 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal.h 2014-01-31 20:38:03.000000000 +0000
11365 +#ifndef _VSERVER_SIGNAL_H
11366 +#define _VSERVER_SIGNAL_H
11373 +int vx_info_kill(struct vx_info *, int, int);
11375 +#endif /* __KERNEL__ */
11376 +#else /* _VSERVER_SIGNAL_H */
11377 +#warning duplicate inclusion
11378 +#endif /* _VSERVER_SIGNAL_H */
11379 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/signal_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal_cmd.h
11380 --- linux-3.13.10/include/linux/vserver/signal_cmd.h 1970-01-01 00:00:00.000000000 +0000
11381 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal_cmd.h 2014-01-31 20:38:03.000000000 +0000
11383 +#ifndef _VSERVER_SIGNAL_CMD_H
11384 +#define _VSERVER_SIGNAL_CMD_H
11386 +#include <uapi/vserver/signal_cmd.h>
11389 +extern int vc_ctx_kill(struct vx_info *, void __user *);
11390 +extern int vc_wait_exit(struct vx_info *, void __user *);
11393 +extern int vc_get_pflags(uint32_t pid, void __user *);
11394 +extern int vc_set_pflags(uint32_t pid, void __user *);
11396 +#endif /* _VSERVER_SIGNAL_CMD_H */
11397 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/space.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/space.h
11398 --- linux-3.13.10/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
11399 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/space.h 2014-01-31 20:38:03.000000000 +0000
11401 +#ifndef _VSERVER_SPACE_H
11402 +#define _VSERVER_SPACE_H
11404 +#include <linux/types.h>
11408 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
11410 +#else /* _VSERVER_SPACE_H */
11411 +#warning duplicate inclusion
11412 +#endif /* _VSERVER_SPACE_H */
11413 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/space_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/space_cmd.h
11414 --- linux-3.13.10/include/linux/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
11415 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/space_cmd.h 2014-01-31 20:38:03.000000000 +0000
11417 +#ifndef _VSERVER_SPACE_CMD_H
11418 +#define _VSERVER_SPACE_CMD_H
11420 +#include <uapi/vserver/space_cmd.h>
11423 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
11424 +extern int vc_set_space_v1(struct vx_info *, void __user *);
11425 +extern int vc_enter_space(struct vx_info *, void __user *);
11426 +extern int vc_set_space(struct vx_info *, void __user *);
11427 +extern int vc_get_space_mask(void __user *, int);
11429 +#endif /* _VSERVER_SPACE_CMD_H */
11430 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/switch.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/switch.h
11431 --- linux-3.13.10/include/linux/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
11432 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/switch.h 2014-01-31 20:38:03.000000000 +0000
11434 +#ifndef _VSERVER_SWITCH_H
11435 +#define _VSERVER_SWITCH_H
11438 +#include <linux/errno.h>
11439 +#include <uapi/vserver/switch.h>
11441 +#endif /* _VSERVER_SWITCH_H */
11442 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/tag.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag.h
11443 --- linux-3.13.10/include/linux/vserver/tag.h 1970-01-01 00:00:00.000000000 +0000
11444 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag.h 2014-01-31 20:38:03.000000000 +0000
11449 +#include <linux/types.h>
11450 +#include <linux/uidgid.h>
11453 +#define DX_TAG(in) (IS_TAGGED(in))
11456 +#ifdef CONFIG_TAG_NFSD
11457 +#define DX_TAG_NFSD 1
11459 +#define DX_TAG_NFSD 0
11463 +#ifdef CONFIG_TAGGING_NONE
11465 +#define MAX_UID 0xFFFFFFFF
11466 +#define MAX_GID 0xFFFFFFFF
11468 +#define INOTAG_TAG(cond, uid, gid, tag) (0)
11470 +#define TAGINO_UID(cond, uid, tag) (uid)
11471 +#define TAGINO_GID(cond, gid, tag) (gid)
11476 +#ifdef CONFIG_TAGGING_GID16
11478 +#define MAX_UID 0xFFFFFFFF
11479 +#define MAX_GID 0x0000FFFF
11481 +#define INOTAG_TAG(cond, uid, gid, tag) \
11482 + ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
11484 +#define TAGINO_UID(cond, uid, tag) (uid)
11485 +#define TAGINO_GID(cond, gid, tag) \
11486 + ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
11491 +#ifdef CONFIG_TAGGING_ID24
11493 +#define MAX_UID 0x00FFFFFF
11494 +#define MAX_GID 0x00FFFFFF
11496 +#define INOTAG_TAG(cond, uid, gid, tag) \
11497 + ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
11499 +#define TAGINO_UID(cond, uid, tag) \
11500 + ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
11501 +#define TAGINO_GID(cond, gid, tag) \
11502 + ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
11507 +#ifdef CONFIG_TAGGING_UID16
11509 +#define MAX_UID 0x0000FFFF
11510 +#define MAX_GID 0xFFFFFFFF
11512 +#define INOTAG_TAG(cond, uid, gid, tag) \
11513 + ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
11515 +#define TAGINO_UID(cond, uid, tag) \
11516 + ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
11517 +#define TAGINO_GID(cond, gid, tag) (gid)
11522 +#ifdef CONFIG_TAGGING_INTERN
11524 +#define MAX_UID 0xFFFFFFFF
11525 +#define MAX_GID 0xFFFFFFFF
11527 +#define INOTAG_TAG(cond, uid, gid, tag) \
11528 + ((cond) ? (tag) : 0)
11530 +#define TAGINO_UID(cond, uid, tag) (uid)
11531 +#define TAGINO_GID(cond, gid, tag) (gid)
11536 +#ifndef CONFIG_TAGGING_NONE
11537 +#define dx_current_fstag(sb) \
11538 + ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
11540 +#define dx_current_fstag(sb) (0)
11543 +#ifndef CONFIG_TAGGING_INTERN
11544 +#define TAGINO_TAG(cond, tag) (0)
11546 +#define TAGINO_TAG(cond, tag) ((cond) ? (tag) : 0)
11549 +#define TAGINO_KUID(cond, kuid, ktag) \
11550 + KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
11551 +#define TAGINO_KGID(cond, kgid, ktag) \
11552 + KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
11553 +#define TAGINO_KTAG(cond, ktag) \
11554 + KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
11557 +#define INOTAG_UID(cond, uid, gid) \
11558 + ((cond) ? ((uid) & MAX_UID) : (uid))
11559 +#define INOTAG_GID(cond, uid, gid) \
11560 + ((cond) ? ((gid) & MAX_GID) : (gid))
11562 +#define INOTAG_KUID(cond, kuid, kgid) \
11563 + KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11564 +#define INOTAG_KGID(cond, kuid, kgid) \
11565 + KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11566 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
11567 + KTAGT_INIT(INOTAG_TAG(cond, \
11568 + __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
11571 +static inline uid_t dx_map_uid(uid_t uid)
11573 + if ((uid > MAX_UID) && (uid != -1))
11575 + return (uid & MAX_UID);
11578 +static inline gid_t dx_map_gid(gid_t gid)
11580 + if ((gid > MAX_GID) && (gid != -1))
11582 + return (gid & MAX_GID);
11590 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
11592 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
11593 + unsigned long *flags);
11595 +#ifdef CONFIG_PROPAGATE
11597 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
11599 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
11602 +#define dx_propagate_tag(n, i) do { } while (0)
11605 +#endif /* _DX_TAG_H */
11606 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/tag_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag_cmd.h
11607 --- linux-3.13.10/include/linux/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
11608 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag_cmd.h 2014-01-31 20:38:03.000000000 +0000
11610 +#ifndef _VSERVER_TAG_CMD_H
11611 +#define _VSERVER_TAG_CMD_H
11613 +#include <uapi/vserver/tag_cmd.h>
11615 +extern int vc_task_tag(uint32_t);
11617 +extern int vc_tag_migrate(uint32_t);
11619 +#endif /* _VSERVER_TAG_CMD_H */
11620 diff -NurpP --minimal linux-3.13.10/include/net/addrconf.h linux-3.13.10-vs2.3.6.11/include/net/addrconf.h
11621 --- linux-3.13.10/include/net/addrconf.h 2013-11-25 15:47:02.000000000 +0000
11622 +++ linux-3.13.10-vs2.3.6.11/include/net/addrconf.h 2014-01-31 20:39:35.000000000 +0000
11623 @@ -79,7 +79,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
11625 int ipv6_dev_get_saddr(struct net *net, const struct net_device *dev,
11626 const struct in6_addr *daddr, unsigned int srcprefs,
11627 - struct in6_addr *saddr);
11628 + struct in6_addr *saddr, struct nx_info *nxi);
11629 int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
11630 unsigned char banned_flags);
11631 int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
11632 diff -NurpP --minimal linux-3.13.10/include/net/af_unix.h linux-3.13.10-vs2.3.6.11/include/net/af_unix.h
11633 --- linux-3.13.10/include/net/af_unix.h 2013-11-25 15:47:02.000000000 +0000
11634 +++ linux-3.13.10-vs2.3.6.11/include/net/af_unix.h 2014-01-31 20:38:03.000000000 +0000
11636 #include <linux/socket.h>
11637 #include <linux/un.h>
11638 #include <linux/mutex.h>
11639 +#include <linux/vs_base.h>
11640 #include <net/sock.h>
11642 void unix_inflight(struct file *fp);
11643 diff -NurpP --minimal linux-3.13.10/include/net/inet_timewait_sock.h linux-3.13.10-vs2.3.6.11/include/net/inet_timewait_sock.h
11644 --- linux-3.13.10/include/net/inet_timewait_sock.h 2014-01-22 20:39:11.000000000 +0000
11645 +++ linux-3.13.10-vs2.3.6.11/include/net/inet_timewait_sock.h 2014-01-31 20:40:30.000000000 +0000
11646 @@ -121,6 +121,10 @@ struct inet_timewait_sock {
11647 #define tw_v6_rcv_saddr __tw_common.skc_v6_rcv_saddr
11648 #define tw_dport __tw_common.skc_dport
11649 #define tw_num __tw_common.skc_num
11650 +#define tw_xid __tw_common.skc_xid
11651 +#define tw_vx_info __tw_common.skc_vx_info
11652 +#define tw_nid __tw_common.skc_nid
11653 +#define tw_nx_info __tw_common.skc_nx_info
11656 volatile unsigned char tw_substate;
11657 diff -NurpP --minimal linux-3.13.10/include/net/ip6_route.h linux-3.13.10-vs2.3.6.11/include/net/ip6_route.h
11658 --- linux-3.13.10/include/net/ip6_route.h 2014-01-22 20:39:11.000000000 +0000
11659 +++ linux-3.13.10-vs2.3.6.11/include/net/ip6_route.h 2014-01-31 20:41:10.000000000 +0000
11660 @@ -90,7 +90,7 @@ int ip6_del_rt(struct rt6_info *);
11662 int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
11663 const struct in6_addr *daddr, unsigned int prefs,
11664 - struct in6_addr *saddr);
11665 + struct in6_addr *saddr, struct nx_info *nxi);
11667 struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
11668 const struct in6_addr *saddr, int oif, int flags);
11669 diff -NurpP --minimal linux-3.13.10/include/net/route.h linux-3.13.10-vs2.3.6.11/include/net/route.h
11670 --- linux-3.13.10/include/net/route.h 2014-01-22 20:39:12.000000000 +0000
11671 +++ linux-3.13.10-vs2.3.6.11/include/net/route.h 2014-02-01 12:30:58.000000000 +0000
11672 @@ -203,6 +203,9 @@ static inline void ip_rt_put(struct rtab
11673 dst_release(&rt->dst);
11676 +#include <linux/vs_base.h>
11677 +#include <linux/vs_inet.h>
11679 #define IPTOS_RT_MASK (IPTOS_TOS_MASK & ~3)
11681 extern const __u8 ip_tos2prio[16];
11682 @@ -252,6 +255,9 @@ static inline void ip_route_connect_init
11683 protocol, flow_flags, dst, src, dport, sport);
11686 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
11687 + struct flowi4 *);
11689 static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
11690 __be32 dst, __be32 src, u32 tos,
11691 int oif, u8 protocol,
11692 @@ -260,11 +266,25 @@ static inline struct rtable *ip_route_co
11694 struct net *net = sock_net(sk);
11696 + struct nx_info *nx_info = current_nx_info();
11698 ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
11701 - if (!dst || !src) {
11703 + nx_info = sk->sk_nx_info;
11705 + vxdprintk(VXD_CBIT(net, 4),
11706 + "ip_route_connect(%p) %p,%p;%lx",
11707 + sk, nx_info, sk->sk_socket,
11708 + (sk->sk_socket?sk->sk_socket->flags:0));
11710 + rt = ip_v4_find_src(net, nx_info, fl4);
11715 + if (!fl4->daddr || !fl4->saddr) {
11716 rt = __ip_route_output_key(net, fl4);
11719 diff -NurpP --minimal linux-3.13.10/include/net/sock.h linux-3.13.10-vs2.3.6.11/include/net/sock.h
11720 --- linux-3.13.10/include/net/sock.h 2014-04-17 01:12:39.000000000 +0000
11721 +++ linux-3.13.10-vs2.3.6.11/include/net/sock.h 2014-04-17 01:17:10.000000000 +0000
11722 @@ -191,6 +191,10 @@ struct sock_common {
11723 #ifdef CONFIG_NET_NS
11724 struct net *skc_net;
11727 + struct vx_info *skc_vx_info;
11729 + struct nx_info *skc_nx_info;
11731 #if IS_ENABLED(CONFIG_IPV6)
11732 struct in6_addr skc_v6_daddr;
11733 @@ -321,7 +325,11 @@ struct sock {
11734 #define sk_prot __sk_common.skc_prot
11735 #define sk_net __sk_common.skc_net
11736 #define sk_v6_daddr __sk_common.skc_v6_daddr
11737 -#define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
11738 +#define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
11739 +#define sk_xid __sk_common.skc_xid
11740 +#define sk_vx_info __sk_common.skc_vx_info
11741 +#define sk_nid __sk_common.skc_nid
11742 +#define sk_nx_info __sk_common.skc_nx_info
11744 socket_lock_t sk_lock;
11745 struct sk_buff_head sk_receive_queue;
11746 diff -NurpP --minimal linux-3.13.10/include/uapi/Kbuild linux-3.13.10-vs2.3.6.11/include/uapi/Kbuild
11747 --- linux-3.13.10/include/uapi/Kbuild 2012-12-11 03:30:57.000000000 +0000
11748 +++ linux-3.13.10-vs2.3.6.11/include/uapi/Kbuild 2014-01-31 20:38:03.000000000 +0000
11749 @@ -12,3 +12,4 @@ header-y += video/
11753 +header-y += vserver/
11754 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/capability.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/capability.h
11755 --- linux-3.13.10/include/uapi/linux/capability.h 2012-12-11 03:30:57.000000000 +0000
11756 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/capability.h 2014-01-31 20:38:03.000000000 +0000
11757 @@ -259,6 +259,7 @@ struct vfs_cap_data {
11758 arbitrary SCSI commands */
11759 /* Allow setting encryption key on loopback filesystem */
11760 /* Allow setting zone reclaim policy */
11761 +/* Allow the selection of a security context */
11763 #define CAP_SYS_ADMIN 21
11765 @@ -345,7 +346,12 @@ struct vfs_cap_data {
11767 #define CAP_LAST_CAP CAP_BLOCK_SUSPEND
11769 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
11770 +/* Allow context manipulations */
11771 +/* Allow changing context info on files */
11773 +#define CAP_CONTEXT 63
11775 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
11778 * Bit location of each capability (used by user-space library and kernel)
11779 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/fs.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/fs.h
11780 --- linux-3.13.10/include/uapi/linux/fs.h 2013-11-25 15:47:02.000000000 +0000
11781 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/fs.h 2014-01-31 20:38:03.000000000 +0000
11782 @@ -86,6 +86,9 @@ struct inodes_stat_t {
11783 #define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */
11784 #define MS_I_VERSION (1<<23) /* Update inode I_version field */
11785 #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
11786 +#define MS_TAGGED (1<<8) /* use generic inode tagging */
11787 +#define MS_NOTAGCHECK (1<<9) /* don't check tags */
11788 +#define MS_TAGID (1<<25) /* use specific tag for this mount */
11790 /* These sb flags are internal to the kernel */
11791 #define MS_NOSEC (1<<28)
11792 @@ -191,11 +194,14 @@ struct inodes_stat_t {
11793 #define FS_EXTENT_FL 0x00080000 /* Extents */
11794 #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */
11795 #define FS_NOCOW_FL 0x00800000 /* Do not cow file */
11796 +#define FS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
11797 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
11799 -#define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
11800 -#define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
11801 +#define FS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
11802 +#define FS_COW_FL 0x20000000 /* Copy on Write marker */
11804 +#define FS_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
11805 +#define FS_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
11807 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
11808 #define SYNC_FILE_RANGE_WRITE 2
11809 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/gfs2_ondisk.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/gfs2_ondisk.h
11810 --- linux-3.13.10/include/uapi/linux/gfs2_ondisk.h 2012-12-11 03:30:57.000000000 +0000
11811 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/gfs2_ondisk.h 2014-01-31 20:38:03.000000000 +0000
11812 @@ -225,6 +225,9 @@ enum {
11815 gfs2fl_TopLevel = 10,
11816 + gfs2fl_IXUnlink = 16,
11817 + gfs2fl_Barrier = 17,
11819 gfs2fl_TruncInProg = 29,
11820 gfs2fl_InheritDirectio = 30,
11821 gfs2fl_InheritJdata = 31,
11822 @@ -242,6 +245,9 @@ enum {
11823 #define GFS2_DIF_SYNC 0x00000100
11824 #define GFS2_DIF_SYSTEM 0x00000200 /* New in gfs2 */
11825 #define GFS2_DIF_TOPDIR 0x00000400 /* New in gfs2 */
11826 +#define GFS2_DIF_IXUNLINK 0x00010000
11827 +#define GFS2_DIF_BARRIER 0x00020000
11828 +#define GFS2_DIF_COW 0x00040000
11829 #define GFS2_DIF_TRUNC_IN_PROG 0x20000000 /* New in gfs2 */
11830 #define GFS2_DIF_INHERIT_DIRECTIO 0x40000000 /* only in gfs1 */
11831 #define GFS2_DIF_INHERIT_JDATA 0x80000000
11832 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/if_tun.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/if_tun.h
11833 --- linux-3.13.10/include/uapi/linux/if_tun.h 2013-11-25 15:47:02.000000000 +0000
11834 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/if_tun.h 2014-01-31 20:45:49.000000000 +0000
11836 #define TUNSETQUEUE _IOW('T', 217, int)
11837 #define TUNSETIFINDEX _IOW('T', 218, unsigned int)
11838 #define TUNGETFILTER _IOR('T', 219, struct sock_fprog)
11839 +#define TUNSETNID _IOW('T', 220, int)
11841 /* TUNSETIFF ifr flags */
11842 #define IFF_TUN 0x0001
11843 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/major.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/major.h
11844 --- linux-3.13.10/include/uapi/linux/major.h 2014-01-22 20:39:12.000000000 +0000
11845 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/major.h 2014-01-31 20:38:03.000000000 +0000
11847 #define HD_MAJOR IDE0_MAJOR
11848 #define PTY_SLAVE_MAJOR 3
11849 #define TTY_MAJOR 4
11850 +#define VROOT_MAJOR 4
11851 #define TTYAUX_MAJOR 5
11853 #define VCS_MAJOR 7
11854 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/nfs_mount.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/nfs_mount.h
11855 --- linux-3.13.10/include/uapi/linux/nfs_mount.h 2014-01-22 20:39:12.000000000 +0000
11856 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/nfs_mount.h 2014-01-31 20:38:03.000000000 +0000
11857 @@ -63,7 +63,8 @@ struct nfs_mount_data {
11858 #define NFS_MOUNT_SECFLAVOUR 0x2000 /* 5 non-text parsed mount data only */
11859 #define NFS_MOUNT_NORDIRPLUS 0x4000 /* 5 */
11860 #define NFS_MOUNT_UNSHARED 0x8000 /* 5 */
11861 -#define NFS_MOUNT_FLAGMASK 0xFFFF
11862 +#define NFS_MOUNT_TAGGED 0x10000 /* context tagging */
11863 +#define NFS_MOUNT_FLAGMASK 0x1FFFF
11865 /* The following are for internal use only */
11866 #define NFS_MOUNT_LOOKUP_CACHE_NONEG 0x10000
11867 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/reboot.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/reboot.h
11868 --- linux-3.13.10/include/uapi/linux/reboot.h 2012-12-11 03:30:57.000000000 +0000
11869 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/reboot.h 2014-01-31 20:38:03.000000000 +0000
11871 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
11872 #define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
11873 #define LINUX_REBOOT_CMD_KEXEC 0x45584543
11875 +#define LINUX_REBOOT_CMD_OOM 0xDEADBEEF
11878 #endif /* _UAPI_LINUX_REBOOT_H */
11879 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/sysctl.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/sysctl.h
11880 --- linux-3.13.10/include/uapi/linux/sysctl.h 2012-12-11 03:30:57.000000000 +0000
11881 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/sysctl.h 2014-01-31 20:38:03.000000000 +0000
11882 @@ -60,6 +60,7 @@ enum
11883 CTL_ABI=9, /* Binary emulation */
11884 CTL_CPU=10, /* CPU stuff (speed scaling, etc) */
11885 CTL_ARLAN=254, /* arlan wireless driver */
11886 + CTL_VSERVER=4242, /* Linux-VServer debug */
11887 CTL_S390DBF=5677, /* s390 debug */
11888 CTL_SUNRPC=7249, /* sunrpc debug */
11889 CTL_PM=9899, /* frv power management */
11890 @@ -94,6 +95,7 @@ enum
11892 KERN_PANIC=15, /* int: panic timeout */
11893 KERN_REALROOTDEV=16, /* real root device to mount after initrd */
11894 + KERN_VSHELPER=17, /* string: path to vshelper policy agent */
11896 KERN_SPARC_REBOOT=21, /* reboot command on Sparc */
11897 KERN_CTLALTDEL=22, /* int: allow ctl-alt-del to reboot */
11898 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/Kbuild linux-3.13.10-vs2.3.6.11/include/uapi/vserver/Kbuild
11899 --- linux-3.13.10/include/uapi/vserver/Kbuild 1970-01-01 00:00:00.000000000 +0000
11900 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/Kbuild 2014-01-31 20:38:03.000000000 +0000
11903 +header-y += context_cmd.h network_cmd.h space_cmd.h \
11904 + cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11905 + inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11906 + debug_cmd.h device_cmd.h
11908 +header-y += switch.h context.h network.h monitor.h \
11909 + limit.h inode.h device.h
11911 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/cacct_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cacct_cmd.h
11912 --- linux-3.13.10/include/uapi/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
11913 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cacct_cmd.h 2014-01-31 20:38:03.000000000 +0000
11915 +#ifndef _UAPI_VS_CACCT_CMD_H
11916 +#define _UAPI_VS_CACCT_CMD_H
11919 +/* virtual host info name commands */
11921 +#define VCMD_sock_stat VC_CMD(VSTAT, 5, 0)
11923 +struct vcmd_sock_stat_v0 {
11925 + uint32_t count[3];
11926 + uint64_t total[3];
11929 +#endif /* _UAPI_VS_CACCT_CMD_H */
11930 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/context.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context.h
11931 --- linux-3.13.10/include/uapi/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
11932 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context.h 2014-01-31 20:38:03.000000000 +0000
11934 +#ifndef _UAPI_VS_CONTEXT_H
11935 +#define _UAPI_VS_CONTEXT_H
11937 +#include <linux/types.h>
11938 +#include <linux/capability.h>
11941 +/* context flags */
11943 +#define VXF_INFO_SCHED 0x00000002
11944 +#define VXF_INFO_NPROC 0x00000004
11945 +#define VXF_INFO_PRIVATE 0x00000008
11947 +#define VXF_INFO_INIT 0x00000010
11948 +#define VXF_INFO_HIDE 0x00000020
11949 +#define VXF_INFO_ULIMIT 0x00000040
11950 +#define VXF_INFO_NSPACE 0x00000080
11952 +#define VXF_SCHED_HARD 0x00000100
11953 +#define VXF_SCHED_PRIO 0x00000200
11954 +#define VXF_SCHED_PAUSE 0x00000400
11956 +#define VXF_VIRT_MEM 0x00010000
11957 +#define VXF_VIRT_UPTIME 0x00020000
11958 +#define VXF_VIRT_CPU 0x00040000
11959 +#define VXF_VIRT_LOAD 0x00080000
11960 +#define VXF_VIRT_TIME 0x00100000
11962 +#define VXF_HIDE_MOUNT 0x01000000
11963 +/* was VXF_HIDE_NETIF 0x02000000 */
11964 +#define VXF_HIDE_VINFO 0x04000000
11966 +#define VXF_STATE_SETUP (1ULL << 32)
11967 +#define VXF_STATE_INIT (1ULL << 33)
11968 +#define VXF_STATE_ADMIN (1ULL << 34)
11970 +#define VXF_SC_HELPER (1ULL << 36)
11971 +#define VXF_REBOOT_KILL (1ULL << 37)
11972 +#define VXF_PERSISTENT (1ULL << 38)
11974 +#define VXF_FORK_RSS (1ULL << 48)
11975 +#define VXF_PROLIFIC (1ULL << 49)
11977 +#define VXF_IGNEG_NICE (1ULL << 52)
11979 +#define VXF_ONE_TIME (0x0007ULL << 32)
11981 +#define VXF_INIT_SET (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11984 +/* context migration */
11986 +#define VXM_SET_INIT 0x00000001
11987 +#define VXM_SET_REAPER 0x00000002
11989 +/* context caps */
11991 +#define VXC_SET_UTSNAME 0x00000001
11992 +#define VXC_SET_RLIMIT 0x00000002
11993 +#define VXC_FS_SECURITY 0x00000004
11994 +#define VXC_FS_TRUSTED 0x00000008
11995 +#define VXC_TIOCSTI 0x00000010
11997 +/* was VXC_RAW_ICMP 0x00000100 */
11998 +#define VXC_SYSLOG 0x00001000
11999 +#define VXC_OOM_ADJUST 0x00002000
12000 +#define VXC_AUDIT_CONTROL 0x00004000
12002 +#define VXC_SECURE_MOUNT 0x00010000
12003 +/* #define VXC_SECURE_REMOUNT 0x00020000 */
12004 +#define VXC_BINARY_MOUNT 0x00040000
12005 +#define VXC_DEV_MOUNT 0x00080000
12007 +#define VXC_QUOTA_CTL 0x00100000
12008 +#define VXC_ADMIN_MAPPER 0x00200000
12009 +#define VXC_ADMIN_CLOOP 0x00400000
12011 +#define VXC_KTHREAD 0x01000000
12012 +#define VXC_NAMESPACE 0x02000000
12014 +#endif /* _UAPI_VS_CONTEXT_H */
12015 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/context_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context_cmd.h
12016 --- linux-3.13.10/include/uapi/vserver/context_cmd.h 1970-01-01 00:00:00.000000000 +0000
12017 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context_cmd.h 2014-01-31 20:38:03.000000000 +0000
12019 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12020 +#define _UAPI_VS_CONTEXT_CMD_H
12023 +/* vinfo commands */
12025 +#define VCMD_task_xid VC_CMD(VINFO, 1, 0)
12028 +#define VCMD_vx_info VC_CMD(VINFO, 5, 0)
12030 +struct vcmd_vx_info_v0 {
12032 + uint32_t initpid;
12033 + /* more to come */
12037 +#define VCMD_ctx_stat VC_CMD(VSTAT, 0, 0)
12039 +struct vcmd_ctx_stat_v0 {
12042 + /* more to come */
12046 +/* context commands */
12048 +#define VCMD_ctx_create_v0 VC_CMD(VPROC, 1, 0)
12049 +#define VCMD_ctx_create VC_CMD(VPROC, 1, 1)
12051 +struct vcmd_ctx_create {
12052 + uint64_t flagword;
12055 +#define VCMD_ctx_migrate_v0 VC_CMD(PROCMIG, 1, 0)
12056 +#define VCMD_ctx_migrate VC_CMD(PROCMIG, 1, 1)
12058 +struct vcmd_ctx_migrate {
12059 + uint64_t flagword;
12064 +/* flag commands */
12066 +#define VCMD_get_cflags VC_CMD(FLAGS, 1, 0)
12067 +#define VCMD_set_cflags VC_CMD(FLAGS, 2, 0)
12069 +struct vcmd_ctx_flags_v0 {
12070 + uint64_t flagword;
12076 +/* context caps commands */
12078 +#define VCMD_get_ccaps VC_CMD(FLAGS, 3, 1)
12079 +#define VCMD_set_ccaps VC_CMD(FLAGS, 4, 1)
12081 +struct vcmd_ctx_caps_v1 {
12088 +/* bcaps commands */
12090 +#define VCMD_get_bcaps VC_CMD(FLAGS, 9, 0)
12091 +#define VCMD_set_bcaps VC_CMD(FLAGS, 10, 0)
12093 +struct vcmd_bcaps {
12100 +/* umask commands */
12102 +#define VCMD_get_umask VC_CMD(FLAGS, 13, 0)
12103 +#define VCMD_set_umask VC_CMD(FLAGS, 14, 0)
12105 +struct vcmd_umask {
12112 +/* wmask commands */
12114 +#define VCMD_get_wmask VC_CMD(FLAGS, 15, 0)
12115 +#define VCMD_set_wmask VC_CMD(FLAGS, 16, 0)
12117 +struct vcmd_wmask {
12126 +#define VCMD_get_badness VC_CMD(MEMCTRL, 5, 0)
12127 +#define VCMD_set_badness VC_CMD(MEMCTRL, 6, 0)
12129 +struct vcmd_badness_v0 {
12133 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12134 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/cvirt_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cvirt_cmd.h
12135 --- linux-3.13.10/include/uapi/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
12136 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cvirt_cmd.h 2014-01-31 20:38:03.000000000 +0000
12138 +#ifndef _UAPI_VS_CVIRT_CMD_H
12139 +#define _UAPI_VS_CVIRT_CMD_H
12142 +/* virtual host info name commands */
12144 +#define VCMD_set_vhi_name VC_CMD(VHOST, 1, 0)
12145 +#define VCMD_get_vhi_name VC_CMD(VHOST, 2, 0)
12147 +struct vcmd_vhi_name_v0 {
12153 +enum vhi_name_field {
12154 + VHIN_CONTEXT = 0,
12165 +#define VCMD_virt_stat VC_CMD(VSTAT, 3, 0)
12167 +struct vcmd_virt_stat_v0 {
12170 + uint32_t nr_threads;
12171 + uint32_t nr_running;
12172 + uint32_t nr_uninterruptible;
12173 + uint32_t nr_onhold;
12174 + uint32_t nr_forks;
12175 + uint32_t load[3];
12178 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12179 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/debug_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/debug_cmd.h
12180 --- linux-3.13.10/include/uapi/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
12181 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/debug_cmd.h 2014-01-31 20:38:03.000000000 +0000
12183 +#ifndef _UAPI_VS_DEBUG_CMD_H
12184 +#define _UAPI_VS_DEBUG_CMD_H
12187 +/* debug commands */
12189 +#define VCMD_dump_history VC_CMD(DEBUG, 1, 0)
12191 +#define VCMD_read_history VC_CMD(DEBUG, 5, 0)
12192 +#define VCMD_read_monitor VC_CMD(DEBUG, 6, 0)
12194 +struct vcmd_read_history_v0 {
12197 + char __user *data;
12200 +struct vcmd_read_monitor_v0 {
12203 + char __user *data;
12206 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12207 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/device.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device.h
12208 --- linux-3.13.10/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
12209 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device.h 2014-01-31 20:38:03.000000000 +0000
12211 +#ifndef _UAPI_VS_DEVICE_H
12212 +#define _UAPI_VS_DEVICE_H
12215 +#define DATTR_CREATE 0x00000001
12216 +#define DATTR_OPEN 0x00000002
12218 +#define DATTR_REMAP 0x00000010
12220 +#define DATTR_MASK 0x00000013
12222 +#endif /* _UAPI_VS_DEVICE_H */
12223 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/device_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device_cmd.h
12224 --- linux-3.13.10/include/uapi/vserver/device_cmd.h 1970-01-01 00:00:00.000000000 +0000
12225 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device_cmd.h 2014-01-31 20:38:03.000000000 +0000
12227 +#ifndef _UAPI_VS_DEVICE_CMD_H
12228 +#define _UAPI_VS_DEVICE_CMD_H
12231 +/* device vserver commands */
12233 +#define VCMD_set_mapping VC_CMD(DEVICE, 1, 0)
12234 +#define VCMD_unset_mapping VC_CMD(DEVICE, 2, 0)
12236 +struct vcmd_set_mapping_v0 {
12237 + const char __user *device;
12238 + const char __user *target;
12242 +#endif /* _UAPI_VS_DEVICE_CMD_H */
12243 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/dlimit_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/dlimit_cmd.h
12244 --- linux-3.13.10/include/uapi/vserver/dlimit_cmd.h 1970-01-01 00:00:00.000000000 +0000
12245 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/dlimit_cmd.h 2014-01-31 20:38:03.000000000 +0000
12247 +#ifndef _UAPI_VS_DLIMIT_CMD_H
12248 +#define _UAPI_VS_DLIMIT_CMD_H
12251 +/* dlimit vserver commands */
12253 +#define VCMD_add_dlimit VC_CMD(DLIMIT, 1, 0)
12254 +#define VCMD_rem_dlimit VC_CMD(DLIMIT, 2, 0)
12256 +#define VCMD_set_dlimit VC_CMD(DLIMIT, 5, 0)
12257 +#define VCMD_get_dlimit VC_CMD(DLIMIT, 6, 0)
12259 +struct vcmd_ctx_dlimit_base_v0 {
12260 + const char __user *name;
12264 +struct vcmd_ctx_dlimit_v0 {
12265 + const char __user *name;
12266 + uint32_t space_used; /* used space in kbytes */
12267 + uint32_t space_total; /* maximum space in kbytes */
12268 + uint32_t inodes_used; /* used inodes */
12269 + uint32_t inodes_total; /* maximum inodes */
12270 + uint32_t reserved; /* reserved for root in % */
12274 +#define CDLIM_UNSET ((uint32_t)0UL)
12275 +#define CDLIM_INFINITY ((uint32_t)~0UL)
12276 +#define CDLIM_KEEP ((uint32_t)~1UL)
12278 +#define DLIME_UNIT 0
12279 +#define DLIME_KILO 1
12280 +#define DLIME_MEGA 2
12281 +#define DLIME_GIGA 3
12283 +#define DLIMF_SHIFT 0x10
12285 +#define DLIMS_USED 0
12286 +#define DLIMS_TOTAL 2
12289 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12291 + int exp = (flags & DLIMF_SHIFT) ?
12292 + (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12293 + return ((uint64_t)val) << (10 * exp);
12297 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12301 + if (*flags & DLIMF_SHIFT) {
12302 + while (val > (1LL << 32) && (exp < 3)) {
12306 + *flags &= ~(DLIME_GIGA << shift);
12307 + *flags |= exp << shift;
12313 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
12314 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/inode.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode.h
12315 --- linux-3.13.10/include/uapi/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
12316 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode.h 2014-01-31 20:38:03.000000000 +0000
12318 +#ifndef _UAPI_VS_INODE_H
12319 +#define _UAPI_VS_INODE_H
12322 +#define IATTR_TAG 0x01000000
12324 +#define IATTR_ADMIN 0x00000001
12325 +#define IATTR_WATCH 0x00000002
12326 +#define IATTR_HIDE 0x00000004
12327 +#define IATTR_FLAGS 0x00000007
12329 +#define IATTR_BARRIER 0x00010000
12330 +#define IATTR_IXUNLINK 0x00020000
12331 +#define IATTR_IMMUTABLE 0x00040000
12332 +#define IATTR_COW 0x00080000
12335 +/* inode ioctls */
12337 +#define FIOC_GETXFLG _IOR('x', 5, long)
12338 +#define FIOC_SETXFLG _IOW('x', 6, long)
12340 +#endif /* _UAPI_VS_INODE_H */
12341 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/inode_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode_cmd.h
12342 --- linux-3.13.10/include/uapi/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
12343 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode_cmd.h 2014-01-31 20:38:03.000000000 +0000
12345 +#ifndef _UAPI_VS_INODE_CMD_H
12346 +#define _UAPI_VS_INODE_CMD_H
12349 +/* inode vserver commands */
12351 +#define VCMD_get_iattr VC_CMD(INODE, 1, 1)
12352 +#define VCMD_set_iattr VC_CMD(INODE, 2, 1)
12354 +#define VCMD_fget_iattr VC_CMD(INODE, 3, 0)
12355 +#define VCMD_fset_iattr VC_CMD(INODE, 4, 0)
12357 +struct vcmd_ctx_iattr_v1 {
12358 + const char __user *name;
12364 +struct vcmd_ctx_fiattr_v0 {
12370 +#endif /* _UAPI_VS_INODE_CMD_H */
12371 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/limit.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit.h
12372 --- linux-3.13.10/include/uapi/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
12373 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit.h 2014-01-31 20:38:03.000000000 +0000
12375 +#ifndef _UAPI_VS_LIMIT_H
12376 +#define _UAPI_VS_LIMIT_H
12379 +#define VLIMIT_NSOCK 16
12380 +#define VLIMIT_OPENFD 17
12381 +#define VLIMIT_ANON 18
12382 +#define VLIMIT_SHMEM 19
12383 +#define VLIMIT_SEMARY 20
12384 +#define VLIMIT_NSEMS 21
12385 +#define VLIMIT_DENTRY 22
12386 +#define VLIMIT_MAPPED 23
12388 +#endif /* _UAPI_VS_LIMIT_H */
12389 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/limit_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit_cmd.h
12390 --- linux-3.13.10/include/uapi/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
12391 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit_cmd.h 2014-01-31 20:38:03.000000000 +0000
12393 +#ifndef _UAPI_VS_LIMIT_CMD_H
12394 +#define _UAPI_VS_LIMIT_CMD_H
12397 +/* rlimit vserver commands */
12399 +#define VCMD_get_rlimit VC_CMD(RLIMIT, 1, 0)
12400 +#define VCMD_set_rlimit VC_CMD(RLIMIT, 2, 0)
12401 +#define VCMD_get_rlimit_mask VC_CMD(RLIMIT, 3, 0)
12402 +#define VCMD_reset_hits VC_CMD(RLIMIT, 7, 0)
12403 +#define VCMD_reset_minmax VC_CMD(RLIMIT, 9, 0)
12405 +struct vcmd_ctx_rlimit_v0 {
12407 + uint64_t minimum;
12408 + uint64_t softlimit;
12409 + uint64_t maximum;
12412 +struct vcmd_ctx_rlimit_mask_v0 {
12413 + uint32_t minimum;
12414 + uint32_t softlimit;
12415 + uint32_t maximum;
12418 +#define VCMD_rlimit_stat VC_CMD(VSTAT, 1, 0)
12420 +struct vcmd_rlimit_stat_v0 {
12424 + uint64_t minimum;
12425 + uint64_t maximum;
12428 +#define CRLIM_UNSET (0ULL)
12429 +#define CRLIM_INFINITY (~0ULL)
12430 +#define CRLIM_KEEP (~1ULL)
12432 +#endif /* _UAPI_VS_LIMIT_CMD_H */
12433 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/monitor.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/monitor.h
12434 --- linux-3.13.10/include/uapi/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
12435 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/monitor.h 2014-01-31 20:38:03.000000000 +0000
12437 +#ifndef _UAPI_VS_MONITOR_H
12438 +#define _UAPI_VS_MONITOR_H
12440 +#include <linux/types.h>
12448 + VXM_UPDATE = 0x20,
12452 + VXM_RQINFO_1 = 0x24,
12455 + VXM_ACTIVATE = 0x40,
12462 + VXM_MIGRATE = 0x48,
12465 + /* all other bits are flags */
12466 + VXM_SCHED = 0x80,
12469 +struct _vxm_update_1 {
12470 + uint32_t tokens_max;
12471 + uint32_t fill_rate;
12472 + uint32_t interval;
12475 +struct _vxm_update_2 {
12476 + uint32_t tokens_min;
12477 + uint32_t fill_rate;
12478 + uint32_t interval;
12481 +struct _vxm_rqinfo_1 {
12482 + uint16_t running;
12486 + uint32_t idle_tokens;
12489 +struct _vxm_rqinfo_2 {
12490 + uint32_t norm_time;
12491 + uint32_t idle_time;
12492 + uint32_t idle_skip;
12495 +struct _vxm_sched {
12497 + uint32_t norm_time;
12498 + uint32_t idle_time;
12501 +struct _vxm_task {
12506 +struct _vxm_event {
12515 + struct _vxm_task tsk;
12519 +struct _vx_mon_entry {
12523 + struct _vxm_event ev;
12524 + struct _vxm_sched sd;
12525 + struct _vxm_update_1 u1;
12526 + struct _vxm_update_2 u2;
12527 + struct _vxm_rqinfo_1 q1;
12528 + struct _vxm_rqinfo_2 q2;
12532 +#endif /* _UAPI_VS_MONITOR_H */
12533 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/network.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network.h
12534 --- linux-3.13.10/include/uapi/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
12535 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network.h 2014-01-31 20:38:03.000000000 +0000
12537 +#ifndef _UAPI_VS_NETWORK_H
12538 +#define _UAPI_VS_NETWORK_H
12540 +#include <linux/types.h>
12543 +#define MAX_N_CONTEXT 65535 /* Arbitrary limit */
12546 +/* network flags */
12548 +#define NXF_INFO_PRIVATE 0x00000008
12550 +#define NXF_SINGLE_IP 0x00000100
12551 +#define NXF_LBACK_REMAP 0x00000200
12552 +#define NXF_LBACK_ALLOW 0x00000400
12554 +#define NXF_HIDE_NETIF 0x02000000
12555 +#define NXF_HIDE_LBACK 0x04000000
12557 +#define NXF_STATE_SETUP (1ULL << 32)
12558 +#define NXF_STATE_ADMIN (1ULL << 34)
12560 +#define NXF_SC_HELPER (1ULL << 36)
12561 +#define NXF_PERSISTENT (1ULL << 38)
12563 +#define NXF_ONE_TIME (0x0005ULL << 32)
12566 +#define NXF_INIT_SET (__nxf_init_set())
12568 +static inline uint64_t __nxf_init_set(void) {
12569 + return NXF_STATE_ADMIN
12570 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12571 + | NXF_LBACK_REMAP
12574 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12577 + | NXF_HIDE_NETIF;
12581 +/* network caps */
12583 +#define NXC_TUN_CREATE 0x00000001
12585 +#define NXC_RAW_ICMP 0x00000100
12587 +#define NXC_MULTICAST 0x00001000
12590 +/* address types */
12592 +#define NXA_TYPE_IPV4 0x0001
12593 +#define NXA_TYPE_IPV6 0x0002
12595 +#define NXA_TYPE_NONE 0x0000
12596 +#define NXA_TYPE_ANY 0x00FF
12598 +#define NXA_TYPE_ADDR 0x0010
12599 +#define NXA_TYPE_MASK 0x0020
12600 +#define NXA_TYPE_RANGE 0x0040
12602 +#define NXA_MASK_ALL (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12604 +#define NXA_MOD_BCAST 0x0100
12605 +#define NXA_MOD_LBACK 0x0200
12607 +#define NXA_LOOPBACK 0x1000
12609 +#define NXA_MASK_BIND (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12610 +#define NXA_MASK_SHOW (NXA_MASK_ALL | NXA_LOOPBACK)
12612 +#endif /* _UAPI_VS_NETWORK_H */
12613 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/network_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network_cmd.h
12614 --- linux-3.13.10/include/uapi/vserver/network_cmd.h 1970-01-01 00:00:00.000000000 +0000
12615 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network_cmd.h 2014-01-31 20:38:03.000000000 +0000
12617 +#ifndef _UAPI_VS_NETWORK_CMD_H
12618 +#define _UAPI_VS_NETWORK_CMD_H
12621 +/* vinfo commands */
12623 +#define VCMD_task_nid VC_CMD(VINFO, 2, 0)
12626 +#define VCMD_nx_info VC_CMD(VINFO, 6, 0)
12628 +struct vcmd_nx_info_v0 {
12630 + /* more to come */
12634 +#include <linux/in.h>
12635 +#include <linux/in6.h>
12637 +#define VCMD_net_create_v0 VC_CMD(VNET, 1, 0)
12638 +#define VCMD_net_create VC_CMD(VNET, 1, 1)
12640 +struct vcmd_net_create {
12641 + uint64_t flagword;
12644 +#define VCMD_net_migrate VC_CMD(NETMIG, 1, 0)
12646 +#define VCMD_net_add VC_CMD(NETALT, 1, 0)
12647 +#define VCMD_net_remove VC_CMD(NETALT, 2, 0)
12649 +struct vcmd_net_addr_v0 {
12652 + struct in_addr ip[4];
12653 + struct in_addr mask[4];
12656 +#define VCMD_net_add_ipv4_v1 VC_CMD(NETALT, 1, 1)
12657 +#define VCMD_net_rem_ipv4_v1 VC_CMD(NETALT, 2, 1)
12659 +struct vcmd_net_addr_ipv4_v1 {
12662 + struct in_addr ip;
12663 + struct in_addr mask;
12666 +#define VCMD_net_add_ipv4 VC_CMD(NETALT, 1, 2)
12667 +#define VCMD_net_rem_ipv4 VC_CMD(NETALT, 2, 2)
12669 +struct vcmd_net_addr_ipv4_v2 {
12672 + struct in_addr ip;
12673 + struct in_addr ip2;
12674 + struct in_addr mask;
12677 +#define VCMD_net_add_ipv6 VC_CMD(NETALT, 3, 1)
12678 +#define VCMD_net_remove_ipv6 VC_CMD(NETALT, 4, 1)
12680 +struct vcmd_net_addr_ipv6_v1 {
12684 + struct in6_addr ip;
12685 + struct in6_addr mask;
12688 +#define VCMD_add_match_ipv4 VC_CMD(NETALT, 5, 0)
12689 +#define VCMD_get_match_ipv4 VC_CMD(NETALT, 6, 0)
12691 +struct vcmd_match_ipv4_v0 {
12696 + struct in_addr ip;
12697 + struct in_addr ip2;
12698 + struct in_addr mask;
12701 +#define VCMD_add_match_ipv6 VC_CMD(NETALT, 7, 0)
12702 +#define VCMD_get_match_ipv6 VC_CMD(NETALT, 8, 0)
12704 +struct vcmd_match_ipv6_v0 {
12709 + struct in6_addr ip;
12710 + struct in6_addr ip2;
12711 + struct in6_addr mask;
12717 +/* flag commands */
12719 +#define VCMD_get_nflags VC_CMD(FLAGS, 5, 0)
12720 +#define VCMD_set_nflags VC_CMD(FLAGS, 6, 0)
12722 +struct vcmd_net_flags_v0 {
12723 + uint64_t flagword;
12729 +/* network caps commands */
12731 +#define VCMD_get_ncaps VC_CMD(FLAGS, 7, 0)
12732 +#define VCMD_set_ncaps VC_CMD(FLAGS, 8, 0)
12734 +struct vcmd_net_caps_v0 {
12739 +#endif /* _UAPI_VS_NETWORK_CMD_H */
12740 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/sched_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/sched_cmd.h
12741 --- linux-3.13.10/include/uapi/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
12742 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/sched_cmd.h 2014-01-31 20:38:03.000000000 +0000
12744 +#ifndef _UAPI_VS_SCHED_CMD_H
12745 +#define _UAPI_VS_SCHED_CMD_H
12748 +struct vcmd_prio_bias {
12750 + int32_t prio_bias;
12753 +#define VCMD_set_prio_bias VC_CMD(SCHED, 4, 0)
12754 +#define VCMD_get_prio_bias VC_CMD(SCHED, 5, 0)
12756 +#endif /* _UAPI_VS_SCHED_CMD_H */
12757 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/signal_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/signal_cmd.h
12758 --- linux-3.13.10/include/uapi/vserver/signal_cmd.h 1970-01-01 00:00:00.000000000 +0000
12759 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/signal_cmd.h 2014-01-31 20:38:03.000000000 +0000
12761 +#ifndef _UAPI_VS_SIGNAL_CMD_H
12762 +#define _UAPI_VS_SIGNAL_CMD_H
12765 +/* signalling vserver commands */
12767 +#define VCMD_ctx_kill VC_CMD(PROCTRL, 1, 0)
12768 +#define VCMD_wait_exit VC_CMD(EVENT, 99, 0)
12770 +struct vcmd_ctx_kill_v0 {
12775 +struct vcmd_wait_exit_v0 {
12776 + int32_t reboot_cmd;
12777 + int32_t exit_code;
12781 +/* process alteration commands */
12783 +#define VCMD_get_pflags VC_CMD(PROCALT, 5, 0)
12784 +#define VCMD_set_pflags VC_CMD(PROCALT, 6, 0)
12786 +struct vcmd_pflags_v0 {
12787 + uint32_t flagword;
12791 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
12792 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/space_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/space_cmd.h
12793 --- linux-3.13.10/include/uapi/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
12794 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/space_cmd.h 2014-01-31 20:38:03.000000000 +0000
12796 +#ifndef _UAPI_VS_SPACE_CMD_H
12797 +#define _UAPI_VS_SPACE_CMD_H
12800 +#define VCMD_enter_space_v0 VC_CMD(PROCALT, 1, 0)
12801 +#define VCMD_enter_space_v1 VC_CMD(PROCALT, 1, 1)
12802 +#define VCMD_enter_space VC_CMD(PROCALT, 1, 2)
12804 +#define VCMD_set_space_v0 VC_CMD(PROCALT, 3, 0)
12805 +#define VCMD_set_space_v1 VC_CMD(PROCALT, 3, 1)
12806 +#define VCMD_set_space VC_CMD(PROCALT, 3, 2)
12808 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12810 +#define VCMD_get_space_mask VC_CMD(VSPACE, 0, 1)
12811 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12814 +struct vcmd_space_mask_v1 {
12818 +struct vcmd_space_mask_v2 {
12823 +#endif /* _UAPI_VS_SPACE_CMD_H */
12824 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/switch.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/switch.h
12825 --- linux-3.13.10/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12826 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/switch.h 2014-01-31 20:38:03.000000000 +0000
12828 +#ifndef _UAPI_VS_SWITCH_H
12829 +#define _UAPI_VS_SWITCH_H
12831 +#include <linux/types.h>
12834 +#define VC_CATEGORY(c) (((c) >> 24) & 0x3F)
12835 +#define VC_COMMAND(c) (((c) >> 16) & 0xFF)
12836 +#define VC_VERSION(c) ((c) & 0xFFF)
12838 +#define VC_CMD(c, i, v) ((((VC_CAT_ ## c) & 0x3F) << 24) \
12839 + | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12843 + Syscall Matrix V2.8
12845 + |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12846 + |STATS |DESTROY|ALTER |CHANGE |LIMIT |TEST | | | |
12847 + |INFO |SETUP | |MOVE | | | | | |
12848 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12849 + SYSTEM |VERSION|VSETUP |VHOST | | | | |DEVICE | |
12850 + HOST | 00| 01| 02| 03| 04| 05| | 06| 07|
12851 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12852 + CPU | |VPROC |PROCALT|PROCMIG|PROCTRL| | |SCHED. | |
12853 + PROCESS| 08| 09| 10| 11| 12| 13| | 14| 15|
12854 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12855 + MEMORY | | | | |MEMCTRL| | |SWAP | |
12856 + | 16| 17| 18| 19| 20| 21| | 22| 23|
12857 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12858 + NETWORK| |VNET |NETALT |NETMIG |NETCTL | | |SERIAL | |
12859 + | 24| 25| 26| 27| 28| 29| | 30| 31|
12860 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12861 + DISK | | | |TAGMIG |DLIMIT | | |INODE | |
12862 + VFS | 32| 33| 34| 35| 36| 37| | 38| 39|
12863 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12864 + OTHER |VSTAT | | | | | | |VINFO | |
12865 + | 40| 41| 42| 43| 44| 45| | 46| 47|
12866 + =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12867 + SPECIAL|EVENT | | | |FLAGS | | |VSPACE | |
12868 + | 48| 49| 50| 51| 52| 53| | 54| 55|
12869 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12870 + SPECIAL|DEBUG | | | |RLIMIT |SYSCALL| | |COMPAT |
12871 + | 56| 57| 58| 59| 60|TEST 61| | 62| 63|
12872 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12876 +#define VC_CAT_VERSION 0
12878 +#define VC_CAT_VSETUP 1
12879 +#define VC_CAT_VHOST 2
12881 +#define VC_CAT_DEVICE 6
12883 +#define VC_CAT_VPROC 9
12884 +#define VC_CAT_PROCALT 10
12885 +#define VC_CAT_PROCMIG 11
12886 +#define VC_CAT_PROCTRL 12
12888 +#define VC_CAT_SCHED 14
12889 +#define VC_CAT_MEMCTRL 20
12891 +#define VC_CAT_VNET 25
12892 +#define VC_CAT_NETALT 26
12893 +#define VC_CAT_NETMIG 27
12894 +#define VC_CAT_NETCTRL 28
12896 +#define VC_CAT_TAGMIG 35
12897 +#define VC_CAT_DLIMIT 36
12898 +#define VC_CAT_INODE 38
12900 +#define VC_CAT_VSTAT 40
12901 +#define VC_CAT_VINFO 46
12902 +#define VC_CAT_EVENT 48
12904 +#define VC_CAT_FLAGS 52
12905 +#define VC_CAT_VSPACE 54
12906 +#define VC_CAT_DEBUG 56
12907 +#define VC_CAT_RLIMIT 60
12909 +#define VC_CAT_SYSTEST 61
12910 +#define VC_CAT_COMPAT 63
12912 +/* query version */
12914 +#define VCMD_get_version VC_CMD(VERSION, 0, 0)
12915 +#define VCMD_get_vci VC_CMD(VERSION, 1, 0)
12917 +#endif /* _UAPI_VS_SWITCH_H */
12918 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/tag_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/tag_cmd.h
12919 --- linux-3.13.10/include/uapi/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
12920 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/tag_cmd.h 2014-01-31 20:38:03.000000000 +0000
12922 +#ifndef _UAPI_VS_TAG_CMD_H
12923 +#define _UAPI_VS_TAG_CMD_H
12926 +/* vinfo commands */
12928 +#define VCMD_task_tag VC_CMD(VINFO, 3, 0)
12931 +/* context commands */
12933 +#define VCMD_tag_migrate VC_CMD(TAGMIG, 1, 0)
12935 +#endif /* _UAPI_VS_TAG_CMD_H */
12936 diff -NurpP --minimal linux-3.13.10/init/Kconfig linux-3.13.10-vs2.3.6.11/init/Kconfig
12937 --- linux-3.13.10/init/Kconfig 2014-04-17 01:12:39.000000000 +0000
12938 +++ linux-3.13.10-vs2.3.6.11/init/Kconfig 2014-04-17 01:17:11.000000000 +0000
12939 @@ -855,6 +855,7 @@ config NUMA_BALANCING
12942 boolean "Control Group support"
12945 This option adds support for grouping sets of processes together, for
12946 use with process control subsystems such as Cpusets, CFS, memory
12947 @@ -1117,6 +1118,7 @@ config IPC_NS
12950 bool "User namespace"
12951 + depends on VSERVER_DISABLED
12954 This allows containers, i.e. vservers, to use user namespaces
12955 diff -NurpP --minimal linux-3.13.10/init/main.c linux-3.13.10-vs2.3.6.11/init/main.c
12956 --- linux-3.13.10/init/main.c 2014-01-22 20:39:12.000000000 +0000
12957 +++ linux-3.13.10-vs2.3.6.11/init/main.c 2014-01-31 20:38:03.000000000 +0000
12959 #include <linux/sched_clock.h>
12960 #include <linux/context_tracking.h>
12961 #include <linux/random.h>
12962 +#include <linux/vserver/percpu.h>
12964 #include <asm/io.h>
12965 #include <asm/bugs.h>
12966 diff -NurpP --minimal linux-3.13.10/ipc/mqueue.c linux-3.13.10-vs2.3.6.11/ipc/mqueue.c
12967 --- linux-3.13.10/ipc/mqueue.c 2014-04-17 01:12:39.000000000 +0000
12968 +++ linux-3.13.10-vs2.3.6.11/ipc/mqueue.c 2014-03-12 15:51:08.000000000 +0000
12970 #include <linux/ipc_namespace.h>
12971 #include <linux/user_namespace.h>
12972 #include <linux/slab.h>
12973 +#include <linux/vs_context.h>
12974 +#include <linux/vs_limit.h>
12976 #include <net/sock.h>
12978 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
12979 struct pid* notify_owner;
12980 struct user_namespace *notify_user_ns;
12981 struct user_struct *user; /* user who created, for accounting */
12982 + struct vx_info *vxi;
12983 struct sock *notify_sock;
12984 struct sk_buff *notify_cookie;
12986 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
12987 if (S_ISREG(mode)) {
12988 struct mqueue_inode_info *info;
12989 unsigned long mq_bytes, mq_treesize;
12990 + struct vx_info *vxi = current_vx_info();
12992 inode->i_fop = &mqueue_file_operations;
12993 inode->i_size = FILENT_SIZE;
12994 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
12995 info->notify_user_ns = NULL;
12997 info->user = NULL; /* set when all is ok */
12998 + info->vxi = NULL;
12999 info->msg_tree = RB_ROOT;
13000 info->node_cache = NULL;
13001 memset(&info->attr, 0, sizeof(info->attr));
13002 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13004 spin_lock(&mq_lock);
13005 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13006 - u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13007 + u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13008 + !vx_ipcmsg_avail(vxi, mq_bytes)) {
13009 spin_unlock(&mq_lock);
13010 /* mqueue_evict_inode() releases info->messages */
13014 u->mq_bytes += mq_bytes;
13015 + vx_ipcmsg_add(vxi, u, mq_bytes);
13016 spin_unlock(&mq_lock);
13019 info->user = get_uid(u);
13020 + info->vxi = get_vx_info(vxi);
13021 } else if (S_ISDIR(mode)) {
13023 /* Some things misbehave if size == 0 on a directory */
13024 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13028 + struct vx_info *vxi = info->vxi;
13030 spin_lock(&mq_lock);
13031 user->mq_bytes -= mq_bytes;
13032 + vx_ipcmsg_sub(vxi, user, mq_bytes);
13034 * get_ns_from_inode() ensures that the
13035 * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13036 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13038 ipc_ns->mq_queues_count--;
13039 spin_unlock(&mq_lock);
13040 + put_vx_info(vxi);
13044 diff -NurpP --minimal linux-3.13.10/ipc/msg.c linux-3.13.10-vs2.3.6.11/ipc/msg.c
13045 --- linux-3.13.10/ipc/msg.c 2014-04-17 01:12:39.000000000 +0000
13046 +++ linux-3.13.10-vs2.3.6.11/ipc/msg.c 2014-04-17 01:17:11.000000000 +0000
13048 #include <linux/rwsem.h>
13049 #include <linux/nsproxy.h>
13050 #include <linux/ipc_namespace.h>
13051 +#include <linux/vs_base.h>
13053 #include <asm/current.h>
13054 #include <asm/uaccess.h>
13055 @@ -194,6 +195,7 @@ static int newque(struct ipc_namespace *
13057 msq->q_perm.mode = msgflg & S_IRWXUGO;
13058 msq->q_perm.key = key;
13059 + msq->q_perm.xid = vx_current_xid();
13061 msq->q_perm.security = NULL;
13062 retval = security_msg_queue_alloc(msq);
13063 diff -NurpP --minimal linux-3.13.10/ipc/sem.c linux-3.13.10-vs2.3.6.11/ipc/sem.c
13064 --- linux-3.13.10/ipc/sem.c 2013-11-25 15:47:03.000000000 +0000
13065 +++ linux-3.13.10-vs2.3.6.11/ipc/sem.c 2014-01-31 20:38:03.000000000 +0000
13067 #include <linux/rwsem.h>
13068 #include <linux/nsproxy.h>
13069 #include <linux/ipc_namespace.h>
13070 +#include <linux/vs_base.h>
13071 +#include <linux/vs_limit.h>
13073 #include <asm/uaccess.h>
13075 @@ -500,6 +502,7 @@ static int newary(struct ipc_namespace *
13077 sma->sem_perm.mode = (semflg & S_IRWXUGO);
13078 sma->sem_perm.key = key;
13079 + sma->sem_perm.xid = vx_current_xid();
13081 sma->sem_perm.security = NULL;
13082 retval = security_sem_alloc(sma);
13083 @@ -514,6 +517,9 @@ static int newary(struct ipc_namespace *
13086 ns->used_sems += nsems;
13087 + /* FIXME: obsoleted? */
13088 + vx_semary_inc(sma);
13089 + vx_nsems_add(sma, nsems);
13091 sma->sem_base = (struct sem *) &sma[1];
13093 @@ -1103,6 +1109,9 @@ static void freeary(struct ipc_namespace
13095 wake_up_sem_queue_do(&tasks);
13096 ns->used_sems -= sma->sem_nsems;
13097 + /* FIXME: obsoleted? */
13098 + vx_nsems_sub(sma, sma->sem_nsems);
13099 + vx_semary_dec(sma);
13100 ipc_rcu_putref(sma, sem_rcu_free);
13103 diff -NurpP --minimal linux-3.13.10/ipc/shm.c linux-3.13.10-vs2.3.6.11/ipc/shm.c
13104 --- linux-3.13.10/ipc/shm.c 2014-01-22 20:39:12.000000000 +0000
13105 +++ linux-3.13.10-vs2.3.6.11/ipc/shm.c 2014-01-31 20:38:03.000000000 +0000
13107 #include <linux/nsproxy.h>
13108 #include <linux/mount.h>
13109 #include <linux/ipc_namespace.h>
13110 +#include <linux/vs_context.h>
13111 +#include <linux/vs_limit.h>
13113 #include <asm/uaccess.h>
13115 @@ -209,10 +211,14 @@ static void shm_open(struct vm_area_stru
13116 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13118 struct file *shm_file;
13119 + struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13120 + int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13122 shm_file = shp->shm_file;
13123 shp->shm_file = NULL;
13124 - ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13125 + vx_ipcshm_sub(vxi, shp, numpages);
13126 + ns->shm_tot -= numpages;
13130 if (!is_file_hugepages(shm_file))
13131 @@ -220,6 +226,7 @@ static void shm_destroy(struct ipc_names
13132 else if (shp->mlock_user)
13133 user_shm_unlock(file_inode(shm_file)->i_size, shp->mlock_user);
13135 + put_vx_info(vxi);
13136 ipc_rcu_putref(shp, shm_rcu_free);
13139 @@ -497,11 +504,15 @@ static int newseg(struct ipc_namespace *
13140 if (ns->shm_tot + numpages > ns->shm_ctlall)
13143 + if (!vx_ipcshm_avail(current_vx_info(), numpages))
13146 shp = ipc_rcu_alloc(sizeof(*shp));
13150 shp->shm_perm.key = key;
13151 + shp->shm_perm.xid = vx_current_xid();
13152 shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13153 shp->mlock_user = NULL;
13155 @@ -570,6 +581,7 @@ static int newseg(struct ipc_namespace *
13157 ipc_unlock_object(&shp->shm_perm);
13159 + vx_ipcshm_add(current_vx_info(), key, numpages);
13163 diff -NurpP --minimal linux-3.13.10/kernel/Makefile linux-3.13.10-vs2.3.6.11/kernel/Makefile
13164 --- linux-3.13.10/kernel/Makefile 2014-01-22 20:39:12.000000000 +0000
13165 +++ linux-3.13.10-vs2.3.6.11/kernel/Makefile 2014-01-31 21:36:22.000000000 +0000
13166 @@ -25,6 +25,7 @@ obj-y += printk/
13172 obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13173 obj-$(CONFIG_FREEZER) += freezer.o
13174 diff -NurpP --minimal linux-3.13.10/kernel/auditsc.c linux-3.13.10-vs2.3.6.11/kernel/auditsc.c
13175 --- linux-3.13.10/kernel/auditsc.c 2014-04-17 01:12:39.000000000 +0000
13176 +++ linux-3.13.10-vs2.3.6.11/kernel/auditsc.c 2014-04-17 01:17:11.000000000 +0000
13177 @@ -1956,7 +1956,7 @@ static int audit_set_loginuid_perm(kuid_
13178 if (is_audit_feature_set(AUDIT_FEATURE_LOGINUID_IMMUTABLE))
13180 /* it is set, you need permission */
13181 - if (!capable(CAP_AUDIT_CONTROL))
13182 + if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13184 /* reject if this is not an unset and we don't allow that */
13185 if (is_audit_feature_set(AUDIT_FEATURE_ONLY_UNSET_LOGINUID) && uid_valid(loginuid))
13186 diff -NurpP --minimal linux-3.13.10/kernel/capability.c linux-3.13.10-vs2.3.6.11/kernel/capability.c
13187 --- linux-3.13.10/kernel/capability.c 2013-11-25 15:47:03.000000000 +0000
13188 +++ linux-3.13.10-vs2.3.6.11/kernel/capability.c 2014-01-31 20:38:03.000000000 +0000
13190 #include <linux/syscalls.h>
13191 #include <linux/pid_namespace.h>
13192 #include <linux/user_namespace.h>
13193 +#include <linux/vs_context.h>
13194 #include <asm/uaccess.h>
13197 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13203 * The only thing that can change the capabilities of the current
13204 * process is the current process. As such, we can't be in this code
13205 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13209 +#include <linux/vserver/base.h>
13212 * has_capability_noaudit - Does a task have a capability (unaudited) in the
13214 diff -NurpP --minimal linux-3.13.10/kernel/compat.c linux-3.13.10-vs2.3.6.11/kernel/compat.c
13215 --- linux-3.13.10/kernel/compat.c 2013-07-14 17:01:34.000000000 +0000
13216 +++ linux-3.13.10-vs2.3.6.11/kernel/compat.c 2014-01-31 20:38:03.000000000 +0000
13218 #include <linux/times.h>
13219 #include <linux/ptrace.h>
13220 #include <linux/gfp.h>
13221 +#include <linux/vs_time.h>
13223 #include <asm/uaccess.h>
13225 @@ -1040,7 +1041,7 @@ asmlinkage long compat_sys_stime(compat_
13229 - do_settimeofday(&tv);
13230 + vx_settimeofday(&tv);
13234 diff -NurpP --minimal linux-3.13.10/kernel/cred.c linux-3.13.10-vs2.3.6.11/kernel/cred.c
13235 --- linux-3.13.10/kernel/cred.c 2013-02-19 13:58:56.000000000 +0000
13236 +++ linux-3.13.10-vs2.3.6.11/kernel/cred.c 2014-01-31 20:38:03.000000000 +0000
13237 @@ -56,31 +56,6 @@ struct cred init_cred = {
13238 .group_info = &init_groups,
13241 -static inline void set_cred_subscribers(struct cred *cred, int n)
13243 -#ifdef CONFIG_DEBUG_CREDENTIALS
13244 - atomic_set(&cred->subscribers, n);
13248 -static inline int read_cred_subscribers(const struct cred *cred)
13250 -#ifdef CONFIG_DEBUG_CREDENTIALS
13251 - return atomic_read(&cred->subscribers);
13257 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
13259 -#ifdef CONFIG_DEBUG_CREDENTIALS
13260 - struct cred *cred = (struct cred *) _cred;
13262 - atomic_add(n, &cred->subscribers);
13267 * The RCU callback to actually dispose of a set of credentials
13269 @@ -232,21 +207,16 @@ error:
13271 * Call commit_creds() or abort_creds() to clean up.
13273 -struct cred *prepare_creds(void)
13274 +struct cred *__prepare_creds(const struct cred *old)
13276 - struct task_struct *task = current;
13277 - const struct cred *old;
13280 - validate_process_creds();
13282 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13286 kdebug("prepare_creds() alloc %p", new);
13288 - old = task->cred;
13289 memcpy(new, old, sizeof(struct cred));
13291 atomic_set(&new->usage, 1);
13292 @@ -275,6 +245,13 @@ error:
13297 +struct cred *prepare_creds(void)
13299 + validate_process_creds();
13301 + return __prepare_creds(current->cred);
13303 EXPORT_SYMBOL(prepare_creds);
13306 diff -NurpP --minimal linux-3.13.10/kernel/exit.c linux-3.13.10-vs2.3.6.11/kernel/exit.c
13307 --- linux-3.13.10/kernel/exit.c 2013-11-25 15:45:07.000000000 +0000
13308 +++ linux-3.13.10-vs2.3.6.11/kernel/exit.c 2014-01-31 20:38:03.000000000 +0000
13310 #include <linux/fs_struct.h>
13311 #include <linux/init_task.h>
13312 #include <linux/perf_event.h>
13313 +#include <linux/vs_limit.h>
13314 +#include <linux/vs_context.h>
13315 +#include <linux/vs_network.h>
13316 +#include <linux/vs_pid.h>
13317 #include <trace/events/sched.h>
13318 #include <linux/hw_breakpoint.h>
13319 #include <linux/oom.h>
13320 @@ -503,15 +507,25 @@ static struct task_struct *find_new_reap
13321 __acquires(&tasklist_lock)
13323 struct pid_namespace *pid_ns = task_active_pid_ns(father);
13324 - struct task_struct *thread;
13325 + struct vx_info *vxi = task_get_vx_info(father);
13326 + struct task_struct *thread = father;
13327 + struct task_struct *reaper;
13330 while_each_thread(father, thread) {
13331 if (thread->flags & PF_EXITING)
13333 if (unlikely(pid_ns->child_reaper == father))
13334 pid_ns->child_reaper = thread;
13340 + reaper = pid_ns->child_reaper;
13342 + BUG_ON(!vxi->vx_reaper);
13343 + if (vxi->vx_reaper != init_pid_ns.child_reaper &&
13344 + vxi->vx_reaper != father)
13345 + reaper = vxi->vx_reaper;
13348 if (unlikely(pid_ns->child_reaper == father)) {
13349 @@ -549,7 +563,9 @@ static struct task_struct *find_new_reap
13353 - return pid_ns->child_reaper;
13355 + put_vx_info(vxi);
13360 @@ -600,10 +616,15 @@ static void forget_original_parent(struc
13361 list_for_each_entry_safe(p, n, &father->children, sibling) {
13362 struct task_struct *t = p;
13364 - t->real_parent = reaper;
13365 + struct task_struct *new_parent = reaper;
13367 + if (unlikely(p == reaper))
13368 + new_parent = task_active_pid_ns(p)->child_reaper;
13370 + t->real_parent = new_parent;
13371 if (t->parent == father) {
13373 - t->parent = t->real_parent;
13374 + t->parent = new_parent;
13376 if (t->pdeath_signal)
13377 group_send_sig_info(t->pdeath_signal,
13378 @@ -810,6 +831,9 @@ void do_exit(long code)
13380 flush_ptrace_hw_breakpoint(tsk);
13382 + /* needs to stay before exit_notify() */
13383 + exit_vx_info_early(tsk, code);
13385 exit_notify(tsk, group_dead);
13388 @@ -863,10 +887,15 @@ void do_exit(long code)
13390 raw_spin_unlock_wait(&tsk->pi_lock);
13392 + /* needs to stay after exit_notify() */
13393 + exit_vx_info(tsk, code);
13394 + exit_nx_info(tsk);
13396 /* causes final put_task_struct in finish_task_switch(). */
13397 tsk->state = TASK_DEAD;
13398 tsk->flags |= PF_NOFREEZE; /* tell freezer to ignore us */
13400 + printk("bad task: %p [%lx]\n", current, current->state);
13402 /* Avoid "noreturn function does return". */
13404 diff -NurpP --minimal linux-3.13.10/kernel/fork.c linux-3.13.10-vs2.3.6.11/kernel/fork.c
13405 --- linux-3.13.10/kernel/fork.c 2014-01-22 20:39:13.000000000 +0000
13406 +++ linux-3.13.10-vs2.3.6.11/kernel/fork.c 2014-01-31 20:38:03.000000000 +0000
13408 #include <linux/signalfd.h>
13409 #include <linux/uprobes.h>
13410 #include <linux/aio.h>
13411 +#include <linux/vs_context.h>
13412 +#include <linux/vs_network.h>
13413 +#include <linux/vs_limit.h>
13415 #include <asm/pgtable.h>
13416 #include <asm/pgalloc.h>
13417 @@ -211,6 +214,8 @@ void free_task(struct task_struct *tsk)
13418 arch_release_thread_info(tsk->stack);
13419 free_thread_info(tsk->stack);
13420 rt_mutex_debug_task_free(tsk);
13421 + clr_vx_info(&tsk->vx_info);
13422 + clr_nx_info(&tsk->nx_info);
13423 ftrace_graph_exit_task(tsk);
13424 put_seccomp_filter(tsk);
13425 arch_release_task_struct(tsk);
13426 @@ -542,6 +547,7 @@ static struct mm_struct *mm_init(struct
13427 if (likely(!mm_alloc_pgd(mm))) {
13429 mmu_notifier_mm_init(mm);
13430 + set_vx_info(&mm->mm_vx_info, p->vx_info);
13434 @@ -594,6 +600,7 @@ void __mmdrop(struct mm_struct *mm)
13435 destroy_context(mm);
13436 mmu_notifier_mm_destroy(mm);
13438 + clr_vx_info(&mm->mm_vx_info);
13441 EXPORT_SYMBOL_GPL(__mmdrop);
13442 @@ -813,6 +820,7 @@ struct mm_struct *dup_mm(struct task_str
13445 memcpy(mm, oldmm, sizeof(*mm));
13446 + mm->mm_vx_info = NULL;
13447 mm_init_cpumask(mm);
13449 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
13450 @@ -851,6 +859,7 @@ fail_nocontext:
13451 * If init_new_context() failed, we cannot use mmput() to free the mm
13452 * because it calls destroy_context()
13454 + clr_vx_info(&mm->mm_vx_info);
13458 @@ -1135,6 +1144,8 @@ static struct task_struct *copy_process(
13461 struct task_struct *p;
13462 + struct vx_info *vxi;
13463 + struct nx_info *nxi;
13465 if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
13466 return ERR_PTR(-EINVAL);
13467 @@ -1197,7 +1208,12 @@ static struct task_struct *copy_process(
13468 DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
13469 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
13471 + init_vx_info(&p->vx_info, current_vx_info());
13472 + init_nx_info(&p->nx_info, current_nx_info());
13475 + if (!vx_nproc_avail(1))
13476 + goto bad_fork_free;
13477 if (atomic_read(&p->real_cred->user->processes) >=
13478 task_rlimit(p, RLIMIT_NPROC)) {
13479 if (p->real_cred->user != INIT_USER &&
13480 @@ -1479,6 +1495,18 @@ static struct task_struct *copy_process(
13483 spin_unlock(¤t->sighand->siglock);
13485 + /* p is copy of current */
13486 + vxi = p->vx_info;
13488 + claim_vx_info(vxi, p);
13489 + atomic_inc(&vxi->cvirt.nr_threads);
13490 + atomic_inc(&vxi->cvirt.total_forks);
13493 + nxi = p->nx_info;
13495 + claim_nx_info(nxi, p);
13496 write_unlock_irq(&tasklist_lock);
13497 proc_fork_connector(p);
13498 cgroup_post_fork(p);
13499 diff -NurpP --minimal linux-3.13.10/kernel/kthread.c linux-3.13.10-vs2.3.6.11/kernel/kthread.c
13500 --- linux-3.13.10/kernel/kthread.c 2014-01-22 20:39:13.000000000 +0000
13501 +++ linux-3.13.10-vs2.3.6.11/kernel/kthread.c 2014-01-31 20:38:03.000000000 +0000
13503 #include <linux/freezer.h>
13504 #include <linux/ptrace.h>
13505 #include <linux/uaccess.h>
13506 +#include <linux/vs_pid.h>
13507 #include <trace/events/sched.h>
13509 static DEFINE_SPINLOCK(kthread_create_lock);
13510 diff -NurpP --minimal linux-3.13.10/kernel/nsproxy.c linux-3.13.10-vs2.3.6.11/kernel/nsproxy.c
13511 --- linux-3.13.10/kernel/nsproxy.c 2013-11-25 15:47:03.000000000 +0000
13512 +++ linux-3.13.10-vs2.3.6.11/kernel/nsproxy.c 2014-02-01 00:17:43.000000000 +0000
13513 @@ -20,11 +20,14 @@
13514 #include <linux/mnt_namespace.h>
13515 #include <linux/utsname.h>
13516 #include <linux/pid_namespace.h>
13517 +#include <linux/vserver/global.h>
13518 +#include <linux/vserver/debug.h>
13519 #include <net/net_namespace.h>
13520 #include <linux/ipc_namespace.h>
13521 #include <linux/proc_ns.h>
13522 #include <linux/file.h>
13523 #include <linux/syscalls.h>
13524 +#include "../fs/mount.h"
13526 static struct kmem_cache *nsproxy_cachep;
13528 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
13529 struct nsproxy *nsproxy;
13531 nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
13534 atomic_set(&nsproxy->count, 1);
13535 + atomic_inc(&vs_global_nsproxy);
13537 + vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
13541 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
13542 * Return the newly created nsproxy. Do not attach this to the task,
13543 * leave it to the caller to do proper locking and attach it to task.
13545 -static struct nsproxy *create_new_namespaces(unsigned long flags,
13546 - struct task_struct *tsk, struct user_namespace *user_ns,
13547 - struct fs_struct *new_fs)
13548 +static struct nsproxy *unshare_namespaces(
13549 + unsigned long flags,
13550 + struct nsproxy *orig,
13551 + struct fs_struct *new_fs,
13552 + struct user_namespace *new_user,
13553 + struct pid_namespace *new_pid)
13555 struct nsproxy *new_nsp;
13557 @@ -67,32 +76,31 @@ static struct nsproxy *create_new_namesp
13559 return ERR_PTR(-ENOMEM);
13561 - new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
13562 + new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
13563 if (IS_ERR(new_nsp->mnt_ns)) {
13564 err = PTR_ERR(new_nsp->mnt_ns);
13568 - new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
13569 + new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
13570 if (IS_ERR(new_nsp->uts_ns)) {
13571 err = PTR_ERR(new_nsp->uts_ns);
13575 - new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
13576 + new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
13577 if (IS_ERR(new_nsp->ipc_ns)) {
13578 err = PTR_ERR(new_nsp->ipc_ns);
13582 - new_nsp->pid_ns_for_children =
13583 - copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children);
13584 + new_nsp->pid_ns_for_children = copy_pid_ns(flags, new_user, new_pid);
13585 if (IS_ERR(new_nsp->pid_ns_for_children)) {
13586 err = PTR_ERR(new_nsp->pid_ns_for_children);
13590 - new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
13591 + new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
13592 if (IS_ERR(new_nsp->net_ns)) {
13593 err = PTR_ERR(new_nsp->net_ns);
13595 @@ -117,6 +125,41 @@ out_ns:
13596 return ERR_PTR(err);
13599 +static struct nsproxy *create_new_namespaces(unsigned long flags,
13600 + struct task_struct *tsk, struct user_namespace *user_ns,
13601 + struct fs_struct *new_fs)
13604 + return unshare_namespaces(flags, tsk->nsproxy,
13605 + new_fs, user_ns, task_active_pid_ns(tsk));
13609 + * copies the nsproxy, setting refcount to 1, and grabbing a
13610 + * reference to all contained namespaces.
13612 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
13614 + struct nsproxy *ns = create_nsproxy();
13617 + memcpy(ns, orig, sizeof(struct nsproxy));
13618 + atomic_set(&ns->count, 1);
13621 + get_mnt_ns(ns->mnt_ns);
13623 + get_uts_ns(ns->uts_ns);
13625 + get_ipc_ns(ns->ipc_ns);
13626 + if (ns->pid_ns_for_children)
13627 + get_pid_ns(ns->pid_ns_for_children);
13629 + get_net(ns->net_ns);
13635 * called from clone. This now handles copy for nsproxy and all
13636 * namespaces therein.
13637 @@ -125,7 +168,10 @@ int copy_namespaces(unsigned long flags,
13639 struct nsproxy *old_ns = tsk->nsproxy;
13640 struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
13641 - struct nsproxy *new_ns;
13642 + struct nsproxy *new_ns = NULL;
13644 + vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
13645 + flags, tsk, old_ns);
13647 if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13648 CLONE_NEWPID | CLONE_NEWNET)))) {
13649 @@ -133,7 +179,7 @@ int copy_namespaces(unsigned long flags,
13653 - if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13654 + if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags))
13658 @@ -152,6 +198,9 @@ int copy_namespaces(unsigned long flags,
13659 return PTR_ERR(new_ns);
13661 tsk->nsproxy = new_ns;
13662 + vxdprintk(VXD_CBIT(space, 3),
13663 + "copy_namespaces(0x%08lx,%p[%p]) = [%p]",
13664 + flags, tsk, old_ns, new_ns);
13668 @@ -165,7 +214,9 @@ void free_nsproxy(struct nsproxy *ns)
13669 put_ipc_ns(ns->ipc_ns);
13670 if (ns->pid_ns_for_children)
13671 put_pid_ns(ns->pid_ns_for_children);
13672 - put_net(ns->net_ns);
13674 + put_net(ns->net_ns);
13675 + atomic_dec(&vs_global_nsproxy);
13676 kmem_cache_free(nsproxy_cachep, ns);
13679 @@ -179,12 +230,16 @@ int unshare_nsproxy_namespaces(unsigned
13680 struct user_namespace *user_ns;
13683 + vxdprintk(VXD_CBIT(space, 4),
13684 + "unshare_nsproxy_namespaces(0x%08lx,[%p])",
13685 + unshare_flags, current->nsproxy);
13687 if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13688 CLONE_NEWNET | CLONE_NEWPID)))
13691 user_ns = new_cred ? new_cred->user_ns : current_user_ns();
13692 - if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13693 + if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
13696 *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
13697 diff -NurpP --minimal linux-3.13.10/kernel/pid.c linux-3.13.10-vs2.3.6.11/kernel/pid.c
13698 --- linux-3.13.10/kernel/pid.c 2013-11-25 15:47:03.000000000 +0000
13699 +++ linux-3.13.10-vs2.3.6.11/kernel/pid.c 2014-01-31 20:38:03.000000000 +0000
13701 #include <linux/syscalls.h>
13702 #include <linux/proc_ns.h>
13703 #include <linux/proc_fs.h>
13704 +#include <linux/vs_pid.h>
13706 #define pid_hashfn(nr, ns) \
13707 hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
13708 @@ -373,7 +374,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
13710 struct pid *find_vpid(int nr)
13712 - return find_pid_ns(nr, task_active_pid_ns(current));
13713 + return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
13715 EXPORT_SYMBOL_GPL(find_vpid);
13717 @@ -429,6 +430,9 @@ void transfer_pid(struct task_struct *ol
13718 struct task_struct *pid_task(struct pid *pid, enum pid_type type)
13720 struct task_struct *result = NULL;
13722 + if (type == PIDTYPE_REALPID)
13723 + type = PIDTYPE_PID;
13725 struct hlist_node *first;
13726 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
13727 @@ -448,7 +452,7 @@ struct task_struct *find_task_by_pid_ns(
13728 rcu_lockdep_assert(rcu_read_lock_held(),
13729 "find_task_by_pid_ns() needs rcu_read_lock()"
13731 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
13732 + return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
13735 struct task_struct *find_task_by_vpid(pid_t vnr)
13736 @@ -492,7 +496,7 @@ struct pid *find_get_pid(pid_t nr)
13738 EXPORT_SYMBOL_GPL(find_get_pid);
13740 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13741 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
13745 @@ -506,6 +510,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
13747 EXPORT_SYMBOL_GPL(pid_nr_ns);
13749 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13751 + return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
13754 pid_t pid_vnr(struct pid *pid)
13756 return pid_nr_ns(pid, task_active_pid_ns(current));
13757 diff -NurpP --minimal linux-3.13.10/kernel/pid_namespace.c linux-3.13.10-vs2.3.6.11/kernel/pid_namespace.c
13758 --- linux-3.13.10/kernel/pid_namespace.c 2014-01-22 20:39:13.000000000 +0000
13759 +++ linux-3.13.10-vs2.3.6.11/kernel/pid_namespace.c 2014-02-01 12:23:11.000000000 +0000
13761 #include <linux/proc_ns.h>
13762 #include <linux/reboot.h>
13763 #include <linux/export.h>
13764 +#include <linux/vserver/global.h>
13768 @@ -110,6 +111,7 @@ static struct pid_namespace *create_pid_
13771 kref_init(&ns->kref);
13772 + atomic_inc(&vs_global_pid_ns);
13774 ns->parent = get_pid_ns(parent_pid_ns);
13775 ns->user_ns = get_user_ns(user_ns);
13776 @@ -127,6 +129,7 @@ static struct pid_namespace *create_pid_
13778 kfree(ns->pidmap[0].page);
13780 + atomic_dec(&vs_global_pid_ns);
13781 kmem_cache_free(pid_ns_cachep, ns);
13783 return ERR_PTR(err);
13784 diff -NurpP --minimal linux-3.13.10/kernel/posix-timers.c linux-3.13.10-vs2.3.6.11/kernel/posix-timers.c
13785 --- linux-3.13.10/kernel/posix-timers.c 2013-07-14 17:01:35.000000000 +0000
13786 +++ linux-3.13.10-vs2.3.6.11/kernel/posix-timers.c 2014-01-31 20:38:03.000000000 +0000
13788 #include <linux/workqueue.h>
13789 #include <linux/export.h>
13790 #include <linux/hashtable.h>
13791 +#include <linux/vs_context.h>
13794 * Management arrays for POSIX timers. Timers are now kept in static hash table
13795 @@ -398,6 +399,7 @@ int posix_timer_event(struct k_itimer *t
13797 struct task_struct *task;
13798 int shared, ret = -1;
13801 * FIXME: if ->sigq is queued we can race with
13802 * dequeue_signal()->do_schedule_next_timer().
13803 @@ -414,10 +416,18 @@ int posix_timer_event(struct k_itimer *t
13805 task = pid_task(timr->it_pid, PIDTYPE_PID);
13807 + struct vx_info_save vxis;
13808 + struct vx_info *vxi;
13810 + vxi = get_vx_info(task->vx_info);
13811 + enter_vx_info(vxi, &vxis);
13812 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
13813 ret = send_sigqueue(timr->sigq, task, shared);
13814 + leave_vx_info(&vxis);
13815 + put_vx_info(vxi);
13819 /* If we failed to send the signal the timer stops. */
13822 diff -NurpP --minimal linux-3.13.10/kernel/printk/printk.c linux-3.13.10-vs2.3.6.11/kernel/printk/printk.c
13823 --- linux-3.13.10/kernel/printk/printk.c 2014-04-17 01:12:39.000000000 +0000
13824 +++ linux-3.13.10-vs2.3.6.11/kernel/printk/printk.c 2014-04-17 01:17:11.000000000 +0000
13826 #include <linux/poll.h>
13827 #include <linux/irq_work.h>
13828 #include <linux/utsname.h>
13829 +#include <linux/vs_cvirt.h>
13831 #include <asm/uaccess.h>
13833 @@ -386,7 +387,7 @@ static int check_syslog_permissions(int
13836 if (syslog_action_restricted(type)) {
13837 - if (capable(CAP_SYSLOG))
13838 + if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
13841 * For historical reasons, accept CAP_SYS_ADMIN too, with
13842 @@ -1134,12 +1135,9 @@ int do_syslog(int type, char __user *buf
13847 - case SYSLOG_ACTION_CLOSE: /* Close log */
13849 - case SYSLOG_ACTION_OPEN: /* Open log */
13851 - case SYSLOG_ACTION_READ: /* Read from log */
13852 + if ((type == SYSLOG_ACTION_READ) ||
13853 + (type == SYSLOG_ACTION_READ_ALL) ||
13854 + (type == SYSLOG_ACTION_READ_CLEAR)) {
13856 if (!buf || len < 0)
13858 @@ -1150,6 +1148,16 @@ int do_syslog(int type, char __user *buf
13863 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
13864 + return vx_do_syslog(type, buf, len);
13867 + case SYSLOG_ACTION_CLOSE: /* Close log */
13869 + case SYSLOG_ACTION_OPEN: /* Open log */
13871 + case SYSLOG_ACTION_READ: /* Read from log */
13872 error = wait_event_interruptible(log_wait,
13873 syslog_seq != log_next_seq);
13875 @@ -1162,16 +1170,6 @@ int do_syslog(int type, char __user *buf
13877 /* Read last kernel messages */
13878 case SYSLOG_ACTION_READ_ALL:
13880 - if (!buf || len < 0)
13885 - if (!access_ok(VERIFY_WRITE, buf, len)) {
13889 error = syslog_print_all(buf, len, clear);
13891 /* Clear ring buffer */
13892 diff -NurpP --minimal linux-3.13.10/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/kernel/ptrace.c
13893 --- linux-3.13.10/kernel/ptrace.c 2014-01-22 20:39:13.000000000 +0000
13894 +++ linux-3.13.10-vs2.3.6.11/kernel/ptrace.c 2014-01-31 20:38:03.000000000 +0000
13896 #include <linux/syscalls.h>
13897 #include <linux/uaccess.h>
13898 #include <linux/regset.h>
13899 +#include <linux/vs_context.h>
13900 #include <linux/hw_breakpoint.h>
13901 #include <linux/cn_proc.h>
13902 #include <linux/compat.h>
13903 @@ -264,6 +265,11 @@ ok:
13907 + if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
13909 + if (!vx_check(task->xid, VS_IDENT) &&
13910 + !task_vx_flags(task, VXF_STATE_ADMIN, 0))
13912 return security_ptrace_access_check(task, mode);
13915 diff -NurpP --minimal linux-3.13.10/kernel/reboot.c linux-3.13.10-vs2.3.6.11/kernel/reboot.c
13916 --- linux-3.13.10/kernel/reboot.c 2014-01-22 20:39:13.000000000 +0000
13917 +++ linux-3.13.10-vs2.3.6.11/kernel/reboot.c 2014-02-01 00:19:40.000000000 +0000
13919 #include <linux/syscalls.h>
13920 #include <linux/syscore_ops.h>
13921 #include <linux/uaccess.h>
13922 +#include <linux/vs_pid.h>
13925 * this indicates whether you can reboot with ctrl-alt-del: the default is yes
13926 @@ -188,6 +189,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
13928 static DEFINE_MUTEX(reboot_mutex);
13930 +long vs_reboot(unsigned int, void __user *);
13933 * Reboot system call: for obvious reasons only root may call it,
13934 * and even root needs to set up some magic numbers in the registers
13935 @@ -230,6 +233,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
13936 if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
13937 cmd = LINUX_REBOOT_CMD_HALT;
13939 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
13940 + return vs_reboot(cmd, arg);
13942 mutex_lock(&reboot_mutex);
13944 case LINUX_REBOOT_CMD_RESTART:
13945 diff -NurpP --minimal linux-3.13.10/kernel/sched/core.c linux-3.13.10-vs2.3.6.11/kernel/sched/core.c
13946 --- linux-3.13.10/kernel/sched/core.c 2014-04-17 01:12:39.000000000 +0000
13947 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/core.c 2014-02-25 11:26:10.000000000 +0000
13949 #include <linux/init_task.h>
13950 #include <linux/binfmts.h>
13951 #include <linux/context_tracking.h>
13952 +#include <linux/vs_sched.h>
13953 +#include <linux/vs_cvirt.h>
13955 #include <asm/switch_to.h>
13956 #include <asm/tlb.h>
13957 @@ -2927,7 +2929,7 @@ SYSCALL_DEFINE1(nice, int, increment)
13960 if (increment < 0 && !can_nice(current, nice))
13962 + return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
13964 retval = security_task_setnice(current, nice);
13966 diff -NurpP --minimal linux-3.13.10/kernel/sched/cputime.c linux-3.13.10-vs2.3.6.11/kernel/sched/cputime.c
13967 --- linux-3.13.10/kernel/sched/cputime.c 2013-11-25 15:47:03.000000000 +0000
13968 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/cputime.c 2014-01-31 20:38:03.000000000 +0000
13970 #include <linux/kernel_stat.h>
13971 #include <linux/static_key.h>
13972 #include <linux/context_tracking.h>
13973 +#include <linux/vs_sched.h>
13977 @@ -135,14 +136,17 @@ static inline void task_group_account_fi
13978 void account_user_time(struct task_struct *p, cputime_t cputime,
13979 cputime_t cputime_scaled)
13981 + struct vx_info *vxi = p->vx_info; /* p is _always_ current */
13982 + int nice = (TASK_NICE(p) > 0);
13985 /* Add user time to process. */
13986 p->utime += cputime;
13987 p->utimescaled += cputime_scaled;
13988 + vx_account_user(vxi, cputime, nice);
13989 account_group_user_time(p, cputime);
13991 - index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
13992 + index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
13994 /* Add user time to cpustat. */
13995 task_group_account_field(p, index, (__force u64) cputime);
13996 @@ -189,9 +193,12 @@ static inline
13997 void __account_system_time(struct task_struct *p, cputime_t cputime,
13998 cputime_t cputime_scaled, int index)
14000 + struct vx_info *vxi = p->vx_info; /* p is _always_ current */
14002 /* Add system time to process. */
14003 p->stime += cputime;
14004 p->stimescaled += cputime_scaled;
14005 + vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14006 account_group_system_time(p, cputime);
14008 /* Add system time to cpustat. */
14009 diff -NurpP --minimal linux-3.13.10/kernel/sched/fair.c linux-3.13.10-vs2.3.6.11/kernel/sched/fair.c
14010 --- linux-3.13.10/kernel/sched/fair.c 2014-04-17 01:12:40.000000000 +0000
14011 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/fair.c 2014-04-17 01:17:11.000000000 +0000
14013 #include <linux/mempolicy.h>
14014 #include <linux/migrate.h>
14015 #include <linux/task_work.h>
14016 +#include <linux/vs_cvirt.h>
14018 #include <trace/events/sched.h>
14020 @@ -2577,6 +2578,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14021 __enqueue_entity(cfs_rq, se);
14024 + if (entity_is_task(se))
14025 + vx_activate_task(task_of(se));
14026 if (cfs_rq->nr_running == 1) {
14027 list_add_leaf_cfs_rq(cfs_rq);
14028 check_enqueue_throttle(cfs_rq);
14029 @@ -2658,6 +2661,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14030 if (se != cfs_rq->curr)
14031 __dequeue_entity(cfs_rq, se);
14033 + if (entity_is_task(se))
14034 + vx_deactivate_task(task_of(se));
14035 account_entity_dequeue(cfs_rq, se);
14038 diff -NurpP --minimal linux-3.13.10/kernel/sched/proc.c linux-3.13.10-vs2.3.6.11/kernel/sched/proc.c
14039 --- linux-3.13.10/kernel/sched/proc.c 2013-11-25 15:45:08.000000000 +0000
14040 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/proc.c 2014-01-31 21:22:36.000000000 +0000
14041 @@ -78,9 +78,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14043 void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14045 - loads[0] = (avenrun[0] + offset) << shift;
14046 - loads[1] = (avenrun[1] + offset) << shift;
14047 - loads[2] = (avenrun[2] + offset) << shift;
14048 + if (vx_flags(VXF_VIRT_LOAD, 0)) {
14049 + struct vx_info *vxi = current_vx_info();
14051 + loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14052 + loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14053 + loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14055 + loads[0] = (avenrun[0] + offset) << shift;
14056 + loads[1] = (avenrun[1] + offset) << shift;
14057 + loads[2] = (avenrun[2] + offset) << shift;
14061 long calc_load_fold_active(struct rq *this_rq)
14062 diff -NurpP --minimal linux-3.13.10/kernel/signal.c linux-3.13.10-vs2.3.6.11/kernel/signal.c
14063 --- linux-3.13.10/kernel/signal.c 2014-01-22 20:39:13.000000000 +0000
14064 +++ linux-3.13.10-vs2.3.6.11/kernel/signal.c 2014-01-31 20:38:03.000000000 +0000
14066 #include <linux/uprobes.h>
14067 #include <linux/compat.h>
14068 #include <linux/cn_proc.h>
14069 +#include <linux/vs_context.h>
14070 +#include <linux/vs_pid.h>
14071 #define CREATE_TRACE_POINTS
14072 #include <trace/events/signal.h>
14074 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14078 + vxdprintk(VXD_CBIT(misc, 7),
14079 + "check_kill_permission(%d,%p,%p[#%u,%u])",
14080 + sig, info, t, vx_task_xid(t), t->pid);
14082 if (!valid_signal(sig))
14085 +/* FIXME: needed? if so, why?
14086 + if ((info != SEND_SIG_NOINFO) &&
14087 + (is_si_special(info) || !si_fromuser(info)))
14090 if (!si_fromuser(info))
14093 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14098 + if (t->pid == 1 && current->xid)
14102 + /* FIXME: we shouldn't return ESRCH ever, to avoid
14103 + loops, maybe ENOENT or EACCES? */
14104 + if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14105 + vxdprintk(current->xid || VXD_CBIT(misc, 7),
14106 + "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14107 + sig, info, t, vx_task_xid(t), t->pid, current->xid);
14111 return security_task_kill(t, info, sig, 0);
14114 @@ -1353,7 +1378,7 @@ int kill_pid_info(int sig, struct siginf
14117 p = pid_task(pid, PIDTYPE_PID);
14119 + if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14120 error = group_send_sig_info(sig, info, p);
14121 if (unlikely(error == -ESRCH))
14123 @@ -1401,7 +1426,7 @@ int kill_pid_info_as_cred(int sig, struc
14126 p = pid_task(pid, PIDTYPE_PID);
14128 + if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14132 @@ -1453,8 +1478,10 @@ static int kill_something_info(int sig,
14133 struct task_struct * p;
14135 for_each_process(p) {
14136 - if (task_pid_vnr(p) > 1 &&
14137 - !same_thread_group(p, current)) {
14138 + if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14139 + task_pid_vnr(p) > 1 &&
14140 + !same_thread_group(p, current) &&
14141 + !vx_current_initpid(p->pid)) {
14142 int err = group_send_sig_info(sig, info, p);
14145 @@ -2308,6 +2335,11 @@ relock:
14146 !sig_kernel_only(signr))
14149 + /* virtual init is protected against user signals */
14150 + if ((info->si_code == SI_USER) &&
14151 + vx_current_initpid(current->pid))
14154 if (sig_kernel_stop(signr)) {
14156 * The default action is to stop all threads in
14157 diff -NurpP --minimal linux-3.13.10/kernel/softirq.c linux-3.13.10-vs2.3.6.11/kernel/softirq.c
14158 --- linux-3.13.10/kernel/softirq.c 2014-01-22 20:39:13.000000000 +0000
14159 +++ linux-3.13.10-vs2.3.6.11/kernel/softirq.c 2014-01-31 20:38:03.000000000 +0000
14161 #include <linux/smp.h>
14162 #include <linux/smpboot.h>
14163 #include <linux/tick.h>
14164 +#include <linux/vs_context.h>
14166 #define CREATE_TRACE_POINTS
14167 #include <trace/events/irq.h>
14168 diff -NurpP --minimal linux-3.13.10/kernel/sys.c linux-3.13.10-vs2.3.6.11/kernel/sys.c
14169 --- linux-3.13.10/kernel/sys.c 2014-01-22 20:39:13.000000000 +0000
14170 +++ linux-3.13.10-vs2.3.6.11/kernel/sys.c 2014-02-01 00:19:29.000000000 +0000
14172 #include <linux/cred.h>
14174 #include <linux/kmsg_dump.h>
14175 +#include <linux/vs_pid.h>
14176 /* Move somewhere else to avoid recompiling? */
14177 #include <generated/utsrelease.h>
14179 @@ -145,7 +146,10 @@ static int set_one_prio(struct task_stru
14182 if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14184 + if (vx_flags(VXF_IGNEG_NICE, 0))
14190 no_nice = security_task_setnice(p, niceval);
14191 @@ -196,6 +200,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14193 pgrp = task_pgrp(current);
14194 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14195 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14197 error = set_one_prio(p, niceval, error);
14198 } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14200 @@ -261,6 +267,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14202 pgrp = task_pgrp(current);
14203 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14204 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14206 niceval = 20 - task_nice(p);
14207 if (niceval > retval)
14209 @@ -1198,7 +1206,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14211 char tmp[__NEW_UTS_LEN];
14213 - if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14214 + if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14215 + CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14218 if (len < 0 || len > __NEW_UTS_LEN)
14219 @@ -1249,7 +1258,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14221 char tmp[__NEW_UTS_LEN];
14223 - if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14224 + if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14225 + CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14227 if (len < 0 || len > __NEW_UTS_LEN)
14229 @@ -1368,7 +1378,7 @@ int do_prlimit(struct task_struct *tsk,
14230 /* Keep the capable check against init_user_ns until
14231 cgroups can contain all limits */
14232 if (new_rlim->rlim_max > rlim->rlim_max &&
14233 - !capable(CAP_SYS_RESOURCE))
14234 + !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14237 retval = security_task_setrlimit(tsk->group_leader,
14238 @@ -1421,7 +1431,8 @@ static int check_prlimit_permission(stru
14239 gid_eq(cred->gid, tcred->sgid) &&
14240 gid_eq(cred->gid, tcred->gid))
14242 - if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14243 + if (vx_ns_capable(tcred->user_ns,
14244 + CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14248 diff -NurpP --minimal linux-3.13.10/kernel/sysctl.c linux-3.13.10-vs2.3.6.11/kernel/sysctl.c
14249 --- linux-3.13.10/kernel/sysctl.c 2014-04-17 01:12:40.000000000 +0000
14250 +++ linux-3.13.10-vs2.3.6.11/kernel/sysctl.c 2014-02-25 11:26:10.000000000 +0000
14252 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14253 #include <linux/lockdep.h>
14255 +extern char vshelper_path[];
14256 #ifdef CONFIG_CHR_DEV_SG
14257 #include <scsi/sg.h>
14259 @@ -650,6 +651,13 @@ static struct ctl_table kern_table[] = {
14261 .proc_handler = proc_dostring,
14264 + .procname = "vshelper",
14265 + .data = &vshelper_path,
14268 + .proc_handler = &proc_dostring,
14271 #ifdef CONFIG_CHR_DEV_SG
14273 diff -NurpP --minimal linux-3.13.10/kernel/sysctl_binary.c linux-3.13.10-vs2.3.6.11/kernel/sysctl_binary.c
14274 --- linux-3.13.10/kernel/sysctl_binary.c 2014-01-22 20:39:13.000000000 +0000
14275 +++ linux-3.13.10-vs2.3.6.11/kernel/sysctl_binary.c 2014-01-31 20:38:03.000000000 +0000
14276 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
14278 { CTL_INT, KERN_PANIC, "panic" },
14279 { CTL_INT, KERN_REALROOTDEV, "real-root-dev" },
14280 + { CTL_STR, KERN_VSHELPER, "vshelper" },
14282 { CTL_STR, KERN_SPARC_REBOOT, "reboot-cmd" },
14283 { CTL_INT, KERN_CTLALTDEL, "ctrl-alt-del" },
14284 diff -NurpP --minimal linux-3.13.10/kernel/time/timekeeping.c linux-3.13.10-vs2.3.6.11/kernel/time/timekeeping.c
14285 --- linux-3.13.10/kernel/time/timekeeping.c 2014-04-17 01:12:40.000000000 +0000
14286 +++ linux-3.13.10-vs2.3.6.11/kernel/time/timekeeping.c 2014-02-25 11:26:10.000000000 +0000
14288 #include <linux/tick.h>
14289 #include <linux/stop_machine.h>
14290 #include <linux/pvclock_gtod.h>
14291 +#include <linux/vs_time.h>
14293 #include "tick-internal.h"
14294 #include "ntp_internal.h"
14295 @@ -709,6 +710,7 @@ void getrawmonotonic(struct timespec *ts
14296 } while (read_seqcount_retry(&timekeeper_seq, seq));
14298 timespec_add_ns(ts, nsecs);
14299 + vx_adjust_timespec(ts);
14301 EXPORT_SYMBOL(getrawmonotonic);
14303 diff -NurpP --minimal linux-3.13.10/kernel/time.c linux-3.13.10-vs2.3.6.11/kernel/time.c
14304 --- linux-3.13.10/kernel/time.c 2013-11-25 15:45:08.000000000 +0000
14305 +++ linux-3.13.10-vs2.3.6.11/kernel/time.c 2014-01-31 20:38:03.000000000 +0000
14307 #include <linux/fs.h>
14308 #include <linux/math64.h>
14309 #include <linux/ptrace.h>
14310 +#include <linux/vs_time.h>
14312 #include <asm/uaccess.h>
14313 #include <asm/unistd.h>
14314 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
14318 - do_settimeofday(&tv);
14319 + vx_settimeofday(&tv);
14323 @@ -181,7 +182,7 @@ int do_sys_settimeofday(const struct tim
14327 - return do_settimeofday(tv);
14328 + return vx_settimeofday(tv);
14332 diff -NurpP --minimal linux-3.13.10/kernel/timer.c linux-3.13.10-vs2.3.6.11/kernel/timer.c
14333 --- linux-3.13.10/kernel/timer.c 2014-01-22 20:39:13.000000000 +0000
14334 +++ linux-3.13.10-vs2.3.6.11/kernel/timer.c 2014-01-31 20:38:03.000000000 +0000
14336 #include <linux/sched/sysctl.h>
14337 #include <linux/slab.h>
14338 #include <linux/compat.h>
14339 +#include <linux/vs_base.h>
14340 +#include <linux/vs_cvirt.h>
14341 +#include <linux/vs_pid.h>
14342 +#include <linux/vserver/sched.h>
14344 #include <asm/uaccess.h>
14345 #include <asm/unistd.h>
14346 diff -NurpP --minimal linux-3.13.10/kernel/user_namespace.c linux-3.13.10-vs2.3.6.11/kernel/user_namespace.c
14347 --- linux-3.13.10/kernel/user_namespace.c 2014-01-22 20:39:13.000000000 +0000
14348 +++ linux-3.13.10-vs2.3.6.11/kernel/user_namespace.c 2014-01-31 20:38:03.000000000 +0000
14350 #include <linux/ctype.h>
14351 #include <linux/projid.h>
14352 #include <linux/fs_struct.h>
14353 +#include <linux/vserver/global.h>
14355 static struct kmem_cache *user_ns_cachep __read_mostly;
14357 @@ -94,6 +95,7 @@ int create_user_ns(struct cred *new)
14359 atomic_set(&ns->count, 1);
14360 /* Leave the new->user_ns reference with the new user namespace. */
14361 + atomic_inc(&vs_global_user_ns);
14362 ns->parent = parent_ns;
14363 ns->level = parent_ns->level + 1;
14365 @@ -848,6 +850,8 @@ static void *userns_get(struct task_stru
14367 static void userns_put(void *ns)
14369 + /* FIXME: maybe move into destroyer? */
14370 + atomic_dec(&vs_global_user_ns);
14374 diff -NurpP --minimal linux-3.13.10/kernel/utsname.c linux-3.13.10-vs2.3.6.11/kernel/utsname.c
14375 --- linux-3.13.10/kernel/utsname.c 2013-11-25 15:47:03.000000000 +0000
14376 +++ linux-3.13.10-vs2.3.6.11/kernel/utsname.c 2014-01-31 20:38:03.000000000 +0000
14377 @@ -16,14 +16,17 @@
14378 #include <linux/slab.h>
14379 #include <linux/user_namespace.h>
14380 #include <linux/proc_ns.h>
14381 +#include <linux/vserver/global.h>
14383 static struct uts_namespace *create_uts_ns(void)
14385 struct uts_namespace *uts_ns;
14387 uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
14390 kref_init(&uts_ns->kref);
14391 + atomic_inc(&vs_global_uts_ns);
14396 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
14397 ns = container_of(kref, struct uts_namespace, kref);
14398 put_user_ns(ns->user_ns);
14399 proc_free_inum(ns->proc_inum);
14400 + atomic_dec(&vs_global_uts_ns);
14404 diff -NurpP --minimal linux-3.13.10/kernel/vserver/Kconfig linux-3.13.10-vs2.3.6.11/kernel/vserver/Kconfig
14405 --- linux-3.13.10/kernel/vserver/Kconfig 1970-01-01 00:00:00.000000000 +0000
14406 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/Kconfig 2014-01-31 20:38:03.000000000 +0000
14409 +# Linux VServer configuration
14412 +menu "Linux VServer"
14414 +config VSERVER_AUTO_LBACK
14415 + bool "Automatically Assign Loopback IP"
14418 + Automatically assign a guest specific loopback
14419 + IP and add it to the kernel network stack on
14422 +config VSERVER_AUTO_SINGLE
14423 + bool "Automatic Single IP Special Casing"
14426 + This allows network contexts with a single IP to
14427 + automatically remap 0.0.0.0 bindings to that IP,
14428 + avoiding further network checks and improving
14431 + (note: such guests do not allow to change the ip
14432 + on the fly and do not show loopback addresses)
14434 +config VSERVER_COWBL
14435 + bool "Enable COW Immutable Link Breaking"
14438 + This enables the COW (Copy-On-Write) link break code.
14439 + It allows you to treat unified files like normal files
14440 + when writing to them (which will implicitely break the
14441 + link and create a copy of the unified file)
14443 +config VSERVER_VTIME
14444 + bool "Enable Virtualized Guest Time (EXPERIMENTAL)"
14447 + This enables per guest time offsets to allow for
14448 + adjusting the system clock individually per guest.
14449 + this adds some overhead to the time functions and
14450 + therefore should not be enabled without good reason.
14452 +config VSERVER_DEVICE
14453 + bool "Enable Guest Device Mapping (EXPERIMENTAL)"
14456 + This enables generic device remapping.
14458 +config VSERVER_PROC_SECURE
14459 + bool "Enable Proc Security"
14460 + depends on PROC_FS
14463 + This configures ProcFS security to initially hide
14464 + non-process entries for all contexts except the main and
14465 + spectator context (i.e. for all guests), which is a secure
14468 + (note: on 1.2x the entries were visible by default)
14471 + prompt "Persistent Inode Tagging"
14472 + default TAGGING_ID24
14474 + This adds persistent context information to filesystems
14475 + mounted with the tagxid option. Tagging is a requirement
14476 + for per-context disk limits and per-context quota.
14479 +config TAGGING_NONE
14482 + do not store per-context information in inodes.
14484 +config TAGGING_UID16
14485 + bool "UID16/GID32"
14487 + reduces UID to 16 bit, but leaves GID at 32 bit.
14489 +config TAGGING_GID16
14490 + bool "UID32/GID16"
14492 + reduces GID to 16 bit, but leaves UID at 32 bit.
14494 +config TAGGING_ID24
14495 + bool "UID24/GID24"
14497 + uses the upper 8bit from UID and GID for XID tagging
14498 + which leaves 24bit for UID/GID each, which should be
14499 + more than sufficient for normal use.
14501 +config TAGGING_INTERN
14502 + bool "UID32/GID32"
14504 + this uses otherwise reserved inode fields in the on
14505 + disk representation, which limits the use to a few
14506 + filesystems (currently ext2 and ext3)
14511 + bool "Tag NFSD User Auth and Files"
14514 + Enable this if you do want the in-kernel NFS
14515 + Server to use the tagging specified above.
14516 + (will require patched clients too)
14518 +config VSERVER_PRIVACY
14519 + bool "Honor Privacy Aspects of Guests"
14522 + When enabled, most context checks will disallow
14523 + access to structures assigned to a specific context,
14524 + like ptys or loop devices.
14526 +config VSERVER_CONTEXTS
14527 + int "Maximum number of Contexts (1-65533)" if EMBEDDED
14529 + default "768" if 64BIT
14532 + This setting will optimize certain data structures
14533 + and memory allocations according to the expected
14536 + note: this is not a strict upper limit.
14538 +config VSERVER_WARN
14539 + bool "VServer Warnings"
14542 + This enables various runtime warnings, which will
14543 + notify about potential manipulation attempts or
14544 + resource shortage. It is generally considered to
14545 + be a good idea to have that enabled.
14547 +config VSERVER_WARN_DEVPTS
14548 + bool "VServer DevPTS Warnings"
14549 + depends on VSERVER_WARN
14552 + This enables DevPTS related warnings, issued when a
14553 + process inside a context tries to lookup or access
14554 + a dynamic pts from the host or a different context.
14556 +config VSERVER_DEBUG
14557 + bool "VServer Debugging Code"
14560 + Set this to yes if you want to be able to activate
14561 + debugging output at runtime. It adds a very small
14562 + overhead to all vserver related functions and
14563 + increases the kernel size by about 20k.
14565 +config VSERVER_HISTORY
14566 + bool "VServer History Tracing"
14567 + depends on VSERVER_DEBUG
14570 + Set this to yes if you want to record the history of
14571 + linux-vserver activities, so they can be replayed in
14572 + the event of a kernel panic or oops.
14574 +config VSERVER_HISTORY_SIZE
14575 + int "Per-CPU History Size (32-65536)"
14576 + depends on VSERVER_HISTORY
14580 + This allows you to specify the number of entries in
14581 + the per-CPU history buffer.
14583 +config VSERVER_EXTRA_MNT_CHECK
14584 + bool "Extra Checks for Reachability"
14587 + Set this to yes if you want to do extra checks for
14588 + vfsmount reachability in the proc filesystem code.
14589 + This shouldn't be required on any setup utilizing
14593 + prompt "Quotes used in debug and warn messages"
14594 + default QUOTES_ISO8859
14596 +config QUOTES_ISO8859
14597 + bool "Extended ASCII (ISO 8859) angle quotes"
14599 + This uses the extended ASCII characters \xbb
14600 + and \xab for quoting file and process names.
14602 +config QUOTES_UTF8
14603 + bool "UTF-8 angle quotes"
14605 + This uses the the UTF-8 sequences for angle
14606 + quotes to quote file and process names.
14608 +config QUOTES_ASCII
14609 + bool "ASCII single quotes"
14611 + This uses the ASCII single quote character
14612 + (\x27) to quote file and process names.
14622 + select NAMESPACES
14628 +config VSERVER_SECURITY
14630 + depends on SECURITY
14632 + select SECURITY_CAPABILITIES
14634 +config VSERVER_DISABLED
14638 diff -NurpP --minimal linux-3.13.10/kernel/vserver/Makefile linux-3.13.10-vs2.3.6.11/kernel/vserver/Makefile
14639 --- linux-3.13.10/kernel/vserver/Makefile 1970-01-01 00:00:00.000000000 +0000
14640 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/Makefile 2014-01-31 20:38:03.000000000 +0000
14643 +# Makefile for the Linux vserver routines.
14647 +obj-y += vserver.o
14649 +vserver-y := switch.o context.o space.o sched.o network.o inode.o \
14650 + limit.o cvirt.o cacct.o signal.o helper.o init.o \
14653 +vserver-$(CONFIG_INET) += inet.o
14654 +vserver-$(CONFIG_PROC_FS) += proc.o
14655 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
14656 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
14657 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
14658 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
14660 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cacct.c linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct.c
14661 --- linux-3.13.10/kernel/vserver/cacct.c 1970-01-01 00:00:00.000000000 +0000
14662 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct.c 2014-01-31 20:38:03.000000000 +0000
14665 + * linux/kernel/vserver/cacct.c
14667 + * Virtual Server: Context Accounting
14669 + * Copyright (C) 2006-2007 Herbert Pötzl
14671 + * V0.01 added accounting stats
14675 +#include <linux/types.h>
14676 +#include <linux/vs_context.h>
14677 +#include <linux/vserver/cacct_cmd.h>
14678 +#include <linux/vserver/cacct_int.h>
14680 +#include <asm/errno.h>
14681 +#include <asm/uaccess.h>
14684 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
14686 + struct vcmd_sock_stat_v0 vc_data;
14689 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
14692 + field = vc_data.field;
14693 + if ((field < 0) || (field >= VXA_SOCK_SIZE))
14696 + for (j = 0; j < 3; j++) {
14697 + vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
14698 + vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
14701 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
14706 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cacct_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_init.h
14707 --- linux-3.13.10/kernel/vserver/cacct_init.h 1970-01-01 00:00:00.000000000 +0000
14708 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_init.h 2014-01-31 20:38:03.000000000 +0000
14712 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
14717 + for (i = 0; i < VXA_SOCK_SIZE; i++) {
14718 + for (j = 0; j < 3; j++) {
14719 + atomic_long_set(&cacct->sock[i][j].count, 0);
14720 + atomic_long_set(&cacct->sock[i][j].total, 0);
14723 + for (i = 0; i < 8; i++)
14724 + atomic_set(&cacct->slab[i], 0);
14725 + for (i = 0; i < 5; i++)
14726 + for (j = 0; j < 4; j++)
14727 + atomic_set(&cacct->page[i][j], 0);
14730 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
14735 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cacct_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_proc.h
14736 --- linux-3.13.10/kernel/vserver/cacct_proc.h 1970-01-01 00:00:00.000000000 +0000
14737 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_proc.h 2014-01-31 20:38:03.000000000 +0000
14739 +#ifndef _VX_CACCT_PROC_H
14740 +#define _VX_CACCT_PROC_H
14742 +#include <linux/vserver/cacct_int.h>
14745 +#define VX_SOCKA_TOP \
14746 + "Type\t recv #/bytes\t\t send #/bytes\t\t fail #/bytes\n"
14748 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
14750 + int i, j, length = 0;
14751 + static char *type[VXA_SOCK_SIZE] = {
14752 + "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
14755 + length += sprintf(buffer + length, VX_SOCKA_TOP);
14756 + for (i = 0; i < VXA_SOCK_SIZE; i++) {
14757 + length += sprintf(buffer + length, "%s:", type[i]);
14758 + for (j = 0; j < 3; j++) {
14759 + length += sprintf(buffer + length,
14760 + "\t%10lu/%-10lu",
14761 + vx_sock_count(cacct, i, j),
14762 + vx_sock_total(cacct, i, j));
14764 + buffer[length++] = '\n';
14767 + length += sprintf(buffer + length, "\n");
14768 + length += sprintf(buffer + length,
14769 + "slab:\t %8u %8u %8u %8u\n",
14770 + atomic_read(&cacct->slab[1]),
14771 + atomic_read(&cacct->slab[4]),
14772 + atomic_read(&cacct->slab[0]),
14773 + atomic_read(&cacct->slab[2]));
14775 + length += sprintf(buffer + length, "\n");
14776 + for (i = 0; i < 5; i++) {
14777 + length += sprintf(buffer + length,
14778 + "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
14779 + atomic_read(&cacct->page[i][0]),
14780 + atomic_read(&cacct->page[i][1]),
14781 + atomic_read(&cacct->page[i][2]),
14782 + atomic_read(&cacct->page[i][3]),
14783 + atomic_read(&cacct->page[i][4]),
14784 + atomic_read(&cacct->page[i][5]),
14785 + atomic_read(&cacct->page[i][6]),
14786 + atomic_read(&cacct->page[i][7]));
14791 +#endif /* _VX_CACCT_PROC_H */
14792 diff -NurpP --minimal linux-3.13.10/kernel/vserver/context.c linux-3.13.10-vs2.3.6.11/kernel/vserver/context.c
14793 --- linux-3.13.10/kernel/vserver/context.c 1970-01-01 00:00:00.000000000 +0000
14794 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/context.c 2014-01-31 20:38:03.000000000 +0000
14797 + * linux/kernel/vserver/context.c
14799 + * Virtual Server: Context Support
14801 + * Copyright (C) 2003-2011 Herbert Pötzl
14803 + * V0.01 context helper
14804 + * V0.02 vx_ctx_kill syscall command
14805 + * V0.03 replaced context_info calls
14806 + * V0.04 redesign of struct (de)alloc
14807 + * V0.05 rlimit basic implementation
14808 + * V0.06 task_xid and info commands
14809 + * V0.07 context flags and caps
14810 + * V0.08 switch to RCU based hash
14811 + * V0.09 revert to non RCU for now
14812 + * V0.10 and back to working RCU hash
14813 + * V0.11 and back to locking again
14814 + * V0.12 referenced context store
14815 + * V0.13 separate per cpu data
14816 + * V0.14 changed vcmds to vxi arg
14817 + * V0.15 added context stat
14818 + * V0.16 have __create claim() the vxi
14819 + * V0.17 removed older and legacy stuff
14820 + * V0.18 added user credentials
14821 + * V0.19 added warn mask
14825 +#include <linux/slab.h>
14826 +#include <linux/types.h>
14827 +#include <linux/security.h>
14828 +#include <linux/pid_namespace.h>
14829 +#include <linux/capability.h>
14831 +#include <linux/vserver/context.h>
14832 +#include <linux/vserver/network.h>
14833 +#include <linux/vserver/debug.h>
14834 +#include <linux/vserver/limit.h>
14835 +#include <linux/vserver/limit_int.h>
14836 +#include <linux/vserver/space.h>
14837 +#include <linux/init_task.h>
14838 +#include <linux/fs_struct.h>
14839 +#include <linux/cred.h>
14841 +#include <linux/vs_context.h>
14842 +#include <linux/vs_limit.h>
14843 +#include <linux/vs_pid.h>
14844 +#include <linux/vserver/context_cmd.h>
14846 +#include "cvirt_init.h"
14847 +#include "cacct_init.h"
14848 +#include "limit_init.h"
14849 +#include "sched_init.h"
14852 +atomic_t vx_global_ctotal = ATOMIC_INIT(0);
14853 +atomic_t vx_global_cactive = ATOMIC_INIT(0);
14856 +/* now inactive context structures */
14858 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
14860 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
14863 +/* __alloc_vx_info()
14865 + * allocate an initialized vx_info struct
14866 + * doesn't make it visible (hash) */
14868 +static struct vx_info *__alloc_vx_info(vxid_t xid)
14870 + struct vx_info *new = NULL;
14873 + vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
14875 + /* would this benefit from a slab cache? */
14876 + new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
14880 + memset(new, 0, sizeof(struct vx_info));
14882 + new->ptr_pc = alloc_percpu(struct _vx_info_pc);
14883 + if (!new->ptr_pc)
14886 + new->vx_id = xid;
14887 + INIT_HLIST_NODE(&new->vx_hlist);
14888 + atomic_set(&new->vx_usecnt, 0);
14889 + atomic_set(&new->vx_tasks, 0);
14890 + new->vx_parent = NULL;
14891 + new->vx_state = 0;
14892 + init_waitqueue_head(&new->vx_wait);
14894 + /* prepare reaper */
14895 + get_task_struct(init_pid_ns.child_reaper);
14896 + new->vx_reaper = init_pid_ns.child_reaper;
14897 + new->vx_badness_bias = 0;
14899 + /* rest of init goes here */
14900 + vx_info_init_limit(&new->limit);
14901 + vx_info_init_sched(&new->sched);
14902 + vx_info_init_cvirt(&new->cvirt);
14903 + vx_info_init_cacct(&new->cacct);
14905 + /* per cpu data structures */
14906 + for_each_possible_cpu(cpu) {
14907 + vx_info_init_sched_pc(
14908 + &vx_per_cpu(new, sched_pc, cpu), cpu);
14909 + vx_info_init_cvirt_pc(
14910 + &vx_per_cpu(new, cvirt_pc, cpu), cpu);
14913 + new->vx_flags = VXF_INIT_SET;
14914 + new->vx_bcaps = CAP_FULL_SET; // maybe ~CAP_SETPCAP
14915 + new->vx_ccaps = 0;
14916 + new->vx_umask = 0;
14917 + new->vx_wmask = 0;
14919 + new->reboot_cmd = 0;
14920 + new->exit_code = 0;
14922 + // preconfig spaces
14923 + for (index = 0; index < VX_SPACES; index++) {
14924 + struct _vx_space *space = &new->space[index];
14927 + spin_lock(&init_fs.lock);
14929 + spin_unlock(&init_fs.lock);
14930 + space->vx_fs = &init_fs;
14932 + /* FIXME: do we want defaults? */
14933 + // space->vx_real_cred = 0;
14934 + // space->vx_cred = 0;
14938 + vxdprintk(VXD_CBIT(xid, 0),
14939 + "alloc_vx_info(%d) = %p", xid, new);
14940 + vxh_alloc_vx_info(new);
14941 + atomic_inc(&vx_global_ctotal);
14950 +/* __dealloc_vx_info()
14952 + * final disposal of vx_info */
14954 +static void __dealloc_vx_info(struct vx_info *vxi)
14956 +#ifdef CONFIG_VSERVER_WARN
14957 + struct vx_info_save vxis;
14960 + vxdprintk(VXD_CBIT(xid, 0),
14961 + "dealloc_vx_info(%p)", vxi);
14962 + vxh_dealloc_vx_info(vxi);
14964 +#ifdef CONFIG_VSERVER_WARN
14965 + enter_vx_info(vxi, &vxis);
14966 + vx_info_exit_limit(&vxi->limit);
14967 + vx_info_exit_sched(&vxi->sched);
14968 + vx_info_exit_cvirt(&vxi->cvirt);
14969 + vx_info_exit_cacct(&vxi->cacct);
14971 + for_each_possible_cpu(cpu) {
14972 + vx_info_exit_sched_pc(
14973 + &vx_per_cpu(vxi, sched_pc, cpu), cpu);
14974 + vx_info_exit_cvirt_pc(
14975 + &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
14977 + leave_vx_info(&vxis);
14981 + vxi->vx_state |= VXS_RELEASED;
14984 + free_percpu(vxi->ptr_pc);
14987 + atomic_dec(&vx_global_ctotal);
14990 +static void __shutdown_vx_info(struct vx_info *vxi)
14992 + struct nsproxy *nsproxy;
14993 + struct fs_struct *fs;
14994 + struct cred *cred;
14999 + vxi->vx_state |= VXS_SHUTDOWN;
15000 + vs_state_change(vxi, VSC_SHUTDOWN);
15002 + for (index = 0; index < VX_SPACES; index++) {
15003 + struct _vx_space *space = &vxi->space[index];
15005 + nsproxy = xchg(&space->vx_nsproxy, NULL);
15007 + put_nsproxy(nsproxy);
15009 + fs = xchg(&space->vx_fs, NULL);
15010 + spin_lock(&fs->lock);
15011 + kill = !--fs->users;
15012 + spin_unlock(&fs->lock);
15014 + free_fs_struct(fs);
15016 + cred = (struct cred *)xchg(&space->vx_cred, NULL);
15018 + abort_creds(cred);
15022 +/* exported stuff */
15024 +void free_vx_info(struct vx_info *vxi)
15026 + unsigned long flags;
15029 + /* check for reference counts first */
15030 + BUG_ON(atomic_read(&vxi->vx_usecnt));
15031 + BUG_ON(atomic_read(&vxi->vx_tasks));
15033 + /* context must not be hashed */
15034 + BUG_ON(vx_info_state(vxi, VXS_HASHED));
15036 + /* context shutdown is mandatory */
15037 + BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15039 + /* spaces check */
15040 + for (index = 0; index < VX_SPACES; index++) {
15041 + struct _vx_space *space = &vxi->space[index];
15043 + BUG_ON(space->vx_nsproxy);
15044 + BUG_ON(space->vx_fs);
15045 + // BUG_ON(space->vx_real_cred);
15046 + // BUG_ON(space->vx_cred);
15049 + spin_lock_irqsave(&vx_info_inactive_lock, flags);
15050 + hlist_del(&vxi->vx_hlist);
15051 + spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15053 + __dealloc_vx_info(vxi);
15057 +/* hash table for vx_info hash */
15059 +#define VX_HASH_SIZE 13
15061 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15062 + { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15064 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15067 +static inline unsigned int __hashval(vxid_t xid)
15069 + return (xid % VX_HASH_SIZE);
15074 +/* __hash_vx_info()
15076 + * add the vxi to the global hash table
15077 + * requires the hash_lock to be held */
15079 +static inline void __hash_vx_info(struct vx_info *vxi)
15081 + struct hlist_head *head;
15083 + vxd_assert_lock(&vx_info_hash_lock);
15084 + vxdprintk(VXD_CBIT(xid, 4),
15085 + "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15086 + vxh_hash_vx_info(vxi);
15088 + /* context must not be hashed */
15089 + BUG_ON(vx_info_state(vxi, VXS_HASHED));
15091 + vxi->vx_state |= VXS_HASHED;
15092 + head = &vx_info_hash[__hashval(vxi->vx_id)];
15093 + hlist_add_head(&vxi->vx_hlist, head);
15094 + atomic_inc(&vx_global_cactive);
15097 +/* __unhash_vx_info()
15099 + * remove the vxi from the global hash table
15100 + * requires the hash_lock to be held */
15102 +static inline void __unhash_vx_info(struct vx_info *vxi)
15104 + unsigned long flags;
15106 + vxd_assert_lock(&vx_info_hash_lock);
15107 + vxdprintk(VXD_CBIT(xid, 4),
15108 + "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15109 + atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15110 + vxh_unhash_vx_info(vxi);
15112 + /* context must be hashed */
15113 + BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15114 + /* but without tasks */
15115 + BUG_ON(atomic_read(&vxi->vx_tasks));
15117 + vxi->vx_state &= ~VXS_HASHED;
15118 + hlist_del_init(&vxi->vx_hlist);
15119 + spin_lock_irqsave(&vx_info_inactive_lock, flags);
15120 + hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15121 + spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15122 + atomic_dec(&vx_global_cactive);
15126 +/* __lookup_vx_info()
15128 + * requires the hash_lock to be held
15129 + * doesn't increment the vx_refcnt */
15131 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
15133 + struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15134 + struct hlist_node *pos;
15135 + struct vx_info *vxi;
15137 + vxd_assert_lock(&vx_info_hash_lock);
15138 + hlist_for_each(pos, head) {
15139 + vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15141 + if (vxi->vx_id == xid)
15146 + vxdprintk(VXD_CBIT(xid, 0),
15147 + "__lookup_vx_info(#%u): %p[#%u]",
15148 + xid, vxi, vxi ? vxi->vx_id : 0);
15149 + vxh_lookup_vx_info(vxi, xid);
15154 +/* __create_vx_info()
15156 + * create the requested context
15157 + * get(), claim() and hash it */
15159 +static struct vx_info *__create_vx_info(int id)
15161 + struct vx_info *new, *vxi = NULL;
15163 + vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15165 + if (!(new = __alloc_vx_info(id)))
15166 + return ERR_PTR(-ENOMEM);
15168 + /* required to make dynamic xids unique */
15169 + spin_lock(&vx_info_hash_lock);
15171 + /* static context requested */
15172 + if ((vxi = __lookup_vx_info(id))) {
15173 + vxdprintk(VXD_CBIT(xid, 0),
15174 + "create_vx_info(%d) = %p (already there)", id, vxi);
15175 + if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15176 + vxi = ERR_PTR(-EBUSY);
15178 + vxi = ERR_PTR(-EEXIST);
15181 + /* new context */
15182 + vxdprintk(VXD_CBIT(xid, 0),
15183 + "create_vx_info(%d) = %p (new)", id, new);
15184 + claim_vx_info(new, NULL);
15185 + __hash_vx_info(get_vx_info(new));
15186 + vxi = new, new = NULL;
15189 + spin_unlock(&vx_info_hash_lock);
15190 + vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15192 + __dealloc_vx_info(new);
15197 +/* exported stuff */
15200 +void unhash_vx_info(struct vx_info *vxi)
15202 + spin_lock(&vx_info_hash_lock);
15203 + __unhash_vx_info(vxi);
15204 + spin_unlock(&vx_info_hash_lock);
15205 + __shutdown_vx_info(vxi);
15206 + __wakeup_vx_info(vxi);
15210 +/* lookup_vx_info()
15212 + * search for a vx_info and get() it
15213 + * negative id means current */
15215 +struct vx_info *lookup_vx_info(int id)
15217 + struct vx_info *vxi = NULL;
15220 + vxi = get_vx_info(current_vx_info());
15221 + } else if (id > 1) {
15222 + spin_lock(&vx_info_hash_lock);
15223 + vxi = get_vx_info(__lookup_vx_info(id));
15224 + spin_unlock(&vx_info_hash_lock);
15229 +/* xid_is_hashed()
15231 + * verify that xid is still hashed */
15233 +int xid_is_hashed(vxid_t xid)
15237 + spin_lock(&vx_info_hash_lock);
15238 + hashed = (__lookup_vx_info(xid) != NULL);
15239 + spin_unlock(&vx_info_hash_lock);
15243 +#ifdef CONFIG_PROC_FS
15247 + * get a subset of hashed xids for proc
15248 + * assumes size is at least one */
15250 +int get_xid_list(int index, unsigned int *xids, int size)
15252 + int hindex, nr_xids = 0;
15254 + /* only show current and children */
15255 + if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15258 + xids[nr_xids] = vx_current_xid();
15262 + for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15263 + struct hlist_head *head = &vx_info_hash[hindex];
15264 + struct hlist_node *pos;
15266 + spin_lock(&vx_info_hash_lock);
15267 + hlist_for_each(pos, head) {
15268 + struct vx_info *vxi;
15273 + vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15274 + xids[nr_xids] = vxi->vx_id;
15275 + if (++nr_xids >= size) {
15276 + spin_unlock(&vx_info_hash_lock);
15280 + /* keep the lock time short */
15281 + spin_unlock(&vx_info_hash_lock);
15288 +#ifdef CONFIG_VSERVER_DEBUG
15290 +void dump_vx_info_inactive(int level)
15292 + struct hlist_node *entry, *next;
15294 + hlist_for_each_safe(entry, next, &vx_info_inactive) {
15295 + struct vx_info *vxi =
15296 + list_entry(entry, struct vx_info, vx_hlist);
15298 + dump_vx_info(vxi, level);
15305 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
15307 + struct user_struct *new_user, *old_user;
15312 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
15315 + new_user = alloc_uid(vxi->vx_id, p->uid);
15319 + old_user = p->user;
15320 + if (new_user != old_user) {
15321 + atomic_inc(&new_user->processes);
15322 + atomic_dec(&old_user->processes);
15323 + p->user = new_user;
15325 + free_uid(old_user);
15331 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
15333 + // p->cap_effective &= vxi->vx_cap_bset;
15334 + p->cap_effective =
15335 + cap_intersect(p->cap_effective, vxi->cap_bset);
15336 + // p->cap_inheritable &= vxi->vx_cap_bset;
15337 + p->cap_inheritable =
15338 + cap_intersect(p->cap_inheritable, vxi->cap_bset);
15339 + // p->cap_permitted &= vxi->vx_cap_bset;
15340 + p->cap_permitted =
15341 + cap_intersect(p->cap_permitted, vxi->cap_bset);
15346 +#include <linux/file.h>
15347 +#include <linux/fdtable.h>
15349 +static int vx_openfd_task(struct task_struct *tsk)
15351 + struct files_struct *files = tsk->files;
15352 + struct fdtable *fdt;
15353 + const unsigned long *bptr;
15354 + int count, total;
15356 + /* no rcu_read_lock() because of spin_lock() */
15357 + spin_lock(&files->file_lock);
15358 + fdt = files_fdtable(files);
15359 + bptr = fdt->open_fds;
15360 + count = fdt->max_fds / (sizeof(unsigned long) * 8);
15361 + for (total = 0; count > 0; count--) {
15363 + total += hweight_long(*bptr);
15366 + spin_unlock(&files->file_lock);
15371 +/* for *space compatibility */
15373 +asmlinkage long sys_unshare(unsigned long);
15376 + * migrate task to new context
15377 + * gets vxi, puts old_vxi on change
15378 + * optionally unshares namespaces (hack)
15381 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
15383 + struct vx_info *old_vxi;
15389 + vxdprintk(VXD_CBIT(xid, 5),
15390 + "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
15391 + vxi->vx_id, atomic_read(&vxi->vx_usecnt));
15393 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
15394 + !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15397 + if (vx_info_state(vxi, VXS_SHUTDOWN))
15400 + old_vxi = task_get_vx_info(p);
15401 + if (old_vxi == vxi)
15404 +// if (!(ret = vx_migrate_user(p, vxi))) {
15409 + openfd = vx_openfd_task(p);
15412 + atomic_dec(&old_vxi->cvirt.nr_threads);
15413 + atomic_dec(&old_vxi->cvirt.nr_running);
15414 + __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
15415 + /* FIXME: what about the struct files here? */
15416 + __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
15417 + /* account for the executable */
15418 + __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
15420 + atomic_inc(&vxi->cvirt.nr_threads);
15421 + atomic_inc(&vxi->cvirt.nr_running);
15422 + __rlim_inc(&vxi->limit, RLIMIT_NPROC);
15423 + /* FIXME: what about the struct files here? */
15424 + __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
15425 + /* account for the executable */
15426 + __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
15429 + release_vx_info(old_vxi, p);
15430 + clr_vx_info(&p->vx_info);
15432 + claim_vx_info(vxi, p);
15433 + set_vx_info(&p->vx_info, vxi);
15434 + p->xid = vxi->vx_id;
15436 + vxdprintk(VXD_CBIT(xid, 5),
15437 + "moved task %p into vxi:%p[#%d]",
15438 + p, vxi, vxi->vx_id);
15440 + // vx_mask_cap_bset(vxi, p);
15443 + /* hack for *spaces to provide compatibility */
15445 + struct nsproxy *old_nsp, *new_nsp;
15447 + ret = unshare_nsproxy_namespaces(
15448 + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
15449 + &new_nsp, NULL, NULL);
15453 + old_nsp = xchg(&p->nsproxy, new_nsp);
15454 + vx_set_space(vxi,
15455 + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
15456 + put_nsproxy(old_nsp);
15460 + put_vx_info(old_vxi);
15464 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
15466 + struct task_struct *old_reaper;
15467 + struct vx_info *reaper_vxi;
15472 + vxdprintk(VXD_CBIT(xid, 6),
15473 + "vx_set_reaper(%p[#%d],%p[#%d,%d])",
15474 + vxi, vxi->vx_id, p, p->xid, p->pid);
15476 + old_reaper = vxi->vx_reaper;
15477 + if (old_reaper == p)
15480 + reaper_vxi = task_get_vx_info(p);
15481 + if (reaper_vxi && reaper_vxi != vxi) {
15483 + "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
15485 + p->comm, p->pid, p->xid, vx_current_xid());
15489 + /* set new child reaper */
15490 + get_task_struct(p);
15491 + vxi->vx_reaper = p;
15492 + put_task_struct(old_reaper);
15494 + put_vx_info(reaper_vxi);
15498 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
15503 + vxdprintk(VXD_CBIT(xid, 6),
15504 + "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
15505 + vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15507 + vxi->vx_flags &= ~VXF_STATE_INIT;
15508 + // vxi->vx_initpid = p->tgid;
15509 + vxi->vx_initpid = p->pid;
15513 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
15515 + vxdprintk(VXD_CBIT(xid, 6),
15516 + "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
15517 + vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15519 + vxi->exit_code = code;
15520 + vxi->vx_initpid = 0;
15524 +void vx_set_persistent(struct vx_info *vxi)
15526 + vxdprintk(VXD_CBIT(xid, 6),
15527 + "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
15529 + get_vx_info(vxi);
15530 + claim_vx_info(vxi, NULL);
15533 +void vx_clear_persistent(struct vx_info *vxi)
15535 + vxdprintk(VXD_CBIT(xid, 6),
15536 + "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
15538 + release_vx_info(vxi, NULL);
15539 + put_vx_info(vxi);
15542 +void vx_update_persistent(struct vx_info *vxi)
15544 + if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
15545 + vx_set_persistent(vxi);
15547 + vx_clear_persistent(vxi);
15551 +/* task must be current or locked */
15553 +void exit_vx_info(struct task_struct *p, int code)
15555 + struct vx_info *vxi = p->vx_info;
15558 + atomic_dec(&vxi->cvirt.nr_threads);
15561 + vxi->exit_code = code;
15562 + release_vx_info(vxi, p);
15566 +void exit_vx_info_early(struct task_struct *p, int code)
15568 + struct vx_info *vxi = p->vx_info;
15571 + if (vxi->vx_initpid == p->pid)
15572 + vx_exit_init(vxi, p, code);
15573 + if (vxi->vx_reaper == p)
15574 + vx_set_reaper(vxi, init_pid_ns.child_reaper);
15579 +/* vserver syscall commands below here */
15581 +/* taks xid and vx_info functions */
15583 +#include <asm/uaccess.h>
15586 +int vc_task_xid(uint32_t id)
15591 + struct task_struct *tsk;
15594 + tsk = find_task_by_real_pid(id);
15595 + xid = (tsk) ? tsk->xid : -ESRCH;
15596 + rcu_read_unlock();
15598 + xid = vx_current_xid();
15603 +int vc_vx_info(struct vx_info *vxi, void __user *data)
15605 + struct vcmd_vx_info_v0 vc_data;
15607 + vc_data.xid = vxi->vx_id;
15608 + vc_data.initpid = vxi->vx_initpid;
15610 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15616 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
15618 + struct vcmd_ctx_stat_v0 vc_data;
15620 + vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
15621 + vc_data.tasks = atomic_read(&vxi->vx_tasks);
15623 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15629 +/* context functions */
15631 +int vc_ctx_create(uint32_t xid, void __user *data)
15633 + struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
15634 + struct vx_info *new_vxi;
15637 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15640 + if ((xid > MAX_S_CONTEXT) || (xid < 2))
15643 + new_vxi = __create_vx_info(xid);
15644 + if (IS_ERR(new_vxi))
15645 + return PTR_ERR(new_vxi);
15647 + /* initial flags */
15648 + new_vxi->vx_flags = vc_data.flagword;
15651 + if (vs_state_change(new_vxi, VSC_STARTUP))
15654 + ret = vx_migrate_task(current, new_vxi, (!data));
15658 + /* return context id on success */
15659 + ret = new_vxi->vx_id;
15661 + /* get a reference for persistent contexts */
15662 + if ((vc_data.flagword & VXF_PERSISTENT))
15663 + vx_set_persistent(new_vxi);
15665 + release_vx_info(new_vxi, NULL);
15666 + put_vx_info(new_vxi);
15671 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
15673 + struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
15676 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15679 + ret = vx_migrate_task(current, vxi, 0);
15682 + if (vc_data.flagword & VXM_SET_INIT)
15683 + ret = vx_set_init(vxi, current);
15686 + if (vc_data.flagword & VXM_SET_REAPER)
15687 + ret = vx_set_reaper(vxi, current);
15692 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
15694 + struct vcmd_ctx_flags_v0 vc_data;
15696 + vc_data.flagword = vxi->vx_flags;
15698 + /* special STATE flag handling */
15699 + vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
15701 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15706 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
15708 + struct vcmd_ctx_flags_v0 vc_data;
15709 + uint64_t mask, trigger;
15711 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15714 + /* special STATE flag handling */
15715 + mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
15716 + trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
15718 + if (vxi == current_vx_info()) {
15719 + /* if (trigger & VXF_STATE_SETUP)
15720 + vx_mask_cap_bset(vxi, current); */
15721 + if (trigger & VXF_STATE_INIT) {
15724 + ret = vx_set_init(vxi, current);
15727 + ret = vx_set_reaper(vxi, current);
15733 + vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
15734 + vc_data.flagword, mask);
15735 + if (trigger & VXF_PERSISTENT)
15736 + vx_update_persistent(vxi);
15742 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
15744 + uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
15746 + // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
15750 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
15752 + kernel_cap_t c = __cap_empty_set;
15754 + c.cap[0] = v & 0xFFFFFFFF;
15755 + c.cap[1] = (v >> 32) & 0xFFFFFFFF;
15757 + // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
15762 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
15765 + *bcaps = caps_from_cap_t(vxi->vx_bcaps);
15767 + *ccaps = vxi->vx_ccaps;
15772 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
15774 + struct vcmd_ctx_caps_v1 vc_data;
15777 + ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
15780 + vc_data.cmask = ~0ULL;
15782 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15787 +static int do_set_caps(struct vx_info *vxi,
15788 + uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
15790 + uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
15793 + printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
15794 + bcaps, bmask, ccaps, cmask);
15796 + vxi->vx_bcaps = cap_t_from_caps(
15797 + vs_mask_flags(bcold, bcaps, bmask));
15798 + vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
15803 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
15805 + struct vcmd_ctx_caps_v1 vc_data;
15807 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15810 + return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
15813 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
15815 + struct vcmd_bcaps vc_data;
15818 + ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
15821 + vc_data.bmask = ~0ULL;
15823 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15828 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
15830 + struct vcmd_bcaps vc_data;
15832 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15835 + return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
15839 +int vc_get_umask(struct vx_info *vxi, void __user *data)
15841 + struct vcmd_umask vc_data;
15843 + vc_data.umask = vxi->vx_umask;
15844 + vc_data.mask = ~0ULL;
15846 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15851 +int vc_set_umask(struct vx_info *vxi, void __user *data)
15853 + struct vcmd_umask vc_data;
15855 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15858 + vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
15859 + vc_data.umask, vc_data.mask);
15864 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
15866 + struct vcmd_wmask vc_data;
15868 + vc_data.wmask = vxi->vx_wmask;
15869 + vc_data.mask = ~0ULL;
15871 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15876 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
15878 + struct vcmd_wmask vc_data;
15880 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15883 + vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
15884 + vc_data.wmask, vc_data.mask);
15889 +int vc_get_badness(struct vx_info *vxi, void __user *data)
15891 + struct vcmd_badness_v0 vc_data;
15893 + vc_data.bias = vxi->vx_badness_bias;
15895 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15900 +int vc_set_badness(struct vx_info *vxi, void __user *data)
15902 + struct vcmd_badness_v0 vc_data;
15904 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15907 + vxi->vx_badness_bias = vc_data.bias;
15911 +#include <linux/module.h>
15913 +EXPORT_SYMBOL_GPL(free_vx_info);
15915 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cvirt.c linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt.c
15916 --- linux-3.13.10/kernel/vserver/cvirt.c 1970-01-01 00:00:00.000000000 +0000
15917 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt.c 2014-01-31 20:38:04.000000000 +0000
15920 + * linux/kernel/vserver/cvirt.c
15922 + * Virtual Server: Context Virtualization
15924 + * Copyright (C) 2004-2007 Herbert Pötzl
15926 + * V0.01 broken out from limit.c
15927 + * V0.02 added utsname stuff
15928 + * V0.03 changed vcmds to vxi arg
15932 +#include <linux/types.h>
15933 +#include <linux/utsname.h>
15934 +#include <linux/vs_cvirt.h>
15935 +#include <linux/vserver/switch.h>
15936 +#include <linux/vserver/cvirt_cmd.h>
15938 +#include <asm/uaccess.h>
15941 +void vx_vsi_boottime(struct timespec *boottime)
15943 + struct vx_info *vxi = current_vx_info();
15945 + set_normalized_timespec(boottime,
15946 + boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
15947 + boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
15951 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
15953 + struct vx_info *vxi = current_vx_info();
15955 + set_normalized_timespec(uptime,
15956 + uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
15957 + uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
15960 + set_normalized_timespec(idle,
15961 + idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
15962 + idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
15966 +uint64_t vx_idle_jiffies(void)
15968 + return init_task.utime + init_task.stime;
15973 +static inline uint32_t __update_loadavg(uint32_t load,
15974 + int wsize, int delta, int n)
15976 + unsigned long long calc, prev;
15978 + /* just set it to n */
15979 + if (unlikely(delta >= wsize))
15980 + return (n << FSHIFT);
15982 + calc = delta * n;
15984 + prev = (wsize - delta);
15987 + do_div(calc, wsize);
15992 +void vx_update_load(struct vx_info *vxi)
15994 + uint32_t now, last, delta;
15995 + unsigned int nr_running, nr_uninterruptible;
15996 + unsigned int total;
15997 + unsigned long flags;
15999 + spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16002 + last = vxi->cvirt.load_last;
16003 + delta = now - last;
16005 + if (delta < 5*HZ)
16008 + nr_running = atomic_read(&vxi->cvirt.nr_running);
16009 + nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16010 + total = nr_running + nr_uninterruptible;
16012 + vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16013 + 60*HZ, delta, total);
16014 + vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16015 + 5*60*HZ, delta, total);
16016 + vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16017 + 15*60*HZ, delta, total);
16019 + vxi->cvirt.load_last = now;
16021 + atomic_inc(&vxi->cvirt.load_updates);
16022 + spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16027 + * Commands to do_syslog:
16029 + * 0 -- Close the log. Currently a NOP.
16030 + * 1 -- Open the log. Currently a NOP.
16031 + * 2 -- Read from the log.
16032 + * 3 -- Read all messages remaining in the ring buffer.
16033 + * 4 -- Read and clear all messages remaining in the ring buffer
16034 + * 5 -- Clear ring buffer.
16035 + * 6 -- Disable printk's to console
16036 + * 7 -- Enable printk's to console
16037 + * 8 -- Set level of messages printed to console
16038 + * 9 -- Return number of unread characters in the log buffer
16039 + * 10 -- Return size of the log buffer
16041 +int vx_do_syslog(int type, char __user *buf, int len)
16044 + int do_clear = 0;
16045 + struct vx_info *vxi = current_vx_info();
16046 + struct _vx_syslog *log;
16050 + log = &vxi->cvirt.syslog;
16053 + case 0: /* Close log */
16054 + case 1: /* Open log */
16056 + case 2: /* Read from log */
16057 + error = wait_event_interruptible(log->log_wait,
16058 + (log->log_start - log->log_end));
16061 + spin_lock_irq(&log->logbuf_lock);
16062 + spin_unlock_irq(&log->logbuf_lock);
16064 + case 4: /* Read/clear last kernel messages */
16066 + /* fall through */
16067 + case 3: /* Read last kernel messages */
16070 + case 5: /* Clear ring buffer */
16073 + case 6: /* Disable logging to console */
16074 + case 7: /* Enable logging to console */
16075 + case 8: /* Set level of messages printed to console */
16078 + case 9: /* Number of chars in the log buffer */
16080 + case 10: /* Size of the log buffer */
16090 +/* virtual host info names */
16092 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16094 + struct nsproxy *nsproxy;
16095 + struct uts_namespace *uts;
16097 + if (id == VHIN_CONTEXT)
16098 + return vxi->vx_name;
16100 + nsproxy = vxi->space[0].vx_nsproxy;
16104 + uts = nsproxy->uts_ns;
16109 + case VHIN_SYSNAME:
16110 + return uts->name.sysname;
16111 + case VHIN_NODENAME:
16112 + return uts->name.nodename;
16113 + case VHIN_RELEASE:
16114 + return uts->name.release;
16115 + case VHIN_VERSION:
16116 + return uts->name.version;
16117 + case VHIN_MACHINE:
16118 + return uts->name.machine;
16119 + case VHIN_DOMAINNAME:
16120 + return uts->name.domainname;
16127 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16129 + struct vcmd_vhi_name_v0 vc_data;
16132 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16135 + name = vx_vhi_name(vxi, vc_data.field);
16139 + memcpy(name, vc_data.name, 65);
16143 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16145 + struct vcmd_vhi_name_v0 vc_data;
16148 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16151 + name = vx_vhi_name(vxi, vc_data.field);
16155 + memcpy(vc_data.name, name, 65);
16156 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16162 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16164 + struct vcmd_virt_stat_v0 vc_data;
16165 + struct _vx_cvirt *cvirt = &vxi->cvirt;
16166 + struct timespec uptime;
16168 + do_posix_clock_monotonic_gettime(&uptime);
16169 + set_normalized_timespec(&uptime,
16170 + uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16171 + uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16173 + vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16174 + vc_data.uptime = timespec_to_ns(&uptime);
16175 + vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16176 + vc_data.nr_running = atomic_read(&cvirt->nr_running);
16177 + vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16178 + vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16179 + vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16180 + vc_data.load[0] = cvirt->load[0];
16181 + vc_data.load[1] = cvirt->load[1];
16182 + vc_data.load[2] = cvirt->load[2];
16184 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16190 +#ifdef CONFIG_VSERVER_VTIME
16192 +/* virtualized time base */
16194 +void vx_adjust_timespec(struct timespec *ts)
16196 + struct vx_info *vxi;
16198 + if (!vx_flags(VXF_VIRT_TIME, 0))
16201 + vxi = current_vx_info();
16202 + ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16203 + ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16205 + if (ts->tv_nsec >= NSEC_PER_SEC) {
16207 + ts->tv_nsec -= NSEC_PER_SEC;
16208 + } else if (ts->tv_nsec < 0) {
16210 + ts->tv_nsec += NSEC_PER_SEC;
16214 +int vx_settimeofday(const struct timespec *ts)
16216 + struct timespec ats, delta;
16217 + struct vx_info *vxi;
16219 + if (!vx_flags(VXF_VIRT_TIME, 0))
16220 + return do_settimeofday(ts);
16222 + getnstimeofday(&ats);
16223 + delta = timespec_sub(*ts, ats);
16225 + vxi = current_vx_info();
16226 + vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16232 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cvirt_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_init.h
16233 --- linux-3.13.10/kernel/vserver/cvirt_init.h 1970-01-01 00:00:00.000000000 +0000
16234 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_init.h 2014-01-31 20:38:04.000000000 +0000
16238 +extern uint64_t vx_idle_jiffies(void);
16240 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16242 + uint64_t idle_jiffies = vx_idle_jiffies();
16243 + uint64_t nsuptime;
16245 + do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16246 + nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16247 + * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16248 + cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16249 + cvirt->bias_ts.tv_sec = 0;
16250 + cvirt->bias_ts.tv_nsec = 0;
16252 + jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16253 + atomic_set(&cvirt->nr_threads, 0);
16254 + atomic_set(&cvirt->nr_running, 0);
16255 + atomic_set(&cvirt->nr_uninterruptible, 0);
16256 + atomic_set(&cvirt->nr_onhold, 0);
16258 + spin_lock_init(&cvirt->load_lock);
16259 + cvirt->load_last = jiffies;
16260 + atomic_set(&cvirt->load_updates, 0);
16261 + cvirt->load[0] = 0;
16262 + cvirt->load[1] = 0;
16263 + cvirt->load[2] = 0;
16264 + atomic_set(&cvirt->total_forks, 0);
16266 + spin_lock_init(&cvirt->syslog.logbuf_lock);
16267 + init_waitqueue_head(&cvirt->syslog.log_wait);
16268 + cvirt->syslog.log_start = 0;
16269 + cvirt->syslog.log_end = 0;
16270 + cvirt->syslog.con_start = 0;
16271 + cvirt->syslog.logged_chars = 0;
16275 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16277 + // cvirt_pc->cpustat = { 0 };
16280 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16282 +#ifdef CONFIG_VSERVER_WARN
16285 + vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16286 + "!!! cvirt: %p[nr_threads] = %d on exit.",
16288 + vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16289 + "!!! cvirt: %p[nr_running] = %d on exit.",
16291 + vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16292 + "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16294 + vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16295 + "!!! cvirt: %p[nr_onhold] = %d on exit.",
16301 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16306 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cvirt_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_proc.h
16307 --- linux-3.13.10/kernel/vserver/cvirt_proc.h 1970-01-01 00:00:00.000000000 +0000
16308 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_proc.h 2014-01-31 20:38:04.000000000 +0000
16310 +#ifndef _VX_CVIRT_PROC_H
16311 +#define _VX_CVIRT_PROC_H
16313 +#include <linux/nsproxy.h>
16314 +#include <linux/mnt_namespace.h>
16315 +#include <linux/ipc_namespace.h>
16316 +#include <linux/utsname.h>
16317 +#include <linux/ipc.h>
16319 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
16322 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
16324 + struct mnt_namespace *ns;
16325 + struct uts_namespace *uts;
16326 + struct ipc_namespace *ipc;
16332 + length += sprintf(buffer + length,
16333 + "NSProxy:\t%p [%p,%p,%p]\n",
16334 + nsproxy, nsproxy->mnt_ns,
16335 + nsproxy->uts_ns, nsproxy->ipc_ns);
16337 + ns = nsproxy->mnt_ns;
16341 + length += vx_info_mnt_namespace(ns, buffer + length);
16345 + uts = nsproxy->uts_ns;
16349 + length += sprintf(buffer + length,
16350 + "SysName:\t%.*s\n"
16351 + "NodeName:\t%.*s\n"
16352 + "Release:\t%.*s\n"
16353 + "Version:\t%.*s\n"
16354 + "Machine:\t%.*s\n"
16355 + "DomainName:\t%.*s\n",
16356 + __NEW_UTS_LEN, uts->name.sysname,
16357 + __NEW_UTS_LEN, uts->name.nodename,
16358 + __NEW_UTS_LEN, uts->name.release,
16359 + __NEW_UTS_LEN, uts->name.version,
16360 + __NEW_UTS_LEN, uts->name.machine,
16361 + __NEW_UTS_LEN, uts->name.domainname);
16364 + ipc = nsproxy->ipc_ns;
16368 + length += sprintf(buffer + length,
16369 + "SEMS:\t\t%d %d %d %d %d\n"
16370 + "MSG:\t\t%d %d %d\n"
16371 + "SHM:\t\t%lu %lu %d %ld\n",
16372 + ipc->sem_ctls[0], ipc->sem_ctls[1],
16373 + ipc->sem_ctls[2], ipc->sem_ctls[3],
16375 + ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
16376 + (unsigned long)ipc->shm_ctlmax,
16377 + (unsigned long)ipc->shm_ctlall,
16378 + ipc->shm_ctlmni, ipc->shm_tot);
16385 +#include <linux/sched.h>
16387 +#define LOAD_INT(x) ((x) >> FSHIFT)
16388 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
16391 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
16396 + length += sprintf(buffer + length,
16397 + "BiasUptime:\t%lu.%02lu\n",
16398 + (unsigned long)cvirt->bias_uptime.tv_sec,
16399 + (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
16401 + a = cvirt->load[0] + (FIXED_1 / 200);
16402 + b = cvirt->load[1] + (FIXED_1 / 200);
16403 + c = cvirt->load[2] + (FIXED_1 / 200);
16404 + length += sprintf(buffer + length,
16405 + "nr_threads:\t%d\n"
16406 + "nr_running:\t%d\n"
16407 + "nr_unintr:\t%d\n"
16408 + "nr_onhold:\t%d\n"
16409 + "load_updates:\t%d\n"
16410 + "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
16411 + "total_forks:\t%d\n",
16412 + atomic_read(&cvirt->nr_threads),
16413 + atomic_read(&cvirt->nr_running),
16414 + atomic_read(&cvirt->nr_uninterruptible),
16415 + atomic_read(&cvirt->nr_onhold),
16416 + atomic_read(&cvirt->load_updates),
16417 + LOAD_INT(a), LOAD_FRAC(a),
16418 + LOAD_INT(b), LOAD_FRAC(b),
16419 + LOAD_INT(c), LOAD_FRAC(c),
16420 + atomic_read(&cvirt->total_forks));
16425 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
16426 + char *buffer, int cpu)
16432 +#endif /* _VX_CVIRT_PROC_H */
16433 diff -NurpP --minimal linux-3.13.10/kernel/vserver/debug.c linux-3.13.10-vs2.3.6.11/kernel/vserver/debug.c
16434 --- linux-3.13.10/kernel/vserver/debug.c 1970-01-01 00:00:00.000000000 +0000
16435 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/debug.c 2014-01-31 20:38:04.000000000 +0000
16438 + * kernel/vserver/debug.c
16440 + * Copyright (C) 2005-2007 Herbert Pötzl
16442 + * V0.01 vx_info dump support
16446 +#include <linux/module.h>
16448 +#include <linux/vserver/context.h>
16451 +void dump_vx_info(struct vx_info *vxi, int level)
16453 + printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
16454 + atomic_read(&vxi->vx_usecnt),
16455 + atomic_read(&vxi->vx_tasks),
16458 + __dump_vx_limit(&vxi->limit);
16459 + __dump_vx_sched(&vxi->sched);
16460 + __dump_vx_cvirt(&vxi->cvirt);
16461 + __dump_vx_cacct(&vxi->cacct);
16467 +EXPORT_SYMBOL_GPL(dump_vx_info);
16469 diff -NurpP --minimal linux-3.13.10/kernel/vserver/device.c linux-3.13.10-vs2.3.6.11/kernel/vserver/device.c
16470 --- linux-3.13.10/kernel/vserver/device.c 1970-01-01 00:00:00.000000000 +0000
16471 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/device.c 2014-01-31 20:38:04.000000000 +0000
16474 + * linux/kernel/vserver/device.c
16476 + * Linux-VServer: Device Support
16478 + * Copyright (C) 2006 Herbert Pötzl
16479 + * Copyright (C) 2007 Daniel Hokka Zakrisson
16481 + * V0.01 device mapping basics
16482 + * V0.02 added defaults
16486 +#include <linux/slab.h>
16487 +#include <linux/rcupdate.h>
16488 +#include <linux/fs.h>
16489 +#include <linux/namei.h>
16490 +#include <linux/hash.h>
16492 +#include <asm/errno.h>
16493 +#include <asm/uaccess.h>
16494 +#include <linux/vserver/base.h>
16495 +#include <linux/vserver/debug.h>
16496 +#include <linux/vserver/context.h>
16497 +#include <linux/vserver/device.h>
16498 +#include <linux/vserver/device_cmd.h>
16501 +#define DMAP_HASH_BITS 4
16504 +struct vs_mapping {
16506 + struct hlist_node hlist;
16507 + struct list_head list;
16509 +#define dm_hlist u.hlist
16510 +#define dm_list u.list
16513 + struct vx_dmap_target target;
16517 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
16519 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
16521 +static struct vx_dmap_target dmap_defaults[2] = {
16522 + { .flags = DATTR_OPEN },
16523 + { .flags = DATTR_OPEN },
16527 +struct kmem_cache *dmap_cachep __read_mostly;
16529 +int __init dmap_cache_init(void)
16531 + dmap_cachep = kmem_cache_create("dmap_cache",
16532 + sizeof(struct vs_mapping), 0,
16533 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
16537 +__initcall(dmap_cache_init);
16540 +static inline unsigned int __hashval(dev_t dev, int bits)
16542 + return hash_long((unsigned long)dev, bits);
16546 +/* __hash_mapping()
16547 + * add the mapping to the hash table
16549 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
16551 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16552 + struct hlist_head *head, *hash = dmap_main_hash;
16553 + int device = vdm->device;
16555 + spin_lock(hash_lock);
16556 + vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
16557 + vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
16559 + head = &hash[__hashval(device, DMAP_HASH_BITS)];
16560 + hlist_add_head(&vdm->dm_hlist, head);
16561 + spin_unlock(hash_lock);
16565 +static inline int __mode_to_default(umode_t mode)
16578 +/* __set_default()
16581 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
16582 + struct vx_dmap_target *vdmt)
16584 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16585 + spin_lock(hash_lock);
16588 + vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
16590 + dmap_defaults[__mode_to_default(mode)] = *vdmt;
16593 + spin_unlock(hash_lock);
16595 + vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
16596 + vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
16600 +/* __remove_default()
16601 + * remove a default
16603 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
16605 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16606 + spin_lock(hash_lock);
16609 + vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
16610 + else /* remove == reset */
16611 + dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
16613 + spin_unlock(hash_lock);
16618 +/* __find_mapping()
16619 + * find a mapping in the hash table
16621 + * caller must hold hash_lock
16623 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
16624 + struct vs_mapping **local, struct vs_mapping **global)
16626 + struct hlist_head *hash = dmap_main_hash;
16627 + struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
16628 + struct hlist_node *pos;
16629 + struct vs_mapping *vdm;
16635 + hlist_for_each(pos, head) {
16636 + vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
16638 + if ((vdm->device == device) &&
16639 + !((vdm->target.flags ^ mode) & S_IFMT)) {
16640 + if (vdm->xid == xid) {
16643 + } else if (global && vdm->xid == 0)
16648 + if (global && *global)
16655 +/* __lookup_mapping()
16656 + * find a mapping and store the result in target and flags
16658 +static inline int __lookup_mapping(struct vx_info *vxi,
16659 + dev_t device, dev_t *target, int *flags, umode_t mode)
16661 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16662 + struct vs_mapping *vdm, *global;
16663 + struct vx_dmap_target *vdmt;
16665 + vxid_t xid = vxi->vx_id;
16668 + spin_lock(hash_lock);
16669 + if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
16671 + vdmt = &vdm->target;
16675 + index = __mode_to_default(mode);
16676 + if (vxi && vxi->dmap.targets[index].flags) {
16678 + vdmt = &vxi->dmap.targets[index];
16679 + } else if (global) {
16681 + vdmt = &global->target;
16685 + vdmt = &dmap_defaults[index];
16689 + if (target && (vdmt->flags & DATTR_REMAP))
16690 + *target = vdmt->target;
16692 + *target = device;
16694 + *flags = vdmt->flags;
16696 + spin_unlock(hash_lock);
16702 +/* __remove_mapping()
16703 + * remove a mapping from the hash table
16705 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
16708 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16709 + struct vs_mapping *vdm = NULL;
16712 + spin_lock(hash_lock);
16714 + ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
16716 + vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
16717 + vxi, vxi ? vxi->vx_id : 0, device, mode);
16720 + hlist_del(&vdm->dm_hlist);
16723 + spin_unlock(hash_lock);
16725 + kmem_cache_free(dmap_cachep, vdm);
16731 +int vs_map_device(struct vx_info *vxi,
16732 + dev_t device, dev_t *target, umode_t mode)
16734 + int ret, flags = DATTR_MASK;
16738 + *target = device;
16741 + ret = __lookup_mapping(vxi, device, target, &flags, mode);
16742 + vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
16743 + device, target ? *target : 0, flags, mode, ret);
16745 + return (flags & DATTR_MASK);
16750 +static int do_set_mapping(struct vx_info *vxi,
16751 + dev_t device, dev_t target, int flags, umode_t mode)
16754 + struct vs_mapping *new;
16756 + new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
16760 + INIT_HLIST_NODE(&new->dm_hlist);
16761 + new->device = device;
16762 + new->target.target = target;
16763 + new->target.flags = flags | mode;
16764 + new->xid = (vxi ? vxi->vx_id : 0);
16766 + vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
16767 + __hash_mapping(vxi, new);
16769 + struct vx_dmap_target new = {
16770 + .target = target,
16771 + .flags = flags | mode,
16773 + __set_default(vxi, mode, &new);
16779 +static int do_unset_mapping(struct vx_info *vxi,
16780 + dev_t device, dev_t target, int flags, umode_t mode)
16782 + int ret = -EINVAL;
16785 + ret = __remove_mapping(vxi, device, mode);
16789 + ret = __remove_default(vxi, mode);
16799 +static inline int __user_device(const char __user *name, dev_t *dev,
16802 + struct nameidata nd;
16809 + ret = user_lpath(name, &nd.path);
16812 + if (nd.path.dentry->d_inode) {
16813 + *dev = nd.path.dentry->d_inode->i_rdev;
16814 + *mode = nd.path.dentry->d_inode->i_mode;
16816 + path_put(&nd.path);
16820 +static inline int __mapping_mode(dev_t device, dev_t target,
16821 + umode_t device_mode, umode_t target_mode, umode_t *mode)
16824 + *mode = device_mode & S_IFMT;
16826 + *mode = target_mode & S_IFMT;
16830 + /* if both given, device and target mode have to match */
16831 + if (device && target &&
16832 + ((device_mode ^ target_mode) & S_IFMT))
16838 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
16839 + const char __user *target_path, int flags, int set)
16841 + dev_t device = ~0, target = ~0;
16842 + umode_t device_mode = 0, target_mode = 0, mode;
16845 + ret = __user_device(device_path, &device, &device_mode);
16848 + ret = __user_device(target_path, &target, &target_mode);
16852 + ret = __mapping_mode(device, target,
16853 + device_mode, target_mode, &mode);
16858 + return do_set_mapping(vxi, device, target,
16861 + return do_unset_mapping(vxi, device, target,
16866 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
16868 + struct vcmd_set_mapping_v0 vc_data;
16870 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16873 + return do_mapping(vxi, vc_data.device, vc_data.target,
16874 + vc_data.flags, 1);
16877 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
16879 + struct vcmd_set_mapping_v0 vc_data;
16881 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16884 + return do_mapping(vxi, vc_data.device, vc_data.target,
16885 + vc_data.flags, 0);
16889 +#ifdef CONFIG_COMPAT
16891 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
16893 + struct vcmd_set_mapping_v0_x32 vc_data;
16895 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16898 + return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16899 + compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
16902 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
16904 + struct vcmd_set_mapping_v0_x32 vc_data;
16906 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16909 + return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16910 + compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
16913 +#endif /* CONFIG_COMPAT */
16916 diff -NurpP --minimal linux-3.13.10/kernel/vserver/dlimit.c linux-3.13.10-vs2.3.6.11/kernel/vserver/dlimit.c
16917 --- linux-3.13.10/kernel/vserver/dlimit.c 1970-01-01 00:00:00.000000000 +0000
16918 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/dlimit.c 2014-01-31 20:38:04.000000000 +0000
16921 + * linux/kernel/vserver/dlimit.c
16923 + * Virtual Server: Context Disk Limits
16925 + * Copyright (C) 2004-2009 Herbert Pötzl
16927 + * V0.01 initial version
16928 + * V0.02 compat32 splitup
16929 + * V0.03 extended interface
16933 +#include <linux/statfs.h>
16934 +#include <linux/sched.h>
16935 +#include <linux/namei.h>
16936 +#include <linux/vs_tag.h>
16937 +#include <linux/vs_dlimit.h>
16938 +#include <linux/vserver/dlimit_cmd.h>
16939 +#include <linux/slab.h>
16940 +// #include <linux/gfp.h>
16942 +#include <asm/uaccess.h>
16944 +/* __alloc_dl_info()
16946 + * allocate an initialized dl_info struct
16947 + * doesn't make it visible (hash) */
16949 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
16951 + struct dl_info *new = NULL;
16953 + vxdprintk(VXD_CBIT(dlim, 5),
16954 + "alloc_dl_info(%p,%d)*", sb, tag);
16956 + /* would this benefit from a slab cache? */
16957 + new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
16961 + memset(new, 0, sizeof(struct dl_info));
16962 + new->dl_tag = tag;
16964 + // INIT_RCU_HEAD(&new->dl_rcu);
16965 + INIT_HLIST_NODE(&new->dl_hlist);
16966 + spin_lock_init(&new->dl_lock);
16967 + atomic_set(&new->dl_refcnt, 0);
16968 + atomic_set(&new->dl_usecnt, 0);
16970 + /* rest of init goes here */
16972 + vxdprintk(VXD_CBIT(dlim, 4),
16973 + "alloc_dl_info(%p,%d) = %p", sb, tag, new);
16977 +/* __dealloc_dl_info()
16979 + * final disposal of dl_info */
16981 +static void __dealloc_dl_info(struct dl_info *dli)
16983 + vxdprintk(VXD_CBIT(dlim, 4),
16984 + "dealloc_dl_info(%p)", dli);
16986 + dli->dl_hlist.next = LIST_POISON1;
16987 + dli->dl_tag = -1;
16990 + BUG_ON(atomic_read(&dli->dl_usecnt));
16991 + BUG_ON(atomic_read(&dli->dl_refcnt));
16997 +/* hash table for dl_info hash */
16999 +#define DL_HASH_SIZE 13
17001 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17003 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17006 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
17008 + return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17013 +/* __hash_dl_info()
17015 + * add the dli to the global hash table
17016 + * requires the hash_lock to be held */
17018 +static inline void __hash_dl_info(struct dl_info *dli)
17020 + struct hlist_head *head;
17022 + vxdprintk(VXD_CBIT(dlim, 6),
17023 + "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17024 + get_dl_info(dli);
17025 + head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17026 + hlist_add_head_rcu(&dli->dl_hlist, head);
17029 +/* __unhash_dl_info()
17031 + * remove the dli from the global hash table
17032 + * requires the hash_lock to be held */
17034 +static inline void __unhash_dl_info(struct dl_info *dli)
17036 + vxdprintk(VXD_CBIT(dlim, 6),
17037 + "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17038 + hlist_del_rcu(&dli->dl_hlist);
17039 + put_dl_info(dli);
17043 +/* __lookup_dl_info()
17045 + * requires the rcu_read_lock()
17046 + * doesn't increment the dl_refcnt */
17048 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
17050 + struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17051 + struct dl_info *dli;
17053 + hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17054 + if (dli->dl_tag == tag && dli->dl_sb == sb)
17061 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
17063 + struct dl_info *dli;
17066 + dli = get_dl_info(__lookup_dl_info(sb, tag));
17067 + vxdprintk(VXD_CBIT(dlim, 7),
17068 + "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17069 + rcu_read_unlock();
17073 +void rcu_free_dl_info(struct rcu_head *head)
17075 + struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17076 + int usecnt, refcnt;
17078 + BUG_ON(!dli || !head);
17080 + usecnt = atomic_read(&dli->dl_usecnt);
17081 + BUG_ON(usecnt < 0);
17083 + refcnt = atomic_read(&dli->dl_refcnt);
17084 + BUG_ON(refcnt < 0);
17086 + vxdprintk(VXD_CBIT(dlim, 3),
17087 + "rcu_free_dl_info(%p)", dli);
17089 + __dealloc_dl_info(dli);
17091 + printk("!!! rcu didn't free\n");
17097 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17098 + uint32_t flags, int add)
17100 + struct path path;
17103 + ret = user_lpath(name, &path);
17105 + struct super_block *sb;
17106 + struct dl_info *dli;
17109 + if (!path.dentry->d_inode)
17110 + goto out_release;
17111 + if (!(sb = path.dentry->d_inode->i_sb))
17112 + goto out_release;
17115 + dli = __alloc_dl_info(sb, id);
17116 + spin_lock(&dl_info_hash_lock);
17119 + if (__lookup_dl_info(sb, id))
17121 + __hash_dl_info(dli);
17124 + spin_lock(&dl_info_hash_lock);
17125 + dli = __lookup_dl_info(sb, id);
17130 + __unhash_dl_info(dli);
17134 + spin_unlock(&dl_info_hash_lock);
17136 + __dealloc_dl_info(dli);
17143 +int vc_add_dlimit(uint32_t id, void __user *data)
17145 + struct vcmd_ctx_dlimit_base_v0 vc_data;
17147 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17150 + return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17153 +int vc_rem_dlimit(uint32_t id, void __user *data)
17155 + struct vcmd_ctx_dlimit_base_v0 vc_data;
17157 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17160 + return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17163 +#ifdef CONFIG_COMPAT
17165 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17167 + struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17169 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17172 + return do_addrem_dlimit(id,
17173 + compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17176 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17178 + struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17180 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17183 + return do_addrem_dlimit(id,
17184 + compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17187 +#endif /* CONFIG_COMPAT */
17191 +int do_set_dlimit(uint32_t id, const char __user *name,
17192 + uint32_t space_used, uint32_t space_total,
17193 + uint32_t inodes_used, uint32_t inodes_total,
17194 + uint32_t reserved, uint32_t flags)
17196 + struct path path;
17199 + ret = user_lpath(name, &path);
17201 + struct super_block *sb;
17202 + struct dl_info *dli;
17205 + if (!path.dentry->d_inode)
17206 + goto out_release;
17207 + if (!(sb = path.dentry->d_inode->i_sb))
17208 + goto out_release;
17210 + /* sanity checks */
17211 + if ((reserved != CDLIM_KEEP &&
17212 + reserved > 100) ||
17213 + (inodes_used != CDLIM_KEEP &&
17214 + inodes_used > inodes_total) ||
17215 + (space_used != CDLIM_KEEP &&
17216 + space_used > space_total))
17217 + goto out_release;
17220 + dli = locate_dl_info(sb, id);
17222 + goto out_release;
17224 + spin_lock(&dli->dl_lock);
17226 + if (inodes_used != CDLIM_KEEP)
17227 + dli->dl_inodes_used = inodes_used;
17228 + if (inodes_total != CDLIM_KEEP)
17229 + dli->dl_inodes_total = inodes_total;
17230 + if (space_used != CDLIM_KEEP)
17231 + dli->dl_space_used = dlimit_space_32to64(
17232 + space_used, flags, DLIMS_USED);
17234 + if (space_total == CDLIM_INFINITY)
17235 + dli->dl_space_total = DLIM_INFINITY;
17236 + else if (space_total != CDLIM_KEEP)
17237 + dli->dl_space_total = dlimit_space_32to64(
17238 + space_total, flags, DLIMS_TOTAL);
17240 + if (reserved != CDLIM_KEEP)
17241 + dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17243 + spin_unlock(&dli->dl_lock);
17245 + put_dl_info(dli);
17254 +int vc_set_dlimit(uint32_t id, void __user *data)
17256 + struct vcmd_ctx_dlimit_v0 vc_data;
17258 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17261 + return do_set_dlimit(id, vc_data.name,
17262 + vc_data.space_used, vc_data.space_total,
17263 + vc_data.inodes_used, vc_data.inodes_total,
17264 + vc_data.reserved, vc_data.flags);
17267 +#ifdef CONFIG_COMPAT
17269 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17271 + struct vcmd_ctx_dlimit_v0_x32 vc_data;
17273 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17276 + return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17277 + vc_data.space_used, vc_data.space_total,
17278 + vc_data.inodes_used, vc_data.inodes_total,
17279 + vc_data.reserved, vc_data.flags);
17282 +#endif /* CONFIG_COMPAT */
17286 +int do_get_dlimit(uint32_t id, const char __user *name,
17287 + uint32_t *space_used, uint32_t *space_total,
17288 + uint32_t *inodes_used, uint32_t *inodes_total,
17289 + uint32_t *reserved, uint32_t *flags)
17291 + struct path path;
17294 + ret = user_lpath(name, &path);
17296 + struct super_block *sb;
17297 + struct dl_info *dli;
17300 + if (!path.dentry->d_inode)
17301 + goto out_release;
17302 + if (!(sb = path.dentry->d_inode->i_sb))
17303 + goto out_release;
17306 + dli = locate_dl_info(sb, id);
17308 + goto out_release;
17310 + spin_lock(&dli->dl_lock);
17311 + *inodes_used = dli->dl_inodes_used;
17312 + *inodes_total = dli->dl_inodes_total;
17314 + *space_used = dlimit_space_64to32(
17315 + dli->dl_space_used, flags, DLIMS_USED);
17317 + if (dli->dl_space_total == DLIM_INFINITY)
17318 + *space_total = CDLIM_INFINITY;
17320 + *space_total = dlimit_space_64to32(
17321 + dli->dl_space_total, flags, DLIMS_TOTAL);
17323 + *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
17324 + spin_unlock(&dli->dl_lock);
17326 + put_dl_info(dli);
17337 +int vc_get_dlimit(uint32_t id, void __user *data)
17339 + struct vcmd_ctx_dlimit_v0 vc_data;
17342 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17345 + ret = do_get_dlimit(id, vc_data.name,
17346 + &vc_data.space_used, &vc_data.space_total,
17347 + &vc_data.inodes_used, &vc_data.inodes_total,
17348 + &vc_data.reserved, &vc_data.flags);
17352 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17357 +#ifdef CONFIG_COMPAT
17359 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
17361 + struct vcmd_ctx_dlimit_v0_x32 vc_data;
17364 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17367 + ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
17368 + &vc_data.space_used, &vc_data.space_total,
17369 + &vc_data.inodes_used, &vc_data.inodes_total,
17370 + &vc_data.reserved, &vc_data.flags);
17374 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17379 +#endif /* CONFIG_COMPAT */
17382 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
17384 + struct dl_info *dli;
17385 + __u64 blimit, bfree, bavail;
17388 + dli = locate_dl_info(sb, dx_current_tag());
17392 + spin_lock(&dli->dl_lock);
17393 + if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
17396 + /* reduce max inodes available to limit */
17397 + if (buf->f_files > dli->dl_inodes_total)
17398 + buf->f_files = dli->dl_inodes_total;
17400 + ifree = dli->dl_inodes_total - dli->dl_inodes_used;
17401 + /* reduce free inodes to min */
17402 + if (ifree < buf->f_ffree)
17403 + buf->f_ffree = ifree;
17406 + if (dli->dl_space_total == DLIM_INFINITY)
17409 + blimit = dli->dl_space_total >> sb->s_blocksize_bits;
17411 + if (dli->dl_space_total < dli->dl_space_used)
17414 + bfree = (dli->dl_space_total - dli->dl_space_used)
17415 + >> sb->s_blocksize_bits;
17417 + bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
17418 + if (bavail < dli->dl_space_used)
17421 + bavail = (bavail - dli->dl_space_used)
17422 + >> sb->s_blocksize_bits;
17424 + /* reduce max space available to limit */
17425 + if (buf->f_blocks > blimit)
17426 + buf->f_blocks = blimit;
17428 + /* reduce free space to min */
17429 + if (bfree < buf->f_bfree)
17430 + buf->f_bfree = bfree;
17432 + /* reduce avail space to min */
17433 + if (bavail < buf->f_bavail)
17434 + buf->f_bavail = bavail;
17437 + spin_unlock(&dli->dl_lock);
17438 + put_dl_info(dli);
17443 +#include <linux/module.h>
17445 +EXPORT_SYMBOL_GPL(locate_dl_info);
17446 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
17448 diff -NurpP --minimal linux-3.13.10/kernel/vserver/helper.c linux-3.13.10-vs2.3.6.11/kernel/vserver/helper.c
17449 --- linux-3.13.10/kernel/vserver/helper.c 1970-01-01 00:00:00.000000000 +0000
17450 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/helper.c 2014-01-31 20:38:04.000000000 +0000
17453 + * linux/kernel/vserver/helper.c
17455 + * Virtual Context Support
17457 + * Copyright (C) 2004-2007 Herbert Pötzl
17459 + * V0.01 basic helper
17463 +#include <linux/kmod.h>
17464 +#include <linux/reboot.h>
17465 +#include <linux/vs_context.h>
17466 +#include <linux/vs_network.h>
17467 +#include <linux/vserver/signal.h>
17470 +char vshelper_path[255] = "/sbin/vshelper";
17472 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
17474 + current->flags &= ~PF_NO_SETAFFINITY;
17478 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
17480 + struct subprocess_info *info;
17481 + gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
17483 + info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
17484 + vshelper_init, NULL, NULL);
17485 + if (info == NULL)
17488 + return call_usermodehelper_exec(info, wait);
17491 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
17495 + if ((ret = vs_call_usermodehelper(name, argv, envp,
17496 + sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
17497 + printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
17498 + name, argv[1], argv[2],
17499 + sync ? "sync" : "async", ret);
17501 + vxdprintk(VXD_CBIT(switch, 4),
17502 + "%s: (%s %s) returned %s with %d",
17503 + name, argv[1], argv[2], sync ? "sync" : "async", ret);
17508 + * vshelper path is set via /proc/sys
17509 + * invoked by vserver sys_reboot(), with
17510 + * the following arguments
17512 + * argv [0] = vshelper_path;
17513 + * argv [1] = action: "restart", "halt", "poweroff", ...
17514 + * argv [2] = context identifier
17516 + * envp [*] = type-specific parameters
17519 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
17521 + char id_buf[8], cmd_buf[16];
17522 + char uid_buf[16], pid_buf[16];
17525 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
17526 + char *envp[] = {"HOME=/", "TERM=linux",
17527 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
17528 + uid_buf, pid_buf, cmd_buf, 0};
17530 + if (vx_info_state(vxi, VXS_HELPER))
17532 + vxi->vx_state |= VXS_HELPER;
17534 + snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17536 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17537 + snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
17538 + from_kuid(&init_user_ns, current_uid()));
17539 + snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
17542 + case LINUX_REBOOT_CMD_RESTART:
17543 + argv[1] = "restart";
17546 + case LINUX_REBOOT_CMD_HALT:
17547 + argv[1] = "halt";
17550 + case LINUX_REBOOT_CMD_POWER_OFF:
17551 + argv[1] = "poweroff";
17554 + case LINUX_REBOOT_CMD_SW_SUSPEND:
17555 + argv[1] = "swsusp";
17558 + case LINUX_REBOOT_CMD_OOM:
17563 + vxi->vx_state &= ~VXS_HELPER;
17567 + ret = do_vshelper(vshelper_path, argv, envp, 0);
17568 + vxi->vx_state &= ~VXS_HELPER;
17569 + __wakeup_vx_info(vxi);
17570 + return (ret) ? -EPERM : 0;
17574 +long vs_reboot(unsigned int cmd, void __user *arg)
17576 + struct vx_info *vxi = current_vx_info();
17579 + vxdprintk(VXD_CBIT(misc, 5),
17580 + "vs_reboot(%p[#%d],%u)",
17581 + vxi, vxi ? vxi->vx_id : 0, cmd);
17583 + ret = vs_reboot_helper(vxi, cmd, arg);
17587 + vxi->reboot_cmd = cmd;
17588 + if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17590 + case LINUX_REBOOT_CMD_RESTART:
17591 + case LINUX_REBOOT_CMD_HALT:
17592 + case LINUX_REBOOT_CMD_POWER_OFF:
17593 + vx_info_kill(vxi, 0, SIGKILL);
17594 + vx_info_kill(vxi, 1, SIGKILL);
17602 +long vs_oom_action(unsigned int cmd)
17604 + struct vx_info *vxi = current_vx_info();
17607 + vxdprintk(VXD_CBIT(misc, 5),
17608 + "vs_oom_action(%p[#%d],%u)",
17609 + vxi, vxi ? vxi->vx_id : 0, cmd);
17611 + ret = vs_reboot_helper(vxi, cmd, NULL);
17615 + vxi->reboot_cmd = cmd;
17616 + if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17617 + vx_info_kill(vxi, 0, SIGKILL);
17618 + vx_info_kill(vxi, 1, SIGKILL);
17624 + * argv [0] = vshelper_path;
17625 + * argv [1] = action: "startup", "shutdown"
17626 + * argv [2] = context identifier
17628 + * envp [*] = type-specific parameters
17631 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
17633 + char id_buf[8], cmd_buf[16];
17634 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
17635 + char *envp[] = {"HOME=/", "TERM=linux",
17636 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17638 + if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
17641 + snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17642 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17645 + case VSC_STARTUP:
17646 + argv[1] = "startup";
17648 + case VSC_SHUTDOWN:
17649 + argv[1] = "shutdown";
17655 + return do_vshelper(vshelper_path, argv, envp, 1);
17660 + * argv [0] = vshelper_path;
17661 + * argv [1] = action: "netup", "netdown"
17662 + * argv [2] = context identifier
17664 + * envp [*] = type-specific parameters
17667 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
17669 + char id_buf[8], cmd_buf[16];
17670 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
17671 + char *envp[] = {"HOME=/", "TERM=linux",
17672 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17674 + if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
17677 + snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
17678 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17682 + argv[1] = "netup";
17684 + case VSC_NETDOWN:
17685 + argv[1] = "netdown";
17691 + return do_vshelper(vshelper_path, argv, envp, 1);
17694 diff -NurpP --minimal linux-3.13.10/kernel/vserver/history.c linux-3.13.10-vs2.3.6.11/kernel/vserver/history.c
17695 --- linux-3.13.10/kernel/vserver/history.c 1970-01-01 00:00:00.000000000 +0000
17696 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/history.c 2014-01-31 20:38:04.000000000 +0000
17699 + * kernel/vserver/history.c
17701 + * Virtual Context History Backtrace
17703 + * Copyright (C) 2004-2007 Herbert Pötzl
17705 + * V0.01 basic structure
17706 + * V0.02 hash/unhash and trace
17707 + * V0.03 preemption fixes
17711 +#include <linux/module.h>
17712 +#include <asm/uaccess.h>
17714 +#include <linux/vserver/context.h>
17715 +#include <linux/vserver/debug.h>
17716 +#include <linux/vserver/debug_cmd.h>
17717 +#include <linux/vserver/history.h>
17720 +#ifdef CONFIG_VSERVER_HISTORY
17721 +#define VXH_SIZE CONFIG_VSERVER_HISTORY_SIZE
17723 +#define VXH_SIZE 64
17726 +struct _vx_history {
17727 + unsigned int counter;
17729 + struct _vx_hist_entry entry[VXH_SIZE + 1];
17733 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
17735 +unsigned volatile int vxh_active = 1;
17737 +static atomic_t sequence = ATOMIC_INIT(0);
17742 + * requires disabled preemption */
17744 +struct _vx_hist_entry *vxh_advance(void *loc)
17746 + unsigned int cpu = smp_processor_id();
17747 + struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17748 + struct _vx_hist_entry *entry;
17749 + unsigned int index;
17751 + index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
17752 + entry = &hist->entry[index];
17754 + entry->seq = atomic_inc_return(&sequence);
17755 + entry->loc = loc;
17759 +EXPORT_SYMBOL_GPL(vxh_advance);
17762 +#define VXH_LOC_FMTS "(#%04x,*%d):%p"
17764 +#define VXH_LOC_ARGS(e) (e)->seq, cpu, (e)->loc
17767 +#define VXH_VXI_FMTS "%p[#%d,%d.%d]"
17769 +#define VXH_VXI_ARGS(e) (e)->vxi.ptr, \
17770 + (e)->vxi.ptr ? (e)->vxi.xid : 0, \
17771 + (e)->vxi.ptr ? (e)->vxi.usecnt : 0, \
17772 + (e)->vxi.ptr ? (e)->vxi.tasks : 0
17774 +void vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
17776 + switch (e->type) {
17777 + case VXH_THROW_OOPS:
17778 + printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
17781 + case VXH_GET_VX_INFO:
17782 + case VXH_PUT_VX_INFO:
17783 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17785 + (e->type == VXH_GET_VX_INFO) ? "get" : "put",
17786 + VXH_VXI_ARGS(e));
17789 + case VXH_INIT_VX_INFO:
17790 + case VXH_SET_VX_INFO:
17791 + case VXH_CLR_VX_INFO:
17792 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17794 + (e->type == VXH_INIT_VX_INFO) ? "init" :
17795 + ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
17796 + VXH_VXI_ARGS(e), e->sc.data);
17799 + case VXH_CLAIM_VX_INFO:
17800 + case VXH_RELEASE_VX_INFO:
17801 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17803 + (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
17804 + VXH_VXI_ARGS(e), e->sc.data);
17807 + case VXH_ALLOC_VX_INFO:
17808 + case VXH_DEALLOC_VX_INFO:
17809 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17811 + (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
17812 + VXH_VXI_ARGS(e));
17815 + case VXH_HASH_VX_INFO:
17816 + case VXH_UNHASH_VX_INFO:
17817 + printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
17819 + (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
17820 + VXH_VXI_ARGS(e));
17823 + case VXH_LOC_VX_INFO:
17824 + case VXH_LOOKUP_VX_INFO:
17825 + case VXH_CREATE_VX_INFO:
17826 + printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
17828 + (e->type == VXH_CREATE_VX_INFO) ? "create" :
17829 + ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
17830 + e->ll.arg, VXH_VXI_ARGS(e));
17835 +static void __vxh_dump_history(void)
17837 + unsigned int i, cpu;
17839 + printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
17840 + atomic_read(&sequence), NR_CPUS);
17842 + for (i = 0; i < VXH_SIZE; i++) {
17843 + for_each_online_cpu(cpu) {
17844 + struct _vx_history *hist =
17845 + &per_cpu(vx_history_buffer, cpu);
17846 + unsigned int index = (hist->counter - i) % VXH_SIZE;
17847 + struct _vx_hist_entry *entry = &hist->entry[index];
17849 + vxh_dump_entry(entry, cpu);
17854 +void vxh_dump_history(void)
17858 + local_irq_enable();
17860 + local_irq_disable();
17862 + __vxh_dump_history();
17866 +/* vserver syscall commands below here */
17869 +int vc_dump_history(uint32_t id)
17872 + __vxh_dump_history();
17879 +int do_read_history(struct __user _vx_hist_entry *data,
17880 + int cpu, uint32_t *index, uint32_t *count)
17882 + int pos, ret = 0;
17883 + struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17884 + int end = hist->counter;
17885 + int start = end - VXH_SIZE + 2;
17886 + int idx = *index;
17888 + /* special case: get current pos */
17894 + /* have we lost some data? */
17898 + for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
17899 + struct _vx_hist_entry *entry =
17900 + &hist->entry[idx % VXH_SIZE];
17902 + /* send entry to userspace */
17903 + ret = copy_to_user(&data[pos], entry, sizeof(*entry));
17907 + /* save new index and count */
17910 + return ret ? ret : (*index < end);
17913 +int vc_read_history(uint32_t id, void __user *data)
17915 + struct vcmd_read_history_v0 vc_data;
17918 + if (id >= NR_CPUS)
17921 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17924 + ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
17925 + id, &vc_data.index, &vc_data.count);
17927 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17932 +#ifdef CONFIG_COMPAT
17934 +int vc_read_history_x32(uint32_t id, void __user *data)
17936 + struct vcmd_read_history_v0_x32 vc_data;
17939 + if (id >= NR_CPUS)
17942 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17945 + ret = do_read_history((struct __user _vx_hist_entry *)
17946 + compat_ptr(vc_data.data_ptr),
17947 + id, &vc_data.index, &vc_data.count);
17949 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17954 +#endif /* CONFIG_COMPAT */
17956 diff -NurpP --minimal linux-3.13.10/kernel/vserver/inet.c linux-3.13.10-vs2.3.6.11/kernel/vserver/inet.c
17957 --- linux-3.13.10/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
17958 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/inet.c 2014-02-01 00:26:40.000000000 +0000
17961 +#include <linux/in.h>
17962 +#include <linux/inetdevice.h>
17963 +#include <linux/export.h>
17964 +#include <linux/vs_inet.h>
17965 +#include <linux/vs_inet6.h>
17966 +#include <linux/vserver/debug.h>
17967 +#include <net/route.h>
17968 +#include <net/addrconf.h>
17971 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
17975 + if (!nxi1 || !nxi2 || nxi1 == nxi2)
17978 + struct nx_addr_v4 *ptr;
17979 + unsigned long irqflags;
17981 + spin_lock_irqsave(&nxi1->addr_lock, irqflags);
17982 + for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
17983 + if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
17988 + spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
17991 + vxdprintk(VXD_CBIT(net, 2),
17992 + "nx_v4_addr_conflict(%p,%p): %d",
17993 + nxi1, nxi2, ret);
17999 +#ifdef CONFIG_IPV6
18001 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18005 + if (!nxi1 || !nxi2 || nxi1 == nxi2)
18008 + struct nx_addr_v6 *ptr;
18009 + unsigned long irqflags;
18011 + spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18012 + for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18013 + if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18018 + spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18021 + vxdprintk(VXD_CBIT(net, 2),
18022 + "nx_v6_addr_conflict(%p,%p): %d",
18023 + nxi1, nxi2, ret);
18030 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18032 + struct in_device *in_dev;
18033 + struct in_ifaddr **ifap;
18034 + struct in_ifaddr *ifa;
18039 + in_dev = in_dev_get(dev);
18043 + for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18044 + ifap = &ifa->ifa_next) {
18045 + if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18050 + in_dev_put(in_dev);
18056 +#ifdef CONFIG_IPV6
18058 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18060 + struct inet6_dev *in_dev;
18061 + struct inet6_ifaddr *ifa;
18066 + in_dev = in6_dev_get(dev);
18070 + // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18071 + list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18072 + if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18077 + in6_dev_put(in_dev);
18084 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18090 + if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18092 +#ifdef CONFIG_IPV6
18094 + if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18099 + vxdprintk(VXD_CBIT(net, 3),
18100 + "dev_in_nx_info(%p,%p[#%d]) = %d",
18101 + dev, nxi, nxi ? nxi->nx_id : 0, ret);
18105 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18106 + struct flowi4 *fl4)
18108 + struct rtable *rt;
18113 + /* FIXME: handle lback only case */
18114 + if (!NX_IPV4(nxi))
18115 + return ERR_PTR(-EPERM);
18117 + vxdprintk(VXD_CBIT(net, 4),
18118 + "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18119 + nxi, nxi ? nxi->nx_id : 0,
18120 + NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18122 + /* single IP is unconditional */
18123 + if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18124 + (fl4->saddr == INADDR_ANY))
18125 + fl4->saddr = nxi->v4.ip[0].s_addr;
18127 + if (fl4->saddr == INADDR_ANY) {
18128 + struct nx_addr_v4 *ptr;
18129 + __be32 found = 0;
18131 + rt = __ip_route_output_key(net, fl4);
18132 + if (!IS_ERR(rt)) {
18133 + found = fl4->saddr;
18135 + vxdprintk(VXD_CBIT(net, 4),
18136 + "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18137 + nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18138 + if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18142 + WARN_ON_ONCE(in_irq());
18143 + spin_lock_bh(&nxi->addr_lock);
18144 + for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18145 + __be32 primary = ptr->ip[0].s_addr;
18146 + __be32 mask = ptr->mask.s_addr;
18147 + __be32 neta = primary & mask;
18149 + vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18150 + NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18151 + nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18152 + NIPQUAD(mask), NIPQUAD(neta));
18153 + if ((found & mask) != neta)
18156 + fl4->saddr = primary;
18157 + rt = __ip_route_output_key(net, fl4);
18158 + vxdprintk(VXD_CBIT(net, 4),
18159 + "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18160 + nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18161 + if (!IS_ERR(rt)) {
18162 + found = fl4->saddr;
18164 + if (found == primary)
18165 + goto found_unlock;
18168 + /* still no source ip? */
18169 + found = ipv4_is_loopback(fl4->daddr)
18170 + ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18172 + spin_unlock_bh(&nxi->addr_lock);
18174 + /* assign src ip to flow */
18175 + fl4->saddr = found;
18178 + if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18179 + return ERR_PTR(-EPERM);
18182 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18183 + if (ipv4_is_loopback(fl4->daddr))
18184 + fl4->daddr = nxi->v4_lback.s_addr;
18185 + if (ipv4_is_loopback(fl4->saddr))
18186 + fl4->saddr = nxi->v4_lback.s_addr;
18187 + } else if (ipv4_is_loopback(fl4->daddr) &&
18188 + !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18189 + return ERR_PTR(-EPERM);
18194 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18196 diff -NurpP --minimal linux-3.13.10/kernel/vserver/init.c linux-3.13.10-vs2.3.6.11/kernel/vserver/init.c
18197 --- linux-3.13.10/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
18198 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/init.c 2014-01-31 20:38:04.000000000 +0000
18201 + * linux/kernel/init.c
18203 + * Virtual Server Init
18205 + * Copyright (C) 2004-2007 Herbert Pötzl
18207 + * V0.01 basic structure
18211 +#include <linux/init.h>
18213 +int vserver_register_sysctl(void);
18214 +void vserver_unregister_sysctl(void);
18217 +static int __init init_vserver(void)
18221 +#ifdef CONFIG_VSERVER_DEBUG
18222 + vserver_register_sysctl();
18228 +static void __exit exit_vserver(void)
18231 +#ifdef CONFIG_VSERVER_DEBUG
18232 + vserver_unregister_sysctl();
18237 +/* FIXME: GFP_ZONETYPES gone
18238 +long vx_slab[GFP_ZONETYPES]; */
18242 +module_init(init_vserver);
18243 +module_exit(exit_vserver);
18245 diff -NurpP --minimal linux-3.13.10/kernel/vserver/inode.c linux-3.13.10-vs2.3.6.11/kernel/vserver/inode.c
18246 --- linux-3.13.10/kernel/vserver/inode.c 1970-01-01 00:00:00.000000000 +0000
18247 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/inode.c 2014-01-31 20:38:04.000000000 +0000
18250 + * linux/kernel/vserver/inode.c
18252 + * Virtual Server: File System Support
18254 + * Copyright (C) 2004-2007 Herbert Pötzl
18256 + * V0.01 separated from vcontext V0.05
18257 + * V0.02 moved to tag (instead of xid)
18261 +#include <linux/tty.h>
18262 +#include <linux/proc_fs.h>
18263 +#include <linux/devpts_fs.h>
18264 +#include <linux/fs.h>
18265 +#include <linux/file.h>
18266 +#include <linux/mount.h>
18267 +#include <linux/parser.h>
18268 +#include <linux/namei.h>
18269 +#include <linux/magic.h>
18270 +#include <linux/slab.h>
18271 +#include <linux/vserver/inode.h>
18272 +#include <linux/vserver/inode_cmd.h>
18273 +#include <linux/vs_base.h>
18274 +#include <linux/vs_tag.h>
18276 +#include <asm/uaccess.h>
18277 +#include <../../fs/proc/internal.h>
18280 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18282 + struct proc_dir_entry *entry;
18284 + if (!in || !in->i_sb)
18287 + *flags = IATTR_TAG
18288 + | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18289 + | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18290 + | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18291 + | (IS_COW(in) ? IATTR_COW : 0);
18292 + *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18294 + if (S_ISDIR(in->i_mode))
18295 + *mask |= IATTR_BARRIER;
18297 + if (IS_TAGGED(in)) {
18298 + *tag = i_tag_read(in);
18299 + *mask |= IATTR_TAG;
18302 + switch (in->i_sb->s_magic) {
18303 + case PROC_SUPER_MAGIC:
18304 + entry = PROC_I(in)->pde;
18306 + /* check for specific inodes? */
18308 + *mask |= IATTR_FLAGS;
18310 + *flags |= (entry->vx_flags & IATTR_FLAGS);
18312 + *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
18315 + case DEVPTS_SUPER_MAGIC:
18316 + *tag = i_tag_read(in);
18317 + *mask |= IATTR_TAG;
18326 +int vc_get_iattr(void __user *data)
18328 + struct path path;
18329 + struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
18332 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18335 + ret = user_lpath(vc_data.name, &path);
18337 + ret = __vc_get_iattr(path.dentry->d_inode,
18338 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18344 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18349 +#ifdef CONFIG_COMPAT
18351 +int vc_get_iattr_x32(void __user *data)
18353 + struct path path;
18354 + struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
18357 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18360 + ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18362 + ret = __vc_get_iattr(path.dentry->d_inode,
18363 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18369 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18374 +#endif /* CONFIG_COMPAT */
18377 +int vc_fget_iattr(uint32_t fd, void __user *data)
18379 + struct file *filp;
18380 + struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
18383 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18387 + if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18390 + ret = __vc_get_iattr(filp->f_dentry->d_inode,
18391 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18395 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18401 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18403 + struct inode *in = de->d_inode;
18404 + int error = 0, is_proc = 0, has_tag = 0;
18405 + struct iattr attr = { 0 };
18407 + if (!in || !in->i_sb)
18410 + is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
18411 + if ((*mask & IATTR_FLAGS) && !is_proc)
18414 + has_tag = IS_TAGGED(in) ||
18415 + (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
18416 + if ((*mask & IATTR_TAG) && !has_tag)
18419 + mutex_lock(&in->i_mutex);
18420 + if (*mask & IATTR_TAG) {
18421 + attr.ia_tag = make_ktag(&init_user_ns, *tag);
18422 + attr.ia_valid |= ATTR_TAG;
18425 + if (*mask & IATTR_FLAGS) {
18426 + struct proc_dir_entry *entry = PROC_I(in)->pde;
18427 + unsigned int iflags = PROC_I(in)->vx_flags;
18429 + iflags = (iflags & ~(*mask & IATTR_FLAGS))
18430 + | (*flags & IATTR_FLAGS);
18431 + PROC_I(in)->vx_flags = iflags;
18433 + entry->vx_flags = iflags;
18436 + if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
18437 + IATTR_BARRIER | IATTR_COW)) {
18438 + int iflags = in->i_flags;
18439 + int vflags = in->i_vflags;
18441 + if (*mask & IATTR_IMMUTABLE) {
18442 + if (*flags & IATTR_IMMUTABLE)
18443 + iflags |= S_IMMUTABLE;
18445 + iflags &= ~S_IMMUTABLE;
18447 + if (*mask & IATTR_IXUNLINK) {
18448 + if (*flags & IATTR_IXUNLINK)
18449 + iflags |= S_IXUNLINK;
18451 + iflags &= ~S_IXUNLINK;
18453 + if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
18454 + if (*flags & IATTR_BARRIER)
18455 + vflags |= V_BARRIER;
18457 + vflags &= ~V_BARRIER;
18459 + if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
18460 + if (*flags & IATTR_COW)
18463 + vflags &= ~V_COW;
18465 + if (in->i_op && in->i_op->sync_flags) {
18466 + error = in->i_op->sync_flags(in, iflags, vflags);
18472 + if (attr.ia_valid) {
18473 + if (in->i_op && in->i_op->setattr)
18474 + error = in->i_op->setattr(de, &attr);
18476 + error = inode_change_ok(in, &attr);
18478 + setattr_copy(in, &attr);
18479 + mark_inode_dirty(in);
18485 + mutex_unlock(&in->i_mutex);
18489 +int vc_set_iattr(void __user *data)
18491 + struct path path;
18492 + struct vcmd_ctx_iattr_v1 vc_data;
18495 + if (!capable(CAP_LINUX_IMMUTABLE))
18497 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18500 + ret = user_lpath(vc_data.name, &path);
18502 + ret = __vc_set_iattr(path.dentry,
18503 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18507 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18512 +#ifdef CONFIG_COMPAT
18514 +int vc_set_iattr_x32(void __user *data)
18516 + struct path path;
18517 + struct vcmd_ctx_iattr_v1_x32 vc_data;
18520 + if (!capable(CAP_LINUX_IMMUTABLE))
18522 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18525 + ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18527 + ret = __vc_set_iattr(path.dentry,
18528 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18532 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18537 +#endif /* CONFIG_COMPAT */
18539 +int vc_fset_iattr(uint32_t fd, void __user *data)
18541 + struct file *filp;
18542 + struct vcmd_ctx_fiattr_v0 vc_data;
18545 + if (!capable(CAP_LINUX_IMMUTABLE))
18547 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18551 + if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18554 + ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
18555 + &vc_data.flags, &vc_data.mask);
18559 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18565 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
18567 +static match_table_t tokens = {
18568 + {Opt_notagcheck, "notagcheck"},
18569 +#ifdef CONFIG_PROPAGATE
18570 + {Opt_notag, "notag"},
18571 + {Opt_tag, "tag"},
18572 + {Opt_tagid, "tagid=%u"},
18578 +static void __dx_parse_remove(char *string, char *opt)
18580 + char *p = strstr(string, opt);
18584 + while (*q != '\0' && *q != ',')
18593 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
18594 + unsigned long *flags)
18597 + substring_t args[MAX_OPT_ARGS];
18599 + char *s, *p, *opts;
18600 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
18606 + s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
18611 + while ((p = strsep(&opts, ",")) != NULL) {
18612 + token = match_token(p, tokens, args);
18615 +#ifdef CONFIG_PROPAGATE
18620 + __dx_parse_remove(s, "tag");
18621 + *mnt_flags |= MNT_TAGID;
18622 + set |= MNT_TAGID;
18626 + __dx_parse_remove(s, "notag");
18627 + *mnt_flags |= MNT_NOTAG;
18628 + set |= MNT_NOTAG;
18631 + if (tag && !match_int(args, &option))
18634 + __dx_parse_remove(s, "tagid");
18635 + *mnt_flags |= MNT_TAGID;
18636 + set |= MNT_TAGID;
18638 +#endif /* CONFIG_PROPAGATE */
18639 + case Opt_notagcheck:
18641 + __dx_parse_remove(s, "notagcheck");
18642 + *flags |= MS_NOTAGCHECK;
18643 + set |= MS_NOTAGCHECK;
18646 + vxdprintk(VXD_CBIT(tag, 7),
18647 + "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
18648 + p, token, option);
18651 + strcpy(string, s);
18656 +#ifdef CONFIG_PROPAGATE
18658 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
18660 + vtag_t new_tag = 0;
18661 + struct vfsmount *mnt;
18666 + mnt = nd->path.mnt;
18670 + propagate = (mnt->mnt_flags & MNT_TAGID);
18672 + new_tag = mnt->mnt_tag;
18674 + vxdprintk(VXD_CBIT(tag, 7),
18675 + "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
18676 + inode, inode->i_ino, inode->i_tag,
18677 + new_tag, (propagate) ? 1 : 0);
18680 + i_tag_write(inode, new_tag);
18683 +#include <linux/module.h>
18685 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
18687 +#endif /* CONFIG_PROPAGATE */
18689 diff -NurpP --minimal linux-3.13.10/kernel/vserver/limit.c linux-3.13.10-vs2.3.6.11/kernel/vserver/limit.c
18690 --- linux-3.13.10/kernel/vserver/limit.c 1970-01-01 00:00:00.000000000 +0000
18691 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit.c 2014-02-01 00:22:08.000000000 +0000
18694 + * linux/kernel/vserver/limit.c
18696 + * Virtual Server: Context Limits
18698 + * Copyright (C) 2004-2010 Herbert Pötzl
18700 + * V0.01 broken out from vcontext V0.05
18701 + * V0.02 changed vcmds to vxi arg
18702 + * V0.03 added memory cgroup support
18706 +#include <linux/sched.h>
18707 +#include <linux/module.h>
18708 +#include <linux/memcontrol.h>
18709 +#include <linux/res_counter.h>
18710 +#include <linux/vs_limit.h>
18711 +#include <linux/vserver/limit.h>
18712 +#include <linux/vserver/limit_cmd.h>
18714 +#include <asm/uaccess.h>
18717 +const char *vlimit_name[NUM_LIMITS] = {
18718 + [RLIMIT_CPU] = "CPU",
18719 + [RLIMIT_NPROC] = "NPROC",
18720 + [RLIMIT_NOFILE] = "NOFILE",
18721 + [RLIMIT_LOCKS] = "LOCKS",
18722 + [RLIMIT_SIGPENDING] = "SIGP",
18723 + [RLIMIT_MSGQUEUE] = "MSGQ",
18725 + [VLIMIT_NSOCK] = "NSOCK",
18726 + [VLIMIT_OPENFD] = "OPENFD",
18727 + [VLIMIT_SHMEM] = "SHMEM",
18728 + [VLIMIT_DENTRY] = "DENTRY",
18731 +EXPORT_SYMBOL_GPL(vlimit_name);
18733 +#define MASK_ENTRY(x) (1 << (x))
18735 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
18738 + , /* softlimit */
18741 + MASK_ENTRY( RLIMIT_NPROC ) |
18742 + MASK_ENTRY( RLIMIT_NOFILE ) |
18743 + MASK_ENTRY( RLIMIT_LOCKS ) |
18744 + MASK_ENTRY( RLIMIT_MSGQUEUE ) |
18746 + MASK_ENTRY( VLIMIT_NSOCK ) |
18747 + MASK_ENTRY( VLIMIT_OPENFD ) |
18748 + MASK_ENTRY( VLIMIT_SHMEM ) |
18749 + MASK_ENTRY( VLIMIT_DENTRY ) |
18752 + /* accounting only */
18753 +uint32_t account_mask =
18754 + MASK_ENTRY( VLIMIT_SEMARY ) |
18755 + MASK_ENTRY( VLIMIT_NSEMS ) |
18756 + MASK_ENTRY( VLIMIT_MAPPED ) |
18760 +static int is_valid_vlimit(int id)
18762 + uint32_t mask = vlimit_mask.minimum |
18763 + vlimit_mask.softlimit | vlimit_mask.maximum;
18764 + return mask & (1 << id);
18767 +static int is_accounted_vlimit(int id)
18769 + if (is_valid_vlimit(id))
18771 + return account_mask & (1 << id);
18775 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
18777 + rlim_t limit = __rlim_soft(&vxi->limit, id);
18778 + return VX_VLIM(limit);
18781 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
18783 + rlim_t limit = __rlim_hard(&vxi->limit, id);
18784 + return VX_VLIM(limit);
18787 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
18788 + uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
18790 + if (!is_valid_vlimit(id))
18794 + *minimum = CRLIM_UNSET;
18796 + *softlimit = vc_get_soft(vxi, id);
18798 + *maximum = vc_get_hard(vxi, id);
18802 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
18804 + struct vcmd_ctx_rlimit_v0 vc_data;
18807 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18810 + ret = do_get_rlimit(vxi, vc_data.id,
18811 + &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18815 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18820 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
18821 + uint64_t minimum, uint64_t softlimit, uint64_t maximum)
18823 + if (!is_valid_vlimit(id))
18826 + if (maximum != CRLIM_KEEP)
18827 + __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
18828 + if (softlimit != CRLIM_KEEP)
18829 + __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
18831 + /* clamp soft limit */
18832 + if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
18833 + __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
18838 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
18840 + struct vcmd_ctx_rlimit_v0 vc_data;
18842 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18845 + return do_set_rlimit(vxi, vc_data.id,
18846 + vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18849 +#ifdef CONFIG_IA32_EMULATION
18851 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
18853 + struct vcmd_ctx_rlimit_v0_x32 vc_data;
18855 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18858 + return do_set_rlimit(vxi, vc_data.id,
18859 + vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18862 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
18864 + struct vcmd_ctx_rlimit_v0_x32 vc_data;
18867 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18870 + ret = do_get_rlimit(vxi, vc_data.id,
18871 + &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18875 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18880 +#endif /* CONFIG_IA32_EMULATION */
18883 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
18885 + if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
18891 +static inline void vx_reset_hits(struct _vx_limit *limit)
18895 + for (lim = 0; lim < NUM_LIMITS; lim++) {
18896 + atomic_set(&__rlim_lhit(limit, lim), 0);
18900 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
18902 + vx_reset_hits(&vxi->limit);
18906 +static inline void vx_reset_minmax(struct _vx_limit *limit)
18911 + for (lim = 0; lim < NUM_LIMITS; lim++) {
18912 + value = __rlim_get(limit, lim);
18913 + __rlim_rmax(limit, lim) = value;
18914 + __rlim_rmin(limit, lim) = value;
18918 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
18920 + vx_reset_minmax(&vxi->limit);
18925 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
18927 + struct vcmd_rlimit_stat_v0 vc_data;
18928 + struct _vx_limit *limit = &vxi->limit;
18931 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18935 + if (!is_accounted_vlimit(id))
18938 + vx_limit_fixup(limit, id);
18939 + vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
18940 + vc_data.value = __rlim_get(limit, id);
18941 + vc_data.minimum = __rlim_rmin(limit, id);
18942 + vc_data.maximum = __rlim_rmax(limit, id);
18944 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18950 +void vx_vsi_meminfo(struct sysinfo *val)
18952 +#ifdef CONFIG_MEMCG
18953 + struct mem_cgroup *mcg;
18954 + u64 res_limit, res_usage;
18957 + mcg = mem_cgroup_from_task(current);
18958 + rcu_read_unlock();
18962 + res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
18963 + res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
18965 + if (res_limit != RES_COUNTER_MAX)
18966 + val->totalram = (res_limit >> PAGE_SHIFT);
18967 + val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
18968 + val->bufferram = 0;
18969 + val->totalhigh = 0;
18970 + val->freehigh = 0;
18972 +#endif /* CONFIG_MEMCG */
18976 +void vx_vsi_swapinfo(struct sysinfo *val)
18978 +#ifdef CONFIG_MEMCG
18979 +#ifdef CONFIG_MEMCG_SWAP
18980 + struct mem_cgroup *mcg;
18981 + u64 res_limit, res_usage, memsw_limit, memsw_usage;
18982 + s64 swap_limit, swap_usage;
18985 + mcg = mem_cgroup_from_task(current);
18986 + rcu_read_unlock();
18990 + res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
18991 + res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
18992 + memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
18993 + memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
18995 + /* memory unlimited */
18996 + if (res_limit == RES_COUNTER_MAX)
18999 + swap_limit = memsw_limit - res_limit;
19000 + /* we have a swap limit? */
19001 + if (memsw_limit != RES_COUNTER_MAX)
19002 + val->totalswap = swap_limit >> PAGE_SHIFT;
19004 + /* calculate swap part */
19005 + swap_usage = (memsw_usage > res_usage) ?
19006 + memsw_usage - res_usage : 0;
19008 + /* total shown minus usage gives free swap */
19009 + val->freeswap = (swap_usage < swap_limit) ?
19010 + val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19012 +#else /* !CONFIG_MEMCG_SWAP */
19013 + val->totalswap = 0;
19014 + val->freeswap = 0;
19015 +#endif /* !CONFIG_MEMCG_SWAP */
19016 +#endif /* CONFIG_MEMCG */
19020 +long vx_vsi_cached(struct sysinfo *val)
19023 +#ifdef CONFIG_MEMCG
19024 + struct mem_cgroup *mcg;
19027 + mcg = mem_cgroup_from_task(current);
19028 + rcu_read_unlock();
19032 + cache = mem_cgroup_stat_read_cache(mcg);
19038 diff -NurpP --minimal linux-3.13.10/kernel/vserver/limit_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_init.h
19039 --- linux-3.13.10/kernel/vserver/limit_init.h 1970-01-01 00:00:00.000000000 +0000
19040 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_init.h 2014-01-31 20:38:04.000000000 +0000
19044 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19048 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19049 + __rlim_soft(limit, lim) = RLIM_INFINITY;
19050 + __rlim_hard(limit, lim) = RLIM_INFINITY;
19051 + __rlim_set(limit, lim, 0);
19052 + atomic_set(&__rlim_lhit(limit, lim), 0);
19053 + __rlim_rmin(limit, lim) = 0;
19054 + __rlim_rmax(limit, lim) = 0;
19058 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19063 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19064 + if ((1 << lim) & VLIM_NOCHECK)
19066 + value = __rlim_get(limit, lim);
19067 + vxwprintk_xid(value,
19068 + "!!! limit: %p[%s,%d] = %ld on exit.",
19069 + limit, vlimit_name[lim], lim, (long)value);
19073 diff -NurpP --minimal linux-3.13.10/kernel/vserver/limit_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_proc.h
19074 --- linux-3.13.10/kernel/vserver/limit_proc.h 1970-01-01 00:00:00.000000000 +0000
19075 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_proc.h 2014-01-31 20:38:04.000000000 +0000
19077 +#ifndef _VX_LIMIT_PROC_H
19078 +#define _VX_LIMIT_PROC_H
19080 +#include <linux/vserver/limit_int.h>
19083 +#define VX_LIMIT_FMT ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19084 +#define VX_LIMIT_TOP \
19085 + "Limit\t current\t min/max\t\t soft/hard\t\thits\n"
19087 +#define VX_LIMIT_ARG(r) \
19088 + (unsigned long)__rlim_get(limit, r), \
19089 + (unsigned long)__rlim_rmin(limit, r), \
19090 + (unsigned long)__rlim_rmax(limit, r), \
19091 + VX_VLIM(__rlim_soft(limit, r)), \
19092 + VX_VLIM(__rlim_hard(limit, r)), \
19093 + atomic_read(&__rlim_lhit(limit, r))
19095 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19097 + vx_limit_fixup(limit, -1);
19098 + return sprintf(buffer, VX_LIMIT_TOP
19099 + "PROC" VX_LIMIT_FMT
19100 + "VM" VX_LIMIT_FMT
19101 + "VML" VX_LIMIT_FMT
19102 + "RSS" VX_LIMIT_FMT
19103 + "ANON" VX_LIMIT_FMT
19104 + "RMAP" VX_LIMIT_FMT
19105 + "FILES" VX_LIMIT_FMT
19106 + "OFD" VX_LIMIT_FMT
19107 + "LOCKS" VX_LIMIT_FMT
19108 + "SOCK" VX_LIMIT_FMT
19109 + "MSGQ" VX_LIMIT_FMT
19110 + "SHM" VX_LIMIT_FMT
19111 + "SEMA" VX_LIMIT_FMT
19112 + "SEMS" VX_LIMIT_FMT
19113 + "DENT" VX_LIMIT_FMT,
19114 + VX_LIMIT_ARG(RLIMIT_NPROC),
19115 + VX_LIMIT_ARG(RLIMIT_AS),
19116 + VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19117 + VX_LIMIT_ARG(RLIMIT_RSS),
19118 + VX_LIMIT_ARG(VLIMIT_ANON),
19119 + VX_LIMIT_ARG(VLIMIT_MAPPED),
19120 + VX_LIMIT_ARG(RLIMIT_NOFILE),
19121 + VX_LIMIT_ARG(VLIMIT_OPENFD),
19122 + VX_LIMIT_ARG(RLIMIT_LOCKS),
19123 + VX_LIMIT_ARG(VLIMIT_NSOCK),
19124 + VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19125 + VX_LIMIT_ARG(VLIMIT_SHMEM),
19126 + VX_LIMIT_ARG(VLIMIT_SEMARY),
19127 + VX_LIMIT_ARG(VLIMIT_NSEMS),
19128 + VX_LIMIT_ARG(VLIMIT_DENTRY));
19131 +#endif /* _VX_LIMIT_PROC_H */
19134 diff -NurpP --minimal linux-3.13.10/kernel/vserver/network.c linux-3.13.10-vs2.3.6.11/kernel/vserver/network.c
19135 --- linux-3.13.10/kernel/vserver/network.c 1970-01-01 00:00:00.000000000 +0000
19136 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/network.c 2014-01-31 20:38:04.000000000 +0000
19139 + * linux/kernel/vserver/network.c
19141 + * Virtual Server: Network Support
19143 + * Copyright (C) 2003-2007 Herbert Pötzl
19145 + * V0.01 broken out from vcontext V0.05
19146 + * V0.02 cleaned up implementation
19147 + * V0.03 added equiv nx commands
19148 + * V0.04 switch to RCU based hash
19149 + * V0.05 and back to locking again
19150 + * V0.06 changed vcmds to nxi arg
19151 + * V0.07 have __create claim() the nxi
19155 +#include <linux/err.h>
19156 +#include <linux/slab.h>
19157 +#include <linux/rcupdate.h>
19158 +#include <net/ipv6.h>
19160 +#include <linux/vs_network.h>
19161 +#include <linux/vs_pid.h>
19162 +#include <linux/vserver/network_cmd.h>
19165 +atomic_t nx_global_ctotal = ATOMIC_INIT(0);
19166 +atomic_t nx_global_cactive = ATOMIC_INIT(0);
19168 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19169 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19172 +static int __init init_network(void)
19174 + nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19175 + sizeof(struct nx_addr_v4), 0,
19176 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19177 + nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19178 + sizeof(struct nx_addr_v6), 0,
19179 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19184 +/* __alloc_nx_addr_v4() */
19186 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19188 + struct nx_addr_v4 *nxa = kmem_cache_alloc(
19189 + nx_addr_v4_cachep, GFP_KERNEL);
19191 + if (!IS_ERR(nxa))
19192 + memset(nxa, 0, sizeof(*nxa));
19196 +/* __dealloc_nx_addr_v4() */
19198 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19200 + kmem_cache_free(nx_addr_v4_cachep, nxa);
19203 +/* __dealloc_nx_addr_v4_all() */
19205 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19208 + struct nx_addr_v4 *next = nxa->next;
19210 + __dealloc_nx_addr_v4(nxa);
19216 +#ifdef CONFIG_IPV6
19218 +/* __alloc_nx_addr_v6() */
19220 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19222 + struct nx_addr_v6 *nxa = kmem_cache_alloc(
19223 + nx_addr_v6_cachep, GFP_KERNEL);
19225 + if (!IS_ERR(nxa))
19226 + memset(nxa, 0, sizeof(*nxa));
19230 +/* __dealloc_nx_addr_v6() */
19232 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19234 + kmem_cache_free(nx_addr_v6_cachep, nxa);
19237 +/* __dealloc_nx_addr_v6_all() */
19239 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19242 + struct nx_addr_v6 *next = nxa->next;
19244 + __dealloc_nx_addr_v6(nxa);
19249 +#endif /* CONFIG_IPV6 */
19251 +/* __alloc_nx_info()
19253 + * allocate an initialized nx_info struct
19254 + * doesn't make it visible (hash) */
19256 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19258 + struct nx_info *new = NULL;
19260 + vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19262 + /* would this benefit from a slab cache? */
19263 + new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19267 + memset(new, 0, sizeof(struct nx_info));
19268 + new->nx_id = nid;
19269 + INIT_HLIST_NODE(&new->nx_hlist);
19270 + atomic_set(&new->nx_usecnt, 0);
19271 + atomic_set(&new->nx_tasks, 0);
19272 + spin_lock_init(&new->addr_lock);
19273 + new->nx_state = 0;
19275 + new->nx_flags = NXF_INIT_SET;
19277 + /* rest of init goes here */
19279 + new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19280 + new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19282 + vxdprintk(VXD_CBIT(nid, 0),
19283 + "alloc_nx_info(%d) = %p", nid, new);
19284 + atomic_inc(&nx_global_ctotal);
19288 +/* __dealloc_nx_info()
19290 + * final disposal of nx_info */
19292 +static void __dealloc_nx_info(struct nx_info *nxi)
19294 + vxdprintk(VXD_CBIT(nid, 0),
19295 + "dealloc_nx_info(%p)", nxi);
19297 + nxi->nx_hlist.next = LIST_POISON1;
19300 + BUG_ON(atomic_read(&nxi->nx_usecnt));
19301 + BUG_ON(atomic_read(&nxi->nx_tasks));
19303 + __dealloc_nx_addr_v4_all(nxi->v4.next);
19304 +#ifdef CONFIG_IPV6
19305 + __dealloc_nx_addr_v6_all(nxi->v6.next);
19308 + nxi->nx_state |= NXS_RELEASED;
19310 + atomic_dec(&nx_global_ctotal);
19313 +static void __shutdown_nx_info(struct nx_info *nxi)
19315 + nxi->nx_state |= NXS_SHUTDOWN;
19316 + vs_net_change(nxi, VSC_NETDOWN);
19319 +/* exported stuff */
19321 +void free_nx_info(struct nx_info *nxi)
19323 + /* context shutdown is mandatory */
19324 + BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
19326 + /* context must not be hashed */
19327 + BUG_ON(nxi->nx_state & NXS_HASHED);
19329 + BUG_ON(atomic_read(&nxi->nx_usecnt));
19330 + BUG_ON(atomic_read(&nxi->nx_tasks));
19332 + __dealloc_nx_info(nxi);
19336 +void __nx_set_lback(struct nx_info *nxi)
19338 + int nid = nxi->nx_id;
19339 + __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
19341 + nxi->v4_lback.s_addr = lback;
19344 +extern int __nx_inet_add_lback(__be32 addr);
19345 +extern int __nx_inet_del_lback(__be32 addr);
19348 +/* hash table for nx_info hash */
19350 +#define NX_HASH_SIZE 13
19352 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
19354 +static DEFINE_SPINLOCK(nx_info_hash_lock);
19357 +static inline unsigned int __hashval(vnid_t nid)
19359 + return (nid % NX_HASH_SIZE);
19364 +/* __hash_nx_info()
19366 + * add the nxi to the global hash table
19367 + * requires the hash_lock to be held */
19369 +static inline void __hash_nx_info(struct nx_info *nxi)
19371 + struct hlist_head *head;
19373 + vxd_assert_lock(&nx_info_hash_lock);
19374 + vxdprintk(VXD_CBIT(nid, 4),
19375 + "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
19377 + /* context must not be hashed */
19378 + BUG_ON(nx_info_state(nxi, NXS_HASHED));
19380 + nxi->nx_state |= NXS_HASHED;
19381 + head = &nx_info_hash[__hashval(nxi->nx_id)];
19382 + hlist_add_head(&nxi->nx_hlist, head);
19383 + atomic_inc(&nx_global_cactive);
19386 +/* __unhash_nx_info()
19388 + * remove the nxi from the global hash table
19389 + * requires the hash_lock to be held */
19391 +static inline void __unhash_nx_info(struct nx_info *nxi)
19393 + vxd_assert_lock(&nx_info_hash_lock);
19394 + vxdprintk(VXD_CBIT(nid, 4),
19395 + "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
19396 + atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
19398 + /* context must be hashed */
19399 + BUG_ON(!nx_info_state(nxi, NXS_HASHED));
19400 + /* but without tasks */
19401 + BUG_ON(atomic_read(&nxi->nx_tasks));
19403 + nxi->nx_state &= ~NXS_HASHED;
19404 + hlist_del(&nxi->nx_hlist);
19405 + atomic_dec(&nx_global_cactive);
19409 +/* __lookup_nx_info()
19411 + * requires the hash_lock to be held
19412 + * doesn't increment the nx_refcnt */
19414 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
19416 + struct hlist_head *head = &nx_info_hash[__hashval(nid)];
19417 + struct hlist_node *pos;
19418 + struct nx_info *nxi;
19420 + vxd_assert_lock(&nx_info_hash_lock);
19421 + hlist_for_each(pos, head) {
19422 + nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19424 + if (nxi->nx_id == nid)
19429 + vxdprintk(VXD_CBIT(nid, 0),
19430 + "__lookup_nx_info(#%u): %p[#%u]",
19431 + nid, nxi, nxi ? nxi->nx_id : 0);
19436 +/* __create_nx_info()
19438 + * create the requested context
19439 + * get(), claim() and hash it */
19441 +static struct nx_info *__create_nx_info(int id)
19443 + struct nx_info *new, *nxi = NULL;
19445 + vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
19447 + if (!(new = __alloc_nx_info(id)))
19448 + return ERR_PTR(-ENOMEM);
19450 + /* required to make dynamic xids unique */
19451 + spin_lock(&nx_info_hash_lock);
19453 + /* static context requested */
19454 + if ((nxi = __lookup_nx_info(id))) {
19455 + vxdprintk(VXD_CBIT(nid, 0),
19456 + "create_nx_info(%d) = %p (already there)", id, nxi);
19457 + if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19458 + nxi = ERR_PTR(-EBUSY);
19460 + nxi = ERR_PTR(-EEXIST);
19463 + /* new context */
19464 + vxdprintk(VXD_CBIT(nid, 0),
19465 + "create_nx_info(%d) = %p (new)", id, new);
19466 + claim_nx_info(new, NULL);
19467 + __nx_set_lback(new);
19468 + __hash_nx_info(get_nx_info(new));
19469 + nxi = new, new = NULL;
19472 + spin_unlock(&nx_info_hash_lock);
19474 + __dealloc_nx_info(new);
19480 +/* exported stuff */
19483 +void unhash_nx_info(struct nx_info *nxi)
19485 + __shutdown_nx_info(nxi);
19486 + spin_lock(&nx_info_hash_lock);
19487 + __unhash_nx_info(nxi);
19488 + spin_unlock(&nx_info_hash_lock);
19491 +/* lookup_nx_info()
19493 + * search for a nx_info and get() it
19494 + * negative id means current */
19496 +struct nx_info *lookup_nx_info(int id)
19498 + struct nx_info *nxi = NULL;
19501 + nxi = get_nx_info(current_nx_info());
19502 + } else if (id > 1) {
19503 + spin_lock(&nx_info_hash_lock);
19504 + nxi = get_nx_info(__lookup_nx_info(id));
19505 + spin_unlock(&nx_info_hash_lock);
19510 +/* nid_is_hashed()
19512 + * verify that nid is still hashed */
19514 +int nid_is_hashed(vnid_t nid)
19518 + spin_lock(&nx_info_hash_lock);
19519 + hashed = (__lookup_nx_info(nid) != NULL);
19520 + spin_unlock(&nx_info_hash_lock);
19525 +#ifdef CONFIG_PROC_FS
19529 + * get a subset of hashed nids for proc
19530 + * assumes size is at least one */
19532 +int get_nid_list(int index, unsigned int *nids, int size)
19534 + int hindex, nr_nids = 0;
19536 + /* only show current and children */
19537 + if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
19540 + nids[nr_nids] = nx_current_nid();
19544 + for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
19545 + struct hlist_head *head = &nx_info_hash[hindex];
19546 + struct hlist_node *pos;
19548 + spin_lock(&nx_info_hash_lock);
19549 + hlist_for_each(pos, head) {
19550 + struct nx_info *nxi;
19555 + nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19556 + nids[nr_nids] = nxi->nx_id;
19557 + if (++nr_nids >= size) {
19558 + spin_unlock(&nx_info_hash_lock);
19562 + /* keep the lock time short */
19563 + spin_unlock(&nx_info_hash_lock);
19572 + * migrate task to new network
19573 + * gets nxi, puts old_nxi on change
19576 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
19578 + struct nx_info *old_nxi;
19584 + vxdprintk(VXD_CBIT(nid, 5),
19585 + "nx_migrate_task(%p,%p[#%d.%d.%d])",
19586 + p, nxi, nxi->nx_id,
19587 + atomic_read(&nxi->nx_usecnt),
19588 + atomic_read(&nxi->nx_tasks));
19590 + if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
19591 + !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19594 + if (nx_info_state(nxi, NXS_SHUTDOWN))
19597 + /* maybe disallow this completely? */
19598 + old_nxi = task_get_nx_info(p);
19599 + if (old_nxi == nxi)
19604 + clr_nx_info(&p->nx_info);
19605 + claim_nx_info(nxi, p);
19606 + set_nx_info(&p->nx_info, nxi);
19607 + p->nid = nxi->nx_id;
19610 + vxdprintk(VXD_CBIT(nid, 5),
19611 + "moved task %p into nxi:%p[#%d]",
19612 + p, nxi, nxi->nx_id);
19615 + release_nx_info(old_nxi, p);
19618 + put_nx_info(old_nxi);
19623 +void nx_set_persistent(struct nx_info *nxi)
19625 + vxdprintk(VXD_CBIT(nid, 6),
19626 + "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
19628 + get_nx_info(nxi);
19629 + claim_nx_info(nxi, NULL);
19632 +void nx_clear_persistent(struct nx_info *nxi)
19634 + vxdprintk(VXD_CBIT(nid, 6),
19635 + "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
19637 + release_nx_info(nxi, NULL);
19638 + put_nx_info(nxi);
19641 +void nx_update_persistent(struct nx_info *nxi)
19643 + if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
19644 + nx_set_persistent(nxi);
19646 + nx_clear_persistent(nxi);
19649 +/* vserver syscall commands below here */
19651 +/* taks nid and nx_info functions */
19653 +#include <asm/uaccess.h>
19656 +int vc_task_nid(uint32_t id)
19661 + struct task_struct *tsk;
19664 + tsk = find_task_by_real_pid(id);
19665 + nid = (tsk) ? tsk->nid : -ESRCH;
19666 + rcu_read_unlock();
19668 + nid = nx_current_nid();
19673 +int vc_nx_info(struct nx_info *nxi, void __user *data)
19675 + struct vcmd_nx_info_v0 vc_data;
19677 + vc_data.nid = nxi->nx_id;
19679 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19685 +/* network functions */
19687 +int vc_net_create(uint32_t nid, void __user *data)
19689 + struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
19690 + struct nx_info *new_nxi;
19693 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19696 + if ((nid > MAX_S_CONTEXT) || (nid < 2))
19699 + new_nxi = __create_nx_info(nid);
19700 + if (IS_ERR(new_nxi))
19701 + return PTR_ERR(new_nxi);
19703 + /* initial flags */
19704 + new_nxi->nx_flags = vc_data.flagword;
19707 + if (vs_net_change(new_nxi, VSC_NETUP))
19710 + ret = nx_migrate_task(current, new_nxi);
19714 + /* return context id on success */
19715 + ret = new_nxi->nx_id;
19717 + /* get a reference for persistent contexts */
19718 + if ((vc_data.flagword & NXF_PERSISTENT))
19719 + nx_set_persistent(new_nxi);
19721 + release_nx_info(new_nxi, NULL);
19722 + put_nx_info(new_nxi);
19727 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
19729 + return nx_migrate_task(current, nxi);
19734 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
19735 + __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
19736 + struct nx_addr_v4 **prev)
19738 + struct nx_addr_v4 *nxa = &nxi->v4;
19740 + for (; nxa; nxa = nxa->next) {
19741 + if ((nxa->ip[0].s_addr == ip) &&
19742 + (nxa->ip[1].s_addr == ip2) &&
19743 + (nxa->mask.s_addr == mask) &&
19744 + (nxa->type == type) &&
19745 + (nxa->flags == flags))
19748 + /* save previous entry */
19755 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19756 + uint16_t type, uint16_t flags)
19758 + struct nx_addr_v4 *nxa = NULL;
19759 + struct nx_addr_v4 *new = __alloc_nx_addr_v4();
19760 + unsigned long irqflags;
19761 + int ret = -EEXIST;
19764 + return PTR_ERR(new);
19766 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
19767 + if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
19770 + if (NX_IPV4(nxi)) {
19775 + /* remove single ip for ip list */
19776 + nxi->nx_flags &= ~NXF_SINGLE_IP;
19779 + nxa->ip[0].s_addr = ip;
19780 + nxa->ip[1].s_addr = ip2;
19781 + nxa->mask.s_addr = mask;
19782 + nxa->type = type;
19783 + nxa->flags = flags;
19786 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19788 + __dealloc_nx_addr_v4(new);
19792 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19793 + uint16_t type, uint16_t flags)
19795 + struct nx_addr_v4 *nxa = NULL;
19796 + struct nx_addr_v4 *old = NULL;
19797 + unsigned long irqflags;
19800 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
19802 + case NXA_TYPE_ADDR:
19803 + old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
19806 + nxa->next = old->next;
19807 + old->next = NULL;
19813 + old->next = NULL;
19815 + memset(old, 0, sizeof(*old));
19823 + case NXA_TYPE_ANY:
19826 + memset(nxa, 0, sizeof(*nxa));
19832 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19833 + __dealloc_nx_addr_v4_all(old);
19838 +int vc_net_add(struct nx_info *nxi, void __user *data)
19840 + struct vcmd_net_addr_v0 vc_data;
19841 + int index, ret = 0;
19843 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19846 + switch (vc_data.type) {
19847 + case NXA_TYPE_IPV4:
19848 + if ((vc_data.count < 1) || (vc_data.count > 4))
19852 + while (index < vc_data.count) {
19853 + ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
19854 + vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
19862 + case NXA_TYPE_IPV4|NXA_MOD_BCAST:
19863 + nxi->v4_bcast = vc_data.ip[0];
19867 + case NXA_TYPE_IPV4|NXA_MOD_LBACK:
19868 + nxi->v4_lback = vc_data.ip[0];
19879 +int vc_net_remove(struct nx_info *nxi, void __user *data)
19881 + struct vcmd_net_addr_v0 vc_data;
19883 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19886 + switch (vc_data.type) {
19887 + case NXA_TYPE_ANY:
19888 + return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
19896 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
19898 + struct vcmd_net_addr_ipv4_v1 vc_data;
19900 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19903 + switch (vc_data.type) {
19904 + case NXA_TYPE_ADDR:
19905 + case NXA_TYPE_MASK:
19906 + return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
19907 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19909 + case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19910 + nxi->v4_bcast = vc_data.ip;
19913 + case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19914 + nxi->v4_lback = vc_data.ip;
19923 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
19925 + struct vcmd_net_addr_ipv4_v2 vc_data;
19927 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19930 + switch (vc_data.type) {
19931 + case NXA_TYPE_ADDR:
19932 + case NXA_TYPE_MASK:
19933 + case NXA_TYPE_RANGE:
19934 + return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19935 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19937 + case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19938 + nxi->v4_bcast = vc_data.ip;
19941 + case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19942 + nxi->v4_lback = vc_data.ip;
19951 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
19953 + struct vcmd_net_addr_ipv4_v1 vc_data;
19955 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19958 + return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
19959 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19962 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
19964 + struct vcmd_net_addr_ipv4_v2 vc_data;
19966 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19969 + return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19970 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19973 +#ifdef CONFIG_IPV6
19976 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
19977 + struct in6_addr *ip, struct in6_addr *mask,
19978 + uint32_t prefix, uint16_t type, uint16_t flags,
19979 + struct nx_addr_v6 **prev)
19981 + struct nx_addr_v6 *nxa = &nxi->v6;
19983 + for (; nxa; nxa = nxa->next) {
19984 + if (ipv6_addr_equal(&nxa->ip, ip) &&
19985 + ipv6_addr_equal(&nxa->mask, mask) &&
19986 + (nxa->prefix == prefix) &&
19987 + (nxa->type == type) &&
19988 + (nxa->flags == flags))
19991 + /* save previous entry */
19999 +int do_add_v6_addr(struct nx_info *nxi,
20000 + struct in6_addr *ip, struct in6_addr *mask,
20001 + uint32_t prefix, uint16_t type, uint16_t flags)
20003 + struct nx_addr_v6 *nxa = NULL;
20004 + struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20005 + unsigned long irqflags;
20006 + int ret = -EEXIST;
20009 + return PTR_ERR(new);
20011 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20012 + if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20015 + if (NX_IPV6(nxi)) {
20022 + nxa->mask = *mask;
20023 + nxa->prefix = prefix;
20024 + nxa->type = type;
20025 + nxa->flags = flags;
20028 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20030 + __dealloc_nx_addr_v6(new);
20034 +int do_remove_v6_addr(struct nx_info *nxi,
20035 + struct in6_addr *ip, struct in6_addr *mask,
20036 + uint32_t prefix, uint16_t type, uint16_t flags)
20038 + struct nx_addr_v6 *nxa = NULL;
20039 + struct nx_addr_v6 *old = NULL;
20040 + unsigned long irqflags;
20043 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20045 + case NXA_TYPE_ADDR:
20046 + old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20049 + nxa->next = old->next;
20050 + old->next = NULL;
20056 + old->next = NULL;
20058 + memset(old, 0, sizeof(*old));
20066 + case NXA_TYPE_ANY:
20069 + memset(nxa, 0, sizeof(*nxa));
20075 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20076 + __dealloc_nx_addr_v6_all(old);
20080 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20082 + struct vcmd_net_addr_ipv6_v1 vc_data;
20084 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20087 + switch (vc_data.type) {
20088 + case NXA_TYPE_ADDR:
20089 + memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20090 + /* fallthrough */
20091 + case NXA_TYPE_MASK:
20092 + return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20093 + vc_data.prefix, vc_data.type, vc_data.flags);
20100 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20102 + struct vcmd_net_addr_ipv6_v1 vc_data;
20104 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20107 + switch (vc_data.type) {
20108 + case NXA_TYPE_ADDR:
20109 + memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20110 + /* fallthrough */
20111 + case NXA_TYPE_MASK:
20112 + return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20113 + vc_data.prefix, vc_data.type, vc_data.flags);
20114 + case NXA_TYPE_ANY:
20115 + return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20122 +#endif /* CONFIG_IPV6 */
20125 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20127 + struct vcmd_net_flags_v0 vc_data;
20129 + vc_data.flagword = nxi->nx_flags;
20131 + /* special STATE flag handling */
20132 + vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20134 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20139 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20141 + struct vcmd_net_flags_v0 vc_data;
20142 + uint64_t mask, trigger;
20144 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20147 + /* special STATE flag handling */
20148 + mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20149 + trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20151 + nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20152 + vc_data.flagword, mask);
20153 + if (trigger & NXF_PERSISTENT)
20154 + nx_update_persistent(nxi);
20159 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20161 + struct vcmd_net_caps_v0 vc_data;
20163 + vc_data.ncaps = nxi->nx_ncaps;
20164 + vc_data.cmask = ~0ULL;
20166 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20171 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20173 + struct vcmd_net_caps_v0 vc_data;
20175 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20178 + nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20179 + vc_data.ncaps, vc_data.cmask);
20184 +#include <linux/module.h>
20186 +module_init(init_network);
20188 +EXPORT_SYMBOL_GPL(free_nx_info);
20189 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20191 diff -NurpP --minimal linux-3.13.10/kernel/vserver/proc.c linux-3.13.10-vs2.3.6.11/kernel/vserver/proc.c
20192 --- linux-3.13.10/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
20193 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/proc.c 2014-02-01 01:21:49.000000000 +0000
20196 + * linux/kernel/vserver/proc.c
20198 + * Virtual Context Support
20200 + * Copyright (C) 2003-2011 Herbert Pötzl
20202 + * V0.01 basic structure
20203 + * V0.02 adaptation vs1.3.0
20204 + * V0.03 proc permissions
20205 + * V0.04 locking/generic
20206 + * V0.05 next generation procfs
20207 + * V0.06 inode validation
20208 + * V0.07 generic rewrite vid
20209 + * V0.08 remove inode type
20210 + * V0.09 added u/wmask info
20214 +#include <linux/proc_fs.h>
20215 +#include <linux/fs_struct.h>
20216 +#include <linux/mount.h>
20217 +#include <linux/namei.h>
20218 +#include <asm/unistd.h>
20220 +#include <linux/vs_context.h>
20221 +#include <linux/vs_network.h>
20222 +#include <linux/vs_cvirt.h>
20224 +#include <linux/in.h>
20225 +#include <linux/inetdevice.h>
20226 +#include <linux/vs_inet.h>
20227 +#include <linux/vs_inet6.h>
20229 +#include <linux/vserver/global.h>
20231 +#include "cvirt_proc.h"
20232 +#include "cacct_proc.h"
20233 +#include "limit_proc.h"
20234 +#include "sched_proc.h"
20235 +#include "vci_config.h"
20237 +#include <../../fs/proc/internal.h>
20240 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20244 + CAP_FOR_EACH_U32(__capi) {
20245 + buffer += sprintf(buffer, "%08x",
20246 + c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20252 +static struct proc_dir_entry *proc_virtual;
20254 +static struct proc_dir_entry *proc_virtnet;
20257 +/* first the actual feeds */
20260 +static int proc_vci(char *buffer)
20262 + return sprintf(buffer,
20263 + "VCIVersion:\t%04x:%04x\n"
20264 + "VCISyscall:\t%d\n"
20265 + "VCIKernel:\t%08x\n",
20266 + VCI_VERSION >> 16,
20267 + VCI_VERSION & 0xFFFF,
20269 + vci_kernel_config());
20272 +static int proc_virtual_info(char *buffer)
20274 + return proc_vci(buffer);
20277 +static int proc_virtual_status(char *buffer)
20279 + return sprintf(buffer,
20281 + "#CActive:\t%d\n"
20282 + "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20283 + "#InitTask:\t%d\t%d %d\n",
20284 + atomic_read(&vx_global_ctotal),
20285 + atomic_read(&vx_global_cactive),
20286 + atomic_read(&vs_global_nsproxy),
20287 + atomic_read(&vs_global_fs),
20288 + atomic_read(&vs_global_mnt_ns),
20289 + atomic_read(&vs_global_uts_ns),
20290 + atomic_read(&nr_ipc_ns),
20291 + atomic_read(&vs_global_user_ns),
20292 + atomic_read(&vs_global_pid_ns),
20293 + atomic_read(&init_task.usage),
20294 + atomic_read(&init_task.nsproxy->count),
20295 + init_task.fs->users);
20299 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20303 + length = sprintf(buffer,
20311 + vxi->vx_badness_bias);
20315 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
20317 + char *orig = buffer;
20319 + buffer += sprintf(buffer,
20322 + "Flags:\t%016llx\n",
20323 + atomic_read(&vxi->vx_usecnt),
20324 + atomic_read(&vxi->vx_tasks),
20325 + (unsigned long long)vxi->vx_flags);
20327 + buffer += sprintf(buffer, "BCaps:\t");
20328 + buffer = print_cap_t(buffer, &vxi->vx_bcaps);
20329 + buffer += sprintf(buffer, "\n");
20331 + buffer += sprintf(buffer,
20332 + "CCaps:\t%016llx\n"
20333 + "Umask:\t%16llx\n"
20334 + "Wmask:\t%16llx\n"
20335 + "Spaces:\t%08lx %08lx\n",
20336 + (unsigned long long)vxi->vx_ccaps,
20337 + (unsigned long long)vxi->vx_umask,
20338 + (unsigned long long)vxi->vx_wmask,
20339 + vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
20340 + return buffer - orig;
20343 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
20345 + return vx_info_proc_limit(&vxi->limit, buffer);
20348 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
20352 + length = vx_info_proc_sched(&vxi->sched, buffer);
20353 + for_each_online_cpu(cpu) {
20354 + length += vx_info_proc_sched_pc(
20355 + &vx_per_cpu(vxi, sched_pc, cpu),
20356 + buffer + length, cpu);
20361 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
20363 + return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
20366 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
20368 + return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
20371 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
20375 + vx_update_load(vxi);
20376 + length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
20377 + for_each_online_cpu(cpu) {
20378 + length += vx_info_proc_cvirt_pc(
20379 + &vx_per_cpu(vxi, cvirt_pc, cpu),
20380 + buffer + length, cpu);
20385 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
20387 + return vx_info_proc_cacct(&vxi->cacct, buffer);
20391 +static int proc_virtnet_info(char *buffer)
20393 + return proc_vci(buffer);
20396 +static int proc_virtnet_status(char *buffer)
20398 + return sprintf(buffer,
20400 + "#CActive:\t%d\n",
20401 + atomic_read(&nx_global_ctotal),
20402 + atomic_read(&nx_global_cactive));
20405 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
20407 + struct nx_addr_v4 *v4a;
20408 +#ifdef CONFIG_IPV6
20409 + struct nx_addr_v6 *v6a;
20413 + length = sprintf(buffer,
20416 + "Bcast:\t" NIPQUAD_FMT "\n"
20417 + "Lback:\t" NIPQUAD_FMT "\n",
20420 + NIPQUAD(nxi->v4_bcast.s_addr),
20421 + NIPQUAD(nxi->v4_lback.s_addr));
20423 + if (!NX_IPV4(nxi))
20425 + for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20426 + length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
20429 +#ifdef CONFIG_IPV6
20430 + if (!NX_IPV6(nxi))
20432 + for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20433 + length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
20440 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
20444 + length = sprintf(buffer,
20447 + "Flags:\t%016llx\n"
20448 + "NCaps:\t%016llx\n",
20449 + atomic_read(&nxi->nx_usecnt),
20450 + atomic_read(&nxi->nx_tasks),
20451 + (unsigned long long)nxi->nx_flags,
20452 + (unsigned long long)nxi->nx_ncaps);
20458 +/* here the inode helpers */
20464 + struct inode_operations *iop;
20465 + struct file_operations *fop;
20466 + union proc_op op;
20469 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
20471 + struct inode *inode = new_inode(sb);
20476 + inode->i_mode = p->mode;
20478 + inode->i_op = p->iop;
20480 + inode->i_fop = p->fop;
20482 + set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
20483 + inode->i_flags |= S_IMMUTABLE;
20485 + inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
20487 + i_uid_write(inode, 0);
20488 + i_gid_write(inode, 0);
20489 + i_tag_write(inode, 0);
20494 +static struct dentry *vs_proc_instantiate(struct inode *dir,
20495 + struct dentry *dentry, int id, void *ptr)
20497 + struct vs_entry *p = ptr;
20498 + struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
20499 + struct dentry *error = ERR_PTR(-EINVAL);
20504 + PROC_I(inode)->op = p->op;
20505 + PROC_I(inode)->fd = id;
20506 + d_add(dentry, inode);
20514 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
20518 + * Fill a directory entry.
20520 + * If possible create the dcache entry and derive our inode number and
20521 + * file type from dcache entry.
20523 + * Since all of the proc inode numbers are dynamically generated, the inode
20524 + * numbers do not exist until the inode is cache. This means creating the
20525 + * the dcache entry in iterate is necessary to keep the inode numbers
20526 + * reported by iterate in sync with the inode numbers reported
20529 +static int vx_proc_fill_cache(struct file *filp, struct dir_context *ctx,
20530 + char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
20532 + struct dentry *child, *dir = filp->f_dentry;
20533 + struct inode *inode;
20534 + struct qstr qname;
20536 + unsigned type = DT_UNKNOWN;
20538 + qname.name = name;
20540 + qname.hash = full_name_hash(name, len);
20542 + child = d_lookup(dir, &qname);
20544 + struct dentry *new;
20545 + new = d_alloc(dir, &qname);
20547 + child = instantiate(dir->d_inode, new, id, ptr);
20554 + if (!child || IS_ERR(child) || !child->d_inode)
20555 + goto end_instantiate;
20556 + inode = child->d_inode;
20558 + ino = inode->i_ino;
20559 + type = inode->i_mode >> 12;
20565 + return !dir_emit(ctx, name, len, ino, type);
20570 +/* get and revalidate vx_info/xid */
20573 +struct vx_info *get_proc_vx_info(struct inode *inode)
20575 + return lookup_vx_info(PROC_I(inode)->fd);
20578 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
20580 + struct inode *inode = dentry->d_inode;
20581 + vxid_t xid = PROC_I(inode)->fd;
20583 + if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20586 + if (!xid || xid_is_hashed(xid))
20593 +/* get and revalidate nx_info/nid */
20595 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
20597 + struct inode *inode = dentry->d_inode;
20598 + vnid_t nid = PROC_I(inode)->fd;
20600 + if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20603 + if (!nid || nid_is_hashed(nid))
20611 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
20613 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
20614 + size_t count, loff_t *ppos)
20616 + struct inode *inode = file->f_dentry->d_inode;
20617 + unsigned long page;
20618 + ssize_t length = 0;
20620 + if (count > PROC_BLOCK_SIZE)
20621 + count = PROC_BLOCK_SIZE;
20623 + /* fade that out as soon as stable */
20624 + WARN_ON(PROC_I(inode)->fd);
20626 + if (!(page = __get_free_page(GFP_KERNEL)))
20629 + BUG_ON(!PROC_I(inode)->op.proc_vs_read);
20630 + length = PROC_I(inode)->op.proc_vs_read((char *)page);
20633 + length = simple_read_from_buffer(buf, count, ppos,
20634 + (char *)page, length);
20640 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
20641 + size_t count, loff_t *ppos)
20643 + struct inode *inode = file->f_dentry->d_inode;
20644 + struct vx_info *vxi = NULL;
20645 + vxid_t xid = PROC_I(inode)->fd;
20646 + unsigned long page;
20647 + ssize_t length = 0;
20649 + if (count > PROC_BLOCK_SIZE)
20650 + count = PROC_BLOCK_SIZE;
20652 + /* fade that out as soon as stable */
20654 + vxi = lookup_vx_info(xid);
20658 + length = -ENOMEM;
20659 + if (!(page = __get_free_page(GFP_KERNEL)))
20662 + BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
20663 + length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
20666 + length = simple_read_from_buffer(buf, count, ppos,
20667 + (char *)page, length);
20671 + put_vx_info(vxi);
20676 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
20677 + size_t count, loff_t *ppos)
20679 + struct inode *inode = file->f_dentry->d_inode;
20680 + struct nx_info *nxi = NULL;
20681 + vnid_t nid = PROC_I(inode)->fd;
20682 + unsigned long page;
20683 + ssize_t length = 0;
20685 + if (count > PROC_BLOCK_SIZE)
20686 + count = PROC_BLOCK_SIZE;
20688 + /* fade that out as soon as stable */
20690 + nxi = lookup_nx_info(nid);
20694 + length = -ENOMEM;
20695 + if (!(page = __get_free_page(GFP_KERNEL)))
20698 + BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
20699 + length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
20702 + length = simple_read_from_buffer(buf, count, ppos,
20703 + (char *)page, length);
20707 + put_nx_info(nxi);
20714 +/* here comes the lower level */
20717 +#define NOD(NAME, MODE, IOP, FOP, OP) { \
20718 + .len = sizeof(NAME) - 1, \
20719 + .name = (NAME), \
20727 +#define DIR(NAME, MODE, OTYPE) \
20728 + NOD(NAME, (S_IFDIR | (MODE)), \
20729 + &proc_ ## OTYPE ## _inode_operations, \
20730 + &proc_ ## OTYPE ## _file_operations, { } )
20732 +#define INF(NAME, MODE, OTYPE) \
20733 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
20734 + &proc_vs_info_file_operations, \
20735 + { .proc_vs_read = &proc_##OTYPE } )
20737 +#define VINF(NAME, MODE, OTYPE) \
20738 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
20739 + &proc_vx_info_file_operations, \
20740 + { .proc_vxi_read = &proc_##OTYPE } )
20742 +#define NINF(NAME, MODE, OTYPE) \
20743 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
20744 + &proc_nx_info_file_operations, \
20745 + { .proc_nxi_read = &proc_##OTYPE } )
20748 +static struct file_operations proc_vs_info_file_operations = {
20749 + .read = proc_vs_info_read,
20752 +static struct file_operations proc_vx_info_file_operations = {
20753 + .read = proc_vx_info_read,
20756 +static struct dentry_operations proc_xid_dentry_operations = {
20757 + .d_revalidate = proc_xid_revalidate,
20760 +static struct vs_entry vx_base_stuff[] = {
20761 + VINF("info", S_IRUGO, vxi_info),
20762 + VINF("status", S_IRUGO, vxi_status),
20763 + VINF("limit", S_IRUGO, vxi_limit),
20764 + VINF("sched", S_IRUGO, vxi_sched),
20765 + VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
20766 + VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
20767 + VINF("cvirt", S_IRUGO, vxi_cvirt),
20768 + VINF("cacct", S_IRUGO, vxi_cacct),
20775 +static struct dentry *proc_xid_instantiate(struct inode *dir,
20776 + struct dentry *dentry, int id, void *ptr)
20778 + dentry->d_op = &proc_xid_dentry_operations;
20779 + return vs_proc_instantiate(dir, dentry, id, ptr);
20782 +static struct dentry *proc_xid_lookup(struct inode *dir,
20783 + struct dentry *dentry, unsigned int flags)
20785 + struct vs_entry *p = vx_base_stuff;
20786 + struct dentry *error = ERR_PTR(-ENOENT);
20788 + for (; p->name; p++) {
20789 + if (p->len != dentry->d_name.len)
20791 + if (!memcmp(dentry->d_name.name, p->name, p->len))
20797 + error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20802 +static int proc_xid_iterate(struct file *filp, struct dir_context *ctx)
20804 + struct dentry *dentry = filp->f_dentry;
20805 + struct inode *inode = dentry->d_inode;
20806 + struct vs_entry *p = vx_base_stuff;
20807 + int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
20811 + switch (ctx->pos) {
20813 + ino = inode->i_ino;
20814 + if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20817 + /* fall through */
20819 + ino = parent_ino(dentry);
20820 + if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20823 + /* fall through */
20825 + index = ctx->pos - 2;
20826 + if (index >= size)
20828 + for (p += index; p->name; p++) {
20829 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20830 + vs_proc_instantiate, PROC_I(inode)->fd, p))
20841 +static struct file_operations proc_nx_info_file_operations = {
20842 + .read = proc_nx_info_read,
20845 +static struct dentry_operations proc_nid_dentry_operations = {
20846 + .d_revalidate = proc_nid_revalidate,
20849 +static struct vs_entry nx_base_stuff[] = {
20850 + NINF("info", S_IRUGO, nxi_info),
20851 + NINF("status", S_IRUGO, nxi_status),
20856 +static struct dentry *proc_nid_instantiate(struct inode *dir,
20857 + struct dentry *dentry, int id, void *ptr)
20859 + dentry->d_op = &proc_nid_dentry_operations;
20860 + return vs_proc_instantiate(dir, dentry, id, ptr);
20863 +static struct dentry *proc_nid_lookup(struct inode *dir,
20864 + struct dentry *dentry, unsigned int flags)
20866 + struct vs_entry *p = nx_base_stuff;
20867 + struct dentry *error = ERR_PTR(-ENOENT);
20869 + for (; p->name; p++) {
20870 + if (p->len != dentry->d_name.len)
20872 + if (!memcmp(dentry->d_name.name, p->name, p->len))
20878 + error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20883 +static int proc_nid_iterate(struct file *filp, struct dir_context *ctx)
20885 + struct dentry *dentry = filp->f_dentry;
20886 + struct inode *inode = dentry->d_inode;
20887 + struct vs_entry *p = nx_base_stuff;
20888 + int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
20892 + switch (ctx->pos) {
20894 + ino = inode->i_ino;
20895 + if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20898 + /* fall through */
20900 + ino = parent_ino(dentry);
20901 + if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20904 + /* fall through */
20906 + index = ctx->pos - 2;
20907 + if (index >= size)
20909 + for (p += index; p->name; p++) {
20910 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20911 + vs_proc_instantiate, PROC_I(inode)->fd, p))
20921 +#define MAX_MULBY10 ((~0U - 9) / 10)
20923 +static inline int atovid(const char *str, int len)
20928 + while (len-- > 0) {
20933 + if (vid >= MAX_MULBY10)
20943 +/* now the upper level (virtual) */
20946 +static struct file_operations proc_xid_file_operations = {
20947 + .read = generic_read_dir,
20948 + .iterate = proc_xid_iterate,
20951 +static struct inode_operations proc_xid_inode_operations = {
20952 + .lookup = proc_xid_lookup,
20955 +static struct vs_entry vx_virtual_stuff[] = {
20956 + INF("info", S_IRUGO, virtual_info),
20957 + INF("status", S_IRUGO, virtual_status),
20958 + DIR(NULL, S_IRUGO | S_IXUGO, xid),
20962 +static struct dentry *proc_virtual_lookup(struct inode *dir,
20963 + struct dentry *dentry, unsigned int flags)
20965 + struct vs_entry *p = vx_virtual_stuff;
20966 + struct dentry *error = ERR_PTR(-ENOENT);
20969 + for (; p->name; p++) {
20970 + if (p->len != dentry->d_name.len)
20972 + if (!memcmp(dentry->d_name.name, p->name, p->len))
20976 + goto instantiate;
20978 + id = atovid(dentry->d_name.name, dentry->d_name.len);
20979 + if ((id < 0) || !xid_is_hashed(id))
20983 + error = proc_xid_instantiate(dir, dentry, id, p);
20988 +static struct file_operations proc_nid_file_operations = {
20989 + .read = generic_read_dir,
20990 + .iterate = proc_nid_iterate,
20993 +static struct inode_operations proc_nid_inode_operations = {
20994 + .lookup = proc_nid_lookup,
20997 +static struct vs_entry nx_virtnet_stuff[] = {
20998 + INF("info", S_IRUGO, virtnet_info),
20999 + INF("status", S_IRUGO, virtnet_status),
21000 + DIR(NULL, S_IRUGO | S_IXUGO, nid),
21004 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21005 + struct dentry *dentry, unsigned int flags)
21007 + struct vs_entry *p = nx_virtnet_stuff;
21008 + struct dentry *error = ERR_PTR(-ENOENT);
21011 + for (; p->name; p++) {
21012 + if (p->len != dentry->d_name.len)
21014 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21018 + goto instantiate;
21020 + id = atovid(dentry->d_name.name, dentry->d_name.len);
21021 + if ((id < 0) || !nid_is_hashed(id))
21025 + error = proc_nid_instantiate(dir, dentry, id, p);
21031 +#define PROC_MAXVIDS 32
21033 +int proc_virtual_iterate(struct file *filp, struct dir_context *ctx)
21035 + struct dentry *dentry = filp->f_dentry;
21036 + struct inode *inode = dentry->d_inode;
21037 + struct vs_entry *p = vx_virtual_stuff;
21038 + int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21040 + unsigned int xid_array[PROC_MAXVIDS];
21041 + char buf[PROC_NUMBUF];
21042 + unsigned int nr_xids, i;
21045 + switch (ctx->pos) {
21047 + ino = inode->i_ino;
21048 + if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21051 + /* fall through */
21053 + ino = parent_ino(dentry);
21054 + if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21057 + /* fall through */
21059 + index = ctx->pos - 2;
21060 + if (index >= size)
21062 + for (p += index; p->name; p++) {
21063 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21064 + vs_proc_instantiate, 0, p))
21069 + index = ctx->pos - size;
21070 + p = &vx_virtual_stuff[size - 1];
21071 + nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21072 + for (i = 0; i < nr_xids; i++) {
21073 + int n, xid = xid_array[i];
21074 + unsigned int j = PROC_NUMBUF;
21078 + buf[--j] = '0' + (n % 10);
21081 + if (vx_proc_fill_cache(filp, ctx,
21082 + buf + j, PROC_NUMBUF - j,
21083 + vs_proc_instantiate, xid, p))
21092 +static int proc_virtual_getattr(struct vfsmount *mnt,
21093 + struct dentry *dentry, struct kstat *stat)
21095 + struct inode *inode = dentry->d_inode;
21097 + generic_fillattr(inode, stat);
21098 + stat->nlink = 2 + atomic_read(&vx_global_cactive);
21102 +static struct file_operations proc_virtual_dir_operations = {
21103 + .read = generic_read_dir,
21104 + .iterate = proc_virtual_iterate,
21107 +static struct inode_operations proc_virtual_dir_inode_operations = {
21108 + .getattr = proc_virtual_getattr,
21109 + .lookup = proc_virtual_lookup,
21114 +int proc_virtnet_iterate(struct file *filp, struct dir_context *ctx)
21116 + struct dentry *dentry = filp->f_dentry;
21117 + struct inode *inode = dentry->d_inode;
21118 + struct vs_entry *p = nx_virtnet_stuff;
21119 + int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21121 + unsigned int nid_array[PROC_MAXVIDS];
21122 + char buf[PROC_NUMBUF];
21123 + unsigned int nr_nids, i;
21126 + switch (ctx->pos) {
21128 + ino = inode->i_ino;
21129 + if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21132 + /* fall through */
21134 + ino = parent_ino(dentry);
21135 + if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21138 + /* fall through */
21140 + index = ctx->pos - 2;
21141 + if (index >= size)
21143 + for (p += index; p->name; p++) {
21144 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21145 + vs_proc_instantiate, 0, p))
21150 + index = ctx->pos - size;
21151 + p = &nx_virtnet_stuff[size - 1];
21152 + nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21153 + for (i = 0; i < nr_nids; i++) {
21154 + int n, nid = nid_array[i];
21155 + unsigned int j = PROC_NUMBUF;
21159 + buf[--j] = '0' + (n % 10);
21162 + if (vx_proc_fill_cache(filp, ctx,
21163 + buf + j, PROC_NUMBUF - j,
21164 + vs_proc_instantiate, nid, p))
21173 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21174 + struct dentry *dentry, struct kstat *stat)
21176 + struct inode *inode = dentry->d_inode;
21178 + generic_fillattr(inode, stat);
21179 + stat->nlink = 2 + atomic_read(&nx_global_cactive);
21183 +static struct file_operations proc_virtnet_dir_operations = {
21184 + .read = generic_read_dir,
21185 + .iterate = proc_virtnet_iterate,
21188 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21189 + .getattr = proc_virtnet_getattr,
21190 + .lookup = proc_virtnet_lookup,
21195 +void proc_vx_init(void)
21197 + struct proc_dir_entry *ent;
21199 + ent = proc_mkdir("virtual", 0);
21201 + ent->proc_fops = &proc_virtual_dir_operations;
21202 + ent->proc_iops = &proc_virtual_dir_inode_operations;
21204 + proc_virtual = ent;
21206 + ent = proc_mkdir("virtnet", 0);
21208 + ent->proc_fops = &proc_virtnet_dir_operations;
21209 + ent->proc_iops = &proc_virtnet_dir_inode_operations;
21211 + proc_virtnet = ent;
21217 +/* per pid info */
21220 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21222 + struct vx_info *vxi;
21223 + char *orig = buffer;
21225 + buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21227 + vxi = task_get_vx_info(p);
21231 + buffer += sprintf(buffer, "BCaps:\t");
21232 + buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21233 + buffer += sprintf(buffer, "\n");
21234 + buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21235 + (unsigned long long)vxi->vx_ccaps);
21236 + buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21237 + (unsigned long long)vxi->vx_flags);
21238 + buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21240 + put_vx_info(vxi);
21242 + return buffer - orig;
21246 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21248 + struct nx_info *nxi;
21249 + struct nx_addr_v4 *v4a;
21250 +#ifdef CONFIG_IPV6
21251 + struct nx_addr_v6 *v6a;
21253 + char *orig = buffer;
21256 + buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21258 + nxi = task_get_nx_info(p);
21262 + buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21263 + (unsigned long long)nxi->nx_ncaps);
21264 + buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21265 + (unsigned long long)nxi->nx_flags);
21267 + buffer += sprintf(buffer,
21268 + "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21269 + NIPQUAD(nxi->v4_bcast.s_addr));
21270 + buffer += sprintf (buffer,
21271 + "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21272 + NIPQUAD(nxi->v4_lback.s_addr));
21273 + if (!NX_IPV4(nxi))
21275 + for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21276 + buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21279 +#ifdef CONFIG_IPV6
21280 + if (!NX_IPV6(nxi))
21282 + for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21283 + buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
21287 + put_nx_info(nxi);
21289 + return buffer - orig;
21292 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sched.c linux-3.13.10-vs2.3.6.11/kernel/vserver/sched.c
21293 --- linux-3.13.10/kernel/vserver/sched.c 1970-01-01 00:00:00.000000000 +0000
21294 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched.c 2014-01-31 20:38:04.000000000 +0000
21297 + * linux/kernel/vserver/sched.c
21299 + * Virtual Server: Scheduler Support
21301 + * Copyright (C) 2004-2010 Herbert Pötzl
21303 + * V0.01 adapted Sam Vilains version to 2.6.3
21304 + * V0.02 removed legacy interface
21305 + * V0.03 changed vcmds to vxi arg
21306 + * V0.04 removed older and legacy interfaces
21307 + * V0.05 removed scheduler code/commands
21311 +#include <linux/vs_context.h>
21312 +#include <linux/vs_sched.h>
21313 +#include <linux/cpumask.h>
21314 +#include <linux/vserver/sched_cmd.h>
21316 +#include <asm/uaccess.h>
21319 +void vx_update_sched_param(struct _vx_sched *sched,
21320 + struct _vx_sched_pc *sched_pc)
21322 + sched_pc->prio_bias = sched->prio_bias;
21325 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
21329 + if (data->prio_bias > MAX_PRIO_BIAS)
21330 + data->prio_bias = MAX_PRIO_BIAS;
21331 + if (data->prio_bias < MIN_PRIO_BIAS)
21332 + data->prio_bias = MIN_PRIO_BIAS;
21334 + if (data->cpu_id != ~0) {
21335 + vxi->sched.update = cpumask_of_cpu(data->cpu_id);
21336 + cpumask_and(&vxi->sched.update, &vxi->sched.update,
21337 + cpu_online_mask);
21339 + cpumask_copy(&vxi->sched.update, cpu_online_mask);
21341 + for_each_cpu_mask(cpu, vxi->sched.update)
21342 + vx_update_sched_param(&vxi->sched,
21343 + &vx_per_cpu(vxi, sched_pc, cpu));
21347 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
21349 + struct vcmd_prio_bias vc_data;
21351 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21354 + return do_set_prio_bias(vxi, &vc_data);
21357 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
21359 + struct vcmd_prio_bias vc_data;
21360 + struct _vx_sched_pc *pcd;
21363 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21366 + cpu = vc_data.cpu_id;
21368 + if (!cpu_possible(cpu))
21371 + pcd = &vx_per_cpu(vxi, sched_pc, cpu);
21372 + vc_data.prio_bias = pcd->prio_bias;
21374 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21379 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sched_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_init.h
21380 --- linux-3.13.10/kernel/vserver/sched_init.h 1970-01-01 00:00:00.000000000 +0000
21381 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_init.h 2014-01-31 20:38:04.000000000 +0000
21384 +static inline void vx_info_init_sched(struct _vx_sched *sched)
21386 + /* scheduling; hard code starting values as constants */
21387 + sched->prio_bias = 0;
21391 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21393 + sched_pc->prio_bias = 0;
21395 + sched_pc->user_ticks = 0;
21396 + sched_pc->sys_ticks = 0;
21397 + sched_pc->hold_ticks = 0;
21400 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
21406 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21410 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sched_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_proc.h
21411 --- linux-3.13.10/kernel/vserver/sched_proc.h 1970-01-01 00:00:00.000000000 +0000
21412 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_proc.h 2014-01-31 20:38:04.000000000 +0000
21414 +#ifndef _VX_SCHED_PROC_H
21415 +#define _VX_SCHED_PROC_H
21419 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
21423 + length += sprintf(buffer,
21424 + "PrioBias:\t%8d\n",
21425 + sched->prio_bias);
21430 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
21431 + char *buffer, int cpu)
21435 + length += sprintf(buffer + length,
21436 + "cpu %d: %lld %lld %lld", cpu,
21437 + (unsigned long long)sched_pc->user_ticks,
21438 + (unsigned long long)sched_pc->sys_ticks,
21439 + (unsigned long long)sched_pc->hold_ticks);
21440 + length += sprintf(buffer + length,
21441 + " %d\n", sched_pc->prio_bias);
21445 +#endif /* _VX_SCHED_PROC_H */
21446 diff -NurpP --minimal linux-3.13.10/kernel/vserver/signal.c linux-3.13.10-vs2.3.6.11/kernel/vserver/signal.c
21447 --- linux-3.13.10/kernel/vserver/signal.c 1970-01-01 00:00:00.000000000 +0000
21448 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/signal.c 2014-01-31 20:38:04.000000000 +0000
21451 + * linux/kernel/vserver/signal.c
21453 + * Virtual Server: Signal Support
21455 + * Copyright (C) 2003-2007 Herbert Pötzl
21457 + * V0.01 broken out from vcontext V0.05
21458 + * V0.02 changed vcmds to vxi arg
21459 + * V0.03 adjusted siginfo for kill
21463 +#include <asm/uaccess.h>
21465 +#include <linux/vs_context.h>
21466 +#include <linux/vs_pid.h>
21467 +#include <linux/vserver/signal_cmd.h>
21470 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
21472 + int retval, count = 0;
21473 + struct task_struct *p;
21474 + struct siginfo *sip = SEND_SIG_PRIV;
21477 + vxdprintk(VXD_CBIT(misc, 4),
21478 + "vx_info_kill(%p[#%d],%d,%d)*",
21479 + vxi, vxi->vx_id, pid, sig);
21480 + read_lock(&tasklist_lock);
21484 + for_each_process(p) {
21487 + if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
21488 + (pid && vxi->vx_initpid == p->pid))
21491 + err = group_send_sig_info(sig, sip, p);
21493 + if (err != -EPERM)
21499 + if (vxi->vx_initpid) {
21500 + pid = vxi->vx_initpid;
21501 + /* for now, only SIGINT to private init ... */
21502 + if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21503 + /* ... as long as there are tasks left */
21504 + (atomic_read(&vxi->vx_tasks) > 1))
21507 + /* fallthrough */
21510 + p = find_task_by_real_pid(pid);
21511 + rcu_read_unlock();
21513 + if (vx_task_xid(p) == vxi->vx_id)
21514 + retval = group_send_sig_info(sig, sip, p);
21518 + read_unlock(&tasklist_lock);
21519 + vxdprintk(VXD_CBIT(misc, 4),
21520 + "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
21521 + vxi, vxi->vx_id, pid, sig, (long)sip, retval);
21525 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
21527 + struct vcmd_ctx_kill_v0 vc_data;
21529 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21532 + /* special check to allow guest shutdown */
21533 + if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21534 + /* forbid killall pid=0 when init is present */
21535 + (((vc_data.pid < 1) && vxi->vx_initpid) ||
21536 + (vc_data.pid > 1)))
21539 + return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
21543 +static int __wait_exit(struct vx_info *vxi)
21545 + DECLARE_WAITQUEUE(wait, current);
21548 + add_wait_queue(&vxi->vx_wait, &wait);
21549 + set_current_state(TASK_INTERRUPTIBLE);
21552 + if (vx_info_state(vxi,
21553 + VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
21555 + if (signal_pending(current)) {
21556 + ret = -ERESTARTSYS;
21563 + set_current_state(TASK_RUNNING);
21564 + remove_wait_queue(&vxi->vx_wait, &wait);
21570 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
21572 + struct vcmd_wait_exit_v0 vc_data;
21575 + ret = __wait_exit(vxi);
21576 + vc_data.reboot_cmd = vxi->reboot_cmd;
21577 + vc_data.exit_code = vxi->exit_code;
21579 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21584 diff -NurpP --minimal linux-3.13.10/kernel/vserver/space.c linux-3.13.10-vs2.3.6.11/kernel/vserver/space.c
21585 --- linux-3.13.10/kernel/vserver/space.c 1970-01-01 00:00:00.000000000 +0000
21586 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/space.c 2014-02-01 12:21:24.000000000 +0000
21589 + * linux/kernel/vserver/space.c
21591 + * Virtual Server: Context Space Support
21593 + * Copyright (C) 2003-2010 Herbert Pötzl
21595 + * V0.01 broken out from context.c 0.07
21596 + * V0.02 added task locking for namespace
21597 + * V0.03 broken out vx_enter_namespace
21598 + * V0.04 added *space support and commands
21599 + * V0.05 added credential support
21603 +#include <linux/utsname.h>
21604 +#include <linux/nsproxy.h>
21605 +#include <linux/err.h>
21606 +#include <linux/fs_struct.h>
21607 +#include <linux/cred.h>
21608 +#include <asm/uaccess.h>
21610 +#include <linux/vs_context.h>
21611 +#include <linux/vserver/space.h>
21612 +#include <linux/vserver/space_cmd.h>
21614 +atomic_t vs_global_nsproxy = ATOMIC_INIT(0);
21615 +atomic_t vs_global_fs = ATOMIC_INIT(0);
21616 +atomic_t vs_global_mnt_ns = ATOMIC_INIT(0);
21617 +atomic_t vs_global_uts_ns = ATOMIC_INIT(0);
21618 +atomic_t vs_global_user_ns = ATOMIC_INIT(0);
21619 +atomic_t vs_global_pid_ns = ATOMIC_INIT(0);
21622 +/* namespace functions */
21624 +#include <linux/mnt_namespace.h>
21625 +#include <linux/user_namespace.h>
21626 +#include <linux/pid_namespace.h>
21627 +#include <linux/ipc_namespace.h>
21628 +#include <net/net_namespace.h>
21629 +#include "../fs/mount.h"
21632 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
21633 + .mask = CLONE_FS |
21635 +#ifdef CONFIG_UTS_NS
21638 +#ifdef CONFIG_IPC_NS
21641 +#ifdef CONFIG_USER_NS
21647 +static const struct vcmd_space_mask_v1 space_mask = {
21648 + .mask = CLONE_FS |
21650 +#ifdef CONFIG_UTS_NS
21653 +#ifdef CONFIG_IPC_NS
21656 +#ifdef CONFIG_USER_NS
21659 +#ifdef CONFIG_PID_NS
21662 +#ifdef CONFIG_NET_NS
21668 +static const struct vcmd_space_mask_v1 default_space_mask = {
21669 + .mask = CLONE_FS |
21671 +#ifdef CONFIG_UTS_NS
21674 +#ifdef CONFIG_IPC_NS
21677 +#ifdef CONFIG_USER_NS
21680 +#ifdef CONFIG_PID_NS
21687 + * build a new nsproxy mix
21688 + * assumes that both proxies are 'const'
21689 + * does not touch nsproxy refcounts
21690 + * will hold a reference on the result.
21693 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
21694 + struct nsproxy *new_nsproxy, unsigned long mask)
21696 + struct mnt_namespace *old_ns;
21697 + struct uts_namespace *old_uts;
21698 + struct ipc_namespace *old_ipc;
21699 +#ifdef CONFIG_PID_NS
21700 + struct pid_namespace *old_pid;
21702 +#ifdef CONFIG_NET_NS
21703 + struct net *old_net;
21705 + struct nsproxy *nsproxy;
21707 + nsproxy = copy_nsproxy(old_nsproxy);
21711 + if (mask & CLONE_NEWNS) {
21712 + old_ns = nsproxy->mnt_ns;
21713 + nsproxy->mnt_ns = new_nsproxy->mnt_ns;
21714 + if (nsproxy->mnt_ns)
21715 + get_mnt_ns(nsproxy->mnt_ns);
21719 + if (mask & CLONE_NEWUTS) {
21720 + old_uts = nsproxy->uts_ns;
21721 + nsproxy->uts_ns = new_nsproxy->uts_ns;
21722 + if (nsproxy->uts_ns)
21723 + get_uts_ns(nsproxy->uts_ns);
21727 + if (mask & CLONE_NEWIPC) {
21728 + old_ipc = nsproxy->ipc_ns;
21729 + nsproxy->ipc_ns = new_nsproxy->ipc_ns;
21730 + if (nsproxy->ipc_ns)
21731 + get_ipc_ns(nsproxy->ipc_ns);
21735 +#ifdef CONFIG_PID_NS
21736 + if (mask & CLONE_NEWPID) {
21737 + old_pid = nsproxy->pid_ns_for_children;
21738 + nsproxy->pid_ns_for_children = new_nsproxy->pid_ns_for_children;
21739 + if (nsproxy->pid_ns_for_children)
21740 + get_pid_ns(nsproxy->pid_ns_for_children);
21744 +#ifdef CONFIG_NET_NS
21745 + if (mask & CLONE_NEWNET) {
21746 + old_net = nsproxy->net_ns;
21747 + nsproxy->net_ns = new_nsproxy->net_ns;
21748 + if (nsproxy->net_ns)
21749 + get_net(nsproxy->net_ns);
21754 + put_mnt_ns(old_ns);
21756 + put_uts_ns(old_uts);
21758 + put_ipc_ns(old_ipc);
21759 +#ifdef CONFIG_PID_NS
21761 + put_pid_ns(old_pid);
21763 +#ifdef CONFIG_NET_NS
21765 + put_net(old_net);
21773 + * merge two nsproxy structs into a new one.
21774 + * will hold a reference on the result.
21778 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
21779 + struct nsproxy *proxy, unsigned long mask)
21781 + struct nsproxy null_proxy = { .mnt_ns = NULL };
21787 + /* vs_mix_nsproxy returns with reference */
21788 + return vs_mix_nsproxy(old ? old : &null_proxy,
21791 + get_nsproxy(proxy);
21796 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21798 + struct nsproxy *proxy, *proxy_cur, *proxy_new;
21799 + struct fs_struct *fs_cur, *fs = NULL;
21800 + struct _vx_space *space;
21801 + int ret, kill = 0;
21803 + vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
21804 + vxi, vxi->vx_id, mask, index);
21806 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
21809 + if (index >= VX_SPACES)
21812 + space = &vxi->space[index];
21815 + mask = space->vx_nsmask;
21817 + if ((mask & space->vx_nsmask) != mask)
21820 + if (mask & CLONE_FS) {
21821 + fs = copy_fs_struct(space->vx_fs);
21825 + proxy = space->vx_nsproxy;
21827 + vxdprintk(VXD_CBIT(space, 9),
21828 + "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
21829 + vxi, vxi->vx_id, mask, index, proxy, fs);
21831 + task_lock(current);
21832 + fs_cur = current->fs;
21834 + if (mask & CLONE_FS) {
21835 + spin_lock(&fs_cur->lock);
21836 + current->fs = fs;
21837 + kill = !--fs_cur->users;
21838 + spin_unlock(&fs_cur->lock);
21841 + proxy_cur = current->nsproxy;
21842 + get_nsproxy(proxy_cur);
21843 + task_unlock(current);
21846 + free_fs_struct(fs_cur);
21848 + proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
21849 + if (IS_ERR(proxy_new)) {
21850 + ret = PTR_ERR(proxy_new);
21854 + proxy_new = xchg(¤t->nsproxy, proxy_new);
21856 + if (mask & CLONE_NEWUSER) {
21857 + struct cred *cred;
21859 + vxdprintk(VXD_CBIT(space, 10),
21860 + "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
21861 + vxi, vxi->vx_id, space->vx_cred,
21862 + current->real_cred, current->cred);
21864 + if (space->vx_cred) {
21865 + cred = __prepare_creds(space->vx_cred);
21867 + commit_creds(cred);
21874 + put_nsproxy(proxy_new);
21877 + put_nsproxy(proxy_cur);
21882 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21884 + struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
21885 + struct fs_struct *fs_vxi, *fs = NULL;
21886 + struct _vx_space *space;
21887 + int ret, kill = 0;
21889 + vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
21890 + vxi, vxi->vx_id, mask, index);
21892 + if ((mask & space_mask.mask) != mask)
21895 + if (index >= VX_SPACES)
21898 + space = &vxi->space[index];
21900 + proxy_vxi = space->vx_nsproxy;
21901 + fs_vxi = space->vx_fs;
21903 + if (mask & CLONE_FS) {
21904 + fs = copy_fs_struct(current->fs);
21909 + task_lock(current);
21911 + if (mask & CLONE_FS) {
21912 + spin_lock(&fs_vxi->lock);
21913 + space->vx_fs = fs;
21914 + kill = !--fs_vxi->users;
21915 + spin_unlock(&fs_vxi->lock);
21918 + proxy_cur = current->nsproxy;
21919 + get_nsproxy(proxy_cur);
21920 + task_unlock(current);
21923 + free_fs_struct(fs_vxi);
21925 + proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
21926 + if (IS_ERR(proxy_new)) {
21927 + ret = PTR_ERR(proxy_new);
21931 + proxy_new = xchg(&space->vx_nsproxy, proxy_new);
21932 + space->vx_nsmask |= mask;
21934 + if (mask & CLONE_NEWUSER) {
21935 + struct cred *cred;
21937 + vxdprintk(VXD_CBIT(space, 10),
21938 + "vx_set_space(%p[#%u],%p) cred (%p,%p)",
21939 + vxi, vxi->vx_id, space->vx_cred,
21940 + current->real_cred, current->cred);
21942 + cred = prepare_creds();
21943 + cred = (struct cred *)xchg(&space->vx_cred, cred);
21945 + abort_creds(cred);
21951 + put_nsproxy(proxy_new);
21954 + put_nsproxy(proxy_cur);
21959 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
21961 + struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21963 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21966 + return vx_enter_space(vxi, vc_data.mask, 0);
21969 +int vc_enter_space(struct vx_info *vxi, void __user *data)
21971 + struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21973 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21976 + if (vc_data.index >= VX_SPACES)
21979 + return vx_enter_space(vxi, vc_data.mask, vc_data.index);
21982 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
21984 + struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21986 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21989 + return vx_set_space(vxi, vc_data.mask, 0);
21992 +int vc_set_space(struct vx_info *vxi, void __user *data)
21994 + struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21996 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21999 + if (vc_data.index >= VX_SPACES)
22002 + return vx_set_space(vxi, vc_data.mask, vc_data.index);
22005 +int vc_get_space_mask(void __user *data, int type)
22007 + const struct vcmd_space_mask_v1 *mask;
22010 + mask = &space_mask_v0;
22011 + else if (type == 1)
22012 + mask = &space_mask;
22014 + mask = &default_space_mask;
22016 + vxdprintk(VXD_CBIT(space, 10),
22017 + "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22019 + if (copy_to_user(data, mask, sizeof(*mask)))
22024 diff -NurpP --minimal linux-3.13.10/kernel/vserver/switch.c linux-3.13.10-vs2.3.6.11/kernel/vserver/switch.c
22025 --- linux-3.13.10/kernel/vserver/switch.c 1970-01-01 00:00:00.000000000 +0000
22026 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/switch.c 2014-01-31 20:38:04.000000000 +0000
22029 + * linux/kernel/vserver/switch.c
22031 + * Virtual Server: Syscall Switch
22033 + * Copyright (C) 2003-2011 Herbert Pötzl
22035 + * V0.01 syscall switch
22036 + * V0.02 added signal to context
22037 + * V0.03 added rlimit functions
22038 + * V0.04 added iattr, task/xid functions
22039 + * V0.05 added debug/history stuff
22040 + * V0.06 added compat32 layer
22041 + * V0.07 vcmd args and perms
22042 + * V0.08 added status commands
22043 + * V0.09 added tag commands
22044 + * V0.10 added oom bias
22045 + * V0.11 added device commands
22046 + * V0.12 added warn mask
22050 +#include <linux/vs_context.h>
22051 +#include <linux/vs_network.h>
22052 +#include <linux/vserver/switch.h>
22054 +#include "vci_config.h"
22058 +int vc_get_version(uint32_t id)
22060 + return VCI_VERSION;
22064 +int vc_get_vci(uint32_t id)
22066 + return vci_kernel_config();
22069 +#include <linux/vserver/context_cmd.h>
22070 +#include <linux/vserver/cvirt_cmd.h>
22071 +#include <linux/vserver/cacct_cmd.h>
22072 +#include <linux/vserver/limit_cmd.h>
22073 +#include <linux/vserver/network_cmd.h>
22074 +#include <linux/vserver/sched_cmd.h>
22075 +#include <linux/vserver/debug_cmd.h>
22076 +#include <linux/vserver/inode_cmd.h>
22077 +#include <linux/vserver/dlimit_cmd.h>
22078 +#include <linux/vserver/signal_cmd.h>
22079 +#include <linux/vserver/space_cmd.h>
22080 +#include <linux/vserver/tag_cmd.h>
22081 +#include <linux/vserver/device_cmd.h>
22083 +#include <linux/vserver/inode.h>
22084 +#include <linux/vserver/dlimit.h>
22087 +#ifdef CONFIG_COMPAT
22088 +#define __COMPAT(name, id, data, compat) \
22089 + (compat) ? name ## _x32(id, data) : name(id, data)
22090 +#define __COMPAT_NO_ID(name, data, compat) \
22091 + (compat) ? name ## _x32(data) : name(data)
22093 +#define __COMPAT(name, id, data, compat) \
22095 +#define __COMPAT_NO_ID(name, data, compat) \
22101 +long do_vcmd(uint32_t cmd, uint32_t id,
22102 + struct vx_info *vxi, struct nx_info *nxi,
22103 + void __user *data, int compat)
22107 + case VCMD_get_version:
22108 + return vc_get_version(id);
22109 + case VCMD_get_vci:
22110 + return vc_get_vci(id);
22112 + case VCMD_task_xid:
22113 + return vc_task_xid(id);
22114 + case VCMD_vx_info:
22115 + return vc_vx_info(vxi, data);
22117 + case VCMD_task_nid:
22118 + return vc_task_nid(id);
22119 + case VCMD_nx_info:
22120 + return vc_nx_info(nxi, data);
22122 + case VCMD_task_tag:
22123 + return vc_task_tag(id);
22125 + case VCMD_set_space_v1:
22126 + return vc_set_space_v1(vxi, data);
22127 + /* this is version 2 */
22128 + case VCMD_set_space:
22129 + return vc_set_space(vxi, data);
22131 + case VCMD_get_space_mask_v0:
22132 + return vc_get_space_mask(data, 0);
22133 + /* this is version 1 */
22134 + case VCMD_get_space_mask:
22135 + return vc_get_space_mask(data, 1);
22137 + case VCMD_get_space_default:
22138 + return vc_get_space_mask(data, -1);
22140 + case VCMD_set_umask:
22141 + return vc_set_umask(vxi, data);
22143 + case VCMD_get_umask:
22144 + return vc_get_umask(vxi, data);
22146 + case VCMD_set_wmask:
22147 + return vc_set_wmask(vxi, data);
22149 + case VCMD_get_wmask:
22150 + return vc_get_wmask(vxi, data);
22151 +#ifdef CONFIG_IA32_EMULATION
22152 + case VCMD_get_rlimit:
22153 + return __COMPAT(vc_get_rlimit, vxi, data, compat);
22154 + case VCMD_set_rlimit:
22155 + return __COMPAT(vc_set_rlimit, vxi, data, compat);
22157 + case VCMD_get_rlimit:
22158 + return vc_get_rlimit(vxi, data);
22159 + case VCMD_set_rlimit:
22160 + return vc_set_rlimit(vxi, data);
22162 + case VCMD_get_rlimit_mask:
22163 + return vc_get_rlimit_mask(id, data);
22164 + case VCMD_reset_hits:
22165 + return vc_reset_hits(vxi, data);
22166 + case VCMD_reset_minmax:
22167 + return vc_reset_minmax(vxi, data);
22169 + case VCMD_get_vhi_name:
22170 + return vc_get_vhi_name(vxi, data);
22171 + case VCMD_set_vhi_name:
22172 + return vc_set_vhi_name(vxi, data);
22174 + case VCMD_ctx_stat:
22175 + return vc_ctx_stat(vxi, data);
22176 + case VCMD_virt_stat:
22177 + return vc_virt_stat(vxi, data);
22178 + case VCMD_sock_stat:
22179 + return vc_sock_stat(vxi, data);
22180 + case VCMD_rlimit_stat:
22181 + return vc_rlimit_stat(vxi, data);
22183 + case VCMD_set_cflags:
22184 + return vc_set_cflags(vxi, data);
22185 + case VCMD_get_cflags:
22186 + return vc_get_cflags(vxi, data);
22188 + /* this is version 1 */
22189 + case VCMD_set_ccaps:
22190 + return vc_set_ccaps(vxi, data);
22191 + /* this is version 1 */
22192 + case VCMD_get_ccaps:
22193 + return vc_get_ccaps(vxi, data);
22194 + case VCMD_set_bcaps:
22195 + return vc_set_bcaps(vxi, data);
22196 + case VCMD_get_bcaps:
22197 + return vc_get_bcaps(vxi, data);
22199 + case VCMD_set_badness:
22200 + return vc_set_badness(vxi, data);
22201 + case VCMD_get_badness:
22202 + return vc_get_badness(vxi, data);
22204 + case VCMD_set_nflags:
22205 + return vc_set_nflags(nxi, data);
22206 + case VCMD_get_nflags:
22207 + return vc_get_nflags(nxi, data);
22209 + case VCMD_set_ncaps:
22210 + return vc_set_ncaps(nxi, data);
22211 + case VCMD_get_ncaps:
22212 + return vc_get_ncaps(nxi, data);
22214 + case VCMD_set_prio_bias:
22215 + return vc_set_prio_bias(vxi, data);
22216 + case VCMD_get_prio_bias:
22217 + return vc_get_prio_bias(vxi, data);
22218 + case VCMD_add_dlimit:
22219 + return __COMPAT(vc_add_dlimit, id, data, compat);
22220 + case VCMD_rem_dlimit:
22221 + return __COMPAT(vc_rem_dlimit, id, data, compat);
22222 + case VCMD_set_dlimit:
22223 + return __COMPAT(vc_set_dlimit, id, data, compat);
22224 + case VCMD_get_dlimit:
22225 + return __COMPAT(vc_get_dlimit, id, data, compat);
22227 + case VCMD_ctx_kill:
22228 + return vc_ctx_kill(vxi, data);
22230 + case VCMD_wait_exit:
22231 + return vc_wait_exit(vxi, data);
22233 + case VCMD_get_iattr:
22234 + return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22235 + case VCMD_set_iattr:
22236 + return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22238 + case VCMD_fget_iattr:
22239 + return vc_fget_iattr(id, data);
22240 + case VCMD_fset_iattr:
22241 + return vc_fset_iattr(id, data);
22243 + case VCMD_enter_space_v0:
22244 + return vc_enter_space_v1(vxi, NULL);
22245 + case VCMD_enter_space_v1:
22246 + return vc_enter_space_v1(vxi, data);
22247 + /* this is version 2 */
22248 + case VCMD_enter_space:
22249 + return vc_enter_space(vxi, data);
22251 + case VCMD_ctx_create_v0:
22252 + return vc_ctx_create(id, NULL);
22253 + case VCMD_ctx_create:
22254 + return vc_ctx_create(id, data);
22255 + case VCMD_ctx_migrate_v0:
22256 + return vc_ctx_migrate(vxi, NULL);
22257 + case VCMD_ctx_migrate:
22258 + return vc_ctx_migrate(vxi, data);
22260 + case VCMD_net_create_v0:
22261 + return vc_net_create(id, NULL);
22262 + case VCMD_net_create:
22263 + return vc_net_create(id, data);
22264 + case VCMD_net_migrate:
22265 + return vc_net_migrate(nxi, data);
22267 + case VCMD_tag_migrate:
22268 + return vc_tag_migrate(id);
22270 + case VCMD_net_add:
22271 + return vc_net_add(nxi, data);
22272 + case VCMD_net_remove:
22273 + return vc_net_remove(nxi, data);
22275 + case VCMD_net_add_ipv4_v1:
22276 + return vc_net_add_ipv4_v1(nxi, data);
22277 + /* this is version 2 */
22278 + case VCMD_net_add_ipv4:
22279 + return vc_net_add_ipv4(nxi, data);
22281 + case VCMD_net_rem_ipv4_v1:
22282 + return vc_net_rem_ipv4_v1(nxi, data);
22283 + /* this is version 2 */
22284 + case VCMD_net_rem_ipv4:
22285 + return vc_net_rem_ipv4(nxi, data);
22286 +#ifdef CONFIG_IPV6
22287 + case VCMD_net_add_ipv6:
22288 + return vc_net_add_ipv6(nxi, data);
22289 + case VCMD_net_remove_ipv6:
22290 + return vc_net_remove_ipv6(nxi, data);
22292 +/* case VCMD_add_match_ipv4:
22293 + return vc_add_match_ipv4(nxi, data);
22294 + case VCMD_get_match_ipv4:
22295 + return vc_get_match_ipv4(nxi, data);
22296 +#ifdef CONFIG_IPV6
22297 + case VCMD_add_match_ipv6:
22298 + return vc_add_match_ipv6(nxi, data);
22299 + case VCMD_get_match_ipv6:
22300 + return vc_get_match_ipv6(nxi, data);
22303 +#ifdef CONFIG_VSERVER_DEVICE
22304 + case VCMD_set_mapping:
22305 + return __COMPAT(vc_set_mapping, vxi, data, compat);
22306 + case VCMD_unset_mapping:
22307 + return __COMPAT(vc_unset_mapping, vxi, data, compat);
22309 +#ifdef CONFIG_VSERVER_HISTORY
22310 + case VCMD_dump_history:
22311 + return vc_dump_history(id);
22312 + case VCMD_read_history:
22313 + return __COMPAT(vc_read_history, id, data, compat);
22316 + vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
22317 + VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
22323 +#define __VCMD(vcmd, _perm, _args, _flags) \
22324 + case VCMD_ ## vcmd: perm = _perm; \
22325 + args = _args; flags = _flags; break
22328 +#define VCA_NONE 0x00
22329 +#define VCA_VXI 0x01
22330 +#define VCA_NXI 0x02
22332 +#define VCF_NONE 0x00
22333 +#define VCF_INFO 0x01
22334 +#define VCF_ADMIN 0x02
22335 +#define VCF_ARES 0x06 /* includes admin */
22336 +#define VCF_SETUP 0x08
22338 +#define VCF_ZIDOK 0x10 /* zero id okay */
22342 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
22345 + int permit = -1, state = 0;
22346 + int perm = -1, args = 0, flags = 0;
22347 + struct vx_info *vxi = NULL;
22348 + struct nx_info *nxi = NULL;
22351 + /* unpriviledged commands */
22352 + __VCMD(get_version, 0, VCA_NONE, 0);
22353 + __VCMD(get_vci, 0, VCA_NONE, 0);
22354 + __VCMD(get_rlimit_mask, 0, VCA_NONE, 0);
22355 + __VCMD(get_space_mask_v0,0, VCA_NONE, 0);
22356 + __VCMD(get_space_mask, 0, VCA_NONE, 0);
22357 + __VCMD(get_space_default,0, VCA_NONE, 0);
22359 + /* info commands */
22360 + __VCMD(task_xid, 2, VCA_NONE, 0);
22361 + __VCMD(reset_hits, 2, VCA_VXI, 0);
22362 + __VCMD(reset_minmax, 2, VCA_VXI, 0);
22363 + __VCMD(vx_info, 3, VCA_VXI, VCF_INFO);
22364 + __VCMD(get_bcaps, 3, VCA_VXI, VCF_INFO);
22365 + __VCMD(get_ccaps, 3, VCA_VXI, VCF_INFO);
22366 + __VCMD(get_cflags, 3, VCA_VXI, VCF_INFO);
22367 + __VCMD(get_umask, 3, VCA_VXI, VCF_INFO);
22368 + __VCMD(get_wmask, 3, VCA_VXI, VCF_INFO);
22369 + __VCMD(get_badness, 3, VCA_VXI, VCF_INFO);
22370 + __VCMD(get_vhi_name, 3, VCA_VXI, VCF_INFO);
22371 + __VCMD(get_rlimit, 3, VCA_VXI, VCF_INFO);
22373 + __VCMD(ctx_stat, 3, VCA_VXI, VCF_INFO);
22374 + __VCMD(virt_stat, 3, VCA_VXI, VCF_INFO);
22375 + __VCMD(sock_stat, 3, VCA_VXI, VCF_INFO);
22376 + __VCMD(rlimit_stat, 3, VCA_VXI, VCF_INFO);
22378 + __VCMD(task_nid, 2, VCA_NONE, 0);
22379 + __VCMD(nx_info, 3, VCA_NXI, VCF_INFO);
22380 + __VCMD(get_ncaps, 3, VCA_NXI, VCF_INFO);
22381 + __VCMD(get_nflags, 3, VCA_NXI, VCF_INFO);
22383 + __VCMD(task_tag, 2, VCA_NONE, 0);
22385 + __VCMD(get_iattr, 2, VCA_NONE, 0);
22386 + __VCMD(fget_iattr, 2, VCA_NONE, 0);
22387 + __VCMD(get_dlimit, 3, VCA_NONE, VCF_INFO);
22388 + __VCMD(get_prio_bias, 3, VCA_VXI, VCF_INFO);
22390 + /* lower admin commands */
22391 + __VCMD(wait_exit, 4, VCA_VXI, VCF_INFO);
22392 + __VCMD(ctx_create_v0, 5, VCA_NONE, 0);
22393 + __VCMD(ctx_create, 5, VCA_NONE, 0);
22394 + __VCMD(ctx_migrate_v0, 5, VCA_VXI, VCF_ADMIN);
22395 + __VCMD(ctx_migrate, 5, VCA_VXI, VCF_ADMIN);
22396 + __VCMD(enter_space_v0, 5, VCA_VXI, VCF_ADMIN);
22397 + __VCMD(enter_space_v1, 5, VCA_VXI, VCF_ADMIN);
22398 + __VCMD(enter_space, 5, VCA_VXI, VCF_ADMIN);
22400 + __VCMD(net_create_v0, 5, VCA_NONE, 0);
22401 + __VCMD(net_create, 5, VCA_NONE, 0);
22402 + __VCMD(net_migrate, 5, VCA_NXI, VCF_ADMIN);
22404 + __VCMD(tag_migrate, 5, VCA_NONE, VCF_ADMIN);
22406 + /* higher admin commands */
22407 + __VCMD(ctx_kill, 6, VCA_VXI, VCF_ARES);
22408 + __VCMD(set_space_v1, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22409 + __VCMD(set_space, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22411 + __VCMD(set_ccaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22412 + __VCMD(set_bcaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22413 + __VCMD(set_cflags, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22414 + __VCMD(set_umask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22415 + __VCMD(set_wmask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22416 + __VCMD(set_badness, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22418 + __VCMD(set_vhi_name, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22419 + __VCMD(set_rlimit, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22420 + __VCMD(set_prio_bias, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22422 + __VCMD(set_ncaps, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
22423 + __VCMD(set_nflags, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
22424 + __VCMD(net_add, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22425 + __VCMD(net_remove, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22426 + __VCMD(net_add_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22427 + __VCMD(net_rem_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22428 + __VCMD(net_add_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22429 + __VCMD(net_rem_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22430 +#ifdef CONFIG_IPV6
22431 + __VCMD(net_add_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22432 + __VCMD(net_remove_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22434 + __VCMD(set_iattr, 7, VCA_NONE, 0);
22435 + __VCMD(fset_iattr, 7, VCA_NONE, 0);
22436 + __VCMD(set_dlimit, 7, VCA_NONE, VCF_ARES);
22437 + __VCMD(add_dlimit, 8, VCA_NONE, VCF_ARES);
22438 + __VCMD(rem_dlimit, 8, VCA_NONE, VCF_ARES);
22440 +#ifdef CONFIG_VSERVER_DEVICE
22441 + __VCMD(set_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
22442 + __VCMD(unset_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
22444 + /* debug level admin commands */
22445 +#ifdef CONFIG_VSERVER_HISTORY
22446 + __VCMD(dump_history, 9, VCA_NONE, 0);
22447 + __VCMD(read_history, 9, VCA_NONE, 0);
22454 + vxdprintk(VXD_CBIT(switch, 0),
22455 + "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
22456 + VC_CATEGORY(cmd), VC_COMMAND(cmd),
22457 + VC_VERSION(cmd), id, data, compat,
22458 + perm, args, flags);
22465 + if (!capable(CAP_CONTEXT))
22469 + /* moved here from the individual commands */
22471 + if ((perm > 1) && !capable(CAP_SYS_ADMIN))
22475 + /* vcmd involves resource management */
22477 + if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
22481 + /* various legacy exceptions */
22483 + /* will go away when spectator is a cap */
22484 + case VCMD_ctx_migrate_v0:
22485 + case VCMD_ctx_migrate:
22487 + current->xid = 1;
22493 + /* will go away when spectator is a cap */
22494 + case VCMD_net_migrate:
22496 + current->nid = 1;
22503 + /* vcmds are fine by default */
22506 + /* admin type vcmds require admin ... */
22507 + if (flags & VCF_ADMIN)
22508 + permit = vx_check(0, VS_ADMIN) ? 1 : 0;
22510 + /* ... but setup type vcmds override that */
22511 + if (!permit && (flags & VCF_SETUP))
22512 + permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
22520 + if (!id && (flags & VCF_ZIDOK))
22524 + if (args & VCA_VXI) {
22525 + vxi = lookup_vx_info(id);
22529 + if ((flags & VCF_ADMIN) &&
22530 + /* special case kill for shutdown */
22531 + (cmd != VCMD_ctx_kill) &&
22532 + /* can context be administrated? */
22533 + !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
22539 + if (args & VCA_NXI) {
22540 + nxi = lookup_nx_info(id);
22544 + if ((flags & VCF_ADMIN) &&
22545 + /* can context be administrated? */
22546 + !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
22553 + ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
22556 + if ((args & VCA_NXI) && nxi)
22557 + put_nx_info(nxi);
22559 + if ((args & VCA_VXI) && vxi)
22560 + put_vx_info(vxi);
22562 + vxdprintk(VXD_CBIT(switch, 1),
22563 + "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
22564 + VC_CATEGORY(cmd), VC_COMMAND(cmd),
22565 + VC_VERSION(cmd), ret, ret, state, permit);
22570 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
22572 + return do_vserver(cmd, id, data, 0);
22575 +#ifdef CONFIG_COMPAT
22578 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
22580 + return do_vserver(cmd, id, data, 1);
22583 +#endif /* CONFIG_COMPAT */
22584 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sysctl.c linux-3.13.10-vs2.3.6.11/kernel/vserver/sysctl.c
22585 --- linux-3.13.10/kernel/vserver/sysctl.c 1970-01-01 00:00:00.000000000 +0000
22586 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sysctl.c 2014-01-31 20:38:04.000000000 +0000
22589 + * kernel/vserver/sysctl.c
22591 + * Virtual Context Support
22593 + * Copyright (C) 2004-2007 Herbert Pötzl
22595 + * V0.01 basic structure
22599 +#include <linux/module.h>
22600 +#include <linux/ctype.h>
22601 +#include <linux/sysctl.h>
22602 +#include <linux/parser.h>
22603 +#include <asm/uaccess.h>
22606 + CTL_DEBUG_ERROR = 0,
22607 + CTL_DEBUG_SWITCH = 1,
22623 +unsigned int vs_debug_switch = 0;
22624 +unsigned int vs_debug_xid = 0;
22625 +unsigned int vs_debug_nid = 0;
22626 +unsigned int vs_debug_tag = 0;
22627 +unsigned int vs_debug_net = 0;
22628 +unsigned int vs_debug_limit = 0;
22629 +unsigned int vs_debug_cres = 0;
22630 +unsigned int vs_debug_dlim = 0;
22631 +unsigned int vs_debug_quota = 0;
22632 +unsigned int vs_debug_cvirt = 0;
22633 +unsigned int vs_debug_space = 0;
22634 +unsigned int vs_debug_perm = 0;
22635 +unsigned int vs_debug_misc = 0;
22638 +static struct ctl_table_header *vserver_table_header;
22639 +static ctl_table vserver_root_table[];
22642 +void vserver_register_sysctl(void)
22644 + if (!vserver_table_header) {
22645 + vserver_table_header = register_sysctl_table(vserver_root_table);
22650 +void vserver_unregister_sysctl(void)
22652 + if (vserver_table_header) {
22653 + unregister_sysctl_table(vserver_table_header);
22654 + vserver_table_header = NULL;
22659 +static int proc_dodebug(ctl_table *table, int write,
22660 + void __user *buffer, size_t *lenp, loff_t *ppos)
22662 + char tmpbuf[20], *p, c;
22663 + unsigned int value;
22664 + size_t left, len;
22666 + if ((*ppos && !write) || !*lenp) {
22674 + if (!access_ok(VERIFY_READ, buffer, left))
22676 + p = (char *)buffer;
22677 + while (left && __get_user(c, p) >= 0 && isspace(c))
22682 + if (left > sizeof(tmpbuf) - 1)
22684 + if (copy_from_user(tmpbuf, p, left))
22686 + tmpbuf[left] = '\0';
22688 + for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
22689 + value = 10 * value + (*p - '0');
22690 + if (*p && !isspace(*p))
22692 + while (left && isspace(*p))
22694 + *(unsigned int *)table->data = value;
22696 + if (!access_ok(VERIFY_WRITE, buffer, left))
22698 + len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
22701 + if (__copy_to_user(buffer, tmpbuf, len))
22703 + if ((left -= len) > 0) {
22704 + if (put_user('\n', (char *)buffer + len))
22718 +#define CTL_ENTRY(ctl, name) \
22720 + .procname = #name, \
22721 + .data = &vs_ ## name, \
22722 + .maxlen = sizeof(int), \
22724 + .proc_handler = &proc_dodebug, \
22725 + .extra1 = &zero, \
22726 + .extra2 = &zero, \
22729 +static ctl_table vserver_debug_table[] = {
22730 + CTL_ENTRY(CTL_DEBUG_SWITCH, debug_switch),
22731 + CTL_ENTRY(CTL_DEBUG_XID, debug_xid),
22732 + CTL_ENTRY(CTL_DEBUG_NID, debug_nid),
22733 + CTL_ENTRY(CTL_DEBUG_TAG, debug_tag),
22734 + CTL_ENTRY(CTL_DEBUG_NET, debug_net),
22735 + CTL_ENTRY(CTL_DEBUG_LIMIT, debug_limit),
22736 + CTL_ENTRY(CTL_DEBUG_CRES, debug_cres),
22737 + CTL_ENTRY(CTL_DEBUG_DLIM, debug_dlim),
22738 + CTL_ENTRY(CTL_DEBUG_QUOTA, debug_quota),
22739 + CTL_ENTRY(CTL_DEBUG_CVIRT, debug_cvirt),
22740 + CTL_ENTRY(CTL_DEBUG_SPACE, debug_space),
22741 + CTL_ENTRY(CTL_DEBUG_PERM, debug_perm),
22742 + CTL_ENTRY(CTL_DEBUG_MISC, debug_misc),
22746 +static ctl_table vserver_root_table[] = {
22748 + .procname = "vserver",
22750 + .child = vserver_debug_table
22756 +static match_table_t tokens = {
22757 + { CTL_DEBUG_SWITCH, "switch=%x" },
22758 + { CTL_DEBUG_XID, "xid=%x" },
22759 + { CTL_DEBUG_NID, "nid=%x" },
22760 + { CTL_DEBUG_TAG, "tag=%x" },
22761 + { CTL_DEBUG_NET, "net=%x" },
22762 + { CTL_DEBUG_LIMIT, "limit=%x" },
22763 + { CTL_DEBUG_CRES, "cres=%x" },
22764 + { CTL_DEBUG_DLIM, "dlim=%x" },
22765 + { CTL_DEBUG_QUOTA, "quota=%x" },
22766 + { CTL_DEBUG_CVIRT, "cvirt=%x" },
22767 + { CTL_DEBUG_SPACE, "space=%x" },
22768 + { CTL_DEBUG_PERM, "perm=%x" },
22769 + { CTL_DEBUG_MISC, "misc=%x" },
22770 + { CTL_DEBUG_ERROR, NULL }
22773 +#define HANDLE_CASE(id, name, val) \
22774 + case CTL_DEBUG_ ## id: \
22775 + vs_debug_ ## name = val; \
22776 + printk("vs_debug_" #name "=0x%x\n", val); \
22780 +static int __init vs_debug_setup(char *str)
22785 + printk("vs_debug_setup(%s)\n", str);
22786 + while ((p = strsep(&str, ",")) != NULL) {
22787 + substring_t args[MAX_OPT_ARGS];
22788 + unsigned int value;
22793 + token = match_token(p, tokens, args);
22794 + value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
22797 + HANDLE_CASE(SWITCH, switch, value);
22798 + HANDLE_CASE(XID, xid, value);
22799 + HANDLE_CASE(NID, nid, value);
22800 + HANDLE_CASE(TAG, tag, value);
22801 + HANDLE_CASE(NET, net, value);
22802 + HANDLE_CASE(LIMIT, limit, value);
22803 + HANDLE_CASE(CRES, cres, value);
22804 + HANDLE_CASE(DLIM, dlim, value);
22805 + HANDLE_CASE(QUOTA, quota, value);
22806 + HANDLE_CASE(CVIRT, cvirt, value);
22807 + HANDLE_CASE(SPACE, space, value);
22808 + HANDLE_CASE(PERM, perm, value);
22809 + HANDLE_CASE(MISC, misc, value);
22818 +__setup("vsdebug=", vs_debug_setup);
22822 +EXPORT_SYMBOL_GPL(vs_debug_switch);
22823 +EXPORT_SYMBOL_GPL(vs_debug_xid);
22824 +EXPORT_SYMBOL_GPL(vs_debug_nid);
22825 +EXPORT_SYMBOL_GPL(vs_debug_net);
22826 +EXPORT_SYMBOL_GPL(vs_debug_limit);
22827 +EXPORT_SYMBOL_GPL(vs_debug_cres);
22828 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
22829 +EXPORT_SYMBOL_GPL(vs_debug_quota);
22830 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
22831 +EXPORT_SYMBOL_GPL(vs_debug_space);
22832 +EXPORT_SYMBOL_GPL(vs_debug_perm);
22833 +EXPORT_SYMBOL_GPL(vs_debug_misc);
22835 diff -NurpP --minimal linux-3.13.10/kernel/vserver/tag.c linux-3.13.10-vs2.3.6.11/kernel/vserver/tag.c
22836 --- linux-3.13.10/kernel/vserver/tag.c 1970-01-01 00:00:00.000000000 +0000
22837 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/tag.c 2014-01-31 20:38:04.000000000 +0000
22840 + * linux/kernel/vserver/tag.c
22842 + * Virtual Server: Shallow Tag Space
22844 + * Copyright (C) 2007 Herbert Pötzl
22846 + * V0.01 basic implementation
22850 +#include <linux/sched.h>
22851 +#include <linux/vserver/debug.h>
22852 +#include <linux/vs_pid.h>
22853 +#include <linux/vs_tag.h>
22855 +#include <linux/vserver/tag_cmd.h>
22858 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
22863 + vxdprintk(VXD_CBIT(tag, 5),
22864 + "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
22870 + vxdprintk(VXD_CBIT(tag, 5),
22871 + "moved task %p into [#%d]", p, tag);
22875 +/* vserver syscall commands below here */
22877 +/* taks xid and vx_info functions */
22880 +int vc_task_tag(uint32_t id)
22885 + struct task_struct *tsk;
22887 + tsk = find_task_by_real_pid(id);
22888 + tag = (tsk) ? tsk->tag : -ESRCH;
22889 + rcu_read_unlock();
22891 + tag = dx_current_tag();
22896 +int vc_tag_migrate(uint32_t tag)
22898 + return dx_migrate_task(current, tag & 0xFFFF);
22902 diff -NurpP --minimal linux-3.13.10/kernel/vserver/vci_config.h linux-3.13.10-vs2.3.6.11/kernel/vserver/vci_config.h
22903 --- linux-3.13.10/kernel/vserver/vci_config.h 1970-01-01 00:00:00.000000000 +0000
22904 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/vci_config.h 2014-01-31 20:38:04.000000000 +0000
22907 +/* interface version */
22909 +#define VCI_VERSION 0x00020308
22913 + VCI_KCBIT_NO_DYNAMIC = 0,
22915 + VCI_KCBIT_PROC_SECURE = 4,
22916 + /* VCI_KCBIT_HARDCPU = 5, */
22917 + /* VCI_KCBIT_IDLELIMIT = 6, */
22918 + /* VCI_KCBIT_IDLETIME = 7, */
22920 + VCI_KCBIT_COWBL = 8,
22921 + VCI_KCBIT_FULLCOWBL = 9,
22922 + VCI_KCBIT_SPACES = 10,
22923 + VCI_KCBIT_NETV2 = 11,
22924 + VCI_KCBIT_MEMCG = 12,
22925 + VCI_KCBIT_MEMCG_SWAP = 13,
22927 + VCI_KCBIT_DEBUG = 16,
22928 + VCI_KCBIT_HISTORY = 20,
22929 + VCI_KCBIT_TAGGED = 24,
22930 + VCI_KCBIT_PPTAG = 28,
22932 + VCI_KCBIT_MORE = 31,
22936 +static inline uint32_t vci_kernel_config(void)
22939 + (1 << VCI_KCBIT_NO_DYNAMIC) |
22941 + /* configured features */
22942 +#ifdef CONFIG_VSERVER_PROC_SECURE
22943 + (1 << VCI_KCBIT_PROC_SECURE) |
22945 +#ifdef CONFIG_VSERVER_COWBL
22946 + (1 << VCI_KCBIT_COWBL) |
22947 + (1 << VCI_KCBIT_FULLCOWBL) |
22949 + (1 << VCI_KCBIT_SPACES) |
22950 + (1 << VCI_KCBIT_NETV2) |
22951 +#ifdef CONFIG_MEMCG
22952 + (1 << VCI_KCBIT_MEMCG) |
22954 +#ifdef CONFIG_MEMCG_SWAP
22955 + (1 << VCI_KCBIT_MEMCG_SWAP) |
22958 + /* debug options */
22959 +#ifdef CONFIG_VSERVER_DEBUG
22960 + (1 << VCI_KCBIT_DEBUG) |
22962 +#ifdef CONFIG_VSERVER_HISTORY
22963 + (1 << VCI_KCBIT_HISTORY) |
22966 + /* inode context tagging */
22967 +#if defined(CONFIG_TAGGING_NONE)
22968 + (0 << VCI_KCBIT_TAGGED) |
22969 +#elif defined(CONFIG_TAGGING_UID16)
22970 + (1 << VCI_KCBIT_TAGGED) |
22971 +#elif defined(CONFIG_TAGGING_GID16)
22972 + (2 << VCI_KCBIT_TAGGED) |
22973 +#elif defined(CONFIG_TAGGING_ID24)
22974 + (3 << VCI_KCBIT_TAGGED) |
22975 +#elif defined(CONFIG_TAGGING_INTERN)
22976 + (4 << VCI_KCBIT_TAGGED) |
22977 +#elif defined(CONFIG_TAGGING_RUNTIME)
22978 + (5 << VCI_KCBIT_TAGGED) |
22980 + (7 << VCI_KCBIT_TAGGED) |
22982 + (1 << VCI_KCBIT_PPTAG) |
22986 diff -NurpP --minimal linux-3.13.10/mm/memcontrol.c linux-3.13.10-vs2.3.6.11/mm/memcontrol.c
22987 --- linux-3.13.10/mm/memcontrol.c 2014-04-17 01:12:40.000000000 +0000
22988 +++ linux-3.13.10-vs2.3.6.11/mm/memcontrol.c 2014-04-17 01:17:11.000000000 +0000
22989 @@ -1056,6 +1056,31 @@ struct mem_cgroup *mem_cgroup_from_task(
22990 return mem_cgroup_from_css(task_css(p, mem_cgroup_subsys_id));
22993 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
22995 + return res_counter_read_u64(&mem->res, member);
22998 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23000 + return res_counter_read_u64(&mem->memsw, member);
23003 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23005 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23008 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23010 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23013 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23015 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23018 struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23020 struct mem_cgroup *memcg = NULL;
23021 diff -NurpP --minimal linux-3.13.10/mm/oom_kill.c linux-3.13.10-vs2.3.6.11/mm/oom_kill.c
23022 --- linux-3.13.10/mm/oom_kill.c 2014-04-17 01:12:40.000000000 +0000
23023 +++ linux-3.13.10-vs2.3.6.11/mm/oom_kill.c 2014-02-25 11:26:10.000000000 +0000
23025 #include <linux/freezer.h>
23026 #include <linux/ftrace.h>
23027 #include <linux/ratelimit.h>
23028 +#include <linux/reboot.h>
23029 +#include <linux/vs_context.h>
23031 #define CREATE_TRACE_POINTS
23032 #include <trace/events/oom.h>
23033 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23034 static bool oom_unkillable_task(struct task_struct *p,
23035 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23037 - if (is_global_init(p))
23038 + unsigned xid = vx_current_xid();
23040 + /* skip the init task, global and per guest */
23041 + if (task_is_init(p))
23043 if (p->flags & PF_KTHREAD)
23046 + /* skip other guest and host processes if oom in guest */
23047 + if (xid && vx_task_xid(p) != xid)
23050 /* When mem_cgroup_out_of_memory() and p is not member of the group */
23051 if (memcg && !task_in_mem_cgroup(p, memcg))
23053 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23054 dump_header(p, gfp_mask, order, memcg, nodemask);
23057 - pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23058 - message, task_pid_nr(p), p->comm, points);
23059 + pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23060 + message, task_pid_nr(p), p->xid, p->comm, points);
23064 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23066 /* mm cannot safely be dereferenced after task_unlock(victim) */
23068 - pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23069 - task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23070 + pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23071 + task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23072 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23073 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23074 task_unlock(victim);
23075 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23077 EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23079 +long vs_oom_action(unsigned int);
23082 * Try to acquire the OOM killer lock for the zones in zonelist. Returns zero
23083 * if a parallel OOM killing is already taking place that includes a zone in
23084 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23085 /* Found nothing?!?! Either we hang forever, or we panic. */
23087 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23088 - panic("Out of memory and no killable processes...\n");
23090 + /* avoid panic for guest OOM */
23091 + if (vx_current_xid())
23092 + vs_oom_action(LINUX_REBOOT_CMD_OOM);
23094 + panic("Out of memory and no killable processes...\n");
23096 if (p != (void *)-1UL) {
23097 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23098 diff -NurpP --minimal linux-3.13.10/mm/page_alloc.c linux-3.13.10-vs2.3.6.11/mm/page_alloc.c
23099 --- linux-3.13.10/mm/page_alloc.c 2014-04-17 01:12:40.000000000 +0000
23100 +++ linux-3.13.10-vs2.3.6.11/mm/page_alloc.c 2014-04-17 01:17:11.000000000 +0000
23102 #include <linux/page-debug-flags.h>
23103 #include <linux/hugetlb.h>
23104 #include <linux/sched/rt.h>
23105 +#include <linux/vs_base.h>
23106 +#include <linux/vs_limit.h>
23108 #include <asm/sections.h>
23109 #include <asm/tlbflush.h>
23110 @@ -2983,6 +2985,9 @@ void si_meminfo(struct sysinfo *val)
23111 val->totalhigh = totalhigh_pages;
23112 val->freehigh = nr_free_highpages();
23113 val->mem_unit = PAGE_SIZE;
23115 + if (vx_flags(VXF_VIRT_MEM, 0))
23116 + vx_vsi_meminfo(val);
23119 EXPORT_SYMBOL(si_meminfo);
23120 @@ -3007,6 +3012,9 @@ void si_meminfo_node(struct sysinfo *val
23123 val->mem_unit = PAGE_SIZE;
23125 + if (vx_flags(VXF_VIRT_MEM, 0))
23126 + vx_vsi_meminfo(val);
23130 diff -NurpP --minimal linux-3.13.10/mm/pgtable-generic.c linux-3.13.10-vs2.3.6.11/mm/pgtable-generic.c
23131 --- linux-3.13.10/mm/pgtable-generic.c 2014-01-22 20:39:14.000000000 +0000
23132 +++ linux-3.13.10-vs2.3.6.11/mm/pgtable-generic.c 2014-01-31 20:38:04.000000000 +0000
23134 * Copyright (C) 2010 Linus Torvalds
23137 +#include <linux/mm.h>
23139 #include <linux/pagemap.h>
23140 #include <asm/tlb.h>
23141 #include <asm-generic/pgtable.h>
23142 diff -NurpP --minimal linux-3.13.10/mm/shmem.c linux-3.13.10-vs2.3.6.11/mm/shmem.c
23143 --- linux-3.13.10/mm/shmem.c 2014-01-22 20:39:14.000000000 +0000
23144 +++ linux-3.13.10-vs2.3.6.11/mm/shmem.c 2014-01-31 20:38:04.000000000 +0000
23145 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23147 struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23149 - buf->f_type = TMPFS_MAGIC;
23150 + buf->f_type = TMPFS_SUPER_MAGIC;
23151 buf->f_bsize = PAGE_CACHE_SIZE;
23152 buf->f_namelen = NAME_MAX;
23153 if (sbinfo->max_blocks) {
23154 @@ -2639,7 +2639,7 @@ int shmem_fill_super(struct super_block
23155 sb->s_maxbytes = MAX_LFS_FILESIZE;
23156 sb->s_blocksize = PAGE_CACHE_SIZE;
23157 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23158 - sb->s_magic = TMPFS_MAGIC;
23159 + sb->s_magic = TMPFS_SUPER_MAGIC;
23160 sb->s_op = &shmem_ops;
23161 sb->s_time_gran = 1;
23162 #ifdef CONFIG_TMPFS_XATTR
23163 diff -NurpP --minimal linux-3.13.10/mm/slab.c linux-3.13.10-vs2.3.6.11/mm/slab.c
23164 --- linux-3.13.10/mm/slab.c 2014-01-22 20:39:14.000000000 +0000
23165 +++ linux-3.13.10-vs2.3.6.11/mm/slab.c 2014-01-31 20:38:04.000000000 +0000
23166 @@ -322,6 +322,8 @@ static void kmem_cache_node_init(struct
23167 #define STATS_INC_FREEMISS(x) do { } while (0)
23170 +#include "slab_vs.h"
23175 @@ -3240,6 +3242,7 @@ slab_alloc_node(struct kmem_cache *cache
23176 /* ___cache_alloc_node can fall back to other nodes */
23177 ptr = ____cache_alloc_node(cachep, flags, nodeid);
23179 + vx_slab_alloc(cachep, flags);
23180 local_irq_restore(save_flags);
23181 ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23182 kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23183 @@ -3430,6 +3433,7 @@ static inline void __cache_free(struct k
23185 kmemleak_free_recursive(objp, cachep->flags);
23186 objp = cache_free_debugcheck(cachep, objp, caller);
23187 + vx_slab_free(cachep);
23189 kmemcheck_slab_free(cachep, objp, cachep->object_size);
23191 diff -NurpP --minimal linux-3.13.10/mm/slab_vs.h linux-3.13.10-vs2.3.6.11/mm/slab_vs.h
23192 --- linux-3.13.10/mm/slab_vs.h 1970-01-01 00:00:00.000000000 +0000
23193 +++ linux-3.13.10-vs2.3.6.11/mm/slab_vs.h 2014-01-31 20:38:04.000000000 +0000
23196 +#include <linux/vserver/context.h>
23198 +#include <linux/vs_context.h>
23201 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23203 + int what = gfp_zone(cachep->allocflags);
23204 + struct vx_info *vxi = current_vx_info();
23209 + atomic_add(cachep->size, &vxi->cacct.slab[what]);
23213 +void vx_slab_free(struct kmem_cache *cachep)
23215 + int what = gfp_zone(cachep->allocflags);
23216 + struct vx_info *vxi = current_vx_info();
23221 + atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23224 diff -NurpP --minimal linux-3.13.10/mm/swapfile.c linux-3.13.10-vs2.3.6.11/mm/swapfile.c
23225 --- linux-3.13.10/mm/swapfile.c 2014-04-17 01:12:40.000000000 +0000
23226 +++ linux-3.13.10-vs2.3.6.11/mm/swapfile.c 2014-02-25 11:26:10.000000000 +0000
23228 #include <asm/tlbflush.h>
23229 #include <linux/swapops.h>
23230 #include <linux/page_cgroup.h>
23231 +#include <linux/vs_base.h>
23233 static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23235 @@ -2042,6 +2043,16 @@ static int swap_show(struct seq_file *sw
23237 if (si == SEQ_START_TOKEN) {
23238 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23239 + if (vx_flags(VXF_VIRT_MEM, 0)) {
23240 + struct sysinfo si;
23242 + vx_vsi_swapinfo(&si);
23243 + if (si.totalswap < (1 << 10))
23245 + seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23246 + "hdv0", "partition", si.totalswap >> 10,
23247 + (si.totalswap - si.freeswap) >> 10, -1);
23252 @@ -2589,6 +2600,8 @@ void si_swapinfo(struct sysinfo *val)
23253 val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
23254 val->totalswap = total_swap_pages + nr_to_be_unused;
23255 spin_unlock(&swap_lock);
23256 + if (vx_flags(VXF_VIRT_MEM, 0))
23257 + vx_vsi_swapinfo(val);
23261 diff -NurpP --minimal linux-3.13.10/net/bridge/br_multicast.c linux-3.13.10-vs2.3.6.11/net/bridge/br_multicast.c
23262 --- linux-3.13.10/net/bridge/br_multicast.c 2014-04-17 01:12:40.000000000 +0000
23263 +++ linux-3.13.10-vs2.3.6.11/net/bridge/br_multicast.c 2014-04-17 01:17:11.000000000 +0000
23264 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
23265 ip6h->hop_limit = 1;
23266 ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23267 if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23269 + &ip6h->saddr, NULL)) {
23273 diff -NurpP --minimal linux-3.13.10/net/core/dev.c linux-3.13.10-vs2.3.6.11/net/core/dev.c
23274 --- linux-3.13.10/net/core/dev.c 2014-04-17 01:12:41.000000000 +0000
23275 +++ linux-3.13.10-vs2.3.6.11/net/core/dev.c 2014-03-12 15:51:08.000000000 +0000
23276 @@ -122,6 +122,7 @@
23277 #include <linux/in.h>
23278 #include <linux/jhash.h>
23279 #include <linux/random.h>
23280 +#include <linux/vs_inet.h>
23281 #include <trace/events/napi.h>
23282 #include <trace/events/net.h>
23283 #include <trace/events/skb.h>
23284 @@ -669,7 +670,8 @@ struct net_device *__dev_get_by_name(str
23285 struct hlist_head *head = dev_name_hash(net, name);
23287 hlist_for_each_entry(dev, head, name_hlist)
23288 - if (!strncmp(dev->name, name, IFNAMSIZ))
23289 + if (!strncmp(dev->name, name, IFNAMSIZ) &&
23290 + nx_dev_visible(current_nx_info(), dev))
23294 @@ -694,7 +696,8 @@ struct net_device *dev_get_by_name_rcu(s
23295 struct hlist_head *head = dev_name_hash(net, name);
23297 hlist_for_each_entry_rcu(dev, head, name_hlist)
23298 - if (!strncmp(dev->name, name, IFNAMSIZ))
23299 + if (!strncmp(dev->name, name, IFNAMSIZ) &&
23300 + nx_dev_visible(current_nx_info(), dev))
23304 @@ -744,7 +747,8 @@ struct net_device *__dev_get_by_index(st
23305 struct hlist_head *head = dev_index_hash(net, ifindex);
23307 hlist_for_each_entry(dev, head, index_hlist)
23308 - if (dev->ifindex == ifindex)
23309 + if ((dev->ifindex == ifindex) &&
23310 + nx_dev_visible(current_nx_info(), dev))
23314 @@ -762,7 +766,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
23315 * about locking. The caller must hold RCU lock.
23318 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23319 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
23321 struct net_device *dev;
23322 struct hlist_head *head = dev_index_hash(net, ifindex);
23323 @@ -773,6 +777,16 @@ struct net_device *dev_get_by_index_rcu(
23327 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
23329 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23331 + struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
23333 + if (nx_dev_visible(current_nx_info(), dev))
23337 EXPORT_SYMBOL(dev_get_by_index_rcu);
23340 @@ -855,7 +869,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
23342 for_each_netdev_rcu(net, dev)
23343 if (dev->type == type &&
23344 - !memcmp(dev->dev_addr, ha, dev->addr_len))
23345 + !memcmp(dev->dev_addr, ha, dev->addr_len) &&
23346 + nx_dev_visible(current_nx_info(), dev))
23350 @@ -867,9 +882,11 @@ struct net_device *__dev_getfirstbyhwtyp
23351 struct net_device *dev;
23354 - for_each_netdev(net, dev)
23355 - if (dev->type == type)
23356 + for_each_netdev(net, dev) {
23357 + if ((dev->type == type) &&
23358 + nx_dev_visible(current_nx_info(), dev))
23364 @@ -881,7 +898,8 @@ struct net_device *dev_getfirstbyhwtype(
23367 for_each_netdev_rcu(net, dev)
23368 - if (dev->type == type) {
23369 + if ((dev->type == type) &&
23370 + nx_dev_visible(current_nx_info(), dev)) {
23374 @@ -909,7 +927,8 @@ struct net_device *dev_get_by_flags_rcu(
23377 for_each_netdev_rcu(net, dev) {
23378 - if (((dev->flags ^ if_flags) & mask) == 0) {
23379 + if ((((dev->flags ^ if_flags) & mask) == 0) &&
23380 + nx_dev_visible(current_nx_info(), dev)) {
23384 @@ -987,6 +1006,8 @@ static int __dev_alloc_name(struct net *
23386 if (i < 0 || i >= max_netdevices)
23388 + if (!nx_dev_visible(current_nx_info(), d))
23391 /* avoid cases where sscanf is not exact inverse of printf */
23392 snprintf(buf, IFNAMSIZ, name, i);
23393 diff -NurpP --minimal linux-3.13.10/net/core/net-procfs.c linux-3.13.10-vs2.3.6.11/net/core/net-procfs.c
23394 --- linux-3.13.10/net/core/net-procfs.c 2013-11-25 15:45:09.000000000 +0000
23395 +++ linux-3.13.10-vs2.3.6.11/net/core/net-procfs.c 2014-01-31 20:38:04.000000000 +0000
23397 #include <linux/netdevice.h>
23398 #include <linux/proc_fs.h>
23399 #include <linux/seq_file.h>
23400 +#include <linux/vs_inet.h>
23401 #include <net/wext.h>
23403 #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
23404 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
23405 static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
23407 struct rtnl_link_stats64 temp;
23408 - const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
23409 + const struct rtnl_link_stats64 *stats;
23411 + /* device visible inside network context? */
23412 + if (!nx_dev_visible(current_nx_info(), dev))
23415 + stats = dev_get_stats(dev, &temp);
23416 seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
23417 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
23418 dev->name, stats->rx_bytes, stats->rx_packets,
23419 diff -NurpP --minimal linux-3.13.10/net/core/rtnetlink.c linux-3.13.10-vs2.3.6.11/net/core/rtnetlink.c
23420 --- linux-3.13.10/net/core/rtnetlink.c 2014-04-17 01:12:41.000000000 +0000
23421 +++ linux-3.13.10-vs2.3.6.11/net/core/rtnetlink.c 2014-04-17 01:17:11.000000000 +0000
23422 @@ -1090,6 +1090,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
23423 hlist_for_each_entry_rcu(dev, head, index_hlist) {
23426 + if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
23428 err = rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
23429 NETLINK_CB(cb->skb).portid,
23430 cb->nlh->nlmsg_seq, 0,
23431 @@ -1992,6 +1994,9 @@ void rtmsg_ifinfo(int type, struct net_d
23432 int err = -ENOBUFS;
23433 size_t if_info_size;
23435 + if (!nx_dev_visible(current_nx_info(), dev))
23438 skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), flags);
23441 diff -NurpP --minimal linux-3.13.10/net/core/sock.c linux-3.13.10-vs2.3.6.11/net/core/sock.c
23442 --- linux-3.13.10/net/core/sock.c 2014-04-17 01:12:41.000000000 +0000
23443 +++ linux-3.13.10-vs2.3.6.11/net/core/sock.c 2014-04-17 01:17:11.000000000 +0000
23444 @@ -133,6 +133,10 @@
23445 #include <net/netprio_cgroup.h>
23447 #include <linux/filter.h>
23448 +#include <linux/vs_socket.h>
23449 +#include <linux/vs_limit.h>
23450 +#include <linux/vs_context.h>
23451 +#include <linux/vs_network.h>
23453 #include <trace/events/sock.h>
23455 @@ -1279,6 +1283,8 @@ static struct sock *sk_prot_alloc(struct
23457 sk_tx_queue_clear(sk);
23459 + sock_vx_init(sk);
23460 + sock_nx_init(sk);
23464 @@ -1387,6 +1393,11 @@ static void __sk_free(struct sock *sk)
23465 put_cred(sk->sk_peer_cred);
23466 put_pid(sk->sk_peer_pid);
23467 put_net(sock_net(sk));
23469 + clr_vx_info(&sk->sk_vx_info);
23471 + clr_nx_info(&sk->sk_nx_info);
23473 sk_prot_free(sk->sk_prot_creator, sk);
23476 @@ -1447,6 +1458,8 @@ struct sock *sk_clone_lock(const struct
23479 get_net(sock_net(newsk));
23480 + sock_vx_init(newsk);
23481 + sock_nx_init(newsk);
23482 sk_node_init(&newsk->sk_node);
23483 sock_lock_init(newsk);
23484 bh_lock_sock(newsk);
23485 @@ -1503,6 +1516,12 @@ struct sock *sk_clone_lock(const struct
23487 atomic_set(&newsk->sk_refcnt, 2);
23489 + set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
23490 + newsk->sk_xid = sk->sk_xid;
23491 + vx_sock_inc(newsk);
23492 + set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
23493 + newsk->sk_nid = sk->sk_nid;
23496 * Increment the counter in the same struct proto as the master
23497 * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
23498 @@ -2340,6 +2359,12 @@ void sock_init_data(struct socket *sock,
23500 sk->sk_stamp = ktime_set(-1L, 0);
23502 + set_vx_info(&sk->sk_vx_info, current_vx_info());
23503 + sk->sk_xid = vx_current_xid();
23505 + set_nx_info(&sk->sk_nx_info, current_nx_info());
23506 + sk->sk_nid = nx_current_nid();
23508 #ifdef CONFIG_NET_RX_BUSY_POLL
23509 sk->sk_napi_id = 0;
23510 sk->sk_ll_usec = sysctl_net_busy_read;
23511 diff -NurpP --minimal linux-3.13.10/net/ipv4/af_inet.c linux-3.13.10-vs2.3.6.11/net/ipv4/af_inet.c
23512 --- linux-3.13.10/net/ipv4/af_inet.c 2014-04-17 01:12:41.000000000 +0000
23513 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/af_inet.c 2014-04-17 01:17:11.000000000 +0000
23514 @@ -118,6 +118,7 @@
23515 #ifdef CONFIG_IP_MROUTE
23516 #include <linux/mroute.h>
23518 +#include <linux/vs_limit.h>
23521 /* The inetsw table contains everything that inet_create needs to
23522 @@ -309,10 +310,13 @@ lookup_protocol:
23526 + if ((protocol == IPPROTO_ICMP) &&
23527 + nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
23529 if (sock->type == SOCK_RAW && !kern &&
23530 !ns_capable(net->user_ns, CAP_NET_RAW))
23531 goto out_rcu_unlock;
23534 sock->ops = answer->ops;
23535 answer_prot = answer->prot;
23536 answer_no_check = answer->no_check;
23537 @@ -433,6 +437,7 @@ int inet_bind(struct socket *sock, struc
23538 struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
23539 struct sock *sk = sock->sk;
23540 struct inet_sock *inet = inet_sk(sk);
23541 + struct nx_v4_sock_addr nsa;
23542 struct net *net = sock_net(sk);
23543 unsigned short snum;
23545 @@ -457,7 +462,11 @@ int inet_bind(struct socket *sock, struc
23549 - chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
23550 + err = v4_map_sock_addr(inet, addr, &nsa);
23554 + chk_addr_ret = inet_addr_type(net, nsa.saddr);
23556 /* Not specified by any standard per-se, however it breaks too
23557 * many applications when removed. It is unfortunate since
23558 @@ -469,7 +478,7 @@ int inet_bind(struct socket *sock, struc
23559 err = -EADDRNOTAVAIL;
23560 if (!sysctl_ip_nonlocal_bind &&
23561 !(inet->freebind || inet->transparent) &&
23562 - addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
23563 + nsa.saddr != htonl(INADDR_ANY) &&
23564 chk_addr_ret != RTN_LOCAL &&
23565 chk_addr_ret != RTN_MULTICAST &&
23566 chk_addr_ret != RTN_BROADCAST)
23567 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
23568 if (sk->sk_state != TCP_CLOSE || inet->inet_num)
23569 goto out_release_sock;
23571 - inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23572 + v4_set_sock_addr(inet, &nsa);
23573 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23574 inet->inet_saddr = 0; /* Use device */
23576 @@ -714,11 +723,13 @@ int inet_getname(struct socket *sock, st
23579 sin->sin_port = inet->inet_dport;
23580 - sin->sin_addr.s_addr = inet->inet_daddr;
23581 + sin->sin_addr.s_addr =
23582 + nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
23584 __be32 addr = inet->inet_rcv_saddr;
23586 addr = inet->inet_saddr;
23587 + addr = nx_map_sock_lback(sk->sk_nx_info, addr);
23588 sin->sin_port = inet->inet_sport;
23589 sin->sin_addr.s_addr = addr;
23591 diff -NurpP --minimal linux-3.13.10/net/ipv4/arp.c linux-3.13.10-vs2.3.6.11/net/ipv4/arp.c
23592 --- linux-3.13.10/net/ipv4/arp.c 2013-11-25 15:47:06.000000000 +0000
23593 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/arp.c 2014-01-31 20:38:04.000000000 +0000
23594 @@ -1336,6 +1336,7 @@ static void arp_format_neigh_entry(struc
23595 struct net_device *dev = n->dev;
23596 int hatype = dev->type;
23598 + /* FIXME: check for network context */
23599 read_lock(&n->lock);
23600 /* Convert hardware address to XX:XX:XX:XX ... form. */
23601 #if IS_ENABLED(CONFIG_AX25)
23602 @@ -1367,6 +1368,7 @@ static void arp_format_pneigh_entry(stru
23603 int hatype = dev ? dev->type : 0;
23606 + /* FIXME: check for network context */
23607 sprintf(tbuf, "%pI4", n->key);
23608 seq_printf(seq, "%-16s 0x%-10x0x%-10x%s * %s\n",
23609 tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
23610 diff -NurpP --minimal linux-3.13.10/net/ipv4/devinet.c linux-3.13.10-vs2.3.6.11/net/ipv4/devinet.c
23611 --- linux-3.13.10/net/ipv4/devinet.c 2014-04-17 01:12:41.000000000 +0000
23612 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/devinet.c 2014-03-12 15:51:08.000000000 +0000
23613 @@ -527,6 +527,7 @@ struct in_device *inetdev_by_index(struc
23615 EXPORT_SYMBOL(inetdev_by_index);
23618 /* Called only from RTNL semaphored context. No locks. */
23620 struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
23621 @@ -947,6 +948,8 @@ int devinet_ioctl(struct net *net, unsig
23623 in_dev = __in_dev_get_rtnl(dev);
23625 + struct nx_info *nxi = current_nx_info();
23627 if (tryaddrmatch) {
23628 /* Matthias Andree */
23629 /* compare label and address (4.4BSD style) */
23630 @@ -955,6 +958,8 @@ int devinet_ioctl(struct net *net, unsig
23631 This is checked above. */
23632 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23633 ifap = &ifa->ifa_next) {
23634 + if (!nx_v4_ifa_visible(nxi, ifa))
23636 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
23637 sin_orig.sin_addr.s_addr ==
23639 @@ -967,9 +972,12 @@ int devinet_ioctl(struct net *net, unsig
23640 comparing just the label */
23642 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23643 - ifap = &ifa->ifa_next)
23644 + ifap = &ifa->ifa_next) {
23645 + if (!nx_v4_ifa_visible(nxi, ifa))
23647 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
23653 @@ -1123,6 +1131,8 @@ static int inet_gifconf(struct net_devic
23656 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
23657 + if (!nx_v4_ifa_visible(current_nx_info(), ifa))
23660 done += sizeof(ifr);
23662 @@ -1524,6 +1534,7 @@ static int inet_dump_ifaddr(struct sk_bu
23663 struct net_device *dev;
23664 struct in_device *in_dev;
23665 struct in_ifaddr *ifa;
23666 + struct sock *sk = skb->sk;
23667 struct hlist_head *head;
23670 @@ -1547,6 +1558,8 @@ static int inet_dump_ifaddr(struct sk_bu
23672 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
23673 ifa = ifa->ifa_next, ip_idx++) {
23674 + if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
23676 if (ip_idx < s_ip_idx)
23678 if (inet_fill_ifaddr(skb, ifa,
23679 diff -NurpP --minimal linux-3.13.10/net/ipv4/fib_trie.c linux-3.13.10-vs2.3.6.11/net/ipv4/fib_trie.c
23680 --- linux-3.13.10/net/ipv4/fib_trie.c 2014-01-22 20:39:15.000000000 +0000
23681 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/fib_trie.c 2014-01-31 20:38:04.000000000 +0000
23682 @@ -2530,6 +2530,7 @@ static int fib_route_seq_show(struct seq
23684 seq_setwidth(seq, 127);
23686 + /* FIXME: check for network context? */
23689 "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
23690 diff -NurpP --minimal linux-3.13.10/net/ipv4/inet_connection_sock.c linux-3.13.10-vs2.3.6.11/net/ipv4/inet_connection_sock.c
23691 --- linux-3.13.10/net/ipv4/inet_connection_sock.c 2014-01-22 20:39:15.000000000 +0000
23692 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_connection_sock.c 2014-02-01 00:33:11.000000000 +0000
23693 @@ -45,6 +45,37 @@ void inet_get_local_port_range(struct ne
23695 EXPORT_SYMBOL(inet_get_local_port_range);
23697 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
23699 + __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr,
23700 + sk2_rcv_saddr = sk2->sk_rcv_saddr;
23702 + if (inet_v6_ipv6only(sk2))
23705 + if (sk1_rcv_saddr &&
23707 + sk1_rcv_saddr == sk2_rcv_saddr)
23710 + if (sk1_rcv_saddr &&
23711 + !sk2_rcv_saddr &&
23712 + v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
23715 + if (sk2_rcv_saddr &&
23716 + !sk1_rcv_saddr &&
23717 + v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
23720 + if (!sk1_rcv_saddr &&
23721 + !sk2_rcv_saddr &&
23722 + nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
23728 int inet_csk_bind_conflict(const struct sock *sk,
23729 const struct inet_bind_bucket *tb, bool relax)
23731 @@ -72,15 +103,13 @@ int inet_csk_bind_conflict(const struct
23732 (sk2->sk_state != TCP_TIME_WAIT &&
23733 !uid_eq(uid, sock_i_uid(sk2))))) {
23735 - if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23736 - sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23737 + if (ipv4_rcv_saddr_equal(sk, sk2))
23740 if (!relax && reuse && sk2->sk_reuse &&
23741 sk2->sk_state != TCP_LISTEN) {
23743 - if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23744 - sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23745 + if (ipv4_rcv_saddr_equal(sk, sk2))
23749 diff -NurpP --minimal linux-3.13.10/net/ipv4/inet_diag.c linux-3.13.10-vs2.3.6.11/net/ipv4/inet_diag.c
23750 --- linux-3.13.10/net/ipv4/inet_diag.c 2014-02-01 02:17:51.000000000 +0000
23751 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_diag.c 2014-02-01 02:32:22.000000000 +0000
23754 #include <linux/inet.h>
23755 #include <linux/stddef.h>
23756 +#include <linux/vs_network.h>
23757 +#include <linux/vs_inet.h>
23759 #include <linux/inet_diag.h>
23760 #include <linux/sock_diag.h>
23761 @@ -110,8 +112,10 @@ int inet_sk_diag_fill(struct sock *sk, s
23762 memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23763 memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23765 - r->id.idiag_src[0] = inet->inet_rcv_saddr;
23766 - r->id.idiag_dst[0] = inet->inet_daddr;
23767 + r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
23768 + inet->inet_rcv_saddr);
23769 + r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
23770 + inet->inet_daddr);
23772 if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
23774 @@ -254,8 +258,8 @@ static int inet_twsk_diag_fill(struct in
23775 memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23776 memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23778 - r->id.idiag_src[0] = tw->tw_rcv_saddr;
23779 - r->id.idiag_dst[0] = tw->tw_daddr;
23780 + r->id.idiag_src[0] = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
23781 + r->id.idiag_dst[0] = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
23783 r->idiag_state = tw->tw_substate;
23784 r->idiag_timer = 3;
23785 @@ -298,12 +302,14 @@ int inet_diag_dump_one_icsk(struct inet_
23788 if (req->sdiag_family == AF_INET) {
23789 + /* TODO: lback */
23790 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
23791 req->id.idiag_dport, req->id.idiag_src[0],
23792 req->id.idiag_sport, req->id.idiag_if);
23794 #if IS_ENABLED(CONFIG_IPV6)
23795 else if (req->sdiag_family == AF_INET6) {
23796 + /* TODO: lback */
23797 sk = inet6_lookup(net, hashinfo,
23798 (struct in6_addr *)req->id.idiag_dst,
23799 req->id.idiag_dport,
23800 @@ -501,6 +507,7 @@ int inet_diag_bc_sk(const struct nlattr
23804 + /* TODO: lback */
23805 entry.saddr = &inet->inet_rcv_saddr;
23806 entry.daddr = &inet->inet_daddr;
23808 @@ -659,6 +666,7 @@ static int inet_twsk_diag_dump(struct so
23812 + /* TODO: lback */
23813 entry.saddr = &tw->tw_rcv_saddr;
23814 entry.daddr = &tw->tw_daddr;
23816 @@ -741,8 +749,8 @@ static int inet_diag_fill_req(struct sk_
23817 memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23818 memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23820 - r->id.idiag_src[0] = ireq->ir_loc_addr;
23821 - r->id.idiag_dst[0] = ireq->ir_rmt_addr;
23822 + r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_loc_addr);
23823 + r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_rmt_addr);
23825 r->idiag_expires = jiffies_to_msecs(tmo);
23826 r->idiag_rqueue = 0;
23827 @@ -806,6 +814,7 @@ static int inet_diag_dump_reqs(struct sk
23831 + /* TODO: lback */
23833 inet_diag_req_addrs(sk, req, &entry);
23834 entry.dport = ntohs(ireq->ir_rmt_port);
23835 @@ -862,6 +871,8 @@ void inet_diag_dump_icsk(struct inet_has
23836 if (!net_eq(sock_net(sk), net))
23839 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23844 @@ -934,6 +945,8 @@ skip_listen_ht:
23846 if (!net_eq(sock_net(sk), net))
23848 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23852 state = (sk->sk_state == TCP_TIME_WAIT) ?
23853 diff -NurpP --minimal linux-3.13.10/net/ipv4/inet_hashtables.c linux-3.13.10-vs2.3.6.11/net/ipv4/inet_hashtables.c
23854 --- linux-3.13.10/net/ipv4/inet_hashtables.c 2014-01-22 20:39:15.000000000 +0000
23855 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_hashtables.c 2014-01-31 20:38:04.000000000 +0000
23857 #include <net/inet_connection_sock.h>
23858 #include <net/inet_hashtables.h>
23859 #include <net/secure_seq.h>
23860 +#include <net/route.h>
23861 #include <net/ip.h>
23863 static unsigned int inet_ehashfn(struct net *net, const __be32 laddr,
23864 @@ -181,6 +182,11 @@ static inline int compute_score(struct s
23865 if (rcv_saddr != daddr)
23869 + /* block non nx_info ips */
23870 + if (!v4_addr_in_nx_info(sk->sk_nx_info,
23871 + daddr, NXA_MASK_BIND))
23874 if (sk->sk_bound_dev_if) {
23875 if (sk->sk_bound_dev_if != dif)
23876 @@ -198,7 +204,6 @@ static inline int compute_score(struct s
23877 * wildcarded during the search since they can never be otherwise.
23881 struct sock *__inet_lookup_listener(struct net *net,
23882 struct inet_hashinfo *hashinfo,
23883 const __be32 saddr, __be16 sport,
23884 @@ -234,6 +239,7 @@ begin:
23885 phash = next_pseudo_random32(phash);
23890 * if the nulls value we got at the end of this lookup is
23891 * not the expected one, we must restart lookup.
23892 diff -NurpP --minimal linux-3.13.10/net/ipv4/netfilter.c linux-3.13.10-vs2.3.6.11/net/ipv4/netfilter.c
23893 --- linux-3.13.10/net/ipv4/netfilter.c 2013-07-14 17:01:37.000000000 +0000
23894 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/netfilter.c 2014-01-31 20:38:04.000000000 +0000
23896 #include <linux/skbuff.h>
23897 #include <linux/gfp.h>
23898 #include <linux/export.h>
23899 -#include <net/route.h>
23900 +// #include <net/route.h>
23901 #include <net/xfrm.h>
23902 #include <net/ip.h>
23903 #include <net/netfilter/nf_queue.h>
23904 diff -NurpP --minimal linux-3.13.10/net/ipv4/raw.c linux-3.13.10-vs2.3.6.11/net/ipv4/raw.c
23905 --- linux-3.13.10/net/ipv4/raw.c 2014-01-22 20:39:15.000000000 +0000
23906 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/raw.c 2014-01-31 20:38:04.000000000 +0000
23907 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
23909 if (net_eq(sock_net(sk), net) && inet->inet_num == num &&
23910 !(inet->inet_daddr && inet->inet_daddr != raddr) &&
23911 - !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
23912 + v4_sock_addr_match(sk->sk_nx_info, inet, laddr) &&
23913 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23914 goto found; /* gotcha */
23916 @@ -397,6 +397,12 @@ static int raw_send_hdrinc(struct sock *
23917 icmp_out_count(net, ((struct icmphdr *)
23918 skb_transport_header(skb))->type);
23921 + if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
23922 + sk->sk_nx_info &&
23923 + !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
23926 err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
23927 rt->dst.dev, dst_output);
23929 @@ -585,6 +591,16 @@ static int raw_sendmsg(struct kiocb *ioc
23933 + if (sk->sk_nx_info) {
23934 + rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
23935 + if (IS_ERR(rt)) {
23936 + err = PTR_ERR(rt);
23943 security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
23944 rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
23946 @@ -661,17 +677,19 @@ static int raw_bind(struct sock *sk, str
23948 struct inet_sock *inet = inet_sk(sk);
23949 struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
23950 + struct nx_v4_sock_addr nsa = { 0 };
23954 if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
23956 - chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
23957 + v4_map_sock_addr(inet, addr, &nsa);
23958 + chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
23959 ret = -EADDRNOTAVAIL;
23960 - if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
23961 + if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
23962 chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
23964 - inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23965 + v4_set_sock_addr(inet, &nsa);
23966 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23967 inet->inet_saddr = 0; /* Use device */
23969 @@ -720,7 +738,8 @@ static int raw_recvmsg(struct kiocb *ioc
23970 /* Copy the address. */
23972 sin->sin_family = AF_INET;
23973 - sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
23974 + sin->sin_addr.s_addr =
23975 + nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
23977 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
23978 *addr_len = sizeof(*sin);
23979 @@ -916,7 +935,8 @@ static struct sock *raw_get_first(struct
23980 for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
23982 sk_for_each(sk, &state->h->ht[state->bucket])
23983 - if (sock_net(sk) == seq_file_net(seq))
23984 + if ((sock_net(sk) == seq_file_net(seq)) &&
23985 + nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23989 @@ -932,7 +952,8 @@ static struct sock *raw_get_next(struct
23993 - } while (sk && sock_net(sk) != seq_file_net(seq));
23994 + } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
23995 + !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
23997 if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
23998 sk = sk_head(&state->h->ht[state->bucket]);
23999 diff -NurpP --minimal linux-3.13.10/net/ipv4/route.c linux-3.13.10-vs2.3.6.11/net/ipv4/route.c
24000 --- linux-3.13.10/net/ipv4/route.c 2014-04-17 01:12:41.000000000 +0000
24001 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/route.c 2014-03-12 15:51:08.000000000 +0000
24002 @@ -2063,7 +2063,7 @@ struct rtable *__ip_route_output_key(str
24005 if (fl4->flowi4_oif) {
24006 - dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24007 + dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24008 rth = ERR_PTR(-ENODEV);
24009 if (dev_out == NULL)
24011 diff -NurpP --minimal linux-3.13.10/net/ipv4/tcp.c linux-3.13.10-vs2.3.6.11/net/ipv4/tcp.c
24012 --- linux-3.13.10/net/ipv4/tcp.c 2014-04-17 01:12:41.000000000 +0000
24013 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp.c 2014-04-17 01:17:11.000000000 +0000
24014 @@ -268,6 +268,7 @@
24015 #include <linux/crypto.h>
24016 #include <linux/time.h>
24017 #include <linux/slab.h>
24018 +#include <linux/in.h>
24020 #include <net/icmp.h>
24021 #include <net/inet_common.h>
24022 diff -NurpP --minimal linux-3.13.10/net/ipv4/tcp_ipv4.c linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_ipv4.c
24023 --- linux-3.13.10/net/ipv4/tcp_ipv4.c 2014-04-17 01:12:41.000000000 +0000
24024 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_ipv4.c 2014-04-17 01:17:11.000000000 +0000
24025 @@ -2227,6 +2227,12 @@ static void *listening_get_next(struct s
24026 req = req->dl_next;
24029 + vxdprintk(VXD_CBIT(net, 6),
24030 + "sk,req: %p [#%d] (from %d)", req->sk,
24031 + (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24033 + !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24035 if (req->rsk_ops->family == st->family) {
24038 @@ -2251,6 +2257,10 @@ get_req:
24041 sk_nulls_for_each_from(sk, node) {
24042 + vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24043 + sk, sk->sk_nid, nx_current_nid());
24044 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24046 if (!net_eq(sock_net(sk), net))
24048 if (sk->sk_family == st->family) {
24049 @@ -2325,6 +2335,11 @@ static void *established_get_first(struc
24051 spin_lock_bh(lock);
24052 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24053 + vxdprintk(VXD_CBIT(net, 6),
24054 + "sk,egf: %p [#%d] (from %d)",
24055 + sk, sk->sk_nid, nx_current_nid());
24056 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24058 if (sk->sk_family != st->family ||
24059 !net_eq(sock_net(sk), net)) {
24061 @@ -2351,6 +2366,11 @@ static void *established_get_next(struct
24062 sk = sk_nulls_next(sk);
24064 sk_nulls_for_each_from(sk, node) {
24065 + vxdprintk(VXD_CBIT(net, 6),
24066 + "sk,egn: %p [#%d] (from %d)",
24067 + sk, sk->sk_nid, nx_current_nid());
24068 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24070 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24073 @@ -2549,9 +2569,9 @@ static void get_openreq4(const struct so
24074 seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24075 " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d %pK",
24077 - ireq->ir_loc_addr,
24078 + nx_map_sock_lback(current_nx_info(), ireq->ir_loc_addr),
24079 ntohs(inet_sk(sk)->inet_sport),
24080 - ireq->ir_rmt_addr,
24081 + nx_map_sock_lback(current_nx_info(), ireq->ir_rmt_addr),
24082 ntohs(ireq->ir_rmt_port),
24084 0, 0, /* could print option size, but that is af dependent. */
24085 @@ -2573,8 +2593,8 @@ static void get_tcp4_sock(struct sock *s
24086 const struct inet_connection_sock *icsk = inet_csk(sk);
24087 const struct inet_sock *inet = inet_sk(sk);
24088 struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24089 - __be32 dest = inet->inet_daddr;
24090 - __be32 src = inet->inet_rcv_saddr;
24091 + __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24092 + __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24093 __u16 destp = ntohs(inet->inet_dport);
24094 __u16 srcp = ntohs(inet->inet_sport);
24096 @@ -2631,8 +2651,8 @@ static void get_timewait4_sock(const str
24098 s32 delta = tw->tw_ttd - inet_tw_time_stamp();
24100 - dest = tw->tw_daddr;
24101 - src = tw->tw_rcv_saddr;
24102 + dest = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24103 + src = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24104 destp = ntohs(tw->tw_dport);
24105 srcp = ntohs(tw->tw_sport);
24107 diff -NurpP --minimal linux-3.13.10/net/ipv4/tcp_minisocks.c linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_minisocks.c
24108 --- linux-3.13.10/net/ipv4/tcp_minisocks.c 2014-01-22 20:39:15.000000000 +0000
24109 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_minisocks.c 2014-01-31 20:38:04.000000000 +0000
24111 #include <linux/slab.h>
24112 #include <linux/sysctl.h>
24113 #include <linux/workqueue.h>
24114 +#include <linux/vs_limit.h>
24115 +#include <linux/vs_socket.h>
24116 +#include <linux/vs_context.h>
24117 #include <net/tcp.h>
24118 #include <net/inet_common.h>
24119 #include <net/xfrm.h>
24120 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int
24121 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24122 tcptw->tw_ts_offset = tp->tsoffset;
24124 + tw->tw_xid = sk->sk_xid;
24125 + tw->tw_vx_info = NULL;
24126 + tw->tw_nid = sk->sk_nid;
24127 + tw->tw_nx_info = NULL;
24129 #if IS_ENABLED(CONFIG_IPV6)
24130 if (tw->tw_family == PF_INET6) {
24131 struct ipv6_pinfo *np = inet6_sk(sk);
24132 diff -NurpP --minimal linux-3.13.10/net/ipv4/udp.c linux-3.13.10-vs2.3.6.11/net/ipv4/udp.c
24133 --- linux-3.13.10/net/ipv4/udp.c 2014-01-22 20:39:15.000000000 +0000
24134 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/udp.c 2014-01-31 22:20:27.000000000 +0000
24135 @@ -308,14 +308,7 @@ fail:
24137 EXPORT_SYMBOL(udp_lib_get_port);
24139 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24141 - struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24143 - return (!ipv6_only_sock(sk2) &&
24144 - (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24145 - inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24147 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24149 static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24151 @@ -350,6 +343,11 @@ static inline int compute_score(struct s
24152 if (inet->inet_rcv_saddr != daddr)
24156 + /* block non nx_info ips */
24157 + if (!v4_addr_in_nx_info(sk->sk_nx_info,
24158 + daddr, NXA_MASK_BIND))
24161 if (inet->inet_daddr) {
24162 if (inet->inet_daddr != saddr)
24163 @@ -472,6 +470,7 @@ begin:
24168 /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24169 * harder than this. -DaveM
24171 @@ -518,6 +517,11 @@ begin:
24172 sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24173 score = compute_score(sk, net, saddr, hnum, sport,
24174 daddr, dport, dif);
24175 + /* FIXME: disabled?
24176 + if (score == 9) {
24180 if (score > badness) {
24183 @@ -542,6 +546,7 @@ begin:
24184 if (get_nulls_value(node) != slot)
24189 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24191 @@ -551,6 +556,7 @@ begin:
24199 @@ -585,7 +591,7 @@ static inline bool __udp_is_mcast_sock(s
24200 udp_sk(sk)->udp_port_hash != hnum ||
24201 (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24202 (inet->inet_dport != rmt_port && inet->inet_dport) ||
24203 - (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||
24204 + !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24205 ipv6_only_sock(sk) ||
24206 (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24208 @@ -989,6 +995,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24209 inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24210 faddr, saddr, dport, inet->inet_sport);
24212 + if (sk->sk_nx_info) {
24213 + rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24214 + if (IS_ERR(rt)) {
24215 + err = PTR_ERR(rt);
24222 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24223 rt = ip_route_output_flow(net, fl4, sk);
24225 @@ -1293,7 +1309,8 @@ try_again:
24227 sin->sin_family = AF_INET;
24228 sin->sin_port = udp_hdr(skb)->source;
24229 - sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24230 + sin->sin_addr.s_addr = nx_map_sock_lback(
24231 + skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24232 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24233 *addr_len = sizeof(*sin);
24235 @@ -2223,6 +2240,8 @@ static struct sock *udp_get_first(struct
24236 sk_nulls_for_each(sk, node, &hslot->head) {
24237 if (!net_eq(sock_net(sk), net))
24239 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24241 if (sk->sk_family == state->family)
24244 @@ -2240,7 +2259,9 @@ static struct sock *udp_get_next(struct
24247 sk = sk_nulls_next(sk);
24248 - } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
24249 + } while (sk && (!net_eq(sock_net(sk), net) ||
24250 + sk->sk_family != state->family ||
24251 + !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24254 if (state->bucket <= state->udp_table->mask)
24255 @@ -2336,8 +2357,8 @@ static void udp4_format_sock(struct sock
24258 struct inet_sock *inet = inet_sk(sp);
24259 - __be32 dest = inet->inet_daddr;
24260 - __be32 src = inet->inet_rcv_saddr;
24261 + __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24262 + __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24263 __u16 destp = ntohs(inet->inet_dport);
24264 __u16 srcp = ntohs(inet->inet_sport);
24266 diff -NurpP --minimal linux-3.13.10/net/ipv6/Kconfig linux-3.13.10-vs2.3.6.11/net/ipv6/Kconfig
24267 --- linux-3.13.10/net/ipv6/Kconfig 2014-01-22 20:39:15.000000000 +0000
24268 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/Kconfig 2014-01-31 20:38:04.000000000 +0000
24271 # IPv6 as module will cause a CRASH if you try to unload it
24273 - tristate "The IPv6 protocol"
24275 + bool "The IPv6 protocol"
24278 This is complemental support for the IP version 6.
24279 You will still be able to do traditional IPv4 networking as well.
24280 diff -NurpP --minimal linux-3.13.10/net/ipv6/addrconf.c linux-3.13.10-vs2.3.6.11/net/ipv6/addrconf.c
24281 --- linux-3.13.10/net/ipv6/addrconf.c 2014-04-17 01:12:41.000000000 +0000
24282 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/addrconf.c 2014-04-17 01:17:11.000000000 +0000
24284 #include <linux/proc_fs.h>
24285 #include <linux/seq_file.h>
24286 #include <linux/export.h>
24287 +#include <linux/vs_network.h>
24288 +#include <linux/vs_inet6.h>
24290 /* Set to 3 to get tracing... */
24291 #define ACONF_DEBUG 2
24292 @@ -1284,7 +1286,7 @@ out:
24294 int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
24295 const struct in6_addr *daddr, unsigned int prefs,
24296 - struct in6_addr *saddr)
24297 + struct in6_addr *saddr, struct nx_info *nxi)
24299 struct ipv6_saddr_score scores[2],
24300 *score = &scores[0], *hiscore = &scores[1];
24301 @@ -1356,6 +1358,8 @@ int ipv6_dev_get_saddr(struct net *net,
24305 + if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
24309 bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
24310 @@ -3371,7 +3375,10 @@ static void if6_seq_stop(struct seq_file
24311 static int if6_seq_show(struct seq_file *seq, void *v)
24313 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
24314 - seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24316 + if (nx_check(0, VS_ADMIN|VS_WATCH) ||
24317 + v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
24318 + seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24320 ifp->idev->dev->ifindex,
24322 @@ -3892,6 +3899,11 @@ static int in6_dump_addrs(struct inet6_d
24323 struct ifacaddr6 *ifaca;
24325 int ip_idx = *p_ip_idx;
24326 + struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24328 + /* disable ipv6 on non v6 guests */
24329 + if (nxi && !nx_info_has_v6(nxi))
24332 read_lock_bh(&idev->lock);
24334 @@ -3902,6 +3914,8 @@ static int in6_dump_addrs(struct inet6_d
24335 list_for_each_entry(ifa, &idev->addr_list, if_list) {
24336 if (++ip_idx < s_ip_idx)
24338 + if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
24340 err = inet6_fill_ifaddr(skb, ifa,
24341 NETLINK_CB(cb->skb).portid,
24342 cb->nlh->nlmsg_seq,
24343 @@ -3919,6 +3933,8 @@ static int in6_dump_addrs(struct inet6_d
24344 ifmca = ifmca->next, ip_idx++) {
24345 if (ip_idx < s_ip_idx)
24347 + if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
24349 err = inet6_fill_ifmcaddr(skb, ifmca,
24350 NETLINK_CB(cb->skb).portid,
24351 cb->nlh->nlmsg_seq,
24352 @@ -3934,6 +3950,8 @@ static int in6_dump_addrs(struct inet6_d
24353 ifaca = ifaca->aca_next, ip_idx++) {
24354 if (ip_idx < s_ip_idx)
24356 + if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
24358 err = inet6_fill_ifacaddr(skb, ifaca,
24359 NETLINK_CB(cb->skb).portid,
24360 cb->nlh->nlmsg_seq,
24361 @@ -3962,6 +3980,10 @@ static int inet6_dump_addr(struct sk_buf
24362 struct inet6_dev *idev;
24363 struct hlist_head *head;
24365 + /* FIXME: maybe disable ipv6 on non v6 guests?
24366 + if (skb->sk && skb->sk->sk_vx_info)
24367 + return skb->len; */
24370 s_idx = idx = cb->args[1];
24371 s_ip_idx = ip_idx = cb->args[2];
24372 @@ -4404,6 +4426,7 @@ static int inet6_dump_ifinfo(struct sk_b
24373 struct net_device *dev;
24374 struct inet6_dev *idev;
24375 struct hlist_head *head;
24376 + struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24379 s_idx = cb->args[1];
24380 @@ -4415,6 +4438,8 @@ static int inet6_dump_ifinfo(struct sk_b
24381 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24384 + if (!v6_dev_in_nx_info(dev, nxi))
24386 idev = __in6_dev_get(dev);
24389 diff -NurpP --minimal linux-3.13.10/net/ipv6/af_inet6.c linux-3.13.10-vs2.3.6.11/net/ipv6/af_inet6.c
24390 --- linux-3.13.10/net/ipv6/af_inet6.c 2014-01-22 20:39:15.000000000 +0000
24391 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/af_inet6.c 2014-01-31 21:39:03.000000000 +0000
24393 #include <linux/netdevice.h>
24394 #include <linux/icmpv6.h>
24395 #include <linux/netfilter_ipv6.h>
24396 +#include <linux/vs_inet.h>
24397 +#include <linux/vs_inet6.h>
24399 #include <net/ip.h>
24400 #include <net/ipv6.h>
24401 @@ -156,10 +158,13 @@ lookup_protocol:
24405 + if ((protocol == IPPROTO_ICMPV6) &&
24406 + nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24408 if (sock->type == SOCK_RAW && !kern &&
24409 !ns_capable(net->user_ns, CAP_NET_RAW))
24410 goto out_rcu_unlock;
24413 sock->ops = answer->ops;
24414 answer_prot = answer->prot;
24415 answer_no_check = answer->no_check;
24416 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
24417 struct inet_sock *inet = inet_sk(sk);
24418 struct ipv6_pinfo *np = inet6_sk(sk);
24419 struct net *net = sock_net(sk);
24420 + struct nx_v6_sock_addr nsa;
24422 unsigned short snum;
24424 @@ -274,6 +280,10 @@ int inet6_bind(struct socket *sock, stru
24425 if (addr->sin6_family != AF_INET6)
24426 return -EAFNOSUPPORT;
24428 + err = v6_map_sock_addr(inet, addr, &nsa);
24432 addr_type = ipv6_addr_type(&addr->sin6_addr);
24433 if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
24435 @@ -305,6 +315,7 @@ int inet6_bind(struct socket *sock, stru
24436 /* Reproduce AF_INET checks to make the bindings consistent */
24437 v4addr = addr->sin6_addr.s6_addr32[3];
24438 chk_addr_ret = inet_addr_type(net, v4addr);
24440 if (!sysctl_ip_nonlocal_bind &&
24441 !(inet->freebind || inet->transparent) &&
24442 v4addr != htonl(INADDR_ANY) &&
24443 @@ -314,6 +325,10 @@ int inet6_bind(struct socket *sock, stru
24444 err = -EADDRNOTAVAIL;
24447 + if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
24448 + err = -EADDRNOTAVAIL;
24452 if (addr_type != IPV6_ADDR_ANY) {
24453 struct net_device *dev = NULL;
24454 @@ -340,6 +355,11 @@ int inet6_bind(struct socket *sock, stru
24458 + if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24459 + err = -EADDRNOTAVAIL;
24463 /* ipv4 addr of the socket is invalid. Only the
24464 * unspecified and mapped address have a v4 equivalent.
24466 @@ -356,6 +376,9 @@ int inet6_bind(struct socket *sock, stru
24470 + /* what's that for? */
24471 + v6_set_sock_addr(inet, &nsa);
24473 inet->inet_rcv_saddr = v4addr;
24474 inet->inet_saddr = v4addr;
24476 @@ -457,9 +480,11 @@ int inet6_getname(struct socket *sock, s
24478 sin->sin6_port = inet->inet_dport;
24479 sin->sin6_addr = sk->sk_v6_daddr;
24480 + /* FIXME: remap lback? */
24482 sin->sin6_flowinfo = np->flow_label;
24484 + /* FIXME: remap lback? */
24485 if (ipv6_addr_any(&sk->sk_v6_rcv_saddr))
24486 sin->sin6_addr = np->saddr;
24488 diff -NurpP --minimal linux-3.13.10/net/ipv6/datagram.c linux-3.13.10-vs2.3.6.11/net/ipv6/datagram.c
24489 --- linux-3.13.10/net/ipv6/datagram.c 2014-01-22 20:39:15.000000000 +0000
24490 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/datagram.c 2014-01-31 20:38:04.000000000 +0000
24491 @@ -655,7 +655,7 @@ int ip6_datagram_send_ctl(struct net *ne
24494 if (fl6->flowi6_oif) {
24495 - dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
24496 + dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
24500 diff -NurpP --minimal linux-3.13.10/net/ipv6/fib6_rules.c linux-3.13.10-vs2.3.6.11/net/ipv6/fib6_rules.c
24501 --- linux-3.13.10/net/ipv6/fib6_rules.c 2014-01-22 20:39:15.000000000 +0000
24502 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/fib6_rules.c 2014-01-31 20:38:04.000000000 +0000
24503 @@ -97,7 +97,7 @@ static int fib6_rule_action(struct fib_r
24504 ip6_dst_idev(&rt->dst)->dev,
24506 rt6_flags2srcprefs(flags),
24510 if (!ipv6_prefix_equal(&saddr, &r->src.addr,
24512 diff -NurpP --minimal linux-3.13.10/net/ipv6/inet6_hashtables.c linux-3.13.10-vs2.3.6.11/net/ipv6/inet6_hashtables.c
24513 --- linux-3.13.10/net/ipv6/inet6_hashtables.c 2014-01-22 20:39:15.000000000 +0000
24514 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/inet6_hashtables.c 2014-01-31 20:38:04.000000000 +0000
24517 #include <linux/module.h>
24518 #include <linux/random.h>
24519 +#include <linux/vs_inet6.h>
24521 #include <net/inet_connection_sock.h>
24522 #include <net/inet_hashtables.h>
24523 @@ -116,7 +117,6 @@ struct sock *__inet6_lookup_established(
24524 unsigned int slot = hash & hashinfo->ehash_mask;
24525 struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
24530 sk_nulls_for_each_rcu(sk, node, &head->chain) {
24531 @@ -158,6 +158,9 @@ static inline int compute_score(struct s
24532 if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24536 + if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24539 if (sk->sk_bound_dev_if) {
24540 if (sk->sk_bound_dev_if != dif)
24541 diff -NurpP --minimal linux-3.13.10/net/ipv6/ip6_fib.c linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_fib.c
24542 --- linux-3.13.10/net/ipv6/ip6_fib.c 2014-01-22 20:39:15.000000000 +0000
24543 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_fib.c 2014-01-31 21:48:35.000000000 +0000
24544 @@ -1779,6 +1779,7 @@ static int ipv6_route_seq_show(struct se
24545 struct rt6_info *rt = v;
24546 struct ipv6_route_iter *iter = seq->private;
24548 + /* FIXME: check for network context? */
24549 seq_printf(seq, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
24551 #ifdef CONFIG_IPV6_SUBTREES
24552 diff -NurpP --minimal linux-3.13.10/net/ipv6/ip6_output.c linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_output.c
24553 --- linux-3.13.10/net/ipv6/ip6_output.c 2014-04-17 01:12:41.000000000 +0000
24554 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_output.c 2014-04-17 01:17:11.000000000 +0000
24555 @@ -872,7 +872,8 @@ static int ip6_dst_lookup_tail(struct so
24556 struct rt6_info *rt = (struct rt6_info *) *dst;
24557 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
24558 sk ? inet6_sk(sk)->srcprefs : 0,
24561 + sk ? sk->sk_nx_info : NULL);
24563 goto out_err_release;
24565 diff -NurpP --minimal linux-3.13.10/net/ipv6/ndisc.c linux-3.13.10-vs2.3.6.11/net/ipv6/ndisc.c
24566 --- linux-3.13.10/net/ipv6/ndisc.c 2014-01-22 20:39:15.000000000 +0000
24567 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ndisc.c 2014-01-31 20:38:04.000000000 +0000
24568 @@ -486,7 +486,7 @@ void ndisc_send_na(struct net_device *de
24570 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
24571 inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
24575 src_addr = &tmpaddr;
24577 diff -NurpP --minimal linux-3.13.10/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.13.10-vs2.3.6.11/net/ipv6/netfilter/ip6t_MASQUERADE.c
24578 --- linux-3.13.10/net/ipv6/netfilter/ip6t_MASQUERADE.c 2013-11-25 15:47:07.000000000 +0000
24579 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/netfilter/ip6t_MASQUERADE.c 2014-01-31 20:38:04.000000000 +0000
24580 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
24581 ctinfo == IP_CT_RELATED_REPLY));
24583 if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
24584 - &ipv6_hdr(skb)->daddr, 0, &src) < 0)
24585 + &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
24588 nfct_nat(ct)->masq_index = par->out->ifindex;
24589 diff -NurpP --minimal linux-3.13.10/net/ipv6/raw.c linux-3.13.10-vs2.3.6.11/net/ipv6/raw.c
24590 --- linux-3.13.10/net/ipv6/raw.c 2014-01-22 20:39:15.000000000 +0000
24591 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/raw.c 2014-01-31 20:38:04.000000000 +0000
24593 #include <linux/icmpv6.h>
24594 #include <linux/netfilter.h>
24595 #include <linux/netfilter_ipv6.h>
24596 +#include <linux/vs_inet6.h>
24597 #include <linux/skbuff.h>
24598 #include <linux/compat.h>
24599 #include <asm/uaccess.h>
24600 @@ -287,6 +288,13 @@ static int rawv6_bind(struct sock *sk, s
24604 + if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24605 + err = -EADDRNOTAVAIL;
24611 /* ipv4 addr of the socket is invalid. Only the
24612 * unspecified and mapped address have a v4 equivalent.
24614 diff -NurpP --minimal linux-3.13.10/net/ipv6/route.c linux-3.13.10-vs2.3.6.11/net/ipv6/route.c
24615 --- linux-3.13.10/net/ipv6/route.c 2014-04-17 01:12:41.000000000 +0000
24616 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/route.c 2014-04-17 01:17:11.000000000 +0000
24618 #include <net/netevent.h>
24619 #include <net/netlink.h>
24620 #include <net/nexthop.h>
24621 +#include <linux/vs_inet6.h>
24623 #include <asm/uaccess.h>
24625 @@ -2196,15 +2197,17 @@ int ip6_route_get_saddr(struct net *net,
24626 struct rt6_info *rt,
24627 const struct in6_addr *daddr,
24628 unsigned int prefs,
24629 - struct in6_addr *saddr)
24630 + struct in6_addr *saddr,
24631 + struct nx_info *nxi)
24633 struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
24635 - if (rt->rt6i_prefsrc.plen)
24636 + if (rt->rt6i_prefsrc.plen && (!nxi ||
24637 + v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
24638 *saddr = rt->rt6i_prefsrc.addr;
24640 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
24641 - daddr, prefs, saddr);
24642 + daddr, prefs, saddr, nxi);
24646 @@ -2624,7 +2627,8 @@ static int rt6_fill_node(struct net *net
24647 goto nla_put_failure;
24649 struct in6_addr saddr_buf;
24650 - if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
24651 + if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
24652 + (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
24653 nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
24654 goto nla_put_failure;
24656 diff -NurpP --minimal linux-3.13.10/net/ipv6/tcp_ipv6.c linux-3.13.10-vs2.3.6.11/net/ipv6/tcp_ipv6.c
24657 --- linux-3.13.10/net/ipv6/tcp_ipv6.c 2014-01-22 20:39:15.000000000 +0000
24658 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/tcp_ipv6.c 2014-01-31 20:38:04.000000000 +0000
24661 #include <linux/crypto.h>
24662 #include <linux/scatterlist.h>
24663 +#include <linux/vs_inet6.h>
24665 static void tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
24666 static void tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
24667 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
24668 * connect() to INADDR_ANY means loopback (BSD'ism).
24671 - if (ipv6_addr_any(&usin->sin6_addr))
24672 - usin->sin6_addr.s6_addr[15] = 0x1;
24673 + if (ipv6_addr_any(&usin->sin6_addr)) {
24674 + struct nx_info *nxi = sk->sk_nx_info;
24676 + if (nxi && nx_info_has_v6(nxi))
24677 + /* FIXME: remap lback? */
24678 + usin->sin6_addr = nxi->v6.ip;
24680 + usin->sin6_addr.s6_addr[15] = 0x1;
24683 addr_type = ipv6_addr_type(&usin->sin6_addr);
24685 diff -NurpP --minimal linux-3.13.10/net/ipv6/udp.c linux-3.13.10-vs2.3.6.11/net/ipv6/udp.c
24686 --- linux-3.13.10/net/ipv6/udp.c 2014-01-22 20:39:15.000000000 +0000
24687 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/udp.c 2014-02-01 02:33:38.000000000 +0000
24689 #include <net/xfrm.h>
24690 #include <net/inet6_hashtables.h>
24691 #include <net/busy_poll.h>
24692 +#include <linux/vs_inet6.h>
24694 #include <linux/proc_fs.h>
24695 #include <linux/seq_file.h>
24696 @@ -76,33 +77,61 @@ static unsigned int udp6_ehashfn(struct
24697 udp_ipv6_hash_secret + net_hash_mix(net));
24700 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
24701 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24703 + const struct in6_addr *sk1_rcv_saddr6 = inet6_rcv_saddr(sk1);
24704 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
24705 - int sk_ipv6only = ipv6_only_sock(sk);
24706 + __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr;
24707 + __be32 sk2_rcv_saddr = sk2->sk_rcv_saddr;
24708 + int sk1_ipv6only = ipv6_only_sock(sk1);
24709 int sk2_ipv6only = inet_v6_ipv6only(sk2);
24710 - int addr_type = ipv6_addr_type(&sk->sk_v6_rcv_saddr);
24711 + int addr_type1 = ipv6_addr_type(sk1_rcv_saddr6);
24712 int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
24714 /* if both are mapped, treat as IPv4 */
24715 - if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
24716 - return (!sk2_ipv6only &&
24717 - (!sk->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24718 - sk->sk_rcv_saddr == sk2->sk_rcv_saddr));
24719 + if (addr_type1 == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
24720 + if (!sk2_ipv6only &&
24721 + (!sk1->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24722 + sk1->sk_rcv_saddr == sk2->sk_rcv_saddr))
24728 if (addr_type2 == IPV6_ADDR_ANY &&
24729 - !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
24731 + !(sk2_ipv6only && addr_type1 == IPV6_ADDR_MAPPED))
24734 - if (addr_type == IPV6_ADDR_ANY &&
24735 - !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24737 + if (addr_type1 == IPV6_ADDR_ANY &&
24738 + !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24741 if (sk2_rcv_saddr6 &&
24742 - ipv6_addr_equal(&sk->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24744 + ipv6_addr_equal(&sk1->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24750 + if (!sk1_rcv_saddr && !sk2_rcv_saddr)
24751 + return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24752 + if (!sk2_rcv_saddr)
24753 + return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
24754 + if (!sk1_rcv_saddr)
24755 + return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
24758 + if (addr_type2 == IPV6_ADDR_ANY && addr_type1 == IPV6_ADDR_ANY)
24759 + return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24760 + else if (addr_type2 == IPV6_ADDR_ANY)
24761 + return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
24762 + else if (addr_type1 == IPV6_ADDR_ANY) {
24763 + if (addr_type2 == IPV6_ADDR_MAPPED)
24764 + return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24766 + return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
24771 static unsigned int udp6_portaddr_hash(struct net *net,
24772 @@ -160,6 +189,10 @@ static inline int compute_score(struct s
24773 if (inet->inet_dport != sport)
24777 + /* block non nx_info ips */
24778 + if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24781 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
24782 if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24783 diff -NurpP --minimal linux-3.13.10/net/ipv6/xfrm6_policy.c linux-3.13.10-vs2.3.6.11/net/ipv6/xfrm6_policy.c
24784 --- linux-3.13.10/net/ipv6/xfrm6_policy.c 2014-01-22 20:39:15.000000000 +0000
24785 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/xfrm6_policy.c 2014-01-31 20:38:04.000000000 +0000
24786 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
24787 dev = ip6_dst_idev(dst)->dev;
24788 ipv6_dev_get_saddr(dev_net(dev), dev,
24789 (struct in6_addr *)&daddr->a6, 0,
24790 - (struct in6_addr *)&saddr->a6);
24791 + (struct in6_addr *)&saddr->a6, NULL);
24795 diff -NurpP --minimal linux-3.13.10/net/netfilter/ipvs/ip_vs_xmit.c linux-3.13.10-vs2.3.6.11/net/netfilter/ipvs/ip_vs_xmit.c
24796 --- linux-3.13.10/net/netfilter/ipvs/ip_vs_xmit.c 2013-11-25 15:47:07.000000000 +0000
24797 +++ linux-3.13.10-vs2.3.6.11/net/netfilter/ipvs/ip_vs_xmit.c 2014-01-31 20:38:04.000000000 +0000
24798 @@ -316,7 +316,7 @@ __ip_vs_route_output_v6(struct net *net,
24800 if (ipv6_addr_any(&fl6.saddr) &&
24801 ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
24802 - &fl6.daddr, 0, &fl6.saddr) < 0)
24803 + &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
24806 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
24807 diff -NurpP --minimal linux-3.13.10/net/netlink/af_netlink.c linux-3.13.10-vs2.3.6.11/net/netlink/af_netlink.c
24808 --- linux-3.13.10/net/netlink/af_netlink.c 2014-01-22 20:39:16.000000000 +0000
24809 +++ linux-3.13.10-vs2.3.6.11/net/netlink/af_netlink.c 2014-02-25 11:47:07.000000000 +0000
24811 #include <linux/mutex.h>
24812 #include <linux/vmalloc.h>
24813 #include <linux/if_arp.h>
24814 +#include <linux/vs_context.h>
24815 +#include <linux/vs_network.h>
24816 +#include <linux/vs_limit.h>
24817 #include <asm/cacheflush.h>
24819 #include <net/net_namespace.h>
24820 @@ -2850,6 +2853,8 @@ static struct sock *netlink_seq_socket_i
24821 sk_for_each(s, &hash->table[j]) {
24822 if (sock_net(s) != seq_file_net(seq))
24824 + if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
24828 iter->hash_idx = j;
24829 @@ -2886,7 +2891,8 @@ static void *netlink_seq_next(struct seq
24833 - } while (s && !nl_table[s->sk_protocol].compare(net, s));
24834 + } while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24835 + !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
24839 @@ -2899,7 +2905,8 @@ static void *netlink_seq_next(struct seq
24840 for (; j <= hash->mask; j++) {
24841 s = sk_head(&hash->table[j]);
24843 - while (s && !nl_table[s->sk_protocol].compare(net, s))
24844 + while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24845 + !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
24849 diff -NurpP --minimal linux-3.13.10/net/socket.c linux-3.13.10-vs2.3.6.11/net/socket.c
24850 --- linux-3.13.10/net/socket.c 2014-04-17 01:12:42.000000000 +0000
24851 +++ linux-3.13.10-vs2.3.6.11/net/socket.c 2014-04-17 01:17:11.000000000 +0000
24854 #include <net/sock.h>
24855 #include <linux/netfilter.h>
24856 +#include <linux/vs_socket.h>
24857 +#include <linux/vs_inet.h>
24858 +#include <linux/vs_inet6.h>
24860 #include <linux/if_tun.h>
24861 #include <linux/ipv6_route.h>
24862 @@ -623,13 +626,29 @@ static inline int __sock_sendmsg_nosec(s
24863 struct msghdr *msg, size_t size)
24865 struct sock_iocb *si = kiocb_to_siocb(iocb);
24873 - return sock->ops->sendmsg(iocb, sock, msg, size);
24874 + len = sock->ops->sendmsg(iocb, sock, msg, size);
24877 + vx_sock_send(sock->sk, size);
24879 + vx_sock_fail(sock->sk, size);
24881 + vxdprintk(VXD_CBIT(net, 7),
24882 + "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
24884 + (sock->sk)?sock->sk->sk_nx_info:0,
24885 + (sock->sk)?sock->sk->sk_vx_info:0,
24886 + (sock->sk)?sock->sk->sk_xid:0,
24887 + (sock->sk)?sock->sk->sk_nid:0,
24888 + (unsigned int)size, len);
24892 static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
24893 @@ -773,6 +792,7 @@ static inline int __sock_recvmsg_nosec(s
24894 struct msghdr *msg, size_t size, int flags)
24896 struct sock_iocb *si = kiocb_to_siocb(iocb);
24901 @@ -780,7 +800,18 @@ static inline int __sock_recvmsg_nosec(s
24905 - return sock->ops->recvmsg(iocb, sock, msg, size, flags);
24906 + len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
24907 + if ((len >= 0) && sock->sk)
24908 + vx_sock_recv(sock->sk, len);
24909 + vxdprintk(VXD_CBIT(net, 7),
24910 + "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
24912 + (sock->sk)?sock->sk->sk_nx_info:0,
24913 + (sock->sk)?sock->sk->sk_vx_info:0,
24914 + (sock->sk)?sock->sk->sk_xid:0,
24915 + (sock->sk)?sock->sk->sk_nid:0,
24916 + (unsigned int)size, len);
24920 static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
24921 @@ -1256,6 +1287,13 @@ int __sock_create(struct net *net, int f
24922 if (type < 0 || type >= SOCK_MAX)
24925 + if (!nx_check(0, VS_ADMIN)) {
24926 + if (family == PF_INET && !current_nx_info_has_v4())
24927 + return -EAFNOSUPPORT;
24928 + if (family == PF_INET6 && !current_nx_info_has_v6())
24929 + return -EAFNOSUPPORT;
24934 This uglymoron is moved from INET layer to here to avoid
24935 @@ -1390,6 +1428,7 @@ SYSCALL_DEFINE3(socket, int, family, int
24939 + set_bit(SOCK_USER_SOCKET, &sock->flags);
24940 retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
24943 @@ -1431,10 +1470,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
24944 err = sock_create(family, type, protocol, &sock1);
24947 + set_bit(SOCK_USER_SOCKET, &sock1->flags);
24949 err = sock_create(family, type, protocol, &sock2);
24951 goto out_release_1;
24952 + set_bit(SOCK_USER_SOCKET, &sock2->flags);
24954 err = sock1->ops->socketpair(sock1, sock2);
24956 diff -NurpP --minimal linux-3.13.10/net/sunrpc/auth.c linux-3.13.10-vs2.3.6.11/net/sunrpc/auth.c
24957 --- linux-3.13.10/net/sunrpc/auth.c 2013-11-25 15:47:08.000000000 +0000
24958 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/auth.c 2014-01-31 20:38:04.000000000 +0000
24960 #include <linux/sunrpc/clnt.h>
24961 #include <linux/sunrpc/gss_api.h>
24962 #include <linux/spinlock.h>
24963 +#include <linux/vs_tag.h>
24966 # define RPCDBG_FACILITY RPCDBG_AUTH
24967 @@ -586,6 +587,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
24968 memset(&acred, 0, sizeof(acred));
24969 acred.uid = cred->fsuid;
24970 acred.gid = cred->fsgid;
24971 + acred.tag = make_ktag(&init_user_ns, dx_current_tag());
24972 acred.group_info = get_group_info(((struct cred *)cred)->group_info);
24974 ret = auth->au_ops->lookup_cred(auth, &acred, flags);
24975 @@ -626,6 +628,7 @@ rpcauth_bind_root_cred(struct rpc_task *
24976 struct auth_cred acred = {
24977 .uid = GLOBAL_ROOT_UID,
24978 .gid = GLOBAL_ROOT_GID,
24979 + .tag = KTAGT_INIT(dx_current_tag()),
24982 dprintk("RPC: %5u looking up %s cred\n",
24983 diff -NurpP --minimal linux-3.13.10/net/sunrpc/auth_unix.c linux-3.13.10-vs2.3.6.11/net/sunrpc/auth_unix.c
24984 --- linux-3.13.10/net/sunrpc/auth_unix.c 2013-11-25 15:47:08.000000000 +0000
24985 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/auth_unix.c 2014-01-31 20:38:04.000000000 +0000
24986 @@ -13,11 +13,13 @@
24987 #include <linux/sunrpc/clnt.h>
24988 #include <linux/sunrpc/auth.h>
24989 #include <linux/user_namespace.h>
24990 +#include <linux/vs_tag.h>
24992 #define NFS_NGROUPS 16
24995 struct rpc_cred uc_base;
24998 kgid_t uc_gids[NFS_NGROUPS];
25000 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25001 groups = NFS_NGROUPS;
25003 cred->uc_gid = acred->gid;
25004 + cred->uc_tag = acred->tag;
25005 for (i = 0; i < groups; i++)
25006 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25007 if (i < NFS_NGROUPS)
25008 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25012 - if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25013 + if (!uid_eq(cred->uc_uid, acred->uid) ||
25014 + !gid_eq(cred->uc_gid, acred->gid) ||
25015 + !tag_eq(cred->uc_tag, acred->tag))
25018 if (acred->group_info != NULL)
25019 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25020 struct rpc_clnt *clnt = task->tk_client;
25021 struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25022 __be32 *base, *hold;
25026 *p++ = htonl(RPC_AUTH_UNIX);
25028 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
25030 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25032 - *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25033 - *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25034 + tag = task->tk_client->cl_tag;
25035 + *p++ = htonl((u32) from_kuid(&init_user_ns,
25036 + TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
25037 + *p++ = htonl((u32) from_kgid(&init_user_ns,
25038 + TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
25040 for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25041 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25042 diff -NurpP --minimal linux-3.13.10/net/sunrpc/clnt.c linux-3.13.10-vs2.3.6.11/net/sunrpc/clnt.c
25043 --- linux-3.13.10/net/sunrpc/clnt.c 2014-04-17 01:12:42.000000000 +0000
25044 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/clnt.c 2014-02-25 11:26:10.000000000 +0000
25046 #include <linux/in.h>
25047 #include <linux/in6.h>
25048 #include <linux/un.h>
25049 +#include <linux/vs_cvirt.h>
25051 #include <linux/sunrpc/clnt.h>
25052 #include <linux/sunrpc/addr.h>
25053 @@ -538,6 +539,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25054 if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25055 clnt->cl_chatty = 1;
25057 + /* TODO: handle RPC_CLNT_CREATE_TAGGED
25058 + if (args->flags & RPC_CLNT_CREATE_TAGGED)
25059 + clnt->cl_tag = 1; */
25062 EXPORT_SYMBOL_GPL(rpc_create);
25063 diff -NurpP --minimal linux-3.13.10/net/unix/af_unix.c linux-3.13.10-vs2.3.6.11/net/unix/af_unix.c
25064 --- linux-3.13.10/net/unix/af_unix.c 2014-04-17 01:12:42.000000000 +0000
25065 +++ linux-3.13.10-vs2.3.6.11/net/unix/af_unix.c 2014-04-17 01:17:11.000000000 +0000
25066 @@ -115,6 +115,8 @@
25067 #include <net/checksum.h>
25068 #include <linux/security.h>
25069 #include <linux/freezer.h>
25070 +#include <linux/vs_context.h>
25071 +#include <linux/vs_limit.h>
25073 struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25074 EXPORT_SYMBOL_GPL(unix_socket_table);
25075 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25076 if (!net_eq(sock_net(s), net))
25079 + if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25081 if (u->addr->len == len &&
25082 !memcmp(u->addr->name, sunname, len))
25084 @@ -2275,6 +2279,8 @@ static struct sock *unix_from_bucket(str
25085 for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25086 if (sock_net(sk) != seq_file_net(seq))
25088 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25090 if (++count == offset)
25093 @@ -2292,6 +2298,8 @@ static struct sock *unix_next_socket(str
25097 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25099 if (sock_net(sk) == seq_file_net(seq))
25102 diff -NurpP --minimal linux-3.13.10/scripts/checksyscalls.sh linux-3.13.10-vs2.3.6.11/scripts/checksyscalls.sh
25103 --- linux-3.13.10/scripts/checksyscalls.sh 2012-12-11 03:30:57.000000000 +0000
25104 +++ linux-3.13.10-vs2.3.6.11/scripts/checksyscalls.sh 2014-01-31 20:38:04.000000000 +0000
25105 @@ -193,7 +193,6 @@ cat << EOF
25106 #define __IGNORE_afs_syscall
25107 #define __IGNORE_getpmsg
25108 #define __IGNORE_putpmsg
25109 -#define __IGNORE_vserver
25113 diff -NurpP --minimal linux-3.13.10/security/commoncap.c linux-3.13.10-vs2.3.6.11/security/commoncap.c
25114 --- linux-3.13.10/security/commoncap.c 2013-11-25 15:47:08.000000000 +0000
25115 +++ linux-3.13.10-vs2.3.6.11/security/commoncap.c 2014-01-31 20:38:04.000000000 +0000
25116 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25117 int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25118 int cap, int audit)
25120 + struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25121 struct user_namespace *ns = targ_ns;
25123 /* See if cred has the capability in the target user namespace
25124 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25127 /* Do we have the necessary capabilities? */
25128 - if (ns == cred->user_ns)
25129 - return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25130 + if (ns == cred->user_ns) {
25131 + if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25132 + cap_raised(cred->cap_effective, cap))
25134 + return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25137 /* Have we tried all of the parent namespaces? */
25138 if (ns == &init_user_ns)
25139 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25141 if (!strncmp(name, XATTR_SECURITY_PREFIX,
25142 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25143 - !capable(CAP_SYS_ADMIN))
25144 + !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25148 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25150 if (!strncmp(name, XATTR_SECURITY_PREFIX,
25151 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25152 - !capable(CAP_SYS_ADMIN))
25153 + !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25157 diff -NurpP --minimal linux-3.13.10/security/selinux/hooks.c linux-3.13.10-vs2.3.6.11/security/selinux/hooks.c
25158 --- linux-3.13.10/security/selinux/hooks.c 2014-04-17 01:12:42.000000000 +0000
25159 +++ linux-3.13.10-vs2.3.6.11/security/selinux/hooks.c 2014-04-17 01:17:11.000000000 +0000
25161 #include <linux/dccp.h>
25162 #include <linux/quota.h>
25163 #include <linux/un.h> /* for Unix socket types */
25164 -#include <net/af_unix.h> /* for Unix socket types */
25165 #include <linux/parser.h>
25166 #include <linux/nfs_mount.h>
25167 #include <net/ipv6.h>