1 diff -NurpP --minimal linux-3.9.4/Documentation/vserver/debug.txt linux-3.9.4-vs2.3.6.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/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/um/include/shared/kern_constants.h linux-3.9.4-vs2.3.6.1/arch/um/include/shared/kern_constants.h
742 --- linux-3.9.4/arch/um/include/shared/kern_constants.h 1970-01-01 00:00:00.000000000 +0000
743 +++ linux-3.9.4-vs2.3.6.1/arch/um/include/shared/kern_constants.h 2013-05-31 14:47:11.000000000 +0000
745 +#include "../../../../include/generated/asm-offsets.h"
746 diff -NurpP --minimal linux-3.9.4/arch/um/include/shared/user_constants.h linux-3.9.4-vs2.3.6.1/arch/um/include/shared/user_constants.h
747 --- linux-3.9.4/arch/um/include/shared/user_constants.h 1970-01-01 00:00:00.000000000 +0000
748 +++ linux-3.9.4-vs2.3.6.1/arch/um/include/shared/user_constants.h 2013-05-31 14:47:11.000000000 +0000
753 + * This file was generated by arch/um/Makefile
757 +#define HOST_SC_CR2 176 /* offsetof(struct sigcontext, cr2) # */
758 +#define HOST_SC_ERR 152 /* offsetof(struct sigcontext, err) # */
759 +#define HOST_SC_TRAPNO 160 /* offsetof(struct sigcontext, trapno) # */
760 +#define HOST_FP_SIZE 64 /* sizeof(struct _fpstate) / sizeof(unsigned long) # */
761 +#define HOST_RBX 5 /* RBX # */
762 +#define HOST_RCX 11 /* RCX # */
763 +#define HOST_RDI 14 /* RDI # */
764 +#define HOST_RSI 13 /* RSI # */
765 +#define HOST_RDX 12 /* RDX # */
766 +#define HOST_RBP 4 /* RBP # */
767 +#define HOST_RAX 10 /* RAX # */
768 +#define HOST_R8 9 /* R8 # */
769 +#define HOST_R9 8 /* R9 # */
770 +#define HOST_R10 7 /* R10 # */
771 +#define HOST_R11 6 /* R11 # */
772 +#define HOST_R12 3 /* R12 # */
773 +#define HOST_R13 2 /* R13 # */
774 +#define HOST_R14 1 /* R14 # */
775 +#define HOST_R15 0 /* R15 # */
776 +#define HOST_ORIG_RAX 15 /* ORIG_RAX # */
777 +#define HOST_CS 17 /* CS # */
778 +#define HOST_SS 20 /* SS # */
779 +#define HOST_EFLAGS 18 /* EFLAGS # */
780 +#define HOST_IP 16 /* RIP # */
781 +#define HOST_SP 19 /* RSP # */
782 +#define UM_FRAME_SIZE 216 /* sizeof(struct user_regs_struct) # */
783 +#define UM_POLLIN 1 /* POLLIN # */
784 +#define UM_POLLPRI 2 /* POLLPRI # */
785 +#define UM_POLLOUT 4 /* POLLOUT # */
786 +#define UM_PROT_READ 1 /* PROT_READ # */
787 +#define UM_PROT_WRITE 2 /* PROT_WRITE # */
788 +#define UM_PROT_EXEC 4 /* PROT_EXEC # */
790 diff -NurpP --minimal linux-3.9.4/arch/x86/Kconfig linux-3.9.4-vs2.3.6.1/arch/x86/Kconfig
791 --- linux-3.9.4/arch/x86/Kconfig 2013-05-31 14:22:26.000000000 +0000
792 +++ linux-3.9.4-vs2.3.6.1/arch/x86/Kconfig 2013-05-31 14:47:11.000000000 +0000
793 @@ -2341,6 +2341,8 @@ source "fs/Kconfig"
795 source "arch/x86/Kconfig.debug"
797 +source "kernel/vserver/Kconfig"
799 source "security/Kconfig"
801 source "crypto/Kconfig"
802 diff -NurpP --minimal linux-3.9.4/arch/x86/syscalls/syscall_32.tbl linux-3.9.4-vs2.3.6.1/arch/x86/syscalls/syscall_32.tbl
803 --- linux-3.9.4/arch/x86/syscalls/syscall_32.tbl 2013-05-31 13:44:50.000000000 +0000
804 +++ linux-3.9.4-vs2.3.6.1/arch/x86/syscalls/syscall_32.tbl 2013-05-31 14:47:11.000000000 +0000
806 270 i386 tgkill sys_tgkill
807 271 i386 utimes sys_utimes compat_sys_utimes
808 272 i386 fadvise64_64 sys_fadvise64_64 sys32_fadvise64_64
810 +273 i386 vserver sys_vserver sys32_vserver
811 274 i386 mbind sys_mbind
812 275 i386 get_mempolicy sys_get_mempolicy compat_sys_get_mempolicy
813 276 i386 set_mempolicy sys_set_mempolicy
814 diff -NurpP --minimal linux-3.9.4/arch/x86/syscalls/syscall_64.tbl linux-3.9.4-vs2.3.6.1/arch/x86/syscalls/syscall_64.tbl
815 --- linux-3.9.4/arch/x86/syscalls/syscall_64.tbl 2013-05-31 13:44:50.000000000 +0000
816 +++ linux-3.9.4-vs2.3.6.1/arch/x86/syscalls/syscall_64.tbl 2013-05-31 14:47:11.000000000 +0000
818 233 common epoll_ctl sys_epoll_ctl
819 234 common tgkill sys_tgkill
820 235 common utimes sys_utimes
822 +236 64 vserver sys_vserver
823 237 common mbind sys_mbind
824 238 common set_mempolicy sys_set_mempolicy
825 239 common get_mempolicy sys_get_mempolicy
826 diff -NurpP --minimal linux-3.9.4/drivers/block/Kconfig linux-3.9.4-vs2.3.6.1/drivers/block/Kconfig
827 --- linux-3.9.4/drivers/block/Kconfig 2013-05-31 13:44:51.000000000 +0000
828 +++ linux-3.9.4-vs2.3.6.1/drivers/block/Kconfig 2013-05-31 14:47:11.000000000 +0000
829 @@ -278,6 +278,13 @@ config BLK_DEV_CRYPTOLOOP
831 source "drivers/block/drbd/Kconfig"
833 +config BLK_DEV_VROOT
834 + tristate "Virtual Root device support"
835 + depends on QUOTACTL
837 + Saying Y here will allow you to use quota/fs ioctls on a shared
838 + partition within a virtual server without compromising security.
841 tristate "Network block device support"
843 diff -NurpP --minimal linux-3.9.4/drivers/block/Makefile linux-3.9.4-vs2.3.6.1/drivers/block/Makefile
844 --- linux-3.9.4/drivers/block/Makefile 2013-05-31 13:44:51.000000000 +0000
845 +++ linux-3.9.4-vs2.3.6.1/drivers/block/Makefile 2013-05-31 14:47:11.000000000 +0000
846 @@ -33,6 +33,7 @@ obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
847 obj-$(CONFIG_VIODASD) += viodasd.o
848 obj-$(CONFIG_BLK_DEV_SX8) += sx8.o
849 obj-$(CONFIG_BLK_DEV_HD) += hd.o
850 +obj-$(CONFIG_BLK_DEV_VROOT) += vroot.o
852 obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o
853 obj-$(CONFIG_XEN_BLKDEV_BACKEND) += xen-blkback/
854 diff -NurpP --minimal linux-3.9.4/drivers/block/loop.c linux-3.9.4-vs2.3.6.1/drivers/block/loop.c
855 --- linux-3.9.4/drivers/block/loop.c 2013-05-31 13:44:51.000000000 +0000
856 +++ linux-3.9.4-vs2.3.6.1/drivers/block/loop.c 2013-05-31 14:47:11.000000000 +0000
858 #include <linux/sysfs.h>
859 #include <linux/miscdevice.h>
860 #include <linux/falloc.h>
861 +#include <linux/vs_context.h>
863 #include <asm/uaccess.h>
865 @@ -882,6 +883,7 @@ static int loop_set_fd(struct loop_devic
866 lo->lo_blocksize = lo_blocksize;
867 lo->lo_device = bdev;
868 lo->lo_flags = lo_flags;
869 + lo->lo_xid = vx_current_xid();
870 lo->lo_backing_file = file;
871 lo->transfer = transfer_none;
873 @@ -1033,6 +1035,7 @@ static int loop_clr_fd(struct loop_devic
874 lo->lo_sizelimit = 0;
875 lo->lo_encrypt_key_size = 0;
876 lo->lo_thread = NULL;
878 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
879 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
880 memset(lo->lo_file_name, 0, LO_NAME_SIZE);
881 @@ -1076,7 +1079,7 @@ loop_set_status(struct loop_device *lo,
883 if (lo->lo_encrypt_key_size &&
884 !uid_eq(lo->lo_key_owner, uid) &&
885 - !capable(CAP_SYS_ADMIN))
886 + !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
888 if (lo->lo_state != Lo_bound)
890 @@ -1166,7 +1169,8 @@ loop_get_status(struct loop_device *lo,
891 memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
892 info->lo_encrypt_type =
893 lo->lo_encryption ? lo->lo_encryption->number : 0;
894 - if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
895 + if (lo->lo_encrypt_key_size &&
896 + vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
897 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
898 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
899 lo->lo_encrypt_key_size);
900 @@ -1508,6 +1512,11 @@ static int lo_open(struct block_device *
904 + if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
909 mutex_lock(&lo->lo_ctl_mutex);
911 mutex_unlock(&lo->lo_ctl_mutex);
912 diff -NurpP --minimal linux-3.9.4/drivers/block/vroot.c linux-3.9.4-vs2.3.6.1/drivers/block/vroot.c
913 --- linux-3.9.4/drivers/block/vroot.c 1970-01-01 00:00:00.000000000 +0000
914 +++ linux-3.9.4-vs2.3.6.1/drivers/block/vroot.c 2013-05-31 14:47:11.000000000 +0000
917 + * linux/drivers/block/vroot.c
919 + * written by Herbert Pötzl, 9/11/2002
920 + * ported to 2.6.10 by Herbert Pötzl, 30/12/2004
922 + * based on the loop.c code by Theodore Ts'o.
924 + * Copyright (C) 2002-2007 by Herbert Pötzl.
925 + * Redistribution of this file is permitted under the
926 + * GNU General Public License.
930 +#include <linux/module.h>
931 +#include <linux/moduleparam.h>
932 +#include <linux/file.h>
933 +#include <linux/major.h>
934 +#include <linux/blkdev.h>
935 +#include <linux/slab.h>
937 +#include <linux/vroot.h>
938 +#include <linux/vs_context.h>
941 +static int max_vroot = 8;
943 +static struct vroot_device *vroot_dev;
944 +static struct gendisk **disks;
947 +static int vroot_set_dev(
948 + struct vroot_device *vr,
949 + struct block_device *bdev,
952 + struct block_device *real_bdev;
954 + struct inode *inode;
958 + if (vr->vr_state != Vr_unbound)
967 + inode = file->f_dentry->d_inode;
970 + if (S_ISBLK(inode->i_mode)) {
971 + real_bdev = inode->i_bdev;
972 + vr->vr_device = real_bdev;
973 + __iget(real_bdev->bd_inode);
977 + vxdprintk(VXD_CBIT(misc, 0),
978 + "vroot[%d]_set_dev: dev=" VXF_DEV,
979 + vr->vr_number, VXD_DEV(real_bdev));
981 + vr->vr_state = Vr_bound;
990 +static int vroot_clr_dev(
991 + struct vroot_device *vr,
992 + struct block_device *bdev)
994 + struct block_device *real_bdev;
996 + if (vr->vr_state != Vr_bound)
998 + if (vr->vr_refcnt > 1) /* we needed one fd for the ioctl */
1001 + real_bdev = vr->vr_device;
1003 + vxdprintk(VXD_CBIT(misc, 0),
1004 + "vroot[%d]_clr_dev: dev=" VXF_DEV,
1005 + vr->vr_number, VXD_DEV(real_bdev));
1008 + vr->vr_state = Vr_unbound;
1009 + vr->vr_device = NULL;
1014 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
1015 + unsigned int cmd, unsigned long arg)
1017 + struct vroot_device *vr = bdev->bd_disk->private_data;
1020 + down(&vr->vr_ctl_mutex);
1022 + case VROOT_SET_DEV:
1023 + err = vroot_set_dev(vr, bdev, arg);
1025 + case VROOT_CLR_DEV:
1026 + err = vroot_clr_dev(vr, bdev);
1032 + up(&vr->vr_ctl_mutex);
1036 +static int vr_open(struct block_device *bdev, fmode_t mode)
1038 + struct vroot_device *vr = bdev->bd_disk->private_data;
1040 + down(&vr->vr_ctl_mutex);
1042 + up(&vr->vr_ctl_mutex);
1046 +static int vr_release(struct gendisk *disk, fmode_t mode)
1048 + struct vroot_device *vr = disk->private_data;
1050 + down(&vr->vr_ctl_mutex);
1052 + up(&vr->vr_ctl_mutex);
1056 +static struct block_device_operations vr_fops = {
1057 + .owner = THIS_MODULE,
1059 + .release = vr_release,
1060 + .ioctl = vr_ioctl,
1063 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
1065 + printk("vroot_make_request %p, %p\n", q, bio);
1066 + bio_io_error(bio);
1069 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
1071 + struct inode *inode = bdev->bd_inode;
1072 + struct vroot_device *vr;
1073 + struct block_device *real_bdev;
1074 + int minor = iminor(inode);
1076 + vr = &vroot_dev[minor];
1077 + real_bdev = vr->vr_device;
1079 + vxdprintk(VXD_CBIT(misc, 0),
1080 + "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
1081 + vr->vr_number, VXD_DEV(real_bdev));
1083 + if (vr->vr_state != Vr_bound)
1084 + return ERR_PTR(-ENXIO);
1086 + __iget(real_bdev->bd_inode);
1093 + * And now the modules code and kernel interface.
1096 +module_param(max_vroot, int, 0);
1098 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1099 +MODULE_LICENSE("GPL");
1100 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1102 +MODULE_AUTHOR ("Herbert Pötzl");
1103 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1106 +int __init vroot_init(void)
1110 + if (max_vroot < 1 || max_vroot > 256) {
1111 + max_vroot = MAX_VROOT_DEFAULT;
1112 + printk(KERN_WARNING "vroot: invalid max_vroot "
1113 + "(must be between 1 and 256), "
1114 + "using default (%d)\n", max_vroot);
1117 + if (register_blkdev(VROOT_MAJOR, "vroot"))
1121 + vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1124 + memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1126 + disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1130 + for (i = 0; i < max_vroot; i++) {
1131 + disks[i] = alloc_disk(1);
1134 + disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1135 + if (!disks[i]->queue)
1137 + blk_queue_make_request(disks[i]->queue, vroot_make_request);
1140 + for (i = 0; i < max_vroot; i++) {
1141 + struct vroot_device *vr = &vroot_dev[i];
1142 + struct gendisk *disk = disks[i];
1144 + memset(vr, 0, sizeof(*vr));
1145 + sema_init(&vr->vr_ctl_mutex, 1);
1146 + vr->vr_number = i;
1147 + disk->major = VROOT_MAJOR;
1148 + disk->first_minor = i;
1149 + disk->fops = &vr_fops;
1150 + sprintf(disk->disk_name, "vroot%d", i);
1151 + disk->private_data = vr;
1154 + err = register_vroot_grb(&__vroot_get_real_bdev);
1158 + for (i = 0; i < max_vroot; i++)
1159 + add_disk(disks[i]);
1160 + printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1165 + put_disk(disks[i]);
1170 + unregister_blkdev(VROOT_MAJOR, "vroot");
1171 + printk(KERN_ERR "vroot: ran out of memory\n");
1175 +void vroot_exit(void)
1179 + if (unregister_vroot_grb(&__vroot_get_real_bdev))
1180 + printk(KERN_WARNING "vroot: cannot unregister grb\n");
1182 + for (i = 0; i < max_vroot; i++) {
1183 + del_gendisk(disks[i]);
1184 + put_disk(disks[i]);
1186 + unregister_blkdev(VROOT_MAJOR, "vroot");
1192 +module_init(vroot_init);
1193 +module_exit(vroot_exit);
1197 +static int __init max_vroot_setup(char *str)
1199 + max_vroot = simple_strtol(str, NULL, 0);
1203 +__setup("max_vroot=", max_vroot_setup);
1207 diff -NurpP --minimal linux-3.9.4/drivers/infiniband/Kconfig linux-3.9.4-vs2.3.6.1/drivers/infiniband/Kconfig
1208 --- linux-3.9.4/drivers/infiniband/Kconfig 2012-12-11 03:30:57.000000000 +0000
1209 +++ linux-3.9.4-vs2.3.6.1/drivers/infiniband/Kconfig 2013-05-31 14:47:11.000000000 +0000
1210 @@ -39,7 +39,7 @@ config INFINIBAND_USER_MEM
1211 config INFINIBAND_ADDR_TRANS
1214 - depends on !(INFINIBAND = y && IPV6 = m)
1215 + depends on !(INFINIBAND = y && IPV6 = y)
1218 source "drivers/infiniband/hw/mthca/Kconfig"
1219 diff -NurpP --minimal linux-3.9.4/drivers/infiniband/core/addr.c linux-3.9.4-vs2.3.6.1/drivers/infiniband/core/addr.c
1220 --- linux-3.9.4/drivers/infiniband/core/addr.c 2012-12-11 03:30:57.000000000 +0000
1221 +++ linux-3.9.4-vs2.3.6.1/drivers/infiniband/core/addr.c 2013-05-31 14:47:11.000000000 +0000
1222 @@ -261,7 +261,7 @@ static int addr6_resolve(struct sockaddr
1224 if (ipv6_addr_any(&fl6.saddr)) {
1225 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1226 - &fl6.daddr, 0, &fl6.saddr);
1227 + &fl6.daddr, 0, &fl6.saddr, NULL);
1231 diff -NurpP --minimal linux-3.9.4/drivers/md/dm-ioctl.c linux-3.9.4-vs2.3.6.1/drivers/md/dm-ioctl.c
1232 --- linux-3.9.4/drivers/md/dm-ioctl.c 2013-05-31 13:44:59.000000000 +0000
1233 +++ linux-3.9.4-vs2.3.6.1/drivers/md/dm-ioctl.c 2013-05-31 14:47:11.000000000 +0000
1235 #include <linux/dm-ioctl.h>
1236 #include <linux/hdreg.h>
1237 #include <linux/compat.h>
1238 +#include <linux/vs_context.h>
1240 #include <asm/uaccess.h>
1242 @@ -106,7 +107,8 @@ static struct hash_cell *__get_name_cell
1243 unsigned int h = hash_str(str);
1245 list_for_each_entry (hc, _name_buckets + h, name_list)
1246 - if (!strcmp(hc->name, str)) {
1247 + if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1248 + !strcmp(hc->name, str)) {
1252 @@ -120,7 +122,8 @@ static struct hash_cell *__get_uuid_cell
1253 unsigned int h = hash_str(str);
1255 list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1256 - if (!strcmp(hc->uuid, str)) {
1257 + if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1258 + !strcmp(hc->uuid, str)) {
1262 @@ -131,13 +134,15 @@ static struct hash_cell *__get_uuid_cell
1263 static struct hash_cell *__get_dev_cell(uint64_t dev)
1265 struct mapped_device *md;
1266 - struct hash_cell *hc;
1267 + struct hash_cell *hc = NULL;
1269 md = dm_get_md(huge_decode_dev(dev));
1273 - hc = dm_get_mdptr(md);
1274 + if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1275 + hc = dm_get_mdptr(md);
1280 @@ -445,6 +450,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1282 static int remove_all(struct dm_ioctl *param, size_t param_size)
1284 + if (!vx_check(0, VS_ADMIN))
1287 dm_hash_remove_all(1);
1288 param->data_size = 0;
1290 @@ -492,6 +500,8 @@ static int list_devices(struct dm_ioctl
1292 for (i = 0; i < NUM_BUCKETS; i++) {
1293 list_for_each_entry (hc, _name_buckets + i, name_list) {
1294 + if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1296 needed += sizeof(struct dm_name_list);
1297 needed += strlen(hc->name) + 1;
1298 needed += ALIGN_MASK;
1299 @@ -515,6 +525,8 @@ static int list_devices(struct dm_ioctl
1301 for (i = 0; i < NUM_BUCKETS; i++) {
1302 list_for_each_entry (hc, _name_buckets + i, name_list) {
1303 + if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1306 old_nl->next = (uint32_t) ((void *) nl -
1308 @@ -1722,8 +1734,8 @@ static int ctl_ioctl(uint command, struc
1309 size_t input_param_size;
1310 struct dm_ioctl param_kernel;
1312 - /* only root can play with this */
1313 - if (!capable(CAP_SYS_ADMIN))
1314 + /* only root and certain contexts can play with this */
1315 + if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1318 if (_IOC_TYPE(command) != DM_IOCTL)
1319 diff -NurpP --minimal linux-3.9.4/drivers/md/dm.c linux-3.9.4-vs2.3.6.1/drivers/md/dm.c
1320 --- linux-3.9.4/drivers/md/dm.c 2013-05-31 13:44:59.000000000 +0000
1321 +++ linux-3.9.4-vs2.3.6.1/drivers/md/dm.c 2013-05-31 14:47:11.000000000 +0000
1323 #include <linux/idr.h>
1324 #include <linux/hdreg.h>
1325 #include <linux/delay.h>
1326 +#include <linux/vs_base.h>
1328 #include <trace/events/block.h>
1330 @@ -125,6 +126,7 @@ struct mapped_device {
1333 atomic_t open_count;
1336 unsigned long flags;
1338 @@ -317,6 +319,7 @@ int dm_deleting_md(struct mapped_device
1339 static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1341 struct mapped_device *md;
1344 spin_lock(&_minor_lock);
1346 @@ -325,18 +328,19 @@ static int dm_blk_open(struct block_devi
1349 if (test_bit(DMF_FREEING, &md->flags) ||
1350 - dm_deleting_md(md)) {
1352 + dm_deleting_md(md))
1356 + if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1361 atomic_inc(&md->open_count);
1365 spin_unlock(&_minor_lock);
1367 - return md ? 0 : -ENXIO;
1371 static int dm_blk_close(struct gendisk *disk, fmode_t mode)
1372 @@ -547,6 +551,14 @@ int dm_set_geometry(struct mapped_device
1377 + * Get the xid associated with a dm device
1379 +xid_t dm_get_xid(struct mapped_device *md)
1384 /*-----------------------------------------------------------------
1386 * A more elegant soln is in the works that uses the queue
1387 @@ -1884,6 +1896,7 @@ static struct mapped_device *alloc_dev(i
1388 INIT_LIST_HEAD(&md->uevent_list);
1389 spin_lock_init(&md->uevent_lock);
1391 + md->xid = vx_current_xid();
1392 md->queue = blk_alloc_queue(GFP_KERNEL);
1395 diff -NurpP --minimal linux-3.9.4/drivers/md/dm.h linux-3.9.4-vs2.3.6.1/drivers/md/dm.h
1396 --- linux-3.9.4/drivers/md/dm.h 2013-02-19 13:57:51.000000000 +0000
1397 +++ linux-3.9.4-vs2.3.6.1/drivers/md/dm.h 2013-05-31 14:47:11.000000000 +0000
1398 @@ -46,6 +46,8 @@ struct dm_dev_internal {
1400 struct dm_md_mempools;
1402 +xid_t dm_get_xid(struct mapped_device *md);
1404 /*-----------------------------------------------------------------
1405 * Internal table functions.
1406 *---------------------------------------------------------------*/
1407 diff -NurpP --minimal linux-3.9.4/drivers/net/tun.c linux-3.9.4-vs2.3.6.1/drivers/net/tun.c
1408 --- linux-3.9.4/drivers/net/tun.c 2013-05-31 14:22:27.000000000 +0000
1409 +++ linux-3.9.4-vs2.3.6.1/drivers/net/tun.c 2013-05-31 20:01:45.000000000 +0000
1411 #include <linux/nsproxy.h>
1412 #include <linux/virtio_net.h>
1413 #include <linux/rcupdate.h>
1414 +#include <linux/vs_network.h>
1415 #include <net/net_namespace.h>
1416 #include <net/netns/generic.h>
1417 #include <net/rtnetlink.h>
1418 @@ -164,6 +165,7 @@ struct tun_struct {
1424 struct net_device *dev;
1425 netdev_features_t set_features;
1426 @@ -380,6 +382,7 @@ static inline bool tun_not_capable(struc
1427 return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1428 (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1429 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1430 + /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1433 static void tun_set_real_num_queues(struct tun_struct *tun)
1434 @@ -1404,6 +1407,7 @@ static void tun_setup(struct net_device
1436 tun->owner = INVALID_UID;
1437 tun->group = INVALID_GID;
1438 + tun->nid = nx_current_nid();
1440 dev->ethtool_ops = &tun_ethtool_ops;
1441 dev->destructor = tun_free_netdev;
1442 @@ -1591,6 +1595,9 @@ static int tun_set_iff(struct net *net,
1446 + if (!nx_check(tun->nid, VS_IDENT | VS_HOSTID | VS_ADMIN_P))
1449 err = tun_attach(tun, file);
1452 @@ -1605,7 +1612,7 @@ static int tun_set_iff(struct net *net,
1453 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1456 - if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1457 + if (!vx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1459 err = security_tun_dev_create();
1461 @@ -1950,6 +1957,16 @@ static long __tun_chr_ioctl(struct file
1462 from_kgid(&init_user_ns, tun->group));
1466 + if (!capable(CAP_CONTEXT))
1469 + /* Set nid owner of the device */
1470 + tun->nid = (nid_t) arg;
1472 + tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1476 /* Only allow setting the type when the interface is down */
1477 if (tun->dev->flags & IFF_UP) {
1478 diff -NurpP --minimal linux-3.9.4/drivers/staging/csr/csr_wifi_hip_xbv.c linux-3.9.4-vs2.3.6.1/drivers/staging/csr/csr_wifi_hip_xbv.c
1479 --- linux-3.9.4/drivers/staging/csr/csr_wifi_hip_xbv.c 2013-02-19 13:58:32.000000000 +0000
1480 +++ linux-3.9.4-vs2.3.6.1/drivers/staging/csr/csr_wifi_hip_xbv.c 2013-05-31 14:47:11.000000000 +0000
1481 @@ -55,7 +55,7 @@ typedef struct
1489 #define TAG_EQ(i, v) (((i)[0] == (v)[0]) && \
1490 @@ -90,7 +90,7 @@ typedef struct
1494 -static s32 read_tag(card_t *card, ct_t *ct, tag_t *tag);
1495 +static s32 read_tag(card_t *card, ct_t *ct, ctag_t *tag);
1496 static s32 read_bytes(card_t *card, ct_t *ct, void *buf, u32 len);
1497 static s32 read_uint(card_t *card, ct_t *ct, u32 *u, u32 len);
1498 static s32 xbv_check(xbv1_t *fwinfo, const xbv_stack_t *stack,
1499 @@ -160,7 +160,7 @@ static u32 write_fwdl_to_ptdl(void *buf,
1500 CsrResult xbv1_parse(card_t *card, fwreadfn_t readfn, void *dlpriv, xbv1_t *fwinfo)
1508 @@ -505,7 +505,7 @@ static u32 xbv2uint(u8 *ptr, s32 len)
1512 -static s32 read_tag(card_t *card, ct_t *ct, tag_t *tag)
1513 +static s32 read_tag(card_t *card, ct_t *ct, ctag_t *tag)
1517 diff -NurpP --minimal linux-3.9.4/drivers/tty/sysrq.c linux-3.9.4-vs2.3.6.1/drivers/tty/sysrq.c
1518 --- linux-3.9.4/drivers/tty/sysrq.c 2013-05-31 13:45:19.000000000 +0000
1519 +++ linux-3.9.4-vs2.3.6.1/drivers/tty/sysrq.c 2013-05-31 15:08:19.000000000 +0000
1521 #include <linux/input.h>
1522 #include <linux/uaccess.h>
1523 #include <linux/moduleparam.h>
1524 +#include <linux/vserver/debug.h>
1526 #include <asm/ptrace.h>
1527 #include <asm/irq_regs.h>
1528 @@ -401,6 +402,21 @@ static struct sysrq_key_op sysrq_unrt_op
1529 .enable_mask = SYSRQ_ENABLE_RTNICE,
1533 +#ifdef CONFIG_VSERVER_DEBUG
1534 +static void sysrq_handle_vxinfo(int key)
1536 + dump_vx_info_inactive((key == 'x') ? 0 : 1);
1539 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1540 + .handler = sysrq_handle_vxinfo,
1541 + .help_msg = "conteXt",
1542 + .action_msg = "Show Context Info",
1543 + .enable_mask = SYSRQ_ENABLE_DUMP,
1547 /* Key Operations table and lock */
1548 static DEFINE_SPINLOCK(sysrq_key_table_lock);
1550 @@ -456,7 +472,11 @@ static struct sysrq_key_op *sysrq_key_ta
1551 &sysrq_showstate_blocked_op, /* w */
1552 /* x: May be registered on ppc/powerpc for xmon */
1553 /* x: May be registered on sparc64 for global PMU dump */
1554 +#ifdef CONFIG_VSERVER_DEBUG
1555 + &sysrq_showvxinfo_op, /* x */
1559 /* y: May be registered on sparc64 for global register dump */
1561 &sysrq_ftrace_dump_op, /* z */
1562 @@ -471,6 +491,8 @@ static int sysrq_key_table_key2index(int
1564 else if ((key >= 'a') && (key <= 'z'))
1565 retval = key + 10 - 'a';
1566 + else if ((key >= 'A') && (key <= 'Z'))
1567 + retval = key + 10 - 'A';
1571 diff -NurpP --minimal linux-3.9.4/drivers/tty/tty_io.c linux-3.9.4-vs2.3.6.1/drivers/tty/tty_io.c
1572 --- linux-3.9.4/drivers/tty/tty_io.c 2013-05-31 14:22:27.000000000 +0000
1573 +++ linux-3.9.4-vs2.3.6.1/drivers/tty/tty_io.c 2013-05-31 14:47:11.000000000 +0000
1576 #include <linux/kmod.h>
1577 #include <linux/nsproxy.h>
1578 +#include <linux/vs_pid.h>
1580 #undef TTY_DEBUG_HANGUP
1582 @@ -2144,7 +2145,8 @@ static int tiocsti(struct tty_struct *tt
1584 struct tty_ldisc *ld;
1586 - if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1587 + if (((current->signal->tty != tty) &&
1588 + !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1590 if (get_user(ch, p))
1592 @@ -2432,6 +2434,7 @@ static int tiocspgrp(struct tty_struct *
1594 if (get_user(pgrp_nr, p))
1596 + pgrp_nr = vx_rmap_pid(pgrp_nr);
1600 diff -NurpP --minimal linux-3.9.4/fs/attr.c linux-3.9.4-vs2.3.6.1/fs/attr.c
1601 --- linux-3.9.4/fs/attr.c 2013-02-19 13:58:46.000000000 +0000
1602 +++ linux-3.9.4-vs2.3.6.1/fs/attr.c 2013-05-31 14:47:11.000000000 +0000
1604 #include <linux/security.h>
1605 #include <linux/evm.h>
1606 #include <linux/ima.h>
1607 +#include <linux/proc_fs.h>
1608 +#include <linux/devpts_fs.h>
1609 +#include <linux/vs_tag.h>
1612 * inode_change_ok - check if attribute changes to an inode are allowed
1613 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1617 + /* check for inode tag permission */
1618 + if (dx_permission(inode, MAY_WRITE))
1623 EXPORT_SYMBOL(inode_change_ok);
1624 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1625 inode->i_uid = attr->ia_uid;
1626 if (ia_valid & ATTR_GID)
1627 inode->i_gid = attr->ia_gid;
1628 + if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1629 + inode->i_tag = attr->ia_tag;
1630 if (ia_valid & ATTR_ATIME)
1631 inode->i_atime = timespec_trunc(attr->ia_atime,
1632 inode->i_sb->s_time_gran);
1633 @@ -177,7 +186,8 @@ int notify_change(struct dentry * dentry
1635 WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1637 - if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1638 + if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1639 + ATTR_TAG | ATTR_TIMES_SET)) {
1640 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1643 diff -NurpP --minimal linux-3.9.4/fs/block_dev.c linux-3.9.4-vs2.3.6.1/fs/block_dev.c
1644 --- linux-3.9.4/fs/block_dev.c 2013-05-31 13:45:22.000000000 +0000
1645 +++ linux-3.9.4-vs2.3.6.1/fs/block_dev.c 2013-05-31 14:47:11.000000000 +0000
1647 #include <linux/namei.h>
1648 #include <linux/log2.h>
1649 #include <linux/cleancache.h>
1650 +#include <linux/vs_device.h>
1651 #include <asm/uaccess.h>
1652 #include "internal.h"
1654 @@ -528,6 +529,7 @@ struct block_device *bdget(dev_t dev)
1655 bdev->bd_invalidated = 0;
1656 inode->i_mode = S_IFBLK;
1657 inode->i_rdev = dev;
1658 + inode->i_mdev = dev;
1659 inode->i_bdev = bdev;
1660 inode->i_data.a_ops = &def_blk_aops;
1661 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1662 @@ -575,6 +577,11 @@ EXPORT_SYMBOL(bdput);
1663 static struct block_device *bd_acquire(struct inode *inode)
1665 struct block_device *bdev;
1668 + if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1670 + inode->i_mdev = mdev;
1672 spin_lock(&bdev_lock);
1673 bdev = inode->i_bdev;
1674 @@ -585,7 +592,7 @@ static struct block_device *bd_acquire(s
1676 spin_unlock(&bdev_lock);
1678 - bdev = bdget(inode->i_rdev);
1679 + bdev = bdget(mdev);
1681 spin_lock(&bdev_lock);
1682 if (!inode->i_bdev) {
1683 diff -NurpP --minimal linux-3.9.4/fs/btrfs/ctree.h linux-3.9.4-vs2.3.6.1/fs/btrfs/ctree.h
1684 --- linux-3.9.4/fs/btrfs/ctree.h 2013-05-31 13:45:22.000000000 +0000
1685 +++ linux-3.9.4-vs2.3.6.1/fs/btrfs/ctree.h 2013-05-31 14:47:11.000000000 +0000
1686 @@ -705,11 +705,14 @@ struct btrfs_inode_item {
1687 /* modification sequence number for NFS */
1692 * a little future expansion, for more than this we can
1693 * just grow the inode item and version it
1695 - __le64 reserved[4];
1696 + __le16 reserved16;
1697 + __le32 reserved32;
1698 + __le64 reserved[3];
1699 struct btrfs_timespec atime;
1700 struct btrfs_timespec ctime;
1701 struct btrfs_timespec mtime;
1702 @@ -1901,6 +1904,8 @@ struct btrfs_ioctl_defrag_range_args {
1703 #define BTRFS_MOUNT_CHECK_INTEGRITY_INCLUDING_EXTENT_DATA (1 << 21)
1704 #define BTRFS_MOUNT_PANIC_ON_FATAL_ERROR (1 << 22)
1706 +#define BTRFS_MOUNT_TAGGED (1 << 24)
1708 #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
1709 #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
1710 #define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt)
1711 @@ -2170,6 +2175,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1712 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1713 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1714 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1715 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1716 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1717 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1718 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1719 @@ -2223,6 +2229,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1721 BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1723 +#define BTRFS_INODE_IXUNLINK (1 << 24)
1724 +#define BTRFS_INODE_BARRIER (1 << 25)
1725 +#define BTRFS_INODE_COW (1 << 26)
1728 BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1730 @@ -3581,6 +3591,7 @@ extern const struct dentry_operations bt
1731 long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
1732 void btrfs_update_iflags(struct inode *inode);
1733 void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1734 +int btrfs_sync_flags(struct inode *inode, int, int);
1735 int btrfs_defrag_file(struct inode *inode, struct file *file,
1736 struct btrfs_ioctl_defrag_range_args *range,
1737 u64 newer_than, unsigned long max_pages);
1738 diff -NurpP --minimal linux-3.9.4/fs/btrfs/disk-io.c linux-3.9.4-vs2.3.6.1/fs/btrfs/disk-io.c
1739 --- linux-3.9.4/fs/btrfs/disk-io.c 2013-05-31 13:45:22.000000000 +0000
1740 +++ linux-3.9.4-vs2.3.6.1/fs/btrfs/disk-io.c 2013-05-31 14:47:11.000000000 +0000
1741 @@ -2258,6 +2258,9 @@ int open_ctree(struct super_block *sb,
1745 + if (btrfs_test_opt(tree_root, TAGGED))
1746 + sb->s_flags |= MS_TAGGED;
1748 features = btrfs_super_incompat_flags(disk_super) &
1749 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1751 diff -NurpP --minimal linux-3.9.4/fs/btrfs/inode.c linux-3.9.4-vs2.3.6.1/fs/btrfs/inode.c
1752 --- linux-3.9.4/fs/btrfs/inode.c 2013-05-31 14:22:27.000000000 +0000
1753 +++ linux-3.9.4-vs2.3.6.1/fs/btrfs/inode.c 2013-05-31 20:42:33.000000000 +0000
1755 #include <linux/mount.h>
1756 #include <linux/btrfs.h>
1757 #include <linux/blkdev.h>
1758 +#include <linux/vs_tag.h>
1761 #include "disk-io.h"
1762 @@ -3312,6 +3313,8 @@ static void btrfs_read_locked_inode(stru
1763 struct btrfs_key location;
1769 bool filled = false;
1771 @@ -3339,8 +3342,13 @@ static void btrfs_read_locked_inode(stru
1772 struct btrfs_inode_item);
1773 inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1774 set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1775 - i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1776 - i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1778 + uid = btrfs_inode_uid(leaf, inode_item);
1779 + gid = btrfs_inode_gid(leaf, inode_item);
1780 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
1781 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
1782 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
1783 + btrfs_inode_tag(leaf, inode_item)));
1784 btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1786 tspec = btrfs_inode_atime(inode_item);
1787 @@ -3431,11 +3439,18 @@ static void fill_inode_item(struct btrfs
1788 struct inode *inode)
1790 struct btrfs_map_token token;
1791 + uid_t uid = TAGINO_UID(DX_TAG(inode),
1792 + i_uid_read(inode), i_tag_read(inode));
1793 + gid_t gid = TAGINO_GID(DX_TAG(inode),
1794 + i_gid_read(inode), i_tag_read(inode));
1796 btrfs_init_map_token(&token);
1798 - btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1799 - btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1800 + btrfs_set_token_inode_uid(leaf, item, uid, &token);
1801 + btrfs_set_token_inode_gid(leaf, item, gid, &token);
1802 +#ifdef CONFIG_TAGGING_INTERN
1803 + btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1805 btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1807 btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1808 @@ -8683,11 +8698,13 @@ static const struct inode_operations btr
1809 .listxattr = btrfs_listxattr,
1810 .removexattr = btrfs_removexattr,
1811 .permission = btrfs_permission,
1812 + .sync_flags = btrfs_sync_flags,
1813 .get_acl = btrfs_get_acl,
1815 static const struct inode_operations btrfs_dir_ro_inode_operations = {
1816 .lookup = btrfs_lookup,
1817 .permission = btrfs_permission,
1818 + .sync_flags = btrfs_sync_flags,
1819 .get_acl = btrfs_get_acl,
1822 diff -NurpP --minimal linux-3.9.4/fs/btrfs/ioctl.c linux-3.9.4-vs2.3.6.1/fs/btrfs/ioctl.c
1823 --- linux-3.9.4/fs/btrfs/ioctl.c 2013-05-31 14:22:27.000000000 +0000
1824 +++ linux-3.9.4-vs2.3.6.1/fs/btrfs/ioctl.c 2013-05-31 14:47:11.000000000 +0000
1825 @@ -75,10 +75,13 @@ static unsigned int btrfs_flags_to_ioctl
1827 unsigned int iflags = 0;
1829 - if (flags & BTRFS_INODE_SYNC)
1830 - iflags |= FS_SYNC_FL;
1831 if (flags & BTRFS_INODE_IMMUTABLE)
1832 iflags |= FS_IMMUTABLE_FL;
1833 + if (flags & BTRFS_INODE_IXUNLINK)
1834 + iflags |= FS_IXUNLINK_FL;
1836 + if (flags & BTRFS_INODE_SYNC)
1837 + iflags |= FS_SYNC_FL;
1838 if (flags & BTRFS_INODE_APPEND)
1839 iflags |= FS_APPEND_FL;
1840 if (flags & BTRFS_INODE_NODUMP)
1841 @@ -95,28 +98,78 @@ static unsigned int btrfs_flags_to_ioctl
1842 else if (flags & BTRFS_INODE_NOCOMPRESS)
1843 iflags |= FS_NOCOMP_FL;
1845 + if (flags & BTRFS_INODE_BARRIER)
1846 + iflags |= FS_BARRIER_FL;
1847 + if (flags & BTRFS_INODE_COW)
1848 + iflags |= FS_COW_FL;
1853 - * Update inode->i_flags based on the btrfs internal flags.
1854 + * Update inode->i_(v)flags based on the btrfs internal flags.
1856 void btrfs_update_iflags(struct inode *inode)
1858 struct btrfs_inode *ip = BTRFS_I(inode);
1860 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1861 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1862 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1864 - if (ip->flags & BTRFS_INODE_SYNC)
1865 - inode->i_flags |= S_SYNC;
1866 if (ip->flags & BTRFS_INODE_IMMUTABLE)
1867 inode->i_flags |= S_IMMUTABLE;
1868 + if (ip->flags & BTRFS_INODE_IXUNLINK)
1869 + inode->i_flags |= S_IXUNLINK;
1871 + if (ip->flags & BTRFS_INODE_SYNC)
1872 + inode->i_flags |= S_SYNC;
1873 if (ip->flags & BTRFS_INODE_APPEND)
1874 inode->i_flags |= S_APPEND;
1875 if (ip->flags & BTRFS_INODE_NOATIME)
1876 inode->i_flags |= S_NOATIME;
1877 if (ip->flags & BTRFS_INODE_DIRSYNC)
1878 inode->i_flags |= S_DIRSYNC;
1880 + inode->i_vflags &= ~(V_BARRIER | V_COW);
1882 + if (ip->flags & BTRFS_INODE_BARRIER)
1883 + inode->i_vflags |= V_BARRIER;
1884 + if (ip->flags & BTRFS_INODE_COW)
1885 + inode->i_vflags |= V_COW;
1889 + * Update btrfs internal flags from inode->i_(v)flags.
1891 +void btrfs_update_flags(struct inode *inode)
1893 + struct btrfs_inode *ip = BTRFS_I(inode);
1895 + unsigned int flags = inode->i_flags;
1896 + unsigned int vflags = inode->i_vflags;
1898 + ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1899 + BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1900 + BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1901 + BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1903 + if (flags & S_IMMUTABLE)
1904 + ip->flags |= BTRFS_INODE_IMMUTABLE;
1905 + if (flags & S_IXUNLINK)
1906 + ip->flags |= BTRFS_INODE_IXUNLINK;
1908 + if (flags & S_SYNC)
1909 + ip->flags |= BTRFS_INODE_SYNC;
1910 + if (flags & S_APPEND)
1911 + ip->flags |= BTRFS_INODE_APPEND;
1912 + if (flags & S_NOATIME)
1913 + ip->flags |= BTRFS_INODE_NOATIME;
1914 + if (flags & S_DIRSYNC)
1915 + ip->flags |= BTRFS_INODE_DIRSYNC;
1917 + if (vflags & V_BARRIER)
1918 + ip->flags |= BTRFS_INODE_BARRIER;
1919 + if (vflags & V_COW)
1920 + ip->flags |= BTRFS_INODE_COW;
1924 @@ -132,6 +185,7 @@ void btrfs_inherit_iflags(struct inode *
1927 flags = BTRFS_I(dir)->flags;
1928 + flags &= ~BTRFS_INODE_BARRIER;
1930 if (flags & BTRFS_INODE_NOCOMPRESS) {
1931 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1932 @@ -150,6 +204,30 @@ void btrfs_inherit_iflags(struct inode *
1933 btrfs_update_iflags(inode);
1936 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1938 + struct btrfs_inode *ip = BTRFS_I(inode);
1939 + struct btrfs_root *root = ip->root;
1940 + struct btrfs_trans_handle *trans;
1943 + trans = btrfs_join_transaction(root);
1946 + inode->i_flags = flags;
1947 + inode->i_vflags = vflags;
1948 + btrfs_update_flags(inode);
1950 + ret = btrfs_update_inode(trans, root, inode);
1953 + btrfs_update_iflags(inode);
1954 + inode->i_ctime = CURRENT_TIME;
1955 + btrfs_end_transaction(trans, root);
1960 static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1962 struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1963 @@ -212,21 +290,27 @@ static int btrfs_ioctl_setflags(struct f
1965 flags = btrfs_mask_flags(inode->i_mode, flags);
1966 oldflags = btrfs_flags_to_ioctl(ip->flags);
1967 - if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1968 + if ((flags ^ oldflags) & (FS_APPEND_FL |
1969 + FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1970 if (!capable(CAP_LINUX_IMMUTABLE)) {
1976 - if (flags & FS_SYNC_FL)
1977 - ip->flags |= BTRFS_INODE_SYNC;
1979 - ip->flags &= ~BTRFS_INODE_SYNC;
1980 if (flags & FS_IMMUTABLE_FL)
1981 ip->flags |= BTRFS_INODE_IMMUTABLE;
1983 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1984 + if (flags & FS_IXUNLINK_FL)
1985 + ip->flags |= BTRFS_INODE_IXUNLINK;
1987 + ip->flags &= ~BTRFS_INODE_IXUNLINK;
1989 + if (flags & FS_SYNC_FL)
1990 + ip->flags |= BTRFS_INODE_SYNC;
1992 + ip->flags &= ~BTRFS_INODE_SYNC;
1993 if (flags & FS_APPEND_FL)
1994 ip->flags |= BTRFS_INODE_APPEND;
1996 diff -NurpP --minimal linux-3.9.4/fs/btrfs/super.c linux-3.9.4-vs2.3.6.1/fs/btrfs/super.c
1997 --- linux-3.9.4/fs/btrfs/super.c 2013-05-31 13:45:22.000000000 +0000
1998 +++ linux-3.9.4-vs2.3.6.1/fs/btrfs/super.c 2013-05-31 14:47:11.000000000 +0000
1999 @@ -321,7 +321,7 @@ enum {
2000 Opt_no_space_cache, Opt_recovery, Opt_skip_balance,
2001 Opt_check_integrity, Opt_check_integrity_including_extent_data,
2002 Opt_check_integrity_print_mask, Opt_fatal_errors,
2004 + Opt_tag, Opt_notag, Opt_tagid, Opt_err,
2007 static match_table_t tokens = {
2008 @@ -361,6 +361,9 @@ static match_table_t tokens = {
2009 {Opt_check_integrity_including_extent_data, "check_int_data"},
2010 {Opt_check_integrity_print_mask, "check_int_print_mask=%d"},
2011 {Opt_fatal_errors, "fatal_errors=%s"},
2013 + {Opt_notag, "notag"},
2014 + {Opt_tagid, "tagid=%u"},
2018 @@ -626,6 +629,22 @@ int btrfs_parse_options(struct btrfs_roo
2022 +#ifndef CONFIG_TAGGING_NONE
2024 + printk(KERN_INFO "btrfs: use tagging\n");
2025 + btrfs_set_opt(info->mount_opt, TAGGED);
2028 + printk(KERN_INFO "btrfs: disabled tagging\n");
2029 + btrfs_clear_opt(info->mount_opt, TAGGED);
2032 +#ifdef CONFIG_PROPAGATE
2035 + btrfs_set_opt(info->mount_opt, TAGGED);
2039 printk(KERN_INFO "btrfs: unrecognized mount option "
2041 @@ -1258,6 +1277,12 @@ static int btrfs_remount(struct super_bl
2042 btrfs_resize_thread_pool(fs_info,
2043 fs_info->thread_pool_size, old_thread_pool_size);
2045 + if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
2046 + printk("btrfs: %s: tagging not permitted on remount.\n",
2051 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
2054 diff -NurpP --minimal linux-3.9.4/fs/char_dev.c linux-3.9.4-vs2.3.6.1/fs/char_dev.c
2055 --- linux-3.9.4/fs/char_dev.c 2012-12-11 03:30:57.000000000 +0000
2056 +++ linux-3.9.4-vs2.3.6.1/fs/char_dev.c 2013-05-31 14:47:11.000000000 +0000
2058 #include <linux/mutex.h>
2059 #include <linux/backing-dev.h>
2060 #include <linux/tty.h>
2061 +#include <linux/vs_context.h>
2062 +#include <linux/vs_device.h>
2064 #include "internal.h"
2066 @@ -371,14 +373,21 @@ static int chrdev_open(struct inode *ino
2068 struct cdev *new = NULL;
2072 + if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
2074 + inode->i_mdev = mdev;
2076 spin_lock(&cdev_lock);
2079 struct kobject *kobj;
2082 spin_unlock(&cdev_lock);
2083 - kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
2085 + kobj = kobj_lookup(cdev_map, mdev, &idx);
2088 new = container_of(kobj, struct cdev, kobj);
2089 diff -NurpP --minimal linux-3.9.4/fs/dcache.c linux-3.9.4-vs2.3.6.1/fs/dcache.c
2090 --- linux-3.9.4/fs/dcache.c 2013-05-31 14:22:27.000000000 +0000
2091 +++ linux-3.9.4-vs2.3.6.1/fs/dcache.c 2013-05-31 14:47:11.000000000 +0000
2093 #include <linux/rculist_bl.h>
2094 #include <linux/prefetch.h>
2095 #include <linux/ratelimit.h>
2096 +#include <linux/vs_limit.h>
2097 #include "internal.h"
2100 @@ -593,6 +594,8 @@ int d_invalidate(struct dentry * dentry)
2101 spin_lock(&dentry->d_lock);
2104 + vx_dentry_dec(dentry);
2107 * Somebody else still using it?
2109 @@ -622,6 +625,7 @@ EXPORT_SYMBOL(d_invalidate);
2110 static inline void __dget_dlock(struct dentry *dentry)
2113 + vx_dentry_inc(dentry);
2116 static inline void __dget(struct dentry *dentry)
2117 @@ -1252,6 +1256,9 @@ struct dentry *__d_alloc(struct super_bl
2118 struct dentry *dentry;
2121 + if (!vx_dentry_avail(1))
2124 dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
2127 @@ -1284,6 +1291,7 @@ struct dentry *__d_alloc(struct super_bl
2129 dentry->d_count = 1;
2130 dentry->d_flags = 0;
2131 + vx_dentry_inc(dentry);
2132 spin_lock_init(&dentry->d_lock);
2133 seqcount_init(&dentry->d_seq);
2134 dentry->d_inode = NULL;
2135 @@ -1984,6 +1992,7 @@ struct dentry *__d_lookup(const struct d
2139 + vx_dentry_inc(dentry);
2141 spin_unlock(&dentry->d_lock);
2143 diff -NurpP --minimal linux-3.9.4/fs/devpts/inode.c linux-3.9.4-vs2.3.6.1/fs/devpts/inode.c
2144 --- linux-3.9.4/fs/devpts/inode.c 2013-05-31 13:45:23.000000000 +0000
2145 +++ linux-3.9.4-vs2.3.6.1/fs/devpts/inode.c 2013-05-31 15:42:25.000000000 +0000
2147 #include <linux/parser.h>
2148 #include <linux/fsnotify.h>
2149 #include <linux/seq_file.h>
2150 +#include <linux/vs_base.h>
2152 #define DEVPTS_DEFAULT_MODE 0600
2155 #define DEVPTS_DEFAULT_PTMX_MODE 0000
2156 #define PTMX_MINOR 2
2158 +static int devpts_permission(struct inode *inode, int mask)
2160 + int ret = -EACCES;
2162 + /* devpts is xid tagged */
2163 + if (vx_check((xid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2164 + ret = generic_permission(inode, mask);
2168 +static struct inode_operations devpts_file_inode_operations = {
2169 + .permission = devpts_permission,
2174 * sysctl support for setting limits on the number of Unix98 ptys allocated.
2175 * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2176 @@ -345,6 +361,34 @@ static int devpts_show_options(struct se
2180 +static int devpts_filter(struct dentry *de)
2184 + /* devpts is xid tagged */
2185 + if (de && de->d_inode)
2186 + xid = (xid_t)i_tag_read(de->d_inode);
2187 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2189 + vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2190 + de->d_name.len, de->d_name.name);
2192 + return vx_check(xid, VS_WATCH_P | VS_IDENT);
2195 +static int devpts_readdir(struct file * filp, void * dirent, filldir_t filldir)
2197 + return dcache_readdir_filter(filp, dirent, filldir, devpts_filter);
2200 +static struct file_operations devpts_dir_operations = {
2201 + .open = dcache_dir_open,
2202 + .release = dcache_dir_close,
2203 + .llseek = dcache_dir_lseek,
2204 + .read = generic_read_dir,
2205 + .readdir = devpts_readdir,
2208 static const struct super_operations devpts_sops = {
2209 .statfs = simple_statfs,
2210 .remount_fs = devpts_remount,
2211 @@ -388,8 +432,10 @@ devpts_fill_super(struct super_block *s,
2212 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2213 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2214 inode->i_op = &simple_dir_inode_operations;
2215 - inode->i_fop = &simple_dir_operations;
2216 + inode->i_fop = &devpts_dir_operations;
2217 set_nlink(inode, 2);
2218 + /* devpts is xid tagged */
2219 + i_tag_write(inode, (tag_t)vx_current_xid());
2221 s->s_root = d_make_root(inode);
2223 @@ -592,6 +638,9 @@ struct inode *devpts_pty_new(struct inod
2224 inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2225 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2226 init_special_inode(inode, S_IFCHR|opts->mode, device);
2227 + /* devpts is xid tagged */
2228 + i_tag_write(inode, (tag_t)vx_current_xid());
2229 + inode->i_op = &devpts_file_inode_operations;
2230 inode->i_private = priv;
2232 sprintf(s, "%d", index);
2233 diff -NurpP --minimal linux-3.9.4/fs/ext2/balloc.c linux-3.9.4-vs2.3.6.1/fs/ext2/balloc.c
2234 --- linux-3.9.4/fs/ext2/balloc.c 2013-05-31 13:45:23.000000000 +0000
2235 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/balloc.c 2013-05-31 14:47:11.000000000 +0000
2236 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2238 end = EXT2_BLOCKS_PER_GROUP(sb);
2241 BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2244 diff -NurpP --minimal linux-3.9.4/fs/ext2/ext2.h linux-3.9.4-vs2.3.6.1/fs/ext2/ext2.h
2245 --- linux-3.9.4/fs/ext2/ext2.h 2012-12-11 03:30:57.000000000 +0000
2246 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/ext2.h 2013-05-31 14:47:11.000000000 +0000
2247 @@ -244,8 +244,12 @@ struct ext2_group_desc
2248 #define EXT2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
2249 #define EXT2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
2250 #define EXT2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
2251 +#define EXT2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
2252 #define EXT2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
2254 +#define EXT2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
2255 +#define EXT2_COW_FL FS_COW_FL /* Copy on Write marker */
2257 #define EXT2_FL_USER_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
2258 #define EXT2_FL_USER_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
2260 @@ -329,7 +333,8 @@ struct ext2_inode {
2262 __le16 l_i_uid_high; /* these 2 fields */
2263 __le16 l_i_gid_high; /* were reserved2[0] */
2264 - __u32 l_i_reserved2;
2265 + __le16 l_i_tag; /* Context Tag */
2266 + __u16 l_i_reserved2;
2269 __u8 h_i_frag; /* Fragment number */
2270 @@ -357,6 +362,7 @@ struct ext2_inode {
2271 #define i_gid_low i_gid
2272 #define i_uid_high osd2.linux2.l_i_uid_high
2273 #define i_gid_high osd2.linux2.l_i_gid_high
2274 +#define i_raw_tag osd2.linux2.l_i_tag
2275 #define i_reserved2 osd2.linux2.l_i_reserved2
2278 @@ -384,6 +390,7 @@ struct ext2_inode {
2279 #define EXT2_MOUNT_USRQUOTA 0x020000 /* user quota */
2280 #define EXT2_MOUNT_GRPQUOTA 0x040000 /* group quota */
2281 #define EXT2_MOUNT_RESERVATION 0x080000 /* Preallocation */
2282 +#define EXT2_MOUNT_TAGGED (1<<24) /* Enable Context Tags */
2285 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
2286 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2287 extern void ext2_get_inode_flags(struct ext2_inode_info *);
2288 extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2289 u64 start, u64 len);
2290 +extern int ext2_sync_flags(struct inode *, int, int);
2293 extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2294 diff -NurpP --minimal linux-3.9.4/fs/ext2/file.c linux-3.9.4-vs2.3.6.1/fs/ext2/file.c
2295 --- linux-3.9.4/fs/ext2/file.c 2012-12-11 03:30:57.000000000 +0000
2296 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/file.c 2013-05-31 14:47:11.000000000 +0000
2297 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2298 .setattr = ext2_setattr,
2299 .get_acl = ext2_get_acl,
2300 .fiemap = ext2_fiemap,
2301 + .sync_flags = ext2_sync_flags,
2303 diff -NurpP --minimal linux-3.9.4/fs/ext2/ialloc.c linux-3.9.4-vs2.3.6.1/fs/ext2/ialloc.c
2304 --- linux-3.9.4/fs/ext2/ialloc.c 2013-05-31 13:45:23.000000000 +0000
2305 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/ialloc.c 2013-05-31 14:47:11.000000000 +0000
2307 #include <linux/backing-dev.h>
2308 #include <linux/buffer_head.h>
2309 #include <linux/random.h>
2310 +#include <linux/vs_tag.h>
2314 @@ -546,6 +547,7 @@ got:
2315 inode->i_mode = mode;
2316 inode->i_uid = current_fsuid();
2317 inode->i_gid = dir->i_gid;
2318 + inode->i_tag = dx_current_fstag(sb);
2320 inode_init_owner(inode, dir, mode);
2322 diff -NurpP --minimal linux-3.9.4/fs/ext2/inode.c linux-3.9.4-vs2.3.6.1/fs/ext2/inode.c
2323 --- linux-3.9.4/fs/ext2/inode.c 2013-05-31 13:45:23.000000000 +0000
2324 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/inode.c 2013-05-31 14:47:11.000000000 +0000
2326 #include <linux/mpage.h>
2327 #include <linux/fiemap.h>
2328 #include <linux/namei.h>
2329 +#include <linux/vs_tag.h>
2333 @@ -1179,7 +1180,7 @@ static void ext2_truncate_blocks(struct
2335 if (ext2_inode_is_fast_symlink(inode))
2337 - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2338 + if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2340 __ext2_truncate_blocks(inode, offset);
2342 @@ -1270,36 +1271,61 @@ void ext2_set_inode_flags(struct inode *
2344 unsigned int flags = EXT2_I(inode)->i_flags;
2346 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2347 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2348 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2351 + if (flags & EXT2_IMMUTABLE_FL)
2352 + inode->i_flags |= S_IMMUTABLE;
2353 + if (flags & EXT2_IXUNLINK_FL)
2354 + inode->i_flags |= S_IXUNLINK;
2356 if (flags & EXT2_SYNC_FL)
2357 inode->i_flags |= S_SYNC;
2358 if (flags & EXT2_APPEND_FL)
2359 inode->i_flags |= S_APPEND;
2360 - if (flags & EXT2_IMMUTABLE_FL)
2361 - inode->i_flags |= S_IMMUTABLE;
2362 if (flags & EXT2_NOATIME_FL)
2363 inode->i_flags |= S_NOATIME;
2364 if (flags & EXT2_DIRSYNC_FL)
2365 inode->i_flags |= S_DIRSYNC;
2367 + inode->i_vflags &= ~(V_BARRIER | V_COW);
2369 + if (flags & EXT2_BARRIER_FL)
2370 + inode->i_vflags |= V_BARRIER;
2371 + if (flags & EXT2_COW_FL)
2372 + inode->i_vflags |= V_COW;
2375 /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2376 void ext2_get_inode_flags(struct ext2_inode_info *ei)
2378 unsigned int flags = ei->vfs_inode.i_flags;
2379 + unsigned int vflags = ei->vfs_inode.i_vflags;
2381 + ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2382 + EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2383 + EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2384 + EXT2_BARRIER_FL | EXT2_COW_FL);
2386 + if (flags & S_IMMUTABLE)
2387 + ei->i_flags |= EXT2_IMMUTABLE_FL;
2388 + if (flags & S_IXUNLINK)
2389 + ei->i_flags |= EXT2_IXUNLINK_FL;
2391 - ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2392 - EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2394 ei->i_flags |= EXT2_SYNC_FL;
2395 if (flags & S_APPEND)
2396 ei->i_flags |= EXT2_APPEND_FL;
2397 - if (flags & S_IMMUTABLE)
2398 - ei->i_flags |= EXT2_IMMUTABLE_FL;
2399 if (flags & S_NOATIME)
2400 ei->i_flags |= EXT2_NOATIME_FL;
2401 if (flags & S_DIRSYNC)
2402 ei->i_flags |= EXT2_DIRSYNC_FL;
2404 + if (vflags & V_BARRIER)
2405 + ei->i_flags |= EXT2_BARRIER_FL;
2406 + if (vflags & V_COW)
2407 + ei->i_flags |= EXT2_COW_FL;
2410 struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2411 @@ -1335,8 +1361,10 @@ struct inode *ext2_iget (struct super_bl
2412 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2413 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2415 - i_uid_write(inode, i_uid);
2416 - i_gid_write(inode, i_gid);
2417 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2418 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2419 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2420 + le16_to_cpu(raw_inode->i_raw_tag)));
2421 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2422 inode->i_size = le32_to_cpu(raw_inode->i_size);
2423 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2424 @@ -1434,8 +1462,10 @@ static int __ext2_write_inode(struct ino
2425 struct ext2_inode_info *ei = EXT2_I(inode);
2426 struct super_block *sb = inode->i_sb;
2427 ino_t ino = inode->i_ino;
2428 - uid_t uid = i_uid_read(inode);
2429 - gid_t gid = i_gid_read(inode);
2430 + uid_t uid = TAGINO_UID(DX_TAG(inode),
2431 + i_uid_read(inode), i_tag_read(inode));
2432 + gid_t gid = TAGINO_GID(DX_TAG(inode),
2433 + i_gid_read(inode), i_tag_read(inode));
2434 struct buffer_head * bh;
2435 struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2437 @@ -1471,6 +1501,9 @@ static int __ext2_write_inode(struct ino
2438 raw_inode->i_uid_high = 0;
2439 raw_inode->i_gid_high = 0;
2441 +#ifdef CONFIG_TAGGING_INTERN
2442 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2444 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2445 raw_inode->i_size = cpu_to_le32(inode->i_size);
2446 raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2447 @@ -1551,7 +1584,8 @@ int ext2_setattr(struct dentry *dentry,
2448 if (is_quota_modification(inode, iattr))
2449 dquot_initialize(inode);
2450 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2451 - (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2452 + (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2453 + (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2454 error = dquot_transfer(inode, iattr);
2457 diff -NurpP --minimal linux-3.9.4/fs/ext2/ioctl.c linux-3.9.4-vs2.3.6.1/fs/ext2/ioctl.c
2458 --- linux-3.9.4/fs/ext2/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2459 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/ioctl.c 2013-05-31 14:47:11.000000000 +0000
2461 #include <asm/uaccess.h>
2464 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2466 + inode->i_flags = flags;
2467 + inode->i_vflags = vflags;
2468 + ext2_get_inode_flags(EXT2_I(inode));
2469 + inode->i_ctime = CURRENT_TIME_SEC;
2470 + mark_inode_dirty(inode);
2474 long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2476 struct inode *inode = file_inode(filp);
2477 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2479 flags = ext2_mask_flags(inode->i_mode, flags);
2481 + if (IS_BARRIER(inode)) {
2482 + vxwprintk_task(1, "messing with the barrier.");
2486 mutex_lock(&inode->i_mutex);
2487 /* Is it quota file? Do not allow user to mess with it */
2488 if (IS_NOQUOTA(inode)) {
2489 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2491 * This test looks nicer. Thanks to Pauline Middelink
2493 - if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2494 + if ((oldflags & EXT2_IMMUTABLE_FL) ||
2495 + ((flags ^ oldflags) & (EXT2_APPEND_FL |
2496 + EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2497 if (!capable(CAP_LINUX_IMMUTABLE)) {
2498 mutex_unlock(&inode->i_mutex);
2500 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2504 - flags = flags & EXT2_FL_USER_MODIFIABLE;
2505 + flags &= EXT2_FL_USER_MODIFIABLE;
2506 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2507 ei->i_flags = flags;
2509 diff -NurpP --minimal linux-3.9.4/fs/ext2/namei.c linux-3.9.4-vs2.3.6.1/fs/ext2/namei.c
2510 --- linux-3.9.4/fs/ext2/namei.c 2012-12-11 03:30:57.000000000 +0000
2511 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/namei.c 2013-05-31 14:47:11.000000000 +0000
2514 #include <linux/pagemap.h>
2515 #include <linux/quotaops.h>
2516 +#include <linux/vs_tag.h>
2520 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2521 (unsigned long) ino);
2522 return ERR_PTR(-EIO);
2524 + dx_propagate_tag(nd, inode);
2526 return d_splice_alias(inode, dentry);
2528 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2529 .removexattr = generic_removexattr,
2531 .setattr = ext2_setattr,
2532 + .sync_flags = ext2_sync_flags,
2533 .get_acl = ext2_get_acl,
2536 diff -NurpP --minimal linux-3.9.4/fs/ext2/super.c linux-3.9.4-vs2.3.6.1/fs/ext2/super.c
2537 --- linux-3.9.4/fs/ext2/super.c 2013-05-31 13:45:23.000000000 +0000
2538 +++ linux-3.9.4-vs2.3.6.1/fs/ext2/super.c 2013-05-31 14:47:11.000000000 +0000
2539 @@ -395,7 +395,8 @@ enum {
2540 Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2541 Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2542 Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2543 - Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2544 + Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2545 + Opt_tag, Opt_notag, Opt_tagid
2548 static const match_table_t tokens = {
2549 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2551 {Opt_noacl, "noacl"},
2554 + {Opt_notag, "notag"},
2555 + {Opt_tagid, "tagid=%u"},
2556 {Opt_grpquota, "grpquota"},
2557 {Opt_ignore, "noquota"},
2558 {Opt_quota, "quota"},
2559 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2561 set_opt (sbi->s_mount_opt, NO_UID32);
2563 +#ifndef CONFIG_TAGGING_NONE
2565 + set_opt (sbi->s_mount_opt, TAGGED);
2568 + clear_opt (sbi->s_mount_opt, TAGGED);
2571 +#ifdef CONFIG_PROPAGATE
2574 + set_opt (sbi->s_mount_opt, TAGGED);
2578 clear_opt (sbi->s_mount_opt, CHECK);
2580 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2581 if (!parse_options((char *) data, sb))
2584 + if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2585 + sb->s_flags |= MS_TAGGED;
2586 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2587 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2589 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2594 + if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2595 + !(sb->s_flags & MS_TAGGED)) {
2596 + printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2599 + goto restore_opts;
2602 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2603 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2604 diff -NurpP --minimal linux-3.9.4/fs/ext3/ext3.h linux-3.9.4-vs2.3.6.1/fs/ext3/ext3.h
2605 --- linux-3.9.4/fs/ext3/ext3.h 2012-12-11 03:30:57.000000000 +0000
2606 +++ linux-3.9.4-vs2.3.6.1/fs/ext3/ext3.h 2013-05-31 14:47:11.000000000 +0000
2607 @@ -151,10 +151,14 @@ struct ext3_group_desc
2608 #define EXT3_NOTAIL_FL 0x00008000 /* file tail should not be merged */
2609 #define EXT3_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
2610 #define EXT3_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
2611 +#define EXT3_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
2612 #define EXT3_RESERVED_FL 0x80000000 /* reserved for ext3 lib */
2614 -#define EXT3_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
2615 -#define EXT3_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
2616 +#define EXT3_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2617 +#define EXT3_COW_FL 0x20000000 /* Copy on Write marker */
2619 +#define EXT3_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
2620 +#define EXT3_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
2622 /* Flags that should be inherited by new inodes from their parent. */
2623 #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2624 @@ -290,7 +294,8 @@ struct ext3_inode {
2626 __le16 l_i_uid_high; /* these 2 fields */
2627 __le16 l_i_gid_high; /* were reserved2[0] */
2628 - __u32 l_i_reserved2;
2629 + __le16 l_i_tag; /* Context Tag */
2630 + __u16 l_i_reserved2;
2633 __u8 h_i_frag; /* Fragment number */
2634 @@ -320,6 +325,7 @@ struct ext3_inode {
2635 #define i_gid_low i_gid
2636 #define i_uid_high osd2.linux2.l_i_uid_high
2637 #define i_gid_high osd2.linux2.l_i_gid_high
2638 +#define i_raw_tag osd2.linux2.l_i_tag
2639 #define i_reserved2 osd2.linux2.l_i_reserved2
2642 @@ -364,6 +370,7 @@ struct ext3_inode {
2643 #define EXT3_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
2644 #define EXT3_MOUNT_DATA_ERR_ABORT 0x400000 /* Abort on file data write
2645 * error in ordered mode */
2646 +#define EXT3_MOUNT_TAGGED (1<<24) /* Enable Context Tags */
2648 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2649 #ifndef _LINUX_EXT2_FS_H
2650 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2651 extern void ext3_set_aops(struct inode *inode);
2652 extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2653 u64 start, u64 len);
2654 +extern int ext3_sync_flags(struct inode *, int, int);
2657 extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2658 diff -NurpP --minimal linux-3.9.4/fs/ext3/file.c linux-3.9.4-vs2.3.6.1/fs/ext3/file.c
2659 --- linux-3.9.4/fs/ext3/file.c 2012-12-11 03:30:57.000000000 +0000
2660 +++ linux-3.9.4-vs2.3.6.1/fs/ext3/file.c 2013-05-31 14:47:11.000000000 +0000
2661 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2663 .get_acl = ext3_get_acl,
2664 .fiemap = ext3_fiemap,
2665 + .sync_flags = ext3_sync_flags,
2668 diff -NurpP --minimal linux-3.9.4/fs/ext3/ialloc.c linux-3.9.4-vs2.3.6.1/fs/ext3/ialloc.c
2669 --- linux-3.9.4/fs/ext3/ialloc.c 2012-12-11 03:30:57.000000000 +0000
2670 +++ linux-3.9.4-vs2.3.6.1/fs/ext3/ialloc.c 2013-05-31 14:47:11.000000000 +0000
2673 #include <linux/quotaops.h>
2674 #include <linux/random.h>
2675 +#include <linux/vs_tag.h>
2679 @@ -469,6 +470,7 @@ got:
2680 inode->i_mode = mode;
2681 inode->i_uid = current_fsuid();
2682 inode->i_gid = dir->i_gid;
2683 + inode->i_tag = dx_current_fstag(sb);
2685 inode_init_owner(inode, dir, mode);
2687 diff -NurpP --minimal linux-3.9.4/fs/ext3/inode.c linux-3.9.4-vs2.3.6.1/fs/ext3/inode.c
2688 --- linux-3.9.4/fs/ext3/inode.c 2013-05-31 13:45:23.000000000 +0000
2689 +++ linux-3.9.4-vs2.3.6.1/fs/ext3/inode.c 2013-05-31 14:47:11.000000000 +0000
2691 #include <linux/writeback.h>
2692 #include <linux/mpage.h>
2693 #include <linux/namei.h>
2694 +#include <linux/vs_tag.h>
2699 @@ -2851,36 +2853,60 @@ void ext3_set_inode_flags(struct inode *
2701 unsigned int flags = EXT3_I(inode)->i_flags;
2703 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2704 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2705 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2707 + if (flags & EXT3_IMMUTABLE_FL)
2708 + inode->i_flags |= S_IMMUTABLE;
2709 + if (flags & EXT3_IXUNLINK_FL)
2710 + inode->i_flags |= S_IXUNLINK;
2712 if (flags & EXT3_SYNC_FL)
2713 inode->i_flags |= S_SYNC;
2714 if (flags & EXT3_APPEND_FL)
2715 inode->i_flags |= S_APPEND;
2716 - if (flags & EXT3_IMMUTABLE_FL)
2717 - inode->i_flags |= S_IMMUTABLE;
2718 if (flags & EXT3_NOATIME_FL)
2719 inode->i_flags |= S_NOATIME;
2720 if (flags & EXT3_DIRSYNC_FL)
2721 inode->i_flags |= S_DIRSYNC;
2723 + inode->i_vflags &= ~(V_BARRIER | V_COW);
2725 + if (flags & EXT3_BARRIER_FL)
2726 + inode->i_vflags |= V_BARRIER;
2727 + if (flags & EXT3_COW_FL)
2728 + inode->i_vflags |= V_COW;
2731 /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2732 void ext3_get_inode_flags(struct ext3_inode_info *ei)
2734 unsigned int flags = ei->vfs_inode.i_flags;
2735 + unsigned int vflags = ei->vfs_inode.i_vflags;
2737 + ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2738 + EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2739 + EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2740 + EXT3_BARRIER_FL | EXT3_COW_FL);
2742 + if (flags & S_IMMUTABLE)
2743 + ei->i_flags |= EXT3_IMMUTABLE_FL;
2744 + if (flags & S_IXUNLINK)
2745 + ei->i_flags |= EXT3_IXUNLINK_FL;
2747 - ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2748 - EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2750 ei->i_flags |= EXT3_SYNC_FL;
2751 if (flags & S_APPEND)
2752 ei->i_flags |= EXT3_APPEND_FL;
2753 - if (flags & S_IMMUTABLE)
2754 - ei->i_flags |= EXT3_IMMUTABLE_FL;
2755 if (flags & S_NOATIME)
2756 ei->i_flags |= EXT3_NOATIME_FL;
2757 if (flags & S_DIRSYNC)
2758 ei->i_flags |= EXT3_DIRSYNC_FL;
2760 + if (vflags & V_BARRIER)
2761 + ei->i_flags |= EXT3_BARRIER_FL;
2762 + if (vflags & V_COW)
2763 + ei->i_flags |= EXT3_COW_FL;
2766 struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2767 @@ -2918,8 +2944,10 @@ struct inode *ext3_iget(struct super_blo
2768 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2769 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2771 - i_uid_write(inode, i_uid);
2772 - i_gid_write(inode, i_gid);
2773 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2774 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2775 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2776 + le16_to_cpu(raw_inode->i_raw_tag)));
2777 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2778 inode->i_size = le32_to_cpu(raw_inode->i_size);
2779 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2780 @@ -3091,8 +3119,10 @@ again:
2782 ext3_get_inode_flags(ei);
2783 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2784 - i_uid = i_uid_read(inode);
2785 - i_gid = i_gid_read(inode);
2786 + i_uid = TAGINO_UID(DX_TAG(inode),
2787 + i_uid_read(inode), i_tag_read(inode));
2788 + i_gid = TAGINO_GID(DX_TAG(inode),
2789 + i_gid_read(inode), i_tag_read(inode));
2790 if(!(test_opt(inode->i_sb, NO_UID32))) {
2791 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2792 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2793 @@ -3117,6 +3147,9 @@ again:
2794 raw_inode->i_uid_high = 0;
2795 raw_inode->i_gid_high = 0;
2797 +#ifdef CONFIG_TAGGING_INTERN
2798 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2800 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2801 disksize = cpu_to_le32(ei->i_disksize);
2802 if (disksize != raw_inode->i_size) {
2803 @@ -3285,7 +3318,8 @@ int ext3_setattr(struct dentry *dentry,
2804 if (is_quota_modification(inode, attr))
2805 dquot_initialize(inode);
2806 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2807 - (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2808 + (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2809 + (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2812 /* (user+group)*(old+new) structure, inode write (sb,
2813 @@ -3307,6 +3341,8 @@ int ext3_setattr(struct dentry *dentry,
2814 inode->i_uid = attr->ia_uid;
2815 if (attr->ia_valid & ATTR_GID)
2816 inode->i_gid = attr->ia_gid;
2817 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2818 + inode->i_tag = attr->ia_tag;
2819 error = ext3_mark_inode_dirty(handle, inode);
2820 ext3_journal_stop(handle);
2822 diff -NurpP --minimal linux-3.9.4/fs/ext3/ioctl.c linux-3.9.4-vs2.3.6.1/fs/ext3/ioctl.c
2823 --- linux-3.9.4/fs/ext3/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2824 +++ linux-3.9.4-vs2.3.6.1/fs/ext3/ioctl.c 2013-05-31 14:47:11.000000000 +0000
2826 #include <asm/uaccess.h>
2830 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2832 + handle_t *handle = NULL;
2833 + struct ext3_iloc iloc;
2836 + handle = ext3_journal_start(inode, 1);
2837 + if (IS_ERR(handle))
2838 + return PTR_ERR(handle);
2840 + if (IS_SYNC(inode))
2841 + handle->h_sync = 1;
2842 + err = ext3_reserve_inode_write(handle, inode, &iloc);
2846 + inode->i_flags = flags;
2847 + inode->i_vflags = vflags;
2848 + ext3_get_inode_flags(EXT3_I(inode));
2849 + inode->i_ctime = CURRENT_TIME_SEC;
2851 + err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2853 + ext3_journal_stop(handle);
2857 long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2859 struct inode *inode = file_inode(filp);
2860 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2862 flags = ext3_mask_flags(inode->i_mode, flags);
2864 + if (IS_BARRIER(inode)) {
2865 + vxwprintk_task(1, "messing with the barrier.");
2869 mutex_lock(&inode->i_mutex);
2871 /* Is it quota file? Do not allow user to mess with it */
2872 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2874 * This test looks nicer. Thanks to Pauline Middelink
2876 - if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2877 + if ((oldflags & EXT3_IMMUTABLE_FL) ||
2878 + ((flags ^ oldflags) & (EXT3_APPEND_FL |
2879 + EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2880 if (!capable(CAP_LINUX_IMMUTABLE))
2883 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2887 - flags = flags & EXT3_FL_USER_MODIFIABLE;
2888 + flags &= EXT3_FL_USER_MODIFIABLE;
2889 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2890 ei->i_flags = flags;
2892 diff -NurpP --minimal linux-3.9.4/fs/ext3/namei.c linux-3.9.4-vs2.3.6.1/fs/ext3/namei.c
2893 --- linux-3.9.4/fs/ext3/namei.c 2013-05-31 13:45:23.000000000 +0000
2894 +++ linux-3.9.4-vs2.3.6.1/fs/ext3/namei.c 2013-05-31 14:47:11.000000000 +0000
2898 #include <linux/quotaops.h>
2899 +#include <linux/vs_tag.h>
2904 @@ -918,6 +920,7 @@ restart:
2905 submit_bh(READ | REQ_META | REQ_PRIO,
2908 + dx_propagate_tag(nd, inode);
2911 if ((bh = bh_use[ra_ptr++]) == NULL)
2912 @@ -2527,6 +2530,7 @@ const struct inode_operations ext3_dir_i
2913 .listxattr = ext3_listxattr,
2914 .removexattr = generic_removexattr,
2916 + .sync_flags = ext3_sync_flags,
2917 .get_acl = ext3_get_acl,
2920 diff -NurpP --minimal linux-3.9.4/fs/ext3/super.c linux-3.9.4-vs2.3.6.1/fs/ext3/super.c
2921 --- linux-3.9.4/fs/ext3/super.c 2013-05-31 13:45:23.000000000 +0000
2922 +++ linux-3.9.4-vs2.3.6.1/fs/ext3/super.c 2013-05-31 14:47:11.000000000 +0000
2923 @@ -816,7 +816,8 @@ enum {
2924 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2925 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2926 Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2927 - Opt_resize, Opt_usrquota, Opt_grpquota
2928 + Opt_resize, Opt_usrquota, Opt_grpquota,
2929 + Opt_tag, Opt_notag, Opt_tagid
2932 static const match_table_t tokens = {
2933 @@ -873,6 +874,9 @@ static const match_table_t tokens = {
2934 {Opt_barrier, "barrier"},
2935 {Opt_nobarrier, "nobarrier"},
2936 {Opt_resize, "resize"},
2938 + {Opt_notag, "notag"},
2939 + {Opt_tagid, "tagid=%u"},
2943 @@ -1040,6 +1044,20 @@ static int parse_options (char *options,
2945 set_opt (sbi->s_mount_opt, NO_UID32);
2947 +#ifndef CONFIG_TAGGING_NONE
2949 + set_opt (sbi->s_mount_opt, TAGGED);
2952 + clear_opt (sbi->s_mount_opt, TAGGED);
2955 +#ifdef CONFIG_PROPAGATE
2958 + set_opt (sbi->s_mount_opt, TAGGED);
2962 clear_opt (sbi->s_mount_opt, CHECK);
2964 @@ -1737,6 +1755,9 @@ static int ext3_fill_super (struct super
2968 + if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2969 + sb->s_flags |= MS_TAGGED;
2971 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2972 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2974 @@ -2633,6 +2654,14 @@ static int ext3_remount (struct super_bl
2975 if (test_opt(sb, ABORT))
2976 ext3_abort(sb, __func__, "Abort forced by user");
2978 + if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2979 + !(sb->s_flags & MS_TAGGED)) {
2980 + printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2983 + goto restore_opts;
2986 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2987 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2989 diff -NurpP --minimal linux-3.9.4/fs/ext4/ext4.h linux-3.9.4-vs2.3.6.1/fs/ext4/ext4.h
2990 --- linux-3.9.4/fs/ext4/ext4.h 2013-05-31 13:45:23.000000000 +0000
2991 +++ linux-3.9.4-vs2.3.6.1/fs/ext4/ext4.h 2013-05-31 16:22:49.000000000 +0000
2992 @@ -399,7 +399,10 @@ struct flex_groups {
2993 #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
2994 #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
2995 #define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
2996 +#define EXT4_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2997 +#define EXT4_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
2998 #define EXT4_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */
2999 +#define EXT4_COW_FL 0x20000000 /* Copy on Write marker */
3000 #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
3002 #define EXT4_FL_USER_VISIBLE 0x004BDFFF /* User visible flags */
3003 @@ -674,7 +677,7 @@ struct ext4_inode {
3004 __le16 l_i_uid_high; /* these 2 fields */
3005 __le16 l_i_gid_high; /* were reserved2[0] */
3006 __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
3007 - __le16 l_i_reserved;
3008 + __le16 l_i_tag; /* Context Tag */
3011 __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
3012 @@ -792,6 +795,7 @@ do { \
3013 #define i_gid_low i_gid
3014 #define i_uid_high osd2.linux2.l_i_uid_high
3015 #define i_gid_high osd2.linux2.l_i_gid_high
3016 +#define i_raw_tag osd2.linux2.l_i_tag
3017 #define i_checksum_lo osd2.linux2.l_i_checksum_lo
3019 #elif defined(__GNU__)
3020 @@ -969,6 +973,7 @@ struct ext4_inode_info {
3021 #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
3022 #define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */
3023 #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */
3024 +#define EXT4_MOUNT_TAGGED 0x40000 /* Enable Context Tags */
3025 #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */
3026 #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
3027 #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
3028 @@ -2527,6 +2532,7 @@ extern struct buffer_head *ext4_get_firs
3029 extern int ext4_inline_data_fiemap(struct inode *inode,
3030 struct fiemap_extent_info *fieinfo,
3032 +extern int ext4_sync_flags(struct inode *, int, int);
3033 extern int ext4_try_to_evict_inline_data(handle_t *handle,
3034 struct inode *inode,
3036 diff -NurpP --minimal linux-3.9.4/fs/ext4/file.c linux-3.9.4-vs2.3.6.1/fs/ext4/file.c
3037 --- linux-3.9.4/fs/ext4/file.c 2013-05-31 13:45:23.000000000 +0000
3038 +++ linux-3.9.4-vs2.3.6.1/fs/ext4/file.c 2013-05-31 14:47:11.000000000 +0000
3039 @@ -650,5 +650,6 @@ const struct inode_operations ext4_file_
3040 .removexattr = generic_removexattr,
3041 .get_acl = ext4_get_acl,
3042 .fiemap = ext4_fiemap,
3043 + .sync_flags = ext4_sync_flags,
3046 diff -NurpP --minimal linux-3.9.4/fs/ext4/ialloc.c linux-3.9.4-vs2.3.6.1/fs/ext4/ialloc.c
3047 --- linux-3.9.4/fs/ext4/ialloc.c 2013-05-31 13:45:23.000000000 +0000
3048 +++ linux-3.9.4-vs2.3.6.1/fs/ext4/ialloc.c 2013-05-31 14:47:11.000000000 +0000
3050 #include <linux/random.h>
3051 #include <linux/bitops.h>
3052 #include <linux/blkdev.h>
3053 +#include <linux/vs_tag.h>
3054 #include <asm/byteorder.h>
3057 @@ -859,6 +860,7 @@ got:
3058 inode->i_mode = mode;
3059 inode->i_uid = current_fsuid();
3060 inode->i_gid = dir->i_gid;
3061 + inode->i_tag = dx_current_fstag(sb);
3063 inode_init_owner(inode, dir, mode);
3065 diff -NurpP --minimal linux-3.9.4/fs/ext4/inode.c linux-3.9.4-vs2.3.6.1/fs/ext4/inode.c
3066 --- linux-3.9.4/fs/ext4/inode.c 2013-05-31 14:22:27.000000000 +0000
3067 +++ linux-3.9.4-vs2.3.6.1/fs/ext4/inode.c 2013-05-31 14:47:11.000000000 +0000
3069 #include <linux/printk.h>
3070 #include <linux/slab.h>
3071 #include <linux/ratelimit.h>
3072 +#include <linux/vs_tag.h>
3074 #include "ext4_jbd2.h"
3076 @@ -3870,41 +3871,64 @@ void ext4_set_inode_flags(struct inode *
3078 unsigned int flags = EXT4_I(inode)->i_flags;
3080 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3081 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3082 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3084 + if (flags & EXT4_IMMUTABLE_FL)
3085 + inode->i_flags |= S_IMMUTABLE;
3086 + if (flags & EXT4_IXUNLINK_FL)
3087 + inode->i_flags |= S_IXUNLINK;
3089 if (flags & EXT4_SYNC_FL)
3090 inode->i_flags |= S_SYNC;
3091 if (flags & EXT4_APPEND_FL)
3092 inode->i_flags |= S_APPEND;
3093 - if (flags & EXT4_IMMUTABLE_FL)
3094 - inode->i_flags |= S_IMMUTABLE;
3095 if (flags & EXT4_NOATIME_FL)
3096 inode->i_flags |= S_NOATIME;
3097 if (flags & EXT4_DIRSYNC_FL)
3098 inode->i_flags |= S_DIRSYNC;
3100 + inode->i_vflags &= ~(V_BARRIER | V_COW);
3102 + if (flags & EXT4_BARRIER_FL)
3103 + inode->i_vflags |= V_BARRIER;
3104 + if (flags & EXT4_COW_FL)
3105 + inode->i_vflags |= V_COW;
3108 /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3109 void ext4_get_inode_flags(struct ext4_inode_info *ei)
3111 - unsigned int vfs_fl;
3112 + unsigned int vfs_fl, vfs_vf;
3113 unsigned long old_fl, new_fl;
3116 vfs_fl = ei->vfs_inode.i_flags;
3117 + vfs_vf = ei->vfs_inode.i_vflags;
3118 old_fl = ei->i_flags;
3119 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3120 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3122 + EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3125 + if (vfs_fl & S_IMMUTABLE)
3126 + new_fl |= EXT4_IMMUTABLE_FL;
3127 + if (vfs_fl & S_IXUNLINK)
3128 + new_fl |= EXT4_IXUNLINK_FL;
3130 if (vfs_fl & S_SYNC)
3131 new_fl |= EXT4_SYNC_FL;
3132 if (vfs_fl & S_APPEND)
3133 new_fl |= EXT4_APPEND_FL;
3134 - if (vfs_fl & S_IMMUTABLE)
3135 - new_fl |= EXT4_IMMUTABLE_FL;
3136 if (vfs_fl & S_NOATIME)
3137 new_fl |= EXT4_NOATIME_FL;
3138 if (vfs_fl & S_DIRSYNC)
3139 new_fl |= EXT4_DIRSYNC_FL;
3141 + if (vfs_vf & V_BARRIER)
3142 + new_fl |= EXT4_BARRIER_FL;
3143 + if (vfs_vf & V_COW)
3144 + new_fl |= EXT4_COW_FL;
3145 } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3148 @@ -4009,8 +4033,10 @@ struct inode *ext4_iget(struct super_blo
3149 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3150 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3152 - i_uid_write(inode, i_uid);
3153 - i_gid_write(inode, i_gid);
3154 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3155 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3156 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3157 + le16_to_cpu(raw_inode->i_raw_tag)));
3158 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3160 ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */
3161 @@ -4233,8 +4259,10 @@ static int ext4_do_update_inode(handle_t
3163 ext4_get_inode_flags(ei);
3164 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3165 - i_uid = i_uid_read(inode);
3166 - i_gid = i_gid_read(inode);
3167 + i_uid = TAGINO_UID(DX_TAG(inode),
3168 + i_uid_read(inode), i_tag_read(inode));
3169 + i_gid = TAGINO_GID(DX_TAG(inode),
3170 + i_gid_read(inode), i_tag_read(inode));
3171 if (!(test_opt(inode->i_sb, NO_UID32))) {
3172 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3173 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3174 @@ -4257,6 +4285,9 @@ static int ext4_do_update_inode(handle_t
3175 raw_inode->i_uid_high = 0;
3176 raw_inode->i_gid_high = 0;
3178 +#ifdef CONFIG_TAGGING_INTERN
3179 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3181 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3183 EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3184 @@ -4487,7 +4518,8 @@ int ext4_setattr(struct dentry *dentry,
3185 if (is_quota_modification(inode, attr))
3186 dquot_initialize(inode);
3187 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3188 - (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3189 + (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3190 + (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3193 /* (user+group)*(old+new) structure, inode write (sb,
3194 @@ -4510,6 +4542,8 @@ int ext4_setattr(struct dentry *dentry,
3195 inode->i_uid = attr->ia_uid;
3196 if (attr->ia_valid & ATTR_GID)
3197 inode->i_gid = attr->ia_gid;
3198 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3199 + inode->i_tag = attr->ia_tag;
3200 error = ext4_mark_inode_dirty(handle, inode);
3201 ext4_journal_stop(handle);
3203 diff -NurpP --minimal linux-3.9.4/fs/ext4/ioctl.c linux-3.9.4-vs2.3.6.1/fs/ext4/ioctl.c
3204 --- linux-3.9.4/fs/ext4/ioctl.c 2013-05-31 13:45:23.000000000 +0000
3205 +++ linux-3.9.4-vs2.3.6.1/fs/ext4/ioctl.c 2013-05-31 19:50:08.000000000 +0000
3207 #include <linux/compat.h>
3208 #include <linux/mount.h>
3209 #include <linux/file.h>
3210 +#include <linux/vs_tag.h>
3211 #include <asm/uaccess.h>
3212 #include "ext4_jbd2.h"
3215 #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3217 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3219 + handle_t *handle = NULL;
3220 + struct ext4_iloc iloc;
3223 + handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3224 + if (IS_ERR(handle))
3225 + return PTR_ERR(handle);
3227 + if (IS_SYNC(inode))
3228 + ext4_handle_sync(handle);
3229 + err = ext4_reserve_inode_write(handle, inode, &iloc);
3233 + inode->i_flags = flags;
3234 + inode->i_vflags = vflags;
3235 + ext4_get_inode_flags(EXT4_I(inode));
3236 + inode->i_ctime = ext4_current_time(inode);
3238 + err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3240 + ext4_journal_stop(handle);
3244 long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3246 struct inode *inode = file_inode(filp);
3247 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3249 flags = ext4_mask_flags(inode->i_mode, flags);
3251 + if (IS_BARRIER(inode)) {
3252 + vxwprintk_task(1, "messing with the barrier.");
3257 mutex_lock(&inode->i_mutex);
3258 /* Is it quota file? Do not allow user to mess with it */
3259 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3261 * This test looks nicer. Thanks to Pauline Middelink
3263 - if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3264 + if ((oldflags & EXT4_IMMUTABLE_FL) ||
3265 + ((flags ^ oldflags) & (EXT4_APPEND_FL |
3266 + EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3267 if (!capable(CAP_LINUX_IMMUTABLE))
3270 diff -NurpP --minimal linux-3.9.4/fs/ext4/namei.c linux-3.9.4-vs2.3.6.1/fs/ext4/namei.c
3271 --- linux-3.9.4/fs/ext4/namei.c 2013-05-31 13:45:23.000000000 +0000
3272 +++ linux-3.9.4-vs2.3.6.1/fs/ext4/namei.c 2013-05-31 14:47:11.000000000 +0000
3274 #include <linux/quotaops.h>
3275 #include <linux/buffer_head.h>
3276 #include <linux/bio.h>
3277 +#include <linux/vs_tag.h>
3279 #include "ext4_jbd2.h"
3281 @@ -1290,6 +1291,7 @@ restart:
3282 ll_rw_block(READ | REQ_META | REQ_PRIO,
3285 + dx_propagate_tag(nd, inode);
3287 if ((bh = bh_use[ra_ptr++]) == NULL)
3289 @@ -3190,6 +3192,7 @@ const struct inode_operations ext4_dir_i
3290 .removexattr = generic_removexattr,
3291 .get_acl = ext4_get_acl,
3292 .fiemap = ext4_fiemap,
3293 + .sync_flags = ext4_sync_flags,
3296 const struct inode_operations ext4_special_inode_operations = {
3297 diff -NurpP --minimal linux-3.9.4/fs/ext4/super.c linux-3.9.4-vs2.3.6.1/fs/ext4/super.c
3298 --- linux-3.9.4/fs/ext4/super.c 2013-05-31 14:22:27.000000000 +0000
3299 +++ linux-3.9.4-vs2.3.6.1/fs/ext4/super.c 2013-05-31 14:47:11.000000000 +0000
3300 @@ -1131,7 +1131,7 @@ enum {
3301 Opt_inode_readahead_blks, Opt_journal_ioprio,
3302 Opt_dioread_nolock, Opt_dioread_lock,
3303 Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3304 - Opt_max_dir_size_kb,
3305 + Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3308 static const match_table_t tokens = {
3309 @@ -1211,6 +1211,9 @@ static const match_table_t tokens = {
3310 {Opt_removed, "reservation"}, /* mount option from ext2/3 */
3311 {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3312 {Opt_removed, "journal=%u"}, /* mount option from ext2/3 */
3314 + {Opt_notag, "notag"},
3315 + {Opt_tagid, "tagid=%u"},
3319 @@ -1441,6 +1444,20 @@ static int handle_mount_opt(struct super
3321 sb->s_flags |= MS_I_VERSION;
3323 +#ifndef CONFIG_TAGGING_NONE
3325 + set_opt(sb, TAGGED);
3328 + clear_opt(sb, TAGGED);
3331 +#ifdef CONFIG_PROPAGATE
3334 + set_opt(sb, TAGGED);
3339 for (m = ext4_mount_opts; m->token != Opt_err; m++)
3340 @@ -3401,6 +3418,9 @@ static int ext4_fill_super(struct super_
3341 clear_opt(sb, DELALLOC);
3344 + if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3345 + sb->s_flags |= MS_TAGGED;
3347 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3348 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3350 @@ -4587,6 +4607,14 @@ static int ext4_remount(struct super_blo
3351 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3352 ext4_abort(sb, "Abort forced by user");
3354 + if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3355 + !(sb->s_flags & MS_TAGGED)) {
3356 + printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3359 + goto restore_opts;
3362 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3363 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3365 diff -NurpP --minimal linux-3.9.4/fs/fcntl.c linux-3.9.4-vs2.3.6.1/fs/fcntl.c
3366 --- linux-3.9.4/fs/fcntl.c 2013-05-31 13:45:23.000000000 +0000
3367 +++ linux-3.9.4-vs2.3.6.1/fs/fcntl.c 2013-05-31 14:47:11.000000000 +0000
3369 #include <linux/rcupdate.h>
3370 #include <linux/pid_namespace.h>
3371 #include <linux/user_namespace.h>
3372 +#include <linux/vs_limit.h>
3374 #include <asm/poll.h>
3375 #include <asm/siginfo.h>
3376 @@ -378,6 +379,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3380 + if (!vx_files_avail(1))
3383 if (unlikely(f.file->f_mode & FMODE_PATH)) {
3384 if (!check_fcntl_cmd(cmd))
3385 diff -NurpP --minimal linux-3.9.4/fs/file.c linux-3.9.4-vs2.3.6.1/fs/file.c
3386 --- linux-3.9.4/fs/file.c 2013-05-31 13:45:23.000000000 +0000
3387 +++ linux-3.9.4-vs2.3.6.1/fs/file.c 2013-05-31 14:47:11.000000000 +0000
3389 #include <linux/spinlock.h>
3390 #include <linux/rcupdate.h>
3391 #include <linux/workqueue.h>
3392 +#include <linux/vs_limit.h>
3394 struct fdtable_defer {
3396 @@ -364,6 +365,8 @@ struct files_struct *dup_fd(struct files
3397 struct file *f = *old_fds++;
3400 + /* TODO: sum it first for check and performance */
3401 + vx_openfd_inc(open_files - i);
3404 * The fd may be claimed in the fd bitmap but not yet
3405 @@ -429,9 +432,11 @@ static void close_files(struct files_str
3406 filp_close(file, files);
3417 @@ -567,6 +572,7 @@ repeat:
3419 __clear_close_on_exec(fd, fdt);
3421 + vx_openfd_inc(fd);
3424 if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3425 @@ -597,6 +603,7 @@ static void __put_unused_fd(struct files
3426 __clear_open_fd(fd, fdt);
3427 if (fd < files->next_fd)
3428 files->next_fd = fd;
3429 + vx_openfd_dec(fd);
3432 void put_unused_fd(unsigned int fd)
3433 @@ -876,6 +883,8 @@ static int do_dup2(struct files_struct *
3436 filp_close(tofree, files);
3438 + vx_openfd_inc(fd); /* fd was unused */
3442 diff -NurpP --minimal linux-3.9.4/fs/file_table.c linux-3.9.4-vs2.3.6.1/fs/file_table.c
3443 --- linux-3.9.4/fs/file_table.c 2013-05-31 13:45:23.000000000 +0000
3444 +++ linux-3.9.4-vs2.3.6.1/fs/file_table.c 2013-05-31 14:47:11.000000000 +0000
3446 #include <linux/hardirq.h>
3447 #include <linux/task_work.h>
3448 #include <linux/ima.h>
3449 +#include <linux/vs_limit.h>
3450 +#include <linux/vs_context.h>
3452 #include <linux/atomic.h>
3454 @@ -140,6 +142,8 @@ struct file *get_empty_filp(void)
3455 spin_lock_init(&f->f_lock);
3456 eventpoll_init_file(f);
3457 /* f->f_version: 0 */
3458 + f->f_xid = vx_current_xid();
3463 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3464 i_readcount_dec(inode);
3465 if (file->f_mode & FMODE_WRITE)
3466 drop_file_write_access(file);
3467 + vx_files_dec(file);
3469 file->f_path.dentry = NULL;
3470 file->f_path.mnt = NULL;
3471 file->f_inode = NULL;
3472 @@ -344,6 +350,8 @@ void put_filp(struct file *file)
3474 if (atomic_long_dec_and_test(&file->f_count)) {
3475 security_file_free(file);
3476 + vx_files_dec(file);
3478 file_sb_list_del(file);
3481 diff -NurpP --minimal linux-3.9.4/fs/fs_struct.c linux-3.9.4-vs2.3.6.1/fs/fs_struct.c
3482 --- linux-3.9.4/fs/fs_struct.c 2013-05-31 13:45:23.000000000 +0000
3483 +++ linux-3.9.4-vs2.3.6.1/fs/fs_struct.c 2013-05-31 14:47:11.000000000 +0000
3485 #include <linux/path.h>
3486 #include <linux/slab.h>
3487 #include <linux/fs_struct.h>
3488 +#include <linux/vserver/global.h>
3489 #include "internal.h"
3492 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3494 path_put(&fs->root);
3496 + atomic_dec(&vs_global_fs);
3497 kmem_cache_free(fs_cachep, fs);
3500 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3503 spin_unlock(&old->lock);
3504 + atomic_inc(&vs_global_fs);
3508 diff -NurpP --minimal linux-3.9.4/fs/gfs2/file.c linux-3.9.4-vs2.3.6.1/fs/gfs2/file.c
3509 --- linux-3.9.4/fs/gfs2/file.c 2013-05-31 13:45:23.000000000 +0000
3510 +++ linux-3.9.4-vs2.3.6.1/fs/gfs2/file.c 2013-05-31 19:54:27.000000000 +0000
3511 @@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3512 [12] = GFS2_DIF_EXHASH,
3513 [14] = GFS2_DIF_INHERIT_JDATA,
3514 [17] = GFS2_DIF_TOPDIR,
3515 + [27] = GFS2_DIF_IXUNLINK,
3516 + [26] = GFS2_DIF_BARRIER,
3517 + [29] = GFS2_DIF_COW,
3520 static const u32 gfs2_to_fsflags[32] = {
3521 @@ -153,6 +156,9 @@ static const u32 gfs2_to_fsflags[32] = {
3522 [gfs2fl_ExHash] = FS_INDEX_FL,
3523 [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3524 [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3525 + [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3526 + [gfs2fl_Barrier] = FS_BARRIER_FL,
3527 + [gfs2fl_Cow] = FS_COW_FL,
3530 static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3531 @@ -183,12 +189,18 @@ void gfs2_set_inode_flags(struct inode *
3533 struct gfs2_inode *ip = GFS2_I(inode);
3534 unsigned int flags = inode->i_flags;
3535 + unsigned int vflags = inode->i_vflags;
3537 + flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3538 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3540 - flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3541 if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3542 inode->i_flags |= S_NOSEC;
3543 if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3544 flags |= S_IMMUTABLE;
3545 + if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3546 + flags |= S_IXUNLINK;
3548 if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3550 if (ip->i_diskflags & GFS2_DIF_NOATIME)
3551 @@ -196,6 +208,43 @@ void gfs2_set_inode_flags(struct inode *
3552 if (ip->i_diskflags & GFS2_DIF_SYNC)
3554 inode->i_flags = flags;
3556 + vflags &= ~(V_BARRIER | V_COW);
3558 + if (ip->i_diskflags & GFS2_DIF_BARRIER)
3559 + vflags |= V_BARRIER;
3560 + if (ip->i_diskflags & GFS2_DIF_COW)
3562 + inode->i_vflags = vflags;
3565 +void gfs2_get_inode_flags(struct inode *inode)
3567 + struct gfs2_inode *ip = GFS2_I(inode);
3568 + unsigned int flags = inode->i_flags;
3569 + unsigned int vflags = inode->i_vflags;
3571 + ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3572 + GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3573 + GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3574 + GFS2_DIF_BARRIER | GFS2_DIF_COW);
3576 + if (flags & S_IMMUTABLE)
3577 + ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3578 + if (flags & S_IXUNLINK)
3579 + ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3581 + if (flags & S_APPEND)
3582 + ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3583 + if (flags & S_NOATIME)
3584 + ip->i_diskflags |= GFS2_DIF_NOATIME;
3585 + if (flags & S_SYNC)
3586 + ip->i_diskflags |= GFS2_DIF_SYNC;
3588 + if (vflags & V_BARRIER)
3589 + ip->i_diskflags |= GFS2_DIF_BARRIER;
3590 + if (vflags & V_COW)
3591 + ip->i_diskflags |= GFS2_DIF_COW;
3594 /* Flags that can be set by user space */
3595 @@ -309,6 +358,37 @@ static int gfs2_set_flags(struct file *f
3596 return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3599 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3601 + struct gfs2_inode *ip = GFS2_I(inode);
3602 + struct gfs2_sbd *sdp = GFS2_SB(inode);
3603 + struct buffer_head *bh;
3604 + struct gfs2_holder gh;
3607 + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3610 + error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3613 + error = gfs2_meta_inode_buffer(ip, &bh);
3615 + goto out_trans_end;
3616 + gfs2_trans_add_meta(ip->i_gl, bh);
3617 + inode->i_flags = flags;
3618 + inode->i_vflags = vflags;
3619 + gfs2_get_inode_flags(inode);
3620 + gfs2_dinode_out(ip, bh->b_data);
3622 + gfs2_set_aops(inode);
3624 + gfs2_trans_end(sdp);
3626 + gfs2_glock_dq_uninit(&gh);
3630 static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3633 diff -NurpP --minimal linux-3.9.4/fs/gfs2/inode.h linux-3.9.4-vs2.3.6.1/fs/gfs2/inode.h
3634 --- linux-3.9.4/fs/gfs2/inode.h 2012-12-11 03:30:57.000000000 +0000
3635 +++ linux-3.9.4-vs2.3.6.1/fs/gfs2/inode.h 2013-05-31 14:47:11.000000000 +0000
3636 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3637 extern const struct file_operations gfs2_dir_fops_nolock;
3639 extern void gfs2_set_inode_flags(struct inode *inode);
3640 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3642 #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3643 extern const struct file_operations gfs2_file_fops;
3644 diff -NurpP --minimal linux-3.9.4/fs/hostfs/hostfs.h linux-3.9.4-vs2.3.6.1/fs/hostfs/hostfs.h
3645 --- linux-3.9.4/fs/hostfs/hostfs.h 2012-12-11 03:30:57.000000000 +0000
3646 +++ linux-3.9.4-vs2.3.6.1/fs/hostfs/hostfs.h 2013-05-31 14:47:11.000000000 +0000
3647 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3648 unsigned short ia_mode;
3653 struct timespec ia_atime;
3654 struct timespec ia_mtime;
3655 diff -NurpP --minimal linux-3.9.4/fs/inode.c linux-3.9.4-vs2.3.6.1/fs/inode.c
3656 --- linux-3.9.4/fs/inode.c 2013-05-31 13:45:24.000000000 +0000
3657 +++ linux-3.9.4-vs2.3.6.1/fs/inode.c 2013-05-31 14:47:11.000000000 +0000
3659 #include <linux/prefetch.h>
3660 #include <linux/buffer_head.h> /* for inode_has_buffers */
3661 #include <linux/ratelimit.h>
3662 +#include <linux/vs_tag.h>
3663 #include "internal.h"
3666 @@ -128,6 +129,8 @@ int inode_init_always(struct super_block
3667 struct address_space *const mapping = &inode->i_data;
3671 + /* essential because of inode slab reuse */
3672 inode->i_blkbits = sb->s_blocksize_bits;
3674 atomic_set(&inode->i_count, 1);
3675 @@ -137,6 +140,7 @@ int inode_init_always(struct super_block
3676 inode->i_opflags = 0;
3677 i_uid_write(inode, 0);
3678 i_gid_write(inode, 0);
3679 + i_tag_write(inode, 0);
3680 atomic_set(&inode->i_writecount, 0);
3682 inode->i_blocks = 0;
3683 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3684 inode->i_bdev = NULL;
3685 inode->i_cdev = NULL;
3687 + inode->i_mdev = 0;
3688 inode->dirtied_when = 0;
3690 if (security_inode_alloc(inode))
3691 @@ -483,6 +488,8 @@ void __insert_inode_hash(struct inode *i
3693 EXPORT_SYMBOL(__insert_inode_hash);
3695 +EXPORT_SYMBOL_GPL(__iget);
3698 * __remove_inode_hash - remove an inode from the hash
3699 * @inode: inode to unhash
3700 @@ -1799,9 +1806,11 @@ void init_special_inode(struct inode *in
3701 if (S_ISCHR(mode)) {
3702 inode->i_fop = &def_chr_fops;
3703 inode->i_rdev = rdev;
3704 + inode->i_mdev = rdev;
3705 } else if (S_ISBLK(mode)) {
3706 inode->i_fop = &def_blk_fops;
3707 inode->i_rdev = rdev;
3708 + inode->i_mdev = rdev;
3709 } else if (S_ISFIFO(mode))
3710 inode->i_fop = &def_fifo_fops;
3711 else if (S_ISSOCK(mode))
3712 @@ -1830,6 +1839,7 @@ void inode_init_owner(struct inode *inod
3714 inode->i_gid = current_fsgid();
3715 inode->i_mode = mode;
3716 + inode->i_tag = dx_current_fstag(inode->i_sb);
3718 EXPORT_SYMBOL(inode_init_owner);
3720 diff -NurpP --minimal linux-3.9.4/fs/ioctl.c linux-3.9.4-vs2.3.6.1/fs/ioctl.c
3721 --- linux-3.9.4/fs/ioctl.c 2013-05-31 13:45:24.000000000 +0000
3722 +++ linux-3.9.4-vs2.3.6.1/fs/ioctl.c 2013-05-31 14:47:11.000000000 +0000
3724 #include <linux/writeback.h>
3725 #include <linux/buffer_head.h>
3726 #include <linux/falloc.h>
3727 +#include <linux/proc_fs.h>
3728 +#include <linux/vserver/inode.h>
3729 +#include <linux/vs_tag.h>
3731 #include <asm/ioctls.h>
3733 diff -NurpP --minimal linux-3.9.4/fs/ioprio.c linux-3.9.4-vs2.3.6.1/fs/ioprio.c
3734 --- linux-3.9.4/fs/ioprio.c 2012-12-11 03:30:57.000000000 +0000
3735 +++ linux-3.9.4-vs2.3.6.1/fs/ioprio.c 2013-05-31 14:47:11.000000000 +0000
3737 #include <linux/syscalls.h>
3738 #include <linux/security.h>
3739 #include <linux/pid_namespace.h>
3740 +#include <linux/vs_base.h>
3742 int set_task_ioprio(struct task_struct *task, int ioprio)
3744 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3746 pgrp = find_vpid(who);
3747 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3748 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3750 ret = set_task_ioprio(p, ioprio);
3753 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3755 pgrp = find_vpid(who);
3756 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3757 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3759 tmpio = get_task_ioprio(p);
3762 diff -NurpP --minimal linux-3.9.4/fs/jfs/file.c linux-3.9.4-vs2.3.6.1/fs/jfs/file.c
3763 --- linux-3.9.4/fs/jfs/file.c 2013-02-19 13:58:48.000000000 +0000
3764 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/file.c 2013-05-31 14:47:11.000000000 +0000
3765 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3766 if (is_quota_modification(inode, iattr))
3767 dquot_initialize(inode);
3768 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3769 - (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3770 + (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3771 + (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3772 rc = dquot_transfer(inode, iattr);
3775 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3776 #ifdef CONFIG_JFS_POSIX_ACL
3777 .get_acl = jfs_get_acl,
3779 + .sync_flags = jfs_sync_flags,
3782 const struct file_operations jfs_file_operations = {
3783 diff -NurpP --minimal linux-3.9.4/fs/jfs/ioctl.c linux-3.9.4-vs2.3.6.1/fs/jfs/ioctl.c
3784 --- linux-3.9.4/fs/jfs/ioctl.c 2013-05-31 13:45:24.000000000 +0000
3785 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/ioctl.c 2013-05-31 14:47:11.000000000 +0000
3787 #include <linux/time.h>
3788 #include <linux/sched.h>
3789 #include <linux/blkdev.h>
3790 +#include <linux/mount.h>
3791 #include <asm/current.h>
3792 #include <asm/uaccess.h>
3794 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3798 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3800 + inode->i_flags = flags;
3801 + inode->i_vflags = vflags;
3802 + jfs_get_inode_flags(JFS_IP(inode));
3803 + inode->i_ctime = CURRENT_TIME_SEC;
3804 + mark_inode_dirty(inode);
3808 long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3810 struct inode *inode = file_inode(filp);
3811 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3812 if (!S_ISDIR(inode->i_mode))
3813 flags &= ~JFS_DIRSYNC_FL;
3815 + if (IS_BARRIER(inode)) {
3816 + vxwprintk_task(1, "messing with the barrier.");
3820 /* Is it quota file? Do not allow user to mess with it */
3821 if (IS_NOQUOTA(inode)) {
3823 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3824 * the relevant capability.
3826 if ((oldflags & JFS_IMMUTABLE_FL) ||
3827 - ((flags ^ oldflags) &
3828 - (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3829 + ((flags ^ oldflags) & (JFS_APPEND_FL |
3830 + JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3831 if (!capable(CAP_LINUX_IMMUTABLE)) {
3832 mutex_unlock(&inode->i_mutex);
3834 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3838 - flags = flags & JFS_FL_USER_MODIFIABLE;
3839 + flags &= JFS_FL_USER_MODIFIABLE;
3840 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3841 jfs_inode->mode2 = flags;
3843 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_dinode.h linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_dinode.h
3844 --- linux-3.9.4/fs/jfs/jfs_dinode.h 2012-12-11 03:30:57.000000000 +0000
3845 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_dinode.h 2013-05-31 14:47:11.000000000 +0000
3846 @@ -161,9 +161,13 @@ struct dinode {
3848 #define JFS_APPEND_FL 0x01000000 /* writes to file may only append */
3849 #define JFS_IMMUTABLE_FL 0x02000000 /* Immutable file */
3850 +#define JFS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
3852 -#define JFS_FL_USER_VISIBLE 0x03F80000
3853 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3854 +#define JFS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
3855 +#define JFS_COW_FL 0x20000000 /* Copy on Write marker */
3857 +#define JFS_FL_USER_VISIBLE 0x07F80000
3858 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3859 #define JFS_FL_INHERIT 0x03C80000
3861 /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3862 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_filsys.h linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_filsys.h
3863 --- linux-3.9.4/fs/jfs/jfs_filsys.h 2012-12-11 03:30:57.000000000 +0000
3864 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_filsys.h 2013-05-31 14:47:11.000000000 +0000
3866 #define JFS_NAME_MAX 255
3867 #define JFS_PATH_MAX BPSIZE
3869 +#define JFS_TAGGED 0x00800000 /* Context Tagging */
3872 * file system state (superblock state)
3873 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_imap.c linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_imap.c
3874 --- linux-3.9.4/fs/jfs/jfs_imap.c 2012-12-11 03:30:57.000000000 +0000
3875 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_imap.c 2013-05-31 14:47:11.000000000 +0000
3877 #include <linux/pagemap.h>
3878 #include <linux/quotaops.h>
3879 #include <linux/slab.h>
3880 +#include <linux/vs_tag.h>
3882 #include "jfs_incore.h"
3883 #include "jfs_inode.h"
3884 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3886 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3887 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3891 jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3892 jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3893 @@ -3078,14 +3081,19 @@ static int copy_from_dinode(struct dinod
3895 set_nlink(ip, le32_to_cpu(dip->di_nlink));
3897 - jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3898 + uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3899 + gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3900 + ip->i_tag = make_ktag(&init_user_ns,
3901 + INOTAG_TAG(DX_TAG(ip), uid, gid, 0));
3903 + jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3904 if (!uid_valid(sbi->uid))
3905 ip->i_uid = jfs_ip->saved_uid;
3907 ip->i_uid = sbi->uid;
3910 - jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3911 + jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3912 if (!gid_valid(sbi->gid))
3913 ip->i_gid = jfs_ip->saved_gid;
3915 @@ -3150,16 +3158,14 @@ static void copy_to_dinode(struct dinode
3916 dip->di_size = cpu_to_le64(ip->i_size);
3917 dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3918 dip->di_nlink = cpu_to_le32(ip->i_nlink);
3919 - if (!uid_valid(sbi->uid))
3920 - dip->di_uid = cpu_to_le32(i_uid_read(ip));
3922 - dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3923 - jfs_ip->saved_uid));
3924 - if (!gid_valid(sbi->gid))
3925 - dip->di_gid = cpu_to_le32(i_gid_read(ip));
3927 - dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3928 - jfs_ip->saved_gid));
3929 + dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3930 + TAGINO_UID(DX_TAG(ip),
3931 + !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3933 + dip->di_gid = cpu_to_le32(from_kuid(&init_user_ns,
3934 + TAGINO_GID(DX_TAG(ip),
3935 + !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3937 jfs_get_inode_flags(jfs_ip);
3939 * mode2 is only needed for storing the higher order bits.
3940 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_inode.c linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_inode.c
3941 --- linux-3.9.4/fs/jfs/jfs_inode.c 2012-12-11 03:30:57.000000000 +0000
3942 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_inode.c 2013-05-31 14:47:11.000000000 +0000
3945 #include <linux/fs.h>
3946 #include <linux/quotaops.h>
3947 +#include <linux/vs_tag.h>
3948 #include "jfs_incore.h"
3949 #include "jfs_inode.h"
3950 #include "jfs_filsys.h"
3951 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3953 unsigned int flags = JFS_IP(inode)->mode2;
3955 - inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3956 - S_NOATIME | S_DIRSYNC | S_SYNC);
3957 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3958 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3960 if (flags & JFS_IMMUTABLE_FL)
3961 inode->i_flags |= S_IMMUTABLE;
3962 + if (flags & JFS_IXUNLINK_FL)
3963 + inode->i_flags |= S_IXUNLINK;
3965 + if (flags & JFS_SYNC_FL)
3966 + inode->i_flags |= S_SYNC;
3967 if (flags & JFS_APPEND_FL)
3968 inode->i_flags |= S_APPEND;
3969 if (flags & JFS_NOATIME_FL)
3970 inode->i_flags |= S_NOATIME;
3971 if (flags & JFS_DIRSYNC_FL)
3972 inode->i_flags |= S_DIRSYNC;
3973 - if (flags & JFS_SYNC_FL)
3974 - inode->i_flags |= S_SYNC;
3976 + inode->i_vflags &= ~(V_BARRIER | V_COW);
3978 + if (flags & JFS_BARRIER_FL)
3979 + inode->i_vflags |= V_BARRIER;
3980 + if (flags & JFS_COW_FL)
3981 + inode->i_vflags |= V_COW;
3984 void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3986 unsigned int flags = jfs_ip->vfs_inode.i_flags;
3987 + unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3989 + jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3990 + JFS_APPEND_FL | JFS_NOATIME_FL |
3991 + JFS_DIRSYNC_FL | JFS_SYNC_FL |
3992 + JFS_BARRIER_FL | JFS_COW_FL);
3994 - jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3995 - JFS_DIRSYNC_FL | JFS_SYNC_FL);
3996 if (flags & S_IMMUTABLE)
3997 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3998 + if (flags & S_IXUNLINK)
3999 + jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4001 if (flags & S_APPEND)
4002 jfs_ip->mode2 |= JFS_APPEND_FL;
4003 if (flags & S_NOATIME)
4004 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4005 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4007 jfs_ip->mode2 |= JFS_SYNC_FL;
4009 + if (vflags & V_BARRIER)
4010 + jfs_ip->mode2 |= JFS_BARRIER_FL;
4011 + if (vflags & V_COW)
4012 + jfs_ip->mode2 |= JFS_COW_FL;
4016 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_inode.h linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_inode.h
4017 --- linux-3.9.4/fs/jfs/jfs_inode.h 2012-12-11 03:30:57.000000000 +0000
4018 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/jfs_inode.h 2013-05-31 14:47:11.000000000 +0000
4019 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4020 extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4021 int fh_len, int fh_type);
4022 extern void jfs_set_inode_flags(struct inode *);
4023 +extern int jfs_sync_flags(struct inode *, int, int);
4024 extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4025 extern int jfs_setattr(struct dentry *, struct iattr *);
4027 diff -NurpP --minimal linux-3.9.4/fs/jfs/namei.c linux-3.9.4-vs2.3.6.1/fs/jfs/namei.c
4028 --- linux-3.9.4/fs/jfs/namei.c 2012-12-11 03:30:57.000000000 +0000
4029 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/namei.c 2013-05-31 14:47:11.000000000 +0000
4031 #include <linux/ctype.h>
4032 #include <linux/quotaops.h>
4033 #include <linux/exportfs.h>
4034 +#include <linux/vs_tag.h>
4035 #include "jfs_incore.h"
4036 #include "jfs_superblock.h"
4037 #include "jfs_inode.h"
4038 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
4039 jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
4042 + dx_propagate_tag(nd, ip);
4043 return d_splice_alias(ip, dentry);
4046 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
4047 #ifdef CONFIG_JFS_POSIX_ACL
4048 .get_acl = jfs_get_acl,
4050 + .sync_flags = jfs_sync_flags,
4053 const struct file_operations jfs_dir_operations = {
4054 diff -NurpP --minimal linux-3.9.4/fs/jfs/super.c linux-3.9.4-vs2.3.6.1/fs/jfs/super.c
4055 --- linux-3.9.4/fs/jfs/super.c 2013-05-31 13:45:24.000000000 +0000
4056 +++ linux-3.9.4-vs2.3.6.1/fs/jfs/super.c 2013-05-31 14:47:11.000000000 +0000
4057 @@ -199,7 +199,8 @@ enum {
4058 Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4059 Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4060 Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4061 - Opt_discard, Opt_nodiscard, Opt_discard_minblk
4062 + Opt_discard, Opt_nodiscard, Opt_discard_minblk,
4063 + Opt_tag, Opt_notag, Opt_tagid
4066 static const match_table_t tokens = {
4067 @@ -209,6 +210,10 @@ static const match_table_t tokens = {
4068 {Opt_resize, "resize=%u"},
4069 {Opt_resize_nosize, "resize"},
4070 {Opt_errors, "errors=%s"},
4072 + {Opt_notag, "notag"},
4073 + {Opt_tagid, "tagid=%u"},
4074 + {Opt_tag, "tagxid"},
4075 {Opt_ignore, "noquota"},
4076 {Opt_ignore, "quota"},
4077 {Opt_usrquota, "usrquota"},
4078 @@ -385,7 +390,20 @@ static int parse_options(char *options,
4083 +#ifndef CONFIG_TAGGING_NONE
4085 + *flag |= JFS_TAGGED;
4088 + *flag &= JFS_TAGGED;
4091 +#ifdef CONFIG_PROPAGATE
4094 + *flag |= JFS_TAGGED;
4098 printk("jfs: Unrecognized mount option \"%s\" "
4099 " or missing value\n", p);
4100 @@ -417,6 +435,12 @@ static int jfs_remount(struct super_bloc
4104 + if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4105 + printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4111 if (sb->s_flags & MS_RDONLY) {
4112 pr_err("JFS: resize requires volume" \
4113 @@ -502,6 +526,9 @@ static int jfs_fill_super(struct super_b
4114 #ifdef CONFIG_JFS_POSIX_ACL
4115 sb->s_flags |= MS_POSIXACL;
4117 + /* map mount option tagxid */
4118 + if (sbi->flag & JFS_TAGGED)
4119 + sb->s_flags |= MS_TAGGED;
4122 pr_err("resize option for remount only\n");
4123 diff -NurpP --minimal linux-3.9.4/fs/libfs.c linux-3.9.4-vs2.3.6.1/fs/libfs.c
4124 --- linux-3.9.4/fs/libfs.c 2013-02-19 13:58:48.000000000 +0000
4125 +++ linux-3.9.4-vs2.3.6.1/fs/libfs.c 2013-05-31 14:47:11.000000000 +0000
4126 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4127 * both impossible due to the lock on directory.
4130 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4131 +static inline int do_dcache_readdir_filter(struct file *filp,
4132 + void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4134 struct dentry *dentry = filp->f_path.dentry;
4135 struct dentry *cursor = filp->private_data;
4136 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4137 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4138 struct dentry *next;
4139 next = list_entry(p, struct dentry, d_u.d_child);
4140 + if (filter && !filter(next))
4142 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4143 if (!simple_positive(next)) {
4144 spin_unlock(&next->d_lock);
4145 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4149 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4151 + return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4154 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4155 + int (*filter)(struct dentry *))
4157 + return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4160 ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4163 @@ -981,6 +995,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4164 EXPORT_SYMBOL(dcache_dir_lseek);
4165 EXPORT_SYMBOL(dcache_dir_open);
4166 EXPORT_SYMBOL(dcache_readdir);
4167 +EXPORT_SYMBOL(dcache_readdir_filter);
4168 EXPORT_SYMBOL(generic_read_dir);
4169 EXPORT_SYMBOL(mount_pseudo);
4170 EXPORT_SYMBOL(simple_write_begin);
4171 diff -NurpP --minimal linux-3.9.4/fs/locks.c linux-3.9.4-vs2.3.6.1/fs/locks.c
4172 --- linux-3.9.4/fs/locks.c 2013-05-31 13:45:24.000000000 +0000
4173 +++ linux-3.9.4-vs2.3.6.1/fs/locks.c 2013-05-31 15:53:57.000000000 +0000
4175 #include <linux/time.h>
4176 #include <linux/rcupdate.h>
4177 #include <linux/pid_namespace.h>
4178 +#include <linux/vs_base.h>
4179 +#include <linux/vs_limit.h>
4181 #include <asm/uaccess.h>
4183 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4184 /* Allocate an empty lock structure. */
4185 struct file_lock *locks_alloc_lock(void)
4187 - struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4188 + struct file_lock *fl;
4191 - locks_init_lock_heads(fl);
4192 + if (!vx_locks_avail(1))
4195 + fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4198 + locks_init_lock_heads(fl);
4203 EXPORT_SYMBOL_GPL(locks_alloc_lock);
4204 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4205 BUG_ON(!list_empty(&fl->fl_block));
4206 BUG_ON(!list_empty(&fl->fl_link));
4209 locks_release_private(fl);
4210 kmem_cache_free(filelock_cache, fl);
4212 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4214 memset(fl, 0, sizeof(struct file_lock));
4215 locks_init_lock_heads(fl);
4219 EXPORT_SYMBOL(locks_init_lock);
4220 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4221 new->fl_file = fl->fl_file;
4222 new->fl_ops = fl->fl_ops;
4223 new->fl_lmops = fl->fl_lmops;
4224 + new->fl_xid = fl->fl_xid;
4226 locks_copy_private(new, fl);
4228 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4229 fl->fl_flags = FL_FLOCK;
4231 fl->fl_end = OFFSET_MAX;
4233 + vxd_assert(filp->f_xid == vx_current_xid(),
4234 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4235 + fl->fl_xid = filp->f_xid;
4240 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4242 fl->fl_owner = current->files;
4243 fl->fl_pid = current->tgid;
4244 + fl->fl_xid = vx_current_xid();
4247 fl->fl_flags = FL_LEASE;
4248 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4250 return ERR_PTR(error);
4252 + fl->fl_xid = vx_current_xid();
4254 + vxd_assert(filp->f_xid == fl->fl_xid,
4255 + "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4257 error = lease_init(filp, type, fl);
4259 locks_free_lock(fl);
4260 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4264 + new_fl->fl_xid = -1;
4266 for_each_lock(inode, before) {
4267 struct file_lock *fl = *before;
4268 @@ -773,6 +796,7 @@ find_conflict:
4270 locks_copy_lock(new_fl, request);
4271 locks_insert_lock(before, new_fl);
4272 + vx_locks_inc(new_fl);
4276 @@ -783,7 +807,8 @@ out:
4280 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4281 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4282 + struct file_lock *conflock, xid_t xid)
4284 struct file_lock *fl;
4285 struct file_lock *new_fl = NULL;
4286 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4287 struct file_lock **before;
4288 int error, added = 0;
4290 + vxd_assert(xid == vx_current_xid(),
4291 + "xid(%d) == current(%d)", xid, vx_current_xid());
4293 * We may need two file_lock structures for this operation,
4294 * so we get them in advance to avoid races.
4295 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4296 (request->fl_type != F_UNLCK ||
4297 request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4298 new_fl = locks_alloc_lock();
4299 + new_fl->fl_xid = xid;
4300 + vx_locks_inc(new_fl);
4301 new_fl2 = locks_alloc_lock();
4302 + new_fl2->fl_xid = xid;
4303 + vx_locks_inc(new_fl2);
4307 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4308 int posix_lock_file(struct file *filp, struct file_lock *fl,
4309 struct file_lock *conflock)
4311 - return __posix_lock_file(file_inode(filp), fl, conflock);
4312 + return __posix_lock_file(file_inode(filp),
4313 + fl, conflock, filp->f_xid);
4315 EXPORT_SYMBOL(posix_lock_file);
4317 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4318 fl.fl_end = offset + count - 1;
4321 - error = __posix_lock_file(inode, &fl, NULL);
4322 + error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4323 if (error != FILE_LOCK_DEFERRED)
4325 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4326 @@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4329 locks_insert_lock(before, lease);
4330 + vx_locks_inc(lease);
4334 @@ -1836,6 +1869,11 @@ int fcntl_setlk(unsigned int fd, struct
4335 if (file_lock == NULL)
4338 + vxd_assert(filp->f_xid == vx_current_xid(),
4339 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4340 + file_lock->fl_xid = filp->f_xid;
4341 + vx_locks_inc(file_lock);
4344 * This might block, so we do it before checking the inode.
4346 @@ -1954,6 +1992,11 @@ int fcntl_setlk64(unsigned int fd, struc
4347 if (file_lock == NULL)
4350 + vxd_assert(filp->f_xid == vx_current_xid(),
4351 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4352 + file_lock->fl_xid = filp->f_xid;
4353 + vx_locks_inc(file_lock);
4356 * This might block, so we do it before checking the inode.
4358 @@ -2219,8 +2262,11 @@ static int locks_show(struct seq_file *f
4360 lock_get_status(f, fl, *((loff_t *)f->private), "");
4362 - list_for_each_entry(bfl, &fl->fl_block, fl_block)
4363 + list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4364 + if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4366 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4371 diff -NurpP --minimal linux-3.9.4/fs/mount.h linux-3.9.4-vs2.3.6.1/fs/mount.h
4372 --- linux-3.9.4/fs/mount.h 2013-02-19 13:58:48.000000000 +0000
4373 +++ linux-3.9.4-vs2.3.6.1/fs/mount.h 2013-05-31 14:47:11.000000000 +0000
4374 @@ -49,6 +49,7 @@ struct mount {
4375 int mnt_expiry_mark; /* true if marked for expiry */
4378 + tag_t mnt_tag; /* tagging used for vfsmount */
4381 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4382 diff -NurpP --minimal linux-3.9.4/fs/namei.c linux-3.9.4-vs2.3.6.1/fs/namei.c
4383 --- linux-3.9.4/fs/namei.c 2013-05-31 14:22:27.000000000 +0000
4384 +++ linux-3.9.4-vs2.3.6.1/fs/namei.c 2013-06-01 00:22:21.000000000 +0000
4386 #include <linux/device_cgroup.h>
4387 #include <linux/fs_struct.h>
4388 #include <linux/posix_acl.h>
4389 +#include <linux/proc_fs.h>
4390 +#include <linux/vserver/inode.h>
4391 +#include <linux/vs_base.h>
4392 +#include <linux/vs_tag.h>
4393 +#include <linux/vs_cowbl.h>
4394 +#include <linux/vs_device.h>
4395 +#include <linux/vs_context.h>
4396 +#include <linux/pid_namespace.h>
4397 #include <asm/uaccess.h>
4399 #include "internal.h"
4400 @@ -266,6 +274,89 @@ static int check_acl(struct inode *inode
4404 +static inline int dx_barrier(const struct inode *inode)
4406 + if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4407 + vxwprintk_task(1, "did hit the barrier.");
4413 +static int __dx_permission(const struct inode *inode, int mask)
4415 + if (dx_barrier(inode))
4418 + if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4419 + /* devpts is xid tagged */
4420 + if (S_ISDIR(inode->i_mode) ||
4421 + vx_check((xid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4424 + /* just pretend we didn't find anything */
4427 + else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4428 + struct proc_dir_entry *de = PDE(inode);
4430 + if (de && !vx_hide_check(0, de->vx_flags))
4433 + if ((mask & (MAY_WRITE | MAY_APPEND))) {
4435 + struct task_struct *tsk;
4437 + if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4438 + vx_flags(VXF_STATE_SETUP, 0))
4441 + pid = PROC_I(inode)->pid;
4446 + tsk = pid_task(pid, PIDTYPE_PID);
4447 + vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4448 + tsk, (tsk ? vx_task_xid(tsk) : 0));
4450 + vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4451 + rcu_read_unlock();
4454 + rcu_read_unlock();
4457 + /* FIXME: Should we block some entries here? */
4462 + if (dx_notagcheck(inode->i_sb) ||
4463 + dx_check((xid_t)i_tag_read(inode),
4464 + DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4472 +int dx_permission(const struct inode *inode, int mask)
4474 + int ret = __dx_permission(inode, mask);
4475 + if (unlikely(ret)) {
4476 +#ifndef CONFIG_VSERVER_WARN_DEVPTS
4477 + if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4480 + "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4481 + mask, inode->i_sb->s_id, inode, inode->i_tag,
4488 * This does the basic permission checking
4490 @@ -388,10 +479,14 @@ int __inode_permission(struct inode *ino
4492 * Nobody gets write access to an immutable file.
4494 - if (IS_IMMUTABLE(inode))
4495 + if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4499 + retval = dx_permission(inode, mask);
4503 retval = do_inode_permission(inode, mask);
4506 @@ -1238,7 +1333,8 @@ static void follow_dotdot(struct nameida
4508 if (nd->path.dentry == nd->root.dentry &&
4509 nd->path.mnt == nd->root.mnt) {
4511 + /* for sane '/' avoid follow_mount() */
4514 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4515 /* rare case of legitimate dget_parent()... */
4516 @@ -1383,6 +1479,9 @@ static int lookup_fast(struct nameidata
4521 + /* FIXME: check dx permission */
4524 path->dentry = dentry;
4525 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4526 @@ -1413,6 +1512,8 @@ unlazy:
4530 + /* FIXME: check dx permission */
4533 path->dentry = dentry;
4534 err = follow_managed(path, nd->flags);
4535 @@ -2237,7 +2338,7 @@ static int may_delete(struct inode *dir,
4538 if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4539 - IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4540 + IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4543 if (!S_ISDIR(victim->d_inode->i_mode))
4544 @@ -2316,19 +2417,25 @@ int vfs_create(struct inode *dir, struct
4547 int error = may_create(dir, dentry);
4550 + vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4554 if (!dir->i_op->create)
4555 return -EACCES; /* shouldn't it be ENOSYS? */
4558 error = security_inode_create(dir, dentry, mode);
4561 + vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4564 error = dir->i_op->create(dir, dentry, mode, want_excl);
4566 fsnotify_create(dir, dentry);
4568 + vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4572 @@ -2363,6 +2470,15 @@ static int may_open(struct path *path, i
4576 +#ifdef CONFIG_VSERVER_COWBL
4577 + if (IS_COW(inode) &&
4578 + ((flag & O_ACCMODE) != O_RDONLY)) {
4579 + if (IS_COW_LINK(inode))
4581 + inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4582 + mark_inode_dirty(inode);
4585 error = inode_permission(inode, acc_mode);
4588 @@ -2865,6 +2981,16 @@ finish_open:
4590 finish_open_created:
4591 error = may_open(&nd->path, acc_mode, open_flag);
4592 +#ifdef CONFIG_VSERVER_COWBL
4593 + if (error == -EMLINK) {
4594 + struct dentry *dentry;
4595 + dentry = cow_break_link(name->name);
4596 + if (IS_ERR(dentry))
4597 + error = PTR_ERR(dentry);
4604 file->f_path.mnt = nd->path.mnt;
4605 @@ -2929,6 +3055,7 @@ static struct file *path_openat(int dfd,
4610 file = get_empty_filp();
4613 @@ -2965,6 +3092,16 @@ static struct file *path_openat(int dfd,
4614 error = do_last(nd, &path, file, op, &opened, pathname);
4615 put_link(nd, &link, cookie);
4618 +#ifdef CONFIG_VSERVER_COWBL
4619 + if (error == -EMLINK) {
4620 + if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4621 + path_put(&nd->root);
4628 if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4629 path_put(&nd->root);
4630 @@ -3079,6 +3216,11 @@ struct dentry *kern_path_create(int dfd,
4634 + vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4635 + path->dentry, path->dentry->d_name.len,
4636 + path->dentry->d_name.name, dentry,
4637 + dentry->d_name.len, dentry->d_name.name,
4638 + path->dentry->d_inode);
4642 @@ -3573,7 +3715,7 @@ int vfs_link(struct dentry *old_dentry,
4644 * A link to an append-only or immutable file cannot be created.
4646 - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4647 + if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4649 if (!dir->i_op->link)
4651 @@ -3976,6 +4118,286 @@ int vfs_follow_link(struct nameidata *nd
4652 return __vfs_follow_link(nd, link);
4656 +#ifdef CONFIG_VSERVER_COWBL
4659 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4663 + return do_splice_direct(in, &ppos, out, len, 0);
4666 +struct dentry *cow_break_link(const char *pathname)
4668 + int ret, mode, pathlen, redo = 0, drop = 1;
4669 + struct nameidata old_nd, dir_nd;
4670 + struct path dir_path, *old_path, *new_path;
4671 + struct dentry *dir, *old_dentry, *new_dentry = NULL;
4672 + struct file *old_file;
4673 + struct file *new_file;
4674 + char *to, *path, pad='\251';
4677 + vxdprintk(VXD_CBIT(misc, 1),
4678 + "cow_break_link(" VS_Q("%s") ")", pathname);
4680 + path = kmalloc(PATH_MAX, GFP_KERNEL);
4685 + /* old_nd.path will have refs to dentry and mnt */
4686 + ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4687 + vxdprintk(VXD_CBIT(misc, 2),
4688 + "do_path_lookup(old): %d", ret);
4690 + goto out_free_path;
4692 + /* dentry/mnt refs handed over to old_path */
4693 + old_path = &old_nd.path;
4694 + /* no explicit reference for old_dentry here */
4695 + old_dentry = old_path->dentry;
4697 + mode = old_dentry->d_inode->i_mode;
4698 + to = d_path(old_path, path, PATH_MAX-2);
4699 + pathlen = strlen(to);
4700 + vxdprintk(VXD_CBIT(misc, 2),
4701 + "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4703 + old_dentry->d_name.len, old_dentry->d_name.name,
4704 + old_dentry->d_name.len);
4706 + to[pathlen + 1] = 0;
4708 + new_dentry = NULL;
4709 + to[pathlen] = pad--;
4711 + if (pad <= '\240')
4714 + vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4716 + /* dir_nd.path will have refs to dentry and mnt */
4717 + ret = do_path_lookup(AT_FDCWD, to,
4718 + LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4719 + vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4723 + /* this puppy downs the dir inode mutex if successful.
4724 + dir_path will hold refs to dentry and mnt and
4725 + we'll have write access to the mnt */
4726 + new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4727 + if (!new_dentry || IS_ERR(new_dentry)) {
4728 + path_put(&dir_nd.path);
4729 + vxdprintk(VXD_CBIT(misc, 2),
4730 + "kern_path_create(new) failed with %ld",
4731 + PTR_ERR(new_dentry));
4734 + vxdprintk(VXD_CBIT(misc, 2),
4735 + "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4737 + new_dentry->d_name.len, new_dentry->d_name.name,
4738 + new_dentry->d_name.len);
4740 + /* take a reference on new_dentry */
4743 + /* dentry/mnt refs handed over to new_path */
4744 + new_path = &dir_path;
4746 + /* dentry for old/new dir */
4747 + dir = dir_nd.path.dentry;
4749 + /* give up reference on dir */
4750 + dput(new_path->dentry);
4752 + /* new_dentry already has a reference */
4753 + new_path->dentry = new_dentry;
4755 + ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4756 + vxdprintk(VXD_CBIT(misc, 2),
4757 + "vfs_create(new): %d", ret);
4758 + if (ret == -EEXIST) {
4759 + path_put(&dir_nd.path);
4760 + mutex_unlock(&dir->d_inode->i_mutex);
4761 + mnt_drop_write(new_path->mnt);
4762 + path_put(new_path);
4763 + new_dentry = NULL;
4767 + goto out_unlock_new;
4769 + /* drop out early, ret passes ENOENT */
4771 + if ((redo = d_unhashed(old_dentry)))
4772 + goto out_unlock_new;
4774 + /* doesn't change refs for old_path */
4775 + old_file = dentry_open(old_path, O_RDONLY, current_cred());
4776 + vxdprintk(VXD_CBIT(misc, 2),
4777 + "dentry_open(old): %p", old_file);
4778 + if (IS_ERR(old_file)) {
4779 + ret = PTR_ERR(old_file);
4780 + goto out_unlock_new;
4783 + /* doesn't change refs for new_path */
4784 + new_file = dentry_open(new_path, O_WRONLY, current_cred());
4785 + vxdprintk(VXD_CBIT(misc, 2),
4786 + "dentry_open(new): %p", new_file);
4787 + if (IS_ERR(new_file)) {
4788 + ret = PTR_ERR(new_file);
4789 + goto out_fput_old;
4792 + /* unlock the inode mutex from kern_path_create() */
4793 + mutex_unlock(&dir->d_inode->i_mutex);
4795 + /* drop write access to mnt */
4796 + mnt_drop_write(new_path->mnt);
4800 + size = i_size_read(old_file->f_dentry->d_inode);
4801 + ret = do_cow_splice(old_file, new_file, size);
4802 + vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4804 + goto out_fput_both;
4805 + } else if (ret < size) {
4807 + goto out_fput_both;
4809 + struct inode *old_inode = old_dentry->d_inode;
4810 + struct inode *new_inode = new_dentry->d_inode;
4811 + struct iattr attr = {
4812 + .ia_uid = old_inode->i_uid,
4813 + .ia_gid = old_inode->i_gid,
4814 + .ia_valid = ATTR_UID | ATTR_GID
4817 + setattr_copy(new_inode, &attr);
4818 + mark_inode_dirty(new_inode);
4821 + /* lock rename mutex */
4822 + mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4824 + /* drop out late */
4826 + if ((redo = d_unhashed(old_dentry)))
4829 + vxdprintk(VXD_CBIT(misc, 2),
4830 + "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4831 + new_dentry->d_name.len, new_dentry->d_name.name,
4832 + new_dentry->d_name.len,
4833 + old_dentry->d_name.len, old_dentry->d_name.name,
4834 + old_dentry->d_name.len);
4835 + ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4836 + old_dentry->d_parent->d_inode, old_dentry);
4837 + vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4840 + mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4843 + vxdprintk(VXD_CBIT(misc, 3),
4844 + "fput(new_file=%p[#%ld])", new_file,
4845 + atomic_long_read(&new_file->f_count));
4849 + vxdprintk(VXD_CBIT(misc, 3),
4850 + "fput(old_file=%p[#%ld])", old_file,
4851 + atomic_long_read(&old_file->f_count));
4855 + /* drop references from dir_nd.path */
4856 + path_put(&dir_nd.path);
4859 + /* unlock the inode mutex from kern_path_create() */
4860 + mutex_unlock(&dir->d_inode->i_mutex);
4862 + /* drop write access to mnt */
4863 + mnt_drop_write(new_path->mnt);
4869 + /* error path cleanup */
4870 + vfs_unlink(dir->d_inode, new_dentry);
4874 + goto out_rel_both;
4876 + /* lookup dentry once again
4877 + old_nd.path will be freed as old_path in out_rel_old */
4878 + ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4880 + goto out_rel_both;
4882 + /* drop reference on new_dentry */
4884 + new_dentry = old_path->dentry;
4886 + vxdprintk(VXD_CBIT(misc, 2),
4887 + "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4889 + new_dentry->d_name.len, new_dentry->d_name.name,
4890 + new_dentry->d_name.len);
4894 + path_put(new_path);
4896 + path_put(old_path);
4902 + new_dentry = ERR_PTR(ret);
4904 + vxdprintk(VXD_CBIT(misc, 3),
4905 + "cow_break_link returning with %p", new_dentry);
4906 + return new_dentry;
4911 +int vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4914 + struct vfsmount *vmnt;
4915 + char *pstr, *root;
4918 + pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4922 + vmnt = &ns->root->mnt;
4924 + path.dentry = vmnt->mnt_root;
4925 + root = d_path(&path, pstr, PATH_MAX - 2);
4926 + length = sprintf(buffer + length,
4927 + "Namespace:\t%p [#%u]\n"
4928 + "RootPath:\t%s\n",
4929 + ns, atomic_read(&ns->count),
4935 /* get the link contents into pagecache */
4936 static char *page_getlink(struct dentry * dentry, struct page **ppage)
4938 @@ -4099,3 +4521,4 @@ EXPORT_SYMBOL(vfs_symlink);
4939 EXPORT_SYMBOL(vfs_unlink);
4940 EXPORT_SYMBOL(dentry_unhash);
4941 EXPORT_SYMBOL(generic_readlink);
4942 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4943 diff -NurpP --minimal linux-3.9.4/fs/namespace.c linux-3.9.4-vs2.3.6.1/fs/namespace.c
4944 --- linux-3.9.4/fs/namespace.c 2013-05-31 14:22:27.000000000 +0000
4945 +++ linux-3.9.4-vs2.3.6.1/fs/namespace.c 2013-05-31 18:47:18.000000000 +0000
4947 #include <linux/fsnotify.h> /* fsnotify_vfsmount_delete */
4948 #include <linux/uaccess.h>
4949 #include <linux/proc_fs.h>
4950 +#include <linux/vs_base.h>
4951 +#include <linux/vs_context.h>
4952 +#include <linux/vs_tag.h>
4953 +#include <linux/vserver/space.h>
4954 +#include <linux/vserver/global.h>
4956 #include "internal.h"
4958 @@ -751,6 +756,10 @@ vfs_kern_mount(struct file_system_type *
4960 return ERR_PTR(-ENODEV);
4962 + if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4963 + !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4964 + return ERR_PTR(-EPERM);
4966 mnt = alloc_vfsmnt(name);
4968 return ERR_PTR(-ENOMEM);
4969 @@ -807,6 +816,7 @@ static struct mount *clone_mnt(struct mo
4970 mnt->mnt.mnt_root = dget(root);
4971 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4972 mnt->mnt_parent = mnt;
4973 + mnt->mnt_tag = old->mnt_tag;
4974 br_write_lock(&vfsmount_lock);
4975 list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4976 br_write_unlock(&vfsmount_lock);
4977 @@ -1639,6 +1649,7 @@ static int do_change_type(struct path *p
4981 + // mnt->mnt_flags = mnt_flags;
4983 br_write_lock(&vfsmount_lock);
4984 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4985 @@ -1654,12 +1665,14 @@ static int do_change_type(struct path *p
4986 * do loopback mount.
4988 static int do_loopback(struct path *path, const char *old_name,
4990 + tag_t tag, unsigned long flags, int mnt_flags)
4992 LIST_HEAD(umount_list);
4993 struct path old_path;
4994 struct mount *mnt = NULL, *old;
4995 + int recurse = flags & MS_REC;
4998 if (!old_name || !*old_name)
5000 err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
5001 @@ -1733,7 +1746,7 @@ static int change_mount_flags(struct vfs
5002 * on it - tough luck.
5004 static int do_remount(struct path *path, int flags, int mnt_flags,
5006 + void *data, xid_t xid)
5009 struct super_block *sb = path->mnt->mnt_sb;
5010 @@ -2046,7 +2059,6 @@ void mark_mounts_for_expiry(struct list_
5012 br_write_unlock(&vfsmount_lock);
5013 up_write(&namespace_sem);
5015 release_mounts(&umounts);
5018 @@ -2218,6 +2230,7 @@ long do_mount(const char *dev_name, cons
5025 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5026 @@ -2247,6 +2260,12 @@ long do_mount(const char *dev_name, cons
5027 if (!(flags & MS_NOATIME))
5028 mnt_flags |= MNT_RELATIME;
5030 + if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5031 + /* FIXME: bind and re-mounts get the tag flag? */
5032 + if (flags & (MS_BIND|MS_REMOUNT))
5033 + flags |= MS_TAGID;
5036 /* Separate the per-mountpoint flags */
5037 if (flags & MS_NOSUID)
5038 mnt_flags |= MNT_NOSUID;
5039 @@ -2263,15 +2282,17 @@ long do_mount(const char *dev_name, cons
5040 if (flags & MS_RDONLY)
5041 mnt_flags |= MNT_READONLY;
5043 + if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
5044 + mnt_flags |= MNT_NODEV;
5045 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5046 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5049 if (flags & MS_REMOUNT)
5050 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5053 else if (flags & MS_BIND)
5054 - retval = do_loopback(&path, dev_name, flags & MS_REC);
5055 + retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5056 else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5057 retval = do_change_type(&path, flags);
5058 else if (flags & MS_MOVE)
5059 @@ -2380,6 +2401,7 @@ static struct mnt_namespace *dup_mnt_ns(
5060 q = next_mnt(q, new);
5062 up_write(&namespace_sem);
5063 + atomic_inc(&vs_global_mnt_ns);
5067 @@ -2575,9 +2597,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5069 new_mnt = real_mount(new.mnt);
5070 root_mnt = real_mount(root.mnt);
5071 - if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5072 + if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5073 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5074 - IS_MNT_SHARED(root_mnt->mnt_parent))
5075 + IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5076 + !vx_flags(VXF_STATE_SETUP, 0))
5078 if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5080 @@ -2703,6 +2726,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5081 br_write_unlock(&vfsmount_lock);
5082 up_write(&namespace_sem);
5083 release_mounts(&umount_list);
5084 + atomic_dec(&vs_global_mnt_ns);
5088 diff -NurpP --minimal linux-3.9.4/fs/nfs/client.c linux-3.9.4-vs2.3.6.1/fs/nfs/client.c
5089 --- linux-3.9.4/fs/nfs/client.c 2013-05-31 13:45:24.000000000 +0000
5090 +++ linux-3.9.4-vs2.3.6.1/fs/nfs/client.c 2013-05-31 14:47:11.000000000 +0000
5091 @@ -682,6 +682,9 @@ int nfs_init_server_rpcclient(struct nfs
5092 if (server->flags & NFS_MOUNT_SOFT)
5093 server->client->cl_softrtry = 1;
5095 + server->client->cl_tag = 0;
5096 + if (server->flags & NFS_MOUNT_TAGGED)
5097 + server->client->cl_tag = 1;
5100 EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
5101 @@ -861,6 +864,10 @@ static void nfs_server_set_fsinfo(struct
5102 server->acdirmin = server->acdirmax = 0;
5105 + /* FIXME: needs fsinfo
5106 + if (server->flags & NFS_MOUNT_TAGGED)
5107 + sb->s_flags |= MS_TAGGED; */
5109 server->maxfilesize = fsinfo->maxfilesize;
5111 server->time_delta = fsinfo->time_delta;
5112 diff -NurpP --minimal linux-3.9.4/fs/nfs/dir.c linux-3.9.4-vs2.3.6.1/fs/nfs/dir.c
5113 --- linux-3.9.4/fs/nfs/dir.c 2013-05-31 13:45:24.000000000 +0000
5114 +++ linux-3.9.4-vs2.3.6.1/fs/nfs/dir.c 2013-05-31 14:47:11.000000000 +0000
5116 #include <linux/sched.h>
5117 #include <linux/kmemleak.h>
5118 #include <linux/xattr.h>
5119 +#include <linux/vs_tag.h>
5121 #include "delegation.h"
5123 @@ -1300,6 +1301,7 @@ struct dentry *nfs_lookup(struct inode *
5124 /* Success: notify readdir to use READDIRPLUS */
5125 nfs_advise_use_readdirplus(dir);
5127 + dx_propagate_tag(nd, inode);
5129 res = d_materialise_unique(dentry, inode);
5131 diff -NurpP --minimal linux-3.9.4/fs/nfs/inode.c linux-3.9.4-vs2.3.6.1/fs/nfs/inode.c
5132 --- linux-3.9.4/fs/nfs/inode.c 2013-05-31 13:45:24.000000000 +0000
5133 +++ linux-3.9.4-vs2.3.6.1/fs/nfs/inode.c 2013-05-31 20:37:45.000000000 +0000
5135 #include <linux/compat.h>
5136 #include <linux/freezer.h>
5137 #include <linux/crc32.h>
5138 +#include <linux/vs_tag.h>
5140 #include <asm/uaccess.h>
5142 @@ -290,6 +291,8 @@ nfs_fhget(struct super_block *sb, struct
5143 if (inode->i_state & I_NEW) {
5144 struct nfs_inode *nfsi = NFS_I(inode);
5145 unsigned long now = jiffies;
5149 /* We set i_ino for the few things that still rely on it,
5150 * such as stat(2) */
5151 @@ -334,8 +337,8 @@ nfs_fhget(struct super_block *sb, struct
5152 inode->i_version = 0;
5155 - inode->i_uid = make_kuid(&init_user_ns, -2);
5156 - inode->i_gid = make_kgid(&init_user_ns, -2);
5157 + uid = make_kuid(&init_user_ns, -2);
5158 + gid = make_kgid(&init_user_ns, -2);
5159 inode->i_blocks = 0;
5160 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5162 @@ -369,11 +372,11 @@ nfs_fhget(struct super_block *sb, struct
5163 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5164 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5165 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5166 - inode->i_uid = fattr->uid;
5168 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5169 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5170 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5171 - inode->i_gid = fattr->gid;
5173 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5174 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5175 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5176 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5178 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5180 + inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5181 + inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5182 + inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5183 + /* maybe fattr->xid someday */
5185 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5186 nfsi->attrtimeo_timestamp = now;
5187 nfsi->access_cache = RB_ROOT;
5188 @@ -505,6 +513,8 @@ void nfs_setattr_update_inode(struct ino
5189 inode->i_uid = attr->ia_uid;
5190 if ((attr->ia_valid & ATTR_GID) != 0)
5191 inode->i_gid = attr->ia_gid;
5192 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5193 + inode->i_tag = attr->ia_tag;
5194 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5195 spin_unlock(&inode->i_lock);
5197 @@ -980,6 +990,11 @@ static int nfs_check_inode_attributes(st
5198 struct nfs_inode *nfsi = NFS_I(inode);
5199 loff_t cur_size, new_isize;
5200 unsigned long invalid = 0;
5208 if (nfs_have_delegated_attributes(inode))
5209 @@ -1005,13 +1020,21 @@ static int nfs_check_inode_attributes(st
5210 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5213 + uid = from_kuid(&init_user_ns, fattr->uid);
5214 + gid = from_kgid(&init_user_ns, fattr->gid);
5216 + kuid = make_kuid(&init_user_ns, INOTAG_UID(DX_TAG(inode), uid, gid));
5217 + kgid = make_kgid(&init_user_ns, INOTAG_GID(DX_TAG(inode), uid, gid));
5218 + ktag = make_ktag(&init_user_ns, INOTAG_TAG(DX_TAG(inode), uid, gid, 0));
5220 /* Have any file permissions changed? */
5221 if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5222 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5223 - if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5224 + if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5225 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5226 - if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5227 + if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5228 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5229 + /* maybe check for tag too? */
5231 /* Has the link count changed? */
5232 if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5233 @@ -1317,6 +1340,9 @@ static int nfs_update_inode(struct inode
5234 unsigned long invalid = 0;
5235 unsigned long now = jiffies;
5236 unsigned long save_cache_validity;
5241 dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5242 __func__, inode->i_sb->s_id, inode->i_ino,
5243 @@ -1418,6 +1444,9 @@ static int nfs_update_inode(struct inode
5244 | NFS_INO_REVAL_PAGECACHE
5245 | NFS_INO_REVAL_FORCED);
5247 + uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5248 + gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5249 + tag = inode->i_tag;
5251 if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5252 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5253 @@ -1460,6 +1489,10 @@ static int nfs_update_inode(struct inode
5254 | NFS_INO_INVALID_ACL
5255 | NFS_INO_REVAL_FORCED);
5257 + inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5258 + inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5259 + inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5261 if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5262 if (inode->i_nlink != fattr->nlink) {
5263 invalid |= NFS_INO_INVALID_ATTR;
5264 diff -NurpP --minimal linux-3.9.4/fs/nfs/nfs3xdr.c linux-3.9.4-vs2.3.6.1/fs/nfs/nfs3xdr.c
5265 --- linux-3.9.4/fs/nfs/nfs3xdr.c 2013-05-31 13:45:24.000000000 +0000
5266 +++ linux-3.9.4-vs2.3.6.1/fs/nfs/nfs3xdr.c 2013-05-31 15:33:48.000000000 +0000
5268 #include <linux/nfs3.h>
5269 #include <linux/nfs_fs.h>
5270 #include <linux/nfsacl.h>
5271 +#include <linux/vs_tag.h>
5272 #include "internal.h"
5274 #define NFSDBG_FACILITY NFSDBG_XDR
5275 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5279 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5280 +static void encode_sattr3(struct xdr_stream *xdr,
5281 + const struct iattr *attr, int tag)
5285 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5289 - if (attr->ia_valid & ATTR_UID) {
5290 + if (attr->ia_valid & ATTR_UID ||
5291 + (tag && (attr->ia_valid & ATTR_TAG))) {
5293 - *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5294 + *p++ = cpu_to_be32(TAGINO_UID(tag,
5295 + from_kuid(&init_user_ns, attr->ia_uid), attr->ia_tag));
5299 - if (attr->ia_valid & ATTR_GID) {
5300 + if (attr->ia_valid & ATTR_GID ||
5301 + (tag && (attr->ia_valid & ATTR_TAG))) {
5303 - *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5304 + *p++ = cpu_to_be32(TAGINO_GID(tag,
5305 + from_kgid(&init_user_ns, attr->ia_gid), attr->ia_tag));
5309 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5310 const struct nfs3_sattrargs *args)
5312 encode_nfs_fh3(xdr, args->fh);
5313 - encode_sattr3(xdr, args->sattr);
5314 + encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5315 encode_sattrguard3(xdr, args);
5318 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5321 static void encode_createhow3(struct xdr_stream *xdr,
5322 - const struct nfs3_createargs *args)
5323 + const struct nfs3_createargs *args, int tag)
5325 encode_uint32(xdr, args->createmode);
5326 switch (args->createmode) {
5327 case NFS3_CREATE_UNCHECKED:
5328 case NFS3_CREATE_GUARDED:
5329 - encode_sattr3(xdr, args->sattr);
5330 + encode_sattr3(xdr, args->sattr, tag);
5332 case NFS3_CREATE_EXCLUSIVE:
5333 encode_createverf3(xdr, args->verifier);
5334 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5335 const struct nfs3_createargs *args)
5337 encode_diropargs3(xdr, args->fh, args->name, args->len);
5338 - encode_createhow3(xdr, args);
5339 + encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5343 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5344 const struct nfs3_mkdirargs *args)
5346 encode_diropargs3(xdr, args->fh, args->name, args->len);
5347 - encode_sattr3(xdr, args->sattr);
5348 + encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5352 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5355 static void encode_symlinkdata3(struct xdr_stream *xdr,
5356 - const struct nfs3_symlinkargs *args)
5357 + const struct nfs3_symlinkargs *args, int tag)
5359 - encode_sattr3(xdr, args->sattr);
5360 + encode_sattr3(xdr, args->sattr, tag);
5361 encode_nfspath3(xdr, args->pages, args->pathlen);
5364 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5365 const struct nfs3_symlinkargs *args)
5367 encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5368 - encode_symlinkdata3(xdr, args);
5369 + encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5373 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5376 static void encode_devicedata3(struct xdr_stream *xdr,
5377 - const struct nfs3_mknodargs *args)
5378 + const struct nfs3_mknodargs *args, int tag)
5380 - encode_sattr3(xdr, args->sattr);
5381 + encode_sattr3(xdr, args->sattr, tag);
5382 encode_specdata3(xdr, args->rdev);
5385 static void encode_mknoddata3(struct xdr_stream *xdr,
5386 - const struct nfs3_mknodargs *args)
5387 + const struct nfs3_mknodargs *args, int tag)
5389 encode_ftype3(xdr, args->type);
5390 switch (args->type) {
5393 - encode_devicedata3(xdr, args);
5394 + encode_devicedata3(xdr, args, tag);
5398 - encode_sattr3(xdr, args->sattr);
5399 + encode_sattr3(xdr, args->sattr, tag);
5403 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5404 const struct nfs3_mknodargs *args)
5406 encode_diropargs3(xdr, args->fh, args->name, args->len);
5407 - encode_mknoddata3(xdr, args);
5408 + encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5412 diff -NurpP --minimal linux-3.9.4/fs/nfs/super.c linux-3.9.4-vs2.3.6.1/fs/nfs/super.c
5413 --- linux-3.9.4/fs/nfs/super.c 2013-05-31 13:45:24.000000000 +0000
5414 +++ linux-3.9.4-vs2.3.6.1/fs/nfs/super.c 2013-05-31 15:41:34.000000000 +0000
5416 #include <linux/parser.h>
5417 #include <linux/nsproxy.h>
5418 #include <linux/rcupdate.h>
5419 +#include <linux/vs_tag.h>
5421 #include <asm/uaccess.h>
5423 @@ -103,6 +104,7 @@ enum {
5429 /* Mount options that take string arguments */
5431 @@ -115,6 +117,9 @@ enum {
5432 /* Special mount options */
5433 Opt_userspace, Opt_deprecated, Opt_sloppy,
5435 + /* Linux-VServer tagging options */
5436 + Opt_tag, Opt_notag,
5441 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5442 { Opt_fscache_uniq, "fsc=%s" },
5443 { Opt_local_lock, "local_lock=%s" },
5445 + { Opt_tag, "tag" },
5446 + { Opt_notag, "notag" },
5447 + { Opt_tagid, "tagid=%u" },
5449 /* The following needs to be listed after all other options */
5450 { Opt_nfsvers, "v%s" },
5452 @@ -635,6 +644,7 @@ static void nfs_show_mount_options(struc
5453 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5454 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5455 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5456 + { NFS_MOUNT_TAGGED, ",tag", "" },
5459 const struct proc_nfs_info *nfs_infop;
5460 @@ -1261,6 +1271,14 @@ static int nfs_parse_mount_options(char
5461 case Opt_nomigration:
5462 mnt->options &= NFS_OPTION_MIGRATION;
5464 +#ifndef CONFIG_TAGGING_NONE
5466 + mnt->flags |= NFS_MOUNT_TAGGED;
5469 + mnt->flags &= ~NFS_MOUNT_TAGGED;
5474 * options that take numeric values
5475 @@ -1347,6 +1365,12 @@ static int nfs_parse_mount_options(char
5476 goto out_invalid_value;
5477 mnt->minorversion = option;
5479 +#ifdef CONFIG_PROPAGATE
5482 + nfs_data.flags |= NFS_MOUNT_TAGGED;
5487 * options that take text values
5488 diff -NurpP --minimal linux-3.9.4/fs/nfsd/auth.c linux-3.9.4-vs2.3.6.1/fs/nfsd/auth.c
5489 --- linux-3.9.4/fs/nfsd/auth.c 2013-05-31 13:45:24.000000000 +0000
5490 +++ linux-3.9.4-vs2.3.6.1/fs/nfsd/auth.c 2013-05-31 14:47:11.000000000 +0000
5493 #include <linux/sched.h>
5494 #include <linux/user_namespace.h>
5495 +#include <linux/vs_tag.h>
5499 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5501 new->fsuid = rqstp->rq_cred.cr_uid;
5502 new->fsgid = rqstp->rq_cred.cr_gid;
5503 + /* FIXME: this desperately needs a tag :)
5504 + new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5507 rqgi = rqstp->rq_cred.cr_group_info;
5509 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfs3xdr.c linux-3.9.4-vs2.3.6.1/fs/nfsd/nfs3xdr.c
5510 --- linux-3.9.4/fs/nfsd/nfs3xdr.c 2013-05-31 13:45:24.000000000 +0000
5511 +++ linux-3.9.4-vs2.3.6.1/fs/nfsd/nfs3xdr.c 2013-05-31 16:17:38.000000000 +0000
5514 #include <linux/namei.h>
5515 #include <linux/sunrpc/svc_xprt.h>
5516 +#include <linux/vs_tag.h>
5520 @@ -98,6 +99,8 @@ static __be32 *
5521 decode_sattr3(__be32 *p, struct iattr *iap)
5529 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5530 iap->ia_mode = ntohl(*p++);
5533 - iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5534 + uid = make_kuid(&init_user_ns, ntohl(*p++));
5535 if (uid_valid(iap->ia_uid))
5536 iap->ia_valid |= ATTR_UID;
5539 - iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5540 + gid = make_kgid(&init_user_ns, ntohl(*p++));
5541 if (gid_valid(iap->ia_gid))
5542 iap->ia_valid |= ATTR_GID;
5544 + iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5545 + iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5546 + iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5550 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5551 *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5552 *p++ = htonl((u32) stat->mode);
5553 *p++ = htonl((u32) stat->nlink);
5554 - *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5555 - *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5556 + *p++ = htonl((u32) from_kuid(&init_user_ns,
5557 + TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5558 + stat->uid, stat->tag)));
5559 + *p++ = htonl((u32) from_kgid(&init_user_ns,
5560 + TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5561 + stat->gid, stat->tag)));
5562 if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5563 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5565 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfs4xdr.c linux-3.9.4-vs2.3.6.1/fs/nfsd/nfs4xdr.c
5566 --- linux-3.9.4/fs/nfsd/nfs4xdr.c 2013-05-31 14:22:27.000000000 +0000
5567 +++ linux-3.9.4-vs2.3.6.1/fs/nfsd/nfs4xdr.c 2013-05-31 14:47:11.000000000 +0000
5569 #include <linux/utsname.h>
5570 #include <linux/pagemap.h>
5571 #include <linux/sunrpc/svcauth_gss.h>
5572 +#include <linux/vs_tag.h>
5576 @@ -2349,14 +2350,18 @@ out_acl:
5577 WRITE32(stat.nlink);
5579 if (bmval1 & FATTR4_WORD1_OWNER) {
5580 - status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5581 + status = nfsd4_encode_user(rqstp,
5582 + TAGINO_UID(DX_TAG(dentry->d_inode),
5583 + stat.uid, stat.tag), &p, &buflen);
5584 if (status == nfserr_resource)
5589 if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5590 - status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5591 + status = nfsd4_encode_group(rqstp,
5592 + TAGINO_GID(DX_TAG(dentry->d_inode),
5593 + stat.gid, stat.tag), &p, &buflen);
5594 if (status == nfserr_resource)
5597 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfsxdr.c linux-3.9.4-vs2.3.6.1/fs/nfsd/nfsxdr.c
5598 --- linux-3.9.4/fs/nfsd/nfsxdr.c 2013-05-31 13:45:24.000000000 +0000
5599 +++ linux-3.9.4-vs2.3.6.1/fs/nfsd/nfsxdr.c 2013-05-31 16:20:53.000000000 +0000
5604 +#include <linux/vs_tag.h>
5606 #define NFSDDBG_FACILITY NFSDDBG_XDR
5608 @@ -89,6 +90,8 @@ static __be32 *
5609 decode_sattr(__be32 *p, struct iattr *iap)
5617 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5620 if ((tmp = ntohl(*p++)) != (u32)-1) {
5621 - iap->ia_uid = make_kuid(&init_user_ns, tmp);
5622 + uid = make_kuid(&init_user_ns, tmp);
5623 if (uid_valid(iap->ia_uid))
5624 iap->ia_valid |= ATTR_UID;
5626 if ((tmp = ntohl(*p++)) != (u32)-1) {
5627 - iap->ia_gid = make_kgid(&init_user_ns, tmp);
5628 + gid = make_kgid(&init_user_ns, tmp);
5629 if (gid_valid(iap->ia_gid))
5630 iap->ia_valid |= ATTR_GID;
5632 + iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5633 + iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5634 + iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5635 if ((tmp = ntohl(*p++)) != (u32)-1) {
5636 iap->ia_valid |= ATTR_SIZE;
5638 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5639 *p++ = htonl(nfs_ftypes[type >> 12]);
5640 *p++ = htonl((u32) stat->mode);
5641 *p++ = htonl((u32) stat->nlink);
5642 - *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5643 - *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5644 + *p++ = htonl((u32) from_kuid(&init_user_ns,
5645 + TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5646 + *p++ = htonl((u32) from_kgid(&init_user_ns,
5647 + TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5649 if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5650 *p++ = htonl(NFS_MAXPATHLEN);
5651 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/dlmglue.c linux-3.9.4-vs2.3.6.1/fs/ocfs2/dlmglue.c
5652 --- linux-3.9.4/fs/ocfs2/dlmglue.c 2013-05-31 13:45:24.000000000 +0000
5653 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/dlmglue.c 2013-05-31 15:47:29.000000000 +0000
5654 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5655 lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5656 lvb->lvb_iuid = cpu_to_be32(i_uid_read(inode));
5657 lvb->lvb_igid = cpu_to_be32(i_gid_read(inode));
5658 + lvb->lvb_itag = cpu_to_be16(inode->i_tag);
5659 lvb->lvb_imode = cpu_to_be16(inode->i_mode);
5660 lvb->lvb_inlink = cpu_to_be16(inode->i_nlink);
5661 lvb->lvb_iatime_packed =
5662 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5664 i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5665 i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5666 + i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5667 inode->i_mode = be16_to_cpu(lvb->lvb_imode);
5668 set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5669 ocfs2_unpack_timespec(&inode->i_atime,
5670 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/dlmglue.h linux-3.9.4-vs2.3.6.1/fs/ocfs2/dlmglue.h
5671 --- linux-3.9.4/fs/ocfs2/dlmglue.h 2012-12-11 03:30:57.000000000 +0000
5672 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/dlmglue.h 2013-05-31 14:47:11.000000000 +0000
5673 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5676 __be32 lvb_igeneration;
5677 - __be32 lvb_reserved2;
5679 + __be16 lvb_reserved2;
5682 #define OCFS2_QINFO_LVB_VERSION 1
5683 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/file.c linux-3.9.4-vs2.3.6.1/fs/ocfs2/file.c
5684 --- linux-3.9.4/fs/ocfs2/file.c 2013-05-31 13:45:24.000000000 +0000
5685 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/file.c 2013-05-31 14:47:11.000000000 +0000
5686 @@ -1124,7 +1124,7 @@ int ocfs2_setattr(struct dentry *dentry,
5687 attr->ia_valid &= ~ATTR_SIZE;
5689 #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5690 - | ATTR_GID | ATTR_UID | ATTR_MODE)
5691 + | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5692 if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5695 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/inode.c linux-3.9.4-vs2.3.6.1/fs/ocfs2/inode.c
5696 --- linux-3.9.4/fs/ocfs2/inode.c 2013-05-31 13:45:24.000000000 +0000
5697 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/inode.c 2013-05-31 20:39:47.000000000 +0000
5699 #include <linux/highmem.h>
5700 #include <linux/pagemap.h>
5701 #include <linux/quotaops.h>
5702 +#include <linux/vs_tag.h>
5704 #include <asm/byteorder.h>
5706 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5708 unsigned int flags = OCFS2_I(inode)->ip_attr;
5710 - inode->i_flags &= ~(S_IMMUTABLE |
5711 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5712 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5714 if (flags & OCFS2_IMMUTABLE_FL)
5715 inode->i_flags |= S_IMMUTABLE;
5716 + if (flags & OCFS2_IXUNLINK_FL)
5717 + inode->i_flags |= S_IXUNLINK;
5719 if (flags & OCFS2_SYNC_FL)
5720 inode->i_flags |= S_SYNC;
5721 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5722 inode->i_flags |= S_NOATIME;
5723 if (flags & OCFS2_DIRSYNC_FL)
5724 inode->i_flags |= S_DIRSYNC;
5726 + inode->i_vflags &= ~(V_BARRIER | V_COW);
5728 + if (flags & OCFS2_BARRIER_FL)
5729 + inode->i_vflags |= V_BARRIER;
5730 + if (flags & OCFS2_COW_FL)
5731 + inode->i_vflags |= V_COW;
5734 /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5735 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5737 unsigned int flags = oi->vfs_inode.i_flags;
5738 + unsigned int vflags = oi->vfs_inode.i_vflags;
5740 + oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5741 + OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5742 + OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5743 + OCFS2_BARRIER_FL | OCFS2_COW_FL);
5745 + if (flags & S_IMMUTABLE)
5746 + oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5747 + if (flags & S_IXUNLINK)
5748 + oi->ip_attr |= OCFS2_IXUNLINK_FL;
5750 - oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5751 - OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5753 oi->ip_attr |= OCFS2_SYNC_FL;
5754 if (flags & S_APPEND)
5755 oi->ip_attr |= OCFS2_APPEND_FL;
5756 - if (flags & S_IMMUTABLE)
5757 - oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5758 if (flags & S_NOATIME)
5759 oi->ip_attr |= OCFS2_NOATIME_FL;
5760 if (flags & S_DIRSYNC)
5761 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5763 + if (vflags & V_BARRIER)
5764 + oi->ip_attr |= OCFS2_BARRIER_FL;
5765 + if (vflags & V_COW)
5766 + oi->ip_attr |= OCFS2_COW_FL;
5769 struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5770 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5771 struct super_block *sb;
5772 struct ocfs2_super *osb;
5779 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5780 inode->i_generation = le32_to_cpu(fe->i_generation);
5781 inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5782 inode->i_mode = le16_to_cpu(fe->i_mode);
5783 - i_uid_write(inode, le32_to_cpu(fe->i_uid));
5784 - i_gid_write(inode, le32_to_cpu(fe->i_gid));
5785 + uid = le32_to_cpu(fe->i_uid);
5786 + gid = le32_to_cpu(fe->i_gid);
5787 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5788 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5789 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5790 + /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5792 /* Fast symlinks will have i_size but no allocated clusters. */
5793 if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5794 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/inode.h linux-3.9.4-vs2.3.6.1/fs/ocfs2/inode.h
5795 --- linux-3.9.4/fs/ocfs2/inode.h 2012-12-11 03:30:57.000000000 +0000
5796 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/inode.h 2013-05-31 14:47:11.000000000 +0000
5797 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5799 void ocfs2_set_inode_flags(struct inode *inode);
5800 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5801 +int ocfs2_sync_flags(struct inode *inode, int, int);
5803 static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5805 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ioctl.c linux-3.9.4-vs2.3.6.1/fs/ocfs2/ioctl.c
5806 --- linux-3.9.4/fs/ocfs2/ioctl.c 2013-05-31 13:45:24.000000000 +0000
5807 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/ioctl.c 2013-05-31 14:47:11.000000000 +0000
5808 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5812 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5813 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5815 + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5816 + struct buffer_head *bh = NULL;
5817 + handle_t *handle = NULL;
5820 + status = ocfs2_inode_lock(inode, &bh, 1);
5822 + mlog_errno(status);
5825 + handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5826 + if (IS_ERR(handle)) {
5827 + status = PTR_ERR(handle);
5828 + mlog_errno(status);
5832 + inode->i_flags = flags;
5833 + inode->i_vflags = vflags;
5834 + ocfs2_get_inode_flags(OCFS2_I(inode));
5836 + status = ocfs2_mark_inode_dirty(handle, inode, bh);
5838 + mlog_errno(status);
5840 + ocfs2_commit_trans(osb, handle);
5842 + ocfs2_inode_unlock(inode, 1);
5847 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5850 struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5851 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5852 if (!S_ISDIR(inode->i_mode))
5853 flags &= ~OCFS2_DIRSYNC_FL;
5855 + if (IS_BARRIER(inode)) {
5856 + vxwprintk_task(1, "messing with the barrier.");
5860 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5861 if (IS_ERR(handle)) {
5862 status = PTR_ERR(handle);
5863 @@ -879,6 +918,7 @@ bail:
5868 long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5870 struct inode *inode = file_inode(filp);
5871 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/namei.c linux-3.9.4-vs2.3.6.1/fs/ocfs2/namei.c
5872 --- linux-3.9.4/fs/ocfs2/namei.c 2013-05-31 13:45:24.000000000 +0000
5873 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/namei.c 2013-05-31 15:52:25.000000000 +0000
5875 #include <linux/slab.h>
5876 #include <linux/highmem.h>
5877 #include <linux/quotaops.h>
5878 +#include <linux/vs_tag.h>
5880 #include <cluster/masklog.h>
5882 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5883 struct ocfs2_dinode *fe = NULL;
5884 struct ocfs2_extent_list *fel;
5890 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5891 fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5892 fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5893 fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5894 - fe->i_uid = cpu_to_le32(i_uid_read(inode));
5895 - fe->i_gid = cpu_to_le32(i_gid_read(inode));
5897 + tag = dx_current_fstag(osb->sb);
5898 + fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), i_uid_read(inode), tag));
5899 + fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), i_gid_read(inode), tag));
5900 + inode->i_tag = tag; /* is this correct? */
5901 fe->i_mode = cpu_to_le16(inode->i_mode);
5902 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5903 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5904 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ocfs2.h linux-3.9.4-vs2.3.6.1/fs/ocfs2/ocfs2.h
5905 --- linux-3.9.4/fs/ocfs2/ocfs2.h 2012-12-11 03:30:57.000000000 +0000
5906 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/ocfs2.h 2013-05-31 14:47:11.000000000 +0000
5907 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5909 OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5910 OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5911 + OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5914 #define OCFS2_OSB_SOFT_RO 0x0001
5915 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ocfs2_fs.h linux-3.9.4-vs2.3.6.1/fs/ocfs2/ocfs2_fs.h
5916 --- linux-3.9.4/fs/ocfs2/ocfs2_fs.h 2012-12-11 03:30:57.000000000 +0000
5917 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/ocfs2_fs.h 2013-05-31 14:47:11.000000000 +0000
5918 @@ -266,6 +266,11 @@
5919 #define OCFS2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
5920 #define OCFS2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
5922 +#define OCFS2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
5924 +#define OCFS2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
5925 +#define OCFS2_COW_FL FS_COW_FL /* Copy on Write marker */
5927 #define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
5928 #define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
5930 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/super.c linux-3.9.4-vs2.3.6.1/fs/ocfs2/super.c
5931 --- linux-3.9.4/fs/ocfs2/super.c 2013-05-31 13:45:25.000000000 +0000
5932 +++ linux-3.9.4-vs2.3.6.1/fs/ocfs2/super.c 2013-05-31 14:47:11.000000000 +0000
5933 @@ -185,6 +185,7 @@ enum {
5937 + Opt_tag, Opt_notag, Opt_tagid,
5941 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5942 {Opt_coherency_full, "coherency=full"},
5943 {Opt_resv_level, "resv_level=%u"},
5944 {Opt_dir_resv_level, "dir_resv_level=%u"},
5946 + {Opt_notag, "notag"},
5947 + {Opt_tagid, "tagid=%u"},
5951 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5955 + if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5956 + (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5958 + mlog(ML_ERROR, "Cannot change tagging on remount\n");
5962 /* We're going to/from readonly mode. */
5963 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5964 /* Disable quota accounting before remounting RO */
5965 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5967 ocfs2_complete_mount_recovery(osb);
5969 + if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5970 + sb->s_flags |= MS_TAGGED;
5972 if (ocfs2_mount_local(osb))
5973 snprintf(nodestr, sizeof(nodestr), "local");
5975 @@ -1504,6 +1518,20 @@ static int ocfs2_parse_options(struct su
5976 option < OCFS2_MAX_RESV_LEVEL)
5977 mopt->dir_resv_level = option;
5979 +#ifndef CONFIG_TAGGING_NONE
5981 + mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5984 + mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5987 +#ifdef CONFIG_PROPAGATE
5990 + mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5995 "Unrecognized mount option \"%s\" "
5996 diff -NurpP --minimal linux-3.9.4/fs/open.c linux-3.9.4-vs2.3.6.1/fs/open.c
5997 --- linux-3.9.4/fs/open.c 2013-05-31 13:45:25.000000000 +0000
5998 +++ linux-3.9.4-vs2.3.6.1/fs/open.c 2013-05-31 21:09:19.000000000 +0000
6000 #include <linux/ima.h>
6001 #include <linux/dnotify.h>
6002 #include <linux/compat.h>
6003 +#include <linux/vs_base.h>
6004 +#include <linux/vs_limit.h>
6005 +#include <linux/vs_tag.h>
6006 +#include <linux/vs_cowbl.h>
6007 +#include <linux/vserver/dlimit.h>
6009 #include "internal.h"
6011 @@ -67,6 +72,11 @@ long vfs_truncate(struct path *path, lof
6012 struct inode *inode;
6015 +#ifdef CONFIG_VSERVER_COWBL
6016 + error = cow_check_and_break(path);
6020 inode = path->dentry->d_inode;
6022 /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6023 @@ -532,6 +542,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6024 unsigned int lookup_flags = LOOKUP_FOLLOW;
6026 error = user_path_at(dfd, filename, lookup_flags, &path);
6027 +#ifdef CONFIG_VSERVER_COWBL
6029 + error = cow_check_and_break(&path);
6035 error = chmod_common(&path, mode);
6037 @@ -564,13 +581,13 @@ static int chown_common(struct path *pat
6038 if (!uid_valid(uid))
6040 newattrs.ia_valid |= ATTR_UID;
6041 - newattrs.ia_uid = uid;
6042 + newattrs.ia_uid = dx_map_uid(user);
6044 if (group != (gid_t) -1) {
6045 if (!gid_valid(gid))
6047 newattrs.ia_valid |= ATTR_GID;
6048 - newattrs.ia_gid = gid;
6049 + newattrs.ia_gid = dx_map_gid(group);
6051 if (!S_ISDIR(inode->i_mode))
6052 newattrs.ia_valid |=
6053 @@ -604,6 +621,18 @@ retry:
6054 error = mnt_want_write(path.mnt);
6057 +#ifdef CONFIG_VSERVER_COWBL
6058 + error = cow_check_and_break(&path);
6061 +#ifdef CONFIG_VSERVER_COWBL
6062 + error = cow_check_and_break(&path);
6065 +#ifdef CONFIG_VSERVER_COWBL
6066 + error = cow_check_and_break(&path);
6069 error = chown_common(&path, user, group);
6070 mnt_drop_write(path.mnt);
6072 diff -NurpP --minimal linux-3.9.4/fs/proc/array.c linux-3.9.4-vs2.3.6.1/fs/proc/array.c
6073 --- linux-3.9.4/fs/proc/array.c 2013-05-31 13:45:25.000000000 +0000
6074 +++ linux-3.9.4-vs2.3.6.1/fs/proc/array.c 2013-05-31 14:47:11.000000000 +0000
6076 #include <linux/ptrace.h>
6077 #include <linux/tracehook.h>
6078 #include <linux/user_namespace.h>
6079 +#include <linux/vs_context.h>
6080 +#include <linux/vs_network.h>
6082 #include <asm/pgtable.h>
6083 #include <asm/processor.h>
6084 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
6086 ppid = pid_alive(p) ?
6087 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6088 + if (unlikely(vx_current_initpid(p->pid)))
6093 struct task_struct *tracer = ptrace_parent(p);
6094 @@ -297,7 +302,7 @@ static inline void task_sig(struct seq_f
6097 static void render_cap_t(struct seq_file *m, const char *header,
6099 + struct vx_info *vxi, kernel_cap_t *a)
6103 @@ -331,10 +336,11 @@ static inline void task_cap(struct seq_f
6104 NORM_CAPS(cap_effective);
6105 NORM_CAPS(cap_bset);
6107 - render_cap_t(m, "CapInh:\t", &cap_inheritable);
6108 - render_cap_t(m, "CapPrm:\t", &cap_permitted);
6109 - render_cap_t(m, "CapEff:\t", &cap_effective);
6110 - render_cap_t(m, "CapBnd:\t", &cap_bset);
6111 + /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6112 + render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6113 + render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6114 + render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6115 + render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6118 static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
6119 @@ -363,6 +369,42 @@ static void task_cpus_allowed(struct seq
6123 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6124 + struct pid *pid, struct task_struct *task)
6126 + seq_printf(m, "Proxy:\t%p(%c)\n"
6134 + (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6135 + atomic_read(&task->nsproxy->count),
6136 + task->nsproxy->uts_ns,
6137 + (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6138 + task->nsproxy->ipc_ns,
6139 + (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6140 + task->nsproxy->mnt_ns,
6141 + (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6142 + task->nsproxy->pid_ns,
6143 + (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6144 + task->nsproxy->net_ns,
6145 + (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6149 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6151 + if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6154 + seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6155 + seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6159 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6160 struct pid *pid, struct task_struct *task)
6162 @@ -380,6 +422,7 @@ int proc_pid_status(struct seq_file *m,
6163 task_seccomp(m, task);
6164 task_cpus_allowed(m, task);
6165 cpuset_task_status_allowed(m, task);
6166 + task_vs_id(m, task);
6167 task_context_switch_counts(m, task);
6170 @@ -489,6 +532,17 @@ static int do_task_stat(struct seq_file
6171 /* convert nsec -> ticks */
6172 start_time = nsec_to_clock_t(start_time);
6174 + /* fixup start time for virt uptime */
6175 + if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6176 + unsigned long long bias =
6177 + current->vx_info->cvirt.bias_clock;
6179 + if (start_time > bias)
6180 + start_time -= bias;
6185 seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6186 seq_put_decimal_ll(m, ' ', ppid);
6187 seq_put_decimal_ll(m, ' ', pgid);
6188 diff -NurpP --minimal linux-3.9.4/fs/proc/base.c linux-3.9.4-vs2.3.6.1/fs/proc/base.c
6189 --- linux-3.9.4/fs/proc/base.c 2013-05-31 13:45:25.000000000 +0000
6190 +++ linux-3.9.4-vs2.3.6.1/fs/proc/base.c 2013-05-31 14:47:11.000000000 +0000
6192 #include <linux/fs_struct.h>
6193 #include <linux/slab.h>
6194 #include <linux/flex_array.h>
6195 +#include <linux/vs_context.h>
6196 +#include <linux/vs_network.h>
6197 #ifdef CONFIG_HARDWALL
6198 #include <asm/hardwall.h>
6200 @@ -944,11 +946,15 @@ static ssize_t oom_adj_write(struct file
6201 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6203 if (oom_adj < task->signal->oom_score_adj &&
6204 - !capable(CAP_SYS_RESOURCE)) {
6205 + !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6210 + /* prevent guest processes from circumventing the oom killer */
6211 + if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6212 + oom_adj = OOM_ADJUST_MIN;
6215 * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6216 * /proc/pid/oom_score_adj instead.
6217 @@ -1528,6 +1534,8 @@ struct inode *proc_pid_make_inode(struct
6218 inode->i_gid = cred->egid;
6221 + /* procfs is xid tagged */
6222 + i_tag_write(inode, (tag_t)vx_task_xid(task));
6223 security_task_to_inode(task, inode);
6226 @@ -1573,6 +1581,8 @@ int pid_getattr(struct vfsmount *mnt, st
6230 +static unsigned name_to_int(struct dentry *dentry);
6233 * Exceptional case: normally we are not allowed to unhash a busy
6234 * directory. In this case, however, we can do it - no aliasing problems
6235 @@ -1601,6 +1611,12 @@ int pid_revalidate(struct dentry *dentry
6236 task = get_proc_task(inode);
6239 + unsigned pid = name_to_int(dentry);
6241 + if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6242 + put_task_struct(task);
6245 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6246 task_dumpable(task)) {
6248 @@ -1617,6 +1633,7 @@ int pid_revalidate(struct dentry *dentry
6249 put_task_struct(task);
6256 @@ -2059,6 +2076,13 @@ static struct dentry *proc_pident_lookup
6260 + /* TODO: maybe we can come up with a generic approach? */
6261 + if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6262 + (dentry->d_name.len == 5) &&
6263 + (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6264 + !memcmp(dentry->d_name.name, "ninfo", 5)))
6268 * Yes, it does not scale. And it should not. Don't add
6269 * new entries into /proc/<tgid>/ without very good reasons.
6270 @@ -2493,6 +2517,9 @@ static int proc_pid_personality(struct s
6271 static const struct file_operations proc_task_operations;
6272 static const struct inode_operations proc_task_inode_operations;
6274 +extern int proc_pid_vx_info(struct task_struct *, char *);
6275 +extern int proc_pid_nx_info(struct task_struct *, char *);
6277 static const struct pid_entry tgid_base_stuff[] = {
6278 DIR("task", S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6279 DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6280 @@ -2559,6 +2586,8 @@ static const struct pid_entry tgid_base_
6281 #ifdef CONFIG_CGROUPS
6282 REG("cgroup", S_IRUGO, proc_cgroup_operations),
6284 + INF("vinfo", S_IRUGO, proc_pid_vx_info),
6285 + INF("ninfo", S_IRUGO, proc_pid_nx_info),
6286 INF("oom_score", S_IRUGO, proc_oom_score),
6287 REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6288 REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6289 @@ -2583,6 +2612,7 @@ static const struct pid_entry tgid_base_
6290 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
6291 REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6293 + ONE("nsproxy", S_IRUGO, proc_pid_nsproxy),
6296 static int proc_tgid_base_readdir(struct file * filp,
6297 @@ -2770,7 +2800,7 @@ retry:
6299 pid = find_ge_pid(iter.tgid, ns);
6301 - iter.tgid = pid_nr_ns(pid, ns);
6302 + iter.tgid = pid_unmapped_nr_ns(pid, ns);
6303 iter.task = pid_task(pid, PIDTYPE_PID);
6304 /* What we to know is if the pid we have find is the
6305 * pid of a thread_group_leader. Testing for task
6306 @@ -2800,7 +2830,7 @@ static int proc_pid_fill_cache(struct fi
6307 struct tgid_iter iter)
6309 char name[PROC_NUMBUF];
6310 - int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6311 + int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6312 return proc_fill_cache(filp, dirent, filldir, name, len,
6313 proc_pid_instantiate, iter.task, NULL);
6315 @@ -2833,6 +2863,8 @@ int proc_pid_readdir(struct file * filp,
6316 __filldir = fake_filldir;
6318 filp->f_pos = iter.tgid + TGID_OFFSET;
6319 + if (!vx_proc_task_visible(iter.task))
6321 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6322 put_task_struct(iter.task);
6324 @@ -2993,6 +3025,8 @@ static struct dentry *proc_task_lookup(s
6325 tid = name_to_int(dentry);
6328 + if (vx_current_initpid(tid))
6331 ns = dentry->d_sb->s_fs_info;
6333 diff -NurpP --minimal linux-3.9.4/fs/proc/generic.c linux-3.9.4-vs2.3.6.1/fs/proc/generic.c
6334 --- linux-3.9.4/fs/proc/generic.c 2013-05-31 13:45:25.000000000 +0000
6335 +++ linux-3.9.4-vs2.3.6.1/fs/proc/generic.c 2013-05-31 16:13:42.000000000 +0000
6337 #include <linux/bitops.h>
6338 #include <linux/spinlock.h>
6339 #include <linux/completion.h>
6340 +#include <linux/vserver/inode.h>
6341 #include <asm/uaccess.h>
6343 #include "internal.h"
6344 @@ -409,6 +410,8 @@ struct dentry *proc_lookup_de(struct pro
6345 for (de = de->subdir; de ; de = de->next) {
6346 if (de->namelen != dentry->d_name.len)
6348 + if (!vx_hide_check(0, de->vx_flags))
6350 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6352 spin_unlock(&proc_subdir_lock);
6353 @@ -417,6 +420,8 @@ struct dentry *proc_lookup_de(struct pro
6354 return ERR_PTR(-ENOMEM);
6355 d_set_d_op(dentry, &proc_dentry_operations);
6356 d_add(dentry, inode);
6357 + /* generic proc entries belong to the host */
6358 + i_tag_write(inode, 0);
6362 @@ -485,6 +490,8 @@ int proc_readdir_de(struct proc_dir_entr
6364 /* filldir passes info to user space */
6366 + if (!vx_hide_check(0, de->vx_flags))
6368 spin_unlock(&proc_subdir_lock);
6369 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6370 de->low_ino, de->mode >> 12) < 0) {
6371 @@ -492,6 +499,7 @@ int proc_readdir_de(struct proc_dir_entr
6374 spin_lock(&proc_subdir_lock);
6379 @@ -603,6 +611,7 @@ static struct proc_dir_entry *__proc_cre
6383 + ent->vx_flags = IATTR_PROC_DEFAULT;
6384 atomic_set(&ent->count, 1);
6385 spin_lock_init(&ent->pde_unload_lock);
6386 INIT_LIST_HEAD(&ent->pde_openers);
6387 @@ -626,7 +635,8 @@ struct proc_dir_entry *proc_symlink(cons
6393 + ent->vx_flags = IATTR_PROC_SYMLINK;
6397 diff -NurpP --minimal linux-3.9.4/fs/proc/inode.c linux-3.9.4-vs2.3.6.1/fs/proc/inode.c
6398 --- linux-3.9.4/fs/proc/inode.c 2013-05-31 13:45:25.000000000 +0000
6399 +++ linux-3.9.4-vs2.3.6.1/fs/proc/inode.c 2013-05-31 14:47:11.000000000 +0000
6400 @@ -458,6 +458,8 @@ struct inode *proc_get_inode(struct supe
6401 inode->i_uid = de->uid;
6402 inode->i_gid = de->gid;
6405 + PROC_I(inode)->vx_flags = de->vx_flags;
6407 inode->i_size = de->size;
6409 diff -NurpP --minimal linux-3.9.4/fs/proc/internal.h linux-3.9.4-vs2.3.6.1/fs/proc/internal.h
6410 --- linux-3.9.4/fs/proc/internal.h 2013-05-31 13:45:25.000000000 +0000
6411 +++ linux-3.9.4-vs2.3.6.1/fs/proc/internal.h 2013-05-31 16:04:34.000000000 +0000
6413 #include <linux/sched.h>
6414 #include <linux/proc_fs.h>
6415 #include <linux/binfmts.h>
6416 +#include <linux/vs_pid.h>
6418 struct ctl_table_header;
6421 @@ -56,6 +58,9 @@ extern int proc_pid_status(struct seq_fi
6422 struct pid *pid, struct task_struct *task);
6423 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6424 struct pid *pid, struct task_struct *task);
6425 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6426 + struct pid *pid, struct task_struct *task);
6428 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6430 extern const struct file_operations proc_tid_children_operations;
6431 @@ -89,11 +94,16 @@ static inline struct pid *proc_pid(struc
6432 return PROC_I(inode)->pid;
6435 -static inline struct task_struct *get_proc_task(struct inode *inode)
6436 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6438 return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6441 +static inline struct task_struct *get_proc_task(struct inode *inode)
6443 + return vx_get_proc_task(inode, proc_pid(inode));
6446 static inline int proc_fd(struct inode *inode)
6448 return PROC_I(inode)->fd;
6449 diff -NurpP --minimal linux-3.9.4/fs/proc/loadavg.c linux-3.9.4-vs2.3.6.1/fs/proc/loadavg.c
6450 --- linux-3.9.4/fs/proc/loadavg.c 2012-12-11 03:30:57.000000000 +0000
6451 +++ linux-3.9.4-vs2.3.6.1/fs/proc/loadavg.c 2013-05-31 14:47:11.000000000 +0000
6454 static int loadavg_proc_show(struct seq_file *m, void *v)
6456 + unsigned long running;
6457 + unsigned int threads;
6458 unsigned long avnrun[3];
6460 get_avenrun(avnrun, FIXED_1/200, 0);
6462 + if (vx_flags(VXF_VIRT_LOAD, 0)) {
6463 + struct vx_info *vxi = current_vx_info();
6465 + running = atomic_read(&vxi->cvirt.nr_running);
6466 + threads = atomic_read(&vxi->cvirt.nr_threads);
6468 + running = nr_running();
6469 + threads = nr_threads;
6472 seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6473 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6474 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6475 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6476 - nr_running(), nr_threads,
6478 task_active_pid_ns(current)->last_pid);
6481 diff -NurpP --minimal linux-3.9.4/fs/proc/meminfo.c linux-3.9.4-vs2.3.6.1/fs/proc/meminfo.c
6482 --- linux-3.9.4/fs/proc/meminfo.c 2013-05-31 13:45:25.000000000 +0000
6483 +++ linux-3.9.4-vs2.3.6.1/fs/proc/meminfo.c 2013-05-31 16:05:39.000000000 +0000
6484 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6485 allowed = ((totalram_pages - hugetlb_total_pages())
6486 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6488 - cached = global_page_state(NR_FILE_PAGES) -
6489 + cached = vx_flags(VXF_VIRT_MEM, 0) ?
6490 + vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6491 total_swapcache_pages() - i.bufferram;
6494 diff -NurpP --minimal linux-3.9.4/fs/proc/root.c linux-3.9.4-vs2.3.6.1/fs/proc/root.c
6495 --- linux-3.9.4/fs/proc/root.c 2013-05-31 13:45:25.000000000 +0000
6496 +++ linux-3.9.4-vs2.3.6.1/fs/proc/root.c 2013-05-31 14:47:11.000000000 +0000
6498 #include <linux/mount.h>
6499 #include <linux/pid_namespace.h>
6500 #include <linux/parser.h>
6501 +#include <linux/vserver/inode.h>
6503 #include "internal.h"
6505 +struct proc_dir_entry *proc_virtual;
6507 +extern void proc_vx_init(void);
6509 static int proc_test_super(struct super_block *sb, void *data)
6511 return sb->s_fs_info == data;
6512 @@ -182,6 +187,7 @@ void __init proc_root_init(void)
6514 proc_mkdir("bus", NULL);
6519 static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6520 @@ -248,6 +254,7 @@ struct proc_dir_entry proc_root = {
6521 .proc_iops = &proc_root_inode_operations,
6522 .proc_fops = &proc_root_operations,
6523 .parent = &proc_root,
6524 + .vx_flags = IATTR_ADMIN | IATTR_WATCH,
6528 diff -NurpP --minimal linux-3.9.4/fs/proc/self.c linux-3.9.4-vs2.3.6.1/fs/proc/self.c
6529 --- linux-3.9.4/fs/proc/self.c 2013-02-19 13:58:49.000000000 +0000
6530 +++ linux-3.9.4-vs2.3.6.1/fs/proc/self.c 2013-05-31 20:57:54.000000000 +0000
6532 #include <linux/proc_fs.h>
6533 #include <linux/sched.h>
6534 #include <linux/namei.h>
6535 +#include <linux/vserver/inode.h>
6539 @@ -56,4 +57,5 @@ void __init proc_self_init(void)
6540 mode = S_IFLNK | S_IRWXUGO;
6541 proc_self_symlink = proc_create("self", mode, NULL, NULL );
6542 proc_self_symlink->proc_iops = &proc_self_inode_operations;
6543 + proc_self_symlink->vx_flags = IATTR_PROC_SYMLINK;
6545 diff -NurpP --minimal linux-3.9.4/fs/proc/stat.c linux-3.9.4-vs2.3.6.1/fs/proc/stat.c
6546 --- linux-3.9.4/fs/proc/stat.c 2012-12-11 03:30:57.000000000 +0000
6547 +++ linux-3.9.4-vs2.3.6.1/fs/proc/stat.c 2013-05-31 14:47:11.000000000 +0000
6549 #include <linux/slab.h>
6550 #include <linux/time.h>
6551 #include <linux/irqnr.h>
6552 +#include <linux/vserver/cvirt.h>
6553 #include <asm/cputime.h>
6554 #include <linux/tick.h>
6555 +#include <linux/cpuset.h>
6557 #ifndef arch_irq_stat_cpu
6558 #define arch_irq_stat_cpu(cpu) 0
6559 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6560 u64 sum_softirq = 0;
6561 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6562 struct timespec boottime;
6563 + cpumask_var_t cpus_allowed;
6564 + bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6566 user = nice = system = idle = iowait =
6567 irq = softirq = steal = 0;
6568 guest = guest_nice = 0;
6569 getboottime(&boottime);
6571 + if (vx_flags(VXF_VIRT_UPTIME, 0))
6572 + vx_vsi_boottime(&boottime);
6575 + cpuset_cpus_allowed(current, cpus_allowed);
6577 jif = boottime.tv_sec;
6579 for_each_possible_cpu(i) {
6580 + if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6583 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6584 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6585 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6586 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6589 for_each_online_cpu(i) {
6590 + if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6593 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6594 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6595 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6596 diff -NurpP --minimal linux-3.9.4/fs/proc/uptime.c linux-3.9.4-vs2.3.6.1/fs/proc/uptime.c
6597 --- linux-3.9.4/fs/proc/uptime.c 2012-12-11 03:30:57.000000000 +0000
6598 +++ linux-3.9.4-vs2.3.6.1/fs/proc/uptime.c 2013-05-31 14:47:11.000000000 +0000
6600 #include <linux/seq_file.h>
6601 #include <linux/time.h>
6602 #include <linux/kernel_stat.h>
6603 +#include <linux/vserver/cvirt.h>
6604 #include <asm/cputime.h>
6606 static int uptime_proc_show(struct seq_file *m, void *v)
6607 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6608 nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6609 idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6612 + if (vx_flags(VXF_VIRT_UPTIME, 0))
6613 + vx_vsi_uptime(&uptime, &idle);
6615 seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6616 (unsigned long) uptime.tv_sec,
6617 (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6618 diff -NurpP --minimal linux-3.9.4/fs/proc_namespace.c linux-3.9.4-vs2.3.6.1/fs/proc_namespace.c
6619 --- linux-3.9.4/fs/proc_namespace.c 2012-12-11 03:30:57.000000000 +0000
6620 +++ linux-3.9.4-vs2.3.6.1/fs/proc_namespace.c 2013-05-31 17:17:53.000000000 +0000
6621 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6622 { MS_SYNCHRONOUS, ",sync" },
6623 { MS_DIRSYNC, ",dirsync" },
6624 { MS_MANDLOCK, ",mand" },
6625 + { MS_TAGGED, ",tag" },
6626 + { MS_NOTAGCHECK, ",notagcheck" },
6629 const struct proc_fs_info *fs_infop;
6630 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6631 seq_escape(m, s, " \t\n\\");
6634 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6636 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6639 + struct dentry *point;
6640 + struct mount *mnt = real_mount(vfsmnt);
6641 + struct mount *root_mnt;
6644 + if (mnt == mnt->mnt_ns->root)
6647 + br_read_lock(&vfsmount_lock);
6648 + root = current->fs->root;
6649 + root_mnt = real_mount(root.mnt);
6650 + point = root.dentry;
6652 + while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6653 + point = mnt->mnt_mountpoint;
6654 + mnt = mnt->mnt_parent;
6657 + ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6659 + br_read_unlock(&vfsmount_lock);
6665 +#define mnt_is_reachable(v) (1)
6668 static void show_type(struct seq_file *m, struct super_block *sb)
6670 mangle(m, sb->s_type->name);
6671 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6672 struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6673 struct super_block *sb = mnt_path.dentry->d_sb;
6675 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6677 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6680 + if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6681 + mnt == current->fs->root.mnt) {
6682 + seq_puts(m, "/dev/root / ");
6686 if (sb->s_op->show_devname) {
6687 err = sb->s_op->show_devname(m, mnt_path.dentry);
6689 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6691 seq_path(m, &mnt_path, " \t\n\\");
6695 seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6696 err = show_sb_opts(m, sb);
6697 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6698 struct path root = p->root;
6701 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6703 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6706 seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6707 MAJOR(sb->s_dev), MINOR(sb->s_dev));
6708 if (sb->s_op->show_path)
6709 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6710 struct super_block *sb = mnt_path.dentry->d_sb;
6713 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6715 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6718 + if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6719 + mnt == current->fs->root.mnt) {
6720 + seq_puts(m, "device /dev/root mounted on / ");
6725 if (sb->s_op->show_devname) {
6726 seq_puts(m, "device ");
6727 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6728 seq_puts(m, " mounted on ");
6729 seq_path(m, &mnt_path, " \t\n\\");
6733 /* file system type */
6734 seq_puts(m, "with fstype ");
6736 diff -NurpP --minimal linux-3.9.4/fs/quota/dquot.c linux-3.9.4-vs2.3.6.1/fs/quota/dquot.c
6737 --- linux-3.9.4/fs/quota/dquot.c 2013-05-31 13:45:25.000000000 +0000
6738 +++ linux-3.9.4-vs2.3.6.1/fs/quota/dquot.c 2013-05-31 14:47:11.000000000 +0000
6739 @@ -1585,6 +1585,9 @@ int __dquot_alloc_space(struct inode *in
6740 struct dquot **dquots = inode->i_dquot;
6741 int reserve = flags & DQUOT_SPACE_RESERVE;
6743 + if ((ret = dl_alloc_space(inode, number)))
6747 * First test before acquiring mutex - solves deadlocks when we
6748 * re-enter the quota code and are already holding the mutex
6749 @@ -1640,6 +1643,9 @@ int dquot_alloc_inode(const struct inode
6750 struct dquot_warn warn[MAXQUOTAS];
6751 struct dquot * const *dquots = inode->i_dquot;
6753 + if ((ret = dl_alloc_inode(inode)))
6756 /* First test before acquiring mutex - solves deadlocks when we
6757 * re-enter the quota code and are already holding the mutex */
6758 if (!dquot_active(inode))
6759 @@ -1711,6 +1717,8 @@ void __dquot_free_space(struct inode *in
6760 struct dquot **dquots = inode->i_dquot;
6761 int reserve = flags & DQUOT_SPACE_RESERVE;
6763 + dl_free_space(inode, number);
6765 /* First test before acquiring mutex - solves deadlocks when we
6766 * re-enter the quota code and are already holding the mutex */
6767 if (!dquot_active(inode)) {
6768 @@ -1755,6 +1763,8 @@ void dquot_free_inode(const struct inode
6769 struct dquot_warn warn[MAXQUOTAS];
6770 struct dquot * const *dquots = inode->i_dquot;
6772 + dl_free_inode(inode);
6774 /* First test before acquiring mutex - solves deadlocks when we
6775 * re-enter the quota code and are already holding the mutex */
6776 if (!dquot_active(inode))
6777 diff -NurpP --minimal linux-3.9.4/fs/quota/quota.c linux-3.9.4-vs2.3.6.1/fs/quota/quota.c
6778 --- linux-3.9.4/fs/quota/quota.c 2013-02-19 13:58:49.000000000 +0000
6779 +++ linux-3.9.4-vs2.3.6.1/fs/quota/quota.c 2013-05-31 14:47:11.000000000 +0000
6781 #include <linux/fs.h>
6782 #include <linux/namei.h>
6783 #include <linux/slab.h>
6784 +#include <linux/vs_context.h>
6785 #include <asm/current.h>
6786 #include <linux/uaccess.h>
6787 #include <linux/kernel.h>
6788 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6792 - if (!capable(CAP_SYS_ADMIN))
6793 + if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6797 @@ -309,6 +310,46 @@ static int do_quotactl(struct super_bloc
6801 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6803 +#include <linux/vroot.h>
6804 +#include <linux/major.h>
6805 +#include <linux/module.h>
6806 +#include <linux/kallsyms.h>
6807 +#include <linux/vserver/debug.h>
6809 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6811 +static DEFINE_SPINLOCK(vroot_grb_lock);
6813 +int register_vroot_grb(vroot_grb_func *func) {
6816 + spin_lock(&vroot_grb_lock);
6817 + if (!vroot_get_real_bdev) {
6818 + vroot_get_real_bdev = func;
6821 + spin_unlock(&vroot_grb_lock);
6824 +EXPORT_SYMBOL(register_vroot_grb);
6826 +int unregister_vroot_grb(vroot_grb_func *func) {
6827 + int ret = -EINVAL;
6829 + spin_lock(&vroot_grb_lock);
6830 + if (vroot_get_real_bdev) {
6831 + vroot_get_real_bdev = NULL;
6834 + spin_unlock(&vroot_grb_lock);
6837 +EXPORT_SYMBOL(unregister_vroot_grb);
6841 /* Return 1 if 'cmd' will block on frozen filesystem */
6842 static int quotactl_cmd_write(int cmd)
6844 @@ -343,6 +384,22 @@ static struct super_block *quotactl_bloc
6847 return ERR_CAST(bdev);
6848 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6849 + if (bdev && bdev->bd_inode &&
6850 + imajor(bdev->bd_inode) == VROOT_MAJOR) {
6851 + struct block_device *bdnew = (void *)-EINVAL;
6853 + if (vroot_get_real_bdev)
6854 + bdnew = vroot_get_real_bdev(bdev);
6856 + vxdprintk(VXD_CBIT(misc, 0),
6857 + "vroot_get_real_bdev not set");
6859 + if (IS_ERR(bdnew))
6860 + return ERR_PTR(PTR_ERR(bdnew));
6864 if (quotactl_cmd_write(cmd))
6865 sb = get_super_thawed(bdev);
6867 diff -NurpP --minimal linux-3.9.4/fs/stat.c linux-3.9.4-vs2.3.6.1/fs/stat.c
6868 --- linux-3.9.4/fs/stat.c 2013-05-31 13:45:25.000000000 +0000
6869 +++ linux-3.9.4-vs2.3.6.1/fs/stat.c 2013-05-31 14:47:11.000000000 +0000
6870 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6871 stat->nlink = inode->i_nlink;
6872 stat->uid = inode->i_uid;
6873 stat->gid = inode->i_gid;
6874 + stat->tag = inode->i_tag;
6875 stat->rdev = inode->i_rdev;
6876 stat->size = i_size_read(inode);
6877 stat->atime = inode->i_atime;
6878 diff -NurpP --minimal linux-3.9.4/fs/statfs.c linux-3.9.4-vs2.3.6.1/fs/statfs.c
6879 --- linux-3.9.4/fs/statfs.c 2013-02-19 13:58:49.000000000 +0000
6880 +++ linux-3.9.4-vs2.3.6.1/fs/statfs.c 2013-05-31 14:47:11.000000000 +0000
6882 #include <linux/statfs.h>
6883 #include <linux/security.h>
6884 #include <linux/uaccess.h>
6885 +#include <linux/vs_base.h>
6886 +#include <linux/vs_dlimit.h>
6887 #include "internal.h"
6889 static int flags_by_mnt(int mnt_flags)
6890 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6891 retval = dentry->d_sb->s_op->statfs(dentry, buf);
6892 if (retval == 0 && buf->f_frsize == 0)
6893 buf->f_frsize = buf->f_bsize;
6894 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
6895 + vx_vsi_statfs(dentry->d_sb, buf);
6899 diff -NurpP --minimal linux-3.9.4/fs/super.c linux-3.9.4-vs2.3.6.1/fs/super.c
6900 --- linux-3.9.4/fs/super.c 2013-05-31 13:45:25.000000000 +0000
6901 +++ linux-3.9.4-vs2.3.6.1/fs/super.c 2013-05-31 14:47:11.000000000 +0000
6903 #include <linux/cleancache.h>
6904 #include <linux/fsnotify.h>
6905 #include <linux/lockdep.h>
6906 +#include <linux/magic.h>
6907 +#include <linux/vs_context.h>
6908 #include "internal.h"
6911 @@ -1117,6 +1119,13 @@ mount_fs(struct file_system_type *type,
6912 WARN_ON(sb->s_bdi == &default_backing_dev_info);
6913 sb->s_flags |= MS_BORN;
6916 + if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6918 + (sb->s_magic != PROC_SUPER_MAGIC) &&
6919 + (sb->s_magic != DEVPTS_SUPER_MAGIC))
6922 error = security_sb_kern_mount(sb, flags, secdata);
6925 diff -NurpP --minimal linux-3.9.4/fs/sysfs/mount.c linux-3.9.4-vs2.3.6.1/fs/sysfs/mount.c
6926 --- linux-3.9.4/fs/sysfs/mount.c 2013-05-31 13:45:25.000000000 +0000
6927 +++ linux-3.9.4-vs2.3.6.1/fs/sysfs/mount.c 2013-05-31 14:47:11.000000000 +0000
6928 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6930 sb->s_blocksize = PAGE_CACHE_SIZE;
6931 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6932 - sb->s_magic = SYSFS_MAGIC;
6933 + sb->s_magic = SYSFS_SUPER_MAGIC;
6934 sb->s_op = &sysfs_ops;
6935 sb->s_time_gran = 1;
6937 diff -NurpP --minimal linux-3.9.4/fs/utimes.c linux-3.9.4-vs2.3.6.1/fs/utimes.c
6938 --- linux-3.9.4/fs/utimes.c 2013-02-19 13:58:49.000000000 +0000
6939 +++ linux-3.9.4-vs2.3.6.1/fs/utimes.c 2013-05-31 22:40:16.000000000 +0000
6941 #include <linux/stat.h>
6942 #include <linux/utime.h>
6943 #include <linux/syscalls.h>
6944 +#include <linux/mount.h>
6945 +#include <linux/vs_cowbl.h>
6946 #include <asm/uaccess.h>
6947 #include <asm/unistd.h>
6949 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
6952 struct iattr newattrs;
6953 - struct inode *inode = path->dentry->d_inode;
6954 + struct inode *inode;
6956 + error = cow_check_and_break(path);
6960 error = mnt_want_write(path->mnt);
6964 + inode = path->dentry->d_inode;
6966 if (times && times[0].tv_nsec == UTIME_NOW &&
6967 times[1].tv_nsec == UTIME_NOW)
6969 diff -NurpP --minimal linux-3.9.4/fs/xattr.c linux-3.9.4-vs2.3.6.1/fs/xattr.c
6970 --- linux-3.9.4/fs/xattr.c 2013-02-19 13:58:49.000000000 +0000
6971 +++ linux-3.9.4-vs2.3.6.1/fs/xattr.c 2013-05-31 14:47:11.000000000 +0000
6973 #include <linux/audit.h>
6974 #include <linux/vmalloc.h>
6975 #include <linux/posix_acl_xattr.h>
6976 +#include <linux/mount.h>
6978 #include <asm/uaccess.h>
6980 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6981 * The trusted.* namespace can only be accessed by privileged users.
6983 if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6984 - if (!capable(CAP_SYS_ADMIN))
6985 + if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6986 return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6989 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_dinode.h linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_dinode.h
6990 --- linux-3.9.4/fs/xfs/xfs_dinode.h 2012-12-11 03:30:57.000000000 +0000
6991 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_dinode.h 2013-05-31 14:47:11.000000000 +0000
6992 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
6993 __be32 di_nlink; /* number of links to file */
6994 __be16 di_projid_lo; /* lower part of owner's project id */
6995 __be16 di_projid_hi; /* higher part owner's project id */
6996 - __u8 di_pad[6]; /* unused, zeroed space */
6997 + __u8 di_pad[2]; /* unused, zeroed space */
6998 + __be16 di_tag; /* context tagging */
6999 + __be16 di_vflags; /* vserver specific flags */
7000 __be16 di_flushiter; /* incremented on flush */
7001 xfs_timestamp_t di_atime; /* time last accessed */
7002 xfs_timestamp_t di_mtime; /* time last modified */
7003 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7004 #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7005 #define XFS_DIFLAG_NODEFRAG_BIT 13 /* do not reorganize/defragment */
7006 #define XFS_DIFLAG_FILESTREAM_BIT 14 /* use filestream allocator */
7007 +#define XFS_DIFLAG_IXUNLINK_BIT 15 /* Immutable inver on unlink */
7009 #define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT)
7010 #define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT)
7011 #define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT)
7012 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7013 #define XFS_DIFLAG_EXTSZINHERIT (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7014 #define XFS_DIFLAG_NODEFRAG (1 << XFS_DIFLAG_NODEFRAG_BIT)
7015 #define XFS_DIFLAG_FILESTREAM (1 << XFS_DIFLAG_FILESTREAM_BIT)
7016 +#define XFS_DIFLAG_IXUNLINK (1 << XFS_DIFLAG_IXUNLINK_BIT)
7018 #ifdef CONFIG_XFS_RT
7019 #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7020 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7021 XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7022 XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7023 XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7024 - XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7025 + XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7026 + XFS_DIFLAG_IXUNLINK)
7028 +#define XFS_DIVFLAG_BARRIER 0x01
7029 +#define XFS_DIVFLAG_COW 0x02
7031 #endif /* __XFS_DINODE_H__ */
7032 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_fs.h linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_fs.h
7033 --- linux-3.9.4/fs/xfs/xfs_fs.h 2013-02-19 13:58:49.000000000 +0000
7034 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_fs.h 2013-05-31 14:47:11.000000000 +0000
7035 @@ -67,6 +67,9 @@ struct fsxattr {
7036 #define XFS_XFLAG_EXTSZINHERIT 0x00001000 /* inherit inode extent size */
7037 #define XFS_XFLAG_NODEFRAG 0x00002000 /* do not defragment */
7038 #define XFS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */
7039 +#define XFS_XFLAG_IXUNLINK 0x00008000 /* immutable invert on unlink */
7040 +#define XFS_XFLAG_BARRIER 0x10000000 /* chroot() barrier */
7041 +#define XFS_XFLAG_COW 0x20000000 /* copy on write mark */
7042 #define XFS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
7045 @@ -303,7 +306,8 @@ typedef struct xfs_bstat {
7046 #define bs_projid bs_projid_lo /* (previously just bs_projid) */
7047 __u16 bs_forkoff; /* inode fork offset in bytes */
7048 __u16 bs_projid_hi; /* higher part of project id */
7049 - unsigned char bs_pad[10]; /* pad space, unused */
7050 + unsigned char bs_pad[8]; /* pad space, unused */
7051 + __u16 bs_tag; /* context tagging */
7052 __u32 bs_dmevmask; /* DMIG event mask */
7053 __u16 bs_dmstate; /* DMIG state info */
7054 __u16 bs_aextents; /* attribute number of extents */
7055 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ialloc.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_ialloc.c
7056 --- linux-3.9.4/fs/xfs/xfs_ialloc.c 2013-05-31 13:45:25.000000000 +0000
7057 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_ialloc.c 2013-05-31 14:47:11.000000000 +0000
7059 #include "xfs_error.h"
7060 #include "xfs_bmap.h"
7064 * Allocation group level functions.
7066 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_inode.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_inode.c
7067 --- linux-3.9.4/fs/xfs/xfs_inode.c 2013-05-31 13:45:25.000000000 +0000
7068 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_inode.c 2013-05-31 14:47:11.000000000 +0000
7070 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7072 #include <linux/log2.h>
7073 +#include <linux/vs_tag.h>
7077 @@ -835,15 +836,25 @@ xfs_iformat_btree(
7079 xfs_dinode_from_disk(
7081 - xfs_dinode_t *from)
7082 + xfs_dinode_t *from,
7085 + uint32_t uid, gid, tag;
7087 to->di_magic = be16_to_cpu(from->di_magic);
7088 to->di_mode = be16_to_cpu(from->di_mode);
7089 to->di_version = from ->di_version;
7090 to->di_format = from->di_format;
7091 to->di_onlink = be16_to_cpu(from->di_onlink);
7092 - to->di_uid = be32_to_cpu(from->di_uid);
7093 - to->di_gid = be32_to_cpu(from->di_gid);
7095 + uid = be32_to_cpu(from->di_uid);
7096 + gid = be32_to_cpu(from->di_gid);
7097 + tag = be16_to_cpu(from->di_tag);
7099 + to->di_uid = INOTAG_UID(tagged, uid, gid);
7100 + to->di_gid = INOTAG_GID(tagged, uid, gid);
7101 + to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7103 to->di_nlink = be32_to_cpu(from->di_nlink);
7104 to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7105 to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7106 @@ -865,21 +876,26 @@ xfs_dinode_from_disk(
7107 to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7108 to->di_dmstate = be16_to_cpu(from->di_dmstate);
7109 to->di_flags = be16_to_cpu(from->di_flags);
7110 + to->di_vflags = be16_to_cpu(from->di_vflags);
7111 to->di_gen = be32_to_cpu(from->di_gen);
7117 - xfs_icdinode_t *from)
7118 + xfs_icdinode_t *from,
7121 to->di_magic = cpu_to_be16(from->di_magic);
7122 to->di_mode = cpu_to_be16(from->di_mode);
7123 to->di_version = from ->di_version;
7124 to->di_format = from->di_format;
7125 to->di_onlink = cpu_to_be16(from->di_onlink);
7126 - to->di_uid = cpu_to_be32(from->di_uid);
7127 - to->di_gid = cpu_to_be32(from->di_gid);
7129 + to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7130 + to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7131 + to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7133 to->di_nlink = cpu_to_be32(from->di_nlink);
7134 to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7135 to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7136 @@ -901,12 +917,14 @@ xfs_dinode_to_disk(
7137 to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7138 to->di_dmstate = cpu_to_be16(from->di_dmstate);
7139 to->di_flags = cpu_to_be16(from->di_flags);
7140 + to->di_vflags = cpu_to_be16(from->di_vflags);
7141 to->di_gen = cpu_to_be32(from->di_gen);
7146 - __uint16_t di_flags)
7147 + __uint16_t di_flags,
7148 + __uint16_t di_vflags)
7152 @@ -917,6 +935,8 @@ _xfs_dic2xflags(
7153 flags |= XFS_XFLAG_PREALLOC;
7154 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7155 flags |= XFS_XFLAG_IMMUTABLE;
7156 + if (di_flags & XFS_DIFLAG_IXUNLINK)
7157 + flags |= XFS_XFLAG_IXUNLINK;
7158 if (di_flags & XFS_DIFLAG_APPEND)
7159 flags |= XFS_XFLAG_APPEND;
7160 if (di_flags & XFS_DIFLAG_SYNC)
7161 @@ -941,6 +961,10 @@ _xfs_dic2xflags(
7162 flags |= XFS_XFLAG_FILESTREAM;
7165 + if (di_vflags & XFS_DIVFLAG_BARRIER)
7166 + flags |= FS_BARRIER_FL;
7167 + if (di_vflags & XFS_DIVFLAG_COW)
7168 + flags |= FS_COW_FL;
7172 @@ -950,7 +974,7 @@ xfs_ip2xflags(
7174 xfs_icdinode_t *dic = &ip->i_d;
7176 - return _xfs_dic2xflags(dic->di_flags) |
7177 + return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7178 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7181 @@ -958,7 +982,8 @@ uint
7185 - return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7186 + return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7187 + be16_to_cpu(dip->di_vflags)) |
7188 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7191 @@ -1012,7 +1037,8 @@ xfs_iread(
7192 * Otherwise, just get the truly permanent information.
7195 - xfs_dinode_from_disk(&ip->i_d, dip);
7196 + xfs_dinode_from_disk(&ip->i_d, dip,
7197 + mp->m_flags & XFS_MOUNT_TAGGED);
7198 error = xfs_iformat(ip, dip);
7201 @@ -1199,6 +1225,7 @@ xfs_ialloc(
7202 ASSERT(ip->i_d.di_nlink == nlink);
7203 ip->i_d.di_uid = current_fsuid();
7204 ip->i_d.di_gid = current_fsgid();
7205 + ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7206 xfs_set_projid(ip, prid);
7207 memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7209 @@ -1258,6 +1285,7 @@ xfs_ialloc(
7210 ip->i_d.di_dmevmask = 0;
7211 ip->i_d.di_dmstate = 0;
7212 ip->i_d.di_flags = 0;
7213 + ip->i_d.di_vflags = 0;
7214 flags = XFS_ILOG_CORE;
7215 switch (mode & S_IFMT) {
7217 @@ -1952,6 +1980,7 @@ xfs_ifree(
7219 ip->i_d.di_mode = 0; /* mark incore inode as free */
7220 ip->i_d.di_flags = 0;
7221 + ip->i_d.di_vflags = 0;
7222 ip->i_d.di_dmevmask = 0;
7223 ip->i_d.di_forkoff = 0; /* mark the attr fork not in use */
7224 ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7225 @@ -2118,7 +2147,6 @@ xfs_iroot_realloc(
7231 * This is called when the amount of space needed for if_data
7232 * is increased or decreased. The change in size is indicated by
7233 @@ -2800,7 +2828,8 @@ xfs_iflush_int(
7234 * because if the inode is dirty at all the core must
7237 - xfs_dinode_to_disk(dip, &ip->i_d);
7238 + xfs_dinode_to_disk(dip, &ip->i_d,
7239 + mp->m_flags & XFS_MOUNT_TAGGED);
7241 /* Wrap, we never let the log put out DI_MAX_FLUSH */
7242 if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7243 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_inode.h linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_inode.h
7244 --- linux-3.9.4/fs/xfs/xfs_inode.h 2013-05-31 13:45:25.000000000 +0000
7245 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_inode.h 2013-05-31 14:47:11.000000000 +0000
7246 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7247 __uint32_t di_nlink; /* number of links to file */
7248 __uint16_t di_projid_lo; /* lower part of owner's project id */
7249 __uint16_t di_projid_hi; /* higher part of owner's project id */
7250 - __uint8_t di_pad[6]; /* unused, zeroed space */
7251 + __uint8_t di_pad[2]; /* unused, zeroed space */
7252 + __uint16_t di_tag; /* context tagging */
7253 + __uint16_t di_vflags; /* vserver specific flags */
7254 __uint16_t di_flushiter; /* incremented on flush */
7255 xfs_ictimestamp_t di_atime; /* time last accessed */
7256 xfs_ictimestamp_t di_mtime; /* time last modified */
7257 @@ -556,7 +558,7 @@ int xfs_imap_to_bp(struct xfs_mount *,
7258 int xfs_iread(struct xfs_mount *, struct xfs_trans *,
7259 struct xfs_inode *, uint);
7260 void xfs_dinode_to_disk(struct xfs_dinode *,
7261 - struct xfs_icdinode *);
7262 + struct xfs_icdinode *, int);
7263 void xfs_idestroy_fork(struct xfs_inode *, int);
7264 void xfs_idata_realloc(struct xfs_inode *, int, int);
7265 void xfs_iroot_realloc(struct xfs_inode *, int, int);
7266 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ioctl.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_ioctl.c
7267 --- linux-3.9.4/fs/xfs/xfs_ioctl.c 2013-05-31 13:45:25.000000000 +0000
7268 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_ioctl.c 2013-05-31 14:47:11.000000000 +0000
7270 #include "xfs_bmap_btree.h"
7271 #include "xfs_dinode.h"
7272 #include "xfs_inode.h"
7273 -#include "xfs_ioctl.h"
7274 +// #include "xfs_ioctl.h"
7275 #include "xfs_rtalloc.h"
7276 #include "xfs_itable.h"
7277 #include "xfs_error.h"
7278 @@ -763,6 +763,10 @@ xfs_merge_ioc_xflags(
7279 xflags |= XFS_XFLAG_IMMUTABLE;
7281 xflags &= ~XFS_XFLAG_IMMUTABLE;
7282 + if (flags & FS_IXUNLINK_FL)
7283 + xflags |= XFS_XFLAG_IXUNLINK;
7285 + xflags &= ~XFS_XFLAG_IXUNLINK;
7286 if (flags & FS_APPEND_FL)
7287 xflags |= XFS_XFLAG_APPEND;
7289 @@ -791,6 +795,8 @@ xfs_di2lxflags(
7291 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7292 flags |= FS_IMMUTABLE_FL;
7293 + if (di_flags & XFS_DIFLAG_IXUNLINK)
7294 + flags |= FS_IXUNLINK_FL;
7295 if (di_flags & XFS_DIFLAG_APPEND)
7296 flags |= FS_APPEND_FL;
7297 if (di_flags & XFS_DIFLAG_SYNC)
7298 @@ -851,6 +857,8 @@ xfs_set_diflags(
7299 di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7300 if (xflags & XFS_XFLAG_IMMUTABLE)
7301 di_flags |= XFS_DIFLAG_IMMUTABLE;
7302 + if (xflags & XFS_XFLAG_IXUNLINK)
7303 + di_flags |= XFS_DIFLAG_IXUNLINK;
7304 if (xflags & XFS_XFLAG_APPEND)
7305 di_flags |= XFS_DIFLAG_APPEND;
7306 if (xflags & XFS_XFLAG_SYNC)
7307 @@ -893,6 +901,10 @@ xfs_diflags_to_linux(
7308 inode->i_flags |= S_IMMUTABLE;
7310 inode->i_flags &= ~S_IMMUTABLE;
7311 + if (xflags & XFS_XFLAG_IXUNLINK)
7312 + inode->i_flags |= S_IXUNLINK;
7314 + inode->i_flags &= ~S_IXUNLINK;
7315 if (xflags & XFS_XFLAG_APPEND)
7316 inode->i_flags |= S_APPEND;
7318 @@ -1397,10 +1409,18 @@ xfs_file_ioctl(
7319 case XFS_IOC_FSGETXATTRA:
7320 return xfs_ioc_fsgetxattr(ip, 1, arg);
7321 case XFS_IOC_FSSETXATTR:
7322 + if (IS_BARRIER(inode)) {
7323 + vxwprintk_task(1, "messing with the barrier.");
7324 + return -XFS_ERROR(EACCES);
7326 return xfs_ioc_fssetxattr(ip, filp, arg);
7327 case XFS_IOC_GETXFLAGS:
7328 return xfs_ioc_getxflags(ip, arg);
7329 case XFS_IOC_SETXFLAGS:
7330 + if (IS_BARRIER(inode)) {
7331 + vxwprintk_task(1, "messing with the barrier.");
7332 + return -XFS_ERROR(EACCES);
7334 return xfs_ioc_setxflags(ip, filp, arg);
7336 case XFS_IOC_FSSETDM: {
7337 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ioctl.h linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_ioctl.h
7338 --- linux-3.9.4/fs/xfs/xfs_ioctl.h 2012-12-11 03:30:57.000000000 +0000
7339 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_ioctl.h 2013-05-31 14:47:11.000000000 +0000
7340 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7341 void __user *uhandle,
7346 + struct inode *inode,
7353 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_iops.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_iops.c
7354 --- linux-3.9.4/fs/xfs/xfs_iops.c 2013-02-19 13:58:49.000000000 +0000
7355 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_iops.c 2013-05-31 14:47:11.000000000 +0000
7357 #include "xfs_bmap_btree.h"
7358 #include "xfs_dinode.h"
7359 #include "xfs_inode.h"
7360 +#include "xfs_ioctl.h"
7361 #include "xfs_bmap.h"
7362 #include "xfs_rtalloc.h"
7363 #include "xfs_error.h"
7365 #include <linux/security.h>
7366 #include <linux/fiemap.h>
7367 #include <linux/slab.h>
7368 +#include <linux/vs_tag.h>
7372 @@ -422,6 +424,7 @@ xfs_vn_getattr(
7373 stat->nlink = ip->i_d.di_nlink;
7374 stat->uid = ip->i_d.di_uid;
7375 stat->gid = ip->i_d.di_gid;
7376 + stat->tag = ip->i_d.di_tag;
7377 stat->ino = ip->i_ino;
7378 stat->atime = inode->i_atime;
7379 stat->mtime = inode->i_mtime;
7380 @@ -1037,6 +1040,7 @@ static const struct inode_operations xfs
7381 .listxattr = xfs_vn_listxattr,
7382 .fiemap = xfs_vn_fiemap,
7383 .update_time = xfs_vn_update_time,
7384 + .sync_flags = xfs_sync_flags,
7387 static const struct inode_operations xfs_dir_inode_operations = {
7388 @@ -1063,6 +1067,7 @@ static const struct inode_operations xfs
7389 .removexattr = generic_removexattr,
7390 .listxattr = xfs_vn_listxattr,
7391 .update_time = xfs_vn_update_time,
7392 + .sync_flags = xfs_sync_flags,
7395 static const struct inode_operations xfs_dir_ci_inode_operations = {
7396 @@ -1114,6 +1119,10 @@ xfs_diflags_to_iflags(
7397 inode->i_flags |= S_IMMUTABLE;
7399 inode->i_flags &= ~S_IMMUTABLE;
7400 + if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7401 + inode->i_flags |= S_IXUNLINK;
7403 + inode->i_flags &= ~S_IXUNLINK;
7404 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7405 inode->i_flags |= S_APPEND;
7407 @@ -1126,6 +1135,15 @@ xfs_diflags_to_iflags(
7408 inode->i_flags |= S_NOATIME;
7410 inode->i_flags &= ~S_NOATIME;
7412 + if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7413 + inode->i_vflags |= V_BARRIER;
7415 + inode->i_vflags &= ~V_BARRIER;
7416 + if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7417 + inode->i_vflags |= V_COW;
7419 + inode->i_vflags &= ~V_COW;
7423 @@ -1157,6 +1175,7 @@ xfs_setup_inode(
7424 set_nlink(inode, ip->i_d.di_nlink);
7425 inode->i_uid = ip->i_d.di_uid;
7426 inode->i_gid = ip->i_d.di_gid;
7427 + inode->i_tag = ip->i_d.di_tag;
7429 switch (inode->i_mode & S_IFMT) {
7431 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_itable.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_itable.c
7432 --- linux-3.9.4/fs/xfs/xfs_itable.c 2013-02-19 13:58:49.000000000 +0000
7433 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_itable.c 2013-05-31 14:47:11.000000000 +0000
7434 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
7435 buf->bs_mode = dic->di_mode;
7436 buf->bs_uid = dic->di_uid;
7437 buf->bs_gid = dic->di_gid;
7438 + buf->bs_tag = dic->di_tag;
7439 buf->bs_size = dic->di_size;
7440 buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7441 buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7442 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_linux.h linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_linux.h
7443 --- linux-3.9.4/fs/xfs/xfs_linux.h 2013-02-19 13:58:49.000000000 +0000
7444 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_linux.h 2013-05-31 14:47:11.000000000 +0000
7447 #define current_cpu() (raw_smp_processor_id())
7448 #define current_pid() (current->pid)
7449 +#define current_fstag(vp) (dx_current_fstag((vp)->i_sb))
7450 #define current_test_flags(f) (current->flags & (f))
7451 #define current_set_flags_nested(sp, f) \
7452 (*(sp) = current->flags, current->flags |= (f))
7453 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_log_recover.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_log_recover.c
7454 --- linux-3.9.4/fs/xfs/xfs_log_recover.c 2013-05-31 13:45:25.000000000 +0000
7455 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_log_recover.c 2013-05-31 14:47:11.000000000 +0000
7456 @@ -2361,7 +2361,8 @@ xlog_recover_inode_pass2(
7459 /* The core is in in-core format */
7460 - xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7461 + xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7462 + mp->m_flags & XFS_MOUNT_TAGGED);
7464 /* the rest is in on-disk format */
7465 if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7466 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_mount.h linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_mount.h
7467 --- linux-3.9.4/fs/xfs/xfs_mount.h 2013-05-31 13:45:25.000000000 +0000
7468 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_mount.h 2013-05-31 14:47:11.000000000 +0000
7469 @@ -254,6 +254,7 @@ typedef struct xfs_mount {
7471 #define XFS_MOUNT_NOATTR2 (1ULL << 25) /* disable use of attr2 format */
7473 +#define XFS_MOUNT_TAGGED (1ULL << 31) /* context tagging */
7476 * Default minimum read and write sizes.
7477 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_super.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_super.c
7478 --- linux-3.9.4/fs/xfs/xfs_super.c 2013-05-31 13:45:25.000000000 +0000
7479 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_super.c 2013-05-31 14:47:11.000000000 +0000
7480 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7481 #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed logging disabled */
7482 #define MNTOPT_DISCARD "discard" /* Discard unused blocks */
7483 #define MNTOPT_NODISCARD "nodiscard" /* Do not discard unused blocks */
7484 +#define MNTOPT_TAGXID "tagxid" /* context tagging for inodes */
7485 +#define MNTOPT_TAGGED "tag" /* context tagging for inodes */
7486 +#define MNTOPT_NOTAGTAG "notag" /* do not use context tagging */
7489 * Table driven mount option parser.
7490 @@ -126,6 +129,8 @@ enum {
7499 @@ -134,6 +139,9 @@ static const match_table_t tokens = {
7500 {Opt_nobarrier, "nobarrier"},
7501 {Opt_inode64, "inode64"},
7502 {Opt_inode32, "inode32"},
7503 + {Opt_tag, "tagxid"},
7505 + {Opt_notag, "notag"},
7509 @@ -392,6 +400,19 @@ xfs_parseargs(
7510 } else if (!strcmp(this_char, "irixsgid")) {
7512 "irixsgid is now a sysctl(2) variable, option is deprecated.");
7513 +#ifndef CONFIG_TAGGING_NONE
7514 + } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7515 + mp->m_flags |= XFS_MOUNT_TAGGED;
7516 + } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7517 + mp->m_flags &= ~XFS_MOUNT_TAGGED;
7518 + } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7519 + mp->m_flags |= XFS_MOUNT_TAGGED;
7521 +#ifdef CONFIG_PROPAGATE
7522 + } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7524 + mp->m_flags |= XFS_MOUNT_TAGGED;
7527 xfs_warn(mp, "unknown mount option [%s].", this_char);
7529 @@ -1238,6 +1259,16 @@ xfs_fs_remount(
7531 mp->m_maxagi = xfs_set_inode32(mp);
7534 + if (!(sb->s_flags & MS_TAGGED)) {
7536 + "XFS: %s: tagging not permitted on remount.\n",
7545 * Logically we would return an error here to prevent
7546 @@ -1458,6 +1489,9 @@ xfs_fs_fill_super(
7550 + if (mp->m_flags & XFS_MOUNT_TAGGED)
7551 + sb->s_flags |= MS_TAGGED;
7554 * we must configure the block size in the superblock before we run the
7555 * full mount process as the mount process can lookup and cache inodes.
7556 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_vnodeops.c linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_vnodeops.c
7557 --- linux-3.9.4/fs/xfs/xfs_vnodeops.c 2013-05-31 13:45:25.000000000 +0000
7558 +++ linux-3.9.4-vs2.3.6.1/fs/xfs/xfs_vnodeops.c 2013-05-31 14:47:11.000000000 +0000
7559 @@ -104,6 +104,77 @@ xfs_readlink_bmap(
7565 +xfs_get_inode_flags(
7568 + struct inode *inode = VFS_I(ip);
7569 + unsigned int flags = inode->i_flags;
7570 + unsigned int vflags = inode->i_vflags;
7572 + if (flags & S_IMMUTABLE)
7573 + ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7575 + ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7576 + if (flags & S_IXUNLINK)
7577 + ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7579 + ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7581 + if (vflags & V_BARRIER)
7582 + ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7584 + ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7585 + if (vflags & V_COW)
7586 + ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7588 + ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7593 + struct inode *inode,
7597 + struct xfs_inode *ip = XFS_I(inode);
7598 + struct xfs_mount *mp = ip->i_mount;
7599 + struct xfs_trans *tp;
7600 + unsigned int lock_flags = 0;
7603 + tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7604 + code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7608 + xfs_ilock(ip, XFS_ILOCK_EXCL);
7609 + xfs_trans_ijoin(tp, ip, 0);
7611 + inode->i_flags = flags;
7612 + inode->i_vflags = vflags;
7613 + xfs_get_inode_flags(ip);
7615 + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7616 + xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7618 + XFS_STATS_INC(xs_ig_attrchg);
7620 + if (mp->m_flags & XFS_MOUNT_WSYNC)
7621 + xfs_trans_set_sync(tp);
7622 + code = xfs_trans_commit(tp, 0);
7623 + xfs_iunlock(ip, XFS_ILOCK_EXCL);
7627 + xfs_trans_cancel(tp, 0);
7629 + xfs_iunlock(ip, XFS_ILOCK_EXCL);
7637 diff -NurpP --minimal linux-3.9.4/include/linux/cred.h linux-3.9.4-vs2.3.6.1/include/linux/cred.h
7638 --- linux-3.9.4/include/linux/cred.h 2013-02-19 13:58:50.000000000 +0000
7639 +++ linux-3.9.4-vs2.3.6.1/include/linux/cred.h 2013-05-31 14:47:11.000000000 +0000
7640 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
7641 extern int copy_creds(struct task_struct *, unsigned long);
7642 extern const struct cred *get_task_cred(struct task_struct *);
7643 extern struct cred *cred_alloc_blank(void);
7644 +extern struct cred *__prepare_creds(const struct cred *);
7645 extern struct cred *prepare_creds(void);
7646 extern struct cred *prepare_exec_creds(void);
7647 extern int commit_creds(struct cred *);
7648 @@ -196,6 +197,31 @@ static inline void validate_process_cred
7652 +static inline void set_cred_subscribers(struct cred *cred, int n)
7654 +#ifdef CONFIG_DEBUG_CREDENTIALS
7655 + atomic_set(&cred->subscribers, n);
7659 +static inline int read_cred_subscribers(const struct cred *cred)
7661 +#ifdef CONFIG_DEBUG_CREDENTIALS
7662 + return atomic_read(&cred->subscribers);
7668 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7670 +#ifdef CONFIG_DEBUG_CREDENTIALS
7671 + struct cred *cred = (struct cred *) _cred;
7673 + atomic_add(n, &cred->subscribers);
7678 * get_new_cred - Get a reference on a new set of credentials
7679 * @cred: The new credentials to reference
7680 diff -NurpP --minimal linux-3.9.4/include/linux/devpts_fs.h linux-3.9.4-vs2.3.6.1/include/linux/devpts_fs.h
7681 --- linux-3.9.4/include/linux/devpts_fs.h 2013-02-19 13:58:50.000000000 +0000
7682 +++ linux-3.9.4-vs2.3.6.1/include/linux/devpts_fs.h 2013-05-31 14:47:11.000000000 +0000
7683 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7688 #endif /* _LINUX_DEVPTS_FS_H */
7689 diff -NurpP --minimal linux-3.9.4/include/linux/fs.h linux-3.9.4-vs2.3.6.1/include/linux/fs.h
7690 --- linux-3.9.4/include/linux/fs.h 2013-05-31 13:45:27.000000000 +0000
7691 +++ linux-3.9.4-vs2.3.6.1/include/linux/fs.h 2013-05-31 14:47:11.000000000 +0000
7692 @@ -211,6 +211,7 @@ typedef void (dio_iodone_t)(struct kiocb
7693 #define ATTR_KILL_PRIV (1 << 14)
7694 #define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */
7695 #define ATTR_TIMES_SET (1 << 16)
7696 +#define ATTR_TAG (1 << 17)
7699 * This is the Inode Attributes structure, used for notify_change(). It
7700 @@ -226,6 +227,7 @@ struct iattr {
7706 struct timespec ia_atime;
7707 struct timespec ia_mtime;
7708 @@ -523,7 +525,9 @@ struct inode {
7709 unsigned short i_opflags;
7712 - unsigned int i_flags;
7714 + unsigned short i_flags;
7715 + unsigned short i_vflags;
7717 #ifdef CONFIG_FS_POSIX_ACL
7718 struct posix_acl *i_acl;
7719 @@ -552,6 +556,7 @@ struct inode {
7720 unsigned int __i_nlink;
7725 struct timespec i_atime;
7726 struct timespec i_mtime;
7727 @@ -702,6 +707,11 @@ static inline gid_t i_gid_read(const str
7728 return from_kgid(&init_user_ns, inode->i_gid);
7731 +static inline tag_t i_tag_read(const struct inode *inode)
7733 + return from_ktag(&init_user_ns, inode->i_tag);
7736 static inline void i_uid_write(struct inode *inode, uid_t uid)
7738 inode->i_uid = make_kuid(&init_user_ns, uid);
7739 @@ -712,14 +722,19 @@ static inline void i_gid_write(struct in
7740 inode->i_gid = make_kgid(&init_user_ns, gid);
7743 +static inline void i_tag_write(struct inode *inode, tag_t tag)
7745 + inode->i_tag = make_ktag(&init_user_ns, tag);
7748 static inline unsigned iminor(const struct inode *inode)
7750 - return MINOR(inode->i_rdev);
7751 + return MINOR(inode->i_mdev);
7754 static inline unsigned imajor(const struct inode *inode)
7756 - return MAJOR(inode->i_rdev);
7757 + return MAJOR(inode->i_mdev);
7760 extern struct block_device *I_BDEV(struct inode *inode);
7761 @@ -786,6 +801,7 @@ struct file {
7763 struct fown_struct f_owner;
7764 const struct cred *f_cred;
7766 struct file_ra_state f_ra;
7769 @@ -937,6 +953,7 @@ struct file_lock {
7770 struct file *fl_file;
7775 struct fasync_struct * fl_fasync; /* for lease break notifications */
7776 /* for lease breaks: */
7777 @@ -1567,6 +1584,7 @@ struct inode_operations {
7778 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7779 ssize_t (*listxattr) (struct dentry *, char *, size_t);
7780 int (*removexattr) (struct dentry *, const char *);
7781 + int (*sync_flags) (struct inode *, int, int);
7782 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7784 int (*update_time)(struct inode *, struct timespec *, int);
7785 @@ -1579,6 +1597,7 @@ ssize_t rw_copy_check_uvector(int type,
7786 unsigned long nr_segs, unsigned long fast_segs,
7787 struct iovec *fast_pointer,
7788 struct iovec **ret_pointer);
7789 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7791 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7792 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7793 @@ -1632,6 +1651,14 @@ struct super_operations {
7794 #define S_IMA 1024 /* Inode has an associated IMA struct */
7795 #define S_AUTOMOUNT 2048 /* Automount/referral quasi-directory */
7796 #define S_NOSEC 4096 /* no suid or xattr security attributes */
7797 +#define S_IXUNLINK 8192 /* Immutable Invert on unlink */
7799 +/* Linux-VServer related Inode flags */
7803 +#define V_BARRIER 4 /* Barrier for chroot() */
7804 +#define V_COW 8 /* Copy on Write */
7807 * Note that nosuid etc flags are inode-specific: setting some file-system
7808 @@ -1656,10 +1683,13 @@ struct super_operations {
7809 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
7810 #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7811 #define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION)
7812 +#define IS_TAGGED(inode) __IS_FLG(inode, MS_TAGGED)
7814 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
7815 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
7816 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
7817 +#define IS_IXUNLINK(inode) ((inode)->i_flags & S_IXUNLINK)
7818 +#define IS_IXORUNLINK(inode) ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7819 #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL)
7821 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
7822 @@ -1670,6 +1700,16 @@ struct super_operations {
7823 #define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT)
7824 #define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC)
7826 +#define IS_BARRIER(inode) (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7828 +#ifdef CONFIG_VSERVER_COWBL
7829 +# define IS_COW(inode) (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7830 +# define IS_COW_LINK(inode) (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7832 +# define IS_COW(inode) (0)
7833 +# define IS_COW_LINK(inode) (0)
7837 * Inode state bits. Protected by inode->i_lock
7839 @@ -1898,6 +1938,9 @@ extern int rw_verify_area(int, struct fi
7840 extern int locks_mandatory_locked(struct inode *);
7841 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7843 +#define ATTR_FLAG_BARRIER 512 /* Barrier for chroot() */
7844 +#define ATTR_FLAG_IXUNLINK 1024 /* Immutable invert on unlink */
7847 * Candidates for mandatory locking have the setgid bit set
7848 * but no group execute bit - an otherwise meaningless combination.
7849 @@ -2509,6 +2552,7 @@ extern int dcache_dir_open(struct inode
7850 extern int dcache_dir_close(struct inode *, struct file *);
7851 extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7852 extern int dcache_readdir(struct file *, void *, filldir_t);
7853 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
7854 extern int simple_setattr(struct dentry *, struct iattr *);
7855 extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7856 extern int simple_statfs(struct dentry *, struct kstatfs *);
7857 diff -NurpP --minimal linux-3.9.4/include/linux/init_task.h linux-3.9.4-vs2.3.6.1/include/linux/init_task.h
7858 --- linux-3.9.4/include/linux/init_task.h 2013-05-31 13:45:27.000000000 +0000
7859 +++ linux-3.9.4-vs2.3.6.1/include/linux/init_task.h 2013-05-31 14:53:41.000000000 +0000
7860 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7861 INIT_TASK_RCU_PREEMPT(tsk) \
7865 + .vx_info = NULL, \
7867 + .nx_info = NULL, \
7871 diff -NurpP --minimal linux-3.9.4/include/linux/ipc.h linux-3.9.4-vs2.3.6.1/include/linux/ipc.h
7872 --- linux-3.9.4/include/linux/ipc.h 2012-12-11 03:30:57.000000000 +0000
7873 +++ linux-3.9.4-vs2.3.6.1/include/linux/ipc.h 2013-05-31 14:47:11.000000000 +0000
7874 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7882 diff -NurpP --minimal linux-3.9.4/include/linux/loop.h linux-3.9.4-vs2.3.6.1/include/linux/loop.h
7883 --- linux-3.9.4/include/linux/loop.h 2013-02-19 13:58:51.000000000 +0000
7884 +++ linux-3.9.4-vs2.3.6.1/include/linux/loop.h 2013-05-31 14:47:11.000000000 +0000
7885 @@ -41,6 +41,7 @@ struct loop_device {
7886 struct loop_func_table *lo_encryption;
7888 kuid_t lo_key_owner; /* Who set the key */
7890 int (*ioctl)(struct loop_device *, int cmd,
7893 diff -NurpP --minimal linux-3.9.4/include/linux/memcontrol.h linux-3.9.4-vs2.3.6.1/include/linux/memcontrol.h
7894 --- linux-3.9.4/include/linux/memcontrol.h 2013-05-31 13:45:28.000000000 +0000
7895 +++ linux-3.9.4-vs2.3.6.1/include/linux/memcontrol.h 2013-05-31 14:47:11.000000000 +0000
7896 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
7897 extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7898 extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
7900 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7901 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7903 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7904 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7905 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7908 bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7910 diff -NurpP --minimal linux-3.9.4/include/linux/mm_types.h linux-3.9.4-vs2.3.6.1/include/linux/mm_types.h
7911 --- linux-3.9.4/include/linux/mm_types.h 2013-05-31 13:45:28.000000000 +0000
7912 +++ linux-3.9.4-vs2.3.6.1/include/linux/mm_types.h 2013-05-31 14:47:11.000000000 +0000
7913 @@ -380,6 +380,7 @@ struct mm_struct {
7915 /* Architecture-specific MM context */
7916 mm_context_t context;
7917 + struct vx_info *mm_vx_info;
7919 unsigned long flags; /* Must use atomic bitops to access the bits */
7921 diff -NurpP --minimal linux-3.9.4/include/linux/mount.h linux-3.9.4-vs2.3.6.1/include/linux/mount.h
7922 --- linux-3.9.4/include/linux/mount.h 2013-05-31 13:45:28.000000000 +0000
7923 +++ linux-3.9.4-vs2.3.6.1/include/linux/mount.h 2013-05-31 14:47:11.000000000 +0000
7924 @@ -49,6 +49,9 @@ struct mnt_namespace;
7926 #define MNT_LOCK_READONLY 0x400000
7928 +#define MNT_TAGID 0x10000
7929 +#define MNT_NOTAG 0x20000
7932 struct dentry *mnt_root; /* root of the mounted tree */
7933 struct super_block *mnt_sb; /* pointer to superblock */
7934 diff -NurpP --minimal linux-3.9.4/include/linux/net.h linux-3.9.4-vs2.3.6.1/include/linux/net.h
7935 --- linux-3.9.4/include/linux/net.h 2012-12-11 03:30:57.000000000 +0000
7936 +++ linux-3.9.4-vs2.3.6.1/include/linux/net.h 2013-05-31 14:47:11.000000000 +0000
7937 @@ -38,6 +38,7 @@ struct net;
7938 #define SOCK_PASSCRED 3
7939 #define SOCK_PASSSEC 4
7940 #define SOCK_EXTERNALLY_ALLOCATED 5
7941 +#define SOCK_USER_SOCKET 6
7943 #ifndef ARCH_HAS_SOCKET_TYPES
7945 diff -NurpP --minimal linux-3.9.4/include/linux/netdevice.h linux-3.9.4-vs2.3.6.1/include/linux/netdevice.h
7946 --- linux-3.9.4/include/linux/netdevice.h 2013-05-31 13:45:28.000000000 +0000
7947 +++ linux-3.9.4-vs2.3.6.1/include/linux/netdevice.h 2013-05-31 14:47:11.000000000 +0000
7948 @@ -1688,6 +1688,7 @@ extern void netdev_resync_ops(struct ne
7950 extern struct net_device *dev_get_by_index(struct net *net, int ifindex);
7951 extern struct net_device *__dev_get_by_index(struct net *net, int ifindex);
7952 +extern struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7953 extern struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
7954 extern int dev_restart(struct net_device *dev);
7955 #ifdef CONFIG_NETPOLL_TRAP
7956 diff -NurpP --minimal linux-3.9.4/include/linux/nsproxy.h linux-3.9.4-vs2.3.6.1/include/linux/nsproxy.h
7957 --- linux-3.9.4/include/linux/nsproxy.h 2013-02-19 13:58:51.000000000 +0000
7958 +++ linux-3.9.4-vs2.3.6.1/include/linux/nsproxy.h 2013-05-31 17:17:53.000000000 +0000
7961 #include <linux/spinlock.h>
7962 #include <linux/sched.h>
7963 +#include <linux/vserver/debug.h>
7965 struct mnt_namespace;
7966 struct uts_namespace;
7967 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
7970 int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7971 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7972 void exit_task_namespaces(struct task_struct *tsk);
7973 void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7974 void free_nsproxy(struct nsproxy *ns);
7975 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
7976 struct cred *, struct fs_struct *);
7977 int __init nsproxy_cache_init(void);
7979 -static inline void put_nsproxy(struct nsproxy *ns)
7980 +#define get_nsproxy(n) __get_nsproxy(n, __FILE__, __LINE__)
7982 +static inline void __get_nsproxy(struct nsproxy *ns,
7983 + const char *_file, int _line)
7985 - if (atomic_dec_and_test(&ns->count)) {
7988 + vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7989 + ns, atomic_read(&ns->count), _file, _line);
7990 + atomic_inc(&ns->count);
7993 -static inline void get_nsproxy(struct nsproxy *ns)
7994 +#define put_nsproxy(n) __put_nsproxy(n, __FILE__, __LINE__)
7996 +static inline void __put_nsproxy(struct nsproxy *ns,
7997 + const char *_file, int _line)
7999 - atomic_inc(&ns->count);
8000 + vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8001 + ns, atomic_read(&ns->count), _file, _line);
8002 + if (atomic_dec_and_test(&ns->count)) {
8008 diff -NurpP --minimal linux-3.9.4/include/linux/pid.h linux-3.9.4-vs2.3.6.1/include/linux/pid.h
8009 --- linux-3.9.4/include/linux/pid.h 2013-05-31 13:45:28.000000000 +0000
8010 +++ linux-3.9.4-vs2.3.6.1/include/linux/pid.h 2013-05-31 14:47:11.000000000 +0000
8011 @@ -8,7 +8,8 @@ enum pid_type
8021 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
8024 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8025 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8026 pid_t pid_vnr(struct pid *pid);
8028 #define do_each_pid_task(pid, type, task) \
8029 diff -NurpP --minimal linux-3.9.4/include/linux/proc_fs.h linux-3.9.4-vs2.3.6.1/include/linux/proc_fs.h
8030 --- linux-3.9.4/include/linux/proc_fs.h 2013-05-31 13:45:28.000000000 +0000
8031 +++ linux-3.9.4-vs2.3.6.1/include/linux/proc_fs.h 2013-05-31 14:47:11.000000000 +0000
8032 @@ -58,6 +58,7 @@ struct proc_dir_entry {
8038 const struct inode_operations *proc_iops;
8040 @@ -274,12 +275,18 @@ extern const struct proc_ns_operations p
8041 extern const struct proc_ns_operations userns_operations;
8042 extern const struct proc_ns_operations mntns_operations;
8048 int (*proc_get_link)(struct dentry *, struct path *);
8049 int (*proc_read)(struct task_struct *task, char *page);
8050 int (*proc_show)(struct seq_file *m,
8051 struct pid_namespace *ns, struct pid *pid,
8052 struct task_struct *task);
8053 + int (*proc_vs_read)(char *page);
8054 + int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8055 + int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8058 struct ctl_table_header;
8059 @@ -287,6 +294,7 @@ struct ctl_table;
8066 struct proc_dir_entry *pde;
8067 diff -NurpP --minimal linux-3.9.4/include/linux/quotaops.h linux-3.9.4-vs2.3.6.1/include/linux/quotaops.h
8068 --- linux-3.9.4/include/linux/quotaops.h 2012-12-11 03:30:57.000000000 +0000
8069 +++ linux-3.9.4-vs2.3.6.1/include/linux/quotaops.h 2013-05-31 14:47:11.000000000 +0000
8071 #define _LINUX_QUOTAOPS_
8073 #include <linux/fs.h>
8074 +#include <linux/vs_dlimit.h>
8076 #define DQUOT_SPACE_WARN 0x1
8077 #define DQUOT_SPACE_RESERVE 0x2
8078 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
8080 static inline int dquot_alloc_inode(const struct inode *inode)
8083 + return dl_alloc_inode(inode);
8086 static inline void dquot_free_inode(const struct inode *inode)
8088 + dl_free_inode(inode);
8091 static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8092 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
8093 static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8098 + if ((ret = dl_alloc_space(inode, number)))
8100 if (!(flags & DQUOT_SPACE_RESERVE))
8101 inode_add_bytes(inode, number);
8103 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
8105 if (!(flags & DQUOT_SPACE_RESERVE))
8106 inode_sub_bytes(inode, number);
8107 + dl_free_space(inode, number);
8110 static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8111 diff -NurpP --minimal linux-3.9.4/include/linux/sched.h linux-3.9.4-vs2.3.6.1/include/linux/sched.h
8112 --- linux-3.9.4/include/linux/sched.h 2013-05-31 14:22:27.000000000 +0000
8113 +++ linux-3.9.4-vs2.3.6.1/include/linux/sched.h 2013-05-31 14:47:11.000000000 +0000
8114 @@ -1398,6 +1398,14 @@ struct task_struct {
8116 struct seccomp seccomp;
8118 +/* vserver context data */
8119 + struct vx_info *vx_info;
8120 + struct nx_info *nx_info;
8126 /* Thread group tracking */
8129 @@ -1637,6 +1645,11 @@ struct pid_namespace;
8130 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8131 struct pid_namespace *ns);
8133 +#include <linux/vserver/base.h>
8134 +#include <linux/vserver/context.h>
8135 +#include <linux/vserver/debug.h>
8136 +#include <linux/vserver/pid.h>
8138 static inline pid_t task_pid_nr(struct task_struct *tsk)
8141 @@ -1650,7 +1663,8 @@ static inline pid_t task_pid_nr_ns(struc
8143 static inline pid_t task_pid_vnr(struct task_struct *tsk)
8145 - return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8146 + // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8147 + return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8151 @@ -1663,7 +1677,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8153 static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8155 - return pid_vnr(task_tgid(tsk));
8156 + return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8160 diff -NurpP --minimal linux-3.9.4/include/linux/shmem_fs.h linux-3.9.4-vs2.3.6.1/include/linux/shmem_fs.h
8161 --- linux-3.9.4/include/linux/shmem_fs.h 2012-12-11 03:30:57.000000000 +0000
8162 +++ linux-3.9.4-vs2.3.6.1/include/linux/shmem_fs.h 2013-05-31 14:47:11.000000000 +0000
8165 /* inode in-kernel data */
8167 +#define TMPFS_SUPER_MAGIC 0x01021994
8170 struct shmem_inode_info {
8172 unsigned long flags;
8173 diff -NurpP --minimal linux-3.9.4/include/linux/stat.h linux-3.9.4-vs2.3.6.1/include/linux/stat.h
8174 --- linux-3.9.4/include/linux/stat.h 2012-12-11 03:30:57.000000000 +0000
8175 +++ linux-3.9.4-vs2.3.6.1/include/linux/stat.h 2013-05-31 14:47:11.000000000 +0000
8176 @@ -25,6 +25,7 @@ struct kstat {
8183 struct timespec atime;
8184 diff -NurpP --minimal linux-3.9.4/include/linux/sunrpc/auth.h linux-3.9.4-vs2.3.6.1/include/linux/sunrpc/auth.h
8185 --- linux-3.9.4/include/linux/sunrpc/auth.h 2013-05-31 13:45:28.000000000 +0000
8186 +++ linux-3.9.4-vs2.3.6.1/include/linux/sunrpc/auth.h 2013-05-31 14:52:57.000000000 +0000
8192 struct group_info *group_info;
8193 const char *principal;
8194 unsigned char machine_cred : 1;
8195 diff -NurpP --minimal linux-3.9.4/include/linux/sunrpc/clnt.h linux-3.9.4-vs2.3.6.1/include/linux/sunrpc/clnt.h
8196 --- linux-3.9.4/include/linux/sunrpc/clnt.h 2013-05-31 13:45:28.000000000 +0000
8197 +++ linux-3.9.4-vs2.3.6.1/include/linux/sunrpc/clnt.h 2013-05-31 14:47:11.000000000 +0000
8198 @@ -49,7 +49,8 @@ struct rpc_clnt {
8199 unsigned int cl_softrtry : 1,/* soft timeouts */
8200 cl_discrtry : 1,/* disconnect before retry */
8201 cl_autobind : 1,/* use getport() */
8202 - cl_chatty : 1;/* be verbose */
8203 + cl_chatty : 1,/* be verbose */
8204 + cl_tag : 1;/* context tagging */
8206 struct rpc_rtt * cl_rtt; /* RTO estimator data */
8207 const struct rpc_timeout *cl_timeout; /* Timeout strategy */
8208 diff -NurpP --minimal linux-3.9.4/include/linux/sysfs.h linux-3.9.4-vs2.3.6.1/include/linux/sysfs.h
8209 --- linux-3.9.4/include/linux/sysfs.h 2013-05-31 13:45:28.000000000 +0000
8210 +++ linux-3.9.4-vs2.3.6.1/include/linux/sysfs.h 2013-05-31 14:47:11.000000000 +0000
8212 #include <linux/kobject_ns.h>
8213 #include <linux/atomic.h>
8215 +#define SYSFS_SUPER_MAGIC 0x62656572
8220 diff -NurpP --minimal linux-3.9.4/include/linux/types.h linux-3.9.4-vs2.3.6.1/include/linux/types.h
8221 --- linux-3.9.4/include/linux/types.h 2013-02-19 13:58:52.000000000 +0000
8222 +++ linux-3.9.4-vs2.3.6.1/include/linux/types.h 2013-05-31 14:47:11.000000000 +0000
8223 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t uid_t;
8224 typedef __kernel_gid32_t gid_t;
8225 typedef __kernel_uid16_t uid16_t;
8226 typedef __kernel_gid16_t gid16_t;
8227 +typedef unsigned int xid_t;
8228 +typedef unsigned int nid_t;
8229 +typedef unsigned int tag_t;
8231 typedef unsigned long uintptr_t;
8233 diff -NurpP --minimal linux-3.9.4/include/linux/uidgid.h linux-3.9.4-vs2.3.6.1/include/linux/uidgid.h
8234 --- linux-3.9.4/include/linux/uidgid.h 2012-12-11 03:30:57.000000000 +0000
8235 +++ linux-3.9.4-vs2.3.6.1/include/linux/uidgid.h 2013-05-31 14:47:11.000000000 +0000
8236 @@ -23,13 +23,17 @@ typedef struct {
8249 #define KUIDT_INIT(value) (kuid_t){ value }
8250 #define KGIDT_INIT(value) (kgid_t){ value }
8251 +#define KTAGT_INIT(value) (ktag_t){ value }
8253 static inline uid_t __kuid_val(kuid_t uid)
8255 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
8259 +static inline tag_t __ktag_val(ktag_t tag)
8266 typedef uid_t kuid_t;
8267 typedef gid_t kgid_t;
8268 +typedef tag_t ktag_t;
8270 static inline uid_t __kuid_val(kuid_t uid)
8272 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
8276 +static inline tag_t __ktag_val(ktag_t tag)
8281 #define KUIDT_INIT(value) ((kuid_t) value )
8282 #define KGIDT_INIT(value) ((kgid_t) value )
8283 +#define KTAGT_INIT(value) ((ktag_t) value )
8287 #define GLOBAL_ROOT_UID KUIDT_INIT(0)
8288 #define GLOBAL_ROOT_GID KGIDT_INIT(0)
8289 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
8291 #define INVALID_UID KUIDT_INIT(-1)
8292 #define INVALID_GID KGIDT_INIT(-1)
8293 +#define INVALID_TAG KTAGT_INIT(-1)
8295 static inline bool uid_eq(kuid_t left, kuid_t right)
8297 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
8298 return __kgid_val(left) == __kgid_val(right);
8301 +static inline bool tag_eq(ktag_t left, ktag_t right)
8303 + return __ktag_val(left) == __ktag_val(right);
8306 static inline bool uid_gt(kuid_t left, kuid_t right)
8308 return __kuid_val(left) > __kuid_val(right);
8309 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
8310 return !gid_eq(gid, INVALID_GID);
8313 +static inline bool tag_valid(ktag_t tag)
8315 + return !tag_eq(tag, INVALID_TAG);
8318 #ifdef CONFIG_USER_NS
8320 extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
8321 extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
8322 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
8324 extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
8325 extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
8326 +extern tag_t from_ktag(struct user_namespace *to, ktag_t tag);
8328 extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
8329 extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
8331 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
8332 return KGIDT_INIT(gid);
8335 +static inline ktag_t make_ktag(struct user_namespace *from, tag_t tag)
8337 + return KTAGT_INIT(tag);
8340 static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
8342 return __kuid_val(kuid);
8343 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
8344 return __kgid_val(kgid);
8347 +static inline tag_t from_ktag(struct user_namespace *to, ktag_t ktag)
8349 + return __ktag_val(ktag);
8352 static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
8354 uid_t uid = from_kuid(to, kuid);
8355 diff -NurpP --minimal linux-3.9.4/include/linux/vroot.h linux-3.9.4-vs2.3.6.1/include/linux/vroot.h
8356 --- linux-3.9.4/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
8357 +++ linux-3.9.4-vs2.3.6.1/include/linux/vroot.h 2013-05-31 14:47:11.000000000 +0000
8361 + * include/linux/vroot.h
8363 + * written by Herbert Pötzl, 9/11/2002
8364 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8366 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8367 + * Redistribution of this file is permitted under the
8368 + * GNU General Public License.
8371 +#ifndef _LINUX_VROOT_H
8372 +#define _LINUX_VROOT_H
8377 +/* Possible states of device */
8383 +struct vroot_device {
8387 + struct semaphore vr_ctl_mutex;
8388 + struct block_device *vr_device;
8393 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8395 +extern int register_vroot_grb(vroot_grb_func *);
8396 +extern int unregister_vroot_grb(vroot_grb_func *);
8398 +#endif /* __KERNEL__ */
8400 +#define MAX_VROOT_DEFAULT 8
8403 + * IOCTL commands --- we will commandeer 0x56 ('V')
8406 +#define VROOT_SET_DEV 0x5600
8407 +#define VROOT_CLR_DEV 0x5601
8409 +#endif /* _LINUX_VROOT_H */
8410 diff -NurpP --minimal linux-3.9.4/include/linux/vs_base.h linux-3.9.4-vs2.3.6.1/include/linux/vs_base.h
8411 --- linux-3.9.4/include/linux/vs_base.h 1970-01-01 00:00:00.000000000 +0000
8412 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_base.h 2013-05-31 14:47:11.000000000 +0000
8417 +#include "vserver/base.h"
8418 +#include "vserver/check.h"
8419 +#include "vserver/debug.h"
8422 +#warning duplicate inclusion
8424 diff -NurpP --minimal linux-3.9.4/include/linux/vs_context.h linux-3.9.4-vs2.3.6.1/include/linux/vs_context.h
8425 --- linux-3.9.4/include/linux/vs_context.h 1970-01-01 00:00:00.000000000 +0000
8426 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_context.h 2013-05-31 14:47:11.000000000 +0000
8428 +#ifndef _VS_CONTEXT_H
8429 +#define _VS_CONTEXT_H
8431 +#include "vserver/base.h"
8432 +#include "vserver/check.h"
8433 +#include "vserver/context.h"
8434 +#include "vserver/history.h"
8435 +#include "vserver/debug.h"
8437 +#include <linux/sched.h>
8440 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8442 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8443 + const char *_file, int _line, void *_here)
8448 + vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8449 + vxi, vxi ? vxi->vx_id : 0,
8450 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8452 + __vxh_get_vx_info(vxi, _here);
8454 + atomic_inc(&vxi->vx_usecnt);
8459 +extern void free_vx_info(struct vx_info *);
8461 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8463 +static inline void __put_vx_info(struct vx_info *vxi,
8464 + const char *_file, int _line, void *_here)
8469 + vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8470 + vxi, vxi ? vxi->vx_id : 0,
8471 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8473 + __vxh_put_vx_info(vxi, _here);
8475 + if (atomic_dec_and_test(&vxi->vx_usecnt))
8476 + free_vx_info(vxi);
8480 +#define init_vx_info(p, i) \
8481 + __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8483 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8484 + const char *_file, int _line, void *_here)
8487 + vxlprintk(VXD_CBIT(xid, 3),
8488 + "init_vx_info(%p[#%d.%d])",
8489 + vxi, vxi ? vxi->vx_id : 0,
8490 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8492 + __vxh_init_vx_info(vxi, vxp, _here);
8494 + atomic_inc(&vxi->vx_usecnt);
8500 +#define set_vx_info(p, i) \
8501 + __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8503 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8504 + const char *_file, int _line, void *_here)
8506 + struct vx_info *vxo;
8511 + vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8512 + vxi, vxi ? vxi->vx_id : 0,
8513 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8515 + __vxh_set_vx_info(vxi, vxp, _here);
8517 + atomic_inc(&vxi->vx_usecnt);
8518 + vxo = xchg(vxp, vxi);
8523 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8525 +static inline void __clr_vx_info(struct vx_info **vxp,
8526 + const char *_file, int _line, void *_here)
8528 + struct vx_info *vxo;
8530 + vxo = xchg(vxp, NULL);
8534 + vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8535 + vxo, vxo ? vxo->vx_id : 0,
8536 + vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8538 + __vxh_clr_vx_info(vxo, vxp, _here);
8540 + if (atomic_dec_and_test(&vxo->vx_usecnt))
8541 + free_vx_info(vxo);
8545 +#define claim_vx_info(v, p) \
8546 + __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8548 +static inline void __claim_vx_info(struct vx_info *vxi,
8549 + struct task_struct *task,
8550 + const char *_file, int _line, void *_here)
8552 + vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8553 + vxi, vxi ? vxi->vx_id : 0,
8554 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8555 + vxi ? atomic_read(&vxi->vx_tasks) : 0,
8556 + task, _file, _line);
8557 + __vxh_claim_vx_info(vxi, task, _here);
8559 + atomic_inc(&vxi->vx_tasks);
8563 +extern void unhash_vx_info(struct vx_info *);
8565 +#define release_vx_info(v, p) \
8566 + __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8568 +static inline void __release_vx_info(struct vx_info *vxi,
8569 + struct task_struct *task,
8570 + const char *_file, int _line, void *_here)
8572 + vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8573 + vxi, vxi ? vxi->vx_id : 0,
8574 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8575 + vxi ? atomic_read(&vxi->vx_tasks) : 0,
8576 + task, _file, _line);
8577 + __vxh_release_vx_info(vxi, task, _here);
8581 + if (atomic_dec_and_test(&vxi->vx_tasks))
8582 + unhash_vx_info(vxi);
8586 +#define task_get_vx_info(p) \
8587 + __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8589 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8590 + const char *_file, int _line, void *_here)
8592 + struct vx_info *vxi;
8595 + vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8597 + vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8603 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8605 + if (waitqueue_active(&vxi->vx_wait))
8606 + wake_up_interruptible(&vxi->vx_wait);
8610 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8612 +static inline void __enter_vx_info(struct vx_info *vxi,
8613 + struct vx_info_save *vxis, const char *_file, int _line)
8615 + vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8616 + vxi, vxi ? vxi->vx_id : 0, vxis, current,
8617 + current->xid, current->vx_info, _file, _line);
8618 + vxis->vxi = xchg(¤t->vx_info, vxi);
8619 + vxis->xid = current->xid;
8620 + current->xid = vxi ? vxi->vx_id : 0;
8623 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8625 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8626 + const char *_file, int _line)
8628 + vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8629 + vxis, vxis->xid, vxis->vxi, current,
8630 + current->xid, current->vx_info, _file, _line);
8631 + (void)xchg(¤t->vx_info, vxis->vxi);
8632 + current->xid = vxis->xid;
8636 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8638 + vxis->vxi = xchg(¤t->vx_info, NULL);
8639 + vxis->xid = xchg(¤t->xid, (xid_t)0);
8642 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8644 + (void)xchg(¤t->xid, vxis->xid);
8645 + (void)xchg(¤t->vx_info, vxis->vxi);
8648 +#define task_is_init(p) \
8649 + __task_is_init(p, __FILE__, __LINE__, __HERE__)
8651 +static inline int __task_is_init(struct task_struct *p,
8652 + const char *_file, int _line, void *_here)
8654 + int is_init = is_global_init(p);
8658 + is_init = p->vx_info->vx_initpid == p->pid;
8663 +extern void exit_vx_info(struct task_struct *, int);
8664 +extern void exit_vx_info_early(struct task_struct *, int);
8668 +#warning duplicate inclusion
8670 diff -NurpP --minimal linux-3.9.4/include/linux/vs_cowbl.h linux-3.9.4-vs2.3.6.1/include/linux/vs_cowbl.h
8671 --- linux-3.9.4/include/linux/vs_cowbl.h 1970-01-01 00:00:00.000000000 +0000
8672 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_cowbl.h 2013-05-31 14:47:11.000000000 +0000
8674 +#ifndef _VS_COWBL_H
8675 +#define _VS_COWBL_H
8677 +#include <linux/fs.h>
8678 +#include <linux/dcache.h>
8679 +#include <linux/namei.h>
8680 +#include <linux/slab.h>
8682 +extern struct dentry *cow_break_link(const char *pathname);
8684 +static inline int cow_check_and_break(struct path *path)
8686 + struct inode *inode = path->dentry->d_inode;
8689 + /* do we need this check? */
8690 + if (IS_RDONLY(inode))
8693 + if (IS_COW(inode)) {
8694 + if (IS_COW_LINK(inode)) {
8695 + struct dentry *new_dentry, *old_dentry = path->dentry;
8698 + buf = kmalloc(PATH_MAX, GFP_KERNEL);
8702 + pp = d_path(path, buf, PATH_MAX);
8703 + new_dentry = cow_break_link(pp);
8705 + if (!IS_ERR(new_dentry)) {
8706 + path->dentry = new_dentry;
8709 + error = PTR_ERR(new_dentry);
8711 + inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8712 + inode->i_ctime = CURRENT_TIME;
8713 + mark_inode_dirty(inode);
8720 +#warning duplicate inclusion
8722 diff -NurpP --minimal linux-3.9.4/include/linux/vs_cvirt.h linux-3.9.4-vs2.3.6.1/include/linux/vs_cvirt.h
8723 --- linux-3.9.4/include/linux/vs_cvirt.h 1970-01-01 00:00:00.000000000 +0000
8724 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_cvirt.h 2013-05-31 14:47:11.000000000 +0000
8726 +#ifndef _VS_CVIRT_H
8727 +#define _VS_CVIRT_H
8729 +#include "vserver/cvirt.h"
8730 +#include "vserver/context.h"
8731 +#include "vserver/base.h"
8732 +#include "vserver/check.h"
8733 +#include "vserver/debug.h"
8736 +static inline void vx_activate_task(struct task_struct *p)
8738 + struct vx_info *vxi;
8740 + if ((vxi = p->vx_info)) {
8741 + vx_update_load(vxi);
8742 + atomic_inc(&vxi->cvirt.nr_running);
8746 +static inline void vx_deactivate_task(struct task_struct *p)
8748 + struct vx_info *vxi;
8750 + if ((vxi = p->vx_info)) {
8751 + vx_update_load(vxi);
8752 + atomic_dec(&vxi->cvirt.nr_running);
8756 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8758 + struct vx_info *vxi;
8760 + if ((vxi = p->vx_info))
8761 + atomic_inc(&vxi->cvirt.nr_uninterruptible);
8764 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8766 + struct vx_info *vxi;
8768 + if ((vxi = p->vx_info))
8769 + atomic_dec(&vxi->cvirt.nr_uninterruptible);
8774 +#warning duplicate inclusion
8776 diff -NurpP --minimal linux-3.9.4/include/linux/vs_device.h linux-3.9.4-vs2.3.6.1/include/linux/vs_device.h
8777 --- linux-3.9.4/include/linux/vs_device.h 1970-01-01 00:00:00.000000000 +0000
8778 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_device.h 2013-05-31 14:47:11.000000000 +0000
8780 +#ifndef _VS_DEVICE_H
8781 +#define _VS_DEVICE_H
8783 +#include "vserver/base.h"
8784 +#include "vserver/device.h"
8785 +#include "vserver/debug.h"
8788 +#ifdef CONFIG_VSERVER_DEVICE
8790 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8792 +#define vs_device_perm(v, d, m, p) \
8793 + ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8798 +int vs_map_device(struct vx_info *vxi,
8799 + dev_t device, dev_t *target, umode_t mode)
8806 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8811 +#define vs_map_chrdev(d, t, p) \
8812 + ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8813 +#define vs_map_blkdev(d, t, p) \
8814 + ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8816 +#define vs_chrdev_perm(d, p) \
8817 + vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8818 +#define vs_blkdev_perm(d, p) \
8819 + vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8823 +#warning duplicate inclusion
8825 diff -NurpP --minimal linux-3.9.4/include/linux/vs_dlimit.h linux-3.9.4-vs2.3.6.1/include/linux/vs_dlimit.h
8826 --- linux-3.9.4/include/linux/vs_dlimit.h 1970-01-01 00:00:00.000000000 +0000
8827 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_dlimit.h 2013-05-31 14:47:11.000000000 +0000
8829 +#ifndef _VS_DLIMIT_H
8830 +#define _VS_DLIMIT_H
8832 +#include <linux/fs.h>
8834 +#include "vserver/dlimit.h"
8835 +#include "vserver/base.h"
8836 +#include "vserver/debug.h"
8839 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8841 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8842 + const char *_file, int _line)
8846 + vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8847 + dli, dli ? dli->dl_tag : 0,
8848 + dli ? atomic_read(&dli->dl_usecnt) : 0,
8850 + atomic_inc(&dli->dl_usecnt);
8855 +#define free_dl_info(i) \
8856 + call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8858 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8860 +static inline void __put_dl_info(struct dl_info *dli,
8861 + const char *_file, int _line)
8865 + vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8866 + dli, dli ? dli->dl_tag : 0,
8867 + dli ? atomic_read(&dli->dl_usecnt) : 0,
8869 + if (atomic_dec_and_test(&dli->dl_usecnt))
8870 + free_dl_info(dli);
8874 +#define __dlimit_char(d) ((d) ? '*' : ' ')
8876 +static inline int __dl_alloc_space(struct super_block *sb,
8877 + tag_t tag, dlsize_t nr, const char *file, int line)
8879 + struct dl_info *dli = NULL;
8884 + dli = locate_dl_info(sb, tag);
8888 + spin_lock(&dli->dl_lock);
8889 + ret = (dli->dl_space_used + nr > dli->dl_space_total);
8891 + dli->dl_space_used += nr;
8892 + spin_unlock(&dli->dl_lock);
8895 + vxlprintk(VXD_CBIT(dlim, 1),
8896 + "ALLOC (%p,#%d)%c %lld bytes (%d)",
8897 + sb, tag, __dlimit_char(dli), (long long)nr,
8899 + return ret ? -ENOSPC : 0;
8902 +static inline void __dl_free_space(struct super_block *sb,
8903 + tag_t tag, dlsize_t nr, const char *_file, int _line)
8905 + struct dl_info *dli = NULL;
8909 + dli = locate_dl_info(sb, tag);
8913 + spin_lock(&dli->dl_lock);
8914 + if (dli->dl_space_used > nr)
8915 + dli->dl_space_used -= nr;
8917 + dli->dl_space_used = 0;
8918 + spin_unlock(&dli->dl_lock);
8921 + vxlprintk(VXD_CBIT(dlim, 1),
8922 + "FREE (%p,#%d)%c %lld bytes",
8923 + sb, tag, __dlimit_char(dli), (long long)nr,
8927 +static inline int __dl_alloc_inode(struct super_block *sb,
8928 + tag_t tag, const char *_file, int _line)
8930 + struct dl_info *dli;
8933 + dli = locate_dl_info(sb, tag);
8937 + spin_lock(&dli->dl_lock);
8938 + dli->dl_inodes_used++;
8939 + ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8940 + spin_unlock(&dli->dl_lock);
8943 + vxlprintk(VXD_CBIT(dlim, 0),
8944 + "ALLOC (%p,#%d)%c inode (%d)",
8945 + sb, tag, __dlimit_char(dli), ret, _file, _line);
8946 + return ret ? -ENOSPC : 0;
8949 +static inline void __dl_free_inode(struct super_block *sb,
8950 + tag_t tag, const char *_file, int _line)
8952 + struct dl_info *dli;
8954 + dli = locate_dl_info(sb, tag);
8958 + spin_lock(&dli->dl_lock);
8959 + if (dli->dl_inodes_used > 1)
8960 + dli->dl_inodes_used--;
8962 + dli->dl_inodes_used = 0;
8963 + spin_unlock(&dli->dl_lock);
8966 + vxlprintk(VXD_CBIT(dlim, 0),
8967 + "FREE (%p,#%d)%c inode",
8968 + sb, tag, __dlimit_char(dli), _file, _line);
8971 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
8972 + unsigned long long *free_blocks, unsigned long long *root_blocks,
8973 + const char *_file, int _line)
8975 + struct dl_info *dli;
8976 + uint64_t broot, bfree;
8978 + dli = locate_dl_info(sb, tag);
8982 + spin_lock(&dli->dl_lock);
8983 + broot = (dli->dl_space_total -
8984 + (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8985 + >> sb->s_blocksize_bits;
8986 + bfree = (dli->dl_space_total - dli->dl_space_used)
8987 + >> sb->s_blocksize_bits;
8988 + spin_unlock(&dli->dl_lock);
8990 + vxlprintk(VXD_CBIT(dlim, 2),
8991 + "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8992 + (long long)bfree, (long long)broot,
8993 + *free_blocks, *root_blocks, dli->dl_nrlmult,
8995 + if (free_blocks) {
8996 + if (*free_blocks > bfree)
8997 + *free_blocks = bfree;
8999 + if (root_blocks) {
9000 + if (*root_blocks > broot)
9001 + *root_blocks = broot;
9006 +#define dl_prealloc_space(in, bytes) \
9007 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9008 + __FILE__, __LINE__ )
9010 +#define dl_alloc_space(in, bytes) \
9011 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9012 + __FILE__, __LINE__ )
9014 +#define dl_reserve_space(in, bytes) \
9015 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9016 + __FILE__, __LINE__ )
9018 +#define dl_claim_space(in, bytes) (0)
9020 +#define dl_release_space(in, bytes) \
9021 + __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9022 + __FILE__, __LINE__ )
9024 +#define dl_free_space(in, bytes) \
9025 + __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9026 + __FILE__, __LINE__ )
9030 +#define dl_alloc_inode(in) \
9031 + __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
9033 +#define dl_free_inode(in) \
9034 + __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
9037 +#define dl_adjust_block(sb, tag, fb, rb) \
9038 + __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9042 +#warning duplicate inclusion
9044 diff -NurpP --minimal linux-3.9.4/include/linux/vs_inet.h linux-3.9.4-vs2.3.6.1/include/linux/vs_inet.h
9045 --- linux-3.9.4/include/linux/vs_inet.h 1970-01-01 00:00:00.000000000 +0000
9046 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_inet.h 2013-05-31 14:47:11.000000000 +0000
9051 +#include "vserver/base.h"
9052 +#include "vserver/network.h"
9053 +#include "vserver/debug.h"
9055 +#define IPI_LOOPBACK htonl(INADDR_LOOPBACK)
9057 +#define NXAV4(a) NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9058 + NIPQUAD((a)->mask), (a)->type
9059 +#define NXAV4_FMT "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9061 +#define NIPQUAD(addr) \
9062 + ((unsigned char *)&addr)[0], \
9063 + ((unsigned char *)&addr)[1], \
9064 + ((unsigned char *)&addr)[2], \
9065 + ((unsigned char *)&addr)[3]
9067 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9071 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9073 + __be32 ip = nxa->ip[0].s_addr;
9074 + __be32 mask = nxa->mask.s_addr;
9075 + __be32 bcast = ip | ~mask;
9078 + switch (nxa->type & tmask) {
9079 + case NXA_TYPE_MASK:
9080 + ret = (ip == (addr & mask));
9082 + case NXA_TYPE_ADDR:
9086 + /* fall through to broadcast */
9087 + case NXA_MOD_BCAST:
9088 + ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9090 + case NXA_TYPE_RANGE:
9091 + ret = ((nxa->ip[0].s_addr <= addr) &&
9092 + (nxa->ip[1].s_addr > addr));
9094 + case NXA_TYPE_ANY:
9099 + vxdprintk(VXD_CBIT(net, 0),
9100 + "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9101 + nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9106 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9108 + struct nx_addr_v4 *nxa;
9109 + unsigned long irqflags;
9116 + /* allow 127.0.0.1 when remapping lback */
9117 + if ((tmask & NXA_LOOPBACK) &&
9118 + (addr == IPI_LOOPBACK) &&
9119 + nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9122 + /* check for lback address */
9123 + if ((tmask & NXA_MOD_LBACK) &&
9124 + (nxi->v4_lback.s_addr == addr))
9127 + /* check for broadcast address */
9128 + if ((tmask & NXA_MOD_BCAST) &&
9129 + (nxi->v4_bcast.s_addr == addr))
9133 + /* check for v4 addresses */
9134 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
9135 + for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9136 + if (v4_addr_match(nxa, addr, tmask))
9140 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9142 + vxdprintk(VXD_CBIT(net, 0),
9143 + "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9144 + nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9149 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9151 + /* FIXME: needs full range checks */
9152 + return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9156 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9158 + struct nx_addr_v4 *ptr;
9159 + unsigned long irqflags;
9162 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
9163 + for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9164 + if (v4_nx_addr_match(ptr, nxa, mask))
9168 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9172 +#include <net/inet_sock.h>
9175 + * Check if a given address matches for a socket
9177 + * nxi: the socket's nx_info if any
9178 + * addr: to be verified address
9181 +int v4_sock_addr_match (
9182 + struct nx_info *nxi,
9183 + struct inet_sock *inet,
9186 + __be32 saddr = inet->inet_rcv_saddr;
9187 + __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9189 + if (addr && (saddr == addr || bcast == addr))
9192 + return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9197 +/* inet related checks and helpers */
9206 +#include <linux/netdevice.h>
9207 +#include <linux/inetdevice.h>
9208 +#include <net/inet_sock.h>
9209 +#include <net/inet_timewait_sock.h>
9212 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9213 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9214 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9218 + * check if address is covered by socket
9220 + * sk: the socket to check against
9221 + * addr: the address in question (must be != 0)
9225 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9227 + struct nx_info *nxi = sk->sk_nx_info;
9228 + __be32 saddr = sk_rcv_saddr(sk);
9230 + vxdprintk(VXD_CBIT(net, 5),
9231 + "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9232 + sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9233 + (sk->sk_socket?sk->sk_socket->flags:0));
9235 + if (saddr) { /* direct address match */
9236 + return v4_addr_match(nxa, saddr, -1);
9237 + } else if (nxi) { /* match against nx_info */
9238 + return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9239 + } else { /* unrestricted any socket */
9247 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9249 + vxdprintk(VXD_CBIT(net, 1),
9250 + "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9251 + nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9252 + nxi ? dev_in_nx_info(dev, nxi) : 0);
9254 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9256 + if (dev_in_nx_info(dev, nxi))
9263 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9269 + return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9273 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9275 + vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9276 + nxi, nxi ? nxi->nx_id : 0, ifa,
9277 + nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9279 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9281 + if (v4_ifa_in_nx_info(ifa, nxi))
9287 +struct nx_v4_sock_addr {
9288 + __be32 saddr; /* Address used for validation */
9289 + __be32 baddr; /* Address used for socket bind */
9293 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9294 + struct nx_v4_sock_addr *nsa)
9296 + struct sock *sk = &inet->sk;
9297 + struct nx_info *nxi = sk->sk_nx_info;
9298 + __be32 saddr = addr->sin_addr.s_addr;
9299 + __be32 baddr = saddr;
9301 + vxdprintk(VXD_CBIT(net, 3),
9302 + "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9303 + sk, sk->sk_nx_info, sk->sk_socket,
9304 + (sk->sk_socket ? sk->sk_socket->flags : 0),
9308 + if (saddr == INADDR_ANY) {
9309 + if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9310 + baddr = nxi->v4.ip[0].s_addr;
9311 + } else if (saddr == IPI_LOOPBACK) {
9312 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9313 + baddr = nxi->v4_lback.s_addr;
9314 + } else if (!ipv4_is_multicast(saddr) ||
9315 + !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9316 + /* normal address bind */
9317 + if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9318 + return -EADDRNOTAVAIL;
9322 + vxdprintk(VXD_CBIT(net, 3),
9323 + "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9324 + sk, NIPQUAD(saddr), NIPQUAD(baddr));
9326 + nsa->saddr = saddr;
9327 + nsa->baddr = baddr;
9332 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9334 + inet->inet_saddr = nsa->baddr;
9335 + inet->inet_rcv_saddr = nsa->baddr;
9340 + * helper to simplify inet_lookup_listener
9342 + * nxi: the socket's nx_info if any
9343 + * addr: to be verified address
9344 + * saddr: socket address
9346 +static inline int v4_inet_addr_match (
9347 + struct nx_info *nxi,
9351 + if (addr && (saddr == addr))
9354 + return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9358 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9360 + if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9361 + (addr == nxi->v4_lback.s_addr))
9362 + return IPI_LOOPBACK;
9367 +int nx_info_has_v4(struct nx_info *nxi)
9373 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9378 +#else /* CONFIG_INET */
9381 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9387 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9393 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9399 +int nx_info_has_v4(struct nx_info *nxi)
9404 +#endif /* CONFIG_INET */
9406 +#define current_nx_info_has_v4() \
9407 + nx_info_has_v4(current_nx_info())
9410 +// #warning duplicate inclusion
9412 diff -NurpP --minimal linux-3.9.4/include/linux/vs_inet6.h linux-3.9.4-vs2.3.6.1/include/linux/vs_inet6.h
9413 --- linux-3.9.4/include/linux/vs_inet6.h 1970-01-01 00:00:00.000000000 +0000
9414 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_inet6.h 2013-05-31 14:47:11.000000000 +0000
9416 +#ifndef _VS_INET6_H
9417 +#define _VS_INET6_H
9419 +#include "vserver/base.h"
9420 +#include "vserver/network.h"
9421 +#include "vserver/debug.h"
9423 +#include <net/ipv6.h>
9425 +#define NXAV6(a) &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9426 +#define NXAV6_FMT "[%pI6/%pI6/%d:%04x]"
9432 +int v6_addr_match(struct nx_addr_v6 *nxa,
9433 + const struct in6_addr *addr, uint16_t mask)
9437 + switch (nxa->type & mask) {
9438 + case NXA_TYPE_MASK:
9439 + ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9441 + case NXA_TYPE_ADDR:
9442 + ret = ipv6_addr_equal(&nxa->ip, addr);
9444 + case NXA_TYPE_ANY:
9448 + vxdprintk(VXD_CBIT(net, 0),
9449 + "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9450 + nxa, NXAV6(nxa), addr, mask, ret);
9455 +int v6_addr_in_nx_info(struct nx_info *nxi,
9456 + const struct in6_addr *addr, uint16_t mask)
9458 + struct nx_addr_v6 *nxa;
9459 + unsigned long irqflags;
9465 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
9466 + for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9467 + if (v6_addr_match(nxa, addr, mask))
9471 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9473 + vxdprintk(VXD_CBIT(net, 0),
9474 + "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9475 + nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9480 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9482 + /* FIXME: needs full range checks */
9483 + return v6_addr_match(nxa, &addr->ip, mask);
9487 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9489 + struct nx_addr_v6 *ptr;
9490 + unsigned long irqflags;
9493 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
9494 + for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9495 + if (v6_nx_addr_match(ptr, nxa, mask))
9499 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9505 + * Check if a given address matches for a socket
9507 + * nxi: the socket's nx_info if any
9508 + * addr: to be verified address
9511 +int v6_sock_addr_match (
9512 + struct nx_info *nxi,
9513 + struct inet_sock *inet,
9514 + struct in6_addr *addr)
9516 + struct sock *sk = &inet->sk;
9517 + struct in6_addr *saddr = inet6_rcv_saddr(sk);
9519 + if (!ipv6_addr_any(addr) &&
9520 + ipv6_addr_equal(saddr, addr))
9522 + if (ipv6_addr_any(saddr))
9523 + return v6_addr_in_nx_info(nxi, addr, -1);
9528 + * check if address is covered by socket
9530 + * sk: the socket to check against
9531 + * addr: the address in question (must be != 0)
9535 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9537 + struct nx_info *nxi = sk->sk_nx_info;
9538 + struct in6_addr *saddr = inet6_rcv_saddr(sk);
9540 + vxdprintk(VXD_CBIT(net, 5),
9541 + "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9542 + sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9543 + (sk->sk_socket?sk->sk_socket->flags:0));
9545 + if (!ipv6_addr_any(saddr)) { /* direct address match */
9546 + return v6_addr_match(nxa, saddr, -1);
9547 + } else if (nxi) { /* match against nx_info */
9548 + return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9549 + } else { /* unrestricted any socket */
9555 +/* inet related checks and helpers */
9563 +#include <linux/netdevice.h>
9564 +#include <linux/inetdevice.h>
9565 +#include <net/inet_timewait_sock.h>
9568 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9569 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9570 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9575 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9581 + return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9585 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9587 + vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9588 + nxi, nxi ? nxi->nx_id : 0, ifa,
9589 + nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9591 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9593 + if (v6_ifa_in_nx_info(ifa, nxi))
9599 +struct nx_v6_sock_addr {
9600 + struct in6_addr saddr; /* Address used for validation */
9601 + struct in6_addr baddr; /* Address used for socket bind */
9605 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9606 + struct nx_v6_sock_addr *nsa)
9608 + // struct sock *sk = &inet->sk;
9609 + // struct nx_info *nxi = sk->sk_nx_info;
9610 + struct in6_addr saddr = addr->sin6_addr;
9611 + struct in6_addr baddr = saddr;
9613 + nsa->saddr = saddr;
9614 + nsa->baddr = baddr;
9619 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9621 + // struct sock *sk = &inet->sk;
9622 + // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9624 + // *saddr = nsa->baddr;
9625 + // inet->inet_saddr = nsa->baddr;
9629 +int nx_info_has_v6(struct nx_info *nxi)
9638 +#else /* CONFIG_IPV6 */
9641 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9648 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9654 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9660 +int nx_info_has_v6(struct nx_info *nxi)
9665 +#endif /* CONFIG_IPV6 */
9667 +#define current_nx_info_has_v6() \
9668 + nx_info_has_v6(current_nx_info())
9671 +#warning duplicate inclusion
9673 diff -NurpP --minimal linux-3.9.4/include/linux/vs_limit.h linux-3.9.4-vs2.3.6.1/include/linux/vs_limit.h
9674 --- linux-3.9.4/include/linux/vs_limit.h 1970-01-01 00:00:00.000000000 +0000
9675 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_limit.h 2013-05-31 14:47:11.000000000 +0000
9677 +#ifndef _VS_LIMIT_H
9678 +#define _VS_LIMIT_H
9680 +#include "vserver/limit.h"
9681 +#include "vserver/base.h"
9682 +#include "vserver/context.h"
9683 +#include "vserver/debug.h"
9684 +#include "vserver/context.h"
9685 +#include "vserver/limit_int.h"
9688 +#define vx_acc_cres(v, d, p, r) \
9689 + __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9691 +#define vx_acc_cres_cond(x, d, p, r) \
9692 + __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9693 + r, d, p, __FILE__, __LINE__)
9696 +#define vx_add_cres(v, a, p, r) \
9697 + __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9698 +#define vx_sub_cres(v, a, p, r) vx_add_cres(v, -(a), p, r)
9700 +#define vx_add_cres_cond(x, a, p, r) \
9701 + __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9702 + r, a, p, __FILE__, __LINE__)
9703 +#define vx_sub_cres_cond(x, a, p, r) vx_add_cres_cond(x, -(a), p, r)
9706 +/* process and file limits */
9708 +#define vx_nproc_inc(p) \
9709 + vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9711 +#define vx_nproc_dec(p) \
9712 + vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9714 +#define vx_files_inc(f) \
9715 + vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9717 +#define vx_files_dec(f) \
9718 + vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9720 +#define vx_locks_inc(l) \
9721 + vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9723 +#define vx_locks_dec(l) \
9724 + vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9726 +#define vx_openfd_inc(f) \
9727 + vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9729 +#define vx_openfd_dec(f) \
9730 + vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9733 +#define vx_cres_avail(v, n, r) \
9734 + __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9737 +#define vx_nproc_avail(n) \
9738 + vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9740 +#define vx_files_avail(n) \
9741 + vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9743 +#define vx_locks_avail(n) \
9744 + vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9746 +#define vx_openfd_avail(n) \
9747 + vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9750 +/* dentry limits */
9752 +#define vx_dentry_inc(d) do { \
9753 + if ((d)->d_count == 1) \
9754 + vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY); \
9757 +#define vx_dentry_dec(d) do { \
9758 + if ((d)->d_count == 0) \
9759 + vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY); \
9762 +#define vx_dentry_avail(n) \
9763 + vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9766 +/* socket limits */
9768 +#define vx_sock_inc(s) \
9769 + vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9771 +#define vx_sock_dec(s) \
9772 + vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9774 +#define vx_sock_avail(n) \
9775 + vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9778 +/* ipc resource limits */
9780 +#define vx_ipcmsg_add(v, u, a) \
9781 + vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9783 +#define vx_ipcmsg_sub(v, u, a) \
9784 + vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9786 +#define vx_ipcmsg_avail(v, a) \
9787 + vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9790 +#define vx_ipcshm_add(v, k, a) \
9791 + vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9793 +#define vx_ipcshm_sub(v, k, a) \
9794 + vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9796 +#define vx_ipcshm_avail(v, a) \
9797 + vx_cres_avail(v, a, VLIMIT_SHMEM)
9800 +#define vx_semary_inc(a) \
9801 + vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9803 +#define vx_semary_dec(a) \
9804 + vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9807 +#define vx_nsems_add(a,n) \
9808 + vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9810 +#define vx_nsems_sub(a,n) \
9811 + vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9815 +#warning duplicate inclusion
9817 diff -NurpP --minimal linux-3.9.4/include/linux/vs_network.h linux-3.9.4-vs2.3.6.1/include/linux/vs_network.h
9818 --- linux-3.9.4/include/linux/vs_network.h 1970-01-01 00:00:00.000000000 +0000
9819 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_network.h 2013-05-31 14:47:11.000000000 +0000
9821 +#ifndef _NX_VS_NETWORK_H
9822 +#define _NX_VS_NETWORK_H
9824 +#include "vserver/context.h"
9825 +#include "vserver/network.h"
9826 +#include "vserver/base.h"
9827 +#include "vserver/check.h"
9828 +#include "vserver/debug.h"
9830 +#include <linux/sched.h>
9833 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9835 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9836 + const char *_file, int _line)
9841 + vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9842 + nxi, nxi ? nxi->nx_id : 0,
9843 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9846 + atomic_inc(&nxi->nx_usecnt);
9851 +extern void free_nx_info(struct nx_info *);
9853 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9855 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9860 + vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9861 + nxi, nxi ? nxi->nx_id : 0,
9862 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9865 + if (atomic_dec_and_test(&nxi->nx_usecnt))
9866 + free_nx_info(nxi);
9870 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9872 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9873 + const char *_file, int _line)
9876 + vxlprintk(VXD_CBIT(nid, 3),
9877 + "init_nx_info(%p[#%d.%d])",
9878 + nxi, nxi ? nxi->nx_id : 0,
9879 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9882 + atomic_inc(&nxi->nx_usecnt);
9888 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9890 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9891 + const char *_file, int _line)
9893 + struct nx_info *nxo;
9898 + vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9899 + nxi, nxi ? nxi->nx_id : 0,
9900 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9903 + atomic_inc(&nxi->nx_usecnt);
9904 + nxo = xchg(nxp, nxi);
9908 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9910 +static inline void __clr_nx_info(struct nx_info **nxp,
9911 + const char *_file, int _line)
9913 + struct nx_info *nxo;
9915 + nxo = xchg(nxp, NULL);
9919 + vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9920 + nxo, nxo ? nxo->nx_id : 0,
9921 + nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9924 + if (atomic_dec_and_test(&nxo->nx_usecnt))
9925 + free_nx_info(nxo);
9929 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9931 +static inline void __claim_nx_info(struct nx_info *nxi,
9932 + struct task_struct *task, const char *_file, int _line)
9934 + vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9935 + nxi, nxi ? nxi->nx_id : 0,
9936 + nxi?atomic_read(&nxi->nx_usecnt):0,
9937 + nxi?atomic_read(&nxi->nx_tasks):0,
9938 + task, _file, _line);
9940 + atomic_inc(&nxi->nx_tasks);
9944 +extern void unhash_nx_info(struct nx_info *);
9946 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9948 +static inline void __release_nx_info(struct nx_info *nxi,
9949 + struct task_struct *task, const char *_file, int _line)
9951 + vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9952 + nxi, nxi ? nxi->nx_id : 0,
9953 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9954 + nxi ? atomic_read(&nxi->nx_tasks) : 0,
9955 + task, _file, _line);
9959 + if (atomic_dec_and_test(&nxi->nx_tasks))
9960 + unhash_nx_info(nxi);
9964 +#define task_get_nx_info(i) __task_get_nx_info(i, __FILE__, __LINE__)
9966 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9967 + const char *_file, int _line)
9969 + struct nx_info *nxi;
9972 + vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9974 + nxi = __get_nx_info(p->nx_info, _file, _line);
9980 +static inline void exit_nx_info(struct task_struct *p)
9983 + release_nx_info(p->nx_info, p);
9988 +#warning duplicate inclusion
9990 diff -NurpP --minimal linux-3.9.4/include/linux/vs_pid.h linux-3.9.4-vs2.3.6.1/include/linux/vs_pid.h
9991 --- linux-3.9.4/include/linux/vs_pid.h 1970-01-01 00:00:00.000000000 +0000
9992 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_pid.h 2013-05-31 14:47:11.000000000 +0000
9997 +#include "vserver/base.h"
9998 +#include "vserver/check.h"
9999 +#include "vserver/context.h"
10000 +#include "vserver/debug.h"
10001 +#include "vserver/pid.h"
10002 +#include <linux/pid_namespace.h>
10005 +#define VXF_FAKE_INIT (VXF_INFO_INIT | VXF_STATE_INIT)
10008 +int vx_proc_task_visible(struct task_struct *task)
10010 + if ((task->pid == 1) &&
10011 + !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10012 + /* show a blend through init */
10014 + if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10021 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10025 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10027 + struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10029 + if (task && !vx_proc_task_visible(task)) {
10030 + vxdprintk(VXD_CBIT(misc, 6),
10031 + "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10032 + task, task->xid, task->pid,
10033 + current, current->xid, current->pid);
10034 + put_task_struct(task);
10042 +#warning duplicate inclusion
10044 diff -NurpP --minimal linux-3.9.4/include/linux/vs_sched.h linux-3.9.4-vs2.3.6.1/include/linux/vs_sched.h
10045 --- linux-3.9.4/include/linux/vs_sched.h 1970-01-01 00:00:00.000000000 +0000
10046 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_sched.h 2013-05-31 14:47:11.000000000 +0000
10048 +#ifndef _VS_SCHED_H
10049 +#define _VS_SCHED_H
10051 +#include "vserver/base.h"
10052 +#include "vserver/context.h"
10053 +#include "vserver/sched.h"
10056 +#define MAX_PRIO_BIAS 20
10057 +#define MIN_PRIO_BIAS -20
10060 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10062 + struct vx_info *vxi = p->vx_info;
10065 + prio += vx_cpu(vxi, sched_pc).prio_bias;
10069 +static inline void vx_account_user(struct vx_info *vxi,
10070 + cputime_t cputime, int nice)
10074 + vx_cpu(vxi, sched_pc).user_ticks += cputime;
10077 +static inline void vx_account_system(struct vx_info *vxi,
10078 + cputime_t cputime, int idle)
10082 + vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10086 +#warning duplicate inclusion
10088 diff -NurpP --minimal linux-3.9.4/include/linux/vs_socket.h linux-3.9.4-vs2.3.6.1/include/linux/vs_socket.h
10089 --- linux-3.9.4/include/linux/vs_socket.h 1970-01-01 00:00:00.000000000 +0000
10090 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_socket.h 2013-05-31 14:47:11.000000000 +0000
10092 +#ifndef _VS_SOCKET_H
10093 +#define _VS_SOCKET_H
10095 +#include "vserver/debug.h"
10096 +#include "vserver/base.h"
10097 +#include "vserver/cacct.h"
10098 +#include "vserver/context.h"
10099 +#include "vserver/tag.h"
10102 +/* socket accounting */
10104 +#include <linux/socket.h>
10106 +static inline int vx_sock_type(int family)
10108 + switch (family) {
10110 + return VXA_SOCK_UNSPEC;
10112 + return VXA_SOCK_UNIX;
10114 + return VXA_SOCK_INET;
10116 + return VXA_SOCK_INET6;
10118 + return VXA_SOCK_PACKET;
10120 + return VXA_SOCK_OTHER;
10124 +#define vx_acc_sock(v, f, p, s) \
10125 + __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10127 +static inline void __vx_acc_sock(struct vx_info *vxi,
10128 + int family, int pos, int size, char *file, int line)
10131 + int type = vx_sock_type(family);
10133 + atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10134 + atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10138 +#define vx_sock_recv(sk, s) \
10139 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10140 +#define vx_sock_send(sk, s) \
10141 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10142 +#define vx_sock_fail(sk, s) \
10143 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10146 +#define sock_vx_init(s) do { \
10147 + (s)->sk_xid = 0; \
10148 + (s)->sk_vx_info = NULL; \
10151 +#define sock_nx_init(s) do { \
10152 + (s)->sk_nid = 0; \
10153 + (s)->sk_nx_info = NULL; \
10157 +#warning duplicate inclusion
10159 diff -NurpP --minimal linux-3.9.4/include/linux/vs_tag.h linux-3.9.4-vs2.3.6.1/include/linux/vs_tag.h
10160 --- linux-3.9.4/include/linux/vs_tag.h 1970-01-01 00:00:00.000000000 +0000
10161 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_tag.h 2013-05-31 14:47:11.000000000 +0000
10166 +#include <linux/vserver/tag.h>
10168 +/* check conditions */
10170 +#define DX_ADMIN 0x0001
10171 +#define DX_WATCH 0x0002
10172 +#define DX_HOSTID 0x0008
10174 +#define DX_IDENT 0x0010
10176 +#define DX_ARG_MASK 0x0010
10179 +#define dx_task_tag(t) ((t)->tag)
10181 +#define dx_current_tag() dx_task_tag(current)
10183 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10185 +#define dx_weak_check(c, m) ((m) ? dx_check(c, m) : 1)
10189 + * check current context for ADMIN/WATCH and
10190 + * optionally against supplied argument
10192 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10194 + if (mode & DX_ARG_MASK) {
10195 + if ((mode & DX_IDENT) && (id == cid))
10198 + return (((mode & DX_ADMIN) && (cid == 0)) ||
10199 + ((mode & DX_WATCH) && (cid == 1)) ||
10200 + ((mode & DX_HOSTID) && (id == 0)));
10204 +int dx_permission(const struct inode *inode, int mask);
10208 +#warning duplicate inclusion
10210 diff -NurpP --minimal linux-3.9.4/include/linux/vs_time.h linux-3.9.4-vs2.3.6.1/include/linux/vs_time.h
10211 --- linux-3.9.4/include/linux/vs_time.h 1970-01-01 00:00:00.000000000 +0000
10212 +++ linux-3.9.4-vs2.3.6.1/include/linux/vs_time.h 2013-05-31 14:47:11.000000000 +0000
10214 +#ifndef _VS_TIME_H
10215 +#define _VS_TIME_H
10218 +/* time faking stuff */
10220 +#ifdef CONFIG_VSERVER_VTIME
10222 +extern void vx_adjust_timespec(struct timespec *ts);
10223 +extern int vx_settimeofday(const struct timespec *ts);
10226 +#define vx_adjust_timespec(t) do { } while (0)
10227 +#define vx_settimeofday(t) do_settimeofday(t)
10231 +#warning duplicate inclusion
10233 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/base.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/base.h
10234 --- linux-3.9.4/include/linux/vserver/base.h 1970-01-01 00:00:00.000000000 +0000
10235 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/base.h 2013-05-31 17:55:09.000000000 +0000
10237 +#ifndef _VSERVER_BASE_H
10238 +#define _VSERVER_BASE_H
10241 +/* context state changes */
10253 +#define vx_task_xid(t) ((t)->xid)
10255 +#define vx_current_xid() vx_task_xid(current)
10257 +#define current_vx_info() (current->vx_info)
10260 +#define nx_task_nid(t) ((t)->nid)
10262 +#define nx_current_nid() nx_task_nid(current)
10264 +#define current_nx_info() (current->nx_info)
10267 +/* generic flag merging */
10269 +#define vs_check_flags(v, m, f) (((v) & (m)) ^ (f))
10271 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10273 +#define vs_mask_mask(v, f, m) (((v) & ~(m)) | ((v) & (f) & (m)))
10275 +#define vs_check_bit(v, n) ((v) & (1LL << (n)))
10278 +/* context flags */
10280 +#define __vx_flags(v) ((v) ? (v)->vx_flags : 0)
10282 +#define vx_current_flags() __vx_flags(current_vx_info())
10284 +#define vx_info_flags(v, m, f) \
10285 + vs_check_flags(__vx_flags(v), m, f)
10287 +#define task_vx_flags(t, m, f) \
10288 + ((t) && vx_info_flags((t)->vx_info, m, f))
10290 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10293 +/* context caps */
10295 +#define __vx_ccaps(v) ((v) ? (v)->vx_ccaps : 0)
10297 +#define vx_current_ccaps() __vx_ccaps(current_vx_info())
10299 +#define vx_info_ccaps(v, c) (__vx_ccaps(v) & (c))
10301 +#define vx_ccaps(c) vx_info_ccaps(current_vx_info(), (c))
10305 +/* network flags */
10307 +#define __nx_flags(n) ((n) ? (n)->nx_flags : 0)
10309 +#define nx_current_flags() __nx_flags(current_nx_info())
10311 +#define nx_info_flags(n, m, f) \
10312 + vs_check_flags(__nx_flags(n), m, f)
10314 +#define task_nx_flags(t, m, f) \
10315 + ((t) && nx_info_flags((t)->nx_info, m, f))
10317 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10320 +/* network caps */
10322 +#define __nx_ncaps(n) ((n) ? (n)->nx_ncaps : 0)
10324 +#define nx_current_ncaps() __nx_ncaps(current_nx_info())
10326 +#define nx_info_ncaps(n, c) (__nx_ncaps(n) & (c))
10328 +#define nx_ncaps(c) nx_info_ncaps(current_nx_info(), c)
10331 +/* context mask capabilities */
10333 +#define __vx_mcaps(v) ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10335 +#define vx_info_mcaps(v, c) (__vx_mcaps(v) & (c))
10337 +#define vx_mcaps(c) vx_info_mcaps(current_vx_info(), c)
10340 +/* context bcap mask */
10342 +#define __vx_bcaps(v) ((v)->vx_bcaps)
10344 +#define vx_current_bcaps() __vx_bcaps(current_vx_info())
10347 +/* mask given bcaps */
10349 +#define vx_info_mbcaps(v, c) ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10351 +#define vx_mbcaps(c) vx_info_mbcaps(current_vx_info(), c)
10354 +/* masked cap_bset */
10356 +#define vx_info_cap_bset(v) vx_info_mbcaps(v, current->cap_bset)
10358 +#define vx_current_cap_bset() vx_info_cap_bset(current_vx_info())
10361 +#define vx_info_mbcap(v, b) \
10362 + (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10363 + vx_info_bcaps(v, b) : (b))
10365 +#define task_vx_mbcap(t, b) \
10366 + vx_info_mbcap((t)->vx_info, (t)->b)
10368 +#define vx_mbcap(b) task_vx_mbcap(current, b)
10371 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10373 +#define vx_capable(b, c) (capable(b) || \
10374 + (cap_raised(current_cap(), b) && vx_ccaps(c)))
10376 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10377 + (cap_raised(current_cap(), b) && vx_ccaps(c)))
10379 +#define nx_capable(b, c) (capable(b) || \
10380 + (cap_raised(current_cap(), b) && nx_ncaps(c)))
10382 +#define vx_task_initpid(t, n) \
10383 + ((t)->vx_info && \
10384 + ((t)->vx_info->vx_initpid == (n)))
10386 +#define vx_current_initpid(n) vx_task_initpid(current, n)
10389 +/* context unshare mask */
10391 +#define __vx_umask(v) ((v)->vx_umask)
10393 +#define vx_current_umask() __vx_umask(current_vx_info())
10395 +#define vx_can_unshare(b, f) (capable(b) || \
10396 + (cap_raised(current_cap(), b) && \
10397 + !((f) & ~vx_current_umask())))
10399 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
10400 + (cap_raised(current_cap(), b) && \
10401 + !((f) & ~vx_current_umask())))
10403 +#define __vx_wmask(v) ((v)->vx_wmask)
10405 +#define vx_current_wmask() __vx_wmask(current_vx_info())
10408 +#define __vx_state(v) ((v) ? ((v)->vx_state) : 0)
10410 +#define vx_info_state(v, m) (__vx_state(v) & (m))
10413 +#define __nx_state(n) ((n) ? ((n)->nx_state) : 0)
10415 +#define nx_info_state(n, m) (__nx_state(n) & (m))
10418 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct.h
10419 --- linux-3.9.4/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
10420 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct.h 2013-05-31 14:47:11.000000000 +0000
10422 +#ifndef _VSERVER_CACCT_H
10423 +#define _VSERVER_CACCT_H
10426 +enum sock_acc_field {
10427 + VXA_SOCK_UNSPEC = 0,
10433 + VXA_SOCK_SIZE /* array size */
10436 +#endif /* _VSERVER_CACCT_H */
10437 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct_cmd.h
10438 --- linux-3.9.4/include/linux/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
10439 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct_cmd.h 2013-05-31 14:47:11.000000000 +0000
10441 +#ifndef _VSERVER_CACCT_CMD_H
10442 +#define _VSERVER_CACCT_CMD_H
10445 +#include <linux/compiler.h>
10446 +#include <uapi/vserver/cacct_cmd.h>
10448 +extern int vc_sock_stat(struct vx_info *, void __user *);
10450 +#endif /* _VSERVER_CACCT_CMD_H */
10451 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_def.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct_def.h
10452 --- linux-3.9.4/include/linux/vserver/cacct_def.h 1970-01-01 00:00:00.000000000 +0000
10453 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct_def.h 2013-05-31 14:47:11.000000000 +0000
10455 +#ifndef _VSERVER_CACCT_DEF_H
10456 +#define _VSERVER_CACCT_DEF_H
10458 +#include <asm/atomic.h>
10459 +#include <linux/vserver/cacct.h>
10462 +struct _vx_sock_acc {
10463 + atomic_long_t count;
10464 + atomic_long_t total;
10467 +/* context sub struct */
10469 +struct _vx_cacct {
10470 + struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10471 + atomic_t slab[8];
10472 + atomic_t page[6][8];
10475 +#ifdef CONFIG_VSERVER_DEBUG
10477 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10481 + printk("\t_vx_cacct:");
10482 + for (i = 0; i < 6; i++) {
10483 + struct _vx_sock_acc *ptr = cacct->sock[i];
10485 + printk("\t [%d] =", i);
10486 + for (j = 0; j < 3; j++) {
10487 + printk(" [%d] = %8lu, %8lu", j,
10488 + atomic_long_read(&ptr[j].count),
10489 + atomic_long_read(&ptr[j].total));
10497 +#endif /* _VSERVER_CACCT_DEF_H */
10498 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_int.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct_int.h
10499 --- linux-3.9.4/include/linux/vserver/cacct_int.h 1970-01-01 00:00:00.000000000 +0000
10500 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/cacct_int.h 2013-05-31 14:47:11.000000000 +0000
10502 +#ifndef _VSERVER_CACCT_INT_H
10503 +#define _VSERVER_CACCT_INT_H
10506 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10508 + return atomic_long_read(&cacct->sock[type][pos].count);
10513 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10515 + return atomic_long_read(&cacct->sock[type][pos].total);
10518 +#endif /* _VSERVER_CACCT_INT_H */
10519 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/check.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/check.h
10520 --- linux-3.9.4/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
10521 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/check.h 2013-05-31 14:47:11.000000000 +0000
10523 +#ifndef _VSERVER_CHECK_H
10524 +#define _VSERVER_CHECK_H
10527 +#define MAX_S_CONTEXT 65535 /* Arbitrary limit */
10529 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10530 +#define MIN_D_CONTEXT 49152 /* dynamic contexts start here */
10532 +#define MIN_D_CONTEXT 65536
10535 +/* check conditions */
10537 +#define VS_ADMIN 0x0001
10538 +#define VS_WATCH 0x0002
10539 +#define VS_HIDE 0x0004
10540 +#define VS_HOSTID 0x0008
10542 +#define VS_IDENT 0x0010
10543 +#define VS_EQUIV 0x0020
10544 +#define VS_PARENT 0x0040
10545 +#define VS_CHILD 0x0080
10547 +#define VS_ARG_MASK 0x00F0
10549 +#define VS_DYNAMIC 0x0100
10550 +#define VS_STATIC 0x0200
10552 +#define VS_ATR_MASK 0x0F00
10554 +#ifdef CONFIG_VSERVER_PRIVACY
10555 +#define VS_ADMIN_P (0)
10556 +#define VS_WATCH_P (0)
10558 +#define VS_ADMIN_P VS_ADMIN
10559 +#define VS_WATCH_P VS_WATCH
10562 +#define VS_HARDIRQ 0x1000
10563 +#define VS_SOFTIRQ 0x2000
10564 +#define VS_IRQ 0x4000
10566 +#define VS_IRQ_MASK 0xF000
10568 +#include <linux/hardirq.h>
10571 + * check current context for ADMIN/WATCH and
10572 + * optionally against supplied argument
10574 +static inline int __vs_check(int cid, int id, unsigned int mode)
10576 + if (mode & VS_ARG_MASK) {
10577 + if ((mode & VS_IDENT) && (id == cid))
10580 + if (mode & VS_ATR_MASK) {
10581 + if ((mode & VS_DYNAMIC) &&
10582 + (id >= MIN_D_CONTEXT) &&
10583 + (id <= MAX_S_CONTEXT))
10585 + if ((mode & VS_STATIC) &&
10586 + (id > 1) && (id < MIN_D_CONTEXT))
10589 + if (mode & VS_IRQ_MASK) {
10590 + if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10592 + if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10594 + if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10597 + return (((mode & VS_ADMIN) && (cid == 0)) ||
10598 + ((mode & VS_WATCH) && (cid == 1)) ||
10599 + ((mode & VS_HOSTID) && (id == 0)));
10602 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10604 +#define vx_weak_check(c, m) ((m) ? vx_check(c, m) : 1)
10607 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10609 +#define nx_weak_check(c, m) ((m) ? nx_check(c, m) : 1)
10612 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/context.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/context.h
10613 --- linux-3.9.4/include/linux/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
10614 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/context.h 2013-05-31 14:47:11.000000000 +0000
10616 +#ifndef _VSERVER_CONTEXT_H
10617 +#define _VSERVER_CONTEXT_H
10620 +#include <linux/list.h>
10621 +#include <linux/spinlock.h>
10622 +#include <linux/rcupdate.h>
10623 +#include <uapi/vserver/context.h>
10625 +#include "limit_def.h"
10626 +#include "sched_def.h"
10627 +#include "cvirt_def.h"
10628 +#include "cacct_def.h"
10629 +#include "device_def.h"
10631 +#define VX_SPACES 2
10633 +struct _vx_info_pc {
10634 + struct _vx_sched_pc sched_pc;
10635 + struct _vx_cvirt_pc cvirt_pc;
10638 +struct _vx_space {
10639 + unsigned long vx_nsmask; /* assignment mask */
10640 + struct nsproxy *vx_nsproxy; /* private namespaces */
10641 + struct fs_struct *vx_fs; /* private namespace fs */
10642 + const struct cred *vx_cred; /* task credentials */
10646 + struct hlist_node vx_hlist; /* linked list of contexts */
10647 + xid_t vx_id; /* context id */
10648 + atomic_t vx_usecnt; /* usage count */
10649 + atomic_t vx_tasks; /* tasks count */
10650 + struct vx_info *vx_parent; /* parent context */
10651 + int vx_state; /* context state */
10653 + struct _vx_space space[VX_SPACES]; /* namespace store */
10655 + uint64_t vx_flags; /* context flags */
10656 + uint64_t vx_ccaps; /* context caps (vserver) */
10657 + uint64_t vx_umask; /* unshare mask (guest) */
10658 + uint64_t vx_wmask; /* warn mask (guest) */
10659 + kernel_cap_t vx_bcaps; /* bounding caps (system) */
10661 + struct task_struct *vx_reaper; /* guest reaper process */
10662 + pid_t vx_initpid; /* PID of guest init */
10663 + int64_t vx_badness_bias; /* OOM points bias */
10665 + struct _vx_limit limit; /* vserver limits */
10666 + struct _vx_sched sched; /* vserver scheduler */
10667 + struct _vx_cvirt cvirt; /* virtual/bias stuff */
10668 + struct _vx_cacct cacct; /* context accounting */
10670 + struct _vx_device dmap; /* default device map targets */
10672 +#ifndef CONFIG_SMP
10673 + struct _vx_info_pc info_pc; /* per cpu data */
10675 + struct _vx_info_pc *ptr_pc; /* per cpu array */
10678 + wait_queue_head_t vx_wait; /* context exit waitqueue */
10679 + int reboot_cmd; /* last sys_reboot() cmd */
10680 + int exit_code; /* last process exit code */
10682 + char vx_name[65]; /* vserver name */
10685 +#ifndef CONFIG_SMP
10686 +#define vx_ptr_pc(vxi) (&(vxi)->info_pc)
10687 +#define vx_per_cpu(vxi, v, id) vx_ptr_pc(vxi)->v
10689 +#define vx_ptr_pc(vxi) ((vxi)->ptr_pc)
10690 +#define vx_per_cpu(vxi, v, id) per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10693 +#define vx_cpu(vxi, v) vx_per_cpu(vxi, v, smp_processor_id())
10696 +struct vx_info_save {
10697 + struct vx_info *vxi;
10702 +/* status flags */
10704 +#define VXS_HASHED 0x0001
10705 +#define VXS_PAUSED 0x0010
10706 +#define VXS_SHUTDOWN 0x0100
10707 +#define VXS_HELPER 0x1000
10708 +#define VXS_RELEASED 0x8000
10711 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10712 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10714 +extern struct vx_info *lookup_vx_info(int);
10715 +extern struct vx_info *lookup_or_create_vx_info(int);
10717 +extern int get_xid_list(int, unsigned int *, int);
10718 +extern int xid_is_hashed(xid_t);
10720 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10722 +extern long vs_state_change(struct vx_info *, unsigned int);
10725 +#endif /* _VSERVER_CONTEXT_H */
10726 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/context_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/context_cmd.h
10727 --- linux-3.9.4/include/linux/vserver/context_cmd.h 1970-01-01 00:00:00.000000000 +0000
10728 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/context_cmd.h 2013-05-31 14:47:11.000000000 +0000
10730 +#ifndef _VSERVER_CONTEXT_CMD_H
10731 +#define _VSERVER_CONTEXT_CMD_H
10733 +#include <uapi/vserver/context_cmd.h>
10735 +extern int vc_task_xid(uint32_t);
10737 +extern int vc_vx_info(struct vx_info *, void __user *);
10739 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10741 +extern int vc_ctx_create(uint32_t, void __user *);
10742 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10744 +extern int vc_get_cflags(struct vx_info *, void __user *);
10745 +extern int vc_set_cflags(struct vx_info *, void __user *);
10747 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10748 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10750 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10751 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10753 +extern int vc_get_umask(struct vx_info *, void __user *);
10754 +extern int vc_set_umask(struct vx_info *, void __user *);
10756 +extern int vc_get_wmask(struct vx_info *, void __user *);
10757 +extern int vc_set_wmask(struct vx_info *, void __user *);
10759 +extern int vc_get_badness(struct vx_info *, void __user *);
10760 +extern int vc_set_badness(struct vx_info *, void __user *);
10762 +#endif /* _VSERVER_CONTEXT_CMD_H */
10763 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/cvirt.h
10764 --- linux-3.9.4/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
10765 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/cvirt.h 2013-05-31 14:47:11.000000000 +0000
10767 +#ifndef _VSERVER_CVIRT_H
10768 +#define _VSERVER_CVIRT_H
10772 +void vx_vsi_boottime(struct timespec *);
10774 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10779 +void vx_update_load(struct vx_info *);
10782 +int vx_do_syslog(int, char __user *, int);
10784 +#endif /* _VSERVER_CVIRT_H */
10785 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/cvirt_cmd.h
10786 --- linux-3.9.4/include/linux/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
10787 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/cvirt_cmd.h 2013-05-31 14:47:11.000000000 +0000
10789 +#ifndef _VSERVER_CVIRT_CMD_H
10790 +#define _VSERVER_CVIRT_CMD_H
10793 +#include <linux/compiler.h>
10794 +#include <uapi/vserver/cvirt_cmd.h>
10796 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10797 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10799 +extern int vc_virt_stat(struct vx_info *, void __user *);
10801 +#endif /* _VSERVER_CVIRT_CMD_H */
10802 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt_def.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/cvirt_def.h
10803 --- linux-3.9.4/include/linux/vserver/cvirt_def.h 1970-01-01 00:00:00.000000000 +0000
10804 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/cvirt_def.h 2013-05-31 14:47:11.000000000 +0000
10806 +#ifndef _VSERVER_CVIRT_DEF_H
10807 +#define _VSERVER_CVIRT_DEF_H
10809 +#include <linux/jiffies.h>
10810 +#include <linux/spinlock.h>
10811 +#include <linux/wait.h>
10812 +#include <linux/time.h>
10813 +#include <asm/atomic.h>
10816 +struct _vx_usage_stat {
10820 + uint64_t softirq;
10826 +struct _vx_syslog {
10827 + wait_queue_head_t log_wait;
10828 + spinlock_t logbuf_lock; /* lock for the log buffer */
10830 + unsigned long log_start; /* next char to be read by syslog() */
10831 + unsigned long con_start; /* next char to be sent to consoles */
10832 + unsigned long log_end; /* most-recently-written-char + 1 */
10833 + unsigned long logged_chars; /* #chars since last read+clear operation */
10835 + char log_buf[1024];
10839 +/* context sub struct */
10841 +struct _vx_cvirt {
10842 + atomic_t nr_threads; /* number of current threads */
10843 + atomic_t nr_running; /* number of running threads */
10844 + atomic_t nr_uninterruptible; /* number of uninterruptible threads */
10846 + atomic_t nr_onhold; /* processes on hold */
10847 + uint32_t onhold_last; /* jiffies when put on hold */
10849 + struct timespec bias_ts; /* time offset to the host */
10850 + struct timespec bias_idle;
10851 + struct timespec bias_uptime; /* context creation point */
10852 + uint64_t bias_clock; /* offset in clock_t */
10854 + spinlock_t load_lock; /* lock for the load averages */
10855 + atomic_t load_updates; /* nr of load updates done so far */
10856 + uint32_t load_last; /* last time load was calculated */
10857 + uint32_t load[3]; /* load averages 1,5,15 */
10859 + atomic_t total_forks; /* number of forks so far */
10861 + struct _vx_syslog syslog;
10864 +struct _vx_cvirt_pc {
10865 + struct _vx_usage_stat cpustat;
10869 +#ifdef CONFIG_VSERVER_DEBUG
10871 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10873 + printk("\t_vx_cvirt:\n");
10874 + printk("\t threads: %4d, %4d, %4d, %4d\n",
10875 + atomic_read(&cvirt->nr_threads),
10876 + atomic_read(&cvirt->nr_running),
10877 + atomic_read(&cvirt->nr_uninterruptible),
10878 + atomic_read(&cvirt->nr_onhold));
10879 + /* add rest here */
10880 + printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10885 +#endif /* _VSERVER_CVIRT_DEF_H */
10886 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/debug.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/debug.h
10887 --- linux-3.9.4/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
10888 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/debug.h 2013-05-31 14:47:11.000000000 +0000
10890 +#ifndef _VSERVER_DEBUG_H
10891 +#define _VSERVER_DEBUG_H
10894 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10895 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10896 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10898 +#define VXD_DEV(d) (d), (d)->bd_inode->i_ino, \
10899 + imajor((d)->bd_inode), iminor((d)->bd_inode)
10900 +#define VXF_DEV "%p[%lu,%d:%d]"
10902 +#if defined(CONFIG_QUOTES_UTF8)
10903 +#define VS_Q_LQM "\xc2\xbb"
10904 +#define VS_Q_RQM "\xc2\xab"
10905 +#elif defined(CONFIG_QUOTES_ASCII)
10906 +#define VS_Q_LQM "\x27"
10907 +#define VS_Q_RQM "\x27"
10909 +#define VS_Q_LQM "\xbb"
10910 +#define VS_Q_RQM "\xab"
10913 +#define VS_Q(f) VS_Q_LQM f VS_Q_RQM
10916 +#define vxd_path(p) \
10917 + ({ static char _buffer[PATH_MAX]; \
10918 + d_path(p, _buffer, sizeof(_buffer)); })
10920 +#define vxd_cond_path(n) \
10921 + ((n) ? vxd_path(&(n)->path) : "<null>" )
10924 +#ifdef CONFIG_VSERVER_DEBUG
10926 +extern unsigned int vs_debug_switch;
10927 +extern unsigned int vs_debug_xid;
10928 +extern unsigned int vs_debug_nid;
10929 +extern unsigned int vs_debug_tag;
10930 +extern unsigned int vs_debug_net;
10931 +extern unsigned int vs_debug_limit;
10932 +extern unsigned int vs_debug_cres;
10933 +extern unsigned int vs_debug_dlim;
10934 +extern unsigned int vs_debug_quota;
10935 +extern unsigned int vs_debug_cvirt;
10936 +extern unsigned int vs_debug_space;
10937 +extern unsigned int vs_debug_perm;
10938 +extern unsigned int vs_debug_misc;
10941 +#define VX_LOGLEVEL "vxD: "
10942 +#define VX_PROC_FMT "%p: "
10943 +#define VX_PROCESS current
10945 +#define vxdprintk(c, f, x...) \
10948 + printk(VX_LOGLEVEL VX_PROC_FMT f "\n", \
10949 + VX_PROCESS , ##x); \
10952 +#define vxlprintk(c, f, x...) \
10955 + printk(VX_LOGLEVEL f " @%s:%d\n", x); \
10958 +#define vxfprintk(c, f, x...) \
10961 + printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10967 +void dump_vx_info(struct vx_info *, int);
10968 +void dump_vx_info_inactive(int);
10970 +#else /* CONFIG_VSERVER_DEBUG */
10972 +#define vs_debug_switch 0
10973 +#define vs_debug_xid 0
10974 +#define vs_debug_nid 0
10975 +#define vs_debug_tag 0
10976 +#define vs_debug_net 0
10977 +#define vs_debug_limit 0
10978 +#define vs_debug_cres 0
10979 +#define vs_debug_dlim 0
10980 +#define vs_debug_quota 0
10981 +#define vs_debug_cvirt 0
10982 +#define vs_debug_space 0
10983 +#define vs_debug_perm 0
10984 +#define vs_debug_misc 0
10986 +#define vxdprintk(x...) do { } while (0)
10987 +#define vxlprintk(x...) do { } while (0)
10988 +#define vxfprintk(x...) do { } while (0)
10990 +#endif /* CONFIG_VSERVER_DEBUG */
10993 +#ifdef CONFIG_VSERVER_WARN
10995 +#define VX_WARNLEVEL KERN_WARNING "vxW: "
10996 +#define VX_WARN_TASK "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10997 +#define VX_WARN_XID "[xid #%u] "
10998 +#define VX_WARN_NID "[nid #%u] "
10999 +#define VX_WARN_TAG "[tag #%u] "
11001 +#define vxwprintk(c, f, x...) \
11004 + printk(VX_WARNLEVEL f "\n", ##x); \
11007 +#else /* CONFIG_VSERVER_WARN */
11009 +#define vxwprintk(x...) do { } while (0)
11011 +#endif /* CONFIG_VSERVER_WARN */
11013 +#define vxwprintk_task(c, f, x...) \
11014 + vxwprintk(c, VX_WARN_TASK f, \
11015 + current->comm, current->pid, \
11016 + current->xid, current->nid, current->tag, ##x)
11017 +#define vxwprintk_xid(c, f, x...) \
11018 + vxwprintk(c, VX_WARN_XID f, current->xid, x)
11019 +#define vxwprintk_nid(c, f, x...) \
11020 + vxwprintk(c, VX_WARN_NID f, current->nid, x)
11021 +#define vxwprintk_tag(c, f, x...) \
11022 + vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11024 +#ifdef CONFIG_VSERVER_DEBUG
11025 +#define vxd_assert_lock(l) assert_spin_locked(l)
11026 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11027 + "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11029 +#define vxd_assert_lock(l) do { } while (0)
11030 +#define vxd_assert(c, f, x...) do { } while (0)
11034 +#endif /* _VSERVER_DEBUG_H */
11035 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/debug_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/debug_cmd.h
11036 --- linux-3.9.4/include/linux/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
11037 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/debug_cmd.h 2013-05-31 14:47:11.000000000 +0000
11039 +#ifndef _VSERVER_DEBUG_CMD_H
11040 +#define _VSERVER_DEBUG_CMD_H
11042 +#include <uapi/vserver/debug_cmd.h>
11045 +#ifdef CONFIG_COMPAT
11047 +#include <asm/compat.h>
11049 +struct vcmd_read_history_v0_x32 {
11052 + compat_uptr_t data_ptr;
11055 +struct vcmd_read_monitor_v0_x32 {
11058 + compat_uptr_t data_ptr;
11061 +#endif /* CONFIG_COMPAT */
11063 +extern int vc_dump_history(uint32_t);
11065 +extern int vc_read_history(uint32_t, void __user *);
11066 +extern int vc_read_monitor(uint32_t, void __user *);
11068 +#ifdef CONFIG_COMPAT
11070 +extern int vc_read_history_x32(uint32_t, void __user *);
11071 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11073 +#endif /* CONFIG_COMPAT */
11075 +#endif /* _VSERVER_DEBUG_CMD_H */
11076 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/device.h
11077 --- linux-3.9.4/include/linux/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
11078 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/device.h 2013-05-31 14:47:11.000000000 +0000
11080 +#ifndef _VSERVER_DEVICE_H
11081 +#define _VSERVER_DEVICE_H
11084 +#include <uapi/vserver/device.h>
11086 +#else /* _VSERVER_DEVICE_H */
11087 +#warning duplicate inclusion
11088 +#endif /* _VSERVER_DEVICE_H */
11089 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/device_cmd.h
11090 --- linux-3.9.4/include/linux/vserver/device_cmd.h 1970-01-01 00:00:00.000000000 +0000
11091 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/device_cmd.h 2013-05-31 14:47:11.000000000 +0000
11093 +#ifndef _VSERVER_DEVICE_CMD_H
11094 +#define _VSERVER_DEVICE_CMD_H
11096 +#include <uapi/vserver/device_cmd.h>
11099 +#ifdef CONFIG_COMPAT
11101 +#include <asm/compat.h>
11103 +struct vcmd_set_mapping_v0_x32 {
11104 + compat_uptr_t device_ptr;
11105 + compat_uptr_t target_ptr;
11109 +#endif /* CONFIG_COMPAT */
11111 +#include <linux/compiler.h>
11113 +extern int vc_set_mapping(struct vx_info *, void __user *);
11114 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11116 +#ifdef CONFIG_COMPAT
11118 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11119 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11121 +#endif /* CONFIG_COMPAT */
11123 +#endif /* _VSERVER_DEVICE_CMD_H */
11124 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device_def.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/device_def.h
11125 --- linux-3.9.4/include/linux/vserver/device_def.h 1970-01-01 00:00:00.000000000 +0000
11126 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/device_def.h 2013-05-31 14:47:11.000000000 +0000
11128 +#ifndef _VSERVER_DEVICE_DEF_H
11129 +#define _VSERVER_DEVICE_DEF_H
11131 +#include <linux/types.h>
11133 +struct vx_dmap_target {
11138 +struct _vx_device {
11139 +#ifdef CONFIG_VSERVER_DEVICE
11140 + struct vx_dmap_target targets[2];
11144 +#endif /* _VSERVER_DEVICE_DEF_H */
11145 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/dlimit.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/dlimit.h
11146 --- linux-3.9.4/include/linux/vserver/dlimit.h 1970-01-01 00:00:00.000000000 +0000
11147 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/dlimit.h 2013-05-31 14:47:11.000000000 +0000
11149 +#ifndef _VSERVER_DLIMIT_H
11150 +#define _VSERVER_DLIMIT_H
11152 +#include "switch.h"
11157 +/* keep in sync with CDLIM_INFINITY */
11159 +#define DLIM_INFINITY (~0ULL)
11161 +#include <linux/spinlock.h>
11162 +#include <linux/rcupdate.h>
11164 +struct super_block;
11167 + struct hlist_node dl_hlist; /* linked list of contexts */
11168 + struct rcu_head dl_rcu; /* the rcu head */
11169 + tag_t dl_tag; /* context tag */
11170 + atomic_t dl_usecnt; /* usage count */
11171 + atomic_t dl_refcnt; /* reference count */
11173 + struct super_block *dl_sb; /* associated superblock */
11175 + spinlock_t dl_lock; /* protect the values */
11177 + unsigned long long dl_space_used; /* used space in bytes */
11178 + unsigned long long dl_space_total; /* maximum space in bytes */
11179 + unsigned long dl_inodes_used; /* used inodes */
11180 + unsigned long dl_inodes_total; /* maximum inodes */
11182 + unsigned int dl_nrlmult; /* non root limit mult */
11187 +extern void rcu_free_dl_info(struct rcu_head *);
11188 +extern void unhash_dl_info(struct dl_info *);
11190 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11195 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11197 +typedef uint64_t dlsize_t;
11199 +#endif /* __KERNEL__ */
11200 +#else /* _VSERVER_DLIMIT_H */
11201 +#warning duplicate inclusion
11202 +#endif /* _VSERVER_DLIMIT_H */
11203 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/dlimit_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/dlimit_cmd.h
11204 --- linux-3.9.4/include/linux/vserver/dlimit_cmd.h 1970-01-01 00:00:00.000000000 +0000
11205 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/dlimit_cmd.h 2013-05-31 14:47:11.000000000 +0000
11207 +#ifndef _VSERVER_DLIMIT_CMD_H
11208 +#define _VSERVER_DLIMIT_CMD_H
11210 +#include <uapi/vserver/dlimit_cmd.h>
11213 +#ifdef CONFIG_COMPAT
11215 +#include <asm/compat.h>
11217 +struct vcmd_ctx_dlimit_base_v0_x32 {
11218 + compat_uptr_t name_ptr;
11222 +struct vcmd_ctx_dlimit_v0_x32 {
11223 + compat_uptr_t name_ptr;
11224 + uint32_t space_used; /* used space in kbytes */
11225 + uint32_t space_total; /* maximum space in kbytes */
11226 + uint32_t inodes_used; /* used inodes */
11227 + uint32_t inodes_total; /* maximum inodes */
11228 + uint32_t reserved; /* reserved for root in % */
11232 +#endif /* CONFIG_COMPAT */
11234 +#include <linux/compiler.h>
11236 +extern int vc_add_dlimit(uint32_t, void __user *);
11237 +extern int vc_rem_dlimit(uint32_t, void __user *);
11239 +extern int vc_set_dlimit(uint32_t, void __user *);
11240 +extern int vc_get_dlimit(uint32_t, void __user *);
11242 +#ifdef CONFIG_COMPAT
11244 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11245 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11247 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11248 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11250 +#endif /* CONFIG_COMPAT */
11252 +#endif /* _VSERVER_DLIMIT_CMD_H */
11253 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/global.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/global.h
11254 --- linux-3.9.4/include/linux/vserver/global.h 1970-01-01 00:00:00.000000000 +0000
11255 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/global.h 2013-05-31 14:47:11.000000000 +0000
11257 +#ifndef _VSERVER_GLOBAL_H
11258 +#define _VSERVER_GLOBAL_H
11261 +extern atomic_t vx_global_ctotal;
11262 +extern atomic_t vx_global_cactive;
11264 +extern atomic_t nx_global_ctotal;
11265 +extern atomic_t nx_global_cactive;
11267 +extern atomic_t vs_global_nsproxy;
11268 +extern atomic_t vs_global_fs;
11269 +extern atomic_t vs_global_mnt_ns;
11270 +extern atomic_t vs_global_uts_ns;
11271 +extern atomic_t vs_global_user_ns;
11272 +extern atomic_t vs_global_pid_ns;
11275 +#endif /* _VSERVER_GLOBAL_H */
11276 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/history.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/history.h
11277 --- linux-3.9.4/include/linux/vserver/history.h 1970-01-01 00:00:00.000000000 +0000
11278 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/history.h 2013-05-31 14:47:11.000000000 +0000
11280 +#ifndef _VSERVER_HISTORY_H
11281 +#define _VSERVER_HISTORY_H
11286 + VXH_THROW_OOPS = 1,
11290 + VXH_INIT_VX_INFO,
11293 + VXH_CLAIM_VX_INFO,
11294 + VXH_RELEASE_VX_INFO,
11295 + VXH_ALLOC_VX_INFO,
11296 + VXH_DEALLOC_VX_INFO,
11297 + VXH_HASH_VX_INFO,
11298 + VXH_UNHASH_VX_INFO,
11300 + VXH_LOOKUP_VX_INFO,
11301 + VXH_CREATE_VX_INFO,
11304 +struct _vxhe_vxi {
11305 + struct vx_info *ptr;
11311 +struct _vxhe_set_clr {
11315 +struct _vxhe_loc_lookup {
11319 +struct _vx_hist_entry {
11321 + unsigned short seq;
11322 + unsigned short type;
11323 + struct _vxhe_vxi vxi;
11325 + struct _vxhe_set_clr sc;
11326 + struct _vxhe_loc_lookup ll;
11330 +#ifdef CONFIG_VSERVER_HISTORY
11332 +extern unsigned volatile int vxh_active;
11334 +struct _vx_hist_entry *vxh_advance(void *loc);
11338 +void __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11340 + entry->vxi.ptr = vxi;
11342 + entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11343 + entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11344 + entry->vxi.xid = vxi->vx_id;
11349 +#define __HERE__ current_text_addr()
11351 +#define __VXH_BODY(__type, __data, __here) \
11352 + struct _vx_hist_entry *entry; \
11354 + preempt_disable(); \
11355 + entry = vxh_advance(__here); \
11357 + entry->type = __type; \
11358 + preempt_enable();
11361 + /* pass vxi only */
11363 +#define __VXH_SMPL \
11364 + __vxh_copy_vxi(entry, vxi)
11367 +void __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11369 + __VXH_BODY(__type, __VXH_SMPL, __here)
11372 + /* pass vxi and data (void *) */
11374 +#define __VXH_DATA \
11375 + __vxh_copy_vxi(entry, vxi); \
11376 + entry->sc.data = data
11379 +void __vxh_data(struct vx_info *vxi, void *data,
11380 + int __type, void *__here)
11382 + __VXH_BODY(__type, __VXH_DATA, __here)
11385 + /* pass vxi and arg (long) */
11387 +#define __VXH_LONG \
11388 + __vxh_copy_vxi(entry, vxi); \
11389 + entry->ll.arg = arg
11392 +void __vxh_long(struct vx_info *vxi, long arg,
11393 + int __type, void *__here)
11395 + __VXH_BODY(__type, __VXH_LONG, __here)
11400 +void __vxh_throw_oops(void *__here)
11402 + __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11403 + /* prevent further acquisition */
11408 +#define vxh_throw_oops() __vxh_throw_oops(__HERE__);
11410 +#define __vxh_get_vx_info(v, h) __vxh_smpl(v, VXH_GET_VX_INFO, h);
11411 +#define __vxh_put_vx_info(v, h) __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11413 +#define __vxh_init_vx_info(v, d, h) \
11414 + __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11415 +#define __vxh_set_vx_info(v, d, h) \
11416 + __vxh_data(v, d, VXH_SET_VX_INFO, h);
11417 +#define __vxh_clr_vx_info(v, d, h) \
11418 + __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11420 +#define __vxh_claim_vx_info(v, d, h) \
11421 + __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11422 +#define __vxh_release_vx_info(v, d, h) \
11423 + __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11425 +#define vxh_alloc_vx_info(v) \
11426 + __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11427 +#define vxh_dealloc_vx_info(v) \
11428 + __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11430 +#define vxh_hash_vx_info(v) \
11431 + __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11432 +#define vxh_unhash_vx_info(v) \
11433 + __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11435 +#define vxh_loc_vx_info(v, l) \
11436 + __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11437 +#define vxh_lookup_vx_info(v, l) \
11438 + __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11439 +#define vxh_create_vx_info(v, l) \
11440 + __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11442 +extern void vxh_dump_history(void);
11445 +#else /* CONFIG_VSERVER_HISTORY */
11447 +#define __HERE__ 0
11449 +#define vxh_throw_oops() do { } while (0)
11451 +#define __vxh_get_vx_info(v, h) do { } while (0)
11452 +#define __vxh_put_vx_info(v, h) do { } while (0)
11454 +#define __vxh_init_vx_info(v, d, h) do { } while (0)
11455 +#define __vxh_set_vx_info(v, d, h) do { } while (0)
11456 +#define __vxh_clr_vx_info(v, d, h) do { } while (0)
11458 +#define __vxh_claim_vx_info(v, d, h) do { } while (0)
11459 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11461 +#define vxh_alloc_vx_info(v) do { } while (0)
11462 +#define vxh_dealloc_vx_info(v) do { } while (0)
11464 +#define vxh_hash_vx_info(v) do { } while (0)
11465 +#define vxh_unhash_vx_info(v) do { } while (0)
11467 +#define vxh_loc_vx_info(v, l) do { } while (0)
11468 +#define vxh_lookup_vx_info(v, l) do { } while (0)
11469 +#define vxh_create_vx_info(v, l) do { } while (0)
11471 +#define vxh_dump_history() do { } while (0)
11474 +#endif /* CONFIG_VSERVER_HISTORY */
11476 +#endif /* _VSERVER_HISTORY_H */
11477 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/inode.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/inode.h
11478 --- linux-3.9.4/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
11479 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/inode.h 2013-05-31 14:47:11.000000000 +0000
11481 +#ifndef _VSERVER_INODE_H
11482 +#define _VSERVER_INODE_H
11484 +#include <uapi/vserver/inode.h>
11487 +#ifdef CONFIG_VSERVER_PROC_SECURE
11488 +#define IATTR_PROC_DEFAULT ( IATTR_ADMIN | IATTR_HIDE )
11489 +#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
11491 +#define IATTR_PROC_DEFAULT ( IATTR_ADMIN )
11492 +#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
11495 +#define vx_hide_check(c, m) (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11497 +#else /* _VSERVER_INODE_H */
11498 +#warning duplicate inclusion
11499 +#endif /* _VSERVER_INODE_H */
11500 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/inode_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/inode_cmd.h
11501 --- linux-3.9.4/include/linux/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
11502 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/inode_cmd.h 2013-05-31 14:47:11.000000000 +0000
11504 +#ifndef _VSERVER_INODE_CMD_H
11505 +#define _VSERVER_INODE_CMD_H
11507 +#include <uapi/vserver/inode_cmd.h>
11511 +#ifdef CONFIG_COMPAT
11513 +#include <asm/compat.h>
11515 +struct vcmd_ctx_iattr_v1_x32 {
11516 + compat_uptr_t name_ptr;
11522 +#endif /* CONFIG_COMPAT */
11524 +#include <linux/compiler.h>
11526 +extern int vc_get_iattr(void __user *);
11527 +extern int vc_set_iattr(void __user *);
11529 +extern int vc_fget_iattr(uint32_t, void __user *);
11530 +extern int vc_fset_iattr(uint32_t, void __user *);
11532 +#ifdef CONFIG_COMPAT
11534 +extern int vc_get_iattr_x32(void __user *);
11535 +extern int vc_set_iattr_x32(void __user *);
11537 +#endif /* CONFIG_COMPAT */
11539 +#endif /* _VSERVER_INODE_CMD_H */
11540 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit.h
11541 --- linux-3.9.4/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
11542 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit.h 2013-05-31 14:47:11.000000000 +0000
11544 +#ifndef _VSERVER_LIMIT_H
11545 +#define _VSERVER_LIMIT_H
11547 +#include <uapi/vserver/limit.h>
11550 +#define VLIM_NOCHECK ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11552 +/* keep in sync with CRLIM_INFINITY */
11554 +#define VLIM_INFINITY (~0ULL)
11556 +#include <asm/atomic.h>
11557 +#include <asm/resource.h>
11559 +#ifndef RLIM_INFINITY
11560 +#warning RLIM_INFINITY is undefined
11563 +#define __rlim_val(l, r, v) ((l)->res[r].v)
11565 +#define __rlim_soft(l, r) __rlim_val(l, r, soft)
11566 +#define __rlim_hard(l, r) __rlim_val(l, r, hard)
11568 +#define __rlim_rcur(l, r) __rlim_val(l, r, rcur)
11569 +#define __rlim_rmin(l, r) __rlim_val(l, r, rmin)
11570 +#define __rlim_rmax(l, r) __rlim_val(l, r, rmax)
11572 +#define __rlim_lhit(l, r) __rlim_val(l, r, lhit)
11573 +#define __rlim_hit(l, r) atomic_inc(&__rlim_lhit(l, r))
11575 +typedef atomic_long_t rlim_atomic_t;
11576 +typedef unsigned long rlim_t;
11578 +#define __rlim_get(l, r) atomic_long_read(&__rlim_rcur(l, r))
11579 +#define __rlim_set(l, r, v) atomic_long_set(&__rlim_rcur(l, r), v)
11580 +#define __rlim_inc(l, r) atomic_long_inc(&__rlim_rcur(l, r))
11581 +#define __rlim_dec(l, r) atomic_long_dec(&__rlim_rcur(l, r))
11582 +#define __rlim_add(l, r, v) atomic_long_add(v, &__rlim_rcur(l, r))
11583 +#define __rlim_sub(l, r, v) atomic_long_sub(v, &__rlim_rcur(l, r))
11586 +#if (RLIM_INFINITY == VLIM_INFINITY)
11587 +#define VX_VLIM(r) ((long long)(long)(r))
11588 +#define VX_RLIM(v) ((rlim_t)(v))
11590 +#define VX_VLIM(r) (((r) == RLIM_INFINITY) \
11591 + ? VLIM_INFINITY : (long long)(r))
11592 +#define VX_RLIM(v) (((v) == VLIM_INFINITY) \
11593 + ? RLIM_INFINITY : (rlim_t)(v))
11598 +void vx_vsi_meminfo(struct sysinfo *);
11599 +void vx_vsi_swapinfo(struct sysinfo *);
11600 +long vx_vsi_cached(struct sysinfo *);
11602 +#define NUM_LIMITS 24
11604 +#endif /* _VSERVER_LIMIT_H */
11605 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit_cmd.h
11606 --- linux-3.9.4/include/linux/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
11607 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit_cmd.h 2013-05-31 14:47:11.000000000 +0000
11609 +#ifndef _VSERVER_LIMIT_CMD_H
11610 +#define _VSERVER_LIMIT_CMD_H
11612 +#include <uapi/vserver/limit_cmd.h>
11615 +#ifdef CONFIG_IA32_EMULATION
11617 +struct vcmd_ctx_rlimit_v0_x32 {
11619 + uint64_t minimum;
11620 + uint64_t softlimit;
11621 + uint64_t maximum;
11622 +} __attribute__ ((packed));
11624 +#endif /* CONFIG_IA32_EMULATION */
11626 +#include <linux/compiler.h>
11628 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11629 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11630 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11631 +extern int vc_reset_hits(struct vx_info *, void __user *);
11632 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11634 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11636 +#ifdef CONFIG_IA32_EMULATION
11638 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11639 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11641 +#endif /* CONFIG_IA32_EMULATION */
11643 +#endif /* _VSERVER_LIMIT_CMD_H */
11644 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_def.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit_def.h
11645 --- linux-3.9.4/include/linux/vserver/limit_def.h 1970-01-01 00:00:00.000000000 +0000
11646 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit_def.h 2013-05-31 14:47:11.000000000 +0000
11648 +#ifndef _VSERVER_LIMIT_DEF_H
11649 +#define _VSERVER_LIMIT_DEF_H
11651 +#include <asm/atomic.h>
11652 +#include <asm/resource.h>
11654 +#include "limit.h"
11657 +struct _vx_res_limit {
11658 + rlim_t soft; /* Context soft limit */
11659 + rlim_t hard; /* Context hard limit */
11661 + rlim_atomic_t rcur; /* Current value */
11662 + rlim_t rmin; /* Context minimum */
11663 + rlim_t rmax; /* Context maximum */
11665 + atomic_t lhit; /* Limit hits */
11668 +/* context sub struct */
11670 +struct _vx_limit {
11671 + struct _vx_res_limit res[NUM_LIMITS];
11674 +#ifdef CONFIG_VSERVER_DEBUG
11676 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11680 + printk("\t_vx_limit:");
11681 + for (i = 0; i < NUM_LIMITS; i++) {
11682 + printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11683 + i, (unsigned long)__rlim_get(limit, i),
11684 + (unsigned long)__rlim_rmin(limit, i),
11685 + (unsigned long)__rlim_rmax(limit, i),
11686 + (long)__rlim_soft(limit, i),
11687 + (long)__rlim_hard(limit, i),
11688 + atomic_read(&__rlim_lhit(limit, i)));
11694 +#endif /* _VSERVER_LIMIT_DEF_H */
11695 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_int.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit_int.h
11696 --- linux-3.9.4/include/linux/vserver/limit_int.h 1970-01-01 00:00:00.000000000 +0000
11697 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/limit_int.h 2013-05-31 14:47:11.000000000 +0000
11699 +#ifndef _VSERVER_LIMIT_INT_H
11700 +#define _VSERVER_LIMIT_INT_H
11702 +#define VXD_RCRES_COND(r) VXD_CBIT(cres, r)
11703 +#define VXD_RLIMIT_COND(r) VXD_CBIT(limit, r)
11705 +extern const char *vlimit_name[NUM_LIMITS];
11707 +static inline void __vx_acc_cres(struct vx_info *vxi,
11708 + int res, int dir, void *_data, char *_file, int _line)
11710 + if (VXD_RCRES_COND(res))
11711 + vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11712 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11713 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11714 + (dir > 0) ? "++" : "--", _data, _file, _line);
11719 + __rlim_inc(&vxi->limit, res);
11721 + __rlim_dec(&vxi->limit, res);
11724 +static inline void __vx_add_cres(struct vx_info *vxi,
11725 + int res, int amount, void *_data, char *_file, int _line)
11727 + if (VXD_RCRES_COND(res))
11728 + vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11729 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11730 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11731 + amount, _data, _file, _line);
11736 + __rlim_add(&vxi->limit, res, amount);
11740 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11742 + int cond = (value > __rlim_rmax(limit, res));
11745 + __rlim_rmax(limit, res) = value;
11750 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11752 + int cond = (value < __rlim_rmin(limit, res));
11755 + __rlim_rmin(limit, res) = value;
11760 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11762 + if (!__vx_cres_adjust_max(limit, res, value))
11763 + __vx_cres_adjust_min(limit, res, value);
11768 + +1 ... no limit hit
11769 + -1 ... over soft limit
11770 + 0 ... over hard limit */
11772 +static inline int __vx_cres_avail(struct vx_info *vxi,
11773 + int res, int num, char *_file, int _line)
11775 + struct _vx_limit *limit;
11778 + if (VXD_RLIMIT_COND(res))
11779 + vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11780 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11781 + (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11782 + (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11783 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11784 + num, _file, _line);
11788 + limit = &vxi->limit;
11789 + value = __rlim_get(limit, res);
11791 + if (!__vx_cres_adjust_max(limit, res, value))
11792 + __vx_cres_adjust_min(limit, res, value);
11797 + if (__rlim_soft(limit, res) == RLIM_INFINITY)
11799 + if (value + num <= __rlim_soft(limit, res))
11802 + if (__rlim_hard(limit, res) == RLIM_INFINITY)
11804 + if (value + num <= __rlim_hard(limit, res))
11807 + __rlim_hit(limit, res);
11812 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11815 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11817 + rlim_t value, sum = 0;
11820 + while ((res = *array++)) {
11821 + value = __rlim_get(limit, res);
11822 + __vx_cres_fixup(limit, res, value);
11829 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11831 + rlim_t value = __vx_cres_array_sum(limit, array + 1);
11832 + int res = *array;
11834 + if (value == __rlim_get(limit, res))
11837 + __rlim_set(limit, res, value);
11838 + /* now adjust min/max */
11839 + if (!__vx_cres_adjust_max(limit, res, value))
11840 + __vx_cres_adjust_min(limit, res, value);
11845 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11846 + const int *array, int num, char *_file, int _line)
11848 + struct _vx_limit *limit;
11849 + rlim_t value = 0;
11857 + limit = &vxi->limit;
11859 + value = __vx_cres_array_sum(limit, array + 1);
11861 + __rlim_set(limit, res, value);
11862 + __vx_cres_fixup(limit, res, value);
11864 + return __vx_cres_avail(vxi, res, num, _file, _line);
11868 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11873 + /* complex resources first */
11874 + if ((id < 0) || (id == RLIMIT_RSS))
11875 + __vx_cres_array_fixup(limit, VLA_RSS);
11877 + for (res = 0; res < NUM_LIMITS; res++) {
11878 + if ((id > 0) && (res != id))
11881 + value = __rlim_get(limit, res);
11882 + __vx_cres_fixup(limit, res, value);
11884 + /* not supposed to happen, maybe warn? */
11885 + if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11886 + __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11891 +#endif /* _VSERVER_LIMIT_INT_H */
11892 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/monitor.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/monitor.h
11893 --- linux-3.9.4/include/linux/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
11894 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/monitor.h 2013-05-31 14:47:11.000000000 +0000
11896 +#ifndef _VSERVER_MONITOR_H
11897 +#define _VSERVER_MONITOR_H
11899 +#include <uapi/vserver/monitor.h>
11901 +#endif /* _VSERVER_MONITOR_H */
11902 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/network.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/network.h
11903 --- linux-3.9.4/include/linux/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
11904 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/network.h 2013-05-31 14:47:11.000000000 +0000
11906 +#ifndef _VSERVER_NETWORK_H
11907 +#define _VSERVER_NETWORK_H
11910 +#include <linux/list.h>
11911 +#include <linux/spinlock.h>
11912 +#include <linux/rcupdate.h>
11913 +#include <linux/in.h>
11914 +#include <linux/in6.h>
11915 +#include <asm/atomic.h>
11916 +#include <uapi/vserver/network.h>
11918 +struct nx_addr_v4 {
11919 + struct nx_addr_v4 *next;
11920 + struct in_addr ip[2];
11921 + struct in_addr mask;
11926 +struct nx_addr_v6 {
11927 + struct nx_addr_v6 *next;
11928 + struct in6_addr ip;
11929 + struct in6_addr mask;
11936 + struct hlist_node nx_hlist; /* linked list of nxinfos */
11937 + nid_t nx_id; /* vnet id */
11938 + atomic_t nx_usecnt; /* usage count */
11939 + atomic_t nx_tasks; /* tasks count */
11940 + int nx_state; /* context state */
11942 + uint64_t nx_flags; /* network flag word */
11943 + uint64_t nx_ncaps; /* network capabilities */
11945 + spinlock_t addr_lock; /* protect address changes */
11946 + struct in_addr v4_lback; /* Loopback address */
11947 + struct in_addr v4_bcast; /* Broadcast address */
11948 + struct nx_addr_v4 v4; /* First/Single ipv4 address */
11949 +#ifdef CONFIG_IPV6
11950 + struct nx_addr_v6 v6; /* First/Single ipv6 address */
11952 + char nx_name[65]; /* network context name */
11956 +/* status flags */
11958 +#define NXS_HASHED 0x0001
11959 +#define NXS_SHUTDOWN 0x0100
11960 +#define NXS_RELEASED 0x8000
11962 +extern struct nx_info *lookup_nx_info(int);
11964 +extern int get_nid_list(int, unsigned int *, int);
11965 +extern int nid_is_hashed(nid_t);
11967 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11969 +extern long vs_net_change(struct nx_info *, unsigned int);
11974 +#define NX_IPV4(n) ((n)->v4.type != NXA_TYPE_NONE)
11975 +#ifdef CONFIG_IPV6
11976 +#define NX_IPV6(n) ((n)->v6.type != NXA_TYPE_NONE)
11978 +#define NX_IPV6(n) (0)
11981 +#endif /* _VSERVER_NETWORK_H */
11982 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/network_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/network_cmd.h
11983 --- linux-3.9.4/include/linux/vserver/network_cmd.h 1970-01-01 00:00:00.000000000 +0000
11984 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/network_cmd.h 2013-05-31 14:47:11.000000000 +0000
11986 +#ifndef _VSERVER_NETWORK_CMD_H
11987 +#define _VSERVER_NETWORK_CMD_H
11989 +#include <uapi/vserver/network_cmd.h>
11991 +extern int vc_task_nid(uint32_t);
11993 +extern int vc_nx_info(struct nx_info *, void __user *);
11995 +extern int vc_net_create(uint32_t, void __user *);
11996 +extern int vc_net_migrate(struct nx_info *, void __user *);
11998 +extern int vc_net_add(struct nx_info *, void __user *);
11999 +extern int vc_net_remove(struct nx_info *, void __user *);
12001 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
12002 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12004 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
12005 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
12007 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12008 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12010 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12011 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12013 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12014 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12016 +extern int vc_get_nflags(struct nx_info *, void __user *);
12017 +extern int vc_set_nflags(struct nx_info *, void __user *);
12019 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12020 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12022 +#endif /* _VSERVER_CONTEXT_CMD_H */
12023 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/percpu.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/percpu.h
12024 --- linux-3.9.4/include/linux/vserver/percpu.h 1970-01-01 00:00:00.000000000 +0000
12025 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/percpu.h 2013-05-31 14:47:11.000000000 +0000
12027 +#ifndef _VSERVER_PERCPU_H
12028 +#define _VSERVER_PERCPU_H
12030 +#include "cvirt_def.h"
12031 +#include "sched_def.h"
12033 +struct _vx_percpu {
12034 + struct _vx_cvirt_pc cvirt;
12035 + struct _vx_sched_pc sched;
12038 +#define PERCPU_PERCTX (sizeof(struct _vx_percpu))
12040 +#endif /* _VSERVER_PERCPU_H */
12041 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/pid.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/pid.h
12042 --- linux-3.9.4/include/linux/vserver/pid.h 1970-01-01 00:00:00.000000000 +0000
12043 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/pid.h 2013-05-31 14:47:11.000000000 +0000
12045 +#ifndef _VSERVER_PID_H
12046 +#define _VSERVER_PID_H
12048 +/* pid faking stuff */
12050 +#define vx_info_map_pid(v, p) \
12051 + __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12052 +#define vx_info_map_tgid(v,p) vx_info_map_pid(v,p)
12053 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12054 +#define vx_map_tgid(p) vx_map_pid(p)
12056 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12057 + const char *func, const char *file, int line)
12059 + if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12060 + vxfprintk(VXD_CBIT(cvirt, 2),
12061 + "vx_map_tgid: %p/%llx: %d -> %d",
12062 + vxi, (long long)vxi->vx_flags, pid,
12063 + (pid && pid == vxi->vx_initpid) ? 1 : pid,
12064 + func, file, line);
12067 + if (pid == vxi->vx_initpid)
12073 +#define vx_info_rmap_pid(v, p) \
12074 + __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12075 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12076 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12078 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12079 + const char *func, const char *file, int line)
12081 + if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12082 + vxfprintk(VXD_CBIT(cvirt, 2),
12083 + "vx_rmap_tgid: %p/%llx: %d -> %d",
12084 + vxi, (long long)vxi->vx_flags, pid,
12085 + (pid == 1) ? vxi->vx_initpid : pid,
12086 + func, file, line);
12087 + if ((pid == 1) && vxi->vx_initpid)
12088 + return vxi->vx_initpid;
12089 + if (pid == vxi->vx_initpid)
12096 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/sched.h
12097 --- linux-3.9.4/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
12098 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/sched.h 2013-05-31 14:47:11.000000000 +0000
12100 +#ifndef _VSERVER_SCHED_H
12101 +#define _VSERVER_SCHED_H
12108 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12113 +void vx_update_load(struct vx_info *);
12116 +void vx_update_sched_param(struct _vx_sched *sched,
12117 + struct _vx_sched_pc *sched_pc);
12119 +#endif /* __KERNEL__ */
12120 +#else /* _VSERVER_SCHED_H */
12121 +#warning duplicate inclusion
12122 +#endif /* _VSERVER_SCHED_H */
12123 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/sched_cmd.h
12124 --- linux-3.9.4/include/linux/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
12125 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/sched_cmd.h 2013-05-31 14:47:11.000000000 +0000
12127 +#ifndef _VSERVER_SCHED_CMD_H
12128 +#define _VSERVER_SCHED_CMD_H
12131 +#include <linux/compiler.h>
12132 +#include <uapi/vserver/sched_cmd.h>
12134 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12135 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12137 +#endif /* _VSERVER_SCHED_CMD_H */
12138 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched_def.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/sched_def.h
12139 --- linux-3.9.4/include/linux/vserver/sched_def.h 1970-01-01 00:00:00.000000000 +0000
12140 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/sched_def.h 2013-05-31 14:47:11.000000000 +0000
12142 +#ifndef _VSERVER_SCHED_DEF_H
12143 +#define _VSERVER_SCHED_DEF_H
12145 +#include <linux/spinlock.h>
12146 +#include <linux/jiffies.h>
12147 +#include <linux/cpumask.h>
12148 +#include <asm/atomic.h>
12149 +#include <asm/param.h>
12152 +/* context sub struct */
12154 +struct _vx_sched {
12155 + int prio_bias; /* bias offset for priority */
12157 + cpumask_t update; /* CPUs which should update */
12160 +struct _vx_sched_pc {
12161 + int prio_bias; /* bias offset for priority */
12163 + uint64_t user_ticks; /* token tick events */
12164 + uint64_t sys_ticks; /* token tick events */
12165 + uint64_t hold_ticks; /* token ticks paused */
12169 +#ifdef CONFIG_VSERVER_DEBUG
12171 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12173 + printk("\t_vx_sched:\n");
12174 + printk("\t priority = %4d\n", sched->prio_bias);
12179 +#endif /* _VSERVER_SCHED_DEF_H */
12180 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/signal.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/signal.h
12181 --- linux-3.9.4/include/linux/vserver/signal.h 1970-01-01 00:00:00.000000000 +0000
12182 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/signal.h 2013-05-31 14:47:11.000000000 +0000
12184 +#ifndef _VSERVER_SIGNAL_H
12185 +#define _VSERVER_SIGNAL_H
12192 +int vx_info_kill(struct vx_info *, int, int);
12194 +#endif /* __KERNEL__ */
12195 +#else /* _VSERVER_SIGNAL_H */
12196 +#warning duplicate inclusion
12197 +#endif /* _VSERVER_SIGNAL_H */
12198 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/signal_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/signal_cmd.h
12199 --- linux-3.9.4/include/linux/vserver/signal_cmd.h 1970-01-01 00:00:00.000000000 +0000
12200 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/signal_cmd.h 2013-05-31 14:47:11.000000000 +0000
12202 +#ifndef _VSERVER_SIGNAL_CMD_H
12203 +#define _VSERVER_SIGNAL_CMD_H
12205 +#include <uapi/vserver/signal_cmd.h>
12208 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12209 +extern int vc_wait_exit(struct vx_info *, void __user *);
12212 +extern int vc_get_pflags(uint32_t pid, void __user *);
12213 +extern int vc_set_pflags(uint32_t pid, void __user *);
12215 +#endif /* _VSERVER_SIGNAL_CMD_H */
12216 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/space.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/space.h
12217 --- linux-3.9.4/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
12218 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/space.h 2013-05-31 14:47:11.000000000 +0000
12220 +#ifndef _VSERVER_SPACE_H
12221 +#define _VSERVER_SPACE_H
12223 +#include <linux/types.h>
12227 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12229 +#else /* _VSERVER_SPACE_H */
12230 +#warning duplicate inclusion
12231 +#endif /* _VSERVER_SPACE_H */
12232 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/space_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/space_cmd.h
12233 --- linux-3.9.4/include/linux/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
12234 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/space_cmd.h 2013-05-31 14:47:11.000000000 +0000
12236 +#ifndef _VSERVER_SPACE_CMD_H
12237 +#define _VSERVER_SPACE_CMD_H
12239 +#include <uapi/vserver/space_cmd.h>
12242 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12243 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12244 +extern int vc_enter_space(struct vx_info *, void __user *);
12245 +extern int vc_set_space(struct vx_info *, void __user *);
12246 +extern int vc_get_space_mask(void __user *, int);
12248 +#endif /* _VSERVER_SPACE_CMD_H */
12249 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/switch.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/switch.h
12250 --- linux-3.9.4/include/linux/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12251 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/switch.h 2013-05-31 14:47:11.000000000 +0000
12253 +#ifndef _VSERVER_SWITCH_H
12254 +#define _VSERVER_SWITCH_H
12257 +#include <linux/errno.h>
12258 +#include <uapi/vserver/switch.h>
12260 +#endif /* _VSERVER_SWITCH_H */
12261 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/tag.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/tag.h
12262 --- linux-3.9.4/include/linux/vserver/tag.h 1970-01-01 00:00:00.000000000 +0000
12263 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/tag.h 2013-05-31 14:47:11.000000000 +0000
12268 +#include <linux/types.h>
12271 +#define DX_TAG(in) (IS_TAGGED(in))
12274 +#ifdef CONFIG_TAG_NFSD
12275 +#define DX_TAG_NFSD 1
12277 +#define DX_TAG_NFSD 0
12281 +#ifdef CONFIG_TAGGING_NONE
12283 +#define MAX_UID 0xFFFFFFFF
12284 +#define MAX_GID 0xFFFFFFFF
12286 +#define INOTAG_TAG(cond, uid, gid, tag) (0)
12288 +#define TAGINO_UID(cond, uid, tag) (uid)
12289 +#define TAGINO_GID(cond, gid, tag) (gid)
12294 +#ifdef CONFIG_TAGGING_GID16
12296 +#define MAX_UID 0xFFFFFFFF
12297 +#define MAX_GID 0x0000FFFF
12299 +#define INOTAG_TAG(cond, uid, gid, tag) \
12300 + ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
12302 +#define TAGINO_UID(cond, uid, tag) (uid)
12303 +#define TAGINO_GID(cond, gid, tag) \
12304 + ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
12309 +#ifdef CONFIG_TAGGING_ID24
12311 +#define MAX_UID 0x00FFFFFF
12312 +#define MAX_GID 0x00FFFFFF
12314 +#define INOTAG_TAG(cond, uid, gid, tag) \
12315 + ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
12317 +#define TAGINO_UID(cond, uid, tag) \
12318 + ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
12319 +#define TAGINO_GID(cond, gid, tag) \
12320 + ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
12325 +#ifdef CONFIG_TAGGING_UID16
12327 +#define MAX_UID 0x0000FFFF
12328 +#define MAX_GID 0xFFFFFFFF
12330 +#define INOTAG_TAG(cond, uid, gid, tag) \
12331 + ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
12333 +#define TAGINO_UID(cond, uid, tag) \
12334 + ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
12335 +#define TAGINO_GID(cond, gid, tag) (gid)
12340 +#ifdef CONFIG_TAGGING_INTERN
12342 +#define MAX_UID 0xFFFFFFFF
12343 +#define MAX_GID 0xFFFFFFFF
12345 +#define INOTAG_TAG(cond, uid, gid, tag) \
12346 + ((cond) ? (tag) : 0)
12348 +#define TAGINO_UID(cond, uid, tag) (uid)
12349 +#define TAGINO_GID(cond, gid, tag) (gid)
12354 +#ifndef CONFIG_TAGGING_NONE
12355 +#define dx_current_fstag(sb) \
12356 + ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
12358 +#define dx_current_fstag(sb) (0)
12361 +#ifndef CONFIG_TAGGING_INTERN
12362 +#define TAGINO_TAG(cond, tag) (0)
12364 +#define TAGINO_TAG(cond, tag) ((cond) ? (tag) : 0)
12367 +#define INOTAG_UID(cond, uid, gid) \
12368 + ((cond) ? ((uid) & MAX_UID) : (uid))
12369 +#define INOTAG_GID(cond, uid, gid) \
12370 + ((cond) ? ((gid) & MAX_GID) : (gid))
12373 +static inline uid_t dx_map_uid(uid_t uid)
12375 + if ((uid > MAX_UID) && (uid != -1))
12377 + return (uid & MAX_UID);
12380 +static inline gid_t dx_map_gid(gid_t gid)
12382 + if ((gid > MAX_GID) && (gid != -1))
12384 + return (gid & MAX_GID);
12392 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
12394 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
12395 + unsigned long *flags);
12397 +#ifdef CONFIG_PROPAGATE
12399 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
12401 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
12404 +#define dx_propagate_tag(n, i) do { } while (0)
12407 +#endif /* _DX_TAG_H */
12408 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/tag_cmd.h linux-3.9.4-vs2.3.6.1/include/linux/vserver/tag_cmd.h
12409 --- linux-3.9.4/include/linux/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
12410 +++ linux-3.9.4-vs2.3.6.1/include/linux/vserver/tag_cmd.h 2013-05-31 14:47:11.000000000 +0000
12412 +#ifndef _VSERVER_TAG_CMD_H
12413 +#define _VSERVER_TAG_CMD_H
12415 +#include <uapi/vserver/tag_cmd.h>
12417 +extern int vc_task_tag(uint32_t);
12419 +extern int vc_tag_migrate(uint32_t);
12421 +#endif /* _VSERVER_TAG_CMD_H */
12422 diff -NurpP --minimal linux-3.9.4/include/net/addrconf.h linux-3.9.4-vs2.3.6.1/include/net/addrconf.h
12423 --- linux-3.9.4/include/net/addrconf.h 2013-05-31 13:45:28.000000000 +0000
12424 +++ linux-3.9.4-vs2.3.6.1/include/net/addrconf.h 2013-05-31 17:17:53.000000000 +0000
12425 @@ -85,7 +85,8 @@ extern int ipv6_dev_get_saddr(struct n
12426 const struct net_device *dev,
12427 const struct in6_addr *daddr,
12428 unsigned int srcprefs,
12429 - struct in6_addr *saddr);
12430 + struct in6_addr *saddr,
12431 + struct nx_info *nxi);
12432 extern int ipv6_get_lladdr(struct net_device *dev,
12433 struct in6_addr *addr,
12434 unsigned char banned_flags);
12435 diff -NurpP --minimal linux-3.9.4/include/net/af_unix.h linux-3.9.4-vs2.3.6.1/include/net/af_unix.h
12436 --- linux-3.9.4/include/net/af_unix.h 2013-02-19 13:58:52.000000000 +0000
12437 +++ linux-3.9.4-vs2.3.6.1/include/net/af_unix.h 2013-05-31 17:17:53.000000000 +0000
12439 #include <linux/socket.h>
12440 #include <linux/un.h>
12441 #include <linux/mutex.h>
12442 +#include <linux/vs_base.h>
12443 #include <net/sock.h>
12445 extern void unix_inflight(struct file *fp);
12446 diff -NurpP --minimal linux-3.9.4/include/net/inet_timewait_sock.h linux-3.9.4-vs2.3.6.1/include/net/inet_timewait_sock.h
12447 --- linux-3.9.4/include/net/inet_timewait_sock.h 2013-05-31 13:45:28.000000000 +0000
12448 +++ linux-3.9.4-vs2.3.6.1/include/net/inet_timewait_sock.h 2013-05-31 17:18:34.000000000 +0000
12449 @@ -116,6 +116,10 @@ struct inet_timewait_sock {
12450 #define tw_dport __tw_common.skc_dport
12451 #define tw_num __tw_common.skc_num
12452 #define tw_portpair __tw_common.skc_portpair
12453 +#define tw_xid __tw_common.skc_xid
12454 +#define tw_vx_info __tw_common.skc_vx_info
12455 +#define tw_nid __tw_common.skc_nid
12456 +#define tw_nx_info __tw_common.skc_nx_info
12459 volatile unsigned char tw_substate;
12460 diff -NurpP --minimal linux-3.9.4/include/net/ip6_route.h linux-3.9.4-vs2.3.6.1/include/net/ip6_route.h
12461 --- linux-3.9.4/include/net/ip6_route.h 2013-05-31 13:45:28.000000000 +0000
12462 +++ linux-3.9.4-vs2.3.6.1/include/net/ip6_route.h 2013-05-31 17:17:53.000000000 +0000
12463 @@ -95,7 +95,8 @@ extern int ip6_route_get_saddr(struct
12464 struct rt6_info *rt,
12465 const struct in6_addr *daddr,
12466 unsigned int prefs,
12467 - struct in6_addr *saddr);
12468 + struct in6_addr *saddr,
12469 + struct nx_info *nxi);
12471 extern struct rt6_info *rt6_lookup(struct net *net,
12472 const struct in6_addr *daddr,
12473 diff -NurpP --minimal linux-3.9.4/include/net/route.h linux-3.9.4-vs2.3.6.1/include/net/route.h
12474 --- linux-3.9.4/include/net/route.h 2013-02-19 13:58:52.000000000 +0000
12475 +++ linux-3.9.4-vs2.3.6.1/include/net/route.h 2013-05-31 17:17:53.000000000 +0000
12476 @@ -207,6 +207,9 @@ static inline void ip_rt_put(struct rtab
12477 dst_release(&rt->dst);
12480 +#include <linux/vs_base.h>
12481 +#include <linux/vs_inet.h>
12483 #define IPTOS_RT_MASK (IPTOS_TOS_MASK & ~3)
12485 extern const __u8 ip_tos2prio[16];
12486 @@ -256,6 +259,9 @@ static inline void ip_route_connect_init
12487 protocol, flow_flags, dst, src, dport, sport);
12490 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
12491 + struct flowi4 *);
12493 static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
12494 __be32 dst, __be32 src, u32 tos,
12495 int oif, u8 protocol,
12496 @@ -264,11 +270,25 @@ static inline struct rtable *ip_route_co
12498 struct net *net = sock_net(sk);
12500 + struct nx_info *nx_info = current_nx_info();
12502 ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
12503 sport, dport, sk, can_sleep);
12505 - if (!dst || !src) {
12507 + nx_info = sk->sk_nx_info;
12509 + vxdprintk(VXD_CBIT(net, 4),
12510 + "ip_route_connect(%p) %p,%p;%lx",
12511 + sk, nx_info, sk->sk_socket,
12512 + (sk->sk_socket?sk->sk_socket->flags:0));
12514 + rt = ip_v4_find_src(net, nx_info, fl4);
12519 + if (!fl4->daddr || !fl4->saddr) {
12520 rt = __ip_route_output_key(net, fl4);
12523 diff -NurpP --minimal linux-3.9.4/include/net/sock.h linux-3.9.4-vs2.3.6.1/include/net/sock.h
12524 --- linux-3.9.4/include/net/sock.h 2013-05-31 14:22:27.000000000 +0000
12525 +++ linux-3.9.4-vs2.3.6.1/include/net/sock.h 2013-05-31 17:17:53.000000000 +0000
12526 @@ -191,6 +191,10 @@ struct sock_common {
12527 #ifdef CONFIG_NET_NS
12528 struct net *skc_net;
12531 + struct vx_info *skc_vx_info;
12533 + struct nx_info *skc_nx_info;
12535 * fields between dontcopy_begin/dontcopy_end
12536 * are not copied in sock_copy()
12537 @@ -304,6 +308,10 @@ struct sock {
12538 #define sk_bind_node __sk_common.skc_bind_node
12539 #define sk_prot __sk_common.skc_prot
12540 #define sk_net __sk_common.skc_net
12541 +#define sk_xid __sk_common.skc_xid
12542 +#define sk_vx_info __sk_common.skc_vx_info
12543 +#define sk_nid __sk_common.skc_nid
12544 +#define sk_nx_info __sk_common.skc_nx_info
12545 socket_lock_t sk_lock;
12546 struct sk_buff_head sk_receive_queue;
12548 diff -NurpP --minimal linux-3.9.4/include/uapi/Kbuild linux-3.9.4-vs2.3.6.1/include/uapi/Kbuild
12549 --- linux-3.9.4/include/uapi/Kbuild 2012-12-11 03:30:57.000000000 +0000
12550 +++ linux-3.9.4-vs2.3.6.1/include/uapi/Kbuild 2013-05-31 14:47:11.000000000 +0000
12551 @@ -12,3 +12,4 @@ header-y += video/
12555 +header-y += vserver/
12556 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/capability.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/capability.h
12557 --- linux-3.9.4/include/uapi/linux/capability.h 2012-12-11 03:30:57.000000000 +0000
12558 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/capability.h 2013-05-31 14:47:11.000000000 +0000
12559 @@ -259,6 +259,7 @@ struct vfs_cap_data {
12560 arbitrary SCSI commands */
12561 /* Allow setting encryption key on loopback filesystem */
12562 /* Allow setting zone reclaim policy */
12563 +/* Allow the selection of a security context */
12565 #define CAP_SYS_ADMIN 21
12567 @@ -345,7 +346,12 @@ struct vfs_cap_data {
12569 #define CAP_LAST_CAP CAP_BLOCK_SUSPEND
12571 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
12572 +/* Allow context manipulations */
12573 +/* Allow changing context info on files */
12575 +#define CAP_CONTEXT 63
12577 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
12580 * Bit location of each capability (used by user-space library and kernel)
12581 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/fs.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/fs.h
12582 --- linux-3.9.4/include/uapi/linux/fs.h 2013-05-31 13:45:29.000000000 +0000
12583 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/fs.h 2013-05-31 23:07:43.000000000 +0000
12584 @@ -86,6 +86,9 @@ struct inodes_stat_t {
12585 #define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */
12586 #define MS_I_VERSION (1<<23) /* Update inode I_version field */
12587 #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
12588 +#define MS_TAGGED (1<<8) /* use generic inode tagging */
12589 +#define MS_NOTAGCHECK (1<<9) /* don't check tags */
12590 +#define MS_TAGID (1<<25) /* use specific tag for this mount */
12592 /* These sb flags are internal to the kernel */
12593 #define MS_SNAP_STABLE (1<<27) /* Snapshot pages during writeback, if needed */
12594 @@ -192,11 +195,14 @@ struct inodes_stat_t {
12595 #define FS_EXTENT_FL 0x00080000 /* Extents */
12596 #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */
12597 #define FS_NOCOW_FL 0x00800000 /* Do not cow file */
12598 +#define FS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
12599 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
12601 -#define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
12602 -#define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
12603 +#define FS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
12604 +#define FS_COW_FL 0x20000000 /* Copy on Write marker */
12606 +#define FS_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
12607 +#define FS_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
12609 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
12610 #define SYNC_FILE_RANGE_WRITE 2
12611 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/gfs2_ondisk.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/gfs2_ondisk.h
12612 --- linux-3.9.4/include/uapi/linux/gfs2_ondisk.h 2012-12-11 03:30:57.000000000 +0000
12613 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/gfs2_ondisk.h 2013-05-31 14:47:11.000000000 +0000
12614 @@ -225,6 +225,9 @@ enum {
12617 gfs2fl_TopLevel = 10,
12618 + gfs2fl_IXUnlink = 16,
12619 + gfs2fl_Barrier = 17,
12621 gfs2fl_TruncInProg = 29,
12622 gfs2fl_InheritDirectio = 30,
12623 gfs2fl_InheritJdata = 31,
12624 @@ -242,6 +245,9 @@ enum {
12625 #define GFS2_DIF_SYNC 0x00000100
12626 #define GFS2_DIF_SYSTEM 0x00000200 /* New in gfs2 */
12627 #define GFS2_DIF_TOPDIR 0x00000400 /* New in gfs2 */
12628 +#define GFS2_DIF_IXUNLINK 0x00010000
12629 +#define GFS2_DIF_BARRIER 0x00020000
12630 +#define GFS2_DIF_COW 0x00040000
12631 #define GFS2_DIF_TRUNC_IN_PROG 0x20000000 /* New in gfs2 */
12632 #define GFS2_DIF_INHERIT_DIRECTIO 0x40000000 /* only in gfs1 */
12633 #define GFS2_DIF_INHERIT_JDATA 0x80000000
12634 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/if_tun.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/if_tun.h
12635 --- linux-3.9.4/include/uapi/linux/if_tun.h 2013-02-19 13:58:55.000000000 +0000
12636 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/if_tun.h 2013-05-31 15:00:16.000000000 +0000
12638 #define TUNGETVNETHDRSZ _IOR('T', 215, int)
12639 #define TUNSETVNETHDRSZ _IOW('T', 216, int)
12640 #define TUNSETQUEUE _IOW('T', 217, int)
12641 +#define TUNSETNID _IOW('T', 218, int)
12643 /* TUNSETIFF ifr flags */
12644 #define IFF_TUN 0x0001
12645 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/major.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/major.h
12646 --- linux-3.9.4/include/uapi/linux/major.h 2012-12-11 03:30:57.000000000 +0000
12647 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/major.h 2013-05-31 14:47:11.000000000 +0000
12649 #define HD_MAJOR IDE0_MAJOR
12650 #define PTY_SLAVE_MAJOR 3
12651 #define TTY_MAJOR 4
12652 +#define VROOT_MAJOR 4
12653 #define TTYAUX_MAJOR 5
12655 #define VCS_MAJOR 7
12656 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/nfs_mount.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/nfs_mount.h
12657 --- linux-3.9.4/include/uapi/linux/nfs_mount.h 2012-12-11 03:30:57.000000000 +0000
12658 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/nfs_mount.h 2013-05-31 14:47:11.000000000 +0000
12659 @@ -63,7 +63,8 @@ struct nfs_mount_data {
12660 #define NFS_MOUNT_SECFLAVOUR 0x2000 /* 5 */
12661 #define NFS_MOUNT_NORDIRPLUS 0x4000 /* 5 */
12662 #define NFS_MOUNT_UNSHARED 0x8000 /* 5 */
12663 -#define NFS_MOUNT_FLAGMASK 0xFFFF
12664 +#define NFS_MOUNT_TAGGED 0x10000 /* context tagging */
12665 +#define NFS_MOUNT_FLAGMASK 0x1FFFF
12667 /* The following are for internal use only */
12668 #define NFS_MOUNT_LOOKUP_CACHE_NONEG 0x10000
12669 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/reboot.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/reboot.h
12670 --- linux-3.9.4/include/uapi/linux/reboot.h 2012-12-11 03:30:57.000000000 +0000
12671 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/reboot.h 2013-05-31 14:47:11.000000000 +0000
12673 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
12674 #define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
12675 #define LINUX_REBOOT_CMD_KEXEC 0x45584543
12677 +#define LINUX_REBOOT_CMD_OOM 0xDEADBEEF
12680 #endif /* _UAPI_LINUX_REBOOT_H */
12681 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/sysctl.h linux-3.9.4-vs2.3.6.1/include/uapi/linux/sysctl.h
12682 --- linux-3.9.4/include/uapi/linux/sysctl.h 2012-12-11 03:30:57.000000000 +0000
12683 +++ linux-3.9.4-vs2.3.6.1/include/uapi/linux/sysctl.h 2013-05-31 14:47:11.000000000 +0000
12684 @@ -60,6 +60,7 @@ enum
12685 CTL_ABI=9, /* Binary emulation */
12686 CTL_CPU=10, /* CPU stuff (speed scaling, etc) */
12687 CTL_ARLAN=254, /* arlan wireless driver */
12688 + CTL_VSERVER=4242, /* Linux-VServer debug */
12689 CTL_S390DBF=5677, /* s390 debug */
12690 CTL_SUNRPC=7249, /* sunrpc debug */
12691 CTL_PM=9899, /* frv power management */
12692 @@ -94,6 +95,7 @@ enum
12694 KERN_PANIC=15, /* int: panic timeout */
12695 KERN_REALROOTDEV=16, /* real root device to mount after initrd */
12696 + KERN_VSHELPER=17, /* string: path to vshelper policy agent */
12698 KERN_SPARC_REBOOT=21, /* reboot command on Sparc */
12699 KERN_CTLALTDEL=22, /* int: allow ctl-alt-del to reboot */
12700 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/Kbuild linux-3.9.4-vs2.3.6.1/include/uapi/vserver/Kbuild
12701 --- linux-3.9.4/include/uapi/vserver/Kbuild 1970-01-01 00:00:00.000000000 +0000
12702 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/Kbuild 2013-05-31 14:47:11.000000000 +0000
12705 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12706 + cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12707 + inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12708 + debug_cmd.h device_cmd.h
12710 +header-y += switch.h context.h network.h monitor.h \
12711 + limit.h inode.h device.h
12713 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/cacct_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/cacct_cmd.h
12714 --- linux-3.9.4/include/uapi/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
12715 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/cacct_cmd.h 2013-05-31 14:47:11.000000000 +0000
12717 +#ifndef _UAPI_VS_CACCT_CMD_H
12718 +#define _UAPI_VS_CACCT_CMD_H
12721 +/* virtual host info name commands */
12723 +#define VCMD_sock_stat VC_CMD(VSTAT, 5, 0)
12725 +struct vcmd_sock_stat_v0 {
12727 + uint32_t count[3];
12728 + uint64_t total[3];
12731 +#endif /* _UAPI_VS_CACCT_CMD_H */
12732 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/context.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/context.h
12733 --- linux-3.9.4/include/uapi/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
12734 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/context.h 2013-05-31 19:44:13.000000000 +0000
12736 +#ifndef _UAPI_VS_CONTEXT_H
12737 +#define _UAPI_VS_CONTEXT_H
12739 +#include <linux/types.h>
12740 +#include <linux/capability.h>
12743 +/* context flags */
12745 +#define VXF_INFO_SCHED 0x00000002
12746 +#define VXF_INFO_NPROC 0x00000004
12747 +#define VXF_INFO_PRIVATE 0x00000008
12749 +#define VXF_INFO_INIT 0x00000010
12750 +#define VXF_INFO_HIDE 0x00000020
12751 +#define VXF_INFO_ULIMIT 0x00000040
12752 +#define VXF_INFO_NSPACE 0x00000080
12754 +#define VXF_SCHED_HARD 0x00000100
12755 +#define VXF_SCHED_PRIO 0x00000200
12756 +#define VXF_SCHED_PAUSE 0x00000400
12758 +#define VXF_VIRT_MEM 0x00010000
12759 +#define VXF_VIRT_UPTIME 0x00020000
12760 +#define VXF_VIRT_CPU 0x00040000
12761 +#define VXF_VIRT_LOAD 0x00080000
12762 +#define VXF_VIRT_TIME 0x00100000
12764 +#define VXF_HIDE_MOUNT 0x01000000
12765 +/* was VXF_HIDE_NETIF 0x02000000 */
12766 +#define VXF_HIDE_VINFO 0x04000000
12768 +#define VXF_STATE_SETUP (1ULL << 32)
12769 +#define VXF_STATE_INIT (1ULL << 33)
12770 +#define VXF_STATE_ADMIN (1ULL << 34)
12772 +#define VXF_SC_HELPER (1ULL << 36)
12773 +#define VXF_REBOOT_KILL (1ULL << 37)
12774 +#define VXF_PERSISTENT (1ULL << 38)
12776 +#define VXF_FORK_RSS (1ULL << 48)
12777 +#define VXF_PROLIFIC (1ULL << 49)
12779 +#define VXF_IGNEG_NICE (1ULL << 52)
12781 +#define VXF_ONE_TIME (0x0007ULL << 32)
12783 +#define VXF_INIT_SET (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12786 +/* context migration */
12788 +#define VXM_SET_INIT 0x00000001
12789 +#define VXM_SET_REAPER 0x00000002
12791 +/* context caps */
12793 +#define VXC_SET_UTSNAME 0x00000001
12794 +#define VXC_SET_RLIMIT 0x00000002
12795 +#define VXC_FS_SECURITY 0x00000004
12796 +#define VXC_FS_TRUSTED 0x00000008
12797 +#define VXC_TIOCSTI 0x00000010
12799 +/* was VXC_RAW_ICMP 0x00000100 */
12800 +#define VXC_SYSLOG 0x00001000
12801 +#define VXC_OOM_ADJUST 0x00002000
12802 +#define VXC_AUDIT_CONTROL 0x00004000
12804 +/* #define VXC_SECURE_MOUNT 0x00010000
12805 +#define VXC_SECURE_REMOUNT 0x00020000 */
12806 +#define VXC_BINARY_MOUNT 0x00040000
12807 +#define VXC_DEV_MOUNT 0x00080000
12809 +#define VXC_QUOTA_CTL 0x00100000
12810 +#define VXC_ADMIN_MAPPER 0x00200000
12811 +#define VXC_ADMIN_CLOOP 0x00400000
12813 +#define VXC_KTHREAD 0x01000000
12814 +#define VXC_NAMESPACE 0x02000000
12816 +#endif /* _UAPI_VS_CONTEXT_H */
12817 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/context_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/context_cmd.h
12818 --- linux-3.9.4/include/uapi/vserver/context_cmd.h 1970-01-01 00:00:00.000000000 +0000
12819 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/context_cmd.h 2013-05-31 14:47:11.000000000 +0000
12821 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12822 +#define _UAPI_VS_CONTEXT_CMD_H
12825 +/* vinfo commands */
12827 +#define VCMD_task_xid VC_CMD(VINFO, 1, 0)
12830 +#define VCMD_vx_info VC_CMD(VINFO, 5, 0)
12832 +struct vcmd_vx_info_v0 {
12834 + uint32_t initpid;
12835 + /* more to come */
12839 +#define VCMD_ctx_stat VC_CMD(VSTAT, 0, 0)
12841 +struct vcmd_ctx_stat_v0 {
12844 + /* more to come */
12848 +/* context commands */
12850 +#define VCMD_ctx_create_v0 VC_CMD(VPROC, 1, 0)
12851 +#define VCMD_ctx_create VC_CMD(VPROC, 1, 1)
12853 +struct vcmd_ctx_create {
12854 + uint64_t flagword;
12857 +#define VCMD_ctx_migrate_v0 VC_CMD(PROCMIG, 1, 0)
12858 +#define VCMD_ctx_migrate VC_CMD(PROCMIG, 1, 1)
12860 +struct vcmd_ctx_migrate {
12861 + uint64_t flagword;
12866 +/* flag commands */
12868 +#define VCMD_get_cflags VC_CMD(FLAGS, 1, 0)
12869 +#define VCMD_set_cflags VC_CMD(FLAGS, 2, 0)
12871 +struct vcmd_ctx_flags_v0 {
12872 + uint64_t flagword;
12878 +/* context caps commands */
12880 +#define VCMD_get_ccaps VC_CMD(FLAGS, 3, 1)
12881 +#define VCMD_set_ccaps VC_CMD(FLAGS, 4, 1)
12883 +struct vcmd_ctx_caps_v1 {
12890 +/* bcaps commands */
12892 +#define VCMD_get_bcaps VC_CMD(FLAGS, 9, 0)
12893 +#define VCMD_set_bcaps VC_CMD(FLAGS, 10, 0)
12895 +struct vcmd_bcaps {
12902 +/* umask commands */
12904 +#define VCMD_get_umask VC_CMD(FLAGS, 13, 0)
12905 +#define VCMD_set_umask VC_CMD(FLAGS, 14, 0)
12907 +struct vcmd_umask {
12914 +/* wmask commands */
12916 +#define VCMD_get_wmask VC_CMD(FLAGS, 15, 0)
12917 +#define VCMD_set_wmask VC_CMD(FLAGS, 16, 0)
12919 +struct vcmd_wmask {
12928 +#define VCMD_get_badness VC_CMD(MEMCTRL, 5, 0)
12929 +#define VCMD_set_badness VC_CMD(MEMCTRL, 6, 0)
12931 +struct vcmd_badness_v0 {
12935 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12936 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/cvirt_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/cvirt_cmd.h
12937 --- linux-3.9.4/include/uapi/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
12938 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/cvirt_cmd.h 2013-05-31 14:47:11.000000000 +0000
12940 +#ifndef _UAPI_VS_CVIRT_CMD_H
12941 +#define _UAPI_VS_CVIRT_CMD_H
12944 +/* virtual host info name commands */
12946 +#define VCMD_set_vhi_name VC_CMD(VHOST, 1, 0)
12947 +#define VCMD_get_vhi_name VC_CMD(VHOST, 2, 0)
12949 +struct vcmd_vhi_name_v0 {
12955 +enum vhi_name_field {
12956 + VHIN_CONTEXT = 0,
12967 +#define VCMD_virt_stat VC_CMD(VSTAT, 3, 0)
12969 +struct vcmd_virt_stat_v0 {
12972 + uint32_t nr_threads;
12973 + uint32_t nr_running;
12974 + uint32_t nr_uninterruptible;
12975 + uint32_t nr_onhold;
12976 + uint32_t nr_forks;
12977 + uint32_t load[3];
12980 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12981 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/debug_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/debug_cmd.h
12982 --- linux-3.9.4/include/uapi/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
12983 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/debug_cmd.h 2013-05-31 14:47:11.000000000 +0000
12985 +#ifndef _UAPI_VS_DEBUG_CMD_H
12986 +#define _UAPI_VS_DEBUG_CMD_H
12989 +/* debug commands */
12991 +#define VCMD_dump_history VC_CMD(DEBUG, 1, 0)
12993 +#define VCMD_read_history VC_CMD(DEBUG, 5, 0)
12994 +#define VCMD_read_monitor VC_CMD(DEBUG, 6, 0)
12996 +struct vcmd_read_history_v0 {
12999 + char __user *data;
13002 +struct vcmd_read_monitor_v0 {
13005 + char __user *data;
13008 +#endif /* _UAPI_VS_DEBUG_CMD_H */
13009 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/device.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/device.h
13010 --- linux-3.9.4/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
13011 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/device.h 2013-05-31 14:47:11.000000000 +0000
13013 +#ifndef _UAPI_VS_DEVICE_H
13014 +#define _UAPI_VS_DEVICE_H
13017 +#define DATTR_CREATE 0x00000001
13018 +#define DATTR_OPEN 0x00000002
13020 +#define DATTR_REMAP 0x00000010
13022 +#define DATTR_MASK 0x00000013
13024 +#endif /* _UAPI_VS_DEVICE_H */
13025 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/device_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/device_cmd.h
13026 --- linux-3.9.4/include/uapi/vserver/device_cmd.h 1970-01-01 00:00:00.000000000 +0000
13027 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/device_cmd.h 2013-05-31 14:47:11.000000000 +0000
13029 +#ifndef _UAPI_VS_DEVICE_CMD_H
13030 +#define _UAPI_VS_DEVICE_CMD_H
13033 +/* device vserver commands */
13035 +#define VCMD_set_mapping VC_CMD(DEVICE, 1, 0)
13036 +#define VCMD_unset_mapping VC_CMD(DEVICE, 2, 0)
13038 +struct vcmd_set_mapping_v0 {
13039 + const char __user *device;
13040 + const char __user *target;
13044 +#endif /* _UAPI_VS_DEVICE_CMD_H */
13045 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/dlimit_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/dlimit_cmd.h
13046 --- linux-3.9.4/include/uapi/vserver/dlimit_cmd.h 1970-01-01 00:00:00.000000000 +0000
13047 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/dlimit_cmd.h 2013-05-31 14:47:11.000000000 +0000
13049 +#ifndef _UAPI_VS_DLIMIT_CMD_H
13050 +#define _UAPI_VS_DLIMIT_CMD_H
13053 +/* dlimit vserver commands */
13055 +#define VCMD_add_dlimit VC_CMD(DLIMIT, 1, 0)
13056 +#define VCMD_rem_dlimit VC_CMD(DLIMIT, 2, 0)
13058 +#define VCMD_set_dlimit VC_CMD(DLIMIT, 5, 0)
13059 +#define VCMD_get_dlimit VC_CMD(DLIMIT, 6, 0)
13061 +struct vcmd_ctx_dlimit_base_v0 {
13062 + const char __user *name;
13066 +struct vcmd_ctx_dlimit_v0 {
13067 + const char __user *name;
13068 + uint32_t space_used; /* used space in kbytes */
13069 + uint32_t space_total; /* maximum space in kbytes */
13070 + uint32_t inodes_used; /* used inodes */
13071 + uint32_t inodes_total; /* maximum inodes */
13072 + uint32_t reserved; /* reserved for root in % */
13076 +#define CDLIM_UNSET ((uint32_t)0UL)
13077 +#define CDLIM_INFINITY ((uint32_t)~0UL)
13078 +#define CDLIM_KEEP ((uint32_t)~1UL)
13080 +#define DLIME_UNIT 0
13081 +#define DLIME_KILO 1
13082 +#define DLIME_MEGA 2
13083 +#define DLIME_GIGA 3
13085 +#define DLIMF_SHIFT 0x10
13087 +#define DLIMS_USED 0
13088 +#define DLIMS_TOTAL 2
13091 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
13093 + int exp = (flags & DLIMF_SHIFT) ?
13094 + (flags >> shift) & DLIME_GIGA : DLIME_KILO;
13095 + return ((uint64_t)val) << (10 * exp);
13099 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
13103 + if (*flags & DLIMF_SHIFT) {
13104 + while (val > (1LL << 32) && (exp < 3)) {
13108 + *flags &= ~(DLIME_GIGA << shift);
13109 + *flags |= exp << shift;
13115 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
13116 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/inode.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/inode.h
13117 --- linux-3.9.4/include/uapi/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
13118 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/inode.h 2013-05-31 14:47:11.000000000 +0000
13120 +#ifndef _UAPI_VS_INODE_H
13121 +#define _UAPI_VS_INODE_H
13124 +#define IATTR_TAG 0x01000000
13126 +#define IATTR_ADMIN 0x00000001
13127 +#define IATTR_WATCH 0x00000002
13128 +#define IATTR_HIDE 0x00000004
13129 +#define IATTR_FLAGS 0x00000007
13131 +#define IATTR_BARRIER 0x00010000
13132 +#define IATTR_IXUNLINK 0x00020000
13133 +#define IATTR_IMMUTABLE 0x00040000
13134 +#define IATTR_COW 0x00080000
13137 +/* inode ioctls */
13139 +#define FIOC_GETXFLG _IOR('x', 5, long)
13140 +#define FIOC_SETXFLG _IOW('x', 6, long)
13142 +#endif /* _UAPI_VS_INODE_H */
13143 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/inode_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/inode_cmd.h
13144 --- linux-3.9.4/include/uapi/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
13145 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/inode_cmd.h 2013-05-31 14:47:11.000000000 +0000
13147 +#ifndef _UAPI_VS_INODE_CMD_H
13148 +#define _UAPI_VS_INODE_CMD_H
13151 +/* inode vserver commands */
13153 +#define VCMD_get_iattr VC_CMD(INODE, 1, 1)
13154 +#define VCMD_set_iattr VC_CMD(INODE, 2, 1)
13156 +#define VCMD_fget_iattr VC_CMD(INODE, 3, 0)
13157 +#define VCMD_fset_iattr VC_CMD(INODE, 4, 0)
13159 +struct vcmd_ctx_iattr_v1 {
13160 + const char __user *name;
13166 +struct vcmd_ctx_fiattr_v0 {
13172 +#endif /* _UAPI_VS_INODE_CMD_H */
13173 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/limit.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/limit.h
13174 --- linux-3.9.4/include/uapi/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
13175 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/limit.h 2013-05-31 14:47:11.000000000 +0000
13177 +#ifndef _UAPI_VS_LIMIT_H
13178 +#define _UAPI_VS_LIMIT_H
13181 +#define VLIMIT_NSOCK 16
13182 +#define VLIMIT_OPENFD 17
13183 +#define VLIMIT_ANON 18
13184 +#define VLIMIT_SHMEM 19
13185 +#define VLIMIT_SEMARY 20
13186 +#define VLIMIT_NSEMS 21
13187 +#define VLIMIT_DENTRY 22
13188 +#define VLIMIT_MAPPED 23
13190 +#endif /* _UAPI_VS_LIMIT_H */
13191 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/limit_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/limit_cmd.h
13192 --- linux-3.9.4/include/uapi/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
13193 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/limit_cmd.h 2013-05-31 14:47:11.000000000 +0000
13195 +#ifndef _UAPI_VS_LIMIT_CMD_H
13196 +#define _UAPI_VS_LIMIT_CMD_H
13199 +/* rlimit vserver commands */
13201 +#define VCMD_get_rlimit VC_CMD(RLIMIT, 1, 0)
13202 +#define VCMD_set_rlimit VC_CMD(RLIMIT, 2, 0)
13203 +#define VCMD_get_rlimit_mask VC_CMD(RLIMIT, 3, 0)
13204 +#define VCMD_reset_hits VC_CMD(RLIMIT, 7, 0)
13205 +#define VCMD_reset_minmax VC_CMD(RLIMIT, 9, 0)
13207 +struct vcmd_ctx_rlimit_v0 {
13209 + uint64_t minimum;
13210 + uint64_t softlimit;
13211 + uint64_t maximum;
13214 +struct vcmd_ctx_rlimit_mask_v0 {
13215 + uint32_t minimum;
13216 + uint32_t softlimit;
13217 + uint32_t maximum;
13220 +#define VCMD_rlimit_stat VC_CMD(VSTAT, 1, 0)
13222 +struct vcmd_rlimit_stat_v0 {
13226 + uint64_t minimum;
13227 + uint64_t maximum;
13230 +#define CRLIM_UNSET (0ULL)
13231 +#define CRLIM_INFINITY (~0ULL)
13232 +#define CRLIM_KEEP (~1ULL)
13234 +#endif /* _UAPI_VS_LIMIT_CMD_H */
13235 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/monitor.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/monitor.h
13236 --- linux-3.9.4/include/uapi/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
13237 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/monitor.h 2013-05-31 14:47:11.000000000 +0000
13239 +#ifndef _UAPI_VS_MONITOR_H
13240 +#define _UAPI_VS_MONITOR_H
13242 +#include <linux/types.h>
13250 + VXM_UPDATE = 0x20,
13254 + VXM_RQINFO_1 = 0x24,
13257 + VXM_ACTIVATE = 0x40,
13264 + VXM_MIGRATE = 0x48,
13267 + /* all other bits are flags */
13268 + VXM_SCHED = 0x80,
13271 +struct _vxm_update_1 {
13272 + uint32_t tokens_max;
13273 + uint32_t fill_rate;
13274 + uint32_t interval;
13277 +struct _vxm_update_2 {
13278 + uint32_t tokens_min;
13279 + uint32_t fill_rate;
13280 + uint32_t interval;
13283 +struct _vxm_rqinfo_1 {
13284 + uint16_t running;
13288 + uint32_t idle_tokens;
13291 +struct _vxm_rqinfo_2 {
13292 + uint32_t norm_time;
13293 + uint32_t idle_time;
13294 + uint32_t idle_skip;
13297 +struct _vxm_sched {
13299 + uint32_t norm_time;
13300 + uint32_t idle_time;
13303 +struct _vxm_task {
13308 +struct _vxm_event {
13317 + struct _vxm_task tsk;
13321 +struct _vx_mon_entry {
13325 + struct _vxm_event ev;
13326 + struct _vxm_sched sd;
13327 + struct _vxm_update_1 u1;
13328 + struct _vxm_update_2 u2;
13329 + struct _vxm_rqinfo_1 q1;
13330 + struct _vxm_rqinfo_2 q2;
13334 +#endif /* _UAPI_VS_MONITOR_H */
13335 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/network.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/network.h
13336 --- linux-3.9.4/include/uapi/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
13337 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/network.h 2013-05-31 14:47:11.000000000 +0000
13339 +#ifndef _UAPI_VS_NETWORK_H
13340 +#define _UAPI_VS_NETWORK_H
13342 +#include <linux/types.h>
13345 +#define MAX_N_CONTEXT 65535 /* Arbitrary limit */
13348 +/* network flags */
13350 +#define NXF_INFO_PRIVATE 0x00000008
13352 +#define NXF_SINGLE_IP 0x00000100
13353 +#define NXF_LBACK_REMAP 0x00000200
13354 +#define NXF_LBACK_ALLOW 0x00000400
13356 +#define NXF_HIDE_NETIF 0x02000000
13357 +#define NXF_HIDE_LBACK 0x04000000
13359 +#define NXF_STATE_SETUP (1ULL << 32)
13360 +#define NXF_STATE_ADMIN (1ULL << 34)
13362 +#define NXF_SC_HELPER (1ULL << 36)
13363 +#define NXF_PERSISTENT (1ULL << 38)
13365 +#define NXF_ONE_TIME (0x0005ULL << 32)
13368 +#define NXF_INIT_SET (__nxf_init_set())
13370 +static inline uint64_t __nxf_init_set(void) {
13371 + return NXF_STATE_ADMIN
13372 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13373 + | NXF_LBACK_REMAP
13376 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13379 + | NXF_HIDE_NETIF;
13383 +/* network caps */
13385 +#define NXC_TUN_CREATE 0x00000001
13387 +#define NXC_RAW_ICMP 0x00000100
13389 +#define NXC_MULTICAST 0x00001000
13392 +/* address types */
13394 +#define NXA_TYPE_IPV4 0x0001
13395 +#define NXA_TYPE_IPV6 0x0002
13397 +#define NXA_TYPE_NONE 0x0000
13398 +#define NXA_TYPE_ANY 0x00FF
13400 +#define NXA_TYPE_ADDR 0x0010
13401 +#define NXA_TYPE_MASK 0x0020
13402 +#define NXA_TYPE_RANGE 0x0040
13404 +#define NXA_MASK_ALL (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13406 +#define NXA_MOD_BCAST 0x0100
13407 +#define NXA_MOD_LBACK 0x0200
13409 +#define NXA_LOOPBACK 0x1000
13411 +#define NXA_MASK_BIND (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13412 +#define NXA_MASK_SHOW (NXA_MASK_ALL | NXA_LOOPBACK)
13414 +#endif /* _UAPI_VS_NETWORK_H */
13415 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/network_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/network_cmd.h
13416 --- linux-3.9.4/include/uapi/vserver/network_cmd.h 1970-01-01 00:00:00.000000000 +0000
13417 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/network_cmd.h 2013-05-31 14:47:11.000000000 +0000
13419 +#ifndef _UAPI_VS_NETWORK_CMD_H
13420 +#define _UAPI_VS_NETWORK_CMD_H
13423 +/* vinfo commands */
13425 +#define VCMD_task_nid VC_CMD(VINFO, 2, 0)
13428 +#define VCMD_nx_info VC_CMD(VINFO, 6, 0)
13430 +struct vcmd_nx_info_v0 {
13432 + /* more to come */
13436 +#include <linux/in.h>
13437 +#include <linux/in6.h>
13439 +#define VCMD_net_create_v0 VC_CMD(VNET, 1, 0)
13440 +#define VCMD_net_create VC_CMD(VNET, 1, 1)
13442 +struct vcmd_net_create {
13443 + uint64_t flagword;
13446 +#define VCMD_net_migrate VC_CMD(NETMIG, 1, 0)
13448 +#define VCMD_net_add VC_CMD(NETALT, 1, 0)
13449 +#define VCMD_net_remove VC_CMD(NETALT, 2, 0)
13451 +struct vcmd_net_addr_v0 {
13454 + struct in_addr ip[4];
13455 + struct in_addr mask[4];
13458 +#define VCMD_net_add_ipv4_v1 VC_CMD(NETALT, 1, 1)
13459 +#define VCMD_net_rem_ipv4_v1 VC_CMD(NETALT, 2, 1)
13461 +struct vcmd_net_addr_ipv4_v1 {
13464 + struct in_addr ip;
13465 + struct in_addr mask;
13468 +#define VCMD_net_add_ipv4 VC_CMD(NETALT, 1, 2)
13469 +#define VCMD_net_rem_ipv4 VC_CMD(NETALT, 2, 2)
13471 +struct vcmd_net_addr_ipv4_v2 {
13474 + struct in_addr ip;
13475 + struct in_addr ip2;
13476 + struct in_addr mask;
13479 +#define VCMD_net_add_ipv6 VC_CMD(NETALT, 3, 1)
13480 +#define VCMD_net_remove_ipv6 VC_CMD(NETALT, 4, 1)
13482 +struct vcmd_net_addr_ipv6_v1 {
13486 + struct in6_addr ip;
13487 + struct in6_addr mask;
13490 +#define VCMD_add_match_ipv4 VC_CMD(NETALT, 5, 0)
13491 +#define VCMD_get_match_ipv4 VC_CMD(NETALT, 6, 0)
13493 +struct vcmd_match_ipv4_v0 {
13498 + struct in_addr ip;
13499 + struct in_addr ip2;
13500 + struct in_addr mask;
13503 +#define VCMD_add_match_ipv6 VC_CMD(NETALT, 7, 0)
13504 +#define VCMD_get_match_ipv6 VC_CMD(NETALT, 8, 0)
13506 +struct vcmd_match_ipv6_v0 {
13511 + struct in6_addr ip;
13512 + struct in6_addr ip2;
13513 + struct in6_addr mask;
13519 +/* flag commands */
13521 +#define VCMD_get_nflags VC_CMD(FLAGS, 5, 0)
13522 +#define VCMD_set_nflags VC_CMD(FLAGS, 6, 0)
13524 +struct vcmd_net_flags_v0 {
13525 + uint64_t flagword;
13531 +/* network caps commands */
13533 +#define VCMD_get_ncaps VC_CMD(FLAGS, 7, 0)
13534 +#define VCMD_set_ncaps VC_CMD(FLAGS, 8, 0)
13536 +struct vcmd_net_caps_v0 {
13541 +#endif /* _UAPI_VS_NETWORK_CMD_H */
13542 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/sched_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/sched_cmd.h
13543 --- linux-3.9.4/include/uapi/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
13544 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/sched_cmd.h 2013-05-31 14:47:11.000000000 +0000
13546 +#ifndef _UAPI_VS_SCHED_CMD_H
13547 +#define _UAPI_VS_SCHED_CMD_H
13550 +struct vcmd_prio_bias {
13552 + int32_t prio_bias;
13555 +#define VCMD_set_prio_bias VC_CMD(SCHED, 4, 0)
13556 +#define VCMD_get_prio_bias VC_CMD(SCHED, 5, 0)
13558 +#endif /* _UAPI_VS_SCHED_CMD_H */
13559 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/signal_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/signal_cmd.h
13560 --- linux-3.9.4/include/uapi/vserver/signal_cmd.h 1970-01-01 00:00:00.000000000 +0000
13561 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/signal_cmd.h 2013-05-31 14:47:11.000000000 +0000
13563 +#ifndef _UAPI_VS_SIGNAL_CMD_H
13564 +#define _UAPI_VS_SIGNAL_CMD_H
13567 +/* signalling vserver commands */
13569 +#define VCMD_ctx_kill VC_CMD(PROCTRL, 1, 0)
13570 +#define VCMD_wait_exit VC_CMD(EVENT, 99, 0)
13572 +struct vcmd_ctx_kill_v0 {
13577 +struct vcmd_wait_exit_v0 {
13578 + int32_t reboot_cmd;
13579 + int32_t exit_code;
13583 +/* process alteration commands */
13585 +#define VCMD_get_pflags VC_CMD(PROCALT, 5, 0)
13586 +#define VCMD_set_pflags VC_CMD(PROCALT, 6, 0)
13588 +struct vcmd_pflags_v0 {
13589 + uint32_t flagword;
13593 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
13594 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/space_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/space_cmd.h
13595 --- linux-3.9.4/include/uapi/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
13596 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/space_cmd.h 2013-05-31 14:47:11.000000000 +0000
13598 +#ifndef _UAPI_VS_SPACE_CMD_H
13599 +#define _UAPI_VS_SPACE_CMD_H
13602 +#define VCMD_enter_space_v0 VC_CMD(PROCALT, 1, 0)
13603 +#define VCMD_enter_space_v1 VC_CMD(PROCALT, 1, 1)
13604 +#define VCMD_enter_space VC_CMD(PROCALT, 1, 2)
13606 +#define VCMD_set_space_v0 VC_CMD(PROCALT, 3, 0)
13607 +#define VCMD_set_space_v1 VC_CMD(PROCALT, 3, 1)
13608 +#define VCMD_set_space VC_CMD(PROCALT, 3, 2)
13610 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13612 +#define VCMD_get_space_mask VC_CMD(VSPACE, 0, 1)
13613 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13616 +struct vcmd_space_mask_v1 {
13620 +struct vcmd_space_mask_v2 {
13625 +#endif /* _UAPI_VS_SPACE_CMD_H */
13626 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/switch.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/switch.h
13627 --- linux-3.9.4/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
13628 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/switch.h 2013-05-31 14:47:11.000000000 +0000
13630 +#ifndef _UAPI_VS_SWITCH_H
13631 +#define _UAPI_VS_SWITCH_H
13633 +#include <linux/types.h>
13636 +#define VC_CATEGORY(c) (((c) >> 24) & 0x3F)
13637 +#define VC_COMMAND(c) (((c) >> 16) & 0xFF)
13638 +#define VC_VERSION(c) ((c) & 0xFFF)
13640 +#define VC_CMD(c, i, v) ((((VC_CAT_ ## c) & 0x3F) << 24) \
13641 + | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13645 + Syscall Matrix V2.8
13647 + |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13648 + |STATS |DESTROY|ALTER |CHANGE |LIMIT |TEST | | | |
13649 + |INFO |SETUP | |MOVE | | | | | |
13650 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13651 + SYSTEM |VERSION|VSETUP |VHOST | | | | |DEVICE | |
13652 + HOST | 00| 01| 02| 03| 04| 05| | 06| 07|
13653 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13654 + CPU | |VPROC |PROCALT|PROCMIG|PROCTRL| | |SCHED. | |
13655 + PROCESS| 08| 09| 10| 11| 12| 13| | 14| 15|
13656 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13657 + MEMORY | | | | |MEMCTRL| | |SWAP | |
13658 + | 16| 17| 18| 19| 20| 21| | 22| 23|
13659 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13660 + NETWORK| |VNET |NETALT |NETMIG |NETCTL | | |SERIAL | |
13661 + | 24| 25| 26| 27| 28| 29| | 30| 31|
13662 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13663 + DISK | | | |TAGMIG |DLIMIT | | |INODE | |
13664 + VFS | 32| 33| 34| 35| 36| 37| | 38| 39|
13665 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13666 + OTHER |VSTAT | | | | | | |VINFO | |
13667 + | 40| 41| 42| 43| 44| 45| | 46| 47|
13668 + =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13669 + SPECIAL|EVENT | | | |FLAGS | | |VSPACE | |
13670 + | 48| 49| 50| 51| 52| 53| | 54| 55|
13671 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13672 + SPECIAL|DEBUG | | | |RLIMIT |SYSCALL| | |COMPAT |
13673 + | 56| 57| 58| 59| 60|TEST 61| | 62| 63|
13674 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13678 +#define VC_CAT_VERSION 0
13680 +#define VC_CAT_VSETUP 1
13681 +#define VC_CAT_VHOST 2
13683 +#define VC_CAT_DEVICE 6
13685 +#define VC_CAT_VPROC 9
13686 +#define VC_CAT_PROCALT 10
13687 +#define VC_CAT_PROCMIG 11
13688 +#define VC_CAT_PROCTRL 12
13690 +#define VC_CAT_SCHED 14
13691 +#define VC_CAT_MEMCTRL 20
13693 +#define VC_CAT_VNET 25
13694 +#define VC_CAT_NETALT 26
13695 +#define VC_CAT_NETMIG 27
13696 +#define VC_CAT_NETCTRL 28
13698 +#define VC_CAT_TAGMIG 35
13699 +#define VC_CAT_DLIMIT 36
13700 +#define VC_CAT_INODE 38
13702 +#define VC_CAT_VSTAT 40
13703 +#define VC_CAT_VINFO 46
13704 +#define VC_CAT_EVENT 48
13706 +#define VC_CAT_FLAGS 52
13707 +#define VC_CAT_VSPACE 54
13708 +#define VC_CAT_DEBUG 56
13709 +#define VC_CAT_RLIMIT 60
13711 +#define VC_CAT_SYSTEST 61
13712 +#define VC_CAT_COMPAT 63
13714 +/* query version */
13716 +#define VCMD_get_version VC_CMD(VERSION, 0, 0)
13717 +#define VCMD_get_vci VC_CMD(VERSION, 1, 0)
13719 +#endif /* _UAPI_VS_SWITCH_H */
13720 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/tag_cmd.h linux-3.9.4-vs2.3.6.1/include/uapi/vserver/tag_cmd.h
13721 --- linux-3.9.4/include/uapi/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
13722 +++ linux-3.9.4-vs2.3.6.1/include/uapi/vserver/tag_cmd.h 2013-05-31 14:47:11.000000000 +0000
13724 +#ifndef _UAPI_VS_TAG_CMD_H
13725 +#define _UAPI_VS_TAG_CMD_H
13728 +/* vinfo commands */
13730 +#define VCMD_task_tag VC_CMD(VINFO, 3, 0)
13733 +/* context commands */
13735 +#define VCMD_tag_migrate VC_CMD(TAGMIG, 1, 0)
13737 +#endif /* _UAPI_VS_TAG_CMD_H */
13738 diff -NurpP --minimal linux-3.9.4/init/Kconfig linux-3.9.4-vs2.3.6.1/init/Kconfig
13739 --- linux-3.9.4/init/Kconfig 2013-05-31 13:45:29.000000000 +0000
13740 +++ linux-3.9.4-vs2.3.6.1/init/Kconfig 2013-05-31 14:47:11.000000000 +0000
13741 @@ -760,6 +760,7 @@ config NUMA_BALANCING
13743 boolean "Control Group support"
13747 This option adds support for grouping sets of processes together, for
13748 use with process control subsystems such as Cpusets, CFS, memory
13749 @@ -1022,6 +1023,7 @@ config IPC_NS
13751 bool "User namespace"
13752 depends on UIDGID_CONVERTED
13753 + depends on VSERVER_DISABLED
13754 select UIDGID_STRICT_TYPE_CHECKS
13757 diff -NurpP --minimal linux-3.9.4/init/main.c linux-3.9.4-vs2.3.6.1/init/main.c
13758 --- linux-3.9.4/init/main.c 2013-05-31 13:45:29.000000000 +0000
13759 +++ linux-3.9.4-vs2.3.6.1/init/main.c 2013-05-31 15:09:17.000000000 +0000
13761 #include <linux/ptrace.h>
13762 #include <linux/blkdev.h>
13763 #include <linux/elevator.h>
13764 +#include <linux/vserver/percpu.h>
13766 #include <asm/io.h>
13767 #include <asm/bugs.h>
13768 diff -NurpP --minimal linux-3.9.4/ipc/mqueue.c linux-3.9.4-vs2.3.6.1/ipc/mqueue.c
13769 --- linux-3.9.4/ipc/mqueue.c 2013-05-31 13:45:29.000000000 +0000
13770 +++ linux-3.9.4-vs2.3.6.1/ipc/mqueue.c 2013-05-31 14:47:11.000000000 +0000
13772 #include <linux/ipc_namespace.h>
13773 #include <linux/user_namespace.h>
13774 #include <linux/slab.h>
13775 +#include <linux/vs_context.h>
13776 +#include <linux/vs_limit.h>
13778 #include <net/sock.h>
13780 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13781 struct pid* notify_owner;
13782 struct user_namespace *notify_user_ns;
13783 struct user_struct *user; /* user who created, for accounting */
13784 + struct vx_info *vxi;
13785 struct sock *notify_sock;
13786 struct sk_buff *notify_cookie;
13788 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13789 if (S_ISREG(mode)) {
13790 struct mqueue_inode_info *info;
13791 unsigned long mq_bytes, mq_treesize;
13792 + struct vx_info *vxi = current_vx_info();
13794 inode->i_fop = &mqueue_file_operations;
13795 inode->i_size = FILENT_SIZE;
13796 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13797 info->notify_user_ns = NULL;
13799 info->user = NULL; /* set when all is ok */
13800 + info->vxi = NULL;
13801 info->msg_tree = RB_ROOT;
13802 info->node_cache = NULL;
13803 memset(&info->attr, 0, sizeof(info->attr));
13804 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13806 spin_lock(&mq_lock);
13807 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13808 - u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13809 + u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13810 + !vx_ipcmsg_avail(vxi, mq_bytes)) {
13811 spin_unlock(&mq_lock);
13812 /* mqueue_evict_inode() releases info->messages */
13816 u->mq_bytes += mq_bytes;
13817 + vx_ipcmsg_add(vxi, u, mq_bytes);
13818 spin_unlock(&mq_lock);
13821 info->user = get_uid(u);
13822 + info->vxi = get_vx_info(vxi);
13823 } else if (S_ISDIR(mode)) {
13825 /* Some things misbehave if size == 0 on a directory */
13826 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13830 + struct vx_info *vxi = info->vxi;
13832 spin_lock(&mq_lock);
13833 user->mq_bytes -= mq_bytes;
13834 + vx_ipcmsg_sub(vxi, user, mq_bytes);
13836 * get_ns_from_inode() ensures that the
13837 * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13838 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13840 ipc_ns->mq_queues_count--;
13841 spin_unlock(&mq_lock);
13842 + put_vx_info(vxi);
13846 diff -NurpP --minimal linux-3.9.4/ipc/msg.c linux-3.9.4-vs2.3.6.1/ipc/msg.c
13847 --- linux-3.9.4/ipc/msg.c 2013-05-31 13:45:29.000000000 +0000
13848 +++ linux-3.9.4-vs2.3.6.1/ipc/msg.c 2013-05-31 14:47:11.000000000 +0000
13850 #include <linux/rwsem.h>
13851 #include <linux/nsproxy.h>
13852 #include <linux/ipc_namespace.h>
13853 +#include <linux/vs_base.h>
13855 #include <asm/current.h>
13856 #include <asm/uaccess.h>
13857 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
13859 msq->q_perm.mode = msgflg & S_IRWXUGO;
13860 msq->q_perm.key = key;
13861 + msq->q_perm.xid = vx_current_xid();
13863 msq->q_perm.security = NULL;
13864 retval = security_msg_queue_alloc(msq);
13865 diff -NurpP --minimal linux-3.9.4/ipc/sem.c linux-3.9.4-vs2.3.6.1/ipc/sem.c
13866 --- linux-3.9.4/ipc/sem.c 2012-12-11 03:30:57.000000000 +0000
13867 +++ linux-3.9.4-vs2.3.6.1/ipc/sem.c 2013-05-31 14:47:11.000000000 +0000
13869 #include <linux/rwsem.h>
13870 #include <linux/nsproxy.h>
13871 #include <linux/ipc_namespace.h>
13872 +#include <linux/vs_base.h>
13873 +#include <linux/vs_limit.h>
13875 #include <asm/uaccess.h>
13877 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
13879 sma->sem_perm.mode = (semflg & S_IRWXUGO);
13880 sma->sem_perm.key = key;
13881 + sma->sem_perm.xid = vx_current_xid();
13883 sma->sem_perm.security = NULL;
13884 retval = security_sem_alloc(sma);
13885 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
13888 ns->used_sems += nsems;
13889 + /* FIXME: obsoleted? */
13890 + vx_semary_inc(sma);
13891 + vx_nsems_add(sma, nsems);
13893 sma->sem_base = (struct sem *) &sma[1];
13895 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
13897 wake_up_sem_queue_do(&tasks);
13898 ns->used_sems -= sma->sem_nsems;
13899 + /* FIXME: obsoleted? */
13900 + vx_nsems_sub(sma, sma->sem_nsems);
13901 + vx_semary_dec(sma);
13902 security_sem_free(sma);
13903 ipc_rcu_putref(sma);
13905 diff -NurpP --minimal linux-3.9.4/ipc/shm.c linux-3.9.4-vs2.3.6.1/ipc/shm.c
13906 --- linux-3.9.4/ipc/shm.c 2013-05-31 14:22:27.000000000 +0000
13907 +++ linux-3.9.4-vs2.3.6.1/ipc/shm.c 2013-05-31 14:47:11.000000000 +0000
13909 #include <linux/nsproxy.h>
13910 #include <linux/mount.h>
13911 #include <linux/ipc_namespace.h>
13912 +#include <linux/vs_context.h>
13913 +#include <linux/vs_limit.h>
13915 #include <asm/uaccess.h>
13917 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
13919 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13921 - ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13922 + struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13923 + int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13925 + vx_ipcshm_sub(vxi, shp, numpages);
13926 + ns->shm_tot -= numpages;
13930 if (!is_file_hugepages(shp->shm_file))
13931 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
13933 fput (shp->shm_file);
13934 security_shm_free(shp);
13935 + put_vx_info(vxi);
13936 ipc_rcu_putref(shp);
13939 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
13940 if (ns->shm_tot + numpages > ns->shm_ctlall)
13943 + if (!vx_ipcshm_avail(current_vx_info(), numpages))
13946 shp = ipc_rcu_alloc(sizeof(*shp));
13950 shp->shm_perm.key = key;
13951 + shp->shm_perm.xid = vx_current_xid();
13952 shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13953 shp->mlock_user = NULL;
13955 @@ -544,6 +556,7 @@ static int newseg(struct ipc_namespace *
13956 ns->shm_tot += numpages;
13957 error = shp->shm_perm.id;
13959 + vx_ipcshm_add(current_vx_info(), key, numpages);
13963 diff -NurpP --minimal linux-3.9.4/kernel/Makefile linux-3.9.4-vs2.3.6.1/kernel/Makefile
13964 --- linux-3.9.4/kernel/Makefile 2013-05-31 14:22:27.000000000 +0000
13965 +++ linux-3.9.4-vs2.3.6.1/kernel/Makefile 2013-05-31 14:47:11.000000000 +0000
13966 @@ -24,6 +24,7 @@ endif
13972 obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13973 obj-$(CONFIG_FREEZER) += freezer.o
13974 diff -NurpP --minimal linux-3.9.4/kernel/auditsc.c linux-3.9.4-vs2.3.6.1/kernel/auditsc.c
13975 --- linux-3.9.4/kernel/auditsc.c 2013-05-31 14:22:27.000000000 +0000
13976 +++ linux-3.9.4-vs2.3.6.1/kernel/auditsc.c 2013-05-31 14:47:11.000000000 +0000
13977 @@ -2315,7 +2315,7 @@ int audit_set_loginuid(kuid_t loginuid)
13978 if (audit_loginuid_set(task))
13980 #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13981 - if (!capable(CAP_AUDIT_CONTROL))
13982 + if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13984 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13986 diff -NurpP --minimal linux-3.9.4/kernel/capability.c linux-3.9.4-vs2.3.6.1/kernel/capability.c
13987 --- linux-3.9.4/kernel/capability.c 2013-05-31 13:45:29.000000000 +0000
13988 +++ linux-3.9.4-vs2.3.6.1/kernel/capability.c 2013-05-31 14:47:11.000000000 +0000
13990 #include <linux/syscalls.h>
13991 #include <linux/pid_namespace.h>
13992 #include <linux/user_namespace.h>
13993 +#include <linux/vs_context.h>
13994 #include <asm/uaccess.h>
13997 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14003 * The only thing that can change the capabilities of the current
14004 * process is the current process. As such, we can't be in this code
14005 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
14009 +#include <linux/vserver/base.h>
14012 * has_capability_noaudit - Does a task have a capability (unaudited) in the
14014 diff -NurpP --minimal linux-3.9.4/kernel/compat.c linux-3.9.4-vs2.3.6.1/kernel/compat.c
14015 --- linux-3.9.4/kernel/compat.c 2013-05-31 13:45:29.000000000 +0000
14016 +++ linux-3.9.4-vs2.3.6.1/kernel/compat.c 2013-05-31 14:47:11.000000000 +0000
14018 #include <linux/times.h>
14019 #include <linux/ptrace.h>
14020 #include <linux/gfp.h>
14021 +#include <linux/vs_time.h>
14023 #include <asm/uaccess.h>
14025 @@ -1059,7 +1060,7 @@ asmlinkage long compat_sys_stime(compat_
14029 - do_settimeofday(&tv);
14030 + vx_settimeofday(&tv);
14034 diff -NurpP --minimal linux-3.9.4/kernel/cred.c linux-3.9.4-vs2.3.6.1/kernel/cred.c
14035 --- linux-3.9.4/kernel/cred.c 2013-02-19 13:58:56.000000000 +0000
14036 +++ linux-3.9.4-vs2.3.6.1/kernel/cred.c 2013-05-31 14:47:11.000000000 +0000
14037 @@ -56,31 +56,6 @@ struct cred init_cred = {
14038 .group_info = &init_groups,
14041 -static inline void set_cred_subscribers(struct cred *cred, int n)
14043 -#ifdef CONFIG_DEBUG_CREDENTIALS
14044 - atomic_set(&cred->subscribers, n);
14048 -static inline int read_cred_subscribers(const struct cred *cred)
14050 -#ifdef CONFIG_DEBUG_CREDENTIALS
14051 - return atomic_read(&cred->subscribers);
14057 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14059 -#ifdef CONFIG_DEBUG_CREDENTIALS
14060 - struct cred *cred = (struct cred *) _cred;
14062 - atomic_add(n, &cred->subscribers);
14067 * The RCU callback to actually dispose of a set of credentials
14069 @@ -232,21 +207,16 @@ error:
14071 * Call commit_creds() or abort_creds() to clean up.
14073 -struct cred *prepare_creds(void)
14074 +struct cred *__prepare_creds(const struct cred *old)
14076 - struct task_struct *task = current;
14077 - const struct cred *old;
14080 - validate_process_creds();
14082 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14086 kdebug("prepare_creds() alloc %p", new);
14088 - old = task->cred;
14089 memcpy(new, old, sizeof(struct cred));
14091 atomic_set(&new->usage, 1);
14092 @@ -275,6 +245,13 @@ error:
14097 +struct cred *prepare_creds(void)
14099 + validate_process_creds();
14101 + return __prepare_creds(current->cred);
14103 EXPORT_SYMBOL(prepare_creds);
14106 diff -NurpP --minimal linux-3.9.4/kernel/exit.c linux-3.9.4-vs2.3.6.1/kernel/exit.c
14107 --- linux-3.9.4/kernel/exit.c 2013-05-31 13:45:29.000000000 +0000
14108 +++ linux-3.9.4-vs2.3.6.1/kernel/exit.c 2013-05-31 14:47:11.000000000 +0000
14110 #include <linux/fs_struct.h>
14111 #include <linux/init_task.h>
14112 #include <linux/perf_event.h>
14113 +#include <linux/vs_limit.h>
14114 +#include <linux/vs_context.h>
14115 +#include <linux/vs_network.h>
14116 +#include <linux/vs_pid.h>
14117 #include <trace/events/sched.h>
14118 #include <linux/hw_breakpoint.h>
14119 #include <linux/oom.h>
14120 @@ -514,15 +518,25 @@ static struct task_struct *find_new_reap
14121 __acquires(&tasklist_lock)
14123 struct pid_namespace *pid_ns = task_active_pid_ns(father);
14124 - struct task_struct *thread;
14125 + struct vx_info *vxi = task_get_vx_info(father);
14126 + struct task_struct *thread = father;
14127 + struct task_struct *reaper;
14130 while_each_thread(father, thread) {
14131 if (thread->flags & PF_EXITING)
14133 if (unlikely(pid_ns->child_reaper == father))
14134 pid_ns->child_reaper = thread;
14140 + reaper = pid_ns->child_reaper;
14142 + BUG_ON(!vxi->vx_reaper);
14143 + if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14144 + vxi->vx_reaper != father)
14145 + reaper = vxi->vx_reaper;
14148 if (unlikely(pid_ns->child_reaper == father)) {
14149 @@ -560,7 +574,9 @@ static struct task_struct *find_new_reap
14153 - return pid_ns->child_reaper;
14155 + put_vx_info(vxi);
14160 @@ -611,10 +627,15 @@ static void forget_original_parent(struc
14161 list_for_each_entry_safe(p, n, &father->children, sibling) {
14162 struct task_struct *t = p;
14164 - t->real_parent = reaper;
14165 + struct task_struct *new_parent = reaper;
14167 + if (unlikely(p == reaper))
14168 + new_parent = task_active_pid_ns(p)->child_reaper;
14170 + t->real_parent = new_parent;
14171 if (t->parent == father) {
14173 - t->parent = t->real_parent;
14174 + t->parent = new_parent;
14176 if (t->pdeath_signal)
14177 group_send_sig_info(t->pdeath_signal,
14178 @@ -821,6 +842,9 @@ void do_exit(long code)
14180 ptrace_put_breakpoints(tsk);
14182 + /* needs to stay before exit_notify() */
14183 + exit_vx_info_early(tsk, code);
14185 exit_notify(tsk, group_dead);
14188 @@ -874,10 +898,15 @@ void do_exit(long code)
14190 raw_spin_unlock_wait(&tsk->pi_lock);
14192 + /* needs to stay after exit_notify() */
14193 + exit_vx_info(tsk, code);
14194 + exit_nx_info(tsk);
14196 /* causes final put_task_struct in finish_task_switch(). */
14197 tsk->state = TASK_DEAD;
14198 tsk->flags |= PF_NOFREEZE; /* tell freezer to ignore us */
14200 + printk("bad task: %p [%lx]\n", current, current->state);
14202 /* Avoid "noreturn function does return". */
14204 diff -NurpP --minimal linux-3.9.4/kernel/fork.c linux-3.9.4-vs2.3.6.1/kernel/fork.c
14205 --- linux-3.9.4/kernel/fork.c 2013-05-31 13:45:29.000000000 +0000
14206 +++ linux-3.9.4-vs2.3.6.1/kernel/fork.c 2013-05-31 14:47:11.000000000 +0000
14208 #include <linux/khugepaged.h>
14209 #include <linux/signalfd.h>
14210 #include <linux/uprobes.h>
14211 +#include <linux/vs_context.h>
14212 +#include <linux/vs_network.h>
14213 +#include <linux/vs_limit.h>
14215 #include <asm/pgtable.h>
14216 #include <asm/pgalloc.h>
14217 @@ -210,6 +213,8 @@ void free_task(struct task_struct *tsk)
14218 arch_release_thread_info(tsk->stack);
14219 free_thread_info(tsk->stack);
14220 rt_mutex_debug_task_free(tsk);
14221 + clr_vx_info(&tsk->vx_info);
14222 + clr_nx_info(&tsk->nx_info);
14223 ftrace_graph_exit_task(tsk);
14224 put_seccomp_filter(tsk);
14225 arch_release_task_struct(tsk);
14226 @@ -547,6 +552,7 @@ static struct mm_struct *mm_init(struct
14227 if (likely(!mm_alloc_pgd(mm))) {
14229 mmu_notifier_mm_init(mm);
14230 + set_vx_info(&mm->mm_vx_info, p->vx_info);
14234 @@ -599,6 +605,7 @@ void __mmdrop(struct mm_struct *mm)
14235 destroy_context(mm);
14236 mmu_notifier_mm_destroy(mm);
14238 + clr_vx_info(&mm->mm_vx_info);
14241 EXPORT_SYMBOL_GPL(__mmdrop);
14242 @@ -818,6 +825,7 @@ struct mm_struct *dup_mm(struct task_str
14245 memcpy(mm, oldmm, sizeof(*mm));
14246 + mm->mm_vx_info = NULL;
14247 mm_init_cpumask(mm);
14249 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14250 @@ -859,6 +867,7 @@ fail_nocontext:
14251 * If init_new_context() failed, we cannot use mmput() to free the mm
14252 * because it calls destroy_context()
14254 + clr_vx_info(&mm->mm_vx_info);
14258 @@ -1137,6 +1146,8 @@ static struct task_struct *copy_process(
14261 struct task_struct *p;
14262 + struct vx_info *vxi;
14263 + struct nx_info *nxi;
14265 if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14266 return ERR_PTR(-EINVAL);
14267 @@ -1195,7 +1206,12 @@ static struct task_struct *copy_process(
14268 DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14269 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14271 + init_vx_info(&p->vx_info, current_vx_info());
14272 + init_nx_info(&p->nx_info, current_nx_info());
14275 + if (!vx_nproc_avail(1))
14276 + goto bad_fork_free;
14277 if (atomic_read(&p->real_cred->user->processes) >=
14278 task_rlimit(p, RLIMIT_NPROC)) {
14279 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14280 @@ -1472,6 +1488,18 @@ static struct task_struct *copy_process(
14283 spin_unlock(¤t->sighand->siglock);
14285 + /* p is copy of current */
14286 + vxi = p->vx_info;
14288 + claim_vx_info(vxi, p);
14289 + atomic_inc(&vxi->cvirt.nr_threads);
14290 + atomic_inc(&vxi->cvirt.total_forks);
14293 + nxi = p->nx_info;
14295 + claim_nx_info(nxi, p);
14296 write_unlock_irq(&tasklist_lock);
14297 proc_fork_connector(p);
14298 cgroup_post_fork(p);
14299 diff -NurpP --minimal linux-3.9.4/kernel/kthread.c linux-3.9.4-vs2.3.6.1/kernel/kthread.c
14300 --- linux-3.9.4/kernel/kthread.c 2013-05-31 13:45:30.000000000 +0000
14301 +++ linux-3.9.4-vs2.3.6.1/kernel/kthread.c 2013-05-31 14:47:11.000000000 +0000
14303 #include <linux/slab.h>
14304 #include <linux/freezer.h>
14305 #include <linux/ptrace.h>
14306 +#include <linux/vs_pid.h>
14307 #include <trace/events/sched.h>
14309 static DEFINE_SPINLOCK(kthread_create_lock);
14310 diff -NurpP --minimal linux-3.9.4/kernel/nsproxy.c linux-3.9.4-vs2.3.6.1/kernel/nsproxy.c
14311 --- linux-3.9.4/kernel/nsproxy.c 2013-05-31 13:45:30.000000000 +0000
14312 +++ linux-3.9.4-vs2.3.6.1/kernel/nsproxy.c 2013-05-31 19:28:43.000000000 +0000
14313 @@ -20,11 +20,14 @@
14314 #include <linux/mnt_namespace.h>
14315 #include <linux/utsname.h>
14316 #include <linux/pid_namespace.h>
14317 +#include <linux/vserver/global.h>
14318 +#include <linux/vserver/debug.h>
14319 #include <net/net_namespace.h>
14320 #include <linux/ipc_namespace.h>
14321 #include <linux/proc_fs.h>
14322 #include <linux/file.h>
14323 #include <linux/syscalls.h>
14324 +#include "../fs/mount.h"
14326 static struct kmem_cache *nsproxy_cachep;
14328 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14329 struct nsproxy *nsproxy;
14331 nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14334 atomic_set(&nsproxy->count, 1);
14335 + atomic_inc(&vs_global_nsproxy);
14337 + vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14341 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
14342 * Return the newly created nsproxy. Do not attach this to the task,
14343 * leave it to the caller to do proper locking and attach it to task.
14345 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14346 - struct task_struct *tsk, struct user_namespace *user_ns,
14347 - struct fs_struct *new_fs)
14348 +static struct nsproxy *unshare_namespaces(
14349 + unsigned long flags,
14350 + struct nsproxy *orig,
14351 + struct fs_struct *new_fs,
14352 + struct user_namespace *new_user,
14353 + struct pid_namespace *new_pid)
14355 struct nsproxy *new_nsp;
14357 @@ -67,31 +76,31 @@ static struct nsproxy *create_new_namesp
14359 return ERR_PTR(-ENOMEM);
14361 - new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
14362 + new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
14363 if (IS_ERR(new_nsp->mnt_ns)) {
14364 err = PTR_ERR(new_nsp->mnt_ns);
14368 - new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
14369 + new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
14370 if (IS_ERR(new_nsp->uts_ns)) {
14371 err = PTR_ERR(new_nsp->uts_ns);
14375 - new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
14376 + new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
14377 if (IS_ERR(new_nsp->ipc_ns)) {
14378 err = PTR_ERR(new_nsp->ipc_ns);
14382 - new_nsp->pid_ns = copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns);
14383 + new_nsp->pid_ns = copy_pid_ns(flags, new_user, new_pid);
14384 if (IS_ERR(new_nsp->pid_ns)) {
14385 err = PTR_ERR(new_nsp->pid_ns);
14389 - new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
14390 + new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
14391 if (IS_ERR(new_nsp->net_ns)) {
14392 err = PTR_ERR(new_nsp->net_ns);
14394 @@ -116,6 +125,41 @@ out_ns:
14395 return ERR_PTR(err);
14398 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14399 + struct task_struct *tsk, struct user_namespace *user_ns,
14400 + struct fs_struct *new_fs)
14403 + return unshare_namespaces(flags, tsk->nsproxy,
14404 + new_fs, user_ns, task_active_pid_ns(tsk));
14408 + * copies the nsproxy, setting refcount to 1, and grabbing a
14409 + * reference to all contained namespaces.
14411 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14413 + struct nsproxy *ns = create_nsproxy();
14416 + memcpy(ns, orig, sizeof(struct nsproxy));
14417 + atomic_set(&ns->count, 1);
14420 + get_mnt_ns(ns->mnt_ns);
14422 + get_uts_ns(ns->uts_ns);
14424 + get_ipc_ns(ns->ipc_ns);
14426 + get_pid_ns(ns->pid_ns);
14428 + get_net(ns->net_ns);
14434 * called from clone. This now handles copy for nsproxy and all
14435 * namespaces therein.
14436 @@ -124,9 +168,12 @@ int copy_namespaces(unsigned long flags,
14438 struct nsproxy *old_ns = tsk->nsproxy;
14439 struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
14440 - struct nsproxy *new_ns;
14441 + struct nsproxy *new_ns = NULL;
14444 + vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14445 + flags, tsk, old_ns);
14450 @@ -136,7 +183,7 @@ int copy_namespaces(unsigned long flags,
14451 CLONE_NEWPID | CLONE_NEWNET)))
14454 - if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
14455 + if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags)) {
14459 @@ -163,6 +210,9 @@ int copy_namespaces(unsigned long flags,
14462 put_nsproxy(old_ns);
14463 + vxdprintk(VXD_CBIT(space, 3),
14464 + "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14465 + flags, tsk, old_ns, err, new_ns);
14469 @@ -176,7 +226,9 @@ void free_nsproxy(struct nsproxy *ns)
14470 put_ipc_ns(ns->ipc_ns);
14472 put_pid_ns(ns->pid_ns);
14473 - put_net(ns->net_ns);
14475 + put_net(ns->net_ns);
14476 + atomic_dec(&vs_global_nsproxy);
14477 kmem_cache_free(nsproxy_cachep, ns);
14480 @@ -190,12 +242,16 @@ int unshare_nsproxy_namespaces(unsigned
14481 struct user_namespace *user_ns;
14484 + vxdprintk(VXD_CBIT(space, 4),
14485 + "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14486 + unshare_flags, current->nsproxy);
14488 if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14489 CLONE_NEWNET | CLONE_NEWPID)))
14492 user_ns = new_cred ? new_cred->user_ns : current_user_ns();
14493 - if (!ns_capable(user_ns, CAP_SYS_ADMIN))
14494 + if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
14497 *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
14498 diff -NurpP --minimal linux-3.9.4/kernel/pid.c linux-3.9.4-vs2.3.6.1/kernel/pid.c
14499 --- linux-3.9.4/kernel/pid.c 2013-05-31 13:45:30.000000000 +0000
14500 +++ linux-3.9.4-vs2.3.6.1/kernel/pid.c 2013-05-31 15:24:34.000000000 +0000
14502 #include <linux/init_task.h>
14503 #include <linux/syscalls.h>
14504 #include <linux/proc_fs.h>
14505 +#include <linux/vs_pid.h>
14507 #define pid_hashfn(nr, ns) \
14508 hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14509 @@ -364,7 +365,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14511 struct pid *find_vpid(int nr)
14513 - return find_pid_ns(nr, task_active_pid_ns(current));
14514 + return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
14516 EXPORT_SYMBOL_GPL(find_vpid);
14518 @@ -424,6 +425,9 @@ void transfer_pid(struct task_struct *ol
14519 struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14521 struct task_struct *result = NULL;
14523 + if (type == PIDTYPE_REALPID)
14524 + type = PIDTYPE_PID;
14526 struct hlist_node *first;
14527 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14528 @@ -443,7 +447,7 @@ struct task_struct *find_task_by_pid_ns(
14529 rcu_lockdep_assert(rcu_read_lock_held(),
14530 "find_task_by_pid_ns() needs rcu_read_lock()"
14532 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14533 + return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14536 struct task_struct *find_task_by_vpid(pid_t vnr)
14537 @@ -487,7 +491,7 @@ struct pid *find_get_pid(pid_t nr)
14539 EXPORT_SYMBOL_GPL(find_get_pid);
14541 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14542 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14546 @@ -501,6 +505,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14548 EXPORT_SYMBOL_GPL(pid_nr_ns);
14550 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14552 + return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14555 pid_t pid_vnr(struct pid *pid)
14557 return pid_nr_ns(pid, task_active_pid_ns(current));
14558 diff -NurpP --minimal linux-3.9.4/kernel/pid_namespace.c linux-3.9.4-vs2.3.6.1/kernel/pid_namespace.c
14559 --- linux-3.9.4/kernel/pid_namespace.c 2013-05-31 13:45:30.000000000 +0000
14560 +++ linux-3.9.4-vs2.3.6.1/kernel/pid_namespace.c 2013-05-31 17:59:48.000000000 +0000
14562 #include <linux/proc_fs.h>
14563 #include <linux/reboot.h>
14564 #include <linux/export.h>
14565 +#include <linux/vserver/global.h>
14567 #define BITS_PER_PAGE (PAGE_SIZE*8)
14569 @@ -112,6 +113,7 @@ static struct pid_namespace *create_pid_
14572 kref_init(&ns->kref);
14573 + atomic_inc(&vs_global_pid_ns);
14575 ns->parent = get_pid_ns(parent_pid_ns);
14576 ns->user_ns = get_user_ns(user_ns);
14577 @@ -142,6 +144,7 @@ static void destroy_pid_namespace(struct
14578 for (i = 0; i < PIDMAP_ENTRIES; i++)
14579 kfree(ns->pidmap[i].page);
14580 put_user_ns(ns->user_ns);
14581 + atomic_dec(&vs_global_pid_ns);
14582 kmem_cache_free(pid_ns_cachep, ns);
14585 diff -NurpP --minimal linux-3.9.4/kernel/posix-timers.c linux-3.9.4-vs2.3.6.1/kernel/posix-timers.c
14586 --- linux-3.9.4/kernel/posix-timers.c 2013-05-31 13:45:30.000000000 +0000
14587 +++ linux-3.9.4-vs2.3.6.1/kernel/posix-timers.c 2013-05-31 14:47:11.000000000 +0000
14589 #include <linux/wait.h>
14590 #include <linux/workqueue.h>
14591 #include <linux/export.h>
14592 +#include <linux/vs_context.h>
14595 * Management arrays for POSIX timers. Timers are kept in slab memory
14596 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14598 struct task_struct *task;
14599 int shared, ret = -1;
14602 * FIXME: if ->sigq is queued we can race with
14603 * dequeue_signal()->do_schedule_next_timer().
14604 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14606 task = pid_task(timr->it_pid, PIDTYPE_PID);
14608 + struct vx_info_save vxis;
14609 + struct vx_info *vxi;
14611 + vxi = get_vx_info(task->vx_info);
14612 + enter_vx_info(vxi, &vxis);
14613 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14614 ret = send_sigqueue(timr->sigq, task, shared);
14615 + leave_vx_info(&vxis);
14616 + put_vx_info(vxi);
14620 /* If we failed to send the signal the timer stops. */
14623 diff -NurpP --minimal linux-3.9.4/kernel/printk.c linux-3.9.4-vs2.3.6.1/kernel/printk.c
14624 --- linux-3.9.4/kernel/printk.c 2013-05-31 13:45:30.000000000 +0000
14625 +++ linux-3.9.4-vs2.3.6.1/kernel/printk.c 2013-05-31 15:23:35.000000000 +0000
14627 #include <linux/rculist.h>
14628 #include <linux/poll.h>
14629 #include <linux/irq_work.h>
14630 +#include <linux/vs_cvirt.h>
14632 #include <asm/uaccess.h>
14634 @@ -841,7 +842,7 @@ static int check_syslog_permissions(int
14637 if (syslog_action_restricted(type)) {
14638 - if (capable(CAP_SYSLOG))
14639 + if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14641 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14642 if (capable(CAP_SYS_ADMIN)) {
14643 @@ -1135,12 +1136,9 @@ int do_syslog(int type, char __user *buf
14648 - case SYSLOG_ACTION_CLOSE: /* Close log */
14650 - case SYSLOG_ACTION_OPEN: /* Open log */
14652 - case SYSLOG_ACTION_READ: /* Read from log */
14653 + if ((type == SYSLOG_ACTION_READ) ||
14654 + (type == SYSLOG_ACTION_READ_ALL) ||
14655 + (type == SYSLOG_ACTION_READ_CLEAR)) {
14657 if (!buf || len < 0)
14659 @@ -1151,6 +1149,16 @@ int do_syslog(int type, char __user *buf
14664 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
14665 + return vx_do_syslog(type, buf, len);
14668 + case SYSLOG_ACTION_CLOSE: /* Close log */
14670 + case SYSLOG_ACTION_OPEN: /* Open log */
14672 + case SYSLOG_ACTION_READ: /* Read from log */
14673 error = wait_event_interruptible(log_wait,
14674 syslog_seq != log_next_seq);
14676 @@ -1163,16 +1171,6 @@ int do_syslog(int type, char __user *buf
14678 /* Read last kernel messages */
14679 case SYSLOG_ACTION_READ_ALL:
14681 - if (!buf || len < 0)
14686 - if (!access_ok(VERIFY_WRITE, buf, len)) {
14690 error = syslog_print_all(buf, len, clear);
14692 /* Clear ring buffer */
14693 diff -NurpP --minimal linux-3.9.4/kernel/ptrace.c linux-3.9.4-vs2.3.6.1/kernel/ptrace.c
14694 --- linux-3.9.4/kernel/ptrace.c 2013-05-31 13:45:30.000000000 +0000
14695 +++ linux-3.9.4-vs2.3.6.1/kernel/ptrace.c 2013-05-31 15:22:34.000000000 +0000
14697 #include <linux/syscalls.h>
14698 #include <linux/uaccess.h>
14699 #include <linux/regset.h>
14700 +#include <linux/vs_context.h>
14701 #include <linux/hw_breakpoint.h>
14702 #include <linux/cn_proc.h>
14704 @@ -261,6 +262,11 @@ ok:
14708 + if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14710 + if (!vx_check(task->xid, VS_IDENT) &&
14711 + !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14713 return security_ptrace_access_check(task, mode);
14716 diff -NurpP --minimal linux-3.9.4/kernel/sched/core.c linux-3.9.4-vs2.3.6.1/kernel/sched/core.c
14717 --- linux-3.9.4/kernel/sched/core.c 2013-05-31 13:45:30.000000000 +0000
14718 +++ linux-3.9.4-vs2.3.6.1/kernel/sched/core.c 2013-05-31 15:17:22.000000000 +0000
14720 #include <linux/init_task.h>
14721 #include <linux/binfmts.h>
14722 #include <linux/context_tracking.h>
14723 +#include <linux/vs_sched.h>
14724 +#include <linux/vs_cvirt.h>
14726 #include <asm/switch_to.h>
14727 #include <asm/tlb.h>
14728 @@ -2091,9 +2093,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14730 void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14732 - loads[0] = (avenrun[0] + offset) << shift;
14733 - loads[1] = (avenrun[1] + offset) << shift;
14734 - loads[2] = (avenrun[2] + offset) << shift;
14735 + if (vx_flags(VXF_VIRT_LOAD, 0)) {
14736 + struct vx_info *vxi = current_vx_info();
14738 + loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14739 + loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14740 + loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14742 + loads[0] = (avenrun[0] + offset) << shift;
14743 + loads[1] = (avenrun[1] + offset) << shift;
14744 + loads[2] = (avenrun[2] + offset) << shift;
14748 static long calc_load_fold_active(struct rq *this_rq)
14749 @@ -3704,7 +3714,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14752 if (increment < 0 && !can_nice(current, nice))
14754 + return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14756 retval = security_task_setnice(current, nice);
14758 diff -NurpP --minimal linux-3.9.4/kernel/sched/cputime.c linux-3.9.4-vs2.3.6.1/kernel/sched/cputime.c
14759 --- linux-3.9.4/kernel/sched/cputime.c 2013-05-31 14:22:27.000000000 +0000
14760 +++ linux-3.9.4-vs2.3.6.1/kernel/sched/cputime.c 2013-05-31 15:17:55.000000000 +0000
14762 #include <linux/kernel_stat.h>
14763 #include <linux/static_key.h>
14764 #include <linux/context_tracking.h>
14765 +#include <linux/vs_sched.h>
14769 @@ -151,14 +152,17 @@ static inline void task_group_account_fi
14770 void account_user_time(struct task_struct *p, cputime_t cputime,
14771 cputime_t cputime_scaled)
14773 + struct vx_info *vxi = p->vx_info; /* p is _always_ current */
14774 + int nice = (TASK_NICE(p) > 0);
14777 /* Add user time to process. */
14778 p->utime += cputime;
14779 p->utimescaled += cputime_scaled;
14780 + vx_account_user(vxi, cputime, nice);
14781 account_group_user_time(p, cputime);
14783 - index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14784 + index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14786 /* Add user time to cpustat. */
14787 task_group_account_field(p, index, (__force u64) cputime);
14788 @@ -205,9 +209,12 @@ static inline
14789 void __account_system_time(struct task_struct *p, cputime_t cputime,
14790 cputime_t cputime_scaled, int index)
14792 + struct vx_info *vxi = p->vx_info; /* p is _always_ current */
14794 /* Add system time to process. */
14795 p->stime += cputime;
14796 p->stimescaled += cputime_scaled;
14797 + vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14798 account_group_system_time(p, cputime);
14800 /* Add system time to cpustat. */
14801 diff -NurpP --minimal linux-3.9.4/kernel/sched/fair.c linux-3.9.4-vs2.3.6.1/kernel/sched/fair.c
14802 --- linux-3.9.4/kernel/sched/fair.c 2013-05-31 13:45:30.000000000 +0000
14803 +++ linux-3.9.4-vs2.3.6.1/kernel/sched/fair.c 2013-05-31 15:19:37.000000000 +0000
14805 #include <linux/mempolicy.h>
14806 #include <linux/migrate.h>
14807 #include <linux/task_work.h>
14808 +#include <linux/vs_cvirt.h>
14810 #include <trace/events/sched.h>
14812 @@ -1714,6 +1715,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14813 __enqueue_entity(cfs_rq, se);
14816 + if (entity_is_task(se))
14817 + vx_activate_task(task_of(se));
14818 if (cfs_rq->nr_running == 1) {
14819 list_add_leaf_cfs_rq(cfs_rq);
14820 check_enqueue_throttle(cfs_rq);
14821 @@ -1795,6 +1798,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14822 if (se != cfs_rq->curr)
14823 __dequeue_entity(cfs_rq, se);
14825 + if (entity_is_task(se))
14826 + vx_deactivate_task(task_of(se));
14827 account_entity_dequeue(cfs_rq, se);
14830 diff -NurpP --minimal linux-3.9.4/kernel/signal.c linux-3.9.4-vs2.3.6.1/kernel/signal.c
14831 --- linux-3.9.4/kernel/signal.c 2013-05-31 13:45:30.000000000 +0000
14832 +++ linux-3.9.4-vs2.3.6.1/kernel/signal.c 2013-05-31 15:20:05.000000000 +0000
14834 #include <linux/user_namespace.h>
14835 #include <linux/uprobes.h>
14836 #include <linux/compat.h>
14837 +#include <linux/vs_context.h>
14838 +#include <linux/vs_pid.h>
14839 #define CREATE_TRACE_POINTS
14840 #include <trace/events/signal.h>
14842 @@ -789,9 +791,18 @@ static int check_kill_permission(int sig
14846 + vxdprintk(VXD_CBIT(misc, 7),
14847 + "check_kill_permission(%d,%p,%p[#%u,%u])",
14848 + sig, info, t, vx_task_xid(t), t->pid);
14850 if (!valid_signal(sig))
14853 +/* FIXME: needed? if so, why?
14854 + if ((info != SEND_SIG_NOINFO) &&
14855 + (is_si_special(info) || !si_fromuser(info)))
14858 if (!si_fromuser(info))
14861 @@ -815,6 +826,20 @@ static int check_kill_permission(int sig
14866 + if (t->pid == 1 && current->xid)
14870 + /* FIXME: we shouldn't return ESRCH ever, to avoid
14871 + loops, maybe ENOENT or EACCES? */
14872 + if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14873 + vxdprintk(current->xid || VXD_CBIT(misc, 7),
14874 + "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14875 + sig, info, t, vx_task_xid(t), t->pid, current->xid);
14879 return security_task_kill(t, info, sig, 0);
14882 @@ -1351,7 +1376,7 @@ int kill_pid_info(int sig, struct siginf
14885 p = pid_task(pid, PIDTYPE_PID);
14887 + if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14888 error = group_send_sig_info(sig, info, p);
14889 if (unlikely(error == -ESRCH))
14891 @@ -1399,7 +1424,7 @@ int kill_pid_info_as_cred(int sig, struc
14894 p = pid_task(pid, PIDTYPE_PID);
14896 + if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14900 @@ -1451,8 +1476,10 @@ static int kill_something_info(int sig,
14901 struct task_struct * p;
14903 for_each_process(p) {
14904 - if (task_pid_vnr(p) > 1 &&
14905 - !same_thread_group(p, current)) {
14906 + if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14907 + task_pid_vnr(p) > 1 &&
14908 + !same_thread_group(p, current) &&
14909 + !vx_current_initpid(p->pid)) {
14910 int err = group_send_sig_info(sig, info, p);
14913 @@ -2306,6 +2333,11 @@ relock:
14914 !sig_kernel_only(signr))
14917 + /* virtual init is protected against user signals */
14918 + if ((info->si_code == SI_USER) &&
14919 + vx_current_initpid(current->pid))
14922 if (sig_kernel_stop(signr)) {
14924 * The default action is to stop all threads in
14925 diff -NurpP --minimal linux-3.9.4/kernel/softirq.c linux-3.9.4-vs2.3.6.1/kernel/softirq.c
14926 --- linux-3.9.4/kernel/softirq.c 2013-05-31 13:45:30.000000000 +0000
14927 +++ linux-3.9.4-vs2.3.6.1/kernel/softirq.c 2013-05-31 14:47:11.000000000 +0000
14929 #include <linux/smp.h>
14930 #include <linux/smpboot.h>
14931 #include <linux/tick.h>
14932 +#include <linux/vs_context.h>
14934 #define CREATE_TRACE_POINTS
14935 #include <trace/events/irq.h>
14936 diff -NurpP --minimal linux-3.9.4/kernel/sys.c linux-3.9.4-vs2.3.6.1/kernel/sys.c
14937 --- linux-3.9.4/kernel/sys.c 2013-05-31 13:45:30.000000000 +0000
14938 +++ linux-3.9.4-vs2.3.6.1/kernel/sys.c 2013-05-31 15:23:14.000000000 +0000
14940 #include <linux/binfmts.h>
14942 #include <linux/kmsg_dump.h>
14943 +#include <linux/vs_pid.h>
14944 /* Move somewhere else to avoid recompiling? */
14945 #include <generated/utsrelease.h>
14947 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
14950 if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14952 + if (vx_flags(VXF_IGNEG_NICE, 0))
14958 no_nice = security_task_setnice(p, niceval);
14959 @@ -206,6 +210,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14961 pgrp = task_pgrp(current);
14962 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14963 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14965 error = set_one_prio(p, niceval, error);
14966 } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14968 @@ -271,6 +277,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14970 pgrp = task_pgrp(current);
14971 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14972 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14974 niceval = 20 - task_nice(p);
14975 if (niceval > retval)
14977 @@ -424,6 +432,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
14979 static DEFINE_MUTEX(reboot_mutex);
14981 +long vs_reboot(unsigned int, void __user *);
14984 * Reboot system call: for obvious reasons only root may call it,
14985 * and even root needs to set up some magic numbers in the registers
14986 @@ -466,6 +476,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
14987 if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
14988 cmd = LINUX_REBOOT_CMD_HALT;
14990 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
14991 + return vs_reboot(cmd, arg);
14993 mutex_lock(&reboot_mutex);
14995 case LINUX_REBOOT_CMD_RESTART:
14996 @@ -1373,7 +1386,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14998 char tmp[__NEW_UTS_LEN];
15000 - if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15001 + if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15002 + CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15005 if (len < 0 || len > __NEW_UTS_LEN)
15006 @@ -1424,7 +1438,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15008 char tmp[__NEW_UTS_LEN];
15010 - if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15011 + if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15012 + CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15014 if (len < 0 || len > __NEW_UTS_LEN)
15016 @@ -1543,7 +1558,7 @@ int do_prlimit(struct task_struct *tsk,
15017 /* Keep the capable check against init_user_ns until
15018 cgroups can contain all limits */
15019 if (new_rlim->rlim_max > rlim->rlim_max &&
15020 - !capable(CAP_SYS_RESOURCE))
15021 + !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15024 retval = security_task_setrlimit(tsk->group_leader,
15025 @@ -1596,7 +1611,8 @@ static int check_prlimit_permission(stru
15026 gid_eq(cred->gid, tcred->sgid) &&
15027 gid_eq(cred->gid, tcred->gid))
15029 - if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
15030 + if (vx_ns_capable(tcred->user_ns,
15031 + CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15035 diff -NurpP --minimal linux-3.9.4/kernel/sysctl.c linux-3.9.4-vs2.3.6.1/kernel/sysctl.c
15036 --- linux-3.9.4/kernel/sysctl.c 2013-05-31 13:45:30.000000000 +0000
15037 +++ linux-3.9.4-vs2.3.6.1/kernel/sysctl.c 2013-05-31 15:28:39.000000000 +0000
15039 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15040 #include <linux/lockdep.h>
15042 +extern char vshelper_path[];
15043 #ifdef CONFIG_CHR_DEV_SG
15044 #include <scsi/sg.h>
15046 @@ -629,6 +630,13 @@ static struct ctl_table kern_table[] = {
15048 .proc_handler = proc_dostring,
15051 + .procname = "vshelper",
15052 + .data = &vshelper_path,
15055 + .proc_handler = &proc_dostring,
15058 #ifdef CONFIG_CHR_DEV_SG
15060 diff -NurpP --minimal linux-3.9.4/kernel/sysctl_binary.c linux-3.9.4-vs2.3.6.1/kernel/sysctl_binary.c
15061 --- linux-3.9.4/kernel/sysctl_binary.c 2013-05-31 13:45:30.000000000 +0000
15062 +++ linux-3.9.4-vs2.3.6.1/kernel/sysctl_binary.c 2013-05-31 14:47:11.000000000 +0000
15063 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15065 { CTL_INT, KERN_PANIC, "panic" },
15066 { CTL_INT, KERN_REALROOTDEV, "real-root-dev" },
15067 + { CTL_STR, KERN_VSHELPER, "vshelper" },
15069 { CTL_STR, KERN_SPARC_REBOOT, "reboot-cmd" },
15070 { CTL_INT, KERN_CTLALTDEL, "ctrl-alt-del" },
15071 diff -NurpP --minimal linux-3.9.4/kernel/time/timekeeping.c linux-3.9.4-vs2.3.6.1/kernel/time/timekeeping.c
15072 --- linux-3.9.4/kernel/time/timekeeping.c 2013-05-31 13:45:30.000000000 +0000
15073 +++ linux-3.9.4-vs2.3.6.1/kernel/time/timekeeping.c 2013-05-31 15:24:55.000000000 +0000
15075 #include <linux/tick.h>
15076 #include <linux/stop_machine.h>
15077 #include <linux/pvclock_gtod.h>
15078 +#include <linux/vs_time.h>
15081 static struct timekeeper timekeeper;
15082 @@ -594,6 +595,7 @@ void getrawmonotonic(struct timespec *ts
15083 } while (read_seqretry(&tk->lock, seq));
15085 timespec_add_ns(ts, nsecs);
15086 + vx_adjust_timespec(ts);
15088 EXPORT_SYMBOL(getrawmonotonic);
15090 diff -NurpP --minimal linux-3.9.4/kernel/time.c linux-3.9.4-vs2.3.6.1/kernel/time.c
15091 --- linux-3.9.4/kernel/time.c 2013-05-31 13:45:30.000000000 +0000
15092 +++ linux-3.9.4-vs2.3.6.1/kernel/time.c 2013-05-31 14:47:11.000000000 +0000
15094 #include <linux/fs.h>
15095 #include <linux/math64.h>
15096 #include <linux/ptrace.h>
15097 +#include <linux/vs_time.h>
15099 #include <asm/uaccess.h>
15100 #include <asm/unistd.h>
15101 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15105 - do_settimeofday(&tv);
15106 + vx_settimeofday(&tv);
15110 @@ -180,7 +181,7 @@ int do_sys_settimeofday(const struct tim
15114 - return do_settimeofday(tv);
15115 + return vx_settimeofday(tv);
15119 diff -NurpP --minimal linux-3.9.4/kernel/timer.c linux-3.9.4-vs2.3.6.1/kernel/timer.c
15120 --- linux-3.9.4/kernel/timer.c 2013-05-31 14:22:27.000000000 +0000
15121 +++ linux-3.9.4-vs2.3.6.1/kernel/timer.c 2013-05-31 14:47:11.000000000 +0000
15123 #include <linux/sched.h>
15124 #include <linux/sched/sysctl.h>
15125 #include <linux/slab.h>
15126 +#include <linux/vs_base.h>
15127 +#include <linux/vs_cvirt.h>
15128 +#include <linux/vs_pid.h>
15129 +#include <linux/vserver/sched.h>
15131 #include <asm/uaccess.h>
15132 #include <asm/unistd.h>
15133 diff -NurpP --minimal linux-3.9.4/kernel/user_namespace.c linux-3.9.4-vs2.3.6.1/kernel/user_namespace.c
15134 --- linux-3.9.4/kernel/user_namespace.c 2013-05-31 13:45:30.000000000 +0000
15135 +++ linux-3.9.4-vs2.3.6.1/kernel/user_namespace.c 2013-05-31 17:44:56.000000000 +0000
15137 #include <linux/ctype.h>
15138 #include <linux/projid.h>
15139 #include <linux/fs_struct.h>
15140 +#include <linux/vserver/global.h>
15142 static struct kmem_cache *user_ns_cachep __read_mostly;
15144 @@ -91,6 +92,7 @@ int create_user_ns(struct cred *new)
15146 atomic_set(&ns->count, 1);
15147 /* Leave the new->user_ns reference with the new user namespace. */
15148 + atomic_inc(&vs_global_user_ns);
15149 ns->parent = parent_ns;
15152 @@ -835,6 +837,8 @@ static void *userns_get(struct task_stru
15154 static void userns_put(void *ns)
15156 + /* FIXME: maybe move into destroyer? */
15157 + atomic_dec(&vs_global_user_ns);
15161 diff -NurpP --minimal linux-3.9.4/kernel/utsname.c linux-3.9.4-vs2.3.6.1/kernel/utsname.c
15162 --- linux-3.9.4/kernel/utsname.c 2013-05-31 13:45:30.000000000 +0000
15163 +++ linux-3.9.4-vs2.3.6.1/kernel/utsname.c 2013-05-31 15:15:55.000000000 +0000
15164 @@ -16,14 +16,17 @@
15165 #include <linux/slab.h>
15166 #include <linux/user_namespace.h>
15167 #include <linux/proc_fs.h>
15168 +#include <linux/vserver/global.h>
15170 static struct uts_namespace *create_uts_ns(void)
15172 struct uts_namespace *uts_ns;
15174 uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15177 kref_init(&uts_ns->kref);
15178 + atomic_inc(&vs_global_uts_ns);
15183 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
15184 ns = container_of(kref, struct uts_namespace, kref);
15185 put_user_ns(ns->user_ns);
15186 proc_free_inum(ns->proc_inum);
15187 + atomic_dec(&vs_global_uts_ns);
15191 diff -NurpP --minimal linux-3.9.4/kernel/vserver/Kconfig linux-3.9.4-vs2.3.6.1/kernel/vserver/Kconfig
15192 --- linux-3.9.4/kernel/vserver/Kconfig 1970-01-01 00:00:00.000000000 +0000
15193 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/Kconfig 2013-05-31 14:47:11.000000000 +0000
15196 +# Linux VServer configuration
15199 +menu "Linux VServer"
15201 +config VSERVER_AUTO_LBACK
15202 + bool "Automatically Assign Loopback IP"
15205 + Automatically assign a guest specific loopback
15206 + IP and add it to the kernel network stack on
15209 +config VSERVER_AUTO_SINGLE
15210 + bool "Automatic Single IP Special Casing"
15211 + depends on EXPERIMENTAL
15214 + This allows network contexts with a single IP to
15215 + automatically remap 0.0.0.0 bindings to that IP,
15216 + avoiding further network checks and improving
15219 + (note: such guests do not allow to change the ip
15220 + on the fly and do not show loopback addresses)
15222 +config VSERVER_COWBL
15223 + bool "Enable COW Immutable Link Breaking"
15226 + This enables the COW (Copy-On-Write) link break code.
15227 + It allows you to treat unified files like normal files
15228 + when writing to them (which will implicitely break the
15229 + link and create a copy of the unified file)
15231 +config VSERVER_VTIME
15232 + bool "Enable Virtualized Guest Time"
15233 + depends on EXPERIMENTAL
15236 + This enables per guest time offsets to allow for
15237 + adjusting the system clock individually per guest.
15238 + this adds some overhead to the time functions and
15239 + therefore should not be enabled without good reason.
15241 +config VSERVER_DEVICE
15242 + bool "Enable Guest Device Mapping"
15243 + depends on EXPERIMENTAL
15246 + This enables generic device remapping.
15248 +config VSERVER_PROC_SECURE
15249 + bool "Enable Proc Security"
15250 + depends on PROC_FS
15253 + This configures ProcFS security to initially hide
15254 + non-process entries for all contexts except the main and
15255 + spectator context (i.e. for all guests), which is a secure
15258 + (note: on 1.2x the entries were visible by default)
15261 + prompt "Persistent Inode Tagging"
15262 + default TAGGING_ID24
15264 + This adds persistent context information to filesystems
15265 + mounted with the tagxid option. Tagging is a requirement
15266 + for per-context disk limits and per-context quota.
15269 +config TAGGING_NONE
15272 + do not store per-context information in inodes.
15274 +config TAGGING_UID16
15275 + bool "UID16/GID32"
15277 + reduces UID to 16 bit, but leaves GID at 32 bit.
15279 +config TAGGING_GID16
15280 + bool "UID32/GID16"
15282 + reduces GID to 16 bit, but leaves UID at 32 bit.
15284 +config TAGGING_ID24
15285 + bool "UID24/GID24"
15287 + uses the upper 8bit from UID and GID for XID tagging
15288 + which leaves 24bit for UID/GID each, which should be
15289 + more than sufficient for normal use.
15291 +config TAGGING_INTERN
15292 + bool "UID32/GID32"
15294 + this uses otherwise reserved inode fields in the on
15295 + disk representation, which limits the use to a few
15296 + filesystems (currently ext2 and ext3)
15301 + bool "Tag NFSD User Auth and Files"
15304 + Enable this if you do want the in-kernel NFS
15305 + Server to use the tagging specified above.
15306 + (will require patched clients too)
15308 +config VSERVER_PRIVACY
15309 + bool "Honor Privacy Aspects of Guests"
15312 + When enabled, most context checks will disallow
15313 + access to structures assigned to a specific context,
15314 + like ptys or loop devices.
15316 +config VSERVER_CONTEXTS
15317 + int "Maximum number of Contexts (1-65533)" if EMBEDDED
15319 + default "768" if 64BIT
15322 + This setting will optimize certain data structures
15323 + and memory allocations according to the expected
15326 + note: this is not a strict upper limit.
15328 +config VSERVER_WARN
15329 + bool "VServer Warnings"
15332 + This enables various runtime warnings, which will
15333 + notify about potential manipulation attempts or
15334 + resource shortage. It is generally considered to
15335 + be a good idea to have that enabled.
15337 +config VSERVER_WARN_DEVPTS
15338 + bool "VServer DevPTS Warnings"
15339 + depends on VSERVER_WARN
15342 + This enables DevPTS related warnings, issued when a
15343 + process inside a context tries to lookup or access
15344 + a dynamic pts from the host or a different context.
15346 +config VSERVER_DEBUG
15347 + bool "VServer Debugging Code"
15350 + Set this to yes if you want to be able to activate
15351 + debugging output at runtime. It adds a very small
15352 + overhead to all vserver related functions and
15353 + increases the kernel size by about 20k.
15355 +config VSERVER_HISTORY
15356 + bool "VServer History Tracing"
15357 + depends on VSERVER_DEBUG
15360 + Set this to yes if you want to record the history of
15361 + linux-vserver activities, so they can be replayed in
15362 + the event of a kernel panic or oops.
15364 +config VSERVER_HISTORY_SIZE
15365 + int "Per-CPU History Size (32-65536)"
15366 + depends on VSERVER_HISTORY
15370 + This allows you to specify the number of entries in
15371 + the per-CPU history buffer.
15373 +config VSERVER_EXTRA_MNT_CHECK
15374 + bool "Extra Checks for Reachability"
15377 + Set this to yes if you want to do extra checks for
15378 + vfsmount reachability in the proc filesystem code.
15379 + This shouldn't be required on any setup utilizing
15383 + prompt "Quotes used in debug and warn messages"
15384 + default QUOTES_ISO8859
15386 +config QUOTES_ISO8859
15387 + bool "Extended ASCII (ISO 8859) angle quotes"
15389 + This uses the extended ASCII characters \xbb
15390 + and \xab for quoting file and process names.
15392 +config QUOTES_UTF8
15393 + bool "UTF-8 angle quotes"
15395 + This uses the the UTF-8 sequences for angle
15396 + quotes to quote file and process names.
15398 +config QUOTES_ASCII
15399 + bool "ASCII single quotes"
15401 + This uses the ASCII single quote character
15402 + (\x27) to quote file and process names.
15412 + select NAMESPACES
15418 +config VSERVER_SECURITY
15420 + depends on SECURITY
15422 + select SECURITY_CAPABILITIES
15424 +config VSERVER_DISABLED
15428 diff -NurpP --minimal linux-3.9.4/kernel/vserver/Makefile linux-3.9.4-vs2.3.6.1/kernel/vserver/Makefile
15429 --- linux-3.9.4/kernel/vserver/Makefile 1970-01-01 00:00:00.000000000 +0000
15430 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/Makefile 2013-05-31 14:47:11.000000000 +0000
15433 +# Makefile for the Linux vserver routines.
15437 +obj-y += vserver.o
15439 +vserver-y := switch.o context.o space.o sched.o network.o inode.o \
15440 + limit.o cvirt.o cacct.o signal.o helper.o init.o \
15443 +vserver-$(CONFIG_INET) += inet.o
15444 +vserver-$(CONFIG_PROC_FS) += proc.o
15445 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15446 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15447 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15448 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15450 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct.c linux-3.9.4-vs2.3.6.1/kernel/vserver/cacct.c
15451 --- linux-3.9.4/kernel/vserver/cacct.c 1970-01-01 00:00:00.000000000 +0000
15452 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/cacct.c 2013-05-31 14:47:11.000000000 +0000
15455 + * linux/kernel/vserver/cacct.c
15457 + * Virtual Server: Context Accounting
15459 + * Copyright (C) 2006-2007 Herbert Pötzl
15461 + * V0.01 added accounting stats
15465 +#include <linux/types.h>
15466 +#include <linux/vs_context.h>
15467 +#include <linux/vserver/cacct_cmd.h>
15468 +#include <linux/vserver/cacct_int.h>
15470 +#include <asm/errno.h>
15471 +#include <asm/uaccess.h>
15474 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15476 + struct vcmd_sock_stat_v0 vc_data;
15479 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15482 + field = vc_data.field;
15483 + if ((field < 0) || (field >= VXA_SOCK_SIZE))
15486 + for (j = 0; j < 3; j++) {
15487 + vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15488 + vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15491 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15496 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct_init.h linux-3.9.4-vs2.3.6.1/kernel/vserver/cacct_init.h
15497 --- linux-3.9.4/kernel/vserver/cacct_init.h 1970-01-01 00:00:00.000000000 +0000
15498 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/cacct_init.h 2013-05-31 14:47:11.000000000 +0000
15502 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15507 + for (i = 0; i < VXA_SOCK_SIZE; i++) {
15508 + for (j = 0; j < 3; j++) {
15509 + atomic_long_set(&cacct->sock[i][j].count, 0);
15510 + atomic_long_set(&cacct->sock[i][j].total, 0);
15513 + for (i = 0; i < 8; i++)
15514 + atomic_set(&cacct->slab[i], 0);
15515 + for (i = 0; i < 5; i++)
15516 + for (j = 0; j < 4; j++)
15517 + atomic_set(&cacct->page[i][j], 0);
15520 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15525 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct_proc.h linux-3.9.4-vs2.3.6.1/kernel/vserver/cacct_proc.h
15526 --- linux-3.9.4/kernel/vserver/cacct_proc.h 1970-01-01 00:00:00.000000000 +0000
15527 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/cacct_proc.h 2013-05-31 14:47:11.000000000 +0000
15529 +#ifndef _VX_CACCT_PROC_H
15530 +#define _VX_CACCT_PROC_H
15532 +#include <linux/vserver/cacct_int.h>
15535 +#define VX_SOCKA_TOP \
15536 + "Type\t recv #/bytes\t\t send #/bytes\t\t fail #/bytes\n"
15538 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15540 + int i, j, length = 0;
15541 + static char *type[VXA_SOCK_SIZE] = {
15542 + "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15545 + length += sprintf(buffer + length, VX_SOCKA_TOP);
15546 + for (i = 0; i < VXA_SOCK_SIZE; i++) {
15547 + length += sprintf(buffer + length, "%s:", type[i]);
15548 + for (j = 0; j < 3; j++) {
15549 + length += sprintf(buffer + length,
15550 + "\t%10lu/%-10lu",
15551 + vx_sock_count(cacct, i, j),
15552 + vx_sock_total(cacct, i, j));
15554 + buffer[length++] = '\n';
15557 + length += sprintf(buffer + length, "\n");
15558 + length += sprintf(buffer + length,
15559 + "slab:\t %8u %8u %8u %8u\n",
15560 + atomic_read(&cacct->slab[1]),
15561 + atomic_read(&cacct->slab[4]),
15562 + atomic_read(&cacct->slab[0]),
15563 + atomic_read(&cacct->slab[2]));
15565 + length += sprintf(buffer + length, "\n");
15566 + for (i = 0; i < 5; i++) {
15567 + length += sprintf(buffer + length,
15568 + "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15569 + atomic_read(&cacct->page[i][0]),
15570 + atomic_read(&cacct->page[i][1]),
15571 + atomic_read(&cacct->page[i][2]),
15572 + atomic_read(&cacct->page[i][3]),
15573 + atomic_read(&cacct->page[i][4]),
15574 + atomic_read(&cacct->page[i][5]),
15575 + atomic_read(&cacct->page[i][6]),
15576 + atomic_read(&cacct->page[i][7]));
15581 +#endif /* _VX_CACCT_PROC_H */
15582 diff -NurpP --minimal linux-3.9.4/kernel/vserver/context.c linux-3.9.4-vs2.3.6.1/kernel/vserver/context.c
15583 --- linux-3.9.4/kernel/vserver/context.c 1970-01-01 00:00:00.000000000 +0000
15584 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/context.c 2013-05-31 19:34:32.000000000 +0000
15587 + * linux/kernel/vserver/context.c
15589 + * Virtual Server: Context Support
15591 + * Copyright (C) 2003-2011 Herbert Pötzl
15593 + * V0.01 context helper
15594 + * V0.02 vx_ctx_kill syscall command
15595 + * V0.03 replaced context_info calls
15596 + * V0.04 redesign of struct (de)alloc
15597 + * V0.05 rlimit basic implementation
15598 + * V0.06 task_xid and info commands
15599 + * V0.07 context flags and caps
15600 + * V0.08 switch to RCU based hash
15601 + * V0.09 revert to non RCU for now
15602 + * V0.10 and back to working RCU hash
15603 + * V0.11 and back to locking again
15604 + * V0.12 referenced context store
15605 + * V0.13 separate per cpu data
15606 + * V0.14 changed vcmds to vxi arg
15607 + * V0.15 added context stat
15608 + * V0.16 have __create claim() the vxi
15609 + * V0.17 removed older and legacy stuff
15610 + * V0.18 added user credentials
15611 + * V0.19 added warn mask
15615 +#include <linux/slab.h>
15616 +#include <linux/types.h>
15617 +#include <linux/security.h>
15618 +#include <linux/pid_namespace.h>
15619 +#include <linux/capability.h>
15621 +#include <linux/vserver/context.h>
15622 +#include <linux/vserver/network.h>
15623 +#include <linux/vserver/debug.h>
15624 +#include <linux/vserver/limit.h>
15625 +#include <linux/vserver/limit_int.h>
15626 +#include <linux/vserver/space.h>
15627 +#include <linux/init_task.h>
15628 +#include <linux/fs_struct.h>
15629 +#include <linux/cred.h>
15631 +#include <linux/vs_context.h>
15632 +#include <linux/vs_limit.h>
15633 +#include <linux/vs_pid.h>
15634 +#include <linux/vserver/context_cmd.h>
15636 +#include "cvirt_init.h"
15637 +#include "cacct_init.h"
15638 +#include "limit_init.h"
15639 +#include "sched_init.h"
15642 +atomic_t vx_global_ctotal = ATOMIC_INIT(0);
15643 +atomic_t vx_global_cactive = ATOMIC_INIT(0);
15646 +/* now inactive context structures */
15648 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15650 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15653 +/* __alloc_vx_info()
15655 + * allocate an initialized vx_info struct
15656 + * doesn't make it visible (hash) */
15658 +static struct vx_info *__alloc_vx_info(xid_t xid)
15660 + struct vx_info *new = NULL;
15663 + vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15665 + /* would this benefit from a slab cache? */
15666 + new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15670 + memset(new, 0, sizeof(struct vx_info));
15672 + new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15673 + if (!new->ptr_pc)
15676 + new->vx_id = xid;
15677 + INIT_HLIST_NODE(&new->vx_hlist);
15678 + atomic_set(&new->vx_usecnt, 0);
15679 + atomic_set(&new->vx_tasks, 0);
15680 + new->vx_parent = NULL;
15681 + new->vx_state = 0;
15682 + init_waitqueue_head(&new->vx_wait);
15684 + /* prepare reaper */
15685 + get_task_struct(init_pid_ns.child_reaper);
15686 + new->vx_reaper = init_pid_ns.child_reaper;
15687 + new->vx_badness_bias = 0;
15689 + /* rest of init goes here */
15690 + vx_info_init_limit(&new->limit);
15691 + vx_info_init_sched(&new->sched);
15692 + vx_info_init_cvirt(&new->cvirt);
15693 + vx_info_init_cacct(&new->cacct);
15695 + /* per cpu data structures */
15696 + for_each_possible_cpu(cpu) {
15697 + vx_info_init_sched_pc(
15698 + &vx_per_cpu(new, sched_pc, cpu), cpu);
15699 + vx_info_init_cvirt_pc(
15700 + &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15703 + new->vx_flags = VXF_INIT_SET;
15704 + new->vx_bcaps = CAP_FULL_SET; // maybe ~CAP_SETPCAP
15705 + new->vx_ccaps = 0;
15706 + new->vx_umask = 0;
15707 + new->vx_wmask = 0;
15709 + new->reboot_cmd = 0;
15710 + new->exit_code = 0;
15712 + // preconfig spaces
15713 + for (index = 0; index < VX_SPACES; index++) {
15714 + struct _vx_space *space = &new->space[index];
15717 + spin_lock(&init_fs.lock);
15719 + spin_unlock(&init_fs.lock);
15720 + space->vx_fs = &init_fs;
15722 + /* FIXME: do we want defaults? */
15723 + // space->vx_real_cred = 0;
15724 + // space->vx_cred = 0;
15728 + vxdprintk(VXD_CBIT(xid, 0),
15729 + "alloc_vx_info(%d) = %p", xid, new);
15730 + vxh_alloc_vx_info(new);
15731 + atomic_inc(&vx_global_ctotal);
15740 +/* __dealloc_vx_info()
15742 + * final disposal of vx_info */
15744 +static void __dealloc_vx_info(struct vx_info *vxi)
15746 +#ifdef CONFIG_VSERVER_WARN
15747 + struct vx_info_save vxis;
15750 + vxdprintk(VXD_CBIT(xid, 0),
15751 + "dealloc_vx_info(%p)", vxi);
15752 + vxh_dealloc_vx_info(vxi);
15754 +#ifdef CONFIG_VSERVER_WARN
15755 + enter_vx_info(vxi, &vxis);
15756 + vx_info_exit_limit(&vxi->limit);
15757 + vx_info_exit_sched(&vxi->sched);
15758 + vx_info_exit_cvirt(&vxi->cvirt);
15759 + vx_info_exit_cacct(&vxi->cacct);
15761 + for_each_possible_cpu(cpu) {
15762 + vx_info_exit_sched_pc(
15763 + &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15764 + vx_info_exit_cvirt_pc(
15765 + &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15767 + leave_vx_info(&vxis);
15771 + vxi->vx_state |= VXS_RELEASED;
15774 + free_percpu(vxi->ptr_pc);
15777 + atomic_dec(&vx_global_ctotal);
15780 +static void __shutdown_vx_info(struct vx_info *vxi)
15782 + struct nsproxy *nsproxy;
15783 + struct fs_struct *fs;
15784 + struct cred *cred;
15789 + vxi->vx_state |= VXS_SHUTDOWN;
15790 + vs_state_change(vxi, VSC_SHUTDOWN);
15792 + for (index = 0; index < VX_SPACES; index++) {
15793 + struct _vx_space *space = &vxi->space[index];
15795 + nsproxy = xchg(&space->vx_nsproxy, NULL);
15797 + put_nsproxy(nsproxy);
15799 + fs = xchg(&space->vx_fs, NULL);
15800 + spin_lock(&fs->lock);
15801 + kill = !--fs->users;
15802 + spin_unlock(&fs->lock);
15804 + free_fs_struct(fs);
15806 + cred = (struct cred *)xchg(&space->vx_cred, NULL);
15808 + abort_creds(cred);
15812 +/* exported stuff */
15814 +void free_vx_info(struct vx_info *vxi)
15816 + unsigned long flags;
15819 + /* check for reference counts first */
15820 + BUG_ON(atomic_read(&vxi->vx_usecnt));
15821 + BUG_ON(atomic_read(&vxi->vx_tasks));
15823 + /* context must not be hashed */
15824 + BUG_ON(vx_info_state(vxi, VXS_HASHED));
15826 + /* context shutdown is mandatory */
15827 + BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15829 + /* spaces check */
15830 + for (index = 0; index < VX_SPACES; index++) {
15831 + struct _vx_space *space = &vxi->space[index];
15833 + BUG_ON(space->vx_nsproxy);
15834 + BUG_ON(space->vx_fs);
15835 + // BUG_ON(space->vx_real_cred);
15836 + // BUG_ON(space->vx_cred);
15839 + spin_lock_irqsave(&vx_info_inactive_lock, flags);
15840 + hlist_del(&vxi->vx_hlist);
15841 + spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15843 + __dealloc_vx_info(vxi);
15847 +/* hash table for vx_info hash */
15849 +#define VX_HASH_SIZE 13
15851 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15852 + { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15854 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15857 +static inline unsigned int __hashval(xid_t xid)
15859 + return (xid % VX_HASH_SIZE);
15864 +/* __hash_vx_info()
15866 + * add the vxi to the global hash table
15867 + * requires the hash_lock to be held */
15869 +static inline void __hash_vx_info(struct vx_info *vxi)
15871 + struct hlist_head *head;
15873 + vxd_assert_lock(&vx_info_hash_lock);
15874 + vxdprintk(VXD_CBIT(xid, 4),
15875 + "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15876 + vxh_hash_vx_info(vxi);
15878 + /* context must not be hashed */
15879 + BUG_ON(vx_info_state(vxi, VXS_HASHED));
15881 + vxi->vx_state |= VXS_HASHED;
15882 + head = &vx_info_hash[__hashval(vxi->vx_id)];
15883 + hlist_add_head(&vxi->vx_hlist, head);
15884 + atomic_inc(&vx_global_cactive);
15887 +/* __unhash_vx_info()
15889 + * remove the vxi from the global hash table
15890 + * requires the hash_lock to be held */
15892 +static inline void __unhash_vx_info(struct vx_info *vxi)
15894 + unsigned long flags;
15896 + vxd_assert_lock(&vx_info_hash_lock);
15897 + vxdprintk(VXD_CBIT(xid, 4),
15898 + "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15899 + atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15900 + vxh_unhash_vx_info(vxi);
15902 + /* context must be hashed */
15903 + BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15904 + /* but without tasks */
15905 + BUG_ON(atomic_read(&vxi->vx_tasks));
15907 + vxi->vx_state &= ~VXS_HASHED;
15908 + hlist_del_init(&vxi->vx_hlist);
15909 + spin_lock_irqsave(&vx_info_inactive_lock, flags);
15910 + hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15911 + spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15912 + atomic_dec(&vx_global_cactive);
15916 +/* __lookup_vx_info()
15918 + * requires the hash_lock to be held
15919 + * doesn't increment the vx_refcnt */
15921 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
15923 + struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15924 + struct hlist_node *pos;
15925 + struct vx_info *vxi;
15927 + vxd_assert_lock(&vx_info_hash_lock);
15928 + hlist_for_each(pos, head) {
15929 + vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15931 + if (vxi->vx_id == xid)
15936 + vxdprintk(VXD_CBIT(xid, 0),
15937 + "__lookup_vx_info(#%u): %p[#%u]",
15938 + xid, vxi, vxi ? vxi->vx_id : 0);
15939 + vxh_lookup_vx_info(vxi, xid);
15944 +/* __create_vx_info()
15946 + * create the requested context
15947 + * get(), claim() and hash it */
15949 +static struct vx_info *__create_vx_info(int id)
15951 + struct vx_info *new, *vxi = NULL;
15953 + vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15955 + if (!(new = __alloc_vx_info(id)))
15956 + return ERR_PTR(-ENOMEM);
15958 + /* required to make dynamic xids unique */
15959 + spin_lock(&vx_info_hash_lock);
15961 + /* static context requested */
15962 + if ((vxi = __lookup_vx_info(id))) {
15963 + vxdprintk(VXD_CBIT(xid, 0),
15964 + "create_vx_info(%d) = %p (already there)", id, vxi);
15965 + if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15966 + vxi = ERR_PTR(-EBUSY);
15968 + vxi = ERR_PTR(-EEXIST);
15971 + /* new context */
15972 + vxdprintk(VXD_CBIT(xid, 0),
15973 + "create_vx_info(%d) = %p (new)", id, new);
15974 + claim_vx_info(new, NULL);
15975 + __hash_vx_info(get_vx_info(new));
15976 + vxi = new, new = NULL;
15979 + spin_unlock(&vx_info_hash_lock);
15980 + vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15982 + __dealloc_vx_info(new);
15987 +/* exported stuff */
15990 +void unhash_vx_info(struct vx_info *vxi)
15992 + spin_lock(&vx_info_hash_lock);
15993 + __unhash_vx_info(vxi);
15994 + spin_unlock(&vx_info_hash_lock);
15995 + __shutdown_vx_info(vxi);
15996 + __wakeup_vx_info(vxi);
16000 +/* lookup_vx_info()
16002 + * search for a vx_info and get() it
16003 + * negative id means current */
16005 +struct vx_info *lookup_vx_info(int id)
16007 + struct vx_info *vxi = NULL;
16010 + vxi = get_vx_info(current_vx_info());
16011 + } else if (id > 1) {
16012 + spin_lock(&vx_info_hash_lock);
16013 + vxi = get_vx_info(__lookup_vx_info(id));
16014 + spin_unlock(&vx_info_hash_lock);
16019 +/* xid_is_hashed()
16021 + * verify that xid is still hashed */
16023 +int xid_is_hashed(xid_t xid)
16027 + spin_lock(&vx_info_hash_lock);
16028 + hashed = (__lookup_vx_info(xid) != NULL);
16029 + spin_unlock(&vx_info_hash_lock);
16033 +#ifdef CONFIG_PROC_FS
16037 + * get a subset of hashed xids for proc
16038 + * assumes size is at least one */
16040 +int get_xid_list(int index, unsigned int *xids, int size)
16042 + int hindex, nr_xids = 0;
16044 + /* only show current and children */
16045 + if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16048 + xids[nr_xids] = vx_current_xid();
16052 + for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16053 + struct hlist_head *head = &vx_info_hash[hindex];
16054 + struct hlist_node *pos;
16056 + spin_lock(&vx_info_hash_lock);
16057 + hlist_for_each(pos, head) {
16058 + struct vx_info *vxi;
16063 + vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16064 + xids[nr_xids] = vxi->vx_id;
16065 + if (++nr_xids >= size) {
16066 + spin_unlock(&vx_info_hash_lock);
16070 + /* keep the lock time short */
16071 + spin_unlock(&vx_info_hash_lock);
16078 +#ifdef CONFIG_VSERVER_DEBUG
16080 +void dump_vx_info_inactive(int level)
16082 + struct hlist_node *entry, *next;
16084 + hlist_for_each_safe(entry, next, &vx_info_inactive) {
16085 + struct vx_info *vxi =
16086 + list_entry(entry, struct vx_info, vx_hlist);
16088 + dump_vx_info(vxi, level);
16095 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16097 + struct user_struct *new_user, *old_user;
16102 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16105 + new_user = alloc_uid(vxi->vx_id, p->uid);
16109 + old_user = p->user;
16110 + if (new_user != old_user) {
16111 + atomic_inc(&new_user->processes);
16112 + atomic_dec(&old_user->processes);
16113 + p->user = new_user;
16115 + free_uid(old_user);
16121 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16123 + // p->cap_effective &= vxi->vx_cap_bset;
16124 + p->cap_effective =
16125 + cap_intersect(p->cap_effective, vxi->cap_bset);
16126 + // p->cap_inheritable &= vxi->vx_cap_bset;
16127 + p->cap_inheritable =
16128 + cap_intersect(p->cap_inheritable, vxi->cap_bset);
16129 + // p->cap_permitted &= vxi->vx_cap_bset;
16130 + p->cap_permitted =
16131 + cap_intersect(p->cap_permitted, vxi->cap_bset);
16136 +#include <linux/file.h>
16137 +#include <linux/fdtable.h>
16139 +static int vx_openfd_task(struct task_struct *tsk)
16141 + struct files_struct *files = tsk->files;
16142 + struct fdtable *fdt;
16143 + const unsigned long *bptr;
16144 + int count, total;
16146 + /* no rcu_read_lock() because of spin_lock() */
16147 + spin_lock(&files->file_lock);
16148 + fdt = files_fdtable(files);
16149 + bptr = fdt->open_fds;
16150 + count = fdt->max_fds / (sizeof(unsigned long) * 8);
16151 + for (total = 0; count > 0; count--) {
16153 + total += hweight_long(*bptr);
16156 + spin_unlock(&files->file_lock);
16161 +/* for *space compatibility */
16163 +asmlinkage long sys_unshare(unsigned long);
16166 + * migrate task to new context
16167 + * gets vxi, puts old_vxi on change
16168 + * optionally unshares namespaces (hack)
16171 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16173 + struct vx_info *old_vxi;
16179 + vxdprintk(VXD_CBIT(xid, 5),
16180 + "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16181 + vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16183 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16184 + !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16187 + if (vx_info_state(vxi, VXS_SHUTDOWN))
16190 + old_vxi = task_get_vx_info(p);
16191 + if (old_vxi == vxi)
16194 +// if (!(ret = vx_migrate_user(p, vxi))) {
16199 + openfd = vx_openfd_task(p);
16202 + atomic_dec(&old_vxi->cvirt.nr_threads);
16203 + atomic_dec(&old_vxi->cvirt.nr_running);
16204 + __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16205 + /* FIXME: what about the struct files here? */
16206 + __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16207 + /* account for the executable */
16208 + __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16210 + atomic_inc(&vxi->cvirt.nr_threads);
16211 + atomic_inc(&vxi->cvirt.nr_running);
16212 + __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16213 + /* FIXME: what about the struct files here? */
16214 + __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16215 + /* account for the executable */
16216 + __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16219 + release_vx_info(old_vxi, p);
16220 + clr_vx_info(&p->vx_info);
16222 + claim_vx_info(vxi, p);
16223 + set_vx_info(&p->vx_info, vxi);
16224 + p->xid = vxi->vx_id;
16226 + vxdprintk(VXD_CBIT(xid, 5),
16227 + "moved task %p into vxi:%p[#%d]",
16228 + p, vxi, vxi->vx_id);
16230 + // vx_mask_cap_bset(vxi, p);
16233 + /* hack for *spaces to provide compatibility */
16235 + struct nsproxy *old_nsp, *new_nsp;
16237 + ret = unshare_nsproxy_namespaces(
16238 + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16239 + &new_nsp, NULL, NULL);
16243 + old_nsp = xchg(&p->nsproxy, new_nsp);
16244 + vx_set_space(vxi,
16245 + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16246 + put_nsproxy(old_nsp);
16250 + put_vx_info(old_vxi);
16254 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16256 + struct task_struct *old_reaper;
16257 + struct vx_info *reaper_vxi;
16262 + vxdprintk(VXD_CBIT(xid, 6),
16263 + "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16264 + vxi, vxi->vx_id, p, p->xid, p->pid);
16266 + old_reaper = vxi->vx_reaper;
16267 + if (old_reaper == p)
16270 + reaper_vxi = task_get_vx_info(p);
16271 + if (reaper_vxi && reaper_vxi != vxi) {
16273 + "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16275 + p->comm, p->pid, p->xid, vx_current_xid());
16279 + /* set new child reaper */
16280 + get_task_struct(p);
16281 + vxi->vx_reaper = p;
16282 + put_task_struct(old_reaper);
16284 + put_vx_info(reaper_vxi);
16288 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16293 + vxdprintk(VXD_CBIT(xid, 6),
16294 + "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16295 + vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16297 + vxi->vx_flags &= ~VXF_STATE_INIT;
16298 + // vxi->vx_initpid = p->tgid;
16299 + vxi->vx_initpid = p->pid;
16303 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16305 + vxdprintk(VXD_CBIT(xid, 6),
16306 + "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16307 + vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16309 + vxi->exit_code = code;
16310 + vxi->vx_initpid = 0;
16314 +void vx_set_persistent(struct vx_info *vxi)
16316 + vxdprintk(VXD_CBIT(xid, 6),
16317 + "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16319 + get_vx_info(vxi);
16320 + claim_vx_info(vxi, NULL);
16323 +void vx_clear_persistent(struct vx_info *vxi)
16325 + vxdprintk(VXD_CBIT(xid, 6),
16326 + "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16328 + release_vx_info(vxi, NULL);
16329 + put_vx_info(vxi);
16332 +void vx_update_persistent(struct vx_info *vxi)
16334 + if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16335 + vx_set_persistent(vxi);
16337 + vx_clear_persistent(vxi);
16341 +/* task must be current or locked */
16343 +void exit_vx_info(struct task_struct *p, int code)
16345 + struct vx_info *vxi = p->vx_info;
16348 + atomic_dec(&vxi->cvirt.nr_threads);
16351 + vxi->exit_code = code;
16352 + release_vx_info(vxi, p);
16356 +void exit_vx_info_early(struct task_struct *p, int code)
16358 + struct vx_info *vxi = p->vx_info;
16361 + if (vxi->vx_initpid == p->pid)
16362 + vx_exit_init(vxi, p, code);
16363 + if (vxi->vx_reaper == p)
16364 + vx_set_reaper(vxi, init_pid_ns.child_reaper);
16369 +/* vserver syscall commands below here */
16371 +/* taks xid and vx_info functions */
16373 +#include <asm/uaccess.h>
16376 +int vc_task_xid(uint32_t id)
16381 + struct task_struct *tsk;
16384 + tsk = find_task_by_real_pid(id);
16385 + xid = (tsk) ? tsk->xid : -ESRCH;
16386 + rcu_read_unlock();
16388 + xid = vx_current_xid();
16393 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16395 + struct vcmd_vx_info_v0 vc_data;
16397 + vc_data.xid = vxi->vx_id;
16398 + vc_data.initpid = vxi->vx_initpid;
16400 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16406 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16408 + struct vcmd_ctx_stat_v0 vc_data;
16410 + vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16411 + vc_data.tasks = atomic_read(&vxi->vx_tasks);
16413 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16419 +/* context functions */
16421 +int vc_ctx_create(uint32_t xid, void __user *data)
16423 + struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16424 + struct vx_info *new_vxi;
16427 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16430 + if ((xid > MAX_S_CONTEXT) || (xid < 2))
16433 + new_vxi = __create_vx_info(xid);
16434 + if (IS_ERR(new_vxi))
16435 + return PTR_ERR(new_vxi);
16437 + /* initial flags */
16438 + new_vxi->vx_flags = vc_data.flagword;
16441 + if (vs_state_change(new_vxi, VSC_STARTUP))
16444 + ret = vx_migrate_task(current, new_vxi, (!data));
16448 + /* return context id on success */
16449 + ret = new_vxi->vx_id;
16451 + /* get a reference for persistent contexts */
16452 + if ((vc_data.flagword & VXF_PERSISTENT))
16453 + vx_set_persistent(new_vxi);
16455 + release_vx_info(new_vxi, NULL);
16456 + put_vx_info(new_vxi);
16461 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16463 + struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16466 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16469 + ret = vx_migrate_task(current, vxi, 0);
16472 + if (vc_data.flagword & VXM_SET_INIT)
16473 + ret = vx_set_init(vxi, current);
16476 + if (vc_data.flagword & VXM_SET_REAPER)
16477 + ret = vx_set_reaper(vxi, current);
16482 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16484 + struct vcmd_ctx_flags_v0 vc_data;
16486 + vc_data.flagword = vxi->vx_flags;
16488 + /* special STATE flag handling */
16489 + vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16491 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16496 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16498 + struct vcmd_ctx_flags_v0 vc_data;
16499 + uint64_t mask, trigger;
16501 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16504 + /* special STATE flag handling */
16505 + mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16506 + trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16508 + if (vxi == current_vx_info()) {
16509 + /* if (trigger & VXF_STATE_SETUP)
16510 + vx_mask_cap_bset(vxi, current); */
16511 + if (trigger & VXF_STATE_INIT) {
16514 + ret = vx_set_init(vxi, current);
16517 + ret = vx_set_reaper(vxi, current);
16523 + vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16524 + vc_data.flagword, mask);
16525 + if (trigger & VXF_PERSISTENT)
16526 + vx_update_persistent(vxi);
16532 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16534 + uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16536 + // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16540 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16542 + kernel_cap_t c = __cap_empty_set;
16544 + c.cap[0] = v & 0xFFFFFFFF;
16545 + c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16547 + // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16552 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16555 + *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16557 + *ccaps = vxi->vx_ccaps;
16562 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16564 + struct vcmd_ctx_caps_v1 vc_data;
16567 + ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16570 + vc_data.cmask = ~0ULL;
16572 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16577 +static int do_set_caps(struct vx_info *vxi,
16578 + uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16580 + uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16583 + printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16584 + bcaps, bmask, ccaps, cmask);
16586 + vxi->vx_bcaps = cap_t_from_caps(
16587 + vs_mask_flags(bcold, bcaps, bmask));
16588 + vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16593 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16595 + struct vcmd_ctx_caps_v1 vc_data;
16597 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16600 + return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16603 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16605 + struct vcmd_bcaps vc_data;
16608 + ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16611 + vc_data.bmask = ~0ULL;
16613 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16618 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16620 + struct vcmd_bcaps vc_data;
16622 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16625 + return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16629 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16631 + struct vcmd_umask vc_data;
16633 + vc_data.umask = vxi->vx_umask;
16634 + vc_data.mask = ~0ULL;
16636 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16641 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16643 + struct vcmd_umask vc_data;
16645 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16648 + vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16649 + vc_data.umask, vc_data.mask);
16654 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16656 + struct vcmd_wmask vc_data;
16658 + vc_data.wmask = vxi->vx_wmask;
16659 + vc_data.mask = ~0ULL;
16661 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16666 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16668 + struct vcmd_wmask vc_data;
16670 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16673 + vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16674 + vc_data.wmask, vc_data.mask);
16679 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16681 + struct vcmd_badness_v0 vc_data;
16683 + vc_data.bias = vxi->vx_badness_bias;
16685 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16690 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16692 + struct vcmd_badness_v0 vc_data;
16694 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16697 + vxi->vx_badness_bias = vc_data.bias;
16701 +#include <linux/module.h>
16703 +EXPORT_SYMBOL_GPL(free_vx_info);
16705 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt.c linux-3.9.4-vs2.3.6.1/kernel/vserver/cvirt.c
16706 --- linux-3.9.4/kernel/vserver/cvirt.c 1970-01-01 00:00:00.000000000 +0000
16707 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/cvirt.c 2013-05-31 14:47:11.000000000 +0000
16710 + * linux/kernel/vserver/cvirt.c
16712 + * Virtual Server: Context Virtualization
16714 + * Copyright (C) 2004-2007 Herbert Pötzl
16716 + * V0.01 broken out from limit.c
16717 + * V0.02 added utsname stuff
16718 + * V0.03 changed vcmds to vxi arg
16722 +#include <linux/types.h>
16723 +#include <linux/utsname.h>
16724 +#include <linux/vs_cvirt.h>
16725 +#include <linux/vserver/switch.h>
16726 +#include <linux/vserver/cvirt_cmd.h>
16728 +#include <asm/uaccess.h>
16731 +void vx_vsi_boottime(struct timespec *boottime)
16733 + struct vx_info *vxi = current_vx_info();
16735 + set_normalized_timespec(boottime,
16736 + boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16737 + boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16741 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16743 + struct vx_info *vxi = current_vx_info();
16745 + set_normalized_timespec(uptime,
16746 + uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16747 + uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16750 + set_normalized_timespec(idle,
16751 + idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16752 + idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16756 +uint64_t vx_idle_jiffies(void)
16758 + return init_task.utime + init_task.stime;
16763 +static inline uint32_t __update_loadavg(uint32_t load,
16764 + int wsize, int delta, int n)
16766 + unsigned long long calc, prev;
16768 + /* just set it to n */
16769 + if (unlikely(delta >= wsize))
16770 + return (n << FSHIFT);
16772 + calc = delta * n;
16774 + prev = (wsize - delta);
16777 + do_div(calc, wsize);
16782 +void vx_update_load(struct vx_info *vxi)
16784 + uint32_t now, last, delta;
16785 + unsigned int nr_running, nr_uninterruptible;
16786 + unsigned int total;
16787 + unsigned long flags;
16789 + spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16792 + last = vxi->cvirt.load_last;
16793 + delta = now - last;
16795 + if (delta < 5*HZ)
16798 + nr_running = atomic_read(&vxi->cvirt.nr_running);
16799 + nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16800 + total = nr_running + nr_uninterruptible;
16802 + vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16803 + 60*HZ, delta, total);
16804 + vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16805 + 5*60*HZ, delta, total);
16806 + vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16807 + 15*60*HZ, delta, total);
16809 + vxi->cvirt.load_last = now;
16811 + atomic_inc(&vxi->cvirt.load_updates);
16812 + spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16817 + * Commands to do_syslog:
16819 + * 0 -- Close the log. Currently a NOP.
16820 + * 1 -- Open the log. Currently a NOP.
16821 + * 2 -- Read from the log.
16822 + * 3 -- Read all messages remaining in the ring buffer.
16823 + * 4 -- Read and clear all messages remaining in the ring buffer
16824 + * 5 -- Clear ring buffer.
16825 + * 6 -- Disable printk's to console
16826 + * 7 -- Enable printk's to console
16827 + * 8 -- Set level of messages printed to console
16828 + * 9 -- Return number of unread characters in the log buffer
16829 + * 10 -- Return size of the log buffer
16831 +int vx_do_syslog(int type, char __user *buf, int len)
16834 + int do_clear = 0;
16835 + struct vx_info *vxi = current_vx_info();
16836 + struct _vx_syslog *log;
16840 + log = &vxi->cvirt.syslog;
16843 + case 0: /* Close log */
16844 + case 1: /* Open log */
16846 + case 2: /* Read from log */
16847 + error = wait_event_interruptible(log->log_wait,
16848 + (log->log_start - log->log_end));
16851 + spin_lock_irq(&log->logbuf_lock);
16852 + spin_unlock_irq(&log->logbuf_lock);
16854 + case 4: /* Read/clear last kernel messages */
16856 + /* fall through */
16857 + case 3: /* Read last kernel messages */
16860 + case 5: /* Clear ring buffer */
16863 + case 6: /* Disable logging to console */
16864 + case 7: /* Enable logging to console */
16865 + case 8: /* Set level of messages printed to console */
16868 + case 9: /* Number of chars in the log buffer */
16870 + case 10: /* Size of the log buffer */
16880 +/* virtual host info names */
16882 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16884 + struct nsproxy *nsproxy;
16885 + struct uts_namespace *uts;
16887 + if (id == VHIN_CONTEXT)
16888 + return vxi->vx_name;
16890 + nsproxy = vxi->space[0].vx_nsproxy;
16894 + uts = nsproxy->uts_ns;
16899 + case VHIN_SYSNAME:
16900 + return uts->name.sysname;
16901 + case VHIN_NODENAME:
16902 + return uts->name.nodename;
16903 + case VHIN_RELEASE:
16904 + return uts->name.release;
16905 + case VHIN_VERSION:
16906 + return uts->name.version;
16907 + case VHIN_MACHINE:
16908 + return uts->name.machine;
16909 + case VHIN_DOMAINNAME:
16910 + return uts->name.domainname;
16917 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16919 + struct vcmd_vhi_name_v0 vc_data;
16922 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16925 + name = vx_vhi_name(vxi, vc_data.field);
16929 + memcpy(name, vc_data.name, 65);
16933 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16935 + struct vcmd_vhi_name_v0 vc_data;
16938 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16941 + name = vx_vhi_name(vxi, vc_data.field);
16945 + memcpy(vc_data.name, name, 65);
16946 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16952 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16954 + struct vcmd_virt_stat_v0 vc_data;
16955 + struct _vx_cvirt *cvirt = &vxi->cvirt;
16956 + struct timespec uptime;
16958 + do_posix_clock_monotonic_gettime(&uptime);
16959 + set_normalized_timespec(&uptime,
16960 + uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16961 + uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16963 + vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16964 + vc_data.uptime = timespec_to_ns(&uptime);
16965 + vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16966 + vc_data.nr_running = atomic_read(&cvirt->nr_running);
16967 + vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16968 + vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16969 + vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16970 + vc_data.load[0] = cvirt->load[0];
16971 + vc_data.load[1] = cvirt->load[1];
16972 + vc_data.load[2] = cvirt->load[2];
16974 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16980 +#ifdef CONFIG_VSERVER_VTIME
16982 +/* virtualized time base */
16984 +void vx_adjust_timespec(struct timespec *ts)
16986 + struct vx_info *vxi;
16988 + if (!vx_flags(VXF_VIRT_TIME, 0))
16991 + vxi = current_vx_info();
16992 + ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16993 + ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16995 + if (ts->tv_nsec >= NSEC_PER_SEC) {
16997 + ts->tv_nsec -= NSEC_PER_SEC;
16998 + } else if (ts->tv_nsec < 0) {
17000 + ts->tv_nsec += NSEC_PER_SEC;
17004 +int vx_settimeofday(const struct timespec *ts)
17006 + struct timespec ats, delta;
17007 + struct vx_info *vxi;
17009 + if (!vx_flags(VXF_VIRT_TIME, 0))
17010 + return do_settimeofday(ts);
17012 + getnstimeofday(&ats);
17013 + delta = timespec_sub(*ts, ats);
17015 + vxi = current_vx_info();
17016 + vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17022 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt_init.h linux-3.9.4-vs2.3.6.1/kernel/vserver/cvirt_init.h
17023 --- linux-3.9.4/kernel/vserver/cvirt_init.h 1970-01-01 00:00:00.000000000 +0000
17024 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/cvirt_init.h 2013-05-31 14:47:11.000000000 +0000
17028 +extern uint64_t vx_idle_jiffies(void);
17030 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17032 + uint64_t idle_jiffies = vx_idle_jiffies();
17033 + uint64_t nsuptime;
17035 + do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17036 + nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17037 + * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17038 + cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17039 + cvirt->bias_ts.tv_sec = 0;
17040 + cvirt->bias_ts.tv_nsec = 0;
17042 + jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17043 + atomic_set(&cvirt->nr_threads, 0);
17044 + atomic_set(&cvirt->nr_running, 0);
17045 + atomic_set(&cvirt->nr_uninterruptible, 0);
17046 + atomic_set(&cvirt->nr_onhold, 0);
17048 + spin_lock_init(&cvirt->load_lock);
17049 + cvirt->load_last = jiffies;
17050 + atomic_set(&cvirt->load_updates, 0);
17051 + cvirt->load[0] = 0;
17052 + cvirt->load[1] = 0;
17053 + cvirt->load[2] = 0;
17054 + atomic_set(&cvirt->total_forks, 0);
17056 + spin_lock_init(&cvirt->syslog.logbuf_lock);
17057 + init_waitqueue_head(&cvirt->syslog.log_wait);
17058 + cvirt->syslog.log_start = 0;
17059 + cvirt->syslog.log_end = 0;
17060 + cvirt->syslog.con_start = 0;
17061 + cvirt->syslog.logged_chars = 0;
17065 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17067 + // cvirt_pc->cpustat = { 0 };
17070 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17072 +#ifdef CONFIG_VSERVER_WARN
17075 + vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17076 + "!!! cvirt: %p[nr_threads] = %d on exit.",
17078 + vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17079 + "!!! cvirt: %p[nr_running] = %d on exit.",
17081 + vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17082 + "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17084 + vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17085 + "!!! cvirt: %p[nr_onhold] = %d on exit.",
17091 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17096 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt_proc.h linux-3.9.4-vs2.3.6.1/kernel/vserver/cvirt_proc.h
17097 --- linux-3.9.4/kernel/vserver/cvirt_proc.h 1970-01-01 00:00:00.000000000 +0000
17098 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/cvirt_proc.h 2013-05-31 19:38:26.000000000 +0000
17100 +#ifndef _VX_CVIRT_PROC_H
17101 +#define _VX_CVIRT_PROC_H
17103 +#include <linux/nsproxy.h>
17104 +#include <linux/mnt_namespace.h>
17105 +#include <linux/ipc_namespace.h>
17106 +#include <linux/utsname.h>
17107 +#include <linux/ipc.h>
17109 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17112 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17114 + struct mnt_namespace *ns;
17115 + struct uts_namespace *uts;
17116 + struct ipc_namespace *ipc;
17122 + length += sprintf(buffer + length,
17123 + "NSProxy:\t%p [%p,%p,%p]\n",
17124 + nsproxy, nsproxy->mnt_ns,
17125 + nsproxy->uts_ns, nsproxy->ipc_ns);
17127 + ns = nsproxy->mnt_ns;
17131 + length += vx_info_mnt_namespace(ns, buffer + length);
17135 + uts = nsproxy->uts_ns;
17139 + length += sprintf(buffer + length,
17140 + "SysName:\t%.*s\n"
17141 + "NodeName:\t%.*s\n"
17142 + "Release:\t%.*s\n"
17143 + "Version:\t%.*s\n"
17144 + "Machine:\t%.*s\n"
17145 + "DomainName:\t%.*s\n",
17146 + __NEW_UTS_LEN, uts->name.sysname,
17147 + __NEW_UTS_LEN, uts->name.nodename,
17148 + __NEW_UTS_LEN, uts->name.release,
17149 + __NEW_UTS_LEN, uts->name.version,
17150 + __NEW_UTS_LEN, uts->name.machine,
17151 + __NEW_UTS_LEN, uts->name.domainname);
17154 + ipc = nsproxy->ipc_ns;
17158 + length += sprintf(buffer + length,
17159 + "SEMS:\t\t%d %d %d %d %d\n"
17160 + "MSG:\t\t%d %d %d\n"
17161 + "SHM:\t\t%lu %lu %d %ld\n",
17162 + ipc->sem_ctls[0], ipc->sem_ctls[1],
17163 + ipc->sem_ctls[2], ipc->sem_ctls[3],
17165 + ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17166 + (unsigned long)ipc->shm_ctlmax,
17167 + (unsigned long)ipc->shm_ctlall,
17168 + ipc->shm_ctlmni, ipc->shm_tot);
17175 +#include <linux/sched.h>
17177 +#define LOAD_INT(x) ((x) >> FSHIFT)
17178 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17181 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17186 + length += sprintf(buffer + length,
17187 + "BiasUptime:\t%lu.%02lu\n",
17188 + (unsigned long)cvirt->bias_uptime.tv_sec,
17189 + (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17191 + a = cvirt->load[0] + (FIXED_1 / 200);
17192 + b = cvirt->load[1] + (FIXED_1 / 200);
17193 + c = cvirt->load[2] + (FIXED_1 / 200);
17194 + length += sprintf(buffer + length,
17195 + "nr_threads:\t%d\n"
17196 + "nr_running:\t%d\n"
17197 + "nr_unintr:\t%d\n"
17198 + "nr_onhold:\t%d\n"
17199 + "load_updates:\t%d\n"
17200 + "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17201 + "total_forks:\t%d\n",
17202 + atomic_read(&cvirt->nr_threads),
17203 + atomic_read(&cvirt->nr_running),
17204 + atomic_read(&cvirt->nr_uninterruptible),
17205 + atomic_read(&cvirt->nr_onhold),
17206 + atomic_read(&cvirt->load_updates),
17207 + LOAD_INT(a), LOAD_FRAC(a),
17208 + LOAD_INT(b), LOAD_FRAC(b),
17209 + LOAD_INT(c), LOAD_FRAC(c),
17210 + atomic_read(&cvirt->total_forks));
17215 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17216 + char *buffer, int cpu)
17222 +#endif /* _VX_CVIRT_PROC_H */
17223 diff -NurpP --minimal linux-3.9.4/kernel/vserver/debug.c linux-3.9.4-vs2.3.6.1/kernel/vserver/debug.c
17224 --- linux-3.9.4/kernel/vserver/debug.c 1970-01-01 00:00:00.000000000 +0000
17225 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/debug.c 2013-05-31 14:47:11.000000000 +0000
17228 + * kernel/vserver/debug.c
17230 + * Copyright (C) 2005-2007 Herbert Pötzl
17232 + * V0.01 vx_info dump support
17236 +#include <linux/module.h>
17238 +#include <linux/vserver/context.h>
17241 +void dump_vx_info(struct vx_info *vxi, int level)
17243 + printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17244 + atomic_read(&vxi->vx_usecnt),
17245 + atomic_read(&vxi->vx_tasks),
17248 + __dump_vx_limit(&vxi->limit);
17249 + __dump_vx_sched(&vxi->sched);
17250 + __dump_vx_cvirt(&vxi->cvirt);
17251 + __dump_vx_cacct(&vxi->cacct);
17257 +EXPORT_SYMBOL_GPL(dump_vx_info);
17259 diff -NurpP --minimal linux-3.9.4/kernel/vserver/device.c linux-3.9.4-vs2.3.6.1/kernel/vserver/device.c
17260 --- linux-3.9.4/kernel/vserver/device.c 1970-01-01 00:00:00.000000000 +0000
17261 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/device.c 2013-05-31 14:47:11.000000000 +0000
17264 + * linux/kernel/vserver/device.c
17266 + * Linux-VServer: Device Support
17268 + * Copyright (C) 2006 Herbert Pötzl
17269 + * Copyright (C) 2007 Daniel Hokka Zakrisson
17271 + * V0.01 device mapping basics
17272 + * V0.02 added defaults
17276 +#include <linux/slab.h>
17277 +#include <linux/rcupdate.h>
17278 +#include <linux/fs.h>
17279 +#include <linux/namei.h>
17280 +#include <linux/hash.h>
17282 +#include <asm/errno.h>
17283 +#include <asm/uaccess.h>
17284 +#include <linux/vserver/base.h>
17285 +#include <linux/vserver/debug.h>
17286 +#include <linux/vserver/context.h>
17287 +#include <linux/vserver/device.h>
17288 +#include <linux/vserver/device_cmd.h>
17291 +#define DMAP_HASH_BITS 4
17294 +struct vs_mapping {
17296 + struct hlist_node hlist;
17297 + struct list_head list;
17299 +#define dm_hlist u.hlist
17300 +#define dm_list u.list
17303 + struct vx_dmap_target target;
17307 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17309 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17311 +static struct vx_dmap_target dmap_defaults[2] = {
17312 + { .flags = DATTR_OPEN },
17313 + { .flags = DATTR_OPEN },
17317 +struct kmem_cache *dmap_cachep __read_mostly;
17319 +int __init dmap_cache_init(void)
17321 + dmap_cachep = kmem_cache_create("dmap_cache",
17322 + sizeof(struct vs_mapping), 0,
17323 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17327 +__initcall(dmap_cache_init);
17330 +static inline unsigned int __hashval(dev_t dev, int bits)
17332 + return hash_long((unsigned long)dev, bits);
17336 +/* __hash_mapping()
17337 + * add the mapping to the hash table
17339 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17341 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17342 + struct hlist_head *head, *hash = dmap_main_hash;
17343 + int device = vdm->device;
17345 + spin_lock(hash_lock);
17346 + vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17347 + vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17349 + head = &hash[__hashval(device, DMAP_HASH_BITS)];
17350 + hlist_add_head(&vdm->dm_hlist, head);
17351 + spin_unlock(hash_lock);
17355 +static inline int __mode_to_default(umode_t mode)
17368 +/* __set_default()
17371 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17372 + struct vx_dmap_target *vdmt)
17374 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17375 + spin_lock(hash_lock);
17378 + vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17380 + dmap_defaults[__mode_to_default(mode)] = *vdmt;
17383 + spin_unlock(hash_lock);
17385 + vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17386 + vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17390 +/* __remove_default()
17391 + * remove a default
17393 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17395 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17396 + spin_lock(hash_lock);
17399 + vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17400 + else /* remove == reset */
17401 + dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17403 + spin_unlock(hash_lock);
17408 +/* __find_mapping()
17409 + * find a mapping in the hash table
17411 + * caller must hold hash_lock
17413 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17414 + struct vs_mapping **local, struct vs_mapping **global)
17416 + struct hlist_head *hash = dmap_main_hash;
17417 + struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17418 + struct hlist_node *pos;
17419 + struct vs_mapping *vdm;
17425 + hlist_for_each(pos, head) {
17426 + vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17428 + if ((vdm->device == device) &&
17429 + !((vdm->target.flags ^ mode) & S_IFMT)) {
17430 + if (vdm->xid == xid) {
17433 + } else if (global && vdm->xid == 0)
17438 + if (global && *global)
17445 +/* __lookup_mapping()
17446 + * find a mapping and store the result in target and flags
17448 +static inline int __lookup_mapping(struct vx_info *vxi,
17449 + dev_t device, dev_t *target, int *flags, umode_t mode)
17451 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17452 + struct vs_mapping *vdm, *global;
17453 + struct vx_dmap_target *vdmt;
17455 + xid_t xid = vxi->vx_id;
17458 + spin_lock(hash_lock);
17459 + if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17461 + vdmt = &vdm->target;
17465 + index = __mode_to_default(mode);
17466 + if (vxi && vxi->dmap.targets[index].flags) {
17468 + vdmt = &vxi->dmap.targets[index];
17469 + } else if (global) {
17471 + vdmt = &global->target;
17475 + vdmt = &dmap_defaults[index];
17479 + if (target && (vdmt->flags & DATTR_REMAP))
17480 + *target = vdmt->target;
17482 + *target = device;
17484 + *flags = vdmt->flags;
17486 + spin_unlock(hash_lock);
17492 +/* __remove_mapping()
17493 + * remove a mapping from the hash table
17495 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17498 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17499 + struct vs_mapping *vdm = NULL;
17502 + spin_lock(hash_lock);
17504 + ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17506 + vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17507 + vxi, vxi ? vxi->vx_id : 0, device, mode);
17510 + hlist_del(&vdm->dm_hlist);
17513 + spin_unlock(hash_lock);
17515 + kmem_cache_free(dmap_cachep, vdm);
17521 +int vs_map_device(struct vx_info *vxi,
17522 + dev_t device, dev_t *target, umode_t mode)
17524 + int ret, flags = DATTR_MASK;
17528 + *target = device;
17531 + ret = __lookup_mapping(vxi, device, target, &flags, mode);
17532 + vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17533 + device, target ? *target : 0, flags, mode, ret);
17535 + return (flags & DATTR_MASK);
17540 +static int do_set_mapping(struct vx_info *vxi,
17541 + dev_t device, dev_t target, int flags, umode_t mode)
17544 + struct vs_mapping *new;
17546 + new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17550 + INIT_HLIST_NODE(&new->dm_hlist);
17551 + new->device = device;
17552 + new->target.target = target;
17553 + new->target.flags = flags | mode;
17554 + new->xid = (vxi ? vxi->vx_id : 0);
17556 + vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17557 + __hash_mapping(vxi, new);
17559 + struct vx_dmap_target new = {
17560 + .target = target,
17561 + .flags = flags | mode,
17563 + __set_default(vxi, mode, &new);
17569 +static int do_unset_mapping(struct vx_info *vxi,
17570 + dev_t device, dev_t target, int flags, umode_t mode)
17572 + int ret = -EINVAL;
17575 + ret = __remove_mapping(vxi, device, mode);
17579 + ret = __remove_default(vxi, mode);
17589 +static inline int __user_device(const char __user *name, dev_t *dev,
17592 + struct nameidata nd;
17599 + ret = user_lpath(name, &nd.path);
17602 + if (nd.path.dentry->d_inode) {
17603 + *dev = nd.path.dentry->d_inode->i_rdev;
17604 + *mode = nd.path.dentry->d_inode->i_mode;
17606 + path_put(&nd.path);
17610 +static inline int __mapping_mode(dev_t device, dev_t target,
17611 + umode_t device_mode, umode_t target_mode, umode_t *mode)
17614 + *mode = device_mode & S_IFMT;
17616 + *mode = target_mode & S_IFMT;
17620 + /* if both given, device and target mode have to match */
17621 + if (device && target &&
17622 + ((device_mode ^ target_mode) & S_IFMT))
17628 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17629 + const char __user *target_path, int flags, int set)
17631 + dev_t device = ~0, target = ~0;
17632 + umode_t device_mode = 0, target_mode = 0, mode;
17635 + ret = __user_device(device_path, &device, &device_mode);
17638 + ret = __user_device(target_path, &target, &target_mode);
17642 + ret = __mapping_mode(device, target,
17643 + device_mode, target_mode, &mode);
17648 + return do_set_mapping(vxi, device, target,
17651 + return do_unset_mapping(vxi, device, target,
17656 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
17658 + struct vcmd_set_mapping_v0 vc_data;
17660 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17663 + return do_mapping(vxi, vc_data.device, vc_data.target,
17664 + vc_data.flags, 1);
17667 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17669 + struct vcmd_set_mapping_v0 vc_data;
17671 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17674 + return do_mapping(vxi, vc_data.device, vc_data.target,
17675 + vc_data.flags, 0);
17679 +#ifdef CONFIG_COMPAT
17681 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
17683 + struct vcmd_set_mapping_v0_x32 vc_data;
17685 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17688 + return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17689 + compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
17692 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17694 + struct vcmd_set_mapping_v0_x32 vc_data;
17696 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17699 + return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17700 + compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17703 +#endif /* CONFIG_COMPAT */
17706 diff -NurpP --minimal linux-3.9.4/kernel/vserver/dlimit.c linux-3.9.4-vs2.3.6.1/kernel/vserver/dlimit.c
17707 --- linux-3.9.4/kernel/vserver/dlimit.c 1970-01-01 00:00:00.000000000 +0000
17708 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/dlimit.c 2013-05-31 19:37:39.000000000 +0000
17711 + * linux/kernel/vserver/dlimit.c
17713 + * Virtual Server: Context Disk Limits
17715 + * Copyright (C) 2004-2009 Herbert Pötzl
17717 + * V0.01 initial version
17718 + * V0.02 compat32 splitup
17719 + * V0.03 extended interface
17723 +#include <linux/statfs.h>
17724 +#include <linux/sched.h>
17725 +#include <linux/namei.h>
17726 +#include <linux/vs_tag.h>
17727 +#include <linux/vs_dlimit.h>
17728 +#include <linux/vserver/dlimit_cmd.h>
17729 +#include <linux/slab.h>
17730 +// #include <linux/gfp.h>
17732 +#include <asm/uaccess.h>
17734 +/* __alloc_dl_info()
17736 + * allocate an initialized dl_info struct
17737 + * doesn't make it visible (hash) */
17739 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17741 + struct dl_info *new = NULL;
17743 + vxdprintk(VXD_CBIT(dlim, 5),
17744 + "alloc_dl_info(%p,%d)*", sb, tag);
17746 + /* would this benefit from a slab cache? */
17747 + new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17751 + memset(new, 0, sizeof(struct dl_info));
17752 + new->dl_tag = tag;
17754 + // INIT_RCU_HEAD(&new->dl_rcu);
17755 + INIT_HLIST_NODE(&new->dl_hlist);
17756 + spin_lock_init(&new->dl_lock);
17757 + atomic_set(&new->dl_refcnt, 0);
17758 + atomic_set(&new->dl_usecnt, 0);
17760 + /* rest of init goes here */
17762 + vxdprintk(VXD_CBIT(dlim, 4),
17763 + "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17767 +/* __dealloc_dl_info()
17769 + * final disposal of dl_info */
17771 +static void __dealloc_dl_info(struct dl_info *dli)
17773 + vxdprintk(VXD_CBIT(dlim, 4),
17774 + "dealloc_dl_info(%p)", dli);
17776 + dli->dl_hlist.next = LIST_POISON1;
17777 + dli->dl_tag = -1;
17780 + BUG_ON(atomic_read(&dli->dl_usecnt));
17781 + BUG_ON(atomic_read(&dli->dl_refcnt));
17787 +/* hash table for dl_info hash */
17789 +#define DL_HASH_SIZE 13
17791 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17793 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17796 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
17798 + return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17803 +/* __hash_dl_info()
17805 + * add the dli to the global hash table
17806 + * requires the hash_lock to be held */
17808 +static inline void __hash_dl_info(struct dl_info *dli)
17810 + struct hlist_head *head;
17812 + vxdprintk(VXD_CBIT(dlim, 6),
17813 + "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17814 + get_dl_info(dli);
17815 + head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17816 + hlist_add_head_rcu(&dli->dl_hlist, head);
17819 +/* __unhash_dl_info()
17821 + * remove the dli from the global hash table
17822 + * requires the hash_lock to be held */
17824 +static inline void __unhash_dl_info(struct dl_info *dli)
17826 + vxdprintk(VXD_CBIT(dlim, 6),
17827 + "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17828 + hlist_del_rcu(&dli->dl_hlist);
17829 + put_dl_info(dli);
17833 +/* __lookup_dl_info()
17835 + * requires the rcu_read_lock()
17836 + * doesn't increment the dl_refcnt */
17838 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
17840 + struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17841 + struct dl_info *dli;
17843 + hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17844 + if (dli->dl_tag == tag && dli->dl_sb == sb)
17851 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
17853 + struct dl_info *dli;
17856 + dli = get_dl_info(__lookup_dl_info(sb, tag));
17857 + vxdprintk(VXD_CBIT(dlim, 7),
17858 + "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17859 + rcu_read_unlock();
17863 +void rcu_free_dl_info(struct rcu_head *head)
17865 + struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17866 + int usecnt, refcnt;
17868 + BUG_ON(!dli || !head);
17870 + usecnt = atomic_read(&dli->dl_usecnt);
17871 + BUG_ON(usecnt < 0);
17873 + refcnt = atomic_read(&dli->dl_refcnt);
17874 + BUG_ON(refcnt < 0);
17876 + vxdprintk(VXD_CBIT(dlim, 3),
17877 + "rcu_free_dl_info(%p)", dli);
17879 + __dealloc_dl_info(dli);
17881 + printk("!!! rcu didn't free\n");
17887 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17888 + uint32_t flags, int add)
17890 + struct path path;
17893 + ret = user_lpath(name, &path);
17895 + struct super_block *sb;
17896 + struct dl_info *dli;
17899 + if (!path.dentry->d_inode)
17900 + goto out_release;
17901 + if (!(sb = path.dentry->d_inode->i_sb))
17902 + goto out_release;
17905 + dli = __alloc_dl_info(sb, id);
17906 + spin_lock(&dl_info_hash_lock);
17909 + if (__lookup_dl_info(sb, id))
17911 + __hash_dl_info(dli);
17914 + spin_lock(&dl_info_hash_lock);
17915 + dli = __lookup_dl_info(sb, id);
17920 + __unhash_dl_info(dli);
17924 + spin_unlock(&dl_info_hash_lock);
17926 + __dealloc_dl_info(dli);
17933 +int vc_add_dlimit(uint32_t id, void __user *data)
17935 + struct vcmd_ctx_dlimit_base_v0 vc_data;
17937 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17940 + return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17943 +int vc_rem_dlimit(uint32_t id, void __user *data)
17945 + struct vcmd_ctx_dlimit_base_v0 vc_data;
17947 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17950 + return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17953 +#ifdef CONFIG_COMPAT
17955 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17957 + struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17959 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17962 + return do_addrem_dlimit(id,
17963 + compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17966 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17968 + struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17970 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17973 + return do_addrem_dlimit(id,
17974 + compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17977 +#endif /* CONFIG_COMPAT */
17981 +int do_set_dlimit(uint32_t id, const char __user *name,
17982 + uint32_t space_used, uint32_t space_total,
17983 + uint32_t inodes_used, uint32_t inodes_total,
17984 + uint32_t reserved, uint32_t flags)
17986 + struct path path;
17989 + ret = user_lpath(name, &path);
17991 + struct super_block *sb;
17992 + struct dl_info *dli;
17995 + if (!path.dentry->d_inode)
17996 + goto out_release;
17997 + if (!(sb = path.dentry->d_inode->i_sb))
17998 + goto out_release;
18000 + /* sanity checks */
18001 + if ((reserved != CDLIM_KEEP &&
18002 + reserved > 100) ||
18003 + (inodes_used != CDLIM_KEEP &&
18004 + inodes_used > inodes_total) ||
18005 + (space_used != CDLIM_KEEP &&
18006 + space_used > space_total))
18007 + goto out_release;
18010 + dli = locate_dl_info(sb, id);
18012 + goto out_release;
18014 + spin_lock(&dli->dl_lock);
18016 + if (inodes_used != CDLIM_KEEP)
18017 + dli->dl_inodes_used = inodes_used;
18018 + if (inodes_total != CDLIM_KEEP)
18019 + dli->dl_inodes_total = inodes_total;
18020 + if (space_used != CDLIM_KEEP)
18021 + dli->dl_space_used = dlimit_space_32to64(
18022 + space_used, flags, DLIMS_USED);
18024 + if (space_total == CDLIM_INFINITY)
18025 + dli->dl_space_total = DLIM_INFINITY;
18026 + else if (space_total != CDLIM_KEEP)
18027 + dli->dl_space_total = dlimit_space_32to64(
18028 + space_total, flags, DLIMS_TOTAL);
18030 + if (reserved != CDLIM_KEEP)
18031 + dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18033 + spin_unlock(&dli->dl_lock);
18035 + put_dl_info(dli);
18044 +int vc_set_dlimit(uint32_t id, void __user *data)
18046 + struct vcmd_ctx_dlimit_v0 vc_data;
18048 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18051 + return do_set_dlimit(id, vc_data.name,
18052 + vc_data.space_used, vc_data.space_total,
18053 + vc_data.inodes_used, vc_data.inodes_total,
18054 + vc_data.reserved, vc_data.flags);
18057 +#ifdef CONFIG_COMPAT
18059 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18061 + struct vcmd_ctx_dlimit_v0_x32 vc_data;
18063 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18066 + return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18067 + vc_data.space_used, vc_data.space_total,
18068 + vc_data.inodes_used, vc_data.inodes_total,
18069 + vc_data.reserved, vc_data.flags);
18072 +#endif /* CONFIG_COMPAT */
18076 +int do_get_dlimit(uint32_t id, const char __user *name,
18077 + uint32_t *space_used, uint32_t *space_total,
18078 + uint32_t *inodes_used, uint32_t *inodes_total,
18079 + uint32_t *reserved, uint32_t *flags)
18081 + struct path path;
18084 + ret = user_lpath(name, &path);
18086 + struct super_block *sb;
18087 + struct dl_info *dli;
18090 + if (!path.dentry->d_inode)
18091 + goto out_release;
18092 + if (!(sb = path.dentry->d_inode->i_sb))
18093 + goto out_release;
18096 + dli = locate_dl_info(sb, id);
18098 + goto out_release;
18100 + spin_lock(&dli->dl_lock);
18101 + *inodes_used = dli->dl_inodes_used;
18102 + *inodes_total = dli->dl_inodes_total;
18104 + *space_used = dlimit_space_64to32(
18105 + dli->dl_space_used, flags, DLIMS_USED);
18107 + if (dli->dl_space_total == DLIM_INFINITY)
18108 + *space_total = CDLIM_INFINITY;
18110 + *space_total = dlimit_space_64to32(
18111 + dli->dl_space_total, flags, DLIMS_TOTAL);
18113 + *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18114 + spin_unlock(&dli->dl_lock);
18116 + put_dl_info(dli);
18127 +int vc_get_dlimit(uint32_t id, void __user *data)
18129 + struct vcmd_ctx_dlimit_v0 vc_data;
18132 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18135 + ret = do_get_dlimit(id, vc_data.name,
18136 + &vc_data.space_used, &vc_data.space_total,
18137 + &vc_data.inodes_used, &vc_data.inodes_total,
18138 + &vc_data.reserved, &vc_data.flags);
18142 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18147 +#ifdef CONFIG_COMPAT
18149 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18151 + struct vcmd_ctx_dlimit_v0_x32 vc_data;
18154 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18157 + ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18158 + &vc_data.space_used, &vc_data.space_total,
18159 + &vc_data.inodes_used, &vc_data.inodes_total,
18160 + &vc_data.reserved, &vc_data.flags);
18164 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18169 +#endif /* CONFIG_COMPAT */
18172 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18174 + struct dl_info *dli;
18175 + __u64 blimit, bfree, bavail;
18178 + dli = locate_dl_info(sb, dx_current_tag());
18182 + spin_lock(&dli->dl_lock);
18183 + if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18186 + /* reduce max inodes available to limit */
18187 + if (buf->f_files > dli->dl_inodes_total)
18188 + buf->f_files = dli->dl_inodes_total;
18190 + ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18191 + /* reduce free inodes to min */
18192 + if (ifree < buf->f_ffree)
18193 + buf->f_ffree = ifree;
18196 + if (dli->dl_space_total == DLIM_INFINITY)
18199 + blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18201 + if (dli->dl_space_total < dli->dl_space_used)
18204 + bfree = (dli->dl_space_total - dli->dl_space_used)
18205 + >> sb->s_blocksize_bits;
18207 + bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18208 + if (bavail < dli->dl_space_used)
18211 + bavail = (bavail - dli->dl_space_used)
18212 + >> sb->s_blocksize_bits;
18214 + /* reduce max space available to limit */
18215 + if (buf->f_blocks > blimit)
18216 + buf->f_blocks = blimit;
18218 + /* reduce free space to min */
18219 + if (bfree < buf->f_bfree)
18220 + buf->f_bfree = bfree;
18222 + /* reduce avail space to min */
18223 + if (bavail < buf->f_bavail)
18224 + buf->f_bavail = bavail;
18227 + spin_unlock(&dli->dl_lock);
18228 + put_dl_info(dli);
18233 +#include <linux/module.h>
18235 +EXPORT_SYMBOL_GPL(locate_dl_info);
18236 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18238 diff -NurpP --minimal linux-3.9.4/kernel/vserver/helper.c linux-3.9.4-vs2.3.6.1/kernel/vserver/helper.c
18239 --- linux-3.9.4/kernel/vserver/helper.c 1970-01-01 00:00:00.000000000 +0000
18240 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/helper.c 2013-05-31 14:47:11.000000000 +0000
18243 + * linux/kernel/vserver/helper.c
18245 + * Virtual Context Support
18247 + * Copyright (C) 2004-2007 Herbert Pötzl
18249 + * V0.01 basic helper
18253 +#include <linux/kmod.h>
18254 +#include <linux/reboot.h>
18255 +#include <linux/vs_context.h>
18256 +#include <linux/vs_network.h>
18257 +#include <linux/vserver/signal.h>
18260 +char vshelper_path[255] = "/sbin/vshelper";
18262 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18264 + current->flags &= ~PF_THREAD_BOUND;
18268 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18272 + if ((ret = call_usermodehelper_fns(name, argv, envp,
18273 + sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18274 + vshelper_init, NULL, NULL))) {
18275 + printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18276 + name, argv[1], argv[2],
18277 + sync ? "sync" : "async", ret);
18279 + vxdprintk(VXD_CBIT(switch, 4),
18280 + "%s: (%s %s) returned %s with %d",
18281 + name, argv[1], argv[2], sync ? "sync" : "async", ret);
18286 + * vshelper path is set via /proc/sys
18287 + * invoked by vserver sys_reboot(), with
18288 + * the following arguments
18290 + * argv [0] = vshelper_path;
18291 + * argv [1] = action: "restart", "halt", "poweroff", ...
18292 + * argv [2] = context identifier
18294 + * envp [*] = type-specific parameters
18297 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18299 + char id_buf[8], cmd_buf[16];
18300 + char uid_buf[16], pid_buf[16];
18303 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
18304 + char *envp[] = {"HOME=/", "TERM=linux",
18305 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18306 + uid_buf, pid_buf, cmd_buf, 0};
18308 + if (vx_info_state(vxi, VXS_HELPER))
18310 + vxi->vx_state |= VXS_HELPER;
18312 + snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18314 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18315 + snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d", current_uid());
18316 + snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18319 + case LINUX_REBOOT_CMD_RESTART:
18320 + argv[1] = "restart";
18323 + case LINUX_REBOOT_CMD_HALT:
18324 + argv[1] = "halt";
18327 + case LINUX_REBOOT_CMD_POWER_OFF:
18328 + argv[1] = "poweroff";
18331 + case LINUX_REBOOT_CMD_SW_SUSPEND:
18332 + argv[1] = "swsusp";
18335 + case LINUX_REBOOT_CMD_OOM:
18340 + vxi->vx_state &= ~VXS_HELPER;
18344 + ret = do_vshelper(vshelper_path, argv, envp, 0);
18345 + vxi->vx_state &= ~VXS_HELPER;
18346 + __wakeup_vx_info(vxi);
18347 + return (ret) ? -EPERM : 0;
18351 +long vs_reboot(unsigned int cmd, void __user *arg)
18353 + struct vx_info *vxi = current_vx_info();
18356 + vxdprintk(VXD_CBIT(misc, 5),
18357 + "vs_reboot(%p[#%d],%u)",
18358 + vxi, vxi ? vxi->vx_id : 0, cmd);
18360 + ret = vs_reboot_helper(vxi, cmd, arg);
18364 + vxi->reboot_cmd = cmd;
18365 + if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18367 + case LINUX_REBOOT_CMD_RESTART:
18368 + case LINUX_REBOOT_CMD_HALT:
18369 + case LINUX_REBOOT_CMD_POWER_OFF:
18370 + vx_info_kill(vxi, 0, SIGKILL);
18371 + vx_info_kill(vxi, 1, SIGKILL);
18379 +long vs_oom_action(unsigned int cmd)
18381 + struct vx_info *vxi = current_vx_info();
18384 + vxdprintk(VXD_CBIT(misc, 5),
18385 + "vs_oom_action(%p[#%d],%u)",
18386 + vxi, vxi ? vxi->vx_id : 0, cmd);
18388 + ret = vs_reboot_helper(vxi, cmd, NULL);
18392 + vxi->reboot_cmd = cmd;
18393 + if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18394 + vx_info_kill(vxi, 0, SIGKILL);
18395 + vx_info_kill(vxi, 1, SIGKILL);
18401 + * argv [0] = vshelper_path;
18402 + * argv [1] = action: "startup", "shutdown"
18403 + * argv [2] = context identifier
18405 + * envp [*] = type-specific parameters
18408 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18410 + char id_buf[8], cmd_buf[16];
18411 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
18412 + char *envp[] = {"HOME=/", "TERM=linux",
18413 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18415 + if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18418 + snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18419 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18422 + case VSC_STARTUP:
18423 + argv[1] = "startup";
18425 + case VSC_SHUTDOWN:
18426 + argv[1] = "shutdown";
18432 + return do_vshelper(vshelper_path, argv, envp, 1);
18437 + * argv [0] = vshelper_path;
18438 + * argv [1] = action: "netup", "netdown"
18439 + * argv [2] = context identifier
18441 + * envp [*] = type-specific parameters
18444 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18446 + char id_buf[8], cmd_buf[16];
18447 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
18448 + char *envp[] = {"HOME=/", "TERM=linux",
18449 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18451 + if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18454 + snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18455 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18459 + argv[1] = "netup";
18461 + case VSC_NETDOWN:
18462 + argv[1] = "netdown";
18468 + return do_vshelper(vshelper_path, argv, envp, 1);
18471 diff -NurpP --minimal linux-3.9.4/kernel/vserver/history.c linux-3.9.4-vs2.3.6.1/kernel/vserver/history.c
18472 --- linux-3.9.4/kernel/vserver/history.c 1970-01-01 00:00:00.000000000 +0000
18473 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/history.c 2013-05-31 14:47:11.000000000 +0000
18476 + * kernel/vserver/history.c
18478 + * Virtual Context History Backtrace
18480 + * Copyright (C) 2004-2007 Herbert Pötzl
18482 + * V0.01 basic structure
18483 + * V0.02 hash/unhash and trace
18484 + * V0.03 preemption fixes
18488 +#include <linux/module.h>
18489 +#include <asm/uaccess.h>
18491 +#include <linux/vserver/context.h>
18492 +#include <linux/vserver/debug.h>
18493 +#include <linux/vserver/debug_cmd.h>
18494 +#include <linux/vserver/history.h>
18497 +#ifdef CONFIG_VSERVER_HISTORY
18498 +#define VXH_SIZE CONFIG_VSERVER_HISTORY_SIZE
18500 +#define VXH_SIZE 64
18503 +struct _vx_history {
18504 + unsigned int counter;
18506 + struct _vx_hist_entry entry[VXH_SIZE + 1];
18510 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18512 +unsigned volatile int vxh_active = 1;
18514 +static atomic_t sequence = ATOMIC_INIT(0);
18519 + * requires disabled preemption */
18521 +struct _vx_hist_entry *vxh_advance(void *loc)
18523 + unsigned int cpu = smp_processor_id();
18524 + struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18525 + struct _vx_hist_entry *entry;
18526 + unsigned int index;
18528 + index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18529 + entry = &hist->entry[index];
18531 + entry->seq = atomic_inc_return(&sequence);
18532 + entry->loc = loc;
18536 +EXPORT_SYMBOL_GPL(vxh_advance);
18539 +#define VXH_LOC_FMTS "(#%04x,*%d):%p"
18541 +#define VXH_LOC_ARGS(e) (e)->seq, cpu, (e)->loc
18544 +#define VXH_VXI_FMTS "%p[#%d,%d.%d]"
18546 +#define VXH_VXI_ARGS(e) (e)->vxi.ptr, \
18547 + (e)->vxi.ptr ? (e)->vxi.xid : 0, \
18548 + (e)->vxi.ptr ? (e)->vxi.usecnt : 0, \
18549 + (e)->vxi.ptr ? (e)->vxi.tasks : 0
18551 +void vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18553 + switch (e->type) {
18554 + case VXH_THROW_OOPS:
18555 + printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18558 + case VXH_GET_VX_INFO:
18559 + case VXH_PUT_VX_INFO:
18560 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18562 + (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18563 + VXH_VXI_ARGS(e));
18566 + case VXH_INIT_VX_INFO:
18567 + case VXH_SET_VX_INFO:
18568 + case VXH_CLR_VX_INFO:
18569 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18571 + (e->type == VXH_INIT_VX_INFO) ? "init" :
18572 + ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18573 + VXH_VXI_ARGS(e), e->sc.data);
18576 + case VXH_CLAIM_VX_INFO:
18577 + case VXH_RELEASE_VX_INFO:
18578 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18580 + (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18581 + VXH_VXI_ARGS(e), e->sc.data);
18584 + case VXH_ALLOC_VX_INFO:
18585 + case VXH_DEALLOC_VX_INFO:
18586 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18588 + (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18589 + VXH_VXI_ARGS(e));
18592 + case VXH_HASH_VX_INFO:
18593 + case VXH_UNHASH_VX_INFO:
18594 + printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18596 + (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18597 + VXH_VXI_ARGS(e));
18600 + case VXH_LOC_VX_INFO:
18601 + case VXH_LOOKUP_VX_INFO:
18602 + case VXH_CREATE_VX_INFO:
18603 + printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18605 + (e->type == VXH_CREATE_VX_INFO) ? "create" :
18606 + ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18607 + e->ll.arg, VXH_VXI_ARGS(e));
18612 +static void __vxh_dump_history(void)
18614 + unsigned int i, cpu;
18616 + printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18617 + atomic_read(&sequence), NR_CPUS);
18619 + for (i = 0; i < VXH_SIZE; i++) {
18620 + for_each_online_cpu(cpu) {
18621 + struct _vx_history *hist =
18622 + &per_cpu(vx_history_buffer, cpu);
18623 + unsigned int index = (hist->counter - i) % VXH_SIZE;
18624 + struct _vx_hist_entry *entry = &hist->entry[index];
18626 + vxh_dump_entry(entry, cpu);
18631 +void vxh_dump_history(void)
18635 + local_irq_enable();
18637 + local_irq_disable();
18639 + __vxh_dump_history();
18643 +/* vserver syscall commands below here */
18646 +int vc_dump_history(uint32_t id)
18649 + __vxh_dump_history();
18656 +int do_read_history(struct __user _vx_hist_entry *data,
18657 + int cpu, uint32_t *index, uint32_t *count)
18659 + int pos, ret = 0;
18660 + struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18661 + int end = hist->counter;
18662 + int start = end - VXH_SIZE + 2;
18663 + int idx = *index;
18665 + /* special case: get current pos */
18671 + /* have we lost some data? */
18675 + for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18676 + struct _vx_hist_entry *entry =
18677 + &hist->entry[idx % VXH_SIZE];
18679 + /* send entry to userspace */
18680 + ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18684 + /* save new index and count */
18687 + return ret ? ret : (*index < end);
18690 +int vc_read_history(uint32_t id, void __user *data)
18692 + struct vcmd_read_history_v0 vc_data;
18695 + if (id >= NR_CPUS)
18698 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18701 + ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18702 + id, &vc_data.index, &vc_data.count);
18704 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18709 +#ifdef CONFIG_COMPAT
18711 +int vc_read_history_x32(uint32_t id, void __user *data)
18713 + struct vcmd_read_history_v0_x32 vc_data;
18716 + if (id >= NR_CPUS)
18719 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18722 + ret = do_read_history((struct __user _vx_hist_entry *)
18723 + compat_ptr(vc_data.data_ptr),
18724 + id, &vc_data.index, &vc_data.count);
18726 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18731 +#endif /* CONFIG_COMPAT */
18733 diff -NurpP --minimal linux-3.9.4/kernel/vserver/inet.c linux-3.9.4-vs2.3.6.1/kernel/vserver/inet.c
18734 --- linux-3.9.4/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
18735 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/inet.c 2013-05-31 22:43:05.000000000 +0000
18738 +#include <linux/in.h>
18739 +#include <linux/inetdevice.h>
18740 +#include <linux/export.h>
18741 +#include <linux/vs_inet.h>
18742 +#include <linux/vs_inet6.h>
18743 +#include <linux/vserver/debug.h>
18744 +#include <net/route.h>
18745 +#include <net/addrconf.h>
18748 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18752 + if (!nxi1 || !nxi2 || nxi1 == nxi2)
18755 + struct nx_addr_v4 *ptr;
18756 + unsigned long irqflags;
18758 + spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18759 + for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18760 + if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18765 + spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18768 + vxdprintk(VXD_CBIT(net, 2),
18769 + "nx_v4_addr_conflict(%p,%p): %d",
18770 + nxi1, nxi2, ret);
18776 +#ifdef CONFIG_IPV6
18778 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18782 + if (!nxi1 || !nxi2 || nxi1 == nxi2)
18785 + struct nx_addr_v6 *ptr;
18786 + unsigned long irqflags;
18788 + spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18789 + for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18790 + if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18795 + spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18798 + vxdprintk(VXD_CBIT(net, 2),
18799 + "nx_v6_addr_conflict(%p,%p): %d",
18800 + nxi1, nxi2, ret);
18807 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18809 + struct in_device *in_dev;
18810 + struct in_ifaddr **ifap;
18811 + struct in_ifaddr *ifa;
18816 + in_dev = in_dev_get(dev);
18820 + for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18821 + ifap = &ifa->ifa_next) {
18822 + if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18827 + in_dev_put(in_dev);
18833 +#ifdef CONFIG_IPV6
18835 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18837 + struct inet6_dev *in_dev;
18838 + struct inet6_ifaddr *ifa;
18843 + in_dev = in6_dev_get(dev);
18847 + // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18848 + list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18849 + if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18854 + in6_dev_put(in_dev);
18861 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18867 + if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18869 +#ifdef CONFIG_IPV6
18871 + if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18876 + vxdprintk(VXD_CBIT(net, 3),
18877 + "dev_in_nx_info(%p,%p[#%d]) = %d",
18878 + dev, nxi, nxi ? nxi->nx_id : 0, ret);
18882 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18883 + struct flowi4 *fl4)
18885 + struct rtable *rt;
18890 + /* FIXME: handle lback only case */
18891 + if (!NX_IPV4(nxi))
18892 + return ERR_PTR(-EPERM);
18894 + vxdprintk(VXD_CBIT(net, 4),
18895 + "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18896 + nxi, nxi ? nxi->nx_id : 0,
18897 + NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18899 + /* single IP is unconditional */
18900 + if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18901 + (fl4->saddr == INADDR_ANY))
18902 + fl4->saddr = nxi->v4.ip[0].s_addr;
18904 + if (fl4->saddr == INADDR_ANY) {
18905 + struct nx_addr_v4 *ptr;
18906 + __be32 found = 0;
18908 + rt = __ip_route_output_key(net, fl4);
18909 + if (!IS_ERR(rt)) {
18910 + found = fl4->saddr;
18912 + vxdprintk(VXD_CBIT(net, 4),
18913 + "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18914 + nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18915 + if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18919 + WARN_ON_ONCE(in_irq());
18920 + spin_lock_bh(&nxi->addr_lock);
18921 + for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18922 + __be32 primary = ptr->ip[0].s_addr;
18923 + __be32 mask = ptr->mask.s_addr;
18924 + __be32 neta = primary & mask;
18926 + vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18927 + NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18928 + nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18929 + NIPQUAD(mask), NIPQUAD(neta));
18930 + if ((found & mask) != neta)
18933 + fl4->saddr = primary;
18934 + rt = __ip_route_output_key(net, fl4);
18935 + vxdprintk(VXD_CBIT(net, 4),
18936 + "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18937 + nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18938 + if (!IS_ERR(rt)) {
18939 + found = fl4->saddr;
18941 + if (found == primary)
18942 + goto found_unlock;
18945 + /* still no source ip? */
18946 + found = ipv4_is_loopback(fl4->daddr)
18947 + ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18949 + spin_unlock_bh(&nxi->addr_lock);
18951 + /* assign src ip to flow */
18952 + fl4->saddr = found;
18955 + if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18956 + return ERR_PTR(-EPERM);
18959 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18960 + if (ipv4_is_loopback(fl4->daddr))
18961 + fl4->daddr = nxi->v4_lback.s_addr;
18962 + if (ipv4_is_loopback(fl4->saddr))
18963 + fl4->saddr = nxi->v4_lback.s_addr;
18964 + } else if (ipv4_is_loopback(fl4->daddr) &&
18965 + !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18966 + return ERR_PTR(-EPERM);
18971 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18973 diff -NurpP --minimal linux-3.9.4/kernel/vserver/init.c linux-3.9.4-vs2.3.6.1/kernel/vserver/init.c
18974 --- linux-3.9.4/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
18975 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/init.c 2013-05-31 14:47:11.000000000 +0000
18978 + * linux/kernel/init.c
18980 + * Virtual Server Init
18982 + * Copyright (C) 2004-2007 Herbert Pötzl
18984 + * V0.01 basic structure
18988 +#include <linux/init.h>
18990 +int vserver_register_sysctl(void);
18991 +void vserver_unregister_sysctl(void);
18994 +static int __init init_vserver(void)
18998 +#ifdef CONFIG_VSERVER_DEBUG
18999 + vserver_register_sysctl();
19005 +static void __exit exit_vserver(void)
19008 +#ifdef CONFIG_VSERVER_DEBUG
19009 + vserver_unregister_sysctl();
19014 +/* FIXME: GFP_ZONETYPES gone
19015 +long vx_slab[GFP_ZONETYPES]; */
19019 +module_init(init_vserver);
19020 +module_exit(exit_vserver);
19022 diff -NurpP --minimal linux-3.9.4/kernel/vserver/inode.c linux-3.9.4-vs2.3.6.1/kernel/vserver/inode.c
19023 --- linux-3.9.4/kernel/vserver/inode.c 1970-01-01 00:00:00.000000000 +0000
19024 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/inode.c 2013-05-31 14:47:11.000000000 +0000
19027 + * linux/kernel/vserver/inode.c
19029 + * Virtual Server: File System Support
19031 + * Copyright (C) 2004-2007 Herbert Pötzl
19033 + * V0.01 separated from vcontext V0.05
19034 + * V0.02 moved to tag (instead of xid)
19038 +#include <linux/tty.h>
19039 +#include <linux/proc_fs.h>
19040 +#include <linux/devpts_fs.h>
19041 +#include <linux/fs.h>
19042 +#include <linux/file.h>
19043 +#include <linux/mount.h>
19044 +#include <linux/parser.h>
19045 +#include <linux/namei.h>
19046 +#include <linux/vserver/inode.h>
19047 +#include <linux/vserver/inode_cmd.h>
19048 +#include <linux/vs_base.h>
19049 +#include <linux/vs_tag.h>
19051 +#include <asm/uaccess.h>
19054 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19056 + struct proc_dir_entry *entry;
19058 + if (!in || !in->i_sb)
19061 + *flags = IATTR_TAG
19062 + | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19063 + | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19064 + | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19065 + | (IS_COW(in) ? IATTR_COW : 0);
19066 + *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19068 + if (S_ISDIR(in->i_mode))
19069 + *mask |= IATTR_BARRIER;
19071 + if (IS_TAGGED(in)) {
19072 + *tag = i_tag_read(in);
19073 + *mask |= IATTR_TAG;
19076 + switch (in->i_sb->s_magic) {
19077 + case PROC_SUPER_MAGIC:
19078 + entry = PROC_I(in)->pde;
19080 + /* check for specific inodes? */
19082 + *mask |= IATTR_FLAGS;
19084 + *flags |= (entry->vx_flags & IATTR_FLAGS);
19086 + *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19089 + case DEVPTS_SUPER_MAGIC:
19090 + *tag = i_tag_read(in);
19091 + *mask |= IATTR_TAG;
19100 +int vc_get_iattr(void __user *data)
19102 + struct path path;
19103 + struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19106 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19109 + ret = user_lpath(vc_data.name, &path);
19111 + ret = __vc_get_iattr(path.dentry->d_inode,
19112 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19118 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19123 +#ifdef CONFIG_COMPAT
19125 +int vc_get_iattr_x32(void __user *data)
19127 + struct path path;
19128 + struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19131 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19134 + ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19136 + ret = __vc_get_iattr(path.dentry->d_inode,
19137 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19143 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19148 +#endif /* CONFIG_COMPAT */
19151 +int vc_fget_iattr(uint32_t fd, void __user *data)
19153 + struct file *filp;
19154 + struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19157 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19161 + if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19164 + ret = __vc_get_iattr(filp->f_dentry->d_inode,
19165 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19169 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19175 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19177 + struct inode *in = de->d_inode;
19178 + int error = 0, is_proc = 0, has_tag = 0;
19179 + struct iattr attr = { 0 };
19181 + if (!in || !in->i_sb)
19184 + is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19185 + if ((*mask & IATTR_FLAGS) && !is_proc)
19188 + has_tag = IS_TAGGED(in) ||
19189 + (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19190 + if ((*mask & IATTR_TAG) && !has_tag)
19193 + mutex_lock(&in->i_mutex);
19194 + if (*mask & IATTR_TAG) {
19195 + attr.ia_tag = *tag;
19196 + attr.ia_valid |= ATTR_TAG;
19199 + if (*mask & IATTR_FLAGS) {
19200 + struct proc_dir_entry *entry = PROC_I(in)->pde;
19201 + unsigned int iflags = PROC_I(in)->vx_flags;
19203 + iflags = (iflags & ~(*mask & IATTR_FLAGS))
19204 + | (*flags & IATTR_FLAGS);
19205 + PROC_I(in)->vx_flags = iflags;
19207 + entry->vx_flags = iflags;
19210 + if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19211 + IATTR_BARRIER | IATTR_COW)) {
19212 + int iflags = in->i_flags;
19213 + int vflags = in->i_vflags;
19215 + if (*mask & IATTR_IMMUTABLE) {
19216 + if (*flags & IATTR_IMMUTABLE)
19217 + iflags |= S_IMMUTABLE;
19219 + iflags &= ~S_IMMUTABLE;
19221 + if (*mask & IATTR_IXUNLINK) {
19222 + if (*flags & IATTR_IXUNLINK)
19223 + iflags |= S_IXUNLINK;
19225 + iflags &= ~S_IXUNLINK;
19227 + if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19228 + if (*flags & IATTR_BARRIER)
19229 + vflags |= V_BARRIER;
19231 + vflags &= ~V_BARRIER;
19233 + if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19234 + if (*flags & IATTR_COW)
19237 + vflags &= ~V_COW;
19239 + if (in->i_op && in->i_op->sync_flags) {
19240 + error = in->i_op->sync_flags(in, iflags, vflags);
19246 + if (attr.ia_valid) {
19247 + if (in->i_op && in->i_op->setattr)
19248 + error = in->i_op->setattr(de, &attr);
19250 + error = inode_change_ok(in, &attr);
19252 + setattr_copy(in, &attr);
19253 + mark_inode_dirty(in);
19259 + mutex_unlock(&in->i_mutex);
19263 +int vc_set_iattr(void __user *data)
19265 + struct path path;
19266 + struct vcmd_ctx_iattr_v1 vc_data;
19269 + if (!capable(CAP_LINUX_IMMUTABLE))
19271 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19274 + ret = user_lpath(vc_data.name, &path);
19276 + ret = __vc_set_iattr(path.dentry,
19277 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19281 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19286 +#ifdef CONFIG_COMPAT
19288 +int vc_set_iattr_x32(void __user *data)
19290 + struct path path;
19291 + struct vcmd_ctx_iattr_v1_x32 vc_data;
19294 + if (!capable(CAP_LINUX_IMMUTABLE))
19296 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19299 + ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19301 + ret = __vc_set_iattr(path.dentry,
19302 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19306 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19311 +#endif /* CONFIG_COMPAT */
19313 +int vc_fset_iattr(uint32_t fd, void __user *data)
19315 + struct file *filp;
19316 + struct vcmd_ctx_fiattr_v0 vc_data;
19319 + if (!capable(CAP_LINUX_IMMUTABLE))
19321 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19325 + if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19328 + ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19329 + &vc_data.flags, &vc_data.mask);
19333 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19339 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19341 +static match_table_t tokens = {
19342 + {Opt_notagcheck, "notagcheck"},
19343 +#ifdef CONFIG_PROPAGATE
19344 + {Opt_notag, "notag"},
19345 + {Opt_tag, "tag"},
19346 + {Opt_tagid, "tagid=%u"},
19352 +static void __dx_parse_remove(char *string, char *opt)
19354 + char *p = strstr(string, opt);
19358 + while (*q != '\0' && *q != ',')
19367 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19368 + unsigned long *flags)
19371 + substring_t args[MAX_OPT_ARGS];
19373 + char *s, *p, *opts;
19374 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19380 + s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19385 + while ((p = strsep(&opts, ",")) != NULL) {
19386 + token = match_token(p, tokens, args);
19389 +#ifdef CONFIG_PROPAGATE
19394 + __dx_parse_remove(s, "tag");
19395 + *mnt_flags |= MNT_TAGID;
19396 + set |= MNT_TAGID;
19400 + __dx_parse_remove(s, "notag");
19401 + *mnt_flags |= MNT_NOTAG;
19402 + set |= MNT_NOTAG;
19405 + if (tag && !match_int(args, &option))
19408 + __dx_parse_remove(s, "tagid");
19409 + *mnt_flags |= MNT_TAGID;
19410 + set |= MNT_TAGID;
19412 +#endif /* CONFIG_PROPAGATE */
19413 + case Opt_notagcheck:
19415 + __dx_parse_remove(s, "notagcheck");
19416 + *flags |= MS_NOTAGCHECK;
19417 + set |= MS_NOTAGCHECK;
19420 + vxdprintk(VXD_CBIT(tag, 7),
19421 + "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19422 + p, token, option);
19425 + strcpy(string, s);
19430 +#ifdef CONFIG_PROPAGATE
19432 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19434 + tag_t new_tag = 0;
19435 + struct vfsmount *mnt;
19440 + mnt = nd->path.mnt;
19444 + propagate = (mnt->mnt_flags & MNT_TAGID);
19446 + new_tag = mnt->mnt_tag;
19448 + vxdprintk(VXD_CBIT(tag, 7),
19449 + "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19450 + inode, inode->i_ino, inode->i_tag,
19451 + new_tag, (propagate) ? 1 : 0);
19454 + i_tag_write(inode, new_tag);
19457 +#include <linux/module.h>
19459 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19461 +#endif /* CONFIG_PROPAGATE */
19463 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit.c linux-3.9.4-vs2.3.6.1/kernel/vserver/limit.c
19464 --- linux-3.9.4/kernel/vserver/limit.c 1970-01-01 00:00:00.000000000 +0000
19465 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/limit.c 2013-05-31 14:47:11.000000000 +0000
19468 + * linux/kernel/vserver/limit.c
19470 + * Virtual Server: Context Limits
19472 + * Copyright (C) 2004-2010 Herbert Pötzl
19474 + * V0.01 broken out from vcontext V0.05
19475 + * V0.02 changed vcmds to vxi arg
19476 + * V0.03 added memory cgroup support
19480 +#include <linux/sched.h>
19481 +#include <linux/module.h>
19482 +#include <linux/memcontrol.h>
19483 +#include <linux/res_counter.h>
19484 +#include <linux/vs_limit.h>
19485 +#include <linux/vserver/limit.h>
19486 +#include <linux/vserver/limit_cmd.h>
19488 +#include <asm/uaccess.h>
19491 +const char *vlimit_name[NUM_LIMITS] = {
19492 + [RLIMIT_CPU] = "CPU",
19493 + [RLIMIT_NPROC] = "NPROC",
19494 + [RLIMIT_NOFILE] = "NOFILE",
19495 + [RLIMIT_LOCKS] = "LOCKS",
19496 + [RLIMIT_SIGPENDING] = "SIGP",
19497 + [RLIMIT_MSGQUEUE] = "MSGQ",
19499 + [VLIMIT_NSOCK] = "NSOCK",
19500 + [VLIMIT_OPENFD] = "OPENFD",
19501 + [VLIMIT_SHMEM] = "SHMEM",
19502 + [VLIMIT_DENTRY] = "DENTRY",
19505 +EXPORT_SYMBOL_GPL(vlimit_name);
19507 +#define MASK_ENTRY(x) (1 << (x))
19509 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19512 + , /* softlimit */
19515 + MASK_ENTRY( RLIMIT_NPROC ) |
19516 + MASK_ENTRY( RLIMIT_NOFILE ) |
19517 + MASK_ENTRY( RLIMIT_LOCKS ) |
19518 + MASK_ENTRY( RLIMIT_MSGQUEUE ) |
19520 + MASK_ENTRY( VLIMIT_NSOCK ) |
19521 + MASK_ENTRY( VLIMIT_OPENFD ) |
19522 + MASK_ENTRY( VLIMIT_SHMEM ) |
19523 + MASK_ENTRY( VLIMIT_DENTRY ) |
19526 + /* accounting only */
19527 +uint32_t account_mask =
19528 + MASK_ENTRY( VLIMIT_SEMARY ) |
19529 + MASK_ENTRY( VLIMIT_NSEMS ) |
19530 + MASK_ENTRY( VLIMIT_MAPPED ) |
19534 +static int is_valid_vlimit(int id)
19536 + uint32_t mask = vlimit_mask.minimum |
19537 + vlimit_mask.softlimit | vlimit_mask.maximum;
19538 + return mask & (1 << id);
19541 +static int is_accounted_vlimit(int id)
19543 + if (is_valid_vlimit(id))
19545 + return account_mask & (1 << id);
19549 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19551 + rlim_t limit = __rlim_soft(&vxi->limit, id);
19552 + return VX_VLIM(limit);
19555 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19557 + rlim_t limit = __rlim_hard(&vxi->limit, id);
19558 + return VX_VLIM(limit);
19561 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19562 + uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19564 + if (!is_valid_vlimit(id))
19568 + *minimum = CRLIM_UNSET;
19570 + *softlimit = vc_get_soft(vxi, id);
19572 + *maximum = vc_get_hard(vxi, id);
19576 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19578 + struct vcmd_ctx_rlimit_v0 vc_data;
19581 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19584 + ret = do_get_rlimit(vxi, vc_data.id,
19585 + &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19589 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19594 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19595 + uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19597 + if (!is_valid_vlimit(id))
19600 + if (maximum != CRLIM_KEEP)
19601 + __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19602 + if (softlimit != CRLIM_KEEP)
19603 + __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19605 + /* clamp soft limit */
19606 + if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19607 + __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19612 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19614 + struct vcmd_ctx_rlimit_v0 vc_data;
19616 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19619 + return do_set_rlimit(vxi, vc_data.id,
19620 + vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19623 +#ifdef CONFIG_IA32_EMULATION
19625 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19627 + struct vcmd_ctx_rlimit_v0_x32 vc_data;
19629 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19632 + return do_set_rlimit(vxi, vc_data.id,
19633 + vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19636 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19638 + struct vcmd_ctx_rlimit_v0_x32 vc_data;
19641 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19644 + ret = do_get_rlimit(vxi, vc_data.id,
19645 + &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19649 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19654 +#endif /* CONFIG_IA32_EMULATION */
19657 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19659 + if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19665 +static inline void vx_reset_hits(struct _vx_limit *limit)
19669 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19670 + atomic_set(&__rlim_lhit(limit, lim), 0);
19674 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19676 + vx_reset_hits(&vxi->limit);
19680 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19685 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19686 + value = __rlim_get(limit, lim);
19687 + __rlim_rmax(limit, lim) = value;
19688 + __rlim_rmin(limit, lim) = value;
19692 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19694 + vx_reset_minmax(&vxi->limit);
19699 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19701 + struct vcmd_rlimit_stat_v0 vc_data;
19702 + struct _vx_limit *limit = &vxi->limit;
19705 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19709 + if (!is_accounted_vlimit(id))
19712 + vx_limit_fixup(limit, id);
19713 + vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19714 + vc_data.value = __rlim_get(limit, id);
19715 + vc_data.minimum = __rlim_rmin(limit, id);
19716 + vc_data.maximum = __rlim_rmax(limit, id);
19718 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19724 +void vx_vsi_meminfo(struct sysinfo *val)
19726 +#ifdef CONFIG_MEMCG
19727 + struct mem_cgroup *mcg;
19728 + u64 res_limit, res_usage;
19731 + mcg = mem_cgroup_from_task(current);
19732 + rcu_read_unlock();
19736 + res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19737 + res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19739 + if (res_limit != RESOURCE_MAX)
19740 + val->totalram = (res_limit >> PAGE_SHIFT);
19741 + val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19742 + val->bufferram = 0;
19743 + val->totalhigh = 0;
19744 + val->freehigh = 0;
19746 +#endif /* CONFIG_MEMCG */
19750 +void vx_vsi_swapinfo(struct sysinfo *val)
19752 +#ifdef CONFIG_MEMCG
19753 +#ifdef CONFIG_MEMCG_SWAP
19754 + struct mem_cgroup *mcg;
19755 + u64 res_limit, res_usage, memsw_limit, memsw_usage;
19756 + s64 swap_limit, swap_usage;
19759 + mcg = mem_cgroup_from_task(current);
19760 + rcu_read_unlock();
19764 + res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19765 + res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19766 + memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19767 + memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19769 + /* memory unlimited */
19770 + if (res_limit == RESOURCE_MAX)
19773 + swap_limit = memsw_limit - res_limit;
19774 + /* we have a swap limit? */
19775 + if (memsw_limit != RESOURCE_MAX)
19776 + val->totalswap = swap_limit >> PAGE_SHIFT;
19778 + /* calculate swap part */
19779 + swap_usage = (memsw_usage > res_usage) ?
19780 + memsw_usage - res_usage : 0;
19782 + /* total shown minus usage gives free swap */
19783 + val->freeswap = (swap_usage < swap_limit) ?
19784 + val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19786 +#else /* !CONFIG_MEMCG_SWAP */
19787 + val->totalswap = 0;
19788 + val->freeswap = 0;
19789 +#endif /* !CONFIG_MEMCG_SWAP */
19790 +#endif /* CONFIG_MEMCG */
19794 +long vx_vsi_cached(struct sysinfo *val)
19797 +#ifdef CONFIG_MEMCG
19798 + struct mem_cgroup *mcg;
19801 + mcg = mem_cgroup_from_task(current);
19802 + rcu_read_unlock();
19806 + cache = mem_cgroup_stat_read_cache(mcg);
19812 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit_init.h linux-3.9.4-vs2.3.6.1/kernel/vserver/limit_init.h
19813 --- linux-3.9.4/kernel/vserver/limit_init.h 1970-01-01 00:00:00.000000000 +0000
19814 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/limit_init.h 2013-05-31 14:47:11.000000000 +0000
19818 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19822 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19823 + __rlim_soft(limit, lim) = RLIM_INFINITY;
19824 + __rlim_hard(limit, lim) = RLIM_INFINITY;
19825 + __rlim_set(limit, lim, 0);
19826 + atomic_set(&__rlim_lhit(limit, lim), 0);
19827 + __rlim_rmin(limit, lim) = 0;
19828 + __rlim_rmax(limit, lim) = 0;
19832 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19837 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19838 + if ((1 << lim) & VLIM_NOCHECK)
19840 + value = __rlim_get(limit, lim);
19841 + vxwprintk_xid(value,
19842 + "!!! limit: %p[%s,%d] = %ld on exit.",
19843 + limit, vlimit_name[lim], lim, (long)value);
19847 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit_proc.h linux-3.9.4-vs2.3.6.1/kernel/vserver/limit_proc.h
19848 --- linux-3.9.4/kernel/vserver/limit_proc.h 1970-01-01 00:00:00.000000000 +0000
19849 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/limit_proc.h 2013-05-31 14:47:11.000000000 +0000
19851 +#ifndef _VX_LIMIT_PROC_H
19852 +#define _VX_LIMIT_PROC_H
19854 +#include <linux/vserver/limit_int.h>
19857 +#define VX_LIMIT_FMT ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19858 +#define VX_LIMIT_TOP \
19859 + "Limit\t current\t min/max\t\t soft/hard\t\thits\n"
19861 +#define VX_LIMIT_ARG(r) \
19862 + (unsigned long)__rlim_get(limit, r), \
19863 + (unsigned long)__rlim_rmin(limit, r), \
19864 + (unsigned long)__rlim_rmax(limit, r), \
19865 + VX_VLIM(__rlim_soft(limit, r)), \
19866 + VX_VLIM(__rlim_hard(limit, r)), \
19867 + atomic_read(&__rlim_lhit(limit, r))
19869 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19871 + vx_limit_fixup(limit, -1);
19872 + return sprintf(buffer, VX_LIMIT_TOP
19873 + "PROC" VX_LIMIT_FMT
19874 + "VM" VX_LIMIT_FMT
19875 + "VML" VX_LIMIT_FMT
19876 + "RSS" VX_LIMIT_FMT
19877 + "ANON" VX_LIMIT_FMT
19878 + "RMAP" VX_LIMIT_FMT
19879 + "FILES" VX_LIMIT_FMT
19880 + "OFD" VX_LIMIT_FMT
19881 + "LOCKS" VX_LIMIT_FMT
19882 + "SOCK" VX_LIMIT_FMT
19883 + "MSGQ" VX_LIMIT_FMT
19884 + "SHM" VX_LIMIT_FMT
19885 + "SEMA" VX_LIMIT_FMT
19886 + "SEMS" VX_LIMIT_FMT
19887 + "DENT" VX_LIMIT_FMT,
19888 + VX_LIMIT_ARG(RLIMIT_NPROC),
19889 + VX_LIMIT_ARG(RLIMIT_AS),
19890 + VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19891 + VX_LIMIT_ARG(RLIMIT_RSS),
19892 + VX_LIMIT_ARG(VLIMIT_ANON),
19893 + VX_LIMIT_ARG(VLIMIT_MAPPED),
19894 + VX_LIMIT_ARG(RLIMIT_NOFILE),
19895 + VX_LIMIT_ARG(VLIMIT_OPENFD),
19896 + VX_LIMIT_ARG(RLIMIT_LOCKS),
19897 + VX_LIMIT_ARG(VLIMIT_NSOCK),
19898 + VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19899 + VX_LIMIT_ARG(VLIMIT_SHMEM),
19900 + VX_LIMIT_ARG(VLIMIT_SEMARY),
19901 + VX_LIMIT_ARG(VLIMIT_NSEMS),
19902 + VX_LIMIT_ARG(VLIMIT_DENTRY));
19905 +#endif /* _VX_LIMIT_PROC_H */
19908 diff -NurpP --minimal linux-3.9.4/kernel/vserver/network.c linux-3.9.4-vs2.3.6.1/kernel/vserver/network.c
19909 --- linux-3.9.4/kernel/vserver/network.c 1970-01-01 00:00:00.000000000 +0000
19910 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/network.c 2013-05-31 14:47:11.000000000 +0000
19913 + * linux/kernel/vserver/network.c
19915 + * Virtual Server: Network Support
19917 + * Copyright (C) 2003-2007 Herbert Pötzl
19919 + * V0.01 broken out from vcontext V0.05
19920 + * V0.02 cleaned up implementation
19921 + * V0.03 added equiv nx commands
19922 + * V0.04 switch to RCU based hash
19923 + * V0.05 and back to locking again
19924 + * V0.06 changed vcmds to nxi arg
19925 + * V0.07 have __create claim() the nxi
19929 +#include <linux/err.h>
19930 +#include <linux/slab.h>
19931 +#include <linux/rcupdate.h>
19932 +#include <net/ipv6.h>
19934 +#include <linux/vs_network.h>
19935 +#include <linux/vs_pid.h>
19936 +#include <linux/vserver/network_cmd.h>
19939 +atomic_t nx_global_ctotal = ATOMIC_INIT(0);
19940 +atomic_t nx_global_cactive = ATOMIC_INIT(0);
19942 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19943 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19946 +static int __init init_network(void)
19948 + nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19949 + sizeof(struct nx_addr_v4), 0,
19950 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19951 + nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19952 + sizeof(struct nx_addr_v6), 0,
19953 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19958 +/* __alloc_nx_addr_v4() */
19960 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19962 + struct nx_addr_v4 *nxa = kmem_cache_alloc(
19963 + nx_addr_v4_cachep, GFP_KERNEL);
19965 + if (!IS_ERR(nxa))
19966 + memset(nxa, 0, sizeof(*nxa));
19970 +/* __dealloc_nx_addr_v4() */
19972 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19974 + kmem_cache_free(nx_addr_v4_cachep, nxa);
19977 +/* __dealloc_nx_addr_v4_all() */
19979 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19982 + struct nx_addr_v4 *next = nxa->next;
19984 + __dealloc_nx_addr_v4(nxa);
19990 +#ifdef CONFIG_IPV6
19992 +/* __alloc_nx_addr_v6() */
19994 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19996 + struct nx_addr_v6 *nxa = kmem_cache_alloc(
19997 + nx_addr_v6_cachep, GFP_KERNEL);
19999 + if (!IS_ERR(nxa))
20000 + memset(nxa, 0, sizeof(*nxa));
20004 +/* __dealloc_nx_addr_v6() */
20006 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20008 + kmem_cache_free(nx_addr_v6_cachep, nxa);
20011 +/* __dealloc_nx_addr_v6_all() */
20013 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20016 + struct nx_addr_v6 *next = nxa->next;
20018 + __dealloc_nx_addr_v6(nxa);
20023 +#endif /* CONFIG_IPV6 */
20025 +/* __alloc_nx_info()
20027 + * allocate an initialized nx_info struct
20028 + * doesn't make it visible (hash) */
20030 +static struct nx_info *__alloc_nx_info(nid_t nid)
20032 + struct nx_info *new = NULL;
20034 + vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20036 + /* would this benefit from a slab cache? */
20037 + new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20041 + memset(new, 0, sizeof(struct nx_info));
20042 + new->nx_id = nid;
20043 + INIT_HLIST_NODE(&new->nx_hlist);
20044 + atomic_set(&new->nx_usecnt, 0);
20045 + atomic_set(&new->nx_tasks, 0);
20046 + spin_lock_init(&new->addr_lock);
20047 + new->nx_state = 0;
20049 + new->nx_flags = NXF_INIT_SET;
20051 + /* rest of init goes here */
20053 + new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20054 + new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20056 + vxdprintk(VXD_CBIT(nid, 0),
20057 + "alloc_nx_info(%d) = %p", nid, new);
20058 + atomic_inc(&nx_global_ctotal);
20062 +/* __dealloc_nx_info()
20064 + * final disposal of nx_info */
20066 +static void __dealloc_nx_info(struct nx_info *nxi)
20068 + vxdprintk(VXD_CBIT(nid, 0),
20069 + "dealloc_nx_info(%p)", nxi);
20071 + nxi->nx_hlist.next = LIST_POISON1;
20074 + BUG_ON(atomic_read(&nxi->nx_usecnt));
20075 + BUG_ON(atomic_read(&nxi->nx_tasks));
20077 + __dealloc_nx_addr_v4_all(nxi->v4.next);
20078 +#ifdef CONFIG_IPV6
20079 + __dealloc_nx_addr_v6_all(nxi->v6.next);
20082 + nxi->nx_state |= NXS_RELEASED;
20084 + atomic_dec(&nx_global_ctotal);
20087 +static void __shutdown_nx_info(struct nx_info *nxi)
20089 + nxi->nx_state |= NXS_SHUTDOWN;
20090 + vs_net_change(nxi, VSC_NETDOWN);
20093 +/* exported stuff */
20095 +void free_nx_info(struct nx_info *nxi)
20097 + /* context shutdown is mandatory */
20098 + BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20100 + /* context must not be hashed */
20101 + BUG_ON(nxi->nx_state & NXS_HASHED);
20103 + BUG_ON(atomic_read(&nxi->nx_usecnt));
20104 + BUG_ON(atomic_read(&nxi->nx_tasks));
20106 + __dealloc_nx_info(nxi);
20110 +void __nx_set_lback(struct nx_info *nxi)
20112 + int nid = nxi->nx_id;
20113 + __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20115 + nxi->v4_lback.s_addr = lback;
20118 +extern int __nx_inet_add_lback(__be32 addr);
20119 +extern int __nx_inet_del_lback(__be32 addr);
20122 +/* hash table for nx_info hash */
20124 +#define NX_HASH_SIZE 13
20126 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20128 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20131 +static inline unsigned int __hashval(nid_t nid)
20133 + return (nid % NX_HASH_SIZE);
20138 +/* __hash_nx_info()
20140 + * add the nxi to the global hash table
20141 + * requires the hash_lock to be held */
20143 +static inline void __hash_nx_info(struct nx_info *nxi)
20145 + struct hlist_head *head;
20147 + vxd_assert_lock(&nx_info_hash_lock);
20148 + vxdprintk(VXD_CBIT(nid, 4),
20149 + "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20151 + /* context must not be hashed */
20152 + BUG_ON(nx_info_state(nxi, NXS_HASHED));
20154 + nxi->nx_state |= NXS_HASHED;
20155 + head = &nx_info_hash[__hashval(nxi->nx_id)];
20156 + hlist_add_head(&nxi->nx_hlist, head);
20157 + atomic_inc(&nx_global_cactive);
20160 +/* __unhash_nx_info()
20162 + * remove the nxi from the global hash table
20163 + * requires the hash_lock to be held */
20165 +static inline void __unhash_nx_info(struct nx_info *nxi)
20167 + vxd_assert_lock(&nx_info_hash_lock);
20168 + vxdprintk(VXD_CBIT(nid, 4),
20169 + "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20170 + atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20172 + /* context must be hashed */
20173 + BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20174 + /* but without tasks */
20175 + BUG_ON(atomic_read(&nxi->nx_tasks));
20177 + nxi->nx_state &= ~NXS_HASHED;
20178 + hlist_del(&nxi->nx_hlist);
20179 + atomic_dec(&nx_global_cactive);
20183 +/* __lookup_nx_info()
20185 + * requires the hash_lock to be held
20186 + * doesn't increment the nx_refcnt */
20188 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20190 + struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20191 + struct hlist_node *pos;
20192 + struct nx_info *nxi;
20194 + vxd_assert_lock(&nx_info_hash_lock);
20195 + hlist_for_each(pos, head) {
20196 + nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20198 + if (nxi->nx_id == nid)
20203 + vxdprintk(VXD_CBIT(nid, 0),
20204 + "__lookup_nx_info(#%u): %p[#%u]",
20205 + nid, nxi, nxi ? nxi->nx_id : 0);
20210 +/* __create_nx_info()
20212 + * create the requested context
20213 + * get(), claim() and hash it */
20215 +static struct nx_info *__create_nx_info(int id)
20217 + struct nx_info *new, *nxi = NULL;
20219 + vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20221 + if (!(new = __alloc_nx_info(id)))
20222 + return ERR_PTR(-ENOMEM);
20224 + /* required to make dynamic xids unique */
20225 + spin_lock(&nx_info_hash_lock);
20227 + /* static context requested */
20228 + if ((nxi = __lookup_nx_info(id))) {
20229 + vxdprintk(VXD_CBIT(nid, 0),
20230 + "create_nx_info(%d) = %p (already there)", id, nxi);
20231 + if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20232 + nxi = ERR_PTR(-EBUSY);
20234 + nxi = ERR_PTR(-EEXIST);
20237 + /* new context */
20238 + vxdprintk(VXD_CBIT(nid, 0),
20239 + "create_nx_info(%d) = %p (new)", id, new);
20240 + claim_nx_info(new, NULL);
20241 + __nx_set_lback(new);
20242 + __hash_nx_info(get_nx_info(new));
20243 + nxi = new, new = NULL;
20246 + spin_unlock(&nx_info_hash_lock);
20248 + __dealloc_nx_info(new);
20254 +/* exported stuff */
20257 +void unhash_nx_info(struct nx_info *nxi)
20259 + __shutdown_nx_info(nxi);
20260 + spin_lock(&nx_info_hash_lock);
20261 + __unhash_nx_info(nxi);
20262 + spin_unlock(&nx_info_hash_lock);
20265 +/* lookup_nx_info()
20267 + * search for a nx_info and get() it
20268 + * negative id means current */
20270 +struct nx_info *lookup_nx_info(int id)
20272 + struct nx_info *nxi = NULL;
20275 + nxi = get_nx_info(current_nx_info());
20276 + } else if (id > 1) {
20277 + spin_lock(&nx_info_hash_lock);
20278 + nxi = get_nx_info(__lookup_nx_info(id));
20279 + spin_unlock(&nx_info_hash_lock);
20284 +/* nid_is_hashed()
20286 + * verify that nid is still hashed */
20288 +int nid_is_hashed(nid_t nid)
20292 + spin_lock(&nx_info_hash_lock);
20293 + hashed = (__lookup_nx_info(nid) != NULL);
20294 + spin_unlock(&nx_info_hash_lock);
20299 +#ifdef CONFIG_PROC_FS
20303 + * get a subset of hashed nids for proc
20304 + * assumes size is at least one */
20306 +int get_nid_list(int index, unsigned int *nids, int size)
20308 + int hindex, nr_nids = 0;
20310 + /* only show current and children */
20311 + if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20314 + nids[nr_nids] = nx_current_nid();
20318 + for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20319 + struct hlist_head *head = &nx_info_hash[hindex];
20320 + struct hlist_node *pos;
20322 + spin_lock(&nx_info_hash_lock);
20323 + hlist_for_each(pos, head) {
20324 + struct nx_info *nxi;
20329 + nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20330 + nids[nr_nids] = nxi->nx_id;
20331 + if (++nr_nids >= size) {
20332 + spin_unlock(&nx_info_hash_lock);
20336 + /* keep the lock time short */
20337 + spin_unlock(&nx_info_hash_lock);
20346 + * migrate task to new network
20347 + * gets nxi, puts old_nxi on change
20350 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20352 + struct nx_info *old_nxi;
20358 + vxdprintk(VXD_CBIT(nid, 5),
20359 + "nx_migrate_task(%p,%p[#%d.%d.%d])",
20360 + p, nxi, nxi->nx_id,
20361 + atomic_read(&nxi->nx_usecnt),
20362 + atomic_read(&nxi->nx_tasks));
20364 + if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20365 + !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20368 + if (nx_info_state(nxi, NXS_SHUTDOWN))
20371 + /* maybe disallow this completely? */
20372 + old_nxi = task_get_nx_info(p);
20373 + if (old_nxi == nxi)
20378 + clr_nx_info(&p->nx_info);
20379 + claim_nx_info(nxi, p);
20380 + set_nx_info(&p->nx_info, nxi);
20381 + p->nid = nxi->nx_id;
20384 + vxdprintk(VXD_CBIT(nid, 5),
20385 + "moved task %p into nxi:%p[#%d]",
20386 + p, nxi, nxi->nx_id);
20389 + release_nx_info(old_nxi, p);
20392 + put_nx_info(old_nxi);
20397 +void nx_set_persistent(struct nx_info *nxi)
20399 + vxdprintk(VXD_CBIT(nid, 6),
20400 + "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20402 + get_nx_info(nxi);
20403 + claim_nx_info(nxi, NULL);
20406 +void nx_clear_persistent(struct nx_info *nxi)
20408 + vxdprintk(VXD_CBIT(nid, 6),
20409 + "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20411 + release_nx_info(nxi, NULL);
20412 + put_nx_info(nxi);
20415 +void nx_update_persistent(struct nx_info *nxi)
20417 + if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20418 + nx_set_persistent(nxi);
20420 + nx_clear_persistent(nxi);
20423 +/* vserver syscall commands below here */
20425 +/* taks nid and nx_info functions */
20427 +#include <asm/uaccess.h>
20430 +int vc_task_nid(uint32_t id)
20435 + struct task_struct *tsk;
20438 + tsk = find_task_by_real_pid(id);
20439 + nid = (tsk) ? tsk->nid : -ESRCH;
20440 + rcu_read_unlock();
20442 + nid = nx_current_nid();
20447 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20449 + struct vcmd_nx_info_v0 vc_data;
20451 + vc_data.nid = nxi->nx_id;
20453 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20459 +/* network functions */
20461 +int vc_net_create(uint32_t nid, void __user *data)
20463 + struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20464 + struct nx_info *new_nxi;
20467 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20470 + if ((nid > MAX_S_CONTEXT) || (nid < 2))
20473 + new_nxi = __create_nx_info(nid);
20474 + if (IS_ERR(new_nxi))
20475 + return PTR_ERR(new_nxi);
20477 + /* initial flags */
20478 + new_nxi->nx_flags = vc_data.flagword;
20481 + if (vs_net_change(new_nxi, VSC_NETUP))
20484 + ret = nx_migrate_task(current, new_nxi);
20488 + /* return context id on success */
20489 + ret = new_nxi->nx_id;
20491 + /* get a reference for persistent contexts */
20492 + if ((vc_data.flagword & NXF_PERSISTENT))
20493 + nx_set_persistent(new_nxi);
20495 + release_nx_info(new_nxi, NULL);
20496 + put_nx_info(new_nxi);
20501 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20503 + return nx_migrate_task(current, nxi);
20508 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
20509 + __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
20510 + struct nx_addr_v4 **prev)
20512 + struct nx_addr_v4 *nxa = &nxi->v4;
20514 + for (; nxa; nxa = nxa->next) {
20515 + if ((nxa->ip[0].s_addr == ip) &&
20516 + (nxa->ip[1].s_addr == ip2) &&
20517 + (nxa->mask.s_addr == mask) &&
20518 + (nxa->type == type) &&
20519 + (nxa->flags == flags))
20522 + /* save previous entry */
20529 +int do_add_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 *new = __alloc_nx_addr_v4();
20534 + unsigned long irqflags;
20535 + int ret = -EEXIST;
20538 + return PTR_ERR(new);
20540 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20541 + if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
20544 + if (NX_IPV4(nxi)) {
20549 + /* remove single ip for ip list */
20550 + nxi->nx_flags &= ~NXF_SINGLE_IP;
20553 + nxa->ip[0].s_addr = ip;
20554 + nxa->ip[1].s_addr = ip2;
20555 + nxa->mask.s_addr = mask;
20556 + nxa->type = type;
20557 + nxa->flags = flags;
20560 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20562 + __dealloc_nx_addr_v4(new);
20566 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20567 + uint16_t type, uint16_t flags)
20569 + struct nx_addr_v4 *nxa = NULL;
20570 + struct nx_addr_v4 *old = NULL;
20571 + unsigned long irqflags;
20574 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20576 + case NXA_TYPE_ADDR:
20577 + old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
20580 + nxa->next = old->next;
20581 + old->next = NULL;
20587 + old->next = NULL;
20589 + memset(old, 0, sizeof(*old));
20597 + case NXA_TYPE_ANY:
20600 + memset(nxa, 0, sizeof(*nxa));
20606 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20607 + __dealloc_nx_addr_v4_all(old);
20612 +int vc_net_add(struct nx_info *nxi, void __user *data)
20614 + struct vcmd_net_addr_v0 vc_data;
20615 + int index, ret = 0;
20617 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20620 + switch (vc_data.type) {
20621 + case NXA_TYPE_IPV4:
20622 + if ((vc_data.count < 1) || (vc_data.count > 4))
20626 + while (index < vc_data.count) {
20627 + ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20628 + vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20636 + case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20637 + nxi->v4_bcast = vc_data.ip[0];
20641 + case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20642 + nxi->v4_lback = vc_data.ip[0];
20653 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20655 + struct vcmd_net_addr_v0 vc_data;
20657 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20660 + switch (vc_data.type) {
20661 + case NXA_TYPE_ANY:
20662 + return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
20670 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20672 + struct vcmd_net_addr_ipv4_v1 vc_data;
20674 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20677 + switch (vc_data.type) {
20678 + case NXA_TYPE_ADDR:
20679 + case NXA_TYPE_MASK:
20680 + return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20681 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20683 + case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20684 + nxi->v4_bcast = vc_data.ip;
20687 + case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20688 + nxi->v4_lback = vc_data.ip;
20697 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20699 + struct vcmd_net_addr_ipv4_v2 vc_data;
20701 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20704 + switch (vc_data.type) {
20705 + case NXA_TYPE_ADDR:
20706 + case NXA_TYPE_MASK:
20707 + case NXA_TYPE_RANGE:
20708 + return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20709 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20711 + case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20712 + nxi->v4_bcast = vc_data.ip;
20715 + case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20716 + nxi->v4_lback = vc_data.ip;
20725 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20727 + struct vcmd_net_addr_ipv4_v1 vc_data;
20729 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20732 + return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20733 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20736 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20738 + struct vcmd_net_addr_ipv4_v2 vc_data;
20740 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20743 + return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20744 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20747 +#ifdef CONFIG_IPV6
20750 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20751 + struct in6_addr *ip, struct in6_addr *mask,
20752 + uint32_t prefix, uint16_t type, uint16_t flags,
20753 + struct nx_addr_v6 **prev)
20755 + struct nx_addr_v6 *nxa = &nxi->v6;
20757 + for (; nxa; nxa = nxa->next) {
20758 + if (ipv6_addr_equal(&nxa->ip, ip) &&
20759 + ipv6_addr_equal(&nxa->mask, mask) &&
20760 + (nxa->prefix == prefix) &&
20761 + (nxa->type == type) &&
20762 + (nxa->flags == flags))
20765 + /* save previous entry */
20773 +int do_add_v6_addr(struct nx_info *nxi,
20774 + struct in6_addr *ip, struct in6_addr *mask,
20775 + uint32_t prefix, uint16_t type, uint16_t flags)
20777 + struct nx_addr_v6 *nxa = NULL;
20778 + struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20779 + unsigned long irqflags;
20780 + int ret = -EEXIST;
20783 + return PTR_ERR(new);
20785 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20786 + if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20789 + if (NX_IPV6(nxi)) {
20796 + nxa->mask = *mask;
20797 + nxa->prefix = prefix;
20798 + nxa->type = type;
20799 + nxa->flags = flags;
20802 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20804 + __dealloc_nx_addr_v6(new);
20808 +int do_remove_v6_addr(struct nx_info *nxi,
20809 + struct in6_addr *ip, struct in6_addr *mask,
20810 + uint32_t prefix, uint16_t type, uint16_t flags)
20812 + struct nx_addr_v6 *nxa = NULL;
20813 + struct nx_addr_v6 *old = NULL;
20814 + unsigned long irqflags;
20817 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20819 + case NXA_TYPE_ADDR:
20820 + old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20823 + nxa->next = old->next;
20824 + old->next = NULL;
20830 + old->next = NULL;
20832 + memset(old, 0, sizeof(*old));
20840 + case NXA_TYPE_ANY:
20843 + memset(nxa, 0, sizeof(*nxa));
20849 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20850 + __dealloc_nx_addr_v6_all(old);
20854 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20856 + struct vcmd_net_addr_ipv6_v1 vc_data;
20858 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20861 + switch (vc_data.type) {
20862 + case NXA_TYPE_ADDR:
20863 + memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20864 + /* fallthrough */
20865 + case NXA_TYPE_MASK:
20866 + return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20867 + vc_data.prefix, vc_data.type, vc_data.flags);
20874 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20876 + struct vcmd_net_addr_ipv6_v1 vc_data;
20878 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20881 + switch (vc_data.type) {
20882 + case NXA_TYPE_ADDR:
20883 + memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20884 + /* fallthrough */
20885 + case NXA_TYPE_MASK:
20886 + return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20887 + vc_data.prefix, vc_data.type, vc_data.flags);
20888 + case NXA_TYPE_ANY:
20889 + return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20896 +#endif /* CONFIG_IPV6 */
20899 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20901 + struct vcmd_net_flags_v0 vc_data;
20903 + vc_data.flagword = nxi->nx_flags;
20905 + /* special STATE flag handling */
20906 + vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20908 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20913 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20915 + struct vcmd_net_flags_v0 vc_data;
20916 + uint64_t mask, trigger;
20918 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20921 + /* special STATE flag handling */
20922 + mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20923 + trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20925 + nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20926 + vc_data.flagword, mask);
20927 + if (trigger & NXF_PERSISTENT)
20928 + nx_update_persistent(nxi);
20933 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20935 + struct vcmd_net_caps_v0 vc_data;
20937 + vc_data.ncaps = nxi->nx_ncaps;
20938 + vc_data.cmask = ~0ULL;
20940 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20945 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20947 + struct vcmd_net_caps_v0 vc_data;
20949 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20952 + nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20953 + vc_data.ncaps, vc_data.cmask);
20958 +#include <linux/module.h>
20960 +module_init(init_network);
20962 +EXPORT_SYMBOL_GPL(free_nx_info);
20963 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20965 diff -NurpP --minimal linux-3.9.4/kernel/vserver/proc.c linux-3.9.4-vs2.3.6.1/kernel/vserver/proc.c
20966 --- linux-3.9.4/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
20967 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/proc.c 2013-05-31 14:47:11.000000000 +0000
20970 + * linux/kernel/vserver/proc.c
20972 + * Virtual Context Support
20974 + * Copyright (C) 2003-2011 Herbert Pötzl
20976 + * V0.01 basic structure
20977 + * V0.02 adaptation vs1.3.0
20978 + * V0.03 proc permissions
20979 + * V0.04 locking/generic
20980 + * V0.05 next generation procfs
20981 + * V0.06 inode validation
20982 + * V0.07 generic rewrite vid
20983 + * V0.08 remove inode type
20984 + * V0.09 added u/wmask info
20988 +#include <linux/proc_fs.h>
20989 +#include <linux/fs_struct.h>
20990 +#include <linux/mount.h>
20991 +#include <linux/namei.h>
20992 +#include <asm/unistd.h>
20994 +#include <linux/vs_context.h>
20995 +#include <linux/vs_network.h>
20996 +#include <linux/vs_cvirt.h>
20998 +#include <linux/in.h>
20999 +#include <linux/inetdevice.h>
21000 +#include <linux/vs_inet.h>
21001 +#include <linux/vs_inet6.h>
21003 +#include <linux/vserver/global.h>
21005 +#include "cvirt_proc.h"
21006 +#include "cacct_proc.h"
21007 +#include "limit_proc.h"
21008 +#include "sched_proc.h"
21009 +#include "vci_config.h"
21012 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21016 + CAP_FOR_EACH_U32(__capi) {
21017 + buffer += sprintf(buffer, "%08x",
21018 + c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21024 +static struct proc_dir_entry *proc_virtual;
21026 +static struct proc_dir_entry *proc_virtnet;
21029 +/* first the actual feeds */
21032 +static int proc_vci(char *buffer)
21034 + return sprintf(buffer,
21035 + "VCIVersion:\t%04x:%04x\n"
21036 + "VCISyscall:\t%d\n"
21037 + "VCIKernel:\t%08x\n",
21038 + VCI_VERSION >> 16,
21039 + VCI_VERSION & 0xFFFF,
21041 + vci_kernel_config());
21044 +static int proc_virtual_info(char *buffer)
21046 + return proc_vci(buffer);
21049 +static int proc_virtual_status(char *buffer)
21051 + return sprintf(buffer,
21053 + "#CActive:\t%d\n"
21054 + "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21055 + "#InitTask:\t%d\t%d %d\n",
21056 + atomic_read(&vx_global_ctotal),
21057 + atomic_read(&vx_global_cactive),
21058 + atomic_read(&vs_global_nsproxy),
21059 + atomic_read(&vs_global_fs),
21060 + atomic_read(&vs_global_mnt_ns),
21061 + atomic_read(&vs_global_uts_ns),
21062 + atomic_read(&nr_ipc_ns),
21063 + atomic_read(&vs_global_user_ns),
21064 + atomic_read(&vs_global_pid_ns),
21065 + atomic_read(&init_task.usage),
21066 + atomic_read(&init_task.nsproxy->count),
21067 + init_task.fs->users);
21071 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21075 + length = sprintf(buffer,
21083 + vxi->vx_badness_bias);
21087 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21089 + char *orig = buffer;
21091 + buffer += sprintf(buffer,
21094 + "Flags:\t%016llx\n",
21095 + atomic_read(&vxi->vx_usecnt),
21096 + atomic_read(&vxi->vx_tasks),
21097 + (unsigned long long)vxi->vx_flags);
21099 + buffer += sprintf(buffer, "BCaps:\t");
21100 + buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21101 + buffer += sprintf(buffer, "\n");
21103 + buffer += sprintf(buffer,
21104 + "CCaps:\t%016llx\n"
21105 + "Umask:\t%16llx\n"
21106 + "Wmask:\t%16llx\n"
21107 + "Spaces:\t%08lx %08lx\n",
21108 + (unsigned long long)vxi->vx_ccaps,
21109 + (unsigned long long)vxi->vx_umask,
21110 + (unsigned long long)vxi->vx_wmask,
21111 + vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21112 + return buffer - orig;
21115 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21117 + return vx_info_proc_limit(&vxi->limit, buffer);
21120 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21124 + length = vx_info_proc_sched(&vxi->sched, buffer);
21125 + for_each_online_cpu(cpu) {
21126 + length += vx_info_proc_sched_pc(
21127 + &vx_per_cpu(vxi, sched_pc, cpu),
21128 + buffer + length, cpu);
21133 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21135 + return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21138 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21140 + return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21143 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21147 + vx_update_load(vxi);
21148 + length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21149 + for_each_online_cpu(cpu) {
21150 + length += vx_info_proc_cvirt_pc(
21151 + &vx_per_cpu(vxi, cvirt_pc, cpu),
21152 + buffer + length, cpu);
21157 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21159 + return vx_info_proc_cacct(&vxi->cacct, buffer);
21163 +static int proc_virtnet_info(char *buffer)
21165 + return proc_vci(buffer);
21168 +static int proc_virtnet_status(char *buffer)
21170 + return sprintf(buffer,
21172 + "#CActive:\t%d\n",
21173 + atomic_read(&nx_global_ctotal),
21174 + atomic_read(&nx_global_cactive));
21177 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21179 + struct nx_addr_v4 *v4a;
21180 +#ifdef CONFIG_IPV6
21181 + struct nx_addr_v6 *v6a;
21185 + length = sprintf(buffer,
21188 + "Bcast:\t" NIPQUAD_FMT "\n"
21189 + "Lback:\t" NIPQUAD_FMT "\n",
21192 + NIPQUAD(nxi->v4_bcast.s_addr),
21193 + NIPQUAD(nxi->v4_lback.s_addr));
21195 + if (!NX_IPV4(nxi))
21197 + for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21198 + length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21201 +#ifdef CONFIG_IPV6
21202 + if (!NX_IPV6(nxi))
21204 + for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21205 + length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21212 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21216 + length = sprintf(buffer,
21219 + "Flags:\t%016llx\n"
21220 + "NCaps:\t%016llx\n",
21221 + atomic_read(&nxi->nx_usecnt),
21222 + atomic_read(&nxi->nx_tasks),
21223 + (unsigned long long)nxi->nx_flags,
21224 + (unsigned long long)nxi->nx_ncaps);
21230 +/* here the inode helpers */
21236 + struct inode_operations *iop;
21237 + struct file_operations *fop;
21238 + union proc_op op;
21241 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21243 + struct inode *inode = new_inode(sb);
21248 + inode->i_mode = p->mode;
21250 + inode->i_op = p->iop;
21252 + inode->i_fop = p->fop;
21254 + set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21255 + inode->i_flags |= S_IMMUTABLE;
21257 + inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21259 + inode->i_uid = 0;
21260 + inode->i_gid = 0;
21261 + inode->i_tag = 0;
21266 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21267 + struct dentry *dentry, int id, void *ptr)
21269 + struct vs_entry *p = ptr;
21270 + struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21271 + struct dentry *error = ERR_PTR(-EINVAL);
21276 + PROC_I(inode)->op = p->op;
21277 + PROC_I(inode)->fd = id;
21278 + d_add(dentry, inode);
21286 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21289 + * Fill a directory entry.
21291 + * If possible create the dcache entry and derive our inode number and
21292 + * file type from dcache entry.
21294 + * Since all of the proc inode numbers are dynamically generated, the inode
21295 + * numbers do not exist until the inode is cache. This means creating the
21296 + * the dcache entry in readdir is necessary to keep the inode numbers
21297 + * reported by readdir in sync with the inode numbers reported
21300 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21301 + char *name, int len, instantiate_t instantiate, int id, void *ptr)
21303 + struct dentry *child, *dir = filp->f_dentry;
21304 + struct inode *inode;
21305 + struct qstr qname;
21307 + unsigned type = DT_UNKNOWN;
21309 + qname.name = name;
21311 + qname.hash = full_name_hash(name, len);
21313 + child = d_lookup(dir, &qname);
21315 + struct dentry *new;
21316 + new = d_alloc(dir, &qname);
21318 + child = instantiate(dir->d_inode, new, id, ptr);
21325 + if (!child || IS_ERR(child) || !child->d_inode)
21326 + goto end_instantiate;
21327 + inode = child->d_inode;
21329 + ino = inode->i_ino;
21330 + type = inode->i_mode >> 12;
21335 + ino = find_inode_number(dir, &qname);
21338 + return filldir(dirent, name, len, filp->f_pos, ino, type);
21343 +/* get and revalidate vx_info/xid */
21346 +struct vx_info *get_proc_vx_info(struct inode *inode)
21348 + return lookup_vx_info(PROC_I(inode)->fd);
21351 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21353 + struct inode *inode = dentry->d_inode;
21354 + xid_t xid = PROC_I(inode)->fd;
21356 + if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21359 + if (!xid || xid_is_hashed(xid))
21366 +/* get and revalidate nx_info/nid */
21368 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21370 + struct inode *inode = dentry->d_inode;
21371 + nid_t nid = PROC_I(inode)->fd;
21373 + if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21376 + if (!nid || nid_is_hashed(nid))
21384 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21386 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21387 + size_t count, loff_t *ppos)
21389 + struct inode *inode = file->f_dentry->d_inode;
21390 + unsigned long page;
21391 + ssize_t length = 0;
21393 + if (count > PROC_BLOCK_SIZE)
21394 + count = PROC_BLOCK_SIZE;
21396 + /* fade that out as soon as stable */
21397 + WARN_ON(PROC_I(inode)->fd);
21399 + if (!(page = __get_free_page(GFP_KERNEL)))
21402 + BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21403 + length = PROC_I(inode)->op.proc_vs_read((char *)page);
21406 + length = simple_read_from_buffer(buf, count, ppos,
21407 + (char *)page, length);
21413 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21414 + size_t count, loff_t *ppos)
21416 + struct inode *inode = file->f_dentry->d_inode;
21417 + struct vx_info *vxi = NULL;
21418 + xid_t xid = PROC_I(inode)->fd;
21419 + unsigned long page;
21420 + ssize_t length = 0;
21422 + if (count > PROC_BLOCK_SIZE)
21423 + count = PROC_BLOCK_SIZE;
21425 + /* fade that out as soon as stable */
21427 + vxi = lookup_vx_info(xid);
21431 + length = -ENOMEM;
21432 + if (!(page = __get_free_page(GFP_KERNEL)))
21435 + BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21436 + length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21439 + length = simple_read_from_buffer(buf, count, ppos,
21440 + (char *)page, length);
21444 + put_vx_info(vxi);
21449 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21450 + size_t count, loff_t *ppos)
21452 + struct inode *inode = file->f_dentry->d_inode;
21453 + struct nx_info *nxi = NULL;
21454 + nid_t nid = PROC_I(inode)->fd;
21455 + unsigned long page;
21456 + ssize_t length = 0;
21458 + if (count > PROC_BLOCK_SIZE)
21459 + count = PROC_BLOCK_SIZE;
21461 + /* fade that out as soon as stable */
21463 + nxi = lookup_nx_info(nid);
21467 + length = -ENOMEM;
21468 + if (!(page = __get_free_page(GFP_KERNEL)))
21471 + BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21472 + length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21475 + length = simple_read_from_buffer(buf, count, ppos,
21476 + (char *)page, length);
21480 + put_nx_info(nxi);
21487 +/* here comes the lower level */
21490 +#define NOD(NAME, MODE, IOP, FOP, OP) { \
21491 + .len = sizeof(NAME) - 1, \
21492 + .name = (NAME), \
21500 +#define DIR(NAME, MODE, OTYPE) \
21501 + NOD(NAME, (S_IFDIR | (MODE)), \
21502 + &proc_ ## OTYPE ## _inode_operations, \
21503 + &proc_ ## OTYPE ## _file_operations, { } )
21505 +#define INF(NAME, MODE, OTYPE) \
21506 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
21507 + &proc_vs_info_file_operations, \
21508 + { .proc_vs_read = &proc_##OTYPE } )
21510 +#define VINF(NAME, MODE, OTYPE) \
21511 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
21512 + &proc_vx_info_file_operations, \
21513 + { .proc_vxi_read = &proc_##OTYPE } )
21515 +#define NINF(NAME, MODE, OTYPE) \
21516 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
21517 + &proc_nx_info_file_operations, \
21518 + { .proc_nxi_read = &proc_##OTYPE } )
21521 +static struct file_operations proc_vs_info_file_operations = {
21522 + .read = proc_vs_info_read,
21525 +static struct file_operations proc_vx_info_file_operations = {
21526 + .read = proc_vx_info_read,
21529 +static struct dentry_operations proc_xid_dentry_operations = {
21530 + .d_revalidate = proc_xid_revalidate,
21533 +static struct vs_entry vx_base_stuff[] = {
21534 + VINF("info", S_IRUGO, vxi_info),
21535 + VINF("status", S_IRUGO, vxi_status),
21536 + VINF("limit", S_IRUGO, vxi_limit),
21537 + VINF("sched", S_IRUGO, vxi_sched),
21538 + VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21539 + VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21540 + VINF("cvirt", S_IRUGO, vxi_cvirt),
21541 + VINF("cacct", S_IRUGO, vxi_cacct),
21548 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21549 + struct dentry *dentry, int id, void *ptr)
21551 + dentry->d_op = &proc_xid_dentry_operations;
21552 + return vs_proc_instantiate(dir, dentry, id, ptr);
21555 +static struct dentry *proc_xid_lookup(struct inode *dir,
21556 + struct dentry *dentry, unsigned int flags)
21558 + struct vs_entry *p = vx_base_stuff;
21559 + struct dentry *error = ERR_PTR(-ENOENT);
21561 + for (; p->name; p++) {
21562 + if (p->len != dentry->d_name.len)
21564 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21570 + error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21575 +static int proc_xid_readdir(struct file *filp,
21576 + void *dirent, filldir_t filldir)
21578 + struct dentry *dentry = filp->f_dentry;
21579 + struct inode *inode = dentry->d_inode;
21580 + struct vs_entry *p = vx_base_stuff;
21581 + int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21585 + pos = filp->f_pos;
21588 + ino = inode->i_ino;
21589 + if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21592 + /* fall through */
21594 + ino = parent_ino(dentry);
21595 + if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21598 + /* fall through */
21601 + if (index >= size)
21603 + for (p += index; p->name; p++) {
21604 + if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21605 + vs_proc_instantiate, PROC_I(inode)->fd, p))
21611 + filp->f_pos = pos;
21617 +static struct file_operations proc_nx_info_file_operations = {
21618 + .read = proc_nx_info_read,
21621 +static struct dentry_operations proc_nid_dentry_operations = {
21622 + .d_revalidate = proc_nid_revalidate,
21625 +static struct vs_entry nx_base_stuff[] = {
21626 + NINF("info", S_IRUGO, nxi_info),
21627 + NINF("status", S_IRUGO, nxi_status),
21632 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21633 + struct dentry *dentry, int id, void *ptr)
21635 + dentry->d_op = &proc_nid_dentry_operations;
21636 + return vs_proc_instantiate(dir, dentry, id, ptr);
21639 +static struct dentry *proc_nid_lookup(struct inode *dir,
21640 + struct dentry *dentry, unsigned int flags)
21642 + struct vs_entry *p = nx_base_stuff;
21643 + struct dentry *error = ERR_PTR(-ENOENT);
21645 + for (; p->name; p++) {
21646 + if (p->len != dentry->d_name.len)
21648 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21654 + error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21659 +static int proc_nid_readdir(struct file *filp,
21660 + void *dirent, filldir_t filldir)
21662 + struct dentry *dentry = filp->f_dentry;
21663 + struct inode *inode = dentry->d_inode;
21664 + struct vs_entry *p = nx_base_stuff;
21665 + int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21669 + pos = filp->f_pos;
21672 + ino = inode->i_ino;
21673 + if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21676 + /* fall through */
21678 + ino = parent_ino(dentry);
21679 + if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21682 + /* fall through */
21685 + if (index >= size)
21687 + for (p += index; p->name; p++) {
21688 + if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21689 + vs_proc_instantiate, PROC_I(inode)->fd, p))
21695 + filp->f_pos = pos;
21700 +#define MAX_MULBY10 ((~0U - 9) / 10)
21702 +static inline int atovid(const char *str, int len)
21707 + while (len-- > 0) {
21712 + if (vid >= MAX_MULBY10)
21722 +/* now the upper level (virtual) */
21725 +static struct file_operations proc_xid_file_operations = {
21726 + .read = generic_read_dir,
21727 + .readdir = proc_xid_readdir,
21730 +static struct inode_operations proc_xid_inode_operations = {
21731 + .lookup = proc_xid_lookup,
21734 +static struct vs_entry vx_virtual_stuff[] = {
21735 + INF("info", S_IRUGO, virtual_info),
21736 + INF("status", S_IRUGO, virtual_status),
21737 + DIR(NULL, S_IRUGO | S_IXUGO, xid),
21741 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21742 + struct dentry *dentry, unsigned int flags)
21744 + struct vs_entry *p = vx_virtual_stuff;
21745 + struct dentry *error = ERR_PTR(-ENOENT);
21748 + for (; p->name; p++) {
21749 + if (p->len != dentry->d_name.len)
21751 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21755 + goto instantiate;
21757 + id = atovid(dentry->d_name.name, dentry->d_name.len);
21758 + if ((id < 0) || !xid_is_hashed(id))
21762 + error = proc_xid_instantiate(dir, dentry, id, p);
21767 +static struct file_operations proc_nid_file_operations = {
21768 + .read = generic_read_dir,
21769 + .readdir = proc_nid_readdir,
21772 +static struct inode_operations proc_nid_inode_operations = {
21773 + .lookup = proc_nid_lookup,
21776 +static struct vs_entry nx_virtnet_stuff[] = {
21777 + INF("info", S_IRUGO, virtnet_info),
21778 + INF("status", S_IRUGO, virtnet_status),
21779 + DIR(NULL, S_IRUGO | S_IXUGO, nid),
21783 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21784 + struct dentry *dentry, unsigned int flags)
21786 + struct vs_entry *p = nx_virtnet_stuff;
21787 + struct dentry *error = ERR_PTR(-ENOENT);
21790 + for (; p->name; p++) {
21791 + if (p->len != dentry->d_name.len)
21793 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21797 + goto instantiate;
21799 + id = atovid(dentry->d_name.name, dentry->d_name.len);
21800 + if ((id < 0) || !nid_is_hashed(id))
21804 + error = proc_nid_instantiate(dir, dentry, id, p);
21810 +#define PROC_MAXVIDS 32
21812 +int proc_virtual_readdir(struct file *filp,
21813 + void *dirent, filldir_t filldir)
21815 + struct dentry *dentry = filp->f_dentry;
21816 + struct inode *inode = dentry->d_inode;
21817 + struct vs_entry *p = vx_virtual_stuff;
21818 + int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21820 + unsigned int xid_array[PROC_MAXVIDS];
21821 + char buf[PROC_NUMBUF];
21822 + unsigned int nr_xids, i;
21825 + pos = filp->f_pos;
21828 + ino = inode->i_ino;
21829 + if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21832 + /* fall through */
21834 + ino = parent_ino(dentry);
21835 + if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21838 + /* fall through */
21841 + if (index >= size)
21843 + for (p += index; p->name; p++) {
21844 + if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21845 + vs_proc_instantiate, 0, p))
21850 + index = pos - size;
21851 + p = &vx_virtual_stuff[size - 1];
21852 + nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21853 + for (i = 0; i < nr_xids; i++) {
21854 + int n, xid = xid_array[i];
21855 + unsigned int j = PROC_NUMBUF;
21859 + buf[--j] = '0' + (n % 10);
21862 + if (proc_fill_cache(filp, dirent, filldir,
21863 + buf + j, PROC_NUMBUF - j,
21864 + vs_proc_instantiate, xid, p))
21870 + filp->f_pos = pos;
21874 +static int proc_virtual_getattr(struct vfsmount *mnt,
21875 + struct dentry *dentry, struct kstat *stat)
21877 + struct inode *inode = dentry->d_inode;
21879 + generic_fillattr(inode, stat);
21880 + stat->nlink = 2 + atomic_read(&vx_global_cactive);
21884 +static struct file_operations proc_virtual_dir_operations = {
21885 + .read = generic_read_dir,
21886 + .readdir = proc_virtual_readdir,
21889 +static struct inode_operations proc_virtual_dir_inode_operations = {
21890 + .getattr = proc_virtual_getattr,
21891 + .lookup = proc_virtual_lookup,
21898 +int proc_virtnet_readdir(struct file *filp,
21899 + void *dirent, filldir_t filldir)
21901 + struct dentry *dentry = filp->f_dentry;
21902 + struct inode *inode = dentry->d_inode;
21903 + struct vs_entry *p = nx_virtnet_stuff;
21904 + int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21906 + unsigned int nid_array[PROC_MAXVIDS];
21907 + char buf[PROC_NUMBUF];
21908 + unsigned int nr_nids, i;
21911 + pos = filp->f_pos;
21914 + ino = inode->i_ino;
21915 + if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21918 + /* fall through */
21920 + ino = parent_ino(dentry);
21921 + if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21924 + /* fall through */
21927 + if (index >= size)
21929 + for (p += index; p->name; p++) {
21930 + if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21931 + vs_proc_instantiate, 0, p))
21936 + index = pos - size;
21937 + p = &nx_virtnet_stuff[size - 1];
21938 + nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21939 + for (i = 0; i < nr_nids; i++) {
21940 + int n, nid = nid_array[i];
21941 + unsigned int j = PROC_NUMBUF;
21945 + buf[--j] = '0' + (n % 10);
21948 + if (proc_fill_cache(filp, dirent, filldir,
21949 + buf + j, PROC_NUMBUF - j,
21950 + vs_proc_instantiate, nid, p))
21956 + filp->f_pos = pos;
21960 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21961 + struct dentry *dentry, struct kstat *stat)
21963 + struct inode *inode = dentry->d_inode;
21965 + generic_fillattr(inode, stat);
21966 + stat->nlink = 2 + atomic_read(&nx_global_cactive);
21970 +static struct file_operations proc_virtnet_dir_operations = {
21971 + .read = generic_read_dir,
21972 + .readdir = proc_virtnet_readdir,
21975 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21976 + .getattr = proc_virtnet_getattr,
21977 + .lookup = proc_virtnet_lookup,
21982 +void proc_vx_init(void)
21984 + struct proc_dir_entry *ent;
21986 + ent = proc_mkdir("virtual", 0);
21988 + ent->proc_fops = &proc_virtual_dir_operations;
21989 + ent->proc_iops = &proc_virtual_dir_inode_operations;
21991 + proc_virtual = ent;
21993 + ent = proc_mkdir("virtnet", 0);
21995 + ent->proc_fops = &proc_virtnet_dir_operations;
21996 + ent->proc_iops = &proc_virtnet_dir_inode_operations;
21998 + proc_virtnet = ent;
22004 +/* per pid info */
22007 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22009 + struct vx_info *vxi;
22010 + char *orig = buffer;
22012 + buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22014 + vxi = task_get_vx_info(p);
22018 + buffer += sprintf(buffer, "BCaps:\t");
22019 + buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22020 + buffer += sprintf(buffer, "\n");
22021 + buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22022 + (unsigned long long)vxi->vx_ccaps);
22023 + buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22024 + (unsigned long long)vxi->vx_flags);
22025 + buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22027 + put_vx_info(vxi);
22029 + return buffer - orig;
22033 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22035 + struct nx_info *nxi;
22036 + struct nx_addr_v4 *v4a;
22037 +#ifdef CONFIG_IPV6
22038 + struct nx_addr_v6 *v6a;
22040 + char *orig = buffer;
22043 + buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22045 + nxi = task_get_nx_info(p);
22049 + buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22050 + (unsigned long long)nxi->nx_ncaps);
22051 + buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22052 + (unsigned long long)nxi->nx_flags);
22054 + buffer += sprintf(buffer,
22055 + "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22056 + NIPQUAD(nxi->v4_bcast.s_addr));
22057 + buffer += sprintf (buffer,
22058 + "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22059 + NIPQUAD(nxi->v4_lback.s_addr));
22060 + if (!NX_IPV4(nxi))
22062 + for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22063 + buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22066 +#ifdef CONFIG_IPV6
22067 + if (!NX_IPV6(nxi))
22069 + for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22070 + buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22074 + put_nx_info(nxi);
22076 + return buffer - orig;
22079 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched.c linux-3.9.4-vs2.3.6.1/kernel/vserver/sched.c
22080 --- linux-3.9.4/kernel/vserver/sched.c 1970-01-01 00:00:00.000000000 +0000
22081 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/sched.c 2013-05-31 14:47:11.000000000 +0000
22084 + * linux/kernel/vserver/sched.c
22086 + * Virtual Server: Scheduler Support
22088 + * Copyright (C) 2004-2010 Herbert Pötzl
22090 + * V0.01 adapted Sam Vilains version to 2.6.3
22091 + * V0.02 removed legacy interface
22092 + * V0.03 changed vcmds to vxi arg
22093 + * V0.04 removed older and legacy interfaces
22094 + * V0.05 removed scheduler code/commands
22098 +#include <linux/vs_context.h>
22099 +#include <linux/vs_sched.h>
22100 +#include <linux/cpumask.h>
22101 +#include <linux/vserver/sched_cmd.h>
22103 +#include <asm/uaccess.h>
22106 +void vx_update_sched_param(struct _vx_sched *sched,
22107 + struct _vx_sched_pc *sched_pc)
22109 + sched_pc->prio_bias = sched->prio_bias;
22112 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22116 + if (data->prio_bias > MAX_PRIO_BIAS)
22117 + data->prio_bias = MAX_PRIO_BIAS;
22118 + if (data->prio_bias < MIN_PRIO_BIAS)
22119 + data->prio_bias = MIN_PRIO_BIAS;
22121 + if (data->cpu_id != ~0) {
22122 + vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22123 + cpumask_and(&vxi->sched.update, &vxi->sched.update,
22124 + cpu_online_mask);
22126 + cpumask_copy(&vxi->sched.update, cpu_online_mask);
22128 + for_each_cpu_mask(cpu, vxi->sched.update)
22129 + vx_update_sched_param(&vxi->sched,
22130 + &vx_per_cpu(vxi, sched_pc, cpu));
22134 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22136 + struct vcmd_prio_bias vc_data;
22138 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22141 + return do_set_prio_bias(vxi, &vc_data);
22144 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22146 + struct vcmd_prio_bias vc_data;
22147 + struct _vx_sched_pc *pcd;
22150 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22153 + cpu = vc_data.cpu_id;
22155 + if (!cpu_possible(cpu))
22158 + pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22159 + vc_data.prio_bias = pcd->prio_bias;
22161 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22166 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched_init.h linux-3.9.4-vs2.3.6.1/kernel/vserver/sched_init.h
22167 --- linux-3.9.4/kernel/vserver/sched_init.h 1970-01-01 00:00:00.000000000 +0000
22168 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/sched_init.h 2013-05-31 14:47:11.000000000 +0000
22171 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22173 + /* scheduling; hard code starting values as constants */
22174 + sched->prio_bias = 0;
22178 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22180 + sched_pc->prio_bias = 0;
22182 + sched_pc->user_ticks = 0;
22183 + sched_pc->sys_ticks = 0;
22184 + sched_pc->hold_ticks = 0;
22187 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22193 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22197 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched_proc.h linux-3.9.4-vs2.3.6.1/kernel/vserver/sched_proc.h
22198 --- linux-3.9.4/kernel/vserver/sched_proc.h 1970-01-01 00:00:00.000000000 +0000
22199 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/sched_proc.h 2013-05-31 14:47:11.000000000 +0000
22201 +#ifndef _VX_SCHED_PROC_H
22202 +#define _VX_SCHED_PROC_H
22206 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22210 + length += sprintf(buffer,
22211 + "PrioBias:\t%8d\n",
22212 + sched->prio_bias);
22217 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22218 + char *buffer, int cpu)
22222 + length += sprintf(buffer + length,
22223 + "cpu %d: %lld %lld %lld", cpu,
22224 + (unsigned long long)sched_pc->user_ticks,
22225 + (unsigned long long)sched_pc->sys_ticks,
22226 + (unsigned long long)sched_pc->hold_ticks);
22227 + length += sprintf(buffer + length,
22228 + " %d\n", sched_pc->prio_bias);
22232 +#endif /* _VX_SCHED_PROC_H */
22233 diff -NurpP --minimal linux-3.9.4/kernel/vserver/signal.c linux-3.9.4-vs2.3.6.1/kernel/vserver/signal.c
22234 --- linux-3.9.4/kernel/vserver/signal.c 1970-01-01 00:00:00.000000000 +0000
22235 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/signal.c 2013-05-31 14:47:11.000000000 +0000
22238 + * linux/kernel/vserver/signal.c
22240 + * Virtual Server: Signal Support
22242 + * Copyright (C) 2003-2007 Herbert Pötzl
22244 + * V0.01 broken out from vcontext V0.05
22245 + * V0.02 changed vcmds to vxi arg
22246 + * V0.03 adjusted siginfo for kill
22250 +#include <asm/uaccess.h>
22252 +#include <linux/vs_context.h>
22253 +#include <linux/vs_pid.h>
22254 +#include <linux/vserver/signal_cmd.h>
22257 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22259 + int retval, count = 0;
22260 + struct task_struct *p;
22261 + struct siginfo *sip = SEND_SIG_PRIV;
22264 + vxdprintk(VXD_CBIT(misc, 4),
22265 + "vx_info_kill(%p[#%d],%d,%d)*",
22266 + vxi, vxi->vx_id, pid, sig);
22267 + read_lock(&tasklist_lock);
22271 + for_each_process(p) {
22274 + if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22275 + (pid && vxi->vx_initpid == p->pid))
22278 + err = group_send_sig_info(sig, sip, p);
22280 + if (err != -EPERM)
22286 + if (vxi->vx_initpid) {
22287 + pid = vxi->vx_initpid;
22288 + /* for now, only SIGINT to private init ... */
22289 + if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22290 + /* ... as long as there are tasks left */
22291 + (atomic_read(&vxi->vx_tasks) > 1))
22294 + /* fallthrough */
22297 + p = find_task_by_real_pid(pid);
22298 + rcu_read_unlock();
22300 + if (vx_task_xid(p) == vxi->vx_id)
22301 + retval = group_send_sig_info(sig, sip, p);
22305 + read_unlock(&tasklist_lock);
22306 + vxdprintk(VXD_CBIT(misc, 4),
22307 + "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22308 + vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22312 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22314 + struct vcmd_ctx_kill_v0 vc_data;
22316 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22319 + /* special check to allow guest shutdown */
22320 + if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22321 + /* forbid killall pid=0 when init is present */
22322 + (((vc_data.pid < 1) && vxi->vx_initpid) ||
22323 + (vc_data.pid > 1)))
22326 + return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22330 +static int __wait_exit(struct vx_info *vxi)
22332 + DECLARE_WAITQUEUE(wait, current);
22335 + add_wait_queue(&vxi->vx_wait, &wait);
22336 + set_current_state(TASK_INTERRUPTIBLE);
22339 + if (vx_info_state(vxi,
22340 + VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22342 + if (signal_pending(current)) {
22343 + ret = -ERESTARTSYS;
22350 + set_current_state(TASK_RUNNING);
22351 + remove_wait_queue(&vxi->vx_wait, &wait);
22357 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22359 + struct vcmd_wait_exit_v0 vc_data;
22362 + ret = __wait_exit(vxi);
22363 + vc_data.reboot_cmd = vxi->reboot_cmd;
22364 + vc_data.exit_code = vxi->exit_code;
22366 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22371 diff -NurpP --minimal linux-3.9.4/kernel/vserver/space.c linux-3.9.4-vs2.3.6.1/kernel/vserver/space.c
22372 --- linux-3.9.4/kernel/vserver/space.c 1970-01-01 00:00:00.000000000 +0000
22373 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/space.c 2013-05-31 14:47:11.000000000 +0000
22376 + * linux/kernel/vserver/space.c
22378 + * Virtual Server: Context Space Support
22380 + * Copyright (C) 2003-2010 Herbert Pötzl
22382 + * V0.01 broken out from context.c 0.07
22383 + * V0.02 added task locking for namespace
22384 + * V0.03 broken out vx_enter_namespace
22385 + * V0.04 added *space support and commands
22386 + * V0.05 added credential support
22390 +#include <linux/utsname.h>
22391 +#include <linux/nsproxy.h>
22392 +#include <linux/err.h>
22393 +#include <linux/fs_struct.h>
22394 +#include <linux/cred.h>
22395 +#include <asm/uaccess.h>
22397 +#include <linux/vs_context.h>
22398 +#include <linux/vserver/space.h>
22399 +#include <linux/vserver/space_cmd.h>
22401 +atomic_t vs_global_nsproxy = ATOMIC_INIT(0);
22402 +atomic_t vs_global_fs = ATOMIC_INIT(0);
22403 +atomic_t vs_global_mnt_ns = ATOMIC_INIT(0);
22404 +atomic_t vs_global_uts_ns = ATOMIC_INIT(0);
22405 +atomic_t vs_global_user_ns = ATOMIC_INIT(0);
22406 +atomic_t vs_global_pid_ns = ATOMIC_INIT(0);
22409 +/* namespace functions */
22411 +#include <linux/mnt_namespace.h>
22412 +#include <linux/user_namespace.h>
22413 +#include <linux/pid_namespace.h>
22414 +#include <linux/ipc_namespace.h>
22415 +#include <net/net_namespace.h>
22416 +#include "../fs/mount.h"
22419 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22420 + .mask = CLONE_FS |
22422 +#ifdef CONFIG_UTS_NS
22425 +#ifdef CONFIG_IPC_NS
22428 +#ifdef CONFIG_USER_NS
22434 +static const struct vcmd_space_mask_v1 space_mask = {
22435 + .mask = CLONE_FS |
22437 +#ifdef CONFIG_UTS_NS
22440 +#ifdef CONFIG_IPC_NS
22443 +#ifdef CONFIG_USER_NS
22446 +#ifdef CONFIG_PID_NS
22449 +#ifdef CONFIG_NET_NS
22455 +static const struct vcmd_space_mask_v1 default_space_mask = {
22456 + .mask = CLONE_FS |
22458 +#ifdef CONFIG_UTS_NS
22461 +#ifdef CONFIG_IPC_NS
22464 +#ifdef CONFIG_USER_NS
22467 +#ifdef CONFIG_PID_NS
22474 + * build a new nsproxy mix
22475 + * assumes that both proxies are 'const'
22476 + * does not touch nsproxy refcounts
22477 + * will hold a reference on the result.
22480 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22481 + struct nsproxy *new_nsproxy, unsigned long mask)
22483 + struct mnt_namespace *old_ns;
22484 + struct uts_namespace *old_uts;
22485 + struct ipc_namespace *old_ipc;
22486 +#ifdef CONFIG_PID_NS
22487 + struct pid_namespace *old_pid;
22489 +#ifdef CONFIG_NET_NS
22490 + struct net *old_net;
22492 + struct nsproxy *nsproxy;
22494 + nsproxy = copy_nsproxy(old_nsproxy);
22498 + if (mask & CLONE_NEWNS) {
22499 + old_ns = nsproxy->mnt_ns;
22500 + nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22501 + if (nsproxy->mnt_ns)
22502 + get_mnt_ns(nsproxy->mnt_ns);
22506 + if (mask & CLONE_NEWUTS) {
22507 + old_uts = nsproxy->uts_ns;
22508 + nsproxy->uts_ns = new_nsproxy->uts_ns;
22509 + if (nsproxy->uts_ns)
22510 + get_uts_ns(nsproxy->uts_ns);
22514 + if (mask & CLONE_NEWIPC) {
22515 + old_ipc = nsproxy->ipc_ns;
22516 + nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22517 + if (nsproxy->ipc_ns)
22518 + get_ipc_ns(nsproxy->ipc_ns);
22522 +#ifdef CONFIG_PID_NS
22523 + if (mask & CLONE_NEWPID) {
22524 + old_pid = nsproxy->pid_ns;
22525 + nsproxy->pid_ns = new_nsproxy->pid_ns;
22526 + if (nsproxy->pid_ns)
22527 + get_pid_ns(nsproxy->pid_ns);
22531 +#ifdef CONFIG_NET_NS
22532 + if (mask & CLONE_NEWNET) {
22533 + old_net = nsproxy->net_ns;
22534 + nsproxy->net_ns = new_nsproxy->net_ns;
22535 + if (nsproxy->net_ns)
22536 + get_net(nsproxy->net_ns);
22541 + put_mnt_ns(old_ns);
22543 + put_uts_ns(old_uts);
22545 + put_ipc_ns(old_ipc);
22546 +#ifdef CONFIG_PID_NS
22548 + put_pid_ns(old_pid);
22550 +#ifdef CONFIG_NET_NS
22552 + put_net(old_net);
22560 + * merge two nsproxy structs into a new one.
22561 + * will hold a reference on the result.
22565 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22566 + struct nsproxy *proxy, unsigned long mask)
22568 + struct nsproxy null_proxy = { .mnt_ns = NULL };
22574 + /* vs_mix_nsproxy returns with reference */
22575 + return vs_mix_nsproxy(old ? old : &null_proxy,
22578 + get_nsproxy(proxy);
22583 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22585 + struct nsproxy *proxy, *proxy_cur, *proxy_new;
22586 + struct fs_struct *fs_cur, *fs = NULL;
22587 + struct _vx_space *space;
22588 + int ret, kill = 0;
22590 + vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22591 + vxi, vxi->vx_id, mask, index);
22593 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22596 + if (index >= VX_SPACES)
22599 + space = &vxi->space[index];
22602 + mask = space->vx_nsmask;
22604 + if ((mask & space->vx_nsmask) != mask)
22607 + if (mask & CLONE_FS) {
22608 + fs = copy_fs_struct(space->vx_fs);
22612 + proxy = space->vx_nsproxy;
22614 + vxdprintk(VXD_CBIT(space, 9),
22615 + "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22616 + vxi, vxi->vx_id, mask, index, proxy, fs);
22618 + task_lock(current);
22619 + fs_cur = current->fs;
22621 + if (mask & CLONE_FS) {
22622 + spin_lock(&fs_cur->lock);
22623 + current->fs = fs;
22624 + kill = !--fs_cur->users;
22625 + spin_unlock(&fs_cur->lock);
22628 + proxy_cur = current->nsproxy;
22629 + get_nsproxy(proxy_cur);
22630 + task_unlock(current);
22633 + free_fs_struct(fs_cur);
22635 + proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22636 + if (IS_ERR(proxy_new)) {
22637 + ret = PTR_ERR(proxy_new);
22641 + proxy_new = xchg(¤t->nsproxy, proxy_new);
22643 + if (mask & CLONE_NEWUSER) {
22644 + struct cred *cred;
22646 + vxdprintk(VXD_CBIT(space, 10),
22647 + "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22648 + vxi, vxi->vx_id, space->vx_cred,
22649 + current->real_cred, current->cred);
22651 + if (space->vx_cred) {
22652 + cred = __prepare_creds(space->vx_cred);
22654 + commit_creds(cred);
22661 + put_nsproxy(proxy_new);
22664 + put_nsproxy(proxy_cur);
22669 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22671 + struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22672 + struct fs_struct *fs_vxi, *fs = NULL;
22673 + struct _vx_space *space;
22674 + int ret, kill = 0;
22676 + vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22677 + vxi, vxi->vx_id, mask, index);
22679 + if ((mask & space_mask.mask) != mask)
22682 + if (index >= VX_SPACES)
22685 + space = &vxi->space[index];
22687 + proxy_vxi = space->vx_nsproxy;
22688 + fs_vxi = space->vx_fs;
22690 + if (mask & CLONE_FS) {
22691 + fs = copy_fs_struct(current->fs);
22696 + task_lock(current);
22698 + if (mask & CLONE_FS) {
22699 + spin_lock(&fs_vxi->lock);
22700 + space->vx_fs = fs;
22701 + kill = !--fs_vxi->users;
22702 + spin_unlock(&fs_vxi->lock);
22705 + proxy_cur = current->nsproxy;
22706 + get_nsproxy(proxy_cur);
22707 + task_unlock(current);
22710 + free_fs_struct(fs_vxi);
22712 + proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22713 + if (IS_ERR(proxy_new)) {
22714 + ret = PTR_ERR(proxy_new);
22718 + proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22719 + space->vx_nsmask |= mask;
22721 + if (mask & CLONE_NEWUSER) {
22722 + struct cred *cred;
22724 + vxdprintk(VXD_CBIT(space, 10),
22725 + "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22726 + vxi, vxi->vx_id, space->vx_cred,
22727 + current->real_cred, current->cred);
22729 + cred = prepare_creds();
22730 + cred = (struct cred *)xchg(&space->vx_cred, cred);
22732 + abort_creds(cred);
22738 + put_nsproxy(proxy_new);
22741 + put_nsproxy(proxy_cur);
22746 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22748 + struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22750 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22753 + return vx_enter_space(vxi, vc_data.mask, 0);
22756 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22758 + struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22760 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22763 + if (vc_data.index >= VX_SPACES)
22766 + return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22769 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22771 + struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22773 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22776 + return vx_set_space(vxi, vc_data.mask, 0);
22779 +int vc_set_space(struct vx_info *vxi, void __user *data)
22781 + struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22783 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22786 + if (vc_data.index >= VX_SPACES)
22789 + return vx_set_space(vxi, vc_data.mask, vc_data.index);
22792 +int vc_get_space_mask(void __user *data, int type)
22794 + const struct vcmd_space_mask_v1 *mask;
22797 + mask = &space_mask_v0;
22798 + else if (type == 1)
22799 + mask = &space_mask;
22801 + mask = &default_space_mask;
22803 + vxdprintk(VXD_CBIT(space, 10),
22804 + "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22806 + if (copy_to_user(data, mask, sizeof(*mask)))
22811 diff -NurpP --minimal linux-3.9.4/kernel/vserver/switch.c linux-3.9.4-vs2.3.6.1/kernel/vserver/switch.c
22812 --- linux-3.9.4/kernel/vserver/switch.c 1970-01-01 00:00:00.000000000 +0000
22813 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/switch.c 2013-05-31 14:47:11.000000000 +0000
22816 + * linux/kernel/vserver/switch.c
22818 + * Virtual Server: Syscall Switch
22820 + * Copyright (C) 2003-2011 Herbert Pötzl
22822 + * V0.01 syscall switch
22823 + * V0.02 added signal to context
22824 + * V0.03 added rlimit functions
22825 + * V0.04 added iattr, task/xid functions
22826 + * V0.05 added debug/history stuff
22827 + * V0.06 added compat32 layer
22828 + * V0.07 vcmd args and perms
22829 + * V0.08 added status commands
22830 + * V0.09 added tag commands
22831 + * V0.10 added oom bias
22832 + * V0.11 added device commands
22833 + * V0.12 added warn mask
22837 +#include <linux/vs_context.h>
22838 +#include <linux/vs_network.h>
22839 +#include <linux/vserver/switch.h>
22841 +#include "vci_config.h"
22845 +int vc_get_version(uint32_t id)
22847 + return VCI_VERSION;
22851 +int vc_get_vci(uint32_t id)
22853 + return vci_kernel_config();
22856 +#include <linux/vserver/context_cmd.h>
22857 +#include <linux/vserver/cvirt_cmd.h>
22858 +#include <linux/vserver/cacct_cmd.h>
22859 +#include <linux/vserver/limit_cmd.h>
22860 +#include <linux/vserver/network_cmd.h>
22861 +#include <linux/vserver/sched_cmd.h>
22862 +#include <linux/vserver/debug_cmd.h>
22863 +#include <linux/vserver/inode_cmd.h>
22864 +#include <linux/vserver/dlimit_cmd.h>
22865 +#include <linux/vserver/signal_cmd.h>
22866 +#include <linux/vserver/space_cmd.h>
22867 +#include <linux/vserver/tag_cmd.h>
22868 +#include <linux/vserver/device_cmd.h>
22870 +#include <linux/vserver/inode.h>
22871 +#include <linux/vserver/dlimit.h>
22874 +#ifdef CONFIG_COMPAT
22875 +#define __COMPAT(name, id, data, compat) \
22876 + (compat) ? name ## _x32(id, data) : name(id, data)
22877 +#define __COMPAT_NO_ID(name, data, compat) \
22878 + (compat) ? name ## _x32(data) : name(data)
22880 +#define __COMPAT(name, id, data, compat) \
22882 +#define __COMPAT_NO_ID(name, data, compat) \
22888 +long do_vcmd(uint32_t cmd, uint32_t id,
22889 + struct vx_info *vxi, struct nx_info *nxi,
22890 + void __user *data, int compat)
22894 + case VCMD_get_version:
22895 + return vc_get_version(id);
22896 + case VCMD_get_vci:
22897 + return vc_get_vci(id);
22899 + case VCMD_task_xid:
22900 + return vc_task_xid(id);
22901 + case VCMD_vx_info:
22902 + return vc_vx_info(vxi, data);
22904 + case VCMD_task_nid:
22905 + return vc_task_nid(id);
22906 + case VCMD_nx_info:
22907 + return vc_nx_info(nxi, data);
22909 + case VCMD_task_tag:
22910 + return vc_task_tag(id);
22912 + case VCMD_set_space_v1:
22913 + return vc_set_space_v1(vxi, data);
22914 + /* this is version 2 */
22915 + case VCMD_set_space:
22916 + return vc_set_space(vxi, data);
22918 + case VCMD_get_space_mask_v0:
22919 + return vc_get_space_mask(data, 0);
22920 + /* this is version 1 */
22921 + case VCMD_get_space_mask:
22922 + return vc_get_space_mask(data, 1);
22924 + case VCMD_get_space_default:
22925 + return vc_get_space_mask(data, -1);
22927 + case VCMD_set_umask:
22928 + return vc_set_umask(vxi, data);
22930 + case VCMD_get_umask:
22931 + return vc_get_umask(vxi, data);
22933 + case VCMD_set_wmask:
22934 + return vc_set_wmask(vxi, data);
22936 + case VCMD_get_wmask:
22937 + return vc_get_wmask(vxi, data);
22938 +#ifdef CONFIG_IA32_EMULATION
22939 + case VCMD_get_rlimit:
22940 + return __COMPAT(vc_get_rlimit, vxi, data, compat);
22941 + case VCMD_set_rlimit:
22942 + return __COMPAT(vc_set_rlimit, vxi, data, compat);
22944 + case VCMD_get_rlimit:
22945 + return vc_get_rlimit(vxi, data);
22946 + case VCMD_set_rlimit:
22947 + return vc_set_rlimit(vxi, data);
22949 + case VCMD_get_rlimit_mask:
22950 + return vc_get_rlimit_mask(id, data);
22951 + case VCMD_reset_hits:
22952 + return vc_reset_hits(vxi, data);
22953 + case VCMD_reset_minmax:
22954 + return vc_reset_minmax(vxi, data);
22956 + case VCMD_get_vhi_name:
22957 + return vc_get_vhi_name(vxi, data);
22958 + case VCMD_set_vhi_name:
22959 + return vc_set_vhi_name(vxi, data);
22961 + case VCMD_ctx_stat:
22962 + return vc_ctx_stat(vxi, data);
22963 + case VCMD_virt_stat:
22964 + return vc_virt_stat(vxi, data);
22965 + case VCMD_sock_stat:
22966 + return vc_sock_stat(vxi, data);
22967 + case VCMD_rlimit_stat:
22968 + return vc_rlimit_stat(vxi, data);
22970 + case VCMD_set_cflags:
22971 + return vc_set_cflags(vxi, data);
22972 + case VCMD_get_cflags:
22973 + return vc_get_cflags(vxi, data);
22975 + /* this is version 1 */
22976 + case VCMD_set_ccaps:
22977 + return vc_set_ccaps(vxi, data);
22978 + /* this is version 1 */
22979 + case VCMD_get_ccaps:
22980 + return vc_get_ccaps(vxi, data);
22981 + case VCMD_set_bcaps:
22982 + return vc_set_bcaps(vxi, data);
22983 + case VCMD_get_bcaps:
22984 + return vc_get_bcaps(vxi, data);
22986 + case VCMD_set_badness:
22987 + return vc_set_badness(vxi, data);
22988 + case VCMD_get_badness:
22989 + return vc_get_badness(vxi, data);
22991 + case VCMD_set_nflags:
22992 + return vc_set_nflags(nxi, data);
22993 + case VCMD_get_nflags:
22994 + return vc_get_nflags(nxi, data);
22996 + case VCMD_set_ncaps:
22997 + return vc_set_ncaps(nxi, data);
22998 + case VCMD_get_ncaps:
22999 + return vc_get_ncaps(nxi, data);
23001 + case VCMD_set_prio_bias:
23002 + return vc_set_prio_bias(vxi, data);
23003 + case VCMD_get_prio_bias:
23004 + return vc_get_prio_bias(vxi, data);
23005 + case VCMD_add_dlimit:
23006 + return __COMPAT(vc_add_dlimit, id, data, compat);
23007 + case VCMD_rem_dlimit:
23008 + return __COMPAT(vc_rem_dlimit, id, data, compat);
23009 + case VCMD_set_dlimit:
23010 + return __COMPAT(vc_set_dlimit, id, data, compat);
23011 + case VCMD_get_dlimit:
23012 + return __COMPAT(vc_get_dlimit, id, data, compat);
23014 + case VCMD_ctx_kill:
23015 + return vc_ctx_kill(vxi, data);
23017 + case VCMD_wait_exit:
23018 + return vc_wait_exit(vxi, data);
23020 + case VCMD_get_iattr:
23021 + return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23022 + case VCMD_set_iattr:
23023 + return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23025 + case VCMD_fget_iattr:
23026 + return vc_fget_iattr(id, data);
23027 + case VCMD_fset_iattr:
23028 + return vc_fset_iattr(id, data);
23030 + case VCMD_enter_space_v0:
23031 + return vc_enter_space_v1(vxi, NULL);
23032 + case VCMD_enter_space_v1:
23033 + return vc_enter_space_v1(vxi, data);
23034 + /* this is version 2 */
23035 + case VCMD_enter_space:
23036 + return vc_enter_space(vxi, data);
23038 + case VCMD_ctx_create_v0:
23039 + return vc_ctx_create(id, NULL);
23040 + case VCMD_ctx_create:
23041 + return vc_ctx_create(id, data);
23042 + case VCMD_ctx_migrate_v0:
23043 + return vc_ctx_migrate(vxi, NULL);
23044 + case VCMD_ctx_migrate:
23045 + return vc_ctx_migrate(vxi, data);
23047 + case VCMD_net_create_v0:
23048 + return vc_net_create(id, NULL);
23049 + case VCMD_net_create:
23050 + return vc_net_create(id, data);
23051 + case VCMD_net_migrate:
23052 + return vc_net_migrate(nxi, data);
23054 + case VCMD_tag_migrate:
23055 + return vc_tag_migrate(id);
23057 + case VCMD_net_add:
23058 + return vc_net_add(nxi, data);
23059 + case VCMD_net_remove:
23060 + return vc_net_remove(nxi, data);
23062 + case VCMD_net_add_ipv4_v1:
23063 + return vc_net_add_ipv4_v1(nxi, data);
23064 + /* this is version 2 */
23065 + case VCMD_net_add_ipv4:
23066 + return vc_net_add_ipv4(nxi, data);
23068 + case VCMD_net_rem_ipv4_v1:
23069 + return vc_net_rem_ipv4_v1(nxi, data);
23070 + /* this is version 2 */
23071 + case VCMD_net_rem_ipv4:
23072 + return vc_net_rem_ipv4(nxi, data);
23073 +#ifdef CONFIG_IPV6
23074 + case VCMD_net_add_ipv6:
23075 + return vc_net_add_ipv6(nxi, data);
23076 + case VCMD_net_remove_ipv6:
23077 + return vc_net_remove_ipv6(nxi, data);
23079 +/* case VCMD_add_match_ipv4:
23080 + return vc_add_match_ipv4(nxi, data);
23081 + case VCMD_get_match_ipv4:
23082 + return vc_get_match_ipv4(nxi, data);
23083 +#ifdef CONFIG_IPV6
23084 + case VCMD_add_match_ipv6:
23085 + return vc_add_match_ipv6(nxi, data);
23086 + case VCMD_get_match_ipv6:
23087 + return vc_get_match_ipv6(nxi, data);
23090 +#ifdef CONFIG_VSERVER_DEVICE
23091 + case VCMD_set_mapping:
23092 + return __COMPAT(vc_set_mapping, vxi, data, compat);
23093 + case VCMD_unset_mapping:
23094 + return __COMPAT(vc_unset_mapping, vxi, data, compat);
23096 +#ifdef CONFIG_VSERVER_HISTORY
23097 + case VCMD_dump_history:
23098 + return vc_dump_history(id);
23099 + case VCMD_read_history:
23100 + return __COMPAT(vc_read_history, id, data, compat);
23103 + vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23104 + VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23110 +#define __VCMD(vcmd, _perm, _args, _flags) \
23111 + case VCMD_ ## vcmd: perm = _perm; \
23112 + args = _args; flags = _flags; break
23115 +#define VCA_NONE 0x00
23116 +#define VCA_VXI 0x01
23117 +#define VCA_NXI 0x02
23119 +#define VCF_NONE 0x00
23120 +#define VCF_INFO 0x01
23121 +#define VCF_ADMIN 0x02
23122 +#define VCF_ARES 0x06 /* includes admin */
23123 +#define VCF_SETUP 0x08
23125 +#define VCF_ZIDOK 0x10 /* zero id okay */
23129 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23132 + int permit = -1, state = 0;
23133 + int perm = -1, args = 0, flags = 0;
23134 + struct vx_info *vxi = NULL;
23135 + struct nx_info *nxi = NULL;
23138 + /* unpriviledged commands */
23139 + __VCMD(get_version, 0, VCA_NONE, 0);
23140 + __VCMD(get_vci, 0, VCA_NONE, 0);
23141 + __VCMD(get_rlimit_mask, 0, VCA_NONE, 0);
23142 + __VCMD(get_space_mask_v0,0, VCA_NONE, 0);
23143 + __VCMD(get_space_mask, 0, VCA_NONE, 0);
23144 + __VCMD(get_space_default,0, VCA_NONE, 0);
23146 + /* info commands */
23147 + __VCMD(task_xid, 2, VCA_NONE, 0);
23148 + __VCMD(reset_hits, 2, VCA_VXI, 0);
23149 + __VCMD(reset_minmax, 2, VCA_VXI, 0);
23150 + __VCMD(vx_info, 3, VCA_VXI, VCF_INFO);
23151 + __VCMD(get_bcaps, 3, VCA_VXI, VCF_INFO);
23152 + __VCMD(get_ccaps, 3, VCA_VXI, VCF_INFO);
23153 + __VCMD(get_cflags, 3, VCA_VXI, VCF_INFO);
23154 + __VCMD(get_umask, 3, VCA_VXI, VCF_INFO);
23155 + __VCMD(get_wmask, 3, VCA_VXI, VCF_INFO);
23156 + __VCMD(get_badness, 3, VCA_VXI, VCF_INFO);
23157 + __VCMD(get_vhi_name, 3, VCA_VXI, VCF_INFO);
23158 + __VCMD(get_rlimit, 3, VCA_VXI, VCF_INFO);
23160 + __VCMD(ctx_stat, 3, VCA_VXI, VCF_INFO);
23161 + __VCMD(virt_stat, 3, VCA_VXI, VCF_INFO);
23162 + __VCMD(sock_stat, 3, VCA_VXI, VCF_INFO);
23163 + __VCMD(rlimit_stat, 3, VCA_VXI, VCF_INFO);
23165 + __VCMD(task_nid, 2, VCA_NONE, 0);
23166 + __VCMD(nx_info, 3, VCA_NXI, VCF_INFO);
23167 + __VCMD(get_ncaps, 3, VCA_NXI, VCF_INFO);
23168 + __VCMD(get_nflags, 3, VCA_NXI, VCF_INFO);
23170 + __VCMD(task_tag, 2, VCA_NONE, 0);
23172 + __VCMD(get_iattr, 2, VCA_NONE, 0);
23173 + __VCMD(fget_iattr, 2, VCA_NONE, 0);
23174 + __VCMD(get_dlimit, 3, VCA_NONE, VCF_INFO);
23175 + __VCMD(get_prio_bias, 3, VCA_VXI, VCF_INFO);
23177 + /* lower admin commands */
23178 + __VCMD(wait_exit, 4, VCA_VXI, VCF_INFO);
23179 + __VCMD(ctx_create_v0, 5, VCA_NONE, 0);
23180 + __VCMD(ctx_create, 5, VCA_NONE, 0);
23181 + __VCMD(ctx_migrate_v0, 5, VCA_VXI, VCF_ADMIN);
23182 + __VCMD(ctx_migrate, 5, VCA_VXI, VCF_ADMIN);
23183 + __VCMD(enter_space_v0, 5, VCA_VXI, VCF_ADMIN);
23184 + __VCMD(enter_space_v1, 5, VCA_VXI, VCF_ADMIN);
23185 + __VCMD(enter_space, 5, VCA_VXI, VCF_ADMIN);
23187 + __VCMD(net_create_v0, 5, VCA_NONE, 0);
23188 + __VCMD(net_create, 5, VCA_NONE, 0);
23189 + __VCMD(net_migrate, 5, VCA_NXI, VCF_ADMIN);
23191 + __VCMD(tag_migrate, 5, VCA_NONE, VCF_ADMIN);
23193 + /* higher admin commands */
23194 + __VCMD(ctx_kill, 6, VCA_VXI, VCF_ARES);
23195 + __VCMD(set_space_v1, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23196 + __VCMD(set_space, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23198 + __VCMD(set_ccaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23199 + __VCMD(set_bcaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23200 + __VCMD(set_cflags, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23201 + __VCMD(set_umask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23202 + __VCMD(set_wmask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23203 + __VCMD(set_badness, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23205 + __VCMD(set_vhi_name, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23206 + __VCMD(set_rlimit, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23207 + __VCMD(set_prio_bias, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23209 + __VCMD(set_ncaps, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
23210 + __VCMD(set_nflags, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
23211 + __VCMD(net_add, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23212 + __VCMD(net_remove, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23213 + __VCMD(net_add_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23214 + __VCMD(net_rem_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23215 + __VCMD(net_add_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23216 + __VCMD(net_rem_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23217 +#ifdef CONFIG_IPV6
23218 + __VCMD(net_add_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23219 + __VCMD(net_remove_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23221 + __VCMD(set_iattr, 7, VCA_NONE, 0);
23222 + __VCMD(fset_iattr, 7, VCA_NONE, 0);
23223 + __VCMD(set_dlimit, 7, VCA_NONE, VCF_ARES);
23224 + __VCMD(add_dlimit, 8, VCA_NONE, VCF_ARES);
23225 + __VCMD(rem_dlimit, 8, VCA_NONE, VCF_ARES);
23227 +#ifdef CONFIG_VSERVER_DEVICE
23228 + __VCMD(set_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
23229 + __VCMD(unset_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
23231 + /* debug level admin commands */
23232 +#ifdef CONFIG_VSERVER_HISTORY
23233 + __VCMD(dump_history, 9, VCA_NONE, 0);
23234 + __VCMD(read_history, 9, VCA_NONE, 0);
23241 + vxdprintk(VXD_CBIT(switch, 0),
23242 + "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23243 + VC_CATEGORY(cmd), VC_COMMAND(cmd),
23244 + VC_VERSION(cmd), id, data, compat,
23245 + perm, args, flags);
23252 + if (!capable(CAP_CONTEXT))
23256 + /* moved here from the individual commands */
23258 + if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23262 + /* vcmd involves resource management */
23264 + if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23268 + /* various legacy exceptions */
23270 + /* will go away when spectator is a cap */
23271 + case VCMD_ctx_migrate_v0:
23272 + case VCMD_ctx_migrate:
23274 + current->xid = 1;
23280 + /* will go away when spectator is a cap */
23281 + case VCMD_net_migrate:
23283 + current->nid = 1;
23290 + /* vcmds are fine by default */
23293 + /* admin type vcmds require admin ... */
23294 + if (flags & VCF_ADMIN)
23295 + permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23297 + /* ... but setup type vcmds override that */
23298 + if (!permit && (flags & VCF_SETUP))
23299 + permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23307 + if (!id && (flags & VCF_ZIDOK))
23311 + if (args & VCA_VXI) {
23312 + vxi = lookup_vx_info(id);
23316 + if ((flags & VCF_ADMIN) &&
23317 + /* special case kill for shutdown */
23318 + (cmd != VCMD_ctx_kill) &&
23319 + /* can context be administrated? */
23320 + !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23326 + if (args & VCA_NXI) {
23327 + nxi = lookup_nx_info(id);
23331 + if ((flags & VCF_ADMIN) &&
23332 + /* can context be administrated? */
23333 + !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23340 + ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23343 + if ((args & VCA_NXI) && nxi)
23344 + put_nx_info(nxi);
23346 + if ((args & VCA_VXI) && vxi)
23347 + put_vx_info(vxi);
23349 + vxdprintk(VXD_CBIT(switch, 1),
23350 + "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23351 + VC_CATEGORY(cmd), VC_COMMAND(cmd),
23352 + VC_VERSION(cmd), ret, ret, state, permit);
23357 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23359 + return do_vserver(cmd, id, data, 0);
23362 +#ifdef CONFIG_COMPAT
23365 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23367 + return do_vserver(cmd, id, data, 1);
23370 +#endif /* CONFIG_COMPAT */
23371 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sysctl.c linux-3.9.4-vs2.3.6.1/kernel/vserver/sysctl.c
23372 --- linux-3.9.4/kernel/vserver/sysctl.c 1970-01-01 00:00:00.000000000 +0000
23373 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/sysctl.c 2013-05-31 14:47:11.000000000 +0000
23376 + * kernel/vserver/sysctl.c
23378 + * Virtual Context Support
23380 + * Copyright (C) 2004-2007 Herbert Pötzl
23382 + * V0.01 basic structure
23386 +#include <linux/module.h>
23387 +#include <linux/ctype.h>
23388 +#include <linux/sysctl.h>
23389 +#include <linux/parser.h>
23390 +#include <asm/uaccess.h>
23393 + CTL_DEBUG_ERROR = 0,
23394 + CTL_DEBUG_SWITCH = 1,
23410 +unsigned int vs_debug_switch = 0;
23411 +unsigned int vs_debug_xid = 0;
23412 +unsigned int vs_debug_nid = 0;
23413 +unsigned int vs_debug_tag = 0;
23414 +unsigned int vs_debug_net = 0;
23415 +unsigned int vs_debug_limit = 0;
23416 +unsigned int vs_debug_cres = 0;
23417 +unsigned int vs_debug_dlim = 0;
23418 +unsigned int vs_debug_quota = 0;
23419 +unsigned int vs_debug_cvirt = 0;
23420 +unsigned int vs_debug_space = 0;
23421 +unsigned int vs_debug_perm = 0;
23422 +unsigned int vs_debug_misc = 0;
23425 +static struct ctl_table_header *vserver_table_header;
23426 +static ctl_table vserver_root_table[];
23429 +void vserver_register_sysctl(void)
23431 + if (!vserver_table_header) {
23432 + vserver_table_header = register_sysctl_table(vserver_root_table);
23437 +void vserver_unregister_sysctl(void)
23439 + if (vserver_table_header) {
23440 + unregister_sysctl_table(vserver_table_header);
23441 + vserver_table_header = NULL;
23446 +static int proc_dodebug(ctl_table *table, int write,
23447 + void __user *buffer, size_t *lenp, loff_t *ppos)
23449 + char tmpbuf[20], *p, c;
23450 + unsigned int value;
23451 + size_t left, len;
23453 + if ((*ppos && !write) || !*lenp) {
23461 + if (!access_ok(VERIFY_READ, buffer, left))
23463 + p = (char *)buffer;
23464 + while (left && __get_user(c, p) >= 0 && isspace(c))
23469 + if (left > sizeof(tmpbuf) - 1)
23471 + if (copy_from_user(tmpbuf, p, left))
23473 + tmpbuf[left] = '\0';
23475 + for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23476 + value = 10 * value + (*p - '0');
23477 + if (*p && !isspace(*p))
23479 + while (left && isspace(*p))
23481 + *(unsigned int *)table->data = value;
23483 + if (!access_ok(VERIFY_WRITE, buffer, left))
23485 + len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23488 + if (__copy_to_user(buffer, tmpbuf, len))
23490 + if ((left -= len) > 0) {
23491 + if (put_user('\n', (char *)buffer + len))
23505 +#define CTL_ENTRY(ctl, name) \
23507 + .procname = #name, \
23508 + .data = &vs_ ## name, \
23509 + .maxlen = sizeof(int), \
23511 + .proc_handler = &proc_dodebug, \
23512 + .extra1 = &zero, \
23513 + .extra2 = &zero, \
23516 +static ctl_table vserver_debug_table[] = {
23517 + CTL_ENTRY(CTL_DEBUG_SWITCH, debug_switch),
23518 + CTL_ENTRY(CTL_DEBUG_XID, debug_xid),
23519 + CTL_ENTRY(CTL_DEBUG_NID, debug_nid),
23520 + CTL_ENTRY(CTL_DEBUG_TAG, debug_tag),
23521 + CTL_ENTRY(CTL_DEBUG_NET, debug_net),
23522 + CTL_ENTRY(CTL_DEBUG_LIMIT, debug_limit),
23523 + CTL_ENTRY(CTL_DEBUG_CRES, debug_cres),
23524 + CTL_ENTRY(CTL_DEBUG_DLIM, debug_dlim),
23525 + CTL_ENTRY(CTL_DEBUG_QUOTA, debug_quota),
23526 + CTL_ENTRY(CTL_DEBUG_CVIRT, debug_cvirt),
23527 + CTL_ENTRY(CTL_DEBUG_SPACE, debug_space),
23528 + CTL_ENTRY(CTL_DEBUG_PERM, debug_perm),
23529 + CTL_ENTRY(CTL_DEBUG_MISC, debug_misc),
23533 +static ctl_table vserver_root_table[] = {
23535 + .procname = "vserver",
23537 + .child = vserver_debug_table
23543 +static match_table_t tokens = {
23544 + { CTL_DEBUG_SWITCH, "switch=%x" },
23545 + { CTL_DEBUG_XID, "xid=%x" },
23546 + { CTL_DEBUG_NID, "nid=%x" },
23547 + { CTL_DEBUG_TAG, "tag=%x" },
23548 + { CTL_DEBUG_NET, "net=%x" },
23549 + { CTL_DEBUG_LIMIT, "limit=%x" },
23550 + { CTL_DEBUG_CRES, "cres=%x" },
23551 + { CTL_DEBUG_DLIM, "dlim=%x" },
23552 + { CTL_DEBUG_QUOTA, "quota=%x" },
23553 + { CTL_DEBUG_CVIRT, "cvirt=%x" },
23554 + { CTL_DEBUG_SPACE, "space=%x" },
23555 + { CTL_DEBUG_PERM, "perm=%x" },
23556 + { CTL_DEBUG_MISC, "misc=%x" },
23557 + { CTL_DEBUG_ERROR, NULL }
23560 +#define HANDLE_CASE(id, name, val) \
23561 + case CTL_DEBUG_ ## id: \
23562 + vs_debug_ ## name = val; \
23563 + printk("vs_debug_" #name "=0x%x\n", val); \
23567 +static int __init vs_debug_setup(char *str)
23572 + printk("vs_debug_setup(%s)\n", str);
23573 + while ((p = strsep(&str, ",")) != NULL) {
23574 + substring_t args[MAX_OPT_ARGS];
23575 + unsigned int value;
23580 + token = match_token(p, tokens, args);
23581 + value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23584 + HANDLE_CASE(SWITCH, switch, value);
23585 + HANDLE_CASE(XID, xid, value);
23586 + HANDLE_CASE(NID, nid, value);
23587 + HANDLE_CASE(TAG, tag, value);
23588 + HANDLE_CASE(NET, net, value);
23589 + HANDLE_CASE(LIMIT, limit, value);
23590 + HANDLE_CASE(CRES, cres, value);
23591 + HANDLE_CASE(DLIM, dlim, value);
23592 + HANDLE_CASE(QUOTA, quota, value);
23593 + HANDLE_CASE(CVIRT, cvirt, value);
23594 + HANDLE_CASE(SPACE, space, value);
23595 + HANDLE_CASE(PERM, perm, value);
23596 + HANDLE_CASE(MISC, misc, value);
23605 +__setup("vsdebug=", vs_debug_setup);
23609 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23610 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23611 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23612 +EXPORT_SYMBOL_GPL(vs_debug_net);
23613 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23614 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23615 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23616 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23617 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23618 +EXPORT_SYMBOL_GPL(vs_debug_space);
23619 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23620 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23622 diff -NurpP --minimal linux-3.9.4/kernel/vserver/tag.c linux-3.9.4-vs2.3.6.1/kernel/vserver/tag.c
23623 --- linux-3.9.4/kernel/vserver/tag.c 1970-01-01 00:00:00.000000000 +0000
23624 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/tag.c 2013-05-31 14:47:11.000000000 +0000
23627 + * linux/kernel/vserver/tag.c
23629 + * Virtual Server: Shallow Tag Space
23631 + * Copyright (C) 2007 Herbert Pötzl
23633 + * V0.01 basic implementation
23637 +#include <linux/sched.h>
23638 +#include <linux/vserver/debug.h>
23639 +#include <linux/vs_pid.h>
23640 +#include <linux/vs_tag.h>
23642 +#include <linux/vserver/tag_cmd.h>
23645 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23650 + vxdprintk(VXD_CBIT(tag, 5),
23651 + "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23657 + vxdprintk(VXD_CBIT(tag, 5),
23658 + "moved task %p into [#%d]", p, tag);
23662 +/* vserver syscall commands below here */
23664 +/* taks xid and vx_info functions */
23667 +int vc_task_tag(uint32_t id)
23672 + struct task_struct *tsk;
23674 + tsk = find_task_by_real_pid(id);
23675 + tag = (tsk) ? tsk->tag : -ESRCH;
23676 + rcu_read_unlock();
23678 + tag = dx_current_tag();
23683 +int vc_tag_migrate(uint32_t tag)
23685 + return dx_migrate_task(current, tag & 0xFFFF);
23689 diff -NurpP --minimal linux-3.9.4/kernel/vserver/vci_config.h linux-3.9.4-vs2.3.6.1/kernel/vserver/vci_config.h
23690 --- linux-3.9.4/kernel/vserver/vci_config.h 1970-01-01 00:00:00.000000000 +0000
23691 +++ linux-3.9.4-vs2.3.6.1/kernel/vserver/vci_config.h 2013-05-31 14:47:11.000000000 +0000
23694 +/* interface version */
23696 +#define VCI_VERSION 0x00020308
23700 + VCI_KCBIT_NO_DYNAMIC = 0,
23702 + VCI_KCBIT_PROC_SECURE = 4,
23703 + /* VCI_KCBIT_HARDCPU = 5, */
23704 + /* VCI_KCBIT_IDLELIMIT = 6, */
23705 + /* VCI_KCBIT_IDLETIME = 7, */
23707 + VCI_KCBIT_COWBL = 8,
23708 + VCI_KCBIT_FULLCOWBL = 9,
23709 + VCI_KCBIT_SPACES = 10,
23710 + VCI_KCBIT_NETV2 = 11,
23711 + VCI_KCBIT_MEMCG = 12,
23712 + VCI_KCBIT_MEMCG_SWAP = 13,
23714 + VCI_KCBIT_DEBUG = 16,
23715 + VCI_KCBIT_HISTORY = 20,
23716 + VCI_KCBIT_TAGGED = 24,
23717 + VCI_KCBIT_PPTAG = 28,
23719 + VCI_KCBIT_MORE = 31,
23723 +static inline uint32_t vci_kernel_config(void)
23726 + (1 << VCI_KCBIT_NO_DYNAMIC) |
23728 + /* configured features */
23729 +#ifdef CONFIG_VSERVER_PROC_SECURE
23730 + (1 << VCI_KCBIT_PROC_SECURE) |
23732 +#ifdef CONFIG_VSERVER_COWBL
23733 + (1 << VCI_KCBIT_COWBL) |
23734 + (1 << VCI_KCBIT_FULLCOWBL) |
23736 + (1 << VCI_KCBIT_SPACES) |
23737 + (1 << VCI_KCBIT_NETV2) |
23738 +#ifdef CONFIG_MEMCG
23739 + (1 << VCI_KCBIT_MEMCG) |
23741 +#ifdef CONFIG_MEMCG_SWAP
23742 + (1 << VCI_KCBIT_MEMCG_SWAP) |
23745 + /* debug options */
23746 +#ifdef CONFIG_VSERVER_DEBUG
23747 + (1 << VCI_KCBIT_DEBUG) |
23749 +#ifdef CONFIG_VSERVER_HISTORY
23750 + (1 << VCI_KCBIT_HISTORY) |
23753 + /* inode context tagging */
23754 +#if defined(CONFIG_TAGGING_NONE)
23755 + (0 << VCI_KCBIT_TAGGED) |
23756 +#elif defined(CONFIG_TAGGING_UID16)
23757 + (1 << VCI_KCBIT_TAGGED) |
23758 +#elif defined(CONFIG_TAGGING_GID16)
23759 + (2 << VCI_KCBIT_TAGGED) |
23760 +#elif defined(CONFIG_TAGGING_ID24)
23761 + (3 << VCI_KCBIT_TAGGED) |
23762 +#elif defined(CONFIG_TAGGING_INTERN)
23763 + (4 << VCI_KCBIT_TAGGED) |
23764 +#elif defined(CONFIG_TAGGING_RUNTIME)
23765 + (5 << VCI_KCBIT_TAGGED) |
23767 + (7 << VCI_KCBIT_TAGGED) |
23769 + (1 << VCI_KCBIT_PPTAG) |
23773 diff -NurpP --minimal linux-3.9.4/mm/memcontrol.c linux-3.9.4-vs2.3.6.1/mm/memcontrol.c
23774 --- linux-3.9.4/mm/memcontrol.c 2013-05-31 13:45:31.000000000 +0000
23775 +++ linux-3.9.4-vs2.3.6.1/mm/memcontrol.c 2013-05-31 14:47:11.000000000 +0000
23776 @@ -1046,6 +1046,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23777 return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23780 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23782 + return res_counter_read_u64(&mem->res, member);
23785 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23787 + return res_counter_read_u64(&mem->memsw, member);
23790 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23792 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23795 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23797 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23800 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23802 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23805 struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23807 struct mem_cgroup *memcg = NULL;
23808 diff -NurpP --minimal linux-3.9.4/mm/oom_kill.c linux-3.9.4-vs2.3.6.1/mm/oom_kill.c
23809 --- linux-3.9.4/mm/oom_kill.c 2013-05-31 13:45:31.000000000 +0000
23810 +++ linux-3.9.4-vs2.3.6.1/mm/oom_kill.c 2013-05-31 14:47:11.000000000 +0000
23812 #include <linux/freezer.h>
23813 #include <linux/ftrace.h>
23814 #include <linux/ratelimit.h>
23815 +#include <linux/reboot.h>
23816 +#include <linux/vs_context.h>
23818 #define CREATE_TRACE_POINTS
23819 #include <trace/events/oom.h>
23820 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23821 static bool oom_unkillable_task(struct task_struct *p,
23822 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23824 - if (is_global_init(p))
23825 + unsigned xid = vx_current_xid();
23827 + /* skip the init task, global and per guest */
23828 + if (task_is_init(p))
23830 if (p->flags & PF_KTHREAD)
23833 + /* skip other guest and host processes if oom in guest */
23834 + if (xid && vx_task_xid(p) != xid)
23837 /* When mem_cgroup_out_of_memory() and p is not member of the group */
23838 if (memcg && !task_in_mem_cgroup(p, memcg))
23840 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23841 dump_header(p, gfp_mask, order, memcg, nodemask);
23844 - pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23845 - message, task_pid_nr(p), p->comm, points);
23846 + pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23847 + message, task_pid_nr(p), p->xid, p->comm, points);
23851 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23853 /* mm cannot safely be dereferenced after task_unlock(victim) */
23855 - pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23856 - task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23857 + pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23858 + task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23859 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23860 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23861 task_unlock(victim);
23862 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23864 EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23866 +long vs_oom_action(unsigned int);
23869 * Try to acquire the OOM killer lock for the zones in zonelist. Returns zero
23870 * if a parallel OOM killing is already taking place that includes a zone in
23871 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23872 /* Found nothing?!?! Either we hang forever, or we panic. */
23874 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23875 - panic("Out of memory and no killable processes...\n");
23877 + /* avoid panic for guest OOM */
23878 + if (vx_current_xid())
23879 + vs_oom_action(LINUX_REBOOT_CMD_OOM);
23881 + panic("Out of memory and no killable processes...\n");
23883 if (PTR_ERR(p) != -1UL) {
23884 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23885 diff -NurpP --minimal linux-3.9.4/mm/page_alloc.c linux-3.9.4-vs2.3.6.1/mm/page_alloc.c
23886 --- linux-3.9.4/mm/page_alloc.c 2013-05-31 13:45:31.000000000 +0000
23887 +++ linux-3.9.4-vs2.3.6.1/mm/page_alloc.c 2013-05-31 15:08:50.000000000 +0000
23889 #include <linux/migrate.h>
23890 #include <linux/page-debug-flags.h>
23891 #include <linux/sched/rt.h>
23892 +#include <linux/vs_base.h>
23893 +#include <linux/vs_limit.h>
23895 #include <asm/tlbflush.h>
23896 #include <asm/div64.h>
23897 @@ -2873,6 +2875,9 @@ void si_meminfo(struct sysinfo *val)
23898 val->totalhigh = totalhigh_pages;
23899 val->freehigh = nr_free_highpages();
23900 val->mem_unit = PAGE_SIZE;
23902 + if (vx_flags(VXF_VIRT_MEM, 0))
23903 + vx_vsi_meminfo(val);
23906 EXPORT_SYMBOL(si_meminfo);
23907 @@ -2893,6 +2898,9 @@ void si_meminfo_node(struct sysinfo *val
23910 val->mem_unit = PAGE_SIZE;
23912 + if (vx_flags(VXF_VIRT_MEM, 0))
23913 + vx_vsi_meminfo(val);
23917 diff -NurpP --minimal linux-3.9.4/mm/pgtable-generic.c linux-3.9.4-vs2.3.6.1/mm/pgtable-generic.c
23918 --- linux-3.9.4/mm/pgtable-generic.c 2013-02-19 13:58:57.000000000 +0000
23919 +++ linux-3.9.4-vs2.3.6.1/mm/pgtable-generic.c 2013-05-31 14:47:11.000000000 +0000
23921 * Copyright (C) 2010 Linus Torvalds
23924 +#include <linux/mm.h>
23926 #include <linux/pagemap.h>
23927 #include <asm/tlb.h>
23928 #include <asm-generic/pgtable.h>
23929 diff -NurpP --minimal linux-3.9.4/mm/shmem.c linux-3.9.4-vs2.3.6.1/mm/shmem.c
23930 --- linux-3.9.4/mm/shmem.c 2013-05-31 13:45:31.000000000 +0000
23931 +++ linux-3.9.4-vs2.3.6.1/mm/shmem.c 2013-05-31 14:47:11.000000000 +0000
23932 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23934 struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23936 - buf->f_type = TMPFS_MAGIC;
23937 + buf->f_type = TMPFS_SUPER_MAGIC;
23938 buf->f_bsize = PAGE_CACHE_SIZE;
23939 buf->f_namelen = NAME_MAX;
23940 if (sbinfo->max_blocks) {
23941 @@ -2606,7 +2606,7 @@ int shmem_fill_super(struct super_block
23942 sb->s_maxbytes = MAX_LFS_FILESIZE;
23943 sb->s_blocksize = PAGE_CACHE_SIZE;
23944 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23945 - sb->s_magic = TMPFS_MAGIC;
23946 + sb->s_magic = TMPFS_SUPER_MAGIC;
23947 sb->s_op = &shmem_ops;
23948 sb->s_time_gran = 1;
23949 #ifdef CONFIG_TMPFS_XATTR
23950 diff -NurpP --minimal linux-3.9.4/mm/slab.c linux-3.9.4-vs2.3.6.1/mm/slab.c
23951 --- linux-3.9.4/mm/slab.c 2013-05-31 13:45:31.000000000 +0000
23952 +++ linux-3.9.4-vs2.3.6.1/mm/slab.c 2013-05-31 14:47:11.000000000 +0000
23953 @@ -429,6 +429,8 @@ static void kmem_list3_init(struct kmem_
23954 #define STATS_INC_FREEMISS(x) do { } while (0)
23957 +#include "slab_vs.h"
23962 @@ -3438,6 +3440,7 @@ retry:
23964 obj = slab_get_obj(cachep, slabp, nodeid);
23965 check_slabp(cachep, slabp);
23966 + vx_slab_alloc(cachep, flags);
23967 l3->free_objects--;
23968 /* move slabp to correct slabp list: */
23969 list_del(&slabp->list);
23970 @@ -3517,6 +3520,7 @@ slab_alloc_node(struct kmem_cache *cache
23971 /* ___cache_alloc_node can fall back to other nodes */
23972 ptr = ____cache_alloc_node(cachep, flags, nodeid);
23974 + vx_slab_alloc(cachep, flags);
23975 local_irq_restore(save_flags);
23976 ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23977 kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23978 @@ -3709,6 +3713,7 @@ static inline void __cache_free(struct k
23980 kmemleak_free_recursive(objp, cachep->flags);
23981 objp = cache_free_debugcheck(cachep, objp, caller);
23982 + vx_slab_free(cachep);
23984 kmemcheck_slab_free(cachep, objp, cachep->object_size);
23986 diff -NurpP --minimal linux-3.9.4/mm/slab_vs.h linux-3.9.4-vs2.3.6.1/mm/slab_vs.h
23987 --- linux-3.9.4/mm/slab_vs.h 1970-01-01 00:00:00.000000000 +0000
23988 +++ linux-3.9.4-vs2.3.6.1/mm/slab_vs.h 2013-05-31 14:47:11.000000000 +0000
23991 +#include <linux/vserver/context.h>
23993 +#include <linux/vs_context.h>
23996 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23998 + int what = gfp_zone(cachep->allocflags);
23999 + struct vx_info *vxi = current_vx_info();
24004 + atomic_add(cachep->size, &vxi->cacct.slab[what]);
24008 +void vx_slab_free(struct kmem_cache *cachep)
24010 + int what = gfp_zone(cachep->allocflags);
24011 + struct vx_info *vxi = current_vx_info();
24016 + atomic_sub(cachep->size, &vxi->cacct.slab[what]);
24019 diff -NurpP --minimal linux-3.9.4/mm/swapfile.c linux-3.9.4-vs2.3.6.1/mm/swapfile.c
24020 --- linux-3.9.4/mm/swapfile.c 2013-05-31 13:45:31.000000000 +0000
24021 +++ linux-3.9.4-vs2.3.6.1/mm/swapfile.c 2013-05-31 14:47:11.000000000 +0000
24023 #include <asm/tlbflush.h>
24024 #include <linux/swapops.h>
24025 #include <linux/page_cgroup.h>
24026 +#include <linux/vs_base.h>
24028 static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24030 @@ -1767,6 +1768,16 @@ static int swap_show(struct seq_file *sw
24032 if (si == SEQ_START_TOKEN) {
24033 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24034 + if (vx_flags(VXF_VIRT_MEM, 0)) {
24035 + struct sysinfo si;
24037 + vx_vsi_swapinfo(&si);
24038 + if (si.totalswap < (1 << 10))
24040 + seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24041 + "hdv0", "partition", si.totalswap >> 10,
24042 + (si.totalswap - si.freeswap) >> 10, -1);
24047 @@ -2195,6 +2206,8 @@ void si_swapinfo(struct sysinfo *val)
24048 val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
24049 val->totalswap = total_swap_pages + nr_to_be_unused;
24050 spin_unlock(&swap_lock);
24051 + if (vx_flags(VXF_VIRT_MEM, 0))
24052 + vx_vsi_swapinfo(val);
24056 diff -NurpP --minimal linux-3.9.4/net/bridge/br_multicast.c linux-3.9.4-vs2.3.6.1/net/bridge/br_multicast.c
24057 --- linux-3.9.4/net/bridge/br_multicast.c 2013-05-31 13:45:31.000000000 +0000
24058 +++ linux-3.9.4-vs2.3.6.1/net/bridge/br_multicast.c 2013-05-31 17:17:53.000000000 +0000
24059 @@ -443,7 +443,7 @@ static struct sk_buff *br_ip6_multicast_
24060 ip6h->hop_limit = 1;
24061 ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24062 if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24064 + &ip6h->saddr, NULL)) {
24068 diff -NurpP --minimal linux-3.9.4/net/core/dev.c linux-3.9.4-vs2.3.6.1/net/core/dev.c
24069 --- linux-3.9.4/net/core/dev.c 2013-05-31 14:22:27.000000000 +0000
24070 +++ linux-3.9.4-vs2.3.6.1/net/core/dev.c 2013-05-31 18:37:38.000000000 +0000
24071 @@ -122,6 +122,7 @@
24072 #include <linux/in.h>
24073 #include <linux/jhash.h>
24074 #include <linux/random.h>
24075 +#include <linux/vs_inet.h>
24076 #include <trace/events/napi.h>
24077 #include <trace/events/net.h>
24078 #include <trace/events/skb.h>
24079 @@ -662,7 +663,8 @@ struct net_device *__dev_get_by_name(str
24080 struct hlist_head *head = dev_name_hash(net, name);
24082 hlist_for_each_entry(dev, head, name_hlist)
24083 - if (!strncmp(dev->name, name, IFNAMSIZ))
24084 + if (!strncmp(dev->name, name, IFNAMSIZ) &&
24085 + nx_dev_visible(current_nx_info(), dev))
24089 @@ -687,7 +689,8 @@ struct net_device *dev_get_by_name_rcu(s
24090 struct hlist_head *head = dev_name_hash(net, name);
24092 hlist_for_each_entry_rcu(dev, head, name_hlist)
24093 - if (!strncmp(dev->name, name, IFNAMSIZ))
24094 + if (!strncmp(dev->name, name, IFNAMSIZ) &&
24095 + nx_dev_visible(current_nx_info(), dev))
24099 @@ -737,7 +740,8 @@ struct net_device *__dev_get_by_index(st
24100 struct hlist_head *head = dev_index_hash(net, ifindex);
24102 hlist_for_each_entry(dev, head, index_hlist)
24103 - if (dev->ifindex == ifindex)
24104 + if ((dev->ifindex == ifindex) &&
24105 + nx_dev_visible(current_nx_info(), dev))
24109 @@ -755,7 +759,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24110 * about locking. The caller must hold RCU lock.
24113 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24114 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24116 struct net_device *dev;
24117 struct hlist_head *head = dev_index_hash(net, ifindex);
24118 @@ -766,6 +770,16 @@ struct net_device *dev_get_by_index_rcu(
24122 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24124 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24126 + struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24128 + if (nx_dev_visible(current_nx_info(), dev))
24132 EXPORT_SYMBOL(dev_get_by_index_rcu);
24135 @@ -814,7 +828,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24137 for_each_netdev_rcu(net, dev)
24138 if (dev->type == type &&
24139 - !memcmp(dev->dev_addr, ha, dev->addr_len))
24140 + !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24141 + nx_dev_visible(current_nx_info(), dev))
24145 @@ -826,9 +841,11 @@ struct net_device *__dev_getfirstbyhwtyp
24146 struct net_device *dev;
24149 - for_each_netdev(net, dev)
24150 - if (dev->type == type)
24151 + for_each_netdev(net, dev) {
24152 + if ((dev->type == type) &&
24153 + nx_dev_visible(current_nx_info(), dev))
24159 @@ -840,7 +857,8 @@ struct net_device *dev_getfirstbyhwtype(
24162 for_each_netdev_rcu(net, dev)
24163 - if (dev->type == type) {
24164 + if ((dev->type == type) &&
24165 + nx_dev_visible(current_nx_info(), dev)) {
24169 @@ -868,7 +886,8 @@ struct net_device *dev_get_by_flags_rcu(
24172 for_each_netdev_rcu(net, dev) {
24173 - if (((dev->flags ^ if_flags) & mask) == 0) {
24174 + if ((((dev->flags ^ if_flags) & mask) == 0) &&
24175 + nx_dev_visible(current_nx_info(), dev)) {
24179 @@ -946,6 +965,8 @@ static int __dev_alloc_name(struct net *
24181 if (i < 0 || i >= max_netdevices)
24183 + if (!nx_dev_visible(current_nx_info(), d))
24186 /* avoid cases where sscanf is not exact inverse of printf */
24187 snprintf(buf, IFNAMSIZ, name, i);
24188 diff -NurpP --minimal linux-3.9.4/net/core/rtnetlink.c linux-3.9.4-vs2.3.6.1/net/core/rtnetlink.c
24189 --- linux-3.9.4/net/core/rtnetlink.c 2013-05-31 13:45:32.000000000 +0000
24190 +++ linux-3.9.4-vs2.3.6.1/net/core/rtnetlink.c 2013-05-31 17:17:54.000000000 +0000
24191 @@ -1085,6 +1085,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24192 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24195 + if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24197 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24198 NETLINK_CB(cb->skb).portid,
24199 cb->nlh->nlmsg_seq, 0,
24200 @@ -1974,6 +1976,9 @@ void rtmsg_ifinfo(int type, struct net_d
24201 int err = -ENOBUFS;
24202 size_t if_info_size;
24204 + if (!nx_dev_visible(current_nx_info(), dev))
24207 skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24210 diff -NurpP --minimal linux-3.9.4/net/core/sock.c linux-3.9.4-vs2.3.6.1/net/core/sock.c
24211 --- linux-3.9.4/net/core/sock.c 2013-05-31 14:22:27.000000000 +0000
24212 +++ linux-3.9.4-vs2.3.6.1/net/core/sock.c 2013-05-31 17:17:54.000000000 +0000
24213 @@ -132,6 +132,10 @@
24214 #include <net/netprio_cgroup.h>
24216 #include <linux/filter.h>
24217 +#include <linux/vs_socket.h>
24218 +#include <linux/vs_limit.h>
24219 +#include <linux/vs_context.h>
24220 +#include <linux/vs_network.h>
24222 #include <trace/events/sock.h>
24224 @@ -1257,6 +1261,8 @@ static struct sock *sk_prot_alloc(struct
24226 sk_tx_queue_clear(sk);
24228 + sock_vx_init(sk);
24229 + sock_nx_init(sk);
24233 @@ -1367,6 +1373,11 @@ static void __sk_free(struct sock *sk)
24234 put_cred(sk->sk_peer_cred);
24235 put_pid(sk->sk_peer_pid);
24236 put_net(sock_net(sk));
24238 + clr_vx_info(&sk->sk_vx_info);
24240 + clr_nx_info(&sk->sk_nx_info);
24242 sk_prot_free(sk->sk_prot_creator, sk);
24245 @@ -1427,6 +1438,8 @@ struct sock *sk_clone_lock(const struct
24248 get_net(sock_net(newsk));
24249 + sock_vx_init(newsk);
24250 + sock_nx_init(newsk);
24251 sk_node_init(&newsk->sk_node);
24252 sock_lock_init(newsk);
24253 bh_lock_sock(newsk);
24254 @@ -1483,6 +1496,12 @@ struct sock *sk_clone_lock(const struct
24256 atomic_set(&newsk->sk_refcnt, 2);
24258 + set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24259 + newsk->sk_xid = sk->sk_xid;
24260 + vx_sock_inc(newsk);
24261 + set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24262 + newsk->sk_nid = sk->sk_nid;
24265 * Increment the counter in the same struct proto as the master
24266 * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24267 @@ -2278,6 +2297,12 @@ void sock_init_data(struct socket *sock,
24269 sk->sk_stamp = ktime_set(-1L, 0);
24271 + set_vx_info(&sk->sk_vx_info, current_vx_info());
24272 + sk->sk_xid = vx_current_xid();
24274 + set_nx_info(&sk->sk_nx_info, current_nx_info());
24275 + sk->sk_nid = nx_current_nid();
24278 * Before updating sk_refcnt, we must commit prior changes to memory
24279 * (Documentation/RCU/rculist_nulls.txt for details)
24280 diff -NurpP --minimal linux-3.9.4/net/ipv4/af_inet.c linux-3.9.4-vs2.3.6.1/net/ipv4/af_inet.c
24281 --- linux-3.9.4/net/ipv4/af_inet.c 2013-05-31 13:45:32.000000000 +0000
24282 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/af_inet.c 2013-05-31 18:24:05.000000000 +0000
24283 @@ -118,6 +118,7 @@
24284 #ifdef CONFIG_IP_MROUTE
24285 #include <linux/mroute.h>
24287 +#include <linux/vs_limit.h>
24290 /* The inetsw table contains everything that inet_create needs to
24291 @@ -336,6 +337,10 @@ lookup_protocol:
24295 + if ((protocol == IPPROTO_ICMP) &&
24296 + nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24299 if (sock->type == SOCK_RAW && !kern &&
24300 !ns_capable(net->user_ns, CAP_NET_RAW))
24301 goto out_rcu_unlock;
24302 @@ -460,6 +465,7 @@ int inet_bind(struct socket *sock, struc
24303 struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24304 struct sock *sk = sock->sk;
24305 struct inet_sock *inet = inet_sk(sk);
24306 + struct nx_v4_sock_addr nsa;
24307 struct net *net = sock_net(sk);
24308 unsigned short snum;
24310 @@ -484,7 +490,11 @@ int inet_bind(struct socket *sock, struc
24314 - chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
24315 + err = v4_map_sock_addr(inet, addr, &nsa);
24319 + chk_addr_ret = inet_addr_type(net, nsa.saddr);
24321 /* Not specified by any standard per-se, however it breaks too
24322 * many applications when removed. It is unfortunate since
24323 @@ -496,7 +506,7 @@ int inet_bind(struct socket *sock, struc
24324 err = -EADDRNOTAVAIL;
24325 if (!sysctl_ip_nonlocal_bind &&
24326 !(inet->freebind || inet->transparent) &&
24327 - addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24328 + nsa.saddr != htonl(INADDR_ANY) &&
24329 chk_addr_ret != RTN_LOCAL &&
24330 chk_addr_ret != RTN_MULTICAST &&
24331 chk_addr_ret != RTN_BROADCAST)
24332 @@ -522,7 +532,7 @@ int inet_bind(struct socket *sock, struc
24333 if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24334 goto out_release_sock;
24336 - inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24337 + v4_set_sock_addr(inet, &nsa);
24338 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24339 inet->inet_saddr = 0; /* Use device */
24341 @@ -741,11 +751,13 @@ int inet_getname(struct socket *sock, st
24344 sin->sin_port = inet->inet_dport;
24345 - sin->sin_addr.s_addr = inet->inet_daddr;
24346 + sin->sin_addr.s_addr =
24347 + nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24349 __be32 addr = inet->inet_rcv_saddr;
24351 addr = inet->inet_saddr;
24352 + addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24353 sin->sin_port = inet->inet_sport;
24354 sin->sin_addr.s_addr = addr;
24356 diff -NurpP --minimal linux-3.9.4/net/ipv4/arp.c linux-3.9.4-vs2.3.6.1/net/ipv4/arp.c
24357 --- linux-3.9.4/net/ipv4/arp.c 2013-05-31 13:45:32.000000000 +0000
24358 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/arp.c 2013-05-31 17:17:54.000000000 +0000
24359 @@ -1317,6 +1317,7 @@ static void arp_format_neigh_entry(struc
24360 struct net_device *dev = n->dev;
24361 int hatype = dev->type;
24363 + /* FIXME: check for network context */
24364 read_lock(&n->lock);
24365 /* Convert hardware address to XX:XX:XX:XX ... form. */
24366 #if IS_ENABLED(CONFIG_AX25)
24367 @@ -1348,6 +1349,7 @@ static void arp_format_pneigh_entry(stru
24368 int hatype = dev ? dev->type : 0;
24371 + /* FIXME: check for network context */
24372 sprintf(tbuf, "%pI4", n->key);
24373 seq_printf(seq, "%-16s 0x%-10x0x%-10x%s * %s\n",
24374 tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24375 diff -NurpP --minimal linux-3.9.4/net/ipv4/devinet.c linux-3.9.4-vs2.3.6.1/net/ipv4/devinet.c
24376 --- linux-3.9.4/net/ipv4/devinet.c 2013-05-31 13:45:32.000000000 +0000
24377 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/devinet.c 2013-05-31 17:17:54.000000000 +0000
24378 @@ -522,6 +522,7 @@ struct in_device *inetdev_by_index(struc
24380 EXPORT_SYMBOL(inetdev_by_index);
24383 /* Called only from RTNL semaphored context. No locks. */
24385 struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24386 @@ -940,6 +941,8 @@ int devinet_ioctl(struct net *net, unsig
24388 in_dev = __in_dev_get_rtnl(dev);
24390 + struct nx_info *nxi = current_nx_info();
24392 if (tryaddrmatch) {
24393 /* Matthias Andree */
24394 /* compare label and address (4.4BSD style) */
24395 @@ -948,6 +951,8 @@ int devinet_ioctl(struct net *net, unsig
24396 This is checked above. */
24397 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24398 ifap = &ifa->ifa_next) {
24399 + if (!nx_v4_ifa_visible(nxi, ifa))
24401 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24402 sin_orig.sin_addr.s_addr ==
24404 @@ -960,9 +965,12 @@ int devinet_ioctl(struct net *net, unsig
24405 comparing just the label */
24407 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24408 - ifap = &ifa->ifa_next)
24409 + ifap = &ifa->ifa_next) {
24410 + if (!nx_v4_ifa_visible(nxi, ifa))
24412 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24418 @@ -1116,6 +1124,8 @@ static int inet_gifconf(struct net_devic
24421 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24422 + if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24425 done += sizeof(ifr);
24427 @@ -1519,6 +1529,7 @@ static int inet_dump_ifaddr(struct sk_bu
24428 struct net_device *dev;
24429 struct in_device *in_dev;
24430 struct in_ifaddr *ifa;
24431 + struct sock *sk = skb->sk;
24432 struct hlist_head *head;
24435 @@ -1540,6 +1551,8 @@ static int inet_dump_ifaddr(struct sk_bu
24437 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24438 ifa = ifa->ifa_next, ip_idx++) {
24439 + if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24441 if (ip_idx < s_ip_idx)
24443 if (inet_fill_ifaddr(skb, ifa,
24444 diff -NurpP --minimal linux-3.9.4/net/ipv4/fib_trie.c linux-3.9.4-vs2.3.6.1/net/ipv4/fib_trie.c
24445 --- linux-3.9.4/net/ipv4/fib_trie.c 2013-05-31 13:45:32.000000000 +0000
24446 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/fib_trie.c 2013-05-31 17:17:54.000000000 +0000
24447 @@ -2548,6 +2548,7 @@ static int fib_route_seq_show(struct seq
24448 || fa->fa_type == RTN_MULTICAST)
24451 + /* FIXME: check for network context? */
24454 "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24455 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_connection_sock.c linux-3.9.4-vs2.3.6.1/net/ipv4/inet_connection_sock.c
24456 --- linux-3.9.4/net/ipv4/inet_connection_sock.c 2013-05-31 13:45:32.000000000 +0000
24457 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/inet_connection_sock.c 2013-05-31 18:29:56.000000000 +0000
24458 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24460 EXPORT_SYMBOL(inet_get_local_port_range);
24462 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24464 + __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1),
24465 + sk2_rcv_saddr = sk_rcv_saddr(sk2);
24467 + if (inet_v6_ipv6only(sk2))
24470 + if (sk1_rcv_saddr &&
24472 + sk1_rcv_saddr == sk2_rcv_saddr)
24475 + if (sk1_rcv_saddr &&
24476 + !sk2_rcv_saddr &&
24477 + v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24480 + if (sk2_rcv_saddr &&
24481 + !sk1_rcv_saddr &&
24482 + v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24485 + if (!sk1_rcv_saddr &&
24486 + !sk2_rcv_saddr &&
24487 + nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24493 int inet_csk_bind_conflict(const struct sock *sk,
24494 const struct inet_bind_bucket *tb, bool relax)
24496 @@ -79,17 +110,12 @@ int inet_csk_bind_conflict(const struct
24497 (!reuseport || !sk2->sk_reuseport ||
24498 (sk2->sk_state != TCP_TIME_WAIT &&
24499 !uid_eq(uid, sock_i_uid(sk2))))) {
24500 - const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24501 - if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24502 - sk2_rcv_saddr == sk_rcv_saddr(sk))
24503 + if (ipv4_rcv_saddr_equal(sk, sk2))
24506 if (!relax && reuse && sk2->sk_reuse &&
24507 sk2->sk_state != TCP_LISTEN) {
24508 - const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24510 - if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24511 - sk2_rcv_saddr == sk_rcv_saddr(sk))
24512 + if (ipv4_rcv_saddr_equal(sk, sk2))
24516 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_diag.c linux-3.9.4-vs2.3.6.1/net/ipv4/inet_diag.c
24517 --- linux-3.9.4/net/ipv4/inet_diag.c 2013-02-19 13:58:58.000000000 +0000
24518 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/inet_diag.c 2013-05-31 17:17:54.000000000 +0000
24521 #include <linux/inet.h>
24522 #include <linux/stddef.h>
24523 +#include <linux/vs_network.h>
24524 +#include <linux/vs_inet.h>
24526 #include <linux/inet_diag.h>
24527 #include <linux/sock_diag.h>
24528 @@ -106,8 +108,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24530 r->id.idiag_sport = inet->inet_sport;
24531 r->id.idiag_dport = inet->inet_dport;
24532 - r->id.idiag_src[0] = inet->inet_rcv_saddr;
24533 - r->id.idiag_dst[0] = inet->inet_daddr;
24534 + r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24535 + inet->inet_rcv_saddr);
24536 + r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24537 + inet->inet_daddr);
24539 if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
24541 @@ -242,8 +246,8 @@ static int inet_twsk_diag_fill(struct in
24542 sock_diag_save_cookie(tw, r->id.idiag_cookie);
24543 r->id.idiag_sport = tw->tw_sport;
24544 r->id.idiag_dport = tw->tw_dport;
24545 - r->id.idiag_src[0] = tw->tw_rcv_saddr;
24546 - r->id.idiag_dst[0] = tw->tw_daddr;
24547 + r->id.idiag_src[0] = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24548 + r->id.idiag_dst[0] = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24549 r->idiag_state = tw->tw_substate;
24550 r->idiag_timer = 3;
24551 r->idiag_expires = DIV_ROUND_UP(tmo * 1000, HZ);
24552 @@ -287,12 +291,14 @@ int inet_diag_dump_one_icsk(struct inet_
24555 if (req->sdiag_family == AF_INET) {
24556 + /* TODO: lback */
24557 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24558 req->id.idiag_dport, req->id.idiag_src[0],
24559 req->id.idiag_sport, req->id.idiag_if);
24561 #if IS_ENABLED(CONFIG_IPV6)
24562 else if (req->sdiag_family == AF_INET6) {
24563 + /* TODO: lback */
24564 sk = inet6_lookup(net, hashinfo,
24565 (struct in6_addr *)req->id.idiag_dst,
24566 req->id.idiag_dport,
24567 @@ -494,6 +500,7 @@ int inet_diag_bc_sk(const struct nlattr
24571 + /* TODO: lback */
24572 entry.saddr = &inet->inet_rcv_saddr;
24573 entry.daddr = &inet->inet_daddr;
24575 @@ -652,6 +659,7 @@ static int inet_twsk_diag_dump(struct in
24579 + /* TODO: lback */
24580 entry.saddr = &tw->tw_rcv_saddr;
24581 entry.daddr = &tw->tw_daddr;
24583 @@ -730,8 +738,8 @@ static int inet_diag_fill_req(struct sk_
24585 r->id.idiag_sport = inet->inet_sport;
24586 r->id.idiag_dport = ireq->rmt_port;
24587 - r->id.idiag_src[0] = ireq->loc_addr;
24588 - r->id.idiag_dst[0] = ireq->rmt_addr;
24589 + r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24590 + r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24591 r->idiag_expires = jiffies_to_msecs(tmo);
24592 r->idiag_rqueue = 0;
24593 r->idiag_wqueue = 0;
24594 @@ -794,6 +802,7 @@ static int inet_diag_dump_reqs(struct sk
24598 + /* TODO: lback */
24600 inet_diag_req_addrs(sk, req, &entry);
24601 entry.dport = ntohs(ireq->rmt_port);
24602 @@ -850,6 +859,8 @@ void inet_diag_dump_icsk(struct inet_has
24603 if (!net_eq(sock_net(sk), net))
24606 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24611 @@ -922,6 +933,8 @@ skip_listen_ht:
24613 if (!net_eq(sock_net(sk), net))
24615 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24619 if (!(r->idiag_states & (1 << sk->sk_state)))
24620 @@ -950,7 +963,8 @@ next_normal:
24622 if (!net_eq(twsk_net(tw), net))
24625 + if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24629 if (r->sdiag_family != AF_UNSPEC &&
24630 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_hashtables.c linux-3.9.4-vs2.3.6.1/net/ipv4/inet_hashtables.c
24631 --- linux-3.9.4/net/ipv4/inet_hashtables.c 2013-05-31 13:45:32.000000000 +0000
24632 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/inet_hashtables.c 2013-05-31 18:20:50.000000000 +0000
24634 #include <net/inet_connection_sock.h>
24635 #include <net/inet_hashtables.h>
24636 #include <net/secure_seq.h>
24637 +#include <net/route.h>
24638 #include <net/ip.h>
24641 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24642 if (rcv_saddr != daddr)
24646 + /* block non nx_info ips */
24647 + if (!v4_addr_in_nx_info(sk->sk_nx_info,
24648 + daddr, NXA_MASK_BIND))
24651 if (sk->sk_bound_dev_if) {
24652 if (sk->sk_bound_dev_if != dif)
24653 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24654 * wildcarded during the search since they can never be otherwise.
24658 struct sock *__inet_lookup_listener(struct net *net,
24659 struct inet_hashinfo *hashinfo,
24660 const __be32 saddr, __be16 sport,
24661 @@ -209,6 +214,7 @@ begin:
24662 phash = next_pseudo_random32(phash);
24667 * if the nulls value we got at the end of this lookup is
24668 * not the expected one, we must restart lookup.
24669 diff -NurpP --minimal linux-3.9.4/net/ipv4/netfilter.c linux-3.9.4-vs2.3.6.1/net/ipv4/netfilter.c
24670 --- linux-3.9.4/net/ipv4/netfilter.c 2012-12-11 03:30:57.000000000 +0000
24671 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/netfilter.c 2013-05-31 17:17:54.000000000 +0000
24673 #include <linux/skbuff.h>
24674 #include <linux/gfp.h>
24675 #include <linux/export.h>
24676 -#include <net/route.h>
24677 +// #include <net/route.h>
24678 #include <net/xfrm.h>
24679 #include <net/ip.h>
24680 #include <net/netfilter/nf_queue.h>
24681 diff -NurpP --minimal linux-3.9.4/net/ipv4/raw.c linux-3.9.4-vs2.3.6.1/net/ipv4/raw.c
24682 --- linux-3.9.4/net/ipv4/raw.c 2013-05-31 13:45:32.000000000 +0000
24683 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/raw.c 2013-05-31 18:19:38.000000000 +0000
24684 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
24686 if (net_eq(sock_net(sk), net) && inet->inet_num == num &&
24687 !(inet->inet_daddr && inet->inet_daddr != raddr) &&
24688 - !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24689 + v4_sock_addr_match(sk->sk_nx_info, inet, laddr) &&
24690 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24691 goto found; /* gotcha */
24693 @@ -395,6 +395,12 @@ static int raw_send_hdrinc(struct sock *
24694 icmp_out_count(net, ((struct icmphdr *)
24695 skb_transport_header(skb))->type);
24698 + if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24699 + sk->sk_nx_info &&
24700 + !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24703 err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24704 rt->dst.dev, dst_output);
24706 @@ -580,6 +586,16 @@ static int raw_sendmsg(struct kiocb *ioc
24710 + if (sk->sk_nx_info) {
24711 + rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24712 + if (IS_ERR(rt)) {
24713 + err = PTR_ERR(rt);
24720 security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24721 rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24723 @@ -656,17 +672,19 @@ static int raw_bind(struct sock *sk, str
24725 struct inet_sock *inet = inet_sk(sk);
24726 struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24727 + struct nx_v4_sock_addr nsa = { 0 };
24731 if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24733 - chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24734 + v4_map_sock_addr(inet, addr, &nsa);
24735 + chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24736 ret = -EADDRNOTAVAIL;
24737 - if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24738 + if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24739 chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24741 - inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24742 + v4_set_sock_addr(inet, &nsa);
24743 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24744 inet->inet_saddr = 0; /* Use device */
24746 @@ -718,7 +736,8 @@ static int raw_recvmsg(struct kiocb *ioc
24747 /* Copy the address. */
24749 sin->sin_family = AF_INET;
24750 - sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24751 + sin->sin_addr.s_addr =
24752 + nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24754 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24756 @@ -913,7 +932,8 @@ static struct sock *raw_get_first(struct
24757 for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24759 sk_for_each(sk, &state->h->ht[state->bucket])
24760 - if (sock_net(sk) == seq_file_net(seq))
24761 + if ((sock_net(sk) == seq_file_net(seq)) &&
24762 + nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24766 @@ -929,7 +949,8 @@ static struct sock *raw_get_next(struct
24770 - } while (sk && sock_net(sk) != seq_file_net(seq));
24771 + } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24772 + !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24774 if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24775 sk = sk_head(&state->h->ht[state->bucket]);
24776 diff -NurpP --minimal linux-3.9.4/net/ipv4/route.c linux-3.9.4-vs2.3.6.1/net/ipv4/route.c
24777 --- linux-3.9.4/net/ipv4/route.c 2013-05-31 13:45:32.000000000 +0000
24778 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/route.c 2013-05-31 17:17:54.000000000 +0000
24779 @@ -1998,7 +1998,7 @@ struct rtable *__ip_route_output_key(str
24782 if (fl4->flowi4_oif) {
24783 - dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24784 + dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24785 rth = ERR_PTR(-ENODEV);
24786 if (dev_out == NULL)
24788 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp.c linux-3.9.4-vs2.3.6.1/net/ipv4/tcp.c
24789 --- linux-3.9.4/net/ipv4/tcp.c 2013-05-31 13:45:32.000000000 +0000
24790 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/tcp.c 2013-05-31 17:17:54.000000000 +0000
24791 @@ -268,6 +268,7 @@
24792 #include <linux/crypto.h>
24793 #include <linux/time.h>
24794 #include <linux/slab.h>
24795 +#include <linux/in.h>
24797 #include <net/icmp.h>
24798 #include <net/inet_common.h>
24799 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp_ipv4.c linux-3.9.4-vs2.3.6.1/net/ipv4/tcp_ipv4.c
24800 --- linux-3.9.4/net/ipv4/tcp_ipv4.c 2013-05-31 13:45:32.000000000 +0000
24801 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/tcp_ipv4.c 2013-05-31 17:17:54.000000000 +0000
24802 @@ -2260,6 +2260,12 @@ static void *listening_get_next(struct s
24803 req = req->dl_next;
24806 + vxdprintk(VXD_CBIT(net, 6),
24807 + "sk,req: %p [#%d] (from %d)", req->sk,
24808 + (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24810 + !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24812 if (req->rsk_ops->family == st->family) {
24815 @@ -2284,6 +2290,10 @@ get_req:
24818 sk_nulls_for_each_from(sk, node) {
24819 + vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24820 + sk, sk->sk_nid, nx_current_nid());
24821 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24823 if (!net_eq(sock_net(sk), net))
24825 if (sk->sk_family == st->family) {
24826 @@ -2360,6 +2370,11 @@ static void *established_get_first(struc
24828 spin_lock_bh(lock);
24829 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24830 + vxdprintk(VXD_CBIT(net, 6),
24831 + "sk,egf: %p [#%d] (from %d)",
24832 + sk, sk->sk_nid, nx_current_nid());
24833 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24835 if (sk->sk_family != st->family ||
24836 !net_eq(sock_net(sk), net)) {
24838 @@ -2370,6 +2385,11 @@ static void *established_get_first(struc
24839 st->state = TCP_SEQ_STATE_TIME_WAIT;
24840 inet_twsk_for_each(tw, node,
24841 &tcp_hashinfo.ehash[st->bucket].twchain) {
24842 + vxdprintk(VXD_CBIT(net, 6),
24843 + "tw: %p [#%d] (from %d)",
24844 + tw, tw->tw_nid, nx_current_nid());
24845 + if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24847 if (tw->tw_family != st->family ||
24848 !net_eq(twsk_net(tw), net)) {
24850 @@ -2399,7 +2419,9 @@ static void *established_get_next(struct
24854 - while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24855 + while (tw && (tw->tw_family != st->family ||
24856 + !net_eq(twsk_net(tw), net) ||
24857 + !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24861 @@ -2423,6 +2445,11 @@ get_tw:
24862 sk = sk_nulls_next(sk);
24864 sk_nulls_for_each_from(sk, node) {
24865 + vxdprintk(VXD_CBIT(net, 6),
24866 + "sk,egn: %p [#%d] (from %d)",
24867 + sk, sk->sk_nid, nx_current_nid());
24868 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24870 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24873 @@ -2628,9 +2655,9 @@ static void get_openreq4(const struct so
24874 seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24875 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24878 + nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24879 ntohs(inet_sk(sk)->inet_sport),
24881 + nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24882 ntohs(ireq->rmt_port),
24884 0, 0, /* could print option size, but that is af dependent. */
24885 @@ -2653,8 +2680,8 @@ static void get_tcp4_sock(struct sock *s
24886 const struct inet_connection_sock *icsk = inet_csk(sk);
24887 const struct inet_sock *inet = inet_sk(sk);
24888 struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24889 - __be32 dest = inet->inet_daddr;
24890 - __be32 src = inet->inet_rcv_saddr;
24891 + __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24892 + __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24893 __u16 destp = ntohs(inet->inet_dport);
24894 __u16 srcp = ntohs(inet->inet_sport);
24896 @@ -2710,8 +2737,8 @@ static void get_timewait4_sock(const str
24898 long delta = tw->tw_ttd - jiffies;
24900 - dest = tw->tw_daddr;
24901 - src = tw->tw_rcv_saddr;
24902 + dest = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24903 + src = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24904 destp = ntohs(tw->tw_dport);
24905 srcp = ntohs(tw->tw_sport);
24907 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp_minisocks.c linux-3.9.4-vs2.3.6.1/net/ipv4/tcp_minisocks.c
24908 --- linux-3.9.4/net/ipv4/tcp_minisocks.c 2013-05-31 14:22:27.000000000 +0000
24909 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/tcp_minisocks.c 2013-05-31 17:17:54.000000000 +0000
24911 #include <linux/slab.h>
24912 #include <linux/sysctl.h>
24913 #include <linux/workqueue.h>
24914 +#include <linux/vs_limit.h>
24915 +#include <linux/vs_socket.h>
24916 +#include <linux/vs_context.h>
24917 #include <net/tcp.h>
24918 #include <net/inet_common.h>
24919 #include <net/xfrm.h>
24920 @@ -291,6 +294,11 @@ void tcp_time_wait(struct sock *sk, int
24921 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24922 tcptw->tw_ts_offset = tp->tsoffset;
24924 + tw->tw_xid = sk->sk_xid;
24925 + tw->tw_vx_info = NULL;
24926 + tw->tw_nid = sk->sk_nid;
24927 + tw->tw_nx_info = NULL;
24929 #if IS_ENABLED(CONFIG_IPV6)
24930 if (tw->tw_family == PF_INET6) {
24931 struct ipv6_pinfo *np = inet6_sk(sk);
24932 diff -NurpP --minimal linux-3.9.4/net/ipv4/udp.c linux-3.9.4-vs2.3.6.1/net/ipv4/udp.c
24933 --- linux-3.9.4/net/ipv4/udp.c 2013-05-31 13:45:32.000000000 +0000
24934 +++ linux-3.9.4-vs2.3.6.1/net/ipv4/udp.c 2013-05-31 18:26:00.000000000 +0000
24935 @@ -306,14 +306,7 @@ fail:
24937 EXPORT_SYMBOL(udp_lib_get_port);
24939 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24941 - struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24943 - return (!ipv6_only_sock(sk2) &&
24944 - (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24945 - inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24947 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24949 static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24951 @@ -348,6 +341,11 @@ static inline int compute_score(struct s
24952 if (inet->inet_rcv_saddr != daddr)
24956 + /* block non nx_info ips */
24957 + if (!v4_addr_in_nx_info(sk->sk_nx_info,
24958 + daddr, NXA_MASK_BIND))
24961 if (inet->inet_daddr) {
24962 if (inet->inet_daddr != saddr)
24963 @@ -458,6 +456,7 @@ begin:
24968 /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24969 * harder than this. -DaveM
24971 @@ -504,6 +503,11 @@ begin:
24972 sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24973 score = compute_score(sk, net, saddr, hnum, sport,
24974 daddr, dport, dif);
24975 + /* FIXME: disabled?
24976 + if (score == 9) {
24980 if (score > badness) {
24983 @@ -528,6 +532,7 @@ begin:
24984 if (get_nulls_value(node) != slot)
24989 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24991 @@ -537,6 +542,7 @@ begin:
24999 @@ -580,8 +586,7 @@ static inline struct sock *udp_v4_mcast_
25000 udp_sk(s)->udp_port_hash != hnum ||
25001 (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25002 (inet->inet_dport != rmt_port && inet->inet_dport) ||
25003 - (inet->inet_rcv_saddr &&
25004 - inet->inet_rcv_saddr != loc_addr) ||
25005 + !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25006 ipv6_only_sock(s) ||
25007 (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25009 @@ -964,6 +969,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25010 inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25011 faddr, saddr, dport, inet->inet_sport);
25013 + if (sk->sk_nx_info) {
25014 + rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25015 + if (IS_ERR(rt)) {
25016 + err = PTR_ERR(rt);
25023 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25024 rt = ip_route_output_flow(net, fl4, sk);
25026 @@ -1269,7 +1284,8 @@ try_again:
25028 sin->sin_family = AF_INET;
25029 sin->sin_port = udp_hdr(skb)->source;
25030 - sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25031 + sin->sin_addr.s_addr = nx_map_sock_lback(
25032 + skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25033 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25035 if (inet->cmsg_flags)
25036 @@ -2025,6 +2041,8 @@ static struct sock *udp_get_first(struct
25037 sk_nulls_for_each(sk, node, &hslot->head) {
25038 if (!net_eq(sock_net(sk), net))
25040 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25042 if (sk->sk_family == state->family)
25045 @@ -2042,7 +2060,9 @@ static struct sock *udp_get_next(struct
25048 sk = sk_nulls_next(sk);
25049 - } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25050 + } while (sk && (!net_eq(sock_net(sk), net) ||
25051 + sk->sk_family != state->family ||
25052 + !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25055 if (state->bucket <= state->udp_table->mask)
25056 @@ -2138,8 +2158,8 @@ static void udp4_format_sock(struct sock
25057 int bucket, int *len)
25059 struct inet_sock *inet = inet_sk(sp);
25060 - __be32 dest = inet->inet_daddr;
25061 - __be32 src = inet->inet_rcv_saddr;
25062 + __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25063 + __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25064 __u16 destp = ntohs(inet->inet_dport);
25065 __u16 srcp = ntohs(inet->inet_sport);
25067 diff -NurpP --minimal linux-3.9.4/net/ipv6/Kconfig linux-3.9.4-vs2.3.6.1/net/ipv6/Kconfig
25068 --- linux-3.9.4/net/ipv6/Kconfig 2013-05-31 13:45:32.000000000 +0000
25069 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/Kconfig 2013-05-31 17:17:54.000000000 +0000
25072 # IPv6 as module will cause a CRASH if you try to unload it
25074 - tristate "The IPv6 protocol"
25076 + bool "The IPv6 protocol"
25079 This is complemental support for the IP version 6.
25080 You will still be able to do traditional IPv4 networking as well.
25081 diff -NurpP --minimal linux-3.9.4/net/ipv6/addrconf.c linux-3.9.4-vs2.3.6.1/net/ipv6/addrconf.c
25082 --- linux-3.9.4/net/ipv6/addrconf.c 2013-05-31 13:45:32.000000000 +0000
25083 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/addrconf.c 2013-05-31 20:07:39.000000000 +0000
25085 #include <linux/proc_fs.h>
25086 #include <linux/seq_file.h>
25087 #include <linux/export.h>
25088 +#include <linux/vs_network.h>
25089 +#include <linux/vs_inet6.h>
25091 /* Set to 3 to get tracing... */
25092 #define ACONF_DEBUG 2
25093 @@ -1250,7 +1252,7 @@ out:
25095 int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
25096 const struct in6_addr *daddr, unsigned int prefs,
25097 - struct in6_addr *saddr)
25098 + struct in6_addr *saddr, struct nx_info *nxi)
25100 struct ipv6_saddr_score scores[2],
25101 *score = &scores[0], *hiscore = &scores[1];
25102 @@ -1322,6 +1324,8 @@ int ipv6_dev_get_saddr(struct net *net,
25106 + if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25110 bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25111 @@ -3311,7 +3315,10 @@ static void if6_seq_stop(struct seq_file
25112 static int if6_seq_show(struct seq_file *seq, void *v)
25114 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25115 - seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25117 + if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25118 + v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25119 + seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25121 ifp->idev->dev->ifindex,
25123 @@ -3815,6 +3822,11 @@ static int in6_dump_addrs(struct inet6_d
25124 struct ifacaddr6 *ifaca;
25126 int ip_idx = *p_ip_idx;
25127 + struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25129 + /* disable ipv6 on non v6 guests */
25130 + if (nxi && !nx_info_has_v6(nxi))
25133 read_lock_bh(&idev->lock);
25135 @@ -3825,6 +3837,8 @@ static int in6_dump_addrs(struct inet6_d
25136 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25137 if (++ip_idx < s_ip_idx)
25139 + if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25141 err = inet6_fill_ifaddr(skb, ifa,
25142 NETLINK_CB(cb->skb).portid,
25143 cb->nlh->nlmsg_seq,
25144 @@ -3841,6 +3855,8 @@ static int in6_dump_addrs(struct inet6_d
25145 ifmca = ifmca->next, ip_idx++) {
25146 if (ip_idx < s_ip_idx)
25148 + if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25150 err = inet6_fill_ifmcaddr(skb, ifmca,
25151 NETLINK_CB(cb->skb).portid,
25152 cb->nlh->nlmsg_seq,
25153 @@ -3856,6 +3872,8 @@ static int in6_dump_addrs(struct inet6_d
25154 ifaca = ifaca->aca_next, ip_idx++) {
25155 if (ip_idx < s_ip_idx)
25157 + if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25159 err = inet6_fill_ifacaddr(skb, ifaca,
25160 NETLINK_CB(cb->skb).portid,
25161 cb->nlh->nlmsg_seq,
25162 @@ -3884,6 +3902,10 @@ static int inet6_dump_addr(struct sk_buf
25163 struct inet6_dev *idev;
25164 struct hlist_head *head;
25166 + /* FIXME: maybe disable ipv6 on non v6 guests?
25167 + if (skb->sk && skb->sk->sk_vx_info)
25168 + return skb->len; */
25171 s_idx = idx = cb->args[1];
25172 s_ip_idx = ip_idx = cb->args[2];
25173 @@ -4238,6 +4260,7 @@ static int inet6_dump_ifinfo(struct sk_b
25174 struct net_device *dev;
25175 struct inet6_dev *idev;
25176 struct hlist_head *head;
25177 + struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25180 s_idx = cb->args[1];
25181 @@ -4249,6 +4272,8 @@ static int inet6_dump_ifinfo(struct sk_b
25182 hlist_for_each_entry_rcu(dev, head, index_hlist) {
25185 + if (!v6_dev_in_nx_info(dev, nxi))
25187 idev = __in6_dev_get(dev);
25190 diff -NurpP --minimal linux-3.9.4/net/ipv6/af_inet6.c linux-3.9.4-vs2.3.6.1/net/ipv6/af_inet6.c
25191 --- linux-3.9.4/net/ipv6/af_inet6.c 2013-05-31 13:45:32.000000000 +0000
25192 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/af_inet6.c 2013-05-31 20:04:41.000000000 +0000
25194 #include <linux/netdevice.h>
25195 #include <linux/icmpv6.h>
25196 #include <linux/netfilter_ipv6.h>
25197 +#include <linux/vs_inet.h>
25198 +#include <linux/vs_inet6.h>
25200 #include <net/ip.h>
25201 #include <net/ipv6.h>
25202 @@ -160,10 +162,13 @@ lookup_protocol:
25206 + if ((protocol == IPPROTO_ICMPV6) &&
25207 + nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25209 if (sock->type == SOCK_RAW && !kern &&
25210 !ns_capable(net->user_ns, CAP_NET_RAW))
25211 goto out_rcu_unlock;
25214 sock->ops = answer->ops;
25215 answer_prot = answer->prot;
25216 answer_no_check = answer->no_check;
25217 @@ -263,6 +268,7 @@ int inet6_bind(struct socket *sock, stru
25218 struct inet_sock *inet = inet_sk(sk);
25219 struct ipv6_pinfo *np = inet6_sk(sk);
25220 struct net *net = sock_net(sk);
25221 + struct nx_v6_sock_addr nsa;
25223 unsigned short snum;
25225 @@ -278,6 +284,10 @@ int inet6_bind(struct socket *sock, stru
25226 if (addr->sin6_family != AF_INET6)
25227 return -EAFNOSUPPORT;
25229 + err = v6_map_sock_addr(inet, addr, &nsa);
25233 addr_type = ipv6_addr_type(&addr->sin6_addr);
25234 if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25236 @@ -309,6 +319,7 @@ int inet6_bind(struct socket *sock, stru
25237 /* Reproduce AF_INET checks to make the bindings consistent */
25238 v4addr = addr->sin6_addr.s6_addr32[3];
25239 chk_addr_ret = inet_addr_type(net, v4addr);
25241 if (!sysctl_ip_nonlocal_bind &&
25242 !(inet->freebind || inet->transparent) &&
25243 v4addr != htonl(INADDR_ANY) &&
25244 @@ -318,6 +329,10 @@ int inet6_bind(struct socket *sock, stru
25245 err = -EADDRNOTAVAIL;
25248 + if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25249 + err = -EADDRNOTAVAIL;
25253 if (addr_type != IPV6_ADDR_ANY) {
25254 struct net_device *dev = NULL;
25255 @@ -344,6 +359,11 @@ int inet6_bind(struct socket *sock, stru
25259 + if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25260 + err = -EADDRNOTAVAIL;
25264 /* ipv4 addr of the socket is invalid. Only the
25265 * unspecified and mapped address have a v4 equivalent.
25267 @@ -360,6 +380,9 @@ int inet6_bind(struct socket *sock, stru
25271 + /* what's that for? */
25272 + v6_set_sock_addr(inet, &nsa);
25274 inet->inet_rcv_saddr = v4addr;
25275 inet->inet_saddr = v4addr;
25277 @@ -461,9 +484,11 @@ int inet6_getname(struct socket *sock, s
25279 sin->sin6_port = inet->inet_dport;
25280 sin->sin6_addr = np->daddr;
25281 + /* FIXME: remap lback? */
25283 sin->sin6_flowinfo = np->flow_label;
25285 + /* FIXME: remap lback? */
25286 if (ipv6_addr_any(&np->rcv_saddr))
25287 sin->sin6_addr = np->saddr;
25289 diff -NurpP --minimal linux-3.9.4/net/ipv6/datagram.c linux-3.9.4-vs2.3.6.1/net/ipv6/datagram.c
25290 --- linux-3.9.4/net/ipv6/datagram.c 2013-05-31 13:45:32.000000000 +0000
25291 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/datagram.c 2013-05-31 17:17:54.000000000 +0000
25292 @@ -648,7 +648,7 @@ int ip6_datagram_send_ctl(struct net *ne
25295 if (fl6->flowi6_oif) {
25296 - dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25297 + dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25301 diff -NurpP --minimal linux-3.9.4/net/ipv6/fib6_rules.c linux-3.9.4-vs2.3.6.1/net/ipv6/fib6_rules.c
25302 --- linux-3.9.4/net/ipv6/fib6_rules.c 2013-02-19 13:58:58.000000000 +0000
25303 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/fib6_rules.c 2013-05-31 17:17:54.000000000 +0000
25304 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25305 ip6_dst_idev(&rt->dst)->dev,
25307 rt6_flags2srcprefs(flags),
25311 if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25313 diff -NurpP --minimal linux-3.9.4/net/ipv6/inet6_hashtables.c linux-3.9.4-vs2.3.6.1/net/ipv6/inet6_hashtables.c
25314 --- linux-3.9.4/net/ipv6/inet6_hashtables.c 2013-05-31 13:45:32.000000000 +0000
25315 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/inet6_hashtables.c 2013-05-31 17:17:54.000000000 +0000
25318 #include <linux/module.h>
25319 #include <linux/random.h>
25320 +#include <linux/vs_inet6.h>
25322 #include <net/inet_connection_sock.h>
25323 #include <net/inet_hashtables.h>
25324 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25325 unsigned int slot = hash & hashinfo->ehash_mask;
25326 struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25331 sk_nulls_for_each_rcu(sk, node, &head->chain) {
25332 @@ -97,7 +97,7 @@ begin:
25340 if (get_nulls_value(node) != slot)
25341 @@ -147,6 +147,9 @@ static inline int compute_score(struct s
25342 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25346 + if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25349 if (sk->sk_bound_dev_if) {
25350 if (sk->sk_bound_dev_if != dif)
25351 diff -NurpP --minimal linux-3.9.4/net/ipv6/ip6_output.c linux-3.9.4-vs2.3.6.1/net/ipv6/ip6_output.c
25352 --- linux-3.9.4/net/ipv6/ip6_output.c 2013-05-31 13:45:32.000000000 +0000
25353 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/ip6_output.c 2013-05-31 17:17:54.000000000 +0000
25354 @@ -877,7 +877,8 @@ static int ip6_dst_lookup_tail(struct so
25355 struct rt6_info *rt = (struct rt6_info *) *dst;
25356 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25357 sk ? inet6_sk(sk)->srcprefs : 0,
25360 + sk ? sk->sk_nx_info : NULL);
25362 goto out_err_release;
25364 diff -NurpP --minimal linux-3.9.4/net/ipv6/ndisc.c linux-3.9.4-vs2.3.6.1/net/ipv6/ndisc.c
25365 --- linux-3.9.4/net/ipv6/ndisc.c 2013-05-31 13:45:32.000000000 +0000
25366 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/ndisc.c 2013-05-31 17:17:54.000000000 +0000
25367 @@ -485,7 +485,7 @@ static void ndisc_send_na(struct net_dev
25369 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25370 inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25374 src_addr = &tmpaddr;
25376 diff -NurpP --minimal linux-3.9.4/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.9.4-vs2.3.6.1/net/ipv6/netfilter/ip6t_MASQUERADE.c
25377 --- linux-3.9.4/net/ipv6/netfilter/ip6t_MASQUERADE.c 2012-12-11 03:30:57.000000000 +0000
25378 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/netfilter/ip6t_MASQUERADE.c 2013-05-31 17:17:54.000000000 +0000
25379 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
25380 ctinfo == IP_CT_RELATED_REPLY));
25382 if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
25383 - &ipv6_hdr(skb)->daddr, 0, &src) < 0)
25384 + &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
25387 nfct_nat(ct)->masq_index = par->out->ifindex;
25388 diff -NurpP --minimal linux-3.9.4/net/ipv6/raw.c linux-3.9.4-vs2.3.6.1/net/ipv6/raw.c
25389 --- linux-3.9.4/net/ipv6/raw.c 2013-05-31 13:45:32.000000000 +0000
25390 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/raw.c 2013-05-31 17:17:54.000000000 +0000
25392 #include <linux/icmpv6.h>
25393 #include <linux/netfilter.h>
25394 #include <linux/netfilter_ipv6.h>
25395 +#include <linux/vs_inet6.h>
25396 #include <linux/skbuff.h>
25397 #include <linux/compat.h>
25398 #include <asm/uaccess.h>
25399 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
25403 + if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25404 + err = -EADDRNOTAVAIL;
25410 /* ipv4 addr of the socket is invalid. Only the
25411 * unspecified and mapped address have a v4 equivalent.
25413 diff -NurpP --minimal linux-3.9.4/net/ipv6/route.c linux-3.9.4-vs2.3.6.1/net/ipv6/route.c
25414 --- linux-3.9.4/net/ipv6/route.c 2013-05-31 13:45:32.000000000 +0000
25415 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/route.c 2013-05-31 18:10:38.000000000 +0000
25417 #include <net/netevent.h>
25418 #include <net/netlink.h>
25419 #include <net/nexthop.h>
25420 +#include <linux/vs_inet6.h>
25422 #include <asm/uaccess.h>
25424 @@ -2079,15 +2080,17 @@ int ip6_route_get_saddr(struct net *net,
25425 struct rt6_info *rt,
25426 const struct in6_addr *daddr,
25427 unsigned int prefs,
25428 - struct in6_addr *saddr)
25429 + struct in6_addr *saddr,
25430 + struct nx_info *nxi)
25432 struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25434 - if (rt->rt6i_prefsrc.plen)
25435 + if (rt->rt6i_prefsrc.plen && (!nxi ||
25436 + v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25437 *saddr = rt->rt6i_prefsrc.addr;
25439 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25440 - daddr, prefs, saddr);
25441 + daddr, prefs, saddr, nxi);
25445 @@ -2507,7 +2510,8 @@ static int rt6_fill_node(struct net *net
25446 goto nla_put_failure;
25448 struct in6_addr saddr_buf;
25449 - if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25450 + if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25451 + (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25452 nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25453 goto nla_put_failure;
25455 @@ -2719,6 +2723,7 @@ static int rt6_info_route(struct rt6_inf
25457 struct seq_file *m = p_arg;
25459 + /* FIXME: check for network context? */
25460 seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25462 #ifdef CONFIG_IPV6_SUBTREES
25463 diff -NurpP --minimal linux-3.9.4/net/ipv6/tcp_ipv6.c linux-3.9.4-vs2.3.6.1/net/ipv6/tcp_ipv6.c
25464 --- linux-3.9.4/net/ipv6/tcp_ipv6.c 2013-05-31 14:22:27.000000000 +0000
25465 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/tcp_ipv6.c 2013-05-31 17:17:54.000000000 +0000
25468 #include <linux/crypto.h>
25469 #include <linux/scatterlist.h>
25470 +#include <linux/vs_inet6.h>
25472 static void tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25473 static void tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25474 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
25475 * connect() to INADDR_ANY means loopback (BSD'ism).
25478 - if(ipv6_addr_any(&usin->sin6_addr))
25479 - usin->sin6_addr.s6_addr[15] = 0x1;
25480 + if(ipv6_addr_any(&usin->sin6_addr)) {
25481 + struct nx_info *nxi = sk->sk_nx_info;
25483 + if (nxi && nx_info_has_v6(nxi))
25484 + /* FIXME: remap lback? */
25485 + usin->sin6_addr = nxi->v6.ip;
25487 + usin->sin6_addr.s6_addr[15] = 0x1;
25490 addr_type = ipv6_addr_type(&usin->sin6_addr);
25492 diff -NurpP --minimal linux-3.9.4/net/ipv6/udp.c linux-3.9.4-vs2.3.6.1/net/ipv6/udp.c
25493 --- linux-3.9.4/net/ipv6/udp.c 2013-05-31 14:22:27.000000000 +0000
25494 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/udp.c 2013-05-31 18:16:01.000000000 +0000
25495 @@ -46,42 +46,68 @@
25496 #include <net/ip6_checksum.h>
25497 #include <net/xfrm.h>
25498 #include <net/inet6_hashtables.h>
25499 +#include <linux/vs_inet6.h>
25501 #include <linux/proc_fs.h>
25502 #include <linux/seq_file.h>
25503 #include <trace/events/skb.h>
25504 #include "udp_impl.h"
25506 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25507 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25509 - const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25510 + const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25511 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25512 - __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25513 + __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25514 __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25515 - int sk_ipv6only = ipv6_only_sock(sk);
25516 + int sk1_ipv6only = ipv6_only_sock(sk1);
25517 int sk2_ipv6only = inet_v6_ipv6only(sk2);
25518 - int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25519 + int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25520 int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25522 /* if both are mapped, treat as IPv4 */
25523 - if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25524 - return (!sk2_ipv6only &&
25525 + if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25526 + if (!sk2_ipv6only &&
25527 (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25528 - sk1_rcv_saddr == sk2_rcv_saddr));
25529 + sk1_rcv_saddr == sk2_rcv_saddr))
25535 if (addr_type2 == IPV6_ADDR_ANY &&
25536 !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25540 if (addr_type == IPV6_ADDR_ANY &&
25541 - !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25543 + !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25546 if (sk2_rcv_saddr6 &&
25547 - ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25549 + ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25555 + if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25556 + return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25557 + if (!sk2_rcv_saddr)
25558 + return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25559 + if (!sk1_rcv_saddr)
25560 + return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25563 + if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25564 + return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25565 + else if (addr_type2 == IPV6_ADDR_ANY)
25566 + return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25567 + else if (addr_type == IPV6_ADDR_ANY) {
25568 + if (addr_type2 == IPV6_ADDR_MAPPED)
25569 + return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25571 + return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25576 static unsigned int udp6_portaddr_hash(struct net *net,
25577 @@ -145,6 +171,10 @@ static inline int compute_score(struct s
25578 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25582 + /* block non nx_info ips */
25583 + if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25586 if (!ipv6_addr_any(&np->daddr)) {
25587 if (!ipv6_addr_equal(&np->daddr, saddr))
25588 diff -NurpP --minimal linux-3.9.4/net/ipv6/xfrm6_policy.c linux-3.9.4-vs2.3.6.1/net/ipv6/xfrm6_policy.c
25589 --- linux-3.9.4/net/ipv6/xfrm6_policy.c 2013-05-31 14:22:27.000000000 +0000
25590 +++ linux-3.9.4-vs2.3.6.1/net/ipv6/xfrm6_policy.c 2013-05-31 17:17:54.000000000 +0000
25591 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25592 dev = ip6_dst_idev(dst)->dev;
25593 ipv6_dev_get_saddr(dev_net(dev), dev,
25594 (struct in6_addr *)&daddr->a6, 0,
25595 - (struct in6_addr *)&saddr->a6);
25596 + (struct in6_addr *)&saddr->a6, NULL);
25600 diff -NurpP --minimal linux-3.9.4/net/netfilter/ipvs/ip_vs_xmit.c linux-3.9.4-vs2.3.6.1/net/netfilter/ipvs/ip_vs_xmit.c
25601 --- linux-3.9.4/net/netfilter/ipvs/ip_vs_xmit.c 2013-02-19 13:58:59.000000000 +0000
25602 +++ linux-3.9.4-vs2.3.6.1/net/netfilter/ipvs/ip_vs_xmit.c 2013-05-31 17:17:54.000000000 +0000
25603 @@ -273,7 +273,7 @@ __ip_vs_route_output_v6(struct net *net,
25605 if (ipv6_addr_any(&fl6.saddr) &&
25606 ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25607 - &fl6.daddr, 0, &fl6.saddr) < 0)
25608 + &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25611 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25612 diff -NurpP --minimal linux-3.9.4/net/netlink/af_netlink.c linux-3.9.4-vs2.3.6.1/net/netlink/af_netlink.c
25613 --- linux-3.9.4/net/netlink/af_netlink.c 2013-05-31 13:45:33.000000000 +0000
25614 +++ linux-3.9.4-vs2.3.6.1/net/netlink/af_netlink.c 2013-05-31 17:17:54.000000000 +0000
25616 #include <linux/types.h>
25617 #include <linux/audit.h>
25618 #include <linux/mutex.h>
25619 +#include <linux/vs_context.h>
25620 +#include <linux/vs_network.h>
25621 +#include <linux/vs_limit.h>
25623 #include <net/net_namespace.h>
25624 #include <net/sock.h>
25625 @@ -1976,6 +1979,8 @@ static struct sock *netlink_seq_socket_i
25626 sk_for_each(s, &hash->table[j]) {
25627 if (sock_net(s) != seq_file_net(seq))
25629 + if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25633 iter->hash_idx = j;
25634 @@ -2010,7 +2015,8 @@ static void *netlink_seq_next(struct seq
25638 - } while (s && sock_net(s) != seq_file_net(seq));
25639 + } while (s && (sock_net(s) != seq_file_net(seq) ||
25640 + !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25644 @@ -2022,7 +2028,8 @@ static void *netlink_seq_next(struct seq
25646 for (; j <= hash->mask; j++) {
25647 s = sk_head(&hash->table[j]);
25648 - while (s && sock_net(s) != seq_file_net(seq))
25649 + while (s && (sock_net(s) != seq_file_net(seq) ||
25650 + !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25654 diff -NurpP --minimal linux-3.9.4/net/socket.c linux-3.9.4-vs2.3.6.1/net/socket.c
25655 --- linux-3.9.4/net/socket.c 2013-05-31 13:45:33.000000000 +0000
25656 +++ linux-3.9.4-vs2.3.6.1/net/socket.c 2013-05-31 17:17:54.000000000 +0000
25659 #include <net/sock.h>
25660 #include <linux/netfilter.h>
25661 +#include <linux/vs_base.h>
25662 +#include <linux/vs_socket.h>
25663 +#include <linux/vs_inet.h>
25664 +#include <linux/vs_inet6.h>
25666 #include <linux/if_tun.h>
25667 #include <linux/ipv6_route.h>
25668 @@ -617,13 +621,29 @@ static inline int __sock_sendmsg_nosec(s
25669 struct msghdr *msg, size_t size)
25671 struct sock_iocb *si = kiocb_to_siocb(iocb);
25679 - return sock->ops->sendmsg(iocb, sock, msg, size);
25680 + len = sock->ops->sendmsg(iocb, sock, msg, size);
25683 + vx_sock_send(sock->sk, size);
25685 + vx_sock_fail(sock->sk, size);
25687 + vxdprintk(VXD_CBIT(net, 7),
25688 + "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25690 + (sock->sk)?sock->sk->sk_nx_info:0,
25691 + (sock->sk)?sock->sk->sk_vx_info:0,
25692 + (sock->sk)?sock->sk->sk_xid:0,
25693 + (sock->sk)?sock->sk->sk_nid:0,
25694 + (unsigned int)size, len);
25698 static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25699 @@ -779,6 +799,7 @@ static inline int __sock_recvmsg_nosec(s
25700 struct msghdr *msg, size_t size, int flags)
25702 struct sock_iocb *si = kiocb_to_siocb(iocb);
25707 @@ -786,7 +807,18 @@ static inline int __sock_recvmsg_nosec(s
25711 - return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25712 + len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25713 + if ((len >= 0) && sock->sk)
25714 + vx_sock_recv(sock->sk, len);
25715 + vxdprintk(VXD_CBIT(net, 7),
25716 + "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25718 + (sock->sk)?sock->sk->sk_nx_info:0,
25719 + (sock->sk)?sock->sk->sk_vx_info:0,
25720 + (sock->sk)?sock->sk->sk_xid:0,
25721 + (sock->sk)?sock->sk->sk_nid:0,
25722 + (unsigned int)size, len);
25726 static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25727 @@ -1269,6 +1301,13 @@ int __sock_create(struct net *net, int f
25728 if (type < 0 || type >= SOCK_MAX)
25731 + if (!nx_check(0, VS_ADMIN)) {
25732 + if (family == PF_INET && !current_nx_info_has_v4())
25733 + return -EAFNOSUPPORT;
25734 + if (family == PF_INET6 && !current_nx_info_has_v6())
25735 + return -EAFNOSUPPORT;
25740 This uglymoron is moved from INET layer to here to avoid
25741 @@ -1403,6 +1442,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25745 + set_bit(SOCK_USER_SOCKET, &sock->flags);
25746 retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25749 @@ -1444,10 +1484,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25750 err = sock_create(family, type, protocol, &sock1);
25753 + set_bit(SOCK_USER_SOCKET, &sock1->flags);
25755 err = sock_create(family, type, protocol, &sock2);
25757 goto out_release_1;
25758 + set_bit(SOCK_USER_SOCKET, &sock2->flags);
25760 err = sock1->ops->socketpair(sock1, sock2);
25762 diff -NurpP --minimal linux-3.9.4/net/sunrpc/auth.c linux-3.9.4-vs2.3.6.1/net/sunrpc/auth.c
25763 --- linux-3.9.4/net/sunrpc/auth.c 2013-05-31 13:45:33.000000000 +0000
25764 +++ linux-3.9.4-vs2.3.6.1/net/sunrpc/auth.c 2013-05-31 18:01:00.000000000 +0000
25766 #include <linux/sunrpc/clnt.h>
25767 #include <linux/sunrpc/gss_api.h>
25768 #include <linux/spinlock.h>
25769 +#include <linux/vs_tag.h>
25772 # define RPCDBG_FACILITY RPCDBG_AUTH
25773 @@ -480,6 +481,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25774 memset(&acred, 0, sizeof(acred));
25775 acred.uid = cred->fsuid;
25776 acred.gid = cred->fsgid;
25777 + acred.tag = dx_current_tag();
25778 acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25780 ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25781 @@ -520,6 +522,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25782 struct auth_cred acred = {
25783 .uid = GLOBAL_ROOT_UID,
25784 .gid = GLOBAL_ROOT_GID,
25785 + .tag = dx_current_tag(),
25788 dprintk("RPC: %5u looking up %s cred\n",
25789 diff -NurpP --minimal linux-3.9.4/net/sunrpc/auth_unix.c linux-3.9.4-vs2.3.6.1/net/sunrpc/auth_unix.c
25790 --- linux-3.9.4/net/sunrpc/auth_unix.c 2013-05-31 13:45:33.000000000 +0000
25791 +++ linux-3.9.4-vs2.3.6.1/net/sunrpc/auth_unix.c 2013-05-31 18:05:54.000000000 +0000
25792 @@ -13,11 +13,13 @@
25793 #include <linux/sunrpc/clnt.h>
25794 #include <linux/sunrpc/auth.h>
25795 #include <linux/user_namespace.h>
25796 +#include <linux/vs_tag.h>
25798 #define NFS_NGROUPS 16
25801 struct rpc_cred uc_base;
25804 kgid_t uc_gids[NFS_NGROUPS];
25806 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25807 groups = NFS_NGROUPS;
25809 cred->uc_gid = acred->gid;
25810 + cred->uc_tag = acred->tag;
25811 for (i = 0; i < groups; i++)
25812 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25813 if (i < NFS_NGROUPS)
25814 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25818 - if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25819 + if (!uid_eq(cred->uc_uid, acred->uid) ||
25820 + !gid_eq(cred->uc_gid, acred->gid) ||
25821 + !tag_eq(cred->uc_tag, acred->tag))
25824 if (acred->group_info != NULL)
25825 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25826 struct rpc_clnt *clnt = task->tk_client;
25827 struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25828 __be32 *base, *hold;
25832 *p++ = htonl(RPC_AUTH_UNIX);
25834 @@ -157,8 +162,13 @@ unx_marshal(struct rpc_task *task, __be3
25836 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25838 - *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25839 - *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25840 + tag = task->tk_client->cl_tag;
25841 + *p++ = htonl((u32) TAGINO_UID(tag,
25842 + from_kuid(&init_user_ns, cred->uc_uid),
25843 + from_ktag(&init_user_ns, cred->uc_tag)));
25844 + *p++ = htonl((u32) TAGINO_GID(tag,
25845 + from_kgid(&init_user_ns, cred->uc_gid),
25846 + from_ktag(&init_user_ns, cred->uc_tag)));
25848 for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25849 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25850 diff -NurpP --minimal linux-3.9.4/net/sunrpc/clnt.c linux-3.9.4-vs2.3.6.1/net/sunrpc/clnt.c
25851 --- linux-3.9.4/net/sunrpc/clnt.c 2013-05-31 13:45:33.000000000 +0000
25852 +++ linux-3.9.4-vs2.3.6.1/net/sunrpc/clnt.c 2013-05-31 17:17:54.000000000 +0000
25854 #include <linux/in6.h>
25855 #include <linux/un.h>
25856 #include <linux/rcupdate.h>
25857 +#include <linux/vs_cvirt.h>
25859 #include <linux/sunrpc/clnt.h>
25860 #include <linux/sunrpc/addr.h>
25861 @@ -482,6 +483,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25862 if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25863 clnt->cl_chatty = 1;
25865 + /* TODO: handle RPC_CLNT_CREATE_TAGGED
25866 + if (args->flags & RPC_CLNT_CREATE_TAGGED)
25867 + clnt->cl_tag = 1; */
25870 EXPORT_SYMBOL_GPL(rpc_create);
25871 diff -NurpP --minimal linux-3.9.4/net/unix/af_unix.c linux-3.9.4-vs2.3.6.1/net/unix/af_unix.c
25872 --- linux-3.9.4/net/unix/af_unix.c 2013-05-31 13:45:33.000000000 +0000
25873 +++ linux-3.9.4-vs2.3.6.1/net/unix/af_unix.c 2013-05-31 17:17:54.000000000 +0000
25874 @@ -114,6 +114,8 @@
25875 #include <linux/mount.h>
25876 #include <net/checksum.h>
25877 #include <linux/security.h>
25878 +#include <linux/vs_context.h>
25879 +#include <linux/vs_limit.h>
25881 struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25882 EXPORT_SYMBOL_GPL(unix_socket_table);
25883 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25884 if (!net_eq(sock_net(s), net))
25887 + if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25889 if (u->addr->len == len &&
25890 !memcmp(u->addr->name, sunname, len))
25892 @@ -2256,6 +2260,8 @@ static struct sock *unix_from_bucket(str
25893 for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25894 if (sock_net(sk) != seq_file_net(seq))
25896 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25898 if (++count == offset)
25901 @@ -2273,6 +2279,8 @@ static struct sock *unix_next_socket(str
25905 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25907 if (sock_net(sk) == seq_file_net(seq))
25910 diff -NurpP --minimal linux-3.9.4/scripts/checksyscalls.sh linux-3.9.4-vs2.3.6.1/scripts/checksyscalls.sh
25911 --- linux-3.9.4/scripts/checksyscalls.sh 2012-12-11 03:30:57.000000000 +0000
25912 +++ linux-3.9.4-vs2.3.6.1/scripts/checksyscalls.sh 2013-05-31 14:47:11.000000000 +0000
25913 @@ -193,7 +193,6 @@ cat << EOF
25914 #define __IGNORE_afs_syscall
25915 #define __IGNORE_getpmsg
25916 #define __IGNORE_putpmsg
25917 -#define __IGNORE_vserver
25921 diff -NurpP --minimal linux-3.9.4/scripts/mod/devicetable-offsets.h linux-3.9.4-vs2.3.6.1/scripts/mod/devicetable-offsets.h
25922 --- linux-3.9.4/scripts/mod/devicetable-offsets.h 1970-01-01 00:00:00.000000000 +0000
25923 +++ linux-3.9.4-vs2.3.6.1/scripts/mod/devicetable-offsets.h 2013-06-01 00:22:25.000000000 +0000
25925 +#ifndef __DEVICEVTABLE_OFFSETS_H__
25926 +#define __DEVICEVTABLE_OFFSETS_H__
25930 + * This file was generated by Kbuild
25934 +#define SIZE_usb_device_id 32 /* sizeof(struct usb_device_id) # */
25935 +#define OFF_usb_device_id_match_flags 0 /* offsetof(struct usb_device_id, match_flags) # */
25936 +#define OFF_usb_device_id_idVendor 2 /* offsetof(struct usb_device_id, idVendor) # */
25937 +#define OFF_usb_device_id_idProduct 4 /* offsetof(struct usb_device_id, idProduct) # */
25938 +#define OFF_usb_device_id_bcdDevice_lo 6 /* offsetof(struct usb_device_id, bcdDevice_lo) # */
25939 +#define OFF_usb_device_id_bcdDevice_hi 8 /* offsetof(struct usb_device_id, bcdDevice_hi) # */
25940 +#define OFF_usb_device_id_bDeviceClass 10 /* offsetof(struct usb_device_id, bDeviceClass) # */
25941 +#define OFF_usb_device_id_bDeviceSubClass 11 /* offsetof(struct usb_device_id, bDeviceSubClass) # */
25942 +#define OFF_usb_device_id_bDeviceProtocol 12 /* offsetof(struct usb_device_id, bDeviceProtocol) # */
25943 +#define OFF_usb_device_id_bInterfaceClass 13 /* offsetof(struct usb_device_id, bInterfaceClass) # */
25944 +#define OFF_usb_device_id_bInterfaceSubClass 14 /* offsetof(struct usb_device_id, bInterfaceSubClass) # */
25945 +#define OFF_usb_device_id_bInterfaceProtocol 15 /* offsetof(struct usb_device_id, bInterfaceProtocol) # */
25946 +#define OFF_usb_device_id_bInterfaceNumber 16 /* offsetof(struct usb_device_id, bInterfaceNumber) # */
25947 +#define SIZE_hid_device_id 24 /* sizeof(struct hid_device_id) # */
25948 +#define OFF_hid_device_id_bus 0 /* offsetof(struct hid_device_id, bus) # */
25949 +#define OFF_hid_device_id_group 2 /* offsetof(struct hid_device_id, group) # */
25950 +#define OFF_hid_device_id_vendor 4 /* offsetof(struct hid_device_id, vendor) # */
25951 +#define OFF_hid_device_id_product 8 /* offsetof(struct hid_device_id, product) # */
25952 +#define SIZE_ieee1394_device_id 32 /* sizeof(struct ieee1394_device_id) # */
25953 +#define OFF_ieee1394_device_id_match_flags 0 /* offsetof(struct ieee1394_device_id, match_flags) # */
25954 +#define OFF_ieee1394_device_id_vendor_id 4 /* offsetof(struct ieee1394_device_id, vendor_id) # */
25955 +#define OFF_ieee1394_device_id_model_id 8 /* offsetof(struct ieee1394_device_id, model_id) # */
25956 +#define OFF_ieee1394_device_id_specifier_id 12 /* offsetof(struct ieee1394_device_id, specifier_id) # */
25957 +#define OFF_ieee1394_device_id_version 16 /* offsetof(struct ieee1394_device_id, version) # */
25958 +#define SIZE_pci_device_id 32 /* sizeof(struct pci_device_id) # */
25959 +#define OFF_pci_device_id_vendor 0 /* offsetof(struct pci_device_id, vendor) # */
25960 +#define OFF_pci_device_id_device 4 /* offsetof(struct pci_device_id, device) # */
25961 +#define OFF_pci_device_id_subvendor 8 /* offsetof(struct pci_device_id, subvendor) # */
25962 +#define OFF_pci_device_id_subdevice 12 /* offsetof(struct pci_device_id, subdevice) # */
25963 +#define OFF_pci_device_id_class 16 /* offsetof(struct pci_device_id, class) # */
25964 +#define OFF_pci_device_id_class_mask 20 /* offsetof(struct pci_device_id, class_mask) # */
25965 +#define SIZE_ccw_device_id 16 /* sizeof(struct ccw_device_id) # */
25966 +#define OFF_ccw_device_id_match_flags 0 /* offsetof(struct ccw_device_id, match_flags) # */
25967 +#define OFF_ccw_device_id_cu_type 2 /* offsetof(struct ccw_device_id, cu_type) # */
25968 +#define OFF_ccw_device_id_cu_model 6 /* offsetof(struct ccw_device_id, cu_model) # */
25969 +#define OFF_ccw_device_id_dev_type 4 /* offsetof(struct ccw_device_id, dev_type) # */
25970 +#define OFF_ccw_device_id_dev_model 7 /* offsetof(struct ccw_device_id, dev_model) # */
25971 +#define SIZE_ap_device_id 16 /* sizeof(struct ap_device_id) # */
25972 +#define OFF_ap_device_id_dev_type 2 /* offsetof(struct ap_device_id, dev_type) # */
25973 +#define SIZE_css_device_id 16 /* sizeof(struct css_device_id) # */
25974 +#define OFF_css_device_id_type 1 /* offsetof(struct css_device_id, type) # */
25975 +#define SIZE_serio_device_id 4 /* sizeof(struct serio_device_id) # */
25976 +#define OFF_serio_device_id_type 0 /* offsetof(struct serio_device_id, type) # */
25977 +#define OFF_serio_device_id_proto 3 /* offsetof(struct serio_device_id, proto) # */
25978 +#define OFF_serio_device_id_id 2 /* offsetof(struct serio_device_id, id) # */
25979 +#define OFF_serio_device_id_extra 1 /* offsetof(struct serio_device_id, extra) # */
25980 +#define SIZE_acpi_device_id 24 /* sizeof(struct acpi_device_id) # */
25981 +#define OFF_acpi_device_id_id 0 /* offsetof(struct acpi_device_id, id) # */
25982 +#define SIZE_pnp_device_id 16 /* sizeof(struct pnp_device_id) # */
25983 +#define OFF_pnp_device_id_id 0 /* offsetof(struct pnp_device_id, id) # */
25984 +#define SIZE_pnp_card_device_id 80 /* sizeof(struct pnp_card_device_id) # */
25985 +#define OFF_pnp_card_device_id_devs 16 /* offsetof(struct pnp_card_device_id, devs) # */
25986 +#define SIZE_pcmcia_device_id 80 /* sizeof(struct pcmcia_device_id) # */
25987 +#define OFF_pcmcia_device_id_match_flags 0 /* offsetof(struct pcmcia_device_id, match_flags) # */
25988 +#define OFF_pcmcia_device_id_manf_id 2 /* offsetof(struct pcmcia_device_id, manf_id) # */
25989 +#define OFF_pcmcia_device_id_card_id 4 /* offsetof(struct pcmcia_device_id, card_id) # */
25990 +#define OFF_pcmcia_device_id_func_id 6 /* offsetof(struct pcmcia_device_id, func_id) # */
25991 +#define OFF_pcmcia_device_id_function 7 /* offsetof(struct pcmcia_device_id, function) # */
25992 +#define OFF_pcmcia_device_id_device_no 8 /* offsetof(struct pcmcia_device_id, device_no) # */
25993 +#define OFF_pcmcia_device_id_prod_id_hash 12 /* offsetof(struct pcmcia_device_id, prod_id_hash) # */
25994 +#define SIZE_of_device_id 200 /* sizeof(struct of_device_id) # */
25995 +#define OFF_of_device_id_name 0 /* offsetof(struct of_device_id, name) # */
25996 +#define OFF_of_device_id_type 32 /* offsetof(struct of_device_id, type) # */
25997 +#define OFF_of_device_id_compatible 64 /* offsetof(struct of_device_id, compatible) # */
25998 +#define SIZE_vio_device_id 64 /* sizeof(struct vio_device_id) # */
25999 +#define OFF_vio_device_id_type 0 /* offsetof(struct vio_device_id, type) # */
26000 +#define OFF_vio_device_id_compat 32 /* offsetof(struct vio_device_id, compat) # */
26001 +#define SIZE_input_device_id 192 /* sizeof(struct input_device_id) # */
26002 +#define OFF_input_device_id_flags 0 /* offsetof(struct input_device_id, flags) # */
26003 +#define OFF_input_device_id_bustype 8 /* offsetof(struct input_device_id, bustype) # */
26004 +#define OFF_input_device_id_vendor 10 /* offsetof(struct input_device_id, vendor) # */
26005 +#define OFF_input_device_id_product 12 /* offsetof(struct input_device_id, product) # */
26006 +#define OFF_input_device_id_version 14 /* offsetof(struct input_device_id, version) # */
26007 +#define OFF_input_device_id_evbit 16 /* offsetof(struct input_device_id, evbit) # */
26008 +#define OFF_input_device_id_keybit 24 /* offsetof(struct input_device_id, keybit) # */
26009 +#define OFF_input_device_id_relbit 120 /* offsetof(struct input_device_id, relbit) # */
26010 +#define OFF_input_device_id_absbit 128 /* offsetof(struct input_device_id, absbit) # */
26011 +#define OFF_input_device_id_mscbit 136 /* offsetof(struct input_device_id, mscbit) # */
26012 +#define OFF_input_device_id_ledbit 144 /* offsetof(struct input_device_id, ledbit) # */
26013 +#define OFF_input_device_id_sndbit 152 /* offsetof(struct input_device_id, sndbit) # */
26014 +#define OFF_input_device_id_ffbit 160 /* offsetof(struct input_device_id, ffbit) # */
26015 +#define OFF_input_device_id_swbit 176 /* offsetof(struct input_device_id, swbit) # */
26016 +#define SIZE_eisa_device_id 16 /* sizeof(struct eisa_device_id) # */
26017 +#define OFF_eisa_device_id_sig 0 /* offsetof(struct eisa_device_id, sig) # */
26018 +#define SIZE_parisc_device_id 8 /* sizeof(struct parisc_device_id) # */
26019 +#define OFF_parisc_device_id_hw_type 0 /* offsetof(struct parisc_device_id, hw_type) # */
26020 +#define OFF_parisc_device_id_hversion 2 /* offsetof(struct parisc_device_id, hversion) # */
26021 +#define OFF_parisc_device_id_hversion_rev 1 /* offsetof(struct parisc_device_id, hversion_rev) # */
26022 +#define OFF_parisc_device_id_sversion 4 /* offsetof(struct parisc_device_id, sversion) # */
26023 +#define SIZE_sdio_device_id 16 /* sizeof(struct sdio_device_id) # */
26024 +#define OFF_sdio_device_id_class 0 /* offsetof(struct sdio_device_id, class) # */
26025 +#define OFF_sdio_device_id_vendor 2 /* offsetof(struct sdio_device_id, vendor) # */
26026 +#define OFF_sdio_device_id_device 4 /* offsetof(struct sdio_device_id, device) # */
26027 +#define SIZE_ssb_device_id 6 /* sizeof(struct ssb_device_id) # */
26028 +#define OFF_ssb_device_id_vendor 0 /* offsetof(struct ssb_device_id, vendor) # */
26029 +#define OFF_ssb_device_id_coreid 2 /* offsetof(struct ssb_device_id, coreid) # */
26030 +#define OFF_ssb_device_id_revision 4 /* offsetof(struct ssb_device_id, revision) # */
26031 +#define SIZE_bcma_device_id 6 /* sizeof(struct bcma_device_id) # */
26032 +#define OFF_bcma_device_id_manuf 0 /* offsetof(struct bcma_device_id, manuf) # */
26033 +#define OFF_bcma_device_id_id 2 /* offsetof(struct bcma_device_id, id) # */
26034 +#define OFF_bcma_device_id_rev 4 /* offsetof(struct bcma_device_id, rev) # */
26035 +#define OFF_bcma_device_id_class 5 /* offsetof(struct bcma_device_id, class) # */
26036 +#define SIZE_virtio_device_id 8 /* sizeof(struct virtio_device_id) # */
26037 +#define OFF_virtio_device_id_device 0 /* offsetof(struct virtio_device_id, device) # */
26038 +#define OFF_virtio_device_id_vendor 4 /* offsetof(struct virtio_device_id, vendor) # */
26039 +#define SIZE_hv_vmbus_device_id 24 /* sizeof(struct hv_vmbus_device_id) # */
26040 +#define OFF_hv_vmbus_device_id_guid 0 /* offsetof(struct hv_vmbus_device_id, guid) # */
26041 +#define SIZE_i2c_device_id 32 /* sizeof(struct i2c_device_id) # */
26042 +#define OFF_i2c_device_id_name 0 /* offsetof(struct i2c_device_id, name) # */
26043 +#define SIZE_spi_device_id 40 /* sizeof(struct spi_device_id) # */
26044 +#define OFF_spi_device_id_name 0 /* offsetof(struct spi_device_id, name) # */
26045 +#define SIZE_dmi_system_id 344 /* sizeof(struct dmi_system_id) # */
26046 +#define OFF_dmi_system_id_matches 16 /* offsetof(struct dmi_system_id, matches) # */
26047 +#define SIZE_platform_device_id 32 /* sizeof(struct platform_device_id) # */
26048 +#define OFF_platform_device_id_name 0 /* offsetof(struct platform_device_id, name) # */
26049 +#define SIZE_mdio_device_id 8 /* sizeof(struct mdio_device_id) # */
26050 +#define OFF_mdio_device_id_phy_id 0 /* offsetof(struct mdio_device_id, phy_id) # */
26051 +#define OFF_mdio_device_id_phy_id_mask 4 /* offsetof(struct mdio_device_id, phy_id_mask) # */
26052 +#define SIZE_zorro_device_id 16 /* sizeof(struct zorro_device_id) # */
26053 +#define OFF_zorro_device_id_id 0 /* offsetof(struct zorro_device_id, id) # */
26054 +#define SIZE_isapnp_device_id 16 /* sizeof(struct isapnp_device_id) # */
26055 +#define OFF_isapnp_device_id_vendor 4 /* offsetof(struct isapnp_device_id, vendor) # */
26056 +#define OFF_isapnp_device_id_function 6 /* offsetof(struct isapnp_device_id, function) # */
26057 +#define SIZE_ipack_device_id 12 /* sizeof(struct ipack_device_id) # */
26058 +#define OFF_ipack_device_id_format 0 /* offsetof(struct ipack_device_id, format) # */
26059 +#define OFF_ipack_device_id_vendor 4 /* offsetof(struct ipack_device_id, vendor) # */
26060 +#define OFF_ipack_device_id_device 8 /* offsetof(struct ipack_device_id, device) # */
26061 +#define SIZE_amba_id 16 /* sizeof(struct amba_id) # */
26062 +#define OFF_amba_id_id 0 /* offsetof(struct amba_id, id) # */
26063 +#define OFF_amba_id_mask 4 /* offsetof(struct amba_id, mask) # */
26064 +#define SIZE_x86_cpu_id 16 /* sizeof(struct x86_cpu_id) # */
26065 +#define OFF_x86_cpu_id_feature 6 /* offsetof(struct x86_cpu_id, feature) # */
26066 +#define OFF_x86_cpu_id_family 2 /* offsetof(struct x86_cpu_id, family) # */
26067 +#define OFF_x86_cpu_id_model 4 /* offsetof(struct x86_cpu_id, model) # */
26068 +#define OFF_x86_cpu_id_vendor 0 /* offsetof(struct x86_cpu_id, vendor) # */
26071 diff -NurpP --minimal linux-3.9.4/security/commoncap.c linux-3.9.4-vs2.3.6.1/security/commoncap.c
26072 --- linux-3.9.4/security/commoncap.c 2013-05-31 13:45:34.000000000 +0000
26073 +++ linux-3.9.4-vs2.3.6.1/security/commoncap.c 2013-05-31 15:07:02.000000000 +0000
26074 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
26075 int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
26076 int cap, int audit)
26078 + struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
26079 struct user_namespace *ns = targ_ns;
26081 /* See if cred has the capability in the target user namespace
26082 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
26085 /* Do we have the necessary capabilities? */
26086 - if (ns == cred->user_ns)
26087 - return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26088 + if (ns == cred->user_ns) {
26089 + if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26090 + cap_raised(cred->cap_effective, cap))
26092 + return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26095 /* Have we tried all of the parent namespaces? */
26096 if (ns == &init_user_ns)
26097 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
26099 if (!strncmp(name, XATTR_SECURITY_PREFIX,
26100 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26101 - !capable(CAP_SYS_ADMIN))
26102 + !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26106 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
26108 if (!strncmp(name, XATTR_SECURITY_PREFIX,
26109 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26110 - !capable(CAP_SYS_ADMIN))
26111 + !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26115 diff -NurpP --minimal linux-3.9.4/security/selinux/hooks.c linux-3.9.4-vs2.3.6.1/security/selinux/hooks.c
26116 --- linux-3.9.4/security/selinux/hooks.c 2013-05-31 13:45:34.000000000 +0000
26117 +++ linux-3.9.4-vs2.3.6.1/security/selinux/hooks.c 2013-05-31 14:47:11.000000000 +0000
26119 #include <linux/dccp.h>
26120 #include <linux/quota.h>
26121 #include <linux/un.h> /* for Unix socket types */
26122 -#include <net/af_unix.h> /* for Unix socket types */
26123 #include <linux/parser.h>
26124 #include <linux/nfs_mount.h>
26125 #include <net/ipv6.h>