1 diff -NurpP --minimal linux-3.13.10/Documentation/vserver/debug.txt linux-3.13.10-vs2.3.6.11/Documentation/vserver/debug.txt
2 --- linux-3.13.10/Documentation/vserver/debug.txt 1970-01-01 00:00:00.000000000 +0000
3 +++ linux-3.13.10-vs2.3.6.11/Documentation/vserver/debug.txt 2014-01-31 20:38:03.000000000 +0000
8 + 2 4 "vx_map_tgid: %p/%llx: %d -> %d"
9 + "vx_rmap_tgid: %p/%llx: %d -> %d"
13 + 0 1 "ALLOC (%p,#%d)%c inode (%d)"
14 + "FREE (%p,#%d)%c inode"
15 + 1 2 "ALLOC (%p,#%d)%c %lld bytes (%d)"
16 + "FREE (%p,#%d)%c %lld bytes"
17 + 2 4 "ADJUST: %lld,%lld on %ld,%ld [mult=%d]"
18 + 3 8 "ext3_has_free_blocks(%p): %lu<%lu+1, %c, %u!=%u r=%d"
19 + "ext3_has_free_blocks(%p): free=%lu, root=%lu"
20 + "rcu_free_dl_info(%p)"
21 + 4 10 "alloc_dl_info(%p,%d) = %p"
22 + "dealloc_dl_info(%p)"
23 + "get_dl_info(%p[#%d.%d])"
24 + "put_dl_info(%p[#%d.%d])"
25 + 5 20 "alloc_dl_info(%p,%d)*"
26 + 6 40 "__hash_dl_info: %p[#%d]"
27 + "__unhash_dl_info: %p[#%d]"
28 + 7 80 "locate_dl_info(%p,#%d) = %p"
32 + 0 1 "destroy_dqhash: %p [#0x%08x] c=%d"
33 + "new_dqhash: %p [#0x%08x]"
34 + "vroot[%d]_clr_dev: dev=%p[%lu,%d:%d]"
35 + "vroot[%d]_get_real_bdev: dev=%p[%lu,%d:%d]"
36 + "vroot[%d]_set_dev: dev=%p[%lu,%d:%d]"
37 + "vroot_get_real_bdev not set"
38 + 1 2 "cow_break_link(»%s«)"
40 + 2 4 "dentry_open(new): %p"
41 + "dentry_open(old): %p"
42 + "lookup_create(new): %p"
44 + "path_lookup(old): %d"
45 + "vfs_create(new): %d"
48 + 3 8 "fput(new_file=%p[#%d])"
49 + "fput(old_file=%p[#%d])"
50 + 4 10 "vx_info_kill(%p[#%d],%d,%d) = %d"
51 + "vx_info_kill(%p[#%d],%d,%d)*"
52 + 5 20 "vs_reboot(%p[#%d],%d)"
53 + 6 40 "dropping task %p[#%u,%u] for %p[#%u,%u]"
57 + 2 4 "nx_addr_conflict(%p,%p) %d.%d,%d.%d"
58 + 3 8 "inet_bind(%p) %d.%d.%d.%d, %d.%d.%d.%d, %d.%d.%d.%d"
59 + "inet_bind(%p)* %p,%p;%lx %d.%d.%d.%d"
60 + 4 10 "ip_route_connect(%p) %p,%p;%lx"
61 + 5 20 "__addr_in_socket(%p,%d.%d.%d.%d) %p:%d.%d.%d.%d %p;%lx"
62 + 6 40 "sk,egf: %p [#%d] (from %d)"
63 + "sk,egn: %p [#%d] (from %d)"
64 + "sk,req: %p [#%d] (from %d)"
65 + "sk: %p [#%d] (from %d)"
66 + "tw: %p [#%d] (from %d)"
67 + 7 80 "__sock_recvmsg: %p[%p,%p,%p;%d]:%d/%d"
68 + "__sock_sendmsg: %p[%p,%p,%p;%d]:%d/%d"
72 + 0 1 "__lookup_nx_info(#%u): %p[#%u]"
73 + "alloc_nx_info(%d) = %p"
74 + "create_nx_info(%d) (dynamic rejected)"
75 + "create_nx_info(%d) = %p (already there)"
76 + "create_nx_info(%d) = %p (new)"
77 + "dealloc_nx_info(%p)"
78 + 1 2 "alloc_nx_info(%d)*"
79 + "create_nx_info(%d)*"
80 + 2 4 "get_nx_info(%p[#%d.%d])"
81 + "put_nx_info(%p[#%d.%d])"
82 + 3 8 "claim_nx_info(%p[#%d.%d.%d]) %p"
83 + "clr_nx_info(%p[#%d.%d])"
84 + "init_nx_info(%p[#%d.%d])"
85 + "release_nx_info(%p[#%d.%d.%d]) %p"
86 + "set_nx_info(%p[#%d.%d])"
87 + 4 10 "__hash_nx_info: %p[#%d]"
88 + "__nx_dynamic_id: [#%d]"
89 + "__unhash_nx_info: %p[#%d.%d.%d]"
90 + 5 20 "moved task %p into nxi:%p[#%d]"
91 + "nx_migrate_task(%p,%p[#%d.%d.%d])"
92 + "task_get_nx_info(%p)"
93 + 6 40 "nx_clear_persistent(%p[#%d])"
97 + 0 1 "quota_sync_dqh(%p,%d) discard inode %p"
98 + 1 2 "quota_sync_dqh(%p,%d)"
99 + "sync_dquots(%p,%d)"
100 + "sync_dquots_dqh(%p,%d)"
101 + 3 8 "do_quotactl(%p,%d,cmd=%d,id=%d,%p)"
105 + 0 1 "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]"
106 + 1 2 "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]"
107 + 4 10 "%s: (%s %s) returned %s with %d"
111 + 7 80 "dx_parse_tag(»%s«): %d:#%d"
112 + "dx_propagate_tag(%p[#%lu.%d]): %d,%d"
116 + 0 1 "__lookup_vx_info(#%u): %p[#%u]"
117 + "alloc_vx_info(%d) = %p"
118 + "alloc_vx_info(%d)*"
119 + "create_vx_info(%d) (dynamic rejected)"
120 + "create_vx_info(%d) = %p (already there)"
121 + "create_vx_info(%d) = %p (new)"
122 + "dealloc_vx_info(%p)"
123 + "loc_vx_info(%d) = %p (found)"
124 + "loc_vx_info(%d) = %p (new)"
125 + "loc_vx_info(%d) = %p (not available)"
126 + 1 2 "create_vx_info(%d)*"
128 + 2 4 "get_vx_info(%p[#%d.%d])"
129 + "put_vx_info(%p[#%d.%d])"
130 + 3 8 "claim_vx_info(%p[#%d.%d.%d]) %p"
131 + "clr_vx_info(%p[#%d.%d])"
132 + "init_vx_info(%p[#%d.%d])"
133 + "release_vx_info(%p[#%d.%d.%d]) %p"
134 + "set_vx_info(%p[#%d.%d])"
135 + 4 10 "__hash_vx_info: %p[#%d]"
136 + "__unhash_vx_info: %p[#%d.%d.%d]"
137 + "__vx_dynamic_id: [#%d]"
138 + 5 20 "enter_vx_info(%p[#%d],%p) %p[#%d,%p]"
139 + "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]"
140 + "moved task %p into vxi:%p[#%d]"
141 + "task_get_vx_info(%p)"
142 + "vx_migrate_task(%p,%p[#%d.%d])"
143 + 6 40 "vx_clear_persistent(%p[#%d])"
144 + "vx_exit_init(%p[#%d],%p[#%d,%d,%d])"
145 + "vx_set_init(%p[#%d],%p[#%d,%d,%d])"
146 + "vx_set_persistent(%p[#%d])"
147 + "vx_set_reaper(%p[#%d],%p[#%d,%d])"
148 + 7 80 "vx_child_reaper(%p[#%u,%u]) = %p[#%u,%u]"
153 + n 2^n "vx_acc_cres[%5d,%s,%2d]: %5d%s"
154 + "vx_cres_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
156 + m 2^m "vx_acc_page[%5d,%s,%2d]: %5d%s"
157 + "vx_acc_pages[%5d,%s,%2d]: %5d += %5d"
158 + "vx_pages_avail[%5d,%s,%2d]: %5ld > %5d + %5d"
159 diff -NurpP --minimal linux-3.13.10/arch/alpha/Kconfig linux-3.13.10-vs2.3.6.11/arch/alpha/Kconfig
160 --- linux-3.13.10/arch/alpha/Kconfig 2014-01-22 20:38:09.000000000 +0000
161 +++ linux-3.13.10-vs2.3.6.11/arch/alpha/Kconfig 2014-01-31 20:38:03.000000000 +0000
162 @@ -735,6 +735,8 @@ config DUMMY_CONSOLE
166 +source "kernel/vserver/Kconfig"
168 source "security/Kconfig"
170 source "crypto/Kconfig"
171 diff -NurpP --minimal linux-3.13.10/arch/alpha/kernel/systbls.S linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/systbls.S
172 --- linux-3.13.10/arch/alpha/kernel/systbls.S 2013-11-25 15:44:11.000000000 +0000
173 +++ linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/systbls.S 2014-01-31 20:38:03.000000000 +0000
174 @@ -446,7 +446,7 @@ sys_call_table:
175 .quad sys_stat64 /* 425 */
178 - .quad sys_ni_syscall /* sys_vserver */
179 + .quad sys_vserver /* sys_vserver */
180 .quad sys_ni_syscall /* sys_mbind */
181 .quad sys_ni_syscall /* sys_get_mempolicy */
182 .quad sys_ni_syscall /* sys_set_mempolicy */
183 diff -NurpP --minimal linux-3.13.10/arch/alpha/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/traps.c
184 --- linux-3.13.10/arch/alpha/kernel/traps.c 2014-01-22 20:38:10.000000000 +0000
185 +++ linux-3.13.10-vs2.3.6.11/arch/alpha/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
186 @@ -175,7 +175,8 @@ die_if_kernel(char * str, struct pt_regs
188 printk("CPU %d ", hard_smp_processor_id());
190 - printk("%s(%d): %s %ld\n", current->comm, task_pid_nr(current), str, err);
191 + printk("%s(%d:#%u): %s %ld\n", current->comm,
192 + task_pid_nr(current), current->xid, str, err);
193 dik_show_regs(regs, r9_15);
194 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
195 dik_show_trace((unsigned long *)(regs+1));
196 diff -NurpP --minimal linux-3.13.10/arch/arm/Kconfig linux-3.13.10-vs2.3.6.11/arch/arm/Kconfig
197 --- linux-3.13.10/arch/arm/Kconfig 2014-04-17 01:12:06.000000000 +0000
198 +++ linux-3.13.10-vs2.3.6.11/arch/arm/Kconfig 2014-04-17 01:17:10.000000000 +0000
199 @@ -2267,6 +2267,8 @@ source "fs/Kconfig"
201 source "arch/arm/Kconfig.debug"
203 +source "kernel/vserver/Kconfig"
205 source "security/Kconfig"
207 source "crypto/Kconfig"
208 diff -NurpP --minimal linux-3.13.10/arch/arm/kernel/calls.S linux-3.13.10-vs2.3.6.11/arch/arm/kernel/calls.S
209 --- linux-3.13.10/arch/arm/kernel/calls.S 2013-05-31 13:44:29.000000000 +0000
210 +++ linux-3.13.10-vs2.3.6.11/arch/arm/kernel/calls.S 2014-01-31 20:38:03.000000000 +0000
212 /* 310 */ CALL(sys_request_key)
214 CALL(ABI(sys_semtimedop, sys_oabi_semtimedop))
215 -/* vserver */ CALL(sys_ni_syscall)
218 /* 315 */ CALL(sys_ioprio_get)
219 CALL(sys_inotify_init)
220 diff -NurpP --minimal linux-3.13.10/arch/arm/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/arm/kernel/traps.c
221 --- linux-3.13.10/arch/arm/kernel/traps.c 2014-01-22 20:38:11.000000000 +0000
222 +++ linux-3.13.10-vs2.3.6.11/arch/arm/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
223 @@ -247,8 +247,8 @@ static int __die(const char *str, int er
227 - printk(KERN_EMERG "Process %.*s (pid: %d, stack limit = 0x%p)\n",
228 - TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), end_of_stack(tsk));
229 + printk(KERN_EMERG "Process %.*s (pid: %d:#%u, stack limit = 0x%p)\n",
230 + TASK_COMM_LEN, tsk->comm, task_pid_nr(tsk), tsk->xid, end_of_stack(tsk));
232 if (!user_mode(regs) || in_interrupt()) {
233 dump_mem(KERN_EMERG, "Stack: ", regs->ARM_sp,
234 diff -NurpP --minimal linux-3.13.10/arch/cris/Kconfig linux-3.13.10-vs2.3.6.11/arch/cris/Kconfig
235 --- linux-3.13.10/arch/cris/Kconfig 2014-01-22 20:38:15.000000000 +0000
236 +++ linux-3.13.10-vs2.3.6.11/arch/cris/Kconfig 2014-01-31 20:38:03.000000000 +0000
237 @@ -561,6 +561,8 @@ source "fs/Kconfig"
239 source "arch/cris/Kconfig.debug"
241 +source "kernel/vserver/Kconfig"
243 source "security/Kconfig"
245 source "crypto/Kconfig"
246 diff -NurpP --minimal linux-3.13.10/arch/ia64/Kconfig linux-3.13.10-vs2.3.6.11/arch/ia64/Kconfig
247 --- linux-3.13.10/arch/ia64/Kconfig 2014-01-22 20:38:16.000000000 +0000
248 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/Kconfig 2014-01-31 20:38:03.000000000 +0000
249 @@ -641,6 +641,8 @@ source "fs/Kconfig"
251 source "arch/ia64/Kconfig.debug"
253 +source "kernel/vserver/Kconfig"
255 source "security/Kconfig"
257 source "crypto/Kconfig"
258 diff -NurpP --minimal linux-3.13.10/arch/ia64/kernel/entry.S linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/entry.S
259 --- linux-3.13.10/arch/ia64/kernel/entry.S 2014-01-22 20:38:16.000000000 +0000
260 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/entry.S 2014-01-31 20:38:03.000000000 +0000
261 @@ -1706,7 +1706,7 @@ sys_call_table:
263 data8 sys_mq_getsetattr
265 - data8 sys_ni_syscall // reserved for vserver
267 data8 sys_waitid // 1270
269 data8 sys_request_key
270 diff -NurpP --minimal linux-3.13.10/arch/ia64/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/ptrace.c
271 --- linux-3.13.10/arch/ia64/kernel/ptrace.c 2013-02-19 13:56:51.000000000 +0000
272 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/ptrace.c 2014-01-31 20:38:03.000000000 +0000
274 #include <linux/regset.h>
275 #include <linux/elf.h>
276 #include <linux/tracehook.h>
277 +#include <linux/vs_base.h>
279 #include <asm/pgtable.h>
280 #include <asm/processor.h>
281 diff -NurpP --minimal linux-3.13.10/arch/ia64/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/traps.c
282 --- linux-3.13.10/arch/ia64/kernel/traps.c 2013-11-25 15:44:20.000000000 +0000
283 +++ linux-3.13.10-vs2.3.6.11/arch/ia64/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
284 @@ -60,8 +60,9 @@ die (const char *str, struct pt_regs *re
287 if (++die.lock_owner_depth < 3) {
288 - printk("%s[%d]: %s %ld [%d]\n",
289 - current->comm, task_pid_nr(current), str, err, ++die_counter);
290 + printk("%s[%d:#%u]: %s %ld [%d]\n",
291 + current->comm, task_pid_nr(current), current->xid,
292 + str, err, ++die_counter);
293 if (notify_die(DIE_OOPS, str, regs, err, 255, SIGSEGV)
296 @@ -324,8 +325,9 @@ handle_fpu_swa (int fp_fault, struct pt_
297 if ((last.count & 15) < 5 && (ia64_fetchadd(1, &last.count, acq) & 15) < 5) {
298 last.time = current_jiffies + 5 * HZ;
300 - "%s(%d): floating-point assist fault at ip %016lx, isr %016lx\n",
301 - current->comm, task_pid_nr(current), regs->cr_iip + ia64_psr(regs)->ri, isr);
302 + "%s(%d:#%u): floating-point assist fault at ip %016lx, isr %016lx\n",
303 + current->comm, task_pid_nr(current), current->xid,
304 + regs->cr_iip + ia64_psr(regs)->ri, isr);
308 diff -NurpP --minimal linux-3.13.10/arch/m32r/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/m32r/kernel/traps.c
309 --- linux-3.13.10/arch/m32r/kernel/traps.c 2013-07-14 17:00:26.000000000 +0000
310 +++ linux-3.13.10-vs2.3.6.11/arch/m32r/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
311 @@ -184,8 +184,9 @@ static void show_registers(struct pt_reg
313 printk("SPI: %08lx\n", sp);
315 - printk("Process %s (pid: %d, process nr: %d, stackpage=%08lx)",
316 - current->comm, task_pid_nr(current), 0xffff & i, 4096+(unsigned long)current);
317 + printk("Process %s (pid: %d:#%u, process nr: %d, stackpage=%08lx)",
318 + current->comm, task_pid_nr(current), current->xid,
319 + 0xffff & i, 4096+(unsigned long)current);
322 * When in-kernel, we also print out the stack and code at the
323 diff -NurpP --minimal linux-3.13.10/arch/m68k/Kconfig linux-3.13.10-vs2.3.6.11/arch/m68k/Kconfig
324 --- linux-3.13.10/arch/m68k/Kconfig 2014-04-17 01:12:07.000000000 +0000
325 +++ linux-3.13.10-vs2.3.6.11/arch/m68k/Kconfig 2014-04-17 01:17:10.000000000 +0000
326 @@ -135,6 +135,8 @@ source "fs/Kconfig"
328 source "arch/m68k/Kconfig.debug"
330 +source "kernel/vserver/Kconfig"
332 source "security/Kconfig"
334 source "crypto/Kconfig"
335 diff -NurpP --minimal linux-3.13.10/arch/mips/Kconfig linux-3.13.10-vs2.3.6.11/arch/mips/Kconfig
336 --- linux-3.13.10/arch/mips/Kconfig 2014-01-22 20:38:16.000000000 +0000
337 +++ linux-3.13.10-vs2.3.6.11/arch/mips/Kconfig 2014-01-31 20:38:03.000000000 +0000
338 @@ -2539,6 +2539,8 @@ source "fs/Kconfig"
340 source "arch/mips/Kconfig.debug"
342 +source "kernel/vserver/Kconfig"
344 source "security/Kconfig"
346 source "crypto/Kconfig"
347 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/arch/mips/kernel/ptrace.c
348 --- linux-3.13.10/arch/mips/kernel/ptrace.c 2014-01-22 20:38:17.000000000 +0000
349 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/ptrace.c 2014-01-31 20:53:13.000000000 +0000
351 #include <linux/audit.h>
352 #include <linux/seccomp.h>
353 #include <linux/ftrace.h>
354 +#include <linux/vs_base.h>
356 #include <asm/byteorder.h>
358 @@ -398,6 +399,9 @@ long arch_ptrace(struct task_struct *chi
359 void __user *datavp = (void __user *) data;
360 unsigned long __user *datalp = (void __user *) data;
362 + if (!vx_check(vx_task_xid(child), VS_WATCH_P | VS_IDENT))
366 /* when I and D space are separate, these will need to be fixed. */
367 case PTRACE_PEEKTEXT: /* read word at location addr. */
368 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/scall32-o32.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall32-o32.S
369 --- linux-3.13.10/arch/mips/kernel/scall32-o32.S 2014-01-22 20:38:17.000000000 +0000
370 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall32-o32.S 2014-01-31 20:48:18.000000000 +0000
371 @@ -491,7 +491,7 @@ EXPORT(sys_call_table)
372 PTR sys_mq_timedreceive
373 PTR sys_mq_notify /* 4275 */
374 PTR sys_mq_getsetattr
375 - PTR sys_ni_syscall /* sys_vserver */
378 PTR sys_ni_syscall /* available, was setaltroot */
379 PTR sys_add_key /* 4280 */
380 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/scall64-64.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-64.S
381 --- linux-3.13.10/arch/mips/kernel/scall64-64.S 2014-01-22 20:38:17.000000000 +0000
382 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-64.S 2014-01-31 20:38:03.000000000 +0000
383 @@ -352,7 +352,7 @@ EXPORT(sys_call_table)
384 PTR sys_mq_timedreceive
386 PTR sys_mq_getsetattr /* 5235 */
387 - PTR sys_ni_syscall /* sys_vserver */
390 PTR sys_ni_syscall /* available, was setaltroot */
392 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/scall64-n32.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-n32.S
393 --- linux-3.13.10/arch/mips/kernel/scall64-n32.S 2014-01-22 20:38:17.000000000 +0000
394 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-n32.S 2014-01-31 20:38:03.000000000 +0000
395 @@ -345,7 +345,7 @@ EXPORT(sysn32_call_table)
396 PTR compat_sys_mq_timedreceive
397 PTR compat_sys_mq_notify
398 PTR compat_sys_mq_getsetattr
399 - PTR sys_ni_syscall /* 6240, sys_vserver */
400 + PTR sys32_vserver /* 6240 */
401 PTR compat_sys_waitid
402 PTR sys_ni_syscall /* available, was setaltroot */
404 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/scall64-o32.S linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-o32.S
405 --- linux-3.13.10/arch/mips/kernel/scall64-o32.S 2014-01-22 20:38:17.000000000 +0000
406 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/scall64-o32.S 2014-01-31 20:38:03.000000000 +0000
407 @@ -469,7 +469,7 @@ EXPORT(sys32_call_table)
408 PTR compat_sys_mq_timedreceive
409 PTR compat_sys_mq_notify /* 4275 */
410 PTR compat_sys_mq_getsetattr
411 - PTR sys_ni_syscall /* sys_vserver */
413 PTR compat_sys_waitid
414 PTR sys_ni_syscall /* available, was setaltroot */
415 PTR sys_add_key /* 4280 */
416 diff -NurpP --minimal linux-3.13.10/arch/mips/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/mips/kernel/traps.c
417 --- linux-3.13.10/arch/mips/kernel/traps.c 2014-01-22 20:38:17.000000000 +0000
418 +++ linux-3.13.10-vs2.3.6.11/arch/mips/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
419 @@ -334,9 +334,10 @@ void show_registers(struct pt_regs *regs
423 - printk("Process %s (pid: %d, threadinfo=%p, task=%p, tls=%0*lx)\n",
424 - current->comm, current->pid, current_thread_info(), current,
425 - field, current_thread_info()->tp_value);
426 + printk("Process %s (pid: %d:#%u, threadinfo=%p, task=%p, tls=%0*lx)\n",
427 + current->comm, task_pid_nr(current), current->xid,
428 + current_thread_info(), current,
429 + field, current_thread_info()->tp_value);
430 if (cpu_has_userlocal) {
433 diff -NurpP --minimal linux-3.13.10/arch/parisc/Kconfig linux-3.13.10-vs2.3.6.11/arch/parisc/Kconfig
434 --- linux-3.13.10/arch/parisc/Kconfig 2014-01-22 20:38:18.000000000 +0000
435 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/Kconfig 2014-01-31 20:38:03.000000000 +0000
436 @@ -320,6 +320,8 @@ source "fs/Kconfig"
438 source "arch/parisc/Kconfig.debug"
440 +source "kernel/vserver/Kconfig"
442 source "security/Kconfig"
444 source "crypto/Kconfig"
445 diff -NurpP --minimal linux-3.13.10/arch/parisc/kernel/syscall_table.S linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/syscall_table.S
446 --- linux-3.13.10/arch/parisc/kernel/syscall_table.S 2013-07-14 17:00:31.000000000 +0000
447 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/syscall_table.S 2014-01-31 20:38:03.000000000 +0000
449 ENTRY_COMP(mbind) /* 260 */
450 ENTRY_COMP(get_mempolicy)
451 ENTRY_COMP(set_mempolicy)
452 - ENTRY_SAME(ni_syscall) /* 263: reserved for vserver */
453 + ENTRY_DIFF(vserver)
455 ENTRY_SAME(request_key) /* 265 */
457 diff -NurpP --minimal linux-3.13.10/arch/parisc/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/traps.c
458 --- linux-3.13.10/arch/parisc/kernel/traps.c 2013-11-25 15:46:28.000000000 +0000
459 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
460 @@ -229,8 +229,9 @@ void die_if_kernel(char *str, struct pt_
464 - printk(KERN_CRIT "%s (pid %d): %s (code %ld) at " RFMT "\n",
465 - current->comm, task_pid_nr(current), str, err, regs->iaoq[0]);
466 + printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld) at " RFMT "\n",
467 + current->comm, task_pid_nr(current), current->xid,
468 + str, err, regs->iaoq[0]);
469 #ifdef PRINT_USER_FAULTS
470 /* XXX for debugging only */
472 @@ -263,8 +264,8 @@ void die_if_kernel(char *str, struct pt_
473 pdc_console_restart();
476 - printk(KERN_CRIT "%s (pid %d): %s (code %ld)\n",
477 - current->comm, task_pid_nr(current), str, err);
478 + printk(KERN_CRIT "%s (pid %d:#%u): %s (code %ld)\n",
479 + current->comm, task_pid_nr(current), current->xid, str, err);
481 /* Wot's wrong wif bein' racy? */
482 if (current->thread.flags & PARISC_KERNEL_DEATH) {
483 diff -NurpP --minimal linux-3.13.10/arch/parisc/mm/fault.c linux-3.13.10-vs2.3.6.11/arch/parisc/mm/fault.c
484 --- linux-3.13.10/arch/parisc/mm/fault.c 2014-01-22 20:38:18.000000000 +0000
485 +++ linux-3.13.10-vs2.3.6.11/arch/parisc/mm/fault.c 2014-01-31 20:38:03.000000000 +0000
486 @@ -272,8 +272,9 @@ bad_area:
488 #ifdef PRINT_USER_FAULTS
489 printk(KERN_DEBUG "\n");
490 - printk(KERN_DEBUG "do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
491 - task_pid_nr(tsk), tsk->comm, code, address);
492 + printk(KERN_DEBUG "do_page_fault() pid=%d:#%u "
493 + "command='%s' type=%lu address=0x%08lx\n",
494 + task_pid_nr(tsk), tsk->xid, tsk->comm, code, address);
496 printk(KERN_DEBUG "vm_start = 0x%08lx, vm_end = 0x%08lx\n",
497 vma->vm_start, vma->vm_end);
498 diff -NurpP --minimal linux-3.13.10/arch/powerpc/Kconfig linux-3.13.10-vs2.3.6.11/arch/powerpc/Kconfig
499 --- linux-3.13.10/arch/powerpc/Kconfig 2014-01-22 20:38:18.000000000 +0000
500 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/Kconfig 2014-01-31 20:38:03.000000000 +0000
501 @@ -1028,6 +1028,8 @@ source "lib/Kconfig"
503 source "arch/powerpc/Kconfig.debug"
505 +source "kernel/vserver/Kconfig"
507 source "security/Kconfig"
510 diff -NurpP --minimal linux-3.13.10/arch/powerpc/include/uapi/asm/unistd.h linux-3.13.10-vs2.3.6.11/arch/powerpc/include/uapi/asm/unistd.h
511 --- linux-3.13.10/arch/powerpc/include/uapi/asm/unistd.h 2013-05-31 13:44:44.000000000 +0000
512 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/include/uapi/asm/unistd.h 2014-01-31 20:38:03.000000000 +0000
515 #define __NR_rtas 255
516 #define __NR_sys_debug_setcontext 256
517 -/* Number 257 is reserved for vserver */
518 +#define __NR_vserver 257
519 #define __NR_migrate_pages 258
520 #define __NR_mbind 259
521 #define __NR_get_mempolicy 260
522 diff -NurpP --minimal linux-3.13.10/arch/powerpc/kernel/traps.c linux-3.13.10-vs2.3.6.11/arch/powerpc/kernel/traps.c
523 --- linux-3.13.10/arch/powerpc/kernel/traps.c 2014-01-22 20:38:23.000000000 +0000
524 +++ linux-3.13.10-vs2.3.6.11/arch/powerpc/kernel/traps.c 2014-01-31 20:38:03.000000000 +0000
525 @@ -1272,8 +1272,9 @@ void nonrecoverable_exception(struct pt_
527 void trace_syscall(struct pt_regs *regs)
529 - printk("Task: %p(%d), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
530 - current, task_pid_nr(current), regs->nip, regs->link, regs->gpr[0],
531 + printk("Task: %p(%d:#%u), PC: %08lX/%08lX, Syscall: %3ld, Result: %s%ld %s\n",
532 + current, task_pid_nr(current), current->xid,
533 + regs->nip, regs->link, regs->gpr[0],
534 regs->ccr&0x10000000?"Error=":"", regs->gpr[3], print_tainted());
537 diff -NurpP --minimal linux-3.13.10/arch/s390/Kconfig linux-3.13.10-vs2.3.6.11/arch/s390/Kconfig
538 --- linux-3.13.10/arch/s390/Kconfig 2014-04-17 01:12:08.000000000 +0000
539 +++ linux-3.13.10-vs2.3.6.11/arch/s390/Kconfig 2014-04-17 01:17:10.000000000 +0000
540 @@ -650,6 +650,8 @@ source "fs/Kconfig"
542 source "arch/s390/Kconfig.debug"
544 +source "kernel/vserver/Kconfig"
546 source "security/Kconfig"
548 source "crypto/Kconfig"
549 diff -NurpP --minimal linux-3.13.10/arch/s390/include/asm/tlb.h linux-3.13.10-vs2.3.6.11/arch/s390/include/asm/tlb.h
550 --- linux-3.13.10/arch/s390/include/asm/tlb.h 2013-11-25 15:46:29.000000000 +0000
551 +++ linux-3.13.10-vs2.3.6.11/arch/s390/include/asm/tlb.h 2014-01-31 20:38:03.000000000 +0000
553 #include <linux/mm.h>
554 #include <linux/pagemap.h>
555 #include <linux/swap.h>
557 #include <asm/processor.h>
558 #include <asm/pgalloc.h>
559 #include <asm/tlbflush.h>
560 diff -NurpP --minimal linux-3.13.10/arch/s390/include/uapi/asm/unistd.h linux-3.13.10-vs2.3.6.11/arch/s390/include/uapi/asm/unistd.h
561 --- linux-3.13.10/arch/s390/include/uapi/asm/unistd.h 2013-02-19 13:57:16.000000000 +0000
562 +++ linux-3.13.10-vs2.3.6.11/arch/s390/include/uapi/asm/unistd.h 2014-01-31 20:38:03.000000000 +0000
564 #define __NR_clock_gettime (__NR_timer_create+6)
565 #define __NR_clock_getres (__NR_timer_create+7)
566 #define __NR_clock_nanosleep (__NR_timer_create+8)
567 -/* Number 263 is reserved for vserver */
568 +#define __NR_vserver 263
569 #define __NR_statfs64 265
570 #define __NR_fstatfs64 266
571 #define __NR_remap_file_pages 267
572 diff -NurpP --minimal linux-3.13.10/arch/s390/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/arch/s390/kernel/ptrace.c
573 --- linux-3.13.10/arch/s390/kernel/ptrace.c 2014-01-22 20:38:24.000000000 +0000
574 +++ linux-3.13.10-vs2.3.6.11/arch/s390/kernel/ptrace.c 2014-01-31 20:38:03.000000000 +0000
576 #include <linux/tracehook.h>
577 #include <linux/seccomp.h>
578 #include <linux/compat.h>
579 +#include <linux/vs_base.h>
580 #include <trace/syscall.h>
581 #include <asm/segment.h>
582 #include <asm/page.h>
583 diff -NurpP --minimal linux-3.13.10/arch/s390/kernel/syscalls.S linux-3.13.10-vs2.3.6.11/arch/s390/kernel/syscalls.S
584 --- linux-3.13.10/arch/s390/kernel/syscalls.S 2013-07-14 17:00:34.000000000 +0000
585 +++ linux-3.13.10-vs2.3.6.11/arch/s390/kernel/syscalls.S 2014-01-31 20:38:03.000000000 +0000
586 @@ -271,7 +271,7 @@ SYSCALL(sys_clock_settime,sys_clock_sett
587 SYSCALL(sys_clock_gettime,sys_clock_gettime,sys32_clock_gettime_wrapper) /* 260 */
588 SYSCALL(sys_clock_getres,sys_clock_getres,sys32_clock_getres_wrapper)
589 SYSCALL(sys_clock_nanosleep,sys_clock_nanosleep,sys32_clock_nanosleep_wrapper)
590 -NI_SYSCALL /* reserved for vserver */
591 +SYSCALL(sys_vserver,sys_vserver,sys32_vserver)
592 SYSCALL(sys_s390_fadvise64_64,sys_ni_syscall,sys32_fadvise64_64_wrapper)
593 SYSCALL(sys_statfs64,sys_statfs64,compat_sys_statfs64_wrapper)
594 SYSCALL(sys_fstatfs64,sys_fstatfs64,compat_sys_fstatfs64_wrapper)
595 diff -NurpP --minimal linux-3.13.10/arch/sh/Kconfig linux-3.13.10-vs2.3.6.11/arch/sh/Kconfig
596 --- linux-3.13.10/arch/sh/Kconfig 2014-01-22 20:38:24.000000000 +0000
597 +++ linux-3.13.10-vs2.3.6.11/arch/sh/Kconfig 2014-01-31 20:38:03.000000000 +0000
598 @@ -927,6 +927,8 @@ source "fs/Kconfig"
600 source "arch/sh/Kconfig.debug"
602 +source "kernel/vserver/Kconfig"
604 source "security/Kconfig"
606 source "crypto/Kconfig"
607 diff -NurpP --minimal linux-3.13.10/arch/sh/kernel/irq.c linux-3.13.10-vs2.3.6.11/arch/sh/kernel/irq.c
608 --- linux-3.13.10/arch/sh/kernel/irq.c 2014-01-22 20:38:24.000000000 +0000
609 +++ linux-3.13.10-vs2.3.6.11/arch/sh/kernel/irq.c 2014-01-31 20:38:03.000000000 +0000
611 #include <linux/ftrace.h>
612 #include <linux/delay.h>
613 #include <linux/ratelimit.h>
614 +// #include <linux/vs_context.h>
615 #include <asm/processor.h>
616 #include <asm/machvec.h>
617 #include <asm/uaccess.h>
618 diff -NurpP --minimal linux-3.13.10/arch/sparc/Kconfig linux-3.13.10-vs2.3.6.11/arch/sparc/Kconfig
619 --- linux-3.13.10/arch/sparc/Kconfig 2014-01-22 20:38:24.000000000 +0000
620 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/Kconfig 2014-01-31 20:38:03.000000000 +0000
621 @@ -553,6 +553,8 @@ source "fs/Kconfig"
623 source "arch/sparc/Kconfig.debug"
625 +source "kernel/vserver/Kconfig"
627 source "security/Kconfig"
629 source "crypto/Kconfig"
630 diff -NurpP --minimal linux-3.13.10/arch/sparc/include/uapi/asm/unistd.h linux-3.13.10-vs2.3.6.11/arch/sparc/include/uapi/asm/unistd.h
631 --- linux-3.13.10/arch/sparc/include/uapi/asm/unistd.h 2013-02-19 13:57:17.000000000 +0000
632 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/include/uapi/asm/unistd.h 2014-01-31 20:38:03.000000000 +0000
634 #define __NR_timer_getoverrun 264
635 #define __NR_timer_delete 265
636 #define __NR_timer_create 266
637 -/* #define __NR_vserver 267 Reserved for VSERVER */
638 +#define __NR_vserver 267
639 #define __NR_io_setup 268
640 #define __NR_io_destroy 269
641 #define __NR_io_submit 270
642 diff -NurpP --minimal linux-3.13.10/arch/sparc/kernel/systbls_32.S linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_32.S
643 --- linux-3.13.10/arch/sparc/kernel/systbls_32.S 2013-05-31 13:44:48.000000000 +0000
644 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_32.S 2014-01-31 20:38:03.000000000 +0000
645 @@ -70,7 +70,7 @@ sys_call_table:
646 /*250*/ .long sys_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_ni_syscall
647 /*255*/ .long sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
648 /*260*/ .long sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
649 -/*265*/ .long sys_timer_delete, sys_timer_create, sys_nis_syscall, sys_io_setup, sys_io_destroy
650 +/*265*/ .long sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
651 /*270*/ .long sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
652 /*275*/ .long sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
653 /*280*/ .long sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
654 diff -NurpP --minimal linux-3.13.10/arch/sparc/kernel/systbls_64.S linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_64.S
655 --- linux-3.13.10/arch/sparc/kernel/systbls_64.S 2013-07-14 17:00:35.000000000 +0000
656 +++ linux-3.13.10-vs2.3.6.11/arch/sparc/kernel/systbls_64.S 2014-01-31 20:38:03.000000000 +0000
657 @@ -71,7 +71,7 @@ sys_call_table32:
658 /*250*/ .word sys_mremap, compat_sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
659 .word sys32_sync_file_range, compat_sys_clock_settime, compat_sys_clock_gettime, compat_sys_clock_getres, sys32_clock_nanosleep
660 /*260*/ .word compat_sys_sched_getaffinity, compat_sys_sched_setaffinity, sys32_timer_settime, compat_sys_timer_gettime, sys_timer_getoverrun
661 - .word sys_timer_delete, compat_sys_timer_create, sys_ni_syscall, compat_sys_io_setup, sys_io_destroy
662 + .word sys_timer_delete, compat_sys_timer_create, sys32_vserver, compat_sys_io_setup, sys_io_destroy
663 /*270*/ .word sys32_io_submit, sys_io_cancel, compat_sys_io_getevents, sys32_mq_open, sys_mq_unlink
664 .word compat_sys_mq_timedsend, compat_sys_mq_timedreceive, compat_sys_mq_notify, compat_sys_mq_getsetattr, compat_sys_waitid
665 /*280*/ .word sys_tee, sys_add_key, sys_request_key, compat_sys_keyctl, compat_sys_openat
666 @@ -149,7 +149,7 @@ sys_call_table:
667 /*250*/ .word sys_64_mremap, sys_sysctl, sys_getsid, sys_fdatasync, sys_nis_syscall
668 .word sys_sync_file_range, sys_clock_settime, sys_clock_gettime, sys_clock_getres, sys_clock_nanosleep
669 /*260*/ .word sys_sched_getaffinity, sys_sched_setaffinity, sys_timer_settime, sys_timer_gettime, sys_timer_getoverrun
670 - .word sys_timer_delete, sys_timer_create, sys_ni_syscall, sys_io_setup, sys_io_destroy
671 + .word sys_timer_delete, sys_timer_create, sys_vserver, sys_io_setup, sys_io_destroy
672 /*270*/ .word sys_io_submit, sys_io_cancel, sys_io_getevents, sys_mq_open, sys_mq_unlink
673 .word sys_mq_timedsend, sys_mq_timedreceive, sys_mq_notify, sys_mq_getsetattr, sys_waitid
674 /*280*/ .word sys_tee, sys_add_key, sys_request_key, sys_keyctl, sys_openat
675 diff -NurpP --minimal linux-3.13.10/arch/um/Kconfig.rest linux-3.13.10-vs2.3.6.11/arch/um/Kconfig.rest
676 --- linux-3.13.10/arch/um/Kconfig.rest 2012-12-11 03:30:57.000000000 +0000
677 +++ linux-3.13.10-vs2.3.6.11/arch/um/Kconfig.rest 2014-01-31 20:38:03.000000000 +0000
678 @@ -12,6 +12,8 @@ source "arch/um/Kconfig.net"
682 +source "kernel/vserver/Kconfig"
684 source "security/Kconfig"
686 source "crypto/Kconfig"
687 diff -NurpP --minimal linux-3.13.10/arch/x86/Kconfig linux-3.13.10-vs2.3.6.11/arch/x86/Kconfig
688 --- linux-3.13.10/arch/x86/Kconfig 2014-01-22 20:38:25.000000000 +0000
689 +++ linux-3.13.10-vs2.3.6.11/arch/x86/Kconfig 2014-01-31 20:38:03.000000000 +0000
690 @@ -2403,6 +2403,8 @@ source "fs/Kconfig"
692 source "arch/x86/Kconfig.debug"
694 +source "kernel/vserver/Kconfig"
696 source "security/Kconfig"
698 source "crypto/Kconfig"
699 diff -NurpP --minimal linux-3.13.10/arch/x86/syscalls/syscall_32.tbl linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_32.tbl
700 --- linux-3.13.10/arch/x86/syscalls/syscall_32.tbl 2013-07-14 17:00:37.000000000 +0000
701 +++ linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_32.tbl 2014-01-31 20:38:03.000000000 +0000
703 270 i386 tgkill sys_tgkill
704 271 i386 utimes sys_utimes compat_sys_utimes
705 272 i386 fadvise64_64 sys_fadvise64_64 sys32_fadvise64_64
707 +273 i386 vserver sys_vserver sys32_vserver
708 274 i386 mbind sys_mbind
709 275 i386 get_mempolicy sys_get_mempolicy compat_sys_get_mempolicy
710 276 i386 set_mempolicy sys_set_mempolicy
711 diff -NurpP --minimal linux-3.13.10/arch/x86/syscalls/syscall_64.tbl linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_64.tbl
712 --- linux-3.13.10/arch/x86/syscalls/syscall_64.tbl 2013-05-31 13:44:50.000000000 +0000
713 +++ linux-3.13.10-vs2.3.6.11/arch/x86/syscalls/syscall_64.tbl 2014-01-31 20:38:03.000000000 +0000
715 233 common epoll_ctl sys_epoll_ctl
716 234 common tgkill sys_tgkill
717 235 common utimes sys_utimes
719 +236 64 vserver sys_vserver
720 237 common mbind sys_mbind
721 238 common set_mempolicy sys_set_mempolicy
722 239 common get_mempolicy sys_get_mempolicy
723 diff -NurpP --minimal linux-3.13.10/drivers/block/Kconfig linux-3.13.10-vs2.3.6.11/drivers/block/Kconfig
724 --- linux-3.13.10/drivers/block/Kconfig 2014-01-22 20:38:27.000000000 +0000
725 +++ linux-3.13.10-vs2.3.6.11/drivers/block/Kconfig 2014-01-31 20:38:03.000000000 +0000
726 @@ -281,6 +281,13 @@ config BLK_DEV_CRYPTOLOOP
728 source "drivers/block/drbd/Kconfig"
730 +config BLK_DEV_VROOT
731 + tristate "Virtual Root device support"
732 + depends on QUOTACTL
734 + Saying Y here will allow you to use quota/fs ioctls on a shared
735 + partition within a virtual server without compromising security.
738 tristate "Network block device support"
740 diff -NurpP --minimal linux-3.13.10/drivers/block/Makefile linux-3.13.10-vs2.3.6.11/drivers/block/Makefile
741 --- linux-3.13.10/drivers/block/Makefile 2014-01-22 20:38:27.000000000 +0000
742 +++ linux-3.13.10-vs2.3.6.11/drivers/block/Makefile 2014-01-31 20:38:03.000000000 +0000
743 @@ -34,6 +34,7 @@ obj-$(CONFIG_VIRTIO_BLK) += virtio_blk.o
744 obj-$(CONFIG_VIODASD) += viodasd.o
745 obj-$(CONFIG_BLK_DEV_SX8) += sx8.o
746 obj-$(CONFIG_BLK_DEV_HD) += hd.o
747 +obj-$(CONFIG_BLK_DEV_VROOT) += vroot.o
749 obj-$(CONFIG_XEN_BLKDEV_FRONTEND) += xen-blkfront.o
750 obj-$(CONFIG_XEN_BLKDEV_BACKEND) += xen-blkback/
751 diff -NurpP --minimal linux-3.13.10/drivers/block/loop.c linux-3.13.10-vs2.3.6.11/drivers/block/loop.c
752 --- linux-3.13.10/drivers/block/loop.c 2014-01-22 20:38:27.000000000 +0000
753 +++ linux-3.13.10-vs2.3.6.11/drivers/block/loop.c 2014-01-31 20:55:14.000000000 +0000
755 #include <linux/sysfs.h>
756 #include <linux/miscdevice.h>
757 #include <linux/falloc.h>
758 +#include <linux/vs_context.h>
761 #include <asm/uaccess.h>
762 @@ -884,6 +885,7 @@ static int loop_set_fd(struct loop_devic
763 lo->lo_blocksize = lo_blocksize;
764 lo->lo_device = bdev;
765 lo->lo_flags = lo_flags;
766 + lo->lo_xid = vx_current_xid();
767 lo->lo_backing_file = file;
768 lo->transfer = transfer_none;
770 @@ -1028,6 +1030,7 @@ static int loop_clr_fd(struct loop_devic
771 lo->lo_sizelimit = 0;
772 lo->lo_encrypt_key_size = 0;
773 lo->lo_thread = NULL;
775 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
776 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
777 memset(lo->lo_file_name, 0, LO_NAME_SIZE);
778 @@ -1071,7 +1074,7 @@ loop_set_status(struct loop_device *lo,
780 if (lo->lo_encrypt_key_size &&
781 !uid_eq(lo->lo_key_owner, uid) &&
782 - !capable(CAP_SYS_ADMIN))
783 + !vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP))
785 if (lo->lo_state != Lo_bound)
787 @@ -1161,7 +1164,8 @@ loop_get_status(struct loop_device *lo,
788 memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE);
789 info->lo_encrypt_type =
790 lo->lo_encryption ? lo->lo_encryption->number : 0;
791 - if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) {
792 + if (lo->lo_encrypt_key_size &&
793 + vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_CLOOP)) {
794 info->lo_encrypt_key_size = lo->lo_encrypt_key_size;
795 memcpy(info->lo_encrypt_key, lo->lo_encrypt_key,
796 lo->lo_encrypt_key_size);
797 @@ -1503,6 +1507,11 @@ static int lo_open(struct block_device *
801 + if (!vx_check(lo->lo_xid, VS_IDENT|VS_HOSTID|VS_ADMIN_P)) {
806 mutex_lock(&lo->lo_ctl_mutex);
808 mutex_unlock(&lo->lo_ctl_mutex);
809 diff -NurpP --minimal linux-3.13.10/drivers/block/loop.h linux-3.13.10-vs2.3.6.11/drivers/block/loop.h
810 --- linux-3.13.10/drivers/block/loop.h 2013-11-25 15:44:28.000000000 +0000
811 +++ linux-3.13.10-vs2.3.6.11/drivers/block/loop.h 2014-02-01 01:57:49.000000000 +0000
812 @@ -41,6 +41,7 @@ struct loop_device {
813 struct loop_func_table *lo_encryption;
815 kuid_t lo_key_owner; /* Who set the key */
817 int (*ioctl)(struct loop_device *, int cmd,
820 diff -NurpP --minimal linux-3.13.10/drivers/block/vroot.c linux-3.13.10-vs2.3.6.11/drivers/block/vroot.c
821 --- linux-3.13.10/drivers/block/vroot.c 1970-01-01 00:00:00.000000000 +0000
822 +++ linux-3.13.10-vs2.3.6.11/drivers/block/vroot.c 2014-01-31 20:38:03.000000000 +0000
825 + * linux/drivers/block/vroot.c
827 + * written by Herbert Pötzl, 9/11/2002
828 + * ported to 2.6.10 by Herbert Pötzl, 30/12/2004
830 + * based on the loop.c code by Theodore Ts'o.
832 + * Copyright (C) 2002-2007 by Herbert Pötzl.
833 + * Redistribution of this file is permitted under the
834 + * GNU General Public License.
838 +#include <linux/module.h>
839 +#include <linux/moduleparam.h>
840 +#include <linux/file.h>
841 +#include <linux/major.h>
842 +#include <linux/blkdev.h>
843 +#include <linux/slab.h>
845 +#include <linux/vroot.h>
846 +#include <linux/vs_context.h>
849 +static int max_vroot = 8;
851 +static struct vroot_device *vroot_dev;
852 +static struct gendisk **disks;
855 +static int vroot_set_dev(
856 + struct vroot_device *vr,
857 + struct block_device *bdev,
860 + struct block_device *real_bdev;
862 + struct inode *inode;
866 + if (vr->vr_state != Vr_unbound)
875 + inode = file->f_dentry->d_inode;
878 + if (S_ISBLK(inode->i_mode)) {
879 + real_bdev = inode->i_bdev;
880 + vr->vr_device = real_bdev;
881 + __iget(real_bdev->bd_inode);
885 + vxdprintk(VXD_CBIT(misc, 0),
886 + "vroot[%d]_set_dev: dev=" VXF_DEV,
887 + vr->vr_number, VXD_DEV(real_bdev));
889 + vr->vr_state = Vr_bound;
898 +static int vroot_clr_dev(
899 + struct vroot_device *vr,
900 + struct block_device *bdev)
902 + struct block_device *real_bdev;
904 + if (vr->vr_state != Vr_bound)
906 + if (vr->vr_refcnt > 1) /* we needed one fd for the ioctl */
909 + real_bdev = vr->vr_device;
911 + vxdprintk(VXD_CBIT(misc, 0),
912 + "vroot[%d]_clr_dev: dev=" VXF_DEV,
913 + vr->vr_number, VXD_DEV(real_bdev));
916 + vr->vr_state = Vr_unbound;
917 + vr->vr_device = NULL;
922 +static int vr_ioctl(struct block_device *bdev, fmode_t mode,
923 + unsigned int cmd, unsigned long arg)
925 + struct vroot_device *vr = bdev->bd_disk->private_data;
928 + down(&vr->vr_ctl_mutex);
930 + case VROOT_SET_DEV:
931 + err = vroot_set_dev(vr, bdev, arg);
933 + case VROOT_CLR_DEV:
934 + err = vroot_clr_dev(vr, bdev);
940 + up(&vr->vr_ctl_mutex);
944 +static int vr_open(struct block_device *bdev, fmode_t mode)
946 + struct vroot_device *vr = bdev->bd_disk->private_data;
948 + down(&vr->vr_ctl_mutex);
950 + up(&vr->vr_ctl_mutex);
954 +static void vr_release(struct gendisk *disk, fmode_t mode)
956 + struct vroot_device *vr = disk->private_data;
958 + down(&vr->vr_ctl_mutex);
960 + up(&vr->vr_ctl_mutex);
963 +static struct block_device_operations vr_fops = {
964 + .owner = THIS_MODULE,
966 + .release = vr_release,
970 +static void vroot_make_request(struct request_queue *q, struct bio *bio)
972 + printk("vroot_make_request %p, %p\n", q, bio);
976 +struct block_device *__vroot_get_real_bdev(struct block_device *bdev)
978 + struct inode *inode = bdev->bd_inode;
979 + struct vroot_device *vr;
980 + struct block_device *real_bdev;
981 + int minor = iminor(inode);
983 + vr = &vroot_dev[minor];
984 + real_bdev = vr->vr_device;
986 + vxdprintk(VXD_CBIT(misc, 0),
987 + "vroot[%d]_get_real_bdev: dev=" VXF_DEV,
988 + vr->vr_number, VXD_DEV(real_bdev));
990 + if (vr->vr_state != Vr_bound)
991 + return ERR_PTR(-ENXIO);
993 + __iget(real_bdev->bd_inode);
1000 + * And now the modules code and kernel interface.
1003 +module_param(max_vroot, int, 0);
1005 +MODULE_PARM_DESC(max_vroot, "Maximum number of vroot devices (1-256)");
1006 +MODULE_LICENSE("GPL");
1007 +MODULE_ALIAS_BLOCKDEV_MAJOR(VROOT_MAJOR);
1009 +MODULE_AUTHOR ("Herbert Pötzl");
1010 +MODULE_DESCRIPTION ("Virtual Root Device Mapper");
1013 +int __init vroot_init(void)
1017 + if (max_vroot < 1 || max_vroot > 256) {
1018 + max_vroot = MAX_VROOT_DEFAULT;
1019 + printk(KERN_WARNING "vroot: invalid max_vroot "
1020 + "(must be between 1 and 256), "
1021 + "using default (%d)\n", max_vroot);
1024 + if (register_blkdev(VROOT_MAJOR, "vroot"))
1028 + vroot_dev = kmalloc(max_vroot * sizeof(struct vroot_device), GFP_KERNEL);
1031 + memset(vroot_dev, 0, max_vroot * sizeof(struct vroot_device));
1033 + disks = kmalloc(max_vroot * sizeof(struct gendisk *), GFP_KERNEL);
1037 + for (i = 0; i < max_vroot; i++) {
1038 + disks[i] = alloc_disk(1);
1041 + disks[i]->queue = blk_alloc_queue(GFP_KERNEL);
1042 + if (!disks[i]->queue)
1044 + blk_queue_make_request(disks[i]->queue, vroot_make_request);
1047 + for (i = 0; i < max_vroot; i++) {
1048 + struct vroot_device *vr = &vroot_dev[i];
1049 + struct gendisk *disk = disks[i];
1051 + memset(vr, 0, sizeof(*vr));
1052 + sema_init(&vr->vr_ctl_mutex, 1);
1053 + vr->vr_number = i;
1054 + disk->major = VROOT_MAJOR;
1055 + disk->first_minor = i;
1056 + disk->fops = &vr_fops;
1057 + sprintf(disk->disk_name, "vroot%d", i);
1058 + disk->private_data = vr;
1061 + err = register_vroot_grb(&__vroot_get_real_bdev);
1065 + for (i = 0; i < max_vroot; i++)
1066 + add_disk(disks[i]);
1067 + printk(KERN_INFO "vroot: loaded (max %d devices)\n", max_vroot);
1072 + put_disk(disks[i]);
1077 + unregister_blkdev(VROOT_MAJOR, "vroot");
1078 + printk(KERN_ERR "vroot: ran out of memory\n");
1082 +void vroot_exit(void)
1086 + if (unregister_vroot_grb(&__vroot_get_real_bdev))
1087 + printk(KERN_WARNING "vroot: cannot unregister grb\n");
1089 + for (i = 0; i < max_vroot; i++) {
1090 + del_gendisk(disks[i]);
1091 + put_disk(disks[i]);
1093 + unregister_blkdev(VROOT_MAJOR, "vroot");
1099 +module_init(vroot_init);
1100 +module_exit(vroot_exit);
1104 +static int __init max_vroot_setup(char *str)
1106 + max_vroot = simple_strtol(str, NULL, 0);
1110 +__setup("max_vroot=", max_vroot_setup);
1114 diff -NurpP --minimal linux-3.13.10/drivers/infiniband/core/addr.c linux-3.13.10-vs2.3.6.11/drivers/infiniband/core/addr.c
1115 --- linux-3.13.10/drivers/infiniband/core/addr.c 2013-11-25 15:44:35.000000000 +0000
1116 +++ linux-3.13.10-vs2.3.6.11/drivers/infiniband/core/addr.c 2014-01-31 20:38:03.000000000 +0000
1117 @@ -277,7 +277,7 @@ static int addr6_resolve(struct sockaddr
1119 if (ipv6_addr_any(&fl6.saddr)) {
1120 ret = ipv6_dev_get_saddr(&init_net, ip6_dst_idev(dst)->dev,
1121 - &fl6.daddr, 0, &fl6.saddr);
1122 + &fl6.daddr, 0, &fl6.saddr, NULL);
1126 diff -NurpP --minimal linux-3.13.10/drivers/md/dm-ioctl.c linux-3.13.10-vs2.3.6.11/drivers/md/dm-ioctl.c
1127 --- linux-3.13.10/drivers/md/dm-ioctl.c 2014-01-22 20:38:36.000000000 +0000
1128 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm-ioctl.c 2014-01-31 21:01:49.000000000 +0000
1130 #include <linux/dm-ioctl.h>
1131 #include <linux/hdreg.h>
1132 #include <linux/compat.h>
1133 +#include <linux/vs_context.h>
1135 #include <asm/uaccess.h>
1137 @@ -114,7 +115,8 @@ static struct hash_cell *__get_name_cell
1138 unsigned int h = hash_str(str);
1140 list_for_each_entry (hc, _name_buckets + h, name_list)
1141 - if (!strcmp(hc->name, str)) {
1142 + if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1143 + !strcmp(hc->name, str)) {
1147 @@ -128,7 +130,8 @@ static struct hash_cell *__get_uuid_cell
1148 unsigned int h = hash_str(str);
1150 list_for_each_entry (hc, _uuid_buckets + h, uuid_list)
1151 - if (!strcmp(hc->uuid, str)) {
1152 + if (vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT) &&
1153 + !strcmp(hc->uuid, str)) {
1157 @@ -139,13 +142,15 @@ static struct hash_cell *__get_uuid_cell
1158 static struct hash_cell *__get_dev_cell(uint64_t dev)
1160 struct mapped_device *md;
1161 - struct hash_cell *hc;
1162 + struct hash_cell *hc = NULL;
1164 md = dm_get_md(huge_decode_dev(dev));
1168 - hc = dm_get_mdptr(md);
1169 + if (vx_check(dm_get_xid(md), VS_WATCH_P | VS_IDENT))
1170 + hc = dm_get_mdptr(md);
1175 @@ -467,6 +472,9 @@ typedef int (*ioctl_fn)(struct dm_ioctl
1177 static int remove_all(struct dm_ioctl *param, size_t param_size)
1179 + if (!vx_check(0, VS_ADMIN))
1182 dm_hash_remove_all(true, !!(param->flags & DM_DEFERRED_REMOVE), false);
1183 param->data_size = 0;
1185 @@ -514,6 +522,8 @@ static int list_devices(struct dm_ioctl
1187 for (i = 0; i < NUM_BUCKETS; i++) {
1188 list_for_each_entry (hc, _name_buckets + i, name_list) {
1189 + if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1191 needed += sizeof(struct dm_name_list);
1192 needed += strlen(hc->name) + 1;
1193 needed += ALIGN_MASK;
1194 @@ -537,6 +547,8 @@ static int list_devices(struct dm_ioctl
1196 for (i = 0; i < NUM_BUCKETS; i++) {
1197 list_for_each_entry (hc, _name_buckets + i, name_list) {
1198 + if (!vx_check(dm_get_xid(hc->md), VS_WATCH_P | VS_IDENT))
1201 old_nl->next = (uint32_t) ((void *) nl -
1203 @@ -1797,8 +1809,8 @@ static int ctl_ioctl(uint command, struc
1204 size_t input_param_size;
1205 struct dm_ioctl param_kernel;
1207 - /* only root can play with this */
1208 - if (!capable(CAP_SYS_ADMIN))
1209 + /* only root and certain contexts can play with this */
1210 + if (!vx_capable(CAP_SYS_ADMIN, VXC_ADMIN_MAPPER))
1213 if (_IOC_TYPE(command) != DM_IOCTL)
1214 diff -NurpP --minimal linux-3.13.10/drivers/md/dm.c linux-3.13.10-vs2.3.6.11/drivers/md/dm.c
1215 --- linux-3.13.10/drivers/md/dm.c 2014-04-17 01:12:19.000000000 +0000
1216 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm.c 2014-02-25 11:26:09.000000000 +0000
1218 #include <linux/idr.h>
1219 #include <linux/hdreg.h>
1220 #include <linux/delay.h>
1221 +#include <linux/vs_base.h>
1223 #include <trace/events/block.h>
1225 @@ -139,6 +140,7 @@ struct mapped_device {
1226 struct mutex suspend_lock;
1228 atomic_t open_count;
1232 * The current mapping.
1233 @@ -384,6 +386,7 @@ int dm_deleting_md(struct mapped_device
1234 static int dm_blk_open(struct block_device *bdev, fmode_t mode)
1236 struct mapped_device *md;
1239 spin_lock(&_minor_lock);
1241 @@ -392,18 +395,19 @@ static int dm_blk_open(struct block_devi
1244 if (test_bit(DMF_FREEING, &md->flags) ||
1245 - dm_deleting_md(md)) {
1247 + dm_deleting_md(md))
1251 + if (!vx_check(md->xid, VS_IDENT|VS_HOSTID))
1256 atomic_inc(&md->open_count);
1260 spin_unlock(&_minor_lock);
1262 - return md ? 0 : -ENXIO;
1266 static void dm_blk_close(struct gendisk *disk, fmode_t mode)
1267 @@ -687,6 +691,14 @@ int dm_set_geometry(struct mapped_device
1272 + * Get the xid associated with a dm device
1274 +vxid_t dm_get_xid(struct mapped_device *md)
1279 /*-----------------------------------------------------------------
1281 * A more elegant soln is in the works that uses the queue
1282 @@ -2026,6 +2038,7 @@ static struct mapped_device *alloc_dev(i
1283 INIT_LIST_HEAD(&md->uevent_list);
1284 spin_lock_init(&md->uevent_lock);
1286 + md->xid = vx_current_xid();
1287 md->queue = blk_alloc_queue(GFP_KERNEL);
1290 diff -NurpP --minimal linux-3.13.10/drivers/md/dm.h linux-3.13.10-vs2.3.6.11/drivers/md/dm.h
1291 --- linux-3.13.10/drivers/md/dm.h 2014-04-17 01:12:19.000000000 +0000
1292 +++ linux-3.13.10-vs2.3.6.11/drivers/md/dm.h 2014-02-25 11:26:09.000000000 +0000
1293 @@ -50,6 +50,8 @@ struct dm_dev_internal {
1295 struct dm_md_mempools;
1297 +vxid_t dm_get_xid(struct mapped_device *md);
1299 /*-----------------------------------------------------------------
1300 * Internal table functions.
1301 *---------------------------------------------------------------*/
1302 diff -NurpP --minimal linux-3.13.10/drivers/net/tun.c linux-3.13.10-vs2.3.6.11/drivers/net/tun.c
1303 --- linux-3.13.10/drivers/net/tun.c 2014-04-17 01:12:21.000000000 +0000
1304 +++ linux-3.13.10-vs2.3.6.11/drivers/net/tun.c 2014-04-17 01:17:10.000000000 +0000
1306 #include <linux/nsproxy.h>
1307 #include <linux/virtio_net.h>
1308 #include <linux/rcupdate.h>
1309 +#include <linux/vs_network.h>
1310 #include <net/net_namespace.h>
1311 #include <net/netns/generic.h>
1312 #include <net/rtnetlink.h>
1313 @@ -168,6 +169,7 @@ struct tun_struct {
1319 struct net_device *dev;
1320 netdev_features_t set_features;
1321 @@ -385,6 +387,7 @@ static inline bool tun_not_capable(struc
1322 return ((uid_valid(tun->owner) && !uid_eq(cred->euid, tun->owner)) ||
1323 (gid_valid(tun->group) && !in_egroup_p(tun->group))) &&
1324 !ns_capable(net->user_ns, CAP_NET_ADMIN);
1325 + /* !cap_raised(current_cap(), CAP_NET_ADMIN) */
1328 static void tun_set_real_num_queues(struct tun_struct *tun)
1329 @@ -1382,6 +1385,7 @@ static void tun_setup(struct net_device
1331 tun->owner = INVALID_UID;
1332 tun->group = INVALID_GID;
1333 + tun->nid = nx_current_nid();
1335 dev->ethtool_ops = &tun_ethtool_ops;
1336 dev->destructor = tun_free_netdev;
1337 @@ -1598,7 +1602,7 @@ static int tun_set_iff(struct net *net,
1338 int queues = ifr->ifr_flags & IFF_MULTI_QUEUE ?
1341 - if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
1342 + if (!nx_ns_capable(net->user_ns, CAP_NET_ADMIN, NXC_TUN_CREATE))
1344 err = security_tun_dev_create();
1346 @@ -1969,6 +1973,16 @@ static long __tun_chr_ioctl(struct file
1347 from_kgid(&init_user_ns, tun->group));
1351 + if (!capable(CAP_CONTEXT))
1354 + /* Set nid owner of the device */
1355 + tun->nid = (vnid_t) arg;
1357 + tun_debug(KERN_INFO, tun, "nid owner set to %u\n", tun->nid);
1361 /* Only allow setting the type when the interface is down */
1362 if (tun->dev->flags & IFF_UP) {
1363 diff -NurpP --minimal linux-3.13.10/drivers/tty/sysrq.c linux-3.13.10-vs2.3.6.11/drivers/tty/sysrq.c
1364 --- linux-3.13.10/drivers/tty/sysrq.c 2014-01-22 20:39:02.000000000 +0000
1365 +++ linux-3.13.10-vs2.3.6.11/drivers/tty/sysrq.c 2014-01-31 20:55:49.000000000 +0000
1367 #include <linux/jiffies.h>
1368 #include <linux/syscalls.h>
1369 #include <linux/of.h>
1370 +#include <linux/vserver/debug.h>
1372 #include <asm/ptrace.h>
1373 #include <asm/irq_regs.h>
1374 @@ -407,6 +408,21 @@ static struct sysrq_key_op sysrq_unrt_op
1375 .enable_mask = SYSRQ_ENABLE_RTNICE,
1379 +#ifdef CONFIG_VSERVER_DEBUG
1380 +static void sysrq_handle_vxinfo(int key)
1382 + dump_vx_info_inactive((key == 'x') ? 0 : 1);
1385 +static struct sysrq_key_op sysrq_showvxinfo_op = {
1386 + .handler = sysrq_handle_vxinfo,
1387 + .help_msg = "conteXt",
1388 + .action_msg = "Show Context Info",
1389 + .enable_mask = SYSRQ_ENABLE_DUMP,
1393 /* Key Operations table and lock */
1394 static DEFINE_SPINLOCK(sysrq_key_table_lock);
1396 @@ -462,7 +478,11 @@ static struct sysrq_key_op *sysrq_key_ta
1397 &sysrq_showstate_blocked_op, /* w */
1398 /* x: May be registered on ppc/powerpc for xmon */
1399 /* x: May be registered on sparc64 for global PMU dump */
1400 +#ifdef CONFIG_VSERVER_DEBUG
1401 + &sysrq_showvxinfo_op, /* x */
1405 /* y: May be registered on sparc64 for global register dump */
1407 &sysrq_ftrace_dump_op, /* z */
1408 @@ -477,6 +497,8 @@ static int sysrq_key_table_key2index(int
1410 else if ((key >= 'a') && (key <= 'z'))
1411 retval = key + 10 - 'a';
1412 + else if ((key >= 'A') && (key <= 'Z'))
1413 + retval = key + 10 - 'A';
1417 diff -NurpP --minimal linux-3.13.10/drivers/tty/tty_io.c linux-3.13.10-vs2.3.6.11/drivers/tty/tty_io.c
1418 --- linux-3.13.10/drivers/tty/tty_io.c 2014-01-22 20:39:02.000000000 +0000
1419 +++ linux-3.13.10-vs2.3.6.11/drivers/tty/tty_io.c 2014-01-31 20:38:03.000000000 +0000
1422 #include <linux/kmod.h>
1423 #include <linux/nsproxy.h>
1424 +#include <linux/vs_pid.h>
1426 #undef TTY_DEBUG_HANGUP
1428 @@ -2218,7 +2219,8 @@ static int tiocsti(struct tty_struct *tt
1430 struct tty_ldisc *ld;
1432 - if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN))
1433 + if (((current->signal->tty != tty) &&
1434 + !vx_capable(CAP_SYS_ADMIN, VXC_TIOCSTI)))
1436 if (get_user(ch, p))
1438 @@ -2506,6 +2508,7 @@ static int tiocspgrp(struct tty_struct *
1440 if (get_user(pgrp_nr, p))
1442 + pgrp_nr = vx_rmap_pid(pgrp_nr);
1446 diff -NurpP --minimal linux-3.13.10/fs/attr.c linux-3.13.10-vs2.3.6.11/fs/attr.c
1447 --- linux-3.13.10/fs/attr.c 2014-04-17 01:12:31.000000000 +0000
1448 +++ linux-3.13.10-vs2.3.6.11/fs/attr.c 2014-03-12 15:51:07.000000000 +0000
1450 #include <linux/security.h>
1451 #include <linux/evm.h>
1452 #include <linux/ima.h>
1453 +#include <linux/proc_fs.h>
1454 +#include <linux/devpts_fs.h>
1455 +#include <linux/vs_tag.h>
1458 * inode_change_ok - check if attribute changes to an inode are allowed
1459 @@ -77,6 +80,10 @@ int inode_change_ok(const struct inode *
1463 + /* check for inode tag permission */
1464 + if (dx_permission(inode, MAY_WRITE))
1469 EXPORT_SYMBOL(inode_change_ok);
1470 @@ -147,6 +154,8 @@ void setattr_copy(struct inode *inode, c
1471 inode->i_uid = attr->ia_uid;
1472 if (ia_valid & ATTR_GID)
1473 inode->i_gid = attr->ia_gid;
1474 + if ((ia_valid & ATTR_TAG) && IS_TAGGED(inode))
1475 + inode->i_tag = attr->ia_tag;
1476 if (ia_valid & ATTR_ATIME)
1477 inode->i_atime = timespec_trunc(attr->ia_atime,
1478 inode->i_sb->s_time_gran);
1479 @@ -197,7 +206,8 @@ int notify_change(struct dentry * dentry
1481 WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex));
1483 - if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID | ATTR_TIMES_SET)) {
1484 + if (ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID |
1485 + ATTR_TAG | ATTR_TIMES_SET)) {
1486 if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
1489 diff -NurpP --minimal linux-3.13.10/fs/block_dev.c linux-3.13.10-vs2.3.6.11/fs/block_dev.c
1490 --- linux-3.13.10/fs/block_dev.c 2013-11-25 15:46:58.000000000 +0000
1491 +++ linux-3.13.10-vs2.3.6.11/fs/block_dev.c 2014-01-31 20:38:03.000000000 +0000
1493 #include <linux/log2.h>
1494 #include <linux/cleancache.h>
1495 #include <linux/aio.h>
1496 +#include <linux/vs_device.h>
1497 #include <asm/uaccess.h>
1498 #include "internal.h"
1500 @@ -515,6 +516,7 @@ struct block_device *bdget(dev_t dev)
1501 bdev->bd_invalidated = 0;
1502 inode->i_mode = S_IFBLK;
1503 inode->i_rdev = dev;
1504 + inode->i_mdev = dev;
1505 inode->i_bdev = bdev;
1506 inode->i_data.a_ops = &def_blk_aops;
1507 mapping_set_gfp_mask(&inode->i_data, GFP_USER);
1508 @@ -562,6 +564,11 @@ EXPORT_SYMBOL(bdput);
1509 static struct block_device *bd_acquire(struct inode *inode)
1511 struct block_device *bdev;
1514 + if (!vs_map_blkdev(inode->i_rdev, &mdev, DATTR_OPEN))
1516 + inode->i_mdev = mdev;
1518 spin_lock(&bdev_lock);
1519 bdev = inode->i_bdev;
1520 @@ -572,7 +579,7 @@ static struct block_device *bd_acquire(s
1522 spin_unlock(&bdev_lock);
1524 - bdev = bdget(inode->i_rdev);
1525 + bdev = bdget(mdev);
1527 spin_lock(&bdev_lock);
1528 if (!inode->i_bdev) {
1529 diff -NurpP --minimal linux-3.13.10/fs/btrfs/ctree.h linux-3.13.10-vs2.3.6.11/fs/btrfs/ctree.h
1530 --- linux-3.13.10/fs/btrfs/ctree.h 2014-01-22 20:39:05.000000000 +0000
1531 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/ctree.h 2014-01-31 23:58:35.000000000 +0000
1532 @@ -718,11 +718,14 @@ struct btrfs_inode_item {
1533 /* modification sequence number for NFS */
1538 * a little future expansion, for more than this we can
1539 * just grow the inode item and version it
1541 - __le64 reserved[4];
1542 + __le16 reserved16;
1543 + __le32 reserved32;
1544 + __le64 reserved[3];
1545 struct btrfs_timespec atime;
1546 struct btrfs_timespec ctime;
1547 struct btrfs_timespec mtime;
1548 @@ -2000,6 +2003,8 @@ struct btrfs_ioctl_defrag_range_args {
1550 #define BTRFS_DEFAULT_COMMIT_INTERVAL (30)
1552 +#define BTRFS_MOUNT_TAGGED (1 << 24)
1554 #define btrfs_clear_opt(o, opt) ((o) &= ~BTRFS_MOUNT_##opt)
1555 #define btrfs_set_opt(o, opt) ((o) |= BTRFS_MOUNT_##opt)
1556 #define btrfs_raw_test_opt(o, opt) ((o) & BTRFS_MOUNT_##opt)
1557 @@ -2269,6 +2274,7 @@ BTRFS_SETGET_FUNCS(inode_block_group, st
1558 BTRFS_SETGET_FUNCS(inode_nlink, struct btrfs_inode_item, nlink, 32);
1559 BTRFS_SETGET_FUNCS(inode_uid, struct btrfs_inode_item, uid, 32);
1560 BTRFS_SETGET_FUNCS(inode_gid, struct btrfs_inode_item, gid, 32);
1561 +BTRFS_SETGET_FUNCS(inode_tag, struct btrfs_inode_item, tag, 16);
1562 BTRFS_SETGET_FUNCS(inode_mode, struct btrfs_inode_item, mode, 32);
1563 BTRFS_SETGET_FUNCS(inode_rdev, struct btrfs_inode_item, rdev, 64);
1564 BTRFS_SETGET_FUNCS(inode_flags, struct btrfs_inode_item, flags, 64);
1565 @@ -2341,6 +2347,10 @@ BTRFS_SETGET_FUNCS(extent_flags, struct
1567 BTRFS_SETGET_FUNCS(extent_refs_v0, struct btrfs_extent_item_v0, refs, 32);
1569 +#define BTRFS_INODE_IXUNLINK (1 << 24)
1570 +#define BTRFS_INODE_BARRIER (1 << 25)
1571 +#define BTRFS_INODE_COW (1 << 26)
1574 BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8);
1576 @@ -3722,6 +3732,7 @@ long btrfs_ioctl(struct file *file, unsi
1577 void btrfs_update_iflags(struct inode *inode);
1578 void btrfs_inherit_iflags(struct inode *inode, struct inode *dir);
1579 int btrfs_is_empty_uuid(u8 *uuid);
1580 +int btrfs_sync_flags(struct inode *inode, int, int);
1581 int btrfs_defrag_file(struct inode *inode, struct file *file,
1582 struct btrfs_ioctl_defrag_range_args *range,
1583 u64 newer_than, unsigned long max_pages);
1584 diff -NurpP --minimal linux-3.13.10/fs/btrfs/disk-io.c linux-3.13.10-vs2.3.6.11/fs/btrfs/disk-io.c
1585 --- linux-3.13.10/fs/btrfs/disk-io.c 2014-01-22 20:39:05.000000000 +0000
1586 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/disk-io.c 2014-01-31 20:38:03.000000000 +0000
1587 @@ -2388,6 +2388,9 @@ int open_ctree(struct super_block *sb,
1591 + if (btrfs_test_opt(tree_root, TAGGED))
1592 + sb->s_flags |= MS_TAGGED;
1594 features = btrfs_super_incompat_flags(disk_super) &
1595 ~BTRFS_FEATURE_INCOMPAT_SUPP;
1597 diff -NurpP --minimal linux-3.13.10/fs/btrfs/inode.c linux-3.13.10-vs2.3.6.11/fs/btrfs/inode.c
1598 --- linux-3.13.10/fs/btrfs/inode.c 2014-04-17 01:12:31.000000000 +0000
1599 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/inode.c 2014-03-12 15:51:07.000000000 +0000
1601 #include <linux/btrfs.h>
1602 #include <linux/blkdev.h>
1603 #include <linux/posix_acl_xattr.h>
1604 +#include <linux/vs_tag.h>
1606 #include "disk-io.h"
1607 #include "transaction.h"
1608 @@ -3317,6 +3318,9 @@ static void btrfs_read_locked_inode(stru
1609 struct btrfs_key location;
1616 bool filled = false;
1618 @@ -3344,8 +3348,14 @@ static void btrfs_read_locked_inode(stru
1619 struct btrfs_inode_item);
1620 inode->i_mode = btrfs_inode_mode(leaf, inode_item);
1621 set_nlink(inode, btrfs_inode_nlink(leaf, inode_item));
1622 - i_uid_write(inode, btrfs_inode_uid(leaf, inode_item));
1623 - i_gid_write(inode, btrfs_inode_gid(leaf, inode_item));
1625 + kuid = make_kuid(&init_user_ns, btrfs_inode_uid(leaf, inode_item));
1626 + kgid = make_kgid(&init_user_ns, btrfs_inode_gid(leaf, inode_item));
1627 + ktag = make_ktag(&init_user_ns, btrfs_inode_tag(leaf, inode_item));
1629 + inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
1630 + inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
1631 + inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
1632 btrfs_i_size_write(inode, btrfs_inode_size(leaf, inode_item));
1634 tspec = btrfs_inode_atime(inode_item);
1635 @@ -3436,11 +3446,18 @@ static void fill_inode_item(struct btrfs
1636 struct inode *inode)
1638 struct btrfs_map_token token;
1639 + uid_t uid = from_kuid(&init_user_ns,
1640 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
1641 + gid_t gid = from_kgid(&init_user_ns,
1642 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
1644 btrfs_init_map_token(&token);
1646 - btrfs_set_token_inode_uid(leaf, item, i_uid_read(inode), &token);
1647 - btrfs_set_token_inode_gid(leaf, item, i_gid_read(inode), &token);
1648 + btrfs_set_token_inode_uid(leaf, item, uid, &token);
1649 + btrfs_set_token_inode_gid(leaf, item, gid, &token);
1650 +#ifdef CONFIG_TAGGING_INTERN
1651 + btrfs_set_token_inode_tag(leaf, item, i_tag_read(inode), &token);
1653 btrfs_set_token_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size,
1655 btrfs_set_token_inode_mode(leaf, item, inode->i_mode, &token);
1656 @@ -8652,14 +8669,17 @@ static const struct inode_operations btr
1657 .listxattr = btrfs_listxattr,
1658 .removexattr = btrfs_removexattr,
1659 .permission = btrfs_permission,
1660 + .sync_flags = btrfs_sync_flags,
1661 .get_acl = btrfs_get_acl,
1662 .set_acl = btrfs_set_acl,
1663 .update_time = btrfs_update_time,
1666 static const struct inode_operations btrfs_dir_ro_inode_operations = {
1667 .lookup = btrfs_lookup,
1668 .permission = btrfs_permission,
1669 + .sync_flags = btrfs_sync_flags,
1670 .get_acl = btrfs_get_acl,
1671 .set_acl = btrfs_set_acl,
1672 .update_time = btrfs_update_time,
1674 @@ -8727,6 +8747,7 @@ static const struct inode_operations btr
1675 .removexattr = btrfs_removexattr,
1676 .permission = btrfs_permission,
1677 .fiemap = btrfs_fiemap,
1678 + .sync_flags = btrfs_sync_flags,
1679 .get_acl = btrfs_get_acl,
1680 .update_time = btrfs_update_time,
1682 diff -NurpP --minimal linux-3.13.10/fs/btrfs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/btrfs/ioctl.c
1683 --- linux-3.13.10/fs/btrfs/ioctl.c 2014-04-17 01:12:31.000000000 +0000
1684 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/ioctl.c 2014-02-25 11:26:09.000000000 +0000
1685 @@ -78,10 +78,13 @@ static unsigned int btrfs_flags_to_ioctl
1687 unsigned int iflags = 0;
1689 - if (flags & BTRFS_INODE_SYNC)
1690 - iflags |= FS_SYNC_FL;
1691 if (flags & BTRFS_INODE_IMMUTABLE)
1692 iflags |= FS_IMMUTABLE_FL;
1693 + if (flags & BTRFS_INODE_IXUNLINK)
1694 + iflags |= FS_IXUNLINK_FL;
1696 + if (flags & BTRFS_INODE_SYNC)
1697 + iflags |= FS_SYNC_FL;
1698 if (flags & BTRFS_INODE_APPEND)
1699 iflags |= FS_APPEND_FL;
1700 if (flags & BTRFS_INODE_NODUMP)
1701 @@ -98,28 +101,78 @@ static unsigned int btrfs_flags_to_ioctl
1702 else if (flags & BTRFS_INODE_NOCOMPRESS)
1703 iflags |= FS_NOCOMP_FL;
1705 + if (flags & BTRFS_INODE_BARRIER)
1706 + iflags |= FS_BARRIER_FL;
1707 + if (flags & BTRFS_INODE_COW)
1708 + iflags |= FS_COW_FL;
1713 - * Update inode->i_flags based on the btrfs internal flags.
1714 + * Update inode->i_(v)flags based on the btrfs internal flags.
1716 void btrfs_update_iflags(struct inode *inode)
1718 struct btrfs_inode *ip = BTRFS_I(inode);
1720 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
1721 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
1722 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
1724 - if (ip->flags & BTRFS_INODE_SYNC)
1725 - inode->i_flags |= S_SYNC;
1726 if (ip->flags & BTRFS_INODE_IMMUTABLE)
1727 inode->i_flags |= S_IMMUTABLE;
1728 + if (ip->flags & BTRFS_INODE_IXUNLINK)
1729 + inode->i_flags |= S_IXUNLINK;
1731 + if (ip->flags & BTRFS_INODE_SYNC)
1732 + inode->i_flags |= S_SYNC;
1733 if (ip->flags & BTRFS_INODE_APPEND)
1734 inode->i_flags |= S_APPEND;
1735 if (ip->flags & BTRFS_INODE_NOATIME)
1736 inode->i_flags |= S_NOATIME;
1737 if (ip->flags & BTRFS_INODE_DIRSYNC)
1738 inode->i_flags |= S_DIRSYNC;
1740 + inode->i_vflags &= ~(V_BARRIER | V_COW);
1742 + if (ip->flags & BTRFS_INODE_BARRIER)
1743 + inode->i_vflags |= V_BARRIER;
1744 + if (ip->flags & BTRFS_INODE_COW)
1745 + inode->i_vflags |= V_COW;
1749 + * Update btrfs internal flags from inode->i_(v)flags.
1751 +void btrfs_update_flags(struct inode *inode)
1753 + struct btrfs_inode *ip = BTRFS_I(inode);
1755 + unsigned int flags = inode->i_flags;
1756 + unsigned int vflags = inode->i_vflags;
1758 + ip->flags &= ~(BTRFS_INODE_SYNC | BTRFS_INODE_APPEND |
1759 + BTRFS_INODE_IMMUTABLE | BTRFS_INODE_IXUNLINK |
1760 + BTRFS_INODE_NOATIME | BTRFS_INODE_DIRSYNC |
1761 + BTRFS_INODE_BARRIER | BTRFS_INODE_COW);
1763 + if (flags & S_IMMUTABLE)
1764 + ip->flags |= BTRFS_INODE_IMMUTABLE;
1765 + if (flags & S_IXUNLINK)
1766 + ip->flags |= BTRFS_INODE_IXUNLINK;
1768 + if (flags & S_SYNC)
1769 + ip->flags |= BTRFS_INODE_SYNC;
1770 + if (flags & S_APPEND)
1771 + ip->flags |= BTRFS_INODE_APPEND;
1772 + if (flags & S_NOATIME)
1773 + ip->flags |= BTRFS_INODE_NOATIME;
1774 + if (flags & S_DIRSYNC)
1775 + ip->flags |= BTRFS_INODE_DIRSYNC;
1777 + if (vflags & V_BARRIER)
1778 + ip->flags |= BTRFS_INODE_BARRIER;
1779 + if (vflags & V_COW)
1780 + ip->flags |= BTRFS_INODE_COW;
1784 @@ -135,6 +188,7 @@ void btrfs_inherit_iflags(struct inode *
1787 flags = BTRFS_I(dir)->flags;
1788 + flags &= ~BTRFS_INODE_BARRIER;
1790 if (flags & BTRFS_INODE_NOCOMPRESS) {
1791 BTRFS_I(inode)->flags &= ~BTRFS_INODE_COMPRESS;
1792 @@ -153,6 +207,30 @@ void btrfs_inherit_iflags(struct inode *
1793 btrfs_update_iflags(inode);
1796 +int btrfs_sync_flags(struct inode *inode, int flags, int vflags)
1798 + struct btrfs_inode *ip = BTRFS_I(inode);
1799 + struct btrfs_root *root = ip->root;
1800 + struct btrfs_trans_handle *trans;
1803 + trans = btrfs_join_transaction(root);
1806 + inode->i_flags = flags;
1807 + inode->i_vflags = vflags;
1808 + btrfs_update_flags(inode);
1810 + ret = btrfs_update_inode(trans, root, inode);
1813 + btrfs_update_iflags(inode);
1814 + inode->i_ctime = CURRENT_TIME;
1815 + btrfs_end_transaction(trans, root);
1820 static int btrfs_ioctl_getflags(struct file *file, void __user *arg)
1822 struct btrfs_inode *ip = BTRFS_I(file_inode(file));
1823 @@ -215,21 +293,27 @@ static int btrfs_ioctl_setflags(struct f
1825 flags = btrfs_mask_flags(inode->i_mode, flags);
1826 oldflags = btrfs_flags_to_ioctl(ip->flags);
1827 - if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) {
1828 + if ((flags ^ oldflags) & (FS_APPEND_FL |
1829 + FS_IMMUTABLE_FL | FS_IXUNLINK_FL)) {
1830 if (!capable(CAP_LINUX_IMMUTABLE)) {
1836 - if (flags & FS_SYNC_FL)
1837 - ip->flags |= BTRFS_INODE_SYNC;
1839 - ip->flags &= ~BTRFS_INODE_SYNC;
1840 if (flags & FS_IMMUTABLE_FL)
1841 ip->flags |= BTRFS_INODE_IMMUTABLE;
1843 ip->flags &= ~BTRFS_INODE_IMMUTABLE;
1844 + if (flags & FS_IXUNLINK_FL)
1845 + ip->flags |= BTRFS_INODE_IXUNLINK;
1847 + ip->flags &= ~BTRFS_INODE_IXUNLINK;
1849 + if (flags & FS_SYNC_FL)
1850 + ip->flags |= BTRFS_INODE_SYNC;
1852 + ip->flags &= ~BTRFS_INODE_SYNC;
1853 if (flags & FS_APPEND_FL)
1854 ip->flags |= BTRFS_INODE_APPEND;
1856 diff -NurpP --minimal linux-3.13.10/fs/btrfs/super.c linux-3.13.10-vs2.3.6.11/fs/btrfs/super.c
1857 --- linux-3.13.10/fs/btrfs/super.c 2014-01-22 20:39:05.000000000 +0000
1858 +++ linux-3.13.10-vs2.3.6.11/fs/btrfs/super.c 2014-01-31 23:58:08.000000000 +0000
1859 @@ -323,7 +323,7 @@ enum {
1860 Opt_commit_interval, Opt_barrier, Opt_nodefrag, Opt_nodiscard,
1861 Opt_noenospc_debug, Opt_noflushoncommit, Opt_acl, Opt_datacow,
1862 Opt_datasum, Opt_treelog, Opt_noinode_cache,
1864 + Opt_tag, Opt_notag, Opt_tagid, Opt_err,
1867 static match_table_t tokens = {
1868 @@ -365,6 +365,9 @@ static match_table_t tokens = {
1869 {Opt_rescan_uuid_tree, "rescan_uuid_tree"},
1870 {Opt_fatal_errors, "fatal_errors=%s"},
1871 {Opt_commit_interval, "commit=%d"},
1873 + {Opt_notag, "notag"},
1874 + {Opt_tagid, "tagid=%u"},
1878 @@ -674,6 +677,22 @@ int btrfs_parse_options(struct btrfs_roo
1879 info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL;
1882 +#ifndef CONFIG_TAGGING_NONE
1884 + printk(KERN_INFO "btrfs: use tagging\n");
1885 + btrfs_set_opt(info->mount_opt, TAGGED);
1888 + printk(KERN_INFO "btrfs: disabled tagging\n");
1889 + btrfs_clear_opt(info->mount_opt, TAGGED);
1892 +#ifdef CONFIG_PROPAGATE
1895 + btrfs_set_opt(info->mount_opt, TAGGED);
1899 printk(KERN_INFO "btrfs: unrecognized mount option "
1901 @@ -1320,6 +1339,12 @@ static int btrfs_remount(struct super_bl
1902 btrfs_resize_thread_pool(fs_info,
1903 fs_info->thread_pool_size, old_thread_pool_size);
1905 + if (btrfs_test_opt(root, TAGGED) && !(sb->s_flags & MS_TAGGED)) {
1906 + printk("btrfs: %s: tagging not permitted on remount.\n",
1911 if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
1914 diff -NurpP --minimal linux-3.13.10/fs/char_dev.c linux-3.13.10-vs2.3.6.11/fs/char_dev.c
1915 --- linux-3.13.10/fs/char_dev.c 2014-01-22 20:39:05.000000000 +0000
1916 +++ linux-3.13.10-vs2.3.6.11/fs/char_dev.c 2014-01-31 20:38:03.000000000 +0000
1918 #include <linux/mutex.h>
1919 #include <linux/backing-dev.h>
1920 #include <linux/tty.h>
1921 +#include <linux/vs_context.h>
1922 +#include <linux/vs_device.h>
1924 #include "internal.h"
1926 @@ -372,14 +374,21 @@ static int chrdev_open(struct inode *ino
1928 struct cdev *new = NULL;
1932 + if (!vs_map_chrdev(inode->i_rdev, &mdev, DATTR_OPEN))
1934 + inode->i_mdev = mdev;
1936 spin_lock(&cdev_lock);
1939 struct kobject *kobj;
1942 spin_unlock(&cdev_lock);
1943 - kobj = kobj_lookup(cdev_map, inode->i_rdev, &idx);
1945 + kobj = kobj_lookup(cdev_map, mdev, &idx);
1948 new = container_of(kobj, struct cdev, kobj);
1949 diff -NurpP --minimal linux-3.13.10/fs/dcache.c linux-3.13.10-vs2.3.6.11/fs/dcache.c
1950 --- linux-3.13.10/fs/dcache.c 2014-04-17 01:12:32.000000000 +0000
1951 +++ linux-3.13.10-vs2.3.6.11/fs/dcache.c 2014-04-17 01:17:10.000000000 +0000
1953 #include <linux/prefetch.h>
1954 #include <linux/ratelimit.h>
1955 #include <linux/list_lru.h>
1956 +#include <linux/vs_limit.h>
1957 #include "internal.h"
1960 @@ -640,6 +641,8 @@ int d_invalidate(struct dentry * dentry)
1961 spin_lock(&dentry->d_lock);
1964 + vx_dentry_dec(dentry);
1967 * Somebody else still using it?
1969 @@ -669,6 +672,7 @@ EXPORT_SYMBOL(d_invalidate);
1970 static inline void __dget_dlock(struct dentry *dentry)
1972 dentry->d_lockref.count++;
1973 + vx_dentry_inc(dentry);
1976 static inline void __dget(struct dentry *dentry)
1977 @@ -1483,6 +1487,9 @@ struct dentry *__d_alloc(struct super_bl
1978 struct dentry *dentry;
1981 + if (!vx_dentry_avail(1))
1984 dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
1987 @@ -1515,6 +1522,7 @@ struct dentry *__d_alloc(struct super_bl
1989 dentry->d_lockref.count = 1;
1990 dentry->d_flags = 0;
1991 + vx_dentry_inc(dentry);
1992 spin_lock_init(&dentry->d_lock);
1993 seqcount_init(&dentry->d_seq);
1994 dentry->d_inode = NULL;
1995 @@ -2278,6 +2286,7 @@ struct dentry *__d_lookup(const struct d
1998 dentry->d_lockref.count++;
1999 + vx_dentry_inc(dentry);
2001 spin_unlock(&dentry->d_lock);
2003 diff -NurpP --minimal linux-3.13.10/fs/devpts/inode.c linux-3.13.10-vs2.3.6.11/fs/devpts/inode.c
2004 --- linux-3.13.10/fs/devpts/inode.c 2014-01-22 20:39:06.000000000 +0000
2005 +++ linux-3.13.10-vs2.3.6.11/fs/devpts/inode.c 2014-02-01 01:40:53.000000000 +0000
2007 #include <linux/parser.h>
2008 #include <linux/fsnotify.h>
2009 #include <linux/seq_file.h>
2010 +#include <linux/vs_base.h>
2012 #define DEVPTS_DEFAULT_MODE 0600
2015 #define DEVPTS_DEFAULT_PTMX_MODE 0000
2016 #define PTMX_MINOR 2
2018 +static int devpts_permission(struct inode *inode, int mask)
2020 + int ret = -EACCES;
2022 + /* devpts is xid tagged */
2023 + if (vx_check((vxid_t)i_tag_read(inode), VS_WATCH_P | VS_IDENT))
2024 + ret = generic_permission(inode, mask);
2028 +static struct inode_operations devpts_file_inode_operations = {
2029 + .permission = devpts_permission,
2034 * sysctl support for setting limits on the number of Unix98 ptys allocated.
2035 * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
2036 @@ -345,6 +361,34 @@ static int devpts_show_options(struct se
2040 +static int devpts_filter(struct dentry *de)
2044 + /* devpts is xid tagged */
2045 + if (de && de->d_inode)
2046 + xid = (vxid_t)i_tag_read(de->d_inode);
2047 +#ifdef CONFIG_VSERVER_WARN_DEVPTS
2049 + vxwprintk_task(1, "devpts " VS_Q("%.*s") " without inode.",
2050 + de->d_name.len, de->d_name.name);
2052 + return vx_check(xid, VS_WATCH_P | VS_IDENT);
2055 +static int devpts_readdir(struct file * filp, struct dir_context *ctx)
2057 + return dcache_readdir_filter(filp, ctx, devpts_filter);
2060 +static struct file_operations devpts_dir_operations = {
2061 + .open = dcache_dir_open,
2062 + .release = dcache_dir_close,
2063 + .llseek = dcache_dir_lseek,
2064 + .read = generic_read_dir,
2065 + .iterate = devpts_readdir,
2068 static const struct super_operations devpts_sops = {
2069 .statfs = simple_statfs,
2070 .remount_fs = devpts_remount,
2071 @@ -388,8 +432,10 @@ devpts_fill_super(struct super_block *s,
2072 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2073 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO | S_IWUSR;
2074 inode->i_op = &simple_dir_inode_operations;
2075 - inode->i_fop = &simple_dir_operations;
2076 + inode->i_fop = &devpts_dir_operations;
2077 set_nlink(inode, 2);
2078 + /* devpts is xid tagged */
2079 + i_tag_write(inode, (vtag_t)vx_current_xid());
2081 s->s_root = d_make_root(inode);
2083 @@ -593,6 +639,9 @@ struct inode *devpts_pty_new(struct inod
2084 inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
2085 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
2086 init_special_inode(inode, S_IFCHR|opts->mode, device);
2087 + /* devpts is xid tagged */
2088 + i_tag_write(inode, (vtag_t)vx_current_xid());
2089 + inode->i_op = &devpts_file_inode_operations;
2090 inode->i_private = priv;
2092 sprintf(s, "%d", index);
2093 diff -NurpP --minimal linux-3.13.10/fs/ext2/balloc.c linux-3.13.10-vs2.3.6.11/fs/ext2/balloc.c
2094 --- linux-3.13.10/fs/ext2/balloc.c 2013-05-31 13:45:23.000000000 +0000
2095 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/balloc.c 2014-01-31 20:38:03.000000000 +0000
2096 @@ -693,7 +693,6 @@ ext2_try_to_allocate(struct super_block
2098 end = EXT2_BLOCKS_PER_GROUP(sb);
2101 BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb));
2104 diff -NurpP --minimal linux-3.13.10/fs/ext2/ext2.h linux-3.13.10-vs2.3.6.11/fs/ext2/ext2.h
2105 --- linux-3.13.10/fs/ext2/ext2.h 2012-12-11 03:30:57.000000000 +0000
2106 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ext2.h 2014-01-31 20:38:03.000000000 +0000
2107 @@ -244,8 +244,12 @@ struct ext2_group_desc
2108 #define EXT2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
2109 #define EXT2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
2110 #define EXT2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
2111 +#define EXT2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
2112 #define EXT2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
2114 +#define EXT2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
2115 +#define EXT2_COW_FL FS_COW_FL /* Copy on Write marker */
2117 #define EXT2_FL_USER_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
2118 #define EXT2_FL_USER_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
2120 @@ -329,7 +333,8 @@ struct ext2_inode {
2122 __le16 l_i_uid_high; /* these 2 fields */
2123 __le16 l_i_gid_high; /* were reserved2[0] */
2124 - __u32 l_i_reserved2;
2125 + __le16 l_i_tag; /* Context Tag */
2126 + __u16 l_i_reserved2;
2129 __u8 h_i_frag; /* Fragment number */
2130 @@ -357,6 +362,7 @@ struct ext2_inode {
2131 #define i_gid_low i_gid
2132 #define i_uid_high osd2.linux2.l_i_uid_high
2133 #define i_gid_high osd2.linux2.l_i_gid_high
2134 +#define i_raw_tag osd2.linux2.l_i_tag
2135 #define i_reserved2 osd2.linux2.l_i_reserved2
2138 @@ -384,6 +390,7 @@ struct ext2_inode {
2139 #define EXT2_MOUNT_USRQUOTA 0x020000 /* user quota */
2140 #define EXT2_MOUNT_GRPQUOTA 0x040000 /* group quota */
2141 #define EXT2_MOUNT_RESERVATION 0x080000 /* Preallocation */
2142 +#define EXT2_MOUNT_TAGGED (1<<24) /* Enable Context Tags */
2145 #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
2146 @@ -757,6 +764,7 @@ extern void ext2_set_inode_flags(struct
2147 extern void ext2_get_inode_flags(struct ext2_inode_info *);
2148 extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2149 u64 start, u64 len);
2150 +extern int ext2_sync_flags(struct inode *, int, int);
2153 extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
2154 diff -NurpP --minimal linux-3.13.10/fs/ext2/file.c linux-3.13.10-vs2.3.6.11/fs/ext2/file.c
2155 --- linux-3.13.10/fs/ext2/file.c 2012-12-11 03:30:57.000000000 +0000
2156 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/file.c 2014-01-31 20:38:03.000000000 +0000
2157 @@ -104,4 +104,5 @@ const struct inode_operations ext2_file_
2158 .setattr = ext2_setattr,
2159 .get_acl = ext2_get_acl,
2160 .fiemap = ext2_fiemap,
2161 + .sync_flags = ext2_sync_flags,
2163 diff -NurpP --minimal linux-3.13.10/fs/ext2/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext2/ialloc.c
2164 --- linux-3.13.10/fs/ext2/ialloc.c 2013-05-31 13:45:23.000000000 +0000
2165 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ialloc.c 2014-01-31 20:38:03.000000000 +0000
2167 #include <linux/backing-dev.h>
2168 #include <linux/buffer_head.h>
2169 #include <linux/random.h>
2170 +#include <linux/vs_tag.h>
2174 @@ -546,6 +547,7 @@ got:
2175 inode->i_mode = mode;
2176 inode->i_uid = current_fsuid();
2177 inode->i_gid = dir->i_gid;
2178 + i_tag_write(inode, dx_current_fstag(sb));
2180 inode_init_owner(inode, dir, mode);
2182 diff -NurpP --minimal linux-3.13.10/fs/ext2/inode.c linux-3.13.10-vs2.3.6.11/fs/ext2/inode.c
2183 --- linux-3.13.10/fs/ext2/inode.c 2014-01-22 20:39:06.000000000 +0000
2184 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/inode.c 2014-01-31 20:38:03.000000000 +0000
2186 #include <linux/fiemap.h>
2187 #include <linux/namei.h>
2188 #include <linux/aio.h>
2189 +#include <linux/vs_tag.h>
2193 @@ -1182,7 +1183,7 @@ static void ext2_truncate_blocks(struct
2195 if (ext2_inode_is_fast_symlink(inode))
2197 - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
2198 + if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
2200 __ext2_truncate_blocks(inode, offset);
2202 @@ -1273,36 +1274,61 @@ void ext2_set_inode_flags(struct inode *
2204 unsigned int flags = EXT2_I(inode)->i_flags;
2206 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2207 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2208 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2211 + if (flags & EXT2_IMMUTABLE_FL)
2212 + inode->i_flags |= S_IMMUTABLE;
2213 + if (flags & EXT2_IXUNLINK_FL)
2214 + inode->i_flags |= S_IXUNLINK;
2216 if (flags & EXT2_SYNC_FL)
2217 inode->i_flags |= S_SYNC;
2218 if (flags & EXT2_APPEND_FL)
2219 inode->i_flags |= S_APPEND;
2220 - if (flags & EXT2_IMMUTABLE_FL)
2221 - inode->i_flags |= S_IMMUTABLE;
2222 if (flags & EXT2_NOATIME_FL)
2223 inode->i_flags |= S_NOATIME;
2224 if (flags & EXT2_DIRSYNC_FL)
2225 inode->i_flags |= S_DIRSYNC;
2227 + inode->i_vflags &= ~(V_BARRIER | V_COW);
2229 + if (flags & EXT2_BARRIER_FL)
2230 + inode->i_vflags |= V_BARRIER;
2231 + if (flags & EXT2_COW_FL)
2232 + inode->i_vflags |= V_COW;
2235 /* Propagate flags from i_flags to EXT2_I(inode)->i_flags */
2236 void ext2_get_inode_flags(struct ext2_inode_info *ei)
2238 unsigned int flags = ei->vfs_inode.i_flags;
2239 + unsigned int vflags = ei->vfs_inode.i_vflags;
2241 + ei->i_flags &= ~(EXT2_SYNC_FL | EXT2_APPEND_FL |
2242 + EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL |
2243 + EXT2_NOATIME_FL | EXT2_DIRSYNC_FL |
2244 + EXT2_BARRIER_FL | EXT2_COW_FL);
2246 + if (flags & S_IMMUTABLE)
2247 + ei->i_flags |= EXT2_IMMUTABLE_FL;
2248 + if (flags & S_IXUNLINK)
2249 + ei->i_flags |= EXT2_IXUNLINK_FL;
2251 - ei->i_flags &= ~(EXT2_SYNC_FL|EXT2_APPEND_FL|
2252 - EXT2_IMMUTABLE_FL|EXT2_NOATIME_FL|EXT2_DIRSYNC_FL);
2254 ei->i_flags |= EXT2_SYNC_FL;
2255 if (flags & S_APPEND)
2256 ei->i_flags |= EXT2_APPEND_FL;
2257 - if (flags & S_IMMUTABLE)
2258 - ei->i_flags |= EXT2_IMMUTABLE_FL;
2259 if (flags & S_NOATIME)
2260 ei->i_flags |= EXT2_NOATIME_FL;
2261 if (flags & S_DIRSYNC)
2262 ei->i_flags |= EXT2_DIRSYNC_FL;
2264 + if (vflags & V_BARRIER)
2265 + ei->i_flags |= EXT2_BARRIER_FL;
2266 + if (vflags & V_COW)
2267 + ei->i_flags |= EXT2_COW_FL;
2270 struct inode *ext2_iget (struct super_block *sb, unsigned long ino)
2271 @@ -1338,8 +1364,10 @@ struct inode *ext2_iget (struct super_bl
2272 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2273 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2275 - i_uid_write(inode, i_uid);
2276 - i_gid_write(inode, i_gid);
2277 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2278 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2279 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2280 + le16_to_cpu(raw_inode->i_raw_tag)));
2281 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2282 inode->i_size = le32_to_cpu(raw_inode->i_size);
2283 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2284 @@ -1437,8 +1465,10 @@ static int __ext2_write_inode(struct ino
2285 struct ext2_inode_info *ei = EXT2_I(inode);
2286 struct super_block *sb = inode->i_sb;
2287 ino_t ino = inode->i_ino;
2288 - uid_t uid = i_uid_read(inode);
2289 - gid_t gid = i_gid_read(inode);
2290 + uid_t uid = from_kuid(&init_user_ns,
2291 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2292 + gid_t gid = from_kgid(&init_user_ns,
2293 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2294 struct buffer_head * bh;
2295 struct ext2_inode * raw_inode = ext2_get_inode(sb, ino, &bh);
2297 @@ -1474,6 +1504,9 @@ static int __ext2_write_inode(struct ino
2298 raw_inode->i_uid_high = 0;
2299 raw_inode->i_gid_high = 0;
2301 +#ifdef CONFIG_TAGGING_INTERN
2302 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2304 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2305 raw_inode->i_size = cpu_to_le32(inode->i_size);
2306 raw_inode->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
2307 @@ -1554,7 +1587,8 @@ int ext2_setattr(struct dentry *dentry,
2308 if (is_quota_modification(inode, iattr))
2309 dquot_initialize(inode);
2310 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
2311 - (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
2312 + (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
2313 + (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
2314 error = dquot_transfer(inode, iattr);
2317 diff -NurpP --minimal linux-3.13.10/fs/ext2/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext2/ioctl.c
2318 --- linux-3.13.10/fs/ext2/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2319 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/ioctl.c 2014-01-31 20:38:03.000000000 +0000
2321 #include <asm/uaccess.h>
2324 +int ext2_sync_flags(struct inode *inode, int flags, int vflags)
2326 + inode->i_flags = flags;
2327 + inode->i_vflags = vflags;
2328 + ext2_get_inode_flags(EXT2_I(inode));
2329 + inode->i_ctime = CURRENT_TIME_SEC;
2330 + mark_inode_dirty(inode);
2334 long ext2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2336 struct inode *inode = file_inode(filp);
2337 @@ -51,6 +61,11 @@ long ext2_ioctl(struct file *filp, unsig
2339 flags = ext2_mask_flags(inode->i_mode, flags);
2341 + if (IS_BARRIER(inode)) {
2342 + vxwprintk_task(1, "messing with the barrier.");
2346 mutex_lock(&inode->i_mutex);
2347 /* Is it quota file? Do not allow user to mess with it */
2348 if (IS_NOQUOTA(inode)) {
2349 @@ -66,7 +81,9 @@ long ext2_ioctl(struct file *filp, unsig
2351 * This test looks nicer. Thanks to Pauline Middelink
2353 - if ((flags ^ oldflags) & (EXT2_APPEND_FL | EXT2_IMMUTABLE_FL)) {
2354 + if ((oldflags & EXT2_IMMUTABLE_FL) ||
2355 + ((flags ^ oldflags) & (EXT2_APPEND_FL |
2356 + EXT2_IMMUTABLE_FL | EXT2_IXUNLINK_FL))) {
2357 if (!capable(CAP_LINUX_IMMUTABLE)) {
2358 mutex_unlock(&inode->i_mutex);
2360 @@ -74,7 +91,7 @@ long ext2_ioctl(struct file *filp, unsig
2364 - flags = flags & EXT2_FL_USER_MODIFIABLE;
2365 + flags &= EXT2_FL_USER_MODIFIABLE;
2366 flags |= oldflags & ~EXT2_FL_USER_MODIFIABLE;
2367 ei->i_flags = flags;
2369 diff -NurpP --minimal linux-3.13.10/fs/ext2/namei.c linux-3.13.10-vs2.3.6.11/fs/ext2/namei.c
2370 --- linux-3.13.10/fs/ext2/namei.c 2013-11-25 15:45:01.000000000 +0000
2371 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/namei.c 2014-01-31 20:38:03.000000000 +0000
2374 #include <linux/pagemap.h>
2375 #include <linux/quotaops.h>
2376 +#include <linux/vs_tag.h>
2380 @@ -73,6 +74,7 @@ static struct dentry *ext2_lookup(struct
2381 (unsigned long) ino);
2382 return ERR_PTR(-EIO);
2384 + dx_propagate_tag(nd, inode);
2386 return d_splice_alias(inode, dentry);
2388 @@ -432,5 +434,6 @@ const struct inode_operations ext2_speci
2389 .removexattr = generic_removexattr,
2391 .setattr = ext2_setattr,
2392 + .sync_flags = ext2_sync_flags,
2393 .get_acl = ext2_get_acl,
2395 diff -NurpP --minimal linux-3.13.10/fs/ext2/super.c linux-3.13.10-vs2.3.6.11/fs/ext2/super.c
2396 --- linux-3.13.10/fs/ext2/super.c 2014-01-22 20:39:06.000000000 +0000
2397 +++ linux-3.13.10-vs2.3.6.11/fs/ext2/super.c 2014-01-31 20:38:03.000000000 +0000
2398 @@ -395,7 +395,8 @@ enum {
2399 Opt_err_ro, Opt_nouid32, Opt_nocheck, Opt_debug,
2400 Opt_oldalloc, Opt_orlov, Opt_nobh, Opt_user_xattr, Opt_nouser_xattr,
2401 Opt_acl, Opt_noacl, Opt_xip, Opt_ignore, Opt_err, Opt_quota,
2402 - Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation
2403 + Opt_usrquota, Opt_grpquota, Opt_reservation, Opt_noreservation,
2404 + Opt_tag, Opt_notag, Opt_tagid
2407 static const match_table_t tokens = {
2408 @@ -423,6 +424,9 @@ static const match_table_t tokens = {
2410 {Opt_noacl, "noacl"},
2413 + {Opt_notag, "notag"},
2414 + {Opt_tagid, "tagid=%u"},
2415 {Opt_grpquota, "grpquota"},
2416 {Opt_ignore, "noquota"},
2417 {Opt_quota, "quota"},
2418 @@ -506,6 +510,20 @@ static int parse_options(char *options,
2420 set_opt (sbi->s_mount_opt, NO_UID32);
2422 +#ifndef CONFIG_TAGGING_NONE
2424 + set_opt (sbi->s_mount_opt, TAGGED);
2427 + clear_opt (sbi->s_mount_opt, TAGGED);
2430 +#ifdef CONFIG_PROPAGATE
2433 + set_opt (sbi->s_mount_opt, TAGGED);
2437 clear_opt (sbi->s_mount_opt, CHECK);
2439 @@ -864,6 +882,8 @@ static int ext2_fill_super(struct super_
2440 if (!parse_options((char *) data, sb))
2443 + if (EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_TAGGED)
2444 + sb->s_flags |= MS_TAGGED;
2445 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2446 ((EXT2_SB(sb)->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ?
2448 @@ -1269,6 +1289,14 @@ static int ext2_remount (struct super_bl
2453 + if ((sbi->s_mount_opt & EXT2_MOUNT_TAGGED) &&
2454 + !(sb->s_flags & MS_TAGGED)) {
2455 + printk("EXT2-fs: %s: tagging not permitted on remount.\n",
2458 + goto restore_opts;
2461 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2462 ((sbi->s_mount_opt & EXT2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
2463 diff -NurpP --minimal linux-3.13.10/fs/ext3/ext3.h linux-3.13.10-vs2.3.6.11/fs/ext3/ext3.h
2464 --- linux-3.13.10/fs/ext3/ext3.h 2012-12-11 03:30:57.000000000 +0000
2465 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ext3.h 2014-01-31 20:38:03.000000000 +0000
2466 @@ -151,10 +151,14 @@ struct ext3_group_desc
2467 #define EXT3_NOTAIL_FL 0x00008000 /* file tail should not be merged */
2468 #define EXT3_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
2469 #define EXT3_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
2470 +#define EXT3_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
2471 #define EXT3_RESERVED_FL 0x80000000 /* reserved for ext3 lib */
2473 -#define EXT3_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
2474 -#define EXT3_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
2475 +#define EXT3_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2476 +#define EXT3_COW_FL 0x20000000 /* Copy on Write marker */
2478 +#define EXT3_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
2479 +#define EXT3_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
2481 /* Flags that should be inherited by new inodes from their parent. */
2482 #define EXT3_FL_INHERITED (EXT3_SECRM_FL | EXT3_UNRM_FL | EXT3_COMPR_FL |\
2483 @@ -290,7 +294,8 @@ struct ext3_inode {
2485 __le16 l_i_uid_high; /* these 2 fields */
2486 __le16 l_i_gid_high; /* were reserved2[0] */
2487 - __u32 l_i_reserved2;
2488 + __le16 l_i_tag; /* Context Tag */
2489 + __u16 l_i_reserved2;
2492 __u8 h_i_frag; /* Fragment number */
2493 @@ -320,6 +325,7 @@ struct ext3_inode {
2494 #define i_gid_low i_gid
2495 #define i_uid_high osd2.linux2.l_i_uid_high
2496 #define i_gid_high osd2.linux2.l_i_gid_high
2497 +#define i_raw_tag osd2.linux2.l_i_tag
2498 #define i_reserved2 osd2.linux2.l_i_reserved2
2501 @@ -364,6 +370,7 @@ struct ext3_inode {
2502 #define EXT3_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
2503 #define EXT3_MOUNT_DATA_ERR_ABORT 0x400000 /* Abort on file data write
2504 * error in ordered mode */
2505 +#define EXT3_MOUNT_TAGGED (1<<24) /* Enable Context Tags */
2507 /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
2508 #ifndef _LINUX_EXT2_FS_H
2509 @@ -1061,6 +1068,7 @@ extern void ext3_get_inode_flags(struct
2510 extern void ext3_set_aops(struct inode *inode);
2511 extern int ext3_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
2512 u64 start, u64 len);
2513 +extern int ext3_sync_flags(struct inode *, int, int);
2516 extern long ext3_ioctl(struct file *, unsigned int, unsigned long);
2517 diff -NurpP --minimal linux-3.13.10/fs/ext3/file.c linux-3.13.10-vs2.3.6.11/fs/ext3/file.c
2518 --- linux-3.13.10/fs/ext3/file.c 2012-12-11 03:30:57.000000000 +0000
2519 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/file.c 2014-01-31 20:38:03.000000000 +0000
2520 @@ -76,5 +76,6 @@ const struct inode_operations ext3_file_
2522 .get_acl = ext3_get_acl,
2523 .fiemap = ext3_fiemap,
2524 + .sync_flags = ext3_sync_flags,
2527 diff -NurpP --minimal linux-3.13.10/fs/ext3/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext3/ialloc.c
2528 --- linux-3.13.10/fs/ext3/ialloc.c 2012-12-11 03:30:57.000000000 +0000
2529 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ialloc.c 2014-01-31 20:38:03.000000000 +0000
2532 #include <linux/quotaops.h>
2533 #include <linux/random.h>
2534 +#include <linux/vs_tag.h>
2538 @@ -469,6 +470,7 @@ got:
2539 inode->i_mode = mode;
2540 inode->i_uid = current_fsuid();
2541 inode->i_gid = dir->i_gid;
2542 + i_tag_write(inode, dx_current_fstag(sb));
2544 inode_init_owner(inode, dir, mode);
2546 diff -NurpP --minimal linux-3.13.10/fs/ext3/inode.c linux-3.13.10-vs2.3.6.11/fs/ext3/inode.c
2547 --- linux-3.13.10/fs/ext3/inode.c 2013-11-25 15:45:01.000000000 +0000
2548 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/inode.c 2014-01-31 20:38:03.000000000 +0000
2550 #include <linux/mpage.h>
2551 #include <linux/namei.h>
2552 #include <linux/aio.h>
2553 +#include <linux/vs_tag.h>
2558 @@ -2855,36 +2857,60 @@ void ext3_set_inode_flags(struct inode *
2560 unsigned int flags = EXT3_I(inode)->i_flags;
2562 - inode->i_flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
2563 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
2564 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
2566 + if (flags & EXT3_IMMUTABLE_FL)
2567 + inode->i_flags |= S_IMMUTABLE;
2568 + if (flags & EXT3_IXUNLINK_FL)
2569 + inode->i_flags |= S_IXUNLINK;
2571 if (flags & EXT3_SYNC_FL)
2572 inode->i_flags |= S_SYNC;
2573 if (flags & EXT3_APPEND_FL)
2574 inode->i_flags |= S_APPEND;
2575 - if (flags & EXT3_IMMUTABLE_FL)
2576 - inode->i_flags |= S_IMMUTABLE;
2577 if (flags & EXT3_NOATIME_FL)
2578 inode->i_flags |= S_NOATIME;
2579 if (flags & EXT3_DIRSYNC_FL)
2580 inode->i_flags |= S_DIRSYNC;
2582 + inode->i_vflags &= ~(V_BARRIER | V_COW);
2584 + if (flags & EXT3_BARRIER_FL)
2585 + inode->i_vflags |= V_BARRIER;
2586 + if (flags & EXT3_COW_FL)
2587 + inode->i_vflags |= V_COW;
2590 /* Propagate flags from i_flags to EXT3_I(inode)->i_flags */
2591 void ext3_get_inode_flags(struct ext3_inode_info *ei)
2593 unsigned int flags = ei->vfs_inode.i_flags;
2594 + unsigned int vflags = ei->vfs_inode.i_vflags;
2596 + ei->i_flags &= ~(EXT3_SYNC_FL | EXT3_APPEND_FL |
2597 + EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL |
2598 + EXT3_NOATIME_FL | EXT3_DIRSYNC_FL |
2599 + EXT3_BARRIER_FL | EXT3_COW_FL);
2601 + if (flags & S_IMMUTABLE)
2602 + ei->i_flags |= EXT3_IMMUTABLE_FL;
2603 + if (flags & S_IXUNLINK)
2604 + ei->i_flags |= EXT3_IXUNLINK_FL;
2606 - ei->i_flags &= ~(EXT3_SYNC_FL|EXT3_APPEND_FL|
2607 - EXT3_IMMUTABLE_FL|EXT3_NOATIME_FL|EXT3_DIRSYNC_FL);
2609 ei->i_flags |= EXT3_SYNC_FL;
2610 if (flags & S_APPEND)
2611 ei->i_flags |= EXT3_APPEND_FL;
2612 - if (flags & S_IMMUTABLE)
2613 - ei->i_flags |= EXT3_IMMUTABLE_FL;
2614 if (flags & S_NOATIME)
2615 ei->i_flags |= EXT3_NOATIME_FL;
2616 if (flags & S_DIRSYNC)
2617 ei->i_flags |= EXT3_DIRSYNC_FL;
2619 + if (vflags & V_BARRIER)
2620 + ei->i_flags |= EXT3_BARRIER_FL;
2621 + if (vflags & V_COW)
2622 + ei->i_flags |= EXT3_COW_FL;
2625 struct inode *ext3_iget(struct super_block *sb, unsigned long ino)
2626 @@ -2922,8 +2948,10 @@ struct inode *ext3_iget(struct super_blo
2627 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
2628 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
2630 - i_uid_write(inode, i_uid);
2631 - i_gid_write(inode, i_gid);
2632 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
2633 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
2634 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
2635 + le16_to_cpu(raw_inode->i_raw_tag)));
2636 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
2637 inode->i_size = le32_to_cpu(raw_inode->i_size);
2638 inode->i_atime.tv_sec = (signed)le32_to_cpu(raw_inode->i_atime);
2639 @@ -3095,8 +3123,10 @@ again:
2641 ext3_get_inode_flags(ei);
2642 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
2643 - i_uid = i_uid_read(inode);
2644 - i_gid = i_gid_read(inode);
2645 + i_uid = from_kuid(&init_user_ns,
2646 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
2647 + i_gid = from_kgid(&init_user_ns,
2648 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
2649 if(!(test_opt(inode->i_sb, NO_UID32))) {
2650 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
2651 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
2652 @@ -3121,6 +3151,9 @@ again:
2653 raw_inode->i_uid_high = 0;
2654 raw_inode->i_gid_high = 0;
2656 +#ifdef CONFIG_TAGGING_INTERN
2657 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
2659 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
2660 disksize = cpu_to_le32(ei->i_disksize);
2661 if (disksize != raw_inode->i_size) {
2662 @@ -3289,7 +3322,8 @@ int ext3_setattr(struct dentry *dentry,
2663 if (is_quota_modification(inode, attr))
2664 dquot_initialize(inode);
2665 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
2666 - (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
2667 + (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
2668 + (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
2671 /* (user+group)*(old+new) structure, inode write (sb,
2672 @@ -3311,6 +3345,8 @@ int ext3_setattr(struct dentry *dentry,
2673 inode->i_uid = attr->ia_uid;
2674 if (attr->ia_valid & ATTR_GID)
2675 inode->i_gid = attr->ia_gid;
2676 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
2677 + inode->i_tag = attr->ia_tag;
2678 error = ext3_mark_inode_dirty(handle, inode);
2679 ext3_journal_stop(handle);
2681 diff -NurpP --minimal linux-3.13.10/fs/ext3/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext3/ioctl.c
2682 --- linux-3.13.10/fs/ext3/ioctl.c 2013-05-31 13:45:23.000000000 +0000
2683 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/ioctl.c 2014-01-31 20:38:03.000000000 +0000
2685 #include <asm/uaccess.h>
2689 +int ext3_sync_flags(struct inode *inode, int flags, int vflags)
2691 + handle_t *handle = NULL;
2692 + struct ext3_iloc iloc;
2695 + handle = ext3_journal_start(inode, 1);
2696 + if (IS_ERR(handle))
2697 + return PTR_ERR(handle);
2699 + if (IS_SYNC(inode))
2700 + handle->h_sync = 1;
2701 + err = ext3_reserve_inode_write(handle, inode, &iloc);
2705 + inode->i_flags = flags;
2706 + inode->i_vflags = vflags;
2707 + ext3_get_inode_flags(EXT3_I(inode));
2708 + inode->i_ctime = CURRENT_TIME_SEC;
2710 + err = ext3_mark_iloc_dirty(handle, inode, &iloc);
2712 + ext3_journal_stop(handle);
2716 long ext3_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2718 struct inode *inode = file_inode(filp);
2719 @@ -45,6 +73,11 @@ long ext3_ioctl(struct file *filp, unsig
2721 flags = ext3_mask_flags(inode->i_mode, flags);
2723 + if (IS_BARRIER(inode)) {
2724 + vxwprintk_task(1, "messing with the barrier.");
2728 mutex_lock(&inode->i_mutex);
2730 /* Is it quota file? Do not allow user to mess with it */
2731 @@ -63,7 +96,9 @@ long ext3_ioctl(struct file *filp, unsig
2733 * This test looks nicer. Thanks to Pauline Middelink
2735 - if ((flags ^ oldflags) & (EXT3_APPEND_FL | EXT3_IMMUTABLE_FL)) {
2736 + if ((oldflags & EXT3_IMMUTABLE_FL) ||
2737 + ((flags ^ oldflags) & (EXT3_APPEND_FL |
2738 + EXT3_IMMUTABLE_FL | EXT3_IXUNLINK_FL))) {
2739 if (!capable(CAP_LINUX_IMMUTABLE))
2742 @@ -88,7 +123,7 @@ long ext3_ioctl(struct file *filp, unsig
2746 - flags = flags & EXT3_FL_USER_MODIFIABLE;
2747 + flags &= EXT3_FL_USER_MODIFIABLE;
2748 flags |= oldflags & ~EXT3_FL_USER_MODIFIABLE;
2749 ei->i_flags = flags;
2751 diff -NurpP --minimal linux-3.13.10/fs/ext3/namei.c linux-3.13.10-vs2.3.6.11/fs/ext3/namei.c
2752 --- linux-3.13.10/fs/ext3/namei.c 2013-11-25 15:46:59.000000000 +0000
2753 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/namei.c 2014-01-31 20:38:03.000000000 +0000
2757 #include <linux/quotaops.h>
2758 +#include <linux/vs_tag.h>
2763 @@ -915,6 +917,7 @@ restart:
2764 submit_bh(READ | REQ_META | REQ_PRIO,
2767 + dx_propagate_tag(nd, inode);
2770 if ((bh = bh_use[ra_ptr++]) == NULL)
2771 @@ -2568,6 +2571,7 @@ const struct inode_operations ext3_dir_i
2772 .listxattr = ext3_listxattr,
2773 .removexattr = generic_removexattr,
2775 + .sync_flags = ext3_sync_flags,
2776 .get_acl = ext3_get_acl,
2779 diff -NurpP --minimal linux-3.13.10/fs/ext3/super.c linux-3.13.10-vs2.3.6.11/fs/ext3/super.c
2780 --- linux-3.13.10/fs/ext3/super.c 2014-01-22 20:39:06.000000000 +0000
2781 +++ linux-3.13.10-vs2.3.6.11/fs/ext3/super.c 2014-01-31 20:38:03.000000000 +0000
2782 @@ -826,7 +826,8 @@ enum {
2783 Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
2784 Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_jqfmt_vfsv1, Opt_quota,
2785 Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err,
2786 - Opt_resize, Opt_usrquota, Opt_grpquota
2787 + Opt_resize, Opt_usrquota, Opt_grpquota,
2788 + Opt_tag, Opt_notag, Opt_tagid
2791 static const match_table_t tokens = {
2792 @@ -884,6 +885,9 @@ static const match_table_t tokens = {
2793 {Opt_barrier, "barrier"},
2794 {Opt_nobarrier, "nobarrier"},
2795 {Opt_resize, "resize"},
2797 + {Opt_notag, "notag"},
2798 + {Opt_tagid, "tagid=%u"},
2802 @@ -1056,6 +1060,20 @@ static int parse_options (char *options,
2804 set_opt (sbi->s_mount_opt, NO_UID32);
2806 +#ifndef CONFIG_TAGGING_NONE
2808 + set_opt (sbi->s_mount_opt, TAGGED);
2811 + clear_opt (sbi->s_mount_opt, TAGGED);
2814 +#ifdef CONFIG_PROPAGATE
2817 + set_opt (sbi->s_mount_opt, TAGGED);
2821 clear_opt (sbi->s_mount_opt, CHECK);
2823 @@ -1788,6 +1806,9 @@ static int ext3_fill_super (struct super
2827 + if (EXT3_SB(sb)->s_mount_opt & EXT3_MOUNT_TAGGED)
2828 + sb->s_flags |= MS_TAGGED;
2830 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2831 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2833 @@ -2683,6 +2704,14 @@ static int ext3_remount (struct super_bl
2834 if (test_opt(sb, ABORT))
2835 ext3_abort(sb, __func__, "Abort forced by user");
2837 + if ((sbi->s_mount_opt & EXT3_MOUNT_TAGGED) &&
2838 + !(sb->s_flags & MS_TAGGED)) {
2839 + printk("EXT3-fs: %s: tagging not permitted on remount.\n",
2842 + goto restore_opts;
2845 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
2846 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
2848 diff -NurpP --minimal linux-3.13.10/fs/ext4/ext4.h linux-3.13.10-vs2.3.6.11/fs/ext4/ext4.h
2849 --- linux-3.13.10/fs/ext4/ext4.h 2014-04-17 01:12:32.000000000 +0000
2850 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ext4.h 2014-03-12 15:51:07.000000000 +0000
2851 @@ -385,7 +385,10 @@ struct flex_groups {
2852 #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
2853 #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
2854 #define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
2855 +#define EXT4_BARRIER_FL 0x04000000 /* Barrier for chroot() */
2856 +#define EXT4_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
2857 #define EXT4_INLINE_DATA_FL 0x10000000 /* Inode has inline data. */
2858 +#define EXT4_COW_FL 0x20000000 /* Copy on Write marker */
2859 #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
2861 #define EXT4_FL_USER_VISIBLE 0x004BDFFF /* User visible flags */
2862 @@ -670,7 +673,7 @@ struct ext4_inode {
2863 __le16 l_i_uid_high; /* these 2 fields */
2864 __le16 l_i_gid_high; /* were reserved2[0] */
2865 __le16 l_i_checksum_lo;/* crc32c(uuid+inum+inode) LE */
2866 - __le16 l_i_reserved;
2867 + __le16 l_i_tag; /* Context Tag */
2870 __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
2871 @@ -790,6 +793,7 @@ do { \
2872 #define i_gid_low i_gid
2873 #define i_uid_high osd2.linux2.l_i_uid_high
2874 #define i_gid_high osd2.linux2.l_i_gid_high
2875 +#define i_raw_tag osd2.linux2.l_i_tag
2876 #define i_checksum_lo osd2.linux2.l_i_checksum_lo
2878 #elif defined(__GNU__)
2879 @@ -976,6 +980,7 @@ struct ext4_inode_info {
2880 #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
2881 #define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */
2882 #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */
2883 +#define EXT4_MOUNT_TAGGED 0x40000 /* Enable Context Tags */
2884 #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */
2885 #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
2886 #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
2887 @@ -2653,6 +2658,7 @@ extern struct buffer_head *ext4_get_firs
2888 extern int ext4_inline_data_fiemap(struct inode *inode,
2889 struct fiemap_extent_info *fieinfo,
2891 +extern int ext4_sync_flags(struct inode *, int, int);
2892 extern int ext4_try_to_evict_inline_data(handle_t *handle,
2893 struct inode *inode,
2895 diff -NurpP --minimal linux-3.13.10/fs/ext4/file.c linux-3.13.10-vs2.3.6.11/fs/ext4/file.c
2896 --- linux-3.13.10/fs/ext4/file.c 2013-11-25 15:46:59.000000000 +0000
2897 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/file.c 2014-01-31 20:38:03.000000000 +0000
2898 @@ -618,5 +618,6 @@ const struct inode_operations ext4_file_
2899 .removexattr = generic_removexattr,
2900 .get_acl = ext4_get_acl,
2901 .fiemap = ext4_fiemap,
2902 + .sync_flags = ext4_sync_flags,
2905 diff -NurpP --minimal linux-3.13.10/fs/ext4/ialloc.c linux-3.13.10-vs2.3.6.11/fs/ext4/ialloc.c
2906 --- linux-3.13.10/fs/ext4/ialloc.c 2014-01-22 20:39:06.000000000 +0000
2907 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ialloc.c 2014-01-31 20:38:03.000000000 +0000
2909 #include <linux/random.h>
2910 #include <linux/bitops.h>
2911 #include <linux/blkdev.h>
2912 +#include <linux/vs_tag.h>
2913 #include <asm/byteorder.h>
2916 @@ -731,6 +732,7 @@ struct inode *__ext4_new_inode(handle_t
2917 inode->i_mode = mode;
2918 inode->i_uid = current_fsuid();
2919 inode->i_gid = dir->i_gid;
2920 + i_tag_write(inode, dx_current_fstag(sb));
2922 inode_init_owner(inode, dir, mode);
2923 dquot_initialize(inode);
2924 diff -NurpP --minimal linux-3.13.10/fs/ext4/inode.c linux-3.13.10-vs2.3.6.11/fs/ext4/inode.c
2925 --- linux-3.13.10/fs/ext4/inode.c 2014-04-17 01:12:32.000000000 +0000
2926 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/inode.c 2014-04-17 01:28:13.000000000 +0000
2928 #include <linux/ratelimit.h>
2929 #include <linux/aio.h>
2930 #include <linux/bitops.h>
2931 +#include <linux/vs_tag.h>
2933 #include "ext4_jbd2.h"
2935 @@ -3929,42 +3930,67 @@ void ext4_set_inode_flags(struct inode *
2936 unsigned int flags = EXT4_I(inode)->i_flags;
2937 unsigned int new_fl = 0;
2939 + if (flags & EXT4_IMMUTABLE_FL)
2940 + new_fl |= S_IMMUTABLE;
2941 + if (flags & EXT4_IXUNLINK_FL)
2942 + new_fl |= S_IXUNLINK;
2944 if (flags & EXT4_SYNC_FL)
2946 if (flags & EXT4_APPEND_FL)
2948 - if (flags & EXT4_IMMUTABLE_FL)
2949 - new_fl |= S_IMMUTABLE;
2950 if (flags & EXT4_NOATIME_FL)
2951 new_fl |= S_NOATIME;
2952 if (flags & EXT4_DIRSYNC_FL)
2953 new_fl |= S_DIRSYNC;
2955 set_mask_bits(&inode->i_flags,
2956 - S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC, new_fl);
2957 + S_IXUNLINK | S_IMMUTABLE |
2958 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC, new_fl);
2961 + if (flags & EXT4_BARRIER_FL)
2962 + new_fl |= V_BARRIER;
2963 + if (flags & EXT4_COW_FL)
2966 + set_mask_bits(&inode->i_vflags,
2967 + V_BARRIER | V_COW, new_fl);
2970 /* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
2971 void ext4_get_inode_flags(struct ext4_inode_info *ei)
2973 - unsigned int vfs_fl;
2974 + unsigned int vfs_fl, vfs_vf;
2975 unsigned long old_fl, new_fl;
2978 vfs_fl = ei->vfs_inode.i_flags;
2979 + vfs_vf = ei->vfs_inode.i_vflags;
2980 old_fl = ei->i_flags;
2981 new_fl = old_fl & ~(EXT4_SYNC_FL|EXT4_APPEND_FL|
2982 EXT4_IMMUTABLE_FL|EXT4_NOATIME_FL|
2984 + EXT4_DIRSYNC_FL|EXT4_BARRIER_FL|
2987 + if (vfs_fl & S_IMMUTABLE)
2988 + new_fl |= EXT4_IMMUTABLE_FL;
2989 + if (vfs_fl & S_IXUNLINK)
2990 + new_fl |= EXT4_IXUNLINK_FL;
2992 if (vfs_fl & S_SYNC)
2993 new_fl |= EXT4_SYNC_FL;
2994 if (vfs_fl & S_APPEND)
2995 new_fl |= EXT4_APPEND_FL;
2996 - if (vfs_fl & S_IMMUTABLE)
2997 - new_fl |= EXT4_IMMUTABLE_FL;
2998 if (vfs_fl & S_NOATIME)
2999 new_fl |= EXT4_NOATIME_FL;
3000 if (vfs_fl & S_DIRSYNC)
3001 new_fl |= EXT4_DIRSYNC_FL;
3003 + if (vfs_vf & V_BARRIER)
3004 + new_fl |= EXT4_BARRIER_FL;
3005 + if (vfs_vf & V_COW)
3006 + new_fl |= EXT4_COW_FL;
3007 } while (cmpxchg(&ei->i_flags, old_fl, new_fl) != old_fl);
3010 @@ -4069,8 +4095,10 @@ struct inode *ext4_iget(struct super_blo
3011 i_uid |= le16_to_cpu(raw_inode->i_uid_high) << 16;
3012 i_gid |= le16_to_cpu(raw_inode->i_gid_high) << 16;
3014 - i_uid_write(inode, i_uid);
3015 - i_gid_write(inode, i_gid);
3016 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), i_uid, i_gid));
3017 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), i_uid, i_gid));
3018 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), i_uid, i_gid,
3019 + le16_to_cpu(raw_inode->i_raw_tag)));
3020 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count));
3022 ext4_clear_state_flags(ei); /* Only relevant on 32-bit archs */
3023 @@ -4298,8 +4326,10 @@ static int ext4_do_update_inode(handle_t
3025 ext4_get_inode_flags(ei);
3026 raw_inode->i_mode = cpu_to_le16(inode->i_mode);
3027 - i_uid = i_uid_read(inode);
3028 - i_gid = i_gid_read(inode);
3029 + i_uid = from_kuid(&init_user_ns,
3030 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag));
3031 + i_gid = from_kgid(&init_user_ns,
3032 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag));
3033 if (!(test_opt(inode->i_sb, NO_UID32))) {
3034 raw_inode->i_uid_low = cpu_to_le16(low_16_bits(i_uid));
3035 raw_inode->i_gid_low = cpu_to_le16(low_16_bits(i_gid));
3036 @@ -4322,6 +4352,9 @@ static int ext4_do_update_inode(handle_t
3037 raw_inode->i_uid_high = 0;
3038 raw_inode->i_gid_high = 0;
3040 +#ifdef CONFIG_TAGGING_INTERN
3041 + raw_inode->i_raw_tag = cpu_to_le16(i_tag_read(inode));
3043 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink);
3045 EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode);
3046 @@ -4553,7 +4586,8 @@ int ext4_setattr(struct dentry *dentry,
3047 if (is_quota_modification(inode, attr))
3048 dquot_initialize(inode);
3049 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) ||
3050 - (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) {
3051 + (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid)) ||
3052 + (ia_valid & ATTR_TAG && !tag_eq(attr->ia_tag, inode->i_tag))) {
3055 /* (user+group)*(old+new) structure, inode write (sb,
3056 @@ -4576,6 +4610,8 @@ int ext4_setattr(struct dentry *dentry,
3057 inode->i_uid = attr->ia_uid;
3058 if (attr->ia_valid & ATTR_GID)
3059 inode->i_gid = attr->ia_gid;
3060 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
3061 + inode->i_tag = attr->ia_tag;
3062 error = ext4_mark_inode_dirty(handle, inode);
3063 ext4_journal_stop(handle);
3065 diff -NurpP --minimal linux-3.13.10/fs/ext4/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ext4/ioctl.c
3066 --- linux-3.13.10/fs/ext4/ioctl.c 2014-04-17 01:12:32.000000000 +0000
3067 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/ioctl.c 2014-03-12 15:51:07.000000000 +0000
3069 #include <linux/compat.h>
3070 #include <linux/mount.h>
3071 #include <linux/file.h>
3072 +#include <linux/vs_tag.h>
3073 #include <asm/uaccess.h>
3074 #include "ext4_jbd2.h"
3076 @@ -214,6 +215,33 @@ swap_boot_out:
3080 +int ext4_sync_flags(struct inode *inode, int flags, int vflags)
3082 + handle_t *handle = NULL;
3083 + struct ext4_iloc iloc;
3086 + handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
3087 + if (IS_ERR(handle))
3088 + return PTR_ERR(handle);
3090 + if (IS_SYNC(inode))
3091 + ext4_handle_sync(handle);
3092 + err = ext4_reserve_inode_write(handle, inode, &iloc);
3096 + inode->i_flags = flags;
3097 + inode->i_vflags = vflags;
3098 + ext4_get_inode_flags(EXT4_I(inode));
3099 + inode->i_ctime = ext4_current_time(inode);
3101 + err = ext4_mark_iloc_dirty(handle, inode, &iloc);
3103 + ext4_journal_stop(handle);
3107 long ext4_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3109 struct inode *inode = file_inode(filp);
3110 @@ -247,6 +275,11 @@ long ext4_ioctl(struct file *filp, unsig
3112 flags = ext4_mask_flags(inode->i_mode, flags);
3114 + if (IS_BARRIER(inode)) {
3115 + vxwprintk_task(1, "messing with the barrier.");
3120 mutex_lock(&inode->i_mutex);
3121 /* Is it quota file? Do not allow user to mess with it */
3122 @@ -264,7 +297,9 @@ long ext4_ioctl(struct file *filp, unsig
3124 * This test looks nicer. Thanks to Pauline Middelink
3126 - if ((flags ^ oldflags) & (EXT4_APPEND_FL | EXT4_IMMUTABLE_FL)) {
3127 + if ((oldflags & EXT4_IMMUTABLE_FL) ||
3128 + ((flags ^ oldflags) & (EXT4_APPEND_FL |
3129 + EXT4_IMMUTABLE_FL | EXT4_IXUNLINK_FL))) {
3130 if (!capable(CAP_LINUX_IMMUTABLE))
3133 diff -NurpP --minimal linux-3.13.10/fs/ext4/namei.c linux-3.13.10-vs2.3.6.11/fs/ext4/namei.c
3134 --- linux-3.13.10/fs/ext4/namei.c 2013-11-25 15:46:59.000000000 +0000
3135 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/namei.c 2014-01-31 20:38:03.000000000 +0000
3137 #include <linux/quotaops.h>
3138 #include <linux/buffer_head.h>
3139 #include <linux/bio.h>
3140 +#include <linux/vs_tag.h>
3142 #include "ext4_jbd2.h"
3144 @@ -1299,6 +1300,7 @@ restart:
3145 ll_rw_block(READ | REQ_META | REQ_PRIO,
3148 + dx_propagate_tag(nd, inode);
3150 if ((bh = bh_use[ra_ptr++]) == NULL)
3152 @@ -3226,6 +3228,7 @@ const struct inode_operations ext4_dir_i
3153 .removexattr = generic_removexattr,
3154 .get_acl = ext4_get_acl,
3155 .fiemap = ext4_fiemap,
3156 + .sync_flags = ext4_sync_flags,
3159 const struct inode_operations ext4_special_inode_operations = {
3160 diff -NurpP --minimal linux-3.13.10/fs/ext4/super.c linux-3.13.10-vs2.3.6.11/fs/ext4/super.c
3161 --- linux-3.13.10/fs/ext4/super.c 2014-04-17 01:12:32.000000000 +0000
3162 +++ linux-3.13.10-vs2.3.6.11/fs/ext4/super.c 2014-03-12 15:51:07.000000000 +0000
3163 @@ -1162,7 +1162,7 @@ enum {
3164 Opt_inode_readahead_blks, Opt_journal_ioprio,
3165 Opt_dioread_nolock, Opt_dioread_lock,
3166 Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
3167 - Opt_max_dir_size_kb,
3168 + Opt_max_dir_size_kb, Opt_tag, Opt_notag, Opt_tagid
3171 static const match_table_t tokens = {
3172 @@ -1243,6 +1243,9 @@ static const match_table_t tokens = {
3173 {Opt_removed, "reservation"}, /* mount option from ext2/3 */
3174 {Opt_removed, "noreservation"}, /* mount option from ext2/3 */
3175 {Opt_removed, "journal=%u"}, /* mount option from ext2/3 */
3177 + {Opt_notag, "notag"},
3178 + {Opt_tagid, "tagid=%u"},
3182 @@ -1475,6 +1478,20 @@ static int handle_mount_opt(struct super
3184 sb->s_flags |= MS_I_VERSION;
3186 +#ifndef CONFIG_TAGGING_NONE
3188 + set_opt(sb, TAGGED);
3191 + clear_opt(sb, TAGGED);
3194 +#ifdef CONFIG_PROPAGATE
3197 + set_opt(sb, TAGGED);
3202 for (m = ext4_mount_opts; m->token != Opt_err; m++)
3203 @@ -3564,6 +3581,9 @@ static int ext4_fill_super(struct super_
3204 clear_opt(sb, DELALLOC);
3207 + if (EXT4_SB(sb)->s_mount_opt & EXT4_MOUNT_TAGGED)
3208 + sb->s_flags |= MS_TAGGED;
3210 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3211 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3213 @@ -4818,6 +4838,14 @@ static int ext4_remount(struct super_blo
3214 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3215 ext4_abort(sb, "Abort forced by user");
3217 + if ((sbi->s_mount_opt & EXT4_MOUNT_TAGGED) &&
3218 + !(sb->s_flags & MS_TAGGED)) {
3219 + printk("EXT4-fs: %s: tagging not permitted on remount.\n",
3222 + goto restore_opts;
3225 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3226 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
3228 diff -NurpP --minimal linux-3.13.10/fs/fcntl.c linux-3.13.10-vs2.3.6.11/fs/fcntl.c
3229 --- linux-3.13.10/fs/fcntl.c 2014-01-22 20:39:06.000000000 +0000
3230 +++ linux-3.13.10-vs2.3.6.11/fs/fcntl.c 2014-01-31 20:38:03.000000000 +0000
3232 #include <linux/rcupdate.h>
3233 #include <linux/pid_namespace.h>
3234 #include <linux/user_namespace.h>
3235 +#include <linux/vs_limit.h>
3237 #include <asm/poll.h>
3238 #include <asm/siginfo.h>
3239 @@ -377,6 +378,8 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, f
3243 + if (!vx_files_avail(1))
3246 if (unlikely(f.file->f_mode & FMODE_PATH)) {
3247 if (!check_fcntl_cmd(cmd))
3248 diff -NurpP --minimal linux-3.13.10/fs/file.c linux-3.13.10-vs2.3.6.11/fs/file.c
3249 --- linux-3.13.10/fs/file.c 2014-04-17 01:12:32.000000000 +0000
3250 +++ linux-3.13.10-vs2.3.6.11/fs/file.c 2014-02-25 11:26:09.000000000 +0000
3252 #include <linux/spinlock.h>
3253 #include <linux/rcupdate.h>
3254 #include <linux/workqueue.h>
3255 +#include <linux/vs_limit.h>
3257 int sysctl_nr_open __read_mostly = 1024*1024;
3258 int sysctl_nr_open_min = BITS_PER_LONG;
3259 @@ -311,6 +312,8 @@ struct files_struct *dup_fd(struct files
3260 struct file *f = *old_fds++;
3263 + /* TODO: sum it first for check and performance */
3264 + vx_openfd_inc(open_files - i);
3267 * The fd may be claimed in the fd bitmap but not yet
3268 @@ -376,9 +379,11 @@ static void close_files(struct files_str
3269 filp_close(file, files);
3280 @@ -503,6 +508,7 @@ repeat:
3282 __clear_close_on_exec(fd, fdt);
3284 + vx_openfd_inc(fd);
3287 if (rcu_dereference_raw(fdt->fd[fd]) != NULL) {
3288 @@ -533,6 +539,7 @@ static void __put_unused_fd(struct files
3289 __clear_open_fd(fd, fdt);
3290 if (fd < files->next_fd)
3291 files->next_fd = fd;
3292 + vx_openfd_dec(fd);
3295 void put_unused_fd(unsigned int fd)
3296 @@ -812,6 +819,8 @@ static int do_dup2(struct files_struct *
3299 filp_close(tofree, files);
3301 + vx_openfd_inc(fd); /* fd was unused */
3305 diff -NurpP --minimal linux-3.13.10/fs/file_table.c linux-3.13.10-vs2.3.6.11/fs/file_table.c
3306 --- linux-3.13.10/fs/file_table.c 2014-01-22 20:39:06.000000000 +0000
3307 +++ linux-3.13.10-vs2.3.6.11/fs/file_table.c 2014-02-01 00:00:01.000000000 +0000
3309 #include <linux/hardirq.h>
3310 #include <linux/task_work.h>
3311 #include <linux/ima.h>
3312 +#include <linux/vs_limit.h>
3313 +#include <linux/vs_context.h>
3315 #include <linux/atomic.h>
3317 @@ -137,6 +139,8 @@ struct file *get_empty_filp(void)
3318 spin_lock_init(&f->f_lock);
3319 eventpoll_init_file(f);
3320 /* f->f_version: 0 */
3321 + f->f_xid = vx_current_xid();
3326 @@ -254,6 +258,8 @@ static void __fput(struct file *file)
3327 i_readcount_dec(inode);
3328 if (file->f_mode & FMODE_WRITE)
3329 drop_file_write_access(file);
3330 + vx_files_dec(file);
3332 file->f_path.dentry = NULL;
3333 file->f_path.mnt = NULL;
3334 file->f_inode = NULL;
3335 @@ -340,6 +346,8 @@ void put_filp(struct file *file)
3337 if (atomic_long_dec_and_test(&file->f_count)) {
3338 security_file_free(file);
3339 + vx_files_dec(file);
3344 diff -NurpP --minimal linux-3.13.10/fs/fs_struct.c linux-3.13.10-vs2.3.6.11/fs/fs_struct.c
3345 --- linux-3.13.10/fs/fs_struct.c 2014-01-22 20:39:06.000000000 +0000
3346 +++ linux-3.13.10-vs2.3.6.11/fs/fs_struct.c 2014-01-31 20:38:03.000000000 +0000
3348 #include <linux/path.h>
3349 #include <linux/slab.h>
3350 #include <linux/fs_struct.h>
3351 +#include <linux/vserver/global.h>
3352 #include "internal.h"
3355 @@ -87,6 +88,7 @@ void free_fs_struct(struct fs_struct *fs
3357 path_put(&fs->root);
3359 + atomic_dec(&vs_global_fs);
3360 kmem_cache_free(fs_cachep, fs);
3363 @@ -124,6 +126,7 @@ struct fs_struct *copy_fs_struct(struct
3366 spin_unlock(&old->lock);
3367 + atomic_inc(&vs_global_fs);
3371 diff -NurpP --minimal linux-3.13.10/fs/gfs2/file.c linux-3.13.10-vs2.3.6.11/fs/gfs2/file.c
3372 --- linux-3.13.10/fs/gfs2/file.c 2014-01-22 20:39:06.000000000 +0000
3373 +++ linux-3.13.10-vs2.3.6.11/fs/gfs2/file.c 2014-01-31 20:38:03.000000000 +0000
3374 @@ -137,6 +137,9 @@ static const u32 fsflags_to_gfs2[32] = {
3375 [12] = GFS2_DIF_EXHASH,
3376 [14] = GFS2_DIF_INHERIT_JDATA,
3377 [17] = GFS2_DIF_TOPDIR,
3378 + [27] = GFS2_DIF_IXUNLINK,
3379 + [26] = GFS2_DIF_BARRIER,
3380 + [29] = GFS2_DIF_COW,
3383 static const u32 gfs2_to_fsflags[32] = {
3384 @@ -147,6 +150,9 @@ static const u32 gfs2_to_fsflags[32] = {
3385 [gfs2fl_ExHash] = FS_INDEX_FL,
3386 [gfs2fl_TopLevel] = FS_TOPDIR_FL,
3387 [gfs2fl_InheritJdata] = FS_JOURNAL_DATA_FL,
3388 + [gfs2fl_IXUnlink] = FS_IXUNLINK_FL,
3389 + [gfs2fl_Barrier] = FS_BARRIER_FL,
3390 + [gfs2fl_Cow] = FS_COW_FL,
3393 static int gfs2_get_flags(struct file *filp, u32 __user *ptr)
3394 @@ -177,12 +183,18 @@ void gfs2_set_inode_flags(struct inode *
3396 struct gfs2_inode *ip = GFS2_I(inode);
3397 unsigned int flags = inode->i_flags;
3398 + unsigned int vflags = inode->i_vflags;
3400 + flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3401 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC | S_NOSEC);
3403 - flags &= ~(S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_NOSEC);
3404 if ((ip->i_eattr == 0) && !is_sxid(inode->i_mode))
3405 inode->i_flags |= S_NOSEC;
3406 if (ip->i_diskflags & GFS2_DIF_IMMUTABLE)
3407 flags |= S_IMMUTABLE;
3408 + if (ip->i_diskflags & GFS2_DIF_IXUNLINK)
3409 + flags |= S_IXUNLINK;
3411 if (ip->i_diskflags & GFS2_DIF_APPENDONLY)
3413 if (ip->i_diskflags & GFS2_DIF_NOATIME)
3414 @@ -190,6 +202,43 @@ void gfs2_set_inode_flags(struct inode *
3415 if (ip->i_diskflags & GFS2_DIF_SYNC)
3417 inode->i_flags = flags;
3419 + vflags &= ~(V_BARRIER | V_COW);
3421 + if (ip->i_diskflags & GFS2_DIF_BARRIER)
3422 + vflags |= V_BARRIER;
3423 + if (ip->i_diskflags & GFS2_DIF_COW)
3425 + inode->i_vflags = vflags;
3428 +void gfs2_get_inode_flags(struct inode *inode)
3430 + struct gfs2_inode *ip = GFS2_I(inode);
3431 + unsigned int flags = inode->i_flags;
3432 + unsigned int vflags = inode->i_vflags;
3434 + ip->i_diskflags &= ~(GFS2_DIF_APPENDONLY |
3435 + GFS2_DIF_NOATIME | GFS2_DIF_SYNC |
3436 + GFS2_DIF_IMMUTABLE | GFS2_DIF_IXUNLINK |
3437 + GFS2_DIF_BARRIER | GFS2_DIF_COW);
3439 + if (flags & S_IMMUTABLE)
3440 + ip->i_diskflags |= GFS2_DIF_IMMUTABLE;
3441 + if (flags & S_IXUNLINK)
3442 + ip->i_diskflags |= GFS2_DIF_IXUNLINK;
3444 + if (flags & S_APPEND)
3445 + ip->i_diskflags |= GFS2_DIF_APPENDONLY;
3446 + if (flags & S_NOATIME)
3447 + ip->i_diskflags |= GFS2_DIF_NOATIME;
3448 + if (flags & S_SYNC)
3449 + ip->i_diskflags |= GFS2_DIF_SYNC;
3451 + if (vflags & V_BARRIER)
3452 + ip->i_diskflags |= GFS2_DIF_BARRIER;
3453 + if (vflags & V_COW)
3454 + ip->i_diskflags |= GFS2_DIF_COW;
3457 /* Flags that can be set by user space */
3458 @@ -303,6 +352,37 @@ static int gfs2_set_flags(struct file *f
3459 return do_gfs2_set_flags(filp, gfsflags, ~GFS2_DIF_JDATA);
3462 +int gfs2_sync_flags(struct inode *inode, int flags, int vflags)
3464 + struct gfs2_inode *ip = GFS2_I(inode);
3465 + struct gfs2_sbd *sdp = GFS2_SB(inode);
3466 + struct buffer_head *bh;
3467 + struct gfs2_holder gh;
3470 + error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
3473 + error = gfs2_trans_begin(sdp, RES_DINODE, 0);
3476 + error = gfs2_meta_inode_buffer(ip, &bh);
3478 + goto out_trans_end;
3479 + gfs2_trans_add_meta(ip->i_gl, bh);
3480 + inode->i_flags = flags;
3481 + inode->i_vflags = vflags;
3482 + gfs2_get_inode_flags(inode);
3483 + gfs2_dinode_out(ip, bh->b_data);
3485 + gfs2_set_aops(inode);
3487 + gfs2_trans_end(sdp);
3489 + gfs2_glock_dq_uninit(&gh);
3493 static long gfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3496 diff -NurpP --minimal linux-3.13.10/fs/gfs2/inode.h linux-3.13.10-vs2.3.6.11/fs/gfs2/inode.h
3497 --- linux-3.13.10/fs/gfs2/inode.h 2013-11-25 15:45:01.000000000 +0000
3498 +++ linux-3.13.10-vs2.3.6.11/fs/gfs2/inode.h 2014-01-31 20:38:03.000000000 +0000
3499 @@ -118,6 +118,7 @@ extern const struct file_operations gfs2
3500 extern const struct file_operations gfs2_dir_fops_nolock;
3502 extern void gfs2_set_inode_flags(struct inode *inode);
3503 +extern int gfs2_sync_flags(struct inode *inode, int flags, int vflags);
3505 #ifdef CONFIG_GFS2_FS_LOCKING_DLM
3506 extern const struct file_operations gfs2_file_fops;
3507 diff -NurpP --minimal linux-3.13.10/fs/hostfs/hostfs.h linux-3.13.10-vs2.3.6.11/fs/hostfs/hostfs.h
3508 --- linux-3.13.10/fs/hostfs/hostfs.h 2012-12-11 03:30:57.000000000 +0000
3509 +++ linux-3.13.10-vs2.3.6.11/fs/hostfs/hostfs.h 2014-01-31 20:38:03.000000000 +0000
3510 @@ -42,6 +42,7 @@ struct hostfs_iattr {
3511 unsigned short ia_mode;
3516 struct timespec ia_atime;
3517 struct timespec ia_mtime;
3518 diff -NurpP --minimal linux-3.13.10/fs/inode.c linux-3.13.10-vs2.3.6.11/fs/inode.c
3519 --- linux-3.13.10/fs/inode.c 2014-01-22 20:39:06.000000000 +0000
3520 +++ linux-3.13.10-vs2.3.6.11/fs/inode.c 2014-01-31 23:33:47.000000000 +0000
3522 #include <linux/buffer_head.h> /* for inode_has_buffers */
3523 #include <linux/ratelimit.h>
3524 #include <linux/list_lru.h>
3525 +#include <linux/vs_tag.h>
3526 #include "internal.h"
3529 @@ -129,6 +130,8 @@ int inode_init_always(struct super_block
3530 struct address_space *const mapping = &inode->i_data;
3534 + /* essential because of inode slab reuse */
3535 inode->i_blkbits = sb->s_blocksize_bits;
3537 atomic_set(&inode->i_count, 1);
3538 @@ -138,6 +141,7 @@ int inode_init_always(struct super_block
3539 inode->i_opflags = 0;
3540 i_uid_write(inode, 0);
3541 i_gid_write(inode, 0);
3542 + i_tag_write(inode, 0);
3543 atomic_set(&inode->i_writecount, 0);
3545 inode->i_blocks = 0;
3546 @@ -150,6 +154,7 @@ int inode_init_always(struct super_block
3547 inode->i_bdev = NULL;
3548 inode->i_cdev = NULL;
3550 + inode->i_mdev = 0;
3551 inode->dirtied_when = 0;
3553 if (security_inode_alloc(inode))
3554 @@ -477,6 +482,8 @@ void __insert_inode_hash(struct inode *i
3556 EXPORT_SYMBOL(__insert_inode_hash);
3558 +EXPORT_SYMBOL_GPL(__iget);
3561 * __remove_inode_hash - remove an inode from the hash
3562 * @inode: inode to unhash
3563 @@ -1802,9 +1809,11 @@ void init_special_inode(struct inode *in
3564 if (S_ISCHR(mode)) {
3565 inode->i_fop = &def_chr_fops;
3566 inode->i_rdev = rdev;
3567 + inode->i_mdev = rdev;
3568 } else if (S_ISBLK(mode)) {
3569 inode->i_fop = &def_blk_fops;
3570 inode->i_rdev = rdev;
3571 + inode->i_mdev = rdev;
3572 } else if (S_ISFIFO(mode))
3573 inode->i_fop = &pipefifo_fops;
3574 else if (S_ISSOCK(mode))
3575 @@ -1833,6 +1842,7 @@ void inode_init_owner(struct inode *inod
3577 inode->i_gid = current_fsgid();
3578 inode->i_mode = mode;
3579 + i_tag_write(inode, dx_current_fstag(inode->i_sb));
3581 EXPORT_SYMBOL(inode_init_owner);
3583 diff -NurpP --minimal linux-3.13.10/fs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ioctl.c
3584 --- linux-3.13.10/fs/ioctl.c 2014-01-22 20:39:06.000000000 +0000
3585 +++ linux-3.13.10-vs2.3.6.11/fs/ioctl.c 2014-01-31 20:38:03.000000000 +0000
3587 #include <linux/writeback.h>
3588 #include <linux/buffer_head.h>
3589 #include <linux/falloc.h>
3590 +#include <linux/proc_fs.h>
3591 +#include <linux/vserver/inode.h>
3592 +#include <linux/vs_tag.h>
3594 #include <asm/ioctls.h>
3596 diff -NurpP --minimal linux-3.13.10/fs/ioprio.c linux-3.13.10-vs2.3.6.11/fs/ioprio.c
3597 --- linux-3.13.10/fs/ioprio.c 2012-12-11 03:30:57.000000000 +0000
3598 +++ linux-3.13.10-vs2.3.6.11/fs/ioprio.c 2014-01-31 20:38:03.000000000 +0000
3600 #include <linux/syscalls.h>
3601 #include <linux/security.h>
3602 #include <linux/pid_namespace.h>
3603 +#include <linux/vs_base.h>
3605 int set_task_ioprio(struct task_struct *task, int ioprio)
3607 @@ -105,6 +106,8 @@ SYSCALL_DEFINE3(ioprio_set, int, which,
3609 pgrp = find_vpid(who);
3610 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3611 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3613 ret = set_task_ioprio(p, ioprio);
3616 @@ -198,6 +201,8 @@ SYSCALL_DEFINE2(ioprio_get, int, which,
3618 pgrp = find_vpid(who);
3619 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
3620 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
3622 tmpio = get_task_ioprio(p);
3625 diff -NurpP --minimal linux-3.13.10/fs/jfs/file.c linux-3.13.10-vs2.3.6.11/fs/jfs/file.c
3626 --- linux-3.13.10/fs/jfs/file.c 2013-02-19 13:58:48.000000000 +0000
3627 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/file.c 2014-01-31 20:38:03.000000000 +0000
3628 @@ -109,7 +109,8 @@ int jfs_setattr(struct dentry *dentry, s
3629 if (is_quota_modification(inode, iattr))
3630 dquot_initialize(inode);
3631 if ((iattr->ia_valid & ATTR_UID && !uid_eq(iattr->ia_uid, inode->i_uid)) ||
3632 - (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid))) {
3633 + (iattr->ia_valid & ATTR_GID && !gid_eq(iattr->ia_gid, inode->i_gid)) ||
3634 + (iattr->ia_valid & ATTR_TAG && !tag_eq(iattr->ia_tag, inode->i_tag))) {
3635 rc = dquot_transfer(inode, iattr);
3638 @@ -144,6 +145,7 @@ const struct inode_operations jfs_file_i
3639 #ifdef CONFIG_JFS_POSIX_ACL
3640 .get_acl = jfs_get_acl,
3642 + .sync_flags = jfs_sync_flags,
3645 const struct file_operations jfs_file_operations = {
3646 diff -NurpP --minimal linux-3.13.10/fs/jfs/ioctl.c linux-3.13.10-vs2.3.6.11/fs/jfs/ioctl.c
3647 --- linux-3.13.10/fs/jfs/ioctl.c 2013-05-31 13:45:24.000000000 +0000
3648 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/ioctl.c 2014-01-31 20:38:03.000000000 +0000
3650 #include <linux/time.h>
3651 #include <linux/sched.h>
3652 #include <linux/blkdev.h>
3653 +#include <linux/mount.h>
3654 #include <asm/current.h>
3655 #include <asm/uaccess.h>
3657 @@ -56,6 +57,16 @@ static long jfs_map_ext2(unsigned long f
3661 +int jfs_sync_flags(struct inode *inode, int flags, int vflags)
3663 + inode->i_flags = flags;
3664 + inode->i_vflags = vflags;
3665 + jfs_get_inode_flags(JFS_IP(inode));
3666 + inode->i_ctime = CURRENT_TIME_SEC;
3667 + mark_inode_dirty(inode);
3671 long jfs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3673 struct inode *inode = file_inode(filp);
3674 @@ -89,6 +100,11 @@ long jfs_ioctl(struct file *filp, unsign
3675 if (!S_ISDIR(inode->i_mode))
3676 flags &= ~JFS_DIRSYNC_FL;
3678 + if (IS_BARRIER(inode)) {
3679 + vxwprintk_task(1, "messing with the barrier.");
3683 /* Is it quota file? Do not allow user to mess with it */
3684 if (IS_NOQUOTA(inode)) {
3686 @@ -106,8 +122,8 @@ long jfs_ioctl(struct file *filp, unsign
3687 * the relevant capability.
3689 if ((oldflags & JFS_IMMUTABLE_FL) ||
3690 - ((flags ^ oldflags) &
3691 - (JFS_APPEND_FL | JFS_IMMUTABLE_FL))) {
3692 + ((flags ^ oldflags) & (JFS_APPEND_FL |
3693 + JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL))) {
3694 if (!capable(CAP_LINUX_IMMUTABLE)) {
3695 mutex_unlock(&inode->i_mutex);
3697 @@ -115,7 +131,7 @@ long jfs_ioctl(struct file *filp, unsign
3701 - flags = flags & JFS_FL_USER_MODIFIABLE;
3702 + flags &= JFS_FL_USER_MODIFIABLE;
3703 flags |= oldflags & ~JFS_FL_USER_MODIFIABLE;
3704 jfs_inode->mode2 = flags;
3706 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_dinode.h linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_dinode.h
3707 --- linux-3.13.10/fs/jfs/jfs_dinode.h 2012-12-11 03:30:57.000000000 +0000
3708 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_dinode.h 2014-01-31 20:38:03.000000000 +0000
3709 @@ -161,9 +161,13 @@ struct dinode {
3711 #define JFS_APPEND_FL 0x01000000 /* writes to file may only append */
3712 #define JFS_IMMUTABLE_FL 0x02000000 /* Immutable file */
3713 +#define JFS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
3715 -#define JFS_FL_USER_VISIBLE 0x03F80000
3716 -#define JFS_FL_USER_MODIFIABLE 0x03F80000
3717 +#define JFS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
3718 +#define JFS_COW_FL 0x20000000 /* Copy on Write marker */
3720 +#define JFS_FL_USER_VISIBLE 0x07F80000
3721 +#define JFS_FL_USER_MODIFIABLE 0x07F80000
3722 #define JFS_FL_INHERIT 0x03C80000
3724 /* These are identical to EXT[23]_IOC_GETFLAGS/SETFLAGS */
3725 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_filsys.h linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_filsys.h
3726 --- linux-3.13.10/fs/jfs/jfs_filsys.h 2012-12-11 03:30:57.000000000 +0000
3727 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_filsys.h 2014-01-31 20:38:03.000000000 +0000
3729 #define JFS_NAME_MAX 255
3730 #define JFS_PATH_MAX BPSIZE
3732 +#define JFS_TAGGED 0x00800000 /* Context Tagging */
3735 * file system state (superblock state)
3736 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_imap.c linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_imap.c
3737 --- linux-3.13.10/fs/jfs/jfs_imap.c 2013-11-25 15:45:01.000000000 +0000
3738 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_imap.c 2014-01-31 20:38:03.000000000 +0000
3740 #include <linux/pagemap.h>
3741 #include <linux/quotaops.h>
3742 #include <linux/slab.h>
3743 +#include <linux/vs_tag.h>
3745 #include "jfs_incore.h"
3746 #include "jfs_inode.h"
3747 @@ -3047,6 +3048,8 @@ static int copy_from_dinode(struct dinod
3749 struct jfs_inode_info *jfs_ip = JFS_IP(ip);
3750 struct jfs_sb_info *sbi = JFS_SBI(ip->i_sb);
3754 jfs_ip->fileset = le32_to_cpu(dip->di_fileset);
3755 jfs_ip->mode2 = le32_to_cpu(dip->di_mode);
3756 @@ -3067,14 +3070,18 @@ static int copy_from_dinode(struct dinod
3758 set_nlink(ip, le32_to_cpu(dip->di_nlink));
3760 - jfs_ip->saved_uid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3761 + kuid = make_kuid(&init_user_ns, le32_to_cpu(dip->di_uid));
3762 + kgid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3763 + ip->i_tag = INOTAG_KTAG(DX_TAG(ip), kuid, kgid, GLOBAL_ROOT_TAG);
3765 + jfs_ip->saved_uid = INOTAG_KUID(DX_TAG(ip), kuid, kgid);
3766 if (!uid_valid(sbi->uid))
3767 ip->i_uid = jfs_ip->saved_uid;
3769 ip->i_uid = sbi->uid;
3772 - jfs_ip->saved_gid = make_kgid(&init_user_ns, le32_to_cpu(dip->di_gid));
3773 + jfs_ip->saved_gid = INOTAG_KGID(DX_TAG(ip), kuid, kgid);
3774 if (!gid_valid(sbi->gid))
3775 ip->i_gid = jfs_ip->saved_gid;
3777 @@ -3139,16 +3146,14 @@ static void copy_to_dinode(struct dinode
3778 dip->di_size = cpu_to_le64(ip->i_size);
3779 dip->di_nblocks = cpu_to_le64(PBLK2LBLK(ip->i_sb, ip->i_blocks));
3780 dip->di_nlink = cpu_to_le32(ip->i_nlink);
3781 - if (!uid_valid(sbi->uid))
3782 - dip->di_uid = cpu_to_le32(i_uid_read(ip));
3784 - dip->di_uid =cpu_to_le32(from_kuid(&init_user_ns,
3785 - jfs_ip->saved_uid));
3786 - if (!gid_valid(sbi->gid))
3787 - dip->di_gid = cpu_to_le32(i_gid_read(ip));
3789 - dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3790 - jfs_ip->saved_gid));
3791 + dip->di_uid = cpu_to_le32(from_kuid(&init_user_ns,
3792 + TAGINO_KUID(DX_TAG(ip),
3793 + !uid_valid(sbi->uid) ? ip->i_uid : jfs_ip->saved_uid,
3795 + dip->di_gid = cpu_to_le32(from_kgid(&init_user_ns,
3796 + TAGINO_KGID(DX_TAG(ip),
3797 + !gid_valid(sbi->gid) ? ip->i_gid : jfs_ip->saved_gid,
3799 jfs_get_inode_flags(jfs_ip);
3801 * mode2 is only needed for storing the higher order bits.
3802 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_inode.c linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.c
3803 --- linux-3.13.10/fs/jfs/jfs_inode.c 2013-11-25 15:46:59.000000000 +0000
3804 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.c 2014-01-31 20:38:03.000000000 +0000
3807 #include <linux/fs.h>
3808 #include <linux/quotaops.h>
3809 +#include <linux/vs_tag.h>
3810 #include "jfs_incore.h"
3811 #include "jfs_inode.h"
3812 #include "jfs_filsys.h"
3813 @@ -30,29 +31,46 @@ void jfs_set_inode_flags(struct inode *i
3815 unsigned int flags = JFS_IP(inode)->mode2;
3817 - inode->i_flags &= ~(S_IMMUTABLE | S_APPEND |
3818 - S_NOATIME | S_DIRSYNC | S_SYNC);
3819 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
3820 + S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
3822 if (flags & JFS_IMMUTABLE_FL)
3823 inode->i_flags |= S_IMMUTABLE;
3824 + if (flags & JFS_IXUNLINK_FL)
3825 + inode->i_flags |= S_IXUNLINK;
3827 + if (flags & JFS_SYNC_FL)
3828 + inode->i_flags |= S_SYNC;
3829 if (flags & JFS_APPEND_FL)
3830 inode->i_flags |= S_APPEND;
3831 if (flags & JFS_NOATIME_FL)
3832 inode->i_flags |= S_NOATIME;
3833 if (flags & JFS_DIRSYNC_FL)
3834 inode->i_flags |= S_DIRSYNC;
3835 - if (flags & JFS_SYNC_FL)
3836 - inode->i_flags |= S_SYNC;
3838 + inode->i_vflags &= ~(V_BARRIER | V_COW);
3840 + if (flags & JFS_BARRIER_FL)
3841 + inode->i_vflags |= V_BARRIER;
3842 + if (flags & JFS_COW_FL)
3843 + inode->i_vflags |= V_COW;
3846 void jfs_get_inode_flags(struct jfs_inode_info *jfs_ip)
3848 unsigned int flags = jfs_ip->vfs_inode.i_flags;
3849 + unsigned int vflags = jfs_ip->vfs_inode.i_vflags;
3851 + jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_IXUNLINK_FL |
3852 + JFS_APPEND_FL | JFS_NOATIME_FL |
3853 + JFS_DIRSYNC_FL | JFS_SYNC_FL |
3854 + JFS_BARRIER_FL | JFS_COW_FL);
3856 - jfs_ip->mode2 &= ~(JFS_IMMUTABLE_FL | JFS_APPEND_FL | JFS_NOATIME_FL |
3857 - JFS_DIRSYNC_FL | JFS_SYNC_FL);
3858 if (flags & S_IMMUTABLE)
3859 jfs_ip->mode2 |= JFS_IMMUTABLE_FL;
3860 + if (flags & S_IXUNLINK)
3861 + jfs_ip->mode2 |= JFS_IXUNLINK_FL;
3863 if (flags & S_APPEND)
3864 jfs_ip->mode2 |= JFS_APPEND_FL;
3865 if (flags & S_NOATIME)
3866 @@ -61,6 +79,11 @@ void jfs_get_inode_flags(struct jfs_inod
3867 jfs_ip->mode2 |= JFS_DIRSYNC_FL;
3869 jfs_ip->mode2 |= JFS_SYNC_FL;
3871 + if (vflags & V_BARRIER)
3872 + jfs_ip->mode2 |= JFS_BARRIER_FL;
3873 + if (vflags & V_COW)
3874 + jfs_ip->mode2 |= JFS_COW_FL;
3878 diff -NurpP --minimal linux-3.13.10/fs/jfs/jfs_inode.h linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.h
3879 --- linux-3.13.10/fs/jfs/jfs_inode.h 2012-12-11 03:30:57.000000000 +0000
3880 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/jfs_inode.h 2014-01-31 20:38:03.000000000 +0000
3881 @@ -39,6 +39,7 @@ extern struct dentry *jfs_fh_to_dentry(s
3882 extern struct dentry *jfs_fh_to_parent(struct super_block *sb, struct fid *fid,
3883 int fh_len, int fh_type);
3884 extern void jfs_set_inode_flags(struct inode *);
3885 +extern int jfs_sync_flags(struct inode *, int, int);
3886 extern int jfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
3887 extern int jfs_setattr(struct dentry *, struct iattr *);
3889 diff -NurpP --minimal linux-3.13.10/fs/jfs/namei.c linux-3.13.10-vs2.3.6.11/fs/jfs/namei.c
3890 --- linux-3.13.10/fs/jfs/namei.c 2013-11-25 15:45:01.000000000 +0000
3891 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/namei.c 2014-01-31 20:38:03.000000000 +0000
3893 #include <linux/ctype.h>
3894 #include <linux/quotaops.h>
3895 #include <linux/exportfs.h>
3896 +#include <linux/vs_tag.h>
3897 #include "jfs_incore.h"
3898 #include "jfs_superblock.h"
3899 #include "jfs_inode.h"
3900 @@ -1461,6 +1462,7 @@ static struct dentry *jfs_lookup(struct
3901 jfs_err("jfs_lookup: iget failed on inum %d", (uint)inum);
3904 + dx_propagate_tag(nd, ip);
3905 return d_splice_alias(ip, dentry);
3908 @@ -1525,6 +1527,7 @@ const struct inode_operations jfs_dir_in
3909 #ifdef CONFIG_JFS_POSIX_ACL
3910 .get_acl = jfs_get_acl,
3912 + .sync_flags = jfs_sync_flags,
3915 const struct file_operations jfs_dir_operations = {
3916 diff -NurpP --minimal linux-3.13.10/fs/jfs/super.c linux-3.13.10-vs2.3.6.11/fs/jfs/super.c
3917 --- linux-3.13.10/fs/jfs/super.c 2013-11-25 15:45:01.000000000 +0000
3918 +++ linux-3.13.10-vs2.3.6.11/fs/jfs/super.c 2014-01-31 20:38:03.000000000 +0000
3919 @@ -203,7 +203,8 @@ enum {
3920 Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
3921 Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
3922 Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
3923 - Opt_discard, Opt_nodiscard, Opt_discard_minblk
3924 + Opt_discard, Opt_nodiscard, Opt_discard_minblk,
3925 + Opt_tag, Opt_notag, Opt_tagid
3928 static const match_table_t tokens = {
3929 @@ -213,6 +214,10 @@ static const match_table_t tokens = {
3930 {Opt_resize, "resize=%u"},
3931 {Opt_resize_nosize, "resize"},
3932 {Opt_errors, "errors=%s"},
3934 + {Opt_notag, "notag"},
3935 + {Opt_tagid, "tagid=%u"},
3936 + {Opt_tag, "tagxid"},
3937 {Opt_ignore, "noquota"},
3938 {Opt_ignore, "quota"},
3939 {Opt_usrquota, "usrquota"},
3940 @@ -389,7 +394,20 @@ static int parse_options(char *options,
3945 +#ifndef CONFIG_TAGGING_NONE
3947 + *flag |= JFS_TAGGED;
3950 + *flag &= JFS_TAGGED;
3953 +#ifdef CONFIG_PROPAGATE
3956 + *flag |= JFS_TAGGED;
3960 printk("jfs: Unrecognized mount option \"%s\" "
3961 " or missing value\n", p);
3962 @@ -421,6 +439,12 @@ static int jfs_remount(struct super_bloc
3966 + if ((flag & JFS_TAGGED) && !(sb->s_flags & MS_TAGGED)) {
3967 + printk(KERN_ERR "JFS: %s: tagging not permitted on remount.\n",
3973 if (sb->s_flags & MS_RDONLY) {
3974 pr_err("JFS: resize requires volume" \
3975 @@ -506,6 +530,9 @@ static int jfs_fill_super(struct super_b
3976 #ifdef CONFIG_JFS_POSIX_ACL
3977 sb->s_flags |= MS_POSIXACL;
3979 + /* map mount option tagxid */
3980 + if (sbi->flag & JFS_TAGGED)
3981 + sb->s_flags |= MS_TAGGED;
3984 pr_err("resize option for remount only\n");
3985 diff -NurpP --minimal linux-3.13.10/fs/libfs.c linux-3.13.10-vs2.3.6.11/fs/libfs.c
3986 --- linux-3.13.10/fs/libfs.c 2014-01-22 20:39:06.000000000 +0000
3987 +++ linux-3.13.10-vs2.3.6.11/fs/libfs.c 2014-02-01 01:35:46.000000000 +0000
3988 @@ -145,13 +145,14 @@ static inline unsigned char dt_type(stru
3989 * both impossible due to the lock on directory.
3992 -int dcache_readdir(struct file *file, struct dir_context *ctx)
3993 +static inline int do_dcache_readdir_filter(struct file *filp,
3994 + struct dir_context *ctx, int (*filter)(struct dentry *dentry))
3996 - struct dentry *dentry = file->f_path.dentry;
3997 - struct dentry *cursor = file->private_data;
3998 + struct dentry *dentry = filp->f_path.dentry;
3999 + struct dentry *cursor = filp->private_data;
4000 struct list_head *p, *q = &cursor->d_u.d_child;
4002 - if (!dir_emit_dots(file, ctx))
4003 + if (!dir_emit_dots(filp, ctx))
4005 spin_lock(&dentry->d_lock);
4007 @@ -159,6 +160,8 @@ int dcache_readdir(struct file *file, st
4009 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
4010 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
4011 + if (filter && !filter(next))
4013 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
4014 if (!simple_positive(next)) {
4015 spin_unlock(&next->d_lock);
4016 @@ -181,8 +184,22 @@ int dcache_readdir(struct file *file, st
4017 spin_unlock(&dentry->d_lock);
4021 EXPORT_SYMBOL(dcache_readdir);
4023 +int dcache_readdir(struct file *filp, struct dir_context *ctx)
4025 + return do_dcache_readdir_filter(filp, ctx, NULL);
4028 +EXPORT_SYMBOL(dcache_readdir_filter);
4030 +int dcache_readdir_filter(struct file *filp, struct dir_context *ctx,
4031 + int (*filter)(struct dentry *))
4033 + return do_dcache_readdir_filter(filp, ctx, filter);
4036 ssize_t generic_read_dir(struct file *filp, char __user *buf, size_t siz, loff_t *ppos)
4039 diff -NurpP --minimal linux-3.13.10/fs/locks.c linux-3.13.10-vs2.3.6.11/fs/locks.c
4040 --- linux-3.13.10/fs/locks.c 2014-01-22 20:39:06.000000000 +0000
4041 +++ linux-3.13.10-vs2.3.6.11/fs/locks.c 2014-01-31 23:51:55.000000000 +0000
4043 #include <linux/hashtable.h>
4044 #include <linux/percpu.h>
4045 #include <linux/lglock.h>
4046 +#include <linux/vs_base.h>
4047 +#include <linux/vs_limit.h>
4049 #include <asm/uaccess.h>
4051 @@ -210,11 +212,17 @@ static void locks_init_lock_heads(struct
4052 /* Allocate an empty lock structure. */
4053 struct file_lock *locks_alloc_lock(void)
4055 - struct file_lock *fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4056 + struct file_lock *fl;
4059 - locks_init_lock_heads(fl);
4060 + if (!vx_locks_avail(1))
4063 + fl = kmem_cache_zalloc(filelock_cache, GFP_KERNEL);
4066 + locks_init_lock_heads(fl);
4071 EXPORT_SYMBOL_GPL(locks_alloc_lock);
4072 @@ -238,6 +246,7 @@ void locks_free_lock(struct file_lock *f
4073 BUG_ON(!list_empty(&fl->fl_block));
4074 BUG_ON(!hlist_unhashed(&fl->fl_link));
4077 locks_release_private(fl);
4078 kmem_cache_free(filelock_cache, fl);
4080 @@ -247,6 +256,7 @@ void locks_init_lock(struct file_lock *f
4082 memset(fl, 0, sizeof(struct file_lock));
4083 locks_init_lock_heads(fl);
4087 EXPORT_SYMBOL(locks_init_lock);
4088 @@ -287,6 +297,7 @@ void locks_copy_lock(struct file_lock *n
4089 new->fl_file = fl->fl_file;
4090 new->fl_ops = fl->fl_ops;
4091 new->fl_lmops = fl->fl_lmops;
4092 + new->fl_xid = fl->fl_xid;
4094 locks_copy_private(new, fl);
4096 @@ -325,6 +336,11 @@ static int flock_make_lock(struct file *
4097 fl->fl_flags = FL_FLOCK;
4099 fl->fl_end = OFFSET_MAX;
4101 + vxd_assert(filp->f_xid == vx_current_xid(),
4102 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4103 + fl->fl_xid = filp->f_xid;
4108 @@ -464,6 +480,7 @@ static int lease_init(struct file *filp,
4110 fl->fl_owner = current->files;
4111 fl->fl_pid = current->tgid;
4112 + fl->fl_xid = vx_current_xid();
4115 fl->fl_flags = FL_LEASE;
4116 @@ -483,6 +500,11 @@ static struct file_lock *lease_alloc(str
4118 return ERR_PTR(error);
4120 + fl->fl_xid = vx_current_xid();
4122 + vxd_assert(filp->f_xid == fl->fl_xid,
4123 + "f_xid(%d) == fl_xid(%d)", filp->f_xid, fl->fl_xid);
4125 error = lease_init(filp, type, fl);
4127 locks_free_lock(fl);
4128 @@ -858,6 +880,7 @@ static int flock_lock_file(struct file *
4129 spin_lock(&inode->i_lock);
4132 + new_fl->fl_xid = -1;
4134 for_each_lock(inode, before) {
4135 struct file_lock *fl = *before;
4136 @@ -878,6 +901,7 @@ find_conflict:
4138 locks_copy_lock(new_fl, request);
4139 locks_insert_lock(before, new_fl);
4140 + vx_locks_inc(new_fl);
4144 @@ -888,7 +912,8 @@ out:
4148 -static int __posix_lock_file(struct inode *inode, struct file_lock *request, struct file_lock *conflock)
4149 +static int __posix_lock_file(struct inode *inode, struct file_lock *request,
4150 + struct file_lock *conflock, vxid_t xid)
4152 struct file_lock *fl;
4153 struct file_lock *new_fl = NULL;
4154 @@ -899,6 +924,8 @@ static int __posix_lock_file(struct inod
4158 + vxd_assert(xid == vx_current_xid(),
4159 + "xid(%d) == current(%d)", xid, vx_current_xid());
4161 * We may need two file_lock structures for this operation,
4162 * so we get them in advance to avoid races.
4163 @@ -909,7 +936,11 @@ static int __posix_lock_file(struct inod
4164 (request->fl_type != F_UNLCK ||
4165 request->fl_start != 0 || request->fl_end != OFFSET_MAX)) {
4166 new_fl = locks_alloc_lock();
4167 + new_fl->fl_xid = xid;
4168 + vx_locks_inc(new_fl);
4169 new_fl2 = locks_alloc_lock();
4170 + new_fl2->fl_xid = xid;
4171 + vx_locks_inc(new_fl2);
4174 spin_lock(&inode->i_lock);
4175 @@ -1118,7 +1149,8 @@ static int __posix_lock_file(struct inod
4176 int posix_lock_file(struct file *filp, struct file_lock *fl,
4177 struct file_lock *conflock)
4179 - return __posix_lock_file(file_inode(filp), fl, conflock);
4180 + return __posix_lock_file(file_inode(filp),
4181 + fl, conflock, filp->f_xid);
4183 EXPORT_SYMBOL(posix_lock_file);
4185 @@ -1208,7 +1240,7 @@ int locks_mandatory_area(int read_write,
4186 fl.fl_end = offset + count - 1;
4189 - error = __posix_lock_file(inode, &fl, NULL);
4190 + error = __posix_lock_file(inode, &fl, NULL, filp->f_xid);
4191 if (error != FILE_LOCK_DEFERRED)
4193 error = wait_event_interruptible(fl.fl_wait, !fl.fl_next);
4194 @@ -1549,6 +1581,7 @@ static int generic_add_lease(struct file
4197 locks_insert_lock(before, lease);
4198 + vx_locks_inc(lease);
4202 @@ -1991,6 +2024,11 @@ int fcntl_setlk(unsigned int fd, struct
4203 if (file_lock == NULL)
4206 + vxd_assert(filp->f_xid == vx_current_xid(),
4207 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4208 + file_lock->fl_xid = filp->f_xid;
4209 + vx_locks_inc(file_lock);
4212 * This might block, so we do it before checking the inode.
4214 @@ -2109,6 +2147,11 @@ int fcntl_setlk64(unsigned int fd, struc
4215 if (file_lock == NULL)
4218 + vxd_assert(filp->f_xid == vx_current_xid(),
4219 + "f_xid(%d) == current(%d)", filp->f_xid, vx_current_xid());
4220 + file_lock->fl_xid = filp->f_xid;
4221 + vx_locks_inc(file_lock);
4224 * This might block, so we do it before checking the inode.
4226 @@ -2378,8 +2421,11 @@ static int locks_show(struct seq_file *f
4228 lock_get_status(f, fl, iter->li_pos, "");
4230 - list_for_each_entry(bfl, &fl->fl_block, fl_block)
4231 - lock_get_status(f, bfl, iter->li_pos, " ->");
4232 + list_for_each_entry(bfl, &fl->fl_block, fl_block) {
4233 + if (!vx_check(fl->fl_xid, VS_WATCH_P | VS_IDENT))
4235 + lock_get_status(f, bfl, iter->li_pos, " ->");
4240 diff -NurpP --minimal linux-3.13.10/fs/mount.h linux-3.13.10-vs2.3.6.11/fs/mount.h
4241 --- linux-3.13.10/fs/mount.h 2014-04-17 01:12:32.000000000 +0000
4242 +++ linux-3.13.10-vs2.3.6.11/fs/mount.h 2014-04-17 01:17:10.000000000 +0000
4243 @@ -57,6 +57,7 @@ struct mount {
4244 int mnt_expiry_mark; /* true if marked for expiry */
4246 struct path mnt_ex_mountpoint;
4247 + vtag_t mnt_tag; /* tagging used for vfsmount */
4250 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
4251 diff -NurpP --minimal linux-3.13.10/fs/namei.c linux-3.13.10-vs2.3.6.11/fs/namei.c
4252 --- linux-3.13.10/fs/namei.c 2014-04-17 01:12:32.000000000 +0000
4253 +++ linux-3.13.10-vs2.3.6.11/fs/namei.c 2014-04-17 01:17:10.000000000 +0000
4255 #include <linux/device_cgroup.h>
4256 #include <linux/fs_struct.h>
4257 #include <linux/posix_acl.h>
4258 +#include <linux/proc_fs.h>
4259 +#include <linux/magic.h>
4260 +#include <linux/vserver/inode.h>
4261 +#include <linux/vs_base.h>
4262 +#include <linux/vs_tag.h>
4263 +#include <linux/vs_cowbl.h>
4264 +#include <linux/vs_device.h>
4265 +#include <linux/vs_context.h>
4266 +#include <linux/pid_namespace.h>
4267 #include <asm/uaccess.h>
4269 #include "internal.h"
4270 +#include "proc/internal.h"
4273 /* [Feb-1997 T. Schoebel-Theuer]
4274 @@ -266,6 +276,89 @@ static int check_acl(struct inode *inode
4278 +static inline int dx_barrier(const struct inode *inode)
4280 + if (IS_BARRIER(inode) && !vx_check(0, VS_ADMIN | VS_WATCH)) {
4281 + vxwprintk_task(1, "did hit the barrier.");
4287 +static int __dx_permission(const struct inode *inode, int mask)
4289 + if (dx_barrier(inode))
4292 + if (inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC) {
4293 + /* devpts is xid tagged */
4294 + if (S_ISDIR(inode->i_mode) ||
4295 + vx_check((vxid_t)i_tag_read(inode), VS_IDENT | VS_WATCH_P))
4298 + /* just pretend we didn't find anything */
4301 + else if (inode->i_sb->s_magic == PROC_SUPER_MAGIC) {
4302 + struct proc_dir_entry *de = PDE(inode);
4304 + if (de && !vx_hide_check(0, de->vx_flags))
4307 + if ((mask & (MAY_WRITE | MAY_APPEND))) {
4309 + struct task_struct *tsk;
4311 + if (vx_check(0, VS_ADMIN | VS_WATCH_P) ||
4312 + vx_flags(VXF_STATE_SETUP, 0))
4315 + pid = PROC_I(inode)->pid;
4320 + tsk = pid_task(pid, PIDTYPE_PID);
4321 + vxdprintk(VXD_CBIT(tag, 0), "accessing %p[#%u]",
4322 + tsk, (tsk ? vx_task_xid(tsk) : 0));
4324 + vx_check(vx_task_xid(tsk), VS_IDENT | VS_WATCH_P)) {
4325 + rcu_read_unlock();
4328 + rcu_read_unlock();
4331 + /* FIXME: Should we block some entries here? */
4336 + if (dx_notagcheck(inode->i_sb) ||
4337 + dx_check((vxid_t)i_tag_read(inode),
4338 + DX_HOSTID | DX_ADMIN | DX_WATCH | DX_IDENT))
4346 +int dx_permission(const struct inode *inode, int mask)
4348 + int ret = __dx_permission(inode, mask);
4349 + if (unlikely(ret)) {
4350 +#ifndef CONFIG_VSERVER_WARN_DEVPTS
4351 + if (inode->i_sb->s_magic != DEVPTS_SUPER_MAGIC)
4354 + "denied [0x%x] access to inode %s:%p[#%d,%lu]",
4355 + mask, inode->i_sb->s_id, inode,
4356 + i_tag_read(inode), inode->i_ino);
4362 * This does the basic permission checking
4364 @@ -388,10 +481,14 @@ int __inode_permission(struct inode *ino
4366 * Nobody gets write access to an immutable file.
4368 - if (IS_IMMUTABLE(inode))
4369 + if (IS_IMMUTABLE(inode) && !IS_COW(inode))
4373 + retval = dx_permission(inode, mask);
4377 retval = do_inode_permission(inode, mask);
4380 @@ -1238,7 +1335,8 @@ static void follow_dotdot(struct nameida
4382 if (nd->path.dentry == nd->root.dentry &&
4383 nd->path.mnt == nd->root.mnt) {
4385 + /* for sane '/' avoid follow_mount() */
4388 if (nd->path.dentry != nd->path.mnt->mnt_root) {
4389 /* rare case of legitimate dget_parent()... */
4390 @@ -1383,6 +1481,9 @@ static int lookup_fast(struct nameidata
4395 + /* FIXME: check dx permission */
4398 path->dentry = dentry;
4399 if (unlikely(!__follow_mount_rcu(nd, path, inode)))
4400 @@ -1413,6 +1514,8 @@ unlazy:
4404 + /* FIXME: check dx permission */
4407 path->dentry = dentry;
4408 err = follow_managed(path, nd->flags);
4409 @@ -2400,7 +2503,7 @@ static int may_delete(struct inode *dir,
4412 if (check_sticky(dir, inode) || IS_APPEND(inode) ||
4413 - IS_IMMUTABLE(inode) || IS_SWAPFILE(inode))
4414 + IS_IXORUNLINK(inode) || IS_SWAPFILE(inode))
4417 if (!d_is_directory(victim) && !d_is_autodir(victim))
4418 @@ -2480,19 +2583,25 @@ int vfs_create(struct inode *dir, struct
4421 int error = may_create(dir, dentry);
4424 + vxdprintk(VXD_CBIT(misc, 3), "may_create failed with %d", error);
4428 if (!dir->i_op->create)
4429 return -EACCES; /* shouldn't it be ENOSYS? */
4432 error = security_inode_create(dir, dentry, mode);
4435 + vxdprintk(VXD_CBIT(misc, 3), "security_inode_create failed with %d", error);
4438 error = dir->i_op->create(dir, dentry, mode, want_excl);
4440 fsnotify_create(dir, dentry);
4442 + vxdprintk(VXD_CBIT(misc, 3), "i_op->create failed with %d", error);
4446 @@ -2527,6 +2636,15 @@ static int may_open(struct path *path, i
4450 +#ifdef CONFIG_VSERVER_COWBL
4451 + if (IS_COW(inode) &&
4452 + ((flag & O_ACCMODE) != O_RDONLY)) {
4453 + if (IS_COW_LINK(inode))
4455 + inode->i_flags &= ~(S_IXUNLINK|S_IMMUTABLE);
4456 + mark_inode_dirty(inode);
4459 error = inode_permission(inode, acc_mode);
4462 @@ -3022,6 +3140,16 @@ finish_open:
4464 finish_open_created:
4465 error = may_open(&nd->path, acc_mode, open_flag);
4466 +#ifdef CONFIG_VSERVER_COWBL
4467 + if (error == -EMLINK) {
4468 + struct dentry *dentry;
4469 + dentry = cow_break_link(name->name);
4470 + if (IS_ERR(dentry))
4471 + error = PTR_ERR(dentry);
4478 file->f_path.mnt = nd->path.mnt;
4479 @@ -3147,6 +3275,7 @@ static struct file *path_openat(int dfd,
4484 file = get_empty_filp();
4487 @@ -3188,6 +3317,16 @@ static struct file *path_openat(int dfd,
4488 error = do_last(nd, &path, file, op, &opened, pathname);
4489 put_link(nd, &link, cookie);
4492 +#ifdef CONFIG_VSERVER_COWBL
4493 + if (error == -EMLINK) {
4494 + if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4495 + path_put(&nd->root);
4502 if (nd->root.mnt && !(nd->flags & LOOKUP_ROOT))
4503 path_put(&nd->root);
4504 @@ -3303,6 +3442,11 @@ struct dentry *kern_path_create(int dfd,
4508 + vxdprintk(VXD_CBIT(misc, 3), "kern_path_create path.dentry = %p (%.*s), dentry = %p (%.*s), d_inode = %p",
4509 + path->dentry, path->dentry->d_name.len,
4510 + path->dentry->d_name.name, dentry,
4511 + dentry->d_name.len, dentry->d_name.name,
4512 + path->dentry->d_inode);
4516 @@ -3850,7 +3994,7 @@ int vfs_link(struct dentry *old_dentry,
4518 * A link to an append-only or immutable file cannot be created.
4520 - if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
4521 + if (IS_APPEND(inode) || IS_IXORUNLINK(inode))
4523 if (!dir->i_op->link)
4525 @@ -4305,6 +4449,287 @@ int generic_readlink(struct dentry *dent
4530 +#ifdef CONFIG_VSERVER_COWBL
4533 +long do_cow_splice(struct file *in, struct file *out, size_t len)
4538 + return do_splice_direct(in, &ppos, out, &opos, len, 0);
4541 +struct dentry *cow_break_link(const char *pathname)
4543 + int ret, mode, pathlen, redo = 0, drop = 1;
4544 + struct nameidata old_nd, dir_nd;
4545 + struct path dir_path, *old_path, *new_path;
4546 + struct dentry *dir, *old_dentry, *new_dentry = NULL;
4547 + struct file *old_file;
4548 + struct file *new_file;
4549 + char *to, *path, pad='\251';
4552 + vxdprintk(VXD_CBIT(misc, 1),
4553 + "cow_break_link(" VS_Q("%s") ")", pathname);
4555 + path = kmalloc(PATH_MAX, GFP_KERNEL);
4560 + /* old_nd.path will have refs to dentry and mnt */
4561 + ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4562 + vxdprintk(VXD_CBIT(misc, 2),
4563 + "do_path_lookup(old): %d", ret);
4565 + goto out_free_path;
4567 + /* dentry/mnt refs handed over to old_path */
4568 + old_path = &old_nd.path;
4569 + /* no explicit reference for old_dentry here */
4570 + old_dentry = old_path->dentry;
4572 + mode = old_dentry->d_inode->i_mode;
4573 + to = d_path(old_path, path, PATH_MAX-2);
4574 + pathlen = strlen(to);
4575 + vxdprintk(VXD_CBIT(misc, 2),
4576 + "old path " VS_Q("%s") " [%p:" VS_Q("%.*s") ":%d]", to,
4578 + old_dentry->d_name.len, old_dentry->d_name.name,
4579 + old_dentry->d_name.len);
4581 + to[pathlen + 1] = 0;
4583 + new_dentry = NULL;
4584 + to[pathlen] = pad--;
4586 + if (pad <= '\240')
4589 + vxdprintk(VXD_CBIT(misc, 1), "temp copy " VS_Q("%s"), to);
4591 + /* dir_nd.path will have refs to dentry and mnt */
4592 + ret = do_path_lookup(AT_FDCWD, to,
4593 + LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE, &dir_nd);
4594 + vxdprintk(VXD_CBIT(misc, 2), "do_path_lookup(new): %d", ret);
4598 + /* this puppy downs the dir inode mutex if successful.
4599 + dir_path will hold refs to dentry and mnt and
4600 + we'll have write access to the mnt */
4601 + new_dentry = kern_path_create(AT_FDCWD, to, &dir_path, 0);
4602 + if (!new_dentry || IS_ERR(new_dentry)) {
4603 + path_put(&dir_nd.path);
4604 + vxdprintk(VXD_CBIT(misc, 2),
4605 + "kern_path_create(new) failed with %ld",
4606 + PTR_ERR(new_dentry));
4609 + vxdprintk(VXD_CBIT(misc, 2),
4610 + "kern_path_create(new): %p [" VS_Q("%.*s") ":%d]",
4612 + new_dentry->d_name.len, new_dentry->d_name.name,
4613 + new_dentry->d_name.len);
4615 + /* take a reference on new_dentry */
4618 + /* dentry/mnt refs handed over to new_path */
4619 + new_path = &dir_path;
4621 + /* dentry for old/new dir */
4622 + dir = dir_nd.path.dentry;
4624 + /* give up reference on dir */
4625 + dput(new_path->dentry);
4627 + /* new_dentry already has a reference */
4628 + new_path->dentry = new_dentry;
4630 + ret = vfs_create(dir->d_inode, new_dentry, mode, 1);
4631 + vxdprintk(VXD_CBIT(misc, 2),
4632 + "vfs_create(new): %d", ret);
4633 + if (ret == -EEXIST) {
4634 + path_put(&dir_nd.path);
4635 + mutex_unlock(&dir->d_inode->i_mutex);
4636 + mnt_drop_write(new_path->mnt);
4637 + path_put(new_path);
4638 + new_dentry = NULL;
4642 + goto out_unlock_new;
4644 + /* drop out early, ret passes ENOENT */
4646 + if ((redo = d_unhashed(old_dentry)))
4647 + goto out_unlock_new;
4649 + /* doesn't change refs for old_path */
4650 + old_file = dentry_open(old_path, O_RDONLY, current_cred());
4651 + vxdprintk(VXD_CBIT(misc, 2),
4652 + "dentry_open(old): %p", old_file);
4653 + if (IS_ERR(old_file)) {
4654 + ret = PTR_ERR(old_file);
4655 + goto out_unlock_new;
4658 + /* doesn't change refs for new_path */
4659 + new_file = dentry_open(new_path, O_WRONLY, current_cred());
4660 + vxdprintk(VXD_CBIT(misc, 2),
4661 + "dentry_open(new): %p", new_file);
4662 + if (IS_ERR(new_file)) {
4663 + ret = PTR_ERR(new_file);
4664 + goto out_fput_old;
4667 + /* unlock the inode mutex from kern_path_create() */
4668 + mutex_unlock(&dir->d_inode->i_mutex);
4670 + /* drop write access to mnt */
4671 + mnt_drop_write(new_path->mnt);
4675 + size = i_size_read(old_file->f_dentry->d_inode);
4676 + ret = do_cow_splice(old_file, new_file, size);
4677 + vxdprintk(VXD_CBIT(misc, 2), "do_splice_direct: %d", ret);
4679 + goto out_fput_both;
4680 + } else if (ret < size) {
4682 + goto out_fput_both;
4684 + struct inode *old_inode = old_dentry->d_inode;
4685 + struct inode *new_inode = new_dentry->d_inode;
4686 + struct iattr attr = {
4687 + .ia_uid = old_inode->i_uid,
4688 + .ia_gid = old_inode->i_gid,
4689 + .ia_valid = ATTR_UID | ATTR_GID
4692 + setattr_copy(new_inode, &attr);
4693 + mark_inode_dirty(new_inode);
4696 + /* lock rename mutex */
4697 + mutex_lock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4699 + /* drop out late */
4701 + if ((redo = d_unhashed(old_dentry)))
4704 + vxdprintk(VXD_CBIT(misc, 2),
4705 + "vfs_rename: [" VS_Q("%*s") ":%d] -> [" VS_Q("%*s") ":%d]",
4706 + new_dentry->d_name.len, new_dentry->d_name.name,
4707 + new_dentry->d_name.len,
4708 + old_dentry->d_name.len, old_dentry->d_name.name,
4709 + old_dentry->d_name.len);
4710 + ret = vfs_rename(dir_nd.path.dentry->d_inode, new_dentry,
4711 + old_dentry->d_parent->d_inode, old_dentry, NULL);
4712 + vxdprintk(VXD_CBIT(misc, 2), "vfs_rename: %d", ret);
4715 + mutex_unlock(&old_dentry->d_inode->i_sb->s_vfs_rename_mutex);
4718 + vxdprintk(VXD_CBIT(misc, 3),
4719 + "fput(new_file=%p[#%ld])", new_file,
4720 + atomic_long_read(&new_file->f_count));
4724 + vxdprintk(VXD_CBIT(misc, 3),
4725 + "fput(old_file=%p[#%ld])", old_file,
4726 + atomic_long_read(&old_file->f_count));
4730 + /* drop references from dir_nd.path */
4731 + path_put(&dir_nd.path);
4734 + /* unlock the inode mutex from kern_path_create() */
4735 + mutex_unlock(&dir->d_inode->i_mutex);
4737 + /* drop write access to mnt */
4738 + mnt_drop_write(new_path->mnt);
4744 + /* error path cleanup */
4745 + vfs_unlink(dir->d_inode, new_dentry, NULL);
4749 + goto out_rel_both;
4751 + /* lookup dentry once again
4752 + old_nd.path will be freed as old_path in out_rel_old */
4753 + ret = do_path_lookup(AT_FDCWD, pathname, LOOKUP_FOLLOW, &old_nd);
4755 + goto out_rel_both;
4757 + /* drop reference on new_dentry */
4759 + new_dentry = old_path->dentry;
4761 + vxdprintk(VXD_CBIT(misc, 2),
4762 + "do_path_lookup(redo): %p [" VS_Q("%.*s") ":%d]",
4764 + new_dentry->d_name.len, new_dentry->d_name.name,
4765 + new_dentry->d_name.len);
4769 + path_put(new_path);
4771 + path_put(old_path);
4777 + new_dentry = ERR_PTR(ret);
4779 + vxdprintk(VXD_CBIT(misc, 3),
4780 + "cow_break_link returning with %p", new_dentry);
4781 + return new_dentry;
4786 +int vx_info_mnt_namespace(struct mnt_namespace *ns, char *buffer)
4789 + struct vfsmount *vmnt;
4790 + char *pstr, *root;
4793 + pstr = kmalloc(PATH_MAX, GFP_KERNEL);
4797 + vmnt = &ns->root->mnt;
4799 + path.dentry = vmnt->mnt_root;
4800 + root = d_path(&path, pstr, PATH_MAX - 2);
4801 + length = sprintf(buffer + length,
4802 + "Namespace:\t%p [#%u]\n"
4803 + "RootPath:\t%s\n",
4804 + ns, atomic_read(&ns->count),
4810 /* get the link contents into pagecache */
4811 static char *page_getlink(struct dentry * dentry, struct page **ppage)
4813 @@ -4427,3 +4852,4 @@ EXPORT_SYMBOL(vfs_symlink);
4814 EXPORT_SYMBOL(vfs_unlink);
4815 EXPORT_SYMBOL(dentry_unhash);
4816 EXPORT_SYMBOL(generic_readlink);
4817 +EXPORT_SYMBOL(vx_info_mnt_namespace);
4818 diff -NurpP --minimal linux-3.13.10/fs/namespace.c linux-3.13.10-vs2.3.6.11/fs/namespace.c
4819 --- linux-3.13.10/fs/namespace.c 2014-04-17 01:12:32.000000000 +0000
4820 +++ linux-3.13.10-vs2.3.6.11/fs/namespace.c 2014-04-17 01:18:37.000000000 +0000
4822 #include <linux/proc_ns.h>
4823 #include <linux/magic.h>
4824 #include <linux/bootmem.h>
4825 +#include <linux/vs_base.h>
4826 +#include <linux/vs_context.h>
4827 +#include <linux/vs_tag.h>
4828 +#include <linux/vserver/space.h>
4829 +#include <linux/vserver/global.h>
4831 #include "internal.h"
4833 @@ -839,6 +844,10 @@ vfs_kern_mount(struct file_system_type *
4835 return ERR_PTR(-ENODEV);
4837 + if ((type->fs_flags & FS_BINARY_MOUNTDATA) &&
4838 + !vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT))
4839 + return ERR_PTR(-EPERM);
4841 mnt = alloc_vfsmnt(name);
4843 return ERR_PTR(-ENOMEM);
4844 @@ -899,6 +908,7 @@ static struct mount *clone_mnt(struct mo
4845 mnt->mnt.mnt_root = dget(root);
4846 mnt->mnt_mountpoint = mnt->mnt.mnt_root;
4847 mnt->mnt_parent = mnt;
4848 + mnt->mnt_tag = old->mnt_tag;
4850 list_add_tail(&mnt->mnt_instance, &sb->s_mounts);
4851 unlock_mount_hash();
4852 @@ -1369,7 +1379,8 @@ static int do_umount(struct mount *mnt,
4854 static inline bool may_mount(void)
4856 - return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
4857 + return vx_ns_capable(current->nsproxy->mnt_ns->user_ns,
4858 + CAP_SYS_ADMIN, VXC_SECURE_MOUNT);
4862 @@ -1785,6 +1796,7 @@ static int do_change_type(struct path *p
4866 + // mnt->mnt_flags = mnt_flags;
4869 for (m = mnt; m; m = (recurse ? next_mnt(m, mnt) : NULL))
4870 @@ -1813,12 +1825,14 @@ static bool has_locked_children(struct m
4871 * do loopback mount.
4873 static int do_loopback(struct path *path, const char *old_name,
4875 + vtag_t tag, unsigned long flags, int mnt_flags)
4877 struct path old_path;
4878 struct mount *mnt = NULL, *old, *parent;
4879 struct mountpoint *mp;
4880 + int recurse = flags & MS_REC;
4883 if (!old_name || !*old_name)
4885 err = kern_path(old_name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &old_path);
4886 @@ -1898,7 +1912,7 @@ static int change_mount_flags(struct vfs
4887 * on it - tough luck.
4889 static int do_remount(struct path *path, int flags, int mnt_flags,
4891 + void *data, vxid_t xid)
4894 struct super_block *sb = path->mnt->mnt_sb;
4895 @@ -2377,6 +2391,7 @@ long do_mount(const char *dev_name, cons
4902 if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
4903 @@ -2406,6 +2421,12 @@ long do_mount(const char *dev_name, cons
4904 if (!(flags & MS_NOATIME))
4905 mnt_flags |= MNT_RELATIME;
4907 + if (dx_parse_tag(data_page, &tag, 1, &mnt_flags, &flags)) {
4908 + /* FIXME: bind and re-mounts get the tag flag? */
4909 + if (flags & (MS_BIND|MS_REMOUNT))
4910 + flags |= MS_TAGID;
4913 /* Separate the per-mountpoint flags */
4914 if (flags & MS_NOSUID)
4915 mnt_flags |= MNT_NOSUID;
4916 @@ -2422,15 +2443,17 @@ long do_mount(const char *dev_name, cons
4917 if (flags & MS_RDONLY)
4918 mnt_flags |= MNT_READONLY;
4920 + if (!vx_capable(CAP_SYS_ADMIN, VXC_DEV_MOUNT))
4921 + mnt_flags |= MNT_NODEV;
4922 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | MS_BORN |
4923 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
4926 if (flags & MS_REMOUNT)
4927 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
4930 else if (flags & MS_BIND)
4931 - retval = do_loopback(&path, dev_name, flags & MS_REC);
4932 + retval = do_loopback(&path, dev_name, tag, flags, mnt_flags);
4933 else if (flags & (MS_SHARED | MS_PRIVATE | MS_SLAVE | MS_UNBINDABLE))
4934 retval = do_change_type(&path, flags);
4935 else if (flags & MS_MOVE)
4936 @@ -2546,6 +2569,7 @@ struct mnt_namespace *copy_mnt_ns(unsign
4937 p = next_mnt(p, old);
4940 + atomic_inc(&vs_global_mnt_ns);
4944 @@ -2727,9 +2751,10 @@ SYSCALL_DEFINE2(pivot_root, const char _
4945 new_mnt = real_mount(new.mnt);
4946 root_mnt = real_mount(root.mnt);
4947 old_mnt = real_mount(old.mnt);
4948 - if (IS_MNT_SHARED(old_mnt) ||
4949 + if ((IS_MNT_SHARED(old_mnt) ||
4950 IS_MNT_SHARED(new_mnt->mnt_parent) ||
4951 - IS_MNT_SHARED(root_mnt->mnt_parent))
4952 + IS_MNT_SHARED(root_mnt->mnt_parent)) &&
4953 + !vx_flags(VXF_STATE_SETUP, 0))
4955 if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4957 @@ -2859,6 +2884,7 @@ void put_mnt_ns(struct mnt_namespace *ns
4958 if (!atomic_dec_and_test(&ns->count))
4960 drop_collected_mounts(&ns->root->mnt);
4961 + atomic_dec(&vs_global_mnt_ns);
4965 diff -NurpP --minimal linux-3.13.10/fs/nfs/client.c linux-3.13.10-vs2.3.6.11/fs/nfs/client.c
4966 --- linux-3.13.10/fs/nfs/client.c 2014-01-22 20:39:06.000000000 +0000
4967 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/client.c 2014-01-31 20:38:03.000000000 +0000
4968 @@ -685,6 +685,9 @@ int nfs_init_server_rpcclient(struct nfs
4969 if (server->flags & NFS_MOUNT_SOFT)
4970 server->client->cl_softrtry = 1;
4972 + server->client->cl_tag = 0;
4973 + if (server->flags & NFS_MOUNT_TAGGED)
4974 + server->client->cl_tag = 1;
4977 EXPORT_SYMBOL_GPL(nfs_init_server_rpcclient);
4978 @@ -863,6 +866,10 @@ static void nfs_server_set_fsinfo(struct
4979 server->acdirmin = server->acdirmax = 0;
4982 + /* FIXME: needs fsinfo
4983 + if (server->flags & NFS_MOUNT_TAGGED)
4984 + sb->s_flags |= MS_TAGGED; */
4986 server->maxfilesize = fsinfo->maxfilesize;
4988 server->time_delta = fsinfo->time_delta;
4989 diff -NurpP --minimal linux-3.13.10/fs/nfs/dir.c linux-3.13.10-vs2.3.6.11/fs/nfs/dir.c
4990 --- linux-3.13.10/fs/nfs/dir.c 2014-04-17 01:12:32.000000000 +0000
4991 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/dir.c 2014-02-25 11:26:10.000000000 +0000
4993 #include <linux/sched.h>
4994 #include <linux/kmemleak.h>
4995 #include <linux/xattr.h>
4996 +#include <linux/vs_tag.h>
4998 #include "delegation.h"
5000 @@ -1319,6 +1320,7 @@ struct dentry *nfs_lookup(struct inode *
5001 /* Success: notify readdir to use READDIRPLUS */
5002 nfs_advise_use_readdirplus(dir);
5004 + dx_propagate_tag(nd, inode);
5006 res = d_materialise_unique(dentry, inode);
5008 diff -NurpP --minimal linux-3.13.10/fs/nfs/inode.c linux-3.13.10-vs2.3.6.11/fs/nfs/inode.c
5009 --- linux-3.13.10/fs/nfs/inode.c 2014-04-17 01:12:32.000000000 +0000
5010 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/inode.c 2014-03-12 15:51:07.000000000 +0000
5012 #include <linux/slab.h>
5013 #include <linux/compat.h>
5014 #include <linux/freezer.h>
5015 +#include <linux/vs_tag.h>
5017 #include <asm/uaccess.h>
5019 @@ -359,6 +360,8 @@ nfs_fhget(struct super_block *sb, struct
5020 if (inode->i_state & I_NEW) {
5021 struct nfs_inode *nfsi = NFS_I(inode);
5022 unsigned long now = jiffies;
5026 /* We set i_ino for the few things that still rely on it,
5027 * such as stat(2) */
5028 @@ -403,8 +406,8 @@ nfs_fhget(struct super_block *sb, struct
5029 inode->i_version = 0;
5032 - inode->i_uid = make_kuid(&init_user_ns, -2);
5033 - inode->i_gid = make_kgid(&init_user_ns, -2);
5034 + kuid = make_kuid(&init_user_ns, -2);
5035 + kgid = make_kgid(&init_user_ns, -2);
5036 inode->i_blocks = 0;
5037 memset(nfsi->cookieverf, 0, sizeof(nfsi->cookieverf));
5039 @@ -438,11 +441,11 @@ nfs_fhget(struct super_block *sb, struct
5040 else if (nfs_server_capable(inode, NFS_CAP_NLINK))
5041 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5042 if (fattr->valid & NFS_ATTR_FATTR_OWNER)
5043 - inode->i_uid = fattr->uid;
5044 + kuid = fattr->uid;
5045 else if (nfs_server_capable(inode, NFS_CAP_OWNER))
5046 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5047 if (fattr->valid & NFS_ATTR_FATTR_GROUP)
5048 - inode->i_gid = fattr->gid;
5049 + kgid = fattr->gid;
5050 else if (nfs_server_capable(inode, NFS_CAP_OWNER_GROUP))
5051 nfsi->cache_validity |= NFS_INO_INVALID_ATTR;
5052 if (fattr->valid & NFS_ATTR_FATTR_BLOCKS_USED)
5053 @@ -453,6 +456,10 @@ nfs_fhget(struct super_block *sb, struct
5055 inode->i_blocks = nfs_calc_block_size(fattr->du.nfs3.used);
5057 + inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5058 + inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5059 + inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, GLOBAL_ROOT_TAG);
5060 + /* maybe fattr->xid someday */
5062 nfs_setsecurity(inode, fattr, label);
5064 @@ -578,6 +585,8 @@ void nfs_setattr_update_inode(struct ino
5065 inode->i_uid = attr->ia_uid;
5066 if ((attr->ia_valid & ATTR_GID) != 0)
5067 inode->i_gid = attr->ia_gid;
5068 + if ((attr->ia_valid & ATTR_TAG) && IS_TAGGED(inode))
5069 + inode->i_tag = attr->ia_tag;
5070 NFS_I(inode)->cache_validity |= NFS_INO_INVALID_ACCESS|NFS_INO_INVALID_ACL;
5071 spin_unlock(&inode->i_lock);
5073 @@ -1092,7 +1101,9 @@ static int nfs_check_inode_attributes(st
5074 struct nfs_inode *nfsi = NFS_I(inode);
5075 loff_t cur_size, new_isize;
5076 unsigned long invalid = 0;
5082 if (nfs_have_delegated_attributes(inode))
5084 @@ -1117,13 +1128,18 @@ static int nfs_check_inode_attributes(st
5085 invalid |= NFS_INO_INVALID_ATTR|NFS_INO_REVAL_PAGECACHE;
5088 + kuid = INOTAG_KUID(DX_TAG(inode), fattr->uid, fattr->gid);
5089 + kgid = INOTAG_KGID(DX_TAG(inode), fattr->uid, fattr->gid);
5090 + ktag = INOTAG_KTAG(DX_TAG(inode), fattr->uid, fattr->gid, GLOBAL_ROOT_TAG);
5092 /* Have any file permissions changed? */
5093 if ((fattr->valid & NFS_ATTR_FATTR_MODE) && (inode->i_mode & S_IALLUGO) != (fattr->mode & S_IALLUGO))
5094 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5095 - if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, fattr->uid))
5096 + if ((fattr->valid & NFS_ATTR_FATTR_OWNER) && !uid_eq(inode->i_uid, kuid))
5097 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5098 - if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, fattr->gid))
5099 + if ((fattr->valid & NFS_ATTR_FATTR_GROUP) && !gid_eq(inode->i_gid, kgid))
5100 invalid |= NFS_INO_INVALID_ATTR | NFS_INO_INVALID_ACCESS | NFS_INO_INVALID_ACL;
5101 + /* maybe check for tag too? */
5103 /* Has the link count changed? */
5104 if ((fattr->valid & NFS_ATTR_FATTR_NLINK) && inode->i_nlink != fattr->nlink)
5105 @@ -1440,6 +1456,9 @@ static int nfs_update_inode(struct inode
5106 unsigned long invalid = 0;
5107 unsigned long now = jiffies;
5108 unsigned long save_cache_validity;
5113 dfprintk(VFS, "NFS: %s(%s/%ld fh_crc=0x%08x ct=%d info=0x%x)\n",
5114 __func__, inode->i_sb->s_id, inode->i_ino,
5115 @@ -1541,6 +1560,9 @@ static int nfs_update_inode(struct inode
5116 | NFS_INO_REVAL_PAGECACHE
5117 | NFS_INO_REVAL_FORCED);
5119 + kuid = TAGINO_KUID(DX_TAG(inode), inode->i_uid, inode->i_tag);
5120 + kgid = TAGINO_KGID(DX_TAG(inode), inode->i_gid, inode->i_tag);
5121 + ktag = TAGINO_KTAG(DX_TAG(inode), inode->i_tag);
5123 if (fattr->valid & NFS_ATTR_FATTR_ATIME)
5124 memcpy(&inode->i_atime, &fattr->atime, sizeof(inode->i_atime));
5125 @@ -1583,6 +1605,10 @@ static int nfs_update_inode(struct inode
5126 | NFS_INO_INVALID_ACL
5127 | NFS_INO_REVAL_FORCED);
5129 + inode->i_uid = INOTAG_KUID(DX_TAG(inode), kuid, kgid);
5130 + inode->i_gid = INOTAG_KGID(DX_TAG(inode), kuid, kgid);
5131 + inode->i_tag = INOTAG_KTAG(DX_TAG(inode), kuid, kgid, ktag);
5133 if (fattr->valid & NFS_ATTR_FATTR_NLINK) {
5134 if (inode->i_nlink != fattr->nlink) {
5135 invalid |= NFS_INO_INVALID_ATTR;
5136 diff -NurpP --minimal linux-3.13.10/fs/nfs/nfs3xdr.c linux-3.13.10-vs2.3.6.11/fs/nfs/nfs3xdr.c
5137 --- linux-3.13.10/fs/nfs/nfs3xdr.c 2013-05-31 13:45:24.000000000 +0000
5138 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/nfs3xdr.c 2014-01-31 20:38:03.000000000 +0000
5140 #include <linux/nfs3.h>
5141 #include <linux/nfs_fs.h>
5142 #include <linux/nfsacl.h>
5143 +#include <linux/vs_tag.h>
5144 #include "internal.h"
5146 #define NFSDBG_FACILITY NFSDBG_XDR
5147 @@ -558,7 +559,8 @@ static __be32 *xdr_decode_nfstime3(__be3
5151 -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr)
5152 +static void encode_sattr3(struct xdr_stream *xdr,
5153 + const struct iattr *attr, int tag)
5157 @@ -590,15 +592,19 @@ static void encode_sattr3(struct xdr_str
5161 - if (attr->ia_valid & ATTR_UID) {
5162 + if (attr->ia_valid & ATTR_UID ||
5163 + (tag && (attr->ia_valid & ATTR_TAG))) {
5165 - *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid));
5166 + *p++ = cpu_to_be32(from_kuid(&init_user_ns,
5167 + TAGINO_KUID(tag, attr->ia_uid, attr->ia_tag)));
5171 - if (attr->ia_valid & ATTR_GID) {
5172 + if (attr->ia_valid & ATTR_GID ||
5173 + (tag && (attr->ia_valid & ATTR_TAG))) {
5175 - *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid));
5176 + *p++ = cpu_to_be32(from_kgid(&init_user_ns,
5177 + TAGINO_KGID(tag, attr->ia_gid, attr->ia_tag)));
5181 @@ -887,7 +893,7 @@ static void nfs3_xdr_enc_setattr3args(st
5182 const struct nfs3_sattrargs *args)
5184 encode_nfs_fh3(xdr, args->fh);
5185 - encode_sattr3(xdr, args->sattr);
5186 + encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5187 encode_sattrguard3(xdr, args);
5190 @@ -1037,13 +1043,13 @@ static void nfs3_xdr_enc_write3args(stru
5193 static void encode_createhow3(struct xdr_stream *xdr,
5194 - const struct nfs3_createargs *args)
5195 + const struct nfs3_createargs *args, int tag)
5197 encode_uint32(xdr, args->createmode);
5198 switch (args->createmode) {
5199 case NFS3_CREATE_UNCHECKED:
5200 case NFS3_CREATE_GUARDED:
5201 - encode_sattr3(xdr, args->sattr);
5202 + encode_sattr3(xdr, args->sattr, tag);
5204 case NFS3_CREATE_EXCLUSIVE:
5205 encode_createverf3(xdr, args->verifier);
5206 @@ -1058,7 +1064,7 @@ static void nfs3_xdr_enc_create3args(str
5207 const struct nfs3_createargs *args)
5209 encode_diropargs3(xdr, args->fh, args->name, args->len);
5210 - encode_createhow3(xdr, args);
5211 + encode_createhow3(xdr, args, req->rq_task->tk_client->cl_tag);
5215 @@ -1074,7 +1080,7 @@ static void nfs3_xdr_enc_mkdir3args(stru
5216 const struct nfs3_mkdirargs *args)
5218 encode_diropargs3(xdr, args->fh, args->name, args->len);
5219 - encode_sattr3(xdr, args->sattr);
5220 + encode_sattr3(xdr, args->sattr, req->rq_task->tk_client->cl_tag);
5224 @@ -1091,9 +1097,9 @@ static void nfs3_xdr_enc_mkdir3args(stru
5227 static void encode_symlinkdata3(struct xdr_stream *xdr,
5228 - const struct nfs3_symlinkargs *args)
5229 + const struct nfs3_symlinkargs *args, int tag)
5231 - encode_sattr3(xdr, args->sattr);
5232 + encode_sattr3(xdr, args->sattr, tag);
5233 encode_nfspath3(xdr, args->pages, args->pathlen);
5236 @@ -1102,7 +1108,7 @@ static void nfs3_xdr_enc_symlink3args(st
5237 const struct nfs3_symlinkargs *args)
5239 encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
5240 - encode_symlinkdata3(xdr, args);
5241 + encode_symlinkdata3(xdr, args, req->rq_task->tk_client->cl_tag);
5245 @@ -1130,24 +1136,24 @@ static void nfs3_xdr_enc_symlink3args(st
5248 static void encode_devicedata3(struct xdr_stream *xdr,
5249 - const struct nfs3_mknodargs *args)
5250 + const struct nfs3_mknodargs *args, int tag)
5252 - encode_sattr3(xdr, args->sattr);
5253 + encode_sattr3(xdr, args->sattr, tag);
5254 encode_specdata3(xdr, args->rdev);
5257 static void encode_mknoddata3(struct xdr_stream *xdr,
5258 - const struct nfs3_mknodargs *args)
5259 + const struct nfs3_mknodargs *args, int tag)
5261 encode_ftype3(xdr, args->type);
5262 switch (args->type) {
5265 - encode_devicedata3(xdr, args);
5266 + encode_devicedata3(xdr, args, tag);
5270 - encode_sattr3(xdr, args->sattr);
5271 + encode_sattr3(xdr, args->sattr, tag);
5275 @@ -1162,7 +1168,7 @@ static void nfs3_xdr_enc_mknod3args(stru
5276 const struct nfs3_mknodargs *args)
5278 encode_diropargs3(xdr, args->fh, args->name, args->len);
5279 - encode_mknoddata3(xdr, args);
5280 + encode_mknoddata3(xdr, args, req->rq_task->tk_client->cl_tag);
5284 diff -NurpP --minimal linux-3.13.10/fs/nfs/super.c linux-3.13.10-vs2.3.6.11/fs/nfs/super.c
5285 --- linux-3.13.10/fs/nfs/super.c 2014-01-22 20:39:06.000000000 +0000
5286 +++ linux-3.13.10-vs2.3.6.11/fs/nfs/super.c 2014-01-31 20:38:03.000000000 +0000
5288 #include <linux/parser.h>
5289 #include <linux/nsproxy.h>
5290 #include <linux/rcupdate.h>
5291 +#include <linux/vs_tag.h>
5293 #include <asm/uaccess.h>
5295 @@ -103,6 +104,7 @@ enum {
5301 /* Mount options that take string arguments */
5303 @@ -115,6 +117,9 @@ enum {
5304 /* Special mount options */
5305 Opt_userspace, Opt_deprecated, Opt_sloppy,
5307 + /* Linux-VServer tagging options */
5308 + Opt_tag, Opt_notag,
5313 @@ -184,6 +189,10 @@ static const match_table_t nfs_mount_opt
5314 { Opt_fscache_uniq, "fsc=%s" },
5315 { Opt_local_lock, "local_lock=%s" },
5317 + { Opt_tag, "tag" },
5318 + { Opt_notag, "notag" },
5319 + { Opt_tagid, "tagid=%u" },
5321 /* The following needs to be listed after all other options */
5322 { Opt_nfsvers, "v%s" },
5324 @@ -638,6 +647,7 @@ static void nfs_show_mount_options(struc
5325 { NFS_MOUNT_NORDIRPLUS, ",nordirplus", "" },
5326 { NFS_MOUNT_UNSHARED, ",nosharecache", "" },
5327 { NFS_MOUNT_NORESVPORT, ",noresvport", "" },
5328 + { NFS_MOUNT_TAGGED, ",tag", "" },
5331 const struct proc_nfs_info *nfs_infop;
5332 @@ -1321,6 +1331,14 @@ static int nfs_parse_mount_options(char
5333 case Opt_nomigration:
5334 mnt->options &= NFS_OPTION_MIGRATION;
5336 +#ifndef CONFIG_TAGGING_NONE
5338 + mnt->flags |= NFS_MOUNT_TAGGED;
5341 + mnt->flags &= ~NFS_MOUNT_TAGGED;
5346 * options that take numeric values
5347 @@ -1407,6 +1425,12 @@ static int nfs_parse_mount_options(char
5348 goto out_invalid_value;
5349 mnt->minorversion = option;
5351 +#ifdef CONFIG_PROPAGATE
5354 + nfs_data.flags |= NFS_MOUNT_TAGGED;
5359 * options that take text values
5360 diff -NurpP --minimal linux-3.13.10/fs/nfsd/auth.c linux-3.13.10-vs2.3.6.11/fs/nfsd/auth.c
5361 --- linux-3.13.10/fs/nfsd/auth.c 2013-05-31 13:45:24.000000000 +0000
5362 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/auth.c 2014-01-31 20:38:03.000000000 +0000
5365 #include <linux/sched.h>
5366 #include <linux/user_namespace.h>
5367 +#include <linux/vs_tag.h>
5371 @@ -37,6 +38,9 @@ int nfsd_setuser(struct svc_rqst *rqstp,
5373 new->fsuid = rqstp->rq_cred.cr_uid;
5374 new->fsgid = rqstp->rq_cred.cr_gid;
5375 + /* FIXME: this desperately needs a tag :)
5376 + new->xid = (vxid_t)INOTAG_TAG(DX_TAG_NFSD, cred.cr_uid, cred.cr_gid, 0);
5379 rqgi = rqstp->rq_cred.cr_group_info;
5381 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfs3xdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs3xdr.c
5382 --- linux-3.13.10/fs/nfsd/nfs3xdr.c 2013-05-31 13:45:24.000000000 +0000
5383 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs3xdr.c 2014-01-31 20:38:03.000000000 +0000
5386 #include <linux/namei.h>
5387 #include <linux/sunrpc/svc_xprt.h>
5388 +#include <linux/vs_tag.h>
5392 @@ -98,6 +99,8 @@ static __be32 *
5393 decode_sattr3(__be32 *p, struct iattr *iap)
5396 + kuid_t kuid = GLOBAL_ROOT_UID;
5397 + kgid_t kgid = GLOBAL_ROOT_GID;
5401 @@ -106,15 +109,18 @@ decode_sattr3(__be32 *p, struct iattr *i
5402 iap->ia_mode = ntohl(*p++);
5405 - iap->ia_uid = make_kuid(&init_user_ns, ntohl(*p++));
5406 + kuid = make_kuid(&init_user_ns, ntohl(*p++));
5407 if (uid_valid(iap->ia_uid))
5408 iap->ia_valid |= ATTR_UID;
5411 - iap->ia_gid = make_kgid(&init_user_ns, ntohl(*p++));
5412 + kgid = make_kgid(&init_user_ns, ntohl(*p++));
5413 if (gid_valid(iap->ia_gid))
5414 iap->ia_valid |= ATTR_GID;
5416 + iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5417 + iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5418 + iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5422 @@ -170,8 +176,12 @@ encode_fattr3(struct svc_rqst *rqstp, __
5423 *p++ = htonl(nfs3_ftypes[(stat->mode & S_IFMT) >> 12]);
5424 *p++ = htonl((u32) stat->mode);
5425 *p++ = htonl((u32) stat->nlink);
5426 - *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5427 - *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5428 + *p++ = htonl((u32) from_kuid(&init_user_ns,
5429 + TAGINO_KUID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5430 + stat->uid, stat->tag)));
5431 + *p++ = htonl((u32) from_kgid(&init_user_ns,
5432 + TAGINO_KGID(0 /* FIXME: DX_TAG(dentry->d_inode) */,
5433 + stat->gid, stat->tag)));
5434 if (S_ISLNK(stat->mode) && stat->size > NFS3_MAXPATHLEN) {
5435 p = xdr_encode_hyper(p, (u64) NFS3_MAXPATHLEN);
5437 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfs4xdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs4xdr.c
5438 --- linux-3.13.10/fs/nfsd/nfs4xdr.c 2014-01-22 20:39:06.000000000 +0000
5439 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfs4xdr.c 2014-01-31 20:38:03.000000000 +0000
5441 #include <linux/utsname.h>
5442 #include <linux/pagemap.h>
5443 #include <linux/sunrpc/svcauth_gss.h>
5444 +#include <linux/vs_tag.h>
5448 @@ -2430,10 +2431,14 @@ out_acl:
5449 WRITE32(stat.nlink);
5451 if (bmval1 & FATTR4_WORD1_OWNER) {
5452 - status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
5453 + status = nfsd4_encode_user(rqstp,
5454 + TAGINO_KUID(DX_TAG(dentry->d_inode),
5455 + stat.uid, stat.tag), &p, &buflen);
5459 if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
5460 - status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
5461 + status = nfsd4_encode_group(rqstp,
5462 + TAGINO_KGID(DX_TAG(dentry->d_inode),
5463 + stat.gid, stat.tag), &p, &buflen);
5467 diff -NurpP --minimal linux-3.13.10/fs/nfsd/nfsxdr.c linux-3.13.10-vs2.3.6.11/fs/nfsd/nfsxdr.c
5468 --- linux-3.13.10/fs/nfsd/nfsxdr.c 2013-05-31 13:45:24.000000000 +0000
5469 +++ linux-3.13.10-vs2.3.6.11/fs/nfsd/nfsxdr.c 2014-01-31 20:38:03.000000000 +0000
5474 +#include <linux/vs_tag.h>
5476 #define NFSDDBG_FACILITY NFSDDBG_XDR
5478 @@ -89,6 +90,8 @@ static __be32 *
5479 decode_sattr(__be32 *p, struct iattr *iap)
5482 + kuid_t kuid = GLOBAL_ROOT_UID;
5483 + kgid_t kgid = GLOBAL_ROOT_GID;
5487 @@ -101,15 +104,18 @@ decode_sattr(__be32 *p, struct iattr *ia
5490 if ((tmp = ntohl(*p++)) != (u32)-1) {
5491 - iap->ia_uid = make_kuid(&init_user_ns, tmp);
5492 + kuid = make_kuid(&init_user_ns, tmp);
5493 if (uid_valid(iap->ia_uid))
5494 iap->ia_valid |= ATTR_UID;
5496 if ((tmp = ntohl(*p++)) != (u32)-1) {
5497 - iap->ia_gid = make_kgid(&init_user_ns, tmp);
5498 + kgid = make_kgid(&init_user_ns, tmp);
5499 if (gid_valid(iap->ia_gid))
5500 iap->ia_valid |= ATTR_GID;
5502 + iap->ia_uid = INOTAG_KUID(DX_TAG_NFSD, kuid, kgid);
5503 + iap->ia_gid = INOTAG_KGID(DX_TAG_NFSD, kuid, kgid);
5504 + iap->ia_tag = INOTAG_KTAG(DX_TAG_NFSD, kuid, kgid, GLOBAL_ROOT_TAG);
5505 if ((tmp = ntohl(*p++)) != (u32)-1) {
5506 iap->ia_valid |= ATTR_SIZE;
5508 @@ -154,8 +160,10 @@ encode_fattr(struct svc_rqst *rqstp, __b
5509 *p++ = htonl(nfs_ftypes[type >> 12]);
5510 *p++ = htonl((u32) stat->mode);
5511 *p++ = htonl((u32) stat->nlink);
5512 - *p++ = htonl((u32) from_kuid(&init_user_ns, stat->uid));
5513 - *p++ = htonl((u32) from_kgid(&init_user_ns, stat->gid));
5514 + *p++ = htonl((u32) from_kuid(&init_user_ns,
5515 + TAGINO_KUID(DX_TAG(dentry->d_inode), stat->uid, stat->tag)));
5516 + *p++ = htonl((u32) from_kgid(&init_user_ns,
5517 + TAGINO_KGID(DX_TAG(dentry->d_inode), stat->gid, stat->tag)));
5519 if (S_ISLNK(type) && stat->size > NFS_MAXPATHLEN) {
5520 *p++ = htonl(NFS_MAXPATHLEN);
5521 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/dlmglue.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.c
5522 --- linux-3.13.10/fs/ocfs2/dlmglue.c 2014-01-22 20:39:07.000000000 +0000
5523 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.c 2014-01-31 20:38:03.000000000 +0000
5524 @@ -2047,6 +2047,7 @@ static void __ocfs2_stuff_meta_lvb(struc
5525 lvb->lvb_iclusters = cpu_to_be32(oi->ip_clusters);
5526 lvb->lvb_iuid = cpu_to_be32(i_uid_read(inode));
5527 lvb->lvb_igid = cpu_to_be32(i_gid_read(inode));
5528 + lvb->lvb_itag = cpu_to_be16(i_tag_read(inode));
5529 lvb->lvb_imode = cpu_to_be16(inode->i_mode);
5530 lvb->lvb_inlink = cpu_to_be16(inode->i_nlink);
5531 lvb->lvb_iatime_packed =
5532 @@ -2097,6 +2098,7 @@ static void ocfs2_refresh_inode_from_lvb
5534 i_uid_write(inode, be32_to_cpu(lvb->lvb_iuid));
5535 i_gid_write(inode, be32_to_cpu(lvb->lvb_igid));
5536 + i_tag_write(inode, be16_to_cpu(lvb->lvb_itag));
5537 inode->i_mode = be16_to_cpu(lvb->lvb_imode);
5538 set_nlink(inode, be16_to_cpu(lvb->lvb_inlink));
5539 ocfs2_unpack_timespec(&inode->i_atime,
5540 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/dlmglue.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.h
5541 --- linux-3.13.10/fs/ocfs2/dlmglue.h 2012-12-11 03:30:57.000000000 +0000
5542 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/dlmglue.h 2014-01-31 20:38:03.000000000 +0000
5543 @@ -46,7 +46,8 @@ struct ocfs2_meta_lvb {
5546 __be32 lvb_igeneration;
5547 - __be32 lvb_reserved2;
5549 + __be16 lvb_reserved2;
5552 #define OCFS2_QINFO_LVB_VERSION 1
5553 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/file.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/file.c
5554 --- linux-3.13.10/fs/ocfs2/file.c 2014-04-17 01:12:32.000000000 +0000
5555 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/file.c 2014-04-17 01:17:10.000000000 +0000
5556 @@ -1119,7 +1119,7 @@ int ocfs2_setattr(struct dentry *dentry,
5557 attr->ia_valid &= ~ATTR_SIZE;
5559 #define OCFS2_VALID_ATTRS (ATTR_ATIME | ATTR_MTIME | ATTR_CTIME | ATTR_SIZE \
5560 - | ATTR_GID | ATTR_UID | ATTR_MODE)
5561 + | ATTR_GID | ATTR_UID | ATTR_TAG | ATTR_MODE)
5562 if (!(attr->ia_valid & OCFS2_VALID_ATTRS))
5565 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/inode.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.c
5566 --- linux-3.13.10/fs/ocfs2/inode.c 2014-01-22 20:39:07.000000000 +0000
5567 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.c 2014-01-31 20:38:03.000000000 +0000
5569 #include <linux/highmem.h>
5570 #include <linux/pagemap.h>
5571 #include <linux/quotaops.h>
5572 +#include <linux/vs_tag.h>
5574 #include <asm/byteorder.h>
5576 @@ -78,11 +79,13 @@ void ocfs2_set_inode_flags(struct inode
5578 unsigned int flags = OCFS2_I(inode)->ip_attr;
5580 - inode->i_flags &= ~(S_IMMUTABLE |
5581 + inode->i_flags &= ~(S_IMMUTABLE | S_IXUNLINK |
5582 S_SYNC | S_APPEND | S_NOATIME | S_DIRSYNC);
5584 if (flags & OCFS2_IMMUTABLE_FL)
5585 inode->i_flags |= S_IMMUTABLE;
5586 + if (flags & OCFS2_IXUNLINK_FL)
5587 + inode->i_flags |= S_IXUNLINK;
5589 if (flags & OCFS2_SYNC_FL)
5590 inode->i_flags |= S_SYNC;
5591 @@ -92,25 +95,44 @@ void ocfs2_set_inode_flags(struct inode
5592 inode->i_flags |= S_NOATIME;
5593 if (flags & OCFS2_DIRSYNC_FL)
5594 inode->i_flags |= S_DIRSYNC;
5596 + inode->i_vflags &= ~(V_BARRIER | V_COW);
5598 + if (flags & OCFS2_BARRIER_FL)
5599 + inode->i_vflags |= V_BARRIER;
5600 + if (flags & OCFS2_COW_FL)
5601 + inode->i_vflags |= V_COW;
5604 /* Propagate flags from i_flags to OCFS2_I(inode)->ip_attr */
5605 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi)
5607 unsigned int flags = oi->vfs_inode.i_flags;
5608 + unsigned int vflags = oi->vfs_inode.i_vflags;
5610 + oi->ip_attr &= ~(OCFS2_SYNC_FL | OCFS2_APPEND_FL |
5611 + OCFS2_IMMUTABLE_FL | OCFS2_IXUNLINK_FL |
5612 + OCFS2_NOATIME_FL | OCFS2_DIRSYNC_FL |
5613 + OCFS2_BARRIER_FL | OCFS2_COW_FL);
5615 + if (flags & S_IMMUTABLE)
5616 + oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5617 + if (flags & S_IXUNLINK)
5618 + oi->ip_attr |= OCFS2_IXUNLINK_FL;
5620 - oi->ip_attr &= ~(OCFS2_SYNC_FL|OCFS2_APPEND_FL|
5621 - OCFS2_IMMUTABLE_FL|OCFS2_NOATIME_FL|OCFS2_DIRSYNC_FL);
5623 oi->ip_attr |= OCFS2_SYNC_FL;
5624 if (flags & S_APPEND)
5625 oi->ip_attr |= OCFS2_APPEND_FL;
5626 - if (flags & S_IMMUTABLE)
5627 - oi->ip_attr |= OCFS2_IMMUTABLE_FL;
5628 if (flags & S_NOATIME)
5629 oi->ip_attr |= OCFS2_NOATIME_FL;
5630 if (flags & S_DIRSYNC)
5631 oi->ip_attr |= OCFS2_DIRSYNC_FL;
5633 + if (vflags & V_BARRIER)
5634 + oi->ip_attr |= OCFS2_BARRIER_FL;
5635 + if (vflags & V_COW)
5636 + oi->ip_attr |= OCFS2_COW_FL;
5639 struct inode *ocfs2_ilookup(struct super_block *sb, u64 blkno)
5640 @@ -241,6 +263,8 @@ void ocfs2_populate_inode(struct inode *
5641 struct super_block *sb;
5642 struct ocfs2_super *osb;
5649 @@ -269,8 +293,12 @@ void ocfs2_populate_inode(struct inode *
5650 inode->i_generation = le32_to_cpu(fe->i_generation);
5651 inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
5652 inode->i_mode = le16_to_cpu(fe->i_mode);
5653 - i_uid_write(inode, le32_to_cpu(fe->i_uid));
5654 - i_gid_write(inode, le32_to_cpu(fe->i_gid));
5655 + uid = le32_to_cpu(fe->i_uid);
5656 + gid = le32_to_cpu(fe->i_gid);
5657 + i_uid_write(inode, INOTAG_UID(DX_TAG(inode), uid, gid));
5658 + i_gid_write(inode, INOTAG_GID(DX_TAG(inode), uid, gid));
5659 + i_tag_write(inode, INOTAG_TAG(DX_TAG(inode), uid, gid,
5660 + /* le16_to_cpu(raw_inode->i_raw_tag) */ 0));
5662 /* Fast symlinks will have i_size but no allocated clusters. */
5663 if (S_ISLNK(inode->i_mode) && !fe->i_clusters) {
5664 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/inode.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.h
5665 --- linux-3.13.10/fs/ocfs2/inode.h 2013-07-14 17:01:29.000000000 +0000
5666 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/inode.h 2014-01-31 20:38:03.000000000 +0000
5667 @@ -152,6 +152,7 @@ struct buffer_head *ocfs2_bread(struct i
5669 void ocfs2_set_inode_flags(struct inode *inode);
5670 void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
5671 +int ocfs2_sync_flags(struct inode *inode, int, int);
5673 static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
5675 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ioctl.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/ioctl.c
5676 --- linux-3.13.10/fs/ocfs2/ioctl.c 2013-11-25 15:47:00.000000000 +0000
5677 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ioctl.c 2014-01-31 20:38:03.000000000 +0000
5678 @@ -76,7 +76,41 @@ static int ocfs2_get_inode_attr(struct i
5682 -static int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5683 +int ocfs2_sync_flags(struct inode *inode, int flags, int vflags)
5685 + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
5686 + struct buffer_head *bh = NULL;
5687 + handle_t *handle = NULL;
5690 + status = ocfs2_inode_lock(inode, &bh, 1);
5692 + mlog_errno(status);
5695 + handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5696 + if (IS_ERR(handle)) {
5697 + status = PTR_ERR(handle);
5698 + mlog_errno(status);
5702 + inode->i_flags = flags;
5703 + inode->i_vflags = vflags;
5704 + ocfs2_get_inode_flags(OCFS2_I(inode));
5706 + status = ocfs2_mark_inode_dirty(handle, inode, bh);
5708 + mlog_errno(status);
5710 + ocfs2_commit_trans(osb, handle);
5712 + ocfs2_inode_unlock(inode, 1);
5717 +int ocfs2_set_inode_attr(struct inode *inode, unsigned flags,
5720 struct ocfs2_inode_info *ocfs2_inode = OCFS2_I(inode);
5721 @@ -116,6 +150,11 @@ static int ocfs2_set_inode_attr(struct i
5725 + if (IS_BARRIER(inode)) {
5726 + vxwprintk_task(1, "messing with the barrier.");
5730 handle = ocfs2_start_trans(osb, OCFS2_INODE_UPDATE_CREDITS);
5731 if (IS_ERR(handle)) {
5732 status = PTR_ERR(handle);
5733 @@ -881,6 +920,7 @@ bail:
5738 long ocfs2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
5740 struct inode *inode = file_inode(filp);
5741 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/namei.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/namei.c
5742 --- linux-3.13.10/fs/ocfs2/namei.c 2014-01-22 20:39:07.000000000 +0000
5743 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/namei.c 2014-01-31 20:38:03.000000000 +0000
5745 #include <linux/slab.h>
5746 #include <linux/highmem.h>
5747 #include <linux/quotaops.h>
5748 +#include <linux/vs_tag.h>
5750 #include <cluster/masklog.h>
5752 @@ -475,6 +476,7 @@ static int __ocfs2_mknod_locked(struct i
5753 struct ocfs2_dinode *fe = NULL;
5754 struct ocfs2_extent_list *fel;
5760 @@ -512,8 +514,13 @@ static int __ocfs2_mknod_locked(struct i
5761 fe->i_suballoc_loc = cpu_to_le64(suballoc_loc);
5762 fe->i_suballoc_bit = cpu_to_le16(suballoc_bit);
5763 fe->i_suballoc_slot = cpu_to_le16(inode_ac->ac_alloc_slot);
5764 - fe->i_uid = cpu_to_le32(i_uid_read(inode));
5765 - fe->i_gid = cpu_to_le32(i_gid_read(inode));
5767 + ktag = make_ktag(&init_user_ns, dx_current_fstag(osb->sb));
5768 + fe->i_uid = cpu_to_le32(from_kuid(&init_user_ns,
5769 + TAGINO_KUID(DX_TAG(inode), inode->i_uid, ktag)));
5770 + fe->i_gid = cpu_to_le32(from_kgid(&init_user_ns,
5771 + TAGINO_KGID(DX_TAG(inode), inode->i_gid, ktag)));
5772 + inode->i_tag = ktag; /* is this correct? */
5773 fe->i_mode = cpu_to_le16(inode->i_mode);
5774 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
5775 fe->id1.dev1.i_rdev = cpu_to_le64(huge_encode_dev(dev));
5776 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ocfs2.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2.h
5777 --- linux-3.13.10/fs/ocfs2/ocfs2.h 2013-11-25 15:45:04.000000000 +0000
5778 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2.h 2014-01-31 20:38:03.000000000 +0000
5779 @@ -272,6 +272,7 @@ enum ocfs2_mount_options
5781 OCFS2_MOUNT_HB_NONE = 1 << 13, /* No heartbeat */
5782 OCFS2_MOUNT_HB_GLOBAL = 1 << 14, /* Global heartbeat */
5783 + OCFS2_MOUNT_TAGGED = 1 << 15, /* use tagging */
5786 #define OCFS2_OSB_SOFT_RO 0x0001
5787 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/ocfs2_fs.h linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2_fs.h
5788 --- linux-3.13.10/fs/ocfs2/ocfs2_fs.h 2012-12-11 03:30:57.000000000 +0000
5789 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/ocfs2_fs.h 2014-01-31 20:38:03.000000000 +0000
5790 @@ -266,6 +266,11 @@
5791 #define OCFS2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
5792 #define OCFS2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
5794 +#define OCFS2_IXUNLINK_FL FS_IXUNLINK_FL /* Immutable invert on unlink */
5796 +#define OCFS2_BARRIER_FL FS_BARRIER_FL /* Barrier for chroot() */
5797 +#define OCFS2_COW_FL FS_COW_FL /* Copy on Write marker */
5799 #define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
5800 #define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
5802 diff -NurpP --minimal linux-3.13.10/fs/ocfs2/super.c linux-3.13.10-vs2.3.6.11/fs/ocfs2/super.c
5803 --- linux-3.13.10/fs/ocfs2/super.c 2014-01-22 20:39:07.000000000 +0000
5804 +++ linux-3.13.10-vs2.3.6.11/fs/ocfs2/super.c 2014-01-31 20:38:03.000000000 +0000
5805 @@ -185,6 +185,7 @@ enum {
5809 + Opt_tag, Opt_notag, Opt_tagid,
5813 @@ -216,6 +217,9 @@ static const match_table_t tokens = {
5814 {Opt_coherency_full, "coherency=full"},
5815 {Opt_resv_level, "resv_level=%u"},
5816 {Opt_dir_resv_level, "dir_resv_level=%u"},
5818 + {Opt_notag, "notag"},
5819 + {Opt_tagid, "tagid=%u"},
5823 @@ -661,6 +665,13 @@ static int ocfs2_remount(struct super_bl
5827 + if ((osb->s_mount_opt & OCFS2_MOUNT_TAGGED) !=
5828 + (parsed_options.mount_opt & OCFS2_MOUNT_TAGGED)) {
5830 + mlog(ML_ERROR, "Cannot change tagging on remount\n");
5834 /* We're going to/from readonly mode. */
5835 if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
5836 /* Disable quota accounting before remounting RO */
5837 @@ -1176,6 +1187,9 @@ static int ocfs2_fill_super(struct super
5839 ocfs2_complete_mount_recovery(osb);
5841 + if (osb->s_mount_opt & OCFS2_MOUNT_TAGGED)
5842 + sb->s_flags |= MS_TAGGED;
5844 if (ocfs2_mount_local(osb))
5845 snprintf(nodestr, sizeof(nodestr), "local");
5847 @@ -1503,6 +1517,20 @@ static int ocfs2_parse_options(struct su
5848 option < OCFS2_MAX_RESV_LEVEL)
5849 mopt->dir_resv_level = option;
5851 +#ifndef CONFIG_TAGGING_NONE
5853 + mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5856 + mopt->mount_opt &= ~OCFS2_MOUNT_TAGGED;
5859 +#ifdef CONFIG_PROPAGATE
5862 + mopt->mount_opt |= OCFS2_MOUNT_TAGGED;
5867 "Unrecognized mount option \"%s\" "
5868 diff -NurpP --minimal linux-3.13.10/fs/open.c linux-3.13.10-vs2.3.6.11/fs/open.c
5869 --- linux-3.13.10/fs/open.c 2014-01-22 20:39:07.000000000 +0000
5870 +++ linux-3.13.10-vs2.3.6.11/fs/open.c 2014-01-31 20:38:03.000000000 +0000
5872 #include <linux/ima.h>
5873 #include <linux/dnotify.h>
5874 #include <linux/compat.h>
5875 +#include <linux/vs_base.h>
5876 +#include <linux/vs_limit.h>
5877 +#include <linux/vs_tag.h>
5878 +#include <linux/vs_cowbl.h>
5879 +#include <linux/vserver/dlimit.h>
5881 #include "internal.h"
5883 @@ -68,6 +73,11 @@ long vfs_truncate(struct path *path, lof
5884 struct inode *inode;
5887 +#ifdef CONFIG_VSERVER_COWBL
5888 + error = cow_check_and_break(path);
5892 inode = path->dentry->d_inode;
5894 /* For directories it's -EISDIR, for other non-regulars - -EINVAL */
5895 @@ -511,6 +521,13 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, cons
5896 unsigned int lookup_flags = LOOKUP_FOLLOW;
5898 error = user_path_at(dfd, filename, lookup_flags, &path);
5899 +#ifdef CONFIG_VSERVER_COWBL
5901 + error = cow_check_and_break(&path);
5907 error = chmod_common(&path, mode);
5909 @@ -544,13 +561,15 @@ static int chown_common(struct path *pat
5910 if (!uid_valid(uid))
5912 newattrs.ia_valid |= ATTR_UID;
5913 - newattrs.ia_uid = uid;
5914 + newattrs.ia_uid = make_kuid(&init_user_ns,
5915 + dx_map_uid(user));
5917 if (group != (gid_t) -1) {
5918 if (!gid_valid(gid))
5920 newattrs.ia_valid |= ATTR_GID;
5921 - newattrs.ia_gid = gid;
5922 + newattrs.ia_gid = make_kgid(&init_user_ns,
5923 + dx_map_gid(group));
5925 if (!S_ISDIR(inode->i_mode))
5926 newattrs.ia_valid |=
5927 @@ -589,6 +608,18 @@ retry:
5928 error = mnt_want_write(path.mnt);
5931 +#ifdef CONFIG_VSERVER_COWBL
5932 + error = cow_check_and_break(&path);
5935 +#ifdef CONFIG_VSERVER_COWBL
5936 + error = cow_check_and_break(&path);
5939 +#ifdef CONFIG_VSERVER_COWBL
5940 + error = cow_check_and_break(&path);
5943 error = chown_common(&path, user, group);
5944 mnt_drop_write(path.mnt);
5946 diff -NurpP --minimal linux-3.13.10/fs/proc/array.c linux-3.13.10-vs2.3.6.11/fs/proc/array.c
5947 --- linux-3.13.10/fs/proc/array.c 2014-01-22 20:39:07.000000000 +0000
5948 +++ linux-3.13.10-vs2.3.6.11/fs/proc/array.c 2014-02-01 01:44:54.000000000 +0000
5950 #include <linux/ptrace.h>
5951 #include <linux/tracehook.h>
5952 #include <linux/user_namespace.h>
5953 +#include <linux/vs_context.h>
5954 +#include <linux/vs_network.h>
5956 #include <asm/pgtable.h>
5957 #include <asm/processor.h>
5958 @@ -173,6 +175,9 @@ static inline void task_state(struct seq
5960 ppid = pid_alive(p) ?
5961 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
5962 + if (unlikely(vx_current_initpid(p->pid)))
5967 struct task_struct *tracer = ptrace_parent(p);
5968 @@ -299,7 +304,7 @@ static inline void task_sig(struct seq_f
5971 static void render_cap_t(struct seq_file *m, const char *header,
5973 + struct vx_info *vxi, kernel_cap_t *a)
5977 @@ -333,10 +338,11 @@ static inline void task_cap(struct seq_f
5978 NORM_CAPS(cap_effective);
5979 NORM_CAPS(cap_bset);
5981 - render_cap_t(m, "CapInh:\t", &cap_inheritable);
5982 - render_cap_t(m, "CapPrm:\t", &cap_permitted);
5983 - render_cap_t(m, "CapEff:\t", &cap_effective);
5984 - render_cap_t(m, "CapBnd:\t", &cap_bset);
5985 + /* FIXME: maybe move the p->vx_info masking to __task_cred() ? */
5986 + render_cap_t(m, "CapInh:\t", p->vx_info, &cap_inheritable);
5987 + render_cap_t(m, "CapPrm:\t", p->vx_info, &cap_permitted);
5988 + render_cap_t(m, "CapEff:\t", p->vx_info, &cap_effective);
5989 + render_cap_t(m, "CapBnd:\t", p->vx_info, &cap_bset);
5992 static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
5993 @@ -365,6 +371,43 @@ static void task_cpus_allowed(struct seq
5997 +int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
5998 + struct pid *pid, struct task_struct *task)
6000 + seq_printf(m, "Proxy:\t%p(%c)\n"
6008 + (task->nsproxy == init_task.nsproxy ? 'I' : '-'),
6009 + atomic_read(&task->nsproxy->count),
6010 + task->nsproxy->uts_ns,
6011 + (task->nsproxy->uts_ns == init_task.nsproxy->uts_ns ? 'I' : '-'),
6012 + task->nsproxy->ipc_ns,
6013 + (task->nsproxy->ipc_ns == init_task.nsproxy->ipc_ns ? 'I' : '-'),
6014 + task->nsproxy->mnt_ns,
6015 + (task->nsproxy->mnt_ns == init_task.nsproxy->mnt_ns ? 'I' : '-'),
6016 + task->nsproxy->pid_ns_for_children,
6017 + (task->nsproxy->pid_ns_for_children ==
6018 + init_task.nsproxy->pid_ns_for_children ? 'I' : '-'),
6019 + task->nsproxy->net_ns,
6020 + (task->nsproxy->net_ns == init_task.nsproxy->net_ns ? 'I' : '-'));
6024 +void task_vs_id(struct seq_file *m, struct task_struct *task)
6026 + if (task_vx_flags(task, VXF_HIDE_VINFO, 0))
6029 + seq_printf(m, "VxID: %d\n", vx_task_xid(task));
6030 + seq_printf(m, "NxID: %d\n", nx_task_nid(task));
6034 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
6035 struct pid *pid, struct task_struct *task)
6037 @@ -382,6 +425,7 @@ int proc_pid_status(struct seq_file *m,
6038 task_seccomp(m, task);
6039 task_cpus_allowed(m, task);
6040 cpuset_task_status_allowed(m, task);
6041 + task_vs_id(m, task);
6042 task_context_switch_counts(m, task);
6045 @@ -491,6 +535,17 @@ static int do_task_stat(struct seq_file
6046 /* convert nsec -> ticks */
6047 start_time = nsec_to_clock_t(start_time);
6049 + /* fixup start time for virt uptime */
6050 + if (vx_flags(VXF_VIRT_UPTIME, 0)) {
6051 + unsigned long long bias =
6052 + current->vx_info->cvirt.bias_clock;
6054 + if (start_time > bias)
6055 + start_time -= bias;
6060 seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state);
6061 seq_put_decimal_ll(m, ' ', ppid);
6062 seq_put_decimal_ll(m, ' ', pgid);
6063 diff -NurpP --minimal linux-3.13.10/fs/proc/base.c linux-3.13.10-vs2.3.6.11/fs/proc/base.c
6064 --- linux-3.13.10/fs/proc/base.c 2014-04-17 01:12:32.000000000 +0000
6065 +++ linux-3.13.10-vs2.3.6.11/fs/proc/base.c 2014-04-17 01:17:10.000000000 +0000
6067 #include <linux/slab.h>
6068 #include <linux/flex_array.h>
6069 #include <linux/posix-timers.h>
6070 +#include <linux/vs_context.h>
6071 +#include <linux/vs_network.h>
6072 #ifdef CONFIG_HARDWALL
6073 #include <asm/hardwall.h>
6075 @@ -976,11 +978,15 @@ static ssize_t oom_adj_write(struct file
6076 oom_adj = (oom_adj * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
6078 if (oom_adj < task->signal->oom_score_adj &&
6079 - !capable(CAP_SYS_RESOURCE)) {
6080 + !vx_capable(CAP_SYS_RESOURCE, VXC_OOM_ADJUST)) {
6085 + /* prevent guest processes from circumventing the oom killer */
6086 + if (vx_current_xid() && (oom_adj == OOM_DISABLE))
6087 + oom_adj = OOM_ADJUST_MIN;
6090 * /proc/pid/oom_adj is provided for legacy purposes, ask users to use
6091 * /proc/pid/oom_score_adj instead.
6092 @@ -1565,6 +1571,8 @@ struct inode *proc_pid_make_inode(struct
6093 inode->i_gid = cred->egid;
6096 + /* procfs is xid tagged */
6097 + i_tag_write(inode, (vtag_t)vx_task_xid(task));
6098 security_task_to_inode(task, inode);
6101 @@ -1610,6 +1618,8 @@ int pid_getattr(struct vfsmount *mnt, st
6105 +static unsigned name_to_int(struct dentry *dentry);
6108 * Exceptional case: normally we are not allowed to unhash a busy
6109 * directory. In this case, however, we can do it - no aliasing problems
6110 @@ -1638,6 +1648,12 @@ int pid_revalidate(struct dentry *dentry
6111 task = get_proc_task(inode);
6114 + unsigned pid = name_to_int(dentry);
6116 + if (pid != ~0U && pid != vx_map_pid(task->pid)) {
6117 + put_task_struct(task);
6120 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
6121 task_dumpable(task)) {
6123 @@ -1654,6 +1670,7 @@ int pid_revalidate(struct dentry *dentry
6124 put_task_struct(task);
6131 @@ -2173,6 +2190,13 @@ static struct dentry *proc_pident_lookup
6135 + /* TODO: maybe we can come up with a generic approach? */
6136 + if (task_vx_flags(task, VXF_HIDE_VINFO, 0) &&
6137 + (dentry->d_name.len == 5) &&
6138 + (!memcmp(dentry->d_name.name, "vinfo", 5) ||
6139 + !memcmp(dentry->d_name.name, "ninfo", 5)))
6143 * Yes, it does not scale. And it should not. Don't add
6144 * new entries into /proc/<tgid>/ without very good reasons.
6145 @@ -2569,6 +2593,9 @@ static int proc_pid_personality(struct s
6146 static const struct file_operations proc_task_operations;
6147 static const struct inode_operations proc_task_inode_operations;
6149 +extern int proc_pid_vx_info(struct task_struct *, char *);
6150 +extern int proc_pid_nx_info(struct task_struct *, char *);
6152 static const struct pid_entry tgid_base_stuff[] = {
6153 DIR("task", S_IRUGO|S_IXUGO, proc_task_inode_operations, proc_task_operations),
6154 DIR("fd", S_IRUSR|S_IXUSR, proc_fd_inode_operations, proc_fd_operations),
6155 @@ -2635,6 +2662,8 @@ static const struct pid_entry tgid_base_
6156 #ifdef CONFIG_CGROUPS
6157 REG("cgroup", S_IRUGO, proc_cgroup_operations),
6159 + INF("vinfo", S_IRUGO, proc_pid_vx_info),
6160 + INF("ninfo", S_IRUGO, proc_pid_nx_info),
6161 INF("oom_score", S_IRUGO, proc_oom_score),
6162 REG("oom_adj", S_IRUGO|S_IWUSR, proc_oom_adj_operations),
6163 REG("oom_score_adj", S_IRUGO|S_IWUSR, proc_oom_score_adj_operations),
6164 @@ -2847,7 +2876,7 @@ retry:
6166 pid = find_ge_pid(iter.tgid, ns);
6168 - iter.tgid = pid_nr_ns(pid, ns);
6169 + iter.tgid = pid_unmapped_nr_ns(pid, ns);
6170 iter.task = pid_task(pid, PIDTYPE_PID);
6171 /* What we to know is if the pid we have find is the
6172 * pid of a thread_group_leader. Testing for task
6173 @@ -2900,8 +2929,10 @@ int proc_pid_readdir(struct file *file,
6174 if (!has_pid_permissions(ns, iter.task, 2))
6177 - len = snprintf(name, sizeof(name), "%d", iter.tgid);
6178 + len = snprintf(name, sizeof(name), "%d", vx_map_tgid(iter.tgid));
6179 ctx->pos = iter.tgid + TGID_OFFSET;
6180 + if (!vx_proc_task_visible(iter.task))
6182 if (!proc_fill_cache(file, ctx, name, len,
6183 proc_pid_instantiate, iter.task, NULL)) {
6184 put_task_struct(iter.task);
6185 @@ -2994,6 +3025,7 @@ static const struct pid_entry tid_base_s
6186 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
6187 REG("projid_map", S_IRUGO|S_IWUSR, proc_projid_map_operations),
6189 + ONE("nsproxy", S_IRUGO, proc_pid_nsproxy),
6192 static int proc_tid_base_readdir(struct file *file, struct dir_context *ctx)
6193 @@ -3060,6 +3092,8 @@ static struct dentry *proc_task_lookup(s
6194 tid = name_to_int(dentry);
6197 + if (vx_current_initpid(tid))
6200 ns = dentry->d_sb->s_fs_info;
6202 diff -NurpP --minimal linux-3.13.10/fs/proc/generic.c linux-3.13.10-vs2.3.6.11/fs/proc/generic.c
6203 --- linux-3.13.10/fs/proc/generic.c 2014-01-22 20:39:07.000000000 +0000
6204 +++ linux-3.13.10-vs2.3.6.11/fs/proc/generic.c 2014-02-01 00:07:40.000000000 +0000
6206 #include <linux/bitops.h>
6207 #include <linux/spinlock.h>
6208 #include <linux/completion.h>
6209 +#include <linux/vserver/inode.h>
6210 #include <asm/uaccess.h>
6212 #include "internal.h"
6213 @@ -187,6 +188,8 @@ struct dentry *proc_lookup_de(struct pro
6214 for (de = de->subdir; de ; de = de->next) {
6215 if (de->namelen != dentry->d_name.len)
6217 + if (!vx_hide_check(0, de->vx_flags))
6219 if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
6221 spin_unlock(&proc_subdir_lock);
6222 @@ -195,6 +198,8 @@ struct dentry *proc_lookup_de(struct pro
6223 return ERR_PTR(-ENOMEM);
6224 d_set_d_op(dentry, &simple_dentry_operations);
6225 d_add(dentry, inode);
6226 + /* generic proc entries belong to the host */
6227 + i_tag_write(inode, 0);
6231 @@ -242,6 +247,9 @@ int proc_readdir_de(struct proc_dir_entr
6233 struct proc_dir_entry *next;
6236 + if (!vx_hide_check(0, de->vx_flags))
6238 spin_unlock(&proc_subdir_lock);
6239 if (!dir_emit(ctx, de->name, de->namelen,
6240 de->low_ino, de->mode >> 12)) {
6241 @@ -249,6 +257,7 @@ int proc_readdir_de(struct proc_dir_entr
6244 spin_lock(&proc_subdir_lock);
6249 @@ -355,6 +364,7 @@ static struct proc_dir_entry *__proc_cre
6253 + ent->vx_flags = IATTR_PROC_DEFAULT;
6254 atomic_set(&ent->count, 1);
6255 spin_lock_init(&ent->pde_unload_lock);
6256 INIT_LIST_HEAD(&ent->pde_openers);
6257 @@ -378,7 +388,8 @@ struct proc_dir_entry *proc_symlink(cons
6263 + ent->vx_flags = IATTR_PROC_SYMLINK;
6267 diff -NurpP --minimal linux-3.13.10/fs/proc/inode.c linux-3.13.10-vs2.3.6.11/fs/proc/inode.c
6268 --- linux-3.13.10/fs/proc/inode.c 2014-01-22 20:39:07.000000000 +0000
6269 +++ linux-3.13.10-vs2.3.6.11/fs/proc/inode.c 2014-01-31 20:38:03.000000000 +0000
6270 @@ -415,6 +415,8 @@ struct inode *proc_get_inode(struct supe
6271 inode->i_uid = de->uid;
6272 inode->i_gid = de->gid;
6275 + PROC_I(inode)->vx_flags = de->vx_flags;
6277 inode->i_size = de->size;
6279 diff -NurpP --minimal linux-3.13.10/fs/proc/internal.h linux-3.13.10-vs2.3.6.11/fs/proc/internal.h
6280 --- linux-3.13.10/fs/proc/internal.h 2013-11-25 15:45:04.000000000 +0000
6281 +++ linux-3.13.10-vs2.3.6.11/fs/proc/internal.h 2014-01-31 20:38:03.000000000 +0000
6283 #include <linux/spinlock.h>
6284 #include <linux/atomic.h>
6285 #include <linux/binfmts.h>
6286 +#include <linux/vs_pid.h>
6288 struct ctl_table_header;
6290 @@ -35,6 +36,7 @@ struct proc_dir_entry {
6296 const struct inode_operations *proc_iops;
6297 const struct file_operations *proc_fops;
6298 @@ -50,16 +52,23 @@ struct proc_dir_entry {
6306 int (*proc_get_link)(struct dentry *, struct path *);
6307 int (*proc_read)(struct task_struct *task, char *page);
6308 int (*proc_show)(struct seq_file *m,
6309 struct pid_namespace *ns, struct pid *pid,
6310 struct task_struct *task);
6311 + int (*proc_vs_read)(char *page);
6312 + int (*proc_vxi_read)(struct vx_info *vxi, char *page);
6313 + int (*proc_nxi_read)(struct nx_info *nxi, char *page);
6321 struct proc_dir_entry *pde;
6322 @@ -92,11 +101,16 @@ static inline struct pid *proc_pid(struc
6323 return PROC_I(inode)->pid;
6326 -static inline struct task_struct *get_proc_task(struct inode *inode)
6327 +static inline struct task_struct *get_proc_task_real(struct inode *inode)
6329 return get_pid_task(proc_pid(inode), PIDTYPE_PID);
6332 +static inline struct task_struct *get_proc_task(struct inode *inode)
6334 + return vx_get_proc_task(inode, proc_pid(inode));
6337 static inline int task_dumpable(struct task_struct *task)
6340 @@ -155,6 +169,8 @@ extern int proc_pid_status(struct seq_fi
6341 struct pid *, struct task_struct *);
6342 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
6343 struct pid *, struct task_struct *);
6344 +extern int proc_pid_nsproxy(struct seq_file *m, struct pid_namespace *ns,
6345 + struct pid *pid, struct task_struct *task);
6349 diff -NurpP --minimal linux-3.13.10/fs/proc/loadavg.c linux-3.13.10-vs2.3.6.11/fs/proc/loadavg.c
6350 --- linux-3.13.10/fs/proc/loadavg.c 2012-12-11 03:30:57.000000000 +0000
6351 +++ linux-3.13.10-vs2.3.6.11/fs/proc/loadavg.c 2014-01-31 20:38:03.000000000 +0000
6354 static int loadavg_proc_show(struct seq_file *m, void *v)
6356 + unsigned long running;
6357 + unsigned int threads;
6358 unsigned long avnrun[3];
6360 get_avenrun(avnrun, FIXED_1/200, 0);
6362 + if (vx_flags(VXF_VIRT_LOAD, 0)) {
6363 + struct vx_info *vxi = current_vx_info();
6365 + running = atomic_read(&vxi->cvirt.nr_running);
6366 + threads = atomic_read(&vxi->cvirt.nr_threads);
6368 + running = nr_running();
6369 + threads = nr_threads;
6372 seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %ld/%d %d\n",
6373 LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]),
6374 LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]),
6375 LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]),
6376 - nr_running(), nr_threads,
6378 task_active_pid_ns(current)->last_pid);
6381 diff -NurpP --minimal linux-3.13.10/fs/proc/meminfo.c linux-3.13.10-vs2.3.6.11/fs/proc/meminfo.c
6382 --- linux-3.13.10/fs/proc/meminfo.c 2014-01-22 20:39:07.000000000 +0000
6383 +++ linux-3.13.10-vs2.3.6.11/fs/proc/meminfo.c 2014-01-31 20:38:03.000000000 +0000
6384 @@ -37,7 +37,8 @@ static int meminfo_proc_show(struct seq_
6386 committed = percpu_counter_read_positive(&vm_committed_as);
6388 - cached = global_page_state(NR_FILE_PAGES) -
6389 + cached = vx_flags(VXF_VIRT_MEM, 0) ?
6390 + vx_vsi_cached(&i) : global_page_state(NR_FILE_PAGES) -
6391 total_swapcache_pages() - i.bufferram;
6394 diff -NurpP --minimal linux-3.13.10/fs/proc/root.c linux-3.13.10-vs2.3.6.11/fs/proc/root.c
6395 --- linux-3.13.10/fs/proc/root.c 2013-11-25 15:47:00.000000000 +0000
6396 +++ linux-3.13.10-vs2.3.6.11/fs/proc/root.c 2014-02-01 00:02:11.000000000 +0000
6398 #include <linux/mount.h>
6399 #include <linux/pid_namespace.h>
6400 #include <linux/parser.h>
6401 +#include <linux/vserver/inode.h>
6403 #include "internal.h"
6405 +struct proc_dir_entry *proc_virtual;
6407 +extern void proc_vx_init(void);
6409 static int proc_test_super(struct super_block *sb, void *data)
6411 return sb->s_fs_info == data;
6412 @@ -114,7 +119,8 @@ static struct dentry *proc_mount(struct
6413 return ERR_PTR(-EPERM);
6415 /* Does the mounter have privilege over the pid namespace? */
6416 - if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
6417 + if (!vx_ns_capable(ns->user_ns,
6418 + CAP_SYS_ADMIN, VXC_SECURE_MOUNT))
6419 return ERR_PTR(-EPERM);
6422 @@ -188,6 +194,7 @@ void __init proc_root_init(void)
6424 proc_mkdir("bus", NULL);
6429 static int proc_root_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat
6430 @@ -249,6 +256,7 @@ struct proc_dir_entry proc_root = {
6431 .proc_iops = &proc_root_inode_operations,
6432 .proc_fops = &proc_root_operations,
6433 .parent = &proc_root,
6434 + .vx_flags = IATTR_ADMIN | IATTR_WATCH,
6438 diff -NurpP --minimal linux-3.13.10/fs/proc/self.c linux-3.13.10-vs2.3.6.11/fs/proc/self.c
6439 --- linux-3.13.10/fs/proc/self.c 2014-01-22 20:39:07.000000000 +0000
6440 +++ linux-3.13.10-vs2.3.6.11/fs/proc/self.c 2014-01-31 20:38:03.000000000 +0000
6442 #include <linux/namei.h>
6443 #include <linux/slab.h>
6444 #include <linux/pid_namespace.h>
6445 +#include <linux/vserver/inode.h>
6446 #include "internal.h"
6449 @@ -54,6 +55,8 @@ int proc_setup_self(struct super_block *
6450 self = d_alloc_name(s->s_root, "self");
6452 struct inode *inode = new_inode_pseudo(s);
6454 + // self->vx_flags = IATTR_PROC_SYMLINK;
6456 inode->i_ino = self_inum;
6457 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
6458 diff -NurpP --minimal linux-3.13.10/fs/proc/stat.c linux-3.13.10-vs2.3.6.11/fs/proc/stat.c
6459 --- linux-3.13.10/fs/proc/stat.c 2013-07-14 17:01:29.000000000 +0000
6460 +++ linux-3.13.10-vs2.3.6.11/fs/proc/stat.c 2014-01-31 20:38:03.000000000 +0000
6462 #include <linux/slab.h>
6463 #include <linux/time.h>
6464 #include <linux/irqnr.h>
6465 +#include <linux/vserver/cvirt.h>
6466 #include <asm/cputime.h>
6467 #include <linux/tick.h>
6468 +#include <linux/cpuset.h>
6470 #ifndef arch_irq_stat_cpu
6471 #define arch_irq_stat_cpu(cpu) 0
6472 @@ -87,14 +89,26 @@ static int show_stat(struct seq_file *p,
6473 u64 sum_softirq = 0;
6474 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
6475 struct timespec boottime;
6476 + cpumask_var_t cpus_allowed;
6477 + bool virt_cpu = vx_flags(VXF_VIRT_CPU, 0);
6479 user = nice = system = idle = iowait =
6480 irq = softirq = steal = 0;
6481 guest = guest_nice = 0;
6482 getboottime(&boottime);
6484 + if (vx_flags(VXF_VIRT_UPTIME, 0))
6485 + vx_vsi_boottime(&boottime);
6488 + cpuset_cpus_allowed(current, cpus_allowed);
6490 jif = boottime.tv_sec;
6492 for_each_possible_cpu(i) {
6493 + if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6496 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
6497 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6498 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
6499 @@ -131,6 +145,9 @@ static int show_stat(struct seq_file *p,
6502 for_each_online_cpu(i) {
6503 + if (virt_cpu && !cpumask_test_cpu(i, cpus_allowed))
6506 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
6507 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
6508 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
6509 diff -NurpP --minimal linux-3.13.10/fs/proc/uptime.c linux-3.13.10-vs2.3.6.11/fs/proc/uptime.c
6510 --- linux-3.13.10/fs/proc/uptime.c 2013-11-25 15:45:04.000000000 +0000
6511 +++ linux-3.13.10-vs2.3.6.11/fs/proc/uptime.c 2014-01-31 20:38:03.000000000 +0000
6513 #include <linux/seq_file.h>
6514 #include <linux/time.h>
6515 #include <linux/kernel_stat.h>
6516 +#include <linux/vserver/cvirt.h>
6517 #include <asm/cputime.h>
6519 static int uptime_proc_show(struct seq_file *m, void *v)
6520 @@ -24,6 +25,10 @@ static int uptime_proc_show(struct seq_f
6521 nsec = cputime64_to_jiffies64(idletime) * TICK_NSEC;
6522 idle.tv_sec = div_u64_rem(nsec, NSEC_PER_SEC, &rem);
6525 + if (vx_flags(VXF_VIRT_UPTIME, 0))
6526 + vx_vsi_uptime(&uptime, &idle);
6528 seq_printf(m, "%lu.%02lu %lu.%02lu\n",
6529 (unsigned long) uptime.tv_sec,
6530 (uptime.tv_nsec / (NSEC_PER_SEC / 100)),
6531 diff -NurpP --minimal linux-3.13.10/fs/proc_namespace.c linux-3.13.10-vs2.3.6.11/fs/proc_namespace.c
6532 --- linux-3.13.10/fs/proc_namespace.c 2014-01-22 20:39:07.000000000 +0000
6533 +++ linux-3.13.10-vs2.3.6.11/fs/proc_namespace.c 2014-02-25 12:43:16.000000000 +0000
6534 @@ -44,6 +44,8 @@ static int show_sb_opts(struct seq_file
6535 { MS_SYNCHRONOUS, ",sync" },
6536 { MS_DIRSYNC, ",dirsync" },
6537 { MS_MANDLOCK, ",mand" },
6538 + { MS_TAGGED, ",tag" },
6539 + { MS_NOTAGCHECK, ",notagcheck" },
6542 const struct proc_fs_info *fs_infop;
6543 @@ -80,6 +82,38 @@ static inline void mangle(struct seq_fil
6544 seq_escape(m, s, " \t\n\\");
6547 +#ifdef CONFIG_VSERVER_EXTRA_MNT_CHECK
6549 +static int mnt_is_reachable(struct vfsmount *vfsmnt)
6552 + struct dentry *point;
6553 + struct mount *mnt = real_mount(vfsmnt);
6554 + struct mount *root_mnt;
6557 + if (mnt == mnt->mnt_ns->root)
6561 + root = current->fs->root;
6562 + root_mnt = real_mount(root.mnt);
6563 + point = root.dentry;
6565 + while ((mnt != mnt->mnt_parent) && (mnt != root_mnt)) {
6566 + point = mnt->mnt_mountpoint;
6567 + mnt = mnt->mnt_parent;
6569 + rcu_read_unlock();
6571 + ret = (mnt == root_mnt) && is_subdir(point, root.dentry);
6576 +#define mnt_is_reachable(v) (1)
6579 static void show_type(struct seq_file *m, struct super_block *sb)
6581 mangle(m, sb->s_type->name);
6582 @@ -96,6 +130,17 @@ static int show_vfsmnt(struct seq_file *
6583 struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
6584 struct super_block *sb = mnt_path.dentry->d_sb;
6586 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6588 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6591 + if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6592 + mnt == current->fs->root.mnt) {
6593 + seq_puts(m, "/dev/root / ");
6597 if (sb->s_op->show_devname) {
6598 err = sb->s_op->show_devname(m, mnt_path.dentry);
6600 @@ -106,6 +151,7 @@ static int show_vfsmnt(struct seq_file *
6602 seq_path(m, &mnt_path, " \t\n\\");
6606 seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
6607 err = show_sb_opts(m, sb);
6608 @@ -128,6 +174,11 @@ static int show_mountinfo(struct seq_fil
6609 struct path root = p->root;
6612 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6614 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6617 seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
6618 MAJOR(sb->s_dev), MINOR(sb->s_dev));
6619 if (sb->s_op->show_path)
6620 @@ -187,6 +238,17 @@ static int show_vfsstat(struct seq_file
6621 struct super_block *sb = mnt_path.dentry->d_sb;
6624 + if (vx_flags(VXF_HIDE_MOUNT, 0))
6626 + if (!mnt_is_reachable(mnt) && !vx_check(0, VS_WATCH_P))
6629 + if (!vx_check(0, VS_ADMIN|VS_WATCH) &&
6630 + mnt == current->fs->root.mnt) {
6631 + seq_puts(m, "device /dev/root mounted on / ");
6636 if (sb->s_op->show_devname) {
6637 seq_puts(m, "device ");
6638 @@ -203,7 +265,7 @@ static int show_vfsstat(struct seq_file
6639 seq_puts(m, " mounted on ");
6640 seq_path(m, &mnt_path, " \t\n\\");
6644 /* file system type */
6645 seq_puts(m, "with fstype ");
6647 diff -NurpP --minimal linux-3.13.10/fs/quota/dquot.c linux-3.13.10-vs2.3.6.11/fs/quota/dquot.c
6648 --- linux-3.13.10/fs/quota/dquot.c 2014-04-17 01:12:34.000000000 +0000
6649 +++ linux-3.13.10-vs2.3.6.11/fs/quota/dquot.c 2014-03-12 15:51:07.000000000 +0000
6650 @@ -1602,6 +1602,9 @@ int __dquot_alloc_space(struct inode *in
6651 struct dquot **dquots = inode->i_dquot;
6652 int reserve = flags & DQUOT_SPACE_RESERVE;
6654 + if ((ret = dl_alloc_space(inode, number)))
6658 * First test before acquiring mutex - solves deadlocks when we
6659 * re-enter the quota code and are already holding the mutex
6660 @@ -1657,6 +1660,9 @@ int dquot_alloc_inode(const struct inode
6661 struct dquot_warn warn[MAXQUOTAS];
6662 struct dquot * const *dquots = inode->i_dquot;
6664 + if ((ret = dl_alloc_inode(inode)))
6667 /* First test before acquiring mutex - solves deadlocks when we
6668 * re-enter the quota code and are already holding the mutex */
6669 if (!dquot_active(inode))
6670 @@ -1757,6 +1763,8 @@ void __dquot_free_space(struct inode *in
6671 struct dquot **dquots = inode->i_dquot;
6672 int reserve = flags & DQUOT_SPACE_RESERVE;
6674 + dl_free_space(inode, number);
6676 /* First test before acquiring mutex - solves deadlocks when we
6677 * re-enter the quota code and are already holding the mutex */
6678 if (!dquot_active(inode)) {
6679 @@ -1801,6 +1809,8 @@ void dquot_free_inode(const struct inode
6680 struct dquot_warn warn[MAXQUOTAS];
6681 struct dquot * const *dquots = inode->i_dquot;
6683 + dl_free_inode(inode);
6685 /* First test before acquiring mutex - solves deadlocks when we
6686 * re-enter the quota code and are already holding the mutex */
6687 if (!dquot_active(inode))
6688 diff -NurpP --minimal linux-3.13.10/fs/quota/quota.c linux-3.13.10-vs2.3.6.11/fs/quota/quota.c
6689 --- linux-3.13.10/fs/quota/quota.c 2014-01-22 20:39:07.000000000 +0000
6690 +++ linux-3.13.10-vs2.3.6.11/fs/quota/quota.c 2014-01-31 20:38:03.000000000 +0000
6692 #include <linux/fs.h>
6693 #include <linux/namei.h>
6694 #include <linux/slab.h>
6695 +#include <linux/vs_context.h>
6696 #include <asm/current.h>
6697 #include <linux/uaccess.h>
6698 #include <linux/kernel.h>
6699 @@ -38,7 +39,7 @@ static int check_quotactl_permission(str
6703 - if (!capable(CAP_SYS_ADMIN))
6704 + if (!vx_capable(CAP_SYS_ADMIN, VXC_QUOTA_CTL))
6708 @@ -338,6 +339,46 @@ static int do_quotactl(struct super_bloc
6712 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6714 +#include <linux/vroot.h>
6715 +#include <linux/major.h>
6716 +#include <linux/module.h>
6717 +#include <linux/kallsyms.h>
6718 +#include <linux/vserver/debug.h>
6720 +static vroot_grb_func *vroot_get_real_bdev = NULL;
6722 +static DEFINE_SPINLOCK(vroot_grb_lock);
6724 +int register_vroot_grb(vroot_grb_func *func) {
6727 + spin_lock(&vroot_grb_lock);
6728 + if (!vroot_get_real_bdev) {
6729 + vroot_get_real_bdev = func;
6732 + spin_unlock(&vroot_grb_lock);
6735 +EXPORT_SYMBOL(register_vroot_grb);
6737 +int unregister_vroot_grb(vroot_grb_func *func) {
6738 + int ret = -EINVAL;
6740 + spin_lock(&vroot_grb_lock);
6741 + if (vroot_get_real_bdev) {
6742 + vroot_get_real_bdev = NULL;
6745 + spin_unlock(&vroot_grb_lock);
6748 +EXPORT_SYMBOL(unregister_vroot_grb);
6752 /* Return 1 if 'cmd' will block on frozen filesystem */
6753 static int quotactl_cmd_write(int cmd)
6755 @@ -373,6 +414,22 @@ static struct super_block *quotactl_bloc
6758 return ERR_CAST(bdev);
6759 +#if defined(CONFIG_BLK_DEV_VROOT) || defined(CONFIG_BLK_DEV_VROOT_MODULE)
6760 + if (bdev && bdev->bd_inode &&
6761 + imajor(bdev->bd_inode) == VROOT_MAJOR) {
6762 + struct block_device *bdnew = (void *)-EINVAL;
6764 + if (vroot_get_real_bdev)
6765 + bdnew = vroot_get_real_bdev(bdev);
6767 + vxdprintk(VXD_CBIT(misc, 0),
6768 + "vroot_get_real_bdev not set");
6770 + if (IS_ERR(bdnew))
6771 + return ERR_PTR(PTR_ERR(bdnew));
6775 if (quotactl_cmd_write(cmd))
6776 sb = get_super_thawed(bdev);
6778 diff -NurpP --minimal linux-3.13.10/fs/stat.c linux-3.13.10-vs2.3.6.11/fs/stat.c
6779 --- linux-3.13.10/fs/stat.c 2014-01-22 20:39:07.000000000 +0000
6780 +++ linux-3.13.10-vs2.3.6.11/fs/stat.c 2014-01-31 20:38:03.000000000 +0000
6781 @@ -26,6 +26,7 @@ void generic_fillattr(struct inode *inod
6782 stat->nlink = inode->i_nlink;
6783 stat->uid = inode->i_uid;
6784 stat->gid = inode->i_gid;
6785 + stat->tag = inode->i_tag;
6786 stat->rdev = inode->i_rdev;
6787 stat->size = i_size_read(inode);
6788 stat->atime = inode->i_atime;
6789 diff -NurpP --minimal linux-3.13.10/fs/statfs.c linux-3.13.10-vs2.3.6.11/fs/statfs.c
6790 --- linux-3.13.10/fs/statfs.c 2013-11-25 15:47:00.000000000 +0000
6791 +++ linux-3.13.10-vs2.3.6.11/fs/statfs.c 2014-01-31 20:38:03.000000000 +0000
6793 #include <linux/statfs.h>
6794 #include <linux/security.h>
6795 #include <linux/uaccess.h>
6796 +#include <linux/vs_base.h>
6797 +#include <linux/vs_dlimit.h>
6798 #include "internal.h"
6800 static int flags_by_mnt(int mnt_flags)
6801 @@ -60,6 +62,8 @@ static int statfs_by_dentry(struct dentr
6802 retval = dentry->d_sb->s_op->statfs(dentry, buf);
6803 if (retval == 0 && buf->f_frsize == 0)
6804 buf->f_frsize = buf->f_bsize;
6805 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
6806 + vx_vsi_statfs(dentry->d_sb, buf);
6810 diff -NurpP --minimal linux-3.13.10/fs/super.c linux-3.13.10-vs2.3.6.11/fs/super.c
6811 --- linux-3.13.10/fs/super.c 2014-01-22 20:39:07.000000000 +0000
6812 +++ linux-3.13.10-vs2.3.6.11/fs/super.c 2014-01-31 20:38:03.000000000 +0000
6814 #include <linux/cleancache.h>
6815 #include <linux/fsnotify.h>
6816 #include <linux/lockdep.h>
6817 +#include <linux/magic.h>
6818 +#include <linux/vs_context.h>
6819 #include "internal.h"
6822 @@ -1098,6 +1100,13 @@ mount_fs(struct file_system_type *type,
6823 WARN_ON(sb->s_bdi == &default_backing_dev_info);
6824 sb->s_flags |= MS_BORN;
6827 + if (!vx_capable(CAP_SYS_ADMIN, VXC_BINARY_MOUNT) &&
6829 + (sb->s_magic != PROC_SUPER_MAGIC) &&
6830 + (sb->s_magic != DEVPTS_SUPER_MAGIC))
6833 error = security_sb_kern_mount(sb, flags, secdata);
6836 diff -NurpP --minimal linux-3.13.10/fs/kernfs/mount.c linux-3.13.10-vs2.3.6.11/fs/kernfs/mount.c
6837 --- linux-3.13.10/fs/kernfs/mount.c 2013-11-25 15:47:00.000000000 +0000
6838 +++ linux-3.13.10-vs2.3.6.11/fs/kernfs/mount.c 2014-01-31 20:38:03.000000000 +0000
6839 @@ -48,7 +48,7 @@ static int sysfs_fill_super(struct super
6841 sb->s_blocksize = PAGE_CACHE_SIZE;
6842 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
6843 - sb->s_magic = SYSFS_MAGIC;
6844 + sb->s_magic = SYSFS_SUPER_MAGIC;
6845 sb->s_op = &kernfs_sops;
6846 sb->s_time_gran = 1;
6848 diff -NurpP --minimal linux-3.13.10/fs/utimes.c linux-3.13.10-vs2.3.6.11/fs/utimes.c
6849 --- linux-3.13.10/fs/utimes.c 2014-01-22 20:39:07.000000000 +0000
6850 +++ linux-3.13.10-vs2.3.6.11/fs/utimes.c 2014-01-31 23:49:14.000000000 +0000
6852 #include <linux/stat.h>
6853 #include <linux/utime.h>
6854 #include <linux/syscalls.h>
6855 +#include <linux/mount.h>
6856 +#include <linux/vs_cowbl.h>
6857 #include <asm/uaccess.h>
6858 #include <asm/unistd.h>
6860 @@ -52,13 +54,19 @@ static int utimes_common(struct path *pa
6863 struct iattr newattrs;
6864 - struct inode *inode = path->dentry->d_inode;
6865 struct inode *delegated_inode = NULL;
6866 + struct inode *inode;
6868 + error = cow_check_and_break(path);
6872 error = mnt_want_write(path->mnt);
6876 + inode = path->dentry->d_inode;
6878 if (times && times[0].tv_nsec == UTIME_NOW &&
6879 times[1].tv_nsec == UTIME_NOW)
6881 diff -NurpP --minimal linux-3.13.10/fs/xattr.c linux-3.13.10-vs2.3.6.11/fs/xattr.c
6882 --- linux-3.13.10/fs/xattr.c 2013-02-19 13:58:49.000000000 +0000
6883 +++ linux-3.13.10-vs2.3.6.11/fs/xattr.c 2014-01-31 20:38:03.000000000 +0000
6885 #include <linux/audit.h>
6886 #include <linux/vmalloc.h>
6887 #include <linux/posix_acl_xattr.h>
6888 +#include <linux/mount.h>
6890 #include <asm/uaccess.h>
6892 @@ -52,7 +53,7 @@ xattr_permission(struct inode *inode, co
6893 * The trusted.* namespace can only be accessed by privileged users.
6895 if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
6896 - if (!capable(CAP_SYS_ADMIN))
6897 + if (!vx_capable(CAP_SYS_ADMIN, VXC_FS_TRUSTED))
6898 return (mask & MAY_WRITE) ? -EPERM : -ENODATA;
6901 diff -NurpP --minimal linux-3.13.10/include/linux/cred.h linux-3.13.10-vs2.3.6.11/include/linux/cred.h
6902 --- linux-3.13.10/include/linux/cred.h 2013-02-19 13:58:50.000000000 +0000
6903 +++ linux-3.13.10-vs2.3.6.11/include/linux/cred.h 2014-01-31 20:38:03.000000000 +0000
6904 @@ -143,6 +143,7 @@ extern void exit_creds(struct task_struc
6905 extern int copy_creds(struct task_struct *, unsigned long);
6906 extern const struct cred *get_task_cred(struct task_struct *);
6907 extern struct cred *cred_alloc_blank(void);
6908 +extern struct cred *__prepare_creds(const struct cred *);
6909 extern struct cred *prepare_creds(void);
6910 extern struct cred *prepare_exec_creds(void);
6911 extern int commit_creds(struct cred *);
6912 @@ -196,6 +197,31 @@ static inline void validate_process_cred
6916 +static inline void set_cred_subscribers(struct cred *cred, int n)
6918 +#ifdef CONFIG_DEBUG_CREDENTIALS
6919 + atomic_set(&cred->subscribers, n);
6923 +static inline int read_cred_subscribers(const struct cred *cred)
6925 +#ifdef CONFIG_DEBUG_CREDENTIALS
6926 + return atomic_read(&cred->subscribers);
6932 +static inline void alter_cred_subscribers(const struct cred *_cred, int n)
6934 +#ifdef CONFIG_DEBUG_CREDENTIALS
6935 + struct cred *cred = (struct cred *) _cred;
6937 + atomic_add(n, &cred->subscribers);
6942 * get_new_cred - Get a reference on a new set of credentials
6943 * @cred: The new credentials to reference
6944 diff -NurpP --minimal linux-3.13.10/include/linux/devpts_fs.h linux-3.13.10-vs2.3.6.11/include/linux/devpts_fs.h
6945 --- linux-3.13.10/include/linux/devpts_fs.h 2013-02-19 13:58:50.000000000 +0000
6946 +++ linux-3.13.10-vs2.3.6.11/include/linux/devpts_fs.h 2014-01-31 20:38:03.000000000 +0000
6947 @@ -45,5 +45,4 @@ static inline void devpts_pty_kill(struc
6952 #endif /* _LINUX_DEVPTS_FS_H */
6953 diff -NurpP --minimal linux-3.13.10/include/linux/fs.h linux-3.13.10-vs2.3.6.11/include/linux/fs.h
6954 --- linux-3.13.10/include/linux/fs.h 2014-01-22 20:39:10.000000000 +0000
6955 +++ linux-3.13.10-vs2.3.6.11/include/linux/fs.h 2014-01-31 23:33:22.000000000 +0000
6956 @@ -213,6 +213,7 @@ typedef void (dio_iodone_t)(struct kiocb
6957 #define ATTR_KILL_PRIV (1 << 14)
6958 #define ATTR_OPEN (1 << 15) /* Truncating from open(O_TRUNC) */
6959 #define ATTR_TIMES_SET (1 << 16)
6960 +#define ATTR_TAG (1 << 17)
6963 * This is the Inode Attributes structure, used for notify_change(). It
6964 @@ -228,6 +229,7 @@ struct iattr {
6970 struct timespec ia_atime;
6971 struct timespec ia_mtime;
6972 @@ -526,7 +528,9 @@ struct inode {
6973 unsigned short i_opflags;
6976 - unsigned int i_flags;
6978 + unsigned short i_flags;
6979 + unsigned short i_vflags;
6981 #ifdef CONFIG_FS_POSIX_ACL
6982 struct posix_acl *i_acl;
6983 @@ -555,6 +559,7 @@ struct inode {
6984 unsigned int __i_nlink;
6989 struct timespec i_atime;
6990 struct timespec i_mtime;
6991 @@ -713,6 +718,11 @@ static inline gid_t i_gid_read(const str
6992 return from_kgid(&init_user_ns, inode->i_gid);
6995 +static inline vtag_t i_tag_read(const struct inode *inode)
6997 + return from_ktag(&init_user_ns, inode->i_tag);
7000 static inline void i_uid_write(struct inode *inode, uid_t uid)
7002 inode->i_uid = make_kuid(&init_user_ns, uid);
7003 @@ -723,14 +733,19 @@ static inline void i_gid_write(struct in
7004 inode->i_gid = make_kgid(&init_user_ns, gid);
7007 +static inline void i_tag_write(struct inode *inode, vtag_t tag)
7009 + inode->i_tag = make_ktag(&init_user_ns, tag);
7012 static inline unsigned iminor(const struct inode *inode)
7014 - return MINOR(inode->i_rdev);
7015 + return MINOR(inode->i_mdev);
7018 static inline unsigned imajor(const struct inode *inode)
7020 - return MAJOR(inode->i_rdev);
7021 + return MAJOR(inode->i_mdev);
7024 extern struct block_device *I_BDEV(struct inode *inode);
7025 @@ -790,6 +805,7 @@ struct file {
7027 struct fown_struct f_owner;
7028 const struct cred *f_cred;
7030 struct file_ra_state f_ra;
7033 @@ -962,6 +978,7 @@ struct file_lock {
7034 struct file *fl_file;
7039 struct fasync_struct * fl_fasync; /* for lease break notifications */
7040 /* for lease breaks: */
7041 @@ -1573,6 +1590,7 @@ struct inode_operations {
7042 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
7043 ssize_t (*listxattr) (struct dentry *, char *, size_t);
7044 int (*removexattr) (struct dentry *, const char *);
7045 + int (*sync_flags) (struct inode *, int, int);
7046 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
7048 int (*update_time)(struct inode *, struct timespec *, int);
7049 @@ -1586,6 +1604,7 @@ ssize_t rw_copy_check_uvector(int type,
7050 unsigned long nr_segs, unsigned long fast_segs,
7051 struct iovec *fast_pointer,
7052 struct iovec **ret_pointer);
7053 +ssize_t vfs_sendfile(struct file *, struct file *, loff_t *, size_t, loff_t);
7055 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
7056 extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *);
7057 @@ -1639,6 +1658,14 @@ struct super_operations {
7058 #define S_IMA 1024 /* Inode has an associated IMA struct */
7059 #define S_AUTOMOUNT 2048 /* Automount/referral quasi-directory */
7060 #define S_NOSEC 4096 /* no suid or xattr security attributes */
7061 +#define S_IXUNLINK 8192 /* Immutable Invert on unlink */
7063 +/* Linux-VServer related Inode flags */
7067 +#define V_BARRIER 4 /* Barrier for chroot() */
7068 +#define V_COW 8 /* Copy on Write */
7071 * Note that nosuid etc flags are inode-specific: setting some file-system
7072 @@ -1663,10 +1690,13 @@ struct super_operations {
7073 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
7074 #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME)
7075 #define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION)
7076 +#define IS_TAGGED(inode) __IS_FLG(inode, MS_TAGGED)
7078 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
7079 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
7080 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
7081 +#define IS_IXUNLINK(inode) ((inode)->i_flags & S_IXUNLINK)
7082 +#define IS_IXORUNLINK(inode) ((IS_IXUNLINK(inode) ? S_IMMUTABLE : 0) ^ IS_IMMUTABLE(inode))
7083 #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL)
7085 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
7086 @@ -1677,6 +1707,16 @@ struct super_operations {
7087 #define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT)
7088 #define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC)
7090 +#define IS_BARRIER(inode) (S_ISDIR((inode)->i_mode) && ((inode)->i_vflags & V_BARRIER))
7092 +#ifdef CONFIG_VSERVER_COWBL
7093 +# define IS_COW(inode) (IS_IXUNLINK(inode) && IS_IMMUTABLE(inode))
7094 +# define IS_COW_LINK(inode) (S_ISREG((inode)->i_mode) && ((inode)->i_nlink > 1))
7096 +# define IS_COW(inode) (0)
7097 +# define IS_COW_LINK(inode) (0)
7101 * Inode state bits. Protected by inode->i_lock
7103 @@ -1920,6 +1960,9 @@ extern struct kobject *fs_kobj;
7104 extern int locks_mandatory_locked(struct inode *);
7105 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
7107 +#define ATTR_FLAG_BARRIER 512 /* Barrier for chroot() */
7108 +#define ATTR_FLAG_IXUNLINK 1024 /* Immutable invert on unlink */
7111 * Candidates for mandatory locking have the setgid bit set
7112 * but no group execute bit - an otherwise meaningless combination.
7113 @@ -2605,6 +2648,7 @@ extern int dcache_dir_open(struct inode
7114 extern int dcache_dir_close(struct inode *, struct file *);
7115 extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
7116 extern int dcache_readdir(struct file *, struct dir_context *);
7117 +extern int dcache_readdir_filter(struct file *, struct dir_context *, int (*)(struct dentry *));
7118 extern int simple_setattr(struct dentry *, struct iattr *);
7119 extern int simple_getattr(struct vfsmount *, struct dentry *, struct kstat *);
7120 extern int simple_statfs(struct dentry *, struct kstatfs *);
7121 diff -NurpP --minimal linux-3.13.10/include/linux/init_task.h linux-3.13.10-vs2.3.6.11/include/linux/init_task.h
7122 --- linux-3.13.10/include/linux/init_task.h 2014-01-22 20:39:11.000000000 +0000
7123 +++ linux-3.13.10-vs2.3.6.11/include/linux/init_task.h 2014-01-31 20:38:03.000000000 +0000
7124 @@ -222,6 +222,10 @@ extern struct task_group root_task_group
7125 INIT_TASK_RCU_PREEMPT(tsk) \
7126 INIT_CPUSET_SEQ(tsk) \
7129 + .vx_info = NULL, \
7131 + .nx_info = NULL, \
7135 diff -NurpP --minimal linux-3.13.10/include/linux/ipc.h linux-3.13.10-vs2.3.6.11/include/linux/ipc.h
7136 --- linux-3.13.10/include/linux/ipc.h 2012-12-11 03:30:57.000000000 +0000
7137 +++ linux-3.13.10-vs2.3.6.11/include/linux/ipc.h 2014-01-31 20:38:03.000000000 +0000
7138 @@ -16,6 +16,7 @@ struct kern_ipc_perm
7146 diff -NurpP --minimal linux-3.13.10/include/linux/memcontrol.h linux-3.13.10-vs2.3.6.11/include/linux/memcontrol.h
7147 --- linux-3.13.10/include/linux/memcontrol.h 2013-11-25 15:47:01.000000000 +0000
7148 +++ linux-3.13.10-vs2.3.6.11/include/linux/memcontrol.h 2014-01-31 20:38:03.000000000 +0000
7149 @@ -99,6 +99,13 @@ extern struct mem_cgroup *try_get_mem_cg
7150 extern struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
7151 extern struct mem_cgroup *mem_cgroup_from_css(struct cgroup_subsys_state *css);
7153 +extern u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member);
7154 +extern u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member);
7156 +extern s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem);
7157 +extern s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem);
7158 +extern s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem);
7161 bool mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *memcg)
7163 diff -NurpP --minimal linux-3.13.10/include/linux/mm_types.h linux-3.13.10-vs2.3.6.11/include/linux/mm_types.h
7164 --- linux-3.13.10/include/linux/mm_types.h 2014-01-22 20:39:11.000000000 +0000
7165 +++ linux-3.13.10-vs2.3.6.11/include/linux/mm_types.h 2014-01-31 20:38:03.000000000 +0000
7166 @@ -397,6 +397,7 @@ struct mm_struct {
7168 /* Architecture-specific MM context */
7169 mm_context_t context;
7170 + struct vx_info *mm_vx_info;
7172 unsigned long flags; /* Must use atomic bitops to access the bits */
7174 diff -NurpP --minimal linux-3.13.10/include/linux/mount.h linux-3.13.10-vs2.3.6.11/include/linux/mount.h
7175 --- linux-3.13.10/include/linux/mount.h 2014-01-22 20:39:11.000000000 +0000
7176 +++ linux-3.13.10-vs2.3.6.11/include/linux/mount.h 2014-01-31 20:38:03.000000000 +0000
7177 @@ -52,6 +52,9 @@ struct mnt_namespace;
7178 #define MNT_DOOMED 0x1000000
7179 #define MNT_SYNC_UMOUNT 0x2000000
7181 +#define MNT_TAGID 0x10000
7182 +#define MNT_NOTAG 0x20000
7185 struct dentry *mnt_root; /* root of the mounted tree */
7186 struct super_block *mnt_sb; /* pointer to superblock */
7187 diff -NurpP --minimal linux-3.13.10/include/linux/net.h linux-3.13.10-vs2.3.6.11/include/linux/net.h
7188 --- linux-3.13.10/include/linux/net.h 2014-01-22 20:39:11.000000000 +0000
7189 +++ linux-3.13.10-vs2.3.6.11/include/linux/net.h 2014-01-31 20:38:03.000000000 +0000
7190 @@ -39,6 +39,7 @@ struct net;
7191 #define SOCK_PASSCRED 3
7192 #define SOCK_PASSSEC 4
7193 #define SOCK_EXTERNALLY_ALLOCATED 5
7194 +#define SOCK_USER_SOCKET 6
7196 #ifndef ARCH_HAS_SOCKET_TYPES
7198 diff -NurpP --minimal linux-3.13.10/include/linux/netdevice.h linux-3.13.10-vs2.3.6.11/include/linux/netdevice.h
7199 --- linux-3.13.10/include/linux/netdevice.h 2014-04-17 01:12:37.000000000 +0000
7200 +++ linux-3.13.10-vs2.3.6.11/include/linux/netdevice.h 2014-03-12 15:51:07.000000000 +0000
7201 @@ -1839,6 +1839,7 @@ int init_dummy_netdev(struct net_device
7203 struct net_device *dev_get_by_index(struct net *net, int ifindex);
7204 struct net_device *__dev_get_by_index(struct net *net, int ifindex);
7205 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex);
7206 struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
7207 int netdev_get_name(struct net *net, char *name, int ifindex);
7208 int dev_restart(struct net_device *dev);
7209 diff -NurpP --minimal linux-3.13.10/include/linux/nsproxy.h linux-3.13.10-vs2.3.6.11/include/linux/nsproxy.h
7210 --- linux-3.13.10/include/linux/nsproxy.h 2013-11-25 15:45:06.000000000 +0000
7211 +++ linux-3.13.10-vs2.3.6.11/include/linux/nsproxy.h 2014-01-31 20:38:03.000000000 +0000
7214 #include <linux/spinlock.h>
7215 #include <linux/sched.h>
7216 +#include <linux/vserver/debug.h>
7218 struct mnt_namespace;
7219 struct uts_namespace;
7220 @@ -67,6 +68,7 @@ static inline struct nsproxy *task_nspro
7223 int copy_namespaces(unsigned long flags, struct task_struct *tsk);
7224 +struct nsproxy *copy_nsproxy(struct nsproxy *orig);
7225 void exit_task_namespaces(struct task_struct *tsk);
7226 void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
7227 void free_nsproxy(struct nsproxy *ns);
7228 @@ -74,16 +76,26 @@ int unshare_nsproxy_namespaces(unsigned
7229 struct cred *, struct fs_struct *);
7230 int __init nsproxy_cache_init(void);
7232 -static inline void put_nsproxy(struct nsproxy *ns)
7233 +#define get_nsproxy(n) __get_nsproxy(n, __FILE__, __LINE__)
7235 +static inline void __get_nsproxy(struct nsproxy *ns,
7236 + const char *_file, int _line)
7238 - if (atomic_dec_and_test(&ns->count)) {
7241 + vxlprintk(VXD_CBIT(space, 0), "get_nsproxy(%p[%u])",
7242 + ns, atomic_read(&ns->count), _file, _line);
7243 + atomic_inc(&ns->count);
7246 -static inline void get_nsproxy(struct nsproxy *ns)
7247 +#define put_nsproxy(n) __put_nsproxy(n, __FILE__, __LINE__)
7249 +static inline void __put_nsproxy(struct nsproxy *ns,
7250 + const char *_file, int _line)
7252 - atomic_inc(&ns->count);
7253 + vxlprintk(VXD_CBIT(space, 0), "put_nsproxy(%p[%u])",
7254 + ns, atomic_read(&ns->count), _file, _line);
7255 + if (atomic_dec_and_test(&ns->count)) {
7261 diff -NurpP --minimal linux-3.13.10/include/linux/pid.h linux-3.13.10-vs2.3.6.11/include/linux/pid.h
7262 --- linux-3.13.10/include/linux/pid.h 2013-11-25 15:45:06.000000000 +0000
7263 +++ linux-3.13.10-vs2.3.6.11/include/linux/pid.h 2014-01-31 20:38:03.000000000 +0000
7264 @@ -8,7 +8,8 @@ enum pid_type
7274 @@ -170,6 +171,7 @@ static inline pid_t pid_nr(struct pid *p
7277 pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns);
7278 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns);
7279 pid_t pid_vnr(struct pid *pid);
7281 #define do_each_pid_task(pid, type, task) \
7282 diff -NurpP --minimal linux-3.13.10/include/linux/quotaops.h linux-3.13.10-vs2.3.6.11/include/linux/quotaops.h
7283 --- linux-3.13.10/include/linux/quotaops.h 2013-11-25 15:47:02.000000000 +0000
7284 +++ linux-3.13.10-vs2.3.6.11/include/linux/quotaops.h 2014-01-31 20:38:03.000000000 +0000
7286 #define _LINUX_QUOTAOPS_
7288 #include <linux/fs.h>
7289 +#include <linux/vs_dlimit.h>
7291 #define DQUOT_SPACE_WARN 0x1
7292 #define DQUOT_SPACE_RESERVE 0x2
7293 @@ -207,11 +208,12 @@ static inline void dquot_drop(struct ino
7295 static inline int dquot_alloc_inode(const struct inode *inode)
7298 + return dl_alloc_inode(inode);
7301 static inline void dquot_free_inode(const struct inode *inode)
7303 + dl_free_inode(inode);
7306 static inline int dquot_transfer(struct inode *inode, struct iattr *iattr)
7307 @@ -222,6 +224,10 @@ static inline int dquot_transfer(struct
7308 static inline int __dquot_alloc_space(struct inode *inode, qsize_t number,
7313 + if ((ret = dl_alloc_space(inode, number)))
7315 if (!(flags & DQUOT_SPACE_RESERVE))
7316 inode_add_bytes(inode, number);
7318 @@ -232,6 +238,7 @@ static inline void __dquot_free_space(st
7320 if (!(flags & DQUOT_SPACE_RESERVE))
7321 inode_sub_bytes(inode, number);
7322 + dl_free_space(inode, number);
7325 static inline int dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
7326 diff -NurpP --minimal linux-3.13.10/include/linux/sched.h linux-3.13.10-vs2.3.6.11/include/linux/sched.h
7327 --- linux-3.13.10/include/linux/sched.h 2014-01-22 20:39:11.000000000 +0000
7328 +++ linux-3.13.10-vs2.3.6.11/include/linux/sched.h 2014-01-31 20:38:03.000000000 +0000
7329 @@ -1237,6 +1237,14 @@ struct task_struct {
7331 struct seccomp seccomp;
7333 +/* vserver context data */
7334 + struct vx_info *vx_info;
7335 + struct nx_info *nx_info;
7341 /* Thread group tracking */
7344 @@ -1531,6 +1539,11 @@ struct pid_namespace;
7345 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
7346 struct pid_namespace *ns);
7348 +#include <linux/vserver/base.h>
7349 +#include <linux/vserver/context.h>
7350 +#include <linux/vserver/debug.h>
7351 +#include <linux/vserver/pid.h>
7353 static inline pid_t task_pid_nr(struct task_struct *tsk)
7356 @@ -1544,7 +1557,8 @@ static inline pid_t task_pid_nr_ns(struc
7358 static inline pid_t task_pid_vnr(struct task_struct *tsk)
7360 - return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7361 + // return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
7362 + return vx_map_pid(__task_pid_nr_ns(tsk, PIDTYPE_PID, NULL));
7366 @@ -1557,7 +1571,7 @@ pid_t task_tgid_nr_ns(struct task_struct
7368 static inline pid_t task_tgid_vnr(struct task_struct *tsk)
7370 - return pid_vnr(task_tgid(tsk));
7371 + return vx_map_tgid(pid_vnr(task_tgid(tsk)));
7375 diff -NurpP --minimal linux-3.13.10/include/linux/shmem_fs.h linux-3.13.10-vs2.3.6.11/include/linux/shmem_fs.h
7376 --- linux-3.13.10/include/linux/shmem_fs.h 2014-01-22 20:39:11.000000000 +0000
7377 +++ linux-3.13.10-vs2.3.6.11/include/linux/shmem_fs.h 2014-01-31 20:38:03.000000000 +0000
7380 /* inode in-kernel data */
7382 +#define TMPFS_SUPER_MAGIC 0x01021994
7385 struct shmem_inode_info {
7387 unsigned long flags;
7388 diff -NurpP --minimal linux-3.13.10/include/linux/stat.h linux-3.13.10-vs2.3.6.11/include/linux/stat.h
7389 --- linux-3.13.10/include/linux/stat.h 2012-12-11 03:30:57.000000000 +0000
7390 +++ linux-3.13.10-vs2.3.6.11/include/linux/stat.h 2014-01-31 20:38:03.000000000 +0000
7391 @@ -25,6 +25,7 @@ struct kstat {
7398 struct timespec atime;
7399 diff -NurpP --minimal linux-3.13.10/include/linux/sunrpc/auth.h linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/auth.h
7400 --- linux-3.13.10/include/linux/sunrpc/auth.h 2013-11-25 15:47:02.000000000 +0000
7401 +++ linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/auth.h 2014-01-31 20:38:03.000000000 +0000
7402 @@ -36,6 +36,7 @@ enum {
7407 struct group_info *group_info;
7408 const char *principal;
7409 unsigned long ac_flags;
7410 diff -NurpP --minimal linux-3.13.10/include/linux/sunrpc/clnt.h linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/clnt.h
7411 --- linux-3.13.10/include/linux/sunrpc/clnt.h 2014-01-22 20:39:11.000000000 +0000
7412 +++ linux-3.13.10-vs2.3.6.11/include/linux/sunrpc/clnt.h 2014-01-31 20:38:03.000000000 +0000
7413 @@ -51,7 +51,8 @@ struct rpc_clnt {
7414 cl_discrtry : 1,/* disconnect before retry */
7415 cl_noretranstimeo: 1,/* No retransmit timeouts */
7416 cl_autobind : 1,/* use getport() */
7417 - cl_chatty : 1;/* be verbose */
7418 + cl_chatty : 1,/* be verbose */
7419 + cl_tag : 1;/* context tagging */
7421 struct rpc_rtt * cl_rtt; /* RTO estimator data */
7422 const struct rpc_timeout *cl_timeout; /* Timeout strategy */
7423 diff -NurpP --minimal linux-3.13.10/include/linux/sysfs.h linux-3.13.10-vs2.3.6.11/include/linux/sysfs.h
7424 --- linux-3.13.10/include/linux/sysfs.h 2014-01-22 20:39:11.000000000 +0000
7425 +++ linux-3.13.10-vs2.3.6.11/include/linux/sysfs.h 2014-01-31 20:38:03.000000000 +0000
7427 #include <linux/stat.h>
7428 #include <linux/atomic.h>
7430 +#define SYSFS_SUPER_MAGIC 0x62656572
7434 struct bin_attribute;
7435 diff -NurpP --minimal linux-3.13.10/include/linux/types.h linux-3.13.10-vs2.3.6.11/include/linux/types.h
7436 --- linux-3.13.10/include/linux/types.h 2013-02-19 13:58:52.000000000 +0000
7437 +++ linux-3.13.10-vs2.3.6.11/include/linux/types.h 2014-01-31 20:38:03.000000000 +0000
7438 @@ -32,6 +32,9 @@ typedef __kernel_uid32_t uid_t;
7439 typedef __kernel_gid32_t gid_t;
7440 typedef __kernel_uid16_t uid16_t;
7441 typedef __kernel_gid16_t gid16_t;
7442 +typedef unsigned int vxid_t;
7443 +typedef unsigned int vnid_t;
7444 +typedef unsigned int vtag_t;
7446 typedef unsigned long uintptr_t;
7448 diff -NurpP --minimal linux-3.13.10/include/linux/uidgid.h linux-3.13.10-vs2.3.6.11/include/linux/uidgid.h
7449 --- linux-3.13.10/include/linux/uidgid.h 2012-12-11 03:30:57.000000000 +0000
7450 +++ linux-3.13.10-vs2.3.6.11/include/linux/uidgid.h 2014-01-31 20:38:03.000000000 +0000
7451 @@ -23,13 +23,17 @@ typedef struct {
7464 #define KUIDT_INIT(value) (kuid_t){ value }
7465 #define KGIDT_INIT(value) (kgid_t){ value }
7466 +#define KTAGT_INIT(value) (ktag_t){ value }
7468 static inline uid_t __kuid_val(kuid_t uid)
7470 @@ -41,11 +45,18 @@ static inline gid_t __kgid_val(kgid_t gi
7474 +static inline vtag_t __ktag_val(ktag_t tag)
7479 #define GLOBAL_ROOT_UID KUIDT_INIT(0)
7480 #define GLOBAL_ROOT_GID KGIDT_INIT(0)
7481 +#define GLOBAL_ROOT_TAG KTAGT_INIT(0)
7483 #define INVALID_UID KUIDT_INIT(-1)
7484 #define INVALID_GID KGIDT_INIT(-1)
7485 +#define INVALID_TAG KTAGT_INIT(-1)
7487 static inline bool uid_eq(kuid_t left, kuid_t right)
7489 @@ -77,6 +95,11 @@ static inline bool gid_eq(kgid_t left, k
7490 return __kgid_val(left) == __kgid_val(right);
7493 +static inline bool tag_eq(ktag_t left, ktag_t right)
7495 + return __ktag_val(left) == __ktag_val(right);
7498 static inline bool uid_gt(kuid_t left, kuid_t right)
7500 return __kuid_val(left) > __kuid_val(right);
7501 @@ -127,13 +150,21 @@ static inline bool gid_valid(kgid_t gid)
7502 return !gid_eq(gid, INVALID_GID);
7505 +static inline bool tag_valid(ktag_t tag)
7507 + return !tag_eq(tag, INVALID_TAG);
7510 #ifdef CONFIG_USER_NS
7512 extern kuid_t make_kuid(struct user_namespace *from, uid_t uid);
7513 extern kgid_t make_kgid(struct user_namespace *from, gid_t gid);
7514 +extern krag_t make_ktag(struct user_namespace *from, gid_t gid);
7516 extern uid_t from_kuid(struct user_namespace *to, kuid_t uid);
7517 extern gid_t from_kgid(struct user_namespace *to, kgid_t gid);
7518 +extern vtag_t from_ktag(struct user_namespace *to, ktag_t tag);
7520 extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid);
7521 extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid);
7523 @@ -159,6 +190,11 @@ static inline kgid_t make_kgid(struct us
7524 return KGIDT_INIT(gid);
7527 +static inline ktag_t make_ktag(struct user_namespace *from, vtag_t tag)
7529 + return KTAGT_INIT(tag);
7532 static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid)
7534 return __kuid_val(kuid);
7535 @@ -169,6 +205,11 @@ static inline gid_t from_kgid(struct use
7536 return __kgid_val(kgid);
7539 +static inline vtag_t from_ktag(struct user_namespace *to, ktag_t ktag)
7541 + return __ktag_val(ktag);
7544 static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid)
7546 uid_t uid = from_kuid(to, kuid);
7547 diff -NurpP --minimal linux-3.13.10/include/linux/vroot.h linux-3.13.10-vs2.3.6.11/include/linux/vroot.h
7548 --- linux-3.13.10/include/linux/vroot.h 1970-01-01 00:00:00.000000000 +0000
7549 +++ linux-3.13.10-vs2.3.6.11/include/linux/vroot.h 2014-01-31 20:38:03.000000000 +0000
7553 + * include/linux/vroot.h
7555 + * written by Herbert Pötzl, 9/11/2002
7556 + * ported to 2.6 by Herbert Pötzl, 30/12/2004
7558 + * Copyright (C) 2002-2007 by Herbert Pötzl.
7559 + * Redistribution of this file is permitted under the
7560 + * GNU General Public License.
7563 +#ifndef _LINUX_VROOT_H
7564 +#define _LINUX_VROOT_H
7569 +/* Possible states of device */
7575 +struct vroot_device {
7579 + struct semaphore vr_ctl_mutex;
7580 + struct block_device *vr_device;
7585 +typedef struct block_device *(vroot_grb_func)(struct block_device *);
7587 +extern int register_vroot_grb(vroot_grb_func *);
7588 +extern int unregister_vroot_grb(vroot_grb_func *);
7590 +#endif /* __KERNEL__ */
7592 +#define MAX_VROOT_DEFAULT 8
7595 + * IOCTL commands --- we will commandeer 0x56 ('V')
7598 +#define VROOT_SET_DEV 0x5600
7599 +#define VROOT_CLR_DEV 0x5601
7601 +#endif /* _LINUX_VROOT_H */
7602 diff -NurpP --minimal linux-3.13.10/include/linux/vs_base.h linux-3.13.10-vs2.3.6.11/include/linux/vs_base.h
7603 --- linux-3.13.10/include/linux/vs_base.h 1970-01-01 00:00:00.000000000 +0000
7604 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_base.h 2014-01-31 20:38:03.000000000 +0000
7609 +#include "vserver/base.h"
7610 +#include "vserver/check.h"
7611 +#include "vserver/debug.h"
7614 +#warning duplicate inclusion
7616 diff -NurpP --minimal linux-3.13.10/include/linux/vs_context.h linux-3.13.10-vs2.3.6.11/include/linux/vs_context.h
7617 --- linux-3.13.10/include/linux/vs_context.h 1970-01-01 00:00:00.000000000 +0000
7618 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_context.h 2014-01-31 20:38:03.000000000 +0000
7620 +#ifndef _VS_CONTEXT_H
7621 +#define _VS_CONTEXT_H
7623 +#include "vserver/base.h"
7624 +#include "vserver/check.h"
7625 +#include "vserver/context.h"
7626 +#include "vserver/history.h"
7627 +#include "vserver/debug.h"
7629 +#include <linux/sched.h>
7632 +#define get_vx_info(i) __get_vx_info(i, __FILE__, __LINE__, __HERE__)
7634 +static inline struct vx_info *__get_vx_info(struct vx_info *vxi,
7635 + const char *_file, int _line, void *_here)
7640 + vxlprintk(VXD_CBIT(xid, 2), "get_vx_info(%p[#%d.%d])",
7641 + vxi, vxi ? vxi->vx_id : 0,
7642 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7644 + __vxh_get_vx_info(vxi, _here);
7646 + atomic_inc(&vxi->vx_usecnt);
7651 +extern void free_vx_info(struct vx_info *);
7653 +#define put_vx_info(i) __put_vx_info(i, __FILE__, __LINE__, __HERE__)
7655 +static inline void __put_vx_info(struct vx_info *vxi,
7656 + const char *_file, int _line, void *_here)
7661 + vxlprintk(VXD_CBIT(xid, 2), "put_vx_info(%p[#%d.%d])",
7662 + vxi, vxi ? vxi->vx_id : 0,
7663 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7665 + __vxh_put_vx_info(vxi, _here);
7667 + if (atomic_dec_and_test(&vxi->vx_usecnt))
7668 + free_vx_info(vxi);
7672 +#define init_vx_info(p, i) \
7673 + __init_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7675 +static inline void __init_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7676 + const char *_file, int _line, void *_here)
7679 + vxlprintk(VXD_CBIT(xid, 3),
7680 + "init_vx_info(%p[#%d.%d])",
7681 + vxi, vxi ? vxi->vx_id : 0,
7682 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7684 + __vxh_init_vx_info(vxi, vxp, _here);
7686 + atomic_inc(&vxi->vx_usecnt);
7692 +#define set_vx_info(p, i) \
7693 + __set_vx_info(p, i, __FILE__, __LINE__, __HERE__)
7695 +static inline void __set_vx_info(struct vx_info **vxp, struct vx_info *vxi,
7696 + const char *_file, int _line, void *_here)
7698 + struct vx_info *vxo;
7703 + vxlprintk(VXD_CBIT(xid, 3), "set_vx_info(%p[#%d.%d])",
7704 + vxi, vxi ? vxi->vx_id : 0,
7705 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7707 + __vxh_set_vx_info(vxi, vxp, _here);
7709 + atomic_inc(&vxi->vx_usecnt);
7710 + vxo = xchg(vxp, vxi);
7715 +#define clr_vx_info(p) __clr_vx_info(p, __FILE__, __LINE__, __HERE__)
7717 +static inline void __clr_vx_info(struct vx_info **vxp,
7718 + const char *_file, int _line, void *_here)
7720 + struct vx_info *vxo;
7722 + vxo = xchg(vxp, NULL);
7726 + vxlprintk(VXD_CBIT(xid, 3), "clr_vx_info(%p[#%d.%d])",
7727 + vxo, vxo ? vxo->vx_id : 0,
7728 + vxo ? atomic_read(&vxo->vx_usecnt) : 0,
7730 + __vxh_clr_vx_info(vxo, vxp, _here);
7732 + if (atomic_dec_and_test(&vxo->vx_usecnt))
7733 + free_vx_info(vxo);
7737 +#define claim_vx_info(v, p) \
7738 + __claim_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7740 +static inline void __claim_vx_info(struct vx_info *vxi,
7741 + struct task_struct *task,
7742 + const char *_file, int _line, void *_here)
7744 + vxlprintk(VXD_CBIT(xid, 3), "claim_vx_info(%p[#%d.%d.%d]) %p",
7745 + vxi, vxi ? vxi->vx_id : 0,
7746 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7747 + vxi ? atomic_read(&vxi->vx_tasks) : 0,
7748 + task, _file, _line);
7749 + __vxh_claim_vx_info(vxi, task, _here);
7751 + atomic_inc(&vxi->vx_tasks);
7755 +extern void unhash_vx_info(struct vx_info *);
7757 +#define release_vx_info(v, p) \
7758 + __release_vx_info(v, p, __FILE__, __LINE__, __HERE__)
7760 +static inline void __release_vx_info(struct vx_info *vxi,
7761 + struct task_struct *task,
7762 + const char *_file, int _line, void *_here)
7764 + vxlprintk(VXD_CBIT(xid, 3), "release_vx_info(%p[#%d.%d.%d]) %p",
7765 + vxi, vxi ? vxi->vx_id : 0,
7766 + vxi ? atomic_read(&vxi->vx_usecnt) : 0,
7767 + vxi ? atomic_read(&vxi->vx_tasks) : 0,
7768 + task, _file, _line);
7769 + __vxh_release_vx_info(vxi, task, _here);
7773 + if (atomic_dec_and_test(&vxi->vx_tasks))
7774 + unhash_vx_info(vxi);
7778 +#define task_get_vx_info(p) \
7779 + __task_get_vx_info(p, __FILE__, __LINE__, __HERE__)
7781 +static inline struct vx_info *__task_get_vx_info(struct task_struct *p,
7782 + const char *_file, int _line, void *_here)
7784 + struct vx_info *vxi;
7787 + vxlprintk(VXD_CBIT(xid, 5), "task_get_vx_info(%p)",
7789 + vxi = __get_vx_info(p->vx_info, _file, _line, _here);
7795 +static inline void __wakeup_vx_info(struct vx_info *vxi)
7797 + if (waitqueue_active(&vxi->vx_wait))
7798 + wake_up_interruptible(&vxi->vx_wait);
7802 +#define enter_vx_info(v, s) __enter_vx_info(v, s, __FILE__, __LINE__)
7804 +static inline void __enter_vx_info(struct vx_info *vxi,
7805 + struct vx_info_save *vxis, const char *_file, int _line)
7807 + vxlprintk(VXD_CBIT(xid, 5), "enter_vx_info(%p[#%d],%p) %p[#%d,%p]",
7808 + vxi, vxi ? vxi->vx_id : 0, vxis, current,
7809 + current->xid, current->vx_info, _file, _line);
7810 + vxis->vxi = xchg(¤t->vx_info, vxi);
7811 + vxis->xid = current->xid;
7812 + current->xid = vxi ? vxi->vx_id : 0;
7815 +#define leave_vx_info(s) __leave_vx_info(s, __FILE__, __LINE__)
7817 +static inline void __leave_vx_info(struct vx_info_save *vxis,
7818 + const char *_file, int _line)
7820 + vxlprintk(VXD_CBIT(xid, 5), "leave_vx_info(%p[#%d,%p]) %p[#%d,%p]",
7821 + vxis, vxis->xid, vxis->vxi, current,
7822 + current->xid, current->vx_info, _file, _line);
7823 + (void)xchg(¤t->vx_info, vxis->vxi);
7824 + current->xid = vxis->xid;
7828 +static inline void __enter_vx_admin(struct vx_info_save *vxis)
7830 + vxis->vxi = xchg(¤t->vx_info, NULL);
7831 + vxis->xid = xchg(¤t->xid, (vxid_t)0);
7834 +static inline void __leave_vx_admin(struct vx_info_save *vxis)
7836 + (void)xchg(¤t->xid, vxis->xid);
7837 + (void)xchg(¤t->vx_info, vxis->vxi);
7840 +#define task_is_init(p) \
7841 + __task_is_init(p, __FILE__, __LINE__, __HERE__)
7843 +static inline int __task_is_init(struct task_struct *p,
7844 + const char *_file, int _line, void *_here)
7846 + int is_init = is_global_init(p);
7850 + is_init = p->vx_info->vx_initpid == p->pid;
7855 +extern void exit_vx_info(struct task_struct *, int);
7856 +extern void exit_vx_info_early(struct task_struct *, int);
7860 +#warning duplicate inclusion
7862 diff -NurpP --minimal linux-3.13.10/include/linux/vs_cowbl.h linux-3.13.10-vs2.3.6.11/include/linux/vs_cowbl.h
7863 --- linux-3.13.10/include/linux/vs_cowbl.h 1970-01-01 00:00:00.000000000 +0000
7864 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_cowbl.h 2014-01-31 20:38:03.000000000 +0000
7866 +#ifndef _VS_COWBL_H
7867 +#define _VS_COWBL_H
7869 +#include <linux/fs.h>
7870 +#include <linux/dcache.h>
7871 +#include <linux/namei.h>
7872 +#include <linux/slab.h>
7874 +extern struct dentry *cow_break_link(const char *pathname);
7876 +static inline int cow_check_and_break(struct path *path)
7878 + struct inode *inode = path->dentry->d_inode;
7881 + /* do we need this check? */
7882 + if (IS_RDONLY(inode))
7885 + if (IS_COW(inode)) {
7886 + if (IS_COW_LINK(inode)) {
7887 + struct dentry *new_dentry, *old_dentry = path->dentry;
7890 + buf = kmalloc(PATH_MAX, GFP_KERNEL);
7894 + pp = d_path(path, buf, PATH_MAX);
7895 + new_dentry = cow_break_link(pp);
7897 + if (!IS_ERR(new_dentry)) {
7898 + path->dentry = new_dentry;
7901 + error = PTR_ERR(new_dentry);
7903 + inode->i_flags &= ~(S_IXUNLINK | S_IMMUTABLE);
7904 + inode->i_ctime = CURRENT_TIME;
7905 + mark_inode_dirty(inode);
7912 +#warning duplicate inclusion
7914 diff -NurpP --minimal linux-3.13.10/include/linux/vs_cvirt.h linux-3.13.10-vs2.3.6.11/include/linux/vs_cvirt.h
7915 --- linux-3.13.10/include/linux/vs_cvirt.h 1970-01-01 00:00:00.000000000 +0000
7916 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_cvirt.h 2014-01-31 20:38:03.000000000 +0000
7918 +#ifndef _VS_CVIRT_H
7919 +#define _VS_CVIRT_H
7921 +#include "vserver/cvirt.h"
7922 +#include "vserver/context.h"
7923 +#include "vserver/base.h"
7924 +#include "vserver/check.h"
7925 +#include "vserver/debug.h"
7928 +static inline void vx_activate_task(struct task_struct *p)
7930 + struct vx_info *vxi;
7932 + if ((vxi = p->vx_info)) {
7933 + vx_update_load(vxi);
7934 + atomic_inc(&vxi->cvirt.nr_running);
7938 +static inline void vx_deactivate_task(struct task_struct *p)
7940 + struct vx_info *vxi;
7942 + if ((vxi = p->vx_info)) {
7943 + vx_update_load(vxi);
7944 + atomic_dec(&vxi->cvirt.nr_running);
7948 +static inline void vx_uninterruptible_inc(struct task_struct *p)
7950 + struct vx_info *vxi;
7952 + if ((vxi = p->vx_info))
7953 + atomic_inc(&vxi->cvirt.nr_uninterruptible);
7956 +static inline void vx_uninterruptible_dec(struct task_struct *p)
7958 + struct vx_info *vxi;
7960 + if ((vxi = p->vx_info))
7961 + atomic_dec(&vxi->cvirt.nr_uninterruptible);
7966 +#warning duplicate inclusion
7968 diff -NurpP --minimal linux-3.13.10/include/linux/vs_device.h linux-3.13.10-vs2.3.6.11/include/linux/vs_device.h
7969 --- linux-3.13.10/include/linux/vs_device.h 1970-01-01 00:00:00.000000000 +0000
7970 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_device.h 2014-01-31 20:38:03.000000000 +0000
7972 +#ifndef _VS_DEVICE_H
7973 +#define _VS_DEVICE_H
7975 +#include "vserver/base.h"
7976 +#include "vserver/device.h"
7977 +#include "vserver/debug.h"
7980 +#ifdef CONFIG_VSERVER_DEVICE
7982 +int vs_map_device(struct vx_info *, dev_t, dev_t *, umode_t);
7984 +#define vs_device_perm(v, d, m, p) \
7985 + ((vs_map_device(current_vx_info(), d, NULL, m) & (p)) == (p))
7990 +int vs_map_device(struct vx_info *vxi,
7991 + dev_t device, dev_t *target, umode_t mode)
7998 +#define vs_device_perm(v, d, m, p) ((p) == (p))
8003 +#define vs_map_chrdev(d, t, p) \
8004 + ((vs_map_device(current_vx_info(), d, t, S_IFCHR) & (p)) == (p))
8005 +#define vs_map_blkdev(d, t, p) \
8006 + ((vs_map_device(current_vx_info(), d, t, S_IFBLK) & (p)) == (p))
8008 +#define vs_chrdev_perm(d, p) \
8009 + vs_device_perm(current_vx_info(), d, S_IFCHR, p)
8010 +#define vs_blkdev_perm(d, p) \
8011 + vs_device_perm(current_vx_info(), d, S_IFBLK, p)
8015 +#warning duplicate inclusion
8017 diff -NurpP --minimal linux-3.13.10/include/linux/vs_dlimit.h linux-3.13.10-vs2.3.6.11/include/linux/vs_dlimit.h
8018 --- linux-3.13.10/include/linux/vs_dlimit.h 1970-01-01 00:00:00.000000000 +0000
8019 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_dlimit.h 2014-01-31 20:38:03.000000000 +0000
8021 +#ifndef _VS_DLIMIT_H
8022 +#define _VS_DLIMIT_H
8024 +#include <linux/fs.h>
8026 +#include "vserver/dlimit.h"
8027 +#include "vserver/base.h"
8028 +#include "vserver/debug.h"
8031 +#define get_dl_info(i) __get_dl_info(i, __FILE__, __LINE__)
8033 +static inline struct dl_info *__get_dl_info(struct dl_info *dli,
8034 + const char *_file, int _line)
8038 + vxlprintk(VXD_CBIT(dlim, 4), "get_dl_info(%p[#%d.%d])",
8039 + dli, dli ? dli->dl_tag : 0,
8040 + dli ? atomic_read(&dli->dl_usecnt) : 0,
8042 + atomic_inc(&dli->dl_usecnt);
8047 +#define free_dl_info(i) \
8048 + call_rcu(&(i)->dl_rcu, rcu_free_dl_info)
8050 +#define put_dl_info(i) __put_dl_info(i, __FILE__, __LINE__)
8052 +static inline void __put_dl_info(struct dl_info *dli,
8053 + const char *_file, int _line)
8057 + vxlprintk(VXD_CBIT(dlim, 4), "put_dl_info(%p[#%d.%d])",
8058 + dli, dli ? dli->dl_tag : 0,
8059 + dli ? atomic_read(&dli->dl_usecnt) : 0,
8061 + if (atomic_dec_and_test(&dli->dl_usecnt))
8062 + free_dl_info(dli);
8066 +#define __dlimit_char(d) ((d) ? '*' : ' ')
8068 +static inline int __dl_alloc_space(struct super_block *sb,
8069 + vtag_t tag, dlsize_t nr, const char *file, int line)
8071 + struct dl_info *dli = NULL;
8076 + dli = locate_dl_info(sb, tag);
8080 + spin_lock(&dli->dl_lock);
8081 + ret = (dli->dl_space_used + nr > dli->dl_space_total);
8083 + dli->dl_space_used += nr;
8084 + spin_unlock(&dli->dl_lock);
8087 + vxlprintk(VXD_CBIT(dlim, 1),
8088 + "ALLOC (%p,#%d)%c %lld bytes (%d)",
8089 + sb, tag, __dlimit_char(dli), (long long)nr,
8091 + return ret ? -ENOSPC : 0;
8094 +static inline void __dl_free_space(struct super_block *sb,
8095 + vtag_t tag, dlsize_t nr, const char *_file, int _line)
8097 + struct dl_info *dli = NULL;
8101 + dli = locate_dl_info(sb, tag);
8105 + spin_lock(&dli->dl_lock);
8106 + if (dli->dl_space_used > nr)
8107 + dli->dl_space_used -= nr;
8109 + dli->dl_space_used = 0;
8110 + spin_unlock(&dli->dl_lock);
8113 + vxlprintk(VXD_CBIT(dlim, 1),
8114 + "FREE (%p,#%d)%c %lld bytes",
8115 + sb, tag, __dlimit_char(dli), (long long)nr,
8119 +static inline int __dl_alloc_inode(struct super_block *sb,
8120 + vtag_t tag, const char *_file, int _line)
8122 + struct dl_info *dli;
8125 + dli = locate_dl_info(sb, tag);
8129 + spin_lock(&dli->dl_lock);
8130 + dli->dl_inodes_used++;
8131 + ret = (dli->dl_inodes_used > dli->dl_inodes_total);
8132 + spin_unlock(&dli->dl_lock);
8135 + vxlprintk(VXD_CBIT(dlim, 0),
8136 + "ALLOC (%p,#%d)%c inode (%d)",
8137 + sb, tag, __dlimit_char(dli), ret, _file, _line);
8138 + return ret ? -ENOSPC : 0;
8141 +static inline void __dl_free_inode(struct super_block *sb,
8142 + vtag_t tag, const char *_file, int _line)
8144 + struct dl_info *dli;
8146 + dli = locate_dl_info(sb, tag);
8150 + spin_lock(&dli->dl_lock);
8151 + if (dli->dl_inodes_used > 1)
8152 + dli->dl_inodes_used--;
8154 + dli->dl_inodes_used = 0;
8155 + spin_unlock(&dli->dl_lock);
8158 + vxlprintk(VXD_CBIT(dlim, 0),
8159 + "FREE (%p,#%d)%c inode",
8160 + sb, tag, __dlimit_char(dli), _file, _line);
8163 +static inline void __dl_adjust_block(struct super_block *sb, vtag_t tag,
8164 + unsigned long long *free_blocks, unsigned long long *root_blocks,
8165 + const char *_file, int _line)
8167 + struct dl_info *dli;
8168 + uint64_t broot, bfree;
8170 + dli = locate_dl_info(sb, tag);
8174 + spin_lock(&dli->dl_lock);
8175 + broot = (dli->dl_space_total -
8176 + (dli->dl_space_total >> 10) * dli->dl_nrlmult)
8177 + >> sb->s_blocksize_bits;
8178 + bfree = (dli->dl_space_total - dli->dl_space_used)
8179 + >> sb->s_blocksize_bits;
8180 + spin_unlock(&dli->dl_lock);
8182 + vxlprintk(VXD_CBIT(dlim, 2),
8183 + "ADJUST: %lld,%lld on %lld,%lld [mult=%d]",
8184 + (long long)bfree, (long long)broot,
8185 + *free_blocks, *root_blocks, dli->dl_nrlmult,
8187 + if (free_blocks) {
8188 + if (*free_blocks > bfree)
8189 + *free_blocks = bfree;
8191 + if (root_blocks) {
8192 + if (*root_blocks > broot)
8193 + *root_blocks = broot;
8198 +#define dl_prealloc_space(in, bytes) \
8199 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8200 + __FILE__, __LINE__ )
8202 +#define dl_alloc_space(in, bytes) \
8203 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8204 + __FILE__, __LINE__ )
8206 +#define dl_reserve_space(in, bytes) \
8207 + __dl_alloc_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8208 + __FILE__, __LINE__ )
8210 +#define dl_claim_space(in, bytes) (0)
8212 +#define dl_release_space(in, bytes) \
8213 + __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8214 + __FILE__, __LINE__ )
8216 +#define dl_free_space(in, bytes) \
8217 + __dl_free_space((in)->i_sb, i_tag_read(in), (dlsize_t)(bytes), \
8218 + __FILE__, __LINE__ )
8222 +#define dl_alloc_inode(in) \
8223 + __dl_alloc_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8225 +#define dl_free_inode(in) \
8226 + __dl_free_inode((in)->i_sb, i_tag_read(in), __FILE__, __LINE__ )
8229 +#define dl_adjust_block(sb, tag, fb, rb) \
8230 + __dl_adjust_block(sb, tag, fb, rb, __FILE__, __LINE__ )
8234 +#warning duplicate inclusion
8236 diff -NurpP --minimal linux-3.13.10/include/linux/vs_inet.h linux-3.13.10-vs2.3.6.11/include/linux/vs_inet.h
8237 --- linux-3.13.10/include/linux/vs_inet.h 1970-01-01 00:00:00.000000000 +0000
8238 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_inet.h 2014-02-01 00:32:45.000000000 +0000
8243 +#include "vserver/base.h"
8244 +#include "vserver/network.h"
8245 +#include "vserver/debug.h"
8247 +#define IPI_LOOPBACK htonl(INADDR_LOOPBACK)
8249 +#define NXAV4(a) NIPQUAD((a)->ip[0]), NIPQUAD((a)->ip[1]), \
8250 + NIPQUAD((a)->mask), (a)->type
8251 +#define NXAV4_FMT "[" NIPQUAD_FMT "-" NIPQUAD_FMT "/" NIPQUAD_FMT ":%04x]"
8253 +#define NIPQUAD(addr) \
8254 + ((unsigned char *)&addr)[0], \
8255 + ((unsigned char *)&addr)[1], \
8256 + ((unsigned char *)&addr)[2], \
8257 + ((unsigned char *)&addr)[3]
8259 +#define NIPQUAD_FMT "%u.%u.%u.%u"
8263 +int v4_addr_match(struct nx_addr_v4 *nxa, __be32 addr, uint16_t tmask)
8265 + __be32 ip = nxa->ip[0].s_addr;
8266 + __be32 mask = nxa->mask.s_addr;
8267 + __be32 bcast = ip | ~mask;
8270 + switch (nxa->type & tmask) {
8271 + case NXA_TYPE_MASK:
8272 + ret = (ip == (addr & mask));
8274 + case NXA_TYPE_ADDR:
8278 + /* fall through to broadcast */
8279 + case NXA_MOD_BCAST:
8280 + ret = ((tmask & NXA_MOD_BCAST) && (addr == bcast));
8282 + case NXA_TYPE_RANGE:
8283 + ret = ((nxa->ip[0].s_addr <= addr) &&
8284 + (nxa->ip[1].s_addr > addr));
8286 + case NXA_TYPE_ANY:
8291 + vxdprintk(VXD_CBIT(net, 0),
8292 + "v4_addr_match(%p" NXAV4_FMT "," NIPQUAD_FMT ",%04x) = %d",
8293 + nxa, NXAV4(nxa), NIPQUAD(addr), tmask, ret);
8298 +int v4_addr_in_nx_info(struct nx_info *nxi, __be32 addr, uint16_t tmask)
8300 + struct nx_addr_v4 *nxa;
8301 + unsigned long irqflags;
8308 + /* allow 127.0.0.1 when remapping lback */
8309 + if ((tmask & NXA_LOOPBACK) &&
8310 + (addr == IPI_LOOPBACK) &&
8311 + nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8314 + /* check for lback address */
8315 + if ((tmask & NXA_MOD_LBACK) &&
8316 + (nxi->v4_lback.s_addr == addr))
8319 + /* check for broadcast address */
8320 + if ((tmask & NXA_MOD_BCAST) &&
8321 + (nxi->v4_bcast.s_addr == addr))
8325 + /* check for v4 addresses */
8326 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
8327 + for (nxa = &nxi->v4; nxa; nxa = nxa->next)
8328 + if (v4_addr_match(nxa, addr, tmask))
8332 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8334 + vxdprintk(VXD_CBIT(net, 0),
8335 + "v4_addr_in_nx_info(%p[#%u]," NIPQUAD_FMT ",%04x) = %d",
8336 + nxi, nxi ? nxi->nx_id : 0, NIPQUAD(addr), tmask, ret);
8341 +int v4_nx_addr_match(struct nx_addr_v4 *nxa, struct nx_addr_v4 *addr, uint16_t mask)
8343 + /* FIXME: needs full range checks */
8344 + return v4_addr_match(nxa, addr->ip[0].s_addr, mask);
8348 +int v4_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v4 *nxa, uint16_t mask)
8350 + struct nx_addr_v4 *ptr;
8351 + unsigned long irqflags;
8354 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
8355 + for (ptr = &nxi->v4; ptr; ptr = ptr->next)
8356 + if (v4_nx_addr_match(ptr, nxa, mask))
8360 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8364 +#include <net/inet_sock.h>
8367 + * Check if a given address matches for a socket
8369 + * nxi: the socket's nx_info if any
8370 + * addr: to be verified address
8373 +int v4_sock_addr_match (
8374 + struct nx_info *nxi,
8375 + struct inet_sock *inet,
8378 + __be32 saddr = inet->inet_rcv_saddr;
8379 + __be32 bcast = nxi ? nxi->v4_bcast.s_addr : INADDR_BROADCAST;
8381 + if (addr && (saddr == addr || bcast == addr))
8384 + return v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND);
8389 +/* inet related checks and helpers */
8398 +#include <linux/netdevice.h>
8399 +#include <linux/inetdevice.h>
8400 +#include <net/inet_sock.h>
8401 +#include <net/inet_timewait_sock.h>
8404 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8405 +int v4_dev_in_nx_info(struct net_device *, struct nx_info *);
8406 +int nx_v4_addr_conflict(struct nx_info *, struct nx_info *);
8410 + * check if address is covered by socket
8412 + * sk: the socket to check against
8413 + * addr: the address in question (must be != 0)
8417 +int __v4_addr_match_socket(const struct sock *sk, struct nx_addr_v4 *nxa)
8419 + struct nx_info *nxi = sk->sk_nx_info;
8420 + __be32 saddr = sk->sk_rcv_saddr;
8422 + vxdprintk(VXD_CBIT(net, 5),
8423 + "__v4_addr_in_socket(%p," NXAV4_FMT ") %p:" NIPQUAD_FMT " %p;%lx",
8424 + sk, NXAV4(nxa), nxi, NIPQUAD(saddr), sk->sk_socket,
8425 + (sk->sk_socket?sk->sk_socket->flags:0));
8427 + if (saddr) { /* direct address match */
8428 + return v4_addr_match(nxa, saddr, -1);
8429 + } else if (nxi) { /* match against nx_info */
8430 + return v4_nx_addr_in_nx_info(nxi, nxa, -1);
8431 + } else { /* unrestricted any socket */
8439 +int nx_dev_visible(struct nx_info *nxi, struct net_device *dev)
8441 + vxdprintk(VXD_CBIT(net, 1),
8442 + "nx_dev_visible(%p[#%u],%p " VS_Q("%s") ") %d",
8443 + nxi, nxi ? nxi->nx_id : 0, dev, dev->name,
8444 + nxi ? dev_in_nx_info(dev, nxi) : 0);
8446 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8448 + if (dev_in_nx_info(dev, nxi))
8455 +int v4_ifa_in_nx_info(struct in_ifaddr *ifa, struct nx_info *nxi)
8461 + return v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW);
8465 +int nx_v4_ifa_visible(struct nx_info *nxi, struct in_ifaddr *ifa)
8467 + vxdprintk(VXD_CBIT(net, 1), "nx_v4_ifa_visible(%p[#%u],%p) %d",
8468 + nxi, nxi ? nxi->nx_id : 0, ifa,
8469 + nxi ? v4_ifa_in_nx_info(ifa, nxi) : 0);
8471 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8473 + if (v4_ifa_in_nx_info(ifa, nxi))
8479 +struct nx_v4_sock_addr {
8480 + __be32 saddr; /* Address used for validation */
8481 + __be32 baddr; /* Address used for socket bind */
8485 +int v4_map_sock_addr(struct inet_sock *inet, struct sockaddr_in *addr,
8486 + struct nx_v4_sock_addr *nsa)
8488 + struct sock *sk = &inet->sk;
8489 + struct nx_info *nxi = sk->sk_nx_info;
8490 + __be32 saddr = addr->sin_addr.s_addr;
8491 + __be32 baddr = saddr;
8493 + vxdprintk(VXD_CBIT(net, 3),
8494 + "inet_bind(%p)* %p,%p;%lx " NIPQUAD_FMT,
8495 + sk, sk->sk_nx_info, sk->sk_socket,
8496 + (sk->sk_socket ? sk->sk_socket->flags : 0),
8500 + if (saddr == INADDR_ANY) {
8501 + if (nx_info_flags(nxi, NXF_SINGLE_IP, 0))
8502 + baddr = nxi->v4.ip[0].s_addr;
8503 + } else if (saddr == IPI_LOOPBACK) {
8504 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8505 + baddr = nxi->v4_lback.s_addr;
8506 + } else if (!ipv4_is_multicast(saddr) ||
8507 + !nx_info_ncaps(nxi, NXC_MULTICAST)) {
8508 + /* normal address bind */
8509 + if (!v4_addr_in_nx_info(nxi, saddr, NXA_MASK_BIND))
8510 + return -EADDRNOTAVAIL;
8514 + vxdprintk(VXD_CBIT(net, 3),
8515 + "inet_bind(%p) " NIPQUAD_FMT ", " NIPQUAD_FMT,
8516 + sk, NIPQUAD(saddr), NIPQUAD(baddr));
8518 + nsa->saddr = saddr;
8519 + nsa->baddr = baddr;
8524 +void v4_set_sock_addr(struct inet_sock *inet, struct nx_v4_sock_addr *nsa)
8526 + inet->inet_saddr = nsa->baddr;
8527 + inet->inet_rcv_saddr = nsa->baddr;
8532 + * helper to simplify inet_lookup_listener
8534 + * nxi: the socket's nx_info if any
8535 + * addr: to be verified address
8536 + * saddr: socket address
8538 +static inline int v4_inet_addr_match (
8539 + struct nx_info *nxi,
8543 + if (addr && (saddr == addr))
8546 + return nxi ? v4_addr_in_nx_info(nxi, addr, NXA_MASK_BIND) : 1;
8550 +static inline __be32 nx_map_sock_lback(struct nx_info *nxi, __be32 addr)
8552 + if (nx_info_flags(nxi, NXF_HIDE_LBACK, 0) &&
8553 + (addr == nxi->v4_lback.s_addr))
8554 + return IPI_LOOPBACK;
8559 +int nx_info_has_v4(struct nx_info *nxi)
8565 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0))
8570 +#else /* CONFIG_INET */
8573 +int nx_dev_visible(struct nx_info *n, struct net_device *d)
8579 +int nx_v4_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8585 +int v4_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8591 +int nx_info_has_v4(struct nx_info *nxi)
8596 +#endif /* CONFIG_INET */
8598 +#define current_nx_info_has_v4() \
8599 + nx_info_has_v4(current_nx_info())
8602 +// #warning duplicate inclusion
8604 diff -NurpP --minimal linux-3.13.10/include/linux/vs_inet6.h linux-3.13.10-vs2.3.6.11/include/linux/vs_inet6.h
8605 --- linux-3.13.10/include/linux/vs_inet6.h 1970-01-01 00:00:00.000000000 +0000
8606 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_inet6.h 2014-02-01 00:35:02.000000000 +0000
8608 +#ifndef _VS_INET6_H
8609 +#define _VS_INET6_H
8611 +#include "vserver/base.h"
8612 +#include "vserver/network.h"
8613 +#include "vserver/debug.h"
8615 +#include <net/ipv6.h>
8617 +#define NXAV6(a) &(a)->ip, &(a)->mask, (a)->prefix, (a)->type
8618 +#define NXAV6_FMT "[%pI6/%pI6/%d:%04x]"
8624 +int v6_addr_match(struct nx_addr_v6 *nxa,
8625 + const struct in6_addr *addr, uint16_t mask)
8629 + switch (nxa->type & mask) {
8630 + case NXA_TYPE_MASK:
8631 + ret = ipv6_masked_addr_cmp(&nxa->ip, &nxa->mask, addr);
8633 + case NXA_TYPE_ADDR:
8634 + ret = ipv6_addr_equal(&nxa->ip, addr);
8636 + case NXA_TYPE_ANY:
8640 + vxdprintk(VXD_CBIT(net, 0),
8641 + "v6_addr_match(%p" NXAV6_FMT ",%pI6,%04x) = %d",
8642 + nxa, NXAV6(nxa), addr, mask, ret);
8647 +int v6_addr_in_nx_info(struct nx_info *nxi,
8648 + const struct in6_addr *addr, uint16_t mask)
8650 + struct nx_addr_v6 *nxa;
8651 + unsigned long irqflags;
8657 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
8658 + for (nxa = &nxi->v6; nxa; nxa = nxa->next)
8659 + if (v6_addr_match(nxa, addr, mask))
8663 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8665 + vxdprintk(VXD_CBIT(net, 0),
8666 + "v6_addr_in_nx_info(%p[#%u],%pI6,%04x) = %d",
8667 + nxi, nxi ? nxi->nx_id : 0, addr, mask, ret);
8672 +int v6_nx_addr_match(struct nx_addr_v6 *nxa, struct nx_addr_v6 *addr, uint16_t mask)
8674 + /* FIXME: needs full range checks */
8675 + return v6_addr_match(nxa, &addr->ip, mask);
8679 +int v6_nx_addr_in_nx_info(struct nx_info *nxi, struct nx_addr_v6 *nxa, uint16_t mask)
8681 + struct nx_addr_v6 *ptr;
8682 + unsigned long irqflags;
8685 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
8686 + for (ptr = &nxi->v6; ptr; ptr = ptr->next)
8687 + if (v6_nx_addr_match(ptr, nxa, mask))
8691 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
8697 + * Check if a given address matches for a socket
8699 + * nxi: the socket's nx_info if any
8700 + * addr: to be verified address
8703 +int v6_sock_addr_match (
8704 + struct nx_info *nxi,
8705 + struct inet_sock *inet,
8706 + struct in6_addr *addr)
8708 + struct sock *sk = &inet->sk;
8709 + const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8711 + if (!ipv6_addr_any(addr) &&
8712 + ipv6_addr_equal(saddr, addr))
8714 + if (ipv6_addr_any(saddr))
8715 + return v6_addr_in_nx_info(nxi, addr, -1);
8720 + * check if address is covered by socket
8722 + * sk: the socket to check against
8723 + * addr: the address in question (must be != 0)
8727 +int __v6_addr_match_socket(const struct sock *sk, struct nx_addr_v6 *nxa)
8729 + struct nx_info *nxi = sk->sk_nx_info;
8730 + const struct in6_addr *saddr = inet6_rcv_saddr(sk);
8732 + vxdprintk(VXD_CBIT(net, 5),
8733 + "__v6_addr_in_socket(%p," NXAV6_FMT ") %p:%pI6 %p;%lx",
8734 + sk, NXAV6(nxa), nxi, saddr, sk->sk_socket,
8735 + (sk->sk_socket?sk->sk_socket->flags:0));
8737 + if (!ipv6_addr_any(saddr)) { /* direct address match */
8738 + return v6_addr_match(nxa, saddr, -1);
8739 + } else if (nxi) { /* match against nx_info */
8740 + return v6_nx_addr_in_nx_info(nxi, nxa, -1);
8741 + } else { /* unrestricted any socket */
8747 +/* inet related checks and helpers */
8755 +#include <linux/netdevice.h>
8756 +#include <linux/inetdevice.h>
8757 +#include <net/inet_timewait_sock.h>
8760 +int dev_in_nx_info(struct net_device *, struct nx_info *);
8761 +int v6_dev_in_nx_info(struct net_device *, struct nx_info *);
8762 +int nx_v6_addr_conflict(struct nx_info *, struct nx_info *);
8767 +int v6_ifa_in_nx_info(struct inet6_ifaddr *ifa, struct nx_info *nxi)
8773 + return v6_addr_in_nx_info(nxi, &ifa->addr, -1);
8777 +int nx_v6_ifa_visible(struct nx_info *nxi, struct inet6_ifaddr *ifa)
8779 + vxdprintk(VXD_CBIT(net, 1), "nx_v6_ifa_visible(%p[#%u],%p) %d",
8780 + nxi, nxi ? nxi->nx_id : 0, ifa,
8781 + nxi ? v6_ifa_in_nx_info(ifa, nxi) : 0);
8783 + if (!nx_info_flags(nxi, NXF_HIDE_NETIF, 0))
8785 + if (v6_ifa_in_nx_info(ifa, nxi))
8791 +struct nx_v6_sock_addr {
8792 + struct in6_addr saddr; /* Address used for validation */
8793 + struct in6_addr baddr; /* Address used for socket bind */
8797 +int v6_map_sock_addr(struct inet_sock *inet, struct sockaddr_in6 *addr,
8798 + struct nx_v6_sock_addr *nsa)
8800 + // struct sock *sk = &inet->sk;
8801 + // struct nx_info *nxi = sk->sk_nx_info;
8802 + struct in6_addr saddr = addr->sin6_addr;
8803 + struct in6_addr baddr = saddr;
8805 + nsa->saddr = saddr;
8806 + nsa->baddr = baddr;
8811 +void v6_set_sock_addr(struct inet_sock *inet, struct nx_v6_sock_addr *nsa)
8813 + // struct sock *sk = &inet->sk;
8814 + // struct in6_addr *saddr = inet6_rcv_saddr(sk);
8816 + // *saddr = nsa->baddr;
8817 + // inet->inet_saddr = nsa->baddr;
8821 +int nx_info_has_v6(struct nx_info *nxi)
8830 +#else /* CONFIG_IPV6 */
8833 +int nx_v6_dev_visible(struct nx_info *n, struct net_device *d)
8840 +int nx_v6_addr_conflict(struct nx_info *n, uint32_t a, const struct sock *s)
8846 +int v6_ifa_in_nx_info(struct in_ifaddr *a, struct nx_info *n)
8852 +int nx_info_has_v6(struct nx_info *nxi)
8857 +#endif /* CONFIG_IPV6 */
8859 +#define current_nx_info_has_v6() \
8860 + nx_info_has_v6(current_nx_info())
8863 +#warning duplicate inclusion
8865 diff -NurpP --minimal linux-3.13.10/include/linux/vs_limit.h linux-3.13.10-vs2.3.6.11/include/linux/vs_limit.h
8866 --- linux-3.13.10/include/linux/vs_limit.h 1970-01-01 00:00:00.000000000 +0000
8867 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_limit.h 2014-02-01 01:29:43.000000000 +0000
8869 +#ifndef _VS_LIMIT_H
8870 +#define _VS_LIMIT_H
8872 +#include "vserver/limit.h"
8873 +#include "vserver/base.h"
8874 +#include "vserver/context.h"
8875 +#include "vserver/debug.h"
8876 +#include "vserver/context.h"
8877 +#include "vserver/limit_int.h"
8880 +#define vx_acc_cres(v, d, p, r) \
8881 + __vx_acc_cres(v, r, d, p, __FILE__, __LINE__)
8883 +#define vx_acc_cres_cond(x, d, p, r) \
8884 + __vx_acc_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8885 + r, d, p, __FILE__, __LINE__)
8888 +#define vx_add_cres(v, a, p, r) \
8889 + __vx_add_cres(v, r, a, p, __FILE__, __LINE__)
8890 +#define vx_sub_cres(v, a, p, r) vx_add_cres(v, -(a), p, r)
8892 +#define vx_add_cres_cond(x, a, p, r) \
8893 + __vx_add_cres(((x) == vx_current_xid()) ? current_vx_info() : 0, \
8894 + r, a, p, __FILE__, __LINE__)
8895 +#define vx_sub_cres_cond(x, a, p, r) vx_add_cres_cond(x, -(a), p, r)
8898 +/* process and file limits */
8900 +#define vx_nproc_inc(p) \
8901 + vx_acc_cres((p)->vx_info, 1, p, RLIMIT_NPROC)
8903 +#define vx_nproc_dec(p) \
8904 + vx_acc_cres((p)->vx_info,-1, p, RLIMIT_NPROC)
8906 +#define vx_files_inc(f) \
8907 + vx_acc_cres_cond((f)->f_xid, 1, f, RLIMIT_NOFILE)
8909 +#define vx_files_dec(f) \
8910 + vx_acc_cres_cond((f)->f_xid,-1, f, RLIMIT_NOFILE)
8912 +#define vx_locks_inc(l) \
8913 + vx_acc_cres_cond((l)->fl_xid, 1, l, RLIMIT_LOCKS)
8915 +#define vx_locks_dec(l) \
8916 + vx_acc_cres_cond((l)->fl_xid,-1, l, RLIMIT_LOCKS)
8918 +#define vx_openfd_inc(f) \
8919 + vx_acc_cres(current_vx_info(), 1, (void *)(long)(f), VLIMIT_OPENFD)
8921 +#define vx_openfd_dec(f) \
8922 + vx_acc_cres(current_vx_info(),-1, (void *)(long)(f), VLIMIT_OPENFD)
8925 +#define vx_cres_avail(v, n, r) \
8926 + __vx_cres_avail(v, r, n, __FILE__, __LINE__)
8929 +#define vx_nproc_avail(n) \
8930 + vx_cres_avail(current_vx_info(), n, RLIMIT_NPROC)
8932 +#define vx_files_avail(n) \
8933 + vx_cres_avail(current_vx_info(), n, RLIMIT_NOFILE)
8935 +#define vx_locks_avail(n) \
8936 + vx_cres_avail(current_vx_info(), n, RLIMIT_LOCKS)
8938 +#define vx_openfd_avail(n) \
8939 + vx_cres_avail(current_vx_info(), n, VLIMIT_OPENFD)
8942 +/* dentry limits */
8944 +#define vx_dentry_inc(d) do { \
8945 + if (d_count(d) == 1) \
8946 + vx_acc_cres(current_vx_info(), 1, d, VLIMIT_DENTRY); \
8949 +#define vx_dentry_dec(d) do { \
8950 + if (d_count(d) == 0) \
8951 + vx_acc_cres(current_vx_info(),-1, d, VLIMIT_DENTRY); \
8954 +#define vx_dentry_avail(n) \
8955 + vx_cres_avail(current_vx_info(), n, VLIMIT_DENTRY)
8958 +/* socket limits */
8960 +#define vx_sock_inc(s) \
8961 + vx_acc_cres((s)->sk_vx_info, 1, s, VLIMIT_NSOCK)
8963 +#define vx_sock_dec(s) \
8964 + vx_acc_cres((s)->sk_vx_info,-1, s, VLIMIT_NSOCK)
8966 +#define vx_sock_avail(n) \
8967 + vx_cres_avail(current_vx_info(), n, VLIMIT_NSOCK)
8970 +/* ipc resource limits */
8972 +#define vx_ipcmsg_add(v, u, a) \
8973 + vx_add_cres(v, a, u, RLIMIT_MSGQUEUE)
8975 +#define vx_ipcmsg_sub(v, u, a) \
8976 + vx_sub_cres(v, a, u, RLIMIT_MSGQUEUE)
8978 +#define vx_ipcmsg_avail(v, a) \
8979 + vx_cres_avail(v, a, RLIMIT_MSGQUEUE)
8982 +#define vx_ipcshm_add(v, k, a) \
8983 + vx_add_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8985 +#define vx_ipcshm_sub(v, k, a) \
8986 + vx_sub_cres(v, a, (void *)(long)(k), VLIMIT_SHMEM)
8988 +#define vx_ipcshm_avail(v, a) \
8989 + vx_cres_avail(v, a, VLIMIT_SHMEM)
8992 +#define vx_semary_inc(a) \
8993 + vx_acc_cres(current_vx_info(), 1, a, VLIMIT_SEMARY)
8995 +#define vx_semary_dec(a) \
8996 + vx_acc_cres(current_vx_info(), -1, a, VLIMIT_SEMARY)
8999 +#define vx_nsems_add(a,n) \
9000 + vx_add_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9002 +#define vx_nsems_sub(a,n) \
9003 + vx_sub_cres(current_vx_info(), n, a, VLIMIT_NSEMS)
9007 +#warning duplicate inclusion
9009 diff -NurpP --minimal linux-3.13.10/include/linux/vs_network.h linux-3.13.10-vs2.3.6.11/include/linux/vs_network.h
9010 --- linux-3.13.10/include/linux/vs_network.h 1970-01-01 00:00:00.000000000 +0000
9011 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_network.h 2014-01-31 20:38:03.000000000 +0000
9013 +#ifndef _NX_VS_NETWORK_H
9014 +#define _NX_VS_NETWORK_H
9016 +#include "vserver/context.h"
9017 +#include "vserver/network.h"
9018 +#include "vserver/base.h"
9019 +#include "vserver/check.h"
9020 +#include "vserver/debug.h"
9022 +#include <linux/sched.h>
9025 +#define get_nx_info(i) __get_nx_info(i, __FILE__, __LINE__)
9027 +static inline struct nx_info *__get_nx_info(struct nx_info *nxi,
9028 + const char *_file, int _line)
9033 + vxlprintk(VXD_CBIT(nid, 2), "get_nx_info(%p[#%d.%d])",
9034 + nxi, nxi ? nxi->nx_id : 0,
9035 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9038 + atomic_inc(&nxi->nx_usecnt);
9043 +extern void free_nx_info(struct nx_info *);
9045 +#define put_nx_info(i) __put_nx_info(i, __FILE__, __LINE__)
9047 +static inline void __put_nx_info(struct nx_info *nxi, const char *_file, int _line)
9052 + vxlprintk(VXD_CBIT(nid, 2), "put_nx_info(%p[#%d.%d])",
9053 + nxi, nxi ? nxi->nx_id : 0,
9054 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9057 + if (atomic_dec_and_test(&nxi->nx_usecnt))
9058 + free_nx_info(nxi);
9062 +#define init_nx_info(p, i) __init_nx_info(p, i, __FILE__, __LINE__)
9064 +static inline void __init_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9065 + const char *_file, int _line)
9068 + vxlprintk(VXD_CBIT(nid, 3),
9069 + "init_nx_info(%p[#%d.%d])",
9070 + nxi, nxi ? nxi->nx_id : 0,
9071 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9074 + atomic_inc(&nxi->nx_usecnt);
9080 +#define set_nx_info(p, i) __set_nx_info(p, i, __FILE__, __LINE__)
9082 +static inline void __set_nx_info(struct nx_info **nxp, struct nx_info *nxi,
9083 + const char *_file, int _line)
9085 + struct nx_info *nxo;
9090 + vxlprintk(VXD_CBIT(nid, 3), "set_nx_info(%p[#%d.%d])",
9091 + nxi, nxi ? nxi->nx_id : 0,
9092 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9095 + atomic_inc(&nxi->nx_usecnt);
9096 + nxo = xchg(nxp, nxi);
9100 +#define clr_nx_info(p) __clr_nx_info(p, __FILE__, __LINE__)
9102 +static inline void __clr_nx_info(struct nx_info **nxp,
9103 + const char *_file, int _line)
9105 + struct nx_info *nxo;
9107 + nxo = xchg(nxp, NULL);
9111 + vxlprintk(VXD_CBIT(nid, 3), "clr_nx_info(%p[#%d.%d])",
9112 + nxo, nxo ? nxo->nx_id : 0,
9113 + nxo ? atomic_read(&nxo->nx_usecnt) : 0,
9116 + if (atomic_dec_and_test(&nxo->nx_usecnt))
9117 + free_nx_info(nxo);
9121 +#define claim_nx_info(v, p) __claim_nx_info(v, p, __FILE__, __LINE__)
9123 +static inline void __claim_nx_info(struct nx_info *nxi,
9124 + struct task_struct *task, const char *_file, int _line)
9126 + vxlprintk(VXD_CBIT(nid, 3), "claim_nx_info(%p[#%d.%d.%d]) %p",
9127 + nxi, nxi ? nxi->nx_id : 0,
9128 + nxi?atomic_read(&nxi->nx_usecnt):0,
9129 + nxi?atomic_read(&nxi->nx_tasks):0,
9130 + task, _file, _line);
9132 + atomic_inc(&nxi->nx_tasks);
9136 +extern void unhash_nx_info(struct nx_info *);
9138 +#define release_nx_info(v, p) __release_nx_info(v, p, __FILE__, __LINE__)
9140 +static inline void __release_nx_info(struct nx_info *nxi,
9141 + struct task_struct *task, const char *_file, int _line)
9143 + vxlprintk(VXD_CBIT(nid, 3), "release_nx_info(%p[#%d.%d.%d]) %p",
9144 + nxi, nxi ? nxi->nx_id : 0,
9145 + nxi ? atomic_read(&nxi->nx_usecnt) : 0,
9146 + nxi ? atomic_read(&nxi->nx_tasks) : 0,
9147 + task, _file, _line);
9151 + if (atomic_dec_and_test(&nxi->nx_tasks))
9152 + unhash_nx_info(nxi);
9156 +#define task_get_nx_info(i) __task_get_nx_info(i, __FILE__, __LINE__)
9158 +static __inline__ struct nx_info *__task_get_nx_info(struct task_struct *p,
9159 + const char *_file, int _line)
9161 + struct nx_info *nxi;
9164 + vxlprintk(VXD_CBIT(nid, 5), "task_get_nx_info(%p)",
9166 + nxi = __get_nx_info(p->nx_info, _file, _line);
9172 +static inline void exit_nx_info(struct task_struct *p)
9175 + release_nx_info(p->nx_info, p);
9180 +#warning duplicate inclusion
9182 diff -NurpP --minimal linux-3.13.10/include/linux/vs_pid.h linux-3.13.10-vs2.3.6.11/include/linux/vs_pid.h
9183 --- linux-3.13.10/include/linux/vs_pid.h 1970-01-01 00:00:00.000000000 +0000
9184 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_pid.h 2014-01-31 20:38:03.000000000 +0000
9189 +#include "vserver/base.h"
9190 +#include "vserver/check.h"
9191 +#include "vserver/context.h"
9192 +#include "vserver/debug.h"
9193 +#include "vserver/pid.h"
9194 +#include <linux/pid_namespace.h>
9197 +#define VXF_FAKE_INIT (VXF_INFO_INIT | VXF_STATE_INIT)
9200 +int vx_proc_task_visible(struct task_struct *task)
9202 + if ((task->pid == 1) &&
9203 + !vx_flags(VXF_FAKE_INIT, VXF_FAKE_INIT))
9204 + /* show a blend through init */
9206 + if (vx_check(vx_task_xid(task), VS_WATCH | VS_IDENT))
9213 +#define find_task_by_real_pid(pid) find_task_by_pid_ns(pid, &init_pid_ns)
9217 +struct task_struct *vx_get_proc_task(struct inode *inode, struct pid *pid)
9219 + struct task_struct *task = get_pid_task(pid, PIDTYPE_PID);
9221 + if (task && !vx_proc_task_visible(task)) {
9222 + vxdprintk(VXD_CBIT(misc, 6),
9223 + "dropping task (get) %p[#%u,%u] for %p[#%u,%u]",
9224 + task, task->xid, task->pid,
9225 + current, current->xid, current->pid);
9226 + put_task_struct(task);
9234 +#warning duplicate inclusion
9236 diff -NurpP --minimal linux-3.13.10/include/linux/vs_sched.h linux-3.13.10-vs2.3.6.11/include/linux/vs_sched.h
9237 --- linux-3.13.10/include/linux/vs_sched.h 1970-01-01 00:00:00.000000000 +0000
9238 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_sched.h 2014-01-31 20:38:03.000000000 +0000
9240 +#ifndef _VS_SCHED_H
9241 +#define _VS_SCHED_H
9243 +#include "vserver/base.h"
9244 +#include "vserver/context.h"
9245 +#include "vserver/sched.h"
9248 +#define MAX_PRIO_BIAS 20
9249 +#define MIN_PRIO_BIAS -20
9252 +int vx_adjust_prio(struct task_struct *p, int prio, int max_user)
9254 + struct vx_info *vxi = p->vx_info;
9257 + prio += vx_cpu(vxi, sched_pc).prio_bias;
9261 +static inline void vx_account_user(struct vx_info *vxi,
9262 + cputime_t cputime, int nice)
9266 + vx_cpu(vxi, sched_pc).user_ticks += cputime;
9269 +static inline void vx_account_system(struct vx_info *vxi,
9270 + cputime_t cputime, int idle)
9274 + vx_cpu(vxi, sched_pc).sys_ticks += cputime;
9278 +#warning duplicate inclusion
9280 diff -NurpP --minimal linux-3.13.10/include/linux/vs_socket.h linux-3.13.10-vs2.3.6.11/include/linux/vs_socket.h
9281 --- linux-3.13.10/include/linux/vs_socket.h 1970-01-01 00:00:00.000000000 +0000
9282 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_socket.h 2014-01-31 20:38:03.000000000 +0000
9284 +#ifndef _VS_SOCKET_H
9285 +#define _VS_SOCKET_H
9287 +#include "vserver/debug.h"
9288 +#include "vserver/base.h"
9289 +#include "vserver/cacct.h"
9290 +#include "vserver/context.h"
9291 +#include "vserver/tag.h"
9294 +/* socket accounting */
9296 +#include <linux/socket.h>
9298 +static inline int vx_sock_type(int family)
9302 + return VXA_SOCK_UNSPEC;
9304 + return VXA_SOCK_UNIX;
9306 + return VXA_SOCK_INET;
9308 + return VXA_SOCK_INET6;
9310 + return VXA_SOCK_PACKET;
9312 + return VXA_SOCK_OTHER;
9316 +#define vx_acc_sock(v, f, p, s) \
9317 + __vx_acc_sock(v, f, p, s, __FILE__, __LINE__)
9319 +static inline void __vx_acc_sock(struct vx_info *vxi,
9320 + int family, int pos, int size, char *file, int line)
9323 + int type = vx_sock_type(family);
9325 + atomic_long_inc(&vxi->cacct.sock[type][pos].count);
9326 + atomic_long_add(size, &vxi->cacct.sock[type][pos].total);
9330 +#define vx_sock_recv(sk, s) \
9331 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 0, s)
9332 +#define vx_sock_send(sk, s) \
9333 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 1, s)
9334 +#define vx_sock_fail(sk, s) \
9335 + vx_acc_sock((sk)->sk_vx_info, (sk)->sk_family, 2, s)
9338 +#define sock_vx_init(s) do { \
9339 + (s)->sk_xid = 0; \
9340 + (s)->sk_vx_info = NULL; \
9343 +#define sock_nx_init(s) do { \
9344 + (s)->sk_nid = 0; \
9345 + (s)->sk_nx_info = NULL; \
9349 +#warning duplicate inclusion
9351 diff -NurpP --minimal linux-3.13.10/include/linux/vs_tag.h linux-3.13.10-vs2.3.6.11/include/linux/vs_tag.h
9352 --- linux-3.13.10/include/linux/vs_tag.h 1970-01-01 00:00:00.000000000 +0000
9353 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_tag.h 2014-01-31 20:38:03.000000000 +0000
9358 +#include <linux/vserver/tag.h>
9360 +/* check conditions */
9362 +#define DX_ADMIN 0x0001
9363 +#define DX_WATCH 0x0002
9364 +#define DX_HOSTID 0x0008
9366 +#define DX_IDENT 0x0010
9368 +#define DX_ARG_MASK 0x0010
9371 +#define dx_task_tag(t) ((t)->tag)
9373 +#define dx_current_tag() dx_task_tag(current)
9375 +#define dx_check(c, m) __dx_check(dx_current_tag(), c, m)
9377 +#define dx_weak_check(c, m) ((m) ? dx_check(c, m) : 1)
9381 + * check current context for ADMIN/WATCH and
9382 + * optionally against supplied argument
9384 +static inline int __dx_check(vtag_t cid, vtag_t id, unsigned int mode)
9386 + if (mode & DX_ARG_MASK) {
9387 + if ((mode & DX_IDENT) && (id == cid))
9390 + return (((mode & DX_ADMIN) && (cid == 0)) ||
9391 + ((mode & DX_WATCH) && (cid == 1)) ||
9392 + ((mode & DX_HOSTID) && (id == 0)));
9396 +int dx_permission(const struct inode *inode, int mask);
9400 +#warning duplicate inclusion
9402 diff -NurpP --minimal linux-3.13.10/include/linux/vs_time.h linux-3.13.10-vs2.3.6.11/include/linux/vs_time.h
9403 --- linux-3.13.10/include/linux/vs_time.h 1970-01-01 00:00:00.000000000 +0000
9404 +++ linux-3.13.10-vs2.3.6.11/include/linux/vs_time.h 2014-01-31 20:38:03.000000000 +0000
9410 +/* time faking stuff */
9412 +#ifdef CONFIG_VSERVER_VTIME
9414 +extern void vx_adjust_timespec(struct timespec *ts);
9415 +extern int vx_settimeofday(const struct timespec *ts);
9418 +#define vx_adjust_timespec(t) do { } while (0)
9419 +#define vx_settimeofday(t) do_settimeofday(t)
9423 +#warning duplicate inclusion
9425 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/base.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/base.h
9426 --- linux-3.13.10/include/linux/vserver/base.h 1970-01-01 00:00:00.000000000 +0000
9427 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/base.h 2014-01-31 20:38:03.000000000 +0000
9429 +#ifndef _VSERVER_BASE_H
9430 +#define _VSERVER_BASE_H
9433 +/* context state changes */
9445 +#define vx_task_xid(t) ((t)->xid)
9447 +#define vx_current_xid() vx_task_xid(current)
9449 +#define current_vx_info() (current->vx_info)
9452 +#define nx_task_nid(t) ((t)->nid)
9454 +#define nx_current_nid() nx_task_nid(current)
9456 +#define current_nx_info() (current->nx_info)
9459 +/* generic flag merging */
9461 +#define vs_check_flags(v, m, f) (((v) & (m)) ^ (f))
9463 +#define vs_mask_flags(v, f, m) (((v) & ~(m)) | ((f) & (m)))
9465 +#define vs_mask_mask(v, f, m) (((v) & ~(m)) | ((v) & (f) & (m)))
9467 +#define vs_check_bit(v, n) ((v) & (1LL << (n)))
9470 +/* context flags */
9472 +#define __vx_flags(v) ((v) ? (v)->vx_flags : 0)
9474 +#define vx_current_flags() __vx_flags(current_vx_info())
9476 +#define vx_info_flags(v, m, f) \
9477 + vs_check_flags(__vx_flags(v), m, f)
9479 +#define task_vx_flags(t, m, f) \
9480 + ((t) && vx_info_flags((t)->vx_info, m, f))
9482 +#define vx_flags(m, f) vx_info_flags(current_vx_info(), m, f)
9487 +#define __vx_ccaps(v) ((v) ? (v)->vx_ccaps : 0)
9489 +#define vx_current_ccaps() __vx_ccaps(current_vx_info())
9491 +#define vx_info_ccaps(v, c) (__vx_ccaps(v) & (c))
9493 +#define vx_ccaps(c) vx_info_ccaps(current_vx_info(), (c))
9497 +/* network flags */
9499 +#define __nx_flags(n) ((n) ? (n)->nx_flags : 0)
9501 +#define nx_current_flags() __nx_flags(current_nx_info())
9503 +#define nx_info_flags(n, m, f) \
9504 + vs_check_flags(__nx_flags(n), m, f)
9506 +#define task_nx_flags(t, m, f) \
9507 + ((t) && nx_info_flags((t)->nx_info, m, f))
9509 +#define nx_flags(m, f) nx_info_flags(current_nx_info(), m, f)
9514 +#define __nx_ncaps(n) ((n) ? (n)->nx_ncaps : 0)
9516 +#define nx_current_ncaps() __nx_ncaps(current_nx_info())
9518 +#define nx_info_ncaps(n, c) (__nx_ncaps(n) & (c))
9520 +#define nx_ncaps(c) nx_info_ncaps(current_nx_info(), c)
9523 +/* context mask capabilities */
9525 +#define __vx_mcaps(v) ((v) ? (v)->vx_ccaps >> 32UL : ~0 )
9527 +#define vx_info_mcaps(v, c) (__vx_mcaps(v) & (c))
9529 +#define vx_mcaps(c) vx_info_mcaps(current_vx_info(), c)
9532 +/* context bcap mask */
9534 +#define __vx_bcaps(v) ((v)->vx_bcaps)
9536 +#define vx_current_bcaps() __vx_bcaps(current_vx_info())
9539 +/* mask given bcaps */
9541 +#define vx_info_mbcaps(v, c) ((v) ? cap_intersect(__vx_bcaps(v), c) : c)
9543 +#define vx_mbcaps(c) vx_info_mbcaps(current_vx_info(), c)
9546 +/* masked cap_bset */
9548 +#define vx_info_cap_bset(v) vx_info_mbcaps(v, current->cap_bset)
9550 +#define vx_current_cap_bset() vx_info_cap_bset(current_vx_info())
9553 +#define vx_info_mbcap(v, b) \
9554 + (!vx_info_flags(v, VXF_STATE_SETUP, 0) ? \
9555 + vx_info_bcaps(v, b) : (b))
9557 +#define task_vx_mbcap(t, b) \
9558 + vx_info_mbcap((t)->vx_info, (t)->b)
9560 +#define vx_mbcap(b) task_vx_mbcap(current, b)
9563 +#define vx_cap_raised(v, c, f) cap_raised(vx_info_mbcaps(v, c), f)
9565 +#define vx_capable(b, c) (capable(b) || \
9566 + (cap_raised(current_cap(), b) && vx_ccaps(c)))
9568 +#define vx_ns_capable(n, b, c) (ns_capable(n, b) || \
9569 + (cap_raised(current_cap(), b) && vx_ccaps(c)))
9571 +#define nx_capable(b, c) (capable(b) || \
9572 + (cap_raised(current_cap(), b) && nx_ncaps(c)))
9574 +#define nx_ns_capable(n, b, c) (ns_capable(n, b) || \
9575 + (cap_raised(current_cap(), b) && nx_ncaps(c)))
9577 +#define vx_task_initpid(t, n) \
9578 + ((t)->vx_info && \
9579 + ((t)->vx_info->vx_initpid == (n)))
9581 +#define vx_current_initpid(n) vx_task_initpid(current, n)
9584 +/* context unshare mask */
9586 +#define __vx_umask(v) ((v)->vx_umask)
9588 +#define vx_current_umask() __vx_umask(current_vx_info())
9590 +#define vx_can_unshare(b, f) (capable(b) || \
9591 + (cap_raised(current_cap(), b) && \
9592 + !((f) & ~vx_current_umask())))
9594 +#define vx_ns_can_unshare(n, b, f) (ns_capable(n, b) || \
9595 + (cap_raised(current_cap(), b) && \
9596 + !((f) & ~vx_current_umask())))
9598 +#define __vx_wmask(v) ((v)->vx_wmask)
9600 +#define vx_current_wmask() __vx_wmask(current_vx_info())
9603 +#define __vx_state(v) ((v) ? ((v)->vx_state) : 0)
9605 +#define vx_info_state(v, m) (__vx_state(v) & (m))
9608 +#define __nx_state(n) ((n) ? ((n)->nx_state) : 0)
9610 +#define nx_info_state(n, m) (__nx_state(n) & (m))
9613 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct.h
9614 --- linux-3.13.10/include/linux/vserver/cacct.h 1970-01-01 00:00:00.000000000 +0000
9615 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct.h 2014-01-31 20:38:03.000000000 +0000
9617 +#ifndef _VSERVER_CACCT_H
9618 +#define _VSERVER_CACCT_H
9621 +enum sock_acc_field {
9622 + VXA_SOCK_UNSPEC = 0,
9628 + VXA_SOCK_SIZE /* array size */
9631 +#endif /* _VSERVER_CACCT_H */
9632 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_cmd.h
9633 --- linux-3.13.10/include/linux/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
9634 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_cmd.h 2014-01-31 20:38:03.000000000 +0000
9636 +#ifndef _VSERVER_CACCT_CMD_H
9637 +#define _VSERVER_CACCT_CMD_H
9640 +#include <linux/compiler.h>
9641 +#include <uapi/vserver/cacct_cmd.h>
9643 +extern int vc_sock_stat(struct vx_info *, void __user *);
9645 +#endif /* _VSERVER_CACCT_CMD_H */
9646 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_def.h
9647 --- linux-3.13.10/include/linux/vserver/cacct_def.h 1970-01-01 00:00:00.000000000 +0000
9648 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_def.h 2014-01-31 20:38:03.000000000 +0000
9650 +#ifndef _VSERVER_CACCT_DEF_H
9651 +#define _VSERVER_CACCT_DEF_H
9653 +#include <asm/atomic.h>
9654 +#include <linux/vserver/cacct.h>
9657 +struct _vx_sock_acc {
9658 + atomic_long_t count;
9659 + atomic_long_t total;
9662 +/* context sub struct */
9665 + struct _vx_sock_acc sock[VXA_SOCK_SIZE][3];
9667 + atomic_t page[6][8];
9670 +#ifdef CONFIG_VSERVER_DEBUG
9672 +static inline void __dump_vx_cacct(struct _vx_cacct *cacct)
9676 + printk("\t_vx_cacct:");
9677 + for (i = 0; i < 6; i++) {
9678 + struct _vx_sock_acc *ptr = cacct->sock[i];
9680 + printk("\t [%d] =", i);
9681 + for (j = 0; j < 3; j++) {
9682 + printk(" [%d] = %8lu, %8lu", j,
9683 + atomic_long_read(&ptr[j].count),
9684 + atomic_long_read(&ptr[j].total));
9692 +#endif /* _VSERVER_CACCT_DEF_H */
9693 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cacct_int.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_int.h
9694 --- linux-3.13.10/include/linux/vserver/cacct_int.h 1970-01-01 00:00:00.000000000 +0000
9695 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cacct_int.h 2014-01-31 20:38:03.000000000 +0000
9697 +#ifndef _VSERVER_CACCT_INT_H
9698 +#define _VSERVER_CACCT_INT_H
9701 +unsigned long vx_sock_count(struct _vx_cacct *cacct, int type, int pos)
9703 + return atomic_long_read(&cacct->sock[type][pos].count);
9708 +unsigned long vx_sock_total(struct _vx_cacct *cacct, int type, int pos)
9710 + return atomic_long_read(&cacct->sock[type][pos].total);
9713 +#endif /* _VSERVER_CACCT_INT_H */
9714 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/check.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/check.h
9715 --- linux-3.13.10/include/linux/vserver/check.h 1970-01-01 00:00:00.000000000 +0000
9716 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/check.h 2014-01-31 20:38:03.000000000 +0000
9718 +#ifndef _VSERVER_CHECK_H
9719 +#define _VSERVER_CHECK_H
9722 +#define MAX_S_CONTEXT 65535 /* Arbitrary limit */
9724 +#ifdef CONFIG_VSERVER_DYNAMIC_IDS
9725 +#define MIN_D_CONTEXT 49152 /* dynamic contexts start here */
9727 +#define MIN_D_CONTEXT 65536
9730 +/* check conditions */
9732 +#define VS_ADMIN 0x0001
9733 +#define VS_WATCH 0x0002
9734 +#define VS_HIDE 0x0004
9735 +#define VS_HOSTID 0x0008
9737 +#define VS_IDENT 0x0010
9738 +#define VS_EQUIV 0x0020
9739 +#define VS_PARENT 0x0040
9740 +#define VS_CHILD 0x0080
9742 +#define VS_ARG_MASK 0x00F0
9744 +#define VS_DYNAMIC 0x0100
9745 +#define VS_STATIC 0x0200
9747 +#define VS_ATR_MASK 0x0F00
9749 +#ifdef CONFIG_VSERVER_PRIVACY
9750 +#define VS_ADMIN_P (0)
9751 +#define VS_WATCH_P (0)
9753 +#define VS_ADMIN_P VS_ADMIN
9754 +#define VS_WATCH_P VS_WATCH
9757 +#define VS_HARDIRQ 0x1000
9758 +#define VS_SOFTIRQ 0x2000
9759 +#define VS_IRQ 0x4000
9761 +#define VS_IRQ_MASK 0xF000
9763 +#include <linux/hardirq.h>
9766 + * check current context for ADMIN/WATCH and
9767 + * optionally against supplied argument
9769 +static inline int __vs_check(int cid, int id, unsigned int mode)
9771 + if (mode & VS_ARG_MASK) {
9772 + if ((mode & VS_IDENT) && (id == cid))
9775 + if (mode & VS_ATR_MASK) {
9776 + if ((mode & VS_DYNAMIC) &&
9777 + (id >= MIN_D_CONTEXT) &&
9778 + (id <= MAX_S_CONTEXT))
9780 + if ((mode & VS_STATIC) &&
9781 + (id > 1) && (id < MIN_D_CONTEXT))
9784 + if (mode & VS_IRQ_MASK) {
9785 + if ((mode & VS_IRQ) && unlikely(in_interrupt()))
9787 + if ((mode & VS_HARDIRQ) && unlikely(in_irq()))
9789 + if ((mode & VS_SOFTIRQ) && unlikely(in_softirq()))
9792 + return (((mode & VS_ADMIN) && (cid == 0)) ||
9793 + ((mode & VS_WATCH) && (cid == 1)) ||
9794 + ((mode & VS_HOSTID) && (id == 0)));
9797 +#define vx_check(c, m) __vs_check(vx_current_xid(), c, (m) | VS_IRQ)
9799 +#define vx_weak_check(c, m) ((m) ? vx_check(c, m) : 1)
9802 +#define nx_check(c, m) __vs_check(nx_current_nid(), c, m)
9804 +#define nx_weak_check(c, m) ((m) ? nx_check(c, m) : 1)
9807 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/context.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/context.h
9808 --- linux-3.13.10/include/linux/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
9809 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/context.h 2014-01-31 20:38:03.000000000 +0000
9811 +#ifndef _VSERVER_CONTEXT_H
9812 +#define _VSERVER_CONTEXT_H
9815 +#include <linux/list.h>
9816 +#include <linux/spinlock.h>
9817 +#include <linux/rcupdate.h>
9818 +#include <uapi/vserver/context.h>
9820 +#include "limit_def.h"
9821 +#include "sched_def.h"
9822 +#include "cvirt_def.h"
9823 +#include "cacct_def.h"
9824 +#include "device_def.h"
9826 +#define VX_SPACES 2
9828 +struct _vx_info_pc {
9829 + struct _vx_sched_pc sched_pc;
9830 + struct _vx_cvirt_pc cvirt_pc;
9834 + unsigned long vx_nsmask; /* assignment mask */
9835 + struct nsproxy *vx_nsproxy; /* private namespaces */
9836 + struct fs_struct *vx_fs; /* private namespace fs */
9837 + const struct cred *vx_cred; /* task credentials */
9841 + struct hlist_node vx_hlist; /* linked list of contexts */
9842 + vxid_t vx_id; /* context id */
9843 + atomic_t vx_usecnt; /* usage count */
9844 + atomic_t vx_tasks; /* tasks count */
9845 + struct vx_info *vx_parent; /* parent context */
9846 + int vx_state; /* context state */
9848 + struct _vx_space space[VX_SPACES]; /* namespace store */
9850 + uint64_t vx_flags; /* context flags */
9851 + uint64_t vx_ccaps; /* context caps (vserver) */
9852 + uint64_t vx_umask; /* unshare mask (guest) */
9853 + uint64_t vx_wmask; /* warn mask (guest) */
9854 + kernel_cap_t vx_bcaps; /* bounding caps (system) */
9856 + struct task_struct *vx_reaper; /* guest reaper process */
9857 + pid_t vx_initpid; /* PID of guest init */
9858 + int64_t vx_badness_bias; /* OOM points bias */
9860 + struct _vx_limit limit; /* vserver limits */
9861 + struct _vx_sched sched; /* vserver scheduler */
9862 + struct _vx_cvirt cvirt; /* virtual/bias stuff */
9863 + struct _vx_cacct cacct; /* context accounting */
9865 + struct _vx_device dmap; /* default device map targets */
9868 + struct _vx_info_pc info_pc; /* per cpu data */
9870 + struct _vx_info_pc *ptr_pc; /* per cpu array */
9873 + wait_queue_head_t vx_wait; /* context exit waitqueue */
9874 + int reboot_cmd; /* last sys_reboot() cmd */
9875 + int exit_code; /* last process exit code */
9877 + char vx_name[65]; /* vserver name */
9881 +#define vx_ptr_pc(vxi) (&(vxi)->info_pc)
9882 +#define vx_per_cpu(vxi, v, id) vx_ptr_pc(vxi)->v
9884 +#define vx_ptr_pc(vxi) ((vxi)->ptr_pc)
9885 +#define vx_per_cpu(vxi, v, id) per_cpu_ptr(vx_ptr_pc(vxi), id)->v
9888 +#define vx_cpu(vxi, v) vx_per_cpu(vxi, v, smp_processor_id())
9891 +struct vx_info_save {
9892 + struct vx_info *vxi;
9899 +#define VXS_HASHED 0x0001
9900 +#define VXS_PAUSED 0x0010
9901 +#define VXS_SHUTDOWN 0x0100
9902 +#define VXS_HELPER 0x1000
9903 +#define VXS_RELEASED 0x8000
9906 +extern void claim_vx_info(struct vx_info *, struct task_struct *);
9907 +extern void release_vx_info(struct vx_info *, struct task_struct *);
9909 +extern struct vx_info *lookup_vx_info(int);
9910 +extern struct vx_info *lookup_or_create_vx_info(int);
9912 +extern int get_xid_list(int, unsigned int *, int);
9913 +extern int xid_is_hashed(vxid_t);
9915 +extern int vx_migrate_task(struct task_struct *, struct vx_info *, int);
9917 +extern long vs_state_change(struct vx_info *, unsigned int);
9920 +#endif /* _VSERVER_CONTEXT_H */
9921 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/context_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/context_cmd.h
9922 --- linux-3.13.10/include/linux/vserver/context_cmd.h 1970-01-01 00:00:00.000000000 +0000
9923 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/context_cmd.h 2014-01-31 20:38:03.000000000 +0000
9925 +#ifndef _VSERVER_CONTEXT_CMD_H
9926 +#define _VSERVER_CONTEXT_CMD_H
9928 +#include <uapi/vserver/context_cmd.h>
9930 +extern int vc_task_xid(uint32_t);
9932 +extern int vc_vx_info(struct vx_info *, void __user *);
9934 +extern int vc_ctx_stat(struct vx_info *, void __user *);
9936 +extern int vc_ctx_create(uint32_t, void __user *);
9937 +extern int vc_ctx_migrate(struct vx_info *, void __user *);
9939 +extern int vc_get_cflags(struct vx_info *, void __user *);
9940 +extern int vc_set_cflags(struct vx_info *, void __user *);
9942 +extern int vc_get_ccaps(struct vx_info *, void __user *);
9943 +extern int vc_set_ccaps(struct vx_info *, void __user *);
9945 +extern int vc_get_bcaps(struct vx_info *, void __user *);
9946 +extern int vc_set_bcaps(struct vx_info *, void __user *);
9948 +extern int vc_get_umask(struct vx_info *, void __user *);
9949 +extern int vc_set_umask(struct vx_info *, void __user *);
9951 +extern int vc_get_wmask(struct vx_info *, void __user *);
9952 +extern int vc_set_wmask(struct vx_info *, void __user *);
9954 +extern int vc_get_badness(struct vx_info *, void __user *);
9955 +extern int vc_set_badness(struct vx_info *, void __user *);
9957 +#endif /* _VSERVER_CONTEXT_CMD_H */
9958 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cvirt.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt.h
9959 --- linux-3.13.10/include/linux/vserver/cvirt.h 1970-01-01 00:00:00.000000000 +0000
9960 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt.h 2014-01-31 20:38:03.000000000 +0000
9962 +#ifndef _VSERVER_CVIRT_H
9963 +#define _VSERVER_CVIRT_H
9967 +void vx_vsi_boottime(struct timespec *);
9969 +void vx_vsi_uptime(struct timespec *, struct timespec *);
9974 +void vx_update_load(struct vx_info *);
9977 +int vx_do_syslog(int, char __user *, int);
9979 +#endif /* _VSERVER_CVIRT_H */
9980 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cvirt_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_cmd.h
9981 --- linux-3.13.10/include/linux/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
9982 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_cmd.h 2014-01-31 20:38:03.000000000 +0000
9984 +#ifndef _VSERVER_CVIRT_CMD_H
9985 +#define _VSERVER_CVIRT_CMD_H
9988 +#include <linux/compiler.h>
9989 +#include <uapi/vserver/cvirt_cmd.h>
9991 +extern int vc_set_vhi_name(struct vx_info *, void __user *);
9992 +extern int vc_get_vhi_name(struct vx_info *, void __user *);
9994 +extern int vc_virt_stat(struct vx_info *, void __user *);
9996 +#endif /* _VSERVER_CVIRT_CMD_H */
9997 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/cvirt_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_def.h
9998 --- linux-3.13.10/include/linux/vserver/cvirt_def.h 1970-01-01 00:00:00.000000000 +0000
9999 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/cvirt_def.h 2014-01-31 20:38:03.000000000 +0000
10001 +#ifndef _VSERVER_CVIRT_DEF_H
10002 +#define _VSERVER_CVIRT_DEF_H
10004 +#include <linux/jiffies.h>
10005 +#include <linux/spinlock.h>
10006 +#include <linux/wait.h>
10007 +#include <linux/time.h>
10008 +#include <asm/atomic.h>
10011 +struct _vx_usage_stat {
10015 + uint64_t softirq;
10021 +struct _vx_syslog {
10022 + wait_queue_head_t log_wait;
10023 + spinlock_t logbuf_lock; /* lock for the log buffer */
10025 + unsigned long log_start; /* next char to be read by syslog() */
10026 + unsigned long con_start; /* next char to be sent to consoles */
10027 + unsigned long log_end; /* most-recently-written-char + 1 */
10028 + unsigned long logged_chars; /* #chars since last read+clear operation */
10030 + char log_buf[1024];
10034 +/* context sub struct */
10036 +struct _vx_cvirt {
10037 + atomic_t nr_threads; /* number of current threads */
10038 + atomic_t nr_running; /* number of running threads */
10039 + atomic_t nr_uninterruptible; /* number of uninterruptible threads */
10041 + atomic_t nr_onhold; /* processes on hold */
10042 + uint32_t onhold_last; /* jiffies when put on hold */
10044 + struct timespec bias_ts; /* time offset to the host */
10045 + struct timespec bias_idle;
10046 + struct timespec bias_uptime; /* context creation point */
10047 + uint64_t bias_clock; /* offset in clock_t */
10049 + spinlock_t load_lock; /* lock for the load averages */
10050 + atomic_t load_updates; /* nr of load updates done so far */
10051 + uint32_t load_last; /* last time load was calculated */
10052 + uint32_t load[3]; /* load averages 1,5,15 */
10054 + atomic_t total_forks; /* number of forks so far */
10056 + struct _vx_syslog syslog;
10059 +struct _vx_cvirt_pc {
10060 + struct _vx_usage_stat cpustat;
10064 +#ifdef CONFIG_VSERVER_DEBUG
10066 +static inline void __dump_vx_cvirt(struct _vx_cvirt *cvirt)
10068 + printk("\t_vx_cvirt:\n");
10069 + printk("\t threads: %4d, %4d, %4d, %4d\n",
10070 + atomic_read(&cvirt->nr_threads),
10071 + atomic_read(&cvirt->nr_running),
10072 + atomic_read(&cvirt->nr_uninterruptible),
10073 + atomic_read(&cvirt->nr_onhold));
10074 + /* add rest here */
10075 + printk("\t total_forks = %d\n", atomic_read(&cvirt->total_forks));
10080 +#endif /* _VSERVER_CVIRT_DEF_H */
10081 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/debug.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug.h
10082 --- linux-3.13.10/include/linux/vserver/debug.h 1970-01-01 00:00:00.000000000 +0000
10083 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug.h 2014-01-31 20:38:03.000000000 +0000
10085 +#ifndef _VSERVER_DEBUG_H
10086 +#define _VSERVER_DEBUG_H
10089 +#define VXD_CBIT(n, m) (vs_debug_ ## n & (1 << (m)))
10090 +#define VXD_CMIN(n, m) (vs_debug_ ## n > (m))
10091 +#define VXD_MASK(n, m) (vs_debug_ ## n & (m))
10093 +#define VXD_DEV(d) (d), (d)->bd_inode->i_ino, \
10094 + imajor((d)->bd_inode), iminor((d)->bd_inode)
10095 +#define VXF_DEV "%p[%lu,%d:%d]"
10097 +#if defined(CONFIG_QUOTES_UTF8)
10098 +#define VS_Q_LQM "\xc2\xbb"
10099 +#define VS_Q_RQM "\xc2\xab"
10100 +#elif defined(CONFIG_QUOTES_ASCII)
10101 +#define VS_Q_LQM "\x27"
10102 +#define VS_Q_RQM "\x27"
10104 +#define VS_Q_LQM "\xbb"
10105 +#define VS_Q_RQM "\xab"
10108 +#define VS_Q(f) VS_Q_LQM f VS_Q_RQM
10111 +#define vxd_path(p) \
10112 + ({ static char _buffer[PATH_MAX]; \
10113 + d_path(p, _buffer, sizeof(_buffer)); })
10115 +#define vxd_cond_path(n) \
10116 + ((n) ? vxd_path(&(n)->path) : "<null>" )
10119 +#ifdef CONFIG_VSERVER_DEBUG
10121 +extern unsigned int vs_debug_switch;
10122 +extern unsigned int vs_debug_xid;
10123 +extern unsigned int vs_debug_nid;
10124 +extern unsigned int vs_debug_tag;
10125 +extern unsigned int vs_debug_net;
10126 +extern unsigned int vs_debug_limit;
10127 +extern unsigned int vs_debug_cres;
10128 +extern unsigned int vs_debug_dlim;
10129 +extern unsigned int vs_debug_quota;
10130 +extern unsigned int vs_debug_cvirt;
10131 +extern unsigned int vs_debug_space;
10132 +extern unsigned int vs_debug_perm;
10133 +extern unsigned int vs_debug_misc;
10136 +#define VX_LOGLEVEL "vxD: "
10137 +#define VX_PROC_FMT "%p: "
10138 +#define VX_PROCESS current
10140 +#define vxdprintk(c, f, x...) \
10143 + printk(VX_LOGLEVEL VX_PROC_FMT f "\n", \
10144 + VX_PROCESS , ##x); \
10147 +#define vxlprintk(c, f, x...) \
10150 + printk(VX_LOGLEVEL f " @%s:%d\n", x); \
10153 +#define vxfprintk(c, f, x...) \
10156 + printk(VX_LOGLEVEL f " %s@%s:%d\n", x); \
10162 +void dump_vx_info(struct vx_info *, int);
10163 +void dump_vx_info_inactive(int);
10165 +#else /* CONFIG_VSERVER_DEBUG */
10167 +#define vs_debug_switch 0
10168 +#define vs_debug_xid 0
10169 +#define vs_debug_nid 0
10170 +#define vs_debug_tag 0
10171 +#define vs_debug_net 0
10172 +#define vs_debug_limit 0
10173 +#define vs_debug_cres 0
10174 +#define vs_debug_dlim 0
10175 +#define vs_debug_quota 0
10176 +#define vs_debug_cvirt 0
10177 +#define vs_debug_space 0
10178 +#define vs_debug_perm 0
10179 +#define vs_debug_misc 0
10181 +#define vxdprintk(x...) do { } while (0)
10182 +#define vxlprintk(x...) do { } while (0)
10183 +#define vxfprintk(x...) do { } while (0)
10185 +#endif /* CONFIG_VSERVER_DEBUG */
10188 +#ifdef CONFIG_VSERVER_WARN
10190 +#define VX_WARNLEVEL KERN_WARNING "vxW: "
10191 +#define VX_WARN_TASK "[" VS_Q("%s") ",%u:#%u|%u|%u] "
10192 +#define VX_WARN_XID "[xid #%u] "
10193 +#define VX_WARN_NID "[nid #%u] "
10194 +#define VX_WARN_TAG "[tag #%u] "
10196 +#define vxwprintk(c, f, x...) \
10199 + printk(VX_WARNLEVEL f "\n", ##x); \
10202 +#else /* CONFIG_VSERVER_WARN */
10204 +#define vxwprintk(x...) do { } while (0)
10206 +#endif /* CONFIG_VSERVER_WARN */
10208 +#define vxwprintk_task(c, f, x...) \
10209 + vxwprintk(c, VX_WARN_TASK f, \
10210 + current->comm, current->pid, \
10211 + current->xid, current->nid, \
10212 + current->tag, ##x)
10213 +#define vxwprintk_xid(c, f, x...) \
10214 + vxwprintk(c, VX_WARN_XID f, current->xid, x)
10215 +#define vxwprintk_nid(c, f, x...) \
10216 + vxwprintk(c, VX_WARN_NID f, current->nid, x)
10217 +#define vxwprintk_tag(c, f, x...) \
10218 + vxwprintk(c, VX_WARN_TAG f, current->tag, x)
10220 +#ifdef CONFIG_VSERVER_DEBUG
10221 +#define vxd_assert_lock(l) assert_spin_locked(l)
10222 +#define vxd_assert(c, f, x...) vxlprintk(!(c), \
10223 + "assertion [" f "] failed.", ##x, __FILE__, __LINE__)
10225 +#define vxd_assert_lock(l) do { } while (0)
10226 +#define vxd_assert(c, f, x...) do { } while (0)
10230 +#endif /* _VSERVER_DEBUG_H */
10231 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/debug_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug_cmd.h
10232 --- linux-3.13.10/include/linux/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
10233 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/debug_cmd.h 2014-01-31 20:38:03.000000000 +0000
10235 +#ifndef _VSERVER_DEBUG_CMD_H
10236 +#define _VSERVER_DEBUG_CMD_H
10238 +#include <uapi/vserver/debug_cmd.h>
10241 +#ifdef CONFIG_COMPAT
10243 +#include <asm/compat.h>
10245 +struct vcmd_read_history_v0_x32 {
10248 + compat_uptr_t data_ptr;
10251 +struct vcmd_read_monitor_v0_x32 {
10254 + compat_uptr_t data_ptr;
10257 +#endif /* CONFIG_COMPAT */
10259 +extern int vc_dump_history(uint32_t);
10261 +extern int vc_read_history(uint32_t, void __user *);
10262 +extern int vc_read_monitor(uint32_t, void __user *);
10264 +#ifdef CONFIG_COMPAT
10266 +extern int vc_read_history_x32(uint32_t, void __user *);
10267 +extern int vc_read_monitor_x32(uint32_t, void __user *);
10269 +#endif /* CONFIG_COMPAT */
10271 +#endif /* _VSERVER_DEBUG_CMD_H */
10272 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/device.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/device.h
10273 --- linux-3.13.10/include/linux/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
10274 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device.h 2014-01-31 20:38:03.000000000 +0000
10276 +#ifndef _VSERVER_DEVICE_H
10277 +#define _VSERVER_DEVICE_H
10280 +#include <uapi/vserver/device.h>
10282 +#else /* _VSERVER_DEVICE_H */
10283 +#warning duplicate inclusion
10284 +#endif /* _VSERVER_DEVICE_H */
10285 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/device_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_cmd.h
10286 --- linux-3.13.10/include/linux/vserver/device_cmd.h 1970-01-01 00:00:00.000000000 +0000
10287 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_cmd.h 2014-01-31 20:38:03.000000000 +0000
10289 +#ifndef _VSERVER_DEVICE_CMD_H
10290 +#define _VSERVER_DEVICE_CMD_H
10292 +#include <uapi/vserver/device_cmd.h>
10295 +#ifdef CONFIG_COMPAT
10297 +#include <asm/compat.h>
10299 +struct vcmd_set_mapping_v0_x32 {
10300 + compat_uptr_t device_ptr;
10301 + compat_uptr_t target_ptr;
10305 +#endif /* CONFIG_COMPAT */
10307 +#include <linux/compiler.h>
10309 +extern int vc_set_mapping(struct vx_info *, void __user *);
10310 +extern int vc_unset_mapping(struct vx_info *, void __user *);
10312 +#ifdef CONFIG_COMPAT
10314 +extern int vc_set_mapping_x32(struct vx_info *, void __user *);
10315 +extern int vc_unset_mapping_x32(struct vx_info *, void __user *);
10317 +#endif /* CONFIG_COMPAT */
10319 +#endif /* _VSERVER_DEVICE_CMD_H */
10320 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/device_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_def.h
10321 --- linux-3.13.10/include/linux/vserver/device_def.h 1970-01-01 00:00:00.000000000 +0000
10322 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/device_def.h 2014-01-31 20:38:03.000000000 +0000
10324 +#ifndef _VSERVER_DEVICE_DEF_H
10325 +#define _VSERVER_DEVICE_DEF_H
10327 +#include <linux/types.h>
10329 +struct vx_dmap_target {
10334 +struct _vx_device {
10335 +#ifdef CONFIG_VSERVER_DEVICE
10336 + struct vx_dmap_target targets[2];
10340 +#endif /* _VSERVER_DEVICE_DEF_H */
10341 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/dlimit.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit.h
10342 --- linux-3.13.10/include/linux/vserver/dlimit.h 1970-01-01 00:00:00.000000000 +0000
10343 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit.h 2014-01-31 20:38:03.000000000 +0000
10345 +#ifndef _VSERVER_DLIMIT_H
10346 +#define _VSERVER_DLIMIT_H
10348 +#include "switch.h"
10353 +/* keep in sync with CDLIM_INFINITY */
10355 +#define DLIM_INFINITY (~0ULL)
10357 +#include <linux/spinlock.h>
10358 +#include <linux/rcupdate.h>
10360 +struct super_block;
10363 + struct hlist_node dl_hlist; /* linked list of contexts */
10364 + struct rcu_head dl_rcu; /* the rcu head */
10365 + vtag_t dl_tag; /* context tag */
10366 + atomic_t dl_usecnt; /* usage count */
10367 + atomic_t dl_refcnt; /* reference count */
10369 + struct super_block *dl_sb; /* associated superblock */
10371 + spinlock_t dl_lock; /* protect the values */
10373 + unsigned long long dl_space_used; /* used space in bytes */
10374 + unsigned long long dl_space_total; /* maximum space in bytes */
10375 + unsigned long dl_inodes_used; /* used inodes */
10376 + unsigned long dl_inodes_total; /* maximum inodes */
10378 + unsigned int dl_nrlmult; /* non root limit mult */
10383 +extern void rcu_free_dl_info(struct rcu_head *);
10384 +extern void unhash_dl_info(struct dl_info *);
10386 +extern struct dl_info *locate_dl_info(struct super_block *, vtag_t);
10391 +extern void vx_vsi_statfs(struct super_block *, struct kstatfs *);
10393 +typedef uint64_t dlsize_t;
10395 +#endif /* __KERNEL__ */
10396 +#else /* _VSERVER_DLIMIT_H */
10397 +#warning duplicate inclusion
10398 +#endif /* _VSERVER_DLIMIT_H */
10399 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/dlimit_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit_cmd.h
10400 --- linux-3.13.10/include/linux/vserver/dlimit_cmd.h 1970-01-01 00:00:00.000000000 +0000
10401 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/dlimit_cmd.h 2014-01-31 20:38:03.000000000 +0000
10403 +#ifndef _VSERVER_DLIMIT_CMD_H
10404 +#define _VSERVER_DLIMIT_CMD_H
10406 +#include <uapi/vserver/dlimit_cmd.h>
10409 +#ifdef CONFIG_COMPAT
10411 +#include <asm/compat.h>
10413 +struct vcmd_ctx_dlimit_base_v0_x32 {
10414 + compat_uptr_t name_ptr;
10418 +struct vcmd_ctx_dlimit_v0_x32 {
10419 + compat_uptr_t name_ptr;
10420 + uint32_t space_used; /* used space in kbytes */
10421 + uint32_t space_total; /* maximum space in kbytes */
10422 + uint32_t inodes_used; /* used inodes */
10423 + uint32_t inodes_total; /* maximum inodes */
10424 + uint32_t reserved; /* reserved for root in % */
10428 +#endif /* CONFIG_COMPAT */
10430 +#include <linux/compiler.h>
10432 +extern int vc_add_dlimit(uint32_t, void __user *);
10433 +extern int vc_rem_dlimit(uint32_t, void __user *);
10435 +extern int vc_set_dlimit(uint32_t, void __user *);
10436 +extern int vc_get_dlimit(uint32_t, void __user *);
10438 +#ifdef CONFIG_COMPAT
10440 +extern int vc_add_dlimit_x32(uint32_t, void __user *);
10441 +extern int vc_rem_dlimit_x32(uint32_t, void __user *);
10443 +extern int vc_set_dlimit_x32(uint32_t, void __user *);
10444 +extern int vc_get_dlimit_x32(uint32_t, void __user *);
10446 +#endif /* CONFIG_COMPAT */
10448 +#endif /* _VSERVER_DLIMIT_CMD_H */
10449 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/global.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/global.h
10450 --- linux-3.13.10/include/linux/vserver/global.h 1970-01-01 00:00:00.000000000 +0000
10451 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/global.h 2014-01-31 20:38:03.000000000 +0000
10453 +#ifndef _VSERVER_GLOBAL_H
10454 +#define _VSERVER_GLOBAL_H
10457 +extern atomic_t vx_global_ctotal;
10458 +extern atomic_t vx_global_cactive;
10460 +extern atomic_t nx_global_ctotal;
10461 +extern atomic_t nx_global_cactive;
10463 +extern atomic_t vs_global_nsproxy;
10464 +extern atomic_t vs_global_fs;
10465 +extern atomic_t vs_global_mnt_ns;
10466 +extern atomic_t vs_global_uts_ns;
10467 +extern atomic_t vs_global_user_ns;
10468 +extern atomic_t vs_global_pid_ns;
10471 +#endif /* _VSERVER_GLOBAL_H */
10472 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/history.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/history.h
10473 --- linux-3.13.10/include/linux/vserver/history.h 1970-01-01 00:00:00.000000000 +0000
10474 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/history.h 2014-01-31 20:38:03.000000000 +0000
10476 +#ifndef _VSERVER_HISTORY_H
10477 +#define _VSERVER_HISTORY_H
10482 + VXH_THROW_OOPS = 1,
10486 + VXH_INIT_VX_INFO,
10489 + VXH_CLAIM_VX_INFO,
10490 + VXH_RELEASE_VX_INFO,
10491 + VXH_ALLOC_VX_INFO,
10492 + VXH_DEALLOC_VX_INFO,
10493 + VXH_HASH_VX_INFO,
10494 + VXH_UNHASH_VX_INFO,
10496 + VXH_LOOKUP_VX_INFO,
10497 + VXH_CREATE_VX_INFO,
10500 +struct _vxhe_vxi {
10501 + struct vx_info *ptr;
10507 +struct _vxhe_set_clr {
10511 +struct _vxhe_loc_lookup {
10515 +struct _vx_hist_entry {
10517 + unsigned short seq;
10518 + unsigned short type;
10519 + struct _vxhe_vxi vxi;
10521 + struct _vxhe_set_clr sc;
10522 + struct _vxhe_loc_lookup ll;
10526 +#ifdef CONFIG_VSERVER_HISTORY
10528 +extern unsigned volatile int vxh_active;
10530 +struct _vx_hist_entry *vxh_advance(void *loc);
10534 +void __vxh_copy_vxi(struct _vx_hist_entry *entry, struct vx_info *vxi)
10536 + entry->vxi.ptr = vxi;
10538 + entry->vxi.usecnt = atomic_read(&vxi->vx_usecnt);
10539 + entry->vxi.tasks = atomic_read(&vxi->vx_tasks);
10540 + entry->vxi.xid = vxi->vx_id;
10545 +#define __HERE__ current_text_addr()
10547 +#define __VXH_BODY(__type, __data, __here) \
10548 + struct _vx_hist_entry *entry; \
10550 + preempt_disable(); \
10551 + entry = vxh_advance(__here); \
10553 + entry->type = __type; \
10554 + preempt_enable();
10557 + /* pass vxi only */
10559 +#define __VXH_SMPL \
10560 + __vxh_copy_vxi(entry, vxi)
10563 +void __vxh_smpl(struct vx_info *vxi, int __type, void *__here)
10565 + __VXH_BODY(__type, __VXH_SMPL, __here)
10568 + /* pass vxi and data (void *) */
10570 +#define __VXH_DATA \
10571 + __vxh_copy_vxi(entry, vxi); \
10572 + entry->sc.data = data
10575 +void __vxh_data(struct vx_info *vxi, void *data,
10576 + int __type, void *__here)
10578 + __VXH_BODY(__type, __VXH_DATA, __here)
10581 + /* pass vxi and arg (long) */
10583 +#define __VXH_LONG \
10584 + __vxh_copy_vxi(entry, vxi); \
10585 + entry->ll.arg = arg
10588 +void __vxh_long(struct vx_info *vxi, long arg,
10589 + int __type, void *__here)
10591 + __VXH_BODY(__type, __VXH_LONG, __here)
10596 +void __vxh_throw_oops(void *__here)
10598 + __VXH_BODY(VXH_THROW_OOPS, {}, __here);
10599 + /* prevent further acquisition */
10604 +#define vxh_throw_oops() __vxh_throw_oops(__HERE__);
10606 +#define __vxh_get_vx_info(v, h) __vxh_smpl(v, VXH_GET_VX_INFO, h);
10607 +#define __vxh_put_vx_info(v, h) __vxh_smpl(v, VXH_PUT_VX_INFO, h);
10609 +#define __vxh_init_vx_info(v, d, h) \
10610 + __vxh_data(v, d, VXH_INIT_VX_INFO, h);
10611 +#define __vxh_set_vx_info(v, d, h) \
10612 + __vxh_data(v, d, VXH_SET_VX_INFO, h);
10613 +#define __vxh_clr_vx_info(v, d, h) \
10614 + __vxh_data(v, d, VXH_CLR_VX_INFO, h);
10616 +#define __vxh_claim_vx_info(v, d, h) \
10617 + __vxh_data(v, d, VXH_CLAIM_VX_INFO, h);
10618 +#define __vxh_release_vx_info(v, d, h) \
10619 + __vxh_data(v, d, VXH_RELEASE_VX_INFO, h);
10621 +#define vxh_alloc_vx_info(v) \
10622 + __vxh_smpl(v, VXH_ALLOC_VX_INFO, __HERE__);
10623 +#define vxh_dealloc_vx_info(v) \
10624 + __vxh_smpl(v, VXH_DEALLOC_VX_INFO, __HERE__);
10626 +#define vxh_hash_vx_info(v) \
10627 + __vxh_smpl(v, VXH_HASH_VX_INFO, __HERE__);
10628 +#define vxh_unhash_vx_info(v) \
10629 + __vxh_smpl(v, VXH_UNHASH_VX_INFO, __HERE__);
10631 +#define vxh_loc_vx_info(v, l) \
10632 + __vxh_long(v, l, VXH_LOC_VX_INFO, __HERE__);
10633 +#define vxh_lookup_vx_info(v, l) \
10634 + __vxh_long(v, l, VXH_LOOKUP_VX_INFO, __HERE__);
10635 +#define vxh_create_vx_info(v, l) \
10636 + __vxh_long(v, l, VXH_CREATE_VX_INFO, __HERE__);
10638 +extern void vxh_dump_history(void);
10641 +#else /* CONFIG_VSERVER_HISTORY */
10643 +#define __HERE__ 0
10645 +#define vxh_throw_oops() do { } while (0)
10647 +#define __vxh_get_vx_info(v, h) do { } while (0)
10648 +#define __vxh_put_vx_info(v, h) do { } while (0)
10650 +#define __vxh_init_vx_info(v, d, h) do { } while (0)
10651 +#define __vxh_set_vx_info(v, d, h) do { } while (0)
10652 +#define __vxh_clr_vx_info(v, d, h) do { } while (0)
10654 +#define __vxh_claim_vx_info(v, d, h) do { } while (0)
10655 +#define __vxh_release_vx_info(v, d, h) do { } while (0)
10657 +#define vxh_alloc_vx_info(v) do { } while (0)
10658 +#define vxh_dealloc_vx_info(v) do { } while (0)
10660 +#define vxh_hash_vx_info(v) do { } while (0)
10661 +#define vxh_unhash_vx_info(v) do { } while (0)
10663 +#define vxh_loc_vx_info(v, l) do { } while (0)
10664 +#define vxh_lookup_vx_info(v, l) do { } while (0)
10665 +#define vxh_create_vx_info(v, l) do { } while (0)
10667 +#define vxh_dump_history() do { } while (0)
10670 +#endif /* CONFIG_VSERVER_HISTORY */
10672 +#endif /* _VSERVER_HISTORY_H */
10673 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/inode.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode.h
10674 --- linux-3.13.10/include/linux/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
10675 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode.h 2014-01-31 20:38:03.000000000 +0000
10677 +#ifndef _VSERVER_INODE_H
10678 +#define _VSERVER_INODE_H
10680 +#include <uapi/vserver/inode.h>
10683 +#ifdef CONFIG_VSERVER_PROC_SECURE
10684 +#define IATTR_PROC_DEFAULT ( IATTR_ADMIN | IATTR_HIDE )
10685 +#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
10687 +#define IATTR_PROC_DEFAULT ( IATTR_ADMIN )
10688 +#define IATTR_PROC_SYMLINK ( IATTR_ADMIN )
10691 +#define vx_hide_check(c, m) (((m) & IATTR_HIDE) ? vx_check(c, m) : 1)
10693 +#else /* _VSERVER_INODE_H */
10694 +#warning duplicate inclusion
10695 +#endif /* _VSERVER_INODE_H */
10696 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/inode_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode_cmd.h
10697 --- linux-3.13.10/include/linux/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
10698 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/inode_cmd.h 2014-01-31 20:38:03.000000000 +0000
10700 +#ifndef _VSERVER_INODE_CMD_H
10701 +#define _VSERVER_INODE_CMD_H
10703 +#include <uapi/vserver/inode_cmd.h>
10707 +#ifdef CONFIG_COMPAT
10709 +#include <asm/compat.h>
10711 +struct vcmd_ctx_iattr_v1_x32 {
10712 + compat_uptr_t name_ptr;
10718 +#endif /* CONFIG_COMPAT */
10720 +#include <linux/compiler.h>
10722 +extern int vc_get_iattr(void __user *);
10723 +extern int vc_set_iattr(void __user *);
10725 +extern int vc_fget_iattr(uint32_t, void __user *);
10726 +extern int vc_fset_iattr(uint32_t, void __user *);
10728 +#ifdef CONFIG_COMPAT
10730 +extern int vc_get_iattr_x32(void __user *);
10731 +extern int vc_set_iattr_x32(void __user *);
10733 +#endif /* CONFIG_COMPAT */
10735 +#endif /* _VSERVER_INODE_CMD_H */
10736 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit.h
10737 --- linux-3.13.10/include/linux/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
10738 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit.h 2014-01-31 20:38:03.000000000 +0000
10740 +#ifndef _VSERVER_LIMIT_H
10741 +#define _VSERVER_LIMIT_H
10743 +#include <uapi/vserver/limit.h>
10746 +#define VLIM_NOCHECK ((1L << VLIMIT_DENTRY) | (1L << RLIMIT_RSS))
10748 +/* keep in sync with CRLIM_INFINITY */
10750 +#define VLIM_INFINITY (~0ULL)
10752 +#include <asm/atomic.h>
10753 +#include <asm/resource.h>
10755 +#ifndef RLIM_INFINITY
10756 +#warning RLIM_INFINITY is undefined
10759 +#define __rlim_val(l, r, v) ((l)->res[r].v)
10761 +#define __rlim_soft(l, r) __rlim_val(l, r, soft)
10762 +#define __rlim_hard(l, r) __rlim_val(l, r, hard)
10764 +#define __rlim_rcur(l, r) __rlim_val(l, r, rcur)
10765 +#define __rlim_rmin(l, r) __rlim_val(l, r, rmin)
10766 +#define __rlim_rmax(l, r) __rlim_val(l, r, rmax)
10768 +#define __rlim_lhit(l, r) __rlim_val(l, r, lhit)
10769 +#define __rlim_hit(l, r) atomic_inc(&__rlim_lhit(l, r))
10771 +typedef atomic_long_t rlim_atomic_t;
10772 +typedef unsigned long rlim_t;
10774 +#define __rlim_get(l, r) atomic_long_read(&__rlim_rcur(l, r))
10775 +#define __rlim_set(l, r, v) atomic_long_set(&__rlim_rcur(l, r), v)
10776 +#define __rlim_inc(l, r) atomic_long_inc(&__rlim_rcur(l, r))
10777 +#define __rlim_dec(l, r) atomic_long_dec(&__rlim_rcur(l, r))
10778 +#define __rlim_add(l, r, v) atomic_long_add(v, &__rlim_rcur(l, r))
10779 +#define __rlim_sub(l, r, v) atomic_long_sub(v, &__rlim_rcur(l, r))
10782 +#if (RLIM_INFINITY == VLIM_INFINITY)
10783 +#define VX_VLIM(r) ((long long)(long)(r))
10784 +#define VX_RLIM(v) ((rlim_t)(v))
10786 +#define VX_VLIM(r) (((r) == RLIM_INFINITY) \
10787 + ? VLIM_INFINITY : (long long)(r))
10788 +#define VX_RLIM(v) (((v) == VLIM_INFINITY) \
10789 + ? RLIM_INFINITY : (rlim_t)(v))
10794 +void vx_vsi_meminfo(struct sysinfo *);
10795 +void vx_vsi_swapinfo(struct sysinfo *);
10796 +long vx_vsi_cached(struct sysinfo *);
10798 +#define NUM_LIMITS 24
10800 +#endif /* _VSERVER_LIMIT_H */
10801 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_cmd.h
10802 --- linux-3.13.10/include/linux/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
10803 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_cmd.h 2014-01-31 20:38:03.000000000 +0000
10805 +#ifndef _VSERVER_LIMIT_CMD_H
10806 +#define _VSERVER_LIMIT_CMD_H
10808 +#include <uapi/vserver/limit_cmd.h>
10811 +#ifdef CONFIG_IA32_EMULATION
10813 +struct vcmd_ctx_rlimit_v0_x32 {
10815 + uint64_t minimum;
10816 + uint64_t softlimit;
10817 + uint64_t maximum;
10818 +} __attribute__ ((packed));
10820 +#endif /* CONFIG_IA32_EMULATION */
10822 +#include <linux/compiler.h>
10824 +extern int vc_get_rlimit_mask(uint32_t, void __user *);
10825 +extern int vc_get_rlimit(struct vx_info *, void __user *);
10826 +extern int vc_set_rlimit(struct vx_info *, void __user *);
10827 +extern int vc_reset_hits(struct vx_info *, void __user *);
10828 +extern int vc_reset_minmax(struct vx_info *, void __user *);
10830 +extern int vc_rlimit_stat(struct vx_info *, void __user *);
10832 +#ifdef CONFIG_IA32_EMULATION
10834 +extern int vc_get_rlimit_x32(struct vx_info *, void __user *);
10835 +extern int vc_set_rlimit_x32(struct vx_info *, void __user *);
10837 +#endif /* CONFIG_IA32_EMULATION */
10839 +#endif /* _VSERVER_LIMIT_CMD_H */
10840 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_def.h
10841 --- linux-3.13.10/include/linux/vserver/limit_def.h 1970-01-01 00:00:00.000000000 +0000
10842 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_def.h 2014-01-31 20:38:03.000000000 +0000
10844 +#ifndef _VSERVER_LIMIT_DEF_H
10845 +#define _VSERVER_LIMIT_DEF_H
10847 +#include <asm/atomic.h>
10848 +#include <asm/resource.h>
10850 +#include "limit.h"
10853 +struct _vx_res_limit {
10854 + rlim_t soft; /* Context soft limit */
10855 + rlim_t hard; /* Context hard limit */
10857 + rlim_atomic_t rcur; /* Current value */
10858 + rlim_t rmin; /* Context minimum */
10859 + rlim_t rmax; /* Context maximum */
10861 + atomic_t lhit; /* Limit hits */
10864 +/* context sub struct */
10866 +struct _vx_limit {
10867 + struct _vx_res_limit res[NUM_LIMITS];
10870 +#ifdef CONFIG_VSERVER_DEBUG
10872 +static inline void __dump_vx_limit(struct _vx_limit *limit)
10876 + printk("\t_vx_limit:");
10877 + for (i = 0; i < NUM_LIMITS; i++) {
10878 + printk("\t [%2d] = %8lu %8lu/%8lu, %8ld/%8ld, %8d\n",
10879 + i, (unsigned long)__rlim_get(limit, i),
10880 + (unsigned long)__rlim_rmin(limit, i),
10881 + (unsigned long)__rlim_rmax(limit, i),
10882 + (long)__rlim_soft(limit, i),
10883 + (long)__rlim_hard(limit, i),
10884 + atomic_read(&__rlim_lhit(limit, i)));
10890 +#endif /* _VSERVER_LIMIT_DEF_H */
10891 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/limit_int.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_int.h
10892 --- linux-3.13.10/include/linux/vserver/limit_int.h 1970-01-01 00:00:00.000000000 +0000
10893 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/limit_int.h 2014-01-31 20:38:03.000000000 +0000
10895 +#ifndef _VSERVER_LIMIT_INT_H
10896 +#define _VSERVER_LIMIT_INT_H
10898 +#define VXD_RCRES_COND(r) VXD_CBIT(cres, r)
10899 +#define VXD_RLIMIT_COND(r) VXD_CBIT(limit, r)
10901 +extern const char *vlimit_name[NUM_LIMITS];
10903 +static inline void __vx_acc_cres(struct vx_info *vxi,
10904 + int res, int dir, void *_data, char *_file, int _line)
10906 + if (VXD_RCRES_COND(res))
10907 + vxlprintk(1, "vx_acc_cres[%5d,%s,%2d]: %5ld%s (%p)",
10908 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10909 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10910 + (dir > 0) ? "++" : "--", _data, _file, _line);
10915 + __rlim_inc(&vxi->limit, res);
10917 + __rlim_dec(&vxi->limit, res);
10920 +static inline void __vx_add_cres(struct vx_info *vxi,
10921 + int res, int amount, void *_data, char *_file, int _line)
10923 + if (VXD_RCRES_COND(res))
10924 + vxlprintk(1, "vx_add_cres[%5d,%s,%2d]: %5ld += %5d (%p)",
10925 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10926 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10927 + amount, _data, _file, _line);
10932 + __rlim_add(&vxi->limit, res, amount);
10936 +int __vx_cres_adjust_max(struct _vx_limit *limit, int res, rlim_t value)
10938 + int cond = (value > __rlim_rmax(limit, res));
10941 + __rlim_rmax(limit, res) = value;
10946 +int __vx_cres_adjust_min(struct _vx_limit *limit, int res, rlim_t value)
10948 + int cond = (value < __rlim_rmin(limit, res));
10951 + __rlim_rmin(limit, res) = value;
10956 +void __vx_cres_fixup(struct _vx_limit *limit, int res, rlim_t value)
10958 + if (!__vx_cres_adjust_max(limit, res, value))
10959 + __vx_cres_adjust_min(limit, res, value);
10964 + +1 ... no limit hit
10965 + -1 ... over soft limit
10966 + 0 ... over hard limit */
10968 +static inline int __vx_cres_avail(struct vx_info *vxi,
10969 + int res, int num, char *_file, int _line)
10971 + struct _vx_limit *limit;
10974 + if (VXD_RLIMIT_COND(res))
10975 + vxlprintk(1, "vx_cres_avail[%5d,%s,%2d]: %5ld/%5ld > %5ld + %5d",
10976 + (vxi ? vxi->vx_id : -1), vlimit_name[res], res,
10977 + (vxi ? (long)__rlim_soft(&vxi->limit, res) : -1),
10978 + (vxi ? (long)__rlim_hard(&vxi->limit, res) : -1),
10979 + (vxi ? (long)__rlim_get(&vxi->limit, res) : 0),
10980 + num, _file, _line);
10984 + limit = &vxi->limit;
10985 + value = __rlim_get(limit, res);
10987 + if (!__vx_cres_adjust_max(limit, res, value))
10988 + __vx_cres_adjust_min(limit, res, value);
10993 + if (__rlim_soft(limit, res) == RLIM_INFINITY)
10995 + if (value + num <= __rlim_soft(limit, res))
10998 + if (__rlim_hard(limit, res) == RLIM_INFINITY)
11000 + if (value + num <= __rlim_hard(limit, res))
11003 + __rlim_hit(limit, res);
11008 +static const int VLA_RSS[] = { RLIMIT_RSS, VLIMIT_ANON, VLIMIT_MAPPED, 0 };
11011 +rlim_t __vx_cres_array_sum(struct _vx_limit *limit, const int *array)
11013 + rlim_t value, sum = 0;
11016 + while ((res = *array++)) {
11017 + value = __rlim_get(limit, res);
11018 + __vx_cres_fixup(limit, res, value);
11025 +rlim_t __vx_cres_array_fixup(struct _vx_limit *limit, const int *array)
11027 + rlim_t value = __vx_cres_array_sum(limit, array + 1);
11028 + int res = *array;
11030 + if (value == __rlim_get(limit, res))
11033 + __rlim_set(limit, res, value);
11034 + /* now adjust min/max */
11035 + if (!__vx_cres_adjust_max(limit, res, value))
11036 + __vx_cres_adjust_min(limit, res, value);
11041 +static inline int __vx_cres_array_avail(struct vx_info *vxi,
11042 + const int *array, int num, char *_file, int _line)
11044 + struct _vx_limit *limit;
11045 + rlim_t value = 0;
11053 + limit = &vxi->limit;
11055 + value = __vx_cres_array_sum(limit, array + 1);
11057 + __rlim_set(limit, res, value);
11058 + __vx_cres_fixup(limit, res, value);
11060 + return __vx_cres_avail(vxi, res, num, _file, _line);
11064 +static inline void vx_limit_fixup(struct _vx_limit *limit, int id)
11069 + /* complex resources first */
11070 + if ((id < 0) || (id == RLIMIT_RSS))
11071 + __vx_cres_array_fixup(limit, VLA_RSS);
11073 + for (res = 0; res < NUM_LIMITS; res++) {
11074 + if ((id > 0) && (res != id))
11077 + value = __rlim_get(limit, res);
11078 + __vx_cres_fixup(limit, res, value);
11080 + /* not supposed to happen, maybe warn? */
11081 + if (__rlim_rmax(limit, res) > __rlim_hard(limit, res))
11082 + __rlim_rmax(limit, res) = __rlim_hard(limit, res);
11087 +#endif /* _VSERVER_LIMIT_INT_H */
11088 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/monitor.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/monitor.h
11089 --- linux-3.13.10/include/linux/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
11090 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/monitor.h 2014-01-31 20:38:03.000000000 +0000
11092 +#ifndef _VSERVER_MONITOR_H
11093 +#define _VSERVER_MONITOR_H
11095 +#include <uapi/vserver/monitor.h>
11097 +#endif /* _VSERVER_MONITOR_H */
11098 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/network.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/network.h
11099 --- linux-3.13.10/include/linux/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
11100 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/network.h 2014-01-31 20:38:03.000000000 +0000
11102 +#ifndef _VSERVER_NETWORK_H
11103 +#define _VSERVER_NETWORK_H
11106 +#include <linux/list.h>
11107 +#include <linux/spinlock.h>
11108 +#include <linux/rcupdate.h>
11109 +#include <linux/in.h>
11110 +#include <linux/in6.h>
11111 +#include <asm/atomic.h>
11112 +#include <uapi/vserver/network.h>
11114 +struct nx_addr_v4 {
11115 + struct nx_addr_v4 *next;
11116 + struct in_addr ip[2];
11117 + struct in_addr mask;
11122 +struct nx_addr_v6 {
11123 + struct nx_addr_v6 *next;
11124 + struct in6_addr ip;
11125 + struct in6_addr mask;
11132 + struct hlist_node nx_hlist; /* linked list of nxinfos */
11133 + vnid_t nx_id; /* vnet id */
11134 + atomic_t nx_usecnt; /* usage count */
11135 + atomic_t nx_tasks; /* tasks count */
11136 + int nx_state; /* context state */
11138 + uint64_t nx_flags; /* network flag word */
11139 + uint64_t nx_ncaps; /* network capabilities */
11141 + spinlock_t addr_lock; /* protect address changes */
11142 + struct in_addr v4_lback; /* Loopback address */
11143 + struct in_addr v4_bcast; /* Broadcast address */
11144 + struct nx_addr_v4 v4; /* First/Single ipv4 address */
11145 +#ifdef CONFIG_IPV6
11146 + struct nx_addr_v6 v6; /* First/Single ipv6 address */
11148 + char nx_name[65]; /* network context name */
11152 +/* status flags */
11154 +#define NXS_HASHED 0x0001
11155 +#define NXS_SHUTDOWN 0x0100
11156 +#define NXS_RELEASED 0x8000
11158 +extern struct nx_info *lookup_nx_info(int);
11160 +extern int get_nid_list(int, unsigned int *, int);
11161 +extern int nid_is_hashed(vnid_t);
11163 +extern int nx_migrate_task(struct task_struct *, struct nx_info *);
11165 +extern long vs_net_change(struct nx_info *, unsigned int);
11170 +#define NX_IPV4(n) ((n)->v4.type != NXA_TYPE_NONE)
11171 +#ifdef CONFIG_IPV6
11172 +#define NX_IPV6(n) ((n)->v6.type != NXA_TYPE_NONE)
11174 +#define NX_IPV6(n) (0)
11177 +#endif /* _VSERVER_NETWORK_H */
11178 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/network_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/network_cmd.h
11179 --- linux-3.13.10/include/linux/vserver/network_cmd.h 1970-01-01 00:00:00.000000000 +0000
11180 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/network_cmd.h 2014-01-31 20:38:03.000000000 +0000
11182 +#ifndef _VSERVER_NETWORK_CMD_H
11183 +#define _VSERVER_NETWORK_CMD_H
11185 +#include <uapi/vserver/network_cmd.h>
11187 +extern int vc_task_nid(uint32_t);
11189 +extern int vc_nx_info(struct nx_info *, void __user *);
11191 +extern int vc_net_create(uint32_t, void __user *);
11192 +extern int vc_net_migrate(struct nx_info *, void __user *);
11194 +extern int vc_net_add(struct nx_info *, void __user *);
11195 +extern int vc_net_remove(struct nx_info *, void __user *);
11197 +extern int vc_net_add_ipv4_v1(struct nx_info *, void __user *);
11198 +extern int vc_net_add_ipv4(struct nx_info *, void __user *);
11200 +extern int vc_net_rem_ipv4_v1(struct nx_info *, void __user *);
11201 +extern int vc_net_rem_ipv4(struct nx_info *, void __user *);
11203 +extern int vc_net_add_ipv6(struct nx_info *, void __user *);
11204 +extern int vc_net_remove_ipv6(struct nx_info *, void __user *);
11206 +extern int vc_add_match_ipv4(struct nx_info *, void __user *);
11207 +extern int vc_get_match_ipv4(struct nx_info *, void __user *);
11209 +extern int vc_add_match_ipv6(struct nx_info *, void __user *);
11210 +extern int vc_get_match_ipv6(struct nx_info *, void __user *);
11212 +extern int vc_get_nflags(struct nx_info *, void __user *);
11213 +extern int vc_set_nflags(struct nx_info *, void __user *);
11215 +extern int vc_get_ncaps(struct nx_info *, void __user *);
11216 +extern int vc_set_ncaps(struct nx_info *, void __user *);
11218 +#endif /* _VSERVER_CONTEXT_CMD_H */
11219 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/percpu.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/percpu.h
11220 --- linux-3.13.10/include/linux/vserver/percpu.h 1970-01-01 00:00:00.000000000 +0000
11221 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/percpu.h 2014-01-31 20:38:03.000000000 +0000
11223 +#ifndef _VSERVER_PERCPU_H
11224 +#define _VSERVER_PERCPU_H
11226 +#include "cvirt_def.h"
11227 +#include "sched_def.h"
11229 +struct _vx_percpu {
11230 + struct _vx_cvirt_pc cvirt;
11231 + struct _vx_sched_pc sched;
11234 +#define PERCPU_PERCTX (sizeof(struct _vx_percpu))
11236 +#endif /* _VSERVER_PERCPU_H */
11237 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/pid.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/pid.h
11238 --- linux-3.13.10/include/linux/vserver/pid.h 1970-01-01 00:00:00.000000000 +0000
11239 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/pid.h 2014-01-31 20:38:03.000000000 +0000
11241 +#ifndef _VSERVER_PID_H
11242 +#define _VSERVER_PID_H
11244 +/* pid faking stuff */
11246 +#define vx_info_map_pid(v, p) \
11247 + __vx_info_map_pid((v), (p), __func__, __FILE__, __LINE__)
11248 +#define vx_info_map_tgid(v,p) vx_info_map_pid(v,p)
11249 +#define vx_map_pid(p) vx_info_map_pid(current_vx_info(), p)
11250 +#define vx_map_tgid(p) vx_map_pid(p)
11252 +static inline int __vx_info_map_pid(struct vx_info *vxi, int pid,
11253 + const char *func, const char *file, int line)
11255 + if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11256 + vxfprintk(VXD_CBIT(cvirt, 2),
11257 + "vx_map_tgid: %p/%llx: %d -> %d",
11258 + vxi, (long long)vxi->vx_flags, pid,
11259 + (pid && pid == vxi->vx_initpid) ? 1 : pid,
11260 + func, file, line);
11263 + if (pid == vxi->vx_initpid)
11269 +#define vx_info_rmap_pid(v, p) \
11270 + __vx_info_rmap_pid((v), (p), __func__, __FILE__, __LINE__)
11271 +#define vx_rmap_pid(p) vx_info_rmap_pid(current_vx_info(), p)
11272 +#define vx_rmap_tgid(p) vx_rmap_pid(p)
11274 +static inline int __vx_info_rmap_pid(struct vx_info *vxi, int pid,
11275 + const char *func, const char *file, int line)
11277 + if (vx_info_flags(vxi, VXF_INFO_INIT, 0)) {
11278 + vxfprintk(VXD_CBIT(cvirt, 2),
11279 + "vx_rmap_tgid: %p/%llx: %d -> %d",
11280 + vxi, (long long)vxi->vx_flags, pid,
11281 + (pid == 1) ? vxi->vx_initpid : pid,
11282 + func, file, line);
11283 + if ((pid == 1) && vxi->vx_initpid)
11284 + return vxi->vx_initpid;
11285 + if (pid == vxi->vx_initpid)
11292 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/sched.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched.h
11293 --- linux-3.13.10/include/linux/vserver/sched.h 1970-01-01 00:00:00.000000000 +0000
11294 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched.h 2014-01-31 20:38:03.000000000 +0000
11296 +#ifndef _VSERVER_SCHED_H
11297 +#define _VSERVER_SCHED_H
11304 +void vx_vsi_uptime(struct timespec *, struct timespec *);
11309 +void vx_update_load(struct vx_info *);
11312 +void vx_update_sched_param(struct _vx_sched *sched,
11313 + struct _vx_sched_pc *sched_pc);
11315 +#endif /* __KERNEL__ */
11316 +#else /* _VSERVER_SCHED_H */
11317 +#warning duplicate inclusion
11318 +#endif /* _VSERVER_SCHED_H */
11319 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/sched_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_cmd.h
11320 --- linux-3.13.10/include/linux/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
11321 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_cmd.h 2014-01-31 20:38:03.000000000 +0000
11323 +#ifndef _VSERVER_SCHED_CMD_H
11324 +#define _VSERVER_SCHED_CMD_H
11327 +#include <linux/compiler.h>
11328 +#include <uapi/vserver/sched_cmd.h>
11330 +extern int vc_set_prio_bias(struct vx_info *, void __user *);
11331 +extern int vc_get_prio_bias(struct vx_info *, void __user *);
11333 +#endif /* _VSERVER_SCHED_CMD_H */
11334 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/sched_def.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_def.h
11335 --- linux-3.13.10/include/linux/vserver/sched_def.h 1970-01-01 00:00:00.000000000 +0000
11336 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/sched_def.h 2014-01-31 20:38:03.000000000 +0000
11338 +#ifndef _VSERVER_SCHED_DEF_H
11339 +#define _VSERVER_SCHED_DEF_H
11341 +#include <linux/spinlock.h>
11342 +#include <linux/jiffies.h>
11343 +#include <linux/cpumask.h>
11344 +#include <asm/atomic.h>
11345 +#include <asm/param.h>
11348 +/* context sub struct */
11350 +struct _vx_sched {
11351 + int prio_bias; /* bias offset for priority */
11353 + cpumask_t update; /* CPUs which should update */
11356 +struct _vx_sched_pc {
11357 + int prio_bias; /* bias offset for priority */
11359 + uint64_t user_ticks; /* token tick events */
11360 + uint64_t sys_ticks; /* token tick events */
11361 + uint64_t hold_ticks; /* token ticks paused */
11365 +#ifdef CONFIG_VSERVER_DEBUG
11367 +static inline void __dump_vx_sched(struct _vx_sched *sched)
11369 + printk("\t_vx_sched:\n");
11370 + printk("\t priority = %4d\n", sched->prio_bias);
11375 +#endif /* _VSERVER_SCHED_DEF_H */
11376 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/signal.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal.h
11377 --- linux-3.13.10/include/linux/vserver/signal.h 1970-01-01 00:00:00.000000000 +0000
11378 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal.h 2014-01-31 20:38:03.000000000 +0000
11380 +#ifndef _VSERVER_SIGNAL_H
11381 +#define _VSERVER_SIGNAL_H
11388 +int vx_info_kill(struct vx_info *, int, int);
11390 +#endif /* __KERNEL__ */
11391 +#else /* _VSERVER_SIGNAL_H */
11392 +#warning duplicate inclusion
11393 +#endif /* _VSERVER_SIGNAL_H */
11394 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/signal_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal_cmd.h
11395 --- linux-3.13.10/include/linux/vserver/signal_cmd.h 1970-01-01 00:00:00.000000000 +0000
11396 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/signal_cmd.h 2014-01-31 20:38:03.000000000 +0000
11398 +#ifndef _VSERVER_SIGNAL_CMD_H
11399 +#define _VSERVER_SIGNAL_CMD_H
11401 +#include <uapi/vserver/signal_cmd.h>
11404 +extern int vc_ctx_kill(struct vx_info *, void __user *);
11405 +extern int vc_wait_exit(struct vx_info *, void __user *);
11408 +extern int vc_get_pflags(uint32_t pid, void __user *);
11409 +extern int vc_set_pflags(uint32_t pid, void __user *);
11411 +#endif /* _VSERVER_SIGNAL_CMD_H */
11412 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/space.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/space.h
11413 --- linux-3.13.10/include/linux/vserver/space.h 1970-01-01 00:00:00.000000000 +0000
11414 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/space.h 2014-01-31 20:38:03.000000000 +0000
11416 +#ifndef _VSERVER_SPACE_H
11417 +#define _VSERVER_SPACE_H
11419 +#include <linux/types.h>
11423 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index);
11425 +#else /* _VSERVER_SPACE_H */
11426 +#warning duplicate inclusion
11427 +#endif /* _VSERVER_SPACE_H */
11428 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/space_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/space_cmd.h
11429 --- linux-3.13.10/include/linux/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
11430 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/space_cmd.h 2014-01-31 20:38:03.000000000 +0000
11432 +#ifndef _VSERVER_SPACE_CMD_H
11433 +#define _VSERVER_SPACE_CMD_H
11435 +#include <uapi/vserver/space_cmd.h>
11438 +extern int vc_enter_space_v1(struct vx_info *, void __user *);
11439 +extern int vc_set_space_v1(struct vx_info *, void __user *);
11440 +extern int vc_enter_space(struct vx_info *, void __user *);
11441 +extern int vc_set_space(struct vx_info *, void __user *);
11442 +extern int vc_get_space_mask(void __user *, int);
11444 +#endif /* _VSERVER_SPACE_CMD_H */
11445 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/switch.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/switch.h
11446 --- linux-3.13.10/include/linux/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
11447 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/switch.h 2014-01-31 20:38:03.000000000 +0000
11449 +#ifndef _VSERVER_SWITCH_H
11450 +#define _VSERVER_SWITCH_H
11453 +#include <linux/errno.h>
11454 +#include <uapi/vserver/switch.h>
11456 +#endif /* _VSERVER_SWITCH_H */
11457 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/tag.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag.h
11458 --- linux-3.13.10/include/linux/vserver/tag.h 1970-01-01 00:00:00.000000000 +0000
11459 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag.h 2014-01-31 20:38:03.000000000 +0000
11464 +#include <linux/types.h>
11465 +#include <linux/uidgid.h>
11468 +#define DX_TAG(in) (IS_TAGGED(in))
11471 +#ifdef CONFIG_TAG_NFSD
11472 +#define DX_TAG_NFSD 1
11474 +#define DX_TAG_NFSD 0
11478 +#ifdef CONFIG_TAGGING_NONE
11480 +#define MAX_UID 0xFFFFFFFF
11481 +#define MAX_GID 0xFFFFFFFF
11483 +#define INOTAG_TAG(cond, uid, gid, tag) (0)
11485 +#define TAGINO_UID(cond, uid, tag) (uid)
11486 +#define TAGINO_GID(cond, gid, tag) (gid)
11491 +#ifdef CONFIG_TAGGING_GID16
11493 +#define MAX_UID 0xFFFFFFFF
11494 +#define MAX_GID 0x0000FFFF
11496 +#define INOTAG_TAG(cond, uid, gid, tag) \
11497 + ((cond) ? (((gid) >> 16) & 0xFFFF) : 0)
11499 +#define TAGINO_UID(cond, uid, tag) (uid)
11500 +#define TAGINO_GID(cond, gid, tag) \
11501 + ((cond) ? (((gid) & 0xFFFF) | ((tag) << 16)) : (gid))
11506 +#ifdef CONFIG_TAGGING_ID24
11508 +#define MAX_UID 0x00FFFFFF
11509 +#define MAX_GID 0x00FFFFFF
11511 +#define INOTAG_TAG(cond, uid, gid, tag) \
11512 + ((cond) ? ((((uid) >> 16) & 0xFF00) | (((gid) >> 24) & 0xFF)) : 0)
11514 +#define TAGINO_UID(cond, uid, tag) \
11515 + ((cond) ? (((uid) & 0xFFFFFF) | (((tag) & 0xFF00) << 16)) : (uid))
11516 +#define TAGINO_GID(cond, gid, tag) \
11517 + ((cond) ? (((gid) & 0xFFFFFF) | (((tag) & 0x00FF) << 24)) : (gid))
11522 +#ifdef CONFIG_TAGGING_UID16
11524 +#define MAX_UID 0x0000FFFF
11525 +#define MAX_GID 0xFFFFFFFF
11527 +#define INOTAG_TAG(cond, uid, gid, tag) \
11528 + ((cond) ? (((uid) >> 16) & 0xFFFF) : 0)
11530 +#define TAGINO_UID(cond, uid, tag) \
11531 + ((cond) ? (((uid) & 0xFFFF) | ((tag) << 16)) : (uid))
11532 +#define TAGINO_GID(cond, gid, tag) (gid)
11537 +#ifdef CONFIG_TAGGING_INTERN
11539 +#define MAX_UID 0xFFFFFFFF
11540 +#define MAX_GID 0xFFFFFFFF
11542 +#define INOTAG_TAG(cond, uid, gid, tag) \
11543 + ((cond) ? (tag) : 0)
11545 +#define TAGINO_UID(cond, uid, tag) (uid)
11546 +#define TAGINO_GID(cond, gid, tag) (gid)
11551 +#ifndef CONFIG_TAGGING_NONE
11552 +#define dx_current_fstag(sb) \
11553 + ((sb)->s_flags & MS_TAGGED ? dx_current_tag() : 0)
11555 +#define dx_current_fstag(sb) (0)
11558 +#ifndef CONFIG_TAGGING_INTERN
11559 +#define TAGINO_TAG(cond, tag) (0)
11561 +#define TAGINO_TAG(cond, tag) ((cond) ? (tag) : 0)
11564 +#define TAGINO_KUID(cond, kuid, ktag) \
11565 + KUIDT_INIT(TAGINO_UID(cond, __kuid_val(kuid), __ktag_val(ktag)))
11566 +#define TAGINO_KGID(cond, kgid, ktag) \
11567 + KGIDT_INIT(TAGINO_GID(cond, __kgid_val(kgid), __ktag_val(ktag)))
11568 +#define TAGINO_KTAG(cond, ktag) \
11569 + KTAGT_INIT(TAGINO_TAG(cond, __ktag_val(ktag)))
11572 +#define INOTAG_UID(cond, uid, gid) \
11573 + ((cond) ? ((uid) & MAX_UID) : (uid))
11574 +#define INOTAG_GID(cond, uid, gid) \
11575 + ((cond) ? ((gid) & MAX_GID) : (gid))
11577 +#define INOTAG_KUID(cond, kuid, kgid) \
11578 + KUIDT_INIT(INOTAG_UID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11579 +#define INOTAG_KGID(cond, kuid, kgid) \
11580 + KGIDT_INIT(INOTAG_GID(cond, __kuid_val(kuid), __kgid_val(kgid)))
11581 +#define INOTAG_KTAG(cond, kuid, kgid, ktag) \
11582 + KTAGT_INIT(INOTAG_TAG(cond, \
11583 + __kuid_val(kuid), __kgid_val(kgid), __ktag_val(ktag)))
11586 +static inline uid_t dx_map_uid(uid_t uid)
11588 + if ((uid > MAX_UID) && (uid != -1))
11590 + return (uid & MAX_UID);
11593 +static inline gid_t dx_map_gid(gid_t gid)
11595 + if ((gid > MAX_GID) && (gid != -1))
11597 + return (gid & MAX_GID);
11605 +#define dx_notagcheck(sb) ((sb) && ((sb)->s_flags & MS_NOTAGCHECK))
11607 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
11608 + unsigned long *flags);
11610 +#ifdef CONFIG_PROPAGATE
11612 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode);
11614 +#define dx_propagate_tag(n, i) __dx_propagate_tag(n, i)
11617 +#define dx_propagate_tag(n, i) do { } while (0)
11620 +#endif /* _DX_TAG_H */
11621 diff -NurpP --minimal linux-3.13.10/include/linux/vserver/tag_cmd.h linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag_cmd.h
11622 --- linux-3.13.10/include/linux/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
11623 +++ linux-3.13.10-vs2.3.6.11/include/linux/vserver/tag_cmd.h 2014-01-31 20:38:03.000000000 +0000
11625 +#ifndef _VSERVER_TAG_CMD_H
11626 +#define _VSERVER_TAG_CMD_H
11628 +#include <uapi/vserver/tag_cmd.h>
11630 +extern int vc_task_tag(uint32_t);
11632 +extern int vc_tag_migrate(uint32_t);
11634 +#endif /* _VSERVER_TAG_CMD_H */
11635 diff -NurpP --minimal linux-3.13.10/include/net/addrconf.h linux-3.13.10-vs2.3.6.11/include/net/addrconf.h
11636 --- linux-3.13.10/include/net/addrconf.h 2013-11-25 15:47:02.000000000 +0000
11637 +++ linux-3.13.10-vs2.3.6.11/include/net/addrconf.h 2014-01-31 20:39:35.000000000 +0000
11638 @@ -79,7 +79,7 @@ struct inet6_ifaddr *ipv6_get_ifaddr(str
11640 int ipv6_dev_get_saddr(struct net *net, const struct net_device *dev,
11641 const struct in6_addr *daddr, unsigned int srcprefs,
11642 - struct in6_addr *saddr);
11643 + struct in6_addr *saddr, struct nx_info *nxi);
11644 int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
11645 unsigned char banned_flags);
11646 int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
11647 diff -NurpP --minimal linux-3.13.10/include/net/af_unix.h linux-3.13.10-vs2.3.6.11/include/net/af_unix.h
11648 --- linux-3.13.10/include/net/af_unix.h 2013-11-25 15:47:02.000000000 +0000
11649 +++ linux-3.13.10-vs2.3.6.11/include/net/af_unix.h 2014-01-31 20:38:03.000000000 +0000
11651 #include <linux/socket.h>
11652 #include <linux/un.h>
11653 #include <linux/mutex.h>
11654 +#include <linux/vs_base.h>
11655 #include <net/sock.h>
11657 void unix_inflight(struct file *fp);
11658 diff -NurpP --minimal linux-3.13.10/include/net/inet_timewait_sock.h linux-3.13.10-vs2.3.6.11/include/net/inet_timewait_sock.h
11659 --- linux-3.13.10/include/net/inet_timewait_sock.h 2014-01-22 20:39:11.000000000 +0000
11660 +++ linux-3.13.10-vs2.3.6.11/include/net/inet_timewait_sock.h 2014-01-31 20:40:30.000000000 +0000
11661 @@ -121,6 +121,10 @@ struct inet_timewait_sock {
11662 #define tw_v6_rcv_saddr __tw_common.skc_v6_rcv_saddr
11663 #define tw_dport __tw_common.skc_dport
11664 #define tw_num __tw_common.skc_num
11665 +#define tw_xid __tw_common.skc_xid
11666 +#define tw_vx_info __tw_common.skc_vx_info
11667 +#define tw_nid __tw_common.skc_nid
11668 +#define tw_nx_info __tw_common.skc_nx_info
11671 volatile unsigned char tw_substate;
11672 diff -NurpP --minimal linux-3.13.10/include/net/ip6_route.h linux-3.13.10-vs2.3.6.11/include/net/ip6_route.h
11673 --- linux-3.13.10/include/net/ip6_route.h 2014-01-22 20:39:11.000000000 +0000
11674 +++ linux-3.13.10-vs2.3.6.11/include/net/ip6_route.h 2014-01-31 20:41:10.000000000 +0000
11675 @@ -90,7 +90,7 @@ int ip6_del_rt(struct rt6_info *);
11677 int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
11678 const struct in6_addr *daddr, unsigned int prefs,
11679 - struct in6_addr *saddr);
11680 + struct in6_addr *saddr, struct nx_info *nxi);
11682 struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
11683 const struct in6_addr *saddr, int oif, int flags);
11684 diff -NurpP --minimal linux-3.13.10/include/net/route.h linux-3.13.10-vs2.3.6.11/include/net/route.h
11685 --- linux-3.13.10/include/net/route.h 2014-01-22 20:39:12.000000000 +0000
11686 +++ linux-3.13.10-vs2.3.6.11/include/net/route.h 2014-02-01 12:30:58.000000000 +0000
11687 @@ -203,6 +203,9 @@ static inline void ip_rt_put(struct rtab
11688 dst_release(&rt->dst);
11691 +#include <linux/vs_base.h>
11692 +#include <linux/vs_inet.h>
11694 #define IPTOS_RT_MASK (IPTOS_TOS_MASK & ~3)
11696 extern const __u8 ip_tos2prio[16];
11697 @@ -252,6 +255,9 @@ static inline void ip_route_connect_init
11698 protocol, flow_flags, dst, src, dport, sport);
11701 +extern struct rtable *ip_v4_find_src(struct net *net, struct nx_info *,
11702 + struct flowi4 *);
11704 static inline struct rtable *ip_route_connect(struct flowi4 *fl4,
11705 __be32 dst, __be32 src, u32 tos,
11706 int oif, u8 protocol,
11707 @@ -260,11 +266,25 @@ static inline struct rtable *ip_route_co
11709 struct net *net = sock_net(sk);
11711 + struct nx_info *nx_info = current_nx_info();
11713 ip_route_connect_init(fl4, dst, src, tos, oif, protocol,
11716 - if (!dst || !src) {
11718 + nx_info = sk->sk_nx_info;
11720 + vxdprintk(VXD_CBIT(net, 4),
11721 + "ip_route_connect(%p) %p,%p;%lx",
11722 + sk, nx_info, sk->sk_socket,
11723 + (sk->sk_socket?sk->sk_socket->flags:0));
11725 + rt = ip_v4_find_src(net, nx_info, fl4);
11730 + if (!fl4->daddr || !fl4->saddr) {
11731 rt = __ip_route_output_key(net, fl4);
11734 diff -NurpP --minimal linux-3.13.10/include/net/sock.h linux-3.13.10-vs2.3.6.11/include/net/sock.h
11735 --- linux-3.13.10/include/net/sock.h 2014-04-17 01:12:39.000000000 +0000
11736 +++ linux-3.13.10-vs2.3.6.11/include/net/sock.h 2014-04-17 01:17:10.000000000 +0000
11737 @@ -191,6 +191,10 @@ struct sock_common {
11738 #ifdef CONFIG_NET_NS
11739 struct net *skc_net;
11742 + struct vx_info *skc_vx_info;
11744 + struct nx_info *skc_nx_info;
11746 #if IS_ENABLED(CONFIG_IPV6)
11747 struct in6_addr skc_v6_daddr;
11748 @@ -321,7 +325,11 @@ struct sock {
11749 #define sk_prot __sk_common.skc_prot
11750 #define sk_net __sk_common.skc_net
11751 #define sk_v6_daddr __sk_common.skc_v6_daddr
11752 -#define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
11753 +#define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr
11754 +#define sk_xid __sk_common.skc_xid
11755 +#define sk_vx_info __sk_common.skc_vx_info
11756 +#define sk_nid __sk_common.skc_nid
11757 +#define sk_nx_info __sk_common.skc_nx_info
11759 socket_lock_t sk_lock;
11760 struct sk_buff_head sk_receive_queue;
11761 diff -NurpP --minimal linux-3.13.10/include/uapi/Kbuild linux-3.13.10-vs2.3.6.11/include/uapi/Kbuild
11762 --- linux-3.13.10/include/uapi/Kbuild 2012-12-11 03:30:57.000000000 +0000
11763 +++ linux-3.13.10-vs2.3.6.11/include/uapi/Kbuild 2014-01-31 20:38:03.000000000 +0000
11764 @@ -12,3 +12,4 @@ header-y += video/
11768 +header-y += vserver/
11769 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/capability.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/capability.h
11770 --- linux-3.13.10/include/uapi/linux/capability.h 2012-12-11 03:30:57.000000000 +0000
11771 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/capability.h 2014-01-31 20:38:03.000000000 +0000
11772 @@ -259,6 +259,7 @@ struct vfs_cap_data {
11773 arbitrary SCSI commands */
11774 /* Allow setting encryption key on loopback filesystem */
11775 /* Allow setting zone reclaim policy */
11776 +/* Allow the selection of a security context */
11778 #define CAP_SYS_ADMIN 21
11780 @@ -345,7 +346,12 @@ struct vfs_cap_data {
11782 #define CAP_LAST_CAP CAP_BLOCK_SUSPEND
11784 -#define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
11785 +/* Allow context manipulations */
11786 +/* Allow changing context info on files */
11788 +#define CAP_CONTEXT 63
11790 +#define cap_valid(x) ((x) >= 0 && ((x) <= CAP_LAST_CAP || (x) == CAP_CONTEXT))
11793 * Bit location of each capability (used by user-space library and kernel)
11794 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/fs.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/fs.h
11795 --- linux-3.13.10/include/uapi/linux/fs.h 2013-11-25 15:47:02.000000000 +0000
11796 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/fs.h 2014-01-31 20:38:03.000000000 +0000
11797 @@ -86,6 +86,9 @@ struct inodes_stat_t {
11798 #define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */
11799 #define MS_I_VERSION (1<<23) /* Update inode I_version field */
11800 #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
11801 +#define MS_TAGGED (1<<8) /* use generic inode tagging */
11802 +#define MS_NOTAGCHECK (1<<9) /* don't check tags */
11803 +#define MS_TAGID (1<<25) /* use specific tag for this mount */
11805 /* These sb flags are internal to the kernel */
11806 #define MS_NOSEC (1<<28)
11807 @@ -191,11 +194,14 @@ struct inodes_stat_t {
11808 #define FS_EXTENT_FL 0x00080000 /* Extents */
11809 #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */
11810 #define FS_NOCOW_FL 0x00800000 /* Do not cow file */
11811 +#define FS_IXUNLINK_FL 0x08000000 /* Immutable invert on unlink */
11812 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
11814 -#define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
11815 -#define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
11816 +#define FS_BARRIER_FL 0x04000000 /* Barrier for chroot() */
11817 +#define FS_COW_FL 0x20000000 /* Copy on Write marker */
11819 +#define FS_FL_USER_VISIBLE 0x0103DFFF /* User visible flags */
11820 +#define FS_FL_USER_MODIFIABLE 0x010380FF /* User modifiable flags */
11822 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
11823 #define SYNC_FILE_RANGE_WRITE 2
11824 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/gfs2_ondisk.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/gfs2_ondisk.h
11825 --- linux-3.13.10/include/uapi/linux/gfs2_ondisk.h 2012-12-11 03:30:57.000000000 +0000
11826 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/gfs2_ondisk.h 2014-01-31 20:38:03.000000000 +0000
11827 @@ -225,6 +225,9 @@ enum {
11830 gfs2fl_TopLevel = 10,
11831 + gfs2fl_IXUnlink = 16,
11832 + gfs2fl_Barrier = 17,
11834 gfs2fl_TruncInProg = 29,
11835 gfs2fl_InheritDirectio = 30,
11836 gfs2fl_InheritJdata = 31,
11837 @@ -242,6 +245,9 @@ enum {
11838 #define GFS2_DIF_SYNC 0x00000100
11839 #define GFS2_DIF_SYSTEM 0x00000200 /* New in gfs2 */
11840 #define GFS2_DIF_TOPDIR 0x00000400 /* New in gfs2 */
11841 +#define GFS2_DIF_IXUNLINK 0x00010000
11842 +#define GFS2_DIF_BARRIER 0x00020000
11843 +#define GFS2_DIF_COW 0x00040000
11844 #define GFS2_DIF_TRUNC_IN_PROG 0x20000000 /* New in gfs2 */
11845 #define GFS2_DIF_INHERIT_DIRECTIO 0x40000000 /* only in gfs1 */
11846 #define GFS2_DIF_INHERIT_JDATA 0x80000000
11847 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/if_tun.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/if_tun.h
11848 --- linux-3.13.10/include/uapi/linux/if_tun.h 2013-11-25 15:47:02.000000000 +0000
11849 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/if_tun.h 2014-01-31 20:45:49.000000000 +0000
11851 #define TUNSETQUEUE _IOW('T', 217, int)
11852 #define TUNSETIFINDEX _IOW('T', 218, unsigned int)
11853 #define TUNGETFILTER _IOR('T', 219, struct sock_fprog)
11854 +#define TUNSETNID _IOW('T', 220, int)
11856 /* TUNSETIFF ifr flags */
11857 #define IFF_TUN 0x0001
11858 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/major.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/major.h
11859 --- linux-3.13.10/include/uapi/linux/major.h 2014-01-22 20:39:12.000000000 +0000
11860 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/major.h 2014-01-31 20:38:03.000000000 +0000
11862 #define HD_MAJOR IDE0_MAJOR
11863 #define PTY_SLAVE_MAJOR 3
11864 #define TTY_MAJOR 4
11865 +#define VROOT_MAJOR 4
11866 #define TTYAUX_MAJOR 5
11868 #define VCS_MAJOR 7
11869 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/nfs_mount.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/nfs_mount.h
11870 --- linux-3.13.10/include/uapi/linux/nfs_mount.h 2014-01-22 20:39:12.000000000 +0000
11871 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/nfs_mount.h 2014-01-31 20:38:03.000000000 +0000
11872 @@ -63,7 +63,8 @@ struct nfs_mount_data {
11873 #define NFS_MOUNT_SECFLAVOUR 0x2000 /* 5 non-text parsed mount data only */
11874 #define NFS_MOUNT_NORDIRPLUS 0x4000 /* 5 */
11875 #define NFS_MOUNT_UNSHARED 0x8000 /* 5 */
11876 -#define NFS_MOUNT_FLAGMASK 0xFFFF
11877 +#define NFS_MOUNT_TAGGED 0x10000 /* context tagging */
11878 +#define NFS_MOUNT_FLAGMASK 0x1FFFF
11880 /* The following are for internal use only */
11881 #define NFS_MOUNT_LOOKUP_CACHE_NONEG 0x10000
11882 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/reboot.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/reboot.h
11883 --- linux-3.13.10/include/uapi/linux/reboot.h 2012-12-11 03:30:57.000000000 +0000
11884 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/reboot.h 2014-01-31 20:38:03.000000000 +0000
11886 #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4
11887 #define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2
11888 #define LINUX_REBOOT_CMD_KEXEC 0x45584543
11890 +#define LINUX_REBOOT_CMD_OOM 0xDEADBEEF
11893 #endif /* _UAPI_LINUX_REBOOT_H */
11894 diff -NurpP --minimal linux-3.13.10/include/uapi/linux/sysctl.h linux-3.13.10-vs2.3.6.11/include/uapi/linux/sysctl.h
11895 --- linux-3.13.10/include/uapi/linux/sysctl.h 2012-12-11 03:30:57.000000000 +0000
11896 +++ linux-3.13.10-vs2.3.6.11/include/uapi/linux/sysctl.h 2014-01-31 20:38:03.000000000 +0000
11897 @@ -60,6 +60,7 @@ enum
11898 CTL_ABI=9, /* Binary emulation */
11899 CTL_CPU=10, /* CPU stuff (speed scaling, etc) */
11900 CTL_ARLAN=254, /* arlan wireless driver */
11901 + CTL_VSERVER=4242, /* Linux-VServer debug */
11902 CTL_S390DBF=5677, /* s390 debug */
11903 CTL_SUNRPC=7249, /* sunrpc debug */
11904 CTL_PM=9899, /* frv power management */
11905 @@ -94,6 +95,7 @@ enum
11907 KERN_PANIC=15, /* int: panic timeout */
11908 KERN_REALROOTDEV=16, /* real root device to mount after initrd */
11909 + KERN_VSHELPER=17, /* string: path to vshelper policy agent */
11911 KERN_SPARC_REBOOT=21, /* reboot command on Sparc */
11912 KERN_CTLALTDEL=22, /* int: allow ctl-alt-del to reboot */
11913 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/Kbuild linux-3.13.10-vs2.3.6.11/include/uapi/vserver/Kbuild
11914 --- linux-3.13.10/include/uapi/vserver/Kbuild 1970-01-01 00:00:00.000000000 +0000
11915 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/Kbuild 2014-01-31 20:38:03.000000000 +0000
11918 +header-y += context_cmd.h network_cmd.h space_cmd.h \
11919 + cacct_cmd.h cvirt_cmd.h limit_cmd.h dlimit_cmd.h \
11920 + inode_cmd.h tag_cmd.h sched_cmd.h signal_cmd.h \
11921 + debug_cmd.h device_cmd.h
11923 +header-y += switch.h context.h network.h monitor.h \
11924 + limit.h inode.h device.h
11926 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/cacct_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cacct_cmd.h
11927 --- linux-3.13.10/include/uapi/vserver/cacct_cmd.h 1970-01-01 00:00:00.000000000 +0000
11928 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cacct_cmd.h 2014-01-31 20:38:03.000000000 +0000
11930 +#ifndef _UAPI_VS_CACCT_CMD_H
11931 +#define _UAPI_VS_CACCT_CMD_H
11934 +/* virtual host info name commands */
11936 +#define VCMD_sock_stat VC_CMD(VSTAT, 5, 0)
11938 +struct vcmd_sock_stat_v0 {
11940 + uint32_t count[3];
11941 + uint64_t total[3];
11944 +#endif /* _UAPI_VS_CACCT_CMD_H */
11945 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/context.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context.h
11946 --- linux-3.13.10/include/uapi/vserver/context.h 1970-01-01 00:00:00.000000000 +0000
11947 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context.h 2014-01-31 20:38:03.000000000 +0000
11949 +#ifndef _UAPI_VS_CONTEXT_H
11950 +#define _UAPI_VS_CONTEXT_H
11952 +#include <linux/types.h>
11953 +#include <linux/capability.h>
11956 +/* context flags */
11958 +#define VXF_INFO_SCHED 0x00000002
11959 +#define VXF_INFO_NPROC 0x00000004
11960 +#define VXF_INFO_PRIVATE 0x00000008
11962 +#define VXF_INFO_INIT 0x00000010
11963 +#define VXF_INFO_HIDE 0x00000020
11964 +#define VXF_INFO_ULIMIT 0x00000040
11965 +#define VXF_INFO_NSPACE 0x00000080
11967 +#define VXF_SCHED_HARD 0x00000100
11968 +#define VXF_SCHED_PRIO 0x00000200
11969 +#define VXF_SCHED_PAUSE 0x00000400
11971 +#define VXF_VIRT_MEM 0x00010000
11972 +#define VXF_VIRT_UPTIME 0x00020000
11973 +#define VXF_VIRT_CPU 0x00040000
11974 +#define VXF_VIRT_LOAD 0x00080000
11975 +#define VXF_VIRT_TIME 0x00100000
11977 +#define VXF_HIDE_MOUNT 0x01000000
11978 +/* was VXF_HIDE_NETIF 0x02000000 */
11979 +#define VXF_HIDE_VINFO 0x04000000
11981 +#define VXF_STATE_SETUP (1ULL << 32)
11982 +#define VXF_STATE_INIT (1ULL << 33)
11983 +#define VXF_STATE_ADMIN (1ULL << 34)
11985 +#define VXF_SC_HELPER (1ULL << 36)
11986 +#define VXF_REBOOT_KILL (1ULL << 37)
11987 +#define VXF_PERSISTENT (1ULL << 38)
11989 +#define VXF_FORK_RSS (1ULL << 48)
11990 +#define VXF_PROLIFIC (1ULL << 49)
11992 +#define VXF_IGNEG_NICE (1ULL << 52)
11994 +#define VXF_ONE_TIME (0x0007ULL << 32)
11996 +#define VXF_INIT_SET (VXF_STATE_SETUP | VXF_STATE_INIT | VXF_STATE_ADMIN)
11999 +/* context migration */
12001 +#define VXM_SET_INIT 0x00000001
12002 +#define VXM_SET_REAPER 0x00000002
12004 +/* context caps */
12006 +#define VXC_SET_UTSNAME 0x00000001
12007 +#define VXC_SET_RLIMIT 0x00000002
12008 +#define VXC_FS_SECURITY 0x00000004
12009 +#define VXC_FS_TRUSTED 0x00000008
12010 +#define VXC_TIOCSTI 0x00000010
12012 +/* was VXC_RAW_ICMP 0x00000100 */
12013 +#define VXC_SYSLOG 0x00001000
12014 +#define VXC_OOM_ADJUST 0x00002000
12015 +#define VXC_AUDIT_CONTROL 0x00004000
12017 +#define VXC_SECURE_MOUNT 0x00010000
12018 +/* #define VXC_SECURE_REMOUNT 0x00020000 */
12019 +#define VXC_BINARY_MOUNT 0x00040000
12020 +#define VXC_DEV_MOUNT 0x00080000
12022 +#define VXC_QUOTA_CTL 0x00100000
12023 +#define VXC_ADMIN_MAPPER 0x00200000
12024 +#define VXC_ADMIN_CLOOP 0x00400000
12026 +#define VXC_KTHREAD 0x01000000
12027 +#define VXC_NAMESPACE 0x02000000
12029 +#endif /* _UAPI_VS_CONTEXT_H */
12030 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/context_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context_cmd.h
12031 --- linux-3.13.10/include/uapi/vserver/context_cmd.h 1970-01-01 00:00:00.000000000 +0000
12032 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/context_cmd.h 2014-01-31 20:38:03.000000000 +0000
12034 +#ifndef _UAPI_VS_CONTEXT_CMD_H
12035 +#define _UAPI_VS_CONTEXT_CMD_H
12038 +/* vinfo commands */
12040 +#define VCMD_task_xid VC_CMD(VINFO, 1, 0)
12043 +#define VCMD_vx_info VC_CMD(VINFO, 5, 0)
12045 +struct vcmd_vx_info_v0 {
12047 + uint32_t initpid;
12048 + /* more to come */
12052 +#define VCMD_ctx_stat VC_CMD(VSTAT, 0, 0)
12054 +struct vcmd_ctx_stat_v0 {
12057 + /* more to come */
12061 +/* context commands */
12063 +#define VCMD_ctx_create_v0 VC_CMD(VPROC, 1, 0)
12064 +#define VCMD_ctx_create VC_CMD(VPROC, 1, 1)
12066 +struct vcmd_ctx_create {
12067 + uint64_t flagword;
12070 +#define VCMD_ctx_migrate_v0 VC_CMD(PROCMIG, 1, 0)
12071 +#define VCMD_ctx_migrate VC_CMD(PROCMIG, 1, 1)
12073 +struct vcmd_ctx_migrate {
12074 + uint64_t flagword;
12079 +/* flag commands */
12081 +#define VCMD_get_cflags VC_CMD(FLAGS, 1, 0)
12082 +#define VCMD_set_cflags VC_CMD(FLAGS, 2, 0)
12084 +struct vcmd_ctx_flags_v0 {
12085 + uint64_t flagword;
12091 +/* context caps commands */
12093 +#define VCMD_get_ccaps VC_CMD(FLAGS, 3, 1)
12094 +#define VCMD_set_ccaps VC_CMD(FLAGS, 4, 1)
12096 +struct vcmd_ctx_caps_v1 {
12103 +/* bcaps commands */
12105 +#define VCMD_get_bcaps VC_CMD(FLAGS, 9, 0)
12106 +#define VCMD_set_bcaps VC_CMD(FLAGS, 10, 0)
12108 +struct vcmd_bcaps {
12115 +/* umask commands */
12117 +#define VCMD_get_umask VC_CMD(FLAGS, 13, 0)
12118 +#define VCMD_set_umask VC_CMD(FLAGS, 14, 0)
12120 +struct vcmd_umask {
12127 +/* wmask commands */
12129 +#define VCMD_get_wmask VC_CMD(FLAGS, 15, 0)
12130 +#define VCMD_set_wmask VC_CMD(FLAGS, 16, 0)
12132 +struct vcmd_wmask {
12141 +#define VCMD_get_badness VC_CMD(MEMCTRL, 5, 0)
12142 +#define VCMD_set_badness VC_CMD(MEMCTRL, 6, 0)
12144 +struct vcmd_badness_v0 {
12148 +#endif /* _UAPI_VS_CONTEXT_CMD_H */
12149 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/cvirt_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cvirt_cmd.h
12150 --- linux-3.13.10/include/uapi/vserver/cvirt_cmd.h 1970-01-01 00:00:00.000000000 +0000
12151 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/cvirt_cmd.h 2014-01-31 20:38:03.000000000 +0000
12153 +#ifndef _UAPI_VS_CVIRT_CMD_H
12154 +#define _UAPI_VS_CVIRT_CMD_H
12157 +/* virtual host info name commands */
12159 +#define VCMD_set_vhi_name VC_CMD(VHOST, 1, 0)
12160 +#define VCMD_get_vhi_name VC_CMD(VHOST, 2, 0)
12162 +struct vcmd_vhi_name_v0 {
12168 +enum vhi_name_field {
12169 + VHIN_CONTEXT = 0,
12180 +#define VCMD_virt_stat VC_CMD(VSTAT, 3, 0)
12182 +struct vcmd_virt_stat_v0 {
12185 + uint32_t nr_threads;
12186 + uint32_t nr_running;
12187 + uint32_t nr_uninterruptible;
12188 + uint32_t nr_onhold;
12189 + uint32_t nr_forks;
12190 + uint32_t load[3];
12193 +#endif /* _UAPI_VS_CVIRT_CMD_H */
12194 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/debug_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/debug_cmd.h
12195 --- linux-3.13.10/include/uapi/vserver/debug_cmd.h 1970-01-01 00:00:00.000000000 +0000
12196 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/debug_cmd.h 2014-01-31 20:38:03.000000000 +0000
12198 +#ifndef _UAPI_VS_DEBUG_CMD_H
12199 +#define _UAPI_VS_DEBUG_CMD_H
12202 +/* debug commands */
12204 +#define VCMD_dump_history VC_CMD(DEBUG, 1, 0)
12206 +#define VCMD_read_history VC_CMD(DEBUG, 5, 0)
12207 +#define VCMD_read_monitor VC_CMD(DEBUG, 6, 0)
12209 +struct vcmd_read_history_v0 {
12212 + char __user *data;
12215 +struct vcmd_read_monitor_v0 {
12218 + char __user *data;
12221 +#endif /* _UAPI_VS_DEBUG_CMD_H */
12222 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/device.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device.h
12223 --- linux-3.13.10/include/uapi/vserver/device.h 1970-01-01 00:00:00.000000000 +0000
12224 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device.h 2014-01-31 20:38:03.000000000 +0000
12226 +#ifndef _UAPI_VS_DEVICE_H
12227 +#define _UAPI_VS_DEVICE_H
12230 +#define DATTR_CREATE 0x00000001
12231 +#define DATTR_OPEN 0x00000002
12233 +#define DATTR_REMAP 0x00000010
12235 +#define DATTR_MASK 0x00000013
12237 +#endif /* _UAPI_VS_DEVICE_H */
12238 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/device_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device_cmd.h
12239 --- linux-3.13.10/include/uapi/vserver/device_cmd.h 1970-01-01 00:00:00.000000000 +0000
12240 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/device_cmd.h 2014-01-31 20:38:03.000000000 +0000
12242 +#ifndef _UAPI_VS_DEVICE_CMD_H
12243 +#define _UAPI_VS_DEVICE_CMD_H
12246 +/* device vserver commands */
12248 +#define VCMD_set_mapping VC_CMD(DEVICE, 1, 0)
12249 +#define VCMD_unset_mapping VC_CMD(DEVICE, 2, 0)
12251 +struct vcmd_set_mapping_v0 {
12252 + const char __user *device;
12253 + const char __user *target;
12257 +#endif /* _UAPI_VS_DEVICE_CMD_H */
12258 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/dlimit_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/dlimit_cmd.h
12259 --- linux-3.13.10/include/uapi/vserver/dlimit_cmd.h 1970-01-01 00:00:00.000000000 +0000
12260 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/dlimit_cmd.h 2014-01-31 20:38:03.000000000 +0000
12262 +#ifndef _UAPI_VS_DLIMIT_CMD_H
12263 +#define _UAPI_VS_DLIMIT_CMD_H
12266 +/* dlimit vserver commands */
12268 +#define VCMD_add_dlimit VC_CMD(DLIMIT, 1, 0)
12269 +#define VCMD_rem_dlimit VC_CMD(DLIMIT, 2, 0)
12271 +#define VCMD_set_dlimit VC_CMD(DLIMIT, 5, 0)
12272 +#define VCMD_get_dlimit VC_CMD(DLIMIT, 6, 0)
12274 +struct vcmd_ctx_dlimit_base_v0 {
12275 + const char __user *name;
12279 +struct vcmd_ctx_dlimit_v0 {
12280 + const char __user *name;
12281 + uint32_t space_used; /* used space in kbytes */
12282 + uint32_t space_total; /* maximum space in kbytes */
12283 + uint32_t inodes_used; /* used inodes */
12284 + uint32_t inodes_total; /* maximum inodes */
12285 + uint32_t reserved; /* reserved for root in % */
12289 +#define CDLIM_UNSET ((uint32_t)0UL)
12290 +#define CDLIM_INFINITY ((uint32_t)~0UL)
12291 +#define CDLIM_KEEP ((uint32_t)~1UL)
12293 +#define DLIME_UNIT 0
12294 +#define DLIME_KILO 1
12295 +#define DLIME_MEGA 2
12296 +#define DLIME_GIGA 3
12298 +#define DLIMF_SHIFT 0x10
12300 +#define DLIMS_USED 0
12301 +#define DLIMS_TOTAL 2
12304 +uint64_t dlimit_space_32to64(uint32_t val, uint32_t flags, int shift)
12306 + int exp = (flags & DLIMF_SHIFT) ?
12307 + (flags >> shift) & DLIME_GIGA : DLIME_KILO;
12308 + return ((uint64_t)val) << (10 * exp);
12312 +uint32_t dlimit_space_64to32(uint64_t val, uint32_t *flags, int shift)
12316 + if (*flags & DLIMF_SHIFT) {
12317 + while (val > (1LL << 32) && (exp < 3)) {
12321 + *flags &= ~(DLIME_GIGA << shift);
12322 + *flags |= exp << shift;
12328 +#endif /* _UAPI_VS_DLIMIT_CMD_H */
12329 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/inode.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode.h
12330 --- linux-3.13.10/include/uapi/vserver/inode.h 1970-01-01 00:00:00.000000000 +0000
12331 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode.h 2014-01-31 20:38:03.000000000 +0000
12333 +#ifndef _UAPI_VS_INODE_H
12334 +#define _UAPI_VS_INODE_H
12337 +#define IATTR_TAG 0x01000000
12339 +#define IATTR_ADMIN 0x00000001
12340 +#define IATTR_WATCH 0x00000002
12341 +#define IATTR_HIDE 0x00000004
12342 +#define IATTR_FLAGS 0x00000007
12344 +#define IATTR_BARRIER 0x00010000
12345 +#define IATTR_IXUNLINK 0x00020000
12346 +#define IATTR_IMMUTABLE 0x00040000
12347 +#define IATTR_COW 0x00080000
12350 +/* inode ioctls */
12352 +#define FIOC_GETXFLG _IOR('x', 5, long)
12353 +#define FIOC_SETXFLG _IOW('x', 6, long)
12355 +#endif /* _UAPI_VS_INODE_H */
12356 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/inode_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode_cmd.h
12357 --- linux-3.13.10/include/uapi/vserver/inode_cmd.h 1970-01-01 00:00:00.000000000 +0000
12358 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/inode_cmd.h 2014-01-31 20:38:03.000000000 +0000
12360 +#ifndef _UAPI_VS_INODE_CMD_H
12361 +#define _UAPI_VS_INODE_CMD_H
12364 +/* inode vserver commands */
12366 +#define VCMD_get_iattr VC_CMD(INODE, 1, 1)
12367 +#define VCMD_set_iattr VC_CMD(INODE, 2, 1)
12369 +#define VCMD_fget_iattr VC_CMD(INODE, 3, 0)
12370 +#define VCMD_fset_iattr VC_CMD(INODE, 4, 0)
12372 +struct vcmd_ctx_iattr_v1 {
12373 + const char __user *name;
12379 +struct vcmd_ctx_fiattr_v0 {
12385 +#endif /* _UAPI_VS_INODE_CMD_H */
12386 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/limit.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit.h
12387 --- linux-3.13.10/include/uapi/vserver/limit.h 1970-01-01 00:00:00.000000000 +0000
12388 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit.h 2014-01-31 20:38:03.000000000 +0000
12390 +#ifndef _UAPI_VS_LIMIT_H
12391 +#define _UAPI_VS_LIMIT_H
12394 +#define VLIMIT_NSOCK 16
12395 +#define VLIMIT_OPENFD 17
12396 +#define VLIMIT_ANON 18
12397 +#define VLIMIT_SHMEM 19
12398 +#define VLIMIT_SEMARY 20
12399 +#define VLIMIT_NSEMS 21
12400 +#define VLIMIT_DENTRY 22
12401 +#define VLIMIT_MAPPED 23
12403 +#endif /* _UAPI_VS_LIMIT_H */
12404 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/limit_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit_cmd.h
12405 --- linux-3.13.10/include/uapi/vserver/limit_cmd.h 1970-01-01 00:00:00.000000000 +0000
12406 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/limit_cmd.h 2014-01-31 20:38:03.000000000 +0000
12408 +#ifndef _UAPI_VS_LIMIT_CMD_H
12409 +#define _UAPI_VS_LIMIT_CMD_H
12412 +/* rlimit vserver commands */
12414 +#define VCMD_get_rlimit VC_CMD(RLIMIT, 1, 0)
12415 +#define VCMD_set_rlimit VC_CMD(RLIMIT, 2, 0)
12416 +#define VCMD_get_rlimit_mask VC_CMD(RLIMIT, 3, 0)
12417 +#define VCMD_reset_hits VC_CMD(RLIMIT, 7, 0)
12418 +#define VCMD_reset_minmax VC_CMD(RLIMIT, 9, 0)
12420 +struct vcmd_ctx_rlimit_v0 {
12422 + uint64_t minimum;
12423 + uint64_t softlimit;
12424 + uint64_t maximum;
12427 +struct vcmd_ctx_rlimit_mask_v0 {
12428 + uint32_t minimum;
12429 + uint32_t softlimit;
12430 + uint32_t maximum;
12433 +#define VCMD_rlimit_stat VC_CMD(VSTAT, 1, 0)
12435 +struct vcmd_rlimit_stat_v0 {
12439 + uint64_t minimum;
12440 + uint64_t maximum;
12443 +#define CRLIM_UNSET (0ULL)
12444 +#define CRLIM_INFINITY (~0ULL)
12445 +#define CRLIM_KEEP (~1ULL)
12447 +#endif /* _UAPI_VS_LIMIT_CMD_H */
12448 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/monitor.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/monitor.h
12449 --- linux-3.13.10/include/uapi/vserver/monitor.h 1970-01-01 00:00:00.000000000 +0000
12450 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/monitor.h 2014-01-31 20:38:03.000000000 +0000
12452 +#ifndef _UAPI_VS_MONITOR_H
12453 +#define _UAPI_VS_MONITOR_H
12455 +#include <linux/types.h>
12463 + VXM_UPDATE = 0x20,
12467 + VXM_RQINFO_1 = 0x24,
12470 + VXM_ACTIVATE = 0x40,
12477 + VXM_MIGRATE = 0x48,
12480 + /* all other bits are flags */
12481 + VXM_SCHED = 0x80,
12484 +struct _vxm_update_1 {
12485 + uint32_t tokens_max;
12486 + uint32_t fill_rate;
12487 + uint32_t interval;
12490 +struct _vxm_update_2 {
12491 + uint32_t tokens_min;
12492 + uint32_t fill_rate;
12493 + uint32_t interval;
12496 +struct _vxm_rqinfo_1 {
12497 + uint16_t running;
12501 + uint32_t idle_tokens;
12504 +struct _vxm_rqinfo_2 {
12505 + uint32_t norm_time;
12506 + uint32_t idle_time;
12507 + uint32_t idle_skip;
12510 +struct _vxm_sched {
12512 + uint32_t norm_time;
12513 + uint32_t idle_time;
12516 +struct _vxm_task {
12521 +struct _vxm_event {
12530 + struct _vxm_task tsk;
12534 +struct _vx_mon_entry {
12538 + struct _vxm_event ev;
12539 + struct _vxm_sched sd;
12540 + struct _vxm_update_1 u1;
12541 + struct _vxm_update_2 u2;
12542 + struct _vxm_rqinfo_1 q1;
12543 + struct _vxm_rqinfo_2 q2;
12547 +#endif /* _UAPI_VS_MONITOR_H */
12548 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/network.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network.h
12549 --- linux-3.13.10/include/uapi/vserver/network.h 1970-01-01 00:00:00.000000000 +0000
12550 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network.h 2014-01-31 20:38:03.000000000 +0000
12552 +#ifndef _UAPI_VS_NETWORK_H
12553 +#define _UAPI_VS_NETWORK_H
12555 +#include <linux/types.h>
12558 +#define MAX_N_CONTEXT 65535 /* Arbitrary limit */
12561 +/* network flags */
12563 +#define NXF_INFO_PRIVATE 0x00000008
12565 +#define NXF_SINGLE_IP 0x00000100
12566 +#define NXF_LBACK_REMAP 0x00000200
12567 +#define NXF_LBACK_ALLOW 0x00000400
12569 +#define NXF_HIDE_NETIF 0x02000000
12570 +#define NXF_HIDE_LBACK 0x04000000
12572 +#define NXF_STATE_SETUP (1ULL << 32)
12573 +#define NXF_STATE_ADMIN (1ULL << 34)
12575 +#define NXF_SC_HELPER (1ULL << 36)
12576 +#define NXF_PERSISTENT (1ULL << 38)
12578 +#define NXF_ONE_TIME (0x0005ULL << 32)
12581 +#define NXF_INIT_SET (__nxf_init_set())
12583 +static inline uint64_t __nxf_init_set(void) {
12584 + return NXF_STATE_ADMIN
12585 +#ifdef CONFIG_VSERVER_AUTO_LBACK
12586 + | NXF_LBACK_REMAP
12589 +#ifdef CONFIG_VSERVER_AUTO_SINGLE
12592 + | NXF_HIDE_NETIF;
12596 +/* network caps */
12598 +#define NXC_TUN_CREATE 0x00000001
12600 +#define NXC_RAW_ICMP 0x00000100
12602 +#define NXC_MULTICAST 0x00001000
12605 +/* address types */
12607 +#define NXA_TYPE_IPV4 0x0001
12608 +#define NXA_TYPE_IPV6 0x0002
12610 +#define NXA_TYPE_NONE 0x0000
12611 +#define NXA_TYPE_ANY 0x00FF
12613 +#define NXA_TYPE_ADDR 0x0010
12614 +#define NXA_TYPE_MASK 0x0020
12615 +#define NXA_TYPE_RANGE 0x0040
12617 +#define NXA_MASK_ALL (NXA_TYPE_ADDR | NXA_TYPE_MASK | NXA_TYPE_RANGE)
12619 +#define NXA_MOD_BCAST 0x0100
12620 +#define NXA_MOD_LBACK 0x0200
12622 +#define NXA_LOOPBACK 0x1000
12624 +#define NXA_MASK_BIND (NXA_MASK_ALL | NXA_MOD_BCAST | NXA_MOD_LBACK)
12625 +#define NXA_MASK_SHOW (NXA_MASK_ALL | NXA_LOOPBACK)
12627 +#endif /* _UAPI_VS_NETWORK_H */
12628 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/network_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network_cmd.h
12629 --- linux-3.13.10/include/uapi/vserver/network_cmd.h 1970-01-01 00:00:00.000000000 +0000
12630 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/network_cmd.h 2014-01-31 20:38:03.000000000 +0000
12632 +#ifndef _UAPI_VS_NETWORK_CMD_H
12633 +#define _UAPI_VS_NETWORK_CMD_H
12636 +/* vinfo commands */
12638 +#define VCMD_task_nid VC_CMD(VINFO, 2, 0)
12641 +#define VCMD_nx_info VC_CMD(VINFO, 6, 0)
12643 +struct vcmd_nx_info_v0 {
12645 + /* more to come */
12649 +#include <linux/in.h>
12650 +#include <linux/in6.h>
12652 +#define VCMD_net_create_v0 VC_CMD(VNET, 1, 0)
12653 +#define VCMD_net_create VC_CMD(VNET, 1, 1)
12655 +struct vcmd_net_create {
12656 + uint64_t flagword;
12659 +#define VCMD_net_migrate VC_CMD(NETMIG, 1, 0)
12661 +#define VCMD_net_add VC_CMD(NETALT, 1, 0)
12662 +#define VCMD_net_remove VC_CMD(NETALT, 2, 0)
12664 +struct vcmd_net_addr_v0 {
12667 + struct in_addr ip[4];
12668 + struct in_addr mask[4];
12671 +#define VCMD_net_add_ipv4_v1 VC_CMD(NETALT, 1, 1)
12672 +#define VCMD_net_rem_ipv4_v1 VC_CMD(NETALT, 2, 1)
12674 +struct vcmd_net_addr_ipv4_v1 {
12677 + struct in_addr ip;
12678 + struct in_addr mask;
12681 +#define VCMD_net_add_ipv4 VC_CMD(NETALT, 1, 2)
12682 +#define VCMD_net_rem_ipv4 VC_CMD(NETALT, 2, 2)
12684 +struct vcmd_net_addr_ipv4_v2 {
12687 + struct in_addr ip;
12688 + struct in_addr ip2;
12689 + struct in_addr mask;
12692 +#define VCMD_net_add_ipv6 VC_CMD(NETALT, 3, 1)
12693 +#define VCMD_net_remove_ipv6 VC_CMD(NETALT, 4, 1)
12695 +struct vcmd_net_addr_ipv6_v1 {
12699 + struct in6_addr ip;
12700 + struct in6_addr mask;
12703 +#define VCMD_add_match_ipv4 VC_CMD(NETALT, 5, 0)
12704 +#define VCMD_get_match_ipv4 VC_CMD(NETALT, 6, 0)
12706 +struct vcmd_match_ipv4_v0 {
12711 + struct in_addr ip;
12712 + struct in_addr ip2;
12713 + struct in_addr mask;
12716 +#define VCMD_add_match_ipv6 VC_CMD(NETALT, 7, 0)
12717 +#define VCMD_get_match_ipv6 VC_CMD(NETALT, 8, 0)
12719 +struct vcmd_match_ipv6_v0 {
12724 + struct in6_addr ip;
12725 + struct in6_addr ip2;
12726 + struct in6_addr mask;
12732 +/* flag commands */
12734 +#define VCMD_get_nflags VC_CMD(FLAGS, 5, 0)
12735 +#define VCMD_set_nflags VC_CMD(FLAGS, 6, 0)
12737 +struct vcmd_net_flags_v0 {
12738 + uint64_t flagword;
12744 +/* network caps commands */
12746 +#define VCMD_get_ncaps VC_CMD(FLAGS, 7, 0)
12747 +#define VCMD_set_ncaps VC_CMD(FLAGS, 8, 0)
12749 +struct vcmd_net_caps_v0 {
12754 +#endif /* _UAPI_VS_NETWORK_CMD_H */
12755 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/sched_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/sched_cmd.h
12756 --- linux-3.13.10/include/uapi/vserver/sched_cmd.h 1970-01-01 00:00:00.000000000 +0000
12757 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/sched_cmd.h 2014-01-31 20:38:03.000000000 +0000
12759 +#ifndef _UAPI_VS_SCHED_CMD_H
12760 +#define _UAPI_VS_SCHED_CMD_H
12763 +struct vcmd_prio_bias {
12765 + int32_t prio_bias;
12768 +#define VCMD_set_prio_bias VC_CMD(SCHED, 4, 0)
12769 +#define VCMD_get_prio_bias VC_CMD(SCHED, 5, 0)
12771 +#endif /* _UAPI_VS_SCHED_CMD_H */
12772 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/signal_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/signal_cmd.h
12773 --- linux-3.13.10/include/uapi/vserver/signal_cmd.h 1970-01-01 00:00:00.000000000 +0000
12774 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/signal_cmd.h 2014-01-31 20:38:03.000000000 +0000
12776 +#ifndef _UAPI_VS_SIGNAL_CMD_H
12777 +#define _UAPI_VS_SIGNAL_CMD_H
12780 +/* signalling vserver commands */
12782 +#define VCMD_ctx_kill VC_CMD(PROCTRL, 1, 0)
12783 +#define VCMD_wait_exit VC_CMD(EVENT, 99, 0)
12785 +struct vcmd_ctx_kill_v0 {
12790 +struct vcmd_wait_exit_v0 {
12791 + int32_t reboot_cmd;
12792 + int32_t exit_code;
12796 +/* process alteration commands */
12798 +#define VCMD_get_pflags VC_CMD(PROCALT, 5, 0)
12799 +#define VCMD_set_pflags VC_CMD(PROCALT, 6, 0)
12801 +struct vcmd_pflags_v0 {
12802 + uint32_t flagword;
12806 +#endif /* _UAPI_VS_SIGNAL_CMD_H */
12807 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/space_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/space_cmd.h
12808 --- linux-3.13.10/include/uapi/vserver/space_cmd.h 1970-01-01 00:00:00.000000000 +0000
12809 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/space_cmd.h 2014-01-31 20:38:03.000000000 +0000
12811 +#ifndef _UAPI_VS_SPACE_CMD_H
12812 +#define _UAPI_VS_SPACE_CMD_H
12815 +#define VCMD_enter_space_v0 VC_CMD(PROCALT, 1, 0)
12816 +#define VCMD_enter_space_v1 VC_CMD(PROCALT, 1, 1)
12817 +#define VCMD_enter_space VC_CMD(PROCALT, 1, 2)
12819 +#define VCMD_set_space_v0 VC_CMD(PROCALT, 3, 0)
12820 +#define VCMD_set_space_v1 VC_CMD(PROCALT, 3, 1)
12821 +#define VCMD_set_space VC_CMD(PROCALT, 3, 2)
12823 +#define VCMD_get_space_mask_v0 VC_CMD(PROCALT, 4, 0)
12825 +#define VCMD_get_space_mask VC_CMD(VSPACE, 0, 1)
12826 +#define VCMD_get_space_default VC_CMD(VSPACE, 1, 0)
12829 +struct vcmd_space_mask_v1 {
12833 +struct vcmd_space_mask_v2 {
12838 +#endif /* _UAPI_VS_SPACE_CMD_H */
12839 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/switch.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/switch.h
12840 --- linux-3.13.10/include/uapi/vserver/switch.h 1970-01-01 00:00:00.000000000 +0000
12841 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/switch.h 2014-01-31 20:38:03.000000000 +0000
12843 +#ifndef _UAPI_VS_SWITCH_H
12844 +#define _UAPI_VS_SWITCH_H
12846 +#include <linux/types.h>
12849 +#define VC_CATEGORY(c) (((c) >> 24) & 0x3F)
12850 +#define VC_COMMAND(c) (((c) >> 16) & 0xFF)
12851 +#define VC_VERSION(c) ((c) & 0xFFF)
12853 +#define VC_CMD(c, i, v) ((((VC_CAT_ ## c) & 0x3F) << 24) \
12854 + | (((i) & 0xFF) << 16) | ((v) & 0xFFF))
12858 + Syscall Matrix V2.8
12860 + |VERSION|CREATE |MODIFY |MIGRATE|CONTROL|EXPERIM| |SPECIAL|SPECIAL|
12861 + |STATS |DESTROY|ALTER |CHANGE |LIMIT |TEST | | | |
12862 + |INFO |SETUP | |MOVE | | | | | |
12863 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12864 + SYSTEM |VERSION|VSETUP |VHOST | | | | |DEVICE | |
12865 + HOST | 00| 01| 02| 03| 04| 05| | 06| 07|
12866 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12867 + CPU | |VPROC |PROCALT|PROCMIG|PROCTRL| | |SCHED. | |
12868 + PROCESS| 08| 09| 10| 11| 12| 13| | 14| 15|
12869 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12870 + MEMORY | | | | |MEMCTRL| | |SWAP | |
12871 + | 16| 17| 18| 19| 20| 21| | 22| 23|
12872 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12873 + NETWORK| |VNET |NETALT |NETMIG |NETCTL | | |SERIAL | |
12874 + | 24| 25| 26| 27| 28| 29| | 30| 31|
12875 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12876 + DISK | | | |TAGMIG |DLIMIT | | |INODE | |
12877 + VFS | 32| 33| 34| 35| 36| 37| | 38| 39|
12878 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12879 + OTHER |VSTAT | | | | | | |VINFO | |
12880 + | 40| 41| 42| 43| 44| 45| | 46| 47|
12881 + =======+=======+=======+=======+=======+=======+=======+ +=======+=======+
12882 + SPECIAL|EVENT | | | |FLAGS | | |VSPACE | |
12883 + | 48| 49| 50| 51| 52| 53| | 54| 55|
12884 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12885 + SPECIAL|DEBUG | | | |RLIMIT |SYSCALL| | |COMPAT |
12886 + | 56| 57| 58| 59| 60|TEST 61| | 62| 63|
12887 + -------+-------+-------+-------+-------+-------+-------+ +-------+-------+
12891 +#define VC_CAT_VERSION 0
12893 +#define VC_CAT_VSETUP 1
12894 +#define VC_CAT_VHOST 2
12896 +#define VC_CAT_DEVICE 6
12898 +#define VC_CAT_VPROC 9
12899 +#define VC_CAT_PROCALT 10
12900 +#define VC_CAT_PROCMIG 11
12901 +#define VC_CAT_PROCTRL 12
12903 +#define VC_CAT_SCHED 14
12904 +#define VC_CAT_MEMCTRL 20
12906 +#define VC_CAT_VNET 25
12907 +#define VC_CAT_NETALT 26
12908 +#define VC_CAT_NETMIG 27
12909 +#define VC_CAT_NETCTRL 28
12911 +#define VC_CAT_TAGMIG 35
12912 +#define VC_CAT_DLIMIT 36
12913 +#define VC_CAT_INODE 38
12915 +#define VC_CAT_VSTAT 40
12916 +#define VC_CAT_VINFO 46
12917 +#define VC_CAT_EVENT 48
12919 +#define VC_CAT_FLAGS 52
12920 +#define VC_CAT_VSPACE 54
12921 +#define VC_CAT_DEBUG 56
12922 +#define VC_CAT_RLIMIT 60
12924 +#define VC_CAT_SYSTEST 61
12925 +#define VC_CAT_COMPAT 63
12927 +/* query version */
12929 +#define VCMD_get_version VC_CMD(VERSION, 0, 0)
12930 +#define VCMD_get_vci VC_CMD(VERSION, 1, 0)
12932 +#endif /* _UAPI_VS_SWITCH_H */
12933 diff -NurpP --minimal linux-3.13.10/include/uapi/vserver/tag_cmd.h linux-3.13.10-vs2.3.6.11/include/uapi/vserver/tag_cmd.h
12934 --- linux-3.13.10/include/uapi/vserver/tag_cmd.h 1970-01-01 00:00:00.000000000 +0000
12935 +++ linux-3.13.10-vs2.3.6.11/include/uapi/vserver/tag_cmd.h 2014-01-31 20:38:03.000000000 +0000
12937 +#ifndef _UAPI_VS_TAG_CMD_H
12938 +#define _UAPI_VS_TAG_CMD_H
12941 +/* vinfo commands */
12943 +#define VCMD_task_tag VC_CMD(VINFO, 3, 0)
12946 +/* context commands */
12948 +#define VCMD_tag_migrate VC_CMD(TAGMIG, 1, 0)
12950 +#endif /* _UAPI_VS_TAG_CMD_H */
12951 diff -NurpP --minimal linux-3.13.10/init/Kconfig linux-3.13.10-vs2.3.6.11/init/Kconfig
12952 --- linux-3.13.10/init/Kconfig 2014-04-17 01:12:39.000000000 +0000
12953 +++ linux-3.13.10-vs2.3.6.11/init/Kconfig 2014-04-17 01:17:11.000000000 +0000
12954 @@ -855,6 +855,7 @@ config NUMA_BALANCING
12957 boolean "Control Group support"
12960 This option adds support for grouping sets of processes together, for
12961 use with process control subsystems such as Cpusets, CFS, memory
12962 @@ -1117,6 +1118,7 @@ config IPC_NS
12965 bool "User namespace"
12966 + depends on VSERVER_DISABLED
12969 This allows containers, i.e. vservers, to use user namespaces
12970 diff -NurpP --minimal linux-3.13.10/init/main.c linux-3.13.10-vs2.3.6.11/init/main.c
12971 --- linux-3.13.10/init/main.c 2014-01-22 20:39:12.000000000 +0000
12972 +++ linux-3.13.10-vs2.3.6.11/init/main.c 2014-01-31 20:38:03.000000000 +0000
12974 #include <linux/sched_clock.h>
12975 #include <linux/context_tracking.h>
12976 #include <linux/random.h>
12977 +#include <linux/vserver/percpu.h>
12979 #include <asm/io.h>
12980 #include <asm/bugs.h>
12981 diff -NurpP --minimal linux-3.13.10/ipc/mqueue.c linux-3.13.10-vs2.3.6.11/ipc/mqueue.c
12982 --- linux-3.13.10/ipc/mqueue.c 2014-04-17 01:12:39.000000000 +0000
12983 +++ linux-3.13.10-vs2.3.6.11/ipc/mqueue.c 2014-03-12 15:51:08.000000000 +0000
12985 #include <linux/ipc_namespace.h>
12986 #include <linux/user_namespace.h>
12987 #include <linux/slab.h>
12988 +#include <linux/vs_context.h>
12989 +#include <linux/vs_limit.h>
12991 #include <net/sock.h>
12993 @@ -76,6 +78,7 @@ struct mqueue_inode_info {
12994 struct pid* notify_owner;
12995 struct user_namespace *notify_user_ns;
12996 struct user_struct *user; /* user who created, for accounting */
12997 + struct vx_info *vxi;
12998 struct sock *notify_sock;
12999 struct sk_buff *notify_cookie;
13001 @@ -234,6 +237,7 @@ static struct inode *mqueue_get_inode(st
13002 if (S_ISREG(mode)) {
13003 struct mqueue_inode_info *info;
13004 unsigned long mq_bytes, mq_treesize;
13005 + struct vx_info *vxi = current_vx_info();
13007 inode->i_fop = &mqueue_file_operations;
13008 inode->i_size = FILENT_SIZE;
13009 @@ -247,6 +251,7 @@ static struct inode *mqueue_get_inode(st
13010 info->notify_user_ns = NULL;
13012 info->user = NULL; /* set when all is ok */
13013 + info->vxi = NULL;
13014 info->msg_tree = RB_ROOT;
13015 info->node_cache = NULL;
13016 memset(&info->attr, 0, sizeof(info->attr));
13017 @@ -280,17 +285,20 @@ static struct inode *mqueue_get_inode(st
13019 spin_lock(&mq_lock);
13020 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
13021 - u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
13022 + u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE) ||
13023 + !vx_ipcmsg_avail(vxi, mq_bytes)) {
13024 spin_unlock(&mq_lock);
13025 /* mqueue_evict_inode() releases info->messages */
13029 u->mq_bytes += mq_bytes;
13030 + vx_ipcmsg_add(vxi, u, mq_bytes);
13031 spin_unlock(&mq_lock);
13034 info->user = get_uid(u);
13035 + info->vxi = get_vx_info(vxi);
13036 } else if (S_ISDIR(mode)) {
13038 /* Some things misbehave if size == 0 on a directory */
13039 @@ -402,8 +410,11 @@ static void mqueue_evict_inode(struct in
13043 + struct vx_info *vxi = info->vxi;
13045 spin_lock(&mq_lock);
13046 user->mq_bytes -= mq_bytes;
13047 + vx_ipcmsg_sub(vxi, user, mq_bytes);
13049 * get_ns_from_inode() ensures that the
13050 * (ipc_ns = sb->s_fs_info) is either a valid ipc_ns
13051 @@ -413,6 +424,7 @@ static void mqueue_evict_inode(struct in
13053 ipc_ns->mq_queues_count--;
13054 spin_unlock(&mq_lock);
13055 + put_vx_info(vxi);
13059 diff -NurpP --minimal linux-3.13.10/ipc/msg.c linux-3.13.10-vs2.3.6.11/ipc/msg.c
13060 --- linux-3.13.10/ipc/msg.c 2014-04-17 01:12:39.000000000 +0000
13061 +++ linux-3.13.10-vs2.3.6.11/ipc/msg.c 2014-04-17 01:17:11.000000000 +0000
13063 #include <linux/rwsem.h>
13064 #include <linux/nsproxy.h>
13065 #include <linux/ipc_namespace.h>
13066 +#include <linux/vs_base.h>
13068 #include <asm/current.h>
13069 #include <asm/uaccess.h>
13070 @@ -194,6 +195,7 @@ static int newque(struct ipc_namespace *
13072 msq->q_perm.mode = msgflg & S_IRWXUGO;
13073 msq->q_perm.key = key;
13074 + msq->q_perm.xid = vx_current_xid();
13076 msq->q_perm.security = NULL;
13077 retval = security_msg_queue_alloc(msq);
13078 diff -NurpP --minimal linux-3.13.10/ipc/sem.c linux-3.13.10-vs2.3.6.11/ipc/sem.c
13079 --- linux-3.13.10/ipc/sem.c 2013-11-25 15:47:03.000000000 +0000
13080 +++ linux-3.13.10-vs2.3.6.11/ipc/sem.c 2014-01-31 20:38:03.000000000 +0000
13082 #include <linux/rwsem.h>
13083 #include <linux/nsproxy.h>
13084 #include <linux/ipc_namespace.h>
13085 +#include <linux/vs_base.h>
13086 +#include <linux/vs_limit.h>
13088 #include <asm/uaccess.h>
13090 @@ -500,6 +502,7 @@ static int newary(struct ipc_namespace *
13092 sma->sem_perm.mode = (semflg & S_IRWXUGO);
13093 sma->sem_perm.key = key;
13094 + sma->sem_perm.xid = vx_current_xid();
13096 sma->sem_perm.security = NULL;
13097 retval = security_sem_alloc(sma);
13098 @@ -514,6 +517,9 @@ static int newary(struct ipc_namespace *
13101 ns->used_sems += nsems;
13102 + /* FIXME: obsoleted? */
13103 + vx_semary_inc(sma);
13104 + vx_nsems_add(sma, nsems);
13106 sma->sem_base = (struct sem *) &sma[1];
13108 @@ -1103,6 +1109,9 @@ static void freeary(struct ipc_namespace
13110 wake_up_sem_queue_do(&tasks);
13111 ns->used_sems -= sma->sem_nsems;
13112 + /* FIXME: obsoleted? */
13113 + vx_nsems_sub(sma, sma->sem_nsems);
13114 + vx_semary_dec(sma);
13115 ipc_rcu_putref(sma, sem_rcu_free);
13118 diff -NurpP --minimal linux-3.13.10/ipc/shm.c linux-3.13.10-vs2.3.6.11/ipc/shm.c
13119 --- linux-3.13.10/ipc/shm.c 2014-01-22 20:39:12.000000000 +0000
13120 +++ linux-3.13.10-vs2.3.6.11/ipc/shm.c 2014-01-31 20:38:03.000000000 +0000
13122 #include <linux/nsproxy.h>
13123 #include <linux/mount.h>
13124 #include <linux/ipc_namespace.h>
13125 +#include <linux/vs_context.h>
13126 +#include <linux/vs_limit.h>
13128 #include <asm/uaccess.h>
13130 @@ -209,10 +211,14 @@ static void shm_open(struct vm_area_stru
13131 static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp)
13133 struct file *shm_file;
13134 + struct vx_info *vxi = lookup_vx_info(shp->shm_perm.xid);
13135 + int numpages = (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13137 shm_file = shp->shm_file;
13138 shp->shm_file = NULL;
13139 - ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT;
13140 + vx_ipcshm_sub(vxi, shp, numpages);
13141 + ns->shm_tot -= numpages;
13145 if (!is_file_hugepages(shm_file))
13146 @@ -220,6 +226,7 @@ static void shm_destroy(struct ipc_names
13147 else if (shp->mlock_user)
13148 user_shm_unlock(file_inode(shm_file)->i_size, shp->mlock_user);
13150 + put_vx_info(vxi);
13151 ipc_rcu_putref(shp, shm_rcu_free);
13154 @@ -497,11 +504,15 @@ static int newseg(struct ipc_namespace *
13155 if (ns->shm_tot + numpages > ns->shm_ctlall)
13158 + if (!vx_ipcshm_avail(current_vx_info(), numpages))
13161 shp = ipc_rcu_alloc(sizeof(*shp));
13165 shp->shm_perm.key = key;
13166 + shp->shm_perm.xid = vx_current_xid();
13167 shp->shm_perm.mode = (shmflg & S_IRWXUGO);
13168 shp->mlock_user = NULL;
13170 @@ -570,6 +581,7 @@ static int newseg(struct ipc_namespace *
13172 ipc_unlock_object(&shp->shm_perm);
13174 + vx_ipcshm_add(current_vx_info(), key, numpages);
13178 diff -NurpP --minimal linux-3.13.10/kernel/Makefile linux-3.13.10-vs2.3.6.11/kernel/Makefile
13179 --- linux-3.13.10/kernel/Makefile 2014-01-22 20:39:12.000000000 +0000
13180 +++ linux-3.13.10-vs2.3.6.11/kernel/Makefile 2014-01-31 21:36:22.000000000 +0000
13181 @@ -25,6 +25,7 @@ obj-y += printk/
13187 obj-$(CONFIG_CHECKPOINT_RESTORE) += kcmp.o
13188 obj-$(CONFIG_FREEZER) += freezer.o
13189 diff -NurpP --minimal linux-3.13.10/kernel/auditsc.c linux-3.13.10-vs2.3.6.11/kernel/auditsc.c
13190 --- linux-3.13.10/kernel/auditsc.c 2014-04-17 01:12:39.000000000 +0000
13191 +++ linux-3.13.10-vs2.3.6.11/kernel/auditsc.c 2014-04-17 01:17:11.000000000 +0000
13192 @@ -1956,7 +1956,7 @@ static int audit_set_loginuid_perm(kuid_
13193 if (is_audit_feature_set(AUDIT_FEATURE_LOGINUID_IMMUTABLE))
13195 /* it is set, you need permission */
13196 - if (!capable(CAP_AUDIT_CONTROL))
13197 + if (!vx_capable(CAP_AUDIT_CONTROL, VXC_AUDIT_CONTROL))
13199 /* reject if this is not an unset and we don't allow that */
13200 if (is_audit_feature_set(AUDIT_FEATURE_ONLY_UNSET_LOGINUID) && uid_valid(loginuid))
13201 diff -NurpP --minimal linux-3.13.10/kernel/capability.c linux-3.13.10-vs2.3.6.11/kernel/capability.c
13202 --- linux-3.13.10/kernel/capability.c 2013-11-25 15:47:03.000000000 +0000
13203 +++ linux-3.13.10-vs2.3.6.11/kernel/capability.c 2014-01-31 20:38:03.000000000 +0000
13205 #include <linux/syscalls.h>
13206 #include <linux/pid_namespace.h>
13207 #include <linux/user_namespace.h>
13208 +#include <linux/vs_context.h>
13209 #include <asm/uaccess.h>
13212 @@ -116,6 +117,7 @@ static int cap_validate_magic(cap_user_h
13218 * The only thing that can change the capabilities of the current
13219 * process is the current process. As such, we can't be in this code
13220 @@ -349,6 +351,8 @@ bool has_ns_capability_noaudit(struct ta
13224 +#include <linux/vserver/base.h>
13227 * has_capability_noaudit - Does a task have a capability (unaudited) in the
13229 diff -NurpP --minimal linux-3.13.10/kernel/compat.c linux-3.13.10-vs2.3.6.11/kernel/compat.c
13230 --- linux-3.13.10/kernel/compat.c 2013-07-14 17:01:34.000000000 +0000
13231 +++ linux-3.13.10-vs2.3.6.11/kernel/compat.c 2014-01-31 20:38:03.000000000 +0000
13233 #include <linux/times.h>
13234 #include <linux/ptrace.h>
13235 #include <linux/gfp.h>
13236 +#include <linux/vs_time.h>
13238 #include <asm/uaccess.h>
13240 @@ -1040,7 +1041,7 @@ asmlinkage long compat_sys_stime(compat_
13244 - do_settimeofday(&tv);
13245 + vx_settimeofday(&tv);
13249 diff -NurpP --minimal linux-3.13.10/kernel/cred.c linux-3.13.10-vs2.3.6.11/kernel/cred.c
13250 --- linux-3.13.10/kernel/cred.c 2013-02-19 13:58:56.000000000 +0000
13251 +++ linux-3.13.10-vs2.3.6.11/kernel/cred.c 2014-01-31 20:38:03.000000000 +0000
13252 @@ -56,31 +56,6 @@ struct cred init_cred = {
13253 .group_info = &init_groups,
13256 -static inline void set_cred_subscribers(struct cred *cred, int n)
13258 -#ifdef CONFIG_DEBUG_CREDENTIALS
13259 - atomic_set(&cred->subscribers, n);
13263 -static inline int read_cred_subscribers(const struct cred *cred)
13265 -#ifdef CONFIG_DEBUG_CREDENTIALS
13266 - return atomic_read(&cred->subscribers);
13272 -static inline void alter_cred_subscribers(const struct cred *_cred, int n)
13274 -#ifdef CONFIG_DEBUG_CREDENTIALS
13275 - struct cred *cred = (struct cred *) _cred;
13277 - atomic_add(n, &cred->subscribers);
13282 * The RCU callback to actually dispose of a set of credentials
13284 @@ -232,21 +207,16 @@ error:
13286 * Call commit_creds() or abort_creds() to clean up.
13288 -struct cred *prepare_creds(void)
13289 +struct cred *__prepare_creds(const struct cred *old)
13291 - struct task_struct *task = current;
13292 - const struct cred *old;
13295 - validate_process_creds();
13297 new = kmem_cache_alloc(cred_jar, GFP_KERNEL);
13301 kdebug("prepare_creds() alloc %p", new);
13303 - old = task->cred;
13304 memcpy(new, old, sizeof(struct cred));
13306 atomic_set(&new->usage, 1);
13307 @@ -275,6 +245,13 @@ error:
13312 +struct cred *prepare_creds(void)
13314 + validate_process_creds();
13316 + return __prepare_creds(current->cred);
13318 EXPORT_SYMBOL(prepare_creds);
13321 diff -NurpP --minimal linux-3.13.10/kernel/exit.c linux-3.13.10-vs2.3.6.11/kernel/exit.c
13322 --- linux-3.13.10/kernel/exit.c 2013-11-25 15:45:07.000000000 +0000
13323 +++ linux-3.13.10-vs2.3.6.11/kernel/exit.c 2014-01-31 20:38:03.000000000 +0000
13325 #include <linux/fs_struct.h>
13326 #include <linux/init_task.h>
13327 #include <linux/perf_event.h>
13328 +#include <linux/vs_limit.h>
13329 +#include <linux/vs_context.h>
13330 +#include <linux/vs_network.h>
13331 +#include <linux/vs_pid.h>
13332 #include <trace/events/sched.h>
13333 #include <linux/hw_breakpoint.h>
13334 #include <linux/oom.h>
13335 @@ -503,15 +507,25 @@ static struct task_struct *find_new_reap
13336 __acquires(&tasklist_lock)
13338 struct pid_namespace *pid_ns = task_active_pid_ns(father);
13339 - struct task_struct *thread;
13340 + struct vx_info *vxi = task_get_vx_info(father);
13341 + struct task_struct *thread = father;
13342 + struct task_struct *reaper;
13345 while_each_thread(father, thread) {
13346 if (thread->flags & PF_EXITING)
13348 if (unlikely(pid_ns->child_reaper == father))
13349 pid_ns->child_reaper = thread;
13355 + reaper = pid_ns->child_reaper;
13357 + BUG_ON(!vxi->vx_reaper);
13358 + if (vxi->vx_reaper != init_pid_ns.child_reaper &&
13359 + vxi->vx_reaper != father)
13360 + reaper = vxi->vx_reaper;
13363 if (unlikely(pid_ns->child_reaper == father)) {
13364 @@ -549,7 +563,9 @@ static struct task_struct *find_new_reap
13368 - return pid_ns->child_reaper;
13370 + put_vx_info(vxi);
13375 @@ -600,10 +616,15 @@ static void forget_original_parent(struc
13376 list_for_each_entry_safe(p, n, &father->children, sibling) {
13377 struct task_struct *t = p;
13379 - t->real_parent = reaper;
13380 + struct task_struct *new_parent = reaper;
13382 + if (unlikely(p == reaper))
13383 + new_parent = task_active_pid_ns(p)->child_reaper;
13385 + t->real_parent = new_parent;
13386 if (t->parent == father) {
13388 - t->parent = t->real_parent;
13389 + t->parent = new_parent;
13391 if (t->pdeath_signal)
13392 group_send_sig_info(t->pdeath_signal,
13393 @@ -810,6 +831,9 @@ void do_exit(long code)
13395 flush_ptrace_hw_breakpoint(tsk);
13397 + /* needs to stay before exit_notify() */
13398 + exit_vx_info_early(tsk, code);
13400 exit_notify(tsk, group_dead);
13403 @@ -863,10 +887,15 @@ void do_exit(long code)
13405 raw_spin_unlock_wait(&tsk->pi_lock);
13407 + /* needs to stay after exit_notify() */
13408 + exit_vx_info(tsk, code);
13409 + exit_nx_info(tsk);
13411 /* causes final put_task_struct in finish_task_switch(). */
13412 tsk->state = TASK_DEAD;
13413 tsk->flags |= PF_NOFREEZE; /* tell freezer to ignore us */
13415 + printk("bad task: %p [%lx]\n", current, current->state);
13417 /* Avoid "noreturn function does return". */
13419 diff -NurpP --minimal linux-3.13.10/kernel/fork.c linux-3.13.10-vs2.3.6.11/kernel/fork.c
13420 --- linux-3.13.10/kernel/fork.c 2014-01-22 20:39:13.000000000 +0000
13421 +++ linux-3.13.10-vs2.3.6.11/kernel/fork.c 2014-01-31 20:38:03.000000000 +0000
13423 #include <linux/signalfd.h>
13424 #include <linux/uprobes.h>
13425 #include <linux/aio.h>
13426 +#include <linux/vs_context.h>
13427 +#include <linux/vs_network.h>
13428 +#include <linux/vs_limit.h>
13430 #include <asm/pgtable.h>
13431 #include <asm/pgalloc.h>
13432 @@ -211,6 +214,8 @@ void free_task(struct task_struct *tsk)
13433 arch_release_thread_info(tsk->stack);
13434 free_thread_info(tsk->stack);
13435 rt_mutex_debug_task_free(tsk);
13436 + clr_vx_info(&tsk->vx_info);
13437 + clr_nx_info(&tsk->nx_info);
13438 ftrace_graph_exit_task(tsk);
13439 put_seccomp_filter(tsk);
13440 arch_release_task_struct(tsk);
13441 @@ -542,6 +547,7 @@ static struct mm_struct *mm_init(struct
13442 if (likely(!mm_alloc_pgd(mm))) {
13444 mmu_notifier_mm_init(mm);
13445 + set_vx_info(&mm->mm_vx_info, p->vx_info);
13449 @@ -594,6 +600,7 @@ void __mmdrop(struct mm_struct *mm)
13450 destroy_context(mm);
13451 mmu_notifier_mm_destroy(mm);
13453 + clr_vx_info(&mm->mm_vx_info);
13456 EXPORT_SYMBOL_GPL(__mmdrop);
13457 @@ -813,6 +820,7 @@ struct mm_struct *dup_mm(struct task_str
13460 memcpy(mm, oldmm, sizeof(*mm));
13461 + mm->mm_vx_info = NULL;
13462 mm_init_cpumask(mm);
13464 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS
13465 @@ -851,6 +859,7 @@ fail_nocontext:
13466 * If init_new_context() failed, we cannot use mmput() to free the mm
13467 * because it calls destroy_context()
13469 + clr_vx_info(&mm->mm_vx_info);
13473 @@ -1135,6 +1144,8 @@ static struct task_struct *copy_process(
13476 struct task_struct *p;
13477 + struct vx_info *vxi;
13478 + struct nx_info *nxi;
13480 if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
13481 return ERR_PTR(-EINVAL);
13482 @@ -1197,7 +1208,12 @@ static struct task_struct *copy_process(
13483 DEBUG_LOCKS_WARN_ON(!p->hardirqs_enabled);
13484 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
13486 + init_vx_info(&p->vx_info, current_vx_info());
13487 + init_nx_info(&p->nx_info, current_nx_info());
13490 + if (!vx_nproc_avail(1))
13491 + goto bad_fork_free;
13492 if (atomic_read(&p->real_cred->user->processes) >=
13493 task_rlimit(p, RLIMIT_NPROC)) {
13494 if (p->real_cred->user != INIT_USER &&
13495 @@ -1479,6 +1495,18 @@ static struct task_struct *copy_process(
13498 spin_unlock(¤t->sighand->siglock);
13500 + /* p is copy of current */
13501 + vxi = p->vx_info;
13503 + claim_vx_info(vxi, p);
13504 + atomic_inc(&vxi->cvirt.nr_threads);
13505 + atomic_inc(&vxi->cvirt.total_forks);
13508 + nxi = p->nx_info;
13510 + claim_nx_info(nxi, p);
13511 write_unlock_irq(&tasklist_lock);
13512 proc_fork_connector(p);
13513 cgroup_post_fork(p);
13514 diff -NurpP --minimal linux-3.13.10/kernel/kthread.c linux-3.13.10-vs2.3.6.11/kernel/kthread.c
13515 --- linux-3.13.10/kernel/kthread.c 2014-01-22 20:39:13.000000000 +0000
13516 +++ linux-3.13.10-vs2.3.6.11/kernel/kthread.c 2014-01-31 20:38:03.000000000 +0000
13518 #include <linux/freezer.h>
13519 #include <linux/ptrace.h>
13520 #include <linux/uaccess.h>
13521 +#include <linux/vs_pid.h>
13522 #include <trace/events/sched.h>
13524 static DEFINE_SPINLOCK(kthread_create_lock);
13525 diff -NurpP --minimal linux-3.13.10/kernel/nsproxy.c linux-3.13.10-vs2.3.6.11/kernel/nsproxy.c
13526 --- linux-3.13.10/kernel/nsproxy.c 2013-11-25 15:47:03.000000000 +0000
13527 +++ linux-3.13.10-vs2.3.6.11/kernel/nsproxy.c 2014-02-01 00:17:43.000000000 +0000
13528 @@ -20,11 +20,14 @@
13529 #include <linux/mnt_namespace.h>
13530 #include <linux/utsname.h>
13531 #include <linux/pid_namespace.h>
13532 +#include <linux/vserver/global.h>
13533 +#include <linux/vserver/debug.h>
13534 #include <net/net_namespace.h>
13535 #include <linux/ipc_namespace.h>
13536 #include <linux/proc_ns.h>
13537 #include <linux/file.h>
13538 #include <linux/syscalls.h>
13539 +#include "../fs/mount.h"
13541 static struct kmem_cache *nsproxy_cachep;
13543 @@ -46,8 +49,11 @@ static inline struct nsproxy *create_nsp
13544 struct nsproxy *nsproxy;
13546 nsproxy = kmem_cache_alloc(nsproxy_cachep, GFP_KERNEL);
13549 atomic_set(&nsproxy->count, 1);
13550 + atomic_inc(&vs_global_nsproxy);
13552 + vxdprintk(VXD_CBIT(space, 2), "create_nsproxy = %p[1]", nsproxy);
13556 @@ -56,9 +62,12 @@ static inline struct nsproxy *create_nsp
13557 * Return the newly created nsproxy. Do not attach this to the task,
13558 * leave it to the caller to do proper locking and attach it to task.
13560 -static struct nsproxy *create_new_namespaces(unsigned long flags,
13561 - struct task_struct *tsk, struct user_namespace *user_ns,
13562 - struct fs_struct *new_fs)
13563 +static struct nsproxy *unshare_namespaces(
13564 + unsigned long flags,
13565 + struct nsproxy *orig,
13566 + struct fs_struct *new_fs,
13567 + struct user_namespace *new_user,
13568 + struct pid_namespace *new_pid)
13570 struct nsproxy *new_nsp;
13572 @@ -67,32 +76,31 @@ static struct nsproxy *create_new_namesp
13574 return ERR_PTR(-ENOMEM);
13576 - new_nsp->mnt_ns = copy_mnt_ns(flags, tsk->nsproxy->mnt_ns, user_ns, new_fs);
13577 + new_nsp->mnt_ns = copy_mnt_ns(flags, orig->mnt_ns, new_user, new_fs);
13578 if (IS_ERR(new_nsp->mnt_ns)) {
13579 err = PTR_ERR(new_nsp->mnt_ns);
13583 - new_nsp->uts_ns = copy_utsname(flags, user_ns, tsk->nsproxy->uts_ns);
13584 + new_nsp->uts_ns = copy_utsname(flags, new_user, orig->uts_ns);
13585 if (IS_ERR(new_nsp->uts_ns)) {
13586 err = PTR_ERR(new_nsp->uts_ns);
13590 - new_nsp->ipc_ns = copy_ipcs(flags, user_ns, tsk->nsproxy->ipc_ns);
13591 + new_nsp->ipc_ns = copy_ipcs(flags, new_user, orig->ipc_ns);
13592 if (IS_ERR(new_nsp->ipc_ns)) {
13593 err = PTR_ERR(new_nsp->ipc_ns);
13597 - new_nsp->pid_ns_for_children =
13598 - copy_pid_ns(flags, user_ns, tsk->nsproxy->pid_ns_for_children);
13599 + new_nsp->pid_ns_for_children = copy_pid_ns(flags, new_user, new_pid);
13600 if (IS_ERR(new_nsp->pid_ns_for_children)) {
13601 err = PTR_ERR(new_nsp->pid_ns_for_children);
13605 - new_nsp->net_ns = copy_net_ns(flags, user_ns, tsk->nsproxy->net_ns);
13606 + new_nsp->net_ns = copy_net_ns(flags, new_user, orig->net_ns);
13607 if (IS_ERR(new_nsp->net_ns)) {
13608 err = PTR_ERR(new_nsp->net_ns);
13610 @@ -117,6 +125,41 @@ out_ns:
13611 return ERR_PTR(err);
13614 +static struct nsproxy *create_new_namespaces(unsigned long flags,
13615 + struct task_struct *tsk, struct user_namespace *user_ns,
13616 + struct fs_struct *new_fs)
13619 + return unshare_namespaces(flags, tsk->nsproxy,
13620 + new_fs, user_ns, task_active_pid_ns(tsk));
13624 + * copies the nsproxy, setting refcount to 1, and grabbing a
13625 + * reference to all contained namespaces.
13627 +struct nsproxy *copy_nsproxy(struct nsproxy *orig)
13629 + struct nsproxy *ns = create_nsproxy();
13632 + memcpy(ns, orig, sizeof(struct nsproxy));
13633 + atomic_set(&ns->count, 1);
13636 + get_mnt_ns(ns->mnt_ns);
13638 + get_uts_ns(ns->uts_ns);
13640 + get_ipc_ns(ns->ipc_ns);
13641 + if (ns->pid_ns_for_children)
13642 + get_pid_ns(ns->pid_ns_for_children);
13644 + get_net(ns->net_ns);
13650 * called from clone. This now handles copy for nsproxy and all
13651 * namespaces therein.
13652 @@ -125,7 +168,10 @@ int copy_namespaces(unsigned long flags,
13654 struct nsproxy *old_ns = tsk->nsproxy;
13655 struct user_namespace *user_ns = task_cred_xxx(tsk, user_ns);
13656 - struct nsproxy *new_ns;
13657 + struct nsproxy *new_ns = NULL;
13659 + vxdprintk(VXD_CBIT(space, 7), "copy_namespaces(0x%08lx,%p[%p])",
13660 + flags, tsk, old_ns);
13662 if (likely(!(flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13663 CLONE_NEWPID | CLONE_NEWNET)))) {
13664 @@ -133,7 +179,7 @@ int copy_namespaces(unsigned long flags,
13668 - if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13669 + if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, flags))
13673 @@ -152,6 +198,9 @@ int copy_namespaces(unsigned long flags,
13674 return PTR_ERR(new_ns);
13676 tsk->nsproxy = new_ns;
13677 + vxdprintk(VXD_CBIT(space, 3),
13678 + "copy_namespaces(0x%08lx,%p[%p]) = [%p]",
13679 + flags, tsk, old_ns, new_ns);
13683 @@ -165,7 +214,9 @@ void free_nsproxy(struct nsproxy *ns)
13684 put_ipc_ns(ns->ipc_ns);
13685 if (ns->pid_ns_for_children)
13686 put_pid_ns(ns->pid_ns_for_children);
13687 - put_net(ns->net_ns);
13689 + put_net(ns->net_ns);
13690 + atomic_dec(&vs_global_nsproxy);
13691 kmem_cache_free(nsproxy_cachep, ns);
13694 @@ -179,12 +230,16 @@ int unshare_nsproxy_namespaces(unsigned
13695 struct user_namespace *user_ns;
13698 + vxdprintk(VXD_CBIT(space, 4),
13699 + "unshare_nsproxy_namespaces(0x%08lx,[%p])",
13700 + unshare_flags, current->nsproxy);
13702 if (!(unshare_flags & (CLONE_NEWNS | CLONE_NEWUTS | CLONE_NEWIPC |
13703 CLONE_NEWNET | CLONE_NEWPID)))
13706 user_ns = new_cred ? new_cred->user_ns : current_user_ns();
13707 - if (!ns_capable(user_ns, CAP_SYS_ADMIN))
13708 + if (!vx_ns_can_unshare(user_ns, CAP_SYS_ADMIN, unshare_flags))
13711 *new_nsp = create_new_namespaces(unshare_flags, current, user_ns,
13712 diff -NurpP --minimal linux-3.13.10/kernel/pid.c linux-3.13.10-vs2.3.6.11/kernel/pid.c
13713 --- linux-3.13.10/kernel/pid.c 2013-11-25 15:47:03.000000000 +0000
13714 +++ linux-3.13.10-vs2.3.6.11/kernel/pid.c 2014-01-31 20:38:03.000000000 +0000
13716 #include <linux/syscalls.h>
13717 #include <linux/proc_ns.h>
13718 #include <linux/proc_fs.h>
13719 +#include <linux/vs_pid.h>
13721 #define pid_hashfn(nr, ns) \
13722 hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
13723 @@ -373,7 +374,7 @@ EXPORT_SYMBOL_GPL(find_pid_ns);
13725 struct pid *find_vpid(int nr)
13727 - return find_pid_ns(nr, task_active_pid_ns(current));
13728 + return find_pid_ns(vx_rmap_pid(nr), task_active_pid_ns(current));
13730 EXPORT_SYMBOL_GPL(find_vpid);
13732 @@ -429,6 +430,9 @@ void transfer_pid(struct task_struct *ol
13733 struct task_struct *pid_task(struct pid *pid, enum pid_type type)
13735 struct task_struct *result = NULL;
13737 + if (type == PIDTYPE_REALPID)
13738 + type = PIDTYPE_PID;
13740 struct hlist_node *first;
13741 first = rcu_dereference_check(hlist_first_rcu(&pid->tasks[type]),
13742 @@ -448,7 +452,7 @@ struct task_struct *find_task_by_pid_ns(
13743 rcu_lockdep_assert(rcu_read_lock_held(),
13744 "find_task_by_pid_ns() needs rcu_read_lock()"
13746 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
13747 + return pid_task(find_pid_ns(vx_rmap_pid(nr), ns), PIDTYPE_PID);
13750 struct task_struct *find_task_by_vpid(pid_t vnr)
13751 @@ -492,7 +496,7 @@ struct pid *find_get_pid(pid_t nr)
13753 EXPORT_SYMBOL_GPL(find_get_pid);
13755 -pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13756 +pid_t pid_unmapped_nr_ns(struct pid *pid, struct pid_namespace *ns)
13760 @@ -506,6 +510,11 @@ pid_t pid_nr_ns(struct pid *pid, struct
13762 EXPORT_SYMBOL_GPL(pid_nr_ns);
13764 +pid_t pid_nr_ns(struct pid *pid, struct pid_namespace *ns)
13766 + return vx_map_pid(pid_unmapped_nr_ns(pid, ns));
13769 pid_t pid_vnr(struct pid *pid)
13771 return pid_nr_ns(pid, task_active_pid_ns(current));
13772 diff -NurpP --minimal linux-3.13.10/kernel/pid_namespace.c linux-3.13.10-vs2.3.6.11/kernel/pid_namespace.c
13773 --- linux-3.13.10/kernel/pid_namespace.c 2014-01-22 20:39:13.000000000 +0000
13774 +++ linux-3.13.10-vs2.3.6.11/kernel/pid_namespace.c 2014-02-01 12:23:11.000000000 +0000
13776 #include <linux/proc_ns.h>
13777 #include <linux/reboot.h>
13778 #include <linux/export.h>
13779 +#include <linux/vserver/global.h>
13783 @@ -110,6 +111,7 @@ static struct pid_namespace *create_pid_
13786 kref_init(&ns->kref);
13787 + atomic_inc(&vs_global_pid_ns);
13789 ns->parent = get_pid_ns(parent_pid_ns);
13790 ns->user_ns = get_user_ns(user_ns);
13791 @@ -127,6 +129,7 @@ static struct pid_namespace *create_pid_
13793 kfree(ns->pidmap[0].page);
13795 + atomic_dec(&vs_global_pid_ns);
13796 kmem_cache_free(pid_ns_cachep, ns);
13798 return ERR_PTR(err);
13799 diff -NurpP --minimal linux-3.13.10/kernel/posix-timers.c linux-3.13.10-vs2.3.6.11/kernel/posix-timers.c
13800 --- linux-3.13.10/kernel/posix-timers.c 2013-07-14 17:01:35.000000000 +0000
13801 +++ linux-3.13.10-vs2.3.6.11/kernel/posix-timers.c 2014-01-31 20:38:03.000000000 +0000
13803 #include <linux/workqueue.h>
13804 #include <linux/export.h>
13805 #include <linux/hashtable.h>
13806 +#include <linux/vs_context.h>
13809 * Management arrays for POSIX timers. Timers are now kept in static hash table
13810 @@ -398,6 +399,7 @@ int posix_timer_event(struct k_itimer *t
13812 struct task_struct *task;
13813 int shared, ret = -1;
13816 * FIXME: if ->sigq is queued we can race with
13817 * dequeue_signal()->do_schedule_next_timer().
13818 @@ -414,10 +416,18 @@ int posix_timer_event(struct k_itimer *t
13820 task = pid_task(timr->it_pid, PIDTYPE_PID);
13822 + struct vx_info_save vxis;
13823 + struct vx_info *vxi;
13825 + vxi = get_vx_info(task->vx_info);
13826 + enter_vx_info(vxi, &vxis);
13827 shared = !(timr->it_sigev_notify & SIGEV_THREAD_ID);
13828 ret = send_sigqueue(timr->sigq, task, shared);
13829 + leave_vx_info(&vxis);
13830 + put_vx_info(vxi);
13834 /* If we failed to send the signal the timer stops. */
13837 diff -NurpP --minimal linux-3.13.10/kernel/printk/printk.c linux-3.13.10-vs2.3.6.11/kernel/printk/printk.c
13838 --- linux-3.13.10/kernel/printk/printk.c 2014-04-17 01:12:39.000000000 +0000
13839 +++ linux-3.13.10-vs2.3.6.11/kernel/printk/printk.c 2014-04-17 01:17:11.000000000 +0000
13841 #include <linux/poll.h>
13842 #include <linux/irq_work.h>
13843 #include <linux/utsname.h>
13844 +#include <linux/vs_cvirt.h>
13846 #include <asm/uaccess.h>
13848 @@ -386,7 +387,7 @@ static int check_syslog_permissions(int
13851 if (syslog_action_restricted(type)) {
13852 - if (capable(CAP_SYSLOG))
13853 + if (vx_capable(CAP_SYSLOG, VXC_SYSLOG))
13856 * For historical reasons, accept CAP_SYS_ADMIN too, with
13857 @@ -1134,12 +1135,9 @@ int do_syslog(int type, char __user *buf
13862 - case SYSLOG_ACTION_CLOSE: /* Close log */
13864 - case SYSLOG_ACTION_OPEN: /* Open log */
13866 - case SYSLOG_ACTION_READ: /* Read from log */
13867 + if ((type == SYSLOG_ACTION_READ) ||
13868 + (type == SYSLOG_ACTION_READ_ALL) ||
13869 + (type == SYSLOG_ACTION_READ_CLEAR)) {
13871 if (!buf || len < 0)
13873 @@ -1150,6 +1148,16 @@ int do_syslog(int type, char __user *buf
13878 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
13879 + return vx_do_syslog(type, buf, len);
13882 + case SYSLOG_ACTION_CLOSE: /* Close log */
13884 + case SYSLOG_ACTION_OPEN: /* Open log */
13886 + case SYSLOG_ACTION_READ: /* Read from log */
13887 error = wait_event_interruptible(log_wait,
13888 syslog_seq != log_next_seq);
13890 @@ -1162,16 +1170,6 @@ int do_syslog(int type, char __user *buf
13892 /* Read last kernel messages */
13893 case SYSLOG_ACTION_READ_ALL:
13895 - if (!buf || len < 0)
13900 - if (!access_ok(VERIFY_WRITE, buf, len)) {
13904 error = syslog_print_all(buf, len, clear);
13906 /* Clear ring buffer */
13907 diff -NurpP --minimal linux-3.13.10/kernel/ptrace.c linux-3.13.10-vs2.3.6.11/kernel/ptrace.c
13908 --- linux-3.13.10/kernel/ptrace.c 2014-01-22 20:39:13.000000000 +0000
13909 +++ linux-3.13.10-vs2.3.6.11/kernel/ptrace.c 2014-01-31 20:38:03.000000000 +0000
13911 #include <linux/syscalls.h>
13912 #include <linux/uaccess.h>
13913 #include <linux/regset.h>
13914 +#include <linux/vs_context.h>
13915 #include <linux/hw_breakpoint.h>
13916 #include <linux/cn_proc.h>
13917 #include <linux/compat.h>
13918 @@ -264,6 +265,11 @@ ok:
13922 + if (!vx_check(task->xid, VS_ADMIN_P|VS_WATCH_P|VS_IDENT))
13924 + if (!vx_check(task->xid, VS_IDENT) &&
13925 + !task_vx_flags(task, VXF_STATE_ADMIN, 0))
13927 return security_ptrace_access_check(task, mode);
13930 diff -NurpP --minimal linux-3.13.10/kernel/reboot.c linux-3.13.10-vs2.3.6.11/kernel/reboot.c
13931 --- linux-3.13.10/kernel/reboot.c 2014-01-22 20:39:13.000000000 +0000
13932 +++ linux-3.13.10-vs2.3.6.11/kernel/reboot.c 2014-02-01 00:19:40.000000000 +0000
13934 #include <linux/syscalls.h>
13935 #include <linux/syscore_ops.h>
13936 #include <linux/uaccess.h>
13937 +#include <linux/vs_pid.h>
13940 * this indicates whether you can reboot with ctrl-alt-del: the default is yes
13941 @@ -188,6 +189,8 @@ EXPORT_SYMBOL_GPL(kernel_power_off);
13943 static DEFINE_MUTEX(reboot_mutex);
13945 +long vs_reboot(unsigned int, void __user *);
13948 * Reboot system call: for obvious reasons only root may call it,
13949 * and even root needs to set up some magic numbers in the registers
13950 @@ -230,6 +233,9 @@ SYSCALL_DEFINE4(reboot, int, magic1, int
13951 if ((cmd == LINUX_REBOOT_CMD_POWER_OFF) && !pm_power_off)
13952 cmd = LINUX_REBOOT_CMD_HALT;
13954 + if (!vx_check(0, VS_ADMIN|VS_WATCH))
13955 + return vs_reboot(cmd, arg);
13957 mutex_lock(&reboot_mutex);
13959 case LINUX_REBOOT_CMD_RESTART:
13960 diff -NurpP --minimal linux-3.13.10/kernel/sched/core.c linux-3.13.10-vs2.3.6.11/kernel/sched/core.c
13961 --- linux-3.13.10/kernel/sched/core.c 2014-04-17 01:12:39.000000000 +0000
13962 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/core.c 2014-02-25 11:26:10.000000000 +0000
13964 #include <linux/init_task.h>
13965 #include <linux/binfmts.h>
13966 #include <linux/context_tracking.h>
13967 +#include <linux/vs_sched.h>
13968 +#include <linux/vs_cvirt.h>
13970 #include <asm/switch_to.h>
13971 #include <asm/tlb.h>
13972 @@ -2927,7 +2929,7 @@ SYSCALL_DEFINE1(nice, int, increment)
13975 if (increment < 0 && !can_nice(current, nice))
13977 + return vx_flags(VXF_IGNEG_NICE, 0) ? 0 : -EPERM;
13979 retval = security_task_setnice(current, nice);
13981 diff -NurpP --minimal linux-3.13.10/kernel/sched/cputime.c linux-3.13.10-vs2.3.6.11/kernel/sched/cputime.c
13982 --- linux-3.13.10/kernel/sched/cputime.c 2013-11-25 15:47:03.000000000 +0000
13983 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/cputime.c 2014-01-31 20:38:03.000000000 +0000
13985 #include <linux/kernel_stat.h>
13986 #include <linux/static_key.h>
13987 #include <linux/context_tracking.h>
13988 +#include <linux/vs_sched.h>
13992 @@ -135,14 +136,17 @@ static inline void task_group_account_fi
13993 void account_user_time(struct task_struct *p, cputime_t cputime,
13994 cputime_t cputime_scaled)
13996 + struct vx_info *vxi = p->vx_info; /* p is _always_ current */
13997 + int nice = (TASK_NICE(p) > 0);
14000 /* Add user time to process. */
14001 p->utime += cputime;
14002 p->utimescaled += cputime_scaled;
14003 + vx_account_user(vxi, cputime, nice);
14004 account_group_user_time(p, cputime);
14006 - index = (TASK_NICE(p) > 0) ? CPUTIME_NICE : CPUTIME_USER;
14007 + index = (nice) ? CPUTIME_NICE : CPUTIME_USER;
14009 /* Add user time to cpustat. */
14010 task_group_account_field(p, index, (__force u64) cputime);
14011 @@ -189,9 +193,12 @@ static inline
14012 void __account_system_time(struct task_struct *p, cputime_t cputime,
14013 cputime_t cputime_scaled, int index)
14015 + struct vx_info *vxi = p->vx_info; /* p is _always_ current */
14017 /* Add system time to process. */
14018 p->stime += cputime;
14019 p->stimescaled += cputime_scaled;
14020 + vx_account_system(vxi, cputime, 0 /* do we have idle time? */);
14021 account_group_system_time(p, cputime);
14023 /* Add system time to cpustat. */
14024 diff -NurpP --minimal linux-3.13.10/kernel/sched/fair.c linux-3.13.10-vs2.3.6.11/kernel/sched/fair.c
14025 --- linux-3.13.10/kernel/sched/fair.c 2014-04-17 01:12:40.000000000 +0000
14026 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/fair.c 2014-04-17 01:17:11.000000000 +0000
14028 #include <linux/mempolicy.h>
14029 #include <linux/migrate.h>
14030 #include <linux/task_work.h>
14031 +#include <linux/vs_cvirt.h>
14033 #include <trace/events/sched.h>
14035 @@ -2577,6 +2578,8 @@ enqueue_entity(struct cfs_rq *cfs_rq, st
14036 __enqueue_entity(cfs_rq, se);
14039 + if (entity_is_task(se))
14040 + vx_activate_task(task_of(se));
14041 if (cfs_rq->nr_running == 1) {
14042 list_add_leaf_cfs_rq(cfs_rq);
14043 check_enqueue_throttle(cfs_rq);
14044 @@ -2658,6 +2661,8 @@ dequeue_entity(struct cfs_rq *cfs_rq, st
14045 if (se != cfs_rq->curr)
14046 __dequeue_entity(cfs_rq, se);
14048 + if (entity_is_task(se))
14049 + vx_deactivate_task(task_of(se));
14050 account_entity_dequeue(cfs_rq, se);
14053 diff -NurpP --minimal linux-3.13.10/kernel/sched/proc.c linux-3.13.10-vs2.3.6.11/kernel/sched/proc.c
14054 --- linux-3.13.10/kernel/sched/proc.c 2013-11-25 15:45:08.000000000 +0000
14055 +++ linux-3.13.10-vs2.3.6.11/kernel/sched/proc.c 2014-01-31 21:22:36.000000000 +0000
14056 @@ -78,9 +78,17 @@ EXPORT_SYMBOL(avenrun); /* should be rem
14058 void get_avenrun(unsigned long *loads, unsigned long offset, int shift)
14060 - loads[0] = (avenrun[0] + offset) << shift;
14061 - loads[1] = (avenrun[1] + offset) << shift;
14062 - loads[2] = (avenrun[2] + offset) << shift;
14063 + if (vx_flags(VXF_VIRT_LOAD, 0)) {
14064 + struct vx_info *vxi = current_vx_info();
14066 + loads[0] = (vxi->cvirt.load[0] + offset) << shift;
14067 + loads[1] = (vxi->cvirt.load[1] + offset) << shift;
14068 + loads[2] = (vxi->cvirt.load[2] + offset) << shift;
14070 + loads[0] = (avenrun[0] + offset) << shift;
14071 + loads[1] = (avenrun[1] + offset) << shift;
14072 + loads[2] = (avenrun[2] + offset) << shift;
14076 long calc_load_fold_active(struct rq *this_rq)
14077 diff -NurpP --minimal linux-3.13.10/kernel/signal.c linux-3.13.10-vs2.3.6.11/kernel/signal.c
14078 --- linux-3.13.10/kernel/signal.c 2014-01-22 20:39:13.000000000 +0000
14079 +++ linux-3.13.10-vs2.3.6.11/kernel/signal.c 2014-01-31 20:38:03.000000000 +0000
14081 #include <linux/uprobes.h>
14082 #include <linux/compat.h>
14083 #include <linux/cn_proc.h>
14084 +#include <linux/vs_context.h>
14085 +#include <linux/vs_pid.h>
14086 #define CREATE_TRACE_POINTS
14087 #include <trace/events/signal.h>
14089 @@ -790,9 +792,18 @@ static int check_kill_permission(int sig
14093 + vxdprintk(VXD_CBIT(misc, 7),
14094 + "check_kill_permission(%d,%p,%p[#%u,%u])",
14095 + sig, info, t, vx_task_xid(t), t->pid);
14097 if (!valid_signal(sig))
14100 +/* FIXME: needed? if so, why?
14101 + if ((info != SEND_SIG_NOINFO) &&
14102 + (is_si_special(info) || !si_fromuser(info)))
14105 if (!si_fromuser(info))
14108 @@ -816,6 +827,20 @@ static int check_kill_permission(int sig
14113 + if (t->pid == 1 && current->xid)
14117 + /* FIXME: we shouldn't return ESRCH ever, to avoid
14118 + loops, maybe ENOENT or EACCES? */
14119 + if (!vx_check(vx_task_xid(t), VS_WATCH_P | VS_IDENT)) {
14120 + vxdprintk(current->xid || VXD_CBIT(misc, 7),
14121 + "signal %d[%p] xid mismatch %p[#%u,%u] xid=#%u",
14122 + sig, info, t, vx_task_xid(t), t->pid, current->xid);
14126 return security_task_kill(t, info, sig, 0);
14129 @@ -1353,7 +1378,7 @@ int kill_pid_info(int sig, struct siginf
14132 p = pid_task(pid, PIDTYPE_PID);
14134 + if (p && vx_check(vx_task_xid(p), VS_IDENT)) {
14135 error = group_send_sig_info(sig, info, p);
14136 if (unlikely(error == -ESRCH))
14138 @@ -1401,7 +1426,7 @@ int kill_pid_info_as_cred(int sig, struc
14141 p = pid_task(pid, PIDTYPE_PID);
14143 + if (!p || !vx_check(vx_task_xid(p), VS_IDENT)) {
14147 @@ -1453,8 +1478,10 @@ static int kill_something_info(int sig,
14148 struct task_struct * p;
14150 for_each_process(p) {
14151 - if (task_pid_vnr(p) > 1 &&
14152 - !same_thread_group(p, current)) {
14153 + if (vx_check(vx_task_xid(p), VS_ADMIN|VS_IDENT) &&
14154 + task_pid_vnr(p) > 1 &&
14155 + !same_thread_group(p, current) &&
14156 + !vx_current_initpid(p->pid)) {
14157 int err = group_send_sig_info(sig, info, p);
14160 @@ -2308,6 +2335,11 @@ relock:
14161 !sig_kernel_only(signr))
14164 + /* virtual init is protected against user signals */
14165 + if ((info->si_code == SI_USER) &&
14166 + vx_current_initpid(current->pid))
14169 if (sig_kernel_stop(signr)) {
14171 * The default action is to stop all threads in
14172 diff -NurpP --minimal linux-3.13.10/kernel/softirq.c linux-3.13.10-vs2.3.6.11/kernel/softirq.c
14173 --- linux-3.13.10/kernel/softirq.c 2014-01-22 20:39:13.000000000 +0000
14174 +++ linux-3.13.10-vs2.3.6.11/kernel/softirq.c 2014-01-31 20:38:03.000000000 +0000
14176 #include <linux/smp.h>
14177 #include <linux/smpboot.h>
14178 #include <linux/tick.h>
14179 +#include <linux/vs_context.h>
14181 #define CREATE_TRACE_POINTS
14182 #include <trace/events/irq.h>
14183 diff -NurpP --minimal linux-3.13.10/kernel/sys.c linux-3.13.10-vs2.3.6.11/kernel/sys.c
14184 --- linux-3.13.10/kernel/sys.c 2014-01-22 20:39:13.000000000 +0000
14185 +++ linux-3.13.10-vs2.3.6.11/kernel/sys.c 2014-02-01 00:19:29.000000000 +0000
14187 #include <linux/cred.h>
14189 #include <linux/kmsg_dump.h>
14190 +#include <linux/vs_pid.h>
14191 /* Move somewhere else to avoid recompiling? */
14192 #include <generated/utsrelease.h>
14194 @@ -145,7 +146,10 @@ static int set_one_prio(struct task_stru
14197 if (niceval < task_nice(p) && !can_nice(p, niceval)) {
14199 + if (vx_flags(VXF_IGNEG_NICE, 0))
14205 no_nice = security_task_setnice(p, niceval);
14206 @@ -196,6 +200,8 @@ SYSCALL_DEFINE3(setpriority, int, which,
14208 pgrp = task_pgrp(current);
14209 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14210 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14212 error = set_one_prio(p, niceval, error);
14213 } while_each_pid_thread(pgrp, PIDTYPE_PGID, p);
14215 @@ -261,6 +267,8 @@ SYSCALL_DEFINE2(getpriority, int, which,
14217 pgrp = task_pgrp(current);
14218 do_each_pid_thread(pgrp, PIDTYPE_PGID, p) {
14219 + if (!vx_check(p->xid, VS_ADMIN_P | VS_IDENT))
14221 niceval = 20 - task_nice(p);
14222 if (niceval > retval)
14224 @@ -1198,7 +1206,8 @@ SYSCALL_DEFINE2(sethostname, char __user
14226 char tmp[__NEW_UTS_LEN];
14228 - if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14229 + if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14230 + CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14233 if (len < 0 || len > __NEW_UTS_LEN)
14234 @@ -1249,7 +1258,8 @@ SYSCALL_DEFINE2(setdomainname, char __us
14236 char tmp[__NEW_UTS_LEN];
14238 - if (!ns_capable(current->nsproxy->uts_ns->user_ns, CAP_SYS_ADMIN))
14239 + if (!vx_ns_capable(current->nsproxy->uts_ns->user_ns,
14240 + CAP_SYS_ADMIN, VXC_SET_UTSNAME))
14242 if (len < 0 || len > __NEW_UTS_LEN)
14244 @@ -1368,7 +1378,7 @@ int do_prlimit(struct task_struct *tsk,
14245 /* Keep the capable check against init_user_ns until
14246 cgroups can contain all limits */
14247 if (new_rlim->rlim_max > rlim->rlim_max &&
14248 - !capable(CAP_SYS_RESOURCE))
14249 + !vx_capable(CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14252 retval = security_task_setrlimit(tsk->group_leader,
14253 @@ -1421,7 +1431,8 @@ static int check_prlimit_permission(stru
14254 gid_eq(cred->gid, tcred->sgid) &&
14255 gid_eq(cred->gid, tcred->gid))
14257 - if (ns_capable(tcred->user_ns, CAP_SYS_RESOURCE))
14258 + if (vx_ns_capable(tcred->user_ns,
14259 + CAP_SYS_RESOURCE, VXC_SET_RLIMIT))
14263 diff -NurpP --minimal linux-3.13.10/kernel/sysctl.c linux-3.13.10-vs2.3.6.11/kernel/sysctl.c
14264 --- linux-3.13.10/kernel/sysctl.c 2014-04-17 01:12:40.000000000 +0000
14265 +++ linux-3.13.10-vs2.3.6.11/kernel/sysctl.c 2014-02-25 11:26:10.000000000 +0000
14267 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
14268 #include <linux/lockdep.h>
14270 +extern char vshelper_path[];
14271 #ifdef CONFIG_CHR_DEV_SG
14272 #include <scsi/sg.h>
14274 @@ -650,6 +651,13 @@ static struct ctl_table kern_table[] = {
14276 .proc_handler = proc_dostring,
14279 + .procname = "vshelper",
14280 + .data = &vshelper_path,
14283 + .proc_handler = &proc_dostring,
14286 #ifdef CONFIG_CHR_DEV_SG
14288 diff -NurpP --minimal linux-3.13.10/kernel/sysctl_binary.c linux-3.13.10-vs2.3.6.11/kernel/sysctl_binary.c
14289 --- linux-3.13.10/kernel/sysctl_binary.c 2014-01-22 20:39:13.000000000 +0000
14290 +++ linux-3.13.10-vs2.3.6.11/kernel/sysctl_binary.c 2014-01-31 20:38:03.000000000 +0000
14291 @@ -73,6 +73,7 @@ static const struct bin_table bin_kern_t
14293 { CTL_INT, KERN_PANIC, "panic" },
14294 { CTL_INT, KERN_REALROOTDEV, "real-root-dev" },
14295 + { CTL_STR, KERN_VSHELPER, "vshelper" },
14297 { CTL_STR, KERN_SPARC_REBOOT, "reboot-cmd" },
14298 { CTL_INT, KERN_CTLALTDEL, "ctrl-alt-del" },
14299 diff -NurpP --minimal linux-3.13.10/kernel/time/timekeeping.c linux-3.13.10-vs2.3.6.11/kernel/time/timekeeping.c
14300 --- linux-3.13.10/kernel/time/timekeeping.c 2014-04-17 01:12:40.000000000 +0000
14301 +++ linux-3.13.10-vs2.3.6.11/kernel/time/timekeeping.c 2014-02-25 11:26:10.000000000 +0000
14303 #include <linux/tick.h>
14304 #include <linux/stop_machine.h>
14305 #include <linux/pvclock_gtod.h>
14306 +#include <linux/vs_time.h>
14308 #include "tick-internal.h"
14309 #include "ntp_internal.h"
14310 @@ -709,6 +710,7 @@ void getrawmonotonic(struct timespec *ts
14311 } while (read_seqcount_retry(&timekeeper_seq, seq));
14313 timespec_add_ns(ts, nsecs);
14314 + vx_adjust_timespec(ts);
14316 EXPORT_SYMBOL(getrawmonotonic);
14318 diff -NurpP --minimal linux-3.13.10/kernel/time.c linux-3.13.10-vs2.3.6.11/kernel/time.c
14319 --- linux-3.13.10/kernel/time.c 2013-11-25 15:45:08.000000000 +0000
14320 +++ linux-3.13.10-vs2.3.6.11/kernel/time.c 2014-01-31 20:38:03.000000000 +0000
14322 #include <linux/fs.h>
14323 #include <linux/math64.h>
14324 #include <linux/ptrace.h>
14325 +#include <linux/vs_time.h>
14327 #include <asm/uaccess.h>
14328 #include <asm/unistd.h>
14329 @@ -92,7 +93,7 @@ SYSCALL_DEFINE1(stime, time_t __user *,
14333 - do_settimeofday(&tv);
14334 + vx_settimeofday(&tv);
14338 @@ -181,7 +182,7 @@ int do_sys_settimeofday(const struct tim
14342 - return do_settimeofday(tv);
14343 + return vx_settimeofday(tv);
14347 diff -NurpP --minimal linux-3.13.10/kernel/timer.c linux-3.13.10-vs2.3.6.11/kernel/timer.c
14348 --- linux-3.13.10/kernel/timer.c 2014-01-22 20:39:13.000000000 +0000
14349 +++ linux-3.13.10-vs2.3.6.11/kernel/timer.c 2014-01-31 20:38:03.000000000 +0000
14351 #include <linux/sched/sysctl.h>
14352 #include <linux/slab.h>
14353 #include <linux/compat.h>
14354 +#include <linux/vs_base.h>
14355 +#include <linux/vs_cvirt.h>
14356 +#include <linux/vs_pid.h>
14357 +#include <linux/vserver/sched.h>
14359 #include <asm/uaccess.h>
14360 #include <asm/unistd.h>
14361 diff -NurpP --minimal linux-3.13.10/kernel/user_namespace.c linux-3.13.10-vs2.3.6.11/kernel/user_namespace.c
14362 --- linux-3.13.10/kernel/user_namespace.c 2014-01-22 20:39:13.000000000 +0000
14363 +++ linux-3.13.10-vs2.3.6.11/kernel/user_namespace.c 2014-01-31 20:38:03.000000000 +0000
14365 #include <linux/ctype.h>
14366 #include <linux/projid.h>
14367 #include <linux/fs_struct.h>
14368 +#include <linux/vserver/global.h>
14370 static struct kmem_cache *user_ns_cachep __read_mostly;
14372 @@ -94,6 +95,7 @@ int create_user_ns(struct cred *new)
14374 atomic_set(&ns->count, 1);
14375 /* Leave the new->user_ns reference with the new user namespace. */
14376 + atomic_inc(&vs_global_user_ns);
14377 ns->parent = parent_ns;
14378 ns->level = parent_ns->level + 1;
14380 @@ -848,6 +850,8 @@ static void *userns_get(struct task_stru
14382 static void userns_put(void *ns)
14384 + /* FIXME: maybe move into destroyer? */
14385 + atomic_dec(&vs_global_user_ns);
14389 diff -NurpP --minimal linux-3.13.10/kernel/utsname.c linux-3.13.10-vs2.3.6.11/kernel/utsname.c
14390 --- linux-3.13.10/kernel/utsname.c 2013-11-25 15:47:03.000000000 +0000
14391 +++ linux-3.13.10-vs2.3.6.11/kernel/utsname.c 2014-01-31 20:38:03.000000000 +0000
14392 @@ -16,14 +16,17 @@
14393 #include <linux/slab.h>
14394 #include <linux/user_namespace.h>
14395 #include <linux/proc_ns.h>
14396 +#include <linux/vserver/global.h>
14398 static struct uts_namespace *create_uts_ns(void)
14400 struct uts_namespace *uts_ns;
14402 uts_ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
14405 kref_init(&uts_ns->kref);
14406 + atomic_inc(&vs_global_uts_ns);
14411 @@ -85,6 +88,7 @@ void free_uts_ns(struct kref *kref)
14412 ns = container_of(kref, struct uts_namespace, kref);
14413 put_user_ns(ns->user_ns);
14414 proc_free_inum(ns->proc_inum);
14415 + atomic_dec(&vs_global_uts_ns);
14419 diff -NurpP --minimal linux-3.13.10/kernel/vserver/Kconfig linux-3.13.10-vs2.3.6.11/kernel/vserver/Kconfig
14420 --- linux-3.13.10/kernel/vserver/Kconfig 1970-01-01 00:00:00.000000000 +0000
14421 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/Kconfig 2014-01-31 20:38:03.000000000 +0000
14424 +# Linux VServer configuration
14427 +menu "Linux VServer"
14429 +config VSERVER_AUTO_LBACK
14430 + bool "Automatically Assign Loopback IP"
14433 + Automatically assign a guest specific loopback
14434 + IP and add it to the kernel network stack on
14437 +config VSERVER_AUTO_SINGLE
14438 + bool "Automatic Single IP Special Casing"
14441 + This allows network contexts with a single IP to
14442 + automatically remap 0.0.0.0 bindings to that IP,
14443 + avoiding further network checks and improving
14446 + (note: such guests do not allow to change the ip
14447 + on the fly and do not show loopback addresses)
14449 +config VSERVER_COWBL
14450 + bool "Enable COW Immutable Link Breaking"
14453 + This enables the COW (Copy-On-Write) link break code.
14454 + It allows you to treat unified files like normal files
14455 + when writing to them (which will implicitely break the
14456 + link and create a copy of the unified file)
14458 +config VSERVER_VTIME
14459 + bool "Enable Virtualized Guest Time (EXPERIMENTAL)"
14462 + This enables per guest time offsets to allow for
14463 + adjusting the system clock individually per guest.
14464 + this adds some overhead to the time functions and
14465 + therefore should not be enabled without good reason.
14467 +config VSERVER_DEVICE
14468 + bool "Enable Guest Device Mapping (EXPERIMENTAL)"
14471 + This enables generic device remapping.
14473 +config VSERVER_PROC_SECURE
14474 + bool "Enable Proc Security"
14475 + depends on PROC_FS
14478 + This configures ProcFS security to initially hide
14479 + non-process entries for all contexts except the main and
14480 + spectator context (i.e. for all guests), which is a secure
14483 + (note: on 1.2x the entries were visible by default)
14486 + prompt "Persistent Inode Tagging"
14487 + default TAGGING_ID24
14489 + This adds persistent context information to filesystems
14490 + mounted with the tagxid option. Tagging is a requirement
14491 + for per-context disk limits and per-context quota.
14494 +config TAGGING_NONE
14497 + do not store per-context information in inodes.
14499 +config TAGGING_UID16
14500 + bool "UID16/GID32"
14502 + reduces UID to 16 bit, but leaves GID at 32 bit.
14504 +config TAGGING_GID16
14505 + bool "UID32/GID16"
14507 + reduces GID to 16 bit, but leaves UID at 32 bit.
14509 +config TAGGING_ID24
14510 + bool "UID24/GID24"
14512 + uses the upper 8bit from UID and GID for XID tagging
14513 + which leaves 24bit for UID/GID each, which should be
14514 + more than sufficient for normal use.
14516 +config TAGGING_INTERN
14517 + bool "UID32/GID32"
14519 + this uses otherwise reserved inode fields in the on
14520 + disk representation, which limits the use to a few
14521 + filesystems (currently ext2 and ext3)
14526 + bool "Tag NFSD User Auth and Files"
14529 + Enable this if you do want the in-kernel NFS
14530 + Server to use the tagging specified above.
14531 + (will require patched clients too)
14533 +config VSERVER_PRIVACY
14534 + bool "Honor Privacy Aspects of Guests"
14537 + When enabled, most context checks will disallow
14538 + access to structures assigned to a specific context,
14539 + like ptys or loop devices.
14541 +config VSERVER_CONTEXTS
14542 + int "Maximum number of Contexts (1-65533)" if EMBEDDED
14544 + default "768" if 64BIT
14547 + This setting will optimize certain data structures
14548 + and memory allocations according to the expected
14551 + note: this is not a strict upper limit.
14553 +config VSERVER_WARN
14554 + bool "VServer Warnings"
14557 + This enables various runtime warnings, which will
14558 + notify about potential manipulation attempts or
14559 + resource shortage. It is generally considered to
14560 + be a good idea to have that enabled.
14562 +config VSERVER_WARN_DEVPTS
14563 + bool "VServer DevPTS Warnings"
14564 + depends on VSERVER_WARN
14567 + This enables DevPTS related warnings, issued when a
14568 + process inside a context tries to lookup or access
14569 + a dynamic pts from the host or a different context.
14571 +config VSERVER_DEBUG
14572 + bool "VServer Debugging Code"
14575 + Set this to yes if you want to be able to activate
14576 + debugging output at runtime. It adds a very small
14577 + overhead to all vserver related functions and
14578 + increases the kernel size by about 20k.
14580 +config VSERVER_HISTORY
14581 + bool "VServer History Tracing"
14582 + depends on VSERVER_DEBUG
14585 + Set this to yes if you want to record the history of
14586 + linux-vserver activities, so they can be replayed in
14587 + the event of a kernel panic or oops.
14589 +config VSERVER_HISTORY_SIZE
14590 + int "Per-CPU History Size (32-65536)"
14591 + depends on VSERVER_HISTORY
14595 + This allows you to specify the number of entries in
14596 + the per-CPU history buffer.
14598 +config VSERVER_EXTRA_MNT_CHECK
14599 + bool "Extra Checks for Reachability"
14602 + Set this to yes if you want to do extra checks for
14603 + vfsmount reachability in the proc filesystem code.
14604 + This shouldn't be required on any setup utilizing
14608 + prompt "Quotes used in debug and warn messages"
14609 + default QUOTES_ISO8859
14611 +config QUOTES_ISO8859
14612 + bool "Extended ASCII (ISO 8859) angle quotes"
14614 + This uses the extended ASCII characters \xbb
14615 + and \xab for quoting file and process names.
14617 +config QUOTES_UTF8
14618 + bool "UTF-8 angle quotes"
14620 + This uses the the UTF-8 sequences for angle
14621 + quotes to quote file and process names.
14623 +config QUOTES_ASCII
14624 + bool "ASCII single quotes"
14626 + This uses the ASCII single quote character
14627 + (\x27) to quote file and process names.
14637 + select NAMESPACES
14643 +config VSERVER_SECURITY
14645 + depends on SECURITY
14647 + select SECURITY_CAPABILITIES
14649 +config VSERVER_DISABLED
14653 diff -NurpP --minimal linux-3.13.10/kernel/vserver/Makefile linux-3.13.10-vs2.3.6.11/kernel/vserver/Makefile
14654 --- linux-3.13.10/kernel/vserver/Makefile 1970-01-01 00:00:00.000000000 +0000
14655 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/Makefile 2014-01-31 20:38:03.000000000 +0000
14658 +# Makefile for the Linux vserver routines.
14662 +obj-y += vserver.o
14664 +vserver-y := switch.o context.o space.o sched.o network.o inode.o \
14665 + limit.o cvirt.o cacct.o signal.o helper.o init.o \
14668 +vserver-$(CONFIG_INET) += inet.o
14669 +vserver-$(CONFIG_PROC_FS) += proc.o
14670 +vserver-$(CONFIG_VSERVER_DEBUG) += sysctl.o debug.o
14671 +vserver-$(CONFIG_VSERVER_HISTORY) += history.o
14672 +vserver-$(CONFIG_VSERVER_MONITOR) += monitor.o
14673 +vserver-$(CONFIG_VSERVER_DEVICE) += device.o
14675 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cacct.c linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct.c
14676 --- linux-3.13.10/kernel/vserver/cacct.c 1970-01-01 00:00:00.000000000 +0000
14677 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct.c 2014-01-31 20:38:03.000000000 +0000
14680 + * linux/kernel/vserver/cacct.c
14682 + * Virtual Server: Context Accounting
14684 + * Copyright (C) 2006-2007 Herbert Pötzl
14686 + * V0.01 added accounting stats
14690 +#include <linux/types.h>
14691 +#include <linux/vs_context.h>
14692 +#include <linux/vserver/cacct_cmd.h>
14693 +#include <linux/vserver/cacct_int.h>
14695 +#include <asm/errno.h>
14696 +#include <asm/uaccess.h>
14699 +int vc_sock_stat(struct vx_info *vxi, void __user *data)
14701 + struct vcmd_sock_stat_v0 vc_data;
14704 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
14707 + field = vc_data.field;
14708 + if ((field < 0) || (field >= VXA_SOCK_SIZE))
14711 + for (j = 0; j < 3; j++) {
14712 + vc_data.count[j] = vx_sock_count(&vxi->cacct, field, j);
14713 + vc_data.total[j] = vx_sock_total(&vxi->cacct, field, j);
14716 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
14721 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cacct_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_init.h
14722 --- linux-3.13.10/kernel/vserver/cacct_init.h 1970-01-01 00:00:00.000000000 +0000
14723 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_init.h 2014-01-31 20:38:03.000000000 +0000
14727 +static inline void vx_info_init_cacct(struct _vx_cacct *cacct)
14732 + for (i = 0; i < VXA_SOCK_SIZE; i++) {
14733 + for (j = 0; j < 3; j++) {
14734 + atomic_long_set(&cacct->sock[i][j].count, 0);
14735 + atomic_long_set(&cacct->sock[i][j].total, 0);
14738 + for (i = 0; i < 8; i++)
14739 + atomic_set(&cacct->slab[i], 0);
14740 + for (i = 0; i < 5; i++)
14741 + for (j = 0; j < 4; j++)
14742 + atomic_set(&cacct->page[i][j], 0);
14745 +static inline void vx_info_exit_cacct(struct _vx_cacct *cacct)
14750 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cacct_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_proc.h
14751 --- linux-3.13.10/kernel/vserver/cacct_proc.h 1970-01-01 00:00:00.000000000 +0000
14752 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cacct_proc.h 2014-01-31 20:38:03.000000000 +0000
14754 +#ifndef _VX_CACCT_PROC_H
14755 +#define _VX_CACCT_PROC_H
14757 +#include <linux/vserver/cacct_int.h>
14760 +#define VX_SOCKA_TOP \
14761 + "Type\t recv #/bytes\t\t send #/bytes\t\t fail #/bytes\n"
14763 +static inline int vx_info_proc_cacct(struct _vx_cacct *cacct, char *buffer)
14765 + int i, j, length = 0;
14766 + static char *type[VXA_SOCK_SIZE] = {
14767 + "UNSPEC", "UNIX", "INET", "INET6", "PACKET", "OTHER"
14770 + length += sprintf(buffer + length, VX_SOCKA_TOP);
14771 + for (i = 0; i < VXA_SOCK_SIZE; i++) {
14772 + length += sprintf(buffer + length, "%s:", type[i]);
14773 + for (j = 0; j < 3; j++) {
14774 + length += sprintf(buffer + length,
14775 + "\t%10lu/%-10lu",
14776 + vx_sock_count(cacct, i, j),
14777 + vx_sock_total(cacct, i, j));
14779 + buffer[length++] = '\n';
14782 + length += sprintf(buffer + length, "\n");
14783 + length += sprintf(buffer + length,
14784 + "slab:\t %8u %8u %8u %8u\n",
14785 + atomic_read(&cacct->slab[1]),
14786 + atomic_read(&cacct->slab[4]),
14787 + atomic_read(&cacct->slab[0]),
14788 + atomic_read(&cacct->slab[2]));
14790 + length += sprintf(buffer + length, "\n");
14791 + for (i = 0; i < 5; i++) {
14792 + length += sprintf(buffer + length,
14793 + "page[%d]: %8u %8u %8u %8u\t %8u %8u %8u %8u\n", i,
14794 + atomic_read(&cacct->page[i][0]),
14795 + atomic_read(&cacct->page[i][1]),
14796 + atomic_read(&cacct->page[i][2]),
14797 + atomic_read(&cacct->page[i][3]),
14798 + atomic_read(&cacct->page[i][4]),
14799 + atomic_read(&cacct->page[i][5]),
14800 + atomic_read(&cacct->page[i][6]),
14801 + atomic_read(&cacct->page[i][7]));
14806 +#endif /* _VX_CACCT_PROC_H */
14807 diff -NurpP --minimal linux-3.13.10/kernel/vserver/context.c linux-3.13.10-vs2.3.6.11/kernel/vserver/context.c
14808 --- linux-3.13.10/kernel/vserver/context.c 1970-01-01 00:00:00.000000000 +0000
14809 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/context.c 2014-01-31 20:38:03.000000000 +0000
14812 + * linux/kernel/vserver/context.c
14814 + * Virtual Server: Context Support
14816 + * Copyright (C) 2003-2011 Herbert Pötzl
14818 + * V0.01 context helper
14819 + * V0.02 vx_ctx_kill syscall command
14820 + * V0.03 replaced context_info calls
14821 + * V0.04 redesign of struct (de)alloc
14822 + * V0.05 rlimit basic implementation
14823 + * V0.06 task_xid and info commands
14824 + * V0.07 context flags and caps
14825 + * V0.08 switch to RCU based hash
14826 + * V0.09 revert to non RCU for now
14827 + * V0.10 and back to working RCU hash
14828 + * V0.11 and back to locking again
14829 + * V0.12 referenced context store
14830 + * V0.13 separate per cpu data
14831 + * V0.14 changed vcmds to vxi arg
14832 + * V0.15 added context stat
14833 + * V0.16 have __create claim() the vxi
14834 + * V0.17 removed older and legacy stuff
14835 + * V0.18 added user credentials
14836 + * V0.19 added warn mask
14840 +#include <linux/slab.h>
14841 +#include <linux/types.h>
14842 +#include <linux/security.h>
14843 +#include <linux/pid_namespace.h>
14844 +#include <linux/capability.h>
14846 +#include <linux/vserver/context.h>
14847 +#include <linux/vserver/network.h>
14848 +#include <linux/vserver/debug.h>
14849 +#include <linux/vserver/limit.h>
14850 +#include <linux/vserver/limit_int.h>
14851 +#include <linux/vserver/space.h>
14852 +#include <linux/init_task.h>
14853 +#include <linux/fs_struct.h>
14854 +#include <linux/cred.h>
14856 +#include <linux/vs_context.h>
14857 +#include <linux/vs_limit.h>
14858 +#include <linux/vs_pid.h>
14859 +#include <linux/vserver/context_cmd.h>
14861 +#include "cvirt_init.h"
14862 +#include "cacct_init.h"
14863 +#include "limit_init.h"
14864 +#include "sched_init.h"
14867 +atomic_t vx_global_ctotal = ATOMIC_INIT(0);
14868 +atomic_t vx_global_cactive = ATOMIC_INIT(0);
14871 +/* now inactive context structures */
14873 +static struct hlist_head vx_info_inactive = HLIST_HEAD_INIT;
14875 +static DEFINE_SPINLOCK(vx_info_inactive_lock);
14878 +/* __alloc_vx_info()
14880 + * allocate an initialized vx_info struct
14881 + * doesn't make it visible (hash) */
14883 +static struct vx_info *__alloc_vx_info(vxid_t xid)
14885 + struct vx_info *new = NULL;
14888 + vxdprintk(VXD_CBIT(xid, 0), "alloc_vx_info(%d)*", xid);
14890 + /* would this benefit from a slab cache? */
14891 + new = kmalloc(sizeof(struct vx_info), GFP_KERNEL);
14895 + memset(new, 0, sizeof(struct vx_info));
14897 + new->ptr_pc = alloc_percpu(struct _vx_info_pc);
14898 + if (!new->ptr_pc)
14901 + new->vx_id = xid;
14902 + INIT_HLIST_NODE(&new->vx_hlist);
14903 + atomic_set(&new->vx_usecnt, 0);
14904 + atomic_set(&new->vx_tasks, 0);
14905 + new->vx_parent = NULL;
14906 + new->vx_state = 0;
14907 + init_waitqueue_head(&new->vx_wait);
14909 + /* prepare reaper */
14910 + get_task_struct(init_pid_ns.child_reaper);
14911 + new->vx_reaper = init_pid_ns.child_reaper;
14912 + new->vx_badness_bias = 0;
14914 + /* rest of init goes here */
14915 + vx_info_init_limit(&new->limit);
14916 + vx_info_init_sched(&new->sched);
14917 + vx_info_init_cvirt(&new->cvirt);
14918 + vx_info_init_cacct(&new->cacct);
14920 + /* per cpu data structures */
14921 + for_each_possible_cpu(cpu) {
14922 + vx_info_init_sched_pc(
14923 + &vx_per_cpu(new, sched_pc, cpu), cpu);
14924 + vx_info_init_cvirt_pc(
14925 + &vx_per_cpu(new, cvirt_pc, cpu), cpu);
14928 + new->vx_flags = VXF_INIT_SET;
14929 + new->vx_bcaps = CAP_FULL_SET; // maybe ~CAP_SETPCAP
14930 + new->vx_ccaps = 0;
14931 + new->vx_umask = 0;
14932 + new->vx_wmask = 0;
14934 + new->reboot_cmd = 0;
14935 + new->exit_code = 0;
14937 + // preconfig spaces
14938 + for (index = 0; index < VX_SPACES; index++) {
14939 + struct _vx_space *space = &new->space[index];
14942 + spin_lock(&init_fs.lock);
14944 + spin_unlock(&init_fs.lock);
14945 + space->vx_fs = &init_fs;
14947 + /* FIXME: do we want defaults? */
14948 + // space->vx_real_cred = 0;
14949 + // space->vx_cred = 0;
14953 + vxdprintk(VXD_CBIT(xid, 0),
14954 + "alloc_vx_info(%d) = %p", xid, new);
14955 + vxh_alloc_vx_info(new);
14956 + atomic_inc(&vx_global_ctotal);
14965 +/* __dealloc_vx_info()
14967 + * final disposal of vx_info */
14969 +static void __dealloc_vx_info(struct vx_info *vxi)
14971 +#ifdef CONFIG_VSERVER_WARN
14972 + struct vx_info_save vxis;
14975 + vxdprintk(VXD_CBIT(xid, 0),
14976 + "dealloc_vx_info(%p)", vxi);
14977 + vxh_dealloc_vx_info(vxi);
14979 +#ifdef CONFIG_VSERVER_WARN
14980 + enter_vx_info(vxi, &vxis);
14981 + vx_info_exit_limit(&vxi->limit);
14982 + vx_info_exit_sched(&vxi->sched);
14983 + vx_info_exit_cvirt(&vxi->cvirt);
14984 + vx_info_exit_cacct(&vxi->cacct);
14986 + for_each_possible_cpu(cpu) {
14987 + vx_info_exit_sched_pc(
14988 + &vx_per_cpu(vxi, sched_pc, cpu), cpu);
14989 + vx_info_exit_cvirt_pc(
14990 + &vx_per_cpu(vxi, cvirt_pc, cpu), cpu);
14992 + leave_vx_info(&vxis);
14996 + vxi->vx_state |= VXS_RELEASED;
14999 + free_percpu(vxi->ptr_pc);
15002 + atomic_dec(&vx_global_ctotal);
15005 +static void __shutdown_vx_info(struct vx_info *vxi)
15007 + struct nsproxy *nsproxy;
15008 + struct fs_struct *fs;
15009 + struct cred *cred;
15014 + vxi->vx_state |= VXS_SHUTDOWN;
15015 + vs_state_change(vxi, VSC_SHUTDOWN);
15017 + for (index = 0; index < VX_SPACES; index++) {
15018 + struct _vx_space *space = &vxi->space[index];
15020 + nsproxy = xchg(&space->vx_nsproxy, NULL);
15022 + put_nsproxy(nsproxy);
15024 + fs = xchg(&space->vx_fs, NULL);
15025 + spin_lock(&fs->lock);
15026 + kill = !--fs->users;
15027 + spin_unlock(&fs->lock);
15029 + free_fs_struct(fs);
15031 + cred = (struct cred *)xchg(&space->vx_cred, NULL);
15033 + abort_creds(cred);
15037 +/* exported stuff */
15039 +void free_vx_info(struct vx_info *vxi)
15041 + unsigned long flags;
15044 + /* check for reference counts first */
15045 + BUG_ON(atomic_read(&vxi->vx_usecnt));
15046 + BUG_ON(atomic_read(&vxi->vx_tasks));
15048 + /* context must not be hashed */
15049 + BUG_ON(vx_info_state(vxi, VXS_HASHED));
15051 + /* context shutdown is mandatory */
15052 + BUG_ON(!vx_info_state(vxi, VXS_SHUTDOWN));
15054 + /* spaces check */
15055 + for (index = 0; index < VX_SPACES; index++) {
15056 + struct _vx_space *space = &vxi->space[index];
15058 + BUG_ON(space->vx_nsproxy);
15059 + BUG_ON(space->vx_fs);
15060 + // BUG_ON(space->vx_real_cred);
15061 + // BUG_ON(space->vx_cred);
15064 + spin_lock_irqsave(&vx_info_inactive_lock, flags);
15065 + hlist_del(&vxi->vx_hlist);
15066 + spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15068 + __dealloc_vx_info(vxi);
15072 +/* hash table for vx_info hash */
15074 +#define VX_HASH_SIZE 13
15076 +static struct hlist_head vx_info_hash[VX_HASH_SIZE] =
15077 + { [0 ... VX_HASH_SIZE-1] = HLIST_HEAD_INIT };
15079 +static DEFINE_SPINLOCK(vx_info_hash_lock);
15082 +static inline unsigned int __hashval(vxid_t xid)
15084 + return (xid % VX_HASH_SIZE);
15089 +/* __hash_vx_info()
15091 + * add the vxi to the global hash table
15092 + * requires the hash_lock to be held */
15094 +static inline void __hash_vx_info(struct vx_info *vxi)
15096 + struct hlist_head *head;
15098 + vxd_assert_lock(&vx_info_hash_lock);
15099 + vxdprintk(VXD_CBIT(xid, 4),
15100 + "__hash_vx_info: %p[#%d]", vxi, vxi->vx_id);
15101 + vxh_hash_vx_info(vxi);
15103 + /* context must not be hashed */
15104 + BUG_ON(vx_info_state(vxi, VXS_HASHED));
15106 + vxi->vx_state |= VXS_HASHED;
15107 + head = &vx_info_hash[__hashval(vxi->vx_id)];
15108 + hlist_add_head(&vxi->vx_hlist, head);
15109 + atomic_inc(&vx_global_cactive);
15112 +/* __unhash_vx_info()
15114 + * remove the vxi from the global hash table
15115 + * requires the hash_lock to be held */
15117 +static inline void __unhash_vx_info(struct vx_info *vxi)
15119 + unsigned long flags;
15121 + vxd_assert_lock(&vx_info_hash_lock);
15122 + vxdprintk(VXD_CBIT(xid, 4),
15123 + "__unhash_vx_info: %p[#%d.%d.%d]", vxi, vxi->vx_id,
15124 + atomic_read(&vxi->vx_usecnt), atomic_read(&vxi->vx_tasks));
15125 + vxh_unhash_vx_info(vxi);
15127 + /* context must be hashed */
15128 + BUG_ON(!vx_info_state(vxi, VXS_HASHED));
15129 + /* but without tasks */
15130 + BUG_ON(atomic_read(&vxi->vx_tasks));
15132 + vxi->vx_state &= ~VXS_HASHED;
15133 + hlist_del_init(&vxi->vx_hlist);
15134 + spin_lock_irqsave(&vx_info_inactive_lock, flags);
15135 + hlist_add_head(&vxi->vx_hlist, &vx_info_inactive);
15136 + spin_unlock_irqrestore(&vx_info_inactive_lock, flags);
15137 + atomic_dec(&vx_global_cactive);
15141 +/* __lookup_vx_info()
15143 + * requires the hash_lock to be held
15144 + * doesn't increment the vx_refcnt */
15146 +static inline struct vx_info *__lookup_vx_info(vxid_t xid)
15148 + struct hlist_head *head = &vx_info_hash[__hashval(xid)];
15149 + struct hlist_node *pos;
15150 + struct vx_info *vxi;
15152 + vxd_assert_lock(&vx_info_hash_lock);
15153 + hlist_for_each(pos, head) {
15154 + vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15156 + if (vxi->vx_id == xid)
15161 + vxdprintk(VXD_CBIT(xid, 0),
15162 + "__lookup_vx_info(#%u): %p[#%u]",
15163 + xid, vxi, vxi ? vxi->vx_id : 0);
15164 + vxh_lookup_vx_info(vxi, xid);
15169 +/* __create_vx_info()
15171 + * create the requested context
15172 + * get(), claim() and hash it */
15174 +static struct vx_info *__create_vx_info(int id)
15176 + struct vx_info *new, *vxi = NULL;
15178 + vxdprintk(VXD_CBIT(xid, 1), "create_vx_info(%d)*", id);
15180 + if (!(new = __alloc_vx_info(id)))
15181 + return ERR_PTR(-ENOMEM);
15183 + /* required to make dynamic xids unique */
15184 + spin_lock(&vx_info_hash_lock);
15186 + /* static context requested */
15187 + if ((vxi = __lookup_vx_info(id))) {
15188 + vxdprintk(VXD_CBIT(xid, 0),
15189 + "create_vx_info(%d) = %p (already there)", id, vxi);
15190 + if (vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15191 + vxi = ERR_PTR(-EBUSY);
15193 + vxi = ERR_PTR(-EEXIST);
15196 + /* new context */
15197 + vxdprintk(VXD_CBIT(xid, 0),
15198 + "create_vx_info(%d) = %p (new)", id, new);
15199 + claim_vx_info(new, NULL);
15200 + __hash_vx_info(get_vx_info(new));
15201 + vxi = new, new = NULL;
15204 + spin_unlock(&vx_info_hash_lock);
15205 + vxh_create_vx_info(IS_ERR(vxi) ? NULL : vxi, id);
15207 + __dealloc_vx_info(new);
15212 +/* exported stuff */
15215 +void unhash_vx_info(struct vx_info *vxi)
15217 + spin_lock(&vx_info_hash_lock);
15218 + __unhash_vx_info(vxi);
15219 + spin_unlock(&vx_info_hash_lock);
15220 + __shutdown_vx_info(vxi);
15221 + __wakeup_vx_info(vxi);
15225 +/* lookup_vx_info()
15227 + * search for a vx_info and get() it
15228 + * negative id means current */
15230 +struct vx_info *lookup_vx_info(int id)
15232 + struct vx_info *vxi = NULL;
15235 + vxi = get_vx_info(current_vx_info());
15236 + } else if (id > 1) {
15237 + spin_lock(&vx_info_hash_lock);
15238 + vxi = get_vx_info(__lookup_vx_info(id));
15239 + spin_unlock(&vx_info_hash_lock);
15244 +/* xid_is_hashed()
15246 + * verify that xid is still hashed */
15248 +int xid_is_hashed(vxid_t xid)
15252 + spin_lock(&vx_info_hash_lock);
15253 + hashed = (__lookup_vx_info(xid) != NULL);
15254 + spin_unlock(&vx_info_hash_lock);
15258 +#ifdef CONFIG_PROC_FS
15262 + * get a subset of hashed xids for proc
15263 + * assumes size is at least one */
15265 +int get_xid_list(int index, unsigned int *xids, int size)
15267 + int hindex, nr_xids = 0;
15269 + /* only show current and children */
15270 + if (!vx_check(0, VS_ADMIN | VS_WATCH)) {
15273 + xids[nr_xids] = vx_current_xid();
15277 + for (hindex = 0; hindex < VX_HASH_SIZE; hindex++) {
15278 + struct hlist_head *head = &vx_info_hash[hindex];
15279 + struct hlist_node *pos;
15281 + spin_lock(&vx_info_hash_lock);
15282 + hlist_for_each(pos, head) {
15283 + struct vx_info *vxi;
15288 + vxi = hlist_entry(pos, struct vx_info, vx_hlist);
15289 + xids[nr_xids] = vxi->vx_id;
15290 + if (++nr_xids >= size) {
15291 + spin_unlock(&vx_info_hash_lock);
15295 + /* keep the lock time short */
15296 + spin_unlock(&vx_info_hash_lock);
15303 +#ifdef CONFIG_VSERVER_DEBUG
15305 +void dump_vx_info_inactive(int level)
15307 + struct hlist_node *entry, *next;
15309 + hlist_for_each_safe(entry, next, &vx_info_inactive) {
15310 + struct vx_info *vxi =
15311 + list_entry(entry, struct vx_info, vx_hlist);
15313 + dump_vx_info(vxi, level);
15320 +int vx_migrate_user(struct task_struct *p, struct vx_info *vxi)
15322 + struct user_struct *new_user, *old_user;
15327 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
15330 + new_user = alloc_uid(vxi->vx_id, p->uid);
15334 + old_user = p->user;
15335 + if (new_user != old_user) {
15336 + atomic_inc(&new_user->processes);
15337 + atomic_dec(&old_user->processes);
15338 + p->user = new_user;
15340 + free_uid(old_user);
15346 +void vx_mask_cap_bset(struct vx_info *vxi, struct task_struct *p)
15348 + // p->cap_effective &= vxi->vx_cap_bset;
15349 + p->cap_effective =
15350 + cap_intersect(p->cap_effective, vxi->cap_bset);
15351 + // p->cap_inheritable &= vxi->vx_cap_bset;
15352 + p->cap_inheritable =
15353 + cap_intersect(p->cap_inheritable, vxi->cap_bset);
15354 + // p->cap_permitted &= vxi->vx_cap_bset;
15355 + p->cap_permitted =
15356 + cap_intersect(p->cap_permitted, vxi->cap_bset);
15361 +#include <linux/file.h>
15362 +#include <linux/fdtable.h>
15364 +static int vx_openfd_task(struct task_struct *tsk)
15366 + struct files_struct *files = tsk->files;
15367 + struct fdtable *fdt;
15368 + const unsigned long *bptr;
15369 + int count, total;
15371 + /* no rcu_read_lock() because of spin_lock() */
15372 + spin_lock(&files->file_lock);
15373 + fdt = files_fdtable(files);
15374 + bptr = fdt->open_fds;
15375 + count = fdt->max_fds / (sizeof(unsigned long) * 8);
15376 + for (total = 0; count > 0; count--) {
15378 + total += hweight_long(*bptr);
15381 + spin_unlock(&files->file_lock);
15386 +/* for *space compatibility */
15388 +asmlinkage long sys_unshare(unsigned long);
15391 + * migrate task to new context
15392 + * gets vxi, puts old_vxi on change
15393 + * optionally unshares namespaces (hack)
15396 +int vx_migrate_task(struct task_struct *p, struct vx_info *vxi, int unshare)
15398 + struct vx_info *old_vxi;
15404 + vxdprintk(VXD_CBIT(xid, 5),
15405 + "vx_migrate_task(%p,%p[#%d.%d])", p, vxi,
15406 + vxi->vx_id, atomic_read(&vxi->vx_usecnt));
15408 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0) &&
15409 + !vx_info_flags(vxi, VXF_STATE_SETUP, 0))
15412 + if (vx_info_state(vxi, VXS_SHUTDOWN))
15415 + old_vxi = task_get_vx_info(p);
15416 + if (old_vxi == vxi)
15419 +// if (!(ret = vx_migrate_user(p, vxi))) {
15424 + openfd = vx_openfd_task(p);
15427 + atomic_dec(&old_vxi->cvirt.nr_threads);
15428 + atomic_dec(&old_vxi->cvirt.nr_running);
15429 + __rlim_dec(&old_vxi->limit, RLIMIT_NPROC);
15430 + /* FIXME: what about the struct files here? */
15431 + __rlim_sub(&old_vxi->limit, VLIMIT_OPENFD, openfd);
15432 + /* account for the executable */
15433 + __rlim_dec(&old_vxi->limit, VLIMIT_DENTRY);
15435 + atomic_inc(&vxi->cvirt.nr_threads);
15436 + atomic_inc(&vxi->cvirt.nr_running);
15437 + __rlim_inc(&vxi->limit, RLIMIT_NPROC);
15438 + /* FIXME: what about the struct files here? */
15439 + __rlim_add(&vxi->limit, VLIMIT_OPENFD, openfd);
15440 + /* account for the executable */
15441 + __rlim_inc(&vxi->limit, VLIMIT_DENTRY);
15444 + release_vx_info(old_vxi, p);
15445 + clr_vx_info(&p->vx_info);
15447 + claim_vx_info(vxi, p);
15448 + set_vx_info(&p->vx_info, vxi);
15449 + p->xid = vxi->vx_id;
15451 + vxdprintk(VXD_CBIT(xid, 5),
15452 + "moved task %p into vxi:%p[#%d]",
15453 + p, vxi, vxi->vx_id);
15455 + // vx_mask_cap_bset(vxi, p);
15458 + /* hack for *spaces to provide compatibility */
15460 + struct nsproxy *old_nsp, *new_nsp;
15462 + ret = unshare_nsproxy_namespaces(
15463 + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER,
15464 + &new_nsp, NULL, NULL);
15468 + old_nsp = xchg(&p->nsproxy, new_nsp);
15469 + vx_set_space(vxi,
15470 + CLONE_NEWUTS | CLONE_NEWIPC | CLONE_NEWUSER, 0);
15471 + put_nsproxy(old_nsp);
15475 + put_vx_info(old_vxi);
15479 +int vx_set_reaper(struct vx_info *vxi, struct task_struct *p)
15481 + struct task_struct *old_reaper;
15482 + struct vx_info *reaper_vxi;
15487 + vxdprintk(VXD_CBIT(xid, 6),
15488 + "vx_set_reaper(%p[#%d],%p[#%d,%d])",
15489 + vxi, vxi->vx_id, p, p->xid, p->pid);
15491 + old_reaper = vxi->vx_reaper;
15492 + if (old_reaper == p)
15495 + reaper_vxi = task_get_vx_info(p);
15496 + if (reaper_vxi && reaper_vxi != vxi) {
15498 + "Unsuitable reaper [" VS_Q("%s") ",%u:#%u] "
15500 + p->comm, p->pid, p->xid, vx_current_xid());
15504 + /* set new child reaper */
15505 + get_task_struct(p);
15506 + vxi->vx_reaper = p;
15507 + put_task_struct(old_reaper);
15509 + put_vx_info(reaper_vxi);
15513 +int vx_set_init(struct vx_info *vxi, struct task_struct *p)
15518 + vxdprintk(VXD_CBIT(xid, 6),
15519 + "vx_set_init(%p[#%d],%p[#%d,%d,%d])",
15520 + vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15522 + vxi->vx_flags &= ~VXF_STATE_INIT;
15523 + // vxi->vx_initpid = p->tgid;
15524 + vxi->vx_initpid = p->pid;
15528 +void vx_exit_init(struct vx_info *vxi, struct task_struct *p, int code)
15530 + vxdprintk(VXD_CBIT(xid, 6),
15531 + "vx_exit_init(%p[#%d],%p[#%d,%d,%d])",
15532 + vxi, vxi->vx_id, p, p->xid, p->pid, p->tgid);
15534 + vxi->exit_code = code;
15535 + vxi->vx_initpid = 0;
15539 +void vx_set_persistent(struct vx_info *vxi)
15541 + vxdprintk(VXD_CBIT(xid, 6),
15542 + "vx_set_persistent(%p[#%d])", vxi, vxi->vx_id);
15544 + get_vx_info(vxi);
15545 + claim_vx_info(vxi, NULL);
15548 +void vx_clear_persistent(struct vx_info *vxi)
15550 + vxdprintk(VXD_CBIT(xid, 6),
15551 + "vx_clear_persistent(%p[#%d])", vxi, vxi->vx_id);
15553 + release_vx_info(vxi, NULL);
15554 + put_vx_info(vxi);
15557 +void vx_update_persistent(struct vx_info *vxi)
15559 + if (vx_info_flags(vxi, VXF_PERSISTENT, 0))
15560 + vx_set_persistent(vxi);
15562 + vx_clear_persistent(vxi);
15566 +/* task must be current or locked */
15568 +void exit_vx_info(struct task_struct *p, int code)
15570 + struct vx_info *vxi = p->vx_info;
15573 + atomic_dec(&vxi->cvirt.nr_threads);
15576 + vxi->exit_code = code;
15577 + release_vx_info(vxi, p);
15581 +void exit_vx_info_early(struct task_struct *p, int code)
15583 + struct vx_info *vxi = p->vx_info;
15586 + if (vxi->vx_initpid == p->pid)
15587 + vx_exit_init(vxi, p, code);
15588 + if (vxi->vx_reaper == p)
15589 + vx_set_reaper(vxi, init_pid_ns.child_reaper);
15594 +/* vserver syscall commands below here */
15596 +/* taks xid and vx_info functions */
15598 +#include <asm/uaccess.h>
15601 +int vc_task_xid(uint32_t id)
15606 + struct task_struct *tsk;
15609 + tsk = find_task_by_real_pid(id);
15610 + xid = (tsk) ? tsk->xid : -ESRCH;
15611 + rcu_read_unlock();
15613 + xid = vx_current_xid();
15618 +int vc_vx_info(struct vx_info *vxi, void __user *data)
15620 + struct vcmd_vx_info_v0 vc_data;
15622 + vc_data.xid = vxi->vx_id;
15623 + vc_data.initpid = vxi->vx_initpid;
15625 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15631 +int vc_ctx_stat(struct vx_info *vxi, void __user *data)
15633 + struct vcmd_ctx_stat_v0 vc_data;
15635 + vc_data.usecnt = atomic_read(&vxi->vx_usecnt);
15636 + vc_data.tasks = atomic_read(&vxi->vx_tasks);
15638 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15644 +/* context functions */
15646 +int vc_ctx_create(uint32_t xid, void __user *data)
15648 + struct vcmd_ctx_create vc_data = { .flagword = VXF_INIT_SET };
15649 + struct vx_info *new_vxi;
15652 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15655 + if ((xid > MAX_S_CONTEXT) || (xid < 2))
15658 + new_vxi = __create_vx_info(xid);
15659 + if (IS_ERR(new_vxi))
15660 + return PTR_ERR(new_vxi);
15662 + /* initial flags */
15663 + new_vxi->vx_flags = vc_data.flagword;
15666 + if (vs_state_change(new_vxi, VSC_STARTUP))
15669 + ret = vx_migrate_task(current, new_vxi, (!data));
15673 + /* return context id on success */
15674 + ret = new_vxi->vx_id;
15676 + /* get a reference for persistent contexts */
15677 + if ((vc_data.flagword & VXF_PERSISTENT))
15678 + vx_set_persistent(new_vxi);
15680 + release_vx_info(new_vxi, NULL);
15681 + put_vx_info(new_vxi);
15686 +int vc_ctx_migrate(struct vx_info *vxi, void __user *data)
15688 + struct vcmd_ctx_migrate vc_data = { .flagword = 0 };
15691 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
15694 + ret = vx_migrate_task(current, vxi, 0);
15697 + if (vc_data.flagword & VXM_SET_INIT)
15698 + ret = vx_set_init(vxi, current);
15701 + if (vc_data.flagword & VXM_SET_REAPER)
15702 + ret = vx_set_reaper(vxi, current);
15707 +int vc_get_cflags(struct vx_info *vxi, void __user *data)
15709 + struct vcmd_ctx_flags_v0 vc_data;
15711 + vc_data.flagword = vxi->vx_flags;
15713 + /* special STATE flag handling */
15714 + vc_data.mask = vs_mask_flags(~0ULL, vxi->vx_flags, VXF_ONE_TIME);
15716 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15721 +int vc_set_cflags(struct vx_info *vxi, void __user *data)
15723 + struct vcmd_ctx_flags_v0 vc_data;
15724 + uint64_t mask, trigger;
15726 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15729 + /* special STATE flag handling */
15730 + mask = vs_mask_mask(vc_data.mask, vxi->vx_flags, VXF_ONE_TIME);
15731 + trigger = (mask & vxi->vx_flags) ^ (mask & vc_data.flagword);
15733 + if (vxi == current_vx_info()) {
15734 + /* if (trigger & VXF_STATE_SETUP)
15735 + vx_mask_cap_bset(vxi, current); */
15736 + if (trigger & VXF_STATE_INIT) {
15739 + ret = vx_set_init(vxi, current);
15742 + ret = vx_set_reaper(vxi, current);
15748 + vxi->vx_flags = vs_mask_flags(vxi->vx_flags,
15749 + vc_data.flagword, mask);
15750 + if (trigger & VXF_PERSISTENT)
15751 + vx_update_persistent(vxi);
15757 +static inline uint64_t caps_from_cap_t(kernel_cap_t c)
15759 + uint64_t v = c.cap[0] | ((uint64_t)c.cap[1] << 32);
15761 + // printk("caps_from_cap_t(%08x:%08x) = %016llx\n", c.cap[1], c.cap[0], v);
15765 +static inline kernel_cap_t cap_t_from_caps(uint64_t v)
15767 + kernel_cap_t c = __cap_empty_set;
15769 + c.cap[0] = v & 0xFFFFFFFF;
15770 + c.cap[1] = (v >> 32) & 0xFFFFFFFF;
15772 + // printk("cap_t_from_caps(%016llx) = %08x:%08x\n", v, c.cap[1], c.cap[0]);
15777 +static int do_get_caps(struct vx_info *vxi, uint64_t *bcaps, uint64_t *ccaps)
15780 + *bcaps = caps_from_cap_t(vxi->vx_bcaps);
15782 + *ccaps = vxi->vx_ccaps;
15787 +int vc_get_ccaps(struct vx_info *vxi, void __user *data)
15789 + struct vcmd_ctx_caps_v1 vc_data;
15792 + ret = do_get_caps(vxi, NULL, &vc_data.ccaps);
15795 + vc_data.cmask = ~0ULL;
15797 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15802 +static int do_set_caps(struct vx_info *vxi,
15803 + uint64_t bcaps, uint64_t bmask, uint64_t ccaps, uint64_t cmask)
15805 + uint64_t bcold = caps_from_cap_t(vxi->vx_bcaps);
15808 + printk("do_set_caps(%16llx, %16llx, %16llx, %16llx)\n",
15809 + bcaps, bmask, ccaps, cmask);
15811 + vxi->vx_bcaps = cap_t_from_caps(
15812 + vs_mask_flags(bcold, bcaps, bmask));
15813 + vxi->vx_ccaps = vs_mask_flags(vxi->vx_ccaps, ccaps, cmask);
15818 +int vc_set_ccaps(struct vx_info *vxi, void __user *data)
15820 + struct vcmd_ctx_caps_v1 vc_data;
15822 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15825 + return do_set_caps(vxi, 0, 0, vc_data.ccaps, vc_data.cmask);
15828 +int vc_get_bcaps(struct vx_info *vxi, void __user *data)
15830 + struct vcmd_bcaps vc_data;
15833 + ret = do_get_caps(vxi, &vc_data.bcaps, NULL);
15836 + vc_data.bmask = ~0ULL;
15838 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15843 +int vc_set_bcaps(struct vx_info *vxi, void __user *data)
15845 + struct vcmd_bcaps vc_data;
15847 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15850 + return do_set_caps(vxi, vc_data.bcaps, vc_data.bmask, 0, 0);
15854 +int vc_get_umask(struct vx_info *vxi, void __user *data)
15856 + struct vcmd_umask vc_data;
15858 + vc_data.umask = vxi->vx_umask;
15859 + vc_data.mask = ~0ULL;
15861 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15866 +int vc_set_umask(struct vx_info *vxi, void __user *data)
15868 + struct vcmd_umask vc_data;
15870 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15873 + vxi->vx_umask = vs_mask_flags(vxi->vx_umask,
15874 + vc_data.umask, vc_data.mask);
15879 +int vc_get_wmask(struct vx_info *vxi, void __user *data)
15881 + struct vcmd_wmask vc_data;
15883 + vc_data.wmask = vxi->vx_wmask;
15884 + vc_data.mask = ~0ULL;
15886 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15891 +int vc_set_wmask(struct vx_info *vxi, void __user *data)
15893 + struct vcmd_wmask vc_data;
15895 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15898 + vxi->vx_wmask = vs_mask_flags(vxi->vx_wmask,
15899 + vc_data.wmask, vc_data.mask);
15904 +int vc_get_badness(struct vx_info *vxi, void __user *data)
15906 + struct vcmd_badness_v0 vc_data;
15908 + vc_data.bias = vxi->vx_badness_bias;
15910 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
15915 +int vc_set_badness(struct vx_info *vxi, void __user *data)
15917 + struct vcmd_badness_v0 vc_data;
15919 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
15922 + vxi->vx_badness_bias = vc_data.bias;
15926 +#include <linux/module.h>
15928 +EXPORT_SYMBOL_GPL(free_vx_info);
15930 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cvirt.c linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt.c
15931 --- linux-3.13.10/kernel/vserver/cvirt.c 1970-01-01 00:00:00.000000000 +0000
15932 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt.c 2014-01-31 20:38:04.000000000 +0000
15935 + * linux/kernel/vserver/cvirt.c
15937 + * Virtual Server: Context Virtualization
15939 + * Copyright (C) 2004-2007 Herbert Pötzl
15941 + * V0.01 broken out from limit.c
15942 + * V0.02 added utsname stuff
15943 + * V0.03 changed vcmds to vxi arg
15947 +#include <linux/types.h>
15948 +#include <linux/utsname.h>
15949 +#include <linux/vs_cvirt.h>
15950 +#include <linux/vserver/switch.h>
15951 +#include <linux/vserver/cvirt_cmd.h>
15953 +#include <asm/uaccess.h>
15956 +void vx_vsi_boottime(struct timespec *boottime)
15958 + struct vx_info *vxi = current_vx_info();
15960 + set_normalized_timespec(boottime,
15961 + boottime->tv_sec + vxi->cvirt.bias_uptime.tv_sec,
15962 + boottime->tv_nsec + vxi->cvirt.bias_uptime.tv_nsec);
15966 +void vx_vsi_uptime(struct timespec *uptime, struct timespec *idle)
15968 + struct vx_info *vxi = current_vx_info();
15970 + set_normalized_timespec(uptime,
15971 + uptime->tv_sec - vxi->cvirt.bias_uptime.tv_sec,
15972 + uptime->tv_nsec - vxi->cvirt.bias_uptime.tv_nsec);
15975 + set_normalized_timespec(idle,
15976 + idle->tv_sec - vxi->cvirt.bias_idle.tv_sec,
15977 + idle->tv_nsec - vxi->cvirt.bias_idle.tv_nsec);
15981 +uint64_t vx_idle_jiffies(void)
15983 + return init_task.utime + init_task.stime;
15988 +static inline uint32_t __update_loadavg(uint32_t load,
15989 + int wsize, int delta, int n)
15991 + unsigned long long calc, prev;
15993 + /* just set it to n */
15994 + if (unlikely(delta >= wsize))
15995 + return (n << FSHIFT);
15997 + calc = delta * n;
15999 + prev = (wsize - delta);
16002 + do_div(calc, wsize);
16007 +void vx_update_load(struct vx_info *vxi)
16009 + uint32_t now, last, delta;
16010 + unsigned int nr_running, nr_uninterruptible;
16011 + unsigned int total;
16012 + unsigned long flags;
16014 + spin_lock_irqsave(&vxi->cvirt.load_lock, flags);
16017 + last = vxi->cvirt.load_last;
16018 + delta = now - last;
16020 + if (delta < 5*HZ)
16023 + nr_running = atomic_read(&vxi->cvirt.nr_running);
16024 + nr_uninterruptible = atomic_read(&vxi->cvirt.nr_uninterruptible);
16025 + total = nr_running + nr_uninterruptible;
16027 + vxi->cvirt.load[0] = __update_loadavg(vxi->cvirt.load[0],
16028 + 60*HZ, delta, total);
16029 + vxi->cvirt.load[1] = __update_loadavg(vxi->cvirt.load[1],
16030 + 5*60*HZ, delta, total);
16031 + vxi->cvirt.load[2] = __update_loadavg(vxi->cvirt.load[2],
16032 + 15*60*HZ, delta, total);
16034 + vxi->cvirt.load_last = now;
16036 + atomic_inc(&vxi->cvirt.load_updates);
16037 + spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags);
16042 + * Commands to do_syslog:
16044 + * 0 -- Close the log. Currently a NOP.
16045 + * 1 -- Open the log. Currently a NOP.
16046 + * 2 -- Read from the log.
16047 + * 3 -- Read all messages remaining in the ring buffer.
16048 + * 4 -- Read and clear all messages remaining in the ring buffer
16049 + * 5 -- Clear ring buffer.
16050 + * 6 -- Disable printk's to console
16051 + * 7 -- Enable printk's to console
16052 + * 8 -- Set level of messages printed to console
16053 + * 9 -- Return number of unread characters in the log buffer
16054 + * 10 -- Return size of the log buffer
16056 +int vx_do_syslog(int type, char __user *buf, int len)
16059 + int do_clear = 0;
16060 + struct vx_info *vxi = current_vx_info();
16061 + struct _vx_syslog *log;
16065 + log = &vxi->cvirt.syslog;
16068 + case 0: /* Close log */
16069 + case 1: /* Open log */
16071 + case 2: /* Read from log */
16072 + error = wait_event_interruptible(log->log_wait,
16073 + (log->log_start - log->log_end));
16076 + spin_lock_irq(&log->logbuf_lock);
16077 + spin_unlock_irq(&log->logbuf_lock);
16079 + case 4: /* Read/clear last kernel messages */
16081 + /* fall through */
16082 + case 3: /* Read last kernel messages */
16085 + case 5: /* Clear ring buffer */
16088 + case 6: /* Disable logging to console */
16089 + case 7: /* Enable logging to console */
16090 + case 8: /* Set level of messages printed to console */
16093 + case 9: /* Number of chars in the log buffer */
16095 + case 10: /* Size of the log buffer */
16105 +/* virtual host info names */
16107 +static char *vx_vhi_name(struct vx_info *vxi, int id)
16109 + struct nsproxy *nsproxy;
16110 + struct uts_namespace *uts;
16112 + if (id == VHIN_CONTEXT)
16113 + return vxi->vx_name;
16115 + nsproxy = vxi->space[0].vx_nsproxy;
16119 + uts = nsproxy->uts_ns;
16124 + case VHIN_SYSNAME:
16125 + return uts->name.sysname;
16126 + case VHIN_NODENAME:
16127 + return uts->name.nodename;
16128 + case VHIN_RELEASE:
16129 + return uts->name.release;
16130 + case VHIN_VERSION:
16131 + return uts->name.version;
16132 + case VHIN_MACHINE:
16133 + return uts->name.machine;
16134 + case VHIN_DOMAINNAME:
16135 + return uts->name.domainname;
16142 +int vc_set_vhi_name(struct vx_info *vxi, void __user *data)
16144 + struct vcmd_vhi_name_v0 vc_data;
16147 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16150 + name = vx_vhi_name(vxi, vc_data.field);
16154 + memcpy(name, vc_data.name, 65);
16158 +int vc_get_vhi_name(struct vx_info *vxi, void __user *data)
16160 + struct vcmd_vhi_name_v0 vc_data;
16163 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16166 + name = vx_vhi_name(vxi, vc_data.field);
16170 + memcpy(vc_data.name, name, 65);
16171 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16177 +int vc_virt_stat(struct vx_info *vxi, void __user *data)
16179 + struct vcmd_virt_stat_v0 vc_data;
16180 + struct _vx_cvirt *cvirt = &vxi->cvirt;
16181 + struct timespec uptime;
16183 + do_posix_clock_monotonic_gettime(&uptime);
16184 + set_normalized_timespec(&uptime,
16185 + uptime.tv_sec - cvirt->bias_uptime.tv_sec,
16186 + uptime.tv_nsec - cvirt->bias_uptime.tv_nsec);
16188 + vc_data.offset = timespec_to_ns(&cvirt->bias_ts);
16189 + vc_data.uptime = timespec_to_ns(&uptime);
16190 + vc_data.nr_threads = atomic_read(&cvirt->nr_threads);
16191 + vc_data.nr_running = atomic_read(&cvirt->nr_running);
16192 + vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible);
16193 + vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold);
16194 + vc_data.nr_forks = atomic_read(&cvirt->total_forks);
16195 + vc_data.load[0] = cvirt->load[0];
16196 + vc_data.load[1] = cvirt->load[1];
16197 + vc_data.load[2] = cvirt->load[2];
16199 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
16205 +#ifdef CONFIG_VSERVER_VTIME
16207 +/* virtualized time base */
16209 +void vx_adjust_timespec(struct timespec *ts)
16211 + struct vx_info *vxi;
16213 + if (!vx_flags(VXF_VIRT_TIME, 0))
16216 + vxi = current_vx_info();
16217 + ts->tv_sec += vxi->cvirt.bias_ts.tv_sec;
16218 + ts->tv_nsec += vxi->cvirt.bias_ts.tv_nsec;
16220 + if (ts->tv_nsec >= NSEC_PER_SEC) {
16222 + ts->tv_nsec -= NSEC_PER_SEC;
16223 + } else if (ts->tv_nsec < 0) {
16225 + ts->tv_nsec += NSEC_PER_SEC;
16229 +int vx_settimeofday(const struct timespec *ts)
16231 + struct timespec ats, delta;
16232 + struct vx_info *vxi;
16234 + if (!vx_flags(VXF_VIRT_TIME, 0))
16235 + return do_settimeofday(ts);
16237 + getnstimeofday(&ats);
16238 + delta = timespec_sub(*ts, ats);
16240 + vxi = current_vx_info();
16241 + vxi->cvirt.bias_ts = timespec_add(vxi->cvirt.bias_ts, delta);
16247 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cvirt_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_init.h
16248 --- linux-3.13.10/kernel/vserver/cvirt_init.h 1970-01-01 00:00:00.000000000 +0000
16249 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_init.h 2014-01-31 20:38:04.000000000 +0000
16253 +extern uint64_t vx_idle_jiffies(void);
16255 +static inline void vx_info_init_cvirt(struct _vx_cvirt *cvirt)
16257 + uint64_t idle_jiffies = vx_idle_jiffies();
16258 + uint64_t nsuptime;
16260 + do_posix_clock_monotonic_gettime(&cvirt->bias_uptime);
16261 + nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
16262 + * NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
16263 + cvirt->bias_clock = nsec_to_clock_t(nsuptime);
16264 + cvirt->bias_ts.tv_sec = 0;
16265 + cvirt->bias_ts.tv_nsec = 0;
16267 + jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
16268 + atomic_set(&cvirt->nr_threads, 0);
16269 + atomic_set(&cvirt->nr_running, 0);
16270 + atomic_set(&cvirt->nr_uninterruptible, 0);
16271 + atomic_set(&cvirt->nr_onhold, 0);
16273 + spin_lock_init(&cvirt->load_lock);
16274 + cvirt->load_last = jiffies;
16275 + atomic_set(&cvirt->load_updates, 0);
16276 + cvirt->load[0] = 0;
16277 + cvirt->load[1] = 0;
16278 + cvirt->load[2] = 0;
16279 + atomic_set(&cvirt->total_forks, 0);
16281 + spin_lock_init(&cvirt->syslog.logbuf_lock);
16282 + init_waitqueue_head(&cvirt->syslog.log_wait);
16283 + cvirt->syslog.log_start = 0;
16284 + cvirt->syslog.log_end = 0;
16285 + cvirt->syslog.con_start = 0;
16286 + cvirt->syslog.logged_chars = 0;
16290 +void vx_info_init_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16292 + // cvirt_pc->cpustat = { 0 };
16295 +static inline void vx_info_exit_cvirt(struct _vx_cvirt *cvirt)
16297 +#ifdef CONFIG_VSERVER_WARN
16300 + vxwprintk_xid((value = atomic_read(&cvirt->nr_threads)),
16301 + "!!! cvirt: %p[nr_threads] = %d on exit.",
16303 + vxwprintk_xid((value = atomic_read(&cvirt->nr_running)),
16304 + "!!! cvirt: %p[nr_running] = %d on exit.",
16306 + vxwprintk_xid((value = atomic_read(&cvirt->nr_uninterruptible)),
16307 + "!!! cvirt: %p[nr_uninterruptible] = %d on exit.",
16309 + vxwprintk_xid((value = atomic_read(&cvirt->nr_onhold)),
16310 + "!!! cvirt: %p[nr_onhold] = %d on exit.",
16316 +void vx_info_exit_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc, int cpu)
16321 diff -NurpP --minimal linux-3.13.10/kernel/vserver/cvirt_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_proc.h
16322 --- linux-3.13.10/kernel/vserver/cvirt_proc.h 1970-01-01 00:00:00.000000000 +0000
16323 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/cvirt_proc.h 2014-01-31 20:38:04.000000000 +0000
16325 +#ifndef _VX_CVIRT_PROC_H
16326 +#define _VX_CVIRT_PROC_H
16328 +#include <linux/nsproxy.h>
16329 +#include <linux/mnt_namespace.h>
16330 +#include <linux/ipc_namespace.h>
16331 +#include <linux/utsname.h>
16332 +#include <linux/ipc.h>
16334 +extern int vx_info_mnt_namespace(struct mnt_namespace *, char *);
16337 +int vx_info_proc_nsproxy(struct nsproxy *nsproxy, char *buffer)
16339 + struct mnt_namespace *ns;
16340 + struct uts_namespace *uts;
16341 + struct ipc_namespace *ipc;
16347 + length += sprintf(buffer + length,
16348 + "NSProxy:\t%p [%p,%p,%p]\n",
16349 + nsproxy, nsproxy->mnt_ns,
16350 + nsproxy->uts_ns, nsproxy->ipc_ns);
16352 + ns = nsproxy->mnt_ns;
16356 + length += vx_info_mnt_namespace(ns, buffer + length);
16360 + uts = nsproxy->uts_ns;
16364 + length += sprintf(buffer + length,
16365 + "SysName:\t%.*s\n"
16366 + "NodeName:\t%.*s\n"
16367 + "Release:\t%.*s\n"
16368 + "Version:\t%.*s\n"
16369 + "Machine:\t%.*s\n"
16370 + "DomainName:\t%.*s\n",
16371 + __NEW_UTS_LEN, uts->name.sysname,
16372 + __NEW_UTS_LEN, uts->name.nodename,
16373 + __NEW_UTS_LEN, uts->name.release,
16374 + __NEW_UTS_LEN, uts->name.version,
16375 + __NEW_UTS_LEN, uts->name.machine,
16376 + __NEW_UTS_LEN, uts->name.domainname);
16379 + ipc = nsproxy->ipc_ns;
16383 + length += sprintf(buffer + length,
16384 + "SEMS:\t\t%d %d %d %d %d\n"
16385 + "MSG:\t\t%d %d %d\n"
16386 + "SHM:\t\t%lu %lu %d %ld\n",
16387 + ipc->sem_ctls[0], ipc->sem_ctls[1],
16388 + ipc->sem_ctls[2], ipc->sem_ctls[3],
16390 + ipc->msg_ctlmax, ipc->msg_ctlmnb, ipc->msg_ctlmni,
16391 + (unsigned long)ipc->shm_ctlmax,
16392 + (unsigned long)ipc->shm_ctlall,
16393 + ipc->shm_ctlmni, ipc->shm_tot);
16400 +#include <linux/sched.h>
16402 +#define LOAD_INT(x) ((x) >> FSHIFT)
16403 +#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1 - 1)) * 100)
16406 +int vx_info_proc_cvirt(struct _vx_cvirt *cvirt, char *buffer)
16411 + length += sprintf(buffer + length,
16412 + "BiasUptime:\t%lu.%02lu\n",
16413 + (unsigned long)cvirt->bias_uptime.tv_sec,
16414 + (cvirt->bias_uptime.tv_nsec / (NSEC_PER_SEC / 100)));
16416 + a = cvirt->load[0] + (FIXED_1 / 200);
16417 + b = cvirt->load[1] + (FIXED_1 / 200);
16418 + c = cvirt->load[2] + (FIXED_1 / 200);
16419 + length += sprintf(buffer + length,
16420 + "nr_threads:\t%d\n"
16421 + "nr_running:\t%d\n"
16422 + "nr_unintr:\t%d\n"
16423 + "nr_onhold:\t%d\n"
16424 + "load_updates:\t%d\n"
16425 + "loadavg:\t%d.%02d %d.%02d %d.%02d\n"
16426 + "total_forks:\t%d\n",
16427 + atomic_read(&cvirt->nr_threads),
16428 + atomic_read(&cvirt->nr_running),
16429 + atomic_read(&cvirt->nr_uninterruptible),
16430 + atomic_read(&cvirt->nr_onhold),
16431 + atomic_read(&cvirt->load_updates),
16432 + LOAD_INT(a), LOAD_FRAC(a),
16433 + LOAD_INT(b), LOAD_FRAC(b),
16434 + LOAD_INT(c), LOAD_FRAC(c),
16435 + atomic_read(&cvirt->total_forks));
16440 +int vx_info_proc_cvirt_pc(struct _vx_cvirt_pc *cvirt_pc,
16441 + char *buffer, int cpu)
16447 +#endif /* _VX_CVIRT_PROC_H */
16448 diff -NurpP --minimal linux-3.13.10/kernel/vserver/debug.c linux-3.13.10-vs2.3.6.11/kernel/vserver/debug.c
16449 --- linux-3.13.10/kernel/vserver/debug.c 1970-01-01 00:00:00.000000000 +0000
16450 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/debug.c 2014-01-31 20:38:04.000000000 +0000
16453 + * kernel/vserver/debug.c
16455 + * Copyright (C) 2005-2007 Herbert Pötzl
16457 + * V0.01 vx_info dump support
16461 +#include <linux/module.h>
16463 +#include <linux/vserver/context.h>
16466 +void dump_vx_info(struct vx_info *vxi, int level)
16468 + printk("vx_info %p[#%d, %d.%d, %4x]\n", vxi, vxi->vx_id,
16469 + atomic_read(&vxi->vx_usecnt),
16470 + atomic_read(&vxi->vx_tasks),
16473 + __dump_vx_limit(&vxi->limit);
16474 + __dump_vx_sched(&vxi->sched);
16475 + __dump_vx_cvirt(&vxi->cvirt);
16476 + __dump_vx_cacct(&vxi->cacct);
16482 +EXPORT_SYMBOL_GPL(dump_vx_info);
16484 diff -NurpP --minimal linux-3.13.10/kernel/vserver/device.c linux-3.13.10-vs2.3.6.11/kernel/vserver/device.c
16485 --- linux-3.13.10/kernel/vserver/device.c 1970-01-01 00:00:00.000000000 +0000
16486 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/device.c 2014-01-31 20:38:04.000000000 +0000
16489 + * linux/kernel/vserver/device.c
16491 + * Linux-VServer: Device Support
16493 + * Copyright (C) 2006 Herbert Pötzl
16494 + * Copyright (C) 2007 Daniel Hokka Zakrisson
16496 + * V0.01 device mapping basics
16497 + * V0.02 added defaults
16501 +#include <linux/slab.h>
16502 +#include <linux/rcupdate.h>
16503 +#include <linux/fs.h>
16504 +#include <linux/namei.h>
16505 +#include <linux/hash.h>
16507 +#include <asm/errno.h>
16508 +#include <asm/uaccess.h>
16509 +#include <linux/vserver/base.h>
16510 +#include <linux/vserver/debug.h>
16511 +#include <linux/vserver/context.h>
16512 +#include <linux/vserver/device.h>
16513 +#include <linux/vserver/device_cmd.h>
16516 +#define DMAP_HASH_BITS 4
16519 +struct vs_mapping {
16521 + struct hlist_node hlist;
16522 + struct list_head list;
16524 +#define dm_hlist u.hlist
16525 +#define dm_list u.list
16528 + struct vx_dmap_target target;
16532 +static struct hlist_head dmap_main_hash[1 << DMAP_HASH_BITS];
16534 +static DEFINE_SPINLOCK(dmap_main_hash_lock);
16536 +static struct vx_dmap_target dmap_defaults[2] = {
16537 + { .flags = DATTR_OPEN },
16538 + { .flags = DATTR_OPEN },
16542 +struct kmem_cache *dmap_cachep __read_mostly;
16544 +int __init dmap_cache_init(void)
16546 + dmap_cachep = kmem_cache_create("dmap_cache",
16547 + sizeof(struct vs_mapping), 0,
16548 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
16552 +__initcall(dmap_cache_init);
16555 +static inline unsigned int __hashval(dev_t dev, int bits)
16557 + return hash_long((unsigned long)dev, bits);
16561 +/* __hash_mapping()
16562 + * add the mapping to the hash table
16564 +static inline void __hash_mapping(struct vx_info *vxi, struct vs_mapping *vdm)
16566 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16567 + struct hlist_head *head, *hash = dmap_main_hash;
16568 + int device = vdm->device;
16570 + spin_lock(hash_lock);
16571 + vxdprintk(VXD_CBIT(misc, 8), "__hash_mapping: %p[#%d] %08x:%08x",
16572 + vxi, vxi ? vxi->vx_id : 0, device, vdm->target.target);
16574 + head = &hash[__hashval(device, DMAP_HASH_BITS)];
16575 + hlist_add_head(&vdm->dm_hlist, head);
16576 + spin_unlock(hash_lock);
16580 +static inline int __mode_to_default(umode_t mode)
16593 +/* __set_default()
16596 +static inline void __set_default(struct vx_info *vxi, umode_t mode,
16597 + struct vx_dmap_target *vdmt)
16599 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16600 + spin_lock(hash_lock);
16603 + vxi->dmap.targets[__mode_to_default(mode)] = *vdmt;
16605 + dmap_defaults[__mode_to_default(mode)] = *vdmt;
16608 + spin_unlock(hash_lock);
16610 + vxdprintk(VXD_CBIT(misc, 8), "__set_default: %p[#%u] %08x %04x",
16611 + vxi, vxi ? vxi->vx_id : 0, vdmt->target, vdmt->flags);
16615 +/* __remove_default()
16616 + * remove a default
16618 +static inline int __remove_default(struct vx_info *vxi, umode_t mode)
16620 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16621 + spin_lock(hash_lock);
16624 + vxi->dmap.targets[__mode_to_default(mode)].flags = 0;
16625 + else /* remove == reset */
16626 + dmap_defaults[__mode_to_default(mode)].flags = DATTR_OPEN | mode;
16628 + spin_unlock(hash_lock);
16633 +/* __find_mapping()
16634 + * find a mapping in the hash table
16636 + * caller must hold hash_lock
16638 +static inline int __find_mapping(vxid_t xid, dev_t device, umode_t mode,
16639 + struct vs_mapping **local, struct vs_mapping **global)
16641 + struct hlist_head *hash = dmap_main_hash;
16642 + struct hlist_head *head = &hash[__hashval(device, DMAP_HASH_BITS)];
16643 + struct hlist_node *pos;
16644 + struct vs_mapping *vdm;
16650 + hlist_for_each(pos, head) {
16651 + vdm = hlist_entry(pos, struct vs_mapping, dm_hlist);
16653 + if ((vdm->device == device) &&
16654 + !((vdm->target.flags ^ mode) & S_IFMT)) {
16655 + if (vdm->xid == xid) {
16658 + } else if (global && vdm->xid == 0)
16663 + if (global && *global)
16670 +/* __lookup_mapping()
16671 + * find a mapping and store the result in target and flags
16673 +static inline int __lookup_mapping(struct vx_info *vxi,
16674 + dev_t device, dev_t *target, int *flags, umode_t mode)
16676 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16677 + struct vs_mapping *vdm, *global;
16678 + struct vx_dmap_target *vdmt;
16680 + vxid_t xid = vxi->vx_id;
16683 + spin_lock(hash_lock);
16684 + if (__find_mapping(xid, device, mode, &vdm, &global) > 0) {
16686 + vdmt = &vdm->target;
16690 + index = __mode_to_default(mode);
16691 + if (vxi && vxi->dmap.targets[index].flags) {
16693 + vdmt = &vxi->dmap.targets[index];
16694 + } else if (global) {
16696 + vdmt = &global->target;
16700 + vdmt = &dmap_defaults[index];
16704 + if (target && (vdmt->flags & DATTR_REMAP))
16705 + *target = vdmt->target;
16707 + *target = device;
16709 + *flags = vdmt->flags;
16711 + spin_unlock(hash_lock);
16717 +/* __remove_mapping()
16718 + * remove a mapping from the hash table
16720 +static inline int __remove_mapping(struct vx_info *vxi, dev_t device,
16723 + spinlock_t *hash_lock = &dmap_main_hash_lock;
16724 + struct vs_mapping *vdm = NULL;
16727 + spin_lock(hash_lock);
16729 + ret = __find_mapping((vxi ? vxi->vx_id : 0), device, mode, &vdm,
16731 + vxdprintk(VXD_CBIT(misc, 8), "__remove_mapping: %p[#%d] %08x %04x",
16732 + vxi, vxi ? vxi->vx_id : 0, device, mode);
16735 + hlist_del(&vdm->dm_hlist);
16738 + spin_unlock(hash_lock);
16740 + kmem_cache_free(dmap_cachep, vdm);
16746 +int vs_map_device(struct vx_info *vxi,
16747 + dev_t device, dev_t *target, umode_t mode)
16749 + int ret, flags = DATTR_MASK;
16753 + *target = device;
16756 + ret = __lookup_mapping(vxi, device, target, &flags, mode);
16757 + vxdprintk(VXD_CBIT(misc, 8), "vs_map_device: %08x target: %08x flags: %04x mode: %04x mapped=%d",
16758 + device, target ? *target : 0, flags, mode, ret);
16760 + return (flags & DATTR_MASK);
16765 +static int do_set_mapping(struct vx_info *vxi,
16766 + dev_t device, dev_t target, int flags, umode_t mode)
16769 + struct vs_mapping *new;
16771 + new = kmem_cache_alloc(dmap_cachep, GFP_KERNEL);
16775 + INIT_HLIST_NODE(&new->dm_hlist);
16776 + new->device = device;
16777 + new->target.target = target;
16778 + new->target.flags = flags | mode;
16779 + new->xid = (vxi ? vxi->vx_id : 0);
16781 + vxdprintk(VXD_CBIT(misc, 8), "do_set_mapping: %08x target: %08x flags: %04x", device, target, flags);
16782 + __hash_mapping(vxi, new);
16784 + struct vx_dmap_target new = {
16785 + .target = target,
16786 + .flags = flags | mode,
16788 + __set_default(vxi, mode, &new);
16794 +static int do_unset_mapping(struct vx_info *vxi,
16795 + dev_t device, dev_t target, int flags, umode_t mode)
16797 + int ret = -EINVAL;
16800 + ret = __remove_mapping(vxi, device, mode);
16804 + ret = __remove_default(vxi, mode);
16814 +static inline int __user_device(const char __user *name, dev_t *dev,
16817 + struct nameidata nd;
16824 + ret = user_lpath(name, &nd.path);
16827 + if (nd.path.dentry->d_inode) {
16828 + *dev = nd.path.dentry->d_inode->i_rdev;
16829 + *mode = nd.path.dentry->d_inode->i_mode;
16831 + path_put(&nd.path);
16835 +static inline int __mapping_mode(dev_t device, dev_t target,
16836 + umode_t device_mode, umode_t target_mode, umode_t *mode)
16839 + *mode = device_mode & S_IFMT;
16841 + *mode = target_mode & S_IFMT;
16845 + /* if both given, device and target mode have to match */
16846 + if (device && target &&
16847 + ((device_mode ^ target_mode) & S_IFMT))
16853 +static inline int do_mapping(struct vx_info *vxi, const char __user *device_path,
16854 + const char __user *target_path, int flags, int set)
16856 + dev_t device = ~0, target = ~0;
16857 + umode_t device_mode = 0, target_mode = 0, mode;
16860 + ret = __user_device(device_path, &device, &device_mode);
16863 + ret = __user_device(target_path, &target, &target_mode);
16867 + ret = __mapping_mode(device, target,
16868 + device_mode, target_mode, &mode);
16873 + return do_set_mapping(vxi, device, target,
16876 + return do_unset_mapping(vxi, device, target,
16881 +int vc_set_mapping(struct vx_info *vxi, void __user *data)
16883 + struct vcmd_set_mapping_v0 vc_data;
16885 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16888 + return do_mapping(vxi, vc_data.device, vc_data.target,
16889 + vc_data.flags, 1);
16892 +int vc_unset_mapping(struct vx_info *vxi, void __user *data)
16894 + struct vcmd_set_mapping_v0 vc_data;
16896 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16899 + return do_mapping(vxi, vc_data.device, vc_data.target,
16900 + vc_data.flags, 0);
16904 +#ifdef CONFIG_COMPAT
16906 +int vc_set_mapping_x32(struct vx_info *vxi, void __user *data)
16908 + struct vcmd_set_mapping_v0_x32 vc_data;
16910 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16913 + return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16914 + compat_ptr(vc_data.target_ptr), vc_data.flags, 1);
16917 +int vc_unset_mapping_x32(struct vx_info *vxi, void __user *data)
16919 + struct vcmd_set_mapping_v0_x32 vc_data;
16921 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
16924 + return do_mapping(vxi, compat_ptr(vc_data.device_ptr),
16925 + compat_ptr(vc_data.target_ptr), vc_data.flags, 0);
16928 +#endif /* CONFIG_COMPAT */
16931 diff -NurpP --minimal linux-3.13.10/kernel/vserver/dlimit.c linux-3.13.10-vs2.3.6.11/kernel/vserver/dlimit.c
16932 --- linux-3.13.10/kernel/vserver/dlimit.c 1970-01-01 00:00:00.000000000 +0000
16933 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/dlimit.c 2014-01-31 20:38:04.000000000 +0000
16936 + * linux/kernel/vserver/dlimit.c
16938 + * Virtual Server: Context Disk Limits
16940 + * Copyright (C) 2004-2009 Herbert Pötzl
16942 + * V0.01 initial version
16943 + * V0.02 compat32 splitup
16944 + * V0.03 extended interface
16948 +#include <linux/statfs.h>
16949 +#include <linux/sched.h>
16950 +#include <linux/namei.h>
16951 +#include <linux/vs_tag.h>
16952 +#include <linux/vs_dlimit.h>
16953 +#include <linux/vserver/dlimit_cmd.h>
16954 +#include <linux/slab.h>
16955 +// #include <linux/gfp.h>
16957 +#include <asm/uaccess.h>
16959 +/* __alloc_dl_info()
16961 + * allocate an initialized dl_info struct
16962 + * doesn't make it visible (hash) */
16964 +static struct dl_info *__alloc_dl_info(struct super_block *sb, vtag_t tag)
16966 + struct dl_info *new = NULL;
16968 + vxdprintk(VXD_CBIT(dlim, 5),
16969 + "alloc_dl_info(%p,%d)*", sb, tag);
16971 + /* would this benefit from a slab cache? */
16972 + new = kmalloc(sizeof(struct dl_info), GFP_KERNEL);
16976 + memset(new, 0, sizeof(struct dl_info));
16977 + new->dl_tag = tag;
16979 + // INIT_RCU_HEAD(&new->dl_rcu);
16980 + INIT_HLIST_NODE(&new->dl_hlist);
16981 + spin_lock_init(&new->dl_lock);
16982 + atomic_set(&new->dl_refcnt, 0);
16983 + atomic_set(&new->dl_usecnt, 0);
16985 + /* rest of init goes here */
16987 + vxdprintk(VXD_CBIT(dlim, 4),
16988 + "alloc_dl_info(%p,%d) = %p", sb, tag, new);
16992 +/* __dealloc_dl_info()
16994 + * final disposal of dl_info */
16996 +static void __dealloc_dl_info(struct dl_info *dli)
16998 + vxdprintk(VXD_CBIT(dlim, 4),
16999 + "dealloc_dl_info(%p)", dli);
17001 + dli->dl_hlist.next = LIST_POISON1;
17002 + dli->dl_tag = -1;
17005 + BUG_ON(atomic_read(&dli->dl_usecnt));
17006 + BUG_ON(atomic_read(&dli->dl_refcnt));
17012 +/* hash table for dl_info hash */
17014 +#define DL_HASH_SIZE 13
17016 +struct hlist_head dl_info_hash[DL_HASH_SIZE];
17018 +static DEFINE_SPINLOCK(dl_info_hash_lock);
17021 +static inline unsigned int __hashval(struct super_block *sb, vtag_t tag)
17023 + return ((tag ^ (unsigned long)sb) % DL_HASH_SIZE);
17028 +/* __hash_dl_info()
17030 + * add the dli to the global hash table
17031 + * requires the hash_lock to be held */
17033 +static inline void __hash_dl_info(struct dl_info *dli)
17035 + struct hlist_head *head;
17037 + vxdprintk(VXD_CBIT(dlim, 6),
17038 + "__hash_dl_info: %p[#%d]", dli, dli->dl_tag);
17039 + get_dl_info(dli);
17040 + head = &dl_info_hash[__hashval(dli->dl_sb, dli->dl_tag)];
17041 + hlist_add_head_rcu(&dli->dl_hlist, head);
17044 +/* __unhash_dl_info()
17046 + * remove the dli from the global hash table
17047 + * requires the hash_lock to be held */
17049 +static inline void __unhash_dl_info(struct dl_info *dli)
17051 + vxdprintk(VXD_CBIT(dlim, 6),
17052 + "__unhash_dl_info: %p[#%d]", dli, dli->dl_tag);
17053 + hlist_del_rcu(&dli->dl_hlist);
17054 + put_dl_info(dli);
17058 +/* __lookup_dl_info()
17060 + * requires the rcu_read_lock()
17061 + * doesn't increment the dl_refcnt */
17063 +static inline struct dl_info *__lookup_dl_info(struct super_block *sb, vtag_t tag)
17065 + struct hlist_head *head = &dl_info_hash[__hashval(sb, tag)];
17066 + struct dl_info *dli;
17068 + hlist_for_each_entry_rcu(dli, head, dl_hlist) {
17069 + if (dli->dl_tag == tag && dli->dl_sb == sb)
17076 +struct dl_info *locate_dl_info(struct super_block *sb, vtag_t tag)
17078 + struct dl_info *dli;
17081 + dli = get_dl_info(__lookup_dl_info(sb, tag));
17082 + vxdprintk(VXD_CBIT(dlim, 7),
17083 + "locate_dl_info(%p,#%d) = %p", sb, tag, dli);
17084 + rcu_read_unlock();
17088 +void rcu_free_dl_info(struct rcu_head *head)
17090 + struct dl_info *dli = container_of(head, struct dl_info, dl_rcu);
17091 + int usecnt, refcnt;
17093 + BUG_ON(!dli || !head);
17095 + usecnt = atomic_read(&dli->dl_usecnt);
17096 + BUG_ON(usecnt < 0);
17098 + refcnt = atomic_read(&dli->dl_refcnt);
17099 + BUG_ON(refcnt < 0);
17101 + vxdprintk(VXD_CBIT(dlim, 3),
17102 + "rcu_free_dl_info(%p)", dli);
17104 + __dealloc_dl_info(dli);
17106 + printk("!!! rcu didn't free\n");
17112 +static int do_addrem_dlimit(uint32_t id, const char __user *name,
17113 + uint32_t flags, int add)
17115 + struct path path;
17118 + ret = user_lpath(name, &path);
17120 + struct super_block *sb;
17121 + struct dl_info *dli;
17124 + if (!path.dentry->d_inode)
17125 + goto out_release;
17126 + if (!(sb = path.dentry->d_inode->i_sb))
17127 + goto out_release;
17130 + dli = __alloc_dl_info(sb, id);
17131 + spin_lock(&dl_info_hash_lock);
17134 + if (__lookup_dl_info(sb, id))
17136 + __hash_dl_info(dli);
17139 + spin_lock(&dl_info_hash_lock);
17140 + dli = __lookup_dl_info(sb, id);
17145 + __unhash_dl_info(dli);
17149 + spin_unlock(&dl_info_hash_lock);
17151 + __dealloc_dl_info(dli);
17158 +int vc_add_dlimit(uint32_t id, void __user *data)
17160 + struct vcmd_ctx_dlimit_base_v0 vc_data;
17162 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17165 + return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 1);
17168 +int vc_rem_dlimit(uint32_t id, void __user *data)
17170 + struct vcmd_ctx_dlimit_base_v0 vc_data;
17172 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17175 + return do_addrem_dlimit(id, vc_data.name, vc_data.flags, 0);
17178 +#ifdef CONFIG_COMPAT
17180 +int vc_add_dlimit_x32(uint32_t id, void __user *data)
17182 + struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17184 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17187 + return do_addrem_dlimit(id,
17188 + compat_ptr(vc_data.name_ptr), vc_data.flags, 1);
17191 +int vc_rem_dlimit_x32(uint32_t id, void __user *data)
17193 + struct vcmd_ctx_dlimit_base_v0_x32 vc_data;
17195 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17198 + return do_addrem_dlimit(id,
17199 + compat_ptr(vc_data.name_ptr), vc_data.flags, 0);
17202 +#endif /* CONFIG_COMPAT */
17206 +int do_set_dlimit(uint32_t id, const char __user *name,
17207 + uint32_t space_used, uint32_t space_total,
17208 + uint32_t inodes_used, uint32_t inodes_total,
17209 + uint32_t reserved, uint32_t flags)
17211 + struct path path;
17214 + ret = user_lpath(name, &path);
17216 + struct super_block *sb;
17217 + struct dl_info *dli;
17220 + if (!path.dentry->d_inode)
17221 + goto out_release;
17222 + if (!(sb = path.dentry->d_inode->i_sb))
17223 + goto out_release;
17225 + /* sanity checks */
17226 + if ((reserved != CDLIM_KEEP &&
17227 + reserved > 100) ||
17228 + (inodes_used != CDLIM_KEEP &&
17229 + inodes_used > inodes_total) ||
17230 + (space_used != CDLIM_KEEP &&
17231 + space_used > space_total))
17232 + goto out_release;
17235 + dli = locate_dl_info(sb, id);
17237 + goto out_release;
17239 + spin_lock(&dli->dl_lock);
17241 + if (inodes_used != CDLIM_KEEP)
17242 + dli->dl_inodes_used = inodes_used;
17243 + if (inodes_total != CDLIM_KEEP)
17244 + dli->dl_inodes_total = inodes_total;
17245 + if (space_used != CDLIM_KEEP)
17246 + dli->dl_space_used = dlimit_space_32to64(
17247 + space_used, flags, DLIMS_USED);
17249 + if (space_total == CDLIM_INFINITY)
17250 + dli->dl_space_total = DLIM_INFINITY;
17251 + else if (space_total != CDLIM_KEEP)
17252 + dli->dl_space_total = dlimit_space_32to64(
17253 + space_total, flags, DLIMS_TOTAL);
17255 + if (reserved != CDLIM_KEEP)
17256 + dli->dl_nrlmult = (1 << 10) * (100 - reserved) / 100;
17258 + spin_unlock(&dli->dl_lock);
17260 + put_dl_info(dli);
17269 +int vc_set_dlimit(uint32_t id, void __user *data)
17271 + struct vcmd_ctx_dlimit_v0 vc_data;
17273 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17276 + return do_set_dlimit(id, vc_data.name,
17277 + vc_data.space_used, vc_data.space_total,
17278 + vc_data.inodes_used, vc_data.inodes_total,
17279 + vc_data.reserved, vc_data.flags);
17282 +#ifdef CONFIG_COMPAT
17284 +int vc_set_dlimit_x32(uint32_t id, void __user *data)
17286 + struct vcmd_ctx_dlimit_v0_x32 vc_data;
17288 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17291 + return do_set_dlimit(id, compat_ptr(vc_data.name_ptr),
17292 + vc_data.space_used, vc_data.space_total,
17293 + vc_data.inodes_used, vc_data.inodes_total,
17294 + vc_data.reserved, vc_data.flags);
17297 +#endif /* CONFIG_COMPAT */
17301 +int do_get_dlimit(uint32_t id, const char __user *name,
17302 + uint32_t *space_used, uint32_t *space_total,
17303 + uint32_t *inodes_used, uint32_t *inodes_total,
17304 + uint32_t *reserved, uint32_t *flags)
17306 + struct path path;
17309 + ret = user_lpath(name, &path);
17311 + struct super_block *sb;
17312 + struct dl_info *dli;
17315 + if (!path.dentry->d_inode)
17316 + goto out_release;
17317 + if (!(sb = path.dentry->d_inode->i_sb))
17318 + goto out_release;
17321 + dli = locate_dl_info(sb, id);
17323 + goto out_release;
17325 + spin_lock(&dli->dl_lock);
17326 + *inodes_used = dli->dl_inodes_used;
17327 + *inodes_total = dli->dl_inodes_total;
17329 + *space_used = dlimit_space_64to32(
17330 + dli->dl_space_used, flags, DLIMS_USED);
17332 + if (dli->dl_space_total == DLIM_INFINITY)
17333 + *space_total = CDLIM_INFINITY;
17335 + *space_total = dlimit_space_64to32(
17336 + dli->dl_space_total, flags, DLIMS_TOTAL);
17338 + *reserved = 100 - ((dli->dl_nrlmult * 100 + 512) >> 10);
17339 + spin_unlock(&dli->dl_lock);
17341 + put_dl_info(dli);
17352 +int vc_get_dlimit(uint32_t id, void __user *data)
17354 + struct vcmd_ctx_dlimit_v0 vc_data;
17357 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17360 + ret = do_get_dlimit(id, vc_data.name,
17361 + &vc_data.space_used, &vc_data.space_total,
17362 + &vc_data.inodes_used, &vc_data.inodes_total,
17363 + &vc_data.reserved, &vc_data.flags);
17367 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17372 +#ifdef CONFIG_COMPAT
17374 +int vc_get_dlimit_x32(uint32_t id, void __user *data)
17376 + struct vcmd_ctx_dlimit_v0_x32 vc_data;
17379 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17382 + ret = do_get_dlimit(id, compat_ptr(vc_data.name_ptr),
17383 + &vc_data.space_used, &vc_data.space_total,
17384 + &vc_data.inodes_used, &vc_data.inodes_total,
17385 + &vc_data.reserved, &vc_data.flags);
17389 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17394 +#endif /* CONFIG_COMPAT */
17397 +void vx_vsi_statfs(struct super_block *sb, struct kstatfs *buf)
17399 + struct dl_info *dli;
17400 + __u64 blimit, bfree, bavail;
17403 + dli = locate_dl_info(sb, dx_current_tag());
17407 + spin_lock(&dli->dl_lock);
17408 + if (dli->dl_inodes_total == (unsigned long)DLIM_INFINITY)
17411 + /* reduce max inodes available to limit */
17412 + if (buf->f_files > dli->dl_inodes_total)
17413 + buf->f_files = dli->dl_inodes_total;
17415 + ifree = dli->dl_inodes_total - dli->dl_inodes_used;
17416 + /* reduce free inodes to min */
17417 + if (ifree < buf->f_ffree)
17418 + buf->f_ffree = ifree;
17421 + if (dli->dl_space_total == DLIM_INFINITY)
17424 + blimit = dli->dl_space_total >> sb->s_blocksize_bits;
17426 + if (dli->dl_space_total < dli->dl_space_used)
17429 + bfree = (dli->dl_space_total - dli->dl_space_used)
17430 + >> sb->s_blocksize_bits;
17432 + bavail = ((dli->dl_space_total >> 10) * dli->dl_nrlmult);
17433 + if (bavail < dli->dl_space_used)
17436 + bavail = (bavail - dli->dl_space_used)
17437 + >> sb->s_blocksize_bits;
17439 + /* reduce max space available to limit */
17440 + if (buf->f_blocks > blimit)
17441 + buf->f_blocks = blimit;
17443 + /* reduce free space to min */
17444 + if (bfree < buf->f_bfree)
17445 + buf->f_bfree = bfree;
17447 + /* reduce avail space to min */
17448 + if (bavail < buf->f_bavail)
17449 + buf->f_bavail = bavail;
17452 + spin_unlock(&dli->dl_lock);
17453 + put_dl_info(dli);
17458 +#include <linux/module.h>
17460 +EXPORT_SYMBOL_GPL(locate_dl_info);
17461 +EXPORT_SYMBOL_GPL(rcu_free_dl_info);
17463 diff -NurpP --minimal linux-3.13.10/kernel/vserver/helper.c linux-3.13.10-vs2.3.6.11/kernel/vserver/helper.c
17464 --- linux-3.13.10/kernel/vserver/helper.c 1970-01-01 00:00:00.000000000 +0000
17465 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/helper.c 2014-01-31 20:38:04.000000000 +0000
17468 + * linux/kernel/vserver/helper.c
17470 + * Virtual Context Support
17472 + * Copyright (C) 2004-2007 Herbert Pötzl
17474 + * V0.01 basic helper
17478 +#include <linux/kmod.h>
17479 +#include <linux/reboot.h>
17480 +#include <linux/vs_context.h>
17481 +#include <linux/vs_network.h>
17482 +#include <linux/vserver/signal.h>
17485 +char vshelper_path[255] = "/sbin/vshelper";
17487 +static int vshelper_init(struct subprocess_info *info, struct cred *new_cred)
17489 + current->flags &= ~PF_NO_SETAFFINITY;
17493 +static int vs_call_usermodehelper(char *path, char **argv, char **envp, int wait)
17495 + struct subprocess_info *info;
17496 + gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL;
17498 + info = call_usermodehelper_setup(path, argv, envp, gfp_mask,
17499 + vshelper_init, NULL, NULL);
17500 + if (info == NULL)
17503 + return call_usermodehelper_exec(info, wait);
17506 +static int do_vshelper(char *name, char *argv[], char *envp[], int sync)
17510 + if ((ret = vs_call_usermodehelper(name, argv, envp,
17511 + sync ? UMH_WAIT_PROC : UMH_WAIT_EXEC))) {
17512 + printk(KERN_WARNING "%s: (%s %s) returned %s with %d\n",
17513 + name, argv[1], argv[2],
17514 + sync ? "sync" : "async", ret);
17516 + vxdprintk(VXD_CBIT(switch, 4),
17517 + "%s: (%s %s) returned %s with %d",
17518 + name, argv[1], argv[2], sync ? "sync" : "async", ret);
17523 + * vshelper path is set via /proc/sys
17524 + * invoked by vserver sys_reboot(), with
17525 + * the following arguments
17527 + * argv [0] = vshelper_path;
17528 + * argv [1] = action: "restart", "halt", "poweroff", ...
17529 + * argv [2] = context identifier
17531 + * envp [*] = type-specific parameters
17534 +long vs_reboot_helper(struct vx_info *vxi, int cmd, void __user *arg)
17536 + char id_buf[8], cmd_buf[16];
17537 + char uid_buf[16], pid_buf[16];
17540 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
17541 + char *envp[] = {"HOME=/", "TERM=linux",
17542 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
17543 + uid_buf, pid_buf, cmd_buf, 0};
17545 + if (vx_info_state(vxi, VXS_HELPER))
17547 + vxi->vx_state |= VXS_HELPER;
17549 + snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17551 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17552 + snprintf(uid_buf, sizeof(uid_buf), "VS_UID=%d",
17553 + from_kuid(&init_user_ns, current_uid()));
17554 + snprintf(pid_buf, sizeof(pid_buf), "VS_PID=%d", current->pid);
17557 + case LINUX_REBOOT_CMD_RESTART:
17558 + argv[1] = "restart";
17561 + case LINUX_REBOOT_CMD_HALT:
17562 + argv[1] = "halt";
17565 + case LINUX_REBOOT_CMD_POWER_OFF:
17566 + argv[1] = "poweroff";
17569 + case LINUX_REBOOT_CMD_SW_SUSPEND:
17570 + argv[1] = "swsusp";
17573 + case LINUX_REBOOT_CMD_OOM:
17578 + vxi->vx_state &= ~VXS_HELPER;
17582 + ret = do_vshelper(vshelper_path, argv, envp, 0);
17583 + vxi->vx_state &= ~VXS_HELPER;
17584 + __wakeup_vx_info(vxi);
17585 + return (ret) ? -EPERM : 0;
17589 +long vs_reboot(unsigned int cmd, void __user *arg)
17591 + struct vx_info *vxi = current_vx_info();
17594 + vxdprintk(VXD_CBIT(misc, 5),
17595 + "vs_reboot(%p[#%d],%u)",
17596 + vxi, vxi ? vxi->vx_id : 0, cmd);
17598 + ret = vs_reboot_helper(vxi, cmd, arg);
17602 + vxi->reboot_cmd = cmd;
17603 + if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17605 + case LINUX_REBOOT_CMD_RESTART:
17606 + case LINUX_REBOOT_CMD_HALT:
17607 + case LINUX_REBOOT_CMD_POWER_OFF:
17608 + vx_info_kill(vxi, 0, SIGKILL);
17609 + vx_info_kill(vxi, 1, SIGKILL);
17617 +long vs_oom_action(unsigned int cmd)
17619 + struct vx_info *vxi = current_vx_info();
17622 + vxdprintk(VXD_CBIT(misc, 5),
17623 + "vs_oom_action(%p[#%d],%u)",
17624 + vxi, vxi ? vxi->vx_id : 0, cmd);
17626 + ret = vs_reboot_helper(vxi, cmd, NULL);
17630 + vxi->reboot_cmd = cmd;
17631 + if (vx_info_flags(vxi, VXF_REBOOT_KILL, 0)) {
17632 + vx_info_kill(vxi, 0, SIGKILL);
17633 + vx_info_kill(vxi, 1, SIGKILL);
17639 + * argv [0] = vshelper_path;
17640 + * argv [1] = action: "startup", "shutdown"
17641 + * argv [2] = context identifier
17643 + * envp [*] = type-specific parameters
17646 +long vs_state_change(struct vx_info *vxi, unsigned int cmd)
17648 + char id_buf[8], cmd_buf[16];
17649 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
17650 + char *envp[] = {"HOME=/", "TERM=linux",
17651 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17653 + if (!vx_info_flags(vxi, VXF_SC_HELPER, 0))
17656 + snprintf(id_buf, sizeof(id_buf), "%d", vxi->vx_id);
17657 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17660 + case VSC_STARTUP:
17661 + argv[1] = "startup";
17663 + case VSC_SHUTDOWN:
17664 + argv[1] = "shutdown";
17670 + return do_vshelper(vshelper_path, argv, envp, 1);
17675 + * argv [0] = vshelper_path;
17676 + * argv [1] = action: "netup", "netdown"
17677 + * argv [2] = context identifier
17679 + * envp [*] = type-specific parameters
17682 +long vs_net_change(struct nx_info *nxi, unsigned int cmd)
17684 + char id_buf[8], cmd_buf[16];
17685 + char *argv[] = {vshelper_path, NULL, id_buf, 0};
17686 + char *envp[] = {"HOME=/", "TERM=linux",
17687 + "PATH=/sbin:/usr/sbin:/bin:/usr/bin", cmd_buf, 0};
17689 + if (!nx_info_flags(nxi, NXF_SC_HELPER, 0))
17692 + snprintf(id_buf, sizeof(id_buf), "%d", nxi->nx_id);
17693 + snprintf(cmd_buf, sizeof(cmd_buf), "VS_CMD=%08x", cmd);
17697 + argv[1] = "netup";
17699 + case VSC_NETDOWN:
17700 + argv[1] = "netdown";
17706 + return do_vshelper(vshelper_path, argv, envp, 1);
17709 diff -NurpP --minimal linux-3.13.10/kernel/vserver/history.c linux-3.13.10-vs2.3.6.11/kernel/vserver/history.c
17710 --- linux-3.13.10/kernel/vserver/history.c 1970-01-01 00:00:00.000000000 +0000
17711 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/history.c 2014-01-31 20:38:04.000000000 +0000
17714 + * kernel/vserver/history.c
17716 + * Virtual Context History Backtrace
17718 + * Copyright (C) 2004-2007 Herbert Pötzl
17720 + * V0.01 basic structure
17721 + * V0.02 hash/unhash and trace
17722 + * V0.03 preemption fixes
17726 +#include <linux/module.h>
17727 +#include <asm/uaccess.h>
17729 +#include <linux/vserver/context.h>
17730 +#include <linux/vserver/debug.h>
17731 +#include <linux/vserver/debug_cmd.h>
17732 +#include <linux/vserver/history.h>
17735 +#ifdef CONFIG_VSERVER_HISTORY
17736 +#define VXH_SIZE CONFIG_VSERVER_HISTORY_SIZE
17738 +#define VXH_SIZE 64
17741 +struct _vx_history {
17742 + unsigned int counter;
17744 + struct _vx_hist_entry entry[VXH_SIZE + 1];
17748 +DEFINE_PER_CPU(struct _vx_history, vx_history_buffer);
17750 +unsigned volatile int vxh_active = 1;
17752 +static atomic_t sequence = ATOMIC_INIT(0);
17757 + * requires disabled preemption */
17759 +struct _vx_hist_entry *vxh_advance(void *loc)
17761 + unsigned int cpu = smp_processor_id();
17762 + struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17763 + struct _vx_hist_entry *entry;
17764 + unsigned int index;
17766 + index = vxh_active ? (hist->counter++ % VXH_SIZE) : VXH_SIZE;
17767 + entry = &hist->entry[index];
17769 + entry->seq = atomic_inc_return(&sequence);
17770 + entry->loc = loc;
17774 +EXPORT_SYMBOL_GPL(vxh_advance);
17777 +#define VXH_LOC_FMTS "(#%04x,*%d):%p"
17779 +#define VXH_LOC_ARGS(e) (e)->seq, cpu, (e)->loc
17782 +#define VXH_VXI_FMTS "%p[#%d,%d.%d]"
17784 +#define VXH_VXI_ARGS(e) (e)->vxi.ptr, \
17785 + (e)->vxi.ptr ? (e)->vxi.xid : 0, \
17786 + (e)->vxi.ptr ? (e)->vxi.usecnt : 0, \
17787 + (e)->vxi.ptr ? (e)->vxi.tasks : 0
17789 +void vxh_dump_entry(struct _vx_hist_entry *e, unsigned cpu)
17791 + switch (e->type) {
17792 + case VXH_THROW_OOPS:
17793 + printk( VXH_LOC_FMTS " oops \n", VXH_LOC_ARGS(e));
17796 + case VXH_GET_VX_INFO:
17797 + case VXH_PUT_VX_INFO:
17798 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17800 + (e->type == VXH_GET_VX_INFO) ? "get" : "put",
17801 + VXH_VXI_ARGS(e));
17804 + case VXH_INIT_VX_INFO:
17805 + case VXH_SET_VX_INFO:
17806 + case VXH_CLR_VX_INFO:
17807 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17809 + (e->type == VXH_INIT_VX_INFO) ? "init" :
17810 + ((e->type == VXH_SET_VX_INFO) ? "set" : "clr"),
17811 + VXH_VXI_ARGS(e), e->sc.data);
17814 + case VXH_CLAIM_VX_INFO:
17815 + case VXH_RELEASE_VX_INFO:
17816 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS " @%p\n",
17818 + (e->type == VXH_CLAIM_VX_INFO) ? "claim" : "release",
17819 + VXH_VXI_ARGS(e), e->sc.data);
17822 + case VXH_ALLOC_VX_INFO:
17823 + case VXH_DEALLOC_VX_INFO:
17824 + printk( VXH_LOC_FMTS " %s_vx_info " VXH_VXI_FMTS "\n",
17826 + (e->type == VXH_ALLOC_VX_INFO) ? "alloc" : "dealloc",
17827 + VXH_VXI_ARGS(e));
17830 + case VXH_HASH_VX_INFO:
17831 + case VXH_UNHASH_VX_INFO:
17832 + printk( VXH_LOC_FMTS " __%s_vx_info " VXH_VXI_FMTS "\n",
17834 + (e->type == VXH_HASH_VX_INFO) ? "hash" : "unhash",
17835 + VXH_VXI_ARGS(e));
17838 + case VXH_LOC_VX_INFO:
17839 + case VXH_LOOKUP_VX_INFO:
17840 + case VXH_CREATE_VX_INFO:
17841 + printk( VXH_LOC_FMTS " __%s_vx_info [#%d] -> " VXH_VXI_FMTS "\n",
17843 + (e->type == VXH_CREATE_VX_INFO) ? "create" :
17844 + ((e->type == VXH_LOC_VX_INFO) ? "loc" : "lookup"),
17845 + e->ll.arg, VXH_VXI_ARGS(e));
17850 +static void __vxh_dump_history(void)
17852 + unsigned int i, cpu;
17854 + printk("History:\tSEQ: %8x\tNR_CPUS: %d\n",
17855 + atomic_read(&sequence), NR_CPUS);
17857 + for (i = 0; i < VXH_SIZE; i++) {
17858 + for_each_online_cpu(cpu) {
17859 + struct _vx_history *hist =
17860 + &per_cpu(vx_history_buffer, cpu);
17861 + unsigned int index = (hist->counter - i) % VXH_SIZE;
17862 + struct _vx_hist_entry *entry = &hist->entry[index];
17864 + vxh_dump_entry(entry, cpu);
17869 +void vxh_dump_history(void)
17873 + local_irq_enable();
17875 + local_irq_disable();
17877 + __vxh_dump_history();
17881 +/* vserver syscall commands below here */
17884 +int vc_dump_history(uint32_t id)
17887 + __vxh_dump_history();
17894 +int do_read_history(struct __user _vx_hist_entry *data,
17895 + int cpu, uint32_t *index, uint32_t *count)
17897 + int pos, ret = 0;
17898 + struct _vx_history *hist = &per_cpu(vx_history_buffer, cpu);
17899 + int end = hist->counter;
17900 + int start = end - VXH_SIZE + 2;
17901 + int idx = *index;
17903 + /* special case: get current pos */
17909 + /* have we lost some data? */
17913 + for (pos = 0; (pos < *count) && (idx < end); pos++, idx++) {
17914 + struct _vx_hist_entry *entry =
17915 + &hist->entry[idx % VXH_SIZE];
17917 + /* send entry to userspace */
17918 + ret = copy_to_user(&data[pos], entry, sizeof(*entry));
17922 + /* save new index and count */
17925 + return ret ? ret : (*index < end);
17928 +int vc_read_history(uint32_t id, void __user *data)
17930 + struct vcmd_read_history_v0 vc_data;
17933 + if (id >= NR_CPUS)
17936 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17939 + ret = do_read_history((struct __user _vx_hist_entry *)vc_data.data,
17940 + id, &vc_data.index, &vc_data.count);
17942 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17947 +#ifdef CONFIG_COMPAT
17949 +int vc_read_history_x32(uint32_t id, void __user *data)
17951 + struct vcmd_read_history_v0_x32 vc_data;
17954 + if (id >= NR_CPUS)
17957 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
17960 + ret = do_read_history((struct __user _vx_hist_entry *)
17961 + compat_ptr(vc_data.data_ptr),
17962 + id, &vc_data.index, &vc_data.count);
17964 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
17969 +#endif /* CONFIG_COMPAT */
17971 diff -NurpP --minimal linux-3.13.10/kernel/vserver/inet.c linux-3.13.10-vs2.3.6.11/kernel/vserver/inet.c
17972 --- linux-3.13.10/kernel/vserver/inet.c 1970-01-01 00:00:00.000000000 +0000
17973 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/inet.c 2014-02-01 00:26:40.000000000 +0000
17976 +#include <linux/in.h>
17977 +#include <linux/inetdevice.h>
17978 +#include <linux/export.h>
17979 +#include <linux/vs_inet.h>
17980 +#include <linux/vs_inet6.h>
17981 +#include <linux/vserver/debug.h>
17982 +#include <net/route.h>
17983 +#include <net/addrconf.h>
17986 +int nx_v4_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
17990 + if (!nxi1 || !nxi2 || nxi1 == nxi2)
17993 + struct nx_addr_v4 *ptr;
17994 + unsigned long irqflags;
17996 + spin_lock_irqsave(&nxi1->addr_lock, irqflags);
17997 + for (ptr = &nxi1->v4; ptr; ptr = ptr->next) {
17998 + if (v4_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18003 + spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18006 + vxdprintk(VXD_CBIT(net, 2),
18007 + "nx_v4_addr_conflict(%p,%p): %d",
18008 + nxi1, nxi2, ret);
18014 +#ifdef CONFIG_IPV6
18016 +int nx_v6_addr_conflict(struct nx_info *nxi1, struct nx_info *nxi2)
18020 + if (!nxi1 || !nxi2 || nxi1 == nxi2)
18023 + struct nx_addr_v6 *ptr;
18024 + unsigned long irqflags;
18026 + spin_lock_irqsave(&nxi1->addr_lock, irqflags);
18027 + for (ptr = &nxi1->v6; ptr; ptr = ptr->next) {
18028 + if (v6_nx_addr_in_nx_info(nxi2, ptr, -1)) {
18033 + spin_unlock_irqrestore(&nxi1->addr_lock, irqflags);
18036 + vxdprintk(VXD_CBIT(net, 2),
18037 + "nx_v6_addr_conflict(%p,%p): %d",
18038 + nxi1, nxi2, ret);
18045 +int v4_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18047 + struct in_device *in_dev;
18048 + struct in_ifaddr **ifap;
18049 + struct in_ifaddr *ifa;
18054 + in_dev = in_dev_get(dev);
18058 + for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
18059 + ifap = &ifa->ifa_next) {
18060 + if (v4_addr_in_nx_info(nxi, ifa->ifa_local, NXA_MASK_SHOW)) {
18065 + in_dev_put(in_dev);
18071 +#ifdef CONFIG_IPV6
18073 +int v6_dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18075 + struct inet6_dev *in_dev;
18076 + struct inet6_ifaddr *ifa;
18081 + in_dev = in6_dev_get(dev);
18085 + // for (ifap = &in_dev->addr_list; (ifa = *ifap) != NULL;
18086 + list_for_each_entry(ifa, &in_dev->addr_list, if_list) {
18087 + if (v6_addr_in_nx_info(nxi, &ifa->addr, -1)) {
18092 + in6_dev_put(in_dev);
18099 +int dev_in_nx_info(struct net_device *dev, struct nx_info *nxi)
18105 + if (nxi->v4.type && v4_dev_in_nx_info(dev, nxi))
18107 +#ifdef CONFIG_IPV6
18109 + if (nxi->v6.type && v6_dev_in_nx_info(dev, nxi))
18114 + vxdprintk(VXD_CBIT(net, 3),
18115 + "dev_in_nx_info(%p,%p[#%d]) = %d",
18116 + dev, nxi, nxi ? nxi->nx_id : 0, ret);
18120 +struct rtable *ip_v4_find_src(struct net *net, struct nx_info *nxi,
18121 + struct flowi4 *fl4)
18123 + struct rtable *rt;
18128 + /* FIXME: handle lback only case */
18129 + if (!NX_IPV4(nxi))
18130 + return ERR_PTR(-EPERM);
18132 + vxdprintk(VXD_CBIT(net, 4),
18133 + "ip_v4_find_src(%p[#%u]) " NIPQUAD_FMT " -> " NIPQUAD_FMT,
18134 + nxi, nxi ? nxi->nx_id : 0,
18135 + NIPQUAD(fl4->saddr), NIPQUAD(fl4->daddr));
18137 + /* single IP is unconditional */
18138 + if (nx_info_flags(nxi, NXF_SINGLE_IP, 0) &&
18139 + (fl4->saddr == INADDR_ANY))
18140 + fl4->saddr = nxi->v4.ip[0].s_addr;
18142 + if (fl4->saddr == INADDR_ANY) {
18143 + struct nx_addr_v4 *ptr;
18144 + __be32 found = 0;
18146 + rt = __ip_route_output_key(net, fl4);
18147 + if (!IS_ERR(rt)) {
18148 + found = fl4->saddr;
18150 + vxdprintk(VXD_CBIT(net, 4),
18151 + "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18152 + nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(found));
18153 + if (v4_addr_in_nx_info(nxi, found, NXA_MASK_BIND))
18157 + WARN_ON_ONCE(in_irq());
18158 + spin_lock_bh(&nxi->addr_lock);
18159 + for (ptr = &nxi->v4; ptr; ptr = ptr->next) {
18160 + __be32 primary = ptr->ip[0].s_addr;
18161 + __be32 mask = ptr->mask.s_addr;
18162 + __be32 neta = primary & mask;
18164 + vxdprintk(VXD_CBIT(net, 4), "ip_v4_find_src(%p[#%u]) chk: "
18165 + NIPQUAD_FMT "/" NIPQUAD_FMT "/" NIPQUAD_FMT,
18166 + nxi, nxi ? nxi->nx_id : 0, NIPQUAD(primary),
18167 + NIPQUAD(mask), NIPQUAD(neta));
18168 + if ((found & mask) != neta)
18171 + fl4->saddr = primary;
18172 + rt = __ip_route_output_key(net, fl4);
18173 + vxdprintk(VXD_CBIT(net, 4),
18174 + "ip_v4_find_src(%p[#%u]) rok[%u]: " NIPQUAD_FMT,
18175 + nxi, nxi ? nxi->nx_id : 0, fl4->flowi4_oif, NIPQUAD(primary));
18176 + if (!IS_ERR(rt)) {
18177 + found = fl4->saddr;
18179 + if (found == primary)
18180 + goto found_unlock;
18183 + /* still no source ip? */
18184 + found = ipv4_is_loopback(fl4->daddr)
18185 + ? IPI_LOOPBACK : nxi->v4.ip[0].s_addr;
18187 + spin_unlock_bh(&nxi->addr_lock);
18189 + /* assign src ip to flow */
18190 + fl4->saddr = found;
18193 + if (!v4_addr_in_nx_info(nxi, fl4->saddr, NXA_MASK_BIND))
18194 + return ERR_PTR(-EPERM);
18197 + if (nx_info_flags(nxi, NXF_LBACK_REMAP, 0)) {
18198 + if (ipv4_is_loopback(fl4->daddr))
18199 + fl4->daddr = nxi->v4_lback.s_addr;
18200 + if (ipv4_is_loopback(fl4->saddr))
18201 + fl4->saddr = nxi->v4_lback.s_addr;
18202 + } else if (ipv4_is_loopback(fl4->daddr) &&
18203 + !nx_info_flags(nxi, NXF_LBACK_ALLOW, 0))
18204 + return ERR_PTR(-EPERM);
18209 +EXPORT_SYMBOL_GPL(ip_v4_find_src);
18211 diff -NurpP --minimal linux-3.13.10/kernel/vserver/init.c linux-3.13.10-vs2.3.6.11/kernel/vserver/init.c
18212 --- linux-3.13.10/kernel/vserver/init.c 1970-01-01 00:00:00.000000000 +0000
18213 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/init.c 2014-01-31 20:38:04.000000000 +0000
18216 + * linux/kernel/init.c
18218 + * Virtual Server Init
18220 + * Copyright (C) 2004-2007 Herbert Pötzl
18222 + * V0.01 basic structure
18226 +#include <linux/init.h>
18228 +int vserver_register_sysctl(void);
18229 +void vserver_unregister_sysctl(void);
18232 +static int __init init_vserver(void)
18236 +#ifdef CONFIG_VSERVER_DEBUG
18237 + vserver_register_sysctl();
18243 +static void __exit exit_vserver(void)
18246 +#ifdef CONFIG_VSERVER_DEBUG
18247 + vserver_unregister_sysctl();
18252 +/* FIXME: GFP_ZONETYPES gone
18253 +long vx_slab[GFP_ZONETYPES]; */
18257 +module_init(init_vserver);
18258 +module_exit(exit_vserver);
18260 diff -NurpP --minimal linux-3.13.10/kernel/vserver/inode.c linux-3.13.10-vs2.3.6.11/kernel/vserver/inode.c
18261 --- linux-3.13.10/kernel/vserver/inode.c 1970-01-01 00:00:00.000000000 +0000
18262 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/inode.c 2014-01-31 20:38:04.000000000 +0000
18265 + * linux/kernel/vserver/inode.c
18267 + * Virtual Server: File System Support
18269 + * Copyright (C) 2004-2007 Herbert Pötzl
18271 + * V0.01 separated from vcontext V0.05
18272 + * V0.02 moved to tag (instead of xid)
18276 +#include <linux/tty.h>
18277 +#include <linux/proc_fs.h>
18278 +#include <linux/devpts_fs.h>
18279 +#include <linux/fs.h>
18280 +#include <linux/file.h>
18281 +#include <linux/mount.h>
18282 +#include <linux/parser.h>
18283 +#include <linux/namei.h>
18284 +#include <linux/magic.h>
18285 +#include <linux/slab.h>
18286 +#include <linux/vserver/inode.h>
18287 +#include <linux/vserver/inode_cmd.h>
18288 +#include <linux/vs_base.h>
18289 +#include <linux/vs_tag.h>
18291 +#include <asm/uaccess.h>
18292 +#include <../../fs/proc/internal.h>
18295 +static int __vc_get_iattr(struct inode *in, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18297 + struct proc_dir_entry *entry;
18299 + if (!in || !in->i_sb)
18302 + *flags = IATTR_TAG
18303 + | (IS_IMMUTABLE(in) ? IATTR_IMMUTABLE : 0)
18304 + | (IS_IXUNLINK(in) ? IATTR_IXUNLINK : 0)
18305 + | (IS_BARRIER(in) ? IATTR_BARRIER : 0)
18306 + | (IS_COW(in) ? IATTR_COW : 0);
18307 + *mask = IATTR_IXUNLINK | IATTR_IMMUTABLE | IATTR_COW;
18309 + if (S_ISDIR(in->i_mode))
18310 + *mask |= IATTR_BARRIER;
18312 + if (IS_TAGGED(in)) {
18313 + *tag = i_tag_read(in);
18314 + *mask |= IATTR_TAG;
18317 + switch (in->i_sb->s_magic) {
18318 + case PROC_SUPER_MAGIC:
18319 + entry = PROC_I(in)->pde;
18321 + /* check for specific inodes? */
18323 + *mask |= IATTR_FLAGS;
18325 + *flags |= (entry->vx_flags & IATTR_FLAGS);
18327 + *flags |= (PROC_I(in)->vx_flags & IATTR_FLAGS);
18330 + case DEVPTS_SUPER_MAGIC:
18331 + *tag = i_tag_read(in);
18332 + *mask |= IATTR_TAG;
18341 +int vc_get_iattr(void __user *data)
18343 + struct path path;
18344 + struct vcmd_ctx_iattr_v1 vc_data = { .tag = -1 };
18347 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18350 + ret = user_lpath(vc_data.name, &path);
18352 + ret = __vc_get_iattr(path.dentry->d_inode,
18353 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18359 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18364 +#ifdef CONFIG_COMPAT
18366 +int vc_get_iattr_x32(void __user *data)
18368 + struct path path;
18369 + struct vcmd_ctx_iattr_v1_x32 vc_data = { .tag = -1 };
18372 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18375 + ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18377 + ret = __vc_get_iattr(path.dentry->d_inode,
18378 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18384 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18389 +#endif /* CONFIG_COMPAT */
18392 +int vc_fget_iattr(uint32_t fd, void __user *data)
18394 + struct file *filp;
18395 + struct vcmd_ctx_fiattr_v0 vc_data = { .tag = -1 };
18398 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18402 + if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18405 + ret = __vc_get_iattr(filp->f_dentry->d_inode,
18406 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18410 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18416 +static int __vc_set_iattr(struct dentry *de, uint32_t *tag, uint32_t *flags, uint32_t *mask)
18418 + struct inode *in = de->d_inode;
18419 + int error = 0, is_proc = 0, has_tag = 0;
18420 + struct iattr attr = { 0 };
18422 + if (!in || !in->i_sb)
18425 + is_proc = (in->i_sb->s_magic == PROC_SUPER_MAGIC);
18426 + if ((*mask & IATTR_FLAGS) && !is_proc)
18429 + has_tag = IS_TAGGED(in) ||
18430 + (in->i_sb->s_magic == DEVPTS_SUPER_MAGIC);
18431 + if ((*mask & IATTR_TAG) && !has_tag)
18434 + mutex_lock(&in->i_mutex);
18435 + if (*mask & IATTR_TAG) {
18436 + attr.ia_tag = make_ktag(&init_user_ns, *tag);
18437 + attr.ia_valid |= ATTR_TAG;
18440 + if (*mask & IATTR_FLAGS) {
18441 + struct proc_dir_entry *entry = PROC_I(in)->pde;
18442 + unsigned int iflags = PROC_I(in)->vx_flags;
18444 + iflags = (iflags & ~(*mask & IATTR_FLAGS))
18445 + | (*flags & IATTR_FLAGS);
18446 + PROC_I(in)->vx_flags = iflags;
18448 + entry->vx_flags = iflags;
18451 + if (*mask & (IATTR_IMMUTABLE | IATTR_IXUNLINK |
18452 + IATTR_BARRIER | IATTR_COW)) {
18453 + int iflags = in->i_flags;
18454 + int vflags = in->i_vflags;
18456 + if (*mask & IATTR_IMMUTABLE) {
18457 + if (*flags & IATTR_IMMUTABLE)
18458 + iflags |= S_IMMUTABLE;
18460 + iflags &= ~S_IMMUTABLE;
18462 + if (*mask & IATTR_IXUNLINK) {
18463 + if (*flags & IATTR_IXUNLINK)
18464 + iflags |= S_IXUNLINK;
18466 + iflags &= ~S_IXUNLINK;
18468 + if (S_ISDIR(in->i_mode) && (*mask & IATTR_BARRIER)) {
18469 + if (*flags & IATTR_BARRIER)
18470 + vflags |= V_BARRIER;
18472 + vflags &= ~V_BARRIER;
18474 + if (S_ISREG(in->i_mode) && (*mask & IATTR_COW)) {
18475 + if (*flags & IATTR_COW)
18478 + vflags &= ~V_COW;
18480 + if (in->i_op && in->i_op->sync_flags) {
18481 + error = in->i_op->sync_flags(in, iflags, vflags);
18487 + if (attr.ia_valid) {
18488 + if (in->i_op && in->i_op->setattr)
18489 + error = in->i_op->setattr(de, &attr);
18491 + error = inode_change_ok(in, &attr);
18493 + setattr_copy(in, &attr);
18494 + mark_inode_dirty(in);
18500 + mutex_unlock(&in->i_mutex);
18504 +int vc_set_iattr(void __user *data)
18506 + struct path path;
18507 + struct vcmd_ctx_iattr_v1 vc_data;
18510 + if (!capable(CAP_LINUX_IMMUTABLE))
18512 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18515 + ret = user_lpath(vc_data.name, &path);
18517 + ret = __vc_set_iattr(path.dentry,
18518 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18522 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18527 +#ifdef CONFIG_COMPAT
18529 +int vc_set_iattr_x32(void __user *data)
18531 + struct path path;
18532 + struct vcmd_ctx_iattr_v1_x32 vc_data;
18535 + if (!capable(CAP_LINUX_IMMUTABLE))
18537 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18540 + ret = user_lpath(compat_ptr(vc_data.name_ptr), &path);
18542 + ret = __vc_set_iattr(path.dentry,
18543 + &vc_data.tag, &vc_data.flags, &vc_data.mask);
18547 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18552 +#endif /* CONFIG_COMPAT */
18554 +int vc_fset_iattr(uint32_t fd, void __user *data)
18556 + struct file *filp;
18557 + struct vcmd_ctx_fiattr_v0 vc_data;
18560 + if (!capable(CAP_LINUX_IMMUTABLE))
18562 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18566 + if (!filp || !filp->f_dentry || !filp->f_dentry->d_inode)
18569 + ret = __vc_set_iattr(filp->f_dentry, &vc_data.tag,
18570 + &vc_data.flags, &vc_data.mask);
18574 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18580 +enum { Opt_notagcheck, Opt_tag, Opt_notag, Opt_tagid, Opt_err };
18582 +static match_table_t tokens = {
18583 + {Opt_notagcheck, "notagcheck"},
18584 +#ifdef CONFIG_PROPAGATE
18585 + {Opt_notag, "notag"},
18586 + {Opt_tag, "tag"},
18587 + {Opt_tagid, "tagid=%u"},
18593 +static void __dx_parse_remove(char *string, char *opt)
18595 + char *p = strstr(string, opt);
18599 + while (*q != '\0' && *q != ',')
18608 +int dx_parse_tag(char *string, vtag_t *tag, int remove, int *mnt_flags,
18609 + unsigned long *flags)
18612 + substring_t args[MAX_OPT_ARGS];
18614 + char *s, *p, *opts;
18615 +#if defined(CONFIG_PROPAGATE) || defined(CONFIG_VSERVER_DEBUG)
18621 + s = kstrdup(string, GFP_KERNEL | GFP_ATOMIC);
18626 + while ((p = strsep(&opts, ",")) != NULL) {
18627 + token = match_token(p, tokens, args);
18630 +#ifdef CONFIG_PROPAGATE
18635 + __dx_parse_remove(s, "tag");
18636 + *mnt_flags |= MNT_TAGID;
18637 + set |= MNT_TAGID;
18641 + __dx_parse_remove(s, "notag");
18642 + *mnt_flags |= MNT_NOTAG;
18643 + set |= MNT_NOTAG;
18646 + if (tag && !match_int(args, &option))
18649 + __dx_parse_remove(s, "tagid");
18650 + *mnt_flags |= MNT_TAGID;
18651 + set |= MNT_TAGID;
18653 +#endif /* CONFIG_PROPAGATE */
18654 + case Opt_notagcheck:
18656 + __dx_parse_remove(s, "notagcheck");
18657 + *flags |= MS_NOTAGCHECK;
18658 + set |= MS_NOTAGCHECK;
18661 + vxdprintk(VXD_CBIT(tag, 7),
18662 + "dx_parse_tag(" VS_Q("%s") "): %d:#%d",
18663 + p, token, option);
18666 + strcpy(string, s);
18671 +#ifdef CONFIG_PROPAGATE
18673 +void __dx_propagate_tag(struct nameidata *nd, struct inode *inode)
18675 + vtag_t new_tag = 0;
18676 + struct vfsmount *mnt;
18681 + mnt = nd->path.mnt;
18685 + propagate = (mnt->mnt_flags & MNT_TAGID);
18687 + new_tag = mnt->mnt_tag;
18689 + vxdprintk(VXD_CBIT(tag, 7),
18690 + "dx_propagate_tag(%p[#%lu.%d]): %d,%d",
18691 + inode, inode->i_ino, inode->i_tag,
18692 + new_tag, (propagate) ? 1 : 0);
18695 + i_tag_write(inode, new_tag);
18698 +#include <linux/module.h>
18700 +EXPORT_SYMBOL_GPL(__dx_propagate_tag);
18702 +#endif /* CONFIG_PROPAGATE */
18704 diff -NurpP --minimal linux-3.13.10/kernel/vserver/limit.c linux-3.13.10-vs2.3.6.11/kernel/vserver/limit.c
18705 --- linux-3.13.10/kernel/vserver/limit.c 1970-01-01 00:00:00.000000000 +0000
18706 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit.c 2014-02-01 00:22:08.000000000 +0000
18709 + * linux/kernel/vserver/limit.c
18711 + * Virtual Server: Context Limits
18713 + * Copyright (C) 2004-2010 Herbert Pötzl
18715 + * V0.01 broken out from vcontext V0.05
18716 + * V0.02 changed vcmds to vxi arg
18717 + * V0.03 added memory cgroup support
18721 +#include <linux/sched.h>
18722 +#include <linux/module.h>
18723 +#include <linux/memcontrol.h>
18724 +#include <linux/res_counter.h>
18725 +#include <linux/vs_limit.h>
18726 +#include <linux/vserver/limit.h>
18727 +#include <linux/vserver/limit_cmd.h>
18729 +#include <asm/uaccess.h>
18732 +const char *vlimit_name[NUM_LIMITS] = {
18733 + [RLIMIT_CPU] = "CPU",
18734 + [RLIMIT_NPROC] = "NPROC",
18735 + [RLIMIT_NOFILE] = "NOFILE",
18736 + [RLIMIT_LOCKS] = "LOCKS",
18737 + [RLIMIT_SIGPENDING] = "SIGP",
18738 + [RLIMIT_MSGQUEUE] = "MSGQ",
18740 + [VLIMIT_NSOCK] = "NSOCK",
18741 + [VLIMIT_OPENFD] = "OPENFD",
18742 + [VLIMIT_SHMEM] = "SHMEM",
18743 + [VLIMIT_DENTRY] = "DENTRY",
18746 +EXPORT_SYMBOL_GPL(vlimit_name);
18748 +#define MASK_ENTRY(x) (1 << (x))
18750 +const struct vcmd_ctx_rlimit_mask_v0 vlimit_mask = {
18753 + , /* softlimit */
18756 + MASK_ENTRY( RLIMIT_NPROC ) |
18757 + MASK_ENTRY( RLIMIT_NOFILE ) |
18758 + MASK_ENTRY( RLIMIT_LOCKS ) |
18759 + MASK_ENTRY( RLIMIT_MSGQUEUE ) |
18761 + MASK_ENTRY( VLIMIT_NSOCK ) |
18762 + MASK_ENTRY( VLIMIT_OPENFD ) |
18763 + MASK_ENTRY( VLIMIT_SHMEM ) |
18764 + MASK_ENTRY( VLIMIT_DENTRY ) |
18767 + /* accounting only */
18768 +uint32_t account_mask =
18769 + MASK_ENTRY( VLIMIT_SEMARY ) |
18770 + MASK_ENTRY( VLIMIT_NSEMS ) |
18771 + MASK_ENTRY( VLIMIT_MAPPED ) |
18775 +static int is_valid_vlimit(int id)
18777 + uint32_t mask = vlimit_mask.minimum |
18778 + vlimit_mask.softlimit | vlimit_mask.maximum;
18779 + return mask & (1 << id);
18782 +static int is_accounted_vlimit(int id)
18784 + if (is_valid_vlimit(id))
18786 + return account_mask & (1 << id);
18790 +static inline uint64_t vc_get_soft(struct vx_info *vxi, int id)
18792 + rlim_t limit = __rlim_soft(&vxi->limit, id);
18793 + return VX_VLIM(limit);
18796 +static inline uint64_t vc_get_hard(struct vx_info *vxi, int id)
18798 + rlim_t limit = __rlim_hard(&vxi->limit, id);
18799 + return VX_VLIM(limit);
18802 +static int do_get_rlimit(struct vx_info *vxi, uint32_t id,
18803 + uint64_t *minimum, uint64_t *softlimit, uint64_t *maximum)
18805 + if (!is_valid_vlimit(id))
18809 + *minimum = CRLIM_UNSET;
18811 + *softlimit = vc_get_soft(vxi, id);
18813 + *maximum = vc_get_hard(vxi, id);
18817 +int vc_get_rlimit(struct vx_info *vxi, void __user *data)
18819 + struct vcmd_ctx_rlimit_v0 vc_data;
18822 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18825 + ret = do_get_rlimit(vxi, vc_data.id,
18826 + &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18830 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18835 +static int do_set_rlimit(struct vx_info *vxi, uint32_t id,
18836 + uint64_t minimum, uint64_t softlimit, uint64_t maximum)
18838 + if (!is_valid_vlimit(id))
18841 + if (maximum != CRLIM_KEEP)
18842 + __rlim_hard(&vxi->limit, id) = VX_RLIM(maximum);
18843 + if (softlimit != CRLIM_KEEP)
18844 + __rlim_soft(&vxi->limit, id) = VX_RLIM(softlimit);
18846 + /* clamp soft limit */
18847 + if (__rlim_soft(&vxi->limit, id) > __rlim_hard(&vxi->limit, id))
18848 + __rlim_soft(&vxi->limit, id) = __rlim_hard(&vxi->limit, id);
18853 +int vc_set_rlimit(struct vx_info *vxi, void __user *data)
18855 + struct vcmd_ctx_rlimit_v0 vc_data;
18857 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18860 + return do_set_rlimit(vxi, vc_data.id,
18861 + vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18864 +#ifdef CONFIG_IA32_EMULATION
18866 +int vc_set_rlimit_x32(struct vx_info *vxi, void __user *data)
18868 + struct vcmd_ctx_rlimit_v0_x32 vc_data;
18870 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18873 + return do_set_rlimit(vxi, vc_data.id,
18874 + vc_data.minimum, vc_data.softlimit, vc_data.maximum);
18877 +int vc_get_rlimit_x32(struct vx_info *vxi, void __user *data)
18879 + struct vcmd_ctx_rlimit_v0_x32 vc_data;
18882 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18885 + ret = do_get_rlimit(vxi, vc_data.id,
18886 + &vc_data.minimum, &vc_data.softlimit, &vc_data.maximum);
18890 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18895 +#endif /* CONFIG_IA32_EMULATION */
18898 +int vc_get_rlimit_mask(uint32_t id, void __user *data)
18900 + if (copy_to_user(data, &vlimit_mask, sizeof(vlimit_mask)))
18906 +static inline void vx_reset_hits(struct _vx_limit *limit)
18910 + for (lim = 0; lim < NUM_LIMITS; lim++) {
18911 + atomic_set(&__rlim_lhit(limit, lim), 0);
18915 +int vc_reset_hits(struct vx_info *vxi, void __user *data)
18917 + vx_reset_hits(&vxi->limit);
18921 +static inline void vx_reset_minmax(struct _vx_limit *limit)
18926 + for (lim = 0; lim < NUM_LIMITS; lim++) {
18927 + value = __rlim_get(limit, lim);
18928 + __rlim_rmax(limit, lim) = value;
18929 + __rlim_rmin(limit, lim) = value;
18933 +int vc_reset_minmax(struct vx_info *vxi, void __user *data)
18935 + vx_reset_minmax(&vxi->limit);
18940 +int vc_rlimit_stat(struct vx_info *vxi, void __user *data)
18942 + struct vcmd_rlimit_stat_v0 vc_data;
18943 + struct _vx_limit *limit = &vxi->limit;
18946 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
18950 + if (!is_accounted_vlimit(id))
18953 + vx_limit_fixup(limit, id);
18954 + vc_data.hits = atomic_read(&__rlim_lhit(limit, id));
18955 + vc_data.value = __rlim_get(limit, id);
18956 + vc_data.minimum = __rlim_rmin(limit, id);
18957 + vc_data.maximum = __rlim_rmax(limit, id);
18959 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
18965 +void vx_vsi_meminfo(struct sysinfo *val)
18967 +#ifdef CONFIG_MEMCG
18968 + struct mem_cgroup *mcg;
18969 + u64 res_limit, res_usage;
18972 + mcg = mem_cgroup_from_task(current);
18973 + rcu_read_unlock();
18977 + res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
18978 + res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
18980 + if (res_limit != RES_COUNTER_MAX)
18981 + val->totalram = (res_limit >> PAGE_SHIFT);
18982 + val->freeram = val->totalram - (res_usage >> PAGE_SHIFT);
18983 + val->bufferram = 0;
18984 + val->totalhigh = 0;
18985 + val->freehigh = 0;
18987 +#endif /* CONFIG_MEMCG */
18991 +void vx_vsi_swapinfo(struct sysinfo *val)
18993 +#ifdef CONFIG_MEMCG
18994 +#ifdef CONFIG_MEMCG_SWAP
18995 + struct mem_cgroup *mcg;
18996 + u64 res_limit, res_usage, memsw_limit, memsw_usage;
18997 + s64 swap_limit, swap_usage;
19000 + mcg = mem_cgroup_from_task(current);
19001 + rcu_read_unlock();
19005 + res_limit = mem_cgroup_res_read_u64(mcg, RES_LIMIT);
19006 + res_usage = mem_cgroup_res_read_u64(mcg, RES_USAGE);
19007 + memsw_limit = mem_cgroup_memsw_read_u64(mcg, RES_LIMIT);
19008 + memsw_usage = mem_cgroup_memsw_read_u64(mcg, RES_USAGE);
19010 + /* memory unlimited */
19011 + if (res_limit == RES_COUNTER_MAX)
19014 + swap_limit = memsw_limit - res_limit;
19015 + /* we have a swap limit? */
19016 + if (memsw_limit != RES_COUNTER_MAX)
19017 + val->totalswap = swap_limit >> PAGE_SHIFT;
19019 + /* calculate swap part */
19020 + swap_usage = (memsw_usage > res_usage) ?
19021 + memsw_usage - res_usage : 0;
19023 + /* total shown minus usage gives free swap */
19024 + val->freeswap = (swap_usage < swap_limit) ?
19025 + val->totalswap - (swap_usage >> PAGE_SHIFT) : 0;
19027 +#else /* !CONFIG_MEMCG_SWAP */
19028 + val->totalswap = 0;
19029 + val->freeswap = 0;
19030 +#endif /* !CONFIG_MEMCG_SWAP */
19031 +#endif /* CONFIG_MEMCG */
19035 +long vx_vsi_cached(struct sysinfo *val)
19038 +#ifdef CONFIG_MEMCG
19039 + struct mem_cgroup *mcg;
19042 + mcg = mem_cgroup_from_task(current);
19043 + rcu_read_unlock();
19047 + cache = mem_cgroup_stat_read_cache(mcg);
19053 diff -NurpP --minimal linux-3.13.10/kernel/vserver/limit_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_init.h
19054 --- linux-3.13.10/kernel/vserver/limit_init.h 1970-01-01 00:00:00.000000000 +0000
19055 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_init.h 2014-01-31 20:38:04.000000000 +0000
19059 +static inline void vx_info_init_limit(struct _vx_limit *limit)
19063 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19064 + __rlim_soft(limit, lim) = RLIM_INFINITY;
19065 + __rlim_hard(limit, lim) = RLIM_INFINITY;
19066 + __rlim_set(limit, lim, 0);
19067 + atomic_set(&__rlim_lhit(limit, lim), 0);
19068 + __rlim_rmin(limit, lim) = 0;
19069 + __rlim_rmax(limit, lim) = 0;
19073 +static inline void vx_info_exit_limit(struct _vx_limit *limit)
19078 + for (lim = 0; lim < NUM_LIMITS; lim++) {
19079 + if ((1 << lim) & VLIM_NOCHECK)
19081 + value = __rlim_get(limit, lim);
19082 + vxwprintk_xid(value,
19083 + "!!! limit: %p[%s,%d] = %ld on exit.",
19084 + limit, vlimit_name[lim], lim, (long)value);
19088 diff -NurpP --minimal linux-3.13.10/kernel/vserver/limit_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_proc.h
19089 --- linux-3.13.10/kernel/vserver/limit_proc.h 1970-01-01 00:00:00.000000000 +0000
19090 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/limit_proc.h 2014-01-31 20:38:04.000000000 +0000
19092 +#ifndef _VX_LIMIT_PROC_H
19093 +#define _VX_LIMIT_PROC_H
19095 +#include <linux/vserver/limit_int.h>
19098 +#define VX_LIMIT_FMT ":\t%8ld\t%8ld/%8ld\t%8lld/%8lld\t%6d\n"
19099 +#define VX_LIMIT_TOP \
19100 + "Limit\t current\t min/max\t\t soft/hard\t\thits\n"
19102 +#define VX_LIMIT_ARG(r) \
19103 + (unsigned long)__rlim_get(limit, r), \
19104 + (unsigned long)__rlim_rmin(limit, r), \
19105 + (unsigned long)__rlim_rmax(limit, r), \
19106 + VX_VLIM(__rlim_soft(limit, r)), \
19107 + VX_VLIM(__rlim_hard(limit, r)), \
19108 + atomic_read(&__rlim_lhit(limit, r))
19110 +static inline int vx_info_proc_limit(struct _vx_limit *limit, char *buffer)
19112 + vx_limit_fixup(limit, -1);
19113 + return sprintf(buffer, VX_LIMIT_TOP
19114 + "PROC" VX_LIMIT_FMT
19115 + "VM" VX_LIMIT_FMT
19116 + "VML" VX_LIMIT_FMT
19117 + "RSS" VX_LIMIT_FMT
19118 + "ANON" VX_LIMIT_FMT
19119 + "RMAP" VX_LIMIT_FMT
19120 + "FILES" VX_LIMIT_FMT
19121 + "OFD" VX_LIMIT_FMT
19122 + "LOCKS" VX_LIMIT_FMT
19123 + "SOCK" VX_LIMIT_FMT
19124 + "MSGQ" VX_LIMIT_FMT
19125 + "SHM" VX_LIMIT_FMT
19126 + "SEMA" VX_LIMIT_FMT
19127 + "SEMS" VX_LIMIT_FMT
19128 + "DENT" VX_LIMIT_FMT,
19129 + VX_LIMIT_ARG(RLIMIT_NPROC),
19130 + VX_LIMIT_ARG(RLIMIT_AS),
19131 + VX_LIMIT_ARG(RLIMIT_MEMLOCK),
19132 + VX_LIMIT_ARG(RLIMIT_RSS),
19133 + VX_LIMIT_ARG(VLIMIT_ANON),
19134 + VX_LIMIT_ARG(VLIMIT_MAPPED),
19135 + VX_LIMIT_ARG(RLIMIT_NOFILE),
19136 + VX_LIMIT_ARG(VLIMIT_OPENFD),
19137 + VX_LIMIT_ARG(RLIMIT_LOCKS),
19138 + VX_LIMIT_ARG(VLIMIT_NSOCK),
19139 + VX_LIMIT_ARG(RLIMIT_MSGQUEUE),
19140 + VX_LIMIT_ARG(VLIMIT_SHMEM),
19141 + VX_LIMIT_ARG(VLIMIT_SEMARY),
19142 + VX_LIMIT_ARG(VLIMIT_NSEMS),
19143 + VX_LIMIT_ARG(VLIMIT_DENTRY));
19146 +#endif /* _VX_LIMIT_PROC_H */
19149 diff -NurpP --minimal linux-3.13.10/kernel/vserver/network.c linux-3.13.10-vs2.3.6.11/kernel/vserver/network.c
19150 --- linux-3.13.10/kernel/vserver/network.c 1970-01-01 00:00:00.000000000 +0000
19151 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/network.c 2014-01-31 20:38:04.000000000 +0000
19154 + * linux/kernel/vserver/network.c
19156 + * Virtual Server: Network Support
19158 + * Copyright (C) 2003-2007 Herbert Pötzl
19160 + * V0.01 broken out from vcontext V0.05
19161 + * V0.02 cleaned up implementation
19162 + * V0.03 added equiv nx commands
19163 + * V0.04 switch to RCU based hash
19164 + * V0.05 and back to locking again
19165 + * V0.06 changed vcmds to nxi arg
19166 + * V0.07 have __create claim() the nxi
19170 +#include <linux/err.h>
19171 +#include <linux/slab.h>
19172 +#include <linux/rcupdate.h>
19173 +#include <net/ipv6.h>
19175 +#include <linux/vs_network.h>
19176 +#include <linux/vs_pid.h>
19177 +#include <linux/vserver/network_cmd.h>
19180 +atomic_t nx_global_ctotal = ATOMIC_INIT(0);
19181 +atomic_t nx_global_cactive = ATOMIC_INIT(0);
19183 +static struct kmem_cache *nx_addr_v4_cachep = NULL;
19184 +static struct kmem_cache *nx_addr_v6_cachep = NULL;
19187 +static int __init init_network(void)
19189 + nx_addr_v4_cachep = kmem_cache_create("nx_v4_addr_cache",
19190 + sizeof(struct nx_addr_v4), 0,
19191 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19192 + nx_addr_v6_cachep = kmem_cache_create("nx_v6_addr_cache",
19193 + sizeof(struct nx_addr_v6), 0,
19194 + SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
19199 +/* __alloc_nx_addr_v4() */
19201 +static inline struct nx_addr_v4 *__alloc_nx_addr_v4(void)
19203 + struct nx_addr_v4 *nxa = kmem_cache_alloc(
19204 + nx_addr_v4_cachep, GFP_KERNEL);
19206 + if (!IS_ERR(nxa))
19207 + memset(nxa, 0, sizeof(*nxa));
19211 +/* __dealloc_nx_addr_v4() */
19213 +static inline void __dealloc_nx_addr_v4(struct nx_addr_v4 *nxa)
19215 + kmem_cache_free(nx_addr_v4_cachep, nxa);
19218 +/* __dealloc_nx_addr_v4_all() */
19220 +static inline void __dealloc_nx_addr_v4_all(struct nx_addr_v4 *nxa)
19223 + struct nx_addr_v4 *next = nxa->next;
19225 + __dealloc_nx_addr_v4(nxa);
19231 +#ifdef CONFIG_IPV6
19233 +/* __alloc_nx_addr_v6() */
19235 +static inline struct nx_addr_v6 *__alloc_nx_addr_v6(void)
19237 + struct nx_addr_v6 *nxa = kmem_cache_alloc(
19238 + nx_addr_v6_cachep, GFP_KERNEL);
19240 + if (!IS_ERR(nxa))
19241 + memset(nxa, 0, sizeof(*nxa));
19245 +/* __dealloc_nx_addr_v6() */
19247 +static inline void __dealloc_nx_addr_v6(struct nx_addr_v6 *nxa)
19249 + kmem_cache_free(nx_addr_v6_cachep, nxa);
19252 +/* __dealloc_nx_addr_v6_all() */
19254 +static inline void __dealloc_nx_addr_v6_all(struct nx_addr_v6 *nxa)
19257 + struct nx_addr_v6 *next = nxa->next;
19259 + __dealloc_nx_addr_v6(nxa);
19264 +#endif /* CONFIG_IPV6 */
19266 +/* __alloc_nx_info()
19268 + * allocate an initialized nx_info struct
19269 + * doesn't make it visible (hash) */
19271 +static struct nx_info *__alloc_nx_info(vnid_t nid)
19273 + struct nx_info *new = NULL;
19275 + vxdprintk(VXD_CBIT(nid, 1), "alloc_nx_info(%d)*", nid);
19277 + /* would this benefit from a slab cache? */
19278 + new = kmalloc(sizeof(struct nx_info), GFP_KERNEL);
19282 + memset(new, 0, sizeof(struct nx_info));
19283 + new->nx_id = nid;
19284 + INIT_HLIST_NODE(&new->nx_hlist);
19285 + atomic_set(&new->nx_usecnt, 0);
19286 + atomic_set(&new->nx_tasks, 0);
19287 + spin_lock_init(&new->addr_lock);
19288 + new->nx_state = 0;
19290 + new->nx_flags = NXF_INIT_SET;
19292 + /* rest of init goes here */
19294 + new->v4_lback.s_addr = htonl(INADDR_LOOPBACK);
19295 + new->v4_bcast.s_addr = htonl(INADDR_BROADCAST);
19297 + vxdprintk(VXD_CBIT(nid, 0),
19298 + "alloc_nx_info(%d) = %p", nid, new);
19299 + atomic_inc(&nx_global_ctotal);
19303 +/* __dealloc_nx_info()
19305 + * final disposal of nx_info */
19307 +static void __dealloc_nx_info(struct nx_info *nxi)
19309 + vxdprintk(VXD_CBIT(nid, 0),
19310 + "dealloc_nx_info(%p)", nxi);
19312 + nxi->nx_hlist.next = LIST_POISON1;
19315 + BUG_ON(atomic_read(&nxi->nx_usecnt));
19316 + BUG_ON(atomic_read(&nxi->nx_tasks));
19318 + __dealloc_nx_addr_v4_all(nxi->v4.next);
19319 +#ifdef CONFIG_IPV6
19320 + __dealloc_nx_addr_v6_all(nxi->v6.next);
19323 + nxi->nx_state |= NXS_RELEASED;
19325 + atomic_dec(&nx_global_ctotal);
19328 +static void __shutdown_nx_info(struct nx_info *nxi)
19330 + nxi->nx_state |= NXS_SHUTDOWN;
19331 + vs_net_change(nxi, VSC_NETDOWN);
19334 +/* exported stuff */
19336 +void free_nx_info(struct nx_info *nxi)
19338 + /* context shutdown is mandatory */
19339 + BUG_ON(nxi->nx_state != NXS_SHUTDOWN);
19341 + /* context must not be hashed */
19342 + BUG_ON(nxi->nx_state & NXS_HASHED);
19344 + BUG_ON(atomic_read(&nxi->nx_usecnt));
19345 + BUG_ON(atomic_read(&nxi->nx_tasks));
19347 + __dealloc_nx_info(nxi);
19351 +void __nx_set_lback(struct nx_info *nxi)
19353 + int nid = nxi->nx_id;
19354 + __be32 lback = htonl(INADDR_LOOPBACK ^ ((nid & 0xFFFF) << 8));
19356 + nxi->v4_lback.s_addr = lback;
19359 +extern int __nx_inet_add_lback(__be32 addr);
19360 +extern int __nx_inet_del_lback(__be32 addr);
19363 +/* hash table for nx_info hash */
19365 +#define NX_HASH_SIZE 13
19367 +struct hlist_head nx_info_hash[NX_HASH_SIZE];
19369 +static DEFINE_SPINLOCK(nx_info_hash_lock);
19372 +static inline unsigned int __hashval(vnid_t nid)
19374 + return (nid % NX_HASH_SIZE);
19379 +/* __hash_nx_info()
19381 + * add the nxi to the global hash table
19382 + * requires the hash_lock to be held */
19384 +static inline void __hash_nx_info(struct nx_info *nxi)
19386 + struct hlist_head *head;
19388 + vxd_assert_lock(&nx_info_hash_lock);
19389 + vxdprintk(VXD_CBIT(nid, 4),
19390 + "__hash_nx_info: %p[#%d]", nxi, nxi->nx_id);
19392 + /* context must not be hashed */
19393 + BUG_ON(nx_info_state(nxi, NXS_HASHED));
19395 + nxi->nx_state |= NXS_HASHED;
19396 + head = &nx_info_hash[__hashval(nxi->nx_id)];
19397 + hlist_add_head(&nxi->nx_hlist, head);
19398 + atomic_inc(&nx_global_cactive);
19401 +/* __unhash_nx_info()
19403 + * remove the nxi from the global hash table
19404 + * requires the hash_lock to be held */
19406 +static inline void __unhash_nx_info(struct nx_info *nxi)
19408 + vxd_assert_lock(&nx_info_hash_lock);
19409 + vxdprintk(VXD_CBIT(nid, 4),
19410 + "__unhash_nx_info: %p[#%d.%d.%d]", nxi, nxi->nx_id,
19411 + atomic_read(&nxi->nx_usecnt), atomic_read(&nxi->nx_tasks));
19413 + /* context must be hashed */
19414 + BUG_ON(!nx_info_state(nxi, NXS_HASHED));
19415 + /* but without tasks */
19416 + BUG_ON(atomic_read(&nxi->nx_tasks));
19418 + nxi->nx_state &= ~NXS_HASHED;
19419 + hlist_del(&nxi->nx_hlist);
19420 + atomic_dec(&nx_global_cactive);
19424 +/* __lookup_nx_info()
19426 + * requires the hash_lock to be held
19427 + * doesn't increment the nx_refcnt */
19429 +static inline struct nx_info *__lookup_nx_info(vnid_t nid)
19431 + struct hlist_head *head = &nx_info_hash[__hashval(nid)];
19432 + struct hlist_node *pos;
19433 + struct nx_info *nxi;
19435 + vxd_assert_lock(&nx_info_hash_lock);
19436 + hlist_for_each(pos, head) {
19437 + nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19439 + if (nxi->nx_id == nid)
19444 + vxdprintk(VXD_CBIT(nid, 0),
19445 + "__lookup_nx_info(#%u): %p[#%u]",
19446 + nid, nxi, nxi ? nxi->nx_id : 0);
19451 +/* __create_nx_info()
19453 + * create the requested context
19454 + * get(), claim() and hash it */
19456 +static struct nx_info *__create_nx_info(int id)
19458 + struct nx_info *new, *nxi = NULL;
19460 + vxdprintk(VXD_CBIT(nid, 1), "create_nx_info(%d)*", id);
19462 + if (!(new = __alloc_nx_info(id)))
19463 + return ERR_PTR(-ENOMEM);
19465 + /* required to make dynamic xids unique */
19466 + spin_lock(&nx_info_hash_lock);
19468 + /* static context requested */
19469 + if ((nxi = __lookup_nx_info(id))) {
19470 + vxdprintk(VXD_CBIT(nid, 0),
19471 + "create_nx_info(%d) = %p (already there)", id, nxi);
19472 + if (nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19473 + nxi = ERR_PTR(-EBUSY);
19475 + nxi = ERR_PTR(-EEXIST);
19478 + /* new context */
19479 + vxdprintk(VXD_CBIT(nid, 0),
19480 + "create_nx_info(%d) = %p (new)", id, new);
19481 + claim_nx_info(new, NULL);
19482 + __nx_set_lback(new);
19483 + __hash_nx_info(get_nx_info(new));
19484 + nxi = new, new = NULL;
19487 + spin_unlock(&nx_info_hash_lock);
19489 + __dealloc_nx_info(new);
19495 +/* exported stuff */
19498 +void unhash_nx_info(struct nx_info *nxi)
19500 + __shutdown_nx_info(nxi);
19501 + spin_lock(&nx_info_hash_lock);
19502 + __unhash_nx_info(nxi);
19503 + spin_unlock(&nx_info_hash_lock);
19506 +/* lookup_nx_info()
19508 + * search for a nx_info and get() it
19509 + * negative id means current */
19511 +struct nx_info *lookup_nx_info(int id)
19513 + struct nx_info *nxi = NULL;
19516 + nxi = get_nx_info(current_nx_info());
19517 + } else if (id > 1) {
19518 + spin_lock(&nx_info_hash_lock);
19519 + nxi = get_nx_info(__lookup_nx_info(id));
19520 + spin_unlock(&nx_info_hash_lock);
19525 +/* nid_is_hashed()
19527 + * verify that nid is still hashed */
19529 +int nid_is_hashed(vnid_t nid)
19533 + spin_lock(&nx_info_hash_lock);
19534 + hashed = (__lookup_nx_info(nid) != NULL);
19535 + spin_unlock(&nx_info_hash_lock);
19540 +#ifdef CONFIG_PROC_FS
19544 + * get a subset of hashed nids for proc
19545 + * assumes size is at least one */
19547 +int get_nid_list(int index, unsigned int *nids, int size)
19549 + int hindex, nr_nids = 0;
19551 + /* only show current and children */
19552 + if (!nx_check(0, VS_ADMIN | VS_WATCH)) {
19555 + nids[nr_nids] = nx_current_nid();
19559 + for (hindex = 0; hindex < NX_HASH_SIZE; hindex++) {
19560 + struct hlist_head *head = &nx_info_hash[hindex];
19561 + struct hlist_node *pos;
19563 + spin_lock(&nx_info_hash_lock);
19564 + hlist_for_each(pos, head) {
19565 + struct nx_info *nxi;
19570 + nxi = hlist_entry(pos, struct nx_info, nx_hlist);
19571 + nids[nr_nids] = nxi->nx_id;
19572 + if (++nr_nids >= size) {
19573 + spin_unlock(&nx_info_hash_lock);
19577 + /* keep the lock time short */
19578 + spin_unlock(&nx_info_hash_lock);
19587 + * migrate task to new network
19588 + * gets nxi, puts old_nxi on change
19591 +int nx_migrate_task(struct task_struct *p, struct nx_info *nxi)
19593 + struct nx_info *old_nxi;
19599 + vxdprintk(VXD_CBIT(nid, 5),
19600 + "nx_migrate_task(%p,%p[#%d.%d.%d])",
19601 + p, nxi, nxi->nx_id,
19602 + atomic_read(&nxi->nx_usecnt),
19603 + atomic_read(&nxi->nx_tasks));
19605 + if (nx_info_flags(nxi, NXF_INFO_PRIVATE, 0) &&
19606 + !nx_info_flags(nxi, NXF_STATE_SETUP, 0))
19609 + if (nx_info_state(nxi, NXS_SHUTDOWN))
19612 + /* maybe disallow this completely? */
19613 + old_nxi = task_get_nx_info(p);
19614 + if (old_nxi == nxi)
19619 + clr_nx_info(&p->nx_info);
19620 + claim_nx_info(nxi, p);
19621 + set_nx_info(&p->nx_info, nxi);
19622 + p->nid = nxi->nx_id;
19625 + vxdprintk(VXD_CBIT(nid, 5),
19626 + "moved task %p into nxi:%p[#%d]",
19627 + p, nxi, nxi->nx_id);
19630 + release_nx_info(old_nxi, p);
19633 + put_nx_info(old_nxi);
19638 +void nx_set_persistent(struct nx_info *nxi)
19640 + vxdprintk(VXD_CBIT(nid, 6),
19641 + "nx_set_persistent(%p[#%d])", nxi, nxi->nx_id);
19643 + get_nx_info(nxi);
19644 + claim_nx_info(nxi, NULL);
19647 +void nx_clear_persistent(struct nx_info *nxi)
19649 + vxdprintk(VXD_CBIT(nid, 6),
19650 + "nx_clear_persistent(%p[#%d])", nxi, nxi->nx_id);
19652 + release_nx_info(nxi, NULL);
19653 + put_nx_info(nxi);
19656 +void nx_update_persistent(struct nx_info *nxi)
19658 + if (nx_info_flags(nxi, NXF_PERSISTENT, 0))
19659 + nx_set_persistent(nxi);
19661 + nx_clear_persistent(nxi);
19664 +/* vserver syscall commands below here */
19666 +/* taks nid and nx_info functions */
19668 +#include <asm/uaccess.h>
19671 +int vc_task_nid(uint32_t id)
19676 + struct task_struct *tsk;
19679 + tsk = find_task_by_real_pid(id);
19680 + nid = (tsk) ? tsk->nid : -ESRCH;
19681 + rcu_read_unlock();
19683 + nid = nx_current_nid();
19688 +int vc_nx_info(struct nx_info *nxi, void __user *data)
19690 + struct vcmd_nx_info_v0 vc_data;
19692 + vc_data.nid = nxi->nx_id;
19694 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
19700 +/* network functions */
19702 +int vc_net_create(uint32_t nid, void __user *data)
19704 + struct vcmd_net_create vc_data = { .flagword = NXF_INIT_SET };
19705 + struct nx_info *new_nxi;
19708 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19711 + if ((nid > MAX_S_CONTEXT) || (nid < 2))
19714 + new_nxi = __create_nx_info(nid);
19715 + if (IS_ERR(new_nxi))
19716 + return PTR_ERR(new_nxi);
19718 + /* initial flags */
19719 + new_nxi->nx_flags = vc_data.flagword;
19722 + if (vs_net_change(new_nxi, VSC_NETUP))
19725 + ret = nx_migrate_task(current, new_nxi);
19729 + /* return context id on success */
19730 + ret = new_nxi->nx_id;
19732 + /* get a reference for persistent contexts */
19733 + if ((vc_data.flagword & NXF_PERSISTENT))
19734 + nx_set_persistent(new_nxi);
19736 + release_nx_info(new_nxi, NULL);
19737 + put_nx_info(new_nxi);
19742 +int vc_net_migrate(struct nx_info *nxi, void __user *data)
19744 + return nx_migrate_task(current, nxi);
19749 +struct nx_addr_v4 *__find_v4_addr(struct nx_info *nxi,
19750 + __be32 ip, __be32 ip2, __be32 mask, uint16_t type, uint16_t flags,
19751 + struct nx_addr_v4 **prev)
19753 + struct nx_addr_v4 *nxa = &nxi->v4;
19755 + for (; nxa; nxa = nxa->next) {
19756 + if ((nxa->ip[0].s_addr == ip) &&
19757 + (nxa->ip[1].s_addr == ip2) &&
19758 + (nxa->mask.s_addr == mask) &&
19759 + (nxa->type == type) &&
19760 + (nxa->flags == flags))
19763 + /* save previous entry */
19770 +int do_add_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19771 + uint16_t type, uint16_t flags)
19773 + struct nx_addr_v4 *nxa = NULL;
19774 + struct nx_addr_v4 *new = __alloc_nx_addr_v4();
19775 + unsigned long irqflags;
19776 + int ret = -EEXIST;
19779 + return PTR_ERR(new);
19781 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
19782 + if (__find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa))
19785 + if (NX_IPV4(nxi)) {
19790 + /* remove single ip for ip list */
19791 + nxi->nx_flags &= ~NXF_SINGLE_IP;
19794 + nxa->ip[0].s_addr = ip;
19795 + nxa->ip[1].s_addr = ip2;
19796 + nxa->mask.s_addr = mask;
19797 + nxa->type = type;
19798 + nxa->flags = flags;
19801 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19803 + __dealloc_nx_addr_v4(new);
19807 +int do_remove_v4_addr(struct nx_info *nxi, __be32 ip, __be32 ip2, __be32 mask,
19808 + uint16_t type, uint16_t flags)
19810 + struct nx_addr_v4 *nxa = NULL;
19811 + struct nx_addr_v4 *old = NULL;
19812 + unsigned long irqflags;
19815 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
19817 + case NXA_TYPE_ADDR:
19818 + old = __find_v4_addr(nxi, ip, ip2, mask, type, flags, &nxa);
19821 + nxa->next = old->next;
19822 + old->next = NULL;
19828 + old->next = NULL;
19830 + memset(old, 0, sizeof(*old));
19838 + case NXA_TYPE_ANY:
19841 + memset(nxa, 0, sizeof(*nxa));
19847 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
19848 + __dealloc_nx_addr_v4_all(old);
19853 +int vc_net_add(struct nx_info *nxi, void __user *data)
19855 + struct vcmd_net_addr_v0 vc_data;
19856 + int index, ret = 0;
19858 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19861 + switch (vc_data.type) {
19862 + case NXA_TYPE_IPV4:
19863 + if ((vc_data.count < 1) || (vc_data.count > 4))
19867 + while (index < vc_data.count) {
19868 + ret = do_add_v4_addr(nxi, vc_data.ip[index].s_addr, 0,
19869 + vc_data.mask[index].s_addr, NXA_TYPE_ADDR, 0);
19877 + case NXA_TYPE_IPV4|NXA_MOD_BCAST:
19878 + nxi->v4_bcast = vc_data.ip[0];
19882 + case NXA_TYPE_IPV4|NXA_MOD_LBACK:
19883 + nxi->v4_lback = vc_data.ip[0];
19894 +int vc_net_remove(struct nx_info *nxi, void __user *data)
19896 + struct vcmd_net_addr_v0 vc_data;
19898 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19901 + switch (vc_data.type) {
19902 + case NXA_TYPE_ANY:
19903 + return do_remove_v4_addr(nxi, 0, 0, 0, vc_data.type, 0);
19911 +int vc_net_add_ipv4_v1(struct nx_info *nxi, void __user *data)
19913 + struct vcmd_net_addr_ipv4_v1 vc_data;
19915 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19918 + switch (vc_data.type) {
19919 + case NXA_TYPE_ADDR:
19920 + case NXA_TYPE_MASK:
19921 + return do_add_v4_addr(nxi, vc_data.ip.s_addr, 0,
19922 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19924 + case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19925 + nxi->v4_bcast = vc_data.ip;
19928 + case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19929 + nxi->v4_lback = vc_data.ip;
19938 +int vc_net_add_ipv4(struct nx_info *nxi, void __user *data)
19940 + struct vcmd_net_addr_ipv4_v2 vc_data;
19942 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19945 + switch (vc_data.type) {
19946 + case NXA_TYPE_ADDR:
19947 + case NXA_TYPE_MASK:
19948 + case NXA_TYPE_RANGE:
19949 + return do_add_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19950 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19952 + case NXA_TYPE_ADDR | NXA_MOD_BCAST:
19953 + nxi->v4_bcast = vc_data.ip;
19956 + case NXA_TYPE_ADDR | NXA_MOD_LBACK:
19957 + nxi->v4_lback = vc_data.ip;
19966 +int vc_net_rem_ipv4_v1(struct nx_info *nxi, void __user *data)
19968 + struct vcmd_net_addr_ipv4_v1 vc_data;
19970 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19973 + return do_remove_v4_addr(nxi, vc_data.ip.s_addr, 0,
19974 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19977 +int vc_net_rem_ipv4(struct nx_info *nxi, void __user *data)
19979 + struct vcmd_net_addr_ipv4_v2 vc_data;
19981 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
19984 + return do_remove_v4_addr(nxi, vc_data.ip.s_addr, vc_data.ip2.s_addr,
19985 + vc_data.mask.s_addr, vc_data.type, vc_data.flags);
19988 +#ifdef CONFIG_IPV6
19991 +struct nx_addr_v6 *__find_v6_addr(struct nx_info *nxi,
19992 + struct in6_addr *ip, struct in6_addr *mask,
19993 + uint32_t prefix, uint16_t type, uint16_t flags,
19994 + struct nx_addr_v6 **prev)
19996 + struct nx_addr_v6 *nxa = &nxi->v6;
19998 + for (; nxa; nxa = nxa->next) {
19999 + if (ipv6_addr_equal(&nxa->ip, ip) &&
20000 + ipv6_addr_equal(&nxa->mask, mask) &&
20001 + (nxa->prefix == prefix) &&
20002 + (nxa->type == type) &&
20003 + (nxa->flags == flags))
20006 + /* save previous entry */
20014 +int do_add_v6_addr(struct nx_info *nxi,
20015 + struct in6_addr *ip, struct in6_addr *mask,
20016 + uint32_t prefix, uint16_t type, uint16_t flags)
20018 + struct nx_addr_v6 *nxa = NULL;
20019 + struct nx_addr_v6 *new = __alloc_nx_addr_v6();
20020 + unsigned long irqflags;
20021 + int ret = -EEXIST;
20024 + return PTR_ERR(new);
20026 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20027 + if (__find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa))
20030 + if (NX_IPV6(nxi)) {
20037 + nxa->mask = *mask;
20038 + nxa->prefix = prefix;
20039 + nxa->type = type;
20040 + nxa->flags = flags;
20043 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20045 + __dealloc_nx_addr_v6(new);
20049 +int do_remove_v6_addr(struct nx_info *nxi,
20050 + struct in6_addr *ip, struct in6_addr *mask,
20051 + uint32_t prefix, uint16_t type, uint16_t flags)
20053 + struct nx_addr_v6 *nxa = NULL;
20054 + struct nx_addr_v6 *old = NULL;
20055 + unsigned long irqflags;
20058 + spin_lock_irqsave(&nxi->addr_lock, irqflags);
20060 + case NXA_TYPE_ADDR:
20061 + old = __find_v6_addr(nxi, ip, mask, prefix, type, flags, &nxa);
20064 + nxa->next = old->next;
20065 + old->next = NULL;
20071 + old->next = NULL;
20073 + memset(old, 0, sizeof(*old));
20081 + case NXA_TYPE_ANY:
20084 + memset(nxa, 0, sizeof(*nxa));
20090 + spin_unlock_irqrestore(&nxi->addr_lock, irqflags);
20091 + __dealloc_nx_addr_v6_all(old);
20095 +int vc_net_add_ipv6(struct nx_info *nxi, void __user *data)
20097 + struct vcmd_net_addr_ipv6_v1 vc_data;
20099 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20102 + switch (vc_data.type) {
20103 + case NXA_TYPE_ADDR:
20104 + memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20105 + /* fallthrough */
20106 + case NXA_TYPE_MASK:
20107 + return do_add_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20108 + vc_data.prefix, vc_data.type, vc_data.flags);
20115 +int vc_net_remove_ipv6(struct nx_info *nxi, void __user *data)
20117 + struct vcmd_net_addr_ipv6_v1 vc_data;
20119 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
20122 + switch (vc_data.type) {
20123 + case NXA_TYPE_ADDR:
20124 + memset(&vc_data.mask, ~0, sizeof(vc_data.mask));
20125 + /* fallthrough */
20126 + case NXA_TYPE_MASK:
20127 + return do_remove_v6_addr(nxi, &vc_data.ip, &vc_data.mask,
20128 + vc_data.prefix, vc_data.type, vc_data.flags);
20129 + case NXA_TYPE_ANY:
20130 + return do_remove_v6_addr(nxi, NULL, NULL, 0, vc_data.type, 0);
20137 +#endif /* CONFIG_IPV6 */
20140 +int vc_get_nflags(struct nx_info *nxi, void __user *data)
20142 + struct vcmd_net_flags_v0 vc_data;
20144 + vc_data.flagword = nxi->nx_flags;
20146 + /* special STATE flag handling */
20147 + vc_data.mask = vs_mask_flags(~0ULL, nxi->nx_flags, NXF_ONE_TIME);
20149 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20154 +int vc_set_nflags(struct nx_info *nxi, void __user *data)
20156 + struct vcmd_net_flags_v0 vc_data;
20157 + uint64_t mask, trigger;
20159 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20162 + /* special STATE flag handling */
20163 + mask = vs_mask_mask(vc_data.mask, nxi->nx_flags, NXF_ONE_TIME);
20164 + trigger = (mask & nxi->nx_flags) ^ (mask & vc_data.flagword);
20166 + nxi->nx_flags = vs_mask_flags(nxi->nx_flags,
20167 + vc_data.flagword, mask);
20168 + if (trigger & NXF_PERSISTENT)
20169 + nx_update_persistent(nxi);
20174 +int vc_get_ncaps(struct nx_info *nxi, void __user *data)
20176 + struct vcmd_net_caps_v0 vc_data;
20178 + vc_data.ncaps = nxi->nx_ncaps;
20179 + vc_data.cmask = ~0ULL;
20181 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
20186 +int vc_set_ncaps(struct nx_info *nxi, void __user *data)
20188 + struct vcmd_net_caps_v0 vc_data;
20190 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
20193 + nxi->nx_ncaps = vs_mask_flags(nxi->nx_ncaps,
20194 + vc_data.ncaps, vc_data.cmask);
20199 +#include <linux/module.h>
20201 +module_init(init_network);
20203 +EXPORT_SYMBOL_GPL(free_nx_info);
20204 +EXPORT_SYMBOL_GPL(unhash_nx_info);
20206 diff -NurpP --minimal linux-3.13.10/kernel/vserver/proc.c linux-3.13.10-vs2.3.6.11/kernel/vserver/proc.c
20207 --- linux-3.13.10/kernel/vserver/proc.c 1970-01-01 00:00:00.000000000 +0000
20208 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/proc.c 2014-02-01 01:21:49.000000000 +0000
20211 + * linux/kernel/vserver/proc.c
20213 + * Virtual Context Support
20215 + * Copyright (C) 2003-2011 Herbert Pötzl
20217 + * V0.01 basic structure
20218 + * V0.02 adaptation vs1.3.0
20219 + * V0.03 proc permissions
20220 + * V0.04 locking/generic
20221 + * V0.05 next generation procfs
20222 + * V0.06 inode validation
20223 + * V0.07 generic rewrite vid
20224 + * V0.08 remove inode type
20225 + * V0.09 added u/wmask info
20229 +#include <linux/proc_fs.h>
20230 +#include <linux/fs_struct.h>
20231 +#include <linux/mount.h>
20232 +#include <linux/namei.h>
20233 +#include <asm/unistd.h>
20235 +#include <linux/vs_context.h>
20236 +#include <linux/vs_network.h>
20237 +#include <linux/vs_cvirt.h>
20239 +#include <linux/in.h>
20240 +#include <linux/inetdevice.h>
20241 +#include <linux/vs_inet.h>
20242 +#include <linux/vs_inet6.h>
20244 +#include <linux/vserver/global.h>
20246 +#include "cvirt_proc.h"
20247 +#include "cacct_proc.h"
20248 +#include "limit_proc.h"
20249 +#include "sched_proc.h"
20250 +#include "vci_config.h"
20252 +#include <../../fs/proc/internal.h>
20255 +static inline char *print_cap_t(char *buffer, kernel_cap_t *c)
20259 + CAP_FOR_EACH_U32(__capi) {
20260 + buffer += sprintf(buffer, "%08x",
20261 + c->cap[(_KERNEL_CAPABILITY_U32S-1) - __capi]);
20267 +static struct proc_dir_entry *proc_virtual;
20269 +static struct proc_dir_entry *proc_virtnet;
20272 +/* first the actual feeds */
20275 +static int proc_vci(char *buffer)
20277 + return sprintf(buffer,
20278 + "VCIVersion:\t%04x:%04x\n"
20279 + "VCISyscall:\t%d\n"
20280 + "VCIKernel:\t%08x\n",
20281 + VCI_VERSION >> 16,
20282 + VCI_VERSION & 0xFFFF,
20284 + vci_kernel_config());
20287 +static int proc_virtual_info(char *buffer)
20289 + return proc_vci(buffer);
20292 +static int proc_virtual_status(char *buffer)
20294 + return sprintf(buffer,
20296 + "#CActive:\t%d\n"
20297 + "#NSProxy:\t%d\t%d %d %d %d %d %d\n"
20298 + "#InitTask:\t%d\t%d %d\n",
20299 + atomic_read(&vx_global_ctotal),
20300 + atomic_read(&vx_global_cactive),
20301 + atomic_read(&vs_global_nsproxy),
20302 + atomic_read(&vs_global_fs),
20303 + atomic_read(&vs_global_mnt_ns),
20304 + atomic_read(&vs_global_uts_ns),
20305 + atomic_read(&nr_ipc_ns),
20306 + atomic_read(&vs_global_user_ns),
20307 + atomic_read(&vs_global_pid_ns),
20308 + atomic_read(&init_task.usage),
20309 + atomic_read(&init_task.nsproxy->count),
20310 + init_task.fs->users);
20314 +int proc_vxi_info(struct vx_info *vxi, char *buffer)
20318 + length = sprintf(buffer,
20326 + vxi->vx_badness_bias);
20330 +int proc_vxi_status(struct vx_info *vxi, char *buffer)
20332 + char *orig = buffer;
20334 + buffer += sprintf(buffer,
20337 + "Flags:\t%016llx\n",
20338 + atomic_read(&vxi->vx_usecnt),
20339 + atomic_read(&vxi->vx_tasks),
20340 + (unsigned long long)vxi->vx_flags);
20342 + buffer += sprintf(buffer, "BCaps:\t");
20343 + buffer = print_cap_t(buffer, &vxi->vx_bcaps);
20344 + buffer += sprintf(buffer, "\n");
20346 + buffer += sprintf(buffer,
20347 + "CCaps:\t%016llx\n"
20348 + "Umask:\t%16llx\n"
20349 + "Wmask:\t%16llx\n"
20350 + "Spaces:\t%08lx %08lx\n",
20351 + (unsigned long long)vxi->vx_ccaps,
20352 + (unsigned long long)vxi->vx_umask,
20353 + (unsigned long long)vxi->vx_wmask,
20354 + vxi->space[0].vx_nsmask, vxi->space[1].vx_nsmask);
20355 + return buffer - orig;
20358 +int proc_vxi_limit(struct vx_info *vxi, char *buffer)
20360 + return vx_info_proc_limit(&vxi->limit, buffer);
20363 +int proc_vxi_sched(struct vx_info *vxi, char *buffer)
20367 + length = vx_info_proc_sched(&vxi->sched, buffer);
20368 + for_each_online_cpu(cpu) {
20369 + length += vx_info_proc_sched_pc(
20370 + &vx_per_cpu(vxi, sched_pc, cpu),
20371 + buffer + length, cpu);
20376 +int proc_vxi_nsproxy0(struct vx_info *vxi, char *buffer)
20378 + return vx_info_proc_nsproxy(vxi->space[0].vx_nsproxy, buffer);
20381 +int proc_vxi_nsproxy1(struct vx_info *vxi, char *buffer)
20383 + return vx_info_proc_nsproxy(vxi->space[1].vx_nsproxy, buffer);
20386 +int proc_vxi_cvirt(struct vx_info *vxi, char *buffer)
20390 + vx_update_load(vxi);
20391 + length = vx_info_proc_cvirt(&vxi->cvirt, buffer);
20392 + for_each_online_cpu(cpu) {
20393 + length += vx_info_proc_cvirt_pc(
20394 + &vx_per_cpu(vxi, cvirt_pc, cpu),
20395 + buffer + length, cpu);
20400 +int proc_vxi_cacct(struct vx_info *vxi, char *buffer)
20402 + return vx_info_proc_cacct(&vxi->cacct, buffer);
20406 +static int proc_virtnet_info(char *buffer)
20408 + return proc_vci(buffer);
20411 +static int proc_virtnet_status(char *buffer)
20413 + return sprintf(buffer,
20415 + "#CActive:\t%d\n",
20416 + atomic_read(&nx_global_ctotal),
20417 + atomic_read(&nx_global_cactive));
20420 +int proc_nxi_info(struct nx_info *nxi, char *buffer)
20422 + struct nx_addr_v4 *v4a;
20423 +#ifdef CONFIG_IPV6
20424 + struct nx_addr_v6 *v6a;
20428 + length = sprintf(buffer,
20431 + "Bcast:\t" NIPQUAD_FMT "\n"
20432 + "Lback:\t" NIPQUAD_FMT "\n",
20435 + NIPQUAD(nxi->v4_bcast.s_addr),
20436 + NIPQUAD(nxi->v4_lback.s_addr));
20438 + if (!NX_IPV4(nxi))
20440 + for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
20441 + length += sprintf(buffer + length, "%d:\t" NXAV4_FMT "\n",
20444 +#ifdef CONFIG_IPV6
20445 + if (!NX_IPV6(nxi))
20447 + for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
20448 + length += sprintf(buffer + length, "%d:\t" NXAV6_FMT "\n",
20455 +int proc_nxi_status(struct nx_info *nxi, char *buffer)
20459 + length = sprintf(buffer,
20462 + "Flags:\t%016llx\n"
20463 + "NCaps:\t%016llx\n",
20464 + atomic_read(&nxi->nx_usecnt),
20465 + atomic_read(&nxi->nx_tasks),
20466 + (unsigned long long)nxi->nx_flags,
20467 + (unsigned long long)nxi->nx_ncaps);
20473 +/* here the inode helpers */
20479 + struct inode_operations *iop;
20480 + struct file_operations *fop;
20481 + union proc_op op;
20484 +static struct inode *vs_proc_make_inode(struct super_block *sb, struct vs_entry *p)
20486 + struct inode *inode = new_inode(sb);
20491 + inode->i_mode = p->mode;
20493 + inode->i_op = p->iop;
20495 + inode->i_fop = p->fop;
20497 + set_nlink(inode, (p->mode & S_IFDIR) ? 2 : 1);
20498 + inode->i_flags |= S_IMMUTABLE;
20500 + inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
20502 + i_uid_write(inode, 0);
20503 + i_gid_write(inode, 0);
20504 + i_tag_write(inode, 0);
20509 +static struct dentry *vs_proc_instantiate(struct inode *dir,
20510 + struct dentry *dentry, int id, void *ptr)
20512 + struct vs_entry *p = ptr;
20513 + struct inode *inode = vs_proc_make_inode(dir->i_sb, p);
20514 + struct dentry *error = ERR_PTR(-EINVAL);
20519 + PROC_I(inode)->op = p->op;
20520 + PROC_I(inode)->fd = id;
20521 + d_add(dentry, inode);
20529 +typedef struct dentry *vx_instantiate_t(struct inode *, struct dentry *, int, void *);
20533 + * Fill a directory entry.
20535 + * If possible create the dcache entry and derive our inode number and
20536 + * file type from dcache entry.
20538 + * Since all of the proc inode numbers are dynamically generated, the inode
20539 + * numbers do not exist until the inode is cache. This means creating the
20540 + * the dcache entry in iterate is necessary to keep the inode numbers
20541 + * reported by iterate in sync with the inode numbers reported
20544 +static int vx_proc_fill_cache(struct file *filp, struct dir_context *ctx,
20545 + char *name, int len, vx_instantiate_t instantiate, int id, void *ptr)
20547 + struct dentry *child, *dir = filp->f_dentry;
20548 + struct inode *inode;
20549 + struct qstr qname;
20551 + unsigned type = DT_UNKNOWN;
20553 + qname.name = name;
20555 + qname.hash = full_name_hash(name, len);
20557 + child = d_lookup(dir, &qname);
20559 + struct dentry *new;
20560 + new = d_alloc(dir, &qname);
20562 + child = instantiate(dir->d_inode, new, id, ptr);
20569 + if (!child || IS_ERR(child) || !child->d_inode)
20570 + goto end_instantiate;
20571 + inode = child->d_inode;
20573 + ino = inode->i_ino;
20574 + type = inode->i_mode >> 12;
20580 + return !dir_emit(ctx, name, len, ino, type);
20585 +/* get and revalidate vx_info/xid */
20588 +struct vx_info *get_proc_vx_info(struct inode *inode)
20590 + return lookup_vx_info(PROC_I(inode)->fd);
20593 +static int proc_xid_revalidate(struct dentry *dentry, unsigned int flags)
20595 + struct inode *inode = dentry->d_inode;
20596 + vxid_t xid = PROC_I(inode)->fd;
20598 + if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20601 + if (!xid || xid_is_hashed(xid))
20608 +/* get and revalidate nx_info/nid */
20610 +static int proc_nid_revalidate(struct dentry *dentry, unsigned int flags)
20612 + struct inode *inode = dentry->d_inode;
20613 + vnid_t nid = PROC_I(inode)->fd;
20615 + if (flags & LOOKUP_RCU) /* FIXME: can be dropped? */
20618 + if (!nid || nid_is_hashed(nid))
20626 +#define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
20628 +static ssize_t proc_vs_info_read(struct file *file, char __user *buf,
20629 + size_t count, loff_t *ppos)
20631 + struct inode *inode = file->f_dentry->d_inode;
20632 + unsigned long page;
20633 + ssize_t length = 0;
20635 + if (count > PROC_BLOCK_SIZE)
20636 + count = PROC_BLOCK_SIZE;
20638 + /* fade that out as soon as stable */
20639 + WARN_ON(PROC_I(inode)->fd);
20641 + if (!(page = __get_free_page(GFP_KERNEL)))
20644 + BUG_ON(!PROC_I(inode)->op.proc_vs_read);
20645 + length = PROC_I(inode)->op.proc_vs_read((char *)page);
20648 + length = simple_read_from_buffer(buf, count, ppos,
20649 + (char *)page, length);
20655 +static ssize_t proc_vx_info_read(struct file *file, char __user *buf,
20656 + size_t count, loff_t *ppos)
20658 + struct inode *inode = file->f_dentry->d_inode;
20659 + struct vx_info *vxi = NULL;
20660 + vxid_t xid = PROC_I(inode)->fd;
20661 + unsigned long page;
20662 + ssize_t length = 0;
20664 + if (count > PROC_BLOCK_SIZE)
20665 + count = PROC_BLOCK_SIZE;
20667 + /* fade that out as soon as stable */
20669 + vxi = lookup_vx_info(xid);
20673 + length = -ENOMEM;
20674 + if (!(page = __get_free_page(GFP_KERNEL)))
20677 + BUG_ON(!PROC_I(inode)->op.proc_vxi_read);
20678 + length = PROC_I(inode)->op.proc_vxi_read(vxi, (char *)page);
20681 + length = simple_read_from_buffer(buf, count, ppos,
20682 + (char *)page, length);
20686 + put_vx_info(vxi);
20691 +static ssize_t proc_nx_info_read(struct file *file, char __user *buf,
20692 + size_t count, loff_t *ppos)
20694 + struct inode *inode = file->f_dentry->d_inode;
20695 + struct nx_info *nxi = NULL;
20696 + vnid_t nid = PROC_I(inode)->fd;
20697 + unsigned long page;
20698 + ssize_t length = 0;
20700 + if (count > PROC_BLOCK_SIZE)
20701 + count = PROC_BLOCK_SIZE;
20703 + /* fade that out as soon as stable */
20705 + nxi = lookup_nx_info(nid);
20709 + length = -ENOMEM;
20710 + if (!(page = __get_free_page(GFP_KERNEL)))
20713 + BUG_ON(!PROC_I(inode)->op.proc_nxi_read);
20714 + length = PROC_I(inode)->op.proc_nxi_read(nxi, (char *)page);
20717 + length = simple_read_from_buffer(buf, count, ppos,
20718 + (char *)page, length);
20722 + put_nx_info(nxi);
20729 +/* here comes the lower level */
20732 +#define NOD(NAME, MODE, IOP, FOP, OP) { \
20733 + .len = sizeof(NAME) - 1, \
20734 + .name = (NAME), \
20742 +#define DIR(NAME, MODE, OTYPE) \
20743 + NOD(NAME, (S_IFDIR | (MODE)), \
20744 + &proc_ ## OTYPE ## _inode_operations, \
20745 + &proc_ ## OTYPE ## _file_operations, { } )
20747 +#define INF(NAME, MODE, OTYPE) \
20748 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
20749 + &proc_vs_info_file_operations, \
20750 + { .proc_vs_read = &proc_##OTYPE } )
20752 +#define VINF(NAME, MODE, OTYPE) \
20753 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
20754 + &proc_vx_info_file_operations, \
20755 + { .proc_vxi_read = &proc_##OTYPE } )
20757 +#define NINF(NAME, MODE, OTYPE) \
20758 + NOD(NAME, (S_IFREG | (MODE)), NULL, \
20759 + &proc_nx_info_file_operations, \
20760 + { .proc_nxi_read = &proc_##OTYPE } )
20763 +static struct file_operations proc_vs_info_file_operations = {
20764 + .read = proc_vs_info_read,
20767 +static struct file_operations proc_vx_info_file_operations = {
20768 + .read = proc_vx_info_read,
20771 +static struct dentry_operations proc_xid_dentry_operations = {
20772 + .d_revalidate = proc_xid_revalidate,
20775 +static struct vs_entry vx_base_stuff[] = {
20776 + VINF("info", S_IRUGO, vxi_info),
20777 + VINF("status", S_IRUGO, vxi_status),
20778 + VINF("limit", S_IRUGO, vxi_limit),
20779 + VINF("sched", S_IRUGO, vxi_sched),
20780 + VINF("nsproxy", S_IRUGO, vxi_nsproxy0),
20781 + VINF("nsproxy1",S_IRUGO, vxi_nsproxy1),
20782 + VINF("cvirt", S_IRUGO, vxi_cvirt),
20783 + VINF("cacct", S_IRUGO, vxi_cacct),
20790 +static struct dentry *proc_xid_instantiate(struct inode *dir,
20791 + struct dentry *dentry, int id, void *ptr)
20793 + dentry->d_op = &proc_xid_dentry_operations;
20794 + return vs_proc_instantiate(dir, dentry, id, ptr);
20797 +static struct dentry *proc_xid_lookup(struct inode *dir,
20798 + struct dentry *dentry, unsigned int flags)
20800 + struct vs_entry *p = vx_base_stuff;
20801 + struct dentry *error = ERR_PTR(-ENOENT);
20803 + for (; p->name; p++) {
20804 + if (p->len != dentry->d_name.len)
20806 + if (!memcmp(dentry->d_name.name, p->name, p->len))
20812 + error = proc_xid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20817 +static int proc_xid_iterate(struct file *filp, struct dir_context *ctx)
20819 + struct dentry *dentry = filp->f_dentry;
20820 + struct inode *inode = dentry->d_inode;
20821 + struct vs_entry *p = vx_base_stuff;
20822 + int size = sizeof(vx_base_stuff) / sizeof(struct vs_entry);
20826 + switch (ctx->pos) {
20828 + ino = inode->i_ino;
20829 + if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20832 + /* fall through */
20834 + ino = parent_ino(dentry);
20835 + if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20838 + /* fall through */
20840 + index = ctx->pos - 2;
20841 + if (index >= size)
20843 + for (p += index; p->name; p++) {
20844 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20845 + vs_proc_instantiate, PROC_I(inode)->fd, p))
20856 +static struct file_operations proc_nx_info_file_operations = {
20857 + .read = proc_nx_info_read,
20860 +static struct dentry_operations proc_nid_dentry_operations = {
20861 + .d_revalidate = proc_nid_revalidate,
20864 +static struct vs_entry nx_base_stuff[] = {
20865 + NINF("info", S_IRUGO, nxi_info),
20866 + NINF("status", S_IRUGO, nxi_status),
20871 +static struct dentry *proc_nid_instantiate(struct inode *dir,
20872 + struct dentry *dentry, int id, void *ptr)
20874 + dentry->d_op = &proc_nid_dentry_operations;
20875 + return vs_proc_instantiate(dir, dentry, id, ptr);
20878 +static struct dentry *proc_nid_lookup(struct inode *dir,
20879 + struct dentry *dentry, unsigned int flags)
20881 + struct vs_entry *p = nx_base_stuff;
20882 + struct dentry *error = ERR_PTR(-ENOENT);
20884 + for (; p->name; p++) {
20885 + if (p->len != dentry->d_name.len)
20887 + if (!memcmp(dentry->d_name.name, p->name, p->len))
20893 + error = proc_nid_instantiate(dir, dentry, PROC_I(dir)->fd, p);
20898 +static int proc_nid_iterate(struct file *filp, struct dir_context *ctx)
20900 + struct dentry *dentry = filp->f_dentry;
20901 + struct inode *inode = dentry->d_inode;
20902 + struct vs_entry *p = nx_base_stuff;
20903 + int size = sizeof(nx_base_stuff) / sizeof(struct vs_entry);
20907 + switch (ctx->pos) {
20909 + ino = inode->i_ino;
20910 + if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
20913 + /* fall through */
20915 + ino = parent_ino(dentry);
20916 + if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
20919 + /* fall through */
20921 + index = ctx->pos - 2;
20922 + if (index >= size)
20924 + for (p += index; p->name; p++) {
20925 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
20926 + vs_proc_instantiate, PROC_I(inode)->fd, p))
20936 +#define MAX_MULBY10 ((~0U - 9) / 10)
20938 +static inline int atovid(const char *str, int len)
20943 + while (len-- > 0) {
20948 + if (vid >= MAX_MULBY10)
20958 +/* now the upper level (virtual) */
20961 +static struct file_operations proc_xid_file_operations = {
20962 + .read = generic_read_dir,
20963 + .iterate = proc_xid_iterate,
20966 +static struct inode_operations proc_xid_inode_operations = {
20967 + .lookup = proc_xid_lookup,
20970 +static struct vs_entry vx_virtual_stuff[] = {
20971 + INF("info", S_IRUGO, virtual_info),
20972 + INF("status", S_IRUGO, virtual_status),
20973 + DIR(NULL, S_IRUGO | S_IXUGO, xid),
20977 +static struct dentry *proc_virtual_lookup(struct inode *dir,
20978 + struct dentry *dentry, unsigned int flags)
20980 + struct vs_entry *p = vx_virtual_stuff;
20981 + struct dentry *error = ERR_PTR(-ENOENT);
20984 + for (; p->name; p++) {
20985 + if (p->len != dentry->d_name.len)
20987 + if (!memcmp(dentry->d_name.name, p->name, p->len))
20991 + goto instantiate;
20993 + id = atovid(dentry->d_name.name, dentry->d_name.len);
20994 + if ((id < 0) || !xid_is_hashed(id))
20998 + error = proc_xid_instantiate(dir, dentry, id, p);
21003 +static struct file_operations proc_nid_file_operations = {
21004 + .read = generic_read_dir,
21005 + .iterate = proc_nid_iterate,
21008 +static struct inode_operations proc_nid_inode_operations = {
21009 + .lookup = proc_nid_lookup,
21012 +static struct vs_entry nx_virtnet_stuff[] = {
21013 + INF("info", S_IRUGO, virtnet_info),
21014 + INF("status", S_IRUGO, virtnet_status),
21015 + DIR(NULL, S_IRUGO | S_IXUGO, nid),
21019 +static struct dentry *proc_virtnet_lookup(struct inode *dir,
21020 + struct dentry *dentry, unsigned int flags)
21022 + struct vs_entry *p = nx_virtnet_stuff;
21023 + struct dentry *error = ERR_PTR(-ENOENT);
21026 + for (; p->name; p++) {
21027 + if (p->len != dentry->d_name.len)
21029 + if (!memcmp(dentry->d_name.name, p->name, p->len))
21033 + goto instantiate;
21035 + id = atovid(dentry->d_name.name, dentry->d_name.len);
21036 + if ((id < 0) || !nid_is_hashed(id))
21040 + error = proc_nid_instantiate(dir, dentry, id, p);
21046 +#define PROC_MAXVIDS 32
21048 +int proc_virtual_iterate(struct file *filp, struct dir_context *ctx)
21050 + struct dentry *dentry = filp->f_dentry;
21051 + struct inode *inode = dentry->d_inode;
21052 + struct vs_entry *p = vx_virtual_stuff;
21053 + int size = sizeof(vx_virtual_stuff) / sizeof(struct vs_entry);
21055 + unsigned int xid_array[PROC_MAXVIDS];
21056 + char buf[PROC_NUMBUF];
21057 + unsigned int nr_xids, i;
21060 + switch (ctx->pos) {
21062 + ino = inode->i_ino;
21063 + if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21066 + /* fall through */
21068 + ino = parent_ino(dentry);
21069 + if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21072 + /* fall through */
21074 + index = ctx->pos - 2;
21075 + if (index >= size)
21077 + for (p += index; p->name; p++) {
21078 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21079 + vs_proc_instantiate, 0, p))
21084 + index = ctx->pos - size;
21085 + p = &vx_virtual_stuff[size - 1];
21086 + nr_xids = get_xid_list(index, xid_array, PROC_MAXVIDS);
21087 + for (i = 0; i < nr_xids; i++) {
21088 + int n, xid = xid_array[i];
21089 + unsigned int j = PROC_NUMBUF;
21093 + buf[--j] = '0' + (n % 10);
21096 + if (vx_proc_fill_cache(filp, ctx,
21097 + buf + j, PROC_NUMBUF - j,
21098 + vs_proc_instantiate, xid, p))
21107 +static int proc_virtual_getattr(struct vfsmount *mnt,
21108 + struct dentry *dentry, struct kstat *stat)
21110 + struct inode *inode = dentry->d_inode;
21112 + generic_fillattr(inode, stat);
21113 + stat->nlink = 2 + atomic_read(&vx_global_cactive);
21117 +static struct file_operations proc_virtual_dir_operations = {
21118 + .read = generic_read_dir,
21119 + .iterate = proc_virtual_iterate,
21122 +static struct inode_operations proc_virtual_dir_inode_operations = {
21123 + .getattr = proc_virtual_getattr,
21124 + .lookup = proc_virtual_lookup,
21129 +int proc_virtnet_iterate(struct file *filp, struct dir_context *ctx)
21131 + struct dentry *dentry = filp->f_dentry;
21132 + struct inode *inode = dentry->d_inode;
21133 + struct vs_entry *p = nx_virtnet_stuff;
21134 + int size = sizeof(nx_virtnet_stuff) / sizeof(struct vs_entry);
21136 + unsigned int nid_array[PROC_MAXVIDS];
21137 + char buf[PROC_NUMBUF];
21138 + unsigned int nr_nids, i;
21141 + switch (ctx->pos) {
21143 + ino = inode->i_ino;
21144 + if (!dir_emit(ctx, ".", 1, ino, DT_DIR) < 0)
21147 + /* fall through */
21149 + ino = parent_ino(dentry);
21150 + if (!dir_emit(ctx, "..", 2, ino, DT_DIR) < 0)
21153 + /* fall through */
21155 + index = ctx->pos - 2;
21156 + if (index >= size)
21158 + for (p += index; p->name; p++) {
21159 + if (vx_proc_fill_cache(filp, ctx, p->name, p->len,
21160 + vs_proc_instantiate, 0, p))
21165 + index = ctx->pos - size;
21166 + p = &nx_virtnet_stuff[size - 1];
21167 + nr_nids = get_nid_list(index, nid_array, PROC_MAXVIDS);
21168 + for (i = 0; i < nr_nids; i++) {
21169 + int n, nid = nid_array[i];
21170 + unsigned int j = PROC_NUMBUF;
21174 + buf[--j] = '0' + (n % 10);
21177 + if (vx_proc_fill_cache(filp, ctx,
21178 + buf + j, PROC_NUMBUF - j,
21179 + vs_proc_instantiate, nid, p))
21188 +static int proc_virtnet_getattr(struct vfsmount *mnt,
21189 + struct dentry *dentry, struct kstat *stat)
21191 + struct inode *inode = dentry->d_inode;
21193 + generic_fillattr(inode, stat);
21194 + stat->nlink = 2 + atomic_read(&nx_global_cactive);
21198 +static struct file_operations proc_virtnet_dir_operations = {
21199 + .read = generic_read_dir,
21200 + .iterate = proc_virtnet_iterate,
21203 +static struct inode_operations proc_virtnet_dir_inode_operations = {
21204 + .getattr = proc_virtnet_getattr,
21205 + .lookup = proc_virtnet_lookup,
21210 +void proc_vx_init(void)
21212 + struct proc_dir_entry *ent;
21214 + ent = proc_mkdir("virtual", 0);
21216 + ent->proc_fops = &proc_virtual_dir_operations;
21217 + ent->proc_iops = &proc_virtual_dir_inode_operations;
21219 + proc_virtual = ent;
21221 + ent = proc_mkdir("virtnet", 0);
21223 + ent->proc_fops = &proc_virtnet_dir_operations;
21224 + ent->proc_iops = &proc_virtnet_dir_inode_operations;
21226 + proc_virtnet = ent;
21232 +/* per pid info */
21235 +int proc_pid_vx_info(struct task_struct *p, char *buffer)
21237 + struct vx_info *vxi;
21238 + char *orig = buffer;
21240 + buffer += sprintf(buffer, "XID:\t%d\n", vx_task_xid(p));
21242 + vxi = task_get_vx_info(p);
21246 + buffer += sprintf(buffer, "BCaps:\t");
21247 + buffer = print_cap_t(buffer, &vxi->vx_bcaps);
21248 + buffer += sprintf(buffer, "\n");
21249 + buffer += sprintf(buffer, "CCaps:\t%016llx\n",
21250 + (unsigned long long)vxi->vx_ccaps);
21251 + buffer += sprintf(buffer, "CFlags:\t%016llx\n",
21252 + (unsigned long long)vxi->vx_flags);
21253 + buffer += sprintf(buffer, "CIPid:\t%d\n", vxi->vx_initpid);
21255 + put_vx_info(vxi);
21257 + return buffer - orig;
21261 +int proc_pid_nx_info(struct task_struct *p, char *buffer)
21263 + struct nx_info *nxi;
21264 + struct nx_addr_v4 *v4a;
21265 +#ifdef CONFIG_IPV6
21266 + struct nx_addr_v6 *v6a;
21268 + char *orig = buffer;
21271 + buffer += sprintf(buffer, "NID:\t%d\n", nx_task_nid(p));
21273 + nxi = task_get_nx_info(p);
21277 + buffer += sprintf(buffer, "NCaps:\t%016llx\n",
21278 + (unsigned long long)nxi->nx_ncaps);
21279 + buffer += sprintf(buffer, "NFlags:\t%016llx\n",
21280 + (unsigned long long)nxi->nx_flags);
21282 + buffer += sprintf(buffer,
21283 + "V4Root[bcast]:\t" NIPQUAD_FMT "\n",
21284 + NIPQUAD(nxi->v4_bcast.s_addr));
21285 + buffer += sprintf (buffer,
21286 + "V4Root[lback]:\t" NIPQUAD_FMT "\n",
21287 + NIPQUAD(nxi->v4_lback.s_addr));
21288 + if (!NX_IPV4(nxi))
21290 + for (i = 0, v4a = &nxi->v4; v4a; i++, v4a = v4a->next)
21291 + buffer += sprintf(buffer, "V4Root[%d]:\t" NXAV4_FMT "\n",
21294 +#ifdef CONFIG_IPV6
21295 + if (!NX_IPV6(nxi))
21297 + for (i = 0, v6a = &nxi->v6; v6a; i++, v6a = v6a->next)
21298 + buffer += sprintf(buffer, "V6Root[%d]:\t" NXAV6_FMT "\n",
21302 + put_nx_info(nxi);
21304 + return buffer - orig;
21307 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sched.c linux-3.13.10-vs2.3.6.11/kernel/vserver/sched.c
21308 --- linux-3.13.10/kernel/vserver/sched.c 1970-01-01 00:00:00.000000000 +0000
21309 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched.c 2014-01-31 20:38:04.000000000 +0000
21312 + * linux/kernel/vserver/sched.c
21314 + * Virtual Server: Scheduler Support
21316 + * Copyright (C) 2004-2010 Herbert Pötzl
21318 + * V0.01 adapted Sam Vilains version to 2.6.3
21319 + * V0.02 removed legacy interface
21320 + * V0.03 changed vcmds to vxi arg
21321 + * V0.04 removed older and legacy interfaces
21322 + * V0.05 removed scheduler code/commands
21326 +#include <linux/vs_context.h>
21327 +#include <linux/vs_sched.h>
21328 +#include <linux/cpumask.h>
21329 +#include <linux/vserver/sched_cmd.h>
21331 +#include <asm/uaccess.h>
21334 +void vx_update_sched_param(struct _vx_sched *sched,
21335 + struct _vx_sched_pc *sched_pc)
21337 + sched_pc->prio_bias = sched->prio_bias;
21340 +static int do_set_prio_bias(struct vx_info *vxi, struct vcmd_prio_bias *data)
21344 + if (data->prio_bias > MAX_PRIO_BIAS)
21345 + data->prio_bias = MAX_PRIO_BIAS;
21346 + if (data->prio_bias < MIN_PRIO_BIAS)
21347 + data->prio_bias = MIN_PRIO_BIAS;
21349 + if (data->cpu_id != ~0) {
21350 + vxi->sched.update = cpumask_of_cpu(data->cpu_id);
21351 + cpumask_and(&vxi->sched.update, &vxi->sched.update,
21352 + cpu_online_mask);
21354 + cpumask_copy(&vxi->sched.update, cpu_online_mask);
21356 + for_each_cpu_mask(cpu, vxi->sched.update)
21357 + vx_update_sched_param(&vxi->sched,
21358 + &vx_per_cpu(vxi, sched_pc, cpu));
21362 +int vc_set_prio_bias(struct vx_info *vxi, void __user *data)
21364 + struct vcmd_prio_bias vc_data;
21366 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21369 + return do_set_prio_bias(vxi, &vc_data);
21372 +int vc_get_prio_bias(struct vx_info *vxi, void __user *data)
21374 + struct vcmd_prio_bias vc_data;
21375 + struct _vx_sched_pc *pcd;
21378 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21381 + cpu = vc_data.cpu_id;
21383 + if (!cpu_possible(cpu))
21386 + pcd = &vx_per_cpu(vxi, sched_pc, cpu);
21387 + vc_data.prio_bias = pcd->prio_bias;
21389 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21394 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sched_init.h linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_init.h
21395 --- linux-3.13.10/kernel/vserver/sched_init.h 1970-01-01 00:00:00.000000000 +0000
21396 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_init.h 2014-01-31 20:38:04.000000000 +0000
21399 +static inline void vx_info_init_sched(struct _vx_sched *sched)
21401 + /* scheduling; hard code starting values as constants */
21402 + sched->prio_bias = 0;
21406 +void vx_info_init_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21408 + sched_pc->prio_bias = 0;
21410 + sched_pc->user_ticks = 0;
21411 + sched_pc->sys_ticks = 0;
21412 + sched_pc->hold_ticks = 0;
21415 +static inline void vx_info_exit_sched(struct _vx_sched *sched)
21421 +void vx_info_exit_sched_pc(struct _vx_sched_pc *sched_pc, int cpu)
21425 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sched_proc.h linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_proc.h
21426 --- linux-3.13.10/kernel/vserver/sched_proc.h 1970-01-01 00:00:00.000000000 +0000
21427 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sched_proc.h 2014-01-31 20:38:04.000000000 +0000
21429 +#ifndef _VX_SCHED_PROC_H
21430 +#define _VX_SCHED_PROC_H
21434 +int vx_info_proc_sched(struct _vx_sched *sched, char *buffer)
21438 + length += sprintf(buffer,
21439 + "PrioBias:\t%8d\n",
21440 + sched->prio_bias);
21445 +int vx_info_proc_sched_pc(struct _vx_sched_pc *sched_pc,
21446 + char *buffer, int cpu)
21450 + length += sprintf(buffer + length,
21451 + "cpu %d: %lld %lld %lld", cpu,
21452 + (unsigned long long)sched_pc->user_ticks,
21453 + (unsigned long long)sched_pc->sys_ticks,
21454 + (unsigned long long)sched_pc->hold_ticks);
21455 + length += sprintf(buffer + length,
21456 + " %d\n", sched_pc->prio_bias);
21460 +#endif /* _VX_SCHED_PROC_H */
21461 diff -NurpP --minimal linux-3.13.10/kernel/vserver/signal.c linux-3.13.10-vs2.3.6.11/kernel/vserver/signal.c
21462 --- linux-3.13.10/kernel/vserver/signal.c 1970-01-01 00:00:00.000000000 +0000
21463 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/signal.c 2014-01-31 20:38:04.000000000 +0000
21466 + * linux/kernel/vserver/signal.c
21468 + * Virtual Server: Signal Support
21470 + * Copyright (C) 2003-2007 Herbert Pötzl
21472 + * V0.01 broken out from vcontext V0.05
21473 + * V0.02 changed vcmds to vxi arg
21474 + * V0.03 adjusted siginfo for kill
21478 +#include <asm/uaccess.h>
21480 +#include <linux/vs_context.h>
21481 +#include <linux/vs_pid.h>
21482 +#include <linux/vserver/signal_cmd.h>
21485 +int vx_info_kill(struct vx_info *vxi, int pid, int sig)
21487 + int retval, count = 0;
21488 + struct task_struct *p;
21489 + struct siginfo *sip = SEND_SIG_PRIV;
21492 + vxdprintk(VXD_CBIT(misc, 4),
21493 + "vx_info_kill(%p[#%d],%d,%d)*",
21494 + vxi, vxi->vx_id, pid, sig);
21495 + read_lock(&tasklist_lock);
21499 + for_each_process(p) {
21502 + if (vx_task_xid(p) != vxi->vx_id || p->pid <= 1 ||
21503 + (pid && vxi->vx_initpid == p->pid))
21506 + err = group_send_sig_info(sig, sip, p);
21508 + if (err != -EPERM)
21514 + if (vxi->vx_initpid) {
21515 + pid = vxi->vx_initpid;
21516 + /* for now, only SIGINT to private init ... */
21517 + if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21518 + /* ... as long as there are tasks left */
21519 + (atomic_read(&vxi->vx_tasks) > 1))
21522 + /* fallthrough */
21525 + p = find_task_by_real_pid(pid);
21526 + rcu_read_unlock();
21528 + if (vx_task_xid(p) == vxi->vx_id)
21529 + retval = group_send_sig_info(sig, sip, p);
21533 + read_unlock(&tasklist_lock);
21534 + vxdprintk(VXD_CBIT(misc, 4),
21535 + "vx_info_kill(%p[#%d],%d,%d,%ld) = %d",
21536 + vxi, vxi->vx_id, pid, sig, (long)sip, retval);
21540 +int vc_ctx_kill(struct vx_info *vxi, void __user *data)
21542 + struct vcmd_ctx_kill_v0 vc_data;
21544 + if (copy_from_user(&vc_data, data, sizeof(vc_data)))
21547 + /* special check to allow guest shutdown */
21548 + if (!vx_info_flags(vxi, VXF_STATE_ADMIN, 0) &&
21549 + /* forbid killall pid=0 when init is present */
21550 + (((vc_data.pid < 1) && vxi->vx_initpid) ||
21551 + (vc_data.pid > 1)))
21554 + return vx_info_kill(vxi, vc_data.pid, vc_data.sig);
21558 +static int __wait_exit(struct vx_info *vxi)
21560 + DECLARE_WAITQUEUE(wait, current);
21563 + add_wait_queue(&vxi->vx_wait, &wait);
21564 + set_current_state(TASK_INTERRUPTIBLE);
21567 + if (vx_info_state(vxi,
21568 + VXS_SHUTDOWN | VXS_HASHED | VXS_HELPER) == VXS_SHUTDOWN)
21570 + if (signal_pending(current)) {
21571 + ret = -ERESTARTSYS;
21578 + set_current_state(TASK_RUNNING);
21579 + remove_wait_queue(&vxi->vx_wait, &wait);
21585 +int vc_wait_exit(struct vx_info *vxi, void __user *data)
21587 + struct vcmd_wait_exit_v0 vc_data;
21590 + ret = __wait_exit(vxi);
21591 + vc_data.reboot_cmd = vxi->reboot_cmd;
21592 + vc_data.exit_code = vxi->exit_code;
21594 + if (copy_to_user(data, &vc_data, sizeof(vc_data)))
21599 diff -NurpP --minimal linux-3.13.10/kernel/vserver/space.c linux-3.13.10-vs2.3.6.11/kernel/vserver/space.c
21600 --- linux-3.13.10/kernel/vserver/space.c 1970-01-01 00:00:00.000000000 +0000
21601 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/space.c 2014-02-01 12:21:24.000000000 +0000
21604 + * linux/kernel/vserver/space.c
21606 + * Virtual Server: Context Space Support
21608 + * Copyright (C) 2003-2010 Herbert Pötzl
21610 + * V0.01 broken out from context.c 0.07
21611 + * V0.02 added task locking for namespace
21612 + * V0.03 broken out vx_enter_namespace
21613 + * V0.04 added *space support and commands
21614 + * V0.05 added credential support
21618 +#include <linux/utsname.h>
21619 +#include <linux/nsproxy.h>
21620 +#include <linux/err.h>
21621 +#include <linux/fs_struct.h>
21622 +#include <linux/cred.h>
21623 +#include <asm/uaccess.h>
21625 +#include <linux/vs_context.h>
21626 +#include <linux/vserver/space.h>
21627 +#include <linux/vserver/space_cmd.h>
21629 +atomic_t vs_global_nsproxy = ATOMIC_INIT(0);
21630 +atomic_t vs_global_fs = ATOMIC_INIT(0);
21631 +atomic_t vs_global_mnt_ns = ATOMIC_INIT(0);
21632 +atomic_t vs_global_uts_ns = ATOMIC_INIT(0);
21633 +atomic_t vs_global_user_ns = ATOMIC_INIT(0);
21634 +atomic_t vs_global_pid_ns = ATOMIC_INIT(0);
21637 +/* namespace functions */
21639 +#include <linux/mnt_namespace.h>
21640 +#include <linux/user_namespace.h>
21641 +#include <linux/pid_namespace.h>
21642 +#include <linux/ipc_namespace.h>
21643 +#include <net/net_namespace.h>
21644 +#include "../fs/mount.h"
21647 +static const struct vcmd_space_mask_v1 space_mask_v0 = {
21648 + .mask = CLONE_FS |
21650 +#ifdef CONFIG_UTS_NS
21653 +#ifdef CONFIG_IPC_NS
21656 +#ifdef CONFIG_USER_NS
21662 +static const struct vcmd_space_mask_v1 space_mask = {
21663 + .mask = CLONE_FS |
21665 +#ifdef CONFIG_UTS_NS
21668 +#ifdef CONFIG_IPC_NS
21671 +#ifdef CONFIG_USER_NS
21674 +#ifdef CONFIG_PID_NS
21677 +#ifdef CONFIG_NET_NS
21683 +static const struct vcmd_space_mask_v1 default_space_mask = {
21684 + .mask = CLONE_FS |
21686 +#ifdef CONFIG_UTS_NS
21689 +#ifdef CONFIG_IPC_NS
21692 +#ifdef CONFIG_USER_NS
21695 +#ifdef CONFIG_PID_NS
21702 + * build a new nsproxy mix
21703 + * assumes that both proxies are 'const'
21704 + * does not touch nsproxy refcounts
21705 + * will hold a reference on the result.
21708 +struct nsproxy *vs_mix_nsproxy(struct nsproxy *old_nsproxy,
21709 + struct nsproxy *new_nsproxy, unsigned long mask)
21711 + struct mnt_namespace *old_ns;
21712 + struct uts_namespace *old_uts;
21713 + struct ipc_namespace *old_ipc;
21714 +#ifdef CONFIG_PID_NS
21715 + struct pid_namespace *old_pid;
21717 +#ifdef CONFIG_NET_NS
21718 + struct net *old_net;
21720 + struct nsproxy *nsproxy;
21722 + nsproxy = copy_nsproxy(old_nsproxy);
21726 + if (mask & CLONE_NEWNS) {
21727 + old_ns = nsproxy->mnt_ns;
21728 + nsproxy->mnt_ns = new_nsproxy->mnt_ns;
21729 + if (nsproxy->mnt_ns)
21730 + get_mnt_ns(nsproxy->mnt_ns);
21734 + if (mask & CLONE_NEWUTS) {
21735 + old_uts = nsproxy->uts_ns;
21736 + nsproxy->uts_ns = new_nsproxy->uts_ns;
21737 + if (nsproxy->uts_ns)
21738 + get_uts_ns(nsproxy->uts_ns);
21742 + if (mask & CLONE_NEWIPC) {
21743 + old_ipc = nsproxy->ipc_ns;
21744 + nsproxy->ipc_ns = new_nsproxy->ipc_ns;
21745 + if (nsproxy->ipc_ns)
21746 + get_ipc_ns(nsproxy->ipc_ns);
21750 +#ifdef CONFIG_PID_NS
21751 + if (mask & CLONE_NEWPID) {
21752 + old_pid = nsproxy->pid_ns_for_children;
21753 + nsproxy->pid_ns_for_children = new_nsproxy->pid_ns_for_children;
21754 + if (nsproxy->pid_ns_for_children)
21755 + get_pid_ns(nsproxy->pid_ns_for_children);
21759 +#ifdef CONFIG_NET_NS
21760 + if (mask & CLONE_NEWNET) {
21761 + old_net = nsproxy->net_ns;
21762 + nsproxy->net_ns = new_nsproxy->net_ns;
21763 + if (nsproxy->net_ns)
21764 + get_net(nsproxy->net_ns);
21769 + put_mnt_ns(old_ns);
21771 + put_uts_ns(old_uts);
21773 + put_ipc_ns(old_ipc);
21774 +#ifdef CONFIG_PID_NS
21776 + put_pid_ns(old_pid);
21778 +#ifdef CONFIG_NET_NS
21780 + put_net(old_net);
21788 + * merge two nsproxy structs into a new one.
21789 + * will hold a reference on the result.
21793 +struct nsproxy *__vs_merge_nsproxy(struct nsproxy *old,
21794 + struct nsproxy *proxy, unsigned long mask)
21796 + struct nsproxy null_proxy = { .mnt_ns = NULL };
21802 + /* vs_mix_nsproxy returns with reference */
21803 + return vs_mix_nsproxy(old ? old : &null_proxy,
21806 + get_nsproxy(proxy);
21811 +int vx_enter_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21813 + struct nsproxy *proxy, *proxy_cur, *proxy_new;
21814 + struct fs_struct *fs_cur, *fs = NULL;
21815 + struct _vx_space *space;
21816 + int ret, kill = 0;
21818 + vxdprintk(VXD_CBIT(space, 8), "vx_enter_space(%p[#%u],0x%08lx,%d)",
21819 + vxi, vxi->vx_id, mask, index);
21821 + if (vx_info_flags(vxi, VXF_INFO_PRIVATE, 0))
21824 + if (index >= VX_SPACES)
21827 + space = &vxi->space[index];
21830 + mask = space->vx_nsmask;
21832 + if ((mask & space->vx_nsmask) != mask)
21835 + if (mask & CLONE_FS) {
21836 + fs = copy_fs_struct(space->vx_fs);
21840 + proxy = space->vx_nsproxy;
21842 + vxdprintk(VXD_CBIT(space, 9),
21843 + "vx_enter_space(%p[#%u],0x%08lx,%d) -> (%p,%p)",
21844 + vxi, vxi->vx_id, mask, index, proxy, fs);
21846 + task_lock(current);
21847 + fs_cur = current->fs;
21849 + if (mask & CLONE_FS) {
21850 + spin_lock(&fs_cur->lock);
21851 + current->fs = fs;
21852 + kill = !--fs_cur->users;
21853 + spin_unlock(&fs_cur->lock);
21856 + proxy_cur = current->nsproxy;
21857 + get_nsproxy(proxy_cur);
21858 + task_unlock(current);
21861 + free_fs_struct(fs_cur);
21863 + proxy_new = __vs_merge_nsproxy(proxy_cur, proxy, mask);
21864 + if (IS_ERR(proxy_new)) {
21865 + ret = PTR_ERR(proxy_new);
21869 + proxy_new = xchg(¤t->nsproxy, proxy_new);
21871 + if (mask & CLONE_NEWUSER) {
21872 + struct cred *cred;
21874 + vxdprintk(VXD_CBIT(space, 10),
21875 + "vx_enter_space(%p[#%u],%p) cred (%p,%p)",
21876 + vxi, vxi->vx_id, space->vx_cred,
21877 + current->real_cred, current->cred);
21879 + if (space->vx_cred) {
21880 + cred = __prepare_creds(space->vx_cred);
21882 + commit_creds(cred);
21889 + put_nsproxy(proxy_new);
21892 + put_nsproxy(proxy_cur);
21897 +int vx_set_space(struct vx_info *vxi, unsigned long mask, unsigned index)
21899 + struct nsproxy *proxy_vxi, *proxy_cur, *proxy_new;
21900 + struct fs_struct *fs_vxi, *fs = NULL;
21901 + struct _vx_space *space;
21902 + int ret, kill = 0;
21904 + vxdprintk(VXD_CBIT(space, 8), "vx_set_space(%p[#%u],0x%08lx,%d)",
21905 + vxi, vxi->vx_id, mask, index);
21907 + if ((mask & space_mask.mask) != mask)
21910 + if (index >= VX_SPACES)
21913 + space = &vxi->space[index];
21915 + proxy_vxi = space->vx_nsproxy;
21916 + fs_vxi = space->vx_fs;
21918 + if (mask & CLONE_FS) {
21919 + fs = copy_fs_struct(current->fs);
21924 + task_lock(current);
21926 + if (mask & CLONE_FS) {
21927 + spin_lock(&fs_vxi->lock);
21928 + space->vx_fs = fs;
21929 + kill = !--fs_vxi->users;
21930 + spin_unlock(&fs_vxi->lock);
21933 + proxy_cur = current->nsproxy;
21934 + get_nsproxy(proxy_cur);
21935 + task_unlock(current);
21938 + free_fs_struct(fs_vxi);
21940 + proxy_new = __vs_merge_nsproxy(proxy_vxi, proxy_cur, mask);
21941 + if (IS_ERR(proxy_new)) {
21942 + ret = PTR_ERR(proxy_new);
21946 + proxy_new = xchg(&space->vx_nsproxy, proxy_new);
21947 + space->vx_nsmask |= mask;
21949 + if (mask & CLONE_NEWUSER) {
21950 + struct cred *cred;
21952 + vxdprintk(VXD_CBIT(space, 10),
21953 + "vx_set_space(%p[#%u],%p) cred (%p,%p)",
21954 + vxi, vxi->vx_id, space->vx_cred,
21955 + current->real_cred, current->cred);
21957 + cred = prepare_creds();
21958 + cred = (struct cred *)xchg(&space->vx_cred, cred);
21960 + abort_creds(cred);
21966 + put_nsproxy(proxy_new);
21969 + put_nsproxy(proxy_cur);
21974 +int vc_enter_space_v1(struct vx_info *vxi, void __user *data)
21976 + struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
21978 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21981 + return vx_enter_space(vxi, vc_data.mask, 0);
21984 +int vc_enter_space(struct vx_info *vxi, void __user *data)
21986 + struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
21988 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
21991 + if (vc_data.index >= VX_SPACES)
21994 + return vx_enter_space(vxi, vc_data.mask, vc_data.index);
21997 +int vc_set_space_v1(struct vx_info *vxi, void __user *data)
21999 + struct vcmd_space_mask_v1 vc_data = { .mask = 0 };
22001 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22004 + return vx_set_space(vxi, vc_data.mask, 0);
22007 +int vc_set_space(struct vx_info *vxi, void __user *data)
22009 + struct vcmd_space_mask_v2 vc_data = { .mask = 0 };
22011 + if (data && copy_from_user(&vc_data, data, sizeof(vc_data)))
22014 + if (vc_data.index >= VX_SPACES)
22017 + return vx_set_space(vxi, vc_data.mask, vc_data.index);
22020 +int vc_get_space_mask(void __user *data, int type)
22022 + const struct vcmd_space_mask_v1 *mask;
22025 + mask = &space_mask_v0;
22026 + else if (type == 1)
22027 + mask = &space_mask;
22029 + mask = &default_space_mask;
22031 + vxdprintk(VXD_CBIT(space, 10),
22032 + "vc_get_space_mask(%d) = %08llx", type, mask->mask);
22034 + if (copy_to_user(data, mask, sizeof(*mask)))
22039 diff -NurpP --minimal linux-3.13.10/kernel/vserver/switch.c linux-3.13.10-vs2.3.6.11/kernel/vserver/switch.c
22040 --- linux-3.13.10/kernel/vserver/switch.c 1970-01-01 00:00:00.000000000 +0000
22041 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/switch.c 2014-01-31 20:38:04.000000000 +0000
22044 + * linux/kernel/vserver/switch.c
22046 + * Virtual Server: Syscall Switch
22048 + * Copyright (C) 2003-2011 Herbert Pötzl
22050 + * V0.01 syscall switch
22051 + * V0.02 added signal to context
22052 + * V0.03 added rlimit functions
22053 + * V0.04 added iattr, task/xid functions
22054 + * V0.05 added debug/history stuff
22055 + * V0.06 added compat32 layer
22056 + * V0.07 vcmd args and perms
22057 + * V0.08 added status commands
22058 + * V0.09 added tag commands
22059 + * V0.10 added oom bias
22060 + * V0.11 added device commands
22061 + * V0.12 added warn mask
22065 +#include <linux/vs_context.h>
22066 +#include <linux/vs_network.h>
22067 +#include <linux/vserver/switch.h>
22069 +#include "vci_config.h"
22073 +int vc_get_version(uint32_t id)
22075 + return VCI_VERSION;
22079 +int vc_get_vci(uint32_t id)
22081 + return vci_kernel_config();
22084 +#include <linux/vserver/context_cmd.h>
22085 +#include <linux/vserver/cvirt_cmd.h>
22086 +#include <linux/vserver/cacct_cmd.h>
22087 +#include <linux/vserver/limit_cmd.h>
22088 +#include <linux/vserver/network_cmd.h>
22089 +#include <linux/vserver/sched_cmd.h>
22090 +#include <linux/vserver/debug_cmd.h>
22091 +#include <linux/vserver/inode_cmd.h>
22092 +#include <linux/vserver/dlimit_cmd.h>
22093 +#include <linux/vserver/signal_cmd.h>
22094 +#include <linux/vserver/space_cmd.h>
22095 +#include <linux/vserver/tag_cmd.h>
22096 +#include <linux/vserver/device_cmd.h>
22098 +#include <linux/vserver/inode.h>
22099 +#include <linux/vserver/dlimit.h>
22102 +#ifdef CONFIG_COMPAT
22103 +#define __COMPAT(name, id, data, compat) \
22104 + (compat) ? name ## _x32(id, data) : name(id, data)
22105 +#define __COMPAT_NO_ID(name, data, compat) \
22106 + (compat) ? name ## _x32(data) : name(data)
22108 +#define __COMPAT(name, id, data, compat) \
22110 +#define __COMPAT_NO_ID(name, data, compat) \
22116 +long do_vcmd(uint32_t cmd, uint32_t id,
22117 + struct vx_info *vxi, struct nx_info *nxi,
22118 + void __user *data, int compat)
22122 + case VCMD_get_version:
22123 + return vc_get_version(id);
22124 + case VCMD_get_vci:
22125 + return vc_get_vci(id);
22127 + case VCMD_task_xid:
22128 + return vc_task_xid(id);
22129 + case VCMD_vx_info:
22130 + return vc_vx_info(vxi, data);
22132 + case VCMD_task_nid:
22133 + return vc_task_nid(id);
22134 + case VCMD_nx_info:
22135 + return vc_nx_info(nxi, data);
22137 + case VCMD_task_tag:
22138 + return vc_task_tag(id);
22140 + case VCMD_set_space_v1:
22141 + return vc_set_space_v1(vxi, data);
22142 + /* this is version 2 */
22143 + case VCMD_set_space:
22144 + return vc_set_space(vxi, data);
22146 + case VCMD_get_space_mask_v0:
22147 + return vc_get_space_mask(data, 0);
22148 + /* this is version 1 */
22149 + case VCMD_get_space_mask:
22150 + return vc_get_space_mask(data, 1);
22152 + case VCMD_get_space_default:
22153 + return vc_get_space_mask(data, -1);
22155 + case VCMD_set_umask:
22156 + return vc_set_umask(vxi, data);
22158 + case VCMD_get_umask:
22159 + return vc_get_umask(vxi, data);
22161 + case VCMD_set_wmask:
22162 + return vc_set_wmask(vxi, data);
22164 + case VCMD_get_wmask:
22165 + return vc_get_wmask(vxi, data);
22166 +#ifdef CONFIG_IA32_EMULATION
22167 + case VCMD_get_rlimit:
22168 + return __COMPAT(vc_get_rlimit, vxi, data, compat);
22169 + case VCMD_set_rlimit:
22170 + return __COMPAT(vc_set_rlimit, vxi, data, compat);
22172 + case VCMD_get_rlimit:
22173 + return vc_get_rlimit(vxi, data);
22174 + case VCMD_set_rlimit:
22175 + return vc_set_rlimit(vxi, data);
22177 + case VCMD_get_rlimit_mask:
22178 + return vc_get_rlimit_mask(id, data);
22179 + case VCMD_reset_hits:
22180 + return vc_reset_hits(vxi, data);
22181 + case VCMD_reset_minmax:
22182 + return vc_reset_minmax(vxi, data);
22184 + case VCMD_get_vhi_name:
22185 + return vc_get_vhi_name(vxi, data);
22186 + case VCMD_set_vhi_name:
22187 + return vc_set_vhi_name(vxi, data);
22189 + case VCMD_ctx_stat:
22190 + return vc_ctx_stat(vxi, data);
22191 + case VCMD_virt_stat:
22192 + return vc_virt_stat(vxi, data);
22193 + case VCMD_sock_stat:
22194 + return vc_sock_stat(vxi, data);
22195 + case VCMD_rlimit_stat:
22196 + return vc_rlimit_stat(vxi, data);
22198 + case VCMD_set_cflags:
22199 + return vc_set_cflags(vxi, data);
22200 + case VCMD_get_cflags:
22201 + return vc_get_cflags(vxi, data);
22203 + /* this is version 1 */
22204 + case VCMD_set_ccaps:
22205 + return vc_set_ccaps(vxi, data);
22206 + /* this is version 1 */
22207 + case VCMD_get_ccaps:
22208 + return vc_get_ccaps(vxi, data);
22209 + case VCMD_set_bcaps:
22210 + return vc_set_bcaps(vxi, data);
22211 + case VCMD_get_bcaps:
22212 + return vc_get_bcaps(vxi, data);
22214 + case VCMD_set_badness:
22215 + return vc_set_badness(vxi, data);
22216 + case VCMD_get_badness:
22217 + return vc_get_badness(vxi, data);
22219 + case VCMD_set_nflags:
22220 + return vc_set_nflags(nxi, data);
22221 + case VCMD_get_nflags:
22222 + return vc_get_nflags(nxi, data);
22224 + case VCMD_set_ncaps:
22225 + return vc_set_ncaps(nxi, data);
22226 + case VCMD_get_ncaps:
22227 + return vc_get_ncaps(nxi, data);
22229 + case VCMD_set_prio_bias:
22230 + return vc_set_prio_bias(vxi, data);
22231 + case VCMD_get_prio_bias:
22232 + return vc_get_prio_bias(vxi, data);
22233 + case VCMD_add_dlimit:
22234 + return __COMPAT(vc_add_dlimit, id, data, compat);
22235 + case VCMD_rem_dlimit:
22236 + return __COMPAT(vc_rem_dlimit, id, data, compat);
22237 + case VCMD_set_dlimit:
22238 + return __COMPAT(vc_set_dlimit, id, data, compat);
22239 + case VCMD_get_dlimit:
22240 + return __COMPAT(vc_get_dlimit, id, data, compat);
22242 + case VCMD_ctx_kill:
22243 + return vc_ctx_kill(vxi, data);
22245 + case VCMD_wait_exit:
22246 + return vc_wait_exit(vxi, data);
22248 + case VCMD_get_iattr:
22249 + return __COMPAT_NO_ID(vc_get_iattr, data, compat);
22250 + case VCMD_set_iattr:
22251 + return __COMPAT_NO_ID(vc_set_iattr, data, compat);
22253 + case VCMD_fget_iattr:
22254 + return vc_fget_iattr(id, data);
22255 + case VCMD_fset_iattr:
22256 + return vc_fset_iattr(id, data);
22258 + case VCMD_enter_space_v0:
22259 + return vc_enter_space_v1(vxi, NULL);
22260 + case VCMD_enter_space_v1:
22261 + return vc_enter_space_v1(vxi, data);
22262 + /* this is version 2 */
22263 + case VCMD_enter_space:
22264 + return vc_enter_space(vxi, data);
22266 + case VCMD_ctx_create_v0:
22267 + return vc_ctx_create(id, NULL);
22268 + case VCMD_ctx_create:
22269 + return vc_ctx_create(id, data);
22270 + case VCMD_ctx_migrate_v0:
22271 + return vc_ctx_migrate(vxi, NULL);
22272 + case VCMD_ctx_migrate:
22273 + return vc_ctx_migrate(vxi, data);
22275 + case VCMD_net_create_v0:
22276 + return vc_net_create(id, NULL);
22277 + case VCMD_net_create:
22278 + return vc_net_create(id, data);
22279 + case VCMD_net_migrate:
22280 + return vc_net_migrate(nxi, data);
22282 + case VCMD_tag_migrate:
22283 + return vc_tag_migrate(id);
22285 + case VCMD_net_add:
22286 + return vc_net_add(nxi, data);
22287 + case VCMD_net_remove:
22288 + return vc_net_remove(nxi, data);
22290 + case VCMD_net_add_ipv4_v1:
22291 + return vc_net_add_ipv4_v1(nxi, data);
22292 + /* this is version 2 */
22293 + case VCMD_net_add_ipv4:
22294 + return vc_net_add_ipv4(nxi, data);
22296 + case VCMD_net_rem_ipv4_v1:
22297 + return vc_net_rem_ipv4_v1(nxi, data);
22298 + /* this is version 2 */
22299 + case VCMD_net_rem_ipv4:
22300 + return vc_net_rem_ipv4(nxi, data);
22301 +#ifdef CONFIG_IPV6
22302 + case VCMD_net_add_ipv6:
22303 + return vc_net_add_ipv6(nxi, data);
22304 + case VCMD_net_remove_ipv6:
22305 + return vc_net_remove_ipv6(nxi, data);
22307 +/* case VCMD_add_match_ipv4:
22308 + return vc_add_match_ipv4(nxi, data);
22309 + case VCMD_get_match_ipv4:
22310 + return vc_get_match_ipv4(nxi, data);
22311 +#ifdef CONFIG_IPV6
22312 + case VCMD_add_match_ipv6:
22313 + return vc_add_match_ipv6(nxi, data);
22314 + case VCMD_get_match_ipv6:
22315 + return vc_get_match_ipv6(nxi, data);
22318 +#ifdef CONFIG_VSERVER_DEVICE
22319 + case VCMD_set_mapping:
22320 + return __COMPAT(vc_set_mapping, vxi, data, compat);
22321 + case VCMD_unset_mapping:
22322 + return __COMPAT(vc_unset_mapping, vxi, data, compat);
22324 +#ifdef CONFIG_VSERVER_HISTORY
22325 + case VCMD_dump_history:
22326 + return vc_dump_history(id);
22327 + case VCMD_read_history:
22328 + return __COMPAT(vc_read_history, id, data, compat);
22331 + vxwprintk_task(1, "unimplemented VCMD_%02d_%d[%d]",
22332 + VC_CATEGORY(cmd), VC_COMMAND(cmd), VC_VERSION(cmd));
22338 +#define __VCMD(vcmd, _perm, _args, _flags) \
22339 + case VCMD_ ## vcmd: perm = _perm; \
22340 + args = _args; flags = _flags; break
22343 +#define VCA_NONE 0x00
22344 +#define VCA_VXI 0x01
22345 +#define VCA_NXI 0x02
22347 +#define VCF_NONE 0x00
22348 +#define VCF_INFO 0x01
22349 +#define VCF_ADMIN 0x02
22350 +#define VCF_ARES 0x06 /* includes admin */
22351 +#define VCF_SETUP 0x08
22353 +#define VCF_ZIDOK 0x10 /* zero id okay */
22357 +long do_vserver(uint32_t cmd, uint32_t id, void __user *data, int compat)
22360 + int permit = -1, state = 0;
22361 + int perm = -1, args = 0, flags = 0;
22362 + struct vx_info *vxi = NULL;
22363 + struct nx_info *nxi = NULL;
22366 + /* unpriviledged commands */
22367 + __VCMD(get_version, 0, VCA_NONE, 0);
22368 + __VCMD(get_vci, 0, VCA_NONE, 0);
22369 + __VCMD(get_rlimit_mask, 0, VCA_NONE, 0);
22370 + __VCMD(get_space_mask_v0,0, VCA_NONE, 0);
22371 + __VCMD(get_space_mask, 0, VCA_NONE, 0);
22372 + __VCMD(get_space_default,0, VCA_NONE, 0);
22374 + /* info commands */
22375 + __VCMD(task_xid, 2, VCA_NONE, 0);
22376 + __VCMD(reset_hits, 2, VCA_VXI, 0);
22377 + __VCMD(reset_minmax, 2, VCA_VXI, 0);
22378 + __VCMD(vx_info, 3, VCA_VXI, VCF_INFO);
22379 + __VCMD(get_bcaps, 3, VCA_VXI, VCF_INFO);
22380 + __VCMD(get_ccaps, 3, VCA_VXI, VCF_INFO);
22381 + __VCMD(get_cflags, 3, VCA_VXI, VCF_INFO);
22382 + __VCMD(get_umask, 3, VCA_VXI, VCF_INFO);
22383 + __VCMD(get_wmask, 3, VCA_VXI, VCF_INFO);
22384 + __VCMD(get_badness, 3, VCA_VXI, VCF_INFO);
22385 + __VCMD(get_vhi_name, 3, VCA_VXI, VCF_INFO);
22386 + __VCMD(get_rlimit, 3, VCA_VXI, VCF_INFO);
22388 + __VCMD(ctx_stat, 3, VCA_VXI, VCF_INFO);
22389 + __VCMD(virt_stat, 3, VCA_VXI, VCF_INFO);
22390 + __VCMD(sock_stat, 3, VCA_VXI, VCF_INFO);
22391 + __VCMD(rlimit_stat, 3, VCA_VXI, VCF_INFO);
22393 + __VCMD(task_nid, 2, VCA_NONE, 0);
22394 + __VCMD(nx_info, 3, VCA_NXI, VCF_INFO);
22395 + __VCMD(get_ncaps, 3, VCA_NXI, VCF_INFO);
22396 + __VCMD(get_nflags, 3, VCA_NXI, VCF_INFO);
22398 + __VCMD(task_tag, 2, VCA_NONE, 0);
22400 + __VCMD(get_iattr, 2, VCA_NONE, 0);
22401 + __VCMD(fget_iattr, 2, VCA_NONE, 0);
22402 + __VCMD(get_dlimit, 3, VCA_NONE, VCF_INFO);
22403 + __VCMD(get_prio_bias, 3, VCA_VXI, VCF_INFO);
22405 + /* lower admin commands */
22406 + __VCMD(wait_exit, 4, VCA_VXI, VCF_INFO);
22407 + __VCMD(ctx_create_v0, 5, VCA_NONE, 0);
22408 + __VCMD(ctx_create, 5, VCA_NONE, 0);
22409 + __VCMD(ctx_migrate_v0, 5, VCA_VXI, VCF_ADMIN);
22410 + __VCMD(ctx_migrate, 5, VCA_VXI, VCF_ADMIN);
22411 + __VCMD(enter_space_v0, 5, VCA_VXI, VCF_ADMIN);
22412 + __VCMD(enter_space_v1, 5, VCA_VXI, VCF_ADMIN);
22413 + __VCMD(enter_space, 5, VCA_VXI, VCF_ADMIN);
22415 + __VCMD(net_create_v0, 5, VCA_NONE, 0);
22416 + __VCMD(net_create, 5, VCA_NONE, 0);
22417 + __VCMD(net_migrate, 5, VCA_NXI, VCF_ADMIN);
22419 + __VCMD(tag_migrate, 5, VCA_NONE, VCF_ADMIN);
22421 + /* higher admin commands */
22422 + __VCMD(ctx_kill, 6, VCA_VXI, VCF_ARES);
22423 + __VCMD(set_space_v1, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22424 + __VCMD(set_space, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22426 + __VCMD(set_ccaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22427 + __VCMD(set_bcaps, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22428 + __VCMD(set_cflags, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22429 + __VCMD(set_umask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22430 + __VCMD(set_wmask, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22431 + __VCMD(set_badness, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22433 + __VCMD(set_vhi_name, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22434 + __VCMD(set_rlimit, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22435 + __VCMD(set_prio_bias, 7, VCA_VXI, VCF_ARES | VCF_SETUP);
22437 + __VCMD(set_ncaps, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
22438 + __VCMD(set_nflags, 7, VCA_NXI, VCF_ARES | VCF_SETUP);
22439 + __VCMD(net_add, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22440 + __VCMD(net_remove, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22441 + __VCMD(net_add_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22442 + __VCMD(net_rem_ipv4_v1, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22443 + __VCMD(net_add_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22444 + __VCMD(net_rem_ipv4, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22445 +#ifdef CONFIG_IPV6
22446 + __VCMD(net_add_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22447 + __VCMD(net_remove_ipv6, 8, VCA_NXI, VCF_ARES | VCF_SETUP);
22449 + __VCMD(set_iattr, 7, VCA_NONE, 0);
22450 + __VCMD(fset_iattr, 7, VCA_NONE, 0);
22451 + __VCMD(set_dlimit, 7, VCA_NONE, VCF_ARES);
22452 + __VCMD(add_dlimit, 8, VCA_NONE, VCF_ARES);
22453 + __VCMD(rem_dlimit, 8, VCA_NONE, VCF_ARES);
22455 +#ifdef CONFIG_VSERVER_DEVICE
22456 + __VCMD(set_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
22457 + __VCMD(unset_mapping, 8, VCA_VXI, VCF_ARES|VCF_ZIDOK);
22459 + /* debug level admin commands */
22460 +#ifdef CONFIG_VSERVER_HISTORY
22461 + __VCMD(dump_history, 9, VCA_NONE, 0);
22462 + __VCMD(read_history, 9, VCA_NONE, 0);
22469 + vxdprintk(VXD_CBIT(switch, 0),
22470 + "vc: VCMD_%02d_%d[%d], %d,%p [%d,%d,%x,%x]",
22471 + VC_CATEGORY(cmd), VC_COMMAND(cmd),
22472 + VC_VERSION(cmd), id, data, compat,
22473 + perm, args, flags);
22480 + if (!capable(CAP_CONTEXT))
22484 + /* moved here from the individual commands */
22486 + if ((perm > 1) && !capable(CAP_SYS_ADMIN))
22490 + /* vcmd involves resource management */
22492 + if ((flags & VCF_ARES) && !capable(CAP_SYS_RESOURCE))
22496 + /* various legacy exceptions */
22498 + /* will go away when spectator is a cap */
22499 + case VCMD_ctx_migrate_v0:
22500 + case VCMD_ctx_migrate:
22502 + current->xid = 1;
22508 + /* will go away when spectator is a cap */
22509 + case VCMD_net_migrate:
22511 + current->nid = 1;
22518 + /* vcmds are fine by default */
22521 + /* admin type vcmds require admin ... */
22522 + if (flags & VCF_ADMIN)
22523 + permit = vx_check(0, VS_ADMIN) ? 1 : 0;
22525 + /* ... but setup type vcmds override that */
22526 + if (!permit && (flags & VCF_SETUP))
22527 + permit = vx_flags(VXF_STATE_SETUP, 0) ? 2 : 0;
22535 + if (!id && (flags & VCF_ZIDOK))
22539 + if (args & VCA_VXI) {
22540 + vxi = lookup_vx_info(id);
22544 + if ((flags & VCF_ADMIN) &&
22545 + /* special case kill for shutdown */
22546 + (cmd != VCMD_ctx_kill) &&
22547 + /* can context be administrated? */
22548 + !vx_info_flags(vxi, VXF_STATE_ADMIN, 0)) {
22554 + if (args & VCA_NXI) {
22555 + nxi = lookup_nx_info(id);
22559 + if ((flags & VCF_ADMIN) &&
22560 + /* can context be administrated? */
22561 + !nx_info_flags(nxi, NXF_STATE_ADMIN, 0)) {
22568 + ret = do_vcmd(cmd, id, vxi, nxi, data, compat);
22571 + if ((args & VCA_NXI) && nxi)
22572 + put_nx_info(nxi);
22574 + if ((args & VCA_VXI) && vxi)
22575 + put_vx_info(vxi);
22577 + vxdprintk(VXD_CBIT(switch, 1),
22578 + "vc: VCMD_%02d_%d[%d] = %08lx(%ld) [%d,%d]",
22579 + VC_CATEGORY(cmd), VC_COMMAND(cmd),
22580 + VC_VERSION(cmd), ret, ret, state, permit);
22585 +sys_vserver(uint32_t cmd, uint32_t id, void __user *data)
22587 + return do_vserver(cmd, id, data, 0);
22590 +#ifdef CONFIG_COMPAT
22593 +sys32_vserver(uint32_t cmd, uint32_t id, void __user *data)
22595 + return do_vserver(cmd, id, data, 1);
22598 +#endif /* CONFIG_COMPAT */
22599 diff -NurpP --minimal linux-3.13.10/kernel/vserver/sysctl.c linux-3.13.10-vs2.3.6.11/kernel/vserver/sysctl.c
22600 --- linux-3.13.10/kernel/vserver/sysctl.c 1970-01-01 00:00:00.000000000 +0000
22601 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/sysctl.c 2014-01-31 20:38:04.000000000 +0000
22604 + * kernel/vserver/sysctl.c
22606 + * Virtual Context Support
22608 + * Copyright (C) 2004-2007 Herbert Pötzl
22610 + * V0.01 basic structure
22614 +#include <linux/module.h>
22615 +#include <linux/ctype.h>
22616 +#include <linux/sysctl.h>
22617 +#include <linux/parser.h>
22618 +#include <asm/uaccess.h>
22621 + CTL_DEBUG_ERROR = 0,
22622 + CTL_DEBUG_SWITCH = 1,
22638 +unsigned int vs_debug_switch = 0;
22639 +unsigned int vs_debug_xid = 0;
22640 +unsigned int vs_debug_nid = 0;
22641 +unsigned int vs_debug_tag = 0;
22642 +unsigned int vs_debug_net = 0;
22643 +unsigned int vs_debug_limit = 0;
22644 +unsigned int vs_debug_cres = 0;
22645 +unsigned int vs_debug_dlim = 0;
22646 +unsigned int vs_debug_quota = 0;
22647 +unsigned int vs_debug_cvirt = 0;
22648 +unsigned int vs_debug_space = 0;
22649 +unsigned int vs_debug_perm = 0;
22650 +unsigned int vs_debug_misc = 0;
22653 +static struct ctl_table_header *vserver_table_header;
22654 +static ctl_table vserver_root_table[];
22657 +void vserver_register_sysctl(void)
22659 + if (!vserver_table_header) {
22660 + vserver_table_header = register_sysctl_table(vserver_root_table);
22665 +void vserver_unregister_sysctl(void)
22667 + if (vserver_table_header) {
22668 + unregister_sysctl_table(vserver_table_header);
22669 + vserver_table_header = NULL;
22674 +static int proc_dodebug(ctl_table *table, int write,
22675 + void __user *buffer, size_t *lenp, loff_t *ppos)
22677 + char tmpbuf[20], *p, c;
22678 + unsigned int value;
22679 + size_t left, len;
22681 + if ((*ppos && !write) || !*lenp) {
22689 + if (!access_ok(VERIFY_READ, buffer, left))
22691 + p = (char *)buffer;
22692 + while (left && __get_user(c, p) >= 0 && isspace(c))
22697 + if (left > sizeof(tmpbuf) - 1)
22699 + if (copy_from_user(tmpbuf, p, left))
22701 + tmpbuf[left] = '\0';
22703 + for (p = tmpbuf, value = 0; '0' <= *p && *p <= '9'; p++, left--)
22704 + value = 10 * value + (*p - '0');
22705 + if (*p && !isspace(*p))
22707 + while (left && isspace(*p))
22709 + *(unsigned int *)table->data = value;
22711 + if (!access_ok(VERIFY_WRITE, buffer, left))
22713 + len = sprintf(tmpbuf, "%d", *(unsigned int *)table->data);
22716 + if (__copy_to_user(buffer, tmpbuf, len))
22718 + if ((left -= len) > 0) {
22719 + if (put_user('\n', (char *)buffer + len))
22733 +#define CTL_ENTRY(ctl, name) \
22735 + .procname = #name, \
22736 + .data = &vs_ ## name, \
22737 + .maxlen = sizeof(int), \
22739 + .proc_handler = &proc_dodebug, \
22740 + .extra1 = &zero, \
22741 + .extra2 = &zero, \
22744 +static ctl_table vserver_debug_table[] = {
22745 + CTL_ENTRY(CTL_DEBUG_SWITCH, debug_switch),
22746 + CTL_ENTRY(CTL_DEBUG_XID, debug_xid),
22747 + CTL_ENTRY(CTL_DEBUG_NID, debug_nid),
22748 + CTL_ENTRY(CTL_DEBUG_TAG, debug_tag),
22749 + CTL_ENTRY(CTL_DEBUG_NET, debug_net),
22750 + CTL_ENTRY(CTL_DEBUG_LIMIT, debug_limit),
22751 + CTL_ENTRY(CTL_DEBUG_CRES, debug_cres),
22752 + CTL_ENTRY(CTL_DEBUG_DLIM, debug_dlim),
22753 + CTL_ENTRY(CTL_DEBUG_QUOTA, debug_quota),
22754 + CTL_ENTRY(CTL_DEBUG_CVIRT, debug_cvirt),
22755 + CTL_ENTRY(CTL_DEBUG_SPACE, debug_space),
22756 + CTL_ENTRY(CTL_DEBUG_PERM, debug_perm),
22757 + CTL_ENTRY(CTL_DEBUG_MISC, debug_misc),
22761 +static ctl_table vserver_root_table[] = {
22763 + .procname = "vserver",
22765 + .child = vserver_debug_table
22771 +static match_table_t tokens = {
22772 + { CTL_DEBUG_SWITCH, "switch=%x" },
22773 + { CTL_DEBUG_XID, "xid=%x" },
22774 + { CTL_DEBUG_NID, "nid=%x" },
22775 + { CTL_DEBUG_TAG, "tag=%x" },
22776 + { CTL_DEBUG_NET, "net=%x" },
22777 + { CTL_DEBUG_LIMIT, "limit=%x" },
22778 + { CTL_DEBUG_CRES, "cres=%x" },
22779 + { CTL_DEBUG_DLIM, "dlim=%x" },
22780 + { CTL_DEBUG_QUOTA, "quota=%x" },
22781 + { CTL_DEBUG_CVIRT, "cvirt=%x" },
22782 + { CTL_DEBUG_SPACE, "space=%x" },
22783 + { CTL_DEBUG_PERM, "perm=%x" },
22784 + { CTL_DEBUG_MISC, "misc=%x" },
22785 + { CTL_DEBUG_ERROR, NULL }
22788 +#define HANDLE_CASE(id, name, val) \
22789 + case CTL_DEBUG_ ## id: \
22790 + vs_debug_ ## name = val; \
22791 + printk("vs_debug_" #name "=0x%x\n", val); \
22795 +static int __init vs_debug_setup(char *str)
22800 + printk("vs_debug_setup(%s)\n", str);
22801 + while ((p = strsep(&str, ",")) != NULL) {
22802 + substring_t args[MAX_OPT_ARGS];
22803 + unsigned int value;
22808 + token = match_token(p, tokens, args);
22809 + value = (token > 0) ? simple_strtoul(args[0].from, NULL, 0) : 0;
22812 + HANDLE_CASE(SWITCH, switch, value);
22813 + HANDLE_CASE(XID, xid, value);
22814 + HANDLE_CASE(NID, nid, value);
22815 + HANDLE_CASE(TAG, tag, value);
22816 + HANDLE_CASE(NET, net, value);
22817 + HANDLE_CASE(LIMIT, limit, value);
22818 + HANDLE_CASE(CRES, cres, value);
22819 + HANDLE_CASE(DLIM, dlim, value);
22820 + HANDLE_CASE(QUOTA, quota, value);
22821 + HANDLE_CASE(CVIRT, cvirt, value);
22822 + HANDLE_CASE(SPACE, space, value);
22823 + HANDLE_CASE(PERM, perm, value);
22824 + HANDLE_CASE(MISC, misc, value);
22833 +__setup("vsdebug=", vs_debug_setup);
22837 +EXPORT_SYMBOL_GPL(vs_debug_switch);
22838 +EXPORT_SYMBOL_GPL(vs_debug_xid);
22839 +EXPORT_SYMBOL_GPL(vs_debug_nid);
22840 +EXPORT_SYMBOL_GPL(vs_debug_net);
22841 +EXPORT_SYMBOL_GPL(vs_debug_limit);
22842 +EXPORT_SYMBOL_GPL(vs_debug_cres);
22843 +EXPORT_SYMBOL_GPL(vs_debug_dlim);
22844 +EXPORT_SYMBOL_GPL(vs_debug_quota);
22845 +EXPORT_SYMBOL_GPL(vs_debug_cvirt);
22846 +EXPORT_SYMBOL_GPL(vs_debug_space);
22847 +EXPORT_SYMBOL_GPL(vs_debug_perm);
22848 +EXPORT_SYMBOL_GPL(vs_debug_misc);
22850 diff -NurpP --minimal linux-3.13.10/kernel/vserver/tag.c linux-3.13.10-vs2.3.6.11/kernel/vserver/tag.c
22851 --- linux-3.13.10/kernel/vserver/tag.c 1970-01-01 00:00:00.000000000 +0000
22852 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/tag.c 2014-01-31 20:38:04.000000000 +0000
22855 + * linux/kernel/vserver/tag.c
22857 + * Virtual Server: Shallow Tag Space
22859 + * Copyright (C) 2007 Herbert Pötzl
22861 + * V0.01 basic implementation
22865 +#include <linux/sched.h>
22866 +#include <linux/vserver/debug.h>
22867 +#include <linux/vs_pid.h>
22868 +#include <linux/vs_tag.h>
22870 +#include <linux/vserver/tag_cmd.h>
22873 +int dx_migrate_task(struct task_struct *p, vtag_t tag)
22878 + vxdprintk(VXD_CBIT(tag, 5),
22879 + "dx_migrate_task(%p[#%d],#%d)", p, p->tag, tag);
22885 + vxdprintk(VXD_CBIT(tag, 5),
22886 + "moved task %p into [#%d]", p, tag);
22890 +/* vserver syscall commands below here */
22892 +/* taks xid and vx_info functions */
22895 +int vc_task_tag(uint32_t id)
22900 + struct task_struct *tsk;
22902 + tsk = find_task_by_real_pid(id);
22903 + tag = (tsk) ? tsk->tag : -ESRCH;
22904 + rcu_read_unlock();
22906 + tag = dx_current_tag();
22911 +int vc_tag_migrate(uint32_t tag)
22913 + return dx_migrate_task(current, tag & 0xFFFF);
22917 diff -NurpP --minimal linux-3.13.10/kernel/vserver/vci_config.h linux-3.13.10-vs2.3.6.11/kernel/vserver/vci_config.h
22918 --- linux-3.13.10/kernel/vserver/vci_config.h 1970-01-01 00:00:00.000000000 +0000
22919 +++ linux-3.13.10-vs2.3.6.11/kernel/vserver/vci_config.h 2014-01-31 20:38:04.000000000 +0000
22922 +/* interface version */
22924 +#define VCI_VERSION 0x00020308
22928 + VCI_KCBIT_NO_DYNAMIC = 0,
22930 + VCI_KCBIT_PROC_SECURE = 4,
22931 + /* VCI_KCBIT_HARDCPU = 5, */
22932 + /* VCI_KCBIT_IDLELIMIT = 6, */
22933 + /* VCI_KCBIT_IDLETIME = 7, */
22935 + VCI_KCBIT_COWBL = 8,
22936 + VCI_KCBIT_FULLCOWBL = 9,
22937 + VCI_KCBIT_SPACES = 10,
22938 + VCI_KCBIT_NETV2 = 11,
22939 + VCI_KCBIT_MEMCG = 12,
22940 + VCI_KCBIT_MEMCG_SWAP = 13,
22942 + VCI_KCBIT_DEBUG = 16,
22943 + VCI_KCBIT_HISTORY = 20,
22944 + VCI_KCBIT_TAGGED = 24,
22945 + VCI_KCBIT_PPTAG = 28,
22947 + VCI_KCBIT_MORE = 31,
22951 +static inline uint32_t vci_kernel_config(void)
22954 + (1 << VCI_KCBIT_NO_DYNAMIC) |
22956 + /* configured features */
22957 +#ifdef CONFIG_VSERVER_PROC_SECURE
22958 + (1 << VCI_KCBIT_PROC_SECURE) |
22960 +#ifdef CONFIG_VSERVER_COWBL
22961 + (1 << VCI_KCBIT_COWBL) |
22962 + (1 << VCI_KCBIT_FULLCOWBL) |
22964 + (1 << VCI_KCBIT_SPACES) |
22965 + (1 << VCI_KCBIT_NETV2) |
22966 +#ifdef CONFIG_MEMCG
22967 + (1 << VCI_KCBIT_MEMCG) |
22969 +#ifdef CONFIG_MEMCG_SWAP
22970 + (1 << VCI_KCBIT_MEMCG_SWAP) |
22973 + /* debug options */
22974 +#ifdef CONFIG_VSERVER_DEBUG
22975 + (1 << VCI_KCBIT_DEBUG) |
22977 +#ifdef CONFIG_VSERVER_HISTORY
22978 + (1 << VCI_KCBIT_HISTORY) |
22981 + /* inode context tagging */
22982 +#if defined(CONFIG_TAGGING_NONE)
22983 + (0 << VCI_KCBIT_TAGGED) |
22984 +#elif defined(CONFIG_TAGGING_UID16)
22985 + (1 << VCI_KCBIT_TAGGED) |
22986 +#elif defined(CONFIG_TAGGING_GID16)
22987 + (2 << VCI_KCBIT_TAGGED) |
22988 +#elif defined(CONFIG_TAGGING_ID24)
22989 + (3 << VCI_KCBIT_TAGGED) |
22990 +#elif defined(CONFIG_TAGGING_INTERN)
22991 + (4 << VCI_KCBIT_TAGGED) |
22992 +#elif defined(CONFIG_TAGGING_RUNTIME)
22993 + (5 << VCI_KCBIT_TAGGED) |
22995 + (7 << VCI_KCBIT_TAGGED) |
22997 + (1 << VCI_KCBIT_PPTAG) |
23001 diff -NurpP --minimal linux-3.13.10/mm/memcontrol.c linux-3.13.10-vs2.3.6.11/mm/memcontrol.c
23002 --- linux-3.13.10/mm/memcontrol.c 2014-04-17 01:12:40.000000000 +0000
23003 +++ linux-3.13.10-vs2.3.6.11/mm/memcontrol.c 2014-04-17 01:17:11.000000000 +0000
23004 @@ -1056,6 +1056,31 @@ struct mem_cgroup *mem_cgroup_from_task(
23005 return mem_cgroup_from_css(task_css(p, mem_cgroup_subsys_id));
23008 +u64 mem_cgroup_res_read_u64(struct mem_cgroup *mem, int member)
23010 + return res_counter_read_u64(&mem->res, member);
23013 +u64 mem_cgroup_memsw_read_u64(struct mem_cgroup *mem, int member)
23015 + return res_counter_read_u64(&mem->memsw, member);
23018 +s64 mem_cgroup_stat_read_cache(struct mem_cgroup *mem)
23020 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
23023 +s64 mem_cgroup_stat_read_anon(struct mem_cgroup *mem)
23025 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
23028 +s64 mem_cgroup_stat_read_mapped(struct mem_cgroup *mem)
23030 + return mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
23033 struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
23035 struct mem_cgroup *memcg = NULL;
23036 diff -NurpP --minimal linux-3.13.10/mm/oom_kill.c linux-3.13.10-vs2.3.6.11/mm/oom_kill.c
23037 --- linux-3.13.10/mm/oom_kill.c 2014-04-17 01:12:40.000000000 +0000
23038 +++ linux-3.13.10-vs2.3.6.11/mm/oom_kill.c 2014-02-25 11:26:10.000000000 +0000
23040 #include <linux/freezer.h>
23041 #include <linux/ftrace.h>
23042 #include <linux/ratelimit.h>
23043 +#include <linux/reboot.h>
23044 +#include <linux/vs_context.h>
23046 #define CREATE_TRACE_POINTS
23047 #include <trace/events/oom.h>
23048 @@ -113,11 +115,18 @@ struct task_struct *find_lock_task_mm(st
23049 static bool oom_unkillable_task(struct task_struct *p,
23050 const struct mem_cgroup *memcg, const nodemask_t *nodemask)
23052 - if (is_global_init(p))
23053 + unsigned xid = vx_current_xid();
23055 + /* skip the init task, global and per guest */
23056 + if (task_is_init(p))
23058 if (p->flags & PF_KTHREAD)
23061 + /* skip other guest and host processes if oom in guest */
23062 + if (xid && vx_task_xid(p) != xid)
23065 /* When mem_cgroup_out_of_memory() and p is not member of the group */
23066 if (memcg && !task_in_mem_cgroup(p, memcg))
23068 @@ -426,8 +435,8 @@ void oom_kill_process(struct task_struct
23069 dump_header(p, gfp_mask, order, memcg, nodemask);
23072 - pr_err("%s: Kill process %d (%s) score %d or sacrifice child\n",
23073 - message, task_pid_nr(p), p->comm, points);
23074 + pr_err("%s: Kill process %d:#%u (%s) score %d or sacrifice child\n",
23075 + message, task_pid_nr(p), p->xid, p->comm, points);
23079 @@ -472,8 +481,8 @@ void oom_kill_process(struct task_struct
23081 /* mm cannot safely be dereferenced after task_unlock(victim) */
23083 - pr_err("Killed process %d (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23084 - task_pid_nr(victim), victim->comm, K(victim->mm->total_vm),
23085 + pr_err("Killed process %d:#%u (%s) total-vm:%lukB, anon-rss:%lukB, file-rss:%lukB\n",
23086 + task_pid_nr(victim), victim->xid, victim->comm, K(victim->mm->total_vm),
23087 K(get_mm_counter(victim->mm, MM_ANONPAGES)),
23088 K(get_mm_counter(victim->mm, MM_FILEPAGES)));
23089 task_unlock(victim);
23090 @@ -543,6 +552,8 @@ int unregister_oom_notifier(struct notif
23092 EXPORT_SYMBOL_GPL(unregister_oom_notifier);
23094 +long vs_oom_action(unsigned int);
23097 * Try to acquire the OOM killer lock for the zones in zonelist. Returns zero
23098 * if a parallel OOM killing is already taking place that includes a zone in
23099 @@ -655,7 +666,12 @@ void out_of_memory(struct zonelist *zone
23100 /* Found nothing?!?! Either we hang forever, or we panic. */
23102 dump_header(NULL, gfp_mask, order, NULL, mpol_mask);
23103 - panic("Out of memory and no killable processes...\n");
23105 + /* avoid panic for guest OOM */
23106 + if (vx_current_xid())
23107 + vs_oom_action(LINUX_REBOOT_CMD_OOM);
23109 + panic("Out of memory and no killable processes...\n");
23111 if (p != (void *)-1UL) {
23112 oom_kill_process(p, gfp_mask, order, points, totalpages, NULL,
23113 diff -NurpP --minimal linux-3.13.10/mm/page_alloc.c linux-3.13.10-vs2.3.6.11/mm/page_alloc.c
23114 --- linux-3.13.10/mm/page_alloc.c 2014-04-17 01:12:40.000000000 +0000
23115 +++ linux-3.13.10-vs2.3.6.11/mm/page_alloc.c 2014-04-17 01:17:11.000000000 +0000
23117 #include <linux/page-debug-flags.h>
23118 #include <linux/hugetlb.h>
23119 #include <linux/sched/rt.h>
23120 +#include <linux/vs_base.h>
23121 +#include <linux/vs_limit.h>
23123 #include <asm/sections.h>
23124 #include <asm/tlbflush.h>
23125 @@ -2983,6 +2985,9 @@ void si_meminfo(struct sysinfo *val)
23126 val->totalhigh = totalhigh_pages;
23127 val->freehigh = nr_free_highpages();
23128 val->mem_unit = PAGE_SIZE;
23130 + if (vx_flags(VXF_VIRT_MEM, 0))
23131 + vx_vsi_meminfo(val);
23134 EXPORT_SYMBOL(si_meminfo);
23135 @@ -3007,6 +3012,9 @@ void si_meminfo_node(struct sysinfo *val
23138 val->mem_unit = PAGE_SIZE;
23140 + if (vx_flags(VXF_VIRT_MEM, 0))
23141 + vx_vsi_meminfo(val);
23145 diff -NurpP --minimal linux-3.13.10/mm/pgtable-generic.c linux-3.13.10-vs2.3.6.11/mm/pgtable-generic.c
23146 --- linux-3.13.10/mm/pgtable-generic.c 2014-01-22 20:39:14.000000000 +0000
23147 +++ linux-3.13.10-vs2.3.6.11/mm/pgtable-generic.c 2014-01-31 20:38:04.000000000 +0000
23149 * Copyright (C) 2010 Linus Torvalds
23152 +#include <linux/mm.h>
23154 #include <linux/pagemap.h>
23155 #include <asm/tlb.h>
23156 #include <asm-generic/pgtable.h>
23157 diff -NurpP --minimal linux-3.13.10/mm/shmem.c linux-3.13.10-vs2.3.6.11/mm/shmem.c
23158 --- linux-3.13.10/mm/shmem.c 2014-01-22 20:39:14.000000000 +0000
23159 +++ linux-3.13.10-vs2.3.6.11/mm/shmem.c 2014-01-31 20:38:04.000000000 +0000
23160 @@ -1909,7 +1909,7 @@ static int shmem_statfs(struct dentry *d
23162 struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
23164 - buf->f_type = TMPFS_MAGIC;
23165 + buf->f_type = TMPFS_SUPER_MAGIC;
23166 buf->f_bsize = PAGE_CACHE_SIZE;
23167 buf->f_namelen = NAME_MAX;
23168 if (sbinfo->max_blocks) {
23169 @@ -2639,7 +2639,7 @@ int shmem_fill_super(struct super_block
23170 sb->s_maxbytes = MAX_LFS_FILESIZE;
23171 sb->s_blocksize = PAGE_CACHE_SIZE;
23172 sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
23173 - sb->s_magic = TMPFS_MAGIC;
23174 + sb->s_magic = TMPFS_SUPER_MAGIC;
23175 sb->s_op = &shmem_ops;
23176 sb->s_time_gran = 1;
23177 #ifdef CONFIG_TMPFS_XATTR
23178 diff -NurpP --minimal linux-3.13.10/mm/slab.c linux-3.13.10-vs2.3.6.11/mm/slab.c
23179 --- linux-3.13.10/mm/slab.c 2014-01-22 20:39:14.000000000 +0000
23180 +++ linux-3.13.10-vs2.3.6.11/mm/slab.c 2014-01-31 20:38:04.000000000 +0000
23181 @@ -322,6 +322,8 @@ static void kmem_cache_node_init(struct
23182 #define STATS_INC_FREEMISS(x) do { } while (0)
23185 +#include "slab_vs.h"
23190 @@ -3240,6 +3242,7 @@ slab_alloc_node(struct kmem_cache *cache
23191 /* ___cache_alloc_node can fall back to other nodes */
23192 ptr = ____cache_alloc_node(cachep, flags, nodeid);
23194 + vx_slab_alloc(cachep, flags);
23195 local_irq_restore(save_flags);
23196 ptr = cache_alloc_debugcheck_after(cachep, flags, ptr, caller);
23197 kmemleak_alloc_recursive(ptr, cachep->object_size, 1, cachep->flags,
23198 @@ -3430,6 +3433,7 @@ static inline void __cache_free(struct k
23200 kmemleak_free_recursive(objp, cachep->flags);
23201 objp = cache_free_debugcheck(cachep, objp, caller);
23202 + vx_slab_free(cachep);
23204 kmemcheck_slab_free(cachep, objp, cachep->object_size);
23206 diff -NurpP --minimal linux-3.13.10/mm/slab_vs.h linux-3.13.10-vs2.3.6.11/mm/slab_vs.h
23207 --- linux-3.13.10/mm/slab_vs.h 1970-01-01 00:00:00.000000000 +0000
23208 +++ linux-3.13.10-vs2.3.6.11/mm/slab_vs.h 2014-01-31 20:38:04.000000000 +0000
23211 +#include <linux/vserver/context.h>
23213 +#include <linux/vs_context.h>
23216 +void vx_slab_alloc(struct kmem_cache *cachep, gfp_t flags)
23218 + int what = gfp_zone(cachep->allocflags);
23219 + struct vx_info *vxi = current_vx_info();
23224 + atomic_add(cachep->size, &vxi->cacct.slab[what]);
23228 +void vx_slab_free(struct kmem_cache *cachep)
23230 + int what = gfp_zone(cachep->allocflags);
23231 + struct vx_info *vxi = current_vx_info();
23236 + atomic_sub(cachep->size, &vxi->cacct.slab[what]);
23239 diff -NurpP --minimal linux-3.13.10/mm/swapfile.c linux-3.13.10-vs2.3.6.11/mm/swapfile.c
23240 --- linux-3.13.10/mm/swapfile.c 2014-04-17 01:12:40.000000000 +0000
23241 +++ linux-3.13.10-vs2.3.6.11/mm/swapfile.c 2014-02-25 11:26:10.000000000 +0000
23243 #include <asm/tlbflush.h>
23244 #include <linux/swapops.h>
23245 #include <linux/page_cgroup.h>
23246 +#include <linux/vs_base.h>
23248 static bool swap_count_continued(struct swap_info_struct *, pgoff_t,
23250 @@ -2042,6 +2043,16 @@ static int swap_show(struct seq_file *sw
23252 if (si == SEQ_START_TOKEN) {
23253 seq_puts(swap,"Filename\t\t\t\tType\t\tSize\tUsed\tPriority\n");
23254 + if (vx_flags(VXF_VIRT_MEM, 0)) {
23255 + struct sysinfo si;
23257 + vx_vsi_swapinfo(&si);
23258 + if (si.totalswap < (1 << 10))
23260 + seq_printf(swap, "%s\t\t\t\t\t%s\t%lu\t%lu\t%d\n",
23261 + "hdv0", "partition", si.totalswap >> 10,
23262 + (si.totalswap - si.freeswap) >> 10, -1);
23267 @@ -2589,6 +2600,8 @@ void si_swapinfo(struct sysinfo *val)
23268 val->freeswap = atomic_long_read(&nr_swap_pages) + nr_to_be_unused;
23269 val->totalswap = total_swap_pages + nr_to_be_unused;
23270 spin_unlock(&swap_lock);
23271 + if (vx_flags(VXF_VIRT_MEM, 0))
23272 + vx_vsi_swapinfo(val);
23276 diff -NurpP --minimal linux-3.13.10/net/bridge/br_multicast.c linux-3.13.10-vs2.3.6.11/net/bridge/br_multicast.c
23277 --- linux-3.13.10/net/bridge/br_multicast.c 2014-04-17 01:12:40.000000000 +0000
23278 +++ linux-3.13.10-vs2.3.6.11/net/bridge/br_multicast.c 2014-04-17 01:17:11.000000000 +0000
23279 @@ -447,7 +447,7 @@ static struct sk_buff *br_ip6_multicast_
23280 ip6h->hop_limit = 1;
23281 ipv6_addr_set(&ip6h->daddr, htonl(0xff020000), 0, 0, htonl(1));
23282 if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
23284 + &ip6h->saddr, NULL)) {
23288 diff -NurpP --minimal linux-3.13.10/net/core/dev.c linux-3.13.10-vs2.3.6.11/net/core/dev.c
23289 --- linux-3.13.10/net/core/dev.c 2014-04-17 01:12:41.000000000 +0000
23290 +++ linux-3.13.10-vs2.3.6.11/net/core/dev.c 2014-03-12 15:51:08.000000000 +0000
23291 @@ -122,6 +122,7 @@
23292 #include <linux/in.h>
23293 #include <linux/jhash.h>
23294 #include <linux/random.h>
23295 +#include <linux/vs_inet.h>
23296 #include <trace/events/napi.h>
23297 #include <trace/events/net.h>
23298 #include <trace/events/skb.h>
23299 @@ -669,7 +670,8 @@ struct net_device *__dev_get_by_name(str
23300 struct hlist_head *head = dev_name_hash(net, name);
23302 hlist_for_each_entry(dev, head, name_hlist)
23303 - if (!strncmp(dev->name, name, IFNAMSIZ))
23304 + if (!strncmp(dev->name, name, IFNAMSIZ) &&
23305 + nx_dev_visible(current_nx_info(), dev))
23309 @@ -694,7 +696,8 @@ struct net_device *dev_get_by_name_rcu(s
23310 struct hlist_head *head = dev_name_hash(net, name);
23312 hlist_for_each_entry_rcu(dev, head, name_hlist)
23313 - if (!strncmp(dev->name, name, IFNAMSIZ))
23314 + if (!strncmp(dev->name, name, IFNAMSIZ) &&
23315 + nx_dev_visible(current_nx_info(), dev))
23319 @@ -744,7 +747,8 @@ struct net_device *__dev_get_by_index(st
23320 struct hlist_head *head = dev_index_hash(net, ifindex);
23322 hlist_for_each_entry(dev, head, index_hlist)
23323 - if (dev->ifindex == ifindex)
23324 + if ((dev->ifindex == ifindex) &&
23325 + nx_dev_visible(current_nx_info(), dev))
23329 @@ -762,7 +766,7 @@ EXPORT_SYMBOL(__dev_get_by_index);
23330 * about locking. The caller must hold RCU lock.
23333 -struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23334 +struct net_device *dev_get_by_index_real_rcu(struct net *net, int ifindex)
23336 struct net_device *dev;
23337 struct hlist_head *head = dev_index_hash(net, ifindex);
23338 @@ -773,6 +777,16 @@ struct net_device *dev_get_by_index_rcu(
23342 +EXPORT_SYMBOL(dev_get_by_index_real_rcu);
23344 +struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
23346 + struct net_device *dev = dev_get_by_index_real_rcu(net, ifindex);
23348 + if (nx_dev_visible(current_nx_info(), dev))
23352 EXPORT_SYMBOL(dev_get_by_index_rcu);
23355 @@ -855,7 +869,8 @@ struct net_device *dev_getbyhwaddr_rcu(s
23357 for_each_netdev_rcu(net, dev)
23358 if (dev->type == type &&
23359 - !memcmp(dev->dev_addr, ha, dev->addr_len))
23360 + !memcmp(dev->dev_addr, ha, dev->addr_len) &&
23361 + nx_dev_visible(current_nx_info(), dev))
23365 @@ -867,9 +882,11 @@ struct net_device *__dev_getfirstbyhwtyp
23366 struct net_device *dev;
23369 - for_each_netdev(net, dev)
23370 - if (dev->type == type)
23371 + for_each_netdev(net, dev) {
23372 + if ((dev->type == type) &&
23373 + nx_dev_visible(current_nx_info(), dev))
23379 @@ -881,7 +898,8 @@ struct net_device *dev_getfirstbyhwtype(
23382 for_each_netdev_rcu(net, dev)
23383 - if (dev->type == type) {
23384 + if ((dev->type == type) &&
23385 + nx_dev_visible(current_nx_info(), dev)) {
23389 @@ -909,7 +927,8 @@ struct net_device *dev_get_by_flags_rcu(
23392 for_each_netdev_rcu(net, dev) {
23393 - if (((dev->flags ^ if_flags) & mask) == 0) {
23394 + if ((((dev->flags ^ if_flags) & mask) == 0) &&
23395 + nx_dev_visible(current_nx_info(), dev)) {
23399 @@ -987,6 +1006,8 @@ static int __dev_alloc_name(struct net *
23401 if (i < 0 || i >= max_netdevices)
23403 + if (!nx_dev_visible(current_nx_info(), d))
23406 /* avoid cases where sscanf is not exact inverse of printf */
23407 snprintf(buf, IFNAMSIZ, name, i);
23408 diff -NurpP --minimal linux-3.13.10/net/core/net-procfs.c linux-3.13.10-vs2.3.6.11/net/core/net-procfs.c
23409 --- linux-3.13.10/net/core/net-procfs.c 2013-11-25 15:45:09.000000000 +0000
23410 +++ linux-3.13.10-vs2.3.6.11/net/core/net-procfs.c 2014-01-31 20:38:04.000000000 +0000
23412 #include <linux/netdevice.h>
23413 #include <linux/proc_fs.h>
23414 #include <linux/seq_file.h>
23415 +#include <linux/vs_inet.h>
23416 #include <net/wext.h>
23418 #define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1)
23419 @@ -77,8 +78,13 @@ static void dev_seq_stop(struct seq_file
23420 static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
23422 struct rtnl_link_stats64 temp;
23423 - const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
23424 + const struct rtnl_link_stats64 *stats;
23426 + /* device visible inside network context? */
23427 + if (!nx_dev_visible(current_nx_info(), dev))
23430 + stats = dev_get_stats(dev, &temp);
23431 seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
23432 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
23433 dev->name, stats->rx_bytes, stats->rx_packets,
23434 diff -NurpP --minimal linux-3.13.10/net/core/rtnetlink.c linux-3.13.10-vs2.3.6.11/net/core/rtnetlink.c
23435 --- linux-3.13.10/net/core/rtnetlink.c 2014-04-17 01:12:41.000000000 +0000
23436 +++ linux-3.13.10-vs2.3.6.11/net/core/rtnetlink.c 2014-04-17 01:17:11.000000000 +0000
23437 @@ -1090,6 +1090,8 @@ static int rtnl_dump_ifinfo(struct sk_bu
23438 hlist_for_each_entry_rcu(dev, head, index_hlist) {
23441 + if (!nx_dev_visible(skb->sk->sk_nx_info, dev))
23443 err = rtnl_fill_ifinfo(skb, dev, RTM_NEWLINK,
23444 NETLINK_CB(cb->skb).portid,
23445 cb->nlh->nlmsg_seq, 0,
23446 @@ -1992,6 +1994,9 @@ void rtmsg_ifinfo(int type, struct net_d
23447 int err = -ENOBUFS;
23448 size_t if_info_size;
23450 + if (!nx_dev_visible(current_nx_info(), dev))
23453 skb = nlmsg_new((if_info_size = if_nlmsg_size(dev, 0)), flags);
23456 diff -NurpP --minimal linux-3.13.10/net/core/sock.c linux-3.13.10-vs2.3.6.11/net/core/sock.c
23457 --- linux-3.13.10/net/core/sock.c 2014-04-17 01:12:41.000000000 +0000
23458 +++ linux-3.13.10-vs2.3.6.11/net/core/sock.c 2014-04-17 01:17:11.000000000 +0000
23459 @@ -133,6 +133,10 @@
23460 #include <net/netprio_cgroup.h>
23462 #include <linux/filter.h>
23463 +#include <linux/vs_socket.h>
23464 +#include <linux/vs_limit.h>
23465 +#include <linux/vs_context.h>
23466 +#include <linux/vs_network.h>
23468 #include <trace/events/sock.h>
23470 @@ -1279,6 +1283,8 @@ static struct sock *sk_prot_alloc(struct
23472 sk_tx_queue_clear(sk);
23474 + sock_vx_init(sk);
23475 + sock_nx_init(sk);
23479 @@ -1387,6 +1393,11 @@ static void __sk_free(struct sock *sk)
23480 put_cred(sk->sk_peer_cred);
23481 put_pid(sk->sk_peer_pid);
23482 put_net(sock_net(sk));
23484 + clr_vx_info(&sk->sk_vx_info);
23486 + clr_nx_info(&sk->sk_nx_info);
23488 sk_prot_free(sk->sk_prot_creator, sk);
23491 @@ -1447,6 +1458,8 @@ struct sock *sk_clone_lock(const struct
23494 get_net(sock_net(newsk));
23495 + sock_vx_init(newsk);
23496 + sock_nx_init(newsk);
23497 sk_node_init(&newsk->sk_node);
23498 sock_lock_init(newsk);
23499 bh_lock_sock(newsk);
23500 @@ -1503,6 +1516,12 @@ struct sock *sk_clone_lock(const struct
23502 atomic_set(&newsk->sk_refcnt, 2);
23504 + set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info);
23505 + newsk->sk_xid = sk->sk_xid;
23506 + vx_sock_inc(newsk);
23507 + set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info);
23508 + newsk->sk_nid = sk->sk_nid;
23511 * Increment the counter in the same struct proto as the master
23512 * sock (sk_refcnt_debug_inc uses newsk->sk_prot->socks, that
23513 @@ -2340,6 +2359,12 @@ void sock_init_data(struct socket *sock,
23515 sk->sk_stamp = ktime_set(-1L, 0);
23517 + set_vx_info(&sk->sk_vx_info, current_vx_info());
23518 + sk->sk_xid = vx_current_xid();
23520 + set_nx_info(&sk->sk_nx_info, current_nx_info());
23521 + sk->sk_nid = nx_current_nid();
23523 #ifdef CONFIG_NET_RX_BUSY_POLL
23524 sk->sk_napi_id = 0;
23525 sk->sk_ll_usec = sysctl_net_busy_read;
23526 diff -NurpP --minimal linux-3.13.10/net/ipv4/af_inet.c linux-3.13.10-vs2.3.6.11/net/ipv4/af_inet.c
23527 --- linux-3.13.10/net/ipv4/af_inet.c 2014-04-17 01:12:41.000000000 +0000
23528 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/af_inet.c 2014-04-17 01:17:11.000000000 +0000
23529 @@ -118,6 +118,7 @@
23530 #ifdef CONFIG_IP_MROUTE
23531 #include <linux/mroute.h>
23533 +#include <linux/vs_limit.h>
23536 /* The inetsw table contains everything that inet_create needs to
23537 @@ -309,10 +310,13 @@ lookup_protocol:
23541 + if ((protocol == IPPROTO_ICMP) &&
23542 + nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
23544 if (sock->type == SOCK_RAW && !kern &&
23545 !ns_capable(net->user_ns, CAP_NET_RAW))
23546 goto out_rcu_unlock;
23549 sock->ops = answer->ops;
23550 answer_prot = answer->prot;
23551 answer_no_check = answer->no_check;
23552 @@ -433,6 +437,7 @@ int inet_bind(struct socket *sock, struc
23553 struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;
23554 struct sock *sk = sock->sk;
23555 struct inet_sock *inet = inet_sk(sk);
23556 + struct nx_v4_sock_addr nsa;
23557 struct net *net = sock_net(sk);
23558 unsigned short snum;
23560 @@ -457,7 +462,11 @@ int inet_bind(struct socket *sock, struc
23564 - chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);
23565 + err = v4_map_sock_addr(inet, addr, &nsa);
23569 + chk_addr_ret = inet_addr_type(net, nsa.saddr);
23571 /* Not specified by any standard per-se, however it breaks too
23572 * many applications when removed. It is unfortunate since
23573 @@ -469,7 +478,7 @@ int inet_bind(struct socket *sock, struc
23574 err = -EADDRNOTAVAIL;
23575 if (!sysctl_ip_nonlocal_bind &&
23576 !(inet->freebind || inet->transparent) &&
23577 - addr->sin_addr.s_addr != htonl(INADDR_ANY) &&
23578 + nsa.saddr != htonl(INADDR_ANY) &&
23579 chk_addr_ret != RTN_LOCAL &&
23580 chk_addr_ret != RTN_MULTICAST &&
23581 chk_addr_ret != RTN_BROADCAST)
23582 @@ -495,7 +504,7 @@ int inet_bind(struct socket *sock, struc
23583 if (sk->sk_state != TCP_CLOSE || inet->inet_num)
23584 goto out_release_sock;
23586 - inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23587 + v4_set_sock_addr(inet, &nsa);
23588 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23589 inet->inet_saddr = 0; /* Use device */
23591 @@ -714,11 +723,13 @@ int inet_getname(struct socket *sock, st
23594 sin->sin_port = inet->inet_dport;
23595 - sin->sin_addr.s_addr = inet->inet_daddr;
23596 + sin->sin_addr.s_addr =
23597 + nx_map_sock_lback(sk->sk_nx_info, inet->inet_daddr);
23599 __be32 addr = inet->inet_rcv_saddr;
23601 addr = inet->inet_saddr;
23602 + addr = nx_map_sock_lback(sk->sk_nx_info, addr);
23603 sin->sin_port = inet->inet_sport;
23604 sin->sin_addr.s_addr = addr;
23606 diff -NurpP --minimal linux-3.13.10/net/ipv4/arp.c linux-3.13.10-vs2.3.6.11/net/ipv4/arp.c
23607 --- linux-3.13.10/net/ipv4/arp.c 2013-11-25 15:47:06.000000000 +0000
23608 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/arp.c 2014-01-31 20:38:04.000000000 +0000
23609 @@ -1336,6 +1336,7 @@ static void arp_format_neigh_entry(struc
23610 struct net_device *dev = n->dev;
23611 int hatype = dev->type;
23613 + /* FIXME: check for network context */
23614 read_lock(&n->lock);
23615 /* Convert hardware address to XX:XX:XX:XX ... form. */
23616 #if IS_ENABLED(CONFIG_AX25)
23617 @@ -1367,6 +1368,7 @@ static void arp_format_pneigh_entry(stru
23618 int hatype = dev ? dev->type : 0;
23621 + /* FIXME: check for network context */
23622 sprintf(tbuf, "%pI4", n->key);
23623 seq_printf(seq, "%-16s 0x%-10x0x%-10x%s * %s\n",
23624 tbuf, hatype, ATF_PUBL | ATF_PERM, "00:00:00:00:00:00",
23625 diff -NurpP --minimal linux-3.13.10/net/ipv4/devinet.c linux-3.13.10-vs2.3.6.11/net/ipv4/devinet.c
23626 --- linux-3.13.10/net/ipv4/devinet.c 2014-04-17 01:12:41.000000000 +0000
23627 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/devinet.c 2014-03-12 15:51:08.000000000 +0000
23628 @@ -527,6 +527,7 @@ struct in_device *inetdev_by_index(struc
23630 EXPORT_SYMBOL(inetdev_by_index);
23633 /* Called only from RTNL semaphored context. No locks. */
23635 struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
23636 @@ -947,6 +948,8 @@ int devinet_ioctl(struct net *net, unsig
23638 in_dev = __in_dev_get_rtnl(dev);
23640 + struct nx_info *nxi = current_nx_info();
23642 if (tryaddrmatch) {
23643 /* Matthias Andree */
23644 /* compare label and address (4.4BSD style) */
23645 @@ -955,6 +958,8 @@ int devinet_ioctl(struct net *net, unsig
23646 This is checked above. */
23647 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23648 ifap = &ifa->ifa_next) {
23649 + if (!nx_v4_ifa_visible(nxi, ifa))
23651 if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
23652 sin_orig.sin_addr.s_addr ==
23654 @@ -967,9 +972,12 @@ int devinet_ioctl(struct net *net, unsig
23655 comparing just the label */
23657 for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
23658 - ifap = &ifa->ifa_next)
23659 + ifap = &ifa->ifa_next) {
23660 + if (!nx_v4_ifa_visible(nxi, ifa))
23662 if (!strcmp(ifr.ifr_name, ifa->ifa_label))
23668 @@ -1123,6 +1131,8 @@ static int inet_gifconf(struct net_devic
23671 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
23672 + if (!nx_v4_ifa_visible(current_nx_info(), ifa))
23675 done += sizeof(ifr);
23677 @@ -1524,6 +1534,7 @@ static int inet_dump_ifaddr(struct sk_bu
23678 struct net_device *dev;
23679 struct in_device *in_dev;
23680 struct in_ifaddr *ifa;
23681 + struct sock *sk = skb->sk;
23682 struct hlist_head *head;
23685 @@ -1547,6 +1558,8 @@ static int inet_dump_ifaddr(struct sk_bu
23687 for (ifa = in_dev->ifa_list, ip_idx = 0; ifa;
23688 ifa = ifa->ifa_next, ip_idx++) {
23689 + if (sk && !nx_v4_ifa_visible(sk->sk_nx_info, ifa))
23691 if (ip_idx < s_ip_idx)
23693 if (inet_fill_ifaddr(skb, ifa,
23694 diff -NurpP --minimal linux-3.13.10/net/ipv4/fib_trie.c linux-3.13.10-vs2.3.6.11/net/ipv4/fib_trie.c
23695 --- linux-3.13.10/net/ipv4/fib_trie.c 2014-01-22 20:39:15.000000000 +0000
23696 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/fib_trie.c 2014-01-31 20:38:04.000000000 +0000
23697 @@ -2530,6 +2530,7 @@ static int fib_route_seq_show(struct seq
23699 seq_setwidth(seq, 127);
23701 + /* FIXME: check for network context? */
23704 "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
23705 diff -NurpP --minimal linux-3.13.10/net/ipv4/inet_connection_sock.c linux-3.13.10-vs2.3.6.11/net/ipv4/inet_connection_sock.c
23706 --- linux-3.13.10/net/ipv4/inet_connection_sock.c 2014-01-22 20:39:15.000000000 +0000
23707 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_connection_sock.c 2014-02-01 00:33:11.000000000 +0000
23708 @@ -45,6 +45,37 @@ void inet_get_local_port_range(struct ne
23710 EXPORT_SYMBOL(inet_get_local_port_range);
23712 +int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
23714 + __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr,
23715 + sk2_rcv_saddr = sk2->sk_rcv_saddr;
23717 + if (inet_v6_ipv6only(sk2))
23720 + if (sk1_rcv_saddr &&
23722 + sk1_rcv_saddr == sk2_rcv_saddr)
23725 + if (sk1_rcv_saddr &&
23726 + !sk2_rcv_saddr &&
23727 + v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, NXA_MASK_BIND))
23730 + if (sk2_rcv_saddr &&
23731 + !sk1_rcv_saddr &&
23732 + v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, NXA_MASK_BIND))
23735 + if (!sk1_rcv_saddr &&
23736 + !sk2_rcv_saddr &&
23737 + nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info))
23743 int inet_csk_bind_conflict(const struct sock *sk,
23744 const struct inet_bind_bucket *tb, bool relax)
23746 @@ -72,15 +103,13 @@ int inet_csk_bind_conflict(const struct
23747 (sk2->sk_state != TCP_TIME_WAIT &&
23748 !uid_eq(uid, sock_i_uid(sk2))))) {
23750 - if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23751 - sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23752 + if (ipv4_rcv_saddr_equal(sk, sk2))
23755 if (!relax && reuse && sk2->sk_reuse &&
23756 sk2->sk_state != TCP_LISTEN) {
23758 - if (!sk2->sk_rcv_saddr || !sk->sk_rcv_saddr ||
23759 - sk2->sk_rcv_saddr == sk->sk_rcv_saddr)
23760 + if (ipv4_rcv_saddr_equal(sk, sk2))
23764 diff -NurpP --minimal linux-3.13.10/net/ipv4/inet_diag.c linux-3.13.10-vs2.3.6.11/net/ipv4/inet_diag.c
23765 --- linux-3.13.10/net/ipv4/inet_diag.c 2014-02-01 02:17:51.000000000 +0000
23766 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_diag.c 2014-02-01 02:32:22.000000000 +0000
23769 #include <linux/inet.h>
23770 #include <linux/stddef.h>
23771 +#include <linux/vs_network.h>
23772 +#include <linux/vs_inet.h>
23774 #include <linux/inet_diag.h>
23775 #include <linux/sock_diag.h>
23776 @@ -110,8 +112,10 @@ int inet_sk_diag_fill(struct sock *sk, s
23777 memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23778 memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23780 - r->id.idiag_src[0] = inet->inet_rcv_saddr;
23781 - r->id.idiag_dst[0] = inet->inet_daddr;
23782 + r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info,
23783 + inet->inet_rcv_saddr);
23784 + r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info,
23785 + inet->inet_daddr);
23787 if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
23789 @@ -254,8 +258,8 @@ static int inet_twsk_diag_fill(struct in
23790 memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23791 memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23793 - r->id.idiag_src[0] = tw->tw_rcv_saddr;
23794 - r->id.idiag_dst[0] = tw->tw_daddr;
23795 + r->id.idiag_src[0] = nx_map_sock_lback(tw->tw_nx_info, tw->tw_rcv_saddr);
23796 + r->id.idiag_dst[0] = nx_map_sock_lback(tw->tw_nx_info, tw->tw_daddr);
23798 r->idiag_state = tw->tw_substate;
23799 r->idiag_timer = 3;
23800 @@ -298,12 +302,14 @@ int inet_diag_dump_one_icsk(struct inet_
23803 if (req->sdiag_family == AF_INET) {
23804 + /* TODO: lback */
23805 sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
23806 req->id.idiag_dport, req->id.idiag_src[0],
23807 req->id.idiag_sport, req->id.idiag_if);
23809 #if IS_ENABLED(CONFIG_IPV6)
23810 else if (req->sdiag_family == AF_INET6) {
23811 + /* TODO: lback */
23812 sk = inet6_lookup(net, hashinfo,
23813 (struct in6_addr *)req->id.idiag_dst,
23814 req->id.idiag_dport,
23815 @@ -501,6 +507,7 @@ int inet_diag_bc_sk(const struct nlattr
23819 + /* TODO: lback */
23820 entry.saddr = &inet->inet_rcv_saddr;
23821 entry.daddr = &inet->inet_daddr;
23823 @@ -659,6 +666,7 @@ static int inet_twsk_diag_dump(struct so
23827 + /* TODO: lback */
23828 entry.saddr = &tw->tw_rcv_saddr;
23829 entry.daddr = &tw->tw_daddr;
23831 @@ -741,8 +749,8 @@ static int inet_diag_fill_req(struct sk_
23832 memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
23833 memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
23835 - r->id.idiag_src[0] = ireq->ir_loc_addr;
23836 - r->id.idiag_dst[0] = ireq->ir_rmt_addr;
23837 + r->id.idiag_src[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_loc_addr);
23838 + r->id.idiag_dst[0] = nx_map_sock_lback(sk->sk_nx_info, ireq->ir_rmt_addr);
23840 r->idiag_expires = jiffies_to_msecs(tmo);
23841 r->idiag_rqueue = 0;
23842 @@ -806,6 +814,7 @@ static int inet_diag_dump_reqs(struct sk
23846 + /* TODO: lback */
23848 inet_diag_req_addrs(sk, req, &entry);
23849 entry.dport = ntohs(ireq->ir_rmt_port);
23850 @@ -862,6 +871,8 @@ void inet_diag_dump_icsk(struct inet_has
23851 if (!net_eq(sock_net(sk), net))
23854 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23859 @@ -934,6 +945,8 @@ skip_listen_ht:
23861 if (!net_eq(sock_net(sk), net))
23863 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
23867 state = (sk->sk_state == TCP_TIME_WAIT) ?
23868 diff -NurpP --minimal linux-3.13.10/net/ipv4/inet_hashtables.c linux-3.13.10-vs2.3.6.11/net/ipv4/inet_hashtables.c
23869 --- linux-3.13.10/net/ipv4/inet_hashtables.c 2014-01-22 20:39:15.000000000 +0000
23870 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/inet_hashtables.c 2014-01-31 20:38:04.000000000 +0000
23872 #include <net/inet_connection_sock.h>
23873 #include <net/inet_hashtables.h>
23874 #include <net/secure_seq.h>
23875 +#include <net/route.h>
23876 #include <net/ip.h>
23878 static unsigned int inet_ehashfn(struct net *net, const __be32 laddr,
23879 @@ -181,6 +182,11 @@ static inline int compute_score(struct s
23880 if (rcv_saddr != daddr)
23884 + /* block non nx_info ips */
23885 + if (!v4_addr_in_nx_info(sk->sk_nx_info,
23886 + daddr, NXA_MASK_BIND))
23889 if (sk->sk_bound_dev_if) {
23890 if (sk->sk_bound_dev_if != dif)
23891 @@ -198,7 +204,6 @@ static inline int compute_score(struct s
23892 * wildcarded during the search since they can never be otherwise.
23896 struct sock *__inet_lookup_listener(struct net *net,
23897 struct inet_hashinfo *hashinfo,
23898 const __be32 saddr, __be16 sport,
23899 @@ -234,6 +239,7 @@ begin:
23900 phash = next_pseudo_random32(phash);
23905 * if the nulls value we got at the end of this lookup is
23906 * not the expected one, we must restart lookup.
23907 diff -NurpP --minimal linux-3.13.10/net/ipv4/netfilter.c linux-3.13.10-vs2.3.6.11/net/ipv4/netfilter.c
23908 --- linux-3.13.10/net/ipv4/netfilter.c 2013-07-14 17:01:37.000000000 +0000
23909 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/netfilter.c 2014-01-31 20:38:04.000000000 +0000
23911 #include <linux/skbuff.h>
23912 #include <linux/gfp.h>
23913 #include <linux/export.h>
23914 -#include <net/route.h>
23915 +// #include <net/route.h>
23916 #include <net/xfrm.h>
23917 #include <net/ip.h>
23918 #include <net/netfilter/nf_queue.h>
23919 diff -NurpP --minimal linux-3.13.10/net/ipv4/raw.c linux-3.13.10-vs2.3.6.11/net/ipv4/raw.c
23920 --- linux-3.13.10/net/ipv4/raw.c 2014-01-22 20:39:15.000000000 +0000
23921 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/raw.c 2014-01-31 20:38:04.000000000 +0000
23922 @@ -116,7 +116,7 @@ static struct sock *__raw_v4_lookup(stru
23924 if (net_eq(sock_net(sk), net) && inet->inet_num == num &&
23925 !(inet->inet_daddr && inet->inet_daddr != raddr) &&
23926 - !(inet->inet_rcv_saddr && inet->inet_rcv_saddr != laddr) &&
23927 + v4_sock_addr_match(sk->sk_nx_info, inet, laddr) &&
23928 !(sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
23929 goto found; /* gotcha */
23931 @@ -397,6 +397,12 @@ static int raw_send_hdrinc(struct sock *
23932 icmp_out_count(net, ((struct icmphdr *)
23933 skb_transport_header(skb))->type);
23936 + if (!nx_check(0, VS_ADMIN) && !capable(CAP_NET_RAW) &&
23937 + sk->sk_nx_info &&
23938 + !v4_addr_in_nx_info(sk->sk_nx_info, iph->saddr, NXA_MASK_BIND))
23941 err = NF_HOOK(NFPROTO_IPV4, NF_INET_LOCAL_OUT, skb, NULL,
23942 rt->dst.dev, dst_output);
23944 @@ -585,6 +591,16 @@ static int raw_sendmsg(struct kiocb *ioc
23948 + if (sk->sk_nx_info) {
23949 + rt = ip_v4_find_src(sock_net(sk), sk->sk_nx_info, &fl4);
23950 + if (IS_ERR(rt)) {
23951 + err = PTR_ERR(rt);
23958 security_sk_classify_flow(sk, flowi4_to_flowi(&fl4));
23959 rt = ip_route_output_flow(sock_net(sk), &fl4, sk);
23961 @@ -661,17 +677,19 @@ static int raw_bind(struct sock *sk, str
23963 struct inet_sock *inet = inet_sk(sk);
23964 struct sockaddr_in *addr = (struct sockaddr_in *) uaddr;
23965 + struct nx_v4_sock_addr nsa = { 0 };
23969 if (sk->sk_state != TCP_CLOSE || addr_len < sizeof(struct sockaddr_in))
23971 - chk_addr_ret = inet_addr_type(sock_net(sk), addr->sin_addr.s_addr);
23972 + v4_map_sock_addr(inet, addr, &nsa);
23973 + chk_addr_ret = inet_addr_type(sock_net(sk), nsa.saddr);
23974 ret = -EADDRNOTAVAIL;
23975 - if (addr->sin_addr.s_addr && chk_addr_ret != RTN_LOCAL &&
23976 + if (nsa.saddr && chk_addr_ret != RTN_LOCAL &&
23977 chk_addr_ret != RTN_MULTICAST && chk_addr_ret != RTN_BROADCAST)
23979 - inet->inet_rcv_saddr = inet->inet_saddr = addr->sin_addr.s_addr;
23980 + v4_set_sock_addr(inet, &nsa);
23981 if (chk_addr_ret == RTN_MULTICAST || chk_addr_ret == RTN_BROADCAST)
23982 inet->inet_saddr = 0; /* Use device */
23984 @@ -720,7 +738,8 @@ static int raw_recvmsg(struct kiocb *ioc
23985 /* Copy the address. */
23987 sin->sin_family = AF_INET;
23988 - sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
23989 + sin->sin_addr.s_addr =
23990 + nx_map_sock_lback(sk->sk_nx_info, ip_hdr(skb)->saddr);
23992 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
23993 *addr_len = sizeof(*sin);
23994 @@ -916,7 +935,8 @@ static struct sock *raw_get_first(struct
23995 for (state->bucket = 0; state->bucket < RAW_HTABLE_SIZE;
23997 sk_for_each(sk, &state->h->ht[state->bucket])
23998 - if (sock_net(sk) == seq_file_net(seq))
23999 + if ((sock_net(sk) == seq_file_net(seq)) &&
24000 + nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24004 @@ -932,7 +952,8 @@ static struct sock *raw_get_next(struct
24008 - } while (sk && sock_net(sk) != seq_file_net(seq));
24009 + } while (sk && ((sock_net(sk) != seq_file_net(seq)) ||
24010 + !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24012 if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
24013 sk = sk_head(&state->h->ht[state->bucket]);
24014 diff -NurpP --minimal linux-3.13.10/net/ipv4/route.c linux-3.13.10-vs2.3.6.11/net/ipv4/route.c
24015 --- linux-3.13.10/net/ipv4/route.c 2014-04-17 01:12:41.000000000 +0000
24016 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/route.c 2014-03-12 15:51:08.000000000 +0000
24017 @@ -2063,7 +2063,7 @@ struct rtable *__ip_route_output_key(str
24020 if (fl4->flowi4_oif) {
24021 - dev_out = dev_get_by_index_rcu(net, fl4->flowi4_oif);
24022 + dev_out = dev_get_by_index_real_rcu(net, fl4->flowi4_oif);
24023 rth = ERR_PTR(-ENODEV);
24024 if (dev_out == NULL)
24026 diff -NurpP --minimal linux-3.13.10/net/ipv4/tcp.c linux-3.13.10-vs2.3.6.11/net/ipv4/tcp.c
24027 --- linux-3.13.10/net/ipv4/tcp.c 2014-04-17 01:12:41.000000000 +0000
24028 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp.c 2014-04-17 01:17:11.000000000 +0000
24029 @@ -268,6 +268,7 @@
24030 #include <linux/crypto.h>
24031 #include <linux/time.h>
24032 #include <linux/slab.h>
24033 +#include <linux/in.h>
24035 #include <net/icmp.h>
24036 #include <net/inet_common.h>
24037 diff -NurpP --minimal linux-3.13.10/net/ipv4/tcp_ipv4.c linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_ipv4.c
24038 --- linux-3.13.10/net/ipv4/tcp_ipv4.c 2014-04-17 01:12:41.000000000 +0000
24039 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_ipv4.c 2014-04-17 01:17:11.000000000 +0000
24040 @@ -2227,6 +2227,12 @@ static void *listening_get_next(struct s
24041 req = req->dl_next;
24044 + vxdprintk(VXD_CBIT(net, 6),
24045 + "sk,req: %p [#%d] (from %d)", req->sk,
24046 + (req->sk)?req->sk->sk_nid:0, nx_current_nid());
24048 + !nx_check(req->sk->sk_nid, VS_WATCH_P | VS_IDENT))
24050 if (req->rsk_ops->family == st->family) {
24053 @@ -2251,6 +2257,10 @@ get_req:
24056 sk_nulls_for_each_from(sk, node) {
24057 + vxdprintk(VXD_CBIT(net, 6), "sk: %p [#%d] (from %d)",
24058 + sk, sk->sk_nid, nx_current_nid());
24059 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24061 if (!net_eq(sock_net(sk), net))
24063 if (sk->sk_family == st->family) {
24064 @@ -2325,6 +2335,11 @@ static void *established_get_first(struc
24066 spin_lock_bh(lock);
24067 sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) {
24068 + vxdprintk(VXD_CBIT(net, 6),
24069 + "sk,egf: %p [#%d] (from %d)",
24070 + sk, sk->sk_nid, nx_current_nid());
24071 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24073 if (sk->sk_family != st->family ||
24074 !net_eq(sock_net(sk), net)) {
24076 @@ -2351,6 +2366,11 @@ static void *established_get_next(struct
24077 sk = sk_nulls_next(sk);
24079 sk_nulls_for_each_from(sk, node) {
24080 + vxdprintk(VXD_CBIT(net, 6),
24081 + "sk,egn: %p [#%d] (from %d)",
24082 + sk, sk->sk_nid, nx_current_nid());
24083 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24085 if (sk->sk_family == st->family && net_eq(sock_net(sk), net))
24088 @@ -2549,9 +2569,9 @@ static void get_openreq4(const struct so
24089 seq_printf(f, "%4d: %08X:%04X %08X:%04X"
24090 " %02X %08X:%08X %02X:%08lX %08X %5u %8d %u %d %pK",
24092 - ireq->ir_loc_addr,
24093 + nx_map_sock_lback(current_nx_info(), ireq->ir_loc_addr),
24094 ntohs(inet_sk(sk)->inet_sport),
24095 - ireq->ir_rmt_addr,
24096 + nx_map_sock_lback(current_nx_info(), ireq->ir_rmt_addr),
24097 ntohs(ireq->ir_rmt_port),
24099 0, 0, /* could print option size, but that is af dependent. */
24100 @@ -2573,8 +2593,8 @@ static void get_tcp4_sock(struct sock *s
24101 const struct inet_connection_sock *icsk = inet_csk(sk);
24102 const struct inet_sock *inet = inet_sk(sk);
24103 struct fastopen_queue *fastopenq = icsk->icsk_accept_queue.fastopenq;
24104 - __be32 dest = inet->inet_daddr;
24105 - __be32 src = inet->inet_rcv_saddr;
24106 + __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24107 + __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24108 __u16 destp = ntohs(inet->inet_dport);
24109 __u16 srcp = ntohs(inet->inet_sport);
24111 @@ -2631,8 +2651,8 @@ static void get_timewait4_sock(const str
24113 s32 delta = tw->tw_ttd - inet_tw_time_stamp();
24115 - dest = tw->tw_daddr;
24116 - src = tw->tw_rcv_saddr;
24117 + dest = nx_map_sock_lback(current_nx_info(), tw->tw_daddr);
24118 + src = nx_map_sock_lback(current_nx_info(), tw->tw_rcv_saddr);
24119 destp = ntohs(tw->tw_dport);
24120 srcp = ntohs(tw->tw_sport);
24122 diff -NurpP --minimal linux-3.13.10/net/ipv4/tcp_minisocks.c linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_minisocks.c
24123 --- linux-3.13.10/net/ipv4/tcp_minisocks.c 2014-01-22 20:39:15.000000000 +0000
24124 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/tcp_minisocks.c 2014-01-31 20:38:04.000000000 +0000
24126 #include <linux/slab.h>
24127 #include <linux/sysctl.h>
24128 #include <linux/workqueue.h>
24129 +#include <linux/vs_limit.h>
24130 +#include <linux/vs_socket.h>
24131 +#include <linux/vs_context.h>
24132 #include <net/tcp.h>
24133 #include <net/inet_common.h>
24134 #include <net/xfrm.h>
24135 @@ -290,6 +293,11 @@ void tcp_time_wait(struct sock *sk, int
24136 tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
24137 tcptw->tw_ts_offset = tp->tsoffset;
24139 + tw->tw_xid = sk->sk_xid;
24140 + tw->tw_vx_info = NULL;
24141 + tw->tw_nid = sk->sk_nid;
24142 + tw->tw_nx_info = NULL;
24144 #if IS_ENABLED(CONFIG_IPV6)
24145 if (tw->tw_family == PF_INET6) {
24146 struct ipv6_pinfo *np = inet6_sk(sk);
24147 diff -NurpP --minimal linux-3.13.10/net/ipv4/udp.c linux-3.13.10-vs2.3.6.11/net/ipv4/udp.c
24148 --- linux-3.13.10/net/ipv4/udp.c 2014-01-22 20:39:15.000000000 +0000
24149 +++ linux-3.13.10-vs2.3.6.11/net/ipv4/udp.c 2014-01-31 22:20:27.000000000 +0000
24150 @@ -308,14 +308,7 @@ fail:
24152 EXPORT_SYMBOL(udp_lib_get_port);
24154 -static int ipv4_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24156 - struct inet_sock *inet1 = inet_sk(sk1), *inet2 = inet_sk(sk2);
24158 - return (!ipv6_only_sock(sk2) &&
24159 - (!inet1->inet_rcv_saddr || !inet2->inet_rcv_saddr ||
24160 - inet1->inet_rcv_saddr == inet2->inet_rcv_saddr));
24162 +extern int ipv4_rcv_saddr_equal(const struct sock *, const struct sock *);
24164 static unsigned int udp4_portaddr_hash(struct net *net, __be32 saddr,
24166 @@ -350,6 +343,11 @@ static inline int compute_score(struct s
24167 if (inet->inet_rcv_saddr != daddr)
24171 + /* block non nx_info ips */
24172 + if (!v4_addr_in_nx_info(sk->sk_nx_info,
24173 + daddr, NXA_MASK_BIND))
24176 if (inet->inet_daddr) {
24177 if (inet->inet_daddr != saddr)
24178 @@ -472,6 +470,7 @@ begin:
24183 /* UDP is nearly always wildcards out the wazoo, it makes no sense to try
24184 * harder than this. -DaveM
24186 @@ -518,6 +517,11 @@ begin:
24187 sk_nulls_for_each_rcu(sk, node, &hslot->head) {
24188 score = compute_score(sk, net, saddr, hnum, sport,
24189 daddr, dport, dif);
24190 + /* FIXME: disabled?
24191 + if (score == 9) {
24195 if (score > badness) {
24198 @@ -542,6 +546,7 @@ begin:
24199 if (get_nulls_value(node) != slot)
24204 if (unlikely(!atomic_inc_not_zero_hint(&result->sk_refcnt, 2)))
24206 @@ -551,6 +556,7 @@ begin:
24214 @@ -585,7 +591,7 @@ static inline bool __udp_is_mcast_sock(s
24215 udp_sk(sk)->udp_port_hash != hnum ||
24216 (inet->inet_daddr && inet->inet_daddr != rmt_addr) ||
24217 (inet->inet_dport != rmt_port && inet->inet_dport) ||
24218 - (inet->inet_rcv_saddr && inet->inet_rcv_saddr != loc_addr) ||
24219 + !v4_sock_addr_match(sk->sk_nx_info, inet, loc_addr) ||
24220 ipv6_only_sock(sk) ||
24221 (sk->sk_bound_dev_if && sk->sk_bound_dev_if != dif))
24223 @@ -989,6 +995,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
24224 inet_sk_flowi_flags(sk)|FLOWI_FLAG_CAN_SLEEP,
24225 faddr, saddr, dport, inet->inet_sport);
24227 + if (sk->sk_nx_info) {
24228 + rt = ip_v4_find_src(net, sk->sk_nx_info, fl4);
24229 + if (IS_ERR(rt)) {
24230 + err = PTR_ERR(rt);
24237 security_sk_classify_flow(sk, flowi4_to_flowi(fl4));
24238 rt = ip_route_output_flow(net, fl4, sk);
24240 @@ -1293,7 +1309,8 @@ try_again:
24242 sin->sin_family = AF_INET;
24243 sin->sin_port = udp_hdr(skb)->source;
24244 - sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
24245 + sin->sin_addr.s_addr = nx_map_sock_lback(
24246 + skb->sk->sk_nx_info, ip_hdr(skb)->saddr);
24247 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
24248 *addr_len = sizeof(*sin);
24250 @@ -2223,6 +2240,8 @@ static struct sock *udp_get_first(struct
24251 sk_nulls_for_each(sk, node, &hslot->head) {
24252 if (!net_eq(sock_net(sk), net))
24254 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
24256 if (sk->sk_family == state->family)
24259 @@ -2240,7 +2259,9 @@ static struct sock *udp_get_next(struct
24262 sk = sk_nulls_next(sk);
24263 - } while (sk && (!net_eq(sock_net(sk), net) || sk->sk_family != state->family));
24264 + } while (sk && (!net_eq(sock_net(sk), net) ||
24265 + sk->sk_family != state->family ||
24266 + !nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT)));
24269 if (state->bucket <= state->udp_table->mask)
24270 @@ -2336,8 +2357,8 @@ static void udp4_format_sock(struct sock
24273 struct inet_sock *inet = inet_sk(sp);
24274 - __be32 dest = inet->inet_daddr;
24275 - __be32 src = inet->inet_rcv_saddr;
24276 + __be32 dest = nx_map_sock_lback(current_nx_info(), inet->inet_daddr);
24277 + __be32 src = nx_map_sock_lback(current_nx_info(), inet->inet_rcv_saddr);
24278 __u16 destp = ntohs(inet->inet_dport);
24279 __u16 srcp = ntohs(inet->inet_sport);
24281 diff -NurpP --minimal linux-3.13.10/net/ipv6/Kconfig linux-3.13.10-vs2.3.6.11/net/ipv6/Kconfig
24282 --- linux-3.13.10/net/ipv6/Kconfig 2014-01-22 20:39:15.000000000 +0000
24283 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/Kconfig 2014-01-31 20:38:04.000000000 +0000
24286 # IPv6 as module will cause a CRASH if you try to unload it
24288 - tristate "The IPv6 protocol"
24290 + bool "The IPv6 protocol"
24293 This is complemental support for the IP version 6.
24294 You will still be able to do traditional IPv4 networking as well.
24295 diff -NurpP --minimal linux-3.13.10/net/ipv6/addrconf.c linux-3.13.10-vs2.3.6.11/net/ipv6/addrconf.c
24296 --- linux-3.13.10/net/ipv6/addrconf.c 2014-04-17 01:12:41.000000000 +0000
24297 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/addrconf.c 2014-04-17 01:17:11.000000000 +0000
24299 #include <linux/proc_fs.h>
24300 #include <linux/seq_file.h>
24301 #include <linux/export.h>
24302 +#include <linux/vs_network.h>
24303 +#include <linux/vs_inet6.h>
24305 /* Set to 3 to get tracing... */
24306 #define ACONF_DEBUG 2
24307 @@ -1284,7 +1286,7 @@ out:
24309 int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
24310 const struct in6_addr *daddr, unsigned int prefs,
24311 - struct in6_addr *saddr)
24312 + struct in6_addr *saddr, struct nx_info *nxi)
24314 struct ipv6_saddr_score scores[2],
24315 *score = &scores[0], *hiscore = &scores[1];
24316 @@ -1356,6 +1358,8 @@ int ipv6_dev_get_saddr(struct net *net,
24320 + if (!v6_addr_in_nx_info(nxi, &score->ifa->addr, -1))
24324 bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX);
24325 @@ -3371,7 +3375,10 @@ static void if6_seq_stop(struct seq_file
24326 static int if6_seq_show(struct seq_file *seq, void *v)
24328 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
24329 - seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24331 + if (nx_check(0, VS_ADMIN|VS_WATCH) ||
24332 + v6_addr_in_nx_info(current_nx_info(), &ifp->addr, -1))
24333 + seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
24335 ifp->idev->dev->ifindex,
24337 @@ -3892,6 +3899,11 @@ static int in6_dump_addrs(struct inet6_d
24338 struct ifacaddr6 *ifaca;
24340 int ip_idx = *p_ip_idx;
24341 + struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24343 + /* disable ipv6 on non v6 guests */
24344 + if (nxi && !nx_info_has_v6(nxi))
24347 read_lock_bh(&idev->lock);
24349 @@ -3902,6 +3914,8 @@ static int in6_dump_addrs(struct inet6_d
24350 list_for_each_entry(ifa, &idev->addr_list, if_list) {
24351 if (++ip_idx < s_ip_idx)
24353 + if (!v6_addr_in_nx_info(nxi, &ifa->addr, -1))
24355 err = inet6_fill_ifaddr(skb, ifa,
24356 NETLINK_CB(cb->skb).portid,
24357 cb->nlh->nlmsg_seq,
24358 @@ -3919,6 +3933,8 @@ static int in6_dump_addrs(struct inet6_d
24359 ifmca = ifmca->next, ip_idx++) {
24360 if (ip_idx < s_ip_idx)
24362 + if (!v6_addr_in_nx_info(nxi, &ifmca->mca_addr, -1))
24364 err = inet6_fill_ifmcaddr(skb, ifmca,
24365 NETLINK_CB(cb->skb).portid,
24366 cb->nlh->nlmsg_seq,
24367 @@ -3934,6 +3950,8 @@ static int in6_dump_addrs(struct inet6_d
24368 ifaca = ifaca->aca_next, ip_idx++) {
24369 if (ip_idx < s_ip_idx)
24371 + if (!v6_addr_in_nx_info(nxi, &ifaca->aca_addr, -1))
24373 err = inet6_fill_ifacaddr(skb, ifaca,
24374 NETLINK_CB(cb->skb).portid,
24375 cb->nlh->nlmsg_seq,
24376 @@ -3962,6 +3980,10 @@ static int inet6_dump_addr(struct sk_buf
24377 struct inet6_dev *idev;
24378 struct hlist_head *head;
24380 + /* FIXME: maybe disable ipv6 on non v6 guests?
24381 + if (skb->sk && skb->sk->sk_vx_info)
24382 + return skb->len; */
24385 s_idx = idx = cb->args[1];
24386 s_ip_idx = ip_idx = cb->args[2];
24387 @@ -4404,6 +4426,7 @@ static int inet6_dump_ifinfo(struct sk_b
24388 struct net_device *dev;
24389 struct inet6_dev *idev;
24390 struct hlist_head *head;
24391 + struct nx_info *nxi = skb->sk ? skb->sk->sk_nx_info : NULL;
24394 s_idx = cb->args[1];
24395 @@ -4415,6 +4438,8 @@ static int inet6_dump_ifinfo(struct sk_b
24396 hlist_for_each_entry_rcu(dev, head, index_hlist) {
24399 + if (!v6_dev_in_nx_info(dev, nxi))
24401 idev = __in6_dev_get(dev);
24404 diff -NurpP --minimal linux-3.13.10/net/ipv6/af_inet6.c linux-3.13.10-vs2.3.6.11/net/ipv6/af_inet6.c
24405 --- linux-3.13.10/net/ipv6/af_inet6.c 2014-01-22 20:39:15.000000000 +0000
24406 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/af_inet6.c 2014-01-31 21:39:03.000000000 +0000
24408 #include <linux/netdevice.h>
24409 #include <linux/icmpv6.h>
24410 #include <linux/netfilter_ipv6.h>
24411 +#include <linux/vs_inet.h>
24412 +#include <linux/vs_inet6.h>
24414 #include <net/ip.h>
24415 #include <net/ipv6.h>
24416 @@ -156,10 +158,13 @@ lookup_protocol:
24420 + if ((protocol == IPPROTO_ICMPV6) &&
24421 + nx_capable(CAP_NET_RAW, NXC_RAW_ICMP))
24423 if (sock->type == SOCK_RAW && !kern &&
24424 !ns_capable(net->user_ns, CAP_NET_RAW))
24425 goto out_rcu_unlock;
24428 sock->ops = answer->ops;
24429 answer_prot = answer->prot;
24430 answer_no_check = answer->no_check;
24431 @@ -259,6 +264,7 @@ int inet6_bind(struct socket *sock, stru
24432 struct inet_sock *inet = inet_sk(sk);
24433 struct ipv6_pinfo *np = inet6_sk(sk);
24434 struct net *net = sock_net(sk);
24435 + struct nx_v6_sock_addr nsa;
24437 unsigned short snum;
24439 @@ -274,6 +280,10 @@ int inet6_bind(struct socket *sock, stru
24440 if (addr->sin6_family != AF_INET6)
24441 return -EAFNOSUPPORT;
24443 + err = v6_map_sock_addr(inet, addr, &nsa);
24447 addr_type = ipv6_addr_type(&addr->sin6_addr);
24448 if ((addr_type & IPV6_ADDR_MULTICAST) && sock->type == SOCK_STREAM)
24450 @@ -305,6 +315,7 @@ int inet6_bind(struct socket *sock, stru
24451 /* Reproduce AF_INET checks to make the bindings consistent */
24452 v4addr = addr->sin6_addr.s6_addr32[3];
24453 chk_addr_ret = inet_addr_type(net, v4addr);
24455 if (!sysctl_ip_nonlocal_bind &&
24456 !(inet->freebind || inet->transparent) &&
24457 v4addr != htonl(INADDR_ANY) &&
24458 @@ -314,6 +325,10 @@ int inet6_bind(struct socket *sock, stru
24459 err = -EADDRNOTAVAIL;
24462 + if (!v4_addr_in_nx_info(sk->sk_nx_info, v4addr, NXA_MASK_BIND)) {
24463 + err = -EADDRNOTAVAIL;
24467 if (addr_type != IPV6_ADDR_ANY) {
24468 struct net_device *dev = NULL;
24469 @@ -340,6 +355,11 @@ int inet6_bind(struct socket *sock, stru
24473 + if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24474 + err = -EADDRNOTAVAIL;
24478 /* ipv4 addr of the socket is invalid. Only the
24479 * unspecified and mapped address have a v4 equivalent.
24481 @@ -356,6 +376,9 @@ int inet6_bind(struct socket *sock, stru
24485 + /* what's that for? */
24486 + v6_set_sock_addr(inet, &nsa);
24488 inet->inet_rcv_saddr = v4addr;
24489 inet->inet_saddr = v4addr;
24491 @@ -457,9 +480,11 @@ int inet6_getname(struct socket *sock, s
24493 sin->sin6_port = inet->inet_dport;
24494 sin->sin6_addr = sk->sk_v6_daddr;
24495 + /* FIXME: remap lback? */
24497 sin->sin6_flowinfo = np->flow_label;
24499 + /* FIXME: remap lback? */
24500 if (ipv6_addr_any(&sk->sk_v6_rcv_saddr))
24501 sin->sin6_addr = np->saddr;
24503 diff -NurpP --minimal linux-3.13.10/net/ipv6/datagram.c linux-3.13.10-vs2.3.6.11/net/ipv6/datagram.c
24504 --- linux-3.13.10/net/ipv6/datagram.c 2014-01-22 20:39:15.000000000 +0000
24505 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/datagram.c 2014-01-31 20:38:04.000000000 +0000
24506 @@ -655,7 +655,7 @@ int ip6_datagram_send_ctl(struct net *ne
24509 if (fl6->flowi6_oif) {
24510 - dev = dev_get_by_index_rcu(net, fl6->flowi6_oif);
24511 + dev = dev_get_by_index_real_rcu(net, fl6->flowi6_oif);
24515 diff -NurpP --minimal linux-3.13.10/net/ipv6/fib6_rules.c linux-3.13.10-vs2.3.6.11/net/ipv6/fib6_rules.c
24516 --- linux-3.13.10/net/ipv6/fib6_rules.c 2014-01-22 20:39:15.000000000 +0000
24517 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/fib6_rules.c 2014-01-31 20:38:04.000000000 +0000
24518 @@ -97,7 +97,7 @@ static int fib6_rule_action(struct fib_r
24519 ip6_dst_idev(&rt->dst)->dev,
24521 rt6_flags2srcprefs(flags),
24525 if (!ipv6_prefix_equal(&saddr, &r->src.addr,
24527 diff -NurpP --minimal linux-3.13.10/net/ipv6/inet6_hashtables.c linux-3.13.10-vs2.3.6.11/net/ipv6/inet6_hashtables.c
24528 --- linux-3.13.10/net/ipv6/inet6_hashtables.c 2014-01-22 20:39:15.000000000 +0000
24529 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/inet6_hashtables.c 2014-01-31 20:38:04.000000000 +0000
24532 #include <linux/module.h>
24533 #include <linux/random.h>
24534 +#include <linux/vs_inet6.h>
24536 #include <net/inet_connection_sock.h>
24537 #include <net/inet_hashtables.h>
24538 @@ -116,7 +117,6 @@ struct sock *__inet6_lookup_established(
24539 unsigned int slot = hash & hashinfo->ehash_mask;
24540 struct inet_ehash_bucket *head = &hashinfo->ehash[slot];
24545 sk_nulls_for_each_rcu(sk, node, &head->chain) {
24546 @@ -158,6 +158,9 @@ static inline int compute_score(struct s
24547 if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24551 + if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24554 if (sk->sk_bound_dev_if) {
24555 if (sk->sk_bound_dev_if != dif)
24556 diff -NurpP --minimal linux-3.13.10/net/ipv6/ip6_fib.c linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_fib.c
24557 --- linux-3.13.10/net/ipv6/ip6_fib.c 2014-01-22 20:39:15.000000000 +0000
24558 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_fib.c 2014-01-31 21:48:35.000000000 +0000
24559 @@ -1779,6 +1779,7 @@ static int ipv6_route_seq_show(struct se
24560 struct rt6_info *rt = v;
24561 struct ipv6_route_iter *iter = seq->private;
24563 + /* FIXME: check for network context? */
24564 seq_printf(seq, "%pi6 %02x ", &rt->rt6i_dst.addr, rt->rt6i_dst.plen);
24566 #ifdef CONFIG_IPV6_SUBTREES
24567 diff -NurpP --minimal linux-3.13.10/net/ipv6/ip6_output.c linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_output.c
24568 --- linux-3.13.10/net/ipv6/ip6_output.c 2014-04-17 01:12:41.000000000 +0000
24569 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ip6_output.c 2014-04-17 01:17:11.000000000 +0000
24570 @@ -872,7 +872,8 @@ static int ip6_dst_lookup_tail(struct so
24571 struct rt6_info *rt = (struct rt6_info *) *dst;
24572 err = ip6_route_get_saddr(net, rt, &fl6->daddr,
24573 sk ? inet6_sk(sk)->srcprefs : 0,
24576 + sk ? sk->sk_nx_info : NULL);
24578 goto out_err_release;
24580 diff -NurpP --minimal linux-3.13.10/net/ipv6/ndisc.c linux-3.13.10-vs2.3.6.11/net/ipv6/ndisc.c
24581 --- linux-3.13.10/net/ipv6/ndisc.c 2014-01-22 20:39:15.000000000 +0000
24582 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/ndisc.c 2014-01-31 20:38:04.000000000 +0000
24583 @@ -486,7 +486,7 @@ void ndisc_send_na(struct net_device *de
24585 if (ipv6_dev_get_saddr(dev_net(dev), dev, daddr,
24586 inet6_sk(dev_net(dev)->ipv6.ndisc_sk)->srcprefs,
24590 src_addr = &tmpaddr;
24592 diff -NurpP --minimal linux-3.13.10/net/ipv6/netfilter/ip6t_MASQUERADE.c linux-3.13.10-vs2.3.6.11/net/ipv6/netfilter/ip6t_MASQUERADE.c
24593 --- linux-3.13.10/net/ipv6/netfilter/ip6t_MASQUERADE.c 2013-11-25 15:47:07.000000000 +0000
24594 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/netfilter/ip6t_MASQUERADE.c 2014-01-31 20:38:04.000000000 +0000
24595 @@ -34,7 +34,7 @@ masquerade_tg6(struct sk_buff *skb, cons
24596 ctinfo == IP_CT_RELATED_REPLY));
24598 if (ipv6_dev_get_saddr(dev_net(par->out), par->out,
24599 - &ipv6_hdr(skb)->daddr, 0, &src) < 0)
24600 + &ipv6_hdr(skb)->daddr, 0, &src, NULL) < 0)
24603 nfct_nat(ct)->masq_index = par->out->ifindex;
24604 diff -NurpP --minimal linux-3.13.10/net/ipv6/raw.c linux-3.13.10-vs2.3.6.11/net/ipv6/raw.c
24605 --- linux-3.13.10/net/ipv6/raw.c 2014-01-22 20:39:15.000000000 +0000
24606 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/raw.c 2014-01-31 20:38:04.000000000 +0000
24608 #include <linux/icmpv6.h>
24609 #include <linux/netfilter.h>
24610 #include <linux/netfilter_ipv6.h>
24611 +#include <linux/vs_inet6.h>
24612 #include <linux/skbuff.h>
24613 #include <linux/compat.h>
24614 #include <asm/uaccess.h>
24615 @@ -287,6 +288,13 @@ static int rawv6_bind(struct sock *sk, s
24619 + if (!v6_addr_in_nx_info(sk->sk_nx_info, &addr->sin6_addr, -1)) {
24620 + err = -EADDRNOTAVAIL;
24626 /* ipv4 addr of the socket is invalid. Only the
24627 * unspecified and mapped address have a v4 equivalent.
24629 diff -NurpP --minimal linux-3.13.10/net/ipv6/route.c linux-3.13.10-vs2.3.6.11/net/ipv6/route.c
24630 --- linux-3.13.10/net/ipv6/route.c 2014-04-17 01:12:41.000000000 +0000
24631 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/route.c 2014-04-17 01:17:11.000000000 +0000
24633 #include <net/netevent.h>
24634 #include <net/netlink.h>
24635 #include <net/nexthop.h>
24636 +#include <linux/vs_inet6.h>
24638 #include <asm/uaccess.h>
24640 @@ -2196,15 +2197,17 @@ int ip6_route_get_saddr(struct net *net,
24641 struct rt6_info *rt,
24642 const struct in6_addr *daddr,
24643 unsigned int prefs,
24644 - struct in6_addr *saddr)
24645 + struct in6_addr *saddr,
24646 + struct nx_info *nxi)
24648 struct inet6_dev *idev = ip6_dst_idev((struct dst_entry*)rt);
24650 - if (rt->rt6i_prefsrc.plen)
24651 + if (rt->rt6i_prefsrc.plen && (!nxi ||
24652 + v6_addr_in_nx_info(nxi, &rt->rt6i_prefsrc.addr, NXA_TYPE_ADDR)))
24653 *saddr = rt->rt6i_prefsrc.addr;
24655 err = ipv6_dev_get_saddr(net, idev ? idev->dev : NULL,
24656 - daddr, prefs, saddr);
24657 + daddr, prefs, saddr, nxi);
24661 @@ -2624,7 +2627,8 @@ static int rt6_fill_node(struct net *net
24662 goto nla_put_failure;
24664 struct in6_addr saddr_buf;
24665 - if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf) == 0 &&
24666 + if (ip6_route_get_saddr(net, rt, dst, 0, &saddr_buf,
24667 + (skb->sk ? skb->sk->sk_nx_info : NULL)) == 0 &&
24668 nla_put(skb, RTA_PREFSRC, 16, &saddr_buf))
24669 goto nla_put_failure;
24671 diff -NurpP --minimal linux-3.13.10/net/ipv6/tcp_ipv6.c linux-3.13.10-vs2.3.6.11/net/ipv6/tcp_ipv6.c
24672 --- linux-3.13.10/net/ipv6/tcp_ipv6.c 2014-01-22 20:39:15.000000000 +0000
24673 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/tcp_ipv6.c 2014-01-31 20:38:04.000000000 +0000
24676 #include <linux/crypto.h>
24677 #include <linux/scatterlist.h>
24678 +#include <linux/vs_inet6.h>
24680 static void tcp_v6_send_reset(struct sock *sk, struct sk_buff *skb);
24681 static void tcp_v6_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
24682 @@ -164,8 +165,15 @@ static int tcp_v6_connect(struct sock *s
24683 * connect() to INADDR_ANY means loopback (BSD'ism).
24686 - if (ipv6_addr_any(&usin->sin6_addr))
24687 - usin->sin6_addr.s6_addr[15] = 0x1;
24688 + if (ipv6_addr_any(&usin->sin6_addr)) {
24689 + struct nx_info *nxi = sk->sk_nx_info;
24691 + if (nxi && nx_info_has_v6(nxi))
24692 + /* FIXME: remap lback? */
24693 + usin->sin6_addr = nxi->v6.ip;
24695 + usin->sin6_addr.s6_addr[15] = 0x1;
24698 addr_type = ipv6_addr_type(&usin->sin6_addr);
24700 diff -NurpP --minimal linux-3.13.10/net/ipv6/udp.c linux-3.13.10-vs2.3.6.11/net/ipv6/udp.c
24701 --- linux-3.13.10/net/ipv6/udp.c 2014-01-22 20:39:15.000000000 +0000
24702 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/udp.c 2014-02-01 02:33:38.000000000 +0000
24704 #include <net/xfrm.h>
24705 #include <net/inet6_hashtables.h>
24706 #include <net/busy_poll.h>
24707 +#include <linux/vs_inet6.h>
24709 #include <linux/proc_fs.h>
24710 #include <linux/seq_file.h>
24711 @@ -76,33 +77,61 @@ static unsigned int udp6_ehashfn(struct
24712 udp_ipv6_hash_secret + net_hash_mix(net));
24715 -int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
24716 +int ipv6_rcv_saddr_equal(const struct sock *sk1, const struct sock *sk2)
24718 + const struct in6_addr *sk1_rcv_saddr6 = inet6_rcv_saddr(sk1);
24719 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
24720 - int sk_ipv6only = ipv6_only_sock(sk);
24721 + __be32 sk1_rcv_saddr = sk1->sk_rcv_saddr;
24722 + __be32 sk2_rcv_saddr = sk2->sk_rcv_saddr;
24723 + int sk1_ipv6only = ipv6_only_sock(sk1);
24724 int sk2_ipv6only = inet_v6_ipv6only(sk2);
24725 - int addr_type = ipv6_addr_type(&sk->sk_v6_rcv_saddr);
24726 + int addr_type1 = ipv6_addr_type(sk1_rcv_saddr6);
24727 int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
24729 /* if both are mapped, treat as IPv4 */
24730 - if (addr_type == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED)
24731 - return (!sk2_ipv6only &&
24732 - (!sk->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24733 - sk->sk_rcv_saddr == sk2->sk_rcv_saddr));
24734 + if (addr_type1 == IPV6_ADDR_MAPPED && addr_type2 == IPV6_ADDR_MAPPED) {
24735 + if (!sk2_ipv6only &&
24736 + (!sk1->sk_rcv_saddr || !sk2->sk_rcv_saddr ||
24737 + sk1->sk_rcv_saddr == sk2->sk_rcv_saddr))
24743 if (addr_type2 == IPV6_ADDR_ANY &&
24744 - !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
24746 + !(sk2_ipv6only && addr_type1 == IPV6_ADDR_MAPPED))
24749 - if (addr_type == IPV6_ADDR_ANY &&
24750 - !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24752 + if (addr_type1 == IPV6_ADDR_ANY &&
24753 + !(sk1_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
24756 if (sk2_rcv_saddr6 &&
24757 - ipv6_addr_equal(&sk->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24759 + ipv6_addr_equal(&sk1->sk_v6_rcv_saddr, sk2_rcv_saddr6))
24765 + if (!sk1_rcv_saddr && !sk2_rcv_saddr)
24766 + return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24767 + if (!sk2_rcv_saddr)
24768 + return v4_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr, -1);
24769 + if (!sk1_rcv_saddr)
24770 + return v4_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr, -1);
24773 + if (addr_type2 == IPV6_ADDR_ANY && addr_type1 == IPV6_ADDR_ANY)
24774 + return nx_v6_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24775 + else if (addr_type2 == IPV6_ADDR_ANY)
24776 + return v6_addr_in_nx_info(sk2->sk_nx_info, sk1_rcv_saddr6, -1);
24777 + else if (addr_type1 == IPV6_ADDR_ANY) {
24778 + if (addr_type2 == IPV6_ADDR_MAPPED)
24779 + return nx_v4_addr_conflict(sk1->sk_nx_info, sk2->sk_nx_info);
24781 + return v6_addr_in_nx_info(sk1->sk_nx_info, sk2_rcv_saddr6, -1);
24786 static unsigned int udp6_portaddr_hash(struct net *net,
24787 @@ -160,6 +189,10 @@ static inline int compute_score(struct s
24788 if (inet->inet_dport != sport)
24792 + /* block non nx_info ips */
24793 + if (!v6_addr_in_nx_info(sk->sk_nx_info, daddr, -1))
24796 if (!ipv6_addr_any(&sk->sk_v6_rcv_saddr)) {
24797 if (!ipv6_addr_equal(&sk->sk_v6_rcv_saddr, daddr))
24798 diff -NurpP --minimal linux-3.13.10/net/ipv6/xfrm6_policy.c linux-3.13.10-vs2.3.6.11/net/ipv6/xfrm6_policy.c
24799 --- linux-3.13.10/net/ipv6/xfrm6_policy.c 2014-01-22 20:39:15.000000000 +0000
24800 +++ linux-3.13.10-vs2.3.6.11/net/ipv6/xfrm6_policy.c 2014-01-31 20:38:04.000000000 +0000
24801 @@ -63,7 +63,7 @@ static int xfrm6_get_saddr(struct net *n
24802 dev = ip6_dst_idev(dst)->dev;
24803 ipv6_dev_get_saddr(dev_net(dev), dev,
24804 (struct in6_addr *)&daddr->a6, 0,
24805 - (struct in6_addr *)&saddr->a6);
24806 + (struct in6_addr *)&saddr->a6, NULL);
24810 diff -NurpP --minimal linux-3.13.10/net/netfilter/ipvs/ip_vs_xmit.c linux-3.13.10-vs2.3.6.11/net/netfilter/ipvs/ip_vs_xmit.c
24811 --- linux-3.13.10/net/netfilter/ipvs/ip_vs_xmit.c 2013-11-25 15:47:07.000000000 +0000
24812 +++ linux-3.13.10-vs2.3.6.11/net/netfilter/ipvs/ip_vs_xmit.c 2014-01-31 20:38:04.000000000 +0000
24813 @@ -316,7 +316,7 @@ __ip_vs_route_output_v6(struct net *net,
24815 if (ipv6_addr_any(&fl6.saddr) &&
24816 ipv6_dev_get_saddr(net, ip6_dst_idev(dst)->dev,
24817 - &fl6.daddr, 0, &fl6.saddr) < 0)
24818 + &fl6.daddr, 0, &fl6.saddr, NULL) < 0)
24821 dst = xfrm_lookup(net, dst, flowi6_to_flowi(&fl6), NULL, 0);
24822 diff -NurpP --minimal linux-3.13.10/net/netlink/af_netlink.c linux-3.13.10-vs2.3.6.11/net/netlink/af_netlink.c
24823 --- linux-3.13.10/net/netlink/af_netlink.c 2014-01-22 20:39:16.000000000 +0000
24824 +++ linux-3.13.10-vs2.3.6.11/net/netlink/af_netlink.c 2014-02-25 11:47:07.000000000 +0000
24826 #include <linux/mutex.h>
24827 #include <linux/vmalloc.h>
24828 #include <linux/if_arp.h>
24829 +#include <linux/vs_context.h>
24830 +#include <linux/vs_network.h>
24831 +#include <linux/vs_limit.h>
24832 #include <asm/cacheflush.h>
24834 #include <net/net_namespace.h>
24835 @@ -2850,6 +2853,8 @@ static struct sock *netlink_seq_socket_i
24836 sk_for_each(s, &hash->table[j]) {
24837 if (sock_net(s) != seq_file_net(seq))
24839 + if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
24843 iter->hash_idx = j;
24844 @@ -2886,7 +2891,8 @@ static void *netlink_seq_next(struct seq
24848 - } while (s && !nl_table[s->sk_protocol].compare(net, s));
24849 + } while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24850 + !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)));
24854 @@ -2899,7 +2905,8 @@ static void *netlink_seq_next(struct seq
24855 for (; j <= hash->mask; j++) {
24856 s = sk_head(&hash->table[j]);
24858 - while (s && !nl_table[s->sk_protocol].compare(net, s))
24859 + while (s && (!nl_table[s->sk_protocol].compare(net, s) ||
24860 + !nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT)))
24864 diff -NurpP --minimal linux-3.13.10/net/socket.c linux-3.13.10-vs2.3.6.11/net/socket.c
24865 --- linux-3.13.10/net/socket.c 2014-04-17 01:12:42.000000000 +0000
24866 +++ linux-3.13.10-vs2.3.6.11/net/socket.c 2014-04-17 01:17:11.000000000 +0000
24869 #include <net/sock.h>
24870 #include <linux/netfilter.h>
24871 +#include <linux/vs_socket.h>
24872 +#include <linux/vs_inet.h>
24873 +#include <linux/vs_inet6.h>
24875 #include <linux/if_tun.h>
24876 #include <linux/ipv6_route.h>
24877 @@ -623,13 +626,29 @@ static inline int __sock_sendmsg_nosec(s
24878 struct msghdr *msg, size_t size)
24880 struct sock_iocb *si = kiocb_to_siocb(iocb);
24888 - return sock->ops->sendmsg(iocb, sock, msg, size);
24889 + len = sock->ops->sendmsg(iocb, sock, msg, size);
24892 + vx_sock_send(sock->sk, size);
24894 + vx_sock_fail(sock->sk, size);
24896 + vxdprintk(VXD_CBIT(net, 7),
24897 + "__sock_sendmsg: %p[%p,%p,%p;%d/%d]:%d/%zu",
24899 + (sock->sk)?sock->sk->sk_nx_info:0,
24900 + (sock->sk)?sock->sk->sk_vx_info:0,
24901 + (sock->sk)?sock->sk->sk_xid:0,
24902 + (sock->sk)?sock->sk->sk_nid:0,
24903 + (unsigned int)size, len);
24907 static inline int __sock_sendmsg(struct kiocb *iocb, struct socket *sock,
24908 @@ -773,6 +792,7 @@ static inline int __sock_recvmsg_nosec(s
24909 struct msghdr *msg, size_t size, int flags)
24911 struct sock_iocb *si = kiocb_to_siocb(iocb);
24916 @@ -780,7 +800,18 @@ static inline int __sock_recvmsg_nosec(s
24920 - return sock->ops->recvmsg(iocb, sock, msg, size, flags);
24921 + len = sock->ops->recvmsg(iocb, sock, msg, size, flags);
24922 + if ((len >= 0) && sock->sk)
24923 + vx_sock_recv(sock->sk, len);
24924 + vxdprintk(VXD_CBIT(net, 7),
24925 + "__sock_recvmsg: %p[%p,%p,%p;%d/%d]:%d/%d",
24927 + (sock->sk)?sock->sk->sk_nx_info:0,
24928 + (sock->sk)?sock->sk->sk_vx_info:0,
24929 + (sock->sk)?sock->sk->sk_xid:0,
24930 + (sock->sk)?sock->sk->sk_nid:0,
24931 + (unsigned int)size, len);
24935 static inline int __sock_recvmsg(struct kiocb *iocb, struct socket *sock,
24936 @@ -1256,6 +1287,13 @@ int __sock_create(struct net *net, int f
24937 if (type < 0 || type >= SOCK_MAX)
24940 + if (!nx_check(0, VS_ADMIN)) {
24941 + if (family == PF_INET && !current_nx_info_has_v4())
24942 + return -EAFNOSUPPORT;
24943 + if (family == PF_INET6 && !current_nx_info_has_v6())
24944 + return -EAFNOSUPPORT;
24949 This uglymoron is moved from INET layer to here to avoid
24950 @@ -1390,6 +1428,7 @@ SYSCALL_DEFINE3(socket, int, family, int
24954 + set_bit(SOCK_USER_SOCKET, &sock->flags);
24955 retval = sock_map_fd(sock, flags & (O_CLOEXEC | O_NONBLOCK));
24958 @@ -1431,10 +1470,12 @@ SYSCALL_DEFINE4(socketpair, int, family,
24959 err = sock_create(family, type, protocol, &sock1);
24962 + set_bit(SOCK_USER_SOCKET, &sock1->flags);
24964 err = sock_create(family, type, protocol, &sock2);
24966 goto out_release_1;
24967 + set_bit(SOCK_USER_SOCKET, &sock2->flags);
24969 err = sock1->ops->socketpair(sock1, sock2);
24971 diff -NurpP --minimal linux-3.13.10/net/sunrpc/auth.c linux-3.13.10-vs2.3.6.11/net/sunrpc/auth.c
24972 --- linux-3.13.10/net/sunrpc/auth.c 2013-11-25 15:47:08.000000000 +0000
24973 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/auth.c 2014-01-31 20:38:04.000000000 +0000
24975 #include <linux/sunrpc/clnt.h>
24976 #include <linux/sunrpc/gss_api.h>
24977 #include <linux/spinlock.h>
24978 +#include <linux/vs_tag.h>
24981 # define RPCDBG_FACILITY RPCDBG_AUTH
24982 @@ -586,6 +587,7 @@ rpcauth_lookupcred(struct rpc_auth *auth
24983 memset(&acred, 0, sizeof(acred));
24984 acred.uid = cred->fsuid;
24985 acred.gid = cred->fsgid;
24986 + acred.tag = make_ktag(&init_user_ns, dx_current_tag());
24987 acred.group_info = get_group_info(((struct cred *)cred)->group_info);
24989 ret = auth->au_ops->lookup_cred(auth, &acred, flags);
24990 @@ -626,6 +628,7 @@ rpcauth_bind_root_cred(struct rpc_task *
24991 struct auth_cred acred = {
24992 .uid = GLOBAL_ROOT_UID,
24993 .gid = GLOBAL_ROOT_GID,
24994 + .tag = KTAGT_INIT(dx_current_tag()),
24997 dprintk("RPC: %5u looking up %s cred\n",
24998 diff -NurpP --minimal linux-3.13.10/net/sunrpc/auth_unix.c linux-3.13.10-vs2.3.6.11/net/sunrpc/auth_unix.c
24999 --- linux-3.13.10/net/sunrpc/auth_unix.c 2013-11-25 15:47:08.000000000 +0000
25000 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/auth_unix.c 2014-01-31 20:38:04.000000000 +0000
25001 @@ -13,11 +13,13 @@
25002 #include <linux/sunrpc/clnt.h>
25003 #include <linux/sunrpc/auth.h>
25004 #include <linux/user_namespace.h>
25005 +#include <linux/vs_tag.h>
25007 #define NFS_NGROUPS 16
25010 struct rpc_cred uc_base;
25013 kgid_t uc_gids[NFS_NGROUPS];
25015 @@ -80,6 +82,7 @@ unx_create_cred(struct rpc_auth *auth, s
25016 groups = NFS_NGROUPS;
25018 cred->uc_gid = acred->gid;
25019 + cred->uc_tag = acred->tag;
25020 for (i = 0; i < groups; i++)
25021 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
25022 if (i < NFS_NGROUPS)
25023 @@ -121,7 +124,9 @@ unx_match(struct auth_cred *acred, struc
25027 - if (!uid_eq(cred->uc_uid, acred->uid) || !gid_eq(cred->uc_gid, acred->gid))
25028 + if (!uid_eq(cred->uc_uid, acred->uid) ||
25029 + !gid_eq(cred->uc_gid, acred->gid) ||
25030 + !tag_eq(cred->uc_tag, acred->tag))
25033 if (acred->group_info != NULL)
25034 @@ -146,7 +151,7 @@ unx_marshal(struct rpc_task *task, __be3
25035 struct rpc_clnt *clnt = task->tk_client;
25036 struct unx_cred *cred = container_of(task->tk_rqstp->rq_cred, struct unx_cred, uc_base);
25037 __be32 *base, *hold;
25041 *p++ = htonl(RPC_AUTH_UNIX);
25043 @@ -157,8 +162,11 @@ unx_marshal(struct rpc_task *task, __be3
25045 p = xdr_encode_array(p, clnt->cl_nodename, clnt->cl_nodelen);
25047 - *p++ = htonl((u32) from_kuid(&init_user_ns, cred->uc_uid));
25048 - *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gid));
25049 + tag = task->tk_client->cl_tag;
25050 + *p++ = htonl((u32) from_kuid(&init_user_ns,
25051 + TAGINO_KUID(tag, cred->uc_uid, cred->uc_tag)));
25052 + *p++ = htonl((u32) from_kgid(&init_user_ns,
25053 + TAGINO_KGID(tag, cred->uc_gid, cred->uc_tag)));
25055 for (i = 0; i < 16 && gid_valid(cred->uc_gids[i]); i++)
25056 *p++ = htonl((u32) from_kgid(&init_user_ns, cred->uc_gids[i]));
25057 diff -NurpP --minimal linux-3.13.10/net/sunrpc/clnt.c linux-3.13.10-vs2.3.6.11/net/sunrpc/clnt.c
25058 --- linux-3.13.10/net/sunrpc/clnt.c 2014-04-17 01:12:42.000000000 +0000
25059 +++ linux-3.13.10-vs2.3.6.11/net/sunrpc/clnt.c 2014-02-25 11:26:10.000000000 +0000
25061 #include <linux/in.h>
25062 #include <linux/in6.h>
25063 #include <linux/un.h>
25064 +#include <linux/vs_cvirt.h>
25066 #include <linux/sunrpc/clnt.h>
25067 #include <linux/sunrpc/addr.h>
25068 @@ -538,6 +539,9 @@ struct rpc_clnt *rpc_create(struct rpc_c
25069 if (!(args->flags & RPC_CLNT_CREATE_QUIET))
25070 clnt->cl_chatty = 1;
25072 + /* TODO: handle RPC_CLNT_CREATE_TAGGED
25073 + if (args->flags & RPC_CLNT_CREATE_TAGGED)
25074 + clnt->cl_tag = 1; */
25077 EXPORT_SYMBOL_GPL(rpc_create);
25078 diff -NurpP --minimal linux-3.13.10/net/unix/af_unix.c linux-3.13.10-vs2.3.6.11/net/unix/af_unix.c
25079 --- linux-3.13.10/net/unix/af_unix.c 2014-04-17 01:12:42.000000000 +0000
25080 +++ linux-3.13.10-vs2.3.6.11/net/unix/af_unix.c 2014-04-17 01:17:11.000000000 +0000
25081 @@ -115,6 +115,8 @@
25082 #include <net/checksum.h>
25083 #include <linux/security.h>
25084 #include <linux/freezer.h>
25085 +#include <linux/vs_context.h>
25086 +#include <linux/vs_limit.h>
25088 struct hlist_head unix_socket_table[2 * UNIX_HASH_SIZE];
25089 EXPORT_SYMBOL_GPL(unix_socket_table);
25090 @@ -270,6 +272,8 @@ static struct sock *__unix_find_socket_b
25091 if (!net_eq(sock_net(s), net))
25094 + if (!nx_check(s->sk_nid, VS_WATCH_P | VS_IDENT))
25096 if (u->addr->len == len &&
25097 !memcmp(u->addr->name, sunname, len))
25099 @@ -2275,6 +2279,8 @@ static struct sock *unix_from_bucket(str
25100 for (sk = sk_head(&unix_socket_table[bucket]); sk; sk = sk_next(sk)) {
25101 if (sock_net(sk) != seq_file_net(seq))
25103 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25105 if (++count == offset)
25108 @@ -2292,6 +2298,8 @@ static struct sock *unix_next_socket(str
25112 + if (!nx_check(sk->sk_nid, VS_WATCH_P | VS_IDENT))
25114 if (sock_net(sk) == seq_file_net(seq))
25117 diff -NurpP --minimal linux-3.13.10/scripts/checksyscalls.sh linux-3.13.10-vs2.3.6.11/scripts/checksyscalls.sh
25118 --- linux-3.13.10/scripts/checksyscalls.sh 2012-12-11 03:30:57.000000000 +0000
25119 +++ linux-3.13.10-vs2.3.6.11/scripts/checksyscalls.sh 2014-01-31 20:38:04.000000000 +0000
25120 @@ -193,7 +193,6 @@ cat << EOF
25121 #define __IGNORE_afs_syscall
25122 #define __IGNORE_getpmsg
25123 #define __IGNORE_putpmsg
25124 -#define __IGNORE_vserver
25128 diff -NurpP --minimal linux-3.13.10/security/commoncap.c linux-3.13.10-vs2.3.6.11/security/commoncap.c
25129 --- linux-3.13.10/security/commoncap.c 2013-11-25 15:47:08.000000000 +0000
25130 +++ linux-3.13.10-vs2.3.6.11/security/commoncap.c 2014-01-31 20:38:04.000000000 +0000
25131 @@ -76,6 +76,7 @@ int cap_netlink_send(struct sock *sk, st
25132 int cap_capable(const struct cred *cred, struct user_namespace *targ_ns,
25133 int cap, int audit)
25135 + struct vx_info *vxi = current_vx_info(); /* FIXME: get vxi from cred? */
25136 struct user_namespace *ns = targ_ns;
25138 /* See if cred has the capability in the target user namespace
25139 @@ -84,8 +85,12 @@ int cap_capable(const struct cred *cred,
25142 /* Do we have the necessary capabilities? */
25143 - if (ns == cred->user_ns)
25144 - return cap_raised(cred->cap_effective, cap) ? 0 : -EPERM;
25145 + if (ns == cred->user_ns) {
25146 + if (vx_info_flags(vxi, VXF_STATE_SETUP, 0) &&
25147 + cap_raised(cred->cap_effective, cap))
25149 + return vx_cap_raised(vxi, cred->cap_effective, cap) ? 0 : -EPERM;
25152 /* Have we tried all of the parent namespaces? */
25153 if (ns == &init_user_ns)
25154 @@ -628,7 +633,7 @@ int cap_inode_setxattr(struct dentry *de
25156 if (!strncmp(name, XATTR_SECURITY_PREFIX,
25157 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25158 - !capable(CAP_SYS_ADMIN))
25159 + !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25163 @@ -654,7 +659,7 @@ int cap_inode_removexattr(struct dentry
25165 if (!strncmp(name, XATTR_SECURITY_PREFIX,
25166 sizeof(XATTR_SECURITY_PREFIX) - 1) &&
25167 - !capable(CAP_SYS_ADMIN))
25168 + !vx_capable(CAP_SYS_ADMIN, VXC_FS_SECURITY))
25172 diff -NurpP --minimal linux-3.13.10/security/selinux/hooks.c linux-3.13.10-vs2.3.6.11/security/selinux/hooks.c
25173 --- linux-3.13.10/security/selinux/hooks.c 2014-04-17 01:12:42.000000000 +0000
25174 +++ linux-3.13.10-vs2.3.6.11/security/selinux/hooks.c 2014-04-17 01:17:11.000000000 +0000
25176 #include <linux/dccp.h>
25177 #include <linux/quota.h>
25178 #include <linux/un.h> /* for Unix socket types */
25179 -#include <net/af_unix.h> /* for Unix socket types */
25180 #include <linux/parser.h>
25181 #include <linux/nfs_mount.h>
25182 #include <net/ipv6.h>