1 diff -NurpP --minimal linux-3.9.4/Documentation/vserver/debug.txt linux-3.9.4-vs2.3.6.2/Documentation/vserver/debug.txt
2 --- linux-3.9.4/Documentation/vserver/debug.txt 1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.9.4-vs2.3.6.2/Documentation/vserver/debug.txt 2013-05-31 14:47:10.000000000 +0000
8 + 2 4 "vx_map_tgid: %p/%llx: %d -> %d"
9 + "vx_rmap_tgid: %p/%llx: %d -> %d"
13 + 0 1 "ALLOC (%p,#%d)%c inode (%d)"
14 + "FREE (%p,#%d)%c inode"
15 + 1 2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
16 + "FREE (%p,#%d)%c %lld bytes"
17 + 2 4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
18 + 3 8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
19 + "ext3_has_free_blocks(%p): free=%lu, root=%lu"
20 + "rcu_free_dl_info(%p)"
21 + 4 10 "alloc_dl_info(%p,%d) = %p"
22 + "dealloc_dl_info(%p)"
23 + "get_dl_info(%p[#%d.%d])"
24 + "put_dl_info(%p[#%d.%d])"
25 + 5 20 "alloc_dl_info(%p,%d)*"
26 + 6 40 "__hash_dl_info: %p[#%d]"
27 + "__unhash_dl_info: %p[#%d]"
28 + 7 80 "locate_dl_info(%p,#%d) = %p"
32 + 0 1 "destroy_dqhash: %p [#0x%08x] c=%d"
33 + "new_dqhash: %p [#0x%08x]"
34 + "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
35 + "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
36 + "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
37 + "vroot_get_real_bdev not set"
38 + 1 2 "cow_break_link(»%s«)"
40 + 2 4 "dentry_open(new): %p"
41 + "dentry_open(old): %p"
42 + "lookup_create(new): %p"
44 + "path_lookup(old): %d"
45 + "vfs_create(new): %d"
48 + 3 8 "fput(new_file=%p[#%d])"
49 + "fput(old_file=%p[#%d])"
50 + 4 10 "vx_info_kill(%p[#%d],%d,%d) = %d"
51 + "vx_info_kill(%p[#%d],%d,%d)*"
52 + 5 20 "vs_reboot(%p[#%d],%d)"
53 + 6 40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
57 + 2 4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
58 + 3 8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
59 + "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
60 + 4 10 "ip_route_connect(%p) %p,%p;%lx"
61 + 5 20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
62 + 6 40 "sk,egf: %p [#%d] (from %d)"
63 + "sk,egn: %p [#%d] (from %d)"
64 + "sk,req: %p [#%d] (from %d)"
65 + "sk: %p [#%d] (from %d)"
66 + "tw: %p [#%d] (from %d)"
67 + 7 80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
68 + "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
72 + 0 1 "__lookup_nx_info(#%u): %p[#%u]"
73 + "alloc_nx_info(%d) = %p"
74 + "create_nx_info(%d) (dynamic rejected)"
75 + "create_nx_info(%d) = %p (already there)"
76 + "create_nx_info(%d) = %p (new)"
77 + "dealloc_nx_info(%p)"
78 + 1 2 "alloc_nx_info(%d)*"
79 + "create_nx_info(%d)*"
80 + 2 4 "get_nx_info(%p[#%d.%d])"
81 + "put_nx_info(%p[#%d.%d])"
82 + 3 8 "claim_nx_info(%p[#%d.%d.%d]) %p"
83 + "clr_nx_info(%p[#%d.%d])"
84 + "init_nx_info(%p[#%d.%d])"
85 + "release_nx_info(%p[#%d.%d.%d]) %p"
86 + "set_nx_info(%p[#%d.%d])"
87 + 4 10 "__hash_nx_info: %p[#%d]"
88 + "__nx_dynamic_id: [#%d]"
89 + "__unhash_nx_info: %p[#%d.%d.%d]"
90 + 5 20 "moved task %p into nxi:%p[#%d]"
91 + "nx_migrate_task(%p,%p[#%d.%d.%d])"
92 + "task_get_nx_info(%p)"
93 + 6 40 "nx_clear_persistent(%p[#%d])"
97 + 0 1 "quota_sync_dqh(%p,%d) discard inode %p"
98 + 1 2 "quota_sync_dqh(%p,%d)"
99 + "sync_dquots(%p,%d)"
100 + "sync_dquots_dqh(%p,%d)"
101 + 3 8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
105 + 0 1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
106 + 1 2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
107 + 4 10 "%s: (%s %s) returned %s with %d"
111 + 7 80 "dx_parse_tag(»%s«): %d:#%d"
112 + "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
116 + 0 1 "__lookup_vx_info(#%u): %p[#%u]"
117 + "alloc_vx_info(%d) = %p"
118 + "alloc_vx_info(%d)*"
119 + "create_vx_info(%d) (dynamic rejected)"
120 + "create_vx_info(%d) = %p (already there)"
121 + "create_vx_info(%d) = %p (new)"
122 + "dealloc_vx_info(%p)"
123 + "loc_vx_info(%d) = %p (found)"
124 + "loc_vx_info(%d) = %p (new)"
125 + "loc_vx_info(%d) = %p (not available)"
126 + 1 2 "create_vx_info(%d)*"
128 + 2 4 "get_vx_info(%p[#%d.%d])"
129 + "put_vx_info(%p[#%d.%d])"
130 + 3 8 "claim_vx_info(%p[#%d.%d.%d]) %p"
131 + "clr_vx_info(%p[#%d.%d])"
132 + "init_vx_info(%p[#%d.%d])"
133 + "release_vx_info(%p[#%d.%d.%d]) %p"
134 + "set_vx_info(%p[#%d.%d])"
135 + 4 10 "__hash_vx_info: %p[#%d]"
136 + "__unhash_vx_info: %p[#%d.%d.%d]"
137 + "__vx_dynamic_id: [#%d]"
138 + 5 20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
139 + "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
140 + "moved task %p into vxi:%p[#%d]"
141 + "task_get_vx_info(%p)"
142 + "vx_migrate_task(%p,%p[#%d.%d])"
143 + 6 40 "vx_clear_persistent(%p[#%d])"
144 + "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
145 + "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
146 + "vx_set_persistent(%p[#%d])"
147 + "vx_set_reaper(%p[#%d],%p[#%d,%d])"
148 + 7 80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
153 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
154 + "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
156 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
157 + "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
158 + "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
159 diff -NurpP --minimal linux-3.9.4/arch/alpha/Kconfig linux-3.9.4-vs2.3.6.2/arch/alpha/Kconfig
160 --- linux-3.9.4/arch/alpha/Kconfig 2013-05-31 13:44:28.000000000 +0000
161 +++ linux-3.9.4-vs2.3.6.2/arch/alpha/Kconfig 2013-05-31 14:47:10.000000000 +0000
162 @@ -669,6 +669,8 @@ config DUMMY_CONSOLE
166 +source "kernel/vserver/Kconfig"
168 source "security/Kconfig"
170 source "crypto/Kconfig"
171 diff -NurpP --minimal linux-3.9.4/arch/alpha/kernel/systbls.S linux-3.9.4-vs2.3.6.2/arch/alpha/kernel/systbls.S
172 --- linux-3.9.4/arch/alpha/kernel/systbls.S 2013-02-19 13:56:11.000000000 +0000
173 +++ linux-3.9.4-vs2.3.6.2/arch/alpha/kernel/systbls.S 2013-05-31 14:47:11.000000000 +0000
174 @@ -446,7 +446,7 @@ sys_call_table:
175 .quad sys_stat64 /* 425 */
178 - .quad sys_ni_syscall /* sys_vserver */
179 + .quad sys_vserver /* sys_vserver */
180 .quad sys_ni_syscall /* sys_mbind */
181 .quad sys_ni_syscall /* sys_get_mempolicy */
182 .quad sys_ni_syscall /* sys_set_mempolicy */
183 diff -NurpP --minimal linux-3.9.4/arch/alpha/kernel/traps.c linux-3.9.4-vs2.3.6.2/arch/alpha/kernel/traps.c
184 --- linux-3.9.4/arch/alpha/kernel/traps.c 2013-05-31 13:44:28.000000000 +0000
185 +++ linux-3.9.4-vs2.3.6.2/arch/alpha/kernel/traps.c 2013-05-31 14:47:11.000000000 +0000
186 @@ -184,7 +184,8 @@ die_if_kernel(char * str, struct pt_regs
188 printk("CPU %d ", hard_smp_processor_id());
190 - printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
191 + printk("%s(%d[#%u]): %s %ld\n", current->comm,
192 + task_pid_nr(current), current->xid, str, err);
193 dik_show_regs(regs, r9_15);
194 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
195 dik_show_trace((unsigned long *)(regs+1));
196 diff -NurpP --minimal linux-3.9.4/arch/arm/Kconfig linux-3.9.4-vs2.3.6.2/arch/arm/Kconfig
197 --- linux-3.9.4/arch/arm/Kconfig 2013-05-31 13:44:29.000000000 +0000
198 +++ linux-3.9.4-vs2.3.6.2/arch/arm/Kconfig 2013-05-31 14:47:11.000000000 +0000
199 @@ -2353,6 +2353,8 @@ source "fs/Kconfig"
201 source "arch/arm/Kconfig.debug"
203 +source "kernel/vserver/Kconfig"
205 source "security/Kconfig"
207 source "crypto/Kconfig"
208 diff -NurpP --minimal linux-3.9.4/arch/arm/kernel/calls.S linux-3.9.4-vs2.3.6.2/arch/arm/kernel/calls.S
209 --- linux-3.9.4/arch/arm/kernel/calls.S 2013-05-31 13:44:29.000000000 +0000
210 +++ linux-3.9.4-vs2.3.6.2/arch/arm/kernel/calls.S 2013-05-31 14:47:11.000000000 +0000
212 /* 310 */ CALL(sys_request_key)
214 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
215 -/* vserver */ CALL(sys_ni_syscall)
218 /* 315 */ CALL(sys_ioprio_get)
219 CALL(sys_inotify_init)
220 diff -NurpP --minimal linux-3.9.4/arch/arm/kernel/process.c linux-3.9.4-vs2.3.6.2/arch/arm/kernel/process.c
221 --- linux-3.9.4/arch/arm/kernel/process.c 2013-05-31 13:44:29.000000000 +0000
222 +++ linux-3.9.4-vs2.3.6.2/arch/arm/kernel/process.c 2013-05-31 14:47:11.000000000 +0000
223 @@ -332,7 +332,8 @@ void __show_regs(struct pt_regs *regs)
224 void show_regs(struct pt_regs * regs)
227 - printk("Pid: %d, comm: %20s\n", task_pid_nr(current), current->comm);
228 + printk("Pid: %d[#%u], comm: %20s\n",
229 + task_pid_nr(current), current->xid, current->comm);
233 diff -NurpP --minimal linux-3.9.4/arch/arm/kernel/traps.c linux-3.9.4-vs2.3.6.2/arch/arm/kernel/traps.c
234 --- linux-3.9.4/arch/arm/kernel/traps.c 2013-05-31 13:44:29.000000000 +0000
235 +++ linux-3.9.4-vs2.3.6.2/arch/arm/kernel/traps.c 2013-05-31 14:47:11.000000000 +0000
236 @@ -249,8 +249,8 @@ static int __die(const char *str, int er
240 - printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
241 - TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), end_of_stack(tsk));
242 + printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
243 + TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, end_of_stack(tsk));
245 if (!user_mode(regs) || in_interrupt()) {
246 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
247 diff -NurpP --minimal linux-3.9.4/arch/cris/Kconfig linux-3.9.4-vs2.3.6.2/arch/cris/Kconfig
248 --- linux-3.9.4/arch/cris/Kconfig 2013-05-31 13:44:37.000000000 +0000
249 +++ linux-3.9.4-vs2.3.6.2/arch/cris/Kconfig 2013-05-31 14:47:11.000000000 +0000
250 @@ -674,6 +674,8 @@ source "drivers/staging/Kconfig"
252 source "arch/cris/Kconfig.debug"
254 +source "kernel/vserver/Kconfig"
256 source "security/Kconfig"
258 source "crypto/Kconfig"
259 diff -NurpP --minimal linux-3.9.4/arch/h8300/Kconfig linux-3.9.4-vs2.3.6.2/arch/h8300/Kconfig
260 --- linux-3.9.4/arch/h8300/Kconfig 2013-05-31 13:44:38.000000000 +0000
261 +++ linux-3.9.4-vs2.3.6.2/arch/h8300/Kconfig 2013-05-31 14:47:11.000000000 +0000
262 @@ -221,6 +221,8 @@ source "fs/Kconfig"
264 source "arch/h8300/Kconfig.debug"
266 +source "kernel/vserver/Kconfig"
268 source "security/Kconfig"
270 source "crypto/Kconfig"
271 diff -NurpP --minimal linux-3.9.4/arch/ia64/Kconfig linux-3.9.4-vs2.3.6.2/arch/ia64/Kconfig
272 --- linux-3.9.4/arch/ia64/Kconfig 2013-05-31 13:44:38.000000000 +0000
273 +++ linux-3.9.4-vs2.3.6.2/arch/ia64/Kconfig 2013-05-31 14:47:11.000000000 +0000
274 @@ -645,6 +645,8 @@ source "fs/Kconfig"
276 source "arch/ia64/Kconfig.debug"
278 +source "kernel/vserver/Kconfig"
280 source "security/Kconfig"
282 source "crypto/Kconfig"
283 diff -NurpP --minimal linux-3.9.4/arch/ia64/kernel/entry.S linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/entry.S
284 --- linux-3.9.4/arch/ia64/kernel/entry.S 2013-05-31 13:44:38.000000000 +0000
285 +++ linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/entry.S 2013-05-31 14:47:11.000000000 +0000
286 @@ -1719,7 +1719,7 @@ sys_call_table:
288 data8 sys_mq_getsetattr
290 - data8 sys_ni_syscall // reserved for vserver
292 data8 sys_waitid // 1270
294 data8 sys_request_key
295 diff -NurpP --minimal linux-3.9.4/arch/ia64/kernel/process.c linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/process.c
296 --- linux-3.9.4/arch/ia64/kernel/process.c 2013-05-31 13:44:38.000000000 +0000
297 +++ linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/process.c 2013-05-31 14:47:11.000000000 +0000
298 @@ -109,8 +109,8 @@ show_regs (struct pt_regs *regs)
299 unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
302 - printk("\nPid: %d, CPU %d, comm: %20s\n", task_pid_nr(current),
303 - smp_processor_id(), current->comm);
304 + printk("\nPid: %d[#%u], CPU %d, comm: %20s\n", task_pid_nr(current),
305 + current->xid, smp_processor_id(), current->comm);
306 printk("psr : %016lx ifs : %016lx ip : [<%016lx>] %s (%s)\n",
307 regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
308 init_utsname()->release);
309 diff -NurpP --minimal linux-3.9.4/arch/ia64/kernel/ptrace.c linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/ptrace.c
310 --- linux-3.9.4/arch/ia64/kernel/ptrace.c 2013-02-19 13:56:51.000000000 +0000
311 +++ linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/ptrace.c 2013-05-31 14:47:11.000000000 +0000
313 #include <linux/regset.h>
314 #include <linux/elf.h>
315 #include <linux/tracehook.h>
316 +#include <linux/vs_base.h>
318 #include <asm/pgtable.h>
319 #include <asm/processor.h>
320 diff -NurpP --minimal linux-3.9.4/arch/ia64/kernel/traps.c linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/traps.c
321 --- linux-3.9.4/arch/ia64/kernel/traps.c 2013-05-31 13:44:38.000000000 +0000
322 +++ linux-3.9.4-vs2.3.6.2/arch/ia64/kernel/traps.c 2013-05-31 14:47:11.000000000 +0000
323 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
326 if (++die.lock_owner_depth < 3) {
327 - printk("%s[%d]: %s %ld [%d]\n",
328 - current->comm, task_pid_nr(current), str, err, ++die_counter);
329 + printk("%s[%d[#%u]]: %s %ld [%d]\n",
330 + current->comm, task_pid_nr(current), current->xid,
331 + str, err, ++die_counter);
332 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
335 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
336 if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
337 last.time = current_jiffies + 5 * HZ;
339 - "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
340 - current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
341 + "%s(%d[#%u]): floating-point assist fault at ip %016lx, isr %016lx\n",
342 + current->comm, task_pid_nr(current), current->xid,
343 + regs->cr_iip + ia64_psr(regs)->ri, isr);
347 diff -NurpP --minimal linux-3.9.4/arch/m32r/kernel/traps.c linux-3.9.4-vs2.3.6.2/arch/m32r/kernel/traps.c
348 --- linux-3.9.4/arch/m32r/kernel/traps.c 2012-12-11 03:30:57.000000000 +0000
349 +++ linux-3.9.4-vs2.3.6.2/arch/m32r/kernel/traps.c 2013-05-31 14:47:11.000000000 +0000
350 @@ -195,8 +195,9 @@ static void show_registers(struct pt_reg
352 printk("SPI: %08lx\n", sp);
354 - printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
355 - current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
356 + printk("Process %s (pid: %d[#%u], process nr: %d, stackpage=%08lx)",
357 + current->comm, task_pid_nr(current), current->xid,
358 + 0xffff & i, 4096+(unsigned long)current);
361 * When in-kernel, we also print out the stack and code at the
362 diff -NurpP --minimal linux-3.9.4/arch/m68k/Kconfig linux-3.9.4-vs2.3.6.2/arch/m68k/Kconfig
363 --- linux-3.9.4/arch/m68k/Kconfig 2013-05-31 13:44:38.000000000 +0000
364 +++ linux-3.9.4-vs2.3.6.2/arch/m68k/Kconfig 2013-05-31 14:47:11.000000000 +0000
365 @@ -137,6 +137,8 @@ source "fs/Kconfig"
367 source "arch/m68k/Kconfig.debug"
369 +source "kernel/vserver/Kconfig"
371 source "security/Kconfig"
373 source "crypto/Kconfig"
374 diff -NurpP --minimal linux-3.9.4/arch/mips/Kconfig linux-3.9.4-vs2.3.6.2/arch/mips/Kconfig
375 --- linux-3.9.4/arch/mips/Kconfig 2013-05-31 13:44:39.000000000 +0000
376 +++ linux-3.9.4-vs2.3.6.2/arch/mips/Kconfig 2013-05-31 14:47:11.000000000 +0000
377 @@ -2550,6 +2550,8 @@ source "fs/Kconfig"
379 source "arch/mips/Kconfig.debug"
381 +source "kernel/vserver/Kconfig"
383 source "security/Kconfig"
385 source "crypto/Kconfig"
386 diff -NurpP --minimal linux-3.9.4/arch/mips/kernel/ptrace.c linux-3.9.4-vs2.3.6.2/arch/mips/kernel/ptrace.c
387 --- linux-3.9.4/arch/mips/kernel/ptrace.c 2013-05-31 13:44:42.000000000 +0000
388 +++ linux-3.9.4-vs2.3.6.2/arch/mips/kernel/ptrace.c 2013-05-31 14:47:11.000000000 +0000
390 #include <linux/security.h>
391 #include <linux/audit.h>
392 #include <linux/seccomp.h>
393 +#include <linux/vs_base.h>
395 #include <asm/byteorder.h>
397 @@ -262,6 +263,9 @@ long arch_ptrace(struct task_struct *chi
398 void __user *datavp = (void __user *) data;
399 unsigned long __user *datalp = (void __user *) data;
401 + if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
405 /* when I and D space are separate, these will need to be fixed. */
406 case PTRACE_PEEKTEXT: /* read word at location addr. */
407 diff -NurpP --minimal linux-3.9.4/arch/mips/kernel/scall32-o32.S linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall32-o32.S
408 --- linux-3.9.4/arch/mips/kernel/scall32-o32.S 2013-05-31 13:44:42.000000000 +0000
409 +++ linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall32-o32.S 2013-05-31 14:47:11.000000000 +0000
410 @@ -512,7 +512,7 @@ einval: li v0, -ENOSYS
411 sys sys_mq_timedreceive 5
412 sys sys_mq_notify 2 /* 4275 */
413 sys sys_mq_getsetattr 3
414 - sys sys_ni_syscall 0 /* sys_vserver */
417 sys sys_ni_syscall 0 /* available, was setaltroot */
418 sys sys_add_key 5 /* 4280 */
419 diff -NurpP --minimal linux-3.9.4/arch/mips/kernel/scall64-64.S linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall64-64.S
420 --- linux-3.9.4/arch/mips/kernel/scall64-64.S 2013-05-31 13:44:42.000000000 +0000
421 +++ linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall64-64.S 2013-05-31 14:47:11.000000000 +0000
422 @@ -351,7 +351,7 @@ sys_call_table:
423 PTR sys_mq_timedreceive
425 PTR sys_mq_getsetattr /* 5235 */
426 - PTR sys_ni_syscall /* sys_vserver */
429 PTR sys_ni_syscall /* available, was setaltroot */
431 diff -NurpP --minimal linux-3.9.4/arch/mips/kernel/scall64-n32.S linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall64-n32.S
432 --- linux-3.9.4/arch/mips/kernel/scall64-n32.S 2013-05-31 13:44:42.000000000 +0000
433 +++ linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall64-n32.S 2013-05-31 14:47:11.000000000 +0000
434 @@ -344,7 +344,7 @@ EXPORT(sysn32_call_table)
435 PTR compat_sys_mq_timedreceive
436 PTR compat_sys_mq_notify
437 PTR compat_sys_mq_getsetattr
438 - PTR sys_ni_syscall /* 6240, sys_vserver */
439 + PTR sys32_vserver /* 6240 */
440 PTR compat_sys_waitid
441 PTR sys_ni_syscall /* available, was setaltroot */
443 diff -NurpP --minimal linux-3.9.4/arch/mips/kernel/scall64-o32.S linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall64-o32.S
444 --- linux-3.9.4/arch/mips/kernel/scall64-o32.S 2013-05-31 13:44:42.000000000 +0000
445 +++ linux-3.9.4-vs2.3.6.2/arch/mips/kernel/scall64-o32.S 2013-05-31 15:07:53.000000000 +0000
446 @@ -469,7 +469,7 @@ sys_call_table:
447 PTR compat_sys_mq_timedreceive
448 PTR compat_sys_mq_notify /* 4275 */
449 PTR compat_sys_mq_getsetattr
450 - PTR sys_ni_syscall /* sys_vserver */
452 PTR compat_sys_waitid
453 PTR sys_ni_syscall /* available, was setaltroot */
454 PTR sys_add_key /* 4280 */
455 diff -NurpP --minimal linux-3.9.4/arch/mips/kernel/traps.c linux-3.9.4-vs2.3.6.2/arch/mips/kernel/traps.c
456 --- linux-3.9.4/arch/mips/kernel/traps.c 2013-05-31 13:44:42.000000000 +0000
457 +++ linux-3.9.4-vs2.3.6.2/arch/mips/kernel/traps.c 2013-05-31 14:47:11.000000000 +0000
458 @@ -348,9 +348,10 @@ void show_registers(struct pt_regs *regs
462 - printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
463 - current->comm, current->pid, current_thread_info(), current,
464 - field, current_thread_info()->tp_value);
465 + printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
466 + current->comm, task_pid_nr(current), current->xid,
467 + current_thread_info(), current,
468 + field, current_thread_info()->tp_value);
469 if (cpu_has_userlocal) {
472 diff -NurpP --minimal linux-3.9.4/arch/parisc/Kconfig linux-3.9.4-vs2.3.6.2/arch/parisc/Kconfig
473 --- linux-3.9.4/arch/parisc/Kconfig 2013-05-31 13:44:44.000000000 +0000
474 +++ linux-3.9.4-vs2.3.6.2/arch/parisc/Kconfig 2013-05-31 14:47:11.000000000 +0000
475 @@ -308,6 +308,8 @@ source "fs/Kconfig"
477 source "arch/parisc/Kconfig.debug"
479 +source "kernel/vserver/Kconfig"
481 source "security/Kconfig"
483 source "crypto/Kconfig"
484 diff -NurpP --minimal linux-3.9.4/arch/parisc/kernel/syscall_table.S linux-3.9.4-vs2.3.6.2/arch/parisc/kernel/syscall_table.S
485 --- linux-3.9.4/arch/parisc/kernel/syscall_table.S 2013-05-31 13:44:44.000000000 +0000
486 +++ linux-3.9.4-vs2.3.6.2/arch/parisc/kernel/syscall_table.S 2013-05-31 14:47:11.000000000 +0000
488 ENTRY_COMP(mbind) /* 260 */
489 ENTRY_COMP(get_mempolicy)
490 ENTRY_COMP(set_mempolicy)
491 - ENTRY_SAME(ni_syscall) /* 263: reserved for vserver */
492 + ENTRY_DIFF(vserver)
494 ENTRY_SAME(request_key) /* 265 */
496 diff -NurpP --minimal linux-3.9.4/arch/parisc/kernel/traps.c linux-3.9.4-vs2.3.6.2/arch/parisc/kernel/traps.c
497 --- linux-3.9.4/arch/parisc/kernel/traps.c 2013-05-31 13:44:44.000000000 +0000
498 +++ linux-3.9.4-vs2.3.6.2/arch/parisc/kernel/traps.c 2013-05-31 14:47:11.000000000 +0000
499 @@ -235,8 +235,9 @@ void die_if_kernel(char *str, struct pt_
503 - printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
504 - current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
505 + printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
506 + current->comm, task_pid_nr(current), current->xid,
507 + str, err, regs->iaoq[0]);
508 #ifdef PRINT_USER_FAULTS
509 /* XXX for debugging only */
511 @@ -269,8 +270,8 @@ void die_if_kernel(char *str, struct pt_
512 pdc_console_restart();
515 - printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
516 - current->comm, task_pid_nr(current), str, err);
517 + printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
518 + current->comm, task_pid_nr(current), current->xid, str, err);
520 /* Wot's wrong wif bein' racy? */
521 if (current->thread.flags & PARISC_KERNEL_DEATH) {
522 diff -NurpP --minimal linux-3.9.4/arch/parisc/mm/fault.c linux-3.9.4-vs2.3.6.2/arch/parisc/mm/fault.c
523 --- linux-3.9.4/arch/parisc/mm/fault.c 2013-05-31 13:44:44.000000000 +0000
524 +++ linux-3.9.4-vs2.3.6.2/arch/parisc/mm/fault.c 2013-05-31 14:47:11.000000000 +0000
525 @@ -257,8 +257,9 @@ bad_area:
527 #ifdef PRINT_USER_FAULTS
528 printk(KERN_DEBUG "\n");
529 - printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
530 - task_pid_nr(tsk), tsk->comm, code, address);
531 + printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
532 + "command='%s' type=%lu address=0x%08lx\n",
533 + task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
535 printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
536 vma->vm_start, vma->vm_end);
537 diff -NurpP --minimal linux-3.9.4/arch/powerpc/Kconfig linux-3.9.4-vs2.3.6.2/arch/powerpc/Kconfig
538 --- linux-3.9.4/arch/powerpc/Kconfig 2013-05-31 13:44:44.000000000 +0000
539 +++ linux-3.9.4-vs2.3.6.2/arch/powerpc/Kconfig 2013-05-31 14:47:11.000000000 +0000
540 @@ -1027,6 +1027,8 @@ source "lib/Kconfig"
542 source "arch/powerpc/Kconfig.debug"
544 +source "kernel/vserver/Kconfig"
546 source "security/Kconfig"
549 diff -NurpP --minimal linux-3.9.4/arch/powerpc/include/uapi/asm/unistd.h linux-3.9.4-vs2.3.6.2/arch/powerpc/include/uapi/asm/unistd.h
550 --- linux-3.9.4/arch/powerpc/include/uapi/asm/unistd.h 2013-05-31 13:44:44.000000000 +0000
551 +++ linux-3.9.4-vs2.3.6.2/arch/powerpc/include/uapi/asm/unistd.h 2013-05-31 14:47:11.000000000 +0000
554 #define __NR_rtas 255
555 #define __NR_sys_debug_setcontext 256
556 -/* Number 257 is reserved for vserver */
557 +#define __NR_vserver 257
558 #define __NR_migrate_pages 258
559 #define __NR_mbind 259
560 #define __NR_get_mempolicy 260
561 diff -NurpP --minimal linux-3.9.4/arch/powerpc/kernel/process.c linux-3.9.4-vs2.3.6.2/arch/powerpc/kernel/process.c
562 --- linux-3.9.4/arch/powerpc/kernel/process.c 2013-05-31 13:44:44.000000000 +0000
563 +++ linux-3.9.4-vs2.3.6.2/arch/powerpc/kernel/process.c 2013-05-31 14:47:11.000000000 +0000
564 @@ -850,8 +850,9 @@ void show_regs(struct pt_regs * regs)
566 printk("DAR: "REG", DSISR: %08lx\n", regs->dar, regs->dsisr);
568 - printk("TASK = %p[%d] '%s' THREAD: %p",
569 - current, task_pid_nr(current), current->comm, task_thread_info(current));
570 + printk("TASK = %p[%d,#%u] '%s' THREAD: %p",
571 + current, task_pid_nr(current), current->xid,
572 + current->comm, task_thread_info(current));
575 printk(" CPU: %d", raw_smp_processor_id());
576 diff -NurpP --minimal linux-3.9.4/arch/powerpc/kernel/traps.c linux-3.9.4-vs2.3.6.2/arch/powerpc/kernel/traps.c
577 --- linux-3.9.4/arch/powerpc/kernel/traps.c 2013-05-31 14:22:26.000000000 +0000
578 +++ linux-3.9.4-vs2.3.6.2/arch/powerpc/kernel/traps.c 2013-05-31 14:47:11.000000000 +0000
579 @@ -1167,8 +1167,9 @@ void nonrecoverable_exception(struct pt_
581 void trace_syscall(struct pt_regs *regs)
583 - printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
584 - current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
585 + printk("Task: %p(%d[#%u]), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
586 + current, task_pid_nr(current), current->xid,
587 + regs->nip, regs->link, regs->gpr[0],
588 regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
591 diff -NurpP --minimal linux-3.9.4/arch/s390/Kconfig linux-3.9.4-vs2.3.6.2/arch/s390/Kconfig
592 --- linux-3.9.4/arch/s390/Kconfig 2013-05-31 13:44:45.000000000 +0000
593 +++ linux-3.9.4-vs2.3.6.2/arch/s390/Kconfig 2013-05-31 14:47:11.000000000 +0000
594 @@ -592,6 +592,8 @@ source "fs/Kconfig"
596 source "arch/s390/Kconfig.debug"
598 +source "kernel/vserver/Kconfig"
600 source "security/Kconfig"
602 source "crypto/Kconfig"
603 diff -NurpP --minimal linux-3.9.4/arch/s390/include/asm/tlb.h linux-3.9.4-vs2.3.6.2/arch/s390/include/asm/tlb.h
604 --- linux-3.9.4/arch/s390/include/asm/tlb.h 2012-12-11 03:30:57.000000000 +0000
605 +++ linux-3.9.4-vs2.3.6.2/arch/s390/include/asm/tlb.h 2013-05-31 14:47:11.000000000 +0000
607 #include <linux/mm.h>
608 #include <linux/pagemap.h>
609 #include <linux/swap.h>
611 #include <asm/processor.h>
612 #include <asm/pgalloc.h>
613 #include <asm/tlbflush.h>
614 diff -NurpP --minimal linux-3.9.4/arch/s390/include/uapi/asm/unistd.h linux-3.9.4-vs2.3.6.2/arch/s390/include/uapi/asm/unistd.h
615 --- linux-3.9.4/arch/s390/include/uapi/asm/unistd.h 2013-02-19 13:57:16.000000000 +0000
616 +++ linux-3.9.4-vs2.3.6.2/arch/s390/include/uapi/asm/unistd.h 2013-05-31 14:47:11.000000000 +0000
618 #define __NR_clock_gettime (__NR_timer_create+6)
619 #define __NR_clock_getres (__NR_timer_create+7)
620 #define __NR_clock_nanosleep (__NR_timer_create+8)
621 -/* Number 263 is reserved for vserver */
622 +#define __NR_vserver 263
623 #define __NR_statfs64 265
624 #define __NR_fstatfs64 266
625 #define __NR_remap_file_pages 267
626 diff -NurpP --minimal linux-3.9.4/arch/s390/kernel/ptrace.c linux-3.9.4-vs2.3.6.2/arch/s390/kernel/ptrace.c
627 --- linux-3.9.4/arch/s390/kernel/ptrace.c 2012-12-11 03:30:57.000000000 +0000
628 +++ linux-3.9.4-vs2.3.6.2/arch/s390/kernel/ptrace.c 2013-05-31 14:47:11.000000000 +0000
630 #include <linux/tracehook.h>
631 #include <linux/seccomp.h>
632 #include <linux/compat.h>
633 +#include <linux/vs_base.h>
634 #include <trace/syscall.h>
635 #include <asm/segment.h>
636 #include <asm/page.h>
637 diff -NurpP --minimal linux-3.9.4/arch/s390/kernel/syscalls.S linux-3.9.4-vs2.3.6.2/arch/s390/kernel/syscalls.S
638 --- linux-3.9.4/arch/s390/kernel/syscalls.S 2013-05-31 13:44:45.000000000 +0000
639 +++ linux-3.9.4-vs2.3.6.2/arch/s390/kernel/syscalls.S 2013-05-31 14:47:11.000000000 +0000
640 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
641 SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper) /* 260 */
642 SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
643 SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
644 -NI_SYSCALL /* reserved for vserver */
645 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
646 SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
647 SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
648 SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
649 diff -NurpP --minimal linux-3.9.4/arch/sh/Kconfig linux-3.9.4-vs2.3.6.2/arch/sh/Kconfig
650 --- linux-3.9.4/arch/sh/Kconfig 2013-05-31 13:44:45.000000000 +0000
651 +++ linux-3.9.4-vs2.3.6.2/arch/sh/Kconfig 2013-05-31 14:47:11.000000000 +0000
652 @@ -951,6 +951,8 @@ source "fs/Kconfig"
654 source "arch/sh/Kconfig.debug"
656 +source "kernel/vserver/Kconfig"
658 source "security/Kconfig"
660 source "crypto/Kconfig"
661 diff -NurpP --minimal linux-3.9.4/arch/sh/kernel/irq.c linux-3.9.4-vs2.3.6.2/arch/sh/kernel/irq.c
662 --- linux-3.9.4/arch/sh/kernel/irq.c 2012-12-11 03:30:57.000000000 +0000
663 +++ linux-3.9.4-vs2.3.6.2/arch/sh/kernel/irq.c 2013-05-31 14:47:11.000000000 +0000
665 #include <linux/ftrace.h>
666 #include <linux/delay.h>
667 #include <linux/ratelimit.h>
668 +// #include <linux/vs_context.h>
669 #include <asm/processor.h>
670 #include <asm/machvec.h>
671 #include <asm/uaccess.h>
672 diff -NurpP --minimal linux-3.9.4/arch/sparc/Kconfig linux-3.9.4-vs2.3.6.2/arch/sparc/Kconfig
673 --- linux-3.9.4/arch/sparc/Kconfig 2013-05-31 13:44:47.000000000 +0000
674 +++ linux-3.9.4-vs2.3.6.2/arch/sparc/Kconfig 2013-05-31 14:47:11.000000000 +0000
675 @@ -559,6 +559,8 @@ source "fs/Kconfig"
677 source "arch/sparc/Kconfig.debug"
679 +source "kernel/vserver/Kconfig"
681 source "security/Kconfig"
683 source "crypto/Kconfig"
684 diff -NurpP --minimal linux-3.9.4/arch/sparc/include/uapi/asm/unistd.h linux-3.9.4-vs2.3.6.2/arch/sparc/include/uapi/asm/unistd.h
685 --- linux-3.9.4/arch/sparc/include/uapi/asm/unistd.h 2013-02-19 13:57:17.000000000 +0000
686 +++ linux-3.9.4-vs2.3.6.2/arch/sparc/include/uapi/asm/unistd.h 2013-05-31 14:47:11.000000000 +0000
688 #define __NR_timer_getoverrun 264
689 #define __NR_timer_delete 265
690 #define __NR_timer_create 266
691 -/* #define __NR_vserver 267 Reserved for VSERVER */
692 +#define __NR_vserver 267
693 #define __NR_io_setup 268
694 #define __NR_io_destroy 269
695 #define __NR_io_submit 270
696 diff -NurpP --minimal linux-3.9.4/arch/sparc/kernel/systbls_32.S linux-3.9.4-vs2.3.6.2/arch/sparc/kernel/systbls_32.S
697 --- linux-3.9.4/arch/sparc/kernel/systbls_32.S 2013-05-31 13:44:48.000000000 +0000
698 +++ linux-3.9.4-vs2.3.6.2/arch/sparc/kernel/systbls_32.S 2013-05-31 14:47:11.000000000 +0000
699 @@ -70,7 +70,7 @@ sys_call_table:
700 /*250*/ .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
701 /*255*/ .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
702 /*260*/ .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
703 -/*265*/ .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
704 +/*265*/ .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
705 /*270*/ .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
706 /*275*/ .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
707 /*280*/ .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
708 diff -NurpP --minimal linux-3.9.4/arch/sparc/kernel/systbls_64.S linux-3.9.4-vs2.3.6.2/arch/sparc/kernel/systbls_64.S
709 --- linux-3.9.4/arch/sparc/kernel/systbls_64.S 2013-05-31 13:44:48.000000000 +0000
710 +++ linux-3.9.4-vs2.3.6.2/arch/sparc/kernel/systbls_64.S 2013-05-31 14:47:11.000000000 +0000
711 @@ -71,7 +71,7 @@ sys_call_table32:
712 /*250*/ .word sys_mremap, compat_sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
713 .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
714 /*260*/ .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
715 - .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
716 + .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
717 /*270*/ .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
718 .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
719 /*280*/ .word sys_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
720 @@ -149,7 +149,7 @@ sys_call_table:
721 /*250*/ .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
722 .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
723 /*260*/ .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
724 - .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
725 + .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
726 /*270*/ .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
727 .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
728 /*280*/ .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
729 diff -NurpP --minimal linux-3.9.4/arch/um/Kconfig.rest linux-3.9.4-vs2.3.6.2/arch/um/Kconfig.rest
730 --- linux-3.9.4/arch/um/Kconfig.rest 2012-12-11 03:30:57.000000000 +0000
731 +++ linux-3.9.4-vs2.3.6.2/arch/um/Kconfig.rest 2013-05-31 14:47:11.000000000 +0000
732 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
736 +source "kernel/vserver/Kconfig"
738 source "security/Kconfig"
740 source "crypto/Kconfig"
741 diff -NurpP --minimal linux-3.9.4/arch/um/include/shared/kern_constants.h linux-3.9.4-vs2.3.6.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/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.2/fs/ext2/ialloc.c 2013-06-01 09:31:28.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,8 @@ got:
2315 inode->i_mode = mode;
2316 inode->i_uid = current_fsuid();
2317 inode->i_gid = dir->i_gid;
2318 + inode->i_tag = make_ktag(&init_user_ns,
2319 + dx_current_fstag(sb));
2321 inode_init_owner(inode, dir, mode);
2323 diff -NurpP --minimal linux-3.9.4/fs/ext2/inode.c linux-3.9.4-vs2.3.6.2/fs/ext2/inode.c
2324 --- linux-3.9.4/fs/ext2/inode.c 2013-05-31 13:45:23.000000000 +0000
2325 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/inode.c 2013-05-31 14:47:11.000000000 +0000
2327 #include <linux/mpage.h>
2328 #include <linux/fiemap.h>
2329 #include <linux/namei.h>
2330 +#include <linux/vs_tag.h>
2334 @@ -1179,7 +1180,7 @@ static void ext2_truncate_blocks(struct
2336 if (ext2_inode_is_fast_symlink(inode))
2338 - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2339 + if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2341 __ext2_truncate_blocks(inode, offset);
2343 @@ -1270,36 +1271,61 @@ void ext2_set_inode_flags(struct inode *
2345 unsigned int flags = EXT2_I(inode)->i_flags;
2347 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2348 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2349 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2352 + if (flags & EXT2_IMMUTABLE_FL)
2353 + inode->i_flags |= S_IMMUTABLE;
2354 + if (flags & EXT2_IXUNLINK_FL)
2355 + inode->i_flags |= S_IXUNLINK;
2357 if (flags & EXT2_SYNC_FL)
2358 inode->i_flags |= S_SYNC;
2359 if (flags & EXT2_APPEND_FL)
2360 inode->i_flags |= S_APPEND;
2361 - if (flags & EXT2_IMMUTABLE_FL)
2362 - inode->i_flags |= S_IMMUTABLE;
2363 if (flags & EXT2_NOATIME_FL)
2364 inode->i_flags |= S_NOATIME;
2365 if (flags & EXT2_DIRSYNC_FL)
2366 inode->i_flags |= S_DIRSYNC;
2368 + inode->i_vflags &= ~(V_BARRIER | V_COW);
2370 + if (flags & EXT2_BARRIER_FL)
2371 + inode->i_vflags |= V_BARRIER;
2372 + if (flags & EXT2_COW_FL)
2373 + inode->i_vflags |= V_COW;
2376 /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2377 void ext2_get_inode_flags(struct ext2_inode_info *ei)
2379 unsigned int flags = ei->vfs_inode.i_flags;
2380 + unsigned int vflags = ei->vfs_inode.i_vflags;
2382 + ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2383 + EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2384 + EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2385 + EXT2_BARRIER_FL | EXT2_COW_FL);
2387 + if (flags & S_IMMUTABLE)
2388 + ei->i_flags |= EXT2_IMMUTABLE_FL;
2389 + if (flags & S_IXUNLINK)
2390 + ei->i_flags |= EXT2_IXUNLINK_FL;
2392 - ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2393 - EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2395 ei->i_flags |= EXT2_SYNC_FL;
2396 if (flags & S_APPEND)
2397 ei->i_flags |= EXT2_APPEND_FL;
2398 - if (flags & S_IMMUTABLE)
2399 - ei->i_flags |= EXT2_IMMUTABLE_FL;
2400 if (flags & S_NOATIME)
2401 ei->i_flags |= EXT2_NOATIME_FL;
2402 if (flags & S_DIRSYNC)
2403 ei->i_flags |= EXT2_DIRSYNC_FL;
2405 + if (vflags & V_BARRIER)
2406 + ei->i_flags |= EXT2_BARRIER_FL;
2407 + if (vflags & V_COW)
2408 + ei->i_flags |= EXT2_COW_FL;
2411 struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2412 @@ -1335,8 +1361,10 @@ struct inode *ext2_iget (struct super_bl
2413 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2414 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2416 - i_uid_write(inode, i_uid);
2417 - i_gid_write(inode, i_gid);
2418 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2419 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2420 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2421 + le16_to_cpu(raw_inode->i_raw_tag)));
2422 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2423 inode->i_size = le32_to_cpu(raw_inode->i_size);
2424 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2425 @@ -1434,8 +1462,10 @@ static int __ext2_write_inode(struct ino
2426 struct ext2_inode_info *ei = EXT2_I(inode);
2427 struct super_block *sb = inode->i_sb;
2428 ino_t ino = inode->i_ino;
2429 - uid_t uid = i_uid_read(inode);
2430 - gid_t gid = i_gid_read(inode);
2431 + uid_t uid = TAGINO_UID(DX_TAG(inode),
2432 + i_uid_read(inode), i_tag_read(inode));
2433 + gid_t gid = TAGINO_GID(DX_TAG(inode),
2434 + i_gid_read(inode), i_tag_read(inode));
2435 struct buffer_head * bh;
2436 struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2438 @@ -1471,6 +1501,9 @@ static int __ext2_write_inode(struct ino
2439 raw_inode->i_uid_high = 0;
2440 raw_inode->i_gid_high = 0;
2442 +#ifdef CONFIG_TAGGING_INTERN
2443 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2445 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2446 raw_inode->i_size = cpu_to_le32(inode->i_size);
2447 raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2448 @@ -1551,7 +1584,8 @@ int ext2_setattr(struct dentry *dentry,
2449 if (is_quota_modification(inode, iattr))
2450 dquot_initialize(inode);
2451 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2452 - (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2453 + (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2454 + (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2455 error = dquot_transfer(inode, iattr);
2458 diff -NurpP --minimal linux-3.9.4/fs/ext2/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ext2/ioctl.c
2459 --- linux-3.9.4/fs/ext2/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2460 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/ioctl.c 2013-05-31 14:47:11.000000000 +0000
2462 #include <asm/uaccess.h>
2465 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2467 + inode->i_flags = flags;
2468 + inode->i_vflags = vflags;
2469 + ext2_get_inode_flags(EXT2_I(inode));
2470 + inode->i_ctime = CURRENT_TIME_SEC;
2471 + mark_inode_dirty(inode);
2475 long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2477 struct inode *inode = file_inode(filp);
2478 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2480 flags = ext2_mask_flags(inode->i_mode, flags);
2482 + if (IS_BARRIER(inode)) {
2483 + vxwprintk_task(1, "messing with the barrier.");
2487 mutex_lock(&inode->i_mutex);
2488 /* Is it quota file? Do not allow user to mess with it */
2489 if (IS_NOQUOTA(inode)) {
2490 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2492 * This test looks nicer. Thanks to Pauline Middelink
2494 - if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2495 + if ((oldflags & EXT2_IMMUTABLE_FL) ||
2496 + ((flags ^ oldflags) & (EXT2_APPEND_FL |
2497 + EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2498 if (!capable(CAP_LINUX_IMMUTABLE)) {
2499 mutex_unlock(&inode->i_mutex);
2501 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2505 - flags = flags & EXT2_FL_USER_MODIFIABLE;
2506 + flags &= EXT2_FL_USER_MODIFIABLE;
2507 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2508 ei->i_flags = flags;
2510 diff -NurpP --minimal linux-3.9.4/fs/ext2/namei.c linux-3.9.4-vs2.3.6.2/fs/ext2/namei.c
2511 --- linux-3.9.4/fs/ext2/namei.c 2012-12-11 03:30:57.000000000 +0000
2512 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/namei.c 2013-05-31 14:47:11.000000000 +0000
2515 #include <linux/pagemap.h>
2516 #include <linux/quotaops.h>
2517 +#include <linux/vs_tag.h>
2521 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2522 (unsigned long) ino);
2523 return ERR_PTR(-EIO);
2525 + dx_propagate_tag(nd, inode);
2527 return d_splice_alias(inode, dentry);
2529 @@ -397,6 +399,7 @@ const struct inode_operations ext2_dir_i
2530 .removexattr = generic_removexattr,
2532 .setattr = ext2_setattr,
2533 + .sync_flags = ext2_sync_flags,
2534 .get_acl = ext2_get_acl,
2537 diff -NurpP --minimal linux-3.9.4/fs/ext2/super.c linux-3.9.4-vs2.3.6.2/fs/ext2/super.c
2538 --- linux-3.9.4/fs/ext2/super.c 2013-05-31 13:45:23.000000000 +0000
2539 +++ linux-3.9.4-vs2.3.6.2/fs/ext2/super.c 2013-05-31 14:47:11.000000000 +0000
2540 @@ -395,7 +395,8 @@ enum {
2541 Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2542 Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2543 Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2544 - Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2545 + Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2546 + Opt_tag, Opt_notag, Opt_tagid
2549 static const match_table_t tokens = {
2550 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2552 {Opt_noacl, "noacl"},
2555 + {Opt_notag, "notag"},
2556 + {Opt_tagid, "tagid=%u"},
2557 {Opt_grpquota, "grpquota"},
2558 {Opt_ignore, "noquota"},
2559 {Opt_quota, "quota"},
2560 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2562 set_opt (sbi->s_mount_opt, NO_UID32);
2564 +#ifndef CONFIG_TAGGING_NONE
2566 + set_opt (sbi->s_mount_opt, TAGGED);
2569 + clear_opt (sbi->s_mount_opt, TAGGED);
2572 +#ifdef CONFIG_PROPAGATE
2575 + set_opt (sbi->s_mount_opt, TAGGED);
2579 clear_opt (sbi->s_mount_opt, CHECK);
2581 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2582 if (!parse_options((char *) data, sb))
2585 + if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2586 + sb->s_flags |= MS_TAGGED;
2587 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2588 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2590 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2595 + if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2596 + !(sb->s_flags & MS_TAGGED)) {
2597 + printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2600 + goto restore_opts;
2603 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2604 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2605 diff -NurpP --minimal linux-3.9.4/fs/ext3/ext3.h linux-3.9.4-vs2.3.6.2/fs/ext3/ext3.h
2606 --- linux-3.9.4/fs/ext3/ext3.h 2012-12-11 03:30:57.000000000 +0000
2607 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/ext3.h 2013-05-31 14:47:11.000000000 +0000
2608 @@ -151,10 +151,14 @@ struct ext3_group_desc
2609 #define EXT3_NOTAIL_FL 0x00008000 /* file tail should not be merged */
2610 #define EXT3_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
2611 #define EXT3_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
2612 +#define EXT3_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
2613 #define EXT3_RESERVED_FL 0x80000000 /* reserved for ext3 lib */
2615 -#define EXT3_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
2616 -#define EXT3_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
2617 +#define EXT3_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2618 +#define EXT3_COW_FL 0x20000000 /* Copy on Write marker */
2620 +#define EXT3_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
2621 +#define EXT3_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
2623 /* Flags that should be inherited by new inodes from their parent. */
2624 #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2625 @@ -290,7 +294,8 @@ struct ext3_inode {
2627 __le16 l_i_uid_high; /* these 2 fields */
2628 __le16 l_i_gid_high; /* were reserved2[0] */
2629 - __u32 l_i_reserved2;
2630 + __le16 l_i_tag; /* Context Tag */
2631 + __u16 l_i_reserved2;
2634 __u8 h_i_frag; /* Fragment number */
2635 @@ -320,6 +325,7 @@ struct ext3_inode {
2636 #define i_gid_low i_gid
2637 #define i_uid_high osd2.linux2.l_i_uid_high
2638 #define i_gid_high osd2.linux2.l_i_gid_high
2639 +#define i_raw_tag osd2.linux2.l_i_tag
2640 #define i_reserved2 osd2.linux2.l_i_reserved2
2643 @@ -364,6 +370,7 @@ struct ext3_inode {
2644 #define EXT3_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
2645 #define EXT3_MOUNT_DATA_ERR_ABORT 0x400000 /* Abort on file data write
2646 * error in ordered mode */
2647 +#define EXT3_MOUNT_TAGGED (1<<24) /* Enable Context Tags */
2649 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2650 #ifndef _LINUX_EXT2_FS_H
2651 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2652 extern void ext3_set_aops(struct inode *inode);
2653 extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2654 u64 start, u64 len);
2655 +extern int ext3_sync_flags(struct inode *, int, int);
2658 extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2659 diff -NurpP --minimal linux-3.9.4/fs/ext3/file.c linux-3.9.4-vs2.3.6.2/fs/ext3/file.c
2660 --- linux-3.9.4/fs/ext3/file.c 2012-12-11 03:30:57.000000000 +0000
2661 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/file.c 2013-05-31 14:47:11.000000000 +0000
2662 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2664 .get_acl = ext3_get_acl,
2665 .fiemap = ext3_fiemap,
2666 + .sync_flags = ext3_sync_flags,
2669 diff -NurpP --minimal linux-3.9.4/fs/ext3/ialloc.c linux-3.9.4-vs2.3.6.2/fs/ext3/ialloc.c
2670 --- linux-3.9.4/fs/ext3/ialloc.c 2012-12-11 03:30:57.000000000 +0000
2671 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/ialloc.c 2013-06-01 09:40:15.000000000 +0000
2674 #include <linux/quotaops.h>
2675 #include <linux/random.h>
2676 +#include <linux/vs_tag.h>
2680 @@ -469,6 +470,8 @@ got:
2681 inode->i_mode = mode;
2682 inode->i_uid = current_fsuid();
2683 inode->i_gid = dir->i_gid;
2684 + inode->i_tag = make_ktag(&init_user_ns,
2685 + dx_current_fstag(sb));
2687 inode_init_owner(inode, dir, mode);
2689 diff -NurpP --minimal linux-3.9.4/fs/ext3/inode.c linux-3.9.4-vs2.3.6.2/fs/ext3/inode.c
2690 --- linux-3.9.4/fs/ext3/inode.c 2013-05-31 13:45:23.000000000 +0000
2691 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/inode.c 2013-05-31 14:47:11.000000000 +0000
2693 #include <linux/writeback.h>
2694 #include <linux/mpage.h>
2695 #include <linux/namei.h>
2696 +#include <linux/vs_tag.h>
2701 @@ -2851,36 +2853,60 @@ void ext3_set_inode_flags(struct inode *
2703 unsigned int flags = EXT3_I(inode)->i_flags;
2705 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2706 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2707 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2709 + if (flags & EXT3_IMMUTABLE_FL)
2710 + inode->i_flags |= S_IMMUTABLE;
2711 + if (flags & EXT3_IXUNLINK_FL)
2712 + inode->i_flags |= S_IXUNLINK;
2714 if (flags & EXT3_SYNC_FL)
2715 inode->i_flags |= S_SYNC;
2716 if (flags & EXT3_APPEND_FL)
2717 inode->i_flags |= S_APPEND;
2718 - if (flags & EXT3_IMMUTABLE_FL)
2719 - inode->i_flags |= S_IMMUTABLE;
2720 if (flags & EXT3_NOATIME_FL)
2721 inode->i_flags |= S_NOATIME;
2722 if (flags & EXT3_DIRSYNC_FL)
2723 inode->i_flags |= S_DIRSYNC;
2725 + inode->i_vflags &= ~(V_BARRIER | V_COW);
2727 + if (flags & EXT3_BARRIER_FL)
2728 + inode->i_vflags |= V_BARRIER;
2729 + if (flags & EXT3_COW_FL)
2730 + inode->i_vflags |= V_COW;
2733 /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2734 void ext3_get_inode_flags(struct ext3_inode_info *ei)
2736 unsigned int flags = ei->vfs_inode.i_flags;
2737 + unsigned int vflags = ei->vfs_inode.i_vflags;
2739 + ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2740 + EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2741 + EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2742 + EXT3_BARRIER_FL | EXT3_COW_FL);
2744 + if (flags & S_IMMUTABLE)
2745 + ei->i_flags |= EXT3_IMMUTABLE_FL;
2746 + if (flags & S_IXUNLINK)
2747 + ei->i_flags |= EXT3_IXUNLINK_FL;
2749 - ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2750 - EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2752 ei->i_flags |= EXT3_SYNC_FL;
2753 if (flags & S_APPEND)
2754 ei->i_flags |= EXT3_APPEND_FL;
2755 - if (flags & S_IMMUTABLE)
2756 - ei->i_flags |= EXT3_IMMUTABLE_FL;
2757 if (flags & S_NOATIME)
2758 ei->i_flags |= EXT3_NOATIME_FL;
2759 if (flags & S_DIRSYNC)
2760 ei->i_flags |= EXT3_DIRSYNC_FL;
2762 + if (vflags & V_BARRIER)
2763 + ei->i_flags |= EXT3_BARRIER_FL;
2764 + if (vflags & V_COW)
2765 + ei->i_flags |= EXT3_COW_FL;
2768 struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2769 @@ -2918,8 +2944,10 @@ struct inode *ext3_iget(struct super_blo
2770 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2771 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2773 - i_uid_write(inode, i_uid);
2774 - i_gid_write(inode, i_gid);
2775 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2776 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2777 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2778 + le16_to_cpu(raw_inode->i_raw_tag)));
2779 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2780 inode->i_size = le32_to_cpu(raw_inode->i_size);
2781 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2782 @@ -3091,8 +3119,10 @@ again:
2784 ext3_get_inode_flags(ei);
2785 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2786 - i_uid = i_uid_read(inode);
2787 - i_gid = i_gid_read(inode);
2788 + i_uid = TAGINO_UID(DX_TAG(inode),
2789 + i_uid_read(inode), i_tag_read(inode));
2790 + i_gid = TAGINO_GID(DX_TAG(inode),
2791 + i_gid_read(inode), i_tag_read(inode));
2792 if(!(test_opt(inode->i_sb, NO_UID32))) {
2793 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2794 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2795 @@ -3117,6 +3147,9 @@ again:
2796 raw_inode->i_uid_high = 0;
2797 raw_inode->i_gid_high = 0;
2799 +#ifdef CONFIG_TAGGING_INTERN
2800 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2802 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2803 disksize = cpu_to_le32(ei->i_disksize);
2804 if (disksize != raw_inode->i_size) {
2805 @@ -3285,7 +3318,8 @@ int ext3_setattr(struct dentry *dentry,
2806 if (is_quota_modification(inode, attr))
2807 dquot_initialize(inode);
2808 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2809 - (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2810 + (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2811 + (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2814 /* (user+group)*(old+new) structure, inode write (sb,
2815 @@ -3307,6 +3341,8 @@ int ext3_setattr(struct dentry *dentry,
2816 inode->i_uid = attr->ia_uid;
2817 if (attr->ia_valid & ATTR_GID)
2818 inode->i_gid = attr->ia_gid;
2819 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2820 + inode->i_tag = attr->ia_tag;
2821 error = ext3_mark_inode_dirty(handle, inode);
2822 ext3_journal_stop(handle);
2824 diff -NurpP --minimal linux-3.9.4/fs/ext3/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ext3/ioctl.c
2825 --- linux-3.9.4/fs/ext3/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2826 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/ioctl.c 2013-05-31 14:47:11.000000000 +0000
2828 #include <asm/uaccess.h>
2832 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2834 + handle_t *handle = NULL;
2835 + struct ext3_iloc iloc;
2838 + handle = ext3_journal_start(inode, 1);
2839 + if (IS_ERR(handle))
2840 + return PTR_ERR(handle);
2842 + if (IS_SYNC(inode))
2843 + handle->h_sync = 1;
2844 + err = ext3_reserve_inode_write(handle, inode, &iloc);
2848 + inode->i_flags = flags;
2849 + inode->i_vflags = vflags;
2850 + ext3_get_inode_flags(EXT3_I(inode));
2851 + inode->i_ctime = CURRENT_TIME_SEC;
2853 + err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2855 + ext3_journal_stop(handle);
2859 long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2861 struct inode *inode = file_inode(filp);
2862 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2864 flags = ext3_mask_flags(inode->i_mode, flags);
2866 + if (IS_BARRIER(inode)) {
2867 + vxwprintk_task(1, "messing with the barrier.");
2871 mutex_lock(&inode->i_mutex);
2873 /* Is it quota file? Do not allow user to mess with it */
2874 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2876 * This test looks nicer. Thanks to Pauline Middelink
2878 - if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2879 + if ((oldflags & EXT3_IMMUTABLE_FL) ||
2880 + ((flags ^ oldflags) & (EXT3_APPEND_FL |
2881 + EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2882 if (!capable(CAP_LINUX_IMMUTABLE))
2885 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2889 - flags = flags & EXT3_FL_USER_MODIFIABLE;
2890 + flags &= EXT3_FL_USER_MODIFIABLE;
2891 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2892 ei->i_flags = flags;
2894 diff -NurpP --minimal linux-3.9.4/fs/ext3/namei.c linux-3.9.4-vs2.3.6.2/fs/ext3/namei.c
2895 --- linux-3.9.4/fs/ext3/namei.c 2013-05-31 13:45:23.000000000 +0000
2896 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/namei.c 2013-05-31 14:47:11.000000000 +0000
2900 #include <linux/quotaops.h>
2901 +#include <linux/vs_tag.h>
2906 @@ -918,6 +920,7 @@ restart:
2907 submit_bh(READ | REQ_META | REQ_PRIO,
2910 + dx_propagate_tag(nd, inode);
2913 if ((bh = bh_use[ra_ptr++]) == NULL)
2914 @@ -2527,6 +2530,7 @@ const struct inode_operations ext3_dir_i
2915 .listxattr = ext3_listxattr,
2916 .removexattr = generic_removexattr,
2918 + .sync_flags = ext3_sync_flags,
2919 .get_acl = ext3_get_acl,
2922 diff -NurpP --minimal linux-3.9.4/fs/ext3/super.c linux-3.9.4-vs2.3.6.2/fs/ext3/super.c
2923 --- linux-3.9.4/fs/ext3/super.c 2013-05-31 13:45:23.000000000 +0000
2924 +++ linux-3.9.4-vs2.3.6.2/fs/ext3/super.c 2013-05-31 14:47:11.000000000 +0000
2925 @@ -816,7 +816,8 @@ enum {
2926 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2927 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2928 Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2929 - Opt_resize, Opt_usrquota, Opt_grpquota
2930 + Opt_resize, Opt_usrquota, Opt_grpquota,
2931 + Opt_tag, Opt_notag, Opt_tagid
2934 static const match_table_t tokens = {
2935 @@ -873,6 +874,9 @@ static const match_table_t tokens = {
2936 {Opt_barrier, "barrier"},
2937 {Opt_nobarrier, "nobarrier"},
2938 {Opt_resize, "resize"},
2940 + {Opt_notag, "notag"},
2941 + {Opt_tagid, "tagid=%u"},
2945 @@ -1040,6 +1044,20 @@ static int parse_options (char *options,
2947 set_opt (sbi->s_mount_opt, NO_UID32);
2949 +#ifndef CONFIG_TAGGING_NONE
2951 + set_opt (sbi->s_mount_opt, TAGGED);
2954 + clear_opt (sbi->s_mount_opt, TAGGED);
2957 +#ifdef CONFIG_PROPAGATE
2960 + set_opt (sbi->s_mount_opt, TAGGED);
2964 clear_opt (sbi->s_mount_opt, CHECK);
2966 @@ -1737,6 +1755,9 @@ static int ext3_fill_super (struct super
2970 + if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2971 + sb->s_flags |= MS_TAGGED;
2973 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2974 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2976 @@ -2633,6 +2654,14 @@ static int ext3_remount (struct super_bl
2977 if (test_opt(sb, ABORT))
2978 ext3_abort(sb, __func__, "Abort forced by user");
2980 + if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2981 + !(sb->s_flags & MS_TAGGED)) {
2982 + printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2985 + goto restore_opts;
2988 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2989 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2991 diff -NurpP --minimal linux-3.9.4/fs/ext4/ext4.h linux-3.9.4-vs2.3.6.2/fs/ext4/ext4.h
2992 --- linux-3.9.4/fs/ext4/ext4.h 2013-05-31 13:45:23.000000000 +0000
2993 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/ext4.h 2013-05-31 16:22:49.000000000 +0000
2994 @@ -399,7 +399,10 @@ struct flex_groups {
2995 #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
2996 #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
2997 #define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
2998 +#define EXT4_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2999 +#define EXT4_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
3000 #define EXT4_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */
3001 +#define EXT4_COW_FL 0x20000000 /* Copy on Write marker */
3002 #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
3004 #define EXT4_FL_USER_VISIBLE 0x004BDFFF /* User visible flags */
3005 @@ -674,7 +677,7 @@ struct ext4_inode {
3006 __le16 l_i_uid_high; /* these 2 fields */
3007 __le16 l_i_gid_high; /* were reserved2[0] */
3008 __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
3009 - __le16 l_i_reserved;
3010 + __le16 l_i_tag; /* Context Tag */
3013 __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
3014 @@ -792,6 +795,7 @@ do { \
3015 #define i_gid_low i_gid
3016 #define i_uid_high osd2.linux2.l_i_uid_high
3017 #define i_gid_high osd2.linux2.l_i_gid_high
3018 +#define i_raw_tag osd2.linux2.l_i_tag
3019 #define i_checksum_lo osd2.linux2.l_i_checksum_lo
3021 #elif defined(__GNU__)
3022 @@ -969,6 +973,7 @@ struct ext4_inode_info {
3023 #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
3024 #define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */
3025 #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */
3026 +#define EXT4_MOUNT_TAGGED 0x40000 /* Enable Context Tags */
3027 #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */
3028 #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
3029 #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
3030 @@ -2527,6 +2532,7 @@ extern struct buffer_head *ext4_get_firs
3031 extern int ext4_inline_data_fiemap(struct inode *inode,
3032 struct fiemap_extent_info *fieinfo,
3034 +extern int ext4_sync_flags(struct inode *, int, int);
3035 extern int ext4_try_to_evict_inline_data(handle_t *handle,
3036 struct inode *inode,
3038 diff -NurpP --minimal linux-3.9.4/fs/ext4/file.c linux-3.9.4-vs2.3.6.2/fs/ext4/file.c
3039 --- linux-3.9.4/fs/ext4/file.c 2013-05-31 13:45:23.000000000 +0000
3040 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/file.c 2013-05-31 14:47:11.000000000 +0000
3041 @@ -650,5 +650,6 @@ const struct inode_operations ext4_file_
3042 .removexattr = generic_removexattr,
3043 .get_acl = ext4_get_acl,
3044 .fiemap = ext4_fiemap,
3045 + .sync_flags = ext4_sync_flags,
3048 diff -NurpP --minimal linux-3.9.4/fs/ext4/ialloc.c linux-3.9.4-vs2.3.6.2/fs/ext4/ialloc.c
3049 --- linux-3.9.4/fs/ext4/ialloc.c 2013-05-31 13:45:23.000000000 +0000
3050 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/ialloc.c 2013-06-01 09:46:49.000000000 +0000
3052 #include <linux/random.h>
3053 #include <linux/bitops.h>
3054 #include <linux/blkdev.h>
3055 +#include <linux/vs_tag.h>
3056 #include <asm/byteorder.h>
3059 @@ -859,6 +860,8 @@ got:
3060 inode->i_mode = mode;
3061 inode->i_uid = current_fsuid();
3062 inode->i_gid = dir->i_gid;
3063 + inode->i_tag = make_ktag(&init_user_ns,
3064 + dx_current_fstag(sb));
3066 inode_init_owner(inode, dir, mode);
3068 diff -NurpP --minimal linux-3.9.4/fs/ext4/inode.c linux-3.9.4-vs2.3.6.2/fs/ext4/inode.c
3069 --- linux-3.9.4/fs/ext4/inode.c 2013-05-31 14:22:27.000000000 +0000
3070 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/inode.c 2013-05-31 14:47:11.000000000 +0000
3072 #include <linux/printk.h>
3073 #include <linux/slab.h>
3074 #include <linux/ratelimit.h>
3075 +#include <linux/vs_tag.h>
3077 #include "ext4_jbd2.h"
3079 @@ -3870,41 +3871,64 @@ void ext4_set_inode_flags(struct inode *
3081 unsigned int flags = EXT4_I(inode)->i_flags;
3083 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
3084 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3085 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3087 + if (flags & EXT4_IMMUTABLE_FL)
3088 + inode->i_flags |= S_IMMUTABLE;
3089 + if (flags & EXT4_IXUNLINK_FL)
3090 + inode->i_flags |= S_IXUNLINK;
3092 if (flags & EXT4_SYNC_FL)
3093 inode->i_flags |= S_SYNC;
3094 if (flags & EXT4_APPEND_FL)
3095 inode->i_flags |= S_APPEND;
3096 - if (flags & EXT4_IMMUTABLE_FL)
3097 - inode->i_flags |= S_IMMUTABLE;
3098 if (flags & EXT4_NOATIME_FL)
3099 inode->i_flags |= S_NOATIME;
3100 if (flags & EXT4_DIRSYNC_FL)
3101 inode->i_flags |= S_DIRSYNC;
3103 + inode->i_vflags &= ~(V_BARRIER | V_COW);
3105 + if (flags & EXT4_BARRIER_FL)
3106 + inode->i_vflags |= V_BARRIER;
3107 + if (flags & EXT4_COW_FL)
3108 + inode->i_vflags |= V_COW;
3111 /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
3112 void ext4_get_inode_flags(struct ext4_inode_info *ei)
3114 - unsigned int vfs_fl;
3115 + unsigned int vfs_fl, vfs_vf;
3116 unsigned long old_fl, new_fl;
3119 vfs_fl = ei->vfs_inode.i_flags;
3120 + vfs_vf = ei->vfs_inode.i_vflags;
3121 old_fl = ei->i_flags;
3122 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
3123 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
3125 + EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
3128 + if (vfs_fl & S_IMMUTABLE)
3129 + new_fl |= EXT4_IMMUTABLE_FL;
3130 + if (vfs_fl & S_IXUNLINK)
3131 + new_fl |= EXT4_IXUNLINK_FL;
3133 if (vfs_fl & S_SYNC)
3134 new_fl |= EXT4_SYNC_FL;
3135 if (vfs_fl & S_APPEND)
3136 new_fl |= EXT4_APPEND_FL;
3137 - if (vfs_fl & S_IMMUTABLE)
3138 - new_fl |= EXT4_IMMUTABLE_FL;
3139 if (vfs_fl & S_NOATIME)
3140 new_fl |= EXT4_NOATIME_FL;
3141 if (vfs_fl & S_DIRSYNC)
3142 new_fl |= EXT4_DIRSYNC_FL;
3144 + if (vfs_vf & V_BARRIER)
3145 + new_fl |= EXT4_BARRIER_FL;
3146 + if (vfs_vf & V_COW)
3147 + new_fl |= EXT4_COW_FL;
3148 } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3151 @@ -4009,8 +4033,10 @@ struct inode *ext4_iget(struct super_blo
3152 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3153 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3155 - i_uid_write(inode, i_uid);
3156 - i_gid_write(inode, i_gid);
3157 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3158 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3159 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3160 + le16_to_cpu(raw_inode->i_raw_tag)));
3161 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3163 ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */
3164 @@ -4233,8 +4259,10 @@ static int ext4_do_update_inode(handle_t
3166 ext4_get_inode_flags(ei);
3167 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3168 - i_uid = i_uid_read(inode);
3169 - i_gid = i_gid_read(inode);
3170 + i_uid = TAGINO_UID(DX_TAG(inode),
3171 + i_uid_read(inode), i_tag_read(inode));
3172 + i_gid = TAGINO_GID(DX_TAG(inode),
3173 + i_gid_read(inode), i_tag_read(inode));
3174 if (!(test_opt(inode->i_sb, NO_UID32))) {
3175 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3176 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3177 @@ -4257,6 +4285,9 @@ static int ext4_do_update_inode(handle_t
3178 raw_inode->i_uid_high = 0;
3179 raw_inode->i_gid_high = 0;
3181 +#ifdef CONFIG_TAGGING_INTERN
3182 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3184 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3186 EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3187 @@ -4487,7 +4518,8 @@ int ext4_setattr(struct dentry *dentry,
3188 if (is_quota_modification(inode, attr))
3189 dquot_initialize(inode);
3190 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3191 - (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3192 + (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3193 + (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3196 /* (user+group)*(old+new) structure, inode write (sb,
3197 @@ -4510,6 +4542,8 @@ int ext4_setattr(struct dentry *dentry,
3198 inode->i_uid = attr->ia_uid;
3199 if (attr->ia_valid & ATTR_GID)
3200 inode->i_gid = attr->ia_gid;
3201 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3202 + inode->i_tag = attr->ia_tag;
3203 error = ext4_mark_inode_dirty(handle, inode);
3204 ext4_journal_stop(handle);
3206 diff -NurpP --minimal linux-3.9.4/fs/ext4/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ext4/ioctl.c
3207 --- linux-3.9.4/fs/ext4/ioctl.c 2013-05-31 13:45:23.000000000 +0000
3208 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/ioctl.c 2013-05-31 19:50:08.000000000 +0000
3210 #include <linux/compat.h>
3211 #include <linux/mount.h>
3212 #include <linux/file.h>
3213 +#include <linux/vs_tag.h>
3214 #include <asm/uaccess.h>
3215 #include "ext4_jbd2.h"
3218 #define MAX_32_NUM ((((unsigned long long) 1) << 32) - 1)
3220 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3222 + handle_t *handle = NULL;
3223 + struct ext4_iloc iloc;
3226 + handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3227 + if (IS_ERR(handle))
3228 + return PTR_ERR(handle);
3230 + if (IS_SYNC(inode))
3231 + ext4_handle_sync(handle);
3232 + err = ext4_reserve_inode_write(handle, inode, &iloc);
3236 + inode->i_flags = flags;
3237 + inode->i_vflags = vflags;
3238 + ext4_get_inode_flags(EXT4_I(inode));
3239 + inode->i_ctime = ext4_current_time(inode);
3241 + err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3243 + ext4_journal_stop(handle);
3247 long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3249 struct inode *inode = file_inode(filp);
3250 @@ -53,6 +81,11 @@ long ext4_ioctl(struct file *filp, unsig
3252 flags = ext4_mask_flags(inode->i_mode, flags);
3254 + if (IS_BARRIER(inode)) {
3255 + vxwprintk_task(1, "messing with the barrier.");
3260 mutex_lock(&inode->i_mutex);
3261 /* Is it quota file? Do not allow user to mess with it */
3262 @@ -70,7 +103,9 @@ long ext4_ioctl(struct file *filp, unsig
3264 * This test looks nicer. Thanks to Pauline Middelink
3266 - if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3267 + if ((oldflags & EXT4_IMMUTABLE_FL) ||
3268 + ((flags ^ oldflags) & (EXT4_APPEND_FL |
3269 + EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3270 if (!capable(CAP_LINUX_IMMUTABLE))
3273 diff -NurpP --minimal linux-3.9.4/fs/ext4/namei.c linux-3.9.4-vs2.3.6.2/fs/ext4/namei.c
3274 --- linux-3.9.4/fs/ext4/namei.c 2013-05-31 13:45:23.000000000 +0000
3275 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/namei.c 2013-05-31 14:47:11.000000000 +0000
3277 #include <linux/quotaops.h>
3278 #include <linux/buffer_head.h>
3279 #include <linux/bio.h>
3280 +#include <linux/vs_tag.h>
3282 #include "ext4_jbd2.h"
3284 @@ -1290,6 +1291,7 @@ restart:
3285 ll_rw_block(READ | REQ_META | REQ_PRIO,
3288 + dx_propagate_tag(nd, inode);
3290 if ((bh = bh_use[ra_ptr++]) == NULL)
3292 @@ -3190,6 +3192,7 @@ const struct inode_operations ext4_dir_i
3293 .removexattr = generic_removexattr,
3294 .get_acl = ext4_get_acl,
3295 .fiemap = ext4_fiemap,
3296 + .sync_flags = ext4_sync_flags,
3299 const struct inode_operations ext4_special_inode_operations = {
3300 diff -NurpP --minimal linux-3.9.4/fs/ext4/super.c linux-3.9.4-vs2.3.6.2/fs/ext4/super.c
3301 --- linux-3.9.4/fs/ext4/super.c 2013-05-31 14:22:27.000000000 +0000
3302 +++ linux-3.9.4-vs2.3.6.2/fs/ext4/super.c 2013-05-31 14:47:11.000000000 +0000
3303 @@ -1131,7 +1131,7 @@ enum {
3304 Opt_inode_readahead_blks, Opt_journal_ioprio,
3305 Opt_dioread_nolock, Opt_dioread_lock,
3306 Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3307 - Opt_max_dir_size_kb,
3308 + Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3311 static const match_table_t tokens = {
3312 @@ -1211,6 +1211,9 @@ static const match_table_t tokens = {
3313 {Opt_removed, "reservation"}, /* mount option from ext2/3 */
3314 {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3315 {Opt_removed, "journal=%u"}, /* mount option from ext2/3 */
3317 + {Opt_notag, "notag"},
3318 + {Opt_tagid, "tagid=%u"},
3322 @@ -1441,6 +1444,20 @@ static int handle_mount_opt(struct super
3324 sb->s_flags |= MS_I_VERSION;
3326 +#ifndef CONFIG_TAGGING_NONE
3328 + set_opt(sb, TAGGED);
3331 + clear_opt(sb, TAGGED);
3334 +#ifdef CONFIG_PROPAGATE
3337 + set_opt(sb, TAGGED);
3342 for (m = ext4_mount_opts; m->token != Opt_err; m++)
3343 @@ -3401,6 +3418,9 @@ static int ext4_fill_super(struct super_
3344 clear_opt(sb, DELALLOC);
3347 + if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3348 + sb->s_flags |= MS_TAGGED;
3350 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3351 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3353 @@ -4587,6 +4607,14 @@ static int ext4_remount(struct super_blo
3354 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3355 ext4_abort(sb, "Abort forced by user");
3357 + if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3358 + !(sb->s_flags & MS_TAGGED)) {
3359 + printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3362 + goto restore_opts;
3365 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3366 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3368 diff -NurpP --minimal linux-3.9.4/fs/fcntl.c linux-3.9.4-vs2.3.6.2/fs/fcntl.c
3369 --- linux-3.9.4/fs/fcntl.c 2013-05-31 13:45:23.000000000 +0000
3370 +++ linux-3.9.4-vs2.3.6.2/fs/fcntl.c 2013-05-31 14:47:11.000000000 +0000
3372 #include <linux/rcupdate.h>
3373 #include <linux/pid_namespace.h>
3374 #include <linux/user_namespace.h>
3375 +#include <linux/vs_limit.h>
3377 #include <asm/poll.h>
3378 #include <asm/siginfo.h>
3379 @@ -378,6 +379,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3383 + if (!vx_files_avail(1))
3386 if (unlikely(f.file->f_mode & FMODE_PATH)) {
3387 if (!check_fcntl_cmd(cmd))
3388 diff -NurpP --minimal linux-3.9.4/fs/file.c linux-3.9.4-vs2.3.6.2/fs/file.c
3389 --- linux-3.9.4/fs/file.c 2013-05-31 13:45:23.000000000 +0000
3390 +++ linux-3.9.4-vs2.3.6.2/fs/file.c 2013-05-31 14:47:11.000000000 +0000
3392 #include <linux/spinlock.h>
3393 #include <linux/rcupdate.h>
3394 #include <linux/workqueue.h>
3395 +#include <linux/vs_limit.h>
3397 struct fdtable_defer {
3399 @@ -364,6 +365,8 @@ struct files_struct *dup_fd(struct files
3400 struct file *f = *old_fds++;
3403 + /* TODO: sum it first for check and performance */
3404 + vx_openfd_inc(open_files - i);
3407 * The fd may be claimed in the fd bitmap but not yet
3408 @@ -429,9 +432,11 @@ static void close_files(struct files_str
3409 filp_close(file, files);
3420 @@ -567,6 +572,7 @@ repeat:
3422 __clear_close_on_exec(fd, fdt);
3424 + vx_openfd_inc(fd);
3427 if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3428 @@ -597,6 +603,7 @@ static void __put_unused_fd(struct files
3429 __clear_open_fd(fd, fdt);
3430 if (fd < files->next_fd)
3431 files->next_fd = fd;
3432 + vx_openfd_dec(fd);
3435 void put_unused_fd(unsigned int fd)
3436 @@ -876,6 +883,8 @@ static int do_dup2(struct files_struct *
3439 filp_close(tofree, files);
3441 + vx_openfd_inc(fd); /* fd was unused */
3445 diff -NurpP --minimal linux-3.9.4/fs/file_table.c linux-3.9.4-vs2.3.6.2/fs/file_table.c
3446 --- linux-3.9.4/fs/file_table.c 2013-05-31 13:45:23.000000000 +0000
3447 +++ linux-3.9.4-vs2.3.6.2/fs/file_table.c 2013-05-31 14:47:11.000000000 +0000
3449 #include <linux/hardirq.h>
3450 #include <linux/task_work.h>
3451 #include <linux/ima.h>
3452 +#include <linux/vs_limit.h>
3453 +#include <linux/vs_context.h>
3455 #include <linux/atomic.h>
3457 @@ -140,6 +142,8 @@ struct file *get_empty_filp(void)
3458 spin_lock_init(&f->f_lock);
3459 eventpoll_init_file(f);
3460 /* f->f_version: 0 */
3461 + f->f_xid = vx_current_xid();
3466 @@ -257,6 +261,8 @@ static void __fput(struct file *file)
3467 i_readcount_dec(inode);
3468 if (file->f_mode & FMODE_WRITE)
3469 drop_file_write_access(file);
3470 + vx_files_dec(file);
3472 file->f_path.dentry = NULL;
3473 file->f_path.mnt = NULL;
3474 file->f_inode = NULL;
3475 @@ -344,6 +350,8 @@ void put_filp(struct file *file)
3477 if (atomic_long_dec_and_test(&file->f_count)) {
3478 security_file_free(file);
3479 + vx_files_dec(file);
3481 file_sb_list_del(file);
3484 diff -NurpP --minimal linux-3.9.4/fs/fs_struct.c linux-3.9.4-vs2.3.6.2/fs/fs_struct.c
3485 --- linux-3.9.4/fs/fs_struct.c 2013-05-31 13:45:23.000000000 +0000
3486 +++ linux-3.9.4-vs2.3.6.2/fs/fs_struct.c 2013-05-31 14:47:11.000000000 +0000
3488 #include <linux/path.h>
3489 #include <linux/slab.h>
3490 #include <linux/fs_struct.h>
3491 +#include <linux/vserver/global.h>
3492 #include "internal.h"
3495 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3497 path_put(&fs->root);
3499 + atomic_dec(&vs_global_fs);
3500 kmem_cache_free(fs_cachep, fs);
3503 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3506 spin_unlock(&old->lock);
3507 + atomic_inc(&vs_global_fs);
3511 diff -NurpP --minimal linux-3.9.4/fs/gfs2/file.c linux-3.9.4-vs2.3.6.2/fs/gfs2/file.c
3512 --- linux-3.9.4/fs/gfs2/file.c 2013-05-31 13:45:23.000000000 +0000
3513 +++ linux-3.9.4-vs2.3.6.2/fs/gfs2/file.c 2013-05-31 19:54:27.000000000 +0000
3514 @@ -143,6 +143,9 @@ static const u32 fsflags_to_gfs2[32] = {
3515 [12] = GFS2_DIF_EXHASH,
3516 [14] = GFS2_DIF_INHERIT_JDATA,
3517 [17] = GFS2_DIF_TOPDIR,
3518 + [27] = GFS2_DIF_IXUNLINK,
3519 + [26] = GFS2_DIF_BARRIER,
3520 + [29] = GFS2_DIF_COW,
3523 static const u32 gfs2_to_fsflags[32] = {
3524 @@ -153,6 +156,9 @@ static const u32 gfs2_to_fsflags[32] = {
3525 [gfs2fl_ExHash] = FS_INDEX_FL,
3526 [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3527 [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3528 + [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3529 + [gfs2fl_Barrier] = FS_BARRIER_FL,
3530 + [gfs2fl_Cow] = FS_COW_FL,
3533 static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3534 @@ -183,12 +189,18 @@ void gfs2_set_inode_flags(struct inode *
3536 struct gfs2_inode *ip = GFS2_I(inode);
3537 unsigned int flags = inode->i_flags;
3538 + unsigned int vflags = inode->i_vflags;
3540 + flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3541 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3543 - flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3544 if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3545 inode->i_flags |= S_NOSEC;
3546 if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3547 flags |= S_IMMUTABLE;
3548 + if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3549 + flags |= S_IXUNLINK;
3551 if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3553 if (ip->i_diskflags & GFS2_DIF_NOATIME)
3554 @@ -196,6 +208,43 @@ void gfs2_set_inode_flags(struct inode *
3555 if (ip->i_diskflags & GFS2_DIF_SYNC)
3557 inode->i_flags = flags;
3559 + vflags &= ~(V_BARRIER | V_COW);
3561 + if (ip->i_diskflags & GFS2_DIF_BARRIER)
3562 + vflags |= V_BARRIER;
3563 + if (ip->i_diskflags & GFS2_DIF_COW)
3565 + inode->i_vflags = vflags;
3568 +void gfs2_get_inode_flags(struct inode *inode)
3570 + struct gfs2_inode *ip = GFS2_I(inode);
3571 + unsigned int flags = inode->i_flags;
3572 + unsigned int vflags = inode->i_vflags;
3574 + ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3575 + GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3576 + GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3577 + GFS2_DIF_BARRIER | GFS2_DIF_COW);
3579 + if (flags & S_IMMUTABLE)
3580 + ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3581 + if (flags & S_IXUNLINK)
3582 + ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3584 + if (flags & S_APPEND)
3585 + ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3586 + if (flags & S_NOATIME)
3587 + ip->i_diskflags |= GFS2_DIF_NOATIME;
3588 + if (flags & S_SYNC)
3589 + ip->i_diskflags |= GFS2_DIF_SYNC;
3591 + if (vflags & V_BARRIER)
3592 + ip->i_diskflags |= GFS2_DIF_BARRIER;
3593 + if (vflags & V_COW)
3594 + ip->i_diskflags |= GFS2_DIF_COW;
3597 /* Flags that can be set by user space */
3598 @@ -309,6 +358,37 @@ static int gfs2_set_flags(struct file *f
3599 return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3602 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3604 + struct gfs2_inode *ip = GFS2_I(inode);
3605 + struct gfs2_sbd *sdp = GFS2_SB(inode);
3606 + struct buffer_head *bh;
3607 + struct gfs2_holder gh;
3610 + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3613 + error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3616 + error = gfs2_meta_inode_buffer(ip, &bh);
3618 + goto out_trans_end;
3619 + gfs2_trans_add_meta(ip->i_gl, bh);
3620 + inode->i_flags = flags;
3621 + inode->i_vflags = vflags;
3622 + gfs2_get_inode_flags(inode);
3623 + gfs2_dinode_out(ip, bh->b_data);
3625 + gfs2_set_aops(inode);
3627 + gfs2_trans_end(sdp);
3629 + gfs2_glock_dq_uninit(&gh);
3633 static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3636 diff -NurpP --minimal linux-3.9.4/fs/gfs2/inode.h linux-3.9.4-vs2.3.6.2/fs/gfs2/inode.h
3637 --- linux-3.9.4/fs/gfs2/inode.h 2012-12-11 03:30:57.000000000 +0000
3638 +++ linux-3.9.4-vs2.3.6.2/fs/gfs2/inode.h 2013-05-31 14:47:11.000000000 +0000
3639 @@ -117,6 +117,7 @@ extern const struct file_operations gfs2
3640 extern const struct file_operations gfs2_dir_fops_nolock;
3642 extern void gfs2_set_inode_flags(struct inode *inode);
3643 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3645 #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3646 extern const struct file_operations gfs2_file_fops;
3647 diff -NurpP --minimal linux-3.9.4/fs/hostfs/hostfs.h linux-3.9.4-vs2.3.6.2/fs/hostfs/hostfs.h
3648 --- linux-3.9.4/fs/hostfs/hostfs.h 2012-12-11 03:30:57.000000000 +0000
3649 +++ linux-3.9.4-vs2.3.6.2/fs/hostfs/hostfs.h 2013-05-31 14:47:11.000000000 +0000
3650 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3651 unsigned short ia_mode;
3656 struct timespec ia_atime;
3657 struct timespec ia_mtime;
3658 diff -NurpP --minimal linux-3.9.4/fs/inode.c linux-3.9.4-vs2.3.6.2/fs/inode.c
3659 --- linux-3.9.4/fs/inode.c 2013-05-31 13:45:24.000000000 +0000
3660 +++ linux-3.9.4-vs2.3.6.2/fs/inode.c 2013-06-01 09:01:48.000000000 +0000
3662 #include <linux/prefetch.h>
3663 #include <linux/buffer_head.h> /* for inode_has_buffers */
3664 #include <linux/ratelimit.h>
3665 +#include <linux/vs_tag.h>
3666 #include "internal.h"
3669 @@ -128,6 +129,8 @@ int inode_init_always(struct super_block
3670 struct address_space *const mapping = &inode->i_data;
3674 + /* essential because of inode slab reuse */
3675 inode->i_blkbits = sb->s_blocksize_bits;
3677 atomic_set(&inode->i_count, 1);
3678 @@ -137,6 +140,7 @@ int inode_init_always(struct super_block
3679 inode->i_opflags = 0;
3680 i_uid_write(inode, 0);
3681 i_gid_write(inode, 0);
3682 + i_tag_write(inode, 0);
3683 atomic_set(&inode->i_writecount, 0);
3685 inode->i_blocks = 0;
3686 @@ -149,6 +153,7 @@ int inode_init_always(struct super_block
3687 inode->i_bdev = NULL;
3688 inode->i_cdev = NULL;
3690 + inode->i_mdev = 0;
3691 inode->dirtied_when = 0;
3693 if (security_inode_alloc(inode))
3694 @@ -483,6 +488,8 @@ void __insert_inode_hash(struct inode *i
3696 EXPORT_SYMBOL(__insert_inode_hash);
3698 +EXPORT_SYMBOL_GPL(__iget);
3701 * __remove_inode_hash - remove an inode from the hash
3702 * @inode: inode to unhash
3703 @@ -1799,9 +1806,11 @@ void init_special_inode(struct inode *in
3704 if (S_ISCHR(mode)) {
3705 inode->i_fop = &def_chr_fops;
3706 inode->i_rdev = rdev;
3707 + inode->i_mdev = rdev;
3708 } else if (S_ISBLK(mode)) {
3709 inode->i_fop = &def_blk_fops;
3710 inode->i_rdev = rdev;
3711 + inode->i_mdev = rdev;
3712 } else if (S_ISFIFO(mode))
3713 inode->i_fop = &def_fifo_fops;
3714 else if (S_ISSOCK(mode))
3715 @@ -1830,6 +1839,7 @@ void inode_init_owner(struct inode *inod
3717 inode->i_gid = current_fsgid();
3718 inode->i_mode = mode;
3719 + i_tag_write(inode, dx_current_fstag(inode->i_sb));
3721 EXPORT_SYMBOL(inode_init_owner);
3723 diff -NurpP --minimal linux-3.9.4/fs/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ioctl.c
3724 --- linux-3.9.4/fs/ioctl.c 2013-05-31 13:45:24.000000000 +0000
3725 +++ linux-3.9.4-vs2.3.6.2/fs/ioctl.c 2013-05-31 14:47:11.000000000 +0000
3727 #include <linux/writeback.h>
3728 #include <linux/buffer_head.h>
3729 #include <linux/falloc.h>
3730 +#include <linux/proc_fs.h>
3731 +#include <linux/vserver/inode.h>
3732 +#include <linux/vs_tag.h>
3734 #include <asm/ioctls.h>
3736 diff -NurpP --minimal linux-3.9.4/fs/ioprio.c linux-3.9.4-vs2.3.6.2/fs/ioprio.c
3737 --- linux-3.9.4/fs/ioprio.c 2012-12-11 03:30:57.000000000 +0000
3738 +++ linux-3.9.4-vs2.3.6.2/fs/ioprio.c 2013-05-31 14:47:11.000000000 +0000
3740 #include <linux/syscalls.h>
3741 #include <linux/security.h>
3742 #include <linux/pid_namespace.h>
3743 +#include <linux/vs_base.h>
3745 int set_task_ioprio(struct task_struct *task, int ioprio)
3747 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3749 pgrp = find_vpid(who);
3750 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3751 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3753 ret = set_task_ioprio(p, ioprio);
3756 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3758 pgrp = find_vpid(who);
3759 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3760 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3762 tmpio = get_task_ioprio(p);
3765 diff -NurpP --minimal linux-3.9.4/fs/jfs/file.c linux-3.9.4-vs2.3.6.2/fs/jfs/file.c
3766 --- linux-3.9.4/fs/jfs/file.c 2013-02-19 13:58:48.000000000 +0000
3767 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/file.c 2013-05-31 14:47:11.000000000 +0000
3768 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3769 if (is_quota_modification(inode, iattr))
3770 dquot_initialize(inode);
3771 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3772 - (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3773 + (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3774 + (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3775 rc = dquot_transfer(inode, iattr);
3778 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3779 #ifdef CONFIG_JFS_POSIX_ACL
3780 .get_acl = jfs_get_acl,
3782 + .sync_flags = jfs_sync_flags,
3785 const struct file_operations jfs_file_operations = {
3786 diff -NurpP --minimal linux-3.9.4/fs/jfs/ioctl.c linux-3.9.4-vs2.3.6.2/fs/jfs/ioctl.c
3787 --- linux-3.9.4/fs/jfs/ioctl.c 2013-05-31 13:45:24.000000000 +0000
3788 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/ioctl.c 2013-05-31 14:47:11.000000000 +0000
3790 #include <linux/time.h>
3791 #include <linux/sched.h>
3792 #include <linux/blkdev.h>
3793 +#include <linux/mount.h>
3794 #include <asm/current.h>
3795 #include <asm/uaccess.h>
3797 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3801 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3803 + inode->i_flags = flags;
3804 + inode->i_vflags = vflags;
3805 + jfs_get_inode_flags(JFS_IP(inode));
3806 + inode->i_ctime = CURRENT_TIME_SEC;
3807 + mark_inode_dirty(inode);
3811 long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3813 struct inode *inode = file_inode(filp);
3814 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3815 if (!S_ISDIR(inode->i_mode))
3816 flags &= ~JFS_DIRSYNC_FL;
3818 + if (IS_BARRIER(inode)) {
3819 + vxwprintk_task(1, "messing with the barrier.");
3823 /* Is it quota file? Do not allow user to mess with it */
3824 if (IS_NOQUOTA(inode)) {
3826 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3827 * the relevant capability.
3829 if ((oldflags & JFS_IMMUTABLE_FL) ||
3830 - ((flags ^ oldflags) &
3831 - (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3832 + ((flags ^ oldflags) & (JFS_APPEND_FL |
3833 + JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3834 if (!capable(CAP_LINUX_IMMUTABLE)) {
3835 mutex_unlock(&inode->i_mutex);
3837 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3841 - flags = flags & JFS_FL_USER_MODIFIABLE;
3842 + flags &= JFS_FL_USER_MODIFIABLE;
3843 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3844 jfs_inode->mode2 = flags;
3846 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_dinode.h linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_dinode.h
3847 --- linux-3.9.4/fs/jfs/jfs_dinode.h 2012-12-11 03:30:57.000000000 +0000
3848 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_dinode.h 2013-05-31 14:47:11.000000000 +0000
3849 @@ -161,9 +161,13 @@ struct dinode {
3851 #define JFS_APPEND_FL 0x01000000 /* writes to file may only append */
3852 #define JFS_IMMUTABLE_FL 0x02000000 /* Immutable file */
3853 +#define JFS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
3855 -#define JFS_FL_USER_VISIBLE 0x03F80000
3856 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3857 +#define JFS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
3858 +#define JFS_COW_FL 0x20000000 /* Copy on Write marker */
3860 +#define JFS_FL_USER_VISIBLE 0x07F80000
3861 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3862 #define JFS_FL_INHERIT 0x03C80000
3864 /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3865 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_filsys.h linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_filsys.h
3866 --- linux-3.9.4/fs/jfs/jfs_filsys.h 2012-12-11 03:30:57.000000000 +0000
3867 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_filsys.h 2013-05-31 14:47:11.000000000 +0000
3869 #define JFS_NAME_MAX 255
3870 #define JFS_PATH_MAX BPSIZE
3872 +#define JFS_TAGGED 0x00800000 /* Context Tagging */
3875 * file system state (superblock state)
3876 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_imap.c linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_imap.c
3877 --- linux-3.9.4/fs/jfs/jfs_imap.c 2012-12-11 03:30:57.000000000 +0000
3878 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_imap.c 2013-05-31 14:47:11.000000000 +0000
3880 #include <linux/pagemap.h>
3881 #include <linux/quotaops.h>
3882 #include <linux/slab.h>
3883 +#include <linux/vs_tag.h>
3885 #include "jfs_incore.h"
3886 #include "jfs_inode.h"
3887 @@ -3058,6 +3059,8 @@ static int copy_from_dinode(struct dinod
3889 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3890 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3894 jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3895 jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3896 @@ -3078,14 +3081,19 @@ static int copy_from_dinode(struct dinod
3898 set_nlink(ip, le32_to_cpu(dip->di_nlink));
3900 - jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3901 + uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3902 + gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3903 + ip->i_tag = make_ktag(&init_user_ns,
3904 + INOTAG_TAG(DX_TAG(ip), uid, gid, 0));
3906 + jfs_ip->saved_uid = INOTAG_UID(DX_TAG(ip), uid, gid);
3907 if (!uid_valid(sbi->uid))
3908 ip->i_uid = jfs_ip->saved_uid;
3910 ip->i_uid = sbi->uid;
3913 - jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3914 + jfs_ip->saved_gid = INOTAG_GID(DX_TAG(ip), uid, gid);
3915 if (!gid_valid(sbi->gid))
3916 ip->i_gid = jfs_ip->saved_gid;
3918 @@ -3150,16 +3158,14 @@ static void copy_to_dinode(struct dinode
3919 dip->di_size = cpu_to_le64(ip->i_size);
3920 dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3921 dip->di_nlink = cpu_to_le32(ip->i_nlink);
3922 - if (!uid_valid(sbi->uid))
3923 - dip->di_uid = cpu_to_le32(i_uid_read(ip));
3925 - dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3926 - jfs_ip->saved_uid));
3927 - if (!gid_valid(sbi->gid))
3928 - dip->di_gid = cpu_to_le32(i_gid_read(ip));
3930 - dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3931 - jfs_ip->saved_gid));
3932 + dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3933 + TAGINO_UID(DX_TAG(ip),
3934 + !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3936 + dip->di_gid = cpu_to_le32(from_kuid(&init_user_ns,
3937 + TAGINO_GID(DX_TAG(ip),
3938 + !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3940 jfs_get_inode_flags(jfs_ip);
3942 * mode2 is only needed for storing the higher order bits.
3943 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_inode.c linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_inode.c
3944 --- linux-3.9.4/fs/jfs/jfs_inode.c 2012-12-11 03:30:57.000000000 +0000
3945 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_inode.c 2013-05-31 14:47:11.000000000 +0000
3948 #include <linux/fs.h>
3949 #include <linux/quotaops.h>
3950 +#include <linux/vs_tag.h>
3951 #include "jfs_incore.h"
3952 #include "jfs_inode.h"
3953 #include "jfs_filsys.h"
3954 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3956 unsigned int flags = JFS_IP(inode)->mode2;
3958 - inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3959 - S_NOATIME | S_DIRSYNC | S_SYNC);
3960 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3961 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3963 if (flags & JFS_IMMUTABLE_FL)
3964 inode->i_flags |= S_IMMUTABLE;
3965 + if (flags & JFS_IXUNLINK_FL)
3966 + inode->i_flags |= S_IXUNLINK;
3968 + if (flags & JFS_SYNC_FL)
3969 + inode->i_flags |= S_SYNC;
3970 if (flags & JFS_APPEND_FL)
3971 inode->i_flags |= S_APPEND;
3972 if (flags & JFS_NOATIME_FL)
3973 inode->i_flags |= S_NOATIME;
3974 if (flags & JFS_DIRSYNC_FL)
3975 inode->i_flags |= S_DIRSYNC;
3976 - if (flags & JFS_SYNC_FL)
3977 - inode->i_flags |= S_SYNC;
3979 + inode->i_vflags &= ~(V_BARRIER | V_COW);
3981 + if (flags & JFS_BARRIER_FL)
3982 + inode->i_vflags |= V_BARRIER;
3983 + if (flags & JFS_COW_FL)
3984 + inode->i_vflags |= V_COW;
3987 void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3989 unsigned int flags = jfs_ip->vfs_inode.i_flags;
3990 + unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3992 + jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3993 + JFS_APPEND_FL | JFS_NOATIME_FL |
3994 + JFS_DIRSYNC_FL | JFS_SYNC_FL |
3995 + JFS_BARRIER_FL | JFS_COW_FL);
3997 - jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3998 - JFS_DIRSYNC_FL | JFS_SYNC_FL);
3999 if (flags & S_IMMUTABLE)
4000 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
4001 + if (flags & S_IXUNLINK)
4002 + jfs_ip->mode2 |= JFS_IXUNLINK_FL;
4004 if (flags & S_APPEND)
4005 jfs_ip->mode2 |= JFS_APPEND_FL;
4006 if (flags & S_NOATIME)
4007 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
4008 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
4010 jfs_ip->mode2 |= JFS_SYNC_FL;
4012 + if (vflags & V_BARRIER)
4013 + jfs_ip->mode2 |= JFS_BARRIER_FL;
4014 + if (vflags & V_COW)
4015 + jfs_ip->mode2 |= JFS_COW_FL;
4019 diff -NurpP --minimal linux-3.9.4/fs/jfs/jfs_inode.h linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_inode.h
4020 --- linux-3.9.4/fs/jfs/jfs_inode.h 2012-12-11 03:30:57.000000000 +0000
4021 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/jfs_inode.h 2013-05-31 14:47:11.000000000 +0000
4022 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
4023 extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
4024 int fh_len, int fh_type);
4025 extern void jfs_set_inode_flags(struct inode *);
4026 +extern int jfs_sync_flags(struct inode *, int, int);
4027 extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
4028 extern int jfs_setattr(struct dentry *, struct iattr *);
4030 diff -NurpP --minimal linux-3.9.4/fs/jfs/namei.c linux-3.9.4-vs2.3.6.2/fs/jfs/namei.c
4031 --- linux-3.9.4/fs/jfs/namei.c 2012-12-11 03:30:57.000000000 +0000
4032 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/namei.c 2013-05-31 14:47:11.000000000 +0000
4034 #include <linux/ctype.h>
4035 #include <linux/quotaops.h>
4036 #include <linux/exportfs.h>
4037 +#include <linux/vs_tag.h>
4038 #include "jfs_incore.h"
4039 #include "jfs_superblock.h"
4040 #include "jfs_inode.h"
4041 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
4042 jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
4045 + dx_propagate_tag(nd, ip);
4046 return d_splice_alias(ip, dentry);
4049 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
4050 #ifdef CONFIG_JFS_POSIX_ACL
4051 .get_acl = jfs_get_acl,
4053 + .sync_flags = jfs_sync_flags,
4056 const struct file_operations jfs_dir_operations = {
4057 diff -NurpP --minimal linux-3.9.4/fs/jfs/super.c linux-3.9.4-vs2.3.6.2/fs/jfs/super.c
4058 --- linux-3.9.4/fs/jfs/super.c 2013-05-31 13:45:24.000000000 +0000
4059 +++ linux-3.9.4-vs2.3.6.2/fs/jfs/super.c 2013-05-31 14:47:11.000000000 +0000
4060 @@ -199,7 +199,8 @@ enum {
4061 Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
4062 Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
4063 Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
4064 - Opt_discard, Opt_nodiscard, Opt_discard_minblk
4065 + Opt_discard, Opt_nodiscard, Opt_discard_minblk,
4066 + Opt_tag, Opt_notag, Opt_tagid
4069 static const match_table_t tokens = {
4070 @@ -209,6 +210,10 @@ static const match_table_t tokens = {
4071 {Opt_resize, "resize=%u"},
4072 {Opt_resize_nosize, "resize"},
4073 {Opt_errors, "errors=%s"},
4075 + {Opt_notag, "notag"},
4076 + {Opt_tagid, "tagid=%u"},
4077 + {Opt_tag, "tagxid"},
4078 {Opt_ignore, "noquota"},
4079 {Opt_ignore, "quota"},
4080 {Opt_usrquota, "usrquota"},
4081 @@ -385,7 +390,20 @@ static int parse_options(char *options,
4086 +#ifndef CONFIG_TAGGING_NONE
4088 + *flag |= JFS_TAGGED;
4091 + *flag &= JFS_TAGGED;
4094 +#ifdef CONFIG_PROPAGATE
4097 + *flag |= JFS_TAGGED;
4101 printk("jfs: Unrecognized mount option \"%s\" "
4102 " or missing value\n", p);
4103 @@ -417,6 +435,12 @@ static int jfs_remount(struct super_bloc
4107 + if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
4108 + printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
4114 if (sb->s_flags & MS_RDONLY) {
4115 pr_err("JFS: resize requires volume" \
4116 @@ -502,6 +526,9 @@ static int jfs_fill_super(struct super_b
4117 #ifdef CONFIG_JFS_POSIX_ACL
4118 sb->s_flags |= MS_POSIXACL;
4120 + /* map mount option tagxid */
4121 + if (sbi->flag & JFS_TAGGED)
4122 + sb->s_flags |= MS_TAGGED;
4125 pr_err("resize option for remount only\n");
4126 diff -NurpP --minimal linux-3.9.4/fs/libfs.c linux-3.9.4-vs2.3.6.2/fs/libfs.c
4127 --- linux-3.9.4/fs/libfs.c 2013-02-19 13:58:48.000000000 +0000
4128 +++ linux-3.9.4-vs2.3.6.2/fs/libfs.c 2013-05-31 14:47:11.000000000 +0000
4129 @@ -135,7 +135,8 @@ static inline unsigned char dt_type(stru
4130 * both impossible due to the lock on directory.
4133 -int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
4134 +static inline int do_dcache_readdir_filter(struct file *filp,
4135 + void *dirent, filldir_t filldir, int (*filter)(struct dentry *dentry))
4137 struct dentry *dentry = filp->f_path.dentry;
4138 struct dentry *cursor = filp->private_data;
4139 @@ -166,6 +167,8 @@ int dcache_readdir(struct file * filp, v
4140 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
4141 struct dentry *next;
4142 next = list_entry(p, struct dentry, d_u.d_child);
4143 + if (filter && !filter(next))
4145 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4146 if (!simple_positive(next)) {
4147 spin_unlock(&next->d_lock);
4148 @@ -192,6 +195,17 @@ int dcache_readdir(struct file * filp, v
4152 +int dcache_readdir(struct file *filp, void *dirent, filldir_t filldir)
4154 + return do_dcache_readdir_filter(filp, dirent, filldir, NULL);
4157 +int dcache_readdir_filter(struct file *filp, void *dirent, filldir_t filldir,
4158 + int (*filter)(struct dentry *))
4160 + return do_dcache_readdir_filter(filp, dirent, filldir, filter);
4163 ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4166 @@ -981,6 +995,7 @@ EXPORT_SYMBOL(dcache_dir_close);
4167 EXPORT_SYMBOL(dcache_dir_lseek);
4168 EXPORT_SYMBOL(dcache_dir_open);
4169 EXPORT_SYMBOL(dcache_readdir);
4170 +EXPORT_SYMBOL(dcache_readdir_filter);
4171 EXPORT_SYMBOL(generic_read_dir);
4172 EXPORT_SYMBOL(mount_pseudo);
4173 EXPORT_SYMBOL(simple_write_begin);
4174 diff -NurpP --minimal linux-3.9.4/fs/locks.c linux-3.9.4-vs2.3.6.2/fs/locks.c
4175 --- linux-3.9.4/fs/locks.c 2013-05-31 13:45:24.000000000 +0000
4176 +++ linux-3.9.4-vs2.3.6.2/fs/locks.c 2013-05-31 15:53:57.000000000 +0000
4178 #include <linux/time.h>
4179 #include <linux/rcupdate.h>
4180 #include <linux/pid_namespace.h>
4181 +#include <linux/vs_base.h>
4182 +#include <linux/vs_limit.h>
4184 #include <asm/uaccess.h>
4186 @@ -184,11 +186,17 @@ static void locks_init_lock_heads(struct
4187 /* Allocate an empty lock structure. */
4188 struct file_lock *locks_alloc_lock(void)
4190 - struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4191 + struct file_lock *fl;
4194 - locks_init_lock_heads(fl);
4195 + if (!vx_locks_avail(1))
4198 + fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4201 + locks_init_lock_heads(fl);
4206 EXPORT_SYMBOL_GPL(locks_alloc_lock);
4207 @@ -212,6 +220,7 @@ void locks_free_lock(struct file_lock *f
4208 BUG_ON(!list_empty(&fl->fl_block));
4209 BUG_ON(!list_empty(&fl->fl_link));
4212 locks_release_private(fl);
4213 kmem_cache_free(filelock_cache, fl);
4215 @@ -221,6 +230,7 @@ void locks_init_lock(struct file_lock *f
4217 memset(fl, 0, sizeof(struct file_lock));
4218 locks_init_lock_heads(fl);
4222 EXPORT_SYMBOL(locks_init_lock);
4223 @@ -261,6 +271,7 @@ void locks_copy_lock(struct file_lock *n
4224 new->fl_file = fl->fl_file;
4225 new->fl_ops = fl->fl_ops;
4226 new->fl_lmops = fl->fl_lmops;
4227 + new->fl_xid = fl->fl_xid;
4229 locks_copy_private(new, fl);
4231 @@ -299,6 +310,11 @@ static int flock_make_lock(struct file *
4232 fl->fl_flags = FL_FLOCK;
4234 fl->fl_end = OFFSET_MAX;
4236 + vxd_assert(filp->f_xid == vx_current_xid(),
4237 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4238 + fl->fl_xid = filp->f_xid;
4243 @@ -438,6 +454,7 @@ static int lease_init(struct file *filp,
4245 fl->fl_owner = current->files;
4246 fl->fl_pid = current->tgid;
4247 + fl->fl_xid = vx_current_xid();
4250 fl->fl_flags = FL_LEASE;
4251 @@ -457,6 +474,11 @@ static struct file_lock *lease_alloc(str
4253 return ERR_PTR(error);
4255 + fl->fl_xid = vx_current_xid();
4257 + vxd_assert(filp->f_xid == fl->fl_xid,
4258 + "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4260 error = lease_init(filp, type, fl);
4262 locks_free_lock(fl);
4263 @@ -753,6 +775,7 @@ static int flock_lock_file(struct file *
4267 + new_fl->fl_xid = -1;
4269 for_each_lock(inode, before) {
4270 struct file_lock *fl = *before;
4271 @@ -773,6 +796,7 @@ find_conflict:
4273 locks_copy_lock(new_fl, request);
4274 locks_insert_lock(before, new_fl);
4275 + vx_locks_inc(new_fl);
4279 @@ -783,7 +807,8 @@ out:
4283 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4284 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4285 + struct file_lock *conflock, xid_t xid)
4287 struct file_lock *fl;
4288 struct file_lock *new_fl = NULL;
4289 @@ -793,6 +818,8 @@ static int __posix_lock_file(struct inod
4290 struct file_lock **before;
4291 int error, added = 0;
4293 + vxd_assert(xid == vx_current_xid(),
4294 + "xid(%d) == current(%d)", xid, vx_current_xid());
4296 * We may need two file_lock structures for this operation,
4297 * so we get them in advance to avoid races.
4298 @@ -803,7 +830,11 @@ static int __posix_lock_file(struct inod
4299 (request->fl_type != F_UNLCK ||
4300 request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4301 new_fl = locks_alloc_lock();
4302 + new_fl->fl_xid = xid;
4303 + vx_locks_inc(new_fl);
4304 new_fl2 = locks_alloc_lock();
4305 + new_fl2->fl_xid = xid;
4306 + vx_locks_inc(new_fl2);
4310 @@ -1002,7 +1033,8 @@ static int __posix_lock_file(struct inod
4311 int posix_lock_file(struct file *filp, struct file_lock *fl,
4312 struct file_lock *conflock)
4314 - return __posix_lock_file(file_inode(filp), fl, conflock);
4315 + return __posix_lock_file(file_inode(filp),
4316 + fl, conflock, filp->f_xid);
4318 EXPORT_SYMBOL(posix_lock_file);
4320 @@ -1092,7 +1124,7 @@ int locks_mandatory_area(int read_write,
4321 fl.fl_end = offset + count - 1;
4324 - error = __posix_lock_file(inode, &fl, NULL);
4325 + error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4326 if (error != FILE_LOCK_DEFERRED)
4328 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4329 @@ -1397,6 +1429,7 @@ int generic_add_lease(struct file *filp,
4332 locks_insert_lock(before, lease);
4333 + vx_locks_inc(lease);
4337 @@ -1836,6 +1869,11 @@ int fcntl_setlk(unsigned int fd, struct
4338 if (file_lock == NULL)
4341 + vxd_assert(filp->f_xid == vx_current_xid(),
4342 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4343 + file_lock->fl_xid = filp->f_xid;
4344 + vx_locks_inc(file_lock);
4347 * This might block, so we do it before checking the inode.
4349 @@ -1954,6 +1992,11 @@ int fcntl_setlk64(unsigned int fd, struc
4350 if (file_lock == NULL)
4353 + vxd_assert(filp->f_xid == vx_current_xid(),
4354 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4355 + file_lock->fl_xid = filp->f_xid;
4356 + vx_locks_inc(file_lock);
4359 * This might block, so we do it before checking the inode.
4361 @@ -2219,8 +2262,11 @@ static int locks_show(struct seq_file *f
4363 lock_get_status(f, fl, *((loff_t *)f->private), "");
4365 - list_for_each_entry(bfl, &fl->fl_block, fl_block)
4366 + list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4367 + if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4369 lock_get_status(f, bfl, *((loff_t *)f->private), " ->");
4374 diff -NurpP --minimal linux-3.9.4/fs/mount.h linux-3.9.4-vs2.3.6.2/fs/mount.h
4375 --- linux-3.9.4/fs/mount.h 2013-02-19 13:58:48.000000000 +0000
4376 +++ linux-3.9.4-vs2.3.6.2/fs/mount.h 2013-05-31 14:47:11.000000000 +0000
4377 @@ -49,6 +49,7 @@ struct mount {
4378 int mnt_expiry_mark; /* true if marked for expiry */
4381 + tag_t mnt_tag; /* tagging used for vfsmount */
4384 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4385 diff -NurpP --minimal linux-3.9.4/fs/namei.c linux-3.9.4-vs2.3.6.2/fs/namei.c
4386 --- linux-3.9.4/fs/namei.c 2013-05-31 14:22:27.000000000 +0000
4387 +++ linux-3.9.4-vs2.3.6.2/fs/namei.c 2013-06-01 09:00:16.000000000 +0000
4389 #include <linux/device_cgroup.h>
4390 #include <linux/fs_struct.h>
4391 #include <linux/posix_acl.h>
4392 +#include <linux/proc_fs.h>
4393 +#include <linux/vserver/inode.h>
4394 +#include <linux/vs_base.h>
4395 +#include <linux/vs_tag.h>
4396 +#include <linux/vs_cowbl.h>
4397 +#include <linux/vs_device.h>
4398 +#include <linux/vs_context.h>
4399 +#include <linux/pid_namespace.h>
4400 #include <asm/uaccess.h>
4402 #include "internal.h"
4403 @@ -266,6 +274,89 @@ static int check_acl(struct inode *inode
4407 +static inline int dx_barrier(const struct inode *inode)
4409 + if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4410 + vxwprintk_task(1, "did hit the barrier.");
4416 +static int __dx_permission(const struct inode *inode, int mask)
4418 + if (dx_barrier(inode))
4421 + if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4422 + /* devpts is xid tagged */
4423 + if (S_ISDIR(inode->i_mode) ||
4424 + vx_check((xid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4427 + /* just pretend we didn't find anything */
4430 + else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4431 + struct proc_dir_entry *de = PDE(inode);
4433 + if (de && !vx_hide_check(0, de->vx_flags))
4436 + if ((mask & (MAY_WRITE | MAY_APPEND))) {
4438 + struct task_struct *tsk;
4440 + if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4441 + vx_flags(VXF_STATE_SETUP, 0))
4444 + pid = PROC_I(inode)->pid;
4449 + tsk = pid_task(pid, PIDTYPE_PID);
4450 + vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4451 + tsk, (tsk ? vx_task_xid(tsk) : 0));
4453 + vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4454 + rcu_read_unlock();
4457 + rcu_read_unlock();
4460 + /* FIXME: Should we block some entries here? */
4465 + if (dx_notagcheck(inode->i_sb) ||
4466 + dx_check((xid_t)i_tag_read(inode),
4467 + DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4475 +int dx_permission(const struct inode *inode, int mask)
4477 + int ret = __dx_permission(inode, mask);
4478 + if (unlikely(ret)) {
4479 +#ifndef CONFIG_VSERVER_WARN_DEVPTS
4480 + if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4483 + "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4484 + mask, inode->i_sb->s_id, inode,
4485 + i_tag_read(inode), inode->i_ino);
4491 * This does the basic permission checking
4493 @@ -388,10 +479,14 @@ int __inode_permission(struct inode *ino
4495 * Nobody gets write access to an immutable file.
4497 - if (IS_IMMUTABLE(inode))
4498 + if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4502 + retval = dx_permission(inode, mask);
4506 retval = do_inode_permission(inode, mask);
4509 @@ -1238,7 +1333,8 @@ static void follow_dotdot(struct nameida
4511 if (nd->path.dentry == nd->root.dentry &&
4512 nd->path.mnt == nd->root.mnt) {
4514 + /* for sane '/' avoid follow_mount() */
4517 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4518 /* rare case of legitimate dget_parent()... */
4519 @@ -1383,6 +1479,9 @@ static int lookup_fast(struct nameidata
4524 + /* FIXME: check dx permission */
4527 path->dentry = dentry;
4528 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4529 @@ -1413,6 +1512,8 @@ unlazy:
4533 + /* FIXME: check dx permission */
4536 path->dentry = dentry;
4537 err = follow_managed(path, nd->flags);
4538 @@ -2237,7 +2338,7 @@ static int may_delete(struct inode *dir,
4541 if (check_sticky(dir, victim->d_inode)||IS_APPEND(victim->d_inode)||
4542 - IS_IMMUTABLE(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4543 + IS_IXORUNLINK(victim->d_inode) || IS_SWAPFILE(victim->d_inode))
4546 if (!S_ISDIR(victim->d_inode->i_mode))
4547 @@ -2316,19 +2417,25 @@ int vfs_create(struct inode *dir, struct
4550 int error = may_create(dir, dentry);
4553 + vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4557 if (!dir->i_op->create)
4558 return -EACCES; /* shouldn't it be ENOSYS? */
4561 error = security_inode_create(dir, dentry, mode);
4564 + vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4567 error = dir->i_op->create(dir, dentry, mode, want_excl);
4569 fsnotify_create(dir, dentry);
4571 + vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4575 @@ -2363,6 +2470,15 @@ static int may_open(struct path *path, i
4579 +#ifdef CONFIG_VSERVER_COWBL
4580 + if (IS_COW(inode) &&
4581 + ((flag & O_ACCMODE) != O_RDONLY)) {
4582 + if (IS_COW_LINK(inode))
4584 + inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4585 + mark_inode_dirty(inode);
4588 error = inode_permission(inode, acc_mode);
4591 @@ -2865,6 +2981,16 @@ finish_open:
4593 finish_open_created:
4594 error = may_open(&nd->path, acc_mode, open_flag);
4595 +#ifdef CONFIG_VSERVER_COWBL
4596 + if (error == -EMLINK) {
4597 + struct dentry *dentry;
4598 + dentry = cow_break_link(name->name);
4599 + if (IS_ERR(dentry))
4600 + error = PTR_ERR(dentry);
4607 file->f_path.mnt = nd->path.mnt;
4608 @@ -2929,6 +3055,7 @@ static struct file *path_openat(int dfd,
4613 file = get_empty_filp();
4616 @@ -2965,6 +3092,16 @@ static struct file *path_openat(int dfd,
4617 error = do_last(nd, &path, file, op, &opened, pathname);
4618 put_link(nd, &link, cookie);
4621 +#ifdef CONFIG_VSERVER_COWBL
4622 + if (error == -EMLINK) {
4623 + if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4624 + path_put(&nd->root);
4631 if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4632 path_put(&nd->root);
4633 @@ -3079,6 +3216,11 @@ struct dentry *kern_path_create(int dfd,
4637 + vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4638 + path->dentry, path->dentry->d_name.len,
4639 + path->dentry->d_name.name, dentry,
4640 + dentry->d_name.len, dentry->d_name.name,
4641 + path->dentry->d_inode);
4645 @@ -3573,7 +3715,7 @@ int vfs_link(struct dentry *old_dentry,
4647 * A link to an append-only or immutable file cannot be created.
4649 - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4650 + if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4652 if (!dir->i_op->link)
4654 @@ -3976,6 +4118,286 @@ int vfs_follow_link(struct nameidata *nd
4655 return __vfs_follow_link(nd, link);
4659 +#ifdef CONFIG_VSERVER_COWBL
4662 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4666 + return do_splice_direct(in, &ppos, out, len, 0);
4669 +struct dentry *cow_break_link(const char *pathname)
4671 + int ret, mode, pathlen, redo = 0, drop = 1;
4672 + struct nameidata old_nd, dir_nd;
4673 + struct path dir_path, *old_path, *new_path;
4674 + struct dentry *dir, *old_dentry, *new_dentry = NULL;
4675 + struct file *old_file;
4676 + struct file *new_file;
4677 + char *to, *path, pad='\251';
4680 + vxdprintk(VXD_CBIT(misc, 1),
4681 + "cow_break_link(" VS_Q("%s") ")", pathname);
4683 + path = kmalloc(PATH_MAX, GFP_KERNEL);
4688 + /* old_nd.path will have refs to dentry and mnt */
4689 + ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4690 + vxdprintk(VXD_CBIT(misc, 2),
4691 + "do_path_lookup(old): %d", ret);
4693 + goto out_free_path;
4695 + /* dentry/mnt refs handed over to old_path */
4696 + old_path = &old_nd.path;
4697 + /* no explicit reference for old_dentry here */
4698 + old_dentry = old_path->dentry;
4700 + mode = old_dentry->d_inode->i_mode;
4701 + to = d_path(old_path, path, PATH_MAX-2);
4702 + pathlen = strlen(to);
4703 + vxdprintk(VXD_CBIT(misc, 2),
4704 + "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4706 + old_dentry->d_name.len, old_dentry->d_name.name,
4707 + old_dentry->d_name.len);
4709 + to[pathlen + 1] = 0;
4711 + new_dentry = NULL;
4712 + to[pathlen] = pad--;
4714 + if (pad <= '\240')
4717 + vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4719 + /* dir_nd.path will have refs to dentry and mnt */
4720 + ret = do_path_lookup(AT_FDCWD, to,
4721 + LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4722 + vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4726 + /* this puppy downs the dir inode mutex if successful.
4727 + dir_path will hold refs to dentry and mnt and
4728 + we'll have write access to the mnt */
4729 + new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4730 + if (!new_dentry || IS_ERR(new_dentry)) {
4731 + path_put(&dir_nd.path);
4732 + vxdprintk(VXD_CBIT(misc, 2),
4733 + "kern_path_create(new) failed with %ld",
4734 + PTR_ERR(new_dentry));
4737 + vxdprintk(VXD_CBIT(misc, 2),
4738 + "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4740 + new_dentry->d_name.len, new_dentry->d_name.name,
4741 + new_dentry->d_name.len);
4743 + /* take a reference on new_dentry */
4746 + /* dentry/mnt refs handed over to new_path */
4747 + new_path = &dir_path;
4749 + /* dentry for old/new dir */
4750 + dir = dir_nd.path.dentry;
4752 + /* give up reference on dir */
4753 + dput(new_path->dentry);
4755 + /* new_dentry already has a reference */
4756 + new_path->dentry = new_dentry;
4758 + ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4759 + vxdprintk(VXD_CBIT(misc, 2),
4760 + "vfs_create(new): %d", ret);
4761 + if (ret == -EEXIST) {
4762 + path_put(&dir_nd.path);
4763 + mutex_unlock(&dir->d_inode->i_mutex);
4764 + mnt_drop_write(new_path->mnt);
4765 + path_put(new_path);
4766 + new_dentry = NULL;
4770 + goto out_unlock_new;
4772 + /* drop out early, ret passes ENOENT */
4774 + if ((redo = d_unhashed(old_dentry)))
4775 + goto out_unlock_new;
4777 + /* doesn't change refs for old_path */
4778 + old_file = dentry_open(old_path, O_RDONLY, current_cred());
4779 + vxdprintk(VXD_CBIT(misc, 2),
4780 + "dentry_open(old): %p", old_file);
4781 + if (IS_ERR(old_file)) {
4782 + ret = PTR_ERR(old_file);
4783 + goto out_unlock_new;
4786 + /* doesn't change refs for new_path */
4787 + new_file = dentry_open(new_path, O_WRONLY, current_cred());
4788 + vxdprintk(VXD_CBIT(misc, 2),
4789 + "dentry_open(new): %p", new_file);
4790 + if (IS_ERR(new_file)) {
4791 + ret = PTR_ERR(new_file);
4792 + goto out_fput_old;
4795 + /* unlock the inode mutex from kern_path_create() */
4796 + mutex_unlock(&dir->d_inode->i_mutex);
4798 + /* drop write access to mnt */
4799 + mnt_drop_write(new_path->mnt);
4803 + size = i_size_read(old_file->f_dentry->d_inode);
4804 + ret = do_cow_splice(old_file, new_file, size);
4805 + vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4807 + goto out_fput_both;
4808 + } else if (ret < size) {
4810 + goto out_fput_both;
4812 + struct inode *old_inode = old_dentry->d_inode;
4813 + struct inode *new_inode = new_dentry->d_inode;
4814 + struct iattr attr = {
4815 + .ia_uid = old_inode->i_uid,
4816 + .ia_gid = old_inode->i_gid,
4817 + .ia_valid = ATTR_UID | ATTR_GID
4820 + setattr_copy(new_inode, &attr);
4821 + mark_inode_dirty(new_inode);
4824 + /* lock rename mutex */
4825 + mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4827 + /* drop out late */
4829 + if ((redo = d_unhashed(old_dentry)))
4832 + vxdprintk(VXD_CBIT(misc, 2),
4833 + "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4834 + new_dentry->d_name.len, new_dentry->d_name.name,
4835 + new_dentry->d_name.len,
4836 + old_dentry->d_name.len, old_dentry->d_name.name,
4837 + old_dentry->d_name.len);
4838 + ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4839 + old_dentry->d_parent->d_inode, old_dentry);
4840 + vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4843 + mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4846 + vxdprintk(VXD_CBIT(misc, 3),
4847 + "fput(new_file=%p[#%ld])", new_file,
4848 + atomic_long_read(&new_file->f_count));
4852 + vxdprintk(VXD_CBIT(misc, 3),
4853 + "fput(old_file=%p[#%ld])", old_file,
4854 + atomic_long_read(&old_file->f_count));
4858 + /* drop references from dir_nd.path */
4859 + path_put(&dir_nd.path);
4862 + /* unlock the inode mutex from kern_path_create() */
4863 + mutex_unlock(&dir->d_inode->i_mutex);
4865 + /* drop write access to mnt */
4866 + mnt_drop_write(new_path->mnt);
4872 + /* error path cleanup */
4873 + vfs_unlink(dir->d_inode, new_dentry);
4877 + goto out_rel_both;
4879 + /* lookup dentry once again
4880 + old_nd.path will be freed as old_path in out_rel_old */
4881 + ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4883 + goto out_rel_both;
4885 + /* drop reference on new_dentry */
4887 + new_dentry = old_path->dentry;
4889 + vxdprintk(VXD_CBIT(misc, 2),
4890 + "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4892 + new_dentry->d_name.len, new_dentry->d_name.name,
4893 + new_dentry->d_name.len);
4897 + path_put(new_path);
4899 + path_put(old_path);
4905 + new_dentry = ERR_PTR(ret);
4907 + vxdprintk(VXD_CBIT(misc, 3),
4908 + "cow_break_link returning with %p", new_dentry);
4909 + return new_dentry;
4914 +int vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4917 + struct vfsmount *vmnt;
4918 + char *pstr, *root;
4921 + pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4925 + vmnt = &ns->root->mnt;
4927 + path.dentry = vmnt->mnt_root;
4928 + root = d_path(&path, pstr, PATH_MAX - 2);
4929 + length = sprintf(buffer + length,
4930 + "Namespace:\t%p [#%u]\n"
4931 + "RootPath:\t%s\n",
4932 + ns, atomic_read(&ns->count),
4938 /* get the link contents into pagecache */
4939 static char *page_getlink(struct dentry * dentry, struct page **ppage)
4941 @@ -4099,3 +4521,4 @@ EXPORT_SYMBOL(vfs_symlink);
4942 EXPORT_SYMBOL(vfs_unlink);
4943 EXPORT_SYMBOL(dentry_unhash);
4944 EXPORT_SYMBOL(generic_readlink);
4945 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4946 diff -NurpP --minimal linux-3.9.4/fs/namespace.c linux-3.9.4-vs2.3.6.2/fs/namespace.c
4947 --- linux-3.9.4/fs/namespace.c 2013-05-31 14:22:27.000000000 +0000
4948 +++ linux-3.9.4-vs2.3.6.2/fs/namespace.c 2013-05-31 18:47:18.000000000 +0000
4950 #include <linux/fsnotify.h> /* fsnotify_vfsmount_delete */
4951 #include <linux/uaccess.h>
4952 #include <linux/proc_fs.h>
4953 +#include <linux/vs_base.h>
4954 +#include <linux/vs_context.h>
4955 +#include <linux/vs_tag.h>
4956 +#include <linux/vserver/space.h>
4957 +#include <linux/vserver/global.h>
4959 #include "internal.h"
4961 @@ -751,6 +756,10 @@ vfs_kern_mount(struct file_system_type *
4963 return ERR_PTR(-ENODEV);
4965 + if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4966 + !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4967 + return ERR_PTR(-EPERM);
4969 mnt = alloc_vfsmnt(name);
4971 return ERR_PTR(-ENOMEM);
4972 @@ -807,6 +816,7 @@ static struct mount *clone_mnt(struct mo
4973 mnt->mnt.mnt_root = dget(root);
4974 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4975 mnt->mnt_parent = mnt;
4976 + mnt->mnt_tag = old->mnt_tag;
4977 br_write_lock(&vfsmount_lock);
4978 list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4979 br_write_unlock(&vfsmount_lock);
4980 @@ -1639,6 +1649,7 @@ static int do_change_type(struct path *p
4984 + // mnt->mnt_flags = mnt_flags;
4986 br_write_lock(&vfsmount_lock);
4987 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4988 @@ -1654,12 +1665,14 @@ static int do_change_type(struct path *p
4989 * do loopback mount.
4991 static int do_loopback(struct path *path, const char *old_name,
4993 + tag_t tag, unsigned long flags, int mnt_flags)
4995 LIST_HEAD(umount_list);
4996 struct path old_path;
4997 struct mount *mnt = NULL, *old;
4998 + int recurse = flags & MS_REC;
5001 if (!old_name || !*old_name)
5003 err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
5004 @@ -1733,7 +1746,7 @@ static int change_mount_flags(struct vfs
5005 * on it - tough luck.
5007 static int do_remount(struct path *path, int flags, int mnt_flags,
5009 + void *data, xid_t xid)
5012 struct super_block *sb = path->mnt->mnt_sb;
5013 @@ -2046,7 +2059,6 @@ void mark_mounts_for_expiry(struct list_
5015 br_write_unlock(&vfsmount_lock);
5016 up_write(&namespace_sem);
5018 release_mounts(&umounts);
5021 @@ -2218,6 +2230,7 @@ long do_mount(const char *dev_name, cons
5028 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
5029 @@ -2247,6 +2260,12 @@ long do_mount(const char *dev_name, cons
5030 if (!(flags & MS_NOATIME))
5031 mnt_flags |= MNT_RELATIME;
5033 + if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
5034 + /* FIXME: bind and re-mounts get the tag flag? */
5035 + if (flags & (MS_BIND|MS_REMOUNT))
5036 + flags |= MS_TAGID;
5039 /* Separate the per-mountpoint flags */
5040 if (flags & MS_NOSUID)
5041 mnt_flags |= MNT_NOSUID;
5042 @@ -2263,15 +2282,17 @@ long do_mount(const char *dev_name, cons
5043 if (flags & MS_RDONLY)
5044 mnt_flags |= MNT_READONLY;
5046 + if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
5047 + mnt_flags |= MNT_NODEV;
5048 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
5049 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
5052 if (flags & MS_REMOUNT)
5053 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
5056 else if (flags & MS_BIND)
5057 - retval = do_loopback(&path, dev_name, flags & MS_REC);
5058 + retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
5059 else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
5060 retval = do_change_type(&path, flags);
5061 else if (flags & MS_MOVE)
5062 @@ -2380,6 +2401,7 @@ static struct mnt_namespace *dup_mnt_ns(
5063 q = next_mnt(q, new);
5065 up_write(&namespace_sem);
5066 + atomic_inc(&vs_global_mnt_ns);
5070 @@ -2575,9 +2597,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
5072 new_mnt = real_mount(new.mnt);
5073 root_mnt = real_mount(root.mnt);
5074 - if (IS_MNT_SHARED(real_mount(old.mnt)) ||
5075 + if ((IS_MNT_SHARED(real_mount(old.mnt)) ||
5076 IS_MNT_SHARED(new_mnt->mnt_parent) ||
5077 - IS_MNT_SHARED(root_mnt->mnt_parent))
5078 + IS_MNT_SHARED(root_mnt->mnt_parent)) &&
5079 + !vx_flags(VXF_STATE_SETUP, 0))
5081 if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
5083 @@ -2703,6 +2726,7 @@ void put_mnt_ns(struct mnt_namespace *ns
5084 br_write_unlock(&vfsmount_lock);
5085 up_write(&namespace_sem);
5086 release_mounts(&umount_list);
5087 + atomic_dec(&vs_global_mnt_ns);
5091 diff -NurpP --minimal linux-3.9.4/fs/nfs/client.c linux-3.9.4-vs2.3.6.2/fs/nfs/client.c
5092 --- linux-3.9.4/fs/nfs/client.c 2013-05-31 13:45:24.000000000 +0000
5093 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/client.c 2013-05-31 14:47:11.000000000 +0000
5094 @@ -682,6 +682,9 @@ int nfs_init_server_rpcclient(struct nfs
5095 if (server->flags & NFS_MOUNT_SOFT)
5096 server->client->cl_softrtry = 1;
5098 + server->client->cl_tag = 0;
5099 + if (server->flags & NFS_MOUNT_TAGGED)
5100 + server->client->cl_tag = 1;
5103 EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
5104 @@ -861,6 +864,10 @@ static void nfs_server_set_fsinfo(struct
5105 server->acdirmin = server->acdirmax = 0;
5108 + /* FIXME: needs fsinfo
5109 + if (server->flags & NFS_MOUNT_TAGGED)
5110 + sb->s_flags |= MS_TAGGED; */
5112 server->maxfilesize = fsinfo->maxfilesize;
5114 server->time_delta = fsinfo->time_delta;
5115 diff -NurpP --minimal linux-3.9.4/fs/nfs/dir.c linux-3.9.4-vs2.3.6.2/fs/nfs/dir.c
5116 --- linux-3.9.4/fs/nfs/dir.c 2013-05-31 13:45:24.000000000 +0000
5117 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/dir.c 2013-05-31 14:47:11.000000000 +0000
5119 #include <linux/sched.h>
5120 #include <linux/kmemleak.h>
5121 #include <linux/xattr.h>
5122 +#include <linux/vs_tag.h>
5124 #include "delegation.h"
5126 @@ -1300,6 +1301,7 @@ struct dentry *nfs_lookup(struct inode *
5127 /* Success: notify readdir to use READDIRPLUS */
5128 nfs_advise_use_readdirplus(dir);
5130 + dx_propagate_tag(nd, inode);
5132 res = d_materialise_unique(dentry, inode);
5134 diff -NurpP --minimal linux-3.9.4/fs/nfs/inode.c linux-3.9.4-vs2.3.6.2/fs/nfs/inode.c
5135 --- linux-3.9.4/fs/nfs/inode.c 2013-05-31 13:45:24.000000000 +0000
5136 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/inode.c 2013-05-31 20:37:45.000000000 +0000
5138 #include <linux/compat.h>
5139 #include <linux/freezer.h>
5140 #include <linux/crc32.h>
5141 +#include <linux/vs_tag.h>
5143 #include <asm/uaccess.h>
5145 @@ -290,6 +291,8 @@ nfs_fhget(struct super_block *sb, struct
5146 if (inode->i_state & I_NEW) {
5147 struct nfs_inode *nfsi = NFS_I(inode);
5148 unsigned long now = jiffies;
5152 /* We set i_ino for the few things that still rely on it,
5153 * such as stat(2) */
5154 @@ -334,8 +337,8 @@ nfs_fhget(struct super_block *sb, struct
5155 inode->i_version = 0;
5158 - inode->i_uid = make_kuid(&init_user_ns, -2);
5159 - inode->i_gid = make_kgid(&init_user_ns, -2);
5160 + uid = make_kuid(&init_user_ns, -2);
5161 + gid = make_kgid(&init_user_ns, -2);
5162 inode->i_blocks = 0;
5163 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5165 @@ -369,11 +372,11 @@ nfs_fhget(struct super_block *sb, struct
5166 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5167 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5168 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5169 - inode->i_uid = fattr->uid;
5171 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5172 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5173 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5174 - inode->i_gid = fattr->gid;
5176 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5177 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5178 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5179 @@ -384,6 +387,11 @@ nfs_fhget(struct super_block *sb, struct
5181 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5183 + inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5184 + inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5185 + inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, 0);
5186 + /* maybe fattr->xid someday */
5188 nfsi->attrtimeo = NFS_MINATTRTIMEO(inode);
5189 nfsi->attrtimeo_timestamp = now;
5190 nfsi->access_cache = RB_ROOT;
5191 @@ -505,6 +513,8 @@ void nfs_setattr_update_inode(struct ino
5192 inode->i_uid = attr->ia_uid;
5193 if ((attr->ia_valid & ATTR_GID) != 0)
5194 inode->i_gid = attr->ia_gid;
5195 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5196 + inode->i_tag = attr->ia_tag;
5197 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5198 spin_unlock(&inode->i_lock);
5200 @@ -980,6 +990,11 @@ static int nfs_check_inode_attributes(st
5201 struct nfs_inode *nfsi = NFS_I(inode);
5202 loff_t cur_size, new_isize;
5203 unsigned long invalid = 0;
5211 if (nfs_have_delegated_attributes(inode))
5212 @@ -1005,13 +1020,21 @@ static int nfs_check_inode_attributes(st
5213 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5216 + uid = from_kuid(&init_user_ns, fattr->uid);
5217 + gid = from_kgid(&init_user_ns, fattr->gid);
5219 + kuid = make_kuid(&init_user_ns, INOTAG_UID(DX_TAG(inode), uid, gid));
5220 + kgid = make_kgid(&init_user_ns, INOTAG_GID(DX_TAG(inode), uid, gid));
5221 + ktag = make_ktag(&init_user_ns, INOTAG_TAG(DX_TAG(inode), uid, gid, 0));
5223 /* Have any file permissions changed? */
5224 if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5225 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5226 - if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5227 + if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5228 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5229 - if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5230 + if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5231 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5232 + /* maybe check for tag too? */
5234 /* Has the link count changed? */
5235 if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5236 @@ -1317,6 +1340,9 @@ static int nfs_update_inode(struct inode
5237 unsigned long invalid = 0;
5238 unsigned long now = jiffies;
5239 unsigned long save_cache_validity;
5244 dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5245 __func__, inode->i_sb->s_id, inode->i_ino,
5246 @@ -1418,6 +1444,9 @@ static int nfs_update_inode(struct inode
5247 | NFS_INO_REVAL_PAGECACHE
5248 | NFS_INO_REVAL_FORCED);
5250 + uid = TAGINO_UID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5251 + gid = TAGINO_GID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5252 + tag = inode->i_tag;
5254 if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5255 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5256 @@ -1460,6 +1489,10 @@ static int nfs_update_inode(struct inode
5257 | NFS_INO_INVALID_ACL
5258 | NFS_INO_REVAL_FORCED);
5260 + inode->i_uid = INOTAG_UID(DX_TAG(inode), uid, gid);
5261 + inode->i_gid = INOTAG_GID(DX_TAG(inode), uid, gid);
5262 + inode->i_tag = INOTAG_TAG(DX_TAG(inode), uid, gid, tag);
5264 if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5265 if (inode->i_nlink != fattr->nlink) {
5266 invalid |= NFS_INO_INVALID_ATTR;
5267 diff -NurpP --minimal linux-3.9.4/fs/nfs/nfs3xdr.c linux-3.9.4-vs2.3.6.2/fs/nfs/nfs3xdr.c
5268 --- linux-3.9.4/fs/nfs/nfs3xdr.c 2013-05-31 13:45:24.000000000 +0000
5269 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/nfs3xdr.c 2013-05-31 15:33:48.000000000 +0000
5271 #include <linux/nfs3.h>
5272 #include <linux/nfs_fs.h>
5273 #include <linux/nfsacl.h>
5274 +#include <linux/vs_tag.h>
5275 #include "internal.h"
5277 #define NFSDBG_FACILITY NFSDBG_XDR
5278 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5282 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5283 +static void encode_sattr3(struct xdr_stream *xdr,
5284 + const struct iattr *attr, int tag)
5288 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5292 - if (attr->ia_valid & ATTR_UID) {
5293 + if (attr->ia_valid & ATTR_UID ||
5294 + (tag && (attr->ia_valid & ATTR_TAG))) {
5296 - *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5297 + *p++ = cpu_to_be32(TAGINO_UID(tag,
5298 + from_kuid(&init_user_ns, attr->ia_uid), attr->ia_tag));
5302 - if (attr->ia_valid & ATTR_GID) {
5303 + if (attr->ia_valid & ATTR_GID ||
5304 + (tag && (attr->ia_valid & ATTR_TAG))) {
5306 - *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5307 + *p++ = cpu_to_be32(TAGINO_GID(tag,
5308 + from_kgid(&init_user_ns, attr->ia_gid), attr->ia_tag));
5312 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5313 const struct nfs3_sattrargs *args)
5315 encode_nfs_fh3(xdr, args->fh);
5316 - encode_sattr3(xdr, args->sattr);
5317 + encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5318 encode_sattrguard3(xdr, args);
5321 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5324 static void encode_createhow3(struct xdr_stream *xdr,
5325 - const struct nfs3_createargs *args)
5326 + const struct nfs3_createargs *args, int tag)
5328 encode_uint32(xdr, args->createmode);
5329 switch (args->createmode) {
5330 case NFS3_CREATE_UNCHECKED:
5331 case NFS3_CREATE_GUARDED:
5332 - encode_sattr3(xdr, args->sattr);
5333 + encode_sattr3(xdr, args->sattr, tag);
5335 case NFS3_CREATE_EXCLUSIVE:
5336 encode_createverf3(xdr, args->verifier);
5337 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5338 const struct nfs3_createargs *args)
5340 encode_diropargs3(xdr, args->fh, args->name, args->len);
5341 - encode_createhow3(xdr, args);
5342 + encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5346 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5347 const struct nfs3_mkdirargs *args)
5349 encode_diropargs3(xdr, args->fh, args->name, args->len);
5350 - encode_sattr3(xdr, args->sattr);
5351 + encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5355 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5358 static void encode_symlinkdata3(struct xdr_stream *xdr,
5359 - const struct nfs3_symlinkargs *args)
5360 + const struct nfs3_symlinkargs *args, int tag)
5362 - encode_sattr3(xdr, args->sattr);
5363 + encode_sattr3(xdr, args->sattr, tag);
5364 encode_nfspath3(xdr, args->pages, args->pathlen);
5367 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5368 const struct nfs3_symlinkargs *args)
5370 encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5371 - encode_symlinkdata3(xdr, args);
5372 + encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5376 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5379 static void encode_devicedata3(struct xdr_stream *xdr,
5380 - const struct nfs3_mknodargs *args)
5381 + const struct nfs3_mknodargs *args, int tag)
5383 - encode_sattr3(xdr, args->sattr);
5384 + encode_sattr3(xdr, args->sattr, tag);
5385 encode_specdata3(xdr, args->rdev);
5388 static void encode_mknoddata3(struct xdr_stream *xdr,
5389 - const struct nfs3_mknodargs *args)
5390 + const struct nfs3_mknodargs *args, int tag)
5392 encode_ftype3(xdr, args->type);
5393 switch (args->type) {
5396 - encode_devicedata3(xdr, args);
5397 + encode_devicedata3(xdr, args, tag);
5401 - encode_sattr3(xdr, args->sattr);
5402 + encode_sattr3(xdr, args->sattr, tag);
5406 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5407 const struct nfs3_mknodargs *args)
5409 encode_diropargs3(xdr, args->fh, args->name, args->len);
5410 - encode_mknoddata3(xdr, args);
5411 + encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5415 diff -NurpP --minimal linux-3.9.4/fs/nfs/super.c linux-3.9.4-vs2.3.6.2/fs/nfs/super.c
5416 --- linux-3.9.4/fs/nfs/super.c 2013-05-31 13:45:24.000000000 +0000
5417 +++ linux-3.9.4-vs2.3.6.2/fs/nfs/super.c 2013-05-31 15:41:34.000000000 +0000
5419 #include <linux/parser.h>
5420 #include <linux/nsproxy.h>
5421 #include <linux/rcupdate.h>
5422 +#include <linux/vs_tag.h>
5424 #include <asm/uaccess.h>
5426 @@ -103,6 +104,7 @@ enum {
5432 /* Mount options that take string arguments */
5434 @@ -115,6 +117,9 @@ enum {
5435 /* Special mount options */
5436 Opt_userspace, Opt_deprecated, Opt_sloppy,
5438 + /* Linux-VServer tagging options */
5439 + Opt_tag, Opt_notag,
5444 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5445 { Opt_fscache_uniq, "fsc=%s" },
5446 { Opt_local_lock, "local_lock=%s" },
5448 + { Opt_tag, "tag" },
5449 + { Opt_notag, "notag" },
5450 + { Opt_tagid, "tagid=%u" },
5452 /* The following needs to be listed after all other options */
5453 { Opt_nfsvers, "v%s" },
5455 @@ -635,6 +644,7 @@ static void nfs_show_mount_options(struc
5456 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5457 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5458 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5459 + { NFS_MOUNT_TAGGED, ",tag", "" },
5462 const struct proc_nfs_info *nfs_infop;
5463 @@ -1261,6 +1271,14 @@ static int nfs_parse_mount_options(char
5464 case Opt_nomigration:
5465 mnt->options &= NFS_OPTION_MIGRATION;
5467 +#ifndef CONFIG_TAGGING_NONE
5469 + mnt->flags |= NFS_MOUNT_TAGGED;
5472 + mnt->flags &= ~NFS_MOUNT_TAGGED;
5477 * options that take numeric values
5478 @@ -1347,6 +1365,12 @@ static int nfs_parse_mount_options(char
5479 goto out_invalid_value;
5480 mnt->minorversion = option;
5482 +#ifdef CONFIG_PROPAGATE
5485 + nfs_data.flags |= NFS_MOUNT_TAGGED;
5490 * options that take text values
5491 diff -NurpP --minimal linux-3.9.4/fs/nfsd/auth.c linux-3.9.4-vs2.3.6.2/fs/nfsd/auth.c
5492 --- linux-3.9.4/fs/nfsd/auth.c 2013-05-31 13:45:24.000000000 +0000
5493 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/auth.c 2013-05-31 14:47:11.000000000 +0000
5496 #include <linux/sched.h>
5497 #include <linux/user_namespace.h>
5498 +#include <linux/vs_tag.h>
5502 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5504 new->fsuid = rqstp->rq_cred.cr_uid;
5505 new->fsgid = rqstp->rq_cred.cr_gid;
5506 + /* FIXME: this desperately needs a tag :)
5507 + new->xid = (xid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5510 rqgi = rqstp->rq_cred.cr_group_info;
5512 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfs3xdr.c linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs3xdr.c
5513 --- linux-3.9.4/fs/nfsd/nfs3xdr.c 2013-05-31 13:45:24.000000000 +0000
5514 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs3xdr.c 2013-05-31 16:17:38.000000000 +0000
5517 #include <linux/namei.h>
5518 #include <linux/sunrpc/svc_xprt.h>
5519 +#include <linux/vs_tag.h>
5523 @@ -98,6 +99,8 @@ static __be32 *
5524 decode_sattr3(__be32 *p, struct iattr *iap)
5532 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5533 iap->ia_mode = ntohl(*p++);
5536 - iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5537 + uid = make_kuid(&init_user_ns, ntohl(*p++));
5538 if (uid_valid(iap->ia_uid))
5539 iap->ia_valid |= ATTR_UID;
5542 - iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5543 + gid = make_kgid(&init_user_ns, ntohl(*p++));
5544 if (gid_valid(iap->ia_gid))
5545 iap->ia_valid |= ATTR_GID;
5547 + iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5548 + iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5549 + iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5553 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5554 *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5555 *p++ = htonl((u32) stat->mode);
5556 *p++ = htonl((u32) stat->nlink);
5557 - *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5558 - *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5559 + *p++ = htonl((u32) from_kuid(&init_user_ns,
5560 + TAGINO_UID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5561 + stat->uid, stat->tag)));
5562 + *p++ = htonl((u32) from_kgid(&init_user_ns,
5563 + TAGINO_GID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5564 + stat->gid, stat->tag)));
5565 if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5566 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5568 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfs4xdr.c linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs4xdr.c
5569 --- linux-3.9.4/fs/nfsd/nfs4xdr.c 2013-05-31 14:22:27.000000000 +0000
5570 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/nfs4xdr.c 2013-05-31 14:47:11.000000000 +0000
5572 #include <linux/utsname.h>
5573 #include <linux/pagemap.h>
5574 #include <linux/sunrpc/svcauth_gss.h>
5575 +#include <linux/vs_tag.h>
5579 @@ -2349,14 +2350,18 @@ out_acl:
5580 WRITE32(stat.nlink);
5582 if (bmval1 & FATTR4_WORD1_OWNER) {
5583 - status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5584 + status = nfsd4_encode_user(rqstp,
5585 + TAGINO_UID(DX_TAG(dentry->d_inode),
5586 + stat.uid, stat.tag), &p, &buflen);
5587 if (status == nfserr_resource)
5592 if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5593 - status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5594 + status = nfsd4_encode_group(rqstp,
5595 + TAGINO_GID(DX_TAG(dentry->d_inode),
5596 + stat.gid, stat.tag), &p, &buflen);
5597 if (status == nfserr_resource)
5600 diff -NurpP --minimal linux-3.9.4/fs/nfsd/nfsxdr.c linux-3.9.4-vs2.3.6.2/fs/nfsd/nfsxdr.c
5601 --- linux-3.9.4/fs/nfsd/nfsxdr.c 2013-05-31 13:45:24.000000000 +0000
5602 +++ linux-3.9.4-vs2.3.6.2/fs/nfsd/nfsxdr.c 2013-05-31 16:20:53.000000000 +0000
5607 +#include <linux/vs_tag.h>
5609 #define NFSDDBG_FACILITY NFSDDBG_XDR
5611 @@ -89,6 +90,8 @@ static __be32 *
5612 decode_sattr(__be32 *p, struct iattr *iap)
5620 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5623 if ((tmp = ntohl(*p++)) != (u32)-1) {
5624 - iap->ia_uid = make_kuid(&init_user_ns, tmp);
5625 + uid = make_kuid(&init_user_ns, tmp);
5626 if (uid_valid(iap->ia_uid))
5627 iap->ia_valid |= ATTR_UID;
5629 if ((tmp = ntohl(*p++)) != (u32)-1) {
5630 - iap->ia_gid = make_kgid(&init_user_ns, tmp);
5631 + gid = make_kgid(&init_user_ns, tmp);
5632 if (gid_valid(iap->ia_gid))
5633 iap->ia_valid |= ATTR_GID;
5635 + iap->ia_uid = INOTAG_UID(DX_TAG_NFSD, uid, gid);
5636 + iap->ia_gid = INOTAG_GID(DX_TAG_NFSD, uid, gid);
5637 + iap->ia_tag = INOTAG_TAG(DX_TAG_NFSD, uid, gid, 0);
5638 if ((tmp = ntohl(*p++)) != (u32)-1) {
5639 iap->ia_valid |= ATTR_SIZE;
5641 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5642 *p++ = htonl(nfs_ftypes[type >> 12]);
5643 *p++ = htonl((u32) stat->mode);
5644 *p++ = htonl((u32) stat->nlink);
5645 - *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5646 - *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5647 + *p++ = htonl((u32) from_kuid(&init_user_ns,
5648 + TAGINO_UID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5649 + *p++ = htonl((u32) from_kgid(&init_user_ns,
5650 + TAGINO_GID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5652 if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5653 *p++ = htonl(NFS_MAXPATHLEN);
5654 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/dlmglue.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.c
5655 --- linux-3.9.4/fs/ocfs2/dlmglue.c 2013-05-31 13:45:24.000000000 +0000
5656 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.c 2013-05-31 15:47:29.000000000 +0000
5657 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5658 lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5659 lvb->lvb_iuid = cpu_to_be32(i_uid_read(inode));
5660 lvb->lvb_igid = cpu_to_be32(i_gid_read(inode));
5661 + lvb->lvb_itag = cpu_to_be16(inode->i_tag);
5662 lvb->lvb_imode = cpu_to_be16(inode->i_mode);
5663 lvb->lvb_inlink = cpu_to_be16(inode->i_nlink);
5664 lvb->lvb_iatime_packed =
5665 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5667 i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5668 i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5669 + i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5670 inode->i_mode = be16_to_cpu(lvb->lvb_imode);
5671 set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5672 ocfs2_unpack_timespec(&inode->i_atime,
5673 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/dlmglue.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.h
5674 --- linux-3.9.4/fs/ocfs2/dlmglue.h 2012-12-11 03:30:57.000000000 +0000
5675 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/dlmglue.h 2013-05-31 14:47:11.000000000 +0000
5676 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5679 __be32 lvb_igeneration;
5680 - __be32 lvb_reserved2;
5682 + __be16 lvb_reserved2;
5685 #define OCFS2_QINFO_LVB_VERSION 1
5686 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/file.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/file.c
5687 --- linux-3.9.4/fs/ocfs2/file.c 2013-05-31 13:45:24.000000000 +0000
5688 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/file.c 2013-05-31 14:47:11.000000000 +0000
5689 @@ -1124,7 +1124,7 @@ int ocfs2_setattr(struct dentry *dentry,
5690 attr->ia_valid &= ~ATTR_SIZE;
5692 #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5693 - | ATTR_GID | ATTR_UID | ATTR_MODE)
5694 + | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5695 if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5698 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/inode.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.c
5699 --- linux-3.9.4/fs/ocfs2/inode.c 2013-05-31 13:45:24.000000000 +0000
5700 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.c 2013-05-31 20:39:47.000000000 +0000
5702 #include <linux/highmem.h>
5703 #include <linux/pagemap.h>
5704 #include <linux/quotaops.h>
5705 +#include <linux/vs_tag.h>
5707 #include <asm/byteorder.h>
5709 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5711 unsigned int flags = OCFS2_I(inode)->ip_attr;
5713 - inode->i_flags &= ~(S_IMMUTABLE |
5714 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5715 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5717 if (flags & OCFS2_IMMUTABLE_FL)
5718 inode->i_flags |= S_IMMUTABLE;
5719 + if (flags & OCFS2_IXUNLINK_FL)
5720 + inode->i_flags |= S_IXUNLINK;
5722 if (flags & OCFS2_SYNC_FL)
5723 inode->i_flags |= S_SYNC;
5724 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5725 inode->i_flags |= S_NOATIME;
5726 if (flags & OCFS2_DIRSYNC_FL)
5727 inode->i_flags |= S_DIRSYNC;
5729 + inode->i_vflags &= ~(V_BARRIER | V_COW);
5731 + if (flags & OCFS2_BARRIER_FL)
5732 + inode->i_vflags |= V_BARRIER;
5733 + if (flags & OCFS2_COW_FL)
5734 + inode->i_vflags |= V_COW;
5737 /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5738 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5740 unsigned int flags = oi->vfs_inode.i_flags;
5741 + unsigned int vflags = oi->vfs_inode.i_vflags;
5743 + oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5744 + OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5745 + OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5746 + OCFS2_BARRIER_FL | OCFS2_COW_FL);
5748 + if (flags & S_IMMUTABLE)
5749 + oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5750 + if (flags & S_IXUNLINK)
5751 + oi->ip_attr |= OCFS2_IXUNLINK_FL;
5753 - oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5754 - OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5756 oi->ip_attr |= OCFS2_SYNC_FL;
5757 if (flags & S_APPEND)
5758 oi->ip_attr |= OCFS2_APPEND_FL;
5759 - if (flags & S_IMMUTABLE)
5760 - oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5761 if (flags & S_NOATIME)
5762 oi->ip_attr |= OCFS2_NOATIME_FL;
5763 if (flags & S_DIRSYNC)
5764 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5766 + if (vflags & V_BARRIER)
5767 + oi->ip_attr |= OCFS2_BARRIER_FL;
5768 + if (vflags & V_COW)
5769 + oi->ip_attr |= OCFS2_COW_FL;
5772 struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5773 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5774 struct super_block *sb;
5775 struct ocfs2_super *osb;
5782 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5783 inode->i_generation = le32_to_cpu(fe->i_generation);
5784 inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5785 inode->i_mode = le16_to_cpu(fe->i_mode);
5786 - i_uid_write(inode, le32_to_cpu(fe->i_uid));
5787 - i_gid_write(inode, le32_to_cpu(fe->i_gid));
5788 + uid = le32_to_cpu(fe->i_uid);
5789 + gid = le32_to_cpu(fe->i_gid);
5790 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5791 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5792 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5793 + /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5795 /* Fast symlinks will have i_size but no allocated clusters. */
5796 if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5797 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/inode.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.h
5798 --- linux-3.9.4/fs/ocfs2/inode.h 2012-12-11 03:30:57.000000000 +0000
5799 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/inode.h 2013-05-31 14:47:11.000000000 +0000
5800 @@ -154,6 +154,7 @@ struct buffer_head *ocfs2_bread(struct i
5802 void ocfs2_set_inode_flags(struct inode *inode);
5803 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5804 +int ocfs2_sync_flags(struct inode *inode, int, int);
5806 static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5808 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ioctl.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/ioctl.c
5809 --- linux-3.9.4/fs/ocfs2/ioctl.c 2013-05-31 13:45:24.000000000 +0000
5810 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/ioctl.c 2013-05-31 14:47:11.000000000 +0000
5811 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5815 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5816 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5818 + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5819 + struct buffer_head *bh = NULL;
5820 + handle_t *handle = NULL;
5823 + status = ocfs2_inode_lock(inode, &bh, 1);
5825 + mlog_errno(status);
5828 + handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5829 + if (IS_ERR(handle)) {
5830 + status = PTR_ERR(handle);
5831 + mlog_errno(status);
5835 + inode->i_flags = flags;
5836 + inode->i_vflags = vflags;
5837 + ocfs2_get_inode_flags(OCFS2_I(inode));
5839 + status = ocfs2_mark_inode_dirty(handle, inode, bh);
5841 + mlog_errno(status);
5843 + ocfs2_commit_trans(osb, handle);
5845 + ocfs2_inode_unlock(inode, 1);
5850 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5853 struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5854 @@ -101,6 +135,11 @@ static int ocfs2_set_inode_attr(struct i
5855 if (!S_ISDIR(inode->i_mode))
5856 flags &= ~OCFS2_DIRSYNC_FL;
5858 + if (IS_BARRIER(inode)) {
5859 + vxwprintk_task(1, "messing with the barrier.");
5863 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5864 if (IS_ERR(handle)) {
5865 status = PTR_ERR(handle);
5866 @@ -879,6 +918,7 @@ bail:
5871 long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5873 struct inode *inode = file_inode(filp);
5874 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/namei.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/namei.c
5875 --- linux-3.9.4/fs/ocfs2/namei.c 2013-05-31 13:45:24.000000000 +0000
5876 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/namei.c 2013-05-31 15:52:25.000000000 +0000
5878 #include <linux/slab.h>
5879 #include <linux/highmem.h>
5880 #include <linux/quotaops.h>
5881 +#include <linux/vs_tag.h>
5883 #include <cluster/masklog.h>
5885 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5886 struct ocfs2_dinode *fe = NULL;
5887 struct ocfs2_extent_list *fel;
5893 @@ -512,8 +514,11 @@ static int __ocfs2_mknod_locked(struct i
5894 fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5895 fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5896 fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5897 - fe->i_uid = cpu_to_le32(i_uid_read(inode));
5898 - fe->i_gid = cpu_to_le32(i_gid_read(inode));
5900 + tag = dx_current_fstag(osb->sb);
5901 + fe->i_uid = cpu_to_le32(TAGINO_UID(DX_TAG(inode), i_uid_read(inode), tag));
5902 + fe->i_gid = cpu_to_le32(TAGINO_GID(DX_TAG(inode), i_gid_read(inode), tag));
5903 + inode->i_tag = tag; /* is this correct? */
5904 fe->i_mode = cpu_to_le16(inode->i_mode);
5905 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5906 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5907 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ocfs2.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2.h
5908 --- linux-3.9.4/fs/ocfs2/ocfs2.h 2012-12-11 03:30:57.000000000 +0000
5909 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2.h 2013-05-31 14:47:11.000000000 +0000
5910 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5912 OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5913 OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5914 + OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5917 #define OCFS2_OSB_SOFT_RO 0x0001
5918 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/ocfs2_fs.h linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2_fs.h
5919 --- linux-3.9.4/fs/ocfs2/ocfs2_fs.h 2012-12-11 03:30:57.000000000 +0000
5920 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/ocfs2_fs.h 2013-05-31 14:47:11.000000000 +0000
5921 @@ -266,6 +266,11 @@
5922 #define OCFS2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
5923 #define OCFS2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
5925 +#define OCFS2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
5927 +#define OCFS2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
5928 +#define OCFS2_COW_FL FS_COW_FL /* Copy on Write marker */
5930 #define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
5931 #define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
5933 diff -NurpP --minimal linux-3.9.4/fs/ocfs2/super.c linux-3.9.4-vs2.3.6.2/fs/ocfs2/super.c
5934 --- linux-3.9.4/fs/ocfs2/super.c 2013-05-31 13:45:25.000000000 +0000
5935 +++ linux-3.9.4-vs2.3.6.2/fs/ocfs2/super.c 2013-05-31 14:47:11.000000000 +0000
5936 @@ -185,6 +185,7 @@ enum {
5940 + Opt_tag, Opt_notag, Opt_tagid,
5944 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5945 {Opt_coherency_full, "coherency=full"},
5946 {Opt_resv_level, "resv_level=%u"},
5947 {Opt_dir_resv_level, "dir_resv_level=%u"},
5949 + {Opt_notag, "notag"},
5950 + {Opt_tagid, "tagid=%u"},
5954 @@ -662,6 +666,13 @@ static int ocfs2_remount(struct super_bl
5958 + if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5959 + (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5961 + mlog(ML_ERROR, "Cannot change tagging on remount\n");
5965 /* We're going to/from readonly mode. */
5966 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5967 /* Disable quota accounting before remounting RO */
5968 @@ -1177,6 +1188,9 @@ static int ocfs2_fill_super(struct super
5970 ocfs2_complete_mount_recovery(osb);
5972 + if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5973 + sb->s_flags |= MS_TAGGED;
5975 if (ocfs2_mount_local(osb))
5976 snprintf(nodestr, sizeof(nodestr), "local");
5978 @@ -1504,6 +1518,20 @@ static int ocfs2_parse_options(struct su
5979 option < OCFS2_MAX_RESV_LEVEL)
5980 mopt->dir_resv_level = option;
5982 +#ifndef CONFIG_TAGGING_NONE
5984 + mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5987 + mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5990 +#ifdef CONFIG_PROPAGATE
5993 + mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5998 "Unrecognized mount option \"%s\" "
5999 diff -NurpP --minimal linux-3.9.4/fs/open.c linux-3.9.4-vs2.3.6.2/fs/open.c
6000 --- linux-3.9.4/fs/open.c 2013-05-31 13:45:25.000000000 +0000
6001 +++ linux-3.9.4-vs2.3.6.2/fs/open.c 2013-06-01 08:41:29.000000000 +0000
6003 #include <linux/ima.h>
6004 #include <linux/dnotify.h>
6005 #include <linux/compat.h>
6006 +#include <linux/vs_base.h>
6007 +#include <linux/vs_limit.h>
6008 +#include <linux/vs_tag.h>
6009 +#include <linux/vs_cowbl.h>
6010 +#include <linux/vserver/dlimit.h>
6012 #include "internal.h"
6014 @@ -67,6 +72,11 @@ long vfs_truncate(struct path *path, lof
6015 struct inode *inode;
6018 +#ifdef CONFIG_VSERVER_COWBL
6019 + error = cow_check_and_break(path);
6023 inode = path->dentry->d_inode;
6025 /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
6026 @@ -532,6 +542,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
6027 unsigned int lookup_flags = LOOKUP_FOLLOW;
6029 error = user_path_at(dfd, filename, lookup_flags, &path);
6030 +#ifdef CONFIG_VSERVER_COWBL
6032 + error = cow_check_and_break(&path);
6038 error = chmod_common(&path, mode);
6040 @@ -564,13 +581,15 @@ static int chown_common(struct path *pat
6041 if (!uid_valid(uid))
6043 newattrs.ia_valid |= ATTR_UID;
6044 - newattrs.ia_uid = uid;
6045 + newattrs.ia_uid = make_kuid(&init_user_ns,
6046 + dx_map_uid(user));
6048 if (group != (gid_t) -1) {
6049 if (!gid_valid(gid))
6051 newattrs.ia_valid |= ATTR_GID;
6052 - newattrs.ia_gid = gid;
6053 + newattrs.ia_gid = make_kgid(&init_user_ns,
6054 + dx_map_gid(group));
6056 if (!S_ISDIR(inode->i_mode))
6057 newattrs.ia_valid |=
6058 @@ -604,6 +623,18 @@ retry:
6059 error = mnt_want_write(path.mnt);
6062 +#ifdef CONFIG_VSERVER_COWBL
6063 + error = cow_check_and_break(&path);
6066 +#ifdef CONFIG_VSERVER_COWBL
6067 + error = cow_check_and_break(&path);
6070 +#ifdef CONFIG_VSERVER_COWBL
6071 + error = cow_check_and_break(&path);
6074 error = chown_common(&path, user, group);
6075 mnt_drop_write(path.mnt);
6077 diff -NurpP --minimal linux-3.9.4/fs/proc/array.c linux-3.9.4-vs2.3.6.2/fs/proc/array.c
6078 --- linux-3.9.4/fs/proc/array.c 2013-05-31 13:45:25.000000000 +0000
6079 +++ linux-3.9.4-vs2.3.6.2/fs/proc/array.c 2013-05-31 14:47:11.000000000 +0000
6081 #include <linux/ptrace.h>
6082 #include <linux/tracehook.h>
6083 #include <linux/user_namespace.h>
6084 +#include <linux/vs_context.h>
6085 +#include <linux/vs_network.h>
6087 #include <asm/pgtable.h>
6088 #include <asm/processor.h>
6089 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
6091 ppid = pid_alive(p) ?
6092 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
6093 + if (unlikely(vx_current_initpid(p->pid)))
6098 struct task_struct *tracer = ptrace_parent(p);
6099 @@ -297,7 +302,7 @@ static inline void task_sig(struct seq_f
6102 static void render_cap_t(struct seq_file *m, const char *header,
6104 + struct vx_info *vxi, kernel_cap_t *a)
6108 @@ -331,10 +336,11 @@ static inline void task_cap(struct seq_f
6109 NORM_CAPS(cap_effective);
6110 NORM_CAPS(cap_bset);
6112 - render_cap_t(m, "CapInh:\t", &cap_inheritable);
6113 - render_cap_t(m, "CapPrm:\t", &cap_permitted);
6114 - render_cap_t(m, "CapEff:\t", &cap_effective);
6115 - render_cap_t(m, "CapBnd:\t", &cap_bset);
6116 + /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
6117 + render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
6118 + render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
6119 + render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
6120 + render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
6123 static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
6124 @@ -363,6 +369,42 @@ static void task_cpus_allowed(struct seq
6128 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6129 + struct pid *pid, struct task_struct *task)
6131 + seq_printf(m, "Proxy:\t%p(%c)\n"
6139 + (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6140 + atomic_read(&task->nsproxy->count),
6141 + task->nsproxy->uts_ns,
6142 + (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6143 + task->nsproxy->ipc_ns,
6144 + (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6145 + task->nsproxy->mnt_ns,
6146 + (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6147 + task->nsproxy->pid_ns,
6148 + (task->nsproxy->pid_ns == init_task.nsproxy->pid_ns ? 'I' : '-'),
6149 + task->nsproxy->net_ns,
6150 + (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6154 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6156 + if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6159 + seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6160 + seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6164 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6165 struct pid *pid, struct task_struct *task)
6167 @@ -380,6 +422,7 @@ int proc_pid_status(struct seq_file *m,
6168 task_seccomp(m, task);
6169 task_cpus_allowed(m, task);
6170 cpuset_task_status_allowed(m, task);
6171 + task_vs_id(m, task);
6172 task_context_switch_counts(m, task);
6175 @@ -489,6 +532,17 @@ static int do_task_stat(struct seq_file
6176 /* convert nsec -> ticks */
6177 start_time = nsec_to_clock_t(start_time);
6179 + /* fixup start time for virt uptime */
6180 + if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6181 + unsigned long long bias =
6182 + current->vx_info->cvirt.bias_clock;
6184 + if (start_time > bias)
6185 + start_time -= bias;
6190 seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6191 seq_put_decimal_ll(m, ' ', ppid);
6192 seq_put_decimal_ll(m, ' ', pgid);
6193 diff -NurpP --minimal linux-3.9.4/fs/proc/base.c linux-3.9.4-vs2.3.6.2/fs/proc/base.c
6194 --- linux-3.9.4/fs/proc/base.c 2013-05-31 13:45:25.000000000 +0000
6195 +++ linux-3.9.4-vs2.3.6.2/fs/proc/base.c 2013-05-31 14:47:11.000000000 +0000
6197 #include <linux/fs_struct.h>
6198 #include <linux/slab.h>
6199 #include <linux/flex_array.h>
6200 +#include <linux/vs_context.h>
6201 +#include <linux/vs_network.h>
6202 #ifdef CONFIG_HARDWALL
6203 #include <asm/hardwall.h>
6205 @@ -944,11 +946,15 @@ static ssize_t oom_adj_write(struct file
6206 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6208 if (oom_adj < task->signal->oom_score_adj &&
6209 - !capable(CAP_SYS_RESOURCE)) {
6210 + !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6215 + /* prevent guest processes from circumventing the oom killer */
6216 + if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6217 + oom_adj = OOM_ADJUST_MIN;
6220 * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6221 * /proc/pid/oom_score_adj instead.
6222 @@ -1528,6 +1534,8 @@ struct inode *proc_pid_make_inode(struct
6223 inode->i_gid = cred->egid;
6226 + /* procfs is xid tagged */
6227 + i_tag_write(inode, (tag_t)vx_task_xid(task));
6228 security_task_to_inode(task, inode);
6231 @@ -1573,6 +1581,8 @@ int pid_getattr(struct vfsmount *mnt, st
6235 +static unsigned name_to_int(struct dentry *dentry);
6238 * Exceptional case: normally we are not allowed to unhash a busy
6239 * directory. In this case, however, we can do it - no aliasing problems
6240 @@ -1601,6 +1611,12 @@ int pid_revalidate(struct dentry *dentry
6241 task = get_proc_task(inode);
6244 + unsigned pid = name_to_int(dentry);
6246 + if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6247 + put_task_struct(task);
6250 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6251 task_dumpable(task)) {
6253 @@ -1617,6 +1633,7 @@ int pid_revalidate(struct dentry *dentry
6254 put_task_struct(task);
6261 @@ -2059,6 +2076,13 @@ static struct dentry *proc_pident_lookup
6265 + /* TODO: maybe we can come up with a generic approach? */
6266 + if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6267 + (dentry->d_name.len == 5) &&
6268 + (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6269 + !memcmp(dentry->d_name.name, "ninfo", 5)))
6273 * Yes, it does not scale. And it should not. Don't add
6274 * new entries into /proc/<tgid>/ without very good reasons.
6275 @@ -2493,6 +2517,9 @@ static int proc_pid_personality(struct s
6276 static const struct file_operations proc_task_operations;
6277 static const struct inode_operations proc_task_inode_operations;
6279 +extern int proc_pid_vx_info(struct task_struct *, char *);
6280 +extern int proc_pid_nx_info(struct task_struct *, char *);
6282 static const struct pid_entry tgid_base_stuff[] = {
6283 DIR("task", S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6284 DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6285 @@ -2559,6 +2586,8 @@ static const struct pid_entry tgid_base_
6286 #ifdef CONFIG_CGROUPS
6287 REG("cgroup", S_IRUGO, proc_cgroup_operations),
6289 + INF("vinfo", S_IRUGO, proc_pid_vx_info),
6290 + INF("ninfo", S_IRUGO, proc_pid_nx_info),
6291 INF("oom_score", S_IRUGO, proc_oom_score),
6292 REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6293 REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6294 @@ -2583,6 +2612,7 @@ static const struct pid_entry tgid_base_
6295 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
6296 REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6298 + ONE("nsproxy", S_IRUGO, proc_pid_nsproxy),
6301 static int proc_tgid_base_readdir(struct file * filp,
6302 @@ -2770,7 +2800,7 @@ retry:
6304 pid = find_ge_pid(iter.tgid, ns);
6306 - iter.tgid = pid_nr_ns(pid, ns);
6307 + iter.tgid = pid_unmapped_nr_ns(pid, ns);
6308 iter.task = pid_task(pid, PIDTYPE_PID);
6309 /* What we to know is if the pid we have find is the
6310 * pid of a thread_group_leader. Testing for task
6311 @@ -2800,7 +2830,7 @@ static int proc_pid_fill_cache(struct fi
6312 struct tgid_iter iter)
6314 char name[PROC_NUMBUF];
6315 - int len = snprintf(name, sizeof(name), "%d", iter.tgid);
6316 + int len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6317 return proc_fill_cache(filp, dirent, filldir, name, len,
6318 proc_pid_instantiate, iter.task, NULL);
6320 @@ -2833,6 +2863,8 @@ int proc_pid_readdir(struct file * filp,
6321 __filldir = fake_filldir;
6323 filp->f_pos = iter.tgid + TGID_OFFSET;
6324 + if (!vx_proc_task_visible(iter.task))
6326 if (proc_pid_fill_cache(filp, dirent, __filldir, iter) < 0) {
6327 put_task_struct(iter.task);
6329 @@ -2993,6 +3025,8 @@ static struct dentry *proc_task_lookup(s
6330 tid = name_to_int(dentry);
6333 + if (vx_current_initpid(tid))
6336 ns = dentry->d_sb->s_fs_info;
6338 diff -NurpP --minimal linux-3.9.4/fs/proc/generic.c linux-3.9.4-vs2.3.6.2/fs/proc/generic.c
6339 --- linux-3.9.4/fs/proc/generic.c 2013-05-31 13:45:25.000000000 +0000
6340 +++ linux-3.9.4-vs2.3.6.2/fs/proc/generic.c 2013-05-31 16:13:42.000000000 +0000
6342 #include <linux/bitops.h>
6343 #include <linux/spinlock.h>
6344 #include <linux/completion.h>
6345 +#include <linux/vserver/inode.h>
6346 #include <asm/uaccess.h>
6348 #include "internal.h"
6349 @@ -409,6 +410,8 @@ struct dentry *proc_lookup_de(struct pro
6350 for (de = de->subdir; de ; de = de->next) {
6351 if (de->namelen != dentry->d_name.len)
6353 + if (!vx_hide_check(0, de->vx_flags))
6355 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6357 spin_unlock(&proc_subdir_lock);
6358 @@ -417,6 +420,8 @@ struct dentry *proc_lookup_de(struct pro
6359 return ERR_PTR(-ENOMEM);
6360 d_set_d_op(dentry, &proc_dentry_operations);
6361 d_add(dentry, inode);
6362 + /* generic proc entries belong to the host */
6363 + i_tag_write(inode, 0);
6367 @@ -485,6 +490,8 @@ int proc_readdir_de(struct proc_dir_entr
6369 /* filldir passes info to user space */
6371 + if (!vx_hide_check(0, de->vx_flags))
6373 spin_unlock(&proc_subdir_lock);
6374 if (filldir(dirent, de->name, de->namelen, filp->f_pos,
6375 de->low_ino, de->mode >> 12) < 0) {
6376 @@ -492,6 +499,7 @@ int proc_readdir_de(struct proc_dir_entr
6379 spin_lock(&proc_subdir_lock);
6384 @@ -603,6 +611,7 @@ static struct proc_dir_entry *__proc_cre
6388 + ent->vx_flags = IATTR_PROC_DEFAULT;
6389 atomic_set(&ent->count, 1);
6390 spin_lock_init(&ent->pde_unload_lock);
6391 INIT_LIST_HEAD(&ent->pde_openers);
6392 @@ -626,7 +635,8 @@ struct proc_dir_entry *proc_symlink(cons
6398 + ent->vx_flags = IATTR_PROC_SYMLINK;
6402 diff -NurpP --minimal linux-3.9.4/fs/proc/inode.c linux-3.9.4-vs2.3.6.2/fs/proc/inode.c
6403 --- linux-3.9.4/fs/proc/inode.c 2013-05-31 13:45:25.000000000 +0000
6404 +++ linux-3.9.4-vs2.3.6.2/fs/proc/inode.c 2013-05-31 14:47:11.000000000 +0000
6405 @@ -458,6 +458,8 @@ struct inode *proc_get_inode(struct supe
6406 inode->i_uid = de->uid;
6407 inode->i_gid = de->gid;
6410 + PROC_I(inode)->vx_flags = de->vx_flags;
6412 inode->i_size = de->size;
6414 diff -NurpP --minimal linux-3.9.4/fs/proc/internal.h linux-3.9.4-vs2.3.6.2/fs/proc/internal.h
6415 --- linux-3.9.4/fs/proc/internal.h 2013-05-31 13:45:25.000000000 +0000
6416 +++ linux-3.9.4-vs2.3.6.2/fs/proc/internal.h 2013-05-31 16:04:34.000000000 +0000
6418 #include <linux/sched.h>
6419 #include <linux/proc_fs.h>
6420 #include <linux/binfmts.h>
6421 +#include <linux/vs_pid.h>
6423 struct ctl_table_header;
6426 @@ -56,6 +58,9 @@ extern int proc_pid_status(struct seq_fi
6427 struct pid *pid, struct task_struct *task);
6428 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
6429 struct pid *pid, struct task_struct *task);
6430 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6431 + struct pid *pid, struct task_struct *task);
6433 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
6435 extern const struct file_operations proc_tid_children_operations;
6436 @@ -89,11 +94,16 @@ static inline struct pid *proc_pid(struc
6437 return PROC_I(inode)->pid;
6440 -static inline struct task_struct *get_proc_task(struct inode *inode)
6441 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6443 return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6446 +static inline struct task_struct *get_proc_task(struct inode *inode)
6448 + return vx_get_proc_task(inode, proc_pid(inode));
6451 static inline int proc_fd(struct inode *inode)
6453 return PROC_I(inode)->fd;
6454 diff -NurpP --minimal linux-3.9.4/fs/proc/loadavg.c linux-3.9.4-vs2.3.6.2/fs/proc/loadavg.c
6455 --- linux-3.9.4/fs/proc/loadavg.c 2012-12-11 03:30:57.000000000 +0000
6456 +++ linux-3.9.4-vs2.3.6.2/fs/proc/loadavg.c 2013-05-31 14:47:11.000000000 +0000
6459 static int loadavg_proc_show(struct seq_file *m, void *v)
6461 + unsigned long running;
6462 + unsigned int threads;
6463 unsigned long avnrun[3];
6465 get_avenrun(avnrun, FIXED_1/200, 0);
6467 + if (vx_flags(VXF_VIRT_LOAD, 0)) {
6468 + struct vx_info *vxi = current_vx_info();
6470 + running = atomic_read(&vxi->cvirt.nr_running);
6471 + threads = atomic_read(&vxi->cvirt.nr_threads);
6473 + running = nr_running();
6474 + threads = nr_threads;
6477 seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6478 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6479 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6480 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6481 - nr_running(), nr_threads,
6483 task_active_pid_ns(current)->last_pid);
6486 diff -NurpP --minimal linux-3.9.4/fs/proc/meminfo.c linux-3.9.4-vs2.3.6.2/fs/proc/meminfo.c
6487 --- linux-3.9.4/fs/proc/meminfo.c 2013-05-31 13:45:25.000000000 +0000
6488 +++ linux-3.9.4-vs2.3.6.2/fs/proc/meminfo.c 2013-05-31 16:05:39.000000000 +0000
6489 @@ -39,7 +39,8 @@ static int meminfo_proc_show(struct seq_
6490 allowed = ((totalram_pages - hugetlb_total_pages())
6491 * sysctl_overcommit_ratio / 100) + total_swap_pages;
6493 - cached = global_page_state(NR_FILE_PAGES) -
6494 + cached = vx_flags(VXF_VIRT_MEM, 0) ?
6495 + vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6496 total_swapcache_pages() - i.bufferram;
6499 diff -NurpP --minimal linux-3.9.4/fs/proc/root.c linux-3.9.4-vs2.3.6.2/fs/proc/root.c
6500 --- linux-3.9.4/fs/proc/root.c 2013-05-31 13:45:25.000000000 +0000
6501 +++ linux-3.9.4-vs2.3.6.2/fs/proc/root.c 2013-05-31 14:47:11.000000000 +0000
6503 #include <linux/mount.h>
6504 #include <linux/pid_namespace.h>
6505 #include <linux/parser.h>
6506 +#include <linux/vserver/inode.h>
6508 #include "internal.h"
6510 +struct proc_dir_entry *proc_virtual;
6512 +extern void proc_vx_init(void);
6514 static int proc_test_super(struct super_block *sb, void *data)
6516 return sb->s_fs_info == data;
6517 @@ -182,6 +187,7 @@ void __init proc_root_init(void)
6519 proc_mkdir("bus", NULL);
6524 static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6525 @@ -248,6 +254,7 @@ struct proc_dir_entry proc_root = {
6526 .proc_iops = &proc_root_inode_operations,
6527 .proc_fops = &proc_root_operations,
6528 .parent = &proc_root,
6529 + .vx_flags = IATTR_ADMIN | IATTR_WATCH,
6533 diff -NurpP --minimal linux-3.9.4/fs/proc/self.c linux-3.9.4-vs2.3.6.2/fs/proc/self.c
6534 --- linux-3.9.4/fs/proc/self.c 2013-02-19 13:58:49.000000000 +0000
6535 +++ linux-3.9.4-vs2.3.6.2/fs/proc/self.c 2013-05-31 20:57:54.000000000 +0000
6537 #include <linux/proc_fs.h>
6538 #include <linux/sched.h>
6539 #include <linux/namei.h>
6540 +#include <linux/vserver/inode.h>
6544 @@ -56,4 +57,5 @@ void __init proc_self_init(void)
6545 mode = S_IFLNK | S_IRWXUGO;
6546 proc_self_symlink = proc_create("self", mode, NULL, NULL );
6547 proc_self_symlink->proc_iops = &proc_self_inode_operations;
6548 + proc_self_symlink->vx_flags = IATTR_PROC_SYMLINK;
6550 diff -NurpP --minimal linux-3.9.4/fs/proc/stat.c linux-3.9.4-vs2.3.6.2/fs/proc/stat.c
6551 --- linux-3.9.4/fs/proc/stat.c 2012-12-11 03:30:57.000000000 +0000
6552 +++ linux-3.9.4-vs2.3.6.2/fs/proc/stat.c 2013-05-31 14:47:11.000000000 +0000
6554 #include <linux/slab.h>
6555 #include <linux/time.h>
6556 #include <linux/irqnr.h>
6557 +#include <linux/vserver/cvirt.h>
6558 #include <asm/cputime.h>
6559 #include <linux/tick.h>
6560 +#include <linux/cpuset.h>
6562 #ifndef arch_irq_stat_cpu
6563 #define arch_irq_stat_cpu(cpu) 0
6564 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6565 u64 sum_softirq = 0;
6566 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6567 struct timespec boottime;
6568 + cpumask_var_t cpus_allowed;
6569 + bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6571 user = nice = system = idle = iowait =
6572 irq = softirq = steal = 0;
6573 guest = guest_nice = 0;
6574 getboottime(&boottime);
6576 + if (vx_flags(VXF_VIRT_UPTIME, 0))
6577 + vx_vsi_boottime(&boottime);
6580 + cpuset_cpus_allowed(current, cpus_allowed);
6582 jif = boottime.tv_sec;
6584 for_each_possible_cpu(i) {
6585 + if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6588 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6589 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6590 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6591 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6594 for_each_online_cpu(i) {
6595 + if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6598 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6599 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6600 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6601 diff -NurpP --minimal linux-3.9.4/fs/proc/uptime.c linux-3.9.4-vs2.3.6.2/fs/proc/uptime.c
6602 --- linux-3.9.4/fs/proc/uptime.c 2012-12-11 03:30:57.000000000 +0000
6603 +++ linux-3.9.4-vs2.3.6.2/fs/proc/uptime.c 2013-05-31 14:47:11.000000000 +0000
6605 #include <linux/seq_file.h>
6606 #include <linux/time.h>
6607 #include <linux/kernel_stat.h>
6608 +#include <linux/vserver/cvirt.h>
6609 #include <asm/cputime.h>
6611 static int uptime_proc_show(struct seq_file *m, void *v)
6612 @@ -25,6 +26,10 @@ static int uptime_proc_show(struct seq_f
6613 nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6614 idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6617 + if (vx_flags(VXF_VIRT_UPTIME, 0))
6618 + vx_vsi_uptime(&uptime, &idle);
6620 seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6621 (unsigned long) uptime.tv_sec,
6622 (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6623 diff -NurpP --minimal linux-3.9.4/fs/proc_namespace.c linux-3.9.4-vs2.3.6.2/fs/proc_namespace.c
6624 --- linux-3.9.4/fs/proc_namespace.c 2012-12-11 03:30:57.000000000 +0000
6625 +++ linux-3.9.4-vs2.3.6.2/fs/proc_namespace.c 2013-05-31 17:17:53.000000000 +0000
6626 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6627 { MS_SYNCHRONOUS, ",sync" },
6628 { MS_DIRSYNC, ",dirsync" },
6629 { MS_MANDLOCK, ",mand" },
6630 + { MS_TAGGED, ",tag" },
6631 + { MS_NOTAGCHECK, ",notagcheck" },
6634 const struct proc_fs_info *fs_infop;
6635 @@ -80,6 +82,40 @@ static inline void mangle(struct seq_fil
6636 seq_escape(m, s, " \t\n\\");
6639 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6641 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6644 + struct dentry *point;
6645 + struct mount *mnt = real_mount(vfsmnt);
6646 + struct mount *root_mnt;
6649 + if (mnt == mnt->mnt_ns->root)
6652 + br_read_lock(&vfsmount_lock);
6653 + root = current->fs->root;
6654 + root_mnt = real_mount(root.mnt);
6655 + point = root.dentry;
6657 + while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6658 + point = mnt->mnt_mountpoint;
6659 + mnt = mnt->mnt_parent;
6662 + ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6664 + br_read_unlock(&vfsmount_lock);
6670 +#define mnt_is_reachable(v) (1)
6673 static void show_type(struct seq_file *m, struct super_block *sb)
6675 mangle(m, sb->s_type->name);
6676 @@ -96,6 +132,17 @@ static int show_vfsmnt(struct seq_file *
6677 struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6678 struct super_block *sb = mnt_path.dentry->d_sb;
6680 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6682 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6685 + if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6686 + mnt == current->fs->root.mnt) {
6687 + seq_puts(m, "/dev/root / ");
6691 if (sb->s_op->show_devname) {
6692 err = sb->s_op->show_devname(m, mnt_path.dentry);
6694 @@ -106,6 +153,7 @@ static int show_vfsmnt(struct seq_file *
6696 seq_path(m, &mnt_path, " \t\n\\");
6700 seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6701 err = show_sb_opts(m, sb);
6702 @@ -128,6 +176,11 @@ static int show_mountinfo(struct seq_fil
6703 struct path root = p->root;
6706 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6708 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6711 seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6712 MAJOR(sb->s_dev), MINOR(sb->s_dev));
6713 if (sb->s_op->show_path)
6714 @@ -187,6 +240,17 @@ static int show_vfsstat(struct seq_file
6715 struct super_block *sb = mnt_path.dentry->d_sb;
6718 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6720 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6723 + if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6724 + mnt == current->fs->root.mnt) {
6725 + seq_puts(m, "device /dev/root mounted on / ");
6730 if (sb->s_op->show_devname) {
6731 seq_puts(m, "device ");
6732 @@ -203,7 +267,7 @@ static int show_vfsstat(struct seq_file
6733 seq_puts(m, " mounted on ");
6734 seq_path(m, &mnt_path, " \t\n\\");
6738 /* file system type */
6739 seq_puts(m, "with fstype ");
6741 diff -NurpP --minimal linux-3.9.4/fs/quota/dquot.c linux-3.9.4-vs2.3.6.2/fs/quota/dquot.c
6742 --- linux-3.9.4/fs/quota/dquot.c 2013-05-31 13:45:25.000000000 +0000
6743 +++ linux-3.9.4-vs2.3.6.2/fs/quota/dquot.c 2013-05-31 14:47:11.000000000 +0000
6744 @@ -1585,6 +1585,9 @@ int __dquot_alloc_space(struct inode *in
6745 struct dquot **dquots = inode->i_dquot;
6746 int reserve = flags & DQUOT_SPACE_RESERVE;
6748 + if ((ret = dl_alloc_space(inode, number)))
6752 * First test before acquiring mutex - solves deadlocks when we
6753 * re-enter the quota code and are already holding the mutex
6754 @@ -1640,6 +1643,9 @@ int dquot_alloc_inode(const struct inode
6755 struct dquot_warn warn[MAXQUOTAS];
6756 struct dquot * const *dquots = inode->i_dquot;
6758 + if ((ret = dl_alloc_inode(inode)))
6761 /* First test before acquiring mutex - solves deadlocks when we
6762 * re-enter the quota code and are already holding the mutex */
6763 if (!dquot_active(inode))
6764 @@ -1711,6 +1717,8 @@ void __dquot_free_space(struct inode *in
6765 struct dquot **dquots = inode->i_dquot;
6766 int reserve = flags & DQUOT_SPACE_RESERVE;
6768 + dl_free_space(inode, number);
6770 /* First test before acquiring mutex - solves deadlocks when we
6771 * re-enter the quota code and are already holding the mutex */
6772 if (!dquot_active(inode)) {
6773 @@ -1755,6 +1763,8 @@ void dquot_free_inode(const struct inode
6774 struct dquot_warn warn[MAXQUOTAS];
6775 struct dquot * const *dquots = inode->i_dquot;
6777 + dl_free_inode(inode);
6779 /* First test before acquiring mutex - solves deadlocks when we
6780 * re-enter the quota code and are already holding the mutex */
6781 if (!dquot_active(inode))
6782 diff -NurpP --minimal linux-3.9.4/fs/quota/quota.c linux-3.9.4-vs2.3.6.2/fs/quota/quota.c
6783 --- linux-3.9.4/fs/quota/quota.c 2013-02-19 13:58:49.000000000 +0000
6784 +++ linux-3.9.4-vs2.3.6.2/fs/quota/quota.c 2013-05-31 14:47:11.000000000 +0000
6786 #include <linux/fs.h>
6787 #include <linux/namei.h>
6788 #include <linux/slab.h>
6789 +#include <linux/vs_context.h>
6790 #include <asm/current.h>
6791 #include <linux/uaccess.h>
6792 #include <linux/kernel.h>
6793 @@ -37,7 +38,7 @@ static int check_quotactl_permission(str
6797 - if (!capable(CAP_SYS_ADMIN))
6798 + if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6802 @@ -309,6 +310,46 @@ static int do_quotactl(struct super_bloc
6806 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6808 +#include <linux/vroot.h>
6809 +#include <linux/major.h>
6810 +#include <linux/module.h>
6811 +#include <linux/kallsyms.h>
6812 +#include <linux/vserver/debug.h>
6814 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6816 +static DEFINE_SPINLOCK(vroot_grb_lock);
6818 +int register_vroot_grb(vroot_grb_func *func) {
6821 + spin_lock(&vroot_grb_lock);
6822 + if (!vroot_get_real_bdev) {
6823 + vroot_get_real_bdev = func;
6826 + spin_unlock(&vroot_grb_lock);
6829 +EXPORT_SYMBOL(register_vroot_grb);
6831 +int unregister_vroot_grb(vroot_grb_func *func) {
6832 + int ret = -EINVAL;
6834 + spin_lock(&vroot_grb_lock);
6835 + if (vroot_get_real_bdev) {
6836 + vroot_get_real_bdev = NULL;
6839 + spin_unlock(&vroot_grb_lock);
6842 +EXPORT_SYMBOL(unregister_vroot_grb);
6846 /* Return 1 if 'cmd' will block on frozen filesystem */
6847 static int quotactl_cmd_write(int cmd)
6849 @@ -343,6 +384,22 @@ static struct super_block *quotactl_bloc
6852 return ERR_CAST(bdev);
6853 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6854 + if (bdev && bdev->bd_inode &&
6855 + imajor(bdev->bd_inode) == VROOT_MAJOR) {
6856 + struct block_device *bdnew = (void *)-EINVAL;
6858 + if (vroot_get_real_bdev)
6859 + bdnew = vroot_get_real_bdev(bdev);
6861 + vxdprintk(VXD_CBIT(misc, 0),
6862 + "vroot_get_real_bdev not set");
6864 + if (IS_ERR(bdnew))
6865 + return ERR_PTR(PTR_ERR(bdnew));
6869 if (quotactl_cmd_write(cmd))
6870 sb = get_super_thawed(bdev);
6872 diff -NurpP --minimal linux-3.9.4/fs/stat.c linux-3.9.4-vs2.3.6.2/fs/stat.c
6873 --- linux-3.9.4/fs/stat.c 2013-05-31 13:45:25.000000000 +0000
6874 +++ linux-3.9.4-vs2.3.6.2/fs/stat.c 2013-06-01 08:53:01.000000000 +0000
6875 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6876 stat->nlink = inode->i_nlink;
6877 stat->uid = inode->i_uid;
6878 stat->gid = inode->i_gid;
6879 + stat->tag = inode->i_tag;
6880 stat->rdev = inode->i_rdev;
6881 stat->size = i_size_read(inode);
6882 stat->atime = inode->i_atime;
6883 diff -NurpP --minimal linux-3.9.4/fs/statfs.c linux-3.9.4-vs2.3.6.2/fs/statfs.c
6884 --- linux-3.9.4/fs/statfs.c 2013-02-19 13:58:49.000000000 +0000
6885 +++ linux-3.9.4-vs2.3.6.2/fs/statfs.c 2013-05-31 14:47:11.000000000 +0000
6887 #include <linux/statfs.h>
6888 #include <linux/security.h>
6889 #include <linux/uaccess.h>
6890 +#include <linux/vs_base.h>
6891 +#include <linux/vs_dlimit.h>
6892 #include "internal.h"
6894 static int flags_by_mnt(int mnt_flags)
6895 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6896 retval = dentry->d_sb->s_op->statfs(dentry, buf);
6897 if (retval == 0 && buf->f_frsize == 0)
6898 buf->f_frsize = buf->f_bsize;
6899 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
6900 + vx_vsi_statfs(dentry->d_sb, buf);
6904 diff -NurpP --minimal linux-3.9.4/fs/super.c linux-3.9.4-vs2.3.6.2/fs/super.c
6905 --- linux-3.9.4/fs/super.c 2013-05-31 13:45:25.000000000 +0000
6906 +++ linux-3.9.4-vs2.3.6.2/fs/super.c 2013-05-31 14:47:11.000000000 +0000
6908 #include <linux/cleancache.h>
6909 #include <linux/fsnotify.h>
6910 #include <linux/lockdep.h>
6911 +#include <linux/magic.h>
6912 +#include <linux/vs_context.h>
6913 #include "internal.h"
6916 @@ -1117,6 +1119,13 @@ mount_fs(struct file_system_type *type,
6917 WARN_ON(sb->s_bdi == &default_backing_dev_info);
6918 sb->s_flags |= MS_BORN;
6921 + if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6923 + (sb->s_magic != PROC_SUPER_MAGIC) &&
6924 + (sb->s_magic != DEVPTS_SUPER_MAGIC))
6927 error = security_sb_kern_mount(sb, flags, secdata);
6930 diff -NurpP --minimal linux-3.9.4/fs/sysfs/mount.c linux-3.9.4-vs2.3.6.2/fs/sysfs/mount.c
6931 --- linux-3.9.4/fs/sysfs/mount.c 2013-05-31 13:45:25.000000000 +0000
6932 +++ linux-3.9.4-vs2.3.6.2/fs/sysfs/mount.c 2013-05-31 14:47:11.000000000 +0000
6933 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6935 sb->s_blocksize = PAGE_CACHE_SIZE;
6936 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6937 - sb->s_magic = SYSFS_MAGIC;
6938 + sb->s_magic = SYSFS_SUPER_MAGIC;
6939 sb->s_op = &sysfs_ops;
6940 sb->s_time_gran = 1;
6942 diff -NurpP --minimal linux-3.9.4/fs/utimes.c linux-3.9.4-vs2.3.6.2/fs/utimes.c
6943 --- linux-3.9.4/fs/utimes.c 2013-02-19 13:58:49.000000000 +0000
6944 +++ linux-3.9.4-vs2.3.6.2/fs/utimes.c 2013-05-31 22:40:16.000000000 +0000
6946 #include <linux/stat.h>
6947 #include <linux/utime.h>
6948 #include <linux/syscalls.h>
6949 +#include <linux/mount.h>
6950 +#include <linux/vs_cowbl.h>
6951 #include <asm/uaccess.h>
6952 #include <asm/unistd.h>
6954 @@ -52,12 +54,18 @@ static int utimes_common(struct path *pa
6957 struct iattr newattrs;
6958 - struct inode *inode = path->dentry->d_inode;
6959 + struct inode *inode;
6961 + error = cow_check_and_break(path);
6965 error = mnt_want_write(path->mnt);
6969 + inode = path->dentry->d_inode;
6971 if (times && times[0].tv_nsec == UTIME_NOW &&
6972 times[1].tv_nsec == UTIME_NOW)
6974 diff -NurpP --minimal linux-3.9.4/fs/xattr.c linux-3.9.4-vs2.3.6.2/fs/xattr.c
6975 --- linux-3.9.4/fs/xattr.c 2013-02-19 13:58:49.000000000 +0000
6976 +++ linux-3.9.4-vs2.3.6.2/fs/xattr.c 2013-05-31 14:47:11.000000000 +0000
6978 #include <linux/audit.h>
6979 #include <linux/vmalloc.h>
6980 #include <linux/posix_acl_xattr.h>
6981 +#include <linux/mount.h>
6983 #include <asm/uaccess.h>
6985 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6986 * The trusted.* namespace can only be accessed by privileged users.
6988 if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6989 - if (!capable(CAP_SYS_ADMIN))
6990 + if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6991 return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6994 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_dinode.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_dinode.h
6995 --- linux-3.9.4/fs/xfs/xfs_dinode.h 2012-12-11 03:30:57.000000000 +0000
6996 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_dinode.h 2013-05-31 14:47:11.000000000 +0000
6997 @@ -51,7 +51,9 @@ typedef struct xfs_dinode {
6998 __be32 di_nlink; /* number of links to file */
6999 __be16 di_projid_lo; /* lower part of owner's project id */
7000 __be16 di_projid_hi; /* higher part owner's project id */
7001 - __u8 di_pad[6]; /* unused, zeroed space */
7002 + __u8 di_pad[2]; /* unused, zeroed space */
7003 + __be16 di_tag; /* context tagging */
7004 + __be16 di_vflags; /* vserver specific flags */
7005 __be16 di_flushiter; /* incremented on flush */
7006 xfs_timestamp_t di_atime; /* time last accessed */
7007 xfs_timestamp_t di_mtime; /* time last modified */
7008 @@ -184,6 +186,8 @@ static inline void xfs_dinode_put_rdev(s
7009 #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
7010 #define XFS_DIFLAG_NODEFRAG_BIT 13 /* do not reorganize/defragment */
7011 #define XFS_DIFLAG_FILESTREAM_BIT 14 /* use filestream allocator */
7012 +#define XFS_DIFLAG_IXUNLINK_BIT 15 /* Immutable inver on unlink */
7014 #define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT)
7015 #define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT)
7016 #define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT)
7017 @@ -199,6 +203,7 @@ static inline void xfs_dinode_put_rdev(s
7018 #define XFS_DIFLAG_EXTSZINHERIT (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
7019 #define XFS_DIFLAG_NODEFRAG (1 << XFS_DIFLAG_NODEFRAG_BIT)
7020 #define XFS_DIFLAG_FILESTREAM (1 << XFS_DIFLAG_FILESTREAM_BIT)
7021 +#define XFS_DIFLAG_IXUNLINK (1 << XFS_DIFLAG_IXUNLINK_BIT)
7023 #ifdef CONFIG_XFS_RT
7024 #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME)
7025 @@ -211,6 +216,10 @@ static inline void xfs_dinode_put_rdev(s
7026 XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
7027 XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
7028 XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
7029 - XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
7030 + XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM | \
7031 + XFS_DIFLAG_IXUNLINK)
7033 +#define XFS_DIVFLAG_BARRIER 0x01
7034 +#define XFS_DIVFLAG_COW 0x02
7036 #endif /* __XFS_DINODE_H__ */
7037 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_fs.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_fs.h
7038 --- linux-3.9.4/fs/xfs/xfs_fs.h 2013-02-19 13:58:49.000000000 +0000
7039 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_fs.h 2013-05-31 14:47:11.000000000 +0000
7040 @@ -67,6 +67,9 @@ struct fsxattr {
7041 #define XFS_XFLAG_EXTSZINHERIT 0x00001000 /* inherit inode extent size */
7042 #define XFS_XFLAG_NODEFRAG 0x00002000 /* do not defragment */
7043 #define XFS_XFLAG_FILESTREAM 0x00004000 /* use filestream allocator */
7044 +#define XFS_XFLAG_IXUNLINK 0x00008000 /* immutable invert on unlink */
7045 +#define XFS_XFLAG_BARRIER 0x10000000 /* chroot() barrier */
7046 +#define XFS_XFLAG_COW 0x20000000 /* copy on write mark */
7047 #define XFS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
7050 @@ -303,7 +306,8 @@ typedef struct xfs_bstat {
7051 #define bs_projid bs_projid_lo /* (previously just bs_projid) */
7052 __u16 bs_forkoff; /* inode fork offset in bytes */
7053 __u16 bs_projid_hi; /* higher part of project id */
7054 - unsigned char bs_pad[10]; /* pad space, unused */
7055 + unsigned char bs_pad[8]; /* pad space, unused */
7056 + __u16 bs_tag; /* context tagging */
7057 __u32 bs_dmevmask; /* DMIG event mask */
7058 __u16 bs_dmstate; /* DMIG state info */
7059 __u16 bs_aextents; /* attribute number of extents */
7060 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ialloc.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ialloc.c
7061 --- linux-3.9.4/fs/xfs/xfs_ialloc.c 2013-05-31 13:45:25.000000000 +0000
7062 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ialloc.c 2013-05-31 14:47:11.000000000 +0000
7064 #include "xfs_error.h"
7065 #include "xfs_bmap.h"
7069 * Allocation group level functions.
7071 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_inode.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_inode.c
7072 --- linux-3.9.4/fs/xfs/xfs_inode.c 2013-05-31 13:45:25.000000000 +0000
7073 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_inode.c 2013-05-31 14:47:11.000000000 +0000
7075 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7077 #include <linux/log2.h>
7078 +#include <linux/vs_tag.h>
7082 @@ -835,15 +836,25 @@ xfs_iformat_btree(
7084 xfs_dinode_from_disk(
7086 - xfs_dinode_t *from)
7087 + xfs_dinode_t *from,
7090 + uint32_t uid, gid, tag;
7092 to->di_magic = be16_to_cpu(from->di_magic);
7093 to->di_mode = be16_to_cpu(from->di_mode);
7094 to->di_version = from ->di_version;
7095 to->di_format = from->di_format;
7096 to->di_onlink = be16_to_cpu(from->di_onlink);
7097 - to->di_uid = be32_to_cpu(from->di_uid);
7098 - to->di_gid = be32_to_cpu(from->di_gid);
7100 + uid = be32_to_cpu(from->di_uid);
7101 + gid = be32_to_cpu(from->di_gid);
7102 + tag = be16_to_cpu(from->di_tag);
7104 + to->di_uid = INOTAG_UID(tagged, uid, gid);
7105 + to->di_gid = INOTAG_GID(tagged, uid, gid);
7106 + to->di_tag = INOTAG_TAG(tagged, uid, gid, tag);
7108 to->di_nlink = be32_to_cpu(from->di_nlink);
7109 to->di_projid_lo = be16_to_cpu(from->di_projid_lo);
7110 to->di_projid_hi = be16_to_cpu(from->di_projid_hi);
7111 @@ -865,21 +876,26 @@ xfs_dinode_from_disk(
7112 to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
7113 to->di_dmstate = be16_to_cpu(from->di_dmstate);
7114 to->di_flags = be16_to_cpu(from->di_flags);
7115 + to->di_vflags = be16_to_cpu(from->di_vflags);
7116 to->di_gen = be32_to_cpu(from->di_gen);
7122 - xfs_icdinode_t *from)
7123 + xfs_icdinode_t *from,
7126 to->di_magic = cpu_to_be16(from->di_magic);
7127 to->di_mode = cpu_to_be16(from->di_mode);
7128 to->di_version = from ->di_version;
7129 to->di_format = from->di_format;
7130 to->di_onlink = cpu_to_be16(from->di_onlink);
7131 - to->di_uid = cpu_to_be32(from->di_uid);
7132 - to->di_gid = cpu_to_be32(from->di_gid);
7134 + to->di_uid = cpu_to_be32(TAGINO_UID(tagged, from->di_uid, from->di_tag));
7135 + to->di_gid = cpu_to_be32(TAGINO_GID(tagged, from->di_gid, from->di_tag));
7136 + to->di_tag = cpu_to_be16(TAGINO_TAG(tagged, from->di_tag));
7138 to->di_nlink = cpu_to_be32(from->di_nlink);
7139 to->di_projid_lo = cpu_to_be16(from->di_projid_lo);
7140 to->di_projid_hi = cpu_to_be16(from->di_projid_hi);
7141 @@ -901,12 +917,14 @@ xfs_dinode_to_disk(
7142 to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
7143 to->di_dmstate = cpu_to_be16(from->di_dmstate);
7144 to->di_flags = cpu_to_be16(from->di_flags);
7145 + to->di_vflags = cpu_to_be16(from->di_vflags);
7146 to->di_gen = cpu_to_be32(from->di_gen);
7151 - __uint16_t di_flags)
7152 + __uint16_t di_flags,
7153 + __uint16_t di_vflags)
7157 @@ -917,6 +935,8 @@ _xfs_dic2xflags(
7158 flags |= XFS_XFLAG_PREALLOC;
7159 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7160 flags |= XFS_XFLAG_IMMUTABLE;
7161 + if (di_flags & XFS_DIFLAG_IXUNLINK)
7162 + flags |= XFS_XFLAG_IXUNLINK;
7163 if (di_flags & XFS_DIFLAG_APPEND)
7164 flags |= XFS_XFLAG_APPEND;
7165 if (di_flags & XFS_DIFLAG_SYNC)
7166 @@ -941,6 +961,10 @@ _xfs_dic2xflags(
7167 flags |= XFS_XFLAG_FILESTREAM;
7170 + if (di_vflags & XFS_DIVFLAG_BARRIER)
7171 + flags |= FS_BARRIER_FL;
7172 + if (di_vflags & XFS_DIVFLAG_COW)
7173 + flags |= FS_COW_FL;
7177 @@ -950,7 +974,7 @@ xfs_ip2xflags(
7179 xfs_icdinode_t *dic = &ip->i_d;
7181 - return _xfs_dic2xflags(dic->di_flags) |
7182 + return _xfs_dic2xflags(dic->di_flags, dic->di_vflags) |
7183 (XFS_IFORK_Q(ip) ? XFS_XFLAG_HASATTR : 0);
7186 @@ -958,7 +982,8 @@ uint
7190 - return _xfs_dic2xflags(be16_to_cpu(dip->di_flags)) |
7191 + return _xfs_dic2xflags(be16_to_cpu(dip->di_flags),
7192 + be16_to_cpu(dip->di_vflags)) |
7193 (XFS_DFORK_Q(dip) ? XFS_XFLAG_HASATTR : 0);
7196 @@ -1012,7 +1037,8 @@ xfs_iread(
7197 * Otherwise, just get the truly permanent information.
7200 - xfs_dinode_from_disk(&ip->i_d, dip);
7201 + xfs_dinode_from_disk(&ip->i_d, dip,
7202 + mp->m_flags & XFS_MOUNT_TAGGED);
7203 error = xfs_iformat(ip, dip);
7206 @@ -1199,6 +1225,7 @@ xfs_ialloc(
7207 ASSERT(ip->i_d.di_nlink == nlink);
7208 ip->i_d.di_uid = current_fsuid();
7209 ip->i_d.di_gid = current_fsgid();
7210 + ip->i_d.di_tag = current_fstag(&ip->i_vnode);
7211 xfs_set_projid(ip, prid);
7212 memset(&(ip->i_d.di_pad[0]), 0, sizeof(ip->i_d.di_pad));
7214 @@ -1258,6 +1285,7 @@ xfs_ialloc(
7215 ip->i_d.di_dmevmask = 0;
7216 ip->i_d.di_dmstate = 0;
7217 ip->i_d.di_flags = 0;
7218 + ip->i_d.di_vflags = 0;
7219 flags = XFS_ILOG_CORE;
7220 switch (mode & S_IFMT) {
7222 @@ -1952,6 +1980,7 @@ xfs_ifree(
7224 ip->i_d.di_mode = 0; /* mark incore inode as free */
7225 ip->i_d.di_flags = 0;
7226 + ip->i_d.di_vflags = 0;
7227 ip->i_d.di_dmevmask = 0;
7228 ip->i_d.di_forkoff = 0; /* mark the attr fork not in use */
7229 ip->i_d.di_format = XFS_DINODE_FMT_EXTENTS;
7230 @@ -2118,7 +2147,6 @@ xfs_iroot_realloc(
7236 * This is called when the amount of space needed for if_data
7237 * is increased or decreased. The change in size is indicated by
7238 @@ -2800,7 +2828,8 @@ xfs_iflush_int(
7239 * because if the inode is dirty at all the core must
7242 - xfs_dinode_to_disk(dip, &ip->i_d);
7243 + xfs_dinode_to_disk(dip, &ip->i_d,
7244 + mp->m_flags & XFS_MOUNT_TAGGED);
7246 /* Wrap, we never let the log put out DI_MAX_FLUSH */
7247 if (ip->i_d.di_flushiter == DI_MAX_FLUSH)
7248 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_inode.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_inode.h
7249 --- linux-3.9.4/fs/xfs/xfs_inode.h 2013-05-31 13:45:25.000000000 +0000
7250 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_inode.h 2013-05-31 14:47:11.000000000 +0000
7251 @@ -134,7 +134,9 @@ typedef struct xfs_icdinode {
7252 __uint32_t di_nlink; /* number of links to file */
7253 __uint16_t di_projid_lo; /* lower part of owner's project id */
7254 __uint16_t di_projid_hi; /* higher part of owner's project id */
7255 - __uint8_t di_pad[6]; /* unused, zeroed space */
7256 + __uint8_t di_pad[2]; /* unused, zeroed space */
7257 + __uint16_t di_tag; /* context tagging */
7258 + __uint16_t di_vflags; /* vserver specific flags */
7259 __uint16_t di_flushiter; /* incremented on flush */
7260 xfs_ictimestamp_t di_atime; /* time last accessed */
7261 xfs_ictimestamp_t di_mtime; /* time last modified */
7262 @@ -556,7 +558,7 @@ int xfs_imap_to_bp(struct xfs_mount *,
7263 int xfs_iread(struct xfs_mount *, struct xfs_trans *,
7264 struct xfs_inode *, uint);
7265 void xfs_dinode_to_disk(struct xfs_dinode *,
7266 - struct xfs_icdinode *);
7267 + struct xfs_icdinode *, int);
7268 void xfs_idestroy_fork(struct xfs_inode *, int);
7269 void xfs_idata_realloc(struct xfs_inode *, int, int);
7270 void xfs_iroot_realloc(struct xfs_inode *, int, int);
7271 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ioctl.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ioctl.c
7272 --- linux-3.9.4/fs/xfs/xfs_ioctl.c 2013-05-31 13:45:25.000000000 +0000
7273 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ioctl.c 2013-05-31 14:47:11.000000000 +0000
7275 #include "xfs_bmap_btree.h"
7276 #include "xfs_dinode.h"
7277 #include "xfs_inode.h"
7278 -#include "xfs_ioctl.h"
7279 +// #include "xfs_ioctl.h"
7280 #include "xfs_rtalloc.h"
7281 #include "xfs_itable.h"
7282 #include "xfs_error.h"
7283 @@ -763,6 +763,10 @@ xfs_merge_ioc_xflags(
7284 xflags |= XFS_XFLAG_IMMUTABLE;
7286 xflags &= ~XFS_XFLAG_IMMUTABLE;
7287 + if (flags & FS_IXUNLINK_FL)
7288 + xflags |= XFS_XFLAG_IXUNLINK;
7290 + xflags &= ~XFS_XFLAG_IXUNLINK;
7291 if (flags & FS_APPEND_FL)
7292 xflags |= XFS_XFLAG_APPEND;
7294 @@ -791,6 +795,8 @@ xfs_di2lxflags(
7296 if (di_flags & XFS_DIFLAG_IMMUTABLE)
7297 flags |= FS_IMMUTABLE_FL;
7298 + if (di_flags & XFS_DIFLAG_IXUNLINK)
7299 + flags |= FS_IXUNLINK_FL;
7300 if (di_flags & XFS_DIFLAG_APPEND)
7301 flags |= FS_APPEND_FL;
7302 if (di_flags & XFS_DIFLAG_SYNC)
7303 @@ -851,6 +857,8 @@ xfs_set_diflags(
7304 di_flags = (ip->i_d.di_flags & XFS_DIFLAG_PREALLOC);
7305 if (xflags & XFS_XFLAG_IMMUTABLE)
7306 di_flags |= XFS_DIFLAG_IMMUTABLE;
7307 + if (xflags & XFS_XFLAG_IXUNLINK)
7308 + di_flags |= XFS_DIFLAG_IXUNLINK;
7309 if (xflags & XFS_XFLAG_APPEND)
7310 di_flags |= XFS_DIFLAG_APPEND;
7311 if (xflags & XFS_XFLAG_SYNC)
7312 @@ -893,6 +901,10 @@ xfs_diflags_to_linux(
7313 inode->i_flags |= S_IMMUTABLE;
7315 inode->i_flags &= ~S_IMMUTABLE;
7316 + if (xflags & XFS_XFLAG_IXUNLINK)
7317 + inode->i_flags |= S_IXUNLINK;
7319 + inode->i_flags &= ~S_IXUNLINK;
7320 if (xflags & XFS_XFLAG_APPEND)
7321 inode->i_flags |= S_APPEND;
7323 @@ -1397,10 +1409,18 @@ xfs_file_ioctl(
7324 case XFS_IOC_FSGETXATTRA:
7325 return xfs_ioc_fsgetxattr(ip, 1, arg);
7326 case XFS_IOC_FSSETXATTR:
7327 + if (IS_BARRIER(inode)) {
7328 + vxwprintk_task(1, "messing with the barrier.");
7329 + return -XFS_ERROR(EACCES);
7331 return xfs_ioc_fssetxattr(ip, filp, arg);
7332 case XFS_IOC_GETXFLAGS:
7333 return xfs_ioc_getxflags(ip, arg);
7334 case XFS_IOC_SETXFLAGS:
7335 + if (IS_BARRIER(inode)) {
7336 + vxwprintk_task(1, "messing with the barrier.");
7337 + return -XFS_ERROR(EACCES);
7339 return xfs_ioc_setxflags(ip, filp, arg);
7341 case XFS_IOC_FSSETDM: {
7342 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_ioctl.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ioctl.h
7343 --- linux-3.9.4/fs/xfs/xfs_ioctl.h 2012-12-11 03:30:57.000000000 +0000
7344 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_ioctl.h 2013-05-31 14:47:11.000000000 +0000
7345 @@ -70,6 +70,12 @@ xfs_handle_to_dentry(
7346 void __user *uhandle,
7351 + struct inode *inode,
7358 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_iops.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_iops.c
7359 --- linux-3.9.4/fs/xfs/xfs_iops.c 2013-02-19 13:58:49.000000000 +0000
7360 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_iops.c 2013-05-31 14:47:11.000000000 +0000
7362 #include "xfs_bmap_btree.h"
7363 #include "xfs_dinode.h"
7364 #include "xfs_inode.h"
7365 +#include "xfs_ioctl.h"
7366 #include "xfs_bmap.h"
7367 #include "xfs_rtalloc.h"
7368 #include "xfs_error.h"
7370 #include <linux/security.h>
7371 #include <linux/fiemap.h>
7372 #include <linux/slab.h>
7373 +#include <linux/vs_tag.h>
7377 @@ -422,6 +424,7 @@ xfs_vn_getattr(
7378 stat->nlink = ip->i_d.di_nlink;
7379 stat->uid = ip->i_d.di_uid;
7380 stat->gid = ip->i_d.di_gid;
7381 + stat->tag = ip->i_d.di_tag;
7382 stat->ino = ip->i_ino;
7383 stat->atime = inode->i_atime;
7384 stat->mtime = inode->i_mtime;
7385 @@ -1037,6 +1040,7 @@ static const struct inode_operations xfs
7386 .listxattr = xfs_vn_listxattr,
7387 .fiemap = xfs_vn_fiemap,
7388 .update_time = xfs_vn_update_time,
7389 + .sync_flags = xfs_sync_flags,
7392 static const struct inode_operations xfs_dir_inode_operations = {
7393 @@ -1063,6 +1067,7 @@ static const struct inode_operations xfs
7394 .removexattr = generic_removexattr,
7395 .listxattr = xfs_vn_listxattr,
7396 .update_time = xfs_vn_update_time,
7397 + .sync_flags = xfs_sync_flags,
7400 static const struct inode_operations xfs_dir_ci_inode_operations = {
7401 @@ -1114,6 +1119,10 @@ xfs_diflags_to_iflags(
7402 inode->i_flags |= S_IMMUTABLE;
7404 inode->i_flags &= ~S_IMMUTABLE;
7405 + if (ip->i_d.di_flags & XFS_DIFLAG_IXUNLINK)
7406 + inode->i_flags |= S_IXUNLINK;
7408 + inode->i_flags &= ~S_IXUNLINK;
7409 if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
7410 inode->i_flags |= S_APPEND;
7412 @@ -1126,6 +1135,15 @@ xfs_diflags_to_iflags(
7413 inode->i_flags |= S_NOATIME;
7415 inode->i_flags &= ~S_NOATIME;
7417 + if (ip->i_d.di_vflags & XFS_DIVFLAG_BARRIER)
7418 + inode->i_vflags |= V_BARRIER;
7420 + inode->i_vflags &= ~V_BARRIER;
7421 + if (ip->i_d.di_vflags & XFS_DIVFLAG_COW)
7422 + inode->i_vflags |= V_COW;
7424 + inode->i_vflags &= ~V_COW;
7428 @@ -1157,6 +1175,7 @@ xfs_setup_inode(
7429 set_nlink(inode, ip->i_d.di_nlink);
7430 inode->i_uid = ip->i_d.di_uid;
7431 inode->i_gid = ip->i_d.di_gid;
7432 + inode->i_tag = ip->i_d.di_tag;
7434 switch (inode->i_mode & S_IFMT) {
7436 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_itable.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_itable.c
7437 --- linux-3.9.4/fs/xfs/xfs_itable.c 2013-02-19 13:58:49.000000000 +0000
7438 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_itable.c 2013-05-31 14:47:11.000000000 +0000
7439 @@ -97,6 +97,7 @@ xfs_bulkstat_one_int(
7440 buf->bs_mode = dic->di_mode;
7441 buf->bs_uid = dic->di_uid;
7442 buf->bs_gid = dic->di_gid;
7443 + buf->bs_tag = dic->di_tag;
7444 buf->bs_size = dic->di_size;
7445 buf->bs_atime.tv_sec = dic->di_atime.t_sec;
7446 buf->bs_atime.tv_nsec = dic->di_atime.t_nsec;
7447 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_linux.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_linux.h
7448 --- linux-3.9.4/fs/xfs/xfs_linux.h 2013-02-19 13:58:49.000000000 +0000
7449 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_linux.h 2013-05-31 14:47:11.000000000 +0000
7452 #define current_cpu() (raw_smp_processor_id())
7453 #define current_pid() (current->pid)
7454 +#define current_fstag(vp) (dx_current_fstag((vp)->i_sb))
7455 #define current_test_flags(f) (current->flags & (f))
7456 #define current_set_flags_nested(sp, f) \
7457 (*(sp) = current->flags, current->flags |= (f))
7458 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_log_recover.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_log_recover.c
7459 --- linux-3.9.4/fs/xfs/xfs_log_recover.c 2013-05-31 13:45:25.000000000 +0000
7460 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_log_recover.c 2013-05-31 14:47:11.000000000 +0000
7461 @@ -2361,7 +2361,8 @@ xlog_recover_inode_pass2(
7464 /* The core is in in-core format */
7465 - xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
7466 + xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr,
7467 + mp->m_flags & XFS_MOUNT_TAGGED);
7469 /* the rest is in on-disk format */
7470 if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
7471 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_mount.h linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_mount.h
7472 --- linux-3.9.4/fs/xfs/xfs_mount.h 2013-05-31 13:45:25.000000000 +0000
7473 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_mount.h 2013-05-31 14:47:11.000000000 +0000
7474 @@ -254,6 +254,7 @@ typedef struct xfs_mount {
7476 #define XFS_MOUNT_NOATTR2 (1ULL << 25) /* disable use of attr2 format */
7478 +#define XFS_MOUNT_TAGGED (1ULL << 31) /* context tagging */
7481 * Default minimum read and write sizes.
7482 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_super.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_super.c
7483 --- linux-3.9.4/fs/xfs/xfs_super.c 2013-05-31 13:45:25.000000000 +0000
7484 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_super.c 2013-05-31 14:47:11.000000000 +0000
7485 @@ -114,6 +114,9 @@ mempool_t *xfs_ioend_pool;
7486 #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed logging disabled */
7487 #define MNTOPT_DISCARD "discard" /* Discard unused blocks */
7488 #define MNTOPT_NODISCARD "nodiscard" /* Do not discard unused blocks */
7489 +#define MNTOPT_TAGXID "tagxid" /* context tagging for inodes */
7490 +#define MNTOPT_TAGGED "tag" /* context tagging for inodes */
7491 +#define MNTOPT_NOTAGTAG "notag" /* do not use context tagging */
7494 * Table driven mount option parser.
7495 @@ -126,6 +129,8 @@ enum {
7504 @@ -134,6 +139,9 @@ static const match_table_t tokens = {
7505 {Opt_nobarrier, "nobarrier"},
7506 {Opt_inode64, "inode64"},
7507 {Opt_inode32, "inode32"},
7508 + {Opt_tag, "tagxid"},
7510 + {Opt_notag, "notag"},
7514 @@ -392,6 +400,19 @@ xfs_parseargs(
7515 } else if (!strcmp(this_char, "irixsgid")) {
7517 "irixsgid is now a sysctl(2) variable, option is deprecated.");
7518 +#ifndef CONFIG_TAGGING_NONE
7519 + } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7520 + mp->m_flags |= XFS_MOUNT_TAGGED;
7521 + } else if (!strcmp(this_char, MNTOPT_NOTAGTAG)) {
7522 + mp->m_flags &= ~XFS_MOUNT_TAGGED;
7523 + } else if (!strcmp(this_char, MNTOPT_TAGXID)) {
7524 + mp->m_flags |= XFS_MOUNT_TAGGED;
7526 +#ifdef CONFIG_PROPAGATE
7527 + } else if (!strcmp(this_char, MNTOPT_TAGGED)) {
7529 + mp->m_flags |= XFS_MOUNT_TAGGED;
7532 xfs_warn(mp, "unknown mount option [%s].", this_char);
7534 @@ -1238,6 +1259,16 @@ xfs_fs_remount(
7536 mp->m_maxagi = xfs_set_inode32(mp);
7539 + if (!(sb->s_flags & MS_TAGGED)) {
7541 + "XFS: %s: tagging not permitted on remount.\n",
7550 * Logically we would return an error here to prevent
7551 @@ -1458,6 +1489,9 @@ xfs_fs_fill_super(
7555 + if (mp->m_flags & XFS_MOUNT_TAGGED)
7556 + sb->s_flags |= MS_TAGGED;
7559 * we must configure the block size in the superblock before we run the
7560 * full mount process as the mount process can lookup and cache inodes.
7561 diff -NurpP --minimal linux-3.9.4/fs/xfs/xfs_vnodeops.c linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_vnodeops.c
7562 --- linux-3.9.4/fs/xfs/xfs_vnodeops.c 2013-05-31 13:45:25.000000000 +0000
7563 +++ linux-3.9.4-vs2.3.6.2/fs/xfs/xfs_vnodeops.c 2013-05-31 14:47:11.000000000 +0000
7564 @@ -104,6 +104,77 @@ xfs_readlink_bmap(
7570 +xfs_get_inode_flags(
7573 + struct inode *inode = VFS_I(ip);
7574 + unsigned int flags = inode->i_flags;
7575 + unsigned int vflags = inode->i_vflags;
7577 + if (flags & S_IMMUTABLE)
7578 + ip->i_d.di_flags |= XFS_DIFLAG_IMMUTABLE;
7580 + ip->i_d.di_flags &= ~XFS_DIFLAG_IMMUTABLE;
7581 + if (flags & S_IXUNLINK)
7582 + ip->i_d.di_flags |= XFS_DIFLAG_IXUNLINK;
7584 + ip->i_d.di_flags &= ~XFS_DIFLAG_IXUNLINK;
7586 + if (vflags & V_BARRIER)
7587 + ip->i_d.di_vflags |= XFS_DIVFLAG_BARRIER;
7589 + ip->i_d.di_vflags &= ~XFS_DIVFLAG_BARRIER;
7590 + if (vflags & V_COW)
7591 + ip->i_d.di_vflags |= XFS_DIVFLAG_COW;
7593 + ip->i_d.di_vflags &= ~XFS_DIVFLAG_COW;
7598 + struct inode *inode,
7602 + struct xfs_inode *ip = XFS_I(inode);
7603 + struct xfs_mount *mp = ip->i_mount;
7604 + struct xfs_trans *tp;
7605 + unsigned int lock_flags = 0;
7608 + tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
7609 + code = xfs_trans_reserve(tp, 0, XFS_ICHANGE_LOG_RES(mp), 0, 0, 0);
7613 + xfs_ilock(ip, XFS_ILOCK_EXCL);
7614 + xfs_trans_ijoin(tp, ip, 0);
7616 + inode->i_flags = flags;
7617 + inode->i_vflags = vflags;
7618 + xfs_get_inode_flags(ip);
7620 + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
7621 + xfs_trans_ichgtime(tp, ip, XFS_ICHGTIME_CHG);
7623 + XFS_STATS_INC(xs_ig_attrchg);
7625 + if (mp->m_flags & XFS_MOUNT_WSYNC)
7626 + xfs_trans_set_sync(tp);
7627 + code = xfs_trans_commit(tp, 0);
7628 + xfs_iunlock(ip, XFS_ILOCK_EXCL);
7632 + xfs_trans_cancel(tp, 0);
7634 + xfs_iunlock(ip, XFS_ILOCK_EXCL);
7642 diff -NurpP --minimal linux-3.9.4/include/linux/cred.h linux-3.9.4-vs2.3.6.2/include/linux/cred.h
7643 --- linux-3.9.4/include/linux/cred.h 2013-02-19 13:58:50.000000000 +0000
7644 +++ linux-3.9.4-vs2.3.6.2/include/linux/cred.h 2013-05-31 14:47:11.000000000 +0000
7645 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
7646 extern int copy_creds(struct task_struct *, unsigned long);
7647 extern const struct cred *get_task_cred(struct task_struct *);
7648 extern struct cred *cred_alloc_blank(void);
7649 +extern struct cred *__prepare_creds(const struct cred *);
7650 extern struct cred *prepare_creds(void);
7651 extern struct cred *prepare_exec_creds(void);
7652 extern int commit_creds(struct cred *);
7653 @@ -196,6 +197,31 @@ static inline void validate_process_cred
7657 +static inline void set_cred_subscribers(struct cred *cred, int n)
7659 +#ifdef CONFIG_DEBUG_CREDENTIALS
7660 + atomic_set(&cred->subscribers, n);
7664 +static inline int read_cred_subscribers(const struct cred *cred)
7666 +#ifdef CONFIG_DEBUG_CREDENTIALS
7667 + return atomic_read(&cred->subscribers);
7673 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
7675 +#ifdef CONFIG_DEBUG_CREDENTIALS
7676 + struct cred *cred = (struct cred *) _cred;
7678 + atomic_add(n, &cred->subscribers);
7683 * get_new_cred - Get a reference on a new set of credentials
7684 * @cred: The new credentials to reference
7685 diff -NurpP --minimal linux-3.9.4/include/linux/devpts_fs.h linux-3.9.4-vs2.3.6.2/include/linux/devpts_fs.h
7686 --- linux-3.9.4/include/linux/devpts_fs.h 2013-02-19 13:58:50.000000000 +0000
7687 +++ linux-3.9.4-vs2.3.6.2/include/linux/devpts_fs.h 2013-05-31 14:47:11.000000000 +0000
7688 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
7693 #endif /* _LINUX_DEVPTS_FS_H */
7694 diff -NurpP --minimal linux-3.9.4/include/linux/fs.h linux-3.9.4-vs2.3.6.2/include/linux/fs.h
7695 --- linux-3.9.4/include/linux/fs.h 2013-05-31 13:45:27.000000000 +0000
7696 +++ linux-3.9.4-vs2.3.6.2/include/linux/fs.h 2013-05-31 14:47:11.000000000 +0000
7697 @@ -211,6 +211,7 @@ typedef void (dio_iodone_t)(struct kiocb
7698 #define ATTR_KILL_PRIV (1 << 14)
7699 #define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */
7700 #define ATTR_TIMES_SET (1 << 16)
7701 +#define ATTR_TAG (1 << 17)
7704 * This is the Inode Attributes structure, used for notify_change(). It
7705 @@ -226,6 +227,7 @@ struct iattr {
7711 struct timespec ia_atime;
7712 struct timespec ia_mtime;
7713 @@ -523,7 +525,9 @@ struct inode {
7714 unsigned short i_opflags;
7717 - unsigned int i_flags;
7719 + unsigned short i_flags;
7720 + unsigned short i_vflags;
7722 #ifdef CONFIG_FS_POSIX_ACL
7723 struct posix_acl *i_acl;
7724 @@ -552,6 +556,7 @@ struct inode {
7725 unsigned int __i_nlink;
7730 struct timespec i_atime;
7731 struct timespec i_mtime;
7732 @@ -702,6 +707,11 @@ static inline gid_t i_gid_read(const str
7733 return from_kgid(&init_user_ns, inode->i_gid);
7736 +static inline tag_t i_tag_read(const struct inode *inode)
7738 + return from_ktag(&init_user_ns, inode->i_tag);
7741 static inline void i_uid_write(struct inode *inode, uid_t uid)
7743 inode->i_uid = make_kuid(&init_user_ns, uid);
7744 @@ -712,14 +722,19 @@ static inline void i_gid_write(struct in
7745 inode->i_gid = make_kgid(&init_user_ns, gid);
7748 +static inline void i_tag_write(struct inode *inode, tag_t tag)
7750 + inode->i_tag = make_ktag(&init_user_ns, tag);
7753 static inline unsigned iminor(const struct inode *inode)
7755 - return MINOR(inode->i_rdev);
7756 + return MINOR(inode->i_mdev);
7759 static inline unsigned imajor(const struct inode *inode)
7761 - return MAJOR(inode->i_rdev);
7762 + return MAJOR(inode->i_mdev);
7765 extern struct block_device *I_BDEV(struct inode *inode);
7766 @@ -786,6 +801,7 @@ struct file {
7768 struct fown_struct f_owner;
7769 const struct cred *f_cred;
7771 struct file_ra_state f_ra;
7774 @@ -937,6 +953,7 @@ struct file_lock {
7775 struct file *fl_file;
7780 struct fasync_struct * fl_fasync; /* for lease break notifications */
7781 /* for lease breaks: */
7782 @@ -1567,6 +1584,7 @@ struct inode_operations {
7783 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7784 ssize_t (*listxattr) (struct dentry *, char *, size_t);
7785 int (*removexattr) (struct dentry *, const char *);
7786 + int (*sync_flags) (struct inode *, int, int);
7787 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7789 int (*update_time)(struct inode *, struct timespec *, int);
7790 @@ -1579,6 +1597,7 @@ ssize_t rw_copy_check_uvector(int type,
7791 unsigned long nr_segs, unsigned long fast_segs,
7792 struct iovec *fast_pointer,
7793 struct iovec **ret_pointer);
7794 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7796 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7797 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7798 @@ -1632,6 +1651,14 @@ struct super_operations {
7799 #define S_IMA 1024 /* Inode has an associated IMA struct */
7800 #define S_AUTOMOUNT 2048 /* Automount/referral quasi-directory */
7801 #define S_NOSEC 4096 /* no suid or xattr security attributes */
7802 +#define S_IXUNLINK 8192 /* Immutable Invert on unlink */
7804 +/* Linux-VServer related Inode flags */
7808 +#define V_BARRIER 4 /* Barrier for chroot() */
7809 +#define V_COW 8 /* Copy on Write */
7812 * Note that nosuid etc flags are inode-specific: setting some file-system
7813 @@ -1656,10 +1683,13 @@ struct super_operations {
7814 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
7815 #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7816 #define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION)
7817 +#define IS_TAGGED(inode) __IS_FLG(inode, MS_TAGGED)
7819 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
7820 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
7821 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
7822 +#define IS_IXUNLINK(inode) ((inode)->i_flags & S_IXUNLINK)
7823 +#define IS_IXORUNLINK(inode) ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7824 #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL)
7826 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
7827 @@ -1670,6 +1700,16 @@ struct super_operations {
7828 #define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT)
7829 #define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC)
7831 +#define IS_BARRIER(inode) (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7833 +#ifdef CONFIG_VSERVER_COWBL
7834 +# define IS_COW(inode) (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7835 +# define IS_COW_LINK(inode) (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7837 +# define IS_COW(inode) (0)
7838 +# define IS_COW_LINK(inode) (0)
7842 * Inode state bits. Protected by inode->i_lock
7844 @@ -1898,6 +1938,9 @@ extern int rw_verify_area(int, struct fi
7845 extern int locks_mandatory_locked(struct inode *);
7846 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7848 +#define ATTR_FLAG_BARRIER 512 /* Barrier for chroot() */
7849 +#define ATTR_FLAG_IXUNLINK 1024 /* Immutable invert on unlink */
7852 * Candidates for mandatory locking have the setgid bit set
7853 * but no group execute bit - an otherwise meaningless combination.
7854 @@ -2509,6 +2552,7 @@ extern int dcache_dir_open(struct inode
7855 extern int dcache_dir_close(struct inode *, struct file *);
7856 extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7857 extern int dcache_readdir(struct file *, void *, filldir_t);
7858 +extern int dcache_readdir_filter(struct file *, void *, filldir_t, int (*)(struct dentry *));
7859 extern int simple_setattr(struct dentry *, struct iattr *);
7860 extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7861 extern int simple_statfs(struct dentry *, struct kstatfs *);
7862 diff -NurpP --minimal linux-3.9.4/include/linux/init_task.h linux-3.9.4-vs2.3.6.2/include/linux/init_task.h
7863 --- linux-3.9.4/include/linux/init_task.h 2013-05-31 13:45:27.000000000 +0000
7864 +++ linux-3.9.4-vs2.3.6.2/include/linux/init_task.h 2013-05-31 14:53:41.000000000 +0000
7865 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7866 INIT_TASK_RCU_PREEMPT(tsk) \
7870 + .vx_info = NULL, \
7872 + .nx_info = NULL, \
7876 diff -NurpP --minimal linux-3.9.4/include/linux/ipc.h linux-3.9.4-vs2.3.6.2/include/linux/ipc.h
7877 --- linux-3.9.4/include/linux/ipc.h 2012-12-11 03:30:57.000000000 +0000
7878 +++ linux-3.9.4-vs2.3.6.2/include/linux/ipc.h 2013-05-31 14:47:11.000000000 +0000
7879 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7887 diff -NurpP --minimal linux-3.9.4/include/linux/loop.h linux-3.9.4-vs2.3.6.2/include/linux/loop.h
7888 --- linux-3.9.4/include/linux/loop.h 2013-02-19 13:58:51.000000000 +0000
7889 +++ linux-3.9.4-vs2.3.6.2/include/linux/loop.h 2013-05-31 14:47:11.000000000 +0000
7890 @@ -41,6 +41,7 @@ struct loop_device {
7891 struct loop_func_table *lo_encryption;
7893 kuid_t lo_key_owner; /* Who set the key */
7895 int (*ioctl)(struct loop_device *, int cmd,
7898 diff -NurpP --minimal linux-3.9.4/include/linux/memcontrol.h linux-3.9.4-vs2.3.6.2/include/linux/memcontrol.h
7899 --- linux-3.9.4/include/linux/memcontrol.h 2013-05-31 13:45:28.000000000 +0000
7900 +++ linux-3.9.4-vs2.3.6.2/include/linux/memcontrol.h 2013-05-31 14:47:11.000000000 +0000
7901 @@ -86,6 +86,13 @@ extern struct mem_cgroup *try_get_mem_cg
7902 extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7903 extern struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont);
7905 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7906 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7908 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7909 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7910 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7913 bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7915 diff -NurpP --minimal linux-3.9.4/include/linux/mm_types.h linux-3.9.4-vs2.3.6.2/include/linux/mm_types.h
7916 --- linux-3.9.4/include/linux/mm_types.h 2013-05-31 13:45:28.000000000 +0000
7917 +++ linux-3.9.4-vs2.3.6.2/include/linux/mm_types.h 2013-05-31 14:47:11.000000000 +0000
7918 @@ -380,6 +380,7 @@ struct mm_struct {
7920 /* Architecture-specific MM context */
7921 mm_context_t context;
7922 + struct vx_info *mm_vx_info;
7924 unsigned long flags; /* Must use atomic bitops to access the bits */
7926 diff -NurpP --minimal linux-3.9.4/include/linux/mount.h linux-3.9.4-vs2.3.6.2/include/linux/mount.h
7927 --- linux-3.9.4/include/linux/mount.h 2013-05-31 13:45:28.000000000 +0000
7928 +++ linux-3.9.4-vs2.3.6.2/include/linux/mount.h 2013-05-31 14:47:11.000000000 +0000
7929 @@ -49,6 +49,9 @@ struct mnt_namespace;
7931 #define MNT_LOCK_READONLY 0x400000
7933 +#define MNT_TAGID 0x10000
7934 +#define MNT_NOTAG 0x20000
7937 struct dentry *mnt_root; /* root of the mounted tree */
7938 struct super_block *mnt_sb; /* pointer to superblock */
7939 diff -NurpP --minimal linux-3.9.4/include/linux/net.h linux-3.9.4-vs2.3.6.2/include/linux/net.h
7940 --- linux-3.9.4/include/linux/net.h 2012-12-11 03:30:57.000000000 +0000
7941 +++ linux-3.9.4-vs2.3.6.2/include/linux/net.h 2013-05-31 14:47:11.000000000 +0000
7942 @@ -38,6 +38,7 @@ struct net;
7943 #define SOCK_PASSCRED 3
7944 #define SOCK_PASSSEC 4
7945 #define SOCK_EXTERNALLY_ALLOCATED 5
7946 +#define SOCK_USER_SOCKET 6
7948 #ifndef ARCH_HAS_SOCKET_TYPES
7950 diff -NurpP --minimal linux-3.9.4/include/linux/netdevice.h linux-3.9.4-vs2.3.6.2/include/linux/netdevice.h
7951 --- linux-3.9.4/include/linux/netdevice.h 2013-05-31 13:45:28.000000000 +0000
7952 +++ linux-3.9.4-vs2.3.6.2/include/linux/netdevice.h 2013-05-31 14:47:11.000000000 +0000
7953 @@ -1688,6 +1688,7 @@ extern void netdev_resync_ops(struct ne
7955 extern struct net_device *dev_get_by_index(struct net *net, int ifindex);
7956 extern struct net_device *__dev_get_by_index(struct net *net, int ifindex);
7957 +extern struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7958 extern struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
7959 extern int dev_restart(struct net_device *dev);
7960 #ifdef CONFIG_NETPOLL_TRAP
7961 diff -NurpP --minimal linux-3.9.4/include/linux/nsproxy.h linux-3.9.4-vs2.3.6.2/include/linux/nsproxy.h
7962 --- linux-3.9.4/include/linux/nsproxy.h 2013-02-19 13:58:51.000000000 +0000
7963 +++ linux-3.9.4-vs2.3.6.2/include/linux/nsproxy.h 2013-05-31 17:17:53.000000000 +0000
7966 #include <linux/spinlock.h>
7967 #include <linux/sched.h>
7968 +#include <linux/vserver/debug.h>
7970 struct mnt_namespace;
7971 struct uts_namespace;
7972 @@ -63,6 +64,7 @@ static inline struct nsproxy *task_nspro
7975 int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7976 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7977 void exit_task_namespaces(struct task_struct *tsk);
7978 void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7979 void free_nsproxy(struct nsproxy *ns);
7980 @@ -70,16 +72,26 @@ int unshare_nsproxy_namespaces(unsigned
7981 struct cred *, struct fs_struct *);
7982 int __init nsproxy_cache_init(void);
7984 -static inline void put_nsproxy(struct nsproxy *ns)
7985 +#define get_nsproxy(n) __get_nsproxy(n, __FILE__, __LINE__)
7987 +static inline void __get_nsproxy(struct nsproxy *ns,
7988 + const char *_file, int _line)
7990 - if (atomic_dec_and_test(&ns->count)) {
7993 + vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7994 + ns, atomic_read(&ns->count), _file, _line);
7995 + atomic_inc(&ns->count);
7998 -static inline void get_nsproxy(struct nsproxy *ns)
7999 +#define put_nsproxy(n) __put_nsproxy(n, __FILE__, __LINE__)
8001 +static inline void __put_nsproxy(struct nsproxy *ns,
8002 + const char *_file, int _line)
8004 - atomic_inc(&ns->count);
8005 + vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
8006 + ns, atomic_read(&ns->count), _file, _line);
8007 + if (atomic_dec_and_test(&ns->count)) {
8013 diff -NurpP --minimal linux-3.9.4/include/linux/pid.h linux-3.9.4-vs2.3.6.2/include/linux/pid.h
8014 --- linux-3.9.4/include/linux/pid.h 2013-05-31 13:45:28.000000000 +0000
8015 +++ linux-3.9.4-vs2.3.6.2/include/linux/pid.h 2013-05-31 14:47:11.000000000 +0000
8016 @@ -8,7 +8,8 @@ enum pid_type
8026 @@ -172,6 +173,7 @@ static inline pid_t pid_nr(struct pid *p
8029 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
8030 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
8031 pid_t pid_vnr(struct pid *pid);
8033 #define do_each_pid_task(pid, type, task) \
8034 diff -NurpP --minimal linux-3.9.4/include/linux/proc_fs.h linux-3.9.4-vs2.3.6.2/include/linux/proc_fs.h
8035 --- linux-3.9.4/include/linux/proc_fs.h 2013-05-31 13:45:28.000000000 +0000
8036 +++ linux-3.9.4-vs2.3.6.2/include/linux/proc_fs.h 2013-05-31 14:47:11.000000000 +0000
8037 @@ -58,6 +58,7 @@ struct proc_dir_entry {
8043 const struct inode_operations *proc_iops;
8045 @@ -274,12 +275,18 @@ extern const struct proc_ns_operations p
8046 extern const struct proc_ns_operations userns_operations;
8047 extern const struct proc_ns_operations mntns_operations;
8053 int (*proc_get_link)(struct dentry *, struct path *);
8054 int (*proc_read)(struct task_struct *task, char *page);
8055 int (*proc_show)(struct seq_file *m,
8056 struct pid_namespace *ns, struct pid *pid,
8057 struct task_struct *task);
8058 + int (*proc_vs_read)(char *page);
8059 + int (*proc_vxi_read)(struct vx_info *vxi, char *page);
8060 + int (*proc_nxi_read)(struct nx_info *nxi, char *page);
8063 struct ctl_table_header;
8064 @@ -287,6 +294,7 @@ struct ctl_table;
8071 struct proc_dir_entry *pde;
8072 diff -NurpP --minimal linux-3.9.4/include/linux/quotaops.h linux-3.9.4-vs2.3.6.2/include/linux/quotaops.h
8073 --- linux-3.9.4/include/linux/quotaops.h 2012-12-11 03:30:57.000000000 +0000
8074 +++ linux-3.9.4-vs2.3.6.2/include/linux/quotaops.h 2013-05-31 14:47:11.000000000 +0000
8076 #define _LINUX_QUOTAOPS_
8078 #include <linux/fs.h>
8079 +#include <linux/vs_dlimit.h>
8081 #define DQUOT_SPACE_WARN 0x1
8082 #define DQUOT_SPACE_RESERVE 0x2
8083 @@ -205,11 +206,12 @@ static inline void dquot_drop(struct ino
8085 static inline int dquot_alloc_inode(const struct inode *inode)
8088 + return dl_alloc_inode(inode);
8091 static inline void dquot_free_inode(const struct inode *inode)
8093 + dl_free_inode(inode);
8096 static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
8097 @@ -220,6 +222,10 @@ static inline int dquot_transfer(struct
8098 static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
8103 + if ((ret = dl_alloc_space(inode, number)))
8105 if (!(flags & DQUOT_SPACE_RESERVE))
8106 inode_add_bytes(inode, number);
8108 @@ -230,6 +236,7 @@ static inline void __dquot_free_space(st
8110 if (!(flags & DQUOT_SPACE_RESERVE))
8111 inode_sub_bytes(inode, number);
8112 + dl_free_space(inode, number);
8115 static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
8116 diff -NurpP --minimal linux-3.9.4/include/linux/sched.h linux-3.9.4-vs2.3.6.2/include/linux/sched.h
8117 --- linux-3.9.4/include/linux/sched.h 2013-05-31 14:22:27.000000000 +0000
8118 +++ linux-3.9.4-vs2.3.6.2/include/linux/sched.h 2013-05-31 14:47:11.000000000 +0000
8119 @@ -1398,6 +1398,14 @@ struct task_struct {
8121 struct seccomp seccomp;
8123 +/* vserver context data */
8124 + struct vx_info *vx_info;
8125 + struct nx_info *nx_info;
8131 /* Thread group tracking */
8134 @@ -1637,6 +1645,11 @@ struct pid_namespace;
8135 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
8136 struct pid_namespace *ns);
8138 +#include <linux/vserver/base.h>
8139 +#include <linux/vserver/context.h>
8140 +#include <linux/vserver/debug.h>
8141 +#include <linux/vserver/pid.h>
8143 static inline pid_t task_pid_nr(struct task_struct *tsk)
8146 @@ -1650,7 +1663,8 @@ static inline pid_t task_pid_nr_ns(struc
8148 static inline pid_t task_pid_vnr(struct task_struct *tsk)
8150 - return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8151 + // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
8152 + return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
8156 @@ -1663,7 +1677,7 @@ pid_t task_tgid_nr_ns(struct task_struct
8158 static inline pid_t task_tgid_vnr(struct task_struct *tsk)
8160 - return pid_vnr(task_tgid(tsk));
8161 + return vx_map_tgid(pid_vnr(task_tgid(tsk)));
8165 diff -NurpP --minimal linux-3.9.4/include/linux/shmem_fs.h linux-3.9.4-vs2.3.6.2/include/linux/shmem_fs.h
8166 --- linux-3.9.4/include/linux/shmem_fs.h 2012-12-11 03:30:57.000000000 +0000
8167 +++ linux-3.9.4-vs2.3.6.2/include/linux/shmem_fs.h 2013-05-31 14:47:11.000000000 +0000
8170 /* inode in-kernel data */
8172 +#define TMPFS_SUPER_MAGIC 0x01021994
8175 struct shmem_inode_info {
8177 unsigned long flags;
8178 diff -NurpP --minimal linux-3.9.4/include/linux/stat.h linux-3.9.4-vs2.3.6.2/include/linux/stat.h
8179 --- linux-3.9.4/include/linux/stat.h 2012-12-11 03:30:57.000000000 +0000
8180 +++ linux-3.9.4-vs2.3.6.2/include/linux/stat.h 2013-06-01 08:53:13.000000000 +0000
8181 @@ -25,6 +25,7 @@ struct kstat {
8188 struct timespec atime;
8189 diff -NurpP --minimal linux-3.9.4/include/linux/sunrpc/auth.h linux-3.9.4-vs2.3.6.2/include/linux/sunrpc/auth.h
8190 --- linux-3.9.4/include/linux/sunrpc/auth.h 2013-05-31 13:45:28.000000000 +0000
8191 +++ linux-3.9.4-vs2.3.6.2/include/linux/sunrpc/auth.h 2013-05-31 14:52:57.000000000 +0000
8197 struct group_info *group_info;
8198 const char *principal;
8199 unsigned char machine_cred : 1;
8200 diff -NurpP --minimal linux-3.9.4/include/linux/sunrpc/clnt.h linux-3.9.4-vs2.3.6.2/include/linux/sunrpc/clnt.h
8201 --- linux-3.9.4/include/linux/sunrpc/clnt.h 2013-05-31 13:45:28.000000000 +0000
8202 +++ linux-3.9.4-vs2.3.6.2/include/linux/sunrpc/clnt.h 2013-05-31 14:47:11.000000000 +0000
8203 @@ -49,7 +49,8 @@ struct rpc_clnt {
8204 unsigned int cl_softrtry : 1,/* soft timeouts */
8205 cl_discrtry : 1,/* disconnect before retry */
8206 cl_autobind : 1,/* use getport() */
8207 - cl_chatty : 1;/* be verbose */
8208 + cl_chatty : 1,/* be verbose */
8209 + cl_tag : 1;/* context tagging */
8211 struct rpc_rtt * cl_rtt; /* RTO estimator data */
8212 const struct rpc_timeout *cl_timeout; /* Timeout strategy */
8213 diff -NurpP --minimal linux-3.9.4/include/linux/sysfs.h linux-3.9.4-vs2.3.6.2/include/linux/sysfs.h
8214 --- linux-3.9.4/include/linux/sysfs.h 2013-05-31 13:45:28.000000000 +0000
8215 +++ linux-3.9.4-vs2.3.6.2/include/linux/sysfs.h 2013-05-31 14:47:11.000000000 +0000
8217 #include <linux/kobject_ns.h>
8218 #include <linux/atomic.h>
8220 +#define SYSFS_SUPER_MAGIC 0x62656572
8225 diff -NurpP --minimal linux-3.9.4/include/linux/types.h linux-3.9.4-vs2.3.6.2/include/linux/types.h
8226 --- linux-3.9.4/include/linux/types.h 2013-02-19 13:58:52.000000000 +0000
8227 +++ linux-3.9.4-vs2.3.6.2/include/linux/types.h 2013-05-31 14:47:11.000000000 +0000
8228 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t uid_t;
8229 typedef __kernel_gid32_t gid_t;
8230 typedef __kernel_uid16_t uid16_t;
8231 typedef __kernel_gid16_t gid16_t;
8232 +typedef unsigned int xid_t;
8233 +typedef unsigned int nid_t;
8234 +typedef unsigned int tag_t;
8236 typedef unsigned long uintptr_t;
8238 diff -NurpP --minimal linux-3.9.4/include/linux/uidgid.h linux-3.9.4-vs2.3.6.2/include/linux/uidgid.h
8239 --- linux-3.9.4/include/linux/uidgid.h 2012-12-11 03:30:57.000000000 +0000
8240 +++ linux-3.9.4-vs2.3.6.2/include/linux/uidgid.h 2013-05-31 14:47:11.000000000 +0000
8241 @@ -23,13 +23,17 @@ typedef struct {
8254 #define KUIDT_INIT(value) (kuid_t){ value }
8255 #define KGIDT_INIT(value) (kgid_t){ value }
8256 +#define KTAGT_INIT(value) (ktag_t){ value }
8258 static inline uid_t __kuid_val(kuid_t uid)
8260 @@ -41,10 +45,16 @@ static inline gid_t __kgid_val(kgid_t gi
8264 +static inline tag_t __ktag_val(ktag_t tag)
8271 typedef uid_t kuid_t;
8272 typedef gid_t kgid_t;
8273 +typedef tag_t ktag_t;
8275 static inline uid_t __kuid_val(kuid_t uid)
8277 @@ -56,16 +66,24 @@ static inline gid_t __kgid_val(kgid_t gi
8281 +static inline tag_t __ktag_val(ktag_t tag)
8286 #define KUIDT_INIT(value) ((kuid_t) value )
8287 #define KGIDT_INIT(value) ((kgid_t) value )
8288 +#define KTAGT_INIT(value) ((ktag_t) value )
8292 #define GLOBAL_ROOT_UID KUIDT_INIT(0)
8293 #define GLOBAL_ROOT_GID KGIDT_INIT(0)
8294 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
8296 #define INVALID_UID KUIDT_INIT(-1)
8297 #define INVALID_GID KGIDT_INIT(-1)
8298 +#define INVALID_TAG KTAGT_INIT(-1)
8300 static inline bool uid_eq(kuid_t left, kuid_t right)
8302 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
8303 return __kgid_val(left) == __kgid_val(right);
8306 +static inline bool tag_eq(ktag_t left, ktag_t right)
8308 + return __ktag_val(left) == __ktag_val(right);
8311 static inline bool uid_gt(kuid_t left, kuid_t right)
8313 return __kuid_val(left) > __kuid_val(right);
8314 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
8315 return !gid_eq(gid, INVALID_GID);
8318 +static inline bool tag_valid(ktag_t tag)
8320 + return !tag_eq(tag, INVALID_TAG);
8323 #ifdef CONFIG_USER_NS
8325 extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
8326 extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
8327 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
8329 extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
8330 extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
8331 +extern tag_t from_ktag(struct user_namespace *to, ktag_t tag);
8333 extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
8334 extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
8336 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
8337 return KGIDT_INIT(gid);
8340 +static inline ktag_t make_ktag(struct user_namespace *from, tag_t tag)
8342 + return KTAGT_INIT(tag);
8345 static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
8347 return __kuid_val(kuid);
8348 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
8349 return __kgid_val(kgid);
8352 +static inline tag_t from_ktag(struct user_namespace *to, ktag_t ktag)
8354 + return __ktag_val(ktag);
8357 static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
8359 uid_t uid = from_kuid(to, kuid);
8360 diff -NurpP --minimal linux-3.9.4/include/linux/vroot.h linux-3.9.4-vs2.3.6.2/include/linux/vroot.h
8361 --- linux-3.9.4/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
8362 +++ linux-3.9.4-vs2.3.6.2/include/linux/vroot.h 2013-05-31 14:47:11.000000000 +0000
8366 + * include/linux/vroot.h
8368 + * written by Herbert Pötzl, 9/11/2002
8369 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
8371 + * Copyright (C) 2002-2007 by Herbert Pötzl.
8372 + * Redistribution of this file is permitted under the
8373 + * GNU General Public License.
8376 +#ifndef _LINUX_VROOT_H
8377 +#define _LINUX_VROOT_H
8382 +/* Possible states of device */
8388 +struct vroot_device {
8392 + struct semaphore vr_ctl_mutex;
8393 + struct block_device *vr_device;
8398 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
8400 +extern int register_vroot_grb(vroot_grb_func *);
8401 +extern int unregister_vroot_grb(vroot_grb_func *);
8403 +#endif /* __KERNEL__ */
8405 +#define MAX_VROOT_DEFAULT 8
8408 + * IOCTL commands --- we will commandeer 0x56 ('V')
8411 +#define VROOT_SET_DEV 0x5600
8412 +#define VROOT_CLR_DEV 0x5601
8414 +#endif /* _LINUX_VROOT_H */
8415 diff -NurpP --minimal linux-3.9.4/include/linux/vs_base.h linux-3.9.4-vs2.3.6.2/include/linux/vs_base.h
8416 --- linux-3.9.4/include/linux/vs_base.h 1970-01-01 00:00:00.000000000 +0000
8417 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_base.h 2013-05-31 14:47:11.000000000 +0000
8422 +#include "vserver/base.h"
8423 +#include "vserver/check.h"
8424 +#include "vserver/debug.h"
8427 +#warning duplicate inclusion
8429 diff -NurpP --minimal linux-3.9.4/include/linux/vs_context.h linux-3.9.4-vs2.3.6.2/include/linux/vs_context.h
8430 --- linux-3.9.4/include/linux/vs_context.h 1970-01-01 00:00:00.000000000 +0000
8431 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_context.h 2013-05-31 14:47:11.000000000 +0000
8433 +#ifndef _VS_CONTEXT_H
8434 +#define _VS_CONTEXT_H
8436 +#include "vserver/base.h"
8437 +#include "vserver/check.h"
8438 +#include "vserver/context.h"
8439 +#include "vserver/history.h"
8440 +#include "vserver/debug.h"
8442 +#include <linux/sched.h>
8445 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
8447 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
8448 + const char *_file, int _line, void *_here)
8453 + vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
8454 + vxi, vxi ? vxi->vx_id : 0,
8455 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8457 + __vxh_get_vx_info(vxi, _here);
8459 + atomic_inc(&vxi->vx_usecnt);
8464 +extern void free_vx_info(struct vx_info *);
8466 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
8468 +static inline void __put_vx_info(struct vx_info *vxi,
8469 + const char *_file, int _line, void *_here)
8474 + vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
8475 + vxi, vxi ? vxi->vx_id : 0,
8476 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8478 + __vxh_put_vx_info(vxi, _here);
8480 + if (atomic_dec_and_test(&vxi->vx_usecnt))
8481 + free_vx_info(vxi);
8485 +#define init_vx_info(p, i) \
8486 + __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8488 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8489 + const char *_file, int _line, void *_here)
8492 + vxlprintk(VXD_CBIT(xid, 3),
8493 + "init_vx_info(%p[#%d.%d])",
8494 + vxi, vxi ? vxi->vx_id : 0,
8495 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8497 + __vxh_init_vx_info(vxi, vxp, _here);
8499 + atomic_inc(&vxi->vx_usecnt);
8505 +#define set_vx_info(p, i) \
8506 + __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
8508 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
8509 + const char *_file, int _line, void *_here)
8511 + struct vx_info *vxo;
8516 + vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
8517 + vxi, vxi ? vxi->vx_id : 0,
8518 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8520 + __vxh_set_vx_info(vxi, vxp, _here);
8522 + atomic_inc(&vxi->vx_usecnt);
8523 + vxo = xchg(vxp, vxi);
8528 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
8530 +static inline void __clr_vx_info(struct vx_info **vxp,
8531 + const char *_file, int _line, void *_here)
8533 + struct vx_info *vxo;
8535 + vxo = xchg(vxp, NULL);
8539 + vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
8540 + vxo, vxo ? vxo->vx_id : 0,
8541 + vxo ? atomic_read(&vxo->vx_usecnt) : 0,
8543 + __vxh_clr_vx_info(vxo, vxp, _here);
8545 + if (atomic_dec_and_test(&vxo->vx_usecnt))
8546 + free_vx_info(vxo);
8550 +#define claim_vx_info(v, p) \
8551 + __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8553 +static inline void __claim_vx_info(struct vx_info *vxi,
8554 + struct task_struct *task,
8555 + const char *_file, int _line, void *_here)
8557 + vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
8558 + vxi, vxi ? vxi->vx_id : 0,
8559 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8560 + vxi ? atomic_read(&vxi->vx_tasks) : 0,
8561 + task, _file, _line);
8562 + __vxh_claim_vx_info(vxi, task, _here);
8564 + atomic_inc(&vxi->vx_tasks);
8568 +extern void unhash_vx_info(struct vx_info *);
8570 +#define release_vx_info(v, p) \
8571 + __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
8573 +static inline void __release_vx_info(struct vx_info *vxi,
8574 + struct task_struct *task,
8575 + const char *_file, int _line, void *_here)
8577 + vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
8578 + vxi, vxi ? vxi->vx_id : 0,
8579 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
8580 + vxi ? atomic_read(&vxi->vx_tasks) : 0,
8581 + task, _file, _line);
8582 + __vxh_release_vx_info(vxi, task, _here);
8586 + if (atomic_dec_and_test(&vxi->vx_tasks))
8587 + unhash_vx_info(vxi);
8591 +#define task_get_vx_info(p) \
8592 + __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
8594 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
8595 + const char *_file, int _line, void *_here)
8597 + struct vx_info *vxi;
8600 + vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
8602 + vxi = __get_vx_info(p->vx_info, _file, _line, _here);
8608 +static inline void __wakeup_vx_info(struct vx_info *vxi)
8610 + if (waitqueue_active(&vxi->vx_wait))
8611 + wake_up_interruptible(&vxi->vx_wait);
8615 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
8617 +static inline void __enter_vx_info(struct vx_info *vxi,
8618 + struct vx_info_save *vxis, const char *_file, int _line)
8620 + vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
8621 + vxi, vxi ? vxi->vx_id : 0, vxis, current,
8622 + current->xid, current->vx_info, _file, _line);
8623 + vxis->vxi = xchg(¤t->vx_info, vxi);
8624 + vxis->xid = current->xid;
8625 + current->xid = vxi ? vxi->vx_id : 0;
8628 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
8630 +static inline void __leave_vx_info(struct vx_info_save *vxis,
8631 + const char *_file, int _line)
8633 + vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
8634 + vxis, vxis->xid, vxis->vxi, current,
8635 + current->xid, current->vx_info, _file, _line);
8636 + (void)xchg(¤t->vx_info, vxis->vxi);
8637 + current->xid = vxis->xid;
8641 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
8643 + vxis->vxi = xchg(¤t->vx_info, NULL);
8644 + vxis->xid = xchg(¤t->xid, (xid_t)0);
8647 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
8649 + (void)xchg(¤t->xid, vxis->xid);
8650 + (void)xchg(¤t->vx_info, vxis->vxi);
8653 +#define task_is_init(p) \
8654 + __task_is_init(p, __FILE__, __LINE__, __HERE__)
8656 +static inline int __task_is_init(struct task_struct *p,
8657 + const char *_file, int _line, void *_here)
8659 + int is_init = is_global_init(p);
8663 + is_init = p->vx_info->vx_initpid == p->pid;
8668 +extern void exit_vx_info(struct task_struct *, int);
8669 +extern void exit_vx_info_early(struct task_struct *, int);
8673 +#warning duplicate inclusion
8675 diff -NurpP --minimal linux-3.9.4/include/linux/vs_cowbl.h linux-3.9.4-vs2.3.6.2/include/linux/vs_cowbl.h
8676 --- linux-3.9.4/include/linux/vs_cowbl.h 1970-01-01 00:00:00.000000000 +0000
8677 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_cowbl.h 2013-05-31 14:47:11.000000000 +0000
8679 +#ifndef _VS_COWBL_H
8680 +#define _VS_COWBL_H
8682 +#include <linux/fs.h>
8683 +#include <linux/dcache.h>
8684 +#include <linux/namei.h>
8685 +#include <linux/slab.h>
8687 +extern struct dentry *cow_break_link(const char *pathname);
8689 +static inline int cow_check_and_break(struct path *path)
8691 + struct inode *inode = path->dentry->d_inode;
8694 + /* do we need this check? */
8695 + if (IS_RDONLY(inode))
8698 + if (IS_COW(inode)) {
8699 + if (IS_COW_LINK(inode)) {
8700 + struct dentry *new_dentry, *old_dentry = path->dentry;
8703 + buf = kmalloc(PATH_MAX, GFP_KERNEL);
8707 + pp = d_path(path, buf, PATH_MAX);
8708 + new_dentry = cow_break_link(pp);
8710 + if (!IS_ERR(new_dentry)) {
8711 + path->dentry = new_dentry;
8714 + error = PTR_ERR(new_dentry);
8716 + inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
8717 + inode->i_ctime = CURRENT_TIME;
8718 + mark_inode_dirty(inode);
8725 +#warning duplicate inclusion
8727 diff -NurpP --minimal linux-3.9.4/include/linux/vs_cvirt.h linux-3.9.4-vs2.3.6.2/include/linux/vs_cvirt.h
8728 --- linux-3.9.4/include/linux/vs_cvirt.h 1970-01-01 00:00:00.000000000 +0000
8729 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_cvirt.h 2013-05-31 14:47:11.000000000 +0000
8731 +#ifndef _VS_CVIRT_H
8732 +#define _VS_CVIRT_H
8734 +#include "vserver/cvirt.h"
8735 +#include "vserver/context.h"
8736 +#include "vserver/base.h"
8737 +#include "vserver/check.h"
8738 +#include "vserver/debug.h"
8741 +static inline void vx_activate_task(struct task_struct *p)
8743 + struct vx_info *vxi;
8745 + if ((vxi = p->vx_info)) {
8746 + vx_update_load(vxi);
8747 + atomic_inc(&vxi->cvirt.nr_running);
8751 +static inline void vx_deactivate_task(struct task_struct *p)
8753 + struct vx_info *vxi;
8755 + if ((vxi = p->vx_info)) {
8756 + vx_update_load(vxi);
8757 + atomic_dec(&vxi->cvirt.nr_running);
8761 +static inline void vx_uninterruptible_inc(struct task_struct *p)
8763 + struct vx_info *vxi;
8765 + if ((vxi = p->vx_info))
8766 + atomic_inc(&vxi->cvirt.nr_uninterruptible);
8769 +static inline void vx_uninterruptible_dec(struct task_struct *p)
8771 + struct vx_info *vxi;
8773 + if ((vxi = p->vx_info))
8774 + atomic_dec(&vxi->cvirt.nr_uninterruptible);
8779 +#warning duplicate inclusion
8781 diff -NurpP --minimal linux-3.9.4/include/linux/vs_device.h linux-3.9.4-vs2.3.6.2/include/linux/vs_device.h
8782 --- linux-3.9.4/include/linux/vs_device.h 1970-01-01 00:00:00.000000000 +0000
8783 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_device.h 2013-05-31 14:47:11.000000000 +0000
8785 +#ifndef _VS_DEVICE_H
8786 +#define _VS_DEVICE_H
8788 +#include "vserver/base.h"
8789 +#include "vserver/device.h"
8790 +#include "vserver/debug.h"
8793 +#ifdef CONFIG_VSERVER_DEVICE
8795 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
8797 +#define vs_device_perm(v, d, m, p) \
8798 + ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
8803 +int vs_map_device(struct vx_info *vxi,
8804 + dev_t device, dev_t *target, umode_t mode)
8811 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8816 +#define vs_map_chrdev(d, t, p) \
8817 + ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8818 +#define vs_map_blkdev(d, t, p) \
8819 + ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8821 +#define vs_chrdev_perm(d, p) \
8822 + vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8823 +#define vs_blkdev_perm(d, p) \
8824 + vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8828 +#warning duplicate inclusion
8830 diff -NurpP --minimal linux-3.9.4/include/linux/vs_dlimit.h linux-3.9.4-vs2.3.6.2/include/linux/vs_dlimit.h
8831 --- linux-3.9.4/include/linux/vs_dlimit.h 1970-01-01 00:00:00.000000000 +0000
8832 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_dlimit.h 2013-05-31 14:47:11.000000000 +0000
8834 +#ifndef _VS_DLIMIT_H
8835 +#define _VS_DLIMIT_H
8837 +#include <linux/fs.h>
8839 +#include "vserver/dlimit.h"
8840 +#include "vserver/base.h"
8841 +#include "vserver/debug.h"
8844 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8846 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8847 + const char *_file, int _line)
8851 + vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8852 + dli, dli ? dli->dl_tag : 0,
8853 + dli ? atomic_read(&dli->dl_usecnt) : 0,
8855 + atomic_inc(&dli->dl_usecnt);
8860 +#define free_dl_info(i) \
8861 + call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8863 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8865 +static inline void __put_dl_info(struct dl_info *dli,
8866 + const char *_file, int _line)
8870 + vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8871 + dli, dli ? dli->dl_tag : 0,
8872 + dli ? atomic_read(&dli->dl_usecnt) : 0,
8874 + if (atomic_dec_and_test(&dli->dl_usecnt))
8875 + free_dl_info(dli);
8879 +#define __dlimit_char(d) ((d) ? '*' : ' ')
8881 +static inline int __dl_alloc_space(struct super_block *sb,
8882 + tag_t tag, dlsize_t nr, const char *file, int line)
8884 + struct dl_info *dli = NULL;
8889 + dli = locate_dl_info(sb, tag);
8893 + spin_lock(&dli->dl_lock);
8894 + ret = (dli->dl_space_used + nr > dli->dl_space_total);
8896 + dli->dl_space_used += nr;
8897 + spin_unlock(&dli->dl_lock);
8900 + vxlprintk(VXD_CBIT(dlim, 1),
8901 + "ALLOC (%p,#%d)%c %lld bytes (%d)",
8902 + sb, tag, __dlimit_char(dli), (long long)nr,
8904 + return ret ? -ENOSPC : 0;
8907 +static inline void __dl_free_space(struct super_block *sb,
8908 + tag_t tag, dlsize_t nr, const char *_file, int _line)
8910 + struct dl_info *dli = NULL;
8914 + dli = locate_dl_info(sb, tag);
8918 + spin_lock(&dli->dl_lock);
8919 + if (dli->dl_space_used > nr)
8920 + dli->dl_space_used -= nr;
8922 + dli->dl_space_used = 0;
8923 + spin_unlock(&dli->dl_lock);
8926 + vxlprintk(VXD_CBIT(dlim, 1),
8927 + "FREE (%p,#%d)%c %lld bytes",
8928 + sb, tag, __dlimit_char(dli), (long long)nr,
8932 +static inline int __dl_alloc_inode(struct super_block *sb,
8933 + tag_t tag, const char *_file, int _line)
8935 + struct dl_info *dli;
8938 + dli = locate_dl_info(sb, tag);
8942 + spin_lock(&dli->dl_lock);
8943 + dli->dl_inodes_used++;
8944 + ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8945 + spin_unlock(&dli->dl_lock);
8948 + vxlprintk(VXD_CBIT(dlim, 0),
8949 + "ALLOC (%p,#%d)%c inode (%d)",
8950 + sb, tag, __dlimit_char(dli), ret, _file, _line);
8951 + return ret ? -ENOSPC : 0;
8954 +static inline void __dl_free_inode(struct super_block *sb,
8955 + tag_t tag, const char *_file, int _line)
8957 + struct dl_info *dli;
8959 + dli = locate_dl_info(sb, tag);
8963 + spin_lock(&dli->dl_lock);
8964 + if (dli->dl_inodes_used > 1)
8965 + dli->dl_inodes_used--;
8967 + dli->dl_inodes_used = 0;
8968 + spin_unlock(&dli->dl_lock);
8971 + vxlprintk(VXD_CBIT(dlim, 0),
8972 + "FREE (%p,#%d)%c inode",
8973 + sb, tag, __dlimit_char(dli), _file, _line);
8976 +static inline void __dl_adjust_block(struct super_block *sb, tag_t tag,
8977 + unsigned long long *free_blocks, unsigned long long *root_blocks,
8978 + const char *_file, int _line)
8980 + struct dl_info *dli;
8981 + uint64_t broot, bfree;
8983 + dli = locate_dl_info(sb, tag);
8987 + spin_lock(&dli->dl_lock);
8988 + broot = (dli->dl_space_total -
8989 + (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8990 + >> sb->s_blocksize_bits;
8991 + bfree = (dli->dl_space_total - dli->dl_space_used)
8992 + >> sb->s_blocksize_bits;
8993 + spin_unlock(&dli->dl_lock);
8995 + vxlprintk(VXD_CBIT(dlim, 2),
8996 + "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8997 + (long long)bfree, (long long)broot,
8998 + *free_blocks, *root_blocks, dli->dl_nrlmult,
9000 + if (free_blocks) {
9001 + if (*free_blocks > bfree)
9002 + *free_blocks = bfree;
9004 + if (root_blocks) {
9005 + if (*root_blocks > broot)
9006 + *root_blocks = broot;
9011 +#define dl_prealloc_space(in, bytes) \
9012 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9013 + __FILE__, __LINE__ )
9015 +#define dl_alloc_space(in, bytes) \
9016 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9017 + __FILE__, __LINE__ )
9019 +#define dl_reserve_space(in, bytes) \
9020 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9021 + __FILE__, __LINE__ )
9023 +#define dl_claim_space(in, bytes) (0)
9025 +#define dl_release_space(in, bytes) \
9026 + __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9027 + __FILE__, __LINE__ )
9029 +#define dl_free_space(in, bytes) \
9030 + __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
9031 + __FILE__, __LINE__ )
9035 +#define dl_alloc_inode(in) \
9036 + __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
9038 +#define dl_free_inode(in) \
9039 + __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
9042 +#define dl_adjust_block(sb, tag, fb, rb) \
9043 + __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
9047 +#warning duplicate inclusion
9049 diff -NurpP --minimal linux-3.9.4/include/linux/vs_inet.h linux-3.9.4-vs2.3.6.2/include/linux/vs_inet.h
9050 --- linux-3.9.4/include/linux/vs_inet.h 1970-01-01 00:00:00.000000000 +0000
9051 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_inet.h 2013-05-31 14:47:11.000000000 +0000
9056 +#include "vserver/base.h"
9057 +#include "vserver/network.h"
9058 +#include "vserver/debug.h"
9060 +#define IPI_LOOPBACK htonl(INADDR_LOOPBACK)
9062 +#define NXAV4(a) NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
9063 + NIPQUAD((a)->mask), (a)->type
9064 +#define NXAV4_FMT "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
9066 +#define NIPQUAD(addr) \
9067 + ((unsigned char *)&addr)[0], \
9068 + ((unsigned char *)&addr)[1], \
9069 + ((unsigned char *)&addr)[2], \
9070 + ((unsigned char *)&addr)[3]
9072 +#define NIPQUAD_FMT "%u.%u.%u.%u"
9076 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
9078 + __be32 ip = nxa->ip[0].s_addr;
9079 + __be32 mask = nxa->mask.s_addr;
9080 + __be32 bcast = ip | ~mask;
9083 + switch (nxa->type & tmask) {
9084 + case NXA_TYPE_MASK:
9085 + ret = (ip == (addr & mask));
9087 + case NXA_TYPE_ADDR:
9091 + /* fall through to broadcast */
9092 + case NXA_MOD_BCAST:
9093 + ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
9095 + case NXA_TYPE_RANGE:
9096 + ret = ((nxa->ip[0].s_addr <= addr) &&
9097 + (nxa->ip[1].s_addr > addr));
9099 + case NXA_TYPE_ANY:
9104 + vxdprintk(VXD_CBIT(net, 0),
9105 + "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
9106 + nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
9111 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
9113 + struct nx_addr_v4 *nxa;
9114 + unsigned long irqflags;
9121 + /* allow 127.0.0.1 when remapping lback */
9122 + if ((tmask & NXA_LOOPBACK) &&
9123 + (addr == IPI_LOOPBACK) &&
9124 + nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9127 + /* check for lback address */
9128 + if ((tmask & NXA_MOD_LBACK) &&
9129 + (nxi->v4_lback.s_addr == addr))
9132 + /* check for broadcast address */
9133 + if ((tmask & NXA_MOD_BCAST) &&
9134 + (nxi->v4_bcast.s_addr == addr))
9138 + /* check for v4 addresses */
9139 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
9140 + for (nxa = &nxi->v4; nxa; nxa = nxa->next)
9141 + if (v4_addr_match(nxa, addr, tmask))
9145 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9147 + vxdprintk(VXD_CBIT(net, 0),
9148 + "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
9149 + nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
9154 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
9156 + /* FIXME: needs full range checks */
9157 + return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
9161 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
9163 + struct nx_addr_v4 *ptr;
9164 + unsigned long irqflags;
9167 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
9168 + for (ptr = &nxi->v4; ptr; ptr = ptr->next)
9169 + if (v4_nx_addr_match(ptr, nxa, mask))
9173 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9177 +#include <net/inet_sock.h>
9180 + * Check if a given address matches for a socket
9182 + * nxi: the socket's nx_info if any
9183 + * addr: to be verified address
9186 +int v4_sock_addr_match (
9187 + struct nx_info *nxi,
9188 + struct inet_sock *inet,
9191 + __be32 saddr = inet->inet_rcv_saddr;
9192 + __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
9194 + if (addr && (saddr == addr || bcast == addr))
9197 + return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
9202 +/* inet related checks and helpers */
9211 +#include <linux/netdevice.h>
9212 +#include <linux/inetdevice.h>
9213 +#include <net/inet_sock.h>
9214 +#include <net/inet_timewait_sock.h>
9217 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9218 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
9219 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
9223 + * check if address is covered by socket
9225 + * sk: the socket to check against
9226 + * addr: the address in question (must be != 0)
9230 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
9232 + struct nx_info *nxi = sk->sk_nx_info;
9233 + __be32 saddr = sk_rcv_saddr(sk);
9235 + vxdprintk(VXD_CBIT(net, 5),
9236 + "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
9237 + sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
9238 + (sk->sk_socket?sk->sk_socket->flags:0));
9240 + if (saddr) { /* direct address match */
9241 + return v4_addr_match(nxa, saddr, -1);
9242 + } else if (nxi) { /* match against nx_info */
9243 + return v4_nx_addr_in_nx_info(nxi, nxa, -1);
9244 + } else { /* unrestricted any socket */
9252 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
9254 + vxdprintk(VXD_CBIT(net, 1),
9255 + "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
9256 + nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
9257 + nxi ? dev_in_nx_info(dev, nxi) : 0);
9259 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9261 + if (dev_in_nx_info(dev, nxi))
9268 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
9274 + return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
9278 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
9280 + vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
9281 + nxi, nxi ? nxi->nx_id : 0, ifa,
9282 + nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
9284 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9286 + if (v4_ifa_in_nx_info(ifa, nxi))
9292 +struct nx_v4_sock_addr {
9293 + __be32 saddr; /* Address used for validation */
9294 + __be32 baddr; /* Address used for socket bind */
9298 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
9299 + struct nx_v4_sock_addr *nsa)
9301 + struct sock *sk = &inet->sk;
9302 + struct nx_info *nxi = sk->sk_nx_info;
9303 + __be32 saddr = addr->sin_addr.s_addr;
9304 + __be32 baddr = saddr;
9306 + vxdprintk(VXD_CBIT(net, 3),
9307 + "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
9308 + sk, sk->sk_nx_info, sk->sk_socket,
9309 + (sk->sk_socket ? sk->sk_socket->flags : 0),
9313 + if (saddr == INADDR_ANY) {
9314 + if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
9315 + baddr = nxi->v4.ip[0].s_addr;
9316 + } else if (saddr == IPI_LOOPBACK) {
9317 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9318 + baddr = nxi->v4_lback.s_addr;
9319 + } else if (!ipv4_is_multicast(saddr) ||
9320 + !nx_info_ncaps(nxi, NXC_MULTICAST)) {
9321 + /* normal address bind */
9322 + if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
9323 + return -EADDRNOTAVAIL;
9327 + vxdprintk(VXD_CBIT(net, 3),
9328 + "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
9329 + sk, NIPQUAD(saddr), NIPQUAD(baddr));
9331 + nsa->saddr = saddr;
9332 + nsa->baddr = baddr;
9337 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
9339 + inet->inet_saddr = nsa->baddr;
9340 + inet->inet_rcv_saddr = nsa->baddr;
9345 + * helper to simplify inet_lookup_listener
9347 + * nxi: the socket's nx_info if any
9348 + * addr: to be verified address
9349 + * saddr: socket address
9351 +static inline int v4_inet_addr_match (
9352 + struct nx_info *nxi,
9356 + if (addr && (saddr == addr))
9359 + return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
9363 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
9365 + if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
9366 + (addr == nxi->v4_lback.s_addr))
9367 + return IPI_LOOPBACK;
9372 +int nx_info_has_v4(struct nx_info *nxi)
9378 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
9383 +#else /* CONFIG_INET */
9386 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
9392 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9398 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9404 +int nx_info_has_v4(struct nx_info *nxi)
9409 +#endif /* CONFIG_INET */
9411 +#define current_nx_info_has_v4() \
9412 + nx_info_has_v4(current_nx_info())
9415 +// #warning duplicate inclusion
9417 diff -NurpP --minimal linux-3.9.4/include/linux/vs_inet6.h linux-3.9.4-vs2.3.6.2/include/linux/vs_inet6.h
9418 --- linux-3.9.4/include/linux/vs_inet6.h 1970-01-01 00:00:00.000000000 +0000
9419 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_inet6.h 2013-05-31 14:47:11.000000000 +0000
9421 +#ifndef _VS_INET6_H
9422 +#define _VS_INET6_H
9424 +#include "vserver/base.h"
9425 +#include "vserver/network.h"
9426 +#include "vserver/debug.h"
9428 +#include <net/ipv6.h>
9430 +#define NXAV6(a) &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
9431 +#define NXAV6_FMT "[%pI6/%pI6/%d:%04x]"
9437 +int v6_addr_match(struct nx_addr_v6 *nxa,
9438 + const struct in6_addr *addr, uint16_t mask)
9442 + switch (nxa->type & mask) {
9443 + case NXA_TYPE_MASK:
9444 + ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
9446 + case NXA_TYPE_ADDR:
9447 + ret = ipv6_addr_equal(&nxa->ip, addr);
9449 + case NXA_TYPE_ANY:
9453 + vxdprintk(VXD_CBIT(net, 0),
9454 + "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
9455 + nxa, NXAV6(nxa), addr, mask, ret);
9460 +int v6_addr_in_nx_info(struct nx_info *nxi,
9461 + const struct in6_addr *addr, uint16_t mask)
9463 + struct nx_addr_v6 *nxa;
9464 + unsigned long irqflags;
9470 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
9471 + for (nxa = &nxi->v6; nxa; nxa = nxa->next)
9472 + if (v6_addr_match(nxa, addr, mask))
9476 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9478 + vxdprintk(VXD_CBIT(net, 0),
9479 + "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
9480 + nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
9485 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
9487 + /* FIXME: needs full range checks */
9488 + return v6_addr_match(nxa, &addr->ip, mask);
9492 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
9494 + struct nx_addr_v6 *ptr;
9495 + unsigned long irqflags;
9498 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
9499 + for (ptr = &nxi->v6; ptr; ptr = ptr->next)
9500 + if (v6_nx_addr_match(ptr, nxa, mask))
9504 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
9510 + * Check if a given address matches for a socket
9512 + * nxi: the socket's nx_info if any
9513 + * addr: to be verified address
9516 +int v6_sock_addr_match (
9517 + struct nx_info *nxi,
9518 + struct inet_sock *inet,
9519 + struct in6_addr *addr)
9521 + struct sock *sk = &inet->sk;
9522 + struct in6_addr *saddr = inet6_rcv_saddr(sk);
9524 + if (!ipv6_addr_any(addr) &&
9525 + ipv6_addr_equal(saddr, addr))
9527 + if (ipv6_addr_any(saddr))
9528 + return v6_addr_in_nx_info(nxi, addr, -1);
9533 + * check if address is covered by socket
9535 + * sk: the socket to check against
9536 + * addr: the address in question (must be != 0)
9540 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
9542 + struct nx_info *nxi = sk->sk_nx_info;
9543 + struct in6_addr *saddr = inet6_rcv_saddr(sk);
9545 + vxdprintk(VXD_CBIT(net, 5),
9546 + "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
9547 + sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
9548 + (sk->sk_socket?sk->sk_socket->flags:0));
9550 + if (!ipv6_addr_any(saddr)) { /* direct address match */
9551 + return v6_addr_match(nxa, saddr, -1);
9552 + } else if (nxi) { /* match against nx_info */
9553 + return v6_nx_addr_in_nx_info(nxi, nxa, -1);
9554 + } else { /* unrestricted any socket */
9560 +/* inet related checks and helpers */
9568 +#include <linux/netdevice.h>
9569 +#include <linux/inetdevice.h>
9570 +#include <net/inet_timewait_sock.h>
9573 +int dev_in_nx_info(struct net_device *, struct nx_info *);
9574 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
9575 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
9580 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
9586 + return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
9590 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
9592 + vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
9593 + nxi, nxi ? nxi->nx_id : 0, ifa,
9594 + nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
9596 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
9598 + if (v6_ifa_in_nx_info(ifa, nxi))
9604 +struct nx_v6_sock_addr {
9605 + struct in6_addr saddr; /* Address used for validation */
9606 + struct in6_addr baddr; /* Address used for socket bind */
9610 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
9611 + struct nx_v6_sock_addr *nsa)
9613 + // struct sock *sk = &inet->sk;
9614 + // struct nx_info *nxi = sk->sk_nx_info;
9615 + struct in6_addr saddr = addr->sin6_addr;
9616 + struct in6_addr baddr = saddr;
9618 + nsa->saddr = saddr;
9619 + nsa->baddr = baddr;
9624 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
9626 + // struct sock *sk = &inet->sk;
9627 + // struct in6_addr *saddr = inet6_rcv_saddr(sk);
9629 + // *saddr = nsa->baddr;
9630 + // inet->inet_saddr = nsa->baddr;
9634 +int nx_info_has_v6(struct nx_info *nxi)
9643 +#else /* CONFIG_IPV6 */
9646 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
9653 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
9659 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
9665 +int nx_info_has_v6(struct nx_info *nxi)
9670 +#endif /* CONFIG_IPV6 */
9672 +#define current_nx_info_has_v6() \
9673 + nx_info_has_v6(current_nx_info())
9676 +#warning duplicate inclusion
9678 diff -NurpP --minimal linux-3.9.4/include/linux/vs_limit.h linux-3.9.4-vs2.3.6.2/include/linux/vs_limit.h
9679 --- linux-3.9.4/include/linux/vs_limit.h 1970-01-01 00:00:00.000000000 +0000
9680 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_limit.h 2013-05-31 14:47:11.000000000 +0000
9682 +#ifndef _VS_LIMIT_H
9683 +#define _VS_LIMIT_H
9685 +#include "vserver/limit.h"
9686 +#include "vserver/base.h"
9687 +#include "vserver/context.h"
9688 +#include "vserver/debug.h"
9689 +#include "vserver/context.h"
9690 +#include "vserver/limit_int.h"
9693 +#define vx_acc_cres(v, d, p, r) \
9694 + __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
9696 +#define vx_acc_cres_cond(x, d, p, r) \
9697 + __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9698 + r, d, p, __FILE__, __LINE__)
9701 +#define vx_add_cres(v, a, p, r) \
9702 + __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
9703 +#define vx_sub_cres(v, a, p, r) vx_add_cres(v, -(a), p, r)
9705 +#define vx_add_cres_cond(x, a, p, r) \
9706 + __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
9707 + r, a, p, __FILE__, __LINE__)
9708 +#define vx_sub_cres_cond(x, a, p, r) vx_add_cres_cond(x, -(a), p, r)
9711 +/* process and file limits */
9713 +#define vx_nproc_inc(p) \
9714 + vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
9716 +#define vx_nproc_dec(p) \
9717 + vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
9719 +#define vx_files_inc(f) \
9720 + vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
9722 +#define vx_files_dec(f) \
9723 + vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
9725 +#define vx_locks_inc(l) \
9726 + vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
9728 +#define vx_locks_dec(l) \
9729 + vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
9731 +#define vx_openfd_inc(f) \
9732 + vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
9734 +#define vx_openfd_dec(f) \
9735 + vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
9738 +#define vx_cres_avail(v, n, r) \
9739 + __vx_cres_avail(v, r, n, __FILE__, __LINE__)
9742 +#define vx_nproc_avail(n) \
9743 + vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
9745 +#define vx_files_avail(n) \
9746 + vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
9748 +#define vx_locks_avail(n) \
9749 + vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
9751 +#define vx_openfd_avail(n) \
9752 + vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
9755 +/* dentry limits */
9757 +#define vx_dentry_inc(d) do { \
9758 + if ((d)->d_count == 1) \
9759 + vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY); \
9762 +#define vx_dentry_dec(d) do { \
9763 + if ((d)->d_count == 0) \
9764 + vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY); \
9767 +#define vx_dentry_avail(n) \
9768 + vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
9771 +/* socket limits */
9773 +#define vx_sock_inc(s) \
9774 + vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
9776 +#define vx_sock_dec(s) \
9777 + vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
9779 +#define vx_sock_avail(n) \
9780 + vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
9783 +/* ipc resource limits */
9785 +#define vx_ipcmsg_add(v, u, a) \
9786 + vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
9788 +#define vx_ipcmsg_sub(v, u, a) \
9789 + vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
9791 +#define vx_ipcmsg_avail(v, a) \
9792 + vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
9795 +#define vx_ipcshm_add(v, k, a) \
9796 + vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9798 +#define vx_ipcshm_sub(v, k, a) \
9799 + vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
9801 +#define vx_ipcshm_avail(v, a) \
9802 + vx_cres_avail(v, a, VLIMIT_SHMEM)
9805 +#define vx_semary_inc(a) \
9806 + vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
9808 +#define vx_semary_dec(a) \
9809 + vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
9812 +#define vx_nsems_add(a,n) \
9813 + vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9815 +#define vx_nsems_sub(a,n) \
9816 + vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9820 +#warning duplicate inclusion
9822 diff -NurpP --minimal linux-3.9.4/include/linux/vs_network.h linux-3.9.4-vs2.3.6.2/include/linux/vs_network.h
9823 --- linux-3.9.4/include/linux/vs_network.h 1970-01-01 00:00:00.000000000 +0000
9824 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_network.h 2013-05-31 14:47:11.000000000 +0000
9826 +#ifndef _NX_VS_NETWORK_H
9827 +#define _NX_VS_NETWORK_H
9829 +#include "vserver/context.h"
9830 +#include "vserver/network.h"
9831 +#include "vserver/base.h"
9832 +#include "vserver/check.h"
9833 +#include "vserver/debug.h"
9835 +#include <linux/sched.h>
9838 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9840 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9841 + const char *_file, int _line)
9846 + vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9847 + nxi, nxi ? nxi->nx_id : 0,
9848 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9851 + atomic_inc(&nxi->nx_usecnt);
9856 +extern void free_nx_info(struct nx_info *);
9858 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9860 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9865 + vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9866 + nxi, nxi ? nxi->nx_id : 0,
9867 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9870 + if (atomic_dec_and_test(&nxi->nx_usecnt))
9871 + free_nx_info(nxi);
9875 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9877 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9878 + const char *_file, int _line)
9881 + vxlprintk(VXD_CBIT(nid, 3),
9882 + "init_nx_info(%p[#%d.%d])",
9883 + nxi, nxi ? nxi->nx_id : 0,
9884 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9887 + atomic_inc(&nxi->nx_usecnt);
9893 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9895 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9896 + const char *_file, int _line)
9898 + struct nx_info *nxo;
9903 + vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9904 + nxi, nxi ? nxi->nx_id : 0,
9905 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9908 + atomic_inc(&nxi->nx_usecnt);
9909 + nxo = xchg(nxp, nxi);
9913 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9915 +static inline void __clr_nx_info(struct nx_info **nxp,
9916 + const char *_file, int _line)
9918 + struct nx_info *nxo;
9920 + nxo = xchg(nxp, NULL);
9924 + vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9925 + nxo, nxo ? nxo->nx_id : 0,
9926 + nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9929 + if (atomic_dec_and_test(&nxo->nx_usecnt))
9930 + free_nx_info(nxo);
9934 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9936 +static inline void __claim_nx_info(struct nx_info *nxi,
9937 + struct task_struct *task, const char *_file, int _line)
9939 + vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9940 + nxi, nxi ? nxi->nx_id : 0,
9941 + nxi?atomic_read(&nxi->nx_usecnt):0,
9942 + nxi?atomic_read(&nxi->nx_tasks):0,
9943 + task, _file, _line);
9945 + atomic_inc(&nxi->nx_tasks);
9949 +extern void unhash_nx_info(struct nx_info *);
9951 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9953 +static inline void __release_nx_info(struct nx_info *nxi,
9954 + struct task_struct *task, const char *_file, int _line)
9956 + vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9957 + nxi, nxi ? nxi->nx_id : 0,
9958 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9959 + nxi ? atomic_read(&nxi->nx_tasks) : 0,
9960 + task, _file, _line);
9964 + if (atomic_dec_and_test(&nxi->nx_tasks))
9965 + unhash_nx_info(nxi);
9969 +#define task_get_nx_info(i) __task_get_nx_info(i, __FILE__, __LINE__)
9971 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9972 + const char *_file, int _line)
9974 + struct nx_info *nxi;
9977 + vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9979 + nxi = __get_nx_info(p->nx_info, _file, _line);
9985 +static inline void exit_nx_info(struct task_struct *p)
9988 + release_nx_info(p->nx_info, p);
9993 +#warning duplicate inclusion
9995 diff -NurpP --minimal linux-3.9.4/include/linux/vs_pid.h linux-3.9.4-vs2.3.6.2/include/linux/vs_pid.h
9996 --- linux-3.9.4/include/linux/vs_pid.h 1970-01-01 00:00:00.000000000 +0000
9997 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_pid.h 2013-05-31 14:47:11.000000000 +0000
10002 +#include "vserver/base.h"
10003 +#include "vserver/check.h"
10004 +#include "vserver/context.h"
10005 +#include "vserver/debug.h"
10006 +#include "vserver/pid.h"
10007 +#include <linux/pid_namespace.h>
10010 +#define VXF_FAKE_INIT (VXF_INFO_INIT | VXF_STATE_INIT)
10013 +int vx_proc_task_visible(struct task_struct *task)
10015 + if ((task->pid == 1) &&
10016 + !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
10017 + /* show a blend through init */
10019 + if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
10026 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
10030 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
10032 + struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
10034 + if (task && !vx_proc_task_visible(task)) {
10035 + vxdprintk(VXD_CBIT(misc, 6),
10036 + "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
10037 + task, task->xid, task->pid,
10038 + current, current->xid, current->pid);
10039 + put_task_struct(task);
10047 +#warning duplicate inclusion
10049 diff -NurpP --minimal linux-3.9.4/include/linux/vs_sched.h linux-3.9.4-vs2.3.6.2/include/linux/vs_sched.h
10050 --- linux-3.9.4/include/linux/vs_sched.h 1970-01-01 00:00:00.000000000 +0000
10051 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_sched.h 2013-05-31 14:47:11.000000000 +0000
10053 +#ifndef _VS_SCHED_H
10054 +#define _VS_SCHED_H
10056 +#include "vserver/base.h"
10057 +#include "vserver/context.h"
10058 +#include "vserver/sched.h"
10061 +#define MAX_PRIO_BIAS 20
10062 +#define MIN_PRIO_BIAS -20
10065 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
10067 + struct vx_info *vxi = p->vx_info;
10070 + prio += vx_cpu(vxi, sched_pc).prio_bias;
10074 +static inline void vx_account_user(struct vx_info *vxi,
10075 + cputime_t cputime, int nice)
10079 + vx_cpu(vxi, sched_pc).user_ticks += cputime;
10082 +static inline void vx_account_system(struct vx_info *vxi,
10083 + cputime_t cputime, int idle)
10087 + vx_cpu(vxi, sched_pc).sys_ticks += cputime;
10091 +#warning duplicate inclusion
10093 diff -NurpP --minimal linux-3.9.4/include/linux/vs_socket.h linux-3.9.4-vs2.3.6.2/include/linux/vs_socket.h
10094 --- linux-3.9.4/include/linux/vs_socket.h 1970-01-01 00:00:00.000000000 +0000
10095 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_socket.h 2013-05-31 14:47:11.000000000 +0000
10097 +#ifndef _VS_SOCKET_H
10098 +#define _VS_SOCKET_H
10100 +#include "vserver/debug.h"
10101 +#include "vserver/base.h"
10102 +#include "vserver/cacct.h"
10103 +#include "vserver/context.h"
10104 +#include "vserver/tag.h"
10107 +/* socket accounting */
10109 +#include <linux/socket.h>
10111 +static inline int vx_sock_type(int family)
10113 + switch (family) {
10115 + return VXA_SOCK_UNSPEC;
10117 + return VXA_SOCK_UNIX;
10119 + return VXA_SOCK_INET;
10121 + return VXA_SOCK_INET6;
10123 + return VXA_SOCK_PACKET;
10125 + return VXA_SOCK_OTHER;
10129 +#define vx_acc_sock(v, f, p, s) \
10130 + __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
10132 +static inline void __vx_acc_sock(struct vx_info *vxi,
10133 + int family, int pos, int size, char *file, int line)
10136 + int type = vx_sock_type(family);
10138 + atomic_long_inc(&vxi->cacct.sock[type][pos].count);
10139 + atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
10143 +#define vx_sock_recv(sk, s) \
10144 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
10145 +#define vx_sock_send(sk, s) \
10146 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
10147 +#define vx_sock_fail(sk, s) \
10148 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
10151 +#define sock_vx_init(s) do { \
10152 + (s)->sk_xid = 0; \
10153 + (s)->sk_vx_info = NULL; \
10156 +#define sock_nx_init(s) do { \
10157 + (s)->sk_nid = 0; \
10158 + (s)->sk_nx_info = NULL; \
10162 +#warning duplicate inclusion
10164 diff -NurpP --minimal linux-3.9.4/include/linux/vs_tag.h linux-3.9.4-vs2.3.6.2/include/linux/vs_tag.h
10165 --- linux-3.9.4/include/linux/vs_tag.h 1970-01-01 00:00:00.000000000 +0000
10166 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_tag.h 2013-05-31 14:47:11.000000000 +0000
10171 +#include <linux/vserver/tag.h>
10173 +/* check conditions */
10175 +#define DX_ADMIN 0x0001
10176 +#define DX_WATCH 0x0002
10177 +#define DX_HOSTID 0x0008
10179 +#define DX_IDENT 0x0010
10181 +#define DX_ARG_MASK 0x0010
10184 +#define dx_task_tag(t) ((t)->tag)
10186 +#define dx_current_tag() dx_task_tag(current)
10188 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
10190 +#define dx_weak_check(c, m) ((m) ? dx_check(c, m) : 1)
10194 + * check current context for ADMIN/WATCH and
10195 + * optionally against supplied argument
10197 +static inline int __dx_check(tag_t cid, tag_t id, unsigned int mode)
10199 + if (mode & DX_ARG_MASK) {
10200 + if ((mode & DX_IDENT) && (id == cid))
10203 + return (((mode & DX_ADMIN) && (cid == 0)) ||
10204 + ((mode & DX_WATCH) && (cid == 1)) ||
10205 + ((mode & DX_HOSTID) && (id == 0)));
10209 +int dx_permission(const struct inode *inode, int mask);
10213 +#warning duplicate inclusion
10215 diff -NurpP --minimal linux-3.9.4/include/linux/vs_time.h linux-3.9.4-vs2.3.6.2/include/linux/vs_time.h
10216 --- linux-3.9.4/include/linux/vs_time.h 1970-01-01 00:00:00.000000000 +0000
10217 +++ linux-3.9.4-vs2.3.6.2/include/linux/vs_time.h 2013-05-31 14:47:11.000000000 +0000
10219 +#ifndef _VS_TIME_H
10220 +#define _VS_TIME_H
10223 +/* time faking stuff */
10225 +#ifdef CONFIG_VSERVER_VTIME
10227 +extern void vx_adjust_timespec(struct timespec *ts);
10228 +extern int vx_settimeofday(const struct timespec *ts);
10231 +#define vx_adjust_timespec(t) do { } while (0)
10232 +#define vx_settimeofday(t) do_settimeofday(t)
10236 +#warning duplicate inclusion
10238 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/base.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/base.h
10239 --- linux-3.9.4/include/linux/vserver/base.h 1970-01-01 00:00:00.000000000 +0000
10240 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/base.h 2013-05-31 17:55:09.000000000 +0000
10242 +#ifndef _VSERVER_BASE_H
10243 +#define _VSERVER_BASE_H
10246 +/* context state changes */
10258 +#define vx_task_xid(t) ((t)->xid)
10260 +#define vx_current_xid() vx_task_xid(current)
10262 +#define current_vx_info() (current->vx_info)
10265 +#define nx_task_nid(t) ((t)->nid)
10267 +#define nx_current_nid() nx_task_nid(current)
10269 +#define current_nx_info() (current->nx_info)
10272 +/* generic flag merging */
10274 +#define vs_check_flags(v, m, f) (((v) & (m)) ^ (f))
10276 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
10278 +#define vs_mask_mask(v, f, m) (((v) & ~(m)) | ((v) & (f) & (m)))
10280 +#define vs_check_bit(v, n) ((v) & (1LL << (n)))
10283 +/* context flags */
10285 +#define __vx_flags(v) ((v) ? (v)->vx_flags : 0)
10287 +#define vx_current_flags() __vx_flags(current_vx_info())
10289 +#define vx_info_flags(v, m, f) \
10290 + vs_check_flags(__vx_flags(v), m, f)
10292 +#define task_vx_flags(t, m, f) \
10293 + ((t) && vx_info_flags((t)->vx_info, m, f))
10295 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
10298 +/* context caps */
10300 +#define __vx_ccaps(v) ((v) ? (v)->vx_ccaps : 0)
10302 +#define vx_current_ccaps() __vx_ccaps(current_vx_info())
10304 +#define vx_info_ccaps(v, c) (__vx_ccaps(v) & (c))
10306 +#define vx_ccaps(c) vx_info_ccaps(current_vx_info(), (c))
10310 +/* network flags */
10312 +#define __nx_flags(n) ((n) ? (n)->nx_flags : 0)
10314 +#define nx_current_flags() __nx_flags(current_nx_info())
10316 +#define nx_info_flags(n, m, f) \
10317 + vs_check_flags(__nx_flags(n), m, f)
10319 +#define task_nx_flags(t, m, f) \
10320 + ((t) && nx_info_flags((t)->nx_info, m, f))
10322 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
10325 +/* network caps */
10327 +#define __nx_ncaps(n) ((n) ? (n)->nx_ncaps : 0)
10329 +#define nx_current_ncaps() __nx_ncaps(current_nx_info())
10331 +#define nx_info_ncaps(n, c) (__nx_ncaps(n) & (c))
10333 +#define nx_ncaps(c) nx_info_ncaps(current_nx_info(), c)
10336 +/* context mask capabilities */
10338 +#define __vx_mcaps(v) ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
10340 +#define vx_info_mcaps(v, c) (__vx_mcaps(v) & (c))
10342 +#define vx_mcaps(c) vx_info_mcaps(current_vx_info(), c)
10345 +/* context bcap mask */
10347 +#define __vx_bcaps(v) ((v)->vx_bcaps)
10349 +#define vx_current_bcaps() __vx_bcaps(current_vx_info())
10352 +/* mask given bcaps */
10354 +#define vx_info_mbcaps(v, c) ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
10356 +#define vx_mbcaps(c) vx_info_mbcaps(current_vx_info(), c)
10359 +/* masked cap_bset */
10361 +#define vx_info_cap_bset(v) vx_info_mbcaps(v, current->cap_bset)
10363 +#define vx_current_cap_bset() vx_info_cap_bset(current_vx_info())
10366 +#define vx_info_mbcap(v, b) \
10367 + (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
10368 + vx_info_bcaps(v, b) : (b))
10370 +#define task_vx_mbcap(t, b) \
10371 + vx_info_mbcap((t)->vx_info, (t)->b)
10373 +#define vx_mbcap(b) task_vx_mbcap(current, b)
10376 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
10378 +#define vx_capable(b, c) (capable(b) || \
10379 + (cap_raised(current_cap(), b) && vx_ccaps(c)))
10381 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
10382 + (cap_raised(current_cap(), b) && vx_ccaps(c)))
10384 +#define nx_capable(b, c) (capable(b) || \
10385 + (cap_raised(current_cap(), b) && nx_ncaps(c)))
10387 +#define vx_task_initpid(t, n) \
10388 + ((t)->vx_info && \
10389 + ((t)->vx_info->vx_initpid == (n)))
10391 +#define vx_current_initpid(n) vx_task_initpid(current, n)
10394 +/* context unshare mask */
10396 +#define __vx_umask(v) ((v)->vx_umask)
10398 +#define vx_current_umask() __vx_umask(current_vx_info())
10400 +#define vx_can_unshare(b, f) (capable(b) || \
10401 + (cap_raised(current_cap(), b) && \
10402 + !((f) & ~vx_current_umask())))
10404 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
10405 + (cap_raised(current_cap(), b) && \
10406 + !((f) & ~vx_current_umask())))
10408 +#define __vx_wmask(v) ((v)->vx_wmask)
10410 +#define vx_current_wmask() __vx_wmask(current_vx_info())
10413 +#define __vx_state(v) ((v) ? ((v)->vx_state) : 0)
10415 +#define vx_info_state(v, m) (__vx_state(v) & (m))
10418 +#define __nx_state(n) ((n) ? ((n)->nx_state) : 0)
10420 +#define nx_info_state(n, m) (__nx_state(n) & (m))
10423 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct.h
10424 --- linux-3.9.4/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
10425 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct.h 2013-05-31 14:47:11.000000000 +0000
10427 +#ifndef _VSERVER_CACCT_H
10428 +#define _VSERVER_CACCT_H
10431 +enum sock_acc_field {
10432 + VXA_SOCK_UNSPEC = 0,
10438 + VXA_SOCK_SIZE /* array size */
10441 +#endif /* _VSERVER_CACCT_H */
10442 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_cmd.h
10443 --- linux-3.9.4/include/linux/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
10444 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_cmd.h 2013-05-31 14:47:11.000000000 +0000
10446 +#ifndef _VSERVER_CACCT_CMD_H
10447 +#define _VSERVER_CACCT_CMD_H
10450 +#include <linux/compiler.h>
10451 +#include <uapi/vserver/cacct_cmd.h>
10453 +extern int vc_sock_stat(struct vx_info *, void __user *);
10455 +#endif /* _VSERVER_CACCT_CMD_H */
10456 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_def.h
10457 --- linux-3.9.4/include/linux/vserver/cacct_def.h 1970-01-01 00:00:00.000000000 +0000
10458 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_def.h 2013-05-31 14:47:11.000000000 +0000
10460 +#ifndef _VSERVER_CACCT_DEF_H
10461 +#define _VSERVER_CACCT_DEF_H
10463 +#include <asm/atomic.h>
10464 +#include <linux/vserver/cacct.h>
10467 +struct _vx_sock_acc {
10468 + atomic_long_t count;
10469 + atomic_long_t total;
10472 +/* context sub struct */
10474 +struct _vx_cacct {
10475 + struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
10476 + atomic_t slab[8];
10477 + atomic_t page[6][8];
10480 +#ifdef CONFIG_VSERVER_DEBUG
10482 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
10486 + printk("\t_vx_cacct:");
10487 + for (i = 0; i < 6; i++) {
10488 + struct _vx_sock_acc *ptr = cacct->sock[i];
10490 + printk("\t [%d] =", i);
10491 + for (j = 0; j < 3; j++) {
10492 + printk(" [%d] = %8lu, %8lu", j,
10493 + atomic_long_read(&ptr[j].count),
10494 + atomic_long_read(&ptr[j].total));
10502 +#endif /* _VSERVER_CACCT_DEF_H */
10503 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cacct_int.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_int.h
10504 --- linux-3.9.4/include/linux/vserver/cacct_int.h 1970-01-01 00:00:00.000000000 +0000
10505 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cacct_int.h 2013-05-31 14:47:11.000000000 +0000
10507 +#ifndef _VSERVER_CACCT_INT_H
10508 +#define _VSERVER_CACCT_INT_H
10511 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
10513 + return atomic_long_read(&cacct->sock[type][pos].count);
10518 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
10520 + return atomic_long_read(&cacct->sock[type][pos].total);
10523 +#endif /* _VSERVER_CACCT_INT_H */
10524 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/check.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/check.h
10525 --- linux-3.9.4/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
10526 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/check.h 2013-05-31 14:47:11.000000000 +0000
10528 +#ifndef _VSERVER_CHECK_H
10529 +#define _VSERVER_CHECK_H
10532 +#define MAX_S_CONTEXT 65535 /* Arbitrary limit */
10534 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
10535 +#define MIN_D_CONTEXT 49152 /* dynamic contexts start here */
10537 +#define MIN_D_CONTEXT 65536
10540 +/* check conditions */
10542 +#define VS_ADMIN 0x0001
10543 +#define VS_WATCH 0x0002
10544 +#define VS_HIDE 0x0004
10545 +#define VS_HOSTID 0x0008
10547 +#define VS_IDENT 0x0010
10548 +#define VS_EQUIV 0x0020
10549 +#define VS_PARENT 0x0040
10550 +#define VS_CHILD 0x0080
10552 +#define VS_ARG_MASK 0x00F0
10554 +#define VS_DYNAMIC 0x0100
10555 +#define VS_STATIC 0x0200
10557 +#define VS_ATR_MASK 0x0F00
10559 +#ifdef CONFIG_VSERVER_PRIVACY
10560 +#define VS_ADMIN_P (0)
10561 +#define VS_WATCH_P (0)
10563 +#define VS_ADMIN_P VS_ADMIN
10564 +#define VS_WATCH_P VS_WATCH
10567 +#define VS_HARDIRQ 0x1000
10568 +#define VS_SOFTIRQ 0x2000
10569 +#define VS_IRQ 0x4000
10571 +#define VS_IRQ_MASK 0xF000
10573 +#include <linux/hardirq.h>
10576 + * check current context for ADMIN/WATCH and
10577 + * optionally against supplied argument
10579 +static inline int __vs_check(int cid, int id, unsigned int mode)
10581 + if (mode & VS_ARG_MASK) {
10582 + if ((mode & VS_IDENT) && (id == cid))
10585 + if (mode & VS_ATR_MASK) {
10586 + if ((mode & VS_DYNAMIC) &&
10587 + (id >= MIN_D_CONTEXT) &&
10588 + (id <= MAX_S_CONTEXT))
10590 + if ((mode & VS_STATIC) &&
10591 + (id > 1) && (id < MIN_D_CONTEXT))
10594 + if (mode & VS_IRQ_MASK) {
10595 + if ((mode & VS_IRQ) && unlikely(in_interrupt()))
10597 + if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
10599 + if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
10602 + return (((mode & VS_ADMIN) && (cid == 0)) ||
10603 + ((mode & VS_WATCH) && (cid == 1)) ||
10604 + ((mode & VS_HOSTID) && (id == 0)));
10607 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
10609 +#define vx_weak_check(c, m) ((m) ? vx_check(c, m) : 1)
10612 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
10614 +#define nx_weak_check(c, m) ((m) ? nx_check(c, m) : 1)
10617 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/context.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/context.h
10618 --- linux-3.9.4/include/linux/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
10619 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/context.h 2013-05-31 14:47:11.000000000 +0000
10621 +#ifndef _VSERVER_CONTEXT_H
10622 +#define _VSERVER_CONTEXT_H
10625 +#include <linux/list.h>
10626 +#include <linux/spinlock.h>
10627 +#include <linux/rcupdate.h>
10628 +#include <uapi/vserver/context.h>
10630 +#include "limit_def.h"
10631 +#include "sched_def.h"
10632 +#include "cvirt_def.h"
10633 +#include "cacct_def.h"
10634 +#include "device_def.h"
10636 +#define VX_SPACES 2
10638 +struct _vx_info_pc {
10639 + struct _vx_sched_pc sched_pc;
10640 + struct _vx_cvirt_pc cvirt_pc;
10643 +struct _vx_space {
10644 + unsigned long vx_nsmask; /* assignment mask */
10645 + struct nsproxy *vx_nsproxy; /* private namespaces */
10646 + struct fs_struct *vx_fs; /* private namespace fs */
10647 + const struct cred *vx_cred; /* task credentials */
10651 + struct hlist_node vx_hlist; /* linked list of contexts */
10652 + xid_t vx_id; /* context id */
10653 + atomic_t vx_usecnt; /* usage count */
10654 + atomic_t vx_tasks; /* tasks count */
10655 + struct vx_info *vx_parent; /* parent context */
10656 + int vx_state; /* context state */
10658 + struct _vx_space space[VX_SPACES]; /* namespace store */
10660 + uint64_t vx_flags; /* context flags */
10661 + uint64_t vx_ccaps; /* context caps (vserver) */
10662 + uint64_t vx_umask; /* unshare mask (guest) */
10663 + uint64_t vx_wmask; /* warn mask (guest) */
10664 + kernel_cap_t vx_bcaps; /* bounding caps (system) */
10666 + struct task_struct *vx_reaper; /* guest reaper process */
10667 + pid_t vx_initpid; /* PID of guest init */
10668 + int64_t vx_badness_bias; /* OOM points bias */
10670 + struct _vx_limit limit; /* vserver limits */
10671 + struct _vx_sched sched; /* vserver scheduler */
10672 + struct _vx_cvirt cvirt; /* virtual/bias stuff */
10673 + struct _vx_cacct cacct; /* context accounting */
10675 + struct _vx_device dmap; /* default device map targets */
10677 +#ifndef CONFIG_SMP
10678 + struct _vx_info_pc info_pc; /* per cpu data */
10680 + struct _vx_info_pc *ptr_pc; /* per cpu array */
10683 + wait_queue_head_t vx_wait; /* context exit waitqueue */
10684 + int reboot_cmd; /* last sys_reboot() cmd */
10685 + int exit_code; /* last process exit code */
10687 + char vx_name[65]; /* vserver name */
10690 +#ifndef CONFIG_SMP
10691 +#define vx_ptr_pc(vxi) (&(vxi)->info_pc)
10692 +#define vx_per_cpu(vxi, v, id) vx_ptr_pc(vxi)->v
10694 +#define vx_ptr_pc(vxi) ((vxi)->ptr_pc)
10695 +#define vx_per_cpu(vxi, v, id) per_cpu_ptr(vx_ptr_pc(vxi), id)->v
10698 +#define vx_cpu(vxi, v) vx_per_cpu(vxi, v, smp_processor_id())
10701 +struct vx_info_save {
10702 + struct vx_info *vxi;
10707 +/* status flags */
10709 +#define VXS_HASHED 0x0001
10710 +#define VXS_PAUSED 0x0010
10711 +#define VXS_SHUTDOWN 0x0100
10712 +#define VXS_HELPER 0x1000
10713 +#define VXS_RELEASED 0x8000
10716 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
10717 +extern void release_vx_info(struct vx_info *, struct task_struct *);
10719 +extern struct vx_info *lookup_vx_info(int);
10720 +extern struct vx_info *lookup_or_create_vx_info(int);
10722 +extern int get_xid_list(int, unsigned int *, int);
10723 +extern int xid_is_hashed(xid_t);
10725 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
10727 +extern long vs_state_change(struct vx_info *, unsigned int);
10730 +#endif /* _VSERVER_CONTEXT_H */
10731 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/context_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/context_cmd.h
10732 --- linux-3.9.4/include/linux/vserver/context_cmd.h 1970-01-01 00:00:00.000000000 +0000
10733 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/context_cmd.h 2013-05-31 14:47:11.000000000 +0000
10735 +#ifndef _VSERVER_CONTEXT_CMD_H
10736 +#define _VSERVER_CONTEXT_CMD_H
10738 +#include <uapi/vserver/context_cmd.h>
10740 +extern int vc_task_xid(uint32_t);
10742 +extern int vc_vx_info(struct vx_info *, void __user *);
10744 +extern int vc_ctx_stat(struct vx_info *, void __user *);
10746 +extern int vc_ctx_create(uint32_t, void __user *);
10747 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
10749 +extern int vc_get_cflags(struct vx_info *, void __user *);
10750 +extern int vc_set_cflags(struct vx_info *, void __user *);
10752 +extern int vc_get_ccaps(struct vx_info *, void __user *);
10753 +extern int vc_set_ccaps(struct vx_info *, void __user *);
10755 +extern int vc_get_bcaps(struct vx_info *, void __user *);
10756 +extern int vc_set_bcaps(struct vx_info *, void __user *);
10758 +extern int vc_get_umask(struct vx_info *, void __user *);
10759 +extern int vc_set_umask(struct vx_info *, void __user *);
10761 +extern int vc_get_wmask(struct vx_info *, void __user *);
10762 +extern int vc_set_wmask(struct vx_info *, void __user *);
10764 +extern int vc_get_badness(struct vx_info *, void __user *);
10765 +extern int vc_set_badness(struct vx_info *, void __user *);
10767 +#endif /* _VSERVER_CONTEXT_CMD_H */
10768 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt.h
10769 --- linux-3.9.4/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
10770 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt.h 2013-05-31 14:47:11.000000000 +0000
10772 +#ifndef _VSERVER_CVIRT_H
10773 +#define _VSERVER_CVIRT_H
10777 +void vx_vsi_boottime(struct timespec *);
10779 +void vx_vsi_uptime(struct timespec *, struct timespec *);
10784 +void vx_update_load(struct vx_info *);
10787 +int vx_do_syslog(int, char __user *, int);
10789 +#endif /* _VSERVER_CVIRT_H */
10790 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt_cmd.h
10791 --- linux-3.9.4/include/linux/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
10792 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt_cmd.h 2013-05-31 14:47:11.000000000 +0000
10794 +#ifndef _VSERVER_CVIRT_CMD_H
10795 +#define _VSERVER_CVIRT_CMD_H
10798 +#include <linux/compiler.h>
10799 +#include <uapi/vserver/cvirt_cmd.h>
10801 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
10802 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
10804 +extern int vc_virt_stat(struct vx_info *, void __user *);
10806 +#endif /* _VSERVER_CVIRT_CMD_H */
10807 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/cvirt_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt_def.h
10808 --- linux-3.9.4/include/linux/vserver/cvirt_def.h 1970-01-01 00:00:00.000000000 +0000
10809 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/cvirt_def.h 2013-05-31 14:47:11.000000000 +0000
10811 +#ifndef _VSERVER_CVIRT_DEF_H
10812 +#define _VSERVER_CVIRT_DEF_H
10814 +#include <linux/jiffies.h>
10815 +#include <linux/spinlock.h>
10816 +#include <linux/wait.h>
10817 +#include <linux/time.h>
10818 +#include <asm/atomic.h>
10821 +struct _vx_usage_stat {
10825 + uint64_t softirq;
10831 +struct _vx_syslog {
10832 + wait_queue_head_t log_wait;
10833 + spinlock_t logbuf_lock; /* lock for the log buffer */
10835 + unsigned long log_start; /* next char to be read by syslog() */
10836 + unsigned long con_start; /* next char to be sent to consoles */
10837 + unsigned long log_end; /* most-recently-written-char + 1 */
10838 + unsigned long logged_chars; /* #chars since last read+clear operation */
10840 + char log_buf[1024];
10844 +/* context sub struct */
10846 +struct _vx_cvirt {
10847 + atomic_t nr_threads; /* number of current threads */
10848 + atomic_t nr_running; /* number of running threads */
10849 + atomic_t nr_uninterruptible; /* number of uninterruptible threads */
10851 + atomic_t nr_onhold; /* processes on hold */
10852 + uint32_t onhold_last; /* jiffies when put on hold */
10854 + struct timespec bias_ts; /* time offset to the host */
10855 + struct timespec bias_idle;
10856 + struct timespec bias_uptime; /* context creation point */
10857 + uint64_t bias_clock; /* offset in clock_t */
10859 + spinlock_t load_lock; /* lock for the load averages */
10860 + atomic_t load_updates; /* nr of load updates done so far */
10861 + uint32_t load_last; /* last time load was calculated */
10862 + uint32_t load[3]; /* load averages 1,5,15 */
10864 + atomic_t total_forks; /* number of forks so far */
10866 + struct _vx_syslog syslog;
10869 +struct _vx_cvirt_pc {
10870 + struct _vx_usage_stat cpustat;
10874 +#ifdef CONFIG_VSERVER_DEBUG
10876 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10878 + printk("\t_vx_cvirt:\n");
10879 + printk("\t threads: %4d, %4d, %4d, %4d\n",
10880 + atomic_read(&cvirt->nr_threads),
10881 + atomic_read(&cvirt->nr_running),
10882 + atomic_read(&cvirt->nr_uninterruptible),
10883 + atomic_read(&cvirt->nr_onhold));
10884 + /* add rest here */
10885 + printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10890 +#endif /* _VSERVER_CVIRT_DEF_H */
10891 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/debug.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/debug.h
10892 --- linux-3.9.4/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
10893 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/debug.h 2013-05-31 14:47:11.000000000 +0000
10895 +#ifndef _VSERVER_DEBUG_H
10896 +#define _VSERVER_DEBUG_H
10899 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10900 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10901 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10903 +#define VXD_DEV(d) (d), (d)->bd_inode->i_ino, \
10904 + imajor((d)->bd_inode), iminor((d)->bd_inode)
10905 +#define VXF_DEV "%p[%lu,%d:%d]"
10907 +#if defined(CONFIG_QUOTES_UTF8)
10908 +#define VS_Q_LQM "\xc2\xbb"
10909 +#define VS_Q_RQM "\xc2\xab"
10910 +#elif defined(CONFIG_QUOTES_ASCII)
10911 +#define VS_Q_LQM "\x27"
10912 +#define VS_Q_RQM "\x27"
10914 +#define VS_Q_LQM "\xbb"
10915 +#define VS_Q_RQM "\xab"
10918 +#define VS_Q(f) VS_Q_LQM f VS_Q_RQM
10921 +#define vxd_path(p) \
10922 + ({ static char _buffer[PATH_MAX]; \
10923 + d_path(p, _buffer, sizeof(_buffer)); })
10925 +#define vxd_cond_path(n) \
10926 + ((n) ? vxd_path(&(n)->path) : "<null>" )
10929 +#ifdef CONFIG_VSERVER_DEBUG
10931 +extern unsigned int vs_debug_switch;
10932 +extern unsigned int vs_debug_xid;
10933 +extern unsigned int vs_debug_nid;
10934 +extern unsigned int vs_debug_tag;
10935 +extern unsigned int vs_debug_net;
10936 +extern unsigned int vs_debug_limit;
10937 +extern unsigned int vs_debug_cres;
10938 +extern unsigned int vs_debug_dlim;
10939 +extern unsigned int vs_debug_quota;
10940 +extern unsigned int vs_debug_cvirt;
10941 +extern unsigned int vs_debug_space;
10942 +extern unsigned int vs_debug_perm;
10943 +extern unsigned int vs_debug_misc;
10946 +#define VX_LOGLEVEL "vxD: "
10947 +#define VX_PROC_FMT "%p: "
10948 +#define VX_PROCESS current
10950 +#define vxdprintk(c, f, x...) \
10953 + printk(VX_LOGLEVEL VX_PROC_FMT f "\n", \
10954 + VX_PROCESS , ##x); \
10957 +#define vxlprintk(c, f, x...) \
10960 + printk(VX_LOGLEVEL f " @%s:%d\n", x); \
10963 +#define vxfprintk(c, f, x...) \
10966 + printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10972 +void dump_vx_info(struct vx_info *, int);
10973 +void dump_vx_info_inactive(int);
10975 +#else /* CONFIG_VSERVER_DEBUG */
10977 +#define vs_debug_switch 0
10978 +#define vs_debug_xid 0
10979 +#define vs_debug_nid 0
10980 +#define vs_debug_tag 0
10981 +#define vs_debug_net 0
10982 +#define vs_debug_limit 0
10983 +#define vs_debug_cres 0
10984 +#define vs_debug_dlim 0
10985 +#define vs_debug_quota 0
10986 +#define vs_debug_cvirt 0
10987 +#define vs_debug_space 0
10988 +#define vs_debug_perm 0
10989 +#define vs_debug_misc 0
10991 +#define vxdprintk(x...) do { } while (0)
10992 +#define vxlprintk(x...) do { } while (0)
10993 +#define vxfprintk(x...) do { } while (0)
10995 +#endif /* CONFIG_VSERVER_DEBUG */
10998 +#ifdef CONFIG_VSERVER_WARN
11000 +#define VX_WARNLEVEL KERN_WARNING "vxW: "
11001 +#define VX_WARN_TASK "[" VS_Q("%s") ",%u:#%u|%u|%u] "
11002 +#define VX_WARN_XID "[xid #%u] "
11003 +#define VX_WARN_NID "[nid #%u] "
11004 +#define VX_WARN_TAG "[tag #%u] "
11006 +#define vxwprintk(c, f, x...) \
11009 + printk(VX_WARNLEVEL f "\n", ##x); \
11012 +#else /* CONFIG_VSERVER_WARN */
11014 +#define vxwprintk(x...) do { } while (0)
11016 +#endif /* CONFIG_VSERVER_WARN */
11018 +#define vxwprintk_task(c, f, x...) \
11019 + vxwprintk(c, VX_WARN_TASK f, \
11020 + current->comm, current->pid, \
11021 + current->xid, current->nid, current->tag, ##x)
11022 +#define vxwprintk_xid(c, f, x...) \
11023 + vxwprintk(c, VX_WARN_XID f, current->xid, x)
11024 +#define vxwprintk_nid(c, f, x...) \
11025 + vxwprintk(c, VX_WARN_NID f, current->nid, x)
11026 +#define vxwprintk_tag(c, f, x...) \
11027 + vxwprintk(c, VX_WARN_TAG f, current->tag, x)
11029 +#ifdef CONFIG_VSERVER_DEBUG
11030 +#define vxd_assert_lock(l) assert_spin_locked(l)
11031 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
11032 + "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
11034 +#define vxd_assert_lock(l) do { } while (0)
11035 +#define vxd_assert(c, f, x...) do { } while (0)
11039 +#endif /* _VSERVER_DEBUG_H */
11040 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/debug_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/debug_cmd.h
11041 --- linux-3.9.4/include/linux/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
11042 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/debug_cmd.h 2013-05-31 14:47:11.000000000 +0000
11044 +#ifndef _VSERVER_DEBUG_CMD_H
11045 +#define _VSERVER_DEBUG_CMD_H
11047 +#include <uapi/vserver/debug_cmd.h>
11050 +#ifdef CONFIG_COMPAT
11052 +#include <asm/compat.h>
11054 +struct vcmd_read_history_v0_x32 {
11057 + compat_uptr_t data_ptr;
11060 +struct vcmd_read_monitor_v0_x32 {
11063 + compat_uptr_t data_ptr;
11066 +#endif /* CONFIG_COMPAT */
11068 +extern int vc_dump_history(uint32_t);
11070 +extern int vc_read_history(uint32_t, void __user *);
11071 +extern int vc_read_monitor(uint32_t, void __user *);
11073 +#ifdef CONFIG_COMPAT
11075 +extern int vc_read_history_x32(uint32_t, void __user *);
11076 +extern int vc_read_monitor_x32(uint32_t, void __user *);
11078 +#endif /* CONFIG_COMPAT */
11080 +#endif /* _VSERVER_DEBUG_CMD_H */
11081 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/device.h
11082 --- linux-3.9.4/include/linux/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
11083 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/device.h 2013-05-31 14:47:11.000000000 +0000
11085 +#ifndef _VSERVER_DEVICE_H
11086 +#define _VSERVER_DEVICE_H
11089 +#include <uapi/vserver/device.h>
11091 +#else /* _VSERVER_DEVICE_H */
11092 +#warning duplicate inclusion
11093 +#endif /* _VSERVER_DEVICE_H */
11094 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/device_cmd.h
11095 --- linux-3.9.4/include/linux/vserver/device_cmd.h 1970-01-01 00:00:00.000000000 +0000
11096 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/device_cmd.h 2013-05-31 14:47:11.000000000 +0000
11098 +#ifndef _VSERVER_DEVICE_CMD_H
11099 +#define _VSERVER_DEVICE_CMD_H
11101 +#include <uapi/vserver/device_cmd.h>
11104 +#ifdef CONFIG_COMPAT
11106 +#include <asm/compat.h>
11108 +struct vcmd_set_mapping_v0_x32 {
11109 + compat_uptr_t device_ptr;
11110 + compat_uptr_t target_ptr;
11114 +#endif /* CONFIG_COMPAT */
11116 +#include <linux/compiler.h>
11118 +extern int vc_set_mapping(struct vx_info *, void __user *);
11119 +extern int vc_unset_mapping(struct vx_info *, void __user *);
11121 +#ifdef CONFIG_COMPAT
11123 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
11124 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
11126 +#endif /* CONFIG_COMPAT */
11128 +#endif /* _VSERVER_DEVICE_CMD_H */
11129 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/device_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/device_def.h
11130 --- linux-3.9.4/include/linux/vserver/device_def.h 1970-01-01 00:00:00.000000000 +0000
11131 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/device_def.h 2013-05-31 14:47:11.000000000 +0000
11133 +#ifndef _VSERVER_DEVICE_DEF_H
11134 +#define _VSERVER_DEVICE_DEF_H
11136 +#include <linux/types.h>
11138 +struct vx_dmap_target {
11143 +struct _vx_device {
11144 +#ifdef CONFIG_VSERVER_DEVICE
11145 + struct vx_dmap_target targets[2];
11149 +#endif /* _VSERVER_DEVICE_DEF_H */
11150 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/dlimit.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/dlimit.h
11151 --- linux-3.9.4/include/linux/vserver/dlimit.h 1970-01-01 00:00:00.000000000 +0000
11152 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/dlimit.h 2013-05-31 14:47:11.000000000 +0000
11154 +#ifndef _VSERVER_DLIMIT_H
11155 +#define _VSERVER_DLIMIT_H
11157 +#include "switch.h"
11162 +/* keep in sync with CDLIM_INFINITY */
11164 +#define DLIM_INFINITY (~0ULL)
11166 +#include <linux/spinlock.h>
11167 +#include <linux/rcupdate.h>
11169 +struct super_block;
11172 + struct hlist_node dl_hlist; /* linked list of contexts */
11173 + struct rcu_head dl_rcu; /* the rcu head */
11174 + tag_t dl_tag; /* context tag */
11175 + atomic_t dl_usecnt; /* usage count */
11176 + atomic_t dl_refcnt; /* reference count */
11178 + struct super_block *dl_sb; /* associated superblock */
11180 + spinlock_t dl_lock; /* protect the values */
11182 + unsigned long long dl_space_used; /* used space in bytes */
11183 + unsigned long long dl_space_total; /* maximum space in bytes */
11184 + unsigned long dl_inodes_used; /* used inodes */
11185 + unsigned long dl_inodes_total; /* maximum inodes */
11187 + unsigned int dl_nrlmult; /* non root limit mult */
11192 +extern void rcu_free_dl_info(struct rcu_head *);
11193 +extern void unhash_dl_info(struct dl_info *);
11195 +extern struct dl_info *locate_dl_info(struct super_block *, tag_t);
11200 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
11202 +typedef uint64_t dlsize_t;
11204 +#endif /* __KERNEL__ */
11205 +#else /* _VSERVER_DLIMIT_H */
11206 +#warning duplicate inclusion
11207 +#endif /* _VSERVER_DLIMIT_H */
11208 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/dlimit_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/dlimit_cmd.h
11209 --- linux-3.9.4/include/linux/vserver/dlimit_cmd.h 1970-01-01 00:00:00.000000000 +0000
11210 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/dlimit_cmd.h 2013-05-31 14:47:11.000000000 +0000
11212 +#ifndef _VSERVER_DLIMIT_CMD_H
11213 +#define _VSERVER_DLIMIT_CMD_H
11215 +#include <uapi/vserver/dlimit_cmd.h>
11218 +#ifdef CONFIG_COMPAT
11220 +#include <asm/compat.h>
11222 +struct vcmd_ctx_dlimit_base_v0_x32 {
11223 + compat_uptr_t name_ptr;
11227 +struct vcmd_ctx_dlimit_v0_x32 {
11228 + compat_uptr_t name_ptr;
11229 + uint32_t space_used; /* used space in kbytes */
11230 + uint32_t space_total; /* maximum space in kbytes */
11231 + uint32_t inodes_used; /* used inodes */
11232 + uint32_t inodes_total; /* maximum inodes */
11233 + uint32_t reserved; /* reserved for root in % */
11237 +#endif /* CONFIG_COMPAT */
11239 +#include <linux/compiler.h>
11241 +extern int vc_add_dlimit(uint32_t, void __user *);
11242 +extern int vc_rem_dlimit(uint32_t, void __user *);
11244 +extern int vc_set_dlimit(uint32_t, void __user *);
11245 +extern int vc_get_dlimit(uint32_t, void __user *);
11247 +#ifdef CONFIG_COMPAT
11249 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
11250 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
11252 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
11253 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
11255 +#endif /* CONFIG_COMPAT */
11257 +#endif /* _VSERVER_DLIMIT_CMD_H */
11258 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/global.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/global.h
11259 --- linux-3.9.4/include/linux/vserver/global.h 1970-01-01 00:00:00.000000000 +0000
11260 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/global.h 2013-05-31 14:47:11.000000000 +0000
11262 +#ifndef _VSERVER_GLOBAL_H
11263 +#define _VSERVER_GLOBAL_H
11266 +extern atomic_t vx_global_ctotal;
11267 +extern atomic_t vx_global_cactive;
11269 +extern atomic_t nx_global_ctotal;
11270 +extern atomic_t nx_global_cactive;
11272 +extern atomic_t vs_global_nsproxy;
11273 +extern atomic_t vs_global_fs;
11274 +extern atomic_t vs_global_mnt_ns;
11275 +extern atomic_t vs_global_uts_ns;
11276 +extern atomic_t vs_global_user_ns;
11277 +extern atomic_t vs_global_pid_ns;
11280 +#endif /* _VSERVER_GLOBAL_H */
11281 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/history.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/history.h
11282 --- linux-3.9.4/include/linux/vserver/history.h 1970-01-01 00:00:00.000000000 +0000
11283 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/history.h 2013-05-31 14:47:11.000000000 +0000
11285 +#ifndef _VSERVER_HISTORY_H
11286 +#define _VSERVER_HISTORY_H
11291 + VXH_THROW_OOPS = 1,
11295 + VXH_INIT_VX_INFO,
11298 + VXH_CLAIM_VX_INFO,
11299 + VXH_RELEASE_VX_INFO,
11300 + VXH_ALLOC_VX_INFO,
11301 + VXH_DEALLOC_VX_INFO,
11302 + VXH_HASH_VX_INFO,
11303 + VXH_UNHASH_VX_INFO,
11305 + VXH_LOOKUP_VX_INFO,
11306 + VXH_CREATE_VX_INFO,
11309 +struct _vxhe_vxi {
11310 + struct vx_info *ptr;
11316 +struct _vxhe_set_clr {
11320 +struct _vxhe_loc_lookup {
11324 +struct _vx_hist_entry {
11326 + unsigned short seq;
11327 + unsigned short type;
11328 + struct _vxhe_vxi vxi;
11330 + struct _vxhe_set_clr sc;
11331 + struct _vxhe_loc_lookup ll;
11335 +#ifdef CONFIG_VSERVER_HISTORY
11337 +extern unsigned volatile int vxh_active;
11339 +struct _vx_hist_entry *vxh_advance(void *loc);
11343 +void __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
11345 + entry->vxi.ptr = vxi;
11347 + entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
11348 + entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
11349 + entry->vxi.xid = vxi->vx_id;
11354 +#define __HERE__ current_text_addr()
11356 +#define __VXH_BODY(__type, __data, __here) \
11357 + struct _vx_hist_entry *entry; \
11359 + preempt_disable(); \
11360 + entry = vxh_advance(__here); \
11362 + entry->type = __type; \
11363 + preempt_enable();
11366 + /* pass vxi only */
11368 +#define __VXH_SMPL \
11369 + __vxh_copy_vxi(entry, vxi)
11372 +void __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
11374 + __VXH_BODY(__type, __VXH_SMPL, __here)
11377 + /* pass vxi and data (void *) */
11379 +#define __VXH_DATA \
11380 + __vxh_copy_vxi(entry, vxi); \
11381 + entry->sc.data = data
11384 +void __vxh_data(struct vx_info *vxi, void *data,
11385 + int __type, void *__here)
11387 + __VXH_BODY(__type, __VXH_DATA, __here)
11390 + /* pass vxi and arg (long) */
11392 +#define __VXH_LONG \
11393 + __vxh_copy_vxi(entry, vxi); \
11394 + entry->ll.arg = arg
11397 +void __vxh_long(struct vx_info *vxi, long arg,
11398 + int __type, void *__here)
11400 + __VXH_BODY(__type, __VXH_LONG, __here)
11405 +void __vxh_throw_oops(void *__here)
11407 + __VXH_BODY(VXH_THROW_OOPS, {}, __here);
11408 + /* prevent further acquisition */
11413 +#define vxh_throw_oops() __vxh_throw_oops(__HERE__);
11415 +#define __vxh_get_vx_info(v, h) __vxh_smpl(v, VXH_GET_VX_INFO, h);
11416 +#define __vxh_put_vx_info(v, h) __vxh_smpl(v, VXH_PUT_VX_INFO, h);
11418 +#define __vxh_init_vx_info(v, d, h) \
11419 + __vxh_data(v, d, VXH_INIT_VX_INFO, h);
11420 +#define __vxh_set_vx_info(v, d, h) \
11421 + __vxh_data(v, d, VXH_SET_VX_INFO, h);
11422 +#define __vxh_clr_vx_info(v, d, h) \
11423 + __vxh_data(v, d, VXH_CLR_VX_INFO, h);
11425 +#define __vxh_claim_vx_info(v, d, h) \
11426 + __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
11427 +#define __vxh_release_vx_info(v, d, h) \
11428 + __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
11430 +#define vxh_alloc_vx_info(v) \
11431 + __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
11432 +#define vxh_dealloc_vx_info(v) \
11433 + __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
11435 +#define vxh_hash_vx_info(v) \
11436 + __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
11437 +#define vxh_unhash_vx_info(v) \
11438 + __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
11440 +#define vxh_loc_vx_info(v, l) \
11441 + __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
11442 +#define vxh_lookup_vx_info(v, l) \
11443 + __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
11444 +#define vxh_create_vx_info(v, l) \
11445 + __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
11447 +extern void vxh_dump_history(void);
11450 +#else /* CONFIG_VSERVER_HISTORY */
11452 +#define __HERE__ 0
11454 +#define vxh_throw_oops() do { } while (0)
11456 +#define __vxh_get_vx_info(v, h) do { } while (0)
11457 +#define __vxh_put_vx_info(v, h) do { } while (0)
11459 +#define __vxh_init_vx_info(v, d, h) do { } while (0)
11460 +#define __vxh_set_vx_info(v, d, h) do { } while (0)
11461 +#define __vxh_clr_vx_info(v, d, h) do { } while (0)
11463 +#define __vxh_claim_vx_info(v, d, h) do { } while (0)
11464 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
11466 +#define vxh_alloc_vx_info(v) do { } while (0)
11467 +#define vxh_dealloc_vx_info(v) do { } while (0)
11469 +#define vxh_hash_vx_info(v) do { } while (0)
11470 +#define vxh_unhash_vx_info(v) do { } while (0)
11472 +#define vxh_loc_vx_info(v, l) do { } while (0)
11473 +#define vxh_lookup_vx_info(v, l) do { } while (0)
11474 +#define vxh_create_vx_info(v, l) do { } while (0)
11476 +#define vxh_dump_history() do { } while (0)
11479 +#endif /* CONFIG_VSERVER_HISTORY */
11481 +#endif /* _VSERVER_HISTORY_H */
11482 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/inode.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/inode.h
11483 --- linux-3.9.4/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
11484 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/inode.h 2013-05-31 14:47:11.000000000 +0000
11486 +#ifndef _VSERVER_INODE_H
11487 +#define _VSERVER_INODE_H
11489 +#include <uapi/vserver/inode.h>
11492 +#ifdef CONFIG_VSERVER_PROC_SECURE
11493 +#define IATTR_PROC_DEFAULT ( IATTR_ADMIN | IATTR_HIDE )
11494 +#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
11496 +#define IATTR_PROC_DEFAULT ( IATTR_ADMIN )
11497 +#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
11500 +#define vx_hide_check(c, m) (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
11502 +#else /* _VSERVER_INODE_H */
11503 +#warning duplicate inclusion
11504 +#endif /* _VSERVER_INODE_H */
11505 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/inode_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/inode_cmd.h
11506 --- linux-3.9.4/include/linux/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
11507 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/inode_cmd.h 2013-05-31 14:47:11.000000000 +0000
11509 +#ifndef _VSERVER_INODE_CMD_H
11510 +#define _VSERVER_INODE_CMD_H
11512 +#include <uapi/vserver/inode_cmd.h>
11516 +#ifdef CONFIG_COMPAT
11518 +#include <asm/compat.h>
11520 +struct vcmd_ctx_iattr_v1_x32 {
11521 + compat_uptr_t name_ptr;
11527 +#endif /* CONFIG_COMPAT */
11529 +#include <linux/compiler.h>
11531 +extern int vc_get_iattr(void __user *);
11532 +extern int vc_set_iattr(void __user *);
11534 +extern int vc_fget_iattr(uint32_t, void __user *);
11535 +extern int vc_fset_iattr(uint32_t, void __user *);
11537 +#ifdef CONFIG_COMPAT
11539 +extern int vc_get_iattr_x32(void __user *);
11540 +extern int vc_set_iattr_x32(void __user *);
11542 +#endif /* CONFIG_COMPAT */
11544 +#endif /* _VSERVER_INODE_CMD_H */
11545 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit.h
11546 --- linux-3.9.4/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
11547 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit.h 2013-05-31 14:47:11.000000000 +0000
11549 +#ifndef _VSERVER_LIMIT_H
11550 +#define _VSERVER_LIMIT_H
11552 +#include <uapi/vserver/limit.h>
11555 +#define VLIM_NOCHECK ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
11557 +/* keep in sync with CRLIM_INFINITY */
11559 +#define VLIM_INFINITY (~0ULL)
11561 +#include <asm/atomic.h>
11562 +#include <asm/resource.h>
11564 +#ifndef RLIM_INFINITY
11565 +#warning RLIM_INFINITY is undefined
11568 +#define __rlim_val(l, r, v) ((l)->res[r].v)
11570 +#define __rlim_soft(l, r) __rlim_val(l, r, soft)
11571 +#define __rlim_hard(l, r) __rlim_val(l, r, hard)
11573 +#define __rlim_rcur(l, r) __rlim_val(l, r, rcur)
11574 +#define __rlim_rmin(l, r) __rlim_val(l, r, rmin)
11575 +#define __rlim_rmax(l, r) __rlim_val(l, r, rmax)
11577 +#define __rlim_lhit(l, r) __rlim_val(l, r, lhit)
11578 +#define __rlim_hit(l, r) atomic_inc(&__rlim_lhit(l, r))
11580 +typedef atomic_long_t rlim_atomic_t;
11581 +typedef unsigned long rlim_t;
11583 +#define __rlim_get(l, r) atomic_long_read(&__rlim_rcur(l, r))
11584 +#define __rlim_set(l, r, v) atomic_long_set(&__rlim_rcur(l, r), v)
11585 +#define __rlim_inc(l, r) atomic_long_inc(&__rlim_rcur(l, r))
11586 +#define __rlim_dec(l, r) atomic_long_dec(&__rlim_rcur(l, r))
11587 +#define __rlim_add(l, r, v) atomic_long_add(v, &__rlim_rcur(l, r))
11588 +#define __rlim_sub(l, r, v) atomic_long_sub(v, &__rlim_rcur(l, r))
11591 +#if (RLIM_INFINITY == VLIM_INFINITY)
11592 +#define VX_VLIM(r) ((long long)(long)(r))
11593 +#define VX_RLIM(v) ((rlim_t)(v))
11595 +#define VX_VLIM(r) (((r) == RLIM_INFINITY) \
11596 + ? VLIM_INFINITY : (long long)(r))
11597 +#define VX_RLIM(v) (((v) == VLIM_INFINITY) \
11598 + ? RLIM_INFINITY : (rlim_t)(v))
11603 +void vx_vsi_meminfo(struct sysinfo *);
11604 +void vx_vsi_swapinfo(struct sysinfo *);
11605 +long vx_vsi_cached(struct sysinfo *);
11607 +#define NUM_LIMITS 24
11609 +#endif /* _VSERVER_LIMIT_H */
11610 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_cmd.h
11611 --- linux-3.9.4/include/linux/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
11612 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_cmd.h 2013-05-31 14:47:11.000000000 +0000
11614 +#ifndef _VSERVER_LIMIT_CMD_H
11615 +#define _VSERVER_LIMIT_CMD_H
11617 +#include <uapi/vserver/limit_cmd.h>
11620 +#ifdef CONFIG_IA32_EMULATION
11622 +struct vcmd_ctx_rlimit_v0_x32 {
11624 + uint64_t minimum;
11625 + uint64_t softlimit;
11626 + uint64_t maximum;
11627 +} __attribute__ ((packed));
11629 +#endif /* CONFIG_IA32_EMULATION */
11631 +#include <linux/compiler.h>
11633 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
11634 +extern int vc_get_rlimit(struct vx_info *, void __user *);
11635 +extern int vc_set_rlimit(struct vx_info *, void __user *);
11636 +extern int vc_reset_hits(struct vx_info *, void __user *);
11637 +extern int vc_reset_minmax(struct vx_info *, void __user *);
11639 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
11641 +#ifdef CONFIG_IA32_EMULATION
11643 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
11644 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
11646 +#endif /* CONFIG_IA32_EMULATION */
11648 +#endif /* _VSERVER_LIMIT_CMD_H */
11649 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_def.h
11650 --- linux-3.9.4/include/linux/vserver/limit_def.h 1970-01-01 00:00:00.000000000 +0000
11651 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_def.h 2013-05-31 14:47:11.000000000 +0000
11653 +#ifndef _VSERVER_LIMIT_DEF_H
11654 +#define _VSERVER_LIMIT_DEF_H
11656 +#include <asm/atomic.h>
11657 +#include <asm/resource.h>
11659 +#include "limit.h"
11662 +struct _vx_res_limit {
11663 + rlim_t soft; /* Context soft limit */
11664 + rlim_t hard; /* Context hard limit */
11666 + rlim_atomic_t rcur; /* Current value */
11667 + rlim_t rmin; /* Context minimum */
11668 + rlim_t rmax; /* Context maximum */
11670 + atomic_t lhit; /* Limit hits */
11673 +/* context sub struct */
11675 +struct _vx_limit {
11676 + struct _vx_res_limit res[NUM_LIMITS];
11679 +#ifdef CONFIG_VSERVER_DEBUG
11681 +static inline void __dump_vx_limit(struct _vx_limit *limit)
11685 + printk("\t_vx_limit:");
11686 + for (i = 0; i < NUM_LIMITS; i++) {
11687 + printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
11688 + i, (unsigned long)__rlim_get(limit, i),
11689 + (unsigned long)__rlim_rmin(limit, i),
11690 + (unsigned long)__rlim_rmax(limit, i),
11691 + (long)__rlim_soft(limit, i),
11692 + (long)__rlim_hard(limit, i),
11693 + atomic_read(&__rlim_lhit(limit, i)));
11699 +#endif /* _VSERVER_LIMIT_DEF_H */
11700 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/limit_int.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_int.h
11701 --- linux-3.9.4/include/linux/vserver/limit_int.h 1970-01-01 00:00:00.000000000 +0000
11702 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/limit_int.h 2013-05-31 14:47:11.000000000 +0000
11704 +#ifndef _VSERVER_LIMIT_INT_H
11705 +#define _VSERVER_LIMIT_INT_H
11707 +#define VXD_RCRES_COND(r) VXD_CBIT(cres, r)
11708 +#define VXD_RLIMIT_COND(r) VXD_CBIT(limit, r)
11710 +extern const char *vlimit_name[NUM_LIMITS];
11712 +static inline void __vx_acc_cres(struct vx_info *vxi,
11713 + int res, int dir, void *_data, char *_file, int _line)
11715 + if (VXD_RCRES_COND(res))
11716 + vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
11717 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11718 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11719 + (dir > 0) ? "++" : "--", _data, _file, _line);
11724 + __rlim_inc(&vxi->limit, res);
11726 + __rlim_dec(&vxi->limit, res);
11729 +static inline void __vx_add_cres(struct vx_info *vxi,
11730 + int res, int amount, void *_data, char *_file, int _line)
11732 + if (VXD_RCRES_COND(res))
11733 + vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
11734 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11735 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11736 + amount, _data, _file, _line);
11741 + __rlim_add(&vxi->limit, res, amount);
11745 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
11747 + int cond = (value > __rlim_rmax(limit, res));
11750 + __rlim_rmax(limit, res) = value;
11755 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
11757 + int cond = (value < __rlim_rmin(limit, res));
11760 + __rlim_rmin(limit, res) = value;
11765 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
11767 + if (!__vx_cres_adjust_max(limit, res, value))
11768 + __vx_cres_adjust_min(limit, res, value);
11773 + +1 ... no limit hit
11774 + -1 ... over soft limit
11775 + 0 ... over hard limit */
11777 +static inline int __vx_cres_avail(struct vx_info *vxi,
11778 + int res, int num, char *_file, int _line)
11780 + struct _vx_limit *limit;
11783 + if (VXD_RLIMIT_COND(res))
11784 + vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
11785 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
11786 + (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
11787 + (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
11788 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
11789 + num, _file, _line);
11793 + limit = &vxi->limit;
11794 + value = __rlim_get(limit, res);
11796 + if (!__vx_cres_adjust_max(limit, res, value))
11797 + __vx_cres_adjust_min(limit, res, value);
11802 + if (__rlim_soft(limit, res) == RLIM_INFINITY)
11804 + if (value + num <= __rlim_soft(limit, res))
11807 + if (__rlim_hard(limit, res) == RLIM_INFINITY)
11809 + if (value + num <= __rlim_hard(limit, res))
11812 + __rlim_hit(limit, res);
11817 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11820 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11822 + rlim_t value, sum = 0;
11825 + while ((res = *array++)) {
11826 + value = __rlim_get(limit, res);
11827 + __vx_cres_fixup(limit, res, value);
11834 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11836 + rlim_t value = __vx_cres_array_sum(limit, array + 1);
11837 + int res = *array;
11839 + if (value == __rlim_get(limit, res))
11842 + __rlim_set(limit, res, value);
11843 + /* now adjust min/max */
11844 + if (!__vx_cres_adjust_max(limit, res, value))
11845 + __vx_cres_adjust_min(limit, res, value);
11850 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11851 + const int *array, int num, char *_file, int _line)
11853 + struct _vx_limit *limit;
11854 + rlim_t value = 0;
11862 + limit = &vxi->limit;
11864 + value = __vx_cres_array_sum(limit, array + 1);
11866 + __rlim_set(limit, res, value);
11867 + __vx_cres_fixup(limit, res, value);
11869 + return __vx_cres_avail(vxi, res, num, _file, _line);
11873 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11878 + /* complex resources first */
11879 + if ((id < 0) || (id == RLIMIT_RSS))
11880 + __vx_cres_array_fixup(limit, VLA_RSS);
11882 + for (res = 0; res < NUM_LIMITS; res++) {
11883 + if ((id > 0) && (res != id))
11886 + value = __rlim_get(limit, res);
11887 + __vx_cres_fixup(limit, res, value);
11889 + /* not supposed to happen, maybe warn? */
11890 + if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11891 + __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11896 +#endif /* _VSERVER_LIMIT_INT_H */
11897 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/monitor.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/monitor.h
11898 --- linux-3.9.4/include/linux/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
11899 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/monitor.h 2013-05-31 14:47:11.000000000 +0000
11901 +#ifndef _VSERVER_MONITOR_H
11902 +#define _VSERVER_MONITOR_H
11904 +#include <uapi/vserver/monitor.h>
11906 +#endif /* _VSERVER_MONITOR_H */
11907 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/network.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/network.h
11908 --- linux-3.9.4/include/linux/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
11909 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/network.h 2013-05-31 14:47:11.000000000 +0000
11911 +#ifndef _VSERVER_NETWORK_H
11912 +#define _VSERVER_NETWORK_H
11915 +#include <linux/list.h>
11916 +#include <linux/spinlock.h>
11917 +#include <linux/rcupdate.h>
11918 +#include <linux/in.h>
11919 +#include <linux/in6.h>
11920 +#include <asm/atomic.h>
11921 +#include <uapi/vserver/network.h>
11923 +struct nx_addr_v4 {
11924 + struct nx_addr_v4 *next;
11925 + struct in_addr ip[2];
11926 + struct in_addr mask;
11931 +struct nx_addr_v6 {
11932 + struct nx_addr_v6 *next;
11933 + struct in6_addr ip;
11934 + struct in6_addr mask;
11941 + struct hlist_node nx_hlist; /* linked list of nxinfos */
11942 + nid_t nx_id; /* vnet id */
11943 + atomic_t nx_usecnt; /* usage count */
11944 + atomic_t nx_tasks; /* tasks count */
11945 + int nx_state; /* context state */
11947 + uint64_t nx_flags; /* network flag word */
11948 + uint64_t nx_ncaps; /* network capabilities */
11950 + spinlock_t addr_lock; /* protect address changes */
11951 + struct in_addr v4_lback; /* Loopback address */
11952 + struct in_addr v4_bcast; /* Broadcast address */
11953 + struct nx_addr_v4 v4; /* First/Single ipv4 address */
11954 +#ifdef CONFIG_IPV6
11955 + struct nx_addr_v6 v6; /* First/Single ipv6 address */
11957 + char nx_name[65]; /* network context name */
11961 +/* status flags */
11963 +#define NXS_HASHED 0x0001
11964 +#define NXS_SHUTDOWN 0x0100
11965 +#define NXS_RELEASED 0x8000
11967 +extern struct nx_info *lookup_nx_info(int);
11969 +extern int get_nid_list(int, unsigned int *, int);
11970 +extern int nid_is_hashed(nid_t);
11972 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11974 +extern long vs_net_change(struct nx_info *, unsigned int);
11979 +#define NX_IPV4(n) ((n)->v4.type != NXA_TYPE_NONE)
11980 +#ifdef CONFIG_IPV6
11981 +#define NX_IPV6(n) ((n)->v6.type != NXA_TYPE_NONE)
11983 +#define NX_IPV6(n) (0)
11986 +#endif /* _VSERVER_NETWORK_H */
11987 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/network_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/network_cmd.h
11988 --- linux-3.9.4/include/linux/vserver/network_cmd.h 1970-01-01 00:00:00.000000000 +0000
11989 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/network_cmd.h 2013-05-31 14:47:11.000000000 +0000
11991 +#ifndef _VSERVER_NETWORK_CMD_H
11992 +#define _VSERVER_NETWORK_CMD_H
11994 +#include <uapi/vserver/network_cmd.h>
11996 +extern int vc_task_nid(uint32_t);
11998 +extern int vc_nx_info(struct nx_info *, void __user *);
12000 +extern int vc_net_create(uint32_t, void __user *);
12001 +extern int vc_net_migrate(struct nx_info *, void __user *);
12003 +extern int vc_net_add(struct nx_info *, void __user *);
12004 +extern int vc_net_remove(struct nx_info *, void __user *);
12006 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
12007 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
12009 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
12010 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
12012 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
12013 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
12015 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
12016 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
12018 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
12019 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
12021 +extern int vc_get_nflags(struct nx_info *, void __user *);
12022 +extern int vc_set_nflags(struct nx_info *, void __user *);
12024 +extern int vc_get_ncaps(struct nx_info *, void __user *);
12025 +extern int vc_set_ncaps(struct nx_info *, void __user *);
12027 +#endif /* _VSERVER_CONTEXT_CMD_H */
12028 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/percpu.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/percpu.h
12029 --- linux-3.9.4/include/linux/vserver/percpu.h 1970-01-01 00:00:00.000000000 +0000
12030 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/percpu.h 2013-05-31 14:47:11.000000000 +0000
12032 +#ifndef _VSERVER_PERCPU_H
12033 +#define _VSERVER_PERCPU_H
12035 +#include "cvirt_def.h"
12036 +#include "sched_def.h"
12038 +struct _vx_percpu {
12039 + struct _vx_cvirt_pc cvirt;
12040 + struct _vx_sched_pc sched;
12043 +#define PERCPU_PERCTX (sizeof(struct _vx_percpu))
12045 +#endif /* _VSERVER_PERCPU_H */
12046 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/pid.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/pid.h
12047 --- linux-3.9.4/include/linux/vserver/pid.h 1970-01-01 00:00:00.000000000 +0000
12048 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/pid.h 2013-05-31 14:47:11.000000000 +0000
12050 +#ifndef _VSERVER_PID_H
12051 +#define _VSERVER_PID_H
12053 +/* pid faking stuff */
12055 +#define vx_info_map_pid(v, p) \
12056 + __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
12057 +#define vx_info_map_tgid(v,p) vx_info_map_pid(v,p)
12058 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
12059 +#define vx_map_tgid(p) vx_map_pid(p)
12061 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
12062 + const char *func, const char *file, int line)
12064 + if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12065 + vxfprintk(VXD_CBIT(cvirt, 2),
12066 + "vx_map_tgid: %p/%llx: %d -> %d",
12067 + vxi, (long long)vxi->vx_flags, pid,
12068 + (pid && pid == vxi->vx_initpid) ? 1 : pid,
12069 + func, file, line);
12072 + if (pid == vxi->vx_initpid)
12078 +#define vx_info_rmap_pid(v, p) \
12079 + __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
12080 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
12081 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
12083 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
12084 + const char *func, const char *file, int line)
12086 + if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
12087 + vxfprintk(VXD_CBIT(cvirt, 2),
12088 + "vx_rmap_tgid: %p/%llx: %d -> %d",
12089 + vxi, (long long)vxi->vx_flags, pid,
12090 + (pid == 1) ? vxi->vx_initpid : pid,
12091 + func, file, line);
12092 + if ((pid == 1) && vxi->vx_initpid)
12093 + return vxi->vx_initpid;
12094 + if (pid == vxi->vx_initpid)
12101 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched.h
12102 --- linux-3.9.4/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
12103 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched.h 2013-05-31 14:47:11.000000000 +0000
12105 +#ifndef _VSERVER_SCHED_H
12106 +#define _VSERVER_SCHED_H
12113 +void vx_vsi_uptime(struct timespec *, struct timespec *);
12118 +void vx_update_load(struct vx_info *);
12121 +void vx_update_sched_param(struct _vx_sched *sched,
12122 + struct _vx_sched_pc *sched_pc);
12124 +#endif /* __KERNEL__ */
12125 +#else /* _VSERVER_SCHED_H */
12126 +#warning duplicate inclusion
12127 +#endif /* _VSERVER_SCHED_H */
12128 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched_cmd.h
12129 --- linux-3.9.4/include/linux/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
12130 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched_cmd.h 2013-05-31 14:47:11.000000000 +0000
12132 +#ifndef _VSERVER_SCHED_CMD_H
12133 +#define _VSERVER_SCHED_CMD_H
12136 +#include <linux/compiler.h>
12137 +#include <uapi/vserver/sched_cmd.h>
12139 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
12140 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
12142 +#endif /* _VSERVER_SCHED_CMD_H */
12143 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/sched_def.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched_def.h
12144 --- linux-3.9.4/include/linux/vserver/sched_def.h 1970-01-01 00:00:00.000000000 +0000
12145 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/sched_def.h 2013-05-31 14:47:11.000000000 +0000
12147 +#ifndef _VSERVER_SCHED_DEF_H
12148 +#define _VSERVER_SCHED_DEF_H
12150 +#include <linux/spinlock.h>
12151 +#include <linux/jiffies.h>
12152 +#include <linux/cpumask.h>
12153 +#include <asm/atomic.h>
12154 +#include <asm/param.h>
12157 +/* context sub struct */
12159 +struct _vx_sched {
12160 + int prio_bias; /* bias offset for priority */
12162 + cpumask_t update; /* CPUs which should update */
12165 +struct _vx_sched_pc {
12166 + int prio_bias; /* bias offset for priority */
12168 + uint64_t user_ticks; /* token tick events */
12169 + uint64_t sys_ticks; /* token tick events */
12170 + uint64_t hold_ticks; /* token ticks paused */
12174 +#ifdef CONFIG_VSERVER_DEBUG
12176 +static inline void __dump_vx_sched(struct _vx_sched *sched)
12178 + printk("\t_vx_sched:\n");
12179 + printk("\t priority = %4d\n", sched->prio_bias);
12184 +#endif /* _VSERVER_SCHED_DEF_H */
12185 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/signal.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/signal.h
12186 --- linux-3.9.4/include/linux/vserver/signal.h 1970-01-01 00:00:00.000000000 +0000
12187 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/signal.h 2013-05-31 14:47:11.000000000 +0000
12189 +#ifndef _VSERVER_SIGNAL_H
12190 +#define _VSERVER_SIGNAL_H
12197 +int vx_info_kill(struct vx_info *, int, int);
12199 +#endif /* __KERNEL__ */
12200 +#else /* _VSERVER_SIGNAL_H */
12201 +#warning duplicate inclusion
12202 +#endif /* _VSERVER_SIGNAL_H */
12203 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/signal_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/signal_cmd.h
12204 --- linux-3.9.4/include/linux/vserver/signal_cmd.h 1970-01-01 00:00:00.000000000 +0000
12205 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/signal_cmd.h 2013-05-31 14:47:11.000000000 +0000
12207 +#ifndef _VSERVER_SIGNAL_CMD_H
12208 +#define _VSERVER_SIGNAL_CMD_H
12210 +#include <uapi/vserver/signal_cmd.h>
12213 +extern int vc_ctx_kill(struct vx_info *, void __user *);
12214 +extern int vc_wait_exit(struct vx_info *, void __user *);
12217 +extern int vc_get_pflags(uint32_t pid, void __user *);
12218 +extern int vc_set_pflags(uint32_t pid, void __user *);
12220 +#endif /* _VSERVER_SIGNAL_CMD_H */
12221 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/space.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/space.h
12222 --- linux-3.9.4/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
12223 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/space.h 2013-05-31 14:47:11.000000000 +0000
12225 +#ifndef _VSERVER_SPACE_H
12226 +#define _VSERVER_SPACE_H
12228 +#include <linux/types.h>
12232 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
12234 +#else /* _VSERVER_SPACE_H */
12235 +#warning duplicate inclusion
12236 +#endif /* _VSERVER_SPACE_H */
12237 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/space_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/space_cmd.h
12238 --- linux-3.9.4/include/linux/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
12239 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/space_cmd.h 2013-05-31 14:47:11.000000000 +0000
12241 +#ifndef _VSERVER_SPACE_CMD_H
12242 +#define _VSERVER_SPACE_CMD_H
12244 +#include <uapi/vserver/space_cmd.h>
12247 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
12248 +extern int vc_set_space_v1(struct vx_info *, void __user *);
12249 +extern int vc_enter_space(struct vx_info *, void __user *);
12250 +extern int vc_set_space(struct vx_info *, void __user *);
12251 +extern int vc_get_space_mask(void __user *, int);
12253 +#endif /* _VSERVER_SPACE_CMD_H */
12254 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/switch.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/switch.h
12255 --- linux-3.9.4/include/linux/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12256 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/switch.h 2013-05-31 14:47:11.000000000 +0000
12258 +#ifndef _VSERVER_SWITCH_H
12259 +#define _VSERVER_SWITCH_H
12262 +#include <linux/errno.h>
12263 +#include <uapi/vserver/switch.h>
12265 +#endif /* _VSERVER_SWITCH_H */
12266 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/tag.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/tag.h
12267 --- linux-3.9.4/include/linux/vserver/tag.h 1970-01-01 00:00:00.000000000 +0000
12268 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/tag.h 2013-06-01 08:36:17.000000000 +0000
12273 +#include <linux/types.h>
12276 +#define DX_TAG(in) (IS_TAGGED(in))
12279 +#ifdef CONFIG_TAG_NFSD
12280 +#define DX_TAG_NFSD 1
12282 +#define DX_TAG_NFSD 0
12286 +#ifdef CONFIG_TAGGING_NONE
12288 +#define MAX_UID 0xFFFFFFFF
12289 +#define MAX_GID 0xFFFFFFFF
12291 +#define INOTAG_TAG(cond, uid, gid, tag) (0)
12293 +#define TAGINO_UID(cond, uid, tag) (uid)
12294 +#define TAGINO_GID(cond, gid, tag) (gid)
12299 +#ifdef CONFIG_TAGGING_GID16
12301 +#define MAX_UID 0xFFFFFFFF
12302 +#define MAX_GID 0x0000FFFF
12304 +#define INOTAG_TAG(cond, uid, gid, tag) \
12305 + ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
12307 +#define TAGINO_UID(cond, uid, tag) (uid)
12308 +#define TAGINO_GID(cond, gid, tag) \
12309 + ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
12314 +#ifdef CONFIG_TAGGING_ID24
12316 +#define MAX_UID 0x00FFFFFF
12317 +#define MAX_GID 0x00FFFFFF
12319 +#define INOTAG_TAG(cond, uid, gid, tag) \
12320 + ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
12322 +#define TAGINO_UID(cond, uid, tag) \
12323 + ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
12324 +#define TAGINO_GID(cond, gid, tag) \
12325 + ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
12330 +#ifdef CONFIG_TAGGING_UID16
12332 +#define MAX_UID 0x0000FFFF
12333 +#define MAX_GID 0xFFFFFFFF
12335 +#define INOTAG_TAG(cond, uid, gid, tag) \
12336 + ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
12338 +#define TAGINO_UID(cond, uid, tag) \
12339 + ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
12340 +#define TAGINO_GID(cond, gid, tag) (gid)
12345 +#ifdef CONFIG_TAGGING_INTERN
12347 +#define MAX_UID 0xFFFFFFFF
12348 +#define MAX_GID 0xFFFFFFFF
12350 +#define INOTAG_TAG(cond, uid, gid, tag) \
12351 + ((cond) ? (tag) : 0)
12353 +#define TAGINO_UID(cond, uid, tag) (uid)
12354 +#define TAGINO_GID(cond, gid, tag) (gid)
12359 +#ifndef CONFIG_TAGGING_NONE
12360 +#define dx_current_fstag(sb) \
12361 + ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
12363 +#define dx_current_fstag(sb) (0)
12366 +#ifndef CONFIG_TAGGING_INTERN
12367 +#define TAGINO_TAG(cond, tag) (0)
12369 +#define TAGINO_TAG(cond, tag) ((cond) ? (tag) : 0)
12372 +#define INOTAG_UID(cond, uid, gid) \
12373 + ((cond) ? ((uid) & MAX_UID) : (uid))
12374 +#define INOTAG_GID(cond, uid, gid) \
12375 + ((cond) ? ((gid) & MAX_GID) : (gid))
12378 +static inline uid_t dx_map_uid(uid_t uid)
12380 + if ((uid > MAX_UID) && (uid != -1))
12382 + return (uid & MAX_UID);
12385 +#define dx_map_kuid(n, u) \
12386 + make_kuid(n, dx_map_uid(from_kuid(n, u)))
12388 +static inline gid_t dx_map_gid(gid_t gid)
12390 + if ((gid > MAX_GID) && (gid != -1))
12392 + return (gid & MAX_GID);
12395 +#define dx_map_kgid(n, u) \
12396 + make_kgid(n, dx_map_gid(from_kgid(n, u)))
12403 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
12405 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
12406 + unsigned long *flags);
12408 +#ifdef CONFIG_PROPAGATE
12410 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
12412 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
12415 +#define dx_propagate_tag(n, i) do { } while (0)
12418 +#endif /* _DX_TAG_H */
12419 diff -NurpP --minimal linux-3.9.4/include/linux/vserver/tag_cmd.h linux-3.9.4-vs2.3.6.2/include/linux/vserver/tag_cmd.h
12420 --- linux-3.9.4/include/linux/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
12421 +++ linux-3.9.4-vs2.3.6.2/include/linux/vserver/tag_cmd.h 2013-05-31 14:47:11.000000000 +0000
12423 +#ifndef _VSERVER_TAG_CMD_H
12424 +#define _VSERVER_TAG_CMD_H
12426 +#include <uapi/vserver/tag_cmd.h>
12428 +extern int vc_task_tag(uint32_t);
12430 +extern int vc_tag_migrate(uint32_t);
12432 +#endif /* _VSERVER_TAG_CMD_H */
12433 diff -NurpP --minimal linux-3.9.4/include/net/addrconf.h linux-3.9.4-vs2.3.6.2/include/net/addrconf.h
12434 --- linux-3.9.4/include/net/addrconf.h 2013-05-31 13:45:28.000000000 +0000
12435 +++ linux-3.9.4-vs2.3.6.2/include/net/addrconf.h 2013-05-31 17:17:53.000000000 +0000
12436 @@ -85,7 +85,8 @@ extern int ipv6_dev_get_saddr(struct n
12437 const struct net_device *dev,
12438 const struct in6_addr *daddr,
12439 unsigned int srcprefs,
12440 - struct in6_addr *saddr);
12441 + struct in6_addr *saddr,
12442 + struct nx_info *nxi);
12443 extern int ipv6_get_lladdr(struct net_device *dev,
12444 struct in6_addr *addr,
12445 unsigned char banned_flags);
12446 diff -NurpP --minimal linux-3.9.4/include/net/af_unix.h linux-3.9.4-vs2.3.6.2/include/net/af_unix.h
12447 --- linux-3.9.4/include/net/af_unix.h 2013-02-19 13:58:52.000000000 +0000
12448 +++ linux-3.9.4-vs2.3.6.2/include/net/af_unix.h 2013-05-31 17:17:53.000000000 +0000
12450 #include <linux/socket.h>
12451 #include <linux/un.h>
12452 #include <linux/mutex.h>
12453 +#include <linux/vs_base.h>
12454 #include <net/sock.h>
12456 extern void unix_inflight(struct file *fp);
12457 diff -NurpP --minimal linux-3.9.4/include/net/inet_timewait_sock.h linux-3.9.4-vs2.3.6.2/include/net/inet_timewait_sock.h
12458 --- linux-3.9.4/include/net/inet_timewait_sock.h 2013-05-31 13:45:28.000000000 +0000
12459 +++ linux-3.9.4-vs2.3.6.2/include/net/inet_timewait_sock.h 2013-05-31 17:18:34.000000000 +0000
12460 @@ -116,6 +116,10 @@ struct inet_timewait_sock {
12461 #define tw_dport __tw_common.skc_dport
12462 #define tw_num __tw_common.skc_num
12463 #define tw_portpair __tw_common.skc_portpair
12464 +#define tw_xid __tw_common.skc_xid
12465 +#define tw_vx_info __tw_common.skc_vx_info
12466 +#define tw_nid __tw_common.skc_nid
12467 +#define tw_nx_info __tw_common.skc_nx_info
12470 volatile unsigned char tw_substate;
12471 diff -NurpP --minimal linux-3.9.4/include/net/ip6_route.h linux-3.9.4-vs2.3.6.2/include/net/ip6_route.h
12472 --- linux-3.9.4/include/net/ip6_route.h 2013-05-31 13:45:28.000000000 +0000
12473 +++ linux-3.9.4-vs2.3.6.2/include/net/ip6_route.h 2013-05-31 17:17:53.000000000 +0000
12474 @@ -95,7 +95,8 @@ extern int ip6_route_get_saddr(struct
12475 struct rt6_info *rt,
12476 const struct in6_addr *daddr,
12477 unsigned int prefs,
12478 - struct in6_addr *saddr);
12479 + struct in6_addr *saddr,
12480 + struct nx_info *nxi);
12482 extern struct rt6_info *rt6_lookup(struct net *net,
12483 const struct in6_addr *daddr,
12484 diff -NurpP --minimal linux-3.9.4/include/net/route.h linux-3.9.4-vs2.3.6.2/include/net/route.h
12485 --- linux-3.9.4/include/net/route.h 2013-02-19 13:58:52.000000000 +0000
12486 +++ linux-3.9.4-vs2.3.6.2/include/net/route.h 2013-05-31 17:17:53.000000000 +0000
12487 @@ -207,6 +207,9 @@ static inline void ip_rt_put(struct rtab
12488 dst_release(&rt->dst);
12491 +#include <linux/vs_base.h>
12492 +#include <linux/vs_inet.h>
12494 #define IPTOS_RT_MASK (IPTOS_TOS_MASK & ~3)
12496 extern const __u8 ip_tos2prio[16];
12497 @@ -256,6 +259,9 @@ static inline void ip_route_connect_init
12498 protocol, flow_flags, dst, src, dport, sport);
12501 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
12502 + struct flowi4 *);
12504 static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
12505 __be32 dst, __be32 src, u32 tos,
12506 int oif, u8 protocol,
12507 @@ -264,11 +270,25 @@ static inline struct rtable *ip_route_co
12509 struct net *net = sock_net(sk);
12511 + struct nx_info *nx_info = current_nx_info();
12513 ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
12514 sport, dport, sk, can_sleep);
12516 - if (!dst || !src) {
12518 + nx_info = sk->sk_nx_info;
12520 + vxdprintk(VXD_CBIT(net, 4),
12521 + "ip_route_connect(%p) %p,%p;%lx",
12522 + sk, nx_info, sk->sk_socket,
12523 + (sk->sk_socket?sk->sk_socket->flags:0));
12525 + rt = ip_v4_find_src(net, nx_info, fl4);
12530 + if (!fl4->daddr || !fl4->saddr) {
12531 rt = __ip_route_output_key(net, fl4);
12534 diff -NurpP --minimal linux-3.9.4/include/net/sock.h linux-3.9.4-vs2.3.6.2/include/net/sock.h
12535 --- linux-3.9.4/include/net/sock.h 2013-05-31 14:22:27.000000000 +0000
12536 +++ linux-3.9.4-vs2.3.6.2/include/net/sock.h 2013-05-31 17:17:53.000000000 +0000
12537 @@ -191,6 +191,10 @@ struct sock_common {
12538 #ifdef CONFIG_NET_NS
12539 struct net *skc_net;
12542 + struct vx_info *skc_vx_info;
12544 + struct nx_info *skc_nx_info;
12546 * fields between dontcopy_begin/dontcopy_end
12547 * are not copied in sock_copy()
12548 @@ -304,6 +308,10 @@ struct sock {
12549 #define sk_bind_node __sk_common.skc_bind_node
12550 #define sk_prot __sk_common.skc_prot
12551 #define sk_net __sk_common.skc_net
12552 +#define sk_xid __sk_common.skc_xid
12553 +#define sk_vx_info __sk_common.skc_vx_info
12554 +#define sk_nid __sk_common.skc_nid
12555 +#define sk_nx_info __sk_common.skc_nx_info
12556 socket_lock_t sk_lock;
12557 struct sk_buff_head sk_receive_queue;
12559 diff -NurpP --minimal linux-3.9.4/include/uapi/Kbuild linux-3.9.4-vs2.3.6.2/include/uapi/Kbuild
12560 --- linux-3.9.4/include/uapi/Kbuild 2012-12-11 03:30:57.000000000 +0000
12561 +++ linux-3.9.4-vs2.3.6.2/include/uapi/Kbuild 2013-05-31 14:47:11.000000000 +0000
12562 @@ -12,3 +12,4 @@ header-y += video/
12566 +header-y += vserver/
12567 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/capability.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/capability.h
12568 --- linux-3.9.4/include/uapi/linux/capability.h 2012-12-11 03:30:57.000000000 +0000
12569 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/capability.h 2013-05-31 14:47:11.000000000 +0000
12570 @@ -259,6 +259,7 @@ struct vfs_cap_data {
12571 arbitrary SCSI commands */
12572 /* Allow setting encryption key on loopback filesystem */
12573 /* Allow setting zone reclaim policy */
12574 +/* Allow the selection of a security context */
12576 #define CAP_SYS_ADMIN 21
12578 @@ -345,7 +346,12 @@ struct vfs_cap_data {
12580 #define CAP_LAST_CAP CAP_BLOCK_SUSPEND
12582 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
12583 +/* Allow context manipulations */
12584 +/* Allow changing context info on files */
12586 +#define CAP_CONTEXT 63
12588 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
12591 * Bit location of each capability (used by user-space library and kernel)
12592 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/fs.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/fs.h
12593 --- linux-3.9.4/include/uapi/linux/fs.h 2013-05-31 13:45:29.000000000 +0000
12594 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/fs.h 2013-05-31 23:07:43.000000000 +0000
12595 @@ -86,6 +86,9 @@ struct inodes_stat_t {
12596 #define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */
12597 #define MS_I_VERSION (1<<23) /* Update inode I_version field */
12598 #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
12599 +#define MS_TAGGED (1<<8) /* use generic inode tagging */
12600 +#define MS_NOTAGCHECK (1<<9) /* don't check tags */
12601 +#define MS_TAGID (1<<25) /* use specific tag for this mount */
12603 /* These sb flags are internal to the kernel */
12604 #define MS_SNAP_STABLE (1<<27) /* Snapshot pages during writeback, if needed */
12605 @@ -192,11 +195,14 @@ struct inodes_stat_t {
12606 #define FS_EXTENT_FL 0x00080000 /* Extents */
12607 #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */
12608 #define FS_NOCOW_FL 0x00800000 /* Do not cow file */
12609 +#define FS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
12610 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
12612 -#define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
12613 -#define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
12614 +#define FS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
12615 +#define FS_COW_FL 0x20000000 /* Copy on Write marker */
12617 +#define FS_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
12618 +#define FS_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
12620 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
12621 #define SYNC_FILE_RANGE_WRITE 2
12622 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/gfs2_ondisk.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/gfs2_ondisk.h
12623 --- linux-3.9.4/include/uapi/linux/gfs2_ondisk.h 2012-12-11 03:30:57.000000000 +0000
12624 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/gfs2_ondisk.h 2013-05-31 14:47:11.000000000 +0000
12625 @@ -225,6 +225,9 @@ enum {
12628 gfs2fl_TopLevel = 10,
12629 + gfs2fl_IXUnlink = 16,
12630 + gfs2fl_Barrier = 17,
12632 gfs2fl_TruncInProg = 29,
12633 gfs2fl_InheritDirectio = 30,
12634 gfs2fl_InheritJdata = 31,
12635 @@ -242,6 +245,9 @@ enum {
12636 #define GFS2_DIF_SYNC 0x00000100
12637 #define GFS2_DIF_SYSTEM 0x00000200 /* New in gfs2 */
12638 #define GFS2_DIF_TOPDIR 0x00000400 /* New in gfs2 */
12639 +#define GFS2_DIF_IXUNLINK 0x00010000
12640 +#define GFS2_DIF_BARRIER 0x00020000
12641 +#define GFS2_DIF_COW 0x00040000
12642 #define GFS2_DIF_TRUNC_IN_PROG 0x20000000 /* New in gfs2 */
12643 #define GFS2_DIF_INHERIT_DIRECTIO 0x40000000 /* only in gfs1 */
12644 #define GFS2_DIF_INHERIT_JDATA 0x80000000
12645 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/if_tun.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/if_tun.h
12646 --- linux-3.9.4/include/uapi/linux/if_tun.h 2013-02-19 13:58:55.000000000 +0000
12647 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/if_tun.h 2013-05-31 15:00:16.000000000 +0000
12649 #define TUNGETVNETHDRSZ _IOR('T', 215, int)
12650 #define TUNSETVNETHDRSZ _IOW('T', 216, int)
12651 #define TUNSETQUEUE _IOW('T', 217, int)
12652 +#define TUNSETNID _IOW('T', 218, int)
12654 /* TUNSETIFF ifr flags */
12655 #define IFF_TUN 0x0001
12656 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/major.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/major.h
12657 --- linux-3.9.4/include/uapi/linux/major.h 2012-12-11 03:30:57.000000000 +0000
12658 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/major.h 2013-05-31 14:47:11.000000000 +0000
12660 #define HD_MAJOR IDE0_MAJOR
12661 #define PTY_SLAVE_MAJOR 3
12662 #define TTY_MAJOR 4
12663 +#define VROOT_MAJOR 4
12664 #define TTYAUX_MAJOR 5
12666 #define VCS_MAJOR 7
12667 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/nfs_mount.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/nfs_mount.h
12668 --- linux-3.9.4/include/uapi/linux/nfs_mount.h 2012-12-11 03:30:57.000000000 +0000
12669 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/nfs_mount.h 2013-05-31 14:47:11.000000000 +0000
12670 @@ -63,7 +63,8 @@ struct nfs_mount_data {
12671 #define NFS_MOUNT_SECFLAVOUR 0x2000 /* 5 */
12672 #define NFS_MOUNT_NORDIRPLUS 0x4000 /* 5 */
12673 #define NFS_MOUNT_UNSHARED 0x8000 /* 5 */
12674 -#define NFS_MOUNT_FLAGMASK 0xFFFF
12675 +#define NFS_MOUNT_TAGGED 0x10000 /* context tagging */
12676 +#define NFS_MOUNT_FLAGMASK 0x1FFFF
12678 /* The following are for internal use only */
12679 #define NFS_MOUNT_LOOKUP_CACHE_NONEG 0x10000
12680 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/reboot.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/reboot.h
12681 --- linux-3.9.4/include/uapi/linux/reboot.h 2012-12-11 03:30:57.000000000 +0000
12682 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/reboot.h 2013-05-31 14:47:11.000000000 +0000
12684 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
12685 #define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
12686 #define LINUX_REBOOT_CMD_KEXEC 0x45584543
12688 +#define LINUX_REBOOT_CMD_OOM 0xDEADBEEF
12691 #endif /* _UAPI_LINUX_REBOOT_H */
12692 diff -NurpP --minimal linux-3.9.4/include/uapi/linux/sysctl.h linux-3.9.4-vs2.3.6.2/include/uapi/linux/sysctl.h
12693 --- linux-3.9.4/include/uapi/linux/sysctl.h 2012-12-11 03:30:57.000000000 +0000
12694 +++ linux-3.9.4-vs2.3.6.2/include/uapi/linux/sysctl.h 2013-05-31 14:47:11.000000000 +0000
12695 @@ -60,6 +60,7 @@ enum
12696 CTL_ABI=9, /* Binary emulation */
12697 CTL_CPU=10, /* CPU stuff (speed scaling, etc) */
12698 CTL_ARLAN=254, /* arlan wireless driver */
12699 + CTL_VSERVER=4242, /* Linux-VServer debug */
12700 CTL_S390DBF=5677, /* s390 debug */
12701 CTL_SUNRPC=7249, /* sunrpc debug */
12702 CTL_PM=9899, /* frv power management */
12703 @@ -94,6 +95,7 @@ enum
12705 KERN_PANIC=15, /* int: panic timeout */
12706 KERN_REALROOTDEV=16, /* real root device to mount after initrd */
12707 + KERN_VSHELPER=17, /* string: path to vshelper policy agent */
12709 KERN_SPARC_REBOOT=21, /* reboot command on Sparc */
12710 KERN_CTLALTDEL=22, /* int: allow ctl-alt-del to reboot */
12711 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/Kbuild linux-3.9.4-vs2.3.6.2/include/uapi/vserver/Kbuild
12712 --- linux-3.9.4/include/uapi/vserver/Kbuild 1970-01-01 00:00:00.000000000 +0000
12713 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/Kbuild 2013-05-31 14:47:11.000000000 +0000
12716 +header-y += context_cmd.h network_cmd.h space_cmd.h \
12717 + cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
12718 + inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
12719 + debug_cmd.h device_cmd.h
12721 +header-y += switch.h context.h network.h monitor.h \
12722 + limit.h inode.h device.h
12724 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/cacct_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/cacct_cmd.h
12725 --- linux-3.9.4/include/uapi/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
12726 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/cacct_cmd.h 2013-05-31 14:47:11.000000000 +0000
12728 +#ifndef _UAPI_VS_CACCT_CMD_H
12729 +#define _UAPI_VS_CACCT_CMD_H
12732 +/* virtual host info name commands */
12734 +#define VCMD_sock_stat VC_CMD(VSTAT, 5, 0)
12736 +struct vcmd_sock_stat_v0 {
12738 + uint32_t count[3];
12739 + uint64_t total[3];
12742 +#endif /* _UAPI_VS_CACCT_CMD_H */
12743 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/context.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/context.h
12744 --- linux-3.9.4/include/uapi/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
12745 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/context.h 2013-05-31 19:44:13.000000000 +0000
12747 +#ifndef _UAPI_VS_CONTEXT_H
12748 +#define _UAPI_VS_CONTEXT_H
12750 +#include <linux/types.h>
12751 +#include <linux/capability.h>
12754 +/* context flags */
12756 +#define VXF_INFO_SCHED 0x00000002
12757 +#define VXF_INFO_NPROC 0x00000004
12758 +#define VXF_INFO_PRIVATE 0x00000008
12760 +#define VXF_INFO_INIT 0x00000010
12761 +#define VXF_INFO_HIDE 0x00000020
12762 +#define VXF_INFO_ULIMIT 0x00000040
12763 +#define VXF_INFO_NSPACE 0x00000080
12765 +#define VXF_SCHED_HARD 0x00000100
12766 +#define VXF_SCHED_PRIO 0x00000200
12767 +#define VXF_SCHED_PAUSE 0x00000400
12769 +#define VXF_VIRT_MEM 0x00010000
12770 +#define VXF_VIRT_UPTIME 0x00020000
12771 +#define VXF_VIRT_CPU 0x00040000
12772 +#define VXF_VIRT_LOAD 0x00080000
12773 +#define VXF_VIRT_TIME 0x00100000
12775 +#define VXF_HIDE_MOUNT 0x01000000
12776 +/* was VXF_HIDE_NETIF 0x02000000 */
12777 +#define VXF_HIDE_VINFO 0x04000000
12779 +#define VXF_STATE_SETUP (1ULL << 32)
12780 +#define VXF_STATE_INIT (1ULL << 33)
12781 +#define VXF_STATE_ADMIN (1ULL << 34)
12783 +#define VXF_SC_HELPER (1ULL << 36)
12784 +#define VXF_REBOOT_KILL (1ULL << 37)
12785 +#define VXF_PERSISTENT (1ULL << 38)
12787 +#define VXF_FORK_RSS (1ULL << 48)
12788 +#define VXF_PROLIFIC (1ULL << 49)
12790 +#define VXF_IGNEG_NICE (1ULL << 52)
12792 +#define VXF_ONE_TIME (0x0007ULL << 32)
12794 +#define VXF_INIT_SET (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
12797 +/* context migration */
12799 +#define VXM_SET_INIT 0x00000001
12800 +#define VXM_SET_REAPER 0x00000002
12802 +/* context caps */
12804 +#define VXC_SET_UTSNAME 0x00000001
12805 +#define VXC_SET_RLIMIT 0x00000002
12806 +#define VXC_FS_SECURITY 0x00000004
12807 +#define VXC_FS_TRUSTED 0x00000008
12808 +#define VXC_TIOCSTI 0x00000010
12810 +/* was VXC_RAW_ICMP 0x00000100 */
12811 +#define VXC_SYSLOG 0x00001000
12812 +#define VXC_OOM_ADJUST 0x00002000
12813 +#define VXC_AUDIT_CONTROL 0x00004000
12815 +/* #define VXC_SECURE_MOUNT 0x00010000
12816 +#define VXC_SECURE_REMOUNT 0x00020000 */
12817 +#define VXC_BINARY_MOUNT 0x00040000
12818 +#define VXC_DEV_MOUNT 0x00080000
12820 +#define VXC_QUOTA_CTL 0x00100000
12821 +#define VXC_ADMIN_MAPPER 0x00200000
12822 +#define VXC_ADMIN_CLOOP 0x00400000
12824 +#define VXC_KTHREAD 0x01000000
12825 +#define VXC_NAMESPACE 0x02000000
12827 +#endif /* _UAPI_VS_CONTEXT_H */
12828 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/context_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/context_cmd.h
12829 --- linux-3.9.4/include/uapi/vserver/context_cmd.h 1970-01-01 00:00:00.000000000 +0000
12830 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/context_cmd.h 2013-05-31 14:47:11.000000000 +0000
12832 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12833 +#define _UAPI_VS_CONTEXT_CMD_H
12836 +/* vinfo commands */
12838 +#define VCMD_task_xid VC_CMD(VINFO, 1, 0)
12841 +#define VCMD_vx_info VC_CMD(VINFO, 5, 0)
12843 +struct vcmd_vx_info_v0 {
12845 + uint32_t initpid;
12846 + /* more to come */
12850 +#define VCMD_ctx_stat VC_CMD(VSTAT, 0, 0)
12852 +struct vcmd_ctx_stat_v0 {
12855 + /* more to come */
12859 +/* context commands */
12861 +#define VCMD_ctx_create_v0 VC_CMD(VPROC, 1, 0)
12862 +#define VCMD_ctx_create VC_CMD(VPROC, 1, 1)
12864 +struct vcmd_ctx_create {
12865 + uint64_t flagword;
12868 +#define VCMD_ctx_migrate_v0 VC_CMD(PROCMIG, 1, 0)
12869 +#define VCMD_ctx_migrate VC_CMD(PROCMIG, 1, 1)
12871 +struct vcmd_ctx_migrate {
12872 + uint64_t flagword;
12877 +/* flag commands */
12879 +#define VCMD_get_cflags VC_CMD(FLAGS, 1, 0)
12880 +#define VCMD_set_cflags VC_CMD(FLAGS, 2, 0)
12882 +struct vcmd_ctx_flags_v0 {
12883 + uint64_t flagword;
12889 +/* context caps commands */
12891 +#define VCMD_get_ccaps VC_CMD(FLAGS, 3, 1)
12892 +#define VCMD_set_ccaps VC_CMD(FLAGS, 4, 1)
12894 +struct vcmd_ctx_caps_v1 {
12901 +/* bcaps commands */
12903 +#define VCMD_get_bcaps VC_CMD(FLAGS, 9, 0)
12904 +#define VCMD_set_bcaps VC_CMD(FLAGS, 10, 0)
12906 +struct vcmd_bcaps {
12913 +/* umask commands */
12915 +#define VCMD_get_umask VC_CMD(FLAGS, 13, 0)
12916 +#define VCMD_set_umask VC_CMD(FLAGS, 14, 0)
12918 +struct vcmd_umask {
12925 +/* wmask commands */
12927 +#define VCMD_get_wmask VC_CMD(FLAGS, 15, 0)
12928 +#define VCMD_set_wmask VC_CMD(FLAGS, 16, 0)
12930 +struct vcmd_wmask {
12939 +#define VCMD_get_badness VC_CMD(MEMCTRL, 5, 0)
12940 +#define VCMD_set_badness VC_CMD(MEMCTRL, 6, 0)
12942 +struct vcmd_badness_v0 {
12946 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12947 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/cvirt_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/cvirt_cmd.h
12948 --- linux-3.9.4/include/uapi/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
12949 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/cvirt_cmd.h 2013-05-31 14:47:11.000000000 +0000
12951 +#ifndef _UAPI_VS_CVIRT_CMD_H
12952 +#define _UAPI_VS_CVIRT_CMD_H
12955 +/* virtual host info name commands */
12957 +#define VCMD_set_vhi_name VC_CMD(VHOST, 1, 0)
12958 +#define VCMD_get_vhi_name VC_CMD(VHOST, 2, 0)
12960 +struct vcmd_vhi_name_v0 {
12966 +enum vhi_name_field {
12967 + VHIN_CONTEXT = 0,
12978 +#define VCMD_virt_stat VC_CMD(VSTAT, 3, 0)
12980 +struct vcmd_virt_stat_v0 {
12983 + uint32_t nr_threads;
12984 + uint32_t nr_running;
12985 + uint32_t nr_uninterruptible;
12986 + uint32_t nr_onhold;
12987 + uint32_t nr_forks;
12988 + uint32_t load[3];
12991 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12992 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/debug_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/debug_cmd.h
12993 --- linux-3.9.4/include/uapi/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
12994 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/debug_cmd.h 2013-05-31 14:47:11.000000000 +0000
12996 +#ifndef _UAPI_VS_DEBUG_CMD_H
12997 +#define _UAPI_VS_DEBUG_CMD_H
13000 +/* debug commands */
13002 +#define VCMD_dump_history VC_CMD(DEBUG, 1, 0)
13004 +#define VCMD_read_history VC_CMD(DEBUG, 5, 0)
13005 +#define VCMD_read_monitor VC_CMD(DEBUG, 6, 0)
13007 +struct vcmd_read_history_v0 {
13010 + char __user *data;
13013 +struct vcmd_read_monitor_v0 {
13016 + char __user *data;
13019 +#endif /* _UAPI_VS_DEBUG_CMD_H */
13020 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/device.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/device.h
13021 --- linux-3.9.4/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
13022 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/device.h 2013-05-31 14:47:11.000000000 +0000
13024 +#ifndef _UAPI_VS_DEVICE_H
13025 +#define _UAPI_VS_DEVICE_H
13028 +#define DATTR_CREATE 0x00000001
13029 +#define DATTR_OPEN 0x00000002
13031 +#define DATTR_REMAP 0x00000010
13033 +#define DATTR_MASK 0x00000013
13035 +#endif /* _UAPI_VS_DEVICE_H */
13036 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/device_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/device_cmd.h
13037 --- linux-3.9.4/include/uapi/vserver/device_cmd.h 1970-01-01 00:00:00.000000000 +0000
13038 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/device_cmd.h 2013-05-31 14:47:11.000000000 +0000
13040 +#ifndef _UAPI_VS_DEVICE_CMD_H
13041 +#define _UAPI_VS_DEVICE_CMD_H
13044 +/* device vserver commands */
13046 +#define VCMD_set_mapping VC_CMD(DEVICE, 1, 0)
13047 +#define VCMD_unset_mapping VC_CMD(DEVICE, 2, 0)
13049 +struct vcmd_set_mapping_v0 {
13050 + const char __user *device;
13051 + const char __user *target;
13055 +#endif /* _UAPI_VS_DEVICE_CMD_H */
13056 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/dlimit_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/dlimit_cmd.h
13057 --- linux-3.9.4/include/uapi/vserver/dlimit_cmd.h 1970-01-01 00:00:00.000000000 +0000
13058 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/dlimit_cmd.h 2013-05-31 14:47:11.000000000 +0000
13060 +#ifndef _UAPI_VS_DLIMIT_CMD_H
13061 +#define _UAPI_VS_DLIMIT_CMD_H
13064 +/* dlimit vserver commands */
13066 +#define VCMD_add_dlimit VC_CMD(DLIMIT, 1, 0)
13067 +#define VCMD_rem_dlimit VC_CMD(DLIMIT, 2, 0)
13069 +#define VCMD_set_dlimit VC_CMD(DLIMIT, 5, 0)
13070 +#define VCMD_get_dlimit VC_CMD(DLIMIT, 6, 0)
13072 +struct vcmd_ctx_dlimit_base_v0 {
13073 + const char __user *name;
13077 +struct vcmd_ctx_dlimit_v0 {
13078 + const char __user *name;
13079 + uint32_t space_used; /* used space in kbytes */
13080 + uint32_t space_total; /* maximum space in kbytes */
13081 + uint32_t inodes_used; /* used inodes */
13082 + uint32_t inodes_total; /* maximum inodes */
13083 + uint32_t reserved; /* reserved for root in % */
13087 +#define CDLIM_UNSET ((uint32_t)0UL)
13088 +#define CDLIM_INFINITY ((uint32_t)~0UL)
13089 +#define CDLIM_KEEP ((uint32_t)~1UL)
13091 +#define DLIME_UNIT 0
13092 +#define DLIME_KILO 1
13093 +#define DLIME_MEGA 2
13094 +#define DLIME_GIGA 3
13096 +#define DLIMF_SHIFT 0x10
13098 +#define DLIMS_USED 0
13099 +#define DLIMS_TOTAL 2
13102 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
13104 + int exp = (flags & DLIMF_SHIFT) ?
13105 + (flags >> shift) & DLIME_GIGA : DLIME_KILO;
13106 + return ((uint64_t)val) << (10 * exp);
13110 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
13114 + if (*flags & DLIMF_SHIFT) {
13115 + while (val > (1LL << 32) && (exp < 3)) {
13119 + *flags &= ~(DLIME_GIGA << shift);
13120 + *flags |= exp << shift;
13126 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
13127 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/inode.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/inode.h
13128 --- linux-3.9.4/include/uapi/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
13129 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/inode.h 2013-05-31 14:47:11.000000000 +0000
13131 +#ifndef _UAPI_VS_INODE_H
13132 +#define _UAPI_VS_INODE_H
13135 +#define IATTR_TAG 0x01000000
13137 +#define IATTR_ADMIN 0x00000001
13138 +#define IATTR_WATCH 0x00000002
13139 +#define IATTR_HIDE 0x00000004
13140 +#define IATTR_FLAGS 0x00000007
13142 +#define IATTR_BARRIER 0x00010000
13143 +#define IATTR_IXUNLINK 0x00020000
13144 +#define IATTR_IMMUTABLE 0x00040000
13145 +#define IATTR_COW 0x00080000
13148 +/* inode ioctls */
13150 +#define FIOC_GETXFLG _IOR('x', 5, long)
13151 +#define FIOC_SETXFLG _IOW('x', 6, long)
13153 +#endif /* _UAPI_VS_INODE_H */
13154 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/inode_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/inode_cmd.h
13155 --- linux-3.9.4/include/uapi/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
13156 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/inode_cmd.h 2013-05-31 14:47:11.000000000 +0000
13158 +#ifndef _UAPI_VS_INODE_CMD_H
13159 +#define _UAPI_VS_INODE_CMD_H
13162 +/* inode vserver commands */
13164 +#define VCMD_get_iattr VC_CMD(INODE, 1, 1)
13165 +#define VCMD_set_iattr VC_CMD(INODE, 2, 1)
13167 +#define VCMD_fget_iattr VC_CMD(INODE, 3, 0)
13168 +#define VCMD_fset_iattr VC_CMD(INODE, 4, 0)
13170 +struct vcmd_ctx_iattr_v1 {
13171 + const char __user *name;
13177 +struct vcmd_ctx_fiattr_v0 {
13183 +#endif /* _UAPI_VS_INODE_CMD_H */
13184 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/limit.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/limit.h
13185 --- linux-3.9.4/include/uapi/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
13186 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/limit.h 2013-05-31 14:47:11.000000000 +0000
13188 +#ifndef _UAPI_VS_LIMIT_H
13189 +#define _UAPI_VS_LIMIT_H
13192 +#define VLIMIT_NSOCK 16
13193 +#define VLIMIT_OPENFD 17
13194 +#define VLIMIT_ANON 18
13195 +#define VLIMIT_SHMEM 19
13196 +#define VLIMIT_SEMARY 20
13197 +#define VLIMIT_NSEMS 21
13198 +#define VLIMIT_DENTRY 22
13199 +#define VLIMIT_MAPPED 23
13201 +#endif /* _UAPI_VS_LIMIT_H */
13202 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/limit_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/limit_cmd.h
13203 --- linux-3.9.4/include/uapi/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
13204 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/limit_cmd.h 2013-05-31 14:47:11.000000000 +0000
13206 +#ifndef _UAPI_VS_LIMIT_CMD_H
13207 +#define _UAPI_VS_LIMIT_CMD_H
13210 +/* rlimit vserver commands */
13212 +#define VCMD_get_rlimit VC_CMD(RLIMIT, 1, 0)
13213 +#define VCMD_set_rlimit VC_CMD(RLIMIT, 2, 0)
13214 +#define VCMD_get_rlimit_mask VC_CMD(RLIMIT, 3, 0)
13215 +#define VCMD_reset_hits VC_CMD(RLIMIT, 7, 0)
13216 +#define VCMD_reset_minmax VC_CMD(RLIMIT, 9, 0)
13218 +struct vcmd_ctx_rlimit_v0 {
13220 + uint64_t minimum;
13221 + uint64_t softlimit;
13222 + uint64_t maximum;
13225 +struct vcmd_ctx_rlimit_mask_v0 {
13226 + uint32_t minimum;
13227 + uint32_t softlimit;
13228 + uint32_t maximum;
13231 +#define VCMD_rlimit_stat VC_CMD(VSTAT, 1, 0)
13233 +struct vcmd_rlimit_stat_v0 {
13237 + uint64_t minimum;
13238 + uint64_t maximum;
13241 +#define CRLIM_UNSET (0ULL)
13242 +#define CRLIM_INFINITY (~0ULL)
13243 +#define CRLIM_KEEP (~1ULL)
13245 +#endif /* _UAPI_VS_LIMIT_CMD_H */
13246 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/monitor.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/monitor.h
13247 --- linux-3.9.4/include/uapi/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
13248 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/monitor.h 2013-05-31 14:47:11.000000000 +0000
13250 +#ifndef _UAPI_VS_MONITOR_H
13251 +#define _UAPI_VS_MONITOR_H
13253 +#include <linux/types.h>
13261 + VXM_UPDATE = 0x20,
13265 + VXM_RQINFO_1 = 0x24,
13268 + VXM_ACTIVATE = 0x40,
13275 + VXM_MIGRATE = 0x48,
13278 + /* all other bits are flags */
13279 + VXM_SCHED = 0x80,
13282 +struct _vxm_update_1 {
13283 + uint32_t tokens_max;
13284 + uint32_t fill_rate;
13285 + uint32_t interval;
13288 +struct _vxm_update_2 {
13289 + uint32_t tokens_min;
13290 + uint32_t fill_rate;
13291 + uint32_t interval;
13294 +struct _vxm_rqinfo_1 {
13295 + uint16_t running;
13299 + uint32_t idle_tokens;
13302 +struct _vxm_rqinfo_2 {
13303 + uint32_t norm_time;
13304 + uint32_t idle_time;
13305 + uint32_t idle_skip;
13308 +struct _vxm_sched {
13310 + uint32_t norm_time;
13311 + uint32_t idle_time;
13314 +struct _vxm_task {
13319 +struct _vxm_event {
13328 + struct _vxm_task tsk;
13332 +struct _vx_mon_entry {
13336 + struct _vxm_event ev;
13337 + struct _vxm_sched sd;
13338 + struct _vxm_update_1 u1;
13339 + struct _vxm_update_2 u2;
13340 + struct _vxm_rqinfo_1 q1;
13341 + struct _vxm_rqinfo_2 q2;
13345 +#endif /* _UAPI_VS_MONITOR_H */
13346 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/network.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/network.h
13347 --- linux-3.9.4/include/uapi/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
13348 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/network.h 2013-05-31 14:47:11.000000000 +0000
13350 +#ifndef _UAPI_VS_NETWORK_H
13351 +#define _UAPI_VS_NETWORK_H
13353 +#include <linux/types.h>
13356 +#define MAX_N_CONTEXT 65535 /* Arbitrary limit */
13359 +/* network flags */
13361 +#define NXF_INFO_PRIVATE 0x00000008
13363 +#define NXF_SINGLE_IP 0x00000100
13364 +#define NXF_LBACK_REMAP 0x00000200
13365 +#define NXF_LBACK_ALLOW 0x00000400
13367 +#define NXF_HIDE_NETIF 0x02000000
13368 +#define NXF_HIDE_LBACK 0x04000000
13370 +#define NXF_STATE_SETUP (1ULL << 32)
13371 +#define NXF_STATE_ADMIN (1ULL << 34)
13373 +#define NXF_SC_HELPER (1ULL << 36)
13374 +#define NXF_PERSISTENT (1ULL << 38)
13376 +#define NXF_ONE_TIME (0x0005ULL << 32)
13379 +#define NXF_INIT_SET (__nxf_init_set())
13381 +static inline uint64_t __nxf_init_set(void) {
13382 + return NXF_STATE_ADMIN
13383 +#ifdef CONFIG_VSERVER_AUTO_LBACK
13384 + | NXF_LBACK_REMAP
13387 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
13390 + | NXF_HIDE_NETIF;
13394 +/* network caps */
13396 +#define NXC_TUN_CREATE 0x00000001
13398 +#define NXC_RAW_ICMP 0x00000100
13400 +#define NXC_MULTICAST 0x00001000
13403 +/* address types */
13405 +#define NXA_TYPE_IPV4 0x0001
13406 +#define NXA_TYPE_IPV6 0x0002
13408 +#define NXA_TYPE_NONE 0x0000
13409 +#define NXA_TYPE_ANY 0x00FF
13411 +#define NXA_TYPE_ADDR 0x0010
13412 +#define NXA_TYPE_MASK 0x0020
13413 +#define NXA_TYPE_RANGE 0x0040
13415 +#define NXA_MASK_ALL (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
13417 +#define NXA_MOD_BCAST 0x0100
13418 +#define NXA_MOD_LBACK 0x0200
13420 +#define NXA_LOOPBACK 0x1000
13422 +#define NXA_MASK_BIND (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
13423 +#define NXA_MASK_SHOW (NXA_MASK_ALL | NXA_LOOPBACK)
13425 +#endif /* _UAPI_VS_NETWORK_H */
13426 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/network_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/network_cmd.h
13427 --- linux-3.9.4/include/uapi/vserver/network_cmd.h 1970-01-01 00:00:00.000000000 +0000
13428 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/network_cmd.h 2013-05-31 14:47:11.000000000 +0000
13430 +#ifndef _UAPI_VS_NETWORK_CMD_H
13431 +#define _UAPI_VS_NETWORK_CMD_H
13434 +/* vinfo commands */
13436 +#define VCMD_task_nid VC_CMD(VINFO, 2, 0)
13439 +#define VCMD_nx_info VC_CMD(VINFO, 6, 0)
13441 +struct vcmd_nx_info_v0 {
13443 + /* more to come */
13447 +#include <linux/in.h>
13448 +#include <linux/in6.h>
13450 +#define VCMD_net_create_v0 VC_CMD(VNET, 1, 0)
13451 +#define VCMD_net_create VC_CMD(VNET, 1, 1)
13453 +struct vcmd_net_create {
13454 + uint64_t flagword;
13457 +#define VCMD_net_migrate VC_CMD(NETMIG, 1, 0)
13459 +#define VCMD_net_add VC_CMD(NETALT, 1, 0)
13460 +#define VCMD_net_remove VC_CMD(NETALT, 2, 0)
13462 +struct vcmd_net_addr_v0 {
13465 + struct in_addr ip[4];
13466 + struct in_addr mask[4];
13469 +#define VCMD_net_add_ipv4_v1 VC_CMD(NETALT, 1, 1)
13470 +#define VCMD_net_rem_ipv4_v1 VC_CMD(NETALT, 2, 1)
13472 +struct vcmd_net_addr_ipv4_v1 {
13475 + struct in_addr ip;
13476 + struct in_addr mask;
13479 +#define VCMD_net_add_ipv4 VC_CMD(NETALT, 1, 2)
13480 +#define VCMD_net_rem_ipv4 VC_CMD(NETALT, 2, 2)
13482 +struct vcmd_net_addr_ipv4_v2 {
13485 + struct in_addr ip;
13486 + struct in_addr ip2;
13487 + struct in_addr mask;
13490 +#define VCMD_net_add_ipv6 VC_CMD(NETALT, 3, 1)
13491 +#define VCMD_net_remove_ipv6 VC_CMD(NETALT, 4, 1)
13493 +struct vcmd_net_addr_ipv6_v1 {
13497 + struct in6_addr ip;
13498 + struct in6_addr mask;
13501 +#define VCMD_add_match_ipv4 VC_CMD(NETALT, 5, 0)
13502 +#define VCMD_get_match_ipv4 VC_CMD(NETALT, 6, 0)
13504 +struct vcmd_match_ipv4_v0 {
13509 + struct in_addr ip;
13510 + struct in_addr ip2;
13511 + struct in_addr mask;
13514 +#define VCMD_add_match_ipv6 VC_CMD(NETALT, 7, 0)
13515 +#define VCMD_get_match_ipv6 VC_CMD(NETALT, 8, 0)
13517 +struct vcmd_match_ipv6_v0 {
13522 + struct in6_addr ip;
13523 + struct in6_addr ip2;
13524 + struct in6_addr mask;
13530 +/* flag commands */
13532 +#define VCMD_get_nflags VC_CMD(FLAGS, 5, 0)
13533 +#define VCMD_set_nflags VC_CMD(FLAGS, 6, 0)
13535 +struct vcmd_net_flags_v0 {
13536 + uint64_t flagword;
13542 +/* network caps commands */
13544 +#define VCMD_get_ncaps VC_CMD(FLAGS, 7, 0)
13545 +#define VCMD_set_ncaps VC_CMD(FLAGS, 8, 0)
13547 +struct vcmd_net_caps_v0 {
13552 +#endif /* _UAPI_VS_NETWORK_CMD_H */
13553 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/sched_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/sched_cmd.h
13554 --- linux-3.9.4/include/uapi/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
13555 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/sched_cmd.h 2013-05-31 14:47:11.000000000 +0000
13557 +#ifndef _UAPI_VS_SCHED_CMD_H
13558 +#define _UAPI_VS_SCHED_CMD_H
13561 +struct vcmd_prio_bias {
13563 + int32_t prio_bias;
13566 +#define VCMD_set_prio_bias VC_CMD(SCHED, 4, 0)
13567 +#define VCMD_get_prio_bias VC_CMD(SCHED, 5, 0)
13569 +#endif /* _UAPI_VS_SCHED_CMD_H */
13570 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/signal_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/signal_cmd.h
13571 --- linux-3.9.4/include/uapi/vserver/signal_cmd.h 1970-01-01 00:00:00.000000000 +0000
13572 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/signal_cmd.h 2013-05-31 14:47:11.000000000 +0000
13574 +#ifndef _UAPI_VS_SIGNAL_CMD_H
13575 +#define _UAPI_VS_SIGNAL_CMD_H
13578 +/* signalling vserver commands */
13580 +#define VCMD_ctx_kill VC_CMD(PROCTRL, 1, 0)
13581 +#define VCMD_wait_exit VC_CMD(EVENT, 99, 0)
13583 +struct vcmd_ctx_kill_v0 {
13588 +struct vcmd_wait_exit_v0 {
13589 + int32_t reboot_cmd;
13590 + int32_t exit_code;
13594 +/* process alteration commands */
13596 +#define VCMD_get_pflags VC_CMD(PROCALT, 5, 0)
13597 +#define VCMD_set_pflags VC_CMD(PROCALT, 6, 0)
13599 +struct vcmd_pflags_v0 {
13600 + uint32_t flagword;
13604 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
13605 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/space_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/space_cmd.h
13606 --- linux-3.9.4/include/uapi/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
13607 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/space_cmd.h 2013-05-31 14:47:11.000000000 +0000
13609 +#ifndef _UAPI_VS_SPACE_CMD_H
13610 +#define _UAPI_VS_SPACE_CMD_H
13613 +#define VCMD_enter_space_v0 VC_CMD(PROCALT, 1, 0)
13614 +#define VCMD_enter_space_v1 VC_CMD(PROCALT, 1, 1)
13615 +#define VCMD_enter_space VC_CMD(PROCALT, 1, 2)
13617 +#define VCMD_set_space_v0 VC_CMD(PROCALT, 3, 0)
13618 +#define VCMD_set_space_v1 VC_CMD(PROCALT, 3, 1)
13619 +#define VCMD_set_space VC_CMD(PROCALT, 3, 2)
13621 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
13623 +#define VCMD_get_space_mask VC_CMD(VSPACE, 0, 1)
13624 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
13627 +struct vcmd_space_mask_v1 {
13631 +struct vcmd_space_mask_v2 {
13636 +#endif /* _UAPI_VS_SPACE_CMD_H */
13637 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/switch.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/switch.h
13638 --- linux-3.9.4/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
13639 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/switch.h 2013-05-31 14:47:11.000000000 +0000
13641 +#ifndef _UAPI_VS_SWITCH_H
13642 +#define _UAPI_VS_SWITCH_H
13644 +#include <linux/types.h>
13647 +#define VC_CATEGORY(c) (((c) >> 24) & 0x3F)
13648 +#define VC_COMMAND(c) (((c) >> 16) & 0xFF)
13649 +#define VC_VERSION(c) ((c) & 0xFFF)
13651 +#define VC_CMD(c, i, v) ((((VC_CAT_ ## c) & 0x3F) << 24) \
13652 + | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
13656 + Syscall Matrix V2.8
13658 + |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
13659 + |STATS |DESTROY|ALTER |CHANGE |LIMIT |TEST | | | |
13660 + |INFO |SETUP | |MOVE | | | | | |
13661 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13662 + SYSTEM |VERSION|VSETUP |VHOST | | | | |DEVICE | |
13663 + HOST | 00| 01| 02| 03| 04| 05| | 06| 07|
13664 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13665 + CPU | |VPROC |PROCALT|PROCMIG|PROCTRL| | |SCHED. | |
13666 + PROCESS| 08| 09| 10| 11| 12| 13| | 14| 15|
13667 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13668 + MEMORY | | | | |MEMCTRL| | |SWAP | |
13669 + | 16| 17| 18| 19| 20| 21| | 22| 23|
13670 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13671 + NETWORK| |VNET |NETALT |NETMIG |NETCTL | | |SERIAL | |
13672 + | 24| 25| 26| 27| 28| 29| | 30| 31|
13673 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13674 + DISK | | | |TAGMIG |DLIMIT | | |INODE | |
13675 + VFS | 32| 33| 34| 35| 36| 37| | 38| 39|
13676 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13677 + OTHER |VSTAT | | | | | | |VINFO | |
13678 + | 40| 41| 42| 43| 44| 45| | 46| 47|
13679 + =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
13680 + SPECIAL|EVENT | | | |FLAGS | | |VSPACE | |
13681 + | 48| 49| 50| 51| 52| 53| | 54| 55|
13682 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13683 + SPECIAL|DEBUG | | | |RLIMIT |SYSCALL| | |COMPAT |
13684 + | 56| 57| 58| 59| 60|TEST 61| | 62| 63|
13685 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
13689 +#define VC_CAT_VERSION 0
13691 +#define VC_CAT_VSETUP 1
13692 +#define VC_CAT_VHOST 2
13694 +#define VC_CAT_DEVICE 6
13696 +#define VC_CAT_VPROC 9
13697 +#define VC_CAT_PROCALT 10
13698 +#define VC_CAT_PROCMIG 11
13699 +#define VC_CAT_PROCTRL 12
13701 +#define VC_CAT_SCHED 14
13702 +#define VC_CAT_MEMCTRL 20
13704 +#define VC_CAT_VNET 25
13705 +#define VC_CAT_NETALT 26
13706 +#define VC_CAT_NETMIG 27
13707 +#define VC_CAT_NETCTRL 28
13709 +#define VC_CAT_TAGMIG 35
13710 +#define VC_CAT_DLIMIT 36
13711 +#define VC_CAT_INODE 38
13713 +#define VC_CAT_VSTAT 40
13714 +#define VC_CAT_VINFO 46
13715 +#define VC_CAT_EVENT 48
13717 +#define VC_CAT_FLAGS 52
13718 +#define VC_CAT_VSPACE 54
13719 +#define VC_CAT_DEBUG 56
13720 +#define VC_CAT_RLIMIT 60
13722 +#define VC_CAT_SYSTEST 61
13723 +#define VC_CAT_COMPAT 63
13725 +/* query version */
13727 +#define VCMD_get_version VC_CMD(VERSION, 0, 0)
13728 +#define VCMD_get_vci VC_CMD(VERSION, 1, 0)
13730 +#endif /* _UAPI_VS_SWITCH_H */
13731 diff -NurpP --minimal linux-3.9.4/include/uapi/vserver/tag_cmd.h linux-3.9.4-vs2.3.6.2/include/uapi/vserver/tag_cmd.h
13732 --- linux-3.9.4/include/uapi/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
13733 +++ linux-3.9.4-vs2.3.6.2/include/uapi/vserver/tag_cmd.h 2013-05-31 14:47:11.000000000 +0000
13735 +#ifndef _UAPI_VS_TAG_CMD_H
13736 +#define _UAPI_VS_TAG_CMD_H
13739 +/* vinfo commands */
13741 +#define VCMD_task_tag VC_CMD(VINFO, 3, 0)
13744 +/* context commands */
13746 +#define VCMD_tag_migrate VC_CMD(TAGMIG, 1, 0)
13748 +#endif /* _UAPI_VS_TAG_CMD_H */
13749 diff -NurpP --minimal linux-3.9.4/init/Kconfig linux-3.9.4-vs2.3.6.2/init/Kconfig
13750 --- linux-3.9.4/init/Kconfig 2013-05-31 13:45:29.000000000 +0000
13751 +++ linux-3.9.4-vs2.3.6.2/init/Kconfig 2013-05-31 14:47:11.000000000 +0000
13752 @@ -760,6 +760,7 @@ config NUMA_BALANCING
13754 boolean "Control Group support"
13758 This option adds support for grouping sets of processes together, for
13759 use with process control subsystems such as Cpusets, CFS, memory
13760 @@ -1022,6 +1023,7 @@ config IPC_NS
13762 bool "User namespace"
13763 depends on UIDGID_CONVERTED
13764 + depends on VSERVER_DISABLED
13765 select UIDGID_STRICT_TYPE_CHECKS
13768 diff -NurpP --minimal linux-3.9.4/init/main.c linux-3.9.4-vs2.3.6.2/init/main.c
13769 --- linux-3.9.4/init/main.c 2013-05-31 13:45:29.000000000 +0000
13770 +++ linux-3.9.4-vs2.3.6.2/init/main.c 2013-05-31 15:09:17.000000000 +0000
13772 #include <linux/ptrace.h>
13773 #include <linux/blkdev.h>
13774 #include <linux/elevator.h>
13775 +#include <linux/vserver/percpu.h>
13777 #include <asm/io.h>
13778 #include <asm/bugs.h>
13779 diff -NurpP --minimal linux-3.9.4/ipc/mqueue.c linux-3.9.4-vs2.3.6.2/ipc/mqueue.c
13780 --- linux-3.9.4/ipc/mqueue.c 2013-05-31 13:45:29.000000000 +0000
13781 +++ linux-3.9.4-vs2.3.6.2/ipc/mqueue.c 2013-05-31 14:47:11.000000000 +0000
13783 #include <linux/ipc_namespace.h>
13784 #include <linux/user_namespace.h>
13785 #include <linux/slab.h>
13786 +#include <linux/vs_context.h>
13787 +#include <linux/vs_limit.h>
13789 #include <net/sock.h>
13791 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
13792 struct pid* notify_owner;
13793 struct user_namespace *notify_user_ns;
13794 struct user_struct *user; /* user who created, for accounting */
13795 + struct vx_info *vxi;
13796 struct sock *notify_sock;
13797 struct sk_buff *notify_cookie;
13799 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13800 if (S_ISREG(mode)) {
13801 struct mqueue_inode_info *info;
13802 unsigned long mq_bytes, mq_treesize;
13803 + struct vx_info *vxi = current_vx_info();
13805 inode->i_fop = &mqueue_file_operations;
13806 inode->i_size = FILENT_SIZE;
13807 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13808 info->notify_user_ns = NULL;
13810 info->user = NULL; /* set when all is ok */
13811 + info->vxi = NULL;
13812 info->msg_tree = RB_ROOT;
13813 info->node_cache = NULL;
13814 memset(&info->attr, 0, sizeof(info->attr));
13815 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13817 spin_lock(&mq_lock);
13818 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13819 - u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13820 + u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13821 + !vx_ipcmsg_avail(vxi, mq_bytes)) {
13822 spin_unlock(&mq_lock);
13823 /* mqueue_evict_inode() releases info->messages */
13827 u->mq_bytes += mq_bytes;
13828 + vx_ipcmsg_add(vxi, u, mq_bytes);
13829 spin_unlock(&mq_lock);
13832 info->user = get_uid(u);
13833 + info->vxi = get_vx_info(vxi);
13834 } else if (S_ISDIR(mode)) {
13836 /* Some things misbehave if size == 0 on a directory */
13837 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13841 + struct vx_info *vxi = info->vxi;
13843 spin_lock(&mq_lock);
13844 user->mq_bytes -= mq_bytes;
13845 + vx_ipcmsg_sub(vxi, user, mq_bytes);
13847 * get_ns_from_inode() ensures that the
13848 * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13849 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13851 ipc_ns->mq_queues_count--;
13852 spin_unlock(&mq_lock);
13853 + put_vx_info(vxi);
13857 diff -NurpP --minimal linux-3.9.4/ipc/msg.c linux-3.9.4-vs2.3.6.2/ipc/msg.c
13858 --- linux-3.9.4/ipc/msg.c 2013-05-31 13:45:29.000000000 +0000
13859 +++ linux-3.9.4-vs2.3.6.2/ipc/msg.c 2013-05-31 14:47:11.000000000 +0000
13861 #include <linux/rwsem.h>
13862 #include <linux/nsproxy.h>
13863 #include <linux/ipc_namespace.h>
13864 +#include <linux/vs_base.h>
13866 #include <asm/current.h>
13867 #include <asm/uaccess.h>
13868 @@ -190,6 +191,7 @@ static int newque(struct ipc_namespace *
13870 msq->q_perm.mode = msgflg & S_IRWXUGO;
13871 msq->q_perm.key = key;
13872 + msq->q_perm.xid = vx_current_xid();
13874 msq->q_perm.security = NULL;
13875 retval = security_msg_queue_alloc(msq);
13876 diff -NurpP --minimal linux-3.9.4/ipc/sem.c linux-3.9.4-vs2.3.6.2/ipc/sem.c
13877 --- linux-3.9.4/ipc/sem.c 2012-12-11 03:30:57.000000000 +0000
13878 +++ linux-3.9.4-vs2.3.6.2/ipc/sem.c 2013-05-31 14:47:11.000000000 +0000
13880 #include <linux/rwsem.h>
13881 #include <linux/nsproxy.h>
13882 #include <linux/ipc_namespace.h>
13883 +#include <linux/vs_base.h>
13884 +#include <linux/vs_limit.h>
13886 #include <asm/uaccess.h>
13888 @@ -306,6 +308,7 @@ static int newary(struct ipc_namespace *
13890 sma->sem_perm.mode = (semflg & S_IRWXUGO);
13891 sma->sem_perm.key = key;
13892 + sma->sem_perm.xid = vx_current_xid();
13894 sma->sem_perm.security = NULL;
13895 retval = security_sem_alloc(sma);
13896 @@ -321,6 +324,9 @@ static int newary(struct ipc_namespace *
13899 ns->used_sems += nsems;
13900 + /* FIXME: obsoleted? */
13901 + vx_semary_inc(sma);
13902 + vx_nsems_add(sma, nsems);
13904 sma->sem_base = (struct sem *) &sma[1];
13906 @@ -770,6 +776,9 @@ static void freeary(struct ipc_namespace
13908 wake_up_sem_queue_do(&tasks);
13909 ns->used_sems -= sma->sem_nsems;
13910 + /* FIXME: obsoleted? */
13911 + vx_nsems_sub(sma, sma->sem_nsems);
13912 + vx_semary_dec(sma);
13913 security_sem_free(sma);
13914 ipc_rcu_putref(sma);
13916 diff -NurpP --minimal linux-3.9.4/ipc/shm.c linux-3.9.4-vs2.3.6.2/ipc/shm.c
13917 --- linux-3.9.4/ipc/shm.c 2013-05-31 14:22:27.000000000 +0000
13918 +++ linux-3.9.4-vs2.3.6.2/ipc/shm.c 2013-05-31 14:47:11.000000000 +0000
13920 #include <linux/nsproxy.h>
13921 #include <linux/mount.h>
13922 #include <linux/ipc_namespace.h>
13923 +#include <linux/vs_context.h>
13924 +#include <linux/vs_limit.h>
13926 #include <asm/uaccess.h>
13928 @@ -187,7 +189,12 @@ static void shm_open(struct vm_area_stru
13930 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13932 - ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13933 + struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13934 + int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13936 + vx_ipcshm_sub(vxi, shp, numpages);
13937 + ns->shm_tot -= numpages;
13941 if (!is_file_hugepages(shp->shm_file))
13942 @@ -197,6 +204,7 @@ static void shm_destroy(struct ipc_names
13944 fput (shp->shm_file);
13945 security_shm_free(shp);
13946 + put_vx_info(vxi);
13947 ipc_rcu_putref(shp);
13950 @@ -474,11 +482,15 @@ static int newseg(struct ipc_namespace *
13951 if (ns->shm_tot + numpages > ns->shm_ctlall)
13954 + if (!vx_ipcshm_avail(current_vx_info(), numpages))
13957 shp = ipc_rcu_alloc(sizeof(*shp));
13961 shp->shm_perm.key = key;
13962 + shp->shm_perm.xid = vx_current_xid();
13963 shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13964 shp->mlock_user = NULL;
13966 @@ -544,6 +556,7 @@ static int newseg(struct ipc_namespace *
13967 ns->shm_tot += numpages;
13968 error = shp->shm_perm.id;
13970 + vx_ipcshm_add(current_vx_info(), key, numpages);
13974 diff -NurpP --minimal linux-3.9.4/kernel/Makefile linux-3.9.4-vs2.3.6.2/kernel/Makefile
13975 --- linux-3.9.4/kernel/Makefile 2013-05-31 14:22:27.000000000 +0000
13976 +++ linux-3.9.4-vs2.3.6.2/kernel/Makefile 2013-05-31 14:47:11.000000000 +0000
13977 @@ -24,6 +24,7 @@ endif
13983 obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13984 obj-$(CONFIG_FREEZER) += freezer.o
13985 diff -NurpP --minimal linux-3.9.4/kernel/auditsc.c linux-3.9.4-vs2.3.6.2/kernel/auditsc.c
13986 --- linux-3.9.4/kernel/auditsc.c 2013-05-31 14:22:27.000000000 +0000
13987 +++ linux-3.9.4-vs2.3.6.2/kernel/auditsc.c 2013-05-31 14:47:11.000000000 +0000
13988 @@ -2315,7 +2315,7 @@ int audit_set_loginuid(kuid_t loginuid)
13989 if (audit_loginuid_set(task))
13991 #else /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13992 - if (!capable(CAP_AUDIT_CONTROL))
13993 + if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13995 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
13997 diff -NurpP --minimal linux-3.9.4/kernel/capability.c linux-3.9.4-vs2.3.6.2/kernel/capability.c
13998 --- linux-3.9.4/kernel/capability.c 2013-05-31 13:45:29.000000000 +0000
13999 +++ linux-3.9.4-vs2.3.6.2/kernel/capability.c 2013-05-31 14:47:11.000000000 +0000
14001 #include <linux/syscalls.h>
14002 #include <linux/pid_namespace.h>
14003 #include <linux/user_namespace.h>
14004 +#include <linux/vs_context.h>
14005 #include <asm/uaccess.h>
14008 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
14014 * The only thing that can change the capabilities of the current
14015 * process is the current process. As such, we can't be in this code
14016 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
14020 +#include <linux/vserver/base.h>
14023 * has_capability_noaudit - Does a task have a capability (unaudited) in the
14025 diff -NurpP --minimal linux-3.9.4/kernel/compat.c linux-3.9.4-vs2.3.6.2/kernel/compat.c
14026 --- linux-3.9.4/kernel/compat.c 2013-05-31 13:45:29.000000000 +0000
14027 +++ linux-3.9.4-vs2.3.6.2/kernel/compat.c 2013-05-31 14:47:11.000000000 +0000
14029 #include <linux/times.h>
14030 #include <linux/ptrace.h>
14031 #include <linux/gfp.h>
14032 +#include <linux/vs_time.h>
14034 #include <asm/uaccess.h>
14036 @@ -1059,7 +1060,7 @@ asmlinkage long compat_sys_stime(compat_
14040 - do_settimeofday(&tv);
14041 + vx_settimeofday(&tv);
14045 diff -NurpP --minimal linux-3.9.4/kernel/cred.c linux-3.9.4-vs2.3.6.2/kernel/cred.c
14046 --- linux-3.9.4/kernel/cred.c 2013-02-19 13:58:56.000000000 +0000
14047 +++ linux-3.9.4-vs2.3.6.2/kernel/cred.c 2013-05-31 14:47:11.000000000 +0000
14048 @@ -56,31 +56,6 @@ struct cred init_cred = {
14049 .group_info = &init_groups,
14052 -static inline void set_cred_subscribers(struct cred *cred, int n)
14054 -#ifdef CONFIG_DEBUG_CREDENTIALS
14055 - atomic_set(&cred->subscribers, n);
14059 -static inline int read_cred_subscribers(const struct cred *cred)
14061 -#ifdef CONFIG_DEBUG_CREDENTIALS
14062 - return atomic_read(&cred->subscribers);
14068 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
14070 -#ifdef CONFIG_DEBUG_CREDENTIALS
14071 - struct cred *cred = (struct cred *) _cred;
14073 - atomic_add(n, &cred->subscribers);
14078 * The RCU callback to actually dispose of a set of credentials
14080 @@ -232,21 +207,16 @@ error:
14082 * Call commit_creds() or abort_creds() to clean up.
14084 -struct cred *prepare_creds(void)
14085 +struct cred *__prepare_creds(const struct cred *old)
14087 - struct task_struct *task = current;
14088 - const struct cred *old;
14091 - validate_process_creds();
14093 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
14097 kdebug("prepare_creds() alloc %p", new);
14099 - old = task->cred;
14100 memcpy(new, old, sizeof(struct cred));
14102 atomic_set(&new->usage, 1);
14103 @@ -275,6 +245,13 @@ error:
14108 +struct cred *prepare_creds(void)
14110 + validate_process_creds();
14112 + return __prepare_creds(current->cred);
14114 EXPORT_SYMBOL(prepare_creds);
14117 diff -NurpP --minimal linux-3.9.4/kernel/exit.c linux-3.9.4-vs2.3.6.2/kernel/exit.c
14118 --- linux-3.9.4/kernel/exit.c 2013-05-31 13:45:29.000000000 +0000
14119 +++ linux-3.9.4-vs2.3.6.2/kernel/exit.c 2013-05-31 14:47:11.000000000 +0000
14121 #include <linux/fs_struct.h>
14122 #include <linux/init_task.h>
14123 #include <linux/perf_event.h>
14124 +#include <linux/vs_limit.h>
14125 +#include <linux/vs_context.h>
14126 +#include <linux/vs_network.h>
14127 +#include <linux/vs_pid.h>
14128 #include <trace/events/sched.h>
14129 #include <linux/hw_breakpoint.h>
14130 #include <linux/oom.h>
14131 @@ -514,15 +518,25 @@ static struct task_struct *find_new_reap
14132 __acquires(&tasklist_lock)
14134 struct pid_namespace *pid_ns = task_active_pid_ns(father);
14135 - struct task_struct *thread;
14136 + struct vx_info *vxi = task_get_vx_info(father);
14137 + struct task_struct *thread = father;
14138 + struct task_struct *reaper;
14141 while_each_thread(father, thread) {
14142 if (thread->flags & PF_EXITING)
14144 if (unlikely(pid_ns->child_reaper == father))
14145 pid_ns->child_reaper = thread;
14151 + reaper = pid_ns->child_reaper;
14153 + BUG_ON(!vxi->vx_reaper);
14154 + if (vxi->vx_reaper != init_pid_ns.child_reaper &&
14155 + vxi->vx_reaper != father)
14156 + reaper = vxi->vx_reaper;
14159 if (unlikely(pid_ns->child_reaper == father)) {
14160 @@ -560,7 +574,9 @@ static struct task_struct *find_new_reap
14164 - return pid_ns->child_reaper;
14166 + put_vx_info(vxi);
14171 @@ -611,10 +627,15 @@ static void forget_original_parent(struc
14172 list_for_each_entry_safe(p, n, &father->children, sibling) {
14173 struct task_struct *t = p;
14175 - t->real_parent = reaper;
14176 + struct task_struct *new_parent = reaper;
14178 + if (unlikely(p == reaper))
14179 + new_parent = task_active_pid_ns(p)->child_reaper;
14181 + t->real_parent = new_parent;
14182 if (t->parent == father) {
14184 - t->parent = t->real_parent;
14185 + t->parent = new_parent;
14187 if (t->pdeath_signal)
14188 group_send_sig_info(t->pdeath_signal,
14189 @@ -821,6 +842,9 @@ void do_exit(long code)
14191 ptrace_put_breakpoints(tsk);
14193 + /* needs to stay before exit_notify() */
14194 + exit_vx_info_early(tsk, code);
14196 exit_notify(tsk, group_dead);
14199 @@ -874,10 +898,15 @@ void do_exit(long code)
14201 raw_spin_unlock_wait(&tsk->pi_lock);
14203 + /* needs to stay after exit_notify() */
14204 + exit_vx_info(tsk, code);
14205 + exit_nx_info(tsk);
14207 /* causes final put_task_struct in finish_task_switch(). */
14208 tsk->state = TASK_DEAD;
14209 tsk->flags |= PF_NOFREEZE; /* tell freezer to ignore us */
14211 + printk("bad task: %p [%lx]\n", current, current->state);
14213 /* Avoid "noreturn function does return". */
14215 diff -NurpP --minimal linux-3.9.4/kernel/fork.c linux-3.9.4-vs2.3.6.2/kernel/fork.c
14216 --- linux-3.9.4/kernel/fork.c 2013-05-31 13:45:29.000000000 +0000
14217 +++ linux-3.9.4-vs2.3.6.2/kernel/fork.c 2013-05-31 14:47:11.000000000 +0000
14219 #include <linux/khugepaged.h>
14220 #include <linux/signalfd.h>
14221 #include <linux/uprobes.h>
14222 +#include <linux/vs_context.h>
14223 +#include <linux/vs_network.h>
14224 +#include <linux/vs_limit.h>
14226 #include <asm/pgtable.h>
14227 #include <asm/pgalloc.h>
14228 @@ -210,6 +213,8 @@ void free_task(struct task_struct *tsk)
14229 arch_release_thread_info(tsk->stack);
14230 free_thread_info(tsk->stack);
14231 rt_mutex_debug_task_free(tsk);
14232 + clr_vx_info(&tsk->vx_info);
14233 + clr_nx_info(&tsk->nx_info);
14234 ftrace_graph_exit_task(tsk);
14235 put_seccomp_filter(tsk);
14236 arch_release_task_struct(tsk);
14237 @@ -547,6 +552,7 @@ static struct mm_struct *mm_init(struct
14238 if (likely(!mm_alloc_pgd(mm))) {
14240 mmu_notifier_mm_init(mm);
14241 + set_vx_info(&mm->mm_vx_info, p->vx_info);
14245 @@ -599,6 +605,7 @@ void __mmdrop(struct mm_struct *mm)
14246 destroy_context(mm);
14247 mmu_notifier_mm_destroy(mm);
14249 + clr_vx_info(&mm->mm_vx_info);
14252 EXPORT_SYMBOL_GPL(__mmdrop);
14253 @@ -818,6 +825,7 @@ struct mm_struct *dup_mm(struct task_str
14256 memcpy(mm, oldmm, sizeof(*mm));
14257 + mm->mm_vx_info = NULL;
14258 mm_init_cpumask(mm);
14260 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
14261 @@ -859,6 +867,7 @@ fail_nocontext:
14262 * If init_new_context() failed, we cannot use mmput() to free the mm
14263 * because it calls destroy_context()
14265 + clr_vx_info(&mm->mm_vx_info);
14269 @@ -1137,6 +1146,8 @@ static struct task_struct *copy_process(
14272 struct task_struct *p;
14273 + struct vx_info *vxi;
14274 + struct nx_info *nxi;
14276 if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
14277 return ERR_PTR(-EINVAL);
14278 @@ -1195,7 +1206,12 @@ static struct task_struct *copy_process(
14279 DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
14280 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
14282 + init_vx_info(&p->vx_info, current_vx_info());
14283 + init_nx_info(&p->nx_info, current_nx_info());
14286 + if (!vx_nproc_avail(1))
14287 + goto bad_fork_free;
14288 if (atomic_read(&p->real_cred->user->processes) >=
14289 task_rlimit(p, RLIMIT_NPROC)) {
14290 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
14291 @@ -1472,6 +1488,18 @@ static struct task_struct *copy_process(
14294 spin_unlock(¤t->sighand->siglock);
14296 + /* p is copy of current */
14297 + vxi = p->vx_info;
14299 + claim_vx_info(vxi, p);
14300 + atomic_inc(&vxi->cvirt.nr_threads);
14301 + atomic_inc(&vxi->cvirt.total_forks);
14304 + nxi = p->nx_info;
14306 + claim_nx_info(nxi, p);
14307 write_unlock_irq(&tasklist_lock);
14308 proc_fork_connector(p);
14309 cgroup_post_fork(p);
14310 diff -NurpP --minimal linux-3.9.4/kernel/kthread.c linux-3.9.4-vs2.3.6.2/kernel/kthread.c
14311 --- linux-3.9.4/kernel/kthread.c 2013-05-31 13:45:30.000000000 +0000
14312 +++ linux-3.9.4-vs2.3.6.2/kernel/kthread.c 2013-05-31 14:47:11.000000000 +0000
14314 #include <linux/slab.h>
14315 #include <linux/freezer.h>
14316 #include <linux/ptrace.h>
14317 +#include <linux/vs_pid.h>
14318 #include <trace/events/sched.h>
14320 static DEFINE_SPINLOCK(kthread_create_lock);
14321 diff -NurpP --minimal linux-3.9.4/kernel/nsproxy.c linux-3.9.4-vs2.3.6.2/kernel/nsproxy.c
14322 --- linux-3.9.4/kernel/nsproxy.c 2013-05-31 13:45:30.000000000 +0000
14323 +++ linux-3.9.4-vs2.3.6.2/kernel/nsproxy.c 2013-05-31 19:28:43.000000000 +0000
14324 @@ -20,11 +20,14 @@
14325 #include <linux/mnt_namespace.h>
14326 #include <linux/utsname.h>
14327 #include <linux/pid_namespace.h>
14328 +#include <linux/vserver/global.h>
14329 +#include <linux/vserver/debug.h>
14330 #include <net/net_namespace.h>
14331 #include <linux/ipc_namespace.h>
14332 #include <linux/proc_fs.h>
14333 #include <linux/file.h>
14334 #include <linux/syscalls.h>
14335 +#include "../fs/mount.h"
14337 static struct kmem_cache *nsproxy_cachep;
14339 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
14340 struct nsproxy *nsproxy;
14342 nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
14345 atomic_set(&nsproxy->count, 1);
14346 + atomic_inc(&vs_global_nsproxy);
14348 + vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
14352 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
14353 * Return the newly created nsproxy. Do not attach this to the task,
14354 * leave it to the caller to do proper locking and attach it to task.
14356 -static struct nsproxy *create_new_namespaces(unsigned long flags,
14357 - struct task_struct *tsk, struct user_namespace *user_ns,
14358 - struct fs_struct *new_fs)
14359 +static struct nsproxy *unshare_namespaces(
14360 + unsigned long flags,
14361 + struct nsproxy *orig,
14362 + struct fs_struct *new_fs,
14363 + struct user_namespace *new_user,
14364 + struct pid_namespace *new_pid)
14366 struct nsproxy *new_nsp;
14368 @@ -67,31 +76,31 @@ static struct nsproxy *create_new_namesp
14370 return ERR_PTR(-ENOMEM);
14372 - new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
14373 + new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
14374 if (IS_ERR(new_nsp->mnt_ns)) {
14375 err = PTR_ERR(new_nsp->mnt_ns);
14379 - new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
14380 + new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
14381 if (IS_ERR(new_nsp->uts_ns)) {
14382 err = PTR_ERR(new_nsp->uts_ns);
14386 - new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
14387 + new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
14388 if (IS_ERR(new_nsp->ipc_ns)) {
14389 err = PTR_ERR(new_nsp->ipc_ns);
14393 - new_nsp->pid_ns = copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns);
14394 + new_nsp->pid_ns = copy_pid_ns(flags, new_user, new_pid);
14395 if (IS_ERR(new_nsp->pid_ns)) {
14396 err = PTR_ERR(new_nsp->pid_ns);
14400 - new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
14401 + new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
14402 if (IS_ERR(new_nsp->net_ns)) {
14403 err = PTR_ERR(new_nsp->net_ns);
14405 @@ -116,6 +125,41 @@ out_ns:
14406 return ERR_PTR(err);
14409 +static struct nsproxy *create_new_namespaces(unsigned long flags,
14410 + struct task_struct *tsk, struct user_namespace *user_ns,
14411 + struct fs_struct *new_fs)
14414 + return unshare_namespaces(flags, tsk->nsproxy,
14415 + new_fs, user_ns, task_active_pid_ns(tsk));
14419 + * copies the nsproxy, setting refcount to 1, and grabbing a
14420 + * reference to all contained namespaces.
14422 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
14424 + struct nsproxy *ns = create_nsproxy();
14427 + memcpy(ns, orig, sizeof(struct nsproxy));
14428 + atomic_set(&ns->count, 1);
14431 + get_mnt_ns(ns->mnt_ns);
14433 + get_uts_ns(ns->uts_ns);
14435 + get_ipc_ns(ns->ipc_ns);
14437 + get_pid_ns(ns->pid_ns);
14439 + get_net(ns->net_ns);
14445 * called from clone. This now handles copy for nsproxy and all
14446 * namespaces therein.
14447 @@ -124,9 +168,12 @@ int copy_namespaces(unsigned long flags,
14449 struct nsproxy *old_ns = tsk->nsproxy;
14450 struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
14451 - struct nsproxy *new_ns;
14452 + struct nsproxy *new_ns = NULL;
14455 + vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
14456 + flags, tsk, old_ns);
14461 @@ -136,7 +183,7 @@ int copy_namespaces(unsigned long flags,
14462 CLONE_NEWPID | CLONE_NEWNET)))
14465 - if (!ns_capable(user_ns, CAP_SYS_ADMIN)) {
14466 + if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags)) {
14470 @@ -163,6 +210,9 @@ int copy_namespaces(unsigned long flags,
14473 put_nsproxy(old_ns);
14474 + vxdprintk(VXD_CBIT(space, 3),
14475 + "copy_namespaces(0x%08lx,%p[%p]) = %d [%p]",
14476 + flags, tsk, old_ns, err, new_ns);
14480 @@ -176,7 +226,9 @@ void free_nsproxy(struct nsproxy *ns)
14481 put_ipc_ns(ns->ipc_ns);
14483 put_pid_ns(ns->pid_ns);
14484 - put_net(ns->net_ns);
14486 + put_net(ns->net_ns);
14487 + atomic_dec(&vs_global_nsproxy);
14488 kmem_cache_free(nsproxy_cachep, ns);
14491 @@ -190,12 +242,16 @@ int unshare_nsproxy_namespaces(unsigned
14492 struct user_namespace *user_ns;
14495 + vxdprintk(VXD_CBIT(space, 4),
14496 + "unshare_nsproxy_namespaces(0x%08lx,[%p])",
14497 + unshare_flags, current->nsproxy);
14499 if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
14500 CLONE_NEWNET | CLONE_NEWPID)))
14503 user_ns = new_cred ? new_cred->user_ns : current_user_ns();
14504 - if (!ns_capable(user_ns, CAP_SYS_ADMIN))
14505 + if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
14508 *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
14509 diff -NurpP --minimal linux-3.9.4/kernel/pid.c linux-3.9.4-vs2.3.6.2/kernel/pid.c
14510 --- linux-3.9.4/kernel/pid.c 2013-05-31 13:45:30.000000000 +0000
14511 +++ linux-3.9.4-vs2.3.6.2/kernel/pid.c 2013-05-31 15:24:34.000000000 +0000
14513 #include <linux/init_task.h>
14514 #include <linux/syscalls.h>
14515 #include <linux/proc_fs.h>
14516 +#include <linux/vs_pid.h>
14518 #define pid_hashfn(nr, ns) \
14519 hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
14520 @@ -364,7 +365,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
14522 struct pid *find_vpid(int nr)
14524 - return find_pid_ns(nr, task_active_pid_ns(current));
14525 + return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
14527 EXPORT_SYMBOL_GPL(find_vpid);
14529 @@ -424,6 +425,9 @@ void transfer_pid(struct task_struct *ol
14530 struct task_struct *pid_task(struct pid *pid, enum pid_type type)
14532 struct task_struct *result = NULL;
14534 + if (type == PIDTYPE_REALPID)
14535 + type = PIDTYPE_PID;
14537 struct hlist_node *first;
14538 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
14539 @@ -443,7 +447,7 @@ struct task_struct *find_task_by_pid_ns(
14540 rcu_lockdep_assert(rcu_read_lock_held(),
14541 "find_task_by_pid_ns() needs rcu_read_lock()"
14543 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
14544 + return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
14547 struct task_struct *find_task_by_vpid(pid_t vnr)
14548 @@ -487,7 +491,7 @@ struct pid *find_get_pid(pid_t nr)
14550 EXPORT_SYMBOL_GPL(find_get_pid);
14552 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14553 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
14557 @@ -501,6 +505,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
14559 EXPORT_SYMBOL_GPL(pid_nr_ns);
14561 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
14563 + return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
14566 pid_t pid_vnr(struct pid *pid)
14568 return pid_nr_ns(pid, task_active_pid_ns(current));
14569 diff -NurpP --minimal linux-3.9.4/kernel/pid_namespace.c linux-3.9.4-vs2.3.6.2/kernel/pid_namespace.c
14570 --- linux-3.9.4/kernel/pid_namespace.c 2013-05-31 13:45:30.000000000 +0000
14571 +++ linux-3.9.4-vs2.3.6.2/kernel/pid_namespace.c 2013-05-31 17:59:48.000000000 +0000
14573 #include <linux/proc_fs.h>
14574 #include <linux/reboot.h>
14575 #include <linux/export.h>
14576 +#include <linux/vserver/global.h>
14578 #define BITS_PER_PAGE (PAGE_SIZE*8)
14580 @@ -112,6 +113,7 @@ static struct pid_namespace *create_pid_
14583 kref_init(&ns->kref);
14584 + atomic_inc(&vs_global_pid_ns);
14586 ns->parent = get_pid_ns(parent_pid_ns);
14587 ns->user_ns = get_user_ns(user_ns);
14588 @@ -142,6 +144,7 @@ static void destroy_pid_namespace(struct
14589 for (i = 0; i < PIDMAP_ENTRIES; i++)
14590 kfree(ns->pidmap[i].page);
14591 put_user_ns(ns->user_ns);
14592 + atomic_dec(&vs_global_pid_ns);
14593 kmem_cache_free(pid_ns_cachep, ns);
14596 diff -NurpP --minimal linux-3.9.4/kernel/posix-timers.c linux-3.9.4-vs2.3.6.2/kernel/posix-timers.c
14597 --- linux-3.9.4/kernel/posix-timers.c 2013-05-31 13:45:30.000000000 +0000
14598 +++ linux-3.9.4-vs2.3.6.2/kernel/posix-timers.c 2013-05-31 14:47:11.000000000 +0000
14600 #include <linux/wait.h>
14601 #include <linux/workqueue.h>
14602 #include <linux/export.h>
14603 +#include <linux/vs_context.h>
14606 * Management arrays for POSIX timers. Timers are kept in slab memory
14607 @@ -340,6 +341,7 @@ int posix_timer_event(struct k_itimer *t
14609 struct task_struct *task;
14610 int shared, ret = -1;
14613 * FIXME: if ->sigq is queued we can race with
14614 * dequeue_signal()->do_schedule_next_timer().
14615 @@ -356,10 +358,18 @@ int posix_timer_event(struct k_itimer *t
14617 task = pid_task(timr->it_pid, PIDTYPE_PID);
14619 + struct vx_info_save vxis;
14620 + struct vx_info *vxi;
14622 + vxi = get_vx_info(task->vx_info);
14623 + enter_vx_info(vxi, &vxis);
14624 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
14625 ret = send_sigqueue(timr->sigq, task, shared);
14626 + leave_vx_info(&vxis);
14627 + put_vx_info(vxi);
14631 /* If we failed to send the signal the timer stops. */
14634 diff -NurpP --minimal linux-3.9.4/kernel/printk.c linux-3.9.4-vs2.3.6.2/kernel/printk.c
14635 --- linux-3.9.4/kernel/printk.c 2013-05-31 13:45:30.000000000 +0000
14636 +++ linux-3.9.4-vs2.3.6.2/kernel/printk.c 2013-05-31 15:23:35.000000000 +0000
14638 #include <linux/rculist.h>
14639 #include <linux/poll.h>
14640 #include <linux/irq_work.h>
14641 +#include <linux/vs_cvirt.h>
14643 #include <asm/uaccess.h>
14645 @@ -841,7 +842,7 @@ static int check_syslog_permissions(int
14648 if (syslog_action_restricted(type)) {
14649 - if (capable(CAP_SYSLOG))
14650 + if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
14652 /* For historical reasons, accept CAP_SYS_ADMIN too, with a warning */
14653 if (capable(CAP_SYS_ADMIN)) {
14654 @@ -1135,12 +1136,9 @@ int do_syslog(int type, char __user *buf
14659 - case SYSLOG_ACTION_CLOSE: /* Close log */
14661 - case SYSLOG_ACTION_OPEN: /* Open log */
14663 - case SYSLOG_ACTION_READ: /* Read from log */
14664 + if ((type == SYSLOG_ACTION_READ) ||
14665 + (type == SYSLOG_ACTION_READ_ALL) ||
14666 + (type == SYSLOG_ACTION_READ_CLEAR)) {
14668 if (!buf || len < 0)
14670 @@ -1151,6 +1149,16 @@ int do_syslog(int type, char __user *buf
14675 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
14676 + return vx_do_syslog(type, buf, len);
14679 + case SYSLOG_ACTION_CLOSE: /* Close log */
14681 + case SYSLOG_ACTION_OPEN: /* Open log */
14683 + case SYSLOG_ACTION_READ: /* Read from log */
14684 error = wait_event_interruptible(log_wait,
14685 syslog_seq != log_next_seq);
14687 @@ -1163,16 +1171,6 @@ int do_syslog(int type, char __user *buf
14689 /* Read last kernel messages */
14690 case SYSLOG_ACTION_READ_ALL:
14692 - if (!buf || len < 0)
14697 - if (!access_ok(VERIFY_WRITE, buf, len)) {
14701 error = syslog_print_all(buf, len, clear);
14703 /* Clear ring buffer */
14704 diff -NurpP --minimal linux-3.9.4/kernel/ptrace.c linux-3.9.4-vs2.3.6.2/kernel/ptrace.c
14705 --- linux-3.9.4/kernel/ptrace.c 2013-05-31 13:45:30.000000000 +0000
14706 +++ linux-3.9.4-vs2.3.6.2/kernel/ptrace.c 2013-05-31 15:22:34.000000000 +0000
14708 #include <linux/syscalls.h>
14709 #include <linux/uaccess.h>
14710 #include <linux/regset.h>
14711 +#include <linux/vs_context.h>
14712 #include <linux/hw_breakpoint.h>
14713 #include <linux/cn_proc.h>
14715 @@ -261,6 +262,11 @@ ok:
14719 + if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
14721 + if (!vx_check(task->xid, VS_IDENT) &&
14722 + !task_vx_flags(task, VXF_STATE_ADMIN, 0))
14724 return security_ptrace_access_check(task, mode);
14727 diff -NurpP --minimal linux-3.9.4/kernel/sched/core.c linux-3.9.4-vs2.3.6.2/kernel/sched/core.c
14728 --- linux-3.9.4/kernel/sched/core.c 2013-05-31 13:45:30.000000000 +0000
14729 +++ linux-3.9.4-vs2.3.6.2/kernel/sched/core.c 2013-05-31 15:17:22.000000000 +0000
14731 #include <linux/init_task.h>
14732 #include <linux/binfmts.h>
14733 #include <linux/context_tracking.h>
14734 +#include <linux/vs_sched.h>
14735 +#include <linux/vs_cvirt.h>
14737 #include <asm/switch_to.h>
14738 #include <asm/tlb.h>
14739 @@ -2091,9 +2093,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14741 void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14743 - loads[0] = (avenrun[0] + offset) << shift;
14744 - loads[1] = (avenrun[1] + offset) << shift;
14745 - loads[2] = (avenrun[2] + offset) << shift;
14746 + if (vx_flags(VXF_VIRT_LOAD, 0)) {
14747 + struct vx_info *vxi = current_vx_info();
14749 + loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14750 + loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14751 + loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14753 + loads[0] = (avenrun[0] + offset) << shift;
14754 + loads[1] = (avenrun[1] + offset) << shift;
14755 + loads[2] = (avenrun[2] + offset) << shift;
14759 static long calc_load_fold_active(struct rq *this_rq)
14760 @@ -3704,7 +3714,7 @@ SYSCALL_DEFINE1(nice, int, increment)
14763 if (increment < 0 && !can_nice(current, nice))
14765 + return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
14767 retval = security_task_setnice(current, nice);
14769 diff -NurpP --minimal linux-3.9.4/kernel/sched/cputime.c linux-3.9.4-vs2.3.6.2/kernel/sched/cputime.c
14770 --- linux-3.9.4/kernel/sched/cputime.c 2013-05-31 14:22:27.000000000 +0000
14771 +++ linux-3.9.4-vs2.3.6.2/kernel/sched/cputime.c 2013-05-31 15:17:55.000000000 +0000
14773 #include <linux/kernel_stat.h>
14774 #include <linux/static_key.h>
14775 #include <linux/context_tracking.h>
14776 +#include <linux/vs_sched.h>
14780 @@ -151,14 +152,17 @@ static inline void task_group_account_fi
14781 void account_user_time(struct task_struct *p, cputime_t cputime,
14782 cputime_t cputime_scaled)
14784 + struct vx_info *vxi = p->vx_info; /* p is _always_ current */
14785 + int nice = (TASK_NICE(p) > 0);
14788 /* Add user time to process. */
14789 p->utime += cputime;
14790 p->utimescaled += cputime_scaled;
14791 + vx_account_user(vxi, cputime, nice);
14792 account_group_user_time(p, cputime);
14794 - index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14795 + index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14797 /* Add user time to cpustat. */
14798 task_group_account_field(p, index, (__force u64) cputime);
14799 @@ -205,9 +209,12 @@ static inline
14800 void __account_system_time(struct task_struct *p, cputime_t cputime,
14801 cputime_t cputime_scaled, int index)
14803 + struct vx_info *vxi = p->vx_info; /* p is _always_ current */
14805 /* Add system time to process. */
14806 p->stime += cputime;
14807 p->stimescaled += cputime_scaled;
14808 + vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14809 account_group_system_time(p, cputime);
14811 /* Add system time to cpustat. */
14812 diff -NurpP --minimal linux-3.9.4/kernel/sched/fair.c linux-3.9.4-vs2.3.6.2/kernel/sched/fair.c
14813 --- linux-3.9.4/kernel/sched/fair.c 2013-05-31 13:45:30.000000000 +0000
14814 +++ linux-3.9.4-vs2.3.6.2/kernel/sched/fair.c 2013-05-31 15:19:37.000000000 +0000
14816 #include <linux/mempolicy.h>
14817 #include <linux/migrate.h>
14818 #include <linux/task_work.h>
14819 +#include <linux/vs_cvirt.h>
14821 #include <trace/events/sched.h>
14823 @@ -1714,6 +1715,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14824 __enqueue_entity(cfs_rq, se);
14827 + if (entity_is_task(se))
14828 + vx_activate_task(task_of(se));
14829 if (cfs_rq->nr_running == 1) {
14830 list_add_leaf_cfs_rq(cfs_rq);
14831 check_enqueue_throttle(cfs_rq);
14832 @@ -1795,6 +1798,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14833 if (se != cfs_rq->curr)
14834 __dequeue_entity(cfs_rq, se);
14836 + if (entity_is_task(se))
14837 + vx_deactivate_task(task_of(se));
14838 account_entity_dequeue(cfs_rq, se);
14841 diff -NurpP --minimal linux-3.9.4/kernel/signal.c linux-3.9.4-vs2.3.6.2/kernel/signal.c
14842 --- linux-3.9.4/kernel/signal.c 2013-05-31 13:45:30.000000000 +0000
14843 +++ linux-3.9.4-vs2.3.6.2/kernel/signal.c 2013-05-31 15:20:05.000000000 +0000
14845 #include <linux/user_namespace.h>
14846 #include <linux/uprobes.h>
14847 #include <linux/compat.h>
14848 +#include <linux/vs_context.h>
14849 +#include <linux/vs_pid.h>
14850 #define CREATE_TRACE_POINTS
14851 #include <trace/events/signal.h>
14853 @@ -789,9 +791,18 @@ static int check_kill_permission(int sig
14857 + vxdprintk(VXD_CBIT(misc, 7),
14858 + "check_kill_permission(%d,%p,%p[#%u,%u])",
14859 + sig, info, t, vx_task_xid(t), t->pid);
14861 if (!valid_signal(sig))
14864 +/* FIXME: needed? if so, why?
14865 + if ((info != SEND_SIG_NOINFO) &&
14866 + (is_si_special(info) || !si_fromuser(info)))
14869 if (!si_fromuser(info))
14872 @@ -815,6 +826,20 @@ static int check_kill_permission(int sig
14877 + if (t->pid == 1 && current->xid)
14881 + /* FIXME: we shouldn't return ESRCH ever, to avoid
14882 + loops, maybe ENOENT or EACCES? */
14883 + if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14884 + vxdprintk(current->xid || VXD_CBIT(misc, 7),
14885 + "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14886 + sig, info, t, vx_task_xid(t), t->pid, current->xid);
14890 return security_task_kill(t, info, sig, 0);
14893 @@ -1351,7 +1376,7 @@ int kill_pid_info(int sig, struct siginf
14896 p = pid_task(pid, PIDTYPE_PID);
14898 + if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14899 error = group_send_sig_info(sig, info, p);
14900 if (unlikely(error == -ESRCH))
14902 @@ -1399,7 +1424,7 @@ int kill_pid_info_as_cred(int sig, struc
14905 p = pid_task(pid, PIDTYPE_PID);
14907 + if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14911 @@ -1451,8 +1476,10 @@ static int kill_something_info(int sig,
14912 struct task_struct * p;
14914 for_each_process(p) {
14915 - if (task_pid_vnr(p) > 1 &&
14916 - !same_thread_group(p, current)) {
14917 + if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14918 + task_pid_vnr(p) > 1 &&
14919 + !same_thread_group(p, current) &&
14920 + !vx_current_initpid(p->pid)) {
14921 int err = group_send_sig_info(sig, info, p);
14924 @@ -2306,6 +2333,11 @@ relock:
14925 !sig_kernel_only(signr))
14928 + /* virtual init is protected against user signals */
14929 + if ((info->si_code == SI_USER) &&
14930 + vx_current_initpid(current->pid))
14933 if (sig_kernel_stop(signr)) {
14935 * The default action is to stop all threads in
14936 diff -NurpP --minimal linux-3.9.4/kernel/softirq.c linux-3.9.4-vs2.3.6.2/kernel/softirq.c
14937 --- linux-3.9.4/kernel/softirq.c 2013-05-31 13:45:30.000000000 +0000
14938 +++ linux-3.9.4-vs2.3.6.2/kernel/softirq.c 2013-05-31 14:47:11.000000000 +0000
14940 #include <linux/smp.h>
14941 #include <linux/smpboot.h>
14942 #include <linux/tick.h>
14943 +#include <linux/vs_context.h>
14945 #define CREATE_TRACE_POINTS
14946 #include <trace/events/irq.h>
14947 diff -NurpP --minimal linux-3.9.4/kernel/sys.c linux-3.9.4-vs2.3.6.2/kernel/sys.c
14948 --- linux-3.9.4/kernel/sys.c 2013-05-31 13:45:30.000000000 +0000
14949 +++ linux-3.9.4-vs2.3.6.2/kernel/sys.c 2013-05-31 15:23:14.000000000 +0000
14951 #include <linux/binfmts.h>
14953 #include <linux/kmsg_dump.h>
14954 +#include <linux/vs_pid.h>
14955 /* Move somewhere else to avoid recompiling? */
14956 #include <generated/utsrelease.h>
14958 @@ -155,7 +156,10 @@ static int set_one_prio(struct task_stru
14961 if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14963 + if (vx_flags(VXF_IGNEG_NICE, 0))
14969 no_nice = security_task_setnice(p, niceval);
14970 @@ -206,6 +210,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14972 pgrp = task_pgrp(current);
14973 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14974 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14976 error = set_one_prio(p, niceval, error);
14977 } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14979 @@ -271,6 +277,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14981 pgrp = task_pgrp(current);
14982 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14983 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14985 niceval = 20 - task_nice(p);
14986 if (niceval > retval)
14988 @@ -424,6 +432,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
14990 static DEFINE_MUTEX(reboot_mutex);
14992 +long vs_reboot(unsigned int, void __user *);
14995 * Reboot system call: for obvious reasons only root may call it,
14996 * and even root needs to set up some magic numbers in the registers
14997 @@ -466,6 +476,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
14998 if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
14999 cmd = LINUX_REBOOT_CMD_HALT;
15001 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
15002 + return vs_reboot(cmd, arg);
15004 mutex_lock(&reboot_mutex);
15006 case LINUX_REBOOT_CMD_RESTART:
15007 @@ -1373,7 +1386,8 @@ SYSCALL_DEFINE2(sethostname, char __user
15009 char tmp[__NEW_UTS_LEN];
15011 - if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15012 + if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15013 + CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15016 if (len < 0 || len > __NEW_UTS_LEN)
15017 @@ -1424,7 +1438,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
15019 char tmp[__NEW_UTS_LEN];
15021 - if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
15022 + if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
15023 + CAP_SYS_ADMIN, VXC_SET_UTSNAME))
15025 if (len < 0 || len > __NEW_UTS_LEN)
15027 @@ -1543,7 +1558,7 @@ int do_prlimit(struct task_struct *tsk,
15028 /* Keep the capable check against init_user_ns until
15029 cgroups can contain all limits */
15030 if (new_rlim->rlim_max > rlim->rlim_max &&
15031 - !capable(CAP_SYS_RESOURCE))
15032 + !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15035 retval = security_task_setrlimit(tsk->group_leader,
15036 @@ -1596,7 +1611,8 @@ static int check_prlimit_permission(stru
15037 gid_eq(cred->gid, tcred->sgid) &&
15038 gid_eq(cred->gid, tcred->gid))
15040 - if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
15041 + if (vx_ns_capable(tcred->user_ns,
15042 + CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
15046 diff -NurpP --minimal linux-3.9.4/kernel/sysctl.c linux-3.9.4-vs2.3.6.2/kernel/sysctl.c
15047 --- linux-3.9.4/kernel/sysctl.c 2013-05-31 13:45:30.000000000 +0000
15048 +++ linux-3.9.4-vs2.3.6.2/kernel/sysctl.c 2013-05-31 15:28:39.000000000 +0000
15050 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
15051 #include <linux/lockdep.h>
15053 +extern char vshelper_path[];
15054 #ifdef CONFIG_CHR_DEV_SG
15055 #include <scsi/sg.h>
15057 @@ -629,6 +630,13 @@ static struct ctl_table kern_table[] = {
15059 .proc_handler = proc_dostring,
15062 + .procname = "vshelper",
15063 + .data = &vshelper_path,
15066 + .proc_handler = &proc_dostring,
15069 #ifdef CONFIG_CHR_DEV_SG
15071 diff -NurpP --minimal linux-3.9.4/kernel/sysctl_binary.c linux-3.9.4-vs2.3.6.2/kernel/sysctl_binary.c
15072 --- linux-3.9.4/kernel/sysctl_binary.c 2013-05-31 13:45:30.000000000 +0000
15073 +++ linux-3.9.4-vs2.3.6.2/kernel/sysctl_binary.c 2013-05-31 14:47:11.000000000 +0000
15074 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
15076 { CTL_INT, KERN_PANIC, "panic" },
15077 { CTL_INT, KERN_REALROOTDEV, "real-root-dev" },
15078 + { CTL_STR, KERN_VSHELPER, "vshelper" },
15080 { CTL_STR, KERN_SPARC_REBOOT, "reboot-cmd" },
15081 { CTL_INT, KERN_CTLALTDEL, "ctrl-alt-del" },
15082 diff -NurpP --minimal linux-3.9.4/kernel/time/timekeeping.c linux-3.9.4-vs2.3.6.2/kernel/time/timekeeping.c
15083 --- linux-3.9.4/kernel/time/timekeeping.c 2013-05-31 13:45:30.000000000 +0000
15084 +++ linux-3.9.4-vs2.3.6.2/kernel/time/timekeeping.c 2013-05-31 15:24:55.000000000 +0000
15086 #include <linux/tick.h>
15087 #include <linux/stop_machine.h>
15088 #include <linux/pvclock_gtod.h>
15089 +#include <linux/vs_time.h>
15092 static struct timekeeper timekeeper;
15093 @@ -594,6 +595,7 @@ void getrawmonotonic(struct timespec *ts
15094 } while (read_seqretry(&tk->lock, seq));
15096 timespec_add_ns(ts, nsecs);
15097 + vx_adjust_timespec(ts);
15099 EXPORT_SYMBOL(getrawmonotonic);
15101 diff -NurpP --minimal linux-3.9.4/kernel/time.c linux-3.9.4-vs2.3.6.2/kernel/time.c
15102 --- linux-3.9.4/kernel/time.c 2013-05-31 13:45:30.000000000 +0000
15103 +++ linux-3.9.4-vs2.3.6.2/kernel/time.c 2013-05-31 14:47:11.000000000 +0000
15105 #include <linux/fs.h>
15106 #include <linux/math64.h>
15107 #include <linux/ptrace.h>
15108 +#include <linux/vs_time.h>
15110 #include <asm/uaccess.h>
15111 #include <asm/unistd.h>
15112 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
15116 - do_settimeofday(&tv);
15117 + vx_settimeofday(&tv);
15121 @@ -180,7 +181,7 @@ int do_sys_settimeofday(const struct tim
15125 - return do_settimeofday(tv);
15126 + return vx_settimeofday(tv);
15130 diff -NurpP --minimal linux-3.9.4/kernel/timer.c linux-3.9.4-vs2.3.6.2/kernel/timer.c
15131 --- linux-3.9.4/kernel/timer.c 2013-05-31 14:22:27.000000000 +0000
15132 +++ linux-3.9.4-vs2.3.6.2/kernel/timer.c 2013-05-31 14:47:11.000000000 +0000
15134 #include <linux/sched.h>
15135 #include <linux/sched/sysctl.h>
15136 #include <linux/slab.h>
15137 +#include <linux/vs_base.h>
15138 +#include <linux/vs_cvirt.h>
15139 +#include <linux/vs_pid.h>
15140 +#include <linux/vserver/sched.h>
15142 #include <asm/uaccess.h>
15143 #include <asm/unistd.h>
15144 diff -NurpP --minimal linux-3.9.4/kernel/user_namespace.c linux-3.9.4-vs2.3.6.2/kernel/user_namespace.c
15145 --- linux-3.9.4/kernel/user_namespace.c 2013-05-31 13:45:30.000000000 +0000
15146 +++ linux-3.9.4-vs2.3.6.2/kernel/user_namespace.c 2013-05-31 17:44:56.000000000 +0000
15148 #include <linux/ctype.h>
15149 #include <linux/projid.h>
15150 #include <linux/fs_struct.h>
15151 +#include <linux/vserver/global.h>
15153 static struct kmem_cache *user_ns_cachep __read_mostly;
15155 @@ -91,6 +92,7 @@ int create_user_ns(struct cred *new)
15157 atomic_set(&ns->count, 1);
15158 /* Leave the new->user_ns reference with the new user namespace. */
15159 + atomic_inc(&vs_global_user_ns);
15160 ns->parent = parent_ns;
15163 @@ -835,6 +837,8 @@ static void *userns_get(struct task_stru
15165 static void userns_put(void *ns)
15167 + /* FIXME: maybe move into destroyer? */
15168 + atomic_dec(&vs_global_user_ns);
15172 diff -NurpP --minimal linux-3.9.4/kernel/utsname.c linux-3.9.4-vs2.3.6.2/kernel/utsname.c
15173 --- linux-3.9.4/kernel/utsname.c 2013-05-31 13:45:30.000000000 +0000
15174 +++ linux-3.9.4-vs2.3.6.2/kernel/utsname.c 2013-05-31 15:15:55.000000000 +0000
15175 @@ -16,14 +16,17 @@
15176 #include <linux/slab.h>
15177 #include <linux/user_namespace.h>
15178 #include <linux/proc_fs.h>
15179 +#include <linux/vserver/global.h>
15181 static struct uts_namespace *create_uts_ns(void)
15183 struct uts_namespace *uts_ns;
15185 uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
15188 kref_init(&uts_ns->kref);
15189 + atomic_inc(&vs_global_uts_ns);
15194 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
15195 ns = container_of(kref, struct uts_namespace, kref);
15196 put_user_ns(ns->user_ns);
15197 proc_free_inum(ns->proc_inum);
15198 + atomic_dec(&vs_global_uts_ns);
15202 diff -NurpP --minimal linux-3.9.4/kernel/vserver/Kconfig linux-3.9.4-vs2.3.6.2/kernel/vserver/Kconfig
15203 --- linux-3.9.4/kernel/vserver/Kconfig 1970-01-01 00:00:00.000000000 +0000
15204 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/Kconfig 2013-05-31 14:47:11.000000000 +0000
15207 +# Linux VServer configuration
15210 +menu "Linux VServer"
15212 +config VSERVER_AUTO_LBACK
15213 + bool "Automatically Assign Loopback IP"
15216 + Automatically assign a guest specific loopback
15217 + IP and add it to the kernel network stack on
15220 +config VSERVER_AUTO_SINGLE
15221 + bool "Automatic Single IP Special Casing"
15222 + depends on EXPERIMENTAL
15225 + This allows network contexts with a single IP to
15226 + automatically remap 0.0.0.0 bindings to that IP,
15227 + avoiding further network checks and improving
15230 + (note: such guests do not allow to change the ip
15231 + on the fly and do not show loopback addresses)
15233 +config VSERVER_COWBL
15234 + bool "Enable COW Immutable Link Breaking"
15237 + This enables the COW (Copy-On-Write) link break code.
15238 + It allows you to treat unified files like normal files
15239 + when writing to them (which will implicitely break the
15240 + link and create a copy of the unified file)
15242 +config VSERVER_VTIME
15243 + bool "Enable Virtualized Guest Time"
15244 + depends on EXPERIMENTAL
15247 + This enables per guest time offsets to allow for
15248 + adjusting the system clock individually per guest.
15249 + this adds some overhead to the time functions and
15250 + therefore should not be enabled without good reason.
15252 +config VSERVER_DEVICE
15253 + bool "Enable Guest Device Mapping"
15254 + depends on EXPERIMENTAL
15257 + This enables generic device remapping.
15259 +config VSERVER_PROC_SECURE
15260 + bool "Enable Proc Security"
15261 + depends on PROC_FS
15264 + This configures ProcFS security to initially hide
15265 + non-process entries for all contexts except the main and
15266 + spectator context (i.e. for all guests), which is a secure
15269 + (note: on 1.2x the entries were visible by default)
15272 + prompt "Persistent Inode Tagging"
15273 + default TAGGING_ID24
15275 + This adds persistent context information to filesystems
15276 + mounted with the tagxid option. Tagging is a requirement
15277 + for per-context disk limits and per-context quota.
15280 +config TAGGING_NONE
15283 + do not store per-context information in inodes.
15285 +config TAGGING_UID16
15286 + bool "UID16/GID32"
15288 + reduces UID to 16 bit, but leaves GID at 32 bit.
15290 +config TAGGING_GID16
15291 + bool "UID32/GID16"
15293 + reduces GID to 16 bit, but leaves UID at 32 bit.
15295 +config TAGGING_ID24
15296 + bool "UID24/GID24"
15298 + uses the upper 8bit from UID and GID for XID tagging
15299 + which leaves 24bit for UID/GID each, which should be
15300 + more than sufficient for normal use.
15302 +config TAGGING_INTERN
15303 + bool "UID32/GID32"
15305 + this uses otherwise reserved inode fields in the on
15306 + disk representation, which limits the use to a few
15307 + filesystems (currently ext2 and ext3)
15312 + bool "Tag NFSD User Auth and Files"
15315 + Enable this if you do want the in-kernel NFS
15316 + Server to use the tagging specified above.
15317 + (will require patched clients too)
15319 +config VSERVER_PRIVACY
15320 + bool "Honor Privacy Aspects of Guests"
15323 + When enabled, most context checks will disallow
15324 + access to structures assigned to a specific context,
15325 + like ptys or loop devices.
15327 +config VSERVER_CONTEXTS
15328 + int "Maximum number of Contexts (1-65533)" if EMBEDDED
15330 + default "768" if 64BIT
15333 + This setting will optimize certain data structures
15334 + and memory allocations according to the expected
15337 + note: this is not a strict upper limit.
15339 +config VSERVER_WARN
15340 + bool "VServer Warnings"
15343 + This enables various runtime warnings, which will
15344 + notify about potential manipulation attempts or
15345 + resource shortage. It is generally considered to
15346 + be a good idea to have that enabled.
15348 +config VSERVER_WARN_DEVPTS
15349 + bool "VServer DevPTS Warnings"
15350 + depends on VSERVER_WARN
15353 + This enables DevPTS related warnings, issued when a
15354 + process inside a context tries to lookup or access
15355 + a dynamic pts from the host or a different context.
15357 +config VSERVER_DEBUG
15358 + bool "VServer Debugging Code"
15361 + Set this to yes if you want to be able to activate
15362 + debugging output at runtime. It adds a very small
15363 + overhead to all vserver related functions and
15364 + increases the kernel size by about 20k.
15366 +config VSERVER_HISTORY
15367 + bool "VServer History Tracing"
15368 + depends on VSERVER_DEBUG
15371 + Set this to yes if you want to record the history of
15372 + linux-vserver activities, so they can be replayed in
15373 + the event of a kernel panic or oops.
15375 +config VSERVER_HISTORY_SIZE
15376 + int "Per-CPU History Size (32-65536)"
15377 + depends on VSERVER_HISTORY
15381 + This allows you to specify the number of entries in
15382 + the per-CPU history buffer.
15384 +config VSERVER_EXTRA_MNT_CHECK
15385 + bool "Extra Checks for Reachability"
15388 + Set this to yes if you want to do extra checks for
15389 + vfsmount reachability in the proc filesystem code.
15390 + This shouldn't be required on any setup utilizing
15394 + prompt "Quotes used in debug and warn messages"
15395 + default QUOTES_ISO8859
15397 +config QUOTES_ISO8859
15398 + bool "Extended ASCII (ISO 8859) angle quotes"
15400 + This uses the extended ASCII characters \xbb
15401 + and \xab for quoting file and process names.
15403 +config QUOTES_UTF8
15404 + bool "UTF-8 angle quotes"
15406 + This uses the the UTF-8 sequences for angle
15407 + quotes to quote file and process names.
15409 +config QUOTES_ASCII
15410 + bool "ASCII single quotes"
15412 + This uses the ASCII single quote character
15413 + (\x27) to quote file and process names.
15423 + select NAMESPACES
15429 +config VSERVER_SECURITY
15431 + depends on SECURITY
15433 + select SECURITY_CAPABILITIES
15435 +config VSERVER_DISABLED
15439 diff -NurpP --minimal linux-3.9.4/kernel/vserver/Makefile linux-3.9.4-vs2.3.6.2/kernel/vserver/Makefile
15440 --- linux-3.9.4/kernel/vserver/Makefile 1970-01-01 00:00:00.000000000 +0000
15441 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/Makefile 2013-05-31 14:47:11.000000000 +0000
15444 +# Makefile for the Linux vserver routines.
15448 +obj-y += vserver.o
15450 +vserver-y := switch.o context.o space.o sched.o network.o inode.o \
15451 + limit.o cvirt.o cacct.o signal.o helper.o init.o \
15454 +vserver-$(CONFIG_INET) += inet.o
15455 +vserver-$(CONFIG_PROC_FS) += proc.o
15456 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
15457 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
15458 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
15459 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
15461 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct.c linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct.c
15462 --- linux-3.9.4/kernel/vserver/cacct.c 1970-01-01 00:00:00.000000000 +0000
15463 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct.c 2013-05-31 14:47:11.000000000 +0000
15466 + * linux/kernel/vserver/cacct.c
15468 + * Virtual Server: Context Accounting
15470 + * Copyright (C) 2006-2007 Herbert Pötzl
15472 + * V0.01 added accounting stats
15476 +#include <linux/types.h>
15477 +#include <linux/vs_context.h>
15478 +#include <linux/vserver/cacct_cmd.h>
15479 +#include <linux/vserver/cacct_int.h>
15481 +#include <asm/errno.h>
15482 +#include <asm/uaccess.h>
15485 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
15487 + struct vcmd_sock_stat_v0 vc_data;
15490 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15493 + field = vc_data.field;
15494 + if ((field < 0) || (field >= VXA_SOCK_SIZE))
15497 + for (j = 0; j < 3; j++) {
15498 + vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
15499 + vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
15502 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15507 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct_init.h linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct_init.h
15508 --- linux-3.9.4/kernel/vserver/cacct_init.h 1970-01-01 00:00:00.000000000 +0000
15509 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct_init.h 2013-05-31 14:47:11.000000000 +0000
15513 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
15518 + for (i = 0; i < VXA_SOCK_SIZE; i++) {
15519 + for (j = 0; j < 3; j++) {
15520 + atomic_long_set(&cacct->sock[i][j].count, 0);
15521 + atomic_long_set(&cacct->sock[i][j].total, 0);
15524 + for (i = 0; i < 8; i++)
15525 + atomic_set(&cacct->slab[i], 0);
15526 + for (i = 0; i < 5; i++)
15527 + for (j = 0; j < 4; j++)
15528 + atomic_set(&cacct->page[i][j], 0);
15531 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
15536 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cacct_proc.h linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct_proc.h
15537 --- linux-3.9.4/kernel/vserver/cacct_proc.h 1970-01-01 00:00:00.000000000 +0000
15538 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cacct_proc.h 2013-05-31 14:47:11.000000000 +0000
15540 +#ifndef _VX_CACCT_PROC_H
15541 +#define _VX_CACCT_PROC_H
15543 +#include <linux/vserver/cacct_int.h>
15546 +#define VX_SOCKA_TOP \
15547 + "Type\t recv #/bytes\t\t send #/bytes\t\t fail #/bytes\n"
15549 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
15551 + int i, j, length = 0;
15552 + static char *type[VXA_SOCK_SIZE] = {
15553 + "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
15556 + length += sprintf(buffer + length, VX_SOCKA_TOP);
15557 + for (i = 0; i < VXA_SOCK_SIZE; i++) {
15558 + length += sprintf(buffer + length, "%s:", type[i]);
15559 + for (j = 0; j < 3; j++) {
15560 + length += sprintf(buffer + length,
15561 + "\t%10lu/%-10lu",
15562 + vx_sock_count(cacct, i, j),
15563 + vx_sock_total(cacct, i, j));
15565 + buffer[length++] = '\n';
15568 + length += sprintf(buffer + length, "\n");
15569 + length += sprintf(buffer + length,
15570 + "slab:\t %8u %8u %8u %8u\n",
15571 + atomic_read(&cacct->slab[1]),
15572 + atomic_read(&cacct->slab[4]),
15573 + atomic_read(&cacct->slab[0]),
15574 + atomic_read(&cacct->slab[2]));
15576 + length += sprintf(buffer + length, "\n");
15577 + for (i = 0; i < 5; i++) {
15578 + length += sprintf(buffer + length,
15579 + "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
15580 + atomic_read(&cacct->page[i][0]),
15581 + atomic_read(&cacct->page[i][1]),
15582 + atomic_read(&cacct->page[i][2]),
15583 + atomic_read(&cacct->page[i][3]),
15584 + atomic_read(&cacct->page[i][4]),
15585 + atomic_read(&cacct->page[i][5]),
15586 + atomic_read(&cacct->page[i][6]),
15587 + atomic_read(&cacct->page[i][7]));
15592 +#endif /* _VX_CACCT_PROC_H */
15593 diff -NurpP --minimal linux-3.9.4/kernel/vserver/context.c linux-3.9.4-vs2.3.6.2/kernel/vserver/context.c
15594 --- linux-3.9.4/kernel/vserver/context.c 1970-01-01 00:00:00.000000000 +0000
15595 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/context.c 2013-05-31 19:34:32.000000000 +0000
15598 + * linux/kernel/vserver/context.c
15600 + * Virtual Server: Context Support
15602 + * Copyright (C) 2003-2011 Herbert Pötzl
15604 + * V0.01 context helper
15605 + * V0.02 vx_ctx_kill syscall command
15606 + * V0.03 replaced context_info calls
15607 + * V0.04 redesign of struct (de)alloc
15608 + * V0.05 rlimit basic implementation
15609 + * V0.06 task_xid and info commands
15610 + * V0.07 context flags and caps
15611 + * V0.08 switch to RCU based hash
15612 + * V0.09 revert to non RCU for now
15613 + * V0.10 and back to working RCU hash
15614 + * V0.11 and back to locking again
15615 + * V0.12 referenced context store
15616 + * V0.13 separate per cpu data
15617 + * V0.14 changed vcmds to vxi arg
15618 + * V0.15 added context stat
15619 + * V0.16 have __create claim() the vxi
15620 + * V0.17 removed older and legacy stuff
15621 + * V0.18 added user credentials
15622 + * V0.19 added warn mask
15626 +#include <linux/slab.h>
15627 +#include <linux/types.h>
15628 +#include <linux/security.h>
15629 +#include <linux/pid_namespace.h>
15630 +#include <linux/capability.h>
15632 +#include <linux/vserver/context.h>
15633 +#include <linux/vserver/network.h>
15634 +#include <linux/vserver/debug.h>
15635 +#include <linux/vserver/limit.h>
15636 +#include <linux/vserver/limit_int.h>
15637 +#include <linux/vserver/space.h>
15638 +#include <linux/init_task.h>
15639 +#include <linux/fs_struct.h>
15640 +#include <linux/cred.h>
15642 +#include <linux/vs_context.h>
15643 +#include <linux/vs_limit.h>
15644 +#include <linux/vs_pid.h>
15645 +#include <linux/vserver/context_cmd.h>
15647 +#include "cvirt_init.h"
15648 +#include "cacct_init.h"
15649 +#include "limit_init.h"
15650 +#include "sched_init.h"
15653 +atomic_t vx_global_ctotal = ATOMIC_INIT(0);
15654 +atomic_t vx_global_cactive = ATOMIC_INIT(0);
15657 +/* now inactive context structures */
15659 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
15661 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
15664 +/* __alloc_vx_info()
15666 + * allocate an initialized vx_info struct
15667 + * doesn't make it visible (hash) */
15669 +static struct vx_info *__alloc_vx_info(xid_t xid)
15671 + struct vx_info *new = NULL;
15674 + vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
15676 + /* would this benefit from a slab cache? */
15677 + new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
15681 + memset(new, 0, sizeof(struct vx_info));
15683 + new->ptr_pc = alloc_percpu(struct _vx_info_pc);
15684 + if (!new->ptr_pc)
15687 + new->vx_id = xid;
15688 + INIT_HLIST_NODE(&new->vx_hlist);
15689 + atomic_set(&new->vx_usecnt, 0);
15690 + atomic_set(&new->vx_tasks, 0);
15691 + new->vx_parent = NULL;
15692 + new->vx_state = 0;
15693 + init_waitqueue_head(&new->vx_wait);
15695 + /* prepare reaper */
15696 + get_task_struct(init_pid_ns.child_reaper);
15697 + new->vx_reaper = init_pid_ns.child_reaper;
15698 + new->vx_badness_bias = 0;
15700 + /* rest of init goes here */
15701 + vx_info_init_limit(&new->limit);
15702 + vx_info_init_sched(&new->sched);
15703 + vx_info_init_cvirt(&new->cvirt);
15704 + vx_info_init_cacct(&new->cacct);
15706 + /* per cpu data structures */
15707 + for_each_possible_cpu(cpu) {
15708 + vx_info_init_sched_pc(
15709 + &vx_per_cpu(new, sched_pc, cpu), cpu);
15710 + vx_info_init_cvirt_pc(
15711 + &vx_per_cpu(new, cvirt_pc, cpu), cpu);
15714 + new->vx_flags = VXF_INIT_SET;
15715 + new->vx_bcaps = CAP_FULL_SET; // maybe ~CAP_SETPCAP
15716 + new->vx_ccaps = 0;
15717 + new->vx_umask = 0;
15718 + new->vx_wmask = 0;
15720 + new->reboot_cmd = 0;
15721 + new->exit_code = 0;
15723 + // preconfig spaces
15724 + for (index = 0; index < VX_SPACES; index++) {
15725 + struct _vx_space *space = &new->space[index];
15728 + spin_lock(&init_fs.lock);
15730 + spin_unlock(&init_fs.lock);
15731 + space->vx_fs = &init_fs;
15733 + /* FIXME: do we want defaults? */
15734 + // space->vx_real_cred = 0;
15735 + // space->vx_cred = 0;
15739 + vxdprintk(VXD_CBIT(xid, 0),
15740 + "alloc_vx_info(%d) = %p", xid, new);
15741 + vxh_alloc_vx_info(new);
15742 + atomic_inc(&vx_global_ctotal);
15751 +/* __dealloc_vx_info()
15753 + * final disposal of vx_info */
15755 +static void __dealloc_vx_info(struct vx_info *vxi)
15757 +#ifdef CONFIG_VSERVER_WARN
15758 + struct vx_info_save vxis;
15761 + vxdprintk(VXD_CBIT(xid, 0),
15762 + "dealloc_vx_info(%p)", vxi);
15763 + vxh_dealloc_vx_info(vxi);
15765 +#ifdef CONFIG_VSERVER_WARN
15766 + enter_vx_info(vxi, &vxis);
15767 + vx_info_exit_limit(&vxi->limit);
15768 + vx_info_exit_sched(&vxi->sched);
15769 + vx_info_exit_cvirt(&vxi->cvirt);
15770 + vx_info_exit_cacct(&vxi->cacct);
15772 + for_each_possible_cpu(cpu) {
15773 + vx_info_exit_sched_pc(
15774 + &vx_per_cpu(vxi, sched_pc, cpu), cpu);
15775 + vx_info_exit_cvirt_pc(
15776 + &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
15778 + leave_vx_info(&vxis);
15782 + vxi->vx_state |= VXS_RELEASED;
15785 + free_percpu(vxi->ptr_pc);
15788 + atomic_dec(&vx_global_ctotal);
15791 +static void __shutdown_vx_info(struct vx_info *vxi)
15793 + struct nsproxy *nsproxy;
15794 + struct fs_struct *fs;
15795 + struct cred *cred;
15800 + vxi->vx_state |= VXS_SHUTDOWN;
15801 + vs_state_change(vxi, VSC_SHUTDOWN);
15803 + for (index = 0; index < VX_SPACES; index++) {
15804 + struct _vx_space *space = &vxi->space[index];
15806 + nsproxy = xchg(&space->vx_nsproxy, NULL);
15808 + put_nsproxy(nsproxy);
15810 + fs = xchg(&space->vx_fs, NULL);
15811 + spin_lock(&fs->lock);
15812 + kill = !--fs->users;
15813 + spin_unlock(&fs->lock);
15815 + free_fs_struct(fs);
15817 + cred = (struct cred *)xchg(&space->vx_cred, NULL);
15819 + abort_creds(cred);
15823 +/* exported stuff */
15825 +void free_vx_info(struct vx_info *vxi)
15827 + unsigned long flags;
15830 + /* check for reference counts first */
15831 + BUG_ON(atomic_read(&vxi->vx_usecnt));
15832 + BUG_ON(atomic_read(&vxi->vx_tasks));
15834 + /* context must not be hashed */
15835 + BUG_ON(vx_info_state(vxi, VXS_HASHED));
15837 + /* context shutdown is mandatory */
15838 + BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15840 + /* spaces check */
15841 + for (index = 0; index < VX_SPACES; index++) {
15842 + struct _vx_space *space = &vxi->space[index];
15844 + BUG_ON(space->vx_nsproxy);
15845 + BUG_ON(space->vx_fs);
15846 + // BUG_ON(space->vx_real_cred);
15847 + // BUG_ON(space->vx_cred);
15850 + spin_lock_irqsave(&vx_info_inactive_lock, flags);
15851 + hlist_del(&vxi->vx_hlist);
15852 + spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15854 + __dealloc_vx_info(vxi);
15858 +/* hash table for vx_info hash */
15860 +#define VX_HASH_SIZE 13
15862 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15863 + { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15865 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15868 +static inline unsigned int __hashval(xid_t xid)
15870 + return (xid % VX_HASH_SIZE);
15875 +/* __hash_vx_info()
15877 + * add the vxi to the global hash table
15878 + * requires the hash_lock to be held */
15880 +static inline void __hash_vx_info(struct vx_info *vxi)
15882 + struct hlist_head *head;
15884 + vxd_assert_lock(&vx_info_hash_lock);
15885 + vxdprintk(VXD_CBIT(xid, 4),
15886 + "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15887 + vxh_hash_vx_info(vxi);
15889 + /* context must not be hashed */
15890 + BUG_ON(vx_info_state(vxi, VXS_HASHED));
15892 + vxi->vx_state |= VXS_HASHED;
15893 + head = &vx_info_hash[__hashval(vxi->vx_id)];
15894 + hlist_add_head(&vxi->vx_hlist, head);
15895 + atomic_inc(&vx_global_cactive);
15898 +/* __unhash_vx_info()
15900 + * remove the vxi from the global hash table
15901 + * requires the hash_lock to be held */
15903 +static inline void __unhash_vx_info(struct vx_info *vxi)
15905 + unsigned long flags;
15907 + vxd_assert_lock(&vx_info_hash_lock);
15908 + vxdprintk(VXD_CBIT(xid, 4),
15909 + "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15910 + atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15911 + vxh_unhash_vx_info(vxi);
15913 + /* context must be hashed */
15914 + BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15915 + /* but without tasks */
15916 + BUG_ON(atomic_read(&vxi->vx_tasks));
15918 + vxi->vx_state &= ~VXS_HASHED;
15919 + hlist_del_init(&vxi->vx_hlist);
15920 + spin_lock_irqsave(&vx_info_inactive_lock, flags);
15921 + hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15922 + spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15923 + atomic_dec(&vx_global_cactive);
15927 +/* __lookup_vx_info()
15929 + * requires the hash_lock to be held
15930 + * doesn't increment the vx_refcnt */
15932 +static inline struct vx_info *__lookup_vx_info(xid_t xid)
15934 + struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15935 + struct hlist_node *pos;
15936 + struct vx_info *vxi;
15938 + vxd_assert_lock(&vx_info_hash_lock);
15939 + hlist_for_each(pos, head) {
15940 + vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15942 + if (vxi->vx_id == xid)
15947 + vxdprintk(VXD_CBIT(xid, 0),
15948 + "__lookup_vx_info(#%u): %p[#%u]",
15949 + xid, vxi, vxi ? vxi->vx_id : 0);
15950 + vxh_lookup_vx_info(vxi, xid);
15955 +/* __create_vx_info()
15957 + * create the requested context
15958 + * get(), claim() and hash it */
15960 +static struct vx_info *__create_vx_info(int id)
15962 + struct vx_info *new, *vxi = NULL;
15964 + vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15966 + if (!(new = __alloc_vx_info(id)))
15967 + return ERR_PTR(-ENOMEM);
15969 + /* required to make dynamic xids unique */
15970 + spin_lock(&vx_info_hash_lock);
15972 + /* static context requested */
15973 + if ((vxi = __lookup_vx_info(id))) {
15974 + vxdprintk(VXD_CBIT(xid, 0),
15975 + "create_vx_info(%d) = %p (already there)", id, vxi);
15976 + if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15977 + vxi = ERR_PTR(-EBUSY);
15979 + vxi = ERR_PTR(-EEXIST);
15982 + /* new context */
15983 + vxdprintk(VXD_CBIT(xid, 0),
15984 + "create_vx_info(%d) = %p (new)", id, new);
15985 + claim_vx_info(new, NULL);
15986 + __hash_vx_info(get_vx_info(new));
15987 + vxi = new, new = NULL;
15990 + spin_unlock(&vx_info_hash_lock);
15991 + vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15993 + __dealloc_vx_info(new);
15998 +/* exported stuff */
16001 +void unhash_vx_info(struct vx_info *vxi)
16003 + spin_lock(&vx_info_hash_lock);
16004 + __unhash_vx_info(vxi);
16005 + spin_unlock(&vx_info_hash_lock);
16006 + __shutdown_vx_info(vxi);
16007 + __wakeup_vx_info(vxi);
16011 +/* lookup_vx_info()
16013 + * search for a vx_info and get() it
16014 + * negative id means current */
16016 +struct vx_info *lookup_vx_info(int id)
16018 + struct vx_info *vxi = NULL;
16021 + vxi = get_vx_info(current_vx_info());
16022 + } else if (id > 1) {
16023 + spin_lock(&vx_info_hash_lock);
16024 + vxi = get_vx_info(__lookup_vx_info(id));
16025 + spin_unlock(&vx_info_hash_lock);
16030 +/* xid_is_hashed()
16032 + * verify that xid is still hashed */
16034 +int xid_is_hashed(xid_t xid)
16038 + spin_lock(&vx_info_hash_lock);
16039 + hashed = (__lookup_vx_info(xid) != NULL);
16040 + spin_unlock(&vx_info_hash_lock);
16044 +#ifdef CONFIG_PROC_FS
16048 + * get a subset of hashed xids for proc
16049 + * assumes size is at least one */
16051 +int get_xid_list(int index, unsigned int *xids, int size)
16053 + int hindex, nr_xids = 0;
16055 + /* only show current and children */
16056 + if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
16059 + xids[nr_xids] = vx_current_xid();
16063 + for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
16064 + struct hlist_head *head = &vx_info_hash[hindex];
16065 + struct hlist_node *pos;
16067 + spin_lock(&vx_info_hash_lock);
16068 + hlist_for_each(pos, head) {
16069 + struct vx_info *vxi;
16074 + vxi = hlist_entry(pos, struct vx_info, vx_hlist);
16075 + xids[nr_xids] = vxi->vx_id;
16076 + if (++nr_xids >= size) {
16077 + spin_unlock(&vx_info_hash_lock);
16081 + /* keep the lock time short */
16082 + spin_unlock(&vx_info_hash_lock);
16089 +#ifdef CONFIG_VSERVER_DEBUG
16091 +void dump_vx_info_inactive(int level)
16093 + struct hlist_node *entry, *next;
16095 + hlist_for_each_safe(entry, next, &vx_info_inactive) {
16096 + struct vx_info *vxi =
16097 + list_entry(entry, struct vx_info, vx_hlist);
16099 + dump_vx_info(vxi, level);
16106 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
16108 + struct user_struct *new_user, *old_user;
16113 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
16116 + new_user = alloc_uid(vxi->vx_id, p->uid);
16120 + old_user = p->user;
16121 + if (new_user != old_user) {
16122 + atomic_inc(&new_user->processes);
16123 + atomic_dec(&old_user->processes);
16124 + p->user = new_user;
16126 + free_uid(old_user);
16132 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
16134 + // p->cap_effective &= vxi->vx_cap_bset;
16135 + p->cap_effective =
16136 + cap_intersect(p->cap_effective, vxi->cap_bset);
16137 + // p->cap_inheritable &= vxi->vx_cap_bset;
16138 + p->cap_inheritable =
16139 + cap_intersect(p->cap_inheritable, vxi->cap_bset);
16140 + // p->cap_permitted &= vxi->vx_cap_bset;
16141 + p->cap_permitted =
16142 + cap_intersect(p->cap_permitted, vxi->cap_bset);
16147 +#include <linux/file.h>
16148 +#include <linux/fdtable.h>
16150 +static int vx_openfd_task(struct task_struct *tsk)
16152 + struct files_struct *files = tsk->files;
16153 + struct fdtable *fdt;
16154 + const unsigned long *bptr;
16155 + int count, total;
16157 + /* no rcu_read_lock() because of spin_lock() */
16158 + spin_lock(&files->file_lock);
16159 + fdt = files_fdtable(files);
16160 + bptr = fdt->open_fds;
16161 + count = fdt->max_fds / (sizeof(unsigned long) * 8);
16162 + for (total = 0; count > 0; count--) {
16164 + total += hweight_long(*bptr);
16167 + spin_unlock(&files->file_lock);
16172 +/* for *space compatibility */
16174 +asmlinkage long sys_unshare(unsigned long);
16177 + * migrate task to new context
16178 + * gets vxi, puts old_vxi on change
16179 + * optionally unshares namespaces (hack)
16182 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
16184 + struct vx_info *old_vxi;
16190 + vxdprintk(VXD_CBIT(xid, 5),
16191 + "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
16192 + vxi->vx_id, atomic_read(&vxi->vx_usecnt));
16194 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
16195 + !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
16198 + if (vx_info_state(vxi, VXS_SHUTDOWN))
16201 + old_vxi = task_get_vx_info(p);
16202 + if (old_vxi == vxi)
16205 +// if (!(ret = vx_migrate_user(p, vxi))) {
16210 + openfd = vx_openfd_task(p);
16213 + atomic_dec(&old_vxi->cvirt.nr_threads);
16214 + atomic_dec(&old_vxi->cvirt.nr_running);
16215 + __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
16216 + /* FIXME: what about the struct files here? */
16217 + __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
16218 + /* account for the executable */
16219 + __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
16221 + atomic_inc(&vxi->cvirt.nr_threads);
16222 + atomic_inc(&vxi->cvirt.nr_running);
16223 + __rlim_inc(&vxi->limit, RLIMIT_NPROC);
16224 + /* FIXME: what about the struct files here? */
16225 + __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
16226 + /* account for the executable */
16227 + __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
16230 + release_vx_info(old_vxi, p);
16231 + clr_vx_info(&p->vx_info);
16233 + claim_vx_info(vxi, p);
16234 + set_vx_info(&p->vx_info, vxi);
16235 + p->xid = vxi->vx_id;
16237 + vxdprintk(VXD_CBIT(xid, 5),
16238 + "moved task %p into vxi:%p[#%d]",
16239 + p, vxi, vxi->vx_id);
16241 + // vx_mask_cap_bset(vxi, p);
16244 + /* hack for *spaces to provide compatibility */
16246 + struct nsproxy *old_nsp, *new_nsp;
16248 + ret = unshare_nsproxy_namespaces(
16249 + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
16250 + &new_nsp, NULL, NULL);
16254 + old_nsp = xchg(&p->nsproxy, new_nsp);
16255 + vx_set_space(vxi,
16256 + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
16257 + put_nsproxy(old_nsp);
16261 + put_vx_info(old_vxi);
16265 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
16267 + struct task_struct *old_reaper;
16268 + struct vx_info *reaper_vxi;
16273 + vxdprintk(VXD_CBIT(xid, 6),
16274 + "vx_set_reaper(%p[#%d],%p[#%d,%d])",
16275 + vxi, vxi->vx_id, p, p->xid, p->pid);
16277 + old_reaper = vxi->vx_reaper;
16278 + if (old_reaper == p)
16281 + reaper_vxi = task_get_vx_info(p);
16282 + if (reaper_vxi && reaper_vxi != vxi) {
16284 + "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
16286 + p->comm, p->pid, p->xid, vx_current_xid());
16290 + /* set new child reaper */
16291 + get_task_struct(p);
16292 + vxi->vx_reaper = p;
16293 + put_task_struct(old_reaper);
16295 + put_vx_info(reaper_vxi);
16299 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
16304 + vxdprintk(VXD_CBIT(xid, 6),
16305 + "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
16306 + vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16308 + vxi->vx_flags &= ~VXF_STATE_INIT;
16309 + // vxi->vx_initpid = p->tgid;
16310 + vxi->vx_initpid = p->pid;
16314 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
16316 + vxdprintk(VXD_CBIT(xid, 6),
16317 + "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
16318 + vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
16320 + vxi->exit_code = code;
16321 + vxi->vx_initpid = 0;
16325 +void vx_set_persistent(struct vx_info *vxi)
16327 + vxdprintk(VXD_CBIT(xid, 6),
16328 + "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
16330 + get_vx_info(vxi);
16331 + claim_vx_info(vxi, NULL);
16334 +void vx_clear_persistent(struct vx_info *vxi)
16336 + vxdprintk(VXD_CBIT(xid, 6),
16337 + "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
16339 + release_vx_info(vxi, NULL);
16340 + put_vx_info(vxi);
16343 +void vx_update_persistent(struct vx_info *vxi)
16345 + if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
16346 + vx_set_persistent(vxi);
16348 + vx_clear_persistent(vxi);
16352 +/* task must be current or locked */
16354 +void exit_vx_info(struct task_struct *p, int code)
16356 + struct vx_info *vxi = p->vx_info;
16359 + atomic_dec(&vxi->cvirt.nr_threads);
16362 + vxi->exit_code = code;
16363 + release_vx_info(vxi, p);
16367 +void exit_vx_info_early(struct task_struct *p, int code)
16369 + struct vx_info *vxi = p->vx_info;
16372 + if (vxi->vx_initpid == p->pid)
16373 + vx_exit_init(vxi, p, code);
16374 + if (vxi->vx_reaper == p)
16375 + vx_set_reaper(vxi, init_pid_ns.child_reaper);
16380 +/* vserver syscall commands below here */
16382 +/* taks xid and vx_info functions */
16384 +#include <asm/uaccess.h>
16387 +int vc_task_xid(uint32_t id)
16392 + struct task_struct *tsk;
16395 + tsk = find_task_by_real_pid(id);
16396 + xid = (tsk) ? tsk->xid : -ESRCH;
16397 + rcu_read_unlock();
16399 + xid = vx_current_xid();
16404 +int vc_vx_info(struct vx_info *vxi, void __user *data)
16406 + struct vcmd_vx_info_v0 vc_data;
16408 + vc_data.xid = vxi->vx_id;
16409 + vc_data.initpid = vxi->vx_initpid;
16411 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16417 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
16419 + struct vcmd_ctx_stat_v0 vc_data;
16421 + vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
16422 + vc_data.tasks = atomic_read(&vxi->vx_tasks);
16424 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16430 +/* context functions */
16432 +int vc_ctx_create(uint32_t xid, void __user *data)
16434 + struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
16435 + struct vx_info *new_vxi;
16438 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16441 + if ((xid > MAX_S_CONTEXT) || (xid < 2))
16444 + new_vxi = __create_vx_info(xid);
16445 + if (IS_ERR(new_vxi))
16446 + return PTR_ERR(new_vxi);
16448 + /* initial flags */
16449 + new_vxi->vx_flags = vc_data.flagword;
16452 + if (vs_state_change(new_vxi, VSC_STARTUP))
16455 + ret = vx_migrate_task(current, new_vxi, (!data));
16459 + /* return context id on success */
16460 + ret = new_vxi->vx_id;
16462 + /* get a reference for persistent contexts */
16463 + if ((vc_data.flagword & VXF_PERSISTENT))
16464 + vx_set_persistent(new_vxi);
16466 + release_vx_info(new_vxi, NULL);
16467 + put_vx_info(new_vxi);
16472 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
16474 + struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
16477 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
16480 + ret = vx_migrate_task(current, vxi, 0);
16483 + if (vc_data.flagword & VXM_SET_INIT)
16484 + ret = vx_set_init(vxi, current);
16487 + if (vc_data.flagword & VXM_SET_REAPER)
16488 + ret = vx_set_reaper(vxi, current);
16493 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
16495 + struct vcmd_ctx_flags_v0 vc_data;
16497 + vc_data.flagword = vxi->vx_flags;
16499 + /* special STATE flag handling */
16500 + vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
16502 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16507 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
16509 + struct vcmd_ctx_flags_v0 vc_data;
16510 + uint64_t mask, trigger;
16512 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16515 + /* special STATE flag handling */
16516 + mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
16517 + trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
16519 + if (vxi == current_vx_info()) {
16520 + /* if (trigger & VXF_STATE_SETUP)
16521 + vx_mask_cap_bset(vxi, current); */
16522 + if (trigger & VXF_STATE_INIT) {
16525 + ret = vx_set_init(vxi, current);
16528 + ret = vx_set_reaper(vxi, current);
16534 + vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
16535 + vc_data.flagword, mask);
16536 + if (trigger & VXF_PERSISTENT)
16537 + vx_update_persistent(vxi);
16543 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
16545 + uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
16547 + // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
16551 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
16553 + kernel_cap_t c = __cap_empty_set;
16555 + c.cap[0] = v & 0xFFFFFFFF;
16556 + c.cap[1] = (v >> 32) & 0xFFFFFFFF;
16558 + // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
16563 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
16566 + *bcaps = caps_from_cap_t(vxi->vx_bcaps);
16568 + *ccaps = vxi->vx_ccaps;
16573 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
16575 + struct vcmd_ctx_caps_v1 vc_data;
16578 + ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
16581 + vc_data.cmask = ~0ULL;
16583 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16588 +static int do_set_caps(struct vx_info *vxi,
16589 + uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
16591 + uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
16594 + printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
16595 + bcaps, bmask, ccaps, cmask);
16597 + vxi->vx_bcaps = cap_t_from_caps(
16598 + vs_mask_flags(bcold, bcaps, bmask));
16599 + vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
16604 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
16606 + struct vcmd_ctx_caps_v1 vc_data;
16608 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16611 + return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
16614 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
16616 + struct vcmd_bcaps vc_data;
16619 + ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
16622 + vc_data.bmask = ~0ULL;
16624 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16629 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
16631 + struct vcmd_bcaps vc_data;
16633 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16636 + return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
16640 +int vc_get_umask(struct vx_info *vxi, void __user *data)
16642 + struct vcmd_umask vc_data;
16644 + vc_data.umask = vxi->vx_umask;
16645 + vc_data.mask = ~0ULL;
16647 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16652 +int vc_set_umask(struct vx_info *vxi, void __user *data)
16654 + struct vcmd_umask vc_data;
16656 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16659 + vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
16660 + vc_data.umask, vc_data.mask);
16665 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
16667 + struct vcmd_wmask vc_data;
16669 + vc_data.wmask = vxi->vx_wmask;
16670 + vc_data.mask = ~0ULL;
16672 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16677 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
16679 + struct vcmd_wmask vc_data;
16681 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16684 + vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
16685 + vc_data.wmask, vc_data.mask);
16690 +int vc_get_badness(struct vx_info *vxi, void __user *data)
16692 + struct vcmd_badness_v0 vc_data;
16694 + vc_data.bias = vxi->vx_badness_bias;
16696 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16701 +int vc_set_badness(struct vx_info *vxi, void __user *data)
16703 + struct vcmd_badness_v0 vc_data;
16705 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16708 + vxi->vx_badness_bias = vc_data.bias;
16712 +#include <linux/module.h>
16714 +EXPORT_SYMBOL_GPL(free_vx_info);
16716 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt.c linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt.c
16717 --- linux-3.9.4/kernel/vserver/cvirt.c 1970-01-01 00:00:00.000000000 +0000
16718 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt.c 2013-05-31 14:47:11.000000000 +0000
16721 + * linux/kernel/vserver/cvirt.c
16723 + * Virtual Server: Context Virtualization
16725 + * Copyright (C) 2004-2007 Herbert Pötzl
16727 + * V0.01 broken out from limit.c
16728 + * V0.02 added utsname stuff
16729 + * V0.03 changed vcmds to vxi arg
16733 +#include <linux/types.h>
16734 +#include <linux/utsname.h>
16735 +#include <linux/vs_cvirt.h>
16736 +#include <linux/vserver/switch.h>
16737 +#include <linux/vserver/cvirt_cmd.h>
16739 +#include <asm/uaccess.h>
16742 +void vx_vsi_boottime(struct timespec *boottime)
16744 + struct vx_info *vxi = current_vx_info();
16746 + set_normalized_timespec(boottime,
16747 + boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
16748 + boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
16752 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
16754 + struct vx_info *vxi = current_vx_info();
16756 + set_normalized_timespec(uptime,
16757 + uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
16758 + uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
16761 + set_normalized_timespec(idle,
16762 + idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
16763 + idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
16767 +uint64_t vx_idle_jiffies(void)
16769 + return init_task.utime + init_task.stime;
16774 +static inline uint32_t __update_loadavg(uint32_t load,
16775 + int wsize, int delta, int n)
16777 + unsigned long long calc, prev;
16779 + /* just set it to n */
16780 + if (unlikely(delta >= wsize))
16781 + return (n << FSHIFT);
16783 + calc = delta * n;
16785 + prev = (wsize - delta);
16788 + do_div(calc, wsize);
16793 +void vx_update_load(struct vx_info *vxi)
16795 + uint32_t now, last, delta;
16796 + unsigned int nr_running, nr_uninterruptible;
16797 + unsigned int total;
16798 + unsigned long flags;
16800 + spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16803 + last = vxi->cvirt.load_last;
16804 + delta = now - last;
16806 + if (delta < 5*HZ)
16809 + nr_running = atomic_read(&vxi->cvirt.nr_running);
16810 + nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16811 + total = nr_running + nr_uninterruptible;
16813 + vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16814 + 60*HZ, delta, total);
16815 + vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16816 + 5*60*HZ, delta, total);
16817 + vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16818 + 15*60*HZ, delta, total);
16820 + vxi->cvirt.load_last = now;
16822 + atomic_inc(&vxi->cvirt.load_updates);
16823 + spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16828 + * Commands to do_syslog:
16830 + * 0 -- Close the log. Currently a NOP.
16831 + * 1 -- Open the log. Currently a NOP.
16832 + * 2 -- Read from the log.
16833 + * 3 -- Read all messages remaining in the ring buffer.
16834 + * 4 -- Read and clear all messages remaining in the ring buffer
16835 + * 5 -- Clear ring buffer.
16836 + * 6 -- Disable printk's to console
16837 + * 7 -- Enable printk's to console
16838 + * 8 -- Set level of messages printed to console
16839 + * 9 -- Return number of unread characters in the log buffer
16840 + * 10 -- Return size of the log buffer
16842 +int vx_do_syslog(int type, char __user *buf, int len)
16845 + int do_clear = 0;
16846 + struct vx_info *vxi = current_vx_info();
16847 + struct _vx_syslog *log;
16851 + log = &vxi->cvirt.syslog;
16854 + case 0: /* Close log */
16855 + case 1: /* Open log */
16857 + case 2: /* Read from log */
16858 + error = wait_event_interruptible(log->log_wait,
16859 + (log->log_start - log->log_end));
16862 + spin_lock_irq(&log->logbuf_lock);
16863 + spin_unlock_irq(&log->logbuf_lock);
16865 + case 4: /* Read/clear last kernel messages */
16867 + /* fall through */
16868 + case 3: /* Read last kernel messages */
16871 + case 5: /* Clear ring buffer */
16874 + case 6: /* Disable logging to console */
16875 + case 7: /* Enable logging to console */
16876 + case 8: /* Set level of messages printed to console */
16879 + case 9: /* Number of chars in the log buffer */
16881 + case 10: /* Size of the log buffer */
16891 +/* virtual host info names */
16893 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16895 + struct nsproxy *nsproxy;
16896 + struct uts_namespace *uts;
16898 + if (id == VHIN_CONTEXT)
16899 + return vxi->vx_name;
16901 + nsproxy = vxi->space[0].vx_nsproxy;
16905 + uts = nsproxy->uts_ns;
16910 + case VHIN_SYSNAME:
16911 + return uts->name.sysname;
16912 + case VHIN_NODENAME:
16913 + return uts->name.nodename;
16914 + case VHIN_RELEASE:
16915 + return uts->name.release;
16916 + case VHIN_VERSION:
16917 + return uts->name.version;
16918 + case VHIN_MACHINE:
16919 + return uts->name.machine;
16920 + case VHIN_DOMAINNAME:
16921 + return uts->name.domainname;
16928 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16930 + struct vcmd_vhi_name_v0 vc_data;
16933 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16936 + name = vx_vhi_name(vxi, vc_data.field);
16940 + memcpy(name, vc_data.name, 65);
16944 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16946 + struct vcmd_vhi_name_v0 vc_data;
16949 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16952 + name = vx_vhi_name(vxi, vc_data.field);
16956 + memcpy(vc_data.name, name, 65);
16957 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16963 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16965 + struct vcmd_virt_stat_v0 vc_data;
16966 + struct _vx_cvirt *cvirt = &vxi->cvirt;
16967 + struct timespec uptime;
16969 + do_posix_clock_monotonic_gettime(&uptime);
16970 + set_normalized_timespec(&uptime,
16971 + uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16972 + uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16974 + vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16975 + vc_data.uptime = timespec_to_ns(&uptime);
16976 + vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16977 + vc_data.nr_running = atomic_read(&cvirt->nr_running);
16978 + vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16979 + vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16980 + vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16981 + vc_data.load[0] = cvirt->load[0];
16982 + vc_data.load[1] = cvirt->load[1];
16983 + vc_data.load[2] = cvirt->load[2];
16985 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16991 +#ifdef CONFIG_VSERVER_VTIME
16993 +/* virtualized time base */
16995 +void vx_adjust_timespec(struct timespec *ts)
16997 + struct vx_info *vxi;
16999 + if (!vx_flags(VXF_VIRT_TIME, 0))
17002 + vxi = current_vx_info();
17003 + ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
17004 + ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
17006 + if (ts->tv_nsec >= NSEC_PER_SEC) {
17008 + ts->tv_nsec -= NSEC_PER_SEC;
17009 + } else if (ts->tv_nsec < 0) {
17011 + ts->tv_nsec += NSEC_PER_SEC;
17015 +int vx_settimeofday(const struct timespec *ts)
17017 + struct timespec ats, delta;
17018 + struct vx_info *vxi;
17020 + if (!vx_flags(VXF_VIRT_TIME, 0))
17021 + return do_settimeofday(ts);
17023 + getnstimeofday(&ats);
17024 + delta = timespec_sub(*ts, ats);
17026 + vxi = current_vx_info();
17027 + vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
17033 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt_init.h linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt_init.h
17034 --- linux-3.9.4/kernel/vserver/cvirt_init.h 1970-01-01 00:00:00.000000000 +0000
17035 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt_init.h 2013-05-31 14:47:11.000000000 +0000
17039 +extern uint64_t vx_idle_jiffies(void);
17041 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
17043 + uint64_t idle_jiffies = vx_idle_jiffies();
17044 + uint64_t nsuptime;
17046 + do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
17047 + nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
17048 + * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
17049 + cvirt->bias_clock = nsec_to_clock_t(nsuptime);
17050 + cvirt->bias_ts.tv_sec = 0;
17051 + cvirt->bias_ts.tv_nsec = 0;
17053 + jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
17054 + atomic_set(&cvirt->nr_threads, 0);
17055 + atomic_set(&cvirt->nr_running, 0);
17056 + atomic_set(&cvirt->nr_uninterruptible, 0);
17057 + atomic_set(&cvirt->nr_onhold, 0);
17059 + spin_lock_init(&cvirt->load_lock);
17060 + cvirt->load_last = jiffies;
17061 + atomic_set(&cvirt->load_updates, 0);
17062 + cvirt->load[0] = 0;
17063 + cvirt->load[1] = 0;
17064 + cvirt->load[2] = 0;
17065 + atomic_set(&cvirt->total_forks, 0);
17067 + spin_lock_init(&cvirt->syslog.logbuf_lock);
17068 + init_waitqueue_head(&cvirt->syslog.log_wait);
17069 + cvirt->syslog.log_start = 0;
17070 + cvirt->syslog.log_end = 0;
17071 + cvirt->syslog.con_start = 0;
17072 + cvirt->syslog.logged_chars = 0;
17076 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17078 + // cvirt_pc->cpustat = { 0 };
17081 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
17083 +#ifdef CONFIG_VSERVER_WARN
17086 + vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
17087 + "!!! cvirt: %p[nr_threads] = %d on exit.",
17089 + vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
17090 + "!!! cvirt: %p[nr_running] = %d on exit.",
17092 + vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
17093 + "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
17095 + vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
17096 + "!!! cvirt: %p[nr_onhold] = %d on exit.",
17102 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
17107 diff -NurpP --minimal linux-3.9.4/kernel/vserver/cvirt_proc.h linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt_proc.h
17108 --- linux-3.9.4/kernel/vserver/cvirt_proc.h 1970-01-01 00:00:00.000000000 +0000
17109 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/cvirt_proc.h 2013-05-31 19:38:26.000000000 +0000
17111 +#ifndef _VX_CVIRT_PROC_H
17112 +#define _VX_CVIRT_PROC_H
17114 +#include <linux/nsproxy.h>
17115 +#include <linux/mnt_namespace.h>
17116 +#include <linux/ipc_namespace.h>
17117 +#include <linux/utsname.h>
17118 +#include <linux/ipc.h>
17120 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
17123 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
17125 + struct mnt_namespace *ns;
17126 + struct uts_namespace *uts;
17127 + struct ipc_namespace *ipc;
17133 + length += sprintf(buffer + length,
17134 + "NSProxy:\t%p [%p,%p,%p]\n",
17135 + nsproxy, nsproxy->mnt_ns,
17136 + nsproxy->uts_ns, nsproxy->ipc_ns);
17138 + ns = nsproxy->mnt_ns;
17142 + length += vx_info_mnt_namespace(ns, buffer + length);
17146 + uts = nsproxy->uts_ns;
17150 + length += sprintf(buffer + length,
17151 + "SysName:\t%.*s\n"
17152 + "NodeName:\t%.*s\n"
17153 + "Release:\t%.*s\n"
17154 + "Version:\t%.*s\n"
17155 + "Machine:\t%.*s\n"
17156 + "DomainName:\t%.*s\n",
17157 + __NEW_UTS_LEN, uts->name.sysname,
17158 + __NEW_UTS_LEN, uts->name.nodename,
17159 + __NEW_UTS_LEN, uts->name.release,
17160 + __NEW_UTS_LEN, uts->name.version,
17161 + __NEW_UTS_LEN, uts->name.machine,
17162 + __NEW_UTS_LEN, uts->name.domainname);
17165 + ipc = nsproxy->ipc_ns;
17169 + length += sprintf(buffer + length,
17170 + "SEMS:\t\t%d %d %d %d %d\n"
17171 + "MSG:\t\t%d %d %d\n"
17172 + "SHM:\t\t%lu %lu %d %ld\n",
17173 + ipc->sem_ctls[0], ipc->sem_ctls[1],
17174 + ipc->sem_ctls[2], ipc->sem_ctls[3],
17176 + ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
17177 + (unsigned long)ipc->shm_ctlmax,
17178 + (unsigned long)ipc->shm_ctlall,
17179 + ipc->shm_ctlmni, ipc->shm_tot);
17186 +#include <linux/sched.h>
17188 +#define LOAD_INT(x) ((x) >> FSHIFT)
17189 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
17192 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
17197 + length += sprintf(buffer + length,
17198 + "BiasUptime:\t%lu.%02lu\n",
17199 + (unsigned long)cvirt->bias_uptime.tv_sec,
17200 + (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
17202 + a = cvirt->load[0] + (FIXED_1 / 200);
17203 + b = cvirt->load[1] + (FIXED_1 / 200);
17204 + c = cvirt->load[2] + (FIXED_1 / 200);
17205 + length += sprintf(buffer + length,
17206 + "nr_threads:\t%d\n"
17207 + "nr_running:\t%d\n"
17208 + "nr_unintr:\t%d\n"
17209 + "nr_onhold:\t%d\n"
17210 + "load_updates:\t%d\n"
17211 + "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
17212 + "total_forks:\t%d\n",
17213 + atomic_read(&cvirt->nr_threads),
17214 + atomic_read(&cvirt->nr_running),
17215 + atomic_read(&cvirt->nr_uninterruptible),
17216 + atomic_read(&cvirt->nr_onhold),
17217 + atomic_read(&cvirt->load_updates),
17218 + LOAD_INT(a), LOAD_FRAC(a),
17219 + LOAD_INT(b), LOAD_FRAC(b),
17220 + LOAD_INT(c), LOAD_FRAC(c),
17221 + atomic_read(&cvirt->total_forks));
17226 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
17227 + char *buffer, int cpu)
17233 +#endif /* _VX_CVIRT_PROC_H */
17234 diff -NurpP --minimal linux-3.9.4/kernel/vserver/debug.c linux-3.9.4-vs2.3.6.2/kernel/vserver/debug.c
17235 --- linux-3.9.4/kernel/vserver/debug.c 1970-01-01 00:00:00.000000000 +0000
17236 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/debug.c 2013-05-31 14:47:11.000000000 +0000
17239 + * kernel/vserver/debug.c
17241 + * Copyright (C) 2005-2007 Herbert Pötzl
17243 + * V0.01 vx_info dump support
17247 +#include <linux/module.h>
17249 +#include <linux/vserver/context.h>
17252 +void dump_vx_info(struct vx_info *vxi, int level)
17254 + printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
17255 + atomic_read(&vxi->vx_usecnt),
17256 + atomic_read(&vxi->vx_tasks),
17259 + __dump_vx_limit(&vxi->limit);
17260 + __dump_vx_sched(&vxi->sched);
17261 + __dump_vx_cvirt(&vxi->cvirt);
17262 + __dump_vx_cacct(&vxi->cacct);
17268 +EXPORT_SYMBOL_GPL(dump_vx_info);
17270 diff -NurpP --minimal linux-3.9.4/kernel/vserver/device.c linux-3.9.4-vs2.3.6.2/kernel/vserver/device.c
17271 --- linux-3.9.4/kernel/vserver/device.c 1970-01-01 00:00:00.000000000 +0000
17272 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/device.c 2013-05-31 14:47:11.000000000 +0000
17275 + * linux/kernel/vserver/device.c
17277 + * Linux-VServer: Device Support
17279 + * Copyright (C) 2006 Herbert Pötzl
17280 + * Copyright (C) 2007 Daniel Hokka Zakrisson
17282 + * V0.01 device mapping basics
17283 + * V0.02 added defaults
17287 +#include <linux/slab.h>
17288 +#include <linux/rcupdate.h>
17289 +#include <linux/fs.h>
17290 +#include <linux/namei.h>
17291 +#include <linux/hash.h>
17293 +#include <asm/errno.h>
17294 +#include <asm/uaccess.h>
17295 +#include <linux/vserver/base.h>
17296 +#include <linux/vserver/debug.h>
17297 +#include <linux/vserver/context.h>
17298 +#include <linux/vserver/device.h>
17299 +#include <linux/vserver/device_cmd.h>
17302 +#define DMAP_HASH_BITS 4
17305 +struct vs_mapping {
17307 + struct hlist_node hlist;
17308 + struct list_head list;
17310 +#define dm_hlist u.hlist
17311 +#define dm_list u.list
17314 + struct vx_dmap_target target;
17318 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
17320 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
17322 +static struct vx_dmap_target dmap_defaults[2] = {
17323 + { .flags = DATTR_OPEN },
17324 + { .flags = DATTR_OPEN },
17328 +struct kmem_cache *dmap_cachep __read_mostly;
17330 +int __init dmap_cache_init(void)
17332 + dmap_cachep = kmem_cache_create("dmap_cache",
17333 + sizeof(struct vs_mapping), 0,
17334 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
17338 +__initcall(dmap_cache_init);
17341 +static inline unsigned int __hashval(dev_t dev, int bits)
17343 + return hash_long((unsigned long)dev, bits);
17347 +/* __hash_mapping()
17348 + * add the mapping to the hash table
17350 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
17352 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17353 + struct hlist_head *head, *hash = dmap_main_hash;
17354 + int device = vdm->device;
17356 + spin_lock(hash_lock);
17357 + vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
17358 + vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
17360 + head = &hash[__hashval(device, DMAP_HASH_BITS)];
17361 + hlist_add_head(&vdm->dm_hlist, head);
17362 + spin_unlock(hash_lock);
17366 +static inline int __mode_to_default(umode_t mode)
17379 +/* __set_default()
17382 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
17383 + struct vx_dmap_target *vdmt)
17385 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17386 + spin_lock(hash_lock);
17389 + vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
17391 + dmap_defaults[__mode_to_default(mode)] = *vdmt;
17394 + spin_unlock(hash_lock);
17396 + vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
17397 + vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
17401 +/* __remove_default()
17402 + * remove a default
17404 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
17406 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17407 + spin_lock(hash_lock);
17410 + vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
17411 + else /* remove == reset */
17412 + dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
17414 + spin_unlock(hash_lock);
17419 +/* __find_mapping()
17420 + * find a mapping in the hash table
17422 + * caller must hold hash_lock
17424 +static inline int __find_mapping(xid_t xid, dev_t device, umode_t mode,
17425 + struct vs_mapping **local, struct vs_mapping **global)
17427 + struct hlist_head *hash = dmap_main_hash;
17428 + struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
17429 + struct hlist_node *pos;
17430 + struct vs_mapping *vdm;
17436 + hlist_for_each(pos, head) {
17437 + vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
17439 + if ((vdm->device == device) &&
17440 + !((vdm->target.flags ^ mode) & S_IFMT)) {
17441 + if (vdm->xid == xid) {
17444 + } else if (global && vdm->xid == 0)
17449 + if (global && *global)
17456 +/* __lookup_mapping()
17457 + * find a mapping and store the result in target and flags
17459 +static inline int __lookup_mapping(struct vx_info *vxi,
17460 + dev_t device, dev_t *target, int *flags, umode_t mode)
17462 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17463 + struct vs_mapping *vdm, *global;
17464 + struct vx_dmap_target *vdmt;
17466 + xid_t xid = vxi->vx_id;
17469 + spin_lock(hash_lock);
17470 + if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
17472 + vdmt = &vdm->target;
17476 + index = __mode_to_default(mode);
17477 + if (vxi && vxi->dmap.targets[index].flags) {
17479 + vdmt = &vxi->dmap.targets[index];
17480 + } else if (global) {
17482 + vdmt = &global->target;
17486 + vdmt = &dmap_defaults[index];
17490 + if (target && (vdmt->flags & DATTR_REMAP))
17491 + *target = vdmt->target;
17493 + *target = device;
17495 + *flags = vdmt->flags;
17497 + spin_unlock(hash_lock);
17503 +/* __remove_mapping()
17504 + * remove a mapping from the hash table
17506 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
17509 + spinlock_t *hash_lock = &dmap_main_hash_lock;
17510 + struct vs_mapping *vdm = NULL;
17513 + spin_lock(hash_lock);
17515 + ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
17517 + vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
17518 + vxi, vxi ? vxi->vx_id : 0, device, mode);
17521 + hlist_del(&vdm->dm_hlist);
17524 + spin_unlock(hash_lock);
17526 + kmem_cache_free(dmap_cachep, vdm);
17532 +int vs_map_device(struct vx_info *vxi,
17533 + dev_t device, dev_t *target, umode_t mode)
17535 + int ret, flags = DATTR_MASK;
17539 + *target = device;
17542 + ret = __lookup_mapping(vxi, device, target, &flags, mode);
17543 + vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
17544 + device, target ? *target : 0, flags, mode, ret);
17546 + return (flags & DATTR_MASK);
17551 +static int do_set_mapping(struct vx_info *vxi,
17552 + dev_t device, dev_t target, int flags, umode_t mode)
17555 + struct vs_mapping *new;
17557 + new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
17561 + INIT_HLIST_NODE(&new->dm_hlist);
17562 + new->device = device;
17563 + new->target.target = target;
17564 + new->target.flags = flags | mode;
17565 + new->xid = (vxi ? vxi->vx_id : 0);
17567 + vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
17568 + __hash_mapping(vxi, new);
17570 + struct vx_dmap_target new = {
17571 + .target = target,
17572 + .flags = flags | mode,
17574 + __set_default(vxi, mode, &new);
17580 +static int do_unset_mapping(struct vx_info *vxi,
17581 + dev_t device, dev_t target, int flags, umode_t mode)
17583 + int ret = -EINVAL;
17586 + ret = __remove_mapping(vxi, device, mode);
17590 + ret = __remove_default(vxi, mode);
17600 +static inline int __user_device(const char __user *name, dev_t *dev,
17603 + struct nameidata nd;
17610 + ret = user_lpath(name, &nd.path);
17613 + if (nd.path.dentry->d_inode) {
17614 + *dev = nd.path.dentry->d_inode->i_rdev;
17615 + *mode = nd.path.dentry->d_inode->i_mode;
17617 + path_put(&nd.path);
17621 +static inline int __mapping_mode(dev_t device, dev_t target,
17622 + umode_t device_mode, umode_t target_mode, umode_t *mode)
17625 + *mode = device_mode & S_IFMT;
17627 + *mode = target_mode & S_IFMT;
17631 + /* if both given, device and target mode have to match */
17632 + if (device && target &&
17633 + ((device_mode ^ target_mode) & S_IFMT))
17639 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
17640 + const char __user *target_path, int flags, int set)
17642 + dev_t device = ~0, target = ~0;
17643 + umode_t device_mode = 0, target_mode = 0, mode;
17646 + ret = __user_device(device_path, &device, &device_mode);
17649 + ret = __user_device(target_path, &target, &target_mode);
17653 + ret = __mapping_mode(device, target,
17654 + device_mode, target_mode, &mode);
17659 + return do_set_mapping(vxi, device, target,
17662 + return do_unset_mapping(vxi, device, target,
17667 +int vc_set_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, 1);
17678 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
17680 + struct vcmd_set_mapping_v0 vc_data;
17682 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17685 + return do_mapping(vxi, vc_data.device, vc_data.target,
17686 + vc_data.flags, 0);
17690 +#ifdef CONFIG_COMPAT
17692 +int vc_set_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, 1);
17703 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
17705 + struct vcmd_set_mapping_v0_x32 vc_data;
17707 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17710 + return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
17711 + compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
17714 +#endif /* CONFIG_COMPAT */
17717 diff -NurpP --minimal linux-3.9.4/kernel/vserver/dlimit.c linux-3.9.4-vs2.3.6.2/kernel/vserver/dlimit.c
17718 --- linux-3.9.4/kernel/vserver/dlimit.c 1970-01-01 00:00:00.000000000 +0000
17719 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/dlimit.c 2013-05-31 19:37:39.000000000 +0000
17722 + * linux/kernel/vserver/dlimit.c
17724 + * Virtual Server: Context Disk Limits
17726 + * Copyright (C) 2004-2009 Herbert Pötzl
17728 + * V0.01 initial version
17729 + * V0.02 compat32 splitup
17730 + * V0.03 extended interface
17734 +#include <linux/statfs.h>
17735 +#include <linux/sched.h>
17736 +#include <linux/namei.h>
17737 +#include <linux/vs_tag.h>
17738 +#include <linux/vs_dlimit.h>
17739 +#include <linux/vserver/dlimit_cmd.h>
17740 +#include <linux/slab.h>
17741 +// #include <linux/gfp.h>
17743 +#include <asm/uaccess.h>
17745 +/* __alloc_dl_info()
17747 + * allocate an initialized dl_info struct
17748 + * doesn't make it visible (hash) */
17750 +static struct dl_info *__alloc_dl_info(struct super_block *sb, tag_t tag)
17752 + struct dl_info *new = NULL;
17754 + vxdprintk(VXD_CBIT(dlim, 5),
17755 + "alloc_dl_info(%p,%d)*", sb, tag);
17757 + /* would this benefit from a slab cache? */
17758 + new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
17762 + memset(new, 0, sizeof(struct dl_info));
17763 + new->dl_tag = tag;
17765 + // INIT_RCU_HEAD(&new->dl_rcu);
17766 + INIT_HLIST_NODE(&new->dl_hlist);
17767 + spin_lock_init(&new->dl_lock);
17768 + atomic_set(&new->dl_refcnt, 0);
17769 + atomic_set(&new->dl_usecnt, 0);
17771 + /* rest of init goes here */
17773 + vxdprintk(VXD_CBIT(dlim, 4),
17774 + "alloc_dl_info(%p,%d) = %p", sb, tag, new);
17778 +/* __dealloc_dl_info()
17780 + * final disposal of dl_info */
17782 +static void __dealloc_dl_info(struct dl_info *dli)
17784 + vxdprintk(VXD_CBIT(dlim, 4),
17785 + "dealloc_dl_info(%p)", dli);
17787 + dli->dl_hlist.next = LIST_POISON1;
17788 + dli->dl_tag = -1;
17791 + BUG_ON(atomic_read(&dli->dl_usecnt));
17792 + BUG_ON(atomic_read(&dli->dl_refcnt));
17798 +/* hash table for dl_info hash */
17800 +#define DL_HASH_SIZE 13
17802 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17804 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17807 +static inline unsigned int __hashval(struct super_block *sb, tag_t tag)
17809 + return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17814 +/* __hash_dl_info()
17816 + * add the dli to the global hash table
17817 + * requires the hash_lock to be held */
17819 +static inline void __hash_dl_info(struct dl_info *dli)
17821 + struct hlist_head *head;
17823 + vxdprintk(VXD_CBIT(dlim, 6),
17824 + "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17825 + get_dl_info(dli);
17826 + head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17827 + hlist_add_head_rcu(&dli->dl_hlist, head);
17830 +/* __unhash_dl_info()
17832 + * remove the dli from the global hash table
17833 + * requires the hash_lock to be held */
17835 +static inline void __unhash_dl_info(struct dl_info *dli)
17837 + vxdprintk(VXD_CBIT(dlim, 6),
17838 + "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17839 + hlist_del_rcu(&dli->dl_hlist);
17840 + put_dl_info(dli);
17844 +/* __lookup_dl_info()
17846 + * requires the rcu_read_lock()
17847 + * doesn't increment the dl_refcnt */
17849 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, tag_t tag)
17851 + struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17852 + struct dl_info *dli;
17854 + hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17855 + if (dli->dl_tag == tag && dli->dl_sb == sb)
17862 +struct dl_info *locate_dl_info(struct super_block *sb, tag_t tag)
17864 + struct dl_info *dli;
17867 + dli = get_dl_info(__lookup_dl_info(sb, tag));
17868 + vxdprintk(VXD_CBIT(dlim, 7),
17869 + "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17870 + rcu_read_unlock();
17874 +void rcu_free_dl_info(struct rcu_head *head)
17876 + struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17877 + int usecnt, refcnt;
17879 + BUG_ON(!dli || !head);
17881 + usecnt = atomic_read(&dli->dl_usecnt);
17882 + BUG_ON(usecnt < 0);
17884 + refcnt = atomic_read(&dli->dl_refcnt);
17885 + BUG_ON(refcnt < 0);
17887 + vxdprintk(VXD_CBIT(dlim, 3),
17888 + "rcu_free_dl_info(%p)", dli);
17890 + __dealloc_dl_info(dli);
17892 + printk("!!! rcu didn't free\n");
17898 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17899 + uint32_t flags, int add)
17901 + struct path path;
17904 + ret = user_lpath(name, &path);
17906 + struct super_block *sb;
17907 + struct dl_info *dli;
17910 + if (!path.dentry->d_inode)
17911 + goto out_release;
17912 + if (!(sb = path.dentry->d_inode->i_sb))
17913 + goto out_release;
17916 + dli = __alloc_dl_info(sb, id);
17917 + spin_lock(&dl_info_hash_lock);
17920 + if (__lookup_dl_info(sb, id))
17922 + __hash_dl_info(dli);
17925 + spin_lock(&dl_info_hash_lock);
17926 + dli = __lookup_dl_info(sb, id);
17931 + __unhash_dl_info(dli);
17935 + spin_unlock(&dl_info_hash_lock);
17937 + __dealloc_dl_info(dli);
17944 +int vc_add_dlimit(uint32_t id, void __user *data)
17946 + struct vcmd_ctx_dlimit_base_v0 vc_data;
17948 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17951 + return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17954 +int vc_rem_dlimit(uint32_t id, void __user *data)
17956 + struct vcmd_ctx_dlimit_base_v0 vc_data;
17958 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17961 + return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17964 +#ifdef CONFIG_COMPAT
17966 +int vc_add_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, 1);
17977 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17979 + struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17981 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17984 + return do_addrem_dlimit(id,
17985 + compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17988 +#endif /* CONFIG_COMPAT */
17992 +int do_set_dlimit(uint32_t id, const char __user *name,
17993 + uint32_t space_used, uint32_t space_total,
17994 + uint32_t inodes_used, uint32_t inodes_total,
17995 + uint32_t reserved, uint32_t flags)
17997 + struct path path;
18000 + ret = user_lpath(name, &path);
18002 + struct super_block *sb;
18003 + struct dl_info *dli;
18006 + if (!path.dentry->d_inode)
18007 + goto out_release;
18008 + if (!(sb = path.dentry->d_inode->i_sb))
18009 + goto out_release;
18011 + /* sanity checks */
18012 + if ((reserved != CDLIM_KEEP &&
18013 + reserved > 100) ||
18014 + (inodes_used != CDLIM_KEEP &&
18015 + inodes_used > inodes_total) ||
18016 + (space_used != CDLIM_KEEP &&
18017 + space_used > space_total))
18018 + goto out_release;
18021 + dli = locate_dl_info(sb, id);
18023 + goto out_release;
18025 + spin_lock(&dli->dl_lock);
18027 + if (inodes_used != CDLIM_KEEP)
18028 + dli->dl_inodes_used = inodes_used;
18029 + if (inodes_total != CDLIM_KEEP)
18030 + dli->dl_inodes_total = inodes_total;
18031 + if (space_used != CDLIM_KEEP)
18032 + dli->dl_space_used = dlimit_space_32to64(
18033 + space_used, flags, DLIMS_USED);
18035 + if (space_total == CDLIM_INFINITY)
18036 + dli->dl_space_total = DLIM_INFINITY;
18037 + else if (space_total != CDLIM_KEEP)
18038 + dli->dl_space_total = dlimit_space_32to64(
18039 + space_total, flags, DLIMS_TOTAL);
18041 + if (reserved != CDLIM_KEEP)
18042 + dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
18044 + spin_unlock(&dli->dl_lock);
18046 + put_dl_info(dli);
18055 +int vc_set_dlimit(uint32_t id, void __user *data)
18057 + struct vcmd_ctx_dlimit_v0 vc_data;
18059 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18062 + return do_set_dlimit(id, vc_data.name,
18063 + vc_data.space_used, vc_data.space_total,
18064 + vc_data.inodes_used, vc_data.inodes_total,
18065 + vc_data.reserved, vc_data.flags);
18068 +#ifdef CONFIG_COMPAT
18070 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
18072 + struct vcmd_ctx_dlimit_v0_x32 vc_data;
18074 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18077 + return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
18078 + vc_data.space_used, vc_data.space_total,
18079 + vc_data.inodes_used, vc_data.inodes_total,
18080 + vc_data.reserved, vc_data.flags);
18083 +#endif /* CONFIG_COMPAT */
18087 +int do_get_dlimit(uint32_t id, const char __user *name,
18088 + uint32_t *space_used, uint32_t *space_total,
18089 + uint32_t *inodes_used, uint32_t *inodes_total,
18090 + uint32_t *reserved, uint32_t *flags)
18092 + struct path path;
18095 + ret = user_lpath(name, &path);
18097 + struct super_block *sb;
18098 + struct dl_info *dli;
18101 + if (!path.dentry->d_inode)
18102 + goto out_release;
18103 + if (!(sb = path.dentry->d_inode->i_sb))
18104 + goto out_release;
18107 + dli = locate_dl_info(sb, id);
18109 + goto out_release;
18111 + spin_lock(&dli->dl_lock);
18112 + *inodes_used = dli->dl_inodes_used;
18113 + *inodes_total = dli->dl_inodes_total;
18115 + *space_used = dlimit_space_64to32(
18116 + dli->dl_space_used, flags, DLIMS_USED);
18118 + if (dli->dl_space_total == DLIM_INFINITY)
18119 + *space_total = CDLIM_INFINITY;
18121 + *space_total = dlimit_space_64to32(
18122 + dli->dl_space_total, flags, DLIMS_TOTAL);
18124 + *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
18125 + spin_unlock(&dli->dl_lock);
18127 + put_dl_info(dli);
18138 +int vc_get_dlimit(uint32_t id, void __user *data)
18140 + struct vcmd_ctx_dlimit_v0 vc_data;
18143 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18146 + ret = do_get_dlimit(id, vc_data.name,
18147 + &vc_data.space_used, &vc_data.space_total,
18148 + &vc_data.inodes_used, &vc_data.inodes_total,
18149 + &vc_data.reserved, &vc_data.flags);
18153 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18158 +#ifdef CONFIG_COMPAT
18160 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
18162 + struct vcmd_ctx_dlimit_v0_x32 vc_data;
18165 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18168 + ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
18169 + &vc_data.space_used, &vc_data.space_total,
18170 + &vc_data.inodes_used, &vc_data.inodes_total,
18171 + &vc_data.reserved, &vc_data.flags);
18175 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18180 +#endif /* CONFIG_COMPAT */
18183 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
18185 + struct dl_info *dli;
18186 + __u64 blimit, bfree, bavail;
18189 + dli = locate_dl_info(sb, dx_current_tag());
18193 + spin_lock(&dli->dl_lock);
18194 + if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
18197 + /* reduce max inodes available to limit */
18198 + if (buf->f_files > dli->dl_inodes_total)
18199 + buf->f_files = dli->dl_inodes_total;
18201 + ifree = dli->dl_inodes_total - dli->dl_inodes_used;
18202 + /* reduce free inodes to min */
18203 + if (ifree < buf->f_ffree)
18204 + buf->f_ffree = ifree;
18207 + if (dli->dl_space_total == DLIM_INFINITY)
18210 + blimit = dli->dl_space_total >> sb->s_blocksize_bits;
18212 + if (dli->dl_space_total < dli->dl_space_used)
18215 + bfree = (dli->dl_space_total - dli->dl_space_used)
18216 + >> sb->s_blocksize_bits;
18218 + bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
18219 + if (bavail < dli->dl_space_used)
18222 + bavail = (bavail - dli->dl_space_used)
18223 + >> sb->s_blocksize_bits;
18225 + /* reduce max space available to limit */
18226 + if (buf->f_blocks > blimit)
18227 + buf->f_blocks = blimit;
18229 + /* reduce free space to min */
18230 + if (bfree < buf->f_bfree)
18231 + buf->f_bfree = bfree;
18233 + /* reduce avail space to min */
18234 + if (bavail < buf->f_bavail)
18235 + buf->f_bavail = bavail;
18238 + spin_unlock(&dli->dl_lock);
18239 + put_dl_info(dli);
18244 +#include <linux/module.h>
18246 +EXPORT_SYMBOL_GPL(locate_dl_info);
18247 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
18249 diff -NurpP --minimal linux-3.9.4/kernel/vserver/helper.c linux-3.9.4-vs2.3.6.2/kernel/vserver/helper.c
18250 --- linux-3.9.4/kernel/vserver/helper.c 1970-01-01 00:00:00.000000000 +0000
18251 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/helper.c 2013-06-01 08:27:59.000000000 +0000
18254 + * linux/kernel/vserver/helper.c
18256 + * Virtual Context Support
18258 + * Copyright (C) 2004-2007 Herbert Pötzl
18260 + * V0.01 basic helper
18264 +#include <linux/kmod.h>
18265 +#include <linux/reboot.h>
18266 +#include <linux/vs_context.h>
18267 +#include <linux/vs_network.h>
18268 +#include <linux/vserver/signal.h>
18271 +char vshelper_path[255] = "/sbin/vshelper";
18273 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
18275 + current->flags &= ~PF_THREAD_BOUND;
18279 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
18283 + if ((ret = call_usermodehelper_fns(name, argv, envp,
18284 + sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC,
18285 + vshelper_init, NULL, NULL))) {
18286 + printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
18287 + name, argv[1], argv[2],
18288 + sync ? "sync" : "async", ret);
18290 + vxdprintk(VXD_CBIT(switch, 4),
18291 + "%s: (%s %s) returned %s with %d",
18292 + name, argv[1], argv[2], sync ? "sync" : "async", ret);
18297 + * vshelper path is set via /proc/sys
18298 + * invoked by vserver sys_reboot(), with
18299 + * the following arguments
18301 + * argv [0] = vshelper_path;
18302 + * argv [1] = action: "restart", "halt", "poweroff", ...
18303 + * argv [2] = context identifier
18305 + * envp [*] = type-specific parameters
18308 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
18310 + char id_buf[8], cmd_buf[16];
18311 + char uid_buf[16], pid_buf[16];
18314 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
18315 + char *envp[] = {"HOME=/", "TERM=linux",
18316 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
18317 + uid_buf, pid_buf, cmd_buf, 0};
18319 + if (vx_info_state(vxi, VXS_HELPER))
18321 + vxi->vx_state |= VXS_HELPER;
18323 + snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18325 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18326 + snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
18327 + from_kuid(&init_user_ns, current_uid()));
18328 + snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
18331 + case LINUX_REBOOT_CMD_RESTART:
18332 + argv[1] = "restart";
18335 + case LINUX_REBOOT_CMD_HALT:
18336 + argv[1] = "halt";
18339 + case LINUX_REBOOT_CMD_POWER_OFF:
18340 + argv[1] = "poweroff";
18343 + case LINUX_REBOOT_CMD_SW_SUSPEND:
18344 + argv[1] = "swsusp";
18347 + case LINUX_REBOOT_CMD_OOM:
18352 + vxi->vx_state &= ~VXS_HELPER;
18356 + ret = do_vshelper(vshelper_path, argv, envp, 0);
18357 + vxi->vx_state &= ~VXS_HELPER;
18358 + __wakeup_vx_info(vxi);
18359 + return (ret) ? -EPERM : 0;
18363 +long vs_reboot(unsigned int cmd, void __user *arg)
18365 + struct vx_info *vxi = current_vx_info();
18368 + vxdprintk(VXD_CBIT(misc, 5),
18369 + "vs_reboot(%p[#%d],%u)",
18370 + vxi, vxi ? vxi->vx_id : 0, cmd);
18372 + ret = vs_reboot_helper(vxi, cmd, arg);
18376 + vxi->reboot_cmd = cmd;
18377 + if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18379 + case LINUX_REBOOT_CMD_RESTART:
18380 + case LINUX_REBOOT_CMD_HALT:
18381 + case LINUX_REBOOT_CMD_POWER_OFF:
18382 + vx_info_kill(vxi, 0, SIGKILL);
18383 + vx_info_kill(vxi, 1, SIGKILL);
18391 +long vs_oom_action(unsigned int cmd)
18393 + struct vx_info *vxi = current_vx_info();
18396 + vxdprintk(VXD_CBIT(misc, 5),
18397 + "vs_oom_action(%p[#%d],%u)",
18398 + vxi, vxi ? vxi->vx_id : 0, cmd);
18400 + ret = vs_reboot_helper(vxi, cmd, NULL);
18404 + vxi->reboot_cmd = cmd;
18405 + if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
18406 + vx_info_kill(vxi, 0, SIGKILL);
18407 + vx_info_kill(vxi, 1, SIGKILL);
18413 + * argv [0] = vshelper_path;
18414 + * argv [1] = action: "startup", "shutdown"
18415 + * argv [2] = context identifier
18417 + * envp [*] = type-specific parameters
18420 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
18422 + char id_buf[8], cmd_buf[16];
18423 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
18424 + char *envp[] = {"HOME=/", "TERM=linux",
18425 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18427 + if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
18430 + snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
18431 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18434 + case VSC_STARTUP:
18435 + argv[1] = "startup";
18437 + case VSC_SHUTDOWN:
18438 + argv[1] = "shutdown";
18444 + return do_vshelper(vshelper_path, argv, envp, 1);
18449 + * argv [0] = vshelper_path;
18450 + * argv [1] = action: "netup", "netdown"
18451 + * argv [2] = context identifier
18453 + * envp [*] = type-specific parameters
18456 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
18458 + char id_buf[8], cmd_buf[16];
18459 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
18460 + char *envp[] = {"HOME=/", "TERM=linux",
18461 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
18463 + if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
18466 + snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
18467 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
18471 + argv[1] = "netup";
18473 + case VSC_NETDOWN:
18474 + argv[1] = "netdown";
18480 + return do_vshelper(vshelper_path, argv, envp, 1);
18483 diff -NurpP --minimal linux-3.9.4/kernel/vserver/history.c linux-3.9.4-vs2.3.6.2/kernel/vserver/history.c
18484 --- linux-3.9.4/kernel/vserver/history.c 1970-01-01 00:00:00.000000000 +0000
18485 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/history.c 2013-05-31 14:47:11.000000000 +0000
18488 + * kernel/vserver/history.c
18490 + * Virtual Context History Backtrace
18492 + * Copyright (C) 2004-2007 Herbert Pötzl
18494 + * V0.01 basic structure
18495 + * V0.02 hash/unhash and trace
18496 + * V0.03 preemption fixes
18500 +#include <linux/module.h>
18501 +#include <asm/uaccess.h>
18503 +#include <linux/vserver/context.h>
18504 +#include <linux/vserver/debug.h>
18505 +#include <linux/vserver/debug_cmd.h>
18506 +#include <linux/vserver/history.h>
18509 +#ifdef CONFIG_VSERVER_HISTORY
18510 +#define VXH_SIZE CONFIG_VSERVER_HISTORY_SIZE
18512 +#define VXH_SIZE 64
18515 +struct _vx_history {
18516 + unsigned int counter;
18518 + struct _vx_hist_entry entry[VXH_SIZE + 1];
18522 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
18524 +unsigned volatile int vxh_active = 1;
18526 +static atomic_t sequence = ATOMIC_INIT(0);
18531 + * requires disabled preemption */
18533 +struct _vx_hist_entry *vxh_advance(void *loc)
18535 + unsigned int cpu = smp_processor_id();
18536 + struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18537 + struct _vx_hist_entry *entry;
18538 + unsigned int index;
18540 + index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
18541 + entry = &hist->entry[index];
18543 + entry->seq = atomic_inc_return(&sequence);
18544 + entry->loc = loc;
18548 +EXPORT_SYMBOL_GPL(vxh_advance);
18551 +#define VXH_LOC_FMTS "(#%04x,*%d):%p"
18553 +#define VXH_LOC_ARGS(e) (e)->seq, cpu, (e)->loc
18556 +#define VXH_VXI_FMTS "%p[#%d,%d.%d]"
18558 +#define VXH_VXI_ARGS(e) (e)->vxi.ptr, \
18559 + (e)->vxi.ptr ? (e)->vxi.xid : 0, \
18560 + (e)->vxi.ptr ? (e)->vxi.usecnt : 0, \
18561 + (e)->vxi.ptr ? (e)->vxi.tasks : 0
18563 +void vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
18565 + switch (e->type) {
18566 + case VXH_THROW_OOPS:
18567 + printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
18570 + case VXH_GET_VX_INFO:
18571 + case VXH_PUT_VX_INFO:
18572 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18574 + (e->type == VXH_GET_VX_INFO) ? "get" : "put",
18575 + VXH_VXI_ARGS(e));
18578 + case VXH_INIT_VX_INFO:
18579 + case VXH_SET_VX_INFO:
18580 + case VXH_CLR_VX_INFO:
18581 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18583 + (e->type == VXH_INIT_VX_INFO) ? "init" :
18584 + ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
18585 + VXH_VXI_ARGS(e), e->sc.data);
18588 + case VXH_CLAIM_VX_INFO:
18589 + case VXH_RELEASE_VX_INFO:
18590 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
18592 + (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
18593 + VXH_VXI_ARGS(e), e->sc.data);
18596 + case VXH_ALLOC_VX_INFO:
18597 + case VXH_DEALLOC_VX_INFO:
18598 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
18600 + (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
18601 + VXH_VXI_ARGS(e));
18604 + case VXH_HASH_VX_INFO:
18605 + case VXH_UNHASH_VX_INFO:
18606 + printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
18608 + (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
18609 + VXH_VXI_ARGS(e));
18612 + case VXH_LOC_VX_INFO:
18613 + case VXH_LOOKUP_VX_INFO:
18614 + case VXH_CREATE_VX_INFO:
18615 + printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
18617 + (e->type == VXH_CREATE_VX_INFO) ? "create" :
18618 + ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
18619 + e->ll.arg, VXH_VXI_ARGS(e));
18624 +static void __vxh_dump_history(void)
18626 + unsigned int i, cpu;
18628 + printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
18629 + atomic_read(&sequence), NR_CPUS);
18631 + for (i = 0; i < VXH_SIZE; i++) {
18632 + for_each_online_cpu(cpu) {
18633 + struct _vx_history *hist =
18634 + &per_cpu(vx_history_buffer, cpu);
18635 + unsigned int index = (hist->counter - i) % VXH_SIZE;
18636 + struct _vx_hist_entry *entry = &hist->entry[index];
18638 + vxh_dump_entry(entry, cpu);
18643 +void vxh_dump_history(void)
18647 + local_irq_enable();
18649 + local_irq_disable();
18651 + __vxh_dump_history();
18655 +/* vserver syscall commands below here */
18658 +int vc_dump_history(uint32_t id)
18661 + __vxh_dump_history();
18668 +int do_read_history(struct __user _vx_hist_entry *data,
18669 + int cpu, uint32_t *index, uint32_t *count)
18671 + int pos, ret = 0;
18672 + struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
18673 + int end = hist->counter;
18674 + int start = end - VXH_SIZE + 2;
18675 + int idx = *index;
18677 + /* special case: get current pos */
18683 + /* have we lost some data? */
18687 + for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
18688 + struct _vx_hist_entry *entry =
18689 + &hist->entry[idx % VXH_SIZE];
18691 + /* send entry to userspace */
18692 + ret = copy_to_user(&data[pos], entry, sizeof(*entry));
18696 + /* save new index and count */
18699 + return ret ? ret : (*index < end);
18702 +int vc_read_history(uint32_t id, void __user *data)
18704 + struct vcmd_read_history_v0 vc_data;
18707 + if (id >= NR_CPUS)
18710 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18713 + ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
18714 + id, &vc_data.index, &vc_data.count);
18716 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18721 +#ifdef CONFIG_COMPAT
18723 +int vc_read_history_x32(uint32_t id, void __user *data)
18725 + struct vcmd_read_history_v0_x32 vc_data;
18728 + if (id >= NR_CPUS)
18731 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18734 + ret = do_read_history((struct __user _vx_hist_entry *)
18735 + compat_ptr(vc_data.data_ptr),
18736 + id, &vc_data.index, &vc_data.count);
18738 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18743 +#endif /* CONFIG_COMPAT */
18745 diff -NurpP --minimal linux-3.9.4/kernel/vserver/inet.c linux-3.9.4-vs2.3.6.2/kernel/vserver/inet.c
18746 --- linux-3.9.4/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
18747 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/inet.c 2013-05-31 22:43:05.000000000 +0000
18750 +#include <linux/in.h>
18751 +#include <linux/inetdevice.h>
18752 +#include <linux/export.h>
18753 +#include <linux/vs_inet.h>
18754 +#include <linux/vs_inet6.h>
18755 +#include <linux/vserver/debug.h>
18756 +#include <net/route.h>
18757 +#include <net/addrconf.h>
18760 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18764 + if (!nxi1 || !nxi2 || nxi1 == nxi2)
18767 + struct nx_addr_v4 *ptr;
18768 + unsigned long irqflags;
18770 + spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18771 + for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
18772 + if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18777 + spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18780 + vxdprintk(VXD_CBIT(net, 2),
18781 + "nx_v4_addr_conflict(%p,%p): %d",
18782 + nxi1, nxi2, ret);
18788 +#ifdef CONFIG_IPV6
18790 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18794 + if (!nxi1 || !nxi2 || nxi1 == nxi2)
18797 + struct nx_addr_v6 *ptr;
18798 + unsigned long irqflags;
18800 + spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18801 + for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18802 + if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18807 + spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18810 + vxdprintk(VXD_CBIT(net, 2),
18811 + "nx_v6_addr_conflict(%p,%p): %d",
18812 + nxi1, nxi2, ret);
18819 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18821 + struct in_device *in_dev;
18822 + struct in_ifaddr **ifap;
18823 + struct in_ifaddr *ifa;
18828 + in_dev = in_dev_get(dev);
18832 + for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18833 + ifap = &ifa->ifa_next) {
18834 + if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18839 + in_dev_put(in_dev);
18845 +#ifdef CONFIG_IPV6
18847 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18849 + struct inet6_dev *in_dev;
18850 + struct inet6_ifaddr *ifa;
18855 + in_dev = in6_dev_get(dev);
18859 + // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18860 + list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18861 + if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18866 + in6_dev_put(in_dev);
18873 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18879 + if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18881 +#ifdef CONFIG_IPV6
18883 + if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18888 + vxdprintk(VXD_CBIT(net, 3),
18889 + "dev_in_nx_info(%p,%p[#%d]) = %d",
18890 + dev, nxi, nxi ? nxi->nx_id : 0, ret);
18894 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18895 + struct flowi4 *fl4)
18897 + struct rtable *rt;
18902 + /* FIXME: handle lback only case */
18903 + if (!NX_IPV4(nxi))
18904 + return ERR_PTR(-EPERM);
18906 + vxdprintk(VXD_CBIT(net, 4),
18907 + "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18908 + nxi, nxi ? nxi->nx_id : 0,
18909 + NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18911 + /* single IP is unconditional */
18912 + if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18913 + (fl4->saddr == INADDR_ANY))
18914 + fl4->saddr = nxi->v4.ip[0].s_addr;
18916 + if (fl4->saddr == INADDR_ANY) {
18917 + struct nx_addr_v4 *ptr;
18918 + __be32 found = 0;
18920 + rt = __ip_route_output_key(net, fl4);
18921 + if (!IS_ERR(rt)) {
18922 + found = fl4->saddr;
18924 + vxdprintk(VXD_CBIT(net, 4),
18925 + "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18926 + nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18927 + if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18931 + WARN_ON_ONCE(in_irq());
18932 + spin_lock_bh(&nxi->addr_lock);
18933 + for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18934 + __be32 primary = ptr->ip[0].s_addr;
18935 + __be32 mask = ptr->mask.s_addr;
18936 + __be32 neta = primary & mask;
18938 + vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18939 + NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18940 + nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18941 + NIPQUAD(mask), NIPQUAD(neta));
18942 + if ((found & mask) != neta)
18945 + fl4->saddr = primary;
18946 + rt = __ip_route_output_key(net, fl4);
18947 + vxdprintk(VXD_CBIT(net, 4),
18948 + "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18949 + nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18950 + if (!IS_ERR(rt)) {
18951 + found = fl4->saddr;
18953 + if (found == primary)
18954 + goto found_unlock;
18957 + /* still no source ip? */
18958 + found = ipv4_is_loopback(fl4->daddr)
18959 + ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18961 + spin_unlock_bh(&nxi->addr_lock);
18963 + /* assign src ip to flow */
18964 + fl4->saddr = found;
18967 + if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18968 + return ERR_PTR(-EPERM);
18971 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18972 + if (ipv4_is_loopback(fl4->daddr))
18973 + fl4->daddr = nxi->v4_lback.s_addr;
18974 + if (ipv4_is_loopback(fl4->saddr))
18975 + fl4->saddr = nxi->v4_lback.s_addr;
18976 + } else if (ipv4_is_loopback(fl4->daddr) &&
18977 + !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18978 + return ERR_PTR(-EPERM);
18983 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18985 diff -NurpP --minimal linux-3.9.4/kernel/vserver/init.c linux-3.9.4-vs2.3.6.2/kernel/vserver/init.c
18986 --- linux-3.9.4/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
18987 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/init.c 2013-05-31 14:47:11.000000000 +0000
18990 + * linux/kernel/init.c
18992 + * Virtual Server Init
18994 + * Copyright (C) 2004-2007 Herbert Pötzl
18996 + * V0.01 basic structure
19000 +#include <linux/init.h>
19002 +int vserver_register_sysctl(void);
19003 +void vserver_unregister_sysctl(void);
19006 +static int __init init_vserver(void)
19010 +#ifdef CONFIG_VSERVER_DEBUG
19011 + vserver_register_sysctl();
19017 +static void __exit exit_vserver(void)
19020 +#ifdef CONFIG_VSERVER_DEBUG
19021 + vserver_unregister_sysctl();
19026 +/* FIXME: GFP_ZONETYPES gone
19027 +long vx_slab[GFP_ZONETYPES]; */
19031 +module_init(init_vserver);
19032 +module_exit(exit_vserver);
19034 diff -NurpP --minimal linux-3.9.4/kernel/vserver/inode.c linux-3.9.4-vs2.3.6.2/kernel/vserver/inode.c
19035 --- linux-3.9.4/kernel/vserver/inode.c 1970-01-01 00:00:00.000000000 +0000
19036 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/inode.c 2013-06-01 08:26:06.000000000 +0000
19039 + * linux/kernel/vserver/inode.c
19041 + * Virtual Server: File System Support
19043 + * Copyright (C) 2004-2007 Herbert Pötzl
19045 + * V0.01 separated from vcontext V0.05
19046 + * V0.02 moved to tag (instead of xid)
19050 +#include <linux/tty.h>
19051 +#include <linux/proc_fs.h>
19052 +#include <linux/devpts_fs.h>
19053 +#include <linux/fs.h>
19054 +#include <linux/file.h>
19055 +#include <linux/mount.h>
19056 +#include <linux/parser.h>
19057 +#include <linux/namei.h>
19058 +#include <linux/vserver/inode.h>
19059 +#include <linux/vserver/inode_cmd.h>
19060 +#include <linux/vs_base.h>
19061 +#include <linux/vs_tag.h>
19063 +#include <asm/uaccess.h>
19066 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19068 + struct proc_dir_entry *entry;
19070 + if (!in || !in->i_sb)
19073 + *flags = IATTR_TAG
19074 + | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
19075 + | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
19076 + | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
19077 + | (IS_COW(in) ? IATTR_COW : 0);
19078 + *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
19080 + if (S_ISDIR(in->i_mode))
19081 + *mask |= IATTR_BARRIER;
19083 + if (IS_TAGGED(in)) {
19084 + *tag = i_tag_read(in);
19085 + *mask |= IATTR_TAG;
19088 + switch (in->i_sb->s_magic) {
19089 + case PROC_SUPER_MAGIC:
19090 + entry = PROC_I(in)->pde;
19092 + /* check for specific inodes? */
19094 + *mask |= IATTR_FLAGS;
19096 + *flags |= (entry->vx_flags & IATTR_FLAGS);
19098 + *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
19101 + case DEVPTS_SUPER_MAGIC:
19102 + *tag = i_tag_read(in);
19103 + *mask |= IATTR_TAG;
19112 +int vc_get_iattr(void __user *data)
19114 + struct path path;
19115 + struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
19118 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19121 + ret = user_lpath(vc_data.name, &path);
19123 + ret = __vc_get_iattr(path.dentry->d_inode,
19124 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19130 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19135 +#ifdef CONFIG_COMPAT
19137 +int vc_get_iattr_x32(void __user *data)
19139 + struct path path;
19140 + struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
19143 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19146 + ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19148 + ret = __vc_get_iattr(path.dentry->d_inode,
19149 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19155 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19160 +#endif /* CONFIG_COMPAT */
19163 +int vc_fget_iattr(uint32_t fd, void __user *data)
19165 + struct file *filp;
19166 + struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
19169 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19173 + if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19176 + ret = __vc_get_iattr(filp->f_dentry->d_inode,
19177 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19181 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19187 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
19189 + struct inode *in = de->d_inode;
19190 + int error = 0, is_proc = 0, has_tag = 0;
19191 + struct iattr attr = { 0 };
19193 + if (!in || !in->i_sb)
19196 + is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
19197 + if ((*mask & IATTR_FLAGS) && !is_proc)
19200 + has_tag = IS_TAGGED(in) ||
19201 + (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
19202 + if ((*mask & IATTR_TAG) && !has_tag)
19205 + mutex_lock(&in->i_mutex);
19206 + if (*mask & IATTR_TAG) {
19207 + attr.ia_tag = make_ktag(&init_user_ns, *tag);
19208 + attr.ia_valid |= ATTR_TAG;
19211 + if (*mask & IATTR_FLAGS) {
19212 + struct proc_dir_entry *entry = PROC_I(in)->pde;
19213 + unsigned int iflags = PROC_I(in)->vx_flags;
19215 + iflags = (iflags & ~(*mask & IATTR_FLAGS))
19216 + | (*flags & IATTR_FLAGS);
19217 + PROC_I(in)->vx_flags = iflags;
19219 + entry->vx_flags = iflags;
19222 + if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
19223 + IATTR_BARRIER | IATTR_COW)) {
19224 + int iflags = in->i_flags;
19225 + int vflags = in->i_vflags;
19227 + if (*mask & IATTR_IMMUTABLE) {
19228 + if (*flags & IATTR_IMMUTABLE)
19229 + iflags |= S_IMMUTABLE;
19231 + iflags &= ~S_IMMUTABLE;
19233 + if (*mask & IATTR_IXUNLINK) {
19234 + if (*flags & IATTR_IXUNLINK)
19235 + iflags |= S_IXUNLINK;
19237 + iflags &= ~S_IXUNLINK;
19239 + if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
19240 + if (*flags & IATTR_BARRIER)
19241 + vflags |= V_BARRIER;
19243 + vflags &= ~V_BARRIER;
19245 + if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
19246 + if (*flags & IATTR_COW)
19249 + vflags &= ~V_COW;
19251 + if (in->i_op && in->i_op->sync_flags) {
19252 + error = in->i_op->sync_flags(in, iflags, vflags);
19258 + if (attr.ia_valid) {
19259 + if (in->i_op && in->i_op->setattr)
19260 + error = in->i_op->setattr(de, &attr);
19262 + error = inode_change_ok(in, &attr);
19264 + setattr_copy(in, &attr);
19265 + mark_inode_dirty(in);
19271 + mutex_unlock(&in->i_mutex);
19275 +int vc_set_iattr(void __user *data)
19277 + struct path path;
19278 + struct vcmd_ctx_iattr_v1 vc_data;
19281 + if (!capable(CAP_LINUX_IMMUTABLE))
19283 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19286 + ret = user_lpath(vc_data.name, &path);
19288 + ret = __vc_set_iattr(path.dentry,
19289 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19293 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19298 +#ifdef CONFIG_COMPAT
19300 +int vc_set_iattr_x32(void __user *data)
19302 + struct path path;
19303 + struct vcmd_ctx_iattr_v1_x32 vc_data;
19306 + if (!capable(CAP_LINUX_IMMUTABLE))
19308 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19311 + ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
19313 + ret = __vc_set_iattr(path.dentry,
19314 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
19318 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19323 +#endif /* CONFIG_COMPAT */
19325 +int vc_fset_iattr(uint32_t fd, void __user *data)
19327 + struct file *filp;
19328 + struct vcmd_ctx_fiattr_v0 vc_data;
19331 + if (!capable(CAP_LINUX_IMMUTABLE))
19333 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19337 + if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
19340 + ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
19341 + &vc_data.flags, &vc_data.mask);
19345 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19351 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
19353 +static match_table_t tokens = {
19354 + {Opt_notagcheck, "notagcheck"},
19355 +#ifdef CONFIG_PROPAGATE
19356 + {Opt_notag, "notag"},
19357 + {Opt_tag, "tag"},
19358 + {Opt_tagid, "tagid=%u"},
19364 +static void __dx_parse_remove(char *string, char *opt)
19366 + char *p = strstr(string, opt);
19370 + while (*q != '\0' && *q != ',')
19379 +int dx_parse_tag(char *string, tag_t *tag, int remove, int *mnt_flags,
19380 + unsigned long *flags)
19383 + substring_t args[MAX_OPT_ARGS];
19385 + char *s, *p, *opts;
19386 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
19392 + s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
19397 + while ((p = strsep(&opts, ",")) != NULL) {
19398 + token = match_token(p, tokens, args);
19401 +#ifdef CONFIG_PROPAGATE
19406 + __dx_parse_remove(s, "tag");
19407 + *mnt_flags |= MNT_TAGID;
19408 + set |= MNT_TAGID;
19412 + __dx_parse_remove(s, "notag");
19413 + *mnt_flags |= MNT_NOTAG;
19414 + set |= MNT_NOTAG;
19417 + if (tag && !match_int(args, &option))
19420 + __dx_parse_remove(s, "tagid");
19421 + *mnt_flags |= MNT_TAGID;
19422 + set |= MNT_TAGID;
19424 +#endif /* CONFIG_PROPAGATE */
19425 + case Opt_notagcheck:
19427 + __dx_parse_remove(s, "notagcheck");
19428 + *flags |= MS_NOTAGCHECK;
19429 + set |= MS_NOTAGCHECK;
19432 + vxdprintk(VXD_CBIT(tag, 7),
19433 + "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
19434 + p, token, option);
19437 + strcpy(string, s);
19442 +#ifdef CONFIG_PROPAGATE
19444 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
19446 + tag_t new_tag = 0;
19447 + struct vfsmount *mnt;
19452 + mnt = nd->path.mnt;
19456 + propagate = (mnt->mnt_flags & MNT_TAGID);
19458 + new_tag = mnt->mnt_tag;
19460 + vxdprintk(VXD_CBIT(tag, 7),
19461 + "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
19462 + inode, inode->i_ino, inode->i_tag,
19463 + new_tag, (propagate) ? 1 : 0);
19466 + i_tag_write(inode, new_tag);
19469 +#include <linux/module.h>
19471 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
19473 +#endif /* CONFIG_PROPAGATE */
19475 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit.c linux-3.9.4-vs2.3.6.2/kernel/vserver/limit.c
19476 --- linux-3.9.4/kernel/vserver/limit.c 1970-01-01 00:00:00.000000000 +0000
19477 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/limit.c 2013-05-31 14:47:11.000000000 +0000
19480 + * linux/kernel/vserver/limit.c
19482 + * Virtual Server: Context Limits
19484 + * Copyright (C) 2004-2010 Herbert Pötzl
19486 + * V0.01 broken out from vcontext V0.05
19487 + * V0.02 changed vcmds to vxi arg
19488 + * V0.03 added memory cgroup support
19492 +#include <linux/sched.h>
19493 +#include <linux/module.h>
19494 +#include <linux/memcontrol.h>
19495 +#include <linux/res_counter.h>
19496 +#include <linux/vs_limit.h>
19497 +#include <linux/vserver/limit.h>
19498 +#include <linux/vserver/limit_cmd.h>
19500 +#include <asm/uaccess.h>
19503 +const char *vlimit_name[NUM_LIMITS] = {
19504 + [RLIMIT_CPU] = "CPU",
19505 + [RLIMIT_NPROC] = "NPROC",
19506 + [RLIMIT_NOFILE] = "NOFILE",
19507 + [RLIMIT_LOCKS] = "LOCKS",
19508 + [RLIMIT_SIGPENDING] = "SIGP",
19509 + [RLIMIT_MSGQUEUE] = "MSGQ",
19511 + [VLIMIT_NSOCK] = "NSOCK",
19512 + [VLIMIT_OPENFD] = "OPENFD",
19513 + [VLIMIT_SHMEM] = "SHMEM",
19514 + [VLIMIT_DENTRY] = "DENTRY",
19517 +EXPORT_SYMBOL_GPL(vlimit_name);
19519 +#define MASK_ENTRY(x) (1 << (x))
19521 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
19524 + , /* softlimit */
19527 + MASK_ENTRY( RLIMIT_NPROC ) |
19528 + MASK_ENTRY( RLIMIT_NOFILE ) |
19529 + MASK_ENTRY( RLIMIT_LOCKS ) |
19530 + MASK_ENTRY( RLIMIT_MSGQUEUE ) |
19532 + MASK_ENTRY( VLIMIT_NSOCK ) |
19533 + MASK_ENTRY( VLIMIT_OPENFD ) |
19534 + MASK_ENTRY( VLIMIT_SHMEM ) |
19535 + MASK_ENTRY( VLIMIT_DENTRY ) |
19538 + /* accounting only */
19539 +uint32_t account_mask =
19540 + MASK_ENTRY( VLIMIT_SEMARY ) |
19541 + MASK_ENTRY( VLIMIT_NSEMS ) |
19542 + MASK_ENTRY( VLIMIT_MAPPED ) |
19546 +static int is_valid_vlimit(int id)
19548 + uint32_t mask = vlimit_mask.minimum |
19549 + vlimit_mask.softlimit | vlimit_mask.maximum;
19550 + return mask & (1 << id);
19553 +static int is_accounted_vlimit(int id)
19555 + if (is_valid_vlimit(id))
19557 + return account_mask & (1 << id);
19561 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
19563 + rlim_t limit = __rlim_soft(&vxi->limit, id);
19564 + return VX_VLIM(limit);
19567 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
19569 + rlim_t limit = __rlim_hard(&vxi->limit, id);
19570 + return VX_VLIM(limit);
19573 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
19574 + uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
19576 + if (!is_valid_vlimit(id))
19580 + *minimum = CRLIM_UNSET;
19582 + *softlimit = vc_get_soft(vxi, id);
19584 + *maximum = vc_get_hard(vxi, id);
19588 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
19590 + struct vcmd_ctx_rlimit_v0 vc_data;
19593 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19596 + ret = do_get_rlimit(vxi, vc_data.id,
19597 + &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19601 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19606 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
19607 + uint64_t minimum, uint64_t softlimit, uint64_t maximum)
19609 + if (!is_valid_vlimit(id))
19612 + if (maximum != CRLIM_KEEP)
19613 + __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
19614 + if (softlimit != CRLIM_KEEP)
19615 + __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
19617 + /* clamp soft limit */
19618 + if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
19619 + __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
19624 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
19626 + struct vcmd_ctx_rlimit_v0 vc_data;
19628 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19631 + return do_set_rlimit(vxi, vc_data.id,
19632 + vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19635 +#ifdef CONFIG_IA32_EMULATION
19637 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
19639 + struct vcmd_ctx_rlimit_v0_x32 vc_data;
19641 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19644 + return do_set_rlimit(vxi, vc_data.id,
19645 + vc_data.minimum, vc_data.softlimit, vc_data.maximum);
19648 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
19650 + struct vcmd_ctx_rlimit_v0_x32 vc_data;
19653 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19656 + ret = do_get_rlimit(vxi, vc_data.id,
19657 + &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
19661 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19666 +#endif /* CONFIG_IA32_EMULATION */
19669 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
19671 + if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
19677 +static inline void vx_reset_hits(struct _vx_limit *limit)
19681 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19682 + atomic_set(&__rlim_lhit(limit, lim), 0);
19686 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
19688 + vx_reset_hits(&vxi->limit);
19692 +static inline void vx_reset_minmax(struct _vx_limit *limit)
19697 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19698 + value = __rlim_get(limit, lim);
19699 + __rlim_rmax(limit, lim) = value;
19700 + __rlim_rmin(limit, lim) = value;
19704 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
19706 + vx_reset_minmax(&vxi->limit);
19711 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
19713 + struct vcmd_rlimit_stat_v0 vc_data;
19714 + struct _vx_limit *limit = &vxi->limit;
19717 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
19721 + if (!is_accounted_vlimit(id))
19724 + vx_limit_fixup(limit, id);
19725 + vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
19726 + vc_data.value = __rlim_get(limit, id);
19727 + vc_data.minimum = __rlim_rmin(limit, id);
19728 + vc_data.maximum = __rlim_rmax(limit, id);
19730 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19736 +void vx_vsi_meminfo(struct sysinfo *val)
19738 +#ifdef CONFIG_MEMCG
19739 + struct mem_cgroup *mcg;
19740 + u64 res_limit, res_usage;
19743 + mcg = mem_cgroup_from_task(current);
19744 + rcu_read_unlock();
19748 + res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19749 + res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19751 + if (res_limit != RESOURCE_MAX)
19752 + val->totalram = (res_limit >> PAGE_SHIFT);
19753 + val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
19754 + val->bufferram = 0;
19755 + val->totalhigh = 0;
19756 + val->freehigh = 0;
19758 +#endif /* CONFIG_MEMCG */
19762 +void vx_vsi_swapinfo(struct sysinfo *val)
19764 +#ifdef CONFIG_MEMCG
19765 +#ifdef CONFIG_MEMCG_SWAP
19766 + struct mem_cgroup *mcg;
19767 + u64 res_limit, res_usage, memsw_limit, memsw_usage;
19768 + s64 swap_limit, swap_usage;
19771 + mcg = mem_cgroup_from_task(current);
19772 + rcu_read_unlock();
19776 + res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19777 + res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19778 + memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19779 + memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19781 + /* memory unlimited */
19782 + if (res_limit == RESOURCE_MAX)
19785 + swap_limit = memsw_limit - res_limit;
19786 + /* we have a swap limit? */
19787 + if (memsw_limit != RESOURCE_MAX)
19788 + val->totalswap = swap_limit >> PAGE_SHIFT;
19790 + /* calculate swap part */
19791 + swap_usage = (memsw_usage > res_usage) ?
19792 + memsw_usage - res_usage : 0;
19794 + /* total shown minus usage gives free swap */
19795 + val->freeswap = (swap_usage < swap_limit) ?
19796 + val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19798 +#else /* !CONFIG_MEMCG_SWAP */
19799 + val->totalswap = 0;
19800 + val->freeswap = 0;
19801 +#endif /* !CONFIG_MEMCG_SWAP */
19802 +#endif /* CONFIG_MEMCG */
19806 +long vx_vsi_cached(struct sysinfo *val)
19809 +#ifdef CONFIG_MEMCG
19810 + struct mem_cgroup *mcg;
19813 + mcg = mem_cgroup_from_task(current);
19814 + rcu_read_unlock();
19818 + cache = mem_cgroup_stat_read_cache(mcg);
19824 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit_init.h linux-3.9.4-vs2.3.6.2/kernel/vserver/limit_init.h
19825 --- linux-3.9.4/kernel/vserver/limit_init.h 1970-01-01 00:00:00.000000000 +0000
19826 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/limit_init.h 2013-05-31 14:47:11.000000000 +0000
19830 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19834 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19835 + __rlim_soft(limit, lim) = RLIM_INFINITY;
19836 + __rlim_hard(limit, lim) = RLIM_INFINITY;
19837 + __rlim_set(limit, lim, 0);
19838 + atomic_set(&__rlim_lhit(limit, lim), 0);
19839 + __rlim_rmin(limit, lim) = 0;
19840 + __rlim_rmax(limit, lim) = 0;
19844 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19849 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19850 + if ((1 << lim) & VLIM_NOCHECK)
19852 + value = __rlim_get(limit, lim);
19853 + vxwprintk_xid(value,
19854 + "!!! limit: %p[%s,%d] = %ld on exit.",
19855 + limit, vlimit_name[lim], lim, (long)value);
19859 diff -NurpP --minimal linux-3.9.4/kernel/vserver/limit_proc.h linux-3.9.4-vs2.3.6.2/kernel/vserver/limit_proc.h
19860 --- linux-3.9.4/kernel/vserver/limit_proc.h 1970-01-01 00:00:00.000000000 +0000
19861 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/limit_proc.h 2013-05-31 14:47:11.000000000 +0000
19863 +#ifndef _VX_LIMIT_PROC_H
19864 +#define _VX_LIMIT_PROC_H
19866 +#include <linux/vserver/limit_int.h>
19869 +#define VX_LIMIT_FMT ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19870 +#define VX_LIMIT_TOP \
19871 + "Limit\t current\t min/max\t\t soft/hard\t\thits\n"
19873 +#define VX_LIMIT_ARG(r) \
19874 + (unsigned long)__rlim_get(limit, r), \
19875 + (unsigned long)__rlim_rmin(limit, r), \
19876 + (unsigned long)__rlim_rmax(limit, r), \
19877 + VX_VLIM(__rlim_soft(limit, r)), \
19878 + VX_VLIM(__rlim_hard(limit, r)), \
19879 + atomic_read(&__rlim_lhit(limit, r))
19881 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19883 + vx_limit_fixup(limit, -1);
19884 + return sprintf(buffer, VX_LIMIT_TOP
19885 + "PROC" VX_LIMIT_FMT
19886 + "VM" VX_LIMIT_FMT
19887 + "VML" VX_LIMIT_FMT
19888 + "RSS" VX_LIMIT_FMT
19889 + "ANON" VX_LIMIT_FMT
19890 + "RMAP" VX_LIMIT_FMT
19891 + "FILES" VX_LIMIT_FMT
19892 + "OFD" VX_LIMIT_FMT
19893 + "LOCKS" VX_LIMIT_FMT
19894 + "SOCK" VX_LIMIT_FMT
19895 + "MSGQ" VX_LIMIT_FMT
19896 + "SHM" VX_LIMIT_FMT
19897 + "SEMA" VX_LIMIT_FMT
19898 + "SEMS" VX_LIMIT_FMT
19899 + "DENT" VX_LIMIT_FMT,
19900 + VX_LIMIT_ARG(RLIMIT_NPROC),
19901 + VX_LIMIT_ARG(RLIMIT_AS),
19902 + VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19903 + VX_LIMIT_ARG(RLIMIT_RSS),
19904 + VX_LIMIT_ARG(VLIMIT_ANON),
19905 + VX_LIMIT_ARG(VLIMIT_MAPPED),
19906 + VX_LIMIT_ARG(RLIMIT_NOFILE),
19907 + VX_LIMIT_ARG(VLIMIT_OPENFD),
19908 + VX_LIMIT_ARG(RLIMIT_LOCKS),
19909 + VX_LIMIT_ARG(VLIMIT_NSOCK),
19910 + VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19911 + VX_LIMIT_ARG(VLIMIT_SHMEM),
19912 + VX_LIMIT_ARG(VLIMIT_SEMARY),
19913 + VX_LIMIT_ARG(VLIMIT_NSEMS),
19914 + VX_LIMIT_ARG(VLIMIT_DENTRY));
19917 +#endif /* _VX_LIMIT_PROC_H */
19920 diff -NurpP --minimal linux-3.9.4/kernel/vserver/network.c linux-3.9.4-vs2.3.6.2/kernel/vserver/network.c
19921 --- linux-3.9.4/kernel/vserver/network.c 1970-01-01 00:00:00.000000000 +0000
19922 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/network.c 2013-05-31 14:47:11.000000000 +0000
19925 + * linux/kernel/vserver/network.c
19927 + * Virtual Server: Network Support
19929 + * Copyright (C) 2003-2007 Herbert Pötzl
19931 + * V0.01 broken out from vcontext V0.05
19932 + * V0.02 cleaned up implementation
19933 + * V0.03 added equiv nx commands
19934 + * V0.04 switch to RCU based hash
19935 + * V0.05 and back to locking again
19936 + * V0.06 changed vcmds to nxi arg
19937 + * V0.07 have __create claim() the nxi
19941 +#include <linux/err.h>
19942 +#include <linux/slab.h>
19943 +#include <linux/rcupdate.h>
19944 +#include <net/ipv6.h>
19946 +#include <linux/vs_network.h>
19947 +#include <linux/vs_pid.h>
19948 +#include <linux/vserver/network_cmd.h>
19951 +atomic_t nx_global_ctotal = ATOMIC_INIT(0);
19952 +atomic_t nx_global_cactive = ATOMIC_INIT(0);
19954 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19955 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19958 +static int __init init_network(void)
19960 + nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19961 + sizeof(struct nx_addr_v4), 0,
19962 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19963 + nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19964 + sizeof(struct nx_addr_v6), 0,
19965 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19970 +/* __alloc_nx_addr_v4() */
19972 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19974 + struct nx_addr_v4 *nxa = kmem_cache_alloc(
19975 + nx_addr_v4_cachep, GFP_KERNEL);
19977 + if (!IS_ERR(nxa))
19978 + memset(nxa, 0, sizeof(*nxa));
19982 +/* __dealloc_nx_addr_v4() */
19984 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19986 + kmem_cache_free(nx_addr_v4_cachep, nxa);
19989 +/* __dealloc_nx_addr_v4_all() */
19991 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19994 + struct nx_addr_v4 *next = nxa->next;
19996 + __dealloc_nx_addr_v4(nxa);
20002 +#ifdef CONFIG_IPV6
20004 +/* __alloc_nx_addr_v6() */
20006 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
20008 + struct nx_addr_v6 *nxa = kmem_cache_alloc(
20009 + nx_addr_v6_cachep, GFP_KERNEL);
20011 + if (!IS_ERR(nxa))
20012 + memset(nxa, 0, sizeof(*nxa));
20016 +/* __dealloc_nx_addr_v6() */
20018 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
20020 + kmem_cache_free(nx_addr_v6_cachep, nxa);
20023 +/* __dealloc_nx_addr_v6_all() */
20025 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
20028 + struct nx_addr_v6 *next = nxa->next;
20030 + __dealloc_nx_addr_v6(nxa);
20035 +#endif /* CONFIG_IPV6 */
20037 +/* __alloc_nx_info()
20039 + * allocate an initialized nx_info struct
20040 + * doesn't make it visible (hash) */
20042 +static struct nx_info *__alloc_nx_info(nid_t nid)
20044 + struct nx_info *new = NULL;
20046 + vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
20048 + /* would this benefit from a slab cache? */
20049 + new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
20053 + memset(new, 0, sizeof(struct nx_info));
20054 + new->nx_id = nid;
20055 + INIT_HLIST_NODE(&new->nx_hlist);
20056 + atomic_set(&new->nx_usecnt, 0);
20057 + atomic_set(&new->nx_tasks, 0);
20058 + spin_lock_init(&new->addr_lock);
20059 + new->nx_state = 0;
20061 + new->nx_flags = NXF_INIT_SET;
20063 + /* rest of init goes here */
20065 + new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
20066 + new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
20068 + vxdprintk(VXD_CBIT(nid, 0),
20069 + "alloc_nx_info(%d) = %p", nid, new);
20070 + atomic_inc(&nx_global_ctotal);
20074 +/* __dealloc_nx_info()
20076 + * final disposal of nx_info */
20078 +static void __dealloc_nx_info(struct nx_info *nxi)
20080 + vxdprintk(VXD_CBIT(nid, 0),
20081 + "dealloc_nx_info(%p)", nxi);
20083 + nxi->nx_hlist.next = LIST_POISON1;
20086 + BUG_ON(atomic_read(&nxi->nx_usecnt));
20087 + BUG_ON(atomic_read(&nxi->nx_tasks));
20089 + __dealloc_nx_addr_v4_all(nxi->v4.next);
20090 +#ifdef CONFIG_IPV6
20091 + __dealloc_nx_addr_v6_all(nxi->v6.next);
20094 + nxi->nx_state |= NXS_RELEASED;
20096 + atomic_dec(&nx_global_ctotal);
20099 +static void __shutdown_nx_info(struct nx_info *nxi)
20101 + nxi->nx_state |= NXS_SHUTDOWN;
20102 + vs_net_change(nxi, VSC_NETDOWN);
20105 +/* exported stuff */
20107 +void free_nx_info(struct nx_info *nxi)
20109 + /* context shutdown is mandatory */
20110 + BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
20112 + /* context must not be hashed */
20113 + BUG_ON(nxi->nx_state & NXS_HASHED);
20115 + BUG_ON(atomic_read(&nxi->nx_usecnt));
20116 + BUG_ON(atomic_read(&nxi->nx_tasks));
20118 + __dealloc_nx_info(nxi);
20122 +void __nx_set_lback(struct nx_info *nxi)
20124 + int nid = nxi->nx_id;
20125 + __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
20127 + nxi->v4_lback.s_addr = lback;
20130 +extern int __nx_inet_add_lback(__be32 addr);
20131 +extern int __nx_inet_del_lback(__be32 addr);
20134 +/* hash table for nx_info hash */
20136 +#define NX_HASH_SIZE 13
20138 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
20140 +static DEFINE_SPINLOCK(nx_info_hash_lock);
20143 +static inline unsigned int __hashval(nid_t nid)
20145 + return (nid % NX_HASH_SIZE);
20150 +/* __hash_nx_info()
20152 + * add the nxi to the global hash table
20153 + * requires the hash_lock to be held */
20155 +static inline void __hash_nx_info(struct nx_info *nxi)
20157 + struct hlist_head *head;
20159 + vxd_assert_lock(&nx_info_hash_lock);
20160 + vxdprintk(VXD_CBIT(nid, 4),
20161 + "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
20163 + /* context must not be hashed */
20164 + BUG_ON(nx_info_state(nxi, NXS_HASHED));
20166 + nxi->nx_state |= NXS_HASHED;
20167 + head = &nx_info_hash[__hashval(nxi->nx_id)];
20168 + hlist_add_head(&nxi->nx_hlist, head);
20169 + atomic_inc(&nx_global_cactive);
20172 +/* __unhash_nx_info()
20174 + * remove the nxi from the global hash table
20175 + * requires the hash_lock to be held */
20177 +static inline void __unhash_nx_info(struct nx_info *nxi)
20179 + vxd_assert_lock(&nx_info_hash_lock);
20180 + vxdprintk(VXD_CBIT(nid, 4),
20181 + "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
20182 + atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
20184 + /* context must be hashed */
20185 + BUG_ON(!nx_info_state(nxi, NXS_HASHED));
20186 + /* but without tasks */
20187 + BUG_ON(atomic_read(&nxi->nx_tasks));
20189 + nxi->nx_state &= ~NXS_HASHED;
20190 + hlist_del(&nxi->nx_hlist);
20191 + atomic_dec(&nx_global_cactive);
20195 +/* __lookup_nx_info()
20197 + * requires the hash_lock to be held
20198 + * doesn't increment the nx_refcnt */
20200 +static inline struct nx_info *__lookup_nx_info(nid_t nid)
20202 + struct hlist_head *head = &nx_info_hash[__hashval(nid)];
20203 + struct hlist_node *pos;
20204 + struct nx_info *nxi;
20206 + vxd_assert_lock(&nx_info_hash_lock);
20207 + hlist_for_each(pos, head) {
20208 + nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20210 + if (nxi->nx_id == nid)
20215 + vxdprintk(VXD_CBIT(nid, 0),
20216 + "__lookup_nx_info(#%u): %p[#%u]",
20217 + nid, nxi, nxi ? nxi->nx_id : 0);
20222 +/* __create_nx_info()
20224 + * create the requested context
20225 + * get(), claim() and hash it */
20227 +static struct nx_info *__create_nx_info(int id)
20229 + struct nx_info *new, *nxi = NULL;
20231 + vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
20233 + if (!(new = __alloc_nx_info(id)))
20234 + return ERR_PTR(-ENOMEM);
20236 + /* required to make dynamic xids unique */
20237 + spin_lock(&nx_info_hash_lock);
20239 + /* static context requested */
20240 + if ((nxi = __lookup_nx_info(id))) {
20241 + vxdprintk(VXD_CBIT(nid, 0),
20242 + "create_nx_info(%d) = %p (already there)", id, nxi);
20243 + if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20244 + nxi = ERR_PTR(-EBUSY);
20246 + nxi = ERR_PTR(-EEXIST);
20249 + /* new context */
20250 + vxdprintk(VXD_CBIT(nid, 0),
20251 + "create_nx_info(%d) = %p (new)", id, new);
20252 + claim_nx_info(new, NULL);
20253 + __nx_set_lback(new);
20254 + __hash_nx_info(get_nx_info(new));
20255 + nxi = new, new = NULL;
20258 + spin_unlock(&nx_info_hash_lock);
20260 + __dealloc_nx_info(new);
20266 +/* exported stuff */
20269 +void unhash_nx_info(struct nx_info *nxi)
20271 + __shutdown_nx_info(nxi);
20272 + spin_lock(&nx_info_hash_lock);
20273 + __unhash_nx_info(nxi);
20274 + spin_unlock(&nx_info_hash_lock);
20277 +/* lookup_nx_info()
20279 + * search for a nx_info and get() it
20280 + * negative id means current */
20282 +struct nx_info *lookup_nx_info(int id)
20284 + struct nx_info *nxi = NULL;
20287 + nxi = get_nx_info(current_nx_info());
20288 + } else if (id > 1) {
20289 + spin_lock(&nx_info_hash_lock);
20290 + nxi = get_nx_info(__lookup_nx_info(id));
20291 + spin_unlock(&nx_info_hash_lock);
20296 +/* nid_is_hashed()
20298 + * verify that nid is still hashed */
20300 +int nid_is_hashed(nid_t nid)
20304 + spin_lock(&nx_info_hash_lock);
20305 + hashed = (__lookup_nx_info(nid) != NULL);
20306 + spin_unlock(&nx_info_hash_lock);
20311 +#ifdef CONFIG_PROC_FS
20315 + * get a subset of hashed nids for proc
20316 + * assumes size is at least one */
20318 +int get_nid_list(int index, unsigned int *nids, int size)
20320 + int hindex, nr_nids = 0;
20322 + /* only show current and children */
20323 + if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
20326 + nids[nr_nids] = nx_current_nid();
20330 + for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
20331 + struct hlist_head *head = &nx_info_hash[hindex];
20332 + struct hlist_node *pos;
20334 + spin_lock(&nx_info_hash_lock);
20335 + hlist_for_each(pos, head) {
20336 + struct nx_info *nxi;
20341 + nxi = hlist_entry(pos, struct nx_info, nx_hlist);
20342 + nids[nr_nids] = nxi->nx_id;
20343 + if (++nr_nids >= size) {
20344 + spin_unlock(&nx_info_hash_lock);
20348 + /* keep the lock time short */
20349 + spin_unlock(&nx_info_hash_lock);
20358 + * migrate task to new network
20359 + * gets nxi, puts old_nxi on change
20362 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
20364 + struct nx_info *old_nxi;
20370 + vxdprintk(VXD_CBIT(nid, 5),
20371 + "nx_migrate_task(%p,%p[#%d.%d.%d])",
20372 + p, nxi, nxi->nx_id,
20373 + atomic_read(&nxi->nx_usecnt),
20374 + atomic_read(&nxi->nx_tasks));
20376 + if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
20377 + !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
20380 + if (nx_info_state(nxi, NXS_SHUTDOWN))
20383 + /* maybe disallow this completely? */
20384 + old_nxi = task_get_nx_info(p);
20385 + if (old_nxi == nxi)
20390 + clr_nx_info(&p->nx_info);
20391 + claim_nx_info(nxi, p);
20392 + set_nx_info(&p->nx_info, nxi);
20393 + p->nid = nxi->nx_id;
20396 + vxdprintk(VXD_CBIT(nid, 5),
20397 + "moved task %p into nxi:%p[#%d]",
20398 + p, nxi, nxi->nx_id);
20401 + release_nx_info(old_nxi, p);
20404 + put_nx_info(old_nxi);
20409 +void nx_set_persistent(struct nx_info *nxi)
20411 + vxdprintk(VXD_CBIT(nid, 6),
20412 + "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
20414 + get_nx_info(nxi);
20415 + claim_nx_info(nxi, NULL);
20418 +void nx_clear_persistent(struct nx_info *nxi)
20420 + vxdprintk(VXD_CBIT(nid, 6),
20421 + "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
20423 + release_nx_info(nxi, NULL);
20424 + put_nx_info(nxi);
20427 +void nx_update_persistent(struct nx_info *nxi)
20429 + if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
20430 + nx_set_persistent(nxi);
20432 + nx_clear_persistent(nxi);
20435 +/* vserver syscall commands below here */
20437 +/* taks nid and nx_info functions */
20439 +#include <asm/uaccess.h>
20442 +int vc_task_nid(uint32_t id)
20447 + struct task_struct *tsk;
20450 + tsk = find_task_by_real_pid(id);
20451 + nid = (tsk) ? tsk->nid : -ESRCH;
20452 + rcu_read_unlock();
20454 + nid = nx_current_nid();
20459 +int vc_nx_info(struct nx_info *nxi, void __user *data)
20461 + struct vcmd_nx_info_v0 vc_data;
20463 + vc_data.nid = nxi->nx_id;
20465 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20471 +/* network functions */
20473 +int vc_net_create(uint32_t nid, void __user *data)
20475 + struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
20476 + struct nx_info *new_nxi;
20479 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20482 + if ((nid > MAX_S_CONTEXT) || (nid < 2))
20485 + new_nxi = __create_nx_info(nid);
20486 + if (IS_ERR(new_nxi))
20487 + return PTR_ERR(new_nxi);
20489 + /* initial flags */
20490 + new_nxi->nx_flags = vc_data.flagword;
20493 + if (vs_net_change(new_nxi, VSC_NETUP))
20496 + ret = nx_migrate_task(current, new_nxi);
20500 + /* return context id on success */
20501 + ret = new_nxi->nx_id;
20503 + /* get a reference for persistent contexts */
20504 + if ((vc_data.flagword & NXF_PERSISTENT))
20505 + nx_set_persistent(new_nxi);
20507 + release_nx_info(new_nxi, NULL);
20508 + put_nx_info(new_nxi);
20513 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
20515 + return nx_migrate_task(current, nxi);
20520 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
20521 + __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
20522 + struct nx_addr_v4 **prev)
20524 + struct nx_addr_v4 *nxa = &nxi->v4;
20526 + for (; nxa; nxa = nxa->next) {
20527 + if ((nxa->ip[0].s_addr == ip) &&
20528 + (nxa->ip[1].s_addr == ip2) &&
20529 + (nxa->mask.s_addr == mask) &&
20530 + (nxa->type == type) &&
20531 + (nxa->flags == flags))
20534 + /* save previous entry */
20541 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20542 + uint16_t type, uint16_t flags)
20544 + struct nx_addr_v4 *nxa = NULL;
20545 + struct nx_addr_v4 *new = __alloc_nx_addr_v4();
20546 + unsigned long irqflags;
20547 + int ret = -EEXIST;
20550 + return PTR_ERR(new);
20552 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20553 + if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
20556 + if (NX_IPV4(nxi)) {
20561 + /* remove single ip for ip list */
20562 + nxi->nx_flags &= ~NXF_SINGLE_IP;
20565 + nxa->ip[0].s_addr = ip;
20566 + nxa->ip[1].s_addr = ip2;
20567 + nxa->mask.s_addr = mask;
20568 + nxa->type = type;
20569 + nxa->flags = flags;
20572 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20574 + __dealloc_nx_addr_v4(new);
20578 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
20579 + uint16_t type, uint16_t flags)
20581 + struct nx_addr_v4 *nxa = NULL;
20582 + struct nx_addr_v4 *old = NULL;
20583 + unsigned long irqflags;
20586 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20588 + case NXA_TYPE_ADDR:
20589 + old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
20592 + nxa->next = old->next;
20593 + old->next = NULL;
20599 + old->next = NULL;
20601 + memset(old, 0, sizeof(*old));
20609 + case NXA_TYPE_ANY:
20612 + memset(nxa, 0, sizeof(*nxa));
20618 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20619 + __dealloc_nx_addr_v4_all(old);
20624 +int vc_net_add(struct nx_info *nxi, void __user *data)
20626 + struct vcmd_net_addr_v0 vc_data;
20627 + int index, ret = 0;
20629 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20632 + switch (vc_data.type) {
20633 + case NXA_TYPE_IPV4:
20634 + if ((vc_data.count < 1) || (vc_data.count > 4))
20638 + while (index < vc_data.count) {
20639 + ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
20640 + vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
20648 + case NXA_TYPE_IPV4|NXA_MOD_BCAST:
20649 + nxi->v4_bcast = vc_data.ip[0];
20653 + case NXA_TYPE_IPV4|NXA_MOD_LBACK:
20654 + nxi->v4_lback = vc_data.ip[0];
20665 +int vc_net_remove(struct nx_info *nxi, void __user *data)
20667 + struct vcmd_net_addr_v0 vc_data;
20669 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20672 + switch (vc_data.type) {
20673 + case NXA_TYPE_ANY:
20674 + return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
20682 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
20684 + struct vcmd_net_addr_ipv4_v1 vc_data;
20686 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20689 + switch (vc_data.type) {
20690 + case NXA_TYPE_ADDR:
20691 + case NXA_TYPE_MASK:
20692 + return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
20693 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20695 + case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20696 + nxi->v4_bcast = vc_data.ip;
20699 + case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20700 + nxi->v4_lback = vc_data.ip;
20709 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
20711 + struct vcmd_net_addr_ipv4_v2 vc_data;
20713 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20716 + switch (vc_data.type) {
20717 + case NXA_TYPE_ADDR:
20718 + case NXA_TYPE_MASK:
20719 + case NXA_TYPE_RANGE:
20720 + return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20721 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20723 + case NXA_TYPE_ADDR | NXA_MOD_BCAST:
20724 + nxi->v4_bcast = vc_data.ip;
20727 + case NXA_TYPE_ADDR | NXA_MOD_LBACK:
20728 + nxi->v4_lback = vc_data.ip;
20737 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
20739 + struct vcmd_net_addr_ipv4_v1 vc_data;
20741 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20744 + return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
20745 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20748 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
20750 + struct vcmd_net_addr_ipv4_v2 vc_data;
20752 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20755 + return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
20756 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
20759 +#ifdef CONFIG_IPV6
20762 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
20763 + struct in6_addr *ip, struct in6_addr *mask,
20764 + uint32_t prefix, uint16_t type, uint16_t flags,
20765 + struct nx_addr_v6 **prev)
20767 + struct nx_addr_v6 *nxa = &nxi->v6;
20769 + for (; nxa; nxa = nxa->next) {
20770 + if (ipv6_addr_equal(&nxa->ip, ip) &&
20771 + ipv6_addr_equal(&nxa->mask, mask) &&
20772 + (nxa->prefix == prefix) &&
20773 + (nxa->type == type) &&
20774 + (nxa->flags == flags))
20777 + /* save previous entry */
20785 +int do_add_v6_addr(struct nx_info *nxi,
20786 + struct in6_addr *ip, struct in6_addr *mask,
20787 + uint32_t prefix, uint16_t type, uint16_t flags)
20789 + struct nx_addr_v6 *nxa = NULL;
20790 + struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20791 + unsigned long irqflags;
20792 + int ret = -EEXIST;
20795 + return PTR_ERR(new);
20797 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20798 + if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20801 + if (NX_IPV6(nxi)) {
20808 + nxa->mask = *mask;
20809 + nxa->prefix = prefix;
20810 + nxa->type = type;
20811 + nxa->flags = flags;
20814 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20816 + __dealloc_nx_addr_v6(new);
20820 +int do_remove_v6_addr(struct nx_info *nxi,
20821 + struct in6_addr *ip, struct in6_addr *mask,
20822 + uint32_t prefix, uint16_t type, uint16_t flags)
20824 + struct nx_addr_v6 *nxa = NULL;
20825 + struct nx_addr_v6 *old = NULL;
20826 + unsigned long irqflags;
20829 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20831 + case NXA_TYPE_ADDR:
20832 + old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20835 + nxa->next = old->next;
20836 + old->next = NULL;
20842 + old->next = NULL;
20844 + memset(old, 0, sizeof(*old));
20852 + case NXA_TYPE_ANY:
20855 + memset(nxa, 0, sizeof(*nxa));
20861 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20862 + __dealloc_nx_addr_v6_all(old);
20866 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20868 + struct vcmd_net_addr_ipv6_v1 vc_data;
20870 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20873 + switch (vc_data.type) {
20874 + case NXA_TYPE_ADDR:
20875 + memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20876 + /* fallthrough */
20877 + case NXA_TYPE_MASK:
20878 + return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20879 + vc_data.prefix, vc_data.type, vc_data.flags);
20886 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20888 + struct vcmd_net_addr_ipv6_v1 vc_data;
20890 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20893 + switch (vc_data.type) {
20894 + case NXA_TYPE_ADDR:
20895 + memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20896 + /* fallthrough */
20897 + case NXA_TYPE_MASK:
20898 + return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20899 + vc_data.prefix, vc_data.type, vc_data.flags);
20900 + case NXA_TYPE_ANY:
20901 + return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20908 +#endif /* CONFIG_IPV6 */
20911 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20913 + struct vcmd_net_flags_v0 vc_data;
20915 + vc_data.flagword = nxi->nx_flags;
20917 + /* special STATE flag handling */
20918 + vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20920 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20925 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20927 + struct vcmd_net_flags_v0 vc_data;
20928 + uint64_t mask, trigger;
20930 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20933 + /* special STATE flag handling */
20934 + mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20935 + trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20937 + nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20938 + vc_data.flagword, mask);
20939 + if (trigger & NXF_PERSISTENT)
20940 + nx_update_persistent(nxi);
20945 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20947 + struct vcmd_net_caps_v0 vc_data;
20949 + vc_data.ncaps = nxi->nx_ncaps;
20950 + vc_data.cmask = ~0ULL;
20952 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20957 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20959 + struct vcmd_net_caps_v0 vc_data;
20961 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20964 + nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20965 + vc_data.ncaps, vc_data.cmask);
20970 +#include <linux/module.h>
20972 +module_init(init_network);
20974 +EXPORT_SYMBOL_GPL(free_nx_info);
20975 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20977 diff -NurpP --minimal linux-3.9.4/kernel/vserver/proc.c linux-3.9.4-vs2.3.6.2/kernel/vserver/proc.c
20978 --- linux-3.9.4/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
20979 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/proc.c 2013-06-01 08:30:38.000000000 +0000
20982 + * linux/kernel/vserver/proc.c
20984 + * Virtual Context Support
20986 + * Copyright (C) 2003-2011 Herbert Pötzl
20988 + * V0.01 basic structure
20989 + * V0.02 adaptation vs1.3.0
20990 + * V0.03 proc permissions
20991 + * V0.04 locking/generic
20992 + * V0.05 next generation procfs
20993 + * V0.06 inode validation
20994 + * V0.07 generic rewrite vid
20995 + * V0.08 remove inode type
20996 + * V0.09 added u/wmask info
21000 +#include <linux/proc_fs.h>
21001 +#include <linux/fs_struct.h>
21002 +#include <linux/mount.h>
21003 +#include <linux/namei.h>
21004 +#include <asm/unistd.h>
21006 +#include <linux/vs_context.h>
21007 +#include <linux/vs_network.h>
21008 +#include <linux/vs_cvirt.h>
21010 +#include <linux/in.h>
21011 +#include <linux/inetdevice.h>
21012 +#include <linux/vs_inet.h>
21013 +#include <linux/vs_inet6.h>
21015 +#include <linux/vserver/global.h>
21017 +#include "cvirt_proc.h"
21018 +#include "cacct_proc.h"
21019 +#include "limit_proc.h"
21020 +#include "sched_proc.h"
21021 +#include "vci_config.h"
21024 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
21028 + CAP_FOR_EACH_U32(__capi) {
21029 + buffer += sprintf(buffer, "%08x",
21030 + c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
21036 +static struct proc_dir_entry *proc_virtual;
21038 +static struct proc_dir_entry *proc_virtnet;
21041 +/* first the actual feeds */
21044 +static int proc_vci(char *buffer)
21046 + return sprintf(buffer,
21047 + "VCIVersion:\t%04x:%04x\n"
21048 + "VCISyscall:\t%d\n"
21049 + "VCIKernel:\t%08x\n",
21050 + VCI_VERSION >> 16,
21051 + VCI_VERSION & 0xFFFF,
21053 + vci_kernel_config());
21056 +static int proc_virtual_info(char *buffer)
21058 + return proc_vci(buffer);
21061 +static int proc_virtual_status(char *buffer)
21063 + return sprintf(buffer,
21065 + "#CActive:\t%d\n"
21066 + "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
21067 + "#InitTask:\t%d\t%d %d\n",
21068 + atomic_read(&vx_global_ctotal),
21069 + atomic_read(&vx_global_cactive),
21070 + atomic_read(&vs_global_nsproxy),
21071 + atomic_read(&vs_global_fs),
21072 + atomic_read(&vs_global_mnt_ns),
21073 + atomic_read(&vs_global_uts_ns),
21074 + atomic_read(&nr_ipc_ns),
21075 + atomic_read(&vs_global_user_ns),
21076 + atomic_read(&vs_global_pid_ns),
21077 + atomic_read(&init_task.usage),
21078 + atomic_read(&init_task.nsproxy->count),
21079 + init_task.fs->users);
21083 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
21087 + length = sprintf(buffer,
21095 + vxi->vx_badness_bias);
21099 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
21101 + char *orig = buffer;
21103 + buffer += sprintf(buffer,
21106 + "Flags:\t%016llx\n",
21107 + atomic_read(&vxi->vx_usecnt),
21108 + atomic_read(&vxi->vx_tasks),
21109 + (unsigned long long)vxi->vx_flags);
21111 + buffer += sprintf(buffer, "BCaps:\t");
21112 + buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21113 + buffer += sprintf(buffer, "\n");
21115 + buffer += sprintf(buffer,
21116 + "CCaps:\t%016llx\n"
21117 + "Umask:\t%16llx\n"
21118 + "Wmask:\t%16llx\n"
21119 + "Spaces:\t%08lx %08lx\n",
21120 + (unsigned long long)vxi->vx_ccaps,
21121 + (unsigned long long)vxi->vx_umask,
21122 + (unsigned long long)vxi->vx_wmask,
21123 + vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
21124 + return buffer - orig;
21127 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
21129 + return vx_info_proc_limit(&vxi->limit, buffer);
21132 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
21136 + length = vx_info_proc_sched(&vxi->sched, buffer);
21137 + for_each_online_cpu(cpu) {
21138 + length += vx_info_proc_sched_pc(
21139 + &vx_per_cpu(vxi, sched_pc, cpu),
21140 + buffer + length, cpu);
21145 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
21147 + return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
21150 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
21152 + return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
21155 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
21159 + vx_update_load(vxi);
21160 + length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
21161 + for_each_online_cpu(cpu) {
21162 + length += vx_info_proc_cvirt_pc(
21163 + &vx_per_cpu(vxi, cvirt_pc, cpu),
21164 + buffer + length, cpu);
21169 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
21171 + return vx_info_proc_cacct(&vxi->cacct, buffer);
21175 +static int proc_virtnet_info(char *buffer)
21177 + return proc_vci(buffer);
21180 +static int proc_virtnet_status(char *buffer)
21182 + return sprintf(buffer,
21184 + "#CActive:\t%d\n",
21185 + atomic_read(&nx_global_ctotal),
21186 + atomic_read(&nx_global_cactive));
21189 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
21191 + struct nx_addr_v4 *v4a;
21192 +#ifdef CONFIG_IPV6
21193 + struct nx_addr_v6 *v6a;
21197 + length = sprintf(buffer,
21200 + "Bcast:\t" NIPQUAD_FMT "\n"
21201 + "Lback:\t" NIPQUAD_FMT "\n",
21204 + NIPQUAD(nxi->v4_bcast.s_addr),
21205 + NIPQUAD(nxi->v4_lback.s_addr));
21207 + if (!NX_IPV4(nxi))
21209 + for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21210 + length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
21213 +#ifdef CONFIG_IPV6
21214 + if (!NX_IPV6(nxi))
21216 + for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21217 + length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
21224 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
21228 + length = sprintf(buffer,
21231 + "Flags:\t%016llx\n"
21232 + "NCaps:\t%016llx\n",
21233 + atomic_read(&nxi->nx_usecnt),
21234 + atomic_read(&nxi->nx_tasks),
21235 + (unsigned long long)nxi->nx_flags,
21236 + (unsigned long long)nxi->nx_ncaps);
21242 +/* here the inode helpers */
21248 + struct inode_operations *iop;
21249 + struct file_operations *fop;
21250 + union proc_op op;
21253 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
21255 + struct inode *inode = new_inode(sb);
21260 + inode->i_mode = p->mode;
21262 + inode->i_op = p->iop;
21264 + inode->i_fop = p->fop;
21266 + set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
21267 + inode->i_flags |= S_IMMUTABLE;
21269 + inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
21271 + i_uid_write(inode, 0);
21272 + i_gid_write(inode, 0);
21273 + i_tag_write(inode, 0);
21278 +static struct dentry *vs_proc_instantiate(struct inode *dir,
21279 + struct dentry *dentry, int id, void *ptr)
21281 + struct vs_entry *p = ptr;
21282 + struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
21283 + struct dentry *error = ERR_PTR(-EINVAL);
21288 + PROC_I(inode)->op = p->op;
21289 + PROC_I(inode)->fd = id;
21290 + d_add(dentry, inode);
21298 +typedef struct dentry *instantiate_t(struct inode *, struct dentry *, int, void *);
21301 + * Fill a directory entry.
21303 + * If possible create the dcache entry and derive our inode number and
21304 + * file type from dcache entry.
21306 + * Since all of the proc inode numbers are dynamically generated, the inode
21307 + * numbers do not exist until the inode is cache. This means creating the
21308 + * the dcache entry in readdir is necessary to keep the inode numbers
21309 + * reported by readdir in sync with the inode numbers reported
21312 +static int proc_fill_cache(struct file *filp, void *dirent, filldir_t filldir,
21313 + char *name, int len, instantiate_t instantiate, int id, void *ptr)
21315 + struct dentry *child, *dir = filp->f_dentry;
21316 + struct inode *inode;
21317 + struct qstr qname;
21319 + unsigned type = DT_UNKNOWN;
21321 + qname.name = name;
21323 + qname.hash = full_name_hash(name, len);
21325 + child = d_lookup(dir, &qname);
21327 + struct dentry *new;
21328 + new = d_alloc(dir, &qname);
21330 + child = instantiate(dir->d_inode, new, id, ptr);
21337 + if (!child || IS_ERR(child) || !child->d_inode)
21338 + goto end_instantiate;
21339 + inode = child->d_inode;
21341 + ino = inode->i_ino;
21342 + type = inode->i_mode >> 12;
21347 + ino = find_inode_number(dir, &qname);
21350 + return filldir(dirent, name, len, filp->f_pos, ino, type);
21355 +/* get and revalidate vx_info/xid */
21358 +struct vx_info *get_proc_vx_info(struct inode *inode)
21360 + return lookup_vx_info(PROC_I(inode)->fd);
21363 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
21365 + struct inode *inode = dentry->d_inode;
21366 + xid_t xid = PROC_I(inode)->fd;
21368 + if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21371 + if (!xid || xid_is_hashed(xid))
21378 +/* get and revalidate nx_info/nid */
21380 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
21382 + struct inode *inode = dentry->d_inode;
21383 + nid_t nid = PROC_I(inode)->fd;
21385 + if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
21388 + if (!nid || nid_is_hashed(nid))
21396 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
21398 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
21399 + size_t count, loff_t *ppos)
21401 + struct inode *inode = file->f_dentry->d_inode;
21402 + unsigned long page;
21403 + ssize_t length = 0;
21405 + if (count > PROC_BLOCK_SIZE)
21406 + count = PROC_BLOCK_SIZE;
21408 + /* fade that out as soon as stable */
21409 + WARN_ON(PROC_I(inode)->fd);
21411 + if (!(page = __get_free_page(GFP_KERNEL)))
21414 + BUG_ON(!PROC_I(inode)->op.proc_vs_read);
21415 + length = PROC_I(inode)->op.proc_vs_read((char *)page);
21418 + length = simple_read_from_buffer(buf, count, ppos,
21419 + (char *)page, length);
21425 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
21426 + size_t count, loff_t *ppos)
21428 + struct inode *inode = file->f_dentry->d_inode;
21429 + struct vx_info *vxi = NULL;
21430 + xid_t xid = PROC_I(inode)->fd;
21431 + unsigned long page;
21432 + ssize_t length = 0;
21434 + if (count > PROC_BLOCK_SIZE)
21435 + count = PROC_BLOCK_SIZE;
21437 + /* fade that out as soon as stable */
21439 + vxi = lookup_vx_info(xid);
21443 + length = -ENOMEM;
21444 + if (!(page = __get_free_page(GFP_KERNEL)))
21447 + BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
21448 + length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
21451 + length = simple_read_from_buffer(buf, count, ppos,
21452 + (char *)page, length);
21456 + put_vx_info(vxi);
21461 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
21462 + size_t count, loff_t *ppos)
21464 + struct inode *inode = file->f_dentry->d_inode;
21465 + struct nx_info *nxi = NULL;
21466 + nid_t nid = PROC_I(inode)->fd;
21467 + unsigned long page;
21468 + ssize_t length = 0;
21470 + if (count > PROC_BLOCK_SIZE)
21471 + count = PROC_BLOCK_SIZE;
21473 + /* fade that out as soon as stable */
21475 + nxi = lookup_nx_info(nid);
21479 + length = -ENOMEM;
21480 + if (!(page = __get_free_page(GFP_KERNEL)))
21483 + BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
21484 + length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
21487 + length = simple_read_from_buffer(buf, count, ppos,
21488 + (char *)page, length);
21492 + put_nx_info(nxi);
21499 +/* here comes the lower level */
21502 +#define NOD(NAME, MODE, IOP, FOP, OP) { \
21503 + .len = sizeof(NAME) - 1, \
21504 + .name = (NAME), \
21512 +#define DIR(NAME, MODE, OTYPE) \
21513 + NOD(NAME, (S_IFDIR | (MODE)), \
21514 + &proc_ ## OTYPE ## _inode_operations, \
21515 + &proc_ ## OTYPE ## _file_operations, { } )
21517 +#define INF(NAME, MODE, OTYPE) \
21518 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
21519 + &proc_vs_info_file_operations, \
21520 + { .proc_vs_read = &proc_##OTYPE } )
21522 +#define VINF(NAME, MODE, OTYPE) \
21523 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
21524 + &proc_vx_info_file_operations, \
21525 + { .proc_vxi_read = &proc_##OTYPE } )
21527 +#define NINF(NAME, MODE, OTYPE) \
21528 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
21529 + &proc_nx_info_file_operations, \
21530 + { .proc_nxi_read = &proc_##OTYPE } )
21533 +static struct file_operations proc_vs_info_file_operations = {
21534 + .read = proc_vs_info_read,
21537 +static struct file_operations proc_vx_info_file_operations = {
21538 + .read = proc_vx_info_read,
21541 +static struct dentry_operations proc_xid_dentry_operations = {
21542 + .d_revalidate = proc_xid_revalidate,
21545 +static struct vs_entry vx_base_stuff[] = {
21546 + VINF("info", S_IRUGO, vxi_info),
21547 + VINF("status", S_IRUGO, vxi_status),
21548 + VINF("limit", S_IRUGO, vxi_limit),
21549 + VINF("sched", S_IRUGO, vxi_sched),
21550 + VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
21551 + VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
21552 + VINF("cvirt", S_IRUGO, vxi_cvirt),
21553 + VINF("cacct", S_IRUGO, vxi_cacct),
21560 +static struct dentry *proc_xid_instantiate(struct inode *dir,
21561 + struct dentry *dentry, int id, void *ptr)
21563 + dentry->d_op = &proc_xid_dentry_operations;
21564 + return vs_proc_instantiate(dir, dentry, id, ptr);
21567 +static struct dentry *proc_xid_lookup(struct inode *dir,
21568 + struct dentry *dentry, unsigned int flags)
21570 + struct vs_entry *p = vx_base_stuff;
21571 + struct dentry *error = ERR_PTR(-ENOENT);
21573 + for (; p->name; p++) {
21574 + if (p->len != dentry->d_name.len)
21576 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21582 + error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21587 +static int proc_xid_readdir(struct file *filp,
21588 + void *dirent, filldir_t filldir)
21590 + struct dentry *dentry = filp->f_dentry;
21591 + struct inode *inode = dentry->d_inode;
21592 + struct vs_entry *p = vx_base_stuff;
21593 + int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
21597 + pos = filp->f_pos;
21600 + ino = inode->i_ino;
21601 + if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21604 + /* fall through */
21606 + ino = parent_ino(dentry);
21607 + if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21610 + /* fall through */
21613 + if (index >= size)
21615 + for (p += index; p->name; p++) {
21616 + if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21617 + vs_proc_instantiate, PROC_I(inode)->fd, p))
21623 + filp->f_pos = pos;
21629 +static struct file_operations proc_nx_info_file_operations = {
21630 + .read = proc_nx_info_read,
21633 +static struct dentry_operations proc_nid_dentry_operations = {
21634 + .d_revalidate = proc_nid_revalidate,
21637 +static struct vs_entry nx_base_stuff[] = {
21638 + NINF("info", S_IRUGO, nxi_info),
21639 + NINF("status", S_IRUGO, nxi_status),
21644 +static struct dentry *proc_nid_instantiate(struct inode *dir,
21645 + struct dentry *dentry, int id, void *ptr)
21647 + dentry->d_op = &proc_nid_dentry_operations;
21648 + return vs_proc_instantiate(dir, dentry, id, ptr);
21651 +static struct dentry *proc_nid_lookup(struct inode *dir,
21652 + struct dentry *dentry, unsigned int flags)
21654 + struct vs_entry *p = nx_base_stuff;
21655 + struct dentry *error = ERR_PTR(-ENOENT);
21657 + for (; p->name; p++) {
21658 + if (p->len != dentry->d_name.len)
21660 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21666 + error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
21671 +static int proc_nid_readdir(struct file *filp,
21672 + void *dirent, filldir_t filldir)
21674 + struct dentry *dentry = filp->f_dentry;
21675 + struct inode *inode = dentry->d_inode;
21676 + struct vs_entry *p = nx_base_stuff;
21677 + int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
21681 + pos = filp->f_pos;
21684 + ino = inode->i_ino;
21685 + if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21688 + /* fall through */
21690 + ino = parent_ino(dentry);
21691 + if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21694 + /* fall through */
21697 + if (index >= size)
21699 + for (p += index; p->name; p++) {
21700 + if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21701 + vs_proc_instantiate, PROC_I(inode)->fd, p))
21707 + filp->f_pos = pos;
21712 +#define MAX_MULBY10 ((~0U - 9) / 10)
21714 +static inline int atovid(const char *str, int len)
21719 + while (len-- > 0) {
21724 + if (vid >= MAX_MULBY10)
21734 +/* now the upper level (virtual) */
21737 +static struct file_operations proc_xid_file_operations = {
21738 + .read = generic_read_dir,
21739 + .readdir = proc_xid_readdir,
21742 +static struct inode_operations proc_xid_inode_operations = {
21743 + .lookup = proc_xid_lookup,
21746 +static struct vs_entry vx_virtual_stuff[] = {
21747 + INF("info", S_IRUGO, virtual_info),
21748 + INF("status", S_IRUGO, virtual_status),
21749 + DIR(NULL, S_IRUGO | S_IXUGO, xid),
21753 +static struct dentry *proc_virtual_lookup(struct inode *dir,
21754 + struct dentry *dentry, unsigned int flags)
21756 + struct vs_entry *p = vx_virtual_stuff;
21757 + struct dentry *error = ERR_PTR(-ENOENT);
21760 + for (; p->name; p++) {
21761 + if (p->len != dentry->d_name.len)
21763 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21767 + goto instantiate;
21769 + id = atovid(dentry->d_name.name, dentry->d_name.len);
21770 + if ((id < 0) || !xid_is_hashed(id))
21774 + error = proc_xid_instantiate(dir, dentry, id, p);
21779 +static struct file_operations proc_nid_file_operations = {
21780 + .read = generic_read_dir,
21781 + .readdir = proc_nid_readdir,
21784 +static struct inode_operations proc_nid_inode_operations = {
21785 + .lookup = proc_nid_lookup,
21788 +static struct vs_entry nx_virtnet_stuff[] = {
21789 + INF("info", S_IRUGO, virtnet_info),
21790 + INF("status", S_IRUGO, virtnet_status),
21791 + DIR(NULL, S_IRUGO | S_IXUGO, nid),
21795 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21796 + struct dentry *dentry, unsigned int flags)
21798 + struct vs_entry *p = nx_virtnet_stuff;
21799 + struct dentry *error = ERR_PTR(-ENOENT);
21802 + for (; p->name; p++) {
21803 + if (p->len != dentry->d_name.len)
21805 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21809 + goto instantiate;
21811 + id = atovid(dentry->d_name.name, dentry->d_name.len);
21812 + if ((id < 0) || !nid_is_hashed(id))
21816 + error = proc_nid_instantiate(dir, dentry, id, p);
21822 +#define PROC_MAXVIDS 32
21824 +int proc_virtual_readdir(struct file *filp,
21825 + void *dirent, filldir_t filldir)
21827 + struct dentry *dentry = filp->f_dentry;
21828 + struct inode *inode = dentry->d_inode;
21829 + struct vs_entry *p = vx_virtual_stuff;
21830 + int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21832 + unsigned int xid_array[PROC_MAXVIDS];
21833 + char buf[PROC_NUMBUF];
21834 + unsigned int nr_xids, i;
21837 + pos = filp->f_pos;
21840 + ino = inode->i_ino;
21841 + if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21844 + /* fall through */
21846 + ino = parent_ino(dentry);
21847 + if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21850 + /* fall through */
21853 + if (index >= size)
21855 + for (p += index; p->name; p++) {
21856 + if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21857 + vs_proc_instantiate, 0, p))
21862 + index = pos - size;
21863 + p = &vx_virtual_stuff[size - 1];
21864 + nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21865 + for (i = 0; i < nr_xids; i++) {
21866 + int n, xid = xid_array[i];
21867 + unsigned int j = PROC_NUMBUF;
21871 + buf[--j] = '0' + (n % 10);
21874 + if (proc_fill_cache(filp, dirent, filldir,
21875 + buf + j, PROC_NUMBUF - j,
21876 + vs_proc_instantiate, xid, p))
21882 + filp->f_pos = pos;
21886 +static int proc_virtual_getattr(struct vfsmount *mnt,
21887 + struct dentry *dentry, struct kstat *stat)
21889 + struct inode *inode = dentry->d_inode;
21891 + generic_fillattr(inode, stat);
21892 + stat->nlink = 2 + atomic_read(&vx_global_cactive);
21896 +static struct file_operations proc_virtual_dir_operations = {
21897 + .read = generic_read_dir,
21898 + .readdir = proc_virtual_readdir,
21901 +static struct inode_operations proc_virtual_dir_inode_operations = {
21902 + .getattr = proc_virtual_getattr,
21903 + .lookup = proc_virtual_lookup,
21910 +int proc_virtnet_readdir(struct file *filp,
21911 + void *dirent, filldir_t filldir)
21913 + struct dentry *dentry = filp->f_dentry;
21914 + struct inode *inode = dentry->d_inode;
21915 + struct vs_entry *p = nx_virtnet_stuff;
21916 + int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21918 + unsigned int nid_array[PROC_MAXVIDS];
21919 + char buf[PROC_NUMBUF];
21920 + unsigned int nr_nids, i;
21923 + pos = filp->f_pos;
21926 + ino = inode->i_ino;
21927 + if (filldir(dirent, ".", 1, pos, ino, DT_DIR) < 0)
21930 + /* fall through */
21932 + ino = parent_ino(dentry);
21933 + if (filldir(dirent, "..", 2, pos, ino, DT_DIR) < 0)
21936 + /* fall through */
21939 + if (index >= size)
21941 + for (p += index; p->name; p++) {
21942 + if (proc_fill_cache(filp, dirent, filldir, p->name, p->len,
21943 + vs_proc_instantiate, 0, p))
21948 + index = pos - size;
21949 + p = &nx_virtnet_stuff[size - 1];
21950 + nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21951 + for (i = 0; i < nr_nids; i++) {
21952 + int n, nid = nid_array[i];
21953 + unsigned int j = PROC_NUMBUF;
21957 + buf[--j] = '0' + (n % 10);
21960 + if (proc_fill_cache(filp, dirent, filldir,
21961 + buf + j, PROC_NUMBUF - j,
21962 + vs_proc_instantiate, nid, p))
21968 + filp->f_pos = pos;
21972 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21973 + struct dentry *dentry, struct kstat *stat)
21975 + struct inode *inode = dentry->d_inode;
21977 + generic_fillattr(inode, stat);
21978 + stat->nlink = 2 + atomic_read(&nx_global_cactive);
21982 +static struct file_operations proc_virtnet_dir_operations = {
21983 + .read = generic_read_dir,
21984 + .readdir = proc_virtnet_readdir,
21987 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21988 + .getattr = proc_virtnet_getattr,
21989 + .lookup = proc_virtnet_lookup,
21994 +void proc_vx_init(void)
21996 + struct proc_dir_entry *ent;
21998 + ent = proc_mkdir("virtual", 0);
22000 + ent->proc_fops = &proc_virtual_dir_operations;
22001 + ent->proc_iops = &proc_virtual_dir_inode_operations;
22003 + proc_virtual = ent;
22005 + ent = proc_mkdir("virtnet", 0);
22007 + ent->proc_fops = &proc_virtnet_dir_operations;
22008 + ent->proc_iops = &proc_virtnet_dir_inode_operations;
22010 + proc_virtnet = ent;
22016 +/* per pid info */
22019 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
22021 + struct vx_info *vxi;
22022 + char *orig = buffer;
22024 + buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
22026 + vxi = task_get_vx_info(p);
22030 + buffer += sprintf(buffer, "BCaps:\t");
22031 + buffer = print_cap_t(buffer, &vxi->vx_bcaps);
22032 + buffer += sprintf(buffer, "\n");
22033 + buffer += sprintf(buffer, "CCaps:\t%016llx\n",
22034 + (unsigned long long)vxi->vx_ccaps);
22035 + buffer += sprintf(buffer, "CFlags:\t%016llx\n",
22036 + (unsigned long long)vxi->vx_flags);
22037 + buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
22039 + put_vx_info(vxi);
22041 + return buffer - orig;
22045 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
22047 + struct nx_info *nxi;
22048 + struct nx_addr_v4 *v4a;
22049 +#ifdef CONFIG_IPV6
22050 + struct nx_addr_v6 *v6a;
22052 + char *orig = buffer;
22055 + buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
22057 + nxi = task_get_nx_info(p);
22061 + buffer += sprintf(buffer, "NCaps:\t%016llx\n",
22062 + (unsigned long long)nxi->nx_ncaps);
22063 + buffer += sprintf(buffer, "NFlags:\t%016llx\n",
22064 + (unsigned long long)nxi->nx_flags);
22066 + buffer += sprintf(buffer,
22067 + "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
22068 + NIPQUAD(nxi->v4_bcast.s_addr));
22069 + buffer += sprintf (buffer,
22070 + "V4Root[lback]:\t" NIPQUAD_FMT "\n",
22071 + NIPQUAD(nxi->v4_lback.s_addr));
22072 + if (!NX_IPV4(nxi))
22074 + for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
22075 + buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
22078 +#ifdef CONFIG_IPV6
22079 + if (!NX_IPV6(nxi))
22081 + for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
22082 + buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
22086 + put_nx_info(nxi);
22088 + return buffer - orig;
22091 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched.c linux-3.9.4-vs2.3.6.2/kernel/vserver/sched.c
22092 --- linux-3.9.4/kernel/vserver/sched.c 1970-01-01 00:00:00.000000000 +0000
22093 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sched.c 2013-05-31 14:47:11.000000000 +0000
22096 + * linux/kernel/vserver/sched.c
22098 + * Virtual Server: Scheduler Support
22100 + * Copyright (C) 2004-2010 Herbert Pötzl
22102 + * V0.01 adapted Sam Vilains version to 2.6.3
22103 + * V0.02 removed legacy interface
22104 + * V0.03 changed vcmds to vxi arg
22105 + * V0.04 removed older and legacy interfaces
22106 + * V0.05 removed scheduler code/commands
22110 +#include <linux/vs_context.h>
22111 +#include <linux/vs_sched.h>
22112 +#include <linux/cpumask.h>
22113 +#include <linux/vserver/sched_cmd.h>
22115 +#include <asm/uaccess.h>
22118 +void vx_update_sched_param(struct _vx_sched *sched,
22119 + struct _vx_sched_pc *sched_pc)
22121 + sched_pc->prio_bias = sched->prio_bias;
22124 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
22128 + if (data->prio_bias > MAX_PRIO_BIAS)
22129 + data->prio_bias = MAX_PRIO_BIAS;
22130 + if (data->prio_bias < MIN_PRIO_BIAS)
22131 + data->prio_bias = MIN_PRIO_BIAS;
22133 + if (data->cpu_id != ~0) {
22134 + vxi->sched.update = cpumask_of_cpu(data->cpu_id);
22135 + cpumask_and(&vxi->sched.update, &vxi->sched.update,
22136 + cpu_online_mask);
22138 + cpumask_copy(&vxi->sched.update, cpu_online_mask);
22140 + for_each_cpu_mask(cpu, vxi->sched.update)
22141 + vx_update_sched_param(&vxi->sched,
22142 + &vx_per_cpu(vxi, sched_pc, cpu));
22146 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
22148 + struct vcmd_prio_bias vc_data;
22150 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22153 + return do_set_prio_bias(vxi, &vc_data);
22156 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
22158 + struct vcmd_prio_bias vc_data;
22159 + struct _vx_sched_pc *pcd;
22162 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22165 + cpu = vc_data.cpu_id;
22167 + if (!cpu_possible(cpu))
22170 + pcd = &vx_per_cpu(vxi, sched_pc, cpu);
22171 + vc_data.prio_bias = pcd->prio_bias;
22173 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22178 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched_init.h linux-3.9.4-vs2.3.6.2/kernel/vserver/sched_init.h
22179 --- linux-3.9.4/kernel/vserver/sched_init.h 1970-01-01 00:00:00.000000000 +0000
22180 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sched_init.h 2013-05-31 14:47:11.000000000 +0000
22183 +static inline void vx_info_init_sched(struct _vx_sched *sched)
22185 + /* scheduling; hard code starting values as constants */
22186 + sched->prio_bias = 0;
22190 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22192 + sched_pc->prio_bias = 0;
22194 + sched_pc->user_ticks = 0;
22195 + sched_pc->sys_ticks = 0;
22196 + sched_pc->hold_ticks = 0;
22199 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
22205 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
22209 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sched_proc.h linux-3.9.4-vs2.3.6.2/kernel/vserver/sched_proc.h
22210 --- linux-3.9.4/kernel/vserver/sched_proc.h 1970-01-01 00:00:00.000000000 +0000
22211 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sched_proc.h 2013-05-31 14:47:11.000000000 +0000
22213 +#ifndef _VX_SCHED_PROC_H
22214 +#define _VX_SCHED_PROC_H
22218 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
22222 + length += sprintf(buffer,
22223 + "PrioBias:\t%8d\n",
22224 + sched->prio_bias);
22229 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
22230 + char *buffer, int cpu)
22234 + length += sprintf(buffer + length,
22235 + "cpu %d: %lld %lld %lld", cpu,
22236 + (unsigned long long)sched_pc->user_ticks,
22237 + (unsigned long long)sched_pc->sys_ticks,
22238 + (unsigned long long)sched_pc->hold_ticks);
22239 + length += sprintf(buffer + length,
22240 + " %d\n", sched_pc->prio_bias);
22244 +#endif /* _VX_SCHED_PROC_H */
22245 diff -NurpP --minimal linux-3.9.4/kernel/vserver/signal.c linux-3.9.4-vs2.3.6.2/kernel/vserver/signal.c
22246 --- linux-3.9.4/kernel/vserver/signal.c 1970-01-01 00:00:00.000000000 +0000
22247 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/signal.c 2013-05-31 14:47:11.000000000 +0000
22250 + * linux/kernel/vserver/signal.c
22252 + * Virtual Server: Signal Support
22254 + * Copyright (C) 2003-2007 Herbert Pötzl
22256 + * V0.01 broken out from vcontext V0.05
22257 + * V0.02 changed vcmds to vxi arg
22258 + * V0.03 adjusted siginfo for kill
22262 +#include <asm/uaccess.h>
22264 +#include <linux/vs_context.h>
22265 +#include <linux/vs_pid.h>
22266 +#include <linux/vserver/signal_cmd.h>
22269 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
22271 + int retval, count = 0;
22272 + struct task_struct *p;
22273 + struct siginfo *sip = SEND_SIG_PRIV;
22276 + vxdprintk(VXD_CBIT(misc, 4),
22277 + "vx_info_kill(%p[#%d],%d,%d)*",
22278 + vxi, vxi->vx_id, pid, sig);
22279 + read_lock(&tasklist_lock);
22283 + for_each_process(p) {
22286 + if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
22287 + (pid && vxi->vx_initpid == p->pid))
22290 + err = group_send_sig_info(sig, sip, p);
22292 + if (err != -EPERM)
22298 + if (vxi->vx_initpid) {
22299 + pid = vxi->vx_initpid;
22300 + /* for now, only SIGINT to private init ... */
22301 + if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22302 + /* ... as long as there are tasks left */
22303 + (atomic_read(&vxi->vx_tasks) > 1))
22306 + /* fallthrough */
22309 + p = find_task_by_real_pid(pid);
22310 + rcu_read_unlock();
22312 + if (vx_task_xid(p) == vxi->vx_id)
22313 + retval = group_send_sig_info(sig, sip, p);
22317 + read_unlock(&tasklist_lock);
22318 + vxdprintk(VXD_CBIT(misc, 4),
22319 + "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
22320 + vxi, vxi->vx_id, pid, sig, (long)sip, retval);
22324 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
22326 + struct vcmd_ctx_kill_v0 vc_data;
22328 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
22331 + /* special check to allow guest shutdown */
22332 + if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
22333 + /* forbid killall pid=0 when init is present */
22334 + (((vc_data.pid < 1) && vxi->vx_initpid) ||
22335 + (vc_data.pid > 1)))
22338 + return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
22342 +static int __wait_exit(struct vx_info *vxi)
22344 + DECLARE_WAITQUEUE(wait, current);
22347 + add_wait_queue(&vxi->vx_wait, &wait);
22348 + set_current_state(TASK_INTERRUPTIBLE);
22351 + if (vx_info_state(vxi,
22352 + VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
22354 + if (signal_pending(current)) {
22355 + ret = -ERESTARTSYS;
22362 + set_current_state(TASK_RUNNING);
22363 + remove_wait_queue(&vxi->vx_wait, &wait);
22369 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
22371 + struct vcmd_wait_exit_v0 vc_data;
22374 + ret = __wait_exit(vxi);
22375 + vc_data.reboot_cmd = vxi->reboot_cmd;
22376 + vc_data.exit_code = vxi->exit_code;
22378 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
22383 diff -NurpP --minimal linux-3.9.4/kernel/vserver/space.c linux-3.9.4-vs2.3.6.2/kernel/vserver/space.c
22384 --- linux-3.9.4/kernel/vserver/space.c 1970-01-01 00:00:00.000000000 +0000
22385 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/space.c 2013-05-31 14:47:11.000000000 +0000
22388 + * linux/kernel/vserver/space.c
22390 + * Virtual Server: Context Space Support
22392 + * Copyright (C) 2003-2010 Herbert Pötzl
22394 + * V0.01 broken out from context.c 0.07
22395 + * V0.02 added task locking for namespace
22396 + * V0.03 broken out vx_enter_namespace
22397 + * V0.04 added *space support and commands
22398 + * V0.05 added credential support
22402 +#include <linux/utsname.h>
22403 +#include <linux/nsproxy.h>
22404 +#include <linux/err.h>
22405 +#include <linux/fs_struct.h>
22406 +#include <linux/cred.h>
22407 +#include <asm/uaccess.h>
22409 +#include <linux/vs_context.h>
22410 +#include <linux/vserver/space.h>
22411 +#include <linux/vserver/space_cmd.h>
22413 +atomic_t vs_global_nsproxy = ATOMIC_INIT(0);
22414 +atomic_t vs_global_fs = ATOMIC_INIT(0);
22415 +atomic_t vs_global_mnt_ns = ATOMIC_INIT(0);
22416 +atomic_t vs_global_uts_ns = ATOMIC_INIT(0);
22417 +atomic_t vs_global_user_ns = ATOMIC_INIT(0);
22418 +atomic_t vs_global_pid_ns = ATOMIC_INIT(0);
22421 +/* namespace functions */
22423 +#include <linux/mnt_namespace.h>
22424 +#include <linux/user_namespace.h>
22425 +#include <linux/pid_namespace.h>
22426 +#include <linux/ipc_namespace.h>
22427 +#include <net/net_namespace.h>
22428 +#include "../fs/mount.h"
22431 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
22432 + .mask = CLONE_FS |
22434 +#ifdef CONFIG_UTS_NS
22437 +#ifdef CONFIG_IPC_NS
22440 +#ifdef CONFIG_USER_NS
22446 +static const struct vcmd_space_mask_v1 space_mask = {
22447 + .mask = CLONE_FS |
22449 +#ifdef CONFIG_UTS_NS
22452 +#ifdef CONFIG_IPC_NS
22455 +#ifdef CONFIG_USER_NS
22458 +#ifdef CONFIG_PID_NS
22461 +#ifdef CONFIG_NET_NS
22467 +static const struct vcmd_space_mask_v1 default_space_mask = {
22468 + .mask = CLONE_FS |
22470 +#ifdef CONFIG_UTS_NS
22473 +#ifdef CONFIG_IPC_NS
22476 +#ifdef CONFIG_USER_NS
22479 +#ifdef CONFIG_PID_NS
22486 + * build a new nsproxy mix
22487 + * assumes that both proxies are 'const'
22488 + * does not touch nsproxy refcounts
22489 + * will hold a reference on the result.
22492 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
22493 + struct nsproxy *new_nsproxy, unsigned long mask)
22495 + struct mnt_namespace *old_ns;
22496 + struct uts_namespace *old_uts;
22497 + struct ipc_namespace *old_ipc;
22498 +#ifdef CONFIG_PID_NS
22499 + struct pid_namespace *old_pid;
22501 +#ifdef CONFIG_NET_NS
22502 + struct net *old_net;
22504 + struct nsproxy *nsproxy;
22506 + nsproxy = copy_nsproxy(old_nsproxy);
22510 + if (mask & CLONE_NEWNS) {
22511 + old_ns = nsproxy->mnt_ns;
22512 + nsproxy->mnt_ns = new_nsproxy->mnt_ns;
22513 + if (nsproxy->mnt_ns)
22514 + get_mnt_ns(nsproxy->mnt_ns);
22518 + if (mask & CLONE_NEWUTS) {
22519 + old_uts = nsproxy->uts_ns;
22520 + nsproxy->uts_ns = new_nsproxy->uts_ns;
22521 + if (nsproxy->uts_ns)
22522 + get_uts_ns(nsproxy->uts_ns);
22526 + if (mask & CLONE_NEWIPC) {
22527 + old_ipc = nsproxy->ipc_ns;
22528 + nsproxy->ipc_ns = new_nsproxy->ipc_ns;
22529 + if (nsproxy->ipc_ns)
22530 + get_ipc_ns(nsproxy->ipc_ns);
22534 +#ifdef CONFIG_PID_NS
22535 + if (mask & CLONE_NEWPID) {
22536 + old_pid = nsproxy->pid_ns;
22537 + nsproxy->pid_ns = new_nsproxy->pid_ns;
22538 + if (nsproxy->pid_ns)
22539 + get_pid_ns(nsproxy->pid_ns);
22543 +#ifdef CONFIG_NET_NS
22544 + if (mask & CLONE_NEWNET) {
22545 + old_net = nsproxy->net_ns;
22546 + nsproxy->net_ns = new_nsproxy->net_ns;
22547 + if (nsproxy->net_ns)
22548 + get_net(nsproxy->net_ns);
22553 + put_mnt_ns(old_ns);
22555 + put_uts_ns(old_uts);
22557 + put_ipc_ns(old_ipc);
22558 +#ifdef CONFIG_PID_NS
22560 + put_pid_ns(old_pid);
22562 +#ifdef CONFIG_NET_NS
22564 + put_net(old_net);
22572 + * merge two nsproxy structs into a new one.
22573 + * will hold a reference on the result.
22577 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
22578 + struct nsproxy *proxy, unsigned long mask)
22580 + struct nsproxy null_proxy = { .mnt_ns = NULL };
22586 + /* vs_mix_nsproxy returns with reference */
22587 + return vs_mix_nsproxy(old ? old : &null_proxy,
22590 + get_nsproxy(proxy);
22595 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22597 + struct nsproxy *proxy, *proxy_cur, *proxy_new;
22598 + struct fs_struct *fs_cur, *fs = NULL;
22599 + struct _vx_space *space;
22600 + int ret, kill = 0;
22602 + vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
22603 + vxi, vxi->vx_id, mask, index);
22605 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
22608 + if (index >= VX_SPACES)
22611 + space = &vxi->space[index];
22614 + mask = space->vx_nsmask;
22616 + if ((mask & space->vx_nsmask) != mask)
22619 + if (mask & CLONE_FS) {
22620 + fs = copy_fs_struct(space->vx_fs);
22624 + proxy = space->vx_nsproxy;
22626 + vxdprintk(VXD_CBIT(space, 9),
22627 + "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
22628 + vxi, vxi->vx_id, mask, index, proxy, fs);
22630 + task_lock(current);
22631 + fs_cur = current->fs;
22633 + if (mask & CLONE_FS) {
22634 + spin_lock(&fs_cur->lock);
22635 + current->fs = fs;
22636 + kill = !--fs_cur->users;
22637 + spin_unlock(&fs_cur->lock);
22640 + proxy_cur = current->nsproxy;
22641 + get_nsproxy(proxy_cur);
22642 + task_unlock(current);
22645 + free_fs_struct(fs_cur);
22647 + proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
22648 + if (IS_ERR(proxy_new)) {
22649 + ret = PTR_ERR(proxy_new);
22653 + proxy_new = xchg(¤t->nsproxy, proxy_new);
22655 + if (mask & CLONE_NEWUSER) {
22656 + struct cred *cred;
22658 + vxdprintk(VXD_CBIT(space, 10),
22659 + "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
22660 + vxi, vxi->vx_id, space->vx_cred,
22661 + current->real_cred, current->cred);
22663 + if (space->vx_cred) {
22664 + cred = __prepare_creds(space->vx_cred);
22666 + commit_creds(cred);
22673 + put_nsproxy(proxy_new);
22676 + put_nsproxy(proxy_cur);
22681 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
22683 + struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
22684 + struct fs_struct *fs_vxi, *fs = NULL;
22685 + struct _vx_space *space;
22686 + int ret, kill = 0;
22688 + vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
22689 + vxi, vxi->vx_id, mask, index);
22691 + if ((mask & space_mask.mask) != mask)
22694 + if (index >= VX_SPACES)
22697 + space = &vxi->space[index];
22699 + proxy_vxi = space->vx_nsproxy;
22700 + fs_vxi = space->vx_fs;
22702 + if (mask & CLONE_FS) {
22703 + fs = copy_fs_struct(current->fs);
22708 + task_lock(current);
22710 + if (mask & CLONE_FS) {
22711 + spin_lock(&fs_vxi->lock);
22712 + space->vx_fs = fs;
22713 + kill = !--fs_vxi->users;
22714 + spin_unlock(&fs_vxi->lock);
22717 + proxy_cur = current->nsproxy;
22718 + get_nsproxy(proxy_cur);
22719 + task_unlock(current);
22722 + free_fs_struct(fs_vxi);
22724 + proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
22725 + if (IS_ERR(proxy_new)) {
22726 + ret = PTR_ERR(proxy_new);
22730 + proxy_new = xchg(&space->vx_nsproxy, proxy_new);
22731 + space->vx_nsmask |= mask;
22733 + if (mask & CLONE_NEWUSER) {
22734 + struct cred *cred;
22736 + vxdprintk(VXD_CBIT(space, 10),
22737 + "vx_set_space(%p[#%u],%p) cred (%p,%p)",
22738 + vxi, vxi->vx_id, space->vx_cred,
22739 + current->real_cred, current->cred);
22741 + cred = prepare_creds();
22742 + cred = (struct cred *)xchg(&space->vx_cred, cred);
22744 + abort_creds(cred);
22750 + put_nsproxy(proxy_new);
22753 + put_nsproxy(proxy_cur);
22758 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
22760 + struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22762 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22765 + return vx_enter_space(vxi, vc_data.mask, 0);
22768 +int vc_enter_space(struct vx_info *vxi, void __user *data)
22770 + struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22772 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22775 + if (vc_data.index >= VX_SPACES)
22778 + return vx_enter_space(vxi, vc_data.mask, vc_data.index);
22781 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
22783 + struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22785 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22788 + return vx_set_space(vxi, vc_data.mask, 0);
22791 +int vc_set_space(struct vx_info *vxi, void __user *data)
22793 + struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22795 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22798 + if (vc_data.index >= VX_SPACES)
22801 + return vx_set_space(vxi, vc_data.mask, vc_data.index);
22804 +int vc_get_space_mask(void __user *data, int type)
22806 + const struct vcmd_space_mask_v1 *mask;
22809 + mask = &space_mask_v0;
22810 + else if (type == 1)
22811 + mask = &space_mask;
22813 + mask = &default_space_mask;
22815 + vxdprintk(VXD_CBIT(space, 10),
22816 + "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22818 + if (copy_to_user(data, mask, sizeof(*mask)))
22823 diff -NurpP --minimal linux-3.9.4/kernel/vserver/switch.c linux-3.9.4-vs2.3.6.2/kernel/vserver/switch.c
22824 --- linux-3.9.4/kernel/vserver/switch.c 1970-01-01 00:00:00.000000000 +0000
22825 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/switch.c 2013-05-31 14:47:11.000000000 +0000
22828 + * linux/kernel/vserver/switch.c
22830 + * Virtual Server: Syscall Switch
22832 + * Copyright (C) 2003-2011 Herbert Pötzl
22834 + * V0.01 syscall switch
22835 + * V0.02 added signal to context
22836 + * V0.03 added rlimit functions
22837 + * V0.04 added iattr, task/xid functions
22838 + * V0.05 added debug/history stuff
22839 + * V0.06 added compat32 layer
22840 + * V0.07 vcmd args and perms
22841 + * V0.08 added status commands
22842 + * V0.09 added tag commands
22843 + * V0.10 added oom bias
22844 + * V0.11 added device commands
22845 + * V0.12 added warn mask
22849 +#include <linux/vs_context.h>
22850 +#include <linux/vs_network.h>
22851 +#include <linux/vserver/switch.h>
22853 +#include "vci_config.h"
22857 +int vc_get_version(uint32_t id)
22859 + return VCI_VERSION;
22863 +int vc_get_vci(uint32_t id)
22865 + return vci_kernel_config();
22868 +#include <linux/vserver/context_cmd.h>
22869 +#include <linux/vserver/cvirt_cmd.h>
22870 +#include <linux/vserver/cacct_cmd.h>
22871 +#include <linux/vserver/limit_cmd.h>
22872 +#include <linux/vserver/network_cmd.h>
22873 +#include <linux/vserver/sched_cmd.h>
22874 +#include <linux/vserver/debug_cmd.h>
22875 +#include <linux/vserver/inode_cmd.h>
22876 +#include <linux/vserver/dlimit_cmd.h>
22877 +#include <linux/vserver/signal_cmd.h>
22878 +#include <linux/vserver/space_cmd.h>
22879 +#include <linux/vserver/tag_cmd.h>
22880 +#include <linux/vserver/device_cmd.h>
22882 +#include <linux/vserver/inode.h>
22883 +#include <linux/vserver/dlimit.h>
22886 +#ifdef CONFIG_COMPAT
22887 +#define __COMPAT(name, id, data, compat) \
22888 + (compat) ? name ## _x32(id, data) : name(id, data)
22889 +#define __COMPAT_NO_ID(name, data, compat) \
22890 + (compat) ? name ## _x32(data) : name(data)
22892 +#define __COMPAT(name, id, data, compat) \
22894 +#define __COMPAT_NO_ID(name, data, compat) \
22900 +long do_vcmd(uint32_t cmd, uint32_t id,
22901 + struct vx_info *vxi, struct nx_info *nxi,
22902 + void __user *data, int compat)
22906 + case VCMD_get_version:
22907 + return vc_get_version(id);
22908 + case VCMD_get_vci:
22909 + return vc_get_vci(id);
22911 + case VCMD_task_xid:
22912 + return vc_task_xid(id);
22913 + case VCMD_vx_info:
22914 + return vc_vx_info(vxi, data);
22916 + case VCMD_task_nid:
22917 + return vc_task_nid(id);
22918 + case VCMD_nx_info:
22919 + return vc_nx_info(nxi, data);
22921 + case VCMD_task_tag:
22922 + return vc_task_tag(id);
22924 + case VCMD_set_space_v1:
22925 + return vc_set_space_v1(vxi, data);
22926 + /* this is version 2 */
22927 + case VCMD_set_space:
22928 + return vc_set_space(vxi, data);
22930 + case VCMD_get_space_mask_v0:
22931 + return vc_get_space_mask(data, 0);
22932 + /* this is version 1 */
22933 + case VCMD_get_space_mask:
22934 + return vc_get_space_mask(data, 1);
22936 + case VCMD_get_space_default:
22937 + return vc_get_space_mask(data, -1);
22939 + case VCMD_set_umask:
22940 + return vc_set_umask(vxi, data);
22942 + case VCMD_get_umask:
22943 + return vc_get_umask(vxi, data);
22945 + case VCMD_set_wmask:
22946 + return vc_set_wmask(vxi, data);
22948 + case VCMD_get_wmask:
22949 + return vc_get_wmask(vxi, data);
22950 +#ifdef CONFIG_IA32_EMULATION
22951 + case VCMD_get_rlimit:
22952 + return __COMPAT(vc_get_rlimit, vxi, data, compat);
22953 + case VCMD_set_rlimit:
22954 + return __COMPAT(vc_set_rlimit, vxi, data, compat);
22956 + case VCMD_get_rlimit:
22957 + return vc_get_rlimit(vxi, data);
22958 + case VCMD_set_rlimit:
22959 + return vc_set_rlimit(vxi, data);
22961 + case VCMD_get_rlimit_mask:
22962 + return vc_get_rlimit_mask(id, data);
22963 + case VCMD_reset_hits:
22964 + return vc_reset_hits(vxi, data);
22965 + case VCMD_reset_minmax:
22966 + return vc_reset_minmax(vxi, data);
22968 + case VCMD_get_vhi_name:
22969 + return vc_get_vhi_name(vxi, data);
22970 + case VCMD_set_vhi_name:
22971 + return vc_set_vhi_name(vxi, data);
22973 + case VCMD_ctx_stat:
22974 + return vc_ctx_stat(vxi, data);
22975 + case VCMD_virt_stat:
22976 + return vc_virt_stat(vxi, data);
22977 + case VCMD_sock_stat:
22978 + return vc_sock_stat(vxi, data);
22979 + case VCMD_rlimit_stat:
22980 + return vc_rlimit_stat(vxi, data);
22982 + case VCMD_set_cflags:
22983 + return vc_set_cflags(vxi, data);
22984 + case VCMD_get_cflags:
22985 + return vc_get_cflags(vxi, data);
22987 + /* this is version 1 */
22988 + case VCMD_set_ccaps:
22989 + return vc_set_ccaps(vxi, data);
22990 + /* this is version 1 */
22991 + case VCMD_get_ccaps:
22992 + return vc_get_ccaps(vxi, data);
22993 + case VCMD_set_bcaps:
22994 + return vc_set_bcaps(vxi, data);
22995 + case VCMD_get_bcaps:
22996 + return vc_get_bcaps(vxi, data);
22998 + case VCMD_set_badness:
22999 + return vc_set_badness(vxi, data);
23000 + case VCMD_get_badness:
23001 + return vc_get_badness(vxi, data);
23003 + case VCMD_set_nflags:
23004 + return vc_set_nflags(nxi, data);
23005 + case VCMD_get_nflags:
23006 + return vc_get_nflags(nxi, data);
23008 + case VCMD_set_ncaps:
23009 + return vc_set_ncaps(nxi, data);
23010 + case VCMD_get_ncaps:
23011 + return vc_get_ncaps(nxi, data);
23013 + case VCMD_set_prio_bias:
23014 + return vc_set_prio_bias(vxi, data);
23015 + case VCMD_get_prio_bias:
23016 + return vc_get_prio_bias(vxi, data);
23017 + case VCMD_add_dlimit:
23018 + return __COMPAT(vc_add_dlimit, id, data, compat);
23019 + case VCMD_rem_dlimit:
23020 + return __COMPAT(vc_rem_dlimit, id, data, compat);
23021 + case VCMD_set_dlimit:
23022 + return __COMPAT(vc_set_dlimit, id, data, compat);
23023 + case VCMD_get_dlimit:
23024 + return __COMPAT(vc_get_dlimit, id, data, compat);
23026 + case VCMD_ctx_kill:
23027 + return vc_ctx_kill(vxi, data);
23029 + case VCMD_wait_exit:
23030 + return vc_wait_exit(vxi, data);
23032 + case VCMD_get_iattr:
23033 + return __COMPAT_NO_ID(vc_get_iattr, data, compat);
23034 + case VCMD_set_iattr:
23035 + return __COMPAT_NO_ID(vc_set_iattr, data, compat);
23037 + case VCMD_fget_iattr:
23038 + return vc_fget_iattr(id, data);
23039 + case VCMD_fset_iattr:
23040 + return vc_fset_iattr(id, data);
23042 + case VCMD_enter_space_v0:
23043 + return vc_enter_space_v1(vxi, NULL);
23044 + case VCMD_enter_space_v1:
23045 + return vc_enter_space_v1(vxi, data);
23046 + /* this is version 2 */
23047 + case VCMD_enter_space:
23048 + return vc_enter_space(vxi, data);
23050 + case VCMD_ctx_create_v0:
23051 + return vc_ctx_create(id, NULL);
23052 + case VCMD_ctx_create:
23053 + return vc_ctx_create(id, data);
23054 + case VCMD_ctx_migrate_v0:
23055 + return vc_ctx_migrate(vxi, NULL);
23056 + case VCMD_ctx_migrate:
23057 + return vc_ctx_migrate(vxi, data);
23059 + case VCMD_net_create_v0:
23060 + return vc_net_create(id, NULL);
23061 + case VCMD_net_create:
23062 + return vc_net_create(id, data);
23063 + case VCMD_net_migrate:
23064 + return vc_net_migrate(nxi, data);
23066 + case VCMD_tag_migrate:
23067 + return vc_tag_migrate(id);
23069 + case VCMD_net_add:
23070 + return vc_net_add(nxi, data);
23071 + case VCMD_net_remove:
23072 + return vc_net_remove(nxi, data);
23074 + case VCMD_net_add_ipv4_v1:
23075 + return vc_net_add_ipv4_v1(nxi, data);
23076 + /* this is version 2 */
23077 + case VCMD_net_add_ipv4:
23078 + return vc_net_add_ipv4(nxi, data);
23080 + case VCMD_net_rem_ipv4_v1:
23081 + return vc_net_rem_ipv4_v1(nxi, data);
23082 + /* this is version 2 */
23083 + case VCMD_net_rem_ipv4:
23084 + return vc_net_rem_ipv4(nxi, data);
23085 +#ifdef CONFIG_IPV6
23086 + case VCMD_net_add_ipv6:
23087 + return vc_net_add_ipv6(nxi, data);
23088 + case VCMD_net_remove_ipv6:
23089 + return vc_net_remove_ipv6(nxi, data);
23091 +/* case VCMD_add_match_ipv4:
23092 + return vc_add_match_ipv4(nxi, data);
23093 + case VCMD_get_match_ipv4:
23094 + return vc_get_match_ipv4(nxi, data);
23095 +#ifdef CONFIG_IPV6
23096 + case VCMD_add_match_ipv6:
23097 + return vc_add_match_ipv6(nxi, data);
23098 + case VCMD_get_match_ipv6:
23099 + return vc_get_match_ipv6(nxi, data);
23102 +#ifdef CONFIG_VSERVER_DEVICE
23103 + case VCMD_set_mapping:
23104 + return __COMPAT(vc_set_mapping, vxi, data, compat);
23105 + case VCMD_unset_mapping:
23106 + return __COMPAT(vc_unset_mapping, vxi, data, compat);
23108 +#ifdef CONFIG_VSERVER_HISTORY
23109 + case VCMD_dump_history:
23110 + return vc_dump_history(id);
23111 + case VCMD_read_history:
23112 + return __COMPAT(vc_read_history, id, data, compat);
23115 + vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
23116 + VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
23122 +#define __VCMD(vcmd, _perm, _args, _flags) \
23123 + case VCMD_ ## vcmd: perm = _perm; \
23124 + args = _args; flags = _flags; break
23127 +#define VCA_NONE 0x00
23128 +#define VCA_VXI 0x01
23129 +#define VCA_NXI 0x02
23131 +#define VCF_NONE 0x00
23132 +#define VCF_INFO 0x01
23133 +#define VCF_ADMIN 0x02
23134 +#define VCF_ARES 0x06 /* includes admin */
23135 +#define VCF_SETUP 0x08
23137 +#define VCF_ZIDOK 0x10 /* zero id okay */
23141 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
23144 + int permit = -1, state = 0;
23145 + int perm = -1, args = 0, flags = 0;
23146 + struct vx_info *vxi = NULL;
23147 + struct nx_info *nxi = NULL;
23150 + /* unpriviledged commands */
23151 + __VCMD(get_version, 0, VCA_NONE, 0);
23152 + __VCMD(get_vci, 0, VCA_NONE, 0);
23153 + __VCMD(get_rlimit_mask, 0, VCA_NONE, 0);
23154 + __VCMD(get_space_mask_v0,0, VCA_NONE, 0);
23155 + __VCMD(get_space_mask, 0, VCA_NONE, 0);
23156 + __VCMD(get_space_default,0, VCA_NONE, 0);
23158 + /* info commands */
23159 + __VCMD(task_xid, 2, VCA_NONE, 0);
23160 + __VCMD(reset_hits, 2, VCA_VXI, 0);
23161 + __VCMD(reset_minmax, 2, VCA_VXI, 0);
23162 + __VCMD(vx_info, 3, VCA_VXI, VCF_INFO);
23163 + __VCMD(get_bcaps, 3, VCA_VXI, VCF_INFO);
23164 + __VCMD(get_ccaps, 3, VCA_VXI, VCF_INFO);
23165 + __VCMD(get_cflags, 3, VCA_VXI, VCF_INFO);
23166 + __VCMD(get_umask, 3, VCA_VXI, VCF_INFO);
23167 + __VCMD(get_wmask, 3, VCA_VXI, VCF_INFO);
23168 + __VCMD(get_badness, 3, VCA_VXI, VCF_INFO);
23169 + __VCMD(get_vhi_name, 3, VCA_VXI, VCF_INFO);
23170 + __VCMD(get_rlimit, 3, VCA_VXI, VCF_INFO);
23172 + __VCMD(ctx_stat, 3, VCA_VXI, VCF_INFO);
23173 + __VCMD(virt_stat, 3, VCA_VXI, VCF_INFO);
23174 + __VCMD(sock_stat, 3, VCA_VXI, VCF_INFO);
23175 + __VCMD(rlimit_stat, 3, VCA_VXI, VCF_INFO);
23177 + __VCMD(task_nid, 2, VCA_NONE, 0);
23178 + __VCMD(nx_info, 3, VCA_NXI, VCF_INFO);
23179 + __VCMD(get_ncaps, 3, VCA_NXI, VCF_INFO);
23180 + __VCMD(get_nflags, 3, VCA_NXI, VCF_INFO);
23182 + __VCMD(task_tag, 2, VCA_NONE, 0);
23184 + __VCMD(get_iattr, 2, VCA_NONE, 0);
23185 + __VCMD(fget_iattr, 2, VCA_NONE, 0);
23186 + __VCMD(get_dlimit, 3, VCA_NONE, VCF_INFO);
23187 + __VCMD(get_prio_bias, 3, VCA_VXI, VCF_INFO);
23189 + /* lower admin commands */
23190 + __VCMD(wait_exit, 4, VCA_VXI, VCF_INFO);
23191 + __VCMD(ctx_create_v0, 5, VCA_NONE, 0);
23192 + __VCMD(ctx_create, 5, VCA_NONE, 0);
23193 + __VCMD(ctx_migrate_v0, 5, VCA_VXI, VCF_ADMIN);
23194 + __VCMD(ctx_migrate, 5, VCA_VXI, VCF_ADMIN);
23195 + __VCMD(enter_space_v0, 5, VCA_VXI, VCF_ADMIN);
23196 + __VCMD(enter_space_v1, 5, VCA_VXI, VCF_ADMIN);
23197 + __VCMD(enter_space, 5, VCA_VXI, VCF_ADMIN);
23199 + __VCMD(net_create_v0, 5, VCA_NONE, 0);
23200 + __VCMD(net_create, 5, VCA_NONE, 0);
23201 + __VCMD(net_migrate, 5, VCA_NXI, VCF_ADMIN);
23203 + __VCMD(tag_migrate, 5, VCA_NONE, VCF_ADMIN);
23205 + /* higher admin commands */
23206 + __VCMD(ctx_kill, 6, VCA_VXI, VCF_ARES);
23207 + __VCMD(set_space_v1, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23208 + __VCMD(set_space, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23210 + __VCMD(set_ccaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23211 + __VCMD(set_bcaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23212 + __VCMD(set_cflags, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23213 + __VCMD(set_umask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23214 + __VCMD(set_wmask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23215 + __VCMD(set_badness, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23217 + __VCMD(set_vhi_name, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23218 + __VCMD(set_rlimit, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23219 + __VCMD(set_prio_bias, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
23221 + __VCMD(set_ncaps, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
23222 + __VCMD(set_nflags, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
23223 + __VCMD(net_add, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23224 + __VCMD(net_remove, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23225 + __VCMD(net_add_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23226 + __VCMD(net_rem_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23227 + __VCMD(net_add_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23228 + __VCMD(net_rem_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23229 +#ifdef CONFIG_IPV6
23230 + __VCMD(net_add_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23231 + __VCMD(net_remove_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
23233 + __VCMD(set_iattr, 7, VCA_NONE, 0);
23234 + __VCMD(fset_iattr, 7, VCA_NONE, 0);
23235 + __VCMD(set_dlimit, 7, VCA_NONE, VCF_ARES);
23236 + __VCMD(add_dlimit, 8, VCA_NONE, VCF_ARES);
23237 + __VCMD(rem_dlimit, 8, VCA_NONE, VCF_ARES);
23239 +#ifdef CONFIG_VSERVER_DEVICE
23240 + __VCMD(set_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
23241 + __VCMD(unset_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
23243 + /* debug level admin commands */
23244 +#ifdef CONFIG_VSERVER_HISTORY
23245 + __VCMD(dump_history, 9, VCA_NONE, 0);
23246 + __VCMD(read_history, 9, VCA_NONE, 0);
23253 + vxdprintk(VXD_CBIT(switch, 0),
23254 + "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
23255 + VC_CATEGORY(cmd), VC_COMMAND(cmd),
23256 + VC_VERSION(cmd), id, data, compat,
23257 + perm, args, flags);
23264 + if (!capable(CAP_CONTEXT))
23268 + /* moved here from the individual commands */
23270 + if ((perm > 1) && !capable(CAP_SYS_ADMIN))
23274 + /* vcmd involves resource management */
23276 + if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
23280 + /* various legacy exceptions */
23282 + /* will go away when spectator is a cap */
23283 + case VCMD_ctx_migrate_v0:
23284 + case VCMD_ctx_migrate:
23286 + current->xid = 1;
23292 + /* will go away when spectator is a cap */
23293 + case VCMD_net_migrate:
23295 + current->nid = 1;
23302 + /* vcmds are fine by default */
23305 + /* admin type vcmds require admin ... */
23306 + if (flags & VCF_ADMIN)
23307 + permit = vx_check(0, VS_ADMIN) ? 1 : 0;
23309 + /* ... but setup type vcmds override that */
23310 + if (!permit && (flags & VCF_SETUP))
23311 + permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
23319 + if (!id && (flags & VCF_ZIDOK))
23323 + if (args & VCA_VXI) {
23324 + vxi = lookup_vx_info(id);
23328 + if ((flags & VCF_ADMIN) &&
23329 + /* special case kill for shutdown */
23330 + (cmd != VCMD_ctx_kill) &&
23331 + /* can context be administrated? */
23332 + !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
23338 + if (args & VCA_NXI) {
23339 + nxi = lookup_nx_info(id);
23343 + if ((flags & VCF_ADMIN) &&
23344 + /* can context be administrated? */
23345 + !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
23352 + ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
23355 + if ((args & VCA_NXI) && nxi)
23356 + put_nx_info(nxi);
23358 + if ((args & VCA_VXI) && vxi)
23359 + put_vx_info(vxi);
23361 + vxdprintk(VXD_CBIT(switch, 1),
23362 + "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
23363 + VC_CATEGORY(cmd), VC_COMMAND(cmd),
23364 + VC_VERSION(cmd), ret, ret, state, permit);
23369 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
23371 + return do_vserver(cmd, id, data, 0);
23374 +#ifdef CONFIG_COMPAT
23377 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
23379 + return do_vserver(cmd, id, data, 1);
23382 +#endif /* CONFIG_COMPAT */
23383 diff -NurpP --minimal linux-3.9.4/kernel/vserver/sysctl.c linux-3.9.4-vs2.3.6.2/kernel/vserver/sysctl.c
23384 --- linux-3.9.4/kernel/vserver/sysctl.c 1970-01-01 00:00:00.000000000 +0000
23385 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/sysctl.c 2013-05-31 14:47:11.000000000 +0000
23388 + * kernel/vserver/sysctl.c
23390 + * Virtual Context Support
23392 + * Copyright (C) 2004-2007 Herbert Pötzl
23394 + * V0.01 basic structure
23398 +#include <linux/module.h>
23399 +#include <linux/ctype.h>
23400 +#include <linux/sysctl.h>
23401 +#include <linux/parser.h>
23402 +#include <asm/uaccess.h>
23405 + CTL_DEBUG_ERROR = 0,
23406 + CTL_DEBUG_SWITCH = 1,
23422 +unsigned int vs_debug_switch = 0;
23423 +unsigned int vs_debug_xid = 0;
23424 +unsigned int vs_debug_nid = 0;
23425 +unsigned int vs_debug_tag = 0;
23426 +unsigned int vs_debug_net = 0;
23427 +unsigned int vs_debug_limit = 0;
23428 +unsigned int vs_debug_cres = 0;
23429 +unsigned int vs_debug_dlim = 0;
23430 +unsigned int vs_debug_quota = 0;
23431 +unsigned int vs_debug_cvirt = 0;
23432 +unsigned int vs_debug_space = 0;
23433 +unsigned int vs_debug_perm = 0;
23434 +unsigned int vs_debug_misc = 0;
23437 +static struct ctl_table_header *vserver_table_header;
23438 +static ctl_table vserver_root_table[];
23441 +void vserver_register_sysctl(void)
23443 + if (!vserver_table_header) {
23444 + vserver_table_header = register_sysctl_table(vserver_root_table);
23449 +void vserver_unregister_sysctl(void)
23451 + if (vserver_table_header) {
23452 + unregister_sysctl_table(vserver_table_header);
23453 + vserver_table_header = NULL;
23458 +static int proc_dodebug(ctl_table *table, int write,
23459 + void __user *buffer, size_t *lenp, loff_t *ppos)
23461 + char tmpbuf[20], *p, c;
23462 + unsigned int value;
23463 + size_t left, len;
23465 + if ((*ppos && !write) || !*lenp) {
23473 + if (!access_ok(VERIFY_READ, buffer, left))
23475 + p = (char *)buffer;
23476 + while (left && __get_user(c, p) >= 0 && isspace(c))
23481 + if (left > sizeof(tmpbuf) - 1)
23483 + if (copy_from_user(tmpbuf, p, left))
23485 + tmpbuf[left] = '\0';
23487 + for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
23488 + value = 10 * value + (*p - '0');
23489 + if (*p && !isspace(*p))
23491 + while (left && isspace(*p))
23493 + *(unsigned int *)table->data = value;
23495 + if (!access_ok(VERIFY_WRITE, buffer, left))
23497 + len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
23500 + if (__copy_to_user(buffer, tmpbuf, len))
23502 + if ((left -= len) > 0) {
23503 + if (put_user('\n', (char *)buffer + len))
23517 +#define CTL_ENTRY(ctl, name) \
23519 + .procname = #name, \
23520 + .data = &vs_ ## name, \
23521 + .maxlen = sizeof(int), \
23523 + .proc_handler = &proc_dodebug, \
23524 + .extra1 = &zero, \
23525 + .extra2 = &zero, \
23528 +static ctl_table vserver_debug_table[] = {
23529 + CTL_ENTRY(CTL_DEBUG_SWITCH, debug_switch),
23530 + CTL_ENTRY(CTL_DEBUG_XID, debug_xid),
23531 + CTL_ENTRY(CTL_DEBUG_NID, debug_nid),
23532 + CTL_ENTRY(CTL_DEBUG_TAG, debug_tag),
23533 + CTL_ENTRY(CTL_DEBUG_NET, debug_net),
23534 + CTL_ENTRY(CTL_DEBUG_LIMIT, debug_limit),
23535 + CTL_ENTRY(CTL_DEBUG_CRES, debug_cres),
23536 + CTL_ENTRY(CTL_DEBUG_DLIM, debug_dlim),
23537 + CTL_ENTRY(CTL_DEBUG_QUOTA, debug_quota),
23538 + CTL_ENTRY(CTL_DEBUG_CVIRT, debug_cvirt),
23539 + CTL_ENTRY(CTL_DEBUG_SPACE, debug_space),
23540 + CTL_ENTRY(CTL_DEBUG_PERM, debug_perm),
23541 + CTL_ENTRY(CTL_DEBUG_MISC, debug_misc),
23545 +static ctl_table vserver_root_table[] = {
23547 + .procname = "vserver",
23549 + .child = vserver_debug_table
23555 +static match_table_t tokens = {
23556 + { CTL_DEBUG_SWITCH, "switch=%x" },
23557 + { CTL_DEBUG_XID, "xid=%x" },
23558 + { CTL_DEBUG_NID, "nid=%x" },
23559 + { CTL_DEBUG_TAG, "tag=%x" },
23560 + { CTL_DEBUG_NET, "net=%x" },
23561 + { CTL_DEBUG_LIMIT, "limit=%x" },
23562 + { CTL_DEBUG_CRES, "cres=%x" },
23563 + { CTL_DEBUG_DLIM, "dlim=%x" },
23564 + { CTL_DEBUG_QUOTA, "quota=%x" },
23565 + { CTL_DEBUG_CVIRT, "cvirt=%x" },
23566 + { CTL_DEBUG_SPACE, "space=%x" },
23567 + { CTL_DEBUG_PERM, "perm=%x" },
23568 + { CTL_DEBUG_MISC, "misc=%x" },
23569 + { CTL_DEBUG_ERROR, NULL }
23572 +#define HANDLE_CASE(id, name, val) \
23573 + case CTL_DEBUG_ ## id: \
23574 + vs_debug_ ## name = val; \
23575 + printk("vs_debug_" #name "=0x%x\n", val); \
23579 +static int __init vs_debug_setup(char *str)
23584 + printk("vs_debug_setup(%s)\n", str);
23585 + while ((p = strsep(&str, ",")) != NULL) {
23586 + substring_t args[MAX_OPT_ARGS];
23587 + unsigned int value;
23592 + token = match_token(p, tokens, args);
23593 + value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
23596 + HANDLE_CASE(SWITCH, switch, value);
23597 + HANDLE_CASE(XID, xid, value);
23598 + HANDLE_CASE(NID, nid, value);
23599 + HANDLE_CASE(TAG, tag, value);
23600 + HANDLE_CASE(NET, net, value);
23601 + HANDLE_CASE(LIMIT, limit, value);
23602 + HANDLE_CASE(CRES, cres, value);
23603 + HANDLE_CASE(DLIM, dlim, value);
23604 + HANDLE_CASE(QUOTA, quota, value);
23605 + HANDLE_CASE(CVIRT, cvirt, value);
23606 + HANDLE_CASE(SPACE, space, value);
23607 + HANDLE_CASE(PERM, perm, value);
23608 + HANDLE_CASE(MISC, misc, value);
23617 +__setup("vsdebug=", vs_debug_setup);
23621 +EXPORT_SYMBOL_GPL(vs_debug_switch);
23622 +EXPORT_SYMBOL_GPL(vs_debug_xid);
23623 +EXPORT_SYMBOL_GPL(vs_debug_nid);
23624 +EXPORT_SYMBOL_GPL(vs_debug_net);
23625 +EXPORT_SYMBOL_GPL(vs_debug_limit);
23626 +EXPORT_SYMBOL_GPL(vs_debug_cres);
23627 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
23628 +EXPORT_SYMBOL_GPL(vs_debug_quota);
23629 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
23630 +EXPORT_SYMBOL_GPL(vs_debug_space);
23631 +EXPORT_SYMBOL_GPL(vs_debug_perm);
23632 +EXPORT_SYMBOL_GPL(vs_debug_misc);
23634 diff -NurpP --minimal linux-3.9.4/kernel/vserver/tag.c linux-3.9.4-vs2.3.6.2/kernel/vserver/tag.c
23635 --- linux-3.9.4/kernel/vserver/tag.c 1970-01-01 00:00:00.000000000 +0000
23636 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/tag.c 2013-05-31 14:47:11.000000000 +0000
23639 + * linux/kernel/vserver/tag.c
23641 + * Virtual Server: Shallow Tag Space
23643 + * Copyright (C) 2007 Herbert Pötzl
23645 + * V0.01 basic implementation
23649 +#include <linux/sched.h>
23650 +#include <linux/vserver/debug.h>
23651 +#include <linux/vs_pid.h>
23652 +#include <linux/vs_tag.h>
23654 +#include <linux/vserver/tag_cmd.h>
23657 +int dx_migrate_task(struct task_struct *p, tag_t tag)
23662 + vxdprintk(VXD_CBIT(tag, 5),
23663 + "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
23669 + vxdprintk(VXD_CBIT(tag, 5),
23670 + "moved task %p into [#%d]", p, tag);
23674 +/* vserver syscall commands below here */
23676 +/* taks xid and vx_info functions */
23679 +int vc_task_tag(uint32_t id)
23684 + struct task_struct *tsk;
23686 + tsk = find_task_by_real_pid(id);
23687 + tag = (tsk) ? tsk->tag : -ESRCH;
23688 + rcu_read_unlock();
23690 + tag = dx_current_tag();
23695 +int vc_tag_migrate(uint32_t tag)
23697 + return dx_migrate_task(current, tag & 0xFFFF);
23701 diff -NurpP --minimal linux-3.9.4/kernel/vserver/vci_config.h linux-3.9.4-vs2.3.6.2/kernel/vserver/vci_config.h
23702 --- linux-3.9.4/kernel/vserver/vci_config.h 1970-01-01 00:00:00.000000000 +0000
23703 +++ linux-3.9.4-vs2.3.6.2/kernel/vserver/vci_config.h 2013-05-31 14:47:11.000000000 +0000
23706 +/* interface version */
23708 +#define VCI_VERSION 0x00020308
23712 + VCI_KCBIT_NO_DYNAMIC = 0,
23714 + VCI_KCBIT_PROC_SECURE = 4,
23715 + /* VCI_KCBIT_HARDCPU = 5, */
23716 + /* VCI_KCBIT_IDLELIMIT = 6, */
23717 + /* VCI_KCBIT_IDLETIME = 7, */
23719 + VCI_KCBIT_COWBL = 8,
23720 + VCI_KCBIT_FULLCOWBL = 9,
23721 + VCI_KCBIT_SPACES = 10,
23722 + VCI_KCBIT_NETV2 = 11,
23723 + VCI_KCBIT_MEMCG = 12,
23724 + VCI_KCBIT_MEMCG_SWAP = 13,
23726 + VCI_KCBIT_DEBUG = 16,
23727 + VCI_KCBIT_HISTORY = 20,
23728 + VCI_KCBIT_TAGGED = 24,
23729 + VCI_KCBIT_PPTAG = 28,
23731 + VCI_KCBIT_MORE = 31,
23735 +static inline uint32_t vci_kernel_config(void)
23738 + (1 << VCI_KCBIT_NO_DYNAMIC) |
23740 + /* configured features */
23741 +#ifdef CONFIG_VSERVER_PROC_SECURE
23742 + (1 << VCI_KCBIT_PROC_SECURE) |
23744 +#ifdef CONFIG_VSERVER_COWBL
23745 + (1 << VCI_KCBIT_COWBL) |
23746 + (1 << VCI_KCBIT_FULLCOWBL) |
23748 + (1 << VCI_KCBIT_SPACES) |
23749 + (1 << VCI_KCBIT_NETV2) |
23750 +#ifdef CONFIG_MEMCG
23751 + (1 << VCI_KCBIT_MEMCG) |
23753 +#ifdef CONFIG_MEMCG_SWAP
23754 + (1 << VCI_KCBIT_MEMCG_SWAP) |
23757 + /* debug options */
23758 +#ifdef CONFIG_VSERVER_DEBUG
23759 + (1 << VCI_KCBIT_DEBUG) |
23761 +#ifdef CONFIG_VSERVER_HISTORY
23762 + (1 << VCI_KCBIT_HISTORY) |
23765 + /* inode context tagging */
23766 +#if defined(CONFIG_TAGGING_NONE)
23767 + (0 << VCI_KCBIT_TAGGED) |
23768 +#elif defined(CONFIG_TAGGING_UID16)
23769 + (1 << VCI_KCBIT_TAGGED) |
23770 +#elif defined(CONFIG_TAGGING_GID16)
23771 + (2 << VCI_KCBIT_TAGGED) |
23772 +#elif defined(CONFIG_TAGGING_ID24)
23773 + (3 << VCI_KCBIT_TAGGED) |
23774 +#elif defined(CONFIG_TAGGING_INTERN)
23775 + (4 << VCI_KCBIT_TAGGED) |
23776 +#elif defined(CONFIG_TAGGING_RUNTIME)
23777 + (5 << VCI_KCBIT_TAGGED) |
23779 + (7 << VCI_KCBIT_TAGGED) |
23781 + (1 << VCI_KCBIT_PPTAG) |
23785 diff -NurpP --minimal linux-3.9.4/mm/memcontrol.c linux-3.9.4-vs2.3.6.2/mm/memcontrol.c
23786 --- linux-3.9.4/mm/memcontrol.c 2013-05-31 13:45:31.000000000 +0000
23787 +++ linux-3.9.4-vs2.3.6.2/mm/memcontrol.c 2013-05-31 14:47:11.000000000 +0000
23788 @@ -1046,6 +1046,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23789 return mem_cgroup_from_css(task_subsys_state(p, mem_cgroup_subsys_id));
23792 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23794 + return res_counter_read_u64(&mem->res, member);
23797 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23799 + return res_counter_read_u64(&mem->memsw, member);
23802 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23804 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23807 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23809 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23812 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23814 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23817 struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23819 struct mem_cgroup *memcg = NULL;
23820 diff -NurpP --minimal linux-3.9.4/mm/oom_kill.c linux-3.9.4-vs2.3.6.2/mm/oom_kill.c
23821 --- linux-3.9.4/mm/oom_kill.c 2013-05-31 13:45:31.000000000 +0000
23822 +++ linux-3.9.4-vs2.3.6.2/mm/oom_kill.c 2013-05-31 14:47:11.000000000 +0000
23824 #include <linux/freezer.h>
23825 #include <linux/ftrace.h>
23826 #include <linux/ratelimit.h>
23827 +#include <linux/reboot.h>
23828 +#include <linux/vs_context.h>
23830 #define CREATE_TRACE_POINTS
23831 #include <trace/events/oom.h>
23832 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23833 static bool oom_unkillable_task(struct task_struct *p,
23834 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23836 - if (is_global_init(p))
23837 + unsigned xid = vx_current_xid();
23839 + /* skip the init task, global and per guest */
23840 + if (task_is_init(p))
23842 if (p->flags & PF_KTHREAD)
23845 + /* skip other guest and host processes if oom in guest */
23846 + if (xid && vx_task_xid(p) != xid)
23849 /* When mem_cgroup_out_of_memory() and p is not member of the group */
23850 if (memcg && !task_in_mem_cgroup(p, memcg))
23852 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23853 dump_header(p, gfp_mask, order, memcg, nodemask);
23856 - pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23857 - message, task_pid_nr(p), p->comm, points);
23858 + pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23859 + message, task_pid_nr(p), p->xid, p->comm, points);
23863 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23865 /* mm cannot safely be dereferenced after task_unlock(victim) */
23867 - pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23868 - task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23869 + pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23870 + task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23871 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23872 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23873 task_unlock(victim);
23874 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23876 EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23878 +long vs_oom_action(unsigned int);
23881 * Try to acquire the OOM killer lock for the zones in zonelist. Returns zero
23882 * if a parallel OOM killing is already taking place that includes a zone in
23883 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23884 /* Found nothing?!?! Either we hang forever, or we panic. */
23886 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23887 - panic("Out of memory and no killable processes...\n");
23889 + /* avoid panic for guest OOM */
23890 + if (vx_current_xid())
23891 + vs_oom_action(LINUX_REBOOT_CMD_OOM);
23893 + panic("Out of memory and no killable processes...\n");
23895 if (PTR_ERR(p) != -1UL) {
23896 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23897 diff -NurpP --minimal linux-3.9.4/mm/page_alloc.c linux-3.9.4-vs2.3.6.2/mm/page_alloc.c
23898 --- linux-3.9.4/mm/page_alloc.c 2013-05-31 13:45:31.000000000 +0000
23899 +++ linux-3.9.4-vs2.3.6.2/mm/page_alloc.c 2013-05-31 15:08:50.000000000 +0000
23901 #include <linux/migrate.h>
23902 #include <linux/page-debug-flags.h>
23903 #include <linux/sched/rt.h>
23904 +#include <linux/vs_base.h>
23905 +#include <linux/vs_limit.h>
23907 #include <asm/tlbflush.h>
23908 #include <asm/div64.h>
23909 @@ -2873,6 +2875,9 @@ void si_meminfo(struct sysinfo *val)
23910 val->totalhigh = totalhigh_pages;
23911 val->freehigh = nr_free_highpages();
23912 val->mem_unit = PAGE_SIZE;
23914 + if (vx_flags(VXF_VIRT_MEM, 0))
23915 + vx_vsi_meminfo(val);
23918 EXPORT_SYMBOL(si_meminfo);
23919 @@ -2893,6 +2898,9 @@ void si_meminfo_node(struct sysinfo *val
23922 val->mem_unit = PAGE_SIZE;
23924 + if (vx_flags(VXF_VIRT_MEM, 0))
23925 + vx_vsi_meminfo(val);
23929 diff -NurpP --minimal linux-3.9.4/mm/pgtable-generic.c linux-3.9.4-vs2.3.6.2/mm/pgtable-generic.c
23930 --- linux-3.9.4/mm/pgtable-generic.c 2013-02-19 13:58:57.000000000 +0000
23931 +++ linux-3.9.4-vs2.3.6.2/mm/pgtable-generic.c 2013-05-31 14:47:11.000000000 +0000
23933 * Copyright (C) 2010 Linus Torvalds
23936 +#include <linux/mm.h>
23938 #include <linux/pagemap.h>
23939 #include <asm/tlb.h>
23940 #include <asm-generic/pgtable.h>
23941 diff -NurpP --minimal linux-3.9.4/mm/shmem.c linux-3.9.4-vs2.3.6.2/mm/shmem.c
23942 --- linux-3.9.4/mm/shmem.c 2013-05-31 13:45:31.000000000 +0000
23943 +++ linux-3.9.4-vs2.3.6.2/mm/shmem.c 2013-05-31 14:47:11.000000000 +0000
23944 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23946 struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23948 - buf->f_type = TMPFS_MAGIC;
23949 + buf->f_type = TMPFS_SUPER_MAGIC;
23950 buf->f_bsize = PAGE_CACHE_SIZE;
23951 buf->f_namelen = NAME_MAX;
23952 if (sbinfo->max_blocks) {
23953 @@ -2606,7 +2606,7 @@ int shmem_fill_super(struct super_block
23954 sb->s_maxbytes = MAX_LFS_FILESIZE;
23955 sb->s_blocksize = PAGE_CACHE_SIZE;
23956 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23957 - sb->s_magic = TMPFS_MAGIC;
23958 + sb->s_magic = TMPFS_SUPER_MAGIC;
23959 sb->s_op = &shmem_ops;
23960 sb->s_time_gran = 1;
23961 #ifdef CONFIG_TMPFS_XATTR
23962 diff -NurpP --minimal linux-3.9.4/mm/slab.c linux-3.9.4-vs2.3.6.2/mm/slab.c
23963 --- linux-3.9.4/mm/slab.c 2013-05-31 13:45:31.000000000 +0000
23964 +++ linux-3.9.4-vs2.3.6.2/mm/slab.c 2013-05-31 14:47:11.000000000 +0000
23965 @@ -429,6 +429,8 @@ static void kmem_list3_init(struct kmem_
23966 #define STATS_INC_FREEMISS(x) do { } while (0)
23969 +#include "slab_vs.h"
23974 @@ -3438,6 +3440,7 @@ retry:
23976 obj = slab_get_obj(cachep, slabp, nodeid);
23977 check_slabp(cachep, slabp);
23978 + vx_slab_alloc(cachep, flags);
23979 l3->free_objects--;
23980 /* move slabp to correct slabp list: */
23981 list_del(&slabp->list);
23982 @@ -3517,6 +3520,7 @@ slab_alloc_node(struct kmem_cache *cache
23983 /* ___cache_alloc_node can fall back to other nodes */
23984 ptr = ____cache_alloc_node(cachep, flags, nodeid);
23986 + vx_slab_alloc(cachep, flags);
23987 local_irq_restore(save_flags);
23988 ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23989 kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23990 @@ -3709,6 +3713,7 @@ static inline void __cache_free(struct k
23992 kmemleak_free_recursive(objp, cachep->flags);
23993 objp = cache_free_debugcheck(cachep, objp, caller);
23994 + vx_slab_free(cachep);
23996 kmemcheck_slab_free(cachep, objp, cachep->object_size);
23998 diff -NurpP --minimal linux-3.9.4/mm/slab_vs.h linux-3.9.4-vs2.3.6.2/mm/slab_vs.h
23999 --- linux-3.9.4/mm/slab_vs.h 1970-01-01 00:00:00.000000000 +0000
24000 +++ linux-3.9.4-vs2.3.6.2/mm/slab_vs.h 2013-05-31 14:47:11.000000000 +0000
24003 +#include <linux/vserver/context.h>
24005 +#include <linux/vs_context.h>
24008 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
24010 + int what = gfp_zone(cachep->allocflags);
24011 + struct vx_info *vxi = current_vx_info();
24016 + atomic_add(cachep->size, &vxi->cacct.slab[what]);
24020 +void vx_slab_free(struct kmem_cache *cachep)
24022 + int what = gfp_zone(cachep->allocflags);
24023 + struct vx_info *vxi = current_vx_info();
24028 + atomic_sub(cachep->size, &vxi->cacct.slab[what]);
24031 diff -NurpP --minimal linux-3.9.4/mm/swapfile.c linux-3.9.4-vs2.3.6.2/mm/swapfile.c
24032 --- linux-3.9.4/mm/swapfile.c 2013-05-31 13:45:31.000000000 +0000
24033 +++ linux-3.9.4-vs2.3.6.2/mm/swapfile.c 2013-05-31 14:47:11.000000000 +0000
24035 #include <asm/tlbflush.h>
24036 #include <linux/swapops.h>
24037 #include <linux/page_cgroup.h>
24038 +#include <linux/vs_base.h>
24040 static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
24042 @@ -1767,6 +1768,16 @@ static int swap_show(struct seq_file *sw
24044 if (si == SEQ_START_TOKEN) {
24045 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
24046 + if (vx_flags(VXF_VIRT_MEM, 0)) {
24047 + struct sysinfo si;
24049 + vx_vsi_swapinfo(&si);
24050 + if (si.totalswap < (1 << 10))
24052 + seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
24053 + "hdv0", "partition", si.totalswap >> 10,
24054 + (si.totalswap - si.freeswap) >> 10, -1);
24059 @@ -2195,6 +2206,8 @@ void si_swapinfo(struct sysinfo *val)
24060 val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
24061 val->totalswap = total_swap_pages + nr_to_be_unused;
24062 spin_unlock(&swap_lock);
24063 + if (vx_flags(VXF_VIRT_MEM, 0))
24064 + vx_vsi_swapinfo(val);
24068 diff -NurpP --minimal linux-3.9.4/net/bridge/br_multicast.c linux-3.9.4-vs2.3.6.2/net/bridge/br_multicast.c
24069 --- linux-3.9.4/net/bridge/br_multicast.c 2013-05-31 13:45:31.000000000 +0000
24070 +++ linux-3.9.4-vs2.3.6.2/net/bridge/br_multicast.c 2013-05-31 17:17:53.000000000 +0000
24071 @@ -443,7 +443,7 @@ static struct sk_buff *br_ip6_multicast_
24072 ip6h->hop_limit = 1;
24073 ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
24074 if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
24076 + &ip6h->saddr, NULL)) {
24080 diff -NurpP --minimal linux-3.9.4/net/core/dev.c linux-3.9.4-vs2.3.6.2/net/core/dev.c
24081 --- linux-3.9.4/net/core/dev.c 2013-05-31 14:22:27.000000000 +0000
24082 +++ linux-3.9.4-vs2.3.6.2/net/core/dev.c 2013-05-31 18:37:38.000000000 +0000
24083 @@ -122,6 +122,7 @@
24084 #include <linux/in.h>
24085 #include <linux/jhash.h>
24086 #include <linux/random.h>
24087 +#include <linux/vs_inet.h>
24088 #include <trace/events/napi.h>
24089 #include <trace/events/net.h>
24090 #include <trace/events/skb.h>
24091 @@ -662,7 +663,8 @@ struct net_device *__dev_get_by_name(str
24092 struct hlist_head *head = dev_name_hash(net, name);
24094 hlist_for_each_entry(dev, head, name_hlist)
24095 - if (!strncmp(dev->name, name, IFNAMSIZ))
24096 + if (!strncmp(dev->name, name, IFNAMSIZ) &&
24097 + nx_dev_visible(current_nx_info(), dev))
24101 @@ -687,7 +689,8 @@ struct net_device *dev_get_by_name_rcu(s
24102 struct hlist_head *head = dev_name_hash(net, name);
24104 hlist_for_each_entry_rcu(dev, head, name_hlist)
24105 - if (!strncmp(dev->name, name, IFNAMSIZ))
24106 + if (!strncmp(dev->name, name, IFNAMSIZ) &&
24107 + nx_dev_visible(current_nx_info(), dev))
24111 @@ -737,7 +740,8 @@ struct net_device *__dev_get_by_index(st
24112 struct hlist_head *head = dev_index_hash(net, ifindex);
24114 hlist_for_each_entry(dev, head, index_hlist)
24115 - if (dev->ifindex == ifindex)
24116 + if ((dev->ifindex == ifindex) &&
24117 + nx_dev_visible(current_nx_info(), dev))
24121 @@ -755,7 +759,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
24122 * about locking. The caller must hold RCU lock.
24125 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24126 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
24128 struct net_device *dev;
24129 struct hlist_head *head = dev_index_hash(net, ifindex);
24130 @@ -766,6 +770,16 @@ struct net_device *dev_get_by_index_rcu(
24134 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
24136 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
24138 + struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
24140 + if (nx_dev_visible(current_nx_info(), dev))
24144 EXPORT_SYMBOL(dev_get_by_index_rcu);
24147 @@ -814,7 +828,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
24149 for_each_netdev_rcu(net, dev)
24150 if (dev->type == type &&
24151 - !memcmp(dev->dev_addr, ha, dev->addr_len))
24152 + !memcmp(dev->dev_addr, ha, dev->addr_len) &&
24153 + nx_dev_visible(current_nx_info(), dev))
24157 @@ -826,9 +841,11 @@ struct net_device *__dev_getfirstbyhwtyp
24158 struct net_device *dev;
24161 - for_each_netdev(net, dev)
24162 - if (dev->type == type)
24163 + for_each_netdev(net, dev) {
24164 + if ((dev->type == type) &&
24165 + nx_dev_visible(current_nx_info(), dev))
24171 @@ -840,7 +857,8 @@ struct net_device *dev_getfirstbyhwtype(
24174 for_each_netdev_rcu(net, dev)
24175 - if (dev->type == type) {
24176 + if ((dev->type == type) &&
24177 + nx_dev_visible(current_nx_info(), dev)) {
24181 @@ -868,7 +886,8 @@ struct net_device *dev_get_by_flags_rcu(
24184 for_each_netdev_rcu(net, dev) {
24185 - if (((dev->flags ^ if_flags) & mask) == 0) {
24186 + if ((((dev->flags ^ if_flags) & mask) == 0) &&
24187 + nx_dev_visible(current_nx_info(), dev)) {
24191 @@ -946,6 +965,8 @@ static int __dev_alloc_name(struct net *
24193 if (i < 0 || i >= max_netdevices)
24195 + if (!nx_dev_visible(current_nx_info(), d))
24198 /* avoid cases where sscanf is not exact inverse of printf */
24199 snprintf(buf, IFNAMSIZ, name, i);
24200 diff -NurpP --minimal linux-3.9.4/net/core/net-procfs.c linux-3.9.4-vs2.3.6.2/net/core/net-procfs.c
24201 --- linux-3.9.4/net/core/net-procfs.c 2013-05-31 13:45:32.000000000 +0000
24202 +++ linux-3.9.4-vs2.3.6.2/net/core/net-procfs.c 2013-06-01 10:40:52.000000000 +0000
24204 #include <linux/netdevice.h>
24205 #include <linux/proc_fs.h>
24206 #include <linux/seq_file.h>
24207 +#include <linux/vs_inet.h>
24208 #include <net/wext.h>
24210 #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
24211 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
24212 static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
24214 struct rtnl_link_stats64 temp;
24215 - const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
24216 + const struct rtnl_link_stats64 *stats;
24218 + /* device visible inside network context? */
24219 + if (!nx_dev_visible(current_nx_info(), dev))
24222 + stats = dev_get_stats(dev, &temp);
24223 seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
24224 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
24225 dev->name, stats->rx_bytes, stats->rx_packets,
24226 diff -NurpP --minimal linux-3.9.4/net/core/rtnetlink.c linux-3.9.4-vs2.3.6.2/net/core/rtnetlink.c
24227 --- linux-3.9.4/net/core/rtnetlink.c 2013-05-31 13:45:32.000000000 +0000
24228 +++ linux-3.9.4-vs2.3.6.2/net/core/rtnetlink.c 2013-05-31 17:17:54.000000000 +0000
24229 @@ -1085,6 +1085,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
24230 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24233 + if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
24235 if (rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
24236 NETLINK_CB(cb->skb).portid,
24237 cb->nlh->nlmsg_seq, 0,
24238 @@ -1974,6 +1976,9 @@ void rtmsg_ifinfo(int type, struct net_d
24239 int err = -ENOBUFS;
24240 size_t if_info_size;
24242 + if (!nx_dev_visible(current_nx_info(), dev))
24245 skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), GFP_KERNEL);
24248 diff -NurpP --minimal linux-3.9.4/net/core/sock.c linux-3.9.4-vs2.3.6.2/net/core/sock.c
24249 --- linux-3.9.4/net/core/sock.c 2013-05-31 14:22:27.000000000 +0000
24250 +++ linux-3.9.4-vs2.3.6.2/net/core/sock.c 2013-05-31 17:17:54.000000000 +0000
24251 @@ -132,6 +132,10 @@
24252 #include <net/netprio_cgroup.h>
24254 #include <linux/filter.h>
24255 +#include <linux/vs_socket.h>
24256 +#include <linux/vs_limit.h>
24257 +#include <linux/vs_context.h>
24258 +#include <linux/vs_network.h>
24260 #include <trace/events/sock.h>
24262 @@ -1257,6 +1261,8 @@ static struct sock *sk_prot_alloc(struct
24264 sk_tx_queue_clear(sk);
24266 + sock_vx_init(sk);
24267 + sock_nx_init(sk);
24271 @@ -1367,6 +1373,11 @@ static void __sk_free(struct sock *sk)
24272 put_cred(sk->sk_peer_cred);
24273 put_pid(sk->sk_peer_pid);
24274 put_net(sock_net(sk));
24276 + clr_vx_info(&sk->sk_vx_info);
24278 + clr_nx_info(&sk->sk_nx_info);
24280 sk_prot_free(sk->sk_prot_creator, sk);
24283 @@ -1427,6 +1438,8 @@ struct sock *sk_clone_lock(const struct
24286 get_net(sock_net(newsk));
24287 + sock_vx_init(newsk);
24288 + sock_nx_init(newsk);
24289 sk_node_init(&newsk->sk_node);
24290 sock_lock_init(newsk);
24291 bh_lock_sock(newsk);
24292 @@ -1483,6 +1496,12 @@ struct sock *sk_clone_lock(const struct
24294 atomic_set(&newsk->sk_refcnt, 2);
24296 + set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
24297 + newsk->sk_xid = sk->sk_xid;
24298 + vx_sock_inc(newsk);
24299 + set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
24300 + newsk->sk_nid = sk->sk_nid;
24303 * Increment the counter in the same struct proto as the master
24304 * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
24305 @@ -2278,6 +2297,12 @@ void sock_init_data(struct socket *sock,
24307 sk->sk_stamp = ktime_set(-1L, 0);
24309 + set_vx_info(&sk->sk_vx_info, current_vx_info());
24310 + sk->sk_xid = vx_current_xid();
24312 + set_nx_info(&sk->sk_nx_info, current_nx_info());
24313 + sk->sk_nid = nx_current_nid();
24316 * Before updating sk_refcnt, we must commit prior changes to memory
24317 * (Documentation/RCU/rculist_nulls.txt for details)
24318 diff -NurpP --minimal linux-3.9.4/net/ipv4/af_inet.c linux-3.9.4-vs2.3.6.2/net/ipv4/af_inet.c
24319 --- linux-3.9.4/net/ipv4/af_inet.c 2013-05-31 13:45:32.000000000 +0000
24320 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/af_inet.c 2013-05-31 18:24:05.000000000 +0000
24321 @@ -118,6 +118,7 @@
24322 #ifdef CONFIG_IP_MROUTE
24323 #include <linux/mroute.h>
24325 +#include <linux/vs_limit.h>
24328 /* The inetsw table contains everything that inet_create needs to
24329 @@ -336,6 +337,10 @@ lookup_protocol:
24333 + if ((protocol == IPPROTO_ICMP) &&
24334 + nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24337 if (sock->type == SOCK_RAW && !kern &&
24338 !ns_capable(net->user_ns, CAP_NET_RAW))
24339 goto out_rcu_unlock;
24340 @@ -460,6 +465,7 @@ int inet_bind(struct socket *sock, struc
24341 struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
24342 struct sock *sk = sock->sk;
24343 struct inet_sock *inet = inet_sk(sk);
24344 + struct nx_v4_sock_addr nsa;
24345 struct net *net = sock_net(sk);
24346 unsigned short snum;
24348 @@ -484,7 +490,11 @@ int inet_bind(struct socket *sock, struc
24352 - chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
24353 + err = v4_map_sock_addr(inet, addr, &nsa);
24357 + chk_addr_ret = inet_addr_type(net, nsa.saddr);
24359 /* Not specified by any standard per-se, however it breaks too
24360 * many applications when removed. It is unfortunate since
24361 @@ -496,7 +506,7 @@ int inet_bind(struct socket *sock, struc
24362 err = -EADDRNOTAVAIL;
24363 if (!sysctl_ip_nonlocal_bind &&
24364 !(inet->freebind || inet->transparent) &&
24365 - addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
24366 + nsa.saddr != htonl(INADDR_ANY) &&
24367 chk_addr_ret != RTN_LOCAL &&
24368 chk_addr_ret != RTN_MULTICAST &&
24369 chk_addr_ret != RTN_BROADCAST)
24370 @@ -522,7 +532,7 @@ int inet_bind(struct socket *sock, struc
24371 if (sk->sk_state != TCP_CLOSE || inet->inet_num)
24372 goto out_release_sock;
24374 - inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24375 + v4_set_sock_addr(inet, &nsa);
24376 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24377 inet->inet_saddr = 0; /* Use device */
24379 @@ -741,11 +751,13 @@ int inet_getname(struct socket *sock, st
24382 sin->sin_port = inet->inet_dport;
24383 - sin->sin_addr.s_addr = inet->inet_daddr;
24384 + sin->sin_addr.s_addr =
24385 + nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
24387 __be32 addr = inet->inet_rcv_saddr;
24389 addr = inet->inet_saddr;
24390 + addr = nx_map_sock_lback(sk->sk_nx_info, addr);
24391 sin->sin_port = inet->inet_sport;
24392 sin->sin_addr.s_addr = addr;
24394 diff -NurpP --minimal linux-3.9.4/net/ipv4/arp.c linux-3.9.4-vs2.3.6.2/net/ipv4/arp.c
24395 --- linux-3.9.4/net/ipv4/arp.c 2013-05-31 13:45:32.000000000 +0000
24396 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/arp.c 2013-05-31 17:17:54.000000000 +0000
24397 @@ -1317,6 +1317,7 @@ static void arp_format_neigh_entry(struc
24398 struct net_device *dev = n->dev;
24399 int hatype = dev->type;
24401 + /* FIXME: check for network context */
24402 read_lock(&n->lock);
24403 /* Convert hardware address to XX:XX:XX:XX ... form. */
24404 #if IS_ENABLED(CONFIG_AX25)
24405 @@ -1348,6 +1349,7 @@ static void arp_format_pneigh_entry(stru
24406 int hatype = dev ? dev->type : 0;
24409 + /* FIXME: check for network context */
24410 sprintf(tbuf, "%pI4", n->key);
24411 seq_printf(seq, "%-16s 0x%-10x0x%-10x%s * %s\n",
24412 tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
24413 diff -NurpP --minimal linux-3.9.4/net/ipv4/devinet.c linux-3.9.4-vs2.3.6.2/net/ipv4/devinet.c
24414 --- linux-3.9.4/net/ipv4/devinet.c 2013-05-31 13:45:32.000000000 +0000
24415 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/devinet.c 2013-05-31 17:17:54.000000000 +0000
24416 @@ -522,6 +522,7 @@ struct in_device *inetdev_by_index(struc
24418 EXPORT_SYMBOL(inetdev_by_index);
24421 /* Called only from RTNL semaphored context. No locks. */
24423 struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
24424 @@ -940,6 +941,8 @@ int devinet_ioctl(struct net *net, unsig
24426 in_dev = __in_dev_get_rtnl(dev);
24428 + struct nx_info *nxi = current_nx_info();
24430 if (tryaddrmatch) {
24431 /* Matthias Andree */
24432 /* compare label and address (4.4BSD style) */
24433 @@ -948,6 +951,8 @@ int devinet_ioctl(struct net *net, unsig
24434 This is checked above. */
24435 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24436 ifap = &ifa->ifa_next) {
24437 + if (!nx_v4_ifa_visible(nxi, ifa))
24439 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
24440 sin_orig.sin_addr.s_addr ==
24442 @@ -960,9 +965,12 @@ int devinet_ioctl(struct net *net, unsig
24443 comparing just the label */
24445 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
24446 - ifap = &ifa->ifa_next)
24447 + ifap = &ifa->ifa_next) {
24448 + if (!nx_v4_ifa_visible(nxi, ifa))
24450 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
24456 @@ -1116,6 +1124,8 @@ static int inet_gifconf(struct net_devic
24459 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
24460 + if (!nx_v4_ifa_visible(current_nx_info(), ifa))
24463 done += sizeof(ifr);
24465 @@ -1519,6 +1529,7 @@ static int inet_dump_ifaddr(struct sk_bu
24466 struct net_device *dev;
24467 struct in_device *in_dev;
24468 struct in_ifaddr *ifa;
24469 + struct sock *sk = skb->sk;
24470 struct hlist_head *head;
24473 @@ -1540,6 +1551,8 @@ static int inet_dump_ifaddr(struct sk_bu
24475 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
24476 ifa = ifa->ifa_next, ip_idx++) {
24477 + if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
24479 if (ip_idx < s_ip_idx)
24481 if (inet_fill_ifaddr(skb, ifa,
24482 diff -NurpP --minimal linux-3.9.4/net/ipv4/fib_trie.c linux-3.9.4-vs2.3.6.2/net/ipv4/fib_trie.c
24483 --- linux-3.9.4/net/ipv4/fib_trie.c 2013-05-31 13:45:32.000000000 +0000
24484 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/fib_trie.c 2013-05-31 17:17:54.000000000 +0000
24485 @@ -2548,6 +2548,7 @@ static int fib_route_seq_show(struct seq
24486 || fa->fa_type == RTN_MULTICAST)
24489 + /* FIXME: check for network context? */
24492 "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
24493 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_connection_sock.c linux-3.9.4-vs2.3.6.2/net/ipv4/inet_connection_sock.c
24494 --- linux-3.9.4/net/ipv4/inet_connection_sock.c 2013-05-31 13:45:32.000000000 +0000
24495 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/inet_connection_sock.c 2013-05-31 18:29:56.000000000 +0000
24496 @@ -53,6 +53,37 @@ void inet_get_local_port_range(int *low,
24498 EXPORT_SYMBOL(inet_get_local_port_range);
24500 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24502 + __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1),
24503 + sk2_rcv_saddr = sk_rcv_saddr(sk2);
24505 + if (inet_v6_ipv6only(sk2))
24508 + if (sk1_rcv_saddr &&
24510 + sk1_rcv_saddr == sk2_rcv_saddr)
24513 + if (sk1_rcv_saddr &&
24514 + !sk2_rcv_saddr &&
24515 + v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
24518 + if (sk2_rcv_saddr &&
24519 + !sk1_rcv_saddr &&
24520 + v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
24523 + if (!sk1_rcv_saddr &&
24524 + !sk2_rcv_saddr &&
24525 + nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
24531 int inet_csk_bind_conflict(const struct sock *sk,
24532 const struct inet_bind_bucket *tb, bool relax)
24534 @@ -79,17 +110,12 @@ int inet_csk_bind_conflict(const struct
24535 (!reuseport || !sk2->sk_reuseport ||
24536 (sk2->sk_state != TCP_TIME_WAIT &&
24537 !uid_eq(uid, sock_i_uid(sk2))))) {
24538 - const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24539 - if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24540 - sk2_rcv_saddr == sk_rcv_saddr(sk))
24541 + if (ipv4_rcv_saddr_equal(sk, sk2))
24544 if (!relax && reuse && sk2->sk_reuse &&
24545 sk2->sk_state != TCP_LISTEN) {
24546 - const __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
24548 - if (!sk2_rcv_saddr || !sk_rcv_saddr(sk) ||
24549 - sk2_rcv_saddr == sk_rcv_saddr(sk))
24550 + if (ipv4_rcv_saddr_equal(sk, sk2))
24554 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_diag.c linux-3.9.4-vs2.3.6.2/net/ipv4/inet_diag.c
24555 --- linux-3.9.4/net/ipv4/inet_diag.c 2013-02-19 13:58:58.000000000 +0000
24556 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/inet_diag.c 2013-05-31 17:17:54.000000000 +0000
24559 #include <linux/inet.h>
24560 #include <linux/stddef.h>
24561 +#include <linux/vs_network.h>
24562 +#include <linux/vs_inet.h>
24564 #include <linux/inet_diag.h>
24565 #include <linux/sock_diag.h>
24566 @@ -106,8 +108,10 @@ int inet_sk_diag_fill(struct sock *sk, s
24568 r->id.idiag_sport = inet->inet_sport;
24569 r->id.idiag_dport = inet->inet_dport;
24570 - r->id.idiag_src[0] = inet->inet_rcv_saddr;
24571 - r->id.idiag_dst[0] = inet->inet_daddr;
24572 + r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
24573 + inet->inet_rcv_saddr);
24574 + r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
24575 + inet->inet_daddr);
24577 if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
24579 @@ -242,8 +246,8 @@ static int inet_twsk_diag_fill(struct in
24580 sock_diag_save_cookie(tw, r->id.idiag_cookie);
24581 r->id.idiag_sport = tw->tw_sport;
24582 r->id.idiag_dport = tw->tw_dport;
24583 - r->id.idiag_src[0] = tw->tw_rcv_saddr;
24584 - r->id.idiag_dst[0] = tw->tw_daddr;
24585 + r->id.idiag_src[0] = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
24586 + r->id.idiag_dst[0] = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
24587 r->idiag_state = tw->tw_substate;
24588 r->idiag_timer = 3;
24589 r->idiag_expires = DIV_ROUND_UP(tmo * 1000, HZ);
24590 @@ -287,12 +291,14 @@ int inet_diag_dump_one_icsk(struct inet_
24593 if (req->sdiag_family == AF_INET) {
24594 + /* TODO: lback */
24595 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
24596 req->id.idiag_dport, req->id.idiag_src[0],
24597 req->id.idiag_sport, req->id.idiag_if);
24599 #if IS_ENABLED(CONFIG_IPV6)
24600 else if (req->sdiag_family == AF_INET6) {
24601 + /* TODO: lback */
24602 sk = inet6_lookup(net, hashinfo,
24603 (struct in6_addr *)req->id.idiag_dst,
24604 req->id.idiag_dport,
24605 @@ -494,6 +500,7 @@ int inet_diag_bc_sk(const struct nlattr
24609 + /* TODO: lback */
24610 entry.saddr = &inet->inet_rcv_saddr;
24611 entry.daddr = &inet->inet_daddr;
24613 @@ -652,6 +659,7 @@ static int inet_twsk_diag_dump(struct in
24617 + /* TODO: lback */
24618 entry.saddr = &tw->tw_rcv_saddr;
24619 entry.daddr = &tw->tw_daddr;
24621 @@ -730,8 +738,8 @@ static int inet_diag_fill_req(struct sk_
24623 r->id.idiag_sport = inet->inet_sport;
24624 r->id.idiag_dport = ireq->rmt_port;
24625 - r->id.idiag_src[0] = ireq->loc_addr;
24626 - r->id.idiag_dst[0] = ireq->rmt_addr;
24627 + r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->loc_addr);
24628 + r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->rmt_addr);
24629 r->idiag_expires = jiffies_to_msecs(tmo);
24630 r->idiag_rqueue = 0;
24631 r->idiag_wqueue = 0;
24632 @@ -794,6 +802,7 @@ static int inet_diag_dump_reqs(struct sk
24636 + /* TODO: lback */
24638 inet_diag_req_addrs(sk, req, &entry);
24639 entry.dport = ntohs(ireq->rmt_port);
24640 @@ -850,6 +859,8 @@ void inet_diag_dump_icsk(struct inet_has
24641 if (!net_eq(sock_net(sk), net))
24644 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24649 @@ -922,6 +933,8 @@ skip_listen_ht:
24651 if (!net_eq(sock_net(sk), net))
24653 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24657 if (!(r->idiag_states & (1 << sk->sk_state)))
24658 @@ -950,7 +963,8 @@ next_normal:
24660 if (!net_eq(twsk_net(tw), net))
24663 + if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24667 if (r->sdiag_family != AF_UNSPEC &&
24668 diff -NurpP --minimal linux-3.9.4/net/ipv4/inet_hashtables.c linux-3.9.4-vs2.3.6.2/net/ipv4/inet_hashtables.c
24669 --- linux-3.9.4/net/ipv4/inet_hashtables.c 2013-05-31 13:45:32.000000000 +0000
24670 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/inet_hashtables.c 2013-05-31 18:20:50.000000000 +0000
24672 #include <net/inet_connection_sock.h>
24673 #include <net/inet_hashtables.h>
24674 #include <net/secure_seq.h>
24675 +#include <net/route.h>
24676 #include <net/ip.h>
24679 @@ -156,6 +157,11 @@ static inline int compute_score(struct s
24680 if (rcv_saddr != daddr)
24684 + /* block non nx_info ips */
24685 + if (!v4_addr_in_nx_info(sk->sk_nx_info,
24686 + daddr, NXA_MASK_BIND))
24689 if (sk->sk_bound_dev_if) {
24690 if (sk->sk_bound_dev_if != dif)
24691 @@ -173,7 +179,6 @@ static inline int compute_score(struct s
24692 * wildcarded during the search since they can never be otherwise.
24696 struct sock *__inet_lookup_listener(struct net *net,
24697 struct inet_hashinfo *hashinfo,
24698 const __be32 saddr, __be16 sport,
24699 @@ -209,6 +214,7 @@ begin:
24700 phash = next_pseudo_random32(phash);
24705 * if the nulls value we got at the end of this lookup is
24706 * not the expected one, we must restart lookup.
24707 diff -NurpP --minimal linux-3.9.4/net/ipv4/netfilter.c linux-3.9.4-vs2.3.6.2/net/ipv4/netfilter.c
24708 --- linux-3.9.4/net/ipv4/netfilter.c 2012-12-11 03:30:57.000000000 +0000
24709 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/netfilter.c 2013-05-31 17:17:54.000000000 +0000
24711 #include <linux/skbuff.h>
24712 #include <linux/gfp.h>
24713 #include <linux/export.h>
24714 -#include <net/route.h>
24715 +// #include <net/route.h>
24716 #include <net/xfrm.h>
24717 #include <net/ip.h>
24718 #include <net/netfilter/nf_queue.h>
24719 diff -NurpP --minimal linux-3.9.4/net/ipv4/raw.c linux-3.9.4-vs2.3.6.2/net/ipv4/raw.c
24720 --- linux-3.9.4/net/ipv4/raw.c 2013-05-31 13:45:32.000000000 +0000
24721 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/raw.c 2013-05-31 18:19:38.000000000 +0000
24722 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
24724 if (net_eq(sock_net(sk), net) && inet->inet_num == num &&
24725 !(inet->inet_daddr && inet->inet_daddr != raddr) &&
24726 - !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
24727 + v4_sock_addr_match(sk->sk_nx_info, inet, laddr) &&
24728 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24729 goto found; /* gotcha */
24731 @@ -395,6 +395,12 @@ static int raw_send_hdrinc(struct sock *
24732 icmp_out_count(net, ((struct icmphdr *)
24733 skb_transport_header(skb))->type);
24736 + if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
24737 + sk->sk_nx_info &&
24738 + !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
24741 err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
24742 rt->dst.dev, dst_output);
24744 @@ -580,6 +586,16 @@ static int raw_sendmsg(struct kiocb *ioc
24748 + if (sk->sk_nx_info) {
24749 + rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
24750 + if (IS_ERR(rt)) {
24751 + err = PTR_ERR(rt);
24758 security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
24759 rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
24761 @@ -656,17 +672,19 @@ static int raw_bind(struct sock *sk, str
24763 struct inet_sock *inet = inet_sk(sk);
24764 struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
24765 + struct nx_v4_sock_addr nsa = { 0 };
24769 if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
24771 - chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
24772 + v4_map_sock_addr(inet, addr, &nsa);
24773 + chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
24774 ret = -EADDRNOTAVAIL;
24775 - if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
24776 + if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
24777 chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
24779 - inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
24780 + v4_set_sock_addr(inet, &nsa);
24781 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
24782 inet->inet_saddr = 0; /* Use device */
24784 @@ -718,7 +736,8 @@ static int raw_recvmsg(struct kiocb *ioc
24785 /* Copy the address. */
24787 sin->sin_family = AF_INET;
24788 - sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24789 + sin->sin_addr.s_addr =
24790 + nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
24792 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
24794 @@ -913,7 +932,8 @@ static struct sock *raw_get_first(struct
24795 for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
24797 sk_for_each(sk, &state->h->ht[state->bucket])
24798 - if (sock_net(sk) == seq_file_net(seq))
24799 + if ((sock_net(sk) == seq_file_net(seq)) &&
24800 + nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24804 @@ -929,7 +949,8 @@ static struct sock *raw_get_next(struct
24808 - } while (sk && sock_net(sk) != seq_file_net(seq));
24809 + } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24810 + !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24812 if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24813 sk = sk_head(&state->h->ht[state->bucket]);
24814 diff -NurpP --minimal linux-3.9.4/net/ipv4/route.c linux-3.9.4-vs2.3.6.2/net/ipv4/route.c
24815 --- linux-3.9.4/net/ipv4/route.c 2013-05-31 13:45:32.000000000 +0000
24816 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/route.c 2013-05-31 17:17:54.000000000 +0000
24817 @@ -1998,7 +1998,7 @@ struct rtable *__ip_route_output_key(str
24820 if (fl4->flowi4_oif) {
24821 - dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24822 + dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24823 rth = ERR_PTR(-ENODEV);
24824 if (dev_out == NULL)
24826 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp.c linux-3.9.4-vs2.3.6.2/net/ipv4/tcp.c
24827 --- linux-3.9.4/net/ipv4/tcp.c 2013-05-31 13:45:32.000000000 +0000
24828 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/tcp.c 2013-05-31 17:17:54.000000000 +0000
24829 @@ -268,6 +268,7 @@
24830 #include <linux/crypto.h>
24831 #include <linux/time.h>
24832 #include <linux/slab.h>
24833 +#include <linux/in.h>
24835 #include <net/icmp.h>
24836 #include <net/inet_common.h>
24837 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp_ipv4.c linux-3.9.4-vs2.3.6.2/net/ipv4/tcp_ipv4.c
24838 --- linux-3.9.4/net/ipv4/tcp_ipv4.c 2013-05-31 13:45:32.000000000 +0000
24839 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/tcp_ipv4.c 2013-05-31 17:17:54.000000000 +0000
24840 @@ -2260,6 +2260,12 @@ static void *listening_get_next(struct s
24841 req = req->dl_next;
24844 + vxdprintk(VXD_CBIT(net, 6),
24845 + "sk,req: %p [#%d] (from %d)", req->sk,
24846 + (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24848 + !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24850 if (req->rsk_ops->family == st->family) {
24853 @@ -2284,6 +2290,10 @@ get_req:
24856 sk_nulls_for_each_from(sk, node) {
24857 + vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24858 + sk, sk->sk_nid, nx_current_nid());
24859 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24861 if (!net_eq(sock_net(sk), net))
24863 if (sk->sk_family == st->family) {
24864 @@ -2360,6 +2370,11 @@ static void *established_get_first(struc
24866 spin_lock_bh(lock);
24867 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24868 + vxdprintk(VXD_CBIT(net, 6),
24869 + "sk,egf: %p [#%d] (from %d)",
24870 + sk, sk->sk_nid, nx_current_nid());
24871 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24873 if (sk->sk_family != st->family ||
24874 !net_eq(sock_net(sk), net)) {
24876 @@ -2370,6 +2385,11 @@ static void *established_get_first(struc
24877 st->state = TCP_SEQ_STATE_TIME_WAIT;
24878 inet_twsk_for_each(tw, node,
24879 &tcp_hashinfo.ehash[st->bucket].twchain) {
24880 + vxdprintk(VXD_CBIT(net, 6),
24881 + "tw: %p [#%d] (from %d)",
24882 + tw, tw->tw_nid, nx_current_nid());
24883 + if (!nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))
24885 if (tw->tw_family != st->family ||
24886 !net_eq(twsk_net(tw), net)) {
24888 @@ -2399,7 +2419,9 @@ static void *established_get_next(struct
24892 - while (tw && (tw->tw_family != st->family || !net_eq(twsk_net(tw), net))) {
24893 + while (tw && (tw->tw_family != st->family ||
24894 + !net_eq(twsk_net(tw), net) ||
24895 + !nx_check(tw->tw_nid, VS_WATCH_P | VS_IDENT))) {
24899 @@ -2423,6 +2445,11 @@ get_tw:
24900 sk = sk_nulls_next(sk);
24902 sk_nulls_for_each_from(sk, node) {
24903 + vxdprintk(VXD_CBIT(net, 6),
24904 + "sk,egn: %p [#%d] (from %d)",
24905 + sk, sk->sk_nid, nx_current_nid());
24906 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24908 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24911 @@ -2628,9 +2655,9 @@ static void get_openreq4(const struct so
24912 seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24913 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %pK%n",
24916 + nx_map_sock_lback(current_nx_info(), ireq->loc_addr),
24917 ntohs(inet_sk(sk)->inet_sport),
24919 + nx_map_sock_lback(current_nx_info(), ireq->rmt_addr),
24920 ntohs(ireq->rmt_port),
24922 0, 0, /* could print option size, but that is af dependent. */
24923 @@ -2653,8 +2680,8 @@ static void get_tcp4_sock(struct sock *s
24924 const struct inet_connection_sock *icsk = inet_csk(sk);
24925 const struct inet_sock *inet = inet_sk(sk);
24926 struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24927 - __be32 dest = inet->inet_daddr;
24928 - __be32 src = inet->inet_rcv_saddr;
24929 + __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24930 + __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24931 __u16 destp = ntohs(inet->inet_dport);
24932 __u16 srcp = ntohs(inet->inet_sport);
24934 @@ -2710,8 +2737,8 @@ static void get_timewait4_sock(const str
24936 long delta = tw->tw_ttd - jiffies;
24938 - dest = tw->tw_daddr;
24939 - src = tw->tw_rcv_saddr;
24940 + dest = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24941 + src = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24942 destp = ntohs(tw->tw_dport);
24943 srcp = ntohs(tw->tw_sport);
24945 diff -NurpP --minimal linux-3.9.4/net/ipv4/tcp_minisocks.c linux-3.9.4-vs2.3.6.2/net/ipv4/tcp_minisocks.c
24946 --- linux-3.9.4/net/ipv4/tcp_minisocks.c 2013-05-31 14:22:27.000000000 +0000
24947 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/tcp_minisocks.c 2013-05-31 17:17:54.000000000 +0000
24949 #include <linux/slab.h>
24950 #include <linux/sysctl.h>
24951 #include <linux/workqueue.h>
24952 +#include <linux/vs_limit.h>
24953 +#include <linux/vs_socket.h>
24954 +#include <linux/vs_context.h>
24955 #include <net/tcp.h>
24956 #include <net/inet_common.h>
24957 #include <net/xfrm.h>
24958 @@ -291,6 +294,11 @@ void tcp_time_wait(struct sock *sk, int
24959 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24960 tcptw->tw_ts_offset = tp->tsoffset;
24962 + tw->tw_xid = sk->sk_xid;
24963 + tw->tw_vx_info = NULL;
24964 + tw->tw_nid = sk->sk_nid;
24965 + tw->tw_nx_info = NULL;
24967 #if IS_ENABLED(CONFIG_IPV6)
24968 if (tw->tw_family == PF_INET6) {
24969 struct ipv6_pinfo *np = inet6_sk(sk);
24970 diff -NurpP --minimal linux-3.9.4/net/ipv4/udp.c linux-3.9.4-vs2.3.6.2/net/ipv4/udp.c
24971 --- linux-3.9.4/net/ipv4/udp.c 2013-05-31 13:45:32.000000000 +0000
24972 +++ linux-3.9.4-vs2.3.6.2/net/ipv4/udp.c 2013-05-31 18:26:00.000000000 +0000
24973 @@ -306,14 +306,7 @@ fail:
24975 EXPORT_SYMBOL(udp_lib_get_port);
24977 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24979 - struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24981 - return (!ipv6_only_sock(sk2) &&
24982 - (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24983 - inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24985 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24987 static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24989 @@ -348,6 +341,11 @@ static inline int compute_score(struct s
24990 if (inet->inet_rcv_saddr != daddr)
24994 + /* block non nx_info ips */
24995 + if (!v4_addr_in_nx_info(sk->sk_nx_info,
24996 + daddr, NXA_MASK_BIND))
24999 if (inet->inet_daddr) {
25000 if (inet->inet_daddr != saddr)
25001 @@ -458,6 +456,7 @@ begin:
25006 /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
25007 * harder than this. -DaveM
25009 @@ -504,6 +503,11 @@ begin:
25010 sk_nulls_for_each_rcu(sk, node, &hslot->head) {
25011 score = compute_score(sk, net, saddr, hnum, sport,
25012 daddr, dport, dif);
25013 + /* FIXME: disabled?
25014 + if (score == 9) {
25018 if (score > badness) {
25021 @@ -528,6 +532,7 @@ begin:
25022 if (get_nulls_value(node) != slot)
25027 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
25029 @@ -537,6 +542,7 @@ begin:
25037 @@ -580,8 +586,7 @@ static inline struct sock *udp_v4_mcast_
25038 udp_sk(s)->udp_port_hash != hnum ||
25039 (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
25040 (inet->inet_dport != rmt_port && inet->inet_dport) ||
25041 - (inet->inet_rcv_saddr &&
25042 - inet->inet_rcv_saddr != loc_addr) ||
25043 + !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
25044 ipv6_only_sock(s) ||
25045 (s->sk_bound_dev_if && s->sk_bound_dev_if != dif))
25047 @@ -964,6 +969,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
25048 inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
25049 faddr, saddr, dport, inet->inet_sport);
25051 + if (sk->sk_nx_info) {
25052 + rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
25053 + if (IS_ERR(rt)) {
25054 + err = PTR_ERR(rt);
25061 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
25062 rt = ip_route_output_flow(net, fl4, sk);
25064 @@ -1269,7 +1284,8 @@ try_again:
25066 sin->sin_family = AF_INET;
25067 sin->sin_port = udp_hdr(skb)->source;
25068 - sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
25069 + sin->sin_addr.s_addr = nx_map_sock_lback(
25070 + skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
25071 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
25073 if (inet->cmsg_flags)
25074 @@ -2025,6 +2041,8 @@ static struct sock *udp_get_first(struct
25075 sk_nulls_for_each(sk, node, &hslot->head) {
25076 if (!net_eq(sock_net(sk), net))
25078 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25080 if (sk->sk_family == state->family)
25083 @@ -2042,7 +2060,9 @@ static struct sock *udp_get_next(struct
25086 sk = sk_nulls_next(sk);
25087 - } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
25088 + } while (sk && (!net_eq(sock_net(sk), net) ||
25089 + sk->sk_family != state->family ||
25090 + !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
25093 if (state->bucket <= state->udp_table->mask)
25094 @@ -2138,8 +2158,8 @@ static void udp4_format_sock(struct sock
25095 int bucket, int *len)
25097 struct inet_sock *inet = inet_sk(sp);
25098 - __be32 dest = inet->inet_daddr;
25099 - __be32 src = inet->inet_rcv_saddr;
25100 + __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
25101 + __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
25102 __u16 destp = ntohs(inet->inet_dport);
25103 __u16 srcp = ntohs(inet->inet_sport);
25105 diff -NurpP --minimal linux-3.9.4/net/ipv6/Kconfig linux-3.9.4-vs2.3.6.2/net/ipv6/Kconfig
25106 --- linux-3.9.4/net/ipv6/Kconfig 2013-05-31 13:45:32.000000000 +0000
25107 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/Kconfig 2013-05-31 17:17:54.000000000 +0000
25110 # IPv6 as module will cause a CRASH if you try to unload it
25112 - tristate "The IPv6 protocol"
25114 + bool "The IPv6 protocol"
25117 This is complemental support for the IP version 6.
25118 You will still be able to do traditional IPv4 networking as well.
25119 diff -NurpP --minimal linux-3.9.4/net/ipv6/addrconf.c linux-3.9.4-vs2.3.6.2/net/ipv6/addrconf.c
25120 --- linux-3.9.4/net/ipv6/addrconf.c 2013-05-31 13:45:32.000000000 +0000
25121 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/addrconf.c 2013-05-31 20:07:39.000000000 +0000
25123 #include <linux/proc_fs.h>
25124 #include <linux/seq_file.h>
25125 #include <linux/export.h>
25126 +#include <linux/vs_network.h>
25127 +#include <linux/vs_inet6.h>
25129 /* Set to 3 to get tracing... */
25130 #define ACONF_DEBUG 2
25131 @@ -1250,7 +1252,7 @@ out:
25133 int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
25134 const struct in6_addr *daddr, unsigned int prefs,
25135 - struct in6_addr *saddr)
25136 + struct in6_addr *saddr, struct nx_info *nxi)
25138 struct ipv6_saddr_score scores[2],
25139 *score = &scores[0], *hiscore = &scores[1];
25140 @@ -1322,6 +1324,8 @@ int ipv6_dev_get_saddr(struct net *net,
25144 + if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
25148 bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
25149 @@ -3311,7 +3315,10 @@ static void if6_seq_stop(struct seq_file
25150 static int if6_seq_show(struct seq_file *seq, void *v)
25152 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
25153 - seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25155 + if (nx_check(0, VS_ADMIN|VS_WATCH) ||
25156 + v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
25157 + seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
25159 ifp->idev->dev->ifindex,
25161 @@ -3815,6 +3822,11 @@ static int in6_dump_addrs(struct inet6_d
25162 struct ifacaddr6 *ifaca;
25164 int ip_idx = *p_ip_idx;
25165 + struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25167 + /* disable ipv6 on non v6 guests */
25168 + if (nxi && !nx_info_has_v6(nxi))
25171 read_lock_bh(&idev->lock);
25173 @@ -3825,6 +3837,8 @@ static int in6_dump_addrs(struct inet6_d
25174 list_for_each_entry(ifa, &idev->addr_list, if_list) {
25175 if (++ip_idx < s_ip_idx)
25177 + if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
25179 err = inet6_fill_ifaddr(skb, ifa,
25180 NETLINK_CB(cb->skb).portid,
25181 cb->nlh->nlmsg_seq,
25182 @@ -3841,6 +3855,8 @@ static int in6_dump_addrs(struct inet6_d
25183 ifmca = ifmca->next, ip_idx++) {
25184 if (ip_idx < s_ip_idx)
25186 + if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
25188 err = inet6_fill_ifmcaddr(skb, ifmca,
25189 NETLINK_CB(cb->skb).portid,
25190 cb->nlh->nlmsg_seq,
25191 @@ -3856,6 +3872,8 @@ static int in6_dump_addrs(struct inet6_d
25192 ifaca = ifaca->aca_next, ip_idx++) {
25193 if (ip_idx < s_ip_idx)
25195 + if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
25197 err = inet6_fill_ifacaddr(skb, ifaca,
25198 NETLINK_CB(cb->skb).portid,
25199 cb->nlh->nlmsg_seq,
25200 @@ -3884,6 +3902,10 @@ static int inet6_dump_addr(struct sk_buf
25201 struct inet6_dev *idev;
25202 struct hlist_head *head;
25204 + /* FIXME: maybe disable ipv6 on non v6 guests?
25205 + if (skb->sk && skb->sk->sk_vx_info)
25206 + return skb->len; */
25209 s_idx = idx = cb->args[1];
25210 s_ip_idx = ip_idx = cb->args[2];
25211 @@ -4238,6 +4260,7 @@ static int inet6_dump_ifinfo(struct sk_b
25212 struct net_device *dev;
25213 struct inet6_dev *idev;
25214 struct hlist_head *head;
25215 + struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
25218 s_idx = cb->args[1];
25219 @@ -4249,6 +4272,8 @@ static int inet6_dump_ifinfo(struct sk_b
25220 hlist_for_each_entry_rcu(dev, head, index_hlist) {
25223 + if (!v6_dev_in_nx_info(dev, nxi))
25225 idev = __in6_dev_get(dev);
25228 diff -NurpP --minimal linux-3.9.4/net/ipv6/af_inet6.c linux-3.9.4-vs2.3.6.2/net/ipv6/af_inet6.c
25229 --- linux-3.9.4/net/ipv6/af_inet6.c 2013-05-31 13:45:32.000000000 +0000
25230 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/af_inet6.c 2013-05-31 20:04:41.000000000 +0000
25232 #include <linux/netdevice.h>
25233 #include <linux/icmpv6.h>
25234 #include <linux/netfilter_ipv6.h>
25235 +#include <linux/vs_inet.h>
25236 +#include <linux/vs_inet6.h>
25238 #include <net/ip.h>
25239 #include <net/ipv6.h>
25240 @@ -160,10 +162,13 @@ lookup_protocol:
25244 + if ((protocol == IPPROTO_ICMPV6) &&
25245 + nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
25247 if (sock->type == SOCK_RAW && !kern &&
25248 !ns_capable(net->user_ns, CAP_NET_RAW))
25249 goto out_rcu_unlock;
25252 sock->ops = answer->ops;
25253 answer_prot = answer->prot;
25254 answer_no_check = answer->no_check;
25255 @@ -263,6 +268,7 @@ int inet6_bind(struct socket *sock, stru
25256 struct inet_sock *inet = inet_sk(sk);
25257 struct ipv6_pinfo *np = inet6_sk(sk);
25258 struct net *net = sock_net(sk);
25259 + struct nx_v6_sock_addr nsa;
25261 unsigned short snum;
25263 @@ -278,6 +284,10 @@ int inet6_bind(struct socket *sock, stru
25264 if (addr->sin6_family != AF_INET6)
25265 return -EAFNOSUPPORT;
25267 + err = v6_map_sock_addr(inet, addr, &nsa);
25271 addr_type = ipv6_addr_type(&addr->sin6_addr);
25272 if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
25274 @@ -309,6 +319,7 @@ int inet6_bind(struct socket *sock, stru
25275 /* Reproduce AF_INET checks to make the bindings consistent */
25276 v4addr = addr->sin6_addr.s6_addr32[3];
25277 chk_addr_ret = inet_addr_type(net, v4addr);
25279 if (!sysctl_ip_nonlocal_bind &&
25280 !(inet->freebind || inet->transparent) &&
25281 v4addr != htonl(INADDR_ANY) &&
25282 @@ -318,6 +329,10 @@ int inet6_bind(struct socket *sock, stru
25283 err = -EADDRNOTAVAIL;
25286 + if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
25287 + err = -EADDRNOTAVAIL;
25291 if (addr_type != IPV6_ADDR_ANY) {
25292 struct net_device *dev = NULL;
25293 @@ -344,6 +359,11 @@ int inet6_bind(struct socket *sock, stru
25297 + if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25298 + err = -EADDRNOTAVAIL;
25302 /* ipv4 addr of the socket is invalid. Only the
25303 * unspecified and mapped address have a v4 equivalent.
25305 @@ -360,6 +380,9 @@ int inet6_bind(struct socket *sock, stru
25309 + /* what's that for? */
25310 + v6_set_sock_addr(inet, &nsa);
25312 inet->inet_rcv_saddr = v4addr;
25313 inet->inet_saddr = v4addr;
25315 @@ -461,9 +484,11 @@ int inet6_getname(struct socket *sock, s
25317 sin->sin6_port = inet->inet_dport;
25318 sin->sin6_addr = np->daddr;
25319 + /* FIXME: remap lback? */
25321 sin->sin6_flowinfo = np->flow_label;
25323 + /* FIXME: remap lback? */
25324 if (ipv6_addr_any(&np->rcv_saddr))
25325 sin->sin6_addr = np->saddr;
25327 diff -NurpP --minimal linux-3.9.4/net/ipv6/datagram.c linux-3.9.4-vs2.3.6.2/net/ipv6/datagram.c
25328 --- linux-3.9.4/net/ipv6/datagram.c 2013-05-31 13:45:32.000000000 +0000
25329 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/datagram.c 2013-05-31 17:17:54.000000000 +0000
25330 @@ -648,7 +648,7 @@ int ip6_datagram_send_ctl(struct net *ne
25333 if (fl6->flowi6_oif) {
25334 - dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
25335 + dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
25339 diff -NurpP --minimal linux-3.9.4/net/ipv6/fib6_rules.c linux-3.9.4-vs2.3.6.2/net/ipv6/fib6_rules.c
25340 --- linux-3.9.4/net/ipv6/fib6_rules.c 2013-02-19 13:58:58.000000000 +0000
25341 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/fib6_rules.c 2013-05-31 17:17:54.000000000 +0000
25342 @@ -90,7 +90,7 @@ static int fib6_rule_action(struct fib_r
25343 ip6_dst_idev(&rt->dst)->dev,
25345 rt6_flags2srcprefs(flags),
25349 if (!ipv6_prefix_equal(&saddr, &r->src.addr,
25351 diff -NurpP --minimal linux-3.9.4/net/ipv6/inet6_hashtables.c linux-3.9.4-vs2.3.6.2/net/ipv6/inet6_hashtables.c
25352 --- linux-3.9.4/net/ipv6/inet6_hashtables.c 2013-05-31 13:45:32.000000000 +0000
25353 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/inet6_hashtables.c 2013-05-31 17:17:54.000000000 +0000
25356 #include <linux/module.h>
25357 #include <linux/random.h>
25358 +#include <linux/vs_inet6.h>
25360 #include <net/inet_connection_sock.h>
25361 #include <net/inet_hashtables.h>
25362 @@ -83,7 +84,6 @@ struct sock *__inet6_lookup_established(
25363 unsigned int slot = hash & hashinfo->ehash_mask;
25364 struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
25369 sk_nulls_for_each_rcu(sk, node, &head->chain) {
25370 @@ -97,7 +97,7 @@ begin:
25378 if (get_nulls_value(node) != slot)
25379 @@ -147,6 +147,9 @@ static inline int compute_score(struct s
25380 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25384 + if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25387 if (sk->sk_bound_dev_if) {
25388 if (sk->sk_bound_dev_if != dif)
25389 diff -NurpP --minimal linux-3.9.4/net/ipv6/ip6_output.c linux-3.9.4-vs2.3.6.2/net/ipv6/ip6_output.c
25390 --- linux-3.9.4/net/ipv6/ip6_output.c 2013-05-31 13:45:32.000000000 +0000
25391 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/ip6_output.c 2013-05-31 17:17:54.000000000 +0000
25392 @@ -877,7 +877,8 @@ static int ip6_dst_lookup_tail(struct so
25393 struct rt6_info *rt = (struct rt6_info *) *dst;
25394 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
25395 sk ? inet6_sk(sk)->srcprefs : 0,
25398 + sk ? sk->sk_nx_info : NULL);
25400 goto out_err_release;
25402 diff -NurpP --minimal linux-3.9.4/net/ipv6/ndisc.c linux-3.9.4-vs2.3.6.2/net/ipv6/ndisc.c
25403 --- linux-3.9.4/net/ipv6/ndisc.c 2013-05-31 13:45:32.000000000 +0000
25404 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/ndisc.c 2013-05-31 17:17:54.000000000 +0000
25405 @@ -485,7 +485,7 @@ static void ndisc_send_na(struct net_dev
25407 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
25408 inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
25412 src_addr = &tmpaddr;
25414 diff -NurpP --minimal linux-3.9.4/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.9.4-vs2.3.6.2/net/ipv6/netfilter/ip6t_MASQUERADE.c
25415 --- linux-3.9.4/net/ipv6/netfilter/ip6t_MASQUERADE.c 2012-12-11 03:30:57.000000000 +0000
25416 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/netfilter/ip6t_MASQUERADE.c 2013-05-31 17:17:54.000000000 +0000
25417 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
25418 ctinfo == IP_CT_RELATED_REPLY));
25420 if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
25421 - &ipv6_hdr(skb)->daddr, 0, &src) < 0)
25422 + &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
25425 nfct_nat(ct)->masq_index = par->out->ifindex;
25426 diff -NurpP --minimal linux-3.9.4/net/ipv6/raw.c linux-3.9.4-vs2.3.6.2/net/ipv6/raw.c
25427 --- linux-3.9.4/net/ipv6/raw.c 2013-05-31 13:45:32.000000000 +0000
25428 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/raw.c 2013-05-31 17:17:54.000000000 +0000
25430 #include <linux/icmpv6.h>
25431 #include <linux/netfilter.h>
25432 #include <linux/netfilter_ipv6.h>
25433 +#include <linux/vs_inet6.h>
25434 #include <linux/skbuff.h>
25435 #include <linux/compat.h>
25436 #include <asm/uaccess.h>
25437 @@ -283,6 +284,13 @@ static int rawv6_bind(struct sock *sk, s
25441 + if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
25442 + err = -EADDRNOTAVAIL;
25448 /* ipv4 addr of the socket is invalid. Only the
25449 * unspecified and mapped address have a v4 equivalent.
25451 diff -NurpP --minimal linux-3.9.4/net/ipv6/route.c linux-3.9.4-vs2.3.6.2/net/ipv6/route.c
25452 --- linux-3.9.4/net/ipv6/route.c 2013-05-31 13:45:32.000000000 +0000
25453 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/route.c 2013-05-31 18:10:38.000000000 +0000
25455 #include <net/netevent.h>
25456 #include <net/netlink.h>
25457 #include <net/nexthop.h>
25458 +#include <linux/vs_inet6.h>
25460 #include <asm/uaccess.h>
25462 @@ -2079,15 +2080,17 @@ int ip6_route_get_saddr(struct net *net,
25463 struct rt6_info *rt,
25464 const struct in6_addr *daddr,
25465 unsigned int prefs,
25466 - struct in6_addr *saddr)
25467 + struct in6_addr *saddr,
25468 + struct nx_info *nxi)
25470 struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
25472 - if (rt->rt6i_prefsrc.plen)
25473 + if (rt->rt6i_prefsrc.plen && (!nxi ||
25474 + v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
25475 *saddr = rt->rt6i_prefsrc.addr;
25477 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
25478 - daddr, prefs, saddr);
25479 + daddr, prefs, saddr, nxi);
25483 @@ -2507,7 +2510,8 @@ static int rt6_fill_node(struct net *net
25484 goto nla_put_failure;
25486 struct in6_addr saddr_buf;
25487 - if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
25488 + if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
25489 + (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
25490 nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
25491 goto nla_put_failure;
25493 @@ -2719,6 +2723,7 @@ static int rt6_info_route(struct rt6_inf
25495 struct seq_file *m = p_arg;
25497 + /* FIXME: check for network context? */
25498 seq_printf(m, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
25500 #ifdef CONFIG_IPV6_SUBTREES
25501 diff -NurpP --minimal linux-3.9.4/net/ipv6/tcp_ipv6.c linux-3.9.4-vs2.3.6.2/net/ipv6/tcp_ipv6.c
25502 --- linux-3.9.4/net/ipv6/tcp_ipv6.c 2013-05-31 14:22:27.000000000 +0000
25503 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/tcp_ipv6.c 2013-05-31 17:17:54.000000000 +0000
25506 #include <linux/crypto.h>
25507 #include <linux/scatterlist.h>
25508 +#include <linux/vs_inet6.h>
25510 static void tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
25511 static void tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
25512 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
25513 * connect() to INADDR_ANY means loopback (BSD'ism).
25516 - if(ipv6_addr_any(&usin->sin6_addr))
25517 - usin->sin6_addr.s6_addr[15] = 0x1;
25518 + if(ipv6_addr_any(&usin->sin6_addr)) {
25519 + struct nx_info *nxi = sk->sk_nx_info;
25521 + if (nxi && nx_info_has_v6(nxi))
25522 + /* FIXME: remap lback? */
25523 + usin->sin6_addr = nxi->v6.ip;
25525 + usin->sin6_addr.s6_addr[15] = 0x1;
25528 addr_type = ipv6_addr_type(&usin->sin6_addr);
25530 diff -NurpP --minimal linux-3.9.4/net/ipv6/udp.c linux-3.9.4-vs2.3.6.2/net/ipv6/udp.c
25531 --- linux-3.9.4/net/ipv6/udp.c 2013-05-31 14:22:27.000000000 +0000
25532 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/udp.c 2013-05-31 18:16:01.000000000 +0000
25533 @@ -46,42 +46,68 @@
25534 #include <net/ip6_checksum.h>
25535 #include <net/xfrm.h>
25536 #include <net/inet6_hashtables.h>
25537 +#include <linux/vs_inet6.h>
25539 #include <linux/proc_fs.h>
25540 #include <linux/seq_file.h>
25541 #include <trace/events/skb.h>
25542 #include "udp_impl.h"
25544 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
25545 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
25547 - const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
25548 + const struct in6_addr *sk1_rcv_saddr6 = &inet6_sk(sk1)->rcv_saddr;
25549 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
25550 - __be32 sk1_rcv_saddr = sk_rcv_saddr(sk);
25551 + __be32 sk1_rcv_saddr = sk_rcv_saddr(sk1);
25552 __be32 sk2_rcv_saddr = sk_rcv_saddr(sk2);
25553 - int sk_ipv6only = ipv6_only_sock(sk);
25554 + int sk1_ipv6only = ipv6_only_sock(sk1);
25555 int sk2_ipv6only = inet_v6_ipv6only(sk2);
25556 - int addr_type = ipv6_addr_type(sk_rcv_saddr6);
25557 + int addr_type = ipv6_addr_type(sk1_rcv_saddr6);
25558 int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
25560 /* if both are mapped, treat as IPv4 */
25561 - if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
25562 - return (!sk2_ipv6only &&
25563 + if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
25564 + if (!sk2_ipv6only &&
25565 (!sk1_rcv_saddr || !sk2_rcv_saddr ||
25566 - sk1_rcv_saddr == sk2_rcv_saddr));
25567 + sk1_rcv_saddr == sk2_rcv_saddr))
25573 if (addr_type2 == IPV6_ADDR_ANY &&
25574 !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
25578 if (addr_type == IPV6_ADDR_ANY &&
25579 - !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25581 + !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
25584 if (sk2_rcv_saddr6 &&
25585 - ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
25587 + ipv6_addr_equal(sk1_rcv_saddr6, sk2_rcv_saddr6))
25593 + if (!sk1_rcv_saddr && !sk2_rcv_saddr)
25594 + return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25595 + if (!sk2_rcv_saddr)
25596 + return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
25597 + if (!sk1_rcv_saddr)
25598 + return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
25601 + if (addr_type2 == IPV6_ADDR_ANY && addr_type == IPV6_ADDR_ANY)
25602 + return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25603 + else if (addr_type2 == IPV6_ADDR_ANY)
25604 + return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
25605 + else if (addr_type == IPV6_ADDR_ANY) {
25606 + if (addr_type2 == IPV6_ADDR_MAPPED)
25607 + return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
25609 + return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
25614 static unsigned int udp6_portaddr_hash(struct net *net,
25615 @@ -145,6 +171,10 @@ static inline int compute_score(struct s
25616 if (!ipv6_addr_equal(&np->rcv_saddr, daddr))
25620 + /* block non nx_info ips */
25621 + if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
25624 if (!ipv6_addr_any(&np->daddr)) {
25625 if (!ipv6_addr_equal(&np->daddr, saddr))
25626 diff -NurpP --minimal linux-3.9.4/net/ipv6/xfrm6_policy.c linux-3.9.4-vs2.3.6.2/net/ipv6/xfrm6_policy.c
25627 --- linux-3.9.4/net/ipv6/xfrm6_policy.c 2013-05-31 14:22:27.000000000 +0000
25628 +++ linux-3.9.4-vs2.3.6.2/net/ipv6/xfrm6_policy.c 2013-05-31 17:17:54.000000000 +0000
25629 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
25630 dev = ip6_dst_idev(dst)->dev;
25631 ipv6_dev_get_saddr(dev_net(dev), dev,
25632 (struct in6_addr *)&daddr->a6, 0,
25633 - (struct in6_addr *)&saddr->a6);
25634 + (struct in6_addr *)&saddr->a6, NULL);
25638 diff -NurpP --minimal linux-3.9.4/net/netfilter/ipvs/ip_vs_xmit.c linux-3.9.4-vs2.3.6.2/net/netfilter/ipvs/ip_vs_xmit.c
25639 --- linux-3.9.4/net/netfilter/ipvs/ip_vs_xmit.c 2013-02-19 13:58:59.000000000 +0000
25640 +++ linux-3.9.4-vs2.3.6.2/net/netfilter/ipvs/ip_vs_xmit.c 2013-05-31 17:17:54.000000000 +0000
25641 @@ -273,7 +273,7 @@ __ip_vs_route_output_v6(struct net *net,
25643 if (ipv6_addr_any(&fl6.saddr) &&
25644 ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
25645 - &fl6.daddr, 0, &fl6.saddr) < 0)
25646 + &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
25649 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
25650 diff -NurpP --minimal linux-3.9.4/net/netlink/af_netlink.c linux-3.9.4-vs2.3.6.2/net/netlink/af_netlink.c
25651 --- linux-3.9.4/net/netlink/af_netlink.c 2013-05-31 13:45:33.000000000 +0000
25652 +++ linux-3.9.4-vs2.3.6.2/net/netlink/af_netlink.c 2013-05-31 17:17:54.000000000 +0000
25654 #include <linux/types.h>
25655 #include <linux/audit.h>
25656 #include <linux/mutex.h>
25657 +#include <linux/vs_context.h>
25658 +#include <linux/vs_network.h>
25659 +#include <linux/vs_limit.h>
25661 #include <net/net_namespace.h>
25662 #include <net/sock.h>
25663 @@ -1976,6 +1979,8 @@ static struct sock *netlink_seq_socket_i
25664 sk_for_each(s, &hash->table[j]) {
25665 if (sock_net(s) != seq_file_net(seq))
25667 + if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25671 iter->hash_idx = j;
25672 @@ -2010,7 +2015,8 @@ static void *netlink_seq_next(struct seq
25676 - } while (s && sock_net(s) != seq_file_net(seq));
25677 + } while (s && (sock_net(s) != seq_file_net(seq) ||
25678 + !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
25682 @@ -2022,7 +2028,8 @@ static void *netlink_seq_next(struct seq
25684 for (; j <= hash->mask; j++) {
25685 s = sk_head(&hash->table[j]);
25686 - while (s && sock_net(s) != seq_file_net(seq))
25687 + while (s && (sock_net(s) != seq_file_net(seq) ||
25688 + !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
25692 diff -NurpP --minimal linux-3.9.4/net/socket.c linux-3.9.4-vs2.3.6.2/net/socket.c
25693 --- linux-3.9.4/net/socket.c 2013-05-31 13:45:33.000000000 +0000
25694 +++ linux-3.9.4-vs2.3.6.2/net/socket.c 2013-05-31 17:17:54.000000000 +0000
25697 #include <net/sock.h>
25698 #include <linux/netfilter.h>
25699 +#include <linux/vs_base.h>
25700 +#include <linux/vs_socket.h>
25701 +#include <linux/vs_inet.h>
25702 +#include <linux/vs_inet6.h>
25704 #include <linux/if_tun.h>
25705 #include <linux/ipv6_route.h>
25706 @@ -617,13 +621,29 @@ static inline int __sock_sendmsg_nosec(s
25707 struct msghdr *msg, size_t size)
25709 struct sock_iocb *si = kiocb_to_siocb(iocb);
25717 - return sock->ops->sendmsg(iocb, sock, msg, size);
25718 + len = sock->ops->sendmsg(iocb, sock, msg, size);
25721 + vx_sock_send(sock->sk, size);
25723 + vx_sock_fail(sock->sk, size);
25725 + vxdprintk(VXD_CBIT(net, 7),
25726 + "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
25728 + (sock->sk)?sock->sk->sk_nx_info:0,
25729 + (sock->sk)?sock->sk->sk_vx_info:0,
25730 + (sock->sk)?sock->sk->sk_xid:0,
25731 + (sock->sk)?sock->sk->sk_nid:0,
25732 + (unsigned int)size, len);
25736 static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
25737 @@ -779,6 +799,7 @@ static inline int __sock_recvmsg_nosec(s
25738 struct msghdr *msg, size_t size, int flags)
25740 struct sock_iocb *si = kiocb_to_siocb(iocb);
25745 @@ -786,7 +807,18 @@ static inline int __sock_recvmsg_nosec(s
25749 - return sock->ops->recvmsg(iocb, sock, msg, size, flags);
25750 + len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
25751 + if ((len >= 0) && sock->sk)
25752 + vx_sock_recv(sock->sk, len);
25753 + vxdprintk(VXD_CBIT(net, 7),
25754 + "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
25756 + (sock->sk)?sock->sk->sk_nx_info:0,
25757 + (sock->sk)?sock->sk->sk_vx_info:0,
25758 + (sock->sk)?sock->sk->sk_xid:0,
25759 + (sock->sk)?sock->sk->sk_nid:0,
25760 + (unsigned int)size, len);
25764 static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
25765 @@ -1269,6 +1301,13 @@ int __sock_create(struct net *net, int f
25766 if (type < 0 || type >= SOCK_MAX)
25769 + if (!nx_check(0, VS_ADMIN)) {
25770 + if (family == PF_INET && !current_nx_info_has_v4())
25771 + return -EAFNOSUPPORT;
25772 + if (family == PF_INET6 && !current_nx_info_has_v6())
25773 + return -EAFNOSUPPORT;
25778 This uglymoron is moved from INET layer to here to avoid
25779 @@ -1403,6 +1442,7 @@ SYSCALL_DEFINE3(socket, int, family, int
25783 + set_bit(SOCK_USER_SOCKET, &sock->flags);
25784 retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
25787 @@ -1444,10 +1484,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
25788 err = sock_create(family, type, protocol, &sock1);
25791 + set_bit(SOCK_USER_SOCKET, &sock1->flags);
25793 err = sock_create(family, type, protocol, &sock2);
25795 goto out_release_1;
25796 + set_bit(SOCK_USER_SOCKET, &sock2->flags);
25798 err = sock1->ops->socketpair(sock1, sock2);
25800 diff -NurpP --minimal linux-3.9.4/net/sunrpc/auth.c linux-3.9.4-vs2.3.6.2/net/sunrpc/auth.c
25801 --- linux-3.9.4/net/sunrpc/auth.c 2013-05-31 13:45:33.000000000 +0000
25802 +++ linux-3.9.4-vs2.3.6.2/net/sunrpc/auth.c 2013-05-31 18:01:00.000000000 +0000
25804 #include <linux/sunrpc/clnt.h>
25805 #include <linux/sunrpc/gss_api.h>
25806 #include <linux/spinlock.h>
25807 +#include <linux/vs_tag.h>
25810 # define RPCDBG_FACILITY RPCDBG_AUTH
25811 @@ -480,6 +481,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
25812 memset(&acred, 0, sizeof(acred));
25813 acred.uid = cred->fsuid;
25814 acred.gid = cred->fsgid;
25815 + acred.tag = dx_current_tag();
25816 acred.group_info = get_group_info(((struct cred *)cred)->group_info);
25818 ret = auth->au_ops->lookup_cred(auth, &acred, flags);
25819 @@ -520,6 +522,7 @@ rpcauth_bind_root_cred(struct rpc_task *
25820 struct auth_cred acred = {
25821 .uid = GLOBAL_ROOT_UID,
25822 .gid = GLOBAL_ROOT_GID,
25823 + .tag = dx_current_tag(),
25826 dprintk("RPC: %5u looking up %s cred\n",
25827 diff -NurpP --minimal linux-3.9.4/net/sunrpc/auth_unix.c linux-3.9.4-vs2.3.6.2/net/sunrpc/auth_unix.c
25828 --- linux-3.9.4/net/sunrpc/auth_unix.c 2013-05-31 13:45:33.000000000 +0000
25829 +++ linux-3.9.4-vs2.3.6.2/net/sunrpc/auth_unix.c 2013-05-31 18:05:54.000000000 +0000
25830 @@ -13,11 +13,13 @@
25831 #include <linux/sunrpc/clnt.h>
25832 #include <linux/sunrpc/auth.h>
25833 #include <linux/user_namespace.h>
25834 +#include <linux/vs_tag.h>
25836 #define NFS_NGROUPS 16
25839 struct rpc_cred uc_base;
25842 kgid_t uc_gids[NFS_NGROUPS];
25844 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25845 groups = NFS_NGROUPS;
25847 cred->uc_gid = acred->gid;
25848 + cred->uc_tag = acred->tag;
25849 for (i = 0; i < groups; i++)
25850 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25851 if (i < NFS_NGROUPS)
25852 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25856 - if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25857 + if (!uid_eq(cred->uc_uid, acred->uid) ||
25858 + !gid_eq(cred->uc_gid, acred->gid) ||
25859 + !tag_eq(cred->uc_tag, acred->tag))
25862 if (acred->group_info != NULL)
25863 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25864 struct rpc_clnt *clnt = task->tk_client;
25865 struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25866 __be32 *base, *hold;
25870 *p++ = htonl(RPC_AUTH_UNIX);
25872 @@ -157,8 +162,13 @@ unx_marshal(struct rpc_task *task, __be3
25874 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25876 - *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25877 - *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25878 + tag = task->tk_client->cl_tag;
25879 + *p++ = htonl((u32) TAGINO_UID(tag,
25880 + from_kuid(&init_user_ns, cred->uc_uid),
25881 + from_ktag(&init_user_ns, cred->uc_tag)));
25882 + *p++ = htonl((u32) TAGINO_GID(tag,
25883 + from_kgid(&init_user_ns, cred->uc_gid),
25884 + from_ktag(&init_user_ns, cred->uc_tag)));
25886 for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25887 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25888 diff -NurpP --minimal linux-3.9.4/net/sunrpc/clnt.c linux-3.9.4-vs2.3.6.2/net/sunrpc/clnt.c
25889 --- linux-3.9.4/net/sunrpc/clnt.c 2013-05-31 13:45:33.000000000 +0000
25890 +++ linux-3.9.4-vs2.3.6.2/net/sunrpc/clnt.c 2013-05-31 17:17:54.000000000 +0000
25892 #include <linux/in6.h>
25893 #include <linux/un.h>
25894 #include <linux/rcupdate.h>
25895 +#include <linux/vs_cvirt.h>
25897 #include <linux/sunrpc/clnt.h>
25898 #include <linux/sunrpc/addr.h>
25899 @@ -482,6 +483,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25900 if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25901 clnt->cl_chatty = 1;
25903 + /* TODO: handle RPC_CLNT_CREATE_TAGGED
25904 + if (args->flags & RPC_CLNT_CREATE_TAGGED)
25905 + clnt->cl_tag = 1; */
25908 EXPORT_SYMBOL_GPL(rpc_create);
25909 diff -NurpP --minimal linux-3.9.4/net/unix/af_unix.c linux-3.9.4-vs2.3.6.2/net/unix/af_unix.c
25910 --- linux-3.9.4/net/unix/af_unix.c 2013-05-31 13:45:33.000000000 +0000
25911 +++ linux-3.9.4-vs2.3.6.2/net/unix/af_unix.c 2013-05-31 17:17:54.000000000 +0000
25912 @@ -114,6 +114,8 @@
25913 #include <linux/mount.h>
25914 #include <net/checksum.h>
25915 #include <linux/security.h>
25916 +#include <linux/vs_context.h>
25917 +#include <linux/vs_limit.h>
25919 struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25920 EXPORT_SYMBOL_GPL(unix_socket_table);
25921 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25922 if (!net_eq(sock_net(s), net))
25925 + if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25927 if (u->addr->len == len &&
25928 !memcmp(u->addr->name, sunname, len))
25930 @@ -2256,6 +2260,8 @@ static struct sock *unix_from_bucket(str
25931 for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25932 if (sock_net(sk) != seq_file_net(seq))
25934 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25936 if (++count == offset)
25939 @@ -2273,6 +2279,8 @@ static struct sock *unix_next_socket(str
25943 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25945 if (sock_net(sk) == seq_file_net(seq))
25948 diff -NurpP --minimal linux-3.9.4/scripts/checksyscalls.sh linux-3.9.4-vs2.3.6.2/scripts/checksyscalls.sh
25949 --- linux-3.9.4/scripts/checksyscalls.sh 2012-12-11 03:30:57.000000000 +0000
25950 +++ linux-3.9.4-vs2.3.6.2/scripts/checksyscalls.sh 2013-05-31 14:47:11.000000000 +0000
25951 @@ -193,7 +193,6 @@ cat << EOF
25952 #define __IGNORE_afs_syscall
25953 #define __IGNORE_getpmsg
25954 #define __IGNORE_putpmsg
25955 -#define __IGNORE_vserver
25959 diff -NurpP --minimal linux-3.9.4/scripts/mod/devicetable-offsets.h linux-3.9.4-vs2.3.6.2/scripts/mod/devicetable-offsets.h
25960 --- linux-3.9.4/scripts/mod/devicetable-offsets.h 1970-01-01 00:00:00.000000000 +0000
25961 +++ linux-3.9.4-vs2.3.6.2/scripts/mod/devicetable-offsets.h 2013-06-01 10:46:36.000000000 +0000
25963 +#ifndef __DEVICEVTABLE_OFFSETS_H__
25964 +#define __DEVICEVTABLE_OFFSETS_H__
25968 + * This file was generated by Kbuild
25972 +#define SIZE_usb_device_id 32 /* sizeof(struct usb_device_id) # */
25973 +#define OFF_usb_device_id_match_flags 0 /* offsetof(struct usb_device_id, match_flags) # */
25974 +#define OFF_usb_device_id_idVendor 2 /* offsetof(struct usb_device_id, idVendor) # */
25975 +#define OFF_usb_device_id_idProduct 4 /* offsetof(struct usb_device_id, idProduct) # */
25976 +#define OFF_usb_device_id_bcdDevice_lo 6 /* offsetof(struct usb_device_id, bcdDevice_lo) # */
25977 +#define OFF_usb_device_id_bcdDevice_hi 8 /* offsetof(struct usb_device_id, bcdDevice_hi) # */
25978 +#define OFF_usb_device_id_bDeviceClass 10 /* offsetof(struct usb_device_id, bDeviceClass) # */
25979 +#define OFF_usb_device_id_bDeviceSubClass 11 /* offsetof(struct usb_device_id, bDeviceSubClass) # */
25980 +#define OFF_usb_device_id_bDeviceProtocol 12 /* offsetof(struct usb_device_id, bDeviceProtocol) # */
25981 +#define OFF_usb_device_id_bInterfaceClass 13 /* offsetof(struct usb_device_id, bInterfaceClass) # */
25982 +#define OFF_usb_device_id_bInterfaceSubClass 14 /* offsetof(struct usb_device_id, bInterfaceSubClass) # */
25983 +#define OFF_usb_device_id_bInterfaceProtocol 15 /* offsetof(struct usb_device_id, bInterfaceProtocol) # */
25984 +#define OFF_usb_device_id_bInterfaceNumber 16 /* offsetof(struct usb_device_id, bInterfaceNumber) # */
25985 +#define SIZE_hid_device_id 24 /* sizeof(struct hid_device_id) # */
25986 +#define OFF_hid_device_id_bus 0 /* offsetof(struct hid_device_id, bus) # */
25987 +#define OFF_hid_device_id_group 2 /* offsetof(struct hid_device_id, group) # */
25988 +#define OFF_hid_device_id_vendor 4 /* offsetof(struct hid_device_id, vendor) # */
25989 +#define OFF_hid_device_id_product 8 /* offsetof(struct hid_device_id, product) # */
25990 +#define SIZE_ieee1394_device_id 32 /* sizeof(struct ieee1394_device_id) # */
25991 +#define OFF_ieee1394_device_id_match_flags 0 /* offsetof(struct ieee1394_device_id, match_flags) # */
25992 +#define OFF_ieee1394_device_id_vendor_id 4 /* offsetof(struct ieee1394_device_id, vendor_id) # */
25993 +#define OFF_ieee1394_device_id_model_id 8 /* offsetof(struct ieee1394_device_id, model_id) # */
25994 +#define OFF_ieee1394_device_id_specifier_id 12 /* offsetof(struct ieee1394_device_id, specifier_id) # */
25995 +#define OFF_ieee1394_device_id_version 16 /* offsetof(struct ieee1394_device_id, version) # */
25996 +#define SIZE_pci_device_id 32 /* sizeof(struct pci_device_id) # */
25997 +#define OFF_pci_device_id_vendor 0 /* offsetof(struct pci_device_id, vendor) # */
25998 +#define OFF_pci_device_id_device 4 /* offsetof(struct pci_device_id, device) # */
25999 +#define OFF_pci_device_id_subvendor 8 /* offsetof(struct pci_device_id, subvendor) # */
26000 +#define OFF_pci_device_id_subdevice 12 /* offsetof(struct pci_device_id, subdevice) # */
26001 +#define OFF_pci_device_id_class 16 /* offsetof(struct pci_device_id, class) # */
26002 +#define OFF_pci_device_id_class_mask 20 /* offsetof(struct pci_device_id, class_mask) # */
26003 +#define SIZE_ccw_device_id 16 /* sizeof(struct ccw_device_id) # */
26004 +#define OFF_ccw_device_id_match_flags 0 /* offsetof(struct ccw_device_id, match_flags) # */
26005 +#define OFF_ccw_device_id_cu_type 2 /* offsetof(struct ccw_device_id, cu_type) # */
26006 +#define OFF_ccw_device_id_cu_model 6 /* offsetof(struct ccw_device_id, cu_model) # */
26007 +#define OFF_ccw_device_id_dev_type 4 /* offsetof(struct ccw_device_id, dev_type) # */
26008 +#define OFF_ccw_device_id_dev_model 7 /* offsetof(struct ccw_device_id, dev_model) # */
26009 +#define SIZE_ap_device_id 16 /* sizeof(struct ap_device_id) # */
26010 +#define OFF_ap_device_id_dev_type 2 /* offsetof(struct ap_device_id, dev_type) # */
26011 +#define SIZE_css_device_id 16 /* sizeof(struct css_device_id) # */
26012 +#define OFF_css_device_id_type 1 /* offsetof(struct css_device_id, type) # */
26013 +#define SIZE_serio_device_id 4 /* sizeof(struct serio_device_id) # */
26014 +#define OFF_serio_device_id_type 0 /* offsetof(struct serio_device_id, type) # */
26015 +#define OFF_serio_device_id_proto 3 /* offsetof(struct serio_device_id, proto) # */
26016 +#define OFF_serio_device_id_id 2 /* offsetof(struct serio_device_id, id) # */
26017 +#define OFF_serio_device_id_extra 1 /* offsetof(struct serio_device_id, extra) # */
26018 +#define SIZE_acpi_device_id 24 /* sizeof(struct acpi_device_id) # */
26019 +#define OFF_acpi_device_id_id 0 /* offsetof(struct acpi_device_id, id) # */
26020 +#define SIZE_pnp_device_id 16 /* sizeof(struct pnp_device_id) # */
26021 +#define OFF_pnp_device_id_id 0 /* offsetof(struct pnp_device_id, id) # */
26022 +#define SIZE_pnp_card_device_id 80 /* sizeof(struct pnp_card_device_id) # */
26023 +#define OFF_pnp_card_device_id_devs 16 /* offsetof(struct pnp_card_device_id, devs) # */
26024 +#define SIZE_pcmcia_device_id 80 /* sizeof(struct pcmcia_device_id) # */
26025 +#define OFF_pcmcia_device_id_match_flags 0 /* offsetof(struct pcmcia_device_id, match_flags) # */
26026 +#define OFF_pcmcia_device_id_manf_id 2 /* offsetof(struct pcmcia_device_id, manf_id) # */
26027 +#define OFF_pcmcia_device_id_card_id 4 /* offsetof(struct pcmcia_device_id, card_id) # */
26028 +#define OFF_pcmcia_device_id_func_id 6 /* offsetof(struct pcmcia_device_id, func_id) # */
26029 +#define OFF_pcmcia_device_id_function 7 /* offsetof(struct pcmcia_device_id, function) # */
26030 +#define OFF_pcmcia_device_id_device_no 8 /* offsetof(struct pcmcia_device_id, device_no) # */
26031 +#define OFF_pcmcia_device_id_prod_id_hash 12 /* offsetof(struct pcmcia_device_id, prod_id_hash) # */
26032 +#define SIZE_of_device_id 200 /* sizeof(struct of_device_id) # */
26033 +#define OFF_of_device_id_name 0 /* offsetof(struct of_device_id, name) # */
26034 +#define OFF_of_device_id_type 32 /* offsetof(struct of_device_id, type) # */
26035 +#define OFF_of_device_id_compatible 64 /* offsetof(struct of_device_id, compatible) # */
26036 +#define SIZE_vio_device_id 64 /* sizeof(struct vio_device_id) # */
26037 +#define OFF_vio_device_id_type 0 /* offsetof(struct vio_device_id, type) # */
26038 +#define OFF_vio_device_id_compat 32 /* offsetof(struct vio_device_id, compat) # */
26039 +#define SIZE_input_device_id 192 /* sizeof(struct input_device_id) # */
26040 +#define OFF_input_device_id_flags 0 /* offsetof(struct input_device_id, flags) # */
26041 +#define OFF_input_device_id_bustype 8 /* offsetof(struct input_device_id, bustype) # */
26042 +#define OFF_input_device_id_vendor 10 /* offsetof(struct input_device_id, vendor) # */
26043 +#define OFF_input_device_id_product 12 /* offsetof(struct input_device_id, product) # */
26044 +#define OFF_input_device_id_version 14 /* offsetof(struct input_device_id, version) # */
26045 +#define OFF_input_device_id_evbit 16 /* offsetof(struct input_device_id, evbit) # */
26046 +#define OFF_input_device_id_keybit 24 /* offsetof(struct input_device_id, keybit) # */
26047 +#define OFF_input_device_id_relbit 120 /* offsetof(struct input_device_id, relbit) # */
26048 +#define OFF_input_device_id_absbit 128 /* offsetof(struct input_device_id, absbit) # */
26049 +#define OFF_input_device_id_mscbit 136 /* offsetof(struct input_device_id, mscbit) # */
26050 +#define OFF_input_device_id_ledbit 144 /* offsetof(struct input_device_id, ledbit) # */
26051 +#define OFF_input_device_id_sndbit 152 /* offsetof(struct input_device_id, sndbit) # */
26052 +#define OFF_input_device_id_ffbit 160 /* offsetof(struct input_device_id, ffbit) # */
26053 +#define OFF_input_device_id_swbit 176 /* offsetof(struct input_device_id, swbit) # */
26054 +#define SIZE_eisa_device_id 16 /* sizeof(struct eisa_device_id) # */
26055 +#define OFF_eisa_device_id_sig 0 /* offsetof(struct eisa_device_id, sig) # */
26056 +#define SIZE_parisc_device_id 8 /* sizeof(struct parisc_device_id) # */
26057 +#define OFF_parisc_device_id_hw_type 0 /* offsetof(struct parisc_device_id, hw_type) # */
26058 +#define OFF_parisc_device_id_hversion 2 /* offsetof(struct parisc_device_id, hversion) # */
26059 +#define OFF_parisc_device_id_hversion_rev 1 /* offsetof(struct parisc_device_id, hversion_rev) # */
26060 +#define OFF_parisc_device_id_sversion 4 /* offsetof(struct parisc_device_id, sversion) # */
26061 +#define SIZE_sdio_device_id 16 /* sizeof(struct sdio_device_id) # */
26062 +#define OFF_sdio_device_id_class 0 /* offsetof(struct sdio_device_id, class) # */
26063 +#define OFF_sdio_device_id_vendor 2 /* offsetof(struct sdio_device_id, vendor) # */
26064 +#define OFF_sdio_device_id_device 4 /* offsetof(struct sdio_device_id, device) # */
26065 +#define SIZE_ssb_device_id 6 /* sizeof(struct ssb_device_id) # */
26066 +#define OFF_ssb_device_id_vendor 0 /* offsetof(struct ssb_device_id, vendor) # */
26067 +#define OFF_ssb_device_id_coreid 2 /* offsetof(struct ssb_device_id, coreid) # */
26068 +#define OFF_ssb_device_id_revision 4 /* offsetof(struct ssb_device_id, revision) # */
26069 +#define SIZE_bcma_device_id 6 /* sizeof(struct bcma_device_id) # */
26070 +#define OFF_bcma_device_id_manuf 0 /* offsetof(struct bcma_device_id, manuf) # */
26071 +#define OFF_bcma_device_id_id 2 /* offsetof(struct bcma_device_id, id) # */
26072 +#define OFF_bcma_device_id_rev 4 /* offsetof(struct bcma_device_id, rev) # */
26073 +#define OFF_bcma_device_id_class 5 /* offsetof(struct bcma_device_id, class) # */
26074 +#define SIZE_virtio_device_id 8 /* sizeof(struct virtio_device_id) # */
26075 +#define OFF_virtio_device_id_device 0 /* offsetof(struct virtio_device_id, device) # */
26076 +#define OFF_virtio_device_id_vendor 4 /* offsetof(struct virtio_device_id, vendor) # */
26077 +#define SIZE_hv_vmbus_device_id 24 /* sizeof(struct hv_vmbus_device_id) # */
26078 +#define OFF_hv_vmbus_device_id_guid 0 /* offsetof(struct hv_vmbus_device_id, guid) # */
26079 +#define SIZE_i2c_device_id 32 /* sizeof(struct i2c_device_id) # */
26080 +#define OFF_i2c_device_id_name 0 /* offsetof(struct i2c_device_id, name) # */
26081 +#define SIZE_spi_device_id 40 /* sizeof(struct spi_device_id) # */
26082 +#define OFF_spi_device_id_name 0 /* offsetof(struct spi_device_id, name) # */
26083 +#define SIZE_dmi_system_id 344 /* sizeof(struct dmi_system_id) # */
26084 +#define OFF_dmi_system_id_matches 16 /* offsetof(struct dmi_system_id, matches) # */
26085 +#define SIZE_platform_device_id 32 /* sizeof(struct platform_device_id) # */
26086 +#define OFF_platform_device_id_name 0 /* offsetof(struct platform_device_id, name) # */
26087 +#define SIZE_mdio_device_id 8 /* sizeof(struct mdio_device_id) # */
26088 +#define OFF_mdio_device_id_phy_id 0 /* offsetof(struct mdio_device_id, phy_id) # */
26089 +#define OFF_mdio_device_id_phy_id_mask 4 /* offsetof(struct mdio_device_id, phy_id_mask) # */
26090 +#define SIZE_zorro_device_id 16 /* sizeof(struct zorro_device_id) # */
26091 +#define OFF_zorro_device_id_id 0 /* offsetof(struct zorro_device_id, id) # */
26092 +#define SIZE_isapnp_device_id 16 /* sizeof(struct isapnp_device_id) # */
26093 +#define OFF_isapnp_device_id_vendor 4 /* offsetof(struct isapnp_device_id, vendor) # */
26094 +#define OFF_isapnp_device_id_function 6 /* offsetof(struct isapnp_device_id, function) # */
26095 +#define SIZE_ipack_device_id 12 /* sizeof(struct ipack_device_id) # */
26096 +#define OFF_ipack_device_id_format 0 /* offsetof(struct ipack_device_id, format) # */
26097 +#define OFF_ipack_device_id_vendor 4 /* offsetof(struct ipack_device_id, vendor) # */
26098 +#define OFF_ipack_device_id_device 8 /* offsetof(struct ipack_device_id, device) # */
26099 +#define SIZE_amba_id 16 /* sizeof(struct amba_id) # */
26100 +#define OFF_amba_id_id 0 /* offsetof(struct amba_id, id) # */
26101 +#define OFF_amba_id_mask 4 /* offsetof(struct amba_id, mask) # */
26102 +#define SIZE_x86_cpu_id 16 /* sizeof(struct x86_cpu_id) # */
26103 +#define OFF_x86_cpu_id_feature 6 /* offsetof(struct x86_cpu_id, feature) # */
26104 +#define OFF_x86_cpu_id_family 2 /* offsetof(struct x86_cpu_id, family) # */
26105 +#define OFF_x86_cpu_id_model 4 /* offsetof(struct x86_cpu_id, model) # */
26106 +#define OFF_x86_cpu_id_vendor 0 /* offsetof(struct x86_cpu_id, vendor) # */
26109 diff -NurpP --minimal linux-3.9.4/security/commoncap.c linux-3.9.4-vs2.3.6.2/security/commoncap.c
26110 --- linux-3.9.4/security/commoncap.c 2013-05-31 13:45:34.000000000 +0000
26111 +++ linux-3.9.4-vs2.3.6.2/security/commoncap.c 2013-05-31 15:07:02.000000000 +0000
26112 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
26113 int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
26114 int cap, int audit)
26116 + struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
26117 struct user_namespace *ns = targ_ns;
26119 /* See if cred has the capability in the target user namespace
26120 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
26123 /* Do we have the necessary capabilities? */
26124 - if (ns == cred->user_ns)
26125 - return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
26126 + if (ns == cred->user_ns) {
26127 + if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
26128 + cap_raised(cred->cap_effective, cap))
26130 + return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
26133 /* Have we tried all of the parent namespaces? */
26134 if (ns == &init_user_ns)
26135 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
26137 if (!strncmp(name, XATTR_SECURITY_PREFIX,
26138 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26139 - !capable(CAP_SYS_ADMIN))
26140 + !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26144 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
26146 if (!strncmp(name, XATTR_SECURITY_PREFIX,
26147 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
26148 - !capable(CAP_SYS_ADMIN))
26149 + !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
26153 diff -NurpP --minimal linux-3.9.4/security/selinux/hooks.c linux-3.9.4-vs2.3.6.2/security/selinux/hooks.c
26154 --- linux-3.9.4/security/selinux/hooks.c 2013-05-31 13:45:34.000000000 +0000
26155 +++ linux-3.9.4-vs2.3.6.2/security/selinux/hooks.c 2013-05-31 14:47:11.000000000 +0000
26157 #include <linux/dccp.h>
26158 #include <linux/quota.h>
26159 #include <linux/un.h> /* for Unix socket types */
26160 -#include <net/af_unix.h> /* for Unix socket types */
26161 #include <linux/parser.h>
26162 #include <linux/nfs_mount.h>
26163 #include <net/ipv6.h>