1 diff -NurpP --minimal linux-3.9.4/Documentation/vserver/debug.txt linux-3.9.4-vs2.3.6.2/Documentation/vserver/debug.txt
2 --- linux-3.9.4/Documentation/vserver/debug.txt 1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.9.4-vs2.3.6.2/Documentation/vserver/debug.txt 2013-05-31 14:47:10.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.9.4/arch/alpha/Kconfig linux-3.9.4-vs2.3.6.2/arch/alpha/Kconfig
160 --- linux-3.9.4/arch/alpha/Kconfig 2013-05-31 13:44:28.000000000 +0000
161 +++ linux-3.9.4-vs2.3.6.2/arch/alpha/Kconfig 2013-05-31 14:47:10.000000000 +0000
162 @@ -669,6 +669,8 @@ config DUMMY_CONSOLE
166 +source "kernel/vserver/Kconfig"
168 source "security/Kconfig"
170 source "crypto/Kconfig"
171 diff -NurpP --minimal linux-3.9.4/arch/alpha/kernel/systbls.S linux-3.9.4-vs2.3.6.2/arch/alpha/kernel/systbls.S
172 --- linux-3.9.4/arch/alpha/kernel/systbls.S 2013-02-19 13:56:11.000000000 +0000
173 +++ linux-3.9.4-vs2.3.6.2/arch/alpha/kernel/systbls.S 2013-05-31 14:47:11.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.9.4/arch/alpha/kernel/traps.c linux-3.9.4-vs2.3.6.2/arch/alpha/kernel/traps.c
184 --- linux-3.9.4/arch/alpha/kernel/traps.c 2013-05-31 13:44:28.000000000 +0000
185 +++ linux-3.9.4-vs2.3.6.2/arch/alpha/kernel/traps.c 2013-05-31 14:47:11.000000000 +0000
186 @@ -184,7 +184,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.9.4/arch/arm/Kconfig linux-3.9.4-vs2.3.6.2/arch/arm/Kconfig
197 --- linux-3.9.4/arch/arm/Kconfig 2013-05-31 13:44:29.000000000 +0000
198 +++ linux-3.9.4-vs2.3.6.2/arch/arm/Kconfig 2013-05-31 14:47:11.000000000 +0000
199 @@ -2353,6 +2353,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.9.4/arch/arm/kernel/calls.S linux-3.9.4-vs2.3.6.2/arch/arm/kernel/calls.S
209 --- linux-3.9.4/arch/arm/kernel/calls.S 2013-05-31 13:44:29.000000000 +0000
210 +++ linux-3.9.4-vs2.3.6.2/arch/arm/kernel/calls.S 2013-05-31 14:47:11.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.9.4/arch/arm/kernel/process.c linux-3.9.4-vs2.3.6.2/arch/arm/kernel/process.c
221 --- linux-3.9.4/arch/arm/kernel/process.c 2013-05-31 13:44:29.000000000 +0000
222 +++ linux-3.9.4-vs2.3.6.2/arch/arm/kernel/process.c 2013-05-31 14:47:11.000000000 +0000
223 @@ -332,7 +332,8 @@ void __show_regs(struct pt_regs *regs)
224 void show_regs(struct pt_regs * regs)
227 - printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
228 + printk("Pid: %d[#%u], comm: %20s\n",
229 + task_pid_nr(current), current->xid, current->comm);
233 diff -NurpP --minimal linux-3.9.4/arch/arm/kernel/traps.c linux-3.9.4-vs2.3.6.2/arch/arm/kernel/traps.c
234 --- linux-3.9.4/arch/arm/kernel/traps.c 2013-05-31 13:44:29.000000000 +0000
235 +++ linux-3.9.4-vs2.3.6.2/arch/arm/kernel/traps.c 2013-05-31 14:47:11.000000000 +0000
236 @@ -249,8 +249,8 @@ static int __die(const char *str, int er
240 - printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
241 - TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), end_of_stack(tsk));
242 + printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
243 + TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, end_of_stack(tsk));
245 if (!user_mode(regs) || in_interrupt()) {
246 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
247 diff -NurpP --minimal linux-3.9.4/arch/cris/Kconfig linux-3.9.4-vs2.3.6.2/arch/cris/Kconfig
248 --- linux-3.9.4/arch/cris/Kconfig 2013-05-31 13:44:37.000000000 +0000
249 +++ linux-3.9.4-vs2.3.6.2/arch/cris/Kconfig 2013-05-31 14:47:11.000000000 +0000
250 @@ -674,6 +674,8 @@ source "drivers/staging/Kconfig"
252 source "arch/cris/Kconfig.debug"
254 +source "kernel/vserver/Kconfig"
256 source "security/Kconfig"
258 source "crypto/Kconfig"
259 diff -NurpP --minimal linux-3.9.4/arch/h8300/Kconfig linux-3.9.4-vs2.3.6.2/arch/h8300/Kconfig
260 --- linux-3.9.4/arch/h8300/Kconfig 2013-05-31 13:44:38.000000000 +0000
261 +++ linux-3.9.4-vs2.3.6.2/arch/h8300/Kconfig 2013-05-31 14:47:11.000000000 +0000
262 @@ -221,6 +221,8 @@ source "fs/Kconfig"
264 source "arch/h8300/Kconfig.debug"
266 +source "kernel/vserver/Kconfig"
268 source "security/Kconfig"
270 source "crypto/Kconfig"
271 diff -NurpP --minimal linux-3.9.4/arch/ia64/Kconfig linux-3.9.4-vs2.3.6.2/arch/ia64/Kconfig
272 --- linux-3.9.4/arch/ia64/Kconfig 2013-05-31 13:44:38.000000000 +0000
273 +++ linux-3.9.4-vs2.3.6.2/arch/ia64/Kconfig 2013-05-31 14:47:11.000000000 +0000
274 @@ -645,6 +645,8 @@ source "fs/Kconfig"
276 source "arch/ia64/Kconfig.debug"
278 +source "kernel/vserver/Kconfig"
280 source "security/Kconfig"
282 source "crypto/Kconfig"
283 diff -NurpP --minimal linux-3.9.4/arch/ia64/kernel/entry.S linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/entry.S
284 --- linux-3.9.4/arch/ia64/kernel/entry.S 2013-05-31 13:44:38.000000000 +0000
285 +++ linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/entry.S 2013-05-31 14:47:11.000000000 +0000
286 @@ -1719,7 +1719,7 @@ sys_call_table:
288 data8 sys_mq_getsetattr
290 - data8 sys_ni_syscall // reserved for vserver
292 data8 sys_waitid // 1270
294 data8 sys_request_key
295 diff -NurpP --minimal linux-3.9.4/arch/ia64/kernel/process.c linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/process.c
296 --- linux-3.9.4/arch/ia64/kernel/process.c 2013-05-31 13:44:38.000000000 +0000
297 +++ linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/process.c 2013-05-31 14:47:11.000000000 +0000
298 @@ -109,8 +109,8 @@ show_regs (struct pt_regs *regs)
299 unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
302 - printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
303 - smp_processor_id(), current->comm);
304 + printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
305 + current->xid, smp_processor_id(), current->comm);
306 printk("psr : %016lx ifs : %016lx ip : [<%016lx>] %s (%s)\n",
307 regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
308 init_utsname()->release);
309 diff -NurpP --minimal linux-3.9.4/arch/ia64/kernel/ptrace.c linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/ptrace.c
310 --- linux-3.9.4/arch/ia64/kernel/ptrace.c 2013-02-19 13:56:51.000000000 +0000
311 +++ linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/ptrace.c 2013-05-31 14:47:11.000000000 +0000
313 #include <linux/regset.h>
314 #include <linux/elf.h>
315 #include <linux/tracehook.h>
316 +#include <linux/vs_base.h>
318 #include <asm/pgtable.h>
319 #include <asm/processor.h>
320 diff -NurpP --minimal linux-3.9.4/arch/ia64/kernel/traps.c linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/traps.c
321 --- linux-3.9.4/arch/ia64/kernel/traps.c 2013-05-31 13:44:38.000000000 +0000
322 +++ linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/traps.c 2013-05-31 14:47:11.000000000 +0000
323 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
326 if (++die.lock_owner_depth < 3) {
327 - printk("%s[%d]: %s %ld [%d]\n",
328 - current->comm, task_pid_nr(current), str, err, ++die_counter);
329 + printk("%s[%d[#%u]]: %s %ld [%d]\n",
330 + current->comm, task_pid_nr(current), current->xid,
331 + str, err, ++die_counter);
332 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
335 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
336 if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
337 last.time = current_jiffies + 5 * HZ;
339 - "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
340 - current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
341 + "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
342 + current->comm, task_pid_nr(current), current->xid,
343 + regs->cr_iip + ia64_psr(regs)->ri, isr);
347 diff -NurpP --minimal linux-3.9.4/arch/m32r/kernel/traps.c linux-3.9.4-vs2.3.6.2/arch/m32r/kernel/traps.c
348 --- linux-3.9.4/arch/m32r/kernel/traps.c 2012-12-11 03:30:57.000000000 +0000
349 +++ linux-3.9.4-vs2.3.6.2/arch/m32r/kernel/traps.c 2013-05-31 14:47:11.000000000 +0000
350 @@ -195,8 +195,9 @@ static void show_registers(struct pt_reg
352 printk("SPI: %08lx\n", sp);
354 - printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
355 - current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
356 + printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
357 + current->comm, task_pid_nr(current), current->xid,
358 + 0xffff & i, 4096+(unsigned long)current);
361 * When in-kernel, we also print out the stack and code at the
362 diff -NurpP --minimal linux-3.9.4/arch/m68k/Kconfig linux-3.9.4-vs2.3.6.2/arch/m68k/Kconfig
363 --- linux-3.9.4/arch/m68k/Kconfig 2013-05-31 13:44:38.000000000 +0000
364 +++ linux-3.9.4-vs2.3.6.2/arch/m68k/Kconfig 2013-05-31 14:47:11.000000000 +0000
365 @@ -137,6 +137,8 @@ source "fs/Kconfig"
367 source "arch/m68k/Kconfig.debug"
369 +source "kernel/vserver/Kconfig"
371 source "security/Kconfig"
373 source "crypto/Kconfig"
374 diff -NurpP --minimal linux-3.9.4/arch/mips/Kconfig linux-3.9.4-vs2.3.6.2/arch/mips/Kconfig
375 --- linux-3.9.4/arch/mips/Kconfig 2013-05-31 13:44:39.000000000 +0000
376 +++ linux-3.9.4-vs2.3.6.2/arch/mips/Kconfig 2013-05-31 14:47:11.000000000 +0000
377 @@ -2550,6 +2550,8 @@ source "fs/Kconfig"
379 source "arch/mips/Kconfig.debug"
381 +source "kernel/vserver/Kconfig"
383 source "security/Kconfig"
385 source "crypto/Kconfig"
386 diff -NurpP --minimal linux-3.9.4/arch/mips/kernel/ptrace.c linux-3.9.4-vs2.3.6.2/arch/mips/kernel/ptrace.c
387 --- linux-3.9.4/arch/mips/kernel/ptrace.c 2013-05-31 13:44:42.000000000 +0000
388 +++ linux-3.9.4-vs2.3.6.2/arch/mips/kernel/ptrace.c 2013-05-31 14:47:11.000000000 +0000
390 #include <linux/security.h>
391 #include <linux/audit.h>
392 #include <linux/seccomp.h>
393 +#include <linux/vs_base.h>
395 #include <asm/byteorder.h>
397 @@ -262,6 +263,9 @@ long arch_ptrace(struct task_struct *chi
398 void __user *datavp = (void __user *) data;
399 unsigned long __user *datalp = (void __user *) data;
401 + if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
405 /* when I and D space are separate, these will need to be fixed. */
406 case PTRACE_PEEKTEXT: /* read word at location addr. */
407 diff -NurpP --minimal linux-3.9.4/arch/mips/kernel/scall32-o32.S linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall32-o32.S
408 --- linux-3.9.4/arch/mips/kernel/scall32-o32.S 2013-05-31 13:44:42.000000000 +0000
409 +++ linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall32-o32.S 2013-05-31 14:47:11.000000000 +0000
410 @@ -512,7 +512,7 @@ einval: li v0, -ENOSYS
411 sys sys_mq_timedreceive 5
412 sys sys_mq_notify 2 /* 4275 */
413 sys sys_mq_getsetattr 3
414 - sys sys_ni_syscall 0 /* sys_vserver */
417 sys sys_ni_syscall 0 /* available, was setaltroot */
418 sys sys_add_key 5 /* 4280 */
419 diff -NurpP --minimal linux-3.9.4/arch/mips/kernel/scall64-64.S linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall64-64.S
420 --- linux-3.9.4/arch/mips/kernel/scall64-64.S 2013-05-31 13:44:42.000000000 +0000
421 +++ linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall64-64.S 2013-05-31 14:47:11.000000000 +0000
422 @@ -351,7 +351,7 @@ sys_call_table:
423 PTR sys_mq_timedreceive
425 PTR sys_mq_getsetattr /* 5235 */
426 - PTR sys_ni_syscall /* sys_vserver */
429 PTR sys_ni_syscall /* available, was setaltroot */
431 diff -NurpP --minimal linux-3.9.4/arch/mips/kernel/scall64-n32.S linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall64-n32.S
432 --- linux-3.9.4/arch/mips/kernel/scall64-n32.S 2013-05-31 13:44:42.000000000 +0000
433 +++ linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall64-n32.S 2013-05-31 14:47:11.000000000 +0000
434 @@ -344,7 +344,7 @@ EXPORT(sysn32_call_table)
435 PTR compat_sys_mq_timedreceive
436 PTR compat_sys_mq_notify
437 PTR compat_sys_mq_getsetattr
438 - PTR sys_ni_syscall /* 6240, sys_vserver */
439 + PTR sys32_vserver /* 6240 */
440 PTR compat_sys_waitid
441 PTR sys_ni_syscall /* available, was setaltroot */
443 diff -NurpP --minimal linux-3.9.4/arch/mips/kernel/scall64-o32.S linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall64-o32.S
444 --- linux-3.9.4/arch/mips/kernel/scall64-o32.S 2013-05-31 13:44:42.000000000 +0000
445 +++ linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall64-o32.S 2013-05-31 15:07:53.000000000 +0000
446 @@ -469,7 +469,7 @@ sys_call_table:
447 PTR compat_sys_mq_timedreceive
448 PTR compat_sys_mq_notify /* 4275 */
449 PTR compat_sys_mq_getsetattr
450 - PTR sys_ni_syscall /* sys_vserver */
452 PTR compat_sys_waitid
453 PTR sys_ni_syscall /* available, was setaltroot */
454 PTR sys_add_key /* 4280 */
455 diff -NurpP --minimal linux-3.9.4/arch/mips/kernel/traps.c linux-3.9.4-vs2.3.6.2/arch/mips/kernel/traps.c
456 --- linux-3.9.4/arch/mips/kernel/traps.c 2013-05-31 13:44:42.000000000 +0000
457 +++ linux-3.9.4-vs2.3.6.2/arch/mips/kernel/traps.c 2013-05-31 14:47:11.000000000 +0000
458 @@ -348,9 +348,10 @@ void show_registers(struct pt_regs *regs
462 - printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
463 - current->comm, current->pid, current_thread_info(), current,
464 - field, current_thread_info()->tp_value);
465 + printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
466 + current->comm, task_pid_nr(current), current->xid,
467 + current_thread_info(), current,
468 + field, current_thread_info()->tp_value);
469 if (cpu_has_userlocal) {
472 diff -NurpP --minimal linux-3.9.4/arch/parisc/Kconfig linux-3.9.4-vs2.3.6.2/arch/parisc/Kconfig
473 --- linux-3.9.4/arch/parisc/Kconfig 2013-05-31 13:44:44.000000000 +0000
474 +++ linux-3.9.4-vs2.3.6.2/arch/parisc/Kconfig 2013-05-31 14:47:11.000000000 +0000
475 @@ -308,6 +308,8 @@ source "fs/Kconfig"
477 source "arch/parisc/Kconfig.debug"
479 +source "kernel/vserver/Kconfig"
481 source "security/Kconfig"
483 source "crypto/Kconfig"
484 diff -NurpP --minimal linux-3.9.4/arch/parisc/kernel/syscall_table.S linux-3.9.4-vs2.3.6.2/arch/parisc/kernel/syscall_table.S
485 --- linux-3.9.4/arch/parisc/kernel/syscall_table.S 2013-05-31 13:44:44.000000000 +0000
486 +++ linux-3.9.4-vs2.3.6.2/arch/parisc/kernel/syscall_table.S 2013-05-31 14:47:11.000000000 +0000
488 ENTRY_COMP(mbind) /* 260 */
489 ENTRY_COMP(get_mempolicy)
490 ENTRY_COMP(set_mempolicy)
491 - ENTRY_SAME(ni_syscall) /* 263: reserved for vserver */
492 + ENTRY_DIFF(vserver)
494 ENTRY_SAME(request_key) /* 265 */
496 diff -NurpP --minimal linux-3.9.4/arch/parisc/kernel/traps.c linux-3.9.4-vs2.3.6.2/arch/parisc/kernel/traps.c
497 --- linux-3.9.4/arch/parisc/kernel/traps.c 2013-05-31 13:44:44.000000000 +0000
498 +++ linux-3.9.4-vs2.3.6.2/arch/parisc/kernel/traps.c 2013-05-31 14:47:11.000000000 +0000
499 @@ -235,8 +235,9 @@ void die_if_kernel(char *str, struct pt_
503 - printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
504 - current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
505 + printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
506 + current->comm, task_pid_nr(current), current->xid,
507 + str, err, regs->iaoq[0]);
508 #ifdef PRINT_USER_FAULTS
509 /* XXX for debugging only */
511 @@ -269,8 +270,8 @@ void die_if_kernel(char *str, struct pt_
512 pdc_console_restart();
515 - printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
516 - current->comm, task_pid_nr(current), str, err);
517 + printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
518 + current->comm, task_pid_nr(current), current->xid, str, err);
520 /* Wot's wrong wif bein' racy? */
521 if (current->thread.flags & PARISC_KERNEL_DEATH) {
522 diff -NurpP --minimal linux-3.9.4/arch/parisc/mm/fault.c linux-3.9.4-vs2.3.6.2/arch/parisc/mm/fault.c
523 --- linux-3.9.4/arch/parisc/mm/fault.c 2013-05-31 13:44:44.000000000 +0000
524 +++ linux-3.9.4-vs2.3.6.2/arch/parisc/mm/fault.c 2013-05-31 14:47:11.000000000 +0000
525 @@ -257,8 +257,9 @@ bad_area:
527 #ifdef PRINT_USER_FAULTS
528 printk(KERN_DEBUG "\n");
529 - printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
530 - task_pid_nr(tsk), tsk->comm, code, address);
531 + printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
532 + "command='%s' type=%lu address=0x%08lx\n",
533 + task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
535 printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
536 vma->vm_start, vma->vm_end);
537 diff -NurpP --minimal linux-3.9.4/arch/powerpc/Kconfig linux-3.9.4-vs2.3.6.2/arch/powerpc/Kconfig
538 --- linux-3.9.4/arch/powerpc/Kconfig 2013-05-31 13:44:44.000000000 +0000
539 +++ linux-3.9.4-vs2.3.6.2/arch/powerpc/Kconfig 2013-05-31 14:47:11.000000000 +0000
540 @@ -1027,6 +1027,8 @@ source "lib/Kconfig"
542 source "arch/powerpc/Kconfig.debug"
544 +source "kernel/vserver/Kconfig"
546 source "security/Kconfig"
549 diff -NurpP --minimal linux-3.9.4/arch/powerpc/include/uapi/asm/unistd.h linux-3.9.4-vs2.3.6.2/arch/powerpc/include/uapi/asm/unistd.h
550 --- linux-3.9.4/arch/powerpc/include/uapi/asm/unistd.h 2013-05-31 13:44:44.000000000 +0000
551 +++ linux-3.9.4-vs2.3.6.2/arch/powerpc/include/uapi/asm/unistd.h 2013-05-31 14:47:11.000000000 +0000
554 #define __NR_rtas 255
555 #define __NR_sys_debug_setcontext 256
556 -/* Number 257 is reserved for vserver */
557 +#define __NR_vserver 257
558 #define __NR_migrate_pages 258
559 #define __NR_mbind 259
560 #define __NR_get_mempolicy 260
561 diff -NurpP --minimal linux-3.9.4/arch/powerpc/kernel/process.c linux-3.9.4-vs2.3.6.2/arch/powerpc/kernel/process.c
562 --- linux-3.9.4/arch/powerpc/kernel/process.c 2013-05-31 13:44:44.000000000 +0000
563 +++ linux-3.9.4-vs2.3.6.2/arch/powerpc/kernel/process.c 2013-05-31 14:47:11.000000000 +0000
564 @@ -850,8 +850,9 @@ void show_regs(struct pt_regs * regs)
566 printk("DAR: "REG", DSISR: %08lx\n", regs->dar, regs->dsisr);
568 - printk("TASK = %p[%d] '%s' THREAD: %p",
569 - current, task_pid_nr(current), current->comm, task_thread_info(current));
570 + printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
571 + current, task_pid_nr(current), current->xid,
572 + current->comm, task_thread_info(current));
575 printk(" CPU: %d", raw_smp_processor_id());
576 diff -NurpP --minimal linux-3.9.4/arch/powerpc/kernel/traps.c linux-3.9.4-vs2.3.6.2/arch/powerpc/kernel/traps.c
577 --- linux-3.9.4/arch/powerpc/kernel/traps.c 2013-05-31 14:22:26.000000000 +0000
578 +++ linux-3.9.4-vs2.3.6.2/arch/powerpc/kernel/traps.c 2013-05-31 14:47:11.000000000 +0000
579 @@ -1167,8 +1167,9 @@ void nonrecoverable_exception(struct pt_
581 void trace_syscall(struct pt_regs *regs)
583 - printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
584 - current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
585 + printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
586 + current, task_pid_nr(current), current->xid,
587 + regs->nip, regs->link, regs->gpr[0],
588 regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
591 diff -NurpP --minimal linux-3.9.4/arch/s390/Kconfig linux-3.9.4-vs2.3.6.2/arch/s390/Kconfig
592 --- linux-3.9.4/arch/s390/Kconfig 2013-05-31 13:44:45.000000000 +0000
593 +++ linux-3.9.4-vs2.3.6.2/arch/s390/Kconfig 2013-05-31 14:47:11.000000000 +0000
594 @@ -592,6 +592,8 @@ source "fs/Kconfig"
596 source "arch/s390/Kconfig.debug"
598 +source "kernel/vserver/Kconfig"
600 source "security/Kconfig"
602 source "crypto/Kconfig"
603 diff -NurpP --minimal linux-3.9.4/arch/s390/include/asm/tlb.h linux-3.9.4-vs2.3.6.2/arch/s390/include/asm/tlb.h
604 --- linux-3.9.4/arch/s390/include/asm/tlb.h 2012-12-11 03:30:57.000000000 +0000
605 +++ linux-3.9.4-vs2.3.6.2/arch/s390/include/asm/tlb.h 2013-05-31 14:47:11.000000000 +0000
607 #include <linux/mm.h>
608 #include <linux/pagemap.h>
609 #include <linux/swap.h>
611 #include <asm/processor.h>
612 #include <asm/pgalloc.h>
613 #include <asm/tlbflush.h>
614 diff -NurpP --minimal linux-3.9.4/arch/s390/include/uapi/asm/unistd.h linux-3.9.4-vs2.3.6.2/arch/s390/include/uapi/asm/unistd.h
615 --- linux-3.9.4/arch/s390/include/uapi/asm/unistd.h 2013-02-19 13:57:16.000000000 +0000
616 +++ linux-3.9.4-vs2.3.6.2/arch/s390/include/uapi/asm/unistd.h 2013-05-31 14:47:11.000000000 +0000
618 #define __NR_clock_gettime (__NR_timer_create+6)
619 #define __NR_clock_getres (__NR_timer_create+7)
620 #define __NR_clock_nanosleep (__NR_timer_create+8)
621 -/* Number 263 is reserved for vserver */
622 +#define __NR_vserver 263
623 #define __NR_statfs64 265
624 #define __NR_fstatfs64 266
625 #define __NR_remap_file_pages 267
626 diff -NurpP --minimal linux-3.9.4/arch/s390/kernel/ptrace.c linux-3.9.4-vs2.3.6.2/arch/s390/kernel/ptrace.c
627 --- linux-3.9.4/arch/s390/kernel/ptrace.c 2012-12-11 03:30:57.000000000 +0000
628 +++ linux-3.9.4-vs2.3.6.2/arch/s390/kernel/ptrace.c 2013-05-31 14:47:11.000000000 +0000
630 #include <linux/tracehook.h>
631 #include <linux/seccomp.h>
632 #include <linux/compat.h>
633 +#include <linux/vs_base.h>
634 #include <trace/syscall.h>
635 #include <asm/segment.h>
636 #include <asm/page.h>
637 diff -NurpP --minimal linux-3.9.4/arch/s390/kernel/syscalls.S linux-3.9.4-vs2.3.6.2/arch/s390/kernel/syscalls.S
638 --- linux-3.9.4/arch/s390/kernel/syscalls.S 2013-05-31 13:44:45.000000000 +0000
639 +++ linux-3.9.4-vs2.3.6.2/arch/s390/kernel/syscalls.S 2013-05-31 14:47:11.000000000 +0000
640 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
641 SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper) /* 260 */
642 SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
643 SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
644 -NI_SYSCALL /* reserved for vserver */
645 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
646 SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
647 SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
648 SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
649 diff -NurpP --minimal linux-3.9.4/arch/sh/Kconfig linux-3.9.4-vs2.3.6.2/arch/sh/Kconfig
650 --- linux-3.9.4/arch/sh/Kconfig 2013-05-31 13:44:45.000000000 +0000
651 +++ linux-3.9.4-vs2.3.6.2/arch/sh/Kconfig 2013-05-31 14:47:11.000000000 +0000
652 @@ -951,6 +951,8 @@ source "fs/Kconfig"
654 source "arch/sh/Kconfig.debug"
656 +source "kernel/vserver/Kconfig"
658 source "security/Kconfig"
660 source "crypto/Kconfig"
661 diff -NurpP --minimal linux-3.9.4/arch/sh/kernel/irq.c linux-3.9.4-vs2.3.6.2/arch/sh/kernel/irq.c
662 --- linux-3.9.4/arch/sh/kernel/irq.c 2012-12-11 03:30:57.000000000 +0000
663 +++ linux-3.9.4-vs2.3.6.2/arch/sh/kernel/irq.c 2013-05-31 14:47:11.000000000 +0000
665 #include <linux/ftrace.h>
666 #include <linux/delay.h>
667 #include <linux/ratelimit.h>
668 +// #include <linux/vs_context.h>
669 #include <asm/processor.h>
670 #include <asm/machvec.h>
671 #include <asm/uaccess.h>
672 diff -NurpP --minimal linux-3.9.4/arch/sparc/Kconfig linux-3.9.4-vs2.3.6.2/arch/sparc/Kconfig
673 --- linux-3.9.4/arch/sparc/Kconfig 2013-05-31 13:44:47.000000000 +0000
674 +++ linux-3.9.4-vs2.3.6.2/arch/sparc/Kconfig 2013-05-31 14:47:11.000000000 +0000
675 @@ -559,6 +559,8 @@ source "fs/Kconfig"
677 source "arch/sparc/Kconfig.debug"
679 +source "kernel/vserver/Kconfig"
681 source "security/Kconfig"
683 source "crypto/Kconfig"
684 diff -NurpP --minimal linux-3.9.4/arch/sparc/include/uapi/asm/unistd.h linux-3.9.4-vs2.3.6.2/arch/sparc/include/uapi/asm/unistd.h
685 --- linux-3.9.4/arch/sparc/include/uapi/asm/unistd.h 2013-02-19 13:57:17.000000000 +0000
686 +++ linux-3.9.4-vs2.3.6.2/arch/sparc/include/uapi/asm/unistd.h 2013-05-31 14:47:11.000000000 +0000
688 #define __NR_timer_getoverrun 264
689 #define __NR_timer_delete 265
690 #define __NR_timer_create 266
691 -/* #define __NR_vserver 267 Reserved for VSERVER */
692 +#define __NR_vserver 267
693 #define __NR_io_setup 268
694 #define __NR_io_destroy 269
695 #define __NR_io_submit 270
696 diff -NurpP --minimal linux-3.9.4/arch/sparc/kernel/systbls_32.S linux-3.9.4-vs2.3.6.2/arch/sparc/kernel/systbls_32.S
697 --- linux-3.9.4/arch/sparc/kernel/systbls_32.S 2013-05-31 13:44:48.000000000 +0000
698 +++ linux-3.9.4-vs2.3.6.2/arch/sparc/kernel/systbls_32.S 2013-05-31 14:47:11.000000000 +0000
699 @@ -70,7 +70,7 @@ sys_call_table:
700 /*250*/ .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
701 /*255*/ .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
702 /*260*/ .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
703 -/*265*/ .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
704 +/*265*/ .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
705 /*270*/ .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
706 /*275*/ .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
707 /*280*/ .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
708 diff -NurpP --minimal linux-3.9.4/arch/sparc/kernel/systbls_64.S linux-3.9.4-vs2.3.6.2/arch/sparc/kernel/systbls_64.S
709 --- linux-3.9.4/arch/sparc/kernel/systbls_64.S 2013-05-31 13:44:48.000000000 +0000
710 +++ linux-3.9.4-vs2.3.6.2/arch/sparc/kernel/systbls_64.S 2013-05-31 14:47:11.000000000 +0000
711 @@ -71,7 +71,7 @@ sys_call_table32:
712 /*250*/ .word sys_mremap, compat_sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
713 .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
714 /*260*/ .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
715 - .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
716 + .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
717 /*270*/ .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
718 .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
719 /*280*/ .word sys_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
720 @@ -149,7 +149,7 @@ sys_call_table:
721 /*250*/ .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
722 .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
723 /*260*/ .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
724 - .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
725 + .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
726 /*270*/ .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
727 .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
728 /*280*/ .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
729 diff -NurpP --minimal linux-3.9.4/arch/um/Kconfig.rest linux-3.9.4-vs2.3.6.2/arch/um/Kconfig.rest
730 --- linux-3.9.4/arch/um/Kconfig.rest 2012-12-11 03:30:57.000000000 +0000
731 +++ linux-3.9.4-vs2.3.6.2/arch/um/Kconfig.rest 2013-05-31 14:47:11.000000000 +0000
732 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
736 +source "kernel/vserver/Kconfig"
738 source "security/Kconfig"
740 source "crypto/Kconfig"
741 diff -NurpP --minimal linux-3.9.4/arch/x86/Kconfig linux-3.9.4-vs2.3.6.2/arch/x86/Kconfig
742 --- linux-3.9.4/arch/x86/Kconfig 2013-05-31 14:22:26.000000000 +0000
743 +++ linux-3.9.4-vs2.3.6.2/arch/x86/Kconfig 2013-05-31 14:47:11.000000000 +0000
744 @@ -2341,6 +2341,8 @@ source "fs/Kconfig"
746 source "arch/x86/Kconfig.debug"
748 +source "kernel/vserver/Kconfig"
750 source "security/Kconfig"
752 source "crypto/Kconfig"
753 diff -NurpP --minimal linux-3.9.4/arch/x86/syscalls/syscall_32.tbl linux-3.9.4-vs2.3.6.2/arch/x86/syscalls/syscall_32.tbl
754 --- linux-3.9.4/arch/x86/syscalls/syscall_32.tbl 2013-05-31 13:44:50.000000000 +0000
755 +++ linux-3.9.4-vs2.3.6.2/arch/x86/syscalls/syscall_32.tbl 2013-05-31 14:47:11.000000000 +0000
757 270 i386 tgkill sys_tgkill
758 271 i386 utimes sys_utimes compat_sys_utimes
759 272 i386 fadvise64_64 sys_fadvise64_64 sys32_fadvise64_64
761 +273 i386 vserver sys_vserver sys32_vserver
762 274 i386 mbind sys_mbind
763 275 i386 get_mempolicy sys_get_mempolicy compat_sys_get_mempolicy
764 276 i386 set_mempolicy sys_set_mempolicy
765 diff -NurpP --minimal linux-3.9.4/arch/x86/syscalls/syscall_64.tbl linux-3.9.4-vs2.3.6.2/arch/x86/syscalls/syscall_64.tbl
766 --- linux-3.9.4/arch/x86/syscalls/syscall_64.tbl 2013-05-31 13:44:50.000000000 +0000
767 +++ linux-3.9.4-vs2.3.6.2/arch/x86/syscalls/syscall_64.tbl 2013-05-31 14:47:11.000000000 +0000
769 233 common epoll_ctl sys_epoll_ctl
770 234 common tgkill sys_tgkill
771 235 common utimes sys_utimes
773 +236 64 vserver sys_vserver
774 237 common mbind sys_mbind
775 238 common set_mempolicy sys_set_mempolicy
776 239 common get_mempolicy sys_get_mempolicy
777 diff -NurpP --minimal linux-3.9.4/drivers/block/Kconfig linux-3.9.4-vs2.3.6.2/drivers/block/Kconfig
778 --- linux-3.9.4/drivers/block/Kconfig 2013-05-31 13:44:51.000000000 +0000
779 +++ linux-3.9.4-vs2.3.6.2/drivers/block/Kconfig 2013-05-31 14:47:11.000000000 +0000
780 @@ -278,6 +278,13 @@ config BLK_DEV_CRYPTOLOOP
782 source "drivers/block/drbd/Kconfig"
784 +config BLK_DEV_VROOT
785 + tristate "Virtual Root device support"
786 + depends on QUOTACTL
788 + Saying Y here will allow you to use quota/fs ioctls on a shared
789 + partition within a virtual server without compromising security.
792 tristate "Network block device support"
794 diff -NurpP --minimal linux-3.9.4/drivers/block/Makefile linux-3.9.4-vs2.3.6.2/drivers/block/Makefile
795 --- linux-3.9.4/drivers/block/Makefile 2013-05-31 13:44:51.000000000 +0000
796 +++ linux-3.9.4-vs2.3.6.2/drivers/block/Makefile 2013-05-31 14:47:11.000000000 +0000
797 @@ -33,6 +33,7 @@ obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
798 obj-$(CONFIG_VIODASD) += viodasd.o
799 obj-$(CONFIG_BLK_DEV_SX8) += sx8.o
800 obj-$(CONFIG_BLK_DEV_HD) += hd.o
801 +obj-$(CONFIG_BLK_DEV_VROOT) += vroot.o
803 obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o
804 obj-$(CONFIG_XEN_BLKDEV_BACKEND) += xen-blkback/
805 diff -NurpP --minimal linux-3.9.4/drivers/block/loop.c linux-3.9.4-vs2.3.6.2/drivers/block/loop.c
806 --- linux-3.9.4/drivers/block/loop.c 2013-05-31 13:44:51.000000000 +0000
807 +++ linux-3.9.4-vs2.3.6.2/drivers/block/loop.c 2013-05-31 14:47:11.000000000 +0000
809 #include <linux/sysfs.h>
810 #include <linux/miscdevice.h>
811 #include <linux/falloc.h>
812 +#include <linux/vs_context.h>
814 #include <asm/uaccess.h>
816 @@ -882,6 +883,7 @@ static int loop_set_fd(struct loop_devic
817 lo->lo_blocksize = lo_blocksize;
818 lo->lo_device = bdev;
819 lo->lo_flags = lo_flags;
820 + lo->lo_xid = vx_current_xid();
821 lo->lo_backing_file = file;
822 lo->transfer = transfer_none;
824 @@ -1033,6 +1035,7 @@ static int loop_clr_fd(struct loop_devic
825 lo->lo_sizelimit = 0;
826 lo->lo_encrypt_key_size = 0;
827 lo->lo_thread = NULL;
829 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
830 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
831 memset(lo->lo_file_name, 0, LO_NAME_SIZE);
832 @@ -1076,7 +1079,7 @@ loop_set_status(struct loop_device *lo,
834 if (lo->lo_encrypt_key_size &&
835 !uid_eq(lo->lo_key_owner, uid) &&
836 - !capable(CAP_SYS_ADMIN))
837 + !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
839 if (lo->lo_state != Lo_bound)
841 @@ -1166,7 +1169,8 @@ loop_get_status(struct loop_device *lo,
842 memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
843 info->lo_encrypt_type =
844 lo->lo_encryption ? lo->lo_encryption->number : 0;
845 - if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
846 + if (lo->lo_encrypt_key_size &&
847 + vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
848 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
849 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
850 lo->lo_encrypt_key_size);
851 @@ -1508,6 +1512,11 @@ static int lo_open(struct block_device *
855 + if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
860 mutex_lock(&lo->lo_ctl_mutex);
862 mutex_unlock(&lo->lo_ctl_mutex);
863 diff -NurpP --minimal linux-3.9.4/drivers/block/vroot.c linux-3.9.4-vs2.3.6.2/drivers/block/vroot.c
864 --- linux-3.9.4/drivers/block/vroot.c 1970-01-01 00:00:00.000000000 +0000
865 +++ linux-3.9.4-vs2.3.6.2/drivers/block/vroot.c 2013-05-31 14:47:11.000000000 +0000
868 + * linux/drivers/block/vroot.c
870 + * written by Herbert Pötzl, 9/11/2002
871 + * ported to 2.6.10 by Herbert Pötzl, 30/12/2004
873 + * based on the loop.c code by Theodore Ts'o.
875 + * Copyright (C) 2002-2007 by Herbert Pötzl.
876 + * Redistribution of this file is permitted under the
877 + * GNU General Public License.
881 +#include <linux/module.h>
882 +#include <linux/moduleparam.h>
883 +#include <linux/file.h>
884 +#include <linux/major.h>
885 +#include <linux/blkdev.h>
886 +#include <linux/slab.h>
888 +#include <linux/vroot.h>
889 +#include <linux/vs_context.h>
892 +static int max_vroot = 8;
894 +static struct vroot_device *vroot_dev;
895 +static struct gendisk **disks;
898 +static int vroot_set_dev(
899 + struct vroot_device *vr,
900 + struct block_device *bdev,
903 + struct block_device *real_bdev;
905 + struct inode *inode;
909 + if (vr->vr_state != Vr_unbound)
918 + inode = file->f_dentry->d_inode;
921 + if (S_ISBLK(inode->i_mode)) {
922 + real_bdev = inode->i_bdev;
923 + vr->vr_device = real_bdev;
924 + __iget(real_bdev->bd_inode);
928 + vxdprintk(VXD_CBIT(misc, 0),
929 + "vroot[%d]_set_dev: dev=" VXF_DEV,
930 + vr->vr_number, VXD_DEV(real_bdev));
932 + vr->vr_state = Vr_bound;
941 +static int vroot_clr_dev(
942 + struct vroot_device *vr,
943 + struct block_device *bdev)
945 + struct block_device *real_bdev;
947 + if (vr->vr_state != Vr_bound)
949 + if (vr->vr_refcnt > 1) /* we needed one fd for the ioctl */
952 + real_bdev = vr->vr_device;
954 + vxdprintk(VXD_CBIT(misc, 0),
955 + "vroot[%d]_clr_dev: dev=" VXF_DEV,
956 + vr->vr_number, VXD_DEV(real_bdev));
959 + vr->vr_state = Vr_unbound;
960 + vr->vr_device = NULL;
965 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
966 + unsigned int cmd, unsigned long arg)
968 + struct vroot_device *vr = bdev->bd_disk->private_data;
971 + down(&vr->vr_ctl_mutex);
973 + case VROOT_SET_DEV:
974 + err = vroot_set_dev(vr, bdev, arg);
976 + case VROOT_CLR_DEV:
977 + err = vroot_clr_dev(vr, bdev);
983 + up(&vr->vr_ctl_mutex);
987 +static int vr_open(struct block_device *bdev, fmode_t mode)
989 + struct vroot_device *vr = bdev->bd_disk->private_data;
991 + down(&vr->vr_ctl_mutex);
993 + up(&vr->vr_ctl_mutex);
997 +static int vr_release(struct gendisk *disk, fmode_t mode)
999 + struct vroot_device *vr = disk->private_data;
1001 + down(&vr->vr_ctl_mutex);
1003 + up(&vr->vr_ctl_mutex);
1007 +static struct block_device_operations vr_fops = {
1008 + .owner = THIS_MODULE,
1010 + .release = vr_release,
1011 + .ioctl = vr_ioctl,
1014 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
1016 + printk("vroot_make_request %p, %p\n", q, bio);
1017 + bio_io_error(bio);
1020 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1022 + struct inode *inode = bdev->bd_inode;
1023 + struct vroot_device *vr;
1024 + struct block_device *real_bdev;
1025 + int minor = iminor(inode);
1027 + vr = &vroot_dev[minor];
1028 + real_bdev = vr->vr_device;
1030 + vxdprintk(VXD_CBIT(misc, 0),
1031 + "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1032 + vr->vr_number, VXD_DEV(real_bdev));
1034 + if (vr->vr_state != Vr_bound)
1035 + return ERR_PTR(-ENXIO);
1037 + __iget(real_bdev->bd_inode);
1044 + * And now the modules code and kernel interface.
1047 +module_param(max_vroot, int, 0);
1049 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1050 +MODULE_LICENSE("GPL");
1051 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1053 +MODULE_AUTHOR ("Herbert Pötzl");
1054 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1057 +int __init vroot_init(void)
1061 + if (max_vroot < 1 || max_vroot > 256) {
1062 + max_vroot = MAX_VROOT_DEFAULT;
1063 + printk(KERN_WARNING "vroot: invalid max_vroot "
1064 + "(must be between 1 and 256), "
1065 + "using default (%d)\n", max_vroot);
1068 + if (register_blkdev(VROOT_MAJOR, "vroot"))
1072 + vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1075 + memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1077 + disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1081 + for (i = 0; i < max_vroot; i++) {
1082 + disks[i] = alloc_disk(1);
1085 + disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1086 + if (!disks[i]->queue)
1088 + blk_queue_make_request(disks[i]->queue, vroot_make_request);
1091 + for (i = 0; i < max_vroot; i++) {
1092 + struct vroot_device *vr = &vroot_dev[i];
1093 + struct gendisk *disk = disks[i];
1095 + memset(vr, 0, sizeof(*vr));
1096 + sema_init(&vr->vr_ctl_mutex, 1);
1097 + vr->vr_number = i;
1098 + disk->major = VROOT_MAJOR;
1099 + disk->first_minor = i;
1100 + disk->fops = &vr_fops;
1101 + sprintf(disk->disk_name, "vroot%d", i);
1102 + disk->private_data = vr;
1105 + err = register_vroot_grb(&__vroot_get_real_bdev);
1109 + for (i = 0; i < max_vroot; i++)
1110 + add_disk(disks[i]);
1111 + printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1116 + put_disk(disks[i]);
1121 + unregister_blkdev(VROOT_MAJOR, "vroot");
1122 + printk(KERN_ERR "vroot: ran out of memory\n");
1126 +void vroot_exit(void)
1130 + if (unregister_vroot_grb(&__vroot_get_real_bdev))
1131 + printk(KERN_WARNING "vroot: cannot unregister grb\n");
1133 + for (i = 0; i < max_vroot; i++) {
1134 + del_gendisk(disks[i]);
1135 + put_disk(disks[i]);
1137 + unregister_blkdev(VROOT_MAJOR, "vroot");
1143 +module_init(vroot_init);
1144 +module_exit(vroot_exit);
1148 +static int __init max_vroot_setup(char *str)
1150 + max_vroot = simple_strtol(str, NULL, 0);
1154 +__setup("max_vroot=", max_vroot_setup);
1158 diff -NurpP --minimal linux-3.9.4/drivers/infiniband/Kconfig linux-3.9.4-vs2.3.6.2/drivers/infiniband/Kconfig
1159 --- linux-3.9.4/drivers/infiniband/Kconfig 2012-12-11 03:30:57.000000000 +0000
1160 +++ linux-3.9.4-vs2.3.6.2/drivers/infiniband/Kconfig 2013-05-31 14:47:11.000000000 +0000
1161 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1162 config INFINIBAND_ADDR_TRANS
1165 - depends on !(INFINIBAND = y && IPV6 = m)
1166 + depends on !(INFINIBAND = y && IPV6 = y)
1169 source "drivers/infiniband/hw/mthca/Kconfig"
1170 diff -NurpP --minimal linux-3.9.4/drivers/infiniband/core/addr.c linux-3.9.4-vs2.3.6.2/drivers/infiniband/core/addr.c
1171 --- linux-3.9.4/drivers/infiniband/core/addr.c 2012-12-11 03:30:57.000000000 +0000
1172 +++ linux-3.9.4-vs2.3.6.2/drivers/infiniband/core/addr.c 2013-05-31 14:47:11.000000000 +0000
1173 @@ -261,7 +261,7 @@ static int addr6_resolve(struct sockaddr
1175 if (ipv6_addr_any(&fl6.saddr)) {
1176 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1177 - &fl6.daddr, 0, &fl6.saddr);
1178 + &fl6.daddr, 0, &fl6.saddr, NULL);
1182 diff -NurpP --minimal linux-3.9.4/drivers/md/dm-ioctl.c linux-3.9.4-vs2.3.6.2/drivers/md/dm-ioctl.c
1183 --- linux-3.9.4/drivers/md/dm-ioctl.c 2013-05-31 13:44:59.000000000 +0000
1184 +++ linux-3.9.4-vs2.3.6.2/drivers/md/dm-ioctl.c 2013-05-31 14:47:11.000000000 +0000
1186 #include <linux/dm-ioctl.h>
1187 #include <linux/hdreg.h>
1188 #include <linux/compat.h>
1189 +#include <linux/vs_context.h>
1191 #include <asm/uaccess.h>
1193 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1194 unsigned int h = hash_str(str);
1196 list_for_each_entry (hc, _name_buckets + h, name_list)
1197 - if (!strcmp(hc->name, str)) {
1198 + if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1199 + !strcmp(hc->name, str)) {
1203 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1204 unsigned int h = hash_str(str);
1206 list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1207 - if (!strcmp(hc->uuid, str)) {
1208 + if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1209 + !strcmp(hc->uuid, str)) {
1213 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1214 static struct hash_cell *__get_dev_cell(uint64_t dev)
1216 struct mapped_device *md;
1217 - struct hash_cell *hc;
1218 + struct hash_cell *hc = NULL;
1220 md = dm_get_md(huge_decode_dev(dev));
1224 - hc = dm_get_mdptr(md);
1225 + if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1226 + hc = dm_get_mdptr(md);
1231 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1233 static int remove_all(struct dm_ioctl *param, size_t param_size)
1235 + if (!vx_check(0, VS_ADMIN))
1238 dm_hash_remove_all(1);
1239 param->data_size = 0;
1241 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl
1243 for (i = 0; i < NUM_BUCKETS; i++) {
1244 list_for_each_entry (hc, _name_buckets + i, name_list) {
1245 + if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1247 needed += sizeof(struct dm_name_list);
1248 needed += strlen(hc->name) + 1;
1249 needed += ALIGN_MASK;
1250 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl
1252 for (i = 0; i < NUM_BUCKETS; i++) {
1253 list_for_each_entry (hc, _name_buckets + i, name_list) {
1254 + if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1257 old_nl->next = (uint32_t) ((void *) nl -
1259 @@ -1722,8 +1734,8 @@ static int ctl_ioctl(uint command, struc
1260 size_t input_param_size;
1261 struct dm_ioctl param_kernel;
1263 - /* only root can play with this */
1264 - if (!capable(CAP_SYS_ADMIN))
1265 + /* only root and certain contexts can play with this */
1266 + if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1269 if (_IOC_TYPE(command) != DM_IOCTL)
1270 diff -NurpP --minimal linux-3.9.4/drivers/md/dm.c linux-3.9.4-vs2.3.6.2/drivers/md/dm.c
1271 --- linux-3.9.4/drivers/md/dm.c 2013-05-31 13:44:59.000000000 +0000
1272 +++ linux-3.9.4-vs2.3.6.2/drivers/md/dm.c 2013-05-31 14:47:11.000000000 +0000
1274 #include <linux/idr.h>
1275 #include <linux/hdreg.h>
1276 #include <linux/delay.h>
1277 +#include <linux/vs_base.h>
1279 #include <trace/events/block.h>
1281 @@ -125,6 +126,7 @@ struct mapped_device {
1284 atomic_t open_count;
1287 unsigned long flags;
1289 @@ -317,6 +319,7 @@ int dm_deleting_md(struct mapped_device
1290 static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1292 struct mapped_device *md;
1295 spin_lock(&_minor_lock);
1297 @@ -325,18 +328,19 @@ static int dm_blk_open(struct block_devi
1300 if (test_bit(DMF_FREEING, &md->flags) ||
1301 - dm_deleting_md(md)) {
1303 + dm_deleting_md(md))
1307 + if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1312 atomic_inc(&md->open_count);
1316 spin_unlock(&_minor_lock);
1318 - return md ? 0 : -ENXIO;
1322 static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1323 @@ -547,6 +551,14 @@ int dm_set_geometry(struct mapped_device
1328 + * Get the xid associated with a dm device
1330 +xid_t dm_get_xid(struct mapped_device *md)
1335 /*-----------------------------------------------------------------
1337 * A more elegant soln is in the works that uses the queue
1338 @@ -1884,6 +1896,7 @@ static struct mapped_device *alloc_dev(i
1339 INIT_LIST_HEAD(&md->uevent_list);
1340 spin_lock_init(&md->uevent_lock);
1342 + md->xid = vx_current_xid();
1343 md->queue = blk_alloc_queue(GFP_KERNEL);
1346 diff -NurpP --minimal linux-3.9.4/drivers/md/dm.h linux-3.9.4-vs2.3.6.2/drivers/md/dm.h
1347 --- linux-3.9.4/drivers/md/dm.h 2013-02-19 13:57:51.000000000 +0000
1348 +++ linux-3.9.4-vs2.3.6.2/drivers/md/dm.h 2013-05-31 14:47:11.000000000 +0000
1349 @@ -46,6 +46,8 @@ struct dm_dev_internal {
1351 struct dm_md_mempools;
1353 +xid_t dm_get_xid(struct mapped_device *md);
1355 /*-----------------------------------------------------------------
1356 * Internal table functions.
1357 *---------------------------------------------------------------*/
1358 diff -NurpP --minimal linux-3.9.4/drivers/net/tun.c linux-3.9.4-vs2.3.6.2/drivers/net/tun.c
1359 --- linux-3.9.4/drivers/net/tun.c 2013-05-31 14:22:27.000000000 +0000
1360 +++ linux-3.9.4-vs2.3.6.2/drivers/net/tun.c 2013-05-31 20:01:45.000000000 +0000
1362 #include <linux/nsproxy.h>
1363 #include <linux/virtio_net.h>
1364 #include <linux/rcupdate.h>
1365 +#include <linux/vs_network.h>
1366 #include <net/net_namespace.h>
1367 #include <net/netns/generic.h>
1368 #include <net/rtnetlink.h>
1369 @@ -164,6 +165,7 @@ struct tun_struct {
1375 struct net_device *dev;
1376 netdev_features_t set_features;
1377 @@ -380,6 +382,7 @@ static inline bool tun_not_capable(struc
1378 return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1379 (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1380 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1381 + /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1384 static void tun_set_real_num_queues(struct tun_struct *tun)
1385 @@ -1404,6 +1407,7 @@ static void tun_setup(struct net_device
1387 tun->owner = INVALID_UID;
1388 tun->group = INVALID_GID;
1389 + tun->nid = nx_current_nid();
1391 dev->ethtool_ops = &tun_ethtool_ops;
1392 dev->destructor = tun_free_netdev;
1393 @@ -1591,6 +1595,9 @@ static int tun_set_iff(struct net *net,
1397 + if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1400 err = tun_attach(tun, file);
1403 @@ -1605,7 +1612,7 @@ static int tun_set_iff(struct net *net,
1404 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1407 - if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1408 + if (!vx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1410 err = security_tun_dev_create();
1412 @@ -1950,6 +1957,16 @@ static long __tun_chr_ioctl(struct file
1413 from_kgid(&init_user_ns, tun->group));
1417 + if (!capable(CAP_CONTEXT))
1420 + /* Set nid owner of the device */
1421 + tun->nid = (nid_t) arg;
1423 + tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1427 /* Only allow setting the type when the interface is down */
1428 if (tun->dev->flags & IFF_UP) {
1429 diff -NurpP --minimal linux-3.9.4/drivers/staging/csr/csr_wifi_hip_xbv.c linux-3.9.4-vs2.3.6.2/drivers/staging/csr/csr_wifi_hip_xbv.c
1430 --- linux-3.9.4/drivers/staging/csr/csr_wifi_hip_xbv.c 2013-02-19 13:58:32.000000000 +0000
1431 +++ linux-3.9.4-vs2.3.6.2/drivers/staging/csr/csr_wifi_hip_xbv.c 2013-05-31 14:47:11.000000000 +0000
1432 @@ -55,7 +55,7 @@ typedef struct
1440 #define TAG_EQ(i, v) (((i)[0] == (v)[0]) && \
1441 @@ -90,7 +90,7 @@ typedef struct
1445 -static s32 read_tag(card_t *card, ct_t *ct, tag_t *tag);
1446 +static s32 read_tag(card_t *card, ct_t *ct, ctag_t *tag);
1447 static s32 read_bytes(card_t *card, ct_t *ct, void *buf, u32 len);
1448 static s32 read_uint(card_t *card, ct_t *ct, u32 *u, u32 len);
1449 static s32 xbv_check(xbv1_t *fwinfo, const xbv_stack_t *stack,
1450 @@ -160,7 +160,7 @@ static u32 write_fwdl_to_ptdl(void *buf,
1451 CsrResult xbv1_parse(card_t *card, fwreadfn_t readfn, void *dlpriv, xbv1_t *fwinfo)
1459 @@ -505,7 +505,7 @@ static u32 xbv2uint(u8 *ptr, s32 len)
1463 -static s32 read_tag(card_t *card, ct_t *ct, tag_t *tag)
1464 +static s32 read_tag(card_t *card, ct_t *ct, ctag_t *tag)
1468 diff -NurpP --minimal linux-3.9.4/drivers/tty/sysrq.c linux-3.9.4-vs2.3.6.2/drivers/tty/sysrq.c
1469 --- linux-3.9.4/drivers/tty/sysrq.c 2013-05-31 13:45:19.000000000 +0000
1470 +++ linux-3.9.4-vs2.3.6.2/drivers/tty/sysrq.c 2013-05-31 15:08:19.000000000 +0000
1472 #include <linux/input.h>
1473 #include <linux/uaccess.h>
1474 #include <linux/moduleparam.h>
1475 +#include <linux/vserver/debug.h>
1477 #include <asm/ptrace.h>
1478 #include <asm/irq_regs.h>
1479 @@ -401,6 +402,21 @@ static struct sysrq_key_op sysrq_unrt_op
1480 .enable_mask = SYSRQ_ENABLE_RTNICE,
1484 +#ifdef CONFIG_VSERVER_DEBUG
1485 +static void sysrq_handle_vxinfo(int key)
1487 + dump_vx_info_inactive((key == 'x') ? 0 : 1);
1490 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1491 + .handler = sysrq_handle_vxinfo,
1492 + .help_msg = "conteXt",
1493 + .action_msg = "Show Context Info",
1494 + .enable_mask = SYSRQ_ENABLE_DUMP,
1498 /* Key Operations table and lock */
1499 static DEFINE_SPINLOCK(sysrq_key_table_lock);
1501 @@ -456,7 +472,11 @@ static struct sysrq_key_op *sysrq_key_ta
1502 &sysrq_showstate_blocked_op, /* w */
1503 /* x: May be registered on ppc/powerpc for xmon */
1504 /* x: May be registered on sparc64 for global PMU dump */
1505 +#ifdef CONFIG_VSERVER_DEBUG
1506 + &sysrq_showvxinfo_op, /* x */
1510 /* y: May be registered on sparc64 for global register dump */
1512 &sysrq_ftrace_dump_op, /* z */
1513 @@ -471,6 +491,8 @@ static int sysrq_key_table_key2index(int
1515 else if ((key >= 'a') && (key <= 'z'))
1516 retval = key + 10 - 'a';
1517 + else if ((key >= 'A') && (key <= 'Z'))
1518 + retval = key + 10 - 'A';
1522 diff -NurpP --minimal linux-3.9.4/drivers/tty/tty_io.c linux-3.9.4-vs2.3.6.2/drivers/tty/tty_io.c
1523 --- linux-3.9.4/drivers/tty/tty_io.c 2013-05-31 14:22:27.000000000 +0000
1524 +++ linux-3.9.4-vs2.3.6.2/drivers/tty/tty_io.c 2013-05-31 14:47:11.000000000 +0000
1527 #include <linux/kmod.h>
1528 #include <linux/nsproxy.h>
1529 +#include <linux/vs_pid.h>
1531 #undef TTY_DEBUG_HANGUP
1533 @@ -2144,7 +2145,8 @@ static int tiocsti(struct tty_struct *tt
1535 struct tty_ldisc *ld;
1537 - if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1538 + if (((current->signal->tty != tty) &&
1539 + !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1541 if (get_user(ch, p))
1543 @@ -2432,6 +2434,7 @@ static int tiocspgrp(struct tty_struct *
1545 if (get_user(pgrp_nr, p))
1547 + pgrp_nr = vx_rmap_pid(pgrp_nr);
1551 diff -NurpP --minimal linux-3.9.4/fs/attr.c linux-3.9.4-vs2.3.6.2/fs/attr.c
1552 --- linux-3.9.4/fs/attr.c 2013-02-19 13:58:46.000000000 +0000
1553 +++ linux-3.9.4-vs2.3.6.2/fs/attr.c 2013-05-31 14:47:11.000000000 +0000
1555 #include <linux/security.h>
1556 #include <linux/evm.h>
1557 #include <linux/ima.h>
1558 +#include <linux/proc_fs.h>
1559 +#include <linux/devpts_fs.h>
1560 +#include <linux/vs_tag.h>
1563 * inode_change_ok - check if attribute changes to an inode are allowed
1564 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1568 + /* check for inode tag permission */
1569 + if (dx_permission(inode, MAY_WRITE))
1574 EXPORT_SYMBOL(inode_change_ok);
1575 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1576 inode->i_uid = attr->ia_uid;
1577 if (ia_valid & ATTR_GID)
1578 inode->i_gid = attr->ia_gid;
1579 + if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1580 + inode->i_tag = attr->ia_tag;
1581 if (ia_valid & ATTR_ATIME)
1582 inode->i_atime = timespec_trunc(attr->ia_atime,
1583 inode->i_sb->s_time_gran);
1584 @@ -177,7 +186,8 @@ int notify_change(struct dentry * dentry
1586 WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1588 - if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1589 + if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1590 + ATTR_TAG | ATTR_TIMES_SET)) {
1591 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1594 diff -NurpP --minimal linux-3.9.4/fs/block_dev.c linux-3.9.4-vs2.3.6.2/fs/block_dev.c
1595 --- linux-3.9.4/fs/block_dev.c 2013-05-31 13:45:22.000000000 +0000
1596 +++ linux-3.9.4-vs2.3.6.2/fs/block_dev.c 2013-05-31 14:47:11.000000000 +0000
1598 #include <linux/namei.h>
1599 #include <linux/log2.h>
1600 #include <linux/cleancache.h>
1601 +#include <linux/vs_device.h>
1602 #include <asm/uaccess.h>
1603 #include "internal.h"
1605 @@ -528,6 +529,7 @@ struct block_device *bdget(dev_t dev)
1606 bdev->bd_invalidated = 0;
1607 inode->i_mode = S_IFBLK;
1608 inode->i_rdev = dev;
1609 + inode->i_mdev = dev;
1610 inode->i_bdev = bdev;
1611 inode->i_data.a_ops = &def_blk_aops;
1612 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1613 @@ -575,6 +577,11 @@ EXPORT_SYMBOL(bdput);
1614 static struct block_device *bd_acquire(struct inode *inode)
1616 struct block_device *bdev;
1619 + if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1621 + inode->i_mdev = mdev;
1623 spin_lock(&bdev_lock);
1624 bdev = inode->i_bdev;
1625 @@ -585,7 +592,7 @@ static struct block_device *bd_acquire(s
1627 spin_unlock(&bdev_lock);
1629 - bdev = bdget(inode->i_rdev);
1630 + bdev = bdget(mdev);
1632 spin_lock(&bdev_lock);
1633 if (!inode->i_bdev) {
1634 diff -NurpP --minimal linux-3.9.4/fs/btrfs/ctree.h linux-3.9.4-vs2.3.6.2/fs/btrfs/ctree.h
1635 --- linux-3.9.4/fs/btrfs/ctree.h 2013-05-31 13:45:22.000000000 +0000
1636 +++ linux-3.9.4-vs2.3.6.2/fs/btrfs/ctree.h 2013-05-31 14:47:11.000000000 +0000
1637 @@ -705,11 +705,14 @@ struct btrfs_inode_item {
1638 /* modification sequence number for NFS */
1643 * a little future expansion, for more than this we can
1644 * just grow the inode item and version it
1646 - __le64 reserved[4];
1647 + __le16 reserved16;
1648 + __le32 reserved32;
1649 + __le64 reserved[3];
1650 struct btrfs_timespec atime;
1651 struct btrfs_timespec ctime;
1652 struct btrfs_timespec mtime;
1653 @@ -1901,6 +1904,8 @@ struct btrfs_ioctl_defrag_range_args {
1654 #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1655 #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR (1 << 22)
1657 +#define BTRFS_MOUNT_TAGGED (1 << 24)
1659 #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
1660 #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
1661 #define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt)
1662 @@ -2170,6 +2175,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1663 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1664 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1665 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1666 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1667 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1668 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1669 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1670 @@ -2223,6 +2229,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1672 BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1674 +#define BTRFS_INODE_IXUNLINK (1 << 24)
1675 +#define BTRFS_INODE_BARRIER (1 << 25)
1676 +#define BTRFS_INODE_COW (1 << 26)
1679 BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1681 @@ -3581,6 +3591,7 @@ extern const struct dentry_operations bt
1682 long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1683 void btrfs_update_iflags(struct inode *inode);
1684 void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1685 +int btrfs_sync_flags(struct inode *inode, int, int);
1686 int btrfs_defrag_file(struct inode *inode, struct file *file,
1687 struct btrfs_ioctl_defrag_range_args *range,
1688 u64 newer_than, unsigned long max_pages);
1689 diff -NurpP --minimal linux-3.9.4/fs/btrfs/disk-io.c linux-3.9.4-vs2.3.6.2/fs/btrfs/disk-io.c
1690 --- linux-3.9.4/fs/btrfs/disk-io.c 2013-05-31 13:45:22.000000000 +0000
1691 +++ linux-3.9.4-vs2.3.6.2/fs/btrfs/disk-io.c 2013-05-31 14:47:11.000000000 +0000
1692 @@ -2258,6 +2258,9 @@ int open_ctree(struct super_block *sb,
1696 + if (btrfs_test_opt(tree_root, TAGGED))
1697 + sb->s_flags |= MS_TAGGED;
1699 features = btrfs_super_incompat_flags(disk_super) &
1700 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1702 diff -NurpP --minimal linux-3.9.4/fs/btrfs/inode.c linux-3.9.4-vs2.3.6.2/fs/btrfs/inode.c
1703 --- linux-3.9.4/fs/btrfs/inode.c 2013-05-31 14:22:27.000000000 +0000
1704 +++ linux-3.9.4-vs2.3.6.2/fs/btrfs/inode.c 2013-05-31 20:42:33.000000000 +0000
1706 #include <linux/mount.h>
1707 #include <linux/btrfs.h>
1708 #include <linux/blkdev.h>
1709 +#include <linux/vs_tag.h>
1712 #include "disk-io.h"
1713 @@ -3312,6 +3313,8 @@ static void btrfs_read_locked_inode(stru
1714 struct btrfs_key location;
1720 bool filled = false;
1722 @@ -3339,8 +3342,13 @@ static void btrfs_read_locked_inode(stru
1723 struct btrfs_inode_item);
1724 inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1725 set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1726 - i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1727 - i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1729 + uid = btrfs_inode_uid(leaf, inode_item);
1730 + gid = btrfs_inode_gid(leaf, inode_item);
1731 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
1732 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
1733 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
1734 + btrfs_inode_tag(leaf, inode_item)));
1735 btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1737 tspec = btrfs_inode_atime(inode_item);
1738 @@ -3431,11 +3439,18 @@ static void fill_inode_item(struct btrfs
1739 struct inode *inode)
1741 struct btrfs_map_token token;
1742 + uid_t uid = TAGINO_UID(DX_TAG(inode),
1743 + i_uid_read(inode), i_tag_read(inode));
1744 + gid_t gid = TAGINO_GID(DX_TAG(inode),
1745 + i_gid_read(inode), i_tag_read(inode));
1747 btrfs_init_map_token(&token);
1749 - btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1750 - btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1751 + btrfs_set_token_inode_uid(leaf, item, uid, &token);
1752 + btrfs_set_token_inode_gid(leaf, item, gid, &token);
1753 +#ifdef CONFIG_TAGGING_INTERN
1754 + btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1756 btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1758 btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1759 @@ -8683,11 +8698,13 @@ static const struct inode_operations btr
1760 .listxattr = btrfs_listxattr,
1761 .removexattr = btrfs_removexattr,
1762 .permission = btrfs_permission,
1763 + .sync_flags = btrfs_sync_flags,
1764 .get_acl = btrfs_get_acl,
1766 static const struct inode_operations btrfs_dir_ro_inode_operations = {
1767 .lookup = btrfs_lookup,
1768 .permission = btrfs_permission,
1769 + .sync_flags = btrfs_sync_flags,
1770 .get_acl = btrfs_get_acl,
1773 diff -NurpP --minimal linux-3.9.4/fs/btrfs/ioctl.c linux-3.9.4-vs2.3.6.2/fs/btrfs/ioctl.c
1774 --- linux-3.9.4/fs/btrfs/ioctl.c 2013-05-31 14:22:27.000000000 +0000
1775 +++ linux-3.9.4-vs2.3.6.2/fs/btrfs/ioctl.c 2013-05-31 14:47:11.000000000 +0000
1776 @@ -75,10 +75,13 @@ static unsigned int btrfs_flags_to_ioctl
1778 unsigned int iflags = 0;
1780 - if (flags & BTRFS_INODE_SYNC)
1781 - iflags |= FS_SYNC_FL;
1782 if (flags & BTRFS_INODE_IMMUTABLE)
1783 iflags |= FS_IMMUTABLE_FL;
1784 + if (flags & BTRFS_INODE_IXUNLINK)
1785 + iflags |= FS_IXUNLINK_FL;
1787 + if (flags & BTRFS_INODE_SYNC)
1788 + iflags |= FS_SYNC_FL;
1789 if (flags & BTRFS_INODE_APPEND)
1790 iflags |= FS_APPEND_FL;
1791 if (flags & BTRFS_INODE_NODUMP)
1792 @@ -95,28 +98,78 @@ static unsigned int btrfs_flags_to_ioctl
1793 else if (flags & BTRFS_INODE_NOCOMPRESS)
1794 iflags |= FS_NOCOMP_FL;
1796 + if (flags & BTRFS_INODE_BARRIER)
1797 + iflags |= FS_BARRIER_FL;
1798 + if (flags & BTRFS_INODE_COW)
1799 + iflags |= FS_COW_FL;
1804 - * Update inode->i_flags based on the btrfs internal flags.
1805 + * Update inode->i_(v)flags based on the btrfs internal flags.
1807 void btrfs_update_iflags(struct inode *inode)
1809 struct btrfs_inode *ip = BTRFS_I(inode);
1811 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1812 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1813 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1815 - if (ip->flags & BTRFS_INODE_SYNC)
1816 - inode->i_flags |= S_SYNC;
1817 if (ip->flags & BTRFS_INODE_IMMUTABLE)
1818 inode->i_flags |= S_IMMUTABLE;
1819 + if (ip->flags & BTRFS_INODE_IXUNLINK)
1820 + inode->i_flags |= S_IXUNLINK;
1822 + if (ip->flags & BTRFS_INODE_SYNC)
1823 + inode->i_flags |= S_SYNC;
1824 if (ip->flags & BTRFS_INODE_APPEND)
1825 inode->i_flags |= S_APPEND;
1826 if (ip->flags & BTRFS_INODE_NOATIME)
1827 inode->i_flags |= S_NOATIME;
1828 if (ip->flags & BTRFS_INODE_DIRSYNC)
1829 inode->i_flags |= S_DIRSYNC;
1831 + inode->i_vflags &= ~(V_BARRIER | V_COW);
1833 + if (ip->flags & BTRFS_INODE_BARRIER)
1834 + inode->i_vflags |= V_BARRIER;
1835 + if (ip->flags & BTRFS_INODE_COW)
1836 + inode->i_vflags |= V_COW;
1840 + * Update btrfs internal flags from inode->i_(v)flags.
1842 +void btrfs_update_flags(struct inode *inode)
1844 + struct btrfs_inode *ip = BTRFS_I(inode);
1846 + unsigned int flags = inode->i_flags;
1847 + unsigned int vflags = inode->i_vflags;
1849 + ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1850 + BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1851 + BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1852 + BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1854 + if (flags & S_IMMUTABLE)
1855 + ip->flags |= BTRFS_INODE_IMMUTABLE;
1856 + if (flags & S_IXUNLINK)
1857 + ip->flags |= BTRFS_INODE_IXUNLINK;
1859 + if (flags & S_SYNC)
1860 + ip->flags |= BTRFS_INODE_SYNC;
1861 + if (flags & S_APPEND)
1862 + ip->flags |= BTRFS_INODE_APPEND;
1863 + if (flags & S_NOATIME)
1864 + ip->flags |= BTRFS_INODE_NOATIME;
1865 + if (flags & S_DIRSYNC)
1866 + ip->flags |= BTRFS_INODE_DIRSYNC;
1868 + if (vflags & V_BARRIER)
1869 + ip->flags |= BTRFS_INODE_BARRIER;
1870 + if (vflags & V_COW)
1871 + ip->flags |= BTRFS_INODE_COW;
1875 @@ -132,6 +185,7 @@ void btrfs_inherit_iflags(struct inode *
1878 flags = BTRFS_I(dir)->flags;
1879 + flags &= ~BTRFS_INODE_BARRIER;
1881 if (flags & BTRFS_INODE_NOCOMPRESS) {
1882 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1883 @@ -150,6 +204,30 @@ void btrfs_inherit_iflags(struct inode *
1884 btrfs_update_iflags(inode);
1887 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1889 + struct btrfs_inode *ip = BTRFS_I(inode);
1890 + struct btrfs_root *root = ip->root;
1891 + struct btrfs_trans_handle *trans;
1894 + trans = btrfs_join_transaction(root);
1897 + inode->i_flags = flags;
1898 + inode->i_vflags = vflags;
1899 + btrfs_update_flags(inode);
1901 + ret = btrfs_update_inode(trans, root, inode);
1904 + btrfs_update_iflags(inode);
1905 + inode->i_ctime = CURRENT_TIME;
1906 + btrfs_end_transaction(trans, root);
1911 static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1913 struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1914 @@ -212,21 +290,27 @@ static int btrfs_ioctl_setflags(struct f
1916 flags = btrfs_mask_flags(inode->i_mode, flags);
1917 oldflags = btrfs_flags_to_ioctl(ip->flags);
1918 - if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1919 + if ((flags ^ oldflags) & (FS_APPEND_FL |
1920 + FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1921 if (!capable(CAP_LINUX_IMMUTABLE)) {
1927 - if (flags & FS_SYNC_FL)
1928 - ip->flags |= BTRFS_INODE_SYNC;
1930 - ip->flags &= ~BTRFS_INODE_SYNC;
1931 if (flags & FS_IMMUTABLE_FL)
1932 ip->flags |= BTRFS_INODE_IMMUTABLE;
1934 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1935 + if (flags & FS_IXUNLINK_FL)
1936 + ip->flags |= BTRFS_INODE_IXUNLINK;
1938 + ip->flags &= ~BTRFS_INODE_IXUNLINK;
1940 + if (flags & FS_SYNC_FL)
1941 + ip->flags |= BTRFS_INODE_SYNC;
1943 + ip->flags &= ~BTRFS_INODE_SYNC;
1944 if (flags & FS_APPEND_FL)
1945 ip->flags |= BTRFS_INODE_APPEND;
1947 diff -NurpP --minimal linux-3.9.4/fs/btrfs/super.c linux-3.9.4-vs2.3.6.2/fs/btrfs/super.c
1948 --- linux-3.9.4/fs/btrfs/super.c 2013-05-31 13:45:22.000000000 +0000
1949 +++ linux-3.9.4-vs2.3.6.2/fs/btrfs/super.c 2013-05-31 14:47:11.000000000 +0000
1950 @@ -321,7 +321,7 @@ enum {
1951 Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
1952 Opt_check_integrity, Opt_check_integrity_including_extent_data,
1953 Opt_check_integrity_print_mask, Opt_fatal_errors,
1955 + Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1958 static match_table_t tokens = {
1959 @@ -361,6 +361,9 @@ static match_table_t tokens = {
1960 {Opt_check_integrity_including_extent_data, "check_int_data"},
1961 {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
1962 {Opt_fatal_errors, "fatal_errors=%s"},
1964 + {Opt_notag, "notag"},
1965 + {Opt_tagid, "tagid=%u"},
1969 @@ -626,6 +629,22 @@ int btrfs_parse_options(struct btrfs_roo
1973 +#ifndef CONFIG_TAGGING_NONE
1975 + printk(KERN_INFO "btrfs: use tagging\n");
1976 + btrfs_set_opt(info->mount_opt, TAGGED);
1979 + printk(KERN_INFO "btrfs: disabled tagging\n");
1980 + btrfs_clear_opt(info->mount_opt, TAGGED);
1983 +#ifdef CONFIG_PROPAGATE
1986 + btrfs_set_opt(info->mount_opt, TAGGED);
1990 printk(KERN_INFO "btrfs: unrecognized mount option "
1992 @@ -1258,6 +1277,12 @@ static int btrfs_remount(struct super_bl
1993 btrfs_resize_thread_pool(fs_info,
1994 fs_info->thread_pool_size, old_thread_pool_size);
1996 + if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1997 + printk("btrfs: %s: tagging not permitted on remount.\n",
2002 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2005 diff -NurpP --minimal linux-3.9.4/fs/char_dev.c linux-3.9.4-vs2.3.6.2/fs/char_dev.c
2006 --- linux-3.9.4/fs/char_dev.c 2012-12-11 03:30:57.000000000 +0000
2007 +++ linux-3.9.4-vs2.3.6.2/fs/char_dev.c 2013-05-31 14:47:11.000000000 +0000
2009 #include <linux/mutex.h>
2010 #include <linux/backing-dev.h>
2011 #include <linux/tty.h>
2012 +#include <linux/vs_context.h>
2013 +#include <linux/vs_device.h>
2015 #include "internal.h"
2017 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2019 struct cdev *new = NULL;
2023 + if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2025 + inode->i_mdev = mdev;
2027 spin_lock(&cdev_lock);
2030 struct kobject *kobj;
2033 spin_unlock(&cdev_lock);
2034 - kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2036 + kobj = kobj_lookup(cdev_map, mdev, &idx);
2039 new = container_of(kobj, struct cdev, kobj);
2040 diff -NurpP --minimal linux-3.9.4/fs/dcache.c linux-3.9.4-vs2.3.6.2/fs/dcache.c
2041 --- linux-3.9.4/fs/dcache.c 2013-05-31 14:22:27.000000000 +0000
2042 +++ linux-3.9.4-vs2.3.6.2/fs/dcache.c 2013-05-31 14:47:11.000000000 +0000
2044 #include <linux/rculist_bl.h>
2045 #include <linux/prefetch.h>
2046 #include <linux/ratelimit.h>
2047 +#include <linux/vs_limit.h>
2048 #include "internal.h"
2051 @@ -593,6 +594,8 @@ int d_invalidate(struct dentry * dentry)
2052 spin_lock(&dentry->d_lock);
2055 + vx_dentry_dec(dentry);
2058 * Somebody else still using it?
2060 @@ -622,6 +625,7 @@ EXPORT_SYMBOL(d_invalidate);
2061 static inline void __dget_dlock(struct dentry *dentry)
2064 + vx_dentry_inc(dentry);
2067 static inline void __dget(struct dentry *dentry)
2068 @@ -1252,6 +1256,9 @@ struct dentry *__d_alloc(struct super_bl
2069 struct dentry *dentry;
2072 + if (!vx_dentry_avail(1))
2075 dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2078 @@ -1284,6 +1291,7 @@ struct dentry *__d_alloc(struct super_bl
2080 dentry->d_count = 1;
2081 dentry->d_flags = 0;
2082 + vx_dentry_inc(dentry);
2083 spin_lock_init(&dentry->d_lock);
2084 seqcount_init(&dentry->d_seq);
2085 dentry->d_inode = NULL;
2086 @@ -1984,6 +1992,7 @@ struct dentry *__d_lookup(const struct d
2090 + vx_dentry_inc(dentry);
2092 spin_unlock(&dentry->d_lock);
2094 diff -NurpP --minimal linux-3.9.4/fs/devpts/inode.c linux-3.9.4-vs2.3.6.2/fs/devpts/inode.c
2095 --- linux-3.9.4/fs/devpts/inode.c 2013-05-31 13:45:23.000000000 +0000
2096 +++ linux-3.9.4-vs2.3.6.2/fs/devpts/inode.c 2013-05-31 15:42:25.000000000 +0000
2098 #include <linux/parser.h>
2099 #include <linux/fsnotify.h>
2100 #include <linux/seq_file.h>
2101 +#include <linux/vs_base.h>
2103 #define DEVPTS_DEFAULT_MODE 0600
2106 #define DEVPTS_DEFAULT_PTMX_MODE 0000
2107 #define PTMX_MINOR 2
2109 +static int devpts_permission(struct inode *inode, int mask)
2111 + int ret = -EACCES;
2113 + /* devpts is xid tagged */
2114 + if (vx_check((xid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2115 + ret = generic_permission(inode, mask);
2119 +static struct inode_operations devpts_file_inode_operations = {
2120 + .permission = devpts_permission,
2125 * sysctl support for setting limits on the number of Unix98 ptys allocated.
2126 * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2127 @@ -345,6 +361,34 @@ static int devpts_show_options(struct se
2131 +static int devpts_filter(struct dentry *de)
2135 + /* devpts is xid tagged */
2136 + if (de && de->d_inode)
2137 + xid = (xid_t)i_tag_read(de->d_inode);
2138 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2140 + vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2141 + de->d_name.len, de->d_name.name);
2143 + return vx_check(xid, VS_WATCH_P | VS_IDENT);
2146 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2148 + return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2151 +static struct file_operations devpts_dir_operations = {
2152 + .open = dcache_dir_open,
2153 + .release = dcache_dir_close,
2154 + .llseek = dcache_dir_lseek,
2155 + .read = generic_read_dir,
2156 + .readdir = devpts_readdir,
2159 static const struct super_operations devpts_sops = {
2160 .statfs = simple_statfs,
2161 .remount_fs = devpts_remount,
2162 @@ -388,8 +432,10 @@ devpts_fill_super(struct super_block *s,
2163 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2164 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2165 inode->i_op = &simple_dir_inode_operations;
2166 - inode->i_fop = &simple_dir_operations;
2167 + inode->i_fop = &devpts_dir_operations;
2168 set_nlink(inode, 2);
2169 + /* devpts is xid tagged */
2170 + i_tag_write(inode, (tag_t)vx_current_xid());
2172 s->s_root = d_make_root(inode);
2174 @@ -592,6 +638,9 @@ struct inode *devpts_pty_new(struct inod
2175 inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2176 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2177 init_special_inode(inode, S_IFCHR|opts->mode, device);
2178 + /* devpts is xid tagged */
2179 + i_tag_write(inode, (tag_t)vx_current_xid());
2180 + inode->i_op = &devpts_file_inode_operations;
2181 inode->i_private = priv;
2183 sprintf(s, "%d", index);
2184 diff -NurpP --minimal linux-3.9.4/fs/ext2/balloc.c linux-3.9.4-vs2.3.6.2/fs/ext2/balloc.c
2185 --- linux-3.9.4/fs/ext2/balloc.c 2013-05-31 13:45:23.000000000 +0000
2186 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/balloc.c 2013-05-31 14:47:11.000000000 +0000
2187 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2189 end = EXT2_BLOCKS_PER_GROUP(sb);
2192 BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2195 diff -NurpP --minimal linux-3.9.4/fs/ext2/ext2.h linux-3.9.4-vs2.3.6.2/fs/ext2/ext2.h
2196 --- linux-3.9.4/fs/ext2/ext2.h 2012-12-11 03:30:57.000000000 +0000
2197 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/ext2.h 2013-05-31 14:47:11.000000000 +0000
2198 @@ -244,8 +244,12 @@ struct ext2_group_desc
2199 #define EXT2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
2200 #define EXT2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
2201 #define EXT2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
2202 +#define EXT2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
2203 #define EXT2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
2205 +#define EXT2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
2206 +#define EXT2_COW_FL FS_COW_FL /* Copy on Write marker */
2208 #define EXT2_FL_USER_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
2209 #define EXT2_FL_USER_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
2211 @@ -329,7 +333,8 @@ struct ext2_inode {
2213 __le16 l_i_uid_high; /* these 2 fields */
2214 __le16 l_i_gid_high; /* were reserved2[0] */
2215 - __u32 l_i_reserved2;
2216 + __le16 l_i_tag; /* Context Tag */
2217 + __u16 l_i_reserved2;
2220 __u8 h_i_frag; /* Fragment number */
2221 @@ -357,6 +362,7 @@ struct ext2_inode {
2222 #define i_gid_low i_gid
2223 #define i_uid_high osd2.linux2.l_i_uid_high
2224 #define i_gid_high osd2.linux2.l_i_gid_high
2225 +#define i_raw_tag osd2.linux2.l_i_tag
2226 #define i_reserved2 osd2.linux2.l_i_reserved2
2229 @@ -384,6 +390,7 @@ struct ext2_inode {
2230 #define EXT2_MOUNT_USRQUOTA 0x020000 /* user quota */
2231 #define EXT2_MOUNT_GRPQUOTA 0x040000 /* group quota */
2232 #define EXT2_MOUNT_RESERVATION 0x080000 /* Preallocation */
2233 +#define EXT2_MOUNT_TAGGED (1<<24) /* Enable Context Tags */
2236 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
2237 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2238 extern void ext2_get_inode_flags(struct ext2_inode_info *);
2239 extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2240 u64 start, u64 len);
2241 +extern int ext2_sync_flags(struct inode *, int, int);
2244 extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2245 diff -NurpP --minimal linux-3.9.4/fs/ext2/file.c linux-3.9.4-vs2.3.6.2/fs/ext2/file.c
2246 --- linux-3.9.4/fs/ext2/file.c 2012-12-11 03:30:57.000000000 +0000
2247 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/file.c 2013-05-31 14:47:11.000000000 +0000
2248 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2249 .setattr = ext2_setattr,
2250 .get_acl = ext2_get_acl,
2251 .fiemap = ext2_fiemap,
2252 + .sync_flags = ext2_sync_flags,
2254 diff -NurpP --minimal linux-3.9.4/fs/ext2/ialloc.c linux-3.9.4-vs2.3.6.2/fs/ext2/ialloc.c
2255 --- linux-3.9.4/fs/ext2/ialloc.c 2013-05-31 13:45:23.000000000 +0000
2256 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/ialloc.c 2013-06-01 09:31:28.000000000 +0000
2258 #include <linux/backing-dev.h>
2259 #include <linux/buffer_head.h>
2260 #include <linux/random.h>
2261 +#include <linux/vs_tag.h>
2265 @@ -546,6 +547,8 @@ got:
2266 inode->i_mode = mode;
2267 inode->i_uid = current_fsuid();
2268 inode->i_gid = dir->i_gid;
2269 + inode->i_tag = make_ktag(&init_user_ns,
2270 + dx_current_fstag(sb));
2272 inode_init_owner(inode, dir, mode);
2274 diff -NurpP --minimal linux-3.9.4/fs/ext2/inode.c linux-3.9.4-vs2.3.6.2/fs/ext2/inode.c
2275 --- linux-3.9.4/fs/ext2/inode.c 2013-05-31 13:45:23.000000000 +0000
2276 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/inode.c 2013-05-31 14:47:11.000000000 +0000
2278 #include <linux/mpage.h>
2279 #include <linux/fiemap.h>
2280 #include <linux/namei.h>
2281 +#include <linux/vs_tag.h>
2285 @@ -1179,7 +1180,7 @@ static void ext2_truncate_blocks(struct
2287 if (ext2_inode_is_fast_symlink(inode))
2289 - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2290 + if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2292 __ext2_truncate_blocks(inode, offset);
2294 @@ -1270,36 +1271,61 @@ void ext2_set_inode_flags(struct inode *
2296 unsigned int flags = EXT2_I(inode)->i_flags;
2298 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2299 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2300 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2303 + if (flags & EXT2_IMMUTABLE_FL)
2304 + inode->i_flags |= S_IMMUTABLE;
2305 + if (flags & EXT2_IXUNLINK_FL)
2306 + inode->i_flags |= S_IXUNLINK;
2308 if (flags & EXT2_SYNC_FL)
2309 inode->i_flags |= S_SYNC;
2310 if (flags & EXT2_APPEND_FL)
2311 inode->i_flags |= S_APPEND;
2312 - if (flags & EXT2_IMMUTABLE_FL)
2313 - inode->i_flags |= S_IMMUTABLE;
2314 if (flags & EXT2_NOATIME_FL)
2315 inode->i_flags |= S_NOATIME;
2316 if (flags & EXT2_DIRSYNC_FL)
2317 inode->i_flags |= S_DIRSYNC;
2319 + inode->i_vflags &= ~(V_BARRIER | V_COW);
2321 + if (flags & EXT2_BARRIER_FL)
2322 + inode->i_vflags |= V_BARRIER;
2323 + if (flags & EXT2_COW_FL)
2324 + inode->i_vflags |= V_COW;
2327 /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2328 void ext2_get_inode_flags(struct ext2_inode_info *ei)
2330 unsigned int flags = ei->vfs_inode.i_flags;
2331 + unsigned int vflags = ei->vfs_inode.i_vflags;
2333 + ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2334 + EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2335 + EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2336 + EXT2_BARRIER_FL | EXT2_COW_FL);
2338 + if (flags & S_IMMUTABLE)
2339 + ei->i_flags |= EXT2_IMMUTABLE_FL;
2340 + if (flags & S_IXUNLINK)
2341 + ei->i_flags |= EXT2_IXUNLINK_FL;
2343 - ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2344 - EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2346 ei->i_flags |= EXT2_SYNC_FL;
2347 if (flags & S_APPEND)
2348 ei->i_flags |= EXT2_APPEND_FL;
2349 - if (flags & S_IMMUTABLE)
2350 - ei->i_flags |= EXT2_IMMUTABLE_FL;
2351 if (flags & S_NOATIME)
2352 ei->i_flags |= EXT2_NOATIME_FL;
2353 if (flags & S_DIRSYNC)
2354 ei->i_flags |= EXT2_DIRSYNC_FL;
2356 + if (vflags & V_BARRIER)
2357 + ei->i_flags |= EXT2_BARRIER_FL;
2358 + if (vflags & V_COW)
2359 + ei->i_flags |= EXT2_COW_FL;
2362 struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2363 @@ -1335,8 +1361,10 @@ struct inode *ext2_iget (struct super_bl
2364 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2365 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2367 - i_uid_write(inode, i_uid);
2368 - i_gid_write(inode, i_gid);
2369 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2370 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2371 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2372 + le16_to_cpu(raw_inode->i_raw_tag)));
2373 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2374 inode->i_size = le32_to_cpu(raw_inode->i_size);
2375 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2376 @@ -1434,8 +1462,10 @@ static int __ext2_write_inode(struct ino
2377 struct ext2_inode_info *ei = EXT2_I(inode);
2378 struct super_block *sb = inode->i_sb;
2379 ino_t ino = inode->i_ino;
2380 - uid_t uid = i_uid_read(inode);
2381 - gid_t gid = i_gid_read(inode);
2382 + uid_t uid = TAGINO_UID(DX_TAG(inode),
2383 + i_uid_read(inode), i_tag_read(inode));
2384 + gid_t gid = TAGINO_GID(DX_TAG(inode),
2385 + i_gid_read(inode), i_tag_read(inode));
2386 struct buffer_head * bh;
2387 struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2389 @@ -1471,6 +1501,9 @@ static int __ext2_write_inode(struct ino
2390 raw_inode->i_uid_high = 0;
2391 raw_inode->i_gid_high = 0;
2393 +#ifdef CONFIG_TAGGING_INTERN
2394 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2396 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2397 raw_inode->i_size = cpu_to_le32(inode->i_size);
2398 raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2399 @@ -1551,7 +1584,8 @@ int ext2_setattr(struct dentry *dentry,
2400 if (is_quota_modification(inode, iattr))
2401 dquot_initialize(inode);
2402 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2403 - (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2404 + (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2405 + (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2406 error = dquot_transfer(inode, iattr);
2409 diff -NurpP --minimal linux-3.9.4/fs/ext2/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ext2/ioctl.c
2410 --- linux-3.9.4/fs/ext2/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2411 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/ioctl.c 2013-05-31 14:47:11.000000000 +0000
2413 #include <asm/uaccess.h>
2416 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2418 + inode->i_flags = flags;
2419 + inode->i_vflags = vflags;
2420 + ext2_get_inode_flags(EXT2_I(inode));
2421 + inode->i_ctime = CURRENT_TIME_SEC;
2422 + mark_inode_dirty(inode);
2426 long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2428 struct inode *inode = file_inode(filp);
2429 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2431 flags = ext2_mask_flags(inode->i_mode, flags);
2433 + if (IS_BARRIER(inode)) {
2434 + vxwprintk_task(1, "messing with the barrier.");
2438 mutex_lock(&inode->i_mutex);
2439 /* Is it quota file? Do not allow user to mess with it */
2440 if (IS_NOQUOTA(inode)) {
2441 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2443 * This test looks nicer. Thanks to Pauline Middelink
2445 - if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2446 + if ((oldflags & EXT2_IMMUTABLE_FL) ||
2447 + ((flags ^ oldflags) & (EXT2_APPEND_FL |
2448 + EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2449 if (!capable(CAP_LINUX_IMMUTABLE)) {
2450 mutex_unlock(&inode->i_mutex);
2452 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2456 - flags = flags & EXT2_FL_USER_MODIFIABLE;
2457 + flags &= EXT2_FL_USER_MODIFIABLE;
2458 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2459 ei->i_flags = flags;
2461 diff -NurpP --minimal linux-3.9.4/fs/ext2/namei.c linux-3.9.4-vs2.3.6.2/fs/ext2/namei.c
2462 --- linux-3.9.4/fs/ext2/namei.c 2012-12-11 03:30:57.000000000 +0000
2463 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/namei.c 2013-05-31 14:47:11.000000000 +0000
2466 #include <linux/pagemap.h>
2467 #include <linux/quotaops.h>
2468 +#include <linux/vs_tag.h>
2472 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2473 (unsigned long) ino);
2474 return ERR_PTR(-EIO);
2476 + dx_propagate_tag(nd, inode);
2478 return d_splice_alias(inode, dentry);
2480 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2481 .removexattr = generic_removexattr,
2483 .setattr = ext2_setattr,
2484 + .sync_flags = ext2_sync_flags,
2485 .get_acl = ext2_get_acl,
2488 diff -NurpP --minimal linux-3.9.4/fs/ext2/super.c linux-3.9.4-vs2.3.6.2/fs/ext2/super.c
2489 --- linux-3.9.4/fs/ext2/super.c 2013-05-31 13:45:23.000000000 +0000
2490 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/super.c 2013-05-31 14:47:11.000000000 +0000
2491 @@ -395,7 +395,8 @@ enum {
2492 Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2493 Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2494 Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2495 - Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2496 + Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2497 + Opt_tag, Opt_notag, Opt_tagid
2500 static const match_table_t tokens = {
2501 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2503 {Opt_noacl, "noacl"},
2506 + {Opt_notag, "notag"},
2507 + {Opt_tagid, "tagid=%u"},
2508 {Opt_grpquota, "grpquota"},
2509 {Opt_ignore, "noquota"},
2510 {Opt_quota, "quota"},
2511 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2513 set_opt (sbi->s_mount_opt, NO_UID32);
2515 +#ifndef CONFIG_TAGGING_NONE
2517 + set_opt (sbi->s_mount_opt, TAGGED);
2520 + clear_opt (sbi->s_mount_opt, TAGGED);
2523 +#ifdef CONFIG_PROPAGATE
2526 + set_opt (sbi->s_mount_opt, TAGGED);
2530 clear_opt (sbi->s_mount_opt, CHECK);
2532 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2533 if (!parse_options((char *) data, sb))
2536 + if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2537 + sb->s_flags |= MS_TAGGED;
2538 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2539 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2541 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2546 + if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2547 + !(sb->s_flags & MS_TAGGED)) {
2548 + printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2551 + goto restore_opts;
2554 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2555 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2556 diff -NurpP --minimal linux-3.9.4/fs/ext3/ext3.h linux-3.9.4-vs2.3.6.2/fs/ext3/ext3.h
2557 --- linux-3.9.4/fs/ext3/ext3.h 2012-12-11 03:30:57.000000000 +0000
2558 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/ext3.h 2013-05-31 14:47:11.000000000 +0000
2559 @@ -151,10 +151,14 @@ struct ext3_group_desc
2560 #define EXT3_NOTAIL_FL 0x00008000 /* file tail should not be merged */
2561 #define EXT3_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
2562 #define EXT3_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
2563 +#define EXT3_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
2564 #define EXT3_RESERVED_FL 0x80000000 /* reserved for ext3 lib */
2566 -#define EXT3_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
2567 -#define EXT3_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
2568 +#define EXT3_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2569 +#define EXT3_COW_FL 0x20000000 /* Copy on Write marker */
2571 +#define EXT3_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
2572 +#define EXT3_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
2574 /* Flags that should be inherited by new inodes from their parent. */
2575 #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2576 @@ -290,7 +294,8 @@ struct ext3_inode {
2578 __le16 l_i_uid_high; /* these 2 fields */
2579 __le16 l_i_gid_high; /* were reserved2[0] */
2580 - __u32 l_i_reserved2;
2581 + __le16 l_i_tag; /* Context Tag */
2582 + __u16 l_i_reserved2;
2585 __u8 h_i_frag; /* Fragment number */
2586 @@ -320,6 +325,7 @@ struct ext3_inode {
2587 #define i_gid_low i_gid
2588 #define i_uid_high osd2.linux2.l_i_uid_high
2589 #define i_gid_high osd2.linux2.l_i_gid_high
2590 +#define i_raw_tag osd2.linux2.l_i_tag
2591 #define i_reserved2 osd2.linux2.l_i_reserved2
2594 @@ -364,6 +370,7 @@ struct ext3_inode {
2595 #define EXT3_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
2596 #define EXT3_MOUNT_DATA_ERR_ABORT 0x400000 /* Abort on file data write
2597 * error in ordered mode */
2598 +#define EXT3_MOUNT_TAGGED (1<<24) /* Enable Context Tags */
2600 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2601 #ifndef _LINUX_EXT2_FS_H
2602 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2603 extern void ext3_set_aops(struct inode *inode);
2604 extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2605 u64 start, u64 len);
2606 +extern int ext3_sync_flags(struct inode *, int, int);
2609 extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2610 diff -NurpP --minimal linux-3.9.4/fs/ext3/file.c linux-3.9.4-vs2.3.6.2/fs/ext3/file.c
2611 --- linux-3.9.4/fs/ext3/file.c 2012-12-11 03:30:57.000000000 +0000
2612 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/file.c 2013-05-31 14:47:11.000000000 +0000
2613 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2615 .get_acl = ext3_get_acl,
2616 .fiemap = ext3_fiemap,
2617 + .sync_flags = ext3_sync_flags,
2620 diff -NurpP --minimal linux-3.9.4/fs/ext3/ialloc.c linux-3.9.4-vs2.3.6.2/fs/ext3/ialloc.c
2621 --- linux-3.9.4/fs/ext3/ialloc.c 2012-12-11 03:30:57.000000000 +0000
2622 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/ialloc.c 2013-06-01 09:40:15.000000000 +0000
2625 #include <linux/quotaops.h>
2626 #include <linux/random.h>
2627 +#include <linux/vs_tag.h>
2631 @@ -469,6 +470,8 @@ got:
2632 inode->i_mode = mode;
2633 inode->i_uid = current_fsuid();
2634 inode->i_gid = dir->i_gid;
2635 + inode->i_tag = make_ktag(&init_user_ns,
2636 + dx_current_fstag(sb));
2638 inode_init_owner(inode, dir, mode);
2640 diff -NurpP --minimal linux-3.9.4/fs/ext3/inode.c linux-3.9.4-vs2.3.6.2/fs/ext3/inode.c
2641 --- linux-3.9.4/fs/ext3/inode.c 2013-05-31 13:45:23.000000000 +0000
2642 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/inode.c 2013-05-31 14:47:11.000000000 +0000
2644 #include <linux/writeback.h>
2645 #include <linux/mpage.h>
2646 #include <linux/namei.h>
2647 +#include <linux/vs_tag.h>
2652 @@ -2851,36 +2853,60 @@ void ext3_set_inode_flags(struct inode *
2654 unsigned int flags = EXT3_I(inode)->i_flags;
2656 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2657 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2658 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2660 + if (flags & EXT3_IMMUTABLE_FL)
2661 + inode->i_flags |= S_IMMUTABLE;
2662 + if (flags & EXT3_IXUNLINK_FL)
2663 + inode->i_flags |= S_IXUNLINK;
2665 if (flags & EXT3_SYNC_FL)
2666 inode->i_flags |= S_SYNC;
2667 if (flags & EXT3_APPEND_FL)
2668 inode->i_flags |= S_APPEND;
2669 - if (flags & EXT3_IMMUTABLE_FL)
2670 - inode->i_flags |= S_IMMUTABLE;
2671 if (flags & EXT3_NOATIME_FL)
2672 inode->i_flags |= S_NOATIME;
2673 if (flags & EXT3_DIRSYNC_FL)
2674 inode->i_flags |= S_DIRSYNC;
2676 + inode->i_vflags &= ~(V_BARRIER | V_COW);
2678 + if (flags & EXT3_BARRIER_FL)
2679 + inode->i_vflags |= V_BARRIER;
2680 + if (flags & EXT3_COW_FL)
2681 + inode->i_vflags |= V_COW;
2684 /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2685 void ext3_get_inode_flags(struct ext3_inode_info *ei)
2687 unsigned int flags = ei->vfs_inode.i_flags;
2688 + unsigned int vflags = ei->vfs_inode.i_vflags;
2690 + ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2691 + EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2692 + EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2693 + EXT3_BARRIER_FL | EXT3_COW_FL);
2695 + if (flags & S_IMMUTABLE)
2696 + ei->i_flags |= EXT3_IMMUTABLE_FL;
2697 + if (flags & S_IXUNLINK)
2698 + ei->i_flags |= EXT3_IXUNLINK_FL;
2700 - ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2701 - EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2703 ei->i_flags |= EXT3_SYNC_FL;
2704 if (flags & S_APPEND)
2705 ei->i_flags |= EXT3_APPEND_FL;
2706 - if (flags & S_IMMUTABLE)
2707 - ei->i_flags |= EXT3_IMMUTABLE_FL;
2708 if (flags & S_NOATIME)
2709 ei->i_flags |= EXT3_NOATIME_FL;
2710 if (flags & S_DIRSYNC)
2711 ei->i_flags |= EXT3_DIRSYNC_FL;
2713 + if (vflags & V_BARRIER)
2714 + ei->i_flags |= EXT3_BARRIER_FL;
2715 + if (vflags & V_COW)
2716 + ei->i_flags |= EXT3_COW_FL;
2719 struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2720 @@ -2918,8 +2944,10 @@ struct inode *ext3_iget(struct super_blo
2721 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2722 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2724 - i_uid_write(inode, i_uid);
2725 - i_gid_write(inode, i_gid);
2726 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2727 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2728 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2729 + le16_to_cpu(raw_inode->i_raw_tag)));
2730 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2731 inode->i_size = le32_to_cpu(raw_inode->i_size);
2732 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2733 @@ -3091,8 +3119,10 @@ again:
2735 ext3_get_inode_flags(ei);
2736 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2737 - i_uid = i_uid_read(inode);
2738 - i_gid = i_gid_read(inode);
2739 + i_uid = TAGINO_UID(DX_TAG(inode),
2740 + i_uid_read(inode), i_tag_read(inode));
2741 + i_gid = TAGINO_GID(DX_TAG(inode),
2742 + i_gid_read(inode), i_tag_read(inode));
2743 if(!(test_opt(inode->i_sb, NO_UID32))) {
2744 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2745 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2746 @@ -3117,6 +3147,9 @@ again:
2747 raw_inode->i_uid_high = 0;
2748 raw_inode->i_gid_high = 0;
2750 +#ifdef CONFIG_TAGGING_INTERN
2751 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2753 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2754 disksize = cpu_to_le32(ei->i_disksize);
2755 if (disksize != raw_inode->i_size) {
2756 @@ -3285,7 +3318,8 @@ int ext3_setattr(struct dentry *dentry,
2757 if (is_quota_modification(inode, attr))
2758 dquot_initialize(inode);
2759 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2760 - (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2761 + (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2762 + (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2765 /* (user+group)*(old+new) structure, inode write (sb,
2766 @@ -3307,6 +3341,8 @@ int ext3_setattr(struct dentry *dentry,
2767 inode->i_uid = attr->ia_uid;
2768 if (attr->ia_valid & ATTR_GID)
2769 inode->i_gid = attr->ia_gid;
2770 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2771 + inode->i_tag = attr->ia_tag;
2772 error = ext3_mark_inode_dirty(handle, inode);
2773 ext3_journal_stop(handle);
2775 diff -NurpP --minimal linux-3.9.4/fs/ext3/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ext3/ioctl.c
2776 --- linux-3.9.4/fs/ext3/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2777 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/ioctl.c 2013-05-31 14:47:11.000000000 +0000
2779 #include <asm/uaccess.h>
2783 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2785 + handle_t *handle = NULL;
2786 + struct ext3_iloc iloc;
2789 + handle = ext3_journal_start(inode, 1);
2790 + if (IS_ERR(handle))
2791 + return PTR_ERR(handle);
2793 + if (IS_SYNC(inode))
2794 + handle->h_sync = 1;
2795 + err = ext3_reserve_inode_write(handle, inode, &iloc);
2799 + inode->i_flags = flags;
2800 + inode->i_vflags = vflags;
2801 + ext3_get_inode_flags(EXT3_I(inode));
2802 + inode->i_ctime = CURRENT_TIME_SEC;
2804 + err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2806 + ext3_journal_stop(handle);
2810 long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2812 struct inode *inode = file_inode(filp);
2813 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2815 flags = ext3_mask_flags(inode->i_mode, flags);
2817 + if (IS_BARRIER(inode)) {
2818 + vxwprintk_task(1, "messing with the barrier.");
2822 mutex_lock(&inode->i_mutex);
2824 /* Is it quota file? Do not allow user to mess with it */
2825 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2827 * This test looks nicer. Thanks to Pauline Middelink
2829 - if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2830 + if ((oldflags & EXT3_IMMUTABLE_FL) ||
2831 + ((flags ^ oldflags) & (EXT3_APPEND_FL |
2832 + EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2833 if (!capable(CAP_LINUX_IMMUTABLE))
2836 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2840 - flags = flags & EXT3_FL_USER_MODIFIABLE;
2841 + flags &= EXT3_FL_USER_MODIFIABLE;
2842 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2843 ei->i_flags = flags;
2845 diff -NurpP --minimal linux-3.9.4/fs/ext3/namei.c linux-3.9.4-vs2.3.6.2/fs/ext3/namei.c
2846 --- linux-3.9.4/fs/ext3/namei.c 2013-05-31 13:45:23.000000000 +0000
2847 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/namei.c 2013-05-31 14:47:11.000000000 +0000
2851 #include <linux/quotaops.h>
2852 +#include <linux/vs_tag.h>
2857 @@ -918,6 +920,7 @@ restart:
2858 submit_bh(READ | REQ_META | REQ_PRIO,
2861 + dx_propagate_tag(nd, inode);
2864 if ((bh = bh_use[ra_ptr++]) == NULL)
2865 @@ -2527,6 +2530,7 @@ const struct inode_operations ext3_dir_i
2866 .listxattr = ext3_listxattr,
2867 .removexattr = generic_removexattr,
2869 + .sync_flags = ext3_sync_flags,
2870 .get_acl = ext3_get_acl,
2873 diff -NurpP --minimal linux-3.9.4/fs/ext3/super.c linux-3.9.4-vs2.3.6.2/fs/ext3/super.c
2874 --- linux-3.9.4/fs/ext3/super.c 2013-05-31 13:45:23.000000000 +0000
2875 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/super.c 2013-05-31 14:47:11.000000000 +0000
2876 @@ -816,7 +816,8 @@ enum {
2877 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2878 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2879 Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2880 - Opt_resize, Opt_usrquota, Opt_grpquota
2881 + Opt_resize, Opt_usrquota, Opt_grpquota,
2882 + Opt_tag, Opt_notag, Opt_tagid
2885 static const match_table_t tokens = {
2886 @@ -873,6 +874,9 @@ static const match_table_t tokens = {
2887 {Opt_barrier, "barrier"},
2888 {Opt_nobarrier, "nobarrier"},
2889 {Opt_resize, "resize"},
2891 + {Opt_notag, "notag"},
2892 + {Opt_tagid, "tagid=%u"},
2896 @@ -1040,6 +1044,20 @@ static int parse_options (char *options,
2898 set_opt (sbi->s_mount_opt, NO_UID32);
2900 +#ifndef CONFIG_TAGGING_NONE
2902 + set_opt (sbi->s_mount_opt, TAGGED);
2905 + clear_opt (sbi->s_mount_opt, TAGGED);
2908 +#ifdef CONFIG_PROPAGATE
2911 + set_opt (sbi->s_mount_opt, TAGGED);
2915 clear_opt (sbi->s_mount_opt, CHECK);
2917 @@ -1737,6 +1755,9 @@ static int ext3_fill_super (struct super
2921 + if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2922 + sb->s_flags |= MS_TAGGED;
2924 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2925 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2927 @@ -2633,6 +2654,14 @@ static int ext3_remount (struct super_bl
2928 if (test_opt(sb, ABORT))
2929 ext3_abort(sb, __func__, "Abort forced by user");
2931 + if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2932 + !(sb->s_flags & MS_TAGGED)) {
2933 + printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2936 + goto restore_opts;
2939 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2940 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2942 diff -NurpP --minimal linux-3.9.4/fs/ext4/ext4.h linux-3.9.4-vs2.3.6.2/fs/ext4/ext4.h
2943 --- linux-3.9.4/fs/ext4/ext4.h 2013-05-31 13:45:23.000000000 +0000
2944 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/ext4.h 2013-05-31 16:22:49.000000000 +0000
2945 @@ -399,7 +399,10 @@ struct flex_groups {
2946 #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
2947 #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
2948 #define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
2949 +#define EXT4_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2950 +#define EXT4_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
2951 #define EXT4_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */
2952 +#define EXT4_COW_FL 0x20000000 /* Copy on Write marker */
2953 #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
2955 #define EXT4_FL_USER_VISIBLE 0x004BDFFF /* User visible flags */
2956 @@ -674,7 +677,7 @@ struct ext4_inode {
2957 __le16 l_i_uid_high; /* these 2 fields */
2958 __le16 l_i_gid_high; /* were reserved2[0] */
2959 __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2960 - __le16 l_i_reserved;
2961 + __le16 l_i_tag; /* Context Tag */
2964 __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
2965 @@ -792,6 +795,7 @@ do { \
2966 #define i_gid_low i_gid
2967 #define i_uid_high osd2.linux2.l_i_uid_high
2968 #define i_gid_high osd2.linux2.l_i_gid_high
2969 +#define i_raw_tag osd2.linux2.l_i_tag
2970 #define i_checksum_lo osd2.linux2.l_i_checksum_lo
2972 #elif defined(__GNU__)
2973 @@ -969,6 +973,7 @@ struct ext4_inode_info {
2974 #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
2975 #define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */
2976 #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */
2977 +#define EXT4_MOUNT_TAGGED 0x40000 /* Enable Context Tags */
2978 #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */
2979 #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
2980 #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
2981 @@ -2527,6 +2532,7 @@ extern struct buffer_head *ext4_get_firs
2982 extern int ext4_inline_data_fiemap(struct inode *inode,
2983 struct fiemap_extent_info *fieinfo,
2985 +extern int ext4_sync_flags(struct inode *, int, int);
2986 extern int ext4_try_to_evict_inline_data(handle_t *handle,
2987 struct inode *inode,
2989 diff -NurpP --minimal linux-3.9.4/fs/ext4/file.c linux-3.9.4-vs2.3.6.2/fs/ext4/file.c
2990 --- linux-3.9.4/fs/ext4/file.c 2013-05-31 13:45:23.000000000 +0000
2991 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/file.c 2013-05-31 14:47:11.000000000 +0000
2992 @@ -650,5 +650,6 @@ const struct inode_operations ext4_file_
2993 .removexattr = generic_removexattr,
2994 .get_acl = ext4_get_acl,
2995 .fiemap = ext4_fiemap,
2996 + .sync_flags = ext4_sync_flags,
2999 diff -NurpP --minimal linux-3.9.4/fs/ext4/ialloc.c linux-3.9.4-vs2.3.6.2/fs/ext4/ialloc.c
3000 --- linux-3.9.4/fs/ext4/ialloc.c 2013-05-31 13:45:23.000000000 +0000
3001 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/ialloc.c 2013-06-01 09:46:49.000000000 +0000
3003 #include <linux/random.h>
3004 #include <linux/bitops.h>
3005 #include <linux/blkdev.h>
3006 +#include <linux/vs_tag.h>
3007 #include <asm/byteorder.h>
3010 @@ -859,6 +860,8 @@ got:
3011 inode->i_mode = mode;
3012 inode->i_uid = current_fsuid();
3013 inode->i_gid = dir->i_gid;
3014 + inode->i_tag = make_ktag(&init_user_ns,
3015 + dx_current_fstag(sb));
3017 inode_init_owner(inode, dir, mode);
3019 diff -NurpP --minimal linux-3.9.4/fs/ext4/inode.c linux-3.9.4-vs2.3.6.2/fs/ext4/inode.c
3020 --- linux-3.9.4/fs/ext4/inode.c 2013-05-31 14:22:27.000000000 +0000
3021 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/inode.c 2013-05-31 14:47:11.000000000 +0000
3023 #include <linux/printk.h>
3024 #include <linux/slab.h>
3025 #include <linux/ratelimit.h>
3026 +#include <linux/vs_tag.h>
3028 #include "ext4_jbd2.h"
3030 @@ -3870,41 +3871,64 @@ void ext4_set_inode_flags(struct inode *
3032 unsigned int flags = EXT4_I(inode)->i_flags;
3034 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3035 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3036 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3038 + if (flags & EXT4_IMMUTABLE_FL)
3039 + inode->i_flags |= S_IMMUTABLE;
3040 + if (flags & EXT4_IXUNLINK_FL)
3041 + inode->i_flags |= S_IXUNLINK;
3043 if (flags & EXT4_SYNC_FL)
3044 inode->i_flags |= S_SYNC;
3045 if (flags & EXT4_APPEND_FL)
3046 inode->i_flags |= S_APPEND;
3047 - if (flags & EXT4_IMMUTABLE_FL)
3048 - inode->i_flags |= S_IMMUTABLE;
3049 if (flags & EXT4_NOATIME_FL)
3050 inode->i_flags |= S_NOATIME;
3051 if (flags & EXT4_DIRSYNC_FL)
3052 inode->i_flags |= S_DIRSYNC;
3054 + inode->i_vflags &= ~(V_BARRIER | V_COW);
3056 + if (flags & EXT4_BARRIER_FL)
3057 + inode->i_vflags |= V_BARRIER;
3058 + if (flags & EXT4_COW_FL)
3059 + inode->i_vflags |= V_COW;
3062 /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3063 void ext4_get_inode_flags(struct ext4_inode_info *ei)
3065 - unsigned int vfs_fl;
3066 + unsigned int vfs_fl, vfs_vf;
3067 unsigned long old_fl, new_fl;
3070 vfs_fl = ei->vfs_inode.i_flags;
3071 + vfs_vf = ei->vfs_inode.i_vflags;
3072 old_fl = ei->i_flags;
3073 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3074 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3076 + EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3079 + if (vfs_fl & S_IMMUTABLE)
3080 + new_fl |= EXT4_IMMUTABLE_FL;
3081 + if (vfs_fl & S_IXUNLINK)
3082 + new_fl |= EXT4_IXUNLINK_FL;
3084 if (vfs_fl & S_SYNC)
3085 new_fl |= EXT4_SYNC_FL;
3086 if (vfs_fl & S_APPEND)
3087 new_fl |= EXT4_APPEND_FL;
3088 - if (vfs_fl & S_IMMUTABLE)
3089 - new_fl |= EXT4_IMMUTABLE_FL;
3090 if (vfs_fl & S_NOATIME)
3091 new_fl |= EXT4_NOATIME_FL;
3092 if (vfs_fl & S_DIRSYNC)
3093 new_fl |= EXT4_DIRSYNC_FL;
3095 + if (vfs_vf & V_BARRIER)
3096 + new_fl |= EXT4_BARRIER_FL;
3097 + if (vfs_vf & V_COW)
3098 + new_fl |= EXT4_COW_FL;
3099 } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3102 @@ -4009,8 +4033,10 @@ struct inode *ext4_iget(struct super_blo
3103 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3104 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3106 - i_uid_write(inode, i_uid);
3107 - i_gid_write(inode, i_gid);
3108 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3109 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3110 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3111 + le16_to_cpu(raw_inode->i_raw_tag)));
3112 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3114 ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */
3115 @@ -4233,8 +4259,10 @@ static int ext4_do_update_inode(handle_t
3117 ext4_get_inode_flags(ei);
3118 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3119 - i_uid = i_uid_read(inode);
3120 - i_gid = i_gid_read(inode);
3121 + i_uid = TAGINO_UID(DX_TAG(inode),
3122 + i_uid_read(inode), i_tag_read(inode));
3123 + i_gid = TAGINO_GID(DX_TAG(inode),
3124 + i_gid_read(inode), i_tag_read(inode));
3125 if (!(test_opt(inode->i_sb, NO_UID32))) {
3126 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3127 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3128 @@ -4257,6 +4285,9 @@ static int ext4_do_update_inode(handle_t
3129 raw_inode->i_uid_high = 0;
3130 raw_inode->i_gid_high = 0;
3132 +#ifdef CONFIG_TAGGING_INTERN
3133 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3135 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3137 EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3138 @@ -4487,7 +4518,8 @@ int ext4_setattr(struct dentry *dentry,
3139 if (is_quota_modification(inode, attr))
3140 dquot_initialize(inode);
3141 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3142 - (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3143 + (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3144 + (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3147 /* (user+group)*(old+new) structure, inode write (sb,
3148 @@ -4510,6 +4542,8 @@ int ext4_setattr(struct dentry *dentry,
3149 inode->i_uid = attr->ia_uid;
3150 if (attr->ia_valid & ATTR_GID)
3151 inode->i_gid = attr->ia_gid;
3152 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3153 + inode->i_tag = attr->ia_tag;
3154 error = ext4_mark_inode_dirty(handle, inode);
3155 ext4_journal_stop(handle);
3157 diff -NurpP --minimal linux-3.9.4/fs/ext4/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ext4/ioctl.c
3158 --- linux-3.9.4/fs/ext4/ioctl.c 2013-05-31 13:45:23.000000000 +0000
3159 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/ioctl.c 2013-05-31 19:50:08.000000000 +0000
3161 #include <linux/compat.h>
3162 #include <linux/mount.h>
3163 #include <linux/file.h>
3164 +#include <linux/vs_tag.h>
3165 #include <asm/uaccess.h>
3166 #include "ext4_jbd2.h"
3169 #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3171 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3173 + handle_t *handle = NULL;
3174 + struct ext4_iloc iloc;
3177 + handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3178 + if (IS_ERR(handle))
3179 + return PTR_ERR(handle);
3181 + if (IS_SYNC(inode))
3182 + ext4_handle_sync(handle);
3183 + err = ext4_reserve_inode_write(handle, inode, &iloc);
3187 + inode->i_flags = flags;
3188 + inode->i_vflags = vflags;
3189 + ext4_get_inode_flags(EXT4_I(inode));
3190 + inode->i_ctime = ext4_current_time(inode);
3192 + err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3194 + ext4_journal_stop(handle);
3198 long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3200 struct inode *inode = file_inode(filp);
3201 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3203 flags = ext4_mask_flags(inode->i_mode, flags);
3205 + if (IS_BARRIER(inode)) {
3206 + vxwprintk_task(1, "messing with the barrier.");
3211 mutex_lock(&inode->i_mutex);
3212 /* Is it quota file? Do not allow user to mess with it */
3213 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3215 * This test looks nicer. Thanks to Pauline Middelink
3217 - if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3218 + if ((oldflags & EXT4_IMMUTABLE_FL) ||
3219 + ((flags ^ oldflags) & (EXT4_APPEND_FL |
3220 + EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3221 if (!capable(CAP_LINUX_IMMUTABLE))
3224 diff -NurpP --minimal linux-3.9.4/fs/ext4/namei.c linux-3.9.4-vs2.3.6.2/fs/ext4/namei.c
3225 --- linux-3.9.4/fs/ext4/namei.c 2013-05-31 13:45:23.000000000 +0000
3226 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/namei.c 2013-05-31 14:47:11.000000000 +0000
3228 #include <linux/quotaops.h>
3229 #include <linux/buffer_head.h>
3230 #include <linux/bio.h>
3231 +#include <linux/vs_tag.h>
3233 #include "ext4_jbd2.h"
3235 @@ -1290,6 +1291,7 @@ restart:
3236 ll_rw_block(READ | REQ_META | REQ_PRIO,
3239 + dx_propagate_tag(nd, inode);
3241 if ((bh = bh_use[ra_ptr++]) == NULL)
3243 @@ -3190,6 +3192,7 @@ const struct inode_operations ext4_dir_i
3244 .removexattr = generic_removexattr,
3245 .get_acl = ext4_get_acl,
3246 .fiemap = ext4_fiemap,
3247 + .sync_flags = ext4_sync_flags,
3250 const struct inode_operations ext4_special_inode_operations = {
3251 diff -NurpP --minimal linux-3.9.4/fs/ext4/super.c linux-3.9.4-vs2.3.6.2/fs/ext4/super.c
3252 --- linux-3.9.4/fs/ext4/super.c 2013-05-31 14:22:27.000000000 +0000
3253 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/super.c 2013-05-31 14:47:11.000000000 +0000
3254 @@ -1131,7 +1131,7 @@ enum {
3255 Opt_inode_readahead_blks, Opt_journal_ioprio,
3256 Opt_dioread_nolock, Opt_dioread_lock,
3257 Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3258 - Opt_max_dir_size_kb,
3259 + Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3262 static const match_table_t tokens = {
3263 @@ -1211,6 +1211,9 @@ static const match_table_t tokens = {
3264 {Opt_removed, "reservation"}, /* mount option from ext2/3 */
3265 {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3266 {Opt_removed, "journal=%u"}, /* mount option from ext2/3 */
3268 + {Opt_notag, "notag"},
3269 + {Opt_tagid, "tagid=%u"},
3273 @@ -1441,6 +1444,20 @@ static int handle_mount_opt(struct super
3275 sb->s_flags |= MS_I_VERSION;
3277 +#ifndef CONFIG_TAGGING_NONE
3279 + set_opt(sb, TAGGED);
3282 + clear_opt(sb, TAGGED);
3285 +#ifdef CONFIG_PROPAGATE
3288 + set_opt(sb, TAGGED);
3293 for (m = ext4_mount_opts; m->token != Opt_err; m++)
3294 @@ -3401,6 +3418,9 @@ static int ext4_fill_super(struct super_
3295 clear_opt(sb, DELALLOC);
3298 + if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3299 + sb->s_flags |= MS_TAGGED;
3301 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3302 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3304 @@ -4587,6 +4607,14 @@ static int ext4_remount(struct super_blo
3305 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3306 ext4_abort(sb, "Abort forced by user");
3308 + if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3309 + !(sb->s_flags & MS_TAGGED)) {
3310 + printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3313 + goto restore_opts;
3316 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3317 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3319 diff -NurpP --minimal linux-3.9.4/fs/fcntl.c linux-3.9.4-vs2.3.6.2/fs/fcntl.c
3320 --- linux-3.9.4/fs/fcntl.c 2013-05-31 13:45:23.000000000 +0000
3321 +++ linux-3.9.4-vs2.3.6.2/fs/fcntl.c 2013-05-31 14:47:11.000000000 +0000
3323 #include <linux/rcupdate.h>
3324 #include <linux/pid_namespace.h>
3325 #include <linux/user_namespace.h>
3326 +#include <linux/vs_limit.h>
3328 #include <asm/poll.h>
3329 #include <asm/siginfo.h>
3330 @@ -378,6 +379,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3334 + if (!vx_files_avail(1))
3337 if (unlikely(f.file->f_mode & FMODE_PATH)) {
3338 if (!check_fcntl_cmd(cmd))
3339 diff -NurpP --minimal linux-3.9.4/fs/file.c linux-3.9.4-vs2.3.6.2/fs/file.c
3340 --- linux-3.9.4/fs/file.c 2013-05-31 13:45:23.000000000 +0000
3341 +++ linux-3.9.4-vs2.3.6.2/fs/file.c 2013-05-31 14:47:11.000000000 +0000
3343 #include <linux/spinlock.h>
3344 #include <linux/rcupdate.h>
3345 #include <linux/workqueue.h>
3346 +#include <linux/vs_limit.h>
3348 struct fdtable_defer {
3350 @@ -364,6 +365,8 @@ struct files_struct *dup_fd(struct files
3351 struct file *f = *old_fds++;
3354 + /* TODO: sum it first for check and performance */
3355 + vx_openfd_inc(open_files - i);
3358 * The fd may be claimed in the fd bitmap but not yet
3359 @@ -429,9 +432,11 @@ static void close_files(struct files_str
3360 filp_close(file, files);
3371 @@ -567,6 +572,7 @@ repeat:
3373 __clear_close_on_exec(fd, fdt);
3375 + vx_openfd_inc(fd);
3378 if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3379 @@ -597,6 +603,7 @@ static void __put_unused_fd(struct files
3380 __clear_open_fd(fd, fdt);
3381 if (fd < files->next_fd)
3382 files->next_fd = fd;
3383 + vx_openfd_dec(fd);
3386 void put_unused_fd(unsigned int fd)
3387 @@ -876,6 +883,8 @@ static int do_dup2(struct files_struct *
3390 filp_close(tofree, files);
3392 + vx_openfd_inc(fd); /* fd was unused */
3396 diff -NurpP --minimal linux-3.9.4/fs/file_table.c linux-3.9.4-vs2.3.6.2/fs/file_table.c
3397 --- linux-3.9.4/fs/file_table.c 2013-05-31 13:45:23.000000000 +0000
3398 +++ linux-3.9.4-vs2.3.6.2/fs/file_table.c 2013-05-31 14:47:11.000000000 +0000
3400 #include <linux/hardirq.h>
3401 #include <linux/task_work.h>
3402 #include <linux/ima.h>
3403 +#include <linux/vs_limit.h>
3404 +#include <linux/vs_context.h>
3406 #include <linux/atomic.h>
3408 @@ -140,6 +142,8 @@ struct file *get_empty_filp(void)
3409 spin_lock_init(&f->f_lock);
3410 eventpoll_init_file(f);
3411 /* f->f_version: 0 */
3412 + f->f_xid = vx_current_xid();
3417 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3418 i_readcount_dec(inode);
3419 if (file->f_mode & FMODE_WRITE)
3420 drop_file_write_access(file);
3421 + vx_files_dec(file);
3423 file->f_path.dentry = NULL;
3424 file->f_path.mnt = NULL;
3425 file->f_inode = NULL;
3426 @@ -344,6 +350,8 @@ void put_filp(struct file *file)
3428 if (atomic_long_dec_and_test(&file->f_count)) {
3429 security_file_free(file);
3430 + vx_files_dec(file);
3432 file_sb_list_del(file);
3435 diff -NurpP --minimal linux-3.9.4/fs/fs_struct.c linux-3.9.4-vs2.3.6.2/fs/fs_struct.c
3436 --- linux-3.9.4/fs/fs_struct.c 2013-05-31 13:45:23.000000000 +0000
3437 +++ linux-3.9.4-vs2.3.6.2/fs/fs_struct.c 2013-05-31 14:47:11.000000000 +0000
3439 #include <linux/path.h>
3440 #include <linux/slab.h>
3441 #include <linux/fs_struct.h>
3442 +#include <linux/vserver/global.h>
3443 #include "internal.h"
3446 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3448 path_put(&fs->root);
3450 + atomic_dec(&vs_global_fs);
3451 kmem_cache_free(fs_cachep, fs);
3454 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3457 spin_unlock(&old->lock);
3458 + atomic_inc(&vs_global_fs);
3462 diff -NurpP --minimal linux-3.9.4/fs/gfs2/file.c linux-3.9.4-vs2.3.6.2/fs/gfs2/file.c
3463 --- linux-3.9.4/fs/gfs2/file.c 2013-05-31 13:45:23.000000000 +0000
3464 +++ linux-3.9.4-vs2.3.6.2/fs/gfs2/file.c 2013-05-31 19:54:27.000000000 +0000
3465 @@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3466 [12] = GFS2_DIF_EXHASH,
3467 [14] = GFS2_DIF_INHERIT_JDATA,
3468 [17] = GFS2_DIF_TOPDIR,
3469 + [27] = GFS2_DIF_IXUNLINK,
3470 + [26] = GFS2_DIF_BARRIER,
3471 + [29] = GFS2_DIF_COW,
3474 static const u32 gfs2_to_fsflags[32] = {
3475 @@ -153,6 +156,9 @@ static const u32 gfs2_to_fsflags[32] = {
3476 [gfs2fl_ExHash] = FS_INDEX_FL,
3477 [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3478 [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3479 + [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3480 + [gfs2fl_Barrier] = FS_BARRIER_FL,
3481 + [gfs2fl_Cow] = FS_COW_FL,
3484 static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3485 @@ -183,12 +189,18 @@ void gfs2_set_inode_flags(struct inode *
3487 struct gfs2_inode *ip = GFS2_I(inode);
3488 unsigned int flags = inode->i_flags;
3489 + unsigned int vflags = inode->i_vflags;
3491 + flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3492 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3494 - flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3495 if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3496 inode->i_flags |= S_NOSEC;
3497 if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3498 flags |= S_IMMUTABLE;
3499 + if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3500 + flags |= S_IXUNLINK;
3502 if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3504 if (ip->i_diskflags & GFS2_DIF_NOATIME)
3505 @@ -196,6 +208,43 @@ void gfs2_set_inode_flags(struct inode *
3506 if (ip->i_diskflags & GFS2_DIF_SYNC)
3508 inode->i_flags = flags;
3510 + vflags &= ~(V_BARRIER | V_COW);
3512 + if (ip->i_diskflags & GFS2_DIF_BARRIER)
3513 + vflags |= V_BARRIER;
3514 + if (ip->i_diskflags & GFS2_DIF_COW)
3516 + inode->i_vflags = vflags;
3519 +void gfs2_get_inode_flags(struct inode *inode)
3521 + struct gfs2_inode *ip = GFS2_I(inode);
3522 + unsigned int flags = inode->i_flags;
3523 + unsigned int vflags = inode->i_vflags;
3525 + ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3526 + GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3527 + GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3528 + GFS2_DIF_BARRIER | GFS2_DIF_COW);
3530 + if (flags & S_IMMUTABLE)
3531 + ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3532 + if (flags & S_IXUNLINK)
3533 + ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3535 + if (flags & S_APPEND)
3536 + ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3537 + if (flags & S_NOATIME)
3538 + ip->i_diskflags |= GFS2_DIF_NOATIME;
3539 + if (flags & S_SYNC)
3540 + ip->i_diskflags |= GFS2_DIF_SYNC;
3542 + if (vflags & V_BARRIER)
3543 + ip->i_diskflags |= GFS2_DIF_BARRIER;
3544 + if (vflags & V_COW)
3545 + ip->i_diskflags |= GFS2_DIF_COW;
3548 /* Flags that can be set by user space */
3549 @@ -309,6 +358,37 @@ static int gfs2_set_flags(struct file *f
3550 return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3553 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3555 + struct gfs2_inode *ip = GFS2_I(inode);
3556 + struct gfs2_sbd *sdp = GFS2_SB(inode);
3557 + struct buffer_head *bh;
3558 + struct gfs2_holder gh;
3561 + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3564 + error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3567 + error = gfs2_meta_inode_buffer(ip, &bh);
3569 + goto out_trans_end;
3570 + gfs2_trans_add_meta(ip->i_gl, bh);
3571 + inode->i_flags = flags;
3572 + inode->i_vflags = vflags;
3573 + gfs2_get_inode_flags(inode);
3574 + gfs2_dinode_out(ip, bh->b_data);
3576 + gfs2_set_aops(inode);
3578 + gfs2_trans_end(sdp);
3580 + gfs2_glock_dq_uninit(&gh);
3584 static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3587 diff -NurpP --minimal linux-3.9.4/fs/gfs2/inode.h linux-3.9.4-vs2.3.6.2/fs/gfs2/inode.h
3588 --- linux-3.9.4/fs/gfs2/inode.h 2012-12-11 03:30:57.000000000 +0000
3589 +++ linux-3.9.4-vs2.3.6.2/fs/gfs2/inode.h 2013-05-31 14:47:11.000000000 +0000
3590 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3591 extern const struct file_operations gfs2_dir_fops_nolock;
3593 extern void gfs2_set_inode_flags(struct inode *inode);
3594 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3596 #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3597 extern const struct file_operations gfs2_file_fops;
3598 diff -NurpP --minimal linux-3.9.4/fs/hostfs/hostfs.h linux-3.9.4-vs2.3.6.2/fs/hostfs/hostfs.h
3599 --- linux-3.9.4/fs/hostfs/hostfs.h 2012-12-11 03:30:57.000000000 +0000
3600 +++ linux-3.9.4-vs2.3.6.2/fs/hostfs/hostfs.h 2013-05-31 14:47:11.000000000 +0000
3601 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3602 unsigned short ia_mode;
3607 struct timespec ia_atime;
3608 struct timespec ia_mtime;
3609 diff -NurpP --minimal linux-3.9.4/fs/inode.c linux-3.9.4-vs2.3.6.2/fs/inode.c
3610 --- linux-3.9.4/fs/inode.c 2013-05-31 13:45:24.000000000 +0000
3611 +++ linux-3.9.4-vs2.3.6.2/fs/inode.c 2013-06-01 09:01:48.000000000 +0000
3613 #include <linux/prefetch.h>
3614 #include <linux/buffer_head.h> /* for inode_has_buffers */
3615 #include <linux/ratelimit.h>
3616 +#include <linux/vs_tag.h>
3617 #include "internal.h"
3620 @@ -128,6 +129,8 @@ int inode_init_always(struct super_block
3621 struct address_space *const mapping = &inode->i_data;
3625 + /* essential because of inode slab reuse */
3626 inode->i_blkbits = sb->s_blocksize_bits;
3628 atomic_set(&inode->i_count, 1);
3629 @@ -137,6 +140,7 @@ int inode_init_always(struct super_block
3630 inode->i_opflags = 0;
3631 i_uid_write(inode, 0);
3632 i_gid_write(inode, 0);
3633 + i_tag_write(inode, 0);
3634 atomic_set(&inode->i_writecount, 0);
3636 inode->i_blocks = 0;
3637 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3638 inode->i_bdev = NULL;
3639 inode->i_cdev = NULL;
3641 + inode->i_mdev = 0;
3642 inode->dirtied_when = 0;
3644 if (security_inode_alloc(inode))
3645 @@ -483,6 +488,8 @@ void __insert_inode_hash(struct inode *i
3647 EXPORT_SYMBOL(__insert_inode_hash);
3649 +EXPORT_SYMBOL_GPL(__iget);
3652 * __remove_inode_hash - remove an inode from the hash
3653 * @inode: inode to unhash
3654 @@ -1799,9 +1806,11 @@ void init_special_inode(struct inode *in
3655 if (S_ISCHR(mode)) {
3656 inode->i_fop = &def_chr_fops;
3657 inode->i_rdev = rdev;
3658 + inode->i_mdev = rdev;
3659 } else if (S_ISBLK(mode)) {
3660 inode->i_fop = &def_blk_fops;
3661 inode->i_rdev = rdev;
3662 + inode->i_mdev = rdev;
3663 } else if (S_ISFIFO(mode))
3664 inode->i_fop = &def_fifo_fops;
3665 else if (S_ISSOCK(mode))
3666 @@ -1830,6 +1839,7 @@ void inode_init_owner(struct inode *inod
3668 inode->i_gid = current_fsgid();
3669 inode->i_mode = mode;
3670 + i_tag_write(inode, dx_current_fstag(inode->i_sb));
3672 EXPORT_SYMBOL(inode_init_owner);
3674 diff -NurpP --minimal linux-3.9.4/fs/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ioctl.c
3675 --- linux-3.9.4/fs/ioctl.c 2013-05-31 13:45:24.000000000 +0000
3676 +++ linux-3.9.4-vs2.3.6.2/fs/ioctl.c 2013-05-31 14:47:11.000000000 +0000
3678 #include <linux/writeback.h>
3679 #include <linux/buffer_head.h>
3680 #include <linux/falloc.h>
3681 +#include <linux/proc_fs.h>
3682 +#include <linux/vserver/inode.h>
3683 +#include <linux/vs_tag.h>
3685 #include <asm/ioctls.h>
3687 diff -NurpP --minimal linux-3.9.4/fs/ioprio.c linux-3.9.4-vs2.3.6.2/fs/ioprio.c
3688 --- linux-3.9.4/fs/ioprio.c 2012-12-11 03:30:57.000000000 +0000
3689 +++ linux-3.9.4-vs2.3.6.2/fs/ioprio.c 2013-05-31 14:47:11.000000000 +0000
3691 #include <linux/syscalls.h>
3692 #include <linux/security.h>
3693 #include <linux/pid_namespace.h>
3694 +#include <linux/vs_base.h>
3696 int set_task_ioprio(struct task_struct *task, int ioprio)
3698 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3700 pgrp = find_vpid(who);
3701 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3702 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3704 ret = set_task_ioprio(p, ioprio);
3707 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3709 pgrp = find_vpid(who);
3710 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3711 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3713 tmpio = get_task_ioprio(p);
3716 diff -NurpP --minimal linux-3.9.4/fs/jfs/file.c linux-3.9.4-vs2.3.6.2/fs/jfs/file.c
3717 --- linux-3.9.4/fs/jfs/file.c 2013-02-19 13:58:48.000000000 +0000
3718 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/file.c 2013-05-31 14:47:11.000000000 +0000
3719 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3720 if (is_quota_modification(inode, iattr))
3721 dquot_initialize(inode);
3722 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3723 - (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3724 + (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3725 + (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3726 rc = dquot_transfer(inode, iattr);
3729 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3730 #ifdef CONFIG_JFS_POSIX_ACL
3731 .get_acl = jfs_get_acl,
3733 + .sync_flags = jfs_sync_flags,
3736 const struct file_operations jfs_file_operations = {
3737 diff -NurpP --minimal linux-3.9.4/fs/jfs/ioctl.c linux-3.9.4-vs2.3.6.2/fs/jfs/ioctl.c
3738 --- linux-3.9.4/fs/jfs/ioctl.c 2013-05-31 13:45:24.000000000 +0000
3739 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/ioctl.c 2013-05-31 14:47:11.000000000 +0000
3741 #include <linux/time.h>
3742 #include <linux/sched.h>
3743 #include <linux/blkdev.h>
3744 +#include <linux/mount.h>
3745 #include <asm/current.h>
3746 #include <asm/uaccess.h>
3748 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3752 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3754 + inode->i_flags = flags;
3755 + inode->i_vflags = vflags;
3756 + jfs_get_inode_flags(JFS_IP(inode));
3757 + inode->i_ctime = CURRENT_TIME_SEC;
3758 + mark_inode_dirty(inode);
3762 long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3764 struct inode *inode = file_inode(filp);
3765 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3766 if (!S_ISDIR(inode->i_mode))
3767 flags &= ~JFS_DIRSYNC_FL;
3769 + if (IS_BARRIER(inode)) {
3770 + vxwprintk_task(1, "messing with the barrier.");
3774 /* Is it quota file? Do not allow user to mess with it */
3775 if (IS_NOQUOTA(inode)) {
3777 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3778 * the relevant capability.
3780 if ((oldflags & JFS_IMMUTABLE_FL) ||
3781 - ((flags ^ oldflags) &
3782 - (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3783 + ((flags ^ oldflags) & (JFS_APPEND_FL |
3784 + JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3785 if (!capable(CAP_LINUX_IMMUTABLE)) {
3786 mutex_unlock(&inode->i_mutex);
3788 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3792 - flags = flags & JFS_FL_USER_MODIFIABLE;
3793 + flags &= JFS_FL_USER_MODIFIABLE;
3794 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3795 jfs_inode->mode2 = flags;
3797 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_dinode.h linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_dinode.h
3798 --- linux-3.9.4/fs/jfs/jfs_dinode.h 2012-12-11 03:30:57.000000000 +0000
3799 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_dinode.h 2013-05-31 14:47:11.000000000 +0000
3800 @@ -161,9 +161,13 @@ struct dinode {
3802 #define JFS_APPEND_FL 0x01000000 /* writes to file may only append */
3803 #define JFS_IMMUTABLE_FL 0x02000000 /* Immutable file */
3804 +#define JFS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
3806 -#define JFS_FL_USER_VISIBLE 0x03F80000
3807 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3808 +#define JFS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
3809 +#define JFS_COW_FL 0x20000000 /* Copy on Write marker */
3811 +#define JFS_FL_USER_VISIBLE 0x07F80000
3812 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3813 #define JFS_FL_INHERIT 0x03C80000
3815 /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3816 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_filsys.h linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_filsys.h
3817 --- linux-3.9.4/fs/jfs/jfs_filsys.h 2012-12-11 03:30:57.000000000 +0000
3818 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_filsys.h 2013-05-31 14:47:11.000000000 +0000
3820 #define JFS_NAME_MAX 255
3821 #define JFS_PATH_MAX BPSIZE
3823 +#define JFS_TAGGED 0x00800000 /* Context Tagging */
3826 * file system state (superblock state)
3827 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_imap.c linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_imap.c
3828 --- linux-3.9.4/fs/jfs/jfs_imap.c 2012-12-11 03:30:57.000000000 +0000
3829 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_imap.c 2013-05-31 14:47:11.000000000 +0000
3831 #include <linux/pagemap.h>
3832 #include <linux/quotaops.h>
3833 #include <linux/slab.h>
3834 +#include <linux/vs_tag.h>
3836 #include "jfs_incore.h"
3837 #include "jfs_inode.h"
3838 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3840 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3841 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3845 jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3846 jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3847 @@ -3078,14 +3081,19 @@ static int copy_from_dinode(struct dinod
3849 set_nlink(ip, le32_to_cpu(dip->di_nlink));
3851 - jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3852 + uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3853 + gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3854 + ip->i_tag = make_ktag(&init_user_ns,
3855 + INOTAG_TAG(DX_TAG(ip), uid, gid, 0));
3857 + jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3858 if (!uid_valid(sbi->uid))
3859 ip->i_uid = jfs_ip->saved_uid;
3861 ip->i_uid = sbi->uid;
3864 - jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3865 + jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3866 if (!gid_valid(sbi->gid))
3867 ip->i_gid = jfs_ip->saved_gid;
3869 @@ -3150,16 +3158,14 @@ static void copy_to_dinode(struct dinode
3870 dip->di_size = cpu_to_le64(ip->i_size);
3871 dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3872 dip->di_nlink = cpu_to_le32(ip->i_nlink);
3873 - if (!uid_valid(sbi->uid))
3874 - dip->di_uid = cpu_to_le32(i_uid_read(ip));
3876 - dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3877 - jfs_ip->saved_uid));
3878 - if (!gid_valid(sbi->gid))
3879 - dip->di_gid = cpu_to_le32(i_gid_read(ip));
3881 - dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3882 - jfs_ip->saved_gid));
3883 + dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3884 + TAGINO_UID(DX_TAG(ip),
3885 + !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3887 + dip->di_gid = cpu_to_le32(from_kuid(&init_user_ns,
3888 + TAGINO_GID(DX_TAG(ip),
3889 + !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3891 jfs_get_inode_flags(jfs_ip);
3893 * mode2 is only needed for storing the higher order bits.
3894 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_inode.c linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_inode.c
3895 --- linux-3.9.4/fs/jfs/jfs_inode.c 2012-12-11 03:30:57.000000000 +0000
3896 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_inode.c 2013-05-31 14:47:11.000000000 +0000
3899 #include <linux/fs.h>
3900 #include <linux/quotaops.h>
3901 +#include <linux/vs_tag.h>
3902 #include "jfs_incore.h"
3903 #include "jfs_inode.h"
3904 #include "jfs_filsys.h"
3905 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3907 unsigned int flags = JFS_IP(inode)->mode2;
3909 - inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3910 - S_NOATIME | S_DIRSYNC | S_SYNC);
3911 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3912 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3914 if (flags & JFS_IMMUTABLE_FL)
3915 inode->i_flags |= S_IMMUTABLE;
3916 + if (flags & JFS_IXUNLINK_FL)
3917 + inode->i_flags |= S_IXUNLINK;
3919 + if (flags & JFS_SYNC_FL)
3920 + inode->i_flags |= S_SYNC;
3921 if (flags & JFS_APPEND_FL)
3922 inode->i_flags |= S_APPEND;
3923 if (flags & JFS_NOATIME_FL)
3924 inode->i_flags |= S_NOATIME;
3925 if (flags & JFS_DIRSYNC_FL)
3926 inode->i_flags |= S_DIRSYNC;
3927 - if (flags & JFS_SYNC_FL)
3928 - inode->i_flags |= S_SYNC;
3930 + inode->i_vflags &= ~(V_BARRIER | V_COW);
3932 + if (flags & JFS_BARRIER_FL)
3933 + inode->i_vflags |= V_BARRIER;
3934 + if (flags & JFS_COW_FL)
3935 + inode->i_vflags |= V_COW;
3938 void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3940 unsigned int flags = jfs_ip->vfs_inode.i_flags;
3941 + unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3943 + jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3944 + JFS_APPEND_FL | JFS_NOATIME_FL |
3945 + JFS_DIRSYNC_FL | JFS_SYNC_FL |
3946 + JFS_BARRIER_FL | JFS_COW_FL);
3948 - jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3949 - JFS_DIRSYNC_FL | JFS_SYNC_FL);
3950 if (flags & S_IMMUTABLE)
3951 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3952 + if (flags & S_IXUNLINK)
3953 + jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3955 if (flags & S_APPEND)
3956 jfs_ip->mode2 |= JFS_APPEND_FL;
3957 if (flags & S_NOATIME)
3958 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3959 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3961 jfs_ip->mode2 |= JFS_SYNC_FL;
3963 + if (vflags & V_BARRIER)
3964 + jfs_ip->mode2 |= JFS_BARRIER_FL;
3965 + if (vflags & V_COW)
3966 + jfs_ip->mode2 |= JFS_COW_FL;
3970 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_inode.h linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_inode.h
3971 --- linux-3.9.4/fs/jfs/jfs_inode.h 2012-12-11 03:30:57.000000000 +0000
3972 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_inode.h 2013-05-31 14:47:11.000000000 +0000
3973 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3974 extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3975 int fh_len, int fh_type);
3976 extern void jfs_set_inode_flags(struct inode *);
3977 +extern int jfs_sync_flags(struct inode *, int, int);
3978 extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3979 extern int jfs_setattr(struct dentry *, struct iattr *);
3981 diff -NurpP --minimal linux-3.9.4/fs/jfs/namei.c linux-3.9.4-vs2.3.6.2/fs/jfs/namei.c
3982 --- linux-3.9.4/fs/jfs/namei.c 2012-12-11 03:30:57.000000000 +0000
3983 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/namei.c 2013-05-31 14:47:11.000000000 +0000
3985 #include <linux/ctype.h>
3986 #include <linux/quotaops.h>
3987 #include <linux/exportfs.h>
3988 +#include <linux/vs_tag.h>
3989 #include "jfs_incore.h"
3990 #include "jfs_superblock.h"
3991 #include "jfs_inode.h"
3992 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3993 jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3996 + dx_propagate_tag(nd, ip);
3997 return d_splice_alias(ip, dentry);
4000 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
4001 #ifdef CONFIG_JFS_POSIX_ACL
4002 .get_acl = jfs_get_acl,
4004 + .sync_flags = jfs_sync_flags,
4007 const struct file_operations jfs_dir_operations = {
4008 diff -NurpP --minimal linux-3.9.4/fs/jfs/super.c linux-3.9.4-vs2.3.6.2/fs/jfs/super.c
4009 --- linux-3.9.4/fs/jfs/super.c 2013-05-31 13:45:24.000000000 +0000
4010 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/super.c 2013-05-31 14:47:11.000000000 +0000
4011 @@ -199,7 +199,8 @@ enum {
4012 Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4013 Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4014 Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4015 - Opt_discard, Opt_nodiscard, Opt_discard_minblk
4016 + Opt_discard, Opt_nodiscard, Opt_discard_minblk,
4017 + Opt_tag, Opt_notag, Opt_tagid
4020 static const match_table_t tokens = {
4021 @@ -209,6 +210,10 @@ static const match_table_t tokens = {
4022 {Opt_resize, "resize=%u"},
4023 {Opt_resize_nosize, "resize"},
4024 {Opt_errors, "errors=%s"},
4026 + {Opt_notag, "notag"},
4027 + {Opt_tagid, "tagid=%u"},
4028 + {Opt_tag, "tagxid"},
4029 {Opt_ignore, "noquota"},
4030 {Opt_ignore, "quota"},
4031 {Opt_usrquota, "usrquota"},
4032 @@ -385,7 +390,20 @@ static int parse_options(char *options,
4037 +#ifndef CONFIG_TAGGING_NONE
4039 + *flag |= JFS_TAGGED;
4042 + *flag &= JFS_TAGGED;
4045 +#ifdef CONFIG_PROPAGATE
4048 + *flag |= JFS_TAGGED;
4052 printk("jfs: Unrecognized mount option \"%s\" "
4053 " or missing value\n", p);
4054 @@ -417,6 +435,12 @@ static int jfs_remount(struct super_bloc
4058 + if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4059 + printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4065 if (sb->s_flags & MS_RDONLY) {
4066 pr_err("JFS: resize requires volume" \
4067 @@ -502,6 +526,9 @@ static int jfs_fill_super(struct super_b
4068 #ifdef CONFIG_JFS_POSIX_ACL
4069 sb->s_flags |= MS_POSIXACL;
4071 + /* map mount option tagxid */
4072 + if (sbi->flag & JFS_TAGGED)
4073 + sb->s_flags |= MS_TAGGED;
4076 pr_err("resize option for remount only\n");
4077 diff -NurpP --minimal linux-3.9.4/fs/libfs.c linux-3.9.4-vs2.3.6.2/fs/libfs.c
4078 --- linux-3.9.4/fs/libfs.c 2013-02-19 13:58:48.000000000 +0000
4079 +++ linux-3.9.4-vs2.3.6.2/fs/libfs.c 2013-05-31 14:47:11.000000000 +0000
4080 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4081 * both impossible due to the lock on directory.
4084 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4085 +static inline int do_dcache_readdir_filter(struct file *filp,
4086 + void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4088 struct dentry *dentry = filp->f_path.dentry;
4089 struct dentry *cursor = filp->private_data;
4090 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4091 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4092 struct dentry *next;
4093 next = list_entry(p, struct dentry, d_u.d_child);
4094 + if (filter && !filter(next))
4096 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4097 if (!simple_positive(next)) {
4098 spin_unlock(&next->d_lock);
4099 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4103 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4105 + return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4108 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4109 + int (*filter)(struct dentry *))
4111 + return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4114 ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4117 @@ -981,6 +995,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4118 EXPORT_SYMBOL(dcache_dir_lseek);
4119 EXPORT_SYMBOL(dcache_dir_open);
4120 EXPORT_SYMBOL(dcache_readdir);
4121 +EXPORT_SYMBOL(dcache_readdir_filter);
4122 EXPORT_SYMBOL(generic_read_dir);
4123 EXPORT_SYMBOL(mount_pseudo);
4124 EXPORT_SYMBOL(simple_write_begin);
4125 diff -NurpP --minimal linux-3.9.4/fs/locks.c linux-3.9.4-vs2.3.6.2/fs/locks.c
4126 --- linux-3.9.4/fs/locks.c 2013-05-31 13:45:24.000000000 +0000
4127 +++ linux-3.9.4-vs2.3.6.2/fs/locks.c 2013-05-31 15:53:57.000000000 +0000
4129 #include <linux/time.h>
4130 #include <linux/rcupdate.h>
4131 #include <linux/pid_namespace.h>
4132 +#include <linux/vs_base.h>
4133 +#include <linux/vs_limit.h>
4135 #include <asm/uaccess.h>
4137 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4138 /* Allocate an empty lock structure. */
4139 struct file_lock *locks_alloc_lock(void)
4141 - struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4142 + struct file_lock *fl;
4145 - locks_init_lock_heads(fl);
4146 + if (!vx_locks_avail(1))
4149 + fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4152 + locks_init_lock_heads(fl);
4157 EXPORT_SYMBOL_GPL(locks_alloc_lock);
4158 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4159 BUG_ON(!list_empty(&fl->fl_block));
4160 BUG_ON(!list_empty(&fl->fl_link));
4163 locks_release_private(fl);
4164 kmem_cache_free(filelock_cache, fl);
4166 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4168 memset(fl, 0, sizeof(struct file_lock));
4169 locks_init_lock_heads(fl);
4173 EXPORT_SYMBOL(locks_init_lock);
4174 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4175 new->fl_file = fl->fl_file;
4176 new->fl_ops = fl->fl_ops;
4177 new->fl_lmops = fl->fl_lmops;
4178 + new->fl_xid = fl->fl_xid;
4180 locks_copy_private(new, fl);
4182 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4183 fl->fl_flags = FL_FLOCK;
4185 fl->fl_end = OFFSET_MAX;
4187 + vxd_assert(filp->f_xid == vx_current_xid(),
4188 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4189 + fl->fl_xid = filp->f_xid;
4194 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4196 fl->fl_owner = current->files;
4197 fl->fl_pid = current->tgid;
4198 + fl->fl_xid = vx_current_xid();
4201 fl->fl_flags = FL_LEASE;
4202 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4204 return ERR_PTR(error);
4206 + fl->fl_xid = vx_current_xid();
4208 + vxd_assert(filp->f_xid == fl->fl_xid,
4209 + "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4211 error = lease_init(filp, type, fl);
4213 locks_free_lock(fl);
4214 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4218 + new_fl->fl_xid = -1;
4220 for_each_lock(inode, before) {
4221 struct file_lock *fl = *before;
4222 @@ -773,6 +796,7 @@ find_conflict:
4224 locks_copy_lock(new_fl, request);
4225 locks_insert_lock(before, new_fl);
4226 + vx_locks_inc(new_fl);
4230 @@ -783,7 +807,8 @@ out:
4234 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4235 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4236 + struct file_lock *conflock, xid_t xid)
4238 struct file_lock *fl;
4239 struct file_lock *new_fl = NULL;
4240 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4241 struct file_lock **before;
4242 int error, added = 0;
4244 + vxd_assert(xid == vx_current_xid(),
4245 + "xid(%d) == current(%d)", xid, vx_current_xid());
4247 * We may need two file_lock structures for this operation,
4248 * so we get them in advance to avoid races.
4249 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4250 (request->fl_type != F_UNLCK ||
4251 request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4252 new_fl = locks_alloc_lock();
4253 + new_fl->fl_xid = xid;
4254 + vx_locks_inc(new_fl);
4255 new_fl2 = locks_alloc_lock();
4256 + new_fl2->fl_xid = xid;
4257 + vx_locks_inc(new_fl2);
4261 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4262 int posix_lock_file(struct file *filp, struct file_lock *fl,
4263 struct file_lock *conflock)
4265 - return __posix_lock_file(file_inode(filp), fl, conflock);
4266 + return __posix_lock_file(file_inode(filp),
4267 + fl, conflock, filp->f_xid);
4269 EXPORT_SYMBOL(posix_lock_file);
4271 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4272 fl.fl_end = offset + count - 1;
4275 - error = __posix_lock_file(inode, &fl, NULL);
4276 + error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4277 if (error != FILE_LOCK_DEFERRED)
4279 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4280 @@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4283 locks_insert_lock(before, lease);
4284 + vx_locks_inc(lease);
4288 @@ -1836,6 +1869,11 @@ int fcntl_setlk(unsigned int fd, struct
4289 if (file_lock == NULL)
4292 + vxd_assert(filp->f_xid == vx_current_xid(),
4293 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4294 + file_lock->fl_xid = filp->f_xid;
4295 + vx_locks_inc(file_lock);
4298 * This might block, so we do it before checking the inode.
4300 @@ -1954,6 +1992,11 @@ int fcntl_setlk64(unsigned int fd, struc
4301 if (file_lock == NULL)
4304 + vxd_assert(filp->f_xid == vx_current_xid(),
4305 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4306 + file_lock->fl_xid = filp->f_xid;
4307 + vx_locks_inc(file_lock);
4310 * This might block, so we do it before checking the inode.
4312 @@ -2219,8 +2262,11 @@ static int locks_show(struct seq_file *f
4314 lock_get_status(f, fl, *((loff_t *)f->private), "");
4316 - list_for_each_entry(bfl, &fl->fl_block, fl_block)
4317 + list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4318 + if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4320 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4325 diff -NurpP --minimal linux-3.9.4/fs/mount.h linux-3.9.4-vs2.3.6.2/fs/mount.h
4326 --- linux-3.9.4/fs/mount.h 2013-02-19 13:58:48.000000000 +0000
4327 +++ linux-3.9.4-vs2.3.6.2/fs/mount.h 2013-05-31 14:47:11.000000000 +0000
4328 @@ -49,6 +49,7 @@ struct mount {
4329 int mnt_expiry_mark; /* true if marked for expiry */
4332 + tag_t mnt_tag; /* tagging used for vfsmount */
4335 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4336 diff -NurpP --minimal linux-3.9.4/fs/namei.c linux-3.9.4-vs2.3.6.2/fs/namei.c
4337 --- linux-3.9.4/fs/namei.c 2013-05-31 14:22:27.000000000 +0000
4338 +++ linux-3.9.4-vs2.3.6.2/fs/namei.c 2013-06-01 09:00:16.000000000 +0000
4340 #include <linux/device_cgroup.h>
4341 #include <linux/fs_struct.h>
4342 #include <linux/posix_acl.h>
4343 +#include <linux/proc_fs.h>
4344 +#include <linux/vserver/inode.h>
4345 +#include <linux/vs_base.h>
4346 +#include <linux/vs_tag.h>
4347 +#include <linux/vs_cowbl.h>
4348 +#include <linux/vs_device.h>
4349 +#include <linux/vs_context.h>
4350 +#include <linux/pid_namespace.h>
4351 #include <asm/uaccess.h>
4353 #include "internal.h"
4354 @@ -266,6 +274,89 @@ static int check_acl(struct inode *inode
4358 +static inline int dx_barrier(const struct inode *inode)
4360 + if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4361 + vxwprintk_task(1, "did hit the barrier.");
4367 +static int __dx_permission(const struct inode *inode, int mask)
4369 + if (dx_barrier(inode))
4372 + if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4373 + /* devpts is xid tagged */
4374 + if (S_ISDIR(inode->i_mode) ||
4375 + vx_check((xid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4378 + /* just pretend we didn't find anything */
4381 + else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4382 + struct proc_dir_entry *de = PDE(inode);
4384 + if (de && !vx_hide_check(0, de->vx_flags))
4387 + if ((mask & (MAY_WRITE | MAY_APPEND))) {
4389 + struct task_struct *tsk;
4391 + if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4392 + vx_flags(VXF_STATE_SETUP, 0))
4395 + pid = PROC_I(inode)->pid;
4400 + tsk = pid_task(pid, PIDTYPE_PID);
4401 + vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4402 + tsk, (tsk ? vx_task_xid(tsk) : 0));
4404 + vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4405 + rcu_read_unlock();
4408 + rcu_read_unlock();
4411 + /* FIXME: Should we block some entries here? */
4416 + if (dx_notagcheck(inode->i_sb) ||
4417 + dx_check((xid_t)i_tag_read(inode),
4418 + DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4426 +int dx_permission(const struct inode *inode, int mask)
4428 + int ret = __dx_permission(inode, mask);
4429 + if (unlikely(ret)) {
4430 +#ifndef CONFIG_VSERVER_WARN_DEVPTS
4431 + if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4434 + "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4435 + mask, inode->i_sb->s_id, inode,
4436 + i_tag_read(inode), inode->i_ino);
4442 * This does the basic permission checking
4444 @@ -388,10 +479,14 @@ int __inode_permission(struct inode *ino
4446 * Nobody gets write access to an immutable file.
4448 - if (IS_IMMUTABLE(inode))
4449 + if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4453 + retval = dx_permission(inode, mask);
4457 retval = do_inode_permission(inode, mask);
4460 @@ -1238,7 +1333,8 @@ static void follow_dotdot(struct nameida
4462 if (nd->path.dentry == nd->root.dentry &&
4463 nd->path.mnt == nd->root.mnt) {
4465 + /* for sane '/' avoid follow_mount() */
4468 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4469 /* rare case of legitimate dget_parent()... */
4470 @@ -1383,6 +1479,9 @@ static int lookup_fast(struct nameidata
4475 + /* FIXME: check dx permission */
4478 path->dentry = dentry;
4479 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4480 @@ -1413,6 +1512,8 @@ unlazy:
4484 + /* FIXME: check dx permission */
4487 path->dentry = dentry;
4488 err = follow_managed(path, nd->flags);
4489 @@ -2237,7 +2338,7 @@ static int may_delete(struct inode *dir,
4492 if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4493 - IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4494 + IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4497 if (!S_ISDIR(victim->d_inode->i_mode))
4498 @@ -2316,19 +2417,25 @@ int vfs_create(struct inode *dir, struct
4501 int error = may_create(dir, dentry);
4504 + vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4508 if (!dir->i_op->create)
4509 return -EACCES; /* shouldn't it be ENOSYS? */
4512 error = security_inode_create(dir, dentry, mode);
4515 + vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4518 error = dir->i_op->create(dir, dentry, mode, want_excl);
4520 fsnotify_create(dir, dentry);
4522 + vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4526 @@ -2363,6 +2470,15 @@ static int may_open(struct path *path, i
4530 +#ifdef CONFIG_VSERVER_COWBL
4531 + if (IS_COW(inode) &&
4532 + ((flag & O_ACCMODE) != O_RDONLY)) {
4533 + if (IS_COW_LINK(inode))
4535 + inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4536 + mark_inode_dirty(inode);
4539 error = inode_permission(inode, acc_mode);
4542 @@ -2865,6 +2981,16 @@ finish_open:
4544 finish_open_created:
4545 error = may_open(&nd->path, acc_mode, open_flag);
4546 +#ifdef CONFIG_VSERVER_COWBL
4547 + if (error == -EMLINK) {
4548 + struct dentry *dentry;
4549 + dentry = cow_break_link(name->name);
4550 + if (IS_ERR(dentry))
4551 + error = PTR_ERR(dentry);
4558 file->f_path.mnt = nd->path.mnt;
4559 @@ -2929,6 +3055,7 @@ static struct file *path_openat(int dfd,
4564 file = get_empty_filp();
4567 @@ -2965,6 +3092,16 @@ static struct file *path_openat(int dfd,
4568 error = do_last(nd, &path, file, op, &opened, pathname);
4569 put_link(nd, &link, cookie);
4572 +#ifdef CONFIG_VSERVER_COWBL
4573 + if (error == -EMLINK) {
4574 + if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4575 + path_put(&nd->root);
4582 if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4583 path_put(&nd->root);
4584 @@ -3079,6 +3216,11 @@ struct dentry *kern_path_create(int dfd,
4588 + vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4589 + path->dentry, path->dentry->d_name.len,
4590 + path->dentry->d_name.name, dentry,
4591 + dentry->d_name.len, dentry->d_name.name,
4592 + path->dentry->d_inode);
4596 @@ -3573,7 +3715,7 @@ int vfs_link(struct dentry *old_dentry,
4598 * A link to an append-only or immutable file cannot be created.
4600 - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4601 + if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4603 if (!dir->i_op->link)
4605 @@ -3976,6 +4118,286 @@ int vfs_follow_link(struct nameidata *nd
4606 return __vfs_follow_link(nd, link);
4610 +#ifdef CONFIG_VSERVER_COWBL
4613 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4617 + return do_splice_direct(in, &ppos, out, len, 0);
4620 +struct dentry *cow_break_link(const char *pathname)
4622 + int ret, mode, pathlen, redo = 0, drop = 1;
4623 + struct nameidata old_nd, dir_nd;
4624 + struct path dir_path, *old_path, *new_path;
4625 + struct dentry *dir, *old_dentry, *new_dentry = NULL;
4626 + struct file *old_file;
4627 + struct file *new_file;
4628 + char *to, *path, pad='\251';
4631 + vxdprintk(VXD_CBIT(misc, 1),
4632 + "cow_break_link(" VS_Q("%s") ")", pathname);
4634 + path = kmalloc(PATH_MAX, GFP_KERNEL);
4639 + /* old_nd.path will have refs to dentry and mnt */
4640 + ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4641 + vxdprintk(VXD_CBIT(misc, 2),
4642 + "do_path_lookup(old): %d", ret);
4644 + goto out_free_path;
4646 + /* dentry/mnt refs handed over to old_path */
4647 + old_path = &old_nd.path;
4648 + /* no explicit reference for old_dentry here */
4649 + old_dentry = old_path->dentry;
4651 + mode = old_dentry->d_inode->i_mode;
4652 + to = d_path(old_path, path, PATH_MAX-2);
4653 + pathlen = strlen(to);
4654 + vxdprintk(VXD_CBIT(misc, 2),
4655 + "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4657 + old_dentry->d_name.len, old_dentry->d_name.name,
4658 + old_dentry->d_name.len);
4660 + to[pathlen + 1] = 0;
4662 + new_dentry = NULL;
4663 + to[pathlen] = pad--;
4665 + if (pad <= '\240')
4668 + vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4670 + /* dir_nd.path will have refs to dentry and mnt */
4671 + ret = do_path_lookup(AT_FDCWD, to,
4672 + LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4673 + vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4677 + /* this puppy downs the dir inode mutex if successful.
4678 + dir_path will hold refs to dentry and mnt and
4679 + we'll have write access to the mnt */
4680 + new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4681 + if (!new_dentry || IS_ERR(new_dentry)) {
4682 + path_put(&dir_nd.path);
4683 + vxdprintk(VXD_CBIT(misc, 2),
4684 + "kern_path_create(new) failed with %ld",
4685 + PTR_ERR(new_dentry));
4688 + vxdprintk(VXD_CBIT(misc, 2),
4689 + "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4691 + new_dentry->d_name.len, new_dentry->d_name.name,
4692 + new_dentry->d_name.len);
4694 + /* take a reference on new_dentry */
4697 + /* dentry/mnt refs handed over to new_path */
4698 + new_path = &dir_path;
4700 + /* dentry for old/new dir */
4701 + dir = dir_nd.path.dentry;
4703 + /* give up reference on dir */
4704 + dput(new_path->dentry);
4706 + /* new_dentry already has a reference */
4707 + new_path->dentry = new_dentry;
4709 + ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4710 + vxdprintk(VXD_CBIT(misc, 2),
4711 + "vfs_create(new): %d", ret);
4712 + if (ret == -EEXIST) {
4713 + path_put(&dir_nd.path);
4714 + mutex_unlock(&dir->d_inode->i_mutex);
4715 + mnt_drop_write(new_path->mnt);
4716 + path_put(new_path);
4717 + new_dentry = NULL;
4721 + goto out_unlock_new;
4723 + /* drop out early, ret passes ENOENT */
4725 + if ((redo = d_unhashed(old_dentry)))
4726 + goto out_unlock_new;
4728 + /* doesn't change refs for old_path */
4729 + old_file = dentry_open(old_path, O_RDONLY, current_cred());
4730 + vxdprintk(VXD_CBIT(misc, 2),
4731 + "dentry_open(old): %p", old_file);
4732 + if (IS_ERR(old_file)) {
4733 + ret = PTR_ERR(old_file);
4734 + goto out_unlock_new;
4737 + /* doesn't change refs for new_path */
4738 + new_file = dentry_open(new_path, O_WRONLY, current_cred());
4739 + vxdprintk(VXD_CBIT(misc, 2),
4740 + "dentry_open(new): %p", new_file);
4741 + if (IS_ERR(new_file)) {
4742 + ret = PTR_ERR(new_file);
4743 + goto out_fput_old;
4746 + /* unlock the inode mutex from kern_path_create() */
4747 + mutex_unlock(&dir->d_inode->i_mutex);
4749 + /* drop write access to mnt */
4750 + mnt_drop_write(new_path->mnt);
4754 + size = i_size_read(old_file->f_dentry->d_inode);
4755 + ret = do_cow_splice(old_file, new_file, size);
4756 + vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4758 + goto out_fput_both;
4759 + } else if (ret < size) {
4761 + goto out_fput_both;
4763 + struct inode *old_inode = old_dentry->d_inode;
4764 + struct inode *new_inode = new_dentry->d_inode;
4765 + struct iattr attr = {
4766 + .ia_uid = old_inode->i_uid,
4767 + .ia_gid = old_inode->i_gid,
4768 + .ia_valid = ATTR_UID | ATTR_GID
4771 + setattr_copy(new_inode, &attr);
4772 + mark_inode_dirty(new_inode);
4775 + /* lock rename mutex */
4776 + mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4778 + /* drop out late */
4780 + if ((redo = d_unhashed(old_dentry)))
4783 + vxdprintk(VXD_CBIT(misc, 2),
4784 + "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4785 + new_dentry->d_name.len, new_dentry->d_name.name,
4786 + new_dentry->d_name.len,
4787 + old_dentry->d_name.len, old_dentry->d_name.name,
4788 + old_dentry->d_name.len);
4789 + ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4790 + old_dentry->d_parent->d_inode, old_dentry);
4791 + vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4794 + mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4797 + vxdprintk(VXD_CBIT(misc, 3),
4798 + "fput(new_file=%p[#%ld])", new_file,
4799 + atomic_long_read(&new_file->f_count));
4803 + vxdprintk(VXD_CBIT(misc, 3),
4804 + "fput(old_file=%p[#%ld])", old_file,
4805 + atomic_long_read(&old_file->f_count));
4809 + /* drop references from dir_nd.path */
4810 + path_put(&dir_nd.path);
4813 + /* unlock the inode mutex from kern_path_create() */
4814 + mutex_unlock(&dir->d_inode->i_mutex);
4816 + /* drop write access to mnt */
4817 + mnt_drop_write(new_path->mnt);
4823 + /* error path cleanup */
4824 + vfs_unlink(dir->d_inode, new_dentry);
4828 + goto out_rel_both;
4830 + /* lookup dentry once again
4831 + old_nd.path will be freed as old_path in out_rel_old */
4832 + ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4834 + goto out_rel_both;
4836 + /* drop reference on new_dentry */
4838 + new_dentry = old_path->dentry;
4840 + vxdprintk(VXD_CBIT(misc, 2),
4841 + "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4843 + new_dentry->d_name.len, new_dentry->d_name.name,
4844 + new_dentry->d_name.len);
4848 + path_put(new_path);
4850 + path_put(old_path);
4856 + new_dentry = ERR_PTR(ret);
4858 + vxdprintk(VXD_CBIT(misc, 3),
4859 + "cow_break_link returning with %p", new_dentry);
4860 + return new_dentry;
4865 +int vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4868 + struct vfsmount *vmnt;
4869 + char *pstr, *root;
4872 + pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4876 + vmnt = &ns->root->mnt;
4878 + path.dentry = vmnt->mnt_root;
4879 + root = d_path(&path, pstr, PATH_MAX - 2);
4880 + length = sprintf(buffer + length,
4881 + "Namespace:\t%p [#%u]\n"
4882 + "RootPath:\t%s\n",
4883 + ns, atomic_read(&ns->count),
4889 /* get the link contents into pagecache */
4890 static char *page_getlink(struct dentry * dentry, struct page **ppage)
4892 @@ -4099,3 +4521,4 @@ EXPORT_SYMBOL(vfs_symlink);
4893 EXPORT_SYMBOL(vfs_unlink);
4894 EXPORT_SYMBOL(dentry_unhash);
4895 EXPORT_SYMBOL(generic_readlink);
4896 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4897 diff -NurpP --minimal linux-3.9.4/fs/namespace.c linux-3.9.4-vs2.3.6.2/fs/namespace.c
4898 --- linux-3.9.4/fs/namespace.c 2013-05-31 14:22:27.000000000 +0000
4899 +++ linux-3.9.4-vs2.3.6.2/fs/namespace.c 2013-05-31 18:47:18.000000000 +0000
4901 #include <linux/fsnotify.h> /* fsnotify_vfsmount_delete */
4902 #include <linux/uaccess.h>
4903 #include <linux/proc_fs.h>
4904 +#include <linux/vs_base.h>
4905 +#include <linux/vs_context.h>
4906 +#include <linux/vs_tag.h>
4907 +#include <linux/vserver/space.h>
4908 +#include <linux/vserver/global.h>
4910 #include "internal.h"
4912 @@ -751,6 +756,10 @@ vfs_kern_mount(struct file_system_type *
4914 return ERR_PTR(-ENODEV);
4916 + if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4917 + !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4918 + return ERR_PTR(-EPERM);
4920 mnt = alloc_vfsmnt(name);
4922 return ERR_PTR(-ENOMEM);
4923 @@ -807,6 +816,7 @@ static struct mount *clone_mnt(struct mo
4924 mnt->mnt.mnt_root = dget(root);
4925 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4926 mnt->mnt_parent = mnt;
4927 + mnt->mnt_tag = old->mnt_tag;
4928 br_write_lock(&vfsmount_lock);
4929 list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4930 br_write_unlock(&vfsmount_lock);
4931 @@ -1639,6 +1649,7 @@ static int do_change_type(struct path *p
4935 + // mnt->mnt_flags = mnt_flags;
4937 br_write_lock(&vfsmount_lock);
4938 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4939 @@ -1654,12 +1665,14 @@ static int do_change_type(struct path *p
4940 * do loopback mount.
4942 static int do_loopback(struct path *path, const char *old_name,
4944 + tag_t tag, unsigned long flags, int mnt_flags)
4946 LIST_HEAD(umount_list);
4947 struct path old_path;
4948 struct mount *mnt = NULL, *old;
4949 + int recurse = flags & MS_REC;
4952 if (!old_name || !*old_name)
4954 err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4955 @@ -1733,7 +1746,7 @@ static int change_mount_flags(struct vfs
4956 * on it - tough luck.
4958 static int do_remount(struct path *path, int flags, int mnt_flags,
4960 + void *data, xid_t xid)
4963 struct super_block *sb = path->mnt->mnt_sb;
4964 @@ -2046,7 +2059,6 @@ void mark_mounts_for_expiry(struct list_
4966 br_write_unlock(&vfsmount_lock);
4967 up_write(&namespace_sem);
4969 release_mounts(&umounts);
4972 @@ -2218,6 +2230,7 @@ long do_mount(const char *dev_name, cons
4979 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4980 @@ -2247,6 +2260,12 @@ long do_mount(const char *dev_name, cons
4981 if (!(flags & MS_NOATIME))
4982 mnt_flags |= MNT_RELATIME;
4984 + if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4985 + /* FIXME: bind and re-mounts get the tag flag? */
4986 + if (flags & (MS_BIND|MS_REMOUNT))
4987 + flags |= MS_TAGID;
4990 /* Separate the per-mountpoint flags */
4991 if (flags & MS_NOSUID)
4992 mnt_flags |= MNT_NOSUID;
4993 @@ -2263,15 +2282,17 @@ long do_mount(const char *dev_name, cons
4994 if (flags & MS_RDONLY)
4995 mnt_flags |= MNT_READONLY;
4997 + if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4998 + mnt_flags |= MNT_NODEV;
4999 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5000 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5003 if (flags & MS_REMOUNT)
5004 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5007 else if (flags & MS_BIND)
5008 - retval = do_loopback(&path, dev_name, flags & MS_REC);
5009 + retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5010 else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5011 retval = do_change_type(&path, flags);
5012 else if (flags & MS_MOVE)
5013 @@ -2380,6 +2401,7 @@ static struct mnt_namespace *dup_mnt_ns(
5014 q = next_mnt(q, new);
5016 up_write(&namespace_sem);
5017 + atomic_inc(&vs_global_mnt_ns);
5021 @@ -2575,9 +2597,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5023 new_mnt = real_mount(new.mnt);
5024 root_mnt = real_mount(root.mnt);
5025 - if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5026 + if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5027 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5028 - IS_MNT_SHARED(root_mnt->mnt_parent))
5029 + IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5030 + !vx_flags(VXF_STATE_SETUP, 0))
5032 if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5034 @@ -2703,6 +2726,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5035 br_write_unlock(&vfsmount_lock);
5036 up_write(&namespace_sem);
5037 release_mounts(&umount_list);
5038 + atomic_dec(&vs_global_mnt_ns);
5042 diff -NurpP --minimal linux-3.9.4/fs/nfs/client.c linux-3.9.4-vs2.3.6.2/fs/nfs/client.c
5043 --- linux-3.9.4/fs/nfs/client.c 2013-05-31 13:45:24.000000000 +0000
5044 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/client.c 2013-05-31 14:47:11.000000000 +0000
5045 @@ -682,6 +682,9 @@ int nfs_init_server_rpcclient(struct nfs
5046 if (server->flags & NFS_MOUNT_SOFT)
5047 server->client->cl_softrtry = 1;
5049 + server->client->cl_tag = 0;
5050 + if (server->flags & NFS_MOUNT_TAGGED)
5051 + server->client->cl_tag = 1;
5054 EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
5055 @@ -861,6 +864,10 @@ static void nfs_server_set_fsinfo(struct
5056 server->acdirmin = server->acdirmax = 0;
5059 + /* FIXME: needs fsinfo
5060 + if (server->flags & NFS_MOUNT_TAGGED)
5061 + sb->s_flags |= MS_TAGGED; */
5063 server->maxfilesize = fsinfo->maxfilesize;
5065 server->time_delta = fsinfo->time_delta;
5066 diff -NurpP --minimal linux-3.9.4/fs/nfs/dir.c linux-3.9.4-vs2.3.6.2/fs/nfs/dir.c
5067 --- linux-3.9.4/fs/nfs/dir.c 2013-05-31 13:45:24.000000000 +0000
5068 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/dir.c 2013-05-31 14:47:11.000000000 +0000
5070 #include <linux/sched.h>
5071 #include <linux/kmemleak.h>
5072 #include <linux/xattr.h>
5073 +#include <linux/vs_tag.h>
5075 #include "delegation.h"
5077 @@ -1300,6 +1301,7 @@ struct dentry *nfs_lookup(struct inode *
5078 /* Success: notify readdir to use READDIRPLUS */
5079 nfs_advise_use_readdirplus(dir);
5081 + dx_propagate_tag(nd, inode);
5083 res = d_materialise_unique(dentry, inode);
5085 diff -NurpP --minimal linux-3.9.4/fs/nfs/inode.c linux-3.9.4-vs2.3.6.2/fs/nfs/inode.c
5086 --- linux-3.9.4/fs/nfs/inode.c 2013-05-31 13:45:24.000000000 +0000
5087 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/inode.c 2013-05-31 20:37:45.000000000 +0000
5089 #include <linux/compat.h>
5090 #include <linux/freezer.h>
5091 #include <linux/crc32.h>
5092 +#include <linux/vs_tag.h>
5094 #include <asm/uaccess.h>
5096 @@ -290,6 +291,8 @@ nfs_fhget(struct super_block *sb, struct
5097 if (inode->i_state & I_NEW) {
5098 struct nfs_inode *nfsi = NFS_I(inode);
5099 unsigned long now = jiffies;
5103 /* We set i_ino for the few things that still rely on it,
5104 * such as stat(2) */
5105 @@ -334,8 +337,8 @@ nfs_fhget(struct super_block *sb, struct
5106 inode->i_version = 0;
5109 - inode->i_uid = make_kuid(&init_user_ns, -2);
5110 - inode->i_gid = make_kgid(&init_user_ns, -2);
5111 + uid = make_kuid(&init_user_ns, -2);
5112 + gid = make_kgid(&init_user_ns, -2);
5113 inode->i_blocks = 0;
5114 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5116 @@ -369,11 +372,11 @@ nfs_fhget(struct super_block *sb, struct
5117 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5118 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5119 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5120 - inode->i_uid = fattr->uid;
5122 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5123 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5124 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5125 - inode->i_gid = fattr->gid;
5127 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5128 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5129 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5130 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5132 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5134 + inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5135 + inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5136 + inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5137 + /* maybe fattr->xid someday */
5139 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5140 nfsi->attrtimeo_timestamp = now;
5141 nfsi->access_cache = RB_ROOT;
5142 @@ -505,6 +513,8 @@ void nfs_setattr_update_inode(struct ino
5143 inode->i_uid = attr->ia_uid;
5144 if ((attr->ia_valid & ATTR_GID) != 0)
5145 inode->i_gid = attr->ia_gid;
5146 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5147 + inode->i_tag = attr->ia_tag;
5148 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5149 spin_unlock(&inode->i_lock);
5151 @@ -980,6 +990,11 @@ static int nfs_check_inode_attributes(st
5152 struct nfs_inode *nfsi = NFS_I(inode);
5153 loff_t cur_size, new_isize;
5154 unsigned long invalid = 0;
5162 if (nfs_have_delegated_attributes(inode))
5163 @@ -1005,13 +1020,21 @@ static int nfs_check_inode_attributes(st
5164 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5167 + uid = from_kuid(&init_user_ns, fattr->uid);
5168 + gid = from_kgid(&init_user_ns, fattr->gid);
5170 + kuid = make_kuid(&init_user_ns, INOTAG_UID(DX_TAG(inode), uid, gid));
5171 + kgid = make_kgid(&init_user_ns, INOTAG_GID(DX_TAG(inode), uid, gid));
5172 + ktag = make_ktag(&init_user_ns, INOTAG_TAG(DX_TAG(inode), uid, gid, 0));
5174 /* Have any file permissions changed? */
5175 if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5176 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5177 - if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5178 + if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5179 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5180 - if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5181 + if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5182 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5183 + /* maybe check for tag too? */
5185 /* Has the link count changed? */
5186 if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5187 @@ -1317,6 +1340,9 @@ static int nfs_update_inode(struct inode
5188 unsigned long invalid = 0;
5189 unsigned long now = jiffies;
5190 unsigned long save_cache_validity;
5195 dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5196 __func__, inode->i_sb->s_id, inode->i_ino,
5197 @@ -1418,6 +1444,9 @@ static int nfs_update_inode(struct inode
5198 | NFS_INO_REVAL_PAGECACHE
5199 | NFS_INO_REVAL_FORCED);
5201 + uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5202 + gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5203 + tag = inode->i_tag;
5205 if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5206 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5207 @@ -1460,6 +1489,10 @@ static int nfs_update_inode(struct inode
5208 | NFS_INO_INVALID_ACL
5209 | NFS_INO_REVAL_FORCED);
5211 + inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5212 + inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5213 + inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5215 if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5216 if (inode->i_nlink != fattr->nlink) {
5217 invalid |= NFS_INO_INVALID_ATTR;
5218 diff -NurpP --minimal linux-3.9.4/fs/nfs/nfs3xdr.c linux-3.9.4-vs2.3.6.2/fs/nfs/nfs3xdr.c
5219 --- linux-3.9.4/fs/nfs/nfs3xdr.c 2013-05-31 13:45:24.000000000 +0000
5220 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/nfs3xdr.c 2013-05-31 15:33:48.000000000 +0000
5222 #include <linux/nfs3.h>
5223 #include <linux/nfs_fs.h>
5224 #include <linux/nfsacl.h>
5225 +#include <linux/vs_tag.h>
5226 #include "internal.h"
5228 #define NFSDBG_FACILITY NFSDBG_XDR
5229 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5233 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5234 +static void encode_sattr3(struct xdr_stream *xdr,
5235 + const struct iattr *attr, int tag)
5239 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5243 - if (attr->ia_valid & ATTR_UID) {
5244 + if (attr->ia_valid & ATTR_UID ||
5245 + (tag && (attr->ia_valid & ATTR_TAG))) {
5247 - *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5248 + *p++ = cpu_to_be32(TAGINO_UID(tag,
5249 + from_kuid(&init_user_ns, attr->ia_uid), attr->ia_tag));
5253 - if (attr->ia_valid & ATTR_GID) {
5254 + if (attr->ia_valid & ATTR_GID ||
5255 + (tag && (attr->ia_valid & ATTR_TAG))) {
5257 - *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5258 + *p++ = cpu_to_be32(TAGINO_GID(tag,
5259 + from_kgid(&init_user_ns, attr->ia_gid), attr->ia_tag));
5263 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5264 const struct nfs3_sattrargs *args)
5266 encode_nfs_fh3(xdr, args->fh);
5267 - encode_sattr3(xdr, args->sattr);
5268 + encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5269 encode_sattrguard3(xdr, args);
5272 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5275 static void encode_createhow3(struct xdr_stream *xdr,
5276 - const struct nfs3_createargs *args)
5277 + const struct nfs3_createargs *args, int tag)
5279 encode_uint32(xdr, args->createmode);
5280 switch (args->createmode) {
5281 case NFS3_CREATE_UNCHECKED:
5282 case NFS3_CREATE_GUARDED:
5283 - encode_sattr3(xdr, args->sattr);
5284 + encode_sattr3(xdr, args->sattr, tag);
5286 case NFS3_CREATE_EXCLUSIVE:
5287 encode_createverf3(xdr, args->verifier);
5288 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5289 const struct nfs3_createargs *args)
5291 encode_diropargs3(xdr, args->fh, args->name, args->len);
5292 - encode_createhow3(xdr, args);
5293 + encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5297 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5298 const struct nfs3_mkdirargs *args)
5300 encode_diropargs3(xdr, args->fh, args->name, args->len);
5301 - encode_sattr3(xdr, args->sattr);
5302 + encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5306 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5309 static void encode_symlinkdata3(struct xdr_stream *xdr,
5310 - const struct nfs3_symlinkargs *args)
5311 + const struct nfs3_symlinkargs *args, int tag)
5313 - encode_sattr3(xdr, args->sattr);
5314 + encode_sattr3(xdr, args->sattr, tag);
5315 encode_nfspath3(xdr, args->pages, args->pathlen);
5318 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5319 const struct nfs3_symlinkargs *args)
5321 encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5322 - encode_symlinkdata3(xdr, args);
5323 + encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5327 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5330 static void encode_devicedata3(struct xdr_stream *xdr,
5331 - const struct nfs3_mknodargs *args)
5332 + const struct nfs3_mknodargs *args, int tag)
5334 - encode_sattr3(xdr, args->sattr);
5335 + encode_sattr3(xdr, args->sattr, tag);
5336 encode_specdata3(xdr, args->rdev);
5339 static void encode_mknoddata3(struct xdr_stream *xdr,
5340 - const struct nfs3_mknodargs *args)
5341 + const struct nfs3_mknodargs *args, int tag)
5343 encode_ftype3(xdr, args->type);
5344 switch (args->type) {
5347 - encode_devicedata3(xdr, args);
5348 + encode_devicedata3(xdr, args, tag);
5352 - encode_sattr3(xdr, args->sattr);
5353 + encode_sattr3(xdr, args->sattr, tag);
5357 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5358 const struct nfs3_mknodargs *args)
5360 encode_diropargs3(xdr, args->fh, args->name, args->len);
5361 - encode_mknoddata3(xdr, args);
5362 + encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5366 diff -NurpP --minimal linux-3.9.4/fs/nfs/super.c linux-3.9.4-vs2.3.6.2/fs/nfs/super.c
5367 --- linux-3.9.4/fs/nfs/super.c 2013-05-31 13:45:24.000000000 +0000
5368 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/super.c 2013-05-31 15:41:34.000000000 +0000
5370 #include <linux/parser.h>
5371 #include <linux/nsproxy.h>
5372 #include <linux/rcupdate.h>
5373 +#include <linux/vs_tag.h>
5375 #include <asm/uaccess.h>
5377 @@ -103,6 +104,7 @@ enum {
5383 /* Mount options that take string arguments */
5385 @@ -115,6 +117,9 @@ enum {
5386 /* Special mount options */
5387 Opt_userspace, Opt_deprecated, Opt_sloppy,
5389 + /* Linux-VServer tagging options */
5390 + Opt_tag, Opt_notag,
5395 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5396 { Opt_fscache_uniq, "fsc=%s" },
5397 { Opt_local_lock, "local_lock=%s" },
5399 + { Opt_tag, "tag" },
5400 + { Opt_notag, "notag" },
5401 + { Opt_tagid, "tagid=%u" },
5403 /* The following needs to be listed after all other options */
5404 { Opt_nfsvers, "v%s" },
5406 @@ -635,6 +644,7 @@ static void nfs_show_mount_options(struc
5407 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5408 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5409 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5410 + { NFS_MOUNT_TAGGED, ",tag", "" },
5413 const struct proc_nfs_info *nfs_infop;
5414 @@ -1261,6 +1271,14 @@ static int nfs_parse_mount_options(char
5415 case Opt_nomigration:
5416 mnt->options &= NFS_OPTION_MIGRATION;
5418 +#ifndef CONFIG_TAGGING_NONE
5420 + mnt->flags |= NFS_MOUNT_TAGGED;
5423 + mnt->flags &= ~NFS_MOUNT_TAGGED;
5428 * options that take numeric values
5429 @@ -1347,6 +1365,12 @@ static int nfs_parse_mount_options(char
5430 goto out_invalid_value;
5431 mnt->minorversion = option;
5433 +#ifdef CONFIG_PROPAGATE
5436 + nfs_data.flags |= NFS_MOUNT_TAGGED;
5441 * options that take text values
5442 diff -NurpP --minimal linux-3.9.4/fs/nfsd/auth.c linux-3.9.4-vs2.3.6.2/fs/nfsd/auth.c
5443 --- linux-3.9.4/fs/nfsd/auth.c 2013-05-31 13:45:24.000000000 +0000
5444 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/auth.c 2013-05-31 14:47:11.000000000 +0000
5447 #include <linux/sched.h>
5448 #include <linux/user_namespace.h>
5449 +#include <linux/vs_tag.h>
5453 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5455 new->fsuid = rqstp->rq_cred.cr_uid;
5456 new->fsgid = rqstp->rq_cred.cr_gid;
5457 + /* FIXME: this desperately needs a tag :)
5458 + new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5461 rqgi = rqstp->rq_cred.cr_group_info;
5463 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfs3xdr.c linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs3xdr.c
5464 --- linux-3.9.4/fs/nfsd/nfs3xdr.c 2013-05-31 13:45:24.000000000 +0000
5465 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs3xdr.c 2013-05-31 16:17:38.000000000 +0000
5468 #include <linux/namei.h>
5469 #include <linux/sunrpc/svc_xprt.h>
5470 +#include <linux/vs_tag.h>
5474 @@ -98,6 +99,8 @@ static __be32 *
5475 decode_sattr3(__be32 *p, struct iattr *iap)
5483 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5484 iap->ia_mode = ntohl(*p++);
5487 - iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5488 + uid = make_kuid(&init_user_ns, ntohl(*p++));
5489 if (uid_valid(iap->ia_uid))
5490 iap->ia_valid |= ATTR_UID;
5493 - iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5494 + gid = make_kgid(&init_user_ns, ntohl(*p++));
5495 if (gid_valid(iap->ia_gid))
5496 iap->ia_valid |= ATTR_GID;
5498 + iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5499 + iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5500 + iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5504 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5505 *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5506 *p++ = htonl((u32) stat->mode);
5507 *p++ = htonl((u32) stat->nlink);
5508 - *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5509 - *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5510 + *p++ = htonl((u32) from_kuid(&init_user_ns,
5511 + TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5512 + stat->uid, stat->tag)));
5513 + *p++ = htonl((u32) from_kgid(&init_user_ns,
5514 + TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5515 + stat->gid, stat->tag)));
5516 if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5517 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5519 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfs4xdr.c linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs4xdr.c
5520 --- linux-3.9.4/fs/nfsd/nfs4xdr.c 2013-05-31 14:22:27.000000000 +0000
5521 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs4xdr.c 2013-05-31 14:47:11.000000000 +0000
5523 #include <linux/utsname.h>
5524 #include <linux/pagemap.h>
5525 #include <linux/sunrpc/svcauth_gss.h>
5526 +#include <linux/vs_tag.h>
5530 @@ -2349,14 +2350,18 @@ out_acl:
5531 WRITE32(stat.nlink);
5533 if (bmval1 & FATTR4_WORD1_OWNER) {
5534 - status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5535 + status = nfsd4_encode_user(rqstp,
5536 + TAGINO_UID(DX_TAG(dentry->d_inode),
5537 + stat.uid, stat.tag), &p, &buflen);
5538 if (status == nfserr_resource)
5543 if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5544 - status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5545 + status = nfsd4_encode_group(rqstp,
5546 + TAGINO_GID(DX_TAG(dentry->d_inode),
5547 + stat.gid, stat.tag), &p, &buflen);
5548 if (status == nfserr_resource)
5551 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfsxdr.c linux-3.9.4-vs2.3.6.2/fs/nfsd/nfsxdr.c
5552 --- linux-3.9.4/fs/nfsd/nfsxdr.c 2013-05-31 13:45:24.000000000 +0000
5553 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/nfsxdr.c 2013-05-31 16:20:53.000000000 +0000
5558 +#include <linux/vs_tag.h>
5560 #define NFSDDBG_FACILITY NFSDDBG_XDR
5562 @@ -89,6 +90,8 @@ static __be32 *
5563 decode_sattr(__be32 *p, struct iattr *iap)
5571 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5574 if ((tmp = ntohl(*p++)) != (u32)-1) {
5575 - iap->ia_uid = make_kuid(&init_user_ns, tmp);
5576 + uid = make_kuid(&init_user_ns, tmp);
5577 if (uid_valid(iap->ia_uid))
5578 iap->ia_valid |= ATTR_UID;
5580 if ((tmp = ntohl(*p++)) != (u32)-1) {
5581 - iap->ia_gid = make_kgid(&init_user_ns, tmp);
5582 + gid = make_kgid(&init_user_ns, tmp);
5583 if (gid_valid(iap->ia_gid))
5584 iap->ia_valid |= ATTR_GID;
5586 + iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5587 + iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5588 + iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5589 if ((tmp = ntohl(*p++)) != (u32)-1) {
5590 iap->ia_valid |= ATTR_SIZE;
5592 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5593 *p++ = htonl(nfs_ftypes[type >> 12]);
5594 *p++ = htonl((u32) stat->mode);
5595 *p++ = htonl((u32) stat->nlink);
5596 - *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5597 - *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5598 + *p++ = htonl((u32) from_kuid(&init_user_ns,
5599 + TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5600 + *p++ = htonl((u32) from_kgid(&init_user_ns,
5601 + TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5603 if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5604 *p++ = htonl(NFS_MAXPATHLEN);
5605 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/dlmglue.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.c
5606 --- linux-3.9.4/fs/ocfs2/dlmglue.c 2013-05-31 13:45:24.000000000 +0000
5607 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.c 2013-05-31 15:47:29.000000000 +0000
5608 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5609 lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5610 lvb->lvb_iuid = cpu_to_be32(i_uid_read(inode));
5611 lvb->lvb_igid = cpu_to_be32(i_gid_read(inode));
5612 + lvb->lvb_itag = cpu_to_be16(inode->i_tag);
5613 lvb->lvb_imode = cpu_to_be16(inode->i_mode);
5614 lvb->lvb_inlink = cpu_to_be16(inode->i_nlink);
5615 lvb->lvb_iatime_packed =
5616 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5618 i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5619 i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5620 + i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5621 inode->i_mode = be16_to_cpu(lvb->lvb_imode);
5622 set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5623 ocfs2_unpack_timespec(&inode->i_atime,
5624 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/dlmglue.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.h
5625 --- linux-3.9.4/fs/ocfs2/dlmglue.h 2012-12-11 03:30:57.000000000 +0000
5626 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.h 2013-05-31 14:47:11.000000000 +0000
5627 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5630 __be32 lvb_igeneration;
5631 - __be32 lvb_reserved2;
5633 + __be16 lvb_reserved2;
5636 #define OCFS2_QINFO_LVB_VERSION 1
5637 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/file.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/file.c
5638 --- linux-3.9.4/fs/ocfs2/file.c 2013-05-31 13:45:24.000000000 +0000
5639 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/file.c 2013-05-31 14:47:11.000000000 +0000
5640 @@ -1124,7 +1124,7 @@ int ocfs2_setattr(struct dentry *dentry,
5641 attr->ia_valid &= ~ATTR_SIZE;
5643 #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5644 - | ATTR_GID | ATTR_UID | ATTR_MODE)
5645 + | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5646 if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5649 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/inode.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.c
5650 --- linux-3.9.4/fs/ocfs2/inode.c 2013-05-31 13:45:24.000000000 +0000
5651 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.c 2013-05-31 20:39:47.000000000 +0000
5653 #include <linux/highmem.h>
5654 #include <linux/pagemap.h>
5655 #include <linux/quotaops.h>
5656 +#include <linux/vs_tag.h>
5658 #include <asm/byteorder.h>
5660 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5662 unsigned int flags = OCFS2_I(inode)->ip_attr;
5664 - inode->i_flags &= ~(S_IMMUTABLE |
5665 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5666 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5668 if (flags & OCFS2_IMMUTABLE_FL)
5669 inode->i_flags |= S_IMMUTABLE;
5670 + if (flags & OCFS2_IXUNLINK_FL)
5671 + inode->i_flags |= S_IXUNLINK;
5673 if (flags & OCFS2_SYNC_FL)
5674 inode->i_flags |= S_SYNC;
5675 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5676 inode->i_flags |= S_NOATIME;
5677 if (flags & OCFS2_DIRSYNC_FL)
5678 inode->i_flags |= S_DIRSYNC;
5680 + inode->i_vflags &= ~(V_BARRIER | V_COW);
5682 + if (flags & OCFS2_BARRIER_FL)
5683 + inode->i_vflags |= V_BARRIER;
5684 + if (flags & OCFS2_COW_FL)
5685 + inode->i_vflags |= V_COW;
5688 /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5689 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5691 unsigned int flags = oi->vfs_inode.i_flags;
5692 + unsigned int vflags = oi->vfs_inode.i_vflags;
5694 + oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5695 + OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5696 + OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5697 + OCFS2_BARRIER_FL | OCFS2_COW_FL);
5699 + if (flags & S_IMMUTABLE)
5700 + oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5701 + if (flags & S_IXUNLINK)
5702 + oi->ip_attr |= OCFS2_IXUNLINK_FL;
5704 - oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5705 - OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5707 oi->ip_attr |= OCFS2_SYNC_FL;
5708 if (flags & S_APPEND)
5709 oi->ip_attr |= OCFS2_APPEND_FL;
5710 - if (flags & S_IMMUTABLE)
5711 - oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5712 if (flags & S_NOATIME)
5713 oi->ip_attr |= OCFS2_NOATIME_FL;
5714 if (flags & S_DIRSYNC)
5715 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5717 + if (vflags & V_BARRIER)
5718 + oi->ip_attr |= OCFS2_BARRIER_FL;
5719 + if (vflags & V_COW)
5720 + oi->ip_attr |= OCFS2_COW_FL;
5723 struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5724 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5725 struct super_block *sb;
5726 struct ocfs2_super *osb;
5733 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5734 inode->i_generation = le32_to_cpu(fe->i_generation);
5735 inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5736 inode->i_mode = le16_to_cpu(fe->i_mode);
5737 - i_uid_write(inode, le32_to_cpu(fe->i_uid));
5738 - i_gid_write(inode, le32_to_cpu(fe->i_gid));
5739 + uid = le32_to_cpu(fe->i_uid);
5740 + gid = le32_to_cpu(fe->i_gid);
5741 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5742 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5743 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5744 + /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5746 /* Fast symlinks will have i_size but no allocated clusters. */
5747 if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5748 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/inode.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.h
5749 --- linux-3.9.4/fs/ocfs2/inode.h 2012-12-11 03:30:57.000000000 +0000
5750 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.h 2013-05-31 14:47:11.000000000 +0000
5751 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5753 void ocfs2_set_inode_flags(struct inode *inode);
5754 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5755 +int ocfs2_sync_flags(struct inode *inode, int, int);
5757 static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5759 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/ioctl.c
5760 --- linux-3.9.4/fs/ocfs2/ioctl.c 2013-05-31 13:45:24.000000000 +0000
5761 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/ioctl.c 2013-05-31 14:47:11.000000000 +0000
5762 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5766 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5767 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5769 + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5770 + struct buffer_head *bh = NULL;
5771 + handle_t *handle = NULL;
5774 + status = ocfs2_inode_lock(inode, &bh, 1);
5776 + mlog_errno(status);
5779 + handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5780 + if (IS_ERR(handle)) {
5781 + status = PTR_ERR(handle);
5782 + mlog_errno(status);
5786 + inode->i_flags = flags;
5787 + inode->i_vflags = vflags;
5788 + ocfs2_get_inode_flags(OCFS2_I(inode));
5790 + status = ocfs2_mark_inode_dirty(handle, inode, bh);
5792 + mlog_errno(status);
5794 + ocfs2_commit_trans(osb, handle);
5796 + ocfs2_inode_unlock(inode, 1);
5801 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5804 struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5805 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5806 if (!S_ISDIR(inode->i_mode))
5807 flags &= ~OCFS2_DIRSYNC_FL;
5809 + if (IS_BARRIER(inode)) {
5810 + vxwprintk_task(1, "messing with the barrier.");
5814 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5815 if (IS_ERR(handle)) {
5816 status = PTR_ERR(handle);
5817 @@ -879,6 +918,7 @@ bail:
5822 long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5824 struct inode *inode = file_inode(filp);
5825 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/namei.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/namei.c
5826 --- linux-3.9.4/fs/ocfs2/namei.c 2013-05-31 13:45:24.000000000 +0000
5827 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/namei.c 2013-05-31 15:52:25.000000000 +0000
5829 #include <linux/slab.h>
5830 #include <linux/highmem.h>
5831 #include <linux/quotaops.h>
5832 +#include <linux/vs_tag.h>
5834 #include <cluster/masklog.h>
5836 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5837 struct ocfs2_dinode *fe = NULL;
5838 struct ocfs2_extent_list *fel;
5844 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5845 fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5846 fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5847 fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5848 - fe->i_uid = cpu_to_le32(i_uid_read(inode));
5849 - fe->i_gid = cpu_to_le32(i_gid_read(inode));
5851 + tag = dx_current_fstag(osb->sb);
5852 + fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), i_uid_read(inode), tag));
5853 + fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), i_gid_read(inode), tag));
5854 + inode->i_tag = tag; /* is this correct? */
5855 fe->i_mode = cpu_to_le16(inode->i_mode);
5856 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5857 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5858 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ocfs2.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2.h
5859 --- linux-3.9.4/fs/ocfs2/ocfs2.h 2012-12-11 03:30:57.000000000 +0000
5860 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2.h 2013-05-31 14:47:11.000000000 +0000
5861 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5863 OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5864 OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5865 + OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5868 #define OCFS2_OSB_SOFT_RO 0x0001
5869 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ocfs2_fs.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2_fs.h
5870 --- linux-3.9.4/fs/ocfs2/ocfs2_fs.h 2012-12-11 03:30:57.000000000 +0000
5871 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2_fs.h 2013-05-31 14:47:11.000000000 +0000
5872 @@ -266,6 +266,11 @@
5873 #define OCFS2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
5874 #define OCFS2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
5876 +#define OCFS2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
5878 +#define OCFS2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
5879 +#define OCFS2_COW_FL FS_COW_FL /* Copy on Write marker */
5881 #define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
5882 #define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
5884 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/super.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/super.c
5885 --- linux-3.9.4/fs/ocfs2/super.c 2013-05-31 13:45:25.000000000 +0000
5886 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/super.c 2013-05-31 14:47:11.000000000 +0000
5887 @@ -185,6 +185,7 @@ enum {
5891 + Opt_tag, Opt_notag, Opt_tagid,
5895 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5896 {Opt_coherency_full, "coherency=full"},
5897 {Opt_resv_level, "resv_level=%u"},
5898 {Opt_dir_resv_level, "dir_resv_level=%u"},
5900 + {Opt_notag, "notag"},
5901 + {Opt_tagid, "tagid=%u"},
5905 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5909 + if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5910 + (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5912 + mlog(ML_ERROR, "Cannot change tagging on remount\n");
5916 /* We're going to/from readonly mode. */
5917 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5918 /* Disable quota accounting before remounting RO */
5919 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5921 ocfs2_complete_mount_recovery(osb);
5923 + if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5924 + sb->s_flags |= MS_TAGGED;
5926 if (ocfs2_mount_local(osb))
5927 snprintf(nodestr, sizeof(nodestr), "local");
5929 @@ -1504,6 +1518,20 @@ static int ocfs2_parse_options(struct su
5930 option < OCFS2_MAX_RESV_LEVEL)
5931 mopt->dir_resv_level = option;
5933 +#ifndef CONFIG_TAGGING_NONE
5935 + mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5938 + mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5941 +#ifdef CONFIG_PROPAGATE
5944 + mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5949 "Unrecognized mount option \"%s\" "
5950 diff -NurpP --minimal linux-3.9.4/fs/open.c linux-3.9.4-vs2.3.6.2/fs/open.c
5951 --- linux-3.9.4/fs/open.c 2013-05-31 13:45:25.000000000 +0000
5952 +++ linux-3.9.4-vs2.3.6.2/fs/open.c 2013-06-01 08:41:29.000000000 +0000
5954 #include <linux/ima.h>
5955 #include <linux/dnotify.h>
5956 #include <linux/compat.h>
5957 +#include <linux/vs_base.h>
5958 +#include <linux/vs_limit.h>
5959 +#include <linux/vs_tag.h>
5960 +#include <linux/vs_cowbl.h>
5961 +#include <linux/vserver/dlimit.h>
5963 #include "internal.h"
5965 @@ -67,6 +72,11 @@ long vfs_truncate(struct path *path, lof
5966 struct inode *inode;
5969 +#ifdef CONFIG_VSERVER_COWBL
5970 + error = cow_check_and_break(path);
5974 inode = path->dentry->d_inode;
5976 /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5977 @@ -532,6 +542,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5978 unsigned int lookup_flags = LOOKUP_FOLLOW;
5980 error = user_path_at(dfd, filename, lookup_flags, &path);
5981 +#ifdef CONFIG_VSERVER_COWBL
5983 + error = cow_check_and_break(&path);
5989 error = chmod_common(&path, mode);
5991 @@ -564,13 +581,15 @@ static int chown_common(struct path *pat
5992 if (!uid_valid(uid))
5994 newattrs.ia_valid |= ATTR_UID;
5995 - newattrs.ia_uid = uid;
5996 + newattrs.ia_uid = make_kuid(&init_user_ns,
5997 + dx_map_uid(user));
5999 if (group != (gid_t) -1) {
6000 if (!gid_valid(gid))
6002 newattrs.ia_valid |= ATTR_GID;
6003 - newattrs.ia_gid = gid;
6004 + newattrs.ia_gid = make_kgid(&init_user_ns,
6005 + dx_map_gid(group));
6007 if (!S_ISDIR(inode->i_mode))
6008 newattrs.ia_valid |=
6009 @@ -604,6 +623,18 @@ retry:
6010 error = mnt_want_write(path.mnt);
6013 +#ifdef CONFIG_VSERVER_COWBL
6014 + error = cow_check_and_break(&path);
6017 +#ifdef CONFIG_VSERVER_COWBL
6018 + error = cow_check_and_break(&path);
6021 +#ifdef CONFIG_VSERVER_COWBL
6022 + error = cow_check_and_break(&path);
6025 error = chown_common(&path, user, group);
6026 mnt_drop_write(path.mnt);
6028 diff -NurpP --minimal linux-3.9.4/fs/proc/array.c linux-3.9.4-vs2.3.6.2/fs/proc/array.c
6029 --- linux-3.9.4/fs/proc/array.c 2013-05-31 13:45:25.000000000 +0000
6030 +++ linux-3.9.4-vs2.3.6.2/fs/proc/array.c 2013-05-31 14:47:11.000000000 +0000
6032 #include <linux/ptrace.h>
6033 #include <linux/tracehook.h>
6034 #include <linux/user_namespace.h>
6035 +#include <linux/vs_context.h>
6036 +#include <linux/vs_network.h>
6038 #include <asm/pgtable.h>
6039 #include <asm/processor.h>
6040 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
6042 ppid = pid_alive(p) ?
6043 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6044 + if (unlikely(vx_current_initpid(p->pid)))
6049 struct task_struct *tracer = ptrace_parent(p);
6050 @@ -297,7 +302,7 @@ static inline void task_sig(struct seq_f
6053 static void render_cap_t(struct seq_file *m, const char *header,
6055 + struct vx_info *vxi, kernel_cap_t *a)
6059 @@ -331,10 +336,11 @@ static inline void task_cap(struct seq_f
6060 NORM_CAPS(cap_effective);
6061 NORM_CAPS(cap_bset);
6063 - render_cap_t(m, "CapInh:\t", &cap_inheritable);
6064 - render_cap_t(m, "CapPrm:\t", &cap_permitted);
6065 - render_cap_t(m, "CapEff:\t", &cap_effective);
6066 - render_cap_t(m, "CapBnd:\t", &cap_bset);
6067 + /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6068 + render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6069 + render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6070 + render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6071 + render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6074 static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
6075 @@ -363,6 +369,42 @@ static void task_cpus_allowed(struct seq
6079 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6080 + struct pid *pid, struct task_struct *task)
6082 + seq_printf(m, "Proxy:\t%p(%c)\n"
6090 + (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6091 + atomic_read(&task->nsproxy->count),
6092 + task->nsproxy->uts_ns,
6093 + (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6094 + task->nsproxy->ipc_ns,
6095 + (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6096 + task->nsproxy->mnt_ns,
6097 + (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6098 + task->nsproxy->pid_ns,
6099 + (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6100 + task->nsproxy->net_ns,
6101 + (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6105 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6107 + if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6110 + seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6111 + seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6115 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6116 struct pid *pid, struct task_struct *task)
6118 @@ -380,6 +422,7 @@ int proc_pid_status(struct seq_file *m,
6119 task_seccomp(m, task);
6120 task_cpus_allowed(m, task);
6121 cpuset_task_status_allowed(m, task);
6122 + task_vs_id(m, task);
6123 task_context_switch_counts(m, task);
6126 @@ -489,6 +532,17 @@ static int do_task_stat(struct seq_file
6127 /* convert nsec -> ticks */
6128 start_time = nsec_to_clock_t(start_time);
6130 + /* fixup start time for virt uptime */
6131 + if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6132 + unsigned long long bias =
6133 + current->vx_info->cvirt.bias_clock;
6135 + if (start_time > bias)
6136 + start_time -= bias;
6141 seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6142 seq_put_decimal_ll(m, ' ', ppid);
6143 seq_put_decimal_ll(m, ' ', pgid);
6144 diff -NurpP --minimal linux-3.9.4/fs/proc/base.c linux-3.9.4-vs2.3.6.2/fs/proc/base.c
6145 --- linux-3.9.4/fs/proc/base.c 2013-05-31 13:45:25.000000000 +0000
6146 +++ linux-3.9.4-vs2.3.6.2/fs/proc/base.c 2013-05-31 14:47:11.000000000 +0000
6148 #include <linux/fs_struct.h>
6149 #include <linux/slab.h>
6150 #include <linux/flex_array.h>
6151 +#include <linux/vs_context.h>
6152 +#include <linux/vs_network.h>
6153 #ifdef CONFIG_HARDWALL
6154 #include <asm/hardwall.h>
6156 @@ -944,11 +946,15 @@ static ssize_t oom_adj_write(struct file
6157 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6159 if (oom_adj < task->signal->oom_score_adj &&
6160 - !capable(CAP_SYS_RESOURCE)) {
6161 + !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6166 + /* prevent guest processes from circumventing the oom killer */
6167 + if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6168 + oom_adj = OOM_ADJUST_MIN;
6171 * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6172 * /proc/pid/oom_score_adj instead.
6173 @@ -1528,6 +1534,8 @@ struct inode *proc_pid_make_inode(struct
6174 inode->i_gid = cred->egid;
6177 + /* procfs is xid tagged */
6178 + i_tag_write(inode, (tag_t)vx_task_xid(task));
6179 security_task_to_inode(task, inode);
6182 @@ -1573,6 +1581,8 @@ int pid_getattr(struct vfsmount *mnt, st
6186 +static unsigned name_to_int(struct dentry *dentry);
6189 * Exceptional case: normally we are not allowed to unhash a busy
6190 * directory. In this case, however, we can do it - no aliasing problems
6191 @@ -1601,6 +1611,12 @@ int pid_revalidate(struct dentry *dentry
6192 task = get_proc_task(inode);
6195 + unsigned pid = name_to_int(dentry);
6197 + if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6198 + put_task_struct(task);
6201 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6202 task_dumpable(task)) {
6204 @@ -1617,6 +1633,7 @@ int pid_revalidate(struct dentry *dentry
6205 put_task_struct(task);
6212 @@ -2059,6 +2076,13 @@ static struct dentry *proc_pident_lookup
6216 + /* TODO: maybe we can come up with a generic approach? */
6217 + if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6218 + (dentry->d_name.len == 5) &&
6219 + (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6220 + !memcmp(dentry->d_name.name, "ninfo", 5)))
6224 * Yes, it does not scale. And it should not. Don't add
6225 * new entries into /proc/<tgid>/ without very good reasons.
6226 @@ -2493,6 +2517,9 @@ static int proc_pid_personality(struct s
6227 static const struct file_operations proc_task_operations;
6228 static const struct inode_operations proc_task_inode_operations;
6230 +extern int proc_pid_vx_info(struct task_struct *, char *);
6231 +extern int proc_pid_nx_info(struct task_struct *, char *);
6233 static const struct pid_entry tgid_base_stuff[] = {
6234 DIR("task", S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6235 DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6236 @@ -2559,6 +2586,8 @@ static const struct pid_entry tgid_base_
6237 #ifdef CONFIG_CGROUPS
6238 REG("cgroup", S_IRUGO, proc_cgroup_operations),
6240 + INF("vinfo", S_IRUGO, proc_pid_vx_info),
6241 + INF("ninfo", S_IRUGO, proc_pid_nx_info),
6242 INF("oom_score", S_IRUGO, proc_oom_score),
6243 REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6244 REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6245 @@ -2583,6 +2612,7 @@ static const struct pid_entry tgid_base_
6246 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
6247 REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6249 + ONE("nsproxy", S_IRUGO, proc_pid_nsproxy),
6252 static int proc_tgid_base_readdir(struct file * filp,
6253 @@ -2770,7 +2800,7 @@ retry:
6255 pid = find_ge_pid(iter.tgid, ns);
6257 - iter.tgid = pid_nr_ns(pid, ns);
6258 + iter.tgid = pid_unmapped_nr_ns(pid, ns);
6259 iter.task = pid_task(pid, PIDTYPE_PID);
6260 /* What we to know is if the pid we have find is the
6261 * pid of a thread_group_leader. Testing for task
6262 @@ -2800,7 +2830,7 @@ static int proc_pid_fill_cache(struct fi
6263 struct tgid_iter iter)
6265 char name[PROC_NUMBUF];
6266 - int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6267 + int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6268 return proc_fill_cache(filp, dirent, filldir, name, len,
6269 proc_pid_instantiate, iter.task, NULL);
6271 @@ -2833,6 +2863,8 @@ int proc_pid_readdir(struct file * filp,
6272 __filldir = fake_filldir;
6274 filp->f_pos = iter.tgid + TGID_OFFSET;
6275 + if (!vx_proc_task_visible(iter.task))
6277 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6278 put_task_struct(iter.task);
6280 @@ -2993,6 +3025,8 @@ static struct dentry *proc_task_lookup(s
6281 tid = name_to_int(dentry);
6284 + if (vx_current_initpid(tid))
6287 ns = dentry->d_sb->s_fs_info;
6289 diff -NurpP --minimal linux-3.9.4/fs/proc/generic.c linux-3.9.4-vs2.3.6.2/fs/proc/generic.c
6290 --- linux-3.9.4/fs/proc/generic.c 2013-05-31 13:45:25.000000000 +0000
6291 +++ linux-3.9.4-vs2.3.6.2/fs/proc/generic.c 2013-05-31 16:13:42.000000000 +0000
6293 #include <linux/bitops.h>
6294 #include <linux/spinlock.h>
6295 #include <linux/completion.h>
6296 +#include <linux/vserver/inode.h>
6297 #include <asm/uaccess.h>
6299 #include "internal.h"
6300 @@ -409,6 +410,8 @@ struct dentry *proc_lookup_de(struct pro
6301 for (de = de->subdir; de ; de = de->next) {
6302 if (de->namelen != dentry->d_name.len)
6304 + if (!vx_hide_check(0, de->vx_flags))
6306 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6308 spin_unlock(&proc_subdir_lock);
6309 @@ -417,6 +420,8 @@ struct dentry *proc_lookup_de(struct pro
6310 return ERR_PTR(-ENOMEM);
6311 d_set_d_op(dentry, &proc_dentry_operations);
6312 d_add(dentry, inode);
6313 + /* generic proc entries belong to the host */
6314 + i_tag_write(inode, 0);
6318 @@ -485,6 +490,8 @@ int proc_readdir_de(struct proc_dir_entr
6320 /* filldir passes info to user space */
6322 + if (!vx_hide_check(0, de->vx_flags))
6324 spin_unlock(&proc_subdir_lock);
6325 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6326 de->low_ino, de->mode >> 12) < 0) {
6327 @@ -492,6 +499,7 @@ int proc_readdir_de(struct proc_dir_entr
6330 spin_lock(&proc_subdir_lock);
6335 @@ -603,6 +611,7 @@ static struct proc_dir_entry *__proc_cre
6339 + ent->vx_flags = IATTR_PROC_DEFAULT;
6340 atomic_set(&ent->count, 1);
6341 spin_lock_init(&ent->pde_unload_lock);
6342 INIT_LIST_HEAD(&ent->pde_openers);
6343 @@ -626,7 +635,8 @@ struct proc_dir_entry *proc_symlink(cons
6349 + ent->vx_flags = IATTR_PROC_SYMLINK;
6353 diff -NurpP --minimal linux-3.9.4/fs/proc/inode.c linux-3.9.4-vs2.3.6.2/fs/proc/inode.c
6354 --- linux-3.9.4/fs/proc/inode.c 2013-05-31 13:45:25.000000000 +0000
6355 +++ linux-3.9.4-vs2.3.6.2/fs/proc/inode.c 2013-05-31 14:47:11.000000000 +0000
6356 @@ -458,6 +458,8 @@ struct inode *proc_get_inode(struct supe
6357 inode->i_uid = de->uid;
6358 inode->i_gid = de->gid;
6361 + PROC_I(inode)->vx_flags = de->vx_flags;
6363 inode->i_size = de->size;
6365 diff -NurpP --minimal linux-3.9.4/fs/proc/internal.h linux-3.9.4-vs2.3.6.2/fs/proc/internal.h
6366 --- linux-3.9.4/fs/proc/internal.h 2013-05-31 13:45:25.000000000 +0000
6367 +++ linux-3.9.4-vs2.3.6.2/fs/proc/internal.h 2013-05-31 16:04:34.000000000 +0000
6369 #include <linux/sched.h>
6370 #include <linux/proc_fs.h>
6371 #include <linux/binfmts.h>
6372 +#include <linux/vs_pid.h>
6374 struct ctl_table_header;
6377 @@ -56,6 +58,9 @@ extern int proc_pid_status(struct seq_fi
6378 struct pid *pid, struct task_struct *task);
6379 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6380 struct pid *pid, struct task_struct *task);
6381 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6382 + struct pid *pid, struct task_struct *task);
6384 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6386 extern const struct file_operations proc_tid_children_operations;
6387 @@ -89,11 +94,16 @@ static inline struct pid *proc_pid(struc
6388 return PROC_I(inode)->pid;
6391 -static inline struct task_struct *get_proc_task(struct inode *inode)
6392 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6394 return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6397 +static inline struct task_struct *get_proc_task(struct inode *inode)
6399 + return vx_get_proc_task(inode, proc_pid(inode));
6402 static inline int proc_fd(struct inode *inode)
6404 return PROC_I(inode)->fd;
6405 diff -NurpP --minimal linux-3.9.4/fs/proc/loadavg.c linux-3.9.4-vs2.3.6.2/fs/proc/loadavg.c
6406 --- linux-3.9.4/fs/proc/loadavg.c 2012-12-11 03:30:57.000000000 +0000
6407 +++ linux-3.9.4-vs2.3.6.2/fs/proc/loadavg.c 2013-05-31 14:47:11.000000000 +0000
6410 static int loadavg_proc_show(struct seq_file *m, void *v)
6412 + unsigned long running;
6413 + unsigned int threads;
6414 unsigned long avnrun[3];
6416 get_avenrun(avnrun, FIXED_1/200, 0);
6418 + if (vx_flags(VXF_VIRT_LOAD, 0)) {
6419 + struct vx_info *vxi = current_vx_info();
6421 + running = atomic_read(&vxi->cvirt.nr_running);
6422 + threads = atomic_read(&vxi->cvirt.nr_threads);
6424 + running = nr_running();
6425 + threads = nr_threads;
6428 seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6429 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6430 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6431 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6432 - nr_running(), nr_threads,
6434 task_active_pid_ns(current)->last_pid);
6437 diff -NurpP --minimal linux-3.9.4/fs/proc/meminfo.c linux-3.9.4-vs2.3.6.2/fs/proc/meminfo.c
6438 --- linux-3.9.4/fs/proc/meminfo.c 2013-05-31 13:45:25.000000000 +0000
6439 +++ linux-3.9.4-vs2.3.6.2/fs/proc/meminfo.c 2013-05-31 16:05:39.000000000 +0000
6440 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6441 allowed = ((totalram_pages - hugetlb_total_pages())
6442 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6444 - cached = global_page_state(NR_FILE_PAGES) -
6445 + cached = vx_flags(VXF_VIRT_MEM, 0) ?
6446 + vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6447 total_swapcache_pages() - i.bufferram;
6450 diff -NurpP --minimal linux-3.9.4/fs/proc/root.c linux-3.9.4-vs2.3.6.2/fs/proc/root.c
6451 --- linux-3.9.4/fs/proc/root.c 2013-05-31 13:45:25.000000000 +0000
6452 +++ linux-3.9.4-vs2.3.6.2/fs/proc/root.c 2013-05-31 14:47:11.000000000 +0000
6454 #include <linux/mount.h>
6455 #include <linux/pid_namespace.h>
6456 #include <linux/parser.h>
6457 +#include <linux/vserver/inode.h>
6459 #include "internal.h"
6461 +struct proc_dir_entry *proc_virtual;
6463 +extern void proc_vx_init(void);
6465 static int proc_test_super(struct super_block *sb, void *data)
6467 return sb->s_fs_info == data;
6468 @@ -182,6 +187,7 @@ void __init proc_root_init(void)
6470 proc_mkdir("bus", NULL);
6475 static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6476 @@ -248,6 +254,7 @@ struct proc_dir_entry proc_root = {
6477 .proc_iops = &proc_root_inode_operations,
6478 .proc_fops = &proc_root_operations,
6479 .parent = &proc_root,
6480 + .vx_flags = IATTR_ADMIN | IATTR_WATCH,
6484 diff -NurpP --minimal linux-3.9.4/fs/proc/self.c linux-3.9.4-vs2.3.6.2/fs/proc/self.c
6485 --- linux-3.9.4/fs/proc/self.c 2013-02-19 13:58:49.000000000 +0000
6486 +++ linux-3.9.4-vs2.3.6.2/fs/proc/self.c 2013-05-31 20:57:54.000000000 +0000
6488 #include <linux/proc_fs.h>
6489 #include <linux/sched.h>
6490 #include <linux/namei.h>
6491 +#include <linux/vserver/inode.h>
6495 @@ -56,4 +57,5 @@ void __init proc_self_init(void)
6496 mode = S_IFLNK | S_IRWXUGO;
6497 proc_self_symlink = proc_create("self", mode, NULL, NULL );
6498 proc_self_symlink->proc_iops = &proc_self_inode_operations;
6499 + proc_self_symlink->vx_flags = IATTR_PROC_SYMLINK;
6501 diff -NurpP --minimal linux-3.9.4/fs/proc/stat.c linux-3.9.4-vs2.3.6.2/fs/proc/stat.c
6502 --- linux-3.9.4/fs/proc/stat.c 2012-12-11 03:30:57.000000000 +0000
6503 +++ linux-3.9.4-vs2.3.6.2/fs/proc/stat.c 2013-05-31 14:47:11.000000000 +0000
6505 #include <linux/slab.h>
6506 #include <linux/time.h>
6507 #include <linux/irqnr.h>
6508 +#include <linux/vserver/cvirt.h>
6509 #include <asm/cputime.h>
6510 #include <linux/tick.h>
6511 +#include <linux/cpuset.h>
6513 #ifndef arch_irq_stat_cpu
6514 #define arch_irq_stat_cpu(cpu) 0
6515 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6516 u64 sum_softirq = 0;
6517 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6518 struct timespec boottime;
6519 + cpumask_var_t cpus_allowed;
6520 + bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6522 user = nice = system = idle = iowait =
6523 irq = softirq = steal = 0;
6524 guest = guest_nice = 0;
6525 getboottime(&boottime);
6527 + if (vx_flags(VXF_VIRT_UPTIME, 0))
6528 + vx_vsi_boottime(&boottime);
6531 + cpuset_cpus_allowed(current, cpus_allowed);
6533 jif = boottime.tv_sec;
6535 for_each_possible_cpu(i) {
6536 + if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6539 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6540 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6541 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6542 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6545 for_each_online_cpu(i) {
6546 + if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6549 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6550 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6551 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6552 diff -NurpP --minimal linux-3.9.4/fs/proc/uptime.c linux-3.9.4-vs2.3.6.2/fs/proc/uptime.c
6553 --- linux-3.9.4/fs/proc/uptime.c 2012-12-11 03:30:57.000000000 +0000
6554 +++ linux-3.9.4-vs2.3.6.2/fs/proc/uptime.c 2013-05-31 14:47:11.000000000 +0000
6556 #include <linux/seq_file.h>
6557 #include <linux/time.h>
6558 #include <linux/kernel_stat.h>
6559 +#include <linux/vserver/cvirt.h>
6560 #include <asm/cputime.h>
6562 static int uptime_proc_show(struct seq_file *m, void *v)
6563 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6564 nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6565 idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6568 + if (vx_flags(VXF_VIRT_UPTIME, 0))
6569 + vx_vsi_uptime(&uptime, &idle);
6571 seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6572 (unsigned long) uptime.tv_sec,
6573 (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6574 diff -NurpP --minimal linux-3.9.4/fs/proc_namespace.c linux-3.9.4-vs2.3.6.2/fs/proc_namespace.c
6575 --- linux-3.9.4/fs/proc_namespace.c 2012-12-11 03:30:57.000000000 +0000
6576 +++ linux-3.9.4-vs2.3.6.2/fs/proc_namespace.c 2013-05-31 17:17:53.000000000 +0000
6577 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6578 { MS_SYNCHRONOUS, ",sync" },
6579 { MS_DIRSYNC, ",dirsync" },
6580 { MS_MANDLOCK, ",mand" },
6581 + { MS_TAGGED, ",tag" },
6582 + { MS_NOTAGCHECK, ",notagcheck" },
6585 const struct proc_fs_info *fs_infop;
6586 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6587 seq_escape(m, s, " \t\n\\");
6590 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6592 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6595 + struct dentry *point;
6596 + struct mount *mnt = real_mount(vfsmnt);
6597 + struct mount *root_mnt;
6600 + if (mnt == mnt->mnt_ns->root)
6603 + br_read_lock(&vfsmount_lock);
6604 + root = current->fs->root;
6605 + root_mnt = real_mount(root.mnt);
6606 + point = root.dentry;
6608 + while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6609 + point = mnt->mnt_mountpoint;
6610 + mnt = mnt->mnt_parent;
6613 + ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6615 + br_read_unlock(&vfsmount_lock);
6621 +#define mnt_is_reachable(v) (1)
6624 static void show_type(struct seq_file *m, struct super_block *sb)
6626 mangle(m, sb->s_type->name);
6627 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6628 struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6629 struct super_block *sb = mnt_path.dentry->d_sb;
6631 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6633 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6636 + if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6637 + mnt == current->fs->root.mnt) {
6638 + seq_puts(m, "/dev/root / ");
6642 if (sb->s_op->show_devname) {
6643 err = sb->s_op->show_devname(m, mnt_path.dentry);
6645 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6647 seq_path(m, &mnt_path, " \t\n\\");
6651 seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6652 err = show_sb_opts(m, sb);
6653 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6654 struct path root = p->root;
6657 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6659 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6662 seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6663 MAJOR(sb->s_dev), MINOR(sb->s_dev));
6664 if (sb->s_op->show_path)
6665 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6666 struct super_block *sb = mnt_path.dentry->d_sb;
6669 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6671 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6674 + if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6675 + mnt == current->fs->root.mnt) {
6676 + seq_puts(m, "device /dev/root mounted on / ");
6681 if (sb->s_op->show_devname) {
6682 seq_puts(m, "device ");
6683 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6684 seq_puts(m, " mounted on ");
6685 seq_path(m, &mnt_path, " \t\n\\");
6689 /* file system type */
6690 seq_puts(m, "with fstype ");
6692 diff -NurpP --minimal linux-3.9.4/fs/quota/dquot.c linux-3.9.4-vs2.3.6.2/fs/quota/dquot.c
6693 --- linux-3.9.4/fs/quota/dquot.c 2013-05-31 13:45:25.000000000 +0000
6694 +++ linux-3.9.4-vs2.3.6.2/fs/quota/dquot.c 2013-05-31 14:47:11.000000000 +0000
6695 @@ -1585,6 +1585,9 @@ int __dquot_alloc_space(struct inode *in
6696 struct dquot **dquots = inode->i_dquot;
6697 int reserve = flags & DQUOT_SPACE_RESERVE;
6699 + if ((ret = dl_alloc_space(inode, number)))
6703 * First test before acquiring mutex - solves deadlocks when we
6704 * re-enter the quota code and are already holding the mutex
6705 @@ -1640,6 +1643,9 @@ int dquot_alloc_inode(const struct inode
6706 struct dquot_warn warn[MAXQUOTAS];
6707 struct dquot * const *dquots = inode->i_dquot;
6709 + if ((ret = dl_alloc_inode(inode)))
6712 /* First test before acquiring mutex - solves deadlocks when we
6713 * re-enter the quota code and are already holding the mutex */
6714 if (!dquot_active(inode))
6715 @@ -1711,6 +1717,8 @@ void __dquot_free_space(struct inode *in
6716 struct dquot **dquots = inode->i_dquot;
6717 int reserve = flags & DQUOT_SPACE_RESERVE;
6719 + dl_free_space(inode, number);
6721 /* First test before acquiring mutex - solves deadlocks when we
6722 * re-enter the quota code and are already holding the mutex */
6723 if (!dquot_active(inode)) {
6724 @@ -1755,6 +1763,8 @@ void dquot_free_inode(const struct inode
6725 struct dquot_warn warn[MAXQUOTAS];
6726 struct dquot * const *dquots = inode->i_dquot;
6728 + dl_free_inode(inode);
6730 /* First test before acquiring mutex - solves deadlocks when we
6731 * re-enter the quota code and are already holding the mutex */
6732 if (!dquot_active(inode))
6733 diff -NurpP --minimal linux-3.9.4/fs/quota/quota.c linux-3.9.4-vs2.3.6.2/fs/quota/quota.c
6734 --- linux-3.9.4/fs/quota/quota.c 2013-02-19 13:58:49.000000000 +0000
6735 +++ linux-3.9.4-vs2.3.6.2/fs/quota/quota.c 2013-05-31 14:47:11.000000000 +0000
6737 #include <linux/fs.h>
6738 #include <linux/namei.h>
6739 #include <linux/slab.h>
6740 +#include <linux/vs_context.h>
6741 #include <asm/current.h>
6742 #include <linux/uaccess.h>
6743 #include <linux/kernel.h>
6744 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6748 - if (!capable(CAP_SYS_ADMIN))
6749 + if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6753 @@ -309,6 +310,46 @@ static int do_quotactl(struct super_bloc
6757 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6759 +#include <linux/vroot.h>
6760 +#include <linux/major.h>
6761 +#include <linux/module.h>
6762 +#include <linux/kallsyms.h>
6763 +#include <linux/vserver/debug.h>
6765 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6767 +static DEFINE_SPINLOCK(vroot_grb_lock);
6769 +int register_vroot_grb(vroot_grb_func *func) {
6772 + spin_lock(&vroot_grb_lock);
6773 + if (!vroot_get_real_bdev) {
6774 + vroot_get_real_bdev = func;
6777 + spin_unlock(&vroot_grb_lock);
6780 +EXPORT_SYMBOL(register_vroot_grb);
6782 +int unregister_vroot_grb(vroot_grb_func *func) {
6783 + int ret = -EINVAL;
6785 + spin_lock(&vroot_grb_lock);
6786 + if (vroot_get_real_bdev) {
6787 + vroot_get_real_bdev = NULL;
6790 + spin_unlock(&vroot_grb_lock);
6793 +EXPORT_SYMBOL(unregister_vroot_grb);
6797 /* Return 1 if 'cmd' will block on frozen filesystem */
6798 static int quotactl_cmd_write(int cmd)
6800 @@ -343,6 +384,22 @@ static struct super_block *quotactl_bloc
6803 return ERR_CAST(bdev);
6804 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6805 + if (bdev && bdev->bd_inode &&
6806 + imajor(bdev->bd_inode) == VROOT_MAJOR) {
6807 + struct block_device *bdnew = (void *)-EINVAL;
6809 + if (vroot_get_real_bdev)
6810 + bdnew = vroot_get_real_bdev(bdev);
6812 + vxdprintk(VXD_CBIT(misc, 0),
6813 + "vroot_get_real_bdev not set");
6815 + if (IS_ERR(bdnew))
6816 + return ERR_PTR(PTR_ERR(bdnew));
6820 if (quotactl_cmd_write(cmd))
6821 sb = get_super_thawed(bdev);
6823 diff -NurpP --minimal linux-3.9.4/fs/stat.c linux-3.9.4-vs2.3.6.2/fs/stat.c
6824 --- linux-3.9.4/fs/stat.c 2013-05-31 13:45:25.000000000 +0000
6825 +++ linux-3.9.4-vs2.3.6.2/fs/stat.c 2013-06-01 08:53:01.000000000 +0000
6826 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6827 stat->nlink = inode->i_nlink;
6828 stat->uid = inode->i_uid;
6829 stat->gid = inode->i_gid;
6830 + stat->tag = inode->i_tag;
6831 stat->rdev = inode->i_rdev;
6832 stat->size = i_size_read(inode);
6833 stat->atime = inode->i_atime;
6834 diff -NurpP --minimal linux-3.9.4/fs/statfs.c linux-3.9.4-vs2.3.6.2/fs/statfs.c
6835 --- linux-3.9.4/fs/statfs.c 2013-02-19 13:58:49.000000000 +0000
6836 +++ linux-3.9.4-vs2.3.6.2/fs/statfs.c 2013-05-31 14:47:11.000000000 +0000
6838 #include <linux/statfs.h>
6839 #include <linux/security.h>
6840 #include <linux/uaccess.h>
6841 +#include <linux/vs_base.h>
6842 +#include <linux/vs_dlimit.h>
6843 #include "internal.h"
6845 static int flags_by_mnt(int mnt_flags)
6846 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6847 retval = dentry->d_sb->s_op->statfs(dentry, buf);
6848 if (retval == 0 && buf->f_frsize == 0)
6849 buf->f_frsize = buf->f_bsize;
6850 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
6851 + vx_vsi_statfs(dentry->d_sb, buf);
6855 diff -NurpP --minimal linux-3.9.4/fs/super.c linux-3.9.4-vs2.3.6.2/fs/super.c
6856 --- linux-3.9.4/fs/super.c 2013-05-31 13:45:25.000000000 +0000
6857 +++ linux-3.9.4-vs2.3.6.2/fs/super.c 2013-05-31 14:47:11.000000000 +0000
6859 #include <linux/cleancache.h>
6860 #include <linux/fsnotify.h>
6861 #include <linux/lockdep.h>
6862 +#include <linux/magic.h>
6863 +#include <linux/vs_context.h>
6864 #include "internal.h"
6867 @@ -1117,6 +1119,13 @@ mount_fs(struct file_system_type *type,
6868 WARN_ON(sb->s_bdi == &default_backing_dev_info);
6869 sb->s_flags |= MS_BORN;
6872 + if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6874 + (sb->s_magic != PROC_SUPER_MAGIC) &&
6875 + (sb->s_magic != DEVPTS_SUPER_MAGIC))
6878 error = security_sb_kern_mount(sb, flags, secdata);
6881 diff -NurpP --minimal linux-3.9.4/fs/sysfs/mount.c linux-3.9.4-vs2.3.6.2/fs/sysfs/mount.c
6882 --- linux-3.9.4/fs/sysfs/mount.c 2013-05-31 13:45:25.000000000 +0000
6883 +++ linux-3.9.4-vs2.3.6.2/fs/sysfs/mount.c 2013-05-31 14:47:11.000000000 +0000
6884 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6886 sb->s_blocksize = PAGE_CACHE_SIZE;
6887 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6888 - sb->s_magic = SYSFS_MAGIC;
6889 + sb->s_magic = SYSFS_SUPER_MAGIC;
6890 sb->s_op = &sysfs_ops;
6891 sb->s_time_gran = 1;
6893 diff -NurpP --minimal linux-3.9.4/fs/utimes.c linux-3.9.4-vs2.3.6.2/fs/utimes.c
6894 --- linux-3.9.4/fs/utimes.c 2013-02-19 13:58:49.000000000 +0000
6895 +++ linux-3.9.4-vs2.3.6.2/fs/utimes.c 2013-05-31 22:40:16.000000000 +0000
6897 #include <linux/stat.h>
6898 #include <linux/utime.h>
6899 #include <linux/syscalls.h>
6900 +#include <linux/mount.h>
6901 +#include <linux/vs_cowbl.h>
6902 #include <asm/uaccess.h>
6903 #include <asm/unistd.h>
6905 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
6908 struct iattr newattrs;
6909 - struct inode *inode = path->dentry->d_inode;
6910 + struct inode *inode;
6912 + error = cow_check_and_break(path);
6916 error = mnt_want_write(path->mnt);
6920 + inode = path->dentry->d_inode;
6922 if (times && times[0].tv_nsec == UTIME_NOW &&
6923 times[1].tv_nsec == UTIME_NOW)
6925 diff -NurpP --minimal linux-3.9.4/fs/xattr.c linux-3.9.4-vs2.3.6.2/fs/xattr.c
6926 --- linux-3.9.4/fs/xattr.c 2013-02-19 13:58:49.000000000 +0000
6927 +++ linux-3.9.4-vs2.3.6.2/fs/xattr.c 2013-05-31 14:47:11.000000000 +0000
6929 #include <linux/audit.h>
6930 #include <linux/vmalloc.h>
6931 #include <linux/posix_acl_xattr.h>
6932 +#include <linux/mount.h>
6934 #include <asm/uaccess.h>
6936 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6937 * The trusted.* namespace can only be accessed by privileged users.
6939 if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6940 - if (!capable(CAP_SYS_ADMIN))
6941 + if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6942 return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6945 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_dinode.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_dinode.h
6946 --- linux-3.9.4/fs/xfs/xfs_dinode.h 2012-12-11 03:30:57.000000000 +0000
6947 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_dinode.h 2013-05-31 14:47:11.000000000 +0000
6948 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
6949 __be32 di_nlink; /* number of links to file */
6950 __be16 di_projid_lo; /* lower part of owner's project id */
6951 __be16 di_projid_hi; /* higher part owner's project id */
6952 - __u8 di_pad[6]; /* unused, zeroed space */
6953 + __u8 di_pad[2]; /* unused, zeroed space */
6954 + __be16 di_tag; /* context tagging */
6955 + __be16 di_vflags; /* vserver specific flags */
6956 __be16 di_flushiter; /* incremented on flush */
6957 xfs_timestamp_t di_atime; /* time last accessed */
6958 xfs_timestamp_t di_mtime; /* time last modified */
6959 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
6960 #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
6961 #define XFS_DIFLAG_NODEFRAG_BIT 13 /* do not reorganize/defragment */
6962 #define XFS_DIFLAG_FILESTREAM_BIT 14 /* use filestream allocator */
6963 +#define XFS_DIFLAG_IXUNLINK_BIT 15 /* Immutable inver on unlink */
6965 #define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT)
6966 #define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT)
6967 #define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT)
6968 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
6969 #define XFS_DIFLAG_EXTSZINHERIT (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
6970 #define XFS_DIFLAG_NODEFRAG (1 << XFS_DIFLAG_NODEFRAG_BIT)
6971 #define XFS_DIFLAG_FILESTREAM (1 << XFS_DIFLAG_FILESTREAM_BIT)
6972 +#define XFS_DIFLAG_IXUNLINK (1 << XFS_DIFLAG_IXUNLINK_BIT)
6974 #ifdef CONFIG_XFS_RT
6975 #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
6976 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
6977 XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
6978 XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
6979 XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
6980 - XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
6981 + XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
6982 + XFS_DIFLAG_IXUNLINK)
6984 +#define XFS_DIVFLAG_BARRIER 0x01
6985 +#define XFS_DIVFLAG_COW 0x02
6987 #endif /* __XFS_DINODE_H__ */
6988 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_fs.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_fs.h
6989 --- linux-3.9.4/fs/xfs/xfs_fs.h 2013-02-19 13:58:49.000000000 +0000
6990 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_fs.h 2013-05-31 14:47:11.000000000 +0000
6991 @@ -67,6 +67,9 @@ struct fsxattr {
6992 #define XFS_XFLAG_EXTSZINHERIT 0x00001000 /* inherit inode extent size */
6993 #define XFS_XFLAG_NODEFRAG 0x00002000 /* do not defragment */
6994 #define XFS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */
6995 +#define XFS_XFLAG_IXUNLINK 0x00008000 /* immutable invert on unlink */
6996 +#define XFS_XFLAG_BARRIER 0x10000000 /* chroot() barrier */
6997 +#define XFS_XFLAG_COW 0x20000000 /* copy on write mark */
6998 #define XFS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
7001 @@ -303,7 +306,8 @@ typedef struct xfs_bstat {
7002 #define bs_projid bs_projid_lo /* (previously just bs_projid) */
7003 __u16 bs_forkoff; /* inode fork offset in bytes */
7004 __u16 bs_projid_hi; /* higher part of project id */
7005 - unsigned char bs_pad[10]; /* pad space, unused */
7006 + unsigned char bs_pad[8]; /* pad space, unused */
7007 + __u16 bs_tag; /* context tagging */
7008 __u32 bs_dmevmask; /* DMIG event mask */
7009 __u16 bs_dmstate; /* DMIG state info */
7010 __u16 bs_aextents; /* attribute number of extents */
7011 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ialloc.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ialloc.c
7012 --- linux-3.9.4/fs/xfs/xfs_ialloc.c 2013-05-31 13:45:25.000000000 +0000
7013 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ialloc.c 2013-05-31 14:47:11.000000000 +0000
7015 #include "xfs_error.h"
7016 #include "xfs_bmap.h"
7020 * Allocation group level functions.
7022 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_inode.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_inode.c
7023 --- linux-3.9.4/fs/xfs/xfs_inode.c 2013-05-31 13:45:25.000000000 +0000
7024 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_inode.c 2013-05-31 14:47:11.000000000 +0000
7026 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7028 #include <linux/log2.h>
7029 +#include <linux/vs_tag.h>
7033 @@ -835,15 +836,25 @@ xfs_iformat_btree(
7035 xfs_dinode_from_disk(
7037 - xfs_dinode_t *from)
7038 + xfs_dinode_t *from,
7041 + uint32_t uid, gid, tag;
7043 to->di_magic = be16_to_cpu(from->di_magic);
7044 to->di_mode = be16_to_cpu(from->di_mode);
7045 to->di_version = from ->di_version;
7046 to->di_format = from->di_format;
7047 to->di_onlink = be16_to_cpu(from->di_onlink);
7048 - to->di_uid = be32_to_cpu(from->di_uid);
7049 - to->di_gid = be32_to_cpu(from->di_gid);
7051 + uid = be32_to_cpu(from->di_uid);
7052 + gid = be32_to_cpu(from->di_gid);
7053 + tag = be16_to_cpu(from->di_tag);
7055 + to->di_uid = INOTAG_UID(tagged, uid, gid);
7056 + to->di_gid = INOTAG_GID(tagged, uid, gid);
7057 + to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7059 to->di_nlink = be32_to_cpu(from->di_nlink);
7060 to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7061 to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7062 @@ -865,21 +876,26 @@ xfs_dinode_from_disk(
7063 to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7064 to->di_dmstate = be16_to_cpu(from->di_dmstate);
7065 to->di_flags = be16_to_cpu(from->di_flags);
7066 + to->di_vflags = be16_to_cpu(from->di_vflags);
7067 to->di_gen = be32_to_cpu(from->di_gen);
7073 - xfs_icdinode_t *from)
7074 + xfs_icdinode_t *from,
7077 to->di_magic = cpu_to_be16(from->di_magic);
7078 to->di_mode = cpu_to_be16(from->di_mode);
7079 to->di_version = from ->di_version;
7080 to->di_format = from->di_format;
7081 to->di_onlink = cpu_to_be16(from->di_onlink);
7082 - to->di_uid = cpu_to_be32(from->di_uid);
7083 - to->di_gid = cpu_to_be32(from->di_gid);
7085 + to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7086 + to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7087 + to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7089 to->di_nlink = cpu_to_be32(from->di_nlink);
7090 to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7091 to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7092 @@ -901,12 +917,14 @@ xfs_dinode_to_disk(
7093 to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7094 to->di_dmstate = cpu_to_be16(from->di_dmstate);
7095 to->di_flags = cpu_to_be16(from->di_flags);
7096 + to->di_vflags = cpu_to_be16(from->di_vflags);
7097 to->di_gen = cpu_to_be32(from->di_gen);
7102 - __uint16_t di_flags)
7103 + __uint16_t di_flags,
7104 + __uint16_t di_vflags)
7108 @@ -917,6 +935,8 @@ _xfs_dic2xflags(
7109 flags |= XFS_XFLAG_PREALLOC;
7110 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7111 flags |= XFS_XFLAG_IMMUTABLE;
7112 + if (di_flags & XFS_DIFLAG_IXUNLINK)
7113 + flags |= XFS_XFLAG_IXUNLINK;
7114 if (di_flags & XFS_DIFLAG_APPEND)
7115 flags |= XFS_XFLAG_APPEND;
7116 if (di_flags & XFS_DIFLAG_SYNC)
7117 @@ -941,6 +961,10 @@ _xfs_dic2xflags(
7118 flags |= XFS_XFLAG_FILESTREAM;
7121 + if (di_vflags & XFS_DIVFLAG_BARRIER)
7122 + flags |= FS_BARRIER_FL;
7123 + if (di_vflags & XFS_DIVFLAG_COW)
7124 + flags |= FS_COW_FL;
7128 @@ -950,7 +974,7 @@ xfs_ip2xflags(
7130 xfs_icdinode_t *dic = &ip->i_d;
7132 - return _xfs_dic2xflags(dic->di_flags) |
7133 + return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7134 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7137 @@ -958,7 +982,8 @@ uint
7141 - return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7142 + return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7143 + be16_to_cpu(dip->di_vflags)) |
7144 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7147 @@ -1012,7 +1037,8 @@ xfs_iread(
7148 * Otherwise, just get the truly permanent information.
7151 - xfs_dinode_from_disk(&ip->i_d, dip);
7152 + xfs_dinode_from_disk(&ip->i_d, dip,
7153 + mp->m_flags & XFS_MOUNT_TAGGED);
7154 error = xfs_iformat(ip, dip);
7157 @@ -1199,6 +1225,7 @@ xfs_ialloc(
7158 ASSERT(ip->i_d.di_nlink == nlink);
7159 ip->i_d.di_uid = current_fsuid();
7160 ip->i_d.di_gid = current_fsgid();
7161 + ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7162 xfs_set_projid(ip, prid);
7163 memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7165 @@ -1258,6 +1285,7 @@ xfs_ialloc(
7166 ip->i_d.di_dmevmask = 0;
7167 ip->i_d.di_dmstate = 0;
7168 ip->i_d.di_flags = 0;
7169 + ip->i_d.di_vflags = 0;
7170 flags = XFS_ILOG_CORE;
7171 switch (mode & S_IFMT) {
7173 @@ -1952,6 +1980,7 @@ xfs_ifree(
7175 ip->i_d.di_mode = 0; /* mark incore inode as free */
7176 ip->i_d.di_flags = 0;
7177 + ip->i_d.di_vflags = 0;
7178 ip->i_d.di_dmevmask = 0;
7179 ip->i_d.di_forkoff = 0; /* mark the attr fork not in use */
7180 ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7181 @@ -2118,7 +2147,6 @@ xfs_iroot_realloc(
7187 * This is called when the amount of space needed for if_data
7188 * is increased or decreased. The change in size is indicated by
7189 @@ -2800,7 +2828,8 @@ xfs_iflush_int(
7190 * because if the inode is dirty at all the core must
7193 - xfs_dinode_to_disk(dip, &ip->i_d);
7194 + xfs_dinode_to_disk(dip, &ip->i_d,
7195 + mp->m_flags & XFS_MOUNT_TAGGED);
7197 /* Wrap, we never let the log put out DI_MAX_FLUSH */
7198 if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7199 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_inode.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_inode.h
7200 --- linux-3.9.4/fs/xfs/xfs_inode.h 2013-05-31 13:45:25.000000000 +0000
7201 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_inode.h 2013-05-31 14:47:11.000000000 +0000
7202 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7203 __uint32_t di_nlink; /* number of links to file */
7204 __uint16_t di_projid_lo; /* lower part of owner's project id */
7205 __uint16_t di_projid_hi; /* higher part of owner's project id */
7206 - __uint8_t di_pad[6]; /* unused, zeroed space */
7207 + __uint8_t di_pad[2]; /* unused, zeroed space */
7208 + __uint16_t di_tag; /* context tagging */
7209 + __uint16_t di_vflags; /* vserver specific flags */
7210 __uint16_t di_flushiter; /* incremented on flush */
7211 xfs_ictimestamp_t di_atime; /* time last accessed */
7212 xfs_ictimestamp_t di_mtime; /* time last modified */
7213 @@ -556,7 +558,7 @@ int xfs_imap_to_bp(struct xfs_mount *,
7214 int xfs_iread(struct xfs_mount *, struct xfs_trans *,
7215 struct xfs_inode *, uint);
7216 void xfs_dinode_to_disk(struct xfs_dinode *,
7217 - struct xfs_icdinode *);
7218 + struct xfs_icdinode *, int);
7219 void xfs_idestroy_fork(struct xfs_inode *, int);
7220 void xfs_idata_realloc(struct xfs_inode *, int, int);
7221 void xfs_iroot_realloc(struct xfs_inode *, int, int);
7222 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ioctl.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ioctl.c
7223 --- linux-3.9.4/fs/xfs/xfs_ioctl.c 2013-05-31 13:45:25.000000000 +0000
7224 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ioctl.c 2013-05-31 14:47:11.000000000 +0000
7226 #include "xfs_bmap_btree.h"
7227 #include "xfs_dinode.h"
7228 #include "xfs_inode.h"
7229 -#include "xfs_ioctl.h"
7230 +// #include "xfs_ioctl.h"
7231 #include "xfs_rtalloc.h"
7232 #include "xfs_itable.h"
7233 #include "xfs_error.h"
7234 @@ -763,6 +763,10 @@ xfs_merge_ioc_xflags(
7235 xflags |= XFS_XFLAG_IMMUTABLE;
7237 xflags &= ~XFS_XFLAG_IMMUTABLE;
7238 + if (flags & FS_IXUNLINK_FL)
7239 + xflags |= XFS_XFLAG_IXUNLINK;
7241 + xflags &= ~XFS_XFLAG_IXUNLINK;
7242 if (flags & FS_APPEND_FL)
7243 xflags |= XFS_XFLAG_APPEND;
7245 @@ -791,6 +795,8 @@ xfs_di2lxflags(
7247 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7248 flags |= FS_IMMUTABLE_FL;
7249 + if (di_flags & XFS_DIFLAG_IXUNLINK)
7250 + flags |= FS_IXUNLINK_FL;
7251 if (di_flags & XFS_DIFLAG_APPEND)
7252 flags |= FS_APPEND_FL;
7253 if (di_flags & XFS_DIFLAG_SYNC)
7254 @@ -851,6 +857,8 @@ xfs_set_diflags(
7255 di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7256 if (xflags & XFS_XFLAG_IMMUTABLE)
7257 di_flags |= XFS_DIFLAG_IMMUTABLE;
7258 + if (xflags & XFS_XFLAG_IXUNLINK)
7259 + di_flags |= XFS_DIFLAG_IXUNLINK;
7260 if (xflags & XFS_XFLAG_APPEND)
7261 di_flags |= XFS_DIFLAG_APPEND;
7262 if (xflags & XFS_XFLAG_SYNC)
7263 @@ -893,6 +901,10 @@ xfs_diflags_to_linux(
7264 inode->i_flags |= S_IMMUTABLE;
7266 inode->i_flags &= ~S_IMMUTABLE;
7267 + if (xflags & XFS_XFLAG_IXUNLINK)
7268 + inode->i_flags |= S_IXUNLINK;
7270 + inode->i_flags &= ~S_IXUNLINK;
7271 if (xflags & XFS_XFLAG_APPEND)
7272 inode->i_flags |= S_APPEND;
7274 @@ -1397,10 +1409,18 @@ xfs_file_ioctl(
7275 case XFS_IOC_FSGETXATTRA:
7276 return xfs_ioc_fsgetxattr(ip, 1, arg);
7277 case XFS_IOC_FSSETXATTR:
7278 + if (IS_BARRIER(inode)) {
7279 + vxwprintk_task(1, "messing with the barrier.");
7280 + return -XFS_ERROR(EACCES);
7282 return xfs_ioc_fssetxattr(ip, filp, arg);
7283 case XFS_IOC_GETXFLAGS:
7284 return xfs_ioc_getxflags(ip, arg);
7285 case XFS_IOC_SETXFLAGS:
7286 + if (IS_BARRIER(inode)) {
7287 + vxwprintk_task(1, "messing with the barrier.");
7288 + return -XFS_ERROR(EACCES);
7290 return xfs_ioc_setxflags(ip, filp, arg);
7292 case XFS_IOC_FSSETDM: {
7293 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ioctl.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ioctl.h
7294 --- linux-3.9.4/fs/xfs/xfs_ioctl.h 2012-12-11 03:30:57.000000000 +0000
7295 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ioctl.h 2013-05-31 14:47:11.000000000 +0000
7296 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7297 void __user *uhandle,
7302 + struct inode *inode,
7309 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_iops.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_iops.c
7310 --- linux-3.9.4/fs/xfs/xfs_iops.c 2013-02-19 13:58:49.000000000 +0000
7311 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_iops.c 2013-05-31 14:47:11.000000000 +0000
7313 #include "xfs_bmap_btree.h"
7314 #include "xfs_dinode.h"
7315 #include "xfs_inode.h"
7316 +#include "xfs_ioctl.h"
7317 #include "xfs_bmap.h"
7318 #include "xfs_rtalloc.h"
7319 #include "xfs_error.h"
7321 #include <linux/security.h>
7322 #include <linux/fiemap.h>
7323 #include <linux/slab.h>
7324 +#include <linux/vs_tag.h>
7328 @@ -422,6 +424,7 @@ xfs_vn_getattr(
7329 stat->nlink = ip->i_d.di_nlink;
7330 stat->uid = ip->i_d.di_uid;
7331 stat->gid = ip->i_d.di_gid;
7332 + stat->tag = ip->i_d.di_tag;
7333 stat->ino = ip->i_ino;
7334 stat->atime = inode->i_atime;
7335 stat->mtime = inode->i_mtime;
7336 @@ -1037,6 +1040,7 @@ static const struct inode_operations xfs
7337 .listxattr = xfs_vn_listxattr,
7338 .fiemap = xfs_vn_fiemap,
7339 .update_time = xfs_vn_update_time,
7340 + .sync_flags = xfs_sync_flags,
7343 static const struct inode_operations xfs_dir_inode_operations = {
7344 @@ -1063,6 +1067,7 @@ static const struct inode_operations xfs
7345 .removexattr = generic_removexattr,
7346 .listxattr = xfs_vn_listxattr,
7347 .update_time = xfs_vn_update_time,
7348 + .sync_flags = xfs_sync_flags,
7351 static const struct inode_operations xfs_dir_ci_inode_operations = {
7352 @@ -1114,6 +1119,10 @@ xfs_diflags_to_iflags(
7353 inode->i_flags |= S_IMMUTABLE;
7355 inode->i_flags &= ~S_IMMUTABLE;
7356 + if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7357 + inode->i_flags |= S_IXUNLINK;
7359 + inode->i_flags &= ~S_IXUNLINK;
7360 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7361 inode->i_flags |= S_APPEND;
7363 @@ -1126,6 +1135,15 @@ xfs_diflags_to_iflags(
7364 inode->i_flags |= S_NOATIME;
7366 inode->i_flags &= ~S_NOATIME;
7368 + if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7369 + inode->i_vflags |= V_BARRIER;
7371 + inode->i_vflags &= ~V_BARRIER;
7372 + if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7373 + inode->i_vflags |= V_COW;
7375 + inode->i_vflags &= ~V_COW;
7379 @@ -1157,6 +1175,7 @@ xfs_setup_inode(
7380 set_nlink(inode, ip->i_d.di_nlink);
7381 inode->i_uid = ip->i_d.di_uid;
7382 inode->i_gid = ip->i_d.di_gid;
7383 + inode->i_tag = ip->i_d.di_tag;
7385 switch (inode->i_mode & S_IFMT) {
7387 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_itable.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_itable.c
7388 --- linux-3.9.4/fs/xfs/xfs_itable.c 2013-02-19 13:58:49.000000000 +0000
7389 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_itable.c 2013-05-31 14:47:11.000000000 +0000
7390 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
7391 buf->bs_mode = dic->di_mode;
7392 buf->bs_uid = dic->di_uid;
7393 buf->bs_gid = dic->di_gid;
7394 + buf->bs_tag = dic->di_tag;
7395 buf->bs_size = dic->di_size;
7396 buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7397 buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7398 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_linux.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_linux.h
7399 --- linux-3.9.4/fs/xfs/xfs_linux.h 2013-02-19 13:58:49.000000000 +0000
7400 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_linux.h 2013-05-31 14:47:11.000000000 +0000
7403 #define current_cpu() (raw_smp_processor_id())
7404 #define current_pid() (current->pid)
7405 +#define current_fstag(vp) (dx_current_fstag((vp)->i_sb))
7406 #define current_test_flags(f) (current->flags & (f))
7407 #define current_set_flags_nested(sp, f) \
7408 (*(sp) = current->flags, current->flags |= (f))
7409 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_log_recover.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_log_recover.c
7410 --- linux-3.9.4/fs/xfs/xfs_log_recover.c 2013-05-31 13:45:25.000000000 +0000
7411 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_log_recover.c 2013-05-31 14:47:11.000000000 +0000
7412 @@ -2361,7 +2361,8 @@ xlog_recover_inode_pass2(
7415 /* The core is in in-core format */
7416 - xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7417 + xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7418 + mp->m_flags & XFS_MOUNT_TAGGED);
7420 /* the rest is in on-disk format */
7421 if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7422 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_mount.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_mount.h
7423 --- linux-3.9.4/fs/xfs/xfs_mount.h 2013-05-31 13:45:25.000000000 +0000
7424 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_mount.h 2013-05-31 14:47:11.000000000 +0000
7425 @@ -254,6 +254,7 @@ typedef struct xfs_mount {
7427 #define XFS_MOUNT_NOATTR2 (1ULL << 25) /* disable use of attr2 format */
7429 +#define XFS_MOUNT_TAGGED (1ULL << 31) /* context tagging */
7432 * Default minimum read and write sizes.
7433 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_super.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_super.c
7434 --- linux-3.9.4/fs/xfs/xfs_super.c 2013-05-31 13:45:25.000000000 +0000
7435 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_super.c 2013-05-31 14:47:11.000000000 +0000
7436 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7437 #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed logging disabled */
7438 #define MNTOPT_DISCARD "discard" /* Discard unused blocks */
7439 #define MNTOPT_NODISCARD "nodiscard" /* Do not discard unused blocks */
7440 +#define MNTOPT_TAGXID "tagxid" /* context tagging for inodes */
7441 +#define MNTOPT_TAGGED "tag" /* context tagging for inodes */
7442 +#define MNTOPT_NOTAGTAG "notag" /* do not use context tagging */
7445 * Table driven mount option parser.
7446 @@ -126,6 +129,8 @@ enum {
7455 @@ -134,6 +139,9 @@ static const match_table_t tokens = {
7456 {Opt_nobarrier, "nobarrier"},
7457 {Opt_inode64, "inode64"},
7458 {Opt_inode32, "inode32"},
7459 + {Opt_tag, "tagxid"},
7461 + {Opt_notag, "notag"},
7465 @@ -392,6 +400,19 @@ xfs_parseargs(
7466 } else if (!strcmp(this_char, "irixsgid")) {
7468 "irixsgid is now a sysctl(2) variable, option is deprecated.");
7469 +#ifndef CONFIG_TAGGING_NONE
7470 + } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7471 + mp->m_flags |= XFS_MOUNT_TAGGED;
7472 + } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7473 + mp->m_flags &= ~XFS_MOUNT_TAGGED;
7474 + } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7475 + mp->m_flags |= XFS_MOUNT_TAGGED;
7477 +#ifdef CONFIG_PROPAGATE
7478 + } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7480 + mp->m_flags |= XFS_MOUNT_TAGGED;
7483 xfs_warn(mp, "unknown mount option [%s].", this_char);
7485 @@ -1238,6 +1259,16 @@ xfs_fs_remount(
7487 mp->m_maxagi = xfs_set_inode32(mp);
7490 + if (!(sb->s_flags & MS_TAGGED)) {
7492 + "XFS: %s: tagging not permitted on remount.\n",
7501 * Logically we would return an error here to prevent
7502 @@ -1458,6 +1489,9 @@ xfs_fs_fill_super(
7506 + if (mp->m_flags & XFS_MOUNT_TAGGED)
7507 + sb->s_flags |= MS_TAGGED;
7510 * we must configure the block size in the superblock before we run the
7511 * full mount process as the mount process can lookup and cache inodes.
7512 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_vnodeops.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_vnodeops.c
7513 --- linux-3.9.4/fs/xfs/xfs_vnodeops.c 2013-05-31 13:45:25.000000000 +0000
7514 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_vnodeops.c 2013-05-31 14:47:11.000000000 +0000
7515 @@ -104,6 +104,77 @@ xfs_readlink_bmap(
7521 +xfs_get_inode_flags(
7524 + struct inode *inode = VFS_I(ip);
7525 + unsigned int flags = inode->i_flags;
7526 + unsigned int vflags = inode->i_vflags;
7528 + if (flags & S_IMMUTABLE)
7529 + ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7531 + ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7532 + if (flags & S_IXUNLINK)
7533 + ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7535 + ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7537 + if (vflags & V_BARRIER)
7538 + ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7540 + ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7541 + if (vflags & V_COW)
7542 + ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7544 + ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7549 + struct inode *inode,
7553 + struct xfs_inode *ip = XFS_I(inode);
7554 + struct xfs_mount *mp = ip->i_mount;
7555 + struct xfs_trans *tp;
7556 + unsigned int lock_flags = 0;
7559 + tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7560 + code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7564 + xfs_ilock(ip, XFS_ILOCK_EXCL);
7565 + xfs_trans_ijoin(tp, ip, 0);
7567 + inode->i_flags = flags;
7568 + inode->i_vflags = vflags;
7569 + xfs_get_inode_flags(ip);
7571 + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7572 + xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7574 + XFS_STATS_INC(xs_ig_attrchg);
7576 + if (mp->m_flags & XFS_MOUNT_WSYNC)
7577 + xfs_trans_set_sync(tp);
7578 + code = xfs_trans_commit(tp, 0);
7579 + xfs_iunlock(ip, XFS_ILOCK_EXCL);
7583 + xfs_trans_cancel(tp, 0);
7585 + xfs_iunlock(ip, XFS_ILOCK_EXCL);
7593 diff -NurpP --minimal linux-3.9.4/include/linux/cred.h linux-3.9.4-vs2.3.6.2/include/linux/cred.h
7594 --- linux-3.9.4/include/linux/cred.h 2013-02-19 13:58:50.000000000 +0000
7595 +++ linux-3.9.4-vs2.3.6.2/include/linux/cred.h 2013-05-31 14:47:11.000000000 +0000
7596 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
7597 extern int copy_creds(struct task_struct *, unsigned long);
7598 extern const struct cred *get_task_cred(struct task_struct *);
7599 extern struct cred *cred_alloc_blank(void);
7600 +extern struct cred *__prepare_creds(const struct cred *);
7601 extern struct cred *prepare_creds(void);
7602 extern struct cred *prepare_exec_creds(void);
7603 extern int commit_creds(struct cred *);
7604 @@ -196,6 +197,31 @@ static inline void validate_process_cred
7608 +static inline void set_cred_subscribers(struct cred *cred, int n)
7610 +#ifdef CONFIG_DEBUG_CREDENTIALS
7611 + atomic_set(&cred->subscribers, n);
7615 +static inline int read_cred_subscribers(const struct cred *cred)
7617 +#ifdef CONFIG_DEBUG_CREDENTIALS
7618 + return atomic_read(&cred->subscribers);
7624 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7626 +#ifdef CONFIG_DEBUG_CREDENTIALS
7627 + struct cred *cred = (struct cred *) _cred;
7629 + atomic_add(n, &cred->subscribers);
7634 * get_new_cred - Get a reference on a new set of credentials
7635 * @cred: The new credentials to reference
7636 diff -NurpP --minimal linux-3.9.4/include/linux/devpts_fs.h linux-3.9.4-vs2.3.6.2/include/linux/devpts_fs.h
7637 --- linux-3.9.4/include/linux/devpts_fs.h 2013-02-19 13:58:50.000000000 +0000
7638 +++ linux-3.9.4-vs2.3.6.2/include/linux/devpts_fs.h 2013-05-31 14:47:11.000000000 +0000
7639 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7644 #endif /* _LINUX_DEVPTS_FS_H */
7645 diff -NurpP --minimal linux-3.9.4/include/linux/fs.h linux-3.9.4-vs2.3.6.2/include/linux/fs.h
7646 --- linux-3.9.4/include/linux/fs.h 2013-05-31 13:45:27.000000000 +0000
7647 +++ linux-3.9.4-vs2.3.6.2/include/linux/fs.h 2013-05-31 14:47:11.000000000 +0000
7648 @@ -211,6 +211,7 @@ typedef void (dio_iodone_t)(struct kiocb
7649 #define ATTR_KILL_PRIV (1 << 14)
7650 #define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */
7651 #define ATTR_TIMES_SET (1 << 16)
7652 +#define ATTR_TAG (1 << 17)
7655 * This is the Inode Attributes structure, used for notify_change(). It
7656 @@ -226,6 +227,7 @@ struct iattr {
7662 struct timespec ia_atime;
7663 struct timespec ia_mtime;
7664 @@ -523,7 +525,9 @@ struct inode {
7665 unsigned short i_opflags;
7668 - unsigned int i_flags;
7670 + unsigned short i_flags;
7671 + unsigned short i_vflags;
7673 #ifdef CONFIG_FS_POSIX_ACL
7674 struct posix_acl *i_acl;
7675 @@ -552,6 +556,7 @@ struct inode {
7676 unsigned int __i_nlink;
7681 struct timespec i_atime;
7682 struct timespec i_mtime;
7683 @@ -702,6 +707,11 @@ static inline gid_t i_gid_read(const str
7684 return from_kgid(&init_user_ns, inode->i_gid);
7687 +static inline tag_t i_tag_read(const struct inode *inode)
7689 + return from_ktag(&init_user_ns, inode->i_tag);
7692 static inline void i_uid_write(struct inode *inode, uid_t uid)
7694 inode->i_uid = make_kuid(&init_user_ns, uid);
7695 @@ -712,14 +722,19 @@ static inline void i_gid_write(struct in
7696 inode->i_gid = make_kgid(&init_user_ns, gid);
7699 +static inline void i_tag_write(struct inode *inode, tag_t tag)
7701 + inode->i_tag = make_ktag(&init_user_ns, tag);
7704 static inline unsigned iminor(const struct inode *inode)
7706 - return MINOR(inode->i_rdev);
7707 + return MINOR(inode->i_mdev);
7710 static inline unsigned imajor(const struct inode *inode)
7712 - return MAJOR(inode->i_rdev);
7713 + return MAJOR(inode->i_mdev);
7716 extern struct block_device *I_BDEV(struct inode *inode);
7717 @@ -786,6 +801,7 @@ struct file {
7719 struct fown_struct f_owner;
7720 const struct cred *f_cred;
7722 struct file_ra_state f_ra;
7725 @@ -937,6 +953,7 @@ struct file_lock {
7726 struct file *fl_file;
7731 struct fasync_struct * fl_fasync; /* for lease break notifications */
7732 /* for lease breaks: */
7733 @@ -1567,6 +1584,7 @@ struct inode_operations {
7734 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7735 ssize_t (*listxattr) (struct dentry *, char *, size_t);
7736 int (*removexattr) (struct dentry *, const char *);
7737 + int (*sync_flags) (struct inode *, int, int);
7738 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7740 int (*update_time)(struct inode *, struct timespec *, int);
7741 @@ -1579,6 +1597,7 @@ ssize_t rw_copy_check_uvector(int type,
7742 unsigned long nr_segs, unsigned long fast_segs,
7743 struct iovec *fast_pointer,
7744 struct iovec **ret_pointer);
7745 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7747 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7748 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7749 @@ -1632,6 +1651,14 @@ struct super_operations {
7750 #define S_IMA 1024 /* Inode has an associated IMA struct */
7751 #define S_AUTOMOUNT 2048 /* Automount/referral quasi-directory */
7752 #define S_NOSEC 4096 /* no suid or xattr security attributes */
7753 +#define S_IXUNLINK 8192 /* Immutable Invert on unlink */
7755 +/* Linux-VServer related Inode flags */
7759 +#define V_BARRIER 4 /* Barrier for chroot() */
7760 +#define V_COW 8 /* Copy on Write */
7763 * Note that nosuid etc flags are inode-specific: setting some file-system
7764 @@ -1656,10 +1683,13 @@ struct super_operations {
7765 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
7766 #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7767 #define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION)
7768 +#define IS_TAGGED(inode) __IS_FLG(inode, MS_TAGGED)
7770 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
7771 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
7772 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
7773 +#define IS_IXUNLINK(inode) ((inode)->i_flags & S_IXUNLINK)
7774 +#define IS_IXORUNLINK(inode) ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7775 #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL)
7777 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
7778 @@ -1670,6 +1700,16 @@ struct super_operations {
7779 #define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT)
7780 #define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC)
7782 +#define IS_BARRIER(inode) (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7784 +#ifdef CONFIG_VSERVER_COWBL
7785 +# define IS_COW(inode) (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7786 +# define IS_COW_LINK(inode) (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7788 +# define IS_COW(inode) (0)
7789 +# define IS_COW_LINK(inode) (0)
7793 * Inode state bits. Protected by inode->i_lock
7795 @@ -1898,6 +1938,9 @@ extern int rw_verify_area(int, struct fi
7796 extern int locks_mandatory_locked(struct inode *);
7797 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7799 +#define ATTR_FLAG_BARRIER 512 /* Barrier for chroot() */
7800 +#define ATTR_FLAG_IXUNLINK 1024 /* Immutable invert on unlink */
7803 * Candidates for mandatory locking have the setgid bit set
7804 * but no group execute bit - an otherwise meaningless combination.
7805 @@ -2509,6 +2552,7 @@ extern int dcache_dir_open(struct inode
7806 extern int dcache_dir_close(struct inode *, struct file *);
7807 extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7808 extern int dcache_readdir(struct file *, void *, filldir_t);
7809 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
7810 extern int simple_setattr(struct dentry *, struct iattr *);
7811 extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7812 extern int simple_statfs(struct dentry *, struct kstatfs *);
7813 diff -NurpP --minimal linux-3.9.4/include/linux/init_task.h linux-3.9.4-vs2.3.6.2/include/linux/init_task.h
7814 --- linux-3.9.4/include/linux/init_task.h 2013-05-31 13:45:27.000000000 +0000
7815 +++ linux-3.9.4-vs2.3.6.2/include/linux/init_task.h 2013-05-31 14:53:41.000000000 +0000
7816 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7817 INIT_TASK_RCU_PREEMPT(tsk) \
7821 + .vx_info = NULL, \
7823 + .nx_info = NULL, \
7827 diff -NurpP --minimal linux-3.9.4/include/linux/ipc.h linux-3.9.4-vs2.3.6.2/include/linux/ipc.h
7828 --- linux-3.9.4/include/linux/ipc.h 2012-12-11 03:30:57.000000000 +0000
7829 +++ linux-3.9.4-vs2.3.6.2/include/linux/ipc.h 2013-05-31 14:47:11.000000000 +0000
7830 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7838 diff -NurpP --minimal linux-3.9.4/include/linux/loop.h linux-3.9.4-vs2.3.6.2/include/linux/loop.h
7839 --- linux-3.9.4/include/linux/loop.h 2013-02-19 13:58:51.000000000 +0000
7840 +++ linux-3.9.4-vs2.3.6.2/include/linux/loop.h 2013-05-31 14:47:11.000000000 +0000
7841 @@ -41,6 +41,7 @@ struct loop_device {
7842 struct loop_func_table *lo_encryption;
7844 kuid_t lo_key_owner; /* Who set the key */
7846 int (*ioctl)(struct loop_device *, int cmd,
7849 diff -NurpP --minimal linux-3.9.4/include/linux/memcontrol.h linux-3.9.4-vs2.3.6.2/include/linux/memcontrol.h
7850 --- linux-3.9.4/include/linux/memcontrol.h 2013-05-31 13:45:28.000000000 +0000
7851 +++ linux-3.9.4-vs2.3.6.2/include/linux/memcontrol.h 2013-05-31 14:47:11.000000000 +0000
7852 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
7853 extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7854 extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
7856 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7857 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7859 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7860 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7861 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7864 bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7866 diff -NurpP --minimal linux-3.9.4/include/linux/mm_types.h linux-3.9.4-vs2.3.6.2/include/linux/mm_types.h
7867 --- linux-3.9.4/include/linux/mm_types.h 2013-05-31 13:45:28.000000000 +0000
7868 +++ linux-3.9.4-vs2.3.6.2/include/linux/mm_types.h 2013-05-31 14:47:11.000000000 +0000
7869 @@ -380,6 +380,7 @@ struct mm_struct {
7871 /* Architecture-specific MM context */
7872 mm_context_t context;
7873 + struct vx_info *mm_vx_info;
7875 unsigned long flags; /* Must use atomic bitops to access the bits */
7877 diff -NurpP --minimal linux-3.9.4/include/linux/mount.h linux-3.9.4-vs2.3.6.2/include/linux/mount.h
7878 --- linux-3.9.4/include/linux/mount.h 2013-05-31 13:45:28.000000000 +0000
7879 +++ linux-3.9.4-vs2.3.6.2/include/linux/mount.h 2013-05-31 14:47:11.000000000 +0000
7880 @@ -49,6 +49,9 @@ struct mnt_namespace;
7882 #define MNT_LOCK_READONLY 0x400000
7884 +#define MNT_TAGID 0x10000
7885 +#define MNT_NOTAG 0x20000
7888 struct dentry *mnt_root; /* root of the mounted tree */
7889 struct super_block *mnt_sb; /* pointer to superblock */
7890 diff -NurpP --minimal linux-3.9.4/include/linux/net.h linux-3.9.4-vs2.3.6.2/include/linux/net.h
7891 --- linux-3.9.4/include/linux/net.h 2012-12-11 03:30:57.000000000 +0000
7892 +++ linux-3.9.4-vs2.3.6.2/include/linux/net.h 2013-05-31 14:47:11.000000000 +0000
7893 @@ -38,6 +38,7 @@ struct net;
7894 #define SOCK_PASSCRED 3
7895 #define SOCK_PASSSEC 4
7896 #define SOCK_EXTERNALLY_ALLOCATED 5
7897 +#define SOCK_USER_SOCKET 6
7899 #ifndef ARCH_HAS_SOCKET_TYPES
7901 diff -NurpP --minimal linux-3.9.4/include/linux/netdevice.h linux-3.9.4-vs2.3.6.2/include/linux/netdevice.h
7902 --- linux-3.9.4/include/linux/netdevice.h 2013-05-31 13:45:28.000000000 +0000
7903 +++ linux-3.9.4-vs2.3.6.2/include/linux/netdevice.h 2013-05-31 14:47:11.000000000 +0000
7904 @@ -1688,6 +1688,7 @@ extern void netdev_resync_ops(struct ne
7906 extern struct net_device *dev_get_by_index(struct net *net, int ifindex);
7907 extern struct net_device *__dev_get_by_index(struct net *net, int ifindex);
7908 +extern struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7909 extern struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
7910 extern int dev_restart(struct net_device *dev);
7911 #ifdef CONFIG_NETPOLL_TRAP
7912 diff -NurpP --minimal linux-3.9.4/include/linux/nsproxy.h linux-3.9.4-vs2.3.6.2/include/linux/nsproxy.h
7913 --- linux-3.9.4/include/linux/nsproxy.h 2013-02-19 13:58:51.000000000 +0000
7914 +++ linux-3.9.4-vs2.3.6.2/include/linux/nsproxy.h 2013-05-31 17:17:53.000000000 +0000
7917 #include <linux/spinlock.h>
7918 #include <linux/sched.h>
7919 +#include <linux/vserver/debug.h>
7921 struct mnt_namespace;
7922 struct uts_namespace;
7923 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
7926 int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7927 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7928 void exit_task_namespaces(struct task_struct *tsk);
7929 void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7930 void free_nsproxy(struct nsproxy *ns);
7931 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
7932 struct cred *, struct fs_struct *);
7933 int __init nsproxy_cache_init(void);
7935 -static inline void put_nsproxy(struct nsproxy *ns)
7936 +#define get_nsproxy(n) __get_nsproxy(n, __FILE__, __LINE__)
7938 +static inline void __get_nsproxy(struct nsproxy *ns,
7939 + const char *_file, int _line)
7941 - if (atomic_dec_and_test(&ns->count)) {
7944 + vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7945 + ns, atomic_read(&ns->count), _file, _line);
7946 + atomic_inc(&ns->count);
7949 -static inline void get_nsproxy(struct nsproxy *ns)
7950 +#define put_nsproxy(n) __put_nsproxy(n, __FILE__, __LINE__)
7952 +static inline void __put_nsproxy(struct nsproxy *ns,
7953 + const char *_file, int _line)
7955 - atomic_inc(&ns->count);
7956 + vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7957 + ns, atomic_read(&ns->count), _file, _line);
7958 + if (atomic_dec_and_test(&ns->count)) {
7964 diff -NurpP --minimal linux-3.9.4/include/linux/pid.h linux-3.9.4-vs2.3.6.2/include/linux/pid.h
7965 --- linux-3.9.4/include/linux/pid.h 2013-05-31 13:45:28.000000000 +0000
7966 +++ linux-3.9.4-vs2.3.6.2/include/linux/pid.h 2013-05-31 14:47:11.000000000 +0000
7967 @@ -8,7 +8,8 @@ enum pid_type
7977 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
7980 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7981 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7982 pid_t pid_vnr(struct pid *pid);
7984 #define do_each_pid_task(pid, type, task) \
7985 diff -NurpP --minimal linux-3.9.4/include/linux/proc_fs.h linux-3.9.4-vs2.3.6.2/include/linux/proc_fs.h
7986 --- linux-3.9.4/include/linux/proc_fs.h 2013-05-31 13:45:28.000000000 +0000
7987 +++ linux-3.9.4-vs2.3.6.2/include/linux/proc_fs.h 2013-05-31 14:47:11.000000000 +0000
7988 @@ -58,6 +58,7 @@ struct proc_dir_entry {
7994 const struct inode_operations *proc_iops;
7996 @@ -274,12 +275,18 @@ extern const struct proc_ns_operations p
7997 extern const struct proc_ns_operations userns_operations;
7998 extern const struct proc_ns_operations mntns_operations;
8004 int (*proc_get_link)(struct dentry *, struct path *);
8005 int (*proc_read)(struct task_struct *task, char *page);
8006 int (*proc_show)(struct seq_file *m,
8007 struct pid_namespace *ns, struct pid *pid,
8008 struct task_struct *task);
8009 + int (*proc_vs_read)(char *page);
8010 + int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8011 + int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8014 struct ctl_table_header;
8015 @@ -287,6 +294,7 @@ struct ctl_table;
8022 struct proc_dir_entry *pde;
8023 diff -NurpP --minimal linux-3.9.4/include/linux/quotaops.h linux-3.9.4-vs2.3.6.2/include/linux/quotaops.h
8024 --- linux-3.9.4/include/linux/quotaops.h 2012-12-11 03:30:57.000000000 +0000
8025 +++ linux-3.9.4-vs2.3.6.2/include/linux/quotaops.h 2013-05-31 14:47:11.000000000 +0000
8027 #define _LINUX_QUOTAOPS_
8029 #include <linux/fs.h>
8030 +#include <linux/vs_dlimit.h>
8032 #define DQUOT_SPACE_WARN 0x1
8033 #define DQUOT_SPACE_RESERVE 0x2
8034 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
8036 static inline int dquot_alloc_inode(const struct inode *inode)
8039 + return dl_alloc_inode(inode);
8042 static inline void dquot_free_inode(const struct inode *inode)
8044 + dl_free_inode(inode);
8047 static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8048 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
8049 static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8054 + if ((ret = dl_alloc_space(inode, number)))
8056 if (!(flags & DQUOT_SPACE_RESERVE))
8057 inode_add_bytes(inode, number);
8059 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
8061 if (!(flags & DQUOT_SPACE_RESERVE))
8062 inode_sub_bytes(inode, number);
8063 + dl_free_space(inode, number);
8066 static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8067 diff -NurpP --minimal linux-3.9.4/include/linux/sched.h linux-3.9.4-vs2.3.6.2/include/linux/sched.h
8068 --- linux-3.9.4/include/linux/sched.h 2013-05-31 14:22:27.000000000 +0000
8069 +++ linux-3.9.4-vs2.3.6.2/include/linux/sched.h 2013-05-31 14:47:11.000000000 +0000
8070 @@ -1398,6 +1398,14 @@ struct task_struct {
8072 struct seccomp seccomp;
8074 +/* vserver context data */
8075 + struct vx_info *vx_info;
8076 + struct nx_info *nx_info;
8082 /* Thread group tracking */
8085 @@ -1637,6 +1645,11 @@ struct pid_namespace;
8086 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8087 struct pid_namespace *ns);
8089 +#include <linux/vserver/base.h>
8090 +#include <linux/vserver/context.h>
8091 +#include <linux/vserver/debug.h>
8092 +#include <linux/vserver/pid.h>
8094 static inline pid_t task_pid_nr(struct task_struct *tsk)
8097 @@ -1650,7 +1663,8 @@ static inline pid_t task_pid_nr_ns(struc
8099 static inline pid_t task_pid_vnr(struct task_struct *tsk)
8101 - return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8102 + // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8103 + return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8107 @@ -1663,7 +1677,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8109 static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8111 - return pid_vnr(task_tgid(tsk));
8112 + return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8116 diff -NurpP --minimal linux-3.9.4/include/linux/shmem_fs.h linux-3.9.4-vs2.3.6.2/include/linux/shmem_fs.h
8117 --- linux-3.9.4/include/linux/shmem_fs.h 2012-12-11 03:30:57.000000000 +0000
8118 +++ linux-3.9.4-vs2.3.6.2/include/linux/shmem_fs.h 2013-05-31 14:47:11.000000000 +0000
8121 /* inode in-kernel data */
8123 +#define TMPFS_SUPER_MAGIC 0x01021994
8126 struct shmem_inode_info {
8128 unsigned long flags;
8129 diff -NurpP --minimal linux-3.9.4/include/linux/stat.h linux-3.9.4-vs2.3.6.2/include/linux/stat.h
8130 --- linux-3.9.4/include/linux/stat.h 2012-12-11 03:30:57.000000000 +0000
8131 +++ linux-3.9.4-vs2.3.6.2/include/linux/stat.h 2013-06-01 08:53:13.000000000 +0000
8132 @@ -25,6 +25,7 @@ struct kstat {
8139 struct timespec atime;
8140 diff -NurpP --minimal linux-3.9.4/include/linux/sunrpc/auth.h linux-3.9.4-vs2.3.6.2/include/linux/sunrpc/auth.h
8141 --- linux-3.9.4/include/linux/sunrpc/auth.h 2013-05-31 13:45:28.000000000 +0000
8142 +++ linux-3.9.4-vs2.3.6.2/include/linux/sunrpc/auth.h 2013-05-31 14:52:57.000000000 +0000
8148 struct group_info *group_info;
8149 const char *principal;
8150 unsigned char machine_cred : 1;
8151 diff -NurpP --minimal linux-3.9.4/include/linux/sunrpc/clnt.h linux-3.9.4-vs2.3.6.2/include/linux/sunrpc/clnt.h
8152 --- linux-3.9.4/include/linux/sunrpc/clnt.h 2013-05-31 13:45:28.000000000 +0000
8153 +++ linux-3.9.4-vs2.3.6.2/include/linux/sunrpc/clnt.h 2013-05-31 14:47:11.000000000 +0000
8154 @@ -49,7 +49,8 @@ struct rpc_clnt {
8155 unsigned int cl_softrtry : 1,/* soft timeouts */
8156 cl_discrtry : 1,/* disconnect before retry */
8157 cl_autobind : 1,/* use getport() */
8158 - cl_chatty : 1;/* be verbose */
8159 + cl_chatty : 1,/* be verbose */
8160 + cl_tag : 1;/* context tagging */
8162 struct rpc_rtt * cl_rtt; /* RTO estimator data */
8163 const struct rpc_timeout *cl_timeout; /* Timeout strategy */
8164 diff -NurpP --minimal linux-3.9.4/include/linux/sysfs.h linux-3.9.4-vs2.3.6.2/include/linux/sysfs.h
8165 --- linux-3.9.4/include/linux/sysfs.h 2013-05-31 13:45:28.000000000 +0000
8166 +++ linux-3.9.4-vs2.3.6.2/include/linux/sysfs.h 2013-05-31 14:47:11.000000000 +0000
8168 #include <linux/kobject_ns.h>
8169 #include <linux/atomic.h>
8171 +#define SYSFS_SUPER_MAGIC 0x62656572
8176 diff -NurpP --minimal linux-3.9.4/include/linux/types.h linux-3.9.4-vs2.3.6.2/include/linux/types.h
8177 --- linux-3.9.4/include/linux/types.h 2013-02-19 13:58:52.000000000 +0000
8178 +++ linux-3.9.4-vs2.3.6.2/include/linux/types.h 2013-05-31 14:47:11.000000000 +0000
8179 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t uid_t;
8180 typedef __kernel_gid32_t gid_t;
8181 typedef __kernel_uid16_t uid16_t;
8182 typedef __kernel_gid16_t gid16_t;
8183 +typedef unsigned int xid_t;
8184 +typedef unsigned int nid_t;
8185 +typedef unsigned int tag_t;
8187 typedef unsigned long uintptr_t;
8189 diff -NurpP --minimal linux-3.9.4/include/linux/uidgid.h linux-3.9.4-vs2.3.6.2/include/linux/uidgid.h
8190 --- linux-3.9.4/include/linux/uidgid.h 2012-12-11 03:30:57.000000000 +0000
8191 +++ linux-3.9.4-vs2.3.6.2/include/linux/uidgid.h 2013-05-31 14:47:11.000000000 +0000
8192 @@ -23,13 +23,17 @@ typedef struct {
8205 #define KUIDT_INIT(value) (kuid_t){ value }
8206 #define KGIDT_INIT(value) (kgid_t){ value }
8207 +#define KTAGT_INIT(value) (ktag_t){ value }
8209 static inline uid_t __kuid_val(kuid_t uid)
8211 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
8215 +static inline tag_t __ktag_val(ktag_t tag)
8222 typedef uid_t kuid_t;
8223 typedef gid_t kgid_t;
8224 +typedef tag_t ktag_t;
8226 static inline uid_t __kuid_val(kuid_t uid)
8228 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
8232 +static inline tag_t __ktag_val(ktag_t tag)
8237 #define KUIDT_INIT(value) ((kuid_t) value )
8238 #define KGIDT_INIT(value) ((kgid_t) value )
8239 +#define KTAGT_INIT(value) ((ktag_t) value )
8243 #define GLOBAL_ROOT_UID KUIDT_INIT(0)
8244 #define GLOBAL_ROOT_GID KGIDT_INIT(0)
8245 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
8247 #define INVALID_UID KUIDT_INIT(-1)
8248 #define INVALID_GID KGIDT_INIT(-1)
8249 +#define INVALID_TAG KTAGT_INIT(-1)
8251 static inline bool uid_eq(kuid_t left, kuid_t right)
8253 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
8254 return __kgid_val(left) == __kgid_val(right);
8257 +static inline bool tag_eq(ktag_t left, ktag_t right)
8259 + return __ktag_val(left) == __ktag_val(right);
8262 static inline bool uid_gt(kuid_t left, kuid_t right)
8264 return __kuid_val(left) > __kuid_val(right);
8265 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
8266 return !gid_eq(gid, INVALID_GID);
8269 +static inline bool tag_valid(ktag_t tag)
8271 + return !tag_eq(tag, INVALID_TAG);
8274 #ifdef CONFIG_USER_NS
8276 extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
8277 extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
8278 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
8280 extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
8281 extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
8282 +extern tag_t from_ktag(struct user_namespace *to, ktag_t tag);
8284 extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
8285 extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
8287 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
8288 return KGIDT_INIT(gid);
8291 +static inline ktag_t make_ktag(struct user_namespace *from, tag_t tag)
8293 + return KTAGT_INIT(tag);
8296 static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
8298 return __kuid_val(kuid);
8299 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
8300 return __kgid_val(kgid);
8303 +static inline tag_t from_ktag(struct user_namespace *to, ktag_t ktag)
8305 + return __ktag_val(ktag);
8308 static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
8310 uid_t uid = from_kuid(to, kuid);
8311 diff -NurpP --minimal linux-3.9.4/include/linux/vroot.h linux-3.9.4-vs2.3.6.2/include/linux/vroot.h
8312 --- linux-3.9.4/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
8313 +++ linux-3.9.4-vs2.3.6.2/include/linux/vroot.h 2013-05-31 14:47:11.000000000 +0000
8317 + * include/linux/vroot.h
8319 + * written by Herbert Pötzl, 9/11/2002
8320 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8322 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8323 + * Redistribution of this file is permitted under the
8324 + * GNU General Public License.
8327 +#ifndef _LINUX_VROOT_H
8328 +#define _LINUX_VROOT_H
8333 +/* Possible states of device */
8339 +struct vroot_device {
8343 + struct semaphore vr_ctl_mutex;
8344 + struct block_device *vr_device;
8349 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8351 +extern int register_vroot_grb(vroot_grb_func *);
8352 +extern int unregister_vroot_grb(vroot_grb_func *);
8354 +#endif /* __KERNEL__ */
8356 +#define MAX_VROOT_DEFAULT 8
8359 + * IOCTL commands --- we will commandeer 0x56 ('V')
8362 +#define VROOT_SET_DEV 0x5600
8363 +#define VROOT_CLR_DEV 0x5601
8365 +#endif /* _LINUX_VROOT_H */
8366 diff -NurpP --minimal linux-3.9.4/include/linux/vs_base.h linux-3.9.4-vs2.3.6.2/include/linux/vs_base.h
8367 --- linux-3.9.4/include/linux/vs_base.h 1970-01-01 00:00:00.000000000 +0000
8368 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_base.h 2013-05-31 14:47:11.000000000 +0000
8373 +#include "vserver/base.h"
8374 +#include "vserver/check.h"
8375 +#include "vserver/debug.h"
8378 +#warning duplicate inclusion
8380 diff -NurpP --minimal linux-3.9.4/include/linux/vs_context.h linux-3.9.4-vs2.3.6.2/include/linux/vs_context.h
8381 --- linux-3.9.4/include/linux/vs_context.h 1970-01-01 00:00:00.000000000 +0000
8382 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_context.h 2013-05-31 14:47:11.000000000 +0000
8384 +#ifndef _VS_CONTEXT_H
8385 +#define _VS_CONTEXT_H
8387 +#include "vserver/base.h"
8388 +#include "vserver/check.h"
8389 +#include "vserver/context.h"
8390 +#include "vserver/history.h"
8391 +#include "vserver/debug.h"
8393 +#include <linux/sched.h>
8396 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8398 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8399 + const char *_file, int _line, void *_here)
8404 + vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8405 + vxi, vxi ? vxi->vx_id : 0,
8406 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8408 + __vxh_get_vx_info(vxi, _here);
8410 + atomic_inc(&vxi->vx_usecnt);
8415 +extern void free_vx_info(struct vx_info *);
8417 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8419 +static inline void __put_vx_info(struct vx_info *vxi,
8420 + const char *_file, int _line, void *_here)
8425 + vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8426 + vxi, vxi ? vxi->vx_id : 0,
8427 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8429 + __vxh_put_vx_info(vxi, _here);
8431 + if (atomic_dec_and_test(&vxi->vx_usecnt))
8432 + free_vx_info(vxi);
8436 +#define init_vx_info(p, i) \
8437 + __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8439 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8440 + const char *_file, int _line, void *_here)
8443 + vxlprintk(VXD_CBIT(xid, 3),
8444 + "init_vx_info(%p[#%d.%d])",
8445 + vxi, vxi ? vxi->vx_id : 0,
8446 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8448 + __vxh_init_vx_info(vxi, vxp, _here);
8450 + atomic_inc(&vxi->vx_usecnt);
8456 +#define set_vx_info(p, i) \
8457 + __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8459 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8460 + const char *_file, int _line, void *_here)
8462 + struct vx_info *vxo;
8467 + vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8468 + vxi, vxi ? vxi->vx_id : 0,
8469 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8471 + __vxh_set_vx_info(vxi, vxp, _here);
8473 + atomic_inc(&vxi->vx_usecnt);
8474 + vxo = xchg(vxp, vxi);
8479 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8481 +static inline void __clr_vx_info(struct vx_info **vxp,
8482 + const char *_file, int _line, void *_here)
8484 + struct vx_info *vxo;
8486 + vxo = xchg(vxp, NULL);
8490 + vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8491 + vxo, vxo ? vxo->vx_id : 0,
8492 + vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8494 + __vxh_clr_vx_info(vxo, vxp, _here);
8496 + if (atomic_dec_and_test(&vxo->vx_usecnt))
8497 + free_vx_info(vxo);
8501 +#define claim_vx_info(v, p) \
8502 + __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8504 +static inline void __claim_vx_info(struct vx_info *vxi,
8505 + struct task_struct *task,
8506 + const char *_file, int _line, void *_here)
8508 + vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8509 + vxi, vxi ? vxi->vx_id : 0,
8510 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8511 + vxi ? atomic_read(&vxi->vx_tasks) : 0,
8512 + task, _file, _line);
8513 + __vxh_claim_vx_info(vxi, task, _here);
8515 + atomic_inc(&vxi->vx_tasks);
8519 +extern void unhash_vx_info(struct vx_info *);
8521 +#define release_vx_info(v, p) \
8522 + __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8524 +static inline void __release_vx_info(struct vx_info *vxi,
8525 + struct task_struct *task,
8526 + const char *_file, int _line, void *_here)
8528 + vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8529 + vxi, vxi ? vxi->vx_id : 0,
8530 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8531 + vxi ? atomic_read(&vxi->vx_tasks) : 0,
8532 + task, _file, _line);
8533 + __vxh_release_vx_info(vxi, task, _here);
8537 + if (atomic_dec_and_test(&vxi->vx_tasks))
8538 + unhash_vx_info(vxi);
8542 +#define task_get_vx_info(p) \
8543 + __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8545 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8546 + const char *_file, int _line, void *_here)
8548 + struct vx_info *vxi;
8551 + vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8553 + vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8559 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8561 + if (waitqueue_active(&vxi->vx_wait))
8562 + wake_up_interruptible(&vxi->vx_wait);
8566 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8568 +static inline void __enter_vx_info(struct vx_info *vxi,
8569 + struct vx_info_save *vxis, const char *_file, int _line)
8571 + vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8572 + vxi, vxi ? vxi->vx_id : 0, vxis, current,
8573 + current->xid, current->vx_info, _file, _line);
8574 + vxis->vxi = xchg(¤t->vx_info, vxi);
8575 + vxis->xid = current->xid;
8576 + current->xid = vxi ? vxi->vx_id : 0;
8579 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8581 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8582 + const char *_file, int _line)
8584 + vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8585 + vxis, vxis->xid, vxis->vxi, current,
8586 + current->xid, current->vx_info, _file, _line);
8587 + (void)xchg(¤t->vx_info, vxis->vxi);
8588 + current->xid = vxis->xid;
8592 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8594 + vxis->vxi = xchg(¤t->vx_info, NULL);
8595 + vxis->xid = xchg(¤t->xid, (xid_t)0);
8598 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8600 + (void)xchg(¤t->xid, vxis->xid);
8601 + (void)xchg(¤t->vx_info, vxis->vxi);
8604 +#define task_is_init(p) \
8605 + __task_is_init(p, __FILE__, __LINE__, __HERE__)
8607 +static inline int __task_is_init(struct task_struct *p,
8608 + const char *_file, int _line, void *_here)
8610 + int is_init = is_global_init(p);
8614 + is_init = p->vx_info->vx_initpid == p->pid;
8619 +extern void exit_vx_info(struct task_struct *, int);
8620 +extern void exit_vx_info_early(struct task_struct *, int);
8624 +#warning duplicate inclusion
8626 diff -NurpP --minimal linux-3.9.4/include/linux/vs_cowbl.h linux-3.9.4-vs2.3.6.2/include/linux/vs_cowbl.h
8627 --- linux-3.9.4/include/linux/vs_cowbl.h 1970-01-01 00:00:00.000000000 +0000
8628 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_cowbl.h 2013-05-31 14:47:11.000000000 +0000
8630 +#ifndef _VS_COWBL_H
8631 +#define _VS_COWBL_H
8633 +#include <linux/fs.h>
8634 +#include <linux/dcache.h>
8635 +#include <linux/namei.h>
8636 +#include <linux/slab.h>
8638 +extern struct dentry *cow_break_link(const char *pathname);
8640 +static inline int cow_check_and_break(struct path *path)
8642 + struct inode *inode = path->dentry->d_inode;
8645 + /* do we need this check? */
8646 + if (IS_RDONLY(inode))
8649 + if (IS_COW(inode)) {
8650 + if (IS_COW_LINK(inode)) {
8651 + struct dentry *new_dentry, *old_dentry = path->dentry;
8654 + buf = kmalloc(PATH_MAX, GFP_KERNEL);
8658 + pp = d_path(path, buf, PATH_MAX);
8659 + new_dentry = cow_break_link(pp);
8661 + if (!IS_ERR(new_dentry)) {
8662 + path->dentry = new_dentry;
8665 + error = PTR_ERR(new_dentry);
8667 + inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8668 + inode->i_ctime = CURRENT_TIME;
8669 + mark_inode_dirty(inode);
8676 +#warning duplicate inclusion
8678 diff -NurpP --minimal linux-3.9.4/include/linux/vs_cvirt.h linux-3.9.4-vs2.3.6.2/include/linux/vs_cvirt.h
8679 --- linux-3.9.4/include/linux/vs_cvirt.h 1970-01-01 00:00:00.000000000 +0000
8680 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_cvirt.h 2013-05-31 14:47:11.000000000 +0000
8682 +#ifndef _VS_CVIRT_H
8683 +#define _VS_CVIRT_H
8685 +#include "vserver/cvirt.h"
8686 +#include "vserver/context.h"
8687 +#include "vserver/base.h"
8688 +#include "vserver/check.h"
8689 +#include "vserver/debug.h"
8692 +static inline void vx_activate_task(struct task_struct *p)
8694 + struct vx_info *vxi;
8696 + if ((vxi = p->vx_info)) {
8697 + vx_update_load(vxi);
8698 + atomic_inc(&vxi->cvirt.nr_running);
8702 +static inline void vx_deactivate_task(struct task_struct *p)
8704 + struct vx_info *vxi;
8706 + if ((vxi = p->vx_info)) {
8707 + vx_update_load(vxi);
8708 + atomic_dec(&vxi->cvirt.nr_running);
8712 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8714 + struct vx_info *vxi;
8716 + if ((vxi = p->vx_info))
8717 + atomic_inc(&vxi->cvirt.nr_uninterruptible);
8720 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8722 + struct vx_info *vxi;
8724 + if ((vxi = p->vx_info))
8725 + atomic_dec(&vxi->cvirt.nr_uninterruptible);
8730 +#warning duplicate inclusion
8732 diff -NurpP --minimal linux-3.9.4/include/linux/vs_device.h linux-3.9.4-vs2.3.6.2/include/linux/vs_device.h
8733 --- linux-3.9.4/include/linux/vs_device.h 1970-01-01 00:00:00.000000000 +0000
8734 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_device.h 2013-05-31 14:47:11.000000000 +0000
8736 +#ifndef _VS_DEVICE_H
8737 +#define _VS_DEVICE_H
8739 +#include "vserver/base.h"
8740 +#include "vserver/device.h"
8741 +#include "vserver/debug.h"
8744 +#ifdef CONFIG_VSERVER_DEVICE
8746 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8748 +#define vs_device_perm(v, d, m, p) \
8749 + ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8754 +int vs_map_device(struct vx_info *vxi,
8755 + dev_t device, dev_t *target, umode_t mode)
8762 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8767 +#define vs_map_chrdev(d, t, p) \
8768 + ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8769 +#define vs_map_blkdev(d, t, p) \
8770 + ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8772 +#define vs_chrdev_perm(d, p) \
8773 + vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8774 +#define vs_blkdev_perm(d, p) \
8775 + vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8779 +#warning duplicate inclusion
8781 diff -NurpP --minimal linux-3.9.4/include/linux/vs_dlimit.h linux-3.9.4-vs2.3.6.2/include/linux/vs_dlimit.h
8782 --- linux-3.9.4/include/linux/vs_dlimit.h 1970-01-01 00:00:00.000000000 +0000
8783 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_dlimit.h 2013-05-31 14:47:11.000000000 +0000
8785 +#ifndef _VS_DLIMIT_H
8786 +#define _VS_DLIMIT_H
8788 +#include <linux/fs.h>
8790 +#include "vserver/dlimit.h"
8791 +#include "vserver/base.h"
8792 +#include "vserver/debug.h"
8795 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8797 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8798 + const char *_file, int _line)
8802 + vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8803 + dli, dli ? dli->dl_tag : 0,
8804 + dli ? atomic_read(&dli->dl_usecnt) : 0,
8806 + atomic_inc(&dli->dl_usecnt);
8811 +#define free_dl_info(i) \
8812 + call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8814 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8816 +static inline void __put_dl_info(struct dl_info *dli,
8817 + const char *_file, int _line)
8821 + vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8822 + dli, dli ? dli->dl_tag : 0,
8823 + dli ? atomic_read(&dli->dl_usecnt) : 0,
8825 + if (atomic_dec_and_test(&dli->dl_usecnt))
8826 + free_dl_info(dli);
8830 +#define __dlimit_char(d) ((d) ? '*' : ' ')
8832 +static inline int __dl_alloc_space(struct super_block *sb,
8833 + tag_t tag, dlsize_t nr, const char *file, int line)
8835 + struct dl_info *dli = NULL;
8840 + dli = locate_dl_info(sb, tag);
8844 + spin_lock(&dli->dl_lock);
8845 + ret = (dli->dl_space_used + nr > dli->dl_space_total);
8847 + dli->dl_space_used += nr;
8848 + spin_unlock(&dli->dl_lock);
8851 + vxlprintk(VXD_CBIT(dlim, 1),
8852 + "ALLOC (%p,#%d)%c %lld bytes (%d)",
8853 + sb, tag, __dlimit_char(dli), (long long)nr,
8855 + return ret ? -ENOSPC : 0;
8858 +static inline void __dl_free_space(struct super_block *sb,
8859 + tag_t tag, dlsize_t nr, const char *_file, int _line)
8861 + struct dl_info *dli = NULL;
8865 + dli = locate_dl_info(sb, tag);
8869 + spin_lock(&dli->dl_lock);
8870 + if (dli->dl_space_used > nr)
8871 + dli->dl_space_used -= nr;
8873 + dli->dl_space_used = 0;
8874 + spin_unlock(&dli->dl_lock);
8877 + vxlprintk(VXD_CBIT(dlim, 1),
8878 + "FREE (%p,#%d)%c %lld bytes",
8879 + sb, tag, __dlimit_char(dli), (long long)nr,
8883 +static inline int __dl_alloc_inode(struct super_block *sb,
8884 + tag_t tag, const char *_file, int _line)
8886 + struct dl_info *dli;
8889 + dli = locate_dl_info(sb, tag);
8893 + spin_lock(&dli->dl_lock);
8894 + dli->dl_inodes_used++;
8895 + ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8896 + spin_unlock(&dli->dl_lock);
8899 + vxlprintk(VXD_CBIT(dlim, 0),
8900 + "ALLOC (%p,#%d)%c inode (%d)",
8901 + sb, tag, __dlimit_char(dli), ret, _file, _line);
8902 + return ret ? -ENOSPC : 0;
8905 +static inline void __dl_free_inode(struct super_block *sb,
8906 + tag_t tag, const char *_file, int _line)
8908 + struct dl_info *dli;
8910 + dli = locate_dl_info(sb, tag);
8914 + spin_lock(&dli->dl_lock);
8915 + if (dli->dl_inodes_used > 1)
8916 + dli->dl_inodes_used--;
8918 + dli->dl_inodes_used = 0;
8919 + spin_unlock(&dli->dl_lock);
8922 + vxlprintk(VXD_CBIT(dlim, 0),
8923 + "FREE (%p,#%d)%c inode",
8924 + sb, tag, __dlimit_char(dli), _file, _line);
8927 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
8928 + unsigned long long *free_blocks, unsigned long long *root_blocks,
8929 + const char *_file, int _line)
8931 + struct dl_info *dli;
8932 + uint64_t broot, bfree;
8934 + dli = locate_dl_info(sb, tag);
8938 + spin_lock(&dli->dl_lock);
8939 + broot = (dli->dl_space_total -
8940 + (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8941 + >> sb->s_blocksize_bits;
8942 + bfree = (dli->dl_space_total - dli->dl_space_used)
8943 + >> sb->s_blocksize_bits;
8944 + spin_unlock(&dli->dl_lock);
8946 + vxlprintk(VXD_CBIT(dlim, 2),
8947 + "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8948 + (long long)bfree, (long long)broot,
8949 + *free_blocks, *root_blocks, dli->dl_nrlmult,
8951 + if (free_blocks) {
8952 + if (*free_blocks > bfree)
8953 + *free_blocks = bfree;
8955 + if (root_blocks) {
8956 + if (*root_blocks > broot)
8957 + *root_blocks = broot;
8962 +#define dl_prealloc_space(in, bytes) \
8963 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8964 + __FILE__, __LINE__ )
8966 +#define dl_alloc_space(in, bytes) \
8967 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8968 + __FILE__, __LINE__ )
8970 +#define dl_reserve_space(in, bytes) \
8971 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8972 + __FILE__, __LINE__ )
8974 +#define dl_claim_space(in, bytes) (0)
8976 +#define dl_release_space(in, bytes) \
8977 + __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8978 + __FILE__, __LINE__ )
8980 +#define dl_free_space(in, bytes) \
8981 + __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8982 + __FILE__, __LINE__ )
8986 +#define dl_alloc_inode(in) \
8987 + __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8989 +#define dl_free_inode(in) \
8990 + __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8993 +#define dl_adjust_block(sb, tag, fb, rb) \
8994 + __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8998 +#warning duplicate inclusion
9000 diff -NurpP --minimal linux-3.9.4/include/linux/vs_inet.h linux-3.9.4-vs2.3.6.2/include/linux/vs_inet.h
9001 --- linux-3.9.4/include/linux/vs_inet.h 1970-01-01 00:00:00.000000000 +0000
9002 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_inet.h 2013-05-31 14:47:11.000000000 +0000
9007 +#include "vserver/base.h"
9008 +#include "vserver/network.h"
9009 +#include "vserver/debug.h"
9011 +#define IPI_LOOPBACK htonl(INADDR_LOOPBACK)
9013 +#define NXAV4(a) NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9014 + NIPQUAD((a)->mask), (a)->type
9015 +#define NXAV4_FMT "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9017 +#define NIPQUAD(addr) \
9018 + ((unsigned char *)&addr)[0], \
9019 + ((unsigned char *)&addr)[1], \
9020 + ((unsigned char *)&addr)[2], \
9021 + ((unsigned char *)&addr)[3]
9023 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9027 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9029 + __be32 ip = nxa->ip[0].s_addr;
9030 + __be32 mask = nxa->mask.s_addr;
9031 + __be32 bcast = ip | ~mask;
9034 + switch (nxa->type & tmask) {
9035 + case NXA_TYPE_MASK:
9036 + ret = (ip == (addr & mask));
9038 + case NXA_TYPE_ADDR:
9042 + /* fall through to broadcast */
9043 + case NXA_MOD_BCAST:
9044 + ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9046 + case NXA_TYPE_RANGE:
9047 + ret = ((nxa->ip[0].s_addr <= addr) &&
9048 + (nxa->ip[1].s_addr > addr));
9050 + case NXA_TYPE_ANY:
9055 + vxdprintk(VXD_CBIT(net, 0),
9056 + "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9057 + nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9062 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9064 + struct nx_addr_v4 *nxa;
9065 + unsigned long irqflags;
9072 + /* allow 127.0.0.1 when remapping lback */
9073 + if ((tmask & NXA_LOOPBACK) &&
9074 + (addr == IPI_LOOPBACK) &&
9075 + nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9078 + /* check for lback address */
9079 + if ((tmask & NXA_MOD_LBACK) &&
9080 + (nxi->v4_lback.s_addr == addr))
9083 + /* check for broadcast address */
9084 + if ((tmask & NXA_MOD_BCAST) &&
9085 + (nxi->v4_bcast.s_addr == addr))
9089 + /* check for v4 addresses */
9090 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
9091 + for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9092 + if (v4_addr_match(nxa, addr, tmask))
9096 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9098 + vxdprintk(VXD_CBIT(net, 0),
9099 + "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9100 + nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9105 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9107 + /* FIXME: needs full range checks */
9108 + return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9112 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9114 + struct nx_addr_v4 *ptr;
9115 + unsigned long irqflags;
9118 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
9119 + for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9120 + if (v4_nx_addr_match(ptr, nxa, mask))
9124 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9128 +#include <net/inet_sock.h>
9131 + * Check if a given address matches for a socket
9133 + * nxi: the socket's nx_info if any
9134 + * addr: to be verified address
9137 +int v4_sock_addr_match (
9138 + struct nx_info *nxi,
9139 + struct inet_sock *inet,
9142 + __be32 saddr = inet->inet_rcv_saddr;
9143 + __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9145 + if (addr && (saddr == addr || bcast == addr))
9148 + return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9153 +/* inet related checks and helpers */
9162 +#include <linux/netdevice.h>
9163 +#include <linux/inetdevice.h>
9164 +#include <net/inet_sock.h>
9165 +#include <net/inet_timewait_sock.h>
9168 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9169 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9170 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9174 + * check if address is covered by socket
9176 + * sk: the socket to check against
9177 + * addr: the address in question (must be != 0)
9181 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9183 + struct nx_info *nxi = sk->sk_nx_info;
9184 + __be32 saddr = sk_rcv_saddr(sk);
9186 + vxdprintk(VXD_CBIT(net, 5),
9187 + "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9188 + sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9189 + (sk->sk_socket?sk->sk_socket->flags:0));
9191 + if (saddr) { /* direct address match */
9192 + return v4_addr_match(nxa, saddr, -1);
9193 + } else if (nxi) { /* match against nx_info */
9194 + return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9195 + } else { /* unrestricted any socket */
9203 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9205 + vxdprintk(VXD_CBIT(net, 1),
9206 + "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9207 + nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9208 + nxi ? dev_in_nx_info(dev, nxi) : 0);
9210 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9212 + if (dev_in_nx_info(dev, nxi))
9219 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9225 + return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9229 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9231 + vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9232 + nxi, nxi ? nxi->nx_id : 0, ifa,
9233 + nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9235 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9237 + if (v4_ifa_in_nx_info(ifa, nxi))
9243 +struct nx_v4_sock_addr {
9244 + __be32 saddr; /* Address used for validation */
9245 + __be32 baddr; /* Address used for socket bind */
9249 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9250 + struct nx_v4_sock_addr *nsa)
9252 + struct sock *sk = &inet->sk;
9253 + struct nx_info *nxi = sk->sk_nx_info;
9254 + __be32 saddr = addr->sin_addr.s_addr;
9255 + __be32 baddr = saddr;
9257 + vxdprintk(VXD_CBIT(net, 3),
9258 + "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9259 + sk, sk->sk_nx_info, sk->sk_socket,
9260 + (sk->sk_socket ? sk->sk_socket->flags : 0),
9264 + if (saddr == INADDR_ANY) {
9265 + if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9266 + baddr = nxi->v4.ip[0].s_addr;
9267 + } else if (saddr == IPI_LOOPBACK) {
9268 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9269 + baddr = nxi->v4_lback.s_addr;
9270 + } else if (!ipv4_is_multicast(saddr) ||
9271 + !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9272 + /* normal address bind */
9273 + if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9274 + return -EADDRNOTAVAIL;
9278 + vxdprintk(VXD_CBIT(net, 3),
9279 + "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9280 + sk, NIPQUAD(saddr), NIPQUAD(baddr));
9282 + nsa->saddr = saddr;
9283 + nsa->baddr = baddr;
9288 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9290 + inet->inet_saddr = nsa->baddr;
9291 + inet->inet_rcv_saddr = nsa->baddr;
9296 + * helper to simplify inet_lookup_listener
9298 + * nxi: the socket's nx_info if any
9299 + * addr: to be verified address
9300 + * saddr: socket address
9302 +static inline int v4_inet_addr_match (
9303 + struct nx_info *nxi,
9307 + if (addr && (saddr == addr))
9310 + return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9314 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9316 + if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9317 + (addr == nxi->v4_lback.s_addr))
9318 + return IPI_LOOPBACK;
9323 +int nx_info_has_v4(struct nx_info *nxi)
9329 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9334 +#else /* CONFIG_INET */
9337 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9343 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9349 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9355 +int nx_info_has_v4(struct nx_info *nxi)
9360 +#endif /* CONFIG_INET */
9362 +#define current_nx_info_has_v4() \
9363 + nx_info_has_v4(current_nx_info())
9366 +// #warning duplicate inclusion
9368 diff -NurpP --minimal linux-3.9.4/include/linux/vs_inet6.h linux-3.9.4-vs2.3.6.2/include/linux/vs_inet6.h
9369 --- linux-3.9.4/include/linux/vs_inet6.h 1970-01-01 00:00:00.000000000 +0000
9370 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_inet6.h 2013-05-31 14:47:11.000000000 +0000
9372 +#ifndef _VS_INET6_H
9373 +#define _VS_INET6_H
9375 +#include "vserver/base.h"
9376 +#include "vserver/network.h"
9377 +#include "vserver/debug.h"
9379 +#include <net/ipv6.h>
9381 +#define NXAV6(a) &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9382 +#define NXAV6_FMT "[%pI6/%pI6/%d:%04x]"
9388 +int v6_addr_match(struct nx_addr_v6 *nxa,
9389 + const struct in6_addr *addr, uint16_t mask)
9393 + switch (nxa->type & mask) {
9394 + case NXA_TYPE_MASK:
9395 + ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9397 + case NXA_TYPE_ADDR:
9398 + ret = ipv6_addr_equal(&nxa->ip, addr);
9400 + case NXA_TYPE_ANY:
9404 + vxdprintk(VXD_CBIT(net, 0),
9405 + "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9406 + nxa, NXAV6(nxa), addr, mask, ret);
9411 +int v6_addr_in_nx_info(struct nx_info *nxi,
9412 + const struct in6_addr *addr, uint16_t mask)
9414 + struct nx_addr_v6 *nxa;
9415 + unsigned long irqflags;
9421 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
9422 + for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9423 + if (v6_addr_match(nxa, addr, mask))
9427 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9429 + vxdprintk(VXD_CBIT(net, 0),
9430 + "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9431 + nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9436 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9438 + /* FIXME: needs full range checks */
9439 + return v6_addr_match(nxa, &addr->ip, mask);
9443 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9445 + struct nx_addr_v6 *ptr;
9446 + unsigned long irqflags;
9449 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
9450 + for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9451 + if (v6_nx_addr_match(ptr, nxa, mask))
9455 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9461 + * Check if a given address matches for a socket
9463 + * nxi: the socket's nx_info if any
9464 + * addr: to be verified address
9467 +int v6_sock_addr_match (
9468 + struct nx_info *nxi,
9469 + struct inet_sock *inet,
9470 + struct in6_addr *addr)
9472 + struct sock *sk = &inet->sk;
9473 + struct in6_addr *saddr = inet6_rcv_saddr(sk);
9475 + if (!ipv6_addr_any(addr) &&
9476 + ipv6_addr_equal(saddr, addr))
9478 + if (ipv6_addr_any(saddr))
9479 + return v6_addr_in_nx_info(nxi, addr, -1);
9484 + * check if address is covered by socket
9486 + * sk: the socket to check against
9487 + * addr: the address in question (must be != 0)
9491 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9493 + struct nx_info *nxi = sk->sk_nx_info;
9494 + struct in6_addr *saddr = inet6_rcv_saddr(sk);
9496 + vxdprintk(VXD_CBIT(net, 5),
9497 + "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9498 + sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9499 + (sk->sk_socket?sk->sk_socket->flags:0));
9501 + if (!ipv6_addr_any(saddr)) { /* direct address match */
9502 + return v6_addr_match(nxa, saddr, -1);
9503 + } else if (nxi) { /* match against nx_info */
9504 + return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9505 + } else { /* unrestricted any socket */
9511 +/* inet related checks and helpers */
9519 +#include <linux/netdevice.h>
9520 +#include <linux/inetdevice.h>
9521 +#include <net/inet_timewait_sock.h>
9524 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9525 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9526 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9531 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9537 + return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9541 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9543 + vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9544 + nxi, nxi ? nxi->nx_id : 0, ifa,
9545 + nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9547 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9549 + if (v6_ifa_in_nx_info(ifa, nxi))
9555 +struct nx_v6_sock_addr {
9556 + struct in6_addr saddr; /* Address used for validation */
9557 + struct in6_addr baddr; /* Address used for socket bind */
9561 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9562 + struct nx_v6_sock_addr *nsa)
9564 + // struct sock *sk = &inet->sk;
9565 + // struct nx_info *nxi = sk->sk_nx_info;
9566 + struct in6_addr saddr = addr->sin6_addr;
9567 + struct in6_addr baddr = saddr;
9569 + nsa->saddr = saddr;
9570 + nsa->baddr = baddr;
9575 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9577 + // struct sock *sk = &inet->sk;
9578 + // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9580 + // *saddr = nsa->baddr;
9581 + // inet->inet_saddr = nsa->baddr;
9585 +int nx_info_has_v6(struct nx_info *nxi)
9594 +#else /* CONFIG_IPV6 */
9597 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9604 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9610 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9616 +int nx_info_has_v6(struct nx_info *nxi)
9621 +#endif /* CONFIG_IPV6 */
9623 +#define current_nx_info_has_v6() \
9624 + nx_info_has_v6(current_nx_info())
9627 +#warning duplicate inclusion
9629 diff -NurpP --minimal linux-3.9.4/include/linux/vs_limit.h linux-3.9.4-vs2.3.6.2/include/linux/vs_limit.h
9630 --- linux-3.9.4/include/linux/vs_limit.h 1970-01-01 00:00:00.000000000 +0000
9631 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_limit.h 2013-05-31 14:47:11.000000000 +0000
9633 +#ifndef _VS_LIMIT_H
9634 +#define _VS_LIMIT_H
9636 +#include "vserver/limit.h"
9637 +#include "vserver/base.h"
9638 +#include "vserver/context.h"
9639 +#include "vserver/debug.h"
9640 +#include "vserver/context.h"
9641 +#include "vserver/limit_int.h"
9644 +#define vx_acc_cres(v, d, p, r) \
9645 + __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9647 +#define vx_acc_cres_cond(x, d, p, r) \
9648 + __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9649 + r, d, p, __FILE__, __LINE__)
9652 +#define vx_add_cres(v, a, p, r) \
9653 + __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9654 +#define vx_sub_cres(v, a, p, r) vx_add_cres(v, -(a), p, r)
9656 +#define vx_add_cres_cond(x, a, p, r) \
9657 + __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9658 + r, a, p, __FILE__, __LINE__)
9659 +#define vx_sub_cres_cond(x, a, p, r) vx_add_cres_cond(x, -(a), p, r)
9662 +/* process and file limits */
9664 +#define vx_nproc_inc(p) \
9665 + vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9667 +#define vx_nproc_dec(p) \
9668 + vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9670 +#define vx_files_inc(f) \
9671 + vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9673 +#define vx_files_dec(f) \
9674 + vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9676 +#define vx_locks_inc(l) \
9677 + vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9679 +#define vx_locks_dec(l) \
9680 + vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9682 +#define vx_openfd_inc(f) \
9683 + vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9685 +#define vx_openfd_dec(f) \
9686 + vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9689 +#define vx_cres_avail(v, n, r) \
9690 + __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9693 +#define vx_nproc_avail(n) \
9694 + vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9696 +#define vx_files_avail(n) \
9697 + vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9699 +#define vx_locks_avail(n) \
9700 + vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9702 +#define vx_openfd_avail(n) \
9703 + vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9706 +/* dentry limits */
9708 +#define vx_dentry_inc(d) do { \
9709 + if ((d)->d_count == 1) \
9710 + vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY); \
9713 +#define vx_dentry_dec(d) do { \
9714 + if ((d)->d_count == 0) \
9715 + vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY); \
9718 +#define vx_dentry_avail(n) \
9719 + vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9722 +/* socket limits */
9724 +#define vx_sock_inc(s) \
9725 + vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9727 +#define vx_sock_dec(s) \
9728 + vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9730 +#define vx_sock_avail(n) \
9731 + vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9734 +/* ipc resource limits */
9736 +#define vx_ipcmsg_add(v, u, a) \
9737 + vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9739 +#define vx_ipcmsg_sub(v, u, a) \
9740 + vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9742 +#define vx_ipcmsg_avail(v, a) \
9743 + vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9746 +#define vx_ipcshm_add(v, k, a) \
9747 + vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9749 +#define vx_ipcshm_sub(v, k, a) \
9750 + vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9752 +#define vx_ipcshm_avail(v, a) \
9753 + vx_cres_avail(v, a, VLIMIT_SHMEM)
9756 +#define vx_semary_inc(a) \
9757 + vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9759 +#define vx_semary_dec(a) \
9760 + vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9763 +#define vx_nsems_add(a,n) \
9764 + vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9766 +#define vx_nsems_sub(a,n) \
9767 + vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9771 +#warning duplicate inclusion
9773 diff -NurpP --minimal linux-3.9.4/include/linux/vs_network.h linux-3.9.4-vs2.3.6.2/include/linux/vs_network.h
9774 --- linux-3.9.4/include/linux/vs_network.h 1970-01-01 00:00:00.000000000 +0000
9775 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_network.h 2013-05-31 14:47:11.000000000 +0000
9777 +#ifndef _NX_VS_NETWORK_H
9778 +#define _NX_VS_NETWORK_H
9780 +#include "vserver/context.h"
9781 +#include "vserver/network.h"
9782 +#include "vserver/base.h"
9783 +#include "vserver/check.h"
9784 +#include "vserver/debug.h"
9786 +#include <linux/sched.h>
9789 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9791 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9792 + const char *_file, int _line)
9797 + vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9798 + nxi, nxi ? nxi->nx_id : 0,
9799 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9802 + atomic_inc(&nxi->nx_usecnt);
9807 +extern void free_nx_info(struct nx_info *);
9809 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9811 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9816 + vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9817 + nxi, nxi ? nxi->nx_id : 0,
9818 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9821 + if (atomic_dec_and_test(&nxi->nx_usecnt))
9822 + free_nx_info(nxi);
9826 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9828 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9829 + const char *_file, int _line)
9832 + vxlprintk(VXD_CBIT(nid, 3),
9833 + "init_nx_info(%p[#%d.%d])",
9834 + nxi, nxi ? nxi->nx_id : 0,
9835 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9838 + atomic_inc(&nxi->nx_usecnt);
9844 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9846 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9847 + const char *_file, int _line)
9849 + struct nx_info *nxo;
9854 + vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9855 + nxi, nxi ? nxi->nx_id : 0,
9856 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9859 + atomic_inc(&nxi->nx_usecnt);
9860 + nxo = xchg(nxp, nxi);
9864 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9866 +static inline void __clr_nx_info(struct nx_info **nxp,
9867 + const char *_file, int _line)
9869 + struct nx_info *nxo;
9871 + nxo = xchg(nxp, NULL);
9875 + vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9876 + nxo, nxo ? nxo->nx_id : 0,
9877 + nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9880 + if (atomic_dec_and_test(&nxo->nx_usecnt))
9881 + free_nx_info(nxo);
9885 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9887 +static inline void __claim_nx_info(struct nx_info *nxi,
9888 + struct task_struct *task, const char *_file, int _line)
9890 + vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9891 + nxi, nxi ? nxi->nx_id : 0,
9892 + nxi?atomic_read(&nxi->nx_usecnt):0,
9893 + nxi?atomic_read(&nxi->nx_tasks):0,
9894 + task, _file, _line);
9896 + atomic_inc(&nxi->nx_tasks);
9900 +extern void unhash_nx_info(struct nx_info *);
9902 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9904 +static inline void __release_nx_info(struct nx_info *nxi,
9905 + struct task_struct *task, const char *_file, int _line)
9907 + vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9908 + nxi, nxi ? nxi->nx_id : 0,
9909 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9910 + nxi ? atomic_read(&nxi->nx_tasks) : 0,
9911 + task, _file, _line);
9915 + if (atomic_dec_and_test(&nxi->nx_tasks))
9916 + unhash_nx_info(nxi);
9920 +#define task_get_nx_info(i) __task_get_nx_info(i, __FILE__, __LINE__)
9922 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9923 + const char *_file, int _line)
9925 + struct nx_info *nxi;
9928 + vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9930 + nxi = __get_nx_info(p->nx_info, _file, _line);
9936 +static inline void exit_nx_info(struct task_struct *p)
9939 + release_nx_info(p->nx_info, p);
9944 +#warning duplicate inclusion
9946 diff -NurpP --minimal linux-3.9.4/include/linux/vs_pid.h linux-3.9.4-vs2.3.6.2/include/linux/vs_pid.h
9947 --- linux-3.9.4/include/linux/vs_pid.h 1970-01-01 00:00:00.000000000 +0000
9948 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_pid.h 2013-05-31 14:47:11.000000000 +0000
9953 +#include "vserver/base.h"
9954 +#include "vserver/check.h"
9955 +#include "vserver/context.h"
9956 +#include "vserver/debug.h"
9957 +#include "vserver/pid.h"
9958 +#include <linux/pid_namespace.h>
9961 +#define VXF_FAKE_INIT (VXF_INFO_INIT | VXF_STATE_INIT)
9964 +int vx_proc_task_visible(struct task_struct *task)
9966 + if ((task->pid == 1) &&
9967 + !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9968 + /* show a blend through init */
9970 + if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9977 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9981 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9983 + struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9985 + if (task && !vx_proc_task_visible(task)) {
9986 + vxdprintk(VXD_CBIT(misc, 6),
9987 + "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9988 + task, task->xid, task->pid,
9989 + current, current->xid, current->pid);
9990 + put_task_struct(task);
9998 +#warning duplicate inclusion
10000 diff -NurpP --minimal linux-3.9.4/include/linux/vs_sched.h linux-3.9.4-vs2.3.6.2/include/linux/vs_sched.h
10001 --- linux-3.9.4/include/linux/vs_sched.h 1970-01-01 00:00:00.000000000 +0000
10002 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_sched.h 2013-05-31 14:47:11.000000000 +0000
10004 +#ifndef _VS_SCHED_H
10005 +#define _VS_SCHED_H
10007 +#include "vserver/base.h"
10008 +#include "vserver/context.h"
10009 +#include "vserver/sched.h"
10012 +#define MAX_PRIO_BIAS 20
10013 +#define MIN_PRIO_BIAS -20
10016 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10018 + struct vx_info *vxi = p->vx_info;
10021 + prio += vx_cpu(vxi, sched_pc).prio_bias;
10025 +static inline void vx_account_user(struct vx_info *vxi,
10026 + cputime_t cputime, int nice)
10030 + vx_cpu(vxi, sched_pc).user_ticks += cputime;
10033 +static inline void vx_account_system(struct vx_info *vxi,
10034 + cputime_t cputime, int idle)
10038 + vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10042 +#warning duplicate inclusion
10044 diff -NurpP --minimal linux-3.9.4/include/linux/vs_socket.h linux-3.9.4-vs2.3.6.2/include/linux/vs_socket.h
10045 --- linux-3.9.4/include/linux/vs_socket.h 1970-01-01 00:00:00.000000000 +0000
10046 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_socket.h 2013-05-31 14:47:11.000000000 +0000
10048 +#ifndef _VS_SOCKET_H
10049 +#define _VS_SOCKET_H
10051 +#include "vserver/debug.h"
10052 +#include "vserver/base.h"
10053 +#include "vserver/cacct.h"
10054 +#include "vserver/context.h"
10055 +#include "vserver/tag.h"
10058 +/* socket accounting */
10060 +#include <linux/socket.h>
10062 +static inline int vx_sock_type(int family)
10064 + switch (family) {
10066 + return VXA_SOCK_UNSPEC;
10068 + return VXA_SOCK_UNIX;
10070 + return VXA_SOCK_INET;
10072 + return VXA_SOCK_INET6;
10074 + return VXA_SOCK_PACKET;
10076 + return VXA_SOCK_OTHER;
10080 +#define vx_acc_sock(v, f, p, s) \
10081 + __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10083 +static inline void __vx_acc_sock(struct vx_info *vxi,
10084 + int family, int pos, int size, char *file, int line)
10087 + int type = vx_sock_type(family);
10089 + atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10090 + atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10094 +#define vx_sock_recv(sk, s) \
10095 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10096 +#define vx_sock_send(sk, s) \
10097 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10098 +#define vx_sock_fail(sk, s) \
10099 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10102 +#define sock_vx_init(s) do { \
10103 + (s)->sk_xid = 0; \
10104 + (s)->sk_vx_info = NULL; \
10107 +#define sock_nx_init(s) do { \
10108 + (s)->sk_nid = 0; \
10109 + (s)->sk_nx_info = NULL; \
10113 +#warning duplicate inclusion
10115 diff -NurpP --minimal linux-3.9.4/include/linux/vs_tag.h linux-3.9.4-vs2.3.6.2/include/linux/vs_tag.h
10116 --- linux-3.9.4/include/linux/vs_tag.h 1970-01-01 00:00:00.000000000 +0000
10117 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_tag.h 2013-05-31 14:47:11.000000000 +0000
10122 +#include <linux/vserver/tag.h>
10124 +/* check conditions */
10126 +#define DX_ADMIN 0x0001
10127 +#define DX_WATCH 0x0002
10128 +#define DX_HOSTID 0x0008
10130 +#define DX_IDENT 0x0010
10132 +#define DX_ARG_MASK 0x0010
10135 +#define dx_task_tag(t) ((t)->tag)
10137 +#define dx_current_tag() dx_task_tag(current)
10139 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10141 +#define dx_weak_check(c, m) ((m) ? dx_check(c, m) : 1)
10145 + * check current context for ADMIN/WATCH and
10146 + * optionally against supplied argument
10148 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10150 + if (mode & DX_ARG_MASK) {
10151 + if ((mode & DX_IDENT) && (id == cid))
10154 + return (((mode & DX_ADMIN) && (cid == 0)) ||
10155 + ((mode & DX_WATCH) && (cid == 1)) ||
10156 + ((mode & DX_HOSTID) && (id == 0)));
10160 +int dx_permission(const struct inode *inode, int mask);
10164 +#warning duplicate inclusion
10166 diff -NurpP --minimal linux-3.9.4/include/linux/vs_time.h linux-3.9.4-vs2.3.6.2/include/linux/vs_time.h
10167 --- linux-3.9.4/include/linux/vs_time.h 1970-01-01 00:00:00.000000000 +0000
10168 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_time.h 2013-05-31 14:47:11.000000000 +0000
10170 +#ifndef _VS_TIME_H
10171 +#define _VS_TIME_H
10174 +/* time faking stuff */
10176 +#ifdef CONFIG_VSERVER_VTIME
10178 +extern void vx_adjust_timespec(struct timespec *ts);
10179 +extern int vx_settimeofday(const struct timespec *ts);
10182 +#define vx_adjust_timespec(t) do { } while (0)
10183 +#define vx_settimeofday(t) do_settimeofday(t)
10187 +#warning duplicate inclusion
10189 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/base.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/base.h
10190 --- linux-3.9.4/include/linux/vserver/base.h 1970-01-01 00:00:00.000000000 +0000
10191 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/base.h 2013-05-31 17:55:09.000000000 +0000
10193 +#ifndef _VSERVER_BASE_H
10194 +#define _VSERVER_BASE_H
10197 +/* context state changes */
10209 +#define vx_task_xid(t) ((t)->xid)
10211 +#define vx_current_xid() vx_task_xid(current)
10213 +#define current_vx_info() (current->vx_info)
10216 +#define nx_task_nid(t) ((t)->nid)
10218 +#define nx_current_nid() nx_task_nid(current)
10220 +#define current_nx_info() (current->nx_info)
10223 +/* generic flag merging */
10225 +#define vs_check_flags(v, m, f) (((v) & (m)) ^ (f))
10227 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10229 +#define vs_mask_mask(v, f, m) (((v) & ~(m)) | ((v) & (f) & (m)))
10231 +#define vs_check_bit(v, n) ((v) & (1LL << (n)))
10234 +/* context flags */
10236 +#define __vx_flags(v) ((v) ? (v)->vx_flags : 0)
10238 +#define vx_current_flags() __vx_flags(current_vx_info())
10240 +#define vx_info_flags(v, m, f) \
10241 + vs_check_flags(__vx_flags(v), m, f)
10243 +#define task_vx_flags(t, m, f) \
10244 + ((t) && vx_info_flags((t)->vx_info, m, f))
10246 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10249 +/* context caps */
10251 +#define __vx_ccaps(v) ((v) ? (v)->vx_ccaps : 0)
10253 +#define vx_current_ccaps() __vx_ccaps(current_vx_info())
10255 +#define vx_info_ccaps(v, c) (__vx_ccaps(v) & (c))
10257 +#define vx_ccaps(c) vx_info_ccaps(current_vx_info(), (c))
10261 +/* network flags */
10263 +#define __nx_flags(n) ((n) ? (n)->nx_flags : 0)
10265 +#define nx_current_flags() __nx_flags(current_nx_info())
10267 +#define nx_info_flags(n, m, f) \
10268 + vs_check_flags(__nx_flags(n), m, f)
10270 +#define task_nx_flags(t, m, f) \
10271 + ((t) && nx_info_flags((t)->nx_info, m, f))
10273 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10276 +/* network caps */
10278 +#define __nx_ncaps(n) ((n) ? (n)->nx_ncaps : 0)
10280 +#define nx_current_ncaps() __nx_ncaps(current_nx_info())
10282 +#define nx_info_ncaps(n, c) (__nx_ncaps(n) & (c))
10284 +#define nx_ncaps(c) nx_info_ncaps(current_nx_info(), c)
10287 +/* context mask capabilities */
10289 +#define __vx_mcaps(v) ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10291 +#define vx_info_mcaps(v, c) (__vx_mcaps(v) & (c))
10293 +#define vx_mcaps(c) vx_info_mcaps(current_vx_info(), c)
10296 +/* context bcap mask */
10298 +#define __vx_bcaps(v) ((v)->vx_bcaps)
10300 +#define vx_current_bcaps() __vx_bcaps(current_vx_info())
10303 +/* mask given bcaps */
10305 +#define vx_info_mbcaps(v, c) ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10307 +#define vx_mbcaps(c) vx_info_mbcaps(current_vx_info(), c)
10310 +/* masked cap_bset */
10312 +#define vx_info_cap_bset(v) vx_info_mbcaps(v, current->cap_bset)
10314 +#define vx_current_cap_bset() vx_info_cap_bset(current_vx_info())
10317 +#define vx_info_mbcap(v, b) \
10318 + (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10319 + vx_info_bcaps(v, b) : (b))
10321 +#define task_vx_mbcap(t, b) \
10322 + vx_info_mbcap((t)->vx_info, (t)->b)
10324 +#define vx_mbcap(b) task_vx_mbcap(current, b)
10327 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10329 +#define vx_capable(b, c) (capable(b) || \
10330 + (cap_raised(current_cap(), b) && vx_ccaps(c)))
10332 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10333 + (cap_raised(current_cap(), b) && vx_ccaps(c)))
10335 +#define nx_capable(b, c) (capable(b) || \
10336 + (cap_raised(current_cap(), b) && nx_ncaps(c)))
10338 +#define vx_task_initpid(t, n) \
10339 + ((t)->vx_info && \
10340 + ((t)->vx_info->vx_initpid == (n)))
10342 +#define vx_current_initpid(n) vx_task_initpid(current, n)
10345 +/* context unshare mask */
10347 +#define __vx_umask(v) ((v)->vx_umask)
10349 +#define vx_current_umask() __vx_umask(current_vx_info())
10351 +#define vx_can_unshare(b, f) (capable(b) || \
10352 + (cap_raised(current_cap(), b) && \
10353 + !((f) & ~vx_current_umask())))
10355 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
10356 + (cap_raised(current_cap(), b) && \
10357 + !((f) & ~vx_current_umask())))
10359 +#define __vx_wmask(v) ((v)->vx_wmask)
10361 +#define vx_current_wmask() __vx_wmask(current_vx_info())
10364 +#define __vx_state(v) ((v) ? ((v)->vx_state) : 0)
10366 +#define vx_info_state(v, m) (__vx_state(v) & (m))
10369 +#define __nx_state(n) ((n) ? ((n)->nx_state) : 0)
10371 +#define nx_info_state(n, m) (__nx_state(n) & (m))
10374 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct.h
10375 --- linux-3.9.4/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
10376 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct.h 2013-05-31 14:47:11.000000000 +0000
10378 +#ifndef _VSERVER_CACCT_H
10379 +#define _VSERVER_CACCT_H
10382 +enum sock_acc_field {
10383 + VXA_SOCK_UNSPEC = 0,
10389 + VXA_SOCK_SIZE /* array size */
10392 +#endif /* _VSERVER_CACCT_H */
10393 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_cmd.h
10394 --- linux-3.9.4/include/linux/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
10395 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_cmd.h 2013-05-31 14:47:11.000000000 +0000
10397 +#ifndef _VSERVER_CACCT_CMD_H
10398 +#define _VSERVER_CACCT_CMD_H
10401 +#include <linux/compiler.h>
10402 +#include <uapi/vserver/cacct_cmd.h>
10404 +extern int vc_sock_stat(struct vx_info *, void __user *);
10406 +#endif /* _VSERVER_CACCT_CMD_H */
10407 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_def.h
10408 --- linux-3.9.4/include/linux/vserver/cacct_def.h 1970-01-01 00:00:00.000000000 +0000
10409 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_def.h 2013-05-31 14:47:11.000000000 +0000
10411 +#ifndef _VSERVER_CACCT_DEF_H
10412 +#define _VSERVER_CACCT_DEF_H
10414 +#include <asm/atomic.h>
10415 +#include <linux/vserver/cacct.h>
10418 +struct _vx_sock_acc {
10419 + atomic_long_t count;
10420 + atomic_long_t total;
10423 +/* context sub struct */
10425 +struct _vx_cacct {
10426 + struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10427 + atomic_t slab[8];
10428 + atomic_t page[6][8];
10431 +#ifdef CONFIG_VSERVER_DEBUG
10433 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10437 + printk("\t_vx_cacct:");
10438 + for (i = 0; i < 6; i++) {
10439 + struct _vx_sock_acc *ptr = cacct->sock[i];
10441 + printk("\t [%d] =", i);
10442 + for (j = 0; j < 3; j++) {
10443 + printk(" [%d] = %8lu, %8lu", j,
10444 + atomic_long_read(&ptr[j].count),
10445 + atomic_long_read(&ptr[j].total));
10453 +#endif /* _VSERVER_CACCT_DEF_H */
10454 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_int.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_int.h
10455 --- linux-3.9.4/include/linux/vserver/cacct_int.h 1970-01-01 00:00:00.000000000 +0000
10456 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_int.h 2013-05-31 14:47:11.000000000 +0000
10458 +#ifndef _VSERVER_CACCT_INT_H
10459 +#define _VSERVER_CACCT_INT_H
10462 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10464 + return atomic_long_read(&cacct->sock[type][pos].count);
10469 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10471 + return atomic_long_read(&cacct->sock[type][pos].total);
10474 +#endif /* _VSERVER_CACCT_INT_H */
10475 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/check.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/check.h
10476 --- linux-3.9.4/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
10477 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/check.h 2013-05-31 14:47:11.000000000 +0000
10479 +#ifndef _VSERVER_CHECK_H
10480 +#define _VSERVER_CHECK_H
10483 +#define MAX_S_CONTEXT 65535 /* Arbitrary limit */
10485 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10486 +#define MIN_D_CONTEXT 49152 /* dynamic contexts start here */
10488 +#define MIN_D_CONTEXT 65536
10491 +/* check conditions */
10493 +#define VS_ADMIN 0x0001
10494 +#define VS_WATCH 0x0002
10495 +#define VS_HIDE 0x0004
10496 +#define VS_HOSTID 0x0008
10498 +#define VS_IDENT 0x0010
10499 +#define VS_EQUIV 0x0020
10500 +#define VS_PARENT 0x0040
10501 +#define VS_CHILD 0x0080
10503 +#define VS_ARG_MASK 0x00F0
10505 +#define VS_DYNAMIC 0x0100
10506 +#define VS_STATIC 0x0200
10508 +#define VS_ATR_MASK 0x0F00
10510 +#ifdef CONFIG_VSERVER_PRIVACY
10511 +#define VS_ADMIN_P (0)
10512 +#define VS_WATCH_P (0)
10514 +#define VS_ADMIN_P VS_ADMIN
10515 +#define VS_WATCH_P VS_WATCH
10518 +#define VS_HARDIRQ 0x1000
10519 +#define VS_SOFTIRQ 0x2000
10520 +#define VS_IRQ 0x4000
10522 +#define VS_IRQ_MASK 0xF000
10524 +#include <linux/hardirq.h>
10527 + * check current context for ADMIN/WATCH and
10528 + * optionally against supplied argument
10530 +static inline int __vs_check(int cid, int id, unsigned int mode)
10532 + if (mode & VS_ARG_MASK) {
10533 + if ((mode & VS_IDENT) && (id == cid))
10536 + if (mode & VS_ATR_MASK) {
10537 + if ((mode & VS_DYNAMIC) &&
10538 + (id >= MIN_D_CONTEXT) &&
10539 + (id <= MAX_S_CONTEXT))
10541 + if ((mode & VS_STATIC) &&
10542 + (id > 1) && (id < MIN_D_CONTEXT))
10545 + if (mode & VS_IRQ_MASK) {
10546 + if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10548 + if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10550 + if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10553 + return (((mode & VS_ADMIN) && (cid == 0)) ||
10554 + ((mode & VS_WATCH) && (cid == 1)) ||
10555 + ((mode & VS_HOSTID) && (id == 0)));
10558 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10560 +#define vx_weak_check(c, m) ((m) ? vx_check(c, m) : 1)
10563 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10565 +#define nx_weak_check(c, m) ((m) ? nx_check(c, m) : 1)
10568 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/context.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/context.h
10569 --- linux-3.9.4/include/linux/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
10570 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/context.h 2013-05-31 14:47:11.000000000 +0000
10572 +#ifndef _VSERVER_CONTEXT_H
10573 +#define _VSERVER_CONTEXT_H
10576 +#include <linux/list.h>
10577 +#include <linux/spinlock.h>
10578 +#include <linux/rcupdate.h>
10579 +#include <uapi/vserver/context.h>
10581 +#include "limit_def.h"
10582 +#include "sched_def.h"
10583 +#include "cvirt_def.h"
10584 +#include "cacct_def.h"
10585 +#include "device_def.h"
10587 +#define VX_SPACES 2
10589 +struct _vx_info_pc {
10590 + struct _vx_sched_pc sched_pc;
10591 + struct _vx_cvirt_pc cvirt_pc;
10594 +struct _vx_space {
10595 + unsigned long vx_nsmask; /* assignment mask */
10596 + struct nsproxy *vx_nsproxy; /* private namespaces */
10597 + struct fs_struct *vx_fs; /* private namespace fs */
10598 + const struct cred *vx_cred; /* task credentials */
10602 + struct hlist_node vx_hlist; /* linked list of contexts */
10603 + xid_t vx_id; /* context id */
10604 + atomic_t vx_usecnt; /* usage count */
10605 + atomic_t vx_tasks; /* tasks count */
10606 + struct vx_info *vx_parent; /* parent context */
10607 + int vx_state; /* context state */
10609 + struct _vx_space space[VX_SPACES]; /* namespace store */
10611 + uint64_t vx_flags; /* context flags */
10612 + uint64_t vx_ccaps; /* context caps (vserver) */
10613 + uint64_t vx_umask; /* unshare mask (guest) */
10614 + uint64_t vx_wmask; /* warn mask (guest) */
10615 + kernel_cap_t vx_bcaps; /* bounding caps (system) */
10617 + struct task_struct *vx_reaper; /* guest reaper process */
10618 + pid_t vx_initpid; /* PID of guest init */
10619 + int64_t vx_badness_bias; /* OOM points bias */
10621 + struct _vx_limit limit; /* vserver limits */
10622 + struct _vx_sched sched; /* vserver scheduler */
10623 + struct _vx_cvirt cvirt; /* virtual/bias stuff */
10624 + struct _vx_cacct cacct; /* context accounting */
10626 + struct _vx_device dmap; /* default device map targets */
10628 +#ifndef CONFIG_SMP
10629 + struct _vx_info_pc info_pc; /* per cpu data */
10631 + struct _vx_info_pc *ptr_pc; /* per cpu array */
10634 + wait_queue_head_t vx_wait; /* context exit waitqueue */
10635 + int reboot_cmd; /* last sys_reboot() cmd */
10636 + int exit_code; /* last process exit code */
10638 + char vx_name[65]; /* vserver name */
10641 +#ifndef CONFIG_SMP
10642 +#define vx_ptr_pc(vxi) (&(vxi)->info_pc)
10643 +#define vx_per_cpu(vxi, v, id) vx_ptr_pc(vxi)->v
10645 +#define vx_ptr_pc(vxi) ((vxi)->ptr_pc)
10646 +#define vx_per_cpu(vxi, v, id) per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10649 +#define vx_cpu(vxi, v) vx_per_cpu(vxi, v, smp_processor_id())
10652 +struct vx_info_save {
10653 + struct vx_info *vxi;
10658 +/* status flags */
10660 +#define VXS_HASHED 0x0001
10661 +#define VXS_PAUSED 0x0010
10662 +#define VXS_SHUTDOWN 0x0100
10663 +#define VXS_HELPER 0x1000
10664 +#define VXS_RELEASED 0x8000
10667 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10668 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10670 +extern struct vx_info *lookup_vx_info(int);
10671 +extern struct vx_info *lookup_or_create_vx_info(int);
10673 +extern int get_xid_list(int, unsigned int *, int);
10674 +extern int xid_is_hashed(xid_t);
10676 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10678 +extern long vs_state_change(struct vx_info *, unsigned int);
10681 +#endif /* _VSERVER_CONTEXT_H */
10682 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/context_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/context_cmd.h
10683 --- linux-3.9.4/include/linux/vserver/context_cmd.h 1970-01-01 00:00:00.000000000 +0000
10684 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/context_cmd.h 2013-05-31 14:47:11.000000000 +0000
10686 +#ifndef _VSERVER_CONTEXT_CMD_H
10687 +#define _VSERVER_CONTEXT_CMD_H
10689 +#include <uapi/vserver/context_cmd.h>
10691 +extern int vc_task_xid(uint32_t);
10693 +extern int vc_vx_info(struct vx_info *, void __user *);
10695 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10697 +extern int vc_ctx_create(uint32_t, void __user *);
10698 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10700 +extern int vc_get_cflags(struct vx_info *, void __user *);
10701 +extern int vc_set_cflags(struct vx_info *, void __user *);
10703 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10704 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10706 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10707 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10709 +extern int vc_get_umask(struct vx_info *, void __user *);
10710 +extern int vc_set_umask(struct vx_info *, void __user *);
10712 +extern int vc_get_wmask(struct vx_info *, void __user *);
10713 +extern int vc_set_wmask(struct vx_info *, void __user *);
10715 +extern int vc_get_badness(struct vx_info *, void __user *);
10716 +extern int vc_set_badness(struct vx_info *, void __user *);
10718 +#endif /* _VSERVER_CONTEXT_CMD_H */
10719 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt.h
10720 --- linux-3.9.4/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
10721 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt.h 2013-05-31 14:47:11.000000000 +0000
10723 +#ifndef _VSERVER_CVIRT_H
10724 +#define _VSERVER_CVIRT_H
10728 +void vx_vsi_boottime(struct timespec *);
10730 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10735 +void vx_update_load(struct vx_info *);
10738 +int vx_do_syslog(int, char __user *, int);
10740 +#endif /* _VSERVER_CVIRT_H */
10741 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt_cmd.h
10742 --- linux-3.9.4/include/linux/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
10743 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt_cmd.h 2013-05-31 14:47:11.000000000 +0000
10745 +#ifndef _VSERVER_CVIRT_CMD_H
10746 +#define _VSERVER_CVIRT_CMD_H
10749 +#include <linux/compiler.h>
10750 +#include <uapi/vserver/cvirt_cmd.h>
10752 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10753 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10755 +extern int vc_virt_stat(struct vx_info *, void __user *);
10757 +#endif /* _VSERVER_CVIRT_CMD_H */
10758 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt_def.h
10759 --- linux-3.9.4/include/linux/vserver/cvirt_def.h 1970-01-01 00:00:00.000000000 +0000
10760 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt_def.h 2013-05-31 14:47:11.000000000 +0000
10762 +#ifndef _VSERVER_CVIRT_DEF_H
10763 +#define _VSERVER_CVIRT_DEF_H
10765 +#include <linux/jiffies.h>
10766 +#include <linux/spinlock.h>
10767 +#include <linux/wait.h>
10768 +#include <linux/time.h>
10769 +#include <asm/atomic.h>
10772 +struct _vx_usage_stat {
10776 + uint64_t softirq;
10782 +struct _vx_syslog {
10783 + wait_queue_head_t log_wait;
10784 + spinlock_t logbuf_lock; /* lock for the log buffer */
10786 + unsigned long log_start; /* next char to be read by syslog() */
10787 + unsigned long con_start; /* next char to be sent to consoles */
10788 + unsigned long log_end; /* most-recently-written-char + 1 */
10789 + unsigned long logged_chars; /* #chars since last read+clear operation */
10791 + char log_buf[1024];
10795 +/* context sub struct */
10797 +struct _vx_cvirt {
10798 + atomic_t nr_threads; /* number of current threads */
10799 + atomic_t nr_running; /* number of running threads */
10800 + atomic_t nr_uninterruptible; /* number of uninterruptible threads */
10802 + atomic_t nr_onhold; /* processes on hold */
10803 + uint32_t onhold_last; /* jiffies when put on hold */
10805 + struct timespec bias_ts; /* time offset to the host */
10806 + struct timespec bias_idle;
10807 + struct timespec bias_uptime; /* context creation point */
10808 + uint64_t bias_clock; /* offset in clock_t */
10810 + spinlock_t load_lock; /* lock for the load averages */
10811 + atomic_t load_updates; /* nr of load updates done so far */
10812 + uint32_t load_last; /* last time load was calculated */
10813 + uint32_t load[3]; /* load averages 1,5,15 */
10815 + atomic_t total_forks; /* number of forks so far */
10817 + struct _vx_syslog syslog;
10820 +struct _vx_cvirt_pc {
10821 + struct _vx_usage_stat cpustat;
10825 +#ifdef CONFIG_VSERVER_DEBUG
10827 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10829 + printk("\t_vx_cvirt:\n");
10830 + printk("\t threads: %4d, %4d, %4d, %4d\n",
10831 + atomic_read(&cvirt->nr_threads),
10832 + atomic_read(&cvirt->nr_running),
10833 + atomic_read(&cvirt->nr_uninterruptible),
10834 + atomic_read(&cvirt->nr_onhold));
10835 + /* add rest here */
10836 + printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10841 +#endif /* _VSERVER_CVIRT_DEF_H */
10842 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/debug.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/debug.h
10843 --- linux-3.9.4/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
10844 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/debug.h 2013-05-31 14:47:11.000000000 +0000
10846 +#ifndef _VSERVER_DEBUG_H
10847 +#define _VSERVER_DEBUG_H
10850 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10851 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10852 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10854 +#define VXD_DEV(d) (d), (d)->bd_inode->i_ino, \
10855 + imajor((d)->bd_inode), iminor((d)->bd_inode)
10856 +#define VXF_DEV "%p[%lu,%d:%d]"
10858 +#if defined(CONFIG_QUOTES_UTF8)
10859 +#define VS_Q_LQM "\xc2\xbb"
10860 +#define VS_Q_RQM "\xc2\xab"
10861 +#elif defined(CONFIG_QUOTES_ASCII)
10862 +#define VS_Q_LQM "\x27"
10863 +#define VS_Q_RQM "\x27"
10865 +#define VS_Q_LQM "\xbb"
10866 +#define VS_Q_RQM "\xab"
10869 +#define VS_Q(f) VS_Q_LQM f VS_Q_RQM
10872 +#define vxd_path(p) \
10873 + ({ static char _buffer[PATH_MAX]; \
10874 + d_path(p, _buffer, sizeof(_buffer)); })
10876 +#define vxd_cond_path(n) \
10877 + ((n) ? vxd_path(&(n)->path) : "<null>" )
10880 +#ifdef CONFIG_VSERVER_DEBUG
10882 +extern unsigned int vs_debug_switch;
10883 +extern unsigned int vs_debug_xid;
10884 +extern unsigned int vs_debug_nid;
10885 +extern unsigned int vs_debug_tag;
10886 +extern unsigned int vs_debug_net;
10887 +extern unsigned int vs_debug_limit;
10888 +extern unsigned int vs_debug_cres;
10889 +extern unsigned int vs_debug_dlim;
10890 +extern unsigned int vs_debug_quota;
10891 +extern unsigned int vs_debug_cvirt;
10892 +extern unsigned int vs_debug_space;
10893 +extern unsigned int vs_debug_perm;
10894 +extern unsigned int vs_debug_misc;
10897 +#define VX_LOGLEVEL "vxD: "
10898 +#define VX_PROC_FMT "%p: "
10899 +#define VX_PROCESS current
10901 +#define vxdprintk(c, f, x...) \
10904 + printk(VX_LOGLEVEL VX_PROC_FMT f "\n", \
10905 + VX_PROCESS , ##x); \
10908 +#define vxlprintk(c, f, x...) \
10911 + printk(VX_LOGLEVEL f " @%s:%d\n", x); \
10914 +#define vxfprintk(c, f, x...) \
10917 + printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10923 +void dump_vx_info(struct vx_info *, int);
10924 +void dump_vx_info_inactive(int);
10926 +#else /* CONFIG_VSERVER_DEBUG */
10928 +#define vs_debug_switch 0
10929 +#define vs_debug_xid 0
10930 +#define vs_debug_nid 0
10931 +#define vs_debug_tag 0
10932 +#define vs_debug_net 0
10933 +#define vs_debug_limit 0
10934 +#define vs_debug_cres 0
10935 +#define vs_debug_dlim 0
10936 +#define vs_debug_quota 0
10937 +#define vs_debug_cvirt 0
10938 +#define vs_debug_space 0
10939 +#define vs_debug_perm 0
10940 +#define vs_debug_misc 0
10942 +#define vxdprintk(x...) do { } while (0)
10943 +#define vxlprintk(x...) do { } while (0)
10944 +#define vxfprintk(x...) do { } while (0)
10946 +#endif /* CONFIG_VSERVER_DEBUG */
10949 +#ifdef CONFIG_VSERVER_WARN
10951 +#define VX_WARNLEVEL KERN_WARNING "vxW: "
10952 +#define VX_WARN_TASK "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10953 +#define VX_WARN_XID "[xid #%u] "
10954 +#define VX_WARN_NID "[nid #%u] "
10955 +#define VX_WARN_TAG "[tag #%u] "
10957 +#define vxwprintk(c, f, x...) \
10960 + printk(VX_WARNLEVEL f "\n", ##x); \
10963 +#else /* CONFIG_VSERVER_WARN */
10965 +#define vxwprintk(x...) do { } while (0)
10967 +#endif /* CONFIG_VSERVER_WARN */
10969 +#define vxwprintk_task(c, f, x...) \
10970 + vxwprintk(c, VX_WARN_TASK f, \
10971 + current->comm, current->pid, \
10972 + current->xid, current->nid, current->tag, ##x)
10973 +#define vxwprintk_xid(c, f, x...) \
10974 + vxwprintk(c, VX_WARN_XID f, current->xid, x)
10975 +#define vxwprintk_nid(c, f, x...) \
10976 + vxwprintk(c, VX_WARN_NID f, current->nid, x)
10977 +#define vxwprintk_tag(c, f, x...) \
10978 + vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10980 +#ifdef CONFIG_VSERVER_DEBUG
10981 +#define vxd_assert_lock(l) assert_spin_locked(l)
10982 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10983 + "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10985 +#define vxd_assert_lock(l) do { } while (0)
10986 +#define vxd_assert(c, f, x...) do { } while (0)
10990 +#endif /* _VSERVER_DEBUG_H */
10991 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/debug_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/debug_cmd.h
10992 --- linux-3.9.4/include/linux/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
10993 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/debug_cmd.h 2013-05-31 14:47:11.000000000 +0000
10995 +#ifndef _VSERVER_DEBUG_CMD_H
10996 +#define _VSERVER_DEBUG_CMD_H
10998 +#include <uapi/vserver/debug_cmd.h>
11001 +#ifdef CONFIG_COMPAT
11003 +#include <asm/compat.h>
11005 +struct vcmd_read_history_v0_x32 {
11008 + compat_uptr_t data_ptr;
11011 +struct vcmd_read_monitor_v0_x32 {
11014 + compat_uptr_t data_ptr;
11017 +#endif /* CONFIG_COMPAT */
11019 +extern int vc_dump_history(uint32_t);
11021 +extern int vc_read_history(uint32_t, void __user *);
11022 +extern int vc_read_monitor(uint32_t, void __user *);
11024 +#ifdef CONFIG_COMPAT
11026 +extern int vc_read_history_x32(uint32_t, void __user *);
11027 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11029 +#endif /* CONFIG_COMPAT */
11031 +#endif /* _VSERVER_DEBUG_CMD_H */
11032 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/device.h
11033 --- linux-3.9.4/include/linux/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
11034 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/device.h 2013-05-31 14:47:11.000000000 +0000
11036 +#ifndef _VSERVER_DEVICE_H
11037 +#define _VSERVER_DEVICE_H
11040 +#include <uapi/vserver/device.h>
11042 +#else /* _VSERVER_DEVICE_H */
11043 +#warning duplicate inclusion
11044 +#endif /* _VSERVER_DEVICE_H */
11045 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/device_cmd.h
11046 --- linux-3.9.4/include/linux/vserver/device_cmd.h 1970-01-01 00:00:00.000000000 +0000
11047 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/device_cmd.h 2013-05-31 14:47:11.000000000 +0000
11049 +#ifndef _VSERVER_DEVICE_CMD_H
11050 +#define _VSERVER_DEVICE_CMD_H
11052 +#include <uapi/vserver/device_cmd.h>
11055 +#ifdef CONFIG_COMPAT
11057 +#include <asm/compat.h>
11059 +struct vcmd_set_mapping_v0_x32 {
11060 + compat_uptr_t device_ptr;
11061 + compat_uptr_t target_ptr;
11065 +#endif /* CONFIG_COMPAT */
11067 +#include <linux/compiler.h>
11069 +extern int vc_set_mapping(struct vx_info *, void __user *);
11070 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11072 +#ifdef CONFIG_COMPAT
11074 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11075 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11077 +#endif /* CONFIG_COMPAT */
11079 +#endif /* _VSERVER_DEVICE_CMD_H */
11080 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/device_def.h
11081 --- linux-3.9.4/include/linux/vserver/device_def.h 1970-01-01 00:00:00.000000000 +0000
11082 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/device_def.h 2013-05-31 14:47:11.000000000 +0000
11084 +#ifndef _VSERVER_DEVICE_DEF_H
11085 +#define _VSERVER_DEVICE_DEF_H
11087 +#include <linux/types.h>
11089 +struct vx_dmap_target {
11094 +struct _vx_device {
11095 +#ifdef CONFIG_VSERVER_DEVICE
11096 + struct vx_dmap_target targets[2];
11100 +#endif /* _VSERVER_DEVICE_DEF_H */
11101 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/dlimit.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/dlimit.h
11102 --- linux-3.9.4/include/linux/vserver/dlimit.h 1970-01-01 00:00:00.000000000 +0000
11103 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/dlimit.h 2013-05-31 14:47:11.000000000 +0000
11105 +#ifndef _VSERVER_DLIMIT_H
11106 +#define _VSERVER_DLIMIT_H
11108 +#include "switch.h"
11113 +/* keep in sync with CDLIM_INFINITY */
11115 +#define DLIM_INFINITY (~0ULL)
11117 +#include <linux/spinlock.h>
11118 +#include <linux/rcupdate.h>
11120 +struct super_block;
11123 + struct hlist_node dl_hlist; /* linked list of contexts */
11124 + struct rcu_head dl_rcu; /* the rcu head */
11125 + tag_t dl_tag; /* context tag */
11126 + atomic_t dl_usecnt; /* usage count */
11127 + atomic_t dl_refcnt; /* reference count */
11129 + struct super_block *dl_sb; /* associated superblock */
11131 + spinlock_t dl_lock; /* protect the values */
11133 + unsigned long long dl_space_used; /* used space in bytes */
11134 + unsigned long long dl_space_total; /* maximum space in bytes */
11135 + unsigned long dl_inodes_used; /* used inodes */
11136 + unsigned long dl_inodes_total; /* maximum inodes */
11138 + unsigned int dl_nrlmult; /* non root limit mult */
11143 +extern void rcu_free_dl_info(struct rcu_head *);
11144 +extern void unhash_dl_info(struct dl_info *);
11146 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11151 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11153 +typedef uint64_t dlsize_t;
11155 +#endif /* __KERNEL__ */
11156 +#else /* _VSERVER_DLIMIT_H */
11157 +#warning duplicate inclusion
11158 +#endif /* _VSERVER_DLIMIT_H */
11159 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/dlimit_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/dlimit_cmd.h
11160 --- linux-3.9.4/include/linux/vserver/dlimit_cmd.h 1970-01-01 00:00:00.000000000 +0000
11161 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/dlimit_cmd.h 2013-05-31 14:47:11.000000000 +0000
11163 +#ifndef _VSERVER_DLIMIT_CMD_H
11164 +#define _VSERVER_DLIMIT_CMD_H
11166 +#include <uapi/vserver/dlimit_cmd.h>
11169 +#ifdef CONFIG_COMPAT
11171 +#include <asm/compat.h>
11173 +struct vcmd_ctx_dlimit_base_v0_x32 {
11174 + compat_uptr_t name_ptr;
11178 +struct vcmd_ctx_dlimit_v0_x32 {
11179 + compat_uptr_t name_ptr;
11180 + uint32_t space_used; /* used space in kbytes */
11181 + uint32_t space_total; /* maximum space in kbytes */
11182 + uint32_t inodes_used; /* used inodes */
11183 + uint32_t inodes_total; /* maximum inodes */
11184 + uint32_t reserved; /* reserved for root in % */
11188 +#endif /* CONFIG_COMPAT */
11190 +#include <linux/compiler.h>
11192 +extern int vc_add_dlimit(uint32_t, void __user *);
11193 +extern int vc_rem_dlimit(uint32_t, void __user *);
11195 +extern int vc_set_dlimit(uint32_t, void __user *);
11196 +extern int vc_get_dlimit(uint32_t, void __user *);
11198 +#ifdef CONFIG_COMPAT
11200 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11201 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11203 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11204 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11206 +#endif /* CONFIG_COMPAT */
11208 +#endif /* _VSERVER_DLIMIT_CMD_H */
11209 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/global.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/global.h
11210 --- linux-3.9.4/include/linux/vserver/global.h 1970-01-01 00:00:00.000000000 +0000
11211 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/global.h 2013-05-31 14:47:11.000000000 +0000
11213 +#ifndef _VSERVER_GLOBAL_H
11214 +#define _VSERVER_GLOBAL_H
11217 +extern atomic_t vx_global_ctotal;
11218 +extern atomic_t vx_global_cactive;
11220 +extern atomic_t nx_global_ctotal;
11221 +extern atomic_t nx_global_cactive;
11223 +extern atomic_t vs_global_nsproxy;
11224 +extern atomic_t vs_global_fs;
11225 +extern atomic_t vs_global_mnt_ns;
11226 +extern atomic_t vs_global_uts_ns;
11227 +extern atomic_t vs_global_user_ns;
11228 +extern atomic_t vs_global_pid_ns;
11231 +#endif /* _VSERVER_GLOBAL_H */
11232 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/history.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/history.h
11233 --- linux-3.9.4/include/linux/vserver/history.h 1970-01-01 00:00:00.000000000 +0000
11234 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/history.h 2013-05-31 14:47:11.000000000 +0000
11236 +#ifndef _VSERVER_HISTORY_H
11237 +#define _VSERVER_HISTORY_H
11242 + VXH_THROW_OOPS = 1,
11246 + VXH_INIT_VX_INFO,
11249 + VXH_CLAIM_VX_INFO,
11250 + VXH_RELEASE_VX_INFO,
11251 + VXH_ALLOC_VX_INFO,
11252 + VXH_DEALLOC_VX_INFO,
11253 + VXH_HASH_VX_INFO,
11254 + VXH_UNHASH_VX_INFO,
11256 + VXH_LOOKUP_VX_INFO,
11257 + VXH_CREATE_VX_INFO,
11260 +struct _vxhe_vxi {
11261 + struct vx_info *ptr;
11267 +struct _vxhe_set_clr {
11271 +struct _vxhe_loc_lookup {
11275 +struct _vx_hist_entry {
11277 + unsigned short seq;
11278 + unsigned short type;
11279 + struct _vxhe_vxi vxi;
11281 + struct _vxhe_set_clr sc;
11282 + struct _vxhe_loc_lookup ll;
11286 +#ifdef CONFIG_VSERVER_HISTORY
11288 +extern unsigned volatile int vxh_active;
11290 +struct _vx_hist_entry *vxh_advance(void *loc);
11294 +void __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11296 + entry->vxi.ptr = vxi;
11298 + entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11299 + entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11300 + entry->vxi.xid = vxi->vx_id;
11305 +#define __HERE__ current_text_addr()
11307 +#define __VXH_BODY(__type, __data, __here) \
11308 + struct _vx_hist_entry *entry; \
11310 + preempt_disable(); \
11311 + entry = vxh_advance(__here); \
11313 + entry->type = __type; \
11314 + preempt_enable();
11317 + /* pass vxi only */
11319 +#define __VXH_SMPL \
11320 + __vxh_copy_vxi(entry, vxi)
11323 +void __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11325 + __VXH_BODY(__type, __VXH_SMPL, __here)
11328 + /* pass vxi and data (void *) */
11330 +#define __VXH_DATA \
11331 + __vxh_copy_vxi(entry, vxi); \
11332 + entry->sc.data = data
11335 +void __vxh_data(struct vx_info *vxi, void *data,
11336 + int __type, void *__here)
11338 + __VXH_BODY(__type, __VXH_DATA, __here)
11341 + /* pass vxi and arg (long) */
11343 +#define __VXH_LONG \
11344 + __vxh_copy_vxi(entry, vxi); \
11345 + entry->ll.arg = arg
11348 +void __vxh_long(struct vx_info *vxi, long arg,
11349 + int __type, void *__here)
11351 + __VXH_BODY(__type, __VXH_LONG, __here)
11356 +void __vxh_throw_oops(void *__here)
11358 + __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11359 + /* prevent further acquisition */
11364 +#define vxh_throw_oops() __vxh_throw_oops(__HERE__);
11366 +#define __vxh_get_vx_info(v, h) __vxh_smpl(v, VXH_GET_VX_INFO, h);
11367 +#define __vxh_put_vx_info(v, h) __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11369 +#define __vxh_init_vx_info(v, d, h) \
11370 + __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11371 +#define __vxh_set_vx_info(v, d, h) \
11372 + __vxh_data(v, d, VXH_SET_VX_INFO, h);
11373 +#define __vxh_clr_vx_info(v, d, h) \
11374 + __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11376 +#define __vxh_claim_vx_info(v, d, h) \
11377 + __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11378 +#define __vxh_release_vx_info(v, d, h) \
11379 + __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11381 +#define vxh_alloc_vx_info(v) \
11382 + __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11383 +#define vxh_dealloc_vx_info(v) \
11384 + __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11386 +#define vxh_hash_vx_info(v) \
11387 + __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11388 +#define vxh_unhash_vx_info(v) \
11389 + __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11391 +#define vxh_loc_vx_info(v, l) \
11392 + __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11393 +#define vxh_lookup_vx_info(v, l) \
11394 + __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11395 +#define vxh_create_vx_info(v, l) \
11396 + __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11398 +extern void vxh_dump_history(void);
11401 +#else /* CONFIG_VSERVER_HISTORY */
11403 +#define __HERE__ 0
11405 +#define vxh_throw_oops() do { } while (0)
11407 +#define __vxh_get_vx_info(v, h) do { } while (0)
11408 +#define __vxh_put_vx_info(v, h) do { } while (0)
11410 +#define __vxh_init_vx_info(v, d, h) do { } while (0)
11411 +#define __vxh_set_vx_info(v, d, h) do { } while (0)
11412 +#define __vxh_clr_vx_info(v, d, h) do { } while (0)
11414 +#define __vxh_claim_vx_info(v, d, h) do { } while (0)
11415 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11417 +#define vxh_alloc_vx_info(v) do { } while (0)
11418 +#define vxh_dealloc_vx_info(v) do { } while (0)
11420 +#define vxh_hash_vx_info(v) do { } while (0)
11421 +#define vxh_unhash_vx_info(v) do { } while (0)
11423 +#define vxh_loc_vx_info(v, l) do { } while (0)
11424 +#define vxh_lookup_vx_info(v, l) do { } while (0)
11425 +#define vxh_create_vx_info(v, l) do { } while (0)
11427 +#define vxh_dump_history() do { } while (0)
11430 +#endif /* CONFIG_VSERVER_HISTORY */
11432 +#endif /* _VSERVER_HISTORY_H */
11433 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/inode.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/inode.h
11434 --- linux-3.9.4/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
11435 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/inode.h 2013-05-31 14:47:11.000000000 +0000
11437 +#ifndef _VSERVER_INODE_H
11438 +#define _VSERVER_INODE_H
11440 +#include <uapi/vserver/inode.h>
11443 +#ifdef CONFIG_VSERVER_PROC_SECURE
11444 +#define IATTR_PROC_DEFAULT ( IATTR_ADMIN | IATTR_HIDE )
11445 +#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
11447 +#define IATTR_PROC_DEFAULT ( IATTR_ADMIN )
11448 +#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
11451 +#define vx_hide_check(c, m) (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11453 +#else /* _VSERVER_INODE_H */
11454 +#warning duplicate inclusion
11455 +#endif /* _VSERVER_INODE_H */
11456 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/inode_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/inode_cmd.h
11457 --- linux-3.9.4/include/linux/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
11458 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/inode_cmd.h 2013-05-31 14:47:11.000000000 +0000
11460 +#ifndef _VSERVER_INODE_CMD_H
11461 +#define _VSERVER_INODE_CMD_H
11463 +#include <uapi/vserver/inode_cmd.h>
11467 +#ifdef CONFIG_COMPAT
11469 +#include <asm/compat.h>
11471 +struct vcmd_ctx_iattr_v1_x32 {
11472 + compat_uptr_t name_ptr;
11478 +#endif /* CONFIG_COMPAT */
11480 +#include <linux/compiler.h>
11482 +extern int vc_get_iattr(void __user *);
11483 +extern int vc_set_iattr(void __user *);
11485 +extern int vc_fget_iattr(uint32_t, void __user *);
11486 +extern int vc_fset_iattr(uint32_t, void __user *);
11488 +#ifdef CONFIG_COMPAT
11490 +extern int vc_get_iattr_x32(void __user *);
11491 +extern int vc_set_iattr_x32(void __user *);
11493 +#endif /* CONFIG_COMPAT */
11495 +#endif /* _VSERVER_INODE_CMD_H */
11496 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit.h
11497 --- linux-3.9.4/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
11498 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit.h 2013-05-31 14:47:11.000000000 +0000
11500 +#ifndef _VSERVER_LIMIT_H
11501 +#define _VSERVER_LIMIT_H
11503 +#include <uapi/vserver/limit.h>
11506 +#define VLIM_NOCHECK ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11508 +/* keep in sync with CRLIM_INFINITY */
11510 +#define VLIM_INFINITY (~0ULL)
11512 +#include <asm/atomic.h>
11513 +#include <asm/resource.h>
11515 +#ifndef RLIM_INFINITY
11516 +#warning RLIM_INFINITY is undefined
11519 +#define __rlim_val(l, r, v) ((l)->res[r].v)
11521 +#define __rlim_soft(l, r) __rlim_val(l, r, soft)
11522 +#define __rlim_hard(l, r) __rlim_val(l, r, hard)
11524 +#define __rlim_rcur(l, r) __rlim_val(l, r, rcur)
11525 +#define __rlim_rmin(l, r) __rlim_val(l, r, rmin)
11526 +#define __rlim_rmax(l, r) __rlim_val(l, r, rmax)
11528 +#define __rlim_lhit(l, r) __rlim_val(l, r, lhit)
11529 +#define __rlim_hit(l, r) atomic_inc(&__rlim_lhit(l, r))
11531 +typedef atomic_long_t rlim_atomic_t;
11532 +typedef unsigned long rlim_t;
11534 +#define __rlim_get(l, r) atomic_long_read(&__rlim_rcur(l, r))
11535 +#define __rlim_set(l, r, v) atomic_long_set(&__rlim_rcur(l, r), v)
11536 +#define __rlim_inc(l, r) atomic_long_inc(&__rlim_rcur(l, r))
11537 +#define __rlim_dec(l, r) atomic_long_dec(&__rlim_rcur(l, r))
11538 +#define __rlim_add(l, r, v) atomic_long_add(v, &__rlim_rcur(l, r))
11539 +#define __rlim_sub(l, r, v) atomic_long_sub(v, &__rlim_rcur(l, r))
11542 +#if (RLIM_INFINITY == VLIM_INFINITY)
11543 +#define VX_VLIM(r) ((long long)(long)(r))
11544 +#define VX_RLIM(v) ((rlim_t)(v))
11546 +#define VX_VLIM(r) (((r) == RLIM_INFINITY) \
11547 + ? VLIM_INFINITY : (long long)(r))
11548 +#define VX_RLIM(v) (((v) == VLIM_INFINITY) \
11549 + ? RLIM_INFINITY : (rlim_t)(v))
11554 +void vx_vsi_meminfo(struct sysinfo *);
11555 +void vx_vsi_swapinfo(struct sysinfo *);
11556 +long vx_vsi_cached(struct sysinfo *);
11558 +#define NUM_LIMITS 24
11560 +#endif /* _VSERVER_LIMIT_H */
11561 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_cmd.h
11562 --- linux-3.9.4/include/linux/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
11563 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_cmd.h 2013-05-31 14:47:11.000000000 +0000
11565 +#ifndef _VSERVER_LIMIT_CMD_H
11566 +#define _VSERVER_LIMIT_CMD_H
11568 +#include <uapi/vserver/limit_cmd.h>
11571 +#ifdef CONFIG_IA32_EMULATION
11573 +struct vcmd_ctx_rlimit_v0_x32 {
11575 + uint64_t minimum;
11576 + uint64_t softlimit;
11577 + uint64_t maximum;
11578 +} __attribute__ ((packed));
11580 +#endif /* CONFIG_IA32_EMULATION */
11582 +#include <linux/compiler.h>
11584 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11585 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11586 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11587 +extern int vc_reset_hits(struct vx_info *, void __user *);
11588 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11590 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11592 +#ifdef CONFIG_IA32_EMULATION
11594 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11595 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11597 +#endif /* CONFIG_IA32_EMULATION */
11599 +#endif /* _VSERVER_LIMIT_CMD_H */
11600 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_def.h
11601 --- linux-3.9.4/include/linux/vserver/limit_def.h 1970-01-01 00:00:00.000000000 +0000
11602 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_def.h 2013-05-31 14:47:11.000000000 +0000
11604 +#ifndef _VSERVER_LIMIT_DEF_H
11605 +#define _VSERVER_LIMIT_DEF_H
11607 +#include <asm/atomic.h>
11608 +#include <asm/resource.h>
11610 +#include "limit.h"
11613 +struct _vx_res_limit {
11614 + rlim_t soft; /* Context soft limit */
11615 + rlim_t hard; /* Context hard limit */
11617 + rlim_atomic_t rcur; /* Current value */
11618 + rlim_t rmin; /* Context minimum */
11619 + rlim_t rmax; /* Context maximum */
11621 + atomic_t lhit; /* Limit hits */
11624 +/* context sub struct */
11626 +struct _vx_limit {
11627 + struct _vx_res_limit res[NUM_LIMITS];
11630 +#ifdef CONFIG_VSERVER_DEBUG
11632 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11636 + printk("\t_vx_limit:");
11637 + for (i = 0; i < NUM_LIMITS; i++) {
11638 + printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11639 + i, (unsigned long)__rlim_get(limit, i),
11640 + (unsigned long)__rlim_rmin(limit, i),
11641 + (unsigned long)__rlim_rmax(limit, i),
11642 + (long)__rlim_soft(limit, i),
11643 + (long)__rlim_hard(limit, i),
11644 + atomic_read(&__rlim_lhit(limit, i)));
11650 +#endif /* _VSERVER_LIMIT_DEF_H */
11651 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_int.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_int.h
11652 --- linux-3.9.4/include/linux/vserver/limit_int.h 1970-01-01 00:00:00.000000000 +0000
11653 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_int.h 2013-05-31 14:47:11.000000000 +0000
11655 +#ifndef _VSERVER_LIMIT_INT_H
11656 +#define _VSERVER_LIMIT_INT_H
11658 +#define VXD_RCRES_COND(r) VXD_CBIT(cres, r)
11659 +#define VXD_RLIMIT_COND(r) VXD_CBIT(limit, r)
11661 +extern const char *vlimit_name[NUM_LIMITS];
11663 +static inline void __vx_acc_cres(struct vx_info *vxi,
11664 + int res, int dir, void *_data, char *_file, int _line)
11666 + if (VXD_RCRES_COND(res))
11667 + vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11668 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11669 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11670 + (dir > 0) ? "++" : "--", _data, _file, _line);
11675 + __rlim_inc(&vxi->limit, res);
11677 + __rlim_dec(&vxi->limit, res);
11680 +static inline void __vx_add_cres(struct vx_info *vxi,
11681 + int res, int amount, void *_data, char *_file, int _line)
11683 + if (VXD_RCRES_COND(res))
11684 + vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11685 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11686 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11687 + amount, _data, _file, _line);
11692 + __rlim_add(&vxi->limit, res, amount);
11696 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11698 + int cond = (value > __rlim_rmax(limit, res));
11701 + __rlim_rmax(limit, res) = value;
11706 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11708 + int cond = (value < __rlim_rmin(limit, res));
11711 + __rlim_rmin(limit, res) = value;
11716 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11718 + if (!__vx_cres_adjust_max(limit, res, value))
11719 + __vx_cres_adjust_min(limit, res, value);
11724 + +1 ... no limit hit
11725 + -1 ... over soft limit
11726 + 0 ... over hard limit */
11728 +static inline int __vx_cres_avail(struct vx_info *vxi,
11729 + int res, int num, char *_file, int _line)
11731 + struct _vx_limit *limit;
11734 + if (VXD_RLIMIT_COND(res))
11735 + vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11736 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11737 + (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11738 + (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11739 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11740 + num, _file, _line);
11744 + limit = &vxi->limit;
11745 + value = __rlim_get(limit, res);
11747 + if (!__vx_cres_adjust_max(limit, res, value))
11748 + __vx_cres_adjust_min(limit, res, value);
11753 + if (__rlim_soft(limit, res) == RLIM_INFINITY)
11755 + if (value + num <= __rlim_soft(limit, res))
11758 + if (__rlim_hard(limit, res) == RLIM_INFINITY)
11760 + if (value + num <= __rlim_hard(limit, res))
11763 + __rlim_hit(limit, res);
11768 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11771 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11773 + rlim_t value, sum = 0;
11776 + while ((res = *array++)) {
11777 + value = __rlim_get(limit, res);
11778 + __vx_cres_fixup(limit, res, value);
11785 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11787 + rlim_t value = __vx_cres_array_sum(limit, array + 1);
11788 + int res = *array;
11790 + if (value == __rlim_get(limit, res))
11793 + __rlim_set(limit, res, value);
11794 + /* now adjust min/max */
11795 + if (!__vx_cres_adjust_max(limit, res, value))
11796 + __vx_cres_adjust_min(limit, res, value);
11801 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11802 + const int *array, int num, char *_file, int _line)
11804 + struct _vx_limit *limit;
11805 + rlim_t value = 0;
11813 + limit = &vxi->limit;
11815 + value = __vx_cres_array_sum(limit, array + 1);
11817 + __rlim_set(limit, res, value);
11818 + __vx_cres_fixup(limit, res, value);
11820 + return __vx_cres_avail(vxi, res, num, _file, _line);
11824 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11829 + /* complex resources first */
11830 + if ((id < 0) || (id == RLIMIT_RSS))
11831 + __vx_cres_array_fixup(limit, VLA_RSS);
11833 + for (res = 0; res < NUM_LIMITS; res++) {
11834 + if ((id > 0) && (res != id))
11837 + value = __rlim_get(limit, res);
11838 + __vx_cres_fixup(limit, res, value);
11840 + /* not supposed to happen, maybe warn? */
11841 + if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11842 + __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11847 +#endif /* _VSERVER_LIMIT_INT_H */
11848 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/monitor.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/monitor.h
11849 --- linux-3.9.4/include/linux/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
11850 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/monitor.h 2013-05-31 14:47:11.000000000 +0000
11852 +#ifndef _VSERVER_MONITOR_H
11853 +#define _VSERVER_MONITOR_H
11855 +#include <uapi/vserver/monitor.h>
11857 +#endif /* _VSERVER_MONITOR_H */
11858 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/network.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/network.h
11859 --- linux-3.9.4/include/linux/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
11860 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/network.h 2013-05-31 14:47:11.000000000 +0000
11862 +#ifndef _VSERVER_NETWORK_H
11863 +#define _VSERVER_NETWORK_H
11866 +#include <linux/list.h>
11867 +#include <linux/spinlock.h>
11868 +#include <linux/rcupdate.h>
11869 +#include <linux/in.h>
11870 +#include <linux/in6.h>
11871 +#include <asm/atomic.h>
11872 +#include <uapi/vserver/network.h>
11874 +struct nx_addr_v4 {
11875 + struct nx_addr_v4 *next;
11876 + struct in_addr ip[2];
11877 + struct in_addr mask;
11882 +struct nx_addr_v6 {
11883 + struct nx_addr_v6 *next;
11884 + struct in6_addr ip;
11885 + struct in6_addr mask;
11892 + struct hlist_node nx_hlist; /* linked list of nxinfos */
11893 + nid_t nx_id; /* vnet id */
11894 + atomic_t nx_usecnt; /* usage count */
11895 + atomic_t nx_tasks; /* tasks count */
11896 + int nx_state; /* context state */
11898 + uint64_t nx_flags; /* network flag word */
11899 + uint64_t nx_ncaps; /* network capabilities */
11901 + spinlock_t addr_lock; /* protect address changes */
11902 + struct in_addr v4_lback; /* Loopback address */
11903 + struct in_addr v4_bcast; /* Broadcast address */
11904 + struct nx_addr_v4 v4; /* First/Single ipv4 address */
11905 +#ifdef CONFIG_IPV6
11906 + struct nx_addr_v6 v6; /* First/Single ipv6 address */
11908 + char nx_name[65]; /* network context name */
11912 +/* status flags */
11914 +#define NXS_HASHED 0x0001
11915 +#define NXS_SHUTDOWN 0x0100
11916 +#define NXS_RELEASED 0x8000
11918 +extern struct nx_info *lookup_nx_info(int);
11920 +extern int get_nid_list(int, unsigned int *, int);
11921 +extern int nid_is_hashed(nid_t);
11923 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11925 +extern long vs_net_change(struct nx_info *, unsigned int);
11930 +#define NX_IPV4(n) ((n)->v4.type != NXA_TYPE_NONE)
11931 +#ifdef CONFIG_IPV6
11932 +#define NX_IPV6(n) ((n)->v6.type != NXA_TYPE_NONE)
11934 +#define NX_IPV6(n) (0)
11937 +#endif /* _VSERVER_NETWORK_H */
11938 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/network_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/network_cmd.h
11939 --- linux-3.9.4/include/linux/vserver/network_cmd.h 1970-01-01 00:00:00.000000000 +0000
11940 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/network_cmd.h 2013-05-31 14:47:11.000000000 +0000
11942 +#ifndef _VSERVER_NETWORK_CMD_H
11943 +#define _VSERVER_NETWORK_CMD_H
11945 +#include <uapi/vserver/network_cmd.h>
11947 +extern int vc_task_nid(uint32_t);
11949 +extern int vc_nx_info(struct nx_info *, void __user *);
11951 +extern int vc_net_create(uint32_t, void __user *);
11952 +extern int vc_net_migrate(struct nx_info *, void __user *);
11954 +extern int vc_net_add(struct nx_info *, void __user *);
11955 +extern int vc_net_remove(struct nx_info *, void __user *);
11957 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11958 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11960 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11961 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11963 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11964 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11966 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11967 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11969 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11970 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11972 +extern int vc_get_nflags(struct nx_info *, void __user *);
11973 +extern int vc_set_nflags(struct nx_info *, void __user *);
11975 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11976 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11978 +#endif /* _VSERVER_CONTEXT_CMD_H */
11979 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/percpu.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/percpu.h
11980 --- linux-3.9.4/include/linux/vserver/percpu.h 1970-01-01 00:00:00.000000000 +0000
11981 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/percpu.h 2013-05-31 14:47:11.000000000 +0000
11983 +#ifndef _VSERVER_PERCPU_H
11984 +#define _VSERVER_PERCPU_H
11986 +#include "cvirt_def.h"
11987 +#include "sched_def.h"
11989 +struct _vx_percpu {
11990 + struct _vx_cvirt_pc cvirt;
11991 + struct _vx_sched_pc sched;
11994 +#define PERCPU_PERCTX (sizeof(struct _vx_percpu))
11996 +#endif /* _VSERVER_PERCPU_H */
11997 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/pid.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/pid.h
11998 --- linux-3.9.4/include/linux/vserver/pid.h 1970-01-01 00:00:00.000000000 +0000
11999 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/pid.h 2013-05-31 14:47:11.000000000 +0000
12001 +#ifndef _VSERVER_PID_H
12002 +#define _VSERVER_PID_H
12004 +/* pid faking stuff */
12006 +#define vx_info_map_pid(v, p) \
12007 + __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12008 +#define vx_info_map_tgid(v,p) vx_info_map_pid(v,p)
12009 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12010 +#define vx_map_tgid(p) vx_map_pid(p)
12012 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12013 + const char *func, const char *file, int line)
12015 + if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12016 + vxfprintk(VXD_CBIT(cvirt, 2),
12017 + "vx_map_tgid: %p/%llx: %d -> %d",
12018 + vxi, (long long)vxi->vx_flags, pid,
12019 + (pid && pid == vxi->vx_initpid) ? 1 : pid,
12020 + func, file, line);
12023 + if (pid == vxi->vx_initpid)
12029 +#define vx_info_rmap_pid(v, p) \
12030 + __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12031 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12032 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12034 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12035 + const char *func, const char *file, int line)
12037 + if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12038 + vxfprintk(VXD_CBIT(cvirt, 2),
12039 + "vx_rmap_tgid: %p/%llx: %d -> %d",
12040 + vxi, (long long)vxi->vx_flags, pid,
12041 + (pid == 1) ? vxi->vx_initpid : pid,
12042 + func, file, line);
12043 + if ((pid == 1) && vxi->vx_initpid)
12044 + return vxi->vx_initpid;
12045 + if (pid == vxi->vx_initpid)
12052 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched.h
12053 --- linux-3.9.4/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
12054 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched.h 2013-05-31 14:47:11.000000000 +0000
12056 +#ifndef _VSERVER_SCHED_H
12057 +#define _VSERVER_SCHED_H
12064 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12069 +void vx_update_load(struct vx_info *);
12072 +void vx_update_sched_param(struct _vx_sched *sched,
12073 + struct _vx_sched_pc *sched_pc);
12075 +#endif /* __KERNEL__ */
12076 +#else /* _VSERVER_SCHED_H */
12077 +#warning duplicate inclusion
12078 +#endif /* _VSERVER_SCHED_H */
12079 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched_cmd.h
12080 --- linux-3.9.4/include/linux/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
12081 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched_cmd.h 2013-05-31 14:47:11.000000000 +0000
12083 +#ifndef _VSERVER_SCHED_CMD_H
12084 +#define _VSERVER_SCHED_CMD_H
12087 +#include <linux/compiler.h>
12088 +#include <uapi/vserver/sched_cmd.h>
12090 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12091 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12093 +#endif /* _VSERVER_SCHED_CMD_H */
12094 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched_def.h
12095 --- linux-3.9.4/include/linux/vserver/sched_def.h 1970-01-01 00:00:00.000000000 +0000
12096 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched_def.h 2013-05-31 14:47:11.000000000 +0000
12098 +#ifndef _VSERVER_SCHED_DEF_H
12099 +#define _VSERVER_SCHED_DEF_H
12101 +#include <linux/spinlock.h>
12102 +#include <linux/jiffies.h>
12103 +#include <linux/cpumask.h>
12104 +#include <asm/atomic.h>
12105 +#include <asm/param.h>
12108 +/* context sub struct */
12110 +struct _vx_sched {
12111 + int prio_bias; /* bias offset for priority */
12113 + cpumask_t update; /* CPUs which should update */
12116 +struct _vx_sched_pc {
12117 + int prio_bias; /* bias offset for priority */
12119 + uint64_t user_ticks; /* token tick events */
12120 + uint64_t sys_ticks; /* token tick events */
12121 + uint64_t hold_ticks; /* token ticks paused */
12125 +#ifdef CONFIG_VSERVER_DEBUG
12127 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12129 + printk("\t_vx_sched:\n");
12130 + printk("\t priority = %4d\n", sched->prio_bias);
12135 +#endif /* _VSERVER_SCHED_DEF_H */
12136 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/signal.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/signal.h
12137 --- linux-3.9.4/include/linux/vserver/signal.h 1970-01-01 00:00:00.000000000 +0000
12138 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/signal.h 2013-05-31 14:47:11.000000000 +0000
12140 +#ifndef _VSERVER_SIGNAL_H
12141 +#define _VSERVER_SIGNAL_H
12148 +int vx_info_kill(struct vx_info *, int, int);
12150 +#endif /* __KERNEL__ */
12151 +#else /* _VSERVER_SIGNAL_H */
12152 +#warning duplicate inclusion
12153 +#endif /* _VSERVER_SIGNAL_H */
12154 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/signal_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/signal_cmd.h
12155 --- linux-3.9.4/include/linux/vserver/signal_cmd.h 1970-01-01 00:00:00.000000000 +0000
12156 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/signal_cmd.h 2013-05-31 14:47:11.000000000 +0000
12158 +#ifndef _VSERVER_SIGNAL_CMD_H
12159 +#define _VSERVER_SIGNAL_CMD_H
12161 +#include <uapi/vserver/signal_cmd.h>
12164 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12165 +extern int vc_wait_exit(struct vx_info *, void __user *);
12168 +extern int vc_get_pflags(uint32_t pid, void __user *);
12169 +extern int vc_set_pflags(uint32_t pid, void __user *);
12171 +#endif /* _VSERVER_SIGNAL_CMD_H */
12172 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/space.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/space.h
12173 --- linux-3.9.4/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
12174 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/space.h 2013-05-31 14:47:11.000000000 +0000
12176 +#ifndef _VSERVER_SPACE_H
12177 +#define _VSERVER_SPACE_H
12179 +#include <linux/types.h>
12183 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12185 +#else /* _VSERVER_SPACE_H */
12186 +#warning duplicate inclusion
12187 +#endif /* _VSERVER_SPACE_H */
12188 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/space_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/space_cmd.h
12189 --- linux-3.9.4/include/linux/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
12190 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/space_cmd.h 2013-05-31 14:47:11.000000000 +0000
12192 +#ifndef _VSERVER_SPACE_CMD_H
12193 +#define _VSERVER_SPACE_CMD_H
12195 +#include <uapi/vserver/space_cmd.h>
12198 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12199 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12200 +extern int vc_enter_space(struct vx_info *, void __user *);
12201 +extern int vc_set_space(struct vx_info *, void __user *);
12202 +extern int vc_get_space_mask(void __user *, int);
12204 +#endif /* _VSERVER_SPACE_CMD_H */
12205 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/switch.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/switch.h
12206 --- linux-3.9.4/include/linux/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12207 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/switch.h 2013-05-31 14:47:11.000000000 +0000
12209 +#ifndef _VSERVER_SWITCH_H
12210 +#define _VSERVER_SWITCH_H
12213 +#include <linux/errno.h>
12214 +#include <uapi/vserver/switch.h>
12216 +#endif /* _VSERVER_SWITCH_H */
12217 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/tag.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/tag.h
12218 --- linux-3.9.4/include/linux/vserver/tag.h 1970-01-01 00:00:00.000000000 +0000
12219 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/tag.h 2013-06-01 08:36:17.000000000 +0000
12224 +#include <linux/types.h>
12227 +#define DX_TAG(in) (IS_TAGGED(in))
12230 +#ifdef CONFIG_TAG_NFSD
12231 +#define DX_TAG_NFSD 1
12233 +#define DX_TAG_NFSD 0
12237 +#ifdef CONFIG_TAGGING_NONE
12239 +#define MAX_UID 0xFFFFFFFF
12240 +#define MAX_GID 0xFFFFFFFF
12242 +#define INOTAG_TAG(cond, uid, gid, tag) (0)
12244 +#define TAGINO_UID(cond, uid, tag) (uid)
12245 +#define TAGINO_GID(cond, gid, tag) (gid)
12250 +#ifdef CONFIG_TAGGING_GID16
12252 +#define MAX_UID 0xFFFFFFFF
12253 +#define MAX_GID 0x0000FFFF
12255 +#define INOTAG_TAG(cond, uid, gid, tag) \
12256 + ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
12258 +#define TAGINO_UID(cond, uid, tag) (uid)
12259 +#define TAGINO_GID(cond, gid, tag) \
12260 + ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
12265 +#ifdef CONFIG_TAGGING_ID24
12267 +#define MAX_UID 0x00FFFFFF
12268 +#define MAX_GID 0x00FFFFFF
12270 +#define INOTAG_TAG(cond, uid, gid, tag) \
12271 + ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
12273 +#define TAGINO_UID(cond, uid, tag) \
12274 + ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
12275 +#define TAGINO_GID(cond, gid, tag) \
12276 + ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
12281 +#ifdef CONFIG_TAGGING_UID16
12283 +#define MAX_UID 0x0000FFFF
12284 +#define MAX_GID 0xFFFFFFFF
12286 +#define INOTAG_TAG(cond, uid, gid, tag) \
12287 + ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
12289 +#define TAGINO_UID(cond, uid, tag) \
12290 + ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
12291 +#define TAGINO_GID(cond, gid, tag) (gid)
12296 +#ifdef CONFIG_TAGGING_INTERN
12298 +#define MAX_UID 0xFFFFFFFF
12299 +#define MAX_GID 0xFFFFFFFF
12301 +#define INOTAG_TAG(cond, uid, gid, tag) \
12302 + ((cond) ? (tag) : 0)
12304 +#define TAGINO_UID(cond, uid, tag) (uid)
12305 +#define TAGINO_GID(cond, gid, tag) (gid)
12310 +#ifndef CONFIG_TAGGING_NONE
12311 +#define dx_current_fstag(sb) \
12312 + ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
12314 +#define dx_current_fstag(sb) (0)
12317 +#ifndef CONFIG_TAGGING_INTERN
12318 +#define TAGINO_TAG(cond, tag) (0)
12320 +#define TAGINO_TAG(cond, tag) ((cond) ? (tag) : 0)
12323 +#define INOTAG_UID(cond, uid, gid) \
12324 + ((cond) ? ((uid) & MAX_UID) : (uid))
12325 +#define INOTAG_GID(cond, uid, gid) \
12326 + ((cond) ? ((gid) & MAX_GID) : (gid))
12329 +static inline uid_t dx_map_uid(uid_t uid)
12331 + if ((uid > MAX_UID) && (uid != -1))
12333 + return (uid & MAX_UID);
12336 +#define dx_map_kuid(n, u) \
12337 + make_kuid(n, dx_map_uid(from_kuid(n, u)))
12339 +static inline gid_t dx_map_gid(gid_t gid)
12341 + if ((gid > MAX_GID) && (gid != -1))
12343 + return (gid & MAX_GID);
12346 +#define dx_map_kgid(n, u) \
12347 + make_kgid(n, dx_map_gid(from_kgid(n, u)))
12354 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
12356 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
12357 + unsigned long *flags);
12359 +#ifdef CONFIG_PROPAGATE
12361 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
12363 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
12366 +#define dx_propagate_tag(n, i) do { } while (0)
12369 +#endif /* _DX_TAG_H */
12370 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/tag_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/tag_cmd.h
12371 --- linux-3.9.4/include/linux/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
12372 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/tag_cmd.h 2013-05-31 14:47:11.000000000 +0000
12374 +#ifndef _VSERVER_TAG_CMD_H
12375 +#define _VSERVER_TAG_CMD_H
12377 +#include <uapi/vserver/tag_cmd.h>
12379 +extern int vc_task_tag(uint32_t);
12381 +extern int vc_tag_migrate(uint32_t);
12383 +#endif /* _VSERVER_TAG_CMD_H */
12384 diff -NurpP --minimal linux-3.9.4/include/net/addrconf.h linux-3.9.4-vs2.3.6.2/include/net/addrconf.h
12385 --- linux-3.9.4/include/net/addrconf.h 2013-05-31 13:45:28.000000000 +0000
12386 +++ linux-3.9.4-vs2.3.6.2/include/net/addrconf.h 2013-05-31 17:17:53.000000000 +0000
12387 @@ -85,7 +85,8 @@ extern int ipv6_dev_get_saddr(struct n
12388 const struct net_device *dev,
12389 const struct in6_addr *daddr,
12390 unsigned int srcprefs,
12391 - struct in6_addr *saddr);
12392 + struct in6_addr *saddr,
12393 + struct nx_info *nxi);
12394 extern int ipv6_get_lladdr(struct net_device *dev,
12395 struct in6_addr *addr,
12396 unsigned char banned_flags);
12397 diff -NurpP --minimal linux-3.9.4/include/net/af_unix.h linux-3.9.4-vs2.3.6.2/include/net/af_unix.h
12398 --- linux-3.9.4/include/net/af_unix.h 2013-02-19 13:58:52.000000000 +0000
12399 +++ linux-3.9.4-vs2.3.6.2/include/net/af_unix.h 2013-05-31 17:17:53.000000000 +0000
12401 #include <linux/socket.h>
12402 #include <linux/un.h>
12403 #include <linux/mutex.h>
12404 +#include <linux/vs_base.h>
12405 #include <net/sock.h>
12407 extern void unix_inflight(struct file *fp);
12408 diff -NurpP --minimal linux-3.9.4/include/net/inet_timewait_sock.h linux-3.9.4-vs2.3.6.2/include/net/inet_timewait_sock.h
12409 --- linux-3.9.4/include/net/inet_timewait_sock.h 2013-05-31 13:45:28.000000000 +0000
12410 +++ linux-3.9.4-vs2.3.6.2/include/net/inet_timewait_sock.h 2013-05-31 17:18:34.000000000 +0000
12411 @@ -116,6 +116,10 @@ struct inet_timewait_sock {
12412 #define tw_dport __tw_common.skc_dport
12413 #define tw_num __tw_common.skc_num
12414 #define tw_portpair __tw_common.skc_portpair
12415 +#define tw_xid __tw_common.skc_xid
12416 +#define tw_vx_info __tw_common.skc_vx_info
12417 +#define tw_nid __tw_common.skc_nid
12418 +#define tw_nx_info __tw_common.skc_nx_info
12421 volatile unsigned char tw_substate;
12422 diff -NurpP --minimal linux-3.9.4/include/net/ip6_route.h linux-3.9.4-vs2.3.6.2/include/net/ip6_route.h
12423 --- linux-3.9.4/include/net/ip6_route.h 2013-05-31 13:45:28.000000000 +0000
12424 +++ linux-3.9.4-vs2.3.6.2/include/net/ip6_route.h 2013-05-31 17:17:53.000000000 +0000
12425 @@ -95,7 +95,8 @@ extern int ip6_route_get_saddr(struct
12426 struct rt6_info *rt,
12427 const struct in6_addr *daddr,
12428 unsigned int prefs,
12429 - struct in6_addr *saddr);
12430 + struct in6_addr *saddr,
12431 + struct nx_info *nxi);
12433 extern struct rt6_info *rt6_lookup(struct net *net,
12434 const struct in6_addr *daddr,
12435 diff -NurpP --minimal linux-3.9.4/include/net/route.h linux-3.9.4-vs2.3.6.2/include/net/route.h
12436 --- linux-3.9.4/include/net/route.h 2013-02-19 13:58:52.000000000 +0000
12437 +++ linux-3.9.4-vs2.3.6.2/include/net/route.h 2013-05-31 17:17:53.000000000 +0000
12438 @@ -207,6 +207,9 @@ static inline void ip_rt_put(struct rtab
12439 dst_release(&rt->dst);
12442 +#include <linux/vs_base.h>
12443 +#include <linux/vs_inet.h>
12445 #define IPTOS_RT_MASK (IPTOS_TOS_MASK & ~3)
12447 extern const __u8 ip_tos2prio[16];
12448 @@ -256,6 +259,9 @@ static inline void ip_route_connect_init
12449 protocol, flow_flags, dst, src, dport, sport);
12452 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
12453 + struct flowi4 *);
12455 static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
12456 __be32 dst, __be32 src, u32 tos,
12457 int oif, u8 protocol,
12458 @@ -264,11 +270,25 @@ static inline struct rtable *ip_route_co
12460 struct net *net = sock_net(sk);
12462 + struct nx_info *nx_info = current_nx_info();
12464 ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
12465 sport, dport, sk, can_sleep);
12467 - if (!dst || !src) {
12469 + nx_info = sk->sk_nx_info;
12471 + vxdprintk(VXD_CBIT(net, 4),
12472 + "ip_route_connect(%p) %p,%p;%lx",
12473 + sk, nx_info, sk->sk_socket,
12474 + (sk->sk_socket?sk->sk_socket->flags:0));
12476 + rt = ip_v4_find_src(net, nx_info, fl4);
12481 + if (!fl4->daddr || !fl4->saddr) {
12482 rt = __ip_route_output_key(net, fl4);
12485 diff -NurpP --minimal linux-3.9.4/include/net/sock.h linux-3.9.4-vs2.3.6.2/include/net/sock.h
12486 --- linux-3.9.4/include/net/sock.h 2013-05-31 14:22:27.000000000 +0000
12487 +++ linux-3.9.4-vs2.3.6.2/include/net/sock.h 2013-05-31 17:17:53.000000000 +0000
12488 @@ -191,6 +191,10 @@ struct sock_common {
12489 #ifdef CONFIG_NET_NS
12490 struct net *skc_net;
12493 + struct vx_info *skc_vx_info;
12495 + struct nx_info *skc_nx_info;
12497 * fields between dontcopy_begin/dontcopy_end
12498 * are not copied in sock_copy()
12499 @@ -304,6 +308,10 @@ struct sock {
12500 #define sk_bind_node __sk_common.skc_bind_node
12501 #define sk_prot __sk_common.skc_prot
12502 #define sk_net __sk_common.skc_net
12503 +#define sk_xid __sk_common.skc_xid
12504 +#define sk_vx_info __sk_common.skc_vx_info
12505 +#define sk_nid __sk_common.skc_nid
12506 +#define sk_nx_info __sk_common.skc_nx_info
12507 socket_lock_t sk_lock;
12508 struct sk_buff_head sk_receive_queue;
12510 diff -NurpP --minimal linux-3.9.4/include/uapi/Kbuild linux-3.9.4-vs2.3.6.2/include/uapi/Kbuild
12511 --- linux-3.9.4/include/uapi/Kbuild 2012-12-11 03:30:57.000000000 +0000
12512 +++ linux-3.9.4-vs2.3.6.2/include/uapi/Kbuild 2013-05-31 14:47:11.000000000 +0000
12513 @@ -12,3 +12,4 @@ header-y += video/
12517 +header-y += vserver/
12518 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/capability.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/capability.h
12519 --- linux-3.9.4/include/uapi/linux/capability.h 2012-12-11 03:30:57.000000000 +0000
12520 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/capability.h 2013-05-31 14:47:11.000000000 +0000
12521 @@ -259,6 +259,7 @@ struct vfs_cap_data {
12522 arbitrary SCSI commands */
12523 /* Allow setting encryption key on loopback filesystem */
12524 /* Allow setting zone reclaim policy */
12525 +/* Allow the selection of a security context */
12527 #define CAP_SYS_ADMIN 21
12529 @@ -345,7 +346,12 @@ struct vfs_cap_data {
12531 #define CAP_LAST_CAP CAP_BLOCK_SUSPEND
12533 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
12534 +/* Allow context manipulations */
12535 +/* Allow changing context info on files */
12537 +#define CAP_CONTEXT 63
12539 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
12542 * Bit location of each capability (used by user-space library and kernel)
12543 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/fs.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/fs.h
12544 --- linux-3.9.4/include/uapi/linux/fs.h 2013-05-31 13:45:29.000000000 +0000
12545 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/fs.h 2013-05-31 23:07:43.000000000 +0000
12546 @@ -86,6 +86,9 @@ struct inodes_stat_t {
12547 #define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */
12548 #define MS_I_VERSION (1<<23) /* Update inode I_version field */
12549 #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
12550 +#define MS_TAGGED (1<<8) /* use generic inode tagging */
12551 +#define MS_NOTAGCHECK (1<<9) /* don't check tags */
12552 +#define MS_TAGID (1<<25) /* use specific tag for this mount */
12554 /* These sb flags are internal to the kernel */
12555 #define MS_SNAP_STABLE (1<<27) /* Snapshot pages during writeback, if needed */
12556 @@ -192,11 +195,14 @@ struct inodes_stat_t {
12557 #define FS_EXTENT_FL 0x00080000 /* Extents */
12558 #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */
12559 #define FS_NOCOW_FL 0x00800000 /* Do not cow file */
12560 +#define FS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
12561 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
12563 -#define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
12564 -#define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
12565 +#define FS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
12566 +#define FS_COW_FL 0x20000000 /* Copy on Write marker */
12568 +#define FS_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
12569 +#define FS_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
12571 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
12572 #define SYNC_FILE_RANGE_WRITE 2
12573 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/gfs2_ondisk.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/gfs2_ondisk.h
12574 --- linux-3.9.4/include/uapi/linux/gfs2_ondisk.h 2012-12-11 03:30:57.000000000 +0000
12575 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/gfs2_ondisk.h 2013-05-31 14:47:11.000000000 +0000
12576 @@ -225,6 +225,9 @@ enum {
12579 gfs2fl_TopLevel = 10,
12580 + gfs2fl_IXUnlink = 16,
12581 + gfs2fl_Barrier = 17,
12583 gfs2fl_TruncInProg = 29,
12584 gfs2fl_InheritDirectio = 30,
12585 gfs2fl_InheritJdata = 31,
12586 @@ -242,6 +245,9 @@ enum {
12587 #define GFS2_DIF_SYNC 0x00000100
12588 #define GFS2_DIF_SYSTEM 0x00000200 /* New in gfs2 */
12589 #define GFS2_DIF_TOPDIR 0x00000400 /* New in gfs2 */
12590 +#define GFS2_DIF_IXUNLINK 0x00010000
12591 +#define GFS2_DIF_BARRIER 0x00020000
12592 +#define GFS2_DIF_COW 0x00040000
12593 #define GFS2_DIF_TRUNC_IN_PROG 0x20000000 /* New in gfs2 */
12594 #define GFS2_DIF_INHERIT_DIRECTIO 0x40000000 /* only in gfs1 */
12595 #define GFS2_DIF_INHERIT_JDATA 0x80000000
12596 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/if_tun.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/if_tun.h
12597 --- linux-3.9.4/include/uapi/linux/if_tun.h 2013-02-19 13:58:55.000000000 +0000
12598 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/if_tun.h 2013-05-31 15:00:16.000000000 +0000
12600 #define TUNGETVNETHDRSZ _IOR('T', 215, int)
12601 #define TUNSETVNETHDRSZ _IOW('T', 216, int)
12602 #define TUNSETQUEUE _IOW('T', 217, int)
12603 +#define TUNSETNID _IOW('T', 218, int)
12605 /* TUNSETIFF ifr flags */
12606 #define IFF_TUN 0x0001
12607 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/major.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/major.h
12608 --- linux-3.9.4/include/uapi/linux/major.h 2012-12-11 03:30:57.000000000 +0000
12609 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/major.h 2013-05-31 14:47:11.000000000 +0000
12611 #define HD_MAJOR IDE0_MAJOR
12612 #define PTY_SLAVE_MAJOR 3
12613 #define TTY_MAJOR 4
12614 +#define VROOT_MAJOR 4
12615 #define TTYAUX_MAJOR 5
12617 #define VCS_MAJOR 7
12618 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/nfs_mount.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/nfs_mount.h
12619 --- linux-3.9.4/include/uapi/linux/nfs_mount.h 2012-12-11 03:30:57.000000000 +0000
12620 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/nfs_mount.h 2013-05-31 14:47:11.000000000 +0000
12621 @@ -63,7 +63,8 @@ struct nfs_mount_data {
12622 #define NFS_MOUNT_SECFLAVOUR 0x2000 /* 5 */
12623 #define NFS_MOUNT_NORDIRPLUS 0x4000 /* 5 */
12624 #define NFS_MOUNT_UNSHARED 0x8000 /* 5 */
12625 -#define NFS_MOUNT_FLAGMASK 0xFFFF
12626 +#define NFS_MOUNT_TAGGED 0x10000 /* context tagging */
12627 +#define NFS_MOUNT_FLAGMASK 0x1FFFF
12629 /* The following are for internal use only */
12630 #define NFS_MOUNT_LOOKUP_CACHE_NONEG 0x10000
12631 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/reboot.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/reboot.h
12632 --- linux-3.9.4/include/uapi/linux/reboot.h 2012-12-11 03:30:57.000000000 +0000
12633 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/reboot.h 2013-05-31 14:47:11.000000000 +0000
12635 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
12636 #define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
12637 #define LINUX_REBOOT_CMD_KEXEC 0x45584543
12639 +#define LINUX_REBOOT_CMD_OOM 0xDEADBEEF
12642 #endif /* _UAPI_LINUX_REBOOT_H */
12643 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/sysctl.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/sysctl.h
12644 --- linux-3.9.4/include/uapi/linux/sysctl.h 2012-12-11 03:30:57.000000000 +0000
12645 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/sysctl.h 2013-05-31 14:47:11.000000000 +0000
12646 @@ -60,6 +60,7 @@ enum
12647 CTL_ABI=9, /* Binary emulation */
12648 CTL_CPU=10, /* CPU stuff (speed scaling, etc) */
12649 CTL_ARLAN=254, /* arlan wireless driver */
12650 + CTL_VSERVER=4242, /* Linux-VServer debug */
12651 CTL_S390DBF=5677, /* s390 debug */
12652 CTL_SUNRPC=7249, /* sunrpc debug */
12653 CTL_PM=9899, /* frv power management */
12654 @@ -94,6 +95,7 @@ enum
12656 KERN_PANIC=15, /* int: panic timeout */
12657 KERN_REALROOTDEV=16, /* real root device to mount after initrd */
12658 + KERN_VSHELPER=17, /* string: path to vshelper policy agent */
12660 KERN_SPARC_REBOOT=21, /* reboot command on Sparc */
12661 KERN_CTLALTDEL=22, /* int: allow ctl-alt-del to reboot */
12662 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/Kbuild linux-3.9.4-vs2.3.6.2/include/uapi/vserver/Kbuild
12663 --- linux-3.9.4/include/uapi/vserver/Kbuild 1970-01-01 00:00:00.000000000 +0000
12664 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/Kbuild 2013-05-31 14:47:11.000000000 +0000
12667 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12668 + cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12669 + inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12670 + debug_cmd.h device_cmd.h
12672 +header-y += switch.h context.h network.h monitor.h \
12673 + limit.h inode.h device.h
12675 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/cacct_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/cacct_cmd.h
12676 --- linux-3.9.4/include/uapi/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
12677 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/cacct_cmd.h 2013-05-31 14:47:11.000000000 +0000
12679 +#ifndef _UAPI_VS_CACCT_CMD_H
12680 +#define _UAPI_VS_CACCT_CMD_H
12683 +/* virtual host info name commands */
12685 +#define VCMD_sock_stat VC_CMD(VSTAT, 5, 0)
12687 +struct vcmd_sock_stat_v0 {
12689 + uint32_t count[3];
12690 + uint64_t total[3];
12693 +#endif /* _UAPI_VS_CACCT_CMD_H */
12694 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/context.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/context.h
12695 --- linux-3.9.4/include/uapi/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
12696 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/context.h 2013-05-31 19:44:13.000000000 +0000
12698 +#ifndef _UAPI_VS_CONTEXT_H
12699 +#define _UAPI_VS_CONTEXT_H
12701 +#include <linux/types.h>
12702 +#include <linux/capability.h>
12705 +/* context flags */
12707 +#define VXF_INFO_SCHED 0x00000002
12708 +#define VXF_INFO_NPROC 0x00000004
12709 +#define VXF_INFO_PRIVATE 0x00000008
12711 +#define VXF_INFO_INIT 0x00000010
12712 +#define VXF_INFO_HIDE 0x00000020
12713 +#define VXF_INFO_ULIMIT 0x00000040
12714 +#define VXF_INFO_NSPACE 0x00000080
12716 +#define VXF_SCHED_HARD 0x00000100
12717 +#define VXF_SCHED_PRIO 0x00000200
12718 +#define VXF_SCHED_PAUSE 0x00000400
12720 +#define VXF_VIRT_MEM 0x00010000
12721 +#define VXF_VIRT_UPTIME 0x00020000
12722 +#define VXF_VIRT_CPU 0x00040000
12723 +#define VXF_VIRT_LOAD 0x00080000
12724 +#define VXF_VIRT_TIME 0x00100000
12726 +#define VXF_HIDE_MOUNT 0x01000000
12727 +/* was VXF_HIDE_NETIF 0x02000000 */
12728 +#define VXF_HIDE_VINFO 0x04000000
12730 +#define VXF_STATE_SETUP (1ULL << 32)
12731 +#define VXF_STATE_INIT (1ULL << 33)
12732 +#define VXF_STATE_ADMIN (1ULL << 34)
12734 +#define VXF_SC_HELPER (1ULL << 36)
12735 +#define VXF_REBOOT_KILL (1ULL << 37)
12736 +#define VXF_PERSISTENT (1ULL << 38)
12738 +#define VXF_FORK_RSS (1ULL << 48)
12739 +#define VXF_PROLIFIC (1ULL << 49)
12741 +#define VXF_IGNEG_NICE (1ULL << 52)
12743 +#define VXF_ONE_TIME (0x0007ULL << 32)
12745 +#define VXF_INIT_SET (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12748 +/* context migration */
12750 +#define VXM_SET_INIT 0x00000001
12751 +#define VXM_SET_REAPER 0x00000002
12753 +/* context caps */
12755 +#define VXC_SET_UTSNAME 0x00000001
12756 +#define VXC_SET_RLIMIT 0x00000002
12757 +#define VXC_FS_SECURITY 0x00000004
12758 +#define VXC_FS_TRUSTED 0x00000008
12759 +#define VXC_TIOCSTI 0x00000010
12761 +/* was VXC_RAW_ICMP 0x00000100 */
12762 +#define VXC_SYSLOG 0x00001000
12763 +#define VXC_OOM_ADJUST 0x00002000
12764 +#define VXC_AUDIT_CONTROL 0x00004000
12766 +/* #define VXC_SECURE_MOUNT 0x00010000
12767 +#define VXC_SECURE_REMOUNT 0x00020000 */
12768 +#define VXC_BINARY_MOUNT 0x00040000
12769 +#define VXC_DEV_MOUNT 0x00080000
12771 +#define VXC_QUOTA_CTL 0x00100000
12772 +#define VXC_ADMIN_MAPPER 0x00200000
12773 +#define VXC_ADMIN_CLOOP 0x00400000
12775 +#define VXC_KTHREAD 0x01000000
12776 +#define VXC_NAMESPACE 0x02000000
12778 +#endif /* _UAPI_VS_CONTEXT_H */
12779 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/context_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/context_cmd.h
12780 --- linux-3.9.4/include/uapi/vserver/context_cmd.h 1970-01-01 00:00:00.000000000 +0000
12781 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/context_cmd.h 2013-05-31 14:47:11.000000000 +0000
12783 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12784 +#define _UAPI_VS_CONTEXT_CMD_H
12787 +/* vinfo commands */
12789 +#define VCMD_task_xid VC_CMD(VINFO, 1, 0)
12792 +#define VCMD_vx_info VC_CMD(VINFO, 5, 0)
12794 +struct vcmd_vx_info_v0 {
12796 + uint32_t initpid;
12797 + /* more to come */
12801 +#define VCMD_ctx_stat VC_CMD(VSTAT, 0, 0)
12803 +struct vcmd_ctx_stat_v0 {
12806 + /* more to come */
12810 +/* context commands */
12812 +#define VCMD_ctx_create_v0 VC_CMD(VPROC, 1, 0)
12813 +#define VCMD_ctx_create VC_CMD(VPROC, 1, 1)
12815 +struct vcmd_ctx_create {
12816 + uint64_t flagword;
12819 +#define VCMD_ctx_migrate_v0 VC_CMD(PROCMIG, 1, 0)
12820 +#define VCMD_ctx_migrate VC_CMD(PROCMIG, 1, 1)
12822 +struct vcmd_ctx_migrate {
12823 + uint64_t flagword;
12828 +/* flag commands */
12830 +#define VCMD_get_cflags VC_CMD(FLAGS, 1, 0)
12831 +#define VCMD_set_cflags VC_CMD(FLAGS, 2, 0)
12833 +struct vcmd_ctx_flags_v0 {
12834 + uint64_t flagword;
12840 +/* context caps commands */
12842 +#define VCMD_get_ccaps VC_CMD(FLAGS, 3, 1)
12843 +#define VCMD_set_ccaps VC_CMD(FLAGS, 4, 1)
12845 +struct vcmd_ctx_caps_v1 {
12852 +/* bcaps commands */
12854 +#define VCMD_get_bcaps VC_CMD(FLAGS, 9, 0)
12855 +#define VCMD_set_bcaps VC_CMD(FLAGS, 10, 0)
12857 +struct vcmd_bcaps {
12864 +/* umask commands */
12866 +#define VCMD_get_umask VC_CMD(FLAGS, 13, 0)
12867 +#define VCMD_set_umask VC_CMD(FLAGS, 14, 0)
12869 +struct vcmd_umask {
12876 +/* wmask commands */
12878 +#define VCMD_get_wmask VC_CMD(FLAGS, 15, 0)
12879 +#define VCMD_set_wmask VC_CMD(FLAGS, 16, 0)
12881 +struct vcmd_wmask {
12890 +#define VCMD_get_badness VC_CMD(MEMCTRL, 5, 0)
12891 +#define VCMD_set_badness VC_CMD(MEMCTRL, 6, 0)
12893 +struct vcmd_badness_v0 {
12897 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12898 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/cvirt_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/cvirt_cmd.h
12899 --- linux-3.9.4/include/uapi/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
12900 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/cvirt_cmd.h 2013-05-31 14:47:11.000000000 +0000
12902 +#ifndef _UAPI_VS_CVIRT_CMD_H
12903 +#define _UAPI_VS_CVIRT_CMD_H
12906 +/* virtual host info name commands */
12908 +#define VCMD_set_vhi_name VC_CMD(VHOST, 1, 0)
12909 +#define VCMD_get_vhi_name VC_CMD(VHOST, 2, 0)
12911 +struct vcmd_vhi_name_v0 {
12917 +enum vhi_name_field {
12918 + VHIN_CONTEXT = 0,
12929 +#define VCMD_virt_stat VC_CMD(VSTAT, 3, 0)
12931 +struct vcmd_virt_stat_v0 {
12934 + uint32_t nr_threads;
12935 + uint32_t nr_running;
12936 + uint32_t nr_uninterruptible;
12937 + uint32_t nr_onhold;
12938 + uint32_t nr_forks;
12939 + uint32_t load[3];
12942 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12943 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/debug_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/debug_cmd.h
12944 --- linux-3.9.4/include/uapi/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
12945 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/debug_cmd.h 2013-05-31 14:47:11.000000000 +0000
12947 +#ifndef _UAPI_VS_DEBUG_CMD_H
12948 +#define _UAPI_VS_DEBUG_CMD_H
12951 +/* debug commands */
12953 +#define VCMD_dump_history VC_CMD(DEBUG, 1, 0)
12955 +#define VCMD_read_history VC_CMD(DEBUG, 5, 0)
12956 +#define VCMD_read_monitor VC_CMD(DEBUG, 6, 0)
12958 +struct vcmd_read_history_v0 {
12961 + char __user *data;
12964 +struct vcmd_read_monitor_v0 {
12967 + char __user *data;
12970 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12971 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/device.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/device.h
12972 --- linux-3.9.4/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
12973 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/device.h 2013-05-31 14:47:11.000000000 +0000
12975 +#ifndef _UAPI_VS_DEVICE_H
12976 +#define _UAPI_VS_DEVICE_H
12979 +#define DATTR_CREATE 0x00000001
12980 +#define DATTR_OPEN 0x00000002
12982 +#define DATTR_REMAP 0x00000010
12984 +#define DATTR_MASK 0x00000013
12986 +#endif /* _UAPI_VS_DEVICE_H */
12987 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/device_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/device_cmd.h
12988 --- linux-3.9.4/include/uapi/vserver/device_cmd.h 1970-01-01 00:00:00.000000000 +0000
12989 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/device_cmd.h 2013-05-31 14:47:11.000000000 +0000
12991 +#ifndef _UAPI_VS_DEVICE_CMD_H
12992 +#define _UAPI_VS_DEVICE_CMD_H
12995 +/* device vserver commands */
12997 +#define VCMD_set_mapping VC_CMD(DEVICE, 1, 0)
12998 +#define VCMD_unset_mapping VC_CMD(DEVICE, 2, 0)
13000 +struct vcmd_set_mapping_v0 {
13001 + const char __user *device;
13002 + const char __user *target;
13006 +#endif /* _UAPI_VS_DEVICE_CMD_H */
13007 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/dlimit_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/dlimit_cmd.h
13008 --- linux-3.9.4/include/uapi/vserver/dlimit_cmd.h 1970-01-01 00:00:00.000000000 +0000
13009 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/dlimit_cmd.h 2013-05-31 14:47:11.000000000 +0000
13011 +#ifndef _UAPI_VS_DLIMIT_CMD_H
13012 +#define _UAPI_VS_DLIMIT_CMD_H
13015 +/* dlimit vserver commands */
13017 +#define VCMD_add_dlimit VC_CMD(DLIMIT, 1, 0)
13018 +#define VCMD_rem_dlimit VC_CMD(DLIMIT, 2, 0)
13020 +#define VCMD_set_dlimit VC_CMD(DLIMIT, 5, 0)
13021 +#define VCMD_get_dlimit VC_CMD(DLIMIT, 6, 0)
13023 +struct vcmd_ctx_dlimit_base_v0 {
13024 + const char __user *name;
13028 +struct vcmd_ctx_dlimit_v0 {
13029 + const char __user *name;
13030 + uint32_t space_used; /* used space in kbytes */
13031 + uint32_t space_total; /* maximum space in kbytes */
13032 + uint32_t inodes_used; /* used inodes */
13033 + uint32_t inodes_total; /* maximum inodes */
13034 + uint32_t reserved; /* reserved for root in % */
13038 +#define CDLIM_UNSET ((uint32_t)0UL)
13039 +#define CDLIM_INFINITY ((uint32_t)~0UL)
13040 +#define CDLIM_KEEP ((uint32_t)~1UL)
13042 +#define DLIME_UNIT 0
13043 +#define DLIME_KILO 1
13044 +#define DLIME_MEGA 2
13045 +#define DLIME_GIGA 3
13047 +#define DLIMF_SHIFT 0x10
13049 +#define DLIMS_USED 0
13050 +#define DLIMS_TOTAL 2
13053 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
13055 + int exp = (flags & DLIMF_SHIFT) ?
13056 + (flags >> shift) & DLIME_GIGA : DLIME_KILO;
13057 + return ((uint64_t)val) << (10 * exp);
13061 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
13065 + if (*flags & DLIMF_SHIFT) {
13066 + while (val > (1LL << 32) && (exp < 3)) {
13070 + *flags &= ~(DLIME_GIGA << shift);
13071 + *flags |= exp << shift;
13077 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
13078 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/inode.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/inode.h
13079 --- linux-3.9.4/include/uapi/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
13080 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/inode.h 2013-05-31 14:47:11.000000000 +0000
13082 +#ifndef _UAPI_VS_INODE_H
13083 +#define _UAPI_VS_INODE_H
13086 +#define IATTR_TAG 0x01000000
13088 +#define IATTR_ADMIN 0x00000001
13089 +#define IATTR_WATCH 0x00000002
13090 +#define IATTR_HIDE 0x00000004
13091 +#define IATTR_FLAGS 0x00000007
13093 +#define IATTR_BARRIER 0x00010000
13094 +#define IATTR_IXUNLINK 0x00020000
13095 +#define IATTR_IMMUTABLE 0x00040000
13096 +#define IATTR_COW 0x00080000
13099 +/* inode ioctls */
13101 +#define FIOC_GETXFLG _IOR('x', 5, long)
13102 +#define FIOC_SETXFLG _IOW('x', 6, long)
13104 +#endif /* _UAPI_VS_INODE_H */
13105 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/inode_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/inode_cmd.h
13106 --- linux-3.9.4/include/uapi/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
13107 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/inode_cmd.h 2013-05-31 14:47:11.000000000 +0000
13109 +#ifndef _UAPI_VS_INODE_CMD_H
13110 +#define _UAPI_VS_INODE_CMD_H
13113 +/* inode vserver commands */
13115 +#define VCMD_get_iattr VC_CMD(INODE, 1, 1)
13116 +#define VCMD_set_iattr VC_CMD(INODE, 2, 1)
13118 +#define VCMD_fget_iattr VC_CMD(INODE, 3, 0)
13119 +#define VCMD_fset_iattr VC_CMD(INODE, 4, 0)
13121 +struct vcmd_ctx_iattr_v1 {
13122 + const char __user *name;
13128 +struct vcmd_ctx_fiattr_v0 {
13134 +#endif /* _UAPI_VS_INODE_CMD_H */
13135 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/limit.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/limit.h
13136 --- linux-3.9.4/include/uapi/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
13137 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/limit.h 2013-05-31 14:47:11.000000000 +0000
13139 +#ifndef _UAPI_VS_LIMIT_H
13140 +#define _UAPI_VS_LIMIT_H
13143 +#define VLIMIT_NSOCK 16
13144 +#define VLIMIT_OPENFD 17
13145 +#define VLIMIT_ANON 18
13146 +#define VLIMIT_SHMEM 19
13147 +#define VLIMIT_SEMARY 20
13148 +#define VLIMIT_NSEMS 21
13149 +#define VLIMIT_DENTRY 22
13150 +#define VLIMIT_MAPPED 23
13152 +#endif /* _UAPI_VS_LIMIT_H */
13153 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/limit_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/limit_cmd.h
13154 --- linux-3.9.4/include/uapi/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
13155 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/limit_cmd.h 2013-05-31 14:47:11.000000000 +0000
13157 +#ifndef _UAPI_VS_LIMIT_CMD_H
13158 +#define _UAPI_VS_LIMIT_CMD_H
13161 +/* rlimit vserver commands */
13163 +#define VCMD_get_rlimit VC_CMD(RLIMIT, 1, 0)
13164 +#define VCMD_set_rlimit VC_CMD(RLIMIT, 2, 0)
13165 +#define VCMD_get_rlimit_mask VC_CMD(RLIMIT, 3, 0)
13166 +#define VCMD_reset_hits VC_CMD(RLIMIT, 7, 0)
13167 +#define VCMD_reset_minmax VC_CMD(RLIMIT, 9, 0)
13169 +struct vcmd_ctx_rlimit_v0 {
13171 + uint64_t minimum;
13172 + uint64_t softlimit;
13173 + uint64_t maximum;
13176 +struct vcmd_ctx_rlimit_mask_v0 {
13177 + uint32_t minimum;
13178 + uint32_t softlimit;
13179 + uint32_t maximum;
13182 +#define VCMD_rlimit_stat VC_CMD(VSTAT, 1, 0)
13184 +struct vcmd_rlimit_stat_v0 {
13188 + uint64_t minimum;
13189 + uint64_t maximum;
13192 +#define CRLIM_UNSET (0ULL)
13193 +#define CRLIM_INFINITY (~0ULL)
13194 +#define CRLIM_KEEP (~1ULL)
13196 +#endif /* _UAPI_VS_LIMIT_CMD_H */
13197 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/monitor.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/monitor.h
13198 --- linux-3.9.4/include/uapi/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
13199 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/monitor.h 2013-05-31 14:47:11.000000000 +0000
13201 +#ifndef _UAPI_VS_MONITOR_H
13202 +#define _UAPI_VS_MONITOR_H
13204 +#include <linux/types.h>
13212 + VXM_UPDATE = 0x20,
13216 + VXM_RQINFO_1 = 0x24,
13219 + VXM_ACTIVATE = 0x40,
13226 + VXM_MIGRATE = 0x48,
13229 + /* all other bits are flags */
13230 + VXM_SCHED = 0x80,
13233 +struct _vxm_update_1 {
13234 + uint32_t tokens_max;
13235 + uint32_t fill_rate;
13236 + uint32_t interval;
13239 +struct _vxm_update_2 {
13240 + uint32_t tokens_min;
13241 + uint32_t fill_rate;
13242 + uint32_t interval;
13245 +struct _vxm_rqinfo_1 {
13246 + uint16_t running;
13250 + uint32_t idle_tokens;
13253 +struct _vxm_rqinfo_2 {
13254 + uint32_t norm_time;
13255 + uint32_t idle_time;
13256 + uint32_t idle_skip;
13259 +struct _vxm_sched {
13261 + uint32_t norm_time;
13262 + uint32_t idle_time;
13265 +struct _vxm_task {
13270 +struct _vxm_event {
13279 + struct _vxm_task tsk;
13283 +struct _vx_mon_entry {
13287 + struct _vxm_event ev;
13288 + struct _vxm_sched sd;
13289 + struct _vxm_update_1 u1;
13290 + struct _vxm_update_2 u2;
13291 + struct _vxm_rqinfo_1 q1;
13292 + struct _vxm_rqinfo_2 q2;
13296 +#endif /* _UAPI_VS_MONITOR_H */
13297 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/network.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/network.h
13298 --- linux-3.9.4/include/uapi/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
13299 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/network.h 2013-05-31 14:47:11.000000000 +0000
13301 +#ifndef _UAPI_VS_NETWORK_H
13302 +#define _UAPI_VS_NETWORK_H
13304 +#include <linux/types.h>
13307 +#define MAX_N_CONTEXT 65535 /* Arbitrary limit */
13310 +/* network flags */
13312 +#define NXF_INFO_PRIVATE 0x00000008
13314 +#define NXF_SINGLE_IP 0x00000100
13315 +#define NXF_LBACK_REMAP 0x00000200
13316 +#define NXF_LBACK_ALLOW 0x00000400
13318 +#define NXF_HIDE_NETIF 0x02000000
13319 +#define NXF_HIDE_LBACK 0x04000000
13321 +#define NXF_STATE_SETUP (1ULL << 32)
13322 +#define NXF_STATE_ADMIN (1ULL << 34)
13324 +#define NXF_SC_HELPER (1ULL << 36)
13325 +#define NXF_PERSISTENT (1ULL << 38)
13327 +#define NXF_ONE_TIME (0x0005ULL << 32)
13330 +#define NXF_INIT_SET (__nxf_init_set())
13332 +static inline uint64_t __nxf_init_set(void) {
13333 + return NXF_STATE_ADMIN
13334 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13335 + | NXF_LBACK_REMAP
13338 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13341 + | NXF_HIDE_NETIF;
13345 +/* network caps */
13347 +#define NXC_TUN_CREATE 0x00000001
13349 +#define NXC_RAW_ICMP 0x00000100
13351 +#define NXC_MULTICAST 0x00001000
13354 +/* address types */
13356 +#define NXA_TYPE_IPV4 0x0001
13357 +#define NXA_TYPE_IPV6 0x0002
13359 +#define NXA_TYPE_NONE 0x0000
13360 +#define NXA_TYPE_ANY 0x00FF
13362 +#define NXA_TYPE_ADDR 0x0010
13363 +#define NXA_TYPE_MASK 0x0020
13364 +#define NXA_TYPE_RANGE 0x0040
13366 +#define NXA_MASK_ALL (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13368 +#define NXA_MOD_BCAST 0x0100
13369 +#define NXA_MOD_LBACK 0x0200
13371 +#define NXA_LOOPBACK 0x1000
13373 +#define NXA_MASK_BIND (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13374 +#define NXA_MASK_SHOW (NXA_MASK_ALL | NXA_LOOPBACK)
13376 +#endif /* _UAPI_VS_NETWORK_H */
13377 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/network_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/network_cmd.h
13378 --- linux-3.9.4/include/uapi/vserver/network_cmd.h 1970-01-01 00:00:00.000000000 +0000
13379 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/network_cmd.h 2013-05-31 14:47:11.000000000 +0000
13381 +#ifndef _UAPI_VS_NETWORK_CMD_H
13382 +#define _UAPI_VS_NETWORK_CMD_H
13385 +/* vinfo commands */
13387 +#define VCMD_task_nid VC_CMD(VINFO, 2, 0)
13390 +#define VCMD_nx_info VC_CMD(VINFO, 6, 0)
13392 +struct vcmd_nx_info_v0 {
13394 + /* more to come */
13398 +#include <linux/in.h>
13399 +#include <linux/in6.h>
13401 +#define VCMD_net_create_v0 VC_CMD(VNET, 1, 0)
13402 +#define VCMD_net_create VC_CMD(VNET, 1, 1)
13404 +struct vcmd_net_create {
13405 + uint64_t flagword;
13408 +#define VCMD_net_migrate VC_CMD(NETMIG, 1, 0)
13410 +#define VCMD_net_add VC_CMD(NETALT, 1, 0)
13411 +#define VCMD_net_remove VC_CMD(NETALT, 2, 0)
13413 +struct vcmd_net_addr_v0 {
13416 + struct in_addr ip[4];
13417 + struct in_addr mask[4];
13420 +#define VCMD_net_add_ipv4_v1 VC_CMD(NETALT, 1, 1)
13421 +#define VCMD_net_rem_ipv4_v1 VC_CMD(NETALT, 2, 1)
13423 +struct vcmd_net_addr_ipv4_v1 {
13426 + struct in_addr ip;
13427 + struct in_addr mask;
13430 +#define VCMD_net_add_ipv4 VC_CMD(NETALT, 1, 2)
13431 +#define VCMD_net_rem_ipv4 VC_CMD(NETALT, 2, 2)
13433 +struct vcmd_net_addr_ipv4_v2 {
13436 + struct in_addr ip;
13437 + struct in_addr ip2;
13438 + struct in_addr mask;
13441 +#define VCMD_net_add_ipv6 VC_CMD(NETALT, 3, 1)
13442 +#define VCMD_net_remove_ipv6 VC_CMD(NETALT, 4, 1)
13444 +struct vcmd_net_addr_ipv6_v1 {
13448 + struct in6_addr ip;
13449 + struct in6_addr mask;
13452 +#define VCMD_add_match_ipv4 VC_CMD(NETALT, 5, 0)
13453 +#define VCMD_get_match_ipv4 VC_CMD(NETALT, 6, 0)
13455 +struct vcmd_match_ipv4_v0 {
13460 + struct in_addr ip;
13461 + struct in_addr ip2;
13462 + struct in_addr mask;
13465 +#define VCMD_add_match_ipv6 VC_CMD(NETALT, 7, 0)
13466 +#define VCMD_get_match_ipv6 VC_CMD(NETALT, 8, 0)
13468 +struct vcmd_match_ipv6_v0 {
13473 + struct in6_addr ip;
13474 + struct in6_addr ip2;
13475 + struct in6_addr mask;
13481 +/* flag commands */
13483 +#define VCMD_get_nflags VC_CMD(FLAGS, 5, 0)
13484 +#define VCMD_set_nflags VC_CMD(FLAGS, 6, 0)
13486 +struct vcmd_net_flags_v0 {
13487 + uint64_t flagword;
13493 +/* network caps commands */
13495 +#define VCMD_get_ncaps VC_CMD(FLAGS, 7, 0)
13496 +#define VCMD_set_ncaps VC_CMD(FLAGS, 8, 0)
13498 +struct vcmd_net_caps_v0 {
13503 +#endif /* _UAPI_VS_NETWORK_CMD_H */
13504 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/sched_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/sched_cmd.h
13505 --- linux-3.9.4/include/uapi/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
13506 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/sched_cmd.h 2013-05-31 14:47:11.000000000 +0000
13508 +#ifndef _UAPI_VS_SCHED_CMD_H
13509 +#define _UAPI_VS_SCHED_CMD_H
13512 +struct vcmd_prio_bias {
13514 + int32_t prio_bias;
13517 +#define VCMD_set_prio_bias VC_CMD(SCHED, 4, 0)
13518 +#define VCMD_get_prio_bias VC_CMD(SCHED, 5, 0)
13520 +#endif /* _UAPI_VS_SCHED_CMD_H */
13521 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/signal_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/signal_cmd.h
13522 --- linux-3.9.4/include/uapi/vserver/signal_cmd.h 1970-01-01 00:00:00.000000000 +0000
13523 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/signal_cmd.h 2013-05-31 14:47:11.000000000 +0000
13525 +#ifndef _UAPI_VS_SIGNAL_CMD_H
13526 +#define _UAPI_VS_SIGNAL_CMD_H
13529 +/* signalling vserver commands */
13531 +#define VCMD_ctx_kill VC_CMD(PROCTRL, 1, 0)
13532 +#define VCMD_wait_exit VC_CMD(EVENT, 99, 0)
13534 +struct vcmd_ctx_kill_v0 {
13539 +struct vcmd_wait_exit_v0 {
13540 + int32_t reboot_cmd;
13541 + int32_t exit_code;
13545 +/* process alteration commands */
13547 +#define VCMD_get_pflags VC_CMD(PROCALT, 5, 0)
13548 +#define VCMD_set_pflags VC_CMD(PROCALT, 6, 0)
13550 +struct vcmd_pflags_v0 {
13551 + uint32_t flagword;
13555 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
13556 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/space_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/space_cmd.h
13557 --- linux-3.9.4/include/uapi/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
13558 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/space_cmd.h 2013-05-31 14:47:11.000000000 +0000
13560 +#ifndef _UAPI_VS_SPACE_CMD_H
13561 +#define _UAPI_VS_SPACE_CMD_H
13564 +#define VCMD_enter_space_v0 VC_CMD(PROCALT, 1, 0)
13565 +#define VCMD_enter_space_v1 VC_CMD(PROCALT, 1, 1)
13566 +#define VCMD_enter_space VC_CMD(PROCALT, 1, 2)
13568 +#define VCMD_set_space_v0 VC_CMD(PROCALT, 3, 0)
13569 +#define VCMD_set_space_v1 VC_CMD(PROCALT, 3, 1)
13570 +#define VCMD_set_space VC_CMD(PROCALT, 3, 2)
13572 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13574 +#define VCMD_get_space_mask VC_CMD(VSPACE, 0, 1)
13575 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13578 +struct vcmd_space_mask_v1 {
13582 +struct vcmd_space_mask_v2 {
13587 +#endif /* _UAPI_VS_SPACE_CMD_H */
13588 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/switch.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/switch.h
13589 --- linux-3.9.4/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
13590 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/switch.h 2013-05-31 14:47:11.000000000 +0000
13592 +#ifndef _UAPI_VS_SWITCH_H
13593 +#define _UAPI_VS_SWITCH_H
13595 +#include <linux/types.h>
13598 +#define VC_CATEGORY(c) (((c) >> 24) & 0x3F)
13599 +#define VC_COMMAND(c) (((c) >> 16) & 0xFF)
13600 +#define VC_VERSION(c) ((c) & 0xFFF)
13602 +#define VC_CMD(c, i, v) ((((VC_CAT_ ## c) & 0x3F) << 24) \
13603 + | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13607 + Syscall Matrix V2.8
13609 + |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13610 + |STATS |DESTROY|ALTER |CHANGE |LIMIT |TEST | | | |
13611 + |INFO |SETUP | |MOVE | | | | | |
13612 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13613 + SYSTEM |VERSION|VSETUP |VHOST | | | | |DEVICE | |
13614 + HOST | 00| 01| 02| 03| 04| 05| | 06| 07|
13615 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13616 + CPU | |VPROC |PROCALT|PROCMIG|PROCTRL| | |SCHED. | |
13617 + PROCESS| 08| 09| 10| 11| 12| 13| | 14| 15|
13618 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13619 + MEMORY | | | | |MEMCTRL| | |SWAP | |
13620 + | 16| 17| 18| 19| 20| 21| | 22| 23|
13621 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13622 + NETWORK| |VNET |NETALT |NETMIG |NETCTL | | |SERIAL | |
13623 + | 24| 25| 26| 27| 28| 29| | 30| 31|
13624 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13625 + DISK | | | |TAGMIG |DLIMIT | | |INODE | |
13626 + VFS | 32| 33| 34| 35| 36| 37| | 38| 39|
13627 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13628 + OTHER |VSTAT | | | | | | |VINFO | |
13629 + | 40| 41| 42| 43| 44| 45| | 46| 47|
13630 + =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13631 + SPECIAL|EVENT | | | |FLAGS | | |VSPACE | |
13632 + | 48| 49| 50| 51| 52| 53| | 54| 55|
13633 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13634 + SPECIAL|DEBUG | | | |RLIMIT |SYSCALL| | |COMPAT |
13635 + | 56| 57| 58| 59| 60|TEST 61| | 62| 63|
13636 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13640 +#define VC_CAT_VERSION 0
13642 +#define VC_CAT_VSETUP 1
13643 +#define VC_CAT_VHOST 2
13645 +#define VC_CAT_DEVICE 6
13647 +#define VC_CAT_VPROC 9
13648 +#define VC_CAT_PROCALT 10
13649 +#define VC_CAT_PROCMIG 11
13650 +#define VC_CAT_PROCTRL 12
13652 +#define VC_CAT_SCHED 14
13653 +#define VC_CAT_MEMCTRL 20
13655 +#define VC_CAT_VNET 25
13656 +#define VC_CAT_NETALT 26
13657 +#define VC_CAT_NETMIG 27
13658 +#define VC_CAT_NETCTRL 28
13660 +#define VC_CAT_TAGMIG 35
13661 +#define VC_CAT_DLIMIT 36
13662 +#define VC_CAT_INODE 38
13664 +#define VC_CAT_VSTAT 40
13665 +#define VC_CAT_VINFO 46
13666 +#define VC_CAT_EVENT 48
13668 +#define VC_CAT_FLAGS 52
13669 +#define VC_CAT_VSPACE 54
13670 +#define VC_CAT_DEBUG 56
13671 +#define VC_CAT_RLIMIT 60
13673 +#define VC_CAT_SYSTEST 61
13674 +#define VC_CAT_COMPAT 63
13676 +/* query version */
13678 +#define VCMD_get_version VC_CMD(VERSION, 0, 0)
13679 +#define VCMD_get_vci VC_CMD(VERSION, 1, 0)
13681 +#endif /* _UAPI_VS_SWITCH_H */
13682 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/tag_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/tag_cmd.h
13683 --- linux-3.9.4/include/uapi/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
13684 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/tag_cmd.h 2013-05-31 14:47:11.000000000 +0000
13686 +#ifndef _UAPI_VS_TAG_CMD_H
13687 +#define _UAPI_VS_TAG_CMD_H
13690 +/* vinfo commands */
13692 +#define VCMD_task_tag VC_CMD(VINFO, 3, 0)
13695 +/* context commands */
13697 +#define VCMD_tag_migrate VC_CMD(TAGMIG, 1, 0)
13699 +#endif /* _UAPI_VS_TAG_CMD_H */
13700 diff -NurpP --minimal linux-3.9.4/init/Kconfig linux-3.9.4-vs2.3.6.2/init/Kconfig
13701 --- linux-3.9.4/init/Kconfig 2013-05-31 13:45:29.000000000 +0000
13702 +++ linux-3.9.4-vs2.3.6.2/init/Kconfig 2013-05-31 14:47:11.000000000 +0000
13703 @@ -760,6 +760,7 @@ config NUMA_BALANCING
13705 boolean "Control Group support"
13709 This option adds support for grouping sets of processes together, for
13710 use with process control subsystems such as Cpusets, CFS, memory
13711 @@ -1022,6 +1023,7 @@ config IPC_NS
13713 bool "User namespace"
13714 depends on UIDGID_CONVERTED
13715 + depends on VSERVER_DISABLED
13716 select UIDGID_STRICT_TYPE_CHECKS
13719 diff -NurpP --minimal linux-3.9.4/init/main.c linux-3.9.4-vs2.3.6.2/init/main.c
13720 --- linux-3.9.4/init/main.c 2013-05-31 13:45:29.000000000 +0000
13721 +++ linux-3.9.4-vs2.3.6.2/init/main.c 2013-05-31 15:09:17.000000000 +0000
13723 #include <linux/ptrace.h>
13724 #include <linux/blkdev.h>
13725 #include <linux/elevator.h>
13726 +#include <linux/vserver/percpu.h>
13728 #include <asm/io.h>
13729 #include <asm/bugs.h>
13730 diff -NurpP --minimal linux-3.9.4/ipc/mqueue.c linux-3.9.4-vs2.3.6.2/ipc/mqueue.c
13731 --- linux-3.9.4/ipc/mqueue.c 2013-05-31 13:45:29.000000000 +0000
13732 +++ linux-3.9.4-vs2.3.6.2/ipc/mqueue.c 2013-05-31 14:47:11.000000000 +0000
13734 #include <linux/ipc_namespace.h>
13735 #include <linux/user_namespace.h>
13736 #include <linux/slab.h>
13737 +#include <linux/vs_context.h>
13738 +#include <linux/vs_limit.h>
13740 #include <net/sock.h>
13742 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13743 struct pid* notify_owner;
13744 struct user_namespace *notify_user_ns;
13745 struct user_struct *user; /* user who created, for accounting */
13746 + struct vx_info *vxi;
13747 struct sock *notify_sock;
13748 struct sk_buff *notify_cookie;
13750 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13751 if (S_ISREG(mode)) {
13752 struct mqueue_inode_info *info;
13753 unsigned long mq_bytes, mq_treesize;
13754 + struct vx_info *vxi = current_vx_info();
13756 inode->i_fop = &mqueue_file_operations;
13757 inode->i_size = FILENT_SIZE;
13758 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13759 info->notify_user_ns = NULL;
13761 info->user = NULL; /* set when all is ok */
13762 + info->vxi = NULL;
13763 info->msg_tree = RB_ROOT;
13764 info->node_cache = NULL;
13765 memset(&info->attr, 0, sizeof(info->attr));
13766 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13768 spin_lock(&mq_lock);
13769 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13770 - u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13771 + u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13772 + !vx_ipcmsg_avail(vxi, mq_bytes)) {
13773 spin_unlock(&mq_lock);
13774 /* mqueue_evict_inode() releases info->messages */
13778 u->mq_bytes += mq_bytes;
13779 + vx_ipcmsg_add(vxi, u, mq_bytes);
13780 spin_unlock(&mq_lock);
13783 info->user = get_uid(u);
13784 + info->vxi = get_vx_info(vxi);
13785 } else if (S_ISDIR(mode)) {
13787 /* Some things misbehave if size == 0 on a directory */
13788 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13792 + struct vx_info *vxi = info->vxi;
13794 spin_lock(&mq_lock);
13795 user->mq_bytes -= mq_bytes;
13796 + vx_ipcmsg_sub(vxi, user, mq_bytes);
13798 * get_ns_from_inode() ensures that the
13799 * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13800 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13802 ipc_ns->mq_queues_count--;
13803 spin_unlock(&mq_lock);
13804 + put_vx_info(vxi);
13808 diff -NurpP --minimal linux-3.9.4/ipc/msg.c linux-3.9.4-vs2.3.6.2/ipc/msg.c
13809 --- linux-3.9.4/ipc/msg.c 2013-05-31 13:45:29.000000000 +0000
13810 +++ linux-3.9.4-vs2.3.6.2/ipc/msg.c 2013-05-31 14:47:11.000000000 +0000
13812 #include <linux/rwsem.h>
13813 #include <linux/nsproxy.h>
13814 #include <linux/ipc_namespace.h>
13815 +#include <linux/vs_base.h>
13817 #include <asm/current.h>
13818 #include <asm/uaccess.h>
13819 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
13821 msq->q_perm.mode = msgflg & S_IRWXUGO;
13822 msq->q_perm.key = key;
13823 + msq->q_perm.xid = vx_current_xid();
13825 msq->q_perm.security = NULL;
13826 retval = security_msg_queue_alloc(msq);
13827 diff -NurpP --minimal linux-3.9.4/ipc/sem.c linux-3.9.4-vs2.3.6.2/ipc/sem.c
13828 --- linux-3.9.4/ipc/sem.c 2012-12-11 03:30:57.000000000 +0000
13829 +++ linux-3.9.4-vs2.3.6.2/ipc/sem.c 2013-05-31 14:47:11.000000000 +0000
13831 #include <linux/rwsem.h>
13832 #include <linux/nsproxy.h>
13833 #include <linux/ipc_namespace.h>
13834 +#include <linux/vs_base.h>
13835 +#include <linux/vs_limit.h>
13837 #include <asm/uaccess.h>
13839 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
13841 sma->sem_perm.mode = (semflg & S_IRWXUGO);
13842 sma->sem_perm.key = key;
13843 + sma->sem_perm.xid = vx_current_xid();
13845 sma->sem_perm.security = NULL;
13846 retval = security_sem_alloc(sma);
13847 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
13850 ns->used_sems += nsems;
13851 + /* FIXME: obsoleted? */
13852 + vx_semary_inc(sma);
13853 + vx_nsems_add(sma, nsems);
13855 sma->sem_base = (struct sem *) &sma[1];
13857 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
13859 wake_up_sem_queue_do(&tasks);
13860 ns->used_sems -= sma->sem_nsems;
13861 + /* FIXME: obsoleted? */
13862 + vx_nsems_sub(sma, sma->sem_nsems);
13863 + vx_semary_dec(sma);
13864 security_sem_free(sma);
13865 ipc_rcu_putref(sma);
13867 diff -NurpP --minimal linux-3.9.4/ipc/shm.c linux-3.9.4-vs2.3.6.2/ipc/shm.c
13868 --- linux-3.9.4/ipc/shm.c 2013-05-31 14:22:27.000000000 +0000
13869 +++ linux-3.9.4-vs2.3.6.2/ipc/shm.c 2013-05-31 14:47:11.000000000 +0000
13871 #include <linux/nsproxy.h>
13872 #include <linux/mount.h>
13873 #include <linux/ipc_namespace.h>
13874 +#include <linux/vs_context.h>
13875 +#include <linux/vs_limit.h>
13877 #include <asm/uaccess.h>
13879 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
13881 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13883 - ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13884 + struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13885 + int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13887 + vx_ipcshm_sub(vxi, shp, numpages);
13888 + ns->shm_tot -= numpages;
13892 if (!is_file_hugepages(shp->shm_file))
13893 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
13895 fput (shp->shm_file);
13896 security_shm_free(shp);
13897 + put_vx_info(vxi);
13898 ipc_rcu_putref(shp);
13901 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
13902 if (ns->shm_tot + numpages > ns->shm_ctlall)
13905 + if (!vx_ipcshm_avail(current_vx_info(), numpages))
13908 shp = ipc_rcu_alloc(sizeof(*shp));
13912 shp->shm_perm.key = key;
13913 + shp->shm_perm.xid = vx_current_xid();
13914 shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13915 shp->mlock_user = NULL;
13917 @@ -544,6 +556,7 @@ static int newseg(struct ipc_namespace *
13918 ns->shm_tot += numpages;
13919 error = shp->shm_perm.id;
13921 + vx_ipcshm_add(current_vx_info(), key, numpages);
13925 diff -NurpP --minimal linux-3.9.4/kernel/Makefile linux-3.9.4-vs2.3.6.2/kernel/Makefile
13926 --- linux-3.9.4/kernel/Makefile 2013-05-31 14:22:27.000000000 +0000
13927 +++ linux-3.9.4-vs2.3.6.2/kernel/Makefile 2013-05-31 14:47:11.000000000 +0000
13928 @@ -24,6 +24,7 @@ endif
13934 obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13935 obj-$(CONFIG_FREEZER) += freezer.o
13936 diff -NurpP --minimal linux-3.9.4/kernel/auditsc.c linux-3.9.4-vs2.3.6.2/kernel/auditsc.c
13937 --- linux-3.9.4/kernel/auditsc.c 2013-05-31 14:22:27.000000000 +0000
13938 +++ linux-3.9.4-vs2.3.6.2/kernel/auditsc.c 2013-05-31 14:47:11.000000000 +0000
13939 @@ -2315,7 +2315,7 @@ int audit_set_loginuid(kuid_t loginuid)
13940 if (audit_loginuid_set(task))
13942 #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13943 - if (!capable(CAP_AUDIT_CONTROL))
13944 + if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13946 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13948 diff -NurpP --minimal linux-3.9.4/kernel/capability.c linux-3.9.4-vs2.3.6.2/kernel/capability.c
13949 --- linux-3.9.4/kernel/capability.c 2013-05-31 13:45:29.000000000 +0000
13950 +++ linux-3.9.4-vs2.3.6.2/kernel/capability.c 2013-05-31 14:47:11.000000000 +0000
13952 #include <linux/syscalls.h>
13953 #include <linux/pid_namespace.h>
13954 #include <linux/user_namespace.h>
13955 +#include <linux/vs_context.h>
13956 #include <asm/uaccess.h>
13959 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13965 * The only thing that can change the capabilities of the current
13966 * process is the current process. As such, we can't be in this code
13967 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13971 +#include <linux/vserver/base.h>
13974 * has_capability_noaudit - Does a task have a capability (unaudited) in the
13976 diff -NurpP --minimal linux-3.9.4/kernel/compat.c linux-3.9.4-vs2.3.6.2/kernel/compat.c
13977 --- linux-3.9.4/kernel/compat.c 2013-05-31 13:45:29.000000000 +0000
13978 +++ linux-3.9.4-vs2.3.6.2/kernel/compat.c 2013-05-31 14:47:11.000000000 +0000
13980 #include <linux/times.h>
13981 #include <linux/ptrace.h>
13982 #include <linux/gfp.h>
13983 +#include <linux/vs_time.h>
13985 #include <asm/uaccess.h>
13987 @@ -1059,7 +1060,7 @@ asmlinkage long compat_sys_stime(compat_
13991 - do_settimeofday(&tv);
13992 + vx_settimeofday(&tv);
13996 diff -NurpP --minimal linux-3.9.4/kernel/cred.c linux-3.9.4-vs2.3.6.2/kernel/cred.c
13997 --- linux-3.9.4/kernel/cred.c 2013-02-19 13:58:56.000000000 +0000
13998 +++ linux-3.9.4-vs2.3.6.2/kernel/cred.c 2013-05-31 14:47:11.000000000 +0000
13999 @@ -56,31 +56,6 @@ struct cred init_cred = {
14000 .group_info = &init_groups,
14003 -static inline void set_cred_subscribers(struct cred *cred, int n)
14005 -#ifdef CONFIG_DEBUG_CREDENTIALS
14006 - atomic_set(&cred->subscribers, n);
14010 -static inline int read_cred_subscribers(const struct cred *cred)
14012 -#ifdef CONFIG_DEBUG_CREDENTIALS
14013 - return atomic_read(&cred->subscribers);
14019 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14021 -#ifdef CONFIG_DEBUG_CREDENTIALS
14022 - struct cred *cred = (struct cred *) _cred;
14024 - atomic_add(n, &cred->subscribers);
14029 * The RCU callback to actually dispose of a set of credentials
14031 @@ -232,21 +207,16 @@ error:
14033 * Call commit_creds() or abort_creds() to clean up.
14035 -struct cred *prepare_creds(void)
14036 +struct cred *__prepare_creds(const struct cred *old)
14038 - struct task_struct *task = current;
14039 - const struct cred *old;
14042 - validate_process_creds();
14044 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14048 kdebug("prepare_creds() alloc %p", new);
14050 - old = task->cred;
14051 memcpy(new, old, sizeof(struct cred));
14053 atomic_set(&new->usage, 1);
14054 @@ -275,6 +245,13 @@ error:
14059 +struct cred *prepare_creds(void)
14061 + validate_process_creds();
14063 + return __prepare_creds(current->cred);
14065 EXPORT_SYMBOL(prepare_creds);
14068 diff -NurpP --minimal linux-3.9.4/kernel/exit.c linux-3.9.4-vs2.3.6.2/kernel/exit.c
14069 --- linux-3.9.4/kernel/exit.c 2013-05-31 13:45:29.000000000 +0000
14070 +++ linux-3.9.4-vs2.3.6.2/kernel/exit.c 2013-05-31 14:47:11.000000000 +0000
14072 #include <linux/fs_struct.h>
14073 #include <linux/init_task.h>
14074 #include <linux/perf_event.h>
14075 +#include <linux/vs_limit.h>
14076 +#include <linux/vs_context.h>
14077 +#include <linux/vs_network.h>
14078 +#include <linux/vs_pid.h>
14079 #include <trace/events/sched.h>
14080 #include <linux/hw_breakpoint.h>
14081 #include <linux/oom.h>
14082 @@ -514,15 +518,25 @@ static struct task_struct *find_new_reap
14083 __acquires(&tasklist_lock)
14085 struct pid_namespace *pid_ns = task_active_pid_ns(father);
14086 - struct task_struct *thread;
14087 + struct vx_info *vxi = task_get_vx_info(father);
14088 + struct task_struct *thread = father;
14089 + struct task_struct *reaper;
14092 while_each_thread(father, thread) {
14093 if (thread->flags & PF_EXITING)
14095 if (unlikely(pid_ns->child_reaper == father))
14096 pid_ns->child_reaper = thread;
14102 + reaper = pid_ns->child_reaper;
14104 + BUG_ON(!vxi->vx_reaper);
14105 + if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14106 + vxi->vx_reaper != father)
14107 + reaper = vxi->vx_reaper;
14110 if (unlikely(pid_ns->child_reaper == father)) {
14111 @@ -560,7 +574,9 @@ static struct task_struct *find_new_reap
14115 - return pid_ns->child_reaper;
14117 + put_vx_info(vxi);
14122 @@ -611,10 +627,15 @@ static void forget_original_parent(struc
14123 list_for_each_entry_safe(p, n, &father->children, sibling) {
14124 struct task_struct *t = p;
14126 - t->real_parent = reaper;
14127 + struct task_struct *new_parent = reaper;
14129 + if (unlikely(p == reaper))
14130 + new_parent = task_active_pid_ns(p)->child_reaper;
14132 + t->real_parent = new_parent;
14133 if (t->parent == father) {
14135 - t->parent = t->real_parent;
14136 + t->parent = new_parent;
14138 if (t->pdeath_signal)
14139 group_send_sig_info(t->pdeath_signal,
14140 @@ -821,6 +842,9 @@ void do_exit(long code)
14142 ptrace_put_breakpoints(tsk);
14144 + /* needs to stay before exit_notify() */
14145 + exit_vx_info_early(tsk, code);
14147 exit_notify(tsk, group_dead);
14150 @@ -874,10 +898,15 @@ void do_exit(long code)
14152 raw_spin_unlock_wait(&tsk->pi_lock);
14154 + /* needs to stay after exit_notify() */
14155 + exit_vx_info(tsk, code);
14156 + exit_nx_info(tsk);
14158 /* causes final put_task_struct in finish_task_switch(). */
14159 tsk->state = TASK_DEAD;
14160 tsk->flags |= PF_NOFREEZE; /* tell freezer to ignore us */
14162 + printk("bad task: %p [%lx]\n", current, current->state);
14164 /* Avoid "noreturn function does return". */
14166 diff -NurpP --minimal linux-3.9.4/kernel/fork.c linux-3.9.4-vs2.3.6.2/kernel/fork.c
14167 --- linux-3.9.4/kernel/fork.c 2013-05-31 13:45:29.000000000 +0000
14168 +++ linux-3.9.4-vs2.3.6.2/kernel/fork.c 2013-05-31 14:47:11.000000000 +0000
14170 #include <linux/khugepaged.h>
14171 #include <linux/signalfd.h>
14172 #include <linux/uprobes.h>
14173 +#include <linux/vs_context.h>
14174 +#include <linux/vs_network.h>
14175 +#include <linux/vs_limit.h>
14177 #include <asm/pgtable.h>
14178 #include <asm/pgalloc.h>
14179 @@ -210,6 +213,8 @@ void free_task(struct task_struct *tsk)
14180 arch_release_thread_info(tsk->stack);
14181 free_thread_info(tsk->stack);
14182 rt_mutex_debug_task_free(tsk);
14183 + clr_vx_info(&tsk->vx_info);
14184 + clr_nx_info(&tsk->nx_info);
14185 ftrace_graph_exit_task(tsk);
14186 put_seccomp_filter(tsk);
14187 arch_release_task_struct(tsk);
14188 @@ -547,6 +552,7 @@ static struct mm_struct *mm_init(struct
14189 if (likely(!mm_alloc_pgd(mm))) {
14191 mmu_notifier_mm_init(mm);
14192 + set_vx_info(&mm->mm_vx_info, p->vx_info);
14196 @@ -599,6 +605,7 @@ void __mmdrop(struct mm_struct *mm)
14197 destroy_context(mm);
14198 mmu_notifier_mm_destroy(mm);
14200 + clr_vx_info(&mm->mm_vx_info);
14203 EXPORT_SYMBOL_GPL(__mmdrop);
14204 @@ -818,6 +825,7 @@ struct mm_struct *dup_mm(struct task_str
14207 memcpy(mm, oldmm, sizeof(*mm));
14208 + mm->mm_vx_info = NULL;
14209 mm_init_cpumask(mm);
14211 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14212 @@ -859,6 +867,7 @@ fail_nocontext:
14213 * If init_new_context() failed, we cannot use mmput() to free the mm
14214 * because it calls destroy_context()
14216 + clr_vx_info(&mm->mm_vx_info);
14220 @@ -1137,6 +1146,8 @@ static struct task_struct *copy_process(
14223 struct task_struct *p;
14224 + struct vx_info *vxi;
14225 + struct nx_info *nxi;
14227 if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14228 return ERR_PTR(-EINVAL);
14229 @@ -1195,7 +1206,12 @@ static struct task_struct *copy_process(
14230 DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14231 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14233 + init_vx_info(&p->vx_info, current_vx_info());
14234 + init_nx_info(&p->nx_info, current_nx_info());
14237 + if (!vx_nproc_avail(1))
14238 + goto bad_fork_free;
14239 if (atomic_read(&p->real_cred->user->processes) >=
14240 task_rlimit(p, RLIMIT_NPROC)) {
14241 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14242 @@ -1472,6 +1488,18 @@ static struct task_struct *copy_process(
14245 spin_unlock(¤t->sighand->siglock);
14247 + /* p is copy of current */
14248 + vxi = p->vx_info;
14250 + claim_vx_info(vxi, p);
14251 + atomic_inc(&vxi->cvirt.nr_threads);
14252 + atomic_inc(&vxi->cvirt.total_forks);
14255 + nxi = p->nx_info;
14257 + claim_nx_info(nxi, p);
14258 write_unlock_irq(&tasklist_lock);
14259 proc_fork_connector(p);
14260 cgroup_post_fork(p);
14261 diff -NurpP --minimal linux-3.9.4/kernel/kthread.c linux-3.9.4-vs2.3.6.2/kernel/kthread.c
14262 --- linux-3.9.4/kernel/kthread.c 2013-05-31 13:45:30.000000000 +0000
14263 +++ linux-3.9.4-vs2.3.6.2/kernel/kthread.c 2013-05-31 14:47:11.000000000 +0000
14265 #include <linux/slab.h>
14266 #include <linux/freezer.h>
14267 #include <linux/ptrace.h>
14268 +#include <linux/vs_pid.h>
14269 #include <trace/events/sched.h>
14271 static DEFINE_SPINLOCK(kthread_create_lock);
14272 diff -NurpP --minimal linux-3.9.4/kernel/nsproxy.c linux-3.9.4-vs2.3.6.2/kernel/nsproxy.c
14273 --- linux-3.9.4/kernel/nsproxy.c 2013-05-31 13:45:30.000000000 +0000
14274 +++ linux-3.9.4-vs2.3.6.2/kernel/nsproxy.c 2013-05-31 19:28:43.000000000 +0000
14275 @@ -20,11 +20,14 @@
14276 #include <linux/mnt_namespace.h>
14277 #include <linux/utsname.h>
14278 #include <linux/pid_namespace.h>
14279 +#include <linux/vserver/global.h>
14280 +#include <linux/vserver/debug.h>
14281 #include <net/net_namespace.h>
14282 #include <linux/ipc_namespace.h>
14283 #include <linux/proc_fs.h>
14284 #include <linux/file.h>
14285 #include <linux/syscalls.h>
14286 +#include "../fs/mount.h"
14288 static struct kmem_cache *nsproxy_cachep;
14290 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14291 struct nsproxy *nsproxy;
14293 nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14296 atomic_set(&nsproxy->count, 1);
14297 + atomic_inc(&vs_global_nsproxy);
14299 + vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14303 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
14304 * Return the newly created nsproxy. Do not attach this to the task,
14305 * leave it to the caller to do proper locking and attach it to task.
14307 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14308 - struct task_struct *tsk, struct user_namespace *user_ns,
14309 - struct fs_struct *new_fs)
14310 +static struct nsproxy *unshare_namespaces(
14311 + unsigned long flags,
14312 + struct nsproxy *orig,
14313 + struct fs_struct *new_fs,
14314 + struct user_namespace *new_user,
14315 + struct pid_namespace *new_pid)
14317 struct nsproxy *new_nsp;
14319 @@ -67,31 +76,31 @@ static struct nsproxy *create_new_namesp
14321 return ERR_PTR(-ENOMEM);
14323 - new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
14324 + new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
14325 if (IS_ERR(new_nsp->mnt_ns)) {
14326 err = PTR_ERR(new_nsp->mnt_ns);
14330 - new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
14331 + new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
14332 if (IS_ERR(new_nsp->uts_ns)) {
14333 err = PTR_ERR(new_nsp->uts_ns);
14337 - new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
14338 + new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
14339 if (IS_ERR(new_nsp->ipc_ns)) {
14340 err = PTR_ERR(new_nsp->ipc_ns);
14344 - new_nsp->pid_ns = copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns);
14345 + new_nsp->pid_ns = copy_pid_ns(flags, new_user, new_pid);
14346 if (IS_ERR(new_nsp->pid_ns)) {
14347 err = PTR_ERR(new_nsp->pid_ns);
14351 - new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
14352 + new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
14353 if (IS_ERR(new_nsp->net_ns)) {
14354 err = PTR_ERR(new_nsp->net_ns);
14356 @@ -116,6 +125,41 @@ out_ns:
14357 return ERR_PTR(err);
14360 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14361 + struct task_struct *tsk, struct user_namespace *user_ns,
14362 + struct fs_struct *new_fs)
14365 + return unshare_namespaces(flags, tsk->nsproxy,
14366 + new_fs, user_ns, task_active_pid_ns(tsk));
14370 + * copies the nsproxy, setting refcount to 1, and grabbing a
14371 + * reference to all contained namespaces.
14373 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14375 + struct nsproxy *ns = create_nsproxy();
14378 + memcpy(ns, orig, sizeof(struct nsproxy));
14379 + atomic_set(&ns->count, 1);
14382 + get_mnt_ns(ns->mnt_ns);
14384 + get_uts_ns(ns->uts_ns);
14386 + get_ipc_ns(ns->ipc_ns);
14388 + get_pid_ns(ns->pid_ns);
14390 + get_net(ns->net_ns);
14396 * called from clone. This now handles copy for nsproxy and all
14397 * namespaces therein.
14398 @@ -124,9 +168,12 @@ int copy_namespaces(unsigned long flags,
14400 struct nsproxy *old_ns = tsk->nsproxy;
14401 struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
14402 - struct nsproxy *new_ns;
14403 + struct nsproxy *new_ns = NULL;
14406 + vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14407 + flags, tsk, old_ns);
14412 @@ -136,7 +183,7 @@ int copy_namespaces(unsigned long flags,
14413 CLONE_NEWPID | CLONE_NEWNET)))
14416 - if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
14417 + if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags)) {
14421 @@ -163,6 +210,9 @@ int copy_namespaces(unsigned long flags,
14424 put_nsproxy(old_ns);
14425 + vxdprintk(VXD_CBIT(space, 3),
14426 + "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14427 + flags, tsk, old_ns, err, new_ns);
14431 @@ -176,7 +226,9 @@ void free_nsproxy(struct nsproxy *ns)
14432 put_ipc_ns(ns->ipc_ns);
14434 put_pid_ns(ns->pid_ns);
14435 - put_net(ns->net_ns);
14437 + put_net(ns->net_ns);
14438 + atomic_dec(&vs_global_nsproxy);
14439 kmem_cache_free(nsproxy_cachep, ns);
14442 @@ -190,12 +242,16 @@ int unshare_nsproxy_namespaces(unsigned
14443 struct user_namespace *user_ns;
14446 + vxdprintk(VXD_CBIT(space, 4),
14447 + "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14448 + unshare_flags, current->nsproxy);
14450 if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14451 CLONE_NEWNET | CLONE_NEWPID)))
14454 user_ns = new_cred ? new_cred->user_ns : current_user_ns();
14455 - if (!ns_capable(user_ns, CAP_SYS_ADMIN))
14456 + if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
14459 *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
14460 diff -NurpP --minimal linux-3.9.4/kernel/pid.c linux-3.9.4-vs2.3.6.2/kernel/pid.c
14461 --- linux-3.9.4/kernel/pid.c 2013-05-31 13:45:30.000000000 +0000
14462 +++ linux-3.9.4-vs2.3.6.2/kernel/pid.c 2013-05-31 15:24:34.000000000 +0000
14464 #include <linux/init_task.h>
14465 #include <linux/syscalls.h>
14466 #include <linux/proc_fs.h>
14467 +#include <linux/vs_pid.h>
14469 #define pid_hashfn(nr, ns) \
14470 hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14471 @@ -364,7 +365,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14473 struct pid *find_vpid(int nr)
14475 - return find_pid_ns(nr, task_active_pid_ns(current));
14476 + return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
14478 EXPORT_SYMBOL_GPL(find_vpid);
14480 @@ -424,6 +425,9 @@ void transfer_pid(struct task_struct *ol
14481 struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14483 struct task_struct *result = NULL;
14485 + if (type == PIDTYPE_REALPID)
14486 + type = PIDTYPE_PID;
14488 struct hlist_node *first;
14489 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14490 @@ -443,7 +447,7 @@ struct task_struct *find_task_by_pid_ns(
14491 rcu_lockdep_assert(rcu_read_lock_held(),
14492 "find_task_by_pid_ns() needs rcu_read_lock()"
14494 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14495 + return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14498 struct task_struct *find_task_by_vpid(pid_t vnr)
14499 @@ -487,7 +491,7 @@ struct pid *find_get_pid(pid_t nr)
14501 EXPORT_SYMBOL_GPL(find_get_pid);
14503 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14504 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14508 @@ -501,6 +505,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14510 EXPORT_SYMBOL_GPL(pid_nr_ns);
14512 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14514 + return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14517 pid_t pid_vnr(struct pid *pid)
14519 return pid_nr_ns(pid, task_active_pid_ns(current));
14520 diff -NurpP --minimal linux-3.9.4/kernel/pid_namespace.c linux-3.9.4-vs2.3.6.2/kernel/pid_namespace.c
14521 --- linux-3.9.4/kernel/pid_namespace.c 2013-05-31 13:45:30.000000000 +0000
14522 +++ linux-3.9.4-vs2.3.6.2/kernel/pid_namespace.c 2013-05-31 17:59:48.000000000 +0000
14524 #include <linux/proc_fs.h>
14525 #include <linux/reboot.h>
14526 #include <linux/export.h>
14527 +#include <linux/vserver/global.h>
14529 #define BITS_PER_PAGE (PAGE_SIZE*8)
14531 @@ -112,6 +113,7 @@ static struct pid_namespace *create_pid_
14534 kref_init(&ns->kref);
14535 + atomic_inc(&vs_global_pid_ns);
14537 ns->parent = get_pid_ns(parent_pid_ns);
14538 ns->user_ns = get_user_ns(user_ns);
14539 @@ -142,6 +144,7 @@ static void destroy_pid_namespace(struct
14540 for (i = 0; i < PIDMAP_ENTRIES; i++)
14541 kfree(ns->pidmap[i].page);
14542 put_user_ns(ns->user_ns);
14543 + atomic_dec(&vs_global_pid_ns);
14544 kmem_cache_free(pid_ns_cachep, ns);
14547 diff -NurpP --minimal linux-3.9.4/kernel/posix-timers.c linux-3.9.4-vs2.3.6.2/kernel/posix-timers.c
14548 --- linux-3.9.4/kernel/posix-timers.c 2013-05-31 13:45:30.000000000 +0000
14549 +++ linux-3.9.4-vs2.3.6.2/kernel/posix-timers.c 2013-05-31 14:47:11.000000000 +0000
14551 #include <linux/wait.h>
14552 #include <linux/workqueue.h>
14553 #include <linux/export.h>
14554 +#include <linux/vs_context.h>
14557 * Management arrays for POSIX timers. Timers are kept in slab memory
14558 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14560 struct task_struct *task;
14561 int shared, ret = -1;
14564 * FIXME: if ->sigq is queued we can race with
14565 * dequeue_signal()->do_schedule_next_timer().
14566 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14568 task = pid_task(timr->it_pid, PIDTYPE_PID);
14570 + struct vx_info_save vxis;
14571 + struct vx_info *vxi;
14573 + vxi = get_vx_info(task->vx_info);
14574 + enter_vx_info(vxi, &vxis);
14575 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14576 ret = send_sigqueue(timr->sigq, task, shared);
14577 + leave_vx_info(&vxis);
14578 + put_vx_info(vxi);
14582 /* If we failed to send the signal the timer stops. */
14585 diff -NurpP --minimal linux-3.9.4/kernel/printk.c linux-3.9.4-vs2.3.6.2/kernel/printk.c
14586 --- linux-3.9.4/kernel/printk.c 2013-05-31 13:45:30.000000000 +0000
14587 +++ linux-3.9.4-vs2.3.6.2/kernel/printk.c 2013-05-31 15:23:35.000000000 +0000
14589 #include <linux/rculist.h>
14590 #include <linux/poll.h>
14591 #include <linux/irq_work.h>
14592 +#include <linux/vs_cvirt.h>
14594 #include <asm/uaccess.h>
14596 @@ -841,7 +842,7 @@ static int check_syslog_permissions(int
14599 if (syslog_action_restricted(type)) {
14600 - if (capable(CAP_SYSLOG))
14601 + if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14603 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14604 if (capable(CAP_SYS_ADMIN)) {
14605 @@ -1135,12 +1136,9 @@ int do_syslog(int type, char __user *buf
14610 - case SYSLOG_ACTION_CLOSE: /* Close log */
14612 - case SYSLOG_ACTION_OPEN: /* Open log */
14614 - case SYSLOG_ACTION_READ: /* Read from log */
14615 + if ((type == SYSLOG_ACTION_READ) ||
14616 + (type == SYSLOG_ACTION_READ_ALL) ||
14617 + (type == SYSLOG_ACTION_READ_CLEAR)) {
14619 if (!buf || len < 0)
14621 @@ -1151,6 +1149,16 @@ int do_syslog(int type, char __user *buf
14626 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
14627 + return vx_do_syslog(type, buf, len);
14630 + case SYSLOG_ACTION_CLOSE: /* Close log */
14632 + case SYSLOG_ACTION_OPEN: /* Open log */
14634 + case SYSLOG_ACTION_READ: /* Read from log */
14635 error = wait_event_interruptible(log_wait,
14636 syslog_seq != log_next_seq);
14638 @@ -1163,16 +1171,6 @@ int do_syslog(int type, char __user *buf
14640 /* Read last kernel messages */
14641 case SYSLOG_ACTION_READ_ALL:
14643 - if (!buf || len < 0)
14648 - if (!access_ok(VERIFY_WRITE, buf, len)) {
14652 error = syslog_print_all(buf, len, clear);
14654 /* Clear ring buffer */
14655 diff -NurpP --minimal linux-3.9.4/kernel/ptrace.c linux-3.9.4-vs2.3.6.2/kernel/ptrace.c
14656 --- linux-3.9.4/kernel/ptrace.c 2013-05-31 13:45:30.000000000 +0000
14657 +++ linux-3.9.4-vs2.3.6.2/kernel/ptrace.c 2013-05-31 15:22:34.000000000 +0000
14659 #include <linux/syscalls.h>
14660 #include <linux/uaccess.h>
14661 #include <linux/regset.h>
14662 +#include <linux/vs_context.h>
14663 #include <linux/hw_breakpoint.h>
14664 #include <linux/cn_proc.h>
14666 @@ -261,6 +262,11 @@ ok:
14670 + if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14672 + if (!vx_check(task->xid, VS_IDENT) &&
14673 + !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14675 return security_ptrace_access_check(task, mode);
14678 diff -NurpP --minimal linux-3.9.4/kernel/sched/core.c linux-3.9.4-vs2.3.6.2/kernel/sched/core.c
14679 --- linux-3.9.4/kernel/sched/core.c 2013-05-31 13:45:30.000000000 +0000
14680 +++ linux-3.9.4-vs2.3.6.2/kernel/sched/core.c 2013-05-31 15:17:22.000000000 +0000
14682 #include <linux/init_task.h>
14683 #include <linux/binfmts.h>
14684 #include <linux/context_tracking.h>
14685 +#include <linux/vs_sched.h>
14686 +#include <linux/vs_cvirt.h>
14688 #include <asm/switch_to.h>
14689 #include <asm/tlb.h>
14690 @@ -2091,9 +2093,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14692 void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14694 - loads[0] = (avenrun[0] + offset) << shift;
14695 - loads[1] = (avenrun[1] + offset) << shift;
14696 - loads[2] = (avenrun[2] + offset) << shift;
14697 + if (vx_flags(VXF_VIRT_LOAD, 0)) {
14698 + struct vx_info *vxi = current_vx_info();
14700 + loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14701 + loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14702 + loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14704 + loads[0] = (avenrun[0] + offset) << shift;
14705 + loads[1] = (avenrun[1] + offset) << shift;
14706 + loads[2] = (avenrun[2] + offset) << shift;
14710 static long calc_load_fold_active(struct rq *this_rq)
14711 @@ -3704,7 +3714,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14714 if (increment < 0 && !can_nice(current, nice))
14716 + return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14718 retval = security_task_setnice(current, nice);
14720 diff -NurpP --minimal linux-3.9.4/kernel/sched/cputime.c linux-3.9.4-vs2.3.6.2/kernel/sched/cputime.c
14721 --- linux-3.9.4/kernel/sched/cputime.c 2013-05-31 14:22:27.000000000 +0000
14722 +++ linux-3.9.4-vs2.3.6.2/kernel/sched/cputime.c 2013-05-31 15:17:55.000000000 +0000
14724 #include <linux/kernel_stat.h>
14725 #include <linux/static_key.h>
14726 #include <linux/context_tracking.h>
14727 +#include <linux/vs_sched.h>
14731 @@ -151,14 +152,17 @@ static inline void task_group_account_fi
14732 void account_user_time(struct task_struct *p, cputime_t cputime,
14733 cputime_t cputime_scaled)
14735 + struct vx_info *vxi = p->vx_info; /* p is _always_ current */
14736 + int nice = (TASK_NICE(p) > 0);
14739 /* Add user time to process. */
14740 p->utime += cputime;
14741 p->utimescaled += cputime_scaled;
14742 + vx_account_user(vxi, cputime, nice);
14743 account_group_user_time(p, cputime);
14745 - index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14746 + index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14748 /* Add user time to cpustat. */
14749 task_group_account_field(p, index, (__force u64) cputime);
14750 @@ -205,9 +209,12 @@ static inline
14751 void __account_system_time(struct task_struct *p, cputime_t cputime,
14752 cputime_t cputime_scaled, int index)
14754 + struct vx_info *vxi = p->vx_info; /* p is _always_ current */
14756 /* Add system time to process. */
14757 p->stime += cputime;
14758 p->stimescaled += cputime_scaled;
14759 + vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14760 account_group_system_time(p, cputime);
14762 /* Add system time to cpustat. */
14763 diff -NurpP --minimal linux-3.9.4/kernel/sched/fair.c linux-3.9.4-vs2.3.6.2/kernel/sched/fair.c
14764 --- linux-3.9.4/kernel/sched/fair.c 2013-05-31 13:45:30.000000000 +0000
14765 +++ linux-3.9.4-vs2.3.6.2/kernel/sched/fair.c 2013-05-31 15:19:37.000000000 +0000
14767 #include <linux/mempolicy.h>
14768 #include <linux/migrate.h>
14769 #include <linux/task_work.h>
14770 +#include <linux/vs_cvirt.h>
14772 #include <trace/events/sched.h>
14774 @@ -1714,6 +1715,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14775 __enqueue_entity(cfs_rq, se);
14778 + if (entity_is_task(se))
14779 + vx_activate_task(task_of(se));
14780 if (cfs_rq->nr_running == 1) {
14781 list_add_leaf_cfs_rq(cfs_rq);
14782 check_enqueue_throttle(cfs_rq);
14783 @@ -1795,6 +1798,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14784 if (se != cfs_rq->curr)
14785 __dequeue_entity(cfs_rq, se);
14787 + if (entity_is_task(se))
14788 + vx_deactivate_task(task_of(se));
14789 account_entity_dequeue(cfs_rq, se);
14792 diff -NurpP --minimal linux-3.9.4/kernel/signal.c linux-3.9.4-vs2.3.6.2/kernel/signal.c
14793 --- linux-3.9.4/kernel/signal.c 2013-05-31 13:45:30.000000000 +0000
14794 +++ linux-3.9.4-vs2.3.6.2/kernel/signal.c 2013-05-31 15:20:05.000000000 +0000
14796 #include <linux/user_namespace.h>
14797 #include <linux/uprobes.h>
14798 #include <linux/compat.h>
14799 +#include <linux/vs_context.h>
14800 +#include <linux/vs_pid.h>
14801 #define CREATE_TRACE_POINTS
14802 #include <trace/events/signal.h>
14804 @@ -789,9 +791,18 @@ static int check_kill_permission(int sig
14808 + vxdprintk(VXD_CBIT(misc, 7),
14809 + "check_kill_permission(%d,%p,%p[#%u,%u])",
14810 + sig, info, t, vx_task_xid(t), t->pid);
14812 if (!valid_signal(sig))
14815 +/* FIXME: needed? if so, why?
14816 + if ((info != SEND_SIG_NOINFO) &&
14817 + (is_si_special(info) || !si_fromuser(info)))
14820 if (!si_fromuser(info))
14823 @@ -815,6 +826,20 @@ static int check_kill_permission(int sig
14828 + if (t->pid == 1 && current->xid)
14832 + /* FIXME: we shouldn't return ESRCH ever, to avoid
14833 + loops, maybe ENOENT or EACCES? */
14834 + if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14835 + vxdprintk(current->xid || VXD_CBIT(misc, 7),
14836 + "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14837 + sig, info, t, vx_task_xid(t), t->pid, current->xid);
14841 return security_task_kill(t, info, sig, 0);
14844 @@ -1351,7 +1376,7 @@ int kill_pid_info(int sig, struct siginf
14847 p = pid_task(pid, PIDTYPE_PID);
14849 + if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14850 error = group_send_sig_info(sig, info, p);
14851 if (unlikely(error == -ESRCH))
14853 @@ -1399,7 +1424,7 @@ int kill_pid_info_as_cred(int sig, struc
14856 p = pid_task(pid, PIDTYPE_PID);
14858 + if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14862 @@ -1451,8 +1476,10 @@ static int kill_something_info(int sig,
14863 struct task_struct * p;
14865 for_each_process(p) {
14866 - if (task_pid_vnr(p) > 1 &&
14867 - !same_thread_group(p, current)) {
14868 + if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14869 + task_pid_vnr(p) > 1 &&
14870 + !same_thread_group(p, current) &&
14871 + !vx_current_initpid(p->pid)) {
14872 int err = group_send_sig_info(sig, info, p);
14875 @@ -2306,6 +2333,11 @@ relock:
14876 !sig_kernel_only(signr))
14879 + /* virtual init is protected against user signals */
14880 + if ((info->si_code == SI_USER) &&
14881 + vx_current_initpid(current->pid))
14884 if (sig_kernel_stop(signr)) {
14886 * The default action is to stop all threads in
14887 diff -NurpP --minimal linux-3.9.4/kernel/softirq.c linux-3.9.4-vs2.3.6.2/kernel/softirq.c
14888 --- linux-3.9.4/kernel/softirq.c 2013-05-31 13:45:30.000000000 +0000
14889 +++ linux-3.9.4-vs2.3.6.2/kernel/softirq.c 2013-05-31 14:47:11.000000000 +0000
14891 #include <linux/smp.h>
14892 #include <linux/smpboot.h>
14893 #include <linux/tick.h>
14894 +#include <linux/vs_context.h>
14896 #define CREATE_TRACE_POINTS
14897 #include <trace/events/irq.h>
14898 diff -NurpP --minimal linux-3.9.4/kernel/sys.c linux-3.9.4-vs2.3.6.2/kernel/sys.c
14899 --- linux-3.9.4/kernel/sys.c 2013-05-31 13:45:30.000000000 +0000
14900 +++ linux-3.9.4-vs2.3.6.2/kernel/sys.c 2013-05-31 15:23:14.000000000 +0000
14902 #include <linux/binfmts.h>
14904 #include <linux/kmsg_dump.h>
14905 +#include <linux/vs_pid.h>
14906 /* Move somewhere else to avoid recompiling? */
14907 #include <generated/utsrelease.h>
14909 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
14912 if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14914 + if (vx_flags(VXF_IGNEG_NICE, 0))
14920 no_nice = security_task_setnice(p, niceval);
14921 @@ -206,6 +210,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14923 pgrp = task_pgrp(current);
14924 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14925 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14927 error = set_one_prio(p, niceval, error);
14928 } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14930 @@ -271,6 +277,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14932 pgrp = task_pgrp(current);
14933 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14934 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14936 niceval = 20 - task_nice(p);
14937 if (niceval > retval)
14939 @@ -424,6 +432,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
14941 static DEFINE_MUTEX(reboot_mutex);
14943 +long vs_reboot(unsigned int, void __user *);
14946 * Reboot system call: for obvious reasons only root may call it,
14947 * and even root needs to set up some magic numbers in the registers
14948 @@ -466,6 +476,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
14949 if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
14950 cmd = LINUX_REBOOT_CMD_HALT;
14952 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
14953 + return vs_reboot(cmd, arg);
14955 mutex_lock(&reboot_mutex);
14957 case LINUX_REBOOT_CMD_RESTART:
14958 @@ -1373,7 +1386,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14960 char tmp[__NEW_UTS_LEN];
14962 - if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14963 + if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14964 + CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14967 if (len < 0 || len > __NEW_UTS_LEN)
14968 @@ -1424,7 +1438,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14970 char tmp[__NEW_UTS_LEN];
14972 - if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14973 + if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14974 + CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14976 if (len < 0 || len > __NEW_UTS_LEN)
14978 @@ -1543,7 +1558,7 @@ int do_prlimit(struct task_struct *tsk,
14979 /* Keep the capable check against init_user_ns until
14980 cgroups can contain all limits */
14981 if (new_rlim->rlim_max > rlim->rlim_max &&
14982 - !capable(CAP_SYS_RESOURCE))
14983 + !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14986 retval = security_task_setrlimit(tsk->group_leader,
14987 @@ -1596,7 +1611,8 @@ static int check_prlimit_permission(stru
14988 gid_eq(cred->gid, tcred->sgid) &&
14989 gid_eq(cred->gid, tcred->gid))
14991 - if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14992 + if (vx_ns_capable(tcred->user_ns,
14993 + CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14997 diff -NurpP --minimal linux-3.9.4/kernel/sysctl.c linux-3.9.4-vs2.3.6.2/kernel/sysctl.c
14998 --- linux-3.9.4/kernel/sysctl.c 2013-05-31 13:45:30.000000000 +0000
14999 +++ linux-3.9.4-vs2.3.6.2/kernel/sysctl.c 2013-05-31 15:28:39.000000000 +0000
15001 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15002 #include <linux/lockdep.h>
15004 +extern char vshelper_path[];
15005 #ifdef CONFIG_CHR_DEV_SG
15006 #include <scsi/sg.h>
15008 @@ -629,6 +630,13 @@ static struct ctl_table kern_table[] = {
15010 .proc_handler = proc_dostring,
15013 + .procname = "vshelper",
15014 + .data = &vshelper_path,
15017 + .proc_handler = &proc_dostring,
15020 #ifdef CONFIG_CHR_DEV_SG
15022 diff -NurpP --minimal linux-3.9.4/kernel/sysctl_binary.c linux-3.9.4-vs2.3.6.2/kernel/sysctl_binary.c
15023 --- linux-3.9.4/kernel/sysctl_binary.c 2013-05-31 13:45:30.000000000 +0000
15024 +++ linux-3.9.4-vs2.3.6.2/kernel/sysctl_binary.c 2013-05-31 14:47:11.000000000 +0000
15025 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15027 { CTL_INT, KERN_PANIC, "panic" },
15028 { CTL_INT, KERN_REALROOTDEV, "real-root-dev" },
15029 + { CTL_STR, KERN_VSHELPER, "vshelper" },
15031 { CTL_STR, KERN_SPARC_REBOOT, "reboot-cmd" },
15032 { CTL_INT, KERN_CTLALTDEL, "ctrl-alt-del" },
15033 diff -NurpP --minimal linux-3.9.4/kernel/time/timekeeping.c linux-3.9.4-vs2.3.6.2/kernel/time/timekeeping.c
15034 --- linux-3.9.4/kernel/time/timekeeping.c 2013-05-31 13:45:30.000000000 +0000
15035 +++ linux-3.9.4-vs2.3.6.2/kernel/time/timekeeping.c 2013-05-31 15:24:55.000000000 +0000
15037 #include <linux/tick.h>
15038 #include <linux/stop_machine.h>
15039 #include <linux/pvclock_gtod.h>
15040 +#include <linux/vs_time.h>
15043 static struct timekeeper timekeeper;
15044 @@ -594,6 +595,7 @@ void getrawmonotonic(struct timespec *ts
15045 } while (read_seqretry(&tk->lock, seq));
15047 timespec_add_ns(ts, nsecs);
15048 + vx_adjust_timespec(ts);
15050 EXPORT_SYMBOL(getrawmonotonic);
15052 diff -NurpP --minimal linux-3.9.4/kernel/time.c linux-3.9.4-vs2.3.6.2/kernel/time.c
15053 --- linux-3.9.4/kernel/time.c 2013-05-31 13:45:30.000000000 +0000
15054 +++ linux-3.9.4-vs2.3.6.2/kernel/time.c 2013-05-31 14:47:11.000000000 +0000
15056 #include <linux/fs.h>
15057 #include <linux/math64.h>
15058 #include <linux/ptrace.h>
15059 +#include <linux/vs_time.h>
15061 #include <asm/uaccess.h>
15062 #include <asm/unistd.h>
15063 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15067 - do_settimeofday(&tv);
15068 + vx_settimeofday(&tv);
15072 @@ -180,7 +181,7 @@ int do_sys_settimeofday(const struct tim
15076 - return do_settimeofday(tv);
15077 + return vx_settimeofday(tv);
15081 diff -NurpP --minimal linux-3.9.4/kernel/timer.c linux-3.9.4-vs2.3.6.2/kernel/timer.c
15082 --- linux-3.9.4/kernel/timer.c 2013-05-31 14:22:27.000000000 +0000
15083 +++ linux-3.9.4-vs2.3.6.2/kernel/timer.c 2013-05-31 14:47:11.000000000 +0000
15085 #include <linux/sched.h>
15086 #include <linux/sched/sysctl.h>
15087 #include <linux/slab.h>
15088 +#include <linux/vs_base.h>
15089 +#include <linux/vs_cvirt.h>
15090 +#include <linux/vs_pid.h>
15091 +#include <linux/vserver/sched.h>
15093 #include <asm/uaccess.h>
15094 #include <asm/unistd.h>
15095 diff -NurpP --minimal linux-3.9.4/kernel/user_namespace.c linux-3.9.4-vs2.3.6.2/kernel/user_namespace.c
15096 --- linux-3.9.4/kernel/user_namespace.c 2013-05-31 13:45:30.000000000 +0000
15097 +++ linux-3.9.4-vs2.3.6.2/kernel/user_namespace.c 2013-05-31 17:44:56.000000000 +0000
15099 #include <linux/ctype.h>
15100 #include <linux/projid.h>
15101 #include <linux/fs_struct.h>
15102 +#include <linux/vserver/global.h>
15104 static struct kmem_cache *user_ns_cachep __read_mostly;
15106 @@ -91,6 +92,7 @@ int create_user_ns(struct cred *new)
15108 atomic_set(&ns->count, 1);
15109 /* Leave the new->user_ns reference with the new user namespace. */
15110 + atomic_inc(&vs_global_user_ns);
15111 ns->parent = parent_ns;
15114 @@ -835,6 +837,8 @@ static void *userns_get(struct task_stru
15116 static void userns_put(void *ns)
15118 + /* FIXME: maybe move into destroyer? */
15119 + atomic_dec(&vs_global_user_ns);
15123 diff -NurpP --minimal linux-3.9.4/kernel/utsname.c linux-3.9.4-vs2.3.6.2/kernel/utsname.c
15124 --- linux-3.9.4/kernel/utsname.c 2013-05-31 13:45:30.000000000 +0000
15125 +++ linux-3.9.4-vs2.3.6.2/kernel/utsname.c 2013-05-31 15:15:55.000000000 +0000
15126 @@ -16,14 +16,17 @@
15127 #include <linux/slab.h>
15128 #include <linux/user_namespace.h>
15129 #include <linux/proc_fs.h>
15130 +#include <linux/vserver/global.h>
15132 static struct uts_namespace *create_uts_ns(void)
15134 struct uts_namespace *uts_ns;
15136 uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15139 kref_init(&uts_ns->kref);
15140 + atomic_inc(&vs_global_uts_ns);
15145 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
15146 ns = container_of(kref, struct uts_namespace, kref);
15147 put_user_ns(ns->user_ns);
15148 proc_free_inum(ns->proc_inum);
15149 + atomic_dec(&vs_global_uts_ns);
15153 diff -NurpP --minimal linux-3.9.4/kernel/vserver/Kconfig linux-3.9.4-vs2.3.6.2/kernel/vserver/Kconfig
15154 --- linux-3.9.4/kernel/vserver/Kconfig 1970-01-01 00:00:00.000000000 +0000
15155 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/Kconfig 2013-05-31 14:47:11.000000000 +0000
15158 +# Linux VServer configuration
15161 +menu "Linux VServer"
15163 +config VSERVER_AUTO_LBACK
15164 + bool "Automatically Assign Loopback IP"
15167 + Automatically assign a guest specific loopback
15168 + IP and add it to the kernel network stack on
15171 +config VSERVER_AUTO_SINGLE
15172 + bool "Automatic Single IP Special Casing"
15173 + depends on EXPERIMENTAL
15176 + This allows network contexts with a single IP to
15177 + automatically remap 0.0.0.0 bindings to that IP,
15178 + avoiding further network checks and improving
15181 + (note: such guests do not allow to change the ip
15182 + on the fly and do not show loopback addresses)
15184 +config VSERVER_COWBL
15185 + bool "Enable COW Immutable Link Breaking"
15188 + This enables the COW (Copy-On-Write) link break code.
15189 + It allows you to treat unified files like normal files
15190 + when writing to them (which will implicitely break the
15191 + link and create a copy of the unified file)
15193 +config VSERVER_VTIME
15194 + bool "Enable Virtualized Guest Time"
15195 + depends on EXPERIMENTAL
15198 + This enables per guest time offsets to allow for
15199 + adjusting the system clock individually per guest.
15200 + this adds some overhead to the time functions and
15201 + therefore should not be enabled without good reason.
15203 +config VSERVER_DEVICE
15204 + bool "Enable Guest Device Mapping"
15205 + depends on EXPERIMENTAL
15208 + This enables generic device remapping.
15210 +config VSERVER_PROC_SECURE
15211 + bool "Enable Proc Security"
15212 + depends on PROC_FS
15215 + This configures ProcFS security to initially hide
15216 + non-process entries for all contexts except the main and
15217 + spectator context (i.e. for all guests), which is a secure
15220 + (note: on 1.2x the entries were visible by default)
15223 + prompt "Persistent Inode Tagging"
15224 + default TAGGING_ID24
15226 + This adds persistent context information to filesystems
15227 + mounted with the tagxid option. Tagging is a requirement
15228 + for per-context disk limits and per-context quota.
15231 +config TAGGING_NONE
15234 + do not store per-context information in inodes.
15236 +config TAGGING_UID16
15237 + bool "UID16/GID32"
15239 + reduces UID to 16 bit, but leaves GID at 32 bit.
15241 +config TAGGING_GID16
15242 + bool "UID32/GID16"
15244 + reduces GID to 16 bit, but leaves UID at 32 bit.
15246 +config TAGGING_ID24
15247 + bool "UID24/GID24"
15249 + uses the upper 8bit from UID and GID for XID tagging
15250 + which leaves 24bit for UID/GID each, which should be
15251 + more than sufficient for normal use.
15253 +config TAGGING_INTERN
15254 + bool "UID32/GID32"
15256 + this uses otherwise reserved inode fields in the on
15257 + disk representation, which limits the use to a few
15258 + filesystems (currently ext2 and ext3)
15263 + bool "Tag NFSD User Auth and Files"
15266 + Enable this if you do want the in-kernel NFS
15267 + Server to use the tagging specified above.
15268 + (will require patched clients too)
15270 +config VSERVER_PRIVACY
15271 + bool "Honor Privacy Aspects of Guests"
15274 + When enabled, most context checks will disallow
15275 + access to structures assigned to a specific context,
15276 + like ptys or loop devices.
15278 +config VSERVER_CONTEXTS
15279 + int "Maximum number of Contexts (1-65533)" if EMBEDDED
15281 + default "768" if 64BIT
15284 + This setting will optimize certain data structures
15285 + and memory allocations according to the expected
15288 + note: this is not a strict upper limit.
15290 +config VSERVER_WARN
15291 + bool "VServer Warnings"
15294 + This enables various runtime warnings, which will
15295 + notify about potential manipulation attempts or
15296 + resource shortage. It is generally considered to
15297 + be a good idea to have that enabled.
15299 +config VSERVER_WARN_DEVPTS
15300 + bool "VServer DevPTS Warnings"
15301 + depends on VSERVER_WARN
15304 + This enables DevPTS related warnings, issued when a
15305 + process inside a context tries to lookup or access
15306 + a dynamic pts from the host or a different context.
15308 +config VSERVER_DEBUG
15309 + bool "VServer Debugging Code"
15312 + Set this to yes if you want to be able to activate
15313 + debugging output at runtime. It adds a very small
15314 + overhead to all vserver related functions and
15315 + increases the kernel size by about 20k.
15317 +config VSERVER_HISTORY
15318 + bool "VServer History Tracing"
15319 + depends on VSERVER_DEBUG
15322 + Set this to yes if you want to record the history of
15323 + linux-vserver activities, so they can be replayed in
15324 + the event of a kernel panic or oops.
15326 +config VSERVER_HISTORY_SIZE
15327 + int "Per-CPU History Size (32-65536)"
15328 + depends on VSERVER_HISTORY
15332 + This allows you to specify the number of entries in
15333 + the per-CPU history buffer.
15335 +config VSERVER_EXTRA_MNT_CHECK
15336 + bool "Extra Checks for Reachability"
15339 + Set this to yes if you want to do extra checks for
15340 + vfsmount reachability in the proc filesystem code.
15341 + This shouldn't be required on any setup utilizing
15345 + prompt "Quotes used in debug and warn messages"
15346 + default QUOTES_ISO8859
15348 +config QUOTES_ISO8859
15349 + bool "Extended ASCII (ISO 8859) angle quotes"
15351 + This uses the extended ASCII characters \xbb
15352 + and \xab for quoting file and process names.
15354 +config QUOTES_UTF8
15355 + bool "UTF-8 angle quotes"
15357 + This uses the the UTF-8 sequences for angle
15358 + quotes to quote file and process names.
15360 +config QUOTES_ASCII
15361 + bool "ASCII single quotes"
15363 + This uses the ASCII single quote character
15364 + (\x27) to quote file and process names.
15374 + select NAMESPACES
15380 +config VSERVER_SECURITY
15382 + depends on SECURITY
15384 + select SECURITY_CAPABILITIES
15386 +config VSERVER_DISABLED
15390 diff -NurpP --minimal linux-3.9.4/kernel/vserver/Makefile linux-3.9.4-vs2.3.6.2/kernel/vserver/Makefile
15391 --- linux-3.9.4/kernel/vserver/Makefile 1970-01-01 00:00:00.000000000 +0000
15392 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/Makefile 2013-05-31 14:47:11.000000000 +0000
15395 +# Makefile for the Linux vserver routines.
15399 +obj-y += vserver.o
15401 +vserver-y := switch.o context.o space.o sched.o network.o inode.o \
15402 + limit.o cvirt.o cacct.o signal.o helper.o init.o \
15405 +vserver-$(CONFIG_INET) += inet.o
15406 +vserver-$(CONFIG_PROC_FS) += proc.o
15407 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15408 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15409 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15410 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15412 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct.c linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct.c
15413 --- linux-3.9.4/kernel/vserver/cacct.c 1970-01-01 00:00:00.000000000 +0000
15414 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct.c 2013-05-31 14:47:11.000000000 +0000
15417 + * linux/kernel/vserver/cacct.c
15419 + * Virtual Server: Context Accounting
15421 + * Copyright (C) 2006-2007 Herbert Pötzl
15423 + * V0.01 added accounting stats
15427 +#include <linux/types.h>
15428 +#include <linux/vs_context.h>
15429 +#include <linux/vserver/cacct_cmd.h>
15430 +#include <linux/vserver/cacct_int.h>
15432 +#include <asm/errno.h>
15433 +#include <asm/uaccess.h>
15436 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15438 + struct vcmd_sock_stat_v0 vc_data;
15441 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15444 + field = vc_data.field;
15445 + if ((field < 0) || (field >= VXA_SOCK_SIZE))
15448 + for (j = 0; j < 3; j++) {
15449 + vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15450 + vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15453 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15458 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct_init.h linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct_init.h
15459 --- linux-3.9.4/kernel/vserver/cacct_init.h 1970-01-01 00:00:00.000000000 +0000
15460 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct_init.h 2013-05-31 14:47:11.000000000 +0000
15464 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15469 + for (i = 0; i < VXA_SOCK_SIZE; i++) {
15470 + for (j = 0; j < 3; j++) {
15471 + atomic_long_set(&cacct->sock[i][j].count, 0);
15472 + atomic_long_set(&cacct->sock[i][j].total, 0);
15475 + for (i = 0; i < 8; i++)
15476 + atomic_set(&cacct->slab[i], 0);
15477 + for (i = 0; i < 5; i++)
15478 + for (j = 0; j < 4; j++)
15479 + atomic_set(&cacct->page[i][j], 0);
15482 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15487 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct_proc.h linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct_proc.h
15488 --- linux-3.9.4/kernel/vserver/cacct_proc.h 1970-01-01 00:00:00.000000000 +0000
15489 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct_proc.h 2013-05-31 14:47:11.000000000 +0000
15491 +#ifndef _VX_CACCT_PROC_H
15492 +#define _VX_CACCT_PROC_H
15494 +#include <linux/vserver/cacct_int.h>
15497 +#define VX_SOCKA_TOP \
15498 + "Type\t recv #/bytes\t\t send #/bytes\t\t fail #/bytes\n"
15500 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15502 + int i, j, length = 0;
15503 + static char *type[VXA_SOCK_SIZE] = {
15504 + "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15507 + length += sprintf(buffer + length, VX_SOCKA_TOP);
15508 + for (i = 0; i < VXA_SOCK_SIZE; i++) {
15509 + length += sprintf(buffer + length, "%s:", type[i]);
15510 + for (j = 0; j < 3; j++) {
15511 + length += sprintf(buffer + length,
15512 + "\t%10lu/%-10lu",
15513 + vx_sock_count(cacct, i, j),
15514 + vx_sock_total(cacct, i, j));
15516 + buffer[length++] = '\n';
15519 + length += sprintf(buffer + length, "\n");
15520 + length += sprintf(buffer + length,
15521 + "slab:\t %8u %8u %8u %8u\n",
15522 + atomic_read(&cacct->slab[1]),
15523 + atomic_read(&cacct->slab[4]),
15524 + atomic_read(&cacct->slab[0]),
15525 + atomic_read(&cacct->slab[2]));
15527 + length += sprintf(buffer + length, "\n");
15528 + for (i = 0; i < 5; i++) {
15529 + length += sprintf(buffer + length,
15530 + "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15531 + atomic_read(&cacct->page[i][0]),
15532 + atomic_read(&cacct->page[i][1]),
15533 + atomic_read(&cacct->page[i][2]),
15534 + atomic_read(&cacct->page[i][3]),
15535 + atomic_read(&cacct->page[i][4]),
15536 + atomic_read(&cacct->page[i][5]),
15537 + atomic_read(&cacct->page[i][6]),
15538 + atomic_read(&cacct->page[i][7]));
15543 +#endif /* _VX_CACCT_PROC_H */
15544 diff -NurpP --minimal linux-3.9.4/kernel/vserver/context.c linux-3.9.4-vs2.3.6.2/kernel/vserver/context.c
15545 --- linux-3.9.4/kernel/vserver/context.c 1970-01-01 00:00:00.000000000 +0000
15546 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/context.c 2013-05-31 19:34:32.000000000 +0000
15549 + * linux/kernel/vserver/context.c
15551 + * Virtual Server: Context Support
15553 + * Copyright (C) 2003-2011 Herbert Pötzl
15555 + * V0.01 context helper
15556 + * V0.02 vx_ctx_kill syscall command
15557 + * V0.03 replaced context_info calls
15558 + * V0.04 redesign of struct (de)alloc
15559 + * V0.05 rlimit basic implementation
15560 + * V0.06 task_xid and info commands
15561 + * V0.07 context flags and caps
15562 + * V0.08 switch to RCU based hash
15563 + * V0.09 revert to non RCU for now
15564 + * V0.10 and back to working RCU hash
15565 + * V0.11 and back to locking again
15566 + * V0.12 referenced context store
15567 + * V0.13 separate per cpu data
15568 + * V0.14 changed vcmds to vxi arg
15569 + * V0.15 added context stat
15570 + * V0.16 have __create claim() the vxi
15571 + * V0.17 removed older and legacy stuff
15572 + * V0.18 added user credentials
15573 + * V0.19 added warn mask
15577 +#include <linux/slab.h>
15578 +#include <linux/types.h>
15579 +#include <linux/security.h>
15580 +#include <linux/pid_namespace.h>
15581 +#include <linux/capability.h>
15583 +#include <linux/vserver/context.h>
15584 +#include <linux/vserver/network.h>
15585 +#include <linux/vserver/debug.h>
15586 +#include <linux/vserver/limit.h>
15587 +#include <linux/vserver/limit_int.h>
15588 +#include <linux/vserver/space.h>
15589 +#include <linux/init_task.h>
15590 +#include <linux/fs_struct.h>
15591 +#include <linux/cred.h>
15593 +#include <linux/vs_context.h>
15594 +#include <linux/vs_limit.h>
15595 +#include <linux/vs_pid.h>
15596 +#include <linux/vserver/context_cmd.h>
15598 +#include "cvirt_init.h"
15599 +#include "cacct_init.h"
15600 +#include "limit_init.h"
15601 +#include "sched_init.h"
15604 +atomic_t vx_global_ctotal = ATOMIC_INIT(0);
15605 +atomic_t vx_global_cactive = ATOMIC_INIT(0);
15608 +/* now inactive context structures */
15610 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15612 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15615 +/* __alloc_vx_info()
15617 + * allocate an initialized vx_info struct
15618 + * doesn't make it visible (hash) */
15620 +static struct vx_info *__alloc_vx_info(xid_t xid)
15622 + struct vx_info *new = NULL;
15625 + vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15627 + /* would this benefit from a slab cache? */
15628 + new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15632 + memset(new, 0, sizeof(struct vx_info));
15634 + new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15635 + if (!new->ptr_pc)
15638 + new->vx_id = xid;
15639 + INIT_HLIST_NODE(&new->vx_hlist);
15640 + atomic_set(&new->vx_usecnt, 0);
15641 + atomic_set(&new->vx_tasks, 0);
15642 + new->vx_parent = NULL;
15643 + new->vx_state = 0;
15644 + init_waitqueue_head(&new->vx_wait);
15646 + /* prepare reaper */
15647 + get_task_struct(init_pid_ns.child_reaper);
15648 + new->vx_reaper = init_pid_ns.child_reaper;
15649 + new->vx_badness_bias = 0;
15651 + /* rest of init goes here */
15652 + vx_info_init_limit(&new->limit);
15653 + vx_info_init_sched(&new->sched);
15654 + vx_info_init_cvirt(&new->cvirt);
15655 + vx_info_init_cacct(&new->cacct);
15657 + /* per cpu data structures */
15658 + for_each_possible_cpu(cpu) {
15659 + vx_info_init_sched_pc(
15660 + &vx_per_cpu(new, sched_pc, cpu), cpu);
15661 + vx_info_init_cvirt_pc(
15662 + &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15665 + new->vx_flags = VXF_INIT_SET;
15666 + new->vx_bcaps = CAP_FULL_SET; // maybe ~CAP_SETPCAP
15667 + new->vx_ccaps = 0;
15668 + new->vx_umask = 0;
15669 + new->vx_wmask = 0;
15671 + new->reboot_cmd = 0;
15672 + new->exit_code = 0;
15674 + // preconfig spaces
15675 + for (index = 0; index < VX_SPACES; index++) {
15676 + struct _vx_space *space = &new->space[index];
15679 + spin_lock(&init_fs.lock);
15681 + spin_unlock(&init_fs.lock);
15682 + space->vx_fs = &init_fs;
15684 + /* FIXME: do we want defaults? */
15685 + // space->vx_real_cred = 0;
15686 + // space->vx_cred = 0;
15690 + vxdprintk(VXD_CBIT(xid, 0),
15691 + "alloc_vx_info(%d) = %p", xid, new);
15692 + vxh_alloc_vx_info(new);
15693 + atomic_inc(&vx_global_ctotal);
15702 +/* __dealloc_vx_info()
15704 + * final disposal of vx_info */
15706 +static void __dealloc_vx_info(struct vx_info *vxi)
15708 +#ifdef CONFIG_VSERVER_WARN
15709 + struct vx_info_save vxis;
15712 + vxdprintk(VXD_CBIT(xid, 0),
15713 + "dealloc_vx_info(%p)", vxi);
15714 + vxh_dealloc_vx_info(vxi);
15716 +#ifdef CONFIG_VSERVER_WARN
15717 + enter_vx_info(vxi, &vxis);
15718 + vx_info_exit_limit(&vxi->limit);
15719 + vx_info_exit_sched(&vxi->sched);
15720 + vx_info_exit_cvirt(&vxi->cvirt);
15721 + vx_info_exit_cacct(&vxi->cacct);
15723 + for_each_possible_cpu(cpu) {
15724 + vx_info_exit_sched_pc(
15725 + &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15726 + vx_info_exit_cvirt_pc(
15727 + &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15729 + leave_vx_info(&vxis);
15733 + vxi->vx_state |= VXS_RELEASED;
15736 + free_percpu(vxi->ptr_pc);
15739 + atomic_dec(&vx_global_ctotal);
15742 +static void __shutdown_vx_info(struct vx_info *vxi)
15744 + struct nsproxy *nsproxy;
15745 + struct fs_struct *fs;
15746 + struct cred *cred;
15751 + vxi->vx_state |= VXS_SHUTDOWN;
15752 + vs_state_change(vxi, VSC_SHUTDOWN);
15754 + for (index = 0; index < VX_SPACES; index++) {
15755 + struct _vx_space *space = &vxi->space[index];
15757 + nsproxy = xchg(&space->vx_nsproxy, NULL);
15759 + put_nsproxy(nsproxy);
15761 + fs = xchg(&space->vx_fs, NULL);
15762 + spin_lock(&fs->lock);
15763 + kill = !--fs->users;
15764 + spin_unlock(&fs->lock);
15766 + free_fs_struct(fs);
15768 + cred = (struct cred *)xchg(&space->vx_cred, NULL);
15770 + abort_creds(cred);
15774 +/* exported stuff */
15776 +void free_vx_info(struct vx_info *vxi)
15778 + unsigned long flags;
15781 + /* check for reference counts first */
15782 + BUG_ON(atomic_read(&vxi->vx_usecnt));
15783 + BUG_ON(atomic_read(&vxi->vx_tasks));
15785 + /* context must not be hashed */
15786 + BUG_ON(vx_info_state(vxi, VXS_HASHED));
15788 + /* context shutdown is mandatory */
15789 + BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15791 + /* spaces check */
15792 + for (index = 0; index < VX_SPACES; index++) {
15793 + struct _vx_space *space = &vxi->space[index];
15795 + BUG_ON(space->vx_nsproxy);
15796 + BUG_ON(space->vx_fs);
15797 + // BUG_ON(space->vx_real_cred);
15798 + // BUG_ON(space->vx_cred);
15801 + spin_lock_irqsave(&vx_info_inactive_lock, flags);
15802 + hlist_del(&vxi->vx_hlist);
15803 + spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15805 + __dealloc_vx_info(vxi);
15809 +/* hash table for vx_info hash */
15811 +#define VX_HASH_SIZE 13
15813 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15814 + { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15816 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15819 +static inline unsigned int __hashval(xid_t xid)
15821 + return (xid % VX_HASH_SIZE);
15826 +/* __hash_vx_info()
15828 + * add the vxi to the global hash table
15829 + * requires the hash_lock to be held */
15831 +static inline void __hash_vx_info(struct vx_info *vxi)
15833 + struct hlist_head *head;
15835 + vxd_assert_lock(&vx_info_hash_lock);
15836 + vxdprintk(VXD_CBIT(xid, 4),
15837 + "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15838 + vxh_hash_vx_info(vxi);
15840 + /* context must not be hashed */
15841 + BUG_ON(vx_info_state(vxi, VXS_HASHED));
15843 + vxi->vx_state |= VXS_HASHED;
15844 + head = &vx_info_hash[__hashval(vxi->vx_id)];
15845 + hlist_add_head(&vxi->vx_hlist, head);
15846 + atomic_inc(&vx_global_cactive);
15849 +/* __unhash_vx_info()
15851 + * remove the vxi from the global hash table
15852 + * requires the hash_lock to be held */
15854 +static inline void __unhash_vx_info(struct vx_info *vxi)
15856 + unsigned long flags;
15858 + vxd_assert_lock(&vx_info_hash_lock);
15859 + vxdprintk(VXD_CBIT(xid, 4),
15860 + "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15861 + atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15862 + vxh_unhash_vx_info(vxi);
15864 + /* context must be hashed */
15865 + BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15866 + /* but without tasks */
15867 + BUG_ON(atomic_read(&vxi->vx_tasks));
15869 + vxi->vx_state &= ~VXS_HASHED;
15870 + hlist_del_init(&vxi->vx_hlist);
15871 + spin_lock_irqsave(&vx_info_inactive_lock, flags);
15872 + hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15873 + spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15874 + atomic_dec(&vx_global_cactive);
15878 +/* __lookup_vx_info()
15880 + * requires the hash_lock to be held
15881 + * doesn't increment the vx_refcnt */
15883 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
15885 + struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15886 + struct hlist_node *pos;
15887 + struct vx_info *vxi;
15889 + vxd_assert_lock(&vx_info_hash_lock);
15890 + hlist_for_each(pos, head) {
15891 + vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15893 + if (vxi->vx_id == xid)
15898 + vxdprintk(VXD_CBIT(xid, 0),
15899 + "__lookup_vx_info(#%u): %p[#%u]",
15900 + xid, vxi, vxi ? vxi->vx_id : 0);
15901 + vxh_lookup_vx_info(vxi, xid);
15906 +/* __create_vx_info()
15908 + * create the requested context
15909 + * get(), claim() and hash it */
15911 +static struct vx_info *__create_vx_info(int id)
15913 + struct vx_info *new, *vxi = NULL;
15915 + vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15917 + if (!(new = __alloc_vx_info(id)))
15918 + return ERR_PTR(-ENOMEM);
15920 + /* required to make dynamic xids unique */
15921 + spin_lock(&vx_info_hash_lock);
15923 + /* static context requested */
15924 + if ((vxi = __lookup_vx_info(id))) {
15925 + vxdprintk(VXD_CBIT(xid, 0),
15926 + "create_vx_info(%d) = %p (already there)", id, vxi);
15927 + if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15928 + vxi = ERR_PTR(-EBUSY);
15930 + vxi = ERR_PTR(-EEXIST);
15933 + /* new context */
15934 + vxdprintk(VXD_CBIT(xid, 0),
15935 + "create_vx_info(%d) = %p (new)", id, new);
15936 + claim_vx_info(new, NULL);
15937 + __hash_vx_info(get_vx_info(new));
15938 + vxi = new, new = NULL;
15941 + spin_unlock(&vx_info_hash_lock);
15942 + vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15944 + __dealloc_vx_info(new);
15949 +/* exported stuff */
15952 +void unhash_vx_info(struct vx_info *vxi)
15954 + spin_lock(&vx_info_hash_lock);
15955 + __unhash_vx_info(vxi);
15956 + spin_unlock(&vx_info_hash_lock);
15957 + __shutdown_vx_info(vxi);
15958 + __wakeup_vx_info(vxi);
15962 +/* lookup_vx_info()
15964 + * search for a vx_info and get() it
15965 + * negative id means current */
15967 +struct vx_info *lookup_vx_info(int id)
15969 + struct vx_info *vxi = NULL;
15972 + vxi = get_vx_info(current_vx_info());
15973 + } else if (id > 1) {
15974 + spin_lock(&vx_info_hash_lock);
15975 + vxi = get_vx_info(__lookup_vx_info(id));
15976 + spin_unlock(&vx_info_hash_lock);
15981 +/* xid_is_hashed()
15983 + * verify that xid is still hashed */
15985 +int xid_is_hashed(xid_t xid)
15989 + spin_lock(&vx_info_hash_lock);
15990 + hashed = (__lookup_vx_info(xid) != NULL);
15991 + spin_unlock(&vx_info_hash_lock);
15995 +#ifdef CONFIG_PROC_FS
15999 + * get a subset of hashed xids for proc
16000 + * assumes size is at least one */
16002 +int get_xid_list(int index, unsigned int *xids, int size)
16004 + int hindex, nr_xids = 0;
16006 + /* only show current and children */
16007 + if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16010 + xids[nr_xids] = vx_current_xid();
16014 + for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16015 + struct hlist_head *head = &vx_info_hash[hindex];
16016 + struct hlist_node *pos;
16018 + spin_lock(&vx_info_hash_lock);
16019 + hlist_for_each(pos, head) {
16020 + struct vx_info *vxi;
16025 + vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16026 + xids[nr_xids] = vxi->vx_id;
16027 + if (++nr_xids >= size) {
16028 + spin_unlock(&vx_info_hash_lock);
16032 + /* keep the lock time short */
16033 + spin_unlock(&vx_info_hash_lock);
16040 +#ifdef CONFIG_VSERVER_DEBUG
16042 +void dump_vx_info_inactive(int level)
16044 + struct hlist_node *entry, *next;
16046 + hlist_for_each_safe(entry, next, &vx_info_inactive) {
16047 + struct vx_info *vxi =
16048 + list_entry(entry, struct vx_info, vx_hlist);
16050 + dump_vx_info(vxi, level);
16057 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16059 + struct user_struct *new_user, *old_user;
16064 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16067 + new_user = alloc_uid(vxi->vx_id, p->uid);
16071 + old_user = p->user;
16072 + if (new_user != old_user) {
16073 + atomic_inc(&new_user->processes);
16074 + atomic_dec(&old_user->processes);
16075 + p->user = new_user;
16077 + free_uid(old_user);
16083 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16085 + // p->cap_effective &= vxi->vx_cap_bset;
16086 + p->cap_effective =
16087 + cap_intersect(p->cap_effective, vxi->cap_bset);
16088 + // p->cap_inheritable &= vxi->vx_cap_bset;
16089 + p->cap_inheritable =
16090 + cap_intersect(p->cap_inheritable, vxi->cap_bset);
16091 + // p->cap_permitted &= vxi->vx_cap_bset;
16092 + p->cap_permitted =
16093 + cap_intersect(p->cap_permitted, vxi->cap_bset);
16098 +#include <linux/file.h>
16099 +#include <linux/fdtable.h>
16101 +static int vx_openfd_task(struct task_struct *tsk)
16103 + struct files_struct *files = tsk->files;
16104 + struct fdtable *fdt;
16105 + const unsigned long *bptr;
16106 + int count, total;
16108 + /* no rcu_read_lock() because of spin_lock() */
16109 + spin_lock(&files->file_lock);
16110 + fdt = files_fdtable(files);
16111 + bptr = fdt->open_fds;
16112 + count = fdt->max_fds / (sizeof(unsigned long) * 8);
16113 + for (total = 0; count > 0; count--) {
16115 + total += hweight_long(*bptr);
16118 + spin_unlock(&files->file_lock);
16123 +/* for *space compatibility */
16125 +asmlinkage long sys_unshare(unsigned long);
16128 + * migrate task to new context
16129 + * gets vxi, puts old_vxi on change
16130 + * optionally unshares namespaces (hack)
16133 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16135 + struct vx_info *old_vxi;
16141 + vxdprintk(VXD_CBIT(xid, 5),
16142 + "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16143 + vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16145 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16146 + !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16149 + if (vx_info_state(vxi, VXS_SHUTDOWN))
16152 + old_vxi = task_get_vx_info(p);
16153 + if (old_vxi == vxi)
16156 +// if (!(ret = vx_migrate_user(p, vxi))) {
16161 + openfd = vx_openfd_task(p);
16164 + atomic_dec(&old_vxi->cvirt.nr_threads);
16165 + atomic_dec(&old_vxi->cvirt.nr_running);
16166 + __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16167 + /* FIXME: what about the struct files here? */
16168 + __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16169 + /* account for the executable */
16170 + __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16172 + atomic_inc(&vxi->cvirt.nr_threads);
16173 + atomic_inc(&vxi->cvirt.nr_running);
16174 + __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16175 + /* FIXME: what about the struct files here? */
16176 + __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16177 + /* account for the executable */
16178 + __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16181 + release_vx_info(old_vxi, p);
16182 + clr_vx_info(&p->vx_info);
16184 + claim_vx_info(vxi, p);
16185 + set_vx_info(&p->vx_info, vxi);
16186 + p->xid = vxi->vx_id;
16188 + vxdprintk(VXD_CBIT(xid, 5),
16189 + "moved task %p into vxi:%p[#%d]",
16190 + p, vxi, vxi->vx_id);
16192 + // vx_mask_cap_bset(vxi, p);
16195 + /* hack for *spaces to provide compatibility */
16197 + struct nsproxy *old_nsp, *new_nsp;
16199 + ret = unshare_nsproxy_namespaces(
16200 + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16201 + &new_nsp, NULL, NULL);
16205 + old_nsp = xchg(&p->nsproxy, new_nsp);
16206 + vx_set_space(vxi,
16207 + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16208 + put_nsproxy(old_nsp);
16212 + put_vx_info(old_vxi);
16216 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16218 + struct task_struct *old_reaper;
16219 + struct vx_info *reaper_vxi;
16224 + vxdprintk(VXD_CBIT(xid, 6),
16225 + "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16226 + vxi, vxi->vx_id, p, p->xid, p->pid);
16228 + old_reaper = vxi->vx_reaper;
16229 + if (old_reaper == p)
16232 + reaper_vxi = task_get_vx_info(p);
16233 + if (reaper_vxi && reaper_vxi != vxi) {
16235 + "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16237 + p->comm, p->pid, p->xid, vx_current_xid());
16241 + /* set new child reaper */
16242 + get_task_struct(p);
16243 + vxi->vx_reaper = p;
16244 + put_task_struct(old_reaper);
16246 + put_vx_info(reaper_vxi);
16250 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16255 + vxdprintk(VXD_CBIT(xid, 6),
16256 + "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16257 + vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16259 + vxi->vx_flags &= ~VXF_STATE_INIT;
16260 + // vxi->vx_initpid = p->tgid;
16261 + vxi->vx_initpid = p->pid;
16265 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16267 + vxdprintk(VXD_CBIT(xid, 6),
16268 + "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16269 + vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16271 + vxi->exit_code = code;
16272 + vxi->vx_initpid = 0;
16276 +void vx_set_persistent(struct vx_info *vxi)
16278 + vxdprintk(VXD_CBIT(xid, 6),
16279 + "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16281 + get_vx_info(vxi);
16282 + claim_vx_info(vxi, NULL);
16285 +void vx_clear_persistent(struct vx_info *vxi)
16287 + vxdprintk(VXD_CBIT(xid, 6),
16288 + "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16290 + release_vx_info(vxi, NULL);
16291 + put_vx_info(vxi);
16294 +void vx_update_persistent(struct vx_info *vxi)
16296 + if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16297 + vx_set_persistent(vxi);
16299 + vx_clear_persistent(vxi);
16303 +/* task must be current or locked */
16305 +void exit_vx_info(struct task_struct *p, int code)
16307 + struct vx_info *vxi = p->vx_info;
16310 + atomic_dec(&vxi->cvirt.nr_threads);
16313 + vxi->exit_code = code;
16314 + release_vx_info(vxi, p);
16318 +void exit_vx_info_early(struct task_struct *p, int code)
16320 + struct vx_info *vxi = p->vx_info;
16323 + if (vxi->vx_initpid == p->pid)
16324 + vx_exit_init(vxi, p, code);
16325 + if (vxi->vx_reaper == p)
16326 + vx_set_reaper(vxi, init_pid_ns.child_reaper);
16331 +/* vserver syscall commands below here */
16333 +/* taks xid and vx_info functions */
16335 +#include <asm/uaccess.h>
16338 +int vc_task_xid(uint32_t id)
16343 + struct task_struct *tsk;
16346 + tsk = find_task_by_real_pid(id);
16347 + xid = (tsk) ? tsk->xid : -ESRCH;
16348 + rcu_read_unlock();
16350 + xid = vx_current_xid();
16355 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16357 + struct vcmd_vx_info_v0 vc_data;
16359 + vc_data.xid = vxi->vx_id;
16360 + vc_data.initpid = vxi->vx_initpid;
16362 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16368 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16370 + struct vcmd_ctx_stat_v0 vc_data;
16372 + vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16373 + vc_data.tasks = atomic_read(&vxi->vx_tasks);
16375 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16381 +/* context functions */
16383 +int vc_ctx_create(uint32_t xid, void __user *data)
16385 + struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16386 + struct vx_info *new_vxi;
16389 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16392 + if ((xid > MAX_S_CONTEXT) || (xid < 2))
16395 + new_vxi = __create_vx_info(xid);
16396 + if (IS_ERR(new_vxi))
16397 + return PTR_ERR(new_vxi);
16399 + /* initial flags */
16400 + new_vxi->vx_flags = vc_data.flagword;
16403 + if (vs_state_change(new_vxi, VSC_STARTUP))
16406 + ret = vx_migrate_task(current, new_vxi, (!data));
16410 + /* return context id on success */
16411 + ret = new_vxi->vx_id;
16413 + /* get a reference for persistent contexts */
16414 + if ((vc_data.flagword & VXF_PERSISTENT))
16415 + vx_set_persistent(new_vxi);
16417 + release_vx_info(new_vxi, NULL);
16418 + put_vx_info(new_vxi);
16423 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16425 + struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16428 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16431 + ret = vx_migrate_task(current, vxi, 0);
16434 + if (vc_data.flagword & VXM_SET_INIT)
16435 + ret = vx_set_init(vxi, current);
16438 + if (vc_data.flagword & VXM_SET_REAPER)
16439 + ret = vx_set_reaper(vxi, current);
16444 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16446 + struct vcmd_ctx_flags_v0 vc_data;
16448 + vc_data.flagword = vxi->vx_flags;
16450 + /* special STATE flag handling */
16451 + vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16453 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16458 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16460 + struct vcmd_ctx_flags_v0 vc_data;
16461 + uint64_t mask, trigger;
16463 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16466 + /* special STATE flag handling */
16467 + mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16468 + trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16470 + if (vxi == current_vx_info()) {
16471 + /* if (trigger & VXF_STATE_SETUP)
16472 + vx_mask_cap_bset(vxi, current); */
16473 + if (trigger & VXF_STATE_INIT) {
16476 + ret = vx_set_init(vxi, current);
16479 + ret = vx_set_reaper(vxi, current);
16485 + vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16486 + vc_data.flagword, mask);
16487 + if (trigger & VXF_PERSISTENT)
16488 + vx_update_persistent(vxi);
16494 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16496 + uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16498 + // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16502 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16504 + kernel_cap_t c = __cap_empty_set;
16506 + c.cap[0] = v & 0xFFFFFFFF;
16507 + c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16509 + // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16514 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16517 + *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16519 + *ccaps = vxi->vx_ccaps;
16524 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16526 + struct vcmd_ctx_caps_v1 vc_data;
16529 + ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16532 + vc_data.cmask = ~0ULL;
16534 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16539 +static int do_set_caps(struct vx_info *vxi,
16540 + uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16542 + uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16545 + printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16546 + bcaps, bmask, ccaps, cmask);
16548 + vxi->vx_bcaps = cap_t_from_caps(
16549 + vs_mask_flags(bcold, bcaps, bmask));
16550 + vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16555 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16557 + struct vcmd_ctx_caps_v1 vc_data;
16559 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16562 + return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16565 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16567 + struct vcmd_bcaps vc_data;
16570 + ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16573 + vc_data.bmask = ~0ULL;
16575 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16580 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16582 + struct vcmd_bcaps vc_data;
16584 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16587 + return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16591 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16593 + struct vcmd_umask vc_data;
16595 + vc_data.umask = vxi->vx_umask;
16596 + vc_data.mask = ~0ULL;
16598 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16603 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16605 + struct vcmd_umask vc_data;
16607 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16610 + vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16611 + vc_data.umask, vc_data.mask);
16616 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16618 + struct vcmd_wmask vc_data;
16620 + vc_data.wmask = vxi->vx_wmask;
16621 + vc_data.mask = ~0ULL;
16623 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16628 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16630 + struct vcmd_wmask vc_data;
16632 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16635 + vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16636 + vc_data.wmask, vc_data.mask);
16641 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16643 + struct vcmd_badness_v0 vc_data;
16645 + vc_data.bias = vxi->vx_badness_bias;
16647 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16652 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16654 + struct vcmd_badness_v0 vc_data;
16656 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16659 + vxi->vx_badness_bias = vc_data.bias;
16663 +#include <linux/module.h>
16665 +EXPORT_SYMBOL_GPL(free_vx_info);
16667 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt.c linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt.c
16668 --- linux-3.9.4/kernel/vserver/cvirt.c 1970-01-01 00:00:00.000000000 +0000
16669 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt.c 2013-05-31 14:47:11.000000000 +0000
16672 + * linux/kernel/vserver/cvirt.c
16674 + * Virtual Server: Context Virtualization
16676 + * Copyright (C) 2004-2007 Herbert Pötzl
16678 + * V0.01 broken out from limit.c
16679 + * V0.02 added utsname stuff
16680 + * V0.03 changed vcmds to vxi arg
16684 +#include <linux/types.h>
16685 +#include <linux/utsname.h>
16686 +#include <linux/vs_cvirt.h>
16687 +#include <linux/vserver/switch.h>
16688 +#include <linux/vserver/cvirt_cmd.h>
16690 +#include <asm/uaccess.h>
16693 +void vx_vsi_boottime(struct timespec *boottime)
16695 + struct vx_info *vxi = current_vx_info();
16697 + set_normalized_timespec(boottime,
16698 + boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16699 + boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16703 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16705 + struct vx_info *vxi = current_vx_info();
16707 + set_normalized_timespec(uptime,
16708 + uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16709 + uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16712 + set_normalized_timespec(idle,
16713 + idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16714 + idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16718 +uint64_t vx_idle_jiffies(void)
16720 + return init_task.utime + init_task.stime;
16725 +static inline uint32_t __update_loadavg(uint32_t load,
16726 + int wsize, int delta, int n)
16728 + unsigned long long calc, prev;
16730 + /* just set it to n */
16731 + if (unlikely(delta >= wsize))
16732 + return (n << FSHIFT);
16734 + calc = delta * n;
16736 + prev = (wsize - delta);
16739 + do_div(calc, wsize);
16744 +void vx_update_load(struct vx_info *vxi)
16746 + uint32_t now, last, delta;
16747 + unsigned int nr_running, nr_uninterruptible;
16748 + unsigned int total;
16749 + unsigned long flags;
16751 + spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16754 + last = vxi->cvirt.load_last;
16755 + delta = now - last;
16757 + if (delta < 5*HZ)
16760 + nr_running = atomic_read(&vxi->cvirt.nr_running);
16761 + nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16762 + total = nr_running + nr_uninterruptible;
16764 + vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16765 + 60*HZ, delta, total);
16766 + vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16767 + 5*60*HZ, delta, total);
16768 + vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16769 + 15*60*HZ, delta, total);
16771 + vxi->cvirt.load_last = now;
16773 + atomic_inc(&vxi->cvirt.load_updates);
16774 + spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16779 + * Commands to do_syslog:
16781 + * 0 -- Close the log. Currently a NOP.
16782 + * 1 -- Open the log. Currently a NOP.
16783 + * 2 -- Read from the log.
16784 + * 3 -- Read all messages remaining in the ring buffer.
16785 + * 4 -- Read and clear all messages remaining in the ring buffer
16786 + * 5 -- Clear ring buffer.
16787 + * 6 -- Disable printk's to console
16788 + * 7 -- Enable printk's to console
16789 + * 8 -- Set level of messages printed to console
16790 + * 9 -- Return number of unread characters in the log buffer
16791 + * 10 -- Return size of the log buffer
16793 +int vx_do_syslog(int type, char __user *buf, int len)
16796 + int do_clear = 0;
16797 + struct vx_info *vxi = current_vx_info();
16798 + struct _vx_syslog *log;
16802 + log = &vxi->cvirt.syslog;
16805 + case 0: /* Close log */
16806 + case 1: /* Open log */
16808 + case 2: /* Read from log */
16809 + error = wait_event_interruptible(log->log_wait,
16810 + (log->log_start - log->log_end));
16813 + spin_lock_irq(&log->logbuf_lock);
16814 + spin_unlock_irq(&log->logbuf_lock);
16816 + case 4: /* Read/clear last kernel messages */
16818 + /* fall through */
16819 + case 3: /* Read last kernel messages */
16822 + case 5: /* Clear ring buffer */
16825 + case 6: /* Disable logging to console */
16826 + case 7: /* Enable logging to console */
16827 + case 8: /* Set level of messages printed to console */
16830 + case 9: /* Number of chars in the log buffer */
16832 + case 10: /* Size of the log buffer */
16842 +/* virtual host info names */
16844 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16846 + struct nsproxy *nsproxy;
16847 + struct uts_namespace *uts;
16849 + if (id == VHIN_CONTEXT)
16850 + return vxi->vx_name;
16852 + nsproxy = vxi->space[0].vx_nsproxy;
16856 + uts = nsproxy->uts_ns;
16861 + case VHIN_SYSNAME:
16862 + return uts->name.sysname;
16863 + case VHIN_NODENAME:
16864 + return uts->name.nodename;
16865 + case VHIN_RELEASE:
16866 + return uts->name.release;
16867 + case VHIN_VERSION:
16868 + return uts->name.version;
16869 + case VHIN_MACHINE:
16870 + return uts->name.machine;
16871 + case VHIN_DOMAINNAME:
16872 + return uts->name.domainname;
16879 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16881 + struct vcmd_vhi_name_v0 vc_data;
16884 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16887 + name = vx_vhi_name(vxi, vc_data.field);
16891 + memcpy(name, vc_data.name, 65);
16895 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16897 + struct vcmd_vhi_name_v0 vc_data;
16900 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16903 + name = vx_vhi_name(vxi, vc_data.field);
16907 + memcpy(vc_data.name, name, 65);
16908 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16914 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16916 + struct vcmd_virt_stat_v0 vc_data;
16917 + struct _vx_cvirt *cvirt = &vxi->cvirt;
16918 + struct timespec uptime;
16920 + do_posix_clock_monotonic_gettime(&uptime);
16921 + set_normalized_timespec(&uptime,
16922 + uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16923 + uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16925 + vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16926 + vc_data.uptime = timespec_to_ns(&uptime);
16927 + vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16928 + vc_data.nr_running = atomic_read(&cvirt->nr_running);
16929 + vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16930 + vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16931 + vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16932 + vc_data.load[0] = cvirt->load[0];
16933 + vc_data.load[1] = cvirt->load[1];
16934 + vc_data.load[2] = cvirt->load[2];
16936 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16942 +#ifdef CONFIG_VSERVER_VTIME
16944 +/* virtualized time base */
16946 +void vx_adjust_timespec(struct timespec *ts)
16948 + struct vx_info *vxi;
16950 + if (!vx_flags(VXF_VIRT_TIME, 0))
16953 + vxi = current_vx_info();
16954 + ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16955 + ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16957 + if (ts->tv_nsec >= NSEC_PER_SEC) {
16959 + ts->tv_nsec -= NSEC_PER_SEC;
16960 + } else if (ts->tv_nsec < 0) {
16962 + ts->tv_nsec += NSEC_PER_SEC;
16966 +int vx_settimeofday(const struct timespec *ts)
16968 + struct timespec ats, delta;
16969 + struct vx_info *vxi;
16971 + if (!vx_flags(VXF_VIRT_TIME, 0))
16972 + return do_settimeofday(ts);
16974 + getnstimeofday(&ats);
16975 + delta = timespec_sub(*ts, ats);
16977 + vxi = current_vx_info();
16978 + vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16984 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt_init.h linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt_init.h
16985 --- linux-3.9.4/kernel/vserver/cvirt_init.h 1970-01-01 00:00:00.000000000 +0000
16986 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt_init.h 2013-05-31 14:47:11.000000000 +0000
16990 +extern uint64_t vx_idle_jiffies(void);
16992 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16994 + uint64_t idle_jiffies = vx_idle_jiffies();
16995 + uint64_t nsuptime;
16997 + do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16998 + nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16999 + * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17000 + cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17001 + cvirt->bias_ts.tv_sec = 0;
17002 + cvirt->bias_ts.tv_nsec = 0;
17004 + jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17005 + atomic_set(&cvirt->nr_threads, 0);
17006 + atomic_set(&cvirt->nr_running, 0);
17007 + atomic_set(&cvirt->nr_uninterruptible, 0);
17008 + atomic_set(&cvirt->nr_onhold, 0);
17010 + spin_lock_init(&cvirt->load_lock);
17011 + cvirt->load_last = jiffies;
17012 + atomic_set(&cvirt->load_updates, 0);
17013 + cvirt->load[0] = 0;
17014 + cvirt->load[1] = 0;
17015 + cvirt->load[2] = 0;
17016 + atomic_set(&cvirt->total_forks, 0);
17018 + spin_lock_init(&cvirt->syslog.logbuf_lock);
17019 + init_waitqueue_head(&cvirt->syslog.log_wait);
17020 + cvirt->syslog.log_start = 0;
17021 + cvirt->syslog.log_end = 0;
17022 + cvirt->syslog.con_start = 0;
17023 + cvirt->syslog.logged_chars = 0;
17027 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17029 + // cvirt_pc->cpustat = { 0 };
17032 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17034 +#ifdef CONFIG_VSERVER_WARN
17037 + vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17038 + "!!! cvirt: %p[nr_threads] = %d on exit.",
17040 + vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17041 + "!!! cvirt: %p[nr_running] = %d on exit.",
17043 + vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17044 + "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17046 + vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17047 + "!!! cvirt: %p[nr_onhold] = %d on exit.",
17053 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17058 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt_proc.h linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt_proc.h
17059 --- linux-3.9.4/kernel/vserver/cvirt_proc.h 1970-01-01 00:00:00.000000000 +0000
17060 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt_proc.h 2013-05-31 19:38:26.000000000 +0000
17062 +#ifndef _VX_CVIRT_PROC_H
17063 +#define _VX_CVIRT_PROC_H
17065 +#include <linux/nsproxy.h>
17066 +#include <linux/mnt_namespace.h>
17067 +#include <linux/ipc_namespace.h>
17068 +#include <linux/utsname.h>
17069 +#include <linux/ipc.h>
17071 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17074 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17076 + struct mnt_namespace *ns;
17077 + struct uts_namespace *uts;
17078 + struct ipc_namespace *ipc;
17084 + length += sprintf(buffer + length,
17085 + "NSProxy:\t%p [%p,%p,%p]\n",
17086 + nsproxy, nsproxy->mnt_ns,
17087 + nsproxy->uts_ns, nsproxy->ipc_ns);
17089 + ns = nsproxy->mnt_ns;
17093 + length += vx_info_mnt_namespace(ns, buffer + length);
17097 + uts = nsproxy->uts_ns;
17101 + length += sprintf(buffer + length,
17102 + "SysName:\t%.*s\n"
17103 + "NodeName:\t%.*s\n"
17104 + "Release:\t%.*s\n"
17105 + "Version:\t%.*s\n"
17106 + "Machine:\t%.*s\n"
17107 + "DomainName:\t%.*s\n",
17108 + __NEW_UTS_LEN, uts->name.sysname,
17109 + __NEW_UTS_LEN, uts->name.nodename,
17110 + __NEW_UTS_LEN, uts->name.release,
17111 + __NEW_UTS_LEN, uts->name.version,
17112 + __NEW_UTS_LEN, uts->name.machine,
17113 + __NEW_UTS_LEN, uts->name.domainname);
17116 + ipc = nsproxy->ipc_ns;
17120 + length += sprintf(buffer + length,
17121 + "SEMS:\t\t%d %d %d %d %d\n"
17122 + "MSG:\t\t%d %d %d\n"
17123 + "SHM:\t\t%lu %lu %d %ld\n",
17124 + ipc->sem_ctls[0], ipc->sem_ctls[1],
17125 + ipc->sem_ctls[2], ipc->sem_ctls[3],
17127 + ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17128 + (unsigned long)ipc->shm_ctlmax,
17129 + (unsigned long)ipc->shm_ctlall,
17130 + ipc->shm_ctlmni, ipc->shm_tot);
17137 +#include <linux/sched.h>
17139 +#define LOAD_INT(x) ((x) >> FSHIFT)
17140 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17143 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17148 + length += sprintf(buffer + length,
17149 + "BiasUptime:\t%lu.%02lu\n",
17150 + (unsigned long)cvirt->bias_uptime.tv_sec,
17151 + (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17153 + a = cvirt->load[0] + (FIXED_1 / 200);
17154 + b = cvirt->load[1] + (FIXED_1 / 200);
17155 + c = cvirt->load[2] + (FIXED_1 / 200);
17156 + length += sprintf(buffer + length,
17157 + "nr_threads:\t%d\n"
17158 + "nr_running:\t%d\n"
17159 + "nr_unintr:\t%d\n"
17160 + "nr_onhold:\t%d\n"
17161 + "load_updates:\t%d\n"
17162 + "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17163 + "total_forks:\t%d\n",
17164 + atomic_read(&cvirt->nr_threads),
17165 + atomic_read(&cvirt->nr_running),
17166 + atomic_read(&cvirt->nr_uninterruptible),
17167 + atomic_read(&cvirt->nr_onhold),
17168 + atomic_read(&cvirt->load_updates),
17169 + LOAD_INT(a), LOAD_FRAC(a),
17170 + LOAD_INT(b), LOAD_FRAC(b),
17171 + LOAD_INT(c), LOAD_FRAC(c),
17172 + atomic_read(&cvirt->total_forks));
17177 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17178 + char *buffer, int cpu)
17184 +#endif /* _VX_CVIRT_PROC_H */
17185 diff -NurpP --minimal linux-3.9.4/kernel/vserver/debug.c linux-3.9.4-vs2.3.6.2/kernel/vserver/debug.c
17186 --- linux-3.9.4/kernel/vserver/debug.c 1970-01-01 00:00:00.000000000 +0000
17187 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/debug.c 2013-05-31 14:47:11.000000000 +0000
17190 + * kernel/vserver/debug.c
17192 + * Copyright (C) 2005-2007 Herbert Pötzl
17194 + * V0.01 vx_info dump support
17198 +#include <linux/module.h>
17200 +#include <linux/vserver/context.h>
17203 +void dump_vx_info(struct vx_info *vxi, int level)
17205 + printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17206 + atomic_read(&vxi->vx_usecnt),
17207 + atomic_read(&vxi->vx_tasks),
17210 + __dump_vx_limit(&vxi->limit);
17211 + __dump_vx_sched(&vxi->sched);
17212 + __dump_vx_cvirt(&vxi->cvirt);
17213 + __dump_vx_cacct(&vxi->cacct);
17219 +EXPORT_SYMBOL_GPL(dump_vx_info);
17221 diff -NurpP --minimal linux-3.9.4/kernel/vserver/device.c linux-3.9.4-vs2.3.6.2/kernel/vserver/device.c
17222 --- linux-3.9.4/kernel/vserver/device.c 1970-01-01 00:00:00.000000000 +0000
17223 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/device.c 2013-05-31 14:47:11.000000000 +0000
17226 + * linux/kernel/vserver/device.c
17228 + * Linux-VServer: Device Support
17230 + * Copyright (C) 2006 Herbert Pötzl
17231 + * Copyright (C) 2007 Daniel Hokka Zakrisson
17233 + * V0.01 device mapping basics
17234 + * V0.02 added defaults
17238 +#include <linux/slab.h>
17239 +#include <linux/rcupdate.h>
17240 +#include <linux/fs.h>
17241 +#include <linux/namei.h>
17242 +#include <linux/hash.h>
17244 +#include <asm/errno.h>
17245 +#include <asm/uaccess.h>
17246 +#include <linux/vserver/base.h>
17247 +#include <linux/vserver/debug.h>
17248 +#include <linux/vserver/context.h>
17249 +#include <linux/vserver/device.h>
17250 +#include <linux/vserver/device_cmd.h>
17253 +#define DMAP_HASH_BITS 4
17256 +struct vs_mapping {
17258 + struct hlist_node hlist;
17259 + struct list_head list;
17261 +#define dm_hlist u.hlist
17262 +#define dm_list u.list
17265 + struct vx_dmap_target target;
17269 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17271 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17273 +static struct vx_dmap_target dmap_defaults[2] = {
17274 + { .flags = DATTR_OPEN },
17275 + { .flags = DATTR_OPEN },
17279 +struct kmem_cache *dmap_cachep __read_mostly;
17281 +int __init dmap_cache_init(void)
17283 + dmap_cachep = kmem_cache_create("dmap_cache",
17284 + sizeof(struct vs_mapping), 0,
17285 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17289 +__initcall(dmap_cache_init);
17292 +static inline unsigned int __hashval(dev_t dev, int bits)
17294 + return hash_long((unsigned long)dev, bits);
17298 +/* __hash_mapping()
17299 + * add the mapping to the hash table
17301 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17303 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17304 + struct hlist_head *head, *hash = dmap_main_hash;
17305 + int device = vdm->device;
17307 + spin_lock(hash_lock);
17308 + vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17309 + vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17311 + head = &hash[__hashval(device, DMAP_HASH_BITS)];
17312 + hlist_add_head(&vdm->dm_hlist, head);
17313 + spin_unlock(hash_lock);
17317 +static inline int __mode_to_default(umode_t mode)
17330 +/* __set_default()
17333 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17334 + struct vx_dmap_target *vdmt)
17336 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17337 + spin_lock(hash_lock);
17340 + vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17342 + dmap_defaults[__mode_to_default(mode)] = *vdmt;
17345 + spin_unlock(hash_lock);
17347 + vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17348 + vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17352 +/* __remove_default()
17353 + * remove a default
17355 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17357 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17358 + spin_lock(hash_lock);
17361 + vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17362 + else /* remove == reset */
17363 + dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17365 + spin_unlock(hash_lock);
17370 +/* __find_mapping()
17371 + * find a mapping in the hash table
17373 + * caller must hold hash_lock
17375 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17376 + struct vs_mapping **local, struct vs_mapping **global)
17378 + struct hlist_head *hash = dmap_main_hash;
17379 + struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17380 + struct hlist_node *pos;
17381 + struct vs_mapping *vdm;
17387 + hlist_for_each(pos, head) {
17388 + vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17390 + if ((vdm->device == device) &&
17391 + !((vdm->target.flags ^ mode) & S_IFMT)) {
17392 + if (vdm->xid == xid) {
17395 + } else if (global && vdm->xid == 0)
17400 + if (global && *global)
17407 +/* __lookup_mapping()
17408 + * find a mapping and store the result in target and flags
17410 +static inline int __lookup_mapping(struct vx_info *vxi,
17411 + dev_t device, dev_t *target, int *flags, umode_t mode)
17413 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17414 + struct vs_mapping *vdm, *global;
17415 + struct vx_dmap_target *vdmt;
17417 + xid_t xid = vxi->vx_id;
17420 + spin_lock(hash_lock);
17421 + if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17423 + vdmt = &vdm->target;
17427 + index = __mode_to_default(mode);
17428 + if (vxi && vxi->dmap.targets[index].flags) {
17430 + vdmt = &vxi->dmap.targets[index];
17431 + } else if (global) {
17433 + vdmt = &global->target;
17437 + vdmt = &dmap_defaults[index];
17441 + if (target && (vdmt->flags & DATTR_REMAP))
17442 + *target = vdmt->target;
17444 + *target = device;
17446 + *flags = vdmt->flags;
17448 + spin_unlock(hash_lock);
17454 +/* __remove_mapping()
17455 + * remove a mapping from the hash table
17457 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17460 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17461 + struct vs_mapping *vdm = NULL;
17464 + spin_lock(hash_lock);
17466 + ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17468 + vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17469 + vxi, vxi ? vxi->vx_id : 0, device, mode);
17472 + hlist_del(&vdm->dm_hlist);
17475 + spin_unlock(hash_lock);
17477 + kmem_cache_free(dmap_cachep, vdm);
17483 +int vs_map_device(struct vx_info *vxi,
17484 + dev_t device, dev_t *target, umode_t mode)
17486 + int ret, flags = DATTR_MASK;
17490 + *target = device;
17493 + ret = __lookup_mapping(vxi, device, target, &flags, mode);
17494 + vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17495 + device, target ? *target : 0, flags, mode, ret);
17497 + return (flags & DATTR_MASK);
17502 +static int do_set_mapping(struct vx_info *vxi,
17503 + dev_t device, dev_t target, int flags, umode_t mode)
17506 + struct vs_mapping *new;
17508 + new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17512 + INIT_HLIST_NODE(&new->dm_hlist);
17513 + new->device = device;
17514 + new->target.target = target;
17515 + new->target.flags = flags | mode;
17516 + new->xid = (vxi ? vxi->vx_id : 0);
17518 + vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17519 + __hash_mapping(vxi, new);
17521 + struct vx_dmap_target new = {
17522 + .target = target,
17523 + .flags = flags | mode,
17525 + __set_default(vxi, mode, &new);
17531 +static int do_unset_mapping(struct vx_info *vxi,
17532 + dev_t device, dev_t target, int flags, umode_t mode)
17534 + int ret = -EINVAL;
17537 + ret = __remove_mapping(vxi, device, mode);
17541 + ret = __remove_default(vxi, mode);
17551 +static inline int __user_device(const char __user *name, dev_t *dev,
17554 + struct nameidata nd;
17561 + ret = user_lpath(name, &nd.path);
17564 + if (nd.path.dentry->d_inode) {
17565 + *dev = nd.path.dentry->d_inode->i_rdev;
17566 + *mode = nd.path.dentry->d_inode->i_mode;
17568 + path_put(&nd.path);
17572 +static inline int __mapping_mode(dev_t device, dev_t target,
17573 + umode_t device_mode, umode_t target_mode, umode_t *mode)
17576 + *mode = device_mode & S_IFMT;
17578 + *mode = target_mode & S_IFMT;
17582 + /* if both given, device and target mode have to match */
17583 + if (device && target &&
17584 + ((device_mode ^ target_mode) & S_IFMT))
17590 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17591 + const char __user *target_path, int flags, int set)
17593 + dev_t device = ~0, target = ~0;
17594 + umode_t device_mode = 0, target_mode = 0, mode;
17597 + ret = __user_device(device_path, &device, &device_mode);
17600 + ret = __user_device(target_path, &target, &target_mode);
17604 + ret = __mapping_mode(device, target,
17605 + device_mode, target_mode, &mode);
17610 + return do_set_mapping(vxi, device, target,
17613 + return do_unset_mapping(vxi, device, target,
17618 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17620 + struct vcmd_set_mapping_v0 vc_data;
17622 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17625 + return do_mapping(vxi, vc_data.device, vc_data.target,
17626 + vc_data.flags, 1);
17629 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17631 + struct vcmd_set_mapping_v0 vc_data;
17633 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17636 + return do_mapping(vxi, vc_data.device, vc_data.target,
17637 + vc_data.flags, 0);
17641 +#ifdef CONFIG_COMPAT
17643 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17645 + struct vcmd_set_mapping_v0_x32 vc_data;
17647 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17650 + return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17651 + compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17654 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17656 + struct vcmd_set_mapping_v0_x32 vc_data;
17658 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17661 + return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17662 + compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17665 +#endif /* CONFIG_COMPAT */
17668 diff -NurpP --minimal linux-3.9.4/kernel/vserver/dlimit.c linux-3.9.4-vs2.3.6.2/kernel/vserver/dlimit.c
17669 --- linux-3.9.4/kernel/vserver/dlimit.c 1970-01-01 00:00:00.000000000 +0000
17670 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/dlimit.c 2013-05-31 19:37:39.000000000 +0000
17673 + * linux/kernel/vserver/dlimit.c
17675 + * Virtual Server: Context Disk Limits
17677 + * Copyright (C) 2004-2009 Herbert Pötzl
17679 + * V0.01 initial version
17680 + * V0.02 compat32 splitup
17681 + * V0.03 extended interface
17685 +#include <linux/statfs.h>
17686 +#include <linux/sched.h>
17687 +#include <linux/namei.h>
17688 +#include <linux/vs_tag.h>
17689 +#include <linux/vs_dlimit.h>
17690 +#include <linux/vserver/dlimit_cmd.h>
17691 +#include <linux/slab.h>
17692 +// #include <linux/gfp.h>
17694 +#include <asm/uaccess.h>
17696 +/* __alloc_dl_info()
17698 + * allocate an initialized dl_info struct
17699 + * doesn't make it visible (hash) */
17701 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17703 + struct dl_info *new = NULL;
17705 + vxdprintk(VXD_CBIT(dlim, 5),
17706 + "alloc_dl_info(%p,%d)*", sb, tag);
17708 + /* would this benefit from a slab cache? */
17709 + new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17713 + memset(new, 0, sizeof(struct dl_info));
17714 + new->dl_tag = tag;
17716 + // INIT_RCU_HEAD(&new->dl_rcu);
17717 + INIT_HLIST_NODE(&new->dl_hlist);
17718 + spin_lock_init(&new->dl_lock);
17719 + atomic_set(&new->dl_refcnt, 0);
17720 + atomic_set(&new->dl_usecnt, 0);
17722 + /* rest of init goes here */
17724 + vxdprintk(VXD_CBIT(dlim, 4),
17725 + "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17729 +/* __dealloc_dl_info()
17731 + * final disposal of dl_info */
17733 +static void __dealloc_dl_info(struct dl_info *dli)
17735 + vxdprintk(VXD_CBIT(dlim, 4),
17736 + "dealloc_dl_info(%p)", dli);
17738 + dli->dl_hlist.next = LIST_POISON1;
17739 + dli->dl_tag = -1;
17742 + BUG_ON(atomic_read(&dli->dl_usecnt));
17743 + BUG_ON(atomic_read(&dli->dl_refcnt));
17749 +/* hash table for dl_info hash */
17751 +#define DL_HASH_SIZE 13
17753 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17755 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17758 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
17760 + return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17765 +/* __hash_dl_info()
17767 + * add the dli to the global hash table
17768 + * requires the hash_lock to be held */
17770 +static inline void __hash_dl_info(struct dl_info *dli)
17772 + struct hlist_head *head;
17774 + vxdprintk(VXD_CBIT(dlim, 6),
17775 + "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17776 + get_dl_info(dli);
17777 + head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17778 + hlist_add_head_rcu(&dli->dl_hlist, head);
17781 +/* __unhash_dl_info()
17783 + * remove the dli from the global hash table
17784 + * requires the hash_lock to be held */
17786 +static inline void __unhash_dl_info(struct dl_info *dli)
17788 + vxdprintk(VXD_CBIT(dlim, 6),
17789 + "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17790 + hlist_del_rcu(&dli->dl_hlist);
17791 + put_dl_info(dli);
17795 +/* __lookup_dl_info()
17797 + * requires the rcu_read_lock()
17798 + * doesn't increment the dl_refcnt */
17800 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
17802 + struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17803 + struct dl_info *dli;
17805 + hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17806 + if (dli->dl_tag == tag && dli->dl_sb == sb)
17813 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
17815 + struct dl_info *dli;
17818 + dli = get_dl_info(__lookup_dl_info(sb, tag));
17819 + vxdprintk(VXD_CBIT(dlim, 7),
17820 + "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17821 + rcu_read_unlock();
17825 +void rcu_free_dl_info(struct rcu_head *head)
17827 + struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17828 + int usecnt, refcnt;
17830 + BUG_ON(!dli || !head);
17832 + usecnt = atomic_read(&dli->dl_usecnt);
17833 + BUG_ON(usecnt < 0);
17835 + refcnt = atomic_read(&dli->dl_refcnt);
17836 + BUG_ON(refcnt < 0);
17838 + vxdprintk(VXD_CBIT(dlim, 3),
17839 + "rcu_free_dl_info(%p)", dli);
17841 + __dealloc_dl_info(dli);
17843 + printk("!!! rcu didn't free\n");
17849 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17850 + uint32_t flags, int add)
17852 + struct path path;
17855 + ret = user_lpath(name, &path);
17857 + struct super_block *sb;
17858 + struct dl_info *dli;
17861 + if (!path.dentry->d_inode)
17862 + goto out_release;
17863 + if (!(sb = path.dentry->d_inode->i_sb))
17864 + goto out_release;
17867 + dli = __alloc_dl_info(sb, id);
17868 + spin_lock(&dl_info_hash_lock);
17871 + if (__lookup_dl_info(sb, id))
17873 + __hash_dl_info(dli);
17876 + spin_lock(&dl_info_hash_lock);
17877 + dli = __lookup_dl_info(sb, id);
17882 + __unhash_dl_info(dli);
17886 + spin_unlock(&dl_info_hash_lock);
17888 + __dealloc_dl_info(dli);
17895 +int vc_add_dlimit(uint32_t id, void __user *data)
17897 + struct vcmd_ctx_dlimit_base_v0 vc_data;
17899 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17902 + return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17905 +int vc_rem_dlimit(uint32_t id, void __user *data)
17907 + struct vcmd_ctx_dlimit_base_v0 vc_data;
17909 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17912 + return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17915 +#ifdef CONFIG_COMPAT
17917 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17919 + struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17921 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17924 + return do_addrem_dlimit(id,
17925 + compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17928 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17930 + struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17932 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17935 + return do_addrem_dlimit(id,
17936 + compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17939 +#endif /* CONFIG_COMPAT */
17943 +int do_set_dlimit(uint32_t id, const char __user *name,
17944 + uint32_t space_used, uint32_t space_total,
17945 + uint32_t inodes_used, uint32_t inodes_total,
17946 + uint32_t reserved, uint32_t flags)
17948 + struct path path;
17951 + ret = user_lpath(name, &path);
17953 + struct super_block *sb;
17954 + struct dl_info *dli;
17957 + if (!path.dentry->d_inode)
17958 + goto out_release;
17959 + if (!(sb = path.dentry->d_inode->i_sb))
17960 + goto out_release;
17962 + /* sanity checks */
17963 + if ((reserved != CDLIM_KEEP &&
17964 + reserved > 100) ||
17965 + (inodes_used != CDLIM_KEEP &&
17966 + inodes_used > inodes_total) ||
17967 + (space_used != CDLIM_KEEP &&
17968 + space_used > space_total))
17969 + goto out_release;
17972 + dli = locate_dl_info(sb, id);
17974 + goto out_release;
17976 + spin_lock(&dli->dl_lock);
17978 + if (inodes_used != CDLIM_KEEP)
17979 + dli->dl_inodes_used = inodes_used;
17980 + if (inodes_total != CDLIM_KEEP)
17981 + dli->dl_inodes_total = inodes_total;
17982 + if (space_used != CDLIM_KEEP)
17983 + dli->dl_space_used = dlimit_space_32to64(
17984 + space_used, flags, DLIMS_USED);
17986 + if (space_total == CDLIM_INFINITY)
17987 + dli->dl_space_total = DLIM_INFINITY;
17988 + else if (space_total != CDLIM_KEEP)
17989 + dli->dl_space_total = dlimit_space_32to64(
17990 + space_total, flags, DLIMS_TOTAL);
17992 + if (reserved != CDLIM_KEEP)
17993 + dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17995 + spin_unlock(&dli->dl_lock);
17997 + put_dl_info(dli);
18006 +int vc_set_dlimit(uint32_t id, void __user *data)
18008 + struct vcmd_ctx_dlimit_v0 vc_data;
18010 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18013 + return do_set_dlimit(id, vc_data.name,
18014 + vc_data.space_used, vc_data.space_total,
18015 + vc_data.inodes_used, vc_data.inodes_total,
18016 + vc_data.reserved, vc_data.flags);
18019 +#ifdef CONFIG_COMPAT
18021 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18023 + struct vcmd_ctx_dlimit_v0_x32 vc_data;
18025 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18028 + return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18029 + vc_data.space_used, vc_data.space_total,
18030 + vc_data.inodes_used, vc_data.inodes_total,
18031 + vc_data.reserved, vc_data.flags);
18034 +#endif /* CONFIG_COMPAT */
18038 +int do_get_dlimit(uint32_t id, const char __user *name,
18039 + uint32_t *space_used, uint32_t *space_total,
18040 + uint32_t *inodes_used, uint32_t *inodes_total,
18041 + uint32_t *reserved, uint32_t *flags)
18043 + struct path path;
18046 + ret = user_lpath(name, &path);
18048 + struct super_block *sb;
18049 + struct dl_info *dli;
18052 + if (!path.dentry->d_inode)
18053 + goto out_release;
18054 + if (!(sb = path.dentry->d_inode->i_sb))
18055 + goto out_release;
18058 + dli = locate_dl_info(sb, id);
18060 + goto out_release;
18062 + spin_lock(&dli->dl_lock);
18063 + *inodes_used = dli->dl_inodes_used;
18064 + *inodes_total = dli->dl_inodes_total;
18066 + *space_used = dlimit_space_64to32(
18067 + dli->dl_space_used, flags, DLIMS_USED);
18069 + if (dli->dl_space_total == DLIM_INFINITY)
18070 + *space_total = CDLIM_INFINITY;
18072 + *space_total = dlimit_space_64to32(
18073 + dli->dl_space_total, flags, DLIMS_TOTAL);
18075 + *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18076 + spin_unlock(&dli->dl_lock);
18078 + put_dl_info(dli);
18089 +int vc_get_dlimit(uint32_t id, void __user *data)
18091 + struct vcmd_ctx_dlimit_v0 vc_data;
18094 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18097 + ret = do_get_dlimit(id, vc_data.name,
18098 + &vc_data.space_used, &vc_data.space_total,
18099 + &vc_data.inodes_used, &vc_data.inodes_total,
18100 + &vc_data.reserved, &vc_data.flags);
18104 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18109 +#ifdef CONFIG_COMPAT
18111 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18113 + struct vcmd_ctx_dlimit_v0_x32 vc_data;
18116 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18119 + ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18120 + &vc_data.space_used, &vc_data.space_total,
18121 + &vc_data.inodes_used, &vc_data.inodes_total,
18122 + &vc_data.reserved, &vc_data.flags);
18126 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18131 +#endif /* CONFIG_COMPAT */
18134 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18136 + struct dl_info *dli;
18137 + __u64 blimit, bfree, bavail;
18140 + dli = locate_dl_info(sb, dx_current_tag());
18144 + spin_lock(&dli->dl_lock);
18145 + if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18148 + /* reduce max inodes available to limit */
18149 + if (buf->f_files > dli->dl_inodes_total)
18150 + buf->f_files = dli->dl_inodes_total;
18152 + ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18153 + /* reduce free inodes to min */
18154 + if (ifree < buf->f_ffree)
18155 + buf->f_ffree = ifree;
18158 + if (dli->dl_space_total == DLIM_INFINITY)
18161 + blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18163 + if (dli->dl_space_total < dli->dl_space_used)
18166 + bfree = (dli->dl_space_total - dli->dl_space_used)
18167 + >> sb->s_blocksize_bits;
18169 + bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18170 + if (bavail < dli->dl_space_used)
18173 + bavail = (bavail - dli->dl_space_used)
18174 + >> sb->s_blocksize_bits;
18176 + /* reduce max space available to limit */
18177 + if (buf->f_blocks > blimit)
18178 + buf->f_blocks = blimit;
18180 + /* reduce free space to min */
18181 + if (bfree < buf->f_bfree)
18182 + buf->f_bfree = bfree;
18184 + /* reduce avail space to min */
18185 + if (bavail < buf->f_bavail)
18186 + buf->f_bavail = bavail;
18189 + spin_unlock(&dli->dl_lock);
18190 + put_dl_info(dli);
18195 +#include <linux/module.h>
18197 +EXPORT_SYMBOL_GPL(locate_dl_info);
18198 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18200 diff -NurpP --minimal linux-3.9.4/kernel/vserver/helper.c linux-3.9.4-vs2.3.6.2/kernel/vserver/helper.c
18201 --- linux-3.9.4/kernel/vserver/helper.c 1970-01-01 00:00:00.000000000 +0000
18202 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/helper.c 2013-06-01 08:27:59.000000000 +0000
18205 + * linux/kernel/vserver/helper.c
18207 + * Virtual Context Support
18209 + * Copyright (C) 2004-2007 Herbert Pötzl
18211 + * V0.01 basic helper
18215 +#include <linux/kmod.h>
18216 +#include <linux/reboot.h>
18217 +#include <linux/vs_context.h>
18218 +#include <linux/vs_network.h>
18219 +#include <linux/vserver/signal.h>
18222 +char vshelper_path[255] = "/sbin/vshelper";
18224 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18226 + current->flags &= ~PF_THREAD_BOUND;
18230 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18234 + if ((ret = call_usermodehelper_fns(name, argv, envp,
18235 + sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18236 + vshelper_init, NULL, NULL))) {
18237 + printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18238 + name, argv[1], argv[2],
18239 + sync ? "sync" : "async", ret);
18241 + vxdprintk(VXD_CBIT(switch, 4),
18242 + "%s: (%s %s) returned %s with %d",
18243 + name, argv[1], argv[2], sync ? "sync" : "async", ret);
18248 + * vshelper path is set via /proc/sys
18249 + * invoked by vserver sys_reboot(), with
18250 + * the following arguments
18252 + * argv [0] = vshelper_path;
18253 + * argv [1] = action: "restart", "halt", "poweroff", ...
18254 + * argv [2] = context identifier
18256 + * envp [*] = type-specific parameters
18259 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18261 + char id_buf[8], cmd_buf[16];
18262 + char uid_buf[16], pid_buf[16];
18265 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
18266 + char *envp[] = {"HOME=/", "TERM=linux",
18267 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18268 + uid_buf, pid_buf, cmd_buf, 0};
18270 + if (vx_info_state(vxi, VXS_HELPER))
18272 + vxi->vx_state |= VXS_HELPER;
18274 + snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18276 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18277 + snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
18278 + from_kuid(&init_user_ns, current_uid()));
18279 + snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18282 + case LINUX_REBOOT_CMD_RESTART:
18283 + argv[1] = "restart";
18286 + case LINUX_REBOOT_CMD_HALT:
18287 + argv[1] = "halt";
18290 + case LINUX_REBOOT_CMD_POWER_OFF:
18291 + argv[1] = "poweroff";
18294 + case LINUX_REBOOT_CMD_SW_SUSPEND:
18295 + argv[1] = "swsusp";
18298 + case LINUX_REBOOT_CMD_OOM:
18303 + vxi->vx_state &= ~VXS_HELPER;
18307 + ret = do_vshelper(vshelper_path, argv, envp, 0);
18308 + vxi->vx_state &= ~VXS_HELPER;
18309 + __wakeup_vx_info(vxi);
18310 + return (ret) ? -EPERM : 0;
18314 +long vs_reboot(unsigned int cmd, void __user *arg)
18316 + struct vx_info *vxi = current_vx_info();
18319 + vxdprintk(VXD_CBIT(misc, 5),
18320 + "vs_reboot(%p[#%d],%u)",
18321 + vxi, vxi ? vxi->vx_id : 0, cmd);
18323 + ret = vs_reboot_helper(vxi, cmd, arg);
18327 + vxi->reboot_cmd = cmd;
18328 + if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18330 + case LINUX_REBOOT_CMD_RESTART:
18331 + case LINUX_REBOOT_CMD_HALT:
18332 + case LINUX_REBOOT_CMD_POWER_OFF:
18333 + vx_info_kill(vxi, 0, SIGKILL);
18334 + vx_info_kill(vxi, 1, SIGKILL);
18342 +long vs_oom_action(unsigned int cmd)
18344 + struct vx_info *vxi = current_vx_info();
18347 + vxdprintk(VXD_CBIT(misc, 5),
18348 + "vs_oom_action(%p[#%d],%u)",
18349 + vxi, vxi ? vxi->vx_id : 0, cmd);
18351 + ret = vs_reboot_helper(vxi, cmd, NULL);
18355 + vxi->reboot_cmd = cmd;
18356 + if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18357 + vx_info_kill(vxi, 0, SIGKILL);
18358 + vx_info_kill(vxi, 1, SIGKILL);
18364 + * argv [0] = vshelper_path;
18365 + * argv [1] = action: "startup", "shutdown"
18366 + * argv [2] = context identifier
18368 + * envp [*] = type-specific parameters
18371 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18373 + char id_buf[8], cmd_buf[16];
18374 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
18375 + char *envp[] = {"HOME=/", "TERM=linux",
18376 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18378 + if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18381 + snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18382 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18385 + case VSC_STARTUP:
18386 + argv[1] = "startup";
18388 + case VSC_SHUTDOWN:
18389 + argv[1] = "shutdown";
18395 + return do_vshelper(vshelper_path, argv, envp, 1);
18400 + * argv [0] = vshelper_path;
18401 + * argv [1] = action: "netup", "netdown"
18402 + * argv [2] = context identifier
18404 + * envp [*] = type-specific parameters
18407 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18409 + char id_buf[8], cmd_buf[16];
18410 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
18411 + char *envp[] = {"HOME=/", "TERM=linux",
18412 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18414 + if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18417 + snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18418 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18422 + argv[1] = "netup";
18424 + case VSC_NETDOWN:
18425 + argv[1] = "netdown";
18431 + return do_vshelper(vshelper_path, argv, envp, 1);
18434 diff -NurpP --minimal linux-3.9.4/kernel/vserver/history.c linux-3.9.4-vs2.3.6.2/kernel/vserver/history.c
18435 --- linux-3.9.4/kernel/vserver/history.c 1970-01-01 00:00:00.000000000 +0000
18436 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/history.c 2013-05-31 14:47:11.000000000 +0000
18439 + * kernel/vserver/history.c
18441 + * Virtual Context History Backtrace
18443 + * Copyright (C) 2004-2007 Herbert Pötzl
18445 + * V0.01 basic structure
18446 + * V0.02 hash/unhash and trace
18447 + * V0.03 preemption fixes
18451 +#include <linux/module.h>
18452 +#include <asm/uaccess.h>
18454 +#include <linux/vserver/context.h>
18455 +#include <linux/vserver/debug.h>
18456 +#include <linux/vserver/debug_cmd.h>
18457 +#include <linux/vserver/history.h>
18460 +#ifdef CONFIG_VSERVER_HISTORY
18461 +#define VXH_SIZE CONFIG_VSERVER_HISTORY_SIZE
18463 +#define VXH_SIZE 64
18466 +struct _vx_history {
18467 + unsigned int counter;
18469 + struct _vx_hist_entry entry[VXH_SIZE + 1];
18473 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18475 +unsigned volatile int vxh_active = 1;
18477 +static atomic_t sequence = ATOMIC_INIT(0);
18482 + * requires disabled preemption */
18484 +struct _vx_hist_entry *vxh_advance(void *loc)
18486 + unsigned int cpu = smp_processor_id();
18487 + struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18488 + struct _vx_hist_entry *entry;
18489 + unsigned int index;
18491 + index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18492 + entry = &hist->entry[index];
18494 + entry->seq = atomic_inc_return(&sequence);
18495 + entry->loc = loc;
18499 +EXPORT_SYMBOL_GPL(vxh_advance);
18502 +#define VXH_LOC_FMTS "(#%04x,*%d):%p"
18504 +#define VXH_LOC_ARGS(e) (e)->seq, cpu, (e)->loc
18507 +#define VXH_VXI_FMTS "%p[#%d,%d.%d]"
18509 +#define VXH_VXI_ARGS(e) (e)->vxi.ptr, \
18510 + (e)->vxi.ptr ? (e)->vxi.xid : 0, \
18511 + (e)->vxi.ptr ? (e)->vxi.usecnt : 0, \
18512 + (e)->vxi.ptr ? (e)->vxi.tasks : 0
18514 +void vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18516 + switch (e->type) {
18517 + case VXH_THROW_OOPS:
18518 + printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18521 + case VXH_GET_VX_INFO:
18522 + case VXH_PUT_VX_INFO:
18523 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18525 + (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18526 + VXH_VXI_ARGS(e));
18529 + case VXH_INIT_VX_INFO:
18530 + case VXH_SET_VX_INFO:
18531 + case VXH_CLR_VX_INFO:
18532 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18534 + (e->type == VXH_INIT_VX_INFO) ? "init" :
18535 + ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18536 + VXH_VXI_ARGS(e), e->sc.data);
18539 + case VXH_CLAIM_VX_INFO:
18540 + case VXH_RELEASE_VX_INFO:
18541 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18543 + (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18544 + VXH_VXI_ARGS(e), e->sc.data);
18547 + case VXH_ALLOC_VX_INFO:
18548 + case VXH_DEALLOC_VX_INFO:
18549 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18551 + (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18552 + VXH_VXI_ARGS(e));
18555 + case VXH_HASH_VX_INFO:
18556 + case VXH_UNHASH_VX_INFO:
18557 + printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18559 + (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18560 + VXH_VXI_ARGS(e));
18563 + case VXH_LOC_VX_INFO:
18564 + case VXH_LOOKUP_VX_INFO:
18565 + case VXH_CREATE_VX_INFO:
18566 + printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18568 + (e->type == VXH_CREATE_VX_INFO) ? "create" :
18569 + ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18570 + e->ll.arg, VXH_VXI_ARGS(e));
18575 +static void __vxh_dump_history(void)
18577 + unsigned int i, cpu;
18579 + printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18580 + atomic_read(&sequence), NR_CPUS);
18582 + for (i = 0; i < VXH_SIZE; i++) {
18583 + for_each_online_cpu(cpu) {
18584 + struct _vx_history *hist =
18585 + &per_cpu(vx_history_buffer, cpu);
18586 + unsigned int index = (hist->counter - i) % VXH_SIZE;
18587 + struct _vx_hist_entry *entry = &hist->entry[index];
18589 + vxh_dump_entry(entry, cpu);
18594 +void vxh_dump_history(void)
18598 + local_irq_enable();
18600 + local_irq_disable();
18602 + __vxh_dump_history();
18606 +/* vserver syscall commands below here */
18609 +int vc_dump_history(uint32_t id)
18612 + __vxh_dump_history();
18619 +int do_read_history(struct __user _vx_hist_entry *data,
18620 + int cpu, uint32_t *index, uint32_t *count)
18622 + int pos, ret = 0;
18623 + struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18624 + int end = hist->counter;
18625 + int start = end - VXH_SIZE + 2;
18626 + int idx = *index;
18628 + /* special case: get current pos */
18634 + /* have we lost some data? */
18638 + for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18639 + struct _vx_hist_entry *entry =
18640 + &hist->entry[idx % VXH_SIZE];
18642 + /* send entry to userspace */
18643 + ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18647 + /* save new index and count */
18650 + return ret ? ret : (*index < end);
18653 +int vc_read_history(uint32_t id, void __user *data)
18655 + struct vcmd_read_history_v0 vc_data;
18658 + if (id >= NR_CPUS)
18661 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18664 + ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18665 + id, &vc_data.index, &vc_data.count);
18667 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18672 +#ifdef CONFIG_COMPAT
18674 +int vc_read_history_x32(uint32_t id, void __user *data)
18676 + struct vcmd_read_history_v0_x32 vc_data;
18679 + if (id >= NR_CPUS)
18682 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18685 + ret = do_read_history((struct __user _vx_hist_entry *)
18686 + compat_ptr(vc_data.data_ptr),
18687 + id, &vc_data.index, &vc_data.count);
18689 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18694 +#endif /* CONFIG_COMPAT */
18696 diff -NurpP --minimal linux-3.9.4/kernel/vserver/inet.c linux-3.9.4-vs2.3.6.2/kernel/vserver/inet.c
18697 --- linux-3.9.4/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
18698 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/inet.c 2013-05-31 22:43:05.000000000 +0000
18701 +#include <linux/in.h>
18702 +#include <linux/inetdevice.h>
18703 +#include <linux/export.h>
18704 +#include <linux/vs_inet.h>
18705 +#include <linux/vs_inet6.h>
18706 +#include <linux/vserver/debug.h>
18707 +#include <net/route.h>
18708 +#include <net/addrconf.h>
18711 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18715 + if (!nxi1 || !nxi2 || nxi1 == nxi2)
18718 + struct nx_addr_v4 *ptr;
18719 + unsigned long irqflags;
18721 + spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18722 + for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18723 + if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18728 + spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18731 + vxdprintk(VXD_CBIT(net, 2),
18732 + "nx_v4_addr_conflict(%p,%p): %d",
18733 + nxi1, nxi2, ret);
18739 +#ifdef CONFIG_IPV6
18741 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18745 + if (!nxi1 || !nxi2 || nxi1 == nxi2)
18748 + struct nx_addr_v6 *ptr;
18749 + unsigned long irqflags;
18751 + spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18752 + for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18753 + if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18758 + spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18761 + vxdprintk(VXD_CBIT(net, 2),
18762 + "nx_v6_addr_conflict(%p,%p): %d",
18763 + nxi1, nxi2, ret);
18770 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18772 + struct in_device *in_dev;
18773 + struct in_ifaddr **ifap;
18774 + struct in_ifaddr *ifa;
18779 + in_dev = in_dev_get(dev);
18783 + for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18784 + ifap = &ifa->ifa_next) {
18785 + if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18790 + in_dev_put(in_dev);
18796 +#ifdef CONFIG_IPV6
18798 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18800 + struct inet6_dev *in_dev;
18801 + struct inet6_ifaddr *ifa;
18806 + in_dev = in6_dev_get(dev);
18810 + // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18811 + list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18812 + if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18817 + in6_dev_put(in_dev);
18824 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18830 + if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18832 +#ifdef CONFIG_IPV6
18834 + if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18839 + vxdprintk(VXD_CBIT(net, 3),
18840 + "dev_in_nx_info(%p,%p[#%d]) = %d",
18841 + dev, nxi, nxi ? nxi->nx_id : 0, ret);
18845 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18846 + struct flowi4 *fl4)
18848 + struct rtable *rt;
18853 + /* FIXME: handle lback only case */
18854 + if (!NX_IPV4(nxi))
18855 + return ERR_PTR(-EPERM);
18857 + vxdprintk(VXD_CBIT(net, 4),
18858 + "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18859 + nxi, nxi ? nxi->nx_id : 0,
18860 + NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18862 + /* single IP is unconditional */
18863 + if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18864 + (fl4->saddr == INADDR_ANY))
18865 + fl4->saddr = nxi->v4.ip[0].s_addr;
18867 + if (fl4->saddr == INADDR_ANY) {
18868 + struct nx_addr_v4 *ptr;
18869 + __be32 found = 0;
18871 + rt = __ip_route_output_key(net, fl4);
18872 + if (!IS_ERR(rt)) {
18873 + found = fl4->saddr;
18875 + vxdprintk(VXD_CBIT(net, 4),
18876 + "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18877 + nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18878 + if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18882 + WARN_ON_ONCE(in_irq());
18883 + spin_lock_bh(&nxi->addr_lock);
18884 + for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18885 + __be32 primary = ptr->ip[0].s_addr;
18886 + __be32 mask = ptr->mask.s_addr;
18887 + __be32 neta = primary & mask;
18889 + vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18890 + NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18891 + nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18892 + NIPQUAD(mask), NIPQUAD(neta));
18893 + if ((found & mask) != neta)
18896 + fl4->saddr = primary;
18897 + rt = __ip_route_output_key(net, fl4);
18898 + vxdprintk(VXD_CBIT(net, 4),
18899 + "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18900 + nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18901 + if (!IS_ERR(rt)) {
18902 + found = fl4->saddr;
18904 + if (found == primary)
18905 + goto found_unlock;
18908 + /* still no source ip? */
18909 + found = ipv4_is_loopback(fl4->daddr)
18910 + ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18912 + spin_unlock_bh(&nxi->addr_lock);
18914 + /* assign src ip to flow */
18915 + fl4->saddr = found;
18918 + if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18919 + return ERR_PTR(-EPERM);
18922 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18923 + if (ipv4_is_loopback(fl4->daddr))
18924 + fl4->daddr = nxi->v4_lback.s_addr;
18925 + if (ipv4_is_loopback(fl4->saddr))
18926 + fl4->saddr = nxi->v4_lback.s_addr;
18927 + } else if (ipv4_is_loopback(fl4->daddr) &&
18928 + !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18929 + return ERR_PTR(-EPERM);
18934 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18936 diff -NurpP --minimal linux-3.9.4/kernel/vserver/init.c linux-3.9.4-vs2.3.6.2/kernel/vserver/init.c
18937 --- linux-3.9.4/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
18938 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/init.c 2013-05-31 14:47:11.000000000 +0000
18941 + * linux/kernel/init.c
18943 + * Virtual Server Init
18945 + * Copyright (C) 2004-2007 Herbert Pötzl
18947 + * V0.01 basic structure
18951 +#include <linux/init.h>
18953 +int vserver_register_sysctl(void);
18954 +void vserver_unregister_sysctl(void);
18957 +static int __init init_vserver(void)
18961 +#ifdef CONFIG_VSERVER_DEBUG
18962 + vserver_register_sysctl();
18968 +static void __exit exit_vserver(void)
18971 +#ifdef CONFIG_VSERVER_DEBUG
18972 + vserver_unregister_sysctl();
18977 +/* FIXME: GFP_ZONETYPES gone
18978 +long vx_slab[GFP_ZONETYPES]; */
18982 +module_init(init_vserver);
18983 +module_exit(exit_vserver);
18985 diff -NurpP --minimal linux-3.9.4/kernel/vserver/inode.c linux-3.9.4-vs2.3.6.2/kernel/vserver/inode.c
18986 --- linux-3.9.4/kernel/vserver/inode.c 1970-01-01 00:00:00.000000000 +0000
18987 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/inode.c 2013-06-01 08:26:06.000000000 +0000
18990 + * linux/kernel/vserver/inode.c
18992 + * Virtual Server: File System Support
18994 + * Copyright (C) 2004-2007 Herbert Pötzl
18996 + * V0.01 separated from vcontext V0.05
18997 + * V0.02 moved to tag (instead of xid)
19001 +#include <linux/tty.h>
19002 +#include <linux/proc_fs.h>
19003 +#include <linux/devpts_fs.h>
19004 +#include <linux/fs.h>
19005 +#include <linux/file.h>
19006 +#include <linux/mount.h>
19007 +#include <linux/parser.h>
19008 +#include <linux/namei.h>
19009 +#include <linux/vserver/inode.h>
19010 +#include <linux/vserver/inode_cmd.h>
19011 +#include <linux/vs_base.h>
19012 +#include <linux/vs_tag.h>
19014 +#include <asm/uaccess.h>
19017 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19019 + struct proc_dir_entry *entry;
19021 + if (!in || !in->i_sb)
19024 + *flags = IATTR_TAG
19025 + | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19026 + | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19027 + | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19028 + | (IS_COW(in) ? IATTR_COW : 0);
19029 + *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19031 + if (S_ISDIR(in->i_mode))
19032 + *mask |= IATTR_BARRIER;
19034 + if (IS_TAGGED(in)) {
19035 + *tag = i_tag_read(in);
19036 + *mask |= IATTR_TAG;
19039 + switch (in->i_sb->s_magic) {
19040 + case PROC_SUPER_MAGIC:
19041 + entry = PROC_I(in)->pde;
19043 + /* check for specific inodes? */
19045 + *mask |= IATTR_FLAGS;
19047 + *flags |= (entry->vx_flags & IATTR_FLAGS);
19049 + *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19052 + case DEVPTS_SUPER_MAGIC:
19053 + *tag = i_tag_read(in);
19054 + *mask |= IATTR_TAG;
19063 +int vc_get_iattr(void __user *data)
19065 + struct path path;
19066 + struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19069 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19072 + ret = user_lpath(vc_data.name, &path);
19074 + ret = __vc_get_iattr(path.dentry->d_inode,
19075 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19081 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19086 +#ifdef CONFIG_COMPAT
19088 +int vc_get_iattr_x32(void __user *data)
19090 + struct path path;
19091 + struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19094 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19097 + ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19099 + ret = __vc_get_iattr(path.dentry->d_inode,
19100 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19106 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19111 +#endif /* CONFIG_COMPAT */
19114 +int vc_fget_iattr(uint32_t fd, void __user *data)
19116 + struct file *filp;
19117 + struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19120 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19124 + if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19127 + ret = __vc_get_iattr(filp->f_dentry->d_inode,
19128 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19132 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19138 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19140 + struct inode *in = de->d_inode;
19141 + int error = 0, is_proc = 0, has_tag = 0;
19142 + struct iattr attr = { 0 };
19144 + if (!in || !in->i_sb)
19147 + is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19148 + if ((*mask & IATTR_FLAGS) && !is_proc)
19151 + has_tag = IS_TAGGED(in) ||
19152 + (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19153 + if ((*mask & IATTR_TAG) && !has_tag)
19156 + mutex_lock(&in->i_mutex);
19157 + if (*mask & IATTR_TAG) {
19158 + attr.ia_tag = make_ktag(&init_user_ns, *tag);
19159 + attr.ia_valid |= ATTR_TAG;
19162 + if (*mask & IATTR_FLAGS) {
19163 + struct proc_dir_entry *entry = PROC_I(in)->pde;
19164 + unsigned int iflags = PROC_I(in)->vx_flags;
19166 + iflags = (iflags & ~(*mask & IATTR_FLAGS))
19167 + | (*flags & IATTR_FLAGS);
19168 + PROC_I(in)->vx_flags = iflags;
19170 + entry->vx_flags = iflags;
19173 + if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19174 + IATTR_BARRIER | IATTR_COW)) {
19175 + int iflags = in->i_flags;
19176 + int vflags = in->i_vflags;
19178 + if (*mask & IATTR_IMMUTABLE) {
19179 + if (*flags & IATTR_IMMUTABLE)
19180 + iflags |= S_IMMUTABLE;
19182 + iflags &= ~S_IMMUTABLE;
19184 + if (*mask & IATTR_IXUNLINK) {
19185 + if (*flags & IATTR_IXUNLINK)
19186 + iflags |= S_IXUNLINK;
19188 + iflags &= ~S_IXUNLINK;
19190 + if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19191 + if (*flags & IATTR_BARRIER)
19192 + vflags |= V_BARRIER;
19194 + vflags &= ~V_BARRIER;
19196 + if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19197 + if (*flags & IATTR_COW)
19200 + vflags &= ~V_COW;
19202 + if (in->i_op && in->i_op->sync_flags) {
19203 + error = in->i_op->sync_flags(in, iflags, vflags);
19209 + if (attr.ia_valid) {
19210 + if (in->i_op && in->i_op->setattr)
19211 + error = in->i_op->setattr(de, &attr);
19213 + error = inode_change_ok(in, &attr);
19215 + setattr_copy(in, &attr);
19216 + mark_inode_dirty(in);
19222 + mutex_unlock(&in->i_mutex);
19226 +int vc_set_iattr(void __user *data)
19228 + struct path path;
19229 + struct vcmd_ctx_iattr_v1 vc_data;
19232 + if (!capable(CAP_LINUX_IMMUTABLE))
19234 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19237 + ret = user_lpath(vc_data.name, &path);
19239 + ret = __vc_set_iattr(path.dentry,
19240 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19244 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19249 +#ifdef CONFIG_COMPAT
19251 +int vc_set_iattr_x32(void __user *data)
19253 + struct path path;
19254 + struct vcmd_ctx_iattr_v1_x32 vc_data;
19257 + if (!capable(CAP_LINUX_IMMUTABLE))
19259 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19262 + ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19264 + ret = __vc_set_iattr(path.dentry,
19265 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19269 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19274 +#endif /* CONFIG_COMPAT */
19276 +int vc_fset_iattr(uint32_t fd, void __user *data)
19278 + struct file *filp;
19279 + struct vcmd_ctx_fiattr_v0 vc_data;
19282 + if (!capable(CAP_LINUX_IMMUTABLE))
19284 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19288 + if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19291 + ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19292 + &vc_data.flags, &vc_data.mask);
19296 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19302 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19304 +static match_table_t tokens = {
19305 + {Opt_notagcheck, "notagcheck"},
19306 +#ifdef CONFIG_PROPAGATE
19307 + {Opt_notag, "notag"},
19308 + {Opt_tag, "tag"},
19309 + {Opt_tagid, "tagid=%u"},
19315 +static void __dx_parse_remove(char *string, char *opt)
19317 + char *p = strstr(string, opt);
19321 + while (*q != '\0' && *q != ',')
19330 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19331 + unsigned long *flags)
19334 + substring_t args[MAX_OPT_ARGS];
19336 + char *s, *p, *opts;
19337 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19343 + s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19348 + while ((p = strsep(&opts, ",")) != NULL) {
19349 + token = match_token(p, tokens, args);
19352 +#ifdef CONFIG_PROPAGATE
19357 + __dx_parse_remove(s, "tag");
19358 + *mnt_flags |= MNT_TAGID;
19359 + set |= MNT_TAGID;
19363 + __dx_parse_remove(s, "notag");
19364 + *mnt_flags |= MNT_NOTAG;
19365 + set |= MNT_NOTAG;
19368 + if (tag && !match_int(args, &option))
19371 + __dx_parse_remove(s, "tagid");
19372 + *mnt_flags |= MNT_TAGID;
19373 + set |= MNT_TAGID;
19375 +#endif /* CONFIG_PROPAGATE */
19376 + case Opt_notagcheck:
19378 + __dx_parse_remove(s, "notagcheck");
19379 + *flags |= MS_NOTAGCHECK;
19380 + set |= MS_NOTAGCHECK;
19383 + vxdprintk(VXD_CBIT(tag, 7),
19384 + "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19385 + p, token, option);
19388 + strcpy(string, s);
19393 +#ifdef CONFIG_PROPAGATE
19395 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19397 + tag_t new_tag = 0;
19398 + struct vfsmount *mnt;
19403 + mnt = nd->path.mnt;
19407 + propagate = (mnt->mnt_flags & MNT_TAGID);
19409 + new_tag = mnt->mnt_tag;
19411 + vxdprintk(VXD_CBIT(tag, 7),
19412 + "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19413 + inode, inode->i_ino, inode->i_tag,
19414 + new_tag, (propagate) ? 1 : 0);
19417 + i_tag_write(inode, new_tag);
19420 +#include <linux/module.h>
19422 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19424 +#endif /* CONFIG_PROPAGATE */
19426 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit.c linux-3.9.4-vs2.3.6.2/kernel/vserver/limit.c
19427 --- linux-3.9.4/kernel/vserver/limit.c 1970-01-01 00:00:00.000000000 +0000
19428 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/limit.c 2013-05-31 14:47:11.000000000 +0000
19431 + * linux/kernel/vserver/limit.c
19433 + * Virtual Server: Context Limits
19435 + * Copyright (C) 2004-2010 Herbert Pötzl
19437 + * V0.01 broken out from vcontext V0.05
19438 + * V0.02 changed vcmds to vxi arg
19439 + * V0.03 added memory cgroup support
19443 +#include <linux/sched.h>
19444 +#include <linux/module.h>
19445 +#include <linux/memcontrol.h>
19446 +#include <linux/res_counter.h>
19447 +#include <linux/vs_limit.h>
19448 +#include <linux/vserver/limit.h>
19449 +#include <linux/vserver/limit_cmd.h>
19451 +#include <asm/uaccess.h>
19454 +const char *vlimit_name[NUM_LIMITS] = {
19455 + [RLIMIT_CPU] = "CPU",
19456 + [RLIMIT_NPROC] = "NPROC",
19457 + [RLIMIT_NOFILE] = "NOFILE",
19458 + [RLIMIT_LOCKS] = "LOCKS",
19459 + [RLIMIT_SIGPENDING] = "SIGP",
19460 + [RLIMIT_MSGQUEUE] = "MSGQ",
19462 + [VLIMIT_NSOCK] = "NSOCK",
19463 + [VLIMIT_OPENFD] = "OPENFD",
19464 + [VLIMIT_SHMEM] = "SHMEM",
19465 + [VLIMIT_DENTRY] = "DENTRY",
19468 +EXPORT_SYMBOL_GPL(vlimit_name);
19470 +#define MASK_ENTRY(x) (1 << (x))
19472 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19475 + , /* softlimit */
19478 + MASK_ENTRY( RLIMIT_NPROC ) |
19479 + MASK_ENTRY( RLIMIT_NOFILE ) |
19480 + MASK_ENTRY( RLIMIT_LOCKS ) |
19481 + MASK_ENTRY( RLIMIT_MSGQUEUE ) |
19483 + MASK_ENTRY( VLIMIT_NSOCK ) |
19484 + MASK_ENTRY( VLIMIT_OPENFD ) |
19485 + MASK_ENTRY( VLIMIT_SHMEM ) |
19486 + MASK_ENTRY( VLIMIT_DENTRY ) |
19489 + /* accounting only */
19490 +uint32_t account_mask =
19491 + MASK_ENTRY( VLIMIT_SEMARY ) |
19492 + MASK_ENTRY( VLIMIT_NSEMS ) |
19493 + MASK_ENTRY( VLIMIT_MAPPED ) |
19497 +static int is_valid_vlimit(int id)
19499 + uint32_t mask = vlimit_mask.minimum |
19500 + vlimit_mask.softlimit | vlimit_mask.maximum;
19501 + return mask & (1 << id);
19504 +static int is_accounted_vlimit(int id)
19506 + if (is_valid_vlimit(id))
19508 + return account_mask & (1 << id);
19512 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19514 + rlim_t limit = __rlim_soft(&vxi->limit, id);
19515 + return VX_VLIM(limit);
19518 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19520 + rlim_t limit = __rlim_hard(&vxi->limit, id);
19521 + return VX_VLIM(limit);
19524 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19525 + uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19527 + if (!is_valid_vlimit(id))
19531 + *minimum = CRLIM_UNSET;
19533 + *softlimit = vc_get_soft(vxi, id);
19535 + *maximum = vc_get_hard(vxi, id);
19539 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19541 + struct vcmd_ctx_rlimit_v0 vc_data;
19544 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19547 + ret = do_get_rlimit(vxi, vc_data.id,
19548 + &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19552 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19557 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19558 + uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19560 + if (!is_valid_vlimit(id))
19563 + if (maximum != CRLIM_KEEP)
19564 + __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19565 + if (softlimit != CRLIM_KEEP)
19566 + __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19568 + /* clamp soft limit */
19569 + if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19570 + __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19575 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19577 + struct vcmd_ctx_rlimit_v0 vc_data;
19579 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19582 + return do_set_rlimit(vxi, vc_data.id,
19583 + vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19586 +#ifdef CONFIG_IA32_EMULATION
19588 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19590 + struct vcmd_ctx_rlimit_v0_x32 vc_data;
19592 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19595 + return do_set_rlimit(vxi, vc_data.id,
19596 + vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19599 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19601 + struct vcmd_ctx_rlimit_v0_x32 vc_data;
19604 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19607 + ret = do_get_rlimit(vxi, vc_data.id,
19608 + &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19612 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19617 +#endif /* CONFIG_IA32_EMULATION */
19620 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19622 + if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19628 +static inline void vx_reset_hits(struct _vx_limit *limit)
19632 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19633 + atomic_set(&__rlim_lhit(limit, lim), 0);
19637 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19639 + vx_reset_hits(&vxi->limit);
19643 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19648 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19649 + value = __rlim_get(limit, lim);
19650 + __rlim_rmax(limit, lim) = value;
19651 + __rlim_rmin(limit, lim) = value;
19655 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19657 + vx_reset_minmax(&vxi->limit);
19662 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19664 + struct vcmd_rlimit_stat_v0 vc_data;
19665 + struct _vx_limit *limit = &vxi->limit;
19668 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19672 + if (!is_accounted_vlimit(id))
19675 + vx_limit_fixup(limit, id);
19676 + vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19677 + vc_data.value = __rlim_get(limit, id);
19678 + vc_data.minimum = __rlim_rmin(limit, id);
19679 + vc_data.maximum = __rlim_rmax(limit, id);
19681 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19687 +void vx_vsi_meminfo(struct sysinfo *val)
19689 +#ifdef CONFIG_MEMCG
19690 + struct mem_cgroup *mcg;
19691 + u64 res_limit, res_usage;
19694 + mcg = mem_cgroup_from_task(current);
19695 + rcu_read_unlock();
19699 + res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19700 + res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19702 + if (res_limit != RESOURCE_MAX)
19703 + val->totalram = (res_limit >> PAGE_SHIFT);
19704 + val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19705 + val->bufferram = 0;
19706 + val->totalhigh = 0;
19707 + val->freehigh = 0;
19709 +#endif /* CONFIG_MEMCG */
19713 +void vx_vsi_swapinfo(struct sysinfo *val)
19715 +#ifdef CONFIG_MEMCG
19716 +#ifdef CONFIG_MEMCG_SWAP
19717 + struct mem_cgroup *mcg;
19718 + u64 res_limit, res_usage, memsw_limit, memsw_usage;
19719 + s64 swap_limit, swap_usage;
19722 + mcg = mem_cgroup_from_task(current);
19723 + rcu_read_unlock();
19727 + res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19728 + res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19729 + memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19730 + memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19732 + /* memory unlimited */
19733 + if (res_limit == RESOURCE_MAX)
19736 + swap_limit = memsw_limit - res_limit;
19737 + /* we have a swap limit? */
19738 + if (memsw_limit != RESOURCE_MAX)
19739 + val->totalswap = swap_limit >> PAGE_SHIFT;
19741 + /* calculate swap part */
19742 + swap_usage = (memsw_usage > res_usage) ?
19743 + memsw_usage - res_usage : 0;
19745 + /* total shown minus usage gives free swap */
19746 + val->freeswap = (swap_usage < swap_limit) ?
19747 + val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19749 +#else /* !CONFIG_MEMCG_SWAP */
19750 + val->totalswap = 0;
19751 + val->freeswap = 0;
19752 +#endif /* !CONFIG_MEMCG_SWAP */
19753 +#endif /* CONFIG_MEMCG */
19757 +long vx_vsi_cached(struct sysinfo *val)
19760 +#ifdef CONFIG_MEMCG
19761 + struct mem_cgroup *mcg;
19764 + mcg = mem_cgroup_from_task(current);
19765 + rcu_read_unlock();
19769 + cache = mem_cgroup_stat_read_cache(mcg);
19775 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit_init.h linux-3.9.4-vs2.3.6.2/kernel/vserver/limit_init.h
19776 --- linux-3.9.4/kernel/vserver/limit_init.h 1970-01-01 00:00:00.000000000 +0000
19777 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/limit_init.h 2013-05-31 14:47:11.000000000 +0000
19781 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19785 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19786 + __rlim_soft(limit, lim) = RLIM_INFINITY;
19787 + __rlim_hard(limit, lim) = RLIM_INFINITY;
19788 + __rlim_set(limit, lim, 0);
19789 + atomic_set(&__rlim_lhit(limit, lim), 0);
19790 + __rlim_rmin(limit, lim) = 0;
19791 + __rlim_rmax(limit, lim) = 0;
19795 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19800 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19801 + if ((1 << lim) & VLIM_NOCHECK)
19803 + value = __rlim_get(limit, lim);
19804 + vxwprintk_xid(value,
19805 + "!!! limit: %p[%s,%d] = %ld on exit.",
19806 + limit, vlimit_name[lim], lim, (long)value);
19810 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit_proc.h linux-3.9.4-vs2.3.6.2/kernel/vserver/limit_proc.h
19811 --- linux-3.9.4/kernel/vserver/limit_proc.h 1970-01-01 00:00:00.000000000 +0000
19812 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/limit_proc.h 2013-05-31 14:47:11.000000000 +0000
19814 +#ifndef _VX_LIMIT_PROC_H
19815 +#define _VX_LIMIT_PROC_H
19817 +#include <linux/vserver/limit_int.h>
19820 +#define VX_LIMIT_FMT ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19821 +#define VX_LIMIT_TOP \
19822 + "Limit\t current\t min/max\t\t soft/hard\t\thits\n"
19824 +#define VX_LIMIT_ARG(r) \
19825 + (unsigned long)__rlim_get(limit, r), \
19826 + (unsigned long)__rlim_rmin(limit, r), \
19827 + (unsigned long)__rlim_rmax(limit, r), \
19828 + VX_VLIM(__rlim_soft(limit, r)), \
19829 + VX_VLIM(__rlim_hard(limit, r)), \
19830 + atomic_read(&__rlim_lhit(limit, r))
19832 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19834 + vx_limit_fixup(limit, -1);
19835 + return sprintf(buffer, VX_LIMIT_TOP
19836 + "PROC" VX_LIMIT_FMT
19837 + "VM" VX_LIMIT_FMT
19838 + "VML" VX_LIMIT_FMT
19839 + "RSS" VX_LIMIT_FMT
19840 + "ANON" VX_LIMIT_FMT
19841 + "RMAP" VX_LIMIT_FMT
19842 + "FILES" VX_LIMIT_FMT
19843 + "OFD" VX_LIMIT_FMT
19844 + "LOCKS" VX_LIMIT_FMT
19845 + "SOCK" VX_LIMIT_FMT
19846 + "MSGQ" VX_LIMIT_FMT
19847 + "SHM" VX_LIMIT_FMT
19848 + "SEMA" VX_LIMIT_FMT
19849 + "SEMS" VX_LIMIT_FMT
19850 + "DENT" VX_LIMIT_FMT,
19851 + VX_LIMIT_ARG(RLIMIT_NPROC),
19852 + VX_LIMIT_ARG(RLIMIT_AS),
19853 + VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19854 + VX_LIMIT_ARG(RLIMIT_RSS),
19855 + VX_LIMIT_ARG(VLIMIT_ANON),
19856 + VX_LIMIT_ARG(VLIMIT_MAPPED),
19857 + VX_LIMIT_ARG(RLIMIT_NOFILE),
19858 + VX_LIMIT_ARG(VLIMIT_OPENFD),
19859 + VX_LIMIT_ARG(RLIMIT_LOCKS),
19860 + VX_LIMIT_ARG(VLIMIT_NSOCK),
19861 + VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19862 + VX_LIMIT_ARG(VLIMIT_SHMEM),
19863 + VX_LIMIT_ARG(VLIMIT_SEMARY),
19864 + VX_LIMIT_ARG(VLIMIT_NSEMS),
19865 + VX_LIMIT_ARG(VLIMIT_DENTRY));
19868 +#endif /* _VX_LIMIT_PROC_H */
19871 diff -NurpP --minimal linux-3.9.4/kernel/vserver/network.c linux-3.9.4-vs2.3.6.2/kernel/vserver/network.c
19872 --- linux-3.9.4/kernel/vserver/network.c 1970-01-01 00:00:00.000000000 +0000
19873 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/network.c 2013-05-31 14:47:11.000000000 +0000
19876 + * linux/kernel/vserver/network.c
19878 + * Virtual Server: Network Support
19880 + * Copyright (C) 2003-2007 Herbert Pötzl
19882 + * V0.01 broken out from vcontext V0.05
19883 + * V0.02 cleaned up implementation
19884 + * V0.03 added equiv nx commands
19885 + * V0.04 switch to RCU based hash
19886 + * V0.05 and back to locking again
19887 + * V0.06 changed vcmds to nxi arg
19888 + * V0.07 have __create claim() the nxi
19892 +#include <linux/err.h>
19893 +#include <linux/slab.h>
19894 +#include <linux/rcupdate.h>
19895 +#include <net/ipv6.h>
19897 +#include <linux/vs_network.h>
19898 +#include <linux/vs_pid.h>
19899 +#include <linux/vserver/network_cmd.h>
19902 +atomic_t nx_global_ctotal = ATOMIC_INIT(0);
19903 +atomic_t nx_global_cactive = ATOMIC_INIT(0);
19905 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19906 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19909 +static int __init init_network(void)
19911 + nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19912 + sizeof(struct nx_addr_v4), 0,
19913 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19914 + nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19915 + sizeof(struct nx_addr_v6), 0,
19916 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19921 +/* __alloc_nx_addr_v4() */
19923 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19925 + struct nx_addr_v4 *nxa = kmem_cache_alloc(
19926 + nx_addr_v4_cachep, GFP_KERNEL);
19928 + if (!IS_ERR(nxa))
19929 + memset(nxa, 0, sizeof(*nxa));
19933 +/* __dealloc_nx_addr_v4() */
19935 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19937 + kmem_cache_free(nx_addr_v4_cachep, nxa);
19940 +/* __dealloc_nx_addr_v4_all() */
19942 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19945 + struct nx_addr_v4 *next = nxa->next;
19947 + __dealloc_nx_addr_v4(nxa);
19953 +#ifdef CONFIG_IPV6
19955 +/* __alloc_nx_addr_v6() */
19957 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19959 + struct nx_addr_v6 *nxa = kmem_cache_alloc(
19960 + nx_addr_v6_cachep, GFP_KERNEL);
19962 + if (!IS_ERR(nxa))
19963 + memset(nxa, 0, sizeof(*nxa));
19967 +/* __dealloc_nx_addr_v6() */
19969 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19971 + kmem_cache_free(nx_addr_v6_cachep, nxa);
19974 +/* __dealloc_nx_addr_v6_all() */
19976 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19979 + struct nx_addr_v6 *next = nxa->next;
19981 + __dealloc_nx_addr_v6(nxa);
19986 +#endif /* CONFIG_IPV6 */
19988 +/* __alloc_nx_info()
19990 + * allocate an initialized nx_info struct
19991 + * doesn't make it visible (hash) */
19993 +static struct nx_info *__alloc_nx_info(nid_t nid)
19995 + struct nx_info *new = NULL;
19997 + vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19999 + /* would this benefit from a slab cache? */
20000 + new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20004 + memset(new, 0, sizeof(struct nx_info));
20005 + new->nx_id = nid;
20006 + INIT_HLIST_NODE(&new->nx_hlist);
20007 + atomic_set(&new->nx_usecnt, 0);
20008 + atomic_set(&new->nx_tasks, 0);
20009 + spin_lock_init(&new->addr_lock);
20010 + new->nx_state = 0;
20012 + new->nx_flags = NXF_INIT_SET;
20014 + /* rest of init goes here */
20016 + new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20017 + new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20019 + vxdprintk(VXD_CBIT(nid, 0),
20020 + "alloc_nx_info(%d) = %p", nid, new);
20021 + atomic_inc(&nx_global_ctotal);
20025 +/* __dealloc_nx_info()
20027 + * final disposal of nx_info */
20029 +static void __dealloc_nx_info(struct nx_info *nxi)
20031 + vxdprintk(VXD_CBIT(nid, 0),
20032 + "dealloc_nx_info(%p)", nxi);
20034 + nxi->nx_hlist.next = LIST_POISON1;
20037 + BUG_ON(atomic_read(&nxi->nx_usecnt));
20038 + BUG_ON(atomic_read(&nxi->nx_tasks));
20040 + __dealloc_nx_addr_v4_all(nxi->v4.next);
20041 +#ifdef CONFIG_IPV6
20042 + __dealloc_nx_addr_v6_all(nxi->v6.next);
20045 + nxi->nx_state |= NXS_RELEASED;
20047 + atomic_dec(&nx_global_ctotal);
20050 +static void __shutdown_nx_info(struct nx_info *nxi)
20052 + nxi->nx_state |= NXS_SHUTDOWN;
20053 + vs_net_change(nxi, VSC_NETDOWN);
20056 +/* exported stuff */
20058 +void free_nx_info(struct nx_info *nxi)
20060 + /* context shutdown is mandatory */
20061 + BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20063 + /* context must not be hashed */
20064 + BUG_ON(nxi->nx_state & NXS_HASHED);
20066 + BUG_ON(atomic_read(&nxi->nx_usecnt));
20067 + BUG_ON(atomic_read(&nxi->nx_tasks));
20069 + __dealloc_nx_info(nxi);
20073 +void __nx_set_lback(struct nx_info *nxi)
20075 + int nid = nxi->nx_id;
20076 + __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20078 + nxi->v4_lback.s_addr = lback;
20081 +extern int __nx_inet_add_lback(__be32 addr);
20082 +extern int __nx_inet_del_lback(__be32 addr);
20085 +/* hash table for nx_info hash */
20087 +#define NX_HASH_SIZE 13
20089 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20091 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20094 +static inline unsigned int __hashval(nid_t nid)
20096 + return (nid % NX_HASH_SIZE);
20101 +/* __hash_nx_info()
20103 + * add the nxi to the global hash table
20104 + * requires the hash_lock to be held */
20106 +static inline void __hash_nx_info(struct nx_info *nxi)
20108 + struct hlist_head *head;
20110 + vxd_assert_lock(&nx_info_hash_lock);
20111 + vxdprintk(VXD_CBIT(nid, 4),
20112 + "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20114 + /* context must not be hashed */
20115 + BUG_ON(nx_info_state(nxi, NXS_HASHED));
20117 + nxi->nx_state |= NXS_HASHED;
20118 + head = &nx_info_hash[__hashval(nxi->nx_id)];
20119 + hlist_add_head(&nxi->nx_hlist, head);
20120 + atomic_inc(&nx_global_cactive);
20123 +/* __unhash_nx_info()
20125 + * remove the nxi from the global hash table
20126 + * requires the hash_lock to be held */
20128 +static inline void __unhash_nx_info(struct nx_info *nxi)
20130 + vxd_assert_lock(&nx_info_hash_lock);
20131 + vxdprintk(VXD_CBIT(nid, 4),
20132 + "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20133 + atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20135 + /* context must be hashed */
20136 + BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20137 + /* but without tasks */
20138 + BUG_ON(atomic_read(&nxi->nx_tasks));
20140 + nxi->nx_state &= ~NXS_HASHED;
20141 + hlist_del(&nxi->nx_hlist);
20142 + atomic_dec(&nx_global_cactive);
20146 +/* __lookup_nx_info()
20148 + * requires the hash_lock to be held
20149 + * doesn't increment the nx_refcnt */
20151 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20153 + struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20154 + struct hlist_node *pos;
20155 + struct nx_info *nxi;
20157 + vxd_assert_lock(&nx_info_hash_lock);
20158 + hlist_for_each(pos, head) {
20159 + nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20161 + if (nxi->nx_id == nid)
20166 + vxdprintk(VXD_CBIT(nid, 0),
20167 + "__lookup_nx_info(#%u): %p[#%u]",
20168 + nid, nxi, nxi ? nxi->nx_id : 0);
20173 +/* __create_nx_info()
20175 + * create the requested context
20176 + * get(), claim() and hash it */
20178 +static struct nx_info *__create_nx_info(int id)
20180 + struct nx_info *new, *nxi = NULL;
20182 + vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20184 + if (!(new = __alloc_nx_info(id)))
20185 + return ERR_PTR(-ENOMEM);
20187 + /* required to make dynamic xids unique */
20188 + spin_lock(&nx_info_hash_lock);
20190 + /* static context requested */
20191 + if ((nxi = __lookup_nx_info(id))) {
20192 + vxdprintk(VXD_CBIT(nid, 0),
20193 + "create_nx_info(%d) = %p (already there)", id, nxi);
20194 + if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20195 + nxi = ERR_PTR(-EBUSY);
20197 + nxi = ERR_PTR(-EEXIST);
20200 + /* new context */
20201 + vxdprintk(VXD_CBIT(nid, 0),
20202 + "create_nx_info(%d) = %p (new)", id, new);
20203 + claim_nx_info(new, NULL);
20204 + __nx_set_lback(new);
20205 + __hash_nx_info(get_nx_info(new));
20206 + nxi = new, new = NULL;
20209 + spin_unlock(&nx_info_hash_lock);
20211 + __dealloc_nx_info(new);
20217 +/* exported stuff */
20220 +void unhash_nx_info(struct nx_info *nxi)
20222 + __shutdown_nx_info(nxi);
20223 + spin_lock(&nx_info_hash_lock);
20224 + __unhash_nx_info(nxi);
20225 + spin_unlock(&nx_info_hash_lock);
20228 +/* lookup_nx_info()
20230 + * search for a nx_info and get() it
20231 + * negative id means current */
20233 +struct nx_info *lookup_nx_info(int id)
20235 + struct nx_info *nxi = NULL;
20238 + nxi = get_nx_info(current_nx_info());
20239 + } else if (id > 1) {
20240 + spin_lock(&nx_info_hash_lock);
20241 + nxi = get_nx_info(__lookup_nx_info(id));
20242 + spin_unlock(&nx_info_hash_lock);
20247 +/* nid_is_hashed()
20249 + * verify that nid is still hashed */
20251 +int nid_is_hashed(nid_t nid)
20255 + spin_lock(&nx_info_hash_lock);
20256 + hashed = (__lookup_nx_info(nid) != NULL);
20257 + spin_unlock(&nx_info_hash_lock);
20262 +#ifdef CONFIG_PROC_FS
20266 + * get a subset of hashed nids for proc
20267 + * assumes size is at least one */
20269 +int get_nid_list(int index, unsigned int *nids, int size)
20271 + int hindex, nr_nids = 0;
20273 + /* only show current and children */
20274 + if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20277 + nids[nr_nids] = nx_current_nid();
20281 + for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20282 + struct hlist_head *head = &nx_info_hash[hindex];
20283 + struct hlist_node *pos;
20285 + spin_lock(&nx_info_hash_lock);
20286 + hlist_for_each(pos, head) {
20287 + struct nx_info *nxi;
20292 + nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20293 + nids[nr_nids] = nxi->nx_id;
20294 + if (++nr_nids >= size) {
20295 + spin_unlock(&nx_info_hash_lock);
20299 + /* keep the lock time short */
20300 + spin_unlock(&nx_info_hash_lock);
20309 + * migrate task to new network
20310 + * gets nxi, puts old_nxi on change
20313 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20315 + struct nx_info *old_nxi;
20321 + vxdprintk(VXD_CBIT(nid, 5),
20322 + "nx_migrate_task(%p,%p[#%d.%d.%d])",
20323 + p, nxi, nxi->nx_id,
20324 + atomic_read(&nxi->nx_usecnt),
20325 + atomic_read(&nxi->nx_tasks));
20327 + if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20328 + !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20331 + if (nx_info_state(nxi, NXS_SHUTDOWN))
20334 + /* maybe disallow this completely? */
20335 + old_nxi = task_get_nx_info(p);
20336 + if (old_nxi == nxi)
20341 + clr_nx_info(&p->nx_info);
20342 + claim_nx_info(nxi, p);
20343 + set_nx_info(&p->nx_info, nxi);
20344 + p->nid = nxi->nx_id;
20347 + vxdprintk(VXD_CBIT(nid, 5),
20348 + "moved task %p into nxi:%p[#%d]",
20349 + p, nxi, nxi->nx_id);
20352 + release_nx_info(old_nxi, p);
20355 + put_nx_info(old_nxi);
20360 +void nx_set_persistent(struct nx_info *nxi)
20362 + vxdprintk(VXD_CBIT(nid, 6),
20363 + "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20365 + get_nx_info(nxi);
20366 + claim_nx_info(nxi, NULL);
20369 +void nx_clear_persistent(struct nx_info *nxi)
20371 + vxdprintk(VXD_CBIT(nid, 6),
20372 + "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20374 + release_nx_info(nxi, NULL);
20375 + put_nx_info(nxi);
20378 +void nx_update_persistent(struct nx_info *nxi)
20380 + if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20381 + nx_set_persistent(nxi);
20383 + nx_clear_persistent(nxi);
20386 +/* vserver syscall commands below here */
20388 +/* taks nid and nx_info functions */
20390 +#include <asm/uaccess.h>
20393 +int vc_task_nid(uint32_t id)
20398 + struct task_struct *tsk;
20401 + tsk = find_task_by_real_pid(id);
20402 + nid = (tsk) ? tsk->nid : -ESRCH;
20403 + rcu_read_unlock();
20405 + nid = nx_current_nid();
20410 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20412 + struct vcmd_nx_info_v0 vc_data;
20414 + vc_data.nid = nxi->nx_id;
20416 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20422 +/* network functions */
20424 +int vc_net_create(uint32_t nid, void __user *data)
20426 + struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20427 + struct nx_info *new_nxi;
20430 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20433 + if ((nid > MAX_S_CONTEXT) || (nid < 2))
20436 + new_nxi = __create_nx_info(nid);
20437 + if (IS_ERR(new_nxi))
20438 + return PTR_ERR(new_nxi);
20440 + /* initial flags */
20441 + new_nxi->nx_flags = vc_data.flagword;
20444 + if (vs_net_change(new_nxi, VSC_NETUP))
20447 + ret = nx_migrate_task(current, new_nxi);
20451 + /* return context id on success */
20452 + ret = new_nxi->nx_id;
20454 + /* get a reference for persistent contexts */
20455 + if ((vc_data.flagword & NXF_PERSISTENT))
20456 + nx_set_persistent(new_nxi);
20458 + release_nx_info(new_nxi, NULL);
20459 + put_nx_info(new_nxi);
20464 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20466 + return nx_migrate_task(current, nxi);
20471 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
20472 + __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
20473 + struct nx_addr_v4 **prev)
20475 + struct nx_addr_v4 *nxa = &nxi->v4;
20477 + for (; nxa; nxa = nxa->next) {
20478 + if ((nxa->ip[0].s_addr == ip) &&
20479 + (nxa->ip[1].s_addr == ip2) &&
20480 + (nxa->mask.s_addr == mask) &&
20481 + (nxa->type == type) &&
20482 + (nxa->flags == flags))
20485 + /* save previous entry */
20492 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20493 + uint16_t type, uint16_t flags)
20495 + struct nx_addr_v4 *nxa = NULL;
20496 + struct nx_addr_v4 *new = __alloc_nx_addr_v4();
20497 + unsigned long irqflags;
20498 + int ret = -EEXIST;
20501 + return PTR_ERR(new);
20503 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20504 + if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
20507 + if (NX_IPV4(nxi)) {
20512 + /* remove single ip for ip list */
20513 + nxi->nx_flags &= ~NXF_SINGLE_IP;
20516 + nxa->ip[0].s_addr = ip;
20517 + nxa->ip[1].s_addr = ip2;
20518 + nxa->mask.s_addr = mask;
20519 + nxa->type = type;
20520 + nxa->flags = flags;
20523 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20525 + __dealloc_nx_addr_v4(new);
20529 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20530 + uint16_t type, uint16_t flags)
20532 + struct nx_addr_v4 *nxa = NULL;
20533 + struct nx_addr_v4 *old = NULL;
20534 + unsigned long irqflags;
20537 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20539 + case NXA_TYPE_ADDR:
20540 + old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
20543 + nxa->next = old->next;
20544 + old->next = NULL;
20550 + old->next = NULL;
20552 + memset(old, 0, sizeof(*old));
20560 + case NXA_TYPE_ANY:
20563 + memset(nxa, 0, sizeof(*nxa));
20569 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20570 + __dealloc_nx_addr_v4_all(old);
20575 +int vc_net_add(struct nx_info *nxi, void __user *data)
20577 + struct vcmd_net_addr_v0 vc_data;
20578 + int index, ret = 0;
20580 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20583 + switch (vc_data.type) {
20584 + case NXA_TYPE_IPV4:
20585 + if ((vc_data.count < 1) || (vc_data.count > 4))
20589 + while (index < vc_data.count) {
20590 + ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20591 + vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20599 + case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20600 + nxi->v4_bcast = vc_data.ip[0];
20604 + case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20605 + nxi->v4_lback = vc_data.ip[0];
20616 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20618 + struct vcmd_net_addr_v0 vc_data;
20620 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20623 + switch (vc_data.type) {
20624 + case NXA_TYPE_ANY:
20625 + return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
20633 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20635 + struct vcmd_net_addr_ipv4_v1 vc_data;
20637 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20640 + switch (vc_data.type) {
20641 + case NXA_TYPE_ADDR:
20642 + case NXA_TYPE_MASK:
20643 + return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20644 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20646 + case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20647 + nxi->v4_bcast = vc_data.ip;
20650 + case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20651 + nxi->v4_lback = vc_data.ip;
20660 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20662 + struct vcmd_net_addr_ipv4_v2 vc_data;
20664 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20667 + switch (vc_data.type) {
20668 + case NXA_TYPE_ADDR:
20669 + case NXA_TYPE_MASK:
20670 + case NXA_TYPE_RANGE:
20671 + return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20672 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20674 + case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20675 + nxi->v4_bcast = vc_data.ip;
20678 + case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20679 + nxi->v4_lback = vc_data.ip;
20688 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20690 + struct vcmd_net_addr_ipv4_v1 vc_data;
20692 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20695 + return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20696 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20699 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20701 + struct vcmd_net_addr_ipv4_v2 vc_data;
20703 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20706 + return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20707 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20710 +#ifdef CONFIG_IPV6
20713 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20714 + struct in6_addr *ip, struct in6_addr *mask,
20715 + uint32_t prefix, uint16_t type, uint16_t flags,
20716 + struct nx_addr_v6 **prev)
20718 + struct nx_addr_v6 *nxa = &nxi->v6;
20720 + for (; nxa; nxa = nxa->next) {
20721 + if (ipv6_addr_equal(&nxa->ip, ip) &&
20722 + ipv6_addr_equal(&nxa->mask, mask) &&
20723 + (nxa->prefix == prefix) &&
20724 + (nxa->type == type) &&
20725 + (nxa->flags == flags))
20728 + /* save previous entry */
20736 +int do_add_v6_addr(struct nx_info *nxi,
20737 + struct in6_addr *ip, struct in6_addr *mask,
20738 + uint32_t prefix, uint16_t type, uint16_t flags)
20740 + struct nx_addr_v6 *nxa = NULL;
20741 + struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20742 + unsigned long irqflags;
20743 + int ret = -EEXIST;
20746 + return PTR_ERR(new);
20748 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20749 + if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20752 + if (NX_IPV6(nxi)) {
20759 + nxa->mask = *mask;
20760 + nxa->prefix = prefix;
20761 + nxa->type = type;
20762 + nxa->flags = flags;
20765 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20767 + __dealloc_nx_addr_v6(new);
20771 +int do_remove_v6_addr(struct nx_info *nxi,
20772 + struct in6_addr *ip, struct in6_addr *mask,
20773 + uint32_t prefix, uint16_t type, uint16_t flags)
20775 + struct nx_addr_v6 *nxa = NULL;
20776 + struct nx_addr_v6 *old = NULL;
20777 + unsigned long irqflags;
20780 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20782 + case NXA_TYPE_ADDR:
20783 + old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20786 + nxa->next = old->next;
20787 + old->next = NULL;
20793 + old->next = NULL;
20795 + memset(old, 0, sizeof(*old));
20803 + case NXA_TYPE_ANY:
20806 + memset(nxa, 0, sizeof(*nxa));
20812 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20813 + __dealloc_nx_addr_v6_all(old);
20817 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20819 + struct vcmd_net_addr_ipv6_v1 vc_data;
20821 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20824 + switch (vc_data.type) {
20825 + case NXA_TYPE_ADDR:
20826 + memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20827 + /* fallthrough */
20828 + case NXA_TYPE_MASK:
20829 + return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20830 + vc_data.prefix, vc_data.type, vc_data.flags);
20837 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20839 + struct vcmd_net_addr_ipv6_v1 vc_data;
20841 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20844 + switch (vc_data.type) {
20845 + case NXA_TYPE_ADDR:
20846 + memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20847 + /* fallthrough */
20848 + case NXA_TYPE_MASK:
20849 + return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20850 + vc_data.prefix, vc_data.type, vc_data.flags);
20851 + case NXA_TYPE_ANY:
20852 + return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20859 +#endif /* CONFIG_IPV6 */
20862 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20864 + struct vcmd_net_flags_v0 vc_data;
20866 + vc_data.flagword = nxi->nx_flags;
20868 + /* special STATE flag handling */
20869 + vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20871 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20876 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20878 + struct vcmd_net_flags_v0 vc_data;
20879 + uint64_t mask, trigger;
20881 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20884 + /* special STATE flag handling */
20885 + mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20886 + trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20888 + nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20889 + vc_data.flagword, mask);
20890 + if (trigger & NXF_PERSISTENT)
20891 + nx_update_persistent(nxi);
20896 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20898 + struct vcmd_net_caps_v0 vc_data;
20900 + vc_data.ncaps = nxi->nx_ncaps;
20901 + vc_data.cmask = ~0ULL;
20903 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20908 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20910 + struct vcmd_net_caps_v0 vc_data;
20912 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20915 + nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20916 + vc_data.ncaps, vc_data.cmask);
20921 +#include <linux/module.h>
20923 +module_init(init_network);
20925 +EXPORT_SYMBOL_GPL(free_nx_info);
20926 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20928 diff -NurpP --minimal linux-3.9.4/kernel/vserver/proc.c linux-3.9.4-vs2.3.6.2/kernel/vserver/proc.c
20929 --- linux-3.9.4/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
20930 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/proc.c 2013-06-01 08:30:38.000000000 +0000
20933 + * linux/kernel/vserver/proc.c
20935 + * Virtual Context Support
20937 + * Copyright (C) 2003-2011 Herbert Pötzl
20939 + * V0.01 basic structure
20940 + * V0.02 adaptation vs1.3.0
20941 + * V0.03 proc permissions
20942 + * V0.04 locking/generic
20943 + * V0.05 next generation procfs
20944 + * V0.06 inode validation
20945 + * V0.07 generic rewrite vid
20946 + * V0.08 remove inode type
20947 + * V0.09 added u/wmask info
20951 +#include <linux/proc_fs.h>
20952 +#include <linux/fs_struct.h>
20953 +#include <linux/mount.h>
20954 +#include <linux/namei.h>
20955 +#include <asm/unistd.h>
20957 +#include <linux/vs_context.h>
20958 +#include <linux/vs_network.h>
20959 +#include <linux/vs_cvirt.h>
20961 +#include <linux/in.h>
20962 +#include <linux/inetdevice.h>
20963 +#include <linux/vs_inet.h>
20964 +#include <linux/vs_inet6.h>
20966 +#include <linux/vserver/global.h>
20968 +#include "cvirt_proc.h"
20969 +#include "cacct_proc.h"
20970 +#include "limit_proc.h"
20971 +#include "sched_proc.h"
20972 +#include "vci_config.h"
20975 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20979 + CAP_FOR_EACH_U32(__capi) {
20980 + buffer += sprintf(buffer, "%08x",
20981 + c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20987 +static struct proc_dir_entry *proc_virtual;
20989 +static struct proc_dir_entry *proc_virtnet;
20992 +/* first the actual feeds */
20995 +static int proc_vci(char *buffer)
20997 + return sprintf(buffer,
20998 + "VCIVersion:\t%04x:%04x\n"
20999 + "VCISyscall:\t%d\n"
21000 + "VCIKernel:\t%08x\n",
21001 + VCI_VERSION >> 16,
21002 + VCI_VERSION & 0xFFFF,
21004 + vci_kernel_config());
21007 +static int proc_virtual_info(char *buffer)
21009 + return proc_vci(buffer);
21012 +static int proc_virtual_status(char *buffer)
21014 + return sprintf(buffer,
21016 + "#CActive:\t%d\n"
21017 + "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21018 + "#InitTask:\t%d\t%d %d\n",
21019 + atomic_read(&vx_global_ctotal),
21020 + atomic_read(&vx_global_cactive),
21021 + atomic_read(&vs_global_nsproxy),
21022 + atomic_read(&vs_global_fs),
21023 + atomic_read(&vs_global_mnt_ns),
21024 + atomic_read(&vs_global_uts_ns),
21025 + atomic_read(&nr_ipc_ns),
21026 + atomic_read(&vs_global_user_ns),
21027 + atomic_read(&vs_global_pid_ns),
21028 + atomic_read(&init_task.usage),
21029 + atomic_read(&init_task.nsproxy->count),
21030 + init_task.fs->users);
21034 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21038 + length = sprintf(buffer,
21046 + vxi->vx_badness_bias);
21050 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21052 + char *orig = buffer;
21054 + buffer += sprintf(buffer,
21057 + "Flags:\t%016llx\n",
21058 + atomic_read(&vxi->vx_usecnt),
21059 + atomic_read(&vxi->vx_tasks),
21060 + (unsigned long long)vxi->vx_flags);
21062 + buffer += sprintf(buffer, "BCaps:\t");
21063 + buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21064 + buffer += sprintf(buffer, "\n");
21066 + buffer += sprintf(buffer,
21067 + "CCaps:\t%016llx\n"
21068 + "Umask:\t%16llx\n"
21069 + "Wmask:\t%16llx\n"
21070 + "Spaces:\t%08lx %08lx\n",
21071 + (unsigned long long)vxi->vx_ccaps,
21072 + (unsigned long long)vxi->vx_umask,
21073 + (unsigned long long)vxi->vx_wmask,
21074 + vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21075 + return buffer - orig;
21078 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21080 + return vx_info_proc_limit(&vxi->limit, buffer);
21083 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21087 + length = vx_info_proc_sched(&vxi->sched, buffer);
21088 + for_each_online_cpu(cpu) {
21089 + length += vx_info_proc_sched_pc(
21090 + &vx_per_cpu(vxi, sched_pc, cpu),
21091 + buffer + length, cpu);
21096 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21098 + return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21101 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21103 + return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21106 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21110 + vx_update_load(vxi);
21111 + length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21112 + for_each_online_cpu(cpu) {
21113 + length += vx_info_proc_cvirt_pc(
21114 + &vx_per_cpu(vxi, cvirt_pc, cpu),
21115 + buffer + length, cpu);
21120 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21122 + return vx_info_proc_cacct(&vxi->cacct, buffer);
21126 +static int proc_virtnet_info(char *buffer)
21128 + return proc_vci(buffer);
21131 +static int proc_virtnet_status(char *buffer)
21133 + return sprintf(buffer,
21135 + "#CActive:\t%d\n",
21136 + atomic_read(&nx_global_ctotal),
21137 + atomic_read(&nx_global_cactive));
21140 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21142 + struct nx_addr_v4 *v4a;
21143 +#ifdef CONFIG_IPV6
21144 + struct nx_addr_v6 *v6a;
21148 + length = sprintf(buffer,
21151 + "Bcast:\t" NIPQUAD_FMT "\n"
21152 + "Lback:\t" NIPQUAD_FMT "\n",
21155 + NIPQUAD(nxi->v4_bcast.s_addr),
21156 + NIPQUAD(nxi->v4_lback.s_addr));
21158 + if (!NX_IPV4(nxi))
21160 + for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21161 + length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21164 +#ifdef CONFIG_IPV6
21165 + if (!NX_IPV6(nxi))
21167 + for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21168 + length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21175 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21179 + length = sprintf(buffer,
21182 + "Flags:\t%016llx\n"
21183 + "NCaps:\t%016llx\n",
21184 + atomic_read(&nxi->nx_usecnt),
21185 + atomic_read(&nxi->nx_tasks),
21186 + (unsigned long long)nxi->nx_flags,
21187 + (unsigned long long)nxi->nx_ncaps);
21193 +/* here the inode helpers */
21199 + struct inode_operations *iop;
21200 + struct file_operations *fop;
21201 + union proc_op op;
21204 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21206 + struct inode *inode = new_inode(sb);
21211 + inode->i_mode = p->mode;
21213 + inode->i_op = p->iop;
21215 + inode->i_fop = p->fop;
21217 + set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21218 + inode->i_flags |= S_IMMUTABLE;
21220 + inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21222 + i_uid_write(inode, 0);
21223 + i_gid_write(inode, 0);
21224 + i_tag_write(inode, 0);
21229 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21230 + struct dentry *dentry, int id, void *ptr)
21232 + struct vs_entry *p = ptr;
21233 + struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21234 + struct dentry *error = ERR_PTR(-EINVAL);
21239 + PROC_I(inode)->op = p->op;
21240 + PROC_I(inode)->fd = id;
21241 + d_add(dentry, inode);
21249 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21252 + * Fill a directory entry.
21254 + * If possible create the dcache entry and derive our inode number and
21255 + * file type from dcache entry.
21257 + * Since all of the proc inode numbers are dynamically generated, the inode
21258 + * numbers do not exist until the inode is cache. This means creating the
21259 + * the dcache entry in readdir is necessary to keep the inode numbers
21260 + * reported by readdir in sync with the inode numbers reported
21263 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21264 + char *name, int len, instantiate_t instantiate, int id, void *ptr)
21266 + struct dentry *child, *dir = filp->f_dentry;
21267 + struct inode *inode;
21268 + struct qstr qname;
21270 + unsigned type = DT_UNKNOWN;
21272 + qname.name = name;
21274 + qname.hash = full_name_hash(name, len);
21276 + child = d_lookup(dir, &qname);
21278 + struct dentry *new;
21279 + new = d_alloc(dir, &qname);
21281 + child = instantiate(dir->d_inode, new, id, ptr);
21288 + if (!child || IS_ERR(child) || !child->d_inode)
21289 + goto end_instantiate;
21290 + inode = child->d_inode;
21292 + ino = inode->i_ino;
21293 + type = inode->i_mode >> 12;
21298 + ino = find_inode_number(dir, &qname);
21301 + return filldir(dirent, name, len, filp->f_pos, ino, type);
21306 +/* get and revalidate vx_info/xid */
21309 +struct vx_info *get_proc_vx_info(struct inode *inode)
21311 + return lookup_vx_info(PROC_I(inode)->fd);
21314 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21316 + struct inode *inode = dentry->d_inode;
21317 + xid_t xid = PROC_I(inode)->fd;
21319 + if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21322 + if (!xid || xid_is_hashed(xid))
21329 +/* get and revalidate nx_info/nid */
21331 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21333 + struct inode *inode = dentry->d_inode;
21334 + nid_t nid = PROC_I(inode)->fd;
21336 + if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21339 + if (!nid || nid_is_hashed(nid))
21347 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21349 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21350 + size_t count, loff_t *ppos)
21352 + struct inode *inode = file->f_dentry->d_inode;
21353 + unsigned long page;
21354 + ssize_t length = 0;
21356 + if (count > PROC_BLOCK_SIZE)
21357 + count = PROC_BLOCK_SIZE;
21359 + /* fade that out as soon as stable */
21360 + WARN_ON(PROC_I(inode)->fd);
21362 + if (!(page = __get_free_page(GFP_KERNEL)))
21365 + BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21366 + length = PROC_I(inode)->op.proc_vs_read((char *)page);
21369 + length = simple_read_from_buffer(buf, count, ppos,
21370 + (char *)page, length);
21376 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21377 + size_t count, loff_t *ppos)
21379 + struct inode *inode = file->f_dentry->d_inode;
21380 + struct vx_info *vxi = NULL;
21381 + xid_t xid = PROC_I(inode)->fd;
21382 + unsigned long page;
21383 + ssize_t length = 0;
21385 + if (count > PROC_BLOCK_SIZE)
21386 + count = PROC_BLOCK_SIZE;
21388 + /* fade that out as soon as stable */
21390 + vxi = lookup_vx_info(xid);
21394 + length = -ENOMEM;
21395 + if (!(page = __get_free_page(GFP_KERNEL)))
21398 + BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21399 + length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21402 + length = simple_read_from_buffer(buf, count, ppos,
21403 + (char *)page, length);
21407 + put_vx_info(vxi);
21412 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21413 + size_t count, loff_t *ppos)
21415 + struct inode *inode = file->f_dentry->d_inode;
21416 + struct nx_info *nxi = NULL;
21417 + nid_t nid = PROC_I(inode)->fd;
21418 + unsigned long page;
21419 + ssize_t length = 0;
21421 + if (count > PROC_BLOCK_SIZE)
21422 + count = PROC_BLOCK_SIZE;
21424 + /* fade that out as soon as stable */
21426 + nxi = lookup_nx_info(nid);
21430 + length = -ENOMEM;
21431 + if (!(page = __get_free_page(GFP_KERNEL)))
21434 + BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21435 + length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21438 + length = simple_read_from_buffer(buf, count, ppos,
21439 + (char *)page, length);
21443 + put_nx_info(nxi);
21450 +/* here comes the lower level */
21453 +#define NOD(NAME, MODE, IOP, FOP, OP) { \
21454 + .len = sizeof(NAME) - 1, \
21455 + .name = (NAME), \
21463 +#define DIR(NAME, MODE, OTYPE) \
21464 + NOD(NAME, (S_IFDIR | (MODE)), \
21465 + &proc_ ## OTYPE ## _inode_operations, \
21466 + &proc_ ## OTYPE ## _file_operations, { } )
21468 +#define INF(NAME, MODE, OTYPE) \
21469 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
21470 + &proc_vs_info_file_operations, \
21471 + { .proc_vs_read = &proc_##OTYPE } )
21473 +#define VINF(NAME, MODE, OTYPE) \
21474 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
21475 + &proc_vx_info_file_operations, \
21476 + { .proc_vxi_read = &proc_##OTYPE } )
21478 +#define NINF(NAME, MODE, OTYPE) \
21479 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
21480 + &proc_nx_info_file_operations, \
21481 + { .proc_nxi_read = &proc_##OTYPE } )
21484 +static struct file_operations proc_vs_info_file_operations = {
21485 + .read = proc_vs_info_read,
21488 +static struct file_operations proc_vx_info_file_operations = {
21489 + .read = proc_vx_info_read,
21492 +static struct dentry_operations proc_xid_dentry_operations = {
21493 + .d_revalidate = proc_xid_revalidate,
21496 +static struct vs_entry vx_base_stuff[] = {
21497 + VINF("info", S_IRUGO, vxi_info),
21498 + VINF("status", S_IRUGO, vxi_status),
21499 + VINF("limit", S_IRUGO, vxi_limit),
21500 + VINF("sched", S_IRUGO, vxi_sched),
21501 + VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21502 + VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21503 + VINF("cvirt", S_IRUGO, vxi_cvirt),
21504 + VINF("cacct", S_IRUGO, vxi_cacct),
21511 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21512 + struct dentry *dentry, int id, void *ptr)
21514 + dentry->d_op = &proc_xid_dentry_operations;
21515 + return vs_proc_instantiate(dir, dentry, id, ptr);
21518 +static struct dentry *proc_xid_lookup(struct inode *dir,
21519 + struct dentry *dentry, unsigned int flags)
21521 + struct vs_entry *p = vx_base_stuff;
21522 + struct dentry *error = ERR_PTR(-ENOENT);
21524 + for (; p->name; p++) {
21525 + if (p->len != dentry->d_name.len)
21527 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21533 + error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21538 +static int proc_xid_readdir(struct file *filp,
21539 + void *dirent, filldir_t filldir)
21541 + struct dentry *dentry = filp->f_dentry;
21542 + struct inode *inode = dentry->d_inode;
21543 + struct vs_entry *p = vx_base_stuff;
21544 + int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21548 + pos = filp->f_pos;
21551 + ino = inode->i_ino;
21552 + if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21555 + /* fall through */
21557 + ino = parent_ino(dentry);
21558 + if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21561 + /* fall through */
21564 + if (index >= size)
21566 + for (p += index; p->name; p++) {
21567 + if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21568 + vs_proc_instantiate, PROC_I(inode)->fd, p))
21574 + filp->f_pos = pos;
21580 +static struct file_operations proc_nx_info_file_operations = {
21581 + .read = proc_nx_info_read,
21584 +static struct dentry_operations proc_nid_dentry_operations = {
21585 + .d_revalidate = proc_nid_revalidate,
21588 +static struct vs_entry nx_base_stuff[] = {
21589 + NINF("info", S_IRUGO, nxi_info),
21590 + NINF("status", S_IRUGO, nxi_status),
21595 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21596 + struct dentry *dentry, int id, void *ptr)
21598 + dentry->d_op = &proc_nid_dentry_operations;
21599 + return vs_proc_instantiate(dir, dentry, id, ptr);
21602 +static struct dentry *proc_nid_lookup(struct inode *dir,
21603 + struct dentry *dentry, unsigned int flags)
21605 + struct vs_entry *p = nx_base_stuff;
21606 + struct dentry *error = ERR_PTR(-ENOENT);
21608 + for (; p->name; p++) {
21609 + if (p->len != dentry->d_name.len)
21611 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21617 + error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21622 +static int proc_nid_readdir(struct file *filp,
21623 + void *dirent, filldir_t filldir)
21625 + struct dentry *dentry = filp->f_dentry;
21626 + struct inode *inode = dentry->d_inode;
21627 + struct vs_entry *p = nx_base_stuff;
21628 + int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21632 + pos = filp->f_pos;
21635 + ino = inode->i_ino;
21636 + if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21639 + /* fall through */
21641 + ino = parent_ino(dentry);
21642 + if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21645 + /* fall through */
21648 + if (index >= size)
21650 + for (p += index; p->name; p++) {
21651 + if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21652 + vs_proc_instantiate, PROC_I(inode)->fd, p))
21658 + filp->f_pos = pos;
21663 +#define MAX_MULBY10 ((~0U - 9) / 10)
21665 +static inline int atovid(const char *str, int len)
21670 + while (len-- > 0) {
21675 + if (vid >= MAX_MULBY10)
21685 +/* now the upper level (virtual) */
21688 +static struct file_operations proc_xid_file_operations = {
21689 + .read = generic_read_dir,
21690 + .readdir = proc_xid_readdir,
21693 +static struct inode_operations proc_xid_inode_operations = {
21694 + .lookup = proc_xid_lookup,
21697 +static struct vs_entry vx_virtual_stuff[] = {
21698 + INF("info", S_IRUGO, virtual_info),
21699 + INF("status", S_IRUGO, virtual_status),
21700 + DIR(NULL, S_IRUGO | S_IXUGO, xid),
21704 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21705 + struct dentry *dentry, unsigned int flags)
21707 + struct vs_entry *p = vx_virtual_stuff;
21708 + struct dentry *error = ERR_PTR(-ENOENT);
21711 + for (; p->name; p++) {
21712 + if (p->len != dentry->d_name.len)
21714 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21718 + goto instantiate;
21720 + id = atovid(dentry->d_name.name, dentry->d_name.len);
21721 + if ((id < 0) || !xid_is_hashed(id))
21725 + error = proc_xid_instantiate(dir, dentry, id, p);
21730 +static struct file_operations proc_nid_file_operations = {
21731 + .read = generic_read_dir,
21732 + .readdir = proc_nid_readdir,
21735 +static struct inode_operations proc_nid_inode_operations = {
21736 + .lookup = proc_nid_lookup,
21739 +static struct vs_entry nx_virtnet_stuff[] = {
21740 + INF("info", S_IRUGO, virtnet_info),
21741 + INF("status", S_IRUGO, virtnet_status),
21742 + DIR(NULL, S_IRUGO | S_IXUGO, nid),
21746 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21747 + struct dentry *dentry, unsigned int flags)
21749 + struct vs_entry *p = nx_virtnet_stuff;
21750 + struct dentry *error = ERR_PTR(-ENOENT);
21753 + for (; p->name; p++) {
21754 + if (p->len != dentry->d_name.len)
21756 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21760 + goto instantiate;
21762 + id = atovid(dentry->d_name.name, dentry->d_name.len);
21763 + if ((id < 0) || !nid_is_hashed(id))
21767 + error = proc_nid_instantiate(dir, dentry, id, p);
21773 +#define PROC_MAXVIDS 32
21775 +int proc_virtual_readdir(struct file *filp,
21776 + void *dirent, filldir_t filldir)
21778 + struct dentry *dentry = filp->f_dentry;
21779 + struct inode *inode = dentry->d_inode;
21780 + struct vs_entry *p = vx_virtual_stuff;
21781 + int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21783 + unsigned int xid_array[PROC_MAXVIDS];
21784 + char buf[PROC_NUMBUF];
21785 + unsigned int nr_xids, i;
21788 + pos = filp->f_pos;
21791 + ino = inode->i_ino;
21792 + if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21795 + /* fall through */
21797 + ino = parent_ino(dentry);
21798 + if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21801 + /* fall through */
21804 + if (index >= size)
21806 + for (p += index; p->name; p++) {
21807 + if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21808 + vs_proc_instantiate, 0, p))
21813 + index = pos - size;
21814 + p = &vx_virtual_stuff[size - 1];
21815 + nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21816 + for (i = 0; i < nr_xids; i++) {
21817 + int n, xid = xid_array[i];
21818 + unsigned int j = PROC_NUMBUF;
21822 + buf[--j] = '0' + (n % 10);
21825 + if (proc_fill_cache(filp, dirent, filldir,
21826 + buf + j, PROC_NUMBUF - j,
21827 + vs_proc_instantiate, xid, p))
21833 + filp->f_pos = pos;
21837 +static int proc_virtual_getattr(struct vfsmount *mnt,
21838 + struct dentry *dentry, struct kstat *stat)
21840 + struct inode *inode = dentry->d_inode;
21842 + generic_fillattr(inode, stat);
21843 + stat->nlink = 2 + atomic_read(&vx_global_cactive);
21847 +static struct file_operations proc_virtual_dir_operations = {
21848 + .read = generic_read_dir,
21849 + .readdir = proc_virtual_readdir,
21852 +static struct inode_operations proc_virtual_dir_inode_operations = {
21853 + .getattr = proc_virtual_getattr,
21854 + .lookup = proc_virtual_lookup,
21861 +int proc_virtnet_readdir(struct file *filp,
21862 + void *dirent, filldir_t filldir)
21864 + struct dentry *dentry = filp->f_dentry;
21865 + struct inode *inode = dentry->d_inode;
21866 + struct vs_entry *p = nx_virtnet_stuff;
21867 + int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21869 + unsigned int nid_array[PROC_MAXVIDS];
21870 + char buf[PROC_NUMBUF];
21871 + unsigned int nr_nids, i;
21874 + pos = filp->f_pos;
21877 + ino = inode->i_ino;
21878 + if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21881 + /* fall through */
21883 + ino = parent_ino(dentry);
21884 + if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21887 + /* fall through */
21890 + if (index >= size)
21892 + for (p += index; p->name; p++) {
21893 + if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21894 + vs_proc_instantiate, 0, p))
21899 + index = pos - size;
21900 + p = &nx_virtnet_stuff[size - 1];
21901 + nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21902 + for (i = 0; i < nr_nids; i++) {
21903 + int n, nid = nid_array[i];
21904 + unsigned int j = PROC_NUMBUF;
21908 + buf[--j] = '0' + (n % 10);
21911 + if (proc_fill_cache(filp, dirent, filldir,
21912 + buf + j, PROC_NUMBUF - j,
21913 + vs_proc_instantiate, nid, p))
21919 + filp->f_pos = pos;
21923 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21924 + struct dentry *dentry, struct kstat *stat)
21926 + struct inode *inode = dentry->d_inode;
21928 + generic_fillattr(inode, stat);
21929 + stat->nlink = 2 + atomic_read(&nx_global_cactive);
21933 +static struct file_operations proc_virtnet_dir_operations = {
21934 + .read = generic_read_dir,
21935 + .readdir = proc_virtnet_readdir,
21938 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21939 + .getattr = proc_virtnet_getattr,
21940 + .lookup = proc_virtnet_lookup,
21945 +void proc_vx_init(void)
21947 + struct proc_dir_entry *ent;
21949 + ent = proc_mkdir("virtual", 0);
21951 + ent->proc_fops = &proc_virtual_dir_operations;
21952 + ent->proc_iops = &proc_virtual_dir_inode_operations;
21954 + proc_virtual = ent;
21956 + ent = proc_mkdir("virtnet", 0);
21958 + ent->proc_fops = &proc_virtnet_dir_operations;
21959 + ent->proc_iops = &proc_virtnet_dir_inode_operations;
21961 + proc_virtnet = ent;
21967 +/* per pid info */
21970 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21972 + struct vx_info *vxi;
21973 + char *orig = buffer;
21975 + buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21977 + vxi = task_get_vx_info(p);
21981 + buffer += sprintf(buffer, "BCaps:\t");
21982 + buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21983 + buffer += sprintf(buffer, "\n");
21984 + buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21985 + (unsigned long long)vxi->vx_ccaps);
21986 + buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21987 + (unsigned long long)vxi->vx_flags);
21988 + buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21990 + put_vx_info(vxi);
21992 + return buffer - orig;
21996 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21998 + struct nx_info *nxi;
21999 + struct nx_addr_v4 *v4a;
22000 +#ifdef CONFIG_IPV6
22001 + struct nx_addr_v6 *v6a;
22003 + char *orig = buffer;
22006 + buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22008 + nxi = task_get_nx_info(p);
22012 + buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22013 + (unsigned long long)nxi->nx_ncaps);
22014 + buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22015 + (unsigned long long)nxi->nx_flags);
22017 + buffer += sprintf(buffer,
22018 + "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22019 + NIPQUAD(nxi->v4_bcast.s_addr));
22020 + buffer += sprintf (buffer,
22021 + "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22022 + NIPQUAD(nxi->v4_lback.s_addr));
22023 + if (!NX_IPV4(nxi))
22025 + for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22026 + buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22029 +#ifdef CONFIG_IPV6
22030 + if (!NX_IPV6(nxi))
22032 + for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22033 + buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22037 + put_nx_info(nxi);
22039 + return buffer - orig;
22042 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched.c linux-3.9.4-vs2.3.6.2/kernel/vserver/sched.c
22043 --- linux-3.9.4/kernel/vserver/sched.c 1970-01-01 00:00:00.000000000 +0000
22044 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sched.c 2013-05-31 14:47:11.000000000 +0000
22047 + * linux/kernel/vserver/sched.c
22049 + * Virtual Server: Scheduler Support
22051 + * Copyright (C) 2004-2010 Herbert Pötzl
22053 + * V0.01 adapted Sam Vilains version to 2.6.3
22054 + * V0.02 removed legacy interface
22055 + * V0.03 changed vcmds to vxi arg
22056 + * V0.04 removed older and legacy interfaces
22057 + * V0.05 removed scheduler code/commands
22061 +#include <linux/vs_context.h>
22062 +#include <linux/vs_sched.h>
22063 +#include <linux/cpumask.h>
22064 +#include <linux/vserver/sched_cmd.h>
22066 +#include <asm/uaccess.h>
22069 +void vx_update_sched_param(struct _vx_sched *sched,
22070 + struct _vx_sched_pc *sched_pc)
22072 + sched_pc->prio_bias = sched->prio_bias;
22075 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22079 + if (data->prio_bias > MAX_PRIO_BIAS)
22080 + data->prio_bias = MAX_PRIO_BIAS;
22081 + if (data->prio_bias < MIN_PRIO_BIAS)
22082 + data->prio_bias = MIN_PRIO_BIAS;
22084 + if (data->cpu_id != ~0) {
22085 + vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22086 + cpumask_and(&vxi->sched.update, &vxi->sched.update,
22087 + cpu_online_mask);
22089 + cpumask_copy(&vxi->sched.update, cpu_online_mask);
22091 + for_each_cpu_mask(cpu, vxi->sched.update)
22092 + vx_update_sched_param(&vxi->sched,
22093 + &vx_per_cpu(vxi, sched_pc, cpu));
22097 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22099 + struct vcmd_prio_bias vc_data;
22101 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22104 + return do_set_prio_bias(vxi, &vc_data);
22107 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22109 + struct vcmd_prio_bias vc_data;
22110 + struct _vx_sched_pc *pcd;
22113 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22116 + cpu = vc_data.cpu_id;
22118 + if (!cpu_possible(cpu))
22121 + pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22122 + vc_data.prio_bias = pcd->prio_bias;
22124 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22129 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched_init.h linux-3.9.4-vs2.3.6.2/kernel/vserver/sched_init.h
22130 --- linux-3.9.4/kernel/vserver/sched_init.h 1970-01-01 00:00:00.000000000 +0000
22131 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sched_init.h 2013-05-31 14:47:11.000000000 +0000
22134 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22136 + /* scheduling; hard code starting values as constants */
22137 + sched->prio_bias = 0;
22141 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22143 + sched_pc->prio_bias = 0;
22145 + sched_pc->user_ticks = 0;
22146 + sched_pc->sys_ticks = 0;
22147 + sched_pc->hold_ticks = 0;
22150 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22156 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22160 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched_proc.h linux-3.9.4-vs2.3.6.2/kernel/vserver/sched_proc.h
22161 --- linux-3.9.4/kernel/vserver/sched_proc.h 1970-01-01 00:00:00.000000000 +0000
22162 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sched_proc.h 2013-05-31 14:47:11.000000000 +0000
22164 +#ifndef _VX_SCHED_PROC_H
22165 +#define _VX_SCHED_PROC_H
22169 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22173 + length += sprintf(buffer,
22174 + "PrioBias:\t%8d\n",
22175 + sched->prio_bias);
22180 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22181 + char *buffer, int cpu)
22185 + length += sprintf(buffer + length,
22186 + "cpu %d: %lld %lld %lld", cpu,
22187 + (unsigned long long)sched_pc->user_ticks,
22188 + (unsigned long long)sched_pc->sys_ticks,
22189 + (unsigned long long)sched_pc->hold_ticks);
22190 + length += sprintf(buffer + length,
22191 + " %d\n", sched_pc->prio_bias);
22195 +#endif /* _VX_SCHED_PROC_H */
22196 diff -NurpP --minimal linux-3.9.4/kernel/vserver/signal.c linux-3.9.4-vs2.3.6.2/kernel/vserver/signal.c
22197 --- linux-3.9.4/kernel/vserver/signal.c 1970-01-01 00:00:00.000000000 +0000
22198 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/signal.c 2013-05-31 14:47:11.000000000 +0000
22201 + * linux/kernel/vserver/signal.c
22203 + * Virtual Server: Signal Support
22205 + * Copyright (C) 2003-2007 Herbert Pötzl
22207 + * V0.01 broken out from vcontext V0.05
22208 + * V0.02 changed vcmds to vxi arg
22209 + * V0.03 adjusted siginfo for kill
22213 +#include <asm/uaccess.h>
22215 +#include <linux/vs_context.h>
22216 +#include <linux/vs_pid.h>
22217 +#include <linux/vserver/signal_cmd.h>
22220 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22222 + int retval, count = 0;
22223 + struct task_struct *p;
22224 + struct siginfo *sip = SEND_SIG_PRIV;
22227 + vxdprintk(VXD_CBIT(misc, 4),
22228 + "vx_info_kill(%p[#%d],%d,%d)*",
22229 + vxi, vxi->vx_id, pid, sig);
22230 + read_lock(&tasklist_lock);
22234 + for_each_process(p) {
22237 + if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22238 + (pid && vxi->vx_initpid == p->pid))
22241 + err = group_send_sig_info(sig, sip, p);
22243 + if (err != -EPERM)
22249 + if (vxi->vx_initpid) {
22250 + pid = vxi->vx_initpid;
22251 + /* for now, only SIGINT to private init ... */
22252 + if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22253 + /* ... as long as there are tasks left */
22254 + (atomic_read(&vxi->vx_tasks) > 1))
22257 + /* fallthrough */
22260 + p = find_task_by_real_pid(pid);
22261 + rcu_read_unlock();
22263 + if (vx_task_xid(p) == vxi->vx_id)
22264 + retval = group_send_sig_info(sig, sip, p);
22268 + read_unlock(&tasklist_lock);
22269 + vxdprintk(VXD_CBIT(misc, 4),
22270 + "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22271 + vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22275 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22277 + struct vcmd_ctx_kill_v0 vc_data;
22279 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22282 + /* special check to allow guest shutdown */
22283 + if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22284 + /* forbid killall pid=0 when init is present */
22285 + (((vc_data.pid < 1) && vxi->vx_initpid) ||
22286 + (vc_data.pid > 1)))
22289 + return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22293 +static int __wait_exit(struct vx_info *vxi)
22295 + DECLARE_WAITQUEUE(wait, current);
22298 + add_wait_queue(&vxi->vx_wait, &wait);
22299 + set_current_state(TASK_INTERRUPTIBLE);
22302 + if (vx_info_state(vxi,
22303 + VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22305 + if (signal_pending(current)) {
22306 + ret = -ERESTARTSYS;
22313 + set_current_state(TASK_RUNNING);
22314 + remove_wait_queue(&vxi->vx_wait, &wait);
22320 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22322 + struct vcmd_wait_exit_v0 vc_data;
22325 + ret = __wait_exit(vxi);
22326 + vc_data.reboot_cmd = vxi->reboot_cmd;
22327 + vc_data.exit_code = vxi->exit_code;
22329 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22334 diff -NurpP --minimal linux-3.9.4/kernel/vserver/space.c linux-3.9.4-vs2.3.6.2/kernel/vserver/space.c
22335 --- linux-3.9.4/kernel/vserver/space.c 1970-01-01 00:00:00.000000000 +0000
22336 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/space.c 2013-05-31 14:47:11.000000000 +0000
22339 + * linux/kernel/vserver/space.c
22341 + * Virtual Server: Context Space Support
22343 + * Copyright (C) 2003-2010 Herbert Pötzl
22345 + * V0.01 broken out from context.c 0.07
22346 + * V0.02 added task locking for namespace
22347 + * V0.03 broken out vx_enter_namespace
22348 + * V0.04 added *space support and commands
22349 + * V0.05 added credential support
22353 +#include <linux/utsname.h>
22354 +#include <linux/nsproxy.h>
22355 +#include <linux/err.h>
22356 +#include <linux/fs_struct.h>
22357 +#include <linux/cred.h>
22358 +#include <asm/uaccess.h>
22360 +#include <linux/vs_context.h>
22361 +#include <linux/vserver/space.h>
22362 +#include <linux/vserver/space_cmd.h>
22364 +atomic_t vs_global_nsproxy = ATOMIC_INIT(0);
22365 +atomic_t vs_global_fs = ATOMIC_INIT(0);
22366 +atomic_t vs_global_mnt_ns = ATOMIC_INIT(0);
22367 +atomic_t vs_global_uts_ns = ATOMIC_INIT(0);
22368 +atomic_t vs_global_user_ns = ATOMIC_INIT(0);
22369 +atomic_t vs_global_pid_ns = ATOMIC_INIT(0);
22372 +/* namespace functions */
22374 +#include <linux/mnt_namespace.h>
22375 +#include <linux/user_namespace.h>
22376 +#include <linux/pid_namespace.h>
22377 +#include <linux/ipc_namespace.h>
22378 +#include <net/net_namespace.h>
22379 +#include "../fs/mount.h"
22382 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22383 + .mask = CLONE_FS |
22385 +#ifdef CONFIG_UTS_NS
22388 +#ifdef CONFIG_IPC_NS
22391 +#ifdef CONFIG_USER_NS
22397 +static const struct vcmd_space_mask_v1 space_mask = {
22398 + .mask = CLONE_FS |
22400 +#ifdef CONFIG_UTS_NS
22403 +#ifdef CONFIG_IPC_NS
22406 +#ifdef CONFIG_USER_NS
22409 +#ifdef CONFIG_PID_NS
22412 +#ifdef CONFIG_NET_NS
22418 +static const struct vcmd_space_mask_v1 default_space_mask = {
22419 + .mask = CLONE_FS |
22421 +#ifdef CONFIG_UTS_NS
22424 +#ifdef CONFIG_IPC_NS
22427 +#ifdef CONFIG_USER_NS
22430 +#ifdef CONFIG_PID_NS
22437 + * build a new nsproxy mix
22438 + * assumes that both proxies are 'const'
22439 + * does not touch nsproxy refcounts
22440 + * will hold a reference on the result.
22443 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22444 + struct nsproxy *new_nsproxy, unsigned long mask)
22446 + struct mnt_namespace *old_ns;
22447 + struct uts_namespace *old_uts;
22448 + struct ipc_namespace *old_ipc;
22449 +#ifdef CONFIG_PID_NS
22450 + struct pid_namespace *old_pid;
22452 +#ifdef CONFIG_NET_NS
22453 + struct net *old_net;
22455 + struct nsproxy *nsproxy;
22457 + nsproxy = copy_nsproxy(old_nsproxy);
22461 + if (mask & CLONE_NEWNS) {
22462 + old_ns = nsproxy->mnt_ns;
22463 + nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22464 + if (nsproxy->mnt_ns)
22465 + get_mnt_ns(nsproxy->mnt_ns);
22469 + if (mask & CLONE_NEWUTS) {
22470 + old_uts = nsproxy->uts_ns;
22471 + nsproxy->uts_ns = new_nsproxy->uts_ns;
22472 + if (nsproxy->uts_ns)
22473 + get_uts_ns(nsproxy->uts_ns);
22477 + if (mask & CLONE_NEWIPC) {
22478 + old_ipc = nsproxy->ipc_ns;
22479 + nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22480 + if (nsproxy->ipc_ns)
22481 + get_ipc_ns(nsproxy->ipc_ns);
22485 +#ifdef CONFIG_PID_NS
22486 + if (mask & CLONE_NEWPID) {
22487 + old_pid = nsproxy->pid_ns;
22488 + nsproxy->pid_ns = new_nsproxy->pid_ns;
22489 + if (nsproxy->pid_ns)
22490 + get_pid_ns(nsproxy->pid_ns);
22494 +#ifdef CONFIG_NET_NS
22495 + if (mask & CLONE_NEWNET) {
22496 + old_net = nsproxy->net_ns;
22497 + nsproxy->net_ns = new_nsproxy->net_ns;
22498 + if (nsproxy->net_ns)
22499 + get_net(nsproxy->net_ns);
22504 + put_mnt_ns(old_ns);
22506 + put_uts_ns(old_uts);
22508 + put_ipc_ns(old_ipc);
22509 +#ifdef CONFIG_PID_NS
22511 + put_pid_ns(old_pid);
22513 +#ifdef CONFIG_NET_NS
22515 + put_net(old_net);
22523 + * merge two nsproxy structs into a new one.
22524 + * will hold a reference on the result.
22528 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22529 + struct nsproxy *proxy, unsigned long mask)
22531 + struct nsproxy null_proxy = { .mnt_ns = NULL };
22537 + /* vs_mix_nsproxy returns with reference */
22538 + return vs_mix_nsproxy(old ? old : &null_proxy,
22541 + get_nsproxy(proxy);
22546 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22548 + struct nsproxy *proxy, *proxy_cur, *proxy_new;
22549 + struct fs_struct *fs_cur, *fs = NULL;
22550 + struct _vx_space *space;
22551 + int ret, kill = 0;
22553 + vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22554 + vxi, vxi->vx_id, mask, index);
22556 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22559 + if (index >= VX_SPACES)
22562 + space = &vxi->space[index];
22565 + mask = space->vx_nsmask;
22567 + if ((mask & space->vx_nsmask) != mask)
22570 + if (mask & CLONE_FS) {
22571 + fs = copy_fs_struct(space->vx_fs);
22575 + proxy = space->vx_nsproxy;
22577 + vxdprintk(VXD_CBIT(space, 9),
22578 + "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22579 + vxi, vxi->vx_id, mask, index, proxy, fs);
22581 + task_lock(current);
22582 + fs_cur = current->fs;
22584 + if (mask & CLONE_FS) {
22585 + spin_lock(&fs_cur->lock);
22586 + current->fs = fs;
22587 + kill = !--fs_cur->users;
22588 + spin_unlock(&fs_cur->lock);
22591 + proxy_cur = current->nsproxy;
22592 + get_nsproxy(proxy_cur);
22593 + task_unlock(current);
22596 + free_fs_struct(fs_cur);
22598 + proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22599 + if (IS_ERR(proxy_new)) {
22600 + ret = PTR_ERR(proxy_new);
22604 + proxy_new = xchg(¤t->nsproxy, proxy_new);
22606 + if (mask & CLONE_NEWUSER) {
22607 + struct cred *cred;
22609 + vxdprintk(VXD_CBIT(space, 10),
22610 + "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22611 + vxi, vxi->vx_id, space->vx_cred,
22612 + current->real_cred, current->cred);
22614 + if (space->vx_cred) {
22615 + cred = __prepare_creds(space->vx_cred);
22617 + commit_creds(cred);
22624 + put_nsproxy(proxy_new);
22627 + put_nsproxy(proxy_cur);
22632 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22634 + struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22635 + struct fs_struct *fs_vxi, *fs = NULL;
22636 + struct _vx_space *space;
22637 + int ret, kill = 0;
22639 + vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22640 + vxi, vxi->vx_id, mask, index);
22642 + if ((mask & space_mask.mask) != mask)
22645 + if (index >= VX_SPACES)
22648 + space = &vxi->space[index];
22650 + proxy_vxi = space->vx_nsproxy;
22651 + fs_vxi = space->vx_fs;
22653 + if (mask & CLONE_FS) {
22654 + fs = copy_fs_struct(current->fs);
22659 + task_lock(current);
22661 + if (mask & CLONE_FS) {
22662 + spin_lock(&fs_vxi->lock);
22663 + space->vx_fs = fs;
22664 + kill = !--fs_vxi->users;
22665 + spin_unlock(&fs_vxi->lock);
22668 + proxy_cur = current->nsproxy;
22669 + get_nsproxy(proxy_cur);
22670 + task_unlock(current);
22673 + free_fs_struct(fs_vxi);
22675 + proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22676 + if (IS_ERR(proxy_new)) {
22677 + ret = PTR_ERR(proxy_new);
22681 + proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22682 + space->vx_nsmask |= mask;
22684 + if (mask & CLONE_NEWUSER) {
22685 + struct cred *cred;
22687 + vxdprintk(VXD_CBIT(space, 10),
22688 + "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22689 + vxi, vxi->vx_id, space->vx_cred,
22690 + current->real_cred, current->cred);
22692 + cred = prepare_creds();
22693 + cred = (struct cred *)xchg(&space->vx_cred, cred);
22695 + abort_creds(cred);
22701 + put_nsproxy(proxy_new);
22704 + put_nsproxy(proxy_cur);
22709 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22711 + struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22713 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22716 + return vx_enter_space(vxi, vc_data.mask, 0);
22719 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22721 + struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22723 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22726 + if (vc_data.index >= VX_SPACES)
22729 + return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22732 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22734 + struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22736 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22739 + return vx_set_space(vxi, vc_data.mask, 0);
22742 +int vc_set_space(struct vx_info *vxi, void __user *data)
22744 + struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22746 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22749 + if (vc_data.index >= VX_SPACES)
22752 + return vx_set_space(vxi, vc_data.mask, vc_data.index);
22755 +int vc_get_space_mask(void __user *data, int type)
22757 + const struct vcmd_space_mask_v1 *mask;
22760 + mask = &space_mask_v0;
22761 + else if (type == 1)
22762 + mask = &space_mask;
22764 + mask = &default_space_mask;
22766 + vxdprintk(VXD_CBIT(space, 10),
22767 + "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22769 + if (copy_to_user(data, mask, sizeof(*mask)))
22774 diff -NurpP --minimal linux-3.9.4/kernel/vserver/switch.c linux-3.9.4-vs2.3.6.2/kernel/vserver/switch.c
22775 --- linux-3.9.4/kernel/vserver/switch.c 1970-01-01 00:00:00.000000000 +0000
22776 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/switch.c 2013-05-31 14:47:11.000000000 +0000
22779 + * linux/kernel/vserver/switch.c
22781 + * Virtual Server: Syscall Switch
22783 + * Copyright (C) 2003-2011 Herbert Pötzl
22785 + * V0.01 syscall switch
22786 + * V0.02 added signal to context
22787 + * V0.03 added rlimit functions
22788 + * V0.04 added iattr, task/xid functions
22789 + * V0.05 added debug/history stuff
22790 + * V0.06 added compat32 layer
22791 + * V0.07 vcmd args and perms
22792 + * V0.08 added status commands
22793 + * V0.09 added tag commands
22794 + * V0.10 added oom bias
22795 + * V0.11 added device commands
22796 + * V0.12 added warn mask
22800 +#include <linux/vs_context.h>
22801 +#include <linux/vs_network.h>
22802 +#include <linux/vserver/switch.h>
22804 +#include "vci_config.h"
22808 +int vc_get_version(uint32_t id)
22810 + return VCI_VERSION;
22814 +int vc_get_vci(uint32_t id)
22816 + return vci_kernel_config();
22819 +#include <linux/vserver/context_cmd.h>
22820 +#include <linux/vserver/cvirt_cmd.h>
22821 +#include <linux/vserver/cacct_cmd.h>
22822 +#include <linux/vserver/limit_cmd.h>
22823 +#include <linux/vserver/network_cmd.h>
22824 +#include <linux/vserver/sched_cmd.h>
22825 +#include <linux/vserver/debug_cmd.h>
22826 +#include <linux/vserver/inode_cmd.h>
22827 +#include <linux/vserver/dlimit_cmd.h>
22828 +#include <linux/vserver/signal_cmd.h>
22829 +#include <linux/vserver/space_cmd.h>
22830 +#include <linux/vserver/tag_cmd.h>
22831 +#include <linux/vserver/device_cmd.h>
22833 +#include <linux/vserver/inode.h>
22834 +#include <linux/vserver/dlimit.h>
22837 +#ifdef CONFIG_COMPAT
22838 +#define __COMPAT(name, id, data, compat) \
22839 + (compat) ? name ## _x32(id, data) : name(id, data)
22840 +#define __COMPAT_NO_ID(name, data, compat) \
22841 + (compat) ? name ## _x32(data) : name(data)
22843 +#define __COMPAT(name, id, data, compat) \
22845 +#define __COMPAT_NO_ID(name, data, compat) \
22851 +long do_vcmd(uint32_t cmd, uint32_t id,
22852 + struct vx_info *vxi, struct nx_info *nxi,
22853 + void __user *data, int compat)
22857 + case VCMD_get_version:
22858 + return vc_get_version(id);
22859 + case VCMD_get_vci:
22860 + return vc_get_vci(id);
22862 + case VCMD_task_xid:
22863 + return vc_task_xid(id);
22864 + case VCMD_vx_info:
22865 + return vc_vx_info(vxi, data);
22867 + case VCMD_task_nid:
22868 + return vc_task_nid(id);
22869 + case VCMD_nx_info:
22870 + return vc_nx_info(nxi, data);
22872 + case VCMD_task_tag:
22873 + return vc_task_tag(id);
22875 + case VCMD_set_space_v1:
22876 + return vc_set_space_v1(vxi, data);
22877 + /* this is version 2 */
22878 + case VCMD_set_space:
22879 + return vc_set_space(vxi, data);
22881 + case VCMD_get_space_mask_v0:
22882 + return vc_get_space_mask(data, 0);
22883 + /* this is version 1 */
22884 + case VCMD_get_space_mask:
22885 + return vc_get_space_mask(data, 1);
22887 + case VCMD_get_space_default:
22888 + return vc_get_space_mask(data, -1);
22890 + case VCMD_set_umask:
22891 + return vc_set_umask(vxi, data);
22893 + case VCMD_get_umask:
22894 + return vc_get_umask(vxi, data);
22896 + case VCMD_set_wmask:
22897 + return vc_set_wmask(vxi, data);
22899 + case VCMD_get_wmask:
22900 + return vc_get_wmask(vxi, data);
22901 +#ifdef CONFIG_IA32_EMULATION
22902 + case VCMD_get_rlimit:
22903 + return __COMPAT(vc_get_rlimit, vxi, data, compat);
22904 + case VCMD_set_rlimit:
22905 + return __COMPAT(vc_set_rlimit, vxi, data, compat);
22907 + case VCMD_get_rlimit:
22908 + return vc_get_rlimit(vxi, data);
22909 + case VCMD_set_rlimit:
22910 + return vc_set_rlimit(vxi, data);
22912 + case VCMD_get_rlimit_mask:
22913 + return vc_get_rlimit_mask(id, data);
22914 + case VCMD_reset_hits:
22915 + return vc_reset_hits(vxi, data);
22916 + case VCMD_reset_minmax:
22917 + return vc_reset_minmax(vxi, data);
22919 + case VCMD_get_vhi_name:
22920 + return vc_get_vhi_name(vxi, data);
22921 + case VCMD_set_vhi_name:
22922 + return vc_set_vhi_name(vxi, data);
22924 + case VCMD_ctx_stat:
22925 + return vc_ctx_stat(vxi, data);
22926 + case VCMD_virt_stat:
22927 + return vc_virt_stat(vxi, data);
22928 + case VCMD_sock_stat:
22929 + return vc_sock_stat(vxi, data);
22930 + case VCMD_rlimit_stat:
22931 + return vc_rlimit_stat(vxi, data);
22933 + case VCMD_set_cflags:
22934 + return vc_set_cflags(vxi, data);
22935 + case VCMD_get_cflags:
22936 + return vc_get_cflags(vxi, data);
22938 + /* this is version 1 */
22939 + case VCMD_set_ccaps:
22940 + return vc_set_ccaps(vxi, data);
22941 + /* this is version 1 */
22942 + case VCMD_get_ccaps:
22943 + return vc_get_ccaps(vxi, data);
22944 + case VCMD_set_bcaps:
22945 + return vc_set_bcaps(vxi, data);
22946 + case VCMD_get_bcaps:
22947 + return vc_get_bcaps(vxi, data);
22949 + case VCMD_set_badness:
22950 + return vc_set_badness(vxi, data);
22951 + case VCMD_get_badness:
22952 + return vc_get_badness(vxi, data);
22954 + case VCMD_set_nflags:
22955 + return vc_set_nflags(nxi, data);
22956 + case VCMD_get_nflags:
22957 + return vc_get_nflags(nxi, data);
22959 + case VCMD_set_ncaps:
22960 + return vc_set_ncaps(nxi, data);
22961 + case VCMD_get_ncaps:
22962 + return vc_get_ncaps(nxi, data);
22964 + case VCMD_set_prio_bias:
22965 + return vc_set_prio_bias(vxi, data);
22966 + case VCMD_get_prio_bias:
22967 + return vc_get_prio_bias(vxi, data);
22968 + case VCMD_add_dlimit:
22969 + return __COMPAT(vc_add_dlimit, id, data, compat);
22970 + case VCMD_rem_dlimit:
22971 + return __COMPAT(vc_rem_dlimit, id, data, compat);
22972 + case VCMD_set_dlimit:
22973 + return __COMPAT(vc_set_dlimit, id, data, compat);
22974 + case VCMD_get_dlimit:
22975 + return __COMPAT(vc_get_dlimit, id, data, compat);
22977 + case VCMD_ctx_kill:
22978 + return vc_ctx_kill(vxi, data);
22980 + case VCMD_wait_exit:
22981 + return vc_wait_exit(vxi, data);
22983 + case VCMD_get_iattr:
22984 + return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22985 + case VCMD_set_iattr:
22986 + return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22988 + case VCMD_fget_iattr:
22989 + return vc_fget_iattr(id, data);
22990 + case VCMD_fset_iattr:
22991 + return vc_fset_iattr(id, data);
22993 + case VCMD_enter_space_v0:
22994 + return vc_enter_space_v1(vxi, NULL);
22995 + case VCMD_enter_space_v1:
22996 + return vc_enter_space_v1(vxi, data);
22997 + /* this is version 2 */
22998 + case VCMD_enter_space:
22999 + return vc_enter_space(vxi, data);
23001 + case VCMD_ctx_create_v0:
23002 + return vc_ctx_create(id, NULL);
23003 + case VCMD_ctx_create:
23004 + return vc_ctx_create(id, data);
23005 + case VCMD_ctx_migrate_v0:
23006 + return vc_ctx_migrate(vxi, NULL);
23007 + case VCMD_ctx_migrate:
23008 + return vc_ctx_migrate(vxi, data);
23010 + case VCMD_net_create_v0:
23011 + return vc_net_create(id, NULL);
23012 + case VCMD_net_create:
23013 + return vc_net_create(id, data);
23014 + case VCMD_net_migrate:
23015 + return vc_net_migrate(nxi, data);
23017 + case VCMD_tag_migrate:
23018 + return vc_tag_migrate(id);
23020 + case VCMD_net_add:
23021 + return vc_net_add(nxi, data);
23022 + case VCMD_net_remove:
23023 + return vc_net_remove(nxi, data);
23025 + case VCMD_net_add_ipv4_v1:
23026 + return vc_net_add_ipv4_v1(nxi, data);
23027 + /* this is version 2 */
23028 + case VCMD_net_add_ipv4:
23029 + return vc_net_add_ipv4(nxi, data);
23031 + case VCMD_net_rem_ipv4_v1:
23032 + return vc_net_rem_ipv4_v1(nxi, data);
23033 + /* this is version 2 */
23034 + case VCMD_net_rem_ipv4:
23035 + return vc_net_rem_ipv4(nxi, data);
23036 +#ifdef CONFIG_IPV6
23037 + case VCMD_net_add_ipv6:
23038 + return vc_net_add_ipv6(nxi, data);
23039 + case VCMD_net_remove_ipv6:
23040 + return vc_net_remove_ipv6(nxi, data);
23042 +/* case VCMD_add_match_ipv4:
23043 + return vc_add_match_ipv4(nxi, data);
23044 + case VCMD_get_match_ipv4:
23045 + return vc_get_match_ipv4(nxi, data);
23046 +#ifdef CONFIG_IPV6
23047 + case VCMD_add_match_ipv6:
23048 + return vc_add_match_ipv6(nxi, data);
23049 + case VCMD_get_match_ipv6:
23050 + return vc_get_match_ipv6(nxi, data);
23053 +#ifdef CONFIG_VSERVER_DEVICE
23054 + case VCMD_set_mapping:
23055 + return __COMPAT(vc_set_mapping, vxi, data, compat);
23056 + case VCMD_unset_mapping:
23057 + return __COMPAT(vc_unset_mapping, vxi, data, compat);
23059 +#ifdef CONFIG_VSERVER_HISTORY
23060 + case VCMD_dump_history:
23061 + return vc_dump_history(id);
23062 + case VCMD_read_history:
23063 + return __COMPAT(vc_read_history, id, data, compat);
23066 + vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23067 + VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23073 +#define __VCMD(vcmd, _perm, _args, _flags) \
23074 + case VCMD_ ## vcmd: perm = _perm; \
23075 + args = _args; flags = _flags; break
23078 +#define VCA_NONE 0x00
23079 +#define VCA_VXI 0x01
23080 +#define VCA_NXI 0x02
23082 +#define VCF_NONE 0x00
23083 +#define VCF_INFO 0x01
23084 +#define VCF_ADMIN 0x02
23085 +#define VCF_ARES 0x06 /* includes admin */
23086 +#define VCF_SETUP 0x08
23088 +#define VCF_ZIDOK 0x10 /* zero id okay */
23092 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23095 + int permit = -1, state = 0;
23096 + int perm = -1, args = 0, flags = 0;
23097 + struct vx_info *vxi = NULL;
23098 + struct nx_info *nxi = NULL;
23101 + /* unpriviledged commands */
23102 + __VCMD(get_version, 0, VCA_NONE, 0);
23103 + __VCMD(get_vci, 0, VCA_NONE, 0);
23104 + __VCMD(get_rlimit_mask, 0, VCA_NONE, 0);
23105 + __VCMD(get_space_mask_v0,0, VCA_NONE, 0);
23106 + __VCMD(get_space_mask, 0, VCA_NONE, 0);
23107 + __VCMD(get_space_default,0, VCA_NONE, 0);
23109 + /* info commands */
23110 + __VCMD(task_xid, 2, VCA_NONE, 0);
23111 + __VCMD(reset_hits, 2, VCA_VXI, 0);
23112 + __VCMD(reset_minmax, 2, VCA_VXI, 0);
23113 + __VCMD(vx_info, 3, VCA_VXI, VCF_INFO);
23114 + __VCMD(get_bcaps, 3, VCA_VXI, VCF_INFO);
23115 + __VCMD(get_ccaps, 3, VCA_VXI, VCF_INFO);
23116 + __VCMD(get_cflags, 3, VCA_VXI, VCF_INFO);
23117 + __VCMD(get_umask, 3, VCA_VXI, VCF_INFO);
23118 + __VCMD(get_wmask, 3, VCA_VXI, VCF_INFO);
23119 + __VCMD(get_badness, 3, VCA_VXI, VCF_INFO);
23120 + __VCMD(get_vhi_name, 3, VCA_VXI, VCF_INFO);
23121 + __VCMD(get_rlimit, 3, VCA_VXI, VCF_INFO);
23123 + __VCMD(ctx_stat, 3, VCA_VXI, VCF_INFO);
23124 + __VCMD(virt_stat, 3, VCA_VXI, VCF_INFO);
23125 + __VCMD(sock_stat, 3, VCA_VXI, VCF_INFO);
23126 + __VCMD(rlimit_stat, 3, VCA_VXI, VCF_INFO);
23128 + __VCMD(task_nid, 2, VCA_NONE, 0);
23129 + __VCMD(nx_info, 3, VCA_NXI, VCF_INFO);
23130 + __VCMD(get_ncaps, 3, VCA_NXI, VCF_INFO);
23131 + __VCMD(get_nflags, 3, VCA_NXI, VCF_INFO);
23133 + __VCMD(task_tag, 2, VCA_NONE, 0);
23135 + __VCMD(get_iattr, 2, VCA_NONE, 0);
23136 + __VCMD(fget_iattr, 2, VCA_NONE, 0);
23137 + __VCMD(get_dlimit, 3, VCA_NONE, VCF_INFO);
23138 + __VCMD(get_prio_bias, 3, VCA_VXI, VCF_INFO);
23140 + /* lower admin commands */
23141 + __VCMD(wait_exit, 4, VCA_VXI, VCF_INFO);
23142 + __VCMD(ctx_create_v0, 5, VCA_NONE, 0);
23143 + __VCMD(ctx_create, 5, VCA_NONE, 0);
23144 + __VCMD(ctx_migrate_v0, 5, VCA_VXI, VCF_ADMIN);
23145 + __VCMD(ctx_migrate, 5, VCA_VXI, VCF_ADMIN);
23146 + __VCMD(enter_space_v0, 5, VCA_VXI, VCF_ADMIN);
23147 + __VCMD(enter_space_v1, 5, VCA_VXI, VCF_ADMIN);
23148 + __VCMD(enter_space, 5, VCA_VXI, VCF_ADMIN);
23150 + __VCMD(net_create_v0, 5, VCA_NONE, 0);
23151 + __VCMD(net_create, 5, VCA_NONE, 0);
23152 + __VCMD(net_migrate, 5, VCA_NXI, VCF_ADMIN);
23154 + __VCMD(tag_migrate, 5, VCA_NONE, VCF_ADMIN);
23156 + /* higher admin commands */
23157 + __VCMD(ctx_kill, 6, VCA_VXI, VCF_ARES);
23158 + __VCMD(set_space_v1, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23159 + __VCMD(set_space, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23161 + __VCMD(set_ccaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23162 + __VCMD(set_bcaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23163 + __VCMD(set_cflags, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23164 + __VCMD(set_umask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23165 + __VCMD(set_wmask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23166 + __VCMD(set_badness, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23168 + __VCMD(set_vhi_name, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23169 + __VCMD(set_rlimit, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23170 + __VCMD(set_prio_bias, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23172 + __VCMD(set_ncaps, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
23173 + __VCMD(set_nflags, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
23174 + __VCMD(net_add, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23175 + __VCMD(net_remove, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23176 + __VCMD(net_add_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23177 + __VCMD(net_rem_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23178 + __VCMD(net_add_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23179 + __VCMD(net_rem_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23180 +#ifdef CONFIG_IPV6
23181 + __VCMD(net_add_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23182 + __VCMD(net_remove_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23184 + __VCMD(set_iattr, 7, VCA_NONE, 0);
23185 + __VCMD(fset_iattr, 7, VCA_NONE, 0);
23186 + __VCMD(set_dlimit, 7, VCA_NONE, VCF_ARES);
23187 + __VCMD(add_dlimit, 8, VCA_NONE, VCF_ARES);
23188 + __VCMD(rem_dlimit, 8, VCA_NONE, VCF_ARES);
23190 +#ifdef CONFIG_VSERVER_DEVICE
23191 + __VCMD(set_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
23192 + __VCMD(unset_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
23194 + /* debug level admin commands */
23195 +#ifdef CONFIG_VSERVER_HISTORY
23196 + __VCMD(dump_history, 9, VCA_NONE, 0);
23197 + __VCMD(read_history, 9, VCA_NONE, 0);
23204 + vxdprintk(VXD_CBIT(switch, 0),
23205 + "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23206 + VC_CATEGORY(cmd), VC_COMMAND(cmd),
23207 + VC_VERSION(cmd), id, data, compat,
23208 + perm, args, flags);
23215 + if (!capable(CAP_CONTEXT))
23219 + /* moved here from the individual commands */
23221 + if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23225 + /* vcmd involves resource management */
23227 + if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23231 + /* various legacy exceptions */
23233 + /* will go away when spectator is a cap */
23234 + case VCMD_ctx_migrate_v0:
23235 + case VCMD_ctx_migrate:
23237 + current->xid = 1;
23243 + /* will go away when spectator is a cap */
23244 + case VCMD_net_migrate:
23246 + current->nid = 1;
23253 + /* vcmds are fine by default */
23256 + /* admin type vcmds require admin ... */
23257 + if (flags & VCF_ADMIN)
23258 + permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23260 + /* ... but setup type vcmds override that */
23261 + if (!permit && (flags & VCF_SETUP))
23262 + permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23270 + if (!id && (flags & VCF_ZIDOK))
23274 + if (args & VCA_VXI) {
23275 + vxi = lookup_vx_info(id);
23279 + if ((flags & VCF_ADMIN) &&
23280 + /* special case kill for shutdown */
23281 + (cmd != VCMD_ctx_kill) &&
23282 + /* can context be administrated? */
23283 + !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23289 + if (args & VCA_NXI) {
23290 + nxi = lookup_nx_info(id);
23294 + if ((flags & VCF_ADMIN) &&
23295 + /* can context be administrated? */
23296 + !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23303 + ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23306 + if ((args & VCA_NXI) && nxi)
23307 + put_nx_info(nxi);
23309 + if ((args & VCA_VXI) && vxi)
23310 + put_vx_info(vxi);
23312 + vxdprintk(VXD_CBIT(switch, 1),
23313 + "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23314 + VC_CATEGORY(cmd), VC_COMMAND(cmd),
23315 + VC_VERSION(cmd), ret, ret, state, permit);
23320 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23322 + return do_vserver(cmd, id, data, 0);
23325 +#ifdef CONFIG_COMPAT
23328 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23330 + return do_vserver(cmd, id, data, 1);
23333 +#endif /* CONFIG_COMPAT */
23334 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sysctl.c linux-3.9.4-vs2.3.6.2/kernel/vserver/sysctl.c
23335 --- linux-3.9.4/kernel/vserver/sysctl.c 1970-01-01 00:00:00.000000000 +0000
23336 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sysctl.c 2013-05-31 14:47:11.000000000 +0000
23339 + * kernel/vserver/sysctl.c
23341 + * Virtual Context Support
23343 + * Copyright (C) 2004-2007 Herbert Pötzl
23345 + * V0.01 basic structure
23349 +#include <linux/module.h>
23350 +#include <linux/ctype.h>
23351 +#include <linux/sysctl.h>
23352 +#include <linux/parser.h>
23353 +#include <asm/uaccess.h>
23356 + CTL_DEBUG_ERROR = 0,
23357 + CTL_DEBUG_SWITCH = 1,
23373 +unsigned int vs_debug_switch = 0;
23374 +unsigned int vs_debug_xid = 0;
23375 +unsigned int vs_debug_nid = 0;
23376 +unsigned int vs_debug_tag = 0;
23377 +unsigned int vs_debug_net = 0;
23378 +unsigned int vs_debug_limit = 0;
23379 +unsigned int vs_debug_cres = 0;
23380 +unsigned int vs_debug_dlim = 0;
23381 +unsigned int vs_debug_quota = 0;
23382 +unsigned int vs_debug_cvirt = 0;
23383 +unsigned int vs_debug_space = 0;
23384 +unsigned int vs_debug_perm = 0;
23385 +unsigned int vs_debug_misc = 0;
23388 +static struct ctl_table_header *vserver_table_header;
23389 +static ctl_table vserver_root_table[];
23392 +void vserver_register_sysctl(void)
23394 + if (!vserver_table_header) {
23395 + vserver_table_header = register_sysctl_table(vserver_root_table);
23400 +void vserver_unregister_sysctl(void)
23402 + if (vserver_table_header) {
23403 + unregister_sysctl_table(vserver_table_header);
23404 + vserver_table_header = NULL;
23409 +static int proc_dodebug(ctl_table *table, int write,
23410 + void __user *buffer, size_t *lenp, loff_t *ppos)
23412 + char tmpbuf[20], *p, c;
23413 + unsigned int value;
23414 + size_t left, len;
23416 + if ((*ppos && !write) || !*lenp) {
23424 + if (!access_ok(VERIFY_READ, buffer, left))
23426 + p = (char *)buffer;
23427 + while (left && __get_user(c, p) >= 0 && isspace(c))
23432 + if (left > sizeof(tmpbuf) - 1)
23434 + if (copy_from_user(tmpbuf, p, left))
23436 + tmpbuf[left] = '\0';
23438 + for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23439 + value = 10 * value + (*p - '0');
23440 + if (*p && !isspace(*p))
23442 + while (left && isspace(*p))
23444 + *(unsigned int *)table->data = value;
23446 + if (!access_ok(VERIFY_WRITE, buffer, left))
23448 + len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23451 + if (__copy_to_user(buffer, tmpbuf, len))
23453 + if ((left -= len) > 0) {
23454 + if (put_user('\n', (char *)buffer + len))
23468 +#define CTL_ENTRY(ctl, name) \
23470 + .procname = #name, \
23471 + .data = &vs_ ## name, \
23472 + .maxlen = sizeof(int), \
23474 + .proc_handler = &proc_dodebug, \
23475 + .extra1 = &zero, \
23476 + .extra2 = &zero, \
23479 +static ctl_table vserver_debug_table[] = {
23480 + CTL_ENTRY(CTL_DEBUG_SWITCH, debug_switch),
23481 + CTL_ENTRY(CTL_DEBUG_XID, debug_xid),
23482 + CTL_ENTRY(CTL_DEBUG_NID, debug_nid),
23483 + CTL_ENTRY(CTL_DEBUG_TAG, debug_tag),
23484 + CTL_ENTRY(CTL_DEBUG_NET, debug_net),
23485 + CTL_ENTRY(CTL_DEBUG_LIMIT, debug_limit),
23486 + CTL_ENTRY(CTL_DEBUG_CRES, debug_cres),
23487 + CTL_ENTRY(CTL_DEBUG_DLIM, debug_dlim),
23488 + CTL_ENTRY(CTL_DEBUG_QUOTA, debug_quota),
23489 + CTL_ENTRY(CTL_DEBUG_CVIRT, debug_cvirt),
23490 + CTL_ENTRY(CTL_DEBUG_SPACE, debug_space),
23491 + CTL_ENTRY(CTL_DEBUG_PERM, debug_perm),
23492 + CTL_ENTRY(CTL_DEBUG_MISC, debug_misc),
23496 +static ctl_table vserver_root_table[] = {
23498 + .procname = "vserver",
23500 + .child = vserver_debug_table
23506 +static match_table_t tokens = {
23507 + { CTL_DEBUG_SWITCH, "switch=%x" },
23508 + { CTL_DEBUG_XID, "xid=%x" },
23509 + { CTL_DEBUG_NID, "nid=%x" },
23510 + { CTL_DEBUG_TAG, "tag=%x" },
23511 + { CTL_DEBUG_NET, "net=%x" },
23512 + { CTL_DEBUG_LIMIT, "limit=%x" },
23513 + { CTL_DEBUG_CRES, "cres=%x" },
23514 + { CTL_DEBUG_DLIM, "dlim=%x" },
23515 + { CTL_DEBUG_QUOTA, "quota=%x" },
23516 + { CTL_DEBUG_CVIRT, "cvirt=%x" },
23517 + { CTL_DEBUG_SPACE, "space=%x" },
23518 + { CTL_DEBUG_PERM, "perm=%x" },
23519 + { CTL_DEBUG_MISC, "misc=%x" },
23520 + { CTL_DEBUG_ERROR, NULL }
23523 +#define HANDLE_CASE(id, name, val) \
23524 + case CTL_DEBUG_ ## id: \
23525 + vs_debug_ ## name = val; \
23526 + printk("vs_debug_" #name "=0x%x\n", val); \
23530 +static int __init vs_debug_setup(char *str)
23535 + printk("vs_debug_setup(%s)\n", str);
23536 + while ((p = strsep(&str, ",")) != NULL) {
23537 + substring_t args[MAX_OPT_ARGS];
23538 + unsigned int value;
23543 + token = match_token(p, tokens, args);
23544 + value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23547 + HANDLE_CASE(SWITCH, switch, value);
23548 + HANDLE_CASE(XID, xid, value);
23549 + HANDLE_CASE(NID, nid, value);
23550 + HANDLE_CASE(TAG, tag, value);
23551 + HANDLE_CASE(NET, net, value);
23552 + HANDLE_CASE(LIMIT, limit, value);
23553 + HANDLE_CASE(CRES, cres, value);
23554 + HANDLE_CASE(DLIM, dlim, value);
23555 + HANDLE_CASE(QUOTA, quota, value);
23556 + HANDLE_CASE(CVIRT, cvirt, value);
23557 + HANDLE_CASE(SPACE, space, value);
23558 + HANDLE_CASE(PERM, perm, value);
23559 + HANDLE_CASE(MISC, misc, value);
23568 +__setup("vsdebug=", vs_debug_setup);
23572 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23573 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23574 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23575 +EXPORT_SYMBOL_GPL(vs_debug_net);
23576 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23577 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23578 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23579 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23580 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23581 +EXPORT_SYMBOL_GPL(vs_debug_space);
23582 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23583 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23585 diff -NurpP --minimal linux-3.9.4/kernel/vserver/tag.c linux-3.9.4-vs2.3.6.2/kernel/vserver/tag.c
23586 --- linux-3.9.4/kernel/vserver/tag.c 1970-01-01 00:00:00.000000000 +0000
23587 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/tag.c 2013-05-31 14:47:11.000000000 +0000
23590 + * linux/kernel/vserver/tag.c
23592 + * Virtual Server: Shallow Tag Space
23594 + * Copyright (C) 2007 Herbert Pötzl
23596 + * V0.01 basic implementation
23600 +#include <linux/sched.h>
23601 +#include <linux/vserver/debug.h>
23602 +#include <linux/vs_pid.h>
23603 +#include <linux/vs_tag.h>
23605 +#include <linux/vserver/tag_cmd.h>
23608 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23613 + vxdprintk(VXD_CBIT(tag, 5),
23614 + "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23620 + vxdprintk(VXD_CBIT(tag, 5),
23621 + "moved task %p into [#%d]", p, tag);
23625 +/* vserver syscall commands below here */
23627 +/* taks xid and vx_info functions */
23630 +int vc_task_tag(uint32_t id)
23635 + struct task_struct *tsk;
23637 + tsk = find_task_by_real_pid(id);
23638 + tag = (tsk) ? tsk->tag : -ESRCH;
23639 + rcu_read_unlock();
23641 + tag = dx_current_tag();
23646 +int vc_tag_migrate(uint32_t tag)
23648 + return dx_migrate_task(current, tag & 0xFFFF);
23652 diff -NurpP --minimal linux-3.9.4/kernel/vserver/vci_config.h linux-3.9.4-vs2.3.6.2/kernel/vserver/vci_config.h
23653 --- linux-3.9.4/kernel/vserver/vci_config.h 1970-01-01 00:00:00.000000000 +0000
23654 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/vci_config.h 2013-05-31 14:47:11.000000000 +0000
23657 +/* interface version */
23659 +#define VCI_VERSION 0x00020308
23663 + VCI_KCBIT_NO_DYNAMIC = 0,
23665 + VCI_KCBIT_PROC_SECURE = 4,
23666 + /* VCI_KCBIT_HARDCPU = 5, */
23667 + /* VCI_KCBIT_IDLELIMIT = 6, */
23668 + /* VCI_KCBIT_IDLETIME = 7, */
23670 + VCI_KCBIT_COWBL = 8,
23671 + VCI_KCBIT_FULLCOWBL = 9,
23672 + VCI_KCBIT_SPACES = 10,
23673 + VCI_KCBIT_NETV2 = 11,
23674 + VCI_KCBIT_MEMCG = 12,
23675 + VCI_KCBIT_MEMCG_SWAP = 13,
23677 + VCI_KCBIT_DEBUG = 16,
23678 + VCI_KCBIT_HISTORY = 20,
23679 + VCI_KCBIT_TAGGED = 24,
23680 + VCI_KCBIT_PPTAG = 28,
23682 + VCI_KCBIT_MORE = 31,
23686 +static inline uint32_t vci_kernel_config(void)
23689 + (1 << VCI_KCBIT_NO_DYNAMIC) |
23691 + /* configured features */
23692 +#ifdef CONFIG_VSERVER_PROC_SECURE
23693 + (1 << VCI_KCBIT_PROC_SECURE) |
23695 +#ifdef CONFIG_VSERVER_COWBL
23696 + (1 << VCI_KCBIT_COWBL) |
23697 + (1 << VCI_KCBIT_FULLCOWBL) |
23699 + (1 << VCI_KCBIT_SPACES) |
23700 + (1 << VCI_KCBIT_NETV2) |
23701 +#ifdef CONFIG_MEMCG
23702 + (1 << VCI_KCBIT_MEMCG) |
23704 +#ifdef CONFIG_MEMCG_SWAP
23705 + (1 << VCI_KCBIT_MEMCG_SWAP) |
23708 + /* debug options */
23709 +#ifdef CONFIG_VSERVER_DEBUG
23710 + (1 << VCI_KCBIT_DEBUG) |
23712 +#ifdef CONFIG_VSERVER_HISTORY
23713 + (1 << VCI_KCBIT_HISTORY) |
23716 + /* inode context tagging */
23717 +#if defined(CONFIG_TAGGING_NONE)
23718 + (0 << VCI_KCBIT_TAGGED) |
23719 +#elif defined(CONFIG_TAGGING_UID16)
23720 + (1 << VCI_KCBIT_TAGGED) |
23721 +#elif defined(CONFIG_TAGGING_GID16)
23722 + (2 << VCI_KCBIT_TAGGED) |
23723 +#elif defined(CONFIG_TAGGING_ID24)
23724 + (3 << VCI_KCBIT_TAGGED) |
23725 +#elif defined(CONFIG_TAGGING_INTERN)
23726 + (4 << VCI_KCBIT_TAGGED) |
23727 +#elif defined(CONFIG_TAGGING_RUNTIME)
23728 + (5 << VCI_KCBIT_TAGGED) |
23730 + (7 << VCI_KCBIT_TAGGED) |
23732 + (1 << VCI_KCBIT_PPTAG) |
23736 diff -NurpP --minimal linux-3.9.4/mm/memcontrol.c linux-3.9.4-vs2.3.6.2/mm/memcontrol.c
23737 --- linux-3.9.4/mm/memcontrol.c 2013-05-31 13:45:31.000000000 +0000
23738 +++ linux-3.9.4-vs2.3.6.2/mm/memcontrol.c 2013-05-31 14:47:11.000000000 +0000
23739 @@ -1046,6 +1046,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23740 return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23743 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23745 + return res_counter_read_u64(&mem->res, member);
23748 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23750 + return res_counter_read_u64(&mem->memsw, member);
23753 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23755 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23758 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23760 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23763 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23765 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23768 struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23770 struct mem_cgroup *memcg = NULL;
23771 diff -NurpP --minimal linux-3.9.4/mm/oom_kill.c linux-3.9.4-vs2.3.6.2/mm/oom_kill.c
23772 --- linux-3.9.4/mm/oom_kill.c 2013-05-31 13:45:31.000000000 +0000
23773 +++ linux-3.9.4-vs2.3.6.2/mm/oom_kill.c 2013-05-31 14:47:11.000000000 +0000
23775 #include <linux/freezer.h>
23776 #include <linux/ftrace.h>
23777 #include <linux/ratelimit.h>
23778 +#include <linux/reboot.h>
23779 +#include <linux/vs_context.h>
23781 #define CREATE_TRACE_POINTS
23782 #include <trace/events/oom.h>
23783 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23784 static bool oom_unkillable_task(struct task_struct *p,
23785 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23787 - if (is_global_init(p))
23788 + unsigned xid = vx_current_xid();
23790 + /* skip the init task, global and per guest */
23791 + if (task_is_init(p))
23793 if (p->flags & PF_KTHREAD)
23796 + /* skip other guest and host processes if oom in guest */
23797 + if (xid && vx_task_xid(p) != xid)
23800 /* When mem_cgroup_out_of_memory() and p is not member of the group */
23801 if (memcg && !task_in_mem_cgroup(p, memcg))
23803 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23804 dump_header(p, gfp_mask, order, memcg, nodemask);
23807 - pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23808 - message, task_pid_nr(p), p->comm, points);
23809 + pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23810 + message, task_pid_nr(p), p->xid, p->comm, points);
23814 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23816 /* mm cannot safely be dereferenced after task_unlock(victim) */
23818 - pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23819 - task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23820 + pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23821 + task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23822 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23823 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23824 task_unlock(victim);
23825 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23827 EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23829 +long vs_oom_action(unsigned int);
23832 * Try to acquire the OOM killer lock for the zones in zonelist. Returns zero
23833 * if a parallel OOM killing is already taking place that includes a zone in
23834 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23835 /* Found nothing?!?! Either we hang forever, or we panic. */
23837 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23838 - panic("Out of memory and no killable processes...\n");
23840 + /* avoid panic for guest OOM */
23841 + if (vx_current_xid())
23842 + vs_oom_action(LINUX_REBOOT_CMD_OOM);
23844 + panic("Out of memory and no killable processes...\n");
23846 if (PTR_ERR(p) != -1UL) {
23847 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23848 diff -NurpP --minimal linux-3.9.4/mm/page_alloc.c linux-3.9.4-vs2.3.6.2/mm/page_alloc.c
23849 --- linux-3.9.4/mm/page_alloc.c 2013-05-31 13:45:31.000000000 +0000
23850 +++ linux-3.9.4-vs2.3.6.2/mm/page_alloc.c 2013-05-31 15:08:50.000000000 +0000
23852 #include <linux/migrate.h>
23853 #include <linux/page-debug-flags.h>
23854 #include <linux/sched/rt.h>
23855 +#include <linux/vs_base.h>
23856 +#include <linux/vs_limit.h>
23858 #include <asm/tlbflush.h>
23859 #include <asm/div64.h>
23860 @@ -2873,6 +2875,9 @@ void si_meminfo(struct sysinfo *val)
23861 val->totalhigh = totalhigh_pages;
23862 val->freehigh = nr_free_highpages();
23863 val->mem_unit = PAGE_SIZE;
23865 + if (vx_flags(VXF_VIRT_MEM, 0))
23866 + vx_vsi_meminfo(val);
23869 EXPORT_SYMBOL(si_meminfo);
23870 @@ -2893,6 +2898,9 @@ void si_meminfo_node(struct sysinfo *val
23873 val->mem_unit = PAGE_SIZE;
23875 + if (vx_flags(VXF_VIRT_MEM, 0))
23876 + vx_vsi_meminfo(val);
23880 diff -NurpP --minimal linux-3.9.4/mm/pgtable-generic.c linux-3.9.4-vs2.3.6.2/mm/pgtable-generic.c
23881 --- linux-3.9.4/mm/pgtable-generic.c 2013-02-19 13:58:57.000000000 +0000
23882 +++ linux-3.9.4-vs2.3.6.2/mm/pgtable-generic.c 2013-05-31 14:47:11.000000000 +0000
23884 * Copyright (C) 2010 Linus Torvalds
23887 +#include <linux/mm.h>
23889 #include <linux/pagemap.h>
23890 #include <asm/tlb.h>
23891 #include <asm-generic/pgtable.h>
23892 diff -NurpP --minimal linux-3.9.4/mm/shmem.c linux-3.9.4-vs2.3.6.2/mm/shmem.c
23893 --- linux-3.9.4/mm/shmem.c 2013-05-31 13:45:31.000000000 +0000
23894 +++ linux-3.9.4-vs2.3.6.2/mm/shmem.c 2013-05-31 14:47:11.000000000 +0000
23895 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23897 struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23899 - buf->f_type = TMPFS_MAGIC;
23900 + buf->f_type = TMPFS_SUPER_MAGIC;
23901 buf->f_bsize = PAGE_CACHE_SIZE;
23902 buf->f_namelen = NAME_MAX;
23903 if (sbinfo->max_blocks) {
23904 @@ -2606,7 +2606,7 @@ int shmem_fill_super(struct super_block
23905 sb->s_maxbytes = MAX_LFS_FILESIZE;
23906 sb->s_blocksize = PAGE_CACHE_SIZE;
23907 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23908 - sb->s_magic = TMPFS_MAGIC;
23909 + sb->s_magic = TMPFS_SUPER_MAGIC;
23910 sb->s_op = &shmem_ops;
23911 sb->s_time_gran = 1;
23912 #ifdef CONFIG_TMPFS_XATTR
23913 diff -NurpP --minimal linux-3.9.4/mm/slab.c linux-3.9.4-vs2.3.6.2/mm/slab.c
23914 --- linux-3.9.4/mm/slab.c 2013-05-31 13:45:31.000000000 +0000
23915 +++ linux-3.9.4-vs2.3.6.2/mm/slab.c 2013-05-31 14:47:11.000000000 +0000
23916 @@ -429,6 +429,8 @@ static void kmem_list3_init(struct kmem_
23917 #define STATS_INC_FREEMISS(x) do { } while (0)
23920 +#include "slab_vs.h"
23925 @@ -3438,6 +3440,7 @@ retry:
23927 obj = slab_get_obj(cachep, slabp, nodeid);
23928 check_slabp(cachep, slabp);
23929 + vx_slab_alloc(cachep, flags);
23930 l3->free_objects--;
23931 /* move slabp to correct slabp list: */
23932 list_del(&slabp->list);
23933 @@ -3517,6 +3520,7 @@ slab_alloc_node(struct kmem_cache *cache
23934 /* ___cache_alloc_node can fall back to other nodes */
23935 ptr = ____cache_alloc_node(cachep, flags, nodeid);
23937 + vx_slab_alloc(cachep, flags);
23938 local_irq_restore(save_flags);
23939 ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23940 kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23941 @@ -3709,6 +3713,7 @@ static inline void __cache_free(struct k
23943 kmemleak_free_recursive(objp, cachep->flags);
23944 objp = cache_free_debugcheck(cachep, objp, caller);
23945 + vx_slab_free(cachep);
23947 kmemcheck_slab_free(cachep, objp, cachep->object_size);
23949 diff -NurpP --minimal linux-3.9.4/mm/slab_vs.h linux-3.9.4-vs2.3.6.2/mm/slab_vs.h
23950 --- linux-3.9.4/mm/slab_vs.h 1970-01-01 00:00:00.000000000 +0000
23951 +++ linux-3.9.4-vs2.3.6.2/mm/slab_vs.h 2013-05-31 14:47:11.000000000 +0000
23954 +#include <linux/vserver/context.h>
23956 +#include <linux/vs_context.h>
23959 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23961 + int what = gfp_zone(cachep->allocflags);
23962 + struct vx_info *vxi = current_vx_info();
23967 + atomic_add(cachep->size, &vxi->cacct.slab[what]);
23971 +void vx_slab_free(struct kmem_cache *cachep)
23973 + int what = gfp_zone(cachep->allocflags);
23974 + struct vx_info *vxi = current_vx_info();
23979 + atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23982 diff -NurpP --minimal linux-3.9.4/mm/swapfile.c linux-3.9.4-vs2.3.6.2/mm/swapfile.c
23983 --- linux-3.9.4/mm/swapfile.c 2013-05-31 13:45:31.000000000 +0000
23984 +++ linux-3.9.4-vs2.3.6.2/mm/swapfile.c 2013-05-31 14:47:11.000000000 +0000
23986 #include <asm/tlbflush.h>
23987 #include <linux/swapops.h>
23988 #include <linux/page_cgroup.h>
23989 +#include <linux/vs_base.h>
23991 static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23993 @@ -1767,6 +1768,16 @@ static int swap_show(struct seq_file *sw
23995 if (si == SEQ_START_TOKEN) {
23996 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23997 + if (vx_flags(VXF_VIRT_MEM, 0)) {
23998 + struct sysinfo si;
24000 + vx_vsi_swapinfo(&si);
24001 + if (si.totalswap < (1 << 10))
24003 + seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24004 + "hdv0", "partition", si.totalswap >> 10,
24005 + (si.totalswap - si.freeswap) >> 10, -1);
24010 @@ -2195,6 +2206,8 @@ void si_swapinfo(struct sysinfo *val)
24011 val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
24012 val->totalswap = total_swap_pages + nr_to_be_unused;
24013 spin_unlock(&swap_lock);
24014 + if (vx_flags(VXF_VIRT_MEM, 0))
24015 + vx_vsi_swapinfo(val);
24019 diff -NurpP --minimal linux-3.9.4/net/bridge/br_multicast.c linux-3.9.4-vs2.3.6.2/net/bridge/br_multicast.c
24020 --- linux-3.9.4/net/bridge/br_multicast.c 2013-05-31 13:45:31.000000000 +0000
24021 +++ linux-3.9.4-vs2.3.6.2/net/bridge/br_multicast.c 2013-05-31 17:17:53.000000000 +0000
24022 @@ -443,7 +443,7 @@ static struct sk_buff *br_ip6_multicast_
24023 ip6h->hop_limit = 1;
24024 ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24025 if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24027 + &ip6h->saddr, NULL)) {
24031 diff -NurpP --minimal linux-3.9.4/net/core/dev.c linux-3.9.4-vs2.3.6.2/net/core/dev.c
24032 --- linux-3.9.4/net/core/dev.c 2013-05-31 14:22:27.000000000 +0000
24033 +++ linux-3.9.4-vs2.3.6.2/net/core/dev.c 2013-05-31 18:37:38.000000000 +0000
24034 @@ -122,6 +122,7 @@
24035 #include <linux/in.h>
24036 #include <linux/jhash.h>
24037 #include <linux/random.h>
24038 +#include <linux/vs_inet.h>
24039 #include <trace/events/napi.h>
24040 #include <trace/events/net.h>
24041 #include <trace/events/skb.h>
24042 @@ -662,7 +663,8 @@ struct net_device *__dev_get_by_name(str
24043 struct hlist_head *head = dev_name_hash(net, name);
24045 hlist_for_each_entry(dev, head, name_hlist)
24046 - if (!strncmp(dev->name, name, IFNAMSIZ))
24047 + if (!strncmp(dev->name, name, IFNAMSIZ) &&
24048 + nx_dev_visible(current_nx_info(), dev))
24052 @@ -687,7 +689,8 @@ struct net_device *dev_get_by_name_rcu(s
24053 struct hlist_head *head = dev_name_hash(net, name);
24055 hlist_for_each_entry_rcu(dev, head, name_hlist)
24056 - if (!strncmp(dev->name, name, IFNAMSIZ))
24057 + if (!strncmp(dev->name, name, IFNAMSIZ) &&
24058 + nx_dev_visible(current_nx_info(), dev))
24062 @@ -737,7 +740,8 @@ struct net_device *__dev_get_by_index(st
24063 struct hlist_head *head = dev_index_hash(net, ifindex);
24065 hlist_for_each_entry(dev, head, index_hlist)
24066 - if (dev->ifindex == ifindex)
24067 + if ((dev->ifindex == ifindex) &&
24068 + nx_dev_visible(current_nx_info(), dev))
24072 @@ -755,7 +759,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24073 * about locking. The caller must hold RCU lock.
24076 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24077 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24079 struct net_device *dev;
24080 struct hlist_head *head = dev_index_hash(net, ifindex);
24081 @@ -766,6 +770,16 @@ struct net_device *dev_get_by_index_rcu(
24085 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24087 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24089 + struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24091 + if (nx_dev_visible(current_nx_info(), dev))
24095 EXPORT_SYMBOL(dev_get_by_index_rcu);
24098 @@ -814,7 +828,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24100 for_each_netdev_rcu(net, dev)
24101 if (dev->type == type &&
24102 - !memcmp(dev->dev_addr, ha, dev->addr_len))
24103 + !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24104 + nx_dev_visible(current_nx_info(), dev))
24108 @@ -826,9 +841,11 @@ struct net_device *__dev_getfirstbyhwtyp
24109 struct net_device *dev;
24112 - for_each_netdev(net, dev)
24113 - if (dev->type == type)
24114 + for_each_netdev(net, dev) {
24115 + if ((dev->type == type) &&
24116 + nx_dev_visible(current_nx_info(), dev))
24122 @@ -840,7 +857,8 @@ struct net_device *dev_getfirstbyhwtype(
24125 for_each_netdev_rcu(net, dev)
24126 - if (dev->type == type) {
24127 + if ((dev->type == type) &&
24128 + nx_dev_visible(current_nx_info(), dev)) {
24132 @@ -868,7 +886,8 @@ struct net_device *dev_get_by_flags_rcu(
24135 for_each_netdev_rcu(net, dev) {
24136 - if (((dev->flags ^ if_flags) & mask) == 0) {
24137 + if ((((dev->flags ^ if_flags) & mask) == 0) &&
24138 + nx_dev_visible(current_nx_info(), dev)) {
24142 @@ -946,6 +965,8 @@ static int __dev_alloc_name(struct net *
24144 if (i < 0 || i >= max_netdevices)
24146 + if (!nx_dev_visible(current_nx_info(), d))
24149 /* avoid cases where sscanf is not exact inverse of printf */
24150 snprintf(buf, IFNAMSIZ, name, i);
24151 diff -NurpP --minimal linux-3.9.4/net/core/net-procfs.c linux-3.9.4-vs2.3.6.2/net/core/net-procfs.c
24152 --- linux-3.9.4/net/core/net-procfs.c 2013-05-31 13:45:32.000000000 +0000
24153 +++ linux-3.9.4-vs2.3.6.2/net/core/net-procfs.c 2013-06-01 10:40:52.000000000 +0000
24155 #include <linux/netdevice.h>
24156 #include <linux/proc_fs.h>
24157 #include <linux/seq_file.h>
24158 +#include <linux/vs_inet.h>
24159 #include <net/wext.h>
24161 #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
24162 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
24163 static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
24165 struct rtnl_link_stats64 temp;
24166 - const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24167 + const struct rtnl_link_stats64 *stats;
24169 + /* device visible inside network context? */
24170 + if (!nx_dev_visible(current_nx_info(), dev))
24173 + stats = dev_get_stats(dev, &temp);
24174 seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24175 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24176 dev->name, stats->rx_bytes, stats->rx_packets,
24177 diff -NurpP --minimal linux-3.9.4/net/core/rtnetlink.c linux-3.9.4-vs2.3.6.2/net/core/rtnetlink.c
24178 --- linux-3.9.4/net/core/rtnetlink.c 2013-05-31 13:45:32.000000000 +0000
24179 +++ linux-3.9.4-vs2.3.6.2/net/core/rtnetlink.c 2013-05-31 17:17:54.000000000 +0000
24180 @@ -1085,6 +1085,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24181 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24184 + if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24186 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24187 NETLINK_CB(cb->skb).portid,
24188 cb->nlh->nlmsg_seq, 0,
24189 @@ -1974,6 +1976,9 @@ void rtmsg_ifinfo(int type, struct net_d
24190 int err = -ENOBUFS;
24191 size_t if_info_size;
24193 + if (!nx_dev_visible(current_nx_info(), dev))
24196 skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24199 diff -NurpP --minimal linux-3.9.4/net/core/sock.c linux-3.9.4-vs2.3.6.2/net/core/sock.c
24200 --- linux-3.9.4/net/core/sock.c 2013-05-31 14:22:27.000000000 +0000
24201 +++ linux-3.9.4-vs2.3.6.2/net/core/sock.c 2013-05-31 17:17:54.000000000 +0000
24202 @@ -132,6 +132,10 @@
24203 #include <net/netprio_cgroup.h>
24205 #include <linux/filter.h>
24206 +#include <linux/vs_socket.h>
24207 +#include <linux/vs_limit.h>
24208 +#include <linux/vs_context.h>
24209 +#include <linux/vs_network.h>
24211 #include <trace/events/sock.h>
24213 @@ -1257,6 +1261,8 @@ static struct sock *sk_prot_alloc(struct
24215 sk_tx_queue_clear(sk);
24217 + sock_vx_init(sk);
24218 + sock_nx_init(sk);
24222 @@ -1367,6 +1373,11 @@ static void __sk_free(struct sock *sk)
24223 put_cred(sk->sk_peer_cred);
24224 put_pid(sk->sk_peer_pid);
24225 put_net(sock_net(sk));
24227 + clr_vx_info(&sk->sk_vx_info);
24229 + clr_nx_info(&sk->sk_nx_info);
24231 sk_prot_free(sk->sk_prot_creator, sk);
24234 @@ -1427,6 +1438,8 @@ struct sock *sk_clone_lock(const struct
24237 get_net(sock_net(newsk));
24238 + sock_vx_init(newsk);
24239 + sock_nx_init(newsk);
24240 sk_node_init(&newsk->sk_node);
24241 sock_lock_init(newsk);
24242 bh_lock_sock(newsk);
24243 @@ -1483,6 +1496,12 @@ struct sock *sk_clone_lock(const struct
24245 atomic_set(&newsk->sk_refcnt, 2);
24247 + set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24248 + newsk->sk_xid = sk->sk_xid;
24249 + vx_sock_inc(newsk);
24250 + set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24251 + newsk->sk_nid = sk->sk_nid;
24254 * Increment the counter in the same struct proto as the master
24255 * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24256 @@ -2278,6 +2297,12 @@ void sock_init_data(struct socket *sock,
24258 sk->sk_stamp = ktime_set(-1L, 0);
24260 + set_vx_info(&sk->sk_vx_info, current_vx_info());
24261 + sk->sk_xid = vx_current_xid();
24263 + set_nx_info(&sk->sk_nx_info, current_nx_info());
24264 + sk->sk_nid = nx_current_nid();
24267 * Before updating sk_refcnt, we must commit prior changes to memory
24268 * (Documentation/RCU/rculist_nulls.txt for details)
24269 diff -NurpP --minimal linux-3.9.4/net/ipv4/af_inet.c linux-3.9.4-vs2.3.6.2/net/ipv4/af_inet.c
24270 --- linux-3.9.4/net/ipv4/af_inet.c 2013-05-31 13:45:32.000000000 +0000
24271 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/af_inet.c 2013-05-31 18:24:05.000000000 +0000
24272 @@ -118,6 +118,7 @@
24273 #ifdef CONFIG_IP_MROUTE
24274 #include <linux/mroute.h>
24276 +#include <linux/vs_limit.h>
24279 /* The inetsw table contains everything that inet_create needs to
24280 @@ -336,6 +337,10 @@ lookup_protocol:
24284 + if ((protocol == IPPROTO_ICMP) &&
24285 + nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24288 if (sock->type == SOCK_RAW && !kern &&
24289 !ns_capable(net->user_ns, CAP_NET_RAW))
24290 goto out_rcu_unlock;
24291 @@ -460,6 +465,7 @@ int inet_bind(struct socket *sock, struc
24292 struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24293 struct sock *sk = sock->sk;
24294 struct inet_sock *inet = inet_sk(sk);
24295 + struct nx_v4_sock_addr nsa;
24296 struct net *net = sock_net(sk);
24297 unsigned short snum;
24299 @@ -484,7 +490,11 @@ int inet_bind(struct socket *sock, struc
24303 - chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
24304 + err = v4_map_sock_addr(inet, addr, &nsa);
24308 + chk_addr_ret = inet_addr_type(net, nsa.saddr);
24310 /* Not specified by any standard per-se, however it breaks too
24311 * many applications when removed. It is unfortunate since
24312 @@ -496,7 +506,7 @@ int inet_bind(struct socket *sock, struc
24313 err = -EADDRNOTAVAIL;
24314 if (!sysctl_ip_nonlocal_bind &&
24315 !(inet->freebind || inet->transparent) &&
24316 - addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24317 + nsa.saddr != htonl(INADDR_ANY) &&
24318 chk_addr_ret != RTN_LOCAL &&
24319 chk_addr_ret != RTN_MULTICAST &&
24320 chk_addr_ret != RTN_BROADCAST)
24321 @@ -522,7 +532,7 @@ int inet_bind(struct socket *sock, struc
24322 if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24323 goto out_release_sock;
24325 - inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24326 + v4_set_sock_addr(inet, &nsa);
24327 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24328 inet->inet_saddr = 0; /* Use device */
24330 @@ -741,11 +751,13 @@ int inet_getname(struct socket *sock, st
24333 sin->sin_port = inet->inet_dport;
24334 - sin->sin_addr.s_addr = inet->inet_daddr;
24335 + sin->sin_addr.s_addr =
24336 + nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24338 __be32 addr = inet->inet_rcv_saddr;
24340 addr = inet->inet_saddr;
24341 + addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24342 sin->sin_port = inet->inet_sport;
24343 sin->sin_addr.s_addr = addr;
24345 diff -NurpP --minimal linux-3.9.4/net/ipv4/arp.c linux-3.9.4-vs2.3.6.2/net/ipv4/arp.c
24346 --- linux-3.9.4/net/ipv4/arp.c 2013-05-31 13:45:32.000000000 +0000
24347 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/arp.c 2013-05-31 17:17:54.000000000 +0000
24348 @@ -1317,6 +1317,7 @@ static void arp_format_neigh_entry(struc
24349 struct net_device *dev = n->dev;
24350 int hatype = dev->type;
24352 + /* FIXME: check for network context */
24353 read_lock(&n->lock);
24354 /* Convert hardware address to XX:XX:XX:XX ... form. */
24355 #if IS_ENABLED(CONFIG_AX25)
24356 @@ -1348,6 +1349,7 @@ static void arp_format_pneigh_entry(stru
24357 int hatype = dev ? dev->type : 0;
24360 + /* FIXME: check for network context */
24361 sprintf(tbuf, "%pI4", n->key);
24362 seq_printf(seq, "%-16s 0x%-10x0x%-10x%s * %s\n",
24363 tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24364 diff -NurpP --minimal linux-3.9.4/net/ipv4/devinet.c linux-3.9.4-vs2.3.6.2/net/ipv4/devinet.c
24365 --- linux-3.9.4/net/ipv4/devinet.c 2013-05-31 13:45:32.000000000 +0000
24366 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/devinet.c 2013-05-31 17:17:54.000000000 +0000
24367 @@ -522,6 +522,7 @@ struct in_device *inetdev_by_index(struc
24369 EXPORT_SYMBOL(inetdev_by_index);
24372 /* Called only from RTNL semaphored context. No locks. */
24374 struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24375 @@ -940,6 +941,8 @@ int devinet_ioctl(struct net *net, unsig
24377 in_dev = __in_dev_get_rtnl(dev);
24379 + struct nx_info *nxi = current_nx_info();
24381 if (tryaddrmatch) {
24382 /* Matthias Andree */
24383 /* compare label and address (4.4BSD style) */
24384 @@ -948,6 +951,8 @@ int devinet_ioctl(struct net *net, unsig
24385 This is checked above. */
24386 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24387 ifap = &ifa->ifa_next) {
24388 + if (!nx_v4_ifa_visible(nxi, ifa))
24390 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24391 sin_orig.sin_addr.s_addr ==
24393 @@ -960,9 +965,12 @@ int devinet_ioctl(struct net *net, unsig
24394 comparing just the label */
24396 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24397 - ifap = &ifa->ifa_next)
24398 + ifap = &ifa->ifa_next) {
24399 + if (!nx_v4_ifa_visible(nxi, ifa))
24401 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24407 @@ -1116,6 +1124,8 @@ static int inet_gifconf(struct net_devic
24410 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24411 + if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24414 done += sizeof(ifr);
24416 @@ -1519,6 +1529,7 @@ static int inet_dump_ifaddr(struct sk_bu
24417 struct net_device *dev;
24418 struct in_device *in_dev;
24419 struct in_ifaddr *ifa;
24420 + struct sock *sk = skb->sk;
24421 struct hlist_head *head;
24424 @@ -1540,6 +1551,8 @@ static int inet_dump_ifaddr(struct sk_bu
24426 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24427 ifa = ifa->ifa_next, ip_idx++) {
24428 + if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24430 if (ip_idx < s_ip_idx)
24432 if (inet_fill_ifaddr(skb, ifa,
24433 diff -NurpP --minimal linux-3.9.4/net/ipv4/fib_trie.c linux-3.9.4-vs2.3.6.2/net/ipv4/fib_trie.c
24434 --- linux-3.9.4/net/ipv4/fib_trie.c 2013-05-31 13:45:32.000000000 +0000
24435 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/fib_trie.c 2013-05-31 17:17:54.000000000 +0000
24436 @@ -2548,6 +2548,7 @@ static int fib_route_seq_show(struct seq
24437 || fa->fa_type == RTN_MULTICAST)
24440 + /* FIXME: check for network context? */
24443 "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24444 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_connection_sock.c linux-3.9.4-vs2.3.6.2/net/ipv4/inet_connection_sock.c
24445 --- linux-3.9.4/net/ipv4/inet_connection_sock.c 2013-05-31 13:45:32.000000000 +0000
24446 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/inet_connection_sock.c 2013-05-31 18:29:56.000000000 +0000
24447 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24449 EXPORT_SYMBOL(inet_get_local_port_range);
24451 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24453 + __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1),
24454 + sk2_rcv_saddr = sk_rcv_saddr(sk2);
24456 + if (inet_v6_ipv6only(sk2))
24459 + if (sk1_rcv_saddr &&
24461 + sk1_rcv_saddr == sk2_rcv_saddr)
24464 + if (sk1_rcv_saddr &&
24465 + !sk2_rcv_saddr &&
24466 + v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24469 + if (sk2_rcv_saddr &&
24470 + !sk1_rcv_saddr &&
24471 + v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24474 + if (!sk1_rcv_saddr &&
24475 + !sk2_rcv_saddr &&
24476 + nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24482 int inet_csk_bind_conflict(const struct sock *sk,
24483 const struct inet_bind_bucket *tb, bool relax)
24485 @@ -79,17 +110,12 @@ int inet_csk_bind_conflict(const struct
24486 (!reuseport || !sk2->sk_reuseport ||
24487 (sk2->sk_state != TCP_TIME_WAIT &&
24488 !uid_eq(uid, sock_i_uid(sk2))))) {
24489 - const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24490 - if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24491 - sk2_rcv_saddr == sk_rcv_saddr(sk))
24492 + if (ipv4_rcv_saddr_equal(sk, sk2))
24495 if (!relax && reuse && sk2->sk_reuse &&
24496 sk2->sk_state != TCP_LISTEN) {
24497 - const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24499 - if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24500 - sk2_rcv_saddr == sk_rcv_saddr(sk))
24501 + if (ipv4_rcv_saddr_equal(sk, sk2))
24505 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_diag.c linux-3.9.4-vs2.3.6.2/net/ipv4/inet_diag.c
24506 --- linux-3.9.4/net/ipv4/inet_diag.c 2013-02-19 13:58:58.000000000 +0000
24507 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/inet_diag.c 2013-05-31 17:17:54.000000000 +0000
24510 #include <linux/inet.h>
24511 #include <linux/stddef.h>
24512 +#include <linux/vs_network.h>
24513 +#include <linux/vs_inet.h>
24515 #include <linux/inet_diag.h>
24516 #include <linux/sock_diag.h>
24517 @@ -106,8 +108,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24519 r->id.idiag_sport = inet->inet_sport;
24520 r->id.idiag_dport = inet->inet_dport;
24521 - r->id.idiag_src[0] = inet->inet_rcv_saddr;
24522 - r->id.idiag_dst[0] = inet->inet_daddr;
24523 + r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24524 + inet->inet_rcv_saddr);
24525 + r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24526 + inet->inet_daddr);
24528 if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
24530 @@ -242,8 +246,8 @@ static int inet_twsk_diag_fill(struct in
24531 sock_diag_save_cookie(tw, r->id.idiag_cookie);
24532 r->id.idiag_sport = tw->tw_sport;
24533 r->id.idiag_dport = tw->tw_dport;
24534 - r->id.idiag_src[0] = tw->tw_rcv_saddr;
24535 - r->id.idiag_dst[0] = tw->tw_daddr;
24536 + r->id.idiag_src[0] = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24537 + r->id.idiag_dst[0] = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24538 r->idiag_state = tw->tw_substate;
24539 r->idiag_timer = 3;
24540 r->idiag_expires = DIV_ROUND_UP(tmo * 1000, HZ);
24541 @@ -287,12 +291,14 @@ int inet_diag_dump_one_icsk(struct inet_
24544 if (req->sdiag_family == AF_INET) {
24545 + /* TODO: lback */
24546 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24547 req->id.idiag_dport, req->id.idiag_src[0],
24548 req->id.idiag_sport, req->id.idiag_if);
24550 #if IS_ENABLED(CONFIG_IPV6)
24551 else if (req->sdiag_family == AF_INET6) {
24552 + /* TODO: lback */
24553 sk = inet6_lookup(net, hashinfo,
24554 (struct in6_addr *)req->id.idiag_dst,
24555 req->id.idiag_dport,
24556 @@ -494,6 +500,7 @@ int inet_diag_bc_sk(const struct nlattr
24560 + /* TODO: lback */
24561 entry.saddr = &inet->inet_rcv_saddr;
24562 entry.daddr = &inet->inet_daddr;
24564 @@ -652,6 +659,7 @@ static int inet_twsk_diag_dump(struct in
24568 + /* TODO: lback */
24569 entry.saddr = &tw->tw_rcv_saddr;
24570 entry.daddr = &tw->tw_daddr;
24572 @@ -730,8 +738,8 @@ static int inet_diag_fill_req(struct sk_
24574 r->id.idiag_sport = inet->inet_sport;
24575 r->id.idiag_dport = ireq->rmt_port;
24576 - r->id.idiag_src[0] = ireq->loc_addr;
24577 - r->id.idiag_dst[0] = ireq->rmt_addr;
24578 + r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24579 + r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24580 r->idiag_expires = jiffies_to_msecs(tmo);
24581 r->idiag_rqueue = 0;
24582 r->idiag_wqueue = 0;
24583 @@ -794,6 +802,7 @@ static int inet_diag_dump_reqs(struct sk
24587 + /* TODO: lback */
24589 inet_diag_req_addrs(sk, req, &entry);
24590 entry.dport = ntohs(ireq->rmt_port);
24591 @@ -850,6 +859,8 @@ void inet_diag_dump_icsk(struct inet_has
24592 if (!net_eq(sock_net(sk), net))
24595 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24600 @@ -922,6 +933,8 @@ skip_listen_ht:
24602 if (!net_eq(sock_net(sk), net))
24604 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24608 if (!(r->idiag_states & (1 << sk->sk_state)))
24609 @@ -950,7 +963,8 @@ next_normal:
24611 if (!net_eq(twsk_net(tw), net))
24614 + if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24618 if (r->sdiag_family != AF_UNSPEC &&
24619 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_hashtables.c linux-3.9.4-vs2.3.6.2/net/ipv4/inet_hashtables.c
24620 --- linux-3.9.4/net/ipv4/inet_hashtables.c 2013-05-31 13:45:32.000000000 +0000
24621 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/inet_hashtables.c 2013-05-31 18:20:50.000000000 +0000
24623 #include <net/inet_connection_sock.h>
24624 #include <net/inet_hashtables.h>
24625 #include <net/secure_seq.h>
24626 +#include <net/route.h>
24627 #include <net/ip.h>
24630 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24631 if (rcv_saddr != daddr)
24635 + /* block non nx_info ips */
24636 + if (!v4_addr_in_nx_info(sk->sk_nx_info,
24637 + daddr, NXA_MASK_BIND))
24640 if (sk->sk_bound_dev_if) {
24641 if (sk->sk_bound_dev_if != dif)
24642 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24643 * wildcarded during the search since they can never be otherwise.
24647 struct sock *__inet_lookup_listener(struct net *net,
24648 struct inet_hashinfo *hashinfo,
24649 const __be32 saddr, __be16 sport,
24650 @@ -209,6 +214,7 @@ begin:
24651 phash = next_pseudo_random32(phash);
24656 * if the nulls value we got at the end of this lookup is
24657 * not the expected one, we must restart lookup.
24658 diff -NurpP --minimal linux-3.9.4/net/ipv4/netfilter.c linux-3.9.4-vs2.3.6.2/net/ipv4/netfilter.c
24659 --- linux-3.9.4/net/ipv4/netfilter.c 2012-12-11 03:30:57.000000000 +0000
24660 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/netfilter.c 2013-05-31 17:17:54.000000000 +0000
24662 #include <linux/skbuff.h>
24663 #include <linux/gfp.h>
24664 #include <linux/export.h>
24665 -#include <net/route.h>
24666 +// #include <net/route.h>
24667 #include <net/xfrm.h>
24668 #include <net/ip.h>
24669 #include <net/netfilter/nf_queue.h>
24670 diff -NurpP --minimal linux-3.9.4/net/ipv4/raw.c linux-3.9.4-vs2.3.6.2/net/ipv4/raw.c
24671 --- linux-3.9.4/net/ipv4/raw.c 2013-05-31 13:45:32.000000000 +0000
24672 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/raw.c 2013-05-31 18:19:38.000000000 +0000
24673 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
24675 if (net_eq(sock_net(sk), net) && inet->inet_num == num &&
24676 !(inet->inet_daddr && inet->inet_daddr != raddr) &&
24677 - !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24678 + v4_sock_addr_match(sk->sk_nx_info, inet, laddr) &&
24679 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24680 goto found; /* gotcha */
24682 @@ -395,6 +395,12 @@ static int raw_send_hdrinc(struct sock *
24683 icmp_out_count(net, ((struct icmphdr *)
24684 skb_transport_header(skb))->type);
24687 + if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24688 + sk->sk_nx_info &&
24689 + !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24692 err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24693 rt->dst.dev, dst_output);
24695 @@ -580,6 +586,16 @@ static int raw_sendmsg(struct kiocb *ioc
24699 + if (sk->sk_nx_info) {
24700 + rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24701 + if (IS_ERR(rt)) {
24702 + err = PTR_ERR(rt);
24709 security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24710 rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24712 @@ -656,17 +672,19 @@ static int raw_bind(struct sock *sk, str
24714 struct inet_sock *inet = inet_sk(sk);
24715 struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24716 + struct nx_v4_sock_addr nsa = { 0 };
24720 if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24722 - chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24723 + v4_map_sock_addr(inet, addr, &nsa);
24724 + chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24725 ret = -EADDRNOTAVAIL;
24726 - if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24727 + if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24728 chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24730 - inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24731 + v4_set_sock_addr(inet, &nsa);
24732 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24733 inet->inet_saddr = 0; /* Use device */
24735 @@ -718,7 +736,8 @@ static int raw_recvmsg(struct kiocb *ioc
24736 /* Copy the address. */
24738 sin->sin_family = AF_INET;
24739 - sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24740 + sin->sin_addr.s_addr =
24741 + nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24743 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24745 @@ -913,7 +932,8 @@ static struct sock *raw_get_first(struct
24746 for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24748 sk_for_each(sk, &state->h->ht[state->bucket])
24749 - if (sock_net(sk) == seq_file_net(seq))
24750 + if ((sock_net(sk) == seq_file_net(seq)) &&
24751 + nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24755 @@ -929,7 +949,8 @@ static struct sock *raw_get_next(struct
24759 - } while (sk && sock_net(sk) != seq_file_net(seq));
24760 + } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24761 + !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24763 if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24764 sk = sk_head(&state->h->ht[state->bucket]);
24765 diff -NurpP --minimal linux-3.9.4/net/ipv4/route.c linux-3.9.4-vs2.3.6.2/net/ipv4/route.c
24766 --- linux-3.9.4/net/ipv4/route.c 2013-05-31 13:45:32.000000000 +0000
24767 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/route.c 2013-05-31 17:17:54.000000000 +0000
24768 @@ -1998,7 +1998,7 @@ struct rtable *__ip_route_output_key(str
24771 if (fl4->flowi4_oif) {
24772 - dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24773 + dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24774 rth = ERR_PTR(-ENODEV);
24775 if (dev_out == NULL)
24777 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp.c linux-3.9.4-vs2.3.6.2/net/ipv4/tcp.c
24778 --- linux-3.9.4/net/ipv4/tcp.c 2013-05-31 13:45:32.000000000 +0000
24779 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/tcp.c 2013-05-31 17:17:54.000000000 +0000
24780 @@ -268,6 +268,7 @@
24781 #include <linux/crypto.h>
24782 #include <linux/time.h>
24783 #include <linux/slab.h>
24784 +#include <linux/in.h>
24786 #include <net/icmp.h>
24787 #include <net/inet_common.h>
24788 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp_ipv4.c linux-3.9.4-vs2.3.6.2/net/ipv4/tcp_ipv4.c
24789 --- linux-3.9.4/net/ipv4/tcp_ipv4.c 2013-05-31 13:45:32.000000000 +0000
24790 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/tcp_ipv4.c 2013-05-31 17:17:54.000000000 +0000
24791 @@ -2260,6 +2260,12 @@ static void *listening_get_next(struct s
24792 req = req->dl_next;
24795 + vxdprintk(VXD_CBIT(net, 6),
24796 + "sk,req: %p [#%d] (from %d)", req->sk,
24797 + (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24799 + !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24801 if (req->rsk_ops->family == st->family) {
24804 @@ -2284,6 +2290,10 @@ get_req:
24807 sk_nulls_for_each_from(sk, node) {
24808 + vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24809 + sk, sk->sk_nid, nx_current_nid());
24810 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24812 if (!net_eq(sock_net(sk), net))
24814 if (sk->sk_family == st->family) {
24815 @@ -2360,6 +2370,11 @@ static void *established_get_first(struc
24817 spin_lock_bh(lock);
24818 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24819 + vxdprintk(VXD_CBIT(net, 6),
24820 + "sk,egf: %p [#%d] (from %d)",
24821 + sk, sk->sk_nid, nx_current_nid());
24822 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24824 if (sk->sk_family != st->family ||
24825 !net_eq(sock_net(sk), net)) {
24827 @@ -2370,6 +2385,11 @@ static void *established_get_first(struc
24828 st->state = TCP_SEQ_STATE_TIME_WAIT;
24829 inet_twsk_for_each(tw, node,
24830 &tcp_hashinfo.ehash[st->bucket].twchain) {
24831 + vxdprintk(VXD_CBIT(net, 6),
24832 + "tw: %p [#%d] (from %d)",
24833 + tw, tw->tw_nid, nx_current_nid());
24834 + if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24836 if (tw->tw_family != st->family ||
24837 !net_eq(twsk_net(tw), net)) {
24839 @@ -2399,7 +2419,9 @@ static void *established_get_next(struct
24843 - while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24844 + while (tw && (tw->tw_family != st->family ||
24845 + !net_eq(twsk_net(tw), net) ||
24846 + !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24850 @@ -2423,6 +2445,11 @@ get_tw:
24851 sk = sk_nulls_next(sk);
24853 sk_nulls_for_each_from(sk, node) {
24854 + vxdprintk(VXD_CBIT(net, 6),
24855 + "sk,egn: %p [#%d] (from %d)",
24856 + sk, sk->sk_nid, nx_current_nid());
24857 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24859 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24862 @@ -2628,9 +2655,9 @@ static void get_openreq4(const struct so
24863 seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24864 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24867 + nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24868 ntohs(inet_sk(sk)->inet_sport),
24870 + nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24871 ntohs(ireq->rmt_port),
24873 0, 0, /* could print option size, but that is af dependent. */
24874 @@ -2653,8 +2680,8 @@ static void get_tcp4_sock(struct sock *s
24875 const struct inet_connection_sock *icsk = inet_csk(sk);
24876 const struct inet_sock *inet = inet_sk(sk);
24877 struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24878 - __be32 dest = inet->inet_daddr;
24879 - __be32 src = inet->inet_rcv_saddr;
24880 + __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24881 + __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24882 __u16 destp = ntohs(inet->inet_dport);
24883 __u16 srcp = ntohs(inet->inet_sport);
24885 @@ -2710,8 +2737,8 @@ static void get_timewait4_sock(const str
24887 long delta = tw->tw_ttd - jiffies;
24889 - dest = tw->tw_daddr;
24890 - src = tw->tw_rcv_saddr;
24891 + dest = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24892 + src = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24893 destp = ntohs(tw->tw_dport);
24894 srcp = ntohs(tw->tw_sport);
24896 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp_minisocks.c linux-3.9.4-vs2.3.6.2/net/ipv4/tcp_minisocks.c
24897 --- linux-3.9.4/net/ipv4/tcp_minisocks.c 2013-05-31 14:22:27.000000000 +0000
24898 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/tcp_minisocks.c 2013-05-31 17:17:54.000000000 +0000
24900 #include <linux/slab.h>
24901 #include <linux/sysctl.h>
24902 #include <linux/workqueue.h>
24903 +#include <linux/vs_limit.h>
24904 +#include <linux/vs_socket.h>
24905 +#include <linux/vs_context.h>
24906 #include <net/tcp.h>
24907 #include <net/inet_common.h>
24908 #include <net/xfrm.h>
24909 @@ -291,6 +294,11 @@ void tcp_time_wait(struct sock *sk, int
24910 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24911 tcptw->tw_ts_offset = tp->tsoffset;
24913 + tw->tw_xid = sk->sk_xid;
24914 + tw->tw_vx_info = NULL;
24915 + tw->tw_nid = sk->sk_nid;
24916 + tw->tw_nx_info = NULL;
24918 #if IS_ENABLED(CONFIG_IPV6)
24919 if (tw->tw_family == PF_INET6) {
24920 struct ipv6_pinfo *np = inet6_sk(sk);
24921 diff -NurpP --minimal linux-3.9.4/net/ipv4/udp.c linux-3.9.4-vs2.3.6.2/net/ipv4/udp.c
24922 --- linux-3.9.4/net/ipv4/udp.c 2013-05-31 13:45:32.000000000 +0000
24923 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/udp.c 2013-05-31 18:26:00.000000000 +0000
24924 @@ -306,14 +306,7 @@ fail:
24926 EXPORT_SYMBOL(udp_lib_get_port);
24928 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24930 - struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24932 - return (!ipv6_only_sock(sk2) &&
24933 - (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24934 - inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24936 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24938 static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24940 @@ -348,6 +341,11 @@ static inline int compute_score(struct s
24941 if (inet->inet_rcv_saddr != daddr)
24945 + /* block non nx_info ips */
24946 + if (!v4_addr_in_nx_info(sk->sk_nx_info,
24947 + daddr, NXA_MASK_BIND))
24950 if (inet->inet_daddr) {
24951 if (inet->inet_daddr != saddr)
24952 @@ -458,6 +456,7 @@ begin:
24957 /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24958 * harder than this. -DaveM
24960 @@ -504,6 +503,11 @@ begin:
24961 sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24962 score = compute_score(sk, net, saddr, hnum, sport,
24963 daddr, dport, dif);
24964 + /* FIXME: disabled?
24965 + if (score == 9) {
24969 if (score > badness) {
24972 @@ -528,6 +532,7 @@ begin:
24973 if (get_nulls_value(node) != slot)
24978 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24980 @@ -537,6 +542,7 @@ begin:
24988 @@ -580,8 +586,7 @@ static inline struct sock *udp_v4_mcast_
24989 udp_sk(s)->udp_port_hash != hnum ||
24990 (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24991 (inet->inet_dport != rmt_port && inet->inet_dport) ||
24992 - (inet->inet_rcv_saddr &&
24993 - inet->inet_rcv_saddr != loc_addr) ||
24994 + !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24995 ipv6_only_sock(s) ||
24996 (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
24998 @@ -964,6 +969,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24999 inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25000 faddr, saddr, dport, inet->inet_sport);
25002 + if (sk->sk_nx_info) {
25003 + rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25004 + if (IS_ERR(rt)) {
25005 + err = PTR_ERR(rt);
25012 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25013 rt = ip_route_output_flow(net, fl4, sk);
25015 @@ -1269,7 +1284,8 @@ try_again:
25017 sin->sin_family = AF_INET;
25018 sin->sin_port = udp_hdr(skb)->source;
25019 - sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25020 + sin->sin_addr.s_addr = nx_map_sock_lback(
25021 + skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25022 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25024 if (inet->cmsg_flags)
25025 @@ -2025,6 +2041,8 @@ static struct sock *udp_get_first(struct
25026 sk_nulls_for_each(sk, node, &hslot->head) {
25027 if (!net_eq(sock_net(sk), net))
25029 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25031 if (sk->sk_family == state->family)
25034 @@ -2042,7 +2060,9 @@ static struct sock *udp_get_next(struct
25037 sk = sk_nulls_next(sk);
25038 - } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25039 + } while (sk && (!net_eq(sock_net(sk), net) ||
25040 + sk->sk_family != state->family ||
25041 + !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25044 if (state->bucket <= state->udp_table->mask)
25045 @@ -2138,8 +2158,8 @@ static void udp4_format_sock(struct sock
25046 int bucket, int *len)
25048 struct inet_sock *inet = inet_sk(sp);
25049 - __be32 dest = inet->inet_daddr;
25050 - __be32 src = inet->inet_rcv_saddr;
25051 + __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25052 + __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25053 __u16 destp = ntohs(inet->inet_dport);
25054 __u16 srcp = ntohs(inet->inet_sport);
25056 diff -NurpP --minimal linux-3.9.4/net/ipv6/Kconfig linux-3.9.4-vs2.3.6.2/net/ipv6/Kconfig
25057 --- linux-3.9.4/net/ipv6/Kconfig 2013-05-31 13:45:32.000000000 +0000
25058 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/Kconfig 2013-05-31 17:17:54.000000000 +0000
25061 # IPv6 as module will cause a CRASH if you try to unload it
25063 - tristate "The IPv6 protocol"
25065 + bool "The IPv6 protocol"
25068 This is complemental support for the IP version 6.
25069 You will still be able to do traditional IPv4 networking as well.
25070 diff -NurpP --minimal linux-3.9.4/net/ipv6/addrconf.c linux-3.9.4-vs2.3.6.2/net/ipv6/addrconf.c
25071 --- linux-3.9.4/net/ipv6/addrconf.c 2013-05-31 13:45:32.000000000 +0000
25072 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/addrconf.c 2013-05-31 20:07:39.000000000 +0000
25074 #include <linux/proc_fs.h>
25075 #include <linux/seq_file.h>
25076 #include <linux/export.h>
25077 +#include <linux/vs_network.h>
25078 +#include <linux/vs_inet6.h>
25080 /* Set to 3 to get tracing... */
25081 #define ACONF_DEBUG 2
25082 @@ -1250,7 +1252,7 @@ out:
25084 int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
25085 const struct in6_addr *daddr, unsigned int prefs,
25086 - struct in6_addr *saddr)
25087 + struct in6_addr *saddr, struct nx_info *nxi)
25089 struct ipv6_saddr_score scores[2],
25090 *score = &scores[0], *hiscore = &scores[1];
25091 @@ -1322,6 +1324,8 @@ int ipv6_dev_get_saddr(struct net *net,
25095 + if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25099 bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25100 @@ -3311,7 +3315,10 @@ static void if6_seq_stop(struct seq_file
25101 static int if6_seq_show(struct seq_file *seq, void *v)
25103 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25104 - seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25106 + if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25107 + v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25108 + seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25110 ifp->idev->dev->ifindex,
25112 @@ -3815,6 +3822,11 @@ static int in6_dump_addrs(struct inet6_d
25113 struct ifacaddr6 *ifaca;
25115 int ip_idx = *p_ip_idx;
25116 + struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25118 + /* disable ipv6 on non v6 guests */
25119 + if (nxi && !nx_info_has_v6(nxi))
25122 read_lock_bh(&idev->lock);
25124 @@ -3825,6 +3837,8 @@ static int in6_dump_addrs(struct inet6_d
25125 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25126 if (++ip_idx < s_ip_idx)
25128 + if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25130 err = inet6_fill_ifaddr(skb, ifa,
25131 NETLINK_CB(cb->skb).portid,
25132 cb->nlh->nlmsg_seq,
25133 @@ -3841,6 +3855,8 @@ static int in6_dump_addrs(struct inet6_d
25134 ifmca = ifmca->next, ip_idx++) {
25135 if (ip_idx < s_ip_idx)
25137 + if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25139 err = inet6_fill_ifmcaddr(skb, ifmca,
25140 NETLINK_CB(cb->skb).portid,
25141 cb->nlh->nlmsg_seq,
25142 @@ -3856,6 +3872,8 @@ static int in6_dump_addrs(struct inet6_d
25143 ifaca = ifaca->aca_next, ip_idx++) {
25144 if (ip_idx < s_ip_idx)
25146 + if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25148 err = inet6_fill_ifacaddr(skb, ifaca,
25149 NETLINK_CB(cb->skb).portid,
25150 cb->nlh->nlmsg_seq,
25151 @@ -3884,6 +3902,10 @@ static int inet6_dump_addr(struct sk_buf
25152 struct inet6_dev *idev;
25153 struct hlist_head *head;
25155 + /* FIXME: maybe disable ipv6 on non v6 guests?
25156 + if (skb->sk && skb->sk->sk_vx_info)
25157 + return skb->len; */
25160 s_idx = idx = cb->args[1];
25161 s_ip_idx = ip_idx = cb->args[2];
25162 @@ -4238,6 +4260,7 @@ static int inet6_dump_ifinfo(struct sk_b
25163 struct net_device *dev;
25164 struct inet6_dev *idev;
25165 struct hlist_head *head;
25166 + struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25169 s_idx = cb->args[1];
25170 @@ -4249,6 +4272,8 @@ static int inet6_dump_ifinfo(struct sk_b
25171 hlist_for_each_entry_rcu(dev, head, index_hlist) {
25174 + if (!v6_dev_in_nx_info(dev, nxi))
25176 idev = __in6_dev_get(dev);
25179 diff -NurpP --minimal linux-3.9.4/net/ipv6/af_inet6.c linux-3.9.4-vs2.3.6.2/net/ipv6/af_inet6.c
25180 --- linux-3.9.4/net/ipv6/af_inet6.c 2013-05-31 13:45:32.000000000 +0000
25181 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/af_inet6.c 2013-05-31 20:04:41.000000000 +0000
25183 #include <linux/netdevice.h>
25184 #include <linux/icmpv6.h>
25185 #include <linux/netfilter_ipv6.h>
25186 +#include <linux/vs_inet.h>
25187 +#include <linux/vs_inet6.h>
25189 #include <net/ip.h>
25190 #include <net/ipv6.h>
25191 @@ -160,10 +162,13 @@ lookup_protocol:
25195 + if ((protocol == IPPROTO_ICMPV6) &&
25196 + nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25198 if (sock->type == SOCK_RAW && !kern &&
25199 !ns_capable(net->user_ns, CAP_NET_RAW))
25200 goto out_rcu_unlock;
25203 sock->ops = answer->ops;
25204 answer_prot = answer->prot;
25205 answer_no_check = answer->no_check;
25206 @@ -263,6 +268,7 @@ int inet6_bind(struct socket *sock, stru
25207 struct inet_sock *inet = inet_sk(sk);
25208 struct ipv6_pinfo *np = inet6_sk(sk);
25209 struct net *net = sock_net(sk);
25210 + struct nx_v6_sock_addr nsa;
25212 unsigned short snum;
25214 @@ -278,6 +284,10 @@ int inet6_bind(struct socket *sock, stru
25215 if (addr->sin6_family != AF_INET6)
25216 return -EAFNOSUPPORT;
25218 + err = v6_map_sock_addr(inet, addr, &nsa);
25222 addr_type = ipv6_addr_type(&addr->sin6_addr);
25223 if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25225 @@ -309,6 +319,7 @@ int inet6_bind(struct socket *sock, stru
25226 /* Reproduce AF_INET checks to make the bindings consistent */
25227 v4addr = addr->sin6_addr.s6_addr32[3];
25228 chk_addr_ret = inet_addr_type(net, v4addr);
25230 if (!sysctl_ip_nonlocal_bind &&
25231 !(inet->freebind || inet->transparent) &&
25232 v4addr != htonl(INADDR_ANY) &&
25233 @@ -318,6 +329,10 @@ int inet6_bind(struct socket *sock, stru
25234 err = -EADDRNOTAVAIL;
25237 + if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25238 + err = -EADDRNOTAVAIL;
25242 if (addr_type != IPV6_ADDR_ANY) {
25243 struct net_device *dev = NULL;
25244 @@ -344,6 +359,11 @@ int inet6_bind(struct socket *sock, stru
25248 + if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25249 + err = -EADDRNOTAVAIL;
25253 /* ipv4 addr of the socket is invalid. Only the
25254 * unspecified and mapped address have a v4 equivalent.
25256 @@ -360,6 +380,9 @@ int inet6_bind(struct socket *sock, stru
25260 + /* what's that for? */
25261 + v6_set_sock_addr(inet, &nsa);
25263 inet->inet_rcv_saddr = v4addr;
25264 inet->inet_saddr = v4addr;
25266 @@ -461,9 +484,11 @@ int inet6_getname(struct socket *sock, s
25268 sin->sin6_port = inet->inet_dport;
25269 sin->sin6_addr = np->daddr;
25270 + /* FIXME: remap lback? */
25272 sin->sin6_flowinfo = np->flow_label;
25274 + /* FIXME: remap lback? */
25275 if (ipv6_addr_any(&np->rcv_saddr))
25276 sin->sin6_addr = np->saddr;
25278 diff -NurpP --minimal linux-3.9.4/net/ipv6/datagram.c linux-3.9.4-vs2.3.6.2/net/ipv6/datagram.c
25279 --- linux-3.9.4/net/ipv6/datagram.c 2013-05-31 13:45:32.000000000 +0000
25280 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/datagram.c 2013-05-31 17:17:54.000000000 +0000
25281 @@ -648,7 +648,7 @@ int ip6_datagram_send_ctl(struct net *ne
25284 if (fl6->flowi6_oif) {
25285 - dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25286 + dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25290 diff -NurpP --minimal linux-3.9.4/net/ipv6/fib6_rules.c linux-3.9.4-vs2.3.6.2/net/ipv6/fib6_rules.c
25291 --- linux-3.9.4/net/ipv6/fib6_rules.c 2013-02-19 13:58:58.000000000 +0000
25292 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/fib6_rules.c 2013-05-31 17:17:54.000000000 +0000
25293 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25294 ip6_dst_idev(&rt->dst)->dev,
25296 rt6_flags2srcprefs(flags),
25300 if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25302 diff -NurpP --minimal linux-3.9.4/net/ipv6/inet6_hashtables.c linux-3.9.4-vs2.3.6.2/net/ipv6/inet6_hashtables.c
25303 --- linux-3.9.4/net/ipv6/inet6_hashtables.c 2013-05-31 13:45:32.000000000 +0000
25304 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/inet6_hashtables.c 2013-05-31 17:17:54.000000000 +0000
25307 #include <linux/module.h>
25308 #include <linux/random.h>
25309 +#include <linux/vs_inet6.h>
25311 #include <net/inet_connection_sock.h>
25312 #include <net/inet_hashtables.h>
25313 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25314 unsigned int slot = hash & hashinfo->ehash_mask;
25315 struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25320 sk_nulls_for_each_rcu(sk, node, &head->chain) {
25321 @@ -97,7 +97,7 @@ begin:
25329 if (get_nulls_value(node) != slot)
25330 @@ -147,6 +147,9 @@ static inline int compute_score(struct s
25331 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25335 + if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25338 if (sk->sk_bound_dev_if) {
25339 if (sk->sk_bound_dev_if != dif)
25340 diff -NurpP --minimal linux-3.9.4/net/ipv6/ip6_output.c linux-3.9.4-vs2.3.6.2/net/ipv6/ip6_output.c
25341 --- linux-3.9.4/net/ipv6/ip6_output.c 2013-05-31 13:45:32.000000000 +0000
25342 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/ip6_output.c 2013-05-31 17:17:54.000000000 +0000
25343 @@ -877,7 +877,8 @@ static int ip6_dst_lookup_tail(struct so
25344 struct rt6_info *rt = (struct rt6_info *) *dst;
25345 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25346 sk ? inet6_sk(sk)->srcprefs : 0,
25349 + sk ? sk->sk_nx_info : NULL);
25351 goto out_err_release;
25353 diff -NurpP --minimal linux-3.9.4/net/ipv6/ndisc.c linux-3.9.4-vs2.3.6.2/net/ipv6/ndisc.c
25354 --- linux-3.9.4/net/ipv6/ndisc.c 2013-05-31 13:45:32.000000000 +0000
25355 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/ndisc.c 2013-05-31 17:17:54.000000000 +0000
25356 @@ -485,7 +485,7 @@ static void ndisc_send_na(struct net_dev
25358 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25359 inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25363 src_addr = &tmpaddr;
25365 diff -NurpP --minimal linux-3.9.4/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.9.4-vs2.3.6.2/net/ipv6/netfilter/ip6t_MASQUERADE.c
25366 --- linux-3.9.4/net/ipv6/netfilter/ip6t_MASQUERADE.c 2012-12-11 03:30:57.000000000 +0000
25367 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/netfilter/ip6t_MASQUERADE.c 2013-05-31 17:17:54.000000000 +0000
25368 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
25369 ctinfo == IP_CT_RELATED_REPLY));
25371 if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
25372 - &ipv6_hdr(skb)->daddr, 0, &src) < 0)
25373 + &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
25376 nfct_nat(ct)->masq_index = par->out->ifindex;
25377 diff -NurpP --minimal linux-3.9.4/net/ipv6/raw.c linux-3.9.4-vs2.3.6.2/net/ipv6/raw.c
25378 --- linux-3.9.4/net/ipv6/raw.c 2013-05-31 13:45:32.000000000 +0000
25379 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/raw.c 2013-05-31 17:17:54.000000000 +0000
25381 #include <linux/icmpv6.h>
25382 #include <linux/netfilter.h>
25383 #include <linux/netfilter_ipv6.h>
25384 +#include <linux/vs_inet6.h>
25385 #include <linux/skbuff.h>
25386 #include <linux/compat.h>
25387 #include <asm/uaccess.h>
25388 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
25392 + if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25393 + err = -EADDRNOTAVAIL;
25399 /* ipv4 addr of the socket is invalid. Only the
25400 * unspecified and mapped address have a v4 equivalent.
25402 diff -NurpP --minimal linux-3.9.4/net/ipv6/route.c linux-3.9.4-vs2.3.6.2/net/ipv6/route.c
25403 --- linux-3.9.4/net/ipv6/route.c 2013-05-31 13:45:32.000000000 +0000
25404 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/route.c 2013-05-31 18:10:38.000000000 +0000
25406 #include <net/netevent.h>
25407 #include <net/netlink.h>
25408 #include <net/nexthop.h>
25409 +#include <linux/vs_inet6.h>
25411 #include <asm/uaccess.h>
25413 @@ -2079,15 +2080,17 @@ int ip6_route_get_saddr(struct net *net,
25414 struct rt6_info *rt,
25415 const struct in6_addr *daddr,
25416 unsigned int prefs,
25417 - struct in6_addr *saddr)
25418 + struct in6_addr *saddr,
25419 + struct nx_info *nxi)
25421 struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25423 - if (rt->rt6i_prefsrc.plen)
25424 + if (rt->rt6i_prefsrc.plen && (!nxi ||
25425 + v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25426 *saddr = rt->rt6i_prefsrc.addr;
25428 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25429 - daddr, prefs, saddr);
25430 + daddr, prefs, saddr, nxi);
25434 @@ -2507,7 +2510,8 @@ static int rt6_fill_node(struct net *net
25435 goto nla_put_failure;
25437 struct in6_addr saddr_buf;
25438 - if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25439 + if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25440 + (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25441 nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25442 goto nla_put_failure;
25444 @@ -2719,6 +2723,7 @@ static int rt6_info_route(struct rt6_inf
25446 struct seq_file *m = p_arg;
25448 + /* FIXME: check for network context? */
25449 seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25451 #ifdef CONFIG_IPV6_SUBTREES
25452 diff -NurpP --minimal linux-3.9.4/net/ipv6/tcp_ipv6.c linux-3.9.4-vs2.3.6.2/net/ipv6/tcp_ipv6.c
25453 --- linux-3.9.4/net/ipv6/tcp_ipv6.c 2013-05-31 14:22:27.000000000 +0000
25454 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/tcp_ipv6.c 2013-05-31 17:17:54.000000000 +0000
25457 #include <linux/crypto.h>
25458 #include <linux/scatterlist.h>
25459 +#include <linux/vs_inet6.h>
25461 static void tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25462 static void tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25463 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
25464 * connect() to INADDR_ANY means loopback (BSD'ism).
25467 - if(ipv6_addr_any(&usin->sin6_addr))
25468 - usin->sin6_addr.s6_addr[15] = 0x1;
25469 + if(ipv6_addr_any(&usin->sin6_addr)) {
25470 + struct nx_info *nxi = sk->sk_nx_info;
25472 + if (nxi && nx_info_has_v6(nxi))
25473 + /* FIXME: remap lback? */
25474 + usin->sin6_addr = nxi->v6.ip;
25476 + usin->sin6_addr.s6_addr[15] = 0x1;
25479 addr_type = ipv6_addr_type(&usin->sin6_addr);
25481 diff -NurpP --minimal linux-3.9.4/net/ipv6/udp.c linux-3.9.4-vs2.3.6.2/net/ipv6/udp.c
25482 --- linux-3.9.4/net/ipv6/udp.c 2013-05-31 14:22:27.000000000 +0000
25483 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/udp.c 2013-05-31 18:16:01.000000000 +0000
25484 @@ -46,42 +46,68 @@
25485 #include <net/ip6_checksum.h>
25486 #include <net/xfrm.h>
25487 #include <net/inet6_hashtables.h>
25488 +#include <linux/vs_inet6.h>
25490 #include <linux/proc_fs.h>
25491 #include <linux/seq_file.h>
25492 #include <trace/events/skb.h>
25493 #include "udp_impl.h"
25495 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25496 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25498 - const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25499 + const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25500 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25501 - __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25502 + __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25503 __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25504 - int sk_ipv6only = ipv6_only_sock(sk);
25505 + int sk1_ipv6only = ipv6_only_sock(sk1);
25506 int sk2_ipv6only = inet_v6_ipv6only(sk2);
25507 - int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25508 + int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25509 int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25511 /* if both are mapped, treat as IPv4 */
25512 - if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25513 - return (!sk2_ipv6only &&
25514 + if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25515 + if (!sk2_ipv6only &&
25516 (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25517 - sk1_rcv_saddr == sk2_rcv_saddr));
25518 + sk1_rcv_saddr == sk2_rcv_saddr))
25524 if (addr_type2 == IPV6_ADDR_ANY &&
25525 !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25529 if (addr_type == IPV6_ADDR_ANY &&
25530 - !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25532 + !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25535 if (sk2_rcv_saddr6 &&
25536 - ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25538 + ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25544 + if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25545 + return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25546 + if (!sk2_rcv_saddr)
25547 + return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25548 + if (!sk1_rcv_saddr)
25549 + return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25552 + if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25553 + return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25554 + else if (addr_type2 == IPV6_ADDR_ANY)
25555 + return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25556 + else if (addr_type == IPV6_ADDR_ANY) {
25557 + if (addr_type2 == IPV6_ADDR_MAPPED)
25558 + return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25560 + return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25565 static unsigned int udp6_portaddr_hash(struct net *net,
25566 @@ -145,6 +171,10 @@ static inline int compute_score(struct s
25567 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25571 + /* block non nx_info ips */
25572 + if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25575 if (!ipv6_addr_any(&np->daddr)) {
25576 if (!ipv6_addr_equal(&np->daddr, saddr))
25577 diff -NurpP --minimal linux-3.9.4/net/ipv6/xfrm6_policy.c linux-3.9.4-vs2.3.6.2/net/ipv6/xfrm6_policy.c
25578 --- linux-3.9.4/net/ipv6/xfrm6_policy.c 2013-05-31 14:22:27.000000000 +0000
25579 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/xfrm6_policy.c 2013-05-31 17:17:54.000000000 +0000
25580 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25581 dev = ip6_dst_idev(dst)->dev;
25582 ipv6_dev_get_saddr(dev_net(dev), dev,
25583 (struct in6_addr *)&daddr->a6, 0,
25584 - (struct in6_addr *)&saddr->a6);
25585 + (struct in6_addr *)&saddr->a6, NULL);
25589 diff -NurpP --minimal linux-3.9.4/net/netfilter/ipvs/ip_vs_xmit.c linux-3.9.4-vs2.3.6.2/net/netfilter/ipvs/ip_vs_xmit.c
25590 --- linux-3.9.4/net/netfilter/ipvs/ip_vs_xmit.c 2013-02-19 13:58:59.000000000 +0000
25591 +++ linux-3.9.4-vs2.3.6.2/net/netfilter/ipvs/ip_vs_xmit.c 2013-05-31 17:17:54.000000000 +0000
25592 @@ -273,7 +273,7 @@ __ip_vs_route_output_v6(struct net *net,
25594 if (ipv6_addr_any(&fl6.saddr) &&
25595 ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25596 - &fl6.daddr, 0, &fl6.saddr) < 0)
25597 + &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25600 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25601 diff -NurpP --minimal linux-3.9.4/net/netlink/af_netlink.c linux-3.9.4-vs2.3.6.2/net/netlink/af_netlink.c
25602 --- linux-3.9.4/net/netlink/af_netlink.c 2013-05-31 13:45:33.000000000 +0000
25603 +++ linux-3.9.4-vs2.3.6.2/net/netlink/af_netlink.c 2013-05-31 17:17:54.000000000 +0000
25605 #include <linux/types.h>
25606 #include <linux/audit.h>
25607 #include <linux/mutex.h>
25608 +#include <linux/vs_context.h>
25609 +#include <linux/vs_network.h>
25610 +#include <linux/vs_limit.h>
25612 #include <net/net_namespace.h>
25613 #include <net/sock.h>
25614 @@ -1976,6 +1979,8 @@ static struct sock *netlink_seq_socket_i
25615 sk_for_each(s, &hash->table[j]) {
25616 if (sock_net(s) != seq_file_net(seq))
25618 + if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25622 iter->hash_idx = j;
25623 @@ -2010,7 +2015,8 @@ static void *netlink_seq_next(struct seq
25627 - } while (s && sock_net(s) != seq_file_net(seq));
25628 + } while (s && (sock_net(s) != seq_file_net(seq) ||
25629 + !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25633 @@ -2022,7 +2028,8 @@ static void *netlink_seq_next(struct seq
25635 for (; j <= hash->mask; j++) {
25636 s = sk_head(&hash->table[j]);
25637 - while (s && sock_net(s) != seq_file_net(seq))
25638 + while (s && (sock_net(s) != seq_file_net(seq) ||
25639 + !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25643 diff -NurpP --minimal linux-3.9.4/net/socket.c linux-3.9.4-vs2.3.6.2/net/socket.c
25644 --- linux-3.9.4/net/socket.c 2013-05-31 13:45:33.000000000 +0000
25645 +++ linux-3.9.4-vs2.3.6.2/net/socket.c 2013-05-31 17:17:54.000000000 +0000
25648 #include <net/sock.h>
25649 #include <linux/netfilter.h>
25650 +#include <linux/vs_base.h>
25651 +#include <linux/vs_socket.h>
25652 +#include <linux/vs_inet.h>
25653 +#include <linux/vs_inet6.h>
25655 #include <linux/if_tun.h>
25656 #include <linux/ipv6_route.h>
25657 @@ -617,13 +621,29 @@ static inline int __sock_sendmsg_nosec(s
25658 struct msghdr *msg, size_t size)
25660 struct sock_iocb *si = kiocb_to_siocb(iocb);
25668 - return sock->ops->sendmsg(iocb, sock, msg, size);
25669 + len = sock->ops->sendmsg(iocb, sock, msg, size);
25672 + vx_sock_send(sock->sk, size);
25674 + vx_sock_fail(sock->sk, size);
25676 + vxdprintk(VXD_CBIT(net, 7),
25677 + "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25679 + (sock->sk)?sock->sk->sk_nx_info:0,
25680 + (sock->sk)?sock->sk->sk_vx_info:0,
25681 + (sock->sk)?sock->sk->sk_xid:0,
25682 + (sock->sk)?sock->sk->sk_nid:0,
25683 + (unsigned int)size, len);
25687 static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25688 @@ -779,6 +799,7 @@ static inline int __sock_recvmsg_nosec(s
25689 struct msghdr *msg, size_t size, int flags)
25691 struct sock_iocb *si = kiocb_to_siocb(iocb);
25696 @@ -786,7 +807,18 @@ static inline int __sock_recvmsg_nosec(s
25700 - return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25701 + len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25702 + if ((len >= 0) && sock->sk)
25703 + vx_sock_recv(sock->sk, len);
25704 + vxdprintk(VXD_CBIT(net, 7),
25705 + "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25707 + (sock->sk)?sock->sk->sk_nx_info:0,
25708 + (sock->sk)?sock->sk->sk_vx_info:0,
25709 + (sock->sk)?sock->sk->sk_xid:0,
25710 + (sock->sk)?sock->sk->sk_nid:0,
25711 + (unsigned int)size, len);
25715 static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25716 @@ -1269,6 +1301,13 @@ int __sock_create(struct net *net, int f
25717 if (type < 0 || type >= SOCK_MAX)
25720 + if (!nx_check(0, VS_ADMIN)) {
25721 + if (family == PF_INET && !current_nx_info_has_v4())
25722 + return -EAFNOSUPPORT;
25723 + if (family == PF_INET6 && !current_nx_info_has_v6())
25724 + return -EAFNOSUPPORT;
25729 This uglymoron is moved from INET layer to here to avoid
25730 @@ -1403,6 +1442,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25734 + set_bit(SOCK_USER_SOCKET, &sock->flags);
25735 retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25738 @@ -1444,10 +1484,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25739 err = sock_create(family, type, protocol, &sock1);
25742 + set_bit(SOCK_USER_SOCKET, &sock1->flags);
25744 err = sock_create(family, type, protocol, &sock2);
25746 goto out_release_1;
25747 + set_bit(SOCK_USER_SOCKET, &sock2->flags);
25749 err = sock1->ops->socketpair(sock1, sock2);
25751 diff -NurpP --minimal linux-3.9.4/net/sunrpc/auth.c linux-3.9.4-vs2.3.6.2/net/sunrpc/auth.c
25752 --- linux-3.9.4/net/sunrpc/auth.c 2013-05-31 13:45:33.000000000 +0000
25753 +++ linux-3.9.4-vs2.3.6.2/net/sunrpc/auth.c 2013-05-31 18:01:00.000000000 +0000
25755 #include <linux/sunrpc/clnt.h>
25756 #include <linux/sunrpc/gss_api.h>
25757 #include <linux/spinlock.h>
25758 +#include <linux/vs_tag.h>
25761 # define RPCDBG_FACILITY RPCDBG_AUTH
25762 @@ -480,6 +481,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25763 memset(&acred, 0, sizeof(acred));
25764 acred.uid = cred->fsuid;
25765 acred.gid = cred->fsgid;
25766 + acred.tag = dx_current_tag();
25767 acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25769 ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25770 @@ -520,6 +522,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25771 struct auth_cred acred = {
25772 .uid = GLOBAL_ROOT_UID,
25773 .gid = GLOBAL_ROOT_GID,
25774 + .tag = dx_current_tag(),
25777 dprintk("RPC: %5u looking up %s cred\n",
25778 diff -NurpP --minimal linux-3.9.4/net/sunrpc/auth_unix.c linux-3.9.4-vs2.3.6.2/net/sunrpc/auth_unix.c
25779 --- linux-3.9.4/net/sunrpc/auth_unix.c 2013-05-31 13:45:33.000000000 +0000
25780 +++ linux-3.9.4-vs2.3.6.2/net/sunrpc/auth_unix.c 2013-05-31 18:05:54.000000000 +0000
25781 @@ -13,11 +13,13 @@
25782 #include <linux/sunrpc/clnt.h>
25783 #include <linux/sunrpc/auth.h>
25784 #include <linux/user_namespace.h>
25785 +#include <linux/vs_tag.h>
25787 #define NFS_NGROUPS 16
25790 struct rpc_cred uc_base;
25793 kgid_t uc_gids[NFS_NGROUPS];
25795 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25796 groups = NFS_NGROUPS;
25798 cred->uc_gid = acred->gid;
25799 + cred->uc_tag = acred->tag;
25800 for (i = 0; i < groups; i++)
25801 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25802 if (i < NFS_NGROUPS)
25803 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25807 - if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25808 + if (!uid_eq(cred->uc_uid, acred->uid) ||
25809 + !gid_eq(cred->uc_gid, acred->gid) ||
25810 + !tag_eq(cred->uc_tag, acred->tag))
25813 if (acred->group_info != NULL)
25814 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25815 struct rpc_clnt *clnt = task->tk_client;
25816 struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25817 __be32 *base, *hold;
25821 *p++ = htonl(RPC_AUTH_UNIX);
25823 @@ -157,8 +162,13 @@ unx_marshal(struct rpc_task *task, __be3
25825 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25827 - *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25828 - *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25829 + tag = task->tk_client->cl_tag;
25830 + *p++ = htonl((u32) TAGINO_UID(tag,
25831 + from_kuid(&init_user_ns, cred->uc_uid),
25832 + from_ktag(&init_user_ns, cred->uc_tag)));
25833 + *p++ = htonl((u32) TAGINO_GID(tag,
25834 + from_kgid(&init_user_ns, cred->uc_gid),
25835 + from_ktag(&init_user_ns, cred->uc_tag)));
25837 for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25838 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25839 diff -NurpP --minimal linux-3.9.4/net/sunrpc/clnt.c linux-3.9.4-vs2.3.6.2/net/sunrpc/clnt.c
25840 --- linux-3.9.4/net/sunrpc/clnt.c 2013-05-31 13:45:33.000000000 +0000
25841 +++ linux-3.9.4-vs2.3.6.2/net/sunrpc/clnt.c 2013-05-31 17:17:54.000000000 +0000
25843 #include <linux/in6.h>
25844 #include <linux/un.h>
25845 #include <linux/rcupdate.h>
25846 +#include <linux/vs_cvirt.h>
25848 #include <linux/sunrpc/clnt.h>
25849 #include <linux/sunrpc/addr.h>
25850 @@ -482,6 +483,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25851 if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25852 clnt->cl_chatty = 1;
25854 + /* TODO: handle RPC_CLNT_CREATE_TAGGED
25855 + if (args->flags & RPC_CLNT_CREATE_TAGGED)
25856 + clnt->cl_tag = 1; */
25859 EXPORT_SYMBOL_GPL(rpc_create);
25860 diff -NurpP --minimal linux-3.9.4/net/unix/af_unix.c linux-3.9.4-vs2.3.6.2/net/unix/af_unix.c
25861 --- linux-3.9.4/net/unix/af_unix.c 2013-05-31 13:45:33.000000000 +0000
25862 +++ linux-3.9.4-vs2.3.6.2/net/unix/af_unix.c 2013-05-31 17:17:54.000000000 +0000
25863 @@ -114,6 +114,8 @@
25864 #include <linux/mount.h>
25865 #include <net/checksum.h>
25866 #include <linux/security.h>
25867 +#include <linux/vs_context.h>
25868 +#include <linux/vs_limit.h>
25870 struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25871 EXPORT_SYMBOL_GPL(unix_socket_table);
25872 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25873 if (!net_eq(sock_net(s), net))
25876 + if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25878 if (u->addr->len == len &&
25879 !memcmp(u->addr->name, sunname, len))
25881 @@ -2256,6 +2260,8 @@ static struct sock *unix_from_bucket(str
25882 for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25883 if (sock_net(sk) != seq_file_net(seq))
25885 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25887 if (++count == offset)
25890 @@ -2273,6 +2279,8 @@ static struct sock *unix_next_socket(str
25894 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25896 if (sock_net(sk) == seq_file_net(seq))
25899 diff -NurpP --minimal linux-3.9.4/scripts/checksyscalls.sh linux-3.9.4-vs2.3.6.2/scripts/checksyscalls.sh
25900 --- linux-3.9.4/scripts/checksyscalls.sh 2012-12-11 03:30:57.000000000 +0000
25901 +++ linux-3.9.4-vs2.3.6.2/scripts/checksyscalls.sh 2013-05-31 14:47:11.000000000 +0000
25902 @@ -193,7 +193,6 @@ cat << EOF
25903 #define __IGNORE_afs_syscall
25904 #define __IGNORE_getpmsg
25905 #define __IGNORE_putpmsg
25906 -#define __IGNORE_vserver
25910 diff -NurpP --minimal linux-3.9.4/security/commoncap.c linux-3.9.4-vs2.3.6.2/security/commoncap.c
25911 --- linux-3.9.4/security/commoncap.c 2013-05-31 13:45:34.000000000 +0000
25912 +++ linux-3.9.4-vs2.3.6.2/security/commoncap.c 2013-05-31 15:07:02.000000000 +0000
25913 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25914 int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25915 int cap, int audit)
25917 + struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25918 struct user_namespace *ns = targ_ns;
25920 /* See if cred has the capability in the target user namespace
25921 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25924 /* Do we have the necessary capabilities? */
25925 - if (ns == cred->user_ns)
25926 - return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25927 + if (ns == cred->user_ns) {
25928 + if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25929 + cap_raised(cred->cap_effective, cap))
25931 + return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25934 /* Have we tried all of the parent namespaces? */
25935 if (ns == &init_user_ns)
25936 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25938 if (!strncmp(name, XATTR_SECURITY_PREFIX,
25939 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25940 - !capable(CAP_SYS_ADMIN))
25941 + !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25945 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25947 if (!strncmp(name, XATTR_SECURITY_PREFIX,
25948 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25949 - !capable(CAP_SYS_ADMIN))
25950 + !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25954 diff -NurpP --minimal linux-3.9.4/security/selinux/hooks.c linux-3.9.4-vs2.3.6.2/security/selinux/hooks.c
25955 --- linux-3.9.4/security/selinux/hooks.c 2013-05-31 13:45:34.000000000 +0000
25956 +++ linux-3.9.4-vs2.3.6.2/security/selinux/hooks.c 2013-05-31 14:47:11.000000000 +0000
25958 #include <linux/dccp.h>
25959 #include <linux/quota.h>
25960 #include <linux/un.h> /* for Unix socket types */
25961 -#include <net/af_unix.h> /* for Unix socket types */
25962 #include <linux/parser.h>
25963 #include <linux/nfs_mount.h>
25964 #include <net/ipv6.h>